]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blame - test/grsecurity-2.2.2-2.6.32.41-201106071941.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.2.2-2.6.32.41-201106071941.patch
CommitLineData
9f6b1984
PK
1diff -urNp linux-2.6.32.41/arch/alpha/include/asm/elf.h linux-2.6.32.41/arch/alpha/include/asm/elf.h
2--- linux-2.6.32.41/arch/alpha/include/asm/elf.h 2011-03-27 14:31:47.000000000 -0400
3+++ linux-2.6.32.41/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.41/arch/alpha/include/asm/pgtable.h linux-2.6.32.41/arch/alpha/include/asm/pgtable.h
19--- linux-2.6.32.41/arch/alpha/include/asm/pgtable.h 2011-03-27 14:31:47.000000000 -0400
20+++ linux-2.6.32.41/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.41/arch/alpha/kernel/module.c linux-2.6.32.41/arch/alpha/kernel/module.c
40--- linux-2.6.32.41/arch/alpha/kernel/module.c 2011-03-27 14:31:47.000000000 -0400
41+++ linux-2.6.32.41/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.41/arch/alpha/kernel/osf_sys.c linux-2.6.32.41/arch/alpha/kernel/osf_sys.c
52--- linux-2.6.32.41/arch/alpha/kernel/osf_sys.c 2011-03-27 14:31:47.000000000 -0400
53+++ linux-2.6.32.41/arch/alpha/kernel/osf_sys.c 2011-04-17 15:56:45.000000000 -0400
54@@ -1169,7 +1169,7 @@ arch_get_unmapped_area_1(unsigned long a
55 /* At this point: (!vma || addr < vma->vm_end). */
56 if (limit - len < addr)
57 return -ENOMEM;
58- if (!vma || addr + len <= vma->vm_start)
59+ if (check_heap_stack_gap(vma, addr, len))
60 return addr;
61 addr = vma->vm_end;
62 vma = vma->vm_next;
63@@ -1205,6 +1205,10 @@ arch_get_unmapped_area(struct file *filp
64 merely specific addresses, but regions of memory -- perhaps
65 this feature should be incorporated into all ports? */
66
67+#ifdef CONFIG_PAX_RANDMMAP
68+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
69+#endif
70+
71 if (addr) {
72 addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
73 if (addr != (unsigned long) -ENOMEM)
74@@ -1212,8 +1216,8 @@ arch_get_unmapped_area(struct file *filp
75 }
76
77 /* Next, try allocating at TASK_UNMAPPED_BASE. */
78- addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
79- len, limit);
80+ addr = arch_get_unmapped_area_1 (PAGE_ALIGN(current->mm->mmap_base), len, limit);
81+
82 if (addr != (unsigned long) -ENOMEM)
83 return addr;
84
85diff -urNp linux-2.6.32.41/arch/alpha/mm/fault.c linux-2.6.32.41/arch/alpha/mm/fault.c
86--- linux-2.6.32.41/arch/alpha/mm/fault.c 2011-03-27 14:31:47.000000000 -0400
87+++ linux-2.6.32.41/arch/alpha/mm/fault.c 2011-04-17 15:56:45.000000000 -0400
88@@ -54,6 +54,124 @@ __load_new_mm_context(struct mm_struct *
89 __reload_thread(pcb);
90 }
91
92+#ifdef CONFIG_PAX_PAGEEXEC
93+/*
94+ * PaX: decide what to do with offenders (regs->pc = fault address)
95+ *
96+ * returns 1 when task should be killed
97+ * 2 when patched PLT trampoline was detected
98+ * 3 when unpatched PLT trampoline was detected
99+ */
100+static int pax_handle_fetch_fault(struct pt_regs *regs)
101+{
102+
103+#ifdef CONFIG_PAX_EMUPLT
104+ int err;
105+
106+ do { /* PaX: patched PLT emulation #1 */
107+ unsigned int ldah, ldq, jmp;
108+
109+ err = get_user(ldah, (unsigned int *)regs->pc);
110+ err |= get_user(ldq, (unsigned int *)(regs->pc+4));
111+ err |= get_user(jmp, (unsigned int *)(regs->pc+8));
112+
113+ if (err)
114+ break;
115+
116+ if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
117+ (ldq & 0xFFFF0000U) == 0xA77B0000U &&
118+ jmp == 0x6BFB0000U)
119+ {
120+ unsigned long r27, addr;
121+ unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
122+ unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
123+
124+ addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
125+ err = get_user(r27, (unsigned long *)addr);
126+ if (err)
127+ break;
128+
129+ regs->r27 = r27;
130+ regs->pc = r27;
131+ return 2;
132+ }
133+ } while (0);
134+
135+ do { /* PaX: patched PLT emulation #2 */
136+ unsigned int ldah, lda, br;
137+
138+ err = get_user(ldah, (unsigned int *)regs->pc);
139+ err |= get_user(lda, (unsigned int *)(regs->pc+4));
140+ err |= get_user(br, (unsigned int *)(regs->pc+8));
141+
142+ if (err)
143+ break;
144+
145+ if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
146+ (lda & 0xFFFF0000U) == 0xA77B0000U &&
147+ (br & 0xFFE00000U) == 0xC3E00000U)
148+ {
149+ unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
150+ unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
151+ unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
152+
153+ regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
154+ regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
155+ return 2;
156+ }
157+ } while (0);
158+
159+ do { /* PaX: unpatched PLT emulation */
160+ unsigned int br;
161+
162+ err = get_user(br, (unsigned int *)regs->pc);
163+
164+ if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
165+ unsigned int br2, ldq, nop, jmp;
166+ unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
167+
168+ addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
169+ err = get_user(br2, (unsigned int *)addr);
170+ err |= get_user(ldq, (unsigned int *)(addr+4));
171+ err |= get_user(nop, (unsigned int *)(addr+8));
172+ err |= get_user(jmp, (unsigned int *)(addr+12));
173+ err |= get_user(resolver, (unsigned long *)(addr+16));
174+
175+ if (err)
176+ break;
177+
178+ if (br2 == 0xC3600000U &&
179+ ldq == 0xA77B000CU &&
180+ nop == 0x47FF041FU &&
181+ jmp == 0x6B7B0000U)
182+ {
183+ regs->r28 = regs->pc+4;
184+ regs->r27 = addr+16;
185+ regs->pc = resolver;
186+ return 3;
187+ }
188+ }
189+ } while (0);
190+#endif
191+
192+ return 1;
193+}
194+
195+void pax_report_insns(void *pc, void *sp)
196+{
197+ unsigned long i;
198+
199+ printk(KERN_ERR "PAX: bytes at PC: ");
200+ for (i = 0; i < 5; i++) {
201+ unsigned int c;
202+ if (get_user(c, (unsigned int *)pc+i))
203+ printk(KERN_CONT "???????? ");
204+ else
205+ printk(KERN_CONT "%08x ", c);
206+ }
207+ printk("\n");
208+}
209+#endif
210
211 /*
212 * This routine handles page faults. It determines the address,
213@@ -131,8 +249,29 @@ do_page_fault(unsigned long address, uns
214 good_area:
215 si_code = SEGV_ACCERR;
216 if (cause < 0) {
217- if (!(vma->vm_flags & VM_EXEC))
218+ if (!(vma->vm_flags & VM_EXEC)) {
219+
220+#ifdef CONFIG_PAX_PAGEEXEC
221+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
222+ goto bad_area;
223+
224+ up_read(&mm->mmap_sem);
225+ switch (pax_handle_fetch_fault(regs)) {
226+
227+#ifdef CONFIG_PAX_EMUPLT
228+ case 2:
229+ case 3:
230+ return;
231+#endif
232+
233+ }
234+ pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
235+ do_group_exit(SIGKILL);
236+#else
237 goto bad_area;
238+#endif
239+
240+ }
241 } else if (!cause) {
242 /* Allow reads even for write-only mappings */
243 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
244diff -urNp linux-2.6.32.41/arch/arm/include/asm/elf.h linux-2.6.32.41/arch/arm/include/asm/elf.h
245--- linux-2.6.32.41/arch/arm/include/asm/elf.h 2011-03-27 14:31:47.000000000 -0400
246+++ linux-2.6.32.41/arch/arm/include/asm/elf.h 2011-04-17 15:56:45.000000000 -0400
247@@ -109,7 +109,14 @@ int dump_task_regs(struct task_struct *t
248 the loader. We need to make sure that it is out of the way of the program
249 that it will "exec", and that there is sufficient room for the brk. */
250
251-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
252+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
253+
254+#ifdef CONFIG_PAX_ASLR
255+#define PAX_ELF_ET_DYN_BASE 0x00008000UL
256+
257+#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
258+#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
259+#endif
260
261 /* When the program starts, a1 contains a pointer to a function to be
262 registered with atexit, as per the SVR4 ABI. A value of 0 means we
263diff -urNp linux-2.6.32.41/arch/arm/include/asm/kmap_types.h linux-2.6.32.41/arch/arm/include/asm/kmap_types.h
264--- linux-2.6.32.41/arch/arm/include/asm/kmap_types.h 2011-03-27 14:31:47.000000000 -0400
265+++ linux-2.6.32.41/arch/arm/include/asm/kmap_types.h 2011-04-17 15:56:45.000000000 -0400
266@@ -19,6 +19,7 @@ enum km_type {
267 KM_SOFTIRQ0,
268 KM_SOFTIRQ1,
269 KM_L2_CACHE,
270+ KM_CLEARPAGE,
271 KM_TYPE_NR
272 };
273
274diff -urNp linux-2.6.32.41/arch/arm/include/asm/uaccess.h linux-2.6.32.41/arch/arm/include/asm/uaccess.h
275--- linux-2.6.32.41/arch/arm/include/asm/uaccess.h 2011-03-27 14:31:47.000000000 -0400
276+++ linux-2.6.32.41/arch/arm/include/asm/uaccess.h 2011-04-17 15:56:45.000000000 -0400
277@@ -403,6 +403,9 @@ extern unsigned long __must_check __strn
278
279 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
280 {
281+ if ((long)n < 0)
282+ return n;
283+
284 if (access_ok(VERIFY_READ, from, n))
285 n = __copy_from_user(to, from, n);
286 else /* security hole - plug it */
287@@ -412,6 +415,9 @@ static inline unsigned long __must_check
288
289 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
290 {
291+ if ((long)n < 0)
292+ return n;
293+
294 if (access_ok(VERIFY_WRITE, to, n))
295 n = __copy_to_user(to, from, n);
296 return n;
297diff -urNp linux-2.6.32.41/arch/arm/kernel/kgdb.c linux-2.6.32.41/arch/arm/kernel/kgdb.c
298--- linux-2.6.32.41/arch/arm/kernel/kgdb.c 2011-03-27 14:31:47.000000000 -0400
299+++ linux-2.6.32.41/arch/arm/kernel/kgdb.c 2011-04-17 15:56:45.000000000 -0400
300@@ -190,7 +190,7 @@ void kgdb_arch_exit(void)
301 * and we handle the normal undef case within the do_undefinstr
302 * handler.
303 */
304-struct kgdb_arch arch_kgdb_ops = {
305+const struct kgdb_arch arch_kgdb_ops = {
306 #ifndef __ARMEB__
307 .gdb_bpt_instr = {0xfe, 0xde, 0xff, 0xe7}
308 #else /* ! __ARMEB__ */
309diff -urNp linux-2.6.32.41/arch/arm/mach-at91/pm.c linux-2.6.32.41/arch/arm/mach-at91/pm.c
310--- linux-2.6.32.41/arch/arm/mach-at91/pm.c 2011-03-27 14:31:47.000000000 -0400
311+++ linux-2.6.32.41/arch/arm/mach-at91/pm.c 2011-04-17 15:56:45.000000000 -0400
312@@ -348,7 +348,7 @@ static void at91_pm_end(void)
313 }
314
315
316-static struct platform_suspend_ops at91_pm_ops ={
317+static const struct platform_suspend_ops at91_pm_ops ={
318 .valid = at91_pm_valid_state,
319 .begin = at91_pm_begin,
320 .enter = at91_pm_enter,
321diff -urNp linux-2.6.32.41/arch/arm/mach-omap1/pm.c linux-2.6.32.41/arch/arm/mach-omap1/pm.c
322--- linux-2.6.32.41/arch/arm/mach-omap1/pm.c 2011-03-27 14:31:47.000000000 -0400
323+++ linux-2.6.32.41/arch/arm/mach-omap1/pm.c 2011-04-17 15:56:45.000000000 -0400
324@@ -647,7 +647,7 @@ static struct irqaction omap_wakeup_irq
325
326
327
328-static struct platform_suspend_ops omap_pm_ops ={
329+static const struct platform_suspend_ops omap_pm_ops ={
330 .prepare = omap_pm_prepare,
331 .enter = omap_pm_enter,
332 .finish = omap_pm_finish,
333diff -urNp linux-2.6.32.41/arch/arm/mach-omap2/pm24xx.c linux-2.6.32.41/arch/arm/mach-omap2/pm24xx.c
334--- linux-2.6.32.41/arch/arm/mach-omap2/pm24xx.c 2011-03-27 14:31:47.000000000 -0400
335+++ linux-2.6.32.41/arch/arm/mach-omap2/pm24xx.c 2011-04-17 15:56:45.000000000 -0400
336@@ -326,7 +326,7 @@ static void omap2_pm_finish(void)
337 enable_hlt();
338 }
339
340-static struct platform_suspend_ops omap_pm_ops = {
341+static const struct platform_suspend_ops omap_pm_ops = {
342 .prepare = omap2_pm_prepare,
343 .enter = omap2_pm_enter,
344 .finish = omap2_pm_finish,
345diff -urNp linux-2.6.32.41/arch/arm/mach-omap2/pm34xx.c linux-2.6.32.41/arch/arm/mach-omap2/pm34xx.c
346--- linux-2.6.32.41/arch/arm/mach-omap2/pm34xx.c 2011-03-27 14:31:47.000000000 -0400
347+++ linux-2.6.32.41/arch/arm/mach-omap2/pm34xx.c 2011-04-17 15:56:45.000000000 -0400
348@@ -401,7 +401,7 @@ static void omap3_pm_end(void)
349 return;
350 }
351
352-static struct platform_suspend_ops omap_pm_ops = {
353+static const struct platform_suspend_ops omap_pm_ops = {
354 .begin = omap3_pm_begin,
355 .end = omap3_pm_end,
356 .prepare = omap3_pm_prepare,
357diff -urNp linux-2.6.32.41/arch/arm/mach-pnx4008/pm.c linux-2.6.32.41/arch/arm/mach-pnx4008/pm.c
358--- linux-2.6.32.41/arch/arm/mach-pnx4008/pm.c 2011-03-27 14:31:47.000000000 -0400
359+++ linux-2.6.32.41/arch/arm/mach-pnx4008/pm.c 2011-04-17 15:56:45.000000000 -0400
360@@ -116,7 +116,7 @@ static int pnx4008_pm_valid(suspend_stat
361 (state == PM_SUSPEND_MEM);
362 }
363
364-static struct platform_suspend_ops pnx4008_pm_ops = {
365+static const struct platform_suspend_ops pnx4008_pm_ops = {
366 .enter = pnx4008_pm_enter,
367 .valid = pnx4008_pm_valid,
368 };
369diff -urNp linux-2.6.32.41/arch/arm/mach-pxa/pm.c linux-2.6.32.41/arch/arm/mach-pxa/pm.c
370--- linux-2.6.32.41/arch/arm/mach-pxa/pm.c 2011-03-27 14:31:47.000000000 -0400
371+++ linux-2.6.32.41/arch/arm/mach-pxa/pm.c 2011-04-17 15:56:45.000000000 -0400
372@@ -95,7 +95,7 @@ void pxa_pm_finish(void)
373 pxa_cpu_pm_fns->finish();
374 }
375
376-static struct platform_suspend_ops pxa_pm_ops = {
377+static const struct platform_suspend_ops pxa_pm_ops = {
378 .valid = pxa_pm_valid,
379 .enter = pxa_pm_enter,
380 .prepare = pxa_pm_prepare,
381diff -urNp linux-2.6.32.41/arch/arm/mach-pxa/sharpsl_pm.c linux-2.6.32.41/arch/arm/mach-pxa/sharpsl_pm.c
382--- linux-2.6.32.41/arch/arm/mach-pxa/sharpsl_pm.c 2011-03-27 14:31:47.000000000 -0400
383+++ linux-2.6.32.41/arch/arm/mach-pxa/sharpsl_pm.c 2011-04-17 15:56:45.000000000 -0400
384@@ -891,7 +891,7 @@ static void sharpsl_apm_get_power_status
385 }
386
387 #ifdef CONFIG_PM
388-static struct platform_suspend_ops sharpsl_pm_ops = {
389+static const struct platform_suspend_ops sharpsl_pm_ops = {
390 .prepare = pxa_pm_prepare,
391 .finish = pxa_pm_finish,
392 .enter = corgi_pxa_pm_enter,
393diff -urNp linux-2.6.32.41/arch/arm/mach-sa1100/pm.c linux-2.6.32.41/arch/arm/mach-sa1100/pm.c
394--- linux-2.6.32.41/arch/arm/mach-sa1100/pm.c 2011-03-27 14:31:47.000000000 -0400
395+++ linux-2.6.32.41/arch/arm/mach-sa1100/pm.c 2011-04-17 15:56:45.000000000 -0400
396@@ -120,7 +120,7 @@ unsigned long sleep_phys_sp(void *sp)
397 return virt_to_phys(sp);
398 }
399
400-static struct platform_suspend_ops sa11x0_pm_ops = {
401+static const struct platform_suspend_ops sa11x0_pm_ops = {
402 .enter = sa11x0_pm_enter,
403 .valid = suspend_valid_only_mem,
404 };
405diff -urNp linux-2.6.32.41/arch/arm/mm/fault.c linux-2.6.32.41/arch/arm/mm/fault.c
406--- linux-2.6.32.41/arch/arm/mm/fault.c 2011-03-27 14:31:47.000000000 -0400
407+++ linux-2.6.32.41/arch/arm/mm/fault.c 2011-04-17 15:56:45.000000000 -0400
408@@ -166,6 +166,13 @@ __do_user_fault(struct task_struct *tsk,
409 }
410 #endif
411
412+#ifdef CONFIG_PAX_PAGEEXEC
413+ if (fsr & FSR_LNX_PF) {
414+ pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
415+ do_group_exit(SIGKILL);
416+ }
417+#endif
418+
419 tsk->thread.address = addr;
420 tsk->thread.error_code = fsr;
421 tsk->thread.trap_no = 14;
422@@ -357,6 +364,33 @@ do_page_fault(unsigned long addr, unsign
423 }
424 #endif /* CONFIG_MMU */
425
426+#ifdef CONFIG_PAX_PAGEEXEC
427+void pax_report_insns(void *pc, void *sp)
428+{
429+ long i;
430+
431+ printk(KERN_ERR "PAX: bytes at PC: ");
432+ for (i = 0; i < 20; i++) {
433+ unsigned char c;
434+ if (get_user(c, (__force unsigned char __user *)pc+i))
435+ printk(KERN_CONT "?? ");
436+ else
437+ printk(KERN_CONT "%02x ", c);
438+ }
439+ printk("\n");
440+
441+ printk(KERN_ERR "PAX: bytes at SP-4: ");
442+ for (i = -1; i < 20; i++) {
443+ unsigned long c;
444+ if (get_user(c, (__force unsigned long __user *)sp+i))
445+ printk(KERN_CONT "???????? ");
446+ else
447+ printk(KERN_CONT "%08lx ", c);
448+ }
449+ printk("\n");
450+}
451+#endif
452+
453 /*
454 * First Level Translation Fault Handler
455 *
456diff -urNp linux-2.6.32.41/arch/arm/mm/mmap.c linux-2.6.32.41/arch/arm/mm/mmap.c
457--- linux-2.6.32.41/arch/arm/mm/mmap.c 2011-03-27 14:31:47.000000000 -0400
458+++ linux-2.6.32.41/arch/arm/mm/mmap.c 2011-04-17 15:56:45.000000000 -0400
459@@ -63,6 +63,10 @@ arch_get_unmapped_area(struct file *filp
460 if (len > TASK_SIZE)
461 return -ENOMEM;
462
463+#ifdef CONFIG_PAX_RANDMMAP
464+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
465+#endif
466+
467 if (addr) {
468 if (do_align)
469 addr = COLOUR_ALIGN(addr, pgoff);
470@@ -70,15 +74,14 @@ arch_get_unmapped_area(struct file *filp
471 addr = PAGE_ALIGN(addr);
472
473 vma = find_vma(mm, addr);
474- if (TASK_SIZE - len >= addr &&
475- (!vma || addr + len <= vma->vm_start))
476+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
477 return addr;
478 }
479 if (len > mm->cached_hole_size) {
480- start_addr = addr = mm->free_area_cache;
481+ start_addr = addr = mm->free_area_cache;
482 } else {
483- start_addr = addr = TASK_UNMAPPED_BASE;
484- mm->cached_hole_size = 0;
485+ start_addr = addr = mm->mmap_base;
486+ mm->cached_hole_size = 0;
487 }
488
489 full_search:
490@@ -94,14 +97,14 @@ full_search:
491 * Start a new search - just in case we missed
492 * some holes.
493 */
494- if (start_addr != TASK_UNMAPPED_BASE) {
495- start_addr = addr = TASK_UNMAPPED_BASE;
496+ if (start_addr != mm->mmap_base) {
497+ start_addr = addr = mm->mmap_base;
498 mm->cached_hole_size = 0;
499 goto full_search;
500 }
501 return -ENOMEM;
502 }
503- if (!vma || addr + len <= vma->vm_start) {
504+ if (check_heap_stack_gap(vma, addr, len)) {
505 /*
506 * Remember the place where we stopped the search:
507 */
508diff -urNp linux-2.6.32.41/arch/arm/plat-s3c/pm.c linux-2.6.32.41/arch/arm/plat-s3c/pm.c
509--- linux-2.6.32.41/arch/arm/plat-s3c/pm.c 2011-03-27 14:31:47.000000000 -0400
510+++ linux-2.6.32.41/arch/arm/plat-s3c/pm.c 2011-04-17 15:56:45.000000000 -0400
511@@ -355,7 +355,7 @@ static void s3c_pm_finish(void)
512 s3c_pm_check_cleanup();
513 }
514
515-static struct platform_suspend_ops s3c_pm_ops = {
516+static const struct platform_suspend_ops s3c_pm_ops = {
517 .enter = s3c_pm_enter,
518 .prepare = s3c_pm_prepare,
519 .finish = s3c_pm_finish,
520diff -urNp linux-2.6.32.41/arch/avr32/include/asm/elf.h linux-2.6.32.41/arch/avr32/include/asm/elf.h
521--- linux-2.6.32.41/arch/avr32/include/asm/elf.h 2011-03-27 14:31:47.000000000 -0400
522+++ linux-2.6.32.41/arch/avr32/include/asm/elf.h 2011-04-17 15:56:45.000000000 -0400
523@@ -85,8 +85,14 @@ typedef struct user_fpu_struct elf_fpreg
524 the loader. We need to make sure that it is out of the way of the program
525 that it will "exec", and that there is sufficient room for the brk. */
526
527-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
528+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
529
530+#ifdef CONFIG_PAX_ASLR
531+#define PAX_ELF_ET_DYN_BASE 0x00001000UL
532+
533+#define PAX_DELTA_MMAP_LEN 15
534+#define PAX_DELTA_STACK_LEN 15
535+#endif
536
537 /* This yields a mask that user programs can use to figure out what
538 instruction set this CPU supports. This could be done in user space,
539diff -urNp linux-2.6.32.41/arch/avr32/include/asm/kmap_types.h linux-2.6.32.41/arch/avr32/include/asm/kmap_types.h
540--- linux-2.6.32.41/arch/avr32/include/asm/kmap_types.h 2011-03-27 14:31:47.000000000 -0400
541+++ linux-2.6.32.41/arch/avr32/include/asm/kmap_types.h 2011-04-17 15:56:45.000000000 -0400
542@@ -22,7 +22,8 @@ D(10) KM_IRQ0,
543 D(11) KM_IRQ1,
544 D(12) KM_SOFTIRQ0,
545 D(13) KM_SOFTIRQ1,
546-D(14) KM_TYPE_NR
547+D(14) KM_CLEARPAGE,
548+D(15) KM_TYPE_NR
549 };
550
551 #undef D
552diff -urNp linux-2.6.32.41/arch/avr32/mach-at32ap/pm.c linux-2.6.32.41/arch/avr32/mach-at32ap/pm.c
553--- linux-2.6.32.41/arch/avr32/mach-at32ap/pm.c 2011-03-27 14:31:47.000000000 -0400
554+++ linux-2.6.32.41/arch/avr32/mach-at32ap/pm.c 2011-04-17 15:56:45.000000000 -0400
555@@ -176,7 +176,7 @@ out:
556 return 0;
557 }
558
559-static struct platform_suspend_ops avr32_pm_ops = {
560+static const struct platform_suspend_ops avr32_pm_ops = {
561 .valid = avr32_pm_valid_state,
562 .enter = avr32_pm_enter,
563 };
564diff -urNp linux-2.6.32.41/arch/avr32/mm/fault.c linux-2.6.32.41/arch/avr32/mm/fault.c
565--- linux-2.6.32.41/arch/avr32/mm/fault.c 2011-03-27 14:31:47.000000000 -0400
566+++ linux-2.6.32.41/arch/avr32/mm/fault.c 2011-04-17 15:56:45.000000000 -0400
567@@ -41,6 +41,23 @@ static inline int notify_page_fault(stru
568
569 int exception_trace = 1;
570
571+#ifdef CONFIG_PAX_PAGEEXEC
572+void pax_report_insns(void *pc, void *sp)
573+{
574+ unsigned long i;
575+
576+ printk(KERN_ERR "PAX: bytes at PC: ");
577+ for (i = 0; i < 20; i++) {
578+ unsigned char c;
579+ if (get_user(c, (unsigned char *)pc+i))
580+ printk(KERN_CONT "???????? ");
581+ else
582+ printk(KERN_CONT "%02x ", c);
583+ }
584+ printk("\n");
585+}
586+#endif
587+
588 /*
589 * This routine handles page faults. It determines the address and the
590 * problem, and then passes it off to one of the appropriate routines.
591@@ -157,6 +174,16 @@ bad_area:
592 up_read(&mm->mmap_sem);
593
594 if (user_mode(regs)) {
595+
596+#ifdef CONFIG_PAX_PAGEEXEC
597+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
598+ if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
599+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
600+ do_group_exit(SIGKILL);
601+ }
602+ }
603+#endif
604+
605 if (exception_trace && printk_ratelimit())
606 printk("%s%s[%d]: segfault at %08lx pc %08lx "
607 "sp %08lx ecr %lu\n",
608diff -urNp linux-2.6.32.41/arch/blackfin/kernel/kgdb.c linux-2.6.32.41/arch/blackfin/kernel/kgdb.c
609--- linux-2.6.32.41/arch/blackfin/kernel/kgdb.c 2011-03-27 14:31:47.000000000 -0400
610+++ linux-2.6.32.41/arch/blackfin/kernel/kgdb.c 2011-04-17 15:56:45.000000000 -0400
611@@ -428,7 +428,7 @@ int kgdb_arch_handle_exception(int vecto
612 return -1; /* this means that we do not want to exit from the handler */
613 }
614
615-struct kgdb_arch arch_kgdb_ops = {
616+const struct kgdb_arch arch_kgdb_ops = {
617 .gdb_bpt_instr = {0xa1},
618 #ifdef CONFIG_SMP
619 .flags = KGDB_HW_BREAKPOINT|KGDB_THR_PROC_SWAP,
620diff -urNp linux-2.6.32.41/arch/blackfin/mach-common/pm.c linux-2.6.32.41/arch/blackfin/mach-common/pm.c
621--- linux-2.6.32.41/arch/blackfin/mach-common/pm.c 2011-03-27 14:31:47.000000000 -0400
622+++ linux-2.6.32.41/arch/blackfin/mach-common/pm.c 2011-04-17 15:56:45.000000000 -0400
623@@ -255,7 +255,7 @@ static int bfin_pm_enter(suspend_state_t
624 return 0;
625 }
626
627-struct platform_suspend_ops bfin_pm_ops = {
628+const struct platform_suspend_ops bfin_pm_ops = {
629 .enter = bfin_pm_enter,
630 .valid = bfin_pm_valid,
631 };
632diff -urNp linux-2.6.32.41/arch/frv/include/asm/kmap_types.h linux-2.6.32.41/arch/frv/include/asm/kmap_types.h
633--- linux-2.6.32.41/arch/frv/include/asm/kmap_types.h 2011-03-27 14:31:47.000000000 -0400
634+++ linux-2.6.32.41/arch/frv/include/asm/kmap_types.h 2011-04-17 15:56:45.000000000 -0400
635@@ -23,6 +23,7 @@ enum km_type {
636 KM_IRQ1,
637 KM_SOFTIRQ0,
638 KM_SOFTIRQ1,
639+ KM_CLEARPAGE,
640 KM_TYPE_NR
641 };
642
643diff -urNp linux-2.6.32.41/arch/frv/mm/elf-fdpic.c linux-2.6.32.41/arch/frv/mm/elf-fdpic.c
644--- linux-2.6.32.41/arch/frv/mm/elf-fdpic.c 2011-03-27 14:31:47.000000000 -0400
645+++ linux-2.6.32.41/arch/frv/mm/elf-fdpic.c 2011-04-17 15:56:45.000000000 -0400
646@@ -73,8 +73,7 @@ unsigned long arch_get_unmapped_area(str
647 if (addr) {
648 addr = PAGE_ALIGN(addr);
649 vma = find_vma(current->mm, addr);
650- if (TASK_SIZE - len >= addr &&
651- (!vma || addr + len <= vma->vm_start))
652+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
653 goto success;
654 }
655
656@@ -89,7 +88,7 @@ unsigned long arch_get_unmapped_area(str
657 for (; vma; vma = vma->vm_next) {
658 if (addr > limit)
659 break;
660- if (addr + len <= vma->vm_start)
661+ if (check_heap_stack_gap(vma, addr, len))
662 goto success;
663 addr = vma->vm_end;
664 }
665@@ -104,7 +103,7 @@ unsigned long arch_get_unmapped_area(str
666 for (; vma; vma = vma->vm_next) {
667 if (addr > limit)
668 break;
669- if (addr + len <= vma->vm_start)
670+ if (check_heap_stack_gap(vma, addr, len))
671 goto success;
672 addr = vma->vm_end;
673 }
674diff -urNp linux-2.6.32.41/arch/ia64/hp/common/hwsw_iommu.c linux-2.6.32.41/arch/ia64/hp/common/hwsw_iommu.c
675--- linux-2.6.32.41/arch/ia64/hp/common/hwsw_iommu.c 2011-03-27 14:31:47.000000000 -0400
676+++ linux-2.6.32.41/arch/ia64/hp/common/hwsw_iommu.c 2011-04-17 15:56:45.000000000 -0400
677@@ -17,7 +17,7 @@
678 #include <linux/swiotlb.h>
679 #include <asm/machvec.h>
680
681-extern struct dma_map_ops sba_dma_ops, swiotlb_dma_ops;
682+extern const struct dma_map_ops sba_dma_ops, swiotlb_dma_ops;
683
684 /* swiotlb declarations & definitions: */
685 extern int swiotlb_late_init_with_default_size (size_t size);
686@@ -33,7 +33,7 @@ static inline int use_swiotlb(struct dev
687 !sba_dma_ops.dma_supported(dev, *dev->dma_mask);
688 }
689
690-struct dma_map_ops *hwsw_dma_get_ops(struct device *dev)
691+const struct dma_map_ops *hwsw_dma_get_ops(struct device *dev)
692 {
693 if (use_swiotlb(dev))
694 return &swiotlb_dma_ops;
695diff -urNp linux-2.6.32.41/arch/ia64/hp/common/sba_iommu.c linux-2.6.32.41/arch/ia64/hp/common/sba_iommu.c
696--- linux-2.6.32.41/arch/ia64/hp/common/sba_iommu.c 2011-03-27 14:31:47.000000000 -0400
697+++ linux-2.6.32.41/arch/ia64/hp/common/sba_iommu.c 2011-04-17 15:56:45.000000000 -0400
698@@ -2097,7 +2097,7 @@ static struct acpi_driver acpi_sba_ioc_d
699 },
700 };
701
702-extern struct dma_map_ops swiotlb_dma_ops;
703+extern const struct dma_map_ops swiotlb_dma_ops;
704
705 static int __init
706 sba_init(void)
707@@ -2211,7 +2211,7 @@ sba_page_override(char *str)
708
709 __setup("sbapagesize=",sba_page_override);
710
711-struct dma_map_ops sba_dma_ops = {
712+const struct dma_map_ops sba_dma_ops = {
713 .alloc_coherent = sba_alloc_coherent,
714 .free_coherent = sba_free_coherent,
715 .map_page = sba_map_page,
716diff -urNp linux-2.6.32.41/arch/ia64/ia32/binfmt_elf32.c linux-2.6.32.41/arch/ia64/ia32/binfmt_elf32.c
717--- linux-2.6.32.41/arch/ia64/ia32/binfmt_elf32.c 2011-03-27 14:31:47.000000000 -0400
718+++ linux-2.6.32.41/arch/ia64/ia32/binfmt_elf32.c 2011-04-17 15:56:45.000000000 -0400
719@@ -45,6 +45,13 @@ randomize_stack_top(unsigned long stack_
720
721 #define elf_read_implies_exec(ex, have_pt_gnu_stack) (!(have_pt_gnu_stack))
722
723+#ifdef CONFIG_PAX_ASLR
724+#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
725+
726+#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
727+#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
728+#endif
729+
730 /* Ugly but avoids duplication */
731 #include "../../../fs/binfmt_elf.c"
732
733diff -urNp linux-2.6.32.41/arch/ia64/ia32/ia32priv.h linux-2.6.32.41/arch/ia64/ia32/ia32priv.h
734--- linux-2.6.32.41/arch/ia64/ia32/ia32priv.h 2011-03-27 14:31:47.000000000 -0400
735+++ linux-2.6.32.41/arch/ia64/ia32/ia32priv.h 2011-04-17 15:56:45.000000000 -0400
736@@ -296,7 +296,14 @@ typedef struct compat_siginfo {
737 #define ELF_DATA ELFDATA2LSB
738 #define ELF_ARCH EM_386
739
740-#define IA32_STACK_TOP IA32_PAGE_OFFSET
741+#ifdef CONFIG_PAX_RANDUSTACK
742+#define __IA32_DELTA_STACK (current->mm->delta_stack)
743+#else
744+#define __IA32_DELTA_STACK 0UL
745+#endif
746+
747+#define IA32_STACK_TOP (IA32_PAGE_OFFSET - __IA32_DELTA_STACK)
748+
749 #define IA32_GATE_OFFSET IA32_PAGE_OFFSET
750 #define IA32_GATE_END IA32_PAGE_OFFSET + PAGE_SIZE
751
752diff -urNp linux-2.6.32.41/arch/ia64/include/asm/dma-mapping.h linux-2.6.32.41/arch/ia64/include/asm/dma-mapping.h
753--- linux-2.6.32.41/arch/ia64/include/asm/dma-mapping.h 2011-03-27 14:31:47.000000000 -0400
754+++ linux-2.6.32.41/arch/ia64/include/asm/dma-mapping.h 2011-04-17 15:56:45.000000000 -0400
755@@ -12,7 +12,7 @@
756
757 #define ARCH_HAS_DMA_GET_REQUIRED_MASK
758
759-extern struct dma_map_ops *dma_ops;
760+extern const struct dma_map_ops *dma_ops;
761 extern struct ia64_machine_vector ia64_mv;
762 extern void set_iommu_machvec(void);
763
764@@ -24,7 +24,7 @@ extern void machvec_dma_sync_sg(struct d
765 static inline void *dma_alloc_coherent(struct device *dev, size_t size,
766 dma_addr_t *daddr, gfp_t gfp)
767 {
768- struct dma_map_ops *ops = platform_dma_get_ops(dev);
769+ const struct dma_map_ops *ops = platform_dma_get_ops(dev);
770 void *caddr;
771
772 caddr = ops->alloc_coherent(dev, size, daddr, gfp);
773@@ -35,7 +35,7 @@ static inline void *dma_alloc_coherent(s
774 static inline void dma_free_coherent(struct device *dev, size_t size,
775 void *caddr, dma_addr_t daddr)
776 {
777- struct dma_map_ops *ops = platform_dma_get_ops(dev);
778+ const struct dma_map_ops *ops = platform_dma_get_ops(dev);
779 debug_dma_free_coherent(dev, size, caddr, daddr);
780 ops->free_coherent(dev, size, caddr, daddr);
781 }
782@@ -49,13 +49,13 @@ static inline void dma_free_coherent(str
783
784 static inline int dma_mapping_error(struct device *dev, dma_addr_t daddr)
785 {
786- struct dma_map_ops *ops = platform_dma_get_ops(dev);
787+ const struct dma_map_ops *ops = platform_dma_get_ops(dev);
788 return ops->mapping_error(dev, daddr);
789 }
790
791 static inline int dma_supported(struct device *dev, u64 mask)
792 {
793- struct dma_map_ops *ops = platform_dma_get_ops(dev);
794+ const struct dma_map_ops *ops = platform_dma_get_ops(dev);
795 return ops->dma_supported(dev, mask);
796 }
797
798diff -urNp linux-2.6.32.41/arch/ia64/include/asm/elf.h linux-2.6.32.41/arch/ia64/include/asm/elf.h
799--- linux-2.6.32.41/arch/ia64/include/asm/elf.h 2011-03-27 14:31:47.000000000 -0400
800+++ linux-2.6.32.41/arch/ia64/include/asm/elf.h 2011-04-17 15:56:45.000000000 -0400
801@@ -43,6 +43,13 @@
802 */
803 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
804
805+#ifdef CONFIG_PAX_ASLR
806+#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
807+
808+#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
809+#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
810+#endif
811+
812 #define PT_IA_64_UNWIND 0x70000001
813
814 /* IA-64 relocations: */
815diff -urNp linux-2.6.32.41/arch/ia64/include/asm/machvec.h linux-2.6.32.41/arch/ia64/include/asm/machvec.h
816--- linux-2.6.32.41/arch/ia64/include/asm/machvec.h 2011-03-27 14:31:47.000000000 -0400
817+++ linux-2.6.32.41/arch/ia64/include/asm/machvec.h 2011-04-17 15:56:45.000000000 -0400
818@@ -45,7 +45,7 @@ typedef void ia64_mv_kernel_launch_event
819 /* DMA-mapping interface: */
820 typedef void ia64_mv_dma_init (void);
821 typedef u64 ia64_mv_dma_get_required_mask (struct device *);
822-typedef struct dma_map_ops *ia64_mv_dma_get_ops(struct device *);
823+typedef const struct dma_map_ops *ia64_mv_dma_get_ops(struct device *);
824
825 /*
826 * WARNING: The legacy I/O space is _architected_. Platforms are
827@@ -251,7 +251,7 @@ extern void machvec_init_from_cmdline(co
828 # endif /* CONFIG_IA64_GENERIC */
829
830 extern void swiotlb_dma_init(void);
831-extern struct dma_map_ops *dma_get_ops(struct device *);
832+extern const struct dma_map_ops *dma_get_ops(struct device *);
833
834 /*
835 * Define default versions so we can extend machvec for new platforms without having
836diff -urNp linux-2.6.32.41/arch/ia64/include/asm/pgtable.h linux-2.6.32.41/arch/ia64/include/asm/pgtable.h
837--- linux-2.6.32.41/arch/ia64/include/asm/pgtable.h 2011-03-27 14:31:47.000000000 -0400
838+++ linux-2.6.32.41/arch/ia64/include/asm/pgtable.h 2011-04-17 15:56:45.000000000 -0400
839@@ -12,7 +12,7 @@
840 * David Mosberger-Tang <davidm@hpl.hp.com>
841 */
842
843-
844+#include <linux/const.h>
845 #include <asm/mman.h>
846 #include <asm/page.h>
847 #include <asm/processor.h>
848@@ -143,6 +143,17 @@
849 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
850 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
851 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
852+
853+#ifdef CONFIG_PAX_PAGEEXEC
854+# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
855+# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
856+# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
857+#else
858+# define PAGE_SHARED_NOEXEC PAGE_SHARED
859+# define PAGE_READONLY_NOEXEC PAGE_READONLY
860+# define PAGE_COPY_NOEXEC PAGE_COPY
861+#endif
862+
863 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
864 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
865 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
866diff -urNp linux-2.6.32.41/arch/ia64/include/asm/spinlock.h linux-2.6.32.41/arch/ia64/include/asm/spinlock.h
867--- linux-2.6.32.41/arch/ia64/include/asm/spinlock.h 2011-03-27 14:31:47.000000000 -0400
868+++ linux-2.6.32.41/arch/ia64/include/asm/spinlock.h 2011-04-17 15:56:45.000000000 -0400
869@@ -72,7 +72,7 @@ static __always_inline void __ticket_spi
870 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
871
872 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
873- ACCESS_ONCE(*p) = (tmp + 2) & ~1;
874+ ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
875 }
876
877 static __always_inline void __ticket_spin_unlock_wait(raw_spinlock_t *lock)
878diff -urNp linux-2.6.32.41/arch/ia64/include/asm/uaccess.h linux-2.6.32.41/arch/ia64/include/asm/uaccess.h
879--- linux-2.6.32.41/arch/ia64/include/asm/uaccess.h 2011-03-27 14:31:47.000000000 -0400
880+++ linux-2.6.32.41/arch/ia64/include/asm/uaccess.h 2011-04-17 15:56:45.000000000 -0400
881@@ -257,7 +257,7 @@ __copy_from_user (void *to, const void _
882 const void *__cu_from = (from); \
883 long __cu_len = (n); \
884 \
885- if (__access_ok(__cu_to, __cu_len, get_fs())) \
886+ if (__cu_len > 0 && __cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) \
887 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
888 __cu_len; \
889 })
890@@ -269,7 +269,7 @@ __copy_from_user (void *to, const void _
891 long __cu_len = (n); \
892 \
893 __chk_user_ptr(__cu_from); \
894- if (__access_ok(__cu_from, __cu_len, get_fs())) \
895+ if (__cu_len > 0 && __cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) \
896 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
897 __cu_len; \
898 })
899diff -urNp linux-2.6.32.41/arch/ia64/kernel/dma-mapping.c linux-2.6.32.41/arch/ia64/kernel/dma-mapping.c
900--- linux-2.6.32.41/arch/ia64/kernel/dma-mapping.c 2011-03-27 14:31:47.000000000 -0400
901+++ linux-2.6.32.41/arch/ia64/kernel/dma-mapping.c 2011-04-17 15:56:45.000000000 -0400
902@@ -3,7 +3,7 @@
903 /* Set this to 1 if there is a HW IOMMU in the system */
904 int iommu_detected __read_mostly;
905
906-struct dma_map_ops *dma_ops;
907+const struct dma_map_ops *dma_ops;
908 EXPORT_SYMBOL(dma_ops);
909
910 #define PREALLOC_DMA_DEBUG_ENTRIES (1 << 16)
911@@ -16,7 +16,7 @@ static int __init dma_init(void)
912 }
913 fs_initcall(dma_init);
914
915-struct dma_map_ops *dma_get_ops(struct device *dev)
916+const struct dma_map_ops *dma_get_ops(struct device *dev)
917 {
918 return dma_ops;
919 }
920diff -urNp linux-2.6.32.41/arch/ia64/kernel/module.c linux-2.6.32.41/arch/ia64/kernel/module.c
921--- linux-2.6.32.41/arch/ia64/kernel/module.c 2011-03-27 14:31:47.000000000 -0400
922+++ linux-2.6.32.41/arch/ia64/kernel/module.c 2011-04-17 15:56:45.000000000 -0400
923@@ -315,8 +315,7 @@ module_alloc (unsigned long size)
924 void
925 module_free (struct module *mod, void *module_region)
926 {
927- if (mod && mod->arch.init_unw_table &&
928- module_region == mod->module_init) {
929+ if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
930 unw_remove_unwind_table(mod->arch.init_unw_table);
931 mod->arch.init_unw_table = NULL;
932 }
933@@ -502,15 +501,39 @@ module_frob_arch_sections (Elf_Ehdr *ehd
934 }
935
936 static inline int
937+in_init_rx (const struct module *mod, uint64_t addr)
938+{
939+ return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
940+}
941+
942+static inline int
943+in_init_rw (const struct module *mod, uint64_t addr)
944+{
945+ return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
946+}
947+
948+static inline int
949 in_init (const struct module *mod, uint64_t addr)
950 {
951- return addr - (uint64_t) mod->module_init < mod->init_size;
952+ return in_init_rx(mod, addr) || in_init_rw(mod, addr);
953+}
954+
955+static inline int
956+in_core_rx (const struct module *mod, uint64_t addr)
957+{
958+ return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
959+}
960+
961+static inline int
962+in_core_rw (const struct module *mod, uint64_t addr)
963+{
964+ return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
965 }
966
967 static inline int
968 in_core (const struct module *mod, uint64_t addr)
969 {
970- return addr - (uint64_t) mod->module_core < mod->core_size;
971+ return in_core_rx(mod, addr) || in_core_rw(mod, addr);
972 }
973
974 static inline int
975@@ -693,7 +716,14 @@ do_reloc (struct module *mod, uint8_t r_
976 break;
977
978 case RV_BDREL:
979- val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
980+ if (in_init_rx(mod, val))
981+ val -= (uint64_t) mod->module_init_rx;
982+ else if (in_init_rw(mod, val))
983+ val -= (uint64_t) mod->module_init_rw;
984+ else if (in_core_rx(mod, val))
985+ val -= (uint64_t) mod->module_core_rx;
986+ else if (in_core_rw(mod, val))
987+ val -= (uint64_t) mod->module_core_rw;
988 break;
989
990 case RV_LTV:
991@@ -828,15 +858,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs,
992 * addresses have been selected...
993 */
994 uint64_t gp;
995- if (mod->core_size > MAX_LTOFF)
996+ if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
997 /*
998 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
999 * at the end of the module.
1000 */
1001- gp = mod->core_size - MAX_LTOFF / 2;
1002+ gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
1003 else
1004- gp = mod->core_size / 2;
1005- gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
1006+ gp = (mod->core_size_rx + mod->core_size_rw) / 2;
1007+ gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
1008 mod->arch.gp = gp;
1009 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
1010 }
1011diff -urNp linux-2.6.32.41/arch/ia64/kernel/pci-dma.c linux-2.6.32.41/arch/ia64/kernel/pci-dma.c
1012--- linux-2.6.32.41/arch/ia64/kernel/pci-dma.c 2011-03-27 14:31:47.000000000 -0400
1013+++ linux-2.6.32.41/arch/ia64/kernel/pci-dma.c 2011-04-17 15:56:45.000000000 -0400
1014@@ -43,7 +43,7 @@ struct device fallback_dev = {
1015 .dma_mask = &fallback_dev.coherent_dma_mask,
1016 };
1017
1018-extern struct dma_map_ops intel_dma_ops;
1019+extern const struct dma_map_ops intel_dma_ops;
1020
1021 static int __init pci_iommu_init(void)
1022 {
1023@@ -96,15 +96,34 @@ int iommu_dma_supported(struct device *d
1024 }
1025 EXPORT_SYMBOL(iommu_dma_supported);
1026
1027+extern void *intel_alloc_coherent(struct device *hwdev, size_t size, dma_addr_t *dma_handle, gfp_t flags);
1028+extern void intel_free_coherent(struct device *hwdev, size_t size, void *vaddr, dma_addr_t dma_handle);
1029+extern int intel_map_sg(struct device *hwdev, struct scatterlist *sglist, int nelems, enum dma_data_direction dir, struct dma_attrs *attrs);
1030+extern void intel_unmap_sg(struct device *hwdev, struct scatterlist *sglist, int nelems, enum dma_data_direction dir, struct dma_attrs *attrs);
1031+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);
1032+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);
1033+extern int intel_mapping_error(struct device *dev, dma_addr_t dma_addr);
1034+
1035+static const struct dma_map_ops intel_iommu_dma_ops = {
1036+ /* from drivers/pci/intel-iommu.c:intel_dma_ops */
1037+ .alloc_coherent = intel_alloc_coherent,
1038+ .free_coherent = intel_free_coherent,
1039+ .map_sg = intel_map_sg,
1040+ .unmap_sg = intel_unmap_sg,
1041+ .map_page = intel_map_page,
1042+ .unmap_page = intel_unmap_page,
1043+ .mapping_error = intel_mapping_error,
1044+
1045+ .sync_single_for_cpu = machvec_dma_sync_single,
1046+ .sync_sg_for_cpu = machvec_dma_sync_sg,
1047+ .sync_single_for_device = machvec_dma_sync_single,
1048+ .sync_sg_for_device = machvec_dma_sync_sg,
1049+ .dma_supported = iommu_dma_supported,
1050+};
1051+
1052 void __init pci_iommu_alloc(void)
1053 {
1054- dma_ops = &intel_dma_ops;
1055-
1056- dma_ops->sync_single_for_cpu = machvec_dma_sync_single;
1057- dma_ops->sync_sg_for_cpu = machvec_dma_sync_sg;
1058- dma_ops->sync_single_for_device = machvec_dma_sync_single;
1059- dma_ops->sync_sg_for_device = machvec_dma_sync_sg;
1060- dma_ops->dma_supported = iommu_dma_supported;
1061+ dma_ops = &intel_iommu_dma_ops;
1062
1063 /*
1064 * The order of these functions is important for
1065diff -urNp linux-2.6.32.41/arch/ia64/kernel/pci-swiotlb.c linux-2.6.32.41/arch/ia64/kernel/pci-swiotlb.c
1066--- linux-2.6.32.41/arch/ia64/kernel/pci-swiotlb.c 2011-03-27 14:31:47.000000000 -0400
1067+++ linux-2.6.32.41/arch/ia64/kernel/pci-swiotlb.c 2011-04-17 15:56:45.000000000 -0400
1068@@ -21,7 +21,7 @@ static void *ia64_swiotlb_alloc_coherent
1069 return swiotlb_alloc_coherent(dev, size, dma_handle, gfp);
1070 }
1071
1072-struct dma_map_ops swiotlb_dma_ops = {
1073+const struct dma_map_ops swiotlb_dma_ops = {
1074 .alloc_coherent = ia64_swiotlb_alloc_coherent,
1075 .free_coherent = swiotlb_free_coherent,
1076 .map_page = swiotlb_map_page,
1077diff -urNp linux-2.6.32.41/arch/ia64/kernel/sys_ia64.c linux-2.6.32.41/arch/ia64/kernel/sys_ia64.c
1078--- linux-2.6.32.41/arch/ia64/kernel/sys_ia64.c 2011-03-27 14:31:47.000000000 -0400
1079+++ linux-2.6.32.41/arch/ia64/kernel/sys_ia64.c 2011-04-17 15:56:45.000000000 -0400
1080@@ -43,6 +43,13 @@ arch_get_unmapped_area (struct file *fil
1081 if (REGION_NUMBER(addr) == RGN_HPAGE)
1082 addr = 0;
1083 #endif
1084+
1085+#ifdef CONFIG_PAX_RANDMMAP
1086+ if (mm->pax_flags & MF_PAX_RANDMMAP)
1087+ addr = mm->free_area_cache;
1088+ else
1089+#endif
1090+
1091 if (!addr)
1092 addr = mm->free_area_cache;
1093
1094@@ -61,14 +68,14 @@ arch_get_unmapped_area (struct file *fil
1095 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
1096 /* At this point: (!vma || addr < vma->vm_end). */
1097 if (TASK_SIZE - len < addr || RGN_MAP_LIMIT - len < REGION_OFFSET(addr)) {
1098- if (start_addr != TASK_UNMAPPED_BASE) {
1099+ if (start_addr != mm->mmap_base) {
1100 /* Start a new search --- just in case we missed some holes. */
1101- addr = TASK_UNMAPPED_BASE;
1102+ addr = mm->mmap_base;
1103 goto full_search;
1104 }
1105 return -ENOMEM;
1106 }
1107- if (!vma || addr + len <= vma->vm_start) {
1108+ if (check_heap_stack_gap(vma, addr, len)) {
1109 /* Remember the address where we stopped this search: */
1110 mm->free_area_cache = addr + len;
1111 return addr;
1112diff -urNp linux-2.6.32.41/arch/ia64/kernel/topology.c linux-2.6.32.41/arch/ia64/kernel/topology.c
1113--- linux-2.6.32.41/arch/ia64/kernel/topology.c 2011-03-27 14:31:47.000000000 -0400
1114+++ linux-2.6.32.41/arch/ia64/kernel/topology.c 2011-04-17 15:56:45.000000000 -0400
1115@@ -282,7 +282,7 @@ static ssize_t cache_show(struct kobject
1116 return ret;
1117 }
1118
1119-static struct sysfs_ops cache_sysfs_ops = {
1120+static const struct sysfs_ops cache_sysfs_ops = {
1121 .show = cache_show
1122 };
1123
1124diff -urNp linux-2.6.32.41/arch/ia64/kernel/vmlinux.lds.S linux-2.6.32.41/arch/ia64/kernel/vmlinux.lds.S
1125--- linux-2.6.32.41/arch/ia64/kernel/vmlinux.lds.S 2011-03-27 14:31:47.000000000 -0400
1126+++ linux-2.6.32.41/arch/ia64/kernel/vmlinux.lds.S 2011-04-17 15:56:45.000000000 -0400
1127@@ -190,7 +190,7 @@ SECTIONS
1128 /* Per-cpu data: */
1129 . = ALIGN(PERCPU_PAGE_SIZE);
1130 PERCPU_VADDR(PERCPU_ADDR, :percpu)
1131- __phys_per_cpu_start = __per_cpu_load;
1132+ __phys_per_cpu_start = per_cpu_load;
1133 . = __phys_per_cpu_start + PERCPU_PAGE_SIZE; /* ensure percpu data fits
1134 * into percpu page size
1135 */
1136diff -urNp linux-2.6.32.41/arch/ia64/mm/fault.c linux-2.6.32.41/arch/ia64/mm/fault.c
1137--- linux-2.6.32.41/arch/ia64/mm/fault.c 2011-03-27 14:31:47.000000000 -0400
1138+++ linux-2.6.32.41/arch/ia64/mm/fault.c 2011-04-17 15:56:45.000000000 -0400
1139@@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned
1140 return pte_present(pte);
1141 }
1142
1143+#ifdef CONFIG_PAX_PAGEEXEC
1144+void pax_report_insns(void *pc, void *sp)
1145+{
1146+ unsigned long i;
1147+
1148+ printk(KERN_ERR "PAX: bytes at PC: ");
1149+ for (i = 0; i < 8; i++) {
1150+ unsigned int c;
1151+ if (get_user(c, (unsigned int *)pc+i))
1152+ printk(KERN_CONT "???????? ");
1153+ else
1154+ printk(KERN_CONT "%08x ", c);
1155+ }
1156+ printk("\n");
1157+}
1158+#endif
1159+
1160 void __kprobes
1161 ia64_do_page_fault (unsigned long address, unsigned long isr, struct pt_regs *regs)
1162 {
1163@@ -145,9 +162,23 @@ ia64_do_page_fault (unsigned long addres
1164 mask = ( (((isr >> IA64_ISR_X_BIT) & 1UL) << VM_EXEC_BIT)
1165 | (((isr >> IA64_ISR_W_BIT) & 1UL) << VM_WRITE_BIT));
1166
1167- if ((vma->vm_flags & mask) != mask)
1168+ if ((vma->vm_flags & mask) != mask) {
1169+
1170+#ifdef CONFIG_PAX_PAGEEXEC
1171+ if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
1172+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
1173+ goto bad_area;
1174+
1175+ up_read(&mm->mmap_sem);
1176+ pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
1177+ do_group_exit(SIGKILL);
1178+ }
1179+#endif
1180+
1181 goto bad_area;
1182
1183+ }
1184+
1185 survive:
1186 /*
1187 * If for any reason at all we couldn't handle the fault, make
1188diff -urNp linux-2.6.32.41/arch/ia64/mm/hugetlbpage.c linux-2.6.32.41/arch/ia64/mm/hugetlbpage.c
1189--- linux-2.6.32.41/arch/ia64/mm/hugetlbpage.c 2011-03-27 14:31:47.000000000 -0400
1190+++ linux-2.6.32.41/arch/ia64/mm/hugetlbpage.c 2011-04-17 15:56:45.000000000 -0400
1191@@ -172,7 +172,7 @@ unsigned long hugetlb_get_unmapped_area(
1192 /* At this point: (!vmm || addr < vmm->vm_end). */
1193 if (REGION_OFFSET(addr) + len > RGN_MAP_LIMIT)
1194 return -ENOMEM;
1195- if (!vmm || (addr + len) <= vmm->vm_start)
1196+ if (check_heap_stack_gap(vmm, addr, len))
1197 return addr;
1198 addr = ALIGN(vmm->vm_end, HPAGE_SIZE);
1199 }
1200diff -urNp linux-2.6.32.41/arch/ia64/mm/init.c linux-2.6.32.41/arch/ia64/mm/init.c
1201--- linux-2.6.32.41/arch/ia64/mm/init.c 2011-03-27 14:31:47.000000000 -0400
1202+++ linux-2.6.32.41/arch/ia64/mm/init.c 2011-04-17 15:56:45.000000000 -0400
1203@@ -122,6 +122,19 @@ ia64_init_addr_space (void)
1204 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
1205 vma->vm_end = vma->vm_start + PAGE_SIZE;
1206 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
1207+
1208+#ifdef CONFIG_PAX_PAGEEXEC
1209+ if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
1210+ vma->vm_flags &= ~VM_EXEC;
1211+
1212+#ifdef CONFIG_PAX_MPROTECT
1213+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
1214+ vma->vm_flags &= ~VM_MAYEXEC;
1215+#endif
1216+
1217+ }
1218+#endif
1219+
1220 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
1221 down_write(&current->mm->mmap_sem);
1222 if (insert_vm_struct(current->mm, vma)) {
1223diff -urNp linux-2.6.32.41/arch/ia64/sn/pci/pci_dma.c linux-2.6.32.41/arch/ia64/sn/pci/pci_dma.c
1224--- linux-2.6.32.41/arch/ia64/sn/pci/pci_dma.c 2011-03-27 14:31:47.000000000 -0400
1225+++ linux-2.6.32.41/arch/ia64/sn/pci/pci_dma.c 2011-04-17 15:56:45.000000000 -0400
1226@@ -464,7 +464,7 @@ int sn_pci_legacy_write(struct pci_bus *
1227 return ret;
1228 }
1229
1230-static struct dma_map_ops sn_dma_ops = {
1231+static const struct dma_map_ops sn_dma_ops = {
1232 .alloc_coherent = sn_dma_alloc_coherent,
1233 .free_coherent = sn_dma_free_coherent,
1234 .map_page = sn_dma_map_page,
1235diff -urNp linux-2.6.32.41/arch/m32r/lib/usercopy.c linux-2.6.32.41/arch/m32r/lib/usercopy.c
1236--- linux-2.6.32.41/arch/m32r/lib/usercopy.c 2011-03-27 14:31:47.000000000 -0400
1237+++ linux-2.6.32.41/arch/m32r/lib/usercopy.c 2011-04-17 15:56:45.000000000 -0400
1238@@ -14,6 +14,9 @@
1239 unsigned long
1240 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
1241 {
1242+ if ((long)n < 0)
1243+ return n;
1244+
1245 prefetch(from);
1246 if (access_ok(VERIFY_WRITE, to, n))
1247 __copy_user(to,from,n);
1248@@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to,
1249 unsigned long
1250 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
1251 {
1252+ if ((long)n < 0)
1253+ return n;
1254+
1255 prefetchw(to);
1256 if (access_ok(VERIFY_READ, from, n))
1257 __copy_user_zeroing(to,from,n);
1258diff -urNp linux-2.6.32.41/arch/mips/alchemy/devboards/pm.c linux-2.6.32.41/arch/mips/alchemy/devboards/pm.c
1259--- linux-2.6.32.41/arch/mips/alchemy/devboards/pm.c 2011-03-27 14:31:47.000000000 -0400
1260+++ linux-2.6.32.41/arch/mips/alchemy/devboards/pm.c 2011-04-17 15:56:45.000000000 -0400
1261@@ -78,7 +78,7 @@ static void db1x_pm_end(void)
1262
1263 }
1264
1265-static struct platform_suspend_ops db1x_pm_ops = {
1266+static const struct platform_suspend_ops db1x_pm_ops = {
1267 .valid = suspend_valid_only_mem,
1268 .begin = db1x_pm_begin,
1269 .enter = db1x_pm_enter,
1270diff -urNp linux-2.6.32.41/arch/mips/include/asm/elf.h linux-2.6.32.41/arch/mips/include/asm/elf.h
1271--- linux-2.6.32.41/arch/mips/include/asm/elf.h 2011-03-27 14:31:47.000000000 -0400
1272+++ linux-2.6.32.41/arch/mips/include/asm/elf.h 2011-04-17 15:56:45.000000000 -0400
1273@@ -368,4 +368,11 @@ extern int dump_task_fpu(struct task_str
1274 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1275 #endif
1276
1277+#ifdef CONFIG_PAX_ASLR
1278+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT_ADDR) ? 0x00400000UL : 0x00400000UL)
1279+
1280+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT_ADDR) ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
1281+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT_ADDR) ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
1282+#endif
1283+
1284 #endif /* _ASM_ELF_H */
1285diff -urNp linux-2.6.32.41/arch/mips/include/asm/page.h linux-2.6.32.41/arch/mips/include/asm/page.h
1286--- linux-2.6.32.41/arch/mips/include/asm/page.h 2011-03-27 14:31:47.000000000 -0400
1287+++ linux-2.6.32.41/arch/mips/include/asm/page.h 2011-04-17 15:56:45.000000000 -0400
1288@@ -93,7 +93,7 @@ extern void copy_user_highpage(struct pa
1289 #ifdef CONFIG_CPU_MIPS32
1290 typedef struct { unsigned long pte_low, pte_high; } pte_t;
1291 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
1292- #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
1293+ #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
1294 #else
1295 typedef struct { unsigned long long pte; } pte_t;
1296 #define pte_val(x) ((x).pte)
1297diff -urNp linux-2.6.32.41/arch/mips/include/asm/system.h linux-2.6.32.41/arch/mips/include/asm/system.h
1298--- linux-2.6.32.41/arch/mips/include/asm/system.h 2011-03-27 14:31:47.000000000 -0400
1299+++ linux-2.6.32.41/arch/mips/include/asm/system.h 2011-04-17 15:56:45.000000000 -0400
1300@@ -230,6 +230,6 @@ extern void per_cpu_trap_init(void);
1301 */
1302 #define __ARCH_WANT_UNLOCKED_CTXSW
1303
1304-extern unsigned long arch_align_stack(unsigned long sp);
1305+#define arch_align_stack(x) ((x) & ~0xfUL)
1306
1307 #endif /* _ASM_SYSTEM_H */
1308diff -urNp linux-2.6.32.41/arch/mips/kernel/binfmt_elfn32.c linux-2.6.32.41/arch/mips/kernel/binfmt_elfn32.c
1309--- linux-2.6.32.41/arch/mips/kernel/binfmt_elfn32.c 2011-03-27 14:31:47.000000000 -0400
1310+++ linux-2.6.32.41/arch/mips/kernel/binfmt_elfn32.c 2011-04-17 15:56:45.000000000 -0400
1311@@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_N
1312 #undef ELF_ET_DYN_BASE
1313 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
1314
1315+#ifdef CONFIG_PAX_ASLR
1316+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT_ADDR) ? 0x00400000UL : 0x00400000UL)
1317+
1318+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT_ADDR) ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
1319+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT_ADDR) ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
1320+#endif
1321+
1322 #include <asm/processor.h>
1323 #include <linux/module.h>
1324 #include <linux/elfcore.h>
1325diff -urNp linux-2.6.32.41/arch/mips/kernel/binfmt_elfo32.c linux-2.6.32.41/arch/mips/kernel/binfmt_elfo32.c
1326--- linux-2.6.32.41/arch/mips/kernel/binfmt_elfo32.c 2011-03-27 14:31:47.000000000 -0400
1327+++ linux-2.6.32.41/arch/mips/kernel/binfmt_elfo32.c 2011-04-17 15:56:45.000000000 -0400
1328@@ -52,6 +52,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_N
1329 #undef ELF_ET_DYN_BASE
1330 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
1331
1332+#ifdef CONFIG_PAX_ASLR
1333+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT_ADDR) ? 0x00400000UL : 0x00400000UL)
1334+
1335+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT_ADDR) ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
1336+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT_ADDR) ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
1337+#endif
1338+
1339 #include <asm/processor.h>
1340
1341 /*
1342diff -urNp linux-2.6.32.41/arch/mips/kernel/kgdb.c linux-2.6.32.41/arch/mips/kernel/kgdb.c
1343--- linux-2.6.32.41/arch/mips/kernel/kgdb.c 2011-03-27 14:31:47.000000000 -0400
1344+++ linux-2.6.32.41/arch/mips/kernel/kgdb.c 2011-04-17 15:56:45.000000000 -0400
1345@@ -245,6 +245,7 @@ int kgdb_arch_handle_exception(int vecto
1346 return -1;
1347 }
1348
1349+/* cannot be const */
1350 struct kgdb_arch arch_kgdb_ops;
1351
1352 /*
1353diff -urNp linux-2.6.32.41/arch/mips/kernel/process.c linux-2.6.32.41/arch/mips/kernel/process.c
1354--- linux-2.6.32.41/arch/mips/kernel/process.c 2011-03-27 14:31:47.000000000 -0400
1355+++ linux-2.6.32.41/arch/mips/kernel/process.c 2011-04-17 15:56:45.000000000 -0400
1356@@ -470,15 +470,3 @@ unsigned long get_wchan(struct task_stru
1357 out:
1358 return pc;
1359 }
1360-
1361-/*
1362- * Don't forget that the stack pointer must be aligned on a 8 bytes
1363- * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
1364- */
1365-unsigned long arch_align_stack(unsigned long sp)
1366-{
1367- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
1368- sp -= get_random_int() & ~PAGE_MASK;
1369-
1370- return sp & ALMASK;
1371-}
1372diff -urNp linux-2.6.32.41/arch/mips/kernel/syscall.c linux-2.6.32.41/arch/mips/kernel/syscall.c
1373--- linux-2.6.32.41/arch/mips/kernel/syscall.c 2011-03-27 14:31:47.000000000 -0400
1374+++ linux-2.6.32.41/arch/mips/kernel/syscall.c 2011-04-17 15:56:45.000000000 -0400
1375@@ -102,17 +102,21 @@ unsigned long arch_get_unmapped_area(str
1376 do_color_align = 0;
1377 if (filp || (flags & MAP_SHARED))
1378 do_color_align = 1;
1379+
1380+#ifdef CONFIG_PAX_RANDMMAP
1381+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
1382+#endif
1383+
1384 if (addr) {
1385 if (do_color_align)
1386 addr = COLOUR_ALIGN(addr, pgoff);
1387 else
1388 addr = PAGE_ALIGN(addr);
1389 vmm = find_vma(current->mm, addr);
1390- if (task_size - len >= addr &&
1391- (!vmm || addr + len <= vmm->vm_start))
1392+ if (task_size - len >= addr && check_heap_stack_gap(vmm, addr, len))
1393 return addr;
1394 }
1395- addr = TASK_UNMAPPED_BASE;
1396+ addr = current->mm->mmap_base;
1397 if (do_color_align)
1398 addr = COLOUR_ALIGN(addr, pgoff);
1399 else
1400@@ -122,7 +126,7 @@ unsigned long arch_get_unmapped_area(str
1401 /* At this point: (!vmm || addr < vmm->vm_end). */
1402 if (task_size - len < addr)
1403 return -ENOMEM;
1404- if (!vmm || addr + len <= vmm->vm_start)
1405+ if (check_heap_stack_gap(vmm, addr, len))
1406 return addr;
1407 addr = vmm->vm_end;
1408 if (do_color_align)
1409diff -urNp linux-2.6.32.41/arch/mips/mm/fault.c linux-2.6.32.41/arch/mips/mm/fault.c
1410--- linux-2.6.32.41/arch/mips/mm/fault.c 2011-03-27 14:31:47.000000000 -0400
1411+++ linux-2.6.32.41/arch/mips/mm/fault.c 2011-04-17 15:56:45.000000000 -0400
1412@@ -26,6 +26,23 @@
1413 #include <asm/ptrace.h>
1414 #include <asm/highmem.h> /* For VMALLOC_END */
1415
1416+#ifdef CONFIG_PAX_PAGEEXEC
1417+void pax_report_insns(void *pc, void *sp)
1418+{
1419+ unsigned long i;
1420+
1421+ printk(KERN_ERR "PAX: bytes at PC: ");
1422+ for (i = 0; i < 5; i++) {
1423+ unsigned int c;
1424+ if (get_user(c, (unsigned int *)pc+i))
1425+ printk(KERN_CONT "???????? ");
1426+ else
1427+ printk(KERN_CONT "%08x ", c);
1428+ }
1429+ printk("\n");
1430+}
1431+#endif
1432+
1433 /*
1434 * This routine handles page faults. It determines the address,
1435 * and the problem, and then passes it off to one of the appropriate
1436diff -urNp linux-2.6.32.41/arch/parisc/include/asm/elf.h linux-2.6.32.41/arch/parisc/include/asm/elf.h
1437--- linux-2.6.32.41/arch/parisc/include/asm/elf.h 2011-03-27 14:31:47.000000000 -0400
1438+++ linux-2.6.32.41/arch/parisc/include/asm/elf.h 2011-04-17 15:56:45.000000000 -0400
1439@@ -343,6 +343,13 @@ struct pt_regs; /* forward declaration..
1440
1441 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
1442
1443+#ifdef CONFIG_PAX_ASLR
1444+#define PAX_ELF_ET_DYN_BASE 0x10000UL
1445+
1446+#define PAX_DELTA_MMAP_LEN 16
1447+#define PAX_DELTA_STACK_LEN 16
1448+#endif
1449+
1450 /* This yields a mask that user programs can use to figure out what
1451 instruction set this CPU supports. This could be done in user space,
1452 but it's not easy, and we've already done it here. */
1453diff -urNp linux-2.6.32.41/arch/parisc/include/asm/pgtable.h linux-2.6.32.41/arch/parisc/include/asm/pgtable.h
1454--- linux-2.6.32.41/arch/parisc/include/asm/pgtable.h 2011-03-27 14:31:47.000000000 -0400
1455+++ linux-2.6.32.41/arch/parisc/include/asm/pgtable.h 2011-04-17 15:56:45.000000000 -0400
1456@@ -207,6 +207,17 @@
1457 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
1458 #define PAGE_COPY PAGE_EXECREAD
1459 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
1460+
1461+#ifdef CONFIG_PAX_PAGEEXEC
1462+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
1463+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
1464+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
1465+#else
1466+# define PAGE_SHARED_NOEXEC PAGE_SHARED
1467+# define PAGE_COPY_NOEXEC PAGE_COPY
1468+# define PAGE_READONLY_NOEXEC PAGE_READONLY
1469+#endif
1470+
1471 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
1472 #define PAGE_KERNEL_RO __pgprot(_PAGE_KERNEL & ~_PAGE_WRITE)
1473 #define PAGE_KERNEL_UNC __pgprot(_PAGE_KERNEL | _PAGE_NO_CACHE)
1474diff -urNp linux-2.6.32.41/arch/parisc/kernel/module.c linux-2.6.32.41/arch/parisc/kernel/module.c
1475--- linux-2.6.32.41/arch/parisc/kernel/module.c 2011-03-27 14:31:47.000000000 -0400
1476+++ linux-2.6.32.41/arch/parisc/kernel/module.c 2011-04-17 15:56:45.000000000 -0400
1477@@ -95,16 +95,38 @@
1478
1479 /* three functions to determine where in the module core
1480 * or init pieces the location is */
1481+static inline int in_init_rx(struct module *me, void *loc)
1482+{
1483+ return (loc >= me->module_init_rx &&
1484+ loc < (me->module_init_rx + me->init_size_rx));
1485+}
1486+
1487+static inline int in_init_rw(struct module *me, void *loc)
1488+{
1489+ return (loc >= me->module_init_rw &&
1490+ loc < (me->module_init_rw + me->init_size_rw));
1491+}
1492+
1493 static inline int in_init(struct module *me, void *loc)
1494 {
1495- return (loc >= me->module_init &&
1496- loc <= (me->module_init + me->init_size));
1497+ return in_init_rx(me, loc) || in_init_rw(me, loc);
1498+}
1499+
1500+static inline int in_core_rx(struct module *me, void *loc)
1501+{
1502+ return (loc >= me->module_core_rx &&
1503+ loc < (me->module_core_rx + me->core_size_rx));
1504+}
1505+
1506+static inline int in_core_rw(struct module *me, void *loc)
1507+{
1508+ return (loc >= me->module_core_rw &&
1509+ loc < (me->module_core_rw + me->core_size_rw));
1510 }
1511
1512 static inline int in_core(struct module *me, void *loc)
1513 {
1514- return (loc >= me->module_core &&
1515- loc <= (me->module_core + me->core_size));
1516+ return in_core_rx(me, loc) || in_core_rw(me, loc);
1517 }
1518
1519 static inline int in_local(struct module *me, void *loc)
1520@@ -364,13 +386,13 @@ int module_frob_arch_sections(CONST Elf_
1521 }
1522
1523 /* align things a bit */
1524- me->core_size = ALIGN(me->core_size, 16);
1525- me->arch.got_offset = me->core_size;
1526- me->core_size += gots * sizeof(struct got_entry);
1527-
1528- me->core_size = ALIGN(me->core_size, 16);
1529- me->arch.fdesc_offset = me->core_size;
1530- me->core_size += fdescs * sizeof(Elf_Fdesc);
1531+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
1532+ me->arch.got_offset = me->core_size_rw;
1533+ me->core_size_rw += gots * sizeof(struct got_entry);
1534+
1535+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
1536+ me->arch.fdesc_offset = me->core_size_rw;
1537+ me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
1538
1539 me->arch.got_max = gots;
1540 me->arch.fdesc_max = fdescs;
1541@@ -388,7 +410,7 @@ static Elf64_Word get_got(struct module
1542
1543 BUG_ON(value == 0);
1544
1545- got = me->module_core + me->arch.got_offset;
1546+ got = me->module_core_rw + me->arch.got_offset;
1547 for (i = 0; got[i].addr; i++)
1548 if (got[i].addr == value)
1549 goto out;
1550@@ -406,7 +428,7 @@ static Elf64_Word get_got(struct module
1551 #ifdef CONFIG_64BIT
1552 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
1553 {
1554- Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
1555+ Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
1556
1557 if (!value) {
1558 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
1559@@ -424,7 +446,7 @@ static Elf_Addr get_fdesc(struct module
1560
1561 /* Create new one */
1562 fdesc->addr = value;
1563- fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
1564+ fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
1565 return (Elf_Addr)fdesc;
1566 }
1567 #endif /* CONFIG_64BIT */
1568@@ -848,7 +870,7 @@ register_unwind_table(struct module *me,
1569
1570 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
1571 end = table + sechdrs[me->arch.unwind_section].sh_size;
1572- gp = (Elf_Addr)me->module_core + me->arch.got_offset;
1573+ gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
1574
1575 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
1576 me->arch.unwind_section, table, end, gp);
1577diff -urNp linux-2.6.32.41/arch/parisc/kernel/sys_parisc.c linux-2.6.32.41/arch/parisc/kernel/sys_parisc.c
1578--- linux-2.6.32.41/arch/parisc/kernel/sys_parisc.c 2011-03-27 14:31:47.000000000 -0400
1579+++ linux-2.6.32.41/arch/parisc/kernel/sys_parisc.c 2011-04-17 15:56:45.000000000 -0400
1580@@ -43,7 +43,7 @@ static unsigned long get_unshared_area(u
1581 /* At this point: (!vma || addr < vma->vm_end). */
1582 if (TASK_SIZE - len < addr)
1583 return -ENOMEM;
1584- if (!vma || addr + len <= vma->vm_start)
1585+ if (check_heap_stack_gap(vma, addr, len))
1586 return addr;
1587 addr = vma->vm_end;
1588 }
1589@@ -79,7 +79,7 @@ static unsigned long get_shared_area(str
1590 /* At this point: (!vma || addr < vma->vm_end). */
1591 if (TASK_SIZE - len < addr)
1592 return -ENOMEM;
1593- if (!vma || addr + len <= vma->vm_start)
1594+ if (check_heap_stack_gap(vma, addr, len))
1595 return addr;
1596 addr = DCACHE_ALIGN(vma->vm_end - offset) + offset;
1597 if (addr < vma->vm_end) /* handle wraparound */
1598@@ -98,7 +98,7 @@ unsigned long arch_get_unmapped_area(str
1599 if (flags & MAP_FIXED)
1600 return addr;
1601 if (!addr)
1602- addr = TASK_UNMAPPED_BASE;
1603+ addr = current->mm->mmap_base;
1604
1605 if (filp) {
1606 addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
1607diff -urNp linux-2.6.32.41/arch/parisc/kernel/traps.c linux-2.6.32.41/arch/parisc/kernel/traps.c
1608--- linux-2.6.32.41/arch/parisc/kernel/traps.c 2011-03-27 14:31:47.000000000 -0400
1609+++ linux-2.6.32.41/arch/parisc/kernel/traps.c 2011-04-17 15:56:45.000000000 -0400
1610@@ -733,9 +733,7 @@ void notrace handle_interruption(int cod
1611
1612 down_read(&current->mm->mmap_sem);
1613 vma = find_vma(current->mm,regs->iaoq[0]);
1614- if (vma && (regs->iaoq[0] >= vma->vm_start)
1615- && (vma->vm_flags & VM_EXEC)) {
1616-
1617+ if (vma && (regs->iaoq[0] >= vma->vm_start)) {
1618 fault_address = regs->iaoq[0];
1619 fault_space = regs->iasq[0];
1620
1621diff -urNp linux-2.6.32.41/arch/parisc/mm/fault.c linux-2.6.32.41/arch/parisc/mm/fault.c
1622--- linux-2.6.32.41/arch/parisc/mm/fault.c 2011-03-27 14:31:47.000000000 -0400
1623+++ linux-2.6.32.41/arch/parisc/mm/fault.c 2011-04-17 15:56:45.000000000 -0400
1624@@ -15,6 +15,7 @@
1625 #include <linux/sched.h>
1626 #include <linux/interrupt.h>
1627 #include <linux/module.h>
1628+#include <linux/unistd.h>
1629
1630 #include <asm/uaccess.h>
1631 #include <asm/traps.h>
1632@@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, ex
1633 static unsigned long
1634 parisc_acctyp(unsigned long code, unsigned int inst)
1635 {
1636- if (code == 6 || code == 16)
1637+ if (code == 6 || code == 7 || code == 16)
1638 return VM_EXEC;
1639
1640 switch (inst & 0xf0000000) {
1641@@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsign
1642 }
1643 #endif
1644
1645+#ifdef CONFIG_PAX_PAGEEXEC
1646+/*
1647+ * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
1648+ *
1649+ * returns 1 when task should be killed
1650+ * 2 when rt_sigreturn trampoline was detected
1651+ * 3 when unpatched PLT trampoline was detected
1652+ */
1653+static int pax_handle_fetch_fault(struct pt_regs *regs)
1654+{
1655+
1656+#ifdef CONFIG_PAX_EMUPLT
1657+ int err;
1658+
1659+ do { /* PaX: unpatched PLT emulation */
1660+ unsigned int bl, depwi;
1661+
1662+ err = get_user(bl, (unsigned int *)instruction_pointer(regs));
1663+ err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
1664+
1665+ if (err)
1666+ break;
1667+
1668+ if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
1669+ unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
1670+
1671+ err = get_user(ldw, (unsigned int *)addr);
1672+ err |= get_user(bv, (unsigned int *)(addr+4));
1673+ err |= get_user(ldw2, (unsigned int *)(addr+8));
1674+
1675+ if (err)
1676+ break;
1677+
1678+ if (ldw == 0x0E801096U &&
1679+ bv == 0xEAC0C000U &&
1680+ ldw2 == 0x0E881095U)
1681+ {
1682+ unsigned int resolver, map;
1683+
1684+ err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
1685+ err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
1686+ if (err)
1687+ break;
1688+
1689+ regs->gr[20] = instruction_pointer(regs)+8;
1690+ regs->gr[21] = map;
1691+ regs->gr[22] = resolver;
1692+ regs->iaoq[0] = resolver | 3UL;
1693+ regs->iaoq[1] = regs->iaoq[0] + 4;
1694+ return 3;
1695+ }
1696+ }
1697+ } while (0);
1698+#endif
1699+
1700+#ifdef CONFIG_PAX_EMUTRAMP
1701+
1702+#ifndef CONFIG_PAX_EMUSIGRT
1703+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
1704+ return 1;
1705+#endif
1706+
1707+ do { /* PaX: rt_sigreturn emulation */
1708+ unsigned int ldi1, ldi2, bel, nop;
1709+
1710+ err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
1711+ err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
1712+ err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
1713+ err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
1714+
1715+ if (err)
1716+ break;
1717+
1718+ if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
1719+ ldi2 == 0x3414015AU &&
1720+ bel == 0xE4008200U &&
1721+ nop == 0x08000240U)
1722+ {
1723+ regs->gr[25] = (ldi1 & 2) >> 1;
1724+ regs->gr[20] = __NR_rt_sigreturn;
1725+ regs->gr[31] = regs->iaoq[1] + 16;
1726+ regs->sr[0] = regs->iasq[1];
1727+ regs->iaoq[0] = 0x100UL;
1728+ regs->iaoq[1] = regs->iaoq[0] + 4;
1729+ regs->iasq[0] = regs->sr[2];
1730+ regs->iasq[1] = regs->sr[2];
1731+ return 2;
1732+ }
1733+ } while (0);
1734+#endif
1735+
1736+ return 1;
1737+}
1738+
1739+void pax_report_insns(void *pc, void *sp)
1740+{
1741+ unsigned long i;
1742+
1743+ printk(KERN_ERR "PAX: bytes at PC: ");
1744+ for (i = 0; i < 5; i++) {
1745+ unsigned int c;
1746+ if (get_user(c, (unsigned int *)pc+i))
1747+ printk(KERN_CONT "???????? ");
1748+ else
1749+ printk(KERN_CONT "%08x ", c);
1750+ }
1751+ printk("\n");
1752+}
1753+#endif
1754+
1755 int fixup_exception(struct pt_regs *regs)
1756 {
1757 const struct exception_table_entry *fix;
1758@@ -192,8 +303,33 @@ good_area:
1759
1760 acc_type = parisc_acctyp(code,regs->iir);
1761
1762- if ((vma->vm_flags & acc_type) != acc_type)
1763+ if ((vma->vm_flags & acc_type) != acc_type) {
1764+
1765+#ifdef CONFIG_PAX_PAGEEXEC
1766+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
1767+ (address & ~3UL) == instruction_pointer(regs))
1768+ {
1769+ up_read(&mm->mmap_sem);
1770+ switch (pax_handle_fetch_fault(regs)) {
1771+
1772+#ifdef CONFIG_PAX_EMUPLT
1773+ case 3:
1774+ return;
1775+#endif
1776+
1777+#ifdef CONFIG_PAX_EMUTRAMP
1778+ case 2:
1779+ return;
1780+#endif
1781+
1782+ }
1783+ pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
1784+ do_group_exit(SIGKILL);
1785+ }
1786+#endif
1787+
1788 goto bad_area;
1789+ }
1790
1791 /*
1792 * If for any reason at all we couldn't handle the fault, make
1793diff -urNp linux-2.6.32.41/arch/powerpc/include/asm/device.h linux-2.6.32.41/arch/powerpc/include/asm/device.h
1794--- linux-2.6.32.41/arch/powerpc/include/asm/device.h 2011-03-27 14:31:47.000000000 -0400
1795+++ linux-2.6.32.41/arch/powerpc/include/asm/device.h 2011-04-17 15:56:45.000000000 -0400
1796@@ -14,7 +14,7 @@ struct dev_archdata {
1797 struct device_node *of_node;
1798
1799 /* DMA operations on that device */
1800- struct dma_map_ops *dma_ops;
1801+ const struct dma_map_ops *dma_ops;
1802
1803 /*
1804 * When an iommu is in use, dma_data is used as a ptr to the base of the
1805diff -urNp linux-2.6.32.41/arch/powerpc/include/asm/dma-mapping.h linux-2.6.32.41/arch/powerpc/include/asm/dma-mapping.h
1806--- linux-2.6.32.41/arch/powerpc/include/asm/dma-mapping.h 2011-03-27 14:31:47.000000000 -0400
1807+++ linux-2.6.32.41/arch/powerpc/include/asm/dma-mapping.h 2011-04-17 15:56:45.000000000 -0400
1808@@ -69,9 +69,9 @@ static inline unsigned long device_to_ma
1809 #ifdef CONFIG_PPC64
1810 extern struct dma_map_ops dma_iommu_ops;
1811 #endif
1812-extern struct dma_map_ops dma_direct_ops;
1813+extern const struct dma_map_ops dma_direct_ops;
1814
1815-static inline struct dma_map_ops *get_dma_ops(struct device *dev)
1816+static inline const struct dma_map_ops *get_dma_ops(struct device *dev)
1817 {
1818 /* We don't handle the NULL dev case for ISA for now. We could
1819 * do it via an out of line call but it is not needed for now. The
1820@@ -84,7 +84,7 @@ static inline struct dma_map_ops *get_dm
1821 return dev->archdata.dma_ops;
1822 }
1823
1824-static inline void set_dma_ops(struct device *dev, struct dma_map_ops *ops)
1825+static inline void set_dma_ops(struct device *dev, const struct dma_map_ops *ops)
1826 {
1827 dev->archdata.dma_ops = ops;
1828 }
1829@@ -118,7 +118,7 @@ static inline void set_dma_offset(struct
1830
1831 static inline int dma_supported(struct device *dev, u64 mask)
1832 {
1833- struct dma_map_ops *dma_ops = get_dma_ops(dev);
1834+ const struct dma_map_ops *dma_ops = get_dma_ops(dev);
1835
1836 if (unlikely(dma_ops == NULL))
1837 return 0;
1838@@ -132,7 +132,7 @@ static inline int dma_supported(struct d
1839
1840 static inline int dma_set_mask(struct device *dev, u64 dma_mask)
1841 {
1842- struct dma_map_ops *dma_ops = get_dma_ops(dev);
1843+ const struct dma_map_ops *dma_ops = get_dma_ops(dev);
1844
1845 if (unlikely(dma_ops == NULL))
1846 return -EIO;
1847@@ -147,7 +147,7 @@ static inline int dma_set_mask(struct de
1848 static inline void *dma_alloc_coherent(struct device *dev, size_t size,
1849 dma_addr_t *dma_handle, gfp_t flag)
1850 {
1851- struct dma_map_ops *dma_ops = get_dma_ops(dev);
1852+ const struct dma_map_ops *dma_ops = get_dma_ops(dev);
1853 void *cpu_addr;
1854
1855 BUG_ON(!dma_ops);
1856@@ -162,7 +162,7 @@ static inline void *dma_alloc_coherent(s
1857 static inline void dma_free_coherent(struct device *dev, size_t size,
1858 void *cpu_addr, dma_addr_t dma_handle)
1859 {
1860- struct dma_map_ops *dma_ops = get_dma_ops(dev);
1861+ const struct dma_map_ops *dma_ops = get_dma_ops(dev);
1862
1863 BUG_ON(!dma_ops);
1864
1865@@ -173,7 +173,7 @@ static inline void dma_free_coherent(str
1866
1867 static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
1868 {
1869- struct dma_map_ops *dma_ops = get_dma_ops(dev);
1870+ const struct dma_map_ops *dma_ops = get_dma_ops(dev);
1871
1872 if (dma_ops->mapping_error)
1873 return dma_ops->mapping_error(dev, dma_addr);
1874diff -urNp linux-2.6.32.41/arch/powerpc/include/asm/elf.h linux-2.6.32.41/arch/powerpc/include/asm/elf.h
1875--- linux-2.6.32.41/arch/powerpc/include/asm/elf.h 2011-03-27 14:31:47.000000000 -0400
1876+++ linux-2.6.32.41/arch/powerpc/include/asm/elf.h 2011-04-17 15:56:45.000000000 -0400
1877@@ -179,8 +179,19 @@ typedef elf_fpreg_t elf_vsrreghalf_t32[E
1878 the loader. We need to make sure that it is out of the way of the program
1879 that it will "exec", and that there is sufficient room for the brk. */
1880
1881-extern unsigned long randomize_et_dyn(unsigned long base);
1882-#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
1883+#define ELF_ET_DYN_BASE (0x20000000)
1884+
1885+#ifdef CONFIG_PAX_ASLR
1886+#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
1887+
1888+#ifdef __powerpc64__
1889+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 16 : 28)
1890+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 16 : 28)
1891+#else
1892+#define PAX_DELTA_MMAP_LEN 15
1893+#define PAX_DELTA_STACK_LEN 15
1894+#endif
1895+#endif
1896
1897 /*
1898 * Our registers are always unsigned longs, whether we're a 32 bit
1899@@ -275,9 +286,6 @@ extern int arch_setup_additional_pages(s
1900 (0x7ff >> (PAGE_SHIFT - 12)) : \
1901 (0x3ffff >> (PAGE_SHIFT - 12)))
1902
1903-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1904-#define arch_randomize_brk arch_randomize_brk
1905-
1906 #endif /* __KERNEL__ */
1907
1908 /*
1909diff -urNp linux-2.6.32.41/arch/powerpc/include/asm/iommu.h linux-2.6.32.41/arch/powerpc/include/asm/iommu.h
1910--- linux-2.6.32.41/arch/powerpc/include/asm/iommu.h 2011-03-27 14:31:47.000000000 -0400
1911+++ linux-2.6.32.41/arch/powerpc/include/asm/iommu.h 2011-04-17 15:56:45.000000000 -0400
1912@@ -116,6 +116,9 @@ extern void iommu_init_early_iSeries(voi
1913 extern void iommu_init_early_dart(void);
1914 extern void iommu_init_early_pasemi(void);
1915
1916+/* dma-iommu.c */
1917+extern int dma_iommu_dma_supported(struct device *dev, u64 mask);
1918+
1919 #ifdef CONFIG_PCI
1920 extern void pci_iommu_init(void);
1921 extern void pci_direct_iommu_init(void);
1922diff -urNp linux-2.6.32.41/arch/powerpc/include/asm/kmap_types.h linux-2.6.32.41/arch/powerpc/include/asm/kmap_types.h
1923--- linux-2.6.32.41/arch/powerpc/include/asm/kmap_types.h 2011-03-27 14:31:47.000000000 -0400
1924+++ linux-2.6.32.41/arch/powerpc/include/asm/kmap_types.h 2011-04-17 15:56:45.000000000 -0400
1925@@ -26,6 +26,7 @@ enum km_type {
1926 KM_SOFTIRQ1,
1927 KM_PPC_SYNC_PAGE,
1928 KM_PPC_SYNC_ICACHE,
1929+ KM_CLEARPAGE,
1930 KM_TYPE_NR
1931 };
1932
1933diff -urNp linux-2.6.32.41/arch/powerpc/include/asm/page_64.h linux-2.6.32.41/arch/powerpc/include/asm/page_64.h
1934--- linux-2.6.32.41/arch/powerpc/include/asm/page_64.h 2011-03-27 14:31:47.000000000 -0400
1935+++ linux-2.6.32.41/arch/powerpc/include/asm/page_64.h 2011-04-17 15:56:45.000000000 -0400
1936@@ -180,15 +180,18 @@ do { \
1937 * stack by default, so in the absense of a PT_GNU_STACK program header
1938 * we turn execute permission off.
1939 */
1940-#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
1941- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
1942+#define VM_STACK_DEFAULT_FLAGS32 \
1943+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
1944+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
1945
1946 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
1947 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
1948
1949+#ifndef CONFIG_PAX_PAGEEXEC
1950 #define VM_STACK_DEFAULT_FLAGS \
1951 (test_thread_flag(TIF_32BIT) ? \
1952 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
1953+#endif
1954
1955 #include <asm-generic/getorder.h>
1956
1957diff -urNp linux-2.6.32.41/arch/powerpc/include/asm/page.h linux-2.6.32.41/arch/powerpc/include/asm/page.h
1958--- linux-2.6.32.41/arch/powerpc/include/asm/page.h 2011-03-27 14:31:47.000000000 -0400
1959+++ linux-2.6.32.41/arch/powerpc/include/asm/page.h 2011-04-17 15:56:45.000000000 -0400
1960@@ -116,8 +116,9 @@ extern phys_addr_t kernstart_addr;
1961 * and needs to be executable. This means the whole heap ends
1962 * up being executable.
1963 */
1964-#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
1965- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
1966+#define VM_DATA_DEFAULT_FLAGS32 \
1967+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
1968+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
1969
1970 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
1971 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
1972@@ -145,6 +146,9 @@ extern phys_addr_t kernstart_addr;
1973 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
1974 #endif
1975
1976+#define ktla_ktva(addr) (addr)
1977+#define ktva_ktla(addr) (addr)
1978+
1979 #ifndef __ASSEMBLY__
1980
1981 #undef STRICT_MM_TYPECHECKS
1982diff -urNp linux-2.6.32.41/arch/powerpc/include/asm/pci.h linux-2.6.32.41/arch/powerpc/include/asm/pci.h
1983--- linux-2.6.32.41/arch/powerpc/include/asm/pci.h 2011-03-27 14:31:47.000000000 -0400
1984+++ linux-2.6.32.41/arch/powerpc/include/asm/pci.h 2011-04-17 15:56:45.000000000 -0400
1985@@ -65,8 +65,8 @@ static inline int pci_get_legacy_ide_irq
1986 }
1987
1988 #ifdef CONFIG_PCI
1989-extern void set_pci_dma_ops(struct dma_map_ops *dma_ops);
1990-extern struct dma_map_ops *get_pci_dma_ops(void);
1991+extern void set_pci_dma_ops(const struct dma_map_ops *dma_ops);
1992+extern const struct dma_map_ops *get_pci_dma_ops(void);
1993 #else /* CONFIG_PCI */
1994 #define set_pci_dma_ops(d)
1995 #define get_pci_dma_ops() NULL
1996diff -urNp linux-2.6.32.41/arch/powerpc/include/asm/pgtable.h linux-2.6.32.41/arch/powerpc/include/asm/pgtable.h
1997--- linux-2.6.32.41/arch/powerpc/include/asm/pgtable.h 2011-03-27 14:31:47.000000000 -0400
1998+++ linux-2.6.32.41/arch/powerpc/include/asm/pgtable.h 2011-04-17 15:56:45.000000000 -0400
1999@@ -2,6 +2,7 @@
2000 #define _ASM_POWERPC_PGTABLE_H
2001 #ifdef __KERNEL__
2002
2003+#include <linux/const.h>
2004 #ifndef __ASSEMBLY__
2005 #include <asm/processor.h> /* For TASK_SIZE */
2006 #include <asm/mmu.h>
2007diff -urNp linux-2.6.32.41/arch/powerpc/include/asm/pte-hash32.h linux-2.6.32.41/arch/powerpc/include/asm/pte-hash32.h
2008--- linux-2.6.32.41/arch/powerpc/include/asm/pte-hash32.h 2011-03-27 14:31:47.000000000 -0400
2009+++ linux-2.6.32.41/arch/powerpc/include/asm/pte-hash32.h 2011-04-17 15:56:45.000000000 -0400
2010@@ -21,6 +21,7 @@
2011 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
2012 #define _PAGE_USER 0x004 /* usermode access allowed */
2013 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
2014+#define _PAGE_EXEC _PAGE_GUARDED
2015 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
2016 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
2017 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
2018diff -urNp linux-2.6.32.41/arch/powerpc/include/asm/reg.h linux-2.6.32.41/arch/powerpc/include/asm/reg.h
2019--- linux-2.6.32.41/arch/powerpc/include/asm/reg.h 2011-03-27 14:31:47.000000000 -0400
2020+++ linux-2.6.32.41/arch/powerpc/include/asm/reg.h 2011-04-17 15:56:45.000000000 -0400
2021@@ -191,6 +191,7 @@
2022 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
2023 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
2024 #define DSISR_NOHPTE 0x40000000 /* no translation found */
2025+#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
2026 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
2027 #define DSISR_ISSTORE 0x02000000 /* access was a store */
2028 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
2029diff -urNp linux-2.6.32.41/arch/powerpc/include/asm/swiotlb.h linux-2.6.32.41/arch/powerpc/include/asm/swiotlb.h
2030--- linux-2.6.32.41/arch/powerpc/include/asm/swiotlb.h 2011-03-27 14:31:47.000000000 -0400
2031+++ linux-2.6.32.41/arch/powerpc/include/asm/swiotlb.h 2011-04-17 15:56:45.000000000 -0400
2032@@ -13,7 +13,7 @@
2033
2034 #include <linux/swiotlb.h>
2035
2036-extern struct dma_map_ops swiotlb_dma_ops;
2037+extern const struct dma_map_ops swiotlb_dma_ops;
2038
2039 static inline void dma_mark_clean(void *addr, size_t size) {}
2040
2041diff -urNp linux-2.6.32.41/arch/powerpc/include/asm/system.h linux-2.6.32.41/arch/powerpc/include/asm/system.h
2042--- linux-2.6.32.41/arch/powerpc/include/asm/system.h 2011-03-27 14:31:47.000000000 -0400
2043+++ linux-2.6.32.41/arch/powerpc/include/asm/system.h 2011-04-17 15:56:45.000000000 -0400
2044@@ -531,7 +531,7 @@ __cmpxchg_local(volatile void *ptr, unsi
2045 #define cmpxchg64_local(ptr, o, n) __cmpxchg64_local_generic((ptr), (o), (n))
2046 #endif
2047
2048-extern unsigned long arch_align_stack(unsigned long sp);
2049+#define arch_align_stack(x) ((x) & ~0xfUL)
2050
2051 /* Used in very early kernel initialization. */
2052 extern unsigned long reloc_offset(void);
2053diff -urNp linux-2.6.32.41/arch/powerpc/include/asm/uaccess.h linux-2.6.32.41/arch/powerpc/include/asm/uaccess.h
2054--- linux-2.6.32.41/arch/powerpc/include/asm/uaccess.h 2011-03-27 14:31:47.000000000 -0400
2055+++ linux-2.6.32.41/arch/powerpc/include/asm/uaccess.h 2011-04-17 15:56:45.000000000 -0400
2056@@ -13,6 +13,8 @@
2057 #define VERIFY_READ 0
2058 #define VERIFY_WRITE 1
2059
2060+extern void check_object_size(const void *ptr, unsigned long n, bool to);
2061+
2062 /*
2063 * The fs value determines whether argument validity checking should be
2064 * performed or not. If get_fs() == USER_DS, checking is performed, with
2065@@ -327,52 +329,6 @@ do { \
2066 extern unsigned long __copy_tofrom_user(void __user *to,
2067 const void __user *from, unsigned long size);
2068
2069-#ifndef __powerpc64__
2070-
2071-static inline unsigned long copy_from_user(void *to,
2072- const void __user *from, unsigned long n)
2073-{
2074- unsigned long over;
2075-
2076- if (access_ok(VERIFY_READ, from, n))
2077- return __copy_tofrom_user((__force void __user *)to, from, n);
2078- if ((unsigned long)from < TASK_SIZE) {
2079- over = (unsigned long)from + n - TASK_SIZE;
2080- return __copy_tofrom_user((__force void __user *)to, from,
2081- n - over) + over;
2082- }
2083- return n;
2084-}
2085-
2086-static inline unsigned long copy_to_user(void __user *to,
2087- const void *from, unsigned long n)
2088-{
2089- unsigned long over;
2090-
2091- if (access_ok(VERIFY_WRITE, to, n))
2092- return __copy_tofrom_user(to, (__force void __user *)from, n);
2093- if ((unsigned long)to < TASK_SIZE) {
2094- over = (unsigned long)to + n - TASK_SIZE;
2095- return __copy_tofrom_user(to, (__force void __user *)from,
2096- n - over) + over;
2097- }
2098- return n;
2099-}
2100-
2101-#else /* __powerpc64__ */
2102-
2103-#define __copy_in_user(to, from, size) \
2104- __copy_tofrom_user((to), (from), (size))
2105-
2106-extern unsigned long copy_from_user(void *to, const void __user *from,
2107- unsigned long n);
2108-extern unsigned long copy_to_user(void __user *to, const void *from,
2109- unsigned long n);
2110-extern unsigned long copy_in_user(void __user *to, const void __user *from,
2111- unsigned long n);
2112-
2113-#endif /* __powerpc64__ */
2114-
2115 static inline unsigned long __copy_from_user_inatomic(void *to,
2116 const void __user *from, unsigned long n)
2117 {
2118@@ -396,6 +352,10 @@ static inline unsigned long __copy_from_
2119 if (ret == 0)
2120 return 0;
2121 }
2122+
2123+ if (!__builtin_constant_p(n))
2124+ check_object_size(to, n, false);
2125+
2126 return __copy_tofrom_user((__force void __user *)to, from, n);
2127 }
2128
2129@@ -422,6 +382,10 @@ static inline unsigned long __copy_to_us
2130 if (ret == 0)
2131 return 0;
2132 }
2133+
2134+ if (!__builtin_constant_p(n))
2135+ check_object_size(from, n, true);
2136+
2137 return __copy_tofrom_user(to, (__force const void __user *)from, n);
2138 }
2139
2140@@ -439,6 +403,92 @@ static inline unsigned long __copy_to_us
2141 return __copy_to_user_inatomic(to, from, size);
2142 }
2143
2144+#ifndef __powerpc64__
2145+
2146+static inline unsigned long __must_check copy_from_user(void *to,
2147+ const void __user *from, unsigned long n)
2148+{
2149+ unsigned long over;
2150+
2151+ if ((long)n < 0)
2152+ return n;
2153+
2154+ if (access_ok(VERIFY_READ, from, n)) {
2155+ if (!__builtin_constant_p(n))
2156+ check_object_size(to, n, false);
2157+ return __copy_tofrom_user((__force void __user *)to, from, n);
2158+ }
2159+ if ((unsigned long)from < TASK_SIZE) {
2160+ over = (unsigned long)from + n - TASK_SIZE;
2161+ if (!__builtin_constant_p(n - over))
2162+ check_object_size(to, n - over, false);
2163+ return __copy_tofrom_user((__force void __user *)to, from,
2164+ n - over) + over;
2165+ }
2166+ return n;
2167+}
2168+
2169+static inline unsigned long __must_check copy_to_user(void __user *to,
2170+ const void *from, unsigned long n)
2171+{
2172+ unsigned long over;
2173+
2174+ if ((long)n < 0)
2175+ return n;
2176+
2177+ if (access_ok(VERIFY_WRITE, to, n)) {
2178+ if (!__builtin_constant_p(n))
2179+ check_object_size(from, n, true);
2180+ return __copy_tofrom_user(to, (__force void __user *)from, n);
2181+ }
2182+ if ((unsigned long)to < TASK_SIZE) {
2183+ over = (unsigned long)to + n - TASK_SIZE;
2184+ if (!__builtin_constant_p(n))
2185+ check_object_size(from, n - over, true);
2186+ return __copy_tofrom_user(to, (__force void __user *)from,
2187+ n - over) + over;
2188+ }
2189+ return n;
2190+}
2191+
2192+#else /* __powerpc64__ */
2193+
2194+#define __copy_in_user(to, from, size) \
2195+ __copy_tofrom_user((to), (from), (size))
2196+
2197+static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
2198+{
2199+ if ((long)n < 0 || n > INT_MAX)
2200+ return n;
2201+
2202+ if (!__builtin_constant_p(n))
2203+ check_object_size(to, n, false);
2204+
2205+ if (likely(access_ok(VERIFY_READ, from, n)))
2206+ n = __copy_from_user(to, from, n);
2207+ else
2208+ memset(to, 0, n);
2209+ return n;
2210+}
2211+
2212+static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
2213+{
2214+ if ((long)n < 0 || n > INT_MAX)
2215+ return n;
2216+
2217+ if (likely(access_ok(VERIFY_WRITE, to, n))) {
2218+ if (!__builtin_constant_p(n))
2219+ check_object_size(from, n, true);
2220+ n = __copy_to_user(to, from, n);
2221+ }
2222+ return n;
2223+}
2224+
2225+extern unsigned long copy_in_user(void __user *to, const void __user *from,
2226+ unsigned long n);
2227+
2228+#endif /* __powerpc64__ */
2229+
2230 extern unsigned long __clear_user(void __user *addr, unsigned long size);
2231
2232 static inline unsigned long clear_user(void __user *addr, unsigned long size)
2233diff -urNp linux-2.6.32.41/arch/powerpc/kernel/cacheinfo.c linux-2.6.32.41/arch/powerpc/kernel/cacheinfo.c
2234--- linux-2.6.32.41/arch/powerpc/kernel/cacheinfo.c 2011-03-27 14:31:47.000000000 -0400
2235+++ linux-2.6.32.41/arch/powerpc/kernel/cacheinfo.c 2011-04-17 15:56:45.000000000 -0400
2236@@ -642,7 +642,7 @@ static struct kobj_attribute *cache_inde
2237 &cache_assoc_attr,
2238 };
2239
2240-static struct sysfs_ops cache_index_ops = {
2241+static const struct sysfs_ops cache_index_ops = {
2242 .show = cache_index_show,
2243 };
2244
2245diff -urNp linux-2.6.32.41/arch/powerpc/kernel/dma.c linux-2.6.32.41/arch/powerpc/kernel/dma.c
2246--- linux-2.6.32.41/arch/powerpc/kernel/dma.c 2011-03-27 14:31:47.000000000 -0400
2247+++ linux-2.6.32.41/arch/powerpc/kernel/dma.c 2011-04-17 15:56:45.000000000 -0400
2248@@ -134,7 +134,7 @@ static inline void dma_direct_sync_singl
2249 }
2250 #endif
2251
2252-struct dma_map_ops dma_direct_ops = {
2253+const struct dma_map_ops dma_direct_ops = {
2254 .alloc_coherent = dma_direct_alloc_coherent,
2255 .free_coherent = dma_direct_free_coherent,
2256 .map_sg = dma_direct_map_sg,
2257diff -urNp linux-2.6.32.41/arch/powerpc/kernel/dma-iommu.c linux-2.6.32.41/arch/powerpc/kernel/dma-iommu.c
2258--- linux-2.6.32.41/arch/powerpc/kernel/dma-iommu.c 2011-03-27 14:31:47.000000000 -0400
2259+++ linux-2.6.32.41/arch/powerpc/kernel/dma-iommu.c 2011-04-17 15:56:45.000000000 -0400
2260@@ -70,7 +70,7 @@ static void dma_iommu_unmap_sg(struct de
2261 }
2262
2263 /* We support DMA to/from any memory page via the iommu */
2264-static int dma_iommu_dma_supported(struct device *dev, u64 mask)
2265+int dma_iommu_dma_supported(struct device *dev, u64 mask)
2266 {
2267 struct iommu_table *tbl = get_iommu_table_base(dev);
2268
2269diff -urNp linux-2.6.32.41/arch/powerpc/kernel/dma-swiotlb.c linux-2.6.32.41/arch/powerpc/kernel/dma-swiotlb.c
2270--- linux-2.6.32.41/arch/powerpc/kernel/dma-swiotlb.c 2011-03-27 14:31:47.000000000 -0400
2271+++ linux-2.6.32.41/arch/powerpc/kernel/dma-swiotlb.c 2011-04-17 15:56:45.000000000 -0400
2272@@ -31,7 +31,7 @@ unsigned int ppc_swiotlb_enable;
2273 * map_page, and unmap_page on highmem, use normal dma_ops
2274 * for everything else.
2275 */
2276-struct dma_map_ops swiotlb_dma_ops = {
2277+const struct dma_map_ops swiotlb_dma_ops = {
2278 .alloc_coherent = dma_direct_alloc_coherent,
2279 .free_coherent = dma_direct_free_coherent,
2280 .map_sg = swiotlb_map_sg_attrs,
2281diff -urNp linux-2.6.32.41/arch/powerpc/kernel/exceptions-64e.S linux-2.6.32.41/arch/powerpc/kernel/exceptions-64e.S
2282--- linux-2.6.32.41/arch/powerpc/kernel/exceptions-64e.S 2011-03-27 14:31:47.000000000 -0400
2283+++ linux-2.6.32.41/arch/powerpc/kernel/exceptions-64e.S 2011-04-17 15:56:45.000000000 -0400
2284@@ -455,6 +455,7 @@ storage_fault_common:
2285 std r14,_DAR(r1)
2286 std r15,_DSISR(r1)
2287 addi r3,r1,STACK_FRAME_OVERHEAD
2288+ bl .save_nvgprs
2289 mr r4,r14
2290 mr r5,r15
2291 ld r14,PACA_EXGEN+EX_R14(r13)
2292@@ -464,8 +465,7 @@ storage_fault_common:
2293 cmpdi r3,0
2294 bne- 1f
2295 b .ret_from_except_lite
2296-1: bl .save_nvgprs
2297- mr r5,r3
2298+1: mr r5,r3
2299 addi r3,r1,STACK_FRAME_OVERHEAD
2300 ld r4,_DAR(r1)
2301 bl .bad_page_fault
2302diff -urNp linux-2.6.32.41/arch/powerpc/kernel/exceptions-64s.S linux-2.6.32.41/arch/powerpc/kernel/exceptions-64s.S
2303--- linux-2.6.32.41/arch/powerpc/kernel/exceptions-64s.S 2011-03-27 14:31:47.000000000 -0400
2304+++ linux-2.6.32.41/arch/powerpc/kernel/exceptions-64s.S 2011-04-17 15:56:45.000000000 -0400
2305@@ -818,10 +818,10 @@ handle_page_fault:
2306 11: ld r4,_DAR(r1)
2307 ld r5,_DSISR(r1)
2308 addi r3,r1,STACK_FRAME_OVERHEAD
2309+ bl .save_nvgprs
2310 bl .do_page_fault
2311 cmpdi r3,0
2312 beq+ 13f
2313- bl .save_nvgprs
2314 mr r5,r3
2315 addi r3,r1,STACK_FRAME_OVERHEAD
2316 lwz r4,_DAR(r1)
2317diff -urNp linux-2.6.32.41/arch/powerpc/kernel/ibmebus.c linux-2.6.32.41/arch/powerpc/kernel/ibmebus.c
2318--- linux-2.6.32.41/arch/powerpc/kernel/ibmebus.c 2011-03-27 14:31:47.000000000 -0400
2319+++ linux-2.6.32.41/arch/powerpc/kernel/ibmebus.c 2011-04-17 15:56:45.000000000 -0400
2320@@ -127,7 +127,7 @@ static int ibmebus_dma_supported(struct
2321 return 1;
2322 }
2323
2324-static struct dma_map_ops ibmebus_dma_ops = {
2325+static const struct dma_map_ops ibmebus_dma_ops = {
2326 .alloc_coherent = ibmebus_alloc_coherent,
2327 .free_coherent = ibmebus_free_coherent,
2328 .map_sg = ibmebus_map_sg,
2329diff -urNp linux-2.6.32.41/arch/powerpc/kernel/kgdb.c linux-2.6.32.41/arch/powerpc/kernel/kgdb.c
2330--- linux-2.6.32.41/arch/powerpc/kernel/kgdb.c 2011-03-27 14:31:47.000000000 -0400
2331+++ linux-2.6.32.41/arch/powerpc/kernel/kgdb.c 2011-04-17 15:56:45.000000000 -0400
2332@@ -126,7 +126,7 @@ static int kgdb_handle_breakpoint(struct
2333 if (kgdb_handle_exception(0, SIGTRAP, 0, regs) != 0)
2334 return 0;
2335
2336- if (*(u32 *) (regs->nip) == *(u32 *) (&arch_kgdb_ops.gdb_bpt_instr))
2337+ if (*(u32 *) (regs->nip) == *(const u32 *) (&arch_kgdb_ops.gdb_bpt_instr))
2338 regs->nip += 4;
2339
2340 return 1;
2341@@ -353,7 +353,7 @@ int kgdb_arch_handle_exception(int vecto
2342 /*
2343 * Global data
2344 */
2345-struct kgdb_arch arch_kgdb_ops = {
2346+const struct kgdb_arch arch_kgdb_ops = {
2347 .gdb_bpt_instr = {0x7d, 0x82, 0x10, 0x08},
2348 };
2349
2350diff -urNp linux-2.6.32.41/arch/powerpc/kernel/module_32.c linux-2.6.32.41/arch/powerpc/kernel/module_32.c
2351--- linux-2.6.32.41/arch/powerpc/kernel/module_32.c 2011-03-27 14:31:47.000000000 -0400
2352+++ linux-2.6.32.41/arch/powerpc/kernel/module_32.c 2011-04-17 15:56:45.000000000 -0400
2353@@ -162,7 +162,7 @@ int module_frob_arch_sections(Elf32_Ehdr
2354 me->arch.core_plt_section = i;
2355 }
2356 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
2357- printk("Module doesn't contain .plt or .init.plt sections.\n");
2358+ printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
2359 return -ENOEXEC;
2360 }
2361
2362@@ -203,11 +203,16 @@ static uint32_t do_plt_call(void *locati
2363
2364 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
2365 /* Init, or core PLT? */
2366- if (location >= mod->module_core
2367- && location < mod->module_core + mod->core_size)
2368+ if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
2369+ (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
2370 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
2371- else
2372+ else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
2373+ (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
2374 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
2375+ else {
2376+ printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
2377+ return ~0UL;
2378+ }
2379
2380 /* Find this entry, or if that fails, the next avail. entry */
2381 while (entry->jump[0]) {
2382diff -urNp linux-2.6.32.41/arch/powerpc/kernel/module.c linux-2.6.32.41/arch/powerpc/kernel/module.c
2383--- linux-2.6.32.41/arch/powerpc/kernel/module.c 2011-03-27 14:31:47.000000000 -0400
2384+++ linux-2.6.32.41/arch/powerpc/kernel/module.c 2011-04-17 15:56:45.000000000 -0400
2385@@ -31,11 +31,24 @@
2386
2387 LIST_HEAD(module_bug_list);
2388
2389+#ifdef CONFIG_PAX_KERNEXEC
2390 void *module_alloc(unsigned long size)
2391 {
2392 if (size == 0)
2393 return NULL;
2394
2395+ return vmalloc(size);
2396+}
2397+
2398+void *module_alloc_exec(unsigned long size)
2399+#else
2400+void *module_alloc(unsigned long size)
2401+#endif
2402+
2403+{
2404+ if (size == 0)
2405+ return NULL;
2406+
2407 return vmalloc_exec(size);
2408 }
2409
2410@@ -45,6 +58,13 @@ void module_free(struct module *mod, voi
2411 vfree(module_region);
2412 }
2413
2414+#ifdef CONFIG_PAX_KERNEXEC
2415+void module_free_exec(struct module *mod, void *module_region)
2416+{
2417+ module_free(mod, module_region);
2418+}
2419+#endif
2420+
2421 static const Elf_Shdr *find_section(const Elf_Ehdr *hdr,
2422 const Elf_Shdr *sechdrs,
2423 const char *name)
2424diff -urNp linux-2.6.32.41/arch/powerpc/kernel/pci-common.c linux-2.6.32.41/arch/powerpc/kernel/pci-common.c
2425--- linux-2.6.32.41/arch/powerpc/kernel/pci-common.c 2011-03-27 14:31:47.000000000 -0400
2426+++ linux-2.6.32.41/arch/powerpc/kernel/pci-common.c 2011-04-17 15:56:45.000000000 -0400
2427@@ -50,14 +50,14 @@ resource_size_t isa_mem_base;
2428 unsigned int ppc_pci_flags = 0;
2429
2430
2431-static struct dma_map_ops *pci_dma_ops = &dma_direct_ops;
2432+static const struct dma_map_ops *pci_dma_ops = &dma_direct_ops;
2433
2434-void set_pci_dma_ops(struct dma_map_ops *dma_ops)
2435+void set_pci_dma_ops(const struct dma_map_ops *dma_ops)
2436 {
2437 pci_dma_ops = dma_ops;
2438 }
2439
2440-struct dma_map_ops *get_pci_dma_ops(void)
2441+const struct dma_map_ops *get_pci_dma_ops(void)
2442 {
2443 return pci_dma_ops;
2444 }
2445diff -urNp linux-2.6.32.41/arch/powerpc/kernel/process.c linux-2.6.32.41/arch/powerpc/kernel/process.c
2446--- linux-2.6.32.41/arch/powerpc/kernel/process.c 2011-03-27 14:31:47.000000000 -0400
2447+++ linux-2.6.32.41/arch/powerpc/kernel/process.c 2011-04-17 15:56:45.000000000 -0400
2448@@ -539,8 +539,8 @@ void show_regs(struct pt_regs * regs)
2449 * Lookup NIP late so we have the best change of getting the
2450 * above info out without failing
2451 */
2452- printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
2453- printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
2454+ printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
2455+ printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
2456 #endif
2457 show_stack(current, (unsigned long *) regs->gpr[1]);
2458 if (!user_mode(regs))
2459@@ -1034,10 +1034,10 @@ void show_stack(struct task_struct *tsk,
2460 newsp = stack[0];
2461 ip = stack[STACK_FRAME_LR_SAVE];
2462 if (!firstframe || ip != lr) {
2463- printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
2464+ printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
2465 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
2466 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
2467- printk(" (%pS)",
2468+ printk(" (%pA)",
2469 (void *)current->ret_stack[curr_frame].ret);
2470 curr_frame--;
2471 }
2472@@ -1057,7 +1057,7 @@ void show_stack(struct task_struct *tsk,
2473 struct pt_regs *regs = (struct pt_regs *)
2474 (sp + STACK_FRAME_OVERHEAD);
2475 lr = regs->link;
2476- printk("--- Exception: %lx at %pS\n LR = %pS\n",
2477+ printk("--- Exception: %lx at %pA\n LR = %pA\n",
2478 regs->trap, (void *)regs->nip, (void *)lr);
2479 firstframe = 1;
2480 }
2481@@ -1134,58 +1134,3 @@ void thread_info_cache_init(void)
2482 }
2483
2484 #endif /* THREAD_SHIFT < PAGE_SHIFT */
2485-
2486-unsigned long arch_align_stack(unsigned long sp)
2487-{
2488- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
2489- sp -= get_random_int() & ~PAGE_MASK;
2490- return sp & ~0xf;
2491-}
2492-
2493-static inline unsigned long brk_rnd(void)
2494-{
2495- unsigned long rnd = 0;
2496-
2497- /* 8MB for 32bit, 1GB for 64bit */
2498- if (is_32bit_task())
2499- rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
2500- else
2501- rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
2502-
2503- return rnd << PAGE_SHIFT;
2504-}
2505-
2506-unsigned long arch_randomize_brk(struct mm_struct *mm)
2507-{
2508- unsigned long base = mm->brk;
2509- unsigned long ret;
2510-
2511-#ifdef CONFIG_PPC_STD_MMU_64
2512- /*
2513- * If we are using 1TB segments and we are allowed to randomise
2514- * the heap, we can put it above 1TB so it is backed by a 1TB
2515- * segment. Otherwise the heap will be in the bottom 1TB
2516- * which always uses 256MB segments and this may result in a
2517- * performance penalty.
2518- */
2519- if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
2520- base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
2521-#endif
2522-
2523- ret = PAGE_ALIGN(base + brk_rnd());
2524-
2525- if (ret < mm->brk)
2526- return mm->brk;
2527-
2528- return ret;
2529-}
2530-
2531-unsigned long randomize_et_dyn(unsigned long base)
2532-{
2533- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
2534-
2535- if (ret < base)
2536- return base;
2537-
2538- return ret;
2539-}
2540diff -urNp linux-2.6.32.41/arch/powerpc/kernel/signal_32.c linux-2.6.32.41/arch/powerpc/kernel/signal_32.c
2541--- linux-2.6.32.41/arch/powerpc/kernel/signal_32.c 2011-03-27 14:31:47.000000000 -0400
2542+++ linux-2.6.32.41/arch/powerpc/kernel/signal_32.c 2011-04-17 15:56:45.000000000 -0400
2543@@ -857,7 +857,7 @@ int handle_rt_signal32(unsigned long sig
2544 /* Save user registers on the stack */
2545 frame = &rt_sf->uc.uc_mcontext;
2546 addr = frame;
2547- if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
2548+ if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
2549 if (save_user_regs(regs, frame, 0, 1))
2550 goto badframe;
2551 regs->link = current->mm->context.vdso_base + vdso32_rt_sigtramp;
2552diff -urNp linux-2.6.32.41/arch/powerpc/kernel/signal_64.c linux-2.6.32.41/arch/powerpc/kernel/signal_64.c
2553--- linux-2.6.32.41/arch/powerpc/kernel/signal_64.c 2011-03-27 14:31:47.000000000 -0400
2554+++ linux-2.6.32.41/arch/powerpc/kernel/signal_64.c 2011-04-17 15:56:45.000000000 -0400
2555@@ -429,7 +429,7 @@ int handle_rt_signal64(int signr, struct
2556 current->thread.fpscr.val = 0;
2557
2558 /* Set up to return from userspace. */
2559- if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
2560+ if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
2561 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
2562 } else {
2563 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
2564diff -urNp linux-2.6.32.41/arch/powerpc/kernel/sys_ppc32.c linux-2.6.32.41/arch/powerpc/kernel/sys_ppc32.c
2565--- linux-2.6.32.41/arch/powerpc/kernel/sys_ppc32.c 2011-03-27 14:31:47.000000000 -0400
2566+++ linux-2.6.32.41/arch/powerpc/kernel/sys_ppc32.c 2011-04-17 15:56:45.000000000 -0400
2567@@ -563,10 +563,10 @@ asmlinkage long compat_sys_sysctl(struct
2568 if (oldlenp) {
2569 if (!error) {
2570 if (get_user(oldlen, oldlenp) ||
2571- put_user(oldlen, (compat_size_t __user *)compat_ptr(tmp.oldlenp)))
2572+ put_user(oldlen, (compat_size_t __user *)compat_ptr(tmp.oldlenp)) ||
2573+ copy_to_user(args->__unused, tmp.__unused, sizeof(tmp.__unused)))
2574 error = -EFAULT;
2575 }
2576- copy_to_user(args->__unused, tmp.__unused, sizeof(tmp.__unused));
2577 }
2578 return error;
2579 }
2580diff -urNp linux-2.6.32.41/arch/powerpc/kernel/vdso.c linux-2.6.32.41/arch/powerpc/kernel/vdso.c
2581--- linux-2.6.32.41/arch/powerpc/kernel/vdso.c 2011-03-27 14:31:47.000000000 -0400
2582+++ linux-2.6.32.41/arch/powerpc/kernel/vdso.c 2011-04-17 15:56:45.000000000 -0400
2583@@ -36,6 +36,7 @@
2584 #include <asm/firmware.h>
2585 #include <asm/vdso.h>
2586 #include <asm/vdso_datapage.h>
2587+#include <asm/mman.h>
2588
2589 #include "setup.h"
2590
2591@@ -220,7 +221,7 @@ int arch_setup_additional_pages(struct l
2592 vdso_base = VDSO32_MBASE;
2593 #endif
2594
2595- current->mm->context.vdso_base = 0;
2596+ current->mm->context.vdso_base = ~0UL;
2597
2598 /* vDSO has a problem and was disabled, just don't "enable" it for the
2599 * process
2600@@ -240,7 +241,7 @@ int arch_setup_additional_pages(struct l
2601 vdso_base = get_unmapped_area(NULL, vdso_base,
2602 (vdso_pages << PAGE_SHIFT) +
2603 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
2604- 0, 0);
2605+ 0, MAP_PRIVATE | MAP_EXECUTABLE);
2606 if (IS_ERR_VALUE(vdso_base)) {
2607 rc = vdso_base;
2608 goto fail_mmapsem;
2609diff -urNp linux-2.6.32.41/arch/powerpc/kernel/vio.c linux-2.6.32.41/arch/powerpc/kernel/vio.c
2610--- linux-2.6.32.41/arch/powerpc/kernel/vio.c 2011-03-27 14:31:47.000000000 -0400
2611+++ linux-2.6.32.41/arch/powerpc/kernel/vio.c 2011-04-17 15:56:45.000000000 -0400
2612@@ -601,11 +601,12 @@ static void vio_dma_iommu_unmap_sg(struc
2613 vio_cmo_dealloc(viodev, alloc_size);
2614 }
2615
2616-struct dma_map_ops vio_dma_mapping_ops = {
2617+static const struct dma_map_ops vio_dma_mapping_ops = {
2618 .alloc_coherent = vio_dma_iommu_alloc_coherent,
2619 .free_coherent = vio_dma_iommu_free_coherent,
2620 .map_sg = vio_dma_iommu_map_sg,
2621 .unmap_sg = vio_dma_iommu_unmap_sg,
2622+ .dma_supported = dma_iommu_dma_supported,
2623 .map_page = vio_dma_iommu_map_page,
2624 .unmap_page = vio_dma_iommu_unmap_page,
2625
2626@@ -857,7 +858,6 @@ static void vio_cmo_bus_remove(struct vi
2627
2628 static void vio_cmo_set_dma_ops(struct vio_dev *viodev)
2629 {
2630- vio_dma_mapping_ops.dma_supported = dma_iommu_ops.dma_supported;
2631 viodev->dev.archdata.dma_ops = &vio_dma_mapping_ops;
2632 }
2633
2634diff -urNp linux-2.6.32.41/arch/powerpc/lib/usercopy_64.c linux-2.6.32.41/arch/powerpc/lib/usercopy_64.c
2635--- linux-2.6.32.41/arch/powerpc/lib/usercopy_64.c 2011-03-27 14:31:47.000000000 -0400
2636+++ linux-2.6.32.41/arch/powerpc/lib/usercopy_64.c 2011-04-17 15:56:45.000000000 -0400
2637@@ -9,22 +9,6 @@
2638 #include <linux/module.h>
2639 #include <asm/uaccess.h>
2640
2641-unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
2642-{
2643- if (likely(access_ok(VERIFY_READ, from, n)))
2644- n = __copy_from_user(to, from, n);
2645- else
2646- memset(to, 0, n);
2647- return n;
2648-}
2649-
2650-unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
2651-{
2652- if (likely(access_ok(VERIFY_WRITE, to, n)))
2653- n = __copy_to_user(to, from, n);
2654- return n;
2655-}
2656-
2657 unsigned long copy_in_user(void __user *to, const void __user *from,
2658 unsigned long n)
2659 {
2660@@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *
2661 return n;
2662 }
2663
2664-EXPORT_SYMBOL(copy_from_user);
2665-EXPORT_SYMBOL(copy_to_user);
2666 EXPORT_SYMBOL(copy_in_user);
2667
2668diff -urNp linux-2.6.32.41/arch/powerpc/mm/fault.c linux-2.6.32.41/arch/powerpc/mm/fault.c
2669--- linux-2.6.32.41/arch/powerpc/mm/fault.c 2011-03-27 14:31:47.000000000 -0400
2670+++ linux-2.6.32.41/arch/powerpc/mm/fault.c 2011-04-17 15:56:45.000000000 -0400
2671@@ -30,6 +30,10 @@
2672 #include <linux/kprobes.h>
2673 #include <linux/kdebug.h>
2674 #include <linux/perf_event.h>
2675+#include <linux/slab.h>
2676+#include <linux/pagemap.h>
2677+#include <linux/compiler.h>
2678+#include <linux/unistd.h>
2679
2680 #include <asm/firmware.h>
2681 #include <asm/page.h>
2682@@ -40,6 +44,7 @@
2683 #include <asm/uaccess.h>
2684 #include <asm/tlbflush.h>
2685 #include <asm/siginfo.h>
2686+#include <asm/ptrace.h>
2687
2688
2689 #ifdef CONFIG_KPROBES
2690@@ -64,6 +69,33 @@ static inline int notify_page_fault(stru
2691 }
2692 #endif
2693
2694+#ifdef CONFIG_PAX_PAGEEXEC
2695+/*
2696+ * PaX: decide what to do with offenders (regs->nip = fault address)
2697+ *
2698+ * returns 1 when task should be killed
2699+ */
2700+static int pax_handle_fetch_fault(struct pt_regs *regs)
2701+{
2702+ return 1;
2703+}
2704+
2705+void pax_report_insns(void *pc, void *sp)
2706+{
2707+ unsigned long i;
2708+
2709+ printk(KERN_ERR "PAX: bytes at PC: ");
2710+ for (i = 0; i < 5; i++) {
2711+ unsigned int c;
2712+ if (get_user(c, (unsigned int __user *)pc+i))
2713+ printk(KERN_CONT "???????? ");
2714+ else
2715+ printk(KERN_CONT "%08x ", c);
2716+ }
2717+ printk("\n");
2718+}
2719+#endif
2720+
2721 /*
2722 * Check whether the instruction at regs->nip is a store using
2723 * an update addressing form which will update r1.
2724@@ -134,7 +166,7 @@ int __kprobes do_page_fault(struct pt_re
2725 * indicate errors in DSISR but can validly be set in SRR1.
2726 */
2727 if (trap == 0x400)
2728- error_code &= 0x48200000;
2729+ error_code &= 0x58200000;
2730 else
2731 is_write = error_code & DSISR_ISSTORE;
2732 #else
2733@@ -250,7 +282,7 @@ good_area:
2734 * "undefined". Of those that can be set, this is the only
2735 * one which seems bad.
2736 */
2737- if (error_code & 0x10000000)
2738+ if (error_code & DSISR_GUARDED)
2739 /* Guarded storage error. */
2740 goto bad_area;
2741 #endif /* CONFIG_8xx */
2742@@ -265,7 +297,7 @@ good_area:
2743 * processors use the same I/D cache coherency mechanism
2744 * as embedded.
2745 */
2746- if (error_code & DSISR_PROTFAULT)
2747+ if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
2748 goto bad_area;
2749 #endif /* CONFIG_PPC_STD_MMU */
2750
2751@@ -335,6 +367,23 @@ bad_area:
2752 bad_area_nosemaphore:
2753 /* User mode accesses cause a SIGSEGV */
2754 if (user_mode(regs)) {
2755+
2756+#ifdef CONFIG_PAX_PAGEEXEC
2757+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
2758+#ifdef CONFIG_PPC_STD_MMU
2759+ if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
2760+#else
2761+ if (is_exec && regs->nip == address) {
2762+#endif
2763+ switch (pax_handle_fetch_fault(regs)) {
2764+ }
2765+
2766+ pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
2767+ do_group_exit(SIGKILL);
2768+ }
2769+ }
2770+#endif
2771+
2772 _exception(SIGSEGV, regs, code, address);
2773 return 0;
2774 }
2775diff -urNp linux-2.6.32.41/arch/powerpc/mm/mmap_64.c linux-2.6.32.41/arch/powerpc/mm/mmap_64.c
2776--- linux-2.6.32.41/arch/powerpc/mm/mmap_64.c 2011-03-27 14:31:47.000000000 -0400
2777+++ linux-2.6.32.41/arch/powerpc/mm/mmap_64.c 2011-04-17 15:56:45.000000000 -0400
2778@@ -99,10 +99,22 @@ void arch_pick_mmap_layout(struct mm_str
2779 */
2780 if (mmap_is_legacy()) {
2781 mm->mmap_base = TASK_UNMAPPED_BASE;
2782+
2783+#ifdef CONFIG_PAX_RANDMMAP
2784+ if (mm->pax_flags & MF_PAX_RANDMMAP)
2785+ mm->mmap_base += mm->delta_mmap;
2786+#endif
2787+
2788 mm->get_unmapped_area = arch_get_unmapped_area;
2789 mm->unmap_area = arch_unmap_area;
2790 } else {
2791 mm->mmap_base = mmap_base();
2792+
2793+#ifdef CONFIG_PAX_RANDMMAP
2794+ if (mm->pax_flags & MF_PAX_RANDMMAP)
2795+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
2796+#endif
2797+
2798 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
2799 mm->unmap_area = arch_unmap_area_topdown;
2800 }
2801diff -urNp linux-2.6.32.41/arch/powerpc/mm/slice.c linux-2.6.32.41/arch/powerpc/mm/slice.c
2802--- linux-2.6.32.41/arch/powerpc/mm/slice.c 2011-03-27 14:31:47.000000000 -0400
2803+++ linux-2.6.32.41/arch/powerpc/mm/slice.c 2011-04-17 15:56:45.000000000 -0400
2804@@ -98,7 +98,7 @@ static int slice_area_is_free(struct mm_
2805 if ((mm->task_size - len) < addr)
2806 return 0;
2807 vma = find_vma(mm, addr);
2808- return (!vma || (addr + len) <= vma->vm_start);
2809+ return check_heap_stack_gap(vma, addr, len);
2810 }
2811
2812 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
2813@@ -256,7 +256,7 @@ full_search:
2814 addr = _ALIGN_UP(addr + 1, 1ul << SLICE_HIGH_SHIFT);
2815 continue;
2816 }
2817- if (!vma || addr + len <= vma->vm_start) {
2818+ if (check_heap_stack_gap(vma, addr, len)) {
2819 /*
2820 * Remember the place where we stopped the search:
2821 */
2822@@ -313,10 +313,14 @@ static unsigned long slice_find_area_top
2823 }
2824 }
2825
2826- addr = mm->mmap_base;
2827- while (addr > len) {
2828+ if (mm->mmap_base < len)
2829+ addr = -ENOMEM;
2830+ else
2831+ addr = mm->mmap_base - len;
2832+
2833+ while (!IS_ERR_VALUE(addr)) {
2834 /* Go down by chunk size */
2835- addr = _ALIGN_DOWN(addr - len, 1ul << pshift);
2836+ addr = _ALIGN_DOWN(addr, 1ul << pshift);
2837
2838 /* Check for hit with different page size */
2839 mask = slice_range_to_mask(addr, len);
2840@@ -336,7 +340,7 @@ static unsigned long slice_find_area_top
2841 * return with success:
2842 */
2843 vma = find_vma(mm, addr);
2844- if (!vma || (addr + len) <= vma->vm_start) {
2845+ if (check_heap_stack_gap(vma, addr, len)) {
2846 /* remember the address as a hint for next time */
2847 if (use_cache)
2848 mm->free_area_cache = addr;
2849@@ -348,7 +352,7 @@ static unsigned long slice_find_area_top
2850 mm->cached_hole_size = vma->vm_start - addr;
2851
2852 /* try just below the current vma->vm_start */
2853- addr = vma->vm_start;
2854+ addr = skip_heap_stack_gap(vma, len);
2855 }
2856
2857 /*
2858@@ -426,6 +430,11 @@ unsigned long slice_get_unmapped_area(un
2859 if (fixed && addr > (mm->task_size - len))
2860 return -EINVAL;
2861
2862+#ifdef CONFIG_PAX_RANDMMAP
2863+ if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
2864+ addr = 0;
2865+#endif
2866+
2867 /* If hint, make sure it matches our alignment restrictions */
2868 if (!fixed && addr) {
2869 addr = _ALIGN_UP(addr, 1ul << pshift);
2870diff -urNp linux-2.6.32.41/arch/powerpc/platforms/52xx/lite5200_pm.c linux-2.6.32.41/arch/powerpc/platforms/52xx/lite5200_pm.c
2871--- linux-2.6.32.41/arch/powerpc/platforms/52xx/lite5200_pm.c 2011-03-27 14:31:47.000000000 -0400
2872+++ linux-2.6.32.41/arch/powerpc/platforms/52xx/lite5200_pm.c 2011-04-17 15:56:45.000000000 -0400
2873@@ -235,7 +235,7 @@ static void lite5200_pm_end(void)
2874 lite5200_pm_target_state = PM_SUSPEND_ON;
2875 }
2876
2877-static struct platform_suspend_ops lite5200_pm_ops = {
2878+static const struct platform_suspend_ops lite5200_pm_ops = {
2879 .valid = lite5200_pm_valid,
2880 .begin = lite5200_pm_begin,
2881 .prepare = lite5200_pm_prepare,
2882diff -urNp linux-2.6.32.41/arch/powerpc/platforms/52xx/mpc52xx_pm.c linux-2.6.32.41/arch/powerpc/platforms/52xx/mpc52xx_pm.c
2883--- linux-2.6.32.41/arch/powerpc/platforms/52xx/mpc52xx_pm.c 2011-03-27 14:31:47.000000000 -0400
2884+++ linux-2.6.32.41/arch/powerpc/platforms/52xx/mpc52xx_pm.c 2011-04-17 15:56:45.000000000 -0400
2885@@ -180,7 +180,7 @@ void mpc52xx_pm_finish(void)
2886 iounmap(mbar);
2887 }
2888
2889-static struct platform_suspend_ops mpc52xx_pm_ops = {
2890+static const struct platform_suspend_ops mpc52xx_pm_ops = {
2891 .valid = mpc52xx_pm_valid,
2892 .prepare = mpc52xx_pm_prepare,
2893 .enter = mpc52xx_pm_enter,
2894diff -urNp linux-2.6.32.41/arch/powerpc/platforms/83xx/suspend.c linux-2.6.32.41/arch/powerpc/platforms/83xx/suspend.c
2895--- linux-2.6.32.41/arch/powerpc/platforms/83xx/suspend.c 2011-03-27 14:31:47.000000000 -0400
2896+++ linux-2.6.32.41/arch/powerpc/platforms/83xx/suspend.c 2011-04-17 15:56:45.000000000 -0400
2897@@ -273,7 +273,7 @@ static int mpc83xx_is_pci_agent(void)
2898 return ret;
2899 }
2900
2901-static struct platform_suspend_ops mpc83xx_suspend_ops = {
2902+static const struct platform_suspend_ops mpc83xx_suspend_ops = {
2903 .valid = mpc83xx_suspend_valid,
2904 .begin = mpc83xx_suspend_begin,
2905 .enter = mpc83xx_suspend_enter,
2906diff -urNp linux-2.6.32.41/arch/powerpc/platforms/cell/iommu.c linux-2.6.32.41/arch/powerpc/platforms/cell/iommu.c
2907--- linux-2.6.32.41/arch/powerpc/platforms/cell/iommu.c 2011-03-27 14:31:47.000000000 -0400
2908+++ linux-2.6.32.41/arch/powerpc/platforms/cell/iommu.c 2011-04-17 15:56:45.000000000 -0400
2909@@ -642,7 +642,7 @@ static int dma_fixed_dma_supported(struc
2910
2911 static int dma_set_mask_and_switch(struct device *dev, u64 dma_mask);
2912
2913-struct dma_map_ops dma_iommu_fixed_ops = {
2914+const struct dma_map_ops dma_iommu_fixed_ops = {
2915 .alloc_coherent = dma_fixed_alloc_coherent,
2916 .free_coherent = dma_fixed_free_coherent,
2917 .map_sg = dma_fixed_map_sg,
2918diff -urNp linux-2.6.32.41/arch/powerpc/platforms/ps3/system-bus.c linux-2.6.32.41/arch/powerpc/platforms/ps3/system-bus.c
2919--- linux-2.6.32.41/arch/powerpc/platforms/ps3/system-bus.c 2011-03-27 14:31:47.000000000 -0400
2920+++ linux-2.6.32.41/arch/powerpc/platforms/ps3/system-bus.c 2011-04-17 15:56:45.000000000 -0400
2921@@ -694,7 +694,7 @@ static int ps3_dma_supported(struct devi
2922 return mask >= DMA_BIT_MASK(32);
2923 }
2924
2925-static struct dma_map_ops ps3_sb_dma_ops = {
2926+static const struct dma_map_ops ps3_sb_dma_ops = {
2927 .alloc_coherent = ps3_alloc_coherent,
2928 .free_coherent = ps3_free_coherent,
2929 .map_sg = ps3_sb_map_sg,
2930@@ -704,7 +704,7 @@ static struct dma_map_ops ps3_sb_dma_ops
2931 .unmap_page = ps3_unmap_page,
2932 };
2933
2934-static struct dma_map_ops ps3_ioc0_dma_ops = {
2935+static const struct dma_map_ops ps3_ioc0_dma_ops = {
2936 .alloc_coherent = ps3_alloc_coherent,
2937 .free_coherent = ps3_free_coherent,
2938 .map_sg = ps3_ioc0_map_sg,
2939diff -urNp linux-2.6.32.41/arch/powerpc/platforms/pseries/Kconfig linux-2.6.32.41/arch/powerpc/platforms/pseries/Kconfig
2940--- linux-2.6.32.41/arch/powerpc/platforms/pseries/Kconfig 2011-03-27 14:31:47.000000000 -0400
2941+++ linux-2.6.32.41/arch/powerpc/platforms/pseries/Kconfig 2011-04-17 15:56:45.000000000 -0400
2942@@ -2,6 +2,8 @@ config PPC_PSERIES
2943 depends on PPC64 && PPC_BOOK3S
2944 bool "IBM pSeries & new (POWER5-based) iSeries"
2945 select MPIC
2946+ select PCI_MSI
2947+ select XICS
2948 select PPC_I8259
2949 select PPC_RTAS
2950 select RTAS_ERROR_LOGGING
2951diff -urNp linux-2.6.32.41/arch/s390/include/asm/elf.h linux-2.6.32.41/arch/s390/include/asm/elf.h
2952--- linux-2.6.32.41/arch/s390/include/asm/elf.h 2011-03-27 14:31:47.000000000 -0400
2953+++ linux-2.6.32.41/arch/s390/include/asm/elf.h 2011-04-17 15:56:45.000000000 -0400
2954@@ -164,6 +164,13 @@ extern unsigned int vdso_enabled;
2955 that it will "exec", and that there is sufficient room for the brk. */
2956 #define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
2957
2958+#ifdef CONFIG_PAX_ASLR
2959+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
2960+
2961+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26 )
2962+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26 )
2963+#endif
2964+
2965 /* This yields a mask that user programs can use to figure out what
2966 instruction set this CPU supports. */
2967
2968diff -urNp linux-2.6.32.41/arch/s390/include/asm/setup.h linux-2.6.32.41/arch/s390/include/asm/setup.h
2969--- linux-2.6.32.41/arch/s390/include/asm/setup.h 2011-03-27 14:31:47.000000000 -0400
2970+++ linux-2.6.32.41/arch/s390/include/asm/setup.h 2011-04-17 15:56:45.000000000 -0400
2971@@ -50,13 +50,13 @@ extern unsigned long memory_end;
2972 void detect_memory_layout(struct mem_chunk chunk[]);
2973
2974 #ifdef CONFIG_S390_SWITCH_AMODE
2975-extern unsigned int switch_amode;
2976+#define switch_amode (1)
2977 #else
2978 #define switch_amode (0)
2979 #endif
2980
2981 #ifdef CONFIG_S390_EXEC_PROTECT
2982-extern unsigned int s390_noexec;
2983+#define s390_noexec (1)
2984 #else
2985 #define s390_noexec (0)
2986 #endif
2987diff -urNp linux-2.6.32.41/arch/s390/include/asm/uaccess.h linux-2.6.32.41/arch/s390/include/asm/uaccess.h
2988--- linux-2.6.32.41/arch/s390/include/asm/uaccess.h 2011-03-27 14:31:47.000000000 -0400
2989+++ linux-2.6.32.41/arch/s390/include/asm/uaccess.h 2011-04-17 15:56:45.000000000 -0400
2990@@ -232,6 +232,10 @@ static inline unsigned long __must_check
2991 copy_to_user(void __user *to, const void *from, unsigned long n)
2992 {
2993 might_fault();
2994+
2995+ if ((long)n < 0)
2996+ return n;
2997+
2998 if (access_ok(VERIFY_WRITE, to, n))
2999 n = __copy_to_user(to, from, n);
3000 return n;
3001@@ -257,6 +261,9 @@ copy_to_user(void __user *to, const void
3002 static inline unsigned long __must_check
3003 __copy_from_user(void *to, const void __user *from, unsigned long n)
3004 {
3005+ if ((long)n < 0)
3006+ return n;
3007+
3008 if (__builtin_constant_p(n) && (n <= 256))
3009 return uaccess.copy_from_user_small(n, from, to);
3010 else
3011@@ -283,6 +290,10 @@ static inline unsigned long __must_check
3012 copy_from_user(void *to, const void __user *from, unsigned long n)
3013 {
3014 might_fault();
3015+
3016+ if ((long)n < 0)
3017+ return n;
3018+
3019 if (access_ok(VERIFY_READ, from, n))
3020 n = __copy_from_user(to, from, n);
3021 else
3022diff -urNp linux-2.6.32.41/arch/s390/Kconfig linux-2.6.32.41/arch/s390/Kconfig
3023--- linux-2.6.32.41/arch/s390/Kconfig 2011-03-27 14:31:47.000000000 -0400
3024+++ linux-2.6.32.41/arch/s390/Kconfig 2011-04-17 15:56:45.000000000 -0400
3025@@ -194,28 +194,26 @@ config AUDIT_ARCH
3026
3027 config S390_SWITCH_AMODE
3028 bool "Switch kernel/user addressing modes"
3029+ default y
3030 help
3031 This option allows to switch the addressing modes of kernel and user
3032- space. The kernel parameter switch_amode=on will enable this feature,
3033- default is disabled. Enabling this (via kernel parameter) on machines
3034- earlier than IBM System z9-109 EC/BC will reduce system performance.
3035+ space. Enabling this on machines earlier than IBM System z9-109 EC/BC
3036+ will reduce system performance.
3037
3038 Note that this option will also be selected by selecting the execute
3039- protection option below. Enabling the execute protection via the
3040- noexec kernel parameter will also switch the addressing modes,
3041- independent of the switch_amode kernel parameter.
3042+ protection option below. Enabling the execute protection will also
3043+ switch the addressing modes, independent of this option.
3044
3045
3046 config S390_EXEC_PROTECT
3047 bool "Data execute protection"
3048+ default y
3049 select S390_SWITCH_AMODE
3050 help
3051 This option allows to enable a buffer overflow protection for user
3052 space programs and it also selects the addressing mode option above.
3053- The kernel parameter noexec=on will enable this feature and also
3054- switch the addressing modes, default is disabled. Enabling this (via
3055- kernel parameter) on machines earlier than IBM System z9-109 EC/BC
3056- will reduce system performance.
3057+ Enabling this on machines earlier than IBM System z9-109 EC/BC will
3058+ reduce system performance.
3059
3060 comment "Code generation options"
3061
3062diff -urNp linux-2.6.32.41/arch/s390/kernel/module.c linux-2.6.32.41/arch/s390/kernel/module.c
3063--- linux-2.6.32.41/arch/s390/kernel/module.c 2011-03-27 14:31:47.000000000 -0400
3064+++ linux-2.6.32.41/arch/s390/kernel/module.c 2011-04-17 15:56:45.000000000 -0400
3065@@ -166,11 +166,11 @@ module_frob_arch_sections(Elf_Ehdr *hdr,
3066
3067 /* Increase core size by size of got & plt and set start
3068 offsets for got and plt. */
3069- me->core_size = ALIGN(me->core_size, 4);
3070- me->arch.got_offset = me->core_size;
3071- me->core_size += me->arch.got_size;
3072- me->arch.plt_offset = me->core_size;
3073- me->core_size += me->arch.plt_size;
3074+ me->core_size_rw = ALIGN(me->core_size_rw, 4);
3075+ me->arch.got_offset = me->core_size_rw;
3076+ me->core_size_rw += me->arch.got_size;
3077+ me->arch.plt_offset = me->core_size_rx;
3078+ me->core_size_rx += me->arch.plt_size;
3079 return 0;
3080 }
3081
3082@@ -256,7 +256,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base
3083 if (info->got_initialized == 0) {
3084 Elf_Addr *gotent;
3085
3086- gotent = me->module_core + me->arch.got_offset +
3087+ gotent = me->module_core_rw + me->arch.got_offset +
3088 info->got_offset;
3089 *gotent = val;
3090 info->got_initialized = 1;
3091@@ -280,7 +280,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base
3092 else if (r_type == R_390_GOTENT ||
3093 r_type == R_390_GOTPLTENT)
3094 *(unsigned int *) loc =
3095- (val + (Elf_Addr) me->module_core - loc) >> 1;
3096+ (val + (Elf_Addr) me->module_core_rw - loc) >> 1;
3097 else if (r_type == R_390_GOT64 ||
3098 r_type == R_390_GOTPLT64)
3099 *(unsigned long *) loc = val;
3100@@ -294,7 +294,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base
3101 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
3102 if (info->plt_initialized == 0) {
3103 unsigned int *ip;
3104- ip = me->module_core + me->arch.plt_offset +
3105+ ip = me->module_core_rx + me->arch.plt_offset +
3106 info->plt_offset;
3107 #ifndef CONFIG_64BIT
3108 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
3109@@ -319,7 +319,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base
3110 val - loc + 0xffffUL < 0x1ffffeUL) ||
3111 (r_type == R_390_PLT32DBL &&
3112 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
3113- val = (Elf_Addr) me->module_core +
3114+ val = (Elf_Addr) me->module_core_rx +
3115 me->arch.plt_offset +
3116 info->plt_offset;
3117 val += rela->r_addend - loc;
3118@@ -341,7 +341,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base
3119 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
3120 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
3121 val = val + rela->r_addend -
3122- ((Elf_Addr) me->module_core + me->arch.got_offset);
3123+ ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
3124 if (r_type == R_390_GOTOFF16)
3125 *(unsigned short *) loc = val;
3126 else if (r_type == R_390_GOTOFF32)
3127@@ -351,7 +351,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base
3128 break;
3129 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
3130 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
3131- val = (Elf_Addr) me->module_core + me->arch.got_offset +
3132+ val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
3133 rela->r_addend - loc;
3134 if (r_type == R_390_GOTPC)
3135 *(unsigned int *) loc = val;
3136diff -urNp linux-2.6.32.41/arch/s390/kernel/setup.c linux-2.6.32.41/arch/s390/kernel/setup.c
3137--- linux-2.6.32.41/arch/s390/kernel/setup.c 2011-03-27 14:31:47.000000000 -0400
3138+++ linux-2.6.32.41/arch/s390/kernel/setup.c 2011-04-17 15:56:45.000000000 -0400
3139@@ -306,9 +306,6 @@ static int __init early_parse_mem(char *
3140 early_param("mem", early_parse_mem);
3141
3142 #ifdef CONFIG_S390_SWITCH_AMODE
3143-unsigned int switch_amode = 0;
3144-EXPORT_SYMBOL_GPL(switch_amode);
3145-
3146 static int set_amode_and_uaccess(unsigned long user_amode,
3147 unsigned long user32_amode)
3148 {
3149@@ -334,17 +331,6 @@ static int set_amode_and_uaccess(unsigne
3150 return 0;
3151 }
3152 }
3153-
3154-/*
3155- * Switch kernel/user addressing modes?
3156- */
3157-static int __init early_parse_switch_amode(char *p)
3158-{
3159- switch_amode = 1;
3160- return 0;
3161-}
3162-early_param("switch_amode", early_parse_switch_amode);
3163-
3164 #else /* CONFIG_S390_SWITCH_AMODE */
3165 static inline int set_amode_and_uaccess(unsigned long user_amode,
3166 unsigned long user32_amode)
3167@@ -353,24 +339,6 @@ static inline int set_amode_and_uaccess(
3168 }
3169 #endif /* CONFIG_S390_SWITCH_AMODE */
3170
3171-#ifdef CONFIG_S390_EXEC_PROTECT
3172-unsigned int s390_noexec = 0;
3173-EXPORT_SYMBOL_GPL(s390_noexec);
3174-
3175-/*
3176- * Enable execute protection?
3177- */
3178-static int __init early_parse_noexec(char *p)
3179-{
3180- if (!strncmp(p, "off", 3))
3181- return 0;
3182- switch_amode = 1;
3183- s390_noexec = 1;
3184- return 0;
3185-}
3186-early_param("noexec", early_parse_noexec);
3187-#endif /* CONFIG_S390_EXEC_PROTECT */
3188-
3189 static void setup_addressing_mode(void)
3190 {
3191 if (s390_noexec) {
3192diff -urNp linux-2.6.32.41/arch/s390/mm/mmap.c linux-2.6.32.41/arch/s390/mm/mmap.c
3193--- linux-2.6.32.41/arch/s390/mm/mmap.c 2011-03-27 14:31:47.000000000 -0400
3194+++ linux-2.6.32.41/arch/s390/mm/mmap.c 2011-04-17 15:56:45.000000000 -0400
3195@@ -78,10 +78,22 @@ void arch_pick_mmap_layout(struct mm_str
3196 */
3197 if (mmap_is_legacy()) {
3198 mm->mmap_base = TASK_UNMAPPED_BASE;
3199+
3200+#ifdef CONFIG_PAX_RANDMMAP
3201+ if (mm->pax_flags & MF_PAX_RANDMMAP)
3202+ mm->mmap_base += mm->delta_mmap;
3203+#endif
3204+
3205 mm->get_unmapped_area = arch_get_unmapped_area;
3206 mm->unmap_area = arch_unmap_area;
3207 } else {
3208 mm->mmap_base = mmap_base();
3209+
3210+#ifdef CONFIG_PAX_RANDMMAP
3211+ if (mm->pax_flags & MF_PAX_RANDMMAP)
3212+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
3213+#endif
3214+
3215 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
3216 mm->unmap_area = arch_unmap_area_topdown;
3217 }
3218@@ -153,10 +165,22 @@ void arch_pick_mmap_layout(struct mm_str
3219 */
3220 if (mmap_is_legacy()) {
3221 mm->mmap_base = TASK_UNMAPPED_BASE;
3222+
3223+#ifdef CONFIG_PAX_RANDMMAP
3224+ if (mm->pax_flags & MF_PAX_RANDMMAP)
3225+ mm->mmap_base += mm->delta_mmap;
3226+#endif
3227+
3228 mm->get_unmapped_area = s390_get_unmapped_area;
3229 mm->unmap_area = arch_unmap_area;
3230 } else {
3231 mm->mmap_base = mmap_base();
3232+
3233+#ifdef CONFIG_PAX_RANDMMAP
3234+ if (mm->pax_flags & MF_PAX_RANDMMAP)
3235+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
3236+#endif
3237+
3238 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
3239 mm->unmap_area = arch_unmap_area_topdown;
3240 }
3241diff -urNp linux-2.6.32.41/arch/score/include/asm/system.h linux-2.6.32.41/arch/score/include/asm/system.h
3242--- linux-2.6.32.41/arch/score/include/asm/system.h 2011-03-27 14:31:47.000000000 -0400
3243+++ linux-2.6.32.41/arch/score/include/asm/system.h 2011-04-17 15:56:45.000000000 -0400
3244@@ -17,7 +17,7 @@ do { \
3245 #define finish_arch_switch(prev) do {} while (0)
3246
3247 typedef void (*vi_handler_t)(void);
3248-extern unsigned long arch_align_stack(unsigned long sp);
3249+#define arch_align_stack(x) (x)
3250
3251 #define mb() barrier()
3252 #define rmb() barrier()
3253diff -urNp linux-2.6.32.41/arch/score/kernel/process.c linux-2.6.32.41/arch/score/kernel/process.c
3254--- linux-2.6.32.41/arch/score/kernel/process.c 2011-03-27 14:31:47.000000000 -0400
3255+++ linux-2.6.32.41/arch/score/kernel/process.c 2011-04-17 15:56:45.000000000 -0400
3256@@ -161,8 +161,3 @@ unsigned long get_wchan(struct task_stru
3257
3258 return task_pt_regs(task)->cp0_epc;
3259 }
3260-
3261-unsigned long arch_align_stack(unsigned long sp)
3262-{
3263- return sp;
3264-}
3265diff -urNp linux-2.6.32.41/arch/sh/boards/mach-hp6xx/pm.c linux-2.6.32.41/arch/sh/boards/mach-hp6xx/pm.c
3266--- linux-2.6.32.41/arch/sh/boards/mach-hp6xx/pm.c 2011-03-27 14:31:47.000000000 -0400
3267+++ linux-2.6.32.41/arch/sh/boards/mach-hp6xx/pm.c 2011-04-17 15:56:45.000000000 -0400
3268@@ -143,7 +143,7 @@ static int hp6x0_pm_enter(suspend_state_
3269 return 0;
3270 }
3271
3272-static struct platform_suspend_ops hp6x0_pm_ops = {
3273+static const struct platform_suspend_ops hp6x0_pm_ops = {
3274 .enter = hp6x0_pm_enter,
3275 .valid = suspend_valid_only_mem,
3276 };
3277diff -urNp linux-2.6.32.41/arch/sh/kernel/cpu/sh4/sq.c linux-2.6.32.41/arch/sh/kernel/cpu/sh4/sq.c
3278--- linux-2.6.32.41/arch/sh/kernel/cpu/sh4/sq.c 2011-03-27 14:31:47.000000000 -0400
3279+++ linux-2.6.32.41/arch/sh/kernel/cpu/sh4/sq.c 2011-04-17 15:56:46.000000000 -0400
3280@@ -327,7 +327,7 @@ static struct attribute *sq_sysfs_attrs[
3281 NULL,
3282 };
3283
3284-static struct sysfs_ops sq_sysfs_ops = {
3285+static const struct sysfs_ops sq_sysfs_ops = {
3286 .show = sq_sysfs_show,
3287 .store = sq_sysfs_store,
3288 };
3289diff -urNp linux-2.6.32.41/arch/sh/kernel/cpu/shmobile/pm.c linux-2.6.32.41/arch/sh/kernel/cpu/shmobile/pm.c
3290--- linux-2.6.32.41/arch/sh/kernel/cpu/shmobile/pm.c 2011-03-27 14:31:47.000000000 -0400
3291+++ linux-2.6.32.41/arch/sh/kernel/cpu/shmobile/pm.c 2011-04-17 15:56:46.000000000 -0400
3292@@ -58,7 +58,7 @@ static int sh_pm_enter(suspend_state_t s
3293 return 0;
3294 }
3295
3296-static struct platform_suspend_ops sh_pm_ops = {
3297+static const struct platform_suspend_ops sh_pm_ops = {
3298 .enter = sh_pm_enter,
3299 .valid = suspend_valid_only_mem,
3300 };
3301diff -urNp linux-2.6.32.41/arch/sh/kernel/kgdb.c linux-2.6.32.41/arch/sh/kernel/kgdb.c
3302--- linux-2.6.32.41/arch/sh/kernel/kgdb.c 2011-03-27 14:31:47.000000000 -0400
3303+++ linux-2.6.32.41/arch/sh/kernel/kgdb.c 2011-04-17 15:56:46.000000000 -0400
3304@@ -271,7 +271,7 @@ void kgdb_arch_exit(void)
3305 {
3306 }
3307
3308-struct kgdb_arch arch_kgdb_ops = {
3309+const struct kgdb_arch arch_kgdb_ops = {
3310 /* Breakpoint instruction: trapa #0x3c */
3311 #ifdef CONFIG_CPU_LITTLE_ENDIAN
3312 .gdb_bpt_instr = { 0x3c, 0xc3 },
3313diff -urNp linux-2.6.32.41/arch/sh/mm/mmap.c linux-2.6.32.41/arch/sh/mm/mmap.c
3314--- linux-2.6.32.41/arch/sh/mm/mmap.c 2011-03-27 14:31:47.000000000 -0400
3315+++ linux-2.6.32.41/arch/sh/mm/mmap.c 2011-04-17 15:56:46.000000000 -0400
3316@@ -74,8 +74,7 @@ unsigned long arch_get_unmapped_area(str
3317 addr = PAGE_ALIGN(addr);
3318
3319 vma = find_vma(mm, addr);
3320- if (TASK_SIZE - len >= addr &&
3321- (!vma || addr + len <= vma->vm_start))
3322+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
3323 return addr;
3324 }
3325
3326@@ -106,7 +105,7 @@ full_search:
3327 }
3328 return -ENOMEM;
3329 }
3330- if (likely(!vma || addr + len <= vma->vm_start)) {
3331+ if (likely(check_heap_stack_gap(vma, addr, len))) {
3332 /*
3333 * Remember the place where we stopped the search:
3334 */
3335@@ -157,8 +156,7 @@ arch_get_unmapped_area_topdown(struct fi
3336 addr = PAGE_ALIGN(addr);
3337
3338 vma = find_vma(mm, addr);
3339- if (TASK_SIZE - len >= addr &&
3340- (!vma || addr + len <= vma->vm_start))
3341+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
3342 return addr;
3343 }
3344
3345@@ -179,7 +177,7 @@ arch_get_unmapped_area_topdown(struct fi
3346 /* make sure it can fit in the remaining address space */
3347 if (likely(addr > len)) {
3348 vma = find_vma(mm, addr-len);
3349- if (!vma || addr <= vma->vm_start) {
3350+ if (check_heap_stack_gap(vma, addr - len, len)) {
3351 /* remember the address as a hint for next time */
3352 return (mm->free_area_cache = addr-len);
3353 }
3354@@ -188,18 +186,18 @@ arch_get_unmapped_area_topdown(struct fi
3355 if (unlikely(mm->mmap_base < len))
3356 goto bottomup;
3357
3358- addr = mm->mmap_base-len;
3359- if (do_colour_align)
3360- addr = COLOUR_ALIGN_DOWN(addr, pgoff);
3361+ addr = mm->mmap_base - len;
3362
3363 do {
3364+ if (do_colour_align)
3365+ addr = COLOUR_ALIGN_DOWN(addr, pgoff);
3366 /*
3367 * Lookup failure means no vma is above this address,
3368 * else if new region fits below vma->vm_start,
3369 * return with success:
3370 */
3371 vma = find_vma(mm, addr);
3372- if (likely(!vma || addr+len <= vma->vm_start)) {
3373+ if (likely(check_heap_stack_gap(vma, addr, len))) {
3374 /* remember the address as a hint for next time */
3375 return (mm->free_area_cache = addr);
3376 }
3377@@ -209,10 +207,8 @@ arch_get_unmapped_area_topdown(struct fi
3378 mm->cached_hole_size = vma->vm_start - addr;
3379
3380 /* try just below the current vma->vm_start */
3381- addr = vma->vm_start-len;
3382- if (do_colour_align)
3383- addr = COLOUR_ALIGN_DOWN(addr, pgoff);
3384- } while (likely(len < vma->vm_start));
3385+ addr = skip_heap_stack_gap(vma, len);
3386+ } while (!IS_ERR_VALUE(addr));
3387
3388 bottomup:
3389 /*
3390diff -urNp linux-2.6.32.41/arch/sparc/include/asm/atomic_64.h linux-2.6.32.41/arch/sparc/include/asm/atomic_64.h
3391--- linux-2.6.32.41/arch/sparc/include/asm/atomic_64.h 2011-03-27 14:31:47.000000000 -0400
3392+++ linux-2.6.32.41/arch/sparc/include/asm/atomic_64.h 2011-05-04 17:56:20.000000000 -0400
3393@@ -14,18 +14,40 @@
3394 #define ATOMIC64_INIT(i) { (i) }
3395
3396 #define atomic_read(v) ((v)->counter)
3397+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
3398+{
3399+ return v->counter;
3400+}
3401 #define atomic64_read(v) ((v)->counter)
3402+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
3403+{
3404+ return v->counter;
3405+}
3406
3407 #define atomic_set(v, i) (((v)->counter) = i)
3408+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
3409+{
3410+ v->counter = i;
3411+}
3412 #define atomic64_set(v, i) (((v)->counter) = i)
3413+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
3414+{
3415+ v->counter = i;
3416+}
3417
3418 extern void atomic_add(int, atomic_t *);
3419+extern void atomic_add_unchecked(int, atomic_unchecked_t *);
3420 extern void atomic64_add(long, atomic64_t *);
3421+extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
3422 extern void atomic_sub(int, atomic_t *);
3423+extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
3424 extern void atomic64_sub(long, atomic64_t *);
3425+extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
3426
3427 extern int atomic_add_ret(int, atomic_t *);
3428+extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
3429 extern long atomic64_add_ret(long, atomic64_t *);
3430+extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
3431 extern int atomic_sub_ret(int, atomic_t *);
3432 extern long atomic64_sub_ret(long, atomic64_t *);
3433
3434@@ -33,7 +55,15 @@ extern long atomic64_sub_ret(long, atomi
3435 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
3436
3437 #define atomic_inc_return(v) atomic_add_ret(1, v)
3438+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
3439+{
3440+ return atomic_add_ret_unchecked(1, v);
3441+}
3442 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
3443+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
3444+{
3445+ return atomic64_add_ret_unchecked(1, v);
3446+}
3447
3448 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
3449 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
3450@@ -50,6 +80,7 @@ extern long atomic64_sub_ret(long, atomi
3451 * other cases.
3452 */
3453 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
3454+#define atomic_inc_and_test_unchecked(v) (atomic_inc_return_unchecked(v) == 0)
3455 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
3456
3457 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
3458@@ -59,30 +90,59 @@ extern long atomic64_sub_ret(long, atomi
3459 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
3460
3461 #define atomic_inc(v) atomic_add(1, v)
3462+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
3463+{
3464+ atomic_add_unchecked(1, v);
3465+}
3466 #define atomic64_inc(v) atomic64_add(1, v)
3467+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
3468+{
3469+ atomic64_add_unchecked(1, v);
3470+}
3471
3472 #define atomic_dec(v) atomic_sub(1, v)
3473+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
3474+{
3475+ atomic_sub_unchecked(1, v);
3476+}
3477 #define atomic64_dec(v) atomic64_sub(1, v)
3478+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
3479+{
3480+ atomic64_sub_unchecked(1, v);
3481+}
3482
3483 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
3484 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
3485
3486 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
3487+#define atomic_cmpxchg_unchecked(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
3488 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
3489+#define atomic_xchg_unchecked(v, new) (xchg(&((v)->counter), new))
3490
3491 static inline int atomic_add_unless(atomic_t *v, int a, int u)
3492 {
3493- int c, old;
3494+ int c, old, new;
3495 c = atomic_read(v);
3496 for (;;) {
3497- if (unlikely(c == (u)))
3498+ if (unlikely(c == u))
3499 break;
3500- old = atomic_cmpxchg((v), c, c + (a));
3501+
3502+ asm volatile("addcc %2, %0, %0\n"
3503+
3504+#ifdef CONFIG_PAX_REFCOUNT
3505+ "tvs %%icc, 6\n"
3506+#endif
3507+
3508+ : "=r" (new)
3509+ : "0" (c), "ir" (a)
3510+ : "cc");
3511+
3512+ old = atomic_cmpxchg(v, c, new);
3513 if (likely(old == c))
3514 break;
3515 c = old;
3516 }
3517- return c != (u);
3518+ return c != u;
3519 }
3520
3521 #define atomic_inc_not_zero(v) atomic_add_unless((v), 1, 0)
3522@@ -93,17 +153,28 @@ static inline int atomic_add_unless(atom
3523
3524 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
3525 {
3526- long c, old;
3527+ long c, old, new;
3528 c = atomic64_read(v);
3529 for (;;) {
3530- if (unlikely(c == (u)))
3531+ if (unlikely(c == u))
3532 break;
3533- old = atomic64_cmpxchg((v), c, c + (a));
3534+
3535+ asm volatile("addcc %2, %0, %0\n"
3536+
3537+#ifdef CONFIG_PAX_REFCOUNT
3538+ "tvs %%xcc, 6\n"
3539+#endif
3540+
3541+ : "=r" (new)
3542+ : "0" (c), "ir" (a)
3543+ : "cc");
3544+
3545+ old = atomic64_cmpxchg(v, c, new);
3546 if (likely(old == c))
3547 break;
3548 c = old;
3549 }
3550- return c != (u);
3551+ return c != u;
3552 }
3553
3554 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
3555diff -urNp linux-2.6.32.41/arch/sparc/include/asm/cache.h linux-2.6.32.41/arch/sparc/include/asm/cache.h
3556--- linux-2.6.32.41/arch/sparc/include/asm/cache.h 2011-03-27 14:31:47.000000000 -0400
3557+++ linux-2.6.32.41/arch/sparc/include/asm/cache.h 2011-05-17 19:26:34.000000000 -0400
3558@@ -8,7 +8,7 @@
3559 #define _SPARC_CACHE_H
3560
3561 #define L1_CACHE_SHIFT 5
3562-#define L1_CACHE_BYTES 32
3563+#define L1_CACHE_BYTES 32U
3564 #define L1_CACHE_ALIGN(x) ((((x)+(L1_CACHE_BYTES-1))&~(L1_CACHE_BYTES-1)))
3565
3566 #ifdef CONFIG_SPARC32
3567diff -urNp linux-2.6.32.41/arch/sparc/include/asm/dma-mapping.h linux-2.6.32.41/arch/sparc/include/asm/dma-mapping.h
3568--- linux-2.6.32.41/arch/sparc/include/asm/dma-mapping.h 2011-03-27 14:31:47.000000000 -0400
3569+++ linux-2.6.32.41/arch/sparc/include/asm/dma-mapping.h 2011-04-17 15:56:46.000000000 -0400
3570@@ -14,10 +14,10 @@ extern int dma_set_mask(struct device *d
3571 #define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h)
3572 #define dma_is_consistent(d, h) (1)
3573
3574-extern struct dma_map_ops *dma_ops, pci32_dma_ops;
3575+extern const struct dma_map_ops *dma_ops, pci32_dma_ops;
3576 extern struct bus_type pci_bus_type;
3577
3578-static inline struct dma_map_ops *get_dma_ops(struct device *dev)
3579+static inline const struct dma_map_ops *get_dma_ops(struct device *dev)
3580 {
3581 #if defined(CONFIG_SPARC32) && defined(CONFIG_PCI)
3582 if (dev->bus == &pci_bus_type)
3583@@ -31,7 +31,7 @@ static inline struct dma_map_ops *get_dm
3584 static inline void *dma_alloc_coherent(struct device *dev, size_t size,
3585 dma_addr_t *dma_handle, gfp_t flag)
3586 {
3587- struct dma_map_ops *ops = get_dma_ops(dev);
3588+ const struct dma_map_ops *ops = get_dma_ops(dev);
3589 void *cpu_addr;
3590
3591 cpu_addr = ops->alloc_coherent(dev, size, dma_handle, flag);
3592@@ -42,7 +42,7 @@ static inline void *dma_alloc_coherent(s
3593 static inline void dma_free_coherent(struct device *dev, size_t size,
3594 void *cpu_addr, dma_addr_t dma_handle)
3595 {
3596- struct dma_map_ops *ops = get_dma_ops(dev);
3597+ const struct dma_map_ops *ops = get_dma_ops(dev);
3598
3599 debug_dma_free_coherent(dev, size, cpu_addr, dma_handle);
3600 ops->free_coherent(dev, size, cpu_addr, dma_handle);
3601diff -urNp linux-2.6.32.41/arch/sparc/include/asm/elf_32.h linux-2.6.32.41/arch/sparc/include/asm/elf_32.h
3602--- linux-2.6.32.41/arch/sparc/include/asm/elf_32.h 2011-03-27 14:31:47.000000000 -0400
3603+++ linux-2.6.32.41/arch/sparc/include/asm/elf_32.h 2011-04-17 15:56:46.000000000 -0400
3604@@ -116,6 +116,13 @@ typedef struct {
3605
3606 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
3607
3608+#ifdef CONFIG_PAX_ASLR
3609+#define PAX_ELF_ET_DYN_BASE 0x10000UL
3610+
3611+#define PAX_DELTA_MMAP_LEN 16
3612+#define PAX_DELTA_STACK_LEN 16
3613+#endif
3614+
3615 /* This yields a mask that user programs can use to figure out what
3616 instruction set this cpu supports. This can NOT be done in userspace
3617 on Sparc. */
3618diff -urNp linux-2.6.32.41/arch/sparc/include/asm/elf_64.h linux-2.6.32.41/arch/sparc/include/asm/elf_64.h
3619--- linux-2.6.32.41/arch/sparc/include/asm/elf_64.h 2011-03-27 14:31:47.000000000 -0400
3620+++ linux-2.6.32.41/arch/sparc/include/asm/elf_64.h 2011-04-17 15:56:46.000000000 -0400
3621@@ -163,6 +163,12 @@ typedef struct {
3622 #define ELF_ET_DYN_BASE 0x0000010000000000UL
3623 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
3624
3625+#ifdef CONFIG_PAX_ASLR
3626+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
3627+
3628+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
3629+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
3630+#endif
3631
3632 /* This yields a mask that user programs can use to figure out what
3633 instruction set this cpu supports. */
3634diff -urNp linux-2.6.32.41/arch/sparc/include/asm/pgtable_32.h linux-2.6.32.41/arch/sparc/include/asm/pgtable_32.h
3635--- linux-2.6.32.41/arch/sparc/include/asm/pgtable_32.h 2011-03-27 14:31:47.000000000 -0400
3636+++ linux-2.6.32.41/arch/sparc/include/asm/pgtable_32.h 2011-04-17 15:56:46.000000000 -0400
3637@@ -43,6 +43,13 @@ BTFIXUPDEF_SIMM13(user_ptrs_per_pgd)
3638 BTFIXUPDEF_INT(page_none)
3639 BTFIXUPDEF_INT(page_copy)
3640 BTFIXUPDEF_INT(page_readonly)
3641+
3642+#ifdef CONFIG_PAX_PAGEEXEC
3643+BTFIXUPDEF_INT(page_shared_noexec)
3644+BTFIXUPDEF_INT(page_copy_noexec)
3645+BTFIXUPDEF_INT(page_readonly_noexec)
3646+#endif
3647+
3648 BTFIXUPDEF_INT(page_kernel)
3649
3650 #define PMD_SHIFT SUN4C_PMD_SHIFT
3651@@ -64,6 +71,16 @@ extern pgprot_t PAGE_SHARED;
3652 #define PAGE_COPY __pgprot(BTFIXUP_INT(page_copy))
3653 #define PAGE_READONLY __pgprot(BTFIXUP_INT(page_readonly))
3654
3655+#ifdef CONFIG_PAX_PAGEEXEC
3656+extern pgprot_t PAGE_SHARED_NOEXEC;
3657+# define PAGE_COPY_NOEXEC __pgprot(BTFIXUP_INT(page_copy_noexec))
3658+# define PAGE_READONLY_NOEXEC __pgprot(BTFIXUP_INT(page_readonly_noexec))
3659+#else
3660+# define PAGE_SHARED_NOEXEC PAGE_SHARED
3661+# define PAGE_COPY_NOEXEC PAGE_COPY
3662+# define PAGE_READONLY_NOEXEC PAGE_READONLY
3663+#endif
3664+
3665 extern unsigned long page_kernel;
3666
3667 #ifdef MODULE
3668diff -urNp linux-2.6.32.41/arch/sparc/include/asm/pgtsrmmu.h linux-2.6.32.41/arch/sparc/include/asm/pgtsrmmu.h
3669--- linux-2.6.32.41/arch/sparc/include/asm/pgtsrmmu.h 2011-03-27 14:31:47.000000000 -0400
3670+++ linux-2.6.32.41/arch/sparc/include/asm/pgtsrmmu.h 2011-04-17 15:56:46.000000000 -0400
3671@@ -115,6 +115,13 @@
3672 SRMMU_EXEC | SRMMU_REF)
3673 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
3674 SRMMU_EXEC | SRMMU_REF)
3675+
3676+#ifdef CONFIG_PAX_PAGEEXEC
3677+#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
3678+#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
3679+#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
3680+#endif
3681+
3682 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
3683 SRMMU_DIRTY | SRMMU_REF)
3684
3685diff -urNp linux-2.6.32.41/arch/sparc/include/asm/spinlock_64.h linux-2.6.32.41/arch/sparc/include/asm/spinlock_64.h
3686--- linux-2.6.32.41/arch/sparc/include/asm/spinlock_64.h 2011-03-27 14:31:47.000000000 -0400
3687+++ linux-2.6.32.41/arch/sparc/include/asm/spinlock_64.h 2011-05-04 17:56:20.000000000 -0400
3688@@ -92,14 +92,19 @@ static inline void __raw_spin_lock_flags
3689
3690 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
3691
3692-static void inline arch_read_lock(raw_rwlock_t *lock)
3693+static inline void arch_read_lock(raw_rwlock_t *lock)
3694 {
3695 unsigned long tmp1, tmp2;
3696
3697 __asm__ __volatile__ (
3698 "1: ldsw [%2], %0\n"
3699 " brlz,pn %0, 2f\n"
3700-"4: add %0, 1, %1\n"
3701+"4: addcc %0, 1, %1\n"
3702+
3703+#ifdef CONFIG_PAX_REFCOUNT
3704+" tvs %%icc, 6\n"
3705+#endif
3706+
3707 " cas [%2], %0, %1\n"
3708 " cmp %0, %1\n"
3709 " bne,pn %%icc, 1b\n"
3710@@ -112,7 +117,7 @@ static void inline arch_read_lock(raw_rw
3711 " .previous"
3712 : "=&r" (tmp1), "=&r" (tmp2)
3713 : "r" (lock)
3714- : "memory");
3715+ : "memory", "cc");
3716 }
3717
3718 static int inline arch_read_trylock(raw_rwlock_t *lock)
3719@@ -123,7 +128,12 @@ static int inline arch_read_trylock(raw_
3720 "1: ldsw [%2], %0\n"
3721 " brlz,a,pn %0, 2f\n"
3722 " mov 0, %0\n"
3723-" add %0, 1, %1\n"
3724+" addcc %0, 1, %1\n"
3725+
3726+#ifdef CONFIG_PAX_REFCOUNT
3727+" tvs %%icc, 6\n"
3728+#endif
3729+
3730 " cas [%2], %0, %1\n"
3731 " cmp %0, %1\n"
3732 " bne,pn %%icc, 1b\n"
3733@@ -136,13 +146,18 @@ static int inline arch_read_trylock(raw_
3734 return tmp1;
3735 }
3736
3737-static void inline arch_read_unlock(raw_rwlock_t *lock)
3738+static inline void arch_read_unlock(raw_rwlock_t *lock)
3739 {
3740 unsigned long tmp1, tmp2;
3741
3742 __asm__ __volatile__(
3743 "1: lduw [%2], %0\n"
3744-" sub %0, 1, %1\n"
3745+" subcc %0, 1, %1\n"
3746+
3747+#ifdef CONFIG_PAX_REFCOUNT
3748+" tvs %%icc, 6\n"
3749+#endif
3750+
3751 " cas [%2], %0, %1\n"
3752 " cmp %0, %1\n"
3753 " bne,pn %%xcc, 1b\n"
3754@@ -152,7 +167,7 @@ static void inline arch_read_unlock(raw_
3755 : "memory");
3756 }
3757
3758-static void inline arch_write_lock(raw_rwlock_t *lock)
3759+static inline void arch_write_lock(raw_rwlock_t *lock)
3760 {
3761 unsigned long mask, tmp1, tmp2;
3762
3763@@ -177,7 +192,7 @@ static void inline arch_write_lock(raw_r
3764 : "memory");
3765 }
3766
3767-static void inline arch_write_unlock(raw_rwlock_t *lock)
3768+static inline void arch_write_unlock(raw_rwlock_t *lock)
3769 {
3770 __asm__ __volatile__(
3771 " stw %%g0, [%0]"
3772diff -urNp linux-2.6.32.41/arch/sparc/include/asm/thread_info_32.h linux-2.6.32.41/arch/sparc/include/asm/thread_info_32.h
3773--- linux-2.6.32.41/arch/sparc/include/asm/thread_info_32.h 2011-03-27 14:31:47.000000000 -0400
3774+++ linux-2.6.32.41/arch/sparc/include/asm/thread_info_32.h 2011-06-04 20:46:01.000000000 -0400
3775@@ -50,6 +50,8 @@ struct thread_info {
3776 unsigned long w_saved;
3777
3778 struct restart_block restart_block;
3779+
3780+ unsigned long lowest_stack;
3781 };
3782
3783 /*
3784diff -urNp linux-2.6.32.41/arch/sparc/include/asm/thread_info_64.h linux-2.6.32.41/arch/sparc/include/asm/thread_info_64.h
3785--- linux-2.6.32.41/arch/sparc/include/asm/thread_info_64.h 2011-03-27 14:31:47.000000000 -0400
3786+++ linux-2.6.32.41/arch/sparc/include/asm/thread_info_64.h 2011-06-04 20:46:21.000000000 -0400
3787@@ -68,6 +68,8 @@ struct thread_info {
3788 struct pt_regs *kern_una_regs;
3789 unsigned int kern_una_insn;
3790
3791+ unsigned long lowest_stack;
3792+
3793 unsigned long fpregs[0] __attribute__ ((aligned(64)));
3794 };
3795
3796diff -urNp linux-2.6.32.41/arch/sparc/include/asm/uaccess_32.h linux-2.6.32.41/arch/sparc/include/asm/uaccess_32.h
3797--- linux-2.6.32.41/arch/sparc/include/asm/uaccess_32.h 2011-03-27 14:31:47.000000000 -0400
3798+++ linux-2.6.32.41/arch/sparc/include/asm/uaccess_32.h 2011-04-17 15:56:46.000000000 -0400
3799@@ -249,27 +249,46 @@ extern unsigned long __copy_user(void __
3800
3801 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
3802 {
3803- if (n && __access_ok((unsigned long) to, n))
3804+ if ((long)n < 0)
3805+ return n;
3806+
3807+ if (n && __access_ok((unsigned long) to, n)) {
3808+ if (!__builtin_constant_p(n))
3809+ check_object_size(from, n, true);
3810 return __copy_user(to, (__force void __user *) from, n);
3811- else
3812+ } else
3813 return n;
3814 }
3815
3816 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
3817 {
3818+ if ((long)n < 0)
3819+ return n;
3820+
3821+ if (!__builtin_constant_p(n))
3822+ check_object_size(from, n, true);
3823+
3824 return __copy_user(to, (__force void __user *) from, n);
3825 }
3826
3827 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
3828 {
3829- if (n && __access_ok((unsigned long) from, n))
3830+ if ((long)n < 0)
3831+ return n;
3832+
3833+ if (n && __access_ok((unsigned long) from, n)) {
3834+ if (!__builtin_constant_p(n))
3835+ check_object_size(to, n, false);
3836 return __copy_user((__force void __user *) to, from, n);
3837- else
3838+ } else
3839 return n;
3840 }
3841
3842 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
3843 {
3844+ if ((long)n < 0)
3845+ return n;
3846+
3847 return __copy_user((__force void __user *) to, from, n);
3848 }
3849
3850diff -urNp linux-2.6.32.41/arch/sparc/include/asm/uaccess_64.h linux-2.6.32.41/arch/sparc/include/asm/uaccess_64.h
3851--- linux-2.6.32.41/arch/sparc/include/asm/uaccess_64.h 2011-03-27 14:31:47.000000000 -0400
3852+++ linux-2.6.32.41/arch/sparc/include/asm/uaccess_64.h 2011-04-17 15:56:46.000000000 -0400
3853@@ -9,6 +9,7 @@
3854 #include <linux/compiler.h>
3855 #include <linux/string.h>
3856 #include <linux/thread_info.h>
3857+#include <linux/kernel.h>
3858 #include <asm/asi.h>
3859 #include <asm/system.h>
3860 #include <asm/spitfire.h>
3861@@ -212,8 +213,15 @@ extern unsigned long copy_from_user_fixu
3862 static inline unsigned long __must_check
3863 copy_from_user(void *to, const void __user *from, unsigned long size)
3864 {
3865- unsigned long ret = ___copy_from_user(to, from, size);
3866+ unsigned long ret;
3867
3868+ if ((long)size < 0 || size > INT_MAX)
3869+ return size;
3870+
3871+ if (!__builtin_constant_p(size))
3872+ check_object_size(to, size, false);
3873+
3874+ ret = ___copy_from_user(to, from, size);
3875 if (unlikely(ret))
3876 ret = copy_from_user_fixup(to, from, size);
3877 return ret;
3878@@ -228,8 +236,15 @@ extern unsigned long copy_to_user_fixup(
3879 static inline unsigned long __must_check
3880 copy_to_user(void __user *to, const void *from, unsigned long size)
3881 {
3882- unsigned long ret = ___copy_to_user(to, from, size);
3883+ unsigned long ret;
3884+
3885+ if ((long)size < 0 || size > INT_MAX)
3886+ return size;
3887+
3888+ if (!__builtin_constant_p(size))
3889+ check_object_size(from, size, true);
3890
3891+ ret = ___copy_to_user(to, from, size);
3892 if (unlikely(ret))
3893 ret = copy_to_user_fixup(to, from, size);
3894 return ret;
3895diff -urNp linux-2.6.32.41/arch/sparc/include/asm/uaccess.h linux-2.6.32.41/arch/sparc/include/asm/uaccess.h
3896--- linux-2.6.32.41/arch/sparc/include/asm/uaccess.h 2011-03-27 14:31:47.000000000 -0400
3897+++ linux-2.6.32.41/arch/sparc/include/asm/uaccess.h 2011-04-17 15:56:46.000000000 -0400
3898@@ -1,5 +1,13 @@
3899 #ifndef ___ASM_SPARC_UACCESS_H
3900 #define ___ASM_SPARC_UACCESS_H
3901+
3902+#ifdef __KERNEL__
3903+#ifndef __ASSEMBLY__
3904+#include <linux/types.h>
3905+extern void check_object_size(const void *ptr, unsigned long n, bool to);
3906+#endif
3907+#endif
3908+
3909 #if defined(__sparc__) && defined(__arch64__)
3910 #include <asm/uaccess_64.h>
3911 #else
3912diff -urNp linux-2.6.32.41/arch/sparc/kernel/iommu.c linux-2.6.32.41/arch/sparc/kernel/iommu.c
3913--- linux-2.6.32.41/arch/sparc/kernel/iommu.c 2011-03-27 14:31:47.000000000 -0400
3914+++ linux-2.6.32.41/arch/sparc/kernel/iommu.c 2011-04-17 15:56:46.000000000 -0400
3915@@ -826,7 +826,7 @@ static void dma_4u_sync_sg_for_cpu(struc
3916 spin_unlock_irqrestore(&iommu->lock, flags);
3917 }
3918
3919-static struct dma_map_ops sun4u_dma_ops = {
3920+static const struct dma_map_ops sun4u_dma_ops = {
3921 .alloc_coherent = dma_4u_alloc_coherent,
3922 .free_coherent = dma_4u_free_coherent,
3923 .map_page = dma_4u_map_page,
3924@@ -837,7 +837,7 @@ static struct dma_map_ops sun4u_dma_ops
3925 .sync_sg_for_cpu = dma_4u_sync_sg_for_cpu,
3926 };
3927
3928-struct dma_map_ops *dma_ops = &sun4u_dma_ops;
3929+const struct dma_map_ops *dma_ops = &sun4u_dma_ops;
3930 EXPORT_SYMBOL(dma_ops);
3931
3932 extern int pci64_dma_supported(struct pci_dev *pdev, u64 device_mask);
3933diff -urNp linux-2.6.32.41/arch/sparc/kernel/ioport.c linux-2.6.32.41/arch/sparc/kernel/ioport.c
3934--- linux-2.6.32.41/arch/sparc/kernel/ioport.c 2011-03-27 14:31:47.000000000 -0400
3935+++ linux-2.6.32.41/arch/sparc/kernel/ioport.c 2011-04-17 15:56:46.000000000 -0400
3936@@ -392,7 +392,7 @@ static void sbus_sync_sg_for_device(stru
3937 BUG();
3938 }
3939
3940-struct dma_map_ops sbus_dma_ops = {
3941+const struct dma_map_ops sbus_dma_ops = {
3942 .alloc_coherent = sbus_alloc_coherent,
3943 .free_coherent = sbus_free_coherent,
3944 .map_page = sbus_map_page,
3945@@ -403,7 +403,7 @@ struct dma_map_ops sbus_dma_ops = {
3946 .sync_sg_for_device = sbus_sync_sg_for_device,
3947 };
3948
3949-struct dma_map_ops *dma_ops = &sbus_dma_ops;
3950+const struct dma_map_ops *dma_ops = &sbus_dma_ops;
3951 EXPORT_SYMBOL(dma_ops);
3952
3953 static int __init sparc_register_ioport(void)
3954@@ -640,7 +640,7 @@ static void pci32_sync_sg_for_device(str
3955 }
3956 }
3957
3958-struct dma_map_ops pci32_dma_ops = {
3959+const struct dma_map_ops pci32_dma_ops = {
3960 .alloc_coherent = pci32_alloc_coherent,
3961 .free_coherent = pci32_free_coherent,
3962 .map_page = pci32_map_page,
3963diff -urNp linux-2.6.32.41/arch/sparc/kernel/kgdb_32.c linux-2.6.32.41/arch/sparc/kernel/kgdb_32.c
3964--- linux-2.6.32.41/arch/sparc/kernel/kgdb_32.c 2011-03-27 14:31:47.000000000 -0400
3965+++ linux-2.6.32.41/arch/sparc/kernel/kgdb_32.c 2011-04-17 15:56:46.000000000 -0400
3966@@ -158,7 +158,7 @@ void kgdb_arch_exit(void)
3967 {
3968 }
3969
3970-struct kgdb_arch arch_kgdb_ops = {
3971+const struct kgdb_arch arch_kgdb_ops = {
3972 /* Breakpoint instruction: ta 0x7d */
3973 .gdb_bpt_instr = { 0x91, 0xd0, 0x20, 0x7d },
3974 };
3975diff -urNp linux-2.6.32.41/arch/sparc/kernel/kgdb_64.c linux-2.6.32.41/arch/sparc/kernel/kgdb_64.c
3976--- linux-2.6.32.41/arch/sparc/kernel/kgdb_64.c 2011-03-27 14:31:47.000000000 -0400
3977+++ linux-2.6.32.41/arch/sparc/kernel/kgdb_64.c 2011-04-17 15:56:46.000000000 -0400
3978@@ -180,7 +180,7 @@ void kgdb_arch_exit(void)
3979 {
3980 }
3981
3982-struct kgdb_arch arch_kgdb_ops = {
3983+const struct kgdb_arch arch_kgdb_ops = {
3984 /* Breakpoint instruction: ta 0x72 */
3985 .gdb_bpt_instr = { 0x91, 0xd0, 0x20, 0x72 },
3986 };
3987diff -urNp linux-2.6.32.41/arch/sparc/kernel/Makefile linux-2.6.32.41/arch/sparc/kernel/Makefile
3988--- linux-2.6.32.41/arch/sparc/kernel/Makefile 2011-03-27 14:31:47.000000000 -0400
3989+++ linux-2.6.32.41/arch/sparc/kernel/Makefile 2011-04-17 15:56:46.000000000 -0400
3990@@ -3,7 +3,7 @@
3991 #
3992
3993 asflags-y := -ansi
3994-ccflags-y := -Werror
3995+#ccflags-y := -Werror
3996
3997 extra-y := head_$(BITS).o
3998 extra-y += init_task.o
3999diff -urNp linux-2.6.32.41/arch/sparc/kernel/pci_sun4v.c linux-2.6.32.41/arch/sparc/kernel/pci_sun4v.c
4000--- linux-2.6.32.41/arch/sparc/kernel/pci_sun4v.c 2011-03-27 14:31:47.000000000 -0400
4001+++ linux-2.6.32.41/arch/sparc/kernel/pci_sun4v.c 2011-04-17 15:56:46.000000000 -0400
4002@@ -525,7 +525,7 @@ static void dma_4v_unmap_sg(struct devic
4003 spin_unlock_irqrestore(&iommu->lock, flags);
4004 }
4005
4006-static struct dma_map_ops sun4v_dma_ops = {
4007+static const struct dma_map_ops sun4v_dma_ops = {
4008 .alloc_coherent = dma_4v_alloc_coherent,
4009 .free_coherent = dma_4v_free_coherent,
4010 .map_page = dma_4v_map_page,
4011diff -urNp linux-2.6.32.41/arch/sparc/kernel/process_32.c linux-2.6.32.41/arch/sparc/kernel/process_32.c
4012--- linux-2.6.32.41/arch/sparc/kernel/process_32.c 2011-03-27 14:31:47.000000000 -0400
4013+++ linux-2.6.32.41/arch/sparc/kernel/process_32.c 2011-04-17 15:56:46.000000000 -0400
4014@@ -196,7 +196,7 @@ void __show_backtrace(unsigned long fp)
4015 rw->ins[4], rw->ins[5],
4016 rw->ins[6],
4017 rw->ins[7]);
4018- printk("%pS\n", (void *) rw->ins[7]);
4019+ printk("%pA\n", (void *) rw->ins[7]);
4020 rw = (struct reg_window32 *) rw->ins[6];
4021 }
4022 spin_unlock_irqrestore(&sparc_backtrace_lock, flags);
4023@@ -263,14 +263,14 @@ void show_regs(struct pt_regs *r)
4024
4025 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
4026 r->psr, r->pc, r->npc, r->y, print_tainted());
4027- printk("PC: <%pS>\n", (void *) r->pc);
4028+ printk("PC: <%pA>\n", (void *) r->pc);
4029 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
4030 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
4031 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
4032 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
4033 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
4034 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
4035- printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
4036+ printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
4037
4038 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
4039 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
4040@@ -305,7 +305,7 @@ void show_stack(struct task_struct *tsk,
4041 rw = (struct reg_window32 *) fp;
4042 pc = rw->ins[7];
4043 printk("[%08lx : ", pc);
4044- printk("%pS ] ", (void *) pc);
4045+ printk("%pA ] ", (void *) pc);
4046 fp = rw->ins[6];
4047 } while (++count < 16);
4048 printk("\n");
4049diff -urNp linux-2.6.32.41/arch/sparc/kernel/process_64.c linux-2.6.32.41/arch/sparc/kernel/process_64.c
4050--- linux-2.6.32.41/arch/sparc/kernel/process_64.c 2011-03-27 14:31:47.000000000 -0400
4051+++ linux-2.6.32.41/arch/sparc/kernel/process_64.c 2011-04-17 15:56:46.000000000 -0400
4052@@ -180,14 +180,14 @@ static void show_regwindow(struct pt_reg
4053 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
4054 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
4055 if (regs->tstate & TSTATE_PRIV)
4056- printk("I7: <%pS>\n", (void *) rwk->ins[7]);
4057+ printk("I7: <%pA>\n", (void *) rwk->ins[7]);
4058 }
4059
4060 void show_regs(struct pt_regs *regs)
4061 {
4062 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
4063 regs->tpc, regs->tnpc, regs->y, print_tainted());
4064- printk("TPC: <%pS>\n", (void *) regs->tpc);
4065+ printk("TPC: <%pA>\n", (void *) regs->tpc);
4066 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
4067 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
4068 regs->u_regs[3]);
4069@@ -200,7 +200,7 @@ void show_regs(struct pt_regs *regs)
4070 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
4071 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
4072 regs->u_regs[15]);
4073- printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
4074+ printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
4075 show_regwindow(regs);
4076 }
4077
4078@@ -284,7 +284,7 @@ void arch_trigger_all_cpu_backtrace(void
4079 ((tp && tp->task) ? tp->task->pid : -1));
4080
4081 if (gp->tstate & TSTATE_PRIV) {
4082- printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
4083+ printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
4084 (void *) gp->tpc,
4085 (void *) gp->o7,
4086 (void *) gp->i7,
4087diff -urNp linux-2.6.32.41/arch/sparc/kernel/sys_sparc_32.c linux-2.6.32.41/arch/sparc/kernel/sys_sparc_32.c
4088--- linux-2.6.32.41/arch/sparc/kernel/sys_sparc_32.c 2011-03-27 14:31:47.000000000 -0400
4089+++ linux-2.6.32.41/arch/sparc/kernel/sys_sparc_32.c 2011-04-17 15:56:46.000000000 -0400
4090@@ -57,7 +57,7 @@ unsigned long arch_get_unmapped_area(str
4091 if (ARCH_SUN4C && len > 0x20000000)
4092 return -ENOMEM;
4093 if (!addr)
4094- addr = TASK_UNMAPPED_BASE;
4095+ addr = current->mm->mmap_base;
4096
4097 if (flags & MAP_SHARED)
4098 addr = COLOUR_ALIGN(addr);
4099@@ -72,7 +72,7 @@ unsigned long arch_get_unmapped_area(str
4100 }
4101 if (TASK_SIZE - PAGE_SIZE - len < addr)
4102 return -ENOMEM;
4103- if (!vmm || addr + len <= vmm->vm_start)
4104+ if (check_heap_stack_gap(vmm, addr, len))
4105 return addr;
4106 addr = vmm->vm_end;
4107 if (flags & MAP_SHARED)
4108diff -urNp linux-2.6.32.41/arch/sparc/kernel/sys_sparc_64.c linux-2.6.32.41/arch/sparc/kernel/sys_sparc_64.c
4109--- linux-2.6.32.41/arch/sparc/kernel/sys_sparc_64.c 2011-03-27 14:31:47.000000000 -0400
4110+++ linux-2.6.32.41/arch/sparc/kernel/sys_sparc_64.c 2011-04-17 15:56:46.000000000 -0400
4111@@ -125,7 +125,7 @@ unsigned long arch_get_unmapped_area(str
4112 /* We do not accept a shared mapping if it would violate
4113 * cache aliasing constraints.
4114 */
4115- if ((flags & MAP_SHARED) &&
4116+ if ((filp || (flags & MAP_SHARED)) &&
4117 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
4118 return -EINVAL;
4119 return addr;
4120@@ -140,6 +140,10 @@ unsigned long arch_get_unmapped_area(str
4121 if (filp || (flags & MAP_SHARED))
4122 do_color_align = 1;
4123
4124+#ifdef CONFIG_PAX_RANDMMAP
4125+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4126+#endif
4127+
4128 if (addr) {
4129 if (do_color_align)
4130 addr = COLOUR_ALIGN(addr, pgoff);
4131@@ -147,15 +151,14 @@ unsigned long arch_get_unmapped_area(str
4132 addr = PAGE_ALIGN(addr);
4133
4134 vma = find_vma(mm, addr);
4135- if (task_size - len >= addr &&
4136- (!vma || addr + len <= vma->vm_start))
4137+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
4138 return addr;
4139 }
4140
4141 if (len > mm->cached_hole_size) {
4142- start_addr = addr = mm->free_area_cache;
4143+ start_addr = addr = mm->free_area_cache;
4144 } else {
4145- start_addr = addr = TASK_UNMAPPED_BASE;
4146+ start_addr = addr = mm->mmap_base;
4147 mm->cached_hole_size = 0;
4148 }
4149
4150@@ -175,14 +178,14 @@ full_search:
4151 vma = find_vma(mm, VA_EXCLUDE_END);
4152 }
4153 if (unlikely(task_size < addr)) {
4154- if (start_addr != TASK_UNMAPPED_BASE) {
4155- start_addr = addr = TASK_UNMAPPED_BASE;
4156+ if (start_addr != mm->mmap_base) {
4157+ start_addr = addr = mm->mmap_base;
4158 mm->cached_hole_size = 0;
4159 goto full_search;
4160 }
4161 return -ENOMEM;
4162 }
4163- if (likely(!vma || addr + len <= vma->vm_start)) {
4164+ if (likely(check_heap_stack_gap(vma, addr, len))) {
4165 /*
4166 * Remember the place where we stopped the search:
4167 */
4168@@ -216,7 +219,7 @@ arch_get_unmapped_area_topdown(struct fi
4169 /* We do not accept a shared mapping if it would violate
4170 * cache aliasing constraints.
4171 */
4172- if ((flags & MAP_SHARED) &&
4173+ if ((filp || (flags & MAP_SHARED)) &&
4174 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
4175 return -EINVAL;
4176 return addr;
4177@@ -237,8 +240,7 @@ arch_get_unmapped_area_topdown(struct fi
4178 addr = PAGE_ALIGN(addr);
4179
4180 vma = find_vma(mm, addr);
4181- if (task_size - len >= addr &&
4182- (!vma || addr + len <= vma->vm_start))
4183+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
4184 return addr;
4185 }
4186
4187@@ -259,7 +261,7 @@ arch_get_unmapped_area_topdown(struct fi
4188 /* make sure it can fit in the remaining address space */
4189 if (likely(addr > len)) {
4190 vma = find_vma(mm, addr-len);
4191- if (!vma || addr <= vma->vm_start) {
4192+ if (check_heap_stack_gap(vma, addr - len, len)) {
4193 /* remember the address as a hint for next time */
4194 return (mm->free_area_cache = addr-len);
4195 }
4196@@ -268,18 +270,18 @@ arch_get_unmapped_area_topdown(struct fi
4197 if (unlikely(mm->mmap_base < len))
4198 goto bottomup;
4199
4200- addr = mm->mmap_base-len;
4201- if (do_color_align)
4202- addr = COLOUR_ALIGN_DOWN(addr, pgoff);
4203+ addr = mm->mmap_base - len;
4204
4205 do {
4206+ if (do_color_align)
4207+ addr = COLOUR_ALIGN_DOWN(addr, pgoff);
4208 /*
4209 * Lookup failure means no vma is above this address,
4210 * else if new region fits below vma->vm_start,
4211 * return with success:
4212 */
4213 vma = find_vma(mm, addr);
4214- if (likely(!vma || addr+len <= vma->vm_start)) {
4215+ if (likely(check_heap_stack_gap(vma, addr, len))) {
4216 /* remember the address as a hint for next time */
4217 return (mm->free_area_cache = addr);
4218 }
4219@@ -289,10 +291,8 @@ arch_get_unmapped_area_topdown(struct fi
4220 mm->cached_hole_size = vma->vm_start - addr;
4221
4222 /* try just below the current vma->vm_start */
4223- addr = vma->vm_start-len;
4224- if (do_color_align)
4225- addr = COLOUR_ALIGN_DOWN(addr, pgoff);
4226- } while (likely(len < vma->vm_start));
4227+ addr = skip_heap_stack_gap(vma, len);
4228+ } while (!IS_ERR_VALUE(addr));
4229
4230 bottomup:
4231 /*
4232@@ -384,6 +384,12 @@ void arch_pick_mmap_layout(struct mm_str
4233 current->signal->rlim[RLIMIT_STACK].rlim_cur == RLIM_INFINITY ||
4234 sysctl_legacy_va_layout) {
4235 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
4236+
4237+#ifdef CONFIG_PAX_RANDMMAP
4238+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4239+ mm->mmap_base += mm->delta_mmap;
4240+#endif
4241+
4242 mm->get_unmapped_area = arch_get_unmapped_area;
4243 mm->unmap_area = arch_unmap_area;
4244 } else {
4245@@ -398,6 +404,12 @@ void arch_pick_mmap_layout(struct mm_str
4246 gap = (task_size / 6 * 5);
4247
4248 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
4249+
4250+#ifdef CONFIG_PAX_RANDMMAP
4251+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4252+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4253+#endif
4254+
4255 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4256 mm->unmap_area = arch_unmap_area_topdown;
4257 }
4258diff -urNp linux-2.6.32.41/arch/sparc/kernel/traps_32.c linux-2.6.32.41/arch/sparc/kernel/traps_32.c
4259--- linux-2.6.32.41/arch/sparc/kernel/traps_32.c 2011-03-27 14:31:47.000000000 -0400
4260+++ linux-2.6.32.41/arch/sparc/kernel/traps_32.c 2011-04-17 15:56:46.000000000 -0400
4261@@ -76,7 +76,7 @@ void die_if_kernel(char *str, struct pt_
4262 count++ < 30 &&
4263 (((unsigned long) rw) >= PAGE_OFFSET) &&
4264 !(((unsigned long) rw) & 0x7)) {
4265- printk("Caller[%08lx]: %pS\n", rw->ins[7],
4266+ printk("Caller[%08lx]: %pA\n", rw->ins[7],
4267 (void *) rw->ins[7]);
4268 rw = (struct reg_window32 *)rw->ins[6];
4269 }
4270diff -urNp linux-2.6.32.41/arch/sparc/kernel/traps_64.c linux-2.6.32.41/arch/sparc/kernel/traps_64.c
4271--- linux-2.6.32.41/arch/sparc/kernel/traps_64.c 2011-03-27 14:31:47.000000000 -0400
4272+++ linux-2.6.32.41/arch/sparc/kernel/traps_64.c 2011-04-17 15:56:46.000000000 -0400
4273@@ -73,7 +73,7 @@ static void dump_tl1_traplog(struct tl1_
4274 i + 1,
4275 p->trapstack[i].tstate, p->trapstack[i].tpc,
4276 p->trapstack[i].tnpc, p->trapstack[i].tt);
4277- printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
4278+ printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
4279 }
4280 }
4281
4282@@ -93,6 +93,12 @@ void bad_trap(struct pt_regs *regs, long
4283
4284 lvl -= 0x100;
4285 if (regs->tstate & TSTATE_PRIV) {
4286+
4287+#ifdef CONFIG_PAX_REFCOUNT
4288+ if (lvl == 6)
4289+ pax_report_refcount_overflow(regs);
4290+#endif
4291+
4292 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
4293 die_if_kernel(buffer, regs);
4294 }
4295@@ -111,11 +117,16 @@ void bad_trap(struct pt_regs *regs, long
4296 void bad_trap_tl1(struct pt_regs *regs, long lvl)
4297 {
4298 char buffer[32];
4299-
4300+
4301 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
4302 0, lvl, SIGTRAP) == NOTIFY_STOP)
4303 return;
4304
4305+#ifdef CONFIG_PAX_REFCOUNT
4306+ if (lvl == 6)
4307+ pax_report_refcount_overflow(regs);
4308+#endif
4309+
4310 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
4311
4312 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
4313@@ -1139,7 +1150,7 @@ static void cheetah_log_errors(struct pt
4314 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
4315 printk("%s" "ERROR(%d): ",
4316 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
4317- printk("TPC<%pS>\n", (void *) regs->tpc);
4318+ printk("TPC<%pA>\n", (void *) regs->tpc);
4319 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
4320 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
4321 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
4322@@ -1746,7 +1757,7 @@ void cheetah_plus_parity_error(int type,
4323 smp_processor_id(),
4324 (type & 0x1) ? 'I' : 'D',
4325 regs->tpc);
4326- printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
4327+ printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
4328 panic("Irrecoverable Cheetah+ parity error.");
4329 }
4330
4331@@ -1754,7 +1765,7 @@ void cheetah_plus_parity_error(int type,
4332 smp_processor_id(),
4333 (type & 0x1) ? 'I' : 'D',
4334 regs->tpc);
4335- printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
4336+ printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
4337 }
4338
4339 struct sun4v_error_entry {
4340@@ -1961,9 +1972,9 @@ void sun4v_itlb_error_report(struct pt_r
4341
4342 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
4343 regs->tpc, tl);
4344- printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
4345+ printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
4346 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
4347- printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
4348+ printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
4349 (void *) regs->u_regs[UREG_I7]);
4350 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
4351 "pte[%lx] error[%lx]\n",
4352@@ -1985,9 +1996,9 @@ void sun4v_dtlb_error_report(struct pt_r
4353
4354 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
4355 regs->tpc, tl);
4356- printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
4357+ printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
4358 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
4359- printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
4360+ printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
4361 (void *) regs->u_regs[UREG_I7]);
4362 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
4363 "pte[%lx] error[%lx]\n",
4364@@ -2191,7 +2202,7 @@ void show_stack(struct task_struct *tsk,
4365 fp = (unsigned long)sf->fp + STACK_BIAS;
4366 }
4367
4368- printk(" [%016lx] %pS\n", pc, (void *) pc);
4369+ printk(" [%016lx] %pA\n", pc, (void *) pc);
4370 } while (++count < 16);
4371 }
4372
4373@@ -2260,7 +2271,7 @@ void die_if_kernel(char *str, struct pt_
4374 while (rw &&
4375 count++ < 30&&
4376 is_kernel_stack(current, rw)) {
4377- printk("Caller[%016lx]: %pS\n", rw->ins[7],
4378+ printk("Caller[%016lx]: %pA\n", rw->ins[7],
4379 (void *) rw->ins[7]);
4380
4381 rw = kernel_stack_up(rw);
4382diff -urNp linux-2.6.32.41/arch/sparc/kernel/unaligned_64.c linux-2.6.32.41/arch/sparc/kernel/unaligned_64.c
4383--- linux-2.6.32.41/arch/sparc/kernel/unaligned_64.c 2011-03-27 14:31:47.000000000 -0400
4384+++ linux-2.6.32.41/arch/sparc/kernel/unaligned_64.c 2011-04-17 15:56:46.000000000 -0400
4385@@ -288,7 +288,7 @@ static void log_unaligned(struct pt_regs
4386 if (count < 5) {
4387 last_time = jiffies;
4388 count++;
4389- printk("Kernel unaligned access at TPC[%lx] %pS\n",
4390+ printk("Kernel unaligned access at TPC[%lx] %pA\n",
4391 regs->tpc, (void *) regs->tpc);
4392 }
4393 }
4394diff -urNp linux-2.6.32.41/arch/sparc/lib/atomic_64.S linux-2.6.32.41/arch/sparc/lib/atomic_64.S
4395--- linux-2.6.32.41/arch/sparc/lib/atomic_64.S 2011-03-27 14:31:47.000000000 -0400
4396+++ linux-2.6.32.41/arch/sparc/lib/atomic_64.S 2011-04-17 15:56:46.000000000 -0400
4397@@ -18,7 +18,12 @@
4398 atomic_add: /* %o0 = increment, %o1 = atomic_ptr */
4399 BACKOFF_SETUP(%o2)
4400 1: lduw [%o1], %g1
4401- add %g1, %o0, %g7
4402+ addcc %g1, %o0, %g7
4403+
4404+#ifdef CONFIG_PAX_REFCOUNT
4405+ tvs %icc, 6
4406+#endif
4407+
4408 cas [%o1], %g1, %g7
4409 cmp %g1, %g7
4410 bne,pn %icc, 2f
4411@@ -28,12 +33,32 @@ atomic_add: /* %o0 = increment, %o1 = at
4412 2: BACKOFF_SPIN(%o2, %o3, 1b)
4413 .size atomic_add, .-atomic_add
4414
4415+ .globl atomic_add_unchecked
4416+ .type atomic_add_unchecked,#function
4417+atomic_add_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
4418+ BACKOFF_SETUP(%o2)
4419+1: lduw [%o1], %g1
4420+ add %g1, %o0, %g7
4421+ cas [%o1], %g1, %g7
4422+ cmp %g1, %g7
4423+ bne,pn %icc, 2f
4424+ nop
4425+ retl
4426+ nop
4427+2: BACKOFF_SPIN(%o2, %o3, 1b)
4428+ .size atomic_add_unchecked, .-atomic_add_unchecked
4429+
4430 .globl atomic_sub
4431 .type atomic_sub,#function
4432 atomic_sub: /* %o0 = decrement, %o1 = atomic_ptr */
4433 BACKOFF_SETUP(%o2)
4434 1: lduw [%o1], %g1
4435- sub %g1, %o0, %g7
4436+ subcc %g1, %o0, %g7
4437+
4438+#ifdef CONFIG_PAX_REFCOUNT
4439+ tvs %icc, 6
4440+#endif
4441+
4442 cas [%o1], %g1, %g7
4443 cmp %g1, %g7
4444 bne,pn %icc, 2f
4445@@ -43,12 +68,32 @@ atomic_sub: /* %o0 = decrement, %o1 = at
4446 2: BACKOFF_SPIN(%o2, %o3, 1b)
4447 .size atomic_sub, .-atomic_sub
4448
4449+ .globl atomic_sub_unchecked
4450+ .type atomic_sub_unchecked,#function
4451+atomic_sub_unchecked: /* %o0 = decrement, %o1 = atomic_ptr */
4452+ BACKOFF_SETUP(%o2)
4453+1: lduw [%o1], %g1
4454+ sub %g1, %o0, %g7
4455+ cas [%o1], %g1, %g7
4456+ cmp %g1, %g7
4457+ bne,pn %icc, 2f
4458+ nop
4459+ retl
4460+ nop
4461+2: BACKOFF_SPIN(%o2, %o3, 1b)
4462+ .size atomic_sub_unchecked, .-atomic_sub_unchecked
4463+
4464 .globl atomic_add_ret
4465 .type atomic_add_ret,#function
4466 atomic_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
4467 BACKOFF_SETUP(%o2)
4468 1: lduw [%o1], %g1
4469- add %g1, %o0, %g7
4470+ addcc %g1, %o0, %g7
4471+
4472+#ifdef CONFIG_PAX_REFCOUNT
4473+ tvs %icc, 6
4474+#endif
4475+
4476 cas [%o1], %g1, %g7
4477 cmp %g1, %g7
4478 bne,pn %icc, 2f
4479@@ -59,12 +104,33 @@ atomic_add_ret: /* %o0 = increment, %o1
4480 2: BACKOFF_SPIN(%o2, %o3, 1b)
4481 .size atomic_add_ret, .-atomic_add_ret
4482
4483+ .globl atomic_add_ret_unchecked
4484+ .type atomic_add_ret_unchecked,#function
4485+atomic_add_ret_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
4486+ BACKOFF_SETUP(%o2)
4487+1: lduw [%o1], %g1
4488+ addcc %g1, %o0, %g7
4489+ cas [%o1], %g1, %g7
4490+ cmp %g1, %g7
4491+ bne,pn %icc, 2f
4492+ add %g7, %o0, %g7
4493+ sra %g7, 0, %o0
4494+ retl
4495+ nop
4496+2: BACKOFF_SPIN(%o2, %o3, 1b)
4497+ .size atomic_add_ret_unchecked, .-atomic_add_ret_unchecked
4498+
4499 .globl atomic_sub_ret
4500 .type atomic_sub_ret,#function
4501 atomic_sub_ret: /* %o0 = decrement, %o1 = atomic_ptr */
4502 BACKOFF_SETUP(%o2)
4503 1: lduw [%o1], %g1
4504- sub %g1, %o0, %g7
4505+ subcc %g1, %o0, %g7
4506+
4507+#ifdef CONFIG_PAX_REFCOUNT
4508+ tvs %icc, 6
4509+#endif
4510+
4511 cas [%o1], %g1, %g7
4512 cmp %g1, %g7
4513 bne,pn %icc, 2f
4514@@ -80,7 +146,12 @@ atomic_sub_ret: /* %o0 = decrement, %o1
4515 atomic64_add: /* %o0 = increment, %o1 = atomic_ptr */
4516 BACKOFF_SETUP(%o2)
4517 1: ldx [%o1], %g1
4518- add %g1, %o0, %g7
4519+ addcc %g1, %o0, %g7
4520+
4521+#ifdef CONFIG_PAX_REFCOUNT
4522+ tvs %xcc, 6
4523+#endif
4524+
4525 casx [%o1], %g1, %g7
4526 cmp %g1, %g7
4527 bne,pn %xcc, 2f
4528@@ -90,12 +161,32 @@ atomic64_add: /* %o0 = increment, %o1 =
4529 2: BACKOFF_SPIN(%o2, %o3, 1b)
4530 .size atomic64_add, .-atomic64_add
4531
4532+ .globl atomic64_add_unchecked
4533+ .type atomic64_add_unchecked,#function
4534+atomic64_add_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
4535+ BACKOFF_SETUP(%o2)
4536+1: ldx [%o1], %g1
4537+ addcc %g1, %o0, %g7
4538+ casx [%o1], %g1, %g7
4539+ cmp %g1, %g7
4540+ bne,pn %xcc, 2f
4541+ nop
4542+ retl
4543+ nop
4544+2: BACKOFF_SPIN(%o2, %o3, 1b)
4545+ .size atomic64_add_unchecked, .-atomic64_add_unchecked
4546+
4547 .globl atomic64_sub
4548 .type atomic64_sub,#function
4549 atomic64_sub: /* %o0 = decrement, %o1 = atomic_ptr */
4550 BACKOFF_SETUP(%o2)
4551 1: ldx [%o1], %g1
4552- sub %g1, %o0, %g7
4553+ subcc %g1, %o0, %g7
4554+
4555+#ifdef CONFIG_PAX_REFCOUNT
4556+ tvs %xcc, 6
4557+#endif
4558+
4559 casx [%o1], %g1, %g7
4560 cmp %g1, %g7
4561 bne,pn %xcc, 2f
4562@@ -105,12 +196,32 @@ atomic64_sub: /* %o0 = decrement, %o1 =
4563 2: BACKOFF_SPIN(%o2, %o3, 1b)
4564 .size atomic64_sub, .-atomic64_sub
4565
4566+ .globl atomic64_sub_unchecked
4567+ .type atomic64_sub_unchecked,#function
4568+atomic64_sub_unchecked: /* %o0 = decrement, %o1 = atomic_ptr */
4569+ BACKOFF_SETUP(%o2)
4570+1: ldx [%o1], %g1
4571+ subcc %g1, %o0, %g7
4572+ casx [%o1], %g1, %g7
4573+ cmp %g1, %g7
4574+ bne,pn %xcc, 2f
4575+ nop
4576+ retl
4577+ nop
4578+2: BACKOFF_SPIN(%o2, %o3, 1b)
4579+ .size atomic64_sub_unchecked, .-atomic64_sub_unchecked
4580+
4581 .globl atomic64_add_ret
4582 .type atomic64_add_ret,#function
4583 atomic64_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
4584 BACKOFF_SETUP(%o2)
4585 1: ldx [%o1], %g1
4586- add %g1, %o0, %g7
4587+ addcc %g1, %o0, %g7
4588+
4589+#ifdef CONFIG_PAX_REFCOUNT
4590+ tvs %xcc, 6
4591+#endif
4592+
4593 casx [%o1], %g1, %g7
4594 cmp %g1, %g7
4595 bne,pn %xcc, 2f
4596@@ -121,12 +232,33 @@ atomic64_add_ret: /* %o0 = increment, %o
4597 2: BACKOFF_SPIN(%o2, %o3, 1b)
4598 .size atomic64_add_ret, .-atomic64_add_ret
4599
4600+ .globl atomic64_add_ret_unchecked
4601+ .type atomic64_add_ret_unchecked,#function
4602+atomic64_add_ret_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
4603+ BACKOFF_SETUP(%o2)
4604+1: ldx [%o1], %g1
4605+ addcc %g1, %o0, %g7
4606+ casx [%o1], %g1, %g7
4607+ cmp %g1, %g7
4608+ bne,pn %xcc, 2f
4609+ add %g7, %o0, %g7
4610+ mov %g7, %o0
4611+ retl
4612+ nop
4613+2: BACKOFF_SPIN(%o2, %o3, 1b)
4614+ .size atomic64_add_ret_unchecked, .-atomic64_add_ret_unchecked
4615+
4616 .globl atomic64_sub_ret
4617 .type atomic64_sub_ret,#function
4618 atomic64_sub_ret: /* %o0 = decrement, %o1 = atomic_ptr */
4619 BACKOFF_SETUP(%o2)
4620 1: ldx [%o1], %g1
4621- sub %g1, %o0, %g7
4622+ subcc %g1, %o0, %g7
4623+
4624+#ifdef CONFIG_PAX_REFCOUNT
4625+ tvs %xcc, 6
4626+#endif
4627+
4628 casx [%o1], %g1, %g7
4629 cmp %g1, %g7
4630 bne,pn %xcc, 2f
4631diff -urNp linux-2.6.32.41/arch/sparc/lib/ksyms.c linux-2.6.32.41/arch/sparc/lib/ksyms.c
4632--- linux-2.6.32.41/arch/sparc/lib/ksyms.c 2011-03-27 14:31:47.000000000 -0400
4633+++ linux-2.6.32.41/arch/sparc/lib/ksyms.c 2011-04-17 15:56:46.000000000 -0400
4634@@ -144,12 +144,17 @@ EXPORT_SYMBOL(__downgrade_write);
4635
4636 /* Atomic counter implementation. */
4637 EXPORT_SYMBOL(atomic_add);
4638+EXPORT_SYMBOL(atomic_add_unchecked);
4639 EXPORT_SYMBOL(atomic_add_ret);
4640 EXPORT_SYMBOL(atomic_sub);
4641+EXPORT_SYMBOL(atomic_sub_unchecked);
4642 EXPORT_SYMBOL(atomic_sub_ret);
4643 EXPORT_SYMBOL(atomic64_add);
4644+EXPORT_SYMBOL(atomic64_add_unchecked);
4645 EXPORT_SYMBOL(atomic64_add_ret);
4646+EXPORT_SYMBOL(atomic64_add_ret_unchecked);
4647 EXPORT_SYMBOL(atomic64_sub);
4648+EXPORT_SYMBOL(atomic64_sub_unchecked);
4649 EXPORT_SYMBOL(atomic64_sub_ret);
4650
4651 /* Atomic bit operations. */
4652diff -urNp linux-2.6.32.41/arch/sparc/lib/Makefile linux-2.6.32.41/arch/sparc/lib/Makefile
4653--- linux-2.6.32.41/arch/sparc/lib/Makefile 2011-03-27 14:31:47.000000000 -0400
4654+++ linux-2.6.32.41/arch/sparc/lib/Makefile 2011-05-17 19:26:34.000000000 -0400
4655@@ -2,7 +2,7 @@
4656 #
4657
4658 asflags-y := -ansi -DST_DIV0=0x02
4659-ccflags-y := -Werror
4660+#ccflags-y := -Werror
4661
4662 lib-$(CONFIG_SPARC32) += mul.o rem.o sdiv.o udiv.o umul.o urem.o ashrdi3.o
4663 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
4664diff -urNp linux-2.6.32.41/arch/sparc/lib/rwsem_64.S linux-2.6.32.41/arch/sparc/lib/rwsem_64.S
4665--- linux-2.6.32.41/arch/sparc/lib/rwsem_64.S 2011-03-27 14:31:47.000000000 -0400
4666+++ linux-2.6.32.41/arch/sparc/lib/rwsem_64.S 2011-04-17 15:56:46.000000000 -0400
4667@@ -11,7 +11,12 @@
4668 .globl __down_read
4669 __down_read:
4670 1: lduw [%o0], %g1
4671- add %g1, 1, %g7
4672+ addcc %g1, 1, %g7
4673+
4674+#ifdef CONFIG_PAX_REFCOUNT
4675+ tvs %icc, 6
4676+#endif
4677+
4678 cas [%o0], %g1, %g7
4679 cmp %g1, %g7
4680 bne,pn %icc, 1b
4681@@ -33,7 +38,12 @@ __down_read:
4682 .globl __down_read_trylock
4683 __down_read_trylock:
4684 1: lduw [%o0], %g1
4685- add %g1, 1, %g7
4686+ addcc %g1, 1, %g7
4687+
4688+#ifdef CONFIG_PAX_REFCOUNT
4689+ tvs %icc, 6
4690+#endif
4691+
4692 cmp %g7, 0
4693 bl,pn %icc, 2f
4694 mov 0, %o1
4695@@ -51,7 +61,12 @@ __down_write:
4696 or %g1, %lo(RWSEM_ACTIVE_WRITE_BIAS), %g1
4697 1:
4698 lduw [%o0], %g3
4699- add %g3, %g1, %g7
4700+ addcc %g3, %g1, %g7
4701+
4702+#ifdef CONFIG_PAX_REFCOUNT
4703+ tvs %icc, 6
4704+#endif
4705+
4706 cas [%o0], %g3, %g7
4707 cmp %g3, %g7
4708 bne,pn %icc, 1b
4709@@ -77,7 +92,12 @@ __down_write_trylock:
4710 cmp %g3, 0
4711 bne,pn %icc, 2f
4712 mov 0, %o1
4713- add %g3, %g1, %g7
4714+ addcc %g3, %g1, %g7
4715+
4716+#ifdef CONFIG_PAX_REFCOUNT
4717+ tvs %icc, 6
4718+#endif
4719+
4720 cas [%o0], %g3, %g7
4721 cmp %g3, %g7
4722 bne,pn %icc, 1b
4723@@ -90,7 +110,12 @@ __down_write_trylock:
4724 __up_read:
4725 1:
4726 lduw [%o0], %g1
4727- sub %g1, 1, %g7
4728+ subcc %g1, 1, %g7
4729+
4730+#ifdef CONFIG_PAX_REFCOUNT
4731+ tvs %icc, 6
4732+#endif
4733+
4734 cas [%o0], %g1, %g7
4735 cmp %g1, %g7
4736 bne,pn %icc, 1b
4737@@ -118,7 +143,12 @@ __up_write:
4738 or %g1, %lo(RWSEM_ACTIVE_WRITE_BIAS), %g1
4739 1:
4740 lduw [%o0], %g3
4741- sub %g3, %g1, %g7
4742+ subcc %g3, %g1, %g7
4743+
4744+#ifdef CONFIG_PAX_REFCOUNT
4745+ tvs %icc, 6
4746+#endif
4747+
4748 cas [%o0], %g3, %g7
4749 cmp %g3, %g7
4750 bne,pn %icc, 1b
4751@@ -143,7 +173,12 @@ __downgrade_write:
4752 or %g1, %lo(RWSEM_WAITING_BIAS), %g1
4753 1:
4754 lduw [%o0], %g3
4755- sub %g3, %g1, %g7
4756+ subcc %g3, %g1, %g7
4757+
4758+#ifdef CONFIG_PAX_REFCOUNT
4759+ tvs %icc, 6
4760+#endif
4761+
4762 cas [%o0], %g3, %g7
4763 cmp %g3, %g7
4764 bne,pn %icc, 1b
4765diff -urNp linux-2.6.32.41/arch/sparc/Makefile linux-2.6.32.41/arch/sparc/Makefile
4766--- linux-2.6.32.41/arch/sparc/Makefile 2011-03-27 14:31:47.000000000 -0400
4767+++ linux-2.6.32.41/arch/sparc/Makefile 2011-04-17 15:56:46.000000000 -0400
4768@@ -75,7 +75,7 @@ drivers-$(CONFIG_OPROFILE) += arch/sparc
4769 # Export what is needed by arch/sparc/boot/Makefile
4770 export VMLINUX_INIT VMLINUX_MAIN
4771 VMLINUX_INIT := $(head-y) $(init-y)
4772-VMLINUX_MAIN := $(core-y) kernel/ mm/ fs/ ipc/ security/ crypto/ block/
4773+VMLINUX_MAIN := $(core-y) kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
4774 VMLINUX_MAIN += $(patsubst %/, %/lib.a, $(libs-y)) $(libs-y)
4775 VMLINUX_MAIN += $(drivers-y) $(net-y)
4776
4777diff -urNp linux-2.6.32.41/arch/sparc/mm/fault_32.c linux-2.6.32.41/arch/sparc/mm/fault_32.c
4778--- linux-2.6.32.41/arch/sparc/mm/fault_32.c 2011-03-27 14:31:47.000000000 -0400
4779+++ linux-2.6.32.41/arch/sparc/mm/fault_32.c 2011-04-17 15:56:46.000000000 -0400
4780@@ -21,6 +21,9 @@
4781 #include <linux/interrupt.h>
4782 #include <linux/module.h>
4783 #include <linux/kdebug.h>
4784+#include <linux/slab.h>
4785+#include <linux/pagemap.h>
4786+#include <linux/compiler.h>
4787
4788 #include <asm/system.h>
4789 #include <asm/page.h>
4790@@ -167,6 +170,267 @@ static unsigned long compute_si_addr(str
4791 return safe_compute_effective_address(regs, insn);
4792 }
4793
4794+#ifdef CONFIG_PAX_PAGEEXEC
4795+#ifdef CONFIG_PAX_DLRESOLVE
4796+static void pax_emuplt_close(struct vm_area_struct *vma)
4797+{
4798+ vma->vm_mm->call_dl_resolve = 0UL;
4799+}
4800+
4801+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
4802+{
4803+ unsigned int *kaddr;
4804+
4805+ vmf->page = alloc_page(GFP_HIGHUSER);
4806+ if (!vmf->page)
4807+ return VM_FAULT_OOM;
4808+
4809+ kaddr = kmap(vmf->page);
4810+ memset(kaddr, 0, PAGE_SIZE);
4811+ kaddr[0] = 0x9DE3BFA8U; /* save */
4812+ flush_dcache_page(vmf->page);
4813+ kunmap(vmf->page);
4814+ return VM_FAULT_MAJOR;
4815+}
4816+
4817+static const struct vm_operations_struct pax_vm_ops = {
4818+ .close = pax_emuplt_close,
4819+ .fault = pax_emuplt_fault
4820+};
4821+
4822+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
4823+{
4824+ int ret;
4825+
4826+ vma->vm_mm = current->mm;
4827+ vma->vm_start = addr;
4828+ vma->vm_end = addr + PAGE_SIZE;
4829+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
4830+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
4831+ vma->vm_ops = &pax_vm_ops;
4832+
4833+ ret = insert_vm_struct(current->mm, vma);
4834+ if (ret)
4835+ return ret;
4836+
4837+ ++current->mm->total_vm;
4838+ return 0;
4839+}
4840+#endif
4841+
4842+/*
4843+ * PaX: decide what to do with offenders (regs->pc = fault address)
4844+ *
4845+ * returns 1 when task should be killed
4846+ * 2 when patched PLT trampoline was detected
4847+ * 3 when unpatched PLT trampoline was detected
4848+ */
4849+static int pax_handle_fetch_fault(struct pt_regs *regs)
4850+{
4851+
4852+#ifdef CONFIG_PAX_EMUPLT
4853+ int err;
4854+
4855+ do { /* PaX: patched PLT emulation #1 */
4856+ unsigned int sethi1, sethi2, jmpl;
4857+
4858+ err = get_user(sethi1, (unsigned int *)regs->pc);
4859+ err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
4860+ err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
4861+
4862+ if (err)
4863+ break;
4864+
4865+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
4866+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
4867+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
4868+ {
4869+ unsigned int addr;
4870+
4871+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
4872+ addr = regs->u_regs[UREG_G1];
4873+ addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
4874+ regs->pc = addr;
4875+ regs->npc = addr+4;
4876+ return 2;
4877+ }
4878+ } while (0);
4879+
4880+ { /* PaX: patched PLT emulation #2 */
4881+ unsigned int ba;
4882+
4883+ err = get_user(ba, (unsigned int *)regs->pc);
4884+
4885+ if (!err && (ba & 0xFFC00000U) == 0x30800000U) {
4886+ unsigned int addr;
4887+
4888+ addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
4889+ regs->pc = addr;
4890+ regs->npc = addr+4;
4891+ return 2;
4892+ }
4893+ }
4894+
4895+ do { /* PaX: patched PLT emulation #3 */
4896+ unsigned int sethi, jmpl, nop;
4897+
4898+ err = get_user(sethi, (unsigned int *)regs->pc);
4899+ err |= get_user(jmpl, (unsigned int *)(regs->pc+4));
4900+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
4901+
4902+ if (err)
4903+ break;
4904+
4905+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
4906+ (jmpl & 0xFFFFE000U) == 0x81C06000U &&
4907+ nop == 0x01000000U)
4908+ {
4909+ unsigned int addr;
4910+
4911+ addr = (sethi & 0x003FFFFFU) << 10;
4912+ regs->u_regs[UREG_G1] = addr;
4913+ addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
4914+ regs->pc = addr;
4915+ regs->npc = addr+4;
4916+ return 2;
4917+ }
4918+ } while (0);
4919+
4920+ do { /* PaX: unpatched PLT emulation step 1 */
4921+ unsigned int sethi, ba, nop;
4922+
4923+ err = get_user(sethi, (unsigned int *)regs->pc);
4924+ err |= get_user(ba, (unsigned int *)(regs->pc+4));
4925+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
4926+
4927+ if (err)
4928+ break;
4929+
4930+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
4931+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
4932+ nop == 0x01000000U)
4933+ {
4934+ unsigned int addr, save, call;
4935+
4936+ if ((ba & 0xFFC00000U) == 0x30800000U)
4937+ addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
4938+ else
4939+ addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
4940+
4941+ err = get_user(save, (unsigned int *)addr);
4942+ err |= get_user(call, (unsigned int *)(addr+4));
4943+ err |= get_user(nop, (unsigned int *)(addr+8));
4944+ if (err)
4945+ break;
4946+
4947+#ifdef CONFIG_PAX_DLRESOLVE
4948+ if (save == 0x9DE3BFA8U &&
4949+ (call & 0xC0000000U) == 0x40000000U &&
4950+ nop == 0x01000000U)
4951+ {
4952+ struct vm_area_struct *vma;
4953+ unsigned long call_dl_resolve;
4954+
4955+ down_read(&current->mm->mmap_sem);
4956+ call_dl_resolve = current->mm->call_dl_resolve;
4957+ up_read(&current->mm->mmap_sem);
4958+ if (likely(call_dl_resolve))
4959+ goto emulate;
4960+
4961+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
4962+
4963+ down_write(&current->mm->mmap_sem);
4964+ if (current->mm->call_dl_resolve) {
4965+ call_dl_resolve = current->mm->call_dl_resolve;
4966+ up_write(&current->mm->mmap_sem);
4967+ if (vma)
4968+ kmem_cache_free(vm_area_cachep, vma);
4969+ goto emulate;
4970+ }
4971+
4972+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
4973+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
4974+ up_write(&current->mm->mmap_sem);
4975+ if (vma)
4976+ kmem_cache_free(vm_area_cachep, vma);
4977+ return 1;
4978+ }
4979+
4980+ if (pax_insert_vma(vma, call_dl_resolve)) {
4981+ up_write(&current->mm->mmap_sem);
4982+ kmem_cache_free(vm_area_cachep, vma);
4983+ return 1;
4984+ }
4985+
4986+ current->mm->call_dl_resolve = call_dl_resolve;
4987+ up_write(&current->mm->mmap_sem);
4988+
4989+emulate:
4990+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
4991+ regs->pc = call_dl_resolve;
4992+ regs->npc = addr+4;
4993+ return 3;
4994+ }
4995+#endif
4996+
4997+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
4998+ if ((save & 0xFFC00000U) == 0x05000000U &&
4999+ (call & 0xFFFFE000U) == 0x85C0A000U &&
5000+ nop == 0x01000000U)
5001+ {
5002+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
5003+ regs->u_regs[UREG_G2] = addr + 4;
5004+ addr = (save & 0x003FFFFFU) << 10;
5005+ addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
5006+ regs->pc = addr;
5007+ regs->npc = addr+4;
5008+ return 3;
5009+ }
5010+ }
5011+ } while (0);
5012+
5013+ do { /* PaX: unpatched PLT emulation step 2 */
5014+ unsigned int save, call, nop;
5015+
5016+ err = get_user(save, (unsigned int *)(regs->pc-4));
5017+ err |= get_user(call, (unsigned int *)regs->pc);
5018+ err |= get_user(nop, (unsigned int *)(regs->pc+4));
5019+ if (err)
5020+ break;
5021+
5022+ if (save == 0x9DE3BFA8U &&
5023+ (call & 0xC0000000U) == 0x40000000U &&
5024+ nop == 0x01000000U)
5025+ {
5026+ unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
5027+
5028+ regs->u_regs[UREG_RETPC] = regs->pc;
5029+ regs->pc = dl_resolve;
5030+ regs->npc = dl_resolve+4;
5031+ return 3;
5032+ }
5033+ } while (0);
5034+#endif
5035+
5036+ return 1;
5037+}
5038+
5039+void pax_report_insns(void *pc, void *sp)
5040+{
5041+ unsigned long i;
5042+
5043+ printk(KERN_ERR "PAX: bytes at PC: ");
5044+ for (i = 0; i < 8; i++) {
5045+ unsigned int c;
5046+ if (get_user(c, (unsigned int *)pc+i))
5047+ printk(KERN_CONT "???????? ");
5048+ else
5049+ printk(KERN_CONT "%08x ", c);
5050+ }
5051+ printk("\n");
5052+}
5053+#endif
5054+
5055 asmlinkage void do_sparc_fault(struct pt_regs *regs, int text_fault, int write,
5056 unsigned long address)
5057 {
5058@@ -231,6 +495,24 @@ good_area:
5059 if(!(vma->vm_flags & VM_WRITE))
5060 goto bad_area;
5061 } else {
5062+
5063+#ifdef CONFIG_PAX_PAGEEXEC
5064+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
5065+ up_read(&mm->mmap_sem);
5066+ switch (pax_handle_fetch_fault(regs)) {
5067+
5068+#ifdef CONFIG_PAX_EMUPLT
5069+ case 2:
5070+ case 3:
5071+ return;
5072+#endif
5073+
5074+ }
5075+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
5076+ do_group_exit(SIGKILL);
5077+ }
5078+#endif
5079+
5080 /* Allow reads even for write-only mappings */
5081 if(!(vma->vm_flags & (VM_READ | VM_EXEC)))
5082 goto bad_area;
5083diff -urNp linux-2.6.32.41/arch/sparc/mm/fault_64.c linux-2.6.32.41/arch/sparc/mm/fault_64.c
5084--- linux-2.6.32.41/arch/sparc/mm/fault_64.c 2011-03-27 14:31:47.000000000 -0400
5085+++ linux-2.6.32.41/arch/sparc/mm/fault_64.c 2011-04-17 15:56:46.000000000 -0400
5086@@ -20,6 +20,9 @@
5087 #include <linux/kprobes.h>
5088 #include <linux/kdebug.h>
5089 #include <linux/percpu.h>
5090+#include <linux/slab.h>
5091+#include <linux/pagemap.h>
5092+#include <linux/compiler.h>
5093
5094 #include <asm/page.h>
5095 #include <asm/pgtable.h>
5096@@ -78,7 +81,7 @@ static void bad_kernel_pc(struct pt_regs
5097 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
5098 regs->tpc);
5099 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
5100- printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
5101+ printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
5102 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
5103 dump_stack();
5104 unhandled_fault(regs->tpc, current, regs);
5105@@ -249,6 +252,456 @@ static void noinline bogus_32bit_fault_a
5106 show_regs(regs);
5107 }
5108
5109+#ifdef CONFIG_PAX_PAGEEXEC
5110+#ifdef CONFIG_PAX_DLRESOLVE
5111+static void pax_emuplt_close(struct vm_area_struct *vma)
5112+{
5113+ vma->vm_mm->call_dl_resolve = 0UL;
5114+}
5115+
5116+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
5117+{
5118+ unsigned int *kaddr;
5119+
5120+ vmf->page = alloc_page(GFP_HIGHUSER);
5121+ if (!vmf->page)
5122+ return VM_FAULT_OOM;
5123+
5124+ kaddr = kmap(vmf->page);
5125+ memset(kaddr, 0, PAGE_SIZE);
5126+ kaddr[0] = 0x9DE3BFA8U; /* save */
5127+ flush_dcache_page(vmf->page);
5128+ kunmap(vmf->page);
5129+ return VM_FAULT_MAJOR;
5130+}
5131+
5132+static const struct vm_operations_struct pax_vm_ops = {
5133+ .close = pax_emuplt_close,
5134+ .fault = pax_emuplt_fault
5135+};
5136+
5137+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
5138+{
5139+ int ret;
5140+
5141+ vma->vm_mm = current->mm;
5142+ vma->vm_start = addr;
5143+ vma->vm_end = addr + PAGE_SIZE;
5144+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
5145+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
5146+ vma->vm_ops = &pax_vm_ops;
5147+
5148+ ret = insert_vm_struct(current->mm, vma);
5149+ if (ret)
5150+ return ret;
5151+
5152+ ++current->mm->total_vm;
5153+ return 0;
5154+}
5155+#endif
5156+
5157+/*
5158+ * PaX: decide what to do with offenders (regs->tpc = fault address)
5159+ *
5160+ * returns 1 when task should be killed
5161+ * 2 when patched PLT trampoline was detected
5162+ * 3 when unpatched PLT trampoline was detected
5163+ */
5164+static int pax_handle_fetch_fault(struct pt_regs *regs)
5165+{
5166+
5167+#ifdef CONFIG_PAX_EMUPLT
5168+ int err;
5169+
5170+ do { /* PaX: patched PLT emulation #1 */
5171+ unsigned int sethi1, sethi2, jmpl;
5172+
5173+ err = get_user(sethi1, (unsigned int *)regs->tpc);
5174+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
5175+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
5176+
5177+ if (err)
5178+ break;
5179+
5180+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
5181+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
5182+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
5183+ {
5184+ unsigned long addr;
5185+
5186+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
5187+ addr = regs->u_regs[UREG_G1];
5188+ addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
5189+
5190+ if (test_thread_flag(TIF_32BIT))
5191+ addr &= 0xFFFFFFFFUL;
5192+
5193+ regs->tpc = addr;
5194+ regs->tnpc = addr+4;
5195+ return 2;
5196+ }
5197+ } while (0);
5198+
5199+ { /* PaX: patched PLT emulation #2 */
5200+ unsigned int ba;
5201+
5202+ err = get_user(ba, (unsigned int *)regs->tpc);
5203+
5204+ if (!err && (ba & 0xFFC00000U) == 0x30800000U) {
5205+ unsigned long addr;
5206+
5207+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
5208+
5209+ if (test_thread_flag(TIF_32BIT))
5210+ addr &= 0xFFFFFFFFUL;
5211+
5212+ regs->tpc = addr;
5213+ regs->tnpc = addr+4;
5214+ return 2;
5215+ }
5216+ }
5217+
5218+ do { /* PaX: patched PLT emulation #3 */
5219+ unsigned int sethi, jmpl, nop;
5220+
5221+ err = get_user(sethi, (unsigned int *)regs->tpc);
5222+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+4));
5223+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
5224+
5225+ if (err)
5226+ break;
5227+
5228+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
5229+ (jmpl & 0xFFFFE000U) == 0x81C06000U &&
5230+ nop == 0x01000000U)
5231+ {
5232+ unsigned long addr;
5233+
5234+ addr = (sethi & 0x003FFFFFU) << 10;
5235+ regs->u_regs[UREG_G1] = addr;
5236+ addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
5237+
5238+ if (test_thread_flag(TIF_32BIT))
5239+ addr &= 0xFFFFFFFFUL;
5240+
5241+ regs->tpc = addr;
5242+ regs->tnpc = addr+4;
5243+ return 2;
5244+ }
5245+ } while (0);
5246+
5247+ do { /* PaX: patched PLT emulation #4 */
5248+ unsigned int sethi, mov1, call, mov2;
5249+
5250+ err = get_user(sethi, (unsigned int *)regs->tpc);
5251+ err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
5252+ err |= get_user(call, (unsigned int *)(regs->tpc+8));
5253+ err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
5254+
5255+ if (err)
5256+ break;
5257+
5258+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
5259+ mov1 == 0x8210000FU &&
5260+ (call & 0xC0000000U) == 0x40000000U &&
5261+ mov2 == 0x9E100001U)
5262+ {
5263+ unsigned long addr;
5264+
5265+ regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
5266+ addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
5267+
5268+ if (test_thread_flag(TIF_32BIT))
5269+ addr &= 0xFFFFFFFFUL;
5270+
5271+ regs->tpc = addr;
5272+ regs->tnpc = addr+4;
5273+ return 2;
5274+ }
5275+ } while (0);
5276+
5277+ do { /* PaX: patched PLT emulation #5 */
5278+ unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
5279+
5280+ err = get_user(sethi, (unsigned int *)regs->tpc);
5281+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
5282+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
5283+ err |= get_user(or1, (unsigned int *)(regs->tpc+12));
5284+ err |= get_user(or2, (unsigned int *)(regs->tpc+16));
5285+ err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
5286+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
5287+ err |= get_user(nop, (unsigned int *)(regs->tpc+28));
5288+
5289+ if (err)
5290+ break;
5291+
5292+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
5293+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
5294+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
5295+ (or1 & 0xFFFFE000U) == 0x82106000U &&
5296+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
5297+ sllx == 0x83287020U &&
5298+ jmpl == 0x81C04005U &&
5299+ nop == 0x01000000U)
5300+ {
5301+ unsigned long addr;
5302+
5303+ regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
5304+ regs->u_regs[UREG_G1] <<= 32;
5305+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
5306+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
5307+ regs->tpc = addr;
5308+ regs->tnpc = addr+4;
5309+ return 2;
5310+ }
5311+ } while (0);
5312+
5313+ do { /* PaX: patched PLT emulation #6 */
5314+ unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
5315+
5316+ err = get_user(sethi, (unsigned int *)regs->tpc);
5317+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
5318+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
5319+ err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
5320+ err |= get_user(or, (unsigned int *)(regs->tpc+16));
5321+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
5322+ err |= get_user(nop, (unsigned int *)(regs->tpc+24));
5323+
5324+ if (err)
5325+ break;
5326+
5327+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
5328+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
5329+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
5330+ sllx == 0x83287020U &&
5331+ (or & 0xFFFFE000U) == 0x8A116000U &&
5332+ jmpl == 0x81C04005U &&
5333+ nop == 0x01000000U)
5334+ {
5335+ unsigned long addr;
5336+
5337+ regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
5338+ regs->u_regs[UREG_G1] <<= 32;
5339+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
5340+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
5341+ regs->tpc = addr;
5342+ regs->tnpc = addr+4;
5343+ return 2;
5344+ }
5345+ } while (0);
5346+
5347+ do { /* PaX: unpatched PLT emulation step 1 */
5348+ unsigned int sethi, ba, nop;
5349+
5350+ err = get_user(sethi, (unsigned int *)regs->tpc);
5351+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
5352+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
5353+
5354+ if (err)
5355+ break;
5356+
5357+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
5358+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
5359+ nop == 0x01000000U)
5360+ {
5361+ unsigned long addr;
5362+ unsigned int save, call;
5363+ unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
5364+
5365+ if ((ba & 0xFFC00000U) == 0x30800000U)
5366+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
5367+ else
5368+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
5369+
5370+ if (test_thread_flag(TIF_32BIT))
5371+ addr &= 0xFFFFFFFFUL;
5372+
5373+ err = get_user(save, (unsigned int *)addr);
5374+ err |= get_user(call, (unsigned int *)(addr+4));
5375+ err |= get_user(nop, (unsigned int *)(addr+8));
5376+ if (err)
5377+ break;
5378+
5379+#ifdef CONFIG_PAX_DLRESOLVE
5380+ if (save == 0x9DE3BFA8U &&
5381+ (call & 0xC0000000U) == 0x40000000U &&
5382+ nop == 0x01000000U)
5383+ {
5384+ struct vm_area_struct *vma;
5385+ unsigned long call_dl_resolve;
5386+
5387+ down_read(&current->mm->mmap_sem);
5388+ call_dl_resolve = current->mm->call_dl_resolve;
5389+ up_read(&current->mm->mmap_sem);
5390+ if (likely(call_dl_resolve))
5391+ goto emulate;
5392+
5393+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
5394+
5395+ down_write(&current->mm->mmap_sem);
5396+ if (current->mm->call_dl_resolve) {
5397+ call_dl_resolve = current->mm->call_dl_resolve;
5398+ up_write(&current->mm->mmap_sem);
5399+ if (vma)
5400+ kmem_cache_free(vm_area_cachep, vma);
5401+ goto emulate;
5402+ }
5403+
5404+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
5405+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
5406+ up_write(&current->mm->mmap_sem);
5407+ if (vma)
5408+ kmem_cache_free(vm_area_cachep, vma);
5409+ return 1;
5410+ }
5411+
5412+ if (pax_insert_vma(vma, call_dl_resolve)) {
5413+ up_write(&current->mm->mmap_sem);
5414+ kmem_cache_free(vm_area_cachep, vma);
5415+ return 1;
5416+ }
5417+
5418+ current->mm->call_dl_resolve = call_dl_resolve;
5419+ up_write(&current->mm->mmap_sem);
5420+
5421+emulate:
5422+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
5423+ regs->tpc = call_dl_resolve;
5424+ regs->tnpc = addr+4;
5425+ return 3;
5426+ }
5427+#endif
5428+
5429+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
5430+ if ((save & 0xFFC00000U) == 0x05000000U &&
5431+ (call & 0xFFFFE000U) == 0x85C0A000U &&
5432+ nop == 0x01000000U)
5433+ {
5434+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
5435+ regs->u_regs[UREG_G2] = addr + 4;
5436+ addr = (save & 0x003FFFFFU) << 10;
5437+ addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
5438+
5439+ if (test_thread_flag(TIF_32BIT))
5440+ addr &= 0xFFFFFFFFUL;
5441+
5442+ regs->tpc = addr;
5443+ regs->tnpc = addr+4;
5444+ return 3;
5445+ }
5446+
5447+ /* PaX: 64-bit PLT stub */
5448+ err = get_user(sethi1, (unsigned int *)addr);
5449+ err |= get_user(sethi2, (unsigned int *)(addr+4));
5450+ err |= get_user(or1, (unsigned int *)(addr+8));
5451+ err |= get_user(or2, (unsigned int *)(addr+12));
5452+ err |= get_user(sllx, (unsigned int *)(addr+16));
5453+ err |= get_user(add, (unsigned int *)(addr+20));
5454+ err |= get_user(jmpl, (unsigned int *)(addr+24));
5455+ err |= get_user(nop, (unsigned int *)(addr+28));
5456+ if (err)
5457+ break;
5458+
5459+ if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
5460+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
5461+ (or1 & 0xFFFFE000U) == 0x88112000U &&
5462+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
5463+ sllx == 0x89293020U &&
5464+ add == 0x8A010005U &&
5465+ jmpl == 0x89C14000U &&
5466+ nop == 0x01000000U)
5467+ {
5468+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
5469+ regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
5470+ regs->u_regs[UREG_G4] <<= 32;
5471+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
5472+ regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
5473+ regs->u_regs[UREG_G4] = addr + 24;
5474+ addr = regs->u_regs[UREG_G5];
5475+ regs->tpc = addr;
5476+ regs->tnpc = addr+4;
5477+ return 3;
5478+ }
5479+ }
5480+ } while (0);
5481+
5482+#ifdef CONFIG_PAX_DLRESOLVE
5483+ do { /* PaX: unpatched PLT emulation step 2 */
5484+ unsigned int save, call, nop;
5485+
5486+ err = get_user(save, (unsigned int *)(regs->tpc-4));
5487+ err |= get_user(call, (unsigned int *)regs->tpc);
5488+ err |= get_user(nop, (unsigned int *)(regs->tpc+4));
5489+ if (err)
5490+ break;
5491+
5492+ if (save == 0x9DE3BFA8U &&
5493+ (call & 0xC0000000U) == 0x40000000U &&
5494+ nop == 0x01000000U)
5495+ {
5496+ unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
5497+
5498+ if (test_thread_flag(TIF_32BIT))
5499+ dl_resolve &= 0xFFFFFFFFUL;
5500+
5501+ regs->u_regs[UREG_RETPC] = regs->tpc;
5502+ regs->tpc = dl_resolve;
5503+ regs->tnpc = dl_resolve+4;
5504+ return 3;
5505+ }
5506+ } while (0);
5507+#endif
5508+
5509+ do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
5510+ unsigned int sethi, ba, nop;
5511+
5512+ err = get_user(sethi, (unsigned int *)regs->tpc);
5513+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
5514+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
5515+
5516+ if (err)
5517+ break;
5518+
5519+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
5520+ (ba & 0xFFF00000U) == 0x30600000U &&
5521+ nop == 0x01000000U)
5522+ {
5523+ unsigned long addr;
5524+
5525+ addr = (sethi & 0x003FFFFFU) << 10;
5526+ regs->u_regs[UREG_G1] = addr;
5527+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
5528+
5529+ if (test_thread_flag(TIF_32BIT))
5530+ addr &= 0xFFFFFFFFUL;
5531+
5532+ regs->tpc = addr;
5533+ regs->tnpc = addr+4;
5534+ return 2;
5535+ }
5536+ } while (0);
5537+
5538+#endif
5539+
5540+ return 1;
5541+}
5542+
5543+void pax_report_insns(void *pc, void *sp)
5544+{
5545+ unsigned long i;
5546+
5547+ printk(KERN_ERR "PAX: bytes at PC: ");
5548+ for (i = 0; i < 8; i++) {
5549+ unsigned int c;
5550+ if (get_user(c, (unsigned int *)pc+i))
5551+ printk(KERN_CONT "???????? ");
5552+ else
5553+ printk(KERN_CONT "%08x ", c);
5554+ }
5555+ printk("\n");
5556+}
5557+#endif
5558+
5559 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
5560 {
5561 struct mm_struct *mm = current->mm;
5562@@ -315,6 +768,29 @@ asmlinkage void __kprobes do_sparc64_fau
5563 if (!vma)
5564 goto bad_area;
5565
5566+#ifdef CONFIG_PAX_PAGEEXEC
5567+ /* PaX: detect ITLB misses on non-exec pages */
5568+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
5569+ !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
5570+ {
5571+ if (address != regs->tpc)
5572+ goto good_area;
5573+
5574+ up_read(&mm->mmap_sem);
5575+ switch (pax_handle_fetch_fault(regs)) {
5576+
5577+#ifdef CONFIG_PAX_EMUPLT
5578+ case 2:
5579+ case 3:
5580+ return;
5581+#endif
5582+
5583+ }
5584+ pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
5585+ do_group_exit(SIGKILL);
5586+ }
5587+#endif
5588+
5589 /* Pure DTLB misses do not tell us whether the fault causing
5590 * load/store/atomic was a write or not, it only says that there
5591 * was no match. So in such a case we (carefully) read the
5592diff -urNp linux-2.6.32.41/arch/sparc/mm/hugetlbpage.c linux-2.6.32.41/arch/sparc/mm/hugetlbpage.c
5593--- linux-2.6.32.41/arch/sparc/mm/hugetlbpage.c 2011-03-27 14:31:47.000000000 -0400
5594+++ linux-2.6.32.41/arch/sparc/mm/hugetlbpage.c 2011-04-17 15:56:46.000000000 -0400
5595@@ -69,7 +69,7 @@ full_search:
5596 }
5597 return -ENOMEM;
5598 }
5599- if (likely(!vma || addr + len <= vma->vm_start)) {
5600+ if (likely(check_heap_stack_gap(vma, addr, len))) {
5601 /*
5602 * Remember the place where we stopped the search:
5603 */
5604@@ -108,7 +108,7 @@ hugetlb_get_unmapped_area_topdown(struct
5605 /* make sure it can fit in the remaining address space */
5606 if (likely(addr > len)) {
5607 vma = find_vma(mm, addr-len);
5608- if (!vma || addr <= vma->vm_start) {
5609+ if (check_heap_stack_gap(vma, addr - len, len)) {
5610 /* remember the address as a hint for next time */
5611 return (mm->free_area_cache = addr-len);
5612 }
5613@@ -117,16 +117,17 @@ hugetlb_get_unmapped_area_topdown(struct
5614 if (unlikely(mm->mmap_base < len))
5615 goto bottomup;
5616
5617- addr = (mm->mmap_base-len) & HPAGE_MASK;
5618+ addr = mm->mmap_base - len;
5619
5620 do {
5621+ addr &= HPAGE_MASK;
5622 /*
5623 * Lookup failure means no vma is above this address,
5624 * else if new region fits below vma->vm_start,
5625 * return with success:
5626 */
5627 vma = find_vma(mm, addr);
5628- if (likely(!vma || addr+len <= vma->vm_start)) {
5629+ if (likely(check_heap_stack_gap(vma, addr, len))) {
5630 /* remember the address as a hint for next time */
5631 return (mm->free_area_cache = addr);
5632 }
5633@@ -136,8 +137,8 @@ hugetlb_get_unmapped_area_topdown(struct
5634 mm->cached_hole_size = vma->vm_start - addr;
5635
5636 /* try just below the current vma->vm_start */
5637- addr = (vma->vm_start-len) & HPAGE_MASK;
5638- } while (likely(len < vma->vm_start));
5639+ addr = skip_heap_stack_gap(vma, len);
5640+ } while (!IS_ERR_VALUE(addr));
5641
5642 bottomup:
5643 /*
5644@@ -183,8 +184,7 @@ hugetlb_get_unmapped_area(struct file *f
5645 if (addr) {
5646 addr = ALIGN(addr, HPAGE_SIZE);
5647 vma = find_vma(mm, addr);
5648- if (task_size - len >= addr &&
5649- (!vma || addr + len <= vma->vm_start))
5650+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
5651 return addr;
5652 }
5653 if (mm->get_unmapped_area == arch_get_unmapped_area)
5654diff -urNp linux-2.6.32.41/arch/sparc/mm/init_32.c linux-2.6.32.41/arch/sparc/mm/init_32.c
5655--- linux-2.6.32.41/arch/sparc/mm/init_32.c 2011-03-27 14:31:47.000000000 -0400
5656+++ linux-2.6.32.41/arch/sparc/mm/init_32.c 2011-04-17 15:56:46.000000000 -0400
5657@@ -317,6 +317,9 @@ extern void device_scan(void);
5658 pgprot_t PAGE_SHARED __read_mostly;
5659 EXPORT_SYMBOL(PAGE_SHARED);
5660
5661+pgprot_t PAGE_SHARED_NOEXEC __read_mostly;
5662+EXPORT_SYMBOL(PAGE_SHARED_NOEXEC);
5663+
5664 void __init paging_init(void)
5665 {
5666 switch(sparc_cpu_model) {
5667@@ -345,17 +348,17 @@ void __init paging_init(void)
5668
5669 /* Initialize the protection map with non-constant, MMU dependent values. */
5670 protection_map[0] = PAGE_NONE;
5671- protection_map[1] = PAGE_READONLY;
5672- protection_map[2] = PAGE_COPY;
5673- protection_map[3] = PAGE_COPY;
5674+ protection_map[1] = PAGE_READONLY_NOEXEC;
5675+ protection_map[2] = PAGE_COPY_NOEXEC;
5676+ protection_map[3] = PAGE_COPY_NOEXEC;
5677 protection_map[4] = PAGE_READONLY;
5678 protection_map[5] = PAGE_READONLY;
5679 protection_map[6] = PAGE_COPY;
5680 protection_map[7] = PAGE_COPY;
5681 protection_map[8] = PAGE_NONE;
5682- protection_map[9] = PAGE_READONLY;
5683- protection_map[10] = PAGE_SHARED;
5684- protection_map[11] = PAGE_SHARED;
5685+ protection_map[9] = PAGE_READONLY_NOEXEC;
5686+ protection_map[10] = PAGE_SHARED_NOEXEC;
5687+ protection_map[11] = PAGE_SHARED_NOEXEC;
5688 protection_map[12] = PAGE_READONLY;
5689 protection_map[13] = PAGE_READONLY;
5690 protection_map[14] = PAGE_SHARED;
5691diff -urNp linux-2.6.32.41/arch/sparc/mm/Makefile linux-2.6.32.41/arch/sparc/mm/Makefile
5692--- linux-2.6.32.41/arch/sparc/mm/Makefile 2011-03-27 14:31:47.000000000 -0400
5693+++ linux-2.6.32.41/arch/sparc/mm/Makefile 2011-04-17 15:56:46.000000000 -0400
5694@@ -2,7 +2,7 @@
5695 #
5696
5697 asflags-y := -ansi
5698-ccflags-y := -Werror
5699+#ccflags-y := -Werror
5700
5701 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o
5702 obj-y += fault_$(BITS).o
5703diff -urNp linux-2.6.32.41/arch/sparc/mm/srmmu.c linux-2.6.32.41/arch/sparc/mm/srmmu.c
5704--- linux-2.6.32.41/arch/sparc/mm/srmmu.c 2011-03-27 14:31:47.000000000 -0400
5705+++ linux-2.6.32.41/arch/sparc/mm/srmmu.c 2011-04-17 15:56:46.000000000 -0400
5706@@ -2200,6 +2200,13 @@ void __init ld_mmu_srmmu(void)
5707 PAGE_SHARED = pgprot_val(SRMMU_PAGE_SHARED);
5708 BTFIXUPSET_INT(page_copy, pgprot_val(SRMMU_PAGE_COPY));
5709 BTFIXUPSET_INT(page_readonly, pgprot_val(SRMMU_PAGE_RDONLY));
5710+
5711+#ifdef CONFIG_PAX_PAGEEXEC
5712+ PAGE_SHARED_NOEXEC = pgprot_val(SRMMU_PAGE_SHARED_NOEXEC);
5713+ BTFIXUPSET_INT(page_copy_noexec, pgprot_val(SRMMU_PAGE_COPY_NOEXEC));
5714+ BTFIXUPSET_INT(page_readonly_noexec, pgprot_val(SRMMU_PAGE_RDONLY_NOEXEC));
5715+#endif
5716+
5717 BTFIXUPSET_INT(page_kernel, pgprot_val(SRMMU_PAGE_KERNEL));
5718 page_kernel = pgprot_val(SRMMU_PAGE_KERNEL);
5719
5720diff -urNp linux-2.6.32.41/arch/um/include/asm/kmap_types.h linux-2.6.32.41/arch/um/include/asm/kmap_types.h
5721--- linux-2.6.32.41/arch/um/include/asm/kmap_types.h 2011-03-27 14:31:47.000000000 -0400
5722+++ linux-2.6.32.41/arch/um/include/asm/kmap_types.h 2011-04-17 15:56:46.000000000 -0400
5723@@ -23,6 +23,7 @@ enum km_type {
5724 KM_IRQ1,
5725 KM_SOFTIRQ0,
5726 KM_SOFTIRQ1,
5727+ KM_CLEARPAGE,
5728 KM_TYPE_NR
5729 };
5730
5731diff -urNp linux-2.6.32.41/arch/um/include/asm/page.h linux-2.6.32.41/arch/um/include/asm/page.h
5732--- linux-2.6.32.41/arch/um/include/asm/page.h 2011-03-27 14:31:47.000000000 -0400
5733+++ linux-2.6.32.41/arch/um/include/asm/page.h 2011-04-17 15:56:46.000000000 -0400
5734@@ -14,6 +14,9 @@
5735 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
5736 #define PAGE_MASK (~(PAGE_SIZE-1))
5737
5738+#define ktla_ktva(addr) (addr)
5739+#define ktva_ktla(addr) (addr)
5740+
5741 #ifndef __ASSEMBLY__
5742
5743 struct page;
5744diff -urNp linux-2.6.32.41/arch/um/kernel/process.c linux-2.6.32.41/arch/um/kernel/process.c
5745--- linux-2.6.32.41/arch/um/kernel/process.c 2011-03-27 14:31:47.000000000 -0400
5746+++ linux-2.6.32.41/arch/um/kernel/process.c 2011-04-17 15:56:46.000000000 -0400
5747@@ -393,22 +393,6 @@ int singlestepping(void * t)
5748 return 2;
5749 }
5750
5751-/*
5752- * Only x86 and x86_64 have an arch_align_stack().
5753- * All other arches have "#define arch_align_stack(x) (x)"
5754- * in their asm/system.h
5755- * As this is included in UML from asm-um/system-generic.h,
5756- * we can use it to behave as the subarch does.
5757- */
5758-#ifndef arch_align_stack
5759-unsigned long arch_align_stack(unsigned long sp)
5760-{
5761- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
5762- sp -= get_random_int() % 8192;
5763- return sp & ~0xf;
5764-}
5765-#endif
5766-
5767 unsigned long get_wchan(struct task_struct *p)
5768 {
5769 unsigned long stack_page, sp, ip;
5770diff -urNp linux-2.6.32.41/arch/um/sys-i386/syscalls.c linux-2.6.32.41/arch/um/sys-i386/syscalls.c
5771--- linux-2.6.32.41/arch/um/sys-i386/syscalls.c 2011-03-27 14:31:47.000000000 -0400
5772+++ linux-2.6.32.41/arch/um/sys-i386/syscalls.c 2011-04-17 15:56:46.000000000 -0400
5773@@ -11,6 +11,21 @@
5774 #include "asm/uaccess.h"
5775 #include "asm/unistd.h"
5776
5777+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
5778+{
5779+ unsigned long pax_task_size = TASK_SIZE;
5780+
5781+#ifdef CONFIG_PAX_SEGMEXEC
5782+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
5783+ pax_task_size = SEGMEXEC_TASK_SIZE;
5784+#endif
5785+
5786+ if (len > pax_task_size || addr > pax_task_size - len)
5787+ return -EINVAL;
5788+
5789+ return 0;
5790+}
5791+
5792 /*
5793 * Perform the select(nd, in, out, ex, tv) and mmap() system
5794 * calls. Linux/i386 didn't use to be able to handle more than
5795diff -urNp linux-2.6.32.41/arch/x86/boot/bitops.h linux-2.6.32.41/arch/x86/boot/bitops.h
5796--- linux-2.6.32.41/arch/x86/boot/bitops.h 2011-03-27 14:31:47.000000000 -0400
5797+++ linux-2.6.32.41/arch/x86/boot/bitops.h 2011-04-17 15:56:46.000000000 -0400
5798@@ -26,7 +26,7 @@ static inline int variable_test_bit(int
5799 u8 v;
5800 const u32 *p = (const u32 *)addr;
5801
5802- asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
5803+ asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
5804 return v;
5805 }
5806
5807@@ -37,7 +37,7 @@ static inline int variable_test_bit(int
5808
5809 static inline void set_bit(int nr, void *addr)
5810 {
5811- asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
5812+ asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
5813 }
5814
5815 #endif /* BOOT_BITOPS_H */
5816diff -urNp linux-2.6.32.41/arch/x86/boot/boot.h linux-2.6.32.41/arch/x86/boot/boot.h
5817--- linux-2.6.32.41/arch/x86/boot/boot.h 2011-03-27 14:31:47.000000000 -0400
5818+++ linux-2.6.32.41/arch/x86/boot/boot.h 2011-04-17 15:56:46.000000000 -0400
5819@@ -82,7 +82,7 @@ static inline void io_delay(void)
5820 static inline u16 ds(void)
5821 {
5822 u16 seg;
5823- asm("movw %%ds,%0" : "=rm" (seg));
5824+ asm volatile("movw %%ds,%0" : "=rm" (seg));
5825 return seg;
5826 }
5827
5828@@ -178,7 +178,7 @@ static inline void wrgs32(u32 v, addr_t
5829 static inline int memcmp(const void *s1, const void *s2, size_t len)
5830 {
5831 u8 diff;
5832- asm("repe; cmpsb; setnz %0"
5833+ asm volatile("repe; cmpsb; setnz %0"
5834 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
5835 return diff;
5836 }
5837diff -urNp linux-2.6.32.41/arch/x86/boot/compressed/head_32.S linux-2.6.32.41/arch/x86/boot/compressed/head_32.S
5838--- linux-2.6.32.41/arch/x86/boot/compressed/head_32.S 2011-03-27 14:31:47.000000000 -0400
5839+++ linux-2.6.32.41/arch/x86/boot/compressed/head_32.S 2011-04-17 15:56:46.000000000 -0400
5840@@ -76,7 +76,7 @@ ENTRY(startup_32)
5841 notl %eax
5842 andl %eax, %ebx
5843 #else
5844- movl $LOAD_PHYSICAL_ADDR, %ebx
5845+ movl $____LOAD_PHYSICAL_ADDR, %ebx
5846 #endif
5847
5848 /* Target address to relocate to for decompression */
5849@@ -149,7 +149,7 @@ relocated:
5850 * and where it was actually loaded.
5851 */
5852 movl %ebp, %ebx
5853- subl $LOAD_PHYSICAL_ADDR, %ebx
5854+ subl $____LOAD_PHYSICAL_ADDR, %ebx
5855 jz 2f /* Nothing to be done if loaded at compiled addr. */
5856 /*
5857 * Process relocations.
5858@@ -157,8 +157,7 @@ relocated:
5859
5860 1: subl $4, %edi
5861 movl (%edi), %ecx
5862- testl %ecx, %ecx
5863- jz 2f
5864+ jecxz 2f
5865 addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
5866 jmp 1b
5867 2:
5868diff -urNp linux-2.6.32.41/arch/x86/boot/compressed/head_64.S linux-2.6.32.41/arch/x86/boot/compressed/head_64.S
5869--- linux-2.6.32.41/arch/x86/boot/compressed/head_64.S 2011-03-27 14:31:47.000000000 -0400
5870+++ linux-2.6.32.41/arch/x86/boot/compressed/head_64.S 2011-04-17 15:56:46.000000000 -0400
5871@@ -91,7 +91,7 @@ ENTRY(startup_32)
5872 notl %eax
5873 andl %eax, %ebx
5874 #else
5875- movl $LOAD_PHYSICAL_ADDR, %ebx
5876+ movl $____LOAD_PHYSICAL_ADDR, %ebx
5877 #endif
5878
5879 /* Target address to relocate to for decompression */
5880@@ -234,7 +234,7 @@ ENTRY(startup_64)
5881 notq %rax
5882 andq %rax, %rbp
5883 #else
5884- movq $LOAD_PHYSICAL_ADDR, %rbp
5885+ movq $____LOAD_PHYSICAL_ADDR, %rbp
5886 #endif
5887
5888 /* Target address to relocate to for decompression */
5889diff -urNp linux-2.6.32.41/arch/x86/boot/compressed/misc.c linux-2.6.32.41/arch/x86/boot/compressed/misc.c
5890--- linux-2.6.32.41/arch/x86/boot/compressed/misc.c 2011-03-27 14:31:47.000000000 -0400
5891+++ linux-2.6.32.41/arch/x86/boot/compressed/misc.c 2011-04-17 15:56:46.000000000 -0400
5892@@ -288,7 +288,7 @@ static void parse_elf(void *output)
5893 case PT_LOAD:
5894 #ifdef CONFIG_RELOCATABLE
5895 dest = output;
5896- dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
5897+ dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
5898 #else
5899 dest = (void *)(phdr->p_paddr);
5900 #endif
5901@@ -335,7 +335,7 @@ asmlinkage void decompress_kernel(void *
5902 error("Destination address too large");
5903 #endif
5904 #ifndef CONFIG_RELOCATABLE
5905- if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
5906+ if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
5907 error("Wrong destination address");
5908 #endif
5909
5910diff -urNp linux-2.6.32.41/arch/x86/boot/compressed/mkpiggy.c linux-2.6.32.41/arch/x86/boot/compressed/mkpiggy.c
5911--- linux-2.6.32.41/arch/x86/boot/compressed/mkpiggy.c 2011-03-27 14:31:47.000000000 -0400
5912+++ linux-2.6.32.41/arch/x86/boot/compressed/mkpiggy.c 2011-04-17 15:56:46.000000000 -0400
5913@@ -74,7 +74,7 @@ int main(int argc, char *argv[])
5914
5915 offs = (olen > ilen) ? olen - ilen : 0;
5916 offs += olen >> 12; /* Add 8 bytes for each 32K block */
5917- offs += 32*1024 + 18; /* Add 32K + 18 bytes slack */
5918+ offs += 64*1024; /* Add 64K bytes slack */
5919 offs = (offs+4095) & ~4095; /* Round to a 4K boundary */
5920
5921 printf(".section \".rodata.compressed\",\"a\",@progbits\n");
5922diff -urNp linux-2.6.32.41/arch/x86/boot/compressed/relocs.c linux-2.6.32.41/arch/x86/boot/compressed/relocs.c
5923--- linux-2.6.32.41/arch/x86/boot/compressed/relocs.c 2011-03-27 14:31:47.000000000 -0400
5924+++ linux-2.6.32.41/arch/x86/boot/compressed/relocs.c 2011-04-17 15:56:46.000000000 -0400
5925@@ -10,8 +10,11 @@
5926 #define USE_BSD
5927 #include <endian.h>
5928
5929+#include "../../../../include/linux/autoconf.h"
5930+
5931 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
5932 static Elf32_Ehdr ehdr;
5933+static Elf32_Phdr *phdr;
5934 static unsigned long reloc_count, reloc_idx;
5935 static unsigned long *relocs;
5936
5937@@ -37,7 +40,7 @@ static const char* safe_abs_relocs[] = {
5938
5939 static int is_safe_abs_reloc(const char* sym_name)
5940 {
5941- int i;
5942+ unsigned int i;
5943
5944 for (i = 0; i < ARRAY_SIZE(safe_abs_relocs); i++) {
5945 if (!strcmp(sym_name, safe_abs_relocs[i]))
5946@@ -245,9 +248,39 @@ static void read_ehdr(FILE *fp)
5947 }
5948 }
5949
5950+static void read_phdrs(FILE *fp)
5951+{
5952+ unsigned int i;
5953+
5954+ phdr = calloc(ehdr.e_phnum, sizeof(Elf32_Phdr));
5955+ if (!phdr) {
5956+ die("Unable to allocate %d program headers\n",
5957+ ehdr.e_phnum);
5958+ }
5959+ if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
5960+ die("Seek to %d failed: %s\n",
5961+ ehdr.e_phoff, strerror(errno));
5962+ }
5963+ if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
5964+ die("Cannot read ELF program headers: %s\n",
5965+ strerror(errno));
5966+ }
5967+ for(i = 0; i < ehdr.e_phnum; i++) {
5968+ phdr[i].p_type = elf32_to_cpu(phdr[i].p_type);
5969+ phdr[i].p_offset = elf32_to_cpu(phdr[i].p_offset);
5970+ phdr[i].p_vaddr = elf32_to_cpu(phdr[i].p_vaddr);
5971+ phdr[i].p_paddr = elf32_to_cpu(phdr[i].p_paddr);
5972+ phdr[i].p_filesz = elf32_to_cpu(phdr[i].p_filesz);
5973+ phdr[i].p_memsz = elf32_to_cpu(phdr[i].p_memsz);
5974+ phdr[i].p_flags = elf32_to_cpu(phdr[i].p_flags);
5975+ phdr[i].p_align = elf32_to_cpu(phdr[i].p_align);
5976+ }
5977+
5978+}
5979+
5980 static void read_shdrs(FILE *fp)
5981 {
5982- int i;
5983+ unsigned int i;
5984 Elf32_Shdr shdr;
5985
5986 secs = calloc(ehdr.e_shnum, sizeof(struct section));
5987@@ -282,7 +315,7 @@ static void read_shdrs(FILE *fp)
5988
5989 static void read_strtabs(FILE *fp)
5990 {
5991- int i;
5992+ unsigned int i;
5993 for (i = 0; i < ehdr.e_shnum; i++) {
5994 struct section *sec = &secs[i];
5995 if (sec->shdr.sh_type != SHT_STRTAB) {
5996@@ -307,7 +340,7 @@ static void read_strtabs(FILE *fp)
5997
5998 static void read_symtabs(FILE *fp)
5999 {
6000- int i,j;
6001+ unsigned int i,j;
6002 for (i = 0; i < ehdr.e_shnum; i++) {
6003 struct section *sec = &secs[i];
6004 if (sec->shdr.sh_type != SHT_SYMTAB) {
6005@@ -340,7 +373,9 @@ static void read_symtabs(FILE *fp)
6006
6007 static void read_relocs(FILE *fp)
6008 {
6009- int i,j;
6010+ unsigned int i,j;
6011+ uint32_t base;
6012+
6013 for (i = 0; i < ehdr.e_shnum; i++) {
6014 struct section *sec = &secs[i];
6015 if (sec->shdr.sh_type != SHT_REL) {
6016@@ -360,9 +395,18 @@ static void read_relocs(FILE *fp)
6017 die("Cannot read symbol table: %s\n",
6018 strerror(errno));
6019 }
6020+ base = 0;
6021+ for (j = 0; j < ehdr.e_phnum; j++) {
6022+ if (phdr[j].p_type != PT_LOAD )
6023+ continue;
6024+ 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)
6025+ continue;
6026+ base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
6027+ break;
6028+ }
6029 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Rel); j++) {
6030 Elf32_Rel *rel = &sec->reltab[j];
6031- rel->r_offset = elf32_to_cpu(rel->r_offset);
6032+ rel->r_offset = elf32_to_cpu(rel->r_offset) + base;
6033 rel->r_info = elf32_to_cpu(rel->r_info);
6034 }
6035 }
6036@@ -371,14 +415,14 @@ static void read_relocs(FILE *fp)
6037
6038 static void print_absolute_symbols(void)
6039 {
6040- int i;
6041+ unsigned int i;
6042 printf("Absolute symbols\n");
6043 printf(" Num: Value Size Type Bind Visibility Name\n");
6044 for (i = 0; i < ehdr.e_shnum; i++) {
6045 struct section *sec = &secs[i];
6046 char *sym_strtab;
6047 Elf32_Sym *sh_symtab;
6048- int j;
6049+ unsigned int j;
6050
6051 if (sec->shdr.sh_type != SHT_SYMTAB) {
6052 continue;
6053@@ -406,14 +450,14 @@ static void print_absolute_symbols(void)
6054
6055 static void print_absolute_relocs(void)
6056 {
6057- int i, printed = 0;
6058+ unsigned int i, printed = 0;
6059
6060 for (i = 0; i < ehdr.e_shnum; i++) {
6061 struct section *sec = &secs[i];
6062 struct section *sec_applies, *sec_symtab;
6063 char *sym_strtab;
6064 Elf32_Sym *sh_symtab;
6065- int j;
6066+ unsigned int j;
6067 if (sec->shdr.sh_type != SHT_REL) {
6068 continue;
6069 }
6070@@ -474,13 +518,13 @@ static void print_absolute_relocs(void)
6071
6072 static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym))
6073 {
6074- int i;
6075+ unsigned int i;
6076 /* Walk through the relocations */
6077 for (i = 0; i < ehdr.e_shnum; i++) {
6078 char *sym_strtab;
6079 Elf32_Sym *sh_symtab;
6080 struct section *sec_applies, *sec_symtab;
6081- int j;
6082+ unsigned int j;
6083 struct section *sec = &secs[i];
6084
6085 if (sec->shdr.sh_type != SHT_REL) {
6086@@ -504,6 +548,21 @@ static void walk_relocs(void (*visit)(El
6087 if (sym->st_shndx == SHN_ABS) {
6088 continue;
6089 }
6090+ /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
6091+ if (!strcmp(sec_name(sym->st_shndx), ".data.percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
6092+ continue;
6093+
6094+#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
6095+ /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
6096+ if (!strcmp(sec_name(sym->st_shndx), ".module.text") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
6097+ continue;
6098+ if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
6099+ continue;
6100+ if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
6101+ continue;
6102+ if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
6103+ continue;
6104+#endif
6105 if (r_type == R_386_NONE || r_type == R_386_PC32) {
6106 /*
6107 * NONE can be ignored and and PC relative
6108@@ -541,7 +600,7 @@ static int cmp_relocs(const void *va, co
6109
6110 static void emit_relocs(int as_text)
6111 {
6112- int i;
6113+ unsigned int i;
6114 /* Count how many relocations I have and allocate space for them. */
6115 reloc_count = 0;
6116 walk_relocs(count_reloc);
6117@@ -634,6 +693,7 @@ int main(int argc, char **argv)
6118 fname, strerror(errno));
6119 }
6120 read_ehdr(fp);
6121+ read_phdrs(fp);
6122 read_shdrs(fp);
6123 read_strtabs(fp);
6124 read_symtabs(fp);
6125diff -urNp linux-2.6.32.41/arch/x86/boot/cpucheck.c linux-2.6.32.41/arch/x86/boot/cpucheck.c
6126--- linux-2.6.32.41/arch/x86/boot/cpucheck.c 2011-03-27 14:31:47.000000000 -0400
6127+++ linux-2.6.32.41/arch/x86/boot/cpucheck.c 2011-04-17 15:56:46.000000000 -0400
6128@@ -74,7 +74,7 @@ static int has_fpu(void)
6129 u16 fcw = -1, fsw = -1;
6130 u32 cr0;
6131
6132- asm("movl %%cr0,%0" : "=r" (cr0));
6133+ asm volatile("movl %%cr0,%0" : "=r" (cr0));
6134 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
6135 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
6136 asm volatile("movl %0,%%cr0" : : "r" (cr0));
6137@@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
6138 {
6139 u32 f0, f1;
6140
6141- asm("pushfl ; "
6142+ asm volatile("pushfl ; "
6143 "pushfl ; "
6144 "popl %0 ; "
6145 "movl %0,%1 ; "
6146@@ -115,7 +115,7 @@ static void get_flags(void)
6147 set_bit(X86_FEATURE_FPU, cpu.flags);
6148
6149 if (has_eflag(X86_EFLAGS_ID)) {
6150- asm("cpuid"
6151+ asm volatile("cpuid"
6152 : "=a" (max_intel_level),
6153 "=b" (cpu_vendor[0]),
6154 "=d" (cpu_vendor[1]),
6155@@ -124,7 +124,7 @@ static void get_flags(void)
6156
6157 if (max_intel_level >= 0x00000001 &&
6158 max_intel_level <= 0x0000ffff) {
6159- asm("cpuid"
6160+ asm volatile("cpuid"
6161 : "=a" (tfms),
6162 "=c" (cpu.flags[4]),
6163 "=d" (cpu.flags[0])
6164@@ -136,7 +136,7 @@ static void get_flags(void)
6165 cpu.model += ((tfms >> 16) & 0xf) << 4;
6166 }
6167
6168- asm("cpuid"
6169+ asm volatile("cpuid"
6170 : "=a" (max_amd_level)
6171 : "a" (0x80000000)
6172 : "ebx", "ecx", "edx");
6173@@ -144,7 +144,7 @@ static void get_flags(void)
6174 if (max_amd_level >= 0x80000001 &&
6175 max_amd_level <= 0x8000ffff) {
6176 u32 eax = 0x80000001;
6177- asm("cpuid"
6178+ asm volatile("cpuid"
6179 : "+a" (eax),
6180 "=c" (cpu.flags[6]),
6181 "=d" (cpu.flags[1])
6182@@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *r
6183 u32 ecx = MSR_K7_HWCR;
6184 u32 eax, edx;
6185
6186- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
6187+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
6188 eax &= ~(1 << 15);
6189- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
6190+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
6191
6192 get_flags(); /* Make sure it really did something */
6193 err = check_flags();
6194@@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *r
6195 u32 ecx = MSR_VIA_FCR;
6196 u32 eax, edx;
6197
6198- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
6199+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
6200 eax |= (1<<1)|(1<<7);
6201- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
6202+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
6203
6204 set_bit(X86_FEATURE_CX8, cpu.flags);
6205 err = check_flags();
6206@@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *r
6207 u32 eax, edx;
6208 u32 level = 1;
6209
6210- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
6211- asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
6212- asm("cpuid"
6213+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
6214+ asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
6215+ asm volatile("cpuid"
6216 : "+a" (level), "=d" (cpu.flags[0])
6217 : : "ecx", "ebx");
6218- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
6219+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
6220
6221 err = check_flags();
6222 }
6223diff -urNp linux-2.6.32.41/arch/x86/boot/header.S linux-2.6.32.41/arch/x86/boot/header.S
6224--- linux-2.6.32.41/arch/x86/boot/header.S 2011-03-27 14:31:47.000000000 -0400
6225+++ linux-2.6.32.41/arch/x86/boot/header.S 2011-04-17 15:56:46.000000000 -0400
6226@@ -224,7 +224,7 @@ setup_data: .quad 0 # 64-bit physical
6227 # single linked list of
6228 # struct setup_data
6229
6230-pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
6231+pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
6232
6233 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
6234 #define VO_INIT_SIZE (VO__end - VO__text)
6235diff -urNp linux-2.6.32.41/arch/x86/boot/memory.c linux-2.6.32.41/arch/x86/boot/memory.c
6236--- linux-2.6.32.41/arch/x86/boot/memory.c 2011-03-27 14:31:47.000000000 -0400
6237+++ linux-2.6.32.41/arch/x86/boot/memory.c 2011-04-17 15:56:46.000000000 -0400
6238@@ -19,7 +19,7 @@
6239
6240 static int detect_memory_e820(void)
6241 {
6242- int count = 0;
6243+ unsigned int count = 0;
6244 struct biosregs ireg, oreg;
6245 struct e820entry *desc = boot_params.e820_map;
6246 static struct e820entry buf; /* static so it is zeroed */
6247diff -urNp linux-2.6.32.41/arch/x86/boot/video.c linux-2.6.32.41/arch/x86/boot/video.c
6248--- linux-2.6.32.41/arch/x86/boot/video.c 2011-03-27 14:31:47.000000000 -0400
6249+++ linux-2.6.32.41/arch/x86/boot/video.c 2011-04-17 15:56:46.000000000 -0400
6250@@ -90,7 +90,7 @@ static void store_mode_params(void)
6251 static unsigned int get_entry(void)
6252 {
6253 char entry_buf[4];
6254- int i, len = 0;
6255+ unsigned int i, len = 0;
6256 int key;
6257 unsigned int v;
6258
6259diff -urNp linux-2.6.32.41/arch/x86/boot/video-vesa.c linux-2.6.32.41/arch/x86/boot/video-vesa.c
6260--- linux-2.6.32.41/arch/x86/boot/video-vesa.c 2011-03-27 14:31:47.000000000 -0400
6261+++ linux-2.6.32.41/arch/x86/boot/video-vesa.c 2011-04-17 15:56:46.000000000 -0400
6262@@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
6263
6264 boot_params.screen_info.vesapm_seg = oreg.es;
6265 boot_params.screen_info.vesapm_off = oreg.di;
6266+ boot_params.screen_info.vesapm_size = oreg.cx;
6267 }
6268
6269 /*
6270diff -urNp linux-2.6.32.41/arch/x86/ia32/ia32_aout.c linux-2.6.32.41/arch/x86/ia32/ia32_aout.c
6271--- linux-2.6.32.41/arch/x86/ia32/ia32_aout.c 2011-03-27 14:31:47.000000000 -0400
6272+++ linux-2.6.32.41/arch/x86/ia32/ia32_aout.c 2011-04-17 15:56:46.000000000 -0400
6273@@ -169,6 +169,8 @@ static int aout_core_dump(long signr, st
6274 unsigned long dump_start, dump_size;
6275 struct user32 dump;
6276
6277+ memset(&dump, 0, sizeof(dump));
6278+
6279 fs = get_fs();
6280 set_fs(KERNEL_DS);
6281 has_dumped = 1;
6282@@ -218,12 +220,6 @@ static int aout_core_dump(long signr, st
6283 dump_size = dump.u_ssize << PAGE_SHIFT;
6284 DUMP_WRITE(dump_start, dump_size);
6285 }
6286- /*
6287- * Finally dump the task struct. Not be used by gdb, but
6288- * could be useful
6289- */
6290- set_fs(KERNEL_DS);
6291- DUMP_WRITE(current, sizeof(*current));
6292 end_coredump:
6293 set_fs(fs);
6294 return has_dumped;
6295diff -urNp linux-2.6.32.41/arch/x86/ia32/ia32entry.S linux-2.6.32.41/arch/x86/ia32/ia32entry.S
6296--- linux-2.6.32.41/arch/x86/ia32/ia32entry.S 2011-03-27 14:31:47.000000000 -0400
6297+++ linux-2.6.32.41/arch/x86/ia32/ia32entry.S 2011-06-04 20:29:52.000000000 -0400
6298@@ -13,6 +13,7 @@
6299 #include <asm/thread_info.h>
6300 #include <asm/segment.h>
6301 #include <asm/irqflags.h>
6302+#include <asm/pgtable.h>
6303 #include <linux/linkage.h>
6304
6305 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
6306@@ -93,6 +94,30 @@ ENTRY(native_irq_enable_sysexit)
6307 ENDPROC(native_irq_enable_sysexit)
6308 #endif
6309
6310+ .macro pax_enter_kernel_user
6311+#ifdef CONFIG_PAX_MEMORY_UDEREF
6312+ call pax_enter_kernel_user
6313+#endif
6314+ .endm
6315+
6316+ .macro pax_exit_kernel_user
6317+#ifdef CONFIG_PAX_MEMORY_UDEREF
6318+ call pax_exit_kernel_user
6319+#endif
6320+#ifdef CONFIG_PAX_RANDKSTACK
6321+ pushq %rax
6322+ call pax_randomize_kstack
6323+ popq %rax
6324+#endif
6325+ pax_erase_kstack
6326+ .endm
6327+
6328+.macro pax_erase_kstack
6329+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
6330+ call pax_erase_kstack
6331+#endif
6332+.endm
6333+
6334 /*
6335 * 32bit SYSENTER instruction entry.
6336 *
6337@@ -119,7 +144,7 @@ ENTRY(ia32_sysenter_target)
6338 CFI_REGISTER rsp,rbp
6339 SWAPGS_UNSAFE_STACK
6340 movq PER_CPU_VAR(kernel_stack), %rsp
6341- addq $(KERNEL_STACK_OFFSET),%rsp
6342+ pax_enter_kernel_user
6343 /*
6344 * No need to follow this irqs on/off section: the syscall
6345 * disabled irqs, here we enable it straight after entry:
6346@@ -135,7 +160,8 @@ ENTRY(ia32_sysenter_target)
6347 pushfq
6348 CFI_ADJUST_CFA_OFFSET 8
6349 /*CFI_REL_OFFSET rflags,0*/
6350- movl 8*3-THREAD_SIZE+TI_sysenter_return(%rsp), %r10d
6351+ GET_THREAD_INFO(%r10)
6352+ movl TI_sysenter_return(%r10), %r10d
6353 CFI_REGISTER rip,r10
6354 pushq $__USER32_CS
6355 CFI_ADJUST_CFA_OFFSET 8
6356@@ -150,6 +176,12 @@ ENTRY(ia32_sysenter_target)
6357 SAVE_ARGS 0,0,1
6358 /* no need to do an access_ok check here because rbp has been
6359 32bit zero extended */
6360+
6361+#ifdef CONFIG_PAX_MEMORY_UDEREF
6362+ mov $PAX_USER_SHADOW_BASE,%r10
6363+ add %r10,%rbp
6364+#endif
6365+
6366 1: movl (%rbp),%ebp
6367 .section __ex_table,"a"
6368 .quad 1b,ia32_badarg
6369@@ -172,6 +204,7 @@ sysenter_dispatch:
6370 testl $_TIF_ALLWORK_MASK,TI_flags(%r10)
6371 jnz sysexit_audit
6372 sysexit_from_sys_call:
6373+ pax_exit_kernel_user
6374 andl $~TS_COMPAT,TI_status(%r10)
6375 /* clear IF, that popfq doesn't enable interrupts early */
6376 andl $~0x200,EFLAGS-R11(%rsp)
6377@@ -200,6 +233,9 @@ sysexit_from_sys_call:
6378 movl %eax,%esi /* 2nd arg: syscall number */
6379 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
6380 call audit_syscall_entry
6381+
6382+ pax_erase_kstack
6383+
6384 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
6385 cmpq $(IA32_NR_syscalls-1),%rax
6386 ja ia32_badsys
6387@@ -252,6 +288,9 @@ sysenter_tracesys:
6388 movq $-ENOSYS,RAX(%rsp)/* ptrace can change this for a bad syscall */
6389 movq %rsp,%rdi /* &pt_regs -> arg1 */
6390 call syscall_trace_enter
6391+
6392+ pax_erase_kstack
6393+
6394 LOAD_ARGS32 ARGOFFSET /* reload args from stack in case ptrace changed it */
6395 RESTORE_REST
6396 cmpq $(IA32_NR_syscalls-1),%rax
6397@@ -283,19 +322,24 @@ ENDPROC(ia32_sysenter_target)
6398 ENTRY(ia32_cstar_target)
6399 CFI_STARTPROC32 simple
6400 CFI_SIGNAL_FRAME
6401- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
6402+ CFI_DEF_CFA rsp,0
6403 CFI_REGISTER rip,rcx
6404 /*CFI_REGISTER rflags,r11*/
6405 SWAPGS_UNSAFE_STACK
6406 movl %esp,%r8d
6407 CFI_REGISTER rsp,r8
6408 movq PER_CPU_VAR(kernel_stack),%rsp
6409+
6410+#ifdef CONFIG_PAX_MEMORY_UDEREF
6411+ pax_enter_kernel_user
6412+#endif
6413+
6414 /*
6415 * No need to follow this irqs on/off section: the syscall
6416 * disabled irqs and here we enable it straight after entry:
6417 */
6418 ENABLE_INTERRUPTS(CLBR_NONE)
6419- SAVE_ARGS 8,1,1
6420+ SAVE_ARGS 8*6,1,1
6421 movl %eax,%eax /* zero extension */
6422 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
6423 movq %rcx,RIP-ARGOFFSET(%rsp)
6424@@ -311,6 +355,12 @@ ENTRY(ia32_cstar_target)
6425 /* no need to do an access_ok check here because r8 has been
6426 32bit zero extended */
6427 /* hardware stack frame is complete now */
6428+
6429+#ifdef CONFIG_PAX_MEMORY_UDEREF
6430+ mov $PAX_USER_SHADOW_BASE,%r10
6431+ add %r10,%r8
6432+#endif
6433+
6434 1: movl (%r8),%r9d
6435 .section __ex_table,"a"
6436 .quad 1b,ia32_badarg
6437@@ -333,6 +383,7 @@ cstar_dispatch:
6438 testl $_TIF_ALLWORK_MASK,TI_flags(%r10)
6439 jnz sysretl_audit
6440 sysretl_from_sys_call:
6441+ pax_exit_kernel_user
6442 andl $~TS_COMPAT,TI_status(%r10)
6443 RESTORE_ARGS 1,-ARG_SKIP,1,1,1
6444 movl RIP-ARGOFFSET(%rsp),%ecx
6445@@ -370,6 +421,9 @@ cstar_tracesys:
6446 movq $-ENOSYS,RAX(%rsp) /* ptrace can change this for a bad syscall */
6447 movq %rsp,%rdi /* &pt_regs -> arg1 */
6448 call syscall_trace_enter
6449+
6450+ pax_erase_kstack
6451+
6452 LOAD_ARGS32 ARGOFFSET, 1 /* reload args from stack in case ptrace changed it */
6453 RESTORE_REST
6454 xchgl %ebp,%r9d
6455@@ -415,6 +469,7 @@ ENTRY(ia32_syscall)
6456 CFI_REL_OFFSET rip,RIP-RIP
6457 PARAVIRT_ADJUST_EXCEPTION_FRAME
6458 SWAPGS
6459+ pax_enter_kernel_user
6460 /*
6461 * No need to follow this irqs on/off section: the syscall
6462 * disabled irqs and here we enable it straight after entry:
6463@@ -448,6 +503,9 @@ ia32_tracesys:
6464 movq $-ENOSYS,RAX(%rsp) /* ptrace can change this for a bad syscall */
6465 movq %rsp,%rdi /* &pt_regs -> arg1 */
6466 call syscall_trace_enter
6467+
6468+ pax_erase_kstack
6469+
6470 LOAD_ARGS32 ARGOFFSET /* reload args from stack in case ptrace changed it */
6471 RESTORE_REST
6472 cmpq $(IA32_NR_syscalls-1),%rax
6473diff -urNp linux-2.6.32.41/arch/x86/ia32/ia32_signal.c linux-2.6.32.41/arch/x86/ia32/ia32_signal.c
6474--- linux-2.6.32.41/arch/x86/ia32/ia32_signal.c 2011-03-27 14:31:47.000000000 -0400
6475+++ linux-2.6.32.41/arch/x86/ia32/ia32_signal.c 2011-04-17 15:56:46.000000000 -0400
6476@@ -403,7 +403,7 @@ static void __user *get_sigframe(struct
6477 sp -= frame_size;
6478 /* Align the stack pointer according to the i386 ABI,
6479 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
6480- sp = ((sp + 4) & -16ul) - 4;
6481+ sp = ((sp - 12) & -16ul) - 4;
6482 return (void __user *) sp;
6483 }
6484
6485@@ -461,7 +461,7 @@ int ia32_setup_frame(int sig, struct k_s
6486 * These are actually not used anymore, but left because some
6487 * gdb versions depend on them as a marker.
6488 */
6489- put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
6490+ put_user_ex(*((const u64 *)&code), (u64 *)frame->retcode);
6491 } put_user_catch(err);
6492
6493 if (err)
6494@@ -503,7 +503,7 @@ int ia32_setup_rt_frame(int sig, struct
6495 0xb8,
6496 __NR_ia32_rt_sigreturn,
6497 0x80cd,
6498- 0,
6499+ 0
6500 };
6501
6502 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
6503@@ -533,16 +533,18 @@ int ia32_setup_rt_frame(int sig, struct
6504
6505 if (ka->sa.sa_flags & SA_RESTORER)
6506 restorer = ka->sa.sa_restorer;
6507+ else if (current->mm->context.vdso)
6508+ /* Return stub is in 32bit vsyscall page */
6509+ restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
6510 else
6511- restorer = VDSO32_SYMBOL(current->mm->context.vdso,
6512- rt_sigreturn);
6513+ restorer = &frame->retcode;
6514 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
6515
6516 /*
6517 * Not actually used anymore, but left because some gdb
6518 * versions need it.
6519 */
6520- put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
6521+ put_user_ex(*((const u64 *)&code), (u64 *)frame->retcode);
6522 } put_user_catch(err);
6523
6524 if (err)
6525diff -urNp linux-2.6.32.41/arch/x86/include/asm/alternative.h linux-2.6.32.41/arch/x86/include/asm/alternative.h
6526--- linux-2.6.32.41/arch/x86/include/asm/alternative.h 2011-03-27 14:31:47.000000000 -0400
6527+++ linux-2.6.32.41/arch/x86/include/asm/alternative.h 2011-04-17 15:56:46.000000000 -0400
6528@@ -85,7 +85,7 @@ static inline void alternatives_smp_swit
6529 " .byte 662b-661b\n" /* sourcelen */ \
6530 " .byte 664f-663f\n" /* replacementlen */ \
6531 ".previous\n" \
6532- ".section .altinstr_replacement, \"ax\"\n" \
6533+ ".section .altinstr_replacement, \"a\"\n" \
6534 "663:\n\t" newinstr "\n664:\n" /* replacement */ \
6535 ".previous"
6536
6537diff -urNp linux-2.6.32.41/arch/x86/include/asm/apm.h linux-2.6.32.41/arch/x86/include/asm/apm.h
6538--- linux-2.6.32.41/arch/x86/include/asm/apm.h 2011-03-27 14:31:47.000000000 -0400
6539+++ linux-2.6.32.41/arch/x86/include/asm/apm.h 2011-04-17 15:56:46.000000000 -0400
6540@@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32
6541 __asm__ __volatile__(APM_DO_ZERO_SEGS
6542 "pushl %%edi\n\t"
6543 "pushl %%ebp\n\t"
6544- "lcall *%%cs:apm_bios_entry\n\t"
6545+ "lcall *%%ss:apm_bios_entry\n\t"
6546 "setc %%al\n\t"
6547 "popl %%ebp\n\t"
6548 "popl %%edi\n\t"
6549@@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_as
6550 __asm__ __volatile__(APM_DO_ZERO_SEGS
6551 "pushl %%edi\n\t"
6552 "pushl %%ebp\n\t"
6553- "lcall *%%cs:apm_bios_entry\n\t"
6554+ "lcall *%%ss:apm_bios_entry\n\t"
6555 "setc %%bl\n\t"
6556 "popl %%ebp\n\t"
6557 "popl %%edi\n\t"
6558diff -urNp linux-2.6.32.41/arch/x86/include/asm/atomic_32.h linux-2.6.32.41/arch/x86/include/asm/atomic_32.h
6559--- linux-2.6.32.41/arch/x86/include/asm/atomic_32.h 2011-03-27 14:31:47.000000000 -0400
6560+++ linux-2.6.32.41/arch/x86/include/asm/atomic_32.h 2011-05-04 17:56:20.000000000 -0400
6561@@ -25,6 +25,17 @@ static inline int atomic_read(const atom
6562 }
6563
6564 /**
6565+ * atomic_read_unchecked - read atomic variable
6566+ * @v: pointer of type atomic_unchecked_t
6567+ *
6568+ * Atomically reads the value of @v.
6569+ */
6570+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
6571+{
6572+ return v->counter;
6573+}
6574+
6575+/**
6576 * atomic_set - set atomic variable
6577 * @v: pointer of type atomic_t
6578 * @i: required value
6579@@ -37,6 +48,18 @@ static inline void atomic_set(atomic_t *
6580 }
6581
6582 /**
6583+ * atomic_set_unchecked - set atomic variable
6584+ * @v: pointer of type atomic_unchecked_t
6585+ * @i: required value
6586+ *
6587+ * Atomically sets the value of @v to @i.
6588+ */
6589+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
6590+{
6591+ v->counter = i;
6592+}
6593+
6594+/**
6595 * atomic_add - add integer to atomic variable
6596 * @i: integer value to add
6597 * @v: pointer of type atomic_t
6598@@ -45,7 +68,29 @@ static inline void atomic_set(atomic_t *
6599 */
6600 static inline void atomic_add(int i, atomic_t *v)
6601 {
6602- asm volatile(LOCK_PREFIX "addl %1,%0"
6603+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
6604+
6605+#ifdef CONFIG_PAX_REFCOUNT
6606+ "jno 0f\n"
6607+ LOCK_PREFIX "subl %1,%0\n"
6608+ "int $4\n0:\n"
6609+ _ASM_EXTABLE(0b, 0b)
6610+#endif
6611+
6612+ : "+m" (v->counter)
6613+ : "ir" (i));
6614+}
6615+
6616+/**
6617+ * atomic_add_unchecked - add integer to atomic variable
6618+ * @i: integer value to add
6619+ * @v: pointer of type atomic_unchecked_t
6620+ *
6621+ * Atomically adds @i to @v.
6622+ */
6623+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
6624+{
6625+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
6626 : "+m" (v->counter)
6627 : "ir" (i));
6628 }
6629@@ -59,7 +104,29 @@ static inline void atomic_add(int i, ato
6630 */
6631 static inline void atomic_sub(int i, atomic_t *v)
6632 {
6633- asm volatile(LOCK_PREFIX "subl %1,%0"
6634+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
6635+
6636+#ifdef CONFIG_PAX_REFCOUNT
6637+ "jno 0f\n"
6638+ LOCK_PREFIX "addl %1,%0\n"
6639+ "int $4\n0:\n"
6640+ _ASM_EXTABLE(0b, 0b)
6641+#endif
6642+
6643+ : "+m" (v->counter)
6644+ : "ir" (i));
6645+}
6646+
6647+/**
6648+ * atomic_sub_unchecked - subtract integer from atomic variable
6649+ * @i: integer value to subtract
6650+ * @v: pointer of type atomic_unchecked_t
6651+ *
6652+ * Atomically subtracts @i from @v.
6653+ */
6654+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
6655+{
6656+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
6657 : "+m" (v->counter)
6658 : "ir" (i));
6659 }
6660@@ -77,7 +144,16 @@ static inline int atomic_sub_and_test(in
6661 {
6662 unsigned char c;
6663
6664- asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
6665+ asm volatile(LOCK_PREFIX "subl %2,%0\n"
6666+
6667+#ifdef CONFIG_PAX_REFCOUNT
6668+ "jno 0f\n"
6669+ LOCK_PREFIX "addl %2,%0\n"
6670+ "int $4\n0:\n"
6671+ _ASM_EXTABLE(0b, 0b)
6672+#endif
6673+
6674+ "sete %1\n"
6675 : "+m" (v->counter), "=qm" (c)
6676 : "ir" (i) : "memory");
6677 return c;
6678@@ -91,7 +167,27 @@ static inline int atomic_sub_and_test(in
6679 */
6680 static inline void atomic_inc(atomic_t *v)
6681 {
6682- asm volatile(LOCK_PREFIX "incl %0"
6683+ asm volatile(LOCK_PREFIX "incl %0\n"
6684+
6685+#ifdef CONFIG_PAX_REFCOUNT
6686+ "jno 0f\n"
6687+ LOCK_PREFIX "decl %0\n"
6688+ "int $4\n0:\n"
6689+ _ASM_EXTABLE(0b, 0b)
6690+#endif
6691+
6692+ : "+m" (v->counter));
6693+}
6694+
6695+/**
6696+ * atomic_inc_unchecked - increment atomic variable
6697+ * @v: pointer of type atomic_unchecked_t
6698+ *
6699+ * Atomically increments @v by 1.
6700+ */
6701+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
6702+{
6703+ asm volatile(LOCK_PREFIX "incl %0\n"
6704 : "+m" (v->counter));
6705 }
6706
6707@@ -103,7 +199,27 @@ static inline void atomic_inc(atomic_t *
6708 */
6709 static inline void atomic_dec(atomic_t *v)
6710 {
6711- asm volatile(LOCK_PREFIX "decl %0"
6712+ asm volatile(LOCK_PREFIX "decl %0\n"
6713+
6714+#ifdef CONFIG_PAX_REFCOUNT
6715+ "jno 0f\n"
6716+ LOCK_PREFIX "incl %0\n"
6717+ "int $4\n0:\n"
6718+ _ASM_EXTABLE(0b, 0b)
6719+#endif
6720+
6721+ : "+m" (v->counter));
6722+}
6723+
6724+/**
6725+ * atomic_dec_unchecked - decrement atomic variable
6726+ * @v: pointer of type atomic_unchecked_t
6727+ *
6728+ * Atomically decrements @v by 1.
6729+ */
6730+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
6731+{
6732+ asm volatile(LOCK_PREFIX "decl %0\n"
6733 : "+m" (v->counter));
6734 }
6735
6736@@ -119,7 +235,16 @@ static inline int atomic_dec_and_test(at
6737 {
6738 unsigned char c;
6739
6740- asm volatile(LOCK_PREFIX "decl %0; sete %1"
6741+ asm volatile(LOCK_PREFIX "decl %0\n"
6742+
6743+#ifdef CONFIG_PAX_REFCOUNT
6744+ "jno 0f\n"
6745+ LOCK_PREFIX "incl %0\n"
6746+ "int $4\n0:\n"
6747+ _ASM_EXTABLE(0b, 0b)
6748+#endif
6749+
6750+ "sete %1\n"
6751 : "+m" (v->counter), "=qm" (c)
6752 : : "memory");
6753 return c != 0;
6754@@ -137,7 +262,35 @@ static inline int atomic_inc_and_test(at
6755 {
6756 unsigned char c;
6757
6758- asm volatile(LOCK_PREFIX "incl %0; sete %1"
6759+ asm volatile(LOCK_PREFIX "incl %0\n"
6760+
6761+#ifdef CONFIG_PAX_REFCOUNT
6762+ "jno 0f\n"
6763+ LOCK_PREFIX "decl %0\n"
6764+ "into\n0:\n"
6765+ _ASM_EXTABLE(0b, 0b)
6766+#endif
6767+
6768+ "sete %1\n"
6769+ : "+m" (v->counter), "=qm" (c)
6770+ : : "memory");
6771+ return c != 0;
6772+}
6773+
6774+/**
6775+ * atomic_inc_and_test_unchecked - increment and test
6776+ * @v: pointer of type atomic_unchecked_t
6777+ *
6778+ * Atomically increments @v by 1
6779+ * and returns true if the result is zero, or false for all
6780+ * other cases.
6781+ */
6782+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
6783+{
6784+ unsigned char c;
6785+
6786+ asm volatile(LOCK_PREFIX "incl %0\n"
6787+ "sete %1\n"
6788 : "+m" (v->counter), "=qm" (c)
6789 : : "memory");
6790 return c != 0;
6791@@ -156,7 +309,16 @@ static inline int atomic_add_negative(in
6792 {
6793 unsigned char c;
6794
6795- asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
6796+ asm volatile(LOCK_PREFIX "addl %2,%0\n"
6797+
6798+#ifdef CONFIG_PAX_REFCOUNT
6799+ "jno 0f\n"
6800+ LOCK_PREFIX "subl %2,%0\n"
6801+ "int $4\n0:\n"
6802+ _ASM_EXTABLE(0b, 0b)
6803+#endif
6804+
6805+ "sets %1\n"
6806 : "+m" (v->counter), "=qm" (c)
6807 : "ir" (i) : "memory");
6808 return c;
6809@@ -179,6 +341,46 @@ static inline int atomic_add_return(int
6810 #endif
6811 /* Modern 486+ processor */
6812 __i = i;
6813+ asm volatile(LOCK_PREFIX "xaddl %0, %1\n"
6814+
6815+#ifdef CONFIG_PAX_REFCOUNT
6816+ "jno 0f\n"
6817+ "movl %0, %1\n"
6818+ "int $4\n0:\n"
6819+ _ASM_EXTABLE(0b, 0b)
6820+#endif
6821+
6822+ : "+r" (i), "+m" (v->counter)
6823+ : : "memory");
6824+ return i + __i;
6825+
6826+#ifdef CONFIG_M386
6827+no_xadd: /* Legacy 386 processor */
6828+ local_irq_save(flags);
6829+ __i = atomic_read(v);
6830+ atomic_set(v, i + __i);
6831+ local_irq_restore(flags);
6832+ return i + __i;
6833+#endif
6834+}
6835+
6836+/**
6837+ * atomic_add_return_unchecked - add integer and return
6838+ * @v: pointer of type atomic_unchecked_t
6839+ * @i: integer value to add
6840+ *
6841+ * Atomically adds @i to @v and returns @i + @v
6842+ */
6843+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
6844+{
6845+ int __i;
6846+#ifdef CONFIG_M386
6847+ unsigned long flags;
6848+ if (unlikely(boot_cpu_data.x86 <= 3))
6849+ goto no_xadd;
6850+#endif
6851+ /* Modern 486+ processor */
6852+ __i = i;
6853 asm volatile(LOCK_PREFIX "xaddl %0, %1"
6854 : "+r" (i), "+m" (v->counter)
6855 : : "memory");
6856@@ -211,11 +413,21 @@ static inline int atomic_cmpxchg(atomic_
6857 return cmpxchg(&v->counter, old, new);
6858 }
6859
6860+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
6861+{
6862+ return cmpxchg(&v->counter, old, new);
6863+}
6864+
6865 static inline int atomic_xchg(atomic_t *v, int new)
6866 {
6867 return xchg(&v->counter, new);
6868 }
6869
6870+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
6871+{
6872+ return xchg(&v->counter, new);
6873+}
6874+
6875 /**
6876 * atomic_add_unless - add unless the number is already a given value
6877 * @v: pointer of type atomic_t
6878@@ -227,22 +439,39 @@ static inline int atomic_xchg(atomic_t *
6879 */
6880 static inline int atomic_add_unless(atomic_t *v, int a, int u)
6881 {
6882- int c, old;
6883+ int c, old, new;
6884 c = atomic_read(v);
6885 for (;;) {
6886- if (unlikely(c == (u)))
6887+ if (unlikely(c == u))
6888 break;
6889- old = atomic_cmpxchg((v), c, c + (a));
6890+
6891+ asm volatile("addl %2,%0\n"
6892+
6893+#ifdef CONFIG_PAX_REFCOUNT
6894+ "jno 0f\n"
6895+ "subl %2,%0\n"
6896+ "int $4\n0:\n"
6897+ _ASM_EXTABLE(0b, 0b)
6898+#endif
6899+
6900+ : "=r" (new)
6901+ : "0" (c), "ir" (a));
6902+
6903+ old = atomic_cmpxchg(v, c, new);
6904 if (likely(old == c))
6905 break;
6906 c = old;
6907 }
6908- return c != (u);
6909+ return c != u;
6910 }
6911
6912 #define atomic_inc_not_zero(v) atomic_add_unless((v), 1, 0)
6913
6914 #define atomic_inc_return(v) (atomic_add_return(1, v))
6915+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
6916+{
6917+ return atomic_add_return_unchecked(1, v);
6918+}
6919 #define atomic_dec_return(v) (atomic_sub_return(1, v))
6920
6921 /* These are x86-specific, used by some header files */
6922@@ -266,9 +495,18 @@ typedef struct {
6923 u64 __aligned(8) counter;
6924 } atomic64_t;
6925
6926+#ifdef CONFIG_PAX_REFCOUNT
6927+typedef struct {
6928+ u64 __aligned(8) counter;
6929+} atomic64_unchecked_t;
6930+#else
6931+typedef atomic64_t atomic64_unchecked_t;
6932+#endif
6933+
6934 #define ATOMIC64_INIT(val) { (val) }
6935
6936 extern u64 atomic64_cmpxchg(atomic64_t *ptr, u64 old_val, u64 new_val);
6937+extern u64 atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, u64 old_val, u64 new_val);
6938
6939 /**
6940 * atomic64_xchg - xchg atomic64 variable
6941@@ -279,6 +517,7 @@ extern u64 atomic64_cmpxchg(atomic64_t *
6942 * the old value.
6943 */
6944 extern u64 atomic64_xchg(atomic64_t *ptr, u64 new_val);
6945+extern u64 atomic64_xchg_unchecked(atomic64_unchecked_t *ptr, u64 new_val);
6946
6947 /**
6948 * atomic64_set - set atomic64 variable
6949@@ -290,6 +529,15 @@ extern u64 atomic64_xchg(atomic64_t *ptr
6950 extern void atomic64_set(atomic64_t *ptr, u64 new_val);
6951
6952 /**
6953+ * atomic64_unchecked_set - set atomic64 variable
6954+ * @ptr: pointer to type atomic64_unchecked_t
6955+ * @new_val: value to assign
6956+ *
6957+ * Atomically sets the value of @ptr to @new_val.
6958+ */
6959+extern void atomic64_set_unchecked(atomic64_unchecked_t *ptr, u64 new_val);
6960+
6961+/**
6962 * atomic64_read - read atomic64 variable
6963 * @ptr: pointer to type atomic64_t
6964 *
6965@@ -317,7 +565,33 @@ static inline u64 atomic64_read(atomic64
6966 return res;
6967 }
6968
6969-extern u64 atomic64_read(atomic64_t *ptr);
6970+/**
6971+ * atomic64_read_unchecked - read atomic64 variable
6972+ * @ptr: pointer to type atomic64_unchecked_t
6973+ *
6974+ * Atomically reads the value of @ptr and returns it.
6975+ */
6976+static inline u64 atomic64_read_unchecked(atomic64_unchecked_t *ptr)
6977+{
6978+ u64 res;
6979+
6980+ /*
6981+ * Note, we inline this atomic64_unchecked_t primitive because
6982+ * it only clobbers EAX/EDX and leaves the others
6983+ * untouched. We also (somewhat subtly) rely on the
6984+ * fact that cmpxchg8b returns the current 64-bit value
6985+ * of the memory location we are touching:
6986+ */
6987+ asm volatile(
6988+ "mov %%ebx, %%eax\n\t"
6989+ "mov %%ecx, %%edx\n\t"
6990+ LOCK_PREFIX "cmpxchg8b %1\n"
6991+ : "=&A" (res)
6992+ : "m" (*ptr)
6993+ );
6994+
6995+ return res;
6996+}
6997
6998 /**
6999 * atomic64_add_return - add and return
7000@@ -332,8 +606,11 @@ extern u64 atomic64_add_return(u64 delta
7001 * Other variants with different arithmetic operators:
7002 */
7003 extern u64 atomic64_sub_return(u64 delta, atomic64_t *ptr);
7004+extern u64 atomic64_sub_return_unchecked(u64 delta, atomic64_unchecked_t *ptr);
7005 extern u64 atomic64_inc_return(atomic64_t *ptr);
7006+extern u64 atomic64_inc_return_unchecked(atomic64_unchecked_t *ptr);
7007 extern u64 atomic64_dec_return(atomic64_t *ptr);
7008+extern u64 atomic64_dec_return_unchecked(atomic64_unchecked_t *ptr);
7009
7010 /**
7011 * atomic64_add - add integer to atomic64 variable
7012@@ -345,6 +622,15 @@ extern u64 atomic64_dec_return(atomic64_
7013 extern void atomic64_add(u64 delta, atomic64_t *ptr);
7014
7015 /**
7016+ * atomic64_add_unchecked - add integer to atomic64 variable
7017+ * @delta: integer value to add
7018+ * @ptr: pointer to type atomic64_unchecked_t
7019+ *
7020+ * Atomically adds @delta to @ptr.
7021+ */
7022+extern void atomic64_add_unchecked(u64 delta, atomic64_unchecked_t *ptr);
7023+
7024+/**
7025 * atomic64_sub - subtract the atomic64 variable
7026 * @delta: integer value to subtract
7027 * @ptr: pointer to type atomic64_t
7028@@ -354,6 +640,15 @@ extern void atomic64_add(u64 delta, atom
7029 extern void atomic64_sub(u64 delta, atomic64_t *ptr);
7030
7031 /**
7032+ * atomic64_sub_unchecked - subtract the atomic64 variable
7033+ * @delta: integer value to subtract
7034+ * @ptr: pointer to type atomic64_unchecked_t
7035+ *
7036+ * Atomically subtracts @delta from @ptr.
7037+ */
7038+extern void atomic64_sub_unchecked(u64 delta, atomic64_unchecked_t *ptr);
7039+
7040+/**
7041 * atomic64_sub_and_test - subtract value from variable and test result
7042 * @delta: integer value to subtract
7043 * @ptr: pointer to type atomic64_t
7044@@ -373,6 +668,14 @@ extern int atomic64_sub_and_test(u64 del
7045 extern void atomic64_inc(atomic64_t *ptr);
7046
7047 /**
7048+ * atomic64_inc_unchecked - increment atomic64 variable
7049+ * @ptr: pointer to type atomic64_unchecked_t
7050+ *
7051+ * Atomically increments @ptr by 1.
7052+ */
7053+extern void atomic64_inc_unchecked(atomic64_unchecked_t *ptr);
7054+
7055+/**
7056 * atomic64_dec - decrement atomic64 variable
7057 * @ptr: pointer to type atomic64_t
7058 *
7059@@ -381,6 +684,14 @@ extern void atomic64_inc(atomic64_t *ptr
7060 extern void atomic64_dec(atomic64_t *ptr);
7061
7062 /**
7063+ * atomic64_dec_unchecked - decrement atomic64 variable
7064+ * @ptr: pointer to type atomic64_unchecked_t
7065+ *
7066+ * Atomically decrements @ptr by 1.
7067+ */
7068+extern void atomic64_dec_unchecked(atomic64_unchecked_t *ptr);
7069+
7070+/**
7071 * atomic64_dec_and_test - decrement and test
7072 * @ptr: pointer to type atomic64_t
7073 *
7074diff -urNp linux-2.6.32.41/arch/x86/include/asm/atomic_64.h linux-2.6.32.41/arch/x86/include/asm/atomic_64.h
7075--- linux-2.6.32.41/arch/x86/include/asm/atomic_64.h 2011-03-27 14:31:47.000000000 -0400
7076+++ linux-2.6.32.41/arch/x86/include/asm/atomic_64.h 2011-05-04 18:35:31.000000000 -0400
7077@@ -24,6 +24,17 @@ static inline int atomic_read(const atom
7078 }
7079
7080 /**
7081+ * atomic_read_unchecked - read atomic variable
7082+ * @v: pointer of type atomic_unchecked_t
7083+ *
7084+ * Atomically reads the value of @v.
7085+ */
7086+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
7087+{
7088+ return v->counter;
7089+}
7090+
7091+/**
7092 * atomic_set - set atomic variable
7093 * @v: pointer of type atomic_t
7094 * @i: required value
7095@@ -36,6 +47,18 @@ static inline void atomic_set(atomic_t *
7096 }
7097
7098 /**
7099+ * atomic_set_unchecked - set atomic variable
7100+ * @v: pointer of type atomic_unchecked_t
7101+ * @i: required value
7102+ *
7103+ * Atomically sets the value of @v to @i.
7104+ */
7105+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
7106+{
7107+ v->counter = i;
7108+}
7109+
7110+/**
7111 * atomic_add - add integer to atomic variable
7112 * @i: integer value to add
7113 * @v: pointer of type atomic_t
7114@@ -44,7 +67,29 @@ static inline void atomic_set(atomic_t *
7115 */
7116 static inline void atomic_add(int i, atomic_t *v)
7117 {
7118- asm volatile(LOCK_PREFIX "addl %1,%0"
7119+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
7120+
7121+#ifdef CONFIG_PAX_REFCOUNT
7122+ "jno 0f\n"
7123+ LOCK_PREFIX "subl %1,%0\n"
7124+ "int $4\n0:\n"
7125+ _ASM_EXTABLE(0b, 0b)
7126+#endif
7127+
7128+ : "=m" (v->counter)
7129+ : "ir" (i), "m" (v->counter));
7130+}
7131+
7132+/**
7133+ * atomic_add_unchecked - add integer to atomic variable
7134+ * @i: integer value to add
7135+ * @v: pointer of type atomic_unchecked_t
7136+ *
7137+ * Atomically adds @i to @v.
7138+ */
7139+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
7140+{
7141+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
7142 : "=m" (v->counter)
7143 : "ir" (i), "m" (v->counter));
7144 }
7145@@ -58,7 +103,29 @@ static inline void atomic_add(int i, ato
7146 */
7147 static inline void atomic_sub(int i, atomic_t *v)
7148 {
7149- asm volatile(LOCK_PREFIX "subl %1,%0"
7150+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
7151+
7152+#ifdef CONFIG_PAX_REFCOUNT
7153+ "jno 0f\n"
7154+ LOCK_PREFIX "addl %1,%0\n"
7155+ "int $4\n0:\n"
7156+ _ASM_EXTABLE(0b, 0b)
7157+#endif
7158+
7159+ : "=m" (v->counter)
7160+ : "ir" (i), "m" (v->counter));
7161+}
7162+
7163+/**
7164+ * atomic_sub_unchecked - subtract the atomic variable
7165+ * @i: integer value to subtract
7166+ * @v: pointer of type atomic_unchecked_t
7167+ *
7168+ * Atomically subtracts @i from @v.
7169+ */
7170+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
7171+{
7172+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
7173 : "=m" (v->counter)
7174 : "ir" (i), "m" (v->counter));
7175 }
7176@@ -76,7 +143,16 @@ static inline int atomic_sub_and_test(in
7177 {
7178 unsigned char c;
7179
7180- asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
7181+ asm volatile(LOCK_PREFIX "subl %2,%0\n"
7182+
7183+#ifdef CONFIG_PAX_REFCOUNT
7184+ "jno 0f\n"
7185+ LOCK_PREFIX "addl %2,%0\n"
7186+ "int $4\n0:\n"
7187+ _ASM_EXTABLE(0b, 0b)
7188+#endif
7189+
7190+ "sete %1\n"
7191 : "=m" (v->counter), "=qm" (c)
7192 : "ir" (i), "m" (v->counter) : "memory");
7193 return c;
7194@@ -90,7 +166,28 @@ static inline int atomic_sub_and_test(in
7195 */
7196 static inline void atomic_inc(atomic_t *v)
7197 {
7198- asm volatile(LOCK_PREFIX "incl %0"
7199+ asm volatile(LOCK_PREFIX "incl %0\n"
7200+
7201+#ifdef CONFIG_PAX_REFCOUNT
7202+ "jno 0f\n"
7203+ LOCK_PREFIX "decl %0\n"
7204+ "int $4\n0:\n"
7205+ _ASM_EXTABLE(0b, 0b)
7206+#endif
7207+
7208+ : "=m" (v->counter)
7209+ : "m" (v->counter));
7210+}
7211+
7212+/**
7213+ * atomic_inc_unchecked - increment atomic variable
7214+ * @v: pointer of type atomic_unchecked_t
7215+ *
7216+ * Atomically increments @v by 1.
7217+ */
7218+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
7219+{
7220+ asm volatile(LOCK_PREFIX "incl %0\n"
7221 : "=m" (v->counter)
7222 : "m" (v->counter));
7223 }
7224@@ -103,7 +200,28 @@ static inline void atomic_inc(atomic_t *
7225 */
7226 static inline void atomic_dec(atomic_t *v)
7227 {
7228- asm volatile(LOCK_PREFIX "decl %0"
7229+ asm volatile(LOCK_PREFIX "decl %0\n"
7230+
7231+#ifdef CONFIG_PAX_REFCOUNT
7232+ "jno 0f\n"
7233+ LOCK_PREFIX "incl %0\n"
7234+ "int $4\n0:\n"
7235+ _ASM_EXTABLE(0b, 0b)
7236+#endif
7237+
7238+ : "=m" (v->counter)
7239+ : "m" (v->counter));
7240+}
7241+
7242+/**
7243+ * atomic_dec_unchecked - decrement atomic variable
7244+ * @v: pointer of type atomic_unchecked_t
7245+ *
7246+ * Atomically decrements @v by 1.
7247+ */
7248+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
7249+{
7250+ asm volatile(LOCK_PREFIX "decl %0\n"
7251 : "=m" (v->counter)
7252 : "m" (v->counter));
7253 }
7254@@ -120,7 +238,16 @@ static inline int atomic_dec_and_test(at
7255 {
7256 unsigned char c;
7257
7258- asm volatile(LOCK_PREFIX "decl %0; sete %1"
7259+ asm volatile(LOCK_PREFIX "decl %0\n"
7260+
7261+#ifdef CONFIG_PAX_REFCOUNT
7262+ "jno 0f\n"
7263+ LOCK_PREFIX "incl %0\n"
7264+ "int $4\n0:\n"
7265+ _ASM_EXTABLE(0b, 0b)
7266+#endif
7267+
7268+ "sete %1\n"
7269 : "=m" (v->counter), "=qm" (c)
7270 : "m" (v->counter) : "memory");
7271 return c != 0;
7272@@ -138,7 +265,35 @@ static inline int atomic_inc_and_test(at
7273 {
7274 unsigned char c;
7275
7276- asm volatile(LOCK_PREFIX "incl %0; sete %1"
7277+ asm volatile(LOCK_PREFIX "incl %0\n"
7278+
7279+#ifdef CONFIG_PAX_REFCOUNT
7280+ "jno 0f\n"
7281+ LOCK_PREFIX "decl %0\n"
7282+ "int $4\n0:\n"
7283+ _ASM_EXTABLE(0b, 0b)
7284+#endif
7285+
7286+ "sete %1\n"
7287+ : "=m" (v->counter), "=qm" (c)
7288+ : "m" (v->counter) : "memory");
7289+ return c != 0;
7290+}
7291+
7292+/**
7293+ * atomic_inc_and_test_unchecked - increment and test
7294+ * @v: pointer of type atomic_unchecked_t
7295+ *
7296+ * Atomically increments @v by 1
7297+ * and returns true if the result is zero, or false for all
7298+ * other cases.
7299+ */
7300+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
7301+{
7302+ unsigned char c;
7303+
7304+ asm volatile(LOCK_PREFIX "incl %0\n"
7305+ "sete %1\n"
7306 : "=m" (v->counter), "=qm" (c)
7307 : "m" (v->counter) : "memory");
7308 return c != 0;
7309@@ -157,7 +312,16 @@ static inline int atomic_add_negative(in
7310 {
7311 unsigned char c;
7312
7313- asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
7314+ asm volatile(LOCK_PREFIX "addl %2,%0\n"
7315+
7316+#ifdef CONFIG_PAX_REFCOUNT
7317+ "jno 0f\n"
7318+ LOCK_PREFIX "subl %2,%0\n"
7319+ "int $4\n0:\n"
7320+ _ASM_EXTABLE(0b, 0b)
7321+#endif
7322+
7323+ "sets %1\n"
7324 : "=m" (v->counter), "=qm" (c)
7325 : "ir" (i), "m" (v->counter) : "memory");
7326 return c;
7327@@ -173,7 +337,31 @@ static inline int atomic_add_negative(in
7328 static inline int atomic_add_return(int i, atomic_t *v)
7329 {
7330 int __i = i;
7331- asm volatile(LOCK_PREFIX "xaddl %0, %1"
7332+ asm volatile(LOCK_PREFIX "xaddl %0, %1\n"
7333+
7334+#ifdef CONFIG_PAX_REFCOUNT
7335+ "jno 0f\n"
7336+ "movl %0, %1\n"
7337+ "int $4\n0:\n"
7338+ _ASM_EXTABLE(0b, 0b)
7339+#endif
7340+
7341+ : "+r" (i), "+m" (v->counter)
7342+ : : "memory");
7343+ return i + __i;
7344+}
7345+
7346+/**
7347+ * atomic_add_return_unchecked - add and return
7348+ * @i: integer value to add
7349+ * @v: pointer of type atomic_unchecked_t
7350+ *
7351+ * Atomically adds @i to @v and returns @i + @v
7352+ */
7353+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
7354+{
7355+ int __i = i;
7356+ asm volatile(LOCK_PREFIX "xaddl %0, %1\n"
7357 : "+r" (i), "+m" (v->counter)
7358 : : "memory");
7359 return i + __i;
7360@@ -185,6 +373,10 @@ static inline int atomic_sub_return(int
7361 }
7362
7363 #define atomic_inc_return(v) (atomic_add_return(1, v))
7364+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
7365+{
7366+ return atomic_add_return_unchecked(1, v);
7367+}
7368 #define atomic_dec_return(v) (atomic_sub_return(1, v))
7369
7370 /* The 64-bit atomic type */
7371@@ -204,6 +396,18 @@ static inline long atomic64_read(const a
7372 }
7373
7374 /**
7375+ * atomic64_read_unchecked - read atomic64 variable
7376+ * @v: pointer of type atomic64_unchecked_t
7377+ *
7378+ * Atomically reads the value of @v.
7379+ * Doesn't imply a read memory barrier.
7380+ */
7381+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
7382+{
7383+ return v->counter;
7384+}
7385+
7386+/**
7387 * atomic64_set - set atomic64 variable
7388 * @v: pointer to type atomic64_t
7389 * @i: required value
7390@@ -216,6 +420,18 @@ static inline void atomic64_set(atomic64
7391 }
7392
7393 /**
7394+ * atomic64_set_unchecked - set atomic64 variable
7395+ * @v: pointer to type atomic64_unchecked_t
7396+ * @i: required value
7397+ *
7398+ * Atomically sets the value of @v to @i.
7399+ */
7400+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
7401+{
7402+ v->counter = i;
7403+}
7404+
7405+/**
7406 * atomic64_add - add integer to atomic64 variable
7407 * @i: integer value to add
7408 * @v: pointer to type atomic64_t
7409@@ -224,6 +440,28 @@ static inline void atomic64_set(atomic64
7410 */
7411 static inline void atomic64_add(long i, atomic64_t *v)
7412 {
7413+ asm volatile(LOCK_PREFIX "addq %1,%0\n"
7414+
7415+#ifdef CONFIG_PAX_REFCOUNT
7416+ "jno 0f\n"
7417+ LOCK_PREFIX "subq %1,%0\n"
7418+ "int $4\n0:\n"
7419+ _ASM_EXTABLE(0b, 0b)
7420+#endif
7421+
7422+ : "=m" (v->counter)
7423+ : "er" (i), "m" (v->counter));
7424+}
7425+
7426+/**
7427+ * atomic64_add_unchecked - add integer to atomic64 variable
7428+ * @i: integer value to add
7429+ * @v: pointer to type atomic64_unchecked_t
7430+ *
7431+ * Atomically adds @i to @v.
7432+ */
7433+static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
7434+{
7435 asm volatile(LOCK_PREFIX "addq %1,%0"
7436 : "=m" (v->counter)
7437 : "er" (i), "m" (v->counter));
7438@@ -238,7 +476,15 @@ static inline void atomic64_add(long i,
7439 */
7440 static inline void atomic64_sub(long i, atomic64_t *v)
7441 {
7442- asm volatile(LOCK_PREFIX "subq %1,%0"
7443+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
7444+
7445+#ifdef CONFIG_PAX_REFCOUNT
7446+ "jno 0f\n"
7447+ LOCK_PREFIX "addq %1,%0\n"
7448+ "int $4\n0:\n"
7449+ _ASM_EXTABLE(0b, 0b)
7450+#endif
7451+
7452 : "=m" (v->counter)
7453 : "er" (i), "m" (v->counter));
7454 }
7455@@ -256,7 +502,16 @@ static inline int atomic64_sub_and_test(
7456 {
7457 unsigned char c;
7458
7459- asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
7460+ asm volatile(LOCK_PREFIX "subq %2,%0\n"
7461+
7462+#ifdef CONFIG_PAX_REFCOUNT
7463+ "jno 0f\n"
7464+ LOCK_PREFIX "addq %2,%0\n"
7465+ "int $4\n0:\n"
7466+ _ASM_EXTABLE(0b, 0b)
7467+#endif
7468+
7469+ "sete %1\n"
7470 : "=m" (v->counter), "=qm" (c)
7471 : "er" (i), "m" (v->counter) : "memory");
7472 return c;
7473@@ -270,6 +525,27 @@ static inline int atomic64_sub_and_test(
7474 */
7475 static inline void atomic64_inc(atomic64_t *v)
7476 {
7477+ asm volatile(LOCK_PREFIX "incq %0\n"
7478+
7479+#ifdef CONFIG_PAX_REFCOUNT
7480+ "jno 0f\n"
7481+ LOCK_PREFIX "decq %0\n"
7482+ "int $4\n0:\n"
7483+ _ASM_EXTABLE(0b, 0b)
7484+#endif
7485+
7486+ : "=m" (v->counter)
7487+ : "m" (v->counter));
7488+}
7489+
7490+/**
7491+ * atomic64_inc_unchecked - increment atomic64 variable
7492+ * @v: pointer to type atomic64_unchecked_t
7493+ *
7494+ * Atomically increments @v by 1.
7495+ */
7496+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
7497+{
7498 asm volatile(LOCK_PREFIX "incq %0"
7499 : "=m" (v->counter)
7500 : "m" (v->counter));
7501@@ -283,7 +559,28 @@ static inline void atomic64_inc(atomic64
7502 */
7503 static inline void atomic64_dec(atomic64_t *v)
7504 {
7505- asm volatile(LOCK_PREFIX "decq %0"
7506+ asm volatile(LOCK_PREFIX "decq %0\n"
7507+
7508+#ifdef CONFIG_PAX_REFCOUNT
7509+ "jno 0f\n"
7510+ LOCK_PREFIX "incq %0\n"
7511+ "int $4\n0:\n"
7512+ _ASM_EXTABLE(0b, 0b)
7513+#endif
7514+
7515+ : "=m" (v->counter)
7516+ : "m" (v->counter));
7517+}
7518+
7519+/**
7520+ * atomic64_dec_unchecked - decrement atomic64 variable
7521+ * @v: pointer to type atomic64_t
7522+ *
7523+ * Atomically decrements @v by 1.
7524+ */
7525+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
7526+{
7527+ asm volatile(LOCK_PREFIX "decq %0\n"
7528 : "=m" (v->counter)
7529 : "m" (v->counter));
7530 }
7531@@ -300,7 +597,16 @@ static inline int atomic64_dec_and_test(
7532 {
7533 unsigned char c;
7534
7535- asm volatile(LOCK_PREFIX "decq %0; sete %1"
7536+ asm volatile(LOCK_PREFIX "decq %0\n"
7537+
7538+#ifdef CONFIG_PAX_REFCOUNT
7539+ "jno 0f\n"
7540+ LOCK_PREFIX "incq %0\n"
7541+ "int $4\n0:\n"
7542+ _ASM_EXTABLE(0b, 0b)
7543+#endif
7544+
7545+ "sete %1\n"
7546 : "=m" (v->counter), "=qm" (c)
7547 : "m" (v->counter) : "memory");
7548 return c != 0;
7549@@ -318,7 +624,16 @@ static inline int atomic64_inc_and_test(
7550 {
7551 unsigned char c;
7552
7553- asm volatile(LOCK_PREFIX "incq %0; sete %1"
7554+ asm volatile(LOCK_PREFIX "incq %0\n"
7555+
7556+#ifdef CONFIG_PAX_REFCOUNT
7557+ "jno 0f\n"
7558+ LOCK_PREFIX "decq %0\n"
7559+ "int $4\n0:\n"
7560+ _ASM_EXTABLE(0b, 0b)
7561+#endif
7562+
7563+ "sete %1\n"
7564 : "=m" (v->counter), "=qm" (c)
7565 : "m" (v->counter) : "memory");
7566 return c != 0;
7567@@ -337,7 +652,16 @@ static inline int atomic64_add_negative(
7568 {
7569 unsigned char c;
7570
7571- asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
7572+ asm volatile(LOCK_PREFIX "addq %2,%0\n"
7573+
7574+#ifdef CONFIG_PAX_REFCOUNT
7575+ "jno 0f\n"
7576+ LOCK_PREFIX "subq %2,%0\n"
7577+ "int $4\n0:\n"
7578+ _ASM_EXTABLE(0b, 0b)
7579+#endif
7580+
7581+ "sets %1\n"
7582 : "=m" (v->counter), "=qm" (c)
7583 : "er" (i), "m" (v->counter) : "memory");
7584 return c;
7585@@ -353,7 +677,31 @@ static inline int atomic64_add_negative(
7586 static inline long atomic64_add_return(long i, atomic64_t *v)
7587 {
7588 long __i = i;
7589- asm volatile(LOCK_PREFIX "xaddq %0, %1;"
7590+ asm volatile(LOCK_PREFIX "xaddq %0, %1\n"
7591+
7592+#ifdef CONFIG_PAX_REFCOUNT
7593+ "jno 0f\n"
7594+ "movq %0, %1\n"
7595+ "int $4\n0:\n"
7596+ _ASM_EXTABLE(0b, 0b)
7597+#endif
7598+
7599+ : "+r" (i), "+m" (v->counter)
7600+ : : "memory");
7601+ return i + __i;
7602+}
7603+
7604+/**
7605+ * atomic64_add_return_unchecked - add and return
7606+ * @i: integer value to add
7607+ * @v: pointer to type atomic64_unchecked_t
7608+ *
7609+ * Atomically adds @i to @v and returns @i + @v
7610+ */
7611+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
7612+{
7613+ long __i = i;
7614+ asm volatile(LOCK_PREFIX "xaddq %0, %1"
7615 : "+r" (i), "+m" (v->counter)
7616 : : "memory");
7617 return i + __i;
7618@@ -365,6 +713,10 @@ static inline long atomic64_sub_return(l
7619 }
7620
7621 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
7622+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
7623+{
7624+ return atomic64_add_return_unchecked(1, v);
7625+}
7626 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
7627
7628 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
7629@@ -372,21 +724,41 @@ static inline long atomic64_cmpxchg(atom
7630 return cmpxchg(&v->counter, old, new);
7631 }
7632
7633+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
7634+{
7635+ return cmpxchg(&v->counter, old, new);
7636+}
7637+
7638 static inline long atomic64_xchg(atomic64_t *v, long new)
7639 {
7640 return xchg(&v->counter, new);
7641 }
7642
7643+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
7644+{
7645+ return xchg(&v->counter, new);
7646+}
7647+
7648 static inline long atomic_cmpxchg(atomic_t *v, int old, int new)
7649 {
7650 return cmpxchg(&v->counter, old, new);
7651 }
7652
7653+static inline long atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
7654+{
7655+ return cmpxchg(&v->counter, old, new);
7656+}
7657+
7658 static inline long atomic_xchg(atomic_t *v, int new)
7659 {
7660 return xchg(&v->counter, new);
7661 }
7662
7663+static inline long atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
7664+{
7665+ return xchg(&v->counter, new);
7666+}
7667+
7668 /**
7669 * atomic_add_unless - add unless the number is a given value
7670 * @v: pointer of type atomic_t
7671@@ -398,17 +770,30 @@ static inline long atomic_xchg(atomic_t
7672 */
7673 static inline int atomic_add_unless(atomic_t *v, int a, int u)
7674 {
7675- int c, old;
7676+ int c, old, new;
7677 c = atomic_read(v);
7678 for (;;) {
7679- if (unlikely(c == (u)))
7680+ if (unlikely(c == u))
7681 break;
7682- old = atomic_cmpxchg((v), c, c + (a));
7683+
7684+ asm volatile("addl %2,%0\n"
7685+
7686+#ifdef CONFIG_PAX_REFCOUNT
7687+ "jno 0f\n"
7688+ "subl %2,%0\n"
7689+ "int $4\n0:\n"
7690+ _ASM_EXTABLE(0b, 0b)
7691+#endif
7692+
7693+ : "=r" (new)
7694+ : "0" (c), "ir" (a));
7695+
7696+ old = atomic_cmpxchg(v, c, new);
7697 if (likely(old == c))
7698 break;
7699 c = old;
7700 }
7701- return c != (u);
7702+ return c != u;
7703 }
7704
7705 #define atomic_inc_not_zero(v) atomic_add_unless((v), 1, 0)
7706@@ -424,17 +809,30 @@ static inline int atomic_add_unless(atom
7707 */
7708 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
7709 {
7710- long c, old;
7711+ long c, old, new;
7712 c = atomic64_read(v);
7713 for (;;) {
7714- if (unlikely(c == (u)))
7715+ if (unlikely(c == u))
7716 break;
7717- old = atomic64_cmpxchg((v), c, c + (a));
7718+
7719+ asm volatile("addq %2,%0\n"
7720+
7721+#ifdef CONFIG_PAX_REFCOUNT
7722+ "jno 0f\n"
7723+ "subq %2,%0\n"
7724+ "int $4\n0:\n"
7725+ _ASM_EXTABLE(0b, 0b)
7726+#endif
7727+
7728+ : "=r" (new)
7729+ : "0" (c), "er" (a));
7730+
7731+ old = atomic64_cmpxchg(v, c, new);
7732 if (likely(old == c))
7733 break;
7734 c = old;
7735 }
7736- return c != (u);
7737+ return c != u;
7738 }
7739
7740 /**
7741diff -urNp linux-2.6.32.41/arch/x86/include/asm/bitops.h linux-2.6.32.41/arch/x86/include/asm/bitops.h
7742--- linux-2.6.32.41/arch/x86/include/asm/bitops.h 2011-03-27 14:31:47.000000000 -0400
7743+++ linux-2.6.32.41/arch/x86/include/asm/bitops.h 2011-04-17 15:56:46.000000000 -0400
7744@@ -38,7 +38,7 @@
7745 * a mask operation on a byte.
7746 */
7747 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
7748-#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
7749+#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
7750 #define CONST_MASK(nr) (1 << ((nr) & 7))
7751
7752 /**
7753diff -urNp linux-2.6.32.41/arch/x86/include/asm/boot.h linux-2.6.32.41/arch/x86/include/asm/boot.h
7754--- linux-2.6.32.41/arch/x86/include/asm/boot.h 2011-03-27 14:31:47.000000000 -0400
7755+++ linux-2.6.32.41/arch/x86/include/asm/boot.h 2011-04-17 15:56:46.000000000 -0400
7756@@ -11,10 +11,15 @@
7757 #include <asm/pgtable_types.h>
7758
7759 /* Physical address where kernel should be loaded. */
7760-#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
7761+#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
7762 + (CONFIG_PHYSICAL_ALIGN - 1)) \
7763 & ~(CONFIG_PHYSICAL_ALIGN - 1))
7764
7765+#ifndef __ASSEMBLY__
7766+extern unsigned char __LOAD_PHYSICAL_ADDR[];
7767+#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
7768+#endif
7769+
7770 /* Minimum kernel alignment, as a power of two */
7771 #ifdef CONFIG_X86_64
7772 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
7773diff -urNp linux-2.6.32.41/arch/x86/include/asm/cacheflush.h linux-2.6.32.41/arch/x86/include/asm/cacheflush.h
7774--- linux-2.6.32.41/arch/x86/include/asm/cacheflush.h 2011-03-27 14:31:47.000000000 -0400
7775+++ linux-2.6.32.41/arch/x86/include/asm/cacheflush.h 2011-04-17 15:56:46.000000000 -0400
7776@@ -60,7 +60,7 @@ PAGEFLAG(WC, WC)
7777 static inline unsigned long get_page_memtype(struct page *pg)
7778 {
7779 if (!PageUncached(pg) && !PageWC(pg))
7780- return -1;
7781+ return ~0UL;
7782 else if (!PageUncached(pg) && PageWC(pg))
7783 return _PAGE_CACHE_WC;
7784 else if (PageUncached(pg) && !PageWC(pg))
7785@@ -85,7 +85,7 @@ static inline void set_page_memtype(stru
7786 SetPageWC(pg);
7787 break;
7788 default:
7789- case -1:
7790+ case ~0UL:
7791 ClearPageUncached(pg);
7792 ClearPageWC(pg);
7793 break;
7794diff -urNp linux-2.6.32.41/arch/x86/include/asm/cache.h linux-2.6.32.41/arch/x86/include/asm/cache.h
7795--- linux-2.6.32.41/arch/x86/include/asm/cache.h 2011-03-27 14:31:47.000000000 -0400
7796+++ linux-2.6.32.41/arch/x86/include/asm/cache.h 2011-05-04 17:56:20.000000000 -0400
7797@@ -5,9 +5,10 @@
7798
7799 /* L1 cache line size */
7800 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
7801-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7802+#define L1_CACHE_BYTES (_AC(1,U) << L1_CACHE_SHIFT)
7803
7804 #define __read_mostly __attribute__((__section__(".data.read_mostly")))
7805+#define __read_only __attribute__((__section__(".data.read_only")))
7806
7807 #ifdef CONFIG_X86_VSMP
7808 /* vSMP Internode cacheline shift */
7809diff -urNp linux-2.6.32.41/arch/x86/include/asm/checksum_32.h linux-2.6.32.41/arch/x86/include/asm/checksum_32.h
7810--- linux-2.6.32.41/arch/x86/include/asm/checksum_32.h 2011-03-27 14:31:47.000000000 -0400
7811+++ linux-2.6.32.41/arch/x86/include/asm/checksum_32.h 2011-04-17 15:56:46.000000000 -0400
7812@@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_gene
7813 int len, __wsum sum,
7814 int *src_err_ptr, int *dst_err_ptr);
7815
7816+asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
7817+ int len, __wsum sum,
7818+ int *src_err_ptr, int *dst_err_ptr);
7819+
7820+asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
7821+ int len, __wsum sum,
7822+ int *src_err_ptr, int *dst_err_ptr);
7823+
7824 /*
7825 * Note: when you get a NULL pointer exception here this means someone
7826 * passed in an incorrect kernel address to one of these functions.
7827@@ -50,7 +58,7 @@ static inline __wsum csum_partial_copy_f
7828 int *err_ptr)
7829 {
7830 might_sleep();
7831- return csum_partial_copy_generic((__force void *)src, dst,
7832+ return csum_partial_copy_generic_from_user((__force void *)src, dst,
7833 len, sum, err_ptr, NULL);
7834 }
7835
7836@@ -178,7 +186,7 @@ static inline __wsum csum_and_copy_to_us
7837 {
7838 might_sleep();
7839 if (access_ok(VERIFY_WRITE, dst, len))
7840- return csum_partial_copy_generic(src, (__force void *)dst,
7841+ return csum_partial_copy_generic_to_user(src, (__force void *)dst,
7842 len, sum, NULL, err_ptr);
7843
7844 if (len)
7845diff -urNp linux-2.6.32.41/arch/x86/include/asm/desc_defs.h linux-2.6.32.41/arch/x86/include/asm/desc_defs.h
7846--- linux-2.6.32.41/arch/x86/include/asm/desc_defs.h 2011-03-27 14:31:47.000000000 -0400
7847+++ linux-2.6.32.41/arch/x86/include/asm/desc_defs.h 2011-04-17 15:56:46.000000000 -0400
7848@@ -31,6 +31,12 @@ struct desc_struct {
7849 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
7850 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
7851 };
7852+ struct {
7853+ u16 offset_low;
7854+ u16 seg;
7855+ unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
7856+ unsigned offset_high: 16;
7857+ } gate;
7858 };
7859 } __attribute__((packed));
7860
7861diff -urNp linux-2.6.32.41/arch/x86/include/asm/desc.h linux-2.6.32.41/arch/x86/include/asm/desc.h
7862--- linux-2.6.32.41/arch/x86/include/asm/desc.h 2011-03-27 14:31:47.000000000 -0400
7863+++ linux-2.6.32.41/arch/x86/include/asm/desc.h 2011-04-23 12:56:10.000000000 -0400
7864@@ -4,6 +4,7 @@
7865 #include <asm/desc_defs.h>
7866 #include <asm/ldt.h>
7867 #include <asm/mmu.h>
7868+#include <asm/pgtable.h>
7869 #include <linux/smp.h>
7870
7871 static inline void fill_ldt(struct desc_struct *desc,
7872@@ -15,6 +16,7 @@ static inline void fill_ldt(struct desc_
7873 desc->base1 = (info->base_addr & 0x00ff0000) >> 16;
7874 desc->type = (info->read_exec_only ^ 1) << 1;
7875 desc->type |= info->contents << 2;
7876+ desc->type |= info->seg_not_present ^ 1;
7877 desc->s = 1;
7878 desc->dpl = 0x3;
7879 desc->p = info->seg_not_present ^ 1;
7880@@ -31,16 +33,12 @@ static inline void fill_ldt(struct desc_
7881 }
7882
7883 extern struct desc_ptr idt_descr;
7884-extern gate_desc idt_table[];
7885-
7886-struct gdt_page {
7887- struct desc_struct gdt[GDT_ENTRIES];
7888-} __attribute__((aligned(PAGE_SIZE)));
7889-DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
7890+extern gate_desc idt_table[256];
7891
7892+extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
7893 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
7894 {
7895- return per_cpu(gdt_page, cpu).gdt;
7896+ return cpu_gdt_table[cpu];
7897 }
7898
7899 #ifdef CONFIG_X86_64
7900@@ -65,9 +63,14 @@ static inline void pack_gate(gate_desc *
7901 unsigned long base, unsigned dpl, unsigned flags,
7902 unsigned short seg)
7903 {
7904- gate->a = (seg << 16) | (base & 0xffff);
7905- gate->b = (base & 0xffff0000) |
7906- (((0x80 | type | (dpl << 5)) & 0xff) << 8);
7907+ gate->gate.offset_low = base;
7908+ gate->gate.seg = seg;
7909+ gate->gate.reserved = 0;
7910+ gate->gate.type = type;
7911+ gate->gate.s = 0;
7912+ gate->gate.dpl = dpl;
7913+ gate->gate.p = 1;
7914+ gate->gate.offset_high = base >> 16;
7915 }
7916
7917 #endif
7918@@ -115,13 +118,17 @@ static inline void paravirt_free_ldt(str
7919 static inline void native_write_idt_entry(gate_desc *idt, int entry,
7920 const gate_desc *gate)
7921 {
7922+ pax_open_kernel();
7923 memcpy(&idt[entry], gate, sizeof(*gate));
7924+ pax_close_kernel();
7925 }
7926
7927 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry,
7928 const void *desc)
7929 {
7930+ pax_open_kernel();
7931 memcpy(&ldt[entry], desc, 8);
7932+ pax_close_kernel();
7933 }
7934
7935 static inline void native_write_gdt_entry(struct desc_struct *gdt, int entry,
7936@@ -139,7 +146,10 @@ static inline void native_write_gdt_entr
7937 size = sizeof(struct desc_struct);
7938 break;
7939 }
7940+
7941+ pax_open_kernel();
7942 memcpy(&gdt[entry], desc, size);
7943+ pax_close_kernel();
7944 }
7945
7946 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
7947@@ -211,7 +221,9 @@ static inline void native_set_ldt(const
7948
7949 static inline void native_load_tr_desc(void)
7950 {
7951+ pax_open_kernel();
7952 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
7953+ pax_close_kernel();
7954 }
7955
7956 static inline void native_load_gdt(const struct desc_ptr *dtr)
7957@@ -246,8 +258,10 @@ static inline void native_load_tls(struc
7958 unsigned int i;
7959 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
7960
7961+ pax_open_kernel();
7962 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
7963 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
7964+ pax_close_kernel();
7965 }
7966
7967 #define _LDT_empty(info) \
7968@@ -309,7 +323,7 @@ static inline void set_desc_limit(struct
7969 desc->limit = (limit >> 16) & 0xf;
7970 }
7971
7972-static inline void _set_gate(int gate, unsigned type, void *addr,
7973+static inline void _set_gate(int gate, unsigned type, const void *addr,
7974 unsigned dpl, unsigned ist, unsigned seg)
7975 {
7976 gate_desc s;
7977@@ -327,7 +341,7 @@ static inline void _set_gate(int gate, u
7978 * Pentium F0 0F bugfix can have resulted in the mapped
7979 * IDT being write-protected.
7980 */
7981-static inline void set_intr_gate(unsigned int n, void *addr)
7982+static inline void set_intr_gate(unsigned int n, const void *addr)
7983 {
7984 BUG_ON((unsigned)n > 0xFF);
7985 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
7986@@ -356,19 +370,19 @@ static inline void alloc_intr_gate(unsig
7987 /*
7988 * This routine sets up an interrupt gate at directory privilege level 3.
7989 */
7990-static inline void set_system_intr_gate(unsigned int n, void *addr)
7991+static inline void set_system_intr_gate(unsigned int n, const void *addr)
7992 {
7993 BUG_ON((unsigned)n > 0xFF);
7994 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
7995 }
7996
7997-static inline void set_system_trap_gate(unsigned int n, void *addr)
7998+static inline void set_system_trap_gate(unsigned int n, const void *addr)
7999 {
8000 BUG_ON((unsigned)n > 0xFF);
8001 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
8002 }
8003
8004-static inline void set_trap_gate(unsigned int n, void *addr)
8005+static inline void set_trap_gate(unsigned int n, const void *addr)
8006 {
8007 BUG_ON((unsigned)n > 0xFF);
8008 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
8009@@ -377,19 +391,31 @@ static inline void set_trap_gate(unsigne
8010 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
8011 {
8012 BUG_ON((unsigned)n > 0xFF);
8013- _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
8014+ _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
8015 }
8016
8017-static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
8018+static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
8019 {
8020 BUG_ON((unsigned)n > 0xFF);
8021 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
8022 }
8023
8024-static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
8025+static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
8026 {
8027 BUG_ON((unsigned)n > 0xFF);
8028 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
8029 }
8030
8031+#ifdef CONFIG_X86_32
8032+static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
8033+{
8034+ struct desc_struct d;
8035+
8036+ if (likely(limit))
8037+ limit = (limit - 1UL) >> PAGE_SHIFT;
8038+ pack_descriptor(&d, base, limit, 0xFB, 0xC);
8039+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
8040+}
8041+#endif
8042+
8043 #endif /* _ASM_X86_DESC_H */
8044diff -urNp linux-2.6.32.41/arch/x86/include/asm/device.h linux-2.6.32.41/arch/x86/include/asm/device.h
8045--- linux-2.6.32.41/arch/x86/include/asm/device.h 2011-03-27 14:31:47.000000000 -0400
8046+++ linux-2.6.32.41/arch/x86/include/asm/device.h 2011-04-17 15:56:46.000000000 -0400
8047@@ -6,7 +6,7 @@ struct dev_archdata {
8048 void *acpi_handle;
8049 #endif
8050 #ifdef CONFIG_X86_64
8051-struct dma_map_ops *dma_ops;
8052+ const struct dma_map_ops *dma_ops;
8053 #endif
8054 #ifdef CONFIG_DMAR
8055 void *iommu; /* hook for IOMMU specific extension */
8056diff -urNp linux-2.6.32.41/arch/x86/include/asm/dma-mapping.h linux-2.6.32.41/arch/x86/include/asm/dma-mapping.h
8057--- linux-2.6.32.41/arch/x86/include/asm/dma-mapping.h 2011-03-27 14:31:47.000000000 -0400
8058+++ linux-2.6.32.41/arch/x86/include/asm/dma-mapping.h 2011-04-17 15:56:46.000000000 -0400
8059@@ -25,9 +25,9 @@ extern int iommu_merge;
8060 extern struct device x86_dma_fallback_dev;
8061 extern int panic_on_overflow;
8062
8063-extern struct dma_map_ops *dma_ops;
8064+extern const struct dma_map_ops *dma_ops;
8065
8066-static inline struct dma_map_ops *get_dma_ops(struct device *dev)
8067+static inline const struct dma_map_ops *get_dma_ops(struct device *dev)
8068 {
8069 #ifdef CONFIG_X86_32
8070 return dma_ops;
8071@@ -44,7 +44,7 @@ static inline struct dma_map_ops *get_dm
8072 /* Make sure we keep the same behaviour */
8073 static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
8074 {
8075- struct dma_map_ops *ops = get_dma_ops(dev);
8076+ const struct dma_map_ops *ops = get_dma_ops(dev);
8077 if (ops->mapping_error)
8078 return ops->mapping_error(dev, dma_addr);
8079
8080@@ -122,7 +122,7 @@ static inline void *
8081 dma_alloc_coherent(struct device *dev, size_t size, dma_addr_t *dma_handle,
8082 gfp_t gfp)
8083 {
8084- struct dma_map_ops *ops = get_dma_ops(dev);
8085+ const struct dma_map_ops *ops = get_dma_ops(dev);
8086 void *memory;
8087
8088 gfp &= ~(__GFP_DMA | __GFP_HIGHMEM | __GFP_DMA32);
8089@@ -149,7 +149,7 @@ dma_alloc_coherent(struct device *dev, s
8090 static inline void dma_free_coherent(struct device *dev, size_t size,
8091 void *vaddr, dma_addr_t bus)
8092 {
8093- struct dma_map_ops *ops = get_dma_ops(dev);
8094+ const struct dma_map_ops *ops = get_dma_ops(dev);
8095
8096 WARN_ON(irqs_disabled()); /* for portability */
8097
8098diff -urNp linux-2.6.32.41/arch/x86/include/asm/e820.h linux-2.6.32.41/arch/x86/include/asm/e820.h
8099--- linux-2.6.32.41/arch/x86/include/asm/e820.h 2011-03-27 14:31:47.000000000 -0400
8100+++ linux-2.6.32.41/arch/x86/include/asm/e820.h 2011-04-17 15:56:46.000000000 -0400
8101@@ -133,7 +133,7 @@ extern char *default_machine_specific_me
8102 #define ISA_END_ADDRESS 0x100000
8103 #define is_ISA_range(s, e) ((s) >= ISA_START_ADDRESS && (e) < ISA_END_ADDRESS)
8104
8105-#define BIOS_BEGIN 0x000a0000
8106+#define BIOS_BEGIN 0x000c0000
8107 #define BIOS_END 0x00100000
8108
8109 #ifdef __KERNEL__
8110diff -urNp linux-2.6.32.41/arch/x86/include/asm/elf.h linux-2.6.32.41/arch/x86/include/asm/elf.h
8111--- linux-2.6.32.41/arch/x86/include/asm/elf.h 2011-03-27 14:31:47.000000000 -0400
8112+++ linux-2.6.32.41/arch/x86/include/asm/elf.h 2011-04-17 15:56:46.000000000 -0400
8113@@ -257,7 +257,25 @@ extern int force_personality32;
8114 the loader. We need to make sure that it is out of the way of the program
8115 that it will "exec", and that there is sufficient room for the brk. */
8116
8117+#ifdef CONFIG_PAX_SEGMEXEC
8118+#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
8119+#else
8120 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
8121+#endif
8122+
8123+#ifdef CONFIG_PAX_ASLR
8124+#ifdef CONFIG_X86_32
8125+#define PAX_ELF_ET_DYN_BASE 0x10000000UL
8126+
8127+#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
8128+#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
8129+#else
8130+#define PAX_ELF_ET_DYN_BASE 0x400000UL
8131+
8132+#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_IA32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
8133+#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_IA32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
8134+#endif
8135+#endif
8136
8137 /* This yields a mask that user programs can use to figure out what
8138 instruction set this CPU supports. This could be done in user space,
8139@@ -311,8 +329,7 @@ do { \
8140 #define ARCH_DLINFO \
8141 do { \
8142 if (vdso_enabled) \
8143- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
8144- (unsigned long)current->mm->context.vdso); \
8145+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso);\
8146 } while (0)
8147
8148 #define AT_SYSINFO 32
8149@@ -323,7 +340,7 @@ do { \
8150
8151 #endif /* !CONFIG_X86_32 */
8152
8153-#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
8154+#define VDSO_CURRENT_BASE (current->mm->context.vdso)
8155
8156 #define VDSO_ENTRY \
8157 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
8158@@ -337,7 +354,4 @@ extern int arch_setup_additional_pages(s
8159 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
8160 #define compat_arch_setup_additional_pages syscall32_setup_pages
8161
8162-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
8163-#define arch_randomize_brk arch_randomize_brk
8164-
8165 #endif /* _ASM_X86_ELF_H */
8166diff -urNp linux-2.6.32.41/arch/x86/include/asm/emergency-restart.h linux-2.6.32.41/arch/x86/include/asm/emergency-restart.h
8167--- linux-2.6.32.41/arch/x86/include/asm/emergency-restart.h 2011-03-27 14:31:47.000000000 -0400
8168+++ linux-2.6.32.41/arch/x86/include/asm/emergency-restart.h 2011-05-22 23:02:06.000000000 -0400
8169@@ -15,6 +15,6 @@ enum reboot_type {
8170
8171 extern enum reboot_type reboot_type;
8172
8173-extern void machine_emergency_restart(void);
8174+extern void machine_emergency_restart(void) __noreturn;
8175
8176 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
8177diff -urNp linux-2.6.32.41/arch/x86/include/asm/futex.h linux-2.6.32.41/arch/x86/include/asm/futex.h
8178--- linux-2.6.32.41/arch/x86/include/asm/futex.h 2011-03-27 14:31:47.000000000 -0400
8179+++ linux-2.6.32.41/arch/x86/include/asm/futex.h 2011-04-17 15:56:46.000000000 -0400
8180@@ -12,16 +12,18 @@
8181 #include <asm/system.h>
8182
8183 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
8184+ typecheck(u32 *, uaddr); \
8185 asm volatile("1:\t" insn "\n" \
8186 "2:\t.section .fixup,\"ax\"\n" \
8187 "3:\tmov\t%3, %1\n" \
8188 "\tjmp\t2b\n" \
8189 "\t.previous\n" \
8190 _ASM_EXTABLE(1b, 3b) \
8191- : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
8192+ : "=r" (oldval), "=r" (ret), "+m" (*(u32 *)____m(uaddr))\
8193 : "i" (-EFAULT), "0" (oparg), "1" (0))
8194
8195 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
8196+ typecheck(u32 *, uaddr); \
8197 asm volatile("1:\tmovl %2, %0\n" \
8198 "\tmovl\t%0, %3\n" \
8199 "\t" insn "\n" \
8200@@ -34,10 +36,10 @@
8201 _ASM_EXTABLE(1b, 4b) \
8202 _ASM_EXTABLE(2b, 4b) \
8203 : "=&a" (oldval), "=&r" (ret), \
8204- "+m" (*uaddr), "=&r" (tem) \
8205+ "+m" (*(u32 *)____m(uaddr)), "=&r" (tem) \
8206 : "r" (oparg), "i" (-EFAULT), "1" (0))
8207
8208-static inline int futex_atomic_op_inuser(int encoded_op, int __user *uaddr)
8209+static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
8210 {
8211 int op = (encoded_op >> 28) & 7;
8212 int cmp = (encoded_op >> 24) & 15;
8213@@ -61,10 +63,10 @@ static inline int futex_atomic_op_inuser
8214
8215 switch (op) {
8216 case FUTEX_OP_SET:
8217- __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
8218+ __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
8219 break;
8220 case FUTEX_OP_ADD:
8221- __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
8222+ __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
8223 uaddr, oparg);
8224 break;
8225 case FUTEX_OP_OR:
8226@@ -109,7 +111,7 @@ static inline int futex_atomic_op_inuser
8227 return ret;
8228 }
8229
8230-static inline int futex_atomic_cmpxchg_inatomic(int __user *uaddr, int oldval,
8231+static inline int futex_atomic_cmpxchg_inatomic(u32 __user *uaddr, int oldval,
8232 int newval)
8233 {
8234
8235@@ -119,16 +121,16 @@ static inline int futex_atomic_cmpxchg_i
8236 return -ENOSYS;
8237 #endif
8238
8239- if (!access_ok(VERIFY_WRITE, uaddr, sizeof(int)))
8240+ if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
8241 return -EFAULT;
8242
8243- asm volatile("1:\t" LOCK_PREFIX "cmpxchgl %3, %1\n"
8244+ asm volatile("1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %1\n"
8245 "2:\t.section .fixup, \"ax\"\n"
8246 "3:\tmov %2, %0\n"
8247 "\tjmp 2b\n"
8248 "\t.previous\n"
8249 _ASM_EXTABLE(1b, 3b)
8250- : "=a" (oldval), "+m" (*uaddr)
8251+ : "=a" (oldval), "+m" (*(u32 *)____m(uaddr))
8252 : "i" (-EFAULT), "r" (newval), "0" (oldval)
8253 : "memory"
8254 );
8255diff -urNp linux-2.6.32.41/arch/x86/include/asm/hw_irq.h linux-2.6.32.41/arch/x86/include/asm/hw_irq.h
8256--- linux-2.6.32.41/arch/x86/include/asm/hw_irq.h 2011-03-27 14:31:47.000000000 -0400
8257+++ linux-2.6.32.41/arch/x86/include/asm/hw_irq.h 2011-05-04 17:56:28.000000000 -0400
8258@@ -92,8 +92,8 @@ extern void setup_ioapic_dest(void);
8259 extern void enable_IO_APIC(void);
8260
8261 /* Statistics */
8262-extern atomic_t irq_err_count;
8263-extern atomic_t irq_mis_count;
8264+extern atomic_unchecked_t irq_err_count;
8265+extern atomic_unchecked_t irq_mis_count;
8266
8267 /* EISA */
8268 extern void eisa_set_level_irq(unsigned int irq);
8269diff -urNp linux-2.6.32.41/arch/x86/include/asm/i387.h linux-2.6.32.41/arch/x86/include/asm/i387.h
8270--- linux-2.6.32.41/arch/x86/include/asm/i387.h 2011-03-27 14:31:47.000000000 -0400
8271+++ linux-2.6.32.41/arch/x86/include/asm/i387.h 2011-04-17 15:56:46.000000000 -0400
8272@@ -60,6 +60,11 @@ static inline int fxrstor_checking(struc
8273 {
8274 int err;
8275
8276+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
8277+ if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
8278+ fx = (struct i387_fxsave_struct *)((void *)fx + PAX_USER_SHADOW_BASE);
8279+#endif
8280+
8281 asm volatile("1: rex64/fxrstor (%[fx])\n\t"
8282 "2:\n"
8283 ".section .fixup,\"ax\"\n"
8284@@ -105,6 +110,11 @@ static inline int fxsave_user(struct i38
8285 {
8286 int err;
8287
8288+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
8289+ if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
8290+ fx = (struct i387_fxsave_struct __user *)((void __user *)fx + PAX_USER_SHADOW_BASE);
8291+#endif
8292+
8293 asm volatile("1: rex64/fxsave (%[fx])\n\t"
8294 "2:\n"
8295 ".section .fixup,\"ax\"\n"
8296@@ -195,13 +205,8 @@ static inline int fxrstor_checking(struc
8297 }
8298
8299 /* We need a safe address that is cheap to find and that is already
8300- in L1 during context switch. The best choices are unfortunately
8301- different for UP and SMP */
8302-#ifdef CONFIG_SMP
8303-#define safe_address (__per_cpu_offset[0])
8304-#else
8305-#define safe_address (kstat_cpu(0).cpustat.user)
8306-#endif
8307+ in L1 during context switch. */
8308+#define safe_address (init_tss[smp_processor_id()].x86_tss.sp0)
8309
8310 /*
8311 * These must be called with preempt disabled
8312@@ -291,7 +296,7 @@ static inline void kernel_fpu_begin(void
8313 struct thread_info *me = current_thread_info();
8314 preempt_disable();
8315 if (me->status & TS_USEDFPU)
8316- __save_init_fpu(me->task);
8317+ __save_init_fpu(current);
8318 else
8319 clts();
8320 }
8321diff -urNp linux-2.6.32.41/arch/x86/include/asm/io_32.h linux-2.6.32.41/arch/x86/include/asm/io_32.h
8322--- linux-2.6.32.41/arch/x86/include/asm/io_32.h 2011-03-27 14:31:47.000000000 -0400
8323+++ linux-2.6.32.41/arch/x86/include/asm/io_32.h 2011-04-17 15:56:46.000000000 -0400
8324@@ -3,6 +3,7 @@
8325
8326 #include <linux/string.h>
8327 #include <linux/compiler.h>
8328+#include <asm/processor.h>
8329
8330 /*
8331 * This file contains the definitions for the x86 IO instructions
8332@@ -42,6 +43,17 @@
8333
8334 #ifdef __KERNEL__
8335
8336+#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
8337+static inline int valid_phys_addr_range(unsigned long addr, size_t count)
8338+{
8339+ return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
8340+}
8341+
8342+static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
8343+{
8344+ return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
8345+}
8346+
8347 #include <asm-generic/iomap.h>
8348
8349 #include <linux/vmalloc.h>
8350diff -urNp linux-2.6.32.41/arch/x86/include/asm/io_64.h linux-2.6.32.41/arch/x86/include/asm/io_64.h
8351--- linux-2.6.32.41/arch/x86/include/asm/io_64.h 2011-03-27 14:31:47.000000000 -0400
8352+++ linux-2.6.32.41/arch/x86/include/asm/io_64.h 2011-04-17 15:56:46.000000000 -0400
8353@@ -140,6 +140,17 @@ __OUTS(l)
8354
8355 #include <linux/vmalloc.h>
8356
8357+#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
8358+static inline int valid_phys_addr_range(unsigned long addr, size_t count)
8359+{
8360+ return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
8361+}
8362+
8363+static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
8364+{
8365+ return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
8366+}
8367+
8368 #include <asm-generic/iomap.h>
8369
8370 void __memcpy_fromio(void *, unsigned long, unsigned);
8371diff -urNp linux-2.6.32.41/arch/x86/include/asm/iommu.h linux-2.6.32.41/arch/x86/include/asm/iommu.h
8372--- linux-2.6.32.41/arch/x86/include/asm/iommu.h 2011-03-27 14:31:47.000000000 -0400
8373+++ linux-2.6.32.41/arch/x86/include/asm/iommu.h 2011-04-17 15:56:46.000000000 -0400
8374@@ -3,7 +3,7 @@
8375
8376 extern void pci_iommu_shutdown(void);
8377 extern void no_iommu_init(void);
8378-extern struct dma_map_ops nommu_dma_ops;
8379+extern const struct dma_map_ops nommu_dma_ops;
8380 extern int force_iommu, no_iommu;
8381 extern int iommu_detected;
8382 extern int iommu_pass_through;
8383diff -urNp linux-2.6.32.41/arch/x86/include/asm/irqflags.h linux-2.6.32.41/arch/x86/include/asm/irqflags.h
8384--- linux-2.6.32.41/arch/x86/include/asm/irqflags.h 2011-03-27 14:31:47.000000000 -0400
8385+++ linux-2.6.32.41/arch/x86/include/asm/irqflags.h 2011-04-17 15:56:46.000000000 -0400
8386@@ -142,6 +142,11 @@ static inline unsigned long __raw_local_
8387 sti; \
8388 sysexit
8389
8390+#define GET_CR0_INTO_RDI mov %cr0, %rdi
8391+#define SET_RDI_INTO_CR0 mov %rdi, %cr0
8392+#define GET_CR3_INTO_RDI mov %cr3, %rdi
8393+#define SET_RDI_INTO_CR3 mov %rdi, %cr3
8394+
8395 #else
8396 #define INTERRUPT_RETURN iret
8397 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
8398diff -urNp linux-2.6.32.41/arch/x86/include/asm/kprobes.h linux-2.6.32.41/arch/x86/include/asm/kprobes.h
8399--- linux-2.6.32.41/arch/x86/include/asm/kprobes.h 2011-03-27 14:31:47.000000000 -0400
8400+++ linux-2.6.32.41/arch/x86/include/asm/kprobes.h 2011-04-23 12:56:12.000000000 -0400
8401@@ -34,13 +34,8 @@ typedef u8 kprobe_opcode_t;
8402 #define BREAKPOINT_INSTRUCTION 0xcc
8403 #define RELATIVEJUMP_INSTRUCTION 0xe9
8404 #define MAX_INSN_SIZE 16
8405-#define MAX_STACK_SIZE 64
8406-#define MIN_STACK_SIZE(ADDR) \
8407- (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
8408- THREAD_SIZE - (unsigned long)(ADDR))) \
8409- ? (MAX_STACK_SIZE) \
8410- : (((unsigned long)current_thread_info()) + \
8411- THREAD_SIZE - (unsigned long)(ADDR)))
8412+#define MAX_STACK_SIZE 64UL
8413+#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
8414
8415 #define flush_insn_slot(p) do { } while (0)
8416
8417diff -urNp linux-2.6.32.41/arch/x86/include/asm/kvm_host.h linux-2.6.32.41/arch/x86/include/asm/kvm_host.h
8418--- linux-2.6.32.41/arch/x86/include/asm/kvm_host.h 2011-05-10 22:12:01.000000000 -0400
8419+++ linux-2.6.32.41/arch/x86/include/asm/kvm_host.h 2011-05-10 22:12:26.000000000 -0400
8420@@ -536,7 +536,7 @@ struct kvm_x86_ops {
8421 const struct trace_print_flags *exit_reasons_str;
8422 };
8423
8424-extern struct kvm_x86_ops *kvm_x86_ops;
8425+extern const struct kvm_x86_ops *kvm_x86_ops;
8426
8427 int kvm_mmu_module_init(void);
8428 void kvm_mmu_module_exit(void);
8429diff -urNp linux-2.6.32.41/arch/x86/include/asm/local.h linux-2.6.32.41/arch/x86/include/asm/local.h
8430--- linux-2.6.32.41/arch/x86/include/asm/local.h 2011-03-27 14:31:47.000000000 -0400
8431+++ linux-2.6.32.41/arch/x86/include/asm/local.h 2011-04-17 15:56:46.000000000 -0400
8432@@ -18,26 +18,58 @@ typedef struct {
8433
8434 static inline void local_inc(local_t *l)
8435 {
8436- asm volatile(_ASM_INC "%0"
8437+ asm volatile(_ASM_INC "%0\n"
8438+
8439+#ifdef CONFIG_PAX_REFCOUNT
8440+ "jno 0f\n"
8441+ _ASM_DEC "%0\n"
8442+ "int $4\n0:\n"
8443+ _ASM_EXTABLE(0b, 0b)
8444+#endif
8445+
8446 : "+m" (l->a.counter));
8447 }
8448
8449 static inline void local_dec(local_t *l)
8450 {
8451- asm volatile(_ASM_DEC "%0"
8452+ asm volatile(_ASM_DEC "%0\n"
8453+
8454+#ifdef CONFIG_PAX_REFCOUNT
8455+ "jno 0f\n"
8456+ _ASM_INC "%0\n"
8457+ "int $4\n0:\n"
8458+ _ASM_EXTABLE(0b, 0b)
8459+#endif
8460+
8461 : "+m" (l->a.counter));
8462 }
8463
8464 static inline void local_add(long i, local_t *l)
8465 {
8466- asm volatile(_ASM_ADD "%1,%0"
8467+ asm volatile(_ASM_ADD "%1,%0\n"
8468+
8469+#ifdef CONFIG_PAX_REFCOUNT
8470+ "jno 0f\n"
8471+ _ASM_SUB "%1,%0\n"
8472+ "int $4\n0:\n"
8473+ _ASM_EXTABLE(0b, 0b)
8474+#endif
8475+
8476 : "+m" (l->a.counter)
8477 : "ir" (i));
8478 }
8479
8480 static inline void local_sub(long i, local_t *l)
8481 {
8482- asm volatile(_ASM_SUB "%1,%0"
8483+ asm volatile(_ASM_SUB "%1,%0\n"
8484+
8485+#ifdef CONFIG_PAX_REFCOUNT
8486+ "jno 0f\n"
8487+ _ASM_ADD "%1,%0\n"
8488+ "int $4\n0:\n"
8489+ _ASM_EXTABLE(0b, 0b)
8490+#endif
8491+
8492 : "+m" (l->a.counter)
8493 : "ir" (i));
8494 }
8495@@ -55,7 +87,16 @@ static inline int local_sub_and_test(lon
8496 {
8497 unsigned char c;
8498
8499- asm volatile(_ASM_SUB "%2,%0; sete %1"
8500+ asm volatile(_ASM_SUB "%2,%0\n"
8501+
8502+#ifdef CONFIG_PAX_REFCOUNT
8503+ "jno 0f\n"
8504+ _ASM_ADD "%2,%0\n"
8505+ "int $4\n0:\n"
8506+ _ASM_EXTABLE(0b, 0b)
8507+#endif
8508+
8509+ "sete %1\n"
8510 : "+m" (l->a.counter), "=qm" (c)
8511 : "ir" (i) : "memory");
8512 return c;
8513@@ -73,7 +114,16 @@ static inline int local_dec_and_test(loc
8514 {
8515 unsigned char c;
8516
8517- asm volatile(_ASM_DEC "%0; sete %1"
8518+ asm volatile(_ASM_DEC "%0\n"
8519+
8520+#ifdef CONFIG_PAX_REFCOUNT
8521+ "jno 0f\n"
8522+ _ASM_INC "%0\n"
8523+ "int $4\n0:\n"
8524+ _ASM_EXTABLE(0b, 0b)
8525+#endif
8526+
8527+ "sete %1\n"
8528 : "+m" (l->a.counter), "=qm" (c)
8529 : : "memory");
8530 return c != 0;
8531@@ -91,7 +141,16 @@ static inline int local_inc_and_test(loc
8532 {
8533 unsigned char c;
8534
8535- asm volatile(_ASM_INC "%0; sete %1"
8536+ asm volatile(_ASM_INC "%0\n"
8537+
8538+#ifdef CONFIG_PAX_REFCOUNT
8539+ "jno 0f\n"
8540+ _ASM_DEC "%0\n"
8541+ "int $4\n0:\n"
8542+ _ASM_EXTABLE(0b, 0b)
8543+#endif
8544+
8545+ "sete %1\n"
8546 : "+m" (l->a.counter), "=qm" (c)
8547 : : "memory");
8548 return c != 0;
8549@@ -110,7 +169,16 @@ static inline int local_add_negative(lon
8550 {
8551 unsigned char c;
8552
8553- asm volatile(_ASM_ADD "%2,%0; sets %1"
8554+ asm volatile(_ASM_ADD "%2,%0\n"
8555+
8556+#ifdef CONFIG_PAX_REFCOUNT
8557+ "jno 0f\n"
8558+ _ASM_SUB "%2,%0\n"
8559+ "int $4\n0:\n"
8560+ _ASM_EXTABLE(0b, 0b)
8561+#endif
8562+
8563+ "sets %1\n"
8564 : "+m" (l->a.counter), "=qm" (c)
8565 : "ir" (i) : "memory");
8566 return c;
8567@@ -133,7 +201,15 @@ static inline long local_add_return(long
8568 #endif
8569 /* Modern 486+ processor */
8570 __i = i;
8571- asm volatile(_ASM_XADD "%0, %1;"
8572+ asm volatile(_ASM_XADD "%0, %1\n"
8573+
8574+#ifdef CONFIG_PAX_REFCOUNT
8575+ "jno 0f\n"
8576+ _ASM_MOV "%0,%1\n"
8577+ "int $4\n0:\n"
8578+ _ASM_EXTABLE(0b, 0b)
8579+#endif
8580+
8581 : "+r" (i), "+m" (l->a.counter)
8582 : : "memory");
8583 return i + __i;
8584diff -urNp linux-2.6.32.41/arch/x86/include/asm/microcode.h linux-2.6.32.41/arch/x86/include/asm/microcode.h
8585--- linux-2.6.32.41/arch/x86/include/asm/microcode.h 2011-03-27 14:31:47.000000000 -0400
8586+++ linux-2.6.32.41/arch/x86/include/asm/microcode.h 2011-04-17 15:56:46.000000000 -0400
8587@@ -12,13 +12,13 @@ struct device;
8588 enum ucode_state { UCODE_ERROR, UCODE_OK, UCODE_NFOUND };
8589
8590 struct microcode_ops {
8591- enum ucode_state (*request_microcode_user) (int cpu,
8592+ enum ucode_state (* const request_microcode_user) (int cpu,
8593 const void __user *buf, size_t size);
8594
8595- enum ucode_state (*request_microcode_fw) (int cpu,
8596+ enum ucode_state (* const request_microcode_fw) (int cpu,
8597 struct device *device);
8598
8599- void (*microcode_fini_cpu) (int cpu);
8600+ void (* const microcode_fini_cpu) (int cpu);
8601
8602 /*
8603 * The generic 'microcode_core' part guarantees that
8604@@ -38,18 +38,18 @@ struct ucode_cpu_info {
8605 extern struct ucode_cpu_info ucode_cpu_info[];
8606
8607 #ifdef CONFIG_MICROCODE_INTEL
8608-extern struct microcode_ops * __init init_intel_microcode(void);
8609+extern const struct microcode_ops * __init init_intel_microcode(void);
8610 #else
8611-static inline struct microcode_ops * __init init_intel_microcode(void)
8612+static inline const struct microcode_ops * __init init_intel_microcode(void)
8613 {
8614 return NULL;
8615 }
8616 #endif /* CONFIG_MICROCODE_INTEL */
8617
8618 #ifdef CONFIG_MICROCODE_AMD
8619-extern struct microcode_ops * __init init_amd_microcode(void);
8620+extern const struct microcode_ops * __init init_amd_microcode(void);
8621 #else
8622-static inline struct microcode_ops * __init init_amd_microcode(void)
8623+static inline const struct microcode_ops * __init init_amd_microcode(void)
8624 {
8625 return NULL;
8626 }
8627diff -urNp linux-2.6.32.41/arch/x86/include/asm/mman.h linux-2.6.32.41/arch/x86/include/asm/mman.h
8628--- linux-2.6.32.41/arch/x86/include/asm/mman.h 2011-03-27 14:31:47.000000000 -0400
8629+++ linux-2.6.32.41/arch/x86/include/asm/mman.h 2011-04-17 15:56:46.000000000 -0400
8630@@ -5,4 +5,14 @@
8631
8632 #include <asm-generic/mman.h>
8633
8634+#ifdef __KERNEL__
8635+#ifndef __ASSEMBLY__
8636+#ifdef CONFIG_X86_32
8637+#define arch_mmap_check i386_mmap_check
8638+int i386_mmap_check(unsigned long addr, unsigned long len,
8639+ unsigned long flags);
8640+#endif
8641+#endif
8642+#endif
8643+
8644 #endif /* _ASM_X86_MMAN_H */
8645diff -urNp linux-2.6.32.41/arch/x86/include/asm/mmu_context.h linux-2.6.32.41/arch/x86/include/asm/mmu_context.h
8646--- linux-2.6.32.41/arch/x86/include/asm/mmu_context.h 2011-03-27 14:31:47.000000000 -0400
8647+++ linux-2.6.32.41/arch/x86/include/asm/mmu_context.h 2011-04-17 15:56:46.000000000 -0400
8648@@ -24,6 +24,21 @@ void destroy_context(struct mm_struct *m
8649
8650 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
8651 {
8652+
8653+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
8654+ unsigned int i;
8655+ pgd_t *pgd;
8656+
8657+ pax_open_kernel();
8658+ pgd = get_cpu_pgd(smp_processor_id());
8659+ for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
8660+ if (paravirt_enabled())
8661+ set_pgd(pgd+i, native_make_pgd(0));
8662+ else
8663+ pgd[i] = native_make_pgd(0);
8664+ pax_close_kernel();
8665+#endif
8666+
8667 #ifdef CONFIG_SMP
8668 if (percpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
8669 percpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
8670@@ -34,16 +49,30 @@ static inline void switch_mm(struct mm_s
8671 struct task_struct *tsk)
8672 {
8673 unsigned cpu = smp_processor_id();
8674+#if defined(CONFIG_X86_32) && defined(CONFIG_SMP)
8675+ int tlbstate = TLBSTATE_OK;
8676+#endif
8677
8678 if (likely(prev != next)) {
8679 #ifdef CONFIG_SMP
8680+#ifdef CONFIG_X86_32
8681+ tlbstate = percpu_read(cpu_tlbstate.state);
8682+#endif
8683 percpu_write(cpu_tlbstate.state, TLBSTATE_OK);
8684 percpu_write(cpu_tlbstate.active_mm, next);
8685 #endif
8686 cpumask_set_cpu(cpu, mm_cpumask(next));
8687
8688 /* Re-load page tables */
8689+#ifdef CONFIG_PAX_PER_CPU_PGD
8690+ pax_open_kernel();
8691+ __clone_user_pgds(get_cpu_pgd(cpu), next->pgd, USER_PGD_PTRS);
8692+ __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd, USER_PGD_PTRS);
8693+ pax_close_kernel();
8694+ load_cr3(get_cpu_pgd(cpu));
8695+#else
8696 load_cr3(next->pgd);
8697+#endif
8698
8699 /* stop flush ipis for the previous mm */
8700 cpumask_clear_cpu(cpu, mm_cpumask(prev));
8701@@ -53,9 +82,38 @@ static inline void switch_mm(struct mm_s
8702 */
8703 if (unlikely(prev->context.ldt != next->context.ldt))
8704 load_LDT_nolock(&next->context);
8705- }
8706+
8707+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
8708+ if (!nx_enabled) {
8709+ smp_mb__before_clear_bit();
8710+ cpu_clear(cpu, prev->context.cpu_user_cs_mask);
8711+ smp_mb__after_clear_bit();
8712+ cpu_set(cpu, next->context.cpu_user_cs_mask);
8713+ }
8714+#endif
8715+
8716+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
8717+ if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
8718+ prev->context.user_cs_limit != next->context.user_cs_limit))
8719+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
8720 #ifdef CONFIG_SMP
8721+ else if (unlikely(tlbstate != TLBSTATE_OK))
8722+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
8723+#endif
8724+#endif
8725+
8726+ }
8727 else {
8728+
8729+#ifdef CONFIG_PAX_PER_CPU_PGD
8730+ pax_open_kernel();
8731+ __clone_user_pgds(get_cpu_pgd(cpu), next->pgd, USER_PGD_PTRS);
8732+ __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd, USER_PGD_PTRS);
8733+ pax_close_kernel();
8734+ load_cr3(get_cpu_pgd(cpu));
8735+#endif
8736+
8737+#ifdef CONFIG_SMP
8738 percpu_write(cpu_tlbstate.state, TLBSTATE_OK);
8739 BUG_ON(percpu_read(cpu_tlbstate.active_mm) != next);
8740
8741@@ -64,11 +122,28 @@ static inline void switch_mm(struct mm_s
8742 * tlb flush IPI delivery. We must reload CR3
8743 * to make sure to use no freed page tables.
8744 */
8745+
8746+#ifndef CONFIG_PAX_PER_CPU_PGD
8747 load_cr3(next->pgd);
8748+#endif
8749+
8750 load_LDT_nolock(&next->context);
8751+
8752+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
8753+ if (!nx_enabled)
8754+ cpu_set(cpu, next->context.cpu_user_cs_mask);
8755+#endif
8756+
8757+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
8758+#ifdef CONFIG_PAX_PAGEEXEC
8759+ if (!((next->pax_flags & MF_PAX_PAGEEXEC) && nx_enabled))
8760+#endif
8761+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
8762+#endif
8763+
8764 }
8765- }
8766 #endif
8767+ }
8768 }
8769
8770 #define activate_mm(prev, next) \
8771diff -urNp linux-2.6.32.41/arch/x86/include/asm/mmu.h linux-2.6.32.41/arch/x86/include/asm/mmu.h
8772--- linux-2.6.32.41/arch/x86/include/asm/mmu.h 2011-03-27 14:31:47.000000000 -0400
8773+++ linux-2.6.32.41/arch/x86/include/asm/mmu.h 2011-04-17 15:56:46.000000000 -0400
8774@@ -9,10 +9,23 @@
8775 * we put the segment information here.
8776 */
8777 typedef struct {
8778- void *ldt;
8779+ struct desc_struct *ldt;
8780 int size;
8781 struct mutex lock;
8782- void *vdso;
8783+ unsigned long vdso;
8784+
8785+#ifdef CONFIG_X86_32
8786+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
8787+ unsigned long user_cs_base;
8788+ unsigned long user_cs_limit;
8789+
8790+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
8791+ cpumask_t cpu_user_cs_mask;
8792+#endif
8793+
8794+#endif
8795+#endif
8796+
8797 } mm_context_t;
8798
8799 #ifdef CONFIG_SMP
8800diff -urNp linux-2.6.32.41/arch/x86/include/asm/module.h linux-2.6.32.41/arch/x86/include/asm/module.h
8801--- linux-2.6.32.41/arch/x86/include/asm/module.h 2011-03-27 14:31:47.000000000 -0400
8802+++ linux-2.6.32.41/arch/x86/include/asm/module.h 2011-04-23 13:18:57.000000000 -0400
8803@@ -5,6 +5,7 @@
8804
8805 #ifdef CONFIG_X86_64
8806 /* X86_64 does not define MODULE_PROC_FAMILY */
8807+#define MODULE_PROC_FAMILY ""
8808 #elif defined CONFIG_M386
8809 #define MODULE_PROC_FAMILY "386 "
8810 #elif defined CONFIG_M486
8811@@ -59,13 +60,36 @@
8812 #error unknown processor family
8813 #endif
8814
8815-#ifdef CONFIG_X86_32
8816-# ifdef CONFIG_4KSTACKS
8817-# define MODULE_STACKSIZE "4KSTACKS "
8818-# else
8819-# define MODULE_STACKSIZE ""
8820-# endif
8821-# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_STACKSIZE
8822+#ifdef CONFIG_PAX_MEMORY_UDEREF
8823+#define MODULE_PAX_UDEREF "UDEREF "
8824+#else
8825+#define MODULE_PAX_UDEREF ""
8826+#endif
8827+
8828+#ifdef CONFIG_PAX_KERNEXEC
8829+#define MODULE_PAX_KERNEXEC "KERNEXEC "
8830+#else
8831+#define MODULE_PAX_KERNEXEC ""
8832+#endif
8833+
8834+#ifdef CONFIG_PAX_REFCOUNT
8835+#define MODULE_PAX_REFCOUNT "REFCOUNT "
8836+#else
8837+#define MODULE_PAX_REFCOUNT ""
8838 #endif
8839
8840+#if defined(CONFIG_X86_32) && defined(CONFIG_4KSTACKS)
8841+#define MODULE_STACKSIZE "4KSTACKS "
8842+#else
8843+#define MODULE_STACKSIZE ""
8844+#endif
8845+
8846+#ifdef CONFIG_GRKERNSEC
8847+#define MODULE_GRSEC "GRSECURITY "
8848+#else
8849+#define MODULE_GRSEC ""
8850+#endif
8851+
8852+#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_STACKSIZE MODULE_GRSEC MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF MODULE_PAX_REFCOUNT
8853+
8854 #endif /* _ASM_X86_MODULE_H */
8855diff -urNp linux-2.6.32.41/arch/x86/include/asm/page_64_types.h linux-2.6.32.41/arch/x86/include/asm/page_64_types.h
8856--- linux-2.6.32.41/arch/x86/include/asm/page_64_types.h 2011-03-27 14:31:47.000000000 -0400
8857+++ linux-2.6.32.41/arch/x86/include/asm/page_64_types.h 2011-04-17 15:56:46.000000000 -0400
8858@@ -56,7 +56,7 @@ void copy_page(void *to, void *from);
8859
8860 /* duplicated to the one in bootmem.h */
8861 extern unsigned long max_pfn;
8862-extern unsigned long phys_base;
8863+extern const unsigned long phys_base;
8864
8865 extern unsigned long __phys_addr(unsigned long);
8866 #define __phys_reloc_hide(x) (x)
8867diff -urNp linux-2.6.32.41/arch/x86/include/asm/paravirt.h linux-2.6.32.41/arch/x86/include/asm/paravirt.h
8868--- linux-2.6.32.41/arch/x86/include/asm/paravirt.h 2011-03-27 14:31:47.000000000 -0400
8869+++ linux-2.6.32.41/arch/x86/include/asm/paravirt.h 2011-04-17 15:56:46.000000000 -0400
8870@@ -729,6 +729,21 @@ static inline void __set_fixmap(unsigned
8871 pv_mmu_ops.set_fixmap(idx, phys, flags);
8872 }
8873
8874+#ifdef CONFIG_PAX_KERNEXEC
8875+static inline unsigned long pax_open_kernel(void)
8876+{
8877+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
8878+}
8879+
8880+static inline unsigned long pax_close_kernel(void)
8881+{
8882+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
8883+}
8884+#else
8885+static inline unsigned long pax_open_kernel(void) { return 0; }
8886+static inline unsigned long pax_close_kernel(void) { return 0; }
8887+#endif
8888+
8889 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
8890
8891 static inline int __raw_spin_is_locked(struct raw_spinlock *lock)
8892@@ -945,7 +960,7 @@ extern void default_banner(void);
8893
8894 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
8895 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
8896-#define PARA_INDIRECT(addr) *%cs:addr
8897+#define PARA_INDIRECT(addr) *%ss:addr
8898 #endif
8899
8900 #define INTERRUPT_RETURN \
8901@@ -1022,6 +1037,21 @@ extern void default_banner(void);
8902 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
8903 CLBR_NONE, \
8904 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
8905+
8906+#define GET_CR0_INTO_RDI \
8907+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
8908+ mov %rax,%rdi
8909+
8910+#define SET_RDI_INTO_CR0 \
8911+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
8912+
8913+#define GET_CR3_INTO_RDI \
8914+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
8915+ mov %rax,%rdi
8916+
8917+#define SET_RDI_INTO_CR3 \
8918+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
8919+
8920 #endif /* CONFIG_X86_32 */
8921
8922 #endif /* __ASSEMBLY__ */
8923diff -urNp linux-2.6.32.41/arch/x86/include/asm/paravirt_types.h linux-2.6.32.41/arch/x86/include/asm/paravirt_types.h
8924--- linux-2.6.32.41/arch/x86/include/asm/paravirt_types.h 2011-03-27 14:31:47.000000000 -0400
8925+++ linux-2.6.32.41/arch/x86/include/asm/paravirt_types.h 2011-04-17 15:56:46.000000000 -0400
8926@@ -316,6 +316,12 @@ struct pv_mmu_ops {
8927 an mfn. We can tell which is which from the index. */
8928 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
8929 phys_addr_t phys, pgprot_t flags);
8930+
8931+#ifdef CONFIG_PAX_KERNEXEC
8932+ unsigned long (*pax_open_kernel)(void);
8933+ unsigned long (*pax_close_kernel)(void);
8934+#endif
8935+
8936 };
8937
8938 struct raw_spinlock;
8939diff -urNp linux-2.6.32.41/arch/x86/include/asm/pci_x86.h linux-2.6.32.41/arch/x86/include/asm/pci_x86.h
8940--- linux-2.6.32.41/arch/x86/include/asm/pci_x86.h 2011-03-27 14:31:47.000000000 -0400
8941+++ linux-2.6.32.41/arch/x86/include/asm/pci_x86.h 2011-04-17 15:56:46.000000000 -0400
8942@@ -89,16 +89,16 @@ extern int (*pcibios_enable_irq)(struct
8943 extern void (*pcibios_disable_irq)(struct pci_dev *dev);
8944
8945 struct pci_raw_ops {
8946- int (*read)(unsigned int domain, unsigned int bus, unsigned int devfn,
8947+ int (* const read)(unsigned int domain, unsigned int bus, unsigned int devfn,
8948 int reg, int len, u32 *val);
8949- int (*write)(unsigned int domain, unsigned int bus, unsigned int devfn,
8950+ int (* const write)(unsigned int domain, unsigned int bus, unsigned int devfn,
8951 int reg, int len, u32 val);
8952 };
8953
8954-extern struct pci_raw_ops *raw_pci_ops;
8955-extern struct pci_raw_ops *raw_pci_ext_ops;
8956+extern const struct pci_raw_ops *raw_pci_ops;
8957+extern const struct pci_raw_ops *raw_pci_ext_ops;
8958
8959-extern struct pci_raw_ops pci_direct_conf1;
8960+extern const struct pci_raw_ops pci_direct_conf1;
8961 extern bool port_cf9_safe;
8962
8963 /* arch_initcall level */
8964diff -urNp linux-2.6.32.41/arch/x86/include/asm/pgalloc.h linux-2.6.32.41/arch/x86/include/asm/pgalloc.h
8965--- linux-2.6.32.41/arch/x86/include/asm/pgalloc.h 2011-03-27 14:31:47.000000000 -0400
8966+++ linux-2.6.32.41/arch/x86/include/asm/pgalloc.h 2011-04-17 15:56:46.000000000 -0400
8967@@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(s
8968 pmd_t *pmd, pte_t *pte)
8969 {
8970 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
8971+ set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
8972+}
8973+
8974+static inline void pmd_populate_user(struct mm_struct *mm,
8975+ pmd_t *pmd, pte_t *pte)
8976+{
8977+ paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
8978 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
8979 }
8980
8981diff -urNp linux-2.6.32.41/arch/x86/include/asm/pgtable-2level.h linux-2.6.32.41/arch/x86/include/asm/pgtable-2level.h
8982--- linux-2.6.32.41/arch/x86/include/asm/pgtable-2level.h 2011-03-27 14:31:47.000000000 -0400
8983+++ linux-2.6.32.41/arch/x86/include/asm/pgtable-2level.h 2011-04-17 15:56:46.000000000 -0400
8984@@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t
8985
8986 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
8987 {
8988+ pax_open_kernel();
8989 *pmdp = pmd;
8990+ pax_close_kernel();
8991 }
8992
8993 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
8994diff -urNp linux-2.6.32.41/arch/x86/include/asm/pgtable_32.h linux-2.6.32.41/arch/x86/include/asm/pgtable_32.h
8995--- linux-2.6.32.41/arch/x86/include/asm/pgtable_32.h 2011-03-27 14:31:47.000000000 -0400
8996+++ linux-2.6.32.41/arch/x86/include/asm/pgtable_32.h 2011-04-17 15:56:46.000000000 -0400
8997@@ -26,9 +26,6 @@
8998 struct mm_struct;
8999 struct vm_area_struct;
9000
9001-extern pgd_t swapper_pg_dir[1024];
9002-extern pgd_t trampoline_pg_dir[1024];
9003-
9004 static inline void pgtable_cache_init(void) { }
9005 static inline void check_pgt_cache(void) { }
9006 void paging_init(void);
9007@@ -49,6 +46,12 @@ extern void set_pmd_pfn(unsigned long, u
9008 # include <asm/pgtable-2level.h>
9009 #endif
9010
9011+extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
9012+extern pgd_t trampoline_pg_dir[PTRS_PER_PGD];
9013+#ifdef CONFIG_X86_PAE
9014+extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
9015+#endif
9016+
9017 #if defined(CONFIG_HIGHPTE)
9018 #define __KM_PTE \
9019 (in_nmi() ? KM_NMI_PTE : \
9020@@ -73,7 +76,9 @@ extern void set_pmd_pfn(unsigned long, u
9021 /* Clear a kernel PTE and flush it from the TLB */
9022 #define kpte_clear_flush(ptep, vaddr) \
9023 do { \
9024+ pax_open_kernel(); \
9025 pte_clear(&init_mm, (vaddr), (ptep)); \
9026+ pax_close_kernel(); \
9027 __flush_tlb_one((vaddr)); \
9028 } while (0)
9029
9030@@ -85,6 +90,9 @@ do { \
9031
9032 #endif /* !__ASSEMBLY__ */
9033
9034+#define HAVE_ARCH_UNMAPPED_AREA
9035+#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
9036+
9037 /*
9038 * kern_addr_valid() is (1) for FLATMEM and (0) for
9039 * SPARSEMEM and DISCONTIGMEM
9040diff -urNp linux-2.6.32.41/arch/x86/include/asm/pgtable_32_types.h linux-2.6.32.41/arch/x86/include/asm/pgtable_32_types.h
9041--- linux-2.6.32.41/arch/x86/include/asm/pgtable_32_types.h 2011-03-27 14:31:47.000000000 -0400
9042+++ linux-2.6.32.41/arch/x86/include/asm/pgtable_32_types.h 2011-04-17 15:56:46.000000000 -0400
9043@@ -8,7 +8,7 @@
9044 */
9045 #ifdef CONFIG_X86_PAE
9046 # include <asm/pgtable-3level_types.h>
9047-# define PMD_SIZE (1UL << PMD_SHIFT)
9048+# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
9049 # define PMD_MASK (~(PMD_SIZE - 1))
9050 #else
9051 # include <asm/pgtable-2level_types.h>
9052@@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set
9053 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
9054 #endif
9055
9056+#ifdef CONFIG_PAX_KERNEXEC
9057+#ifndef __ASSEMBLY__
9058+extern unsigned char MODULES_EXEC_VADDR[];
9059+extern unsigned char MODULES_EXEC_END[];
9060+#endif
9061+#include <asm/boot.h>
9062+#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
9063+#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
9064+#else
9065+#define ktla_ktva(addr) (addr)
9066+#define ktva_ktla(addr) (addr)
9067+#endif
9068+
9069 #define MODULES_VADDR VMALLOC_START
9070 #define MODULES_END VMALLOC_END
9071 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
9072diff -urNp linux-2.6.32.41/arch/x86/include/asm/pgtable-3level.h linux-2.6.32.41/arch/x86/include/asm/pgtable-3level.h
9073--- linux-2.6.32.41/arch/x86/include/asm/pgtable-3level.h 2011-03-27 14:31:47.000000000 -0400
9074+++ linux-2.6.32.41/arch/x86/include/asm/pgtable-3level.h 2011-04-17 15:56:46.000000000 -0400
9075@@ -38,12 +38,16 @@ static inline void native_set_pte_atomic
9076
9077 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
9078 {
9079+ pax_open_kernel();
9080 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
9081+ pax_close_kernel();
9082 }
9083
9084 static inline void native_set_pud(pud_t *pudp, pud_t pud)
9085 {
9086+ pax_open_kernel();
9087 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
9088+ pax_close_kernel();
9089 }
9090
9091 /*
9092diff -urNp linux-2.6.32.41/arch/x86/include/asm/pgtable_64.h linux-2.6.32.41/arch/x86/include/asm/pgtable_64.h
9093--- linux-2.6.32.41/arch/x86/include/asm/pgtable_64.h 2011-03-27 14:31:47.000000000 -0400
9094+++ linux-2.6.32.41/arch/x86/include/asm/pgtable_64.h 2011-04-17 15:56:46.000000000 -0400
9095@@ -16,10 +16,13 @@
9096
9097 extern pud_t level3_kernel_pgt[512];
9098 extern pud_t level3_ident_pgt[512];
9099+extern pud_t level3_vmalloc_pgt[512];
9100+extern pud_t level3_vmemmap_pgt[512];
9101+extern pud_t level2_vmemmap_pgt[512];
9102 extern pmd_t level2_kernel_pgt[512];
9103 extern pmd_t level2_fixmap_pgt[512];
9104-extern pmd_t level2_ident_pgt[512];
9105-extern pgd_t init_level4_pgt[];
9106+extern pmd_t level2_ident_pgt[512*2];
9107+extern pgd_t init_level4_pgt[512];
9108
9109 #define swapper_pg_dir init_level4_pgt
9110
9111@@ -74,7 +77,9 @@ static inline pte_t native_ptep_get_and_
9112
9113 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
9114 {
9115+ pax_open_kernel();
9116 *pmdp = pmd;
9117+ pax_close_kernel();
9118 }
9119
9120 static inline void native_pmd_clear(pmd_t *pmd)
9121@@ -94,7 +99,9 @@ static inline void native_pud_clear(pud_
9122
9123 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
9124 {
9125+ pax_open_kernel();
9126 *pgdp = pgd;
9127+ pax_close_kernel();
9128 }
9129
9130 static inline void native_pgd_clear(pgd_t *pgd)
9131diff -urNp linux-2.6.32.41/arch/x86/include/asm/pgtable_64_types.h linux-2.6.32.41/arch/x86/include/asm/pgtable_64_types.h
9132--- linux-2.6.32.41/arch/x86/include/asm/pgtable_64_types.h 2011-03-27 14:31:47.000000000 -0400
9133+++ linux-2.6.32.41/arch/x86/include/asm/pgtable_64_types.h 2011-04-17 15:56:46.000000000 -0400
9134@@ -59,5 +59,10 @@ typedef struct { pteval_t pte; } pte_t;
9135 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
9136 #define MODULES_END _AC(0xffffffffff000000, UL)
9137 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
9138+#define MODULES_EXEC_VADDR MODULES_VADDR
9139+#define MODULES_EXEC_END MODULES_END
9140+
9141+#define ktla_ktva(addr) (addr)
9142+#define ktva_ktla(addr) (addr)
9143
9144 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
9145diff -urNp linux-2.6.32.41/arch/x86/include/asm/pgtable.h linux-2.6.32.41/arch/x86/include/asm/pgtable.h
9146--- linux-2.6.32.41/arch/x86/include/asm/pgtable.h 2011-03-27 14:31:47.000000000 -0400
9147+++ linux-2.6.32.41/arch/x86/include/asm/pgtable.h 2011-04-17 15:56:46.000000000 -0400
9148@@ -74,12 +74,51 @@ extern struct list_head pgd_list;
9149
9150 #define arch_end_context_switch(prev) do {} while(0)
9151
9152+#define pax_open_kernel() native_pax_open_kernel()
9153+#define pax_close_kernel() native_pax_close_kernel()
9154 #endif /* CONFIG_PARAVIRT */
9155
9156+#define __HAVE_ARCH_PAX_OPEN_KERNEL
9157+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
9158+
9159+#ifdef CONFIG_PAX_KERNEXEC
9160+static inline unsigned long native_pax_open_kernel(void)
9161+{
9162+ unsigned long cr0;
9163+
9164+ preempt_disable();
9165+ barrier();
9166+ cr0 = read_cr0() ^ X86_CR0_WP;
9167+ BUG_ON(unlikely(cr0 & X86_CR0_WP));
9168+ write_cr0(cr0);
9169+ return cr0 ^ X86_CR0_WP;
9170+}
9171+
9172+static inline unsigned long native_pax_close_kernel(void)
9173+{
9174+ unsigned long cr0;
9175+
9176+ cr0 = read_cr0() ^ X86_CR0_WP;
9177+ BUG_ON(unlikely(!(cr0 & X86_CR0_WP)));
9178+ write_cr0(cr0);
9179+ barrier();
9180+ preempt_enable_no_resched();
9181+ return cr0 ^ X86_CR0_WP;
9182+}
9183+#else
9184+static inline unsigned long native_pax_open_kernel(void) { return 0; }
9185+static inline unsigned long native_pax_close_kernel(void) { return 0; }
9186+#endif
9187+
9188 /*
9189 * The following only work if pte_present() is true.
9190 * Undefined behaviour if not..
9191 */
9192+static inline int pte_user(pte_t pte)
9193+{
9194+ return pte_val(pte) & _PAGE_USER;
9195+}
9196+
9197 static inline int pte_dirty(pte_t pte)
9198 {
9199 return pte_flags(pte) & _PAGE_DIRTY;
9200@@ -167,9 +206,29 @@ static inline pte_t pte_wrprotect(pte_t
9201 return pte_clear_flags(pte, _PAGE_RW);
9202 }
9203
9204+static inline pte_t pte_mkread(pte_t pte)
9205+{
9206+ return __pte(pte_val(pte) | _PAGE_USER);
9207+}
9208+
9209 static inline pte_t pte_mkexec(pte_t pte)
9210 {
9211- return pte_clear_flags(pte, _PAGE_NX);
9212+#ifdef CONFIG_X86_PAE
9213+ if (__supported_pte_mask & _PAGE_NX)
9214+ return pte_clear_flags(pte, _PAGE_NX);
9215+ else
9216+#endif
9217+ return pte_set_flags(pte, _PAGE_USER);
9218+}
9219+
9220+static inline pte_t pte_exprotect(pte_t pte)
9221+{
9222+#ifdef CONFIG_X86_PAE
9223+ if (__supported_pte_mask & _PAGE_NX)
9224+ return pte_set_flags(pte, _PAGE_NX);
9225+ else
9226+#endif
9227+ return pte_clear_flags(pte, _PAGE_USER);
9228 }
9229
9230 static inline pte_t pte_mkdirty(pte_t pte)
9231@@ -302,6 +361,15 @@ pte_t *populate_extra_pte(unsigned long
9232 #endif
9233
9234 #ifndef __ASSEMBLY__
9235+
9236+#ifdef CONFIG_PAX_PER_CPU_PGD
9237+extern pgd_t cpu_pgd[NR_CPUS][PTRS_PER_PGD];
9238+static inline pgd_t *get_cpu_pgd(unsigned int cpu)
9239+{
9240+ return cpu_pgd[cpu];
9241+}
9242+#endif
9243+
9244 #include <linux/mm_types.h>
9245
9246 static inline int pte_none(pte_t pte)
9247@@ -472,7 +540,7 @@ static inline pud_t *pud_offset(pgd_t *p
9248
9249 static inline int pgd_bad(pgd_t pgd)
9250 {
9251- return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
9252+ return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
9253 }
9254
9255 static inline int pgd_none(pgd_t pgd)
9256@@ -495,7 +563,12 @@ static inline int pgd_none(pgd_t pgd)
9257 * pgd_offset() returns a (pgd_t *)
9258 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
9259 */
9260-#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
9261+#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
9262+
9263+#ifdef CONFIG_PAX_PER_CPU_PGD
9264+#define pgd_offset_cpu(cpu, address) (get_cpu_pgd(cpu) + pgd_index(address))
9265+#endif
9266+
9267 /*
9268 * a shortcut which implies the use of the kernel's pgd, instead
9269 * of a process's
9270@@ -506,6 +579,20 @@ static inline int pgd_none(pgd_t pgd)
9271 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
9272 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
9273
9274+#ifdef CONFIG_X86_32
9275+#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
9276+#else
9277+#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
9278+#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
9279+
9280+#ifdef CONFIG_PAX_MEMORY_UDEREF
9281+#define PAX_USER_SHADOW_BASE (_AC(1,UL) << TASK_SIZE_MAX_SHIFT)
9282+#else
9283+#define PAX_USER_SHADOW_BASE (_AC(0,UL))
9284+#endif
9285+
9286+#endif
9287+
9288 #ifndef __ASSEMBLY__
9289
9290 extern int direct_gbpages;
9291@@ -611,11 +698,23 @@ static inline void ptep_set_wrprotect(st
9292 * dst and src can be on the same page, but the range must not overlap,
9293 * and must not cross a page boundary.
9294 */
9295-static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
9296+static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
9297 {
9298- memcpy(dst, src, count * sizeof(pgd_t));
9299+ pax_open_kernel();
9300+ while (count--)
9301+ *dst++ = *src++;
9302+ pax_close_kernel();
9303 }
9304
9305+#ifdef CONFIG_PAX_PER_CPU_PGD
9306+extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src, int count);
9307+#endif
9308+
9309+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
9310+extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src, int count);
9311+#else
9312+static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src, int count) {}
9313+#endif
9314
9315 #include <asm-generic/pgtable.h>
9316 #endif /* __ASSEMBLY__ */
9317diff -urNp linux-2.6.32.41/arch/x86/include/asm/pgtable_types.h linux-2.6.32.41/arch/x86/include/asm/pgtable_types.h
9318--- linux-2.6.32.41/arch/x86/include/asm/pgtable_types.h 2011-03-27 14:31:47.000000000 -0400
9319+++ linux-2.6.32.41/arch/x86/include/asm/pgtable_types.h 2011-04-17 15:56:46.000000000 -0400
9320@@ -16,12 +16,11 @@
9321 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
9322 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
9323 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
9324-#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
9325+#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
9326 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
9327 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
9328 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
9329-#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
9330-#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
9331+#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
9332 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
9333
9334 /* If _PAGE_BIT_PRESENT is clear, we use these: */
9335@@ -39,7 +38,6 @@
9336 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
9337 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
9338 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
9339-#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
9340 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
9341 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
9342 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
9343@@ -55,8 +53,10 @@
9344
9345 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
9346 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
9347-#else
9348+#elif defined(CONFIG_KMEMCHECK)
9349 #define _PAGE_NX (_AT(pteval_t, 0))
9350+#else
9351+#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
9352 #endif
9353
9354 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
9355@@ -93,6 +93,9 @@
9356 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
9357 _PAGE_ACCESSED)
9358
9359+#define PAGE_READONLY_NOEXEC PAGE_READONLY
9360+#define PAGE_SHARED_NOEXEC PAGE_SHARED
9361+
9362 #define __PAGE_KERNEL_EXEC \
9363 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
9364 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
9365@@ -103,8 +106,8 @@
9366 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
9367 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
9368 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
9369-#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
9370-#define __PAGE_KERNEL_VSYSCALL_NOCACHE (__PAGE_KERNEL_VSYSCALL | _PAGE_PCD | _PAGE_PWT)
9371+#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
9372+#define __PAGE_KERNEL_VSYSCALL_NOCACHE (__PAGE_KERNEL_RO | _PAGE_PCD | _PAGE_PWT | _PAGE_USER)
9373 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
9374 #define __PAGE_KERNEL_LARGE_NOCACHE (__PAGE_KERNEL | _PAGE_CACHE_UC | _PAGE_PSE)
9375 #define __PAGE_KERNEL_LARGE_EXEC (__PAGE_KERNEL_EXEC | _PAGE_PSE)
9376@@ -163,8 +166,8 @@
9377 * bits are combined, this will alow user to access the high address mapped
9378 * VDSO in the presence of CONFIG_COMPAT_VDSO
9379 */
9380-#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
9381-#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
9382+#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
9383+#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
9384 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
9385 #endif
9386
9387@@ -202,7 +205,17 @@ static inline pgdval_t pgd_flags(pgd_t p
9388 {
9389 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
9390 }
9391+#endif
9392
9393+#if PAGETABLE_LEVELS == 3
9394+#include <asm-generic/pgtable-nopud.h>
9395+#endif
9396+
9397+#if PAGETABLE_LEVELS == 2
9398+#include <asm-generic/pgtable-nopmd.h>
9399+#endif
9400+
9401+#ifndef __ASSEMBLY__
9402 #if PAGETABLE_LEVELS > 3
9403 typedef struct { pudval_t pud; } pud_t;
9404
9405@@ -216,8 +229,6 @@ static inline pudval_t native_pud_val(pu
9406 return pud.pud;
9407 }
9408 #else
9409-#include <asm-generic/pgtable-nopud.h>
9410-
9411 static inline pudval_t native_pud_val(pud_t pud)
9412 {
9413 return native_pgd_val(pud.pgd);
9414@@ -237,8 +248,6 @@ static inline pmdval_t native_pmd_val(pm
9415 return pmd.pmd;
9416 }
9417 #else
9418-#include <asm-generic/pgtable-nopmd.h>
9419-
9420 static inline pmdval_t native_pmd_val(pmd_t pmd)
9421 {
9422 return native_pgd_val(pmd.pud.pgd);
9423@@ -278,7 +287,16 @@ typedef struct page *pgtable_t;
9424
9425 extern pteval_t __supported_pte_mask;
9426 extern void set_nx(void);
9427+
9428+#ifdef CONFIG_X86_32
9429+#ifdef CONFIG_X86_PAE
9430 extern int nx_enabled;
9431+#else
9432+#define nx_enabled (0)
9433+#endif
9434+#else
9435+#define nx_enabled (1)
9436+#endif
9437
9438 #define pgprot_writecombine pgprot_writecombine
9439 extern pgprot_t pgprot_writecombine(pgprot_t prot);
9440diff -urNp linux-2.6.32.41/arch/x86/include/asm/processor.h linux-2.6.32.41/arch/x86/include/asm/processor.h
9441--- linux-2.6.32.41/arch/x86/include/asm/processor.h 2011-04-22 19:16:29.000000000 -0400
9442+++ linux-2.6.32.41/arch/x86/include/asm/processor.h 2011-05-11 18:25:15.000000000 -0400
9443@@ -272,7 +272,7 @@ struct tss_struct {
9444
9445 } ____cacheline_aligned;
9446
9447-DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
9448+extern struct tss_struct init_tss[NR_CPUS];
9449
9450 /*
9451 * Save the original ist values for checking stack pointers during debugging
9452@@ -888,11 +888,18 @@ static inline void spin_lock_prefetch(co
9453 */
9454 #define TASK_SIZE PAGE_OFFSET
9455 #define TASK_SIZE_MAX TASK_SIZE
9456+
9457+#ifdef CONFIG_PAX_SEGMEXEC
9458+#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
9459+#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
9460+#else
9461 #define STACK_TOP TASK_SIZE
9462-#define STACK_TOP_MAX STACK_TOP
9463+#endif
9464+
9465+#define STACK_TOP_MAX TASK_SIZE
9466
9467 #define INIT_THREAD { \
9468- .sp0 = sizeof(init_stack) + (long)&init_stack, \
9469+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
9470 .vm86_info = NULL, \
9471 .sysenter_cs = __KERNEL_CS, \
9472 .io_bitmap_ptr = NULL, \
9473@@ -906,7 +913,7 @@ static inline void spin_lock_prefetch(co
9474 */
9475 #define INIT_TSS { \
9476 .x86_tss = { \
9477- .sp0 = sizeof(init_stack) + (long)&init_stack, \
9478+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
9479 .ss0 = __KERNEL_DS, \
9480 .ss1 = __KERNEL_CS, \
9481 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
9482@@ -917,11 +924,7 @@ static inline void spin_lock_prefetch(co
9483 extern unsigned long thread_saved_pc(struct task_struct *tsk);
9484
9485 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
9486-#define KSTK_TOP(info) \
9487-({ \
9488- unsigned long *__ptr = (unsigned long *)(info); \
9489- (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
9490-})
9491+#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
9492
9493 /*
9494 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
9495@@ -936,7 +939,7 @@ extern unsigned long thread_saved_pc(str
9496 #define task_pt_regs(task) \
9497 ({ \
9498 struct pt_regs *__regs__; \
9499- __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
9500+ __regs__ = (struct pt_regs *)((task)->thread.sp0); \
9501 __regs__ - 1; \
9502 })
9503
9504@@ -946,13 +949,13 @@ extern unsigned long thread_saved_pc(str
9505 /*
9506 * User space process size. 47bits minus one guard page.
9507 */
9508-#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
9509+#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
9510
9511 /* This decides where the kernel will search for a free chunk of vm
9512 * space during mmap's.
9513 */
9514 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
9515- 0xc0000000 : 0xFFFFe000)
9516+ 0xc0000000 : 0xFFFFf000)
9517
9518 #define TASK_SIZE (test_thread_flag(TIF_IA32) ? \
9519 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
9520@@ -963,11 +966,11 @@ extern unsigned long thread_saved_pc(str
9521 #define STACK_TOP_MAX TASK_SIZE_MAX
9522
9523 #define INIT_THREAD { \
9524- .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
9525+ .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
9526 }
9527
9528 #define INIT_TSS { \
9529- .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
9530+ .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
9531 }
9532
9533 /*
9534@@ -989,6 +992,10 @@ extern void start_thread(struct pt_regs
9535 */
9536 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
9537
9538+#ifdef CONFIG_PAX_SEGMEXEC
9539+#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
9540+#endif
9541+
9542 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
9543
9544 /* Get/set a process' ability to use the timestamp counter instruction */
9545diff -urNp linux-2.6.32.41/arch/x86/include/asm/ptrace.h linux-2.6.32.41/arch/x86/include/asm/ptrace.h
9546--- linux-2.6.32.41/arch/x86/include/asm/ptrace.h 2011-03-27 14:31:47.000000000 -0400
9547+++ linux-2.6.32.41/arch/x86/include/asm/ptrace.h 2011-04-17 15:56:46.000000000 -0400
9548@@ -151,28 +151,29 @@ static inline unsigned long regs_return_
9549 }
9550
9551 /*
9552- * user_mode_vm(regs) determines whether a register set came from user mode.
9553+ * user_mode(regs) determines whether a register set came from user mode.
9554 * This is true if V8086 mode was enabled OR if the register set was from
9555 * protected mode with RPL-3 CS value. This tricky test checks that with
9556 * one comparison. Many places in the kernel can bypass this full check
9557- * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
9558+ * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
9559+ * be used.
9560 */
9561-static inline int user_mode(struct pt_regs *regs)
9562+static inline int user_mode_novm(struct pt_regs *regs)
9563 {
9564 #ifdef CONFIG_X86_32
9565 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
9566 #else
9567- return !!(regs->cs & 3);
9568+ return !!(regs->cs & SEGMENT_RPL_MASK);
9569 #endif
9570 }
9571
9572-static inline int user_mode_vm(struct pt_regs *regs)
9573+static inline int user_mode(struct pt_regs *regs)
9574 {
9575 #ifdef CONFIG_X86_32
9576 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
9577 USER_RPL;
9578 #else
9579- return user_mode(regs);
9580+ return user_mode_novm(regs);
9581 #endif
9582 }
9583
9584diff -urNp linux-2.6.32.41/arch/x86/include/asm/reboot.h linux-2.6.32.41/arch/x86/include/asm/reboot.h
9585--- linux-2.6.32.41/arch/x86/include/asm/reboot.h 2011-03-27 14:31:47.000000000 -0400
9586+++ linux-2.6.32.41/arch/x86/include/asm/reboot.h 2011-05-22 23:02:03.000000000 -0400
9587@@ -6,19 +6,19 @@
9588 struct pt_regs;
9589
9590 struct machine_ops {
9591- void (*restart)(char *cmd);
9592- void (*halt)(void);
9593- void (*power_off)(void);
9594+ void (* __noreturn restart)(char *cmd);
9595+ void (* __noreturn halt)(void);
9596+ void (* __noreturn power_off)(void);
9597 void (*shutdown)(void);
9598 void (*crash_shutdown)(struct pt_regs *);
9599- void (*emergency_restart)(void);
9600+ void (* __noreturn emergency_restart)(void);
9601 };
9602
9603 extern struct machine_ops machine_ops;
9604
9605 void native_machine_crash_shutdown(struct pt_regs *regs);
9606 void native_machine_shutdown(void);
9607-void machine_real_restart(const unsigned char *code, int length);
9608+void machine_real_restart(const unsigned char *code, unsigned int length) __noreturn;
9609
9610 typedef void (*nmi_shootdown_cb)(int, struct die_args*);
9611 void nmi_shootdown_cpus(nmi_shootdown_cb callback);
9612diff -urNp linux-2.6.32.41/arch/x86/include/asm/rwsem.h linux-2.6.32.41/arch/x86/include/asm/rwsem.h
9613--- linux-2.6.32.41/arch/x86/include/asm/rwsem.h 2011-03-27 14:31:47.000000000 -0400
9614+++ linux-2.6.32.41/arch/x86/include/asm/rwsem.h 2011-04-17 15:56:46.000000000 -0400
9615@@ -118,6 +118,14 @@ static inline void __down_read(struct rw
9616 {
9617 asm volatile("# beginning down_read\n\t"
9618 LOCK_PREFIX _ASM_INC "(%1)\n\t"
9619+
9620+#ifdef CONFIG_PAX_REFCOUNT
9621+ "jno 0f\n"
9622+ LOCK_PREFIX _ASM_DEC "(%1)\n\t"
9623+ "int $4\n0:\n"
9624+ _ASM_EXTABLE(0b, 0b)
9625+#endif
9626+
9627 /* adds 0x00000001, returns the old value */
9628 " jns 1f\n"
9629 " call call_rwsem_down_read_failed\n"
9630@@ -139,6 +147,14 @@ static inline int __down_read_trylock(st
9631 "1:\n\t"
9632 " mov %1,%2\n\t"
9633 " add %3,%2\n\t"
9634+
9635+#ifdef CONFIG_PAX_REFCOUNT
9636+ "jno 0f\n"
9637+ "sub %3,%2\n"
9638+ "int $4\n0:\n"
9639+ _ASM_EXTABLE(0b, 0b)
9640+#endif
9641+
9642 " jle 2f\n\t"
9643 LOCK_PREFIX " cmpxchg %2,%0\n\t"
9644 " jnz 1b\n\t"
9645@@ -160,6 +176,14 @@ static inline void __down_write_nested(s
9646 tmp = RWSEM_ACTIVE_WRITE_BIAS;
9647 asm volatile("# beginning down_write\n\t"
9648 LOCK_PREFIX " xadd %1,(%2)\n\t"
9649+
9650+#ifdef CONFIG_PAX_REFCOUNT
9651+ "jno 0f\n"
9652+ "mov %1,(%2)\n"
9653+ "int $4\n0:\n"
9654+ _ASM_EXTABLE(0b, 0b)
9655+#endif
9656+
9657 /* subtract 0x0000ffff, returns the old value */
9658 " test %1,%1\n\t"
9659 /* was the count 0 before? */
9660@@ -198,6 +222,14 @@ static inline void __up_read(struct rw_s
9661 rwsem_count_t tmp = -RWSEM_ACTIVE_READ_BIAS;
9662 asm volatile("# beginning __up_read\n\t"
9663 LOCK_PREFIX " xadd %1,(%2)\n\t"
9664+
9665+#ifdef CONFIG_PAX_REFCOUNT
9666+ "jno 0f\n"
9667+ "mov %1,(%2)\n"
9668+ "int $4\n0:\n"
9669+ _ASM_EXTABLE(0b, 0b)
9670+#endif
9671+
9672 /* subtracts 1, returns the old value */
9673 " jns 1f\n\t"
9674 " call call_rwsem_wake\n"
9675@@ -216,6 +248,14 @@ static inline void __up_write(struct rw_
9676 rwsem_count_t tmp;
9677 asm volatile("# beginning __up_write\n\t"
9678 LOCK_PREFIX " xadd %1,(%2)\n\t"
9679+
9680+#ifdef CONFIG_PAX_REFCOUNT
9681+ "jno 0f\n"
9682+ "mov %1,(%2)\n"
9683+ "int $4\n0:\n"
9684+ _ASM_EXTABLE(0b, 0b)
9685+#endif
9686+
9687 /* tries to transition
9688 0xffff0001 -> 0x00000000 */
9689 " jz 1f\n"
9690@@ -234,6 +274,14 @@ static inline void __downgrade_write(str
9691 {
9692 asm volatile("# beginning __downgrade_write\n\t"
9693 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
9694+
9695+#ifdef CONFIG_PAX_REFCOUNT
9696+ "jno 0f\n"
9697+ LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
9698+ "int $4\n0:\n"
9699+ _ASM_EXTABLE(0b, 0b)
9700+#endif
9701+
9702 /*
9703 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
9704 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
9705@@ -253,7 +301,15 @@ static inline void __downgrade_write(str
9706 static inline void rwsem_atomic_add(rwsem_count_t delta,
9707 struct rw_semaphore *sem)
9708 {
9709- asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
9710+ asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
9711+
9712+#ifdef CONFIG_PAX_REFCOUNT
9713+ "jno 0f\n"
9714+ LOCK_PREFIX _ASM_SUB "%1,%0\n"
9715+ "int $4\n0:\n"
9716+ _ASM_EXTABLE(0b, 0b)
9717+#endif
9718+
9719 : "+m" (sem->count)
9720 : "er" (delta));
9721 }
9722@@ -266,7 +322,15 @@ static inline rwsem_count_t rwsem_atomic
9723 {
9724 rwsem_count_t tmp = delta;
9725
9726- asm volatile(LOCK_PREFIX "xadd %0,%1"
9727+ asm volatile(LOCK_PREFIX "xadd %0,%1\n"
9728+
9729+#ifdef CONFIG_PAX_REFCOUNT
9730+ "jno 0f\n"
9731+ "mov %0,%1\n"
9732+ "int $4\n0:\n"
9733+ _ASM_EXTABLE(0b, 0b)
9734+#endif
9735+
9736 : "+r" (tmp), "+m" (sem->count)
9737 : : "memory");
9738
9739diff -urNp linux-2.6.32.41/arch/x86/include/asm/segment.h linux-2.6.32.41/arch/x86/include/asm/segment.h
9740--- linux-2.6.32.41/arch/x86/include/asm/segment.h 2011-03-27 14:31:47.000000000 -0400
9741+++ linux-2.6.32.41/arch/x86/include/asm/segment.h 2011-04-17 15:56:46.000000000 -0400
9742@@ -62,8 +62,8 @@
9743 * 26 - ESPFIX small SS
9744 * 27 - per-cpu [ offset to per-cpu data area ]
9745 * 28 - stack_canary-20 [ for stack protector ]
9746- * 29 - unused
9747- * 30 - unused
9748+ * 29 - PCI BIOS CS
9749+ * 30 - PCI BIOS DS
9750 * 31 - TSS for double fault handler
9751 */
9752 #define GDT_ENTRY_TLS_MIN 6
9753@@ -77,6 +77,8 @@
9754
9755 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE + 0)
9756
9757+#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
9758+
9759 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE + 1)
9760
9761 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE + 4)
9762@@ -88,7 +90,7 @@
9763 #define GDT_ENTRY_ESPFIX_SS (GDT_ENTRY_KERNEL_BASE + 14)
9764 #define __ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)
9765
9766-#define GDT_ENTRY_PERCPU (GDT_ENTRY_KERNEL_BASE + 15)
9767+#define GDT_ENTRY_PERCPU (GDT_ENTRY_KERNEL_BASE + 15)
9768 #ifdef CONFIG_SMP
9769 #define __KERNEL_PERCPU (GDT_ENTRY_PERCPU * 8)
9770 #else
9771@@ -102,6 +104,12 @@
9772 #define __KERNEL_STACK_CANARY 0
9773 #endif
9774
9775+#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE + 17)
9776+#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
9777+
9778+#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE + 18)
9779+#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
9780+
9781 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
9782
9783 /*
9784@@ -139,7 +147,7 @@
9785 */
9786
9787 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
9788-#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
9789+#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
9790
9791
9792 #else
9793@@ -163,6 +171,8 @@
9794 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS * 8 + 3)
9795 #define __USER32_DS __USER_DS
9796
9797+#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
9798+
9799 #define GDT_ENTRY_TSS 8 /* needs two entries */
9800 #define GDT_ENTRY_LDT 10 /* needs two entries */
9801 #define GDT_ENTRY_TLS_MIN 12
9802@@ -183,6 +193,7 @@
9803 #endif
9804
9805 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS * 8)
9806+#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS * 8)
9807 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS * 8)
9808 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS* 8 + 3)
9809 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS* 8 + 3)
9810diff -urNp linux-2.6.32.41/arch/x86/include/asm/smp.h linux-2.6.32.41/arch/x86/include/asm/smp.h
9811--- linux-2.6.32.41/arch/x86/include/asm/smp.h 2011-03-27 14:31:47.000000000 -0400
9812+++ linux-2.6.32.41/arch/x86/include/asm/smp.h 2011-04-17 15:56:46.000000000 -0400
9813@@ -24,7 +24,7 @@ extern unsigned int num_processors;
9814 DECLARE_PER_CPU(cpumask_var_t, cpu_sibling_map);
9815 DECLARE_PER_CPU(cpumask_var_t, cpu_core_map);
9816 DECLARE_PER_CPU(u16, cpu_llc_id);
9817-DECLARE_PER_CPU(int, cpu_number);
9818+DECLARE_PER_CPU(unsigned int, cpu_number);
9819
9820 static inline struct cpumask *cpu_sibling_mask(int cpu)
9821 {
9822@@ -175,14 +175,8 @@ extern unsigned disabled_cpus __cpuinitd
9823 extern int safe_smp_processor_id(void);
9824
9825 #elif defined(CONFIG_X86_64_SMP)
9826-#define raw_smp_processor_id() (percpu_read(cpu_number))
9827-
9828-#define stack_smp_processor_id() \
9829-({ \
9830- struct thread_info *ti; \
9831- __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
9832- ti->cpu; \
9833-})
9834+#define raw_smp_processor_id() (percpu_read(cpu_number))
9835+#define stack_smp_processor_id() raw_smp_processor_id()
9836 #define safe_smp_processor_id() smp_processor_id()
9837
9838 #endif
9839diff -urNp linux-2.6.32.41/arch/x86/include/asm/spinlock.h linux-2.6.32.41/arch/x86/include/asm/spinlock.h
9840--- linux-2.6.32.41/arch/x86/include/asm/spinlock.h 2011-03-27 14:31:47.000000000 -0400
9841+++ linux-2.6.32.41/arch/x86/include/asm/spinlock.h 2011-04-17 15:56:46.000000000 -0400
9842@@ -249,6 +249,14 @@ static inline int __raw_write_can_lock(r
9843 static inline void __raw_read_lock(raw_rwlock_t *rw)
9844 {
9845 asm volatile(LOCK_PREFIX " subl $1,(%0)\n\t"
9846+
9847+#ifdef CONFIG_PAX_REFCOUNT
9848+ "jno 0f\n"
9849+ LOCK_PREFIX " addl $1,(%0)\n"
9850+ "int $4\n0:\n"
9851+ _ASM_EXTABLE(0b, 0b)
9852+#endif
9853+
9854 "jns 1f\n"
9855 "call __read_lock_failed\n\t"
9856 "1:\n"
9857@@ -258,6 +266,14 @@ static inline void __raw_read_lock(raw_r
9858 static inline void __raw_write_lock(raw_rwlock_t *rw)
9859 {
9860 asm volatile(LOCK_PREFIX " subl %1,(%0)\n\t"
9861+
9862+#ifdef CONFIG_PAX_REFCOUNT
9863+ "jno 0f\n"
9864+ LOCK_PREFIX " addl %1,(%0)\n"
9865+ "int $4\n0:\n"
9866+ _ASM_EXTABLE(0b, 0b)
9867+#endif
9868+
9869 "jz 1f\n"
9870 "call __write_lock_failed\n\t"
9871 "1:\n"
9872@@ -286,12 +302,29 @@ static inline int __raw_write_trylock(ra
9873
9874 static inline void __raw_read_unlock(raw_rwlock_t *rw)
9875 {
9876- asm volatile(LOCK_PREFIX "incl %0" :"+m" (rw->lock) : : "memory");
9877+ asm volatile(LOCK_PREFIX "incl %0\n"
9878+
9879+#ifdef CONFIG_PAX_REFCOUNT
9880+ "jno 0f\n"
9881+ LOCK_PREFIX "decl %0\n"
9882+ "int $4\n0:\n"
9883+ _ASM_EXTABLE(0b, 0b)
9884+#endif
9885+
9886+ :"+m" (rw->lock) : : "memory");
9887 }
9888
9889 static inline void __raw_write_unlock(raw_rwlock_t *rw)
9890 {
9891- asm volatile(LOCK_PREFIX "addl %1, %0"
9892+ asm volatile(LOCK_PREFIX "addl %1, %0\n"
9893+
9894+#ifdef CONFIG_PAX_REFCOUNT
9895+ "jno 0f\n"
9896+ LOCK_PREFIX "subl %1, %0\n"
9897+ "int $4\n0:\n"
9898+ _ASM_EXTABLE(0b, 0b)
9899+#endif
9900+
9901 : "+m" (rw->lock) : "i" (RW_LOCK_BIAS) : "memory");
9902 }
9903
9904diff -urNp linux-2.6.32.41/arch/x86/include/asm/stackprotector.h linux-2.6.32.41/arch/x86/include/asm/stackprotector.h
9905--- linux-2.6.32.41/arch/x86/include/asm/stackprotector.h 2011-03-27 14:31:47.000000000 -0400
9906+++ linux-2.6.32.41/arch/x86/include/asm/stackprotector.h 2011-04-17 15:56:46.000000000 -0400
9907@@ -113,7 +113,7 @@ static inline void setup_stack_canary_se
9908
9909 static inline void load_stack_canary_segment(void)
9910 {
9911-#ifdef CONFIG_X86_32
9912+#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
9913 asm volatile ("mov %0, %%gs" : : "r" (0));
9914 #endif
9915 }
9916diff -urNp linux-2.6.32.41/arch/x86/include/asm/system.h linux-2.6.32.41/arch/x86/include/asm/system.h
9917--- linux-2.6.32.41/arch/x86/include/asm/system.h 2011-03-27 14:31:47.000000000 -0400
9918+++ linux-2.6.32.41/arch/x86/include/asm/system.h 2011-05-22 23:02:03.000000000 -0400
9919@@ -132,7 +132,7 @@ do { \
9920 "thread_return:\n\t" \
9921 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
9922 __switch_canary \
9923- "movq %P[thread_info](%%rsi),%%r8\n\t" \
9924+ "movq "__percpu_arg([thread_info])",%%r8\n\t" \
9925 "movq %%rax,%%rdi\n\t" \
9926 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
9927 "jnz ret_from_fork\n\t" \
9928@@ -143,7 +143,7 @@ do { \
9929 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
9930 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
9931 [_tif_fork] "i" (_TIF_FORK), \
9932- [thread_info] "i" (offsetof(struct task_struct, stack)), \
9933+ [thread_info] "m" (per_cpu_var(current_tinfo)), \
9934 [current_task] "m" (per_cpu_var(current_task)) \
9935 __switch_canary_iparam \
9936 : "memory", "cc" __EXTRA_CLOBBER)
9937@@ -200,7 +200,7 @@ static inline unsigned long get_limit(un
9938 {
9939 unsigned long __limit;
9940 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
9941- return __limit + 1;
9942+ return __limit;
9943 }
9944
9945 static inline void native_clts(void)
9946@@ -340,12 +340,12 @@ void enable_hlt(void);
9947
9948 void cpu_idle_wait(void);
9949
9950-extern unsigned long arch_align_stack(unsigned long sp);
9951+#define arch_align_stack(x) ((x) & ~0xfUL)
9952 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
9953
9954 void default_idle(void);
9955
9956-void stop_this_cpu(void *dummy);
9957+void stop_this_cpu(void *dummy) __noreturn;
9958
9959 /*
9960 * Force strict CPU ordering.
9961diff -urNp linux-2.6.32.41/arch/x86/include/asm/thread_info.h linux-2.6.32.41/arch/x86/include/asm/thread_info.h
9962--- linux-2.6.32.41/arch/x86/include/asm/thread_info.h 2011-03-27 14:31:47.000000000 -0400
9963+++ linux-2.6.32.41/arch/x86/include/asm/thread_info.h 2011-05-17 19:26:34.000000000 -0400
9964@@ -10,6 +10,7 @@
9965 #include <linux/compiler.h>
9966 #include <asm/page.h>
9967 #include <asm/types.h>
9968+#include <asm/percpu.h>
9969
9970 /*
9971 * low level task data that entry.S needs immediate access to
9972@@ -24,7 +25,6 @@ struct exec_domain;
9973 #include <asm/atomic.h>
9974
9975 struct thread_info {
9976- struct task_struct *task; /* main task structure */
9977 struct exec_domain *exec_domain; /* execution domain */
9978 __u32 flags; /* low level flags */
9979 __u32 status; /* thread synchronous flags */
9980@@ -34,18 +34,12 @@ struct thread_info {
9981 mm_segment_t addr_limit;
9982 struct restart_block restart_block;
9983 void __user *sysenter_return;
9984-#ifdef CONFIG_X86_32
9985- unsigned long previous_esp; /* ESP of the previous stack in
9986- case of nested (IRQ) stacks
9987- */
9988- __u8 supervisor_stack[0];
9989-#endif
9990+ unsigned long lowest_stack;
9991 int uaccess_err;
9992 };
9993
9994-#define INIT_THREAD_INFO(tsk) \
9995+#define INIT_THREAD_INFO \
9996 { \
9997- .task = &tsk, \
9998 .exec_domain = &default_exec_domain, \
9999 .flags = 0, \
10000 .cpu = 0, \
10001@@ -56,7 +50,7 @@ struct thread_info {
10002 }, \
10003 }
10004
10005-#define init_thread_info (init_thread_union.thread_info)
10006+#define init_thread_info (init_thread_union.stack)
10007 #define init_stack (init_thread_union.stack)
10008
10009 #else /* !__ASSEMBLY__ */
10010@@ -163,6 +157,23 @@ struct thread_info {
10011 #define alloc_thread_info(tsk) \
10012 ((struct thread_info *)__get_free_pages(THREAD_FLAGS, THREAD_ORDER))
10013
10014+#ifdef __ASSEMBLY__
10015+/* how to get the thread information struct from ASM */
10016+#define GET_THREAD_INFO(reg) \
10017+ mov PER_CPU_VAR(current_tinfo), reg
10018+
10019+/* use this one if reg already contains %esp */
10020+#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
10021+#else
10022+/* how to get the thread information struct from C */
10023+DECLARE_PER_CPU(struct thread_info *, current_tinfo);
10024+
10025+static __always_inline struct thread_info *current_thread_info(void)
10026+{
10027+ return percpu_read_stable(current_tinfo);
10028+}
10029+#endif
10030+
10031 #ifdef CONFIG_X86_32
10032
10033 #define STACK_WARN (THREAD_SIZE/8)
10034@@ -173,35 +184,13 @@ struct thread_info {
10035 */
10036 #ifndef __ASSEMBLY__
10037
10038-
10039 /* how to get the current stack pointer from C */
10040 register unsigned long current_stack_pointer asm("esp") __used;
10041
10042-/* how to get the thread information struct from C */
10043-static inline struct thread_info *current_thread_info(void)
10044-{
10045- return (struct thread_info *)
10046- (current_stack_pointer & ~(THREAD_SIZE - 1));
10047-}
10048-
10049-#else /* !__ASSEMBLY__ */
10050-
10051-/* how to get the thread information struct from ASM */
10052-#define GET_THREAD_INFO(reg) \
10053- movl $-THREAD_SIZE, reg; \
10054- andl %esp, reg
10055-
10056-/* use this one if reg already contains %esp */
10057-#define GET_THREAD_INFO_WITH_ESP(reg) \
10058- andl $-THREAD_SIZE, reg
10059-
10060 #endif
10061
10062 #else /* X86_32 */
10063
10064-#include <asm/percpu.h>
10065-#define KERNEL_STACK_OFFSET (5*8)
10066-
10067 /*
10068 * macros/functions for gaining access to the thread information structure
10069 * preempt_count needs to be 1 initially, until the scheduler is functional.
10070@@ -209,21 +198,8 @@ static inline struct thread_info *curren
10071 #ifndef __ASSEMBLY__
10072 DECLARE_PER_CPU(unsigned long, kernel_stack);
10073
10074-static inline struct thread_info *current_thread_info(void)
10075-{
10076- struct thread_info *ti;
10077- ti = (void *)(percpu_read_stable(kernel_stack) +
10078- KERNEL_STACK_OFFSET - THREAD_SIZE);
10079- return ti;
10080-}
10081-
10082-#else /* !__ASSEMBLY__ */
10083-
10084-/* how to get the thread information struct from ASM */
10085-#define GET_THREAD_INFO(reg) \
10086- movq PER_CPU_VAR(kernel_stack),reg ; \
10087- subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
10088-
10089+/* how to get the current stack pointer from C */
10090+register unsigned long current_stack_pointer asm("rsp") __used;
10091 #endif
10092
10093 #endif /* !X86_32 */
10094@@ -260,5 +236,16 @@ extern void arch_task_cache_init(void);
10095 extern void free_thread_info(struct thread_info *ti);
10096 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
10097 #define arch_task_cache_init arch_task_cache_init
10098+
10099+#define __HAVE_THREAD_FUNCTIONS
10100+#define task_thread_info(task) (&(task)->tinfo)
10101+#define task_stack_page(task) ((task)->stack)
10102+#define setup_thread_stack(p, org) do {} while (0)
10103+#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
10104+
10105+#define __HAVE_ARCH_TASK_STRUCT_ALLOCATOR
10106+extern struct task_struct *alloc_task_struct(void);
10107+extern void free_task_struct(struct task_struct *);
10108+
10109 #endif
10110 #endif /* _ASM_X86_THREAD_INFO_H */
10111diff -urNp linux-2.6.32.41/arch/x86/include/asm/uaccess_32.h linux-2.6.32.41/arch/x86/include/asm/uaccess_32.h
10112--- linux-2.6.32.41/arch/x86/include/asm/uaccess_32.h 2011-03-27 14:31:47.000000000 -0400
10113+++ linux-2.6.32.41/arch/x86/include/asm/uaccess_32.h 2011-05-16 21:46:57.000000000 -0400
10114@@ -44,6 +44,11 @@ unsigned long __must_check __copy_from_u
10115 static __always_inline unsigned long __must_check
10116 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
10117 {
10118+ pax_track_stack();
10119+
10120+ if ((long)n < 0)
10121+ return n;
10122+
10123 if (__builtin_constant_p(n)) {
10124 unsigned long ret;
10125
10126@@ -62,6 +67,8 @@ __copy_to_user_inatomic(void __user *to,
10127 return ret;
10128 }
10129 }
10130+ if (!__builtin_constant_p(n))
10131+ check_object_size(from, n, true);
10132 return __copy_to_user_ll(to, from, n);
10133 }
10134
10135@@ -83,12 +90,16 @@ static __always_inline unsigned long __m
10136 __copy_to_user(void __user *to, const void *from, unsigned long n)
10137 {
10138 might_fault();
10139+
10140 return __copy_to_user_inatomic(to, from, n);
10141 }
10142
10143 static __always_inline unsigned long
10144 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
10145 {
10146+ if ((long)n < 0)
10147+ return n;
10148+
10149 /* Avoid zeroing the tail if the copy fails..
10150 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
10151 * but as the zeroing behaviour is only significant when n is not
10152@@ -138,6 +149,12 @@ static __always_inline unsigned long
10153 __copy_from_user(void *to, const void __user *from, unsigned long n)
10154 {
10155 might_fault();
10156+
10157+ pax_track_stack();
10158+
10159+ if ((long)n < 0)
10160+ return n;
10161+
10162 if (__builtin_constant_p(n)) {
10163 unsigned long ret;
10164
10165@@ -153,6 +170,8 @@ __copy_from_user(void *to, const void __
10166 return ret;
10167 }
10168 }
10169+ if (!__builtin_constant_p(n))
10170+ check_object_size(to, n, false);
10171 return __copy_from_user_ll(to, from, n);
10172 }
10173
10174@@ -160,6 +179,10 @@ static __always_inline unsigned long __c
10175 const void __user *from, unsigned long n)
10176 {
10177 might_fault();
10178+
10179+ if ((long)n < 0)
10180+ return n;
10181+
10182 if (__builtin_constant_p(n)) {
10183 unsigned long ret;
10184
10185@@ -182,14 +205,62 @@ static __always_inline unsigned long
10186 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
10187 unsigned long n)
10188 {
10189- return __copy_from_user_ll_nocache_nozero(to, from, n);
10190+ if ((long)n < 0)
10191+ return n;
10192+
10193+ return __copy_from_user_ll_nocache_nozero(to, from, n);
10194+}
10195+
10196+/**
10197+ * copy_to_user: - Copy a block of data into user space.
10198+ * @to: Destination address, in user space.
10199+ * @from: Source address, in kernel space.
10200+ * @n: Number of bytes to copy.
10201+ *
10202+ * Context: User context only. This function may sleep.
10203+ *
10204+ * Copy data from kernel space to user space.
10205+ *
10206+ * Returns number of bytes that could not be copied.
10207+ * On success, this will be zero.
10208+ */
10209+static __always_inline unsigned long __must_check
10210+copy_to_user(void __user *to, const void *from, unsigned long n)
10211+{
10212+ if (access_ok(VERIFY_WRITE, to, n))
10213+ n = __copy_to_user(to, from, n);
10214+ return n;
10215+}
10216+
10217+/**
10218+ * copy_from_user: - Copy a block of data from user space.
10219+ * @to: Destination address, in kernel space.
10220+ * @from: Source address, in user space.
10221+ * @n: Number of bytes to copy.
10222+ *
10223+ * Context: User context only. This function may sleep.
10224+ *
10225+ * Copy data from user space to kernel space.
10226+ *
10227+ * Returns number of bytes that could not be copied.
10228+ * On success, this will be zero.
10229+ *
10230+ * If some data could not be copied, this function will pad the copied
10231+ * data to the requested size using zero bytes.
10232+ */
10233+static __always_inline unsigned long __must_check
10234+copy_from_user(void *to, const void __user *from, unsigned long n)
10235+{
10236+ if (access_ok(VERIFY_READ, from, n))
10237+ n = __copy_from_user(to, from, n);
10238+ else if ((long)n > 0) {
10239+ if (!__builtin_constant_p(n))
10240+ check_object_size(to, n, false);
10241+ memset(to, 0, n);
10242+ }
10243+ return n;
10244 }
10245
10246-unsigned long __must_check copy_to_user(void __user *to,
10247- const void *from, unsigned long n);
10248-unsigned long __must_check copy_from_user(void *to,
10249- const void __user *from,
10250- unsigned long n);
10251 long __must_check strncpy_from_user(char *dst, const char __user *src,
10252 long count);
10253 long __must_check __strncpy_from_user(char *dst,
10254diff -urNp linux-2.6.32.41/arch/x86/include/asm/uaccess_64.h linux-2.6.32.41/arch/x86/include/asm/uaccess_64.h
10255--- linux-2.6.32.41/arch/x86/include/asm/uaccess_64.h 2011-03-27 14:31:47.000000000 -0400
10256+++ linux-2.6.32.41/arch/x86/include/asm/uaccess_64.h 2011-05-16 21:46:57.000000000 -0400
10257@@ -9,6 +9,9 @@
10258 #include <linux/prefetch.h>
10259 #include <linux/lockdep.h>
10260 #include <asm/page.h>
10261+#include <asm/pgtable.h>
10262+
10263+#define set_fs(x) (current_thread_info()->addr_limit = (x))
10264
10265 /*
10266 * Copy To/From Userspace
10267@@ -19,113 +22,203 @@ __must_check unsigned long
10268 copy_user_generic(void *to, const void *from, unsigned len);
10269
10270 __must_check unsigned long
10271-copy_to_user(void __user *to, const void *from, unsigned len);
10272-__must_check unsigned long
10273-copy_from_user(void *to, const void __user *from, unsigned len);
10274-__must_check unsigned long
10275 copy_in_user(void __user *to, const void __user *from, unsigned len);
10276
10277 static __always_inline __must_check
10278-int __copy_from_user(void *dst, const void __user *src, unsigned size)
10279+unsigned long __copy_from_user(void *dst, const void __user *src, unsigned size)
10280 {
10281- int ret = 0;
10282+ unsigned ret = 0;
10283
10284 might_fault();
10285- if (!__builtin_constant_p(size))
10286- return copy_user_generic(dst, (__force void *)src, size);
10287+
10288+ if ((int)size < 0)
10289+ return size;
10290+
10291+#ifdef CONFIG_PAX_MEMORY_UDEREF
10292+ if (!__access_ok(VERIFY_READ, src, size))
10293+ return size;
10294+#endif
10295+
10296+ if (!__builtin_constant_p(size)) {
10297+ check_object_size(dst, size, false);
10298+
10299+#ifdef CONFIG_PAX_MEMORY_UDEREF
10300+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
10301+ src += PAX_USER_SHADOW_BASE;
10302+#endif
10303+
10304+ return copy_user_generic(dst, (__force const void *)src, size);
10305+ }
10306 switch (size) {
10307- case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
10308+ case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
10309 ret, "b", "b", "=q", 1);
10310 return ret;
10311- case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
10312+ case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
10313 ret, "w", "w", "=r", 2);
10314 return ret;
10315- case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
10316+ case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
10317 ret, "l", "k", "=r", 4);
10318 return ret;
10319- case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
10320+ case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
10321 ret, "q", "", "=r", 8);
10322 return ret;
10323 case 10:
10324- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
10325+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
10326 ret, "q", "", "=r", 10);
10327 if (unlikely(ret))
10328 return ret;
10329 __get_user_asm(*(u16 *)(8 + (char *)dst),
10330- (u16 __user *)(8 + (char __user *)src),
10331+ (const u16 __user *)(8 + (const char __user *)src),
10332 ret, "w", "w", "=r", 2);
10333 return ret;
10334 case 16:
10335- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
10336+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
10337 ret, "q", "", "=r", 16);
10338 if (unlikely(ret))
10339 return ret;
10340 __get_user_asm(*(u64 *)(8 + (char *)dst),
10341- (u64 __user *)(8 + (char __user *)src),
10342+ (const u64 __user *)(8 + (const char __user *)src),
10343 ret, "q", "", "=r", 8);
10344 return ret;
10345 default:
10346- return copy_user_generic(dst, (__force void *)src, size);
10347+
10348+#ifdef CONFIG_PAX_MEMORY_UDEREF
10349+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
10350+ src += PAX_USER_SHADOW_BASE;
10351+#endif
10352+
10353+ return copy_user_generic(dst, (__force const void *)src, size);
10354 }
10355 }
10356
10357 static __always_inline __must_check
10358-int __copy_to_user(void __user *dst, const void *src, unsigned size)
10359+unsigned long __copy_to_user(void __user *dst, const void *src, unsigned size)
10360 {
10361- int ret = 0;
10362+ unsigned ret = 0;
10363
10364 might_fault();
10365- if (!__builtin_constant_p(size))
10366+
10367+ pax_track_stack();
10368+
10369+ if ((int)size < 0)
10370+ return size;
10371+
10372+#ifdef CONFIG_PAX_MEMORY_UDEREF
10373+ if (!__access_ok(VERIFY_WRITE, dst, size))
10374+ return size;
10375+#endif
10376+
10377+ if (!__builtin_constant_p(size)) {
10378+ check_object_size(src, size, true);
10379+
10380+#ifdef CONFIG_PAX_MEMORY_UDEREF
10381+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
10382+ dst += PAX_USER_SHADOW_BASE;
10383+#endif
10384+
10385 return copy_user_generic((__force void *)dst, src, size);
10386+ }
10387 switch (size) {
10388- case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
10389+ case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
10390 ret, "b", "b", "iq", 1);
10391 return ret;
10392- case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
10393+ case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
10394 ret, "w", "w", "ir", 2);
10395 return ret;
10396- case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
10397+ case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
10398 ret, "l", "k", "ir", 4);
10399 return ret;
10400- case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
10401+ case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
10402 ret, "q", "", "er", 8);
10403 return ret;
10404 case 10:
10405- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
10406+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
10407 ret, "q", "", "er", 10);
10408 if (unlikely(ret))
10409 return ret;
10410 asm("":::"memory");
10411- __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
10412+ __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
10413 ret, "w", "w", "ir", 2);
10414 return ret;
10415 case 16:
10416- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
10417+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
10418 ret, "q", "", "er", 16);
10419 if (unlikely(ret))
10420 return ret;
10421 asm("":::"memory");
10422- __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
10423+ __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
10424 ret, "q", "", "er", 8);
10425 return ret;
10426 default:
10427+
10428+#ifdef CONFIG_PAX_MEMORY_UDEREF
10429+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
10430+ dst += PAX_USER_SHADOW_BASE;
10431+#endif
10432+
10433 return copy_user_generic((__force void *)dst, src, size);
10434 }
10435 }
10436
10437 static __always_inline __must_check
10438-int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
10439+unsigned long copy_to_user(void __user *to, const void *from, unsigned len)
10440+{
10441+ if (access_ok(VERIFY_WRITE, to, len))
10442+ len = __copy_to_user(to, from, len);
10443+ return len;
10444+}
10445+
10446+static __always_inline __must_check
10447+unsigned long copy_from_user(void *to, const void __user *from, unsigned len)
10448+{
10449+ if ((int)len < 0)
10450+ return len;
10451+
10452+ if (access_ok(VERIFY_READ, from, len))
10453+ len = __copy_from_user(to, from, len);
10454+ else if ((int)len > 0) {
10455+ if (!__builtin_constant_p(len))
10456+ check_object_size(to, len, false);
10457+ memset(to, 0, len);
10458+ }
10459+ return len;
10460+}
10461+
10462+static __always_inline __must_check
10463+unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned size)
10464 {
10465- int ret = 0;
10466+ unsigned ret = 0;
10467
10468 might_fault();
10469- if (!__builtin_constant_p(size))
10470+
10471+ pax_track_stack();
10472+
10473+ if ((int)size < 0)
10474+ return size;
10475+
10476+#ifdef CONFIG_PAX_MEMORY_UDEREF
10477+ if (!__access_ok(VERIFY_READ, src, size))
10478+ return size;
10479+ if (!__access_ok(VERIFY_WRITE, dst, size))
10480+ return size;
10481+#endif
10482+
10483+ if (!__builtin_constant_p(size)) {
10484+
10485+#ifdef CONFIG_PAX_MEMORY_UDEREF
10486+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
10487+ src += PAX_USER_SHADOW_BASE;
10488+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
10489+ dst += PAX_USER_SHADOW_BASE;
10490+#endif
10491+
10492 return copy_user_generic((__force void *)dst,
10493- (__force void *)src, size);
10494+ (__force const void *)src, size);
10495+ }
10496 switch (size) {
10497 case 1: {
10498 u8 tmp;
10499- __get_user_asm(tmp, (u8 __user *)src,
10500+ __get_user_asm(tmp, (const u8 __user *)src,
10501 ret, "b", "b", "=q", 1);
10502 if (likely(!ret))
10503 __put_user_asm(tmp, (u8 __user *)dst,
10504@@ -134,7 +227,7 @@ int __copy_in_user(void __user *dst, con
10505 }
10506 case 2: {
10507 u16 tmp;
10508- __get_user_asm(tmp, (u16 __user *)src,
10509+ __get_user_asm(tmp, (const u16 __user *)src,
10510 ret, "w", "w", "=r", 2);
10511 if (likely(!ret))
10512 __put_user_asm(tmp, (u16 __user *)dst,
10513@@ -144,7 +237,7 @@ int __copy_in_user(void __user *dst, con
10514
10515 case 4: {
10516 u32 tmp;
10517- __get_user_asm(tmp, (u32 __user *)src,
10518+ __get_user_asm(tmp, (const u32 __user *)src,
10519 ret, "l", "k", "=r", 4);
10520 if (likely(!ret))
10521 __put_user_asm(tmp, (u32 __user *)dst,
10522@@ -153,7 +246,7 @@ int __copy_in_user(void __user *dst, con
10523 }
10524 case 8: {
10525 u64 tmp;
10526- __get_user_asm(tmp, (u64 __user *)src,
10527+ __get_user_asm(tmp, (const u64 __user *)src,
10528 ret, "q", "", "=r", 8);
10529 if (likely(!ret))
10530 __put_user_asm(tmp, (u64 __user *)dst,
10531@@ -161,8 +254,16 @@ int __copy_in_user(void __user *dst, con
10532 return ret;
10533 }
10534 default:
10535+
10536+#ifdef CONFIG_PAX_MEMORY_UDEREF
10537+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
10538+ src += PAX_USER_SHADOW_BASE;
10539+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
10540+ dst += PAX_USER_SHADOW_BASE;
10541+#endif
10542+
10543 return copy_user_generic((__force void *)dst,
10544- (__force void *)src, size);
10545+ (__force const void *)src, size);
10546 }
10547 }
10548
10549@@ -176,33 +277,75 @@ __must_check long strlen_user(const char
10550 __must_check unsigned long clear_user(void __user *mem, unsigned long len);
10551 __must_check unsigned long __clear_user(void __user *mem, unsigned long len);
10552
10553-__must_check long __copy_from_user_inatomic(void *dst, const void __user *src,
10554- unsigned size);
10555+static __must_check __always_inline unsigned long
10556+__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
10557+{
10558+ pax_track_stack();
10559+
10560+ if ((int)size < 0)
10561+ return size;
10562
10563-static __must_check __always_inline int
10564+#ifdef CONFIG_PAX_MEMORY_UDEREF
10565+ if (!__access_ok(VERIFY_READ, src, size))
10566+ return size;
10567+
10568+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
10569+ src += PAX_USER_SHADOW_BASE;
10570+#endif
10571+
10572+ return copy_user_generic(dst, (__force const void *)src, size);
10573+}
10574+
10575+static __must_check __always_inline unsigned long
10576 __copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
10577 {
10578+ if ((int)size < 0)
10579+ return size;
10580+
10581+#ifdef CONFIG_PAX_MEMORY_UDEREF
10582+ if (!__access_ok(VERIFY_WRITE, dst, size))
10583+ return size;
10584+
10585+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
10586+ dst += PAX_USER_SHADOW_BASE;
10587+#endif
10588+
10589 return copy_user_generic((__force void *)dst, src, size);
10590 }
10591
10592-extern long __copy_user_nocache(void *dst, const void __user *src,
10593+extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
10594 unsigned size, int zerorest);
10595
10596-static inline int
10597-__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
10598+static inline unsigned long __copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
10599 {
10600 might_sleep();
10601+
10602+ if ((int)size < 0)
10603+ return size;
10604+
10605+#ifdef CONFIG_PAX_MEMORY_UDEREF
10606+ if (!__access_ok(VERIFY_READ, src, size))
10607+ return size;
10608+#endif
10609+
10610 return __copy_user_nocache(dst, src, size, 1);
10611 }
10612
10613-static inline int
10614-__copy_from_user_inatomic_nocache(void *dst, const void __user *src,
10615+static inline unsigned long __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
10616 unsigned size)
10617 {
10618+ if ((int)size < 0)
10619+ return size;
10620+
10621+#ifdef CONFIG_PAX_MEMORY_UDEREF
10622+ if (!__access_ok(VERIFY_READ, src, size))
10623+ return size;
10624+#endif
10625+
10626 return __copy_user_nocache(dst, src, size, 0);
10627 }
10628
10629-unsigned long
10630+extern unsigned long
10631 copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
10632
10633 #endif /* _ASM_X86_UACCESS_64_H */
10634diff -urNp linux-2.6.32.41/arch/x86/include/asm/uaccess.h linux-2.6.32.41/arch/x86/include/asm/uaccess.h
10635--- linux-2.6.32.41/arch/x86/include/asm/uaccess.h 2011-03-27 14:31:47.000000000 -0400
10636+++ linux-2.6.32.41/arch/x86/include/asm/uaccess.h 2011-04-17 15:56:46.000000000 -0400
10637@@ -8,12 +8,15 @@
10638 #include <linux/thread_info.h>
10639 #include <linux/prefetch.h>
10640 #include <linux/string.h>
10641+#include <linux/sched.h>
10642 #include <asm/asm.h>
10643 #include <asm/page.h>
10644
10645 #define VERIFY_READ 0
10646 #define VERIFY_WRITE 1
10647
10648+extern void check_object_size(const void *ptr, unsigned long n, bool to);
10649+
10650 /*
10651 * The fs value determines whether argument validity checking should be
10652 * performed or not. If get_fs() == USER_DS, checking is performed, with
10653@@ -29,7 +32,12 @@
10654
10655 #define get_ds() (KERNEL_DS)
10656 #define get_fs() (current_thread_info()->addr_limit)
10657+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
10658+void __set_fs(mm_segment_t x);
10659+void set_fs(mm_segment_t x);
10660+#else
10661 #define set_fs(x) (current_thread_info()->addr_limit = (x))
10662+#endif
10663
10664 #define segment_eq(a, b) ((a).seg == (b).seg)
10665
10666@@ -77,7 +85,33 @@
10667 * checks that the pointer is in the user space range - after calling
10668 * this function, memory access functions may still return -EFAULT.
10669 */
10670-#define access_ok(type, addr, size) (likely(__range_not_ok(addr, size) == 0))
10671+#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size) == 0))
10672+#define access_ok(type, addr, size) \
10673+({ \
10674+ long __size = size; \
10675+ unsigned long __addr = (unsigned long)addr; \
10676+ unsigned long __addr_ao = __addr & PAGE_MASK; \
10677+ unsigned long __end_ao = __addr + __size - 1; \
10678+ bool __ret_ao = __range_not_ok(__addr, __size) == 0; \
10679+ if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
10680+ while(__addr_ao <= __end_ao) { \
10681+ char __c_ao; \
10682+ __addr_ao += PAGE_SIZE; \
10683+ if (__size > PAGE_SIZE) \
10684+ cond_resched(); \
10685+ if (__get_user(__c_ao, (char __user *)__addr)) \
10686+ break; \
10687+ if (type != VERIFY_WRITE) { \
10688+ __addr = __addr_ao; \
10689+ continue; \
10690+ } \
10691+ if (__put_user(__c_ao, (char __user *)__addr)) \
10692+ break; \
10693+ __addr = __addr_ao; \
10694+ } \
10695+ } \
10696+ __ret_ao; \
10697+})
10698
10699 /*
10700 * The exception table consists of pairs of addresses: the first is the
10701@@ -183,12 +217,20 @@ extern int __get_user_bad(void);
10702 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
10703 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
10704
10705-
10706+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
10707+#define __copyuser_seg "gs;"
10708+#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
10709+#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
10710+#else
10711+#define __copyuser_seg
10712+#define __COPYUSER_SET_ES
10713+#define __COPYUSER_RESTORE_ES
10714+#endif
10715
10716 #ifdef CONFIG_X86_32
10717 #define __put_user_asm_u64(x, addr, err, errret) \
10718- asm volatile("1: movl %%eax,0(%2)\n" \
10719- "2: movl %%edx,4(%2)\n" \
10720+ asm volatile("1: "__copyuser_seg"movl %%eax,0(%2)\n" \
10721+ "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
10722 "3:\n" \
10723 ".section .fixup,\"ax\"\n" \
10724 "4: movl %3,%0\n" \
10725@@ -200,8 +242,8 @@ extern int __get_user_bad(void);
10726 : "A" (x), "r" (addr), "i" (errret), "0" (err))
10727
10728 #define __put_user_asm_ex_u64(x, addr) \
10729- asm volatile("1: movl %%eax,0(%1)\n" \
10730- "2: movl %%edx,4(%1)\n" \
10731+ asm volatile("1: "__copyuser_seg"movl %%eax,0(%1)\n" \
10732+ "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
10733 "3:\n" \
10734 _ASM_EXTABLE(1b, 2b - 1b) \
10735 _ASM_EXTABLE(2b, 3b - 2b) \
10736@@ -374,7 +416,7 @@ do { \
10737 } while (0)
10738
10739 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
10740- asm volatile("1: mov"itype" %2,%"rtype"1\n" \
10741+ asm volatile("1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
10742 "2:\n" \
10743 ".section .fixup,\"ax\"\n" \
10744 "3: mov %3,%0\n" \
10745@@ -382,7 +424,7 @@ do { \
10746 " jmp 2b\n" \
10747 ".previous\n" \
10748 _ASM_EXTABLE(1b, 3b) \
10749- : "=r" (err), ltype(x) \
10750+ : "=r" (err), ltype (x) \
10751 : "m" (__m(addr)), "i" (errret), "0" (err))
10752
10753 #define __get_user_size_ex(x, ptr, size) \
10754@@ -407,7 +449,7 @@ do { \
10755 } while (0)
10756
10757 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
10758- asm volatile("1: mov"itype" %1,%"rtype"0\n" \
10759+ asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
10760 "2:\n" \
10761 _ASM_EXTABLE(1b, 2b - 1b) \
10762 : ltype(x) : "m" (__m(addr)))
10763@@ -424,13 +466,24 @@ do { \
10764 int __gu_err; \
10765 unsigned long __gu_val; \
10766 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
10767- (x) = (__force __typeof__(*(ptr)))__gu_val; \
10768+ (x) = (__typeof__(*(ptr)))__gu_val; \
10769 __gu_err; \
10770 })
10771
10772 /* FIXME: this hack is definitely wrong -AK */
10773 struct __large_struct { unsigned long buf[100]; };
10774-#define __m(x) (*(struct __large_struct __user *)(x))
10775+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10776+#define ____m(x) \
10777+({ \
10778+ unsigned long ____x = (unsigned long)(x); \
10779+ if (____x < PAX_USER_SHADOW_BASE) \
10780+ ____x += PAX_USER_SHADOW_BASE; \
10781+ (void __user *)____x; \
10782+})
10783+#else
10784+#define ____m(x) (x)
10785+#endif
10786+#define __m(x) (*(struct __large_struct __user *)____m(x))
10787
10788 /*
10789 * Tell gcc we read from memory instead of writing: this is because
10790@@ -438,7 +491,7 @@ struct __large_struct { unsigned long bu
10791 * aliasing issues.
10792 */
10793 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
10794- asm volatile("1: mov"itype" %"rtype"1,%2\n" \
10795+ asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
10796 "2:\n" \
10797 ".section .fixup,\"ax\"\n" \
10798 "3: mov %3,%0\n" \
10799@@ -446,10 +499,10 @@ struct __large_struct { unsigned long bu
10800 ".previous\n" \
10801 _ASM_EXTABLE(1b, 3b) \
10802 : "=r"(err) \
10803- : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
10804+ : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err))
10805
10806 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
10807- asm volatile("1: mov"itype" %"rtype"0,%1\n" \
10808+ asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
10809 "2:\n" \
10810 _ASM_EXTABLE(1b, 2b - 1b) \
10811 : : ltype(x), "m" (__m(addr)))
10812@@ -488,8 +541,12 @@ struct __large_struct { unsigned long bu
10813 * On error, the variable @x is set to zero.
10814 */
10815
10816+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10817+#define __get_user(x, ptr) get_user((x), (ptr))
10818+#else
10819 #define __get_user(x, ptr) \
10820 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
10821+#endif
10822
10823 /**
10824 * __put_user: - Write a simple value into user space, with less checking.
10825@@ -511,8 +568,12 @@ struct __large_struct { unsigned long bu
10826 * Returns zero on success, or -EFAULT on error.
10827 */
10828
10829+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10830+#define __put_user(x, ptr) put_user((x), (ptr))
10831+#else
10832 #define __put_user(x, ptr) \
10833 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
10834+#endif
10835
10836 #define __get_user_unaligned __get_user
10837 #define __put_user_unaligned __put_user
10838@@ -530,7 +591,7 @@ struct __large_struct { unsigned long bu
10839 #define get_user_ex(x, ptr) do { \
10840 unsigned long __gue_val; \
10841 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
10842- (x) = (__force __typeof__(*(ptr)))__gue_val; \
10843+ (x) = (__typeof__(*(ptr)))__gue_val; \
10844 } while (0)
10845
10846 #ifdef CONFIG_X86_WP_WORKS_OK
10847@@ -567,6 +628,7 @@ extern struct movsl_mask {
10848
10849 #define ARCH_HAS_NOCACHE_UACCESS 1
10850
10851+#define ARCH_HAS_SORT_EXTABLE
10852 #ifdef CONFIG_X86_32
10853 # include "uaccess_32.h"
10854 #else
10855diff -urNp linux-2.6.32.41/arch/x86/include/asm/vgtod.h linux-2.6.32.41/arch/x86/include/asm/vgtod.h
10856--- linux-2.6.32.41/arch/x86/include/asm/vgtod.h 2011-03-27 14:31:47.000000000 -0400
10857+++ linux-2.6.32.41/arch/x86/include/asm/vgtod.h 2011-04-17 15:56:46.000000000 -0400
10858@@ -14,6 +14,7 @@ struct vsyscall_gtod_data {
10859 int sysctl_enabled;
10860 struct timezone sys_tz;
10861 struct { /* extract of a clocksource struct */
10862+ char name[8];
10863 cycle_t (*vread)(void);
10864 cycle_t cycle_last;
10865 cycle_t mask;
10866diff -urNp linux-2.6.32.41/arch/x86/include/asm/vmi.h linux-2.6.32.41/arch/x86/include/asm/vmi.h
10867--- linux-2.6.32.41/arch/x86/include/asm/vmi.h 2011-03-27 14:31:47.000000000 -0400
10868+++ linux-2.6.32.41/arch/x86/include/asm/vmi.h 2011-04-17 15:56:46.000000000 -0400
10869@@ -191,6 +191,7 @@ struct vrom_header {
10870 u8 reserved[96]; /* Reserved for headers */
10871 char vmi_init[8]; /* VMI_Init jump point */
10872 char get_reloc[8]; /* VMI_GetRelocationInfo jump point */
10873+ char rom_data[8048]; /* rest of the option ROM */
10874 } __attribute__((packed));
10875
10876 struct pnp_header {
10877diff -urNp linux-2.6.32.41/arch/x86/include/asm/vsyscall.h linux-2.6.32.41/arch/x86/include/asm/vsyscall.h
10878--- linux-2.6.32.41/arch/x86/include/asm/vsyscall.h 2011-03-27 14:31:47.000000000 -0400
10879+++ linux-2.6.32.41/arch/x86/include/asm/vsyscall.h 2011-04-17 15:56:46.000000000 -0400
10880@@ -15,9 +15,10 @@ enum vsyscall_num {
10881
10882 #ifdef __KERNEL__
10883 #include <linux/seqlock.h>
10884+#include <linux/getcpu.h>
10885+#include <linux/time.h>
10886
10887 #define __section_vgetcpu_mode __attribute__ ((unused, __section__ (".vgetcpu_mode"), aligned(16)))
10888-#define __section_jiffies __attribute__ ((unused, __section__ (".jiffies"), aligned(16)))
10889
10890 /* Definitions for CONFIG_GENERIC_TIME definitions */
10891 #define __section_vsyscall_gtod_data __attribute__ \
10892@@ -31,7 +32,6 @@ enum vsyscall_num {
10893 #define VGETCPU_LSL 2
10894
10895 extern int __vgetcpu_mode;
10896-extern volatile unsigned long __jiffies;
10897
10898 /* kernel space (writeable) */
10899 extern int vgetcpu_mode;
10900@@ -39,6 +39,9 @@ extern struct timezone sys_tz;
10901
10902 extern void map_vsyscall(void);
10903
10904+extern int vgettimeofday(struct timeval * tv, struct timezone * tz);
10905+extern time_t vtime(time_t *t);
10906+extern long vgetcpu(unsigned *cpu, unsigned *node, struct getcpu_cache *tcache);
10907 #endif /* __KERNEL__ */
10908
10909 #endif /* _ASM_X86_VSYSCALL_H */
10910diff -urNp linux-2.6.32.41/arch/x86/include/asm/xsave.h linux-2.6.32.41/arch/x86/include/asm/xsave.h
10911--- linux-2.6.32.41/arch/x86/include/asm/xsave.h 2011-03-27 14:31:47.000000000 -0400
10912+++ linux-2.6.32.41/arch/x86/include/asm/xsave.h 2011-04-17 15:56:46.000000000 -0400
10913@@ -56,6 +56,12 @@ static inline int xrstor_checking(struct
10914 static inline int xsave_user(struct xsave_struct __user *buf)
10915 {
10916 int err;
10917+
10918+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10919+ if ((unsigned long)buf < PAX_USER_SHADOW_BASE)
10920+ buf = (struct xsave_struct __user *)((void __user*)buf + PAX_USER_SHADOW_BASE);
10921+#endif
10922+
10923 __asm__ __volatile__("1: .byte " REX_PREFIX "0x0f,0xae,0x27\n"
10924 "2:\n"
10925 ".section .fixup,\"ax\"\n"
10926@@ -82,6 +88,11 @@ static inline int xrestore_user(struct x
10927 u32 lmask = mask;
10928 u32 hmask = mask >> 32;
10929
10930+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10931+ if ((unsigned long)xstate < PAX_USER_SHADOW_BASE)
10932+ xstate = (struct xsave_struct *)((void *)xstate + PAX_USER_SHADOW_BASE);
10933+#endif
10934+
10935 __asm__ __volatile__("1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
10936 "2:\n"
10937 ".section .fixup,\"ax\"\n"
10938diff -urNp linux-2.6.32.41/arch/x86/Kconfig linux-2.6.32.41/arch/x86/Kconfig
10939--- linux-2.6.32.41/arch/x86/Kconfig 2011-03-27 14:31:47.000000000 -0400
10940+++ linux-2.6.32.41/arch/x86/Kconfig 2011-04-17 15:56:46.000000000 -0400
10941@@ -223,7 +223,7 @@ config X86_TRAMPOLINE
10942
10943 config X86_32_LAZY_GS
10944 def_bool y
10945- depends on X86_32 && !CC_STACKPROTECTOR
10946+ depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
10947
10948 config KTIME_SCALAR
10949 def_bool X86_32
10950@@ -1008,7 +1008,7 @@ choice
10951
10952 config NOHIGHMEM
10953 bool "off"
10954- depends on !X86_NUMAQ
10955+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
10956 ---help---
10957 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
10958 However, the address space of 32-bit x86 processors is only 4
10959@@ -1045,7 +1045,7 @@ config NOHIGHMEM
10960
10961 config HIGHMEM4G
10962 bool "4GB"
10963- depends on !X86_NUMAQ
10964+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
10965 ---help---
10966 Select this if you have a 32-bit processor and between 1 and 4
10967 gigabytes of physical RAM.
10968@@ -1099,7 +1099,7 @@ config PAGE_OFFSET
10969 hex
10970 default 0xB0000000 if VMSPLIT_3G_OPT
10971 default 0x80000000 if VMSPLIT_2G
10972- default 0x78000000 if VMSPLIT_2G_OPT
10973+ default 0x70000000 if VMSPLIT_2G_OPT
10974 default 0x40000000 if VMSPLIT_1G
10975 default 0xC0000000
10976 depends on X86_32
10977@@ -1430,7 +1430,7 @@ config ARCH_USES_PG_UNCACHED
10978
10979 config EFI
10980 bool "EFI runtime service support"
10981- depends on ACPI
10982+ depends on ACPI && !PAX_KERNEXEC
10983 ---help---
10984 This enables the kernel to use EFI runtime services that are
10985 available (such as the EFI variable services).
10986@@ -1460,6 +1460,7 @@ config SECCOMP
10987
10988 config CC_STACKPROTECTOR
10989 bool "Enable -fstack-protector buffer overflow detection (EXPERIMENTAL)"
10990+ depends on X86_64 || !PAX_MEMORY_UDEREF
10991 ---help---
10992 This option turns on the -fstack-protector GCC feature. This
10993 feature puts, at the beginning of functions, a canary value on
10994@@ -1517,6 +1518,7 @@ config KEXEC_JUMP
10995 config PHYSICAL_START
10996 hex "Physical address where the kernel is loaded" if (EMBEDDED || CRASH_DUMP)
10997 default "0x1000000"
10998+ range 0x400000 0x40000000
10999 ---help---
11000 This gives the physical address where the kernel is loaded.
11001
11002@@ -1581,6 +1583,7 @@ config PHYSICAL_ALIGN
11003 hex
11004 prompt "Alignment value to which kernel should be aligned" if X86_32
11005 default "0x1000000"
11006+ range 0x400000 0x1000000 if PAX_KERNEXEC
11007 range 0x2000 0x1000000
11008 ---help---
11009 This value puts the alignment restrictions on physical address
11010@@ -1612,9 +1615,10 @@ config HOTPLUG_CPU
11011 Say N if you want to disable CPU hotplug.
11012
11013 config COMPAT_VDSO
11014- def_bool y
11015+ def_bool n
11016 prompt "Compat VDSO support"
11017 depends on X86_32 || IA32_EMULATION
11018+ depends on !PAX_NOEXEC && !PAX_MEMORY_UDEREF
11019 ---help---
11020 Map the 32-bit VDSO to the predictable old-style address too.
11021 ---help---
11022diff -urNp linux-2.6.32.41/arch/x86/Kconfig.cpu linux-2.6.32.41/arch/x86/Kconfig.cpu
11023--- linux-2.6.32.41/arch/x86/Kconfig.cpu 2011-03-27 14:31:47.000000000 -0400
11024+++ linux-2.6.32.41/arch/x86/Kconfig.cpu 2011-04-17 15:56:46.000000000 -0400
11025@@ -340,7 +340,7 @@ config X86_PPRO_FENCE
11026
11027 config X86_F00F_BUG
11028 def_bool y
11029- depends on M586MMX || M586TSC || M586 || M486 || M386
11030+ depends on (M586MMX || M586TSC || M586 || M486 || M386) && !PAX_KERNEXEC
11031
11032 config X86_WP_WORKS_OK
11033 def_bool y
11034@@ -360,7 +360,7 @@ config X86_POPAD_OK
11035
11036 config X86_ALIGNMENT_16
11037 def_bool y
11038- depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
11039+ depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
11040
11041 config X86_INTEL_USERCOPY
11042 def_bool y
11043@@ -406,7 +406,7 @@ config X86_CMPXCHG64
11044 # generates cmov.
11045 config X86_CMOV
11046 def_bool y
11047- depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM)
11048+ depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM)
11049
11050 config X86_MINIMUM_CPU_FAMILY
11051 int
11052diff -urNp linux-2.6.32.41/arch/x86/Kconfig.debug linux-2.6.32.41/arch/x86/Kconfig.debug
11053--- linux-2.6.32.41/arch/x86/Kconfig.debug 2011-03-27 14:31:47.000000000 -0400
11054+++ linux-2.6.32.41/arch/x86/Kconfig.debug 2011-04-17 15:56:46.000000000 -0400
11055@@ -99,7 +99,7 @@ config X86_PTDUMP
11056 config DEBUG_RODATA
11057 bool "Write protect kernel read-only data structures"
11058 default y
11059- depends on DEBUG_KERNEL
11060+ depends on DEBUG_KERNEL && BROKEN
11061 ---help---
11062 Mark the kernel read-only data as write-protected in the pagetables,
11063 in order to catch accidental (and incorrect) writes to such const
11064diff -urNp linux-2.6.32.41/arch/x86/kernel/acpi/realmode/wakeup.S linux-2.6.32.41/arch/x86/kernel/acpi/realmode/wakeup.S
11065--- linux-2.6.32.41/arch/x86/kernel/acpi/realmode/wakeup.S 2011-03-27 14:31:47.000000000 -0400
11066+++ linux-2.6.32.41/arch/x86/kernel/acpi/realmode/wakeup.S 2011-04-17 15:56:46.000000000 -0400
11067@@ -104,7 +104,7 @@ _start:
11068 movl %eax, %ecx
11069 orl %edx, %ecx
11070 jz 1f
11071- movl $0xc0000080, %ecx
11072+ mov $MSR_EFER, %ecx
11073 wrmsr
11074 1:
11075
11076diff -urNp linux-2.6.32.41/arch/x86/kernel/acpi/sleep.c linux-2.6.32.41/arch/x86/kernel/acpi/sleep.c
11077--- linux-2.6.32.41/arch/x86/kernel/acpi/sleep.c 2011-03-27 14:31:47.000000000 -0400
11078+++ linux-2.6.32.41/arch/x86/kernel/acpi/sleep.c 2011-04-17 15:56:46.000000000 -0400
11079@@ -11,11 +11,12 @@
11080 #include <linux/cpumask.h>
11081 #include <asm/segment.h>
11082 #include <asm/desc.h>
11083+#include <asm/e820.h>
11084
11085 #include "realmode/wakeup.h"
11086 #include "sleep.h"
11087
11088-unsigned long acpi_wakeup_address;
11089+unsigned long acpi_wakeup_address = 0x2000;
11090 unsigned long acpi_realmode_flags;
11091
11092 /* address in low memory of the wakeup routine. */
11093@@ -99,8 +100,12 @@ int acpi_save_state_mem(void)
11094 header->trampoline_segment = setup_trampoline() >> 4;
11095 #ifdef CONFIG_SMP
11096 stack_start.sp = temp_stack + sizeof(temp_stack);
11097+
11098+ pax_open_kernel();
11099 early_gdt_descr.address =
11100 (unsigned long)get_cpu_gdt_table(smp_processor_id());
11101+ pax_close_kernel();
11102+
11103 initial_gs = per_cpu_offset(smp_processor_id());
11104 #endif
11105 initial_code = (unsigned long)wakeup_long64;
11106@@ -134,14 +139,8 @@ void __init acpi_reserve_bootmem(void)
11107 return;
11108 }
11109
11110- acpi_realmode = (unsigned long)alloc_bootmem_low(WAKEUP_SIZE);
11111-
11112- if (!acpi_realmode) {
11113- printk(KERN_ERR "ACPI: Cannot allocate lowmem, S3 disabled.\n");
11114- return;
11115- }
11116-
11117- acpi_wakeup_address = virt_to_phys((void *)acpi_realmode);
11118+ reserve_early(acpi_wakeup_address, acpi_wakeup_address + WAKEUP_SIZE, "ACPI Wakeup Code");
11119+ acpi_realmode = (unsigned long)__va(acpi_wakeup_address);;
11120 }
11121
11122
11123diff -urNp linux-2.6.32.41/arch/x86/kernel/acpi/wakeup_32.S linux-2.6.32.41/arch/x86/kernel/acpi/wakeup_32.S
11124--- linux-2.6.32.41/arch/x86/kernel/acpi/wakeup_32.S 2011-03-27 14:31:47.000000000 -0400
11125+++ linux-2.6.32.41/arch/x86/kernel/acpi/wakeup_32.S 2011-04-17 15:56:46.000000000 -0400
11126@@ -30,13 +30,11 @@ wakeup_pmode_return:
11127 # and restore the stack ... but you need gdt for this to work
11128 movl saved_context_esp, %esp
11129
11130- movl %cs:saved_magic, %eax
11131- cmpl $0x12345678, %eax
11132+ cmpl $0x12345678, saved_magic
11133 jne bogus_magic
11134
11135 # jump to place where we left off
11136- movl saved_eip, %eax
11137- jmp *%eax
11138+ jmp *(saved_eip)
11139
11140 bogus_magic:
11141 jmp bogus_magic
11142diff -urNp linux-2.6.32.41/arch/x86/kernel/alternative.c linux-2.6.32.41/arch/x86/kernel/alternative.c
11143--- linux-2.6.32.41/arch/x86/kernel/alternative.c 2011-03-27 14:31:47.000000000 -0400
11144+++ linux-2.6.32.41/arch/x86/kernel/alternative.c 2011-04-17 15:56:46.000000000 -0400
11145@@ -407,7 +407,7 @@ void __init_or_module apply_paravirt(str
11146
11147 BUG_ON(p->len > MAX_PATCH_LEN);
11148 /* prep the buffer with the original instructions */
11149- memcpy(insnbuf, p->instr, p->len);
11150+ memcpy(insnbuf, ktla_ktva(p->instr), p->len);
11151 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
11152 (unsigned long)p->instr, p->len);
11153
11154@@ -475,7 +475,7 @@ void __init alternative_instructions(voi
11155 if (smp_alt_once)
11156 free_init_pages("SMP alternatives",
11157 (unsigned long)__smp_locks,
11158- (unsigned long)__smp_locks_end);
11159+ PAGE_ALIGN((unsigned long)__smp_locks_end));
11160
11161 restart_nmi();
11162 }
11163@@ -492,13 +492,17 @@ void __init alternative_instructions(voi
11164 * instructions. And on the local CPU you need to be protected again NMI or MCE
11165 * handlers seeing an inconsistent instruction while you patch.
11166 */
11167-static void *__init_or_module text_poke_early(void *addr, const void *opcode,
11168+static void *__kprobes text_poke_early(void *addr, const void *opcode,
11169 size_t len)
11170 {
11171 unsigned long flags;
11172 local_irq_save(flags);
11173- memcpy(addr, opcode, len);
11174+
11175+ pax_open_kernel();
11176+ memcpy(ktla_ktva(addr), opcode, len);
11177 sync_core();
11178+ pax_close_kernel();
11179+
11180 local_irq_restore(flags);
11181 /* Could also do a CLFLUSH here to speed up CPU recovery; but
11182 that causes hangs on some VIA CPUs. */
11183@@ -520,35 +524,21 @@ static void *__init_or_module text_poke_
11184 */
11185 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
11186 {
11187- unsigned long flags;
11188- char *vaddr;
11189+ unsigned char *vaddr = ktla_ktva(addr);
11190 struct page *pages[2];
11191- int i;
11192+ size_t i;
11193
11194 if (!core_kernel_text((unsigned long)addr)) {
11195- pages[0] = vmalloc_to_page(addr);
11196- pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
11197+ pages[0] = vmalloc_to_page(vaddr);
11198+ pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
11199 } else {
11200- pages[0] = virt_to_page(addr);
11201+ pages[0] = virt_to_page(vaddr);
11202 WARN_ON(!PageReserved(pages[0]));
11203- pages[1] = virt_to_page(addr + PAGE_SIZE);
11204+ pages[1] = virt_to_page(vaddr + PAGE_SIZE);
11205 }
11206 BUG_ON(!pages[0]);
11207- local_irq_save(flags);
11208- set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
11209- if (pages[1])
11210- set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
11211- vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
11212- memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
11213- clear_fixmap(FIX_TEXT_POKE0);
11214- if (pages[1])
11215- clear_fixmap(FIX_TEXT_POKE1);
11216- local_flush_tlb();
11217- sync_core();
11218- /* Could also do a CLFLUSH here to speed up CPU recovery; but
11219- that causes hangs on some VIA CPUs. */
11220+ text_poke_early(addr, opcode, len);
11221 for (i = 0; i < len; i++)
11222- BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
11223- local_irq_restore(flags);
11224+ BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
11225 return addr;
11226 }
11227diff -urNp linux-2.6.32.41/arch/x86/kernel/amd_iommu.c linux-2.6.32.41/arch/x86/kernel/amd_iommu.c
11228--- linux-2.6.32.41/arch/x86/kernel/amd_iommu.c 2011-03-27 14:31:47.000000000 -0400
11229+++ linux-2.6.32.41/arch/x86/kernel/amd_iommu.c 2011-04-17 15:56:46.000000000 -0400
11230@@ -2076,7 +2076,7 @@ static void prealloc_protection_domains(
11231 }
11232 }
11233
11234-static struct dma_map_ops amd_iommu_dma_ops = {
11235+static const struct dma_map_ops amd_iommu_dma_ops = {
11236 .alloc_coherent = alloc_coherent,
11237 .free_coherent = free_coherent,
11238 .map_page = map_page,
11239diff -urNp linux-2.6.32.41/arch/x86/kernel/apic/apic.c linux-2.6.32.41/arch/x86/kernel/apic/apic.c
11240--- linux-2.6.32.41/arch/x86/kernel/apic/apic.c 2011-03-27 14:31:47.000000000 -0400
11241+++ linux-2.6.32.41/arch/x86/kernel/apic/apic.c 2011-05-16 21:46:57.000000000 -0400
11242@@ -1794,7 +1794,7 @@ void smp_error_interrupt(struct pt_regs
11243 apic_write(APIC_ESR, 0);
11244 v1 = apic_read(APIC_ESR);
11245 ack_APIC_irq();
11246- atomic_inc(&irq_err_count);
11247+ atomic_inc_unchecked(&irq_err_count);
11248
11249 /*
11250 * Here is what the APIC error bits mean:
11251@@ -2184,6 +2184,8 @@ static int __cpuinit apic_cluster_num(vo
11252 u16 *bios_cpu_apicid;
11253 DECLARE_BITMAP(clustermap, NUM_APIC_CLUSTERS);
11254
11255+ pax_track_stack();
11256+
11257 bios_cpu_apicid = early_per_cpu_ptr(x86_bios_cpu_apicid);
11258 bitmap_zero(clustermap, NUM_APIC_CLUSTERS);
11259
11260diff -urNp linux-2.6.32.41/arch/x86/kernel/apic/io_apic.c linux-2.6.32.41/arch/x86/kernel/apic/io_apic.c
11261--- linux-2.6.32.41/arch/x86/kernel/apic/io_apic.c 2011-03-27 14:31:47.000000000 -0400
11262+++ linux-2.6.32.41/arch/x86/kernel/apic/io_apic.c 2011-05-04 17:56:20.000000000 -0400
11263@@ -716,7 +716,7 @@ struct IO_APIC_route_entry **alloc_ioapi
11264 ioapic_entries = kzalloc(sizeof(*ioapic_entries) * nr_ioapics,
11265 GFP_ATOMIC);
11266 if (!ioapic_entries)
11267- return 0;
11268+ return NULL;
11269
11270 for (apic = 0; apic < nr_ioapics; apic++) {
11271 ioapic_entries[apic] =
11272@@ -733,7 +733,7 @@ nomem:
11273 kfree(ioapic_entries[apic]);
11274 kfree(ioapic_entries);
11275
11276- return 0;
11277+ return NULL;
11278 }
11279
11280 /*
11281@@ -1150,7 +1150,7 @@ int IO_APIC_get_PCI_irq_vector(int bus,
11282 }
11283 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
11284
11285-void lock_vector_lock(void)
11286+void lock_vector_lock(void) __acquires(vector_lock)
11287 {
11288 /* Used to the online set of cpus does not change
11289 * during assign_irq_vector.
11290@@ -1158,7 +1158,7 @@ void lock_vector_lock(void)
11291 spin_lock(&vector_lock);
11292 }
11293
11294-void unlock_vector_lock(void)
11295+void unlock_vector_lock(void) __releases(vector_lock)
11296 {
11297 spin_unlock(&vector_lock);
11298 }
11299@@ -2542,7 +2542,7 @@ static void ack_apic_edge(unsigned int i
11300 ack_APIC_irq();
11301 }
11302
11303-atomic_t irq_mis_count;
11304+atomic_unchecked_t irq_mis_count;
11305
11306 static void ack_apic_level(unsigned int irq)
11307 {
11308@@ -2626,7 +2626,7 @@ static void ack_apic_level(unsigned int
11309
11310 /* Tail end of version 0x11 I/O APIC bug workaround */
11311 if (!(v & (1 << (i & 0x1f)))) {
11312- atomic_inc(&irq_mis_count);
11313+ atomic_inc_unchecked(&irq_mis_count);
11314 spin_lock(&ioapic_lock);
11315 __mask_and_edge_IO_APIC_irq(cfg);
11316 __unmask_and_level_IO_APIC_irq(cfg);
11317diff -urNp linux-2.6.32.41/arch/x86/kernel/apm_32.c linux-2.6.32.41/arch/x86/kernel/apm_32.c
11318--- linux-2.6.32.41/arch/x86/kernel/apm_32.c 2011-03-27 14:31:47.000000000 -0400
11319+++ linux-2.6.32.41/arch/x86/kernel/apm_32.c 2011-04-23 12:56:10.000000000 -0400
11320@@ -410,7 +410,7 @@ static DEFINE_SPINLOCK(user_list_lock);
11321 * This is for buggy BIOS's that refer to (real mode) segment 0x40
11322 * even though they are called in protected mode.
11323 */
11324-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
11325+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
11326 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
11327
11328 static const char driver_version[] = "1.16ac"; /* no spaces */
11329@@ -588,7 +588,10 @@ static long __apm_bios_call(void *_call)
11330 BUG_ON(cpu != 0);
11331 gdt = get_cpu_gdt_table(cpu);
11332 save_desc_40 = gdt[0x40 / 8];
11333+
11334+ pax_open_kernel();
11335 gdt[0x40 / 8] = bad_bios_desc;
11336+ pax_close_kernel();
11337
11338 apm_irq_save(flags);
11339 APM_DO_SAVE_SEGS;
11340@@ -597,7 +600,11 @@ static long __apm_bios_call(void *_call)
11341 &call->esi);
11342 APM_DO_RESTORE_SEGS;
11343 apm_irq_restore(flags);
11344+
11345+ pax_open_kernel();
11346 gdt[0x40 / 8] = save_desc_40;
11347+ pax_close_kernel();
11348+
11349 put_cpu();
11350
11351 return call->eax & 0xff;
11352@@ -664,7 +671,10 @@ static long __apm_bios_call_simple(void
11353 BUG_ON(cpu != 0);
11354 gdt = get_cpu_gdt_table(cpu);
11355 save_desc_40 = gdt[0x40 / 8];
11356+
11357+ pax_open_kernel();
11358 gdt[0x40 / 8] = bad_bios_desc;
11359+ pax_close_kernel();
11360
11361 apm_irq_save(flags);
11362 APM_DO_SAVE_SEGS;
11363@@ -672,7 +682,11 @@ static long __apm_bios_call_simple(void
11364 &call->eax);
11365 APM_DO_RESTORE_SEGS;
11366 apm_irq_restore(flags);
11367+
11368+ pax_open_kernel();
11369 gdt[0x40 / 8] = save_desc_40;
11370+ pax_close_kernel();
11371+
11372 put_cpu();
11373 return error;
11374 }
11375@@ -975,7 +989,7 @@ recalc:
11376
11377 static void apm_power_off(void)
11378 {
11379- unsigned char po_bios_call[] = {
11380+ const unsigned char po_bios_call[] = {
11381 0xb8, 0x00, 0x10, /* movw $0x1000,ax */
11382 0x8e, 0xd0, /* movw ax,ss */
11383 0xbc, 0x00, 0xf0, /* movw $0xf000,sp */
11384@@ -2357,12 +2371,15 @@ static int __init apm_init(void)
11385 * code to that CPU.
11386 */
11387 gdt = get_cpu_gdt_table(0);
11388+
11389+ pax_open_kernel();
11390 set_desc_base(&gdt[APM_CS >> 3],
11391 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
11392 set_desc_base(&gdt[APM_CS_16 >> 3],
11393 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
11394 set_desc_base(&gdt[APM_DS >> 3],
11395 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
11396+ pax_close_kernel();
11397
11398 proc_create("apm", 0, NULL, &apm_file_ops);
11399
11400diff -urNp linux-2.6.32.41/arch/x86/kernel/asm-offsets_32.c linux-2.6.32.41/arch/x86/kernel/asm-offsets_32.c
11401--- linux-2.6.32.41/arch/x86/kernel/asm-offsets_32.c 2011-03-27 14:31:47.000000000 -0400
11402+++ linux-2.6.32.41/arch/x86/kernel/asm-offsets_32.c 2011-05-16 21:46:57.000000000 -0400
11403@@ -51,7 +51,6 @@ void foo(void)
11404 OFFSET(CPUINFO_x86_vendor_id, cpuinfo_x86, x86_vendor_id);
11405 BLANK();
11406
11407- OFFSET(TI_task, thread_info, task);
11408 OFFSET(TI_exec_domain, thread_info, exec_domain);
11409 OFFSET(TI_flags, thread_info, flags);
11410 OFFSET(TI_status, thread_info, status);
11411@@ -60,6 +59,8 @@ void foo(void)
11412 OFFSET(TI_restart_block, thread_info, restart_block);
11413 OFFSET(TI_sysenter_return, thread_info, sysenter_return);
11414 OFFSET(TI_cpu, thread_info, cpu);
11415+ OFFSET(TI_lowest_stack, thread_info, lowest_stack);
11416+ DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
11417 BLANK();
11418
11419 OFFSET(GDS_size, desc_ptr, size);
11420@@ -99,6 +100,7 @@ void foo(void)
11421
11422 DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
11423 DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
11424+ DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
11425 DEFINE(PTRS_PER_PTE, PTRS_PER_PTE);
11426 DEFINE(PTRS_PER_PMD, PTRS_PER_PMD);
11427 DEFINE(PTRS_PER_PGD, PTRS_PER_PGD);
11428@@ -115,6 +117,11 @@ void foo(void)
11429 OFFSET(PV_CPU_iret, pv_cpu_ops, iret);
11430 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
11431 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
11432+
11433+#ifdef CONFIG_PAX_KERNEXEC
11434+ OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
11435+#endif
11436+
11437 #endif
11438
11439 #ifdef CONFIG_XEN
11440diff -urNp linux-2.6.32.41/arch/x86/kernel/asm-offsets_64.c linux-2.6.32.41/arch/x86/kernel/asm-offsets_64.c
11441--- linux-2.6.32.41/arch/x86/kernel/asm-offsets_64.c 2011-03-27 14:31:47.000000000 -0400
11442+++ linux-2.6.32.41/arch/x86/kernel/asm-offsets_64.c 2011-05-16 21:46:57.000000000 -0400
11443@@ -44,6 +44,8 @@ int main(void)
11444 ENTRY(addr_limit);
11445 ENTRY(preempt_count);
11446 ENTRY(status);
11447+ ENTRY(lowest_stack);
11448+ DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
11449 #ifdef CONFIG_IA32_EMULATION
11450 ENTRY(sysenter_return);
11451 #endif
11452@@ -63,6 +65,18 @@ int main(void)
11453 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
11454 OFFSET(PV_CPU_swapgs, pv_cpu_ops, swapgs);
11455 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
11456+
11457+#ifdef CONFIG_PAX_KERNEXEC
11458+ OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
11459+ OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
11460+#endif
11461+
11462+#ifdef CONFIG_PAX_MEMORY_UDEREF
11463+ OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
11464+ OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
11465+ OFFSET(PV_MMU_set_pgd, pv_mmu_ops, set_pgd);
11466+#endif
11467+
11468 #endif
11469
11470
11471@@ -115,6 +129,7 @@ int main(void)
11472 ENTRY(cr8);
11473 BLANK();
11474 #undef ENTRY
11475+ DEFINE(TSS_size, sizeof(struct tss_struct));
11476 DEFINE(TSS_ist, offsetof(struct tss_struct, x86_tss.ist));
11477 BLANK();
11478 DEFINE(crypto_tfm_ctx_offset, offsetof(struct crypto_tfm, __crt_ctx));
11479@@ -130,6 +145,7 @@ int main(void)
11480
11481 BLANK();
11482 DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
11483+ DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
11484 #ifdef CONFIG_XEN
11485 BLANK();
11486 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
11487diff -urNp linux-2.6.32.41/arch/x86/kernel/cpu/amd.c linux-2.6.32.41/arch/x86/kernel/cpu/amd.c
11488--- linux-2.6.32.41/arch/x86/kernel/cpu/amd.c 2011-05-23 16:56:59.000000000 -0400
11489+++ linux-2.6.32.41/arch/x86/kernel/cpu/amd.c 2011-05-23 16:57:13.000000000 -0400
11490@@ -596,7 +596,7 @@ static unsigned int __cpuinit amd_size_c
11491 unsigned int size)
11492 {
11493 /* AMD errata T13 (order #21922) */
11494- if ((c->x86 == 6)) {
11495+ if (c->x86 == 6) {
11496 /* Duron Rev A0 */
11497 if (c->x86_model == 3 && c->x86_mask == 0)
11498 size = 64;
11499diff -urNp linux-2.6.32.41/arch/x86/kernel/cpu/common.c linux-2.6.32.41/arch/x86/kernel/cpu/common.c
11500--- linux-2.6.32.41/arch/x86/kernel/cpu/common.c 2011-03-27 14:31:47.000000000 -0400
11501+++ linux-2.6.32.41/arch/x86/kernel/cpu/common.c 2011-05-11 18:25:15.000000000 -0400
11502@@ -83,60 +83,6 @@ static const struct cpu_dev __cpuinitcon
11503
11504 static const struct cpu_dev *this_cpu __cpuinitdata = &default_cpu;
11505
11506-DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
11507-#ifdef CONFIG_X86_64
11508- /*
11509- * We need valid kernel segments for data and code in long mode too
11510- * IRET will check the segment types kkeil 2000/10/28
11511- * Also sysret mandates a special GDT layout
11512- *
11513- * TLS descriptors are currently at a different place compared to i386.
11514- * Hopefully nobody expects them at a fixed place (Wine?)
11515- */
11516- [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
11517- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
11518- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
11519- [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
11520- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
11521- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
11522-#else
11523- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
11524- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
11525- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
11526- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
11527- /*
11528- * Segments used for calling PnP BIOS have byte granularity.
11529- * They code segments and data segments have fixed 64k limits,
11530- * the transfer segment sizes are set at run time.
11531- */
11532- /* 32-bit code */
11533- [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
11534- /* 16-bit code */
11535- [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
11536- /* 16-bit data */
11537- [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
11538- /* 16-bit data */
11539- [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
11540- /* 16-bit data */
11541- [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
11542- /*
11543- * The APM segments have byte granularity and their bases
11544- * are set at run time. All have 64k limits.
11545- */
11546- /* 32-bit code */
11547- [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
11548- /* 16-bit code */
11549- [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
11550- /* data */
11551- [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
11552-
11553- [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
11554- [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
11555- GDT_STACK_CANARY_INIT
11556-#endif
11557-} };
11558-EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
11559-
11560 static int __init x86_xsave_setup(char *s)
11561 {
11562 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
11563@@ -344,7 +290,7 @@ void switch_to_new_gdt(int cpu)
11564 {
11565 struct desc_ptr gdt_descr;
11566
11567- gdt_descr.address = (long)get_cpu_gdt_table(cpu);
11568+ gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
11569 gdt_descr.size = GDT_SIZE - 1;
11570 load_gdt(&gdt_descr);
11571 /* Reload the per-cpu base */
11572@@ -798,6 +744,10 @@ static void __cpuinit identify_cpu(struc
11573 /* Filter out anything that depends on CPUID levels we don't have */
11574 filter_cpuid_features(c, true);
11575
11576+#if defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || (defined(CONFIG_PAX_MEMORY_UDEREF) && defined(CONFIG_X86_32))
11577+ setup_clear_cpu_cap(X86_FEATURE_SEP);
11578+#endif
11579+
11580 /* If the model name is still unset, do table lookup. */
11581 if (!c->x86_model_id[0]) {
11582 const char *p;
11583@@ -980,6 +930,9 @@ static __init int setup_disablecpuid(cha
11584 }
11585 __setup("clearcpuid=", setup_disablecpuid);
11586
11587+DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
11588+EXPORT_PER_CPU_SYMBOL(current_tinfo);
11589+
11590 #ifdef CONFIG_X86_64
11591 struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
11592
11593@@ -995,7 +948,7 @@ DEFINE_PER_CPU(struct task_struct *, cur
11594 EXPORT_PER_CPU_SYMBOL(current_task);
11595
11596 DEFINE_PER_CPU(unsigned long, kernel_stack) =
11597- (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
11598+ (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
11599 EXPORT_PER_CPU_SYMBOL(kernel_stack);
11600
11601 DEFINE_PER_CPU(char *, irq_stack_ptr) =
11602@@ -1060,7 +1013,7 @@ struct pt_regs * __cpuinit idle_regs(str
11603 {
11604 memset(regs, 0, sizeof(struct pt_regs));
11605 regs->fs = __KERNEL_PERCPU;
11606- regs->gs = __KERNEL_STACK_CANARY;
11607+ savesegment(gs, regs->gs);
11608
11609 return regs;
11610 }
11611@@ -1101,7 +1054,7 @@ void __cpuinit cpu_init(void)
11612 int i;
11613
11614 cpu = stack_smp_processor_id();
11615- t = &per_cpu(init_tss, cpu);
11616+ t = init_tss + cpu;
11617 orig_ist = &per_cpu(orig_ist, cpu);
11618
11619 #ifdef CONFIG_NUMA
11620@@ -1127,7 +1080,7 @@ void __cpuinit cpu_init(void)
11621 switch_to_new_gdt(cpu);
11622 loadsegment(fs, 0);
11623
11624- load_idt((const struct desc_ptr *)&idt_descr);
11625+ load_idt(&idt_descr);
11626
11627 memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
11628 syscall_init();
11629@@ -1136,7 +1089,6 @@ void __cpuinit cpu_init(void)
11630 wrmsrl(MSR_KERNEL_GS_BASE, 0);
11631 barrier();
11632
11633- check_efer();
11634 if (cpu != 0)
11635 enable_x2apic();
11636
11637@@ -1199,7 +1151,7 @@ void __cpuinit cpu_init(void)
11638 {
11639 int cpu = smp_processor_id();
11640 struct task_struct *curr = current;
11641- struct tss_struct *t = &per_cpu(init_tss, cpu);
11642+ struct tss_struct *t = init_tss + cpu;
11643 struct thread_struct *thread = &curr->thread;
11644
11645 if (cpumask_test_and_set_cpu(cpu, cpu_initialized_mask)) {
11646diff -urNp linux-2.6.32.41/arch/x86/kernel/cpu/intel.c linux-2.6.32.41/arch/x86/kernel/cpu/intel.c
11647--- linux-2.6.32.41/arch/x86/kernel/cpu/intel.c 2011-03-27 14:31:47.000000000 -0400
11648+++ linux-2.6.32.41/arch/x86/kernel/cpu/intel.c 2011-04-17 15:56:46.000000000 -0400
11649@@ -162,7 +162,7 @@ static void __cpuinit trap_init_f00f_bug
11650 * Update the IDT descriptor and reload the IDT so that
11651 * it uses the read-only mapped virtual address.
11652 */
11653- idt_descr.address = fix_to_virt(FIX_F00F_IDT);
11654+ idt_descr.address = (struct desc_struct *)fix_to_virt(FIX_F00F_IDT);
11655 load_idt(&idt_descr);
11656 }
11657 #endif
11658diff -urNp linux-2.6.32.41/arch/x86/kernel/cpu/intel_cacheinfo.c linux-2.6.32.41/arch/x86/kernel/cpu/intel_cacheinfo.c
11659--- linux-2.6.32.41/arch/x86/kernel/cpu/intel_cacheinfo.c 2011-03-27 14:31:47.000000000 -0400
11660+++ linux-2.6.32.41/arch/x86/kernel/cpu/intel_cacheinfo.c 2011-04-17 15:56:46.000000000 -0400
11661@@ -921,7 +921,7 @@ static ssize_t store(struct kobject *kob
11662 return ret;
11663 }
11664
11665-static struct sysfs_ops sysfs_ops = {
11666+static const struct sysfs_ops sysfs_ops = {
11667 .show = show,
11668 .store = store,
11669 };
11670diff -urNp linux-2.6.32.41/arch/x86/kernel/cpu/Makefile linux-2.6.32.41/arch/x86/kernel/cpu/Makefile
11671--- linux-2.6.32.41/arch/x86/kernel/cpu/Makefile 2011-03-27 14:31:47.000000000 -0400
11672+++ linux-2.6.32.41/arch/x86/kernel/cpu/Makefile 2011-04-17 15:56:46.000000000 -0400
11673@@ -7,10 +7,6 @@ ifdef CONFIG_FUNCTION_TRACER
11674 CFLAGS_REMOVE_common.o = -pg
11675 endif
11676
11677-# Make sure load_percpu_segment has no stackprotector
11678-nostackp := $(call cc-option, -fno-stack-protector)
11679-CFLAGS_common.o := $(nostackp)
11680-
11681 obj-y := intel_cacheinfo.o addon_cpuid_features.o
11682 obj-y += proc.o capflags.o powerflags.o common.o
11683 obj-y += vmware.o hypervisor.o sched.o
11684diff -urNp linux-2.6.32.41/arch/x86/kernel/cpu/mcheck/mce_amd.c linux-2.6.32.41/arch/x86/kernel/cpu/mcheck/mce_amd.c
11685--- linux-2.6.32.41/arch/x86/kernel/cpu/mcheck/mce_amd.c 2011-05-23 16:56:59.000000000 -0400
11686+++ linux-2.6.32.41/arch/x86/kernel/cpu/mcheck/mce_amd.c 2011-05-23 16:57:13.000000000 -0400
11687@@ -385,7 +385,7 @@ static ssize_t store(struct kobject *kob
11688 return ret;
11689 }
11690
11691-static struct sysfs_ops threshold_ops = {
11692+static const struct sysfs_ops threshold_ops = {
11693 .show = show,
11694 .store = store,
11695 };
11696diff -urNp linux-2.6.32.41/arch/x86/kernel/cpu/mcheck/mce.c linux-2.6.32.41/arch/x86/kernel/cpu/mcheck/mce.c
11697--- linux-2.6.32.41/arch/x86/kernel/cpu/mcheck/mce.c 2011-03-27 14:31:47.000000000 -0400
11698+++ linux-2.6.32.41/arch/x86/kernel/cpu/mcheck/mce.c 2011-05-04 17:56:20.000000000 -0400
11699@@ -43,6 +43,7 @@
11700 #include <asm/ipi.h>
11701 #include <asm/mce.h>
11702 #include <asm/msr.h>
11703+#include <asm/local.h>
11704
11705 #include "mce-internal.h"
11706
11707@@ -187,7 +188,7 @@ static void print_mce(struct mce *m)
11708 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
11709 m->cs, m->ip);
11710
11711- if (m->cs == __KERNEL_CS)
11712+ if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
11713 print_symbol("{%s}", m->ip);
11714 pr_cont("\n");
11715 }
11716@@ -221,10 +222,10 @@ static void print_mce_tail(void)
11717
11718 #define PANIC_TIMEOUT 5 /* 5 seconds */
11719
11720-static atomic_t mce_paniced;
11721+static atomic_unchecked_t mce_paniced;
11722
11723 static int fake_panic;
11724-static atomic_t mce_fake_paniced;
11725+static atomic_unchecked_t mce_fake_paniced;
11726
11727 /* Panic in progress. Enable interrupts and wait for final IPI */
11728 static void wait_for_panic(void)
11729@@ -248,7 +249,7 @@ static void mce_panic(char *msg, struct
11730 /*
11731 * Make sure only one CPU runs in machine check panic
11732 */
11733- if (atomic_inc_return(&mce_paniced) > 1)
11734+ if (atomic_inc_return_unchecked(&mce_paniced) > 1)
11735 wait_for_panic();
11736 barrier();
11737
11738@@ -256,7 +257,7 @@ static void mce_panic(char *msg, struct
11739 console_verbose();
11740 } else {
11741 /* Don't log too much for fake panic */
11742- if (atomic_inc_return(&mce_fake_paniced) > 1)
11743+ if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
11744 return;
11745 }
11746 print_mce_head();
11747@@ -616,7 +617,7 @@ static int mce_timed_out(u64 *t)
11748 * might have been modified by someone else.
11749 */
11750 rmb();
11751- if (atomic_read(&mce_paniced))
11752+ if (atomic_read_unchecked(&mce_paniced))
11753 wait_for_panic();
11754 if (!monarch_timeout)
11755 goto out;
11756@@ -1429,14 +1430,14 @@ void __cpuinit mcheck_init(struct cpuinf
11757 */
11758
11759 static DEFINE_SPINLOCK(mce_state_lock);
11760-static int open_count; /* #times opened */
11761+static local_t open_count; /* #times opened */
11762 static int open_exclu; /* already open exclusive? */
11763
11764 static int mce_open(struct inode *inode, struct file *file)
11765 {
11766 spin_lock(&mce_state_lock);
11767
11768- if (open_exclu || (open_count && (file->f_flags & O_EXCL))) {
11769+ if (open_exclu || (local_read(&open_count) && (file->f_flags & O_EXCL))) {
11770 spin_unlock(&mce_state_lock);
11771
11772 return -EBUSY;
11773@@ -1444,7 +1445,7 @@ static int mce_open(struct inode *inode,
11774
11775 if (file->f_flags & O_EXCL)
11776 open_exclu = 1;
11777- open_count++;
11778+ local_inc(&open_count);
11779
11780 spin_unlock(&mce_state_lock);
11781
11782@@ -1455,7 +1456,7 @@ static int mce_release(struct inode *ino
11783 {
11784 spin_lock(&mce_state_lock);
11785
11786- open_count--;
11787+ local_dec(&open_count);
11788 open_exclu = 0;
11789
11790 spin_unlock(&mce_state_lock);
11791@@ -2082,7 +2083,7 @@ struct dentry *mce_get_debugfs_dir(void)
11792 static void mce_reset(void)
11793 {
11794 cpu_missing = 0;
11795- atomic_set(&mce_fake_paniced, 0);
11796+ atomic_set_unchecked(&mce_fake_paniced, 0);
11797 atomic_set(&mce_executing, 0);
11798 atomic_set(&mce_callin, 0);
11799 atomic_set(&global_nwo, 0);
11800diff -urNp linux-2.6.32.41/arch/x86/kernel/cpu/mtrr/amd.c linux-2.6.32.41/arch/x86/kernel/cpu/mtrr/amd.c
11801--- linux-2.6.32.41/arch/x86/kernel/cpu/mtrr/amd.c 2011-03-27 14:31:47.000000000 -0400
11802+++ linux-2.6.32.41/arch/x86/kernel/cpu/mtrr/amd.c 2011-04-17 15:56:46.000000000 -0400
11803@@ -108,7 +108,7 @@ amd_validate_add_page(unsigned long base
11804 return 0;
11805 }
11806
11807-static struct mtrr_ops amd_mtrr_ops = {
11808+static const struct mtrr_ops amd_mtrr_ops = {
11809 .vendor = X86_VENDOR_AMD,
11810 .set = amd_set_mtrr,
11811 .get = amd_get_mtrr,
11812diff -urNp linux-2.6.32.41/arch/x86/kernel/cpu/mtrr/centaur.c linux-2.6.32.41/arch/x86/kernel/cpu/mtrr/centaur.c
11813--- linux-2.6.32.41/arch/x86/kernel/cpu/mtrr/centaur.c 2011-03-27 14:31:47.000000000 -0400
11814+++ linux-2.6.32.41/arch/x86/kernel/cpu/mtrr/centaur.c 2011-04-17 15:56:46.000000000 -0400
11815@@ -110,7 +110,7 @@ centaur_validate_add_page(unsigned long
11816 return 0;
11817 }
11818
11819-static struct mtrr_ops centaur_mtrr_ops = {
11820+static const struct mtrr_ops centaur_mtrr_ops = {
11821 .vendor = X86_VENDOR_CENTAUR,
11822 .set = centaur_set_mcr,
11823 .get = centaur_get_mcr,
11824diff -urNp linux-2.6.32.41/arch/x86/kernel/cpu/mtrr/cyrix.c linux-2.6.32.41/arch/x86/kernel/cpu/mtrr/cyrix.c
11825--- linux-2.6.32.41/arch/x86/kernel/cpu/mtrr/cyrix.c 2011-03-27 14:31:47.000000000 -0400
11826+++ linux-2.6.32.41/arch/x86/kernel/cpu/mtrr/cyrix.c 2011-04-17 15:56:46.000000000 -0400
11827@@ -265,7 +265,7 @@ static void cyrix_set_all(void)
11828 post_set();
11829 }
11830
11831-static struct mtrr_ops cyrix_mtrr_ops = {
11832+static const struct mtrr_ops cyrix_mtrr_ops = {
11833 .vendor = X86_VENDOR_CYRIX,
11834 .set_all = cyrix_set_all,
11835 .set = cyrix_set_arr,
11836diff -urNp linux-2.6.32.41/arch/x86/kernel/cpu/mtrr/generic.c linux-2.6.32.41/arch/x86/kernel/cpu/mtrr/generic.c
11837--- linux-2.6.32.41/arch/x86/kernel/cpu/mtrr/generic.c 2011-03-27 14:31:47.000000000 -0400
11838+++ linux-2.6.32.41/arch/x86/kernel/cpu/mtrr/generic.c 2011-04-23 12:56:10.000000000 -0400
11839@@ -752,7 +752,7 @@ int positive_have_wrcomb(void)
11840 /*
11841 * Generic structure...
11842 */
11843-struct mtrr_ops generic_mtrr_ops = {
11844+const struct mtrr_ops generic_mtrr_ops = {
11845 .use_intel_if = 1,
11846 .set_all = generic_set_all,
11847 .get = generic_get_mtrr,
11848diff -urNp linux-2.6.32.41/arch/x86/kernel/cpu/mtrr/main.c linux-2.6.32.41/arch/x86/kernel/cpu/mtrr/main.c
11849--- linux-2.6.32.41/arch/x86/kernel/cpu/mtrr/main.c 2011-04-17 17:00:52.000000000 -0400
11850+++ linux-2.6.32.41/arch/x86/kernel/cpu/mtrr/main.c 2011-04-17 17:03:05.000000000 -0400
11851@@ -60,14 +60,14 @@ static DEFINE_MUTEX(mtrr_mutex);
11852 u64 size_or_mask, size_and_mask;
11853 static bool mtrr_aps_delayed_init;
11854
11855-static struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
11856+static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
11857
11858-struct mtrr_ops *mtrr_if;
11859+const struct mtrr_ops *mtrr_if;
11860
11861 static void set_mtrr(unsigned int reg, unsigned long base,
11862 unsigned long size, mtrr_type type);
11863
11864-void set_mtrr_ops(struct mtrr_ops *ops)
11865+void set_mtrr_ops(const struct mtrr_ops *ops)
11866 {
11867 if (ops->vendor && ops->vendor < X86_VENDOR_NUM)
11868 mtrr_ops[ops->vendor] = ops;
11869diff -urNp linux-2.6.32.41/arch/x86/kernel/cpu/mtrr/mtrr.h linux-2.6.32.41/arch/x86/kernel/cpu/mtrr/mtrr.h
11870--- linux-2.6.32.41/arch/x86/kernel/cpu/mtrr/mtrr.h 2011-03-27 14:31:47.000000000 -0400
11871+++ linux-2.6.32.41/arch/x86/kernel/cpu/mtrr/mtrr.h 2011-04-17 15:56:46.000000000 -0400
11872@@ -12,19 +12,19 @@
11873 extern unsigned int mtrr_usage_table[MTRR_MAX_VAR_RANGES];
11874
11875 struct mtrr_ops {
11876- u32 vendor;
11877- u32 use_intel_if;
11878- void (*set)(unsigned int reg, unsigned long base,
11879+ const u32 vendor;
11880+ const u32 use_intel_if;
11881+ void (* const set)(unsigned int reg, unsigned long base,
11882 unsigned long size, mtrr_type type);
11883- void (*set_all)(void);
11884+ void (* const set_all)(void);
11885
11886- void (*get)(unsigned int reg, unsigned long *base,
11887+ void (* const get)(unsigned int reg, unsigned long *base,
11888 unsigned long *size, mtrr_type *type);
11889- int (*get_free_region)(unsigned long base, unsigned long size,
11890+ int (* const get_free_region)(unsigned long base, unsigned long size,
11891 int replace_reg);
11892- int (*validate_add_page)(unsigned long base, unsigned long size,
11893+ int (* const validate_add_page)(unsigned long base, unsigned long size,
11894 unsigned int type);
11895- int (*have_wrcomb)(void);
11896+ int (* const have_wrcomb)(void);
11897 };
11898
11899 extern int generic_get_free_region(unsigned long base, unsigned long size,
11900@@ -32,7 +32,7 @@ extern int generic_get_free_region(unsig
11901 extern int generic_validate_add_page(unsigned long base, unsigned long size,
11902 unsigned int type);
11903
11904-extern struct mtrr_ops generic_mtrr_ops;
11905+extern const struct mtrr_ops generic_mtrr_ops;
11906
11907 extern int positive_have_wrcomb(void);
11908
11909@@ -53,10 +53,10 @@ void fill_mtrr_var_range(unsigned int in
11910 u32 base_lo, u32 base_hi, u32 mask_lo, u32 mask_hi);
11911 void get_mtrr_state(void);
11912
11913-extern void set_mtrr_ops(struct mtrr_ops *ops);
11914+extern void set_mtrr_ops(const struct mtrr_ops *ops);
11915
11916 extern u64 size_or_mask, size_and_mask;
11917-extern struct mtrr_ops *mtrr_if;
11918+extern const struct mtrr_ops *mtrr_if;
11919
11920 #define is_cpu(vnd) (mtrr_if && mtrr_if->vendor == X86_VENDOR_##vnd)
11921 #define use_intel() (mtrr_if && mtrr_if->use_intel_if == 1)
11922diff -urNp linux-2.6.32.41/arch/x86/kernel/cpu/perfctr-watchdog.c linux-2.6.32.41/arch/x86/kernel/cpu/perfctr-watchdog.c
11923--- linux-2.6.32.41/arch/x86/kernel/cpu/perfctr-watchdog.c 2011-03-27 14:31:47.000000000 -0400
11924+++ linux-2.6.32.41/arch/x86/kernel/cpu/perfctr-watchdog.c 2011-04-17 15:56:46.000000000 -0400
11925@@ -30,11 +30,11 @@ struct nmi_watchdog_ctlblk {
11926
11927 /* Interface defining a CPU specific perfctr watchdog */
11928 struct wd_ops {
11929- int (*reserve)(void);
11930- void (*unreserve)(void);
11931- int (*setup)(unsigned nmi_hz);
11932- void (*rearm)(struct nmi_watchdog_ctlblk *wd, unsigned nmi_hz);
11933- void (*stop)(void);
11934+ int (* const reserve)(void);
11935+ void (* const unreserve)(void);
11936+ int (* const setup)(unsigned nmi_hz);
11937+ void (* const rearm)(struct nmi_watchdog_ctlblk *wd, unsigned nmi_hz);
11938+ void (* const stop)(void);
11939 unsigned perfctr;
11940 unsigned evntsel;
11941 u64 checkbit;
11942@@ -645,6 +645,7 @@ static const struct wd_ops p4_wd_ops = {
11943 #define ARCH_PERFMON_NMI_EVENT_SEL ARCH_PERFMON_UNHALTED_CORE_CYCLES_SEL
11944 #define ARCH_PERFMON_NMI_EVENT_UMASK ARCH_PERFMON_UNHALTED_CORE_CYCLES_UMASK
11945
11946+/* cannot be const */
11947 static struct wd_ops intel_arch_wd_ops;
11948
11949 static int setup_intel_arch_watchdog(unsigned nmi_hz)
11950@@ -697,6 +698,7 @@ static int setup_intel_arch_watchdog(uns
11951 return 1;
11952 }
11953
11954+/* cannot be const */
11955 static struct wd_ops intel_arch_wd_ops __read_mostly = {
11956 .reserve = single_msr_reserve,
11957 .unreserve = single_msr_unreserve,
11958diff -urNp linux-2.6.32.41/arch/x86/kernel/cpu/perf_event.c linux-2.6.32.41/arch/x86/kernel/cpu/perf_event.c
11959--- linux-2.6.32.41/arch/x86/kernel/cpu/perf_event.c 2011-03-27 14:31:47.000000000 -0400
11960+++ linux-2.6.32.41/arch/x86/kernel/cpu/perf_event.c 2011-05-04 17:56:20.000000000 -0400
11961@@ -723,10 +723,10 @@ x86_perf_event_update(struct perf_event
11962 * count to the generic event atomically:
11963 */
11964 again:
11965- prev_raw_count = atomic64_read(&hwc->prev_count);
11966+ prev_raw_count = atomic64_read_unchecked(&hwc->prev_count);
11967 rdmsrl(hwc->event_base + idx, new_raw_count);
11968
11969- if (atomic64_cmpxchg(&hwc->prev_count, prev_raw_count,
11970+ if (atomic64_cmpxchg_unchecked(&hwc->prev_count, prev_raw_count,
11971 new_raw_count) != prev_raw_count)
11972 goto again;
11973
11974@@ -741,7 +741,7 @@ again:
11975 delta = (new_raw_count << shift) - (prev_raw_count << shift);
11976 delta >>= shift;
11977
11978- atomic64_add(delta, &event->count);
11979+ atomic64_add_unchecked(delta, &event->count);
11980 atomic64_sub(delta, &hwc->period_left);
11981
11982 return new_raw_count;
11983@@ -1353,7 +1353,7 @@ x86_perf_event_set_period(struct perf_ev
11984 * The hw event starts counting from this event offset,
11985 * mark it to be able to extra future deltas:
11986 */
11987- atomic64_set(&hwc->prev_count, (u64)-left);
11988+ atomic64_set_unchecked(&hwc->prev_count, (u64)-left);
11989
11990 err = checking_wrmsrl(hwc->event_base + idx,
11991 (u64)(-left) & x86_pmu.event_mask);
11992@@ -2357,7 +2357,7 @@ perf_callchain_user(struct pt_regs *regs
11993 break;
11994
11995 callchain_store(entry, frame.return_address);
11996- fp = frame.next_frame;
11997+ fp = (__force const void __user *)frame.next_frame;
11998 }
11999 }
12000
12001diff -urNp linux-2.6.32.41/arch/x86/kernel/crash.c linux-2.6.32.41/arch/x86/kernel/crash.c
12002--- linux-2.6.32.41/arch/x86/kernel/crash.c 2011-03-27 14:31:47.000000000 -0400
12003+++ linux-2.6.32.41/arch/x86/kernel/crash.c 2011-04-17 15:56:46.000000000 -0400
12004@@ -41,7 +41,7 @@ static void kdump_nmi_callback(int cpu,
12005 regs = args->regs;
12006
12007 #ifdef CONFIG_X86_32
12008- if (!user_mode_vm(regs)) {
12009+ if (!user_mode(regs)) {
12010 crash_fixup_ss_esp(&fixed_regs, regs);
12011 regs = &fixed_regs;
12012 }
12013diff -urNp linux-2.6.32.41/arch/x86/kernel/doublefault_32.c linux-2.6.32.41/arch/x86/kernel/doublefault_32.c
12014--- linux-2.6.32.41/arch/x86/kernel/doublefault_32.c 2011-03-27 14:31:47.000000000 -0400
12015+++ linux-2.6.32.41/arch/x86/kernel/doublefault_32.c 2011-04-17 15:56:46.000000000 -0400
12016@@ -11,7 +11,7 @@
12017
12018 #define DOUBLEFAULT_STACKSIZE (1024)
12019 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
12020-#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
12021+#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
12022
12023 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
12024
12025@@ -21,7 +21,7 @@ static void doublefault_fn(void)
12026 unsigned long gdt, tss;
12027
12028 store_gdt(&gdt_desc);
12029- gdt = gdt_desc.address;
12030+ gdt = (unsigned long)gdt_desc.address;
12031
12032 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
12033
12034@@ -58,10 +58,10 @@ struct tss_struct doublefault_tss __cach
12035 /* 0x2 bit is always set */
12036 .flags = X86_EFLAGS_SF | 0x2,
12037 .sp = STACK_START,
12038- .es = __USER_DS,
12039+ .es = __KERNEL_DS,
12040 .cs = __KERNEL_CS,
12041 .ss = __KERNEL_DS,
12042- .ds = __USER_DS,
12043+ .ds = __KERNEL_DS,
12044 .fs = __KERNEL_PERCPU,
12045
12046 .__cr3 = __pa_nodebug(swapper_pg_dir),
12047diff -urNp linux-2.6.32.41/arch/x86/kernel/dumpstack_32.c linux-2.6.32.41/arch/x86/kernel/dumpstack_32.c
12048--- linux-2.6.32.41/arch/x86/kernel/dumpstack_32.c 2011-03-27 14:31:47.000000000 -0400
12049+++ linux-2.6.32.41/arch/x86/kernel/dumpstack_32.c 2011-04-17 15:56:46.000000000 -0400
12050@@ -53,16 +53,12 @@ void dump_trace(struct task_struct *task
12051 #endif
12052
12053 for (;;) {
12054- struct thread_info *context;
12055+ void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
12056+ bp = print_context_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
12057
12058- context = (struct thread_info *)
12059- ((unsigned long)stack & (~(THREAD_SIZE - 1)));
12060- bp = print_context_stack(context, stack, bp, ops,
12061- data, NULL, &graph);
12062-
12063- stack = (unsigned long *)context->previous_esp;
12064- if (!stack)
12065+ if (stack_start == task_stack_page(task))
12066 break;
12067+ stack = *(unsigned long **)stack_start;
12068 if (ops->stack(data, "IRQ") < 0)
12069 break;
12070 touch_nmi_watchdog();
12071@@ -112,11 +108,12 @@ void show_registers(struct pt_regs *regs
12072 * When in-kernel, we also print out the stack and code at the
12073 * time of the fault..
12074 */
12075- if (!user_mode_vm(regs)) {
12076+ if (!user_mode(regs)) {
12077 unsigned int code_prologue = code_bytes * 43 / 64;
12078 unsigned int code_len = code_bytes;
12079 unsigned char c;
12080 u8 *ip;
12081+ unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(smp_processor_id())[(0xffff & regs->cs) >> 3]);
12082
12083 printk(KERN_EMERG "Stack:\n");
12084 show_stack_log_lvl(NULL, regs, &regs->sp,
12085@@ -124,10 +121,10 @@ void show_registers(struct pt_regs *regs
12086
12087 printk(KERN_EMERG "Code: ");
12088
12089- ip = (u8 *)regs->ip - code_prologue;
12090+ ip = (u8 *)regs->ip - code_prologue + cs_base;
12091 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
12092 /* try starting at IP */
12093- ip = (u8 *)regs->ip;
12094+ ip = (u8 *)regs->ip + cs_base;
12095 code_len = code_len - code_prologue + 1;
12096 }
12097 for (i = 0; i < code_len; i++, ip++) {
12098@@ -136,7 +133,7 @@ void show_registers(struct pt_regs *regs
12099 printk(" Bad EIP value.");
12100 break;
12101 }
12102- if (ip == (u8 *)regs->ip)
12103+ if (ip == (u8 *)regs->ip + cs_base)
12104 printk("<%02x> ", c);
12105 else
12106 printk("%02x ", c);
12107@@ -149,6 +146,7 @@ int is_valid_bugaddr(unsigned long ip)
12108 {
12109 unsigned short ud2;
12110
12111+ ip = ktla_ktva(ip);
12112 if (ip < PAGE_OFFSET)
12113 return 0;
12114 if (probe_kernel_address((unsigned short *)ip, ud2))
12115diff -urNp linux-2.6.32.41/arch/x86/kernel/dumpstack_64.c linux-2.6.32.41/arch/x86/kernel/dumpstack_64.c
12116--- linux-2.6.32.41/arch/x86/kernel/dumpstack_64.c 2011-03-27 14:31:47.000000000 -0400
12117+++ linux-2.6.32.41/arch/x86/kernel/dumpstack_64.c 2011-04-17 15:56:46.000000000 -0400
12118@@ -116,8 +116,8 @@ void dump_trace(struct task_struct *task
12119 unsigned long *irq_stack_end =
12120 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
12121 unsigned used = 0;
12122- struct thread_info *tinfo;
12123 int graph = 0;
12124+ void *stack_start;
12125
12126 if (!task)
12127 task = current;
12128@@ -146,10 +146,10 @@ void dump_trace(struct task_struct *task
12129 * current stack address. If the stacks consist of nested
12130 * exceptions
12131 */
12132- tinfo = task_thread_info(task);
12133 for (;;) {
12134 char *id;
12135 unsigned long *estack_end;
12136+
12137 estack_end = in_exception_stack(cpu, (unsigned long)stack,
12138 &used, &id);
12139
12140@@ -157,7 +157,7 @@ void dump_trace(struct task_struct *task
12141 if (ops->stack(data, id) < 0)
12142 break;
12143
12144- bp = print_context_stack(tinfo, stack, bp, ops,
12145+ bp = print_context_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
12146 data, estack_end, &graph);
12147 ops->stack(data, "<EOE>");
12148 /*
12149@@ -176,7 +176,7 @@ void dump_trace(struct task_struct *task
12150 if (stack >= irq_stack && stack < irq_stack_end) {
12151 if (ops->stack(data, "IRQ") < 0)
12152 break;
12153- bp = print_context_stack(tinfo, stack, bp,
12154+ bp = print_context_stack(task, irq_stack, stack, bp,
12155 ops, data, irq_stack_end, &graph);
12156 /*
12157 * We link to the next stack (which would be
12158@@ -195,7 +195,8 @@ void dump_trace(struct task_struct *task
12159 /*
12160 * This handles the process stack:
12161 */
12162- bp = print_context_stack(tinfo, stack, bp, ops, data, NULL, &graph);
12163+ stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
12164+ bp = print_context_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
12165 put_cpu();
12166 }
12167 EXPORT_SYMBOL(dump_trace);
12168diff -urNp linux-2.6.32.41/arch/x86/kernel/dumpstack.c linux-2.6.32.41/arch/x86/kernel/dumpstack.c
12169--- linux-2.6.32.41/arch/x86/kernel/dumpstack.c 2011-03-27 14:31:47.000000000 -0400
12170+++ linux-2.6.32.41/arch/x86/kernel/dumpstack.c 2011-04-17 15:56:46.000000000 -0400
12171@@ -2,6 +2,9 @@
12172 * Copyright (C) 1991, 1992 Linus Torvalds
12173 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
12174 */
12175+#ifdef CONFIG_GRKERNSEC_HIDESYM
12176+#define __INCLUDED_BY_HIDESYM 1
12177+#endif
12178 #include <linux/kallsyms.h>
12179 #include <linux/kprobes.h>
12180 #include <linux/uaccess.h>
12181@@ -28,7 +31,7 @@ static int die_counter;
12182
12183 void printk_address(unsigned long address, int reliable)
12184 {
12185- printk(" [<%p>] %s%pS\n", (void *) address,
12186+ printk(" [<%p>] %s%pA\n", (void *) address,
12187 reliable ? "" : "? ", (void *) address);
12188 }
12189
12190@@ -36,9 +39,8 @@ void printk_address(unsigned long addres
12191 static void
12192 print_ftrace_graph_addr(unsigned long addr, void *data,
12193 const struct stacktrace_ops *ops,
12194- struct thread_info *tinfo, int *graph)
12195+ struct task_struct *task, int *graph)
12196 {
12197- struct task_struct *task = tinfo->task;
12198 unsigned long ret_addr;
12199 int index = task->curr_ret_stack;
12200
12201@@ -59,7 +61,7 @@ print_ftrace_graph_addr(unsigned long ad
12202 static inline void
12203 print_ftrace_graph_addr(unsigned long addr, void *data,
12204 const struct stacktrace_ops *ops,
12205- struct thread_info *tinfo, int *graph)
12206+ struct task_struct *task, int *graph)
12207 { }
12208 #endif
12209
12210@@ -70,10 +72,8 @@ print_ftrace_graph_addr(unsigned long ad
12211 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
12212 */
12213
12214-static inline int valid_stack_ptr(struct thread_info *tinfo,
12215- void *p, unsigned int size, void *end)
12216+static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
12217 {
12218- void *t = tinfo;
12219 if (end) {
12220 if (p < end && p >= (end-THREAD_SIZE))
12221 return 1;
12222@@ -84,14 +84,14 @@ static inline int valid_stack_ptr(struct
12223 }
12224
12225 unsigned long
12226-print_context_stack(struct thread_info *tinfo,
12227+print_context_stack(struct task_struct *task, void *stack_start,
12228 unsigned long *stack, unsigned long bp,
12229 const struct stacktrace_ops *ops, void *data,
12230 unsigned long *end, int *graph)
12231 {
12232 struct stack_frame *frame = (struct stack_frame *)bp;
12233
12234- while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
12235+ while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
12236 unsigned long addr;
12237
12238 addr = *stack;
12239@@ -103,7 +103,7 @@ print_context_stack(struct thread_info *
12240 } else {
12241 ops->address(data, addr, 0);
12242 }
12243- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
12244+ print_ftrace_graph_addr(addr, data, ops, task, graph);
12245 }
12246 stack++;
12247 }
12248@@ -180,7 +180,7 @@ void dump_stack(void)
12249 #endif
12250
12251 printk("Pid: %d, comm: %.20s %s %s %.*s\n",
12252- current->pid, current->comm, print_tainted(),
12253+ task_pid_nr(current), current->comm, print_tainted(),
12254 init_utsname()->release,
12255 (int)strcspn(init_utsname()->version, " "),
12256 init_utsname()->version);
12257@@ -220,6 +220,8 @@ unsigned __kprobes long oops_begin(void)
12258 return flags;
12259 }
12260
12261+extern void gr_handle_kernel_exploit(void);
12262+
12263 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
12264 {
12265 if (regs && kexec_should_crash(current))
12266@@ -241,7 +243,10 @@ void __kprobes oops_end(unsigned long fl
12267 panic("Fatal exception in interrupt");
12268 if (panic_on_oops)
12269 panic("Fatal exception");
12270- do_exit(signr);
12271+
12272+ gr_handle_kernel_exploit();
12273+
12274+ do_group_exit(signr);
12275 }
12276
12277 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
12278@@ -295,7 +300,7 @@ void die(const char *str, struct pt_regs
12279 unsigned long flags = oops_begin();
12280 int sig = SIGSEGV;
12281
12282- if (!user_mode_vm(regs))
12283+ if (!user_mode(regs))
12284 report_bug(regs->ip, regs);
12285
12286 if (__die(str, regs, err))
12287diff -urNp linux-2.6.32.41/arch/x86/kernel/dumpstack.h linux-2.6.32.41/arch/x86/kernel/dumpstack.h
12288--- linux-2.6.32.41/arch/x86/kernel/dumpstack.h 2011-03-27 14:31:47.000000000 -0400
12289+++ linux-2.6.32.41/arch/x86/kernel/dumpstack.h 2011-04-23 13:25:26.000000000 -0400
12290@@ -15,7 +15,7 @@
12291 #endif
12292
12293 extern unsigned long
12294-print_context_stack(struct thread_info *tinfo,
12295+print_context_stack(struct task_struct *task, void *stack_start,
12296 unsigned long *stack, unsigned long bp,
12297 const struct stacktrace_ops *ops, void *data,
12298 unsigned long *end, int *graph);
12299diff -urNp linux-2.6.32.41/arch/x86/kernel/e820.c linux-2.6.32.41/arch/x86/kernel/e820.c
12300--- linux-2.6.32.41/arch/x86/kernel/e820.c 2011-03-27 14:31:47.000000000 -0400
12301+++ linux-2.6.32.41/arch/x86/kernel/e820.c 2011-04-17 15:56:46.000000000 -0400
12302@@ -733,7 +733,7 @@ struct early_res {
12303 };
12304 static struct early_res early_res[MAX_EARLY_RES] __initdata = {
12305 { 0, PAGE_SIZE, "BIOS data page" }, /* BIOS data page */
12306- {}
12307+ { 0, 0, {0}, 0 }
12308 };
12309
12310 static int __init find_overlapped_early(u64 start, u64 end)
12311diff -urNp linux-2.6.32.41/arch/x86/kernel/early_printk.c linux-2.6.32.41/arch/x86/kernel/early_printk.c
12312--- linux-2.6.32.41/arch/x86/kernel/early_printk.c 2011-03-27 14:31:47.000000000 -0400
12313+++ linux-2.6.32.41/arch/x86/kernel/early_printk.c 2011-05-16 21:46:57.000000000 -0400
12314@@ -7,6 +7,7 @@
12315 #include <linux/pci_regs.h>
12316 #include <linux/pci_ids.h>
12317 #include <linux/errno.h>
12318+#include <linux/sched.h>
12319 #include <asm/io.h>
12320 #include <asm/processor.h>
12321 #include <asm/fcntl.h>
12322@@ -170,6 +171,8 @@ asmlinkage void early_printk(const char
12323 int n;
12324 va_list ap;
12325
12326+ pax_track_stack();
12327+
12328 va_start(ap, fmt);
12329 n = vscnprintf(buf, sizeof(buf), fmt, ap);
12330 early_console->write(early_console, buf, n);
12331diff -urNp linux-2.6.32.41/arch/x86/kernel/efi_32.c linux-2.6.32.41/arch/x86/kernel/efi_32.c
12332--- linux-2.6.32.41/arch/x86/kernel/efi_32.c 2011-03-27 14:31:47.000000000 -0400
12333+++ linux-2.6.32.41/arch/x86/kernel/efi_32.c 2011-04-17 15:56:46.000000000 -0400
12334@@ -38,70 +38,38 @@
12335 */
12336
12337 static unsigned long efi_rt_eflags;
12338-static pgd_t efi_bak_pg_dir_pointer[2];
12339+static pgd_t __initdata efi_bak_pg_dir_pointer[KERNEL_PGD_PTRS];
12340
12341-void efi_call_phys_prelog(void)
12342+void __init efi_call_phys_prelog(void)
12343 {
12344- unsigned long cr4;
12345- unsigned long temp;
12346 struct desc_ptr gdt_descr;
12347
12348 local_irq_save(efi_rt_eflags);
12349
12350- /*
12351- * If I don't have PAE, I should just duplicate two entries in page
12352- * directory. If I have PAE, I just need to duplicate one entry in
12353- * page directory.
12354- */
12355- cr4 = read_cr4_safe();
12356
12357- if (cr4 & X86_CR4_PAE) {
12358- efi_bak_pg_dir_pointer[0].pgd =
12359- swapper_pg_dir[pgd_index(0)].pgd;
12360- swapper_pg_dir[0].pgd =
12361- swapper_pg_dir[pgd_index(PAGE_OFFSET)].pgd;
12362- } else {
12363- efi_bak_pg_dir_pointer[0].pgd =
12364- swapper_pg_dir[pgd_index(0)].pgd;
12365- efi_bak_pg_dir_pointer[1].pgd =
12366- swapper_pg_dir[pgd_index(0x400000)].pgd;
12367- swapper_pg_dir[pgd_index(0)].pgd =
12368- swapper_pg_dir[pgd_index(PAGE_OFFSET)].pgd;
12369- temp = PAGE_OFFSET + 0x400000;
12370- swapper_pg_dir[pgd_index(0x400000)].pgd =
12371- swapper_pg_dir[pgd_index(temp)].pgd;
12372- }
12373+ clone_pgd_range(efi_bak_pg_dir_pointer, swapper_pg_dir, KERNEL_PGD_PTRS);
12374+ clone_pgd_range(swapper_pg_dir, swapper_pg_dir + KERNEL_PGD_BOUNDARY,
12375+ min_t(unsigned long, KERNEL_PGD_PTRS, KERNEL_PGD_BOUNDARY));
12376
12377 /*
12378 * After the lock is released, the original page table is restored.
12379 */
12380 __flush_tlb_all();
12381
12382- gdt_descr.address = __pa(get_cpu_gdt_table(0));
12383+ gdt_descr.address = (struct desc_struct *)__pa(get_cpu_gdt_table(0));
12384 gdt_descr.size = GDT_SIZE - 1;
12385 load_gdt(&gdt_descr);
12386 }
12387
12388-void efi_call_phys_epilog(void)
12389+void __init efi_call_phys_epilog(void)
12390 {
12391- unsigned long cr4;
12392 struct desc_ptr gdt_descr;
12393
12394- gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
12395+ gdt_descr.address = get_cpu_gdt_table(0);
12396 gdt_descr.size = GDT_SIZE - 1;
12397 load_gdt(&gdt_descr);
12398
12399- cr4 = read_cr4_safe();
12400-
12401- if (cr4 & X86_CR4_PAE) {
12402- swapper_pg_dir[pgd_index(0)].pgd =
12403- efi_bak_pg_dir_pointer[0].pgd;
12404- } else {
12405- swapper_pg_dir[pgd_index(0)].pgd =
12406- efi_bak_pg_dir_pointer[0].pgd;
12407- swapper_pg_dir[pgd_index(0x400000)].pgd =
12408- efi_bak_pg_dir_pointer[1].pgd;
12409- }
12410+ clone_pgd_range(swapper_pg_dir, efi_bak_pg_dir_pointer, KERNEL_PGD_PTRS);
12411
12412 /*
12413 * After the lock is released, the original page table is restored.
12414diff -urNp linux-2.6.32.41/arch/x86/kernel/efi_stub_32.S linux-2.6.32.41/arch/x86/kernel/efi_stub_32.S
12415--- linux-2.6.32.41/arch/x86/kernel/efi_stub_32.S 2011-03-27 14:31:47.000000000 -0400
12416+++ linux-2.6.32.41/arch/x86/kernel/efi_stub_32.S 2011-04-17 15:56:46.000000000 -0400
12417@@ -6,6 +6,7 @@
12418 */
12419
12420 #include <linux/linkage.h>
12421+#include <linux/init.h>
12422 #include <asm/page_types.h>
12423
12424 /*
12425@@ -20,7 +21,7 @@
12426 * service functions will comply with gcc calling convention, too.
12427 */
12428
12429-.text
12430+__INIT
12431 ENTRY(efi_call_phys)
12432 /*
12433 * 0. The function can only be called in Linux kernel. So CS has been
12434@@ -36,9 +37,7 @@ ENTRY(efi_call_phys)
12435 * The mapping of lower virtual memory has been created in prelog and
12436 * epilog.
12437 */
12438- movl $1f, %edx
12439- subl $__PAGE_OFFSET, %edx
12440- jmp *%edx
12441+ jmp 1f-__PAGE_OFFSET
12442 1:
12443
12444 /*
12445@@ -47,14 +46,8 @@ ENTRY(efi_call_phys)
12446 * parameter 2, ..., param n. To make things easy, we save the return
12447 * address of efi_call_phys in a global variable.
12448 */
12449- popl %edx
12450- movl %edx, saved_return_addr
12451- /* get the function pointer into ECX*/
12452- popl %ecx
12453- movl %ecx, efi_rt_function_ptr
12454- movl $2f, %edx
12455- subl $__PAGE_OFFSET, %edx
12456- pushl %edx
12457+ popl (saved_return_addr)
12458+ popl (efi_rt_function_ptr)
12459
12460 /*
12461 * 3. Clear PG bit in %CR0.
12462@@ -73,9 +66,8 @@ ENTRY(efi_call_phys)
12463 /*
12464 * 5. Call the physical function.
12465 */
12466- jmp *%ecx
12467+ call *(efi_rt_function_ptr-__PAGE_OFFSET)
12468
12469-2:
12470 /*
12471 * 6. After EFI runtime service returns, control will return to
12472 * following instruction. We'd better readjust stack pointer first.
12473@@ -88,35 +80,28 @@ ENTRY(efi_call_phys)
12474 movl %cr0, %edx
12475 orl $0x80000000, %edx
12476 movl %edx, %cr0
12477- jmp 1f
12478-1:
12479+
12480 /*
12481 * 8. Now restore the virtual mode from flat mode by
12482 * adding EIP with PAGE_OFFSET.
12483 */
12484- movl $1f, %edx
12485- jmp *%edx
12486+ jmp 1f+__PAGE_OFFSET
12487 1:
12488
12489 /*
12490 * 9. Balance the stack. And because EAX contain the return value,
12491 * we'd better not clobber it.
12492 */
12493- leal efi_rt_function_ptr, %edx
12494- movl (%edx), %ecx
12495- pushl %ecx
12496+ pushl (efi_rt_function_ptr)
12497
12498 /*
12499- * 10. Push the saved return address onto the stack and return.
12500+ * 10. Return to the saved return address.
12501 */
12502- leal saved_return_addr, %edx
12503- movl (%edx), %ecx
12504- pushl %ecx
12505- ret
12506+ jmpl *(saved_return_addr)
12507 ENDPROC(efi_call_phys)
12508 .previous
12509
12510-.data
12511+__INITDATA
12512 saved_return_addr:
12513 .long 0
12514 efi_rt_function_ptr:
12515diff -urNp linux-2.6.32.41/arch/x86/kernel/entry_32.S linux-2.6.32.41/arch/x86/kernel/entry_32.S
12516--- linux-2.6.32.41/arch/x86/kernel/entry_32.S 2011-03-27 14:31:47.000000000 -0400
12517+++ linux-2.6.32.41/arch/x86/kernel/entry_32.S 2011-05-22 23:02:03.000000000 -0400
12518@@ -185,13 +185,146 @@
12519 /*CFI_REL_OFFSET gs, PT_GS*/
12520 .endm
12521 .macro SET_KERNEL_GS reg
12522+
12523+#ifdef CONFIG_CC_STACKPROTECTOR
12524 movl $(__KERNEL_STACK_CANARY), \reg
12525+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
12526+ movl $(__USER_DS), \reg
12527+#else
12528+ xorl \reg, \reg
12529+#endif
12530+
12531 movl \reg, %gs
12532 .endm
12533
12534 #endif /* CONFIG_X86_32_LAZY_GS */
12535
12536-.macro SAVE_ALL
12537+.macro pax_enter_kernel
12538+#ifdef CONFIG_PAX_KERNEXEC
12539+ call pax_enter_kernel
12540+#endif
12541+.endm
12542+
12543+.macro pax_exit_kernel
12544+#ifdef CONFIG_PAX_KERNEXEC
12545+ call pax_exit_kernel
12546+#endif
12547+.endm
12548+
12549+#ifdef CONFIG_PAX_KERNEXEC
12550+ENTRY(pax_enter_kernel)
12551+#ifdef CONFIG_PARAVIRT
12552+ pushl %eax
12553+ pushl %ecx
12554+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
12555+ mov %eax, %esi
12556+#else
12557+ mov %cr0, %esi
12558+#endif
12559+ bts $16, %esi
12560+ jnc 1f
12561+ mov %cs, %esi
12562+ cmp $__KERNEL_CS, %esi
12563+ jz 3f
12564+ ljmp $__KERNEL_CS, $3f
12565+1: ljmp $__KERNEXEC_KERNEL_CS, $2f
12566+2:
12567+#ifdef CONFIG_PARAVIRT
12568+ mov %esi, %eax
12569+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
12570+#else
12571+ mov %esi, %cr0
12572+#endif
12573+3:
12574+#ifdef CONFIG_PARAVIRT
12575+ popl %ecx
12576+ popl %eax
12577+#endif
12578+ ret
12579+ENDPROC(pax_enter_kernel)
12580+
12581+ENTRY(pax_exit_kernel)
12582+#ifdef CONFIG_PARAVIRT
12583+ pushl %eax
12584+ pushl %ecx
12585+#endif
12586+ mov %cs, %esi
12587+ cmp $__KERNEXEC_KERNEL_CS, %esi
12588+ jnz 2f
12589+#ifdef CONFIG_PARAVIRT
12590+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
12591+ mov %eax, %esi
12592+#else
12593+ mov %cr0, %esi
12594+#endif
12595+ btr $16, %esi
12596+ ljmp $__KERNEL_CS, $1f
12597+1:
12598+#ifdef CONFIG_PARAVIRT
12599+ mov %esi, %eax
12600+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
12601+#else
12602+ mov %esi, %cr0
12603+#endif
12604+2:
12605+#ifdef CONFIG_PARAVIRT
12606+ popl %ecx
12607+ popl %eax
12608+#endif
12609+ ret
12610+ENDPROC(pax_exit_kernel)
12611+#endif
12612+
12613+.macro pax_erase_kstack
12614+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
12615+ call pax_erase_kstack
12616+#endif
12617+.endm
12618+
12619+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
12620+/*
12621+ * ebp: thread_info
12622+ * ecx, edx: can be clobbered
12623+ */
12624+ENTRY(pax_erase_kstack)
12625+ pushl %edi
12626+ pushl %eax
12627+
12628+ mov TI_lowest_stack(%ebp), %edi
12629+ mov $-0xBEEF, %eax
12630+ std
12631+
12632+1: mov %edi, %ecx
12633+ and $THREAD_SIZE_asm - 1, %ecx
12634+ shr $2, %ecx
12635+ repne scasl
12636+ jecxz 2f
12637+
12638+ cmp $2*16, %ecx
12639+ jc 2f
12640+
12641+ mov $2*16, %ecx
12642+ repe scasl
12643+ jecxz 2f
12644+ jne 1b
12645+
12646+2: cld
12647+ mov %esp, %ecx
12648+ sub %edi, %ecx
12649+ shr $2, %ecx
12650+ rep stosl
12651+
12652+ mov TI_task_thread_sp0(%ebp), %edi
12653+ sub $128, %edi
12654+ mov %edi, TI_lowest_stack(%ebp)
12655+
12656+ popl %eax
12657+ popl %edi
12658+ ret
12659+ENDPROC(pax_erase_kstack)
12660+#endif
12661+
12662+.macro __SAVE_ALL _DS
12663 cld
12664 PUSH_GS
12665 pushl %fs
12666@@ -224,7 +357,7 @@
12667 pushl %ebx
12668 CFI_ADJUST_CFA_OFFSET 4
12669 CFI_REL_OFFSET ebx, 0
12670- movl $(__USER_DS), %edx
12671+ movl $\_DS, %edx
12672 movl %edx, %ds
12673 movl %edx, %es
12674 movl $(__KERNEL_PERCPU), %edx
12675@@ -232,6 +365,15 @@
12676 SET_KERNEL_GS %edx
12677 .endm
12678
12679+.macro SAVE_ALL
12680+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
12681+ __SAVE_ALL __KERNEL_DS
12682+ pax_enter_kernel
12683+#else
12684+ __SAVE_ALL __USER_DS
12685+#endif
12686+.endm
12687+
12688 .macro RESTORE_INT_REGS
12689 popl %ebx
12690 CFI_ADJUST_CFA_OFFSET -4
12691@@ -352,7 +494,15 @@ check_userspace:
12692 movb PT_CS(%esp), %al
12693 andl $(X86_EFLAGS_VM | SEGMENT_RPL_MASK), %eax
12694 cmpl $USER_RPL, %eax
12695+
12696+#ifdef CONFIG_PAX_KERNEXEC
12697+ jae resume_userspace
12698+
12699+ PAX_EXIT_KERNEL
12700+ jmp resume_kernel
12701+#else
12702 jb resume_kernel # not returning to v8086 or userspace
12703+#endif
12704
12705 ENTRY(resume_userspace)
12706 LOCKDEP_SYS_EXIT
12707@@ -364,7 +514,7 @@ ENTRY(resume_userspace)
12708 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
12709 # int/exception return?
12710 jne work_pending
12711- jmp restore_all
12712+ jmp restore_all_pax
12713 END(ret_from_exception)
12714
12715 #ifdef CONFIG_PREEMPT
12716@@ -414,25 +564,36 @@ sysenter_past_esp:
12717 /*CFI_REL_OFFSET cs, 0*/
12718 /*
12719 * Push current_thread_info()->sysenter_return to the stack.
12720- * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
12721- * pushed above; +8 corresponds to copy_thread's esp0 setting.
12722 */
12723- pushl (TI_sysenter_return-THREAD_SIZE+8+4*4)(%esp)
12724+ pushl $0
12725 CFI_ADJUST_CFA_OFFSET 4
12726 CFI_REL_OFFSET eip, 0
12727
12728 pushl %eax
12729 CFI_ADJUST_CFA_OFFSET 4
12730 SAVE_ALL
12731+ GET_THREAD_INFO(%ebp)
12732+ movl TI_sysenter_return(%ebp),%ebp
12733+ movl %ebp,PT_EIP(%esp)
12734 ENABLE_INTERRUPTS(CLBR_NONE)
12735
12736 /*
12737 * Load the potential sixth argument from user stack.
12738 * Careful about security.
12739 */
12740+ movl PT_OLDESP(%esp),%ebp
12741+
12742+#ifdef CONFIG_PAX_MEMORY_UDEREF
12743+ mov PT_OLDSS(%esp),%ds
12744+1: movl %ds:(%ebp),%ebp
12745+ push %ss
12746+ pop %ds
12747+#else
12748 cmpl $__PAGE_OFFSET-3,%ebp
12749 jae syscall_fault
12750 1: movl (%ebp),%ebp
12751+#endif
12752+
12753 movl %ebp,PT_EBP(%esp)
12754 .section __ex_table,"a"
12755 .align 4
12756@@ -455,12 +616,23 @@ sysenter_do_call:
12757 testl $_TIF_ALLWORK_MASK, %ecx
12758 jne sysexit_audit
12759 sysenter_exit:
12760+
12761+#ifdef CONFIG_PAX_RANDKSTACK
12762+ pushl_cfi %eax
12763+ call pax_randomize_kstack
12764+ popl_cfi %eax
12765+#endif
12766+
12767+ pax_erase_kstack
12768+
12769 /* if something modifies registers it must also disable sysexit */
12770 movl PT_EIP(%esp), %edx
12771 movl PT_OLDESP(%esp), %ecx
12772 xorl %ebp,%ebp
12773 TRACE_IRQS_ON
12774 1: mov PT_FS(%esp), %fs
12775+2: mov PT_DS(%esp), %ds
12776+3: mov PT_ES(%esp), %es
12777 PTGS_TO_GS
12778 ENABLE_INTERRUPTS_SYSEXIT
12779
12780@@ -477,6 +649,9 @@ sysenter_audit:
12781 movl %eax,%edx /* 2nd arg: syscall number */
12782 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
12783 call audit_syscall_entry
12784+
12785+ pax_erase_kstack
12786+
12787 pushl %ebx
12788 CFI_ADJUST_CFA_OFFSET 4
12789 movl PT_EAX(%esp),%eax /* reload syscall number */
12790@@ -504,11 +679,17 @@ sysexit_audit:
12791
12792 CFI_ENDPROC
12793 .pushsection .fixup,"ax"
12794-2: movl $0,PT_FS(%esp)
12795+4: movl $0,PT_FS(%esp)
12796+ jmp 1b
12797+5: movl $0,PT_DS(%esp)
12798+ jmp 1b
12799+6: movl $0,PT_ES(%esp)
12800 jmp 1b
12801 .section __ex_table,"a"
12802 .align 4
12803- .long 1b,2b
12804+ .long 1b,4b
12805+ .long 2b,5b
12806+ .long 3b,6b
12807 .popsection
12808 PTGS_TO_GS_EX
12809 ENDPROC(ia32_sysenter_target)
12810@@ -538,6 +719,14 @@ syscall_exit:
12811 testl $_TIF_ALLWORK_MASK, %ecx # current->work
12812 jne syscall_exit_work
12813
12814+restore_all_pax:
12815+
12816+#ifdef CONFIG_PAX_RANDKSTACK
12817+ call pax_randomize_kstack
12818+#endif
12819+
12820+ pax_erase_kstack
12821+
12822 restore_all:
12823 TRACE_IRQS_IRET
12824 restore_all_notrace:
12825@@ -602,7 +791,13 @@ ldt_ss:
12826 mov PT_OLDESP(%esp), %eax /* load userspace esp */
12827 mov %dx, %ax /* eax: new kernel esp */
12828 sub %eax, %edx /* offset (low word is 0) */
12829- PER_CPU(gdt_page, %ebx)
12830+#ifdef CONFIG_SMP
12831+ movl PER_CPU_VAR(cpu_number), %ebx
12832+ shll $PAGE_SHIFT_asm, %ebx
12833+ addl $cpu_gdt_table, %ebx
12834+#else
12835+ movl $cpu_gdt_table, %ebx
12836+#endif
12837 shr $16, %edx
12838 mov %dl, GDT_ENTRY_ESPFIX_SS * 8 + 4(%ebx) /* bits 16..23 */
12839 mov %dh, GDT_ENTRY_ESPFIX_SS * 8 + 7(%ebx) /* bits 24..31 */
12840@@ -636,31 +831,25 @@ work_resched:
12841 movl TI_flags(%ebp), %ecx
12842 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
12843 # than syscall tracing?
12844- jz restore_all
12845+ jz restore_all_pax
12846 testb $_TIF_NEED_RESCHED, %cl
12847 jnz work_resched
12848
12849 work_notifysig: # deal with pending signals and
12850 # notify-resume requests
12851+ movl %esp, %eax
12852 #ifdef CONFIG_VM86
12853 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
12854- movl %esp, %eax
12855- jne work_notifysig_v86 # returning to kernel-space or
12856+ jz 1f # returning to kernel-space or
12857 # vm86-space
12858- xorl %edx, %edx
12859- call do_notify_resume
12860- jmp resume_userspace_sig
12861
12862- ALIGN
12863-work_notifysig_v86:
12864 pushl %ecx # save ti_flags for do_notify_resume
12865 CFI_ADJUST_CFA_OFFSET 4
12866 call save_v86_state # %eax contains pt_regs pointer
12867 popl %ecx
12868 CFI_ADJUST_CFA_OFFSET -4
12869 movl %eax, %esp
12870-#else
12871- movl %esp, %eax
12872+1:
12873 #endif
12874 xorl %edx, %edx
12875 call do_notify_resume
12876@@ -673,6 +862,9 @@ syscall_trace_entry:
12877 movl $-ENOSYS,PT_EAX(%esp)
12878 movl %esp, %eax
12879 call syscall_trace_enter
12880+
12881+ pax_erase_kstack
12882+
12883 /* What it returned is what we'll actually use. */
12884 cmpl $(nr_syscalls), %eax
12885 jnae syscall_call
12886@@ -695,6 +887,10 @@ END(syscall_exit_work)
12887
12888 RING0_INT_FRAME # can't unwind into user space anyway
12889 syscall_fault:
12890+#ifdef CONFIG_PAX_MEMORY_UDEREF
12891+ push %ss
12892+ pop %ds
12893+#endif
12894 GET_THREAD_INFO(%ebp)
12895 movl $-EFAULT,PT_EAX(%esp)
12896 jmp resume_userspace
12897@@ -726,6 +922,33 @@ PTREGSCALL(rt_sigreturn)
12898 PTREGSCALL(vm86)
12899 PTREGSCALL(vm86old)
12900
12901+ ALIGN;
12902+ENTRY(kernel_execve)
12903+ push %ebp
12904+ sub $PT_OLDSS+4,%esp
12905+ push %edi
12906+ push %ecx
12907+ push %eax
12908+ lea 3*4(%esp),%edi
12909+ mov $PT_OLDSS/4+1,%ecx
12910+ xorl %eax,%eax
12911+ rep stosl
12912+ pop %eax
12913+ pop %ecx
12914+ pop %edi
12915+ movl $X86_EFLAGS_IF,PT_EFLAGS(%esp)
12916+ mov %eax,PT_EBX(%esp)
12917+ mov %edx,PT_ECX(%esp)
12918+ mov %ecx,PT_EDX(%esp)
12919+ mov %esp,%eax
12920+ call sys_execve
12921+ GET_THREAD_INFO(%ebp)
12922+ test %eax,%eax
12923+ jz syscall_exit
12924+ add $PT_OLDSS+4,%esp
12925+ pop %ebp
12926+ ret
12927+
12928 .macro FIXUP_ESPFIX_STACK
12929 /*
12930 * Switch back for ESPFIX stack to the normal zerobased stack
12931@@ -735,7 +958,13 @@ PTREGSCALL(vm86old)
12932 * normal stack and adjusts ESP with the matching offset.
12933 */
12934 /* fixup the stack */
12935- PER_CPU(gdt_page, %ebx)
12936+#ifdef CONFIG_SMP
12937+ movl PER_CPU_VAR(cpu_number), %ebx
12938+ shll $PAGE_SHIFT_asm, %ebx
12939+ addl $cpu_gdt_table, %ebx
12940+#else
12941+ movl $cpu_gdt_table, %ebx
12942+#endif
12943 mov GDT_ENTRY_ESPFIX_SS * 8 + 4(%ebx), %al /* bits 16..23 */
12944 mov GDT_ENTRY_ESPFIX_SS * 8 + 7(%ebx), %ah /* bits 24..31 */
12945 shl $16, %eax
12946@@ -1198,7 +1427,6 @@ return_to_handler:
12947 ret
12948 #endif
12949
12950-.section .rodata,"a"
12951 #include "syscall_table_32.S"
12952
12953 syscall_table_size=(.-sys_call_table)
12954@@ -1255,9 +1483,12 @@ error_code:
12955 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
12956 REG_TO_PTGS %ecx
12957 SET_KERNEL_GS %ecx
12958- movl $(__USER_DS), %ecx
12959+ movl $(__KERNEL_DS), %ecx
12960 movl %ecx, %ds
12961 movl %ecx, %es
12962+
12963+ pax_enter_kernel
12964+
12965 TRACE_IRQS_OFF
12966 movl %esp,%eax # pt_regs pointer
12967 call *%edi
12968@@ -1351,6 +1582,9 @@ nmi_stack_correct:
12969 xorl %edx,%edx # zero error code
12970 movl %esp,%eax # pt_regs pointer
12971 call do_nmi
12972+
12973+ pax_exit_kernel
12974+
12975 jmp restore_all_notrace
12976 CFI_ENDPROC
12977
12978@@ -1391,6 +1625,9 @@ nmi_espfix_stack:
12979 FIXUP_ESPFIX_STACK # %eax == %esp
12980 xorl %edx,%edx # zero error code
12981 call do_nmi
12982+
12983+ pax_exit_kernel
12984+
12985 RESTORE_REGS
12986 lss 12+4(%esp), %esp # back to espfix stack
12987 CFI_ADJUST_CFA_OFFSET -24
12988diff -urNp linux-2.6.32.41/arch/x86/kernel/entry_64.S linux-2.6.32.41/arch/x86/kernel/entry_64.S
12989--- linux-2.6.32.41/arch/x86/kernel/entry_64.S 2011-03-27 14:31:47.000000000 -0400
12990+++ linux-2.6.32.41/arch/x86/kernel/entry_64.S 2011-06-04 20:30:53.000000000 -0400
12991@@ -53,6 +53,7 @@
12992 #include <asm/paravirt.h>
12993 #include <asm/ftrace.h>
12994 #include <asm/percpu.h>
12995+#include <asm/pgtable.h>
12996
12997 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
12998 #include <linux/elf-em.h>
12999@@ -174,6 +175,257 @@ ENTRY(native_usergs_sysret64)
13000 ENDPROC(native_usergs_sysret64)
13001 #endif /* CONFIG_PARAVIRT */
13002
13003+ .macro ljmpq sel, off
13004+#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
13005+ .byte 0x48; ljmp *1234f(%rip)
13006+ .pushsection .rodata
13007+ .align 16
13008+ 1234: .quad \off; .word \sel
13009+ .popsection
13010+#else
13011+ pushq $\sel
13012+ pushq $\off
13013+ lretq
13014+#endif
13015+ .endm
13016+
13017+ .macro pax_enter_kernel
13018+#ifdef CONFIG_PAX_KERNEXEC
13019+ call pax_enter_kernel
13020+#endif
13021+ .endm
13022+
13023+ .macro pax_exit_kernel
13024+#ifdef CONFIG_PAX_KERNEXEC
13025+ call pax_exit_kernel
13026+#endif
13027+ .endm
13028+
13029+#ifdef CONFIG_PAX_KERNEXEC
13030+ENTRY(pax_enter_kernel)
13031+ pushq %rdi
13032+
13033+#ifdef CONFIG_PARAVIRT
13034+ PV_SAVE_REGS(CLBR_RDI)
13035+#endif
13036+
13037+ GET_CR0_INTO_RDI
13038+ bts $16,%rdi
13039+ jnc 1f
13040+ mov %cs,%edi
13041+ cmp $__KERNEL_CS,%edi
13042+ jz 3f
13043+ ljmpq __KERNEL_CS,3f
13044+1: ljmpq __KERNEXEC_KERNEL_CS,2f
13045+2: SET_RDI_INTO_CR0
13046+3:
13047+
13048+#ifdef CONFIG_PARAVIRT
13049+ PV_RESTORE_REGS(CLBR_RDI)
13050+#endif
13051+
13052+ popq %rdi
13053+ retq
13054+ENDPROC(pax_enter_kernel)
13055+
13056+ENTRY(pax_exit_kernel)
13057+ pushq %rdi
13058+
13059+#ifdef CONFIG_PARAVIRT
13060+ PV_SAVE_REGS(CLBR_RDI)
13061+#endif
13062+
13063+ mov %cs,%rdi
13064+ cmp $__KERNEXEC_KERNEL_CS,%edi
13065+ jnz 2f
13066+ GET_CR0_INTO_RDI
13067+ btr $16,%rdi
13068+ ljmpq __KERNEL_CS,1f
13069+1: SET_RDI_INTO_CR0
13070+2:
13071+
13072+#ifdef CONFIG_PARAVIRT
13073+ PV_RESTORE_REGS(CLBR_RDI);
13074+#endif
13075+
13076+ popq %rdi
13077+ retq
13078+ENDPROC(pax_exit_kernel)
13079+#endif
13080+
13081+ .macro pax_enter_kernel_user
13082+#ifdef CONFIG_PAX_MEMORY_UDEREF
13083+ call pax_enter_kernel_user
13084+#endif
13085+ .endm
13086+
13087+ .macro pax_exit_kernel_user
13088+#ifdef CONFIG_PAX_MEMORY_UDEREF
13089+ call pax_exit_kernel_user
13090+#endif
13091+#ifdef CONFIG_PAX_RANDKSTACK
13092+ push %rax
13093+ call pax_randomize_kstack
13094+ pop %rax
13095+#endif
13096+ pax_erase_kstack
13097+ .endm
13098+
13099+#ifdef CONFIG_PAX_MEMORY_UDEREF
13100+ENTRY(pax_enter_kernel_user)
13101+ pushq %rdi
13102+ pushq %rbx
13103+
13104+#ifdef CONFIG_PARAVIRT
13105+ PV_SAVE_REGS(CLBR_RDI)
13106+#endif
13107+
13108+ GET_CR3_INTO_RDI
13109+ mov %rdi,%rbx
13110+ add $__START_KERNEL_map,%rbx
13111+ sub phys_base(%rip),%rbx
13112+
13113+#ifdef CONFIG_PARAVIRT
13114+ pushq %rdi
13115+ cmpl $0, pv_info+PARAVIRT_enabled
13116+ jz 1f
13117+ i = 0
13118+ .rept USER_PGD_PTRS
13119+ mov i*8(%rbx),%rsi
13120+ mov $0,%sil
13121+ lea i*8(%rbx),%rdi
13122+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd)
13123+ i = i + 1
13124+ .endr
13125+ jmp 2f
13126+1:
13127+#endif
13128+
13129+ i = 0
13130+ .rept USER_PGD_PTRS
13131+ movb $0,i*8(%rbx)
13132+ i = i + 1
13133+ .endr
13134+
13135+#ifdef CONFIG_PARAVIRT
13136+2: popq %rdi
13137+#endif
13138+ SET_RDI_INTO_CR3
13139+
13140+#ifdef CONFIG_PAX_KERNEXEC
13141+ GET_CR0_INTO_RDI
13142+ bts $16,%rdi
13143+ SET_RDI_INTO_CR0
13144+#endif
13145+
13146+#ifdef CONFIG_PARAVIRT
13147+ PV_RESTORE_REGS(CLBR_RDI)
13148+#endif
13149+
13150+ popq %rbx
13151+ popq %rdi
13152+ retq
13153+ENDPROC(pax_enter_kernel_user)
13154+
13155+ENTRY(pax_exit_kernel_user)
13156+ push %rdi
13157+
13158+#ifdef CONFIG_PARAVIRT
13159+ pushq %rbx
13160+ PV_SAVE_REGS(CLBR_RDI)
13161+#endif
13162+
13163+#ifdef CONFIG_PAX_KERNEXEC
13164+ GET_CR0_INTO_RDI
13165+ btr $16,%rdi
13166+ SET_RDI_INTO_CR0
13167+#endif
13168+
13169+ GET_CR3_INTO_RDI
13170+ add $__START_KERNEL_map,%rdi
13171+ sub phys_base(%rip),%rdi
13172+
13173+#ifdef CONFIG_PARAVIRT
13174+ cmpl $0, pv_info+PARAVIRT_enabled
13175+ jz 1f
13176+ mov %rdi,%rbx
13177+ i = 0
13178+ .rept USER_PGD_PTRS
13179+ mov i*8(%rbx),%rsi
13180+ mov $0x67,%sil
13181+ lea i*8(%rbx),%rdi
13182+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd)
13183+ i = i + 1
13184+ .endr
13185+ jmp 2f
13186+1:
13187+#endif
13188+
13189+ i = 0
13190+ .rept USER_PGD_PTRS
13191+ movb $0x67,i*8(%rdi)
13192+ i = i + 1
13193+ .endr
13194+
13195+#ifdef CONFIG_PARAVIRT
13196+2: PV_RESTORE_REGS(CLBR_RDI)
13197+ popq %rbx
13198+#endif
13199+
13200+ popq %rdi
13201+ retq
13202+ENDPROC(pax_exit_kernel_user)
13203+#endif
13204+
13205+.macro pax_erase_kstack
13206+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
13207+ call pax_erase_kstack
13208+#endif
13209+.endm
13210+
13211+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
13212+/*
13213+ * r10: thread_info
13214+ * rcx, rdx: can be clobbered
13215+ */
13216+ENTRY(pax_erase_kstack)
13217+ pushq %rdi
13218+ pushq %rax
13219+
13220+ GET_THREAD_INFO(%r10)
13221+ mov TI_lowest_stack(%r10), %rdi
13222+ mov $-0xBEEF, %rax
13223+ std
13224+
13225+1: mov %edi, %ecx
13226+ and $THREAD_SIZE_asm - 1, %ecx
13227+ shr $3, %ecx
13228+ repne scasq
13229+ jecxz 2f
13230+
13231+ cmp $2*8, %ecx
13232+ jc 2f
13233+
13234+ mov $2*8, %ecx
13235+ repe scasq
13236+ jecxz 2f
13237+ jne 1b
13238+
13239+2: cld
13240+ mov %esp, %ecx
13241+ sub %edi, %ecx
13242+ shr $3, %ecx
13243+ rep stosq
13244+
13245+ mov TI_task_thread_sp0(%r10), %rdi
13246+ sub $256, %rdi
13247+ mov %rdi, TI_lowest_stack(%r10)
13248+
13249+ popq %rax
13250+ popq %rdi
13251+ ret
13252+ENDPROC(pax_erase_kstack)
13253+#endif
13254
13255 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
13256 #ifdef CONFIG_TRACE_IRQFLAGS
13257@@ -317,7 +569,7 @@ ENTRY(save_args)
13258 leaq -ARGOFFSET+16(%rsp),%rdi /* arg1 for handler */
13259 movq_cfi rbp, 8 /* push %rbp */
13260 leaq 8(%rsp), %rbp /* mov %rsp, %ebp */
13261- testl $3, CS(%rdi)
13262+ testb $3, CS(%rdi)
13263 je 1f
13264 SWAPGS
13265 /*
13266@@ -409,7 +661,7 @@ ENTRY(ret_from_fork)
13267
13268 RESTORE_REST
13269
13270- testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
13271+ testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
13272 je int_ret_from_sys_call
13273
13274 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
13275@@ -455,7 +707,7 @@ END(ret_from_fork)
13276 ENTRY(system_call)
13277 CFI_STARTPROC simple
13278 CFI_SIGNAL_FRAME
13279- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
13280+ CFI_DEF_CFA rsp,0
13281 CFI_REGISTER rip,rcx
13282 /*CFI_REGISTER rflags,r11*/
13283 SWAPGS_UNSAFE_STACK
13284@@ -468,12 +720,13 @@ ENTRY(system_call_after_swapgs)
13285
13286 movq %rsp,PER_CPU_VAR(old_rsp)
13287 movq PER_CPU_VAR(kernel_stack),%rsp
13288+ pax_enter_kernel_user
13289 /*
13290 * No need to follow this irqs off/on section - it's straight
13291 * and short:
13292 */
13293 ENABLE_INTERRUPTS(CLBR_NONE)
13294- SAVE_ARGS 8,1
13295+ SAVE_ARGS 8*6,1
13296 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
13297 movq %rcx,RIP-ARGOFFSET(%rsp)
13298 CFI_REL_OFFSET rip,RIP-ARGOFFSET
13299@@ -502,6 +755,7 @@ sysret_check:
13300 andl %edi,%edx
13301 jnz sysret_careful
13302 CFI_REMEMBER_STATE
13303+ pax_exit_kernel_user
13304 /*
13305 * sysretq will re-enable interrupts:
13306 */
13307@@ -562,6 +816,9 @@ auditsys:
13308 movq %rax,%rsi /* 2nd arg: syscall number */
13309 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
13310 call audit_syscall_entry
13311+
13312+ pax_erase_kstack
13313+
13314 LOAD_ARGS 0 /* reload call-clobbered registers */
13315 jmp system_call_fastpath
13316
13317@@ -592,6 +849,9 @@ tracesys:
13318 FIXUP_TOP_OF_STACK %rdi
13319 movq %rsp,%rdi
13320 call syscall_trace_enter
13321+
13322+ pax_erase_kstack
13323+
13324 /*
13325 * Reload arg registers from stack in case ptrace changed them.
13326 * We don't reload %rax because syscall_trace_enter() returned
13327@@ -613,7 +873,7 @@ tracesys:
13328 GLOBAL(int_ret_from_sys_call)
13329 DISABLE_INTERRUPTS(CLBR_NONE)
13330 TRACE_IRQS_OFF
13331- testl $3,CS-ARGOFFSET(%rsp)
13332+ testb $3,CS-ARGOFFSET(%rsp)
13333 je retint_restore_args
13334 movl $_TIF_ALLWORK_MASK,%edi
13335 /* edi: mask to check */
13336@@ -800,6 +1060,16 @@ END(interrupt)
13337 CFI_ADJUST_CFA_OFFSET 10*8
13338 call save_args
13339 PARTIAL_FRAME 0
13340+#ifdef CONFIG_PAX_MEMORY_UDEREF
13341+ testb $3, CS(%rdi)
13342+ jnz 1f
13343+ pax_enter_kernel
13344+ jmp 2f
13345+1: pax_enter_kernel_user
13346+2:
13347+#else
13348+ pax_enter_kernel
13349+#endif
13350 call \func
13351 .endm
13352
13353@@ -822,7 +1092,7 @@ ret_from_intr:
13354 CFI_ADJUST_CFA_OFFSET -8
13355 exit_intr:
13356 GET_THREAD_INFO(%rcx)
13357- testl $3,CS-ARGOFFSET(%rsp)
13358+ testb $3,CS-ARGOFFSET(%rsp)
13359 je retint_kernel
13360
13361 /* Interrupt came from user space */
13362@@ -844,12 +1114,14 @@ retint_swapgs: /* return to user-space
13363 * The iretq could re-enable interrupts:
13364 */
13365 DISABLE_INTERRUPTS(CLBR_ANY)
13366+ pax_exit_kernel_user
13367 TRACE_IRQS_IRETQ
13368 SWAPGS
13369 jmp restore_args
13370
13371 retint_restore_args: /* return to kernel space */
13372 DISABLE_INTERRUPTS(CLBR_ANY)
13373+ pax_exit_kernel
13374 /*
13375 * The iretq could re-enable interrupts:
13376 */
13377@@ -1032,6 +1304,16 @@ ENTRY(\sym)
13378 CFI_ADJUST_CFA_OFFSET 15*8
13379 call error_entry
13380 DEFAULT_FRAME 0
13381+#ifdef CONFIG_PAX_MEMORY_UDEREF
13382+ testb $3, CS(%rsp)
13383+ jnz 1f
13384+ pax_enter_kernel
13385+ jmp 2f
13386+1: pax_enter_kernel_user
13387+2:
13388+#else
13389+ pax_enter_kernel
13390+#endif
13391 movq %rsp,%rdi /* pt_regs pointer */
13392 xorl %esi,%esi /* no error code */
13393 call \do_sym
13394@@ -1049,6 +1331,16 @@ ENTRY(\sym)
13395 subq $15*8, %rsp
13396 call save_paranoid
13397 TRACE_IRQS_OFF
13398+#ifdef CONFIG_PAX_MEMORY_UDEREF
13399+ testb $3, CS(%rsp)
13400+ jnz 1f
13401+ pax_enter_kernel
13402+ jmp 2f
13403+1: pax_enter_kernel_user
13404+2:
13405+#else
13406+ pax_enter_kernel
13407+#endif
13408 movq %rsp,%rdi /* pt_regs pointer */
13409 xorl %esi,%esi /* no error code */
13410 call \do_sym
13411@@ -1066,9 +1358,24 @@ ENTRY(\sym)
13412 subq $15*8, %rsp
13413 call save_paranoid
13414 TRACE_IRQS_OFF
13415+#ifdef CONFIG_PAX_MEMORY_UDEREF
13416+ testb $3, CS(%rsp)
13417+ jnz 1f
13418+ pax_enter_kernel
13419+ jmp 2f
13420+1: pax_enter_kernel_user
13421+2:
13422+#else
13423+ pax_enter_kernel
13424+#endif
13425 movq %rsp,%rdi /* pt_regs pointer */
13426 xorl %esi,%esi /* no error code */
13427- PER_CPU(init_tss, %rbp)
13428+#ifdef CONFIG_SMP
13429+ imul $TSS_size, PER_CPU_VAR(cpu_number), %ebp
13430+ lea init_tss(%rbp), %rbp
13431+#else
13432+ lea init_tss(%rip), %rbp
13433+#endif
13434 subq $EXCEPTION_STKSZ, TSS_ist + (\ist - 1) * 8(%rbp)
13435 call \do_sym
13436 addq $EXCEPTION_STKSZ, TSS_ist + (\ist - 1) * 8(%rbp)
13437@@ -1085,6 +1392,16 @@ ENTRY(\sym)
13438 CFI_ADJUST_CFA_OFFSET 15*8
13439 call error_entry
13440 DEFAULT_FRAME 0
13441+#ifdef CONFIG_PAX_MEMORY_UDEREF
13442+ testb $3, CS(%rsp)
13443+ jnz 1f
13444+ pax_enter_kernel
13445+ jmp 2f
13446+1: pax_enter_kernel_user
13447+2:
13448+#else
13449+ pax_enter_kernel
13450+#endif
13451 movq %rsp,%rdi /* pt_regs pointer */
13452 movq ORIG_RAX(%rsp),%rsi /* get error code */
13453 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
13454@@ -1104,6 +1421,16 @@ ENTRY(\sym)
13455 call save_paranoid
13456 DEFAULT_FRAME 0
13457 TRACE_IRQS_OFF
13458+#ifdef CONFIG_PAX_MEMORY_UDEREF
13459+ testb $3, CS(%rsp)
13460+ jnz 1f
13461+ pax_enter_kernel
13462+ jmp 2f
13463+1: pax_enter_kernel_user
13464+2:
13465+#else
13466+ pax_enter_kernel
13467+#endif
13468 movq %rsp,%rdi /* pt_regs pointer */
13469 movq ORIG_RAX(%rsp),%rsi /* get error code */
13470 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
13471@@ -1405,14 +1732,27 @@ ENTRY(paranoid_exit)
13472 TRACE_IRQS_OFF
13473 testl %ebx,%ebx /* swapgs needed? */
13474 jnz paranoid_restore
13475- testl $3,CS(%rsp)
13476+ testb $3,CS(%rsp)
13477 jnz paranoid_userspace
13478+#ifdef CONFIG_PAX_MEMORY_UDEREF
13479+ pax_exit_kernel
13480+ TRACE_IRQS_IRETQ 0
13481+ SWAPGS_UNSAFE_STACK
13482+ RESTORE_ALL 8
13483+ jmp irq_return
13484+#endif
13485 paranoid_swapgs:
13486+#ifdef CONFIG_PAX_MEMORY_UDEREF
13487+ pax_exit_kernel_user
13488+#else
13489+ pax_exit_kernel
13490+#endif
13491 TRACE_IRQS_IRETQ 0
13492 SWAPGS_UNSAFE_STACK
13493 RESTORE_ALL 8
13494 jmp irq_return
13495 paranoid_restore:
13496+ pax_exit_kernel
13497 TRACE_IRQS_IRETQ 0
13498 RESTORE_ALL 8
13499 jmp irq_return
13500@@ -1470,7 +1810,7 @@ ENTRY(error_entry)
13501 movq_cfi r14, R14+8
13502 movq_cfi r15, R15+8
13503 xorl %ebx,%ebx
13504- testl $3,CS+8(%rsp)
13505+ testb $3,CS+8(%rsp)
13506 je error_kernelspace
13507 error_swapgs:
13508 SWAPGS
13509@@ -1529,6 +1869,16 @@ ENTRY(nmi)
13510 CFI_ADJUST_CFA_OFFSET 15*8
13511 call save_paranoid
13512 DEFAULT_FRAME 0
13513+#ifdef CONFIG_PAX_MEMORY_UDEREF
13514+ testb $3, CS(%rsp)
13515+ jnz 1f
13516+ pax_enter_kernel
13517+ jmp 2f
13518+1: pax_enter_kernel_user
13519+2:
13520+#else
13521+ pax_enter_kernel
13522+#endif
13523 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
13524 movq %rsp,%rdi
13525 movq $-1,%rsi
13526@@ -1539,11 +1889,25 @@ ENTRY(nmi)
13527 DISABLE_INTERRUPTS(CLBR_NONE)
13528 testl %ebx,%ebx /* swapgs needed? */
13529 jnz nmi_restore
13530- testl $3,CS(%rsp)
13531+ testb $3,CS(%rsp)
13532 jnz nmi_userspace
13533+#ifdef CONFIG_PAX_MEMORY_UDEREF
13534+ pax_exit_kernel
13535+ SWAPGS_UNSAFE_STACK
13536+ RESTORE_ALL 8
13537+ jmp irq_return
13538+#endif
13539 nmi_swapgs:
13540+#ifdef CONFIG_PAX_MEMORY_UDEREF
13541+ pax_exit_kernel_user
13542+#else
13543+ pax_exit_kernel
13544+#endif
13545 SWAPGS_UNSAFE_STACK
13546+ RESTORE_ALL 8
13547+ jmp irq_return
13548 nmi_restore:
13549+ pax_exit_kernel
13550 RESTORE_ALL 8
13551 jmp irq_return
13552 nmi_userspace:
13553diff -urNp linux-2.6.32.41/arch/x86/kernel/ftrace.c linux-2.6.32.41/arch/x86/kernel/ftrace.c
13554--- linux-2.6.32.41/arch/x86/kernel/ftrace.c 2011-03-27 14:31:47.000000000 -0400
13555+++ linux-2.6.32.41/arch/x86/kernel/ftrace.c 2011-05-04 17:56:20.000000000 -0400
13556@@ -103,7 +103,7 @@ static void *mod_code_ip; /* holds the
13557 static void *mod_code_newcode; /* holds the text to write to the IP */
13558
13559 static unsigned nmi_wait_count;
13560-static atomic_t nmi_update_count = ATOMIC_INIT(0);
13561+static atomic_unchecked_t nmi_update_count = ATOMIC_INIT(0);
13562
13563 int ftrace_arch_read_dyn_info(char *buf, int size)
13564 {
13565@@ -111,7 +111,7 @@ int ftrace_arch_read_dyn_info(char *buf,
13566
13567 r = snprintf(buf, size, "%u %u",
13568 nmi_wait_count,
13569- atomic_read(&nmi_update_count));
13570+ atomic_read_unchecked(&nmi_update_count));
13571 return r;
13572 }
13573
13574@@ -149,8 +149,10 @@ void ftrace_nmi_enter(void)
13575 {
13576 if (atomic_inc_return(&nmi_running) & MOD_CODE_WRITE_FLAG) {
13577 smp_rmb();
13578+ pax_open_kernel();
13579 ftrace_mod_code();
13580- atomic_inc(&nmi_update_count);
13581+ pax_close_kernel();
13582+ atomic_inc_unchecked(&nmi_update_count);
13583 }
13584 /* Must have previous changes seen before executions */
13585 smp_mb();
13586@@ -215,7 +217,7 @@ do_ftrace_mod_code(unsigned long ip, voi
13587
13588
13589
13590-static unsigned char ftrace_nop[MCOUNT_INSN_SIZE];
13591+static unsigned char ftrace_nop[MCOUNT_INSN_SIZE] __read_only;
13592
13593 static unsigned char *ftrace_nop_replace(void)
13594 {
13595@@ -228,6 +230,8 @@ ftrace_modify_code(unsigned long ip, uns
13596 {
13597 unsigned char replaced[MCOUNT_INSN_SIZE];
13598
13599+ ip = ktla_ktva(ip);
13600+
13601 /*
13602 * Note: Due to modules and __init, code can
13603 * disappear and change, we need to protect against faulting
13604@@ -284,7 +288,7 @@ int ftrace_update_ftrace_func(ftrace_fun
13605 unsigned char old[MCOUNT_INSN_SIZE], *new;
13606 int ret;
13607
13608- memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
13609+ memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
13610 new = ftrace_call_replace(ip, (unsigned long)func);
13611 ret = ftrace_modify_code(ip, old, new);
13612
13613@@ -337,15 +341,15 @@ int __init ftrace_dyn_arch_init(void *da
13614 switch (faulted) {
13615 case 0:
13616 pr_info("ftrace: converting mcount calls to 0f 1f 44 00 00\n");
13617- memcpy(ftrace_nop, ftrace_test_p6nop, MCOUNT_INSN_SIZE);
13618+ memcpy(ftrace_nop, ktla_ktva(ftrace_test_p6nop), MCOUNT_INSN_SIZE);
13619 break;
13620 case 1:
13621 pr_info("ftrace: converting mcount calls to 66 66 66 66 90\n");
13622- memcpy(ftrace_nop, ftrace_test_nop5, MCOUNT_INSN_SIZE);
13623+ memcpy(ftrace_nop, ktla_ktva(ftrace_test_nop5), MCOUNT_INSN_SIZE);
13624 break;
13625 case 2:
13626 pr_info("ftrace: converting mcount calls to jmp . + 5\n");
13627- memcpy(ftrace_nop, ftrace_test_jmp, MCOUNT_INSN_SIZE);
13628+ memcpy(ftrace_nop, ktla_ktva(ftrace_test_jmp), MCOUNT_INSN_SIZE);
13629 break;
13630 }
13631
13632@@ -366,6 +370,8 @@ static int ftrace_mod_jmp(unsigned long
13633 {
13634 unsigned char code[MCOUNT_INSN_SIZE];
13635
13636+ ip = ktla_ktva(ip);
13637+
13638 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
13639 return -EFAULT;
13640
13641diff -urNp linux-2.6.32.41/arch/x86/kernel/head32.c linux-2.6.32.41/arch/x86/kernel/head32.c
13642--- linux-2.6.32.41/arch/x86/kernel/head32.c 2011-03-27 14:31:47.000000000 -0400
13643+++ linux-2.6.32.41/arch/x86/kernel/head32.c 2011-04-17 15:56:46.000000000 -0400
13644@@ -16,6 +16,7 @@
13645 #include <asm/apic.h>
13646 #include <asm/io_apic.h>
13647 #include <asm/bios_ebda.h>
13648+#include <asm/boot.h>
13649
13650 static void __init i386_default_early_setup(void)
13651 {
13652@@ -31,7 +32,7 @@ void __init i386_start_kernel(void)
13653 {
13654 reserve_trampoline_memory();
13655
13656- reserve_early(__pa_symbol(&_text), __pa_symbol(&__bss_stop), "TEXT DATA BSS");
13657+ reserve_early(LOAD_PHYSICAL_ADDR, __pa_symbol(&__bss_stop), "TEXT DATA BSS");
13658
13659 #ifdef CONFIG_BLK_DEV_INITRD
13660 /* Reserve INITRD */
13661diff -urNp linux-2.6.32.41/arch/x86/kernel/head_32.S linux-2.6.32.41/arch/x86/kernel/head_32.S
13662--- linux-2.6.32.41/arch/x86/kernel/head_32.S 2011-03-27 14:31:47.000000000 -0400
13663+++ linux-2.6.32.41/arch/x86/kernel/head_32.S 2011-04-17 15:56:46.000000000 -0400
13664@@ -19,10 +19,17 @@
13665 #include <asm/setup.h>
13666 #include <asm/processor-flags.h>
13667 #include <asm/percpu.h>
13668+#include <asm/msr-index.h>
13669
13670 /* Physical address */
13671 #define pa(X) ((X) - __PAGE_OFFSET)
13672
13673+#ifdef CONFIG_PAX_KERNEXEC
13674+#define ta(X) (X)
13675+#else
13676+#define ta(X) ((X) - __PAGE_OFFSET)
13677+#endif
13678+
13679 /*
13680 * References to members of the new_cpu_data structure.
13681 */
13682@@ -52,11 +59,7 @@
13683 * and small than max_low_pfn, otherwise will waste some page table entries
13684 */
13685
13686-#if PTRS_PER_PMD > 1
13687-#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
13688-#else
13689-#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
13690-#endif
13691+#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
13692
13693 /* Enough space to fit pagetables for the low memory linear map */
13694 MAPPING_BEYOND_END = \
13695@@ -73,6 +76,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_P
13696 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
13697
13698 /*
13699+ * Real beginning of normal "text" segment
13700+ */
13701+ENTRY(stext)
13702+ENTRY(_stext)
13703+
13704+/*
13705 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
13706 * %esi points to the real-mode code as a 32-bit pointer.
13707 * CS and DS must be 4 GB flat segments, but we don't depend on
13708@@ -80,6 +89,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
13709 * can.
13710 */
13711 __HEAD
13712+
13713+#ifdef CONFIG_PAX_KERNEXEC
13714+ jmp startup_32
13715+/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
13716+.fill PAGE_SIZE-5,1,0xcc
13717+#endif
13718+
13719 ENTRY(startup_32)
13720 /* test KEEP_SEGMENTS flag to see if the bootloader is asking
13721 us to not reload segments */
13722@@ -97,6 +113,57 @@ ENTRY(startup_32)
13723 movl %eax,%gs
13724 2:
13725
13726+#ifdef CONFIG_SMP
13727+ movl $pa(cpu_gdt_table),%edi
13728+ movl $__per_cpu_load,%eax
13729+ movw %ax,__KERNEL_PERCPU + 2(%edi)
13730+ rorl $16,%eax
13731+ movb %al,__KERNEL_PERCPU + 4(%edi)
13732+ movb %ah,__KERNEL_PERCPU + 7(%edi)
13733+ movl $__per_cpu_end - 1,%eax
13734+ subl $__per_cpu_start,%eax
13735+ movw %ax,__KERNEL_PERCPU + 0(%edi)
13736+#endif
13737+
13738+#ifdef CONFIG_PAX_MEMORY_UDEREF
13739+ movl $NR_CPUS,%ecx
13740+ movl $pa(cpu_gdt_table),%edi
13741+1:
13742+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
13743+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
13744+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
13745+ addl $PAGE_SIZE_asm,%edi
13746+ loop 1b
13747+#endif
13748+
13749+#ifdef CONFIG_PAX_KERNEXEC
13750+ movl $pa(boot_gdt),%edi
13751+ movl $__LOAD_PHYSICAL_ADDR,%eax
13752+ movw %ax,__BOOT_CS + 2(%edi)
13753+ rorl $16,%eax
13754+ movb %al,__BOOT_CS + 4(%edi)
13755+ movb %ah,__BOOT_CS + 7(%edi)
13756+ rorl $16,%eax
13757+
13758+ ljmp $(__BOOT_CS),$1f
13759+1:
13760+
13761+ movl $NR_CPUS,%ecx
13762+ movl $pa(cpu_gdt_table),%edi
13763+ addl $__PAGE_OFFSET,%eax
13764+1:
13765+ movw %ax,__KERNEL_CS + 2(%edi)
13766+ movw %ax,__KERNEXEC_KERNEL_CS + 2(%edi)
13767+ rorl $16,%eax
13768+ movb %al,__KERNEL_CS + 4(%edi)
13769+ movb %al,__KERNEXEC_KERNEL_CS + 4(%edi)
13770+ movb %ah,__KERNEL_CS + 7(%edi)
13771+ movb %ah,__KERNEXEC_KERNEL_CS + 7(%edi)
13772+ rorl $16,%eax
13773+ addl $PAGE_SIZE_asm,%edi
13774+ loop 1b
13775+#endif
13776+
13777 /*
13778 * Clear BSS first so that there are no surprises...
13779 */
13780@@ -140,9 +207,7 @@ ENTRY(startup_32)
13781 cmpl $num_subarch_entries, %eax
13782 jae bad_subarch
13783
13784- movl pa(subarch_entries)(,%eax,4), %eax
13785- subl $__PAGE_OFFSET, %eax
13786- jmp *%eax
13787+ jmp *pa(subarch_entries)(,%eax,4)
13788
13789 bad_subarch:
13790 WEAK(lguest_entry)
13791@@ -154,10 +219,10 @@ WEAK(xen_entry)
13792 __INITDATA
13793
13794 subarch_entries:
13795- .long default_entry /* normal x86/PC */
13796- .long lguest_entry /* lguest hypervisor */
13797- .long xen_entry /* Xen hypervisor */
13798- .long default_entry /* Moorestown MID */
13799+ .long ta(default_entry) /* normal x86/PC */
13800+ .long ta(lguest_entry) /* lguest hypervisor */
13801+ .long ta(xen_entry) /* Xen hypervisor */
13802+ .long ta(default_entry) /* Moorestown MID */
13803 num_subarch_entries = (. - subarch_entries) / 4
13804 .previous
13805 #endif /* CONFIG_PARAVIRT */
13806@@ -218,8 +283,11 @@ default_entry:
13807 movl %eax, pa(max_pfn_mapped)
13808
13809 /* Do early initialization of the fixmap area */
13810- movl $pa(swapper_pg_fixmap)+PDE_IDENT_ATTR,%eax
13811- movl %eax,pa(swapper_pg_pmd+0x1000*KPMDS-8)
13812+#ifdef CONFIG_COMPAT_VDSO
13813+ movl $pa(swapper_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(swapper_pg_pmd+0x1000*KPMDS-8)
13814+#else
13815+ movl $pa(swapper_pg_fixmap)+PDE_IDENT_ATTR,pa(swapper_pg_pmd+0x1000*KPMDS-8)
13816+#endif
13817 #else /* Not PAE */
13818
13819 page_pde_offset = (__PAGE_OFFSET >> 20);
13820@@ -249,8 +317,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
13821 movl %eax, pa(max_pfn_mapped)
13822
13823 /* Do early initialization of the fixmap area */
13824- movl $pa(swapper_pg_fixmap)+PDE_IDENT_ATTR,%eax
13825- movl %eax,pa(swapper_pg_dir+0xffc)
13826+#ifdef CONFIG_COMPAT_VDSO
13827+ movl $pa(swapper_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(swapper_pg_dir+0xffc)
13828+#else
13829+ movl $pa(swapper_pg_fixmap)+PDE_IDENT_ATTR,pa(swapper_pg_dir+0xffc)
13830+#endif
13831 #endif
13832 jmp 3f
13833 /*
13834@@ -297,6 +368,7 @@ ENTRY(startup_32_smp)
13835 orl %edx,%eax
13836 movl %eax,%cr4
13837
13838+#ifdef CONFIG_X86_PAE
13839 btl $5, %eax # check if PAE is enabled
13840 jnc 6f
13841
13842@@ -312,13 +384,17 @@ ENTRY(startup_32_smp)
13843 jnc 6f
13844
13845 /* Setup EFER (Extended Feature Enable Register) */
13846- movl $0xc0000080, %ecx
13847+ movl $MSR_EFER, %ecx
13848 rdmsr
13849
13850 btsl $11, %eax
13851 /* Make changes effective */
13852 wrmsr
13853
13854+ btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
13855+ movl $1,pa(nx_enabled)
13856+#endif
13857+
13858 6:
13859
13860 /*
13861@@ -344,9 +420,7 @@ ENTRY(startup_32_smp)
13862
13863 #ifdef CONFIG_SMP
13864 cmpb $0, ready
13865- jz 1f /* Initial CPU cleans BSS */
13866- jmp checkCPUtype
13867-1:
13868+ jnz checkCPUtype /* Initial CPU cleans BSS */
13869 #endif /* CONFIG_SMP */
13870
13871 /*
13872@@ -424,7 +498,7 @@ is386: movl $2,%ecx # set MP
13873 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
13874 movl %eax,%ss # after changing gdt.
13875
13876- movl $(__USER_DS),%eax # DS/ES contains default USER segment
13877+# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
13878 movl %eax,%ds
13879 movl %eax,%es
13880
13881@@ -438,15 +512,22 @@ is386: movl $2,%ecx # set MP
13882 */
13883 cmpb $0,ready
13884 jne 1f
13885- movl $per_cpu__gdt_page,%eax
13886+ movl $cpu_gdt_table,%eax
13887 movl $per_cpu__stack_canary,%ecx
13888+#ifdef CONFIG_SMP
13889+ addl $__per_cpu_load,%ecx
13890+#endif
13891 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
13892 shrl $16, %ecx
13893 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
13894 movb %ch, 8 * GDT_ENTRY_STACK_CANARY + 7(%eax)
13895 1:
13896-#endif
13897 movl $(__KERNEL_STACK_CANARY),%eax
13898+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
13899+ movl $(__USER_DS),%eax
13900+#else
13901+ xorl %eax,%eax
13902+#endif
13903 movl %eax,%gs
13904
13905 xorl %eax,%eax # Clear LDT
13906@@ -457,10 +538,6 @@ is386: movl $2,%ecx # set MP
13907 #ifdef CONFIG_SMP
13908 movb ready, %cl
13909 movb $1, ready
13910- cmpb $0,%cl # the first CPU calls start_kernel
13911- je 1f
13912- movl (stack_start), %esp
13913-1:
13914 #endif /* CONFIG_SMP */
13915 jmp *(initial_code)
13916
13917@@ -546,22 +623,22 @@ early_page_fault:
13918 jmp early_fault
13919
13920 early_fault:
13921- cld
13922 #ifdef CONFIG_PRINTK
13923+ cmpl $1,%ss:early_recursion_flag
13924+ je hlt_loop
13925+ incl %ss:early_recursion_flag
13926+ cld
13927 pusha
13928 movl $(__KERNEL_DS),%eax
13929 movl %eax,%ds
13930 movl %eax,%es
13931- cmpl $2,early_recursion_flag
13932- je hlt_loop
13933- incl early_recursion_flag
13934 movl %cr2,%eax
13935 pushl %eax
13936 pushl %edx /* trapno */
13937 pushl $fault_msg
13938 call printk
13939+; call dump_stack
13940 #endif
13941- call dump_stack
13942 hlt_loop:
13943 hlt
13944 jmp hlt_loop
13945@@ -569,8 +646,11 @@ hlt_loop:
13946 /* This is the default interrupt "handler" :-) */
13947 ALIGN
13948 ignore_int:
13949- cld
13950 #ifdef CONFIG_PRINTK
13951+ cmpl $2,%ss:early_recursion_flag
13952+ je hlt_loop
13953+ incl %ss:early_recursion_flag
13954+ cld
13955 pushl %eax
13956 pushl %ecx
13957 pushl %edx
13958@@ -579,9 +659,6 @@ ignore_int:
13959 movl $(__KERNEL_DS),%eax
13960 movl %eax,%ds
13961 movl %eax,%es
13962- cmpl $2,early_recursion_flag
13963- je hlt_loop
13964- incl early_recursion_flag
13965 pushl 16(%esp)
13966 pushl 24(%esp)
13967 pushl 32(%esp)
13968@@ -610,31 +687,47 @@ ENTRY(initial_page_table)
13969 /*
13970 * BSS section
13971 */
13972-__PAGE_ALIGNED_BSS
13973- .align PAGE_SIZE_asm
13974 #ifdef CONFIG_X86_PAE
13975+.section .swapper_pg_pmd,"a",@progbits
13976 swapper_pg_pmd:
13977 .fill 1024*KPMDS,4,0
13978 #else
13979+.section .swapper_pg_dir,"a",@progbits
13980 ENTRY(swapper_pg_dir)
13981 .fill 1024,4,0
13982 #endif
13983+.section .swapper_pg_fixmap,"a",@progbits
13984 swapper_pg_fixmap:
13985 .fill 1024,4,0
13986 #ifdef CONFIG_X86_TRAMPOLINE
13987+.section .trampoline_pg_dir,"a",@progbits
13988 ENTRY(trampoline_pg_dir)
13989+#ifdef CONFIG_X86_PAE
13990+ .fill 4,8,0
13991+#else
13992 .fill 1024,4,0
13993 #endif
13994+#endif
13995+
13996+.section .empty_zero_page,"a",@progbits
13997 ENTRY(empty_zero_page)
13998 .fill 4096,1,0
13999
14000 /*
14001+ * The IDT has to be page-aligned to simplify the Pentium
14002+ * F0 0F bug workaround.. We have a special link segment
14003+ * for this.
14004+ */
14005+.section .idt,"a",@progbits
14006+ENTRY(idt_table)
14007+ .fill 256,8,0
14008+
14009+/*
14010 * This starts the data section.
14011 */
14012 #ifdef CONFIG_X86_PAE
14013-__PAGE_ALIGNED_DATA
14014- /* Page-aligned for the benefit of paravirt? */
14015- .align PAGE_SIZE_asm
14016+.section .swapper_pg_dir,"a",@progbits
14017+
14018 ENTRY(swapper_pg_dir)
14019 .long pa(swapper_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
14020 # if KPMDS == 3
14021@@ -653,15 +746,24 @@ ENTRY(swapper_pg_dir)
14022 # error "Kernel PMDs should be 1, 2 or 3"
14023 # endif
14024 .align PAGE_SIZE_asm /* needs to be page-sized too */
14025+
14026+#ifdef CONFIG_PAX_PER_CPU_PGD
14027+ENTRY(cpu_pgd)
14028+ .rept NR_CPUS
14029+ .fill 4,8,0
14030+ .endr
14031+#endif
14032+
14033 #endif
14034
14035 .data
14036 ENTRY(stack_start)
14037- .long init_thread_union+THREAD_SIZE
14038+ .long init_thread_union+THREAD_SIZE-8
14039 .long __BOOT_DS
14040
14041 ready: .byte 0
14042
14043+.section .rodata,"a",@progbits
14044 early_recursion_flag:
14045 .long 0
14046
14047@@ -697,7 +799,7 @@ fault_msg:
14048 .word 0 # 32 bit align gdt_desc.address
14049 boot_gdt_descr:
14050 .word __BOOT_DS+7
14051- .long boot_gdt - __PAGE_OFFSET
14052+ .long pa(boot_gdt)
14053
14054 .word 0 # 32-bit align idt_desc.address
14055 idt_descr:
14056@@ -708,7 +810,7 @@ idt_descr:
14057 .word 0 # 32 bit align gdt_desc.address
14058 ENTRY(early_gdt_descr)
14059 .word GDT_ENTRIES*8-1
14060- .long per_cpu__gdt_page /* Overwritten for secondary CPUs */
14061+ .long cpu_gdt_table /* Overwritten for secondary CPUs */
14062
14063 /*
14064 * The boot_gdt must mirror the equivalent in setup.S and is
14065@@ -717,5 +819,65 @@ ENTRY(early_gdt_descr)
14066 .align L1_CACHE_BYTES
14067 ENTRY(boot_gdt)
14068 .fill GDT_ENTRY_BOOT_CS,8,0
14069- .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
14070- .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
14071+ .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
14072+ .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
14073+
14074+ .align PAGE_SIZE_asm
14075+ENTRY(cpu_gdt_table)
14076+ .rept NR_CPUS
14077+ .quad 0x0000000000000000 /* NULL descriptor */
14078+ .quad 0x0000000000000000 /* 0x0b reserved */
14079+ .quad 0x0000000000000000 /* 0x13 reserved */
14080+ .quad 0x0000000000000000 /* 0x1b reserved */
14081+
14082+#ifdef CONFIG_PAX_KERNEXEC
14083+ .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
14084+#else
14085+ .quad 0x0000000000000000 /* 0x20 unused */
14086+#endif
14087+
14088+ .quad 0x0000000000000000 /* 0x28 unused */
14089+ .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
14090+ .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
14091+ .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
14092+ .quad 0x0000000000000000 /* 0x4b reserved */
14093+ .quad 0x0000000000000000 /* 0x53 reserved */
14094+ .quad 0x0000000000000000 /* 0x5b reserved */
14095+
14096+ .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
14097+ .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
14098+ .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
14099+ .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
14100+
14101+ .quad 0x0000000000000000 /* 0x80 TSS descriptor */
14102+ .quad 0x0000000000000000 /* 0x88 LDT descriptor */
14103+
14104+ /*
14105+ * Segments used for calling PnP BIOS have byte granularity.
14106+ * The code segments and data segments have fixed 64k limits,
14107+ * the transfer segment sizes are set at run time.
14108+ */
14109+ .quad 0x00409b000000ffff /* 0x90 32-bit code */
14110+ .quad 0x00009b000000ffff /* 0x98 16-bit code */
14111+ .quad 0x000093000000ffff /* 0xa0 16-bit data */
14112+ .quad 0x0000930000000000 /* 0xa8 16-bit data */
14113+ .quad 0x0000930000000000 /* 0xb0 16-bit data */
14114+
14115+ /*
14116+ * The APM segments have byte granularity and their bases
14117+ * are set at run time. All have 64k limits.
14118+ */
14119+ .quad 0x00409b000000ffff /* 0xb8 APM CS code */
14120+ .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
14121+ .quad 0x004093000000ffff /* 0xc8 APM DS data */
14122+
14123+ .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
14124+ .quad 0x0040930000000000 /* 0xd8 - PERCPU */
14125+ .quad 0x0040910000000018 /* 0xe0 - STACK_CANARY */
14126+ .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
14127+ .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
14128+ .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
14129+
14130+ /* Be sure this is zeroed to avoid false validations in Xen */
14131+ .fill PAGE_SIZE_asm - GDT_SIZE,1,0
14132+ .endr
14133diff -urNp linux-2.6.32.41/arch/x86/kernel/head_64.S linux-2.6.32.41/arch/x86/kernel/head_64.S
14134--- linux-2.6.32.41/arch/x86/kernel/head_64.S 2011-03-27 14:31:47.000000000 -0400
14135+++ linux-2.6.32.41/arch/x86/kernel/head_64.S 2011-04-17 15:56:46.000000000 -0400
14136@@ -19,6 +19,7 @@
14137 #include <asm/cache.h>
14138 #include <asm/processor-flags.h>
14139 #include <asm/percpu.h>
14140+#include <asm/cpufeature.h>
14141
14142 #ifdef CONFIG_PARAVIRT
14143 #include <asm/asm-offsets.h>
14144@@ -38,6 +39,10 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET
14145 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
14146 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
14147 L3_START_KERNEL = pud_index(__START_KERNEL_map)
14148+L4_VMALLOC_START = pgd_index(VMALLOC_START)
14149+L3_VMALLOC_START = pud_index(VMALLOC_START)
14150+L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
14151+L3_VMEMMAP_START = pud_index(VMEMMAP_START)
14152
14153 .text
14154 __HEAD
14155@@ -85,35 +90,22 @@ startup_64:
14156 */
14157 addq %rbp, init_level4_pgt + 0(%rip)
14158 addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
14159+ addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
14160+ addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
14161 addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
14162
14163 addq %rbp, level3_ident_pgt + 0(%rip)
14164+#ifndef CONFIG_XEN
14165+ addq %rbp, level3_ident_pgt + 8(%rip)
14166+#endif
14167
14168- addq %rbp, level3_kernel_pgt + (510*8)(%rip)
14169- addq %rbp, level3_kernel_pgt + (511*8)(%rip)
14170+ addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
14171
14172- addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
14173+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
14174+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8+8)(%rip)
14175
14176- /* Add an Identity mapping if I am above 1G */
14177- leaq _text(%rip), %rdi
14178- andq $PMD_PAGE_MASK, %rdi
14179-
14180- movq %rdi, %rax
14181- shrq $PUD_SHIFT, %rax
14182- andq $(PTRS_PER_PUD - 1), %rax
14183- jz ident_complete
14184-
14185- leaq (level2_spare_pgt - __START_KERNEL_map + _KERNPG_TABLE)(%rbp), %rdx
14186- leaq level3_ident_pgt(%rip), %rbx
14187- movq %rdx, 0(%rbx, %rax, 8)
14188-
14189- movq %rdi, %rax
14190- shrq $PMD_SHIFT, %rax
14191- andq $(PTRS_PER_PMD - 1), %rax
14192- leaq __PAGE_KERNEL_IDENT_LARGE_EXEC(%rdi), %rdx
14193- leaq level2_spare_pgt(%rip), %rbx
14194- movq %rdx, 0(%rbx, %rax, 8)
14195-ident_complete:
14196+ addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
14197+ addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
14198
14199 /*
14200 * Fixup the kernel text+data virtual addresses. Note that
14201@@ -161,8 +153,8 @@ ENTRY(secondary_startup_64)
14202 * after the boot processor executes this code.
14203 */
14204
14205- /* Enable PAE mode and PGE */
14206- movl $(X86_CR4_PAE | X86_CR4_PGE), %eax
14207+ /* Enable PAE mode and PSE/PGE */
14208+ movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
14209 movq %rax, %cr4
14210
14211 /* Setup early boot stage 4 level pagetables. */
14212@@ -184,9 +176,13 @@ ENTRY(secondary_startup_64)
14213 movl $MSR_EFER, %ecx
14214 rdmsr
14215 btsl $_EFER_SCE, %eax /* Enable System Call */
14216- btl $20,%edi /* No Execute supported? */
14217+ btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
14218 jnc 1f
14219 btsl $_EFER_NX, %eax
14220+ leaq init_level4_pgt(%rip), %rdi
14221+ btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
14222+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
14223+ btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
14224 1: wrmsr /* Make changes effective */
14225
14226 /* Setup cr0 */
14227@@ -262,16 +258,16 @@ ENTRY(secondary_startup_64)
14228 .quad x86_64_start_kernel
14229 ENTRY(initial_gs)
14230 .quad INIT_PER_CPU_VAR(irq_stack_union)
14231- __FINITDATA
14232
14233 ENTRY(stack_start)
14234 .quad init_thread_union+THREAD_SIZE-8
14235 .word 0
14236+ __FINITDATA
14237
14238 bad_address:
14239 jmp bad_address
14240
14241- .section ".init.text","ax"
14242+ __INIT
14243 #ifdef CONFIG_EARLY_PRINTK
14244 .globl early_idt_handlers
14245 early_idt_handlers:
14246@@ -316,18 +312,23 @@ ENTRY(early_idt_handler)
14247 #endif /* EARLY_PRINTK */
14248 1: hlt
14249 jmp 1b
14250+ .previous
14251
14252 #ifdef CONFIG_EARLY_PRINTK
14253+ __INITDATA
14254 early_recursion_flag:
14255 .long 0
14256+ .previous
14257
14258+ .section .rodata,"a",@progbits
14259 early_idt_msg:
14260 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
14261 early_idt_ripmsg:
14262 .asciz "RIP %s\n"
14263-#endif /* CONFIG_EARLY_PRINTK */
14264 .previous
14265+#endif /* CONFIG_EARLY_PRINTK */
14266
14267+ .section .rodata,"a",@progbits
14268 #define NEXT_PAGE(name) \
14269 .balign PAGE_SIZE; \
14270 ENTRY(name)
14271@@ -350,13 +351,36 @@ NEXT_PAGE(init_level4_pgt)
14272 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
14273 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
14274 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
14275+ .org init_level4_pgt + L4_VMALLOC_START*8, 0
14276+ .quad level3_vmalloc_pgt - __START_KERNEL_map + _KERNPG_TABLE
14277+ .org init_level4_pgt + L4_VMEMMAP_START*8, 0
14278+ .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
14279 .org init_level4_pgt + L4_START_KERNEL*8, 0
14280 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
14281 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
14282
14283+#ifdef CONFIG_PAX_PER_CPU_PGD
14284+NEXT_PAGE(cpu_pgd)
14285+ .rept NR_CPUS
14286+ .fill 512,8,0
14287+ .endr
14288+#endif
14289+
14290 NEXT_PAGE(level3_ident_pgt)
14291 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
14292+#ifdef CONFIG_XEN
14293 .fill 511,8,0
14294+#else
14295+ .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
14296+ .fill 510,8,0
14297+#endif
14298+
14299+NEXT_PAGE(level3_vmalloc_pgt)
14300+ .fill 512,8,0
14301+
14302+NEXT_PAGE(level3_vmemmap_pgt)
14303+ .fill L3_VMEMMAP_START,8,0
14304+ .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
14305
14306 NEXT_PAGE(level3_kernel_pgt)
14307 .fill L3_START_KERNEL,8,0
14308@@ -364,20 +388,23 @@ NEXT_PAGE(level3_kernel_pgt)
14309 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
14310 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
14311
14312+NEXT_PAGE(level2_vmemmap_pgt)
14313+ .fill 512,8,0
14314+
14315 NEXT_PAGE(level2_fixmap_pgt)
14316- .fill 506,8,0
14317- .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
14318- /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
14319- .fill 5,8,0
14320+ .fill 507,8,0
14321+ .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
14322+ /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
14323+ .fill 4,8,0
14324
14325-NEXT_PAGE(level1_fixmap_pgt)
14326+NEXT_PAGE(level1_vsyscall_pgt)
14327 .fill 512,8,0
14328
14329-NEXT_PAGE(level2_ident_pgt)
14330- /* Since I easily can, map the first 1G.
14331+ /* Since I easily can, map the first 2G.
14332 * Don't set NX because code runs from these pages.
14333 */
14334- PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
14335+NEXT_PAGE(level2_ident_pgt)
14336+ PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
14337
14338 NEXT_PAGE(level2_kernel_pgt)
14339 /*
14340@@ -390,33 +417,55 @@ NEXT_PAGE(level2_kernel_pgt)
14341 * If you want to increase this then increase MODULES_VADDR
14342 * too.)
14343 */
14344- PMDS(0, __PAGE_KERNEL_LARGE_EXEC,
14345- KERNEL_IMAGE_SIZE/PMD_SIZE)
14346-
14347-NEXT_PAGE(level2_spare_pgt)
14348- .fill 512, 8, 0
14349+ PMDS(0, __PAGE_KERNEL_LARGE_EXEC, KERNEL_IMAGE_SIZE/PMD_SIZE)
14350
14351 #undef PMDS
14352 #undef NEXT_PAGE
14353
14354- .data
14355+ .align PAGE_SIZE
14356+ENTRY(cpu_gdt_table)
14357+ .rept NR_CPUS
14358+ .quad 0x0000000000000000 /* NULL descriptor */
14359+ .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
14360+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
14361+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
14362+ .quad 0x00cffb000000ffff /* __USER32_CS */
14363+ .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
14364+ .quad 0x00affb000000ffff /* __USER_CS */
14365+
14366+#ifdef CONFIG_PAX_KERNEXEC
14367+ .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
14368+#else
14369+ .quad 0x0 /* unused */
14370+#endif
14371+
14372+ .quad 0,0 /* TSS */
14373+ .quad 0,0 /* LDT */
14374+ .quad 0,0,0 /* three TLS descriptors */
14375+ .quad 0x0000f40000000000 /* node/CPU stored in limit */
14376+ /* asm/segment.h:GDT_ENTRIES must match this */
14377+
14378+ /* zero the remaining page */
14379+ .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
14380+ .endr
14381+
14382 .align 16
14383 .globl early_gdt_descr
14384 early_gdt_descr:
14385 .word GDT_ENTRIES*8-1
14386 early_gdt_descr_base:
14387- .quad INIT_PER_CPU_VAR(gdt_page)
14388+ .quad cpu_gdt_table
14389
14390 ENTRY(phys_base)
14391 /* This must match the first entry in level2_kernel_pgt */
14392 .quad 0x0000000000000000
14393
14394 #include "../../x86/xen/xen-head.S"
14395-
14396- .section .bss, "aw", @nobits
14397+
14398+ .section .rodata,"a",@progbits
14399 .align L1_CACHE_BYTES
14400 ENTRY(idt_table)
14401- .skip IDT_ENTRIES * 16
14402+ .fill 512,8,0
14403
14404 __PAGE_ALIGNED_BSS
14405 .align PAGE_SIZE
14406diff -urNp linux-2.6.32.41/arch/x86/kernel/i386_ksyms_32.c linux-2.6.32.41/arch/x86/kernel/i386_ksyms_32.c
14407--- linux-2.6.32.41/arch/x86/kernel/i386_ksyms_32.c 2011-03-27 14:31:47.000000000 -0400
14408+++ linux-2.6.32.41/arch/x86/kernel/i386_ksyms_32.c 2011-04-17 15:56:46.000000000 -0400
14409@@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
14410 EXPORT_SYMBOL(cmpxchg8b_emu);
14411 #endif
14412
14413+EXPORT_SYMBOL_GPL(cpu_gdt_table);
14414+
14415 /* Networking helper routines. */
14416 EXPORT_SYMBOL(csum_partial_copy_generic);
14417+EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
14418+EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
14419
14420 EXPORT_SYMBOL(__get_user_1);
14421 EXPORT_SYMBOL(__get_user_2);
14422@@ -36,3 +40,7 @@ EXPORT_SYMBOL(strstr);
14423
14424 EXPORT_SYMBOL(csum_partial);
14425 EXPORT_SYMBOL(empty_zero_page);
14426+
14427+#ifdef CONFIG_PAX_KERNEXEC
14428+EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
14429+#endif
14430diff -urNp linux-2.6.32.41/arch/x86/kernel/i8259.c linux-2.6.32.41/arch/x86/kernel/i8259.c
14431--- linux-2.6.32.41/arch/x86/kernel/i8259.c 2011-03-27 14:31:47.000000000 -0400
14432+++ linux-2.6.32.41/arch/x86/kernel/i8259.c 2011-05-04 17:56:28.000000000 -0400
14433@@ -208,7 +208,7 @@ spurious_8259A_irq:
14434 "spurious 8259A interrupt: IRQ%d.\n", irq);
14435 spurious_irq_mask |= irqmask;
14436 }
14437- atomic_inc(&irq_err_count);
14438+ atomic_inc_unchecked(&irq_err_count);
14439 /*
14440 * Theoretically we do not have to handle this IRQ,
14441 * but in Linux this does not cause problems and is
14442diff -urNp linux-2.6.32.41/arch/x86/kernel/init_task.c linux-2.6.32.41/arch/x86/kernel/init_task.c
14443--- linux-2.6.32.41/arch/x86/kernel/init_task.c 2011-03-27 14:31:47.000000000 -0400
14444+++ linux-2.6.32.41/arch/x86/kernel/init_task.c 2011-04-17 15:56:46.000000000 -0400
14445@@ -20,8 +20,7 @@ static struct sighand_struct init_sighan
14446 * way process stacks are handled. This is done by having a special
14447 * "init_task" linker map entry..
14448 */
14449-union thread_union init_thread_union __init_task_data =
14450- { INIT_THREAD_INFO(init_task) };
14451+union thread_union init_thread_union __init_task_data;
14452
14453 /*
14454 * Initial task structure.
14455@@ -38,5 +37,5 @@ EXPORT_SYMBOL(init_task);
14456 * section. Since TSS's are completely CPU-local, we want them
14457 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
14458 */
14459-DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
14460-
14461+struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
14462+EXPORT_SYMBOL(init_tss);
14463diff -urNp linux-2.6.32.41/arch/x86/kernel/ioport.c linux-2.6.32.41/arch/x86/kernel/ioport.c
14464--- linux-2.6.32.41/arch/x86/kernel/ioport.c 2011-03-27 14:31:47.000000000 -0400
14465+++ linux-2.6.32.41/arch/x86/kernel/ioport.c 2011-04-17 15:56:46.000000000 -0400
14466@@ -6,6 +6,7 @@
14467 #include <linux/sched.h>
14468 #include <linux/kernel.h>
14469 #include <linux/capability.h>
14470+#include <linux/security.h>
14471 #include <linux/errno.h>
14472 #include <linux/types.h>
14473 #include <linux/ioport.h>
14474@@ -41,6 +42,12 @@ asmlinkage long sys_ioperm(unsigned long
14475
14476 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
14477 return -EINVAL;
14478+#ifdef CONFIG_GRKERNSEC_IO
14479+ if (turn_on && grsec_disable_privio) {
14480+ gr_handle_ioperm();
14481+ return -EPERM;
14482+ }
14483+#endif
14484 if (turn_on && !capable(CAP_SYS_RAWIO))
14485 return -EPERM;
14486
14487@@ -67,7 +74,7 @@ asmlinkage long sys_ioperm(unsigned long
14488 * because the ->io_bitmap_max value must match the bitmap
14489 * contents:
14490 */
14491- tss = &per_cpu(init_tss, get_cpu());
14492+ tss = init_tss + get_cpu();
14493
14494 set_bitmap(t->io_bitmap_ptr, from, num, !turn_on);
14495
14496@@ -111,6 +118,12 @@ static int do_iopl(unsigned int level, s
14497 return -EINVAL;
14498 /* Trying to gain more privileges? */
14499 if (level > old) {
14500+#ifdef CONFIG_GRKERNSEC_IO
14501+ if (grsec_disable_privio) {
14502+ gr_handle_iopl();
14503+ return -EPERM;
14504+ }
14505+#endif
14506 if (!capable(CAP_SYS_RAWIO))
14507 return -EPERM;
14508 }
14509diff -urNp linux-2.6.32.41/arch/x86/kernel/irq_32.c linux-2.6.32.41/arch/x86/kernel/irq_32.c
14510--- linux-2.6.32.41/arch/x86/kernel/irq_32.c 2011-03-27 14:31:47.000000000 -0400
14511+++ linux-2.6.32.41/arch/x86/kernel/irq_32.c 2011-04-23 13:26:46.000000000 -0400
14512@@ -35,7 +35,7 @@ static int check_stack_overflow(void)
14513 __asm__ __volatile__("andl %%esp,%0" :
14514 "=r" (sp) : "0" (THREAD_SIZE - 1));
14515
14516- return sp < (sizeof(struct thread_info) + STACK_WARN);
14517+ return sp < STACK_WARN;
14518 }
14519
14520 static void print_stack_overflow(void)
14521@@ -54,9 +54,9 @@ static inline void print_stack_overflow(
14522 * per-CPU IRQ handling contexts (thread information and stack)
14523 */
14524 union irq_ctx {
14525- struct thread_info tinfo;
14526- u32 stack[THREAD_SIZE/sizeof(u32)];
14527-} __attribute__((aligned(PAGE_SIZE)));
14528+ unsigned long previous_esp;
14529+ u32 stack[THREAD_SIZE/sizeof(u32)];
14530+} __attribute__((aligned(THREAD_SIZE)));
14531
14532 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
14533 static DEFINE_PER_CPU(union irq_ctx *, softirq_ctx);
14534@@ -78,10 +78,9 @@ static void call_on_stack(void *func, vo
14535 static inline int
14536 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
14537 {
14538- union irq_ctx *curctx, *irqctx;
14539+ union irq_ctx *irqctx;
14540 u32 *isp, arg1, arg2;
14541
14542- curctx = (union irq_ctx *) current_thread_info();
14543 irqctx = __get_cpu_var(hardirq_ctx);
14544
14545 /*
14546@@ -90,21 +89,17 @@ execute_on_irq_stack(int overflow, struc
14547 * handler) we can't do that and just have to keep using the
14548 * current stack (which is the irq stack already after all)
14549 */
14550- if (unlikely(curctx == irqctx))
14551+ if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
14552 return 0;
14553
14554 /* build the stack frame on the IRQ stack */
14555- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
14556- irqctx->tinfo.task = curctx->tinfo.task;
14557- irqctx->tinfo.previous_esp = current_stack_pointer;
14558+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
14559+ irqctx->previous_esp = current_stack_pointer;
14560+ add_preempt_count(HARDIRQ_OFFSET);
14561
14562- /*
14563- * Copy the softirq bits in preempt_count so that the
14564- * softirq checks work in the hardirq context.
14565- */
14566- irqctx->tinfo.preempt_count =
14567- (irqctx->tinfo.preempt_count & ~SOFTIRQ_MASK) |
14568- (curctx->tinfo.preempt_count & SOFTIRQ_MASK);
14569+#ifdef CONFIG_PAX_MEMORY_UDEREF
14570+ __set_fs(MAKE_MM_SEG(0));
14571+#endif
14572
14573 if (unlikely(overflow))
14574 call_on_stack(print_stack_overflow, isp);
14575@@ -116,6 +111,12 @@ execute_on_irq_stack(int overflow, struc
14576 : "0" (irq), "1" (desc), "2" (isp),
14577 "D" (desc->handle_irq)
14578 : "memory", "cc", "ecx");
14579+
14580+#ifdef CONFIG_PAX_MEMORY_UDEREF
14581+ __set_fs(current_thread_info()->addr_limit);
14582+#endif
14583+
14584+ sub_preempt_count(HARDIRQ_OFFSET);
14585 return 1;
14586 }
14587
14588@@ -124,28 +125,11 @@ execute_on_irq_stack(int overflow, struc
14589 */
14590 void __cpuinit irq_ctx_init(int cpu)
14591 {
14592- union irq_ctx *irqctx;
14593-
14594 if (per_cpu(hardirq_ctx, cpu))
14595 return;
14596
14597- irqctx = &per_cpu(hardirq_stack, cpu);
14598- irqctx->tinfo.task = NULL;
14599- irqctx->tinfo.exec_domain = NULL;
14600- irqctx->tinfo.cpu = cpu;
14601- irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
14602- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
14603-
14604- per_cpu(hardirq_ctx, cpu) = irqctx;
14605-
14606- irqctx = &per_cpu(softirq_stack, cpu);
14607- irqctx->tinfo.task = NULL;
14608- irqctx->tinfo.exec_domain = NULL;
14609- irqctx->tinfo.cpu = cpu;
14610- irqctx->tinfo.preempt_count = 0;
14611- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
14612-
14613- per_cpu(softirq_ctx, cpu) = irqctx;
14614+ per_cpu(hardirq_ctx, cpu) = &per_cpu(hardirq_stack, cpu);
14615+ per_cpu(softirq_ctx, cpu) = &per_cpu(softirq_stack, cpu);
14616
14617 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
14618 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
14619@@ -159,7 +143,6 @@ void irq_ctx_exit(int cpu)
14620 asmlinkage void do_softirq(void)
14621 {
14622 unsigned long flags;
14623- struct thread_info *curctx;
14624 union irq_ctx *irqctx;
14625 u32 *isp;
14626
14627@@ -169,15 +152,22 @@ asmlinkage void do_softirq(void)
14628 local_irq_save(flags);
14629
14630 if (local_softirq_pending()) {
14631- curctx = current_thread_info();
14632 irqctx = __get_cpu_var(softirq_ctx);
14633- irqctx->tinfo.task = curctx->task;
14634- irqctx->tinfo.previous_esp = current_stack_pointer;
14635+ irqctx->previous_esp = current_stack_pointer;
14636
14637 /* build the stack frame on the softirq stack */
14638- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
14639+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
14640+
14641+#ifdef CONFIG_PAX_MEMORY_UDEREF
14642+ __set_fs(MAKE_MM_SEG(0));
14643+#endif
14644
14645 call_on_stack(__do_softirq, isp);
14646+
14647+#ifdef CONFIG_PAX_MEMORY_UDEREF
14648+ __set_fs(current_thread_info()->addr_limit);
14649+#endif
14650+
14651 /*
14652 * Shouldnt happen, we returned above if in_interrupt():
14653 */
14654diff -urNp linux-2.6.32.41/arch/x86/kernel/irq.c linux-2.6.32.41/arch/x86/kernel/irq.c
14655--- linux-2.6.32.41/arch/x86/kernel/irq.c 2011-03-27 14:31:47.000000000 -0400
14656+++ linux-2.6.32.41/arch/x86/kernel/irq.c 2011-05-04 17:56:28.000000000 -0400
14657@@ -15,7 +15,7 @@
14658 #include <asm/mce.h>
14659 #include <asm/hw_irq.h>
14660
14661-atomic_t irq_err_count;
14662+atomic_unchecked_t irq_err_count;
14663
14664 /* Function pointer for generic interrupt vector handling */
14665 void (*generic_interrupt_extension)(void) = NULL;
14666@@ -114,9 +114,9 @@ static int show_other_interrupts(struct
14667 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
14668 seq_printf(p, " Machine check polls\n");
14669 #endif
14670- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
14671+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
14672 #if defined(CONFIG_X86_IO_APIC)
14673- seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
14674+ seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
14675 #endif
14676 return 0;
14677 }
14678@@ -209,10 +209,10 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
14679
14680 u64 arch_irq_stat(void)
14681 {
14682- u64 sum = atomic_read(&irq_err_count);
14683+ u64 sum = atomic_read_unchecked(&irq_err_count);
14684
14685 #ifdef CONFIG_X86_IO_APIC
14686- sum += atomic_read(&irq_mis_count);
14687+ sum += atomic_read_unchecked(&irq_mis_count);
14688 #endif
14689 return sum;
14690 }
14691diff -urNp linux-2.6.32.41/arch/x86/kernel/kgdb.c linux-2.6.32.41/arch/x86/kernel/kgdb.c
14692--- linux-2.6.32.41/arch/x86/kernel/kgdb.c 2011-03-27 14:31:47.000000000 -0400
14693+++ linux-2.6.32.41/arch/x86/kernel/kgdb.c 2011-05-04 17:56:20.000000000 -0400
14694@@ -390,13 +390,13 @@ int kgdb_arch_handle_exception(int e_vec
14695
14696 /* clear the trace bit */
14697 linux_regs->flags &= ~X86_EFLAGS_TF;
14698- atomic_set(&kgdb_cpu_doing_single_step, -1);
14699+ atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
14700
14701 /* set the trace bit if we're stepping */
14702 if (remcomInBuffer[0] == 's') {
14703 linux_regs->flags |= X86_EFLAGS_TF;
14704 kgdb_single_step = 1;
14705- atomic_set(&kgdb_cpu_doing_single_step,
14706+ atomic_set_unchecked(&kgdb_cpu_doing_single_step,
14707 raw_smp_processor_id());
14708 }
14709
14710@@ -476,7 +476,7 @@ static int __kgdb_notify(struct die_args
14711 break;
14712
14713 case DIE_DEBUG:
14714- if (atomic_read(&kgdb_cpu_doing_single_step) ==
14715+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) ==
14716 raw_smp_processor_id()) {
14717 if (user_mode(regs))
14718 return single_step_cont(regs, args);
14719@@ -573,7 +573,7 @@ unsigned long kgdb_arch_pc(int exception
14720 return instruction_pointer(regs);
14721 }
14722
14723-struct kgdb_arch arch_kgdb_ops = {
14724+const struct kgdb_arch arch_kgdb_ops = {
14725 /* Breakpoint instruction: */
14726 .gdb_bpt_instr = { 0xcc },
14727 .flags = KGDB_HW_BREAKPOINT,
14728diff -urNp linux-2.6.32.41/arch/x86/kernel/kprobes.c linux-2.6.32.41/arch/x86/kernel/kprobes.c
14729--- linux-2.6.32.41/arch/x86/kernel/kprobes.c 2011-03-27 14:31:47.000000000 -0400
14730+++ linux-2.6.32.41/arch/x86/kernel/kprobes.c 2011-04-17 15:56:46.000000000 -0400
14731@@ -166,9 +166,13 @@ static void __kprobes set_jmp_op(void *f
14732 char op;
14733 s32 raddr;
14734 } __attribute__((packed)) * jop;
14735- jop = (struct __arch_jmp_op *)from;
14736+
14737+ jop = (struct __arch_jmp_op *)(ktla_ktva(from));
14738+
14739+ pax_open_kernel();
14740 jop->raddr = (s32)((long)(to) - ((long)(from) + 5));
14741 jop->op = RELATIVEJUMP_INSTRUCTION;
14742+ pax_close_kernel();
14743 }
14744
14745 /*
14746@@ -193,7 +197,7 @@ static int __kprobes can_boost(kprobe_op
14747 kprobe_opcode_t opcode;
14748 kprobe_opcode_t *orig_opcodes = opcodes;
14749
14750- if (search_exception_tables((unsigned long)opcodes))
14751+ if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
14752 return 0; /* Page fault may occur on this address. */
14753
14754 retry:
14755@@ -337,7 +341,9 @@ static void __kprobes fix_riprel(struct
14756 disp = (u8 *) p->addr + *((s32 *) insn) -
14757 (u8 *) p->ainsn.insn;
14758 BUG_ON((s64) (s32) disp != disp); /* Sanity check. */
14759+ pax_open_kernel();
14760 *(s32 *)insn = (s32) disp;
14761+ pax_close_kernel();
14762 }
14763 }
14764 #endif
14765@@ -345,16 +351,18 @@ static void __kprobes fix_riprel(struct
14766
14767 static void __kprobes arch_copy_kprobe(struct kprobe *p)
14768 {
14769- memcpy(p->ainsn.insn, p->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
14770+ pax_open_kernel();
14771+ memcpy(p->ainsn.insn, ktla_ktva(p->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
14772+ pax_close_kernel();
14773
14774 fix_riprel(p);
14775
14776- if (can_boost(p->addr))
14777+ if (can_boost(ktla_ktva(p->addr)))
14778 p->ainsn.boostable = 0;
14779 else
14780 p->ainsn.boostable = -1;
14781
14782- p->opcode = *p->addr;
14783+ p->opcode = *(ktla_ktva(p->addr));
14784 }
14785
14786 int __kprobes arch_prepare_kprobe(struct kprobe *p)
14787@@ -432,7 +440,7 @@ static void __kprobes prepare_singlestep
14788 if (p->opcode == BREAKPOINT_INSTRUCTION)
14789 regs->ip = (unsigned long)p->addr;
14790 else
14791- regs->ip = (unsigned long)p->ainsn.insn;
14792+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
14793 }
14794
14795 void __kprobes arch_prepare_kretprobe(struct kretprobe_instance *ri,
14796@@ -453,7 +461,7 @@ static void __kprobes setup_singlestep(s
14797 if (p->ainsn.boostable == 1 && !p->post_handler) {
14798 /* Boost up -- we can execute copied instructions directly */
14799 reset_current_kprobe();
14800- regs->ip = (unsigned long)p->ainsn.insn;
14801+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
14802 preempt_enable_no_resched();
14803 return;
14804 }
14805@@ -523,7 +531,7 @@ static int __kprobes kprobe_handler(stru
14806 struct kprobe_ctlblk *kcb;
14807
14808 addr = (kprobe_opcode_t *)(regs->ip - sizeof(kprobe_opcode_t));
14809- if (*addr != BREAKPOINT_INSTRUCTION) {
14810+ if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
14811 /*
14812 * The breakpoint instruction was removed right
14813 * after we hit it. Another cpu has removed
14814@@ -775,7 +783,7 @@ static void __kprobes resume_execution(s
14815 struct pt_regs *regs, struct kprobe_ctlblk *kcb)
14816 {
14817 unsigned long *tos = stack_addr(regs);
14818- unsigned long copy_ip = (unsigned long)p->ainsn.insn;
14819+ unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
14820 unsigned long orig_ip = (unsigned long)p->addr;
14821 kprobe_opcode_t *insn = p->ainsn.insn;
14822
14823@@ -958,7 +966,7 @@ int __kprobes kprobe_exceptions_notify(s
14824 struct die_args *args = data;
14825 int ret = NOTIFY_DONE;
14826
14827- if (args->regs && user_mode_vm(args->regs))
14828+ if (args->regs && user_mode(args->regs))
14829 return ret;
14830
14831 switch (val) {
14832diff -urNp linux-2.6.32.41/arch/x86/kernel/ldt.c linux-2.6.32.41/arch/x86/kernel/ldt.c
14833--- linux-2.6.32.41/arch/x86/kernel/ldt.c 2011-03-27 14:31:47.000000000 -0400
14834+++ linux-2.6.32.41/arch/x86/kernel/ldt.c 2011-04-17 15:56:46.000000000 -0400
14835@@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, i
14836 if (reload) {
14837 #ifdef CONFIG_SMP
14838 preempt_disable();
14839- load_LDT(pc);
14840+ load_LDT_nolock(pc);
14841 if (!cpumask_equal(mm_cpumask(current->mm),
14842 cpumask_of(smp_processor_id())))
14843 smp_call_function(flush_ldt, current->mm, 1);
14844 preempt_enable();
14845 #else
14846- load_LDT(pc);
14847+ load_LDT_nolock(pc);
14848 #endif
14849 }
14850 if (oldsize) {
14851@@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t
14852 return err;
14853
14854 for (i = 0; i < old->size; i++)
14855- write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
14856+ write_ldt_entry(new->ldt, i, old->ldt + i);
14857 return 0;
14858 }
14859
14860@@ -115,6 +115,24 @@ int init_new_context(struct task_struct
14861 retval = copy_ldt(&mm->context, &old_mm->context);
14862 mutex_unlock(&old_mm->context.lock);
14863 }
14864+
14865+ if (tsk == current) {
14866+ mm->context.vdso = 0;
14867+
14868+#ifdef CONFIG_X86_32
14869+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
14870+ mm->context.user_cs_base = 0UL;
14871+ mm->context.user_cs_limit = ~0UL;
14872+
14873+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
14874+ cpus_clear(mm->context.cpu_user_cs_mask);
14875+#endif
14876+
14877+#endif
14878+#endif
14879+
14880+ }
14881+
14882 return retval;
14883 }
14884
14885@@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, u
14886 }
14887 }
14888
14889+#ifdef CONFIG_PAX_SEGMEXEC
14890+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
14891+ error = -EINVAL;
14892+ goto out_unlock;
14893+ }
14894+#endif
14895+
14896 fill_ldt(&ldt, &ldt_info);
14897 if (oldmode)
14898 ldt.avl = 0;
14899diff -urNp linux-2.6.32.41/arch/x86/kernel/machine_kexec_32.c linux-2.6.32.41/arch/x86/kernel/machine_kexec_32.c
14900--- linux-2.6.32.41/arch/x86/kernel/machine_kexec_32.c 2011-03-27 14:31:47.000000000 -0400
14901+++ linux-2.6.32.41/arch/x86/kernel/machine_kexec_32.c 2011-04-17 15:56:46.000000000 -0400
14902@@ -26,7 +26,7 @@
14903 #include <asm/system.h>
14904 #include <asm/cacheflush.h>
14905
14906-static void set_idt(void *newidt, __u16 limit)
14907+static void set_idt(struct desc_struct *newidt, __u16 limit)
14908 {
14909 struct desc_ptr curidt;
14910
14911@@ -38,7 +38,7 @@ static void set_idt(void *newidt, __u16
14912 }
14913
14914
14915-static void set_gdt(void *newgdt, __u16 limit)
14916+static void set_gdt(struct desc_struct *newgdt, __u16 limit)
14917 {
14918 struct desc_ptr curgdt;
14919
14920@@ -217,7 +217,7 @@ void machine_kexec(struct kimage *image)
14921 }
14922
14923 control_page = page_address(image->control_code_page);
14924- memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
14925+ memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
14926
14927 relocate_kernel_ptr = control_page;
14928 page_list[PA_CONTROL_PAGE] = __pa(control_page);
14929diff -urNp linux-2.6.32.41/arch/x86/kernel/microcode_amd.c linux-2.6.32.41/arch/x86/kernel/microcode_amd.c
14930--- linux-2.6.32.41/arch/x86/kernel/microcode_amd.c 2011-04-17 17:00:52.000000000 -0400
14931+++ linux-2.6.32.41/arch/x86/kernel/microcode_amd.c 2011-04-17 17:03:05.000000000 -0400
14932@@ -364,7 +364,7 @@ static void microcode_fini_cpu_amd(int c
14933 uci->mc = NULL;
14934 }
14935
14936-static struct microcode_ops microcode_amd_ops = {
14937+static const struct microcode_ops microcode_amd_ops = {
14938 .request_microcode_user = request_microcode_user,
14939 .request_microcode_fw = request_microcode_fw,
14940 .collect_cpu_info = collect_cpu_info_amd,
14941@@ -372,7 +372,7 @@ static struct microcode_ops microcode_am
14942 .microcode_fini_cpu = microcode_fini_cpu_amd,
14943 };
14944
14945-struct microcode_ops * __init init_amd_microcode(void)
14946+const struct microcode_ops * __init init_amd_microcode(void)
14947 {
14948 return &microcode_amd_ops;
14949 }
14950diff -urNp linux-2.6.32.41/arch/x86/kernel/microcode_core.c linux-2.6.32.41/arch/x86/kernel/microcode_core.c
14951--- linux-2.6.32.41/arch/x86/kernel/microcode_core.c 2011-03-27 14:31:47.000000000 -0400
14952+++ linux-2.6.32.41/arch/x86/kernel/microcode_core.c 2011-04-17 15:56:46.000000000 -0400
14953@@ -90,7 +90,7 @@ MODULE_LICENSE("GPL");
14954
14955 #define MICROCODE_VERSION "2.00"
14956
14957-static struct microcode_ops *microcode_ops;
14958+static const struct microcode_ops *microcode_ops;
14959
14960 /*
14961 * Synchronization.
14962diff -urNp linux-2.6.32.41/arch/x86/kernel/microcode_intel.c linux-2.6.32.41/arch/x86/kernel/microcode_intel.c
14963--- linux-2.6.32.41/arch/x86/kernel/microcode_intel.c 2011-03-27 14:31:47.000000000 -0400
14964+++ linux-2.6.32.41/arch/x86/kernel/microcode_intel.c 2011-04-17 15:56:46.000000000 -0400
14965@@ -443,13 +443,13 @@ static enum ucode_state request_microcod
14966
14967 static int get_ucode_user(void *to, const void *from, size_t n)
14968 {
14969- return copy_from_user(to, from, n);
14970+ return copy_from_user(to, (__force const void __user *)from, n);
14971 }
14972
14973 static enum ucode_state
14974 request_microcode_user(int cpu, const void __user *buf, size_t size)
14975 {
14976- return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
14977+ return generic_load_microcode(cpu, (__force void *)buf, size, &get_ucode_user);
14978 }
14979
14980 static void microcode_fini_cpu(int cpu)
14981@@ -460,7 +460,7 @@ static void microcode_fini_cpu(int cpu)
14982 uci->mc = NULL;
14983 }
14984
14985-static struct microcode_ops microcode_intel_ops = {
14986+static const struct microcode_ops microcode_intel_ops = {
14987 .request_microcode_user = request_microcode_user,
14988 .request_microcode_fw = request_microcode_fw,
14989 .collect_cpu_info = collect_cpu_info,
14990@@ -468,7 +468,7 @@ static struct microcode_ops microcode_in
14991 .microcode_fini_cpu = microcode_fini_cpu,
14992 };
14993
14994-struct microcode_ops * __init init_intel_microcode(void)
14995+const struct microcode_ops * __init init_intel_microcode(void)
14996 {
14997 return &microcode_intel_ops;
14998 }
14999diff -urNp linux-2.6.32.41/arch/x86/kernel/module.c linux-2.6.32.41/arch/x86/kernel/module.c
15000--- linux-2.6.32.41/arch/x86/kernel/module.c 2011-03-27 14:31:47.000000000 -0400
15001+++ linux-2.6.32.41/arch/x86/kernel/module.c 2011-04-17 15:56:46.000000000 -0400
15002@@ -34,7 +34,7 @@
15003 #define DEBUGP(fmt...)
15004 #endif
15005
15006-void *module_alloc(unsigned long size)
15007+static void *__module_alloc(unsigned long size, pgprot_t prot)
15008 {
15009 struct vm_struct *area;
15010
15011@@ -48,8 +48,18 @@ void *module_alloc(unsigned long size)
15012 if (!area)
15013 return NULL;
15014
15015- return __vmalloc_area(area, GFP_KERNEL | __GFP_HIGHMEM,
15016- PAGE_KERNEL_EXEC);
15017+ return __vmalloc_area(area, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot);
15018+}
15019+
15020+void *module_alloc(unsigned long size)
15021+{
15022+
15023+#ifdef CONFIG_PAX_KERNEXEC
15024+ return __module_alloc(size, PAGE_KERNEL);
15025+#else
15026+ return __module_alloc(size, PAGE_KERNEL_EXEC);
15027+#endif
15028+
15029 }
15030
15031 /* Free memory returned from module_alloc */
15032@@ -58,6 +68,40 @@ void module_free(struct module *mod, voi
15033 vfree(module_region);
15034 }
15035
15036+#ifdef CONFIG_PAX_KERNEXEC
15037+#ifdef CONFIG_X86_32
15038+void *module_alloc_exec(unsigned long size)
15039+{
15040+ struct vm_struct *area;
15041+
15042+ if (size == 0)
15043+ return NULL;
15044+
15045+ area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
15046+ return area ? area->addr : NULL;
15047+}
15048+EXPORT_SYMBOL(module_alloc_exec);
15049+
15050+void module_free_exec(struct module *mod, void *module_region)
15051+{
15052+ vunmap(module_region);
15053+}
15054+EXPORT_SYMBOL(module_free_exec);
15055+#else
15056+void module_free_exec(struct module *mod, void *module_region)
15057+{
15058+ module_free(mod, module_region);
15059+}
15060+EXPORT_SYMBOL(module_free_exec);
15061+
15062+void *module_alloc_exec(unsigned long size)
15063+{
15064+ return __module_alloc(size, PAGE_KERNEL_RX);
15065+}
15066+EXPORT_SYMBOL(module_alloc_exec);
15067+#endif
15068+#endif
15069+
15070 /* We don't need anything special. */
15071 int module_frob_arch_sections(Elf_Ehdr *hdr,
15072 Elf_Shdr *sechdrs,
15073@@ -77,14 +121,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
15074 unsigned int i;
15075 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
15076 Elf32_Sym *sym;
15077- uint32_t *location;
15078+ uint32_t *plocation, location;
15079
15080 DEBUGP("Applying relocate section %u to %u\n", relsec,
15081 sechdrs[relsec].sh_info);
15082 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
15083 /* This is where to make the change */
15084- location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
15085- + rel[i].r_offset;
15086+ plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
15087+ location = (uint32_t)plocation;
15088+ if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
15089+ plocation = ktla_ktva((void *)plocation);
15090 /* This is the symbol it is referring to. Note that all
15091 undefined symbols have been resolved. */
15092 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
15093@@ -93,11 +139,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
15094 switch (ELF32_R_TYPE(rel[i].r_info)) {
15095 case R_386_32:
15096 /* We add the value into the location given */
15097- *location += sym->st_value;
15098+ pax_open_kernel();
15099+ *plocation += sym->st_value;
15100+ pax_close_kernel();
15101 break;
15102 case R_386_PC32:
15103 /* Add the value, subtract its postition */
15104- *location += sym->st_value - (uint32_t)location;
15105+ pax_open_kernel();
15106+ *plocation += sym->st_value - location;
15107+ pax_close_kernel();
15108 break;
15109 default:
15110 printk(KERN_ERR "module %s: Unknown relocation: %u\n",
15111@@ -153,21 +203,30 @@ int apply_relocate_add(Elf64_Shdr *sechd
15112 case R_X86_64_NONE:
15113 break;
15114 case R_X86_64_64:
15115+ pax_open_kernel();
15116 *(u64 *)loc = val;
15117+ pax_close_kernel();
15118 break;
15119 case R_X86_64_32:
15120+ pax_open_kernel();
15121 *(u32 *)loc = val;
15122+ pax_close_kernel();
15123 if (val != *(u32 *)loc)
15124 goto overflow;
15125 break;
15126 case R_X86_64_32S:
15127+ pax_open_kernel();
15128 *(s32 *)loc = val;
15129+ pax_close_kernel();
15130 if ((s64)val != *(s32 *)loc)
15131 goto overflow;
15132 break;
15133 case R_X86_64_PC32:
15134 val -= (u64)loc;
15135+ pax_open_kernel();
15136 *(u32 *)loc = val;
15137+ pax_close_kernel();
15138+
15139 #if 0
15140 if ((s64)val != *(s32 *)loc)
15141 goto overflow;
15142diff -urNp linux-2.6.32.41/arch/x86/kernel/paravirt.c linux-2.6.32.41/arch/x86/kernel/paravirt.c
15143--- linux-2.6.32.41/arch/x86/kernel/paravirt.c 2011-03-27 14:31:47.000000000 -0400
15144+++ linux-2.6.32.41/arch/x86/kernel/paravirt.c 2011-05-16 21:46:57.000000000 -0400
15145@@ -122,7 +122,7 @@ unsigned paravirt_patch_jmp(void *insnbu
15146 * corresponding structure. */
15147 static void *get_call_destination(u8 type)
15148 {
15149- struct paravirt_patch_template tmpl = {
15150+ const struct paravirt_patch_template tmpl = {
15151 .pv_init_ops = pv_init_ops,
15152 .pv_time_ops = pv_time_ops,
15153 .pv_cpu_ops = pv_cpu_ops,
15154@@ -133,6 +133,9 @@ static void *get_call_destination(u8 typ
15155 .pv_lock_ops = pv_lock_ops,
15156 #endif
15157 };
15158+
15159+ pax_track_stack();
15160+
15161 return *((void **)&tmpl + type);
15162 }
15163
15164@@ -145,14 +148,14 @@ unsigned paravirt_patch_default(u8 type,
15165 if (opfunc == NULL)
15166 /* If there's no function, patch it with a ud2a (BUG) */
15167 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
15168- else if (opfunc == _paravirt_nop)
15169+ else if (opfunc == (void *)_paravirt_nop)
15170 /* If the operation is a nop, then nop the callsite */
15171 ret = paravirt_patch_nop();
15172
15173 /* identity functions just return their single argument */
15174- else if (opfunc == _paravirt_ident_32)
15175+ else if (opfunc == (void *)_paravirt_ident_32)
15176 ret = paravirt_patch_ident_32(insnbuf, len);
15177- else if (opfunc == _paravirt_ident_64)
15178+ else if (opfunc == (void *)_paravirt_ident_64)
15179 ret = paravirt_patch_ident_64(insnbuf, len);
15180
15181 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
15182@@ -178,7 +181,7 @@ unsigned paravirt_patch_insns(void *insn
15183 if (insn_len > len || start == NULL)
15184 insn_len = len;
15185 else
15186- memcpy(insnbuf, start, insn_len);
15187+ memcpy(insnbuf, ktla_ktva(start), insn_len);
15188
15189 return insn_len;
15190 }
15191@@ -294,22 +297,22 @@ void arch_flush_lazy_mmu_mode(void)
15192 preempt_enable();
15193 }
15194
15195-struct pv_info pv_info = {
15196+struct pv_info pv_info __read_only = {
15197 .name = "bare hardware",
15198 .paravirt_enabled = 0,
15199 .kernel_rpl = 0,
15200 .shared_kernel_pmd = 1, /* Only used when CONFIG_X86_PAE is set */
15201 };
15202
15203-struct pv_init_ops pv_init_ops = {
15204+struct pv_init_ops pv_init_ops __read_only = {
15205 .patch = native_patch,
15206 };
15207
15208-struct pv_time_ops pv_time_ops = {
15209+struct pv_time_ops pv_time_ops __read_only = {
15210 .sched_clock = native_sched_clock,
15211 };
15212
15213-struct pv_irq_ops pv_irq_ops = {
15214+struct pv_irq_ops pv_irq_ops __read_only = {
15215 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
15216 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
15217 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
15218@@ -321,7 +324,7 @@ struct pv_irq_ops pv_irq_ops = {
15219 #endif
15220 };
15221
15222-struct pv_cpu_ops pv_cpu_ops = {
15223+struct pv_cpu_ops pv_cpu_ops __read_only = {
15224 .cpuid = native_cpuid,
15225 .get_debugreg = native_get_debugreg,
15226 .set_debugreg = native_set_debugreg,
15227@@ -382,7 +385,7 @@ struct pv_cpu_ops pv_cpu_ops = {
15228 .end_context_switch = paravirt_nop,
15229 };
15230
15231-struct pv_apic_ops pv_apic_ops = {
15232+struct pv_apic_ops pv_apic_ops __read_only = {
15233 #ifdef CONFIG_X86_LOCAL_APIC
15234 .startup_ipi_hook = paravirt_nop,
15235 #endif
15236@@ -396,7 +399,7 @@ struct pv_apic_ops pv_apic_ops = {
15237 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
15238 #endif
15239
15240-struct pv_mmu_ops pv_mmu_ops = {
15241+struct pv_mmu_ops pv_mmu_ops __read_only = {
15242
15243 .read_cr2 = native_read_cr2,
15244 .write_cr2 = native_write_cr2,
15245@@ -467,6 +470,12 @@ struct pv_mmu_ops pv_mmu_ops = {
15246 },
15247
15248 .set_fixmap = native_set_fixmap,
15249+
15250+#ifdef CONFIG_PAX_KERNEXEC
15251+ .pax_open_kernel = native_pax_open_kernel,
15252+ .pax_close_kernel = native_pax_close_kernel,
15253+#endif
15254+
15255 };
15256
15257 EXPORT_SYMBOL_GPL(pv_time_ops);
15258diff -urNp linux-2.6.32.41/arch/x86/kernel/paravirt-spinlocks.c linux-2.6.32.41/arch/x86/kernel/paravirt-spinlocks.c
15259--- linux-2.6.32.41/arch/x86/kernel/paravirt-spinlocks.c 2011-03-27 14:31:47.000000000 -0400
15260+++ linux-2.6.32.41/arch/x86/kernel/paravirt-spinlocks.c 2011-04-17 15:56:46.000000000 -0400
15261@@ -13,7 +13,7 @@ default_spin_lock_flags(raw_spinlock_t *
15262 __raw_spin_lock(lock);
15263 }
15264
15265-struct pv_lock_ops pv_lock_ops = {
15266+struct pv_lock_ops pv_lock_ops __read_only = {
15267 #ifdef CONFIG_SMP
15268 .spin_is_locked = __ticket_spin_is_locked,
15269 .spin_is_contended = __ticket_spin_is_contended,
15270diff -urNp linux-2.6.32.41/arch/x86/kernel/pci-calgary_64.c linux-2.6.32.41/arch/x86/kernel/pci-calgary_64.c
15271--- linux-2.6.32.41/arch/x86/kernel/pci-calgary_64.c 2011-03-27 14:31:47.000000000 -0400
15272+++ linux-2.6.32.41/arch/x86/kernel/pci-calgary_64.c 2011-04-17 15:56:46.000000000 -0400
15273@@ -477,7 +477,7 @@ static void calgary_free_coherent(struct
15274 free_pages((unsigned long)vaddr, get_order(size));
15275 }
15276
15277-static struct dma_map_ops calgary_dma_ops = {
15278+static const struct dma_map_ops calgary_dma_ops = {
15279 .alloc_coherent = calgary_alloc_coherent,
15280 .free_coherent = calgary_free_coherent,
15281 .map_sg = calgary_map_sg,
15282diff -urNp linux-2.6.32.41/arch/x86/kernel/pci-dma.c linux-2.6.32.41/arch/x86/kernel/pci-dma.c
15283--- linux-2.6.32.41/arch/x86/kernel/pci-dma.c 2011-03-27 14:31:47.000000000 -0400
15284+++ linux-2.6.32.41/arch/x86/kernel/pci-dma.c 2011-04-17 15:56:46.000000000 -0400
15285@@ -14,7 +14,7 @@
15286
15287 static int forbid_dac __read_mostly;
15288
15289-struct dma_map_ops *dma_ops;
15290+const struct dma_map_ops *dma_ops;
15291 EXPORT_SYMBOL(dma_ops);
15292
15293 static int iommu_sac_force __read_mostly;
15294@@ -243,7 +243,7 @@ early_param("iommu", iommu_setup);
15295
15296 int dma_supported(struct device *dev, u64 mask)
15297 {
15298- struct dma_map_ops *ops = get_dma_ops(dev);
15299+ const struct dma_map_ops *ops = get_dma_ops(dev);
15300
15301 #ifdef CONFIG_PCI
15302 if (mask > 0xffffffff && forbid_dac > 0) {
15303diff -urNp linux-2.6.32.41/arch/x86/kernel/pci-gart_64.c linux-2.6.32.41/arch/x86/kernel/pci-gart_64.c
15304--- linux-2.6.32.41/arch/x86/kernel/pci-gart_64.c 2011-03-27 14:31:47.000000000 -0400
15305+++ linux-2.6.32.41/arch/x86/kernel/pci-gart_64.c 2011-04-17 15:56:46.000000000 -0400
15306@@ -682,7 +682,7 @@ static __init int init_k8_gatt(struct ag
15307 return -1;
15308 }
15309
15310-static struct dma_map_ops gart_dma_ops = {
15311+static const struct dma_map_ops gart_dma_ops = {
15312 .map_sg = gart_map_sg,
15313 .unmap_sg = gart_unmap_sg,
15314 .map_page = gart_map_page,
15315diff -urNp linux-2.6.32.41/arch/x86/kernel/pci-nommu.c linux-2.6.32.41/arch/x86/kernel/pci-nommu.c
15316--- linux-2.6.32.41/arch/x86/kernel/pci-nommu.c 2011-03-27 14:31:47.000000000 -0400
15317+++ linux-2.6.32.41/arch/x86/kernel/pci-nommu.c 2011-04-17 15:56:46.000000000 -0400
15318@@ -94,7 +94,7 @@ static void nommu_sync_sg_for_device(str
15319 flush_write_buffers();
15320 }
15321
15322-struct dma_map_ops nommu_dma_ops = {
15323+const struct dma_map_ops nommu_dma_ops = {
15324 .alloc_coherent = dma_generic_alloc_coherent,
15325 .free_coherent = nommu_free_coherent,
15326 .map_sg = nommu_map_sg,
15327diff -urNp linux-2.6.32.41/arch/x86/kernel/pci-swiotlb.c linux-2.6.32.41/arch/x86/kernel/pci-swiotlb.c
15328--- linux-2.6.32.41/arch/x86/kernel/pci-swiotlb.c 2011-03-27 14:31:47.000000000 -0400
15329+++ linux-2.6.32.41/arch/x86/kernel/pci-swiotlb.c 2011-04-17 15:56:46.000000000 -0400
15330@@ -25,7 +25,7 @@ static void *x86_swiotlb_alloc_coherent(
15331 return swiotlb_alloc_coherent(hwdev, size, dma_handle, flags);
15332 }
15333
15334-static struct dma_map_ops swiotlb_dma_ops = {
15335+static const struct dma_map_ops swiotlb_dma_ops = {
15336 .mapping_error = swiotlb_dma_mapping_error,
15337 .alloc_coherent = x86_swiotlb_alloc_coherent,
15338 .free_coherent = swiotlb_free_coherent,
15339diff -urNp linux-2.6.32.41/arch/x86/kernel/process_32.c linux-2.6.32.41/arch/x86/kernel/process_32.c
15340--- linux-2.6.32.41/arch/x86/kernel/process_32.c 2011-03-27 14:31:47.000000000 -0400
15341+++ linux-2.6.32.41/arch/x86/kernel/process_32.c 2011-05-16 21:46:57.000000000 -0400
15342@@ -67,6 +67,7 @@ asmlinkage void ret_from_fork(void) __as
15343 unsigned long thread_saved_pc(struct task_struct *tsk)
15344 {
15345 return ((unsigned long *)tsk->thread.sp)[3];
15346+//XXX return tsk->thread.eip;
15347 }
15348
15349 #ifndef CONFIG_SMP
15350@@ -129,15 +130,14 @@ void __show_regs(struct pt_regs *regs, i
15351 unsigned short ss, gs;
15352 const char *board;
15353
15354- if (user_mode_vm(regs)) {
15355+ if (user_mode(regs)) {
15356 sp = regs->sp;
15357 ss = regs->ss & 0xffff;
15358- gs = get_user_gs(regs);
15359 } else {
15360 sp = (unsigned long) (&regs->sp);
15361 savesegment(ss, ss);
15362- savesegment(gs, gs);
15363 }
15364+ gs = get_user_gs(regs);
15365
15366 printk("\n");
15367
15368@@ -210,10 +210,10 @@ int kernel_thread(int (*fn)(void *), voi
15369 regs.bx = (unsigned long) fn;
15370 regs.dx = (unsigned long) arg;
15371
15372- regs.ds = __USER_DS;
15373- regs.es = __USER_DS;
15374+ regs.ds = __KERNEL_DS;
15375+ regs.es = __KERNEL_DS;
15376 regs.fs = __KERNEL_PERCPU;
15377- regs.gs = __KERNEL_STACK_CANARY;
15378+ savesegment(gs, regs.gs);
15379 regs.orig_ax = -1;
15380 regs.ip = (unsigned long) kernel_thread_helper;
15381 regs.cs = __KERNEL_CS | get_kernel_rpl();
15382@@ -247,13 +247,14 @@ int copy_thread(unsigned long clone_flag
15383 struct task_struct *tsk;
15384 int err;
15385
15386- childregs = task_pt_regs(p);
15387+ childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
15388 *childregs = *regs;
15389 childregs->ax = 0;
15390 childregs->sp = sp;
15391
15392 p->thread.sp = (unsigned long) childregs;
15393 p->thread.sp0 = (unsigned long) (childregs+1);
15394+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
15395
15396 p->thread.ip = (unsigned long) ret_from_fork;
15397
15398@@ -346,7 +347,7 @@ __switch_to(struct task_struct *prev_p,
15399 struct thread_struct *prev = &prev_p->thread,
15400 *next = &next_p->thread;
15401 int cpu = smp_processor_id();
15402- struct tss_struct *tss = &per_cpu(init_tss, cpu);
15403+ struct tss_struct *tss = init_tss + cpu;
15404 bool preload_fpu;
15405
15406 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
15407@@ -381,6 +382,10 @@ __switch_to(struct task_struct *prev_p,
15408 */
15409 lazy_save_gs(prev->gs);
15410
15411+#ifdef CONFIG_PAX_MEMORY_UDEREF
15412+ __set_fs(task_thread_info(next_p)->addr_limit);
15413+#endif
15414+
15415 /*
15416 * Load the per-thread Thread-Local Storage descriptor.
15417 */
15418@@ -416,6 +421,9 @@ __switch_to(struct task_struct *prev_p,
15419 */
15420 arch_end_context_switch(next_p);
15421
15422+ percpu_write(current_task, next_p);
15423+ percpu_write(current_tinfo, &next_p->tinfo);
15424+
15425 if (preload_fpu)
15426 __math_state_restore();
15427
15428@@ -425,8 +433,6 @@ __switch_to(struct task_struct *prev_p,
15429 if (prev->gs | next->gs)
15430 lazy_load_gs(next->gs);
15431
15432- percpu_write(current_task, next_p);
15433-
15434 return prev_p;
15435 }
15436
15437@@ -496,4 +502,3 @@ unsigned long get_wchan(struct task_stru
15438 } while (count++ < 16);
15439 return 0;
15440 }
15441-
15442diff -urNp linux-2.6.32.41/arch/x86/kernel/process_64.c linux-2.6.32.41/arch/x86/kernel/process_64.c
15443--- linux-2.6.32.41/arch/x86/kernel/process_64.c 2011-03-27 14:31:47.000000000 -0400
15444+++ linux-2.6.32.41/arch/x86/kernel/process_64.c 2011-05-16 21:46:57.000000000 -0400
15445@@ -91,7 +91,7 @@ static void __exit_idle(void)
15446 void exit_idle(void)
15447 {
15448 /* idle loop has pid 0 */
15449- if (current->pid)
15450+ if (task_pid_nr(current))
15451 return;
15452 __exit_idle();
15453 }
15454@@ -170,7 +170,7 @@ void __show_regs(struct pt_regs *regs, i
15455 if (!board)
15456 board = "";
15457 printk(KERN_INFO "Pid: %d, comm: %.20s %s %s %.*s %s\n",
15458- current->pid, current->comm, print_tainted(),
15459+ task_pid_nr(current), current->comm, print_tainted(),
15460 init_utsname()->release,
15461 (int)strcspn(init_utsname()->version, " "),
15462 init_utsname()->version, board);
15463@@ -280,8 +280,7 @@ int copy_thread(unsigned long clone_flag
15464 struct pt_regs *childregs;
15465 struct task_struct *me = current;
15466
15467- childregs = ((struct pt_regs *)
15468- (THREAD_SIZE + task_stack_page(p))) - 1;
15469+ childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 16;
15470 *childregs = *regs;
15471
15472 childregs->ax = 0;
15473@@ -292,6 +291,7 @@ int copy_thread(unsigned long clone_flag
15474 p->thread.sp = (unsigned long) childregs;
15475 p->thread.sp0 = (unsigned long) (childregs+1);
15476 p->thread.usersp = me->thread.usersp;
15477+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
15478
15479 set_tsk_thread_flag(p, TIF_FORK);
15480
15481@@ -380,7 +380,7 @@ __switch_to(struct task_struct *prev_p,
15482 struct thread_struct *prev = &prev_p->thread;
15483 struct thread_struct *next = &next_p->thread;
15484 int cpu = smp_processor_id();
15485- struct tss_struct *tss = &per_cpu(init_tss, cpu);
15486+ struct tss_struct *tss = init_tss + cpu;
15487 unsigned fsindex, gsindex;
15488 bool preload_fpu;
15489
15490@@ -476,10 +476,9 @@ __switch_to(struct task_struct *prev_p,
15491 prev->usersp = percpu_read(old_rsp);
15492 percpu_write(old_rsp, next->usersp);
15493 percpu_write(current_task, next_p);
15494+ percpu_write(current_tinfo, &next_p->tinfo);
15495
15496- percpu_write(kernel_stack,
15497- (unsigned long)task_stack_page(next_p) +
15498- THREAD_SIZE - KERNEL_STACK_OFFSET);
15499+ percpu_write(kernel_stack, next->sp0);
15500
15501 /*
15502 * Now maybe reload the debug registers and handle I/O bitmaps
15503@@ -560,12 +559,11 @@ unsigned long get_wchan(struct task_stru
15504 if (!p || p == current || p->state == TASK_RUNNING)
15505 return 0;
15506 stack = (unsigned long)task_stack_page(p);
15507- if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
15508+ if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
15509 return 0;
15510 fp = *(u64 *)(p->thread.sp);
15511 do {
15512- if (fp < (unsigned long)stack ||
15513- fp >= (unsigned long)stack+THREAD_SIZE)
15514+ if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
15515 return 0;
15516 ip = *(u64 *)(fp+8);
15517 if (!in_sched_functions(ip))
15518diff -urNp linux-2.6.32.41/arch/x86/kernel/process.c linux-2.6.32.41/arch/x86/kernel/process.c
15519--- linux-2.6.32.41/arch/x86/kernel/process.c 2011-04-22 19:16:29.000000000 -0400
15520+++ linux-2.6.32.41/arch/x86/kernel/process.c 2011-05-22 23:02:03.000000000 -0400
15521@@ -51,16 +51,33 @@ void free_thread_xstate(struct task_stru
15522
15523 void free_thread_info(struct thread_info *ti)
15524 {
15525- free_thread_xstate(ti->task);
15526 free_pages((unsigned long)ti, get_order(THREAD_SIZE));
15527 }
15528
15529+static struct kmem_cache *task_struct_cachep;
15530+
15531 void arch_task_cache_init(void)
15532 {
15533- task_xstate_cachep =
15534- kmem_cache_create("task_xstate", xstate_size,
15535+ /* create a slab on which task_structs can be allocated */
15536+ task_struct_cachep =
15537+ kmem_cache_create("task_struct", sizeof(struct task_struct),
15538+ ARCH_MIN_TASKALIGN, SLAB_PANIC | SLAB_NOTRACK, NULL);
15539+
15540+ task_xstate_cachep =
15541+ kmem_cache_create("task_xstate", xstate_size,
15542 __alignof__(union thread_xstate),
15543- SLAB_PANIC | SLAB_NOTRACK, NULL);
15544+ SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
15545+}
15546+
15547+struct task_struct *alloc_task_struct(void)
15548+{
15549+ return kmem_cache_alloc(task_struct_cachep, GFP_KERNEL);
15550+}
15551+
15552+void free_task_struct(struct task_struct *task)
15553+{
15554+ free_thread_xstate(task);
15555+ kmem_cache_free(task_struct_cachep, task);
15556 }
15557
15558 /*
15559@@ -73,7 +90,7 @@ void exit_thread(void)
15560 unsigned long *bp = t->io_bitmap_ptr;
15561
15562 if (bp) {
15563- struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
15564+ struct tss_struct *tss = init_tss + get_cpu();
15565
15566 t->io_bitmap_ptr = NULL;
15567 clear_thread_flag(TIF_IO_BITMAP);
15568@@ -93,6 +110,9 @@ void flush_thread(void)
15569
15570 clear_tsk_thread_flag(tsk, TIF_DEBUG);
15571
15572+#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
15573+ loadsegment(gs, 0);
15574+#endif
15575 tsk->thread.debugreg0 = 0;
15576 tsk->thread.debugreg1 = 0;
15577 tsk->thread.debugreg2 = 0;
15578@@ -307,7 +327,7 @@ void default_idle(void)
15579 EXPORT_SYMBOL(default_idle);
15580 #endif
15581
15582-void stop_this_cpu(void *dummy)
15583+__noreturn void stop_this_cpu(void *dummy)
15584 {
15585 local_irq_disable();
15586 /*
15587@@ -568,16 +588,35 @@ static int __init idle_setup(char *str)
15588 }
15589 early_param("idle", idle_setup);
15590
15591-unsigned long arch_align_stack(unsigned long sp)
15592+#ifdef CONFIG_PAX_RANDKSTACK
15593+asmlinkage void pax_randomize_kstack(void)
15594 {
15595- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
15596- sp -= get_random_int() % 8192;
15597- return sp & ~0xf;
15598-}
15599+ struct thread_struct *thread = &current->thread;
15600+ unsigned long time;
15601
15602-unsigned long arch_randomize_brk(struct mm_struct *mm)
15603-{
15604- unsigned long range_end = mm->brk + 0x02000000;
15605- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
15606+ if (!randomize_va_space)
15607+ return;
15608+
15609+ rdtscl(time);
15610+
15611+ /* P4 seems to return a 0 LSB, ignore it */
15612+#ifdef CONFIG_MPENTIUM4
15613+ time &= 0x3EUL;
15614+ time <<= 2;
15615+#elif defined(CONFIG_X86_64)
15616+ time &= 0xFUL;
15617+ time <<= 4;
15618+#else
15619+ time &= 0x1FUL;
15620+ time <<= 3;
15621+#endif
15622+
15623+ thread->sp0 ^= time;
15624+ load_sp0(init_tss + smp_processor_id(), thread);
15625+
15626+#ifdef CONFIG_X86_64
15627+ percpu_write(kernel_stack, thread->sp0);
15628+#endif
15629 }
15630+#endif
15631
15632diff -urNp linux-2.6.32.41/arch/x86/kernel/ptrace.c linux-2.6.32.41/arch/x86/kernel/ptrace.c
15633--- linux-2.6.32.41/arch/x86/kernel/ptrace.c 2011-03-27 14:31:47.000000000 -0400
15634+++ linux-2.6.32.41/arch/x86/kernel/ptrace.c 2011-04-17 15:56:46.000000000 -0400
15635@@ -925,7 +925,7 @@ static const struct user_regset_view use
15636 long arch_ptrace(struct task_struct *child, long request, long addr, long data)
15637 {
15638 int ret;
15639- unsigned long __user *datap = (unsigned long __user *)data;
15640+ unsigned long __user *datap = (__force unsigned long __user *)data;
15641
15642 switch (request) {
15643 /* read the word at location addr in the USER area. */
15644@@ -1012,14 +1012,14 @@ long arch_ptrace(struct task_struct *chi
15645 if (addr < 0)
15646 return -EIO;
15647 ret = do_get_thread_area(child, addr,
15648- (struct user_desc __user *) data);
15649+ (__force struct user_desc __user *) data);
15650 break;
15651
15652 case PTRACE_SET_THREAD_AREA:
15653 if (addr < 0)
15654 return -EIO;
15655 ret = do_set_thread_area(child, addr,
15656- (struct user_desc __user *) data, 0);
15657+ (__force struct user_desc __user *) data, 0);
15658 break;
15659 #endif
15660
15661@@ -1038,12 +1038,12 @@ long arch_ptrace(struct task_struct *chi
15662 #ifdef CONFIG_X86_PTRACE_BTS
15663 case PTRACE_BTS_CONFIG:
15664 ret = ptrace_bts_config
15665- (child, data, (struct ptrace_bts_config __user *)addr);
15666+ (child, data, (__force struct ptrace_bts_config __user *)addr);
15667 break;
15668
15669 case PTRACE_BTS_STATUS:
15670 ret = ptrace_bts_status
15671- (child, data, (struct ptrace_bts_config __user *)addr);
15672+ (child, data, (__force struct ptrace_bts_config __user *)addr);
15673 break;
15674
15675 case PTRACE_BTS_SIZE:
15676@@ -1052,7 +1052,7 @@ long arch_ptrace(struct task_struct *chi
15677
15678 case PTRACE_BTS_GET:
15679 ret = ptrace_bts_read_record
15680- (child, data, (struct bts_struct __user *) addr);
15681+ (child, data, (__force struct bts_struct __user *) addr);
15682 break;
15683
15684 case PTRACE_BTS_CLEAR:
15685@@ -1061,7 +1061,7 @@ long arch_ptrace(struct task_struct *chi
15686
15687 case PTRACE_BTS_DRAIN:
15688 ret = ptrace_bts_drain
15689- (child, data, (struct bts_struct __user *) addr);
15690+ (child, data, (__force struct bts_struct __user *) addr);
15691 break;
15692 #endif /* CONFIG_X86_PTRACE_BTS */
15693
15694@@ -1450,7 +1450,7 @@ void send_sigtrap(struct task_struct *ts
15695 info.si_code = si_code;
15696
15697 /* User-mode ip? */
15698- info.si_addr = user_mode_vm(regs) ? (void __user *) regs->ip : NULL;
15699+ info.si_addr = user_mode(regs) ? (__force void __user *) regs->ip : NULL;
15700
15701 /* Send us the fake SIGTRAP */
15702 force_sig_info(SIGTRAP, &info, tsk);
15703@@ -1469,7 +1469,7 @@ void send_sigtrap(struct task_struct *ts
15704 * We must return the syscall number to actually look up in the table.
15705 * This can be -1L to skip running any syscall at all.
15706 */
15707-asmregparm long syscall_trace_enter(struct pt_regs *regs)
15708+long syscall_trace_enter(struct pt_regs *regs)
15709 {
15710 long ret = 0;
15711
15712@@ -1514,7 +1514,7 @@ asmregparm long syscall_trace_enter(stru
15713 return ret ?: regs->orig_ax;
15714 }
15715
15716-asmregparm void syscall_trace_leave(struct pt_regs *regs)
15717+void syscall_trace_leave(struct pt_regs *regs)
15718 {
15719 if (unlikely(current->audit_context))
15720 audit_syscall_exit(AUDITSC_RESULT(regs->ax), regs->ax);
15721diff -urNp linux-2.6.32.41/arch/x86/kernel/reboot.c linux-2.6.32.41/arch/x86/kernel/reboot.c
15722--- linux-2.6.32.41/arch/x86/kernel/reboot.c 2011-03-27 14:31:47.000000000 -0400
15723+++ linux-2.6.32.41/arch/x86/kernel/reboot.c 2011-05-22 23:02:03.000000000 -0400
15724@@ -33,7 +33,7 @@ void (*pm_power_off)(void);
15725 EXPORT_SYMBOL(pm_power_off);
15726
15727 static const struct desc_ptr no_idt = {};
15728-static int reboot_mode;
15729+static unsigned short reboot_mode;
15730 enum reboot_type reboot_type = BOOT_KBD;
15731 int reboot_force;
15732
15733@@ -292,12 +292,12 @@ core_initcall(reboot_init);
15734 controller to pulse the CPU reset line, which is more thorough, but
15735 doesn't work with at least one type of 486 motherboard. It is easy
15736 to stop this code working; hence the copious comments. */
15737-static const unsigned long long
15738-real_mode_gdt_entries [3] =
15739+static struct desc_struct
15740+real_mode_gdt_entries [3] __read_only =
15741 {
15742- 0x0000000000000000ULL, /* Null descriptor */
15743- 0x00009b000000ffffULL, /* 16-bit real-mode 64k code at 0x00000000 */
15744- 0x000093000100ffffULL /* 16-bit real-mode 64k data at 0x00000100 */
15745+ GDT_ENTRY_INIT(0, 0, 0), /* Null descriptor */
15746+ GDT_ENTRY_INIT(0x9b, 0, 0xffff), /* 16-bit real-mode 64k code at 0x00000000 */
15747+ GDT_ENTRY_INIT(0x93, 0x100, 0xffff) /* 16-bit real-mode 64k data at 0x00000100 */
15748 };
15749
15750 static const struct desc_ptr
15751@@ -346,7 +346,7 @@ static const unsigned char jump_to_bios
15752 * specified by the code and length parameters.
15753 * We assume that length will aways be less that 100!
15754 */
15755-void machine_real_restart(const unsigned char *code, int length)
15756+__noreturn void machine_real_restart(const unsigned char *code, unsigned int length)
15757 {
15758 local_irq_disable();
15759
15760@@ -366,8 +366,8 @@ void machine_real_restart(const unsigned
15761 /* Remap the kernel at virtual address zero, as well as offset zero
15762 from the kernel segment. This assumes the kernel segment starts at
15763 virtual address PAGE_OFFSET. */
15764- memcpy(swapper_pg_dir, swapper_pg_dir + KERNEL_PGD_BOUNDARY,
15765- sizeof(swapper_pg_dir [0]) * KERNEL_PGD_PTRS);
15766+ clone_pgd_range(swapper_pg_dir, swapper_pg_dir + KERNEL_PGD_BOUNDARY,
15767+ min_t(unsigned long, KERNEL_PGD_PTRS, KERNEL_PGD_BOUNDARY));
15768
15769 /*
15770 * Use `swapper_pg_dir' as our page directory.
15771@@ -379,16 +379,15 @@ void machine_real_restart(const unsigned
15772 boot)". This seems like a fairly standard thing that gets set by
15773 REBOOT.COM programs, and the previous reset routine did this
15774 too. */
15775- *((unsigned short *)0x472) = reboot_mode;
15776+ *(unsigned short *)(__va(0x472)) = reboot_mode;
15777
15778 /* For the switch to real mode, copy some code to low memory. It has
15779 to be in the first 64k because it is running in 16-bit mode, and it
15780 has to have the same physical and virtual address, because it turns
15781 off paging. Copy it near the end of the first page, out of the way
15782 of BIOS variables. */
15783- memcpy((void *)(0x1000 - sizeof(real_mode_switch) - 100),
15784- real_mode_switch, sizeof (real_mode_switch));
15785- memcpy((void *)(0x1000 - 100), code, length);
15786+ memcpy(__va(0x1000 - sizeof (real_mode_switch) - 100), real_mode_switch, sizeof (real_mode_switch));
15787+ memcpy(__va(0x1000 - 100), code, length);
15788
15789 /* Set up the IDT for real mode. */
15790 load_idt(&real_mode_idt);
15791@@ -416,6 +415,7 @@ void machine_real_restart(const unsigned
15792 __asm__ __volatile__ ("ljmp $0x0008,%0"
15793 :
15794 : "i" ((void *)(0x1000 - sizeof (real_mode_switch) - 100)));
15795+ do { } while (1);
15796 }
15797 #ifdef CONFIG_APM_MODULE
15798 EXPORT_SYMBOL(machine_real_restart);
15799@@ -536,7 +536,7 @@ void __attribute__((weak)) mach_reboot_f
15800 {
15801 }
15802
15803-static void native_machine_emergency_restart(void)
15804+__noreturn static void native_machine_emergency_restart(void)
15805 {
15806 int i;
15807
15808@@ -651,13 +651,13 @@ void native_machine_shutdown(void)
15809 #endif
15810 }
15811
15812-static void __machine_emergency_restart(int emergency)
15813+static __noreturn void __machine_emergency_restart(int emergency)
15814 {
15815 reboot_emergency = emergency;
15816 machine_ops.emergency_restart();
15817 }
15818
15819-static void native_machine_restart(char *__unused)
15820+static __noreturn void native_machine_restart(char *__unused)
15821 {
15822 printk("machine restart\n");
15823
15824@@ -666,7 +666,7 @@ static void native_machine_restart(char
15825 __machine_emergency_restart(0);
15826 }
15827
15828-static void native_machine_halt(void)
15829+static __noreturn void native_machine_halt(void)
15830 {
15831 /* stop other cpus and apics */
15832 machine_shutdown();
15833@@ -677,7 +677,7 @@ static void native_machine_halt(void)
15834 stop_this_cpu(NULL);
15835 }
15836
15837-static void native_machine_power_off(void)
15838+__noreturn static void native_machine_power_off(void)
15839 {
15840 if (pm_power_off) {
15841 if (!reboot_force)
15842@@ -686,6 +686,7 @@ static void native_machine_power_off(voi
15843 }
15844 /* a fallback in case there is no PM info available */
15845 tboot_shutdown(TB_SHUTDOWN_HALT);
15846+ do { } while (1);
15847 }
15848
15849 struct machine_ops machine_ops = {
15850diff -urNp linux-2.6.32.41/arch/x86/kernel/setup.c linux-2.6.32.41/arch/x86/kernel/setup.c
15851--- linux-2.6.32.41/arch/x86/kernel/setup.c 2011-04-17 17:00:52.000000000 -0400
15852+++ linux-2.6.32.41/arch/x86/kernel/setup.c 2011-04-17 17:03:05.000000000 -0400
15853@@ -783,14 +783,14 @@ void __init setup_arch(char **cmdline_p)
15854
15855 if (!boot_params.hdr.root_flags)
15856 root_mountflags &= ~MS_RDONLY;
15857- init_mm.start_code = (unsigned long) _text;
15858- init_mm.end_code = (unsigned long) _etext;
15859+ init_mm.start_code = ktla_ktva((unsigned long) _text);
15860+ init_mm.end_code = ktla_ktva((unsigned long) _etext);
15861 init_mm.end_data = (unsigned long) _edata;
15862 init_mm.brk = _brk_end;
15863
15864- code_resource.start = virt_to_phys(_text);
15865- code_resource.end = virt_to_phys(_etext)-1;
15866- data_resource.start = virt_to_phys(_etext);
15867+ code_resource.start = virt_to_phys(ktla_ktva(_text));
15868+ code_resource.end = virt_to_phys(ktla_ktva(_etext))-1;
15869+ data_resource.start = virt_to_phys(_sdata);
15870 data_resource.end = virt_to_phys(_edata)-1;
15871 bss_resource.start = virt_to_phys(&__bss_start);
15872 bss_resource.end = virt_to_phys(&__bss_stop)-1;
15873diff -urNp linux-2.6.32.41/arch/x86/kernel/setup_percpu.c linux-2.6.32.41/arch/x86/kernel/setup_percpu.c
15874--- linux-2.6.32.41/arch/x86/kernel/setup_percpu.c 2011-03-27 14:31:47.000000000 -0400
15875+++ linux-2.6.32.41/arch/x86/kernel/setup_percpu.c 2011-06-04 20:36:29.000000000 -0400
15876@@ -25,19 +25,17 @@
15877 # define DBG(x...)
15878 #endif
15879
15880-DEFINE_PER_CPU(int, cpu_number);
15881+#ifdef CONFIG_SMP
15882+DEFINE_PER_CPU(unsigned int, cpu_number);
15883 EXPORT_PER_CPU_SYMBOL(cpu_number);
15884+#endif
15885
15886-#ifdef CONFIG_X86_64
15887 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
15888-#else
15889-#define BOOT_PERCPU_OFFSET 0
15890-#endif
15891
15892 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
15893 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
15894
15895-unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
15896+unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
15897 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
15898 };
15899 EXPORT_SYMBOL(__per_cpu_offset);
15900@@ -159,10 +157,10 @@ static inline void setup_percpu_segment(
15901 {
15902 #ifdef CONFIG_X86_32
15903 struct desc_struct gdt;
15904+ unsigned long base = per_cpu_offset(cpu);
15905
15906- pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
15907- 0x2 | DESCTYPE_S, 0x8);
15908- gdt.s = 1;
15909+ pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
15910+ 0x83 | DESCTYPE_S, 0xC);
15911 write_gdt_entry(get_cpu_gdt_table(cpu),
15912 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
15913 #endif
15914@@ -212,6 +210,11 @@ void __init setup_per_cpu_areas(void)
15915 /* alrighty, percpu areas up and running */
15916 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
15917 for_each_possible_cpu(cpu) {
15918+#ifdef CONFIG_CC_STACKPROTECTOR
15919+#ifdef CONFIG_X86_32
15920+ unsigned long canary = per_cpu(stack_canary.canary, cpu);
15921+#endif
15922+#endif
15923 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
15924 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
15925 per_cpu(cpu_number, cpu) = cpu;
15926@@ -239,6 +242,12 @@ void __init setup_per_cpu_areas(void)
15927 early_per_cpu_map(x86_cpu_to_node_map, cpu);
15928 #endif
15929 #endif
15930+#ifdef CONFIG_CC_STACKPROTECTOR
15931+#ifdef CONFIG_X86_32
15932+ if (!cpu)
15933+ per_cpu(stack_canary.canary, cpu) = canary;
15934+#endif
15935+#endif
15936 /*
15937 * Up to this point, the boot CPU has been using .data.init
15938 * area. Reload any changed state for the boot CPU.
15939diff -urNp linux-2.6.32.41/arch/x86/kernel/signal.c linux-2.6.32.41/arch/x86/kernel/signal.c
15940--- linux-2.6.32.41/arch/x86/kernel/signal.c 2011-03-27 14:31:47.000000000 -0400
15941+++ linux-2.6.32.41/arch/x86/kernel/signal.c 2011-05-22 23:02:03.000000000 -0400
15942@@ -197,7 +197,7 @@ static unsigned long align_sigframe(unsi
15943 * Align the stack pointer according to the i386 ABI,
15944 * i.e. so that on function entry ((sp + 4) & 15) == 0.
15945 */
15946- sp = ((sp + 4) & -16ul) - 4;
15947+ sp = ((sp - 12) & -16ul) - 4;
15948 #else /* !CONFIG_X86_32 */
15949 sp = round_down(sp, 16) - 8;
15950 #endif
15951@@ -248,11 +248,11 @@ get_sigframe(struct k_sigaction *ka, str
15952 * Return an always-bogus address instead so we will die with SIGSEGV.
15953 */
15954 if (onsigstack && !likely(on_sig_stack(sp)))
15955- return (void __user *)-1L;
15956+ return (__force void __user *)-1L;
15957
15958 /* save i387 state */
15959 if (used_math() && save_i387_xstate(*fpstate) < 0)
15960- return (void __user *)-1L;
15961+ return (__force void __user *)-1L;
15962
15963 return (void __user *)sp;
15964 }
15965@@ -307,9 +307,9 @@ __setup_frame(int sig, struct k_sigactio
15966 }
15967
15968 if (current->mm->context.vdso)
15969- restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
15970+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
15971 else
15972- restorer = &frame->retcode;
15973+ restorer = (void __user *)&frame->retcode;
15974 if (ka->sa.sa_flags & SA_RESTORER)
15975 restorer = ka->sa.sa_restorer;
15976
15977@@ -323,7 +323,7 @@ __setup_frame(int sig, struct k_sigactio
15978 * reasons and because gdb uses it as a signature to notice
15979 * signal handler stack frames.
15980 */
15981- err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
15982+ err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
15983
15984 if (err)
15985 return -EFAULT;
15986@@ -377,7 +377,10 @@ static int __setup_rt_frame(int sig, str
15987 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
15988
15989 /* Set up to return from userspace. */
15990- restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
15991+ if (current->mm->context.vdso)
15992+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
15993+ else
15994+ restorer = (void __user *)&frame->retcode;
15995 if (ka->sa.sa_flags & SA_RESTORER)
15996 restorer = ka->sa.sa_restorer;
15997 put_user_ex(restorer, &frame->pretcode);
15998@@ -389,7 +392,7 @@ static int __setup_rt_frame(int sig, str
15999 * reasons and because gdb uses it as a signature to notice
16000 * signal handler stack frames.
16001 */
16002- put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
16003+ put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
16004 } put_user_catch(err);
16005
16006 if (err)
16007@@ -782,6 +785,8 @@ static void do_signal(struct pt_regs *re
16008 int signr;
16009 sigset_t *oldset;
16010
16011+ pax_track_stack();
16012+
16013 /*
16014 * We want the common case to go fast, which is why we may in certain
16015 * cases get here from kernel mode. Just return without doing anything
16016@@ -789,7 +794,7 @@ static void do_signal(struct pt_regs *re
16017 * X86_32: vm86 regs switched out by assembly code before reaching
16018 * here, so testing against kernel CS suffices.
16019 */
16020- if (!user_mode(regs))
16021+ if (!user_mode_novm(regs))
16022 return;
16023
16024 if (current_thread_info()->status & TS_RESTORE_SIGMASK)
16025diff -urNp linux-2.6.32.41/arch/x86/kernel/smpboot.c linux-2.6.32.41/arch/x86/kernel/smpboot.c
16026--- linux-2.6.32.41/arch/x86/kernel/smpboot.c 2011-03-27 14:31:47.000000000 -0400
16027+++ linux-2.6.32.41/arch/x86/kernel/smpboot.c 2011-05-11 18:25:15.000000000 -0400
16028@@ -94,14 +94,14 @@ static DEFINE_PER_CPU(struct task_struct
16029 */
16030 static DEFINE_MUTEX(x86_cpu_hotplug_driver_mutex);
16031
16032-void cpu_hotplug_driver_lock()
16033+void cpu_hotplug_driver_lock(void)
16034 {
16035- mutex_lock(&x86_cpu_hotplug_driver_mutex);
16036+ mutex_lock(&x86_cpu_hotplug_driver_mutex);
16037 }
16038
16039-void cpu_hotplug_driver_unlock()
16040+void cpu_hotplug_driver_unlock(void)
16041 {
16042- mutex_unlock(&x86_cpu_hotplug_driver_mutex);
16043+ mutex_unlock(&x86_cpu_hotplug_driver_mutex);
16044 }
16045
16046 ssize_t arch_cpu_probe(const char *buf, size_t count) { return -1; }
16047@@ -743,6 +743,7 @@ static int __cpuinit do_boot_cpu(int api
16048 set_idle_for_cpu(cpu, c_idle.idle);
16049 do_rest:
16050 per_cpu(current_task, cpu) = c_idle.idle;
16051+ per_cpu(current_tinfo, cpu) = &c_idle.idle->tinfo;
16052 #ifdef CONFIG_X86_32
16053 /* Stack for startup_32 can be just as for start_secondary onwards */
16054 irq_ctx_init(cpu);
16055@@ -750,11 +751,13 @@ do_rest:
16056 #else
16057 clear_tsk_thread_flag(c_idle.idle, TIF_FORK);
16058 initial_gs = per_cpu_offset(cpu);
16059- per_cpu(kernel_stack, cpu) =
16060- (unsigned long)task_stack_page(c_idle.idle) -
16061- KERNEL_STACK_OFFSET + THREAD_SIZE;
16062+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(c_idle.idle) - 16 + THREAD_SIZE;
16063 #endif
16064+
16065+ pax_open_kernel();
16066 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
16067+ pax_close_kernel();
16068+
16069 initial_code = (unsigned long)start_secondary;
16070 stack_start.sp = (void *) c_idle.idle->thread.sp;
16071
16072@@ -891,6 +894,12 @@ int __cpuinit native_cpu_up(unsigned int
16073
16074 per_cpu(cpu_state, cpu) = CPU_UP_PREPARE;
16075
16076+#ifdef CONFIG_PAX_PER_CPU_PGD
16077+ clone_pgd_range(get_cpu_pgd(cpu) + KERNEL_PGD_BOUNDARY,
16078+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
16079+ KERNEL_PGD_PTRS);
16080+#endif
16081+
16082 err = do_boot_cpu(apicid, cpu);
16083
16084 if (err) {
16085diff -urNp linux-2.6.32.41/arch/x86/kernel/step.c linux-2.6.32.41/arch/x86/kernel/step.c
16086--- linux-2.6.32.41/arch/x86/kernel/step.c 2011-03-27 14:31:47.000000000 -0400
16087+++ linux-2.6.32.41/arch/x86/kernel/step.c 2011-04-17 15:56:46.000000000 -0400
16088@@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struc
16089 struct desc_struct *desc;
16090 unsigned long base;
16091
16092- seg &= ~7UL;
16093+ seg >>= 3;
16094
16095 mutex_lock(&child->mm->context.lock);
16096- if (unlikely((seg >> 3) >= child->mm->context.size))
16097+ if (unlikely(seg >= child->mm->context.size))
16098 addr = -1L; /* bogus selector, access would fault */
16099 else {
16100 desc = child->mm->context.ldt + seg;
16101@@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struc
16102 addr += base;
16103 }
16104 mutex_unlock(&child->mm->context.lock);
16105- }
16106+ } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
16107+ addr = ktla_ktva(addr);
16108
16109 return addr;
16110 }
16111@@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct t
16112 unsigned char opcode[15];
16113 unsigned long addr = convert_ip_to_linear(child, regs);
16114
16115+ if (addr == -EINVAL)
16116+ return 0;
16117+
16118 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
16119 for (i = 0; i < copied; i++) {
16120 switch (opcode[i]) {
16121@@ -74,7 +78,7 @@ static int is_setting_trap_flag(struct t
16122
16123 #ifdef CONFIG_X86_64
16124 case 0x40 ... 0x4f:
16125- if (regs->cs != __USER_CS)
16126+ if ((regs->cs & 0xffff) != __USER_CS)
16127 /* 32-bit mode: register increment */
16128 return 0;
16129 /* 64-bit mode: REX prefix */
16130diff -urNp linux-2.6.32.41/arch/x86/kernel/syscall_table_32.S linux-2.6.32.41/arch/x86/kernel/syscall_table_32.S
16131--- linux-2.6.32.41/arch/x86/kernel/syscall_table_32.S 2011-03-27 14:31:47.000000000 -0400
16132+++ linux-2.6.32.41/arch/x86/kernel/syscall_table_32.S 2011-04-17 15:56:46.000000000 -0400
16133@@ -1,3 +1,4 @@
16134+.section .rodata,"a",@progbits
16135 ENTRY(sys_call_table)
16136 .long sys_restart_syscall /* 0 - old "setup()" system call, used for restarting */
16137 .long sys_exit
16138diff -urNp linux-2.6.32.41/arch/x86/kernel/sys_i386_32.c linux-2.6.32.41/arch/x86/kernel/sys_i386_32.c
16139--- linux-2.6.32.41/arch/x86/kernel/sys_i386_32.c 2011-03-27 14:31:47.000000000 -0400
16140+++ linux-2.6.32.41/arch/x86/kernel/sys_i386_32.c 2011-04-17 15:56:46.000000000 -0400
16141@@ -24,6 +24,21 @@
16142
16143 #include <asm/syscalls.h>
16144
16145+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
16146+{
16147+ unsigned long pax_task_size = TASK_SIZE;
16148+
16149+#ifdef CONFIG_PAX_SEGMEXEC
16150+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
16151+ pax_task_size = SEGMEXEC_TASK_SIZE;
16152+#endif
16153+
16154+ if (len > pax_task_size || addr > pax_task_size - len)
16155+ return -EINVAL;
16156+
16157+ return 0;
16158+}
16159+
16160 /*
16161 * Perform the select(nd, in, out, ex, tv) and mmap() system
16162 * calls. Linux/i386 didn't use to be able to handle more than
16163@@ -58,6 +73,212 @@ out:
16164 return err;
16165 }
16166
16167+unsigned long
16168+arch_get_unmapped_area(struct file *filp, unsigned long addr,
16169+ unsigned long len, unsigned long pgoff, unsigned long flags)
16170+{
16171+ struct mm_struct *mm = current->mm;
16172+ struct vm_area_struct *vma;
16173+ unsigned long start_addr, pax_task_size = TASK_SIZE;
16174+
16175+#ifdef CONFIG_PAX_SEGMEXEC
16176+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
16177+ pax_task_size = SEGMEXEC_TASK_SIZE;
16178+#endif
16179+
16180+ pax_task_size -= PAGE_SIZE;
16181+
16182+ if (len > pax_task_size)
16183+ return -ENOMEM;
16184+
16185+ if (flags & MAP_FIXED)
16186+ return addr;
16187+
16188+#ifdef CONFIG_PAX_RANDMMAP
16189+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
16190+#endif
16191+
16192+ if (addr) {
16193+ addr = PAGE_ALIGN(addr);
16194+ if (pax_task_size - len >= addr) {
16195+ vma = find_vma(mm, addr);
16196+ if (check_heap_stack_gap(vma, addr, len))
16197+ return addr;
16198+ }
16199+ }
16200+ if (len > mm->cached_hole_size) {
16201+ start_addr = addr = mm->free_area_cache;
16202+ } else {
16203+ start_addr = addr = mm->mmap_base;
16204+ mm->cached_hole_size = 0;
16205+ }
16206+
16207+#ifdef CONFIG_PAX_PAGEEXEC
16208+ if (!nx_enabled && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE) && start_addr >= mm->mmap_base) {
16209+ start_addr = 0x00110000UL;
16210+
16211+#ifdef CONFIG_PAX_RANDMMAP
16212+ if (mm->pax_flags & MF_PAX_RANDMMAP)
16213+ start_addr += mm->delta_mmap & 0x03FFF000UL;
16214+#endif
16215+
16216+ if (mm->start_brk <= start_addr && start_addr < mm->mmap_base)
16217+ start_addr = addr = mm->mmap_base;
16218+ else
16219+ addr = start_addr;
16220+ }
16221+#endif
16222+
16223+full_search:
16224+ for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
16225+ /* At this point: (!vma || addr < vma->vm_end). */
16226+ if (pax_task_size - len < addr) {
16227+ /*
16228+ * Start a new search - just in case we missed
16229+ * some holes.
16230+ */
16231+ if (start_addr != mm->mmap_base) {
16232+ start_addr = addr = mm->mmap_base;
16233+ mm->cached_hole_size = 0;
16234+ goto full_search;
16235+ }
16236+ return -ENOMEM;
16237+ }
16238+ if (check_heap_stack_gap(vma, addr, len))
16239+ break;
16240+ if (addr + mm->cached_hole_size < vma->vm_start)
16241+ mm->cached_hole_size = vma->vm_start - addr;
16242+ addr = vma->vm_end;
16243+ if (mm->start_brk <= addr && addr < mm->mmap_base) {
16244+ start_addr = addr = mm->mmap_base;
16245+ mm->cached_hole_size = 0;
16246+ goto full_search;
16247+ }
16248+ }
16249+
16250+ /*
16251+ * Remember the place where we stopped the search:
16252+ */
16253+ mm->free_area_cache = addr + len;
16254+ return addr;
16255+}
16256+
16257+unsigned long
16258+arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
16259+ const unsigned long len, const unsigned long pgoff,
16260+ const unsigned long flags)
16261+{
16262+ struct vm_area_struct *vma;
16263+ struct mm_struct *mm = current->mm;
16264+ unsigned long base = mm->mmap_base, addr = addr0, pax_task_size = TASK_SIZE;
16265+
16266+#ifdef CONFIG_PAX_SEGMEXEC
16267+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
16268+ pax_task_size = SEGMEXEC_TASK_SIZE;
16269+#endif
16270+
16271+ pax_task_size -= PAGE_SIZE;
16272+
16273+ /* requested length too big for entire address space */
16274+ if (len > pax_task_size)
16275+ return -ENOMEM;
16276+
16277+ if (flags & MAP_FIXED)
16278+ return addr;
16279+
16280+#ifdef CONFIG_PAX_PAGEEXEC
16281+ if (!nx_enabled && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
16282+ goto bottomup;
16283+#endif
16284+
16285+#ifdef CONFIG_PAX_RANDMMAP
16286+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
16287+#endif
16288+
16289+ /* requesting a specific address */
16290+ if (addr) {
16291+ addr = PAGE_ALIGN(addr);
16292+ if (pax_task_size - len >= addr) {
16293+ vma = find_vma(mm, addr);
16294+ if (check_heap_stack_gap(vma, addr, len))
16295+ return addr;
16296+ }
16297+ }
16298+
16299+ /* check if free_area_cache is useful for us */
16300+ if (len <= mm->cached_hole_size) {
16301+ mm->cached_hole_size = 0;
16302+ mm->free_area_cache = mm->mmap_base;
16303+ }
16304+
16305+ /* either no address requested or can't fit in requested address hole */
16306+ addr = mm->free_area_cache;
16307+
16308+ /* make sure it can fit in the remaining address space */
16309+ if (addr > len) {
16310+ vma = find_vma(mm, addr-len);
16311+ if (check_heap_stack_gap(vma, addr - len, len))
16312+ /* remember the address as a hint for next time */
16313+ return (mm->free_area_cache = addr-len);
16314+ }
16315+
16316+ if (mm->mmap_base < len)
16317+ goto bottomup;
16318+
16319+ addr = mm->mmap_base-len;
16320+
16321+ do {
16322+ /*
16323+ * Lookup failure means no vma is above this address,
16324+ * else if new region fits below vma->vm_start,
16325+ * return with success:
16326+ */
16327+ vma = find_vma(mm, addr);
16328+ if (check_heap_stack_gap(vma, addr, len))
16329+ /* remember the address as a hint for next time */
16330+ return (mm->free_area_cache = addr);
16331+
16332+ /* remember the largest hole we saw so far */
16333+ if (addr + mm->cached_hole_size < vma->vm_start)
16334+ mm->cached_hole_size = vma->vm_start - addr;
16335+
16336+ /* try just below the current vma->vm_start */
16337+ addr = skip_heap_stack_gap(vma, len);
16338+ } while (!IS_ERR_VALUE(addr));
16339+
16340+bottomup:
16341+ /*
16342+ * A failed mmap() very likely causes application failure,
16343+ * so fall back to the bottom-up function here. This scenario
16344+ * can happen with large stack limits and large mmap()
16345+ * allocations.
16346+ */
16347+
16348+#ifdef CONFIG_PAX_SEGMEXEC
16349+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
16350+ mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
16351+ else
16352+#endif
16353+
16354+ mm->mmap_base = TASK_UNMAPPED_BASE;
16355+
16356+#ifdef CONFIG_PAX_RANDMMAP
16357+ if (mm->pax_flags & MF_PAX_RANDMMAP)
16358+ mm->mmap_base += mm->delta_mmap;
16359+#endif
16360+
16361+ mm->free_area_cache = mm->mmap_base;
16362+ mm->cached_hole_size = ~0UL;
16363+ addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
16364+ /*
16365+ * Restore the topdown base:
16366+ */
16367+ mm->mmap_base = base;
16368+ mm->free_area_cache = base;
16369+ mm->cached_hole_size = ~0UL;
16370+
16371+ return addr;
16372+}
16373
16374 struct sel_arg_struct {
16375 unsigned long n;
16376@@ -93,7 +314,7 @@ asmlinkage int sys_ipc(uint call, int fi
16377 return sys_semtimedop(first, (struct sembuf __user *)ptr, second, NULL);
16378 case SEMTIMEDOP:
16379 return sys_semtimedop(first, (struct sembuf __user *)ptr, second,
16380- (const struct timespec __user *)fifth);
16381+ (__force const struct timespec __user *)fifth);
16382
16383 case SEMGET:
16384 return sys_semget(first, second, third);
16385@@ -140,7 +361,7 @@ asmlinkage int sys_ipc(uint call, int fi
16386 ret = do_shmat(first, (char __user *) ptr, second, &raddr);
16387 if (ret)
16388 return ret;
16389- return put_user(raddr, (ulong __user *) third);
16390+ return put_user(raddr, (__force ulong __user *) third);
16391 }
16392 case 1: /* iBCS2 emulator entry point */
16393 if (!segment_eq(get_fs(), get_ds()))
16394@@ -207,17 +428,3 @@ asmlinkage int sys_olduname(struct oldol
16395
16396 return error;
16397 }
16398-
16399-
16400-/*
16401- * Do a system call from kernel instead of calling sys_execve so we
16402- * end up with proper pt_regs.
16403- */
16404-int kernel_execve(const char *filename, char *const argv[], char *const envp[])
16405-{
16406- long __res;
16407- asm volatile ("push %%ebx ; movl %2,%%ebx ; int $0x80 ; pop %%ebx"
16408- : "=a" (__res)
16409- : "0" (__NR_execve), "ri" (filename), "c" (argv), "d" (envp) : "memory");
16410- return __res;
16411-}
16412diff -urNp linux-2.6.32.41/arch/x86/kernel/sys_x86_64.c linux-2.6.32.41/arch/x86/kernel/sys_x86_64.c
16413--- linux-2.6.32.41/arch/x86/kernel/sys_x86_64.c 2011-03-27 14:31:47.000000000 -0400
16414+++ linux-2.6.32.41/arch/x86/kernel/sys_x86_64.c 2011-04-17 15:56:46.000000000 -0400
16415@@ -32,8 +32,8 @@ out:
16416 return error;
16417 }
16418
16419-static void find_start_end(unsigned long flags, unsigned long *begin,
16420- unsigned long *end)
16421+static void find_start_end(struct mm_struct *mm, unsigned long flags,
16422+ unsigned long *begin, unsigned long *end)
16423 {
16424 if (!test_thread_flag(TIF_IA32) && (flags & MAP_32BIT)) {
16425 unsigned long new_begin;
16426@@ -52,7 +52,7 @@ static void find_start_end(unsigned long
16427 *begin = new_begin;
16428 }
16429 } else {
16430- *begin = TASK_UNMAPPED_BASE;
16431+ *begin = mm->mmap_base;
16432 *end = TASK_SIZE;
16433 }
16434 }
16435@@ -69,16 +69,19 @@ arch_get_unmapped_area(struct file *filp
16436 if (flags & MAP_FIXED)
16437 return addr;
16438
16439- find_start_end(flags, &begin, &end);
16440+ find_start_end(mm, flags, &begin, &end);
16441
16442 if (len > end)
16443 return -ENOMEM;
16444
16445+#ifdef CONFIG_PAX_RANDMMAP
16446+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
16447+#endif
16448+
16449 if (addr) {
16450 addr = PAGE_ALIGN(addr);
16451 vma = find_vma(mm, addr);
16452- if (end - len >= addr &&
16453- (!vma || addr + len <= vma->vm_start))
16454+ if (end - len >= addr && check_heap_stack_gap(vma, addr, len))
16455 return addr;
16456 }
16457 if (((flags & MAP_32BIT) || test_thread_flag(TIF_IA32))
16458@@ -106,7 +109,7 @@ full_search:
16459 }
16460 return -ENOMEM;
16461 }
16462- if (!vma || addr + len <= vma->vm_start) {
16463+ if (check_heap_stack_gap(vma, addr, len)) {
16464 /*
16465 * Remember the place where we stopped the search:
16466 */
16467@@ -128,7 +131,7 @@ arch_get_unmapped_area_topdown(struct fi
16468 {
16469 struct vm_area_struct *vma;
16470 struct mm_struct *mm = current->mm;
16471- unsigned long addr = addr0;
16472+ unsigned long base = mm->mmap_base, addr = addr0;
16473
16474 /* requested length too big for entire address space */
16475 if (len > TASK_SIZE)
16476@@ -141,13 +144,18 @@ arch_get_unmapped_area_topdown(struct fi
16477 if (!test_thread_flag(TIF_IA32) && (flags & MAP_32BIT))
16478 goto bottomup;
16479
16480+#ifdef CONFIG_PAX_RANDMMAP
16481+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
16482+#endif
16483+
16484 /* requesting a specific address */
16485 if (addr) {
16486 addr = PAGE_ALIGN(addr);
16487- vma = find_vma(mm, addr);
16488- if (TASK_SIZE - len >= addr &&
16489- (!vma || addr + len <= vma->vm_start))
16490- return addr;
16491+ if (TASK_SIZE - len >= addr) {
16492+ vma = find_vma(mm, addr);
16493+ if (check_heap_stack_gap(vma, addr, len))
16494+ return addr;
16495+ }
16496 }
16497
16498 /* check if free_area_cache is useful for us */
16499@@ -162,7 +170,7 @@ arch_get_unmapped_area_topdown(struct fi
16500 /* make sure it can fit in the remaining address space */
16501 if (addr > len) {
16502 vma = find_vma(mm, addr-len);
16503- if (!vma || addr <= vma->vm_start)
16504+ if (check_heap_stack_gap(vma, addr - len, len))
16505 /* remember the address as a hint for next time */
16506 return mm->free_area_cache = addr-len;
16507 }
16508@@ -179,7 +187,7 @@ arch_get_unmapped_area_topdown(struct fi
16509 * return with success:
16510 */
16511 vma = find_vma(mm, addr);
16512- if (!vma || addr+len <= vma->vm_start)
16513+ if (check_heap_stack_gap(vma, addr, len))
16514 /* remember the address as a hint for next time */
16515 return mm->free_area_cache = addr;
16516
16517@@ -188,8 +196,8 @@ arch_get_unmapped_area_topdown(struct fi
16518 mm->cached_hole_size = vma->vm_start - addr;
16519
16520 /* try just below the current vma->vm_start */
16521- addr = vma->vm_start-len;
16522- } while (len < vma->vm_start);
16523+ addr = skip_heap_stack_gap(vma, len);
16524+ } while (!IS_ERR_VALUE(addr));
16525
16526 bottomup:
16527 /*
16528@@ -198,13 +206,21 @@ bottomup:
16529 * can happen with large stack limits and large mmap()
16530 * allocations.
16531 */
16532+ mm->mmap_base = TASK_UNMAPPED_BASE;
16533+
16534+#ifdef CONFIG_PAX_RANDMMAP
16535+ if (mm->pax_flags & MF_PAX_RANDMMAP)
16536+ mm->mmap_base += mm->delta_mmap;
16537+#endif
16538+
16539+ mm->free_area_cache = mm->mmap_base;
16540 mm->cached_hole_size = ~0UL;
16541- mm->free_area_cache = TASK_UNMAPPED_BASE;
16542 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
16543 /*
16544 * Restore the topdown base:
16545 */
16546- mm->free_area_cache = mm->mmap_base;
16547+ mm->mmap_base = base;
16548+ mm->free_area_cache = base;
16549 mm->cached_hole_size = ~0UL;
16550
16551 return addr;
16552diff -urNp linux-2.6.32.41/arch/x86/kernel/tboot.c linux-2.6.32.41/arch/x86/kernel/tboot.c
16553--- linux-2.6.32.41/arch/x86/kernel/tboot.c 2011-03-27 14:31:47.000000000 -0400
16554+++ linux-2.6.32.41/arch/x86/kernel/tboot.c 2011-05-22 23:02:03.000000000 -0400
16555@@ -216,7 +216,7 @@ static int tboot_setup_sleep(void)
16556
16557 void tboot_shutdown(u32 shutdown_type)
16558 {
16559- void (*shutdown)(void);
16560+ void (* __noreturn shutdown)(void);
16561
16562 if (!tboot_enabled())
16563 return;
16564@@ -238,7 +238,7 @@ void tboot_shutdown(u32 shutdown_type)
16565
16566 switch_to_tboot_pt();
16567
16568- shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
16569+ shutdown = (void *)tboot->shutdown_entry;
16570 shutdown();
16571
16572 /* should not reach here */
16573@@ -295,7 +295,7 @@ void tboot_sleep(u8 sleep_state, u32 pm1
16574 tboot_shutdown(acpi_shutdown_map[sleep_state]);
16575 }
16576
16577-static atomic_t ap_wfs_count;
16578+static atomic_unchecked_t ap_wfs_count;
16579
16580 static int tboot_wait_for_aps(int num_aps)
16581 {
16582@@ -319,9 +319,9 @@ static int __cpuinit tboot_cpu_callback(
16583 {
16584 switch (action) {
16585 case CPU_DYING:
16586- atomic_inc(&ap_wfs_count);
16587+ atomic_inc_unchecked(&ap_wfs_count);
16588 if (num_online_cpus() == 1)
16589- if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
16590+ if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
16591 return NOTIFY_BAD;
16592 break;
16593 }
16594@@ -340,7 +340,7 @@ static __init int tboot_late_init(void)
16595
16596 tboot_create_trampoline();
16597
16598- atomic_set(&ap_wfs_count, 0);
16599+ atomic_set_unchecked(&ap_wfs_count, 0);
16600 register_hotcpu_notifier(&tboot_cpu_notifier);
16601 return 0;
16602 }
16603diff -urNp linux-2.6.32.41/arch/x86/kernel/time.c linux-2.6.32.41/arch/x86/kernel/time.c
16604--- linux-2.6.32.41/arch/x86/kernel/time.c 2011-03-27 14:31:47.000000000 -0400
16605+++ linux-2.6.32.41/arch/x86/kernel/time.c 2011-04-17 15:56:46.000000000 -0400
16606@@ -26,17 +26,13 @@
16607 int timer_ack;
16608 #endif
16609
16610-#ifdef CONFIG_X86_64
16611-volatile unsigned long __jiffies __section_jiffies = INITIAL_JIFFIES;
16612-#endif
16613-
16614 unsigned long profile_pc(struct pt_regs *regs)
16615 {
16616 unsigned long pc = instruction_pointer(regs);
16617
16618- if (!user_mode_vm(regs) && in_lock_functions(pc)) {
16619+ if (!user_mode(regs) && in_lock_functions(pc)) {
16620 #ifdef CONFIG_FRAME_POINTER
16621- return *(unsigned long *)(regs->bp + sizeof(long));
16622+ return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
16623 #else
16624 unsigned long *sp =
16625 (unsigned long *)kernel_stack_pointer(regs);
16626@@ -45,11 +41,17 @@ unsigned long profile_pc(struct pt_regs
16627 * or above a saved flags. Eflags has bits 22-31 zero,
16628 * kernel addresses don't.
16629 */
16630+
16631+#ifdef CONFIG_PAX_KERNEXEC
16632+ return ktla_ktva(sp[0]);
16633+#else
16634 if (sp[0] >> 22)
16635 return sp[0];
16636 if (sp[1] >> 22)
16637 return sp[1];
16638 #endif
16639+
16640+#endif
16641 }
16642 return pc;
16643 }
16644diff -urNp linux-2.6.32.41/arch/x86/kernel/tls.c linux-2.6.32.41/arch/x86/kernel/tls.c
16645--- linux-2.6.32.41/arch/x86/kernel/tls.c 2011-03-27 14:31:47.000000000 -0400
16646+++ linux-2.6.32.41/arch/x86/kernel/tls.c 2011-04-17 15:56:46.000000000 -0400
16647@@ -85,6 +85,11 @@ int do_set_thread_area(struct task_struc
16648 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
16649 return -EINVAL;
16650
16651+#ifdef CONFIG_PAX_SEGMEXEC
16652+ if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
16653+ return -EINVAL;
16654+#endif
16655+
16656 set_tls_desc(p, idx, &info, 1);
16657
16658 return 0;
16659diff -urNp linux-2.6.32.41/arch/x86/kernel/trampoline_32.S linux-2.6.32.41/arch/x86/kernel/trampoline_32.S
16660--- linux-2.6.32.41/arch/x86/kernel/trampoline_32.S 2011-03-27 14:31:47.000000000 -0400
16661+++ linux-2.6.32.41/arch/x86/kernel/trampoline_32.S 2011-04-17 15:56:46.000000000 -0400
16662@@ -32,6 +32,12 @@
16663 #include <asm/segment.h>
16664 #include <asm/page_types.h>
16665
16666+#ifdef CONFIG_PAX_KERNEXEC
16667+#define ta(X) (X)
16668+#else
16669+#define ta(X) ((X) - __PAGE_OFFSET)
16670+#endif
16671+
16672 /* We can free up trampoline after bootup if cpu hotplug is not supported. */
16673 __CPUINITRODATA
16674 .code16
16675@@ -60,7 +66,7 @@ r_base = .
16676 inc %ax # protected mode (PE) bit
16677 lmsw %ax # into protected mode
16678 # flush prefetch and jump to startup_32_smp in arch/i386/kernel/head.S
16679- ljmpl $__BOOT_CS, $(startup_32_smp-__PAGE_OFFSET)
16680+ ljmpl $__BOOT_CS, $ta(startup_32_smp)
16681
16682 # These need to be in the same 64K segment as the above;
16683 # hence we don't use the boot_gdt_descr defined in head.S
16684diff -urNp linux-2.6.32.41/arch/x86/kernel/trampoline_64.S linux-2.6.32.41/arch/x86/kernel/trampoline_64.S
16685--- linux-2.6.32.41/arch/x86/kernel/trampoline_64.S 2011-03-27 14:31:47.000000000 -0400
16686+++ linux-2.6.32.41/arch/x86/kernel/trampoline_64.S 2011-04-17 15:56:46.000000000 -0400
16687@@ -91,7 +91,7 @@ startup_32:
16688 movl $__KERNEL_DS, %eax # Initialize the %ds segment register
16689 movl %eax, %ds
16690
16691- movl $X86_CR4_PAE, %eax
16692+ movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
16693 movl %eax, %cr4 # Enable PAE mode
16694
16695 # Setup trampoline 4 level pagetables
16696@@ -138,7 +138,7 @@ tidt:
16697 # so the kernel can live anywhere
16698 .balign 4
16699 tgdt:
16700- .short tgdt_end - tgdt # gdt limit
16701+ .short tgdt_end - tgdt - 1 # gdt limit
16702 .long tgdt - r_base
16703 .short 0
16704 .quad 0x00cf9b000000ffff # __KERNEL32_CS
16705diff -urNp linux-2.6.32.41/arch/x86/kernel/traps.c linux-2.6.32.41/arch/x86/kernel/traps.c
16706--- linux-2.6.32.41/arch/x86/kernel/traps.c 2011-03-27 14:31:47.000000000 -0400
16707+++ linux-2.6.32.41/arch/x86/kernel/traps.c 2011-04-17 15:56:46.000000000 -0400
16708@@ -69,12 +69,6 @@ asmlinkage int system_call(void);
16709
16710 /* Do we ignore FPU interrupts ? */
16711 char ignore_fpu_irq;
16712-
16713-/*
16714- * The IDT has to be page-aligned to simplify the Pentium
16715- * F0 0F bug workaround.
16716- */
16717-gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
16718 #endif
16719
16720 DECLARE_BITMAP(used_vectors, NR_VECTORS);
16721@@ -112,19 +106,19 @@ static inline void preempt_conditional_c
16722 static inline void
16723 die_if_kernel(const char *str, struct pt_regs *regs, long err)
16724 {
16725- if (!user_mode_vm(regs))
16726+ if (!user_mode(regs))
16727 die(str, regs, err);
16728 }
16729 #endif
16730
16731 static void __kprobes
16732-do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
16733+do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
16734 long error_code, siginfo_t *info)
16735 {
16736 struct task_struct *tsk = current;
16737
16738 #ifdef CONFIG_X86_32
16739- if (regs->flags & X86_VM_MASK) {
16740+ if (v8086_mode(regs)) {
16741 /*
16742 * traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
16743 * On nmi (interrupt 2), do_trap should not be called.
16744@@ -135,7 +129,7 @@ do_trap(int trapnr, int signr, char *str
16745 }
16746 #endif
16747
16748- if (!user_mode(regs))
16749+ if (!user_mode_novm(regs))
16750 goto kernel_trap;
16751
16752 #ifdef CONFIG_X86_32
16753@@ -158,7 +152,7 @@ trap_signal:
16754 printk_ratelimit()) {
16755 printk(KERN_INFO
16756 "%s[%d] trap %s ip:%lx sp:%lx error:%lx",
16757- tsk->comm, tsk->pid, str,
16758+ tsk->comm, task_pid_nr(tsk), str,
16759 regs->ip, regs->sp, error_code);
16760 print_vma_addr(" in ", regs->ip);
16761 printk("\n");
16762@@ -175,8 +169,20 @@ kernel_trap:
16763 if (!fixup_exception(regs)) {
16764 tsk->thread.error_code = error_code;
16765 tsk->thread.trap_no = trapnr;
16766+
16767+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
16768+ if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
16769+ str = "PAX: suspicious stack segment fault";
16770+#endif
16771+
16772 die(str, regs, error_code);
16773 }
16774+
16775+#ifdef CONFIG_PAX_REFCOUNT
16776+ if (trapnr == 4)
16777+ pax_report_refcount_overflow(regs);
16778+#endif
16779+
16780 return;
16781
16782 #ifdef CONFIG_X86_32
16783@@ -265,14 +271,30 @@ do_general_protection(struct pt_regs *re
16784 conditional_sti(regs);
16785
16786 #ifdef CONFIG_X86_32
16787- if (regs->flags & X86_VM_MASK)
16788+ if (v8086_mode(regs))
16789 goto gp_in_vm86;
16790 #endif
16791
16792 tsk = current;
16793- if (!user_mode(regs))
16794+ if (!user_mode_novm(regs))
16795 goto gp_in_kernel;
16796
16797+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
16798+ if (!nx_enabled && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
16799+ struct mm_struct *mm = tsk->mm;
16800+ unsigned long limit;
16801+
16802+ down_write(&mm->mmap_sem);
16803+ limit = mm->context.user_cs_limit;
16804+ if (limit < TASK_SIZE) {
16805+ track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
16806+ up_write(&mm->mmap_sem);
16807+ return;
16808+ }
16809+ up_write(&mm->mmap_sem);
16810+ }
16811+#endif
16812+
16813 tsk->thread.error_code = error_code;
16814 tsk->thread.trap_no = 13;
16815
16816@@ -305,6 +327,13 @@ gp_in_kernel:
16817 if (notify_die(DIE_GPF, "general protection fault", regs,
16818 error_code, 13, SIGSEGV) == NOTIFY_STOP)
16819 return;
16820+
16821+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
16822+ if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
16823+ die("PAX: suspicious general protection fault", regs, error_code);
16824+ else
16825+#endif
16826+
16827 die("general protection fault", regs, error_code);
16828 }
16829
16830@@ -558,7 +587,7 @@ dotraplinkage void __kprobes do_debug(st
16831 }
16832
16833 #ifdef CONFIG_X86_32
16834- if (regs->flags & X86_VM_MASK)
16835+ if (v8086_mode(regs))
16836 goto debug_vm86;
16837 #endif
16838
16839@@ -570,7 +599,7 @@ dotraplinkage void __kprobes do_debug(st
16840 * kernel space (but re-enable TF when returning to user mode).
16841 */
16842 if (condition & DR_STEP) {
16843- if (!user_mode(regs))
16844+ if (!user_mode_novm(regs))
16845 goto clear_TF_reenable;
16846 }
16847
16848@@ -757,7 +786,7 @@ do_simd_coprocessor_error(struct pt_regs
16849 * Handle strange cache flush from user space exception
16850 * in all other cases. This is undocumented behaviour.
16851 */
16852- if (regs->flags & X86_VM_MASK) {
16853+ if (v8086_mode(regs)) {
16854 handle_vm86_fault((struct kernel_vm86_regs *)regs, error_code);
16855 return;
16856 }
16857@@ -798,7 +827,7 @@ asmlinkage void __attribute__((weak)) sm
16858 void __math_state_restore(void)
16859 {
16860 struct thread_info *thread = current_thread_info();
16861- struct task_struct *tsk = thread->task;
16862+ struct task_struct *tsk = current;
16863
16864 /*
16865 * Paranoid restore. send a SIGSEGV if we fail to restore the state.
16866@@ -825,8 +854,7 @@ void __math_state_restore(void)
16867 */
16868 asmlinkage void math_state_restore(void)
16869 {
16870- struct thread_info *thread = current_thread_info();
16871- struct task_struct *tsk = thread->task;
16872+ struct task_struct *tsk = current;
16873
16874 if (!tsk_used_math(tsk)) {
16875 local_irq_enable();
16876diff -urNp linux-2.6.32.41/arch/x86/kernel/vm86_32.c linux-2.6.32.41/arch/x86/kernel/vm86_32.c
16877--- linux-2.6.32.41/arch/x86/kernel/vm86_32.c 2011-03-27 14:31:47.000000000 -0400
16878+++ linux-2.6.32.41/arch/x86/kernel/vm86_32.c 2011-04-17 15:56:46.000000000 -0400
16879@@ -41,6 +41,7 @@
16880 #include <linux/ptrace.h>
16881 #include <linux/audit.h>
16882 #include <linux/stddef.h>
16883+#include <linux/grsecurity.h>
16884
16885 #include <asm/uaccess.h>
16886 #include <asm/io.h>
16887@@ -148,7 +149,7 @@ struct pt_regs *save_v86_state(struct ke
16888 do_exit(SIGSEGV);
16889 }
16890
16891- tss = &per_cpu(init_tss, get_cpu());
16892+ tss = init_tss + get_cpu();
16893 current->thread.sp0 = current->thread.saved_sp0;
16894 current->thread.sysenter_cs = __KERNEL_CS;
16895 load_sp0(tss, &current->thread);
16896@@ -208,6 +209,13 @@ int sys_vm86old(struct pt_regs *regs)
16897 struct task_struct *tsk;
16898 int tmp, ret = -EPERM;
16899
16900+#ifdef CONFIG_GRKERNSEC_VM86
16901+ if (!capable(CAP_SYS_RAWIO)) {
16902+ gr_handle_vm86();
16903+ goto out;
16904+ }
16905+#endif
16906+
16907 tsk = current;
16908 if (tsk->thread.saved_sp0)
16909 goto out;
16910@@ -238,6 +246,14 @@ int sys_vm86(struct pt_regs *regs)
16911 int tmp, ret;
16912 struct vm86plus_struct __user *v86;
16913
16914+#ifdef CONFIG_GRKERNSEC_VM86
16915+ if (!capable(CAP_SYS_RAWIO)) {
16916+ gr_handle_vm86();
16917+ ret = -EPERM;
16918+ goto out;
16919+ }
16920+#endif
16921+
16922 tsk = current;
16923 switch (regs->bx) {
16924 case VM86_REQUEST_IRQ:
16925@@ -324,7 +340,7 @@ static void do_sys_vm86(struct kernel_vm
16926 tsk->thread.saved_fs = info->regs32->fs;
16927 tsk->thread.saved_gs = get_user_gs(info->regs32);
16928
16929- tss = &per_cpu(init_tss, get_cpu());
16930+ tss = init_tss + get_cpu();
16931 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
16932 if (cpu_has_sep)
16933 tsk->thread.sysenter_cs = 0;
16934@@ -529,7 +545,7 @@ static void do_int(struct kernel_vm86_re
16935 goto cannot_handle;
16936 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
16937 goto cannot_handle;
16938- intr_ptr = (unsigned long __user *) (i << 2);
16939+ intr_ptr = (__force unsigned long __user *) (i << 2);
16940 if (get_user(segoffs, intr_ptr))
16941 goto cannot_handle;
16942 if ((segoffs >> 16) == BIOSSEG)
16943diff -urNp linux-2.6.32.41/arch/x86/kernel/vmi_32.c linux-2.6.32.41/arch/x86/kernel/vmi_32.c
16944--- linux-2.6.32.41/arch/x86/kernel/vmi_32.c 2011-03-27 14:31:47.000000000 -0400
16945+++ linux-2.6.32.41/arch/x86/kernel/vmi_32.c 2011-04-17 15:56:46.000000000 -0400
16946@@ -44,12 +44,17 @@ typedef u32 __attribute__((regparm(1)))
16947 typedef u64 __attribute__((regparm(2))) (VROMLONGFUNC)(int);
16948
16949 #define call_vrom_func(rom,func) \
16950- (((VROMFUNC *)(rom->func))())
16951+ (((VROMFUNC *)(ktva_ktla(rom.func)))())
16952
16953 #define call_vrom_long_func(rom,func,arg) \
16954- (((VROMLONGFUNC *)(rom->func)) (arg))
16955+({\
16956+ u64 __reloc = ((VROMLONGFUNC *)(ktva_ktla(rom.func))) (arg);\
16957+ struct vmi_relocation_info *const __rel = (struct vmi_relocation_info *)&__reloc;\
16958+ __rel->eip = (unsigned char *)ktva_ktla((unsigned long)__rel->eip);\
16959+ __reloc;\
16960+})
16961
16962-static struct vrom_header *vmi_rom;
16963+static struct vrom_header vmi_rom __attribute((__section__(".vmi.rom"), __aligned__(PAGE_SIZE)));
16964 static int disable_pge;
16965 static int disable_pse;
16966 static int disable_sep;
16967@@ -76,10 +81,10 @@ static struct {
16968 void (*set_initial_ap_state)(int, int);
16969 void (*halt)(void);
16970 void (*set_lazy_mode)(int mode);
16971-} vmi_ops;
16972+} vmi_ops __read_only;
16973
16974 /* Cached VMI operations */
16975-struct vmi_timer_ops vmi_timer_ops;
16976+struct vmi_timer_ops vmi_timer_ops __read_only;
16977
16978 /*
16979 * VMI patching routines.
16980@@ -94,7 +99,7 @@ struct vmi_timer_ops vmi_timer_ops;
16981 static inline void patch_offset(void *insnbuf,
16982 unsigned long ip, unsigned long dest)
16983 {
16984- *(unsigned long *)(insnbuf+1) = dest-ip-5;
16985+ *(unsigned long *)(insnbuf+1) = dest-ip-5;
16986 }
16987
16988 static unsigned patch_internal(int call, unsigned len, void *insnbuf,
16989@@ -102,6 +107,7 @@ static unsigned patch_internal(int call,
16990 {
16991 u64 reloc;
16992 struct vmi_relocation_info *const rel = (struct vmi_relocation_info *)&reloc;
16993+
16994 reloc = call_vrom_long_func(vmi_rom, get_reloc, call);
16995 switch(rel->type) {
16996 case VMI_RELOCATION_CALL_REL:
16997@@ -404,13 +410,13 @@ static void vmi_set_pud(pud_t *pudp, pud
16998
16999 static void vmi_pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
17000 {
17001- const pte_t pte = { .pte = 0 };
17002+ const pte_t pte = __pte(0ULL);
17003 vmi_ops.set_pte(pte, ptep, vmi_flags_addr(mm, addr, VMI_PAGE_PT, 0));
17004 }
17005
17006 static void vmi_pmd_clear(pmd_t *pmd)
17007 {
17008- const pte_t pte = { .pte = 0 };
17009+ const pte_t pte = __pte(0ULL);
17010 vmi_ops.set_pte(pte, (pte_t *)pmd, VMI_PAGE_PD);
17011 }
17012 #endif
17013@@ -438,10 +444,10 @@ vmi_startup_ipi_hook(int phys_apicid, un
17014 ap.ss = __KERNEL_DS;
17015 ap.esp = (unsigned long) start_esp;
17016
17017- ap.ds = __USER_DS;
17018- ap.es = __USER_DS;
17019+ ap.ds = __KERNEL_DS;
17020+ ap.es = __KERNEL_DS;
17021 ap.fs = __KERNEL_PERCPU;
17022- ap.gs = __KERNEL_STACK_CANARY;
17023+ savesegment(gs, ap.gs);
17024
17025 ap.eflags = 0;
17026
17027@@ -486,6 +492,18 @@ static void vmi_leave_lazy_mmu(void)
17028 paravirt_leave_lazy_mmu();
17029 }
17030
17031+#ifdef CONFIG_PAX_KERNEXEC
17032+static unsigned long vmi_pax_open_kernel(void)
17033+{
17034+ return 0;
17035+}
17036+
17037+static unsigned long vmi_pax_close_kernel(void)
17038+{
17039+ return 0;
17040+}
17041+#endif
17042+
17043 static inline int __init check_vmi_rom(struct vrom_header *rom)
17044 {
17045 struct pci_header *pci;
17046@@ -498,6 +516,10 @@ static inline int __init check_vmi_rom(s
17047 return 0;
17048 if (rom->vrom_signature != VMI_SIGNATURE)
17049 return 0;
17050+ if (rom->rom_length * 512 > sizeof(*rom)) {
17051+ printk(KERN_WARNING "PAX: VMI: ROM size too big: %x\n", rom->rom_length * 512);
17052+ return 0;
17053+ }
17054 if (rom->api_version_maj != VMI_API_REV_MAJOR ||
17055 rom->api_version_min+1 < VMI_API_REV_MINOR+1) {
17056 printk(KERN_WARNING "VMI: Found mismatched rom version %d.%d\n",
17057@@ -562,7 +584,7 @@ static inline int __init probe_vmi_rom(v
17058 struct vrom_header *romstart;
17059 romstart = (struct vrom_header *)isa_bus_to_virt(base);
17060 if (check_vmi_rom(romstart)) {
17061- vmi_rom = romstart;
17062+ vmi_rom = *romstart;
17063 return 1;
17064 }
17065 }
17066@@ -836,6 +858,11 @@ static inline int __init activate_vmi(vo
17067
17068 para_fill(pv_irq_ops.safe_halt, Halt);
17069
17070+#ifdef CONFIG_PAX_KERNEXEC
17071+ pv_mmu_ops.pax_open_kernel = vmi_pax_open_kernel;
17072+ pv_mmu_ops.pax_close_kernel = vmi_pax_close_kernel;
17073+#endif
17074+
17075 /*
17076 * Alternative instruction rewriting doesn't happen soon enough
17077 * to convert VMI_IRET to a call instead of a jump; so we have
17078@@ -853,16 +880,16 @@ static inline int __init activate_vmi(vo
17079
17080 void __init vmi_init(void)
17081 {
17082- if (!vmi_rom)
17083+ if (!vmi_rom.rom_signature)
17084 probe_vmi_rom();
17085 else
17086- check_vmi_rom(vmi_rom);
17087+ check_vmi_rom(&vmi_rom);
17088
17089 /* In case probing for or validating the ROM failed, basil */
17090- if (!vmi_rom)
17091+ if (!vmi_rom.rom_signature)
17092 return;
17093
17094- reserve_top_address(-vmi_rom->virtual_top);
17095+ reserve_top_address(-vmi_rom.virtual_top);
17096
17097 #ifdef CONFIG_X86_IO_APIC
17098 /* This is virtual hardware; timer routing is wired correctly */
17099@@ -874,7 +901,7 @@ void __init vmi_activate(void)
17100 {
17101 unsigned long flags;
17102
17103- if (!vmi_rom)
17104+ if (!vmi_rom.rom_signature)
17105 return;
17106
17107 local_irq_save(flags);
17108diff -urNp linux-2.6.32.41/arch/x86/kernel/vmlinux.lds.S linux-2.6.32.41/arch/x86/kernel/vmlinux.lds.S
17109--- linux-2.6.32.41/arch/x86/kernel/vmlinux.lds.S 2011-03-27 14:31:47.000000000 -0400
17110+++ linux-2.6.32.41/arch/x86/kernel/vmlinux.lds.S 2011-04-17 15:56:46.000000000 -0400
17111@@ -26,6 +26,13 @@
17112 #include <asm/page_types.h>
17113 #include <asm/cache.h>
17114 #include <asm/boot.h>
17115+#include <asm/segment.h>
17116+
17117+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
17118+#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
17119+#else
17120+#define __KERNEL_TEXT_OFFSET 0
17121+#endif
17122
17123 #undef i386 /* in case the preprocessor is a 32bit one */
17124
17125@@ -34,40 +41,53 @@ OUTPUT_FORMAT(CONFIG_OUTPUT_FORMAT, CONF
17126 #ifdef CONFIG_X86_32
17127 OUTPUT_ARCH(i386)
17128 ENTRY(phys_startup_32)
17129-jiffies = jiffies_64;
17130 #else
17131 OUTPUT_ARCH(i386:x86-64)
17132 ENTRY(phys_startup_64)
17133-jiffies_64 = jiffies;
17134 #endif
17135
17136 PHDRS {
17137 text PT_LOAD FLAGS(5); /* R_E */
17138- data PT_LOAD FLAGS(7); /* RWE */
17139+#ifdef CONFIG_X86_32
17140+ module PT_LOAD FLAGS(5); /* R_E */
17141+#endif
17142+#ifdef CONFIG_XEN
17143+ rodata PT_LOAD FLAGS(5); /* R_E */
17144+#else
17145+ rodata PT_LOAD FLAGS(4); /* R__ */
17146+#endif
17147+ data PT_LOAD FLAGS(6); /* RW_ */
17148 #ifdef CONFIG_X86_64
17149 user PT_LOAD FLAGS(5); /* R_E */
17150+#endif
17151+ init.begin PT_LOAD FLAGS(6); /* RW_ */
17152 #ifdef CONFIG_SMP
17153 percpu PT_LOAD FLAGS(6); /* RW_ */
17154 #endif
17155+ text.init PT_LOAD FLAGS(5); /* R_E */
17156+ text.exit PT_LOAD FLAGS(5); /* R_E */
17157 init PT_LOAD FLAGS(7); /* RWE */
17158-#endif
17159 note PT_NOTE FLAGS(0); /* ___ */
17160 }
17161
17162 SECTIONS
17163 {
17164 #ifdef CONFIG_X86_32
17165- . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
17166- phys_startup_32 = startup_32 - LOAD_OFFSET;
17167+ . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
17168 #else
17169- . = __START_KERNEL;
17170- phys_startup_64 = startup_64 - LOAD_OFFSET;
17171+ . = __START_KERNEL;
17172 #endif
17173
17174 /* Text and read-only data */
17175- .text : AT(ADDR(.text) - LOAD_OFFSET) {
17176- _text = .;
17177+ .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
17178 /* bootstrapping code */
17179+#ifdef CONFIG_X86_32
17180+ phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
17181+#else
17182+ phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
17183+#endif
17184+ __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
17185+ _text = .;
17186 HEAD_TEXT
17187 #ifdef CONFIG_X86_32
17188 . = ALIGN(PAGE_SIZE);
17189@@ -82,28 +102,71 @@ SECTIONS
17190 IRQENTRY_TEXT
17191 *(.fixup)
17192 *(.gnu.warning)
17193- /* End of text section */
17194- _etext = .;
17195 } :text = 0x9090
17196
17197- NOTES :text :note
17198+ . += __KERNEL_TEXT_OFFSET;
17199+
17200+#ifdef CONFIG_X86_32
17201+ . = ALIGN(PAGE_SIZE);
17202+ .vmi.rom : AT(ADDR(.vmi.rom) - LOAD_OFFSET) {
17203+ *(.vmi.rom)
17204+ } :module
17205+
17206+ . = ALIGN(PAGE_SIZE);
17207+ .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
17208+
17209+#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_MODULES)
17210+ MODULES_EXEC_VADDR = .;
17211+ BYTE(0)
17212+ . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
17213+ . = ALIGN(HPAGE_SIZE);
17214+ MODULES_EXEC_END = . - 1;
17215+#endif
17216+
17217+ } :module
17218+#endif
17219
17220- EXCEPTION_TABLE(16) :text = 0x9090
17221+ .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
17222+ /* End of text section */
17223+ _etext = . - __KERNEL_TEXT_OFFSET;
17224+ }
17225+
17226+#ifdef CONFIG_X86_32
17227+ . = ALIGN(PAGE_SIZE);
17228+ .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
17229+ *(.idt)
17230+ . = ALIGN(PAGE_SIZE);
17231+ *(.empty_zero_page)
17232+ *(.swapper_pg_fixmap)
17233+ *(.swapper_pg_pmd)
17234+ *(.swapper_pg_dir)
17235+ *(.trampoline_pg_dir)
17236+ } :rodata
17237+#endif
17238+
17239+ . = ALIGN(PAGE_SIZE);
17240+ NOTES :rodata :note
17241+
17242+ EXCEPTION_TABLE(16) :rodata
17243
17244 RO_DATA(PAGE_SIZE)
17245
17246 /* Data */
17247 .data : AT(ADDR(.data) - LOAD_OFFSET) {
17248+
17249+#ifdef CONFIG_PAX_KERNEXEC
17250+ . = ALIGN(HPAGE_SIZE);
17251+#else
17252+ . = ALIGN(PAGE_SIZE);
17253+#endif
17254+
17255 /* Start of data section */
17256 _sdata = .;
17257
17258 /* init_task */
17259 INIT_TASK_DATA(THREAD_SIZE)
17260
17261-#ifdef CONFIG_X86_32
17262- /* 32 bit has nosave before _edata */
17263 NOSAVE_DATA
17264-#endif
17265
17266 PAGE_ALIGNED_DATA(PAGE_SIZE)
17267
17268@@ -112,6 +175,8 @@ SECTIONS
17269 DATA_DATA
17270 CONSTRUCTORS
17271
17272+ jiffies = jiffies_64;
17273+
17274 /* rarely changed data like cpu maps */
17275 READ_MOSTLY_DATA(CONFIG_X86_INTERNODE_CACHE_BYTES)
17276
17277@@ -166,12 +231,6 @@ SECTIONS
17278 }
17279 vgetcpu_mode = VVIRT(.vgetcpu_mode);
17280
17281- . = ALIGN(CONFIG_X86_L1_CACHE_BYTES);
17282- .jiffies : AT(VLOAD(.jiffies)) {
17283- *(.jiffies)
17284- }
17285- jiffies = VVIRT(.jiffies);
17286-
17287 .vsyscall_3 ADDR(.vsyscall_0) + 3072: AT(VLOAD(.vsyscall_3)) {
17288 *(.vsyscall_3)
17289 }
17290@@ -187,12 +246,19 @@ SECTIONS
17291 #endif /* CONFIG_X86_64 */
17292
17293 /* Init code and data - will be freed after init */
17294- . = ALIGN(PAGE_SIZE);
17295 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
17296+ BYTE(0)
17297+
17298+#ifdef CONFIG_PAX_KERNEXEC
17299+ . = ALIGN(HPAGE_SIZE);
17300+#else
17301+ . = ALIGN(PAGE_SIZE);
17302+#endif
17303+
17304 __init_begin = .; /* paired with __init_end */
17305- }
17306+ } :init.begin
17307
17308-#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
17309+#ifdef CONFIG_SMP
17310 /*
17311 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
17312 * output PHDR, so the next output section - .init.text - should
17313@@ -201,12 +267,27 @@ SECTIONS
17314 PERCPU_VADDR(0, :percpu)
17315 #endif
17316
17317- INIT_TEXT_SECTION(PAGE_SIZE)
17318-#ifdef CONFIG_X86_64
17319- :init
17320-#endif
17321+ . = ALIGN(PAGE_SIZE);
17322+ init_begin = .;
17323+ .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
17324+ VMLINUX_SYMBOL(_sinittext) = .;
17325+ INIT_TEXT
17326+ VMLINUX_SYMBOL(_einittext) = .;
17327+ . = ALIGN(PAGE_SIZE);
17328+ } :text.init
17329
17330- INIT_DATA_SECTION(16)
17331+ /*
17332+ * .exit.text is discard at runtime, not link time, to deal with
17333+ * references from .altinstructions and .eh_frame
17334+ */
17335+ .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
17336+ EXIT_TEXT
17337+ . = ALIGN(16);
17338+ } :text.exit
17339+ . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
17340+
17341+ . = ALIGN(PAGE_SIZE);
17342+ INIT_DATA_SECTION(16) :init
17343
17344 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
17345 __x86_cpu_dev_start = .;
17346@@ -232,19 +313,11 @@ SECTIONS
17347 *(.altinstr_replacement)
17348 }
17349
17350- /*
17351- * .exit.text is discard at runtime, not link time, to deal with
17352- * references from .altinstructions and .eh_frame
17353- */
17354- .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
17355- EXIT_TEXT
17356- }
17357-
17358 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
17359 EXIT_DATA
17360 }
17361
17362-#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
17363+#ifndef CONFIG_SMP
17364 PERCPU(PAGE_SIZE)
17365 #endif
17366
17367@@ -267,12 +340,6 @@ SECTIONS
17368 . = ALIGN(PAGE_SIZE);
17369 }
17370
17371-#ifdef CONFIG_X86_64
17372- .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
17373- NOSAVE_DATA
17374- }
17375-#endif
17376-
17377 /* BSS */
17378 . = ALIGN(PAGE_SIZE);
17379 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
17380@@ -288,6 +355,7 @@ SECTIONS
17381 __brk_base = .;
17382 . += 64 * 1024; /* 64k alignment slop space */
17383 *(.brk_reservation) /* areas brk users have reserved */
17384+ . = ALIGN(HPAGE_SIZE);
17385 __brk_limit = .;
17386 }
17387
17388@@ -316,13 +384,12 @@ SECTIONS
17389 * for the boot processor.
17390 */
17391 #define INIT_PER_CPU(x) init_per_cpu__##x = per_cpu__##x + __per_cpu_load
17392-INIT_PER_CPU(gdt_page);
17393 INIT_PER_CPU(irq_stack_union);
17394
17395 /*
17396 * Build-time check on the image size:
17397 */
17398-. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
17399+. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
17400 "kernel image bigger than KERNEL_IMAGE_SIZE");
17401
17402 #ifdef CONFIG_SMP
17403diff -urNp linux-2.6.32.41/arch/x86/kernel/vsyscall_64.c linux-2.6.32.41/arch/x86/kernel/vsyscall_64.c
17404--- linux-2.6.32.41/arch/x86/kernel/vsyscall_64.c 2011-03-27 14:31:47.000000000 -0400
17405+++ linux-2.6.32.41/arch/x86/kernel/vsyscall_64.c 2011-04-23 12:56:10.000000000 -0400
17406@@ -80,6 +80,7 @@ void update_vsyscall(struct timespec *wa
17407
17408 write_seqlock_irqsave(&vsyscall_gtod_data.lock, flags);
17409 /* copy vsyscall data */
17410+ strlcpy(vsyscall_gtod_data.clock.name, clock->name, sizeof vsyscall_gtod_data.clock.name);
17411 vsyscall_gtod_data.clock.vread = clock->vread;
17412 vsyscall_gtod_data.clock.cycle_last = clock->cycle_last;
17413 vsyscall_gtod_data.clock.mask = clock->mask;
17414@@ -203,7 +204,7 @@ vgetcpu(unsigned *cpu, unsigned *node, s
17415 We do this here because otherwise user space would do it on
17416 its own in a likely inferior way (no access to jiffies).
17417 If you don't like it pass NULL. */
17418- if (tcache && tcache->blob[0] == (j = __jiffies)) {
17419+ if (tcache && tcache->blob[0] == (j = jiffies)) {
17420 p = tcache->blob[1];
17421 } else if (__vgetcpu_mode == VGETCPU_RDTSCP) {
17422 /* Load per CPU data from RDTSCP */
17423diff -urNp linux-2.6.32.41/arch/x86/kernel/x8664_ksyms_64.c linux-2.6.32.41/arch/x86/kernel/x8664_ksyms_64.c
17424--- linux-2.6.32.41/arch/x86/kernel/x8664_ksyms_64.c 2011-03-27 14:31:47.000000000 -0400
17425+++ linux-2.6.32.41/arch/x86/kernel/x8664_ksyms_64.c 2011-04-17 15:56:46.000000000 -0400
17426@@ -30,8 +30,6 @@ EXPORT_SYMBOL(__put_user_8);
17427
17428 EXPORT_SYMBOL(copy_user_generic);
17429 EXPORT_SYMBOL(__copy_user_nocache);
17430-EXPORT_SYMBOL(copy_from_user);
17431-EXPORT_SYMBOL(copy_to_user);
17432 EXPORT_SYMBOL(__copy_from_user_inatomic);
17433
17434 EXPORT_SYMBOL(copy_page);
17435diff -urNp linux-2.6.32.41/arch/x86/kernel/xsave.c linux-2.6.32.41/arch/x86/kernel/xsave.c
17436--- linux-2.6.32.41/arch/x86/kernel/xsave.c 2011-03-27 14:31:47.000000000 -0400
17437+++ linux-2.6.32.41/arch/x86/kernel/xsave.c 2011-04-17 15:56:46.000000000 -0400
17438@@ -54,7 +54,7 @@ int check_for_xstate(struct i387_fxsave_
17439 fx_sw_user->xstate_size > fx_sw_user->extended_size)
17440 return -1;
17441
17442- err = __get_user(magic2, (__u32 *) (((void *)fpstate) +
17443+ err = __get_user(magic2, (__u32 __user *) (((void __user *)fpstate) +
17444 fx_sw_user->extended_size -
17445 FP_XSTATE_MAGIC2_SIZE));
17446 /*
17447@@ -196,7 +196,7 @@ fx_only:
17448 * the other extended state.
17449 */
17450 xrstor_state(init_xstate_buf, pcntxt_mask & ~XSTATE_FPSSE);
17451- return fxrstor_checking((__force struct i387_fxsave_struct *)buf);
17452+ return fxrstor_checking((struct i387_fxsave_struct __user *)buf);
17453 }
17454
17455 /*
17456@@ -228,7 +228,7 @@ int restore_i387_xstate(void __user *buf
17457 if (task_thread_info(tsk)->status & TS_XSAVE)
17458 err = restore_user_xstate(buf);
17459 else
17460- err = fxrstor_checking((__force struct i387_fxsave_struct *)
17461+ err = fxrstor_checking((struct i387_fxsave_struct __user *)
17462 buf);
17463 if (unlikely(err)) {
17464 /*
17465diff -urNp linux-2.6.32.41/arch/x86/kvm/emulate.c linux-2.6.32.41/arch/x86/kvm/emulate.c
17466--- linux-2.6.32.41/arch/x86/kvm/emulate.c 2011-03-27 14:31:47.000000000 -0400
17467+++ linux-2.6.32.41/arch/x86/kvm/emulate.c 2011-04-17 15:56:46.000000000 -0400
17468@@ -81,8 +81,8 @@
17469 #define Src2CL (1<<29)
17470 #define Src2ImmByte (2<<29)
17471 #define Src2One (3<<29)
17472-#define Src2Imm16 (4<<29)
17473-#define Src2Mask (7<<29)
17474+#define Src2Imm16 (4U<<29)
17475+#define Src2Mask (7U<<29)
17476
17477 enum {
17478 Group1_80, Group1_81, Group1_82, Group1_83,
17479@@ -411,6 +411,7 @@ static u32 group2_table[] = {
17480
17481 #define ____emulate_2op(_op, _src, _dst, _eflags, _x, _y, _suffix) \
17482 do { \
17483+ unsigned long _tmp; \
17484 __asm__ __volatile__ ( \
17485 _PRE_EFLAGS("0", "4", "2") \
17486 _op _suffix " %"_x"3,%1; " \
17487@@ -424,8 +425,6 @@ static u32 group2_table[] = {
17488 /* Raw emulation: instruction has two explicit operands. */
17489 #define __emulate_2op_nobyte(_op,_src,_dst,_eflags,_wx,_wy,_lx,_ly,_qx,_qy) \
17490 do { \
17491- unsigned long _tmp; \
17492- \
17493 switch ((_dst).bytes) { \
17494 case 2: \
17495 ____emulate_2op(_op,_src,_dst,_eflags,_wx,_wy,"w"); \
17496@@ -441,7 +440,6 @@ static u32 group2_table[] = {
17497
17498 #define __emulate_2op(_op,_src,_dst,_eflags,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy) \
17499 do { \
17500- unsigned long _tmp; \
17501 switch ((_dst).bytes) { \
17502 case 1: \
17503 ____emulate_2op(_op,_src,_dst,_eflags,_bx,_by,"b"); \
17504diff -urNp linux-2.6.32.41/arch/x86/kvm/lapic.c linux-2.6.32.41/arch/x86/kvm/lapic.c
17505--- linux-2.6.32.41/arch/x86/kvm/lapic.c 2011-03-27 14:31:47.000000000 -0400
17506+++ linux-2.6.32.41/arch/x86/kvm/lapic.c 2011-04-17 15:56:46.000000000 -0400
17507@@ -52,7 +52,7 @@
17508 #define APIC_BUS_CYCLE_NS 1
17509
17510 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
17511-#define apic_debug(fmt, arg...)
17512+#define apic_debug(fmt, arg...) do {} while (0)
17513
17514 #define APIC_LVT_NUM 6
17515 /* 14 is the version for Xeon and Pentium 8.4.8*/
17516diff -urNp linux-2.6.32.41/arch/x86/kvm/paging_tmpl.h linux-2.6.32.41/arch/x86/kvm/paging_tmpl.h
17517--- linux-2.6.32.41/arch/x86/kvm/paging_tmpl.h 2011-03-27 14:31:47.000000000 -0400
17518+++ linux-2.6.32.41/arch/x86/kvm/paging_tmpl.h 2011-05-16 21:46:57.000000000 -0400
17519@@ -416,6 +416,8 @@ static int FNAME(page_fault)(struct kvm_
17520 int level = PT_PAGE_TABLE_LEVEL;
17521 unsigned long mmu_seq;
17522
17523+ pax_track_stack();
17524+
17525 pgprintk("%s: addr %lx err %x\n", __func__, addr, error_code);
17526 kvm_mmu_audit(vcpu, "pre page fault");
17527
17528diff -urNp linux-2.6.32.41/arch/x86/kvm/svm.c linux-2.6.32.41/arch/x86/kvm/svm.c
17529--- linux-2.6.32.41/arch/x86/kvm/svm.c 2011-03-27 14:31:47.000000000 -0400
17530+++ linux-2.6.32.41/arch/x86/kvm/svm.c 2011-04-17 15:56:46.000000000 -0400
17531@@ -2483,9 +2483,12 @@ static int handle_exit(struct kvm_run *k
17532 static void reload_tss(struct kvm_vcpu *vcpu)
17533 {
17534 int cpu = raw_smp_processor_id();
17535-
17536 struct svm_cpu_data *svm_data = per_cpu(svm_data, cpu);
17537+
17538+ pax_open_kernel();
17539 svm_data->tss_desc->type = 9; /* available 32/64-bit TSS */
17540+ pax_close_kernel();
17541+
17542 load_TR_desc();
17543 }
17544
17545@@ -2946,7 +2949,7 @@ static bool svm_gb_page_enable(void)
17546 return true;
17547 }
17548
17549-static struct kvm_x86_ops svm_x86_ops = {
17550+static const struct kvm_x86_ops svm_x86_ops = {
17551 .cpu_has_kvm_support = has_svm,
17552 .disabled_by_bios = is_disabled,
17553 .hardware_setup = svm_hardware_setup,
17554diff -urNp linux-2.6.32.41/arch/x86/kvm/vmx.c linux-2.6.32.41/arch/x86/kvm/vmx.c
17555--- linux-2.6.32.41/arch/x86/kvm/vmx.c 2011-03-27 14:31:47.000000000 -0400
17556+++ linux-2.6.32.41/arch/x86/kvm/vmx.c 2011-05-04 17:56:20.000000000 -0400
17557@@ -570,7 +570,11 @@ static void reload_tss(void)
17558
17559 kvm_get_gdt(&gdt);
17560 descs = (void *)gdt.base;
17561+
17562+ pax_open_kernel();
17563 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
17564+ pax_close_kernel();
17565+
17566 load_TR_desc();
17567 }
17568
17569@@ -1409,8 +1413,11 @@ static __init int hardware_setup(void)
17570 if (!cpu_has_vmx_flexpriority())
17571 flexpriority_enabled = 0;
17572
17573- if (!cpu_has_vmx_tpr_shadow())
17574- kvm_x86_ops->update_cr8_intercept = NULL;
17575+ if (!cpu_has_vmx_tpr_shadow()) {
17576+ pax_open_kernel();
17577+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
17578+ pax_close_kernel();
17579+ }
17580
17581 if (enable_ept && !cpu_has_vmx_ept_2m_page())
17582 kvm_disable_largepages();
17583@@ -2361,7 +2368,7 @@ static int vmx_vcpu_setup(struct vcpu_vm
17584 vmcs_writel(HOST_IDTR_BASE, dt.base); /* 22.2.4 */
17585
17586 asm("mov $.Lkvm_vmx_return, %0" : "=r"(kvm_vmx_return));
17587- vmcs_writel(HOST_RIP, kvm_vmx_return); /* 22.2.5 */
17588+ vmcs_writel(HOST_RIP, ktla_ktva(kvm_vmx_return)); /* 22.2.5 */
17589 vmcs_write32(VM_EXIT_MSR_STORE_COUNT, 0);
17590 vmcs_write32(VM_EXIT_MSR_LOAD_COUNT, 0);
17591 vmcs_write32(VM_ENTRY_MSR_LOAD_COUNT, 0);
17592@@ -3717,6 +3724,12 @@ static void vmx_vcpu_run(struct kvm_vcpu
17593 "jmp .Lkvm_vmx_return \n\t"
17594 ".Llaunched: " __ex(ASM_VMX_VMRESUME) "\n\t"
17595 ".Lkvm_vmx_return: "
17596+
17597+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
17598+ "ljmp %[cs],$.Lkvm_vmx_return2\n\t"
17599+ ".Lkvm_vmx_return2: "
17600+#endif
17601+
17602 /* Save guest registers, load host registers, keep flags */
17603 "xchg %0, (%%"R"sp) \n\t"
17604 "mov %%"R"ax, %c[rax](%0) \n\t"
17605@@ -3763,8 +3776,13 @@ static void vmx_vcpu_run(struct kvm_vcpu
17606 [r15]"i"(offsetof(struct vcpu_vmx, vcpu.arch.regs[VCPU_REGS_R15])),
17607 #endif
17608 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2))
17609+
17610+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
17611+ ,[cs]"i"(__KERNEL_CS)
17612+#endif
17613+
17614 : "cc", "memory"
17615- , R"bx", R"di", R"si"
17616+ , R"ax", R"bx", R"di", R"si"
17617 #ifdef CONFIG_X86_64
17618 , "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15"
17619 #endif
17620@@ -3781,7 +3799,16 @@ static void vmx_vcpu_run(struct kvm_vcpu
17621 if (vmx->rmode.irq.pending)
17622 fixup_rmode_irq(vmx);
17623
17624- asm("mov %0, %%ds; mov %0, %%es" : : "r"(__USER_DS));
17625+ asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r"(__KERNEL_DS));
17626+
17627+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
17628+ loadsegment(fs, __KERNEL_PERCPU);
17629+#endif
17630+
17631+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
17632+ __set_fs(current_thread_info()->addr_limit);
17633+#endif
17634+
17635 vmx->launched = 1;
17636
17637 vmx_complete_interrupts(vmx);
17638@@ -3956,7 +3983,7 @@ static bool vmx_gb_page_enable(void)
17639 return false;
17640 }
17641
17642-static struct kvm_x86_ops vmx_x86_ops = {
17643+static const struct kvm_x86_ops vmx_x86_ops = {
17644 .cpu_has_kvm_support = cpu_has_kvm_support,
17645 .disabled_by_bios = vmx_disabled_by_bios,
17646 .hardware_setup = hardware_setup,
17647diff -urNp linux-2.6.32.41/arch/x86/kvm/x86.c linux-2.6.32.41/arch/x86/kvm/x86.c
17648--- linux-2.6.32.41/arch/x86/kvm/x86.c 2011-05-10 22:12:01.000000000 -0400
17649+++ linux-2.6.32.41/arch/x86/kvm/x86.c 2011-05-10 22:12:26.000000000 -0400
17650@@ -82,7 +82,7 @@ static void update_cr8_intercept(struct
17651 static int kvm_dev_ioctl_get_supported_cpuid(struct kvm_cpuid2 *cpuid,
17652 struct kvm_cpuid_entry2 __user *entries);
17653
17654-struct kvm_x86_ops *kvm_x86_ops;
17655+const struct kvm_x86_ops *kvm_x86_ops;
17656 EXPORT_SYMBOL_GPL(kvm_x86_ops);
17657
17658 int ignore_msrs = 0;
17659@@ -1430,15 +1430,20 @@ static int kvm_vcpu_ioctl_set_cpuid2(str
17660 struct kvm_cpuid2 *cpuid,
17661 struct kvm_cpuid_entry2 __user *entries)
17662 {
17663- int r;
17664+ int r, i;
17665
17666 r = -E2BIG;
17667 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
17668 goto out;
17669 r = -EFAULT;
17670- if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
17671- cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
17672+ if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
17673 goto out;
17674+ for (i = 0; i < cpuid->nent; ++i) {
17675+ struct kvm_cpuid_entry2 cpuid_entry;
17676+ if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
17677+ goto out;
17678+ vcpu->arch.cpuid_entries[i] = cpuid_entry;
17679+ }
17680 vcpu->arch.cpuid_nent = cpuid->nent;
17681 kvm_apic_set_version(vcpu);
17682 return 0;
17683@@ -1451,16 +1456,20 @@ static int kvm_vcpu_ioctl_get_cpuid2(str
17684 struct kvm_cpuid2 *cpuid,
17685 struct kvm_cpuid_entry2 __user *entries)
17686 {
17687- int r;
17688+ int r, i;
17689
17690 vcpu_load(vcpu);
17691 r = -E2BIG;
17692 if (cpuid->nent < vcpu->arch.cpuid_nent)
17693 goto out;
17694 r = -EFAULT;
17695- if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
17696- vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
17697+ if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
17698 goto out;
17699+ for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
17700+ struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
17701+ if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
17702+ goto out;
17703+ }
17704 return 0;
17705
17706 out:
17707@@ -1678,7 +1687,7 @@ static int kvm_vcpu_ioctl_set_lapic(stru
17708 static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
17709 struct kvm_interrupt *irq)
17710 {
17711- if (irq->irq < 0 || irq->irq >= 256)
17712+ if (irq->irq >= 256)
17713 return -EINVAL;
17714 if (irqchip_in_kernel(vcpu->kvm))
17715 return -ENXIO;
17716@@ -3260,10 +3269,10 @@ static struct notifier_block kvmclock_cp
17717 .notifier_call = kvmclock_cpufreq_notifier
17718 };
17719
17720-int kvm_arch_init(void *opaque)
17721+int kvm_arch_init(const void *opaque)
17722 {
17723 int r, cpu;
17724- struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
17725+ const struct kvm_x86_ops *ops = (const struct kvm_x86_ops *)opaque;
17726
17727 if (kvm_x86_ops) {
17728 printk(KERN_ERR "kvm: already loaded the other module\n");
17729diff -urNp linux-2.6.32.41/arch/x86/lib/atomic64_32.c linux-2.6.32.41/arch/x86/lib/atomic64_32.c
17730--- linux-2.6.32.41/arch/x86/lib/atomic64_32.c 2011-03-27 14:31:47.000000000 -0400
17731+++ linux-2.6.32.41/arch/x86/lib/atomic64_32.c 2011-05-04 17:56:28.000000000 -0400
17732@@ -25,6 +25,12 @@ u64 atomic64_cmpxchg(atomic64_t *ptr, u6
17733 }
17734 EXPORT_SYMBOL(atomic64_cmpxchg);
17735
17736+u64 atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, u64 old_val, u64 new_val)
17737+{
17738+ return cmpxchg8b(&ptr->counter, old_val, new_val);
17739+}
17740+EXPORT_SYMBOL(atomic64_cmpxchg_unchecked);
17741+
17742 /**
17743 * atomic64_xchg - xchg atomic64 variable
17744 * @ptr: pointer to type atomic64_t
17745@@ -56,6 +62,36 @@ u64 atomic64_xchg(atomic64_t *ptr, u64 n
17746 EXPORT_SYMBOL(atomic64_xchg);
17747
17748 /**
17749+ * atomic64_xchg_unchecked - xchg atomic64 variable
17750+ * @ptr: pointer to type atomic64_unchecked_t
17751+ * @new_val: value to assign
17752+ *
17753+ * Atomically xchgs the value of @ptr to @new_val and returns
17754+ * the old value.
17755+ */
17756+u64 atomic64_xchg_unchecked(atomic64_unchecked_t *ptr, u64 new_val)
17757+{
17758+ /*
17759+ * Try first with a (possibly incorrect) assumption about
17760+ * what we have there. We'll do two loops most likely,
17761+ * but we'll get an ownership MESI transaction straight away
17762+ * instead of a read transaction followed by a
17763+ * flush-for-ownership transaction:
17764+ */
17765+ u64 old_val, real_val = 0;
17766+
17767+ do {
17768+ old_val = real_val;
17769+
17770+ real_val = atomic64_cmpxchg_unchecked(ptr, old_val, new_val);
17771+
17772+ } while (real_val != old_val);
17773+
17774+ return old_val;
17775+}
17776+EXPORT_SYMBOL(atomic64_xchg_unchecked);
17777+
17778+/**
17779 * atomic64_set - set atomic64 variable
17780 * @ptr: pointer to type atomic64_t
17781 * @new_val: value to assign
17782@@ -69,7 +105,19 @@ void atomic64_set(atomic64_t *ptr, u64 n
17783 EXPORT_SYMBOL(atomic64_set);
17784
17785 /**
17786-EXPORT_SYMBOL(atomic64_read);
17787+ * atomic64_unchecked_set - set atomic64 variable
17788+ * @ptr: pointer to type atomic64_unchecked_t
17789+ * @new_val: value to assign
17790+ *
17791+ * Atomically sets the value of @ptr to @new_val.
17792+ */
17793+void atomic64_set_unchecked(atomic64_unchecked_t *ptr, u64 new_val)
17794+{
17795+ atomic64_xchg_unchecked(ptr, new_val);
17796+}
17797+EXPORT_SYMBOL(atomic64_set_unchecked);
17798+
17799+/**
17800 * atomic64_add_return - add and return
17801 * @delta: integer value to add
17802 * @ptr: pointer to type atomic64_t
17803@@ -99,24 +147,72 @@ noinline u64 atomic64_add_return(u64 del
17804 }
17805 EXPORT_SYMBOL(atomic64_add_return);
17806
17807+/**
17808+ * atomic64_add_return_unchecked - add and return
17809+ * @delta: integer value to add
17810+ * @ptr: pointer to type atomic64_unchecked_t
17811+ *
17812+ * Atomically adds @delta to @ptr and returns @delta + *@ptr
17813+ */
17814+noinline u64 atomic64_add_return_unchecked(u64 delta, atomic64_unchecked_t *ptr)
17815+{
17816+ /*
17817+ * Try first with a (possibly incorrect) assumption about
17818+ * what we have there. We'll do two loops most likely,
17819+ * but we'll get an ownership MESI transaction straight away
17820+ * instead of a read transaction followed by a
17821+ * flush-for-ownership transaction:
17822+ */
17823+ u64 old_val, new_val, real_val = 0;
17824+
17825+ do {
17826+ old_val = real_val;
17827+ new_val = old_val + delta;
17828+
17829+ real_val = atomic64_cmpxchg_unchecked(ptr, old_val, new_val);
17830+
17831+ } while (real_val != old_val);
17832+
17833+ return new_val;
17834+}
17835+EXPORT_SYMBOL(atomic64_add_return_unchecked);
17836+
17837 u64 atomic64_sub_return(u64 delta, atomic64_t *ptr)
17838 {
17839 return atomic64_add_return(-delta, ptr);
17840 }
17841 EXPORT_SYMBOL(atomic64_sub_return);
17842
17843+u64 atomic64_sub_return_unchecked(u64 delta, atomic64_unchecked_t *ptr)
17844+{
17845+ return atomic64_add_return_unchecked(-delta, ptr);
17846+}
17847+EXPORT_SYMBOL(atomic64_sub_return_unchecked);
17848+
17849 u64 atomic64_inc_return(atomic64_t *ptr)
17850 {
17851 return atomic64_add_return(1, ptr);
17852 }
17853 EXPORT_SYMBOL(atomic64_inc_return);
17854
17855+u64 atomic64_inc_return_unchecked(atomic64_unchecked_t *ptr)
17856+{
17857+ return atomic64_add_return_unchecked(1, ptr);
17858+}
17859+EXPORT_SYMBOL(atomic64_inc_return_unchecked);
17860+
17861 u64 atomic64_dec_return(atomic64_t *ptr)
17862 {
17863 return atomic64_sub_return(1, ptr);
17864 }
17865 EXPORT_SYMBOL(atomic64_dec_return);
17866
17867+u64 atomic64_dec_return_unchecked(atomic64_unchecked_t *ptr)
17868+{
17869+ return atomic64_sub_return_unchecked(1, ptr);
17870+}
17871+EXPORT_SYMBOL(atomic64_dec_return_unchecked);
17872+
17873 /**
17874 * atomic64_add - add integer to atomic64 variable
17875 * @delta: integer value to add
17876@@ -131,6 +227,19 @@ void atomic64_add(u64 delta, atomic64_t
17877 EXPORT_SYMBOL(atomic64_add);
17878
17879 /**
17880+ * atomic64_add_unchecked - add integer to atomic64 variable
17881+ * @delta: integer value to add
17882+ * @ptr: pointer to type atomic64_unchecked_t
17883+ *
17884+ * Atomically adds @delta to @ptr.
17885+ */
17886+void atomic64_add_unchecked(u64 delta, atomic64_unchecked_t *ptr)
17887+{
17888+ atomic64_add_return_unchecked(delta, ptr);
17889+}
17890+EXPORT_SYMBOL(atomic64_add_unchecked);
17891+
17892+/**
17893 * atomic64_sub - subtract the atomic64 variable
17894 * @delta: integer value to subtract
17895 * @ptr: pointer to type atomic64_t
17896@@ -144,6 +253,19 @@ void atomic64_sub(u64 delta, atomic64_t
17897 EXPORT_SYMBOL(atomic64_sub);
17898
17899 /**
17900+ * atomic64_sub_unchecked - subtract the atomic64 variable
17901+ * @delta: integer value to subtract
17902+ * @ptr: pointer to type atomic64_unchecked_t
17903+ *
17904+ * Atomically subtracts @delta from @ptr.
17905+ */
17906+void atomic64_sub_unchecked(u64 delta, atomic64_unchecked_t *ptr)
17907+{
17908+ atomic64_add_unchecked(-delta, ptr);
17909+}
17910+EXPORT_SYMBOL(atomic64_sub_unchecked);
17911+
17912+/**
17913 * atomic64_sub_and_test - subtract value from variable and test result
17914 * @delta: integer value to subtract
17915 * @ptr: pointer to type atomic64_t
17916@@ -173,6 +295,18 @@ void atomic64_inc(atomic64_t *ptr)
17917 EXPORT_SYMBOL(atomic64_inc);
17918
17919 /**
17920+ * atomic64_inc_unchecked - increment atomic64 variable
17921+ * @ptr: pointer to type atomic64_unchecked_t
17922+ *
17923+ * Atomically increments @ptr by 1.
17924+ */
17925+void atomic64_inc_unchecked(atomic64_unchecked_t *ptr)
17926+{
17927+ atomic64_add_unchecked(1, ptr);
17928+}
17929+EXPORT_SYMBOL(atomic64_inc_unchecked);
17930+
17931+/**
17932 * atomic64_dec - decrement atomic64 variable
17933 * @ptr: pointer to type atomic64_t
17934 *
17935@@ -185,6 +319,18 @@ void atomic64_dec(atomic64_t *ptr)
17936 EXPORT_SYMBOL(atomic64_dec);
17937
17938 /**
17939+ * atomic64_dec_unchecked - decrement atomic64 variable
17940+ * @ptr: pointer to type atomic64_unchecked_t
17941+ *
17942+ * Atomically decrements @ptr by 1.
17943+ */
17944+void atomic64_dec_unchecked(atomic64_unchecked_t *ptr)
17945+{
17946+ atomic64_sub_unchecked(1, ptr);
17947+}
17948+EXPORT_SYMBOL(atomic64_dec_unchecked);
17949+
17950+/**
17951 * atomic64_dec_and_test - decrement and test
17952 * @ptr: pointer to type atomic64_t
17953 *
17954diff -urNp linux-2.6.32.41/arch/x86/lib/checksum_32.S linux-2.6.32.41/arch/x86/lib/checksum_32.S
17955--- linux-2.6.32.41/arch/x86/lib/checksum_32.S 2011-03-27 14:31:47.000000000 -0400
17956+++ linux-2.6.32.41/arch/x86/lib/checksum_32.S 2011-04-17 15:56:46.000000000 -0400
17957@@ -28,7 +28,8 @@
17958 #include <linux/linkage.h>
17959 #include <asm/dwarf2.h>
17960 #include <asm/errno.h>
17961-
17962+#include <asm/segment.h>
17963+
17964 /*
17965 * computes a partial checksum, e.g. for TCP/UDP fragments
17966 */
17967@@ -304,9 +305,28 @@ unsigned int csum_partial_copy_generic (
17968
17969 #define ARGBASE 16
17970 #define FP 12
17971-
17972-ENTRY(csum_partial_copy_generic)
17973+
17974+ENTRY(csum_partial_copy_generic_to_user)
17975 CFI_STARTPROC
17976+
17977+#ifdef CONFIG_PAX_MEMORY_UDEREF
17978+ pushl %gs
17979+ CFI_ADJUST_CFA_OFFSET 4
17980+ popl %es
17981+ CFI_ADJUST_CFA_OFFSET -4
17982+ jmp csum_partial_copy_generic
17983+#endif
17984+
17985+ENTRY(csum_partial_copy_generic_from_user)
17986+
17987+#ifdef CONFIG_PAX_MEMORY_UDEREF
17988+ pushl %gs
17989+ CFI_ADJUST_CFA_OFFSET 4
17990+ popl %ds
17991+ CFI_ADJUST_CFA_OFFSET -4
17992+#endif
17993+
17994+ENTRY(csum_partial_copy_generic)
17995 subl $4,%esp
17996 CFI_ADJUST_CFA_OFFSET 4
17997 pushl %edi
17998@@ -331,7 +351,7 @@ ENTRY(csum_partial_copy_generic)
17999 jmp 4f
18000 SRC(1: movw (%esi), %bx )
18001 addl $2, %esi
18002-DST( movw %bx, (%edi) )
18003+DST( movw %bx, %es:(%edi) )
18004 addl $2, %edi
18005 addw %bx, %ax
18006 adcl $0, %eax
18007@@ -343,30 +363,30 @@ DST( movw %bx, (%edi) )
18008 SRC(1: movl (%esi), %ebx )
18009 SRC( movl 4(%esi), %edx )
18010 adcl %ebx, %eax
18011-DST( movl %ebx, (%edi) )
18012+DST( movl %ebx, %es:(%edi) )
18013 adcl %edx, %eax
18014-DST( movl %edx, 4(%edi) )
18015+DST( movl %edx, %es:4(%edi) )
18016
18017 SRC( movl 8(%esi), %ebx )
18018 SRC( movl 12(%esi), %edx )
18019 adcl %ebx, %eax
18020-DST( movl %ebx, 8(%edi) )
18021+DST( movl %ebx, %es:8(%edi) )
18022 adcl %edx, %eax
18023-DST( movl %edx, 12(%edi) )
18024+DST( movl %edx, %es:12(%edi) )
18025
18026 SRC( movl 16(%esi), %ebx )
18027 SRC( movl 20(%esi), %edx )
18028 adcl %ebx, %eax
18029-DST( movl %ebx, 16(%edi) )
18030+DST( movl %ebx, %es:16(%edi) )
18031 adcl %edx, %eax
18032-DST( movl %edx, 20(%edi) )
18033+DST( movl %edx, %es:20(%edi) )
18034
18035 SRC( movl 24(%esi), %ebx )
18036 SRC( movl 28(%esi), %edx )
18037 adcl %ebx, %eax
18038-DST( movl %ebx, 24(%edi) )
18039+DST( movl %ebx, %es:24(%edi) )
18040 adcl %edx, %eax
18041-DST( movl %edx, 28(%edi) )
18042+DST( movl %edx, %es:28(%edi) )
18043
18044 lea 32(%esi), %esi
18045 lea 32(%edi), %edi
18046@@ -380,7 +400,7 @@ DST( movl %edx, 28(%edi) )
18047 shrl $2, %edx # This clears CF
18048 SRC(3: movl (%esi), %ebx )
18049 adcl %ebx, %eax
18050-DST( movl %ebx, (%edi) )
18051+DST( movl %ebx, %es:(%edi) )
18052 lea 4(%esi), %esi
18053 lea 4(%edi), %edi
18054 dec %edx
18055@@ -392,12 +412,12 @@ DST( movl %ebx, (%edi) )
18056 jb 5f
18057 SRC( movw (%esi), %cx )
18058 leal 2(%esi), %esi
18059-DST( movw %cx, (%edi) )
18060+DST( movw %cx, %es:(%edi) )
18061 leal 2(%edi), %edi
18062 je 6f
18063 shll $16,%ecx
18064 SRC(5: movb (%esi), %cl )
18065-DST( movb %cl, (%edi) )
18066+DST( movb %cl, %es:(%edi) )
18067 6: addl %ecx, %eax
18068 adcl $0, %eax
18069 7:
18070@@ -408,7 +428,7 @@ DST( movb %cl, (%edi) )
18071
18072 6001:
18073 movl ARGBASE+20(%esp), %ebx # src_err_ptr
18074- movl $-EFAULT, (%ebx)
18075+ movl $-EFAULT, %ss:(%ebx)
18076
18077 # zero the complete destination - computing the rest
18078 # is too much work
18079@@ -421,11 +441,19 @@ DST( movb %cl, (%edi) )
18080
18081 6002:
18082 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
18083- movl $-EFAULT,(%ebx)
18084+ movl $-EFAULT,%ss:(%ebx)
18085 jmp 5000b
18086
18087 .previous
18088
18089+ pushl %ss
18090+ CFI_ADJUST_CFA_OFFSET 4
18091+ popl %ds
18092+ CFI_ADJUST_CFA_OFFSET -4
18093+ pushl %ss
18094+ CFI_ADJUST_CFA_OFFSET 4
18095+ popl %es
18096+ CFI_ADJUST_CFA_OFFSET -4
18097 popl %ebx
18098 CFI_ADJUST_CFA_OFFSET -4
18099 CFI_RESTORE ebx
18100@@ -439,26 +467,47 @@ DST( movb %cl, (%edi) )
18101 CFI_ADJUST_CFA_OFFSET -4
18102 ret
18103 CFI_ENDPROC
18104-ENDPROC(csum_partial_copy_generic)
18105+ENDPROC(csum_partial_copy_generic_to_user)
18106
18107 #else
18108
18109 /* Version for PentiumII/PPro */
18110
18111 #define ROUND1(x) \
18112+ nop; nop; nop; \
18113 SRC(movl x(%esi), %ebx ) ; \
18114 addl %ebx, %eax ; \
18115- DST(movl %ebx, x(%edi) ) ;
18116+ DST(movl %ebx, %es:x(%edi)) ;
18117
18118 #define ROUND(x) \
18119+ nop; nop; nop; \
18120 SRC(movl x(%esi), %ebx ) ; \
18121 adcl %ebx, %eax ; \
18122- DST(movl %ebx, x(%edi) ) ;
18123+ DST(movl %ebx, %es:x(%edi)) ;
18124
18125 #define ARGBASE 12
18126-
18127-ENTRY(csum_partial_copy_generic)
18128+
18129+ENTRY(csum_partial_copy_generic_to_user)
18130 CFI_STARTPROC
18131+
18132+#ifdef CONFIG_PAX_MEMORY_UDEREF
18133+ pushl %gs
18134+ CFI_ADJUST_CFA_OFFSET 4
18135+ popl %es
18136+ CFI_ADJUST_CFA_OFFSET -4
18137+ jmp csum_partial_copy_generic
18138+#endif
18139+
18140+ENTRY(csum_partial_copy_generic_from_user)
18141+
18142+#ifdef CONFIG_PAX_MEMORY_UDEREF
18143+ pushl %gs
18144+ CFI_ADJUST_CFA_OFFSET 4
18145+ popl %ds
18146+ CFI_ADJUST_CFA_OFFSET -4
18147+#endif
18148+
18149+ENTRY(csum_partial_copy_generic)
18150 pushl %ebx
18151 CFI_ADJUST_CFA_OFFSET 4
18152 CFI_REL_OFFSET ebx, 0
18153@@ -482,7 +531,7 @@ ENTRY(csum_partial_copy_generic)
18154 subl %ebx, %edi
18155 lea -1(%esi),%edx
18156 andl $-32,%edx
18157- lea 3f(%ebx,%ebx), %ebx
18158+ lea 3f(%ebx,%ebx,2), %ebx
18159 testl %esi, %esi
18160 jmp *%ebx
18161 1: addl $64,%esi
18162@@ -503,19 +552,19 @@ ENTRY(csum_partial_copy_generic)
18163 jb 5f
18164 SRC( movw (%esi), %dx )
18165 leal 2(%esi), %esi
18166-DST( movw %dx, (%edi) )
18167+DST( movw %dx, %es:(%edi) )
18168 leal 2(%edi), %edi
18169 je 6f
18170 shll $16,%edx
18171 5:
18172 SRC( movb (%esi), %dl )
18173-DST( movb %dl, (%edi) )
18174+DST( movb %dl, %es:(%edi) )
18175 6: addl %edx, %eax
18176 adcl $0, %eax
18177 7:
18178 .section .fixup, "ax"
18179 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
18180- movl $-EFAULT, (%ebx)
18181+ movl $-EFAULT, %ss:(%ebx)
18182 # zero the complete destination (computing the rest is too much work)
18183 movl ARGBASE+8(%esp),%edi # dst
18184 movl ARGBASE+12(%esp),%ecx # len
18185@@ -523,10 +572,21 @@ DST( movb %dl, (%edi) )
18186 rep; stosb
18187 jmp 7b
18188 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
18189- movl $-EFAULT, (%ebx)
18190+ movl $-EFAULT, %ss:(%ebx)
18191 jmp 7b
18192 .previous
18193
18194+#ifdef CONFIG_PAX_MEMORY_UDEREF
18195+ pushl %ss
18196+ CFI_ADJUST_CFA_OFFSET 4
18197+ popl %ds
18198+ CFI_ADJUST_CFA_OFFSET -4
18199+ pushl %ss
18200+ CFI_ADJUST_CFA_OFFSET 4
18201+ popl %es
18202+ CFI_ADJUST_CFA_OFFSET -4
18203+#endif
18204+
18205 popl %esi
18206 CFI_ADJUST_CFA_OFFSET -4
18207 CFI_RESTORE esi
18208@@ -538,7 +598,7 @@ DST( movb %dl, (%edi) )
18209 CFI_RESTORE ebx
18210 ret
18211 CFI_ENDPROC
18212-ENDPROC(csum_partial_copy_generic)
18213+ENDPROC(csum_partial_copy_generic_to_user)
18214
18215 #undef ROUND
18216 #undef ROUND1
18217diff -urNp linux-2.6.32.41/arch/x86/lib/clear_page_64.S linux-2.6.32.41/arch/x86/lib/clear_page_64.S
18218--- linux-2.6.32.41/arch/x86/lib/clear_page_64.S 2011-03-27 14:31:47.000000000 -0400
18219+++ linux-2.6.32.41/arch/x86/lib/clear_page_64.S 2011-04-17 15:56:46.000000000 -0400
18220@@ -43,7 +43,7 @@ ENDPROC(clear_page)
18221
18222 #include <asm/cpufeature.h>
18223
18224- .section .altinstr_replacement,"ax"
18225+ .section .altinstr_replacement,"a"
18226 1: .byte 0xeb /* jmp <disp8> */
18227 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
18228 2:
18229diff -urNp linux-2.6.32.41/arch/x86/lib/copy_page_64.S linux-2.6.32.41/arch/x86/lib/copy_page_64.S
18230--- linux-2.6.32.41/arch/x86/lib/copy_page_64.S 2011-03-27 14:31:47.000000000 -0400
18231+++ linux-2.6.32.41/arch/x86/lib/copy_page_64.S 2011-04-17 15:56:46.000000000 -0400
18232@@ -104,7 +104,7 @@ ENDPROC(copy_page)
18233
18234 #include <asm/cpufeature.h>
18235
18236- .section .altinstr_replacement,"ax"
18237+ .section .altinstr_replacement,"a"
18238 1: .byte 0xeb /* jmp <disp8> */
18239 .byte (copy_page_c - copy_page) - (2f - 1b) /* offset */
18240 2:
18241diff -urNp linux-2.6.32.41/arch/x86/lib/copy_user_64.S linux-2.6.32.41/arch/x86/lib/copy_user_64.S
18242--- linux-2.6.32.41/arch/x86/lib/copy_user_64.S 2011-03-27 14:31:47.000000000 -0400
18243+++ linux-2.6.32.41/arch/x86/lib/copy_user_64.S 2011-04-17 15:56:46.000000000 -0400
18244@@ -15,13 +15,14 @@
18245 #include <asm/asm-offsets.h>
18246 #include <asm/thread_info.h>
18247 #include <asm/cpufeature.h>
18248+#include <asm/pgtable.h>
18249
18250 .macro ALTERNATIVE_JUMP feature,orig,alt
18251 0:
18252 .byte 0xe9 /* 32bit jump */
18253 .long \orig-1f /* by default jump to orig */
18254 1:
18255- .section .altinstr_replacement,"ax"
18256+ .section .altinstr_replacement,"a"
18257 2: .byte 0xe9 /* near jump with 32bit immediate */
18258 .long \alt-1b /* offset */ /* or alternatively to alt */
18259 .previous
18260@@ -64,49 +65,19 @@
18261 #endif
18262 .endm
18263
18264-/* Standard copy_to_user with segment limit checking */
18265-ENTRY(copy_to_user)
18266- CFI_STARTPROC
18267- GET_THREAD_INFO(%rax)
18268- movq %rdi,%rcx
18269- addq %rdx,%rcx
18270- jc bad_to_user
18271- cmpq TI_addr_limit(%rax),%rcx
18272- jae bad_to_user
18273- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,copy_user_generic_unrolled,copy_user_generic_string
18274- CFI_ENDPROC
18275-ENDPROC(copy_to_user)
18276-
18277-/* Standard copy_from_user with segment limit checking */
18278-ENTRY(copy_from_user)
18279- CFI_STARTPROC
18280- GET_THREAD_INFO(%rax)
18281- movq %rsi,%rcx
18282- addq %rdx,%rcx
18283- jc bad_from_user
18284- cmpq TI_addr_limit(%rax),%rcx
18285- jae bad_from_user
18286- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,copy_user_generic_unrolled,copy_user_generic_string
18287- CFI_ENDPROC
18288-ENDPROC(copy_from_user)
18289-
18290 ENTRY(copy_user_generic)
18291 CFI_STARTPROC
18292 ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,copy_user_generic_unrolled,copy_user_generic_string
18293 CFI_ENDPROC
18294 ENDPROC(copy_user_generic)
18295
18296-ENTRY(__copy_from_user_inatomic)
18297- CFI_STARTPROC
18298- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,copy_user_generic_unrolled,copy_user_generic_string
18299- CFI_ENDPROC
18300-ENDPROC(__copy_from_user_inatomic)
18301-
18302 .section .fixup,"ax"
18303 /* must zero dest */
18304 ENTRY(bad_from_user)
18305 bad_from_user:
18306 CFI_STARTPROC
18307+ testl %edx,%edx
18308+ js bad_to_user
18309 movl %edx,%ecx
18310 xorl %eax,%eax
18311 rep
18312diff -urNp linux-2.6.32.41/arch/x86/lib/copy_user_nocache_64.S linux-2.6.32.41/arch/x86/lib/copy_user_nocache_64.S
18313--- linux-2.6.32.41/arch/x86/lib/copy_user_nocache_64.S 2011-03-27 14:31:47.000000000 -0400
18314+++ linux-2.6.32.41/arch/x86/lib/copy_user_nocache_64.S 2011-04-17 15:56:46.000000000 -0400
18315@@ -14,6 +14,7 @@
18316 #include <asm/current.h>
18317 #include <asm/asm-offsets.h>
18318 #include <asm/thread_info.h>
18319+#include <asm/pgtable.h>
18320
18321 .macro ALIGN_DESTINATION
18322 #ifdef FIX_ALIGNMENT
18323@@ -50,6 +51,15 @@
18324 */
18325 ENTRY(__copy_user_nocache)
18326 CFI_STARTPROC
18327+
18328+#ifdef CONFIG_PAX_MEMORY_UDEREF
18329+ mov $PAX_USER_SHADOW_BASE,%rcx
18330+ cmp %rcx,%rsi
18331+ jae 1f
18332+ add %rcx,%rsi
18333+1:
18334+#endif
18335+
18336 cmpl $8,%edx
18337 jb 20f /* less then 8 bytes, go to byte copy loop */
18338 ALIGN_DESTINATION
18339diff -urNp linux-2.6.32.41/arch/x86/lib/csum-wrappers_64.c linux-2.6.32.41/arch/x86/lib/csum-wrappers_64.c
18340--- linux-2.6.32.41/arch/x86/lib/csum-wrappers_64.c 2011-03-27 14:31:47.000000000 -0400
18341+++ linux-2.6.32.41/arch/x86/lib/csum-wrappers_64.c 2011-05-04 17:56:20.000000000 -0400
18342@@ -52,6 +52,12 @@ csum_partial_copy_from_user(const void _
18343 len -= 2;
18344 }
18345 }
18346+
18347+#ifdef CONFIG_PAX_MEMORY_UDEREF
18348+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
18349+ src += PAX_USER_SHADOW_BASE;
18350+#endif
18351+
18352 isum = csum_partial_copy_generic((__force const void *)src,
18353 dst, len, isum, errp, NULL);
18354 if (unlikely(*errp))
18355@@ -105,6 +111,12 @@ csum_partial_copy_to_user(const void *sr
18356 }
18357
18358 *errp = 0;
18359+
18360+#ifdef CONFIG_PAX_MEMORY_UDEREF
18361+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
18362+ dst += PAX_USER_SHADOW_BASE;
18363+#endif
18364+
18365 return csum_partial_copy_generic(src, (void __force *)dst,
18366 len, isum, NULL, errp);
18367 }
18368diff -urNp linux-2.6.32.41/arch/x86/lib/getuser.S linux-2.6.32.41/arch/x86/lib/getuser.S
18369--- linux-2.6.32.41/arch/x86/lib/getuser.S 2011-03-27 14:31:47.000000000 -0400
18370+++ linux-2.6.32.41/arch/x86/lib/getuser.S 2011-04-17 15:56:46.000000000 -0400
18371@@ -33,14 +33,35 @@
18372 #include <asm/asm-offsets.h>
18373 #include <asm/thread_info.h>
18374 #include <asm/asm.h>
18375+#include <asm/segment.h>
18376+#include <asm/pgtable.h>
18377+
18378+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
18379+#define __copyuser_seg gs;
18380+#else
18381+#define __copyuser_seg
18382+#endif
18383
18384 .text
18385 ENTRY(__get_user_1)
18386 CFI_STARTPROC
18387+
18388+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
18389 GET_THREAD_INFO(%_ASM_DX)
18390 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
18391 jae bad_get_user
18392-1: movzb (%_ASM_AX),%edx
18393+
18394+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18395+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
18396+ cmp %_ASM_DX,%_ASM_AX
18397+ jae 1234f
18398+ add %_ASM_DX,%_ASM_AX
18399+1234:
18400+#endif
18401+
18402+#endif
18403+
18404+1: __copyuser_seg movzb (%_ASM_AX),%edx
18405 xor %eax,%eax
18406 ret
18407 CFI_ENDPROC
18408@@ -49,11 +70,24 @@ ENDPROC(__get_user_1)
18409 ENTRY(__get_user_2)
18410 CFI_STARTPROC
18411 add $1,%_ASM_AX
18412+
18413+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
18414 jc bad_get_user
18415 GET_THREAD_INFO(%_ASM_DX)
18416 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
18417 jae bad_get_user
18418-2: movzwl -1(%_ASM_AX),%edx
18419+
18420+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18421+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
18422+ cmp %_ASM_DX,%_ASM_AX
18423+ jae 1234f
18424+ add %_ASM_DX,%_ASM_AX
18425+1234:
18426+#endif
18427+
18428+#endif
18429+
18430+2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
18431 xor %eax,%eax
18432 ret
18433 CFI_ENDPROC
18434@@ -62,11 +96,24 @@ ENDPROC(__get_user_2)
18435 ENTRY(__get_user_4)
18436 CFI_STARTPROC
18437 add $3,%_ASM_AX
18438+
18439+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
18440 jc bad_get_user
18441 GET_THREAD_INFO(%_ASM_DX)
18442 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
18443 jae bad_get_user
18444-3: mov -3(%_ASM_AX),%edx
18445+
18446+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18447+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
18448+ cmp %_ASM_DX,%_ASM_AX
18449+ jae 1234f
18450+ add %_ASM_DX,%_ASM_AX
18451+1234:
18452+#endif
18453+
18454+#endif
18455+
18456+3: __copyuser_seg mov -3(%_ASM_AX),%edx
18457 xor %eax,%eax
18458 ret
18459 CFI_ENDPROC
18460@@ -80,6 +127,15 @@ ENTRY(__get_user_8)
18461 GET_THREAD_INFO(%_ASM_DX)
18462 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
18463 jae bad_get_user
18464+
18465+#ifdef CONFIG_PAX_MEMORY_UDEREF
18466+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
18467+ cmp %_ASM_DX,%_ASM_AX
18468+ jae 1234f
18469+ add %_ASM_DX,%_ASM_AX
18470+1234:
18471+#endif
18472+
18473 4: movq -7(%_ASM_AX),%_ASM_DX
18474 xor %eax,%eax
18475 ret
18476diff -urNp linux-2.6.32.41/arch/x86/lib/memcpy_64.S linux-2.6.32.41/arch/x86/lib/memcpy_64.S
18477--- linux-2.6.32.41/arch/x86/lib/memcpy_64.S 2011-03-27 14:31:47.000000000 -0400
18478+++ linux-2.6.32.41/arch/x86/lib/memcpy_64.S 2011-04-17 15:56:46.000000000 -0400
18479@@ -128,7 +128,7 @@ ENDPROC(__memcpy)
18480 * It is also a lot simpler. Use this when possible:
18481 */
18482
18483- .section .altinstr_replacement, "ax"
18484+ .section .altinstr_replacement, "a"
18485 1: .byte 0xeb /* jmp <disp8> */
18486 .byte (memcpy_c - memcpy) - (2f - 1b) /* offset */
18487 2:
18488diff -urNp linux-2.6.32.41/arch/x86/lib/memset_64.S linux-2.6.32.41/arch/x86/lib/memset_64.S
18489--- linux-2.6.32.41/arch/x86/lib/memset_64.S 2011-03-27 14:31:47.000000000 -0400
18490+++ linux-2.6.32.41/arch/x86/lib/memset_64.S 2011-04-17 15:56:46.000000000 -0400
18491@@ -118,7 +118,7 @@ ENDPROC(__memset)
18492
18493 #include <asm/cpufeature.h>
18494
18495- .section .altinstr_replacement,"ax"
18496+ .section .altinstr_replacement,"a"
18497 1: .byte 0xeb /* jmp <disp8> */
18498 .byte (memset_c - memset) - (2f - 1b) /* offset */
18499 2:
18500diff -urNp linux-2.6.32.41/arch/x86/lib/mmx_32.c linux-2.6.32.41/arch/x86/lib/mmx_32.c
18501--- linux-2.6.32.41/arch/x86/lib/mmx_32.c 2011-03-27 14:31:47.000000000 -0400
18502+++ linux-2.6.32.41/arch/x86/lib/mmx_32.c 2011-04-17 15:56:46.000000000 -0400
18503@@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *
18504 {
18505 void *p;
18506 int i;
18507+ unsigned long cr0;
18508
18509 if (unlikely(in_interrupt()))
18510 return __memcpy(to, from, len);
18511@@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *
18512 kernel_fpu_begin();
18513
18514 __asm__ __volatile__ (
18515- "1: prefetch (%0)\n" /* This set is 28 bytes */
18516- " prefetch 64(%0)\n"
18517- " prefetch 128(%0)\n"
18518- " prefetch 192(%0)\n"
18519- " prefetch 256(%0)\n"
18520+ "1: prefetch (%1)\n" /* This set is 28 bytes */
18521+ " prefetch 64(%1)\n"
18522+ " prefetch 128(%1)\n"
18523+ " prefetch 192(%1)\n"
18524+ " prefetch 256(%1)\n"
18525 "2: \n"
18526 ".section .fixup, \"ax\"\n"
18527- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
18528+ "3: \n"
18529+
18530+#ifdef CONFIG_PAX_KERNEXEC
18531+ " movl %%cr0, %0\n"
18532+ " movl %0, %%eax\n"
18533+ " andl $0xFFFEFFFF, %%eax\n"
18534+ " movl %%eax, %%cr0\n"
18535+#endif
18536+
18537+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
18538+
18539+#ifdef CONFIG_PAX_KERNEXEC
18540+ " movl %0, %%cr0\n"
18541+#endif
18542+
18543 " jmp 2b\n"
18544 ".previous\n"
18545 _ASM_EXTABLE(1b, 3b)
18546- : : "r" (from));
18547+ : "=&r" (cr0) : "r" (from) : "ax");
18548
18549 for ( ; i > 5; i--) {
18550 __asm__ __volatile__ (
18551- "1: prefetch 320(%0)\n"
18552- "2: movq (%0), %%mm0\n"
18553- " movq 8(%0), %%mm1\n"
18554- " movq 16(%0), %%mm2\n"
18555- " movq 24(%0), %%mm3\n"
18556- " movq %%mm0, (%1)\n"
18557- " movq %%mm1, 8(%1)\n"
18558- " movq %%mm2, 16(%1)\n"
18559- " movq %%mm3, 24(%1)\n"
18560- " movq 32(%0), %%mm0\n"
18561- " movq 40(%0), %%mm1\n"
18562- " movq 48(%0), %%mm2\n"
18563- " movq 56(%0), %%mm3\n"
18564- " movq %%mm0, 32(%1)\n"
18565- " movq %%mm1, 40(%1)\n"
18566- " movq %%mm2, 48(%1)\n"
18567- " movq %%mm3, 56(%1)\n"
18568+ "1: prefetch 320(%1)\n"
18569+ "2: movq (%1), %%mm0\n"
18570+ " movq 8(%1), %%mm1\n"
18571+ " movq 16(%1), %%mm2\n"
18572+ " movq 24(%1), %%mm3\n"
18573+ " movq %%mm0, (%2)\n"
18574+ " movq %%mm1, 8(%2)\n"
18575+ " movq %%mm2, 16(%2)\n"
18576+ " movq %%mm3, 24(%2)\n"
18577+ " movq 32(%1), %%mm0\n"
18578+ " movq 40(%1), %%mm1\n"
18579+ " movq 48(%1), %%mm2\n"
18580+ " movq 56(%1), %%mm3\n"
18581+ " movq %%mm0, 32(%2)\n"
18582+ " movq %%mm1, 40(%2)\n"
18583+ " movq %%mm2, 48(%2)\n"
18584+ " movq %%mm3, 56(%2)\n"
18585 ".section .fixup, \"ax\"\n"
18586- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
18587+ "3:\n"
18588+
18589+#ifdef CONFIG_PAX_KERNEXEC
18590+ " movl %%cr0, %0\n"
18591+ " movl %0, %%eax\n"
18592+ " andl $0xFFFEFFFF, %%eax\n"
18593+ " movl %%eax, %%cr0\n"
18594+#endif
18595+
18596+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
18597+
18598+#ifdef CONFIG_PAX_KERNEXEC
18599+ " movl %0, %%cr0\n"
18600+#endif
18601+
18602 " jmp 2b\n"
18603 ".previous\n"
18604 _ASM_EXTABLE(1b, 3b)
18605- : : "r" (from), "r" (to) : "memory");
18606+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
18607
18608 from += 64;
18609 to += 64;
18610@@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
18611 static void fast_copy_page(void *to, void *from)
18612 {
18613 int i;
18614+ unsigned long cr0;
18615
18616 kernel_fpu_begin();
18617
18618@@ -166,42 +196,70 @@ static void fast_copy_page(void *to, voi
18619 * but that is for later. -AV
18620 */
18621 __asm__ __volatile__(
18622- "1: prefetch (%0)\n"
18623- " prefetch 64(%0)\n"
18624- " prefetch 128(%0)\n"
18625- " prefetch 192(%0)\n"
18626- " prefetch 256(%0)\n"
18627+ "1: prefetch (%1)\n"
18628+ " prefetch 64(%1)\n"
18629+ " prefetch 128(%1)\n"
18630+ " prefetch 192(%1)\n"
18631+ " prefetch 256(%1)\n"
18632 "2: \n"
18633 ".section .fixup, \"ax\"\n"
18634- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
18635+ "3: \n"
18636+
18637+#ifdef CONFIG_PAX_KERNEXEC
18638+ " movl %%cr0, %0\n"
18639+ " movl %0, %%eax\n"
18640+ " andl $0xFFFEFFFF, %%eax\n"
18641+ " movl %%eax, %%cr0\n"
18642+#endif
18643+
18644+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
18645+
18646+#ifdef CONFIG_PAX_KERNEXEC
18647+ " movl %0, %%cr0\n"
18648+#endif
18649+
18650 " jmp 2b\n"
18651 ".previous\n"
18652- _ASM_EXTABLE(1b, 3b) : : "r" (from));
18653+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
18654
18655 for (i = 0; i < (4096-320)/64; i++) {
18656 __asm__ __volatile__ (
18657- "1: prefetch 320(%0)\n"
18658- "2: movq (%0), %%mm0\n"
18659- " movntq %%mm0, (%1)\n"
18660- " movq 8(%0), %%mm1\n"
18661- " movntq %%mm1, 8(%1)\n"
18662- " movq 16(%0), %%mm2\n"
18663- " movntq %%mm2, 16(%1)\n"
18664- " movq 24(%0), %%mm3\n"
18665- " movntq %%mm3, 24(%1)\n"
18666- " movq 32(%0), %%mm4\n"
18667- " movntq %%mm4, 32(%1)\n"
18668- " movq 40(%0), %%mm5\n"
18669- " movntq %%mm5, 40(%1)\n"
18670- " movq 48(%0), %%mm6\n"
18671- " movntq %%mm6, 48(%1)\n"
18672- " movq 56(%0), %%mm7\n"
18673- " movntq %%mm7, 56(%1)\n"
18674+ "1: prefetch 320(%1)\n"
18675+ "2: movq (%1), %%mm0\n"
18676+ " movntq %%mm0, (%2)\n"
18677+ " movq 8(%1), %%mm1\n"
18678+ " movntq %%mm1, 8(%2)\n"
18679+ " movq 16(%1), %%mm2\n"
18680+ " movntq %%mm2, 16(%2)\n"
18681+ " movq 24(%1), %%mm3\n"
18682+ " movntq %%mm3, 24(%2)\n"
18683+ " movq 32(%1), %%mm4\n"
18684+ " movntq %%mm4, 32(%2)\n"
18685+ " movq 40(%1), %%mm5\n"
18686+ " movntq %%mm5, 40(%2)\n"
18687+ " movq 48(%1), %%mm6\n"
18688+ " movntq %%mm6, 48(%2)\n"
18689+ " movq 56(%1), %%mm7\n"
18690+ " movntq %%mm7, 56(%2)\n"
18691 ".section .fixup, \"ax\"\n"
18692- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
18693+ "3:\n"
18694+
18695+#ifdef CONFIG_PAX_KERNEXEC
18696+ " movl %%cr0, %0\n"
18697+ " movl %0, %%eax\n"
18698+ " andl $0xFFFEFFFF, %%eax\n"
18699+ " movl %%eax, %%cr0\n"
18700+#endif
18701+
18702+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
18703+
18704+#ifdef CONFIG_PAX_KERNEXEC
18705+ " movl %0, %%cr0\n"
18706+#endif
18707+
18708 " jmp 2b\n"
18709 ".previous\n"
18710- _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
18711+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
18712
18713 from += 64;
18714 to += 64;
18715@@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
18716 static void fast_copy_page(void *to, void *from)
18717 {
18718 int i;
18719+ unsigned long cr0;
18720
18721 kernel_fpu_begin();
18722
18723 __asm__ __volatile__ (
18724- "1: prefetch (%0)\n"
18725- " prefetch 64(%0)\n"
18726- " prefetch 128(%0)\n"
18727- " prefetch 192(%0)\n"
18728- " prefetch 256(%0)\n"
18729+ "1: prefetch (%1)\n"
18730+ " prefetch 64(%1)\n"
18731+ " prefetch 128(%1)\n"
18732+ " prefetch 192(%1)\n"
18733+ " prefetch 256(%1)\n"
18734 "2: \n"
18735 ".section .fixup, \"ax\"\n"
18736- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
18737+ "3: \n"
18738+
18739+#ifdef CONFIG_PAX_KERNEXEC
18740+ " movl %%cr0, %0\n"
18741+ " movl %0, %%eax\n"
18742+ " andl $0xFFFEFFFF, %%eax\n"
18743+ " movl %%eax, %%cr0\n"
18744+#endif
18745+
18746+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
18747+
18748+#ifdef CONFIG_PAX_KERNEXEC
18749+ " movl %0, %%cr0\n"
18750+#endif
18751+
18752 " jmp 2b\n"
18753 ".previous\n"
18754- _ASM_EXTABLE(1b, 3b) : : "r" (from));
18755+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
18756
18757 for (i = 0; i < 4096/64; i++) {
18758 __asm__ __volatile__ (
18759- "1: prefetch 320(%0)\n"
18760- "2: movq (%0), %%mm0\n"
18761- " movq 8(%0), %%mm1\n"
18762- " movq 16(%0), %%mm2\n"
18763- " movq 24(%0), %%mm3\n"
18764- " movq %%mm0, (%1)\n"
18765- " movq %%mm1, 8(%1)\n"
18766- " movq %%mm2, 16(%1)\n"
18767- " movq %%mm3, 24(%1)\n"
18768- " movq 32(%0), %%mm0\n"
18769- " movq 40(%0), %%mm1\n"
18770- " movq 48(%0), %%mm2\n"
18771- " movq 56(%0), %%mm3\n"
18772- " movq %%mm0, 32(%1)\n"
18773- " movq %%mm1, 40(%1)\n"
18774- " movq %%mm2, 48(%1)\n"
18775- " movq %%mm3, 56(%1)\n"
18776+ "1: prefetch 320(%1)\n"
18777+ "2: movq (%1), %%mm0\n"
18778+ " movq 8(%1), %%mm1\n"
18779+ " movq 16(%1), %%mm2\n"
18780+ " movq 24(%1), %%mm3\n"
18781+ " movq %%mm0, (%2)\n"
18782+ " movq %%mm1, 8(%2)\n"
18783+ " movq %%mm2, 16(%2)\n"
18784+ " movq %%mm3, 24(%2)\n"
18785+ " movq 32(%1), %%mm0\n"
18786+ " movq 40(%1), %%mm1\n"
18787+ " movq 48(%1), %%mm2\n"
18788+ " movq 56(%1), %%mm3\n"
18789+ " movq %%mm0, 32(%2)\n"
18790+ " movq %%mm1, 40(%2)\n"
18791+ " movq %%mm2, 48(%2)\n"
18792+ " movq %%mm3, 56(%2)\n"
18793 ".section .fixup, \"ax\"\n"
18794- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
18795+ "3:\n"
18796+
18797+#ifdef CONFIG_PAX_KERNEXEC
18798+ " movl %%cr0, %0\n"
18799+ " movl %0, %%eax\n"
18800+ " andl $0xFFFEFFFF, %%eax\n"
18801+ " movl %%eax, %%cr0\n"
18802+#endif
18803+
18804+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
18805+
18806+#ifdef CONFIG_PAX_KERNEXEC
18807+ " movl %0, %%cr0\n"
18808+#endif
18809+
18810 " jmp 2b\n"
18811 ".previous\n"
18812 _ASM_EXTABLE(1b, 3b)
18813- : : "r" (from), "r" (to) : "memory");
18814+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
18815
18816 from += 64;
18817 to += 64;
18818diff -urNp linux-2.6.32.41/arch/x86/lib/putuser.S linux-2.6.32.41/arch/x86/lib/putuser.S
18819--- linux-2.6.32.41/arch/x86/lib/putuser.S 2011-03-27 14:31:47.000000000 -0400
18820+++ linux-2.6.32.41/arch/x86/lib/putuser.S 2011-04-17 15:56:46.000000000 -0400
18821@@ -15,7 +15,8 @@
18822 #include <asm/thread_info.h>
18823 #include <asm/errno.h>
18824 #include <asm/asm.h>
18825-
18826+#include <asm/segment.h>
18827+#include <asm/pgtable.h>
18828
18829 /*
18830 * __put_user_X
18831@@ -29,52 +30,119 @@
18832 * as they get called from within inline assembly.
18833 */
18834
18835-#define ENTER CFI_STARTPROC ; \
18836- GET_THREAD_INFO(%_ASM_BX)
18837+#define ENTER CFI_STARTPROC
18838 #define EXIT ret ; \
18839 CFI_ENDPROC
18840
18841+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18842+#define _DEST %_ASM_CX,%_ASM_BX
18843+#else
18844+#define _DEST %_ASM_CX
18845+#endif
18846+
18847+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
18848+#define __copyuser_seg gs;
18849+#else
18850+#define __copyuser_seg
18851+#endif
18852+
18853 .text
18854 ENTRY(__put_user_1)
18855 ENTER
18856+
18857+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
18858+ GET_THREAD_INFO(%_ASM_BX)
18859 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
18860 jae bad_put_user
18861-1: movb %al,(%_ASM_CX)
18862+
18863+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18864+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
18865+ cmp %_ASM_BX,%_ASM_CX
18866+ jb 1234f
18867+ xor %ebx,%ebx
18868+1234:
18869+#endif
18870+
18871+#endif
18872+
18873+1: __copyuser_seg movb %al,(_DEST)
18874 xor %eax,%eax
18875 EXIT
18876 ENDPROC(__put_user_1)
18877
18878 ENTRY(__put_user_2)
18879 ENTER
18880+
18881+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
18882+ GET_THREAD_INFO(%_ASM_BX)
18883 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
18884 sub $1,%_ASM_BX
18885 cmp %_ASM_BX,%_ASM_CX
18886 jae bad_put_user
18887-2: movw %ax,(%_ASM_CX)
18888+
18889+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18890+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
18891+ cmp %_ASM_BX,%_ASM_CX
18892+ jb 1234f
18893+ xor %ebx,%ebx
18894+1234:
18895+#endif
18896+
18897+#endif
18898+
18899+2: __copyuser_seg movw %ax,(_DEST)
18900 xor %eax,%eax
18901 EXIT
18902 ENDPROC(__put_user_2)
18903
18904 ENTRY(__put_user_4)
18905 ENTER
18906+
18907+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
18908+ GET_THREAD_INFO(%_ASM_BX)
18909 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
18910 sub $3,%_ASM_BX
18911 cmp %_ASM_BX,%_ASM_CX
18912 jae bad_put_user
18913-3: movl %eax,(%_ASM_CX)
18914+
18915+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18916+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
18917+ cmp %_ASM_BX,%_ASM_CX
18918+ jb 1234f
18919+ xor %ebx,%ebx
18920+1234:
18921+#endif
18922+
18923+#endif
18924+
18925+3: __copyuser_seg movl %eax,(_DEST)
18926 xor %eax,%eax
18927 EXIT
18928 ENDPROC(__put_user_4)
18929
18930 ENTRY(__put_user_8)
18931 ENTER
18932+
18933+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
18934+ GET_THREAD_INFO(%_ASM_BX)
18935 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
18936 sub $7,%_ASM_BX
18937 cmp %_ASM_BX,%_ASM_CX
18938 jae bad_put_user
18939-4: mov %_ASM_AX,(%_ASM_CX)
18940+
18941+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18942+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
18943+ cmp %_ASM_BX,%_ASM_CX
18944+ jb 1234f
18945+ xor %ebx,%ebx
18946+1234:
18947+#endif
18948+
18949+#endif
18950+
18951+4: __copyuser_seg mov %_ASM_AX,(_DEST)
18952 #ifdef CONFIG_X86_32
18953-5: movl %edx,4(%_ASM_CX)
18954+5: __copyuser_seg movl %edx,4(_DEST)
18955 #endif
18956 xor %eax,%eax
18957 EXIT
18958diff -urNp linux-2.6.32.41/arch/x86/lib/usercopy_32.c linux-2.6.32.41/arch/x86/lib/usercopy_32.c
18959--- linux-2.6.32.41/arch/x86/lib/usercopy_32.c 2011-03-27 14:31:47.000000000 -0400
18960+++ linux-2.6.32.41/arch/x86/lib/usercopy_32.c 2011-04-23 21:12:28.000000000 -0400
18961@@ -43,7 +43,7 @@ do { \
18962 __asm__ __volatile__( \
18963 " testl %1,%1\n" \
18964 " jz 2f\n" \
18965- "0: lodsb\n" \
18966+ "0: "__copyuser_seg"lodsb\n" \
18967 " stosb\n" \
18968 " testb %%al,%%al\n" \
18969 " jz 1f\n" \
18970@@ -128,10 +128,12 @@ do { \
18971 int __d0; \
18972 might_fault(); \
18973 __asm__ __volatile__( \
18974+ __COPYUSER_SET_ES \
18975 "0: rep; stosl\n" \
18976 " movl %2,%0\n" \
18977 "1: rep; stosb\n" \
18978 "2:\n" \
18979+ __COPYUSER_RESTORE_ES \
18980 ".section .fixup,\"ax\"\n" \
18981 "3: lea 0(%2,%0,4),%0\n" \
18982 " jmp 2b\n" \
18983@@ -200,6 +202,7 @@ long strnlen_user(const char __user *s,
18984 might_fault();
18985
18986 __asm__ __volatile__(
18987+ __COPYUSER_SET_ES
18988 " testl %0, %0\n"
18989 " jz 3f\n"
18990 " andl %0,%%ecx\n"
18991@@ -208,6 +211,7 @@ long strnlen_user(const char __user *s,
18992 " subl %%ecx,%0\n"
18993 " addl %0,%%eax\n"
18994 "1:\n"
18995+ __COPYUSER_RESTORE_ES
18996 ".section .fixup,\"ax\"\n"
18997 "2: xorl %%eax,%%eax\n"
18998 " jmp 1b\n"
18999@@ -227,7 +231,7 @@ EXPORT_SYMBOL(strnlen_user);
19000
19001 #ifdef CONFIG_X86_INTEL_USERCOPY
19002 static unsigned long
19003-__copy_user_intel(void __user *to, const void *from, unsigned long size)
19004+__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
19005 {
19006 int d0, d1;
19007 __asm__ __volatile__(
19008@@ -239,36 +243,36 @@ __copy_user_intel(void __user *to, const
19009 " .align 2,0x90\n"
19010 "3: movl 0(%4), %%eax\n"
19011 "4: movl 4(%4), %%edx\n"
19012- "5: movl %%eax, 0(%3)\n"
19013- "6: movl %%edx, 4(%3)\n"
19014+ "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
19015+ "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
19016 "7: movl 8(%4), %%eax\n"
19017 "8: movl 12(%4),%%edx\n"
19018- "9: movl %%eax, 8(%3)\n"
19019- "10: movl %%edx, 12(%3)\n"
19020+ "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
19021+ "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
19022 "11: movl 16(%4), %%eax\n"
19023 "12: movl 20(%4), %%edx\n"
19024- "13: movl %%eax, 16(%3)\n"
19025- "14: movl %%edx, 20(%3)\n"
19026+ "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
19027+ "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
19028 "15: movl 24(%4), %%eax\n"
19029 "16: movl 28(%4), %%edx\n"
19030- "17: movl %%eax, 24(%3)\n"
19031- "18: movl %%edx, 28(%3)\n"
19032+ "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
19033+ "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
19034 "19: movl 32(%4), %%eax\n"
19035 "20: movl 36(%4), %%edx\n"
19036- "21: movl %%eax, 32(%3)\n"
19037- "22: movl %%edx, 36(%3)\n"
19038+ "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
19039+ "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
19040 "23: movl 40(%4), %%eax\n"
19041 "24: movl 44(%4), %%edx\n"
19042- "25: movl %%eax, 40(%3)\n"
19043- "26: movl %%edx, 44(%3)\n"
19044+ "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
19045+ "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
19046 "27: movl 48(%4), %%eax\n"
19047 "28: movl 52(%4), %%edx\n"
19048- "29: movl %%eax, 48(%3)\n"
19049- "30: movl %%edx, 52(%3)\n"
19050+ "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
19051+ "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
19052 "31: movl 56(%4), %%eax\n"
19053 "32: movl 60(%4), %%edx\n"
19054- "33: movl %%eax, 56(%3)\n"
19055- "34: movl %%edx, 60(%3)\n"
19056+ "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
19057+ "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
19058 " addl $-64, %0\n"
19059 " addl $64, %4\n"
19060 " addl $64, %3\n"
19061@@ -278,10 +282,119 @@ __copy_user_intel(void __user *to, const
19062 " shrl $2, %0\n"
19063 " andl $3, %%eax\n"
19064 " cld\n"
19065+ __COPYUSER_SET_ES
19066 "99: rep; movsl\n"
19067 "36: movl %%eax, %0\n"
19068 "37: rep; movsb\n"
19069 "100:\n"
19070+ __COPYUSER_RESTORE_ES
19071+ ".section .fixup,\"ax\"\n"
19072+ "101: lea 0(%%eax,%0,4),%0\n"
19073+ " jmp 100b\n"
19074+ ".previous\n"
19075+ ".section __ex_table,\"a\"\n"
19076+ " .align 4\n"
19077+ " .long 1b,100b\n"
19078+ " .long 2b,100b\n"
19079+ " .long 3b,100b\n"
19080+ " .long 4b,100b\n"
19081+ " .long 5b,100b\n"
19082+ " .long 6b,100b\n"
19083+ " .long 7b,100b\n"
19084+ " .long 8b,100b\n"
19085+ " .long 9b,100b\n"
19086+ " .long 10b,100b\n"
19087+ " .long 11b,100b\n"
19088+ " .long 12b,100b\n"
19089+ " .long 13b,100b\n"
19090+ " .long 14b,100b\n"
19091+ " .long 15b,100b\n"
19092+ " .long 16b,100b\n"
19093+ " .long 17b,100b\n"
19094+ " .long 18b,100b\n"
19095+ " .long 19b,100b\n"
19096+ " .long 20b,100b\n"
19097+ " .long 21b,100b\n"
19098+ " .long 22b,100b\n"
19099+ " .long 23b,100b\n"
19100+ " .long 24b,100b\n"
19101+ " .long 25b,100b\n"
19102+ " .long 26b,100b\n"
19103+ " .long 27b,100b\n"
19104+ " .long 28b,100b\n"
19105+ " .long 29b,100b\n"
19106+ " .long 30b,100b\n"
19107+ " .long 31b,100b\n"
19108+ " .long 32b,100b\n"
19109+ " .long 33b,100b\n"
19110+ " .long 34b,100b\n"
19111+ " .long 35b,100b\n"
19112+ " .long 36b,100b\n"
19113+ " .long 37b,100b\n"
19114+ " .long 99b,101b\n"
19115+ ".previous"
19116+ : "=&c"(size), "=&D" (d0), "=&S" (d1)
19117+ : "1"(to), "2"(from), "0"(size)
19118+ : "eax", "edx", "memory");
19119+ return size;
19120+}
19121+
19122+static unsigned long
19123+__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
19124+{
19125+ int d0, d1;
19126+ __asm__ __volatile__(
19127+ " .align 2,0x90\n"
19128+ "1: "__copyuser_seg" movl 32(%4), %%eax\n"
19129+ " cmpl $67, %0\n"
19130+ " jbe 3f\n"
19131+ "2: "__copyuser_seg" movl 64(%4), %%eax\n"
19132+ " .align 2,0x90\n"
19133+ "3: "__copyuser_seg" movl 0(%4), %%eax\n"
19134+ "4: "__copyuser_seg" movl 4(%4), %%edx\n"
19135+ "5: movl %%eax, 0(%3)\n"
19136+ "6: movl %%edx, 4(%3)\n"
19137+ "7: "__copyuser_seg" movl 8(%4), %%eax\n"
19138+ "8: "__copyuser_seg" movl 12(%4),%%edx\n"
19139+ "9: movl %%eax, 8(%3)\n"
19140+ "10: movl %%edx, 12(%3)\n"
19141+ "11: "__copyuser_seg" movl 16(%4), %%eax\n"
19142+ "12: "__copyuser_seg" movl 20(%4), %%edx\n"
19143+ "13: movl %%eax, 16(%3)\n"
19144+ "14: movl %%edx, 20(%3)\n"
19145+ "15: "__copyuser_seg" movl 24(%4), %%eax\n"
19146+ "16: "__copyuser_seg" movl 28(%4), %%edx\n"
19147+ "17: movl %%eax, 24(%3)\n"
19148+ "18: movl %%edx, 28(%3)\n"
19149+ "19: "__copyuser_seg" movl 32(%4), %%eax\n"
19150+ "20: "__copyuser_seg" movl 36(%4), %%edx\n"
19151+ "21: movl %%eax, 32(%3)\n"
19152+ "22: movl %%edx, 36(%3)\n"
19153+ "23: "__copyuser_seg" movl 40(%4), %%eax\n"
19154+ "24: "__copyuser_seg" movl 44(%4), %%edx\n"
19155+ "25: movl %%eax, 40(%3)\n"
19156+ "26: movl %%edx, 44(%3)\n"
19157+ "27: "__copyuser_seg" movl 48(%4), %%eax\n"
19158+ "28: "__copyuser_seg" movl 52(%4), %%edx\n"
19159+ "29: movl %%eax, 48(%3)\n"
19160+ "30: movl %%edx, 52(%3)\n"
19161+ "31: "__copyuser_seg" movl 56(%4), %%eax\n"
19162+ "32: "__copyuser_seg" movl 60(%4), %%edx\n"
19163+ "33: movl %%eax, 56(%3)\n"
19164+ "34: movl %%edx, 60(%3)\n"
19165+ " addl $-64, %0\n"
19166+ " addl $64, %4\n"
19167+ " addl $64, %3\n"
19168+ " cmpl $63, %0\n"
19169+ " ja 1b\n"
19170+ "35: movl %0, %%eax\n"
19171+ " shrl $2, %0\n"
19172+ " andl $3, %%eax\n"
19173+ " cld\n"
19174+ "99: rep; "__copyuser_seg" movsl\n"
19175+ "36: movl %%eax, %0\n"
19176+ "37: rep; "__copyuser_seg" movsb\n"
19177+ "100:\n"
19178 ".section .fixup,\"ax\"\n"
19179 "101: lea 0(%%eax,%0,4),%0\n"
19180 " jmp 100b\n"
19181@@ -339,41 +452,41 @@ __copy_user_zeroing_intel(void *to, cons
19182 int d0, d1;
19183 __asm__ __volatile__(
19184 " .align 2,0x90\n"
19185- "0: movl 32(%4), %%eax\n"
19186+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
19187 " cmpl $67, %0\n"
19188 " jbe 2f\n"
19189- "1: movl 64(%4), %%eax\n"
19190+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
19191 " .align 2,0x90\n"
19192- "2: movl 0(%4), %%eax\n"
19193- "21: movl 4(%4), %%edx\n"
19194+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
19195+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
19196 " movl %%eax, 0(%3)\n"
19197 " movl %%edx, 4(%3)\n"
19198- "3: movl 8(%4), %%eax\n"
19199- "31: movl 12(%4),%%edx\n"
19200+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
19201+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
19202 " movl %%eax, 8(%3)\n"
19203 " movl %%edx, 12(%3)\n"
19204- "4: movl 16(%4), %%eax\n"
19205- "41: movl 20(%4), %%edx\n"
19206+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
19207+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
19208 " movl %%eax, 16(%3)\n"
19209 " movl %%edx, 20(%3)\n"
19210- "10: movl 24(%4), %%eax\n"
19211- "51: movl 28(%4), %%edx\n"
19212+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
19213+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
19214 " movl %%eax, 24(%3)\n"
19215 " movl %%edx, 28(%3)\n"
19216- "11: movl 32(%4), %%eax\n"
19217- "61: movl 36(%4), %%edx\n"
19218+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
19219+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
19220 " movl %%eax, 32(%3)\n"
19221 " movl %%edx, 36(%3)\n"
19222- "12: movl 40(%4), %%eax\n"
19223- "71: movl 44(%4), %%edx\n"
19224+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
19225+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
19226 " movl %%eax, 40(%3)\n"
19227 " movl %%edx, 44(%3)\n"
19228- "13: movl 48(%4), %%eax\n"
19229- "81: movl 52(%4), %%edx\n"
19230+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
19231+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
19232 " movl %%eax, 48(%3)\n"
19233 " movl %%edx, 52(%3)\n"
19234- "14: movl 56(%4), %%eax\n"
19235- "91: movl 60(%4), %%edx\n"
19236+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
19237+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
19238 " movl %%eax, 56(%3)\n"
19239 " movl %%edx, 60(%3)\n"
19240 " addl $-64, %0\n"
19241@@ -385,9 +498,9 @@ __copy_user_zeroing_intel(void *to, cons
19242 " shrl $2, %0\n"
19243 " andl $3, %%eax\n"
19244 " cld\n"
19245- "6: rep; movsl\n"
19246+ "6: rep; "__copyuser_seg" movsl\n"
19247 " movl %%eax,%0\n"
19248- "7: rep; movsb\n"
19249+ "7: rep; "__copyuser_seg" movsb\n"
19250 "8:\n"
19251 ".section .fixup,\"ax\"\n"
19252 "9: lea 0(%%eax,%0,4),%0\n"
19253@@ -440,41 +553,41 @@ static unsigned long __copy_user_zeroing
19254
19255 __asm__ __volatile__(
19256 " .align 2,0x90\n"
19257- "0: movl 32(%4), %%eax\n"
19258+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
19259 " cmpl $67, %0\n"
19260 " jbe 2f\n"
19261- "1: movl 64(%4), %%eax\n"
19262+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
19263 " .align 2,0x90\n"
19264- "2: movl 0(%4), %%eax\n"
19265- "21: movl 4(%4), %%edx\n"
19266+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
19267+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
19268 " movnti %%eax, 0(%3)\n"
19269 " movnti %%edx, 4(%3)\n"
19270- "3: movl 8(%4), %%eax\n"
19271- "31: movl 12(%4),%%edx\n"
19272+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
19273+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
19274 " movnti %%eax, 8(%3)\n"
19275 " movnti %%edx, 12(%3)\n"
19276- "4: movl 16(%4), %%eax\n"
19277- "41: movl 20(%4), %%edx\n"
19278+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
19279+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
19280 " movnti %%eax, 16(%3)\n"
19281 " movnti %%edx, 20(%3)\n"
19282- "10: movl 24(%4), %%eax\n"
19283- "51: movl 28(%4), %%edx\n"
19284+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
19285+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
19286 " movnti %%eax, 24(%3)\n"
19287 " movnti %%edx, 28(%3)\n"
19288- "11: movl 32(%4), %%eax\n"
19289- "61: movl 36(%4), %%edx\n"
19290+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
19291+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
19292 " movnti %%eax, 32(%3)\n"
19293 " movnti %%edx, 36(%3)\n"
19294- "12: movl 40(%4), %%eax\n"
19295- "71: movl 44(%4), %%edx\n"
19296+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
19297+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
19298 " movnti %%eax, 40(%3)\n"
19299 " movnti %%edx, 44(%3)\n"
19300- "13: movl 48(%4), %%eax\n"
19301- "81: movl 52(%4), %%edx\n"
19302+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
19303+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
19304 " movnti %%eax, 48(%3)\n"
19305 " movnti %%edx, 52(%3)\n"
19306- "14: movl 56(%4), %%eax\n"
19307- "91: movl 60(%4), %%edx\n"
19308+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
19309+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
19310 " movnti %%eax, 56(%3)\n"
19311 " movnti %%edx, 60(%3)\n"
19312 " addl $-64, %0\n"
19313@@ -487,9 +600,9 @@ static unsigned long __copy_user_zeroing
19314 " shrl $2, %0\n"
19315 " andl $3, %%eax\n"
19316 " cld\n"
19317- "6: rep; movsl\n"
19318+ "6: rep; "__copyuser_seg" movsl\n"
19319 " movl %%eax,%0\n"
19320- "7: rep; movsb\n"
19321+ "7: rep; "__copyuser_seg" movsb\n"
19322 "8:\n"
19323 ".section .fixup,\"ax\"\n"
19324 "9: lea 0(%%eax,%0,4),%0\n"
19325@@ -537,41 +650,41 @@ static unsigned long __copy_user_intel_n
19326
19327 __asm__ __volatile__(
19328 " .align 2,0x90\n"
19329- "0: movl 32(%4), %%eax\n"
19330+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
19331 " cmpl $67, %0\n"
19332 " jbe 2f\n"
19333- "1: movl 64(%4), %%eax\n"
19334+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
19335 " .align 2,0x90\n"
19336- "2: movl 0(%4), %%eax\n"
19337- "21: movl 4(%4), %%edx\n"
19338+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
19339+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
19340 " movnti %%eax, 0(%3)\n"
19341 " movnti %%edx, 4(%3)\n"
19342- "3: movl 8(%4), %%eax\n"
19343- "31: movl 12(%4),%%edx\n"
19344+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
19345+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
19346 " movnti %%eax, 8(%3)\n"
19347 " movnti %%edx, 12(%3)\n"
19348- "4: movl 16(%4), %%eax\n"
19349- "41: movl 20(%4), %%edx\n"
19350+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
19351+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
19352 " movnti %%eax, 16(%3)\n"
19353 " movnti %%edx, 20(%3)\n"
19354- "10: movl 24(%4), %%eax\n"
19355- "51: movl 28(%4), %%edx\n"
19356+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
19357+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
19358 " movnti %%eax, 24(%3)\n"
19359 " movnti %%edx, 28(%3)\n"
19360- "11: movl 32(%4), %%eax\n"
19361- "61: movl 36(%4), %%edx\n"
19362+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
19363+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
19364 " movnti %%eax, 32(%3)\n"
19365 " movnti %%edx, 36(%3)\n"
19366- "12: movl 40(%4), %%eax\n"
19367- "71: movl 44(%4), %%edx\n"
19368+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
19369+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
19370 " movnti %%eax, 40(%3)\n"
19371 " movnti %%edx, 44(%3)\n"
19372- "13: movl 48(%4), %%eax\n"
19373- "81: movl 52(%4), %%edx\n"
19374+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
19375+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
19376 " movnti %%eax, 48(%3)\n"
19377 " movnti %%edx, 52(%3)\n"
19378- "14: movl 56(%4), %%eax\n"
19379- "91: movl 60(%4), %%edx\n"
19380+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
19381+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
19382 " movnti %%eax, 56(%3)\n"
19383 " movnti %%edx, 60(%3)\n"
19384 " addl $-64, %0\n"
19385@@ -584,9 +697,9 @@ static unsigned long __copy_user_intel_n
19386 " shrl $2, %0\n"
19387 " andl $3, %%eax\n"
19388 " cld\n"
19389- "6: rep; movsl\n"
19390+ "6: rep; "__copyuser_seg" movsl\n"
19391 " movl %%eax,%0\n"
19392- "7: rep; movsb\n"
19393+ "7: rep; "__copyuser_seg" movsb\n"
19394 "8:\n"
19395 ".section .fixup,\"ax\"\n"
19396 "9: lea 0(%%eax,%0,4),%0\n"
19397@@ -629,32 +742,36 @@ static unsigned long __copy_user_intel_n
19398 */
19399 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
19400 unsigned long size);
19401-unsigned long __copy_user_intel(void __user *to, const void *from,
19402+unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
19403+ unsigned long size);
19404+unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
19405 unsigned long size);
19406 unsigned long __copy_user_zeroing_intel_nocache(void *to,
19407 const void __user *from, unsigned long size);
19408 #endif /* CONFIG_X86_INTEL_USERCOPY */
19409
19410 /* Generic arbitrary sized copy. */
19411-#define __copy_user(to, from, size) \
19412+#define __copy_user(to, from, size, prefix, set, restore) \
19413 do { \
19414 int __d0, __d1, __d2; \
19415 __asm__ __volatile__( \
19416+ set \
19417 " cmp $7,%0\n" \
19418 " jbe 1f\n" \
19419 " movl %1,%0\n" \
19420 " negl %0\n" \
19421 " andl $7,%0\n" \
19422 " subl %0,%3\n" \
19423- "4: rep; movsb\n" \
19424+ "4: rep; "prefix"movsb\n" \
19425 " movl %3,%0\n" \
19426 " shrl $2,%0\n" \
19427 " andl $3,%3\n" \
19428 " .align 2,0x90\n" \
19429- "0: rep; movsl\n" \
19430+ "0: rep; "prefix"movsl\n" \
19431 " movl %3,%0\n" \
19432- "1: rep; movsb\n" \
19433+ "1: rep; "prefix"movsb\n" \
19434 "2:\n" \
19435+ restore \
19436 ".section .fixup,\"ax\"\n" \
19437 "5: addl %3,%0\n" \
19438 " jmp 2b\n" \
19439@@ -682,14 +799,14 @@ do { \
19440 " negl %0\n" \
19441 " andl $7,%0\n" \
19442 " subl %0,%3\n" \
19443- "4: rep; movsb\n" \
19444+ "4: rep; "__copyuser_seg"movsb\n" \
19445 " movl %3,%0\n" \
19446 " shrl $2,%0\n" \
19447 " andl $3,%3\n" \
19448 " .align 2,0x90\n" \
19449- "0: rep; movsl\n" \
19450+ "0: rep; "__copyuser_seg"movsl\n" \
19451 " movl %3,%0\n" \
19452- "1: rep; movsb\n" \
19453+ "1: rep; "__copyuser_seg"movsb\n" \
19454 "2:\n" \
19455 ".section .fixup,\"ax\"\n" \
19456 "5: addl %3,%0\n" \
19457@@ -775,9 +892,9 @@ survive:
19458 }
19459 #endif
19460 if (movsl_is_ok(to, from, n))
19461- __copy_user(to, from, n);
19462+ __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
19463 else
19464- n = __copy_user_intel(to, from, n);
19465+ n = __generic_copy_to_user_intel(to, from, n);
19466 return n;
19467 }
19468 EXPORT_SYMBOL(__copy_to_user_ll);
19469@@ -797,10 +914,9 @@ unsigned long __copy_from_user_ll_nozero
19470 unsigned long n)
19471 {
19472 if (movsl_is_ok(to, from, n))
19473- __copy_user(to, from, n);
19474+ __copy_user(to, from, n, __copyuser_seg, "", "");
19475 else
19476- n = __copy_user_intel((void __user *)to,
19477- (const void *)from, n);
19478+ n = __generic_copy_from_user_intel(to, from, n);
19479 return n;
19480 }
19481 EXPORT_SYMBOL(__copy_from_user_ll_nozero);
19482@@ -827,59 +943,38 @@ unsigned long __copy_from_user_ll_nocach
19483 if (n > 64 && cpu_has_xmm2)
19484 n = __copy_user_intel_nocache(to, from, n);
19485 else
19486- __copy_user(to, from, n);
19487+ __copy_user(to, from, n, __copyuser_seg, "", "");
19488 #else
19489- __copy_user(to, from, n);
19490+ __copy_user(to, from, n, __copyuser_seg, "", "");
19491 #endif
19492 return n;
19493 }
19494 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
19495
19496-/**
19497- * copy_to_user: - Copy a block of data into user space.
19498- * @to: Destination address, in user space.
19499- * @from: Source address, in kernel space.
19500- * @n: Number of bytes to copy.
19501- *
19502- * Context: User context only. This function may sleep.
19503- *
19504- * Copy data from kernel space to user space.
19505- *
19506- * Returns number of bytes that could not be copied.
19507- * On success, this will be zero.
19508- */
19509-unsigned long
19510-copy_to_user(void __user *to, const void *from, unsigned long n)
19511+#ifdef CONFIG_PAX_MEMORY_UDEREF
19512+void __set_fs(mm_segment_t x)
19513 {
19514- if (access_ok(VERIFY_WRITE, to, n))
19515- n = __copy_to_user(to, from, n);
19516- return n;
19517+ switch (x.seg) {
19518+ case 0:
19519+ loadsegment(gs, 0);
19520+ break;
19521+ case TASK_SIZE_MAX:
19522+ loadsegment(gs, __USER_DS);
19523+ break;
19524+ case -1UL:
19525+ loadsegment(gs, __KERNEL_DS);
19526+ break;
19527+ default:
19528+ BUG();
19529+ }
19530+ return;
19531 }
19532-EXPORT_SYMBOL(copy_to_user);
19533+EXPORT_SYMBOL(__set_fs);
19534
19535-/**
19536- * copy_from_user: - Copy a block of data from user space.
19537- * @to: Destination address, in kernel space.
19538- * @from: Source address, in user space.
19539- * @n: Number of bytes to copy.
19540- *
19541- * Context: User context only. This function may sleep.
19542- *
19543- * Copy data from user space to kernel space.
19544- *
19545- * Returns number of bytes that could not be copied.
19546- * On success, this will be zero.
19547- *
19548- * If some data could not be copied, this function will pad the copied
19549- * data to the requested size using zero bytes.
19550- */
19551-unsigned long
19552-copy_from_user(void *to, const void __user *from, unsigned long n)
19553+void set_fs(mm_segment_t x)
19554 {
19555- if (access_ok(VERIFY_READ, from, n))
19556- n = __copy_from_user(to, from, n);
19557- else
19558- memset(to, 0, n);
19559- return n;
19560+ current_thread_info()->addr_limit = x;
19561+ __set_fs(x);
19562 }
19563-EXPORT_SYMBOL(copy_from_user);
19564+EXPORT_SYMBOL(set_fs);
19565+#endif
19566diff -urNp linux-2.6.32.41/arch/x86/lib/usercopy_64.c linux-2.6.32.41/arch/x86/lib/usercopy_64.c
19567--- linux-2.6.32.41/arch/x86/lib/usercopy_64.c 2011-03-27 14:31:47.000000000 -0400
19568+++ linux-2.6.32.41/arch/x86/lib/usercopy_64.c 2011-05-04 17:56:20.000000000 -0400
19569@@ -42,6 +42,12 @@ long
19570 __strncpy_from_user(char *dst, const char __user *src, long count)
19571 {
19572 long res;
19573+
19574+#ifdef CONFIG_PAX_MEMORY_UDEREF
19575+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
19576+ src += PAX_USER_SHADOW_BASE;
19577+#endif
19578+
19579 __do_strncpy_from_user(dst, src, count, res);
19580 return res;
19581 }
19582@@ -65,6 +71,12 @@ unsigned long __clear_user(void __user *
19583 {
19584 long __d0;
19585 might_fault();
19586+
19587+#ifdef CONFIG_PAX_MEMORY_UDEREF
19588+ if ((unsigned long)addr < PAX_USER_SHADOW_BASE)
19589+ addr += PAX_USER_SHADOW_BASE;
19590+#endif
19591+
19592 /* no memory constraint because it doesn't change any memory gcc knows
19593 about */
19594 asm volatile(
19595@@ -151,10 +163,18 @@ EXPORT_SYMBOL(strlen_user);
19596
19597 unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
19598 {
19599- if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
19600+ if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
19601+
19602+#ifdef CONFIG_PAX_MEMORY_UDEREF
19603+ if ((unsigned long)to < PAX_USER_SHADOW_BASE)
19604+ to += PAX_USER_SHADOW_BASE;
19605+ if ((unsigned long)from < PAX_USER_SHADOW_BASE)
19606+ from += PAX_USER_SHADOW_BASE;
19607+#endif
19608+
19609 return copy_user_generic((__force void *)to, (__force void *)from, len);
19610- }
19611- return len;
19612+ }
19613+ return len;
19614 }
19615 EXPORT_SYMBOL(copy_in_user);
19616
19617diff -urNp linux-2.6.32.41/arch/x86/Makefile linux-2.6.32.41/arch/x86/Makefile
19618--- linux-2.6.32.41/arch/x86/Makefile 2011-03-27 14:31:47.000000000 -0400
19619+++ linux-2.6.32.41/arch/x86/Makefile 2011-04-17 15:56:46.000000000 -0400
19620@@ -189,3 +189,12 @@ define archhelp
19621 echo ' FDARGS="..." arguments for the booted kernel'
19622 echo ' FDINITRD=file initrd for the booted kernel'
19623 endef
19624+
19625+define OLD_LD
19626+
19627+*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
19628+*** Please upgrade your binutils to 2.18 or newer
19629+endef
19630+
19631+archprepare:
19632+ $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
19633diff -urNp linux-2.6.32.41/arch/x86/mm/extable.c linux-2.6.32.41/arch/x86/mm/extable.c
19634--- linux-2.6.32.41/arch/x86/mm/extable.c 2011-03-27 14:31:47.000000000 -0400
19635+++ linux-2.6.32.41/arch/x86/mm/extable.c 2011-04-17 15:56:46.000000000 -0400
19636@@ -1,14 +1,71 @@
19637 #include <linux/module.h>
19638 #include <linux/spinlock.h>
19639+#include <linux/sort.h>
19640 #include <asm/uaccess.h>
19641+#include <asm/pgtable.h>
19642
19643+/*
19644+ * The exception table needs to be sorted so that the binary
19645+ * search that we use to find entries in it works properly.
19646+ * This is used both for the kernel exception table and for
19647+ * the exception tables of modules that get loaded.
19648+ */
19649+static int cmp_ex(const void *a, const void *b)
19650+{
19651+ const struct exception_table_entry *x = a, *y = b;
19652+
19653+ /* avoid overflow */
19654+ if (x->insn > y->insn)
19655+ return 1;
19656+ if (x->insn < y->insn)
19657+ return -1;
19658+ return 0;
19659+}
19660+
19661+static void swap_ex(void *a, void *b, int size)
19662+{
19663+ struct exception_table_entry t, *x = a, *y = b;
19664+
19665+ t = *x;
19666+
19667+ pax_open_kernel();
19668+ *x = *y;
19669+ *y = t;
19670+ pax_close_kernel();
19671+}
19672+
19673+void sort_extable(struct exception_table_entry *start,
19674+ struct exception_table_entry *finish)
19675+{
19676+ sort(start, finish - start, sizeof(struct exception_table_entry),
19677+ cmp_ex, swap_ex);
19678+}
19679+
19680+#ifdef CONFIG_MODULES
19681+/*
19682+ * If the exception table is sorted, any referring to the module init
19683+ * will be at the beginning or the end.
19684+ */
19685+void trim_init_extable(struct module *m)
19686+{
19687+ /*trim the beginning*/
19688+ while (m->num_exentries && within_module_init(m->extable[0].insn, m)) {
19689+ m->extable++;
19690+ m->num_exentries--;
19691+ }
19692+ /*trim the end*/
19693+ while (m->num_exentries &&
19694+ within_module_init(m->extable[m->num_exentries-1].insn, m))
19695+ m->num_exentries--;
19696+}
19697+#endif /* CONFIG_MODULES */
19698
19699 int fixup_exception(struct pt_regs *regs)
19700 {
19701 const struct exception_table_entry *fixup;
19702
19703 #ifdef CONFIG_PNPBIOS
19704- if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
19705+ if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
19706 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
19707 extern u32 pnp_bios_is_utter_crap;
19708 pnp_bios_is_utter_crap = 1;
19709diff -urNp linux-2.6.32.41/arch/x86/mm/fault.c linux-2.6.32.41/arch/x86/mm/fault.c
19710--- linux-2.6.32.41/arch/x86/mm/fault.c 2011-03-27 14:31:47.000000000 -0400
19711+++ linux-2.6.32.41/arch/x86/mm/fault.c 2011-06-06 17:35:16.000000000 -0400
19712@@ -11,10 +11,19 @@
19713 #include <linux/kprobes.h> /* __kprobes, ... */
19714 #include <linux/mmiotrace.h> /* kmmio_handler, ... */
19715 #include <linux/perf_event.h> /* perf_sw_event */
19716+#include <linux/unistd.h>
19717+#include <linux/compiler.h>
19718
19719 #include <asm/traps.h> /* dotraplinkage, ... */
19720 #include <asm/pgalloc.h> /* pgd_*(), ... */
19721 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
19722+#include <asm/vsyscall.h>
19723+#include <asm/tlbflush.h>
19724+
19725+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19726+#include <asm/stacktrace.h>
19727+#include "../kernel/dumpstack.h"
19728+#endif
19729
19730 /*
19731 * Page fault error code bits:
19732@@ -51,7 +60,7 @@ static inline int notify_page_fault(stru
19733 int ret = 0;
19734
19735 /* kprobe_running() needs smp_processor_id() */
19736- if (kprobes_built_in() && !user_mode_vm(regs)) {
19737+ if (kprobes_built_in() && !user_mode(regs)) {
19738 preempt_disable();
19739 if (kprobe_running() && kprobe_fault_handler(regs, 14))
19740 ret = 1;
19741@@ -112,7 +121,10 @@ check_prefetch_opcode(struct pt_regs *re
19742 return !instr_lo || (instr_lo>>1) == 1;
19743 case 0x00:
19744 /* Prefetch instruction is 0x0F0D or 0x0F18 */
19745- if (probe_kernel_address(instr, opcode))
19746+ if (user_mode(regs)) {
19747+ if (__copy_from_user_inatomic(&opcode, (__force unsigned char __user *)(instr), 1))
19748+ return 0;
19749+ } else if (probe_kernel_address(instr, opcode))
19750 return 0;
19751
19752 *prefetch = (instr_lo == 0xF) &&
19753@@ -146,7 +158,10 @@ is_prefetch(struct pt_regs *regs, unsign
19754 while (instr < max_instr) {
19755 unsigned char opcode;
19756
19757- if (probe_kernel_address(instr, opcode))
19758+ if (user_mode(regs)) {
19759+ if (__copy_from_user_inatomic(&opcode, (__force unsigned char __user *)(instr), 1))
19760+ break;
19761+ } else if (probe_kernel_address(instr, opcode))
19762 break;
19763
19764 instr++;
19765@@ -172,6 +187,30 @@ force_sig_info_fault(int si_signo, int s
19766 force_sig_info(si_signo, &info, tsk);
19767 }
19768
19769+#ifdef CONFIG_PAX_EMUTRAMP
19770+static int pax_handle_fetch_fault(struct pt_regs *regs);
19771+#endif
19772+
19773+#ifdef CONFIG_PAX_PAGEEXEC
19774+static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
19775+{
19776+ pgd_t *pgd;
19777+ pud_t *pud;
19778+ pmd_t *pmd;
19779+
19780+ pgd = pgd_offset(mm, address);
19781+ if (!pgd_present(*pgd))
19782+ return NULL;
19783+ pud = pud_offset(pgd, address);
19784+ if (!pud_present(*pud))
19785+ return NULL;
19786+ pmd = pmd_offset(pud, address);
19787+ if (!pmd_present(*pmd))
19788+ return NULL;
19789+ return pmd;
19790+}
19791+#endif
19792+
19793 DEFINE_SPINLOCK(pgd_lock);
19794 LIST_HEAD(pgd_list);
19795
19796@@ -224,11 +263,24 @@ void vmalloc_sync_all(void)
19797 address += PMD_SIZE) {
19798
19799 unsigned long flags;
19800+
19801+#ifdef CONFIG_PAX_PER_CPU_PGD
19802+ unsigned long cpu;
19803+#else
19804 struct page *page;
19805+#endif
19806
19807 spin_lock_irqsave(&pgd_lock, flags);
19808+
19809+#ifdef CONFIG_PAX_PER_CPU_PGD
19810+ for (cpu = 0; cpu < NR_CPUS; ++cpu) {
19811+ pgd_t *pgd = get_cpu_pgd(cpu);
19812+#else
19813 list_for_each_entry(page, &pgd_list, lru) {
19814- if (!vmalloc_sync_one(page_address(page), address))
19815+ pgd_t *pgd = page_address(page);
19816+#endif
19817+
19818+ if (!vmalloc_sync_one(pgd, address))
19819 break;
19820 }
19821 spin_unlock_irqrestore(&pgd_lock, flags);
19822@@ -258,6 +310,11 @@ static noinline int vmalloc_fault(unsign
19823 * an interrupt in the middle of a task switch..
19824 */
19825 pgd_paddr = read_cr3();
19826+
19827+#ifdef CONFIG_PAX_PER_CPU_PGD
19828+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (pgd_paddr & PHYSICAL_PAGE_MASK));
19829+#endif
19830+
19831 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
19832 if (!pmd_k)
19833 return -1;
19834@@ -332,15 +389,27 @@ void vmalloc_sync_all(void)
19835
19836 const pgd_t *pgd_ref = pgd_offset_k(address);
19837 unsigned long flags;
19838+
19839+#ifdef CONFIG_PAX_PER_CPU_PGD
19840+ unsigned long cpu;
19841+#else
19842 struct page *page;
19843+#endif
19844
19845 if (pgd_none(*pgd_ref))
19846 continue;
19847
19848 spin_lock_irqsave(&pgd_lock, flags);
19849+
19850+#ifdef CONFIG_PAX_PER_CPU_PGD
19851+ for (cpu = 0; cpu < NR_CPUS; ++cpu) {
19852+ pgd_t *pgd = pgd_offset_cpu(cpu, address);
19853+#else
19854 list_for_each_entry(page, &pgd_list, lru) {
19855 pgd_t *pgd;
19856 pgd = (pgd_t *)page_address(page) + pgd_index(address);
19857+#endif
19858+
19859 if (pgd_none(*pgd))
19860 set_pgd(pgd, *pgd_ref);
19861 else
19862@@ -373,7 +442,14 @@ static noinline int vmalloc_fault(unsign
19863 * happen within a race in page table update. In the later
19864 * case just flush:
19865 */
19866+
19867+#ifdef CONFIG_PAX_PER_CPU_PGD
19868+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (read_cr3() & PHYSICAL_PAGE_MASK));
19869+ pgd = pgd_offset_cpu(smp_processor_id(), address);
19870+#else
19871 pgd = pgd_offset(current->active_mm, address);
19872+#endif
19873+
19874 pgd_ref = pgd_offset_k(address);
19875 if (pgd_none(*pgd_ref))
19876 return -1;
19877@@ -535,7 +611,7 @@ static int is_errata93(struct pt_regs *r
19878 static int is_errata100(struct pt_regs *regs, unsigned long address)
19879 {
19880 #ifdef CONFIG_X86_64
19881- if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
19882+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
19883 return 1;
19884 #endif
19885 return 0;
19886@@ -562,7 +638,7 @@ static int is_f00f_bug(struct pt_regs *r
19887 }
19888
19889 static const char nx_warning[] = KERN_CRIT
19890-"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
19891+"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
19892
19893 static void
19894 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
19895@@ -571,15 +647,26 @@ show_fault_oops(struct pt_regs *regs, un
19896 if (!oops_may_print())
19897 return;
19898
19899- if (error_code & PF_INSTR) {
19900+ if (nx_enabled && (error_code & PF_INSTR)) {
19901 unsigned int level;
19902
19903 pte_t *pte = lookup_address(address, &level);
19904
19905 if (pte && pte_present(*pte) && !pte_exec(*pte))
19906- printk(nx_warning, current_uid());
19907+ printk(nx_warning, current_uid(), current->comm, task_pid_nr(current));
19908 }
19909
19910+#ifdef CONFIG_PAX_KERNEXEC
19911+ if (init_mm.start_code <= address && address < init_mm.end_code) {
19912+ if (current->signal->curr_ip)
19913+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
19914+ &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
19915+ else
19916+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
19917+ current->comm, task_pid_nr(current), current_uid(), current_euid());
19918+ }
19919+#endif
19920+
19921 printk(KERN_ALERT "BUG: unable to handle kernel ");
19922 if (address < PAGE_SIZE)
19923 printk(KERN_CONT "NULL pointer dereference");
19924@@ -704,6 +791,68 @@ __bad_area_nosemaphore(struct pt_regs *r
19925 unsigned long address, int si_code)
19926 {
19927 struct task_struct *tsk = current;
19928+ struct mm_struct *mm = tsk->mm;
19929+
19930+#ifdef CONFIG_X86_64
19931+ if (mm && (error_code & PF_INSTR) && mm->context.vdso) {
19932+ if (regs->ip == (unsigned long)vgettimeofday) {
19933+ regs->ip = (unsigned long)VDSO64_SYMBOL(mm->context.vdso, fallback_gettimeofday);
19934+ return;
19935+ } else if (regs->ip == (unsigned long)vtime) {
19936+ regs->ip = (unsigned long)VDSO64_SYMBOL(mm->context.vdso, fallback_time);
19937+ return;
19938+ } else if (regs->ip == (unsigned long)vgetcpu) {
19939+ regs->ip = (unsigned long)VDSO64_SYMBOL(mm->context.vdso, getcpu);
19940+ return;
19941+ }
19942+ }
19943+#endif
19944+
19945+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
19946+ if (mm && (error_code & PF_USER)) {
19947+ unsigned long ip = regs->ip;
19948+
19949+ if (v8086_mode(regs))
19950+ ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
19951+
19952+ /*
19953+ * It's possible to have interrupts off here:
19954+ */
19955+ local_irq_enable();
19956+
19957+#ifdef CONFIG_PAX_PAGEEXEC
19958+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) &&
19959+ ((nx_enabled && (error_code & PF_INSTR)) || (!(error_code & (PF_PROT | PF_WRITE)) && ip == address))) {
19960+
19961+#ifdef CONFIG_PAX_EMUTRAMP
19962+ switch (pax_handle_fetch_fault(regs)) {
19963+ case 2:
19964+ return;
19965+ }
19966+#endif
19967+
19968+ pax_report_fault(regs, (void *)ip, (void *)regs->sp);
19969+ do_group_exit(SIGKILL);
19970+ }
19971+#endif
19972+
19973+#ifdef CONFIG_PAX_SEGMEXEC
19974+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && !(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address)) {
19975+
19976+#ifdef CONFIG_PAX_EMUTRAMP
19977+ switch (pax_handle_fetch_fault(regs)) {
19978+ case 2:
19979+ return;
19980+ }
19981+#endif
19982+
19983+ pax_report_fault(regs, (void *)ip, (void *)regs->sp);
19984+ do_group_exit(SIGKILL);
19985+ }
19986+#endif
19987+
19988+ }
19989+#endif
19990
19991 /* User mode accesses just cause a SIGSEGV */
19992 if (error_code & PF_USER) {
19993@@ -857,6 +1006,99 @@ static int spurious_fault_check(unsigned
19994 return 1;
19995 }
19996
19997+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
19998+static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
19999+{
20000+ pte_t *pte;
20001+ pmd_t *pmd;
20002+ spinlock_t *ptl;
20003+ unsigned char pte_mask;
20004+
20005+ if (nx_enabled || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
20006+ !(mm->pax_flags & MF_PAX_PAGEEXEC))
20007+ return 0;
20008+
20009+ /* PaX: it's our fault, let's handle it if we can */
20010+
20011+ /* PaX: take a look at read faults before acquiring any locks */
20012+ if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
20013+ /* instruction fetch attempt from a protected page in user mode */
20014+ up_read(&mm->mmap_sem);
20015+
20016+#ifdef CONFIG_PAX_EMUTRAMP
20017+ switch (pax_handle_fetch_fault(regs)) {
20018+ case 2:
20019+ return 1;
20020+ }
20021+#endif
20022+
20023+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
20024+ do_group_exit(SIGKILL);
20025+ }
20026+
20027+ pmd = pax_get_pmd(mm, address);
20028+ if (unlikely(!pmd))
20029+ return 0;
20030+
20031+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
20032+ if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
20033+ pte_unmap_unlock(pte, ptl);
20034+ return 0;
20035+ }
20036+
20037+ if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
20038+ /* write attempt to a protected page in user mode */
20039+ pte_unmap_unlock(pte, ptl);
20040+ return 0;
20041+ }
20042+
20043+#ifdef CONFIG_SMP
20044+ if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
20045+#else
20046+ if (likely(address > get_limit(regs->cs)))
20047+#endif
20048+ {
20049+ set_pte(pte, pte_mkread(*pte));
20050+ __flush_tlb_one(address);
20051+ pte_unmap_unlock(pte, ptl);
20052+ up_read(&mm->mmap_sem);
20053+ return 1;
20054+ }
20055+
20056+ pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
20057+
20058+ /*
20059+ * PaX: fill DTLB with user rights and retry
20060+ */
20061+ __asm__ __volatile__ (
20062+ "orb %2,(%1)\n"
20063+#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
20064+/*
20065+ * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
20066+ * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
20067+ * page fault when examined during a TLB load attempt. this is true not only
20068+ * for PTEs holding a non-present entry but also present entries that will
20069+ * raise a page fault (such as those set up by PaX, or the copy-on-write
20070+ * mechanism). in effect it means that we do *not* need to flush the TLBs
20071+ * for our target pages since their PTEs are simply not in the TLBs at all.
20072+
20073+ * the best thing in omitting it is that we gain around 15-20% speed in the
20074+ * fast path of the page fault handler and can get rid of tracing since we
20075+ * can no longer flush unintended entries.
20076+ */
20077+ "invlpg (%0)\n"
20078+#endif
20079+ __copyuser_seg"testb $0,(%0)\n"
20080+ "xorb %3,(%1)\n"
20081+ :
20082+ : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
20083+ : "memory", "cc");
20084+ pte_unmap_unlock(pte, ptl);
20085+ up_read(&mm->mmap_sem);
20086+ return 1;
20087+}
20088+#endif
20089+
20090 /*
20091 * Handle a spurious fault caused by a stale TLB entry.
20092 *
20093@@ -923,6 +1165,9 @@ int show_unhandled_signals = 1;
20094 static inline int
20095 access_error(unsigned long error_code, int write, struct vm_area_struct *vma)
20096 {
20097+ if (nx_enabled && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
20098+ return 1;
20099+
20100 if (write) {
20101 /* write, present and write, not present: */
20102 if (unlikely(!(vma->vm_flags & VM_WRITE)))
20103@@ -956,17 +1201,31 @@ do_page_fault(struct pt_regs *regs, unsi
20104 {
20105 struct vm_area_struct *vma;
20106 struct task_struct *tsk;
20107- unsigned long address;
20108 struct mm_struct *mm;
20109 int write;
20110 int fault;
20111
20112+ /* Get the faulting address: */
20113+ unsigned long address = read_cr2();
20114+
20115+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
20116+ if (!user_mode(regs) && address < 2 * PAX_USER_SHADOW_BASE) {
20117+ if (!search_exception_tables(regs->ip)) {
20118+ bad_area_nosemaphore(regs, error_code, address);
20119+ return;
20120+ }
20121+ if (address < PAX_USER_SHADOW_BASE) {
20122+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
20123+ printk(KERN_ERR "PAX: faulting IP: %pA\n", (void *)regs->ip);
20124+ show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
20125+ } else
20126+ address -= PAX_USER_SHADOW_BASE;
20127+ }
20128+#endif
20129+
20130 tsk = current;
20131 mm = tsk->mm;
20132
20133- /* Get the faulting address: */
20134- address = read_cr2();
20135-
20136 /*
20137 * Detect and handle instructions that would cause a page fault for
20138 * both a tracked kernel page and a userspace page.
20139@@ -1026,7 +1285,7 @@ do_page_fault(struct pt_regs *regs, unsi
20140 * User-mode registers count as a user access even for any
20141 * potential system fault or CPU buglet:
20142 */
20143- if (user_mode_vm(regs)) {
20144+ if (user_mode(regs)) {
20145 local_irq_enable();
20146 error_code |= PF_USER;
20147 } else {
20148@@ -1080,6 +1339,11 @@ do_page_fault(struct pt_regs *regs, unsi
20149 might_sleep();
20150 }
20151
20152+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
20153+ if (pax_handle_pageexec_fault(regs, mm, address, error_code))
20154+ return;
20155+#endif
20156+
20157 vma = find_vma(mm, address);
20158 if (unlikely(!vma)) {
20159 bad_area(regs, error_code, address);
20160@@ -1091,18 +1355,24 @@ do_page_fault(struct pt_regs *regs, unsi
20161 bad_area(regs, error_code, address);
20162 return;
20163 }
20164- if (error_code & PF_USER) {
20165- /*
20166- * Accessing the stack below %sp is always a bug.
20167- * The large cushion allows instructions like enter
20168- * and pusha to work. ("enter $65535, $31" pushes
20169- * 32 pointers and then decrements %sp by 65535.)
20170- */
20171- if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
20172- bad_area(regs, error_code, address);
20173- return;
20174- }
20175+ /*
20176+ * Accessing the stack below %sp is always a bug.
20177+ * The large cushion allows instructions like enter
20178+ * and pusha to work. ("enter $65535, $31" pushes
20179+ * 32 pointers and then decrements %sp by 65535.)
20180+ */
20181+ if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
20182+ bad_area(regs, error_code, address);
20183+ return;
20184+ }
20185+
20186+#ifdef CONFIG_PAX_SEGMEXEC
20187+ if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
20188+ bad_area(regs, error_code, address);
20189+ return;
20190 }
20191+#endif
20192+
20193 if (unlikely(expand_stack(vma, address))) {
20194 bad_area(regs, error_code, address);
20195 return;
20196@@ -1146,3 +1416,199 @@ good_area:
20197
20198 up_read(&mm->mmap_sem);
20199 }
20200+
20201+#ifdef CONFIG_PAX_EMUTRAMP
20202+static int pax_handle_fetch_fault_32(struct pt_regs *regs)
20203+{
20204+ int err;
20205+
20206+ do { /* PaX: gcc trampoline emulation #1 */
20207+ unsigned char mov1, mov2;
20208+ unsigned short jmp;
20209+ unsigned int addr1, addr2;
20210+
20211+#ifdef CONFIG_X86_64
20212+ if ((regs->ip + 11) >> 32)
20213+ break;
20214+#endif
20215+
20216+ err = get_user(mov1, (unsigned char __user *)regs->ip);
20217+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
20218+ err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
20219+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
20220+ err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
20221+
20222+ if (err)
20223+ break;
20224+
20225+ if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
20226+ regs->cx = addr1;
20227+ regs->ax = addr2;
20228+ regs->ip = addr2;
20229+ return 2;
20230+ }
20231+ } while (0);
20232+
20233+ do { /* PaX: gcc trampoline emulation #2 */
20234+ unsigned char mov, jmp;
20235+ unsigned int addr1, addr2;
20236+
20237+#ifdef CONFIG_X86_64
20238+ if ((regs->ip + 9) >> 32)
20239+ break;
20240+#endif
20241+
20242+ err = get_user(mov, (unsigned char __user *)regs->ip);
20243+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
20244+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
20245+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
20246+
20247+ if (err)
20248+ break;
20249+
20250+ if (mov == 0xB9 && jmp == 0xE9) {
20251+ regs->cx = addr1;
20252+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
20253+ return 2;
20254+ }
20255+ } while (0);
20256+
20257+ return 1; /* PaX in action */
20258+}
20259+
20260+#ifdef CONFIG_X86_64
20261+static int pax_handle_fetch_fault_64(struct pt_regs *regs)
20262+{
20263+ int err;
20264+
20265+ do { /* PaX: gcc trampoline emulation #1 */
20266+ unsigned short mov1, mov2, jmp1;
20267+ unsigned char jmp2;
20268+ unsigned int addr1;
20269+ unsigned long addr2;
20270+
20271+ err = get_user(mov1, (unsigned short __user *)regs->ip);
20272+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
20273+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
20274+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
20275+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
20276+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
20277+
20278+ if (err)
20279+ break;
20280+
20281+ if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
20282+ regs->r11 = addr1;
20283+ regs->r10 = addr2;
20284+ regs->ip = addr1;
20285+ return 2;
20286+ }
20287+ } while (0);
20288+
20289+ do { /* PaX: gcc trampoline emulation #2 */
20290+ unsigned short mov1, mov2, jmp1;
20291+ unsigned char jmp2;
20292+ unsigned long addr1, addr2;
20293+
20294+ err = get_user(mov1, (unsigned short __user *)regs->ip);
20295+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
20296+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
20297+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
20298+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
20299+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
20300+
20301+ if (err)
20302+ break;
20303+
20304+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
20305+ regs->r11 = addr1;
20306+ regs->r10 = addr2;
20307+ regs->ip = addr1;
20308+ return 2;
20309+ }
20310+ } while (0);
20311+
20312+ return 1; /* PaX in action */
20313+}
20314+#endif
20315+
20316+/*
20317+ * PaX: decide what to do with offenders (regs->ip = fault address)
20318+ *
20319+ * returns 1 when task should be killed
20320+ * 2 when gcc trampoline was detected
20321+ */
20322+static int pax_handle_fetch_fault(struct pt_regs *regs)
20323+{
20324+ if (v8086_mode(regs))
20325+ return 1;
20326+
20327+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
20328+ return 1;
20329+
20330+#ifdef CONFIG_X86_32
20331+ return pax_handle_fetch_fault_32(regs);
20332+#else
20333+ if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
20334+ return pax_handle_fetch_fault_32(regs);
20335+ else
20336+ return pax_handle_fetch_fault_64(regs);
20337+#endif
20338+}
20339+#endif
20340+
20341+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
20342+void pax_report_insns(void *pc, void *sp)
20343+{
20344+ long i;
20345+
20346+ printk(KERN_ERR "PAX: bytes at PC: ");
20347+ for (i = 0; i < 20; i++) {
20348+ unsigned char c;
20349+ if (get_user(c, (__force unsigned char __user *)pc+i))
20350+ printk(KERN_CONT "?? ");
20351+ else
20352+ printk(KERN_CONT "%02x ", c);
20353+ }
20354+ printk("\n");
20355+
20356+ printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
20357+ for (i = -1; i < 80 / (long)sizeof(long); i++) {
20358+ unsigned long c;
20359+ if (get_user(c, (__force unsigned long __user *)sp+i))
20360+#ifdef CONFIG_X86_32
20361+ printk(KERN_CONT "???????? ");
20362+#else
20363+ printk(KERN_CONT "???????????????? ");
20364+#endif
20365+ else
20366+ printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
20367+ }
20368+ printk("\n");
20369+}
20370+#endif
20371+
20372+/**
20373+ * probe_kernel_write(): safely attempt to write to a location
20374+ * @dst: address to write to
20375+ * @src: pointer to the data that shall be written
20376+ * @size: size of the data chunk
20377+ *
20378+ * Safely write to address @dst from the buffer at @src. If a kernel fault
20379+ * happens, handle that and return -EFAULT.
20380+ */
20381+long notrace probe_kernel_write(void *dst, const void *src, size_t size)
20382+{
20383+ long ret;
20384+ mm_segment_t old_fs = get_fs();
20385+
20386+ set_fs(KERNEL_DS);
20387+ pagefault_disable();
20388+ pax_open_kernel();
20389+ ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
20390+ pax_close_kernel();
20391+ pagefault_enable();
20392+ set_fs(old_fs);
20393+
20394+ return ret ? -EFAULT : 0;
20395+}
20396diff -urNp linux-2.6.32.41/arch/x86/mm/gup.c linux-2.6.32.41/arch/x86/mm/gup.c
20397--- linux-2.6.32.41/arch/x86/mm/gup.c 2011-03-27 14:31:47.000000000 -0400
20398+++ linux-2.6.32.41/arch/x86/mm/gup.c 2011-04-17 15:56:46.000000000 -0400
20399@@ -237,7 +237,7 @@ int __get_user_pages_fast(unsigned long
20400 addr = start;
20401 len = (unsigned long) nr_pages << PAGE_SHIFT;
20402 end = start + len;
20403- if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
20404+ if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
20405 (void __user *)start, len)))
20406 return 0;
20407
20408diff -urNp linux-2.6.32.41/arch/x86/mm/highmem_32.c linux-2.6.32.41/arch/x86/mm/highmem_32.c
20409--- linux-2.6.32.41/arch/x86/mm/highmem_32.c 2011-03-27 14:31:47.000000000 -0400
20410+++ linux-2.6.32.41/arch/x86/mm/highmem_32.c 2011-04-17 15:56:46.000000000 -0400
20411@@ -43,7 +43,10 @@ void *kmap_atomic_prot(struct page *page
20412 idx = type + KM_TYPE_NR*smp_processor_id();
20413 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
20414 BUG_ON(!pte_none(*(kmap_pte-idx)));
20415+
20416+ pax_open_kernel();
20417 set_pte(kmap_pte-idx, mk_pte(page, prot));
20418+ pax_close_kernel();
20419
20420 return (void *)vaddr;
20421 }
20422diff -urNp linux-2.6.32.41/arch/x86/mm/hugetlbpage.c linux-2.6.32.41/arch/x86/mm/hugetlbpage.c
20423--- linux-2.6.32.41/arch/x86/mm/hugetlbpage.c 2011-03-27 14:31:47.000000000 -0400
20424+++ linux-2.6.32.41/arch/x86/mm/hugetlbpage.c 2011-04-17 15:56:46.000000000 -0400
20425@@ -267,13 +267,20 @@ static unsigned long hugetlb_get_unmappe
20426 struct hstate *h = hstate_file(file);
20427 struct mm_struct *mm = current->mm;
20428 struct vm_area_struct *vma;
20429- unsigned long start_addr;
20430+ unsigned long start_addr, pax_task_size = TASK_SIZE;
20431+
20432+#ifdef CONFIG_PAX_SEGMEXEC
20433+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
20434+ pax_task_size = SEGMEXEC_TASK_SIZE;
20435+#endif
20436+
20437+ pax_task_size -= PAGE_SIZE;
20438
20439 if (len > mm->cached_hole_size) {
20440- start_addr = mm->free_area_cache;
20441+ start_addr = mm->free_area_cache;
20442 } else {
20443- start_addr = TASK_UNMAPPED_BASE;
20444- mm->cached_hole_size = 0;
20445+ start_addr = mm->mmap_base;
20446+ mm->cached_hole_size = 0;
20447 }
20448
20449 full_search:
20450@@ -281,26 +288,27 @@ full_search:
20451
20452 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
20453 /* At this point: (!vma || addr < vma->vm_end). */
20454- if (TASK_SIZE - len < addr) {
20455+ if (pax_task_size - len < addr) {
20456 /*
20457 * Start a new search - just in case we missed
20458 * some holes.
20459 */
20460- if (start_addr != TASK_UNMAPPED_BASE) {
20461- start_addr = TASK_UNMAPPED_BASE;
20462+ if (start_addr != mm->mmap_base) {
20463+ start_addr = mm->mmap_base;
20464 mm->cached_hole_size = 0;
20465 goto full_search;
20466 }
20467 return -ENOMEM;
20468 }
20469- if (!vma || addr + len <= vma->vm_start) {
20470- mm->free_area_cache = addr + len;
20471- return addr;
20472- }
20473+ if (check_heap_stack_gap(vma, addr, len))
20474+ break;
20475 if (addr + mm->cached_hole_size < vma->vm_start)
20476 mm->cached_hole_size = vma->vm_start - addr;
20477 addr = ALIGN(vma->vm_end, huge_page_size(h));
20478 }
20479+
20480+ mm->free_area_cache = addr + len;
20481+ return addr;
20482 }
20483
20484 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
20485@@ -309,10 +317,9 @@ static unsigned long hugetlb_get_unmappe
20486 {
20487 struct hstate *h = hstate_file(file);
20488 struct mm_struct *mm = current->mm;
20489- struct vm_area_struct *vma, *prev_vma;
20490- unsigned long base = mm->mmap_base, addr = addr0;
20491+ struct vm_area_struct *vma;
20492+ unsigned long base = mm->mmap_base, addr;
20493 unsigned long largest_hole = mm->cached_hole_size;
20494- int first_time = 1;
20495
20496 /* don't allow allocations above current base */
20497 if (mm->free_area_cache > base)
20498@@ -322,64 +329,63 @@ static unsigned long hugetlb_get_unmappe
20499 largest_hole = 0;
20500 mm->free_area_cache = base;
20501 }
20502-try_again:
20503+
20504 /* make sure it can fit in the remaining address space */
20505 if (mm->free_area_cache < len)
20506 goto fail;
20507
20508 /* either no address requested or cant fit in requested address hole */
20509- addr = (mm->free_area_cache - len) & huge_page_mask(h);
20510+ addr = (mm->free_area_cache - len);
20511 do {
20512+ addr &= huge_page_mask(h);
20513+ vma = find_vma(mm, addr);
20514 /*
20515 * Lookup failure means no vma is above this address,
20516 * i.e. return with success:
20517- */
20518- if (!(vma = find_vma_prev(mm, addr, &prev_vma)))
20519- return addr;
20520-
20521- /*
20522 * new region fits between prev_vma->vm_end and
20523 * vma->vm_start, use it:
20524 */
20525- if (addr + len <= vma->vm_start &&
20526- (!prev_vma || (addr >= prev_vma->vm_end))) {
20527+ if (check_heap_stack_gap(vma, addr, len)) {
20528 /* remember the address as a hint for next time */
20529- mm->cached_hole_size = largest_hole;
20530- return (mm->free_area_cache = addr);
20531- } else {
20532- /* pull free_area_cache down to the first hole */
20533- if (mm->free_area_cache == vma->vm_end) {
20534- mm->free_area_cache = vma->vm_start;
20535- mm->cached_hole_size = largest_hole;
20536- }
20537+ mm->cached_hole_size = largest_hole;
20538+ return (mm->free_area_cache = addr);
20539+ }
20540+ /* pull free_area_cache down to the first hole */
20541+ if (mm->free_area_cache == vma->vm_end) {
20542+ mm->free_area_cache = vma->vm_start;
20543+ mm->cached_hole_size = largest_hole;
20544 }
20545
20546 /* remember the largest hole we saw so far */
20547 if (addr + largest_hole < vma->vm_start)
20548- largest_hole = vma->vm_start - addr;
20549+ largest_hole = vma->vm_start - addr;
20550
20551 /* try just below the current vma->vm_start */
20552- addr = (vma->vm_start - len) & huge_page_mask(h);
20553- } while (len <= vma->vm_start);
20554+ addr = skip_heap_stack_gap(vma, len);
20555+ } while (!IS_ERR_VALUE(addr));
20556
20557 fail:
20558 /*
20559- * if hint left us with no space for the requested
20560- * mapping then try again:
20561- */
20562- if (first_time) {
20563- mm->free_area_cache = base;
20564- largest_hole = 0;
20565- first_time = 0;
20566- goto try_again;
20567- }
20568- /*
20569 * A failed mmap() very likely causes application failure,
20570 * so fall back to the bottom-up function here. This scenario
20571 * can happen with large stack limits and large mmap()
20572 * allocations.
20573 */
20574- mm->free_area_cache = TASK_UNMAPPED_BASE;
20575+
20576+#ifdef CONFIG_PAX_SEGMEXEC
20577+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
20578+ mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
20579+ else
20580+#endif
20581+
20582+ mm->mmap_base = TASK_UNMAPPED_BASE;
20583+
20584+#ifdef CONFIG_PAX_RANDMMAP
20585+ if (mm->pax_flags & MF_PAX_RANDMMAP)
20586+ mm->mmap_base += mm->delta_mmap;
20587+#endif
20588+
20589+ mm->free_area_cache = mm->mmap_base;
20590 mm->cached_hole_size = ~0UL;
20591 addr = hugetlb_get_unmapped_area_bottomup(file, addr0,
20592 len, pgoff, flags);
20593@@ -387,6 +393,7 @@ fail:
20594 /*
20595 * Restore the topdown base:
20596 */
20597+ mm->mmap_base = base;
20598 mm->free_area_cache = base;
20599 mm->cached_hole_size = ~0UL;
20600
20601@@ -400,10 +407,19 @@ hugetlb_get_unmapped_area(struct file *f
20602 struct hstate *h = hstate_file(file);
20603 struct mm_struct *mm = current->mm;
20604 struct vm_area_struct *vma;
20605+ unsigned long pax_task_size = TASK_SIZE;
20606
20607 if (len & ~huge_page_mask(h))
20608 return -EINVAL;
20609- if (len > TASK_SIZE)
20610+
20611+#ifdef CONFIG_PAX_SEGMEXEC
20612+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
20613+ pax_task_size = SEGMEXEC_TASK_SIZE;
20614+#endif
20615+
20616+ pax_task_size -= PAGE_SIZE;
20617+
20618+ if (len > pax_task_size)
20619 return -ENOMEM;
20620
20621 if (flags & MAP_FIXED) {
20622@@ -415,8 +431,7 @@ hugetlb_get_unmapped_area(struct file *f
20623 if (addr) {
20624 addr = ALIGN(addr, huge_page_size(h));
20625 vma = find_vma(mm, addr);
20626- if (TASK_SIZE - len >= addr &&
20627- (!vma || addr + len <= vma->vm_start))
20628+ if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
20629 return addr;
20630 }
20631 if (mm->get_unmapped_area == arch_get_unmapped_area)
20632diff -urNp linux-2.6.32.41/arch/x86/mm/init_32.c linux-2.6.32.41/arch/x86/mm/init_32.c
20633--- linux-2.6.32.41/arch/x86/mm/init_32.c 2011-03-27 14:31:47.000000000 -0400
20634+++ linux-2.6.32.41/arch/x86/mm/init_32.c 2011-04-17 15:56:46.000000000 -0400
20635@@ -72,36 +72,6 @@ static __init void *alloc_low_page(void)
20636 }
20637
20638 /*
20639- * Creates a middle page table and puts a pointer to it in the
20640- * given global directory entry. This only returns the gd entry
20641- * in non-PAE compilation mode, since the middle layer is folded.
20642- */
20643-static pmd_t * __init one_md_table_init(pgd_t *pgd)
20644-{
20645- pud_t *pud;
20646- pmd_t *pmd_table;
20647-
20648-#ifdef CONFIG_X86_PAE
20649- if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
20650- if (after_bootmem)
20651- pmd_table = (pmd_t *)alloc_bootmem_pages(PAGE_SIZE);
20652- else
20653- pmd_table = (pmd_t *)alloc_low_page();
20654- paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
20655- set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
20656- pud = pud_offset(pgd, 0);
20657- BUG_ON(pmd_table != pmd_offset(pud, 0));
20658-
20659- return pmd_table;
20660- }
20661-#endif
20662- pud = pud_offset(pgd, 0);
20663- pmd_table = pmd_offset(pud, 0);
20664-
20665- return pmd_table;
20666-}
20667-
20668-/*
20669 * Create a page table and place a pointer to it in a middle page
20670 * directory entry:
20671 */
20672@@ -121,13 +91,28 @@ static pte_t * __init one_page_table_ini
20673 page_table = (pte_t *)alloc_low_page();
20674
20675 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
20676+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
20677+ set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
20678+#else
20679 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
20680+#endif
20681 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
20682 }
20683
20684 return pte_offset_kernel(pmd, 0);
20685 }
20686
20687+static pmd_t * __init one_md_table_init(pgd_t *pgd)
20688+{
20689+ pud_t *pud;
20690+ pmd_t *pmd_table;
20691+
20692+ pud = pud_offset(pgd, 0);
20693+ pmd_table = pmd_offset(pud, 0);
20694+
20695+ return pmd_table;
20696+}
20697+
20698 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
20699 {
20700 int pgd_idx = pgd_index(vaddr);
20701@@ -201,6 +186,7 @@ page_table_range_init(unsigned long star
20702 int pgd_idx, pmd_idx;
20703 unsigned long vaddr;
20704 pgd_t *pgd;
20705+ pud_t *pud;
20706 pmd_t *pmd;
20707 pte_t *pte = NULL;
20708
20709@@ -210,8 +196,13 @@ page_table_range_init(unsigned long star
20710 pgd = pgd_base + pgd_idx;
20711
20712 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
20713- pmd = one_md_table_init(pgd);
20714- pmd = pmd + pmd_index(vaddr);
20715+ pud = pud_offset(pgd, vaddr);
20716+ pmd = pmd_offset(pud, vaddr);
20717+
20718+#ifdef CONFIG_X86_PAE
20719+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
20720+#endif
20721+
20722 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
20723 pmd++, pmd_idx++) {
20724 pte = page_table_kmap_check(one_page_table_init(pmd),
20725@@ -223,11 +214,20 @@ page_table_range_init(unsigned long star
20726 }
20727 }
20728
20729-static inline int is_kernel_text(unsigned long addr)
20730+static inline int is_kernel_text(unsigned long start, unsigned long end)
20731 {
20732- if (addr >= PAGE_OFFSET && addr <= (unsigned long)__init_end)
20733- return 1;
20734- return 0;
20735+ if ((start > ktla_ktva((unsigned long)_etext) ||
20736+ end <= ktla_ktva((unsigned long)_stext)) &&
20737+ (start > ktla_ktva((unsigned long)_einittext) ||
20738+ end <= ktla_ktva((unsigned long)_sinittext)) &&
20739+
20740+#ifdef CONFIG_ACPI_SLEEP
20741+ (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
20742+#endif
20743+
20744+ (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
20745+ return 0;
20746+ return 1;
20747 }
20748
20749 /*
20750@@ -243,9 +243,10 @@ kernel_physical_mapping_init(unsigned lo
20751 int use_pse = page_size_mask == (1<<PG_LEVEL_2M);
20752 unsigned long start_pfn, end_pfn;
20753 pgd_t *pgd_base = swapper_pg_dir;
20754- int pgd_idx, pmd_idx, pte_ofs;
20755+ unsigned int pgd_idx, pmd_idx, pte_ofs;
20756 unsigned long pfn;
20757 pgd_t *pgd;
20758+ pud_t *pud;
20759 pmd_t *pmd;
20760 pte_t *pte;
20761 unsigned pages_2m, pages_4k;
20762@@ -278,8 +279,13 @@ repeat:
20763 pfn = start_pfn;
20764 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
20765 pgd = pgd_base + pgd_idx;
20766- for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
20767- pmd = one_md_table_init(pgd);
20768+ for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
20769+ pud = pud_offset(pgd, 0);
20770+ pmd = pmd_offset(pud, 0);
20771+
20772+#ifdef CONFIG_X86_PAE
20773+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
20774+#endif
20775
20776 if (pfn >= end_pfn)
20777 continue;
20778@@ -291,14 +297,13 @@ repeat:
20779 #endif
20780 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
20781 pmd++, pmd_idx++) {
20782- unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
20783+ unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
20784
20785 /*
20786 * Map with big pages if possible, otherwise
20787 * create normal page tables:
20788 */
20789 if (use_pse) {
20790- unsigned int addr2;
20791 pgprot_t prot = PAGE_KERNEL_LARGE;
20792 /*
20793 * first pass will use the same initial
20794@@ -308,11 +313,7 @@ repeat:
20795 __pgprot(PTE_IDENT_ATTR |
20796 _PAGE_PSE);
20797
20798- addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
20799- PAGE_OFFSET + PAGE_SIZE-1;
20800-
20801- if (is_kernel_text(addr) ||
20802- is_kernel_text(addr2))
20803+ if (is_kernel_text(address, address + PMD_SIZE))
20804 prot = PAGE_KERNEL_LARGE_EXEC;
20805
20806 pages_2m++;
20807@@ -329,7 +330,7 @@ repeat:
20808 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
20809 pte += pte_ofs;
20810 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
20811- pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
20812+ pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
20813 pgprot_t prot = PAGE_KERNEL;
20814 /*
20815 * first pass will use the same initial
20816@@ -337,7 +338,7 @@ repeat:
20817 */
20818 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
20819
20820- if (is_kernel_text(addr))
20821+ if (is_kernel_text(address, address + PAGE_SIZE))
20822 prot = PAGE_KERNEL_EXEC;
20823
20824 pages_4k++;
20825@@ -489,7 +490,7 @@ void __init native_pagetable_setup_start
20826
20827 pud = pud_offset(pgd, va);
20828 pmd = pmd_offset(pud, va);
20829- if (!pmd_present(*pmd))
20830+ if (!pmd_present(*pmd) || pmd_huge(*pmd))
20831 break;
20832
20833 pte = pte_offset_kernel(pmd, va);
20834@@ -541,9 +542,7 @@ void __init early_ioremap_page_table_ran
20835
20836 static void __init pagetable_init(void)
20837 {
20838- pgd_t *pgd_base = swapper_pg_dir;
20839-
20840- permanent_kmaps_init(pgd_base);
20841+ permanent_kmaps_init(swapper_pg_dir);
20842 }
20843
20844 #ifdef CONFIG_ACPI_SLEEP
20845@@ -551,12 +550,12 @@ static void __init pagetable_init(void)
20846 * ACPI suspend needs this for resume, because things like the intel-agp
20847 * driver might have split up a kernel 4MB mapping.
20848 */
20849-char swsusp_pg_dir[PAGE_SIZE]
20850+pgd_t swsusp_pg_dir[PTRS_PER_PGD]
20851 __attribute__ ((aligned(PAGE_SIZE)));
20852
20853 static inline void save_pg_dir(void)
20854 {
20855- memcpy(swsusp_pg_dir, swapper_pg_dir, PAGE_SIZE);
20856+ clone_pgd_range(swsusp_pg_dir, swapper_pg_dir, PTRS_PER_PGD);
20857 }
20858 #else /* !CONFIG_ACPI_SLEEP */
20859 static inline void save_pg_dir(void)
20860@@ -588,7 +587,7 @@ void zap_low_mappings(bool early)
20861 flush_tlb_all();
20862 }
20863
20864-pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
20865+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
20866 EXPORT_SYMBOL_GPL(__supported_pte_mask);
20867
20868 /* user-defined highmem size */
20869@@ -777,7 +776,7 @@ void __init setup_bootmem_allocator(void
20870 * Initialize the boot-time allocator (with low memory only):
20871 */
20872 bootmap_size = bootmem_bootmap_pages(max_low_pfn)<<PAGE_SHIFT;
20873- bootmap = find_e820_area(0, max_pfn_mapped<<PAGE_SHIFT, bootmap_size,
20874+ bootmap = find_e820_area(0x100000, max_pfn_mapped<<PAGE_SHIFT, bootmap_size,
20875 PAGE_SIZE);
20876 if (bootmap == -1L)
20877 panic("Cannot find bootmem map of size %ld\n", bootmap_size);
20878@@ -864,6 +863,12 @@ void __init mem_init(void)
20879
20880 pci_iommu_alloc();
20881
20882+#ifdef CONFIG_PAX_PER_CPU_PGD
20883+ clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
20884+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
20885+ KERNEL_PGD_PTRS);
20886+#endif
20887+
20888 #ifdef CONFIG_FLATMEM
20889 BUG_ON(!mem_map);
20890 #endif
20891@@ -881,7 +886,7 @@ void __init mem_init(void)
20892 set_highmem_pages_init();
20893
20894 codesize = (unsigned long) &_etext - (unsigned long) &_text;
20895- datasize = (unsigned long) &_edata - (unsigned long) &_etext;
20896+ datasize = (unsigned long) &_edata - (unsigned long) &_sdata;
20897 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
20898
20899 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
20900@@ -923,10 +928,10 @@ void __init mem_init(void)
20901 ((unsigned long)&__init_end -
20902 (unsigned long)&__init_begin) >> 10,
20903
20904- (unsigned long)&_etext, (unsigned long)&_edata,
20905- ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
20906+ (unsigned long)&_sdata, (unsigned long)&_edata,
20907+ ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
20908
20909- (unsigned long)&_text, (unsigned long)&_etext,
20910+ ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
20911 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
20912
20913 /*
20914@@ -1007,6 +1012,7 @@ void set_kernel_text_rw(void)
20915 if (!kernel_set_to_readonly)
20916 return;
20917
20918+ start = ktla_ktva(start);
20919 pr_debug("Set kernel text: %lx - %lx for read write\n",
20920 start, start+size);
20921
20922@@ -1021,6 +1027,7 @@ void set_kernel_text_ro(void)
20923 if (!kernel_set_to_readonly)
20924 return;
20925
20926+ start = ktla_ktva(start);
20927 pr_debug("Set kernel text: %lx - %lx for read only\n",
20928 start, start+size);
20929
20930@@ -1032,6 +1039,7 @@ void mark_rodata_ro(void)
20931 unsigned long start = PFN_ALIGN(_text);
20932 unsigned long size = PFN_ALIGN(_etext) - start;
20933
20934+ start = ktla_ktva(start);
20935 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
20936 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
20937 size >> 10);
20938diff -urNp linux-2.6.32.41/arch/x86/mm/init_64.c linux-2.6.32.41/arch/x86/mm/init_64.c
20939--- linux-2.6.32.41/arch/x86/mm/init_64.c 2011-04-17 17:00:52.000000000 -0400
20940+++ linux-2.6.32.41/arch/x86/mm/init_64.c 2011-04-17 17:03:05.000000000 -0400
20941@@ -164,7 +164,9 @@ void set_pte_vaddr_pud(pud_t *pud_page,
20942 pmd = fill_pmd(pud, vaddr);
20943 pte = fill_pte(pmd, vaddr);
20944
20945+ pax_open_kernel();
20946 set_pte(pte, new_pte);
20947+ pax_close_kernel();
20948
20949 /*
20950 * It's enough to flush this one mapping.
20951@@ -223,14 +225,12 @@ static void __init __init_extra_mapping(
20952 pgd = pgd_offset_k((unsigned long)__va(phys));
20953 if (pgd_none(*pgd)) {
20954 pud = (pud_t *) spp_getpage();
20955- set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
20956- _PAGE_USER));
20957+ set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
20958 }
20959 pud = pud_offset(pgd, (unsigned long)__va(phys));
20960 if (pud_none(*pud)) {
20961 pmd = (pmd_t *) spp_getpage();
20962- set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
20963- _PAGE_USER));
20964+ set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
20965 }
20966 pmd = pmd_offset(pud, phys);
20967 BUG_ON(!pmd_none(*pmd));
20968@@ -675,6 +675,12 @@ void __init mem_init(void)
20969
20970 pci_iommu_alloc();
20971
20972+#ifdef CONFIG_PAX_PER_CPU_PGD
20973+ clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
20974+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
20975+ KERNEL_PGD_PTRS);
20976+#endif
20977+
20978 /* clear_bss() already clear the empty_zero_page */
20979
20980 reservedpages = 0;
20981@@ -861,8 +867,8 @@ int kern_addr_valid(unsigned long addr)
20982 static struct vm_area_struct gate_vma = {
20983 .vm_start = VSYSCALL_START,
20984 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
20985- .vm_page_prot = PAGE_READONLY_EXEC,
20986- .vm_flags = VM_READ | VM_EXEC
20987+ .vm_page_prot = PAGE_READONLY,
20988+ .vm_flags = VM_READ
20989 };
20990
20991 struct vm_area_struct *get_gate_vma(struct task_struct *tsk)
20992@@ -896,7 +902,7 @@ int in_gate_area_no_task(unsigned long a
20993
20994 const char *arch_vma_name(struct vm_area_struct *vma)
20995 {
20996- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
20997+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
20998 return "[vdso]";
20999 if (vma == &gate_vma)
21000 return "[vsyscall]";
21001diff -urNp linux-2.6.32.41/arch/x86/mm/init.c linux-2.6.32.41/arch/x86/mm/init.c
21002--- linux-2.6.32.41/arch/x86/mm/init.c 2011-04-17 17:00:52.000000000 -0400
21003+++ linux-2.6.32.41/arch/x86/mm/init.c 2011-06-07 19:06:09.000000000 -0400
21004@@ -69,11 +69,7 @@ static void __init find_early_table_spac
21005 * cause a hotspot and fill up ZONE_DMA. The page tables
21006 * need roughly 0.5KB per GB.
21007 */
21008-#ifdef CONFIG_X86_32
21009- start = 0x7000;
21010-#else
21011- start = 0x8000;
21012-#endif
21013+ start = 0x100000;
21014 e820_table_start = find_e820_area(start, max_pfn_mapped<<PAGE_SHIFT,
21015 tables, PAGE_SIZE);
21016 if (e820_table_start == -1UL)
21017@@ -147,7 +143,7 @@ unsigned long __init_refok init_memory_m
21018 #endif
21019
21020 set_nx();
21021- if (nx_enabled)
21022+ if (nx_enabled && cpu_has_nx)
21023 printk(KERN_INFO "NX (Execute Disable) protection: active\n");
21024
21025 /* Enable PSE if available */
21026@@ -329,10 +325,27 @@ unsigned long __init_refok init_memory_m
21027 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
21028 * mmio resources as well as potential bios/acpi data regions.
21029 */
21030+
21031 int devmem_is_allowed(unsigned long pagenr)
21032 {
21033+#ifdef CONFIG_GRKERNSEC_KMEM
21034+ /* allow BDA */
21035+ if (!pagenr)
21036+ return 1;
21037+ /* allow EBDA */
21038+ if ((0x9f000 >> PAGE_SHIFT) == pagenr)
21039+ return 1;
21040+ /* allow ISA/video mem */
21041+ if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
21042+ return 1;
21043+ /* throw out everything else below 1MB */
21044+ if (pagenr <= 256)
21045+ return 0;
21046+#else
21047 if (pagenr <= 256)
21048 return 1;
21049+#endif
21050+
21051 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
21052 return 0;
21053 if (!page_is_ram(pagenr))
21054@@ -379,6 +392,86 @@ void free_init_pages(char *what, unsigne
21055
21056 void free_initmem(void)
21057 {
21058+
21059+#ifdef CONFIG_PAX_KERNEXEC
21060+#ifdef CONFIG_X86_32
21061+ /* PaX: limit KERNEL_CS to actual size */
21062+ unsigned long addr, limit;
21063+ struct desc_struct d;
21064+ int cpu;
21065+
21066+ limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
21067+ limit = (limit - 1UL) >> PAGE_SHIFT;
21068+
21069+ memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
21070+ for (cpu = 0; cpu < NR_CPUS; cpu++) {
21071+ pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
21072+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
21073+ }
21074+
21075+ /* PaX: make KERNEL_CS read-only */
21076+ addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
21077+ if (!paravirt_enabled())
21078+ set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
21079+/*
21080+ for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
21081+ pgd = pgd_offset_k(addr);
21082+ pud = pud_offset(pgd, addr);
21083+ pmd = pmd_offset(pud, addr);
21084+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
21085+ }
21086+*/
21087+#ifdef CONFIG_X86_PAE
21088+ set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
21089+/*
21090+ for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
21091+ pgd = pgd_offset_k(addr);
21092+ pud = pud_offset(pgd, addr);
21093+ pmd = pmd_offset(pud, addr);
21094+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
21095+ }
21096+*/
21097+#endif
21098+
21099+#ifdef CONFIG_MODULES
21100+ set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
21101+#endif
21102+
21103+#else
21104+ pgd_t *pgd;
21105+ pud_t *pud;
21106+ pmd_t *pmd;
21107+ unsigned long addr, end;
21108+
21109+ /* PaX: make kernel code/rodata read-only, rest non-executable */
21110+ for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
21111+ pgd = pgd_offset_k(addr);
21112+ pud = pud_offset(pgd, addr);
21113+ pmd = pmd_offset(pud, addr);
21114+ if (!pmd_present(*pmd))
21115+ continue;
21116+ if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
21117+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
21118+ else
21119+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
21120+ }
21121+
21122+ addr = (unsigned long)__va(__pa(__START_KERNEL_map));
21123+ end = addr + KERNEL_IMAGE_SIZE;
21124+ for (; addr < end; addr += PMD_SIZE) {
21125+ pgd = pgd_offset_k(addr);
21126+ pud = pud_offset(pgd, addr);
21127+ pmd = pmd_offset(pud, addr);
21128+ if (!pmd_present(*pmd))
21129+ continue;
21130+ if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
21131+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
21132+ }
21133+#endif
21134+
21135+ flush_tlb_all();
21136+#endif
21137+
21138 free_init_pages("unused kernel memory",
21139 (unsigned long)(&__init_begin),
21140 (unsigned long)(&__init_end));
21141diff -urNp linux-2.6.32.41/arch/x86/mm/iomap_32.c linux-2.6.32.41/arch/x86/mm/iomap_32.c
21142--- linux-2.6.32.41/arch/x86/mm/iomap_32.c 2011-03-27 14:31:47.000000000 -0400
21143+++ linux-2.6.32.41/arch/x86/mm/iomap_32.c 2011-04-17 15:56:46.000000000 -0400
21144@@ -65,7 +65,11 @@ void *kmap_atomic_prot_pfn(unsigned long
21145 debug_kmap_atomic(type);
21146 idx = type + KM_TYPE_NR * smp_processor_id();
21147 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
21148+
21149+ pax_open_kernel();
21150 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
21151+ pax_close_kernel();
21152+
21153 arch_flush_lazy_mmu_mode();
21154
21155 return (void *)vaddr;
21156diff -urNp linux-2.6.32.41/arch/x86/mm/ioremap.c linux-2.6.32.41/arch/x86/mm/ioremap.c
21157--- linux-2.6.32.41/arch/x86/mm/ioremap.c 2011-03-27 14:31:47.000000000 -0400
21158+++ linux-2.6.32.41/arch/x86/mm/ioremap.c 2011-04-17 15:56:46.000000000 -0400
21159@@ -41,8 +41,8 @@ int page_is_ram(unsigned long pagenr)
21160 * Second special case: Some BIOSen report the PC BIOS
21161 * area (640->1Mb) as ram even though it is not.
21162 */
21163- if (pagenr >= (BIOS_BEGIN >> PAGE_SHIFT) &&
21164- pagenr < (BIOS_END >> PAGE_SHIFT))
21165+ if (pagenr >= (ISA_START_ADDRESS >> PAGE_SHIFT) &&
21166+ pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
21167 return 0;
21168
21169 for (i = 0; i < e820.nr_map; i++) {
21170@@ -137,13 +137,10 @@ static void __iomem *__ioremap_caller(re
21171 /*
21172 * Don't allow anybody to remap normal RAM that we're using..
21173 */
21174- for (pfn = phys_addr >> PAGE_SHIFT;
21175- (pfn << PAGE_SHIFT) < (last_addr & PAGE_MASK);
21176- pfn++) {
21177-
21178+ for (pfn = phys_addr >> PAGE_SHIFT; ((resource_size_t)pfn << PAGE_SHIFT) < (last_addr & PAGE_MASK); pfn++) {
21179 int is_ram = page_is_ram(pfn);
21180
21181- if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
21182+ if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
21183 return NULL;
21184 WARN_ON_ONCE(is_ram);
21185 }
21186@@ -407,7 +404,7 @@ static int __init early_ioremap_debug_se
21187 early_param("early_ioremap_debug", early_ioremap_debug_setup);
21188
21189 static __initdata int after_paging_init;
21190-static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
21191+static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
21192
21193 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
21194 {
21195@@ -439,8 +436,7 @@ void __init early_ioremap_init(void)
21196 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
21197
21198 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
21199- memset(bm_pte, 0, sizeof(bm_pte));
21200- pmd_populate_kernel(&init_mm, pmd, bm_pte);
21201+ pmd_populate_user(&init_mm, pmd, bm_pte);
21202
21203 /*
21204 * The boot-ioremap range spans multiple pmds, for which
21205diff -urNp linux-2.6.32.41/arch/x86/mm/kmemcheck/kmemcheck.c linux-2.6.32.41/arch/x86/mm/kmemcheck/kmemcheck.c
21206--- linux-2.6.32.41/arch/x86/mm/kmemcheck/kmemcheck.c 2011-03-27 14:31:47.000000000 -0400
21207+++ linux-2.6.32.41/arch/x86/mm/kmemcheck/kmemcheck.c 2011-04-17 15:56:46.000000000 -0400
21208@@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *reg
21209 * memory (e.g. tracked pages)? For now, we need this to avoid
21210 * invoking kmemcheck for PnP BIOS calls.
21211 */
21212- if (regs->flags & X86_VM_MASK)
21213+ if (v8086_mode(regs))
21214 return false;
21215- if (regs->cs != __KERNEL_CS)
21216+ if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
21217 return false;
21218
21219 pte = kmemcheck_pte_lookup(address);
21220diff -urNp linux-2.6.32.41/arch/x86/mm/mmap.c linux-2.6.32.41/arch/x86/mm/mmap.c
21221--- linux-2.6.32.41/arch/x86/mm/mmap.c 2011-03-27 14:31:47.000000000 -0400
21222+++ linux-2.6.32.41/arch/x86/mm/mmap.c 2011-04-17 15:56:46.000000000 -0400
21223@@ -49,7 +49,7 @@ static unsigned int stack_maxrandom_size
21224 * Leave an at least ~128 MB hole with possible stack randomization.
21225 */
21226 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
21227-#define MAX_GAP (TASK_SIZE/6*5)
21228+#define MAX_GAP (pax_task_size/6*5)
21229
21230 /*
21231 * True on X86_32 or when emulating IA32 on X86_64
21232@@ -94,27 +94,40 @@ static unsigned long mmap_rnd(void)
21233 return rnd << PAGE_SHIFT;
21234 }
21235
21236-static unsigned long mmap_base(void)
21237+static unsigned long mmap_base(struct mm_struct *mm)
21238 {
21239 unsigned long gap = current->signal->rlim[RLIMIT_STACK].rlim_cur;
21240+ unsigned long pax_task_size = TASK_SIZE;
21241+
21242+#ifdef CONFIG_PAX_SEGMEXEC
21243+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
21244+ pax_task_size = SEGMEXEC_TASK_SIZE;
21245+#endif
21246
21247 if (gap < MIN_GAP)
21248 gap = MIN_GAP;
21249 else if (gap > MAX_GAP)
21250 gap = MAX_GAP;
21251
21252- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
21253+ return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
21254 }
21255
21256 /*
21257 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
21258 * does, but not when emulating X86_32
21259 */
21260-static unsigned long mmap_legacy_base(void)
21261+static unsigned long mmap_legacy_base(struct mm_struct *mm)
21262 {
21263- if (mmap_is_ia32())
21264+ if (mmap_is_ia32()) {
21265+
21266+#ifdef CONFIG_PAX_SEGMEXEC
21267+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
21268+ return SEGMEXEC_TASK_UNMAPPED_BASE;
21269+ else
21270+#endif
21271+
21272 return TASK_UNMAPPED_BASE;
21273- else
21274+ } else
21275 return TASK_UNMAPPED_BASE + mmap_rnd();
21276 }
21277
21278@@ -125,11 +138,23 @@ static unsigned long mmap_legacy_base(vo
21279 void arch_pick_mmap_layout(struct mm_struct *mm)
21280 {
21281 if (mmap_is_legacy()) {
21282- mm->mmap_base = mmap_legacy_base();
21283+ mm->mmap_base = mmap_legacy_base(mm);
21284+
21285+#ifdef CONFIG_PAX_RANDMMAP
21286+ if (mm->pax_flags & MF_PAX_RANDMMAP)
21287+ mm->mmap_base += mm->delta_mmap;
21288+#endif
21289+
21290 mm->get_unmapped_area = arch_get_unmapped_area;
21291 mm->unmap_area = arch_unmap_area;
21292 } else {
21293- mm->mmap_base = mmap_base();
21294+ mm->mmap_base = mmap_base(mm);
21295+
21296+#ifdef CONFIG_PAX_RANDMMAP
21297+ if (mm->pax_flags & MF_PAX_RANDMMAP)
21298+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
21299+#endif
21300+
21301 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
21302 mm->unmap_area = arch_unmap_area_topdown;
21303 }
21304diff -urNp linux-2.6.32.41/arch/x86/mm/mmio-mod.c linux-2.6.32.41/arch/x86/mm/mmio-mod.c
21305--- linux-2.6.32.41/arch/x86/mm/mmio-mod.c 2011-03-27 14:31:47.000000000 -0400
21306+++ linux-2.6.32.41/arch/x86/mm/mmio-mod.c 2011-05-04 17:56:28.000000000 -0400
21307@@ -233,7 +233,7 @@ static void post(struct kmmio_probe *p,
21308 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
21309 void __iomem *addr)
21310 {
21311- static atomic_t next_id;
21312+ static atomic_unchecked_t next_id;
21313 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
21314 /* These are page-unaligned. */
21315 struct mmiotrace_map map = {
21316@@ -257,7 +257,7 @@ static void ioremap_trace_core(resource_
21317 .private = trace
21318 },
21319 .phys = offset,
21320- .id = atomic_inc_return(&next_id)
21321+ .id = atomic_inc_return_unchecked(&next_id)
21322 };
21323 map.map_id = trace->id;
21324
21325diff -urNp linux-2.6.32.41/arch/x86/mm/numa_32.c linux-2.6.32.41/arch/x86/mm/numa_32.c
21326--- linux-2.6.32.41/arch/x86/mm/numa_32.c 2011-03-27 14:31:47.000000000 -0400
21327+++ linux-2.6.32.41/arch/x86/mm/numa_32.c 2011-04-17 15:56:46.000000000 -0400
21328@@ -98,7 +98,6 @@ unsigned long node_memmap_size_bytes(int
21329 }
21330 #endif
21331
21332-extern unsigned long find_max_low_pfn(void);
21333 extern unsigned long highend_pfn, highstart_pfn;
21334
21335 #define LARGE_PAGE_BYTES (PTRS_PER_PTE * PAGE_SIZE)
21336diff -urNp linux-2.6.32.41/arch/x86/mm/pageattr.c linux-2.6.32.41/arch/x86/mm/pageattr.c
21337--- linux-2.6.32.41/arch/x86/mm/pageattr.c 2011-03-27 14:31:47.000000000 -0400
21338+++ linux-2.6.32.41/arch/x86/mm/pageattr.c 2011-04-17 15:56:46.000000000 -0400
21339@@ -261,16 +261,17 @@ static inline pgprot_t static_protection
21340 * PCI BIOS based config access (CONFIG_PCI_GOBIOS) support.
21341 */
21342 if (within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
21343- pgprot_val(forbidden) |= _PAGE_NX;
21344+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
21345
21346 /*
21347 * The kernel text needs to be executable for obvious reasons
21348 * Does not cover __inittext since that is gone later on. On
21349 * 64bit we do not enforce !NX on the low mapping
21350 */
21351- if (within(address, (unsigned long)_text, (unsigned long)_etext))
21352- pgprot_val(forbidden) |= _PAGE_NX;
21353+ if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
21354+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
21355
21356+#ifdef CONFIG_DEBUG_RODATA
21357 /*
21358 * The .rodata section needs to be read-only. Using the pfn
21359 * catches all aliases.
21360@@ -278,6 +279,14 @@ static inline pgprot_t static_protection
21361 if (within(pfn, __pa((unsigned long)__start_rodata) >> PAGE_SHIFT,
21362 __pa((unsigned long)__end_rodata) >> PAGE_SHIFT))
21363 pgprot_val(forbidden) |= _PAGE_RW;
21364+#endif
21365+
21366+#ifdef CONFIG_PAX_KERNEXEC
21367+ if (within(pfn, __pa((unsigned long)&_text), __pa((unsigned long)&_sdata))) {
21368+ pgprot_val(forbidden) |= _PAGE_RW;
21369+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
21370+ }
21371+#endif
21372
21373 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
21374
21375@@ -331,23 +340,37 @@ EXPORT_SYMBOL_GPL(lookup_address);
21376 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
21377 {
21378 /* change init_mm */
21379+ pax_open_kernel();
21380 set_pte_atomic(kpte, pte);
21381+
21382 #ifdef CONFIG_X86_32
21383 if (!SHARED_KERNEL_PMD) {
21384+
21385+#ifdef CONFIG_PAX_PER_CPU_PGD
21386+ unsigned long cpu;
21387+#else
21388 struct page *page;
21389+#endif
21390
21391+#ifdef CONFIG_PAX_PER_CPU_PGD
21392+ for (cpu = 0; cpu < NR_CPUS; ++cpu) {
21393+ pgd_t *pgd = get_cpu_pgd(cpu);
21394+#else
21395 list_for_each_entry(page, &pgd_list, lru) {
21396- pgd_t *pgd;
21397+ pgd_t *pgd = (pgd_t *)page_address(page);
21398+#endif
21399+
21400 pud_t *pud;
21401 pmd_t *pmd;
21402
21403- pgd = (pgd_t *)page_address(page) + pgd_index(address);
21404+ pgd += pgd_index(address);
21405 pud = pud_offset(pgd, address);
21406 pmd = pmd_offset(pud, address);
21407 set_pte_atomic((pte_t *)pmd, pte);
21408 }
21409 }
21410 #endif
21411+ pax_close_kernel();
21412 }
21413
21414 static int
21415diff -urNp linux-2.6.32.41/arch/x86/mm/pageattr-test.c linux-2.6.32.41/arch/x86/mm/pageattr-test.c
21416--- linux-2.6.32.41/arch/x86/mm/pageattr-test.c 2011-03-27 14:31:47.000000000 -0400
21417+++ linux-2.6.32.41/arch/x86/mm/pageattr-test.c 2011-04-17 15:56:46.000000000 -0400
21418@@ -36,7 +36,7 @@ enum {
21419
21420 static int pte_testbit(pte_t pte)
21421 {
21422- return pte_flags(pte) & _PAGE_UNUSED1;
21423+ return pte_flags(pte) & _PAGE_CPA_TEST;
21424 }
21425
21426 struct split_state {
21427diff -urNp linux-2.6.32.41/arch/x86/mm/pat.c linux-2.6.32.41/arch/x86/mm/pat.c
21428--- linux-2.6.32.41/arch/x86/mm/pat.c 2011-03-27 14:31:47.000000000 -0400
21429+++ linux-2.6.32.41/arch/x86/mm/pat.c 2011-04-17 15:56:46.000000000 -0400
21430@@ -258,7 +258,7 @@ chk_conflict(struct memtype *new, struct
21431
21432 conflict:
21433 printk(KERN_INFO "%s:%d conflicting memory types "
21434- "%Lx-%Lx %s<->%s\n", current->comm, current->pid, new->start,
21435+ "%Lx-%Lx %s<->%s\n", current->comm, task_pid_nr(current), new->start,
21436 new->end, cattr_name(new->type), cattr_name(entry->type));
21437 return -EBUSY;
21438 }
21439@@ -559,7 +559,7 @@ unlock_ret:
21440
21441 if (err) {
21442 printk(KERN_INFO "%s:%d freeing invalid memtype %Lx-%Lx\n",
21443- current->comm, current->pid, start, end);
21444+ current->comm, task_pid_nr(current), start, end);
21445 }
21446
21447 dprintk("free_memtype request 0x%Lx-0x%Lx\n", start, end);
21448@@ -689,8 +689,8 @@ static inline int range_is_allowed(unsig
21449 while (cursor < to) {
21450 if (!devmem_is_allowed(pfn)) {
21451 printk(KERN_INFO
21452- "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
21453- current->comm, from, to);
21454+ "Program %s tried to access /dev/mem between %Lx->%Lx (%Lx).\n",
21455+ current->comm, from, to, cursor);
21456 return 0;
21457 }
21458 cursor += PAGE_SIZE;
21459@@ -755,7 +755,7 @@ int kernel_map_sync_memtype(u64 base, un
21460 printk(KERN_INFO
21461 "%s:%d ioremap_change_attr failed %s "
21462 "for %Lx-%Lx\n",
21463- current->comm, current->pid,
21464+ current->comm, task_pid_nr(current),
21465 cattr_name(flags),
21466 base, (unsigned long long)(base + size));
21467 return -EINVAL;
21468@@ -813,7 +813,7 @@ static int reserve_pfn_range(u64 paddr,
21469 free_memtype(paddr, paddr + size);
21470 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
21471 " for %Lx-%Lx, got %s\n",
21472- current->comm, current->pid,
21473+ current->comm, task_pid_nr(current),
21474 cattr_name(want_flags),
21475 (unsigned long long)paddr,
21476 (unsigned long long)(paddr + size),
21477diff -urNp linux-2.6.32.41/arch/x86/mm/pgtable_32.c linux-2.6.32.41/arch/x86/mm/pgtable_32.c
21478--- linux-2.6.32.41/arch/x86/mm/pgtable_32.c 2011-03-27 14:31:47.000000000 -0400
21479+++ linux-2.6.32.41/arch/x86/mm/pgtable_32.c 2011-04-17 15:56:46.000000000 -0400
21480@@ -49,10 +49,13 @@ void set_pte_vaddr(unsigned long vaddr,
21481 return;
21482 }
21483 pte = pte_offset_kernel(pmd, vaddr);
21484+
21485+ pax_open_kernel();
21486 if (pte_val(pteval))
21487 set_pte_at(&init_mm, vaddr, pte, pteval);
21488 else
21489 pte_clear(&init_mm, vaddr, pte);
21490+ pax_close_kernel();
21491
21492 /*
21493 * It's enough to flush this one mapping.
21494diff -urNp linux-2.6.32.41/arch/x86/mm/pgtable.c linux-2.6.32.41/arch/x86/mm/pgtable.c
21495--- linux-2.6.32.41/arch/x86/mm/pgtable.c 2011-03-27 14:31:47.000000000 -0400
21496+++ linux-2.6.32.41/arch/x86/mm/pgtable.c 2011-05-11 18:25:15.000000000 -0400
21497@@ -83,9 +83,52 @@ static inline void pgd_list_del(pgd_t *p
21498 list_del(&page->lru);
21499 }
21500
21501-#define UNSHARED_PTRS_PER_PGD \
21502- (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
21503+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21504+pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
21505
21506+void __shadow_user_pgds(pgd_t *dst, const pgd_t *src, int count)
21507+{
21508+ while (count--)
21509+ *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
21510+}
21511+#endif
21512+
21513+#ifdef CONFIG_PAX_PER_CPU_PGD
21514+void __clone_user_pgds(pgd_t *dst, const pgd_t *src, int count)
21515+{
21516+ while (count--)
21517+
21518+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21519+ *dst++ = __pgd(pgd_val(*src++) & clone_pgd_mask);
21520+#else
21521+ *dst++ = *src++;
21522+#endif
21523+
21524+}
21525+#endif
21526+
21527+#ifdef CONFIG_X86_64
21528+#define pxd_t pud_t
21529+#define pyd_t pgd_t
21530+#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
21531+#define pxd_free(mm, pud) pud_free((mm), (pud))
21532+#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
21533+#define pyd_offset(mm ,address) pgd_offset((mm), (address))
21534+#define PYD_SIZE PGDIR_SIZE
21535+#else
21536+#define pxd_t pmd_t
21537+#define pyd_t pud_t
21538+#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
21539+#define pxd_free(mm, pud) pmd_free((mm), (pud))
21540+#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
21541+#define pyd_offset(mm ,address) pud_offset((mm), (address))
21542+#define PYD_SIZE PUD_SIZE
21543+#endif
21544+
21545+#ifdef CONFIG_PAX_PER_CPU_PGD
21546+static inline void pgd_ctor(pgd_t *pgd) {}
21547+static inline void pgd_dtor(pgd_t *pgd) {}
21548+#else
21549 static void pgd_ctor(pgd_t *pgd)
21550 {
21551 /* If the pgd points to a shared pagetable level (either the
21552@@ -119,6 +162,7 @@ static void pgd_dtor(pgd_t *pgd)
21553 pgd_list_del(pgd);
21554 spin_unlock_irqrestore(&pgd_lock, flags);
21555 }
21556+#endif
21557
21558 /*
21559 * List of all pgd's needed for non-PAE so it can invalidate entries
21560@@ -131,7 +175,7 @@ static void pgd_dtor(pgd_t *pgd)
21561 * -- wli
21562 */
21563
21564-#ifdef CONFIG_X86_PAE
21565+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
21566 /*
21567 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
21568 * updating the top-level pagetable entries to guarantee the
21569@@ -143,7 +187,7 @@ static void pgd_dtor(pgd_t *pgd)
21570 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
21571 * and initialize the kernel pmds here.
21572 */
21573-#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
21574+#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
21575
21576 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
21577 {
21578@@ -161,36 +205,38 @@ void pud_populate(struct mm_struct *mm,
21579 */
21580 flush_tlb_mm(mm);
21581 }
21582+#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
21583+#define PREALLOCATED_PXDS USER_PGD_PTRS
21584 #else /* !CONFIG_X86_PAE */
21585
21586 /* No need to prepopulate any pagetable entries in non-PAE modes. */
21587-#define PREALLOCATED_PMDS 0
21588+#define PREALLOCATED_PXDS 0
21589
21590 #endif /* CONFIG_X86_PAE */
21591
21592-static void free_pmds(pmd_t *pmds[])
21593+static void free_pxds(pxd_t *pxds[])
21594 {
21595 int i;
21596
21597- for(i = 0; i < PREALLOCATED_PMDS; i++)
21598- if (pmds[i])
21599- free_page((unsigned long)pmds[i]);
21600+ for(i = 0; i < PREALLOCATED_PXDS; i++)
21601+ if (pxds[i])
21602+ free_page((unsigned long)pxds[i]);
21603 }
21604
21605-static int preallocate_pmds(pmd_t *pmds[])
21606+static int preallocate_pxds(pxd_t *pxds[])
21607 {
21608 int i;
21609 bool failed = false;
21610
21611- for(i = 0; i < PREALLOCATED_PMDS; i++) {
21612- pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
21613- if (pmd == NULL)
21614+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
21615+ pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
21616+ if (pxd == NULL)
21617 failed = true;
21618- pmds[i] = pmd;
21619+ pxds[i] = pxd;
21620 }
21621
21622 if (failed) {
21623- free_pmds(pmds);
21624+ free_pxds(pxds);
21625 return -ENOMEM;
21626 }
21627
21628@@ -203,51 +249,56 @@ static int preallocate_pmds(pmd_t *pmds[
21629 * preallocate which never got a corresponding vma will need to be
21630 * freed manually.
21631 */
21632-static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
21633+static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
21634 {
21635 int i;
21636
21637- for(i = 0; i < PREALLOCATED_PMDS; i++) {
21638+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
21639 pgd_t pgd = pgdp[i];
21640
21641 if (pgd_val(pgd) != 0) {
21642- pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
21643+ pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
21644
21645- pgdp[i] = native_make_pgd(0);
21646+ set_pgd(pgdp + i, native_make_pgd(0));
21647
21648- paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
21649- pmd_free(mm, pmd);
21650+ paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
21651+ pxd_free(mm, pxd);
21652 }
21653 }
21654 }
21655
21656-static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
21657+static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
21658 {
21659- pud_t *pud;
21660+ pyd_t *pyd;
21661 unsigned long addr;
21662 int i;
21663
21664- if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
21665+ if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
21666 return;
21667
21668- pud = pud_offset(pgd, 0);
21669+#ifdef CONFIG_X86_64
21670+ pyd = pyd_offset(mm, 0L);
21671+#else
21672+ pyd = pyd_offset(pgd, 0L);
21673+#endif
21674
21675- for (addr = i = 0; i < PREALLOCATED_PMDS;
21676- i++, pud++, addr += PUD_SIZE) {
21677- pmd_t *pmd = pmds[i];
21678+ for (addr = i = 0; i < PREALLOCATED_PXDS;
21679+ i++, pyd++, addr += PYD_SIZE) {
21680+ pxd_t *pxd = pxds[i];
21681
21682 if (i >= KERNEL_PGD_BOUNDARY)
21683- memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
21684- sizeof(pmd_t) * PTRS_PER_PMD);
21685+ memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
21686+ sizeof(pxd_t) * PTRS_PER_PMD);
21687
21688- pud_populate(mm, pud, pmd);
21689+ pyd_populate(mm, pyd, pxd);
21690 }
21691 }
21692
21693 pgd_t *pgd_alloc(struct mm_struct *mm)
21694 {
21695 pgd_t *pgd;
21696- pmd_t *pmds[PREALLOCATED_PMDS];
21697+ pxd_t *pxds[PREALLOCATED_PXDS];
21698+
21699 unsigned long flags;
21700
21701 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
21702@@ -257,11 +308,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
21703
21704 mm->pgd = pgd;
21705
21706- if (preallocate_pmds(pmds) != 0)
21707+ if (preallocate_pxds(pxds) != 0)
21708 goto out_free_pgd;
21709
21710 if (paravirt_pgd_alloc(mm) != 0)
21711- goto out_free_pmds;
21712+ goto out_free_pxds;
21713
21714 /*
21715 * Make sure that pre-populating the pmds is atomic with
21716@@ -271,14 +322,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
21717 spin_lock_irqsave(&pgd_lock, flags);
21718
21719 pgd_ctor(pgd);
21720- pgd_prepopulate_pmd(mm, pgd, pmds);
21721+ pgd_prepopulate_pxd(mm, pgd, pxds);
21722
21723 spin_unlock_irqrestore(&pgd_lock, flags);
21724
21725 return pgd;
21726
21727-out_free_pmds:
21728- free_pmds(pmds);
21729+out_free_pxds:
21730+ free_pxds(pxds);
21731 out_free_pgd:
21732 free_page((unsigned long)pgd);
21733 out:
21734@@ -287,7 +338,7 @@ out:
21735
21736 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
21737 {
21738- pgd_mop_up_pmds(mm, pgd);
21739+ pgd_mop_up_pxds(mm, pgd);
21740 pgd_dtor(pgd);
21741 paravirt_pgd_free(mm, pgd);
21742 free_page((unsigned long)pgd);
21743diff -urNp linux-2.6.32.41/arch/x86/mm/setup_nx.c linux-2.6.32.41/arch/x86/mm/setup_nx.c
21744--- linux-2.6.32.41/arch/x86/mm/setup_nx.c 2011-03-27 14:31:47.000000000 -0400
21745+++ linux-2.6.32.41/arch/x86/mm/setup_nx.c 2011-04-17 15:56:46.000000000 -0400
21746@@ -4,11 +4,10 @@
21747
21748 #include <asm/pgtable.h>
21749
21750+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
21751 int nx_enabled;
21752
21753-#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
21754-static int disable_nx __cpuinitdata;
21755-
21756+#ifndef CONFIG_PAX_PAGEEXEC
21757 /*
21758 * noexec = on|off
21759 *
21760@@ -22,32 +21,26 @@ static int __init noexec_setup(char *str
21761 if (!str)
21762 return -EINVAL;
21763 if (!strncmp(str, "on", 2)) {
21764- __supported_pte_mask |= _PAGE_NX;
21765- disable_nx = 0;
21766+ nx_enabled = 1;
21767 } else if (!strncmp(str, "off", 3)) {
21768- disable_nx = 1;
21769- __supported_pte_mask &= ~_PAGE_NX;
21770+ nx_enabled = 0;
21771 }
21772 return 0;
21773 }
21774 early_param("noexec", noexec_setup);
21775 #endif
21776+#endif
21777
21778 #ifdef CONFIG_X86_PAE
21779 void __init set_nx(void)
21780 {
21781- unsigned int v[4], l, h;
21782+ if (!nx_enabled && cpu_has_nx) {
21783+ unsigned l, h;
21784
21785- if (cpu_has_pae && (cpuid_eax(0x80000000) > 0x80000001)) {
21786- cpuid(0x80000001, &v[0], &v[1], &v[2], &v[3]);
21787-
21788- if ((v[3] & (1 << 20)) && !disable_nx) {
21789- rdmsr(MSR_EFER, l, h);
21790- l |= EFER_NX;
21791- wrmsr(MSR_EFER, l, h);
21792- nx_enabled = 1;
21793- __supported_pte_mask |= _PAGE_NX;
21794- }
21795+ __supported_pte_mask &= ~_PAGE_NX;
21796+ rdmsr(MSR_EFER, l, h);
21797+ l &= ~EFER_NX;
21798+ wrmsr(MSR_EFER, l, h);
21799 }
21800 }
21801 #else
21802@@ -62,7 +55,7 @@ void __cpuinit check_efer(void)
21803 unsigned long efer;
21804
21805 rdmsrl(MSR_EFER, efer);
21806- if (!(efer & EFER_NX) || disable_nx)
21807+ if (!(efer & EFER_NX) || !nx_enabled)
21808 __supported_pte_mask &= ~_PAGE_NX;
21809 }
21810 #endif
21811diff -urNp linux-2.6.32.41/arch/x86/mm/tlb.c linux-2.6.32.41/arch/x86/mm/tlb.c
21812--- linux-2.6.32.41/arch/x86/mm/tlb.c 2011-03-27 14:31:47.000000000 -0400
21813+++ linux-2.6.32.41/arch/x86/mm/tlb.c 2011-04-23 12:56:10.000000000 -0400
21814@@ -61,7 +61,11 @@ void leave_mm(int cpu)
21815 BUG();
21816 cpumask_clear_cpu(cpu,
21817 mm_cpumask(percpu_read(cpu_tlbstate.active_mm)));
21818+
21819+#ifndef CONFIG_PAX_PER_CPU_PGD
21820 load_cr3(swapper_pg_dir);
21821+#endif
21822+
21823 }
21824 EXPORT_SYMBOL_GPL(leave_mm);
21825
21826diff -urNp linux-2.6.32.41/arch/x86/oprofile/backtrace.c linux-2.6.32.41/arch/x86/oprofile/backtrace.c
21827--- linux-2.6.32.41/arch/x86/oprofile/backtrace.c 2011-03-27 14:31:47.000000000 -0400
21828+++ linux-2.6.32.41/arch/x86/oprofile/backtrace.c 2011-04-17 15:56:46.000000000 -0400
21829@@ -57,7 +57,7 @@ static struct frame_head *dump_user_back
21830 struct frame_head bufhead[2];
21831
21832 /* Also check accessibility of one struct frame_head beyond */
21833- if (!access_ok(VERIFY_READ, head, sizeof(bufhead)))
21834+ if (!__access_ok(VERIFY_READ, head, sizeof(bufhead)))
21835 return NULL;
21836 if (__copy_from_user_inatomic(bufhead, head, sizeof(bufhead)))
21837 return NULL;
21838@@ -77,7 +77,7 @@ x86_backtrace(struct pt_regs * const reg
21839 {
21840 struct frame_head *head = (struct frame_head *)frame_pointer(regs);
21841
21842- if (!user_mode_vm(regs)) {
21843+ if (!user_mode(regs)) {
21844 unsigned long stack = kernel_stack_pointer(regs);
21845 if (depth)
21846 dump_trace(NULL, regs, (unsigned long *)stack, 0,
21847diff -urNp linux-2.6.32.41/arch/x86/oprofile/op_model_p4.c linux-2.6.32.41/arch/x86/oprofile/op_model_p4.c
21848--- linux-2.6.32.41/arch/x86/oprofile/op_model_p4.c 2011-03-27 14:31:47.000000000 -0400
21849+++ linux-2.6.32.41/arch/x86/oprofile/op_model_p4.c 2011-04-17 15:56:46.000000000 -0400
21850@@ -50,7 +50,7 @@ static inline void setup_num_counters(vo
21851 #endif
21852 }
21853
21854-static int inline addr_increment(void)
21855+static inline int addr_increment(void)
21856 {
21857 #ifdef CONFIG_SMP
21858 return smp_num_siblings == 2 ? 2 : 1;
21859diff -urNp linux-2.6.32.41/arch/x86/pci/common.c linux-2.6.32.41/arch/x86/pci/common.c
21860--- linux-2.6.32.41/arch/x86/pci/common.c 2011-03-27 14:31:47.000000000 -0400
21861+++ linux-2.6.32.41/arch/x86/pci/common.c 2011-04-23 12:56:10.000000000 -0400
21862@@ -31,8 +31,8 @@ int noioapicreroute = 1;
21863 int pcibios_last_bus = -1;
21864 unsigned long pirq_table_addr;
21865 struct pci_bus *pci_root_bus;
21866-struct pci_raw_ops *raw_pci_ops;
21867-struct pci_raw_ops *raw_pci_ext_ops;
21868+const struct pci_raw_ops *raw_pci_ops;
21869+const struct pci_raw_ops *raw_pci_ext_ops;
21870
21871 int raw_pci_read(unsigned int domain, unsigned int bus, unsigned int devfn,
21872 int reg, int len, u32 *val)
21873diff -urNp linux-2.6.32.41/arch/x86/pci/direct.c linux-2.6.32.41/arch/x86/pci/direct.c
21874--- linux-2.6.32.41/arch/x86/pci/direct.c 2011-03-27 14:31:47.000000000 -0400
21875+++ linux-2.6.32.41/arch/x86/pci/direct.c 2011-04-17 15:56:46.000000000 -0400
21876@@ -79,7 +79,7 @@ static int pci_conf1_write(unsigned int
21877
21878 #undef PCI_CONF1_ADDRESS
21879
21880-struct pci_raw_ops pci_direct_conf1 = {
21881+const struct pci_raw_ops pci_direct_conf1 = {
21882 .read = pci_conf1_read,
21883 .write = pci_conf1_write,
21884 };
21885@@ -173,7 +173,7 @@ static int pci_conf2_write(unsigned int
21886
21887 #undef PCI_CONF2_ADDRESS
21888
21889-struct pci_raw_ops pci_direct_conf2 = {
21890+const struct pci_raw_ops pci_direct_conf2 = {
21891 .read = pci_conf2_read,
21892 .write = pci_conf2_write,
21893 };
21894@@ -189,7 +189,7 @@ struct pci_raw_ops pci_direct_conf2 = {
21895 * This should be close to trivial, but it isn't, because there are buggy
21896 * chipsets (yes, you guessed it, by Intel and Compaq) that have no class ID.
21897 */
21898-static int __init pci_sanity_check(struct pci_raw_ops *o)
21899+static int __init pci_sanity_check(const struct pci_raw_ops *o)
21900 {
21901 u32 x = 0;
21902 int year, devfn;
21903diff -urNp linux-2.6.32.41/arch/x86/pci/mmconfig_32.c linux-2.6.32.41/arch/x86/pci/mmconfig_32.c
21904--- linux-2.6.32.41/arch/x86/pci/mmconfig_32.c 2011-03-27 14:31:47.000000000 -0400
21905+++ linux-2.6.32.41/arch/x86/pci/mmconfig_32.c 2011-04-17 15:56:46.000000000 -0400
21906@@ -125,7 +125,7 @@ static int pci_mmcfg_write(unsigned int
21907 return 0;
21908 }
21909
21910-static struct pci_raw_ops pci_mmcfg = {
21911+static const struct pci_raw_ops pci_mmcfg = {
21912 .read = pci_mmcfg_read,
21913 .write = pci_mmcfg_write,
21914 };
21915diff -urNp linux-2.6.32.41/arch/x86/pci/mmconfig_64.c linux-2.6.32.41/arch/x86/pci/mmconfig_64.c
21916--- linux-2.6.32.41/arch/x86/pci/mmconfig_64.c 2011-03-27 14:31:47.000000000 -0400
21917+++ linux-2.6.32.41/arch/x86/pci/mmconfig_64.c 2011-04-17 15:56:46.000000000 -0400
21918@@ -104,7 +104,7 @@ static int pci_mmcfg_write(unsigned int
21919 return 0;
21920 }
21921
21922-static struct pci_raw_ops pci_mmcfg = {
21923+static const struct pci_raw_ops pci_mmcfg = {
21924 .read = pci_mmcfg_read,
21925 .write = pci_mmcfg_write,
21926 };
21927diff -urNp linux-2.6.32.41/arch/x86/pci/numaq_32.c linux-2.6.32.41/arch/x86/pci/numaq_32.c
21928--- linux-2.6.32.41/arch/x86/pci/numaq_32.c 2011-03-27 14:31:47.000000000 -0400
21929+++ linux-2.6.32.41/arch/x86/pci/numaq_32.c 2011-04-17 15:56:46.000000000 -0400
21930@@ -112,7 +112,7 @@ static int pci_conf1_mq_write(unsigned i
21931
21932 #undef PCI_CONF1_MQ_ADDRESS
21933
21934-static struct pci_raw_ops pci_direct_conf1_mq = {
21935+static const struct pci_raw_ops pci_direct_conf1_mq = {
21936 .read = pci_conf1_mq_read,
21937 .write = pci_conf1_mq_write
21938 };
21939diff -urNp linux-2.6.32.41/arch/x86/pci/olpc.c linux-2.6.32.41/arch/x86/pci/olpc.c
21940--- linux-2.6.32.41/arch/x86/pci/olpc.c 2011-03-27 14:31:47.000000000 -0400
21941+++ linux-2.6.32.41/arch/x86/pci/olpc.c 2011-04-17 15:56:46.000000000 -0400
21942@@ -297,7 +297,7 @@ static int pci_olpc_write(unsigned int s
21943 return 0;
21944 }
21945
21946-static struct pci_raw_ops pci_olpc_conf = {
21947+static const struct pci_raw_ops pci_olpc_conf = {
21948 .read = pci_olpc_read,
21949 .write = pci_olpc_write,
21950 };
21951diff -urNp linux-2.6.32.41/arch/x86/pci/pcbios.c linux-2.6.32.41/arch/x86/pci/pcbios.c
21952--- linux-2.6.32.41/arch/x86/pci/pcbios.c 2011-03-27 14:31:47.000000000 -0400
21953+++ linux-2.6.32.41/arch/x86/pci/pcbios.c 2011-04-17 15:56:46.000000000 -0400
21954@@ -56,50 +56,93 @@ union bios32 {
21955 static struct {
21956 unsigned long address;
21957 unsigned short segment;
21958-} bios32_indirect = { 0, __KERNEL_CS };
21959+} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
21960
21961 /*
21962 * Returns the entry point for the given service, NULL on error
21963 */
21964
21965-static unsigned long bios32_service(unsigned long service)
21966+static unsigned long __devinit bios32_service(unsigned long service)
21967 {
21968 unsigned char return_code; /* %al */
21969 unsigned long address; /* %ebx */
21970 unsigned long length; /* %ecx */
21971 unsigned long entry; /* %edx */
21972 unsigned long flags;
21973+ struct desc_struct d, *gdt;
21974
21975 local_irq_save(flags);
21976- __asm__("lcall *(%%edi); cld"
21977+
21978+ gdt = get_cpu_gdt_table(smp_processor_id());
21979+
21980+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
21981+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
21982+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
21983+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
21984+
21985+ __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
21986 : "=a" (return_code),
21987 "=b" (address),
21988 "=c" (length),
21989 "=d" (entry)
21990 : "0" (service),
21991 "1" (0),
21992- "D" (&bios32_indirect));
21993+ "D" (&bios32_indirect),
21994+ "r"(__PCIBIOS_DS)
21995+ : "memory");
21996+
21997+ pax_open_kernel();
21998+ gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
21999+ gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
22000+ gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
22001+ gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
22002+ pax_close_kernel();
22003+
22004 local_irq_restore(flags);
22005
22006 switch (return_code) {
22007- case 0:
22008- return address + entry;
22009- case 0x80: /* Not present */
22010- printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
22011- return 0;
22012- default: /* Shouldn't happen */
22013- printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
22014- service, return_code);
22015+ case 0: {
22016+ int cpu;
22017+ unsigned char flags;
22018+
22019+ printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
22020+ if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
22021+ printk(KERN_WARNING "bios32_service: not valid\n");
22022 return 0;
22023+ }
22024+ address = address + PAGE_OFFSET;
22025+ length += 16UL; /* some BIOSs underreport this... */
22026+ flags = 4;
22027+ if (length >= 64*1024*1024) {
22028+ length >>= PAGE_SHIFT;
22029+ flags |= 8;
22030+ }
22031+
22032+ for (cpu = 0; cpu < NR_CPUS; cpu++) {
22033+ gdt = get_cpu_gdt_table(cpu);
22034+ pack_descriptor(&d, address, length, 0x9b, flags);
22035+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
22036+ pack_descriptor(&d, address, length, 0x93, flags);
22037+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
22038+ }
22039+ return entry;
22040+ }
22041+ case 0x80: /* Not present */
22042+ printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
22043+ return 0;
22044+ default: /* Shouldn't happen */
22045+ printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
22046+ service, return_code);
22047+ return 0;
22048 }
22049 }
22050
22051 static struct {
22052 unsigned long address;
22053 unsigned short segment;
22054-} pci_indirect = { 0, __KERNEL_CS };
22055+} pci_indirect __read_only = { 0, __PCIBIOS_CS };
22056
22057-static int pci_bios_present;
22058+static int pci_bios_present __read_only;
22059
22060 static int __devinit check_pcibios(void)
22061 {
22062@@ -108,11 +151,13 @@ static int __devinit check_pcibios(void)
22063 unsigned long flags, pcibios_entry;
22064
22065 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
22066- pci_indirect.address = pcibios_entry + PAGE_OFFSET;
22067+ pci_indirect.address = pcibios_entry;
22068
22069 local_irq_save(flags);
22070- __asm__(
22071- "lcall *(%%edi); cld\n\t"
22072+ __asm__("movw %w6, %%ds\n\t"
22073+ "lcall *%%ss:(%%edi); cld\n\t"
22074+ "push %%ss\n\t"
22075+ "pop %%ds\n\t"
22076 "jc 1f\n\t"
22077 "xor %%ah, %%ah\n"
22078 "1:"
22079@@ -121,7 +166,8 @@ static int __devinit check_pcibios(void)
22080 "=b" (ebx),
22081 "=c" (ecx)
22082 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
22083- "D" (&pci_indirect)
22084+ "D" (&pci_indirect),
22085+ "r" (__PCIBIOS_DS)
22086 : "memory");
22087 local_irq_restore(flags);
22088
22089@@ -165,7 +211,10 @@ static int pci_bios_read(unsigned int se
22090
22091 switch (len) {
22092 case 1:
22093- __asm__("lcall *(%%esi); cld\n\t"
22094+ __asm__("movw %w6, %%ds\n\t"
22095+ "lcall *%%ss:(%%esi); cld\n\t"
22096+ "push %%ss\n\t"
22097+ "pop %%ds\n\t"
22098 "jc 1f\n\t"
22099 "xor %%ah, %%ah\n"
22100 "1:"
22101@@ -174,7 +223,8 @@ static int pci_bios_read(unsigned int se
22102 : "1" (PCIBIOS_READ_CONFIG_BYTE),
22103 "b" (bx),
22104 "D" ((long)reg),
22105- "S" (&pci_indirect));
22106+ "S" (&pci_indirect),
22107+ "r" (__PCIBIOS_DS));
22108 /*
22109 * Zero-extend the result beyond 8 bits, do not trust the
22110 * BIOS having done it:
22111@@ -182,7 +232,10 @@ static int pci_bios_read(unsigned int se
22112 *value &= 0xff;
22113 break;
22114 case 2:
22115- __asm__("lcall *(%%esi); cld\n\t"
22116+ __asm__("movw %w6, %%ds\n\t"
22117+ "lcall *%%ss:(%%esi); cld\n\t"
22118+ "push %%ss\n\t"
22119+ "pop %%ds\n\t"
22120 "jc 1f\n\t"
22121 "xor %%ah, %%ah\n"
22122 "1:"
22123@@ -191,7 +244,8 @@ static int pci_bios_read(unsigned int se
22124 : "1" (PCIBIOS_READ_CONFIG_WORD),
22125 "b" (bx),
22126 "D" ((long)reg),
22127- "S" (&pci_indirect));
22128+ "S" (&pci_indirect),
22129+ "r" (__PCIBIOS_DS));
22130 /*
22131 * Zero-extend the result beyond 16 bits, do not trust the
22132 * BIOS having done it:
22133@@ -199,7 +253,10 @@ static int pci_bios_read(unsigned int se
22134 *value &= 0xffff;
22135 break;
22136 case 4:
22137- __asm__("lcall *(%%esi); cld\n\t"
22138+ __asm__("movw %w6, %%ds\n\t"
22139+ "lcall *%%ss:(%%esi); cld\n\t"
22140+ "push %%ss\n\t"
22141+ "pop %%ds\n\t"
22142 "jc 1f\n\t"
22143 "xor %%ah, %%ah\n"
22144 "1:"
22145@@ -208,7 +265,8 @@ static int pci_bios_read(unsigned int se
22146 : "1" (PCIBIOS_READ_CONFIG_DWORD),
22147 "b" (bx),
22148 "D" ((long)reg),
22149- "S" (&pci_indirect));
22150+ "S" (&pci_indirect),
22151+ "r" (__PCIBIOS_DS));
22152 break;
22153 }
22154
22155@@ -231,7 +289,10 @@ static int pci_bios_write(unsigned int s
22156
22157 switch (len) {
22158 case 1:
22159- __asm__("lcall *(%%esi); cld\n\t"
22160+ __asm__("movw %w6, %%ds\n\t"
22161+ "lcall *%%ss:(%%esi); cld\n\t"
22162+ "push %%ss\n\t"
22163+ "pop %%ds\n\t"
22164 "jc 1f\n\t"
22165 "xor %%ah, %%ah\n"
22166 "1:"
22167@@ -240,10 +301,14 @@ static int pci_bios_write(unsigned int s
22168 "c" (value),
22169 "b" (bx),
22170 "D" ((long)reg),
22171- "S" (&pci_indirect));
22172+ "S" (&pci_indirect),
22173+ "r" (__PCIBIOS_DS));
22174 break;
22175 case 2:
22176- __asm__("lcall *(%%esi); cld\n\t"
22177+ __asm__("movw %w6, %%ds\n\t"
22178+ "lcall *%%ss:(%%esi); cld\n\t"
22179+ "push %%ss\n\t"
22180+ "pop %%ds\n\t"
22181 "jc 1f\n\t"
22182 "xor %%ah, %%ah\n"
22183 "1:"
22184@@ -252,10 +317,14 @@ static int pci_bios_write(unsigned int s
22185 "c" (value),
22186 "b" (bx),
22187 "D" ((long)reg),
22188- "S" (&pci_indirect));
22189+ "S" (&pci_indirect),
22190+ "r" (__PCIBIOS_DS));
22191 break;
22192 case 4:
22193- __asm__("lcall *(%%esi); cld\n\t"
22194+ __asm__("movw %w6, %%ds\n\t"
22195+ "lcall *%%ss:(%%esi); cld\n\t"
22196+ "push %%ss\n\t"
22197+ "pop %%ds\n\t"
22198 "jc 1f\n\t"
22199 "xor %%ah, %%ah\n"
22200 "1:"
22201@@ -264,7 +333,8 @@ static int pci_bios_write(unsigned int s
22202 "c" (value),
22203 "b" (bx),
22204 "D" ((long)reg),
22205- "S" (&pci_indirect));
22206+ "S" (&pci_indirect),
22207+ "r" (__PCIBIOS_DS));
22208 break;
22209 }
22210
22211@@ -278,7 +348,7 @@ static int pci_bios_write(unsigned int s
22212 * Function table for BIOS32 access
22213 */
22214
22215-static struct pci_raw_ops pci_bios_access = {
22216+static const struct pci_raw_ops pci_bios_access = {
22217 .read = pci_bios_read,
22218 .write = pci_bios_write
22219 };
22220@@ -287,7 +357,7 @@ static struct pci_raw_ops pci_bios_acces
22221 * Try to find PCI BIOS.
22222 */
22223
22224-static struct pci_raw_ops * __devinit pci_find_bios(void)
22225+static const struct pci_raw_ops * __devinit pci_find_bios(void)
22226 {
22227 union bios32 *check;
22228 unsigned char sum;
22229@@ -368,10 +438,13 @@ struct irq_routing_table * pcibios_get_i
22230
22231 DBG("PCI: Fetching IRQ routing table... ");
22232 __asm__("push %%es\n\t"
22233+ "movw %w8, %%ds\n\t"
22234 "push %%ds\n\t"
22235 "pop %%es\n\t"
22236- "lcall *(%%esi); cld\n\t"
22237+ "lcall *%%ss:(%%esi); cld\n\t"
22238 "pop %%es\n\t"
22239+ "push %%ss\n\t"
22240+ "pop %%ds\n"
22241 "jc 1f\n\t"
22242 "xor %%ah, %%ah\n"
22243 "1:"
22244@@ -382,7 +455,8 @@ struct irq_routing_table * pcibios_get_i
22245 "1" (0),
22246 "D" ((long) &opt),
22247 "S" (&pci_indirect),
22248- "m" (opt)
22249+ "m" (opt),
22250+ "r" (__PCIBIOS_DS)
22251 : "memory");
22252 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
22253 if (ret & 0xff00)
22254@@ -406,7 +480,10 @@ int pcibios_set_irq_routing(struct pci_d
22255 {
22256 int ret;
22257
22258- __asm__("lcall *(%%esi); cld\n\t"
22259+ __asm__("movw %w5, %%ds\n\t"
22260+ "lcall *%%ss:(%%esi); cld\n\t"
22261+ "push %%ss\n\t"
22262+ "pop %%ds\n"
22263 "jc 1f\n\t"
22264 "xor %%ah, %%ah\n"
22265 "1:"
22266@@ -414,7 +491,8 @@ int pcibios_set_irq_routing(struct pci_d
22267 : "0" (PCIBIOS_SET_PCI_HW_INT),
22268 "b" ((dev->bus->number << 8) | dev->devfn),
22269 "c" ((irq << 8) | (pin + 10)),
22270- "S" (&pci_indirect));
22271+ "S" (&pci_indirect),
22272+ "r" (__PCIBIOS_DS));
22273 return !(ret & 0xff00);
22274 }
22275 EXPORT_SYMBOL(pcibios_set_irq_routing);
22276diff -urNp linux-2.6.32.41/arch/x86/power/cpu.c linux-2.6.32.41/arch/x86/power/cpu.c
22277--- linux-2.6.32.41/arch/x86/power/cpu.c 2011-03-27 14:31:47.000000000 -0400
22278+++ linux-2.6.32.41/arch/x86/power/cpu.c 2011-04-17 15:56:46.000000000 -0400
22279@@ -129,7 +129,7 @@ static void do_fpu_end(void)
22280 static void fix_processor_context(void)
22281 {
22282 int cpu = smp_processor_id();
22283- struct tss_struct *t = &per_cpu(init_tss, cpu);
22284+ struct tss_struct *t = init_tss + cpu;
22285
22286 set_tss_desc(cpu, t); /*
22287 * This just modifies memory; should not be
22288@@ -139,7 +139,9 @@ static void fix_processor_context(void)
22289 */
22290
22291 #ifdef CONFIG_X86_64
22292+ pax_open_kernel();
22293 get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
22294+ pax_close_kernel();
22295
22296 syscall_init(); /* This sets MSR_*STAR and related */
22297 #endif
22298diff -urNp linux-2.6.32.41/arch/x86/vdso/Makefile linux-2.6.32.41/arch/x86/vdso/Makefile
22299--- linux-2.6.32.41/arch/x86/vdso/Makefile 2011-03-27 14:31:47.000000000 -0400
22300+++ linux-2.6.32.41/arch/x86/vdso/Makefile 2011-04-17 15:56:46.000000000 -0400
22301@@ -122,7 +122,7 @@ quiet_cmd_vdso = VDSO $@
22302 $(VDSO_LDFLAGS) $(VDSO_LDFLAGS_$(filter %.lds,$(^F))) \
22303 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^)
22304
22305-VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
22306+VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
22307 GCOV_PROFILE := n
22308
22309 #
22310diff -urNp linux-2.6.32.41/arch/x86/vdso/vclock_gettime.c linux-2.6.32.41/arch/x86/vdso/vclock_gettime.c
22311--- linux-2.6.32.41/arch/x86/vdso/vclock_gettime.c 2011-03-27 14:31:47.000000000 -0400
22312+++ linux-2.6.32.41/arch/x86/vdso/vclock_gettime.c 2011-04-17 15:56:46.000000000 -0400
22313@@ -22,24 +22,48 @@
22314 #include <asm/hpet.h>
22315 #include <asm/unistd.h>
22316 #include <asm/io.h>
22317+#include <asm/fixmap.h>
22318 #include "vextern.h"
22319
22320 #define gtod vdso_vsyscall_gtod_data
22321
22322+notrace noinline long __vdso_fallback_time(long *t)
22323+{
22324+ long secs;
22325+ asm volatile("syscall"
22326+ : "=a" (secs)
22327+ : "0" (__NR_time),"D" (t) : "r11", "cx", "memory");
22328+ return secs;
22329+}
22330+
22331 notrace static long vdso_fallback_gettime(long clock, struct timespec *ts)
22332 {
22333 long ret;
22334 asm("syscall" : "=a" (ret) :
22335- "0" (__NR_clock_gettime),"D" (clock), "S" (ts) : "memory");
22336+ "0" (__NR_clock_gettime),"D" (clock), "S" (ts) : "r11", "cx", "memory");
22337 return ret;
22338 }
22339
22340+notrace static inline cycle_t __vdso_vread_hpet(void)
22341+{
22342+ return readl((const void __iomem *)fix_to_virt(VSYSCALL_HPET) + 0xf0);
22343+}
22344+
22345+notrace static inline cycle_t __vdso_vread_tsc(void)
22346+{
22347+ cycle_t ret = (cycle_t)vget_cycles();
22348+
22349+ return ret >= gtod->clock.cycle_last ? ret : gtod->clock.cycle_last;
22350+}
22351+
22352 notrace static inline long vgetns(void)
22353 {
22354 long v;
22355- cycles_t (*vread)(void);
22356- vread = gtod->clock.vread;
22357- v = (vread() - gtod->clock.cycle_last) & gtod->clock.mask;
22358+ if (gtod->clock.name[0] == 't' && gtod->clock.name[1] == 's' && gtod->clock.name[2] == 'c' && !gtod->clock.name[3])
22359+ v = __vdso_vread_tsc();
22360+ else
22361+ v = __vdso_vread_hpet();
22362+ v = (v - gtod->clock.cycle_last) & gtod->clock.mask;
22363 return (v * gtod->clock.mult) >> gtod->clock.shift;
22364 }
22365
22366@@ -113,7 +137,9 @@ notrace static noinline int do_monotonic
22367
22368 notrace int __vdso_clock_gettime(clockid_t clock, struct timespec *ts)
22369 {
22370- if (likely(gtod->sysctl_enabled))
22371+ if (likely(gtod->sysctl_enabled &&
22372+ ((gtod->clock.name[0] == 'h' && gtod->clock.name[1] == 'p' && gtod->clock.name[2] == 'e' && gtod->clock.name[3] == 't' && !gtod->clock.name[4]) ||
22373+ (gtod->clock.name[0] == 't' && gtod->clock.name[1] == 's' && gtod->clock.name[2] == 'c' && !gtod->clock.name[3]))))
22374 switch (clock) {
22375 case CLOCK_REALTIME:
22376 if (likely(gtod->clock.vread))
22377@@ -133,10 +159,20 @@ notrace int __vdso_clock_gettime(clockid
22378 int clock_gettime(clockid_t, struct timespec *)
22379 __attribute__((weak, alias("__vdso_clock_gettime")));
22380
22381-notrace int __vdso_gettimeofday(struct timeval *tv, struct timezone *tz)
22382+notrace noinline int __vdso_fallback_gettimeofday(struct timeval *tv, struct timezone *tz)
22383 {
22384 long ret;
22385- if (likely(gtod->sysctl_enabled && gtod->clock.vread)) {
22386+ asm("syscall" : "=a" (ret) :
22387+ "0" (__NR_gettimeofday), "D" (tv), "S" (tz) : "r11", "cx", "memory");
22388+ return ret;
22389+}
22390+
22391+notrace int __vdso_gettimeofday(struct timeval *tv, struct timezone *tz)
22392+{
22393+ if (likely(gtod->sysctl_enabled &&
22394+ ((gtod->clock.name[0] == 'h' && gtod->clock.name[1] == 'p' && gtod->clock.name[2] == 'e' && gtod->clock.name[3] == 't' && !gtod->clock.name[4]) ||
22395+ (gtod->clock.name[0] == 't' && gtod->clock.name[1] == 's' && gtod->clock.name[2] == 'c' && !gtod->clock.name[3]))))
22396+ {
22397 if (likely(tv != NULL)) {
22398 BUILD_BUG_ON(offsetof(struct timeval, tv_usec) !=
22399 offsetof(struct timespec, tv_nsec) ||
22400@@ -151,9 +187,7 @@ notrace int __vdso_gettimeofday(struct t
22401 }
22402 return 0;
22403 }
22404- asm("syscall" : "=a" (ret) :
22405- "0" (__NR_gettimeofday), "D" (tv), "S" (tz) : "memory");
22406- return ret;
22407+ return __vdso_fallback_gettimeofday(tv, tz);
22408 }
22409 int gettimeofday(struct timeval *, struct timezone *)
22410 __attribute__((weak, alias("__vdso_gettimeofday")));
22411diff -urNp linux-2.6.32.41/arch/x86/vdso/vdso32-setup.c linux-2.6.32.41/arch/x86/vdso/vdso32-setup.c
22412--- linux-2.6.32.41/arch/x86/vdso/vdso32-setup.c 2011-03-27 14:31:47.000000000 -0400
22413+++ linux-2.6.32.41/arch/x86/vdso/vdso32-setup.c 2011-04-23 12:56:10.000000000 -0400
22414@@ -25,6 +25,7 @@
22415 #include <asm/tlbflush.h>
22416 #include <asm/vdso.h>
22417 #include <asm/proto.h>
22418+#include <asm/mman.h>
22419
22420 enum {
22421 VDSO_DISABLED = 0,
22422@@ -226,7 +227,7 @@ static inline void map_compat_vdso(int m
22423 void enable_sep_cpu(void)
22424 {
22425 int cpu = get_cpu();
22426- struct tss_struct *tss = &per_cpu(init_tss, cpu);
22427+ struct tss_struct *tss = init_tss + cpu;
22428
22429 if (!boot_cpu_has(X86_FEATURE_SEP)) {
22430 put_cpu();
22431@@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
22432 gate_vma.vm_start = FIXADDR_USER_START;
22433 gate_vma.vm_end = FIXADDR_USER_END;
22434 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
22435- gate_vma.vm_page_prot = __P101;
22436+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
22437 /*
22438 * Make sure the vDSO gets into every core dump.
22439 * Dumping its contents makes post-mortem fully interpretable later
22440@@ -331,14 +332,14 @@ int arch_setup_additional_pages(struct l
22441 if (compat)
22442 addr = VDSO_HIGH_BASE;
22443 else {
22444- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
22445+ addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
22446 if (IS_ERR_VALUE(addr)) {
22447 ret = addr;
22448 goto up_fail;
22449 }
22450 }
22451
22452- current->mm->context.vdso = (void *)addr;
22453+ current->mm->context.vdso = addr;
22454
22455 if (compat_uses_vma || !compat) {
22456 /*
22457@@ -361,11 +362,11 @@ int arch_setup_additional_pages(struct l
22458 }
22459
22460 current_thread_info()->sysenter_return =
22461- VDSO32_SYMBOL(addr, SYSENTER_RETURN);
22462+ (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
22463
22464 up_fail:
22465 if (ret)
22466- current->mm->context.vdso = NULL;
22467+ current->mm->context.vdso = 0;
22468
22469 up_write(&mm->mmap_sem);
22470
22471@@ -413,8 +414,14 @@ __initcall(ia32_binfmt_init);
22472
22473 const char *arch_vma_name(struct vm_area_struct *vma)
22474 {
22475- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
22476+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
22477 return "[vdso]";
22478+
22479+#ifdef CONFIG_PAX_SEGMEXEC
22480+ if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
22481+ return "[vdso]";
22482+#endif
22483+
22484 return NULL;
22485 }
22486
22487@@ -423,7 +430,7 @@ struct vm_area_struct *get_gate_vma(stru
22488 struct mm_struct *mm = tsk->mm;
22489
22490 /* Check to see if this task was created in compat vdso mode */
22491- if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
22492+ if (mm && mm->context.vdso == VDSO_HIGH_BASE)
22493 return &gate_vma;
22494 return NULL;
22495 }
22496diff -urNp linux-2.6.32.41/arch/x86/vdso/vdso.lds.S linux-2.6.32.41/arch/x86/vdso/vdso.lds.S
22497--- linux-2.6.32.41/arch/x86/vdso/vdso.lds.S 2011-03-27 14:31:47.000000000 -0400
22498+++ linux-2.6.32.41/arch/x86/vdso/vdso.lds.S 2011-06-06 17:35:35.000000000 -0400
22499@@ -35,3 +35,9 @@ VDSO64_PRELINK = VDSO_PRELINK;
22500 #define VEXTERN(x) VDSO64_ ## x = vdso_ ## x;
22501 #include "vextern.h"
22502 #undef VEXTERN
22503+
22504+#define VEXTERN(x) VDSO64_ ## x = __vdso_ ## x;
22505+VEXTERN(fallback_gettimeofday)
22506+VEXTERN(fallback_time)
22507+VEXTERN(getcpu)
22508+#undef VEXTERN
22509diff -urNp linux-2.6.32.41/arch/x86/vdso/vextern.h linux-2.6.32.41/arch/x86/vdso/vextern.h
22510--- linux-2.6.32.41/arch/x86/vdso/vextern.h 2011-03-27 14:31:47.000000000 -0400
22511+++ linux-2.6.32.41/arch/x86/vdso/vextern.h 2011-04-17 15:56:46.000000000 -0400
22512@@ -11,6 +11,5 @@
22513 put into vextern.h and be referenced as a pointer with vdso prefix.
22514 The main kernel later fills in the values. */
22515
22516-VEXTERN(jiffies)
22517 VEXTERN(vgetcpu_mode)
22518 VEXTERN(vsyscall_gtod_data)
22519diff -urNp linux-2.6.32.41/arch/x86/vdso/vma.c linux-2.6.32.41/arch/x86/vdso/vma.c
22520--- linux-2.6.32.41/arch/x86/vdso/vma.c 2011-03-27 14:31:47.000000000 -0400
22521+++ linux-2.6.32.41/arch/x86/vdso/vma.c 2011-04-17 15:56:46.000000000 -0400
22522@@ -57,7 +57,7 @@ static int __init init_vdso_vars(void)
22523 if (!vbase)
22524 goto oom;
22525
22526- if (memcmp(vbase, "\177ELF", 4)) {
22527+ if (memcmp(vbase, ELFMAG, SELFMAG)) {
22528 printk("VDSO: I'm broken; not ELF\n");
22529 vdso_enabled = 0;
22530 }
22531@@ -66,6 +66,7 @@ static int __init init_vdso_vars(void)
22532 *(typeof(__ ## x) **) var_ref(VDSO64_SYMBOL(vbase, x), #x) = &__ ## x;
22533 #include "vextern.h"
22534 #undef VEXTERN
22535+ vunmap(vbase);
22536 return 0;
22537
22538 oom:
22539@@ -116,7 +117,7 @@ int arch_setup_additional_pages(struct l
22540 goto up_fail;
22541 }
22542
22543- current->mm->context.vdso = (void *)addr;
22544+ current->mm->context.vdso = addr;
22545
22546 ret = install_special_mapping(mm, addr, vdso_size,
22547 VM_READ|VM_EXEC|
22548@@ -124,7 +125,7 @@ int arch_setup_additional_pages(struct l
22549 VM_ALWAYSDUMP,
22550 vdso_pages);
22551 if (ret) {
22552- current->mm->context.vdso = NULL;
22553+ current->mm->context.vdso = 0;
22554 goto up_fail;
22555 }
22556
22557@@ -132,10 +133,3 @@ up_fail:
22558 up_write(&mm->mmap_sem);
22559 return ret;
22560 }
22561-
22562-static __init int vdso_setup(char *s)
22563-{
22564- vdso_enabled = simple_strtoul(s, NULL, 0);
22565- return 0;
22566-}
22567-__setup("vdso=", vdso_setup);
22568diff -urNp linux-2.6.32.41/arch/x86/xen/enlighten.c linux-2.6.32.41/arch/x86/xen/enlighten.c
22569--- linux-2.6.32.41/arch/x86/xen/enlighten.c 2011-03-27 14:31:47.000000000 -0400
22570+++ linux-2.6.32.41/arch/x86/xen/enlighten.c 2011-05-22 23:02:03.000000000 -0400
22571@@ -71,8 +71,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
22572
22573 struct shared_info xen_dummy_shared_info;
22574
22575-void *xen_initial_gdt;
22576-
22577 /*
22578 * Point at some empty memory to start with. We map the real shared_info
22579 * page as soon as fixmap is up and running.
22580@@ -548,7 +546,7 @@ static void xen_write_idt_entry(gate_des
22581
22582 preempt_disable();
22583
22584- start = __get_cpu_var(idt_desc).address;
22585+ start = (unsigned long)__get_cpu_var(idt_desc).address;
22586 end = start + __get_cpu_var(idt_desc).size + 1;
22587
22588 xen_mc_flush();
22589@@ -993,7 +991,7 @@ static const struct pv_apic_ops xen_apic
22590 #endif
22591 };
22592
22593-static void xen_reboot(int reason)
22594+static __noreturn void xen_reboot(int reason)
22595 {
22596 struct sched_shutdown r = { .reason = reason };
22597
22598@@ -1001,17 +999,17 @@ static void xen_reboot(int reason)
22599 BUG();
22600 }
22601
22602-static void xen_restart(char *msg)
22603+static __noreturn void xen_restart(char *msg)
22604 {
22605 xen_reboot(SHUTDOWN_reboot);
22606 }
22607
22608-static void xen_emergency_restart(void)
22609+static __noreturn void xen_emergency_restart(void)
22610 {
22611 xen_reboot(SHUTDOWN_reboot);
22612 }
22613
22614-static void xen_machine_halt(void)
22615+static __noreturn void xen_machine_halt(void)
22616 {
22617 xen_reboot(SHUTDOWN_poweroff);
22618 }
22619@@ -1095,9 +1093,20 @@ asmlinkage void __init xen_start_kernel(
22620 */
22621 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
22622
22623-#ifdef CONFIG_X86_64
22624 /* Work out if we support NX */
22625- check_efer();
22626+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
22627+ if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
22628+ (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
22629+ unsigned l, h;
22630+
22631+#ifdef CONFIG_X86_PAE
22632+ nx_enabled = 1;
22633+#endif
22634+ __supported_pte_mask |= _PAGE_NX;
22635+ rdmsr(MSR_EFER, l, h);
22636+ l |= EFER_NX;
22637+ wrmsr(MSR_EFER, l, h);
22638+ }
22639 #endif
22640
22641 xen_setup_features();
22642@@ -1129,13 +1138,6 @@ asmlinkage void __init xen_start_kernel(
22643
22644 machine_ops = xen_machine_ops;
22645
22646- /*
22647- * The only reliable way to retain the initial address of the
22648- * percpu gdt_page is to remember it here, so we can go and
22649- * mark it RW later, when the initial percpu area is freed.
22650- */
22651- xen_initial_gdt = &per_cpu(gdt_page, 0);
22652-
22653 xen_smp_init();
22654
22655 pgd = (pgd_t *)xen_start_info->pt_base;
22656diff -urNp linux-2.6.32.41/arch/x86/xen/mmu.c linux-2.6.32.41/arch/x86/xen/mmu.c
22657--- linux-2.6.32.41/arch/x86/xen/mmu.c 2011-03-27 14:31:47.000000000 -0400
22658+++ linux-2.6.32.41/arch/x86/xen/mmu.c 2011-04-17 15:56:46.000000000 -0400
22659@@ -1714,6 +1714,8 @@ __init pgd_t *xen_setup_kernel_pagetable
22660 convert_pfn_mfn(init_level4_pgt);
22661 convert_pfn_mfn(level3_ident_pgt);
22662 convert_pfn_mfn(level3_kernel_pgt);
22663+ convert_pfn_mfn(level3_vmalloc_pgt);
22664+ convert_pfn_mfn(level3_vmemmap_pgt);
22665
22666 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
22667 l2 = m2v(l3[pud_index(__START_KERNEL_map)].pud);
22668@@ -1732,7 +1734,10 @@ __init pgd_t *xen_setup_kernel_pagetable
22669 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
22670 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
22671 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
22672+ set_page_prot(level3_vmalloc_pgt, PAGE_KERNEL_RO);
22673+ set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
22674 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
22675+ set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
22676 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
22677 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
22678
22679diff -urNp linux-2.6.32.41/arch/x86/xen/smp.c linux-2.6.32.41/arch/x86/xen/smp.c
22680--- linux-2.6.32.41/arch/x86/xen/smp.c 2011-03-27 14:31:47.000000000 -0400
22681+++ linux-2.6.32.41/arch/x86/xen/smp.c 2011-05-11 18:25:15.000000000 -0400
22682@@ -167,11 +167,6 @@ static void __init xen_smp_prepare_boot_
22683 {
22684 BUG_ON(smp_processor_id() != 0);
22685 native_smp_prepare_boot_cpu();
22686-
22687- /* We've switched to the "real" per-cpu gdt, so make sure the
22688- old memory can be recycled */
22689- make_lowmem_page_readwrite(xen_initial_gdt);
22690-
22691 xen_setup_vcpu_info_placement();
22692 }
22693
22694@@ -231,12 +226,12 @@ cpu_initialize_context(unsigned int cpu,
22695 gdt = get_cpu_gdt_table(cpu);
22696
22697 ctxt->flags = VGCF_IN_KERNEL;
22698- ctxt->user_regs.ds = __USER_DS;
22699- ctxt->user_regs.es = __USER_DS;
22700+ ctxt->user_regs.ds = __KERNEL_DS;
22701+ ctxt->user_regs.es = __KERNEL_DS;
22702 ctxt->user_regs.ss = __KERNEL_DS;
22703 #ifdef CONFIG_X86_32
22704 ctxt->user_regs.fs = __KERNEL_PERCPU;
22705- ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
22706+ savesegment(gs, ctxt->user_regs.gs);
22707 #else
22708 ctxt->gs_base_kernel = per_cpu_offset(cpu);
22709 #endif
22710@@ -287,13 +282,12 @@ static int __cpuinit xen_cpu_up(unsigned
22711 int rc;
22712
22713 per_cpu(current_task, cpu) = idle;
22714+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
22715 #ifdef CONFIG_X86_32
22716 irq_ctx_init(cpu);
22717 #else
22718 clear_tsk_thread_flag(idle, TIF_FORK);
22719- per_cpu(kernel_stack, cpu) =
22720- (unsigned long)task_stack_page(idle) -
22721- KERNEL_STACK_OFFSET + THREAD_SIZE;
22722+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
22723 #endif
22724 xen_setup_runstate_info(cpu);
22725 xen_setup_timer(cpu);
22726diff -urNp linux-2.6.32.41/arch/x86/xen/xen-asm_32.S linux-2.6.32.41/arch/x86/xen/xen-asm_32.S
22727--- linux-2.6.32.41/arch/x86/xen/xen-asm_32.S 2011-03-27 14:31:47.000000000 -0400
22728+++ linux-2.6.32.41/arch/x86/xen/xen-asm_32.S 2011-04-22 19:13:13.000000000 -0400
22729@@ -83,14 +83,14 @@ ENTRY(xen_iret)
22730 ESP_OFFSET=4 # bytes pushed onto stack
22731
22732 /*
22733- * Store vcpu_info pointer for easy access. Do it this way to
22734- * avoid having to reload %fs
22735+ * Store vcpu_info pointer for easy access.
22736 */
22737 #ifdef CONFIG_SMP
22738- GET_THREAD_INFO(%eax)
22739- movl TI_cpu(%eax), %eax
22740- movl __per_cpu_offset(,%eax,4), %eax
22741- mov per_cpu__xen_vcpu(%eax), %eax
22742+ push %fs
22743+ mov $(__KERNEL_PERCPU), %eax
22744+ mov %eax, %fs
22745+ mov PER_CPU_VAR(xen_vcpu), %eax
22746+ pop %fs
22747 #else
22748 movl per_cpu__xen_vcpu, %eax
22749 #endif
22750diff -urNp linux-2.6.32.41/arch/x86/xen/xen-head.S linux-2.6.32.41/arch/x86/xen/xen-head.S
22751--- linux-2.6.32.41/arch/x86/xen/xen-head.S 2011-03-27 14:31:47.000000000 -0400
22752+++ linux-2.6.32.41/arch/x86/xen/xen-head.S 2011-04-17 15:56:46.000000000 -0400
22753@@ -19,6 +19,17 @@ ENTRY(startup_xen)
22754 #ifdef CONFIG_X86_32
22755 mov %esi,xen_start_info
22756 mov $init_thread_union+THREAD_SIZE,%esp
22757+#ifdef CONFIG_SMP
22758+ movl $cpu_gdt_table,%edi
22759+ movl $__per_cpu_load,%eax
22760+ movw %ax,__KERNEL_PERCPU + 2(%edi)
22761+ rorl $16,%eax
22762+ movb %al,__KERNEL_PERCPU + 4(%edi)
22763+ movb %ah,__KERNEL_PERCPU + 7(%edi)
22764+ movl $__per_cpu_end - 1,%eax
22765+ subl $__per_cpu_start,%eax
22766+ movw %ax,__KERNEL_PERCPU + 0(%edi)
22767+#endif
22768 #else
22769 mov %rsi,xen_start_info
22770 mov $init_thread_union+THREAD_SIZE,%rsp
22771diff -urNp linux-2.6.32.41/arch/x86/xen/xen-ops.h linux-2.6.32.41/arch/x86/xen/xen-ops.h
22772--- linux-2.6.32.41/arch/x86/xen/xen-ops.h 2011-03-27 14:31:47.000000000 -0400
22773+++ linux-2.6.32.41/arch/x86/xen/xen-ops.h 2011-04-17 15:56:46.000000000 -0400
22774@@ -10,8 +10,6 @@
22775 extern const char xen_hypervisor_callback[];
22776 extern const char xen_failsafe_callback[];
22777
22778-extern void *xen_initial_gdt;
22779-
22780 struct trap_info;
22781 void xen_copy_trap_info(struct trap_info *traps);
22782
22783diff -urNp linux-2.6.32.41/block/blk-integrity.c linux-2.6.32.41/block/blk-integrity.c
22784--- linux-2.6.32.41/block/blk-integrity.c 2011-03-27 14:31:47.000000000 -0400
22785+++ linux-2.6.32.41/block/blk-integrity.c 2011-04-17 15:56:46.000000000 -0400
22786@@ -278,7 +278,7 @@ static struct attribute *integrity_attrs
22787 NULL,
22788 };
22789
22790-static struct sysfs_ops integrity_ops = {
22791+static const struct sysfs_ops integrity_ops = {
22792 .show = &integrity_attr_show,
22793 .store = &integrity_attr_store,
22794 };
22795diff -urNp linux-2.6.32.41/block/blk-iopoll.c linux-2.6.32.41/block/blk-iopoll.c
22796--- linux-2.6.32.41/block/blk-iopoll.c 2011-03-27 14:31:47.000000000 -0400
22797+++ linux-2.6.32.41/block/blk-iopoll.c 2011-04-17 15:56:46.000000000 -0400
22798@@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopo
22799 }
22800 EXPORT_SYMBOL(blk_iopoll_complete);
22801
22802-static void blk_iopoll_softirq(struct softirq_action *h)
22803+static void blk_iopoll_softirq(void)
22804 {
22805 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
22806 int rearm = 0, budget = blk_iopoll_budget;
22807diff -urNp linux-2.6.32.41/block/blk-map.c linux-2.6.32.41/block/blk-map.c
22808--- linux-2.6.32.41/block/blk-map.c 2011-03-27 14:31:47.000000000 -0400
22809+++ linux-2.6.32.41/block/blk-map.c 2011-04-18 16:57:33.000000000 -0400
22810@@ -54,7 +54,7 @@ static int __blk_rq_map_user(struct requ
22811 * direct dma. else, set up kernel bounce buffers
22812 */
22813 uaddr = (unsigned long) ubuf;
22814- if (blk_rq_aligned(q, ubuf, len) && !map_data)
22815+ if (blk_rq_aligned(q, (__force void *)ubuf, len) && !map_data)
22816 bio = bio_map_user(q, NULL, uaddr, len, reading, gfp_mask);
22817 else
22818 bio = bio_copy_user(q, map_data, uaddr, len, reading, gfp_mask);
22819@@ -201,12 +201,13 @@ int blk_rq_map_user_iov(struct request_q
22820 for (i = 0; i < iov_count; i++) {
22821 unsigned long uaddr = (unsigned long)iov[i].iov_base;
22822
22823+ if (!iov[i].iov_len)
22824+ return -EINVAL;
22825+
22826 if (uaddr & queue_dma_alignment(q)) {
22827 unaligned = 1;
22828 break;
22829 }
22830- if (!iov[i].iov_len)
22831- return -EINVAL;
22832 }
22833
22834 if (unaligned || (q->dma_pad_mask & len) || map_data)
22835@@ -299,7 +300,7 @@ int blk_rq_map_kern(struct request_queue
22836 if (!len || !kbuf)
22837 return -EINVAL;
22838
22839- do_copy = !blk_rq_aligned(q, kbuf, len) || object_is_on_stack(kbuf);
22840+ do_copy = !blk_rq_aligned(q, kbuf, len) || object_starts_on_stack(kbuf);
22841 if (do_copy)
22842 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
22843 else
22844diff -urNp linux-2.6.32.41/block/blk-softirq.c linux-2.6.32.41/block/blk-softirq.c
22845--- linux-2.6.32.41/block/blk-softirq.c 2011-03-27 14:31:47.000000000 -0400
22846+++ linux-2.6.32.41/block/blk-softirq.c 2011-04-17 15:56:46.000000000 -0400
22847@@ -17,7 +17,7 @@ static DEFINE_PER_CPU(struct list_head,
22848 * Softirq action handler - move entries to local list and loop over them
22849 * while passing them to the queue registered handler.
22850 */
22851-static void blk_done_softirq(struct softirq_action *h)
22852+static void blk_done_softirq(void)
22853 {
22854 struct list_head *cpu_list, local_list;
22855
22856diff -urNp linux-2.6.32.41/block/blk-sysfs.c linux-2.6.32.41/block/blk-sysfs.c
22857--- linux-2.6.32.41/block/blk-sysfs.c 2011-05-10 22:12:01.000000000 -0400
22858+++ linux-2.6.32.41/block/blk-sysfs.c 2011-05-10 22:12:26.000000000 -0400
22859@@ -414,7 +414,7 @@ static void blk_release_queue(struct kob
22860 kmem_cache_free(blk_requestq_cachep, q);
22861 }
22862
22863-static struct sysfs_ops queue_sysfs_ops = {
22864+static const struct sysfs_ops queue_sysfs_ops = {
22865 .show = queue_attr_show,
22866 .store = queue_attr_store,
22867 };
22868diff -urNp linux-2.6.32.41/block/bsg.c linux-2.6.32.41/block/bsg.c
22869--- linux-2.6.32.41/block/bsg.c 2011-03-27 14:31:47.000000000 -0400
22870+++ linux-2.6.32.41/block/bsg.c 2011-04-17 15:56:46.000000000 -0400
22871@@ -175,16 +175,24 @@ static int blk_fill_sgv4_hdr_rq(struct r
22872 struct sg_io_v4 *hdr, struct bsg_device *bd,
22873 fmode_t has_write_perm)
22874 {
22875+ unsigned char tmpcmd[sizeof(rq->__cmd)];
22876+ unsigned char *cmdptr;
22877+
22878 if (hdr->request_len > BLK_MAX_CDB) {
22879 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
22880 if (!rq->cmd)
22881 return -ENOMEM;
22882- }
22883+ cmdptr = rq->cmd;
22884+ } else
22885+ cmdptr = tmpcmd;
22886
22887- if (copy_from_user(rq->cmd, (void *)(unsigned long)hdr->request,
22888+ if (copy_from_user(cmdptr, (void *)(unsigned long)hdr->request,
22889 hdr->request_len))
22890 return -EFAULT;
22891
22892+ if (cmdptr != rq->cmd)
22893+ memcpy(rq->cmd, cmdptr, hdr->request_len);
22894+
22895 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
22896 if (blk_verify_command(rq->cmd, has_write_perm))
22897 return -EPERM;
22898diff -urNp linux-2.6.32.41/block/elevator.c linux-2.6.32.41/block/elevator.c
22899--- linux-2.6.32.41/block/elevator.c 2011-03-27 14:31:47.000000000 -0400
22900+++ linux-2.6.32.41/block/elevator.c 2011-04-17 15:56:46.000000000 -0400
22901@@ -889,7 +889,7 @@ elv_attr_store(struct kobject *kobj, str
22902 return error;
22903 }
22904
22905-static struct sysfs_ops elv_sysfs_ops = {
22906+static const struct sysfs_ops elv_sysfs_ops = {
22907 .show = elv_attr_show,
22908 .store = elv_attr_store,
22909 };
22910diff -urNp linux-2.6.32.41/block/scsi_ioctl.c linux-2.6.32.41/block/scsi_ioctl.c
22911--- linux-2.6.32.41/block/scsi_ioctl.c 2011-03-27 14:31:47.000000000 -0400
22912+++ linux-2.6.32.41/block/scsi_ioctl.c 2011-04-23 13:28:22.000000000 -0400
22913@@ -220,8 +220,20 @@ EXPORT_SYMBOL(blk_verify_command);
22914 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
22915 struct sg_io_hdr *hdr, fmode_t mode)
22916 {
22917- if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
22918+ unsigned char tmpcmd[sizeof(rq->__cmd)];
22919+ unsigned char *cmdptr;
22920+
22921+ if (rq->cmd != rq->__cmd)
22922+ cmdptr = rq->cmd;
22923+ else
22924+ cmdptr = tmpcmd;
22925+
22926+ if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
22927 return -EFAULT;
22928+
22929+ if (cmdptr != rq->cmd)
22930+ memcpy(rq->cmd, cmdptr, hdr->cmd_len);
22931+
22932 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
22933 return -EPERM;
22934
22935@@ -430,6 +442,8 @@ int sg_scsi_ioctl(struct request_queue *
22936 int err;
22937 unsigned int in_len, out_len, bytes, opcode, cmdlen;
22938 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
22939+ unsigned char tmpcmd[sizeof(rq->__cmd)];
22940+ unsigned char *cmdptr;
22941
22942 if (!sic)
22943 return -EINVAL;
22944@@ -463,9 +477,18 @@ int sg_scsi_ioctl(struct request_queue *
22945 */
22946 err = -EFAULT;
22947 rq->cmd_len = cmdlen;
22948- if (copy_from_user(rq->cmd, sic->data, cmdlen))
22949+
22950+ if (rq->cmd != rq->__cmd)
22951+ cmdptr = rq->cmd;
22952+ else
22953+ cmdptr = tmpcmd;
22954+
22955+ if (copy_from_user(cmdptr, sic->data, cmdlen))
22956 goto error;
22957
22958+ if (rq->cmd != cmdptr)
22959+ memcpy(rq->cmd, cmdptr, cmdlen);
22960+
22961 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
22962 goto error;
22963
22964diff -urNp linux-2.6.32.41/crypto/serpent.c linux-2.6.32.41/crypto/serpent.c
22965--- linux-2.6.32.41/crypto/serpent.c 2011-03-27 14:31:47.000000000 -0400
22966+++ linux-2.6.32.41/crypto/serpent.c 2011-05-16 21:46:57.000000000 -0400
22967@@ -224,6 +224,8 @@ static int serpent_setkey(struct crypto_
22968 u32 r0,r1,r2,r3,r4;
22969 int i;
22970
22971+ pax_track_stack();
22972+
22973 /* Copy key, add padding */
22974
22975 for (i = 0; i < keylen; ++i)
22976diff -urNp linux-2.6.32.41/Documentation/dontdiff linux-2.6.32.41/Documentation/dontdiff
22977--- linux-2.6.32.41/Documentation/dontdiff 2011-03-27 14:31:47.000000000 -0400
22978+++ linux-2.6.32.41/Documentation/dontdiff 2011-05-18 20:09:36.000000000 -0400
22979@@ -1,13 +1,16 @@
22980 *.a
22981 *.aux
22982 *.bin
22983+*.cis
22984 *.cpio
22985 *.csp
22986+*.dbg
22987 *.dsp
22988 *.dvi
22989 *.elf
22990 *.eps
22991 *.fw
22992+*.gcno
22993 *.gen.S
22994 *.gif
22995 *.grep
22996@@ -38,8 +41,10 @@
22997 *.tab.h
22998 *.tex
22999 *.ver
23000+*.vim
23001 *.xml
23002 *_MODULES
23003+*_reg_safe.h
23004 *_vga16.c
23005 *~
23006 *.9
23007@@ -49,11 +54,16 @@
23008 53c700_d.h
23009 CVS
23010 ChangeSet
23011+GPATH
23012+GRTAGS
23013+GSYMS
23014+GTAGS
23015 Image
23016 Kerntypes
23017 Module.markers
23018 Module.symvers
23019 PENDING
23020+PERF*
23021 SCCS
23022 System.map*
23023 TAGS
23024@@ -76,7 +86,11 @@ btfixupprep
23025 build
23026 bvmlinux
23027 bzImage*
23028+capability_names.h
23029+capflags.c
23030 classlist.h*
23031+clut_vga16.c
23032+common-cmds.h
23033 comp*.log
23034 compile.h*
23035 conf
23036@@ -103,13 +117,14 @@ gen_crc32table
23037 gen_init_cpio
23038 genksyms
23039 *_gray256.c
23040+hash
23041 ihex2fw
23042 ikconfig.h*
23043 initramfs_data.cpio
23044+initramfs_data.cpio.bz2
23045 initramfs_data.cpio.gz
23046 initramfs_list
23047 kallsyms
23048-kconfig
23049 keywords.c
23050 ksym.c*
23051 ksym.h*
23052@@ -133,7 +148,9 @@ mkboot
23053 mkbugboot
23054 mkcpustr
23055 mkdep
23056+mkpiggy
23057 mkprep
23058+mkregtable
23059 mktables
23060 mktree
23061 modpost
23062@@ -149,6 +166,7 @@ patches*
23063 pca200e.bin
23064 pca200e_ecd.bin2
23065 piggy.gz
23066+piggy.S
23067 piggyback
23068 pnmtologo
23069 ppc_defs.h*
23070@@ -157,12 +175,15 @@ qconf
23071 raid6altivec*.c
23072 raid6int*.c
23073 raid6tables.c
23074+regdb.c
23075 relocs
23076+rlim_names.h
23077 series
23078 setup
23079 setup.bin
23080 setup.elf
23081 sImage
23082+slabinfo
23083 sm_tbl*
23084 split-include
23085 syscalltab.h
23086@@ -186,14 +207,20 @@ version.h*
23087 vmlinux
23088 vmlinux-*
23089 vmlinux.aout
23090+vmlinux.bin.all
23091+vmlinux.bin.bz2
23092 vmlinux.lds
23093+vmlinux.relocs
23094+voffset.h
23095 vsyscall.lds
23096 vsyscall_32.lds
23097 wanxlfw.inc
23098 uImage
23099 unifdef
23100+utsrelease.h
23101 wakeup.bin
23102 wakeup.elf
23103 wakeup.lds
23104 zImage*
23105 zconf.hash.c
23106+zoffset.h
23107diff -urNp linux-2.6.32.41/Documentation/kernel-parameters.txt linux-2.6.32.41/Documentation/kernel-parameters.txt
23108--- linux-2.6.32.41/Documentation/kernel-parameters.txt 2011-03-27 14:31:47.000000000 -0400
23109+++ linux-2.6.32.41/Documentation/kernel-parameters.txt 2011-04-17 15:56:45.000000000 -0400
23110@@ -1837,6 +1837,13 @@ and is between 256 and 4096 characters.
23111 the specified number of seconds. This is to be used if
23112 your oopses keep scrolling off the screen.
23113
23114+ pax_nouderef [X86] disables UDEREF. Most likely needed under certain
23115+ virtualization environments that don't cope well with the
23116+ expand down segment used by UDEREF on X86-32 or the frequent
23117+ page table updates on X86-64.
23118+
23119+ pax_softmode= 0/1 to disable/enable PaX softmode on boot already.
23120+
23121 pcbit= [HW,ISDN]
23122
23123 pcd. [PARIDE]
23124diff -urNp linux-2.6.32.41/drivers/acpi/acpi_pad.c linux-2.6.32.41/drivers/acpi/acpi_pad.c
23125--- linux-2.6.32.41/drivers/acpi/acpi_pad.c 2011-03-27 14:31:47.000000000 -0400
23126+++ linux-2.6.32.41/drivers/acpi/acpi_pad.c 2011-04-17 15:56:46.000000000 -0400
23127@@ -30,7 +30,7 @@
23128 #include <acpi/acpi_bus.h>
23129 #include <acpi/acpi_drivers.h>
23130
23131-#define ACPI_PROCESSOR_AGGREGATOR_CLASS "processor_aggregator"
23132+#define ACPI_PROCESSOR_AGGREGATOR_CLASS "acpi_pad"
23133 #define ACPI_PROCESSOR_AGGREGATOR_DEVICE_NAME "Processor Aggregator"
23134 #define ACPI_PROCESSOR_AGGREGATOR_NOTIFY 0x80
23135 static DEFINE_MUTEX(isolated_cpus_lock);
23136diff -urNp linux-2.6.32.41/drivers/acpi/battery.c linux-2.6.32.41/drivers/acpi/battery.c
23137--- linux-2.6.32.41/drivers/acpi/battery.c 2011-03-27 14:31:47.000000000 -0400
23138+++ linux-2.6.32.41/drivers/acpi/battery.c 2011-04-17 15:56:46.000000000 -0400
23139@@ -763,7 +763,7 @@ DECLARE_FILE_FUNCTIONS(alarm);
23140 }
23141
23142 static struct battery_file {
23143- struct file_operations ops;
23144+ const struct file_operations ops;
23145 mode_t mode;
23146 const char *name;
23147 } acpi_battery_file[] = {
23148diff -urNp linux-2.6.32.41/drivers/acpi/dock.c linux-2.6.32.41/drivers/acpi/dock.c
23149--- linux-2.6.32.41/drivers/acpi/dock.c 2011-03-27 14:31:47.000000000 -0400
23150+++ linux-2.6.32.41/drivers/acpi/dock.c 2011-04-17 15:56:46.000000000 -0400
23151@@ -77,7 +77,7 @@ struct dock_dependent_device {
23152 struct list_head list;
23153 struct list_head hotplug_list;
23154 acpi_handle handle;
23155- struct acpi_dock_ops *ops;
23156+ const struct acpi_dock_ops *ops;
23157 void *context;
23158 };
23159
23160@@ -605,7 +605,7 @@ EXPORT_SYMBOL_GPL(unregister_dock_notifi
23161 * the dock driver after _DCK is executed.
23162 */
23163 int
23164-register_hotplug_dock_device(acpi_handle handle, struct acpi_dock_ops *ops,
23165+register_hotplug_dock_device(acpi_handle handle, const struct acpi_dock_ops *ops,
23166 void *context)
23167 {
23168 struct dock_dependent_device *dd;
23169diff -urNp linux-2.6.32.41/drivers/acpi/osl.c linux-2.6.32.41/drivers/acpi/osl.c
23170--- linux-2.6.32.41/drivers/acpi/osl.c 2011-03-27 14:31:47.000000000 -0400
23171+++ linux-2.6.32.41/drivers/acpi/osl.c 2011-04-17 15:56:46.000000000 -0400
23172@@ -523,6 +523,8 @@ acpi_os_read_memory(acpi_physical_addres
23173 void __iomem *virt_addr;
23174
23175 virt_addr = ioremap(phys_addr, width);
23176+ if (!virt_addr)
23177+ return AE_NO_MEMORY;
23178 if (!value)
23179 value = &dummy;
23180
23181@@ -551,6 +553,8 @@ acpi_os_write_memory(acpi_physical_addre
23182 void __iomem *virt_addr;
23183
23184 virt_addr = ioremap(phys_addr, width);
23185+ if (!virt_addr)
23186+ return AE_NO_MEMORY;
23187
23188 switch (width) {
23189 case 8:
23190diff -urNp linux-2.6.32.41/drivers/acpi/power_meter.c linux-2.6.32.41/drivers/acpi/power_meter.c
23191--- linux-2.6.32.41/drivers/acpi/power_meter.c 2011-03-27 14:31:47.000000000 -0400
23192+++ linux-2.6.32.41/drivers/acpi/power_meter.c 2011-04-17 15:56:46.000000000 -0400
23193@@ -315,8 +315,6 @@ static ssize_t set_trip(struct device *d
23194 return res;
23195
23196 temp /= 1000;
23197- if (temp < 0)
23198- return -EINVAL;
23199
23200 mutex_lock(&resource->lock);
23201 resource->trip[attr->index - 7] = temp;
23202diff -urNp linux-2.6.32.41/drivers/acpi/proc.c linux-2.6.32.41/drivers/acpi/proc.c
23203--- linux-2.6.32.41/drivers/acpi/proc.c 2011-03-27 14:31:47.000000000 -0400
23204+++ linux-2.6.32.41/drivers/acpi/proc.c 2011-04-17 15:56:46.000000000 -0400
23205@@ -391,20 +391,15 @@ acpi_system_write_wakeup_device(struct f
23206 size_t count, loff_t * ppos)
23207 {
23208 struct list_head *node, *next;
23209- char strbuf[5];
23210- char str[5] = "";
23211- unsigned int len = count;
23212+ char strbuf[5] = {0};
23213 struct acpi_device *found_dev = NULL;
23214
23215- if (len > 4)
23216- len = 4;
23217- if (len < 0)
23218- return -EFAULT;
23219+ if (count > 4)
23220+ count = 4;
23221
23222- if (copy_from_user(strbuf, buffer, len))
23223+ if (copy_from_user(strbuf, buffer, count))
23224 return -EFAULT;
23225- strbuf[len] = '\0';
23226- sscanf(strbuf, "%s", str);
23227+ strbuf[count] = '\0';
23228
23229 mutex_lock(&acpi_device_lock);
23230 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
23231@@ -413,7 +408,7 @@ acpi_system_write_wakeup_device(struct f
23232 if (!dev->wakeup.flags.valid)
23233 continue;
23234
23235- if (!strncmp(dev->pnp.bus_id, str, 4)) {
23236+ if (!strncmp(dev->pnp.bus_id, strbuf, 4)) {
23237 dev->wakeup.state.enabled =
23238 dev->wakeup.state.enabled ? 0 : 1;
23239 found_dev = dev;
23240diff -urNp linux-2.6.32.41/drivers/acpi/processor_core.c linux-2.6.32.41/drivers/acpi/processor_core.c
23241--- linux-2.6.32.41/drivers/acpi/processor_core.c 2011-03-27 14:31:47.000000000 -0400
23242+++ linux-2.6.32.41/drivers/acpi/processor_core.c 2011-04-17 15:56:46.000000000 -0400
23243@@ -790,7 +790,7 @@ static int __cpuinit acpi_processor_add(
23244 return 0;
23245 }
23246
23247- BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
23248+ BUG_ON(pr->id >= nr_cpu_ids);
23249
23250 /*
23251 * Buggy BIOS check
23252diff -urNp linux-2.6.32.41/drivers/acpi/sbshc.c linux-2.6.32.41/drivers/acpi/sbshc.c
23253--- linux-2.6.32.41/drivers/acpi/sbshc.c 2011-03-27 14:31:47.000000000 -0400
23254+++ linux-2.6.32.41/drivers/acpi/sbshc.c 2011-04-17 15:56:46.000000000 -0400
23255@@ -17,7 +17,7 @@
23256
23257 #define PREFIX "ACPI: "
23258
23259-#define ACPI_SMB_HC_CLASS "smbus_host_controller"
23260+#define ACPI_SMB_HC_CLASS "smbus_host_ctl"
23261 #define ACPI_SMB_HC_DEVICE_NAME "ACPI SMBus HC"
23262
23263 struct acpi_smb_hc {
23264diff -urNp linux-2.6.32.41/drivers/acpi/sleep.c linux-2.6.32.41/drivers/acpi/sleep.c
23265--- linux-2.6.32.41/drivers/acpi/sleep.c 2011-03-27 14:31:47.000000000 -0400
23266+++ linux-2.6.32.41/drivers/acpi/sleep.c 2011-04-17 15:56:46.000000000 -0400
23267@@ -283,7 +283,7 @@ static int acpi_suspend_state_valid(susp
23268 }
23269 }
23270
23271-static struct platform_suspend_ops acpi_suspend_ops = {
23272+static const struct platform_suspend_ops acpi_suspend_ops = {
23273 .valid = acpi_suspend_state_valid,
23274 .begin = acpi_suspend_begin,
23275 .prepare_late = acpi_pm_prepare,
23276@@ -311,7 +311,7 @@ static int acpi_suspend_begin_old(suspen
23277 * The following callbacks are used if the pre-ACPI 2.0 suspend ordering has
23278 * been requested.
23279 */
23280-static struct platform_suspend_ops acpi_suspend_ops_old = {
23281+static const struct platform_suspend_ops acpi_suspend_ops_old = {
23282 .valid = acpi_suspend_state_valid,
23283 .begin = acpi_suspend_begin_old,
23284 .prepare_late = acpi_pm_disable_gpes,
23285@@ -460,7 +460,7 @@ static void acpi_pm_enable_gpes(void)
23286 acpi_enable_all_runtime_gpes();
23287 }
23288
23289-static struct platform_hibernation_ops acpi_hibernation_ops = {
23290+static const struct platform_hibernation_ops acpi_hibernation_ops = {
23291 .begin = acpi_hibernation_begin,
23292 .end = acpi_pm_end,
23293 .pre_snapshot = acpi_hibernation_pre_snapshot,
23294@@ -513,7 +513,7 @@ static int acpi_hibernation_pre_snapshot
23295 * The following callbacks are used if the pre-ACPI 2.0 suspend ordering has
23296 * been requested.
23297 */
23298-static struct platform_hibernation_ops acpi_hibernation_ops_old = {
23299+static const struct platform_hibernation_ops acpi_hibernation_ops_old = {
23300 .begin = acpi_hibernation_begin_old,
23301 .end = acpi_pm_end,
23302 .pre_snapshot = acpi_hibernation_pre_snapshot_old,
23303diff -urNp linux-2.6.32.41/drivers/acpi/video.c linux-2.6.32.41/drivers/acpi/video.c
23304--- linux-2.6.32.41/drivers/acpi/video.c 2011-03-27 14:31:47.000000000 -0400
23305+++ linux-2.6.32.41/drivers/acpi/video.c 2011-04-17 15:56:46.000000000 -0400
23306@@ -359,7 +359,7 @@ static int acpi_video_set_brightness(str
23307 vd->brightness->levels[request_level]);
23308 }
23309
23310-static struct backlight_ops acpi_backlight_ops = {
23311+static const struct backlight_ops acpi_backlight_ops = {
23312 .get_brightness = acpi_video_get_brightness,
23313 .update_status = acpi_video_set_brightness,
23314 };
23315diff -urNp linux-2.6.32.41/drivers/ata/ahci.c linux-2.6.32.41/drivers/ata/ahci.c
23316--- linux-2.6.32.41/drivers/ata/ahci.c 2011-03-27 14:31:47.000000000 -0400
23317+++ linux-2.6.32.41/drivers/ata/ahci.c 2011-04-23 12:56:10.000000000 -0400
23318@@ -387,7 +387,7 @@ static struct scsi_host_template ahci_sh
23319 .sdev_attrs = ahci_sdev_attrs,
23320 };
23321
23322-static struct ata_port_operations ahci_ops = {
23323+static const struct ata_port_operations ahci_ops = {
23324 .inherits = &sata_pmp_port_ops,
23325
23326 .qc_defer = sata_pmp_qc_defer_cmd_switch,
23327@@ -424,17 +424,17 @@ static struct ata_port_operations ahci_o
23328 .port_stop = ahci_port_stop,
23329 };
23330
23331-static struct ata_port_operations ahci_vt8251_ops = {
23332+static const struct ata_port_operations ahci_vt8251_ops = {
23333 .inherits = &ahci_ops,
23334 .hardreset = ahci_vt8251_hardreset,
23335 };
23336
23337-static struct ata_port_operations ahci_p5wdh_ops = {
23338+static const struct ata_port_operations ahci_p5wdh_ops = {
23339 .inherits = &ahci_ops,
23340 .hardreset = ahci_p5wdh_hardreset,
23341 };
23342
23343-static struct ata_port_operations ahci_sb600_ops = {
23344+static const struct ata_port_operations ahci_sb600_ops = {
23345 .inherits = &ahci_ops,
23346 .softreset = ahci_sb600_softreset,
23347 .pmp_softreset = ahci_sb600_softreset,
23348diff -urNp linux-2.6.32.41/drivers/ata/ata_generic.c linux-2.6.32.41/drivers/ata/ata_generic.c
23349--- linux-2.6.32.41/drivers/ata/ata_generic.c 2011-03-27 14:31:47.000000000 -0400
23350+++ linux-2.6.32.41/drivers/ata/ata_generic.c 2011-04-17 15:56:46.000000000 -0400
23351@@ -104,7 +104,7 @@ static struct scsi_host_template generic
23352 ATA_BMDMA_SHT(DRV_NAME),
23353 };
23354
23355-static struct ata_port_operations generic_port_ops = {
23356+static const struct ata_port_operations generic_port_ops = {
23357 .inherits = &ata_bmdma_port_ops,
23358 .cable_detect = ata_cable_unknown,
23359 .set_mode = generic_set_mode,
23360diff -urNp linux-2.6.32.41/drivers/ata/ata_piix.c linux-2.6.32.41/drivers/ata/ata_piix.c
23361--- linux-2.6.32.41/drivers/ata/ata_piix.c 2011-03-27 14:31:47.000000000 -0400
23362+++ linux-2.6.32.41/drivers/ata/ata_piix.c 2011-04-23 12:56:10.000000000 -0400
23363@@ -318,7 +318,7 @@ static struct scsi_host_template piix_sh
23364 ATA_BMDMA_SHT(DRV_NAME),
23365 };
23366
23367-static struct ata_port_operations piix_pata_ops = {
23368+static const struct ata_port_operations piix_pata_ops = {
23369 .inherits = &ata_bmdma32_port_ops,
23370 .cable_detect = ata_cable_40wire,
23371 .set_piomode = piix_set_piomode,
23372@@ -326,22 +326,22 @@ static struct ata_port_operations piix_p
23373 .prereset = piix_pata_prereset,
23374 };
23375
23376-static struct ata_port_operations piix_vmw_ops = {
23377+static const struct ata_port_operations piix_vmw_ops = {
23378 .inherits = &piix_pata_ops,
23379 .bmdma_status = piix_vmw_bmdma_status,
23380 };
23381
23382-static struct ata_port_operations ich_pata_ops = {
23383+static const struct ata_port_operations ich_pata_ops = {
23384 .inherits = &piix_pata_ops,
23385 .cable_detect = ich_pata_cable_detect,
23386 .set_dmamode = ich_set_dmamode,
23387 };
23388
23389-static struct ata_port_operations piix_sata_ops = {
23390+static const struct ata_port_operations piix_sata_ops = {
23391 .inherits = &ata_bmdma_port_ops,
23392 };
23393
23394-static struct ata_port_operations piix_sidpr_sata_ops = {
23395+static const struct ata_port_operations piix_sidpr_sata_ops = {
23396 .inherits = &piix_sata_ops,
23397 .hardreset = sata_std_hardreset,
23398 .scr_read = piix_sidpr_scr_read,
23399diff -urNp linux-2.6.32.41/drivers/ata/libata-acpi.c linux-2.6.32.41/drivers/ata/libata-acpi.c
23400--- linux-2.6.32.41/drivers/ata/libata-acpi.c 2011-03-27 14:31:47.000000000 -0400
23401+++ linux-2.6.32.41/drivers/ata/libata-acpi.c 2011-04-17 15:56:46.000000000 -0400
23402@@ -223,12 +223,12 @@ static void ata_acpi_dev_uevent(acpi_han
23403 ata_acpi_uevent(dev->link->ap, dev, event);
23404 }
23405
23406-static struct acpi_dock_ops ata_acpi_dev_dock_ops = {
23407+static const struct acpi_dock_ops ata_acpi_dev_dock_ops = {
23408 .handler = ata_acpi_dev_notify_dock,
23409 .uevent = ata_acpi_dev_uevent,
23410 };
23411
23412-static struct acpi_dock_ops ata_acpi_ap_dock_ops = {
23413+static const struct acpi_dock_ops ata_acpi_ap_dock_ops = {
23414 .handler = ata_acpi_ap_notify_dock,
23415 .uevent = ata_acpi_ap_uevent,
23416 };
23417diff -urNp linux-2.6.32.41/drivers/ata/libata-core.c linux-2.6.32.41/drivers/ata/libata-core.c
23418--- linux-2.6.32.41/drivers/ata/libata-core.c 2011-03-27 14:31:47.000000000 -0400
23419+++ linux-2.6.32.41/drivers/ata/libata-core.c 2011-04-23 12:56:10.000000000 -0400
23420@@ -4954,7 +4954,7 @@ void ata_qc_free(struct ata_queued_cmd *
23421 struct ata_port *ap;
23422 unsigned int tag;
23423
23424- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
23425+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
23426 ap = qc->ap;
23427
23428 qc->flags = 0;
23429@@ -4970,7 +4970,7 @@ void __ata_qc_complete(struct ata_queued
23430 struct ata_port *ap;
23431 struct ata_link *link;
23432
23433- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
23434+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
23435 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
23436 ap = qc->ap;
23437 link = qc->dev->link;
23438@@ -5987,7 +5987,7 @@ static void ata_host_stop(struct device
23439 * LOCKING:
23440 * None.
23441 */
23442-static void ata_finalize_port_ops(struct ata_port_operations *ops)
23443+static void ata_finalize_port_ops(const struct ata_port_operations *ops)
23444 {
23445 static DEFINE_SPINLOCK(lock);
23446 const struct ata_port_operations *cur;
23447@@ -5999,6 +5999,7 @@ static void ata_finalize_port_ops(struct
23448 return;
23449
23450 spin_lock(&lock);
23451+ pax_open_kernel();
23452
23453 for (cur = ops->inherits; cur; cur = cur->inherits) {
23454 void **inherit = (void **)cur;
23455@@ -6012,8 +6013,9 @@ static void ata_finalize_port_ops(struct
23456 if (IS_ERR(*pp))
23457 *pp = NULL;
23458
23459- ops->inherits = NULL;
23460+ ((struct ata_port_operations *)ops)->inherits = NULL;
23461
23462+ pax_close_kernel();
23463 spin_unlock(&lock);
23464 }
23465
23466@@ -6110,7 +6112,7 @@ int ata_host_start(struct ata_host *host
23467 */
23468 /* KILLME - the only user left is ipr */
23469 void ata_host_init(struct ata_host *host, struct device *dev,
23470- unsigned long flags, struct ata_port_operations *ops)
23471+ unsigned long flags, const struct ata_port_operations *ops)
23472 {
23473 spin_lock_init(&host->lock);
23474 host->dev = dev;
23475@@ -6773,7 +6775,7 @@ static void ata_dummy_error_handler(stru
23476 /* truly dummy */
23477 }
23478
23479-struct ata_port_operations ata_dummy_port_ops = {
23480+const struct ata_port_operations ata_dummy_port_ops = {
23481 .qc_prep = ata_noop_qc_prep,
23482 .qc_issue = ata_dummy_qc_issue,
23483 .error_handler = ata_dummy_error_handler,
23484diff -urNp linux-2.6.32.41/drivers/ata/libata-eh.c linux-2.6.32.41/drivers/ata/libata-eh.c
23485--- linux-2.6.32.41/drivers/ata/libata-eh.c 2011-03-27 14:31:47.000000000 -0400
23486+++ linux-2.6.32.41/drivers/ata/libata-eh.c 2011-05-16 21:46:57.000000000 -0400
23487@@ -2423,6 +2423,8 @@ void ata_eh_report(struct ata_port *ap)
23488 {
23489 struct ata_link *link;
23490
23491+ pax_track_stack();
23492+
23493 ata_for_each_link(link, ap, HOST_FIRST)
23494 ata_eh_link_report(link);
23495 }
23496@@ -3590,7 +3592,7 @@ void ata_do_eh(struct ata_port *ap, ata_
23497 */
23498 void ata_std_error_handler(struct ata_port *ap)
23499 {
23500- struct ata_port_operations *ops = ap->ops;
23501+ const struct ata_port_operations *ops = ap->ops;
23502 ata_reset_fn_t hardreset = ops->hardreset;
23503
23504 /* ignore built-in hardreset if SCR access is not available */
23505diff -urNp linux-2.6.32.41/drivers/ata/libata-pmp.c linux-2.6.32.41/drivers/ata/libata-pmp.c
23506--- linux-2.6.32.41/drivers/ata/libata-pmp.c 2011-03-27 14:31:47.000000000 -0400
23507+++ linux-2.6.32.41/drivers/ata/libata-pmp.c 2011-04-17 15:56:46.000000000 -0400
23508@@ -841,7 +841,7 @@ static int sata_pmp_handle_link_fail(str
23509 */
23510 static int sata_pmp_eh_recover(struct ata_port *ap)
23511 {
23512- struct ata_port_operations *ops = ap->ops;
23513+ const struct ata_port_operations *ops = ap->ops;
23514 int pmp_tries, link_tries[SATA_PMP_MAX_PORTS];
23515 struct ata_link *pmp_link = &ap->link;
23516 struct ata_device *pmp_dev = pmp_link->device;
23517diff -urNp linux-2.6.32.41/drivers/ata/pata_acpi.c linux-2.6.32.41/drivers/ata/pata_acpi.c
23518--- linux-2.6.32.41/drivers/ata/pata_acpi.c 2011-03-27 14:31:47.000000000 -0400
23519+++ linux-2.6.32.41/drivers/ata/pata_acpi.c 2011-04-17 15:56:46.000000000 -0400
23520@@ -215,7 +215,7 @@ static struct scsi_host_template pacpi_s
23521 ATA_BMDMA_SHT(DRV_NAME),
23522 };
23523
23524-static struct ata_port_operations pacpi_ops = {
23525+static const struct ata_port_operations pacpi_ops = {
23526 .inherits = &ata_bmdma_port_ops,
23527 .qc_issue = pacpi_qc_issue,
23528 .cable_detect = pacpi_cable_detect,
23529diff -urNp linux-2.6.32.41/drivers/ata/pata_ali.c linux-2.6.32.41/drivers/ata/pata_ali.c
23530--- linux-2.6.32.41/drivers/ata/pata_ali.c 2011-03-27 14:31:47.000000000 -0400
23531+++ linux-2.6.32.41/drivers/ata/pata_ali.c 2011-04-17 15:56:46.000000000 -0400
23532@@ -365,7 +365,7 @@ static struct scsi_host_template ali_sht
23533 * Port operations for PIO only ALi
23534 */
23535
23536-static struct ata_port_operations ali_early_port_ops = {
23537+static const struct ata_port_operations ali_early_port_ops = {
23538 .inherits = &ata_sff_port_ops,
23539 .cable_detect = ata_cable_40wire,
23540 .set_piomode = ali_set_piomode,
23541@@ -382,7 +382,7 @@ static const struct ata_port_operations
23542 * Port operations for DMA capable ALi without cable
23543 * detect
23544 */
23545-static struct ata_port_operations ali_20_port_ops = {
23546+static const struct ata_port_operations ali_20_port_ops = {
23547 .inherits = &ali_dma_base_ops,
23548 .cable_detect = ata_cable_40wire,
23549 .mode_filter = ali_20_filter,
23550@@ -393,7 +393,7 @@ static struct ata_port_operations ali_20
23551 /*
23552 * Port operations for DMA capable ALi with cable detect
23553 */
23554-static struct ata_port_operations ali_c2_port_ops = {
23555+static const struct ata_port_operations ali_c2_port_ops = {
23556 .inherits = &ali_dma_base_ops,
23557 .check_atapi_dma = ali_check_atapi_dma,
23558 .cable_detect = ali_c2_cable_detect,
23559@@ -404,7 +404,7 @@ static struct ata_port_operations ali_c2
23560 /*
23561 * Port operations for DMA capable ALi with cable detect
23562 */
23563-static struct ata_port_operations ali_c4_port_ops = {
23564+static const struct ata_port_operations ali_c4_port_ops = {
23565 .inherits = &ali_dma_base_ops,
23566 .check_atapi_dma = ali_check_atapi_dma,
23567 .cable_detect = ali_c2_cable_detect,
23568@@ -414,7 +414,7 @@ static struct ata_port_operations ali_c4
23569 /*
23570 * Port operations for DMA capable ALi with cable detect and LBA48
23571 */
23572-static struct ata_port_operations ali_c5_port_ops = {
23573+static const struct ata_port_operations ali_c5_port_ops = {
23574 .inherits = &ali_dma_base_ops,
23575 .check_atapi_dma = ali_check_atapi_dma,
23576 .dev_config = ali_warn_atapi_dma,
23577diff -urNp linux-2.6.32.41/drivers/ata/pata_amd.c linux-2.6.32.41/drivers/ata/pata_amd.c
23578--- linux-2.6.32.41/drivers/ata/pata_amd.c 2011-03-27 14:31:47.000000000 -0400
23579+++ linux-2.6.32.41/drivers/ata/pata_amd.c 2011-04-17 15:56:46.000000000 -0400
23580@@ -397,28 +397,28 @@ static const struct ata_port_operations
23581 .prereset = amd_pre_reset,
23582 };
23583
23584-static struct ata_port_operations amd33_port_ops = {
23585+static const struct ata_port_operations amd33_port_ops = {
23586 .inherits = &amd_base_port_ops,
23587 .cable_detect = ata_cable_40wire,
23588 .set_piomode = amd33_set_piomode,
23589 .set_dmamode = amd33_set_dmamode,
23590 };
23591
23592-static struct ata_port_operations amd66_port_ops = {
23593+static const struct ata_port_operations amd66_port_ops = {
23594 .inherits = &amd_base_port_ops,
23595 .cable_detect = ata_cable_unknown,
23596 .set_piomode = amd66_set_piomode,
23597 .set_dmamode = amd66_set_dmamode,
23598 };
23599
23600-static struct ata_port_operations amd100_port_ops = {
23601+static const struct ata_port_operations amd100_port_ops = {
23602 .inherits = &amd_base_port_ops,
23603 .cable_detect = ata_cable_unknown,
23604 .set_piomode = amd100_set_piomode,
23605 .set_dmamode = amd100_set_dmamode,
23606 };
23607
23608-static struct ata_port_operations amd133_port_ops = {
23609+static const struct ata_port_operations amd133_port_ops = {
23610 .inherits = &amd_base_port_ops,
23611 .cable_detect = amd_cable_detect,
23612 .set_piomode = amd133_set_piomode,
23613@@ -433,13 +433,13 @@ static const struct ata_port_operations
23614 .host_stop = nv_host_stop,
23615 };
23616
23617-static struct ata_port_operations nv100_port_ops = {
23618+static const struct ata_port_operations nv100_port_ops = {
23619 .inherits = &nv_base_port_ops,
23620 .set_piomode = nv100_set_piomode,
23621 .set_dmamode = nv100_set_dmamode,
23622 };
23623
23624-static struct ata_port_operations nv133_port_ops = {
23625+static const struct ata_port_operations nv133_port_ops = {
23626 .inherits = &nv_base_port_ops,
23627 .set_piomode = nv133_set_piomode,
23628 .set_dmamode = nv133_set_dmamode,
23629diff -urNp linux-2.6.32.41/drivers/ata/pata_artop.c linux-2.6.32.41/drivers/ata/pata_artop.c
23630--- linux-2.6.32.41/drivers/ata/pata_artop.c 2011-03-27 14:31:47.000000000 -0400
23631+++ linux-2.6.32.41/drivers/ata/pata_artop.c 2011-04-17 15:56:46.000000000 -0400
23632@@ -311,7 +311,7 @@ static struct scsi_host_template artop_s
23633 ATA_BMDMA_SHT(DRV_NAME),
23634 };
23635
23636-static struct ata_port_operations artop6210_ops = {
23637+static const struct ata_port_operations artop6210_ops = {
23638 .inherits = &ata_bmdma_port_ops,
23639 .cable_detect = ata_cable_40wire,
23640 .set_piomode = artop6210_set_piomode,
23641@@ -320,7 +320,7 @@ static struct ata_port_operations artop6
23642 .qc_defer = artop6210_qc_defer,
23643 };
23644
23645-static struct ata_port_operations artop6260_ops = {
23646+static const struct ata_port_operations artop6260_ops = {
23647 .inherits = &ata_bmdma_port_ops,
23648 .cable_detect = artop6260_cable_detect,
23649 .set_piomode = artop6260_set_piomode,
23650diff -urNp linux-2.6.32.41/drivers/ata/pata_at32.c linux-2.6.32.41/drivers/ata/pata_at32.c
23651--- linux-2.6.32.41/drivers/ata/pata_at32.c 2011-03-27 14:31:47.000000000 -0400
23652+++ linux-2.6.32.41/drivers/ata/pata_at32.c 2011-04-17 15:56:46.000000000 -0400
23653@@ -172,7 +172,7 @@ static struct scsi_host_template at32_sh
23654 ATA_PIO_SHT(DRV_NAME),
23655 };
23656
23657-static struct ata_port_operations at32_port_ops = {
23658+static const struct ata_port_operations at32_port_ops = {
23659 .inherits = &ata_sff_port_ops,
23660 .cable_detect = ata_cable_40wire,
23661 .set_piomode = pata_at32_set_piomode,
23662diff -urNp linux-2.6.32.41/drivers/ata/pata_at91.c linux-2.6.32.41/drivers/ata/pata_at91.c
23663--- linux-2.6.32.41/drivers/ata/pata_at91.c 2011-03-27 14:31:47.000000000 -0400
23664+++ linux-2.6.32.41/drivers/ata/pata_at91.c 2011-04-17 15:56:46.000000000 -0400
23665@@ -195,7 +195,7 @@ static struct scsi_host_template pata_at
23666 ATA_PIO_SHT(DRV_NAME),
23667 };
23668
23669-static struct ata_port_operations pata_at91_port_ops = {
23670+static const struct ata_port_operations pata_at91_port_ops = {
23671 .inherits = &ata_sff_port_ops,
23672
23673 .sff_data_xfer = pata_at91_data_xfer_noirq,
23674diff -urNp linux-2.6.32.41/drivers/ata/pata_atiixp.c linux-2.6.32.41/drivers/ata/pata_atiixp.c
23675--- linux-2.6.32.41/drivers/ata/pata_atiixp.c 2011-03-27 14:31:47.000000000 -0400
23676+++ linux-2.6.32.41/drivers/ata/pata_atiixp.c 2011-04-17 15:56:46.000000000 -0400
23677@@ -205,7 +205,7 @@ static struct scsi_host_template atiixp_
23678 .sg_tablesize = LIBATA_DUMB_MAX_PRD,
23679 };
23680
23681-static struct ata_port_operations atiixp_port_ops = {
23682+static const struct ata_port_operations atiixp_port_ops = {
23683 .inherits = &ata_bmdma_port_ops,
23684
23685 .qc_prep = ata_sff_dumb_qc_prep,
23686diff -urNp linux-2.6.32.41/drivers/ata/pata_atp867x.c linux-2.6.32.41/drivers/ata/pata_atp867x.c
23687--- linux-2.6.32.41/drivers/ata/pata_atp867x.c 2011-03-27 14:31:47.000000000 -0400
23688+++ linux-2.6.32.41/drivers/ata/pata_atp867x.c 2011-04-17 15:56:46.000000000 -0400
23689@@ -274,7 +274,7 @@ static struct scsi_host_template atp867x
23690 ATA_BMDMA_SHT(DRV_NAME),
23691 };
23692
23693-static struct ata_port_operations atp867x_ops = {
23694+static const struct ata_port_operations atp867x_ops = {
23695 .inherits = &ata_bmdma_port_ops,
23696 .cable_detect = atp867x_cable_detect,
23697 .set_piomode = atp867x_set_piomode,
23698diff -urNp linux-2.6.32.41/drivers/ata/pata_bf54x.c linux-2.6.32.41/drivers/ata/pata_bf54x.c
23699--- linux-2.6.32.41/drivers/ata/pata_bf54x.c 2011-03-27 14:31:47.000000000 -0400
23700+++ linux-2.6.32.41/drivers/ata/pata_bf54x.c 2011-04-17 15:56:46.000000000 -0400
23701@@ -1464,7 +1464,7 @@ static struct scsi_host_template bfin_sh
23702 .dma_boundary = ATA_DMA_BOUNDARY,
23703 };
23704
23705-static struct ata_port_operations bfin_pata_ops = {
23706+static const struct ata_port_operations bfin_pata_ops = {
23707 .inherits = &ata_sff_port_ops,
23708
23709 .set_piomode = bfin_set_piomode,
23710diff -urNp linux-2.6.32.41/drivers/ata/pata_cmd640.c linux-2.6.32.41/drivers/ata/pata_cmd640.c
23711--- linux-2.6.32.41/drivers/ata/pata_cmd640.c 2011-03-27 14:31:47.000000000 -0400
23712+++ linux-2.6.32.41/drivers/ata/pata_cmd640.c 2011-04-17 15:56:46.000000000 -0400
23713@@ -168,7 +168,7 @@ static struct scsi_host_template cmd640_
23714 ATA_BMDMA_SHT(DRV_NAME),
23715 };
23716
23717-static struct ata_port_operations cmd640_port_ops = {
23718+static const struct ata_port_operations cmd640_port_ops = {
23719 .inherits = &ata_bmdma_port_ops,
23720 /* In theory xfer_noirq is not needed once we kill the prefetcher */
23721 .sff_data_xfer = ata_sff_data_xfer_noirq,
23722diff -urNp linux-2.6.32.41/drivers/ata/pata_cmd64x.c linux-2.6.32.41/drivers/ata/pata_cmd64x.c
23723--- linux-2.6.32.41/drivers/ata/pata_cmd64x.c 2011-03-27 14:31:47.000000000 -0400
23724+++ linux-2.6.32.41/drivers/ata/pata_cmd64x.c 2011-04-17 15:56:46.000000000 -0400
23725@@ -275,18 +275,18 @@ static const struct ata_port_operations
23726 .set_dmamode = cmd64x_set_dmamode,
23727 };
23728
23729-static struct ata_port_operations cmd64x_port_ops = {
23730+static const struct ata_port_operations cmd64x_port_ops = {
23731 .inherits = &cmd64x_base_ops,
23732 .cable_detect = ata_cable_40wire,
23733 };
23734
23735-static struct ata_port_operations cmd646r1_port_ops = {
23736+static const struct ata_port_operations cmd646r1_port_ops = {
23737 .inherits = &cmd64x_base_ops,
23738 .bmdma_stop = cmd646r1_bmdma_stop,
23739 .cable_detect = ata_cable_40wire,
23740 };
23741
23742-static struct ata_port_operations cmd648_port_ops = {
23743+static const struct ata_port_operations cmd648_port_ops = {
23744 .inherits = &cmd64x_base_ops,
23745 .bmdma_stop = cmd648_bmdma_stop,
23746 .cable_detect = cmd648_cable_detect,
23747diff -urNp linux-2.6.32.41/drivers/ata/pata_cs5520.c linux-2.6.32.41/drivers/ata/pata_cs5520.c
23748--- linux-2.6.32.41/drivers/ata/pata_cs5520.c 2011-03-27 14:31:47.000000000 -0400
23749+++ linux-2.6.32.41/drivers/ata/pata_cs5520.c 2011-04-17 15:56:46.000000000 -0400
23750@@ -144,7 +144,7 @@ static struct scsi_host_template cs5520_
23751 .sg_tablesize = LIBATA_DUMB_MAX_PRD,
23752 };
23753
23754-static struct ata_port_operations cs5520_port_ops = {
23755+static const struct ata_port_operations cs5520_port_ops = {
23756 .inherits = &ata_bmdma_port_ops,
23757 .qc_prep = ata_sff_dumb_qc_prep,
23758 .cable_detect = ata_cable_40wire,
23759diff -urNp linux-2.6.32.41/drivers/ata/pata_cs5530.c linux-2.6.32.41/drivers/ata/pata_cs5530.c
23760--- linux-2.6.32.41/drivers/ata/pata_cs5530.c 2011-03-27 14:31:47.000000000 -0400
23761+++ linux-2.6.32.41/drivers/ata/pata_cs5530.c 2011-04-17 15:56:46.000000000 -0400
23762@@ -164,7 +164,7 @@ static struct scsi_host_template cs5530_
23763 .sg_tablesize = LIBATA_DUMB_MAX_PRD,
23764 };
23765
23766-static struct ata_port_operations cs5530_port_ops = {
23767+static const struct ata_port_operations cs5530_port_ops = {
23768 .inherits = &ata_bmdma_port_ops,
23769
23770 .qc_prep = ata_sff_dumb_qc_prep,
23771diff -urNp linux-2.6.32.41/drivers/ata/pata_cs5535.c linux-2.6.32.41/drivers/ata/pata_cs5535.c
23772--- linux-2.6.32.41/drivers/ata/pata_cs5535.c 2011-03-27 14:31:47.000000000 -0400
23773+++ linux-2.6.32.41/drivers/ata/pata_cs5535.c 2011-04-17 15:56:46.000000000 -0400
23774@@ -160,7 +160,7 @@ static struct scsi_host_template cs5535_
23775 ATA_BMDMA_SHT(DRV_NAME),
23776 };
23777
23778-static struct ata_port_operations cs5535_port_ops = {
23779+static const struct ata_port_operations cs5535_port_ops = {
23780 .inherits = &ata_bmdma_port_ops,
23781 .cable_detect = cs5535_cable_detect,
23782 .set_piomode = cs5535_set_piomode,
23783diff -urNp linux-2.6.32.41/drivers/ata/pata_cs5536.c linux-2.6.32.41/drivers/ata/pata_cs5536.c
23784--- linux-2.6.32.41/drivers/ata/pata_cs5536.c 2011-03-27 14:31:47.000000000 -0400
23785+++ linux-2.6.32.41/drivers/ata/pata_cs5536.c 2011-04-17 15:56:46.000000000 -0400
23786@@ -223,7 +223,7 @@ static struct scsi_host_template cs5536_
23787 ATA_BMDMA_SHT(DRV_NAME),
23788 };
23789
23790-static struct ata_port_operations cs5536_port_ops = {
23791+static const struct ata_port_operations cs5536_port_ops = {
23792 .inherits = &ata_bmdma_port_ops,
23793 .cable_detect = cs5536_cable_detect,
23794 .set_piomode = cs5536_set_piomode,
23795diff -urNp linux-2.6.32.41/drivers/ata/pata_cypress.c linux-2.6.32.41/drivers/ata/pata_cypress.c
23796--- linux-2.6.32.41/drivers/ata/pata_cypress.c 2011-03-27 14:31:47.000000000 -0400
23797+++ linux-2.6.32.41/drivers/ata/pata_cypress.c 2011-04-17 15:56:46.000000000 -0400
23798@@ -113,7 +113,7 @@ static struct scsi_host_template cy82c69
23799 ATA_BMDMA_SHT(DRV_NAME),
23800 };
23801
23802-static struct ata_port_operations cy82c693_port_ops = {
23803+static const struct ata_port_operations cy82c693_port_ops = {
23804 .inherits = &ata_bmdma_port_ops,
23805 .cable_detect = ata_cable_40wire,
23806 .set_piomode = cy82c693_set_piomode,
23807diff -urNp linux-2.6.32.41/drivers/ata/pata_efar.c linux-2.6.32.41/drivers/ata/pata_efar.c
23808--- linux-2.6.32.41/drivers/ata/pata_efar.c 2011-03-27 14:31:47.000000000 -0400
23809+++ linux-2.6.32.41/drivers/ata/pata_efar.c 2011-04-17 15:56:46.000000000 -0400
23810@@ -222,7 +222,7 @@ static struct scsi_host_template efar_sh
23811 ATA_BMDMA_SHT(DRV_NAME),
23812 };
23813
23814-static struct ata_port_operations efar_ops = {
23815+static const struct ata_port_operations efar_ops = {
23816 .inherits = &ata_bmdma_port_ops,
23817 .cable_detect = efar_cable_detect,
23818 .set_piomode = efar_set_piomode,
23819diff -urNp linux-2.6.32.41/drivers/ata/pata_hpt366.c linux-2.6.32.41/drivers/ata/pata_hpt366.c
23820--- linux-2.6.32.41/drivers/ata/pata_hpt366.c 2011-03-27 14:31:47.000000000 -0400
23821+++ linux-2.6.32.41/drivers/ata/pata_hpt366.c 2011-04-17 15:56:46.000000000 -0400
23822@@ -282,7 +282,7 @@ static struct scsi_host_template hpt36x_
23823 * Configuration for HPT366/68
23824 */
23825
23826-static struct ata_port_operations hpt366_port_ops = {
23827+static const struct ata_port_operations hpt366_port_ops = {
23828 .inherits = &ata_bmdma_port_ops,
23829 .cable_detect = hpt36x_cable_detect,
23830 .mode_filter = hpt366_filter,
23831diff -urNp linux-2.6.32.41/drivers/ata/pata_hpt37x.c linux-2.6.32.41/drivers/ata/pata_hpt37x.c
23832--- linux-2.6.32.41/drivers/ata/pata_hpt37x.c 2011-03-27 14:31:47.000000000 -0400
23833+++ linux-2.6.32.41/drivers/ata/pata_hpt37x.c 2011-04-17 15:56:46.000000000 -0400
23834@@ -576,7 +576,7 @@ static struct scsi_host_template hpt37x_
23835 * Configuration for HPT370
23836 */
23837
23838-static struct ata_port_operations hpt370_port_ops = {
23839+static const struct ata_port_operations hpt370_port_ops = {
23840 .inherits = &ata_bmdma_port_ops,
23841
23842 .bmdma_stop = hpt370_bmdma_stop,
23843@@ -591,7 +591,7 @@ static struct ata_port_operations hpt370
23844 * Configuration for HPT370A. Close to 370 but less filters
23845 */
23846
23847-static struct ata_port_operations hpt370a_port_ops = {
23848+static const struct ata_port_operations hpt370a_port_ops = {
23849 .inherits = &hpt370_port_ops,
23850 .mode_filter = hpt370a_filter,
23851 };
23852@@ -601,7 +601,7 @@ static struct ata_port_operations hpt370
23853 * and DMA mode setting functionality.
23854 */
23855
23856-static struct ata_port_operations hpt372_port_ops = {
23857+static const struct ata_port_operations hpt372_port_ops = {
23858 .inherits = &ata_bmdma_port_ops,
23859
23860 .bmdma_stop = hpt37x_bmdma_stop,
23861@@ -616,7 +616,7 @@ static struct ata_port_operations hpt372
23862 * but we have a different cable detection procedure for function 1.
23863 */
23864
23865-static struct ata_port_operations hpt374_fn1_port_ops = {
23866+static const struct ata_port_operations hpt374_fn1_port_ops = {
23867 .inherits = &hpt372_port_ops,
23868 .prereset = hpt374_fn1_pre_reset,
23869 };
23870diff -urNp linux-2.6.32.41/drivers/ata/pata_hpt3x2n.c linux-2.6.32.41/drivers/ata/pata_hpt3x2n.c
23871--- linux-2.6.32.41/drivers/ata/pata_hpt3x2n.c 2011-03-27 14:31:47.000000000 -0400
23872+++ linux-2.6.32.41/drivers/ata/pata_hpt3x2n.c 2011-04-17 15:56:46.000000000 -0400
23873@@ -337,7 +337,7 @@ static struct scsi_host_template hpt3x2n
23874 * Configuration for HPT3x2n.
23875 */
23876
23877-static struct ata_port_operations hpt3x2n_port_ops = {
23878+static const struct ata_port_operations hpt3x2n_port_ops = {
23879 .inherits = &ata_bmdma_port_ops,
23880
23881 .bmdma_stop = hpt3x2n_bmdma_stop,
23882diff -urNp linux-2.6.32.41/drivers/ata/pata_hpt3x3.c linux-2.6.32.41/drivers/ata/pata_hpt3x3.c
23883--- linux-2.6.32.41/drivers/ata/pata_hpt3x3.c 2011-03-27 14:31:47.000000000 -0400
23884+++ linux-2.6.32.41/drivers/ata/pata_hpt3x3.c 2011-04-17 15:56:46.000000000 -0400
23885@@ -141,7 +141,7 @@ static struct scsi_host_template hpt3x3_
23886 ATA_BMDMA_SHT(DRV_NAME),
23887 };
23888
23889-static struct ata_port_operations hpt3x3_port_ops = {
23890+static const struct ata_port_operations hpt3x3_port_ops = {
23891 .inherits = &ata_bmdma_port_ops,
23892 .cable_detect = ata_cable_40wire,
23893 .set_piomode = hpt3x3_set_piomode,
23894diff -urNp linux-2.6.32.41/drivers/ata/pata_icside.c linux-2.6.32.41/drivers/ata/pata_icside.c
23895--- linux-2.6.32.41/drivers/ata/pata_icside.c 2011-03-27 14:31:47.000000000 -0400
23896+++ linux-2.6.32.41/drivers/ata/pata_icside.c 2011-04-17 15:56:46.000000000 -0400
23897@@ -319,7 +319,7 @@ static void pata_icside_postreset(struct
23898 }
23899 }
23900
23901-static struct ata_port_operations pata_icside_port_ops = {
23902+static const struct ata_port_operations pata_icside_port_ops = {
23903 .inherits = &ata_sff_port_ops,
23904 /* no need to build any PRD tables for DMA */
23905 .qc_prep = ata_noop_qc_prep,
23906diff -urNp linux-2.6.32.41/drivers/ata/pata_isapnp.c linux-2.6.32.41/drivers/ata/pata_isapnp.c
23907--- linux-2.6.32.41/drivers/ata/pata_isapnp.c 2011-03-27 14:31:47.000000000 -0400
23908+++ linux-2.6.32.41/drivers/ata/pata_isapnp.c 2011-04-17 15:56:46.000000000 -0400
23909@@ -23,12 +23,12 @@ static struct scsi_host_template isapnp_
23910 ATA_PIO_SHT(DRV_NAME),
23911 };
23912
23913-static struct ata_port_operations isapnp_port_ops = {
23914+static const struct ata_port_operations isapnp_port_ops = {
23915 .inherits = &ata_sff_port_ops,
23916 .cable_detect = ata_cable_40wire,
23917 };
23918
23919-static struct ata_port_operations isapnp_noalt_port_ops = {
23920+static const struct ata_port_operations isapnp_noalt_port_ops = {
23921 .inherits = &ata_sff_port_ops,
23922 .cable_detect = ata_cable_40wire,
23923 /* No altstatus so we don't want to use the lost interrupt poll */
23924diff -urNp linux-2.6.32.41/drivers/ata/pata_it8213.c linux-2.6.32.41/drivers/ata/pata_it8213.c
23925--- linux-2.6.32.41/drivers/ata/pata_it8213.c 2011-03-27 14:31:47.000000000 -0400
23926+++ linux-2.6.32.41/drivers/ata/pata_it8213.c 2011-04-17 15:56:46.000000000 -0400
23927@@ -234,7 +234,7 @@ static struct scsi_host_template it8213_
23928 };
23929
23930
23931-static struct ata_port_operations it8213_ops = {
23932+static const struct ata_port_operations it8213_ops = {
23933 .inherits = &ata_bmdma_port_ops,
23934 .cable_detect = it8213_cable_detect,
23935 .set_piomode = it8213_set_piomode,
23936diff -urNp linux-2.6.32.41/drivers/ata/pata_it821x.c linux-2.6.32.41/drivers/ata/pata_it821x.c
23937--- linux-2.6.32.41/drivers/ata/pata_it821x.c 2011-03-27 14:31:47.000000000 -0400
23938+++ linux-2.6.32.41/drivers/ata/pata_it821x.c 2011-04-17 15:56:46.000000000 -0400
23939@@ -800,7 +800,7 @@ static struct scsi_host_template it821x_
23940 ATA_BMDMA_SHT(DRV_NAME),
23941 };
23942
23943-static struct ata_port_operations it821x_smart_port_ops = {
23944+static const struct ata_port_operations it821x_smart_port_ops = {
23945 .inherits = &ata_bmdma_port_ops,
23946
23947 .check_atapi_dma= it821x_check_atapi_dma,
23948@@ -814,7 +814,7 @@ static struct ata_port_operations it821x
23949 .port_start = it821x_port_start,
23950 };
23951
23952-static struct ata_port_operations it821x_passthru_port_ops = {
23953+static const struct ata_port_operations it821x_passthru_port_ops = {
23954 .inherits = &ata_bmdma_port_ops,
23955
23956 .check_atapi_dma= it821x_check_atapi_dma,
23957@@ -830,7 +830,7 @@ static struct ata_port_operations it821x
23958 .port_start = it821x_port_start,
23959 };
23960
23961-static struct ata_port_operations it821x_rdc_port_ops = {
23962+static const struct ata_port_operations it821x_rdc_port_ops = {
23963 .inherits = &ata_bmdma_port_ops,
23964
23965 .check_atapi_dma= it821x_check_atapi_dma,
23966diff -urNp linux-2.6.32.41/drivers/ata/pata_ixp4xx_cf.c linux-2.6.32.41/drivers/ata/pata_ixp4xx_cf.c
23967--- linux-2.6.32.41/drivers/ata/pata_ixp4xx_cf.c 2011-03-27 14:31:47.000000000 -0400
23968+++ linux-2.6.32.41/drivers/ata/pata_ixp4xx_cf.c 2011-04-17 15:56:46.000000000 -0400
23969@@ -89,7 +89,7 @@ static struct scsi_host_template ixp4xx_
23970 ATA_PIO_SHT(DRV_NAME),
23971 };
23972
23973-static struct ata_port_operations ixp4xx_port_ops = {
23974+static const struct ata_port_operations ixp4xx_port_ops = {
23975 .inherits = &ata_sff_port_ops,
23976 .sff_data_xfer = ixp4xx_mmio_data_xfer,
23977 .cable_detect = ata_cable_40wire,
23978diff -urNp linux-2.6.32.41/drivers/ata/pata_jmicron.c linux-2.6.32.41/drivers/ata/pata_jmicron.c
23979--- linux-2.6.32.41/drivers/ata/pata_jmicron.c 2011-03-27 14:31:47.000000000 -0400
23980+++ linux-2.6.32.41/drivers/ata/pata_jmicron.c 2011-04-17 15:56:46.000000000 -0400
23981@@ -111,7 +111,7 @@ static struct scsi_host_template jmicron
23982 ATA_BMDMA_SHT(DRV_NAME),
23983 };
23984
23985-static struct ata_port_operations jmicron_ops = {
23986+static const struct ata_port_operations jmicron_ops = {
23987 .inherits = &ata_bmdma_port_ops,
23988 .prereset = jmicron_pre_reset,
23989 };
23990diff -urNp linux-2.6.32.41/drivers/ata/pata_legacy.c linux-2.6.32.41/drivers/ata/pata_legacy.c
23991--- linux-2.6.32.41/drivers/ata/pata_legacy.c 2011-03-27 14:31:47.000000000 -0400
23992+++ linux-2.6.32.41/drivers/ata/pata_legacy.c 2011-04-17 15:56:46.000000000 -0400
23993@@ -106,7 +106,7 @@ struct legacy_probe {
23994
23995 struct legacy_controller {
23996 const char *name;
23997- struct ata_port_operations *ops;
23998+ const struct ata_port_operations *ops;
23999 unsigned int pio_mask;
24000 unsigned int flags;
24001 unsigned int pflags;
24002@@ -223,12 +223,12 @@ static const struct ata_port_operations
24003 * pio_mask as well.
24004 */
24005
24006-static struct ata_port_operations simple_port_ops = {
24007+static const struct ata_port_operations simple_port_ops = {
24008 .inherits = &legacy_base_port_ops,
24009 .sff_data_xfer = ata_sff_data_xfer_noirq,
24010 };
24011
24012-static struct ata_port_operations legacy_port_ops = {
24013+static const struct ata_port_operations legacy_port_ops = {
24014 .inherits = &legacy_base_port_ops,
24015 .sff_data_xfer = ata_sff_data_xfer_noirq,
24016 .set_mode = legacy_set_mode,
24017@@ -324,7 +324,7 @@ static unsigned int pdc_data_xfer_vlb(st
24018 return buflen;
24019 }
24020
24021-static struct ata_port_operations pdc20230_port_ops = {
24022+static const struct ata_port_operations pdc20230_port_ops = {
24023 .inherits = &legacy_base_port_ops,
24024 .set_piomode = pdc20230_set_piomode,
24025 .sff_data_xfer = pdc_data_xfer_vlb,
24026@@ -357,7 +357,7 @@ static void ht6560a_set_piomode(struct a
24027 ioread8(ap->ioaddr.status_addr);
24028 }
24029
24030-static struct ata_port_operations ht6560a_port_ops = {
24031+static const struct ata_port_operations ht6560a_port_ops = {
24032 .inherits = &legacy_base_port_ops,
24033 .set_piomode = ht6560a_set_piomode,
24034 };
24035@@ -400,7 +400,7 @@ static void ht6560b_set_piomode(struct a
24036 ioread8(ap->ioaddr.status_addr);
24037 }
24038
24039-static struct ata_port_operations ht6560b_port_ops = {
24040+static const struct ata_port_operations ht6560b_port_ops = {
24041 .inherits = &legacy_base_port_ops,
24042 .set_piomode = ht6560b_set_piomode,
24043 };
24044@@ -499,7 +499,7 @@ static void opti82c611a_set_piomode(stru
24045 }
24046
24047
24048-static struct ata_port_operations opti82c611a_port_ops = {
24049+static const struct ata_port_operations opti82c611a_port_ops = {
24050 .inherits = &legacy_base_port_ops,
24051 .set_piomode = opti82c611a_set_piomode,
24052 };
24053@@ -609,7 +609,7 @@ static unsigned int opti82c46x_qc_issue(
24054 return ata_sff_qc_issue(qc);
24055 }
24056
24057-static struct ata_port_operations opti82c46x_port_ops = {
24058+static const struct ata_port_operations opti82c46x_port_ops = {
24059 .inherits = &legacy_base_port_ops,
24060 .set_piomode = opti82c46x_set_piomode,
24061 .qc_issue = opti82c46x_qc_issue,
24062@@ -771,20 +771,20 @@ static int qdi_port(struct platform_devi
24063 return 0;
24064 }
24065
24066-static struct ata_port_operations qdi6500_port_ops = {
24067+static const struct ata_port_operations qdi6500_port_ops = {
24068 .inherits = &legacy_base_port_ops,
24069 .set_piomode = qdi6500_set_piomode,
24070 .qc_issue = qdi_qc_issue,
24071 .sff_data_xfer = vlb32_data_xfer,
24072 };
24073
24074-static struct ata_port_operations qdi6580_port_ops = {
24075+static const struct ata_port_operations qdi6580_port_ops = {
24076 .inherits = &legacy_base_port_ops,
24077 .set_piomode = qdi6580_set_piomode,
24078 .sff_data_xfer = vlb32_data_xfer,
24079 };
24080
24081-static struct ata_port_operations qdi6580dp_port_ops = {
24082+static const struct ata_port_operations qdi6580dp_port_ops = {
24083 .inherits = &legacy_base_port_ops,
24084 .set_piomode = qdi6580dp_set_piomode,
24085 .sff_data_xfer = vlb32_data_xfer,
24086@@ -855,7 +855,7 @@ static int winbond_port(struct platform_
24087 return 0;
24088 }
24089
24090-static struct ata_port_operations winbond_port_ops = {
24091+static const struct ata_port_operations winbond_port_ops = {
24092 .inherits = &legacy_base_port_ops,
24093 .set_piomode = winbond_set_piomode,
24094 .sff_data_xfer = vlb32_data_xfer,
24095@@ -978,7 +978,7 @@ static __init int legacy_init_one(struct
24096 int pio_modes = controller->pio_mask;
24097 unsigned long io = probe->port;
24098 u32 mask = (1 << probe->slot);
24099- struct ata_port_operations *ops = controller->ops;
24100+ const struct ata_port_operations *ops = controller->ops;
24101 struct legacy_data *ld = &legacy_data[probe->slot];
24102 struct ata_host *host = NULL;
24103 struct ata_port *ap;
24104diff -urNp linux-2.6.32.41/drivers/ata/pata_marvell.c linux-2.6.32.41/drivers/ata/pata_marvell.c
24105--- linux-2.6.32.41/drivers/ata/pata_marvell.c 2011-03-27 14:31:47.000000000 -0400
24106+++ linux-2.6.32.41/drivers/ata/pata_marvell.c 2011-04-17 15:56:46.000000000 -0400
24107@@ -100,7 +100,7 @@ static struct scsi_host_template marvell
24108 ATA_BMDMA_SHT(DRV_NAME),
24109 };
24110
24111-static struct ata_port_operations marvell_ops = {
24112+static const struct ata_port_operations marvell_ops = {
24113 .inherits = &ata_bmdma_port_ops,
24114 .cable_detect = marvell_cable_detect,
24115 .prereset = marvell_pre_reset,
24116diff -urNp linux-2.6.32.41/drivers/ata/pata_mpc52xx.c linux-2.6.32.41/drivers/ata/pata_mpc52xx.c
24117--- linux-2.6.32.41/drivers/ata/pata_mpc52xx.c 2011-03-27 14:31:47.000000000 -0400
24118+++ linux-2.6.32.41/drivers/ata/pata_mpc52xx.c 2011-04-17 15:56:46.000000000 -0400
24119@@ -609,7 +609,7 @@ static struct scsi_host_template mpc52xx
24120 ATA_PIO_SHT(DRV_NAME),
24121 };
24122
24123-static struct ata_port_operations mpc52xx_ata_port_ops = {
24124+static const struct ata_port_operations mpc52xx_ata_port_ops = {
24125 .inherits = &ata_bmdma_port_ops,
24126 .sff_dev_select = mpc52xx_ata_dev_select,
24127 .set_piomode = mpc52xx_ata_set_piomode,
24128diff -urNp linux-2.6.32.41/drivers/ata/pata_mpiix.c linux-2.6.32.41/drivers/ata/pata_mpiix.c
24129--- linux-2.6.32.41/drivers/ata/pata_mpiix.c 2011-03-27 14:31:47.000000000 -0400
24130+++ linux-2.6.32.41/drivers/ata/pata_mpiix.c 2011-04-17 15:56:46.000000000 -0400
24131@@ -140,7 +140,7 @@ static struct scsi_host_template mpiix_s
24132 ATA_PIO_SHT(DRV_NAME),
24133 };
24134
24135-static struct ata_port_operations mpiix_port_ops = {
24136+static const struct ata_port_operations mpiix_port_ops = {
24137 .inherits = &ata_sff_port_ops,
24138 .qc_issue = mpiix_qc_issue,
24139 .cable_detect = ata_cable_40wire,
24140diff -urNp linux-2.6.32.41/drivers/ata/pata_netcell.c linux-2.6.32.41/drivers/ata/pata_netcell.c
24141--- linux-2.6.32.41/drivers/ata/pata_netcell.c 2011-03-27 14:31:47.000000000 -0400
24142+++ linux-2.6.32.41/drivers/ata/pata_netcell.c 2011-04-17 15:56:46.000000000 -0400
24143@@ -34,7 +34,7 @@ static struct scsi_host_template netcell
24144 ATA_BMDMA_SHT(DRV_NAME),
24145 };
24146
24147-static struct ata_port_operations netcell_ops = {
24148+static const struct ata_port_operations netcell_ops = {
24149 .inherits = &ata_bmdma_port_ops,
24150 .cable_detect = ata_cable_80wire,
24151 .read_id = netcell_read_id,
24152diff -urNp linux-2.6.32.41/drivers/ata/pata_ninja32.c linux-2.6.32.41/drivers/ata/pata_ninja32.c
24153--- linux-2.6.32.41/drivers/ata/pata_ninja32.c 2011-03-27 14:31:47.000000000 -0400
24154+++ linux-2.6.32.41/drivers/ata/pata_ninja32.c 2011-04-17 15:56:46.000000000 -0400
24155@@ -81,7 +81,7 @@ static struct scsi_host_template ninja32
24156 ATA_BMDMA_SHT(DRV_NAME),
24157 };
24158
24159-static struct ata_port_operations ninja32_port_ops = {
24160+static const struct ata_port_operations ninja32_port_ops = {
24161 .inherits = &ata_bmdma_port_ops,
24162 .sff_dev_select = ninja32_dev_select,
24163 .cable_detect = ata_cable_40wire,
24164diff -urNp linux-2.6.32.41/drivers/ata/pata_ns87410.c linux-2.6.32.41/drivers/ata/pata_ns87410.c
24165--- linux-2.6.32.41/drivers/ata/pata_ns87410.c 2011-03-27 14:31:47.000000000 -0400
24166+++ linux-2.6.32.41/drivers/ata/pata_ns87410.c 2011-04-17 15:56:46.000000000 -0400
24167@@ -132,7 +132,7 @@ static struct scsi_host_template ns87410
24168 ATA_PIO_SHT(DRV_NAME),
24169 };
24170
24171-static struct ata_port_operations ns87410_port_ops = {
24172+static const struct ata_port_operations ns87410_port_ops = {
24173 .inherits = &ata_sff_port_ops,
24174 .qc_issue = ns87410_qc_issue,
24175 .cable_detect = ata_cable_40wire,
24176diff -urNp linux-2.6.32.41/drivers/ata/pata_ns87415.c linux-2.6.32.41/drivers/ata/pata_ns87415.c
24177--- linux-2.6.32.41/drivers/ata/pata_ns87415.c 2011-03-27 14:31:47.000000000 -0400
24178+++ linux-2.6.32.41/drivers/ata/pata_ns87415.c 2011-04-17 15:56:46.000000000 -0400
24179@@ -299,7 +299,7 @@ static u8 ns87560_bmdma_status(struct at
24180 }
24181 #endif /* 87560 SuperIO Support */
24182
24183-static struct ata_port_operations ns87415_pata_ops = {
24184+static const struct ata_port_operations ns87415_pata_ops = {
24185 .inherits = &ata_bmdma_port_ops,
24186
24187 .check_atapi_dma = ns87415_check_atapi_dma,
24188@@ -313,7 +313,7 @@ static struct ata_port_operations ns8741
24189 };
24190
24191 #if defined(CONFIG_SUPERIO)
24192-static struct ata_port_operations ns87560_pata_ops = {
24193+static const struct ata_port_operations ns87560_pata_ops = {
24194 .inherits = &ns87415_pata_ops,
24195 .sff_tf_read = ns87560_tf_read,
24196 .sff_check_status = ns87560_check_status,
24197diff -urNp linux-2.6.32.41/drivers/ata/pata_octeon_cf.c linux-2.6.32.41/drivers/ata/pata_octeon_cf.c
24198--- linux-2.6.32.41/drivers/ata/pata_octeon_cf.c 2011-03-27 14:31:47.000000000 -0400
24199+++ linux-2.6.32.41/drivers/ata/pata_octeon_cf.c 2011-04-17 15:56:46.000000000 -0400
24200@@ -801,6 +801,7 @@ static unsigned int octeon_cf_qc_issue(s
24201 return 0;
24202 }
24203
24204+/* cannot be const */
24205 static struct ata_port_operations octeon_cf_ops = {
24206 .inherits = &ata_sff_port_ops,
24207 .check_atapi_dma = octeon_cf_check_atapi_dma,
24208diff -urNp linux-2.6.32.41/drivers/ata/pata_oldpiix.c linux-2.6.32.41/drivers/ata/pata_oldpiix.c
24209--- linux-2.6.32.41/drivers/ata/pata_oldpiix.c 2011-03-27 14:31:47.000000000 -0400
24210+++ linux-2.6.32.41/drivers/ata/pata_oldpiix.c 2011-04-17 15:56:46.000000000 -0400
24211@@ -208,7 +208,7 @@ static struct scsi_host_template oldpiix
24212 ATA_BMDMA_SHT(DRV_NAME),
24213 };
24214
24215-static struct ata_port_operations oldpiix_pata_ops = {
24216+static const struct ata_port_operations oldpiix_pata_ops = {
24217 .inherits = &ata_bmdma_port_ops,
24218 .qc_issue = oldpiix_qc_issue,
24219 .cable_detect = ata_cable_40wire,
24220diff -urNp linux-2.6.32.41/drivers/ata/pata_opti.c linux-2.6.32.41/drivers/ata/pata_opti.c
24221--- linux-2.6.32.41/drivers/ata/pata_opti.c 2011-03-27 14:31:47.000000000 -0400
24222+++ linux-2.6.32.41/drivers/ata/pata_opti.c 2011-04-17 15:56:46.000000000 -0400
24223@@ -152,7 +152,7 @@ static struct scsi_host_template opti_sh
24224 ATA_PIO_SHT(DRV_NAME),
24225 };
24226
24227-static struct ata_port_operations opti_port_ops = {
24228+static const struct ata_port_operations opti_port_ops = {
24229 .inherits = &ata_sff_port_ops,
24230 .cable_detect = ata_cable_40wire,
24231 .set_piomode = opti_set_piomode,
24232diff -urNp linux-2.6.32.41/drivers/ata/pata_optidma.c linux-2.6.32.41/drivers/ata/pata_optidma.c
24233--- linux-2.6.32.41/drivers/ata/pata_optidma.c 2011-03-27 14:31:47.000000000 -0400
24234+++ linux-2.6.32.41/drivers/ata/pata_optidma.c 2011-04-17 15:56:46.000000000 -0400
24235@@ -337,7 +337,7 @@ static struct scsi_host_template optidma
24236 ATA_BMDMA_SHT(DRV_NAME),
24237 };
24238
24239-static struct ata_port_operations optidma_port_ops = {
24240+static const struct ata_port_operations optidma_port_ops = {
24241 .inherits = &ata_bmdma_port_ops,
24242 .cable_detect = ata_cable_40wire,
24243 .set_piomode = optidma_set_pio_mode,
24244@@ -346,7 +346,7 @@ static struct ata_port_operations optidm
24245 .prereset = optidma_pre_reset,
24246 };
24247
24248-static struct ata_port_operations optiplus_port_ops = {
24249+static const struct ata_port_operations optiplus_port_ops = {
24250 .inherits = &optidma_port_ops,
24251 .set_piomode = optiplus_set_pio_mode,
24252 .set_dmamode = optiplus_set_dma_mode,
24253diff -urNp linux-2.6.32.41/drivers/ata/pata_palmld.c linux-2.6.32.41/drivers/ata/pata_palmld.c
24254--- linux-2.6.32.41/drivers/ata/pata_palmld.c 2011-03-27 14:31:47.000000000 -0400
24255+++ linux-2.6.32.41/drivers/ata/pata_palmld.c 2011-04-17 15:56:46.000000000 -0400
24256@@ -37,7 +37,7 @@ static struct scsi_host_template palmld_
24257 ATA_PIO_SHT(DRV_NAME),
24258 };
24259
24260-static struct ata_port_operations palmld_port_ops = {
24261+static const struct ata_port_operations palmld_port_ops = {
24262 .inherits = &ata_sff_port_ops,
24263 .sff_data_xfer = ata_sff_data_xfer_noirq,
24264 .cable_detect = ata_cable_40wire,
24265diff -urNp linux-2.6.32.41/drivers/ata/pata_pcmcia.c linux-2.6.32.41/drivers/ata/pata_pcmcia.c
24266--- linux-2.6.32.41/drivers/ata/pata_pcmcia.c 2011-03-27 14:31:47.000000000 -0400
24267+++ linux-2.6.32.41/drivers/ata/pata_pcmcia.c 2011-04-17 15:56:46.000000000 -0400
24268@@ -162,14 +162,14 @@ static struct scsi_host_template pcmcia_
24269 ATA_PIO_SHT(DRV_NAME),
24270 };
24271
24272-static struct ata_port_operations pcmcia_port_ops = {
24273+static const struct ata_port_operations pcmcia_port_ops = {
24274 .inherits = &ata_sff_port_ops,
24275 .sff_data_xfer = ata_sff_data_xfer_noirq,
24276 .cable_detect = ata_cable_40wire,
24277 .set_mode = pcmcia_set_mode,
24278 };
24279
24280-static struct ata_port_operations pcmcia_8bit_port_ops = {
24281+static const struct ata_port_operations pcmcia_8bit_port_ops = {
24282 .inherits = &ata_sff_port_ops,
24283 .sff_data_xfer = ata_data_xfer_8bit,
24284 .cable_detect = ata_cable_40wire,
24285@@ -256,7 +256,7 @@ static int pcmcia_init_one(struct pcmcia
24286 unsigned long io_base, ctl_base;
24287 void __iomem *io_addr, *ctl_addr;
24288 int n_ports = 1;
24289- struct ata_port_operations *ops = &pcmcia_port_ops;
24290+ const struct ata_port_operations *ops = &pcmcia_port_ops;
24291
24292 info = kzalloc(sizeof(*info), GFP_KERNEL);
24293 if (info == NULL)
24294diff -urNp linux-2.6.32.41/drivers/ata/pata_pdc2027x.c linux-2.6.32.41/drivers/ata/pata_pdc2027x.c
24295--- linux-2.6.32.41/drivers/ata/pata_pdc2027x.c 2011-03-27 14:31:47.000000000 -0400
24296+++ linux-2.6.32.41/drivers/ata/pata_pdc2027x.c 2011-04-17 15:56:46.000000000 -0400
24297@@ -132,14 +132,14 @@ static struct scsi_host_template pdc2027
24298 ATA_BMDMA_SHT(DRV_NAME),
24299 };
24300
24301-static struct ata_port_operations pdc2027x_pata100_ops = {
24302+static const struct ata_port_operations pdc2027x_pata100_ops = {
24303 .inherits = &ata_bmdma_port_ops,
24304 .check_atapi_dma = pdc2027x_check_atapi_dma,
24305 .cable_detect = pdc2027x_cable_detect,
24306 .prereset = pdc2027x_prereset,
24307 };
24308
24309-static struct ata_port_operations pdc2027x_pata133_ops = {
24310+static const struct ata_port_operations pdc2027x_pata133_ops = {
24311 .inherits = &pdc2027x_pata100_ops,
24312 .mode_filter = pdc2027x_mode_filter,
24313 .set_piomode = pdc2027x_set_piomode,
24314diff -urNp linux-2.6.32.41/drivers/ata/pata_pdc202xx_old.c linux-2.6.32.41/drivers/ata/pata_pdc202xx_old.c
24315--- linux-2.6.32.41/drivers/ata/pata_pdc202xx_old.c 2011-03-27 14:31:47.000000000 -0400
24316+++ linux-2.6.32.41/drivers/ata/pata_pdc202xx_old.c 2011-04-17 15:56:46.000000000 -0400
24317@@ -274,7 +274,7 @@ static struct scsi_host_template pdc202x
24318 ATA_BMDMA_SHT(DRV_NAME),
24319 };
24320
24321-static struct ata_port_operations pdc2024x_port_ops = {
24322+static const struct ata_port_operations pdc2024x_port_ops = {
24323 .inherits = &ata_bmdma_port_ops,
24324
24325 .cable_detect = ata_cable_40wire,
24326@@ -284,7 +284,7 @@ static struct ata_port_operations pdc202
24327 .sff_exec_command = pdc202xx_exec_command,
24328 };
24329
24330-static struct ata_port_operations pdc2026x_port_ops = {
24331+static const struct ata_port_operations pdc2026x_port_ops = {
24332 .inherits = &pdc2024x_port_ops,
24333
24334 .check_atapi_dma = pdc2026x_check_atapi_dma,
24335diff -urNp linux-2.6.32.41/drivers/ata/pata_platform.c linux-2.6.32.41/drivers/ata/pata_platform.c
24336--- linux-2.6.32.41/drivers/ata/pata_platform.c 2011-03-27 14:31:47.000000000 -0400
24337+++ linux-2.6.32.41/drivers/ata/pata_platform.c 2011-04-17 15:56:46.000000000 -0400
24338@@ -48,7 +48,7 @@ static struct scsi_host_template pata_pl
24339 ATA_PIO_SHT(DRV_NAME),
24340 };
24341
24342-static struct ata_port_operations pata_platform_port_ops = {
24343+static const struct ata_port_operations pata_platform_port_ops = {
24344 .inherits = &ata_sff_port_ops,
24345 .sff_data_xfer = ata_sff_data_xfer_noirq,
24346 .cable_detect = ata_cable_unknown,
24347diff -urNp linux-2.6.32.41/drivers/ata/pata_qdi.c linux-2.6.32.41/drivers/ata/pata_qdi.c
24348--- linux-2.6.32.41/drivers/ata/pata_qdi.c 2011-03-27 14:31:47.000000000 -0400
24349+++ linux-2.6.32.41/drivers/ata/pata_qdi.c 2011-04-17 15:56:46.000000000 -0400
24350@@ -157,7 +157,7 @@ static struct scsi_host_template qdi_sht
24351 ATA_PIO_SHT(DRV_NAME),
24352 };
24353
24354-static struct ata_port_operations qdi6500_port_ops = {
24355+static const struct ata_port_operations qdi6500_port_ops = {
24356 .inherits = &ata_sff_port_ops,
24357 .qc_issue = qdi_qc_issue,
24358 .sff_data_xfer = qdi_data_xfer,
24359@@ -165,7 +165,7 @@ static struct ata_port_operations qdi650
24360 .set_piomode = qdi6500_set_piomode,
24361 };
24362
24363-static struct ata_port_operations qdi6580_port_ops = {
24364+static const struct ata_port_operations qdi6580_port_ops = {
24365 .inherits = &qdi6500_port_ops,
24366 .set_piomode = qdi6580_set_piomode,
24367 };
24368diff -urNp linux-2.6.32.41/drivers/ata/pata_radisys.c linux-2.6.32.41/drivers/ata/pata_radisys.c
24369--- linux-2.6.32.41/drivers/ata/pata_radisys.c 2011-03-27 14:31:47.000000000 -0400
24370+++ linux-2.6.32.41/drivers/ata/pata_radisys.c 2011-04-17 15:56:46.000000000 -0400
24371@@ -187,7 +187,7 @@ static struct scsi_host_template radisys
24372 ATA_BMDMA_SHT(DRV_NAME),
24373 };
24374
24375-static struct ata_port_operations radisys_pata_ops = {
24376+static const struct ata_port_operations radisys_pata_ops = {
24377 .inherits = &ata_bmdma_port_ops,
24378 .qc_issue = radisys_qc_issue,
24379 .cable_detect = ata_cable_unknown,
24380diff -urNp linux-2.6.32.41/drivers/ata/pata_rb532_cf.c linux-2.6.32.41/drivers/ata/pata_rb532_cf.c
24381--- linux-2.6.32.41/drivers/ata/pata_rb532_cf.c 2011-03-27 14:31:47.000000000 -0400
24382+++ linux-2.6.32.41/drivers/ata/pata_rb532_cf.c 2011-04-17 15:56:46.000000000 -0400
24383@@ -68,7 +68,7 @@ static irqreturn_t rb532_pata_irq_handle
24384 return IRQ_HANDLED;
24385 }
24386
24387-static struct ata_port_operations rb532_pata_port_ops = {
24388+static const struct ata_port_operations rb532_pata_port_ops = {
24389 .inherits = &ata_sff_port_ops,
24390 .sff_data_xfer = ata_sff_data_xfer32,
24391 };
24392diff -urNp linux-2.6.32.41/drivers/ata/pata_rdc.c linux-2.6.32.41/drivers/ata/pata_rdc.c
24393--- linux-2.6.32.41/drivers/ata/pata_rdc.c 2011-03-27 14:31:47.000000000 -0400
24394+++ linux-2.6.32.41/drivers/ata/pata_rdc.c 2011-04-17 15:56:46.000000000 -0400
24395@@ -272,7 +272,7 @@ static void rdc_set_dmamode(struct ata_p
24396 pci_write_config_byte(dev, 0x48, udma_enable);
24397 }
24398
24399-static struct ata_port_operations rdc_pata_ops = {
24400+static const struct ata_port_operations rdc_pata_ops = {
24401 .inherits = &ata_bmdma32_port_ops,
24402 .cable_detect = rdc_pata_cable_detect,
24403 .set_piomode = rdc_set_piomode,
24404diff -urNp linux-2.6.32.41/drivers/ata/pata_rz1000.c linux-2.6.32.41/drivers/ata/pata_rz1000.c
24405--- linux-2.6.32.41/drivers/ata/pata_rz1000.c 2011-03-27 14:31:47.000000000 -0400
24406+++ linux-2.6.32.41/drivers/ata/pata_rz1000.c 2011-04-17 15:56:46.000000000 -0400
24407@@ -54,7 +54,7 @@ static struct scsi_host_template rz1000_
24408 ATA_PIO_SHT(DRV_NAME),
24409 };
24410
24411-static struct ata_port_operations rz1000_port_ops = {
24412+static const struct ata_port_operations rz1000_port_ops = {
24413 .inherits = &ata_sff_port_ops,
24414 .cable_detect = ata_cable_40wire,
24415 .set_mode = rz1000_set_mode,
24416diff -urNp linux-2.6.32.41/drivers/ata/pata_sc1200.c linux-2.6.32.41/drivers/ata/pata_sc1200.c
24417--- linux-2.6.32.41/drivers/ata/pata_sc1200.c 2011-03-27 14:31:47.000000000 -0400
24418+++ linux-2.6.32.41/drivers/ata/pata_sc1200.c 2011-04-17 15:56:46.000000000 -0400
24419@@ -207,7 +207,7 @@ static struct scsi_host_template sc1200_
24420 .sg_tablesize = LIBATA_DUMB_MAX_PRD,
24421 };
24422
24423-static struct ata_port_operations sc1200_port_ops = {
24424+static const struct ata_port_operations sc1200_port_ops = {
24425 .inherits = &ata_bmdma_port_ops,
24426 .qc_prep = ata_sff_dumb_qc_prep,
24427 .qc_issue = sc1200_qc_issue,
24428diff -urNp linux-2.6.32.41/drivers/ata/pata_scc.c linux-2.6.32.41/drivers/ata/pata_scc.c
24429--- linux-2.6.32.41/drivers/ata/pata_scc.c 2011-03-27 14:31:47.000000000 -0400
24430+++ linux-2.6.32.41/drivers/ata/pata_scc.c 2011-04-17 15:56:46.000000000 -0400
24431@@ -965,7 +965,7 @@ static struct scsi_host_template scc_sht
24432 ATA_BMDMA_SHT(DRV_NAME),
24433 };
24434
24435-static struct ata_port_operations scc_pata_ops = {
24436+static const struct ata_port_operations scc_pata_ops = {
24437 .inherits = &ata_bmdma_port_ops,
24438
24439 .set_piomode = scc_set_piomode,
24440diff -urNp linux-2.6.32.41/drivers/ata/pata_sch.c linux-2.6.32.41/drivers/ata/pata_sch.c
24441--- linux-2.6.32.41/drivers/ata/pata_sch.c 2011-03-27 14:31:47.000000000 -0400
24442+++ linux-2.6.32.41/drivers/ata/pata_sch.c 2011-04-17 15:56:46.000000000 -0400
24443@@ -75,7 +75,7 @@ static struct scsi_host_template sch_sht
24444 ATA_BMDMA_SHT(DRV_NAME),
24445 };
24446
24447-static struct ata_port_operations sch_pata_ops = {
24448+static const struct ata_port_operations sch_pata_ops = {
24449 .inherits = &ata_bmdma_port_ops,
24450 .cable_detect = ata_cable_unknown,
24451 .set_piomode = sch_set_piomode,
24452diff -urNp linux-2.6.32.41/drivers/ata/pata_serverworks.c linux-2.6.32.41/drivers/ata/pata_serverworks.c
24453--- linux-2.6.32.41/drivers/ata/pata_serverworks.c 2011-03-27 14:31:47.000000000 -0400
24454+++ linux-2.6.32.41/drivers/ata/pata_serverworks.c 2011-04-17 15:56:46.000000000 -0400
24455@@ -299,7 +299,7 @@ static struct scsi_host_template serverw
24456 ATA_BMDMA_SHT(DRV_NAME),
24457 };
24458
24459-static struct ata_port_operations serverworks_osb4_port_ops = {
24460+static const struct ata_port_operations serverworks_osb4_port_ops = {
24461 .inherits = &ata_bmdma_port_ops,
24462 .cable_detect = serverworks_cable_detect,
24463 .mode_filter = serverworks_osb4_filter,
24464@@ -307,7 +307,7 @@ static struct ata_port_operations server
24465 .set_dmamode = serverworks_set_dmamode,
24466 };
24467
24468-static struct ata_port_operations serverworks_csb_port_ops = {
24469+static const struct ata_port_operations serverworks_csb_port_ops = {
24470 .inherits = &serverworks_osb4_port_ops,
24471 .mode_filter = serverworks_csb_filter,
24472 };
24473diff -urNp linux-2.6.32.41/drivers/ata/pata_sil680.c linux-2.6.32.41/drivers/ata/pata_sil680.c
24474--- linux-2.6.32.41/drivers/ata/pata_sil680.c 2011-03-27 14:31:47.000000000 -0400
24475+++ linux-2.6.32.41/drivers/ata/pata_sil680.c 2011-04-17 15:56:46.000000000 -0400
24476@@ -194,7 +194,7 @@ static struct scsi_host_template sil680_
24477 ATA_BMDMA_SHT(DRV_NAME),
24478 };
24479
24480-static struct ata_port_operations sil680_port_ops = {
24481+static const struct ata_port_operations sil680_port_ops = {
24482 .inherits = &ata_bmdma32_port_ops,
24483 .cable_detect = sil680_cable_detect,
24484 .set_piomode = sil680_set_piomode,
24485diff -urNp linux-2.6.32.41/drivers/ata/pata_sis.c linux-2.6.32.41/drivers/ata/pata_sis.c
24486--- linux-2.6.32.41/drivers/ata/pata_sis.c 2011-03-27 14:31:47.000000000 -0400
24487+++ linux-2.6.32.41/drivers/ata/pata_sis.c 2011-04-17 15:56:46.000000000 -0400
24488@@ -503,47 +503,47 @@ static struct scsi_host_template sis_sht
24489 ATA_BMDMA_SHT(DRV_NAME),
24490 };
24491
24492-static struct ata_port_operations sis_133_for_sata_ops = {
24493+static const struct ata_port_operations sis_133_for_sata_ops = {
24494 .inherits = &ata_bmdma_port_ops,
24495 .set_piomode = sis_133_set_piomode,
24496 .set_dmamode = sis_133_set_dmamode,
24497 .cable_detect = sis_133_cable_detect,
24498 };
24499
24500-static struct ata_port_operations sis_base_ops = {
24501+static const struct ata_port_operations sis_base_ops = {
24502 .inherits = &ata_bmdma_port_ops,
24503 .prereset = sis_pre_reset,
24504 };
24505
24506-static struct ata_port_operations sis_133_ops = {
24507+static const struct ata_port_operations sis_133_ops = {
24508 .inherits = &sis_base_ops,
24509 .set_piomode = sis_133_set_piomode,
24510 .set_dmamode = sis_133_set_dmamode,
24511 .cable_detect = sis_133_cable_detect,
24512 };
24513
24514-static struct ata_port_operations sis_133_early_ops = {
24515+static const struct ata_port_operations sis_133_early_ops = {
24516 .inherits = &sis_base_ops,
24517 .set_piomode = sis_100_set_piomode,
24518 .set_dmamode = sis_133_early_set_dmamode,
24519 .cable_detect = sis_66_cable_detect,
24520 };
24521
24522-static struct ata_port_operations sis_100_ops = {
24523+static const struct ata_port_operations sis_100_ops = {
24524 .inherits = &sis_base_ops,
24525 .set_piomode = sis_100_set_piomode,
24526 .set_dmamode = sis_100_set_dmamode,
24527 .cable_detect = sis_66_cable_detect,
24528 };
24529
24530-static struct ata_port_operations sis_66_ops = {
24531+static const struct ata_port_operations sis_66_ops = {
24532 .inherits = &sis_base_ops,
24533 .set_piomode = sis_old_set_piomode,
24534 .set_dmamode = sis_66_set_dmamode,
24535 .cable_detect = sis_66_cable_detect,
24536 };
24537
24538-static struct ata_port_operations sis_old_ops = {
24539+static const struct ata_port_operations sis_old_ops = {
24540 .inherits = &sis_base_ops,
24541 .set_piomode = sis_old_set_piomode,
24542 .set_dmamode = sis_old_set_dmamode,
24543diff -urNp linux-2.6.32.41/drivers/ata/pata_sl82c105.c linux-2.6.32.41/drivers/ata/pata_sl82c105.c
24544--- linux-2.6.32.41/drivers/ata/pata_sl82c105.c 2011-03-27 14:31:47.000000000 -0400
24545+++ linux-2.6.32.41/drivers/ata/pata_sl82c105.c 2011-04-17 15:56:46.000000000 -0400
24546@@ -231,7 +231,7 @@ static struct scsi_host_template sl82c10
24547 ATA_BMDMA_SHT(DRV_NAME),
24548 };
24549
24550-static struct ata_port_operations sl82c105_port_ops = {
24551+static const struct ata_port_operations sl82c105_port_ops = {
24552 .inherits = &ata_bmdma_port_ops,
24553 .qc_defer = sl82c105_qc_defer,
24554 .bmdma_start = sl82c105_bmdma_start,
24555diff -urNp linux-2.6.32.41/drivers/ata/pata_triflex.c linux-2.6.32.41/drivers/ata/pata_triflex.c
24556--- linux-2.6.32.41/drivers/ata/pata_triflex.c 2011-03-27 14:31:47.000000000 -0400
24557+++ linux-2.6.32.41/drivers/ata/pata_triflex.c 2011-04-17 15:56:46.000000000 -0400
24558@@ -178,7 +178,7 @@ static struct scsi_host_template triflex
24559 ATA_BMDMA_SHT(DRV_NAME),
24560 };
24561
24562-static struct ata_port_operations triflex_port_ops = {
24563+static const struct ata_port_operations triflex_port_ops = {
24564 .inherits = &ata_bmdma_port_ops,
24565 .bmdma_start = triflex_bmdma_start,
24566 .bmdma_stop = triflex_bmdma_stop,
24567diff -urNp linux-2.6.32.41/drivers/ata/pata_via.c linux-2.6.32.41/drivers/ata/pata_via.c
24568--- linux-2.6.32.41/drivers/ata/pata_via.c 2011-03-27 14:31:47.000000000 -0400
24569+++ linux-2.6.32.41/drivers/ata/pata_via.c 2011-04-17 15:56:46.000000000 -0400
24570@@ -419,7 +419,7 @@ static struct scsi_host_template via_sht
24571 ATA_BMDMA_SHT(DRV_NAME),
24572 };
24573
24574-static struct ata_port_operations via_port_ops = {
24575+static const struct ata_port_operations via_port_ops = {
24576 .inherits = &ata_bmdma_port_ops,
24577 .cable_detect = via_cable_detect,
24578 .set_piomode = via_set_piomode,
24579@@ -429,7 +429,7 @@ static struct ata_port_operations via_po
24580 .port_start = via_port_start,
24581 };
24582
24583-static struct ata_port_operations via_port_ops_noirq = {
24584+static const struct ata_port_operations via_port_ops_noirq = {
24585 .inherits = &via_port_ops,
24586 .sff_data_xfer = ata_sff_data_xfer_noirq,
24587 };
24588diff -urNp linux-2.6.32.41/drivers/ata/pata_winbond.c linux-2.6.32.41/drivers/ata/pata_winbond.c
24589--- linux-2.6.32.41/drivers/ata/pata_winbond.c 2011-03-27 14:31:47.000000000 -0400
24590+++ linux-2.6.32.41/drivers/ata/pata_winbond.c 2011-04-17 15:56:46.000000000 -0400
24591@@ -125,7 +125,7 @@ static struct scsi_host_template winbond
24592 ATA_PIO_SHT(DRV_NAME),
24593 };
24594
24595-static struct ata_port_operations winbond_port_ops = {
24596+static const struct ata_port_operations winbond_port_ops = {
24597 .inherits = &ata_sff_port_ops,
24598 .sff_data_xfer = winbond_data_xfer,
24599 .cable_detect = ata_cable_40wire,
24600diff -urNp linux-2.6.32.41/drivers/ata/pdc_adma.c linux-2.6.32.41/drivers/ata/pdc_adma.c
24601--- linux-2.6.32.41/drivers/ata/pdc_adma.c 2011-03-27 14:31:47.000000000 -0400
24602+++ linux-2.6.32.41/drivers/ata/pdc_adma.c 2011-04-17 15:56:46.000000000 -0400
24603@@ -145,7 +145,7 @@ static struct scsi_host_template adma_at
24604 .dma_boundary = ADMA_DMA_BOUNDARY,
24605 };
24606
24607-static struct ata_port_operations adma_ata_ops = {
24608+static const struct ata_port_operations adma_ata_ops = {
24609 .inherits = &ata_sff_port_ops,
24610
24611 .lost_interrupt = ATA_OP_NULL,
24612diff -urNp linux-2.6.32.41/drivers/ata/sata_fsl.c linux-2.6.32.41/drivers/ata/sata_fsl.c
24613--- linux-2.6.32.41/drivers/ata/sata_fsl.c 2011-03-27 14:31:47.000000000 -0400
24614+++ linux-2.6.32.41/drivers/ata/sata_fsl.c 2011-04-17 15:56:46.000000000 -0400
24615@@ -1258,7 +1258,7 @@ static struct scsi_host_template sata_fs
24616 .dma_boundary = ATA_DMA_BOUNDARY,
24617 };
24618
24619-static struct ata_port_operations sata_fsl_ops = {
24620+static const struct ata_port_operations sata_fsl_ops = {
24621 .inherits = &sata_pmp_port_ops,
24622
24623 .qc_defer = ata_std_qc_defer,
24624diff -urNp linux-2.6.32.41/drivers/ata/sata_inic162x.c linux-2.6.32.41/drivers/ata/sata_inic162x.c
24625--- linux-2.6.32.41/drivers/ata/sata_inic162x.c 2011-03-27 14:31:47.000000000 -0400
24626+++ linux-2.6.32.41/drivers/ata/sata_inic162x.c 2011-04-17 15:56:46.000000000 -0400
24627@@ -721,7 +721,7 @@ static int inic_port_start(struct ata_po
24628 return 0;
24629 }
24630
24631-static struct ata_port_operations inic_port_ops = {
24632+static const struct ata_port_operations inic_port_ops = {
24633 .inherits = &sata_port_ops,
24634
24635 .check_atapi_dma = inic_check_atapi_dma,
24636diff -urNp linux-2.6.32.41/drivers/ata/sata_mv.c linux-2.6.32.41/drivers/ata/sata_mv.c
24637--- linux-2.6.32.41/drivers/ata/sata_mv.c 2011-03-27 14:31:47.000000000 -0400
24638+++ linux-2.6.32.41/drivers/ata/sata_mv.c 2011-04-17 15:56:46.000000000 -0400
24639@@ -656,7 +656,7 @@ static struct scsi_host_template mv6_sht
24640 .dma_boundary = MV_DMA_BOUNDARY,
24641 };
24642
24643-static struct ata_port_operations mv5_ops = {
24644+static const struct ata_port_operations mv5_ops = {
24645 .inherits = &ata_sff_port_ops,
24646
24647 .lost_interrupt = ATA_OP_NULL,
24648@@ -678,7 +678,7 @@ static struct ata_port_operations mv5_op
24649 .port_stop = mv_port_stop,
24650 };
24651
24652-static struct ata_port_operations mv6_ops = {
24653+static const struct ata_port_operations mv6_ops = {
24654 .inherits = &mv5_ops,
24655 .dev_config = mv6_dev_config,
24656 .scr_read = mv_scr_read,
24657@@ -698,7 +698,7 @@ static struct ata_port_operations mv6_op
24658 .bmdma_status = mv_bmdma_status,
24659 };
24660
24661-static struct ata_port_operations mv_iie_ops = {
24662+static const struct ata_port_operations mv_iie_ops = {
24663 .inherits = &mv6_ops,
24664 .dev_config = ATA_OP_NULL,
24665 .qc_prep = mv_qc_prep_iie,
24666diff -urNp linux-2.6.32.41/drivers/ata/sata_nv.c linux-2.6.32.41/drivers/ata/sata_nv.c
24667--- linux-2.6.32.41/drivers/ata/sata_nv.c 2011-03-27 14:31:47.000000000 -0400
24668+++ linux-2.6.32.41/drivers/ata/sata_nv.c 2011-04-17 15:56:46.000000000 -0400
24669@@ -464,7 +464,7 @@ static struct scsi_host_template nv_swnc
24670 * cases. Define nv_hardreset() which only kicks in for post-boot
24671 * probing and use it for all variants.
24672 */
24673-static struct ata_port_operations nv_generic_ops = {
24674+static const struct ata_port_operations nv_generic_ops = {
24675 .inherits = &ata_bmdma_port_ops,
24676 .lost_interrupt = ATA_OP_NULL,
24677 .scr_read = nv_scr_read,
24678@@ -472,20 +472,20 @@ static struct ata_port_operations nv_gen
24679 .hardreset = nv_hardreset,
24680 };
24681
24682-static struct ata_port_operations nv_nf2_ops = {
24683+static const struct ata_port_operations nv_nf2_ops = {
24684 .inherits = &nv_generic_ops,
24685 .freeze = nv_nf2_freeze,
24686 .thaw = nv_nf2_thaw,
24687 };
24688
24689-static struct ata_port_operations nv_ck804_ops = {
24690+static const struct ata_port_operations nv_ck804_ops = {
24691 .inherits = &nv_generic_ops,
24692 .freeze = nv_ck804_freeze,
24693 .thaw = nv_ck804_thaw,
24694 .host_stop = nv_ck804_host_stop,
24695 };
24696
24697-static struct ata_port_operations nv_adma_ops = {
24698+static const struct ata_port_operations nv_adma_ops = {
24699 .inherits = &nv_ck804_ops,
24700
24701 .check_atapi_dma = nv_adma_check_atapi_dma,
24702@@ -509,7 +509,7 @@ static struct ata_port_operations nv_adm
24703 .host_stop = nv_adma_host_stop,
24704 };
24705
24706-static struct ata_port_operations nv_swncq_ops = {
24707+static const struct ata_port_operations nv_swncq_ops = {
24708 .inherits = &nv_generic_ops,
24709
24710 .qc_defer = ata_std_qc_defer,
24711diff -urNp linux-2.6.32.41/drivers/ata/sata_promise.c linux-2.6.32.41/drivers/ata/sata_promise.c
24712--- linux-2.6.32.41/drivers/ata/sata_promise.c 2011-03-27 14:31:47.000000000 -0400
24713+++ linux-2.6.32.41/drivers/ata/sata_promise.c 2011-04-17 15:56:46.000000000 -0400
24714@@ -195,7 +195,7 @@ static const struct ata_port_operations
24715 .error_handler = pdc_error_handler,
24716 };
24717
24718-static struct ata_port_operations pdc_sata_ops = {
24719+static const struct ata_port_operations pdc_sata_ops = {
24720 .inherits = &pdc_common_ops,
24721 .cable_detect = pdc_sata_cable_detect,
24722 .freeze = pdc_sata_freeze,
24723@@ -208,14 +208,14 @@ static struct ata_port_operations pdc_sa
24724
24725 /* First-generation chips need a more restrictive ->check_atapi_dma op,
24726 and ->freeze/thaw that ignore the hotplug controls. */
24727-static struct ata_port_operations pdc_old_sata_ops = {
24728+static const struct ata_port_operations pdc_old_sata_ops = {
24729 .inherits = &pdc_sata_ops,
24730 .freeze = pdc_freeze,
24731 .thaw = pdc_thaw,
24732 .check_atapi_dma = pdc_old_sata_check_atapi_dma,
24733 };
24734
24735-static struct ata_port_operations pdc_pata_ops = {
24736+static const struct ata_port_operations pdc_pata_ops = {
24737 .inherits = &pdc_common_ops,
24738 .cable_detect = pdc_pata_cable_detect,
24739 .freeze = pdc_freeze,
24740diff -urNp linux-2.6.32.41/drivers/ata/sata_qstor.c linux-2.6.32.41/drivers/ata/sata_qstor.c
24741--- linux-2.6.32.41/drivers/ata/sata_qstor.c 2011-03-27 14:31:47.000000000 -0400
24742+++ linux-2.6.32.41/drivers/ata/sata_qstor.c 2011-04-17 15:56:46.000000000 -0400
24743@@ -132,7 +132,7 @@ static struct scsi_host_template qs_ata_
24744 .dma_boundary = QS_DMA_BOUNDARY,
24745 };
24746
24747-static struct ata_port_operations qs_ata_ops = {
24748+static const struct ata_port_operations qs_ata_ops = {
24749 .inherits = &ata_sff_port_ops,
24750
24751 .check_atapi_dma = qs_check_atapi_dma,
24752diff -urNp linux-2.6.32.41/drivers/ata/sata_sil24.c linux-2.6.32.41/drivers/ata/sata_sil24.c
24753--- linux-2.6.32.41/drivers/ata/sata_sil24.c 2011-03-27 14:31:47.000000000 -0400
24754+++ linux-2.6.32.41/drivers/ata/sata_sil24.c 2011-04-17 15:56:46.000000000 -0400
24755@@ -388,7 +388,7 @@ static struct scsi_host_template sil24_s
24756 .dma_boundary = ATA_DMA_BOUNDARY,
24757 };
24758
24759-static struct ata_port_operations sil24_ops = {
24760+static const struct ata_port_operations sil24_ops = {
24761 .inherits = &sata_pmp_port_ops,
24762
24763 .qc_defer = sil24_qc_defer,
24764diff -urNp linux-2.6.32.41/drivers/ata/sata_sil.c linux-2.6.32.41/drivers/ata/sata_sil.c
24765--- linux-2.6.32.41/drivers/ata/sata_sil.c 2011-03-27 14:31:47.000000000 -0400
24766+++ linux-2.6.32.41/drivers/ata/sata_sil.c 2011-04-17 15:56:46.000000000 -0400
24767@@ -182,7 +182,7 @@ static struct scsi_host_template sil_sht
24768 .sg_tablesize = ATA_MAX_PRD
24769 };
24770
24771-static struct ata_port_operations sil_ops = {
24772+static const struct ata_port_operations sil_ops = {
24773 .inherits = &ata_bmdma32_port_ops,
24774 .dev_config = sil_dev_config,
24775 .set_mode = sil_set_mode,
24776diff -urNp linux-2.6.32.41/drivers/ata/sata_sis.c linux-2.6.32.41/drivers/ata/sata_sis.c
24777--- linux-2.6.32.41/drivers/ata/sata_sis.c 2011-03-27 14:31:47.000000000 -0400
24778+++ linux-2.6.32.41/drivers/ata/sata_sis.c 2011-04-17 15:56:46.000000000 -0400
24779@@ -89,7 +89,7 @@ static struct scsi_host_template sis_sht
24780 ATA_BMDMA_SHT(DRV_NAME),
24781 };
24782
24783-static struct ata_port_operations sis_ops = {
24784+static const struct ata_port_operations sis_ops = {
24785 .inherits = &ata_bmdma_port_ops,
24786 .scr_read = sis_scr_read,
24787 .scr_write = sis_scr_write,
24788diff -urNp linux-2.6.32.41/drivers/ata/sata_svw.c linux-2.6.32.41/drivers/ata/sata_svw.c
24789--- linux-2.6.32.41/drivers/ata/sata_svw.c 2011-03-27 14:31:47.000000000 -0400
24790+++ linux-2.6.32.41/drivers/ata/sata_svw.c 2011-04-17 15:56:46.000000000 -0400
24791@@ -344,7 +344,7 @@ static struct scsi_host_template k2_sata
24792 };
24793
24794
24795-static struct ata_port_operations k2_sata_ops = {
24796+static const struct ata_port_operations k2_sata_ops = {
24797 .inherits = &ata_bmdma_port_ops,
24798 .sff_tf_load = k2_sata_tf_load,
24799 .sff_tf_read = k2_sata_tf_read,
24800diff -urNp linux-2.6.32.41/drivers/ata/sata_sx4.c linux-2.6.32.41/drivers/ata/sata_sx4.c
24801--- linux-2.6.32.41/drivers/ata/sata_sx4.c 2011-03-27 14:31:47.000000000 -0400
24802+++ linux-2.6.32.41/drivers/ata/sata_sx4.c 2011-04-17 15:56:46.000000000 -0400
24803@@ -248,7 +248,7 @@ static struct scsi_host_template pdc_sat
24804 };
24805
24806 /* TODO: inherit from base port_ops after converting to new EH */
24807-static struct ata_port_operations pdc_20621_ops = {
24808+static const struct ata_port_operations pdc_20621_ops = {
24809 .inherits = &ata_sff_port_ops,
24810
24811 .check_atapi_dma = pdc_check_atapi_dma,
24812diff -urNp linux-2.6.32.41/drivers/ata/sata_uli.c linux-2.6.32.41/drivers/ata/sata_uli.c
24813--- linux-2.6.32.41/drivers/ata/sata_uli.c 2011-03-27 14:31:47.000000000 -0400
24814+++ linux-2.6.32.41/drivers/ata/sata_uli.c 2011-04-17 15:56:46.000000000 -0400
24815@@ -79,7 +79,7 @@ static struct scsi_host_template uli_sht
24816 ATA_BMDMA_SHT(DRV_NAME),
24817 };
24818
24819-static struct ata_port_operations uli_ops = {
24820+static const struct ata_port_operations uli_ops = {
24821 .inherits = &ata_bmdma_port_ops,
24822 .scr_read = uli_scr_read,
24823 .scr_write = uli_scr_write,
24824diff -urNp linux-2.6.32.41/drivers/ata/sata_via.c linux-2.6.32.41/drivers/ata/sata_via.c
24825--- linux-2.6.32.41/drivers/ata/sata_via.c 2011-05-10 22:12:01.000000000 -0400
24826+++ linux-2.6.32.41/drivers/ata/sata_via.c 2011-05-10 22:15:08.000000000 -0400
24827@@ -115,32 +115,32 @@ static struct scsi_host_template svia_sh
24828 ATA_BMDMA_SHT(DRV_NAME),
24829 };
24830
24831-static struct ata_port_operations svia_base_ops = {
24832+static const struct ata_port_operations svia_base_ops = {
24833 .inherits = &ata_bmdma_port_ops,
24834 .sff_tf_load = svia_tf_load,
24835 };
24836
24837-static struct ata_port_operations vt6420_sata_ops = {
24838+static const struct ata_port_operations vt6420_sata_ops = {
24839 .inherits = &svia_base_ops,
24840 .freeze = svia_noop_freeze,
24841 .prereset = vt6420_prereset,
24842 .bmdma_start = vt6420_bmdma_start,
24843 };
24844
24845-static struct ata_port_operations vt6421_pata_ops = {
24846+static const struct ata_port_operations vt6421_pata_ops = {
24847 .inherits = &svia_base_ops,
24848 .cable_detect = vt6421_pata_cable_detect,
24849 .set_piomode = vt6421_set_pio_mode,
24850 .set_dmamode = vt6421_set_dma_mode,
24851 };
24852
24853-static struct ata_port_operations vt6421_sata_ops = {
24854+static const struct ata_port_operations vt6421_sata_ops = {
24855 .inherits = &svia_base_ops,
24856 .scr_read = svia_scr_read,
24857 .scr_write = svia_scr_write,
24858 };
24859
24860-static struct ata_port_operations vt8251_ops = {
24861+static const struct ata_port_operations vt8251_ops = {
24862 .inherits = &svia_base_ops,
24863 .hardreset = sata_std_hardreset,
24864 .scr_read = vt8251_scr_read,
24865diff -urNp linux-2.6.32.41/drivers/ata/sata_vsc.c linux-2.6.32.41/drivers/ata/sata_vsc.c
24866--- linux-2.6.32.41/drivers/ata/sata_vsc.c 2011-03-27 14:31:47.000000000 -0400
24867+++ linux-2.6.32.41/drivers/ata/sata_vsc.c 2011-04-17 15:56:46.000000000 -0400
24868@@ -306,7 +306,7 @@ static struct scsi_host_template vsc_sat
24869 };
24870
24871
24872-static struct ata_port_operations vsc_sata_ops = {
24873+static const struct ata_port_operations vsc_sata_ops = {
24874 .inherits = &ata_bmdma_port_ops,
24875 /* The IRQ handling is not quite standard SFF behaviour so we
24876 cannot use the default lost interrupt handler */
24877diff -urNp linux-2.6.32.41/drivers/atm/adummy.c linux-2.6.32.41/drivers/atm/adummy.c
24878--- linux-2.6.32.41/drivers/atm/adummy.c 2011-03-27 14:31:47.000000000 -0400
24879+++ linux-2.6.32.41/drivers/atm/adummy.c 2011-04-17 15:56:46.000000000 -0400
24880@@ -77,7 +77,7 @@ adummy_send(struct atm_vcc *vcc, struct
24881 vcc->pop(vcc, skb);
24882 else
24883 dev_kfree_skb_any(skb);
24884- atomic_inc(&vcc->stats->tx);
24885+ atomic_inc_unchecked(&vcc->stats->tx);
24886
24887 return 0;
24888 }
24889diff -urNp linux-2.6.32.41/drivers/atm/ambassador.c linux-2.6.32.41/drivers/atm/ambassador.c
24890--- linux-2.6.32.41/drivers/atm/ambassador.c 2011-03-27 14:31:47.000000000 -0400
24891+++ linux-2.6.32.41/drivers/atm/ambassador.c 2011-04-17 15:56:46.000000000 -0400
24892@@ -453,7 +453,7 @@ static void tx_complete (amb_dev * dev,
24893 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
24894
24895 // VC layer stats
24896- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
24897+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
24898
24899 // free the descriptor
24900 kfree (tx_descr);
24901@@ -494,7 +494,7 @@ static void rx_complete (amb_dev * dev,
24902 dump_skb ("<<<", vc, skb);
24903
24904 // VC layer stats
24905- atomic_inc(&atm_vcc->stats->rx);
24906+ atomic_inc_unchecked(&atm_vcc->stats->rx);
24907 __net_timestamp(skb);
24908 // end of our responsability
24909 atm_vcc->push (atm_vcc, skb);
24910@@ -509,7 +509,7 @@ static void rx_complete (amb_dev * dev,
24911 } else {
24912 PRINTK (KERN_INFO, "dropped over-size frame");
24913 // should we count this?
24914- atomic_inc(&atm_vcc->stats->rx_drop);
24915+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
24916 }
24917
24918 } else {
24919@@ -1341,7 +1341,7 @@ static int amb_send (struct atm_vcc * at
24920 }
24921
24922 if (check_area (skb->data, skb->len)) {
24923- atomic_inc(&atm_vcc->stats->tx_err);
24924+ atomic_inc_unchecked(&atm_vcc->stats->tx_err);
24925 return -ENOMEM; // ?
24926 }
24927
24928diff -urNp linux-2.6.32.41/drivers/atm/atmtcp.c linux-2.6.32.41/drivers/atm/atmtcp.c
24929--- linux-2.6.32.41/drivers/atm/atmtcp.c 2011-03-27 14:31:47.000000000 -0400
24930+++ linux-2.6.32.41/drivers/atm/atmtcp.c 2011-04-17 15:56:46.000000000 -0400
24931@@ -206,7 +206,7 @@ static int atmtcp_v_send(struct atm_vcc
24932 if (vcc->pop) vcc->pop(vcc,skb);
24933 else dev_kfree_skb(skb);
24934 if (dev_data) return 0;
24935- atomic_inc(&vcc->stats->tx_err);
24936+ atomic_inc_unchecked(&vcc->stats->tx_err);
24937 return -ENOLINK;
24938 }
24939 size = skb->len+sizeof(struct atmtcp_hdr);
24940@@ -214,7 +214,7 @@ static int atmtcp_v_send(struct atm_vcc
24941 if (!new_skb) {
24942 if (vcc->pop) vcc->pop(vcc,skb);
24943 else dev_kfree_skb(skb);
24944- atomic_inc(&vcc->stats->tx_err);
24945+ atomic_inc_unchecked(&vcc->stats->tx_err);
24946 return -ENOBUFS;
24947 }
24948 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
24949@@ -225,8 +225,8 @@ static int atmtcp_v_send(struct atm_vcc
24950 if (vcc->pop) vcc->pop(vcc,skb);
24951 else dev_kfree_skb(skb);
24952 out_vcc->push(out_vcc,new_skb);
24953- atomic_inc(&vcc->stats->tx);
24954- atomic_inc(&out_vcc->stats->rx);
24955+ atomic_inc_unchecked(&vcc->stats->tx);
24956+ atomic_inc_unchecked(&out_vcc->stats->rx);
24957 return 0;
24958 }
24959
24960@@ -300,7 +300,7 @@ static int atmtcp_c_send(struct atm_vcc
24961 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
24962 read_unlock(&vcc_sklist_lock);
24963 if (!out_vcc) {
24964- atomic_inc(&vcc->stats->tx_err);
24965+ atomic_inc_unchecked(&vcc->stats->tx_err);
24966 goto done;
24967 }
24968 skb_pull(skb,sizeof(struct atmtcp_hdr));
24969@@ -312,8 +312,8 @@ static int atmtcp_c_send(struct atm_vcc
24970 __net_timestamp(new_skb);
24971 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
24972 out_vcc->push(out_vcc,new_skb);
24973- atomic_inc(&vcc->stats->tx);
24974- atomic_inc(&out_vcc->stats->rx);
24975+ atomic_inc_unchecked(&vcc->stats->tx);
24976+ atomic_inc_unchecked(&out_vcc->stats->rx);
24977 done:
24978 if (vcc->pop) vcc->pop(vcc,skb);
24979 else dev_kfree_skb(skb);
24980diff -urNp linux-2.6.32.41/drivers/atm/eni.c linux-2.6.32.41/drivers/atm/eni.c
24981--- linux-2.6.32.41/drivers/atm/eni.c 2011-03-27 14:31:47.000000000 -0400
24982+++ linux-2.6.32.41/drivers/atm/eni.c 2011-04-17 15:56:46.000000000 -0400
24983@@ -525,7 +525,7 @@ static int rx_aal0(struct atm_vcc *vcc)
24984 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
24985 vcc->dev->number);
24986 length = 0;
24987- atomic_inc(&vcc->stats->rx_err);
24988+ atomic_inc_unchecked(&vcc->stats->rx_err);
24989 }
24990 else {
24991 length = ATM_CELL_SIZE-1; /* no HEC */
24992@@ -580,7 +580,7 @@ static int rx_aal5(struct atm_vcc *vcc)
24993 size);
24994 }
24995 eff = length = 0;
24996- atomic_inc(&vcc->stats->rx_err);
24997+ atomic_inc_unchecked(&vcc->stats->rx_err);
24998 }
24999 else {
25000 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
25001@@ -597,7 +597,7 @@ static int rx_aal5(struct atm_vcc *vcc)
25002 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
25003 vcc->dev->number,vcc->vci,length,size << 2,descr);
25004 length = eff = 0;
25005- atomic_inc(&vcc->stats->rx_err);
25006+ atomic_inc_unchecked(&vcc->stats->rx_err);
25007 }
25008 }
25009 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
25010@@ -770,7 +770,7 @@ rx_dequeued++;
25011 vcc->push(vcc,skb);
25012 pushed++;
25013 }
25014- atomic_inc(&vcc->stats->rx);
25015+ atomic_inc_unchecked(&vcc->stats->rx);
25016 }
25017 wake_up(&eni_dev->rx_wait);
25018 }
25019@@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *d
25020 PCI_DMA_TODEVICE);
25021 if (vcc->pop) vcc->pop(vcc,skb);
25022 else dev_kfree_skb_irq(skb);
25023- atomic_inc(&vcc->stats->tx);
25024+ atomic_inc_unchecked(&vcc->stats->tx);
25025 wake_up(&eni_dev->tx_wait);
25026 dma_complete++;
25027 }
25028diff -urNp linux-2.6.32.41/drivers/atm/firestream.c linux-2.6.32.41/drivers/atm/firestream.c
25029--- linux-2.6.32.41/drivers/atm/firestream.c 2011-03-27 14:31:47.000000000 -0400
25030+++ linux-2.6.32.41/drivers/atm/firestream.c 2011-04-17 15:56:46.000000000 -0400
25031@@ -748,7 +748,7 @@ static void process_txdone_queue (struct
25032 }
25033 }
25034
25035- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
25036+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
25037
25038 fs_dprintk (FS_DEBUG_TXMEM, "i");
25039 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
25040@@ -815,7 +815,7 @@ static void process_incoming (struct fs_
25041 #endif
25042 skb_put (skb, qe->p1 & 0xffff);
25043 ATM_SKB(skb)->vcc = atm_vcc;
25044- atomic_inc(&atm_vcc->stats->rx);
25045+ atomic_inc_unchecked(&atm_vcc->stats->rx);
25046 __net_timestamp(skb);
25047 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
25048 atm_vcc->push (atm_vcc, skb);
25049@@ -836,12 +836,12 @@ static void process_incoming (struct fs_
25050 kfree (pe);
25051 }
25052 if (atm_vcc)
25053- atomic_inc(&atm_vcc->stats->rx_drop);
25054+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
25055 break;
25056 case 0x1f: /* Reassembly abort: no buffers. */
25057 /* Silently increment error counter. */
25058 if (atm_vcc)
25059- atomic_inc(&atm_vcc->stats->rx_drop);
25060+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
25061 break;
25062 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
25063 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
25064diff -urNp linux-2.6.32.41/drivers/atm/fore200e.c linux-2.6.32.41/drivers/atm/fore200e.c
25065--- linux-2.6.32.41/drivers/atm/fore200e.c 2011-03-27 14:31:47.000000000 -0400
25066+++ linux-2.6.32.41/drivers/atm/fore200e.c 2011-04-17 15:56:46.000000000 -0400
25067@@ -931,9 +931,9 @@ fore200e_tx_irq(struct fore200e* fore200
25068 #endif
25069 /* check error condition */
25070 if (*entry->status & STATUS_ERROR)
25071- atomic_inc(&vcc->stats->tx_err);
25072+ atomic_inc_unchecked(&vcc->stats->tx_err);
25073 else
25074- atomic_inc(&vcc->stats->tx);
25075+ atomic_inc_unchecked(&vcc->stats->tx);
25076 }
25077 }
25078
25079@@ -1082,7 +1082,7 @@ fore200e_push_rpd(struct fore200e* fore2
25080 if (skb == NULL) {
25081 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
25082
25083- atomic_inc(&vcc->stats->rx_drop);
25084+ atomic_inc_unchecked(&vcc->stats->rx_drop);
25085 return -ENOMEM;
25086 }
25087
25088@@ -1125,14 +1125,14 @@ fore200e_push_rpd(struct fore200e* fore2
25089
25090 dev_kfree_skb_any(skb);
25091
25092- atomic_inc(&vcc->stats->rx_drop);
25093+ atomic_inc_unchecked(&vcc->stats->rx_drop);
25094 return -ENOMEM;
25095 }
25096
25097 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
25098
25099 vcc->push(vcc, skb);
25100- atomic_inc(&vcc->stats->rx);
25101+ atomic_inc_unchecked(&vcc->stats->rx);
25102
25103 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
25104
25105@@ -1210,7 +1210,7 @@ fore200e_rx_irq(struct fore200e* fore200
25106 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
25107 fore200e->atm_dev->number,
25108 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
25109- atomic_inc(&vcc->stats->rx_err);
25110+ atomic_inc_unchecked(&vcc->stats->rx_err);
25111 }
25112 }
25113
25114@@ -1655,7 +1655,7 @@ fore200e_send(struct atm_vcc *vcc, struc
25115 goto retry_here;
25116 }
25117
25118- atomic_inc(&vcc->stats->tx_err);
25119+ atomic_inc_unchecked(&vcc->stats->tx_err);
25120
25121 fore200e->tx_sat++;
25122 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
25123diff -urNp linux-2.6.32.41/drivers/atm/he.c linux-2.6.32.41/drivers/atm/he.c
25124--- linux-2.6.32.41/drivers/atm/he.c 2011-03-27 14:31:47.000000000 -0400
25125+++ linux-2.6.32.41/drivers/atm/he.c 2011-04-17 15:56:46.000000000 -0400
25126@@ -1769,7 +1769,7 @@ he_service_rbrq(struct he_dev *he_dev, i
25127
25128 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
25129 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
25130- atomic_inc(&vcc->stats->rx_drop);
25131+ atomic_inc_unchecked(&vcc->stats->rx_drop);
25132 goto return_host_buffers;
25133 }
25134
25135@@ -1802,7 +1802,7 @@ he_service_rbrq(struct he_dev *he_dev, i
25136 RBRQ_LEN_ERR(he_dev->rbrq_head)
25137 ? "LEN_ERR" : "",
25138 vcc->vpi, vcc->vci);
25139- atomic_inc(&vcc->stats->rx_err);
25140+ atomic_inc_unchecked(&vcc->stats->rx_err);
25141 goto return_host_buffers;
25142 }
25143
25144@@ -1861,7 +1861,7 @@ he_service_rbrq(struct he_dev *he_dev, i
25145 vcc->push(vcc, skb);
25146 spin_lock(&he_dev->global_lock);
25147
25148- atomic_inc(&vcc->stats->rx);
25149+ atomic_inc_unchecked(&vcc->stats->rx);
25150
25151 return_host_buffers:
25152 ++pdus_assembled;
25153@@ -2206,7 +2206,7 @@ __enqueue_tpd(struct he_dev *he_dev, str
25154 tpd->vcc->pop(tpd->vcc, tpd->skb);
25155 else
25156 dev_kfree_skb_any(tpd->skb);
25157- atomic_inc(&tpd->vcc->stats->tx_err);
25158+ atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
25159 }
25160 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
25161 return;
25162@@ -2618,7 +2618,7 @@ he_send(struct atm_vcc *vcc, struct sk_b
25163 vcc->pop(vcc, skb);
25164 else
25165 dev_kfree_skb_any(skb);
25166- atomic_inc(&vcc->stats->tx_err);
25167+ atomic_inc_unchecked(&vcc->stats->tx_err);
25168 return -EINVAL;
25169 }
25170
25171@@ -2629,7 +2629,7 @@ he_send(struct atm_vcc *vcc, struct sk_b
25172 vcc->pop(vcc, skb);
25173 else
25174 dev_kfree_skb_any(skb);
25175- atomic_inc(&vcc->stats->tx_err);
25176+ atomic_inc_unchecked(&vcc->stats->tx_err);
25177 return -EINVAL;
25178 }
25179 #endif
25180@@ -2641,7 +2641,7 @@ he_send(struct atm_vcc *vcc, struct sk_b
25181 vcc->pop(vcc, skb);
25182 else
25183 dev_kfree_skb_any(skb);
25184- atomic_inc(&vcc->stats->tx_err);
25185+ atomic_inc_unchecked(&vcc->stats->tx_err);
25186 spin_unlock_irqrestore(&he_dev->global_lock, flags);
25187 return -ENOMEM;
25188 }
25189@@ -2683,7 +2683,7 @@ he_send(struct atm_vcc *vcc, struct sk_b
25190 vcc->pop(vcc, skb);
25191 else
25192 dev_kfree_skb_any(skb);
25193- atomic_inc(&vcc->stats->tx_err);
25194+ atomic_inc_unchecked(&vcc->stats->tx_err);
25195 spin_unlock_irqrestore(&he_dev->global_lock, flags);
25196 return -ENOMEM;
25197 }
25198@@ -2714,7 +2714,7 @@ he_send(struct atm_vcc *vcc, struct sk_b
25199 __enqueue_tpd(he_dev, tpd, cid);
25200 spin_unlock_irqrestore(&he_dev->global_lock, flags);
25201
25202- atomic_inc(&vcc->stats->tx);
25203+ atomic_inc_unchecked(&vcc->stats->tx);
25204
25205 return 0;
25206 }
25207diff -urNp linux-2.6.32.41/drivers/atm/horizon.c linux-2.6.32.41/drivers/atm/horizon.c
25208--- linux-2.6.32.41/drivers/atm/horizon.c 2011-03-27 14:31:47.000000000 -0400
25209+++ linux-2.6.32.41/drivers/atm/horizon.c 2011-04-17 15:56:46.000000000 -0400
25210@@ -1033,7 +1033,7 @@ static void rx_schedule (hrz_dev * dev,
25211 {
25212 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
25213 // VC layer stats
25214- atomic_inc(&vcc->stats->rx);
25215+ atomic_inc_unchecked(&vcc->stats->rx);
25216 __net_timestamp(skb);
25217 // end of our responsability
25218 vcc->push (vcc, skb);
25219@@ -1185,7 +1185,7 @@ static void tx_schedule (hrz_dev * const
25220 dev->tx_iovec = NULL;
25221
25222 // VC layer stats
25223- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
25224+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
25225
25226 // free the skb
25227 hrz_kfree_skb (skb);
25228diff -urNp linux-2.6.32.41/drivers/atm/idt77252.c linux-2.6.32.41/drivers/atm/idt77252.c
25229--- linux-2.6.32.41/drivers/atm/idt77252.c 2011-03-27 14:31:47.000000000 -0400
25230+++ linux-2.6.32.41/drivers/atm/idt77252.c 2011-04-17 15:56:46.000000000 -0400
25231@@ -810,7 +810,7 @@ drain_scq(struct idt77252_dev *card, str
25232 else
25233 dev_kfree_skb(skb);
25234
25235- atomic_inc(&vcc->stats->tx);
25236+ atomic_inc_unchecked(&vcc->stats->tx);
25237 }
25238
25239 atomic_dec(&scq->used);
25240@@ -1073,13 +1073,13 @@ dequeue_rx(struct idt77252_dev *card, st
25241 if ((sb = dev_alloc_skb(64)) == NULL) {
25242 printk("%s: Can't allocate buffers for aal0.\n",
25243 card->name);
25244- atomic_add(i, &vcc->stats->rx_drop);
25245+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
25246 break;
25247 }
25248 if (!atm_charge(vcc, sb->truesize)) {
25249 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
25250 card->name);
25251- atomic_add(i - 1, &vcc->stats->rx_drop);
25252+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
25253 dev_kfree_skb(sb);
25254 break;
25255 }
25256@@ -1096,7 +1096,7 @@ dequeue_rx(struct idt77252_dev *card, st
25257 ATM_SKB(sb)->vcc = vcc;
25258 __net_timestamp(sb);
25259 vcc->push(vcc, sb);
25260- atomic_inc(&vcc->stats->rx);
25261+ atomic_inc_unchecked(&vcc->stats->rx);
25262
25263 cell += ATM_CELL_PAYLOAD;
25264 }
25265@@ -1133,13 +1133,13 @@ dequeue_rx(struct idt77252_dev *card, st
25266 "(CDC: %08x)\n",
25267 card->name, len, rpp->len, readl(SAR_REG_CDC));
25268 recycle_rx_pool_skb(card, rpp);
25269- atomic_inc(&vcc->stats->rx_err);
25270+ atomic_inc_unchecked(&vcc->stats->rx_err);
25271 return;
25272 }
25273 if (stat & SAR_RSQE_CRC) {
25274 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
25275 recycle_rx_pool_skb(card, rpp);
25276- atomic_inc(&vcc->stats->rx_err);
25277+ atomic_inc_unchecked(&vcc->stats->rx_err);
25278 return;
25279 }
25280 if (skb_queue_len(&rpp->queue) > 1) {
25281@@ -1150,7 +1150,7 @@ dequeue_rx(struct idt77252_dev *card, st
25282 RXPRINTK("%s: Can't alloc RX skb.\n",
25283 card->name);
25284 recycle_rx_pool_skb(card, rpp);
25285- atomic_inc(&vcc->stats->rx_err);
25286+ atomic_inc_unchecked(&vcc->stats->rx_err);
25287 return;
25288 }
25289 if (!atm_charge(vcc, skb->truesize)) {
25290@@ -1169,7 +1169,7 @@ dequeue_rx(struct idt77252_dev *card, st
25291 __net_timestamp(skb);
25292
25293 vcc->push(vcc, skb);
25294- atomic_inc(&vcc->stats->rx);
25295+ atomic_inc_unchecked(&vcc->stats->rx);
25296
25297 return;
25298 }
25299@@ -1191,7 +1191,7 @@ dequeue_rx(struct idt77252_dev *card, st
25300 __net_timestamp(skb);
25301
25302 vcc->push(vcc, skb);
25303- atomic_inc(&vcc->stats->rx);
25304+ atomic_inc_unchecked(&vcc->stats->rx);
25305
25306 if (skb->truesize > SAR_FB_SIZE_3)
25307 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
25308@@ -1303,14 +1303,14 @@ idt77252_rx_raw(struct idt77252_dev *car
25309 if (vcc->qos.aal != ATM_AAL0) {
25310 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
25311 card->name, vpi, vci);
25312- atomic_inc(&vcc->stats->rx_drop);
25313+ atomic_inc_unchecked(&vcc->stats->rx_drop);
25314 goto drop;
25315 }
25316
25317 if ((sb = dev_alloc_skb(64)) == NULL) {
25318 printk("%s: Can't allocate buffers for AAL0.\n",
25319 card->name);
25320- atomic_inc(&vcc->stats->rx_err);
25321+ atomic_inc_unchecked(&vcc->stats->rx_err);
25322 goto drop;
25323 }
25324
25325@@ -1329,7 +1329,7 @@ idt77252_rx_raw(struct idt77252_dev *car
25326 ATM_SKB(sb)->vcc = vcc;
25327 __net_timestamp(sb);
25328 vcc->push(vcc, sb);
25329- atomic_inc(&vcc->stats->rx);
25330+ atomic_inc_unchecked(&vcc->stats->rx);
25331
25332 drop:
25333 skb_pull(queue, 64);
25334@@ -1954,13 +1954,13 @@ idt77252_send_skb(struct atm_vcc *vcc, s
25335
25336 if (vc == NULL) {
25337 printk("%s: NULL connection in send().\n", card->name);
25338- atomic_inc(&vcc->stats->tx_err);
25339+ atomic_inc_unchecked(&vcc->stats->tx_err);
25340 dev_kfree_skb(skb);
25341 return -EINVAL;
25342 }
25343 if (!test_bit(VCF_TX, &vc->flags)) {
25344 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
25345- atomic_inc(&vcc->stats->tx_err);
25346+ atomic_inc_unchecked(&vcc->stats->tx_err);
25347 dev_kfree_skb(skb);
25348 return -EINVAL;
25349 }
25350@@ -1972,14 +1972,14 @@ idt77252_send_skb(struct atm_vcc *vcc, s
25351 break;
25352 default:
25353 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
25354- atomic_inc(&vcc->stats->tx_err);
25355+ atomic_inc_unchecked(&vcc->stats->tx_err);
25356 dev_kfree_skb(skb);
25357 return -EINVAL;
25358 }
25359
25360 if (skb_shinfo(skb)->nr_frags != 0) {
25361 printk("%s: No scatter-gather yet.\n", card->name);
25362- atomic_inc(&vcc->stats->tx_err);
25363+ atomic_inc_unchecked(&vcc->stats->tx_err);
25364 dev_kfree_skb(skb);
25365 return -EINVAL;
25366 }
25367@@ -1987,7 +1987,7 @@ idt77252_send_skb(struct atm_vcc *vcc, s
25368
25369 err = queue_skb(card, vc, skb, oam);
25370 if (err) {
25371- atomic_inc(&vcc->stats->tx_err);
25372+ atomic_inc_unchecked(&vcc->stats->tx_err);
25373 dev_kfree_skb(skb);
25374 return err;
25375 }
25376@@ -2010,7 +2010,7 @@ idt77252_send_oam(struct atm_vcc *vcc, v
25377 skb = dev_alloc_skb(64);
25378 if (!skb) {
25379 printk("%s: Out of memory in send_oam().\n", card->name);
25380- atomic_inc(&vcc->stats->tx_err);
25381+ atomic_inc_unchecked(&vcc->stats->tx_err);
25382 return -ENOMEM;
25383 }
25384 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
25385diff -urNp linux-2.6.32.41/drivers/atm/iphase.c linux-2.6.32.41/drivers/atm/iphase.c
25386--- linux-2.6.32.41/drivers/atm/iphase.c 2011-03-27 14:31:47.000000000 -0400
25387+++ linux-2.6.32.41/drivers/atm/iphase.c 2011-04-17 15:56:46.000000000 -0400
25388@@ -1123,7 +1123,7 @@ static int rx_pkt(struct atm_dev *dev)
25389 status = (u_short) (buf_desc_ptr->desc_mode);
25390 if (status & (RX_CER | RX_PTE | RX_OFL))
25391 {
25392- atomic_inc(&vcc->stats->rx_err);
25393+ atomic_inc_unchecked(&vcc->stats->rx_err);
25394 IF_ERR(printk("IA: bad packet, dropping it");)
25395 if (status & RX_CER) {
25396 IF_ERR(printk(" cause: packet CRC error\n");)
25397@@ -1146,7 +1146,7 @@ static int rx_pkt(struct atm_dev *dev)
25398 len = dma_addr - buf_addr;
25399 if (len > iadev->rx_buf_sz) {
25400 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
25401- atomic_inc(&vcc->stats->rx_err);
25402+ atomic_inc_unchecked(&vcc->stats->rx_err);
25403 goto out_free_desc;
25404 }
25405
25406@@ -1296,7 +1296,7 @@ static void rx_dle_intr(struct atm_dev *
25407 ia_vcc = INPH_IA_VCC(vcc);
25408 if (ia_vcc == NULL)
25409 {
25410- atomic_inc(&vcc->stats->rx_err);
25411+ atomic_inc_unchecked(&vcc->stats->rx_err);
25412 dev_kfree_skb_any(skb);
25413 atm_return(vcc, atm_guess_pdu2truesize(len));
25414 goto INCR_DLE;
25415@@ -1308,7 +1308,7 @@ static void rx_dle_intr(struct atm_dev *
25416 if ((length > iadev->rx_buf_sz) || (length >
25417 (skb->len - sizeof(struct cpcs_trailer))))
25418 {
25419- atomic_inc(&vcc->stats->rx_err);
25420+ atomic_inc_unchecked(&vcc->stats->rx_err);
25421 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
25422 length, skb->len);)
25423 dev_kfree_skb_any(skb);
25424@@ -1324,7 +1324,7 @@ static void rx_dle_intr(struct atm_dev *
25425
25426 IF_RX(printk("rx_dle_intr: skb push");)
25427 vcc->push(vcc,skb);
25428- atomic_inc(&vcc->stats->rx);
25429+ atomic_inc_unchecked(&vcc->stats->rx);
25430 iadev->rx_pkt_cnt++;
25431 }
25432 INCR_DLE:
25433@@ -2806,15 +2806,15 @@ static int ia_ioctl(struct atm_dev *dev,
25434 {
25435 struct k_sonet_stats *stats;
25436 stats = &PRIV(_ia_dev[board])->sonet_stats;
25437- printk("section_bip: %d\n", atomic_read(&stats->section_bip));
25438- printk("line_bip : %d\n", atomic_read(&stats->line_bip));
25439- printk("path_bip : %d\n", atomic_read(&stats->path_bip));
25440- printk("line_febe : %d\n", atomic_read(&stats->line_febe));
25441- printk("path_febe : %d\n", atomic_read(&stats->path_febe));
25442- printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
25443- printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
25444- printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
25445- printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
25446+ printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
25447+ printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
25448+ printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
25449+ printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
25450+ printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
25451+ printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
25452+ printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
25453+ printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
25454+ printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
25455 }
25456 ia_cmds.status = 0;
25457 break;
25458@@ -2919,7 +2919,7 @@ static int ia_pkt_tx (struct atm_vcc *vc
25459 if ((desc == 0) || (desc > iadev->num_tx_desc))
25460 {
25461 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
25462- atomic_inc(&vcc->stats->tx);
25463+ atomic_inc_unchecked(&vcc->stats->tx);
25464 if (vcc->pop)
25465 vcc->pop(vcc, skb);
25466 else
25467@@ -3024,14 +3024,14 @@ static int ia_pkt_tx (struct atm_vcc *vc
25468 ATM_DESC(skb) = vcc->vci;
25469 skb_queue_tail(&iadev->tx_dma_q, skb);
25470
25471- atomic_inc(&vcc->stats->tx);
25472+ atomic_inc_unchecked(&vcc->stats->tx);
25473 iadev->tx_pkt_cnt++;
25474 /* Increment transaction counter */
25475 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
25476
25477 #if 0
25478 /* add flow control logic */
25479- if (atomic_read(&vcc->stats->tx) % 20 == 0) {
25480+ if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
25481 if (iavcc->vc_desc_cnt > 10) {
25482 vcc->tx_quota = vcc->tx_quota * 3 / 4;
25483 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
25484diff -urNp linux-2.6.32.41/drivers/atm/lanai.c linux-2.6.32.41/drivers/atm/lanai.c
25485--- linux-2.6.32.41/drivers/atm/lanai.c 2011-03-27 14:31:47.000000000 -0400
25486+++ linux-2.6.32.41/drivers/atm/lanai.c 2011-04-17 15:56:46.000000000 -0400
25487@@ -1305,7 +1305,7 @@ static void lanai_send_one_aal5(struct l
25488 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
25489 lanai_endtx(lanai, lvcc);
25490 lanai_free_skb(lvcc->tx.atmvcc, skb);
25491- atomic_inc(&lvcc->tx.atmvcc->stats->tx);
25492+ atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
25493 }
25494
25495 /* Try to fill the buffer - don't call unless there is backlog */
25496@@ -1428,7 +1428,7 @@ static void vcc_rx_aal5(struct lanai_vcc
25497 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
25498 __net_timestamp(skb);
25499 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
25500- atomic_inc(&lvcc->rx.atmvcc->stats->rx);
25501+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
25502 out:
25503 lvcc->rx.buf.ptr = end;
25504 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
25505@@ -1670,7 +1670,7 @@ static int handle_service(struct lanai_d
25506 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
25507 "vcc %d\n", lanai->number, (unsigned int) s, vci);
25508 lanai->stats.service_rxnotaal5++;
25509- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
25510+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
25511 return 0;
25512 }
25513 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
25514@@ -1682,7 +1682,7 @@ static int handle_service(struct lanai_d
25515 int bytes;
25516 read_unlock(&vcc_sklist_lock);
25517 DPRINTK("got trashed rx pdu on vci %d\n", vci);
25518- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
25519+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
25520 lvcc->stats.x.aal5.service_trash++;
25521 bytes = (SERVICE_GET_END(s) * 16) -
25522 (((unsigned long) lvcc->rx.buf.ptr) -
25523@@ -1694,7 +1694,7 @@ static int handle_service(struct lanai_d
25524 }
25525 if (s & SERVICE_STREAM) {
25526 read_unlock(&vcc_sklist_lock);
25527- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
25528+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
25529 lvcc->stats.x.aal5.service_stream++;
25530 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
25531 "PDU on VCI %d!\n", lanai->number, vci);
25532@@ -1702,7 +1702,7 @@ static int handle_service(struct lanai_d
25533 return 0;
25534 }
25535 DPRINTK("got rx crc error on vci %d\n", vci);
25536- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
25537+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
25538 lvcc->stats.x.aal5.service_rxcrc++;
25539 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
25540 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
25541diff -urNp linux-2.6.32.41/drivers/atm/nicstar.c linux-2.6.32.41/drivers/atm/nicstar.c
25542--- linux-2.6.32.41/drivers/atm/nicstar.c 2011-03-27 14:31:47.000000000 -0400
25543+++ linux-2.6.32.41/drivers/atm/nicstar.c 2011-04-17 15:56:46.000000000 -0400
25544@@ -1723,7 +1723,7 @@ static int ns_send(struct atm_vcc *vcc,
25545 if ((vc = (vc_map *) vcc->dev_data) == NULL)
25546 {
25547 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n", card->index);
25548- atomic_inc(&vcc->stats->tx_err);
25549+ atomic_inc_unchecked(&vcc->stats->tx_err);
25550 dev_kfree_skb_any(skb);
25551 return -EINVAL;
25552 }
25553@@ -1731,7 +1731,7 @@ static int ns_send(struct atm_vcc *vcc,
25554 if (!vc->tx)
25555 {
25556 printk("nicstar%d: Trying to transmit on a non-tx VC.\n", card->index);
25557- atomic_inc(&vcc->stats->tx_err);
25558+ atomic_inc_unchecked(&vcc->stats->tx_err);
25559 dev_kfree_skb_any(skb);
25560 return -EINVAL;
25561 }
25562@@ -1739,7 +1739,7 @@ static int ns_send(struct atm_vcc *vcc,
25563 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0)
25564 {
25565 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n", card->index);
25566- atomic_inc(&vcc->stats->tx_err);
25567+ atomic_inc_unchecked(&vcc->stats->tx_err);
25568 dev_kfree_skb_any(skb);
25569 return -EINVAL;
25570 }
25571@@ -1747,7 +1747,7 @@ static int ns_send(struct atm_vcc *vcc,
25572 if (skb_shinfo(skb)->nr_frags != 0)
25573 {
25574 printk("nicstar%d: No scatter-gather yet.\n", card->index);
25575- atomic_inc(&vcc->stats->tx_err);
25576+ atomic_inc_unchecked(&vcc->stats->tx_err);
25577 dev_kfree_skb_any(skb);
25578 return -EINVAL;
25579 }
25580@@ -1792,11 +1792,11 @@ static int ns_send(struct atm_vcc *vcc,
25581
25582 if (push_scqe(card, vc, scq, &scqe, skb) != 0)
25583 {
25584- atomic_inc(&vcc->stats->tx_err);
25585+ atomic_inc_unchecked(&vcc->stats->tx_err);
25586 dev_kfree_skb_any(skb);
25587 return -EIO;
25588 }
25589- atomic_inc(&vcc->stats->tx);
25590+ atomic_inc_unchecked(&vcc->stats->tx);
25591
25592 return 0;
25593 }
25594@@ -2111,14 +2111,14 @@ static void dequeue_rx(ns_dev *card, ns_
25595 {
25596 printk("nicstar%d: Can't allocate buffers for aal0.\n",
25597 card->index);
25598- atomic_add(i,&vcc->stats->rx_drop);
25599+ atomic_add_unchecked(i,&vcc->stats->rx_drop);
25600 break;
25601 }
25602 if (!atm_charge(vcc, sb->truesize))
25603 {
25604 RXPRINTK("nicstar%d: atm_charge() dropped aal0 packets.\n",
25605 card->index);
25606- atomic_add(i-1,&vcc->stats->rx_drop); /* already increased by 1 */
25607+ atomic_add_unchecked(i-1,&vcc->stats->rx_drop); /* already increased by 1 */
25608 dev_kfree_skb_any(sb);
25609 break;
25610 }
25611@@ -2133,7 +2133,7 @@ static void dequeue_rx(ns_dev *card, ns_
25612 ATM_SKB(sb)->vcc = vcc;
25613 __net_timestamp(sb);
25614 vcc->push(vcc, sb);
25615- atomic_inc(&vcc->stats->rx);
25616+ atomic_inc_unchecked(&vcc->stats->rx);
25617 cell += ATM_CELL_PAYLOAD;
25618 }
25619
25620@@ -2152,7 +2152,7 @@ static void dequeue_rx(ns_dev *card, ns_
25621 if (iovb == NULL)
25622 {
25623 printk("nicstar%d: Out of iovec buffers.\n", card->index);
25624- atomic_inc(&vcc->stats->rx_drop);
25625+ atomic_inc_unchecked(&vcc->stats->rx_drop);
25626 recycle_rx_buf(card, skb);
25627 return;
25628 }
25629@@ -2182,7 +2182,7 @@ static void dequeue_rx(ns_dev *card, ns_
25630 else if (NS_SKB(iovb)->iovcnt >= NS_MAX_IOVECS)
25631 {
25632 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
25633- atomic_inc(&vcc->stats->rx_err);
25634+ atomic_inc_unchecked(&vcc->stats->rx_err);
25635 recycle_iovec_rx_bufs(card, (struct iovec *) iovb->data, NS_MAX_IOVECS);
25636 NS_SKB(iovb)->iovcnt = 0;
25637 iovb->len = 0;
25638@@ -2202,7 +2202,7 @@ static void dequeue_rx(ns_dev *card, ns_
25639 printk("nicstar%d: Expected a small buffer, and this is not one.\n",
25640 card->index);
25641 which_list(card, skb);
25642- atomic_inc(&vcc->stats->rx_err);
25643+ atomic_inc_unchecked(&vcc->stats->rx_err);
25644 recycle_rx_buf(card, skb);
25645 vc->rx_iov = NULL;
25646 recycle_iov_buf(card, iovb);
25647@@ -2216,7 +2216,7 @@ static void dequeue_rx(ns_dev *card, ns_
25648 printk("nicstar%d: Expected a large buffer, and this is not one.\n",
25649 card->index);
25650 which_list(card, skb);
25651- atomic_inc(&vcc->stats->rx_err);
25652+ atomic_inc_unchecked(&vcc->stats->rx_err);
25653 recycle_iovec_rx_bufs(card, (struct iovec *) iovb->data,
25654 NS_SKB(iovb)->iovcnt);
25655 vc->rx_iov = NULL;
25656@@ -2240,7 +2240,7 @@ static void dequeue_rx(ns_dev *card, ns_
25657 printk(" - PDU size mismatch.\n");
25658 else
25659 printk(".\n");
25660- atomic_inc(&vcc->stats->rx_err);
25661+ atomic_inc_unchecked(&vcc->stats->rx_err);
25662 recycle_iovec_rx_bufs(card, (struct iovec *) iovb->data,
25663 NS_SKB(iovb)->iovcnt);
25664 vc->rx_iov = NULL;
25665@@ -2256,7 +2256,7 @@ static void dequeue_rx(ns_dev *card, ns_
25666 if (!atm_charge(vcc, skb->truesize))
25667 {
25668 push_rxbufs(card, skb);
25669- atomic_inc(&vcc->stats->rx_drop);
25670+ atomic_inc_unchecked(&vcc->stats->rx_drop);
25671 }
25672 else
25673 {
25674@@ -2268,7 +2268,7 @@ static void dequeue_rx(ns_dev *card, ns_
25675 ATM_SKB(skb)->vcc = vcc;
25676 __net_timestamp(skb);
25677 vcc->push(vcc, skb);
25678- atomic_inc(&vcc->stats->rx);
25679+ atomic_inc_unchecked(&vcc->stats->rx);
25680 }
25681 }
25682 else if (NS_SKB(iovb)->iovcnt == 2) /* One small plus one large buffer */
25683@@ -2283,7 +2283,7 @@ static void dequeue_rx(ns_dev *card, ns_
25684 if (!atm_charge(vcc, sb->truesize))
25685 {
25686 push_rxbufs(card, sb);
25687- atomic_inc(&vcc->stats->rx_drop);
25688+ atomic_inc_unchecked(&vcc->stats->rx_drop);
25689 }
25690 else
25691 {
25692@@ -2295,7 +2295,7 @@ static void dequeue_rx(ns_dev *card, ns_
25693 ATM_SKB(sb)->vcc = vcc;
25694 __net_timestamp(sb);
25695 vcc->push(vcc, sb);
25696- atomic_inc(&vcc->stats->rx);
25697+ atomic_inc_unchecked(&vcc->stats->rx);
25698 }
25699
25700 push_rxbufs(card, skb);
25701@@ -2306,7 +2306,7 @@ static void dequeue_rx(ns_dev *card, ns_
25702 if (!atm_charge(vcc, skb->truesize))
25703 {
25704 push_rxbufs(card, skb);
25705- atomic_inc(&vcc->stats->rx_drop);
25706+ atomic_inc_unchecked(&vcc->stats->rx_drop);
25707 }
25708 else
25709 {
25710@@ -2320,7 +2320,7 @@ static void dequeue_rx(ns_dev *card, ns_
25711 ATM_SKB(skb)->vcc = vcc;
25712 __net_timestamp(skb);
25713 vcc->push(vcc, skb);
25714- atomic_inc(&vcc->stats->rx);
25715+ atomic_inc_unchecked(&vcc->stats->rx);
25716 }
25717
25718 push_rxbufs(card, sb);
25719@@ -2342,7 +2342,7 @@ static void dequeue_rx(ns_dev *card, ns_
25720 if (hb == NULL)
25721 {
25722 printk("nicstar%d: Out of huge buffers.\n", card->index);
25723- atomic_inc(&vcc->stats->rx_drop);
25724+ atomic_inc_unchecked(&vcc->stats->rx_drop);
25725 recycle_iovec_rx_bufs(card, (struct iovec *) iovb->data,
25726 NS_SKB(iovb)->iovcnt);
25727 vc->rx_iov = NULL;
25728@@ -2393,7 +2393,7 @@ static void dequeue_rx(ns_dev *card, ns_
25729 }
25730 else
25731 dev_kfree_skb_any(hb);
25732- atomic_inc(&vcc->stats->rx_drop);
25733+ atomic_inc_unchecked(&vcc->stats->rx_drop);
25734 }
25735 else
25736 {
25737@@ -2427,7 +2427,7 @@ static void dequeue_rx(ns_dev *card, ns_
25738 #endif /* NS_USE_DESTRUCTORS */
25739 __net_timestamp(hb);
25740 vcc->push(vcc, hb);
25741- atomic_inc(&vcc->stats->rx);
25742+ atomic_inc_unchecked(&vcc->stats->rx);
25743 }
25744 }
25745
25746diff -urNp linux-2.6.32.41/drivers/atm/solos-pci.c linux-2.6.32.41/drivers/atm/solos-pci.c
25747--- linux-2.6.32.41/drivers/atm/solos-pci.c 2011-04-17 17:00:52.000000000 -0400
25748+++ linux-2.6.32.41/drivers/atm/solos-pci.c 2011-05-16 21:46:57.000000000 -0400
25749@@ -708,7 +708,7 @@ void solos_bh(unsigned long card_arg)
25750 }
25751 atm_charge(vcc, skb->truesize);
25752 vcc->push(vcc, skb);
25753- atomic_inc(&vcc->stats->rx);
25754+ atomic_inc_unchecked(&vcc->stats->rx);
25755 break;
25756
25757 case PKT_STATUS:
25758@@ -914,6 +914,8 @@ static int print_buffer(struct sk_buff *
25759 char msg[500];
25760 char item[10];
25761
25762+ pax_track_stack();
25763+
25764 len = buf->len;
25765 for (i = 0; i < len; i++){
25766 if(i % 8 == 0)
25767@@ -1023,7 +1025,7 @@ static uint32_t fpga_tx(struct solos_car
25768 vcc = SKB_CB(oldskb)->vcc;
25769
25770 if (vcc) {
25771- atomic_inc(&vcc->stats->tx);
25772+ atomic_inc_unchecked(&vcc->stats->tx);
25773 solos_pop(vcc, oldskb);
25774 } else
25775 dev_kfree_skb_irq(oldskb);
25776diff -urNp linux-2.6.32.41/drivers/atm/suni.c linux-2.6.32.41/drivers/atm/suni.c
25777--- linux-2.6.32.41/drivers/atm/suni.c 2011-03-27 14:31:47.000000000 -0400
25778+++ linux-2.6.32.41/drivers/atm/suni.c 2011-04-17 15:56:46.000000000 -0400
25779@@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
25780
25781
25782 #define ADD_LIMITED(s,v) \
25783- atomic_add((v),&stats->s); \
25784- if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
25785+ atomic_add_unchecked((v),&stats->s); \
25786+ if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
25787
25788
25789 static void suni_hz(unsigned long from_timer)
25790diff -urNp linux-2.6.32.41/drivers/atm/uPD98402.c linux-2.6.32.41/drivers/atm/uPD98402.c
25791--- linux-2.6.32.41/drivers/atm/uPD98402.c 2011-03-27 14:31:47.000000000 -0400
25792+++ linux-2.6.32.41/drivers/atm/uPD98402.c 2011-04-17 15:56:46.000000000 -0400
25793@@ -41,7 +41,7 @@ static int fetch_stats(struct atm_dev *d
25794 struct sonet_stats tmp;
25795 int error = 0;
25796
25797- atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
25798+ atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
25799 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
25800 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
25801 if (zero && !error) {
25802@@ -160,9 +160,9 @@ static int uPD98402_ioctl(struct atm_dev
25803
25804
25805 #define ADD_LIMITED(s,v) \
25806- { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
25807- if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
25808- atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
25809+ { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
25810+ if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
25811+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
25812
25813
25814 static void stat_event(struct atm_dev *dev)
25815@@ -193,7 +193,7 @@ static void uPD98402_int(struct atm_dev
25816 if (reason & uPD98402_INT_PFM) stat_event(dev);
25817 if (reason & uPD98402_INT_PCO) {
25818 (void) GET(PCOCR); /* clear interrupt cause */
25819- atomic_add(GET(HECCT),
25820+ atomic_add_unchecked(GET(HECCT),
25821 &PRIV(dev)->sonet_stats.uncorr_hcs);
25822 }
25823 if ((reason & uPD98402_INT_RFO) &&
25824@@ -221,9 +221,9 @@ static int uPD98402_start(struct atm_dev
25825 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
25826 uPD98402_INT_LOS),PIMR); /* enable them */
25827 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
25828- atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
25829- atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
25830- atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
25831+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
25832+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
25833+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
25834 return 0;
25835 }
25836
25837diff -urNp linux-2.6.32.41/drivers/atm/zatm.c linux-2.6.32.41/drivers/atm/zatm.c
25838--- linux-2.6.32.41/drivers/atm/zatm.c 2011-03-27 14:31:47.000000000 -0400
25839+++ linux-2.6.32.41/drivers/atm/zatm.c 2011-04-17 15:56:46.000000000 -0400
25840@@ -458,7 +458,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy
25841 }
25842 if (!size) {
25843 dev_kfree_skb_irq(skb);
25844- if (vcc) atomic_inc(&vcc->stats->rx_err);
25845+ if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
25846 continue;
25847 }
25848 if (!atm_charge(vcc,skb->truesize)) {
25849@@ -468,7 +468,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy
25850 skb->len = size;
25851 ATM_SKB(skb)->vcc = vcc;
25852 vcc->push(vcc,skb);
25853- atomic_inc(&vcc->stats->rx);
25854+ atomic_inc_unchecked(&vcc->stats->rx);
25855 }
25856 zout(pos & 0xffff,MTA(mbx));
25857 #if 0 /* probably a stupid idea */
25858@@ -732,7 +732,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD
25859 skb_queue_head(&zatm_vcc->backlog,skb);
25860 break;
25861 }
25862- atomic_inc(&vcc->stats->tx);
25863+ atomic_inc_unchecked(&vcc->stats->tx);
25864 wake_up(&zatm_vcc->tx_wait);
25865 }
25866
25867diff -urNp linux-2.6.32.41/drivers/base/bus.c linux-2.6.32.41/drivers/base/bus.c
25868--- linux-2.6.32.41/drivers/base/bus.c 2011-03-27 14:31:47.000000000 -0400
25869+++ linux-2.6.32.41/drivers/base/bus.c 2011-04-17 15:56:46.000000000 -0400
25870@@ -70,7 +70,7 @@ static ssize_t drv_attr_store(struct kob
25871 return ret;
25872 }
25873
25874-static struct sysfs_ops driver_sysfs_ops = {
25875+static const struct sysfs_ops driver_sysfs_ops = {
25876 .show = drv_attr_show,
25877 .store = drv_attr_store,
25878 };
25879@@ -115,7 +115,7 @@ static ssize_t bus_attr_store(struct kob
25880 return ret;
25881 }
25882
25883-static struct sysfs_ops bus_sysfs_ops = {
25884+static const struct sysfs_ops bus_sysfs_ops = {
25885 .show = bus_attr_show,
25886 .store = bus_attr_store,
25887 };
25888@@ -154,7 +154,7 @@ static int bus_uevent_filter(struct kset
25889 return 0;
25890 }
25891
25892-static struct kset_uevent_ops bus_uevent_ops = {
25893+static const struct kset_uevent_ops bus_uevent_ops = {
25894 .filter = bus_uevent_filter,
25895 };
25896
25897diff -urNp linux-2.6.32.41/drivers/base/class.c linux-2.6.32.41/drivers/base/class.c
25898--- linux-2.6.32.41/drivers/base/class.c 2011-03-27 14:31:47.000000000 -0400
25899+++ linux-2.6.32.41/drivers/base/class.c 2011-04-17 15:56:46.000000000 -0400
25900@@ -63,7 +63,7 @@ static void class_release(struct kobject
25901 kfree(cp);
25902 }
25903
25904-static struct sysfs_ops class_sysfs_ops = {
25905+static const struct sysfs_ops class_sysfs_ops = {
25906 .show = class_attr_show,
25907 .store = class_attr_store,
25908 };
25909diff -urNp linux-2.6.32.41/drivers/base/core.c linux-2.6.32.41/drivers/base/core.c
25910--- linux-2.6.32.41/drivers/base/core.c 2011-03-27 14:31:47.000000000 -0400
25911+++ linux-2.6.32.41/drivers/base/core.c 2011-04-17 15:56:46.000000000 -0400
25912@@ -100,7 +100,7 @@ static ssize_t dev_attr_store(struct kob
25913 return ret;
25914 }
25915
25916-static struct sysfs_ops dev_sysfs_ops = {
25917+static const struct sysfs_ops dev_sysfs_ops = {
25918 .show = dev_attr_show,
25919 .store = dev_attr_store,
25920 };
25921@@ -252,7 +252,7 @@ static int dev_uevent(struct kset *kset,
25922 return retval;
25923 }
25924
25925-static struct kset_uevent_ops device_uevent_ops = {
25926+static const struct kset_uevent_ops device_uevent_ops = {
25927 .filter = dev_uevent_filter,
25928 .name = dev_uevent_name,
25929 .uevent = dev_uevent,
25930diff -urNp linux-2.6.32.41/drivers/base/memory.c linux-2.6.32.41/drivers/base/memory.c
25931--- linux-2.6.32.41/drivers/base/memory.c 2011-03-27 14:31:47.000000000 -0400
25932+++ linux-2.6.32.41/drivers/base/memory.c 2011-04-17 15:56:46.000000000 -0400
25933@@ -44,7 +44,7 @@ static int memory_uevent(struct kset *ks
25934 return retval;
25935 }
25936
25937-static struct kset_uevent_ops memory_uevent_ops = {
25938+static const struct kset_uevent_ops memory_uevent_ops = {
25939 .name = memory_uevent_name,
25940 .uevent = memory_uevent,
25941 };
25942diff -urNp linux-2.6.32.41/drivers/base/sys.c linux-2.6.32.41/drivers/base/sys.c
25943--- linux-2.6.32.41/drivers/base/sys.c 2011-03-27 14:31:47.000000000 -0400
25944+++ linux-2.6.32.41/drivers/base/sys.c 2011-04-17 15:56:46.000000000 -0400
25945@@ -54,7 +54,7 @@ sysdev_store(struct kobject *kobj, struc
25946 return -EIO;
25947 }
25948
25949-static struct sysfs_ops sysfs_ops = {
25950+static const struct sysfs_ops sysfs_ops = {
25951 .show = sysdev_show,
25952 .store = sysdev_store,
25953 };
25954@@ -104,7 +104,7 @@ static ssize_t sysdev_class_store(struct
25955 return -EIO;
25956 }
25957
25958-static struct sysfs_ops sysfs_class_ops = {
25959+static const struct sysfs_ops sysfs_class_ops = {
25960 .show = sysdev_class_show,
25961 .store = sysdev_class_store,
25962 };
25963diff -urNp linux-2.6.32.41/drivers/block/cciss.c linux-2.6.32.41/drivers/block/cciss.c
25964--- linux-2.6.32.41/drivers/block/cciss.c 2011-03-27 14:31:47.000000000 -0400
25965+++ linux-2.6.32.41/drivers/block/cciss.c 2011-04-17 15:56:46.000000000 -0400
25966@@ -1011,6 +1011,8 @@ static int cciss_ioctl32_passthru(struct
25967 int err;
25968 u32 cp;
25969
25970+ memset(&arg64, 0, sizeof(arg64));
25971+
25972 err = 0;
25973 err |=
25974 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
25975diff -urNp linux-2.6.32.41/drivers/block/cpqarray.c linux-2.6.32.41/drivers/block/cpqarray.c
25976--- linux-2.6.32.41/drivers/block/cpqarray.c 2011-03-27 14:31:47.000000000 -0400
25977+++ linux-2.6.32.41/drivers/block/cpqarray.c 2011-05-16 21:46:57.000000000 -0400
25978@@ -896,6 +896,8 @@ static void do_ida_request(struct reques
25979 struct scatterlist tmp_sg[SG_MAX];
25980 int i, dir, seg;
25981
25982+ pax_track_stack();
25983+
25984 if (blk_queue_plugged(q))
25985 goto startio;
25986
25987diff -urNp linux-2.6.32.41/drivers/block/DAC960.c linux-2.6.32.41/drivers/block/DAC960.c
25988--- linux-2.6.32.41/drivers/block/DAC960.c 2011-03-27 14:31:47.000000000 -0400
25989+++ linux-2.6.32.41/drivers/block/DAC960.c 2011-05-16 21:46:57.000000000 -0400
25990@@ -1973,6 +1973,8 @@ static bool DAC960_V1_ReadDeviceConfigur
25991 unsigned long flags;
25992 int Channel, TargetID;
25993
25994+ pax_track_stack();
25995+
25996 if (!init_dma_loaf(Controller->PCIDevice, &local_dma,
25997 DAC960_V1_MaxChannels*(sizeof(DAC960_V1_DCDB_T) +
25998 sizeof(DAC960_SCSI_Inquiry_T) +
25999diff -urNp linux-2.6.32.41/drivers/block/nbd.c linux-2.6.32.41/drivers/block/nbd.c
26000--- linux-2.6.32.41/drivers/block/nbd.c 2011-03-27 14:31:47.000000000 -0400
26001+++ linux-2.6.32.41/drivers/block/nbd.c 2011-05-16 21:46:57.000000000 -0400
26002@@ -155,6 +155,8 @@ static int sock_xmit(struct nbd_device *
26003 struct kvec iov;
26004 sigset_t blocked, oldset;
26005
26006+ pax_track_stack();
26007+
26008 if (unlikely(!sock)) {
26009 printk(KERN_ERR "%s: Attempted %s on closed socket in sock_xmit\n",
26010 lo->disk->disk_name, (send ? "send" : "recv"));
26011@@ -569,6 +571,8 @@ static void do_nbd_request(struct reques
26012 static int __nbd_ioctl(struct block_device *bdev, struct nbd_device *lo,
26013 unsigned int cmd, unsigned long arg)
26014 {
26015+ pax_track_stack();
26016+
26017 switch (cmd) {
26018 case NBD_DISCONNECT: {
26019 struct request sreq;
26020diff -urNp linux-2.6.32.41/drivers/block/pktcdvd.c linux-2.6.32.41/drivers/block/pktcdvd.c
26021--- linux-2.6.32.41/drivers/block/pktcdvd.c 2011-03-27 14:31:47.000000000 -0400
26022+++ linux-2.6.32.41/drivers/block/pktcdvd.c 2011-04-17 15:56:46.000000000 -0400
26023@@ -284,7 +284,7 @@ static ssize_t kobj_pkt_store(struct kob
26024 return len;
26025 }
26026
26027-static struct sysfs_ops kobj_pkt_ops = {
26028+static const struct sysfs_ops kobj_pkt_ops = {
26029 .show = kobj_pkt_show,
26030 .store = kobj_pkt_store
26031 };
26032diff -urNp linux-2.6.32.41/drivers/char/agp/frontend.c linux-2.6.32.41/drivers/char/agp/frontend.c
26033--- linux-2.6.32.41/drivers/char/agp/frontend.c 2011-03-27 14:31:47.000000000 -0400
26034+++ linux-2.6.32.41/drivers/char/agp/frontend.c 2011-04-17 15:56:46.000000000 -0400
26035@@ -824,7 +824,7 @@ static int agpioc_reserve_wrap(struct ag
26036 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
26037 return -EFAULT;
26038
26039- if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
26040+ if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
26041 return -EFAULT;
26042
26043 client = agp_find_client_by_pid(reserve.pid);
26044diff -urNp linux-2.6.32.41/drivers/char/briq_panel.c linux-2.6.32.41/drivers/char/briq_panel.c
26045--- linux-2.6.32.41/drivers/char/briq_panel.c 2011-03-27 14:31:47.000000000 -0400
26046+++ linux-2.6.32.41/drivers/char/briq_panel.c 2011-04-18 19:48:57.000000000 -0400
26047@@ -10,6 +10,7 @@
26048 #include <linux/types.h>
26049 #include <linux/errno.h>
26050 #include <linux/tty.h>
26051+#include <linux/mutex.h>
26052 #include <linux/timer.h>
26053 #include <linux/kernel.h>
26054 #include <linux/wait.h>
26055@@ -36,6 +37,7 @@ static int vfd_is_open;
26056 static unsigned char vfd[40];
26057 static int vfd_cursor;
26058 static unsigned char ledpb, led;
26059+static DEFINE_MUTEX(vfd_mutex);
26060
26061 static void update_vfd(void)
26062 {
26063@@ -142,12 +144,15 @@ static ssize_t briq_panel_write(struct f
26064 if (!vfd_is_open)
26065 return -EBUSY;
26066
26067+ mutex_lock(&vfd_mutex);
26068 for (;;) {
26069 char c;
26070 if (!indx)
26071 break;
26072- if (get_user(c, buf))
26073+ if (get_user(c, buf)) {
26074+ mutex_unlock(&vfd_mutex);
26075 return -EFAULT;
26076+ }
26077 if (esc) {
26078 set_led(c);
26079 esc = 0;
26080@@ -177,6 +182,7 @@ static ssize_t briq_panel_write(struct f
26081 buf++;
26082 }
26083 update_vfd();
26084+ mutex_unlock(&vfd_mutex);
26085
26086 return len;
26087 }
26088diff -urNp linux-2.6.32.41/drivers/char/genrtc.c linux-2.6.32.41/drivers/char/genrtc.c
26089--- linux-2.6.32.41/drivers/char/genrtc.c 2011-03-27 14:31:47.000000000 -0400
26090+++ linux-2.6.32.41/drivers/char/genrtc.c 2011-04-18 19:45:42.000000000 -0400
26091@@ -272,6 +272,7 @@ static int gen_rtc_ioctl(struct inode *i
26092 switch (cmd) {
26093
26094 case RTC_PLL_GET:
26095+ memset(&pll, 0, sizeof(pll));
26096 if (get_rtc_pll(&pll))
26097 return -EINVAL;
26098 else
26099diff -urNp linux-2.6.32.41/drivers/char/hpet.c linux-2.6.32.41/drivers/char/hpet.c
26100--- linux-2.6.32.41/drivers/char/hpet.c 2011-03-27 14:31:47.000000000 -0400
26101+++ linux-2.6.32.41/drivers/char/hpet.c 2011-04-23 12:56:11.000000000 -0400
26102@@ -430,7 +430,7 @@ static int hpet_release(struct inode *in
26103 return 0;
26104 }
26105
26106-static int hpet_ioctl_common(struct hpet_dev *, int, unsigned long, int);
26107+static int hpet_ioctl_common(struct hpet_dev *, unsigned int, unsigned long, int);
26108
26109 static int
26110 hpet_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
26111@@ -565,7 +565,7 @@ static inline unsigned long hpet_time_di
26112 }
26113
26114 static int
26115-hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg, int kernel)
26116+hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg, int kernel)
26117 {
26118 struct hpet_timer __iomem *timer;
26119 struct hpet __iomem *hpet;
26120@@ -608,11 +608,11 @@ hpet_ioctl_common(struct hpet_dev *devp,
26121 {
26122 struct hpet_info info;
26123
26124+ memset(&info, 0, sizeof(info));
26125+
26126 if (devp->hd_ireqfreq)
26127 info.hi_ireqfreq =
26128 hpet_time_div(hpetp, devp->hd_ireqfreq);
26129- else
26130- info.hi_ireqfreq = 0;
26131 info.hi_flags =
26132 readq(&timer->hpet_config) & Tn_PER_INT_CAP_MASK;
26133 info.hi_hpet = hpetp->hp_which;
26134diff -urNp linux-2.6.32.41/drivers/char/hvc_beat.c linux-2.6.32.41/drivers/char/hvc_beat.c
26135--- linux-2.6.32.41/drivers/char/hvc_beat.c 2011-03-27 14:31:47.000000000 -0400
26136+++ linux-2.6.32.41/drivers/char/hvc_beat.c 2011-04-17 15:56:46.000000000 -0400
26137@@ -84,7 +84,7 @@ static int hvc_beat_put_chars(uint32_t v
26138 return cnt;
26139 }
26140
26141-static struct hv_ops hvc_beat_get_put_ops = {
26142+static const struct hv_ops hvc_beat_get_put_ops = {
26143 .get_chars = hvc_beat_get_chars,
26144 .put_chars = hvc_beat_put_chars,
26145 };
26146diff -urNp linux-2.6.32.41/drivers/char/hvc_console.c linux-2.6.32.41/drivers/char/hvc_console.c
26147--- linux-2.6.32.41/drivers/char/hvc_console.c 2011-03-27 14:31:47.000000000 -0400
26148+++ linux-2.6.32.41/drivers/char/hvc_console.c 2011-04-17 15:56:46.000000000 -0400
26149@@ -125,7 +125,7 @@ static struct hvc_struct *hvc_get_by_ind
26150 * console interfaces but can still be used as a tty device. This has to be
26151 * static because kmalloc will not work during early console init.
26152 */
26153-static struct hv_ops *cons_ops[MAX_NR_HVC_CONSOLES];
26154+static const struct hv_ops *cons_ops[MAX_NR_HVC_CONSOLES];
26155 static uint32_t vtermnos[MAX_NR_HVC_CONSOLES] =
26156 {[0 ... MAX_NR_HVC_CONSOLES - 1] = -1};
26157
26158@@ -247,7 +247,7 @@ static void destroy_hvc_struct(struct kr
26159 * vty adapters do NOT get an hvc_instantiate() callback since they
26160 * appear after early console init.
26161 */
26162-int hvc_instantiate(uint32_t vtermno, int index, struct hv_ops *ops)
26163+int hvc_instantiate(uint32_t vtermno, int index, const struct hv_ops *ops)
26164 {
26165 struct hvc_struct *hp;
26166
26167@@ -756,7 +756,7 @@ static const struct tty_operations hvc_o
26168 };
26169
26170 struct hvc_struct __devinit *hvc_alloc(uint32_t vtermno, int data,
26171- struct hv_ops *ops, int outbuf_size)
26172+ const struct hv_ops *ops, int outbuf_size)
26173 {
26174 struct hvc_struct *hp;
26175 int i;
26176diff -urNp linux-2.6.32.41/drivers/char/hvc_console.h linux-2.6.32.41/drivers/char/hvc_console.h
26177--- linux-2.6.32.41/drivers/char/hvc_console.h 2011-03-27 14:31:47.000000000 -0400
26178+++ linux-2.6.32.41/drivers/char/hvc_console.h 2011-04-17 15:56:46.000000000 -0400
26179@@ -55,7 +55,7 @@ struct hvc_struct {
26180 int outbuf_size;
26181 int n_outbuf;
26182 uint32_t vtermno;
26183- struct hv_ops *ops;
26184+ const struct hv_ops *ops;
26185 int irq_requested;
26186 int data;
26187 struct winsize ws;
26188@@ -76,11 +76,11 @@ struct hv_ops {
26189 };
26190
26191 /* Register a vterm and a slot index for use as a console (console_init) */
26192-extern int hvc_instantiate(uint32_t vtermno, int index, struct hv_ops *ops);
26193+extern int hvc_instantiate(uint32_t vtermno, int index, const struct hv_ops *ops);
26194
26195 /* register a vterm for hvc tty operation (module_init or hotplug add) */
26196 extern struct hvc_struct * __devinit hvc_alloc(uint32_t vtermno, int data,
26197- struct hv_ops *ops, int outbuf_size);
26198+ const struct hv_ops *ops, int outbuf_size);
26199 /* remove a vterm from hvc tty operation (module_exit or hotplug remove) */
26200 extern int hvc_remove(struct hvc_struct *hp);
26201
26202diff -urNp linux-2.6.32.41/drivers/char/hvc_iseries.c linux-2.6.32.41/drivers/char/hvc_iseries.c
26203--- linux-2.6.32.41/drivers/char/hvc_iseries.c 2011-03-27 14:31:47.000000000 -0400
26204+++ linux-2.6.32.41/drivers/char/hvc_iseries.c 2011-04-17 15:56:46.000000000 -0400
26205@@ -197,7 +197,7 @@ done:
26206 return sent;
26207 }
26208
26209-static struct hv_ops hvc_get_put_ops = {
26210+static const struct hv_ops hvc_get_put_ops = {
26211 .get_chars = get_chars,
26212 .put_chars = put_chars,
26213 .notifier_add = notifier_add_irq,
26214diff -urNp linux-2.6.32.41/drivers/char/hvc_iucv.c linux-2.6.32.41/drivers/char/hvc_iucv.c
26215--- linux-2.6.32.41/drivers/char/hvc_iucv.c 2011-03-27 14:31:47.000000000 -0400
26216+++ linux-2.6.32.41/drivers/char/hvc_iucv.c 2011-04-17 15:56:46.000000000 -0400
26217@@ -924,7 +924,7 @@ static int hvc_iucv_pm_restore_thaw(stru
26218
26219
26220 /* HVC operations */
26221-static struct hv_ops hvc_iucv_ops = {
26222+static const struct hv_ops hvc_iucv_ops = {
26223 .get_chars = hvc_iucv_get_chars,
26224 .put_chars = hvc_iucv_put_chars,
26225 .notifier_add = hvc_iucv_notifier_add,
26226diff -urNp linux-2.6.32.41/drivers/char/hvc_rtas.c linux-2.6.32.41/drivers/char/hvc_rtas.c
26227--- linux-2.6.32.41/drivers/char/hvc_rtas.c 2011-03-27 14:31:47.000000000 -0400
26228+++ linux-2.6.32.41/drivers/char/hvc_rtas.c 2011-04-17 15:56:46.000000000 -0400
26229@@ -71,7 +71,7 @@ static int hvc_rtas_read_console(uint32_
26230 return i;
26231 }
26232
26233-static struct hv_ops hvc_rtas_get_put_ops = {
26234+static const struct hv_ops hvc_rtas_get_put_ops = {
26235 .get_chars = hvc_rtas_read_console,
26236 .put_chars = hvc_rtas_write_console,
26237 };
26238diff -urNp linux-2.6.32.41/drivers/char/hvcs.c linux-2.6.32.41/drivers/char/hvcs.c
26239--- linux-2.6.32.41/drivers/char/hvcs.c 2011-03-27 14:31:47.000000000 -0400
26240+++ linux-2.6.32.41/drivers/char/hvcs.c 2011-04-17 15:56:46.000000000 -0400
26241@@ -82,6 +82,7 @@
26242 #include <asm/hvcserver.h>
26243 #include <asm/uaccess.h>
26244 #include <asm/vio.h>
26245+#include <asm/local.h>
26246
26247 /*
26248 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
26249@@ -269,7 +270,7 @@ struct hvcs_struct {
26250 unsigned int index;
26251
26252 struct tty_struct *tty;
26253- int open_count;
26254+ local_t open_count;
26255
26256 /*
26257 * Used to tell the driver kernel_thread what operations need to take
26258@@ -419,7 +420,7 @@ static ssize_t hvcs_vterm_state_store(st
26259
26260 spin_lock_irqsave(&hvcsd->lock, flags);
26261
26262- if (hvcsd->open_count > 0) {
26263+ if (local_read(&hvcsd->open_count) > 0) {
26264 spin_unlock_irqrestore(&hvcsd->lock, flags);
26265 printk(KERN_INFO "HVCS: vterm state unchanged. "
26266 "The hvcs device node is still in use.\n");
26267@@ -1135,7 +1136,7 @@ static int hvcs_open(struct tty_struct *
26268 if ((retval = hvcs_partner_connect(hvcsd)))
26269 goto error_release;
26270
26271- hvcsd->open_count = 1;
26272+ local_set(&hvcsd->open_count, 1);
26273 hvcsd->tty = tty;
26274 tty->driver_data = hvcsd;
26275
26276@@ -1169,7 +1170,7 @@ fast_open:
26277
26278 spin_lock_irqsave(&hvcsd->lock, flags);
26279 kref_get(&hvcsd->kref);
26280- hvcsd->open_count++;
26281+ local_inc(&hvcsd->open_count);
26282 hvcsd->todo_mask |= HVCS_SCHED_READ;
26283 spin_unlock_irqrestore(&hvcsd->lock, flags);
26284
26285@@ -1213,7 +1214,7 @@ static void hvcs_close(struct tty_struct
26286 hvcsd = tty->driver_data;
26287
26288 spin_lock_irqsave(&hvcsd->lock, flags);
26289- if (--hvcsd->open_count == 0) {
26290+ if (local_dec_and_test(&hvcsd->open_count)) {
26291
26292 vio_disable_interrupts(hvcsd->vdev);
26293
26294@@ -1239,10 +1240,10 @@ static void hvcs_close(struct tty_struct
26295 free_irq(irq, hvcsd);
26296 kref_put(&hvcsd->kref, destroy_hvcs_struct);
26297 return;
26298- } else if (hvcsd->open_count < 0) {
26299+ } else if (local_read(&hvcsd->open_count) < 0) {
26300 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
26301 " is missmanaged.\n",
26302- hvcsd->vdev->unit_address, hvcsd->open_count);
26303+ hvcsd->vdev->unit_address, local_read(&hvcsd->open_count));
26304 }
26305
26306 spin_unlock_irqrestore(&hvcsd->lock, flags);
26307@@ -1258,7 +1259,7 @@ static void hvcs_hangup(struct tty_struc
26308
26309 spin_lock_irqsave(&hvcsd->lock, flags);
26310 /* Preserve this so that we know how many kref refs to put */
26311- temp_open_count = hvcsd->open_count;
26312+ temp_open_count = local_read(&hvcsd->open_count);
26313
26314 /*
26315 * Don't kref put inside the spinlock because the destruction
26316@@ -1273,7 +1274,7 @@ static void hvcs_hangup(struct tty_struc
26317 hvcsd->tty->driver_data = NULL;
26318 hvcsd->tty = NULL;
26319
26320- hvcsd->open_count = 0;
26321+ local_set(&hvcsd->open_count, 0);
26322
26323 /* This will drop any buffered data on the floor which is OK in a hangup
26324 * scenario. */
26325@@ -1344,7 +1345,7 @@ static int hvcs_write(struct tty_struct
26326 * the middle of a write operation? This is a crummy place to do this
26327 * but we want to keep it all in the spinlock.
26328 */
26329- if (hvcsd->open_count <= 0) {
26330+ if (local_read(&hvcsd->open_count) <= 0) {
26331 spin_unlock_irqrestore(&hvcsd->lock, flags);
26332 return -ENODEV;
26333 }
26334@@ -1418,7 +1419,7 @@ static int hvcs_write_room(struct tty_st
26335 {
26336 struct hvcs_struct *hvcsd = tty->driver_data;
26337
26338- if (!hvcsd || hvcsd->open_count <= 0)
26339+ if (!hvcsd || local_read(&hvcsd->open_count) <= 0)
26340 return 0;
26341
26342 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
26343diff -urNp linux-2.6.32.41/drivers/char/hvc_udbg.c linux-2.6.32.41/drivers/char/hvc_udbg.c
26344--- linux-2.6.32.41/drivers/char/hvc_udbg.c 2011-03-27 14:31:47.000000000 -0400
26345+++ linux-2.6.32.41/drivers/char/hvc_udbg.c 2011-04-17 15:56:46.000000000 -0400
26346@@ -58,7 +58,7 @@ static int hvc_udbg_get(uint32_t vtermno
26347 return i;
26348 }
26349
26350-static struct hv_ops hvc_udbg_ops = {
26351+static const struct hv_ops hvc_udbg_ops = {
26352 .get_chars = hvc_udbg_get,
26353 .put_chars = hvc_udbg_put,
26354 };
26355diff -urNp linux-2.6.32.41/drivers/char/hvc_vio.c linux-2.6.32.41/drivers/char/hvc_vio.c
26356--- linux-2.6.32.41/drivers/char/hvc_vio.c 2011-03-27 14:31:47.000000000 -0400
26357+++ linux-2.6.32.41/drivers/char/hvc_vio.c 2011-04-17 15:56:46.000000000 -0400
26358@@ -77,7 +77,7 @@ static int filtered_get_chars(uint32_t v
26359 return got;
26360 }
26361
26362-static struct hv_ops hvc_get_put_ops = {
26363+static const struct hv_ops hvc_get_put_ops = {
26364 .get_chars = filtered_get_chars,
26365 .put_chars = hvc_put_chars,
26366 .notifier_add = notifier_add_irq,
26367diff -urNp linux-2.6.32.41/drivers/char/hvc_xen.c linux-2.6.32.41/drivers/char/hvc_xen.c
26368--- linux-2.6.32.41/drivers/char/hvc_xen.c 2011-03-27 14:31:47.000000000 -0400
26369+++ linux-2.6.32.41/drivers/char/hvc_xen.c 2011-04-17 15:56:46.000000000 -0400
26370@@ -120,7 +120,7 @@ static int read_console(uint32_t vtermno
26371 return recv;
26372 }
26373
26374-static struct hv_ops hvc_ops = {
26375+static const struct hv_ops hvc_ops = {
26376 .get_chars = read_console,
26377 .put_chars = write_console,
26378 .notifier_add = notifier_add_irq,
26379diff -urNp linux-2.6.32.41/drivers/char/ipmi/ipmi_msghandler.c linux-2.6.32.41/drivers/char/ipmi/ipmi_msghandler.c
26380--- linux-2.6.32.41/drivers/char/ipmi/ipmi_msghandler.c 2011-03-27 14:31:47.000000000 -0400
26381+++ linux-2.6.32.41/drivers/char/ipmi/ipmi_msghandler.c 2011-05-16 21:46:57.000000000 -0400
26382@@ -414,7 +414,7 @@ struct ipmi_smi {
26383 struct proc_dir_entry *proc_dir;
26384 char proc_dir_name[10];
26385
26386- atomic_t stats[IPMI_NUM_STATS];
26387+ atomic_unchecked_t stats[IPMI_NUM_STATS];
26388
26389 /*
26390 * run_to_completion duplicate of smb_info, smi_info
26391@@ -447,9 +447,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
26392
26393
26394 #define ipmi_inc_stat(intf, stat) \
26395- atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
26396+ atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
26397 #define ipmi_get_stat(intf, stat) \
26398- ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
26399+ ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
26400
26401 static int is_lan_addr(struct ipmi_addr *addr)
26402 {
26403@@ -2808,7 +2808,7 @@ int ipmi_register_smi(struct ipmi_smi_ha
26404 INIT_LIST_HEAD(&intf->cmd_rcvrs);
26405 init_waitqueue_head(&intf->waitq);
26406 for (i = 0; i < IPMI_NUM_STATS; i++)
26407- atomic_set(&intf->stats[i], 0);
26408+ atomic_set_unchecked(&intf->stats[i], 0);
26409
26410 intf->proc_dir = NULL;
26411
26412@@ -4160,6 +4160,8 @@ static void send_panic_events(char *str)
26413 struct ipmi_smi_msg smi_msg;
26414 struct ipmi_recv_msg recv_msg;
26415
26416+ pax_track_stack();
26417+
26418 si = (struct ipmi_system_interface_addr *) &addr;
26419 si->addr_type = IPMI_SYSTEM_INTERFACE_ADDR_TYPE;
26420 si->channel = IPMI_BMC_CHANNEL;
26421diff -urNp linux-2.6.32.41/drivers/char/ipmi/ipmi_si_intf.c linux-2.6.32.41/drivers/char/ipmi/ipmi_si_intf.c
26422--- linux-2.6.32.41/drivers/char/ipmi/ipmi_si_intf.c 2011-03-27 14:31:47.000000000 -0400
26423+++ linux-2.6.32.41/drivers/char/ipmi/ipmi_si_intf.c 2011-04-17 15:56:46.000000000 -0400
26424@@ -277,7 +277,7 @@ struct smi_info {
26425 unsigned char slave_addr;
26426
26427 /* Counters and things for the proc filesystem. */
26428- atomic_t stats[SI_NUM_STATS];
26429+ atomic_unchecked_t stats[SI_NUM_STATS];
26430
26431 struct task_struct *thread;
26432
26433@@ -285,9 +285,9 @@ struct smi_info {
26434 };
26435
26436 #define smi_inc_stat(smi, stat) \
26437- atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
26438+ atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
26439 #define smi_get_stat(smi, stat) \
26440- ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
26441+ ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
26442
26443 #define SI_MAX_PARMS 4
26444
26445@@ -2931,7 +2931,7 @@ static int try_smi_init(struct smi_info
26446 atomic_set(&new_smi->req_events, 0);
26447 new_smi->run_to_completion = 0;
26448 for (i = 0; i < SI_NUM_STATS; i++)
26449- atomic_set(&new_smi->stats[i], 0);
26450+ atomic_set_unchecked(&new_smi->stats[i], 0);
26451
26452 new_smi->interrupt_disabled = 0;
26453 atomic_set(&new_smi->stop_operation, 0);
26454diff -urNp linux-2.6.32.41/drivers/char/istallion.c linux-2.6.32.41/drivers/char/istallion.c
26455--- linux-2.6.32.41/drivers/char/istallion.c 2011-03-27 14:31:47.000000000 -0400
26456+++ linux-2.6.32.41/drivers/char/istallion.c 2011-05-16 21:46:57.000000000 -0400
26457@@ -187,7 +187,6 @@ static struct ktermios stli_deftermios
26458 * re-used for each stats call.
26459 */
26460 static comstats_t stli_comstats;
26461-static combrd_t stli_brdstats;
26462 static struct asystats stli_cdkstats;
26463
26464 /*****************************************************************************/
26465@@ -4058,6 +4057,7 @@ static int stli_getbrdstats(combrd_t __u
26466 {
26467 struct stlibrd *brdp;
26468 unsigned int i;
26469+ combrd_t stli_brdstats;
26470
26471 if (copy_from_user(&stli_brdstats, bp, sizeof(combrd_t)))
26472 return -EFAULT;
26473@@ -4269,6 +4269,8 @@ static int stli_getportstruct(struct stl
26474 struct stliport stli_dummyport;
26475 struct stliport *portp;
26476
26477+ pax_track_stack();
26478+
26479 if (copy_from_user(&stli_dummyport, arg, sizeof(struct stliport)))
26480 return -EFAULT;
26481 portp = stli_getport(stli_dummyport.brdnr, stli_dummyport.panelnr,
26482@@ -4291,6 +4293,8 @@ static int stli_getbrdstruct(struct stli
26483 struct stlibrd stli_dummybrd;
26484 struct stlibrd *brdp;
26485
26486+ pax_track_stack();
26487+
26488 if (copy_from_user(&stli_dummybrd, arg, sizeof(struct stlibrd)))
26489 return -EFAULT;
26490 if (stli_dummybrd.brdnr >= STL_MAXBRDS)
26491diff -urNp linux-2.6.32.41/drivers/char/Kconfig linux-2.6.32.41/drivers/char/Kconfig
26492--- linux-2.6.32.41/drivers/char/Kconfig 2011-03-27 14:31:47.000000000 -0400
26493+++ linux-2.6.32.41/drivers/char/Kconfig 2011-04-18 19:20:15.000000000 -0400
26494@@ -90,7 +90,8 @@ config VT_HW_CONSOLE_BINDING
26495
26496 config DEVKMEM
26497 bool "/dev/kmem virtual device support"
26498- default y
26499+ default n
26500+ depends on !GRKERNSEC_KMEM
26501 help
26502 Say Y here if you want to support the /dev/kmem device. The
26503 /dev/kmem device is rarely used, but can be used for certain
26504@@ -1114,6 +1115,7 @@ config DEVPORT
26505 bool
26506 depends on !M68K
26507 depends on ISA || PCI
26508+ depends on !GRKERNSEC_KMEM
26509 default y
26510
26511 source "drivers/s390/char/Kconfig"
26512diff -urNp linux-2.6.32.41/drivers/char/keyboard.c linux-2.6.32.41/drivers/char/keyboard.c
26513--- linux-2.6.32.41/drivers/char/keyboard.c 2011-03-27 14:31:47.000000000 -0400
26514+++ linux-2.6.32.41/drivers/char/keyboard.c 2011-04-17 15:56:46.000000000 -0400
26515@@ -635,6 +635,16 @@ static void k_spec(struct vc_data *vc, u
26516 kbd->kbdmode == VC_MEDIUMRAW) &&
26517 value != KVAL(K_SAK))
26518 return; /* SAK is allowed even in raw mode */
26519+
26520+#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
26521+ {
26522+ void *func = fn_handler[value];
26523+ if (func == fn_show_state || func == fn_show_ptregs ||
26524+ func == fn_show_mem)
26525+ return;
26526+ }
26527+#endif
26528+
26529 fn_handler[value](vc);
26530 }
26531
26532@@ -1386,7 +1396,7 @@ static const struct input_device_id kbd_
26533 .evbit = { BIT_MASK(EV_SND) },
26534 },
26535
26536- { }, /* Terminating entry */
26537+ { 0 }, /* Terminating entry */
26538 };
26539
26540 MODULE_DEVICE_TABLE(input, kbd_ids);
26541diff -urNp linux-2.6.32.41/drivers/char/mem.c linux-2.6.32.41/drivers/char/mem.c
26542--- linux-2.6.32.41/drivers/char/mem.c 2011-03-27 14:31:47.000000000 -0400
26543+++ linux-2.6.32.41/drivers/char/mem.c 2011-04-17 15:56:46.000000000 -0400
26544@@ -18,6 +18,7 @@
26545 #include <linux/raw.h>
26546 #include <linux/tty.h>
26547 #include <linux/capability.h>
26548+#include <linux/security.h>
26549 #include <linux/ptrace.h>
26550 #include <linux/device.h>
26551 #include <linux/highmem.h>
26552@@ -35,6 +36,10 @@
26553 # include <linux/efi.h>
26554 #endif
26555
26556+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
26557+extern struct file_operations grsec_fops;
26558+#endif
26559+
26560 static inline unsigned long size_inside_page(unsigned long start,
26561 unsigned long size)
26562 {
26563@@ -102,9 +107,13 @@ static inline int range_is_allowed(unsig
26564
26565 while (cursor < to) {
26566 if (!devmem_is_allowed(pfn)) {
26567+#ifdef CONFIG_GRKERNSEC_KMEM
26568+ gr_handle_mem_readwrite(from, to);
26569+#else
26570 printk(KERN_INFO
26571 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
26572 current->comm, from, to);
26573+#endif
26574 return 0;
26575 }
26576 cursor += PAGE_SIZE;
26577@@ -112,6 +121,11 @@ static inline int range_is_allowed(unsig
26578 }
26579 return 1;
26580 }
26581+#elif defined(CONFIG_GRKERNSEC_KMEM)
26582+static inline int range_is_allowed(unsigned long pfn, unsigned long size)
26583+{
26584+ return 0;
26585+}
26586 #else
26587 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
26588 {
26589@@ -155,6 +169,8 @@ static ssize_t read_mem(struct file * fi
26590 #endif
26591
26592 while (count > 0) {
26593+ char *temp;
26594+
26595 /*
26596 * Handle first page in case it's not aligned
26597 */
26598@@ -177,11 +193,31 @@ static ssize_t read_mem(struct file * fi
26599 if (!ptr)
26600 return -EFAULT;
26601
26602- if (copy_to_user(buf, ptr, sz)) {
26603+#ifdef CONFIG_PAX_USERCOPY
26604+ temp = kmalloc(sz, GFP_KERNEL);
26605+ if (!temp) {
26606+ unxlate_dev_mem_ptr(p, ptr);
26607+ return -ENOMEM;
26608+ }
26609+ memcpy(temp, ptr, sz);
26610+#else
26611+ temp = ptr;
26612+#endif
26613+
26614+ if (copy_to_user(buf, temp, sz)) {
26615+
26616+#ifdef CONFIG_PAX_USERCOPY
26617+ kfree(temp);
26618+#endif
26619+
26620 unxlate_dev_mem_ptr(p, ptr);
26621 return -EFAULT;
26622 }
26623
26624+#ifdef CONFIG_PAX_USERCOPY
26625+ kfree(temp);
26626+#endif
26627+
26628 unxlate_dev_mem_ptr(p, ptr);
26629
26630 buf += sz;
26631@@ -419,9 +455,8 @@ static ssize_t read_kmem(struct file *fi
26632 size_t count, loff_t *ppos)
26633 {
26634 unsigned long p = *ppos;
26635- ssize_t low_count, read, sz;
26636+ ssize_t low_count, read, sz, err = 0;
26637 char * kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
26638- int err = 0;
26639
26640 read = 0;
26641 if (p < (unsigned long) high_memory) {
26642@@ -444,6 +479,8 @@ static ssize_t read_kmem(struct file *fi
26643 }
26644 #endif
26645 while (low_count > 0) {
26646+ char *temp;
26647+
26648 sz = size_inside_page(p, low_count);
26649
26650 /*
26651@@ -453,7 +490,22 @@ static ssize_t read_kmem(struct file *fi
26652 */
26653 kbuf = xlate_dev_kmem_ptr((char *)p);
26654
26655- if (copy_to_user(buf, kbuf, sz))
26656+#ifdef CONFIG_PAX_USERCOPY
26657+ temp = kmalloc(sz, GFP_KERNEL);
26658+ if (!temp)
26659+ return -ENOMEM;
26660+ memcpy(temp, kbuf, sz);
26661+#else
26662+ temp = kbuf;
26663+#endif
26664+
26665+ err = copy_to_user(buf, temp, sz);
26666+
26667+#ifdef CONFIG_PAX_USERCOPY
26668+ kfree(temp);
26669+#endif
26670+
26671+ if (err)
26672 return -EFAULT;
26673 buf += sz;
26674 p += sz;
26675@@ -889,6 +941,9 @@ static const struct memdev {
26676 #ifdef CONFIG_CRASH_DUMP
26677 [12] = { "oldmem", 0, &oldmem_fops, NULL },
26678 #endif
26679+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
26680+ [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
26681+#endif
26682 };
26683
26684 static int memory_open(struct inode *inode, struct file *filp)
26685diff -urNp linux-2.6.32.41/drivers/char/pcmcia/ipwireless/tty.c linux-2.6.32.41/drivers/char/pcmcia/ipwireless/tty.c
26686--- linux-2.6.32.41/drivers/char/pcmcia/ipwireless/tty.c 2011-03-27 14:31:47.000000000 -0400
26687+++ linux-2.6.32.41/drivers/char/pcmcia/ipwireless/tty.c 2011-04-17 15:56:46.000000000 -0400
26688@@ -29,6 +29,7 @@
26689 #include <linux/tty_driver.h>
26690 #include <linux/tty_flip.h>
26691 #include <linux/uaccess.h>
26692+#include <asm/local.h>
26693
26694 #include "tty.h"
26695 #include "network.h"
26696@@ -51,7 +52,7 @@ struct ipw_tty {
26697 int tty_type;
26698 struct ipw_network *network;
26699 struct tty_struct *linux_tty;
26700- int open_count;
26701+ local_t open_count;
26702 unsigned int control_lines;
26703 struct mutex ipw_tty_mutex;
26704 int tx_bytes_queued;
26705@@ -127,10 +128,10 @@ static int ipw_open(struct tty_struct *l
26706 mutex_unlock(&tty->ipw_tty_mutex);
26707 return -ENODEV;
26708 }
26709- if (tty->open_count == 0)
26710+ if (local_read(&tty->open_count) == 0)
26711 tty->tx_bytes_queued = 0;
26712
26713- tty->open_count++;
26714+ local_inc(&tty->open_count);
26715
26716 tty->linux_tty = linux_tty;
26717 linux_tty->driver_data = tty;
26718@@ -146,9 +147,7 @@ static int ipw_open(struct tty_struct *l
26719
26720 static void do_ipw_close(struct ipw_tty *tty)
26721 {
26722- tty->open_count--;
26723-
26724- if (tty->open_count == 0) {
26725+ if (local_dec_return(&tty->open_count) == 0) {
26726 struct tty_struct *linux_tty = tty->linux_tty;
26727
26728 if (linux_tty != NULL) {
26729@@ -169,7 +168,7 @@ static void ipw_hangup(struct tty_struct
26730 return;
26731
26732 mutex_lock(&tty->ipw_tty_mutex);
26733- if (tty->open_count == 0) {
26734+ if (local_read(&tty->open_count) == 0) {
26735 mutex_unlock(&tty->ipw_tty_mutex);
26736 return;
26737 }
26738@@ -198,7 +197,7 @@ void ipwireless_tty_received(struct ipw_
26739 return;
26740 }
26741
26742- if (!tty->open_count) {
26743+ if (!local_read(&tty->open_count)) {
26744 mutex_unlock(&tty->ipw_tty_mutex);
26745 return;
26746 }
26747@@ -240,7 +239,7 @@ static int ipw_write(struct tty_struct *
26748 return -ENODEV;
26749
26750 mutex_lock(&tty->ipw_tty_mutex);
26751- if (!tty->open_count) {
26752+ if (!local_read(&tty->open_count)) {
26753 mutex_unlock(&tty->ipw_tty_mutex);
26754 return -EINVAL;
26755 }
26756@@ -280,7 +279,7 @@ static int ipw_write_room(struct tty_str
26757 if (!tty)
26758 return -ENODEV;
26759
26760- if (!tty->open_count)
26761+ if (!local_read(&tty->open_count))
26762 return -EINVAL;
26763
26764 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
26765@@ -322,7 +321,7 @@ static int ipw_chars_in_buffer(struct tt
26766 if (!tty)
26767 return 0;
26768
26769- if (!tty->open_count)
26770+ if (!local_read(&tty->open_count))
26771 return 0;
26772
26773 return tty->tx_bytes_queued;
26774@@ -403,7 +402,7 @@ static int ipw_tiocmget(struct tty_struc
26775 if (!tty)
26776 return -ENODEV;
26777
26778- if (!tty->open_count)
26779+ if (!local_read(&tty->open_count))
26780 return -EINVAL;
26781
26782 return get_control_lines(tty);
26783@@ -419,7 +418,7 @@ ipw_tiocmset(struct tty_struct *linux_tt
26784 if (!tty)
26785 return -ENODEV;
26786
26787- if (!tty->open_count)
26788+ if (!local_read(&tty->open_count))
26789 return -EINVAL;
26790
26791 return set_control_lines(tty, set, clear);
26792@@ -433,7 +432,7 @@ static int ipw_ioctl(struct tty_struct *
26793 if (!tty)
26794 return -ENODEV;
26795
26796- if (!tty->open_count)
26797+ if (!local_read(&tty->open_count))
26798 return -EINVAL;
26799
26800 /* FIXME: Exactly how is the tty object locked here .. */
26801@@ -591,7 +590,7 @@ void ipwireless_tty_free(struct ipw_tty
26802 against a parallel ioctl etc */
26803 mutex_lock(&ttyj->ipw_tty_mutex);
26804 }
26805- while (ttyj->open_count)
26806+ while (local_read(&ttyj->open_count))
26807 do_ipw_close(ttyj);
26808 ipwireless_disassociate_network_ttys(network,
26809 ttyj->channel_idx);
26810diff -urNp linux-2.6.32.41/drivers/char/pty.c linux-2.6.32.41/drivers/char/pty.c
26811--- linux-2.6.32.41/drivers/char/pty.c 2011-03-27 14:31:47.000000000 -0400
26812+++ linux-2.6.32.41/drivers/char/pty.c 2011-04-17 15:56:46.000000000 -0400
26813@@ -682,7 +682,18 @@ static int ptmx_open(struct inode *inode
26814 return ret;
26815 }
26816
26817-static struct file_operations ptmx_fops;
26818+static const struct file_operations ptmx_fops = {
26819+ .llseek = no_llseek,
26820+ .read = tty_read,
26821+ .write = tty_write,
26822+ .poll = tty_poll,
26823+ .unlocked_ioctl = tty_ioctl,
26824+ .compat_ioctl = tty_compat_ioctl,
26825+ .open = ptmx_open,
26826+ .release = tty_release,
26827+ .fasync = tty_fasync,
26828+};
26829+
26830
26831 static void __init unix98_pty_init(void)
26832 {
26833@@ -736,9 +747,6 @@ static void __init unix98_pty_init(void)
26834 register_sysctl_table(pty_root_table);
26835
26836 /* Now create the /dev/ptmx special device */
26837- tty_default_fops(&ptmx_fops);
26838- ptmx_fops.open = ptmx_open;
26839-
26840 cdev_init(&ptmx_cdev, &ptmx_fops);
26841 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
26842 register_chrdev_region(MKDEV(TTYAUX_MAJOR, 2), 1, "/dev/ptmx") < 0)
26843diff -urNp linux-2.6.32.41/drivers/char/random.c linux-2.6.32.41/drivers/char/random.c
26844--- linux-2.6.32.41/drivers/char/random.c 2011-03-27 14:31:47.000000000 -0400
26845+++ linux-2.6.32.41/drivers/char/random.c 2011-04-17 15:56:46.000000000 -0400
26846@@ -254,8 +254,13 @@
26847 /*
26848 * Configuration information
26849 */
26850+#ifdef CONFIG_GRKERNSEC_RANDNET
26851+#define INPUT_POOL_WORDS 512
26852+#define OUTPUT_POOL_WORDS 128
26853+#else
26854 #define INPUT_POOL_WORDS 128
26855 #define OUTPUT_POOL_WORDS 32
26856+#endif
26857 #define SEC_XFER_SIZE 512
26858
26859 /*
26860@@ -292,10 +297,17 @@ static struct poolinfo {
26861 int poolwords;
26862 int tap1, tap2, tap3, tap4, tap5;
26863 } poolinfo_table[] = {
26864+#ifdef CONFIG_GRKERNSEC_RANDNET
26865+ /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
26866+ { 512, 411, 308, 208, 104, 1 },
26867+ /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
26868+ { 128, 103, 76, 51, 25, 1 },
26869+#else
26870 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
26871 { 128, 103, 76, 51, 25, 1 },
26872 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
26873 { 32, 26, 20, 14, 7, 1 },
26874+#endif
26875 #if 0
26876 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
26877 { 2048, 1638, 1231, 819, 411, 1 },
26878@@ -1209,7 +1221,7 @@ EXPORT_SYMBOL(generate_random_uuid);
26879 #include <linux/sysctl.h>
26880
26881 static int min_read_thresh = 8, min_write_thresh;
26882-static int max_read_thresh = INPUT_POOL_WORDS * 32;
26883+static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
26884 static int max_write_thresh = INPUT_POOL_WORDS * 32;
26885 static char sysctl_bootid[16];
26886
26887diff -urNp linux-2.6.32.41/drivers/char/rocket.c linux-2.6.32.41/drivers/char/rocket.c
26888--- linux-2.6.32.41/drivers/char/rocket.c 2011-03-27 14:31:47.000000000 -0400
26889+++ linux-2.6.32.41/drivers/char/rocket.c 2011-05-16 21:46:57.000000000 -0400
26890@@ -1266,6 +1266,8 @@ static int get_ports(struct r_port *info
26891 struct rocket_ports tmp;
26892 int board;
26893
26894+ pax_track_stack();
26895+
26896 if (!retports)
26897 return -EFAULT;
26898 memset(&tmp, 0, sizeof (tmp));
26899diff -urNp linux-2.6.32.41/drivers/char/sonypi.c linux-2.6.32.41/drivers/char/sonypi.c
26900--- linux-2.6.32.41/drivers/char/sonypi.c 2011-03-27 14:31:47.000000000 -0400
26901+++ linux-2.6.32.41/drivers/char/sonypi.c 2011-04-17 15:56:46.000000000 -0400
26902@@ -55,6 +55,7 @@
26903 #include <asm/uaccess.h>
26904 #include <asm/io.h>
26905 #include <asm/system.h>
26906+#include <asm/local.h>
26907
26908 #include <linux/sonypi.h>
26909
26910@@ -491,7 +492,7 @@ static struct sonypi_device {
26911 spinlock_t fifo_lock;
26912 wait_queue_head_t fifo_proc_list;
26913 struct fasync_struct *fifo_async;
26914- int open_count;
26915+ local_t open_count;
26916 int model;
26917 struct input_dev *input_jog_dev;
26918 struct input_dev *input_key_dev;
26919@@ -895,7 +896,7 @@ static int sonypi_misc_fasync(int fd, st
26920 static int sonypi_misc_release(struct inode *inode, struct file *file)
26921 {
26922 mutex_lock(&sonypi_device.lock);
26923- sonypi_device.open_count--;
26924+ local_dec(&sonypi_device.open_count);
26925 mutex_unlock(&sonypi_device.lock);
26926 return 0;
26927 }
26928@@ -905,9 +906,9 @@ static int sonypi_misc_open(struct inode
26929 lock_kernel();
26930 mutex_lock(&sonypi_device.lock);
26931 /* Flush input queue on first open */
26932- if (!sonypi_device.open_count)
26933+ if (!local_read(&sonypi_device.open_count))
26934 kfifo_reset(sonypi_device.fifo);
26935- sonypi_device.open_count++;
26936+ local_inc(&sonypi_device.open_count);
26937 mutex_unlock(&sonypi_device.lock);
26938 unlock_kernel();
26939 return 0;
26940diff -urNp linux-2.6.32.41/drivers/char/stallion.c linux-2.6.32.41/drivers/char/stallion.c
26941--- linux-2.6.32.41/drivers/char/stallion.c 2011-03-27 14:31:47.000000000 -0400
26942+++ linux-2.6.32.41/drivers/char/stallion.c 2011-05-16 21:46:57.000000000 -0400
26943@@ -2448,6 +2448,8 @@ static int stl_getportstruct(struct stlp
26944 struct stlport stl_dummyport;
26945 struct stlport *portp;
26946
26947+ pax_track_stack();
26948+
26949 if (copy_from_user(&stl_dummyport, arg, sizeof(struct stlport)))
26950 return -EFAULT;
26951 portp = stl_getport(stl_dummyport.brdnr, stl_dummyport.panelnr,
26952diff -urNp linux-2.6.32.41/drivers/char/tpm/tpm_bios.c linux-2.6.32.41/drivers/char/tpm/tpm_bios.c
26953--- linux-2.6.32.41/drivers/char/tpm/tpm_bios.c 2011-03-27 14:31:47.000000000 -0400
26954+++ linux-2.6.32.41/drivers/char/tpm/tpm_bios.c 2011-04-17 15:56:46.000000000 -0400
26955@@ -172,7 +172,7 @@ static void *tpm_bios_measurements_start
26956 event = addr;
26957
26958 if ((event->event_type == 0 && event->event_size == 0) ||
26959- ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
26960+ (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
26961 return NULL;
26962
26963 return addr;
26964@@ -197,7 +197,7 @@ static void *tpm_bios_measurements_next(
26965 return NULL;
26966
26967 if ((event->event_type == 0 && event->event_size == 0) ||
26968- ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
26969+ (event->event_size >= limit - v - sizeof(struct tcpa_event)))
26970 return NULL;
26971
26972 (*pos)++;
26973@@ -290,7 +290,8 @@ static int tpm_binary_bios_measurements_
26974 int i;
26975
26976 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
26977- seq_putc(m, data[i]);
26978+ if (!seq_putc(m, data[i]))
26979+ return -EFAULT;
26980
26981 return 0;
26982 }
26983@@ -409,6 +410,11 @@ static int read_log(struct tpm_bios_log
26984 log->bios_event_log_end = log->bios_event_log + len;
26985
26986 virt = acpi_os_map_memory(start, len);
26987+ if (!virt) {
26988+ kfree(log->bios_event_log);
26989+ log->bios_event_log = NULL;
26990+ return -EFAULT;
26991+ }
26992
26993 memcpy(log->bios_event_log, virt, len);
26994
26995diff -urNp linux-2.6.32.41/drivers/char/tpm/tpm.c linux-2.6.32.41/drivers/char/tpm/tpm.c
26996--- linux-2.6.32.41/drivers/char/tpm/tpm.c 2011-04-17 17:00:52.000000000 -0400
26997+++ linux-2.6.32.41/drivers/char/tpm/tpm.c 2011-05-16 21:46:57.000000000 -0400
26998@@ -402,7 +402,7 @@ static ssize_t tpm_transmit(struct tpm_c
26999 chip->vendor.req_complete_val)
27000 goto out_recv;
27001
27002- if ((status == chip->vendor.req_canceled)) {
27003+ if (status == chip->vendor.req_canceled) {
27004 dev_err(chip->dev, "Operation Canceled\n");
27005 rc = -ECANCELED;
27006 goto out;
27007@@ -821,6 +821,8 @@ ssize_t tpm_show_pubek(struct device *de
27008
27009 struct tpm_chip *chip = dev_get_drvdata(dev);
27010
27011+ pax_track_stack();
27012+
27013 tpm_cmd.header.in = tpm_readpubek_header;
27014 err = transmit_cmd(chip, &tpm_cmd, READ_PUBEK_RESULT_SIZE,
27015 "attempting to read the PUBEK");
27016diff -urNp linux-2.6.32.41/drivers/char/tty_io.c linux-2.6.32.41/drivers/char/tty_io.c
27017--- linux-2.6.32.41/drivers/char/tty_io.c 2011-03-27 14:31:47.000000000 -0400
27018+++ linux-2.6.32.41/drivers/char/tty_io.c 2011-04-17 15:56:46.000000000 -0400
27019@@ -136,21 +136,10 @@ LIST_HEAD(tty_drivers); /* linked list
27020 DEFINE_MUTEX(tty_mutex);
27021 EXPORT_SYMBOL(tty_mutex);
27022
27023-static ssize_t tty_read(struct file *, char __user *, size_t, loff_t *);
27024-static ssize_t tty_write(struct file *, const char __user *, size_t, loff_t *);
27025 ssize_t redirected_tty_write(struct file *, const char __user *,
27026 size_t, loff_t *);
27027-static unsigned int tty_poll(struct file *, poll_table *);
27028 static int tty_open(struct inode *, struct file *);
27029-static int tty_release(struct inode *, struct file *);
27030 long tty_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
27031-#ifdef CONFIG_COMPAT
27032-static long tty_compat_ioctl(struct file *file, unsigned int cmd,
27033- unsigned long arg);
27034-#else
27035-#define tty_compat_ioctl NULL
27036-#endif
27037-static int tty_fasync(int fd, struct file *filp, int on);
27038 static void release_tty(struct tty_struct *tty, int idx);
27039 static void __proc_set_tty(struct task_struct *tsk, struct tty_struct *tty);
27040 static void proc_set_tty(struct task_struct *tsk, struct tty_struct *tty);
27041@@ -870,7 +859,7 @@ EXPORT_SYMBOL(start_tty);
27042 * read calls may be outstanding in parallel.
27043 */
27044
27045-static ssize_t tty_read(struct file *file, char __user *buf, size_t count,
27046+ssize_t tty_read(struct file *file, char __user *buf, size_t count,
27047 loff_t *ppos)
27048 {
27049 int i;
27050@@ -898,6 +887,8 @@ static ssize_t tty_read(struct file *fil
27051 return i;
27052 }
27053
27054+EXPORT_SYMBOL(tty_read);
27055+
27056 void tty_write_unlock(struct tty_struct *tty)
27057 {
27058 mutex_unlock(&tty->atomic_write_lock);
27059@@ -1045,7 +1036,7 @@ void tty_write_message(struct tty_struct
27060 * write method will not be invoked in parallel for each device.
27061 */
27062
27063-static ssize_t tty_write(struct file *file, const char __user *buf,
27064+ssize_t tty_write(struct file *file, const char __user *buf,
27065 size_t count, loff_t *ppos)
27066 {
27067 struct tty_struct *tty;
27068@@ -1072,6 +1063,8 @@ static ssize_t tty_write(struct file *fi
27069 return ret;
27070 }
27071
27072+EXPORT_SYMBOL(tty_write);
27073+
27074 ssize_t redirected_tty_write(struct file *file, const char __user *buf,
27075 size_t count, loff_t *ppos)
27076 {
27077@@ -1867,7 +1860,7 @@ static int tty_open(struct inode *inode,
27078 * Takes bkl. See tty_release_dev
27079 */
27080
27081-static int tty_release(struct inode *inode, struct file *filp)
27082+int tty_release(struct inode *inode, struct file *filp)
27083 {
27084 lock_kernel();
27085 tty_release_dev(filp);
27086@@ -1875,6 +1868,8 @@ static int tty_release(struct inode *ino
27087 return 0;
27088 }
27089
27090+EXPORT_SYMBOL(tty_release);
27091+
27092 /**
27093 * tty_poll - check tty status
27094 * @filp: file being polled
27095@@ -1887,7 +1882,7 @@ static int tty_release(struct inode *ino
27096 * may be re-entered freely by other callers.
27097 */
27098
27099-static unsigned int tty_poll(struct file *filp, poll_table *wait)
27100+unsigned int tty_poll(struct file *filp, poll_table *wait)
27101 {
27102 struct tty_struct *tty;
27103 struct tty_ldisc *ld;
27104@@ -1904,7 +1899,9 @@ static unsigned int tty_poll(struct file
27105 return ret;
27106 }
27107
27108-static int tty_fasync(int fd, struct file *filp, int on)
27109+EXPORT_SYMBOL(tty_poll);
27110+
27111+int tty_fasync(int fd, struct file *filp, int on)
27112 {
27113 struct tty_struct *tty;
27114 unsigned long flags;
27115@@ -1948,6 +1945,8 @@ out:
27116 return retval;
27117 }
27118
27119+EXPORT_SYMBOL(tty_fasync);
27120+
27121 /**
27122 * tiocsti - fake input character
27123 * @tty: tty to fake input into
27124@@ -2582,8 +2581,10 @@ long tty_ioctl(struct file *file, unsign
27125 return retval;
27126 }
27127
27128+EXPORT_SYMBOL(tty_ioctl);
27129+
27130 #ifdef CONFIG_COMPAT
27131-static long tty_compat_ioctl(struct file *file, unsigned int cmd,
27132+long tty_compat_ioctl(struct file *file, unsigned int cmd,
27133 unsigned long arg)
27134 {
27135 struct inode *inode = file->f_dentry->d_inode;
27136@@ -2607,6 +2608,8 @@ static long tty_compat_ioctl(struct file
27137
27138 return retval;
27139 }
27140+
27141+EXPORT_SYMBOL(tty_compat_ioctl);
27142 #endif
27143
27144 /*
27145@@ -3050,11 +3053,6 @@ struct tty_struct *get_current_tty(void)
27146 }
27147 EXPORT_SYMBOL_GPL(get_current_tty);
27148
27149-void tty_default_fops(struct file_operations *fops)
27150-{
27151- *fops = tty_fops;
27152-}
27153-
27154 /*
27155 * Initialize the console device. This is called *early*, so
27156 * we can't necessarily depend on lots of kernel help here.
27157diff -urNp linux-2.6.32.41/drivers/char/tty_ldisc.c linux-2.6.32.41/drivers/char/tty_ldisc.c
27158--- linux-2.6.32.41/drivers/char/tty_ldisc.c 2011-03-27 14:31:47.000000000 -0400
27159+++ linux-2.6.32.41/drivers/char/tty_ldisc.c 2011-04-17 15:56:46.000000000 -0400
27160@@ -74,7 +74,7 @@ static void put_ldisc(struct tty_ldisc *
27161 if (atomic_dec_and_lock(&ld->users, &tty_ldisc_lock)) {
27162 struct tty_ldisc_ops *ldo = ld->ops;
27163
27164- ldo->refcount--;
27165+ atomic_dec(&ldo->refcount);
27166 module_put(ldo->owner);
27167 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
27168
27169@@ -109,7 +109,7 @@ int tty_register_ldisc(int disc, struct
27170 spin_lock_irqsave(&tty_ldisc_lock, flags);
27171 tty_ldiscs[disc] = new_ldisc;
27172 new_ldisc->num = disc;
27173- new_ldisc->refcount = 0;
27174+ atomic_set(&new_ldisc->refcount, 0);
27175 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
27176
27177 return ret;
27178@@ -137,7 +137,7 @@ int tty_unregister_ldisc(int disc)
27179 return -EINVAL;
27180
27181 spin_lock_irqsave(&tty_ldisc_lock, flags);
27182- if (tty_ldiscs[disc]->refcount)
27183+ if (atomic_read(&tty_ldiscs[disc]->refcount))
27184 ret = -EBUSY;
27185 else
27186 tty_ldiscs[disc] = NULL;
27187@@ -158,7 +158,7 @@ static struct tty_ldisc_ops *get_ldops(i
27188 if (ldops) {
27189 ret = ERR_PTR(-EAGAIN);
27190 if (try_module_get(ldops->owner)) {
27191- ldops->refcount++;
27192+ atomic_inc(&ldops->refcount);
27193 ret = ldops;
27194 }
27195 }
27196@@ -171,7 +171,7 @@ static void put_ldops(struct tty_ldisc_o
27197 unsigned long flags;
27198
27199 spin_lock_irqsave(&tty_ldisc_lock, flags);
27200- ldops->refcount--;
27201+ atomic_dec(&ldops->refcount);
27202 module_put(ldops->owner);
27203 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
27204 }
27205diff -urNp linux-2.6.32.41/drivers/char/virtio_console.c linux-2.6.32.41/drivers/char/virtio_console.c
27206--- linux-2.6.32.41/drivers/char/virtio_console.c 2011-03-27 14:31:47.000000000 -0400
27207+++ linux-2.6.32.41/drivers/char/virtio_console.c 2011-04-17 15:56:46.000000000 -0400
27208@@ -44,6 +44,7 @@ static unsigned int in_len;
27209 static char *in, *inbuf;
27210
27211 /* The operations for our console. */
27212+/* cannot be const */
27213 static struct hv_ops virtio_cons;
27214
27215 /* The hvc device */
27216diff -urNp linux-2.6.32.41/drivers/char/vt.c linux-2.6.32.41/drivers/char/vt.c
27217--- linux-2.6.32.41/drivers/char/vt.c 2011-03-27 14:31:47.000000000 -0400
27218+++ linux-2.6.32.41/drivers/char/vt.c 2011-04-17 15:56:46.000000000 -0400
27219@@ -243,7 +243,7 @@ EXPORT_SYMBOL_GPL(unregister_vt_notifier
27220
27221 static void notify_write(struct vc_data *vc, unsigned int unicode)
27222 {
27223- struct vt_notifier_param param = { .vc = vc, unicode = unicode };
27224+ struct vt_notifier_param param = { .vc = vc, .c = unicode };
27225 atomic_notifier_call_chain(&vt_notifier_list, VT_WRITE, &param);
27226 }
27227
27228diff -urNp linux-2.6.32.41/drivers/char/vt_ioctl.c linux-2.6.32.41/drivers/char/vt_ioctl.c
27229--- linux-2.6.32.41/drivers/char/vt_ioctl.c 2011-03-27 14:31:47.000000000 -0400
27230+++ linux-2.6.32.41/drivers/char/vt_ioctl.c 2011-04-17 15:56:46.000000000 -0400
27231@@ -210,9 +210,6 @@ do_kdsk_ioctl(int cmd, struct kbentry __
27232 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
27233 return -EFAULT;
27234
27235- if (!capable(CAP_SYS_TTY_CONFIG))
27236- perm = 0;
27237-
27238 switch (cmd) {
27239 case KDGKBENT:
27240 key_map = key_maps[s];
27241@@ -224,8 +221,12 @@ do_kdsk_ioctl(int cmd, struct kbentry __
27242 val = (i ? K_HOLE : K_NOSUCHMAP);
27243 return put_user(val, &user_kbe->kb_value);
27244 case KDSKBENT:
27245+ if (!capable(CAP_SYS_TTY_CONFIG))
27246+ perm = 0;
27247+
27248 if (!perm)
27249 return -EPERM;
27250+
27251 if (!i && v == K_NOSUCHMAP) {
27252 /* deallocate map */
27253 key_map = key_maps[s];
27254@@ -325,9 +326,6 @@ do_kdgkb_ioctl(int cmd, struct kbsentry
27255 int i, j, k;
27256 int ret;
27257
27258- if (!capable(CAP_SYS_TTY_CONFIG))
27259- perm = 0;
27260-
27261 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
27262 if (!kbs) {
27263 ret = -ENOMEM;
27264@@ -361,6 +359,9 @@ do_kdgkb_ioctl(int cmd, struct kbsentry
27265 kfree(kbs);
27266 return ((p && *p) ? -EOVERFLOW : 0);
27267 case KDSKBSENT:
27268+ if (!capable(CAP_SYS_TTY_CONFIG))
27269+ perm = 0;
27270+
27271 if (!perm) {
27272 ret = -EPERM;
27273 goto reterr;
27274diff -urNp linux-2.6.32.41/drivers/cpufreq/cpufreq.c linux-2.6.32.41/drivers/cpufreq/cpufreq.c
27275--- linux-2.6.32.41/drivers/cpufreq/cpufreq.c 2011-03-27 14:31:47.000000000 -0400
27276+++ linux-2.6.32.41/drivers/cpufreq/cpufreq.c 2011-04-17 15:56:46.000000000 -0400
27277@@ -750,7 +750,7 @@ static void cpufreq_sysfs_release(struct
27278 complete(&policy->kobj_unregister);
27279 }
27280
27281-static struct sysfs_ops sysfs_ops = {
27282+static const struct sysfs_ops sysfs_ops = {
27283 .show = show,
27284 .store = store,
27285 };
27286diff -urNp linux-2.6.32.41/drivers/cpuidle/sysfs.c linux-2.6.32.41/drivers/cpuidle/sysfs.c
27287--- linux-2.6.32.41/drivers/cpuidle/sysfs.c 2011-03-27 14:31:47.000000000 -0400
27288+++ linux-2.6.32.41/drivers/cpuidle/sysfs.c 2011-04-17 15:56:46.000000000 -0400
27289@@ -191,7 +191,7 @@ static ssize_t cpuidle_store(struct kobj
27290 return ret;
27291 }
27292
27293-static struct sysfs_ops cpuidle_sysfs_ops = {
27294+static const struct sysfs_ops cpuidle_sysfs_ops = {
27295 .show = cpuidle_show,
27296 .store = cpuidle_store,
27297 };
27298@@ -277,7 +277,7 @@ static ssize_t cpuidle_state_show(struct
27299 return ret;
27300 }
27301
27302-static struct sysfs_ops cpuidle_state_sysfs_ops = {
27303+static const struct sysfs_ops cpuidle_state_sysfs_ops = {
27304 .show = cpuidle_state_show,
27305 };
27306
27307@@ -294,7 +294,7 @@ static struct kobj_type ktype_state_cpui
27308 .release = cpuidle_state_sysfs_release,
27309 };
27310
27311-static void inline cpuidle_free_state_kobj(struct cpuidle_device *device, int i)
27312+static inline void cpuidle_free_state_kobj(struct cpuidle_device *device, int i)
27313 {
27314 kobject_put(&device->kobjs[i]->kobj);
27315 wait_for_completion(&device->kobjs[i]->kobj_unregister);
27316diff -urNp linux-2.6.32.41/drivers/crypto/hifn_795x.c linux-2.6.32.41/drivers/crypto/hifn_795x.c
27317--- linux-2.6.32.41/drivers/crypto/hifn_795x.c 2011-03-27 14:31:47.000000000 -0400
27318+++ linux-2.6.32.41/drivers/crypto/hifn_795x.c 2011-05-16 21:46:57.000000000 -0400
27319@@ -1655,6 +1655,8 @@ static int hifn_test(struct hifn_device
27320 0xCA, 0x34, 0x2B, 0x2E};
27321 struct scatterlist sg;
27322
27323+ pax_track_stack();
27324+
27325 memset(src, 0, sizeof(src));
27326 memset(ctx.key, 0, sizeof(ctx.key));
27327
27328diff -urNp linux-2.6.32.41/drivers/crypto/padlock-aes.c linux-2.6.32.41/drivers/crypto/padlock-aes.c
27329--- linux-2.6.32.41/drivers/crypto/padlock-aes.c 2011-03-27 14:31:47.000000000 -0400
27330+++ linux-2.6.32.41/drivers/crypto/padlock-aes.c 2011-05-16 21:46:57.000000000 -0400
27331@@ -108,6 +108,8 @@ static int aes_set_key(struct crypto_tfm
27332 struct crypto_aes_ctx gen_aes;
27333 int cpu;
27334
27335+ pax_track_stack();
27336+
27337 if (key_len % 8) {
27338 *flags |= CRYPTO_TFM_RES_BAD_KEY_LEN;
27339 return -EINVAL;
27340diff -urNp linux-2.6.32.41/drivers/dma/ioat/dma.c linux-2.6.32.41/drivers/dma/ioat/dma.c
27341--- linux-2.6.32.41/drivers/dma/ioat/dma.c 2011-03-27 14:31:47.000000000 -0400
27342+++ linux-2.6.32.41/drivers/dma/ioat/dma.c 2011-04-17 15:56:46.000000000 -0400
27343@@ -1146,7 +1146,7 @@ ioat_attr_show(struct kobject *kobj, str
27344 return entry->show(&chan->common, page);
27345 }
27346
27347-struct sysfs_ops ioat_sysfs_ops = {
27348+const struct sysfs_ops ioat_sysfs_ops = {
27349 .show = ioat_attr_show,
27350 };
27351
27352diff -urNp linux-2.6.32.41/drivers/dma/ioat/dma.h linux-2.6.32.41/drivers/dma/ioat/dma.h
27353--- linux-2.6.32.41/drivers/dma/ioat/dma.h 2011-03-27 14:31:47.000000000 -0400
27354+++ linux-2.6.32.41/drivers/dma/ioat/dma.h 2011-04-17 15:56:46.000000000 -0400
27355@@ -347,7 +347,7 @@ bool ioat_cleanup_preamble(struct ioat_c
27356 unsigned long *phys_complete);
27357 void ioat_kobject_add(struct ioatdma_device *device, struct kobj_type *type);
27358 void ioat_kobject_del(struct ioatdma_device *device);
27359-extern struct sysfs_ops ioat_sysfs_ops;
27360+extern const struct sysfs_ops ioat_sysfs_ops;
27361 extern struct ioat_sysfs_entry ioat_version_attr;
27362 extern struct ioat_sysfs_entry ioat_cap_attr;
27363 #endif /* IOATDMA_H */
27364diff -urNp linux-2.6.32.41/drivers/edac/edac_device_sysfs.c linux-2.6.32.41/drivers/edac/edac_device_sysfs.c
27365--- linux-2.6.32.41/drivers/edac/edac_device_sysfs.c 2011-03-27 14:31:47.000000000 -0400
27366+++ linux-2.6.32.41/drivers/edac/edac_device_sysfs.c 2011-04-17 15:56:46.000000000 -0400
27367@@ -137,7 +137,7 @@ static ssize_t edac_dev_ctl_info_store(s
27368 }
27369
27370 /* edac_dev file operations for an 'ctl_info' */
27371-static struct sysfs_ops device_ctl_info_ops = {
27372+static const struct sysfs_ops device_ctl_info_ops = {
27373 .show = edac_dev_ctl_info_show,
27374 .store = edac_dev_ctl_info_store
27375 };
27376@@ -373,7 +373,7 @@ static ssize_t edac_dev_instance_store(s
27377 }
27378
27379 /* edac_dev file operations for an 'instance' */
27380-static struct sysfs_ops device_instance_ops = {
27381+static const struct sysfs_ops device_instance_ops = {
27382 .show = edac_dev_instance_show,
27383 .store = edac_dev_instance_store
27384 };
27385@@ -476,7 +476,7 @@ static ssize_t edac_dev_block_store(stru
27386 }
27387
27388 /* edac_dev file operations for a 'block' */
27389-static struct sysfs_ops device_block_ops = {
27390+static const struct sysfs_ops device_block_ops = {
27391 .show = edac_dev_block_show,
27392 .store = edac_dev_block_store
27393 };
27394diff -urNp linux-2.6.32.41/drivers/edac/edac_mc_sysfs.c linux-2.6.32.41/drivers/edac/edac_mc_sysfs.c
27395--- linux-2.6.32.41/drivers/edac/edac_mc_sysfs.c 2011-03-27 14:31:47.000000000 -0400
27396+++ linux-2.6.32.41/drivers/edac/edac_mc_sysfs.c 2011-04-17 15:56:46.000000000 -0400
27397@@ -245,7 +245,7 @@ static ssize_t csrowdev_store(struct kob
27398 return -EIO;
27399 }
27400
27401-static struct sysfs_ops csrowfs_ops = {
27402+static const struct sysfs_ops csrowfs_ops = {
27403 .show = csrowdev_show,
27404 .store = csrowdev_store
27405 };
27406@@ -575,7 +575,7 @@ static ssize_t mcidev_store(struct kobje
27407 }
27408
27409 /* Intermediate show/store table */
27410-static struct sysfs_ops mci_ops = {
27411+static const struct sysfs_ops mci_ops = {
27412 .show = mcidev_show,
27413 .store = mcidev_store
27414 };
27415diff -urNp linux-2.6.32.41/drivers/edac/edac_pci_sysfs.c linux-2.6.32.41/drivers/edac/edac_pci_sysfs.c
27416--- linux-2.6.32.41/drivers/edac/edac_pci_sysfs.c 2011-03-27 14:31:47.000000000 -0400
27417+++ linux-2.6.32.41/drivers/edac/edac_pci_sysfs.c 2011-05-04 17:56:20.000000000 -0400
27418@@ -25,8 +25,8 @@ static int edac_pci_log_pe = 1; /* log
27419 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
27420 static int edac_pci_poll_msec = 1000; /* one second workq period */
27421
27422-static atomic_t pci_parity_count = ATOMIC_INIT(0);
27423-static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
27424+static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
27425+static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
27426
27427 static struct kobject *edac_pci_top_main_kobj;
27428 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
27429@@ -121,7 +121,7 @@ static ssize_t edac_pci_instance_store(s
27430 }
27431
27432 /* fs_ops table */
27433-static struct sysfs_ops pci_instance_ops = {
27434+static const struct sysfs_ops pci_instance_ops = {
27435 .show = edac_pci_instance_show,
27436 .store = edac_pci_instance_store
27437 };
27438@@ -261,7 +261,7 @@ static ssize_t edac_pci_dev_store(struct
27439 return -EIO;
27440 }
27441
27442-static struct sysfs_ops edac_pci_sysfs_ops = {
27443+static const struct sysfs_ops edac_pci_sysfs_ops = {
27444 .show = edac_pci_dev_show,
27445 .store = edac_pci_dev_store
27446 };
27447@@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(str
27448 edac_printk(KERN_CRIT, EDAC_PCI,
27449 "Signaled System Error on %s\n",
27450 pci_name(dev));
27451- atomic_inc(&pci_nonparity_count);
27452+ atomic_inc_unchecked(&pci_nonparity_count);
27453 }
27454
27455 if (status & (PCI_STATUS_PARITY)) {
27456@@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(str
27457 "Master Data Parity Error on %s\n",
27458 pci_name(dev));
27459
27460- atomic_inc(&pci_parity_count);
27461+ atomic_inc_unchecked(&pci_parity_count);
27462 }
27463
27464 if (status & (PCI_STATUS_DETECTED_PARITY)) {
27465@@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(str
27466 "Detected Parity Error on %s\n",
27467 pci_name(dev));
27468
27469- atomic_inc(&pci_parity_count);
27470+ atomic_inc_unchecked(&pci_parity_count);
27471 }
27472 }
27473
27474@@ -616,7 +616,7 @@ static void edac_pci_dev_parity_test(str
27475 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
27476 "Signaled System Error on %s\n",
27477 pci_name(dev));
27478- atomic_inc(&pci_nonparity_count);
27479+ atomic_inc_unchecked(&pci_nonparity_count);
27480 }
27481
27482 if (status & (PCI_STATUS_PARITY)) {
27483@@ -624,7 +624,7 @@ static void edac_pci_dev_parity_test(str
27484 "Master Data Parity Error on "
27485 "%s\n", pci_name(dev));
27486
27487- atomic_inc(&pci_parity_count);
27488+ atomic_inc_unchecked(&pci_parity_count);
27489 }
27490
27491 if (status & (PCI_STATUS_DETECTED_PARITY)) {
27492@@ -632,7 +632,7 @@ static void edac_pci_dev_parity_test(str
27493 "Detected Parity Error on %s\n",
27494 pci_name(dev));
27495
27496- atomic_inc(&pci_parity_count);
27497+ atomic_inc_unchecked(&pci_parity_count);
27498 }
27499 }
27500 }
27501@@ -674,7 +674,7 @@ void edac_pci_do_parity_check(void)
27502 if (!check_pci_errors)
27503 return;
27504
27505- before_count = atomic_read(&pci_parity_count);
27506+ before_count = atomic_read_unchecked(&pci_parity_count);
27507
27508 /* scan all PCI devices looking for a Parity Error on devices and
27509 * bridges.
27510@@ -686,7 +686,7 @@ void edac_pci_do_parity_check(void)
27511 /* Only if operator has selected panic on PCI Error */
27512 if (edac_pci_get_panic_on_pe()) {
27513 /* If the count is different 'after' from 'before' */
27514- if (before_count != atomic_read(&pci_parity_count))
27515+ if (before_count != atomic_read_unchecked(&pci_parity_count))
27516 panic("EDAC: PCI Parity Error");
27517 }
27518 }
27519diff -urNp linux-2.6.32.41/drivers/firewire/core-cdev.c linux-2.6.32.41/drivers/firewire/core-cdev.c
27520--- linux-2.6.32.41/drivers/firewire/core-cdev.c 2011-03-27 14:31:47.000000000 -0400
27521+++ linux-2.6.32.41/drivers/firewire/core-cdev.c 2011-04-17 15:56:46.000000000 -0400
27522@@ -1141,8 +1141,7 @@ static int init_iso_resource(struct clie
27523 int ret;
27524
27525 if ((request->channels == 0 && request->bandwidth == 0) ||
27526- request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL ||
27527- request->bandwidth < 0)
27528+ request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL)
27529 return -EINVAL;
27530
27531 r = kmalloc(sizeof(*r), GFP_KERNEL);
27532diff -urNp linux-2.6.32.41/drivers/firewire/core-transaction.c linux-2.6.32.41/drivers/firewire/core-transaction.c
27533--- linux-2.6.32.41/drivers/firewire/core-transaction.c 2011-03-27 14:31:47.000000000 -0400
27534+++ linux-2.6.32.41/drivers/firewire/core-transaction.c 2011-05-16 21:46:57.000000000 -0400
27535@@ -36,6 +36,7 @@
27536 #include <linux/string.h>
27537 #include <linux/timer.h>
27538 #include <linux/types.h>
27539+#include <linux/sched.h>
27540
27541 #include <asm/byteorder.h>
27542
27543@@ -344,6 +345,8 @@ int fw_run_transaction(struct fw_card *c
27544 struct transaction_callback_data d;
27545 struct fw_transaction t;
27546
27547+ pax_track_stack();
27548+
27549 init_completion(&d.done);
27550 d.payload = payload;
27551 fw_send_request(card, &t, tcode, destination_id, generation, speed,
27552diff -urNp linux-2.6.32.41/drivers/firmware/dmi_scan.c linux-2.6.32.41/drivers/firmware/dmi_scan.c
27553--- linux-2.6.32.41/drivers/firmware/dmi_scan.c 2011-03-27 14:31:47.000000000 -0400
27554+++ linux-2.6.32.41/drivers/firmware/dmi_scan.c 2011-04-17 15:56:46.000000000 -0400
27555@@ -391,11 +391,6 @@ void __init dmi_scan_machine(void)
27556 }
27557 }
27558 else {
27559- /*
27560- * no iounmap() for that ioremap(); it would be a no-op, but
27561- * it's so early in setup that sucker gets confused into doing
27562- * what it shouldn't if we actually call it.
27563- */
27564 p = dmi_ioremap(0xF0000, 0x10000);
27565 if (p == NULL)
27566 goto error;
27567diff -urNp linux-2.6.32.41/drivers/firmware/edd.c linux-2.6.32.41/drivers/firmware/edd.c
27568--- linux-2.6.32.41/drivers/firmware/edd.c 2011-03-27 14:31:47.000000000 -0400
27569+++ linux-2.6.32.41/drivers/firmware/edd.c 2011-04-17 15:56:46.000000000 -0400
27570@@ -122,7 +122,7 @@ edd_attr_show(struct kobject * kobj, str
27571 return ret;
27572 }
27573
27574-static struct sysfs_ops edd_attr_ops = {
27575+static const struct sysfs_ops edd_attr_ops = {
27576 .show = edd_attr_show,
27577 };
27578
27579diff -urNp linux-2.6.32.41/drivers/firmware/efivars.c linux-2.6.32.41/drivers/firmware/efivars.c
27580--- linux-2.6.32.41/drivers/firmware/efivars.c 2011-03-27 14:31:47.000000000 -0400
27581+++ linux-2.6.32.41/drivers/firmware/efivars.c 2011-04-17 15:56:46.000000000 -0400
27582@@ -362,7 +362,7 @@ static ssize_t efivar_attr_store(struct
27583 return ret;
27584 }
27585
27586-static struct sysfs_ops efivar_attr_ops = {
27587+static const struct sysfs_ops efivar_attr_ops = {
27588 .show = efivar_attr_show,
27589 .store = efivar_attr_store,
27590 };
27591diff -urNp linux-2.6.32.41/drivers/firmware/iscsi_ibft.c linux-2.6.32.41/drivers/firmware/iscsi_ibft.c
27592--- linux-2.6.32.41/drivers/firmware/iscsi_ibft.c 2011-03-27 14:31:47.000000000 -0400
27593+++ linux-2.6.32.41/drivers/firmware/iscsi_ibft.c 2011-04-17 15:56:46.000000000 -0400
27594@@ -525,7 +525,7 @@ static ssize_t ibft_show_attribute(struc
27595 return ret;
27596 }
27597
27598-static struct sysfs_ops ibft_attr_ops = {
27599+static const struct sysfs_ops ibft_attr_ops = {
27600 .show = ibft_show_attribute,
27601 };
27602
27603diff -urNp linux-2.6.32.41/drivers/firmware/memmap.c linux-2.6.32.41/drivers/firmware/memmap.c
27604--- linux-2.6.32.41/drivers/firmware/memmap.c 2011-03-27 14:31:47.000000000 -0400
27605+++ linux-2.6.32.41/drivers/firmware/memmap.c 2011-04-17 15:56:46.000000000 -0400
27606@@ -74,7 +74,7 @@ static struct attribute *def_attrs[] = {
27607 NULL
27608 };
27609
27610-static struct sysfs_ops memmap_attr_ops = {
27611+static const struct sysfs_ops memmap_attr_ops = {
27612 .show = memmap_attr_show,
27613 };
27614
27615diff -urNp linux-2.6.32.41/drivers/gpio/vr41xx_giu.c linux-2.6.32.41/drivers/gpio/vr41xx_giu.c
27616--- linux-2.6.32.41/drivers/gpio/vr41xx_giu.c 2011-03-27 14:31:47.000000000 -0400
27617+++ linux-2.6.32.41/drivers/gpio/vr41xx_giu.c 2011-05-04 17:56:28.000000000 -0400
27618@@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
27619 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
27620 maskl, pendl, maskh, pendh);
27621
27622- atomic_inc(&irq_err_count);
27623+ atomic_inc_unchecked(&irq_err_count);
27624
27625 return -EINVAL;
27626 }
27627diff -urNp linux-2.6.32.41/drivers/gpu/drm/drm_crtc_helper.c linux-2.6.32.41/drivers/gpu/drm/drm_crtc_helper.c
27628--- linux-2.6.32.41/drivers/gpu/drm/drm_crtc_helper.c 2011-03-27 14:31:47.000000000 -0400
27629+++ linux-2.6.32.41/drivers/gpu/drm/drm_crtc_helper.c 2011-05-16 21:46:57.000000000 -0400
27630@@ -573,7 +573,7 @@ static bool drm_encoder_crtc_ok(struct d
27631 struct drm_crtc *tmp;
27632 int crtc_mask = 1;
27633
27634- WARN(!crtc, "checking null crtc?");
27635+ BUG_ON(!crtc);
27636
27637 dev = crtc->dev;
27638
27639@@ -642,6 +642,8 @@ bool drm_crtc_helper_set_mode(struct drm
27640
27641 adjusted_mode = drm_mode_duplicate(dev, mode);
27642
27643+ pax_track_stack();
27644+
27645 crtc->enabled = drm_helper_crtc_in_use(crtc);
27646
27647 if (!crtc->enabled)
27648diff -urNp linux-2.6.32.41/drivers/gpu/drm/drm_drv.c linux-2.6.32.41/drivers/gpu/drm/drm_drv.c
27649--- linux-2.6.32.41/drivers/gpu/drm/drm_drv.c 2011-03-27 14:31:47.000000000 -0400
27650+++ linux-2.6.32.41/drivers/gpu/drm/drm_drv.c 2011-04-17 15:56:46.000000000 -0400
27651@@ -417,7 +417,7 @@ int drm_ioctl(struct inode *inode, struc
27652 char *kdata = NULL;
27653
27654 atomic_inc(&dev->ioctl_count);
27655- atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
27656+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
27657 ++file_priv->ioctl_count;
27658
27659 DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
27660diff -urNp linux-2.6.32.41/drivers/gpu/drm/drm_fops.c linux-2.6.32.41/drivers/gpu/drm/drm_fops.c
27661--- linux-2.6.32.41/drivers/gpu/drm/drm_fops.c 2011-03-27 14:31:47.000000000 -0400
27662+++ linux-2.6.32.41/drivers/gpu/drm/drm_fops.c 2011-04-17 15:56:46.000000000 -0400
27663@@ -66,7 +66,7 @@ static int drm_setup(struct drm_device *
27664 }
27665
27666 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
27667- atomic_set(&dev->counts[i], 0);
27668+ atomic_set_unchecked(&dev->counts[i], 0);
27669
27670 dev->sigdata.lock = NULL;
27671
27672@@ -130,9 +130,9 @@ int drm_open(struct inode *inode, struct
27673
27674 retcode = drm_open_helper(inode, filp, dev);
27675 if (!retcode) {
27676- atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
27677+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
27678 spin_lock(&dev->count_lock);
27679- if (!dev->open_count++) {
27680+ if (local_inc_return(&dev->open_count) == 1) {
27681 spin_unlock(&dev->count_lock);
27682 retcode = drm_setup(dev);
27683 goto out;
27684@@ -435,7 +435,7 @@ int drm_release(struct inode *inode, str
27685
27686 lock_kernel();
27687
27688- DRM_DEBUG("open_count = %d\n", dev->open_count);
27689+ DRM_DEBUG("open_count = %d\n", local_read(&dev->open_count));
27690
27691 if (dev->driver->preclose)
27692 dev->driver->preclose(dev, file_priv);
27693@@ -447,7 +447,7 @@ int drm_release(struct inode *inode, str
27694 DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
27695 task_pid_nr(current),
27696 (long)old_encode_dev(file_priv->minor->device),
27697- dev->open_count);
27698+ local_read(&dev->open_count));
27699
27700 /* if the master has gone away we can't do anything with the lock */
27701 if (file_priv->minor->master)
27702@@ -524,9 +524,9 @@ int drm_release(struct inode *inode, str
27703 * End inline drm_release
27704 */
27705
27706- atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
27707+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
27708 spin_lock(&dev->count_lock);
27709- if (!--dev->open_count) {
27710+ if (local_dec_and_test(&dev->open_count)) {
27711 if (atomic_read(&dev->ioctl_count)) {
27712 DRM_ERROR("Device busy: %d\n",
27713 atomic_read(&dev->ioctl_count));
27714diff -urNp linux-2.6.32.41/drivers/gpu/drm/drm_gem.c linux-2.6.32.41/drivers/gpu/drm/drm_gem.c
27715--- linux-2.6.32.41/drivers/gpu/drm/drm_gem.c 2011-03-27 14:31:47.000000000 -0400
27716+++ linux-2.6.32.41/drivers/gpu/drm/drm_gem.c 2011-04-17 15:56:46.000000000 -0400
27717@@ -83,11 +83,11 @@ drm_gem_init(struct drm_device *dev)
27718 spin_lock_init(&dev->object_name_lock);
27719 idr_init(&dev->object_name_idr);
27720 atomic_set(&dev->object_count, 0);
27721- atomic_set(&dev->object_memory, 0);
27722+ atomic_set_unchecked(&dev->object_memory, 0);
27723 atomic_set(&dev->pin_count, 0);
27724- atomic_set(&dev->pin_memory, 0);
27725+ atomic_set_unchecked(&dev->pin_memory, 0);
27726 atomic_set(&dev->gtt_count, 0);
27727- atomic_set(&dev->gtt_memory, 0);
27728+ atomic_set_unchecked(&dev->gtt_memory, 0);
27729
27730 mm = kzalloc(sizeof(struct drm_gem_mm), GFP_KERNEL);
27731 if (!mm) {
27732@@ -150,7 +150,7 @@ drm_gem_object_alloc(struct drm_device *
27733 goto fput;
27734 }
27735 atomic_inc(&dev->object_count);
27736- atomic_add(obj->size, &dev->object_memory);
27737+ atomic_add_unchecked(obj->size, &dev->object_memory);
27738 return obj;
27739 fput:
27740 fput(obj->filp);
27741@@ -429,7 +429,7 @@ drm_gem_object_free(struct kref *kref)
27742
27743 fput(obj->filp);
27744 atomic_dec(&dev->object_count);
27745- atomic_sub(obj->size, &dev->object_memory);
27746+ atomic_sub_unchecked(obj->size, &dev->object_memory);
27747 kfree(obj);
27748 }
27749 EXPORT_SYMBOL(drm_gem_object_free);
27750diff -urNp linux-2.6.32.41/drivers/gpu/drm/drm_info.c linux-2.6.32.41/drivers/gpu/drm/drm_info.c
27751--- linux-2.6.32.41/drivers/gpu/drm/drm_info.c 2011-03-27 14:31:47.000000000 -0400
27752+++ linux-2.6.32.41/drivers/gpu/drm/drm_info.c 2011-04-17 15:56:46.000000000 -0400
27753@@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void
27754 struct drm_local_map *map;
27755 struct drm_map_list *r_list;
27756
27757- /* Hardcoded from _DRM_FRAME_BUFFER,
27758- _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
27759- _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
27760- const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
27761+ static const char * const types[] = {
27762+ [_DRM_FRAME_BUFFER] = "FB",
27763+ [_DRM_REGISTERS] = "REG",
27764+ [_DRM_SHM] = "SHM",
27765+ [_DRM_AGP] = "AGP",
27766+ [_DRM_SCATTER_GATHER] = "SG",
27767+ [_DRM_CONSISTENT] = "PCI",
27768+ [_DRM_GEM] = "GEM" };
27769 const char *type;
27770 int i;
27771
27772@@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void
27773 map = r_list->map;
27774 if (!map)
27775 continue;
27776- if (map->type < 0 || map->type > 5)
27777+ if (map->type >= ARRAY_SIZE(types))
27778 type = "??";
27779 else
27780 type = types[map->type];
27781@@ -265,10 +269,10 @@ int drm_gem_object_info(struct seq_file
27782 struct drm_device *dev = node->minor->dev;
27783
27784 seq_printf(m, "%d objects\n", atomic_read(&dev->object_count));
27785- seq_printf(m, "%d object bytes\n", atomic_read(&dev->object_memory));
27786+ seq_printf(m, "%d object bytes\n", atomic_read_unchecked(&dev->object_memory));
27787 seq_printf(m, "%d pinned\n", atomic_read(&dev->pin_count));
27788- seq_printf(m, "%d pin bytes\n", atomic_read(&dev->pin_memory));
27789- seq_printf(m, "%d gtt bytes\n", atomic_read(&dev->gtt_memory));
27790+ seq_printf(m, "%d pin bytes\n", atomic_read_unchecked(&dev->pin_memory));
27791+ seq_printf(m, "%d gtt bytes\n", atomic_read_unchecked(&dev->gtt_memory));
27792 seq_printf(m, "%d gtt total\n", dev->gtt_total);
27793 return 0;
27794 }
27795@@ -288,7 +292,11 @@ int drm_vma_info(struct seq_file *m, voi
27796 mutex_lock(&dev->struct_mutex);
27797 seq_printf(m, "vma use count: %d, high_memory = %p, 0x%08llx\n",
27798 atomic_read(&dev->vma_count),
27799+#ifdef CONFIG_GRKERNSEC_HIDESYM
27800+ NULL, 0);
27801+#else
27802 high_memory, (u64)virt_to_phys(high_memory));
27803+#endif
27804
27805 list_for_each_entry(pt, &dev->vmalist, head) {
27806 vma = pt->vma;
27807@@ -296,14 +304,23 @@ int drm_vma_info(struct seq_file *m, voi
27808 continue;
27809 seq_printf(m,
27810 "\n%5d 0x%08lx-0x%08lx %c%c%c%c%c%c 0x%08lx000",
27811- pt->pid, vma->vm_start, vma->vm_end,
27812+ pt->pid,
27813+#ifdef CONFIG_GRKERNSEC_HIDESYM
27814+ 0, 0,
27815+#else
27816+ vma->vm_start, vma->vm_end,
27817+#endif
27818 vma->vm_flags & VM_READ ? 'r' : '-',
27819 vma->vm_flags & VM_WRITE ? 'w' : '-',
27820 vma->vm_flags & VM_EXEC ? 'x' : '-',
27821 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
27822 vma->vm_flags & VM_LOCKED ? 'l' : '-',
27823 vma->vm_flags & VM_IO ? 'i' : '-',
27824+#ifdef CONFIG_GRKERNSEC_HIDESYM
27825+ 0);
27826+#else
27827 vma->vm_pgoff);
27828+#endif
27829
27830 #if defined(__i386__)
27831 pgprot = pgprot_val(vma->vm_page_prot);
27832diff -urNp linux-2.6.32.41/drivers/gpu/drm/drm_ioctl.c linux-2.6.32.41/drivers/gpu/drm/drm_ioctl.c
27833--- linux-2.6.32.41/drivers/gpu/drm/drm_ioctl.c 2011-03-27 14:31:47.000000000 -0400
27834+++ linux-2.6.32.41/drivers/gpu/drm/drm_ioctl.c 2011-04-17 15:56:46.000000000 -0400
27835@@ -283,7 +283,7 @@ int drm_getstats(struct drm_device *dev,
27836 stats->data[i].value =
27837 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
27838 else
27839- stats->data[i].value = atomic_read(&dev->counts[i]);
27840+ stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
27841 stats->data[i].type = dev->types[i];
27842 }
27843
27844diff -urNp linux-2.6.32.41/drivers/gpu/drm/drm_lock.c linux-2.6.32.41/drivers/gpu/drm/drm_lock.c
27845--- linux-2.6.32.41/drivers/gpu/drm/drm_lock.c 2011-03-27 14:31:47.000000000 -0400
27846+++ linux-2.6.32.41/drivers/gpu/drm/drm_lock.c 2011-04-17 15:56:46.000000000 -0400
27847@@ -87,7 +87,7 @@ int drm_lock(struct drm_device *dev, voi
27848 if (drm_lock_take(&master->lock, lock->context)) {
27849 master->lock.file_priv = file_priv;
27850 master->lock.lock_time = jiffies;
27851- atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
27852+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
27853 break; /* Got lock */
27854 }
27855
27856@@ -165,7 +165,7 @@ int drm_unlock(struct drm_device *dev, v
27857 return -EINVAL;
27858 }
27859
27860- atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
27861+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
27862
27863 /* kernel_context_switch isn't used by any of the x86 drm
27864 * modules but is required by the Sparc driver.
27865diff -urNp linux-2.6.32.41/drivers/gpu/drm/i810/i810_dma.c linux-2.6.32.41/drivers/gpu/drm/i810/i810_dma.c
27866--- linux-2.6.32.41/drivers/gpu/drm/i810/i810_dma.c 2011-03-27 14:31:47.000000000 -0400
27867+++ linux-2.6.32.41/drivers/gpu/drm/i810/i810_dma.c 2011-04-17 15:56:46.000000000 -0400
27868@@ -952,8 +952,8 @@ static int i810_dma_vertex(struct drm_de
27869 dma->buflist[vertex->idx],
27870 vertex->discard, vertex->used);
27871
27872- atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
27873- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
27874+ atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
27875+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
27876 sarea_priv->last_enqueue = dev_priv->counter - 1;
27877 sarea_priv->last_dispatch = (int)hw_status[5];
27878
27879@@ -1115,8 +1115,8 @@ static int i810_dma_mc(struct drm_device
27880 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
27881 mc->last_render);
27882
27883- atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
27884- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
27885+ atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
27886+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
27887 sarea_priv->last_enqueue = dev_priv->counter - 1;
27888 sarea_priv->last_dispatch = (int)hw_status[5];
27889
27890diff -urNp linux-2.6.32.41/drivers/gpu/drm/i810/i810_drv.h linux-2.6.32.41/drivers/gpu/drm/i810/i810_drv.h
27891--- linux-2.6.32.41/drivers/gpu/drm/i810/i810_drv.h 2011-03-27 14:31:47.000000000 -0400
27892+++ linux-2.6.32.41/drivers/gpu/drm/i810/i810_drv.h 2011-05-04 17:56:28.000000000 -0400
27893@@ -108,8 +108,8 @@ typedef struct drm_i810_private {
27894 int page_flipping;
27895
27896 wait_queue_head_t irq_queue;
27897- atomic_t irq_received;
27898- atomic_t irq_emitted;
27899+ atomic_unchecked_t irq_received;
27900+ atomic_unchecked_t irq_emitted;
27901
27902 int front_offset;
27903 } drm_i810_private_t;
27904diff -urNp linux-2.6.32.41/drivers/gpu/drm/i830/i830_drv.h linux-2.6.32.41/drivers/gpu/drm/i830/i830_drv.h
27905--- linux-2.6.32.41/drivers/gpu/drm/i830/i830_drv.h 2011-03-27 14:31:47.000000000 -0400
27906+++ linux-2.6.32.41/drivers/gpu/drm/i830/i830_drv.h 2011-05-04 17:56:28.000000000 -0400
27907@@ -115,8 +115,8 @@ typedef struct drm_i830_private {
27908 int page_flipping;
27909
27910 wait_queue_head_t irq_queue;
27911- atomic_t irq_received;
27912- atomic_t irq_emitted;
27913+ atomic_unchecked_t irq_received;
27914+ atomic_unchecked_t irq_emitted;
27915
27916 int use_mi_batchbuffer_start;
27917
27918diff -urNp linux-2.6.32.41/drivers/gpu/drm/i830/i830_irq.c linux-2.6.32.41/drivers/gpu/drm/i830/i830_irq.c
27919--- linux-2.6.32.41/drivers/gpu/drm/i830/i830_irq.c 2011-03-27 14:31:47.000000000 -0400
27920+++ linux-2.6.32.41/drivers/gpu/drm/i830/i830_irq.c 2011-05-04 17:56:28.000000000 -0400
27921@@ -47,7 +47,7 @@ irqreturn_t i830_driver_irq_handler(DRM_
27922
27923 I830_WRITE16(I830REG_INT_IDENTITY_R, temp);
27924
27925- atomic_inc(&dev_priv->irq_received);
27926+ atomic_inc_unchecked(&dev_priv->irq_received);
27927 wake_up_interruptible(&dev_priv->irq_queue);
27928
27929 return IRQ_HANDLED;
27930@@ -60,14 +60,14 @@ static int i830_emit_irq(struct drm_devi
27931
27932 DRM_DEBUG("%s\n", __func__);
27933
27934- atomic_inc(&dev_priv->irq_emitted);
27935+ atomic_inc_unchecked(&dev_priv->irq_emitted);
27936
27937 BEGIN_LP_RING(2);
27938 OUT_RING(0);
27939 OUT_RING(GFX_OP_USER_INTERRUPT);
27940 ADVANCE_LP_RING();
27941
27942- return atomic_read(&dev_priv->irq_emitted);
27943+ return atomic_read_unchecked(&dev_priv->irq_emitted);
27944 }
27945
27946 static int i830_wait_irq(struct drm_device * dev, int irq_nr)
27947@@ -79,7 +79,7 @@ static int i830_wait_irq(struct drm_devi
27948
27949 DRM_DEBUG("%s\n", __func__);
27950
27951- if (atomic_read(&dev_priv->irq_received) >= irq_nr)
27952+ if (atomic_read_unchecked(&dev_priv->irq_received) >= irq_nr)
27953 return 0;
27954
27955 dev_priv->sarea_priv->perf_boxes |= I830_BOX_WAIT;
27956@@ -88,7 +88,7 @@ static int i830_wait_irq(struct drm_devi
27957
27958 for (;;) {
27959 __set_current_state(TASK_INTERRUPTIBLE);
27960- if (atomic_read(&dev_priv->irq_received) >= irq_nr)
27961+ if (atomic_read_unchecked(&dev_priv->irq_received) >= irq_nr)
27962 break;
27963 if ((signed)(end - jiffies) <= 0) {
27964 DRM_ERROR("timeout iir %x imr %x ier %x hwstam %x\n",
27965@@ -163,8 +163,8 @@ void i830_driver_irq_preinstall(struct d
27966 I830_WRITE16(I830REG_HWSTAM, 0xffff);
27967 I830_WRITE16(I830REG_INT_MASK_R, 0x0);
27968 I830_WRITE16(I830REG_INT_ENABLE_R, 0x0);
27969- atomic_set(&dev_priv->irq_received, 0);
27970- atomic_set(&dev_priv->irq_emitted, 0);
27971+ atomic_set_unchecked(&dev_priv->irq_received, 0);
27972+ atomic_set_unchecked(&dev_priv->irq_emitted, 0);
27973 init_waitqueue_head(&dev_priv->irq_queue);
27974 }
27975
27976diff -urNp linux-2.6.32.41/drivers/gpu/drm/i915/dvo_ch7017.c linux-2.6.32.41/drivers/gpu/drm/i915/dvo_ch7017.c
27977--- linux-2.6.32.41/drivers/gpu/drm/i915/dvo_ch7017.c 2011-03-27 14:31:47.000000000 -0400
27978+++ linux-2.6.32.41/drivers/gpu/drm/i915/dvo_ch7017.c 2011-04-17 15:56:46.000000000 -0400
27979@@ -443,7 +443,7 @@ static void ch7017_destroy(struct intel_
27980 }
27981 }
27982
27983-struct intel_dvo_dev_ops ch7017_ops = {
27984+const struct intel_dvo_dev_ops ch7017_ops = {
27985 .init = ch7017_init,
27986 .detect = ch7017_detect,
27987 .mode_valid = ch7017_mode_valid,
27988diff -urNp linux-2.6.32.41/drivers/gpu/drm/i915/dvo_ch7xxx.c linux-2.6.32.41/drivers/gpu/drm/i915/dvo_ch7xxx.c
27989--- linux-2.6.32.41/drivers/gpu/drm/i915/dvo_ch7xxx.c 2011-03-27 14:31:47.000000000 -0400
27990+++ linux-2.6.32.41/drivers/gpu/drm/i915/dvo_ch7xxx.c 2011-04-17 15:56:46.000000000 -0400
27991@@ -356,7 +356,7 @@ static void ch7xxx_destroy(struct intel_
27992 }
27993 }
27994
27995-struct intel_dvo_dev_ops ch7xxx_ops = {
27996+const struct intel_dvo_dev_ops ch7xxx_ops = {
27997 .init = ch7xxx_init,
27998 .detect = ch7xxx_detect,
27999 .mode_valid = ch7xxx_mode_valid,
28000diff -urNp linux-2.6.32.41/drivers/gpu/drm/i915/dvo.h linux-2.6.32.41/drivers/gpu/drm/i915/dvo.h
28001--- linux-2.6.32.41/drivers/gpu/drm/i915/dvo.h 2011-03-27 14:31:47.000000000 -0400
28002+++ linux-2.6.32.41/drivers/gpu/drm/i915/dvo.h 2011-04-17 15:56:46.000000000 -0400
28003@@ -135,23 +135,23 @@ struct intel_dvo_dev_ops {
28004 *
28005 * \return singly-linked list of modes or NULL if no modes found.
28006 */
28007- struct drm_display_mode *(*get_modes)(struct intel_dvo_device *dvo);
28008+ struct drm_display_mode *(* const get_modes)(struct intel_dvo_device *dvo);
28009
28010 /**
28011 * Clean up driver-specific bits of the output
28012 */
28013- void (*destroy) (struct intel_dvo_device *dvo);
28014+ void (* const destroy) (struct intel_dvo_device *dvo);
28015
28016 /**
28017 * Debugging hook to dump device registers to log file
28018 */
28019- void (*dump_regs)(struct intel_dvo_device *dvo);
28020+ void (* const dump_regs)(struct intel_dvo_device *dvo);
28021 };
28022
28023-extern struct intel_dvo_dev_ops sil164_ops;
28024-extern struct intel_dvo_dev_ops ch7xxx_ops;
28025-extern struct intel_dvo_dev_ops ivch_ops;
28026-extern struct intel_dvo_dev_ops tfp410_ops;
28027-extern struct intel_dvo_dev_ops ch7017_ops;
28028+extern const struct intel_dvo_dev_ops sil164_ops;
28029+extern const struct intel_dvo_dev_ops ch7xxx_ops;
28030+extern const struct intel_dvo_dev_ops ivch_ops;
28031+extern const struct intel_dvo_dev_ops tfp410_ops;
28032+extern const struct intel_dvo_dev_ops ch7017_ops;
28033
28034 #endif /* _INTEL_DVO_H */
28035diff -urNp linux-2.6.32.41/drivers/gpu/drm/i915/dvo_ivch.c linux-2.6.32.41/drivers/gpu/drm/i915/dvo_ivch.c
28036--- linux-2.6.32.41/drivers/gpu/drm/i915/dvo_ivch.c 2011-03-27 14:31:47.000000000 -0400
28037+++ linux-2.6.32.41/drivers/gpu/drm/i915/dvo_ivch.c 2011-04-17 15:56:46.000000000 -0400
28038@@ -430,7 +430,7 @@ static void ivch_destroy(struct intel_dv
28039 }
28040 }
28041
28042-struct intel_dvo_dev_ops ivch_ops= {
28043+const struct intel_dvo_dev_ops ivch_ops= {
28044 .init = ivch_init,
28045 .dpms = ivch_dpms,
28046 .save = ivch_save,
28047diff -urNp linux-2.6.32.41/drivers/gpu/drm/i915/dvo_sil164.c linux-2.6.32.41/drivers/gpu/drm/i915/dvo_sil164.c
28048--- linux-2.6.32.41/drivers/gpu/drm/i915/dvo_sil164.c 2011-03-27 14:31:47.000000000 -0400
28049+++ linux-2.6.32.41/drivers/gpu/drm/i915/dvo_sil164.c 2011-04-17 15:56:46.000000000 -0400
28050@@ -290,7 +290,7 @@ static void sil164_destroy(struct intel_
28051 }
28052 }
28053
28054-struct intel_dvo_dev_ops sil164_ops = {
28055+const struct intel_dvo_dev_ops sil164_ops = {
28056 .init = sil164_init,
28057 .detect = sil164_detect,
28058 .mode_valid = sil164_mode_valid,
28059diff -urNp linux-2.6.32.41/drivers/gpu/drm/i915/dvo_tfp410.c linux-2.6.32.41/drivers/gpu/drm/i915/dvo_tfp410.c
28060--- linux-2.6.32.41/drivers/gpu/drm/i915/dvo_tfp410.c 2011-03-27 14:31:47.000000000 -0400
28061+++ linux-2.6.32.41/drivers/gpu/drm/i915/dvo_tfp410.c 2011-04-17 15:56:46.000000000 -0400
28062@@ -323,7 +323,7 @@ static void tfp410_destroy(struct intel_
28063 }
28064 }
28065
28066-struct intel_dvo_dev_ops tfp410_ops = {
28067+const struct intel_dvo_dev_ops tfp410_ops = {
28068 .init = tfp410_init,
28069 .detect = tfp410_detect,
28070 .mode_valid = tfp410_mode_valid,
28071diff -urNp linux-2.6.32.41/drivers/gpu/drm/i915/i915_debugfs.c linux-2.6.32.41/drivers/gpu/drm/i915/i915_debugfs.c
28072--- linux-2.6.32.41/drivers/gpu/drm/i915/i915_debugfs.c 2011-03-27 14:31:47.000000000 -0400
28073+++ linux-2.6.32.41/drivers/gpu/drm/i915/i915_debugfs.c 2011-05-04 17:56:28.000000000 -0400
28074@@ -192,7 +192,7 @@ static int i915_interrupt_info(struct se
28075 I915_READ(GTIMR));
28076 }
28077 seq_printf(m, "Interrupts received: %d\n",
28078- atomic_read(&dev_priv->irq_received));
28079+ atomic_read_unchecked(&dev_priv->irq_received));
28080 if (dev_priv->hw_status_page != NULL) {
28081 seq_printf(m, "Current sequence: %d\n",
28082 i915_get_gem_seqno(dev));
28083diff -urNp linux-2.6.32.41/drivers/gpu/drm/i915/i915_drv.c linux-2.6.32.41/drivers/gpu/drm/i915/i915_drv.c
28084--- linux-2.6.32.41/drivers/gpu/drm/i915/i915_drv.c 2011-03-27 14:31:47.000000000 -0400
28085+++ linux-2.6.32.41/drivers/gpu/drm/i915/i915_drv.c 2011-04-17 15:56:46.000000000 -0400
28086@@ -285,7 +285,7 @@ i915_pci_resume(struct pci_dev *pdev)
28087 return i915_resume(dev);
28088 }
28089
28090-static struct vm_operations_struct i915_gem_vm_ops = {
28091+static const struct vm_operations_struct i915_gem_vm_ops = {
28092 .fault = i915_gem_fault,
28093 .open = drm_gem_vm_open,
28094 .close = drm_gem_vm_close,
28095diff -urNp linux-2.6.32.41/drivers/gpu/drm/i915/i915_drv.h linux-2.6.32.41/drivers/gpu/drm/i915/i915_drv.h
28096--- linux-2.6.32.41/drivers/gpu/drm/i915/i915_drv.h 2011-03-27 14:31:47.000000000 -0400
28097+++ linux-2.6.32.41/drivers/gpu/drm/i915/i915_drv.h 2011-05-04 17:56:28.000000000 -0400
28098@@ -197,7 +197,7 @@ typedef struct drm_i915_private {
28099 int page_flipping;
28100
28101 wait_queue_head_t irq_queue;
28102- atomic_t irq_received;
28103+ atomic_unchecked_t irq_received;
28104 /** Protects user_irq_refcount and irq_mask_reg */
28105 spinlock_t user_irq_lock;
28106 /** Refcount for i915_user_irq_get() versus i915_user_irq_put(). */
28107diff -urNp linux-2.6.32.41/drivers/gpu/drm/i915/i915_gem.c linux-2.6.32.41/drivers/gpu/drm/i915/i915_gem.c
28108--- linux-2.6.32.41/drivers/gpu/drm/i915/i915_gem.c 2011-03-27 14:31:47.000000000 -0400
28109+++ linux-2.6.32.41/drivers/gpu/drm/i915/i915_gem.c 2011-04-17 15:56:46.000000000 -0400
28110@@ -102,7 +102,7 @@ i915_gem_get_aperture_ioctl(struct drm_d
28111
28112 args->aper_size = dev->gtt_total;
28113 args->aper_available_size = (args->aper_size -
28114- atomic_read(&dev->pin_memory));
28115+ atomic_read_unchecked(&dev->pin_memory));
28116
28117 return 0;
28118 }
28119@@ -492,6 +492,11 @@ i915_gem_pread_ioctl(struct drm_device *
28120 return -EINVAL;
28121 }
28122
28123+ if (!access_ok(VERIFY_WRITE, (char __user *) (uintptr_t)args->data_ptr, args->size)) {
28124+ drm_gem_object_unreference(obj);
28125+ return -EFAULT;
28126+ }
28127+
28128 if (i915_gem_object_needs_bit17_swizzle(obj)) {
28129 ret = i915_gem_shmem_pread_slow(dev, obj, args, file_priv);
28130 } else {
28131@@ -965,6 +970,11 @@ i915_gem_pwrite_ioctl(struct drm_device
28132 return -EINVAL;
28133 }
28134
28135+ if (!access_ok(VERIFY_READ, (char __user *) (uintptr_t)args->data_ptr, args->size)) {
28136+ drm_gem_object_unreference(obj);
28137+ return -EFAULT;
28138+ }
28139+
28140 /* We can only do the GTT pwrite on untiled buffers, as otherwise
28141 * it would end up going through the fenced access, and we'll get
28142 * different detiling behavior between reading and writing.
28143@@ -2054,7 +2064,7 @@ i915_gem_object_unbind(struct drm_gem_ob
28144
28145 if (obj_priv->gtt_space) {
28146 atomic_dec(&dev->gtt_count);
28147- atomic_sub(obj->size, &dev->gtt_memory);
28148+ atomic_sub_unchecked(obj->size, &dev->gtt_memory);
28149
28150 drm_mm_put_block(obj_priv->gtt_space);
28151 obj_priv->gtt_space = NULL;
28152@@ -2697,7 +2707,7 @@ i915_gem_object_bind_to_gtt(struct drm_g
28153 goto search_free;
28154 }
28155 atomic_inc(&dev->gtt_count);
28156- atomic_add(obj->size, &dev->gtt_memory);
28157+ atomic_add_unchecked(obj->size, &dev->gtt_memory);
28158
28159 /* Assert that the object is not currently in any GPU domain. As it
28160 * wasn't in the GTT, there shouldn't be any way it could have been in
28161@@ -3751,9 +3761,9 @@ i915_gem_execbuffer(struct drm_device *d
28162 "%d/%d gtt bytes\n",
28163 atomic_read(&dev->object_count),
28164 atomic_read(&dev->pin_count),
28165- atomic_read(&dev->object_memory),
28166- atomic_read(&dev->pin_memory),
28167- atomic_read(&dev->gtt_memory),
28168+ atomic_read_unchecked(&dev->object_memory),
28169+ atomic_read_unchecked(&dev->pin_memory),
28170+ atomic_read_unchecked(&dev->gtt_memory),
28171 dev->gtt_total);
28172 }
28173 goto err;
28174@@ -3985,7 +3995,7 @@ i915_gem_object_pin(struct drm_gem_objec
28175 */
28176 if (obj_priv->pin_count == 1) {
28177 atomic_inc(&dev->pin_count);
28178- atomic_add(obj->size, &dev->pin_memory);
28179+ atomic_add_unchecked(obj->size, &dev->pin_memory);
28180 if (!obj_priv->active &&
28181 (obj->write_domain & I915_GEM_GPU_DOMAINS) == 0 &&
28182 !list_empty(&obj_priv->list))
28183@@ -4018,7 +4028,7 @@ i915_gem_object_unpin(struct drm_gem_obj
28184 list_move_tail(&obj_priv->list,
28185 &dev_priv->mm.inactive_list);
28186 atomic_dec(&dev->pin_count);
28187- atomic_sub(obj->size, &dev->pin_memory);
28188+ atomic_sub_unchecked(obj->size, &dev->pin_memory);
28189 }
28190 i915_verify_inactive(dev, __FILE__, __LINE__);
28191 }
28192diff -urNp linux-2.6.32.41/drivers/gpu/drm/i915/i915_irq.c linux-2.6.32.41/drivers/gpu/drm/i915/i915_irq.c
28193--- linux-2.6.32.41/drivers/gpu/drm/i915/i915_irq.c 2011-03-27 14:31:47.000000000 -0400
28194+++ linux-2.6.32.41/drivers/gpu/drm/i915/i915_irq.c 2011-05-04 17:56:28.000000000 -0400
28195@@ -528,7 +528,7 @@ irqreturn_t i915_driver_irq_handler(DRM_
28196 int irq_received;
28197 int ret = IRQ_NONE;
28198
28199- atomic_inc(&dev_priv->irq_received);
28200+ atomic_inc_unchecked(&dev_priv->irq_received);
28201
28202 if (IS_IGDNG(dev))
28203 return igdng_irq_handler(dev);
28204@@ -1021,7 +1021,7 @@ void i915_driver_irq_preinstall(struct d
28205 {
28206 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
28207
28208- atomic_set(&dev_priv->irq_received, 0);
28209+ atomic_set_unchecked(&dev_priv->irq_received, 0);
28210
28211 INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func);
28212 INIT_WORK(&dev_priv->error_work, i915_error_work_func);
28213diff -urNp linux-2.6.32.41/drivers/gpu/drm/mga/mga_drv.h linux-2.6.32.41/drivers/gpu/drm/mga/mga_drv.h
28214--- linux-2.6.32.41/drivers/gpu/drm/mga/mga_drv.h 2011-03-27 14:31:47.000000000 -0400
28215+++ linux-2.6.32.41/drivers/gpu/drm/mga/mga_drv.h 2011-05-04 17:56:28.000000000 -0400
28216@@ -120,9 +120,9 @@ typedef struct drm_mga_private {
28217 u32 clear_cmd;
28218 u32 maccess;
28219
28220- atomic_t vbl_received; /**< Number of vblanks received. */
28221+ atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
28222 wait_queue_head_t fence_queue;
28223- atomic_t last_fence_retired;
28224+ atomic_unchecked_t last_fence_retired;
28225 u32 next_fence_to_post;
28226
28227 unsigned int fb_cpp;
28228diff -urNp linux-2.6.32.41/drivers/gpu/drm/mga/mga_irq.c linux-2.6.32.41/drivers/gpu/drm/mga/mga_irq.c
28229--- linux-2.6.32.41/drivers/gpu/drm/mga/mga_irq.c 2011-03-27 14:31:47.000000000 -0400
28230+++ linux-2.6.32.41/drivers/gpu/drm/mga/mga_irq.c 2011-05-04 17:56:28.000000000 -0400
28231@@ -44,7 +44,7 @@ u32 mga_get_vblank_counter(struct drm_de
28232 if (crtc != 0)
28233 return 0;
28234
28235- return atomic_read(&dev_priv->vbl_received);
28236+ return atomic_read_unchecked(&dev_priv->vbl_received);
28237 }
28238
28239
28240@@ -60,7 +60,7 @@ irqreturn_t mga_driver_irq_handler(DRM_I
28241 /* VBLANK interrupt */
28242 if (status & MGA_VLINEPEN) {
28243 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
28244- atomic_inc(&dev_priv->vbl_received);
28245+ atomic_inc_unchecked(&dev_priv->vbl_received);
28246 drm_handle_vblank(dev, 0);
28247 handled = 1;
28248 }
28249@@ -80,7 +80,7 @@ irqreturn_t mga_driver_irq_handler(DRM_I
28250 MGA_WRITE(MGA_PRIMEND, prim_end);
28251 }
28252
28253- atomic_inc(&dev_priv->last_fence_retired);
28254+ atomic_inc_unchecked(&dev_priv->last_fence_retired);
28255 DRM_WAKEUP(&dev_priv->fence_queue);
28256 handled = 1;
28257 }
28258@@ -131,7 +131,7 @@ int mga_driver_fence_wait(struct drm_dev
28259 * using fences.
28260 */
28261 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
28262- (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
28263+ (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
28264 - *sequence) <= (1 << 23)));
28265
28266 *sequence = cur_fence;
28267diff -urNp linux-2.6.32.41/drivers/gpu/drm/r128/r128_cce.c linux-2.6.32.41/drivers/gpu/drm/r128/r128_cce.c
28268--- linux-2.6.32.41/drivers/gpu/drm/r128/r128_cce.c 2011-03-27 14:31:47.000000000 -0400
28269+++ linux-2.6.32.41/drivers/gpu/drm/r128/r128_cce.c 2011-05-04 17:56:28.000000000 -0400
28270@@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_d
28271
28272 /* GH: Simple idle check.
28273 */
28274- atomic_set(&dev_priv->idle_count, 0);
28275+ atomic_set_unchecked(&dev_priv->idle_count, 0);
28276
28277 /* We don't support anything other than bus-mastering ring mode,
28278 * but the ring can be in either AGP or PCI space for the ring
28279diff -urNp linux-2.6.32.41/drivers/gpu/drm/r128/r128_drv.h linux-2.6.32.41/drivers/gpu/drm/r128/r128_drv.h
28280--- linux-2.6.32.41/drivers/gpu/drm/r128/r128_drv.h 2011-03-27 14:31:47.000000000 -0400
28281+++ linux-2.6.32.41/drivers/gpu/drm/r128/r128_drv.h 2011-05-04 17:56:28.000000000 -0400
28282@@ -90,14 +90,14 @@ typedef struct drm_r128_private {
28283 int is_pci;
28284 unsigned long cce_buffers_offset;
28285
28286- atomic_t idle_count;
28287+ atomic_unchecked_t idle_count;
28288
28289 int page_flipping;
28290 int current_page;
28291 u32 crtc_offset;
28292 u32 crtc_offset_cntl;
28293
28294- atomic_t vbl_received;
28295+ atomic_unchecked_t vbl_received;
28296
28297 u32 color_fmt;
28298 unsigned int front_offset;
28299diff -urNp linux-2.6.32.41/drivers/gpu/drm/r128/r128_irq.c linux-2.6.32.41/drivers/gpu/drm/r128/r128_irq.c
28300--- linux-2.6.32.41/drivers/gpu/drm/r128/r128_irq.c 2011-03-27 14:31:47.000000000 -0400
28301+++ linux-2.6.32.41/drivers/gpu/drm/r128/r128_irq.c 2011-05-04 17:56:28.000000000 -0400
28302@@ -42,7 +42,7 @@ u32 r128_get_vblank_counter(struct drm_d
28303 if (crtc != 0)
28304 return 0;
28305
28306- return atomic_read(&dev_priv->vbl_received);
28307+ return atomic_read_unchecked(&dev_priv->vbl_received);
28308 }
28309
28310 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
28311@@ -56,7 +56,7 @@ irqreturn_t r128_driver_irq_handler(DRM_
28312 /* VBLANK interrupt */
28313 if (status & R128_CRTC_VBLANK_INT) {
28314 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
28315- atomic_inc(&dev_priv->vbl_received);
28316+ atomic_inc_unchecked(&dev_priv->vbl_received);
28317 drm_handle_vblank(dev, 0);
28318 return IRQ_HANDLED;
28319 }
28320diff -urNp linux-2.6.32.41/drivers/gpu/drm/r128/r128_state.c linux-2.6.32.41/drivers/gpu/drm/r128/r128_state.c
28321--- linux-2.6.32.41/drivers/gpu/drm/r128/r128_state.c 2011-03-27 14:31:47.000000000 -0400
28322+++ linux-2.6.32.41/drivers/gpu/drm/r128/r128_state.c 2011-05-04 17:56:28.000000000 -0400
28323@@ -323,10 +323,10 @@ static void r128_clear_box(drm_r128_priv
28324
28325 static void r128_cce_performance_boxes(drm_r128_private_t * dev_priv)
28326 {
28327- if (atomic_read(&dev_priv->idle_count) == 0) {
28328+ if (atomic_read_unchecked(&dev_priv->idle_count) == 0) {
28329 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
28330 } else {
28331- atomic_set(&dev_priv->idle_count, 0);
28332+ atomic_set_unchecked(&dev_priv->idle_count, 0);
28333 }
28334 }
28335
28336diff -urNp linux-2.6.32.41/drivers/gpu/drm/radeon/atom.c linux-2.6.32.41/drivers/gpu/drm/radeon/atom.c
28337--- linux-2.6.32.41/drivers/gpu/drm/radeon/atom.c 2011-05-10 22:12:01.000000000 -0400
28338+++ linux-2.6.32.41/drivers/gpu/drm/radeon/atom.c 2011-05-16 21:46:57.000000000 -0400
28339@@ -1115,6 +1115,8 @@ struct atom_context *atom_parse(struct c
28340 char name[512];
28341 int i;
28342
28343+ pax_track_stack();
28344+
28345 ctx->card = card;
28346 ctx->bios = bios;
28347
28348diff -urNp linux-2.6.32.41/drivers/gpu/drm/radeon/mkregtable.c linux-2.6.32.41/drivers/gpu/drm/radeon/mkregtable.c
28349--- linux-2.6.32.41/drivers/gpu/drm/radeon/mkregtable.c 2011-03-27 14:31:47.000000000 -0400
28350+++ linux-2.6.32.41/drivers/gpu/drm/radeon/mkregtable.c 2011-04-17 15:56:46.000000000 -0400
28351@@ -637,14 +637,14 @@ static int parser_auth(struct table *t,
28352 regex_t mask_rex;
28353 regmatch_t match[4];
28354 char buf[1024];
28355- size_t end;
28356+ long end;
28357 int len;
28358 int done = 0;
28359 int r;
28360 unsigned o;
28361 struct offset *offset;
28362 char last_reg_s[10];
28363- int last_reg;
28364+ unsigned long last_reg;
28365
28366 if (regcomp
28367 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
28368diff -urNp linux-2.6.32.41/drivers/gpu/drm/radeon/radeon_atombios.c linux-2.6.32.41/drivers/gpu/drm/radeon/radeon_atombios.c
28369--- linux-2.6.32.41/drivers/gpu/drm/radeon/radeon_atombios.c 2011-03-27 14:31:47.000000000 -0400
28370+++ linux-2.6.32.41/drivers/gpu/drm/radeon/radeon_atombios.c 2011-05-16 21:46:57.000000000 -0400
28371@@ -275,6 +275,8 @@ bool radeon_get_atom_connector_info_from
28372 bool linkb;
28373 struct radeon_i2c_bus_rec ddc_bus;
28374
28375+ pax_track_stack();
28376+
28377 atom_parse_data_header(ctx, index, &size, &frev, &crev, &data_offset);
28378
28379 if (data_offset == 0)
28380@@ -520,13 +522,13 @@ static uint16_t atombios_get_connector_o
28381 }
28382 }
28383
28384-struct bios_connector {
28385+static struct bios_connector {
28386 bool valid;
28387 uint16_t line_mux;
28388 uint16_t devices;
28389 int connector_type;
28390 struct radeon_i2c_bus_rec ddc_bus;
28391-};
28392+} bios_connectors[ATOM_MAX_SUPPORTED_DEVICE];
28393
28394 bool radeon_get_atom_connector_info_from_supported_devices_table(struct
28395 drm_device
28396@@ -542,7 +544,6 @@ bool radeon_get_atom_connector_info_from
28397 uint8_t dac;
28398 union atom_supported_devices *supported_devices;
28399 int i, j;
28400- struct bios_connector bios_connectors[ATOM_MAX_SUPPORTED_DEVICE];
28401
28402 atom_parse_data_header(ctx, index, &size, &frev, &crev, &data_offset);
28403
28404diff -urNp linux-2.6.32.41/drivers/gpu/drm/radeon/radeon_display.c linux-2.6.32.41/drivers/gpu/drm/radeon/radeon_display.c
28405--- linux-2.6.32.41/drivers/gpu/drm/radeon/radeon_display.c 2011-03-27 14:31:47.000000000 -0400
28406+++ linux-2.6.32.41/drivers/gpu/drm/radeon/radeon_display.c 2011-04-17 15:56:46.000000000 -0400
28407@@ -482,7 +482,7 @@ void radeon_compute_pll(struct radeon_pl
28408
28409 if (flags & RADEON_PLL_PREFER_CLOSEST_LOWER) {
28410 error = freq - current_freq;
28411- error = error < 0 ? 0xffffffff : error;
28412+ error = (int32_t)error < 0 ? 0xffffffff : error;
28413 } else
28414 error = abs(current_freq - freq);
28415 vco_diff = abs(vco - best_vco);
28416diff -urNp linux-2.6.32.41/drivers/gpu/drm/radeon/radeon_drv.h linux-2.6.32.41/drivers/gpu/drm/radeon/radeon_drv.h
28417--- linux-2.6.32.41/drivers/gpu/drm/radeon/radeon_drv.h 2011-03-27 14:31:47.000000000 -0400
28418+++ linux-2.6.32.41/drivers/gpu/drm/radeon/radeon_drv.h 2011-05-04 17:56:28.000000000 -0400
28419@@ -253,7 +253,7 @@ typedef struct drm_radeon_private {
28420
28421 /* SW interrupt */
28422 wait_queue_head_t swi_queue;
28423- atomic_t swi_emitted;
28424+ atomic_unchecked_t swi_emitted;
28425 int vblank_crtc;
28426 uint32_t irq_enable_reg;
28427 uint32_t r500_disp_irq_reg;
28428diff -urNp linux-2.6.32.41/drivers/gpu/drm/radeon/radeon_fence.c linux-2.6.32.41/drivers/gpu/drm/radeon/radeon_fence.c
28429--- linux-2.6.32.41/drivers/gpu/drm/radeon/radeon_fence.c 2011-03-27 14:31:47.000000000 -0400
28430+++ linux-2.6.32.41/drivers/gpu/drm/radeon/radeon_fence.c 2011-05-04 17:56:28.000000000 -0400
28431@@ -47,7 +47,7 @@ int radeon_fence_emit(struct radeon_devi
28432 write_unlock_irqrestore(&rdev->fence_drv.lock, irq_flags);
28433 return 0;
28434 }
28435- fence->seq = atomic_add_return(1, &rdev->fence_drv.seq);
28436+ fence->seq = atomic_add_return_unchecked(1, &rdev->fence_drv.seq);
28437 if (!rdev->cp.ready) {
28438 /* FIXME: cp is not running assume everythings is done right
28439 * away
28440@@ -364,7 +364,7 @@ int radeon_fence_driver_init(struct rade
28441 return r;
28442 }
28443 WREG32(rdev->fence_drv.scratch_reg, 0);
28444- atomic_set(&rdev->fence_drv.seq, 0);
28445+ atomic_set_unchecked(&rdev->fence_drv.seq, 0);
28446 INIT_LIST_HEAD(&rdev->fence_drv.created);
28447 INIT_LIST_HEAD(&rdev->fence_drv.emited);
28448 INIT_LIST_HEAD(&rdev->fence_drv.signaled);
28449diff -urNp linux-2.6.32.41/drivers/gpu/drm/radeon/radeon.h linux-2.6.32.41/drivers/gpu/drm/radeon/radeon.h
28450--- linux-2.6.32.41/drivers/gpu/drm/radeon/radeon.h 2011-03-27 14:31:47.000000000 -0400
28451+++ linux-2.6.32.41/drivers/gpu/drm/radeon/radeon.h 2011-05-04 17:56:28.000000000 -0400
28452@@ -149,7 +149,7 @@ int radeon_pm_init(struct radeon_device
28453 */
28454 struct radeon_fence_driver {
28455 uint32_t scratch_reg;
28456- atomic_t seq;
28457+ atomic_unchecked_t seq;
28458 uint32_t last_seq;
28459 unsigned long count_timeout;
28460 wait_queue_head_t queue;
28461diff -urNp linux-2.6.32.41/drivers/gpu/drm/radeon/radeon_ioc32.c linux-2.6.32.41/drivers/gpu/drm/radeon/radeon_ioc32.c
28462--- linux-2.6.32.41/drivers/gpu/drm/radeon/radeon_ioc32.c 2011-03-27 14:31:47.000000000 -0400
28463+++ linux-2.6.32.41/drivers/gpu/drm/radeon/radeon_ioc32.c 2011-04-23 13:57:24.000000000 -0400
28464@@ -368,7 +368,7 @@ static int compat_radeon_cp_setparam(str
28465 request = compat_alloc_user_space(sizeof(*request));
28466 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
28467 || __put_user(req32.param, &request->param)
28468- || __put_user((void __user *)(unsigned long)req32.value,
28469+ || __put_user((unsigned long)req32.value,
28470 &request->value))
28471 return -EFAULT;
28472
28473diff -urNp linux-2.6.32.41/drivers/gpu/drm/radeon/radeon_irq.c linux-2.6.32.41/drivers/gpu/drm/radeon/radeon_irq.c
28474--- linux-2.6.32.41/drivers/gpu/drm/radeon/radeon_irq.c 2011-03-27 14:31:47.000000000 -0400
28475+++ linux-2.6.32.41/drivers/gpu/drm/radeon/radeon_irq.c 2011-05-04 17:56:28.000000000 -0400
28476@@ -225,8 +225,8 @@ static int radeon_emit_irq(struct drm_de
28477 unsigned int ret;
28478 RING_LOCALS;
28479
28480- atomic_inc(&dev_priv->swi_emitted);
28481- ret = atomic_read(&dev_priv->swi_emitted);
28482+ atomic_inc_unchecked(&dev_priv->swi_emitted);
28483+ ret = atomic_read_unchecked(&dev_priv->swi_emitted);
28484
28485 BEGIN_RING(4);
28486 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
28487@@ -352,7 +352,7 @@ int radeon_driver_irq_postinstall(struct
28488 drm_radeon_private_t *dev_priv =
28489 (drm_radeon_private_t *) dev->dev_private;
28490
28491- atomic_set(&dev_priv->swi_emitted, 0);
28492+ atomic_set_unchecked(&dev_priv->swi_emitted, 0);
28493 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
28494
28495 dev->max_vblank_count = 0x001fffff;
28496diff -urNp linux-2.6.32.41/drivers/gpu/drm/radeon/radeon_state.c linux-2.6.32.41/drivers/gpu/drm/radeon/radeon_state.c
28497--- linux-2.6.32.41/drivers/gpu/drm/radeon/radeon_state.c 2011-03-27 14:31:47.000000000 -0400
28498+++ linux-2.6.32.41/drivers/gpu/drm/radeon/radeon_state.c 2011-04-17 15:56:46.000000000 -0400
28499@@ -3021,7 +3021,7 @@ static int radeon_cp_getparam(struct drm
28500 {
28501 drm_radeon_private_t *dev_priv = dev->dev_private;
28502 drm_radeon_getparam_t *param = data;
28503- int value;
28504+ int value = 0;
28505
28506 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
28507
28508diff -urNp linux-2.6.32.41/drivers/gpu/drm/radeon/radeon_ttm.c linux-2.6.32.41/drivers/gpu/drm/radeon/radeon_ttm.c
28509--- linux-2.6.32.41/drivers/gpu/drm/radeon/radeon_ttm.c 2011-03-27 14:31:47.000000000 -0400
28510+++ linux-2.6.32.41/drivers/gpu/drm/radeon/radeon_ttm.c 2011-04-17 15:56:46.000000000 -0400
28511@@ -535,27 +535,10 @@ void radeon_ttm_fini(struct radeon_devic
28512 DRM_INFO("radeon: ttm finalized\n");
28513 }
28514
28515-static struct vm_operations_struct radeon_ttm_vm_ops;
28516-static const struct vm_operations_struct *ttm_vm_ops = NULL;
28517-
28518-static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
28519-{
28520- struct ttm_buffer_object *bo;
28521- int r;
28522-
28523- bo = (struct ttm_buffer_object *)vma->vm_private_data;
28524- if (bo == NULL) {
28525- return VM_FAULT_NOPAGE;
28526- }
28527- r = ttm_vm_ops->fault(vma, vmf);
28528- return r;
28529-}
28530-
28531 int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
28532 {
28533 struct drm_file *file_priv;
28534 struct radeon_device *rdev;
28535- int r;
28536
28537 if (unlikely(vma->vm_pgoff < DRM_FILE_PAGE_OFFSET)) {
28538 return drm_mmap(filp, vma);
28539@@ -563,20 +546,9 @@ int radeon_mmap(struct file *filp, struc
28540
28541 file_priv = (struct drm_file *)filp->private_data;
28542 rdev = file_priv->minor->dev->dev_private;
28543- if (rdev == NULL) {
28544+ if (!rdev)
28545 return -EINVAL;
28546- }
28547- r = ttm_bo_mmap(filp, vma, &rdev->mman.bdev);
28548- if (unlikely(r != 0)) {
28549- return r;
28550- }
28551- if (unlikely(ttm_vm_ops == NULL)) {
28552- ttm_vm_ops = vma->vm_ops;
28553- radeon_ttm_vm_ops = *ttm_vm_ops;
28554- radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
28555- }
28556- vma->vm_ops = &radeon_ttm_vm_ops;
28557- return 0;
28558+ return ttm_bo_mmap(filp, vma, &rdev->mman.bdev);
28559 }
28560
28561
28562diff -urNp linux-2.6.32.41/drivers/gpu/drm/radeon/rs690.c linux-2.6.32.41/drivers/gpu/drm/radeon/rs690.c
28563--- linux-2.6.32.41/drivers/gpu/drm/radeon/rs690.c 2011-03-27 14:31:47.000000000 -0400
28564+++ linux-2.6.32.41/drivers/gpu/drm/radeon/rs690.c 2011-04-17 15:56:46.000000000 -0400
28565@@ -302,9 +302,11 @@ void rs690_crtc_bandwidth_compute(struct
28566 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
28567 rdev->pm.sideport_bandwidth.full)
28568 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
28569- read_delay_latency.full = rfixed_const(370 * 800 * 1000);
28570+ read_delay_latency.full = rfixed_const(800 * 1000);
28571 read_delay_latency.full = rfixed_div(read_delay_latency,
28572 rdev->pm.igp_sideport_mclk);
28573+ a.full = rfixed_const(370);
28574+ read_delay_latency.full = rfixed_mul(read_delay_latency, a);
28575 } else {
28576 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
28577 rdev->pm.k8_bandwidth.full)
28578diff -urNp linux-2.6.32.41/drivers/gpu/drm/ttm/ttm_bo.c linux-2.6.32.41/drivers/gpu/drm/ttm/ttm_bo.c
28579--- linux-2.6.32.41/drivers/gpu/drm/ttm/ttm_bo.c 2011-03-27 14:31:47.000000000 -0400
28580+++ linux-2.6.32.41/drivers/gpu/drm/ttm/ttm_bo.c 2011-04-23 12:56:11.000000000 -0400
28581@@ -67,7 +67,7 @@ static struct attribute *ttm_bo_global_a
28582 NULL
28583 };
28584
28585-static struct sysfs_ops ttm_bo_global_ops = {
28586+static const struct sysfs_ops ttm_bo_global_ops = {
28587 .show = &ttm_bo_global_show
28588 };
28589
28590diff -urNp linux-2.6.32.41/drivers/gpu/drm/ttm/ttm_bo_vm.c linux-2.6.32.41/drivers/gpu/drm/ttm/ttm_bo_vm.c
28591--- linux-2.6.32.41/drivers/gpu/drm/ttm/ttm_bo_vm.c 2011-03-27 14:31:47.000000000 -0400
28592+++ linux-2.6.32.41/drivers/gpu/drm/ttm/ttm_bo_vm.c 2011-04-17 15:56:46.000000000 -0400
28593@@ -73,7 +73,7 @@ static int ttm_bo_vm_fault(struct vm_are
28594 {
28595 struct ttm_buffer_object *bo = (struct ttm_buffer_object *)
28596 vma->vm_private_data;
28597- struct ttm_bo_device *bdev = bo->bdev;
28598+ struct ttm_bo_device *bdev;
28599 unsigned long bus_base;
28600 unsigned long bus_offset;
28601 unsigned long bus_size;
28602@@ -88,6 +88,10 @@ static int ttm_bo_vm_fault(struct vm_are
28603 unsigned long address = (unsigned long)vmf->virtual_address;
28604 int retval = VM_FAULT_NOPAGE;
28605
28606+ if (!bo)
28607+ return VM_FAULT_NOPAGE;
28608+ bdev = bo->bdev;
28609+
28610 /*
28611 * Work around locking order reversal in fault / nopfn
28612 * between mmap_sem and bo_reserve: Perform a trylock operation
28613diff -urNp linux-2.6.32.41/drivers/gpu/drm/ttm/ttm_global.c linux-2.6.32.41/drivers/gpu/drm/ttm/ttm_global.c
28614--- linux-2.6.32.41/drivers/gpu/drm/ttm/ttm_global.c 2011-03-27 14:31:47.000000000 -0400
28615+++ linux-2.6.32.41/drivers/gpu/drm/ttm/ttm_global.c 2011-04-17 15:56:46.000000000 -0400
28616@@ -36,7 +36,7 @@
28617 struct ttm_global_item {
28618 struct mutex mutex;
28619 void *object;
28620- int refcount;
28621+ atomic_t refcount;
28622 };
28623
28624 static struct ttm_global_item glob[TTM_GLOBAL_NUM];
28625@@ -49,7 +49,7 @@ void ttm_global_init(void)
28626 struct ttm_global_item *item = &glob[i];
28627 mutex_init(&item->mutex);
28628 item->object = NULL;
28629- item->refcount = 0;
28630+ atomic_set(&item->refcount, 0);
28631 }
28632 }
28633
28634@@ -59,7 +59,7 @@ void ttm_global_release(void)
28635 for (i = 0; i < TTM_GLOBAL_NUM; ++i) {
28636 struct ttm_global_item *item = &glob[i];
28637 BUG_ON(item->object != NULL);
28638- BUG_ON(item->refcount != 0);
28639+ BUG_ON(atomic_read(&item->refcount) != 0);
28640 }
28641 }
28642
28643@@ -70,7 +70,7 @@ int ttm_global_item_ref(struct ttm_globa
28644 void *object;
28645
28646 mutex_lock(&item->mutex);
28647- if (item->refcount == 0) {
28648+ if (atomic_read(&item->refcount) == 0) {
28649 item->object = kzalloc(ref->size, GFP_KERNEL);
28650 if (unlikely(item->object == NULL)) {
28651 ret = -ENOMEM;
28652@@ -83,7 +83,7 @@ int ttm_global_item_ref(struct ttm_globa
28653 goto out_err;
28654
28655 }
28656- ++item->refcount;
28657+ atomic_inc(&item->refcount);
28658 ref->object = item->object;
28659 object = item->object;
28660 mutex_unlock(&item->mutex);
28661@@ -100,9 +100,9 @@ void ttm_global_item_unref(struct ttm_gl
28662 struct ttm_global_item *item = &glob[ref->global_type];
28663
28664 mutex_lock(&item->mutex);
28665- BUG_ON(item->refcount == 0);
28666+ BUG_ON(atomic_read(&item->refcount) == 0);
28667 BUG_ON(ref->object != item->object);
28668- if (--item->refcount == 0) {
28669+ if (atomic_dec_and_test(&item->refcount)) {
28670 ref->release(ref);
28671 item->object = NULL;
28672 }
28673diff -urNp linux-2.6.32.41/drivers/gpu/drm/ttm/ttm_memory.c linux-2.6.32.41/drivers/gpu/drm/ttm/ttm_memory.c
28674--- linux-2.6.32.41/drivers/gpu/drm/ttm/ttm_memory.c 2011-03-27 14:31:47.000000000 -0400
28675+++ linux-2.6.32.41/drivers/gpu/drm/ttm/ttm_memory.c 2011-04-17 15:56:46.000000000 -0400
28676@@ -152,7 +152,7 @@ static struct attribute *ttm_mem_zone_at
28677 NULL
28678 };
28679
28680-static struct sysfs_ops ttm_mem_zone_ops = {
28681+static const struct sysfs_ops ttm_mem_zone_ops = {
28682 .show = &ttm_mem_zone_show,
28683 .store = &ttm_mem_zone_store
28684 };
28685diff -urNp linux-2.6.32.41/drivers/gpu/drm/via/via_drv.h linux-2.6.32.41/drivers/gpu/drm/via/via_drv.h
28686--- linux-2.6.32.41/drivers/gpu/drm/via/via_drv.h 2011-03-27 14:31:47.000000000 -0400
28687+++ linux-2.6.32.41/drivers/gpu/drm/via/via_drv.h 2011-05-04 17:56:28.000000000 -0400
28688@@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
28689 typedef uint32_t maskarray_t[5];
28690
28691 typedef struct drm_via_irq {
28692- atomic_t irq_received;
28693+ atomic_unchecked_t irq_received;
28694 uint32_t pending_mask;
28695 uint32_t enable_mask;
28696 wait_queue_head_t irq_queue;
28697@@ -75,7 +75,7 @@ typedef struct drm_via_private {
28698 struct timeval last_vblank;
28699 int last_vblank_valid;
28700 unsigned usec_per_vblank;
28701- atomic_t vbl_received;
28702+ atomic_unchecked_t vbl_received;
28703 drm_via_state_t hc_state;
28704 char pci_buf[VIA_PCI_BUF_SIZE];
28705 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
28706diff -urNp linux-2.6.32.41/drivers/gpu/drm/via/via_irq.c linux-2.6.32.41/drivers/gpu/drm/via/via_irq.c
28707--- linux-2.6.32.41/drivers/gpu/drm/via/via_irq.c 2011-03-27 14:31:47.000000000 -0400
28708+++ linux-2.6.32.41/drivers/gpu/drm/via/via_irq.c 2011-05-04 17:56:28.000000000 -0400
28709@@ -102,7 +102,7 @@ u32 via_get_vblank_counter(struct drm_de
28710 if (crtc != 0)
28711 return 0;
28712
28713- return atomic_read(&dev_priv->vbl_received);
28714+ return atomic_read_unchecked(&dev_priv->vbl_received);
28715 }
28716
28717 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
28718@@ -117,8 +117,8 @@ irqreturn_t via_driver_irq_handler(DRM_I
28719
28720 status = VIA_READ(VIA_REG_INTERRUPT);
28721 if (status & VIA_IRQ_VBLANK_PENDING) {
28722- atomic_inc(&dev_priv->vbl_received);
28723- if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
28724+ atomic_inc_unchecked(&dev_priv->vbl_received);
28725+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
28726 do_gettimeofday(&cur_vblank);
28727 if (dev_priv->last_vblank_valid) {
28728 dev_priv->usec_per_vblank =
28729@@ -128,7 +128,7 @@ irqreturn_t via_driver_irq_handler(DRM_I
28730 dev_priv->last_vblank = cur_vblank;
28731 dev_priv->last_vblank_valid = 1;
28732 }
28733- if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
28734+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
28735 DRM_DEBUG("US per vblank is: %u\n",
28736 dev_priv->usec_per_vblank);
28737 }
28738@@ -138,7 +138,7 @@ irqreturn_t via_driver_irq_handler(DRM_I
28739
28740 for (i = 0; i < dev_priv->num_irqs; ++i) {
28741 if (status & cur_irq->pending_mask) {
28742- atomic_inc(&cur_irq->irq_received);
28743+ atomic_inc_unchecked(&cur_irq->irq_received);
28744 DRM_WAKEUP(&cur_irq->irq_queue);
28745 handled = 1;
28746 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i) {
28747@@ -244,11 +244,11 @@ via_driver_irq_wait(struct drm_device *
28748 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
28749 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
28750 masks[irq][4]));
28751- cur_irq_sequence = atomic_read(&cur_irq->irq_received);
28752+ cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
28753 } else {
28754 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
28755 (((cur_irq_sequence =
28756- atomic_read(&cur_irq->irq_received)) -
28757+ atomic_read_unchecked(&cur_irq->irq_received)) -
28758 *sequence) <= (1 << 23)));
28759 }
28760 *sequence = cur_irq_sequence;
28761@@ -286,7 +286,7 @@ void via_driver_irq_preinstall(struct dr
28762 }
28763
28764 for (i = 0; i < dev_priv->num_irqs; ++i) {
28765- atomic_set(&cur_irq->irq_received, 0);
28766+ atomic_set_unchecked(&cur_irq->irq_received, 0);
28767 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
28768 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
28769 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
28770@@ -368,7 +368,7 @@ int via_wait_irq(struct drm_device *dev,
28771 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
28772 case VIA_IRQ_RELATIVE:
28773 irqwait->request.sequence +=
28774- atomic_read(&cur_irq->irq_received);
28775+ atomic_read_unchecked(&cur_irq->irq_received);
28776 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
28777 case VIA_IRQ_ABSOLUTE:
28778 break;
28779diff -urNp linux-2.6.32.41/drivers/hid/hid-core.c linux-2.6.32.41/drivers/hid/hid-core.c
28780--- linux-2.6.32.41/drivers/hid/hid-core.c 2011-05-10 22:12:01.000000000 -0400
28781+++ linux-2.6.32.41/drivers/hid/hid-core.c 2011-05-10 22:12:32.000000000 -0400
28782@@ -1752,7 +1752,7 @@ static bool hid_ignore(struct hid_device
28783
28784 int hid_add_device(struct hid_device *hdev)
28785 {
28786- static atomic_t id = ATOMIC_INIT(0);
28787+ static atomic_unchecked_t id = ATOMIC_INIT(0);
28788 int ret;
28789
28790 if (WARN_ON(hdev->status & HID_STAT_ADDED))
28791@@ -1766,7 +1766,7 @@ int hid_add_device(struct hid_device *hd
28792 /* XXX hack, any other cleaner solution after the driver core
28793 * is converted to allow more than 20 bytes as the device name? */
28794 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
28795- hdev->vendor, hdev->product, atomic_inc_return(&id));
28796+ hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
28797
28798 ret = device_add(&hdev->dev);
28799 if (!ret)
28800diff -urNp linux-2.6.32.41/drivers/hid/usbhid/hiddev.c linux-2.6.32.41/drivers/hid/usbhid/hiddev.c
28801--- linux-2.6.32.41/drivers/hid/usbhid/hiddev.c 2011-03-27 14:31:47.000000000 -0400
28802+++ linux-2.6.32.41/drivers/hid/usbhid/hiddev.c 2011-04-17 15:56:46.000000000 -0400
28803@@ -617,7 +617,7 @@ static long hiddev_ioctl(struct file *fi
28804 return put_user(HID_VERSION, (int __user *)arg);
28805
28806 case HIDIOCAPPLICATION:
28807- if (arg < 0 || arg >= hid->maxapplication)
28808+ if (arg >= hid->maxapplication)
28809 return -EINVAL;
28810
28811 for (i = 0; i < hid->maxcollection; i++)
28812diff -urNp linux-2.6.32.41/drivers/hwmon/lis3lv02d.c linux-2.6.32.41/drivers/hwmon/lis3lv02d.c
28813--- linux-2.6.32.41/drivers/hwmon/lis3lv02d.c 2011-03-27 14:31:47.000000000 -0400
28814+++ linux-2.6.32.41/drivers/hwmon/lis3lv02d.c 2011-05-04 17:56:28.000000000 -0400
28815@@ -146,7 +146,7 @@ static irqreturn_t lis302dl_interrupt(in
28816 * the lid is closed. This leads to interrupts as soon as a little move
28817 * is done.
28818 */
28819- atomic_inc(&lis3_dev.count);
28820+ atomic_inc_unchecked(&lis3_dev.count);
28821
28822 wake_up_interruptible(&lis3_dev.misc_wait);
28823 kill_fasync(&lis3_dev.async_queue, SIGIO, POLL_IN);
28824@@ -160,7 +160,7 @@ static int lis3lv02d_misc_open(struct in
28825 if (test_and_set_bit(0, &lis3_dev.misc_opened))
28826 return -EBUSY; /* already open */
28827
28828- atomic_set(&lis3_dev.count, 0);
28829+ atomic_set_unchecked(&lis3_dev.count, 0);
28830
28831 /*
28832 * The sensor can generate interrupts for free-fall and direction
28833@@ -206,7 +206,7 @@ static ssize_t lis3lv02d_misc_read(struc
28834 add_wait_queue(&lis3_dev.misc_wait, &wait);
28835 while (true) {
28836 set_current_state(TASK_INTERRUPTIBLE);
28837- data = atomic_xchg(&lis3_dev.count, 0);
28838+ data = atomic_xchg_unchecked(&lis3_dev.count, 0);
28839 if (data)
28840 break;
28841
28842@@ -244,7 +244,7 @@ out:
28843 static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
28844 {
28845 poll_wait(file, &lis3_dev.misc_wait, wait);
28846- if (atomic_read(&lis3_dev.count))
28847+ if (atomic_read_unchecked(&lis3_dev.count))
28848 return POLLIN | POLLRDNORM;
28849 return 0;
28850 }
28851diff -urNp linux-2.6.32.41/drivers/hwmon/lis3lv02d.h linux-2.6.32.41/drivers/hwmon/lis3lv02d.h
28852--- linux-2.6.32.41/drivers/hwmon/lis3lv02d.h 2011-03-27 14:31:47.000000000 -0400
28853+++ linux-2.6.32.41/drivers/hwmon/lis3lv02d.h 2011-05-04 17:56:28.000000000 -0400
28854@@ -201,7 +201,7 @@ struct lis3lv02d {
28855
28856 struct input_polled_dev *idev; /* input device */
28857 struct platform_device *pdev; /* platform device */
28858- atomic_t count; /* interrupt count after last read */
28859+ atomic_unchecked_t count; /* interrupt count after last read */
28860 int xcalib; /* calibrated null value for x */
28861 int ycalib; /* calibrated null value for y */
28862 int zcalib; /* calibrated null value for z */
28863diff -urNp linux-2.6.32.41/drivers/hwmon/sht15.c linux-2.6.32.41/drivers/hwmon/sht15.c
28864--- linux-2.6.32.41/drivers/hwmon/sht15.c 2011-03-27 14:31:47.000000000 -0400
28865+++ linux-2.6.32.41/drivers/hwmon/sht15.c 2011-05-04 17:56:28.000000000 -0400
28866@@ -112,7 +112,7 @@ struct sht15_data {
28867 int supply_uV;
28868 int supply_uV_valid;
28869 struct work_struct update_supply_work;
28870- atomic_t interrupt_handled;
28871+ atomic_unchecked_t interrupt_handled;
28872 };
28873
28874 /**
28875@@ -245,13 +245,13 @@ static inline int sht15_update_single_va
28876 return ret;
28877
28878 gpio_direction_input(data->pdata->gpio_data);
28879- atomic_set(&data->interrupt_handled, 0);
28880+ atomic_set_unchecked(&data->interrupt_handled, 0);
28881
28882 enable_irq(gpio_to_irq(data->pdata->gpio_data));
28883 if (gpio_get_value(data->pdata->gpio_data) == 0) {
28884 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
28885 /* Only relevant if the interrupt hasn't occured. */
28886- if (!atomic_read(&data->interrupt_handled))
28887+ if (!atomic_read_unchecked(&data->interrupt_handled))
28888 schedule_work(&data->read_work);
28889 }
28890 ret = wait_event_timeout(data->wait_queue,
28891@@ -398,7 +398,7 @@ static irqreturn_t sht15_interrupt_fired
28892 struct sht15_data *data = d;
28893 /* First disable the interrupt */
28894 disable_irq_nosync(irq);
28895- atomic_inc(&data->interrupt_handled);
28896+ atomic_inc_unchecked(&data->interrupt_handled);
28897 /* Then schedule a reading work struct */
28898 if (data->flag != SHT15_READING_NOTHING)
28899 schedule_work(&data->read_work);
28900@@ -449,11 +449,11 @@ static void sht15_bh_read_data(struct wo
28901 here as could have gone low in meantime so verify
28902 it hasn't!
28903 */
28904- atomic_set(&data->interrupt_handled, 0);
28905+ atomic_set_unchecked(&data->interrupt_handled, 0);
28906 enable_irq(gpio_to_irq(data->pdata->gpio_data));
28907 /* If still not occured or another handler has been scheduled */
28908 if (gpio_get_value(data->pdata->gpio_data)
28909- || atomic_read(&data->interrupt_handled))
28910+ || atomic_read_unchecked(&data->interrupt_handled))
28911 return;
28912 }
28913 /* Read the data back from the device */
28914diff -urNp linux-2.6.32.41/drivers/hwmon/w83791d.c linux-2.6.32.41/drivers/hwmon/w83791d.c
28915--- linux-2.6.32.41/drivers/hwmon/w83791d.c 2011-03-27 14:31:47.000000000 -0400
28916+++ linux-2.6.32.41/drivers/hwmon/w83791d.c 2011-04-17 15:56:46.000000000 -0400
28917@@ -330,8 +330,8 @@ static int w83791d_detect(struct i2c_cli
28918 struct i2c_board_info *info);
28919 static int w83791d_remove(struct i2c_client *client);
28920
28921-static int w83791d_read(struct i2c_client *client, u8 register);
28922-static int w83791d_write(struct i2c_client *client, u8 register, u8 value);
28923+static int w83791d_read(struct i2c_client *client, u8 reg);
28924+static int w83791d_write(struct i2c_client *client, u8 reg, u8 value);
28925 static struct w83791d_data *w83791d_update_device(struct device *dev);
28926
28927 #ifdef DEBUG
28928diff -urNp linux-2.6.32.41/drivers/ide/ide-cd.c linux-2.6.32.41/drivers/ide/ide-cd.c
28929--- linux-2.6.32.41/drivers/ide/ide-cd.c 2011-03-27 14:31:47.000000000 -0400
28930+++ linux-2.6.32.41/drivers/ide/ide-cd.c 2011-04-17 15:56:46.000000000 -0400
28931@@ -774,7 +774,7 @@ static void cdrom_do_block_pc(ide_drive_
28932 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
28933 if ((unsigned long)buf & alignment
28934 || blk_rq_bytes(rq) & q->dma_pad_mask
28935- || object_is_on_stack(buf))
28936+ || object_starts_on_stack(buf))
28937 drive->dma = 0;
28938 }
28939 }
28940diff -urNp linux-2.6.32.41/drivers/ide/ide-floppy.c linux-2.6.32.41/drivers/ide/ide-floppy.c
28941--- linux-2.6.32.41/drivers/ide/ide-floppy.c 2011-03-27 14:31:47.000000000 -0400
28942+++ linux-2.6.32.41/drivers/ide/ide-floppy.c 2011-05-16 21:46:57.000000000 -0400
28943@@ -373,6 +373,8 @@ static int ide_floppy_get_capacity(ide_d
28944 u8 pc_buf[256], header_len, desc_cnt;
28945 int i, rc = 1, blocks, length;
28946
28947+ pax_track_stack();
28948+
28949 ide_debug_log(IDE_DBG_FUNC, "enter");
28950
28951 drive->bios_cyl = 0;
28952diff -urNp linux-2.6.32.41/drivers/ide/setup-pci.c linux-2.6.32.41/drivers/ide/setup-pci.c
28953--- linux-2.6.32.41/drivers/ide/setup-pci.c 2011-03-27 14:31:47.000000000 -0400
28954+++ linux-2.6.32.41/drivers/ide/setup-pci.c 2011-05-16 21:46:57.000000000 -0400
28955@@ -542,6 +542,8 @@ int ide_pci_init_two(struct pci_dev *dev
28956 int ret, i, n_ports = dev2 ? 4 : 2;
28957 struct ide_hw hw[4], *hws[] = { NULL, NULL, NULL, NULL };
28958
28959+ pax_track_stack();
28960+
28961 for (i = 0; i < n_ports / 2; i++) {
28962 ret = ide_setup_pci_controller(pdev[i], d, !i);
28963 if (ret < 0)
28964diff -urNp linux-2.6.32.41/drivers/ieee1394/dv1394.c linux-2.6.32.41/drivers/ieee1394/dv1394.c
28965--- linux-2.6.32.41/drivers/ieee1394/dv1394.c 2011-03-27 14:31:47.000000000 -0400
28966+++ linux-2.6.32.41/drivers/ieee1394/dv1394.c 2011-04-23 12:56:11.000000000 -0400
28967@@ -739,7 +739,7 @@ static void frame_prepare(struct video_c
28968 based upon DIF section and sequence
28969 */
28970
28971-static void inline
28972+static inline void
28973 frame_put_packet (struct frame *f, struct packet *p)
28974 {
28975 int section_type = p->data[0] >> 5; /* section type is in bits 5 - 7 */
28976diff -urNp linux-2.6.32.41/drivers/ieee1394/hosts.c linux-2.6.32.41/drivers/ieee1394/hosts.c
28977--- linux-2.6.32.41/drivers/ieee1394/hosts.c 2011-03-27 14:31:47.000000000 -0400
28978+++ linux-2.6.32.41/drivers/ieee1394/hosts.c 2011-04-17 15:56:46.000000000 -0400
28979@@ -78,6 +78,7 @@ static int dummy_isoctl(struct hpsb_iso
28980 }
28981
28982 static struct hpsb_host_driver dummy_driver = {
28983+ .name = "dummy",
28984 .transmit_packet = dummy_transmit_packet,
28985 .devctl = dummy_devctl,
28986 .isoctl = dummy_isoctl
28987diff -urNp linux-2.6.32.41/drivers/ieee1394/init_ohci1394_dma.c linux-2.6.32.41/drivers/ieee1394/init_ohci1394_dma.c
28988--- linux-2.6.32.41/drivers/ieee1394/init_ohci1394_dma.c 2011-03-27 14:31:47.000000000 -0400
28989+++ linux-2.6.32.41/drivers/ieee1394/init_ohci1394_dma.c 2011-04-17 15:56:46.000000000 -0400
28990@@ -257,7 +257,7 @@ void __init init_ohci1394_dma_on_all_con
28991 for (func = 0; func < 8; func++) {
28992 u32 class = read_pci_config(num,slot,func,
28993 PCI_CLASS_REVISION);
28994- if ((class == 0xffffffff))
28995+ if (class == 0xffffffff)
28996 continue; /* No device at this func */
28997
28998 if (class>>8 != PCI_CLASS_SERIAL_FIREWIRE_OHCI)
28999diff -urNp linux-2.6.32.41/drivers/ieee1394/ohci1394.c linux-2.6.32.41/drivers/ieee1394/ohci1394.c
29000--- linux-2.6.32.41/drivers/ieee1394/ohci1394.c 2011-03-27 14:31:47.000000000 -0400
29001+++ linux-2.6.32.41/drivers/ieee1394/ohci1394.c 2011-04-23 12:56:11.000000000 -0400
29002@@ -147,9 +147,9 @@ printk(level "%s: " fmt "\n" , OHCI1394_
29003 printk(level "%s: fw-host%d: " fmt "\n" , OHCI1394_DRIVER_NAME, ohci->host->id , ## args)
29004
29005 /* Module Parameters */
29006-static int phys_dma = 1;
29007+static int phys_dma;
29008 module_param(phys_dma, int, 0444);
29009-MODULE_PARM_DESC(phys_dma, "Enable physical DMA (default = 1).");
29010+MODULE_PARM_DESC(phys_dma, "Enable physical DMA (default = 0).");
29011
29012 static void dma_trm_tasklet(unsigned long data);
29013 static void dma_trm_reset(struct dma_trm_ctx *d);
29014diff -urNp linux-2.6.32.41/drivers/ieee1394/sbp2.c linux-2.6.32.41/drivers/ieee1394/sbp2.c
29015--- linux-2.6.32.41/drivers/ieee1394/sbp2.c 2011-03-27 14:31:47.000000000 -0400
29016+++ linux-2.6.32.41/drivers/ieee1394/sbp2.c 2011-04-23 12:56:11.000000000 -0400
29017@@ -2111,7 +2111,7 @@ MODULE_DESCRIPTION("IEEE-1394 SBP-2 prot
29018 MODULE_SUPPORTED_DEVICE(SBP2_DEVICE_NAME);
29019 MODULE_LICENSE("GPL");
29020
29021-static int sbp2_module_init(void)
29022+static int __init sbp2_module_init(void)
29023 {
29024 int ret;
29025
29026diff -urNp linux-2.6.32.41/drivers/infiniband/core/cm.c linux-2.6.32.41/drivers/infiniband/core/cm.c
29027--- linux-2.6.32.41/drivers/infiniband/core/cm.c 2011-03-27 14:31:47.000000000 -0400
29028+++ linux-2.6.32.41/drivers/infiniband/core/cm.c 2011-04-17 15:56:46.000000000 -0400
29029@@ -112,7 +112,7 @@ static char const counter_group_names[CM
29030
29031 struct cm_counter_group {
29032 struct kobject obj;
29033- atomic_long_t counter[CM_ATTR_COUNT];
29034+ atomic_long_unchecked_t counter[CM_ATTR_COUNT];
29035 };
29036
29037 struct cm_counter_attribute {
29038@@ -1386,7 +1386,7 @@ static void cm_dup_req_handler(struct cm
29039 struct ib_mad_send_buf *msg = NULL;
29040 int ret;
29041
29042- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
29043+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
29044 counter[CM_REQ_COUNTER]);
29045
29046 /* Quick state check to discard duplicate REQs. */
29047@@ -1764,7 +1764,7 @@ static void cm_dup_rep_handler(struct cm
29048 if (!cm_id_priv)
29049 return;
29050
29051- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
29052+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
29053 counter[CM_REP_COUNTER]);
29054 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
29055 if (ret)
29056@@ -1931,7 +1931,7 @@ static int cm_rtu_handler(struct cm_work
29057 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
29058 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
29059 spin_unlock_irq(&cm_id_priv->lock);
29060- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
29061+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
29062 counter[CM_RTU_COUNTER]);
29063 goto out;
29064 }
29065@@ -2110,7 +2110,7 @@ static int cm_dreq_handler(struct cm_wor
29066 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
29067 dreq_msg->local_comm_id);
29068 if (!cm_id_priv) {
29069- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
29070+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
29071 counter[CM_DREQ_COUNTER]);
29072 cm_issue_drep(work->port, work->mad_recv_wc);
29073 return -EINVAL;
29074@@ -2131,7 +2131,7 @@ static int cm_dreq_handler(struct cm_wor
29075 case IB_CM_MRA_REP_RCVD:
29076 break;
29077 case IB_CM_TIMEWAIT:
29078- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
29079+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
29080 counter[CM_DREQ_COUNTER]);
29081 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
29082 goto unlock;
29083@@ -2145,7 +2145,7 @@ static int cm_dreq_handler(struct cm_wor
29084 cm_free_msg(msg);
29085 goto deref;
29086 case IB_CM_DREQ_RCVD:
29087- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
29088+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
29089 counter[CM_DREQ_COUNTER]);
29090 goto unlock;
29091 default:
29092@@ -2501,7 +2501,7 @@ static int cm_mra_handler(struct cm_work
29093 ib_modify_mad(cm_id_priv->av.port->mad_agent,
29094 cm_id_priv->msg, timeout)) {
29095 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
29096- atomic_long_inc(&work->port->
29097+ atomic_long_inc_unchecked(&work->port->
29098 counter_group[CM_RECV_DUPLICATES].
29099 counter[CM_MRA_COUNTER]);
29100 goto out;
29101@@ -2510,7 +2510,7 @@ static int cm_mra_handler(struct cm_work
29102 break;
29103 case IB_CM_MRA_REQ_RCVD:
29104 case IB_CM_MRA_REP_RCVD:
29105- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
29106+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
29107 counter[CM_MRA_COUNTER]);
29108 /* fall through */
29109 default:
29110@@ -2672,7 +2672,7 @@ static int cm_lap_handler(struct cm_work
29111 case IB_CM_LAP_IDLE:
29112 break;
29113 case IB_CM_MRA_LAP_SENT:
29114- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
29115+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
29116 counter[CM_LAP_COUNTER]);
29117 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
29118 goto unlock;
29119@@ -2688,7 +2688,7 @@ static int cm_lap_handler(struct cm_work
29120 cm_free_msg(msg);
29121 goto deref;
29122 case IB_CM_LAP_RCVD:
29123- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
29124+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
29125 counter[CM_LAP_COUNTER]);
29126 goto unlock;
29127 default:
29128@@ -2972,7 +2972,7 @@ static int cm_sidr_req_handler(struct cm
29129 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
29130 if (cur_cm_id_priv) {
29131 spin_unlock_irq(&cm.lock);
29132- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
29133+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
29134 counter[CM_SIDR_REQ_COUNTER]);
29135 goto out; /* Duplicate message. */
29136 }
29137@@ -3184,10 +3184,10 @@ static void cm_send_handler(struct ib_ma
29138 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
29139 msg->retries = 1;
29140
29141- atomic_long_add(1 + msg->retries,
29142+ atomic_long_add_unchecked(1 + msg->retries,
29143 &port->counter_group[CM_XMIT].counter[attr_index]);
29144 if (msg->retries)
29145- atomic_long_add(msg->retries,
29146+ atomic_long_add_unchecked(msg->retries,
29147 &port->counter_group[CM_XMIT_RETRIES].
29148 counter[attr_index]);
29149
29150@@ -3397,7 +3397,7 @@ static void cm_recv_handler(struct ib_ma
29151 }
29152
29153 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
29154- atomic_long_inc(&port->counter_group[CM_RECV].
29155+ atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
29156 counter[attr_id - CM_ATTR_ID_OFFSET]);
29157
29158 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
29159@@ -3595,10 +3595,10 @@ static ssize_t cm_show_counter(struct ko
29160 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
29161
29162 return sprintf(buf, "%ld\n",
29163- atomic_long_read(&group->counter[cm_attr->index]));
29164+ atomic_long_read_unchecked(&group->counter[cm_attr->index]));
29165 }
29166
29167-static struct sysfs_ops cm_counter_ops = {
29168+static const struct sysfs_ops cm_counter_ops = {
29169 .show = cm_show_counter
29170 };
29171
29172diff -urNp linux-2.6.32.41/drivers/infiniband/core/fmr_pool.c linux-2.6.32.41/drivers/infiniband/core/fmr_pool.c
29173--- linux-2.6.32.41/drivers/infiniband/core/fmr_pool.c 2011-03-27 14:31:47.000000000 -0400
29174+++ linux-2.6.32.41/drivers/infiniband/core/fmr_pool.c 2011-05-04 17:56:28.000000000 -0400
29175@@ -97,8 +97,8 @@ struct ib_fmr_pool {
29176
29177 struct task_struct *thread;
29178
29179- atomic_t req_ser;
29180- atomic_t flush_ser;
29181+ atomic_unchecked_t req_ser;
29182+ atomic_unchecked_t flush_ser;
29183
29184 wait_queue_head_t force_wait;
29185 };
29186@@ -179,10 +179,10 @@ static int ib_fmr_cleanup_thread(void *p
29187 struct ib_fmr_pool *pool = pool_ptr;
29188
29189 do {
29190- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
29191+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
29192 ib_fmr_batch_release(pool);
29193
29194- atomic_inc(&pool->flush_ser);
29195+ atomic_inc_unchecked(&pool->flush_ser);
29196 wake_up_interruptible(&pool->force_wait);
29197
29198 if (pool->flush_function)
29199@@ -190,7 +190,7 @@ static int ib_fmr_cleanup_thread(void *p
29200 }
29201
29202 set_current_state(TASK_INTERRUPTIBLE);
29203- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
29204+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
29205 !kthread_should_stop())
29206 schedule();
29207 __set_current_state(TASK_RUNNING);
29208@@ -282,8 +282,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(s
29209 pool->dirty_watermark = params->dirty_watermark;
29210 pool->dirty_len = 0;
29211 spin_lock_init(&pool->pool_lock);
29212- atomic_set(&pool->req_ser, 0);
29213- atomic_set(&pool->flush_ser, 0);
29214+ atomic_set_unchecked(&pool->req_ser, 0);
29215+ atomic_set_unchecked(&pool->flush_ser, 0);
29216 init_waitqueue_head(&pool->force_wait);
29217
29218 pool->thread = kthread_run(ib_fmr_cleanup_thread,
29219@@ -411,11 +411,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool
29220 }
29221 spin_unlock_irq(&pool->pool_lock);
29222
29223- serial = atomic_inc_return(&pool->req_ser);
29224+ serial = atomic_inc_return_unchecked(&pool->req_ser);
29225 wake_up_process(pool->thread);
29226
29227 if (wait_event_interruptible(pool->force_wait,
29228- atomic_read(&pool->flush_ser) - serial >= 0))
29229+ atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
29230 return -EINTR;
29231
29232 return 0;
29233@@ -525,7 +525,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr
29234 } else {
29235 list_add_tail(&fmr->list, &pool->dirty_list);
29236 if (++pool->dirty_len >= pool->dirty_watermark) {
29237- atomic_inc(&pool->req_ser);
29238+ atomic_inc_unchecked(&pool->req_ser);
29239 wake_up_process(pool->thread);
29240 }
29241 }
29242diff -urNp linux-2.6.32.41/drivers/infiniband/core/sysfs.c linux-2.6.32.41/drivers/infiniband/core/sysfs.c
29243--- linux-2.6.32.41/drivers/infiniband/core/sysfs.c 2011-03-27 14:31:47.000000000 -0400
29244+++ linux-2.6.32.41/drivers/infiniband/core/sysfs.c 2011-04-17 15:56:46.000000000 -0400
29245@@ -79,7 +79,7 @@ static ssize_t port_attr_show(struct kob
29246 return port_attr->show(p, port_attr, buf);
29247 }
29248
29249-static struct sysfs_ops port_sysfs_ops = {
29250+static const struct sysfs_ops port_sysfs_ops = {
29251 .show = port_attr_show
29252 };
29253
29254diff -urNp linux-2.6.32.41/drivers/infiniband/core/uverbs_marshall.c linux-2.6.32.41/drivers/infiniband/core/uverbs_marshall.c
29255--- linux-2.6.32.41/drivers/infiniband/core/uverbs_marshall.c 2011-03-27 14:31:47.000000000 -0400
29256+++ linux-2.6.32.41/drivers/infiniband/core/uverbs_marshall.c 2011-04-17 15:56:46.000000000 -0400
29257@@ -40,18 +40,21 @@ void ib_copy_ah_attr_to_user(struct ib_u
29258 dst->grh.sgid_index = src->grh.sgid_index;
29259 dst->grh.hop_limit = src->grh.hop_limit;
29260 dst->grh.traffic_class = src->grh.traffic_class;
29261+ memset(&dst->grh.reserved, 0, sizeof(dst->grh.reserved));
29262 dst->dlid = src->dlid;
29263 dst->sl = src->sl;
29264 dst->src_path_bits = src->src_path_bits;
29265 dst->static_rate = src->static_rate;
29266 dst->is_global = src->ah_flags & IB_AH_GRH ? 1 : 0;
29267 dst->port_num = src->port_num;
29268+ dst->reserved = 0;
29269 }
29270 EXPORT_SYMBOL(ib_copy_ah_attr_to_user);
29271
29272 void ib_copy_qp_attr_to_user(struct ib_uverbs_qp_attr *dst,
29273 struct ib_qp_attr *src)
29274 {
29275+ dst->qp_state = src->qp_state;
29276 dst->cur_qp_state = src->cur_qp_state;
29277 dst->path_mtu = src->path_mtu;
29278 dst->path_mig_state = src->path_mig_state;
29279@@ -83,6 +86,7 @@ void ib_copy_qp_attr_to_user(struct ib_u
29280 dst->rnr_retry = src->rnr_retry;
29281 dst->alt_port_num = src->alt_port_num;
29282 dst->alt_timeout = src->alt_timeout;
29283+ memset(dst->reserved, 0, sizeof(dst->reserved));
29284 }
29285 EXPORT_SYMBOL(ib_copy_qp_attr_to_user);
29286
29287diff -urNp linux-2.6.32.41/drivers/infiniband/hw/ipath/ipath_fs.c linux-2.6.32.41/drivers/infiniband/hw/ipath/ipath_fs.c
29288--- linux-2.6.32.41/drivers/infiniband/hw/ipath/ipath_fs.c 2011-03-27 14:31:47.000000000 -0400
29289+++ linux-2.6.32.41/drivers/infiniband/hw/ipath/ipath_fs.c 2011-05-16 21:46:57.000000000 -0400
29290@@ -110,6 +110,8 @@ static ssize_t atomic_counters_read(stru
29291 struct infinipath_counters counters;
29292 struct ipath_devdata *dd;
29293
29294+ pax_track_stack();
29295+
29296 dd = file->f_path.dentry->d_inode->i_private;
29297 dd->ipath_f_read_counters(dd, &counters);
29298
29299diff -urNp linux-2.6.32.41/drivers/infiniband/hw/nes/nes.c linux-2.6.32.41/drivers/infiniband/hw/nes/nes.c
29300--- linux-2.6.32.41/drivers/infiniband/hw/nes/nes.c 2011-03-27 14:31:47.000000000 -0400
29301+++ linux-2.6.32.41/drivers/infiniband/hw/nes/nes.c 2011-05-04 17:56:28.000000000 -0400
29302@@ -102,7 +102,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limi
29303 LIST_HEAD(nes_adapter_list);
29304 static LIST_HEAD(nes_dev_list);
29305
29306-atomic_t qps_destroyed;
29307+atomic_unchecked_t qps_destroyed;
29308
29309 static unsigned int ee_flsh_adapter;
29310 static unsigned int sysfs_nonidx_addr;
29311@@ -259,7 +259,7 @@ static void nes_cqp_rem_ref_callback(str
29312 struct nes_adapter *nesadapter = nesdev->nesadapter;
29313 u32 qp_id;
29314
29315- atomic_inc(&qps_destroyed);
29316+ atomic_inc_unchecked(&qps_destroyed);
29317
29318 /* Free the control structures */
29319
29320diff -urNp linux-2.6.32.41/drivers/infiniband/hw/nes/nes_cm.c linux-2.6.32.41/drivers/infiniband/hw/nes/nes_cm.c
29321--- linux-2.6.32.41/drivers/infiniband/hw/nes/nes_cm.c 2011-03-27 14:31:47.000000000 -0400
29322+++ linux-2.6.32.41/drivers/infiniband/hw/nes/nes_cm.c 2011-05-04 17:56:28.000000000 -0400
29323@@ -69,11 +69,11 @@ u32 cm_packets_received;
29324 u32 cm_listens_created;
29325 u32 cm_listens_destroyed;
29326 u32 cm_backlog_drops;
29327-atomic_t cm_loopbacks;
29328-atomic_t cm_nodes_created;
29329-atomic_t cm_nodes_destroyed;
29330-atomic_t cm_accel_dropped_pkts;
29331-atomic_t cm_resets_recvd;
29332+atomic_unchecked_t cm_loopbacks;
29333+atomic_unchecked_t cm_nodes_created;
29334+atomic_unchecked_t cm_nodes_destroyed;
29335+atomic_unchecked_t cm_accel_dropped_pkts;
29336+atomic_unchecked_t cm_resets_recvd;
29337
29338 static inline int mini_cm_accelerated(struct nes_cm_core *,
29339 struct nes_cm_node *);
29340@@ -149,13 +149,13 @@ static struct nes_cm_ops nes_cm_api = {
29341
29342 static struct nes_cm_core *g_cm_core;
29343
29344-atomic_t cm_connects;
29345-atomic_t cm_accepts;
29346-atomic_t cm_disconnects;
29347-atomic_t cm_closes;
29348-atomic_t cm_connecteds;
29349-atomic_t cm_connect_reqs;
29350-atomic_t cm_rejects;
29351+atomic_unchecked_t cm_connects;
29352+atomic_unchecked_t cm_accepts;
29353+atomic_unchecked_t cm_disconnects;
29354+atomic_unchecked_t cm_closes;
29355+atomic_unchecked_t cm_connecteds;
29356+atomic_unchecked_t cm_connect_reqs;
29357+atomic_unchecked_t cm_rejects;
29358
29359
29360 /**
29361@@ -1195,7 +1195,7 @@ static struct nes_cm_node *make_cm_node(
29362 cm_node->rem_mac);
29363
29364 add_hte_node(cm_core, cm_node);
29365- atomic_inc(&cm_nodes_created);
29366+ atomic_inc_unchecked(&cm_nodes_created);
29367
29368 return cm_node;
29369 }
29370@@ -1253,7 +1253,7 @@ static int rem_ref_cm_node(struct nes_cm
29371 }
29372
29373 atomic_dec(&cm_core->node_cnt);
29374- atomic_inc(&cm_nodes_destroyed);
29375+ atomic_inc_unchecked(&cm_nodes_destroyed);
29376 nesqp = cm_node->nesqp;
29377 if (nesqp) {
29378 nesqp->cm_node = NULL;
29379@@ -1320,7 +1320,7 @@ static int process_options(struct nes_cm
29380
29381 static void drop_packet(struct sk_buff *skb)
29382 {
29383- atomic_inc(&cm_accel_dropped_pkts);
29384+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
29385 dev_kfree_skb_any(skb);
29386 }
29387
29388@@ -1377,7 +1377,7 @@ static void handle_rst_pkt(struct nes_cm
29389
29390 int reset = 0; /* whether to send reset in case of err.. */
29391 int passive_state;
29392- atomic_inc(&cm_resets_recvd);
29393+ atomic_inc_unchecked(&cm_resets_recvd);
29394 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
29395 " refcnt=%d\n", cm_node, cm_node->state,
29396 atomic_read(&cm_node->ref_count));
29397@@ -2000,7 +2000,7 @@ static struct nes_cm_node *mini_cm_conne
29398 rem_ref_cm_node(cm_node->cm_core, cm_node);
29399 return NULL;
29400 }
29401- atomic_inc(&cm_loopbacks);
29402+ atomic_inc_unchecked(&cm_loopbacks);
29403 loopbackremotenode->loopbackpartner = cm_node;
29404 loopbackremotenode->tcp_cntxt.rcv_wscale =
29405 NES_CM_DEFAULT_RCV_WND_SCALE;
29406@@ -2262,7 +2262,7 @@ static int mini_cm_recv_pkt(struct nes_c
29407 add_ref_cm_node(cm_node);
29408 } else if (cm_node->state == NES_CM_STATE_TSA) {
29409 rem_ref_cm_node(cm_core, cm_node);
29410- atomic_inc(&cm_accel_dropped_pkts);
29411+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
29412 dev_kfree_skb_any(skb);
29413 break;
29414 }
29415@@ -2568,7 +2568,7 @@ static int nes_cm_disconn_true(struct ne
29416
29417 if ((cm_id) && (cm_id->event_handler)) {
29418 if (issue_disconn) {
29419- atomic_inc(&cm_disconnects);
29420+ atomic_inc_unchecked(&cm_disconnects);
29421 cm_event.event = IW_CM_EVENT_DISCONNECT;
29422 cm_event.status = disconn_status;
29423 cm_event.local_addr = cm_id->local_addr;
29424@@ -2590,7 +2590,7 @@ static int nes_cm_disconn_true(struct ne
29425 }
29426
29427 if (issue_close) {
29428- atomic_inc(&cm_closes);
29429+ atomic_inc_unchecked(&cm_closes);
29430 nes_disconnect(nesqp, 1);
29431
29432 cm_id->provider_data = nesqp;
29433@@ -2710,7 +2710,7 @@ int nes_accept(struct iw_cm_id *cm_id, s
29434
29435 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
29436 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
29437- atomic_inc(&cm_accepts);
29438+ atomic_inc_unchecked(&cm_accepts);
29439
29440 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
29441 atomic_read(&nesvnic->netdev->refcnt));
29442@@ -2919,7 +2919,7 @@ int nes_reject(struct iw_cm_id *cm_id, c
29443
29444 struct nes_cm_core *cm_core;
29445
29446- atomic_inc(&cm_rejects);
29447+ atomic_inc_unchecked(&cm_rejects);
29448 cm_node = (struct nes_cm_node *) cm_id->provider_data;
29449 loopback = cm_node->loopbackpartner;
29450 cm_core = cm_node->cm_core;
29451@@ -2982,7 +2982,7 @@ int nes_connect(struct iw_cm_id *cm_id,
29452 ntohl(cm_id->local_addr.sin_addr.s_addr),
29453 ntohs(cm_id->local_addr.sin_port));
29454
29455- atomic_inc(&cm_connects);
29456+ atomic_inc_unchecked(&cm_connects);
29457 nesqp->active_conn = 1;
29458
29459 /* cache the cm_id in the qp */
29460@@ -3195,7 +3195,7 @@ static void cm_event_connected(struct ne
29461 if (nesqp->destroyed) {
29462 return;
29463 }
29464- atomic_inc(&cm_connecteds);
29465+ atomic_inc_unchecked(&cm_connecteds);
29466 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
29467 " local port 0x%04X. jiffies = %lu.\n",
29468 nesqp->hwqp.qp_id,
29469@@ -3403,7 +3403,7 @@ static void cm_event_reset(struct nes_cm
29470
29471 ret = cm_id->event_handler(cm_id, &cm_event);
29472 cm_id->add_ref(cm_id);
29473- atomic_inc(&cm_closes);
29474+ atomic_inc_unchecked(&cm_closes);
29475 cm_event.event = IW_CM_EVENT_CLOSE;
29476 cm_event.status = IW_CM_EVENT_STATUS_OK;
29477 cm_event.provider_data = cm_id->provider_data;
29478@@ -3439,7 +3439,7 @@ static void cm_event_mpa_req(struct nes_
29479 return;
29480 cm_id = cm_node->cm_id;
29481
29482- atomic_inc(&cm_connect_reqs);
29483+ atomic_inc_unchecked(&cm_connect_reqs);
29484 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
29485 cm_node, cm_id, jiffies);
29486
29487@@ -3477,7 +3477,7 @@ static void cm_event_mpa_reject(struct n
29488 return;
29489 cm_id = cm_node->cm_id;
29490
29491- atomic_inc(&cm_connect_reqs);
29492+ atomic_inc_unchecked(&cm_connect_reqs);
29493 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
29494 cm_node, cm_id, jiffies);
29495
29496diff -urNp linux-2.6.32.41/drivers/infiniband/hw/nes/nes.h linux-2.6.32.41/drivers/infiniband/hw/nes/nes.h
29497--- linux-2.6.32.41/drivers/infiniband/hw/nes/nes.h 2011-03-27 14:31:47.000000000 -0400
29498+++ linux-2.6.32.41/drivers/infiniband/hw/nes/nes.h 2011-05-04 17:56:28.000000000 -0400
29499@@ -174,17 +174,17 @@ extern unsigned int nes_debug_level;
29500 extern unsigned int wqm_quanta;
29501 extern struct list_head nes_adapter_list;
29502
29503-extern atomic_t cm_connects;
29504-extern atomic_t cm_accepts;
29505-extern atomic_t cm_disconnects;
29506-extern atomic_t cm_closes;
29507-extern atomic_t cm_connecteds;
29508-extern atomic_t cm_connect_reqs;
29509-extern atomic_t cm_rejects;
29510-extern atomic_t mod_qp_timouts;
29511-extern atomic_t qps_created;
29512-extern atomic_t qps_destroyed;
29513-extern atomic_t sw_qps_destroyed;
29514+extern atomic_unchecked_t cm_connects;
29515+extern atomic_unchecked_t cm_accepts;
29516+extern atomic_unchecked_t cm_disconnects;
29517+extern atomic_unchecked_t cm_closes;
29518+extern atomic_unchecked_t cm_connecteds;
29519+extern atomic_unchecked_t cm_connect_reqs;
29520+extern atomic_unchecked_t cm_rejects;
29521+extern atomic_unchecked_t mod_qp_timouts;
29522+extern atomic_unchecked_t qps_created;
29523+extern atomic_unchecked_t qps_destroyed;
29524+extern atomic_unchecked_t sw_qps_destroyed;
29525 extern u32 mh_detected;
29526 extern u32 mh_pauses_sent;
29527 extern u32 cm_packets_sent;
29528@@ -196,11 +196,11 @@ extern u32 cm_packets_retrans;
29529 extern u32 cm_listens_created;
29530 extern u32 cm_listens_destroyed;
29531 extern u32 cm_backlog_drops;
29532-extern atomic_t cm_loopbacks;
29533-extern atomic_t cm_nodes_created;
29534-extern atomic_t cm_nodes_destroyed;
29535-extern atomic_t cm_accel_dropped_pkts;
29536-extern atomic_t cm_resets_recvd;
29537+extern atomic_unchecked_t cm_loopbacks;
29538+extern atomic_unchecked_t cm_nodes_created;
29539+extern atomic_unchecked_t cm_nodes_destroyed;
29540+extern atomic_unchecked_t cm_accel_dropped_pkts;
29541+extern atomic_unchecked_t cm_resets_recvd;
29542
29543 extern u32 int_mod_timer_init;
29544 extern u32 int_mod_cq_depth_256;
29545diff -urNp linux-2.6.32.41/drivers/infiniband/hw/nes/nes_nic.c linux-2.6.32.41/drivers/infiniband/hw/nes/nes_nic.c
29546--- linux-2.6.32.41/drivers/infiniband/hw/nes/nes_nic.c 2011-03-27 14:31:47.000000000 -0400
29547+++ linux-2.6.32.41/drivers/infiniband/hw/nes/nes_nic.c 2011-05-04 17:56:28.000000000 -0400
29548@@ -1210,17 +1210,17 @@ static void nes_netdev_get_ethtool_stats
29549 target_stat_values[++index] = mh_detected;
29550 target_stat_values[++index] = mh_pauses_sent;
29551 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
29552- target_stat_values[++index] = atomic_read(&cm_connects);
29553- target_stat_values[++index] = atomic_read(&cm_accepts);
29554- target_stat_values[++index] = atomic_read(&cm_disconnects);
29555- target_stat_values[++index] = atomic_read(&cm_connecteds);
29556- target_stat_values[++index] = atomic_read(&cm_connect_reqs);
29557- target_stat_values[++index] = atomic_read(&cm_rejects);
29558- target_stat_values[++index] = atomic_read(&mod_qp_timouts);
29559- target_stat_values[++index] = atomic_read(&qps_created);
29560- target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
29561- target_stat_values[++index] = atomic_read(&qps_destroyed);
29562- target_stat_values[++index] = atomic_read(&cm_closes);
29563+ target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
29564+ target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
29565+ target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
29566+ target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
29567+ target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
29568+ target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
29569+ target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
29570+ target_stat_values[++index] = atomic_read_unchecked(&qps_created);
29571+ target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
29572+ target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
29573+ target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
29574 target_stat_values[++index] = cm_packets_sent;
29575 target_stat_values[++index] = cm_packets_bounced;
29576 target_stat_values[++index] = cm_packets_created;
29577@@ -1230,11 +1230,11 @@ static void nes_netdev_get_ethtool_stats
29578 target_stat_values[++index] = cm_listens_created;
29579 target_stat_values[++index] = cm_listens_destroyed;
29580 target_stat_values[++index] = cm_backlog_drops;
29581- target_stat_values[++index] = atomic_read(&cm_loopbacks);
29582- target_stat_values[++index] = atomic_read(&cm_nodes_created);
29583- target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
29584- target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
29585- target_stat_values[++index] = atomic_read(&cm_resets_recvd);
29586+ target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
29587+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
29588+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
29589+ target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
29590+ target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
29591 target_stat_values[++index] = int_mod_timer_init;
29592 target_stat_values[++index] = int_mod_cq_depth_1;
29593 target_stat_values[++index] = int_mod_cq_depth_4;
29594diff -urNp linux-2.6.32.41/drivers/infiniband/hw/nes/nes_verbs.c linux-2.6.32.41/drivers/infiniband/hw/nes/nes_verbs.c
29595--- linux-2.6.32.41/drivers/infiniband/hw/nes/nes_verbs.c 2011-03-27 14:31:47.000000000 -0400
29596+++ linux-2.6.32.41/drivers/infiniband/hw/nes/nes_verbs.c 2011-05-04 17:56:28.000000000 -0400
29597@@ -45,9 +45,9 @@
29598
29599 #include <rdma/ib_umem.h>
29600
29601-atomic_t mod_qp_timouts;
29602-atomic_t qps_created;
29603-atomic_t sw_qps_destroyed;
29604+atomic_unchecked_t mod_qp_timouts;
29605+atomic_unchecked_t qps_created;
29606+atomic_unchecked_t sw_qps_destroyed;
29607
29608 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
29609
29610@@ -1240,7 +1240,7 @@ static struct ib_qp *nes_create_qp(struc
29611 if (init_attr->create_flags)
29612 return ERR_PTR(-EINVAL);
29613
29614- atomic_inc(&qps_created);
29615+ atomic_inc_unchecked(&qps_created);
29616 switch (init_attr->qp_type) {
29617 case IB_QPT_RC:
29618 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
29619@@ -1568,7 +1568,7 @@ static int nes_destroy_qp(struct ib_qp *
29620 struct iw_cm_event cm_event;
29621 int ret;
29622
29623- atomic_inc(&sw_qps_destroyed);
29624+ atomic_inc_unchecked(&sw_qps_destroyed);
29625 nesqp->destroyed = 1;
29626
29627 /* Blow away the connection if it exists. */
29628diff -urNp linux-2.6.32.41/drivers/input/gameport/gameport.c linux-2.6.32.41/drivers/input/gameport/gameport.c
29629--- linux-2.6.32.41/drivers/input/gameport/gameport.c 2011-03-27 14:31:47.000000000 -0400
29630+++ linux-2.6.32.41/drivers/input/gameport/gameport.c 2011-05-04 17:56:28.000000000 -0400
29631@@ -515,13 +515,13 @@ EXPORT_SYMBOL(gameport_set_phys);
29632 */
29633 static void gameport_init_port(struct gameport *gameport)
29634 {
29635- static atomic_t gameport_no = ATOMIC_INIT(0);
29636+ static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
29637
29638 __module_get(THIS_MODULE);
29639
29640 mutex_init(&gameport->drv_mutex);
29641 device_initialize(&gameport->dev);
29642- dev_set_name(&gameport->dev, "gameport%lu", (unsigned long)atomic_inc_return(&gameport_no) - 1);
29643+ dev_set_name(&gameport->dev, "gameport%lu", (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
29644 gameport->dev.bus = &gameport_bus;
29645 gameport->dev.release = gameport_release_port;
29646 if (gameport->parent)
29647diff -urNp linux-2.6.32.41/drivers/input/input.c linux-2.6.32.41/drivers/input/input.c
29648--- linux-2.6.32.41/drivers/input/input.c 2011-03-27 14:31:47.000000000 -0400
29649+++ linux-2.6.32.41/drivers/input/input.c 2011-05-04 17:56:28.000000000 -0400
29650@@ -1558,7 +1558,7 @@ EXPORT_SYMBOL(input_set_capability);
29651 */
29652 int input_register_device(struct input_dev *dev)
29653 {
29654- static atomic_t input_no = ATOMIC_INIT(0);
29655+ static atomic_unchecked_t input_no = ATOMIC_INIT(0);
29656 struct input_handler *handler;
29657 const char *path;
29658 int error;
29659@@ -1585,7 +1585,7 @@ int input_register_device(struct input_d
29660 dev->setkeycode = input_default_setkeycode;
29661
29662 dev_set_name(&dev->dev, "input%ld",
29663- (unsigned long) atomic_inc_return(&input_no) - 1);
29664+ (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
29665
29666 error = device_add(&dev->dev);
29667 if (error)
29668diff -urNp linux-2.6.32.41/drivers/input/joystick/sidewinder.c linux-2.6.32.41/drivers/input/joystick/sidewinder.c
29669--- linux-2.6.32.41/drivers/input/joystick/sidewinder.c 2011-03-27 14:31:47.000000000 -0400
29670+++ linux-2.6.32.41/drivers/input/joystick/sidewinder.c 2011-05-18 20:09:36.000000000 -0400
29671@@ -30,6 +30,7 @@
29672 #include <linux/kernel.h>
29673 #include <linux/module.h>
29674 #include <linux/slab.h>
29675+#include <linux/sched.h>
29676 #include <linux/init.h>
29677 #include <linux/input.h>
29678 #include <linux/gameport.h>
29679@@ -428,6 +429,8 @@ static int sw_read(struct sw *sw)
29680 unsigned char buf[SW_LENGTH];
29681 int i;
29682
29683+ pax_track_stack();
29684+
29685 i = sw_read_packet(sw->gameport, buf, sw->length, 0);
29686
29687 if (sw->type == SW_ID_3DP && sw->length == 66 && i != 66) { /* Broken packet, try to fix */
29688diff -urNp linux-2.6.32.41/drivers/input/joystick/xpad.c linux-2.6.32.41/drivers/input/joystick/xpad.c
29689--- linux-2.6.32.41/drivers/input/joystick/xpad.c 2011-03-27 14:31:47.000000000 -0400
29690+++ linux-2.6.32.41/drivers/input/joystick/xpad.c 2011-05-04 17:56:28.000000000 -0400
29691@@ -621,7 +621,7 @@ static void xpad_led_set(struct led_clas
29692
29693 static int xpad_led_probe(struct usb_xpad *xpad)
29694 {
29695- static atomic_t led_seq = ATOMIC_INIT(0);
29696+ static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
29697 long led_no;
29698 struct xpad_led *led;
29699 struct led_classdev *led_cdev;
29700@@ -634,7 +634,7 @@ static int xpad_led_probe(struct usb_xpa
29701 if (!led)
29702 return -ENOMEM;
29703
29704- led_no = (long)atomic_inc_return(&led_seq) - 1;
29705+ led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
29706
29707 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
29708 led->xpad = xpad;
29709diff -urNp linux-2.6.32.41/drivers/input/serio/serio.c linux-2.6.32.41/drivers/input/serio/serio.c
29710--- linux-2.6.32.41/drivers/input/serio/serio.c 2011-03-27 14:31:47.000000000 -0400
29711+++ linux-2.6.32.41/drivers/input/serio/serio.c 2011-05-04 17:56:28.000000000 -0400
29712@@ -527,7 +527,7 @@ static void serio_release_port(struct de
29713 */
29714 static void serio_init_port(struct serio *serio)
29715 {
29716- static atomic_t serio_no = ATOMIC_INIT(0);
29717+ static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
29718
29719 __module_get(THIS_MODULE);
29720
29721@@ -536,7 +536,7 @@ static void serio_init_port(struct serio
29722 mutex_init(&serio->drv_mutex);
29723 device_initialize(&serio->dev);
29724 dev_set_name(&serio->dev, "serio%ld",
29725- (long)atomic_inc_return(&serio_no) - 1);
29726+ (long)atomic_inc_return_unchecked(&serio_no) - 1);
29727 serio->dev.bus = &serio_bus;
29728 serio->dev.release = serio_release_port;
29729 if (serio->parent) {
29730diff -urNp linux-2.6.32.41/drivers/isdn/gigaset/common.c linux-2.6.32.41/drivers/isdn/gigaset/common.c
29731--- linux-2.6.32.41/drivers/isdn/gigaset/common.c 2011-03-27 14:31:47.000000000 -0400
29732+++ linux-2.6.32.41/drivers/isdn/gigaset/common.c 2011-04-17 15:56:46.000000000 -0400
29733@@ -712,7 +712,7 @@ struct cardstate *gigaset_initcs(struct
29734 cs->commands_pending = 0;
29735 cs->cur_at_seq = 0;
29736 cs->gotfwver = -1;
29737- cs->open_count = 0;
29738+ local_set(&cs->open_count, 0);
29739 cs->dev = NULL;
29740 cs->tty = NULL;
29741 cs->tty_dev = NULL;
29742diff -urNp linux-2.6.32.41/drivers/isdn/gigaset/gigaset.h linux-2.6.32.41/drivers/isdn/gigaset/gigaset.h
29743--- linux-2.6.32.41/drivers/isdn/gigaset/gigaset.h 2011-03-27 14:31:47.000000000 -0400
29744+++ linux-2.6.32.41/drivers/isdn/gigaset/gigaset.h 2011-04-17 15:56:46.000000000 -0400
29745@@ -34,6 +34,7 @@
29746 #include <linux/tty_driver.h>
29747 #include <linux/list.h>
29748 #include <asm/atomic.h>
29749+#include <asm/local.h>
29750
29751 #define GIG_VERSION {0,5,0,0}
29752 #define GIG_COMPAT {0,4,0,0}
29753@@ -446,7 +447,7 @@ struct cardstate {
29754 spinlock_t cmdlock;
29755 unsigned curlen, cmdbytes;
29756
29757- unsigned open_count;
29758+ local_t open_count;
29759 struct tty_struct *tty;
29760 struct tasklet_struct if_wake_tasklet;
29761 unsigned control_state;
29762diff -urNp linux-2.6.32.41/drivers/isdn/gigaset/interface.c linux-2.6.32.41/drivers/isdn/gigaset/interface.c
29763--- linux-2.6.32.41/drivers/isdn/gigaset/interface.c 2011-03-27 14:31:47.000000000 -0400
29764+++ linux-2.6.32.41/drivers/isdn/gigaset/interface.c 2011-04-17 15:56:46.000000000 -0400
29765@@ -165,9 +165,7 @@ static int if_open(struct tty_struct *tt
29766 return -ERESTARTSYS; // FIXME -EINTR?
29767 tty->driver_data = cs;
29768
29769- ++cs->open_count;
29770-
29771- if (cs->open_count == 1) {
29772+ if (local_inc_return(&cs->open_count) == 1) {
29773 spin_lock_irqsave(&cs->lock, flags);
29774 cs->tty = tty;
29775 spin_unlock_irqrestore(&cs->lock, flags);
29776@@ -195,10 +193,10 @@ static void if_close(struct tty_struct *
29777
29778 if (!cs->connected)
29779 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
29780- else if (!cs->open_count)
29781+ else if (!local_read(&cs->open_count))
29782 dev_warn(cs->dev, "%s: device not opened\n", __func__);
29783 else {
29784- if (!--cs->open_count) {
29785+ if (!local_dec_return(&cs->open_count)) {
29786 spin_lock_irqsave(&cs->lock, flags);
29787 cs->tty = NULL;
29788 spin_unlock_irqrestore(&cs->lock, flags);
29789@@ -233,7 +231,7 @@ static int if_ioctl(struct tty_struct *t
29790 if (!cs->connected) {
29791 gig_dbg(DEBUG_IF, "not connected");
29792 retval = -ENODEV;
29793- } else if (!cs->open_count)
29794+ } else if (!local_read(&cs->open_count))
29795 dev_warn(cs->dev, "%s: device not opened\n", __func__);
29796 else {
29797 retval = 0;
29798@@ -361,7 +359,7 @@ static int if_write(struct tty_struct *t
29799 if (!cs->connected) {
29800 gig_dbg(DEBUG_IF, "not connected");
29801 retval = -ENODEV;
29802- } else if (!cs->open_count)
29803+ } else if (!local_read(&cs->open_count))
29804 dev_warn(cs->dev, "%s: device not opened\n", __func__);
29805 else if (cs->mstate != MS_LOCKED) {
29806 dev_warn(cs->dev, "can't write to unlocked device\n");
29807@@ -395,7 +393,7 @@ static int if_write_room(struct tty_stru
29808 if (!cs->connected) {
29809 gig_dbg(DEBUG_IF, "not connected");
29810 retval = -ENODEV;
29811- } else if (!cs->open_count)
29812+ } else if (!local_read(&cs->open_count))
29813 dev_warn(cs->dev, "%s: device not opened\n", __func__);
29814 else if (cs->mstate != MS_LOCKED) {
29815 dev_warn(cs->dev, "can't write to unlocked device\n");
29816@@ -425,7 +423,7 @@ static int if_chars_in_buffer(struct tty
29817
29818 if (!cs->connected)
29819 gig_dbg(DEBUG_IF, "not connected");
29820- else if (!cs->open_count)
29821+ else if (!local_read(&cs->open_count))
29822 dev_warn(cs->dev, "%s: device not opened\n", __func__);
29823 else if (cs->mstate != MS_LOCKED)
29824 dev_warn(cs->dev, "can't write to unlocked device\n");
29825@@ -453,7 +451,7 @@ static void if_throttle(struct tty_struc
29826
29827 if (!cs->connected)
29828 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
29829- else if (!cs->open_count)
29830+ else if (!local_read(&cs->open_count))
29831 dev_warn(cs->dev, "%s: device not opened\n", __func__);
29832 else {
29833 //FIXME
29834@@ -478,7 +476,7 @@ static void if_unthrottle(struct tty_str
29835
29836 if (!cs->connected)
29837 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
29838- else if (!cs->open_count)
29839+ else if (!local_read(&cs->open_count))
29840 dev_warn(cs->dev, "%s: device not opened\n", __func__);
29841 else {
29842 //FIXME
29843@@ -510,7 +508,7 @@ static void if_set_termios(struct tty_st
29844 goto out;
29845 }
29846
29847- if (!cs->open_count) {
29848+ if (!local_read(&cs->open_count)) {
29849 dev_warn(cs->dev, "%s: device not opened\n", __func__);
29850 goto out;
29851 }
29852diff -urNp linux-2.6.32.41/drivers/isdn/hardware/avm/b1.c linux-2.6.32.41/drivers/isdn/hardware/avm/b1.c
29853--- linux-2.6.32.41/drivers/isdn/hardware/avm/b1.c 2011-03-27 14:31:47.000000000 -0400
29854+++ linux-2.6.32.41/drivers/isdn/hardware/avm/b1.c 2011-04-17 15:56:46.000000000 -0400
29855@@ -173,7 +173,7 @@ int b1_load_t4file(avmcard *card, capilo
29856 }
29857 if (left) {
29858 if (t4file->user) {
29859- if (copy_from_user(buf, dp, left))
29860+ if (left > sizeof buf || copy_from_user(buf, dp, left))
29861 return -EFAULT;
29862 } else {
29863 memcpy(buf, dp, left);
29864@@ -221,7 +221,7 @@ int b1_load_config(avmcard *card, capilo
29865 }
29866 if (left) {
29867 if (config->user) {
29868- if (copy_from_user(buf, dp, left))
29869+ if (left > sizeof buf || copy_from_user(buf, dp, left))
29870 return -EFAULT;
29871 } else {
29872 memcpy(buf, dp, left);
29873diff -urNp linux-2.6.32.41/drivers/isdn/hardware/eicon/capidtmf.c linux-2.6.32.41/drivers/isdn/hardware/eicon/capidtmf.c
29874--- linux-2.6.32.41/drivers/isdn/hardware/eicon/capidtmf.c 2011-03-27 14:31:47.000000000 -0400
29875+++ linux-2.6.32.41/drivers/isdn/hardware/eicon/capidtmf.c 2011-05-16 21:46:57.000000000 -0400
29876@@ -498,6 +498,7 @@ void capidtmf_recv_block (t_capidtmf_sta
29877 byte goertzel_result_buffer[CAPIDTMF_RECV_TOTAL_FREQUENCY_COUNT];
29878 short windowed_sample_buffer[CAPIDTMF_RECV_WINDOWED_SAMPLES];
29879
29880+ pax_track_stack();
29881
29882 if (p_state->recv.state & CAPIDTMF_RECV_STATE_DTMF_ACTIVE)
29883 {
29884diff -urNp linux-2.6.32.41/drivers/isdn/hardware/eicon/capifunc.c linux-2.6.32.41/drivers/isdn/hardware/eicon/capifunc.c
29885--- linux-2.6.32.41/drivers/isdn/hardware/eicon/capifunc.c 2011-03-27 14:31:47.000000000 -0400
29886+++ linux-2.6.32.41/drivers/isdn/hardware/eicon/capifunc.c 2011-05-16 21:46:57.000000000 -0400
29887@@ -1055,6 +1055,8 @@ static int divacapi_connect_didd(void)
29888 IDI_SYNC_REQ req;
29889 DESCRIPTOR DIDD_Table[MAX_DESCRIPTORS];
29890
29891+ pax_track_stack();
29892+
29893 DIVA_DIDD_Read(DIDD_Table, sizeof(DIDD_Table));
29894
29895 for (x = 0; x < MAX_DESCRIPTORS; x++) {
29896diff -urNp linux-2.6.32.41/drivers/isdn/hardware/eicon/diddfunc.c linux-2.6.32.41/drivers/isdn/hardware/eicon/diddfunc.c
29897--- linux-2.6.32.41/drivers/isdn/hardware/eicon/diddfunc.c 2011-03-27 14:31:47.000000000 -0400
29898+++ linux-2.6.32.41/drivers/isdn/hardware/eicon/diddfunc.c 2011-05-16 21:46:57.000000000 -0400
29899@@ -54,6 +54,8 @@ static int DIVA_INIT_FUNCTION connect_di
29900 IDI_SYNC_REQ req;
29901 DESCRIPTOR DIDD_Table[MAX_DESCRIPTORS];
29902
29903+ pax_track_stack();
29904+
29905 DIVA_DIDD_Read(DIDD_Table, sizeof(DIDD_Table));
29906
29907 for (x = 0; x < MAX_DESCRIPTORS; x++) {
29908diff -urNp linux-2.6.32.41/drivers/isdn/hardware/eicon/divasfunc.c linux-2.6.32.41/drivers/isdn/hardware/eicon/divasfunc.c
29909--- linux-2.6.32.41/drivers/isdn/hardware/eicon/divasfunc.c 2011-03-27 14:31:47.000000000 -0400
29910+++ linux-2.6.32.41/drivers/isdn/hardware/eicon/divasfunc.c 2011-05-16 21:46:57.000000000 -0400
29911@@ -161,6 +161,8 @@ static int DIVA_INIT_FUNCTION connect_di
29912 IDI_SYNC_REQ req;
29913 DESCRIPTOR DIDD_Table[MAX_DESCRIPTORS];
29914
29915+ pax_track_stack();
29916+
29917 DIVA_DIDD_Read(DIDD_Table, sizeof(DIDD_Table));
29918
29919 for (x = 0; x < MAX_DESCRIPTORS; x++) {
29920diff -urNp linux-2.6.32.41/drivers/isdn/hardware/eicon/idifunc.c linux-2.6.32.41/drivers/isdn/hardware/eicon/idifunc.c
29921--- linux-2.6.32.41/drivers/isdn/hardware/eicon/idifunc.c 2011-03-27 14:31:47.000000000 -0400
29922+++ linux-2.6.32.41/drivers/isdn/hardware/eicon/idifunc.c 2011-05-16 21:46:57.000000000 -0400
29923@@ -188,6 +188,8 @@ static int DIVA_INIT_FUNCTION connect_di
29924 IDI_SYNC_REQ req;
29925 DESCRIPTOR DIDD_Table[MAX_DESCRIPTORS];
29926
29927+ pax_track_stack();
29928+
29929 DIVA_DIDD_Read(DIDD_Table, sizeof(DIDD_Table));
29930
29931 for (x = 0; x < MAX_DESCRIPTORS; x++) {
29932diff -urNp linux-2.6.32.41/drivers/isdn/hardware/eicon/message.c linux-2.6.32.41/drivers/isdn/hardware/eicon/message.c
29933--- linux-2.6.32.41/drivers/isdn/hardware/eicon/message.c 2011-03-27 14:31:47.000000000 -0400
29934+++ linux-2.6.32.41/drivers/isdn/hardware/eicon/message.c 2011-05-16 21:46:57.000000000 -0400
29935@@ -4889,6 +4889,8 @@ static void sig_ind(PLCI *plci)
29936 dword d;
29937 word w;
29938
29939+ pax_track_stack();
29940+
29941 a = plci->adapter;
29942 Id = ((word)plci->Id<<8)|a->Id;
29943 PUT_WORD(&SS_Ind[4],0x0000);
29944@@ -7484,6 +7486,8 @@ static word add_b1(PLCI *plci, API_PARSE
29945 word j, n, w;
29946 dword d;
29947
29948+ pax_track_stack();
29949+
29950
29951 for(i=0;i<8;i++) bp_parms[i].length = 0;
29952 for(i=0;i<2;i++) global_config[i].length = 0;
29953@@ -7958,6 +7962,8 @@ static word add_b23(PLCI *plci, API_PARS
29954 const byte llc3[] = {4,3,2,2,6,6,0};
29955 const byte header[] = {0,2,3,3,0,0,0};
29956
29957+ pax_track_stack();
29958+
29959 for(i=0;i<8;i++) bp_parms[i].length = 0;
29960 for(i=0;i<6;i++) b2_config_parms[i].length = 0;
29961 for(i=0;i<5;i++) b3_config_parms[i].length = 0;
29962@@ -14761,6 +14767,8 @@ static void group_optimization(DIVA_CAPI
29963 word appl_number_group_type[MAX_APPL];
29964 PLCI *auxplci;
29965
29966+ pax_track_stack();
29967+
29968 set_group_ind_mask (plci); /* all APPLs within this inc. call are allowed to dial in */
29969
29970 if(!a->group_optimization_enabled)
29971diff -urNp linux-2.6.32.41/drivers/isdn/hardware/eicon/mntfunc.c linux-2.6.32.41/drivers/isdn/hardware/eicon/mntfunc.c
29972--- linux-2.6.32.41/drivers/isdn/hardware/eicon/mntfunc.c 2011-03-27 14:31:47.000000000 -0400
29973+++ linux-2.6.32.41/drivers/isdn/hardware/eicon/mntfunc.c 2011-05-16 21:46:57.000000000 -0400
29974@@ -79,6 +79,8 @@ static int DIVA_INIT_FUNCTION connect_di
29975 IDI_SYNC_REQ req;
29976 DESCRIPTOR DIDD_Table[MAX_DESCRIPTORS];
29977
29978+ pax_track_stack();
29979+
29980 DIVA_DIDD_Read(DIDD_Table, sizeof(DIDD_Table));
29981
29982 for (x = 0; x < MAX_DESCRIPTORS; x++) {
29983diff -urNp linux-2.6.32.41/drivers/isdn/i4l/isdn_common.c linux-2.6.32.41/drivers/isdn/i4l/isdn_common.c
29984--- linux-2.6.32.41/drivers/isdn/i4l/isdn_common.c 2011-03-27 14:31:47.000000000 -0400
29985+++ linux-2.6.32.41/drivers/isdn/i4l/isdn_common.c 2011-05-16 21:46:57.000000000 -0400
29986@@ -1290,6 +1290,8 @@ isdn_ioctl(struct inode *inode, struct f
29987 } iocpar;
29988 void __user *argp = (void __user *)arg;
29989
29990+ pax_track_stack();
29991+
29992 #define name iocpar.name
29993 #define bname iocpar.bname
29994 #define iocts iocpar.iocts
29995diff -urNp linux-2.6.32.41/drivers/isdn/icn/icn.c linux-2.6.32.41/drivers/isdn/icn/icn.c
29996--- linux-2.6.32.41/drivers/isdn/icn/icn.c 2011-03-27 14:31:47.000000000 -0400
29997+++ linux-2.6.32.41/drivers/isdn/icn/icn.c 2011-04-17 15:56:46.000000000 -0400
29998@@ -1044,7 +1044,7 @@ icn_writecmd(const u_char * buf, int len
29999 if (count > len)
30000 count = len;
30001 if (user) {
30002- if (copy_from_user(msg, buf, count))
30003+ if (count > sizeof msg || copy_from_user(msg, buf, count))
30004 return -EFAULT;
30005 } else
30006 memcpy(msg, buf, count);
30007diff -urNp linux-2.6.32.41/drivers/isdn/mISDN/socket.c linux-2.6.32.41/drivers/isdn/mISDN/socket.c
30008--- linux-2.6.32.41/drivers/isdn/mISDN/socket.c 2011-03-27 14:31:47.000000000 -0400
30009+++ linux-2.6.32.41/drivers/isdn/mISDN/socket.c 2011-04-17 15:56:46.000000000 -0400
30010@@ -391,6 +391,7 @@ data_sock_ioctl(struct socket *sock, uns
30011 if (dev) {
30012 struct mISDN_devinfo di;
30013
30014+ memset(&di, 0, sizeof(di));
30015 di.id = dev->id;
30016 di.Dprotocols = dev->Dprotocols;
30017 di.Bprotocols = dev->Bprotocols | get_all_Bprotocols();
30018@@ -671,6 +672,7 @@ base_sock_ioctl(struct socket *sock, uns
30019 if (dev) {
30020 struct mISDN_devinfo di;
30021
30022+ memset(&di, 0, sizeof(di));
30023 di.id = dev->id;
30024 di.Dprotocols = dev->Dprotocols;
30025 di.Bprotocols = dev->Bprotocols | get_all_Bprotocols();
30026diff -urNp linux-2.6.32.41/drivers/isdn/sc/interrupt.c linux-2.6.32.41/drivers/isdn/sc/interrupt.c
30027--- linux-2.6.32.41/drivers/isdn/sc/interrupt.c 2011-03-27 14:31:47.000000000 -0400
30028+++ linux-2.6.32.41/drivers/isdn/sc/interrupt.c 2011-04-17 15:56:46.000000000 -0400
30029@@ -112,11 +112,19 @@ irqreturn_t interrupt_handler(int dummy,
30030 }
30031 else if(callid>=0x0000 && callid<=0x7FFF)
30032 {
30033+ int len;
30034+
30035 pr_debug("%s: Got Incoming Call\n",
30036 sc_adapter[card]->devicename);
30037- strcpy(setup.phone,&(rcvmsg.msg_data.byte_array[4]));
30038- strcpy(setup.eazmsn,
30039- sc_adapter[card]->channel[rcvmsg.phy_link_no-1].dn);
30040+ len = strlcpy(setup.phone, &(rcvmsg.msg_data.byte_array[4]),
30041+ sizeof(setup.phone));
30042+ if (len >= sizeof(setup.phone))
30043+ continue;
30044+ len = strlcpy(setup.eazmsn,
30045+ sc_adapter[card]->channel[rcvmsg.phy_link_no - 1].dn,
30046+ sizeof(setup.eazmsn));
30047+ if (len >= sizeof(setup.eazmsn))
30048+ continue;
30049 setup.si1 = 7;
30050 setup.si2 = 0;
30051 setup.plan = 0;
30052@@ -176,7 +184,9 @@ irqreturn_t interrupt_handler(int dummy,
30053 * Handle a GetMyNumber Rsp
30054 */
30055 if (IS_CE_MESSAGE(rcvmsg,Call,0,GetMyNumber)){
30056- strcpy(sc_adapter[card]->channel[rcvmsg.phy_link_no-1].dn,rcvmsg.msg_data.byte_array);
30057+ strlcpy(sc_adapter[card]->channel[rcvmsg.phy_link_no - 1].dn,
30058+ rcvmsg.msg_data.byte_array,
30059+ sizeof(rcvmsg.msg_data.byte_array));
30060 continue;
30061 }
30062
30063diff -urNp linux-2.6.32.41/drivers/lguest/core.c linux-2.6.32.41/drivers/lguest/core.c
30064--- linux-2.6.32.41/drivers/lguest/core.c 2011-03-27 14:31:47.000000000 -0400
30065+++ linux-2.6.32.41/drivers/lguest/core.c 2011-04-17 15:56:46.000000000 -0400
30066@@ -91,9 +91,17 @@ static __init int map_switcher(void)
30067 * it's worked so far. The end address needs +1 because __get_vm_area
30068 * allocates an extra guard page, so we need space for that.
30069 */
30070+
30071+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
30072+ switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
30073+ VM_ALLOC | VM_KERNEXEC, SWITCHER_ADDR, SWITCHER_ADDR
30074+ + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
30075+#else
30076 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
30077 VM_ALLOC, SWITCHER_ADDR, SWITCHER_ADDR
30078 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
30079+#endif
30080+
30081 if (!switcher_vma) {
30082 err = -ENOMEM;
30083 printk("lguest: could not map switcher pages high\n");
30084@@ -118,7 +126,7 @@ static __init int map_switcher(void)
30085 * Now the Switcher is mapped at the right address, we can't fail!
30086 * Copy in the compiled-in Switcher code (from <arch>_switcher.S).
30087 */
30088- memcpy(switcher_vma->addr, start_switcher_text,
30089+ memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
30090 end_switcher_text - start_switcher_text);
30091
30092 printk(KERN_INFO "lguest: mapped switcher at %p\n",
30093diff -urNp linux-2.6.32.41/drivers/lguest/x86/core.c linux-2.6.32.41/drivers/lguest/x86/core.c
30094--- linux-2.6.32.41/drivers/lguest/x86/core.c 2011-03-27 14:31:47.000000000 -0400
30095+++ linux-2.6.32.41/drivers/lguest/x86/core.c 2011-04-17 15:56:46.000000000 -0400
30096@@ -59,7 +59,7 @@ static struct {
30097 /* Offset from where switcher.S was compiled to where we've copied it */
30098 static unsigned long switcher_offset(void)
30099 {
30100- return SWITCHER_ADDR - (unsigned long)start_switcher_text;
30101+ return SWITCHER_ADDR - (unsigned long)ktla_ktva(start_switcher_text);
30102 }
30103
30104 /* This cpu's struct lguest_pages. */
30105@@ -100,7 +100,13 @@ static void copy_in_guest_info(struct lg
30106 * These copies are pretty cheap, so we do them unconditionally: */
30107 /* Save the current Host top-level page directory.
30108 */
30109+
30110+#ifdef CONFIG_PAX_PER_CPU_PGD
30111+ pages->state.host_cr3 = read_cr3();
30112+#else
30113 pages->state.host_cr3 = __pa(current->mm->pgd);
30114+#endif
30115+
30116 /*
30117 * Set up the Guest's page tables to see this CPU's pages (and no
30118 * other CPU's pages).
30119@@ -535,7 +541,7 @@ void __init lguest_arch_host_init(void)
30120 * compiled-in switcher code and the high-mapped copy we just made.
30121 */
30122 for (i = 0; i < IDT_ENTRIES; i++)
30123- default_idt_entries[i] += switcher_offset();
30124+ default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
30125
30126 /*
30127 * Set up the Switcher's per-cpu areas.
30128@@ -618,7 +624,7 @@ void __init lguest_arch_host_init(void)
30129 * it will be undisturbed when we switch. To change %cs and jump we
30130 * need this structure to feed to Intel's "lcall" instruction.
30131 */
30132- lguest_entry.offset = (long)switch_to_guest + switcher_offset();
30133+ lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
30134 lguest_entry.segment = LGUEST_CS;
30135
30136 /*
30137diff -urNp linux-2.6.32.41/drivers/lguest/x86/switcher_32.S linux-2.6.32.41/drivers/lguest/x86/switcher_32.S
30138--- linux-2.6.32.41/drivers/lguest/x86/switcher_32.S 2011-03-27 14:31:47.000000000 -0400
30139+++ linux-2.6.32.41/drivers/lguest/x86/switcher_32.S 2011-04-17 15:56:46.000000000 -0400
30140@@ -87,6 +87,7 @@
30141 #include <asm/page.h>
30142 #include <asm/segment.h>
30143 #include <asm/lguest.h>
30144+#include <asm/processor-flags.h>
30145
30146 // We mark the start of the code to copy
30147 // It's placed in .text tho it's never run here
30148@@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
30149 // Changes type when we load it: damn Intel!
30150 // For after we switch over our page tables
30151 // That entry will be read-only: we'd crash.
30152+
30153+#ifdef CONFIG_PAX_KERNEXEC
30154+ mov %cr0, %edx
30155+ xor $X86_CR0_WP, %edx
30156+ mov %edx, %cr0
30157+#endif
30158+
30159 movl $(GDT_ENTRY_TSS*8), %edx
30160 ltr %dx
30161
30162@@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
30163 // Let's clear it again for our return.
30164 // The GDT descriptor of the Host
30165 // Points to the table after two "size" bytes
30166- movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
30167+ movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
30168 // Clear "used" from type field (byte 5, bit 2)
30169- andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
30170+ andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
30171+
30172+#ifdef CONFIG_PAX_KERNEXEC
30173+ mov %cr0, %eax
30174+ xor $X86_CR0_WP, %eax
30175+ mov %eax, %cr0
30176+#endif
30177
30178 // Once our page table's switched, the Guest is live!
30179 // The Host fades as we run this final step.
30180@@ -295,13 +309,12 @@ deliver_to_host:
30181 // I consulted gcc, and it gave
30182 // These instructions, which I gladly credit:
30183 leal (%edx,%ebx,8), %eax
30184- movzwl (%eax),%edx
30185- movl 4(%eax), %eax
30186- xorw %ax, %ax
30187- orl %eax, %edx
30188+ movl 4(%eax), %edx
30189+ movw (%eax), %dx
30190 // Now the address of the handler's in %edx
30191 // We call it now: its "iret" drops us home.
30192- jmp *%edx
30193+ ljmp $__KERNEL_CS, $1f
30194+1: jmp *%edx
30195
30196 // Every interrupt can come to us here
30197 // But we must truly tell each apart.
30198diff -urNp linux-2.6.32.41/drivers/macintosh/via-pmu-backlight.c linux-2.6.32.41/drivers/macintosh/via-pmu-backlight.c
30199--- linux-2.6.32.41/drivers/macintosh/via-pmu-backlight.c 2011-03-27 14:31:47.000000000 -0400
30200+++ linux-2.6.32.41/drivers/macintosh/via-pmu-backlight.c 2011-04-17 15:56:46.000000000 -0400
30201@@ -15,7 +15,7 @@
30202
30203 #define MAX_PMU_LEVEL 0xFF
30204
30205-static struct backlight_ops pmu_backlight_data;
30206+static const struct backlight_ops pmu_backlight_data;
30207 static DEFINE_SPINLOCK(pmu_backlight_lock);
30208 static int sleeping, uses_pmu_bl;
30209 static u8 bl_curve[FB_BACKLIGHT_LEVELS];
30210@@ -115,7 +115,7 @@ static int pmu_backlight_get_brightness(
30211 return bd->props.brightness;
30212 }
30213
30214-static struct backlight_ops pmu_backlight_data = {
30215+static const struct backlight_ops pmu_backlight_data = {
30216 .get_brightness = pmu_backlight_get_brightness,
30217 .update_status = pmu_backlight_update_status,
30218
30219diff -urNp linux-2.6.32.41/drivers/macintosh/via-pmu.c linux-2.6.32.41/drivers/macintosh/via-pmu.c
30220--- linux-2.6.32.41/drivers/macintosh/via-pmu.c 2011-03-27 14:31:47.000000000 -0400
30221+++ linux-2.6.32.41/drivers/macintosh/via-pmu.c 2011-04-17 15:56:46.000000000 -0400
30222@@ -2232,7 +2232,7 @@ static int pmu_sleep_valid(suspend_state
30223 && (pmac_call_feature(PMAC_FTR_SLEEP_STATE, NULL, 0, -1) >= 0);
30224 }
30225
30226-static struct platform_suspend_ops pmu_pm_ops = {
30227+static const struct platform_suspend_ops pmu_pm_ops = {
30228 .enter = powerbook_sleep,
30229 .valid = pmu_sleep_valid,
30230 };
30231diff -urNp linux-2.6.32.41/drivers/md/dm.c linux-2.6.32.41/drivers/md/dm.c
30232--- linux-2.6.32.41/drivers/md/dm.c 2011-03-27 14:31:47.000000000 -0400
30233+++ linux-2.6.32.41/drivers/md/dm.c 2011-05-04 17:56:28.000000000 -0400
30234@@ -163,9 +163,9 @@ struct mapped_device {
30235 /*
30236 * Event handling.
30237 */
30238- atomic_t event_nr;
30239+ atomic_unchecked_t event_nr;
30240 wait_queue_head_t eventq;
30241- atomic_t uevent_seq;
30242+ atomic_unchecked_t uevent_seq;
30243 struct list_head uevent_list;
30244 spinlock_t uevent_lock; /* Protect access to uevent_list */
30245
30246@@ -1770,8 +1770,8 @@ static struct mapped_device *alloc_dev(i
30247 rwlock_init(&md->map_lock);
30248 atomic_set(&md->holders, 1);
30249 atomic_set(&md->open_count, 0);
30250- atomic_set(&md->event_nr, 0);
30251- atomic_set(&md->uevent_seq, 0);
30252+ atomic_set_unchecked(&md->event_nr, 0);
30253+ atomic_set_unchecked(&md->uevent_seq, 0);
30254 INIT_LIST_HEAD(&md->uevent_list);
30255 spin_lock_init(&md->uevent_lock);
30256
30257@@ -1921,7 +1921,7 @@ static void event_callback(void *context
30258
30259 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
30260
30261- atomic_inc(&md->event_nr);
30262+ atomic_inc_unchecked(&md->event_nr);
30263 wake_up(&md->eventq);
30264 }
30265
30266@@ -2556,18 +2556,18 @@ void dm_kobject_uevent(struct mapped_dev
30267
30268 uint32_t dm_next_uevent_seq(struct mapped_device *md)
30269 {
30270- return atomic_add_return(1, &md->uevent_seq);
30271+ return atomic_add_return_unchecked(1, &md->uevent_seq);
30272 }
30273
30274 uint32_t dm_get_event_nr(struct mapped_device *md)
30275 {
30276- return atomic_read(&md->event_nr);
30277+ return atomic_read_unchecked(&md->event_nr);
30278 }
30279
30280 int dm_wait_event(struct mapped_device *md, int event_nr)
30281 {
30282 return wait_event_interruptible(md->eventq,
30283- (event_nr != atomic_read(&md->event_nr)));
30284+ (event_nr != atomic_read_unchecked(&md->event_nr)));
30285 }
30286
30287 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
30288diff -urNp linux-2.6.32.41/drivers/md/dm-ioctl.c linux-2.6.32.41/drivers/md/dm-ioctl.c
30289--- linux-2.6.32.41/drivers/md/dm-ioctl.c 2011-03-27 14:31:47.000000000 -0400
30290+++ linux-2.6.32.41/drivers/md/dm-ioctl.c 2011-04-17 15:56:46.000000000 -0400
30291@@ -1437,7 +1437,7 @@ static int validate_params(uint cmd, str
30292 cmd == DM_LIST_VERSIONS_CMD)
30293 return 0;
30294
30295- if ((cmd == DM_DEV_CREATE_CMD)) {
30296+ if (cmd == DM_DEV_CREATE_CMD) {
30297 if (!*param->name) {
30298 DMWARN("name not supplied when creating device");
30299 return -EINVAL;
30300diff -urNp linux-2.6.32.41/drivers/md/dm-raid1.c linux-2.6.32.41/drivers/md/dm-raid1.c
30301--- linux-2.6.32.41/drivers/md/dm-raid1.c 2011-03-27 14:31:47.000000000 -0400
30302+++ linux-2.6.32.41/drivers/md/dm-raid1.c 2011-05-04 17:56:28.000000000 -0400
30303@@ -41,7 +41,7 @@ enum dm_raid1_error {
30304
30305 struct mirror {
30306 struct mirror_set *ms;
30307- atomic_t error_count;
30308+ atomic_unchecked_t error_count;
30309 unsigned long error_type;
30310 struct dm_dev *dev;
30311 sector_t offset;
30312@@ -203,7 +203,7 @@ static void fail_mirror(struct mirror *m
30313 * simple way to tell if a device has encountered
30314 * errors.
30315 */
30316- atomic_inc(&m->error_count);
30317+ atomic_inc_unchecked(&m->error_count);
30318
30319 if (test_and_set_bit(error_type, &m->error_type))
30320 return;
30321@@ -225,7 +225,7 @@ static void fail_mirror(struct mirror *m
30322 }
30323
30324 for (new = ms->mirror; new < ms->mirror + ms->nr_mirrors; new++)
30325- if (!atomic_read(&new->error_count)) {
30326+ if (!atomic_read_unchecked(&new->error_count)) {
30327 set_default_mirror(new);
30328 break;
30329 }
30330@@ -363,7 +363,7 @@ static struct mirror *choose_mirror(stru
30331 struct mirror *m = get_default_mirror(ms);
30332
30333 do {
30334- if (likely(!atomic_read(&m->error_count)))
30335+ if (likely(!atomic_read_unchecked(&m->error_count)))
30336 return m;
30337
30338 if (m-- == ms->mirror)
30339@@ -377,7 +377,7 @@ static int default_ok(struct mirror *m)
30340 {
30341 struct mirror *default_mirror = get_default_mirror(m->ms);
30342
30343- return !atomic_read(&default_mirror->error_count);
30344+ return !atomic_read_unchecked(&default_mirror->error_count);
30345 }
30346
30347 static int mirror_available(struct mirror_set *ms, struct bio *bio)
30348@@ -484,7 +484,7 @@ static void do_reads(struct mirror_set *
30349 */
30350 if (likely(region_in_sync(ms, region, 1)))
30351 m = choose_mirror(ms, bio->bi_sector);
30352- else if (m && atomic_read(&m->error_count))
30353+ else if (m && atomic_read_unchecked(&m->error_count))
30354 m = NULL;
30355
30356 if (likely(m))
30357@@ -855,7 +855,7 @@ static int get_mirror(struct mirror_set
30358 }
30359
30360 ms->mirror[mirror].ms = ms;
30361- atomic_set(&(ms->mirror[mirror].error_count), 0);
30362+ atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
30363 ms->mirror[mirror].error_type = 0;
30364 ms->mirror[mirror].offset = offset;
30365
30366@@ -1241,7 +1241,7 @@ static void mirror_resume(struct dm_targ
30367 */
30368 static char device_status_char(struct mirror *m)
30369 {
30370- if (!atomic_read(&(m->error_count)))
30371+ if (!atomic_read_unchecked(&(m->error_count)))
30372 return 'A';
30373
30374 return (test_bit(DM_RAID1_WRITE_ERROR, &(m->error_type))) ? 'D' :
30375diff -urNp linux-2.6.32.41/drivers/md/dm-stripe.c linux-2.6.32.41/drivers/md/dm-stripe.c
30376--- linux-2.6.32.41/drivers/md/dm-stripe.c 2011-03-27 14:31:47.000000000 -0400
30377+++ linux-2.6.32.41/drivers/md/dm-stripe.c 2011-05-04 17:56:28.000000000 -0400
30378@@ -20,7 +20,7 @@ struct stripe {
30379 struct dm_dev *dev;
30380 sector_t physical_start;
30381
30382- atomic_t error_count;
30383+ atomic_unchecked_t error_count;
30384 };
30385
30386 struct stripe_c {
30387@@ -188,7 +188,7 @@ static int stripe_ctr(struct dm_target *
30388 kfree(sc);
30389 return r;
30390 }
30391- atomic_set(&(sc->stripe[i].error_count), 0);
30392+ atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
30393 }
30394
30395 ti->private = sc;
30396@@ -257,7 +257,7 @@ static int stripe_status(struct dm_targe
30397 DMEMIT("%d ", sc->stripes);
30398 for (i = 0; i < sc->stripes; i++) {
30399 DMEMIT("%s ", sc->stripe[i].dev->name);
30400- buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
30401+ buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
30402 'D' : 'A';
30403 }
30404 buffer[i] = '\0';
30405@@ -304,8 +304,8 @@ static int stripe_end_io(struct dm_targe
30406 */
30407 for (i = 0; i < sc->stripes; i++)
30408 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
30409- atomic_inc(&(sc->stripe[i].error_count));
30410- if (atomic_read(&(sc->stripe[i].error_count)) <
30411+ atomic_inc_unchecked(&(sc->stripe[i].error_count));
30412+ if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
30413 DM_IO_ERROR_THRESHOLD)
30414 queue_work(kstriped, &sc->kstriped_ws);
30415 }
30416diff -urNp linux-2.6.32.41/drivers/md/dm-sysfs.c linux-2.6.32.41/drivers/md/dm-sysfs.c
30417--- linux-2.6.32.41/drivers/md/dm-sysfs.c 2011-03-27 14:31:47.000000000 -0400
30418+++ linux-2.6.32.41/drivers/md/dm-sysfs.c 2011-04-17 15:56:46.000000000 -0400
30419@@ -75,7 +75,7 @@ static struct attribute *dm_attrs[] = {
30420 NULL,
30421 };
30422
30423-static struct sysfs_ops dm_sysfs_ops = {
30424+static const struct sysfs_ops dm_sysfs_ops = {
30425 .show = dm_attr_show,
30426 };
30427
30428diff -urNp linux-2.6.32.41/drivers/md/dm-table.c linux-2.6.32.41/drivers/md/dm-table.c
30429--- linux-2.6.32.41/drivers/md/dm-table.c 2011-03-27 14:31:47.000000000 -0400
30430+++ linux-2.6.32.41/drivers/md/dm-table.c 2011-04-17 15:56:46.000000000 -0400
30431@@ -359,7 +359,7 @@ static int device_area_is_invalid(struct
30432 if (!dev_size)
30433 return 0;
30434
30435- if ((start >= dev_size) || (start + len > dev_size)) {
30436+ if ((start >= dev_size) || (len > dev_size - start)) {
30437 DMWARN("%s: %s too small for target: "
30438 "start=%llu, len=%llu, dev_size=%llu",
30439 dm_device_name(ti->table->md), bdevname(bdev, b),
30440diff -urNp linux-2.6.32.41/drivers/md/md.c linux-2.6.32.41/drivers/md/md.c
30441--- linux-2.6.32.41/drivers/md/md.c 2011-03-27 14:31:47.000000000 -0400
30442+++ linux-2.6.32.41/drivers/md/md.c 2011-05-04 17:56:20.000000000 -0400
30443@@ -153,10 +153,10 @@ static int start_readonly;
30444 * start build, activate spare
30445 */
30446 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
30447-static atomic_t md_event_count;
30448+static atomic_unchecked_t md_event_count;
30449 void md_new_event(mddev_t *mddev)
30450 {
30451- atomic_inc(&md_event_count);
30452+ atomic_inc_unchecked(&md_event_count);
30453 wake_up(&md_event_waiters);
30454 }
30455 EXPORT_SYMBOL_GPL(md_new_event);
30456@@ -166,7 +166,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
30457 */
30458 static void md_new_event_inintr(mddev_t *mddev)
30459 {
30460- atomic_inc(&md_event_count);
30461+ atomic_inc_unchecked(&md_event_count);
30462 wake_up(&md_event_waiters);
30463 }
30464
30465@@ -1218,7 +1218,7 @@ static int super_1_load(mdk_rdev_t *rdev
30466
30467 rdev->preferred_minor = 0xffff;
30468 rdev->data_offset = le64_to_cpu(sb->data_offset);
30469- atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
30470+ atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
30471
30472 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
30473 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
30474@@ -1392,7 +1392,7 @@ static void super_1_sync(mddev_t *mddev,
30475 else
30476 sb->resync_offset = cpu_to_le64(0);
30477
30478- sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
30479+ sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
30480
30481 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
30482 sb->size = cpu_to_le64(mddev->dev_sectors);
30483@@ -2214,7 +2214,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_sho
30484 static ssize_t
30485 errors_show(mdk_rdev_t *rdev, char *page)
30486 {
30487- return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
30488+ return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
30489 }
30490
30491 static ssize_t
30492@@ -2223,7 +2223,7 @@ errors_store(mdk_rdev_t *rdev, const cha
30493 char *e;
30494 unsigned long n = simple_strtoul(buf, &e, 10);
30495 if (*buf && (*e == 0 || *e == '\n')) {
30496- atomic_set(&rdev->corrected_errors, n);
30497+ atomic_set_unchecked(&rdev->corrected_errors, n);
30498 return len;
30499 }
30500 return -EINVAL;
30501@@ -2517,7 +2517,7 @@ static void rdev_free(struct kobject *ko
30502 mdk_rdev_t *rdev = container_of(ko, mdk_rdev_t, kobj);
30503 kfree(rdev);
30504 }
30505-static struct sysfs_ops rdev_sysfs_ops = {
30506+static const struct sysfs_ops rdev_sysfs_ops = {
30507 .show = rdev_attr_show,
30508 .store = rdev_attr_store,
30509 };
30510@@ -2566,8 +2566,8 @@ static mdk_rdev_t *md_import_device(dev_
30511 rdev->data_offset = 0;
30512 rdev->sb_events = 0;
30513 atomic_set(&rdev->nr_pending, 0);
30514- atomic_set(&rdev->read_errors, 0);
30515- atomic_set(&rdev->corrected_errors, 0);
30516+ atomic_set_unchecked(&rdev->read_errors, 0);
30517+ atomic_set_unchecked(&rdev->corrected_errors, 0);
30518
30519 size = rdev->bdev->bd_inode->i_size >> BLOCK_SIZE_BITS;
30520 if (!size) {
30521@@ -3887,7 +3887,7 @@ static void md_free(struct kobject *ko)
30522 kfree(mddev);
30523 }
30524
30525-static struct sysfs_ops md_sysfs_ops = {
30526+static const struct sysfs_ops md_sysfs_ops = {
30527 .show = md_attr_show,
30528 .store = md_attr_store,
30529 };
30530@@ -4474,7 +4474,8 @@ out:
30531 err = 0;
30532 blk_integrity_unregister(disk);
30533 md_new_event(mddev);
30534- sysfs_notify_dirent(mddev->sysfs_state);
30535+ if (mddev->sysfs_state)
30536+ sysfs_notify_dirent(mddev->sysfs_state);
30537 return err;
30538 }
30539
30540@@ -5954,7 +5955,7 @@ static int md_seq_show(struct seq_file *
30541
30542 spin_unlock(&pers_lock);
30543 seq_printf(seq, "\n");
30544- mi->event = atomic_read(&md_event_count);
30545+ mi->event = atomic_read_unchecked(&md_event_count);
30546 return 0;
30547 }
30548 if (v == (void*)2) {
30549@@ -6043,7 +6044,7 @@ static int md_seq_show(struct seq_file *
30550 chunk_kb ? "KB" : "B");
30551 if (bitmap->file) {
30552 seq_printf(seq, ", file: ");
30553- seq_path(seq, &bitmap->file->f_path, " \t\n");
30554+ seq_path(seq, &bitmap->file->f_path, " \t\n\\");
30555 }
30556
30557 seq_printf(seq, "\n");
30558@@ -6077,7 +6078,7 @@ static int md_seq_open(struct inode *ino
30559 else {
30560 struct seq_file *p = file->private_data;
30561 p->private = mi;
30562- mi->event = atomic_read(&md_event_count);
30563+ mi->event = atomic_read_unchecked(&md_event_count);
30564 }
30565 return error;
30566 }
30567@@ -6093,7 +6094,7 @@ static unsigned int mdstat_poll(struct f
30568 /* always allow read */
30569 mask = POLLIN | POLLRDNORM;
30570
30571- if (mi->event != atomic_read(&md_event_count))
30572+ if (mi->event != atomic_read_unchecked(&md_event_count))
30573 mask |= POLLERR | POLLPRI;
30574 return mask;
30575 }
30576@@ -6137,7 +6138,7 @@ static int is_mddev_idle(mddev_t *mddev,
30577 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
30578 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
30579 (int)part_stat_read(&disk->part0, sectors[1]) -
30580- atomic_read(&disk->sync_io);
30581+ atomic_read_unchecked(&disk->sync_io);
30582 /* sync IO will cause sync_io to increase before the disk_stats
30583 * as sync_io is counted when a request starts, and
30584 * disk_stats is counted when it completes.
30585diff -urNp linux-2.6.32.41/drivers/md/md.h linux-2.6.32.41/drivers/md/md.h
30586--- linux-2.6.32.41/drivers/md/md.h 2011-03-27 14:31:47.000000000 -0400
30587+++ linux-2.6.32.41/drivers/md/md.h 2011-05-04 17:56:20.000000000 -0400
30588@@ -94,10 +94,10 @@ struct mdk_rdev_s
30589 * only maintained for arrays that
30590 * support hot removal
30591 */
30592- atomic_t read_errors; /* number of consecutive read errors that
30593+ atomic_unchecked_t read_errors; /* number of consecutive read errors that
30594 * we have tried to ignore.
30595 */
30596- atomic_t corrected_errors; /* number of corrected read errors,
30597+ atomic_unchecked_t corrected_errors; /* number of corrected read errors,
30598 * for reporting to userspace and storing
30599 * in superblock.
30600 */
30601@@ -304,7 +304,7 @@ static inline void rdev_dec_pending(mdk_
30602
30603 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
30604 {
30605- atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
30606+ atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
30607 }
30608
30609 struct mdk_personality
30610diff -urNp linux-2.6.32.41/drivers/md/raid10.c linux-2.6.32.41/drivers/md/raid10.c
30611--- linux-2.6.32.41/drivers/md/raid10.c 2011-03-27 14:31:47.000000000 -0400
30612+++ linux-2.6.32.41/drivers/md/raid10.c 2011-05-04 17:56:28.000000000 -0400
30613@@ -1255,7 +1255,7 @@ static void end_sync_read(struct bio *bi
30614 if (test_bit(BIO_UPTODATE, &bio->bi_flags))
30615 set_bit(R10BIO_Uptodate, &r10_bio->state);
30616 else {
30617- atomic_add(r10_bio->sectors,
30618+ atomic_add_unchecked(r10_bio->sectors,
30619 &conf->mirrors[d].rdev->corrected_errors);
30620 if (!test_bit(MD_RECOVERY_SYNC, &conf->mddev->recovery))
30621 md_error(r10_bio->mddev,
30622@@ -1520,7 +1520,7 @@ static void fix_read_error(conf_t *conf,
30623 test_bit(In_sync, &rdev->flags)) {
30624 atomic_inc(&rdev->nr_pending);
30625 rcu_read_unlock();
30626- atomic_add(s, &rdev->corrected_errors);
30627+ atomic_add_unchecked(s, &rdev->corrected_errors);
30628 if (sync_page_io(rdev->bdev,
30629 r10_bio->devs[sl].addr +
30630 sect + rdev->data_offset,
30631diff -urNp linux-2.6.32.41/drivers/md/raid1.c linux-2.6.32.41/drivers/md/raid1.c
30632--- linux-2.6.32.41/drivers/md/raid1.c 2011-03-27 14:31:47.000000000 -0400
30633+++ linux-2.6.32.41/drivers/md/raid1.c 2011-05-04 17:56:28.000000000 -0400
30634@@ -1415,7 +1415,7 @@ static void sync_request_write(mddev_t *
30635 if (r1_bio->bios[d]->bi_end_io != end_sync_read)
30636 continue;
30637 rdev = conf->mirrors[d].rdev;
30638- atomic_add(s, &rdev->corrected_errors);
30639+ atomic_add_unchecked(s, &rdev->corrected_errors);
30640 if (sync_page_io(rdev->bdev,
30641 sect + rdev->data_offset,
30642 s<<9,
30643@@ -1564,7 +1564,7 @@ static void fix_read_error(conf_t *conf,
30644 /* Well, this device is dead */
30645 md_error(mddev, rdev);
30646 else {
30647- atomic_add(s, &rdev->corrected_errors);
30648+ atomic_add_unchecked(s, &rdev->corrected_errors);
30649 printk(KERN_INFO
30650 "raid1:%s: read error corrected "
30651 "(%d sectors at %llu on %s)\n",
30652diff -urNp linux-2.6.32.41/drivers/md/raid5.c linux-2.6.32.41/drivers/md/raid5.c
30653--- linux-2.6.32.41/drivers/md/raid5.c 2011-03-27 14:31:47.000000000 -0400
30654+++ linux-2.6.32.41/drivers/md/raid5.c 2011-05-16 21:46:57.000000000 -0400
30655@@ -482,7 +482,7 @@ static void ops_run_io(struct stripe_hea
30656 bi->bi_next = NULL;
30657 if (rw == WRITE &&
30658 test_bit(R5_ReWrite, &sh->dev[i].flags))
30659- atomic_add(STRIPE_SECTORS,
30660+ atomic_add_unchecked(STRIPE_SECTORS,
30661 &rdev->corrected_errors);
30662 generic_make_request(bi);
30663 } else {
30664@@ -1517,15 +1517,15 @@ static void raid5_end_read_request(struc
30665 clear_bit(R5_ReadError, &sh->dev[i].flags);
30666 clear_bit(R5_ReWrite, &sh->dev[i].flags);
30667 }
30668- if (atomic_read(&conf->disks[i].rdev->read_errors))
30669- atomic_set(&conf->disks[i].rdev->read_errors, 0);
30670+ if (atomic_read_unchecked(&conf->disks[i].rdev->read_errors))
30671+ atomic_set_unchecked(&conf->disks[i].rdev->read_errors, 0);
30672 } else {
30673 const char *bdn = bdevname(conf->disks[i].rdev->bdev, b);
30674 int retry = 0;
30675 rdev = conf->disks[i].rdev;
30676
30677 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
30678- atomic_inc(&rdev->read_errors);
30679+ atomic_inc_unchecked(&rdev->read_errors);
30680 if (conf->mddev->degraded >= conf->max_degraded)
30681 printk_rl(KERN_WARNING
30682 "raid5:%s: read error not correctable "
30683@@ -1543,7 +1543,7 @@ static void raid5_end_read_request(struc
30684 (unsigned long long)(sh->sector
30685 + rdev->data_offset),
30686 bdn);
30687- else if (atomic_read(&rdev->read_errors)
30688+ else if (atomic_read_unchecked(&rdev->read_errors)
30689 > conf->max_nr_stripes)
30690 printk(KERN_WARNING
30691 "raid5:%s: Too many read errors, failing device %s.\n",
30692@@ -1870,6 +1870,7 @@ static sector_t compute_blocknr(struct s
30693 sector_t r_sector;
30694 struct stripe_head sh2;
30695
30696+ pax_track_stack();
30697
30698 chunk_offset = sector_div(new_sector, sectors_per_chunk);
30699 stripe = new_sector;
30700diff -urNp linux-2.6.32.41/drivers/media/common/saa7146_hlp.c linux-2.6.32.41/drivers/media/common/saa7146_hlp.c
30701--- linux-2.6.32.41/drivers/media/common/saa7146_hlp.c 2011-03-27 14:31:47.000000000 -0400
30702+++ linux-2.6.32.41/drivers/media/common/saa7146_hlp.c 2011-05-16 21:46:57.000000000 -0400
30703@@ -353,6 +353,8 @@ static void calculate_clipping_registers
30704
30705 int x[32], y[32], w[32], h[32];
30706
30707+ pax_track_stack();
30708+
30709 /* clear out memory */
30710 memset(&line_list[0], 0x00, sizeof(u32)*32);
30711 memset(&pixel_list[0], 0x00, sizeof(u32)*32);
30712diff -urNp linux-2.6.32.41/drivers/media/dvb/dvb-core/dvb_ca_en50221.c linux-2.6.32.41/drivers/media/dvb/dvb-core/dvb_ca_en50221.c
30713--- linux-2.6.32.41/drivers/media/dvb/dvb-core/dvb_ca_en50221.c 2011-03-27 14:31:47.000000000 -0400
30714+++ linux-2.6.32.41/drivers/media/dvb/dvb-core/dvb_ca_en50221.c 2011-05-16 21:46:57.000000000 -0400
30715@@ -590,6 +590,8 @@ static int dvb_ca_en50221_read_data(stru
30716 u8 buf[HOST_LINK_BUF_SIZE];
30717 int i;
30718
30719+ pax_track_stack();
30720+
30721 dprintk("%s\n", __func__);
30722
30723 /* check if we have space for a link buf in the rx_buffer */
30724@@ -1285,6 +1287,8 @@ static ssize_t dvb_ca_en50221_io_write(s
30725 unsigned long timeout;
30726 int written;
30727
30728+ pax_track_stack();
30729+
30730 dprintk("%s\n", __func__);
30731
30732 /* Incoming packet has a 2 byte header. hdr[0] = slot_id, hdr[1] = connection_id */
30733diff -urNp linux-2.6.32.41/drivers/media/dvb/dvb-core/dvbdev.c linux-2.6.32.41/drivers/media/dvb/dvb-core/dvbdev.c
30734--- linux-2.6.32.41/drivers/media/dvb/dvb-core/dvbdev.c 2011-03-27 14:31:47.000000000 -0400
30735+++ linux-2.6.32.41/drivers/media/dvb/dvb-core/dvbdev.c 2011-04-17 15:56:46.000000000 -0400
30736@@ -191,6 +191,7 @@ int dvb_register_device(struct dvb_adapt
30737 const struct dvb_device *template, void *priv, int type)
30738 {
30739 struct dvb_device *dvbdev;
30740+ /* cannot be const */
30741 struct file_operations *dvbdevfops;
30742 struct device *clsdev;
30743 int minor;
30744diff -urNp linux-2.6.32.41/drivers/media/dvb/dvb-usb/dib0700_core.c linux-2.6.32.41/drivers/media/dvb/dvb-usb/dib0700_core.c
30745--- linux-2.6.32.41/drivers/media/dvb/dvb-usb/dib0700_core.c 2011-03-27 14:31:47.000000000 -0400
30746+++ linux-2.6.32.41/drivers/media/dvb/dvb-usb/dib0700_core.c 2011-05-16 21:46:57.000000000 -0400
30747@@ -332,6 +332,8 @@ int dib0700_download_firmware(struct usb
30748
30749 u8 buf[260];
30750
30751+ pax_track_stack();
30752+
30753 while ((ret = dvb_usb_get_hexline(fw, &hx, &pos)) > 0) {
30754 deb_fwdata("writing to address 0x%08x (buffer: 0x%02x %02x)\n",hx.addr, hx.len, hx.chk);
30755
30756diff -urNp linux-2.6.32.41/drivers/media/dvb/frontends/or51211.c linux-2.6.32.41/drivers/media/dvb/frontends/or51211.c
30757--- linux-2.6.32.41/drivers/media/dvb/frontends/or51211.c 2011-03-27 14:31:47.000000000 -0400
30758+++ linux-2.6.32.41/drivers/media/dvb/frontends/or51211.c 2011-05-16 21:46:57.000000000 -0400
30759@@ -113,6 +113,8 @@ static int or51211_load_firmware (struct
30760 u8 tudata[585];
30761 int i;
30762
30763+ pax_track_stack();
30764+
30765 dprintk("Firmware is %zd bytes\n",fw->size);
30766
30767 /* Get eprom data */
30768diff -urNp linux-2.6.32.41/drivers/media/radio/radio-cadet.c linux-2.6.32.41/drivers/media/radio/radio-cadet.c
30769--- linux-2.6.32.41/drivers/media/radio/radio-cadet.c 2011-03-27 14:31:47.000000000 -0400
30770+++ linux-2.6.32.41/drivers/media/radio/radio-cadet.c 2011-04-17 15:56:46.000000000 -0400
30771@@ -347,7 +347,7 @@ static ssize_t cadet_read(struct file *f
30772 while (i < count && dev->rdsin != dev->rdsout)
30773 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
30774
30775- if (copy_to_user(data, readbuf, i))
30776+ if (i > sizeof readbuf || copy_to_user(data, readbuf, i))
30777 return -EFAULT;
30778 return i;
30779 }
30780diff -urNp linux-2.6.32.41/drivers/media/video/cx18/cx18-driver.c linux-2.6.32.41/drivers/media/video/cx18/cx18-driver.c
30781--- linux-2.6.32.41/drivers/media/video/cx18/cx18-driver.c 2011-03-27 14:31:47.000000000 -0400
30782+++ linux-2.6.32.41/drivers/media/video/cx18/cx18-driver.c 2011-05-16 21:46:57.000000000 -0400
30783@@ -56,7 +56,7 @@ static struct pci_device_id cx18_pci_tbl
30784
30785 MODULE_DEVICE_TABLE(pci, cx18_pci_tbl);
30786
30787-static atomic_t cx18_instance = ATOMIC_INIT(0);
30788+static atomic_unchecked_t cx18_instance = ATOMIC_INIT(0);
30789
30790 /* Parameter declarations */
30791 static int cardtype[CX18_MAX_CARDS];
30792@@ -288,6 +288,8 @@ void cx18_read_eeprom(struct cx18 *cx, s
30793 struct i2c_client c;
30794 u8 eedata[256];
30795
30796+ pax_track_stack();
30797+
30798 memset(&c, 0, sizeof(c));
30799 strlcpy(c.name, "cx18 tveeprom tmp", sizeof(c.name));
30800 c.adapter = &cx->i2c_adap[0];
30801@@ -800,7 +802,7 @@ static int __devinit cx18_probe(struct p
30802 struct cx18 *cx;
30803
30804 /* FIXME - module parameter arrays constrain max instances */
30805- i = atomic_inc_return(&cx18_instance) - 1;
30806+ i = atomic_inc_return_unchecked(&cx18_instance) - 1;
30807 if (i >= CX18_MAX_CARDS) {
30808 printk(KERN_ERR "cx18: cannot manage card %d, driver has a "
30809 "limit of 0 - %d\n", i, CX18_MAX_CARDS - 1);
30810diff -urNp linux-2.6.32.41/drivers/media/video/ivtv/ivtv-driver.c linux-2.6.32.41/drivers/media/video/ivtv/ivtv-driver.c
30811--- linux-2.6.32.41/drivers/media/video/ivtv/ivtv-driver.c 2011-03-27 14:31:47.000000000 -0400
30812+++ linux-2.6.32.41/drivers/media/video/ivtv/ivtv-driver.c 2011-05-04 17:56:28.000000000 -0400
30813@@ -79,7 +79,7 @@ static struct pci_device_id ivtv_pci_tbl
30814 MODULE_DEVICE_TABLE(pci,ivtv_pci_tbl);
30815
30816 /* ivtv instance counter */
30817-static atomic_t ivtv_instance = ATOMIC_INIT(0);
30818+static atomic_unchecked_t ivtv_instance = ATOMIC_INIT(0);
30819
30820 /* Parameter declarations */
30821 static int cardtype[IVTV_MAX_CARDS];
30822diff -urNp linux-2.6.32.41/drivers/media/video/omap24xxcam.c linux-2.6.32.41/drivers/media/video/omap24xxcam.c
30823--- linux-2.6.32.41/drivers/media/video/omap24xxcam.c 2011-03-27 14:31:47.000000000 -0400
30824+++ linux-2.6.32.41/drivers/media/video/omap24xxcam.c 2011-05-04 17:56:28.000000000 -0400
30825@@ -401,7 +401,7 @@ static void omap24xxcam_vbq_complete(str
30826 spin_unlock_irqrestore(&cam->core_enable_disable_lock, flags);
30827
30828 do_gettimeofday(&vb->ts);
30829- vb->field_count = atomic_add_return(2, &fh->field_count);
30830+ vb->field_count = atomic_add_return_unchecked(2, &fh->field_count);
30831 if (csr & csr_error) {
30832 vb->state = VIDEOBUF_ERROR;
30833 if (!atomic_read(&fh->cam->in_reset)) {
30834diff -urNp linux-2.6.32.41/drivers/media/video/omap24xxcam.h linux-2.6.32.41/drivers/media/video/omap24xxcam.h
30835--- linux-2.6.32.41/drivers/media/video/omap24xxcam.h 2011-03-27 14:31:47.000000000 -0400
30836+++ linux-2.6.32.41/drivers/media/video/omap24xxcam.h 2011-05-04 17:56:28.000000000 -0400
30837@@ -533,7 +533,7 @@ struct omap24xxcam_fh {
30838 spinlock_t vbq_lock; /* spinlock for the videobuf queue */
30839 struct videobuf_queue vbq;
30840 struct v4l2_pix_format pix; /* serialise pix by vbq->lock */
30841- atomic_t field_count; /* field counter for videobuf_buffer */
30842+ atomic_unchecked_t field_count; /* field counter for videobuf_buffer */
30843 /* accessing cam here doesn't need serialisation: it's constant */
30844 struct omap24xxcam_device *cam;
30845 };
30846diff -urNp linux-2.6.32.41/drivers/media/video/pvrusb2/pvrusb2-eeprom.c linux-2.6.32.41/drivers/media/video/pvrusb2/pvrusb2-eeprom.c
30847--- linux-2.6.32.41/drivers/media/video/pvrusb2/pvrusb2-eeprom.c 2011-03-27 14:31:47.000000000 -0400
30848+++ linux-2.6.32.41/drivers/media/video/pvrusb2/pvrusb2-eeprom.c 2011-05-16 21:46:57.000000000 -0400
30849@@ -119,6 +119,8 @@ int pvr2_eeprom_analyze(struct pvr2_hdw
30850 u8 *eeprom;
30851 struct tveeprom tvdata;
30852
30853+ pax_track_stack();
30854+
30855 memset(&tvdata,0,sizeof(tvdata));
30856
30857 eeprom = pvr2_eeprom_fetch(hdw);
30858diff -urNp linux-2.6.32.41/drivers/media/video/saa7134/saa6752hs.c linux-2.6.32.41/drivers/media/video/saa7134/saa6752hs.c
30859--- linux-2.6.32.41/drivers/media/video/saa7134/saa6752hs.c 2011-03-27 14:31:47.000000000 -0400
30860+++ linux-2.6.32.41/drivers/media/video/saa7134/saa6752hs.c 2011-05-16 21:46:57.000000000 -0400
30861@@ -683,6 +683,8 @@ static int saa6752hs_init(struct v4l2_su
30862 unsigned char localPAT[256];
30863 unsigned char localPMT[256];
30864
30865+ pax_track_stack();
30866+
30867 /* Set video format - must be done first as it resets other settings */
30868 set_reg8(client, 0x41, h->video_format);
30869
30870diff -urNp linux-2.6.32.41/drivers/media/video/saa7164/saa7164-cmd.c linux-2.6.32.41/drivers/media/video/saa7164/saa7164-cmd.c
30871--- linux-2.6.32.41/drivers/media/video/saa7164/saa7164-cmd.c 2011-03-27 14:31:47.000000000 -0400
30872+++ linux-2.6.32.41/drivers/media/video/saa7164/saa7164-cmd.c 2011-05-16 21:46:57.000000000 -0400
30873@@ -87,6 +87,8 @@ int saa7164_irq_dequeue(struct saa7164_d
30874 wait_queue_head_t *q = 0;
30875 dprintk(DBGLVL_CMD, "%s()\n", __func__);
30876
30877+ pax_track_stack();
30878+
30879 /* While any outstand message on the bus exists... */
30880 do {
30881
30882@@ -126,6 +128,8 @@ int saa7164_cmd_dequeue(struct saa7164_d
30883 u8 tmp[512];
30884 dprintk(DBGLVL_CMD, "%s()\n", __func__);
30885
30886+ pax_track_stack();
30887+
30888 while (loop) {
30889
30890 tmComResInfo_t tRsp = { 0, 0, 0, 0, 0, 0 };
30891diff -urNp linux-2.6.32.41/drivers/media/video/usbvideo/konicawc.c linux-2.6.32.41/drivers/media/video/usbvideo/konicawc.c
30892--- linux-2.6.32.41/drivers/media/video/usbvideo/konicawc.c 2011-03-27 14:31:47.000000000 -0400
30893+++ linux-2.6.32.41/drivers/media/video/usbvideo/konicawc.c 2011-04-17 15:56:46.000000000 -0400
30894@@ -225,7 +225,7 @@ static void konicawc_register_input(stru
30895 int error;
30896
30897 usb_make_path(dev, cam->input_physname, sizeof(cam->input_physname));
30898- strncat(cam->input_physname, "/input0", sizeof(cam->input_physname));
30899+ strlcat(cam->input_physname, "/input0", sizeof(cam->input_physname));
30900
30901 cam->input = input_dev = input_allocate_device();
30902 if (!input_dev) {
30903diff -urNp linux-2.6.32.41/drivers/media/video/usbvideo/quickcam_messenger.c linux-2.6.32.41/drivers/media/video/usbvideo/quickcam_messenger.c
30904--- linux-2.6.32.41/drivers/media/video/usbvideo/quickcam_messenger.c 2011-03-27 14:31:47.000000000 -0400
30905+++ linux-2.6.32.41/drivers/media/video/usbvideo/quickcam_messenger.c 2011-04-17 15:56:46.000000000 -0400
30906@@ -89,7 +89,7 @@ static void qcm_register_input(struct qc
30907 int error;
30908
30909 usb_make_path(dev, cam->input_physname, sizeof(cam->input_physname));
30910- strncat(cam->input_physname, "/input0", sizeof(cam->input_physname));
30911+ strlcat(cam->input_physname, "/input0", sizeof(cam->input_physname));
30912
30913 cam->input = input_dev = input_allocate_device();
30914 if (!input_dev) {
30915diff -urNp linux-2.6.32.41/drivers/media/video/usbvision/usbvision-core.c linux-2.6.32.41/drivers/media/video/usbvision/usbvision-core.c
30916--- linux-2.6.32.41/drivers/media/video/usbvision/usbvision-core.c 2011-03-27 14:31:47.000000000 -0400
30917+++ linux-2.6.32.41/drivers/media/video/usbvision/usbvision-core.c 2011-05-16 21:46:57.000000000 -0400
30918@@ -820,6 +820,8 @@ static enum ParseState usbvision_parse_c
30919 unsigned char rv, gv, bv;
30920 static unsigned char *Y, *U, *V;
30921
30922+ pax_track_stack();
30923+
30924 frame = usbvision->curFrame;
30925 imageSize = frame->frmwidth * frame->frmheight;
30926 if ( (frame->v4l2_format.format == V4L2_PIX_FMT_YUV422P) ||
30927diff -urNp linux-2.6.32.41/drivers/media/video/v4l2-device.c linux-2.6.32.41/drivers/media/video/v4l2-device.c
30928--- linux-2.6.32.41/drivers/media/video/v4l2-device.c 2011-03-27 14:31:47.000000000 -0400
30929+++ linux-2.6.32.41/drivers/media/video/v4l2-device.c 2011-05-04 17:56:28.000000000 -0400
30930@@ -50,9 +50,9 @@ int v4l2_device_register(struct device *
30931 EXPORT_SYMBOL_GPL(v4l2_device_register);
30932
30933 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
30934- atomic_t *instance)
30935+ atomic_unchecked_t *instance)
30936 {
30937- int num = atomic_inc_return(instance) - 1;
30938+ int num = atomic_inc_return_unchecked(instance) - 1;
30939 int len = strlen(basename);
30940
30941 if (basename[len - 1] >= '0' && basename[len - 1] <= '9')
30942diff -urNp linux-2.6.32.41/drivers/media/video/videobuf-dma-sg.c linux-2.6.32.41/drivers/media/video/videobuf-dma-sg.c
30943--- linux-2.6.32.41/drivers/media/video/videobuf-dma-sg.c 2011-03-27 14:31:47.000000000 -0400
30944+++ linux-2.6.32.41/drivers/media/video/videobuf-dma-sg.c 2011-05-16 21:46:57.000000000 -0400
30945@@ -693,6 +693,8 @@ void *videobuf_sg_alloc(size_t size)
30946 {
30947 struct videobuf_queue q;
30948
30949+ pax_track_stack();
30950+
30951 /* Required to make generic handler to call __videobuf_alloc */
30952 q.int_ops = &sg_ops;
30953
30954diff -urNp linux-2.6.32.41/drivers/message/fusion/mptbase.c linux-2.6.32.41/drivers/message/fusion/mptbase.c
30955--- linux-2.6.32.41/drivers/message/fusion/mptbase.c 2011-03-27 14:31:47.000000000 -0400
30956+++ linux-2.6.32.41/drivers/message/fusion/mptbase.c 2011-04-17 15:56:46.000000000 -0400
30957@@ -6709,8 +6709,14 @@ procmpt_iocinfo_read(char *buf, char **s
30958 len += sprintf(buf+len, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
30959 len += sprintf(buf+len, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
30960
30961+#ifdef CONFIG_GRKERNSEC_HIDESYM
30962+ len += sprintf(buf+len, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
30963+ NULL, NULL);
30964+#else
30965 len += sprintf(buf+len, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
30966 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
30967+#endif
30968+
30969 /*
30970 * Rounding UP to nearest 4-kB boundary here...
30971 */
30972diff -urNp linux-2.6.32.41/drivers/message/fusion/mptsas.c linux-2.6.32.41/drivers/message/fusion/mptsas.c
30973--- linux-2.6.32.41/drivers/message/fusion/mptsas.c 2011-03-27 14:31:47.000000000 -0400
30974+++ linux-2.6.32.41/drivers/message/fusion/mptsas.c 2011-04-17 15:56:46.000000000 -0400
30975@@ -436,6 +436,23 @@ mptsas_is_end_device(struct mptsas_devin
30976 return 0;
30977 }
30978
30979+static inline void
30980+mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
30981+{
30982+ if (phy_info->port_details) {
30983+ phy_info->port_details->rphy = rphy;
30984+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
30985+ ioc->name, rphy));
30986+ }
30987+
30988+ if (rphy) {
30989+ dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
30990+ &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
30991+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
30992+ ioc->name, rphy, rphy->dev.release));
30993+ }
30994+}
30995+
30996 /* no mutex */
30997 static void
30998 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
30999@@ -474,23 +491,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *p
31000 return NULL;
31001 }
31002
31003-static inline void
31004-mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
31005-{
31006- if (phy_info->port_details) {
31007- phy_info->port_details->rphy = rphy;
31008- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
31009- ioc->name, rphy));
31010- }
31011-
31012- if (rphy) {
31013- dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
31014- &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
31015- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
31016- ioc->name, rphy, rphy->dev.release));
31017- }
31018-}
31019-
31020 static inline struct sas_port *
31021 mptsas_get_port(struct mptsas_phyinfo *phy_info)
31022 {
31023diff -urNp linux-2.6.32.41/drivers/message/fusion/mptscsih.c linux-2.6.32.41/drivers/message/fusion/mptscsih.c
31024--- linux-2.6.32.41/drivers/message/fusion/mptscsih.c 2011-03-27 14:31:47.000000000 -0400
31025+++ linux-2.6.32.41/drivers/message/fusion/mptscsih.c 2011-04-17 15:56:46.000000000 -0400
31026@@ -1248,15 +1248,16 @@ mptscsih_info(struct Scsi_Host *SChost)
31027
31028 h = shost_priv(SChost);
31029
31030- if (h) {
31031- if (h->info_kbuf == NULL)
31032- if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
31033- return h->info_kbuf;
31034- h->info_kbuf[0] = '\0';
31035+ if (!h)
31036+ return NULL;
31037
31038- mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
31039- h->info_kbuf[size-1] = '\0';
31040- }
31041+ if (h->info_kbuf == NULL)
31042+ if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
31043+ return h->info_kbuf;
31044+ h->info_kbuf[0] = '\0';
31045+
31046+ mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
31047+ h->info_kbuf[size-1] = '\0';
31048
31049 return h->info_kbuf;
31050 }
31051diff -urNp linux-2.6.32.41/drivers/message/i2o/i2o_config.c linux-2.6.32.41/drivers/message/i2o/i2o_config.c
31052--- linux-2.6.32.41/drivers/message/i2o/i2o_config.c 2011-03-27 14:31:47.000000000 -0400
31053+++ linux-2.6.32.41/drivers/message/i2o/i2o_config.c 2011-05-16 21:46:57.000000000 -0400
31054@@ -787,6 +787,8 @@ static int i2o_cfg_passthru(unsigned lon
31055 struct i2o_message *msg;
31056 unsigned int iop;
31057
31058+ pax_track_stack();
31059+
31060 if (get_user(iop, &cmd->iop) || get_user(user_msg, &cmd->msg))
31061 return -EFAULT;
31062
31063diff -urNp linux-2.6.32.41/drivers/message/i2o/i2o_proc.c linux-2.6.32.41/drivers/message/i2o/i2o_proc.c
31064--- linux-2.6.32.41/drivers/message/i2o/i2o_proc.c 2011-03-27 14:31:47.000000000 -0400
31065+++ linux-2.6.32.41/drivers/message/i2o/i2o_proc.c 2011-04-17 15:56:46.000000000 -0400
31066@@ -259,13 +259,6 @@ static char *scsi_devices[] = {
31067 "Array Controller Device"
31068 };
31069
31070-static char *chtostr(u8 * chars, int n)
31071-{
31072- char tmp[256];
31073- tmp[0] = 0;
31074- return strncat(tmp, (char *)chars, n);
31075-}
31076-
31077 static int i2o_report_query_status(struct seq_file *seq, int block_status,
31078 char *group)
31079 {
31080@@ -842,8 +835,7 @@ static int i2o_seq_show_ddm_table(struct
31081
31082 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
31083 seq_printf(seq, "%-#8x", ddm_table.module_id);
31084- seq_printf(seq, "%-29s",
31085- chtostr(ddm_table.module_name_version, 28));
31086+ seq_printf(seq, "%-.28s", ddm_table.module_name_version);
31087 seq_printf(seq, "%9d ", ddm_table.data_size);
31088 seq_printf(seq, "%8d", ddm_table.code_size);
31089
31090@@ -944,8 +936,8 @@ static int i2o_seq_show_drivers_stored(s
31091
31092 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
31093 seq_printf(seq, "%-#8x", dst->module_id);
31094- seq_printf(seq, "%-29s", chtostr(dst->module_name_version, 28));
31095- seq_printf(seq, "%-9s", chtostr(dst->date, 8));
31096+ seq_printf(seq, "%-.28s", dst->module_name_version);
31097+ seq_printf(seq, "%-.8s", dst->date);
31098 seq_printf(seq, "%8d ", dst->module_size);
31099 seq_printf(seq, "%8d ", dst->mpb_size);
31100 seq_printf(seq, "0x%04x", dst->module_flags);
31101@@ -1276,14 +1268,10 @@ static int i2o_seq_show_dev_identity(str
31102 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
31103 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
31104 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
31105- seq_printf(seq, "Vendor info : %s\n",
31106- chtostr((u8 *) (work32 + 2), 16));
31107- seq_printf(seq, "Product info : %s\n",
31108- chtostr((u8 *) (work32 + 6), 16));
31109- seq_printf(seq, "Description : %s\n",
31110- chtostr((u8 *) (work32 + 10), 16));
31111- seq_printf(seq, "Product rev. : %s\n",
31112- chtostr((u8 *) (work32 + 14), 8));
31113+ seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
31114+ seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
31115+ seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
31116+ seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
31117
31118 seq_printf(seq, "Serial number : ");
31119 print_serial_number(seq, (u8 *) (work32 + 16),
31120@@ -1328,10 +1316,8 @@ static int i2o_seq_show_ddm_identity(str
31121 }
31122
31123 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
31124- seq_printf(seq, "Module name : %s\n",
31125- chtostr(result.module_name, 24));
31126- seq_printf(seq, "Module revision : %s\n",
31127- chtostr(result.module_rev, 8));
31128+ seq_printf(seq, "Module name : %.24s\n", result.module_name);
31129+ seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
31130
31131 seq_printf(seq, "Serial number : ");
31132 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
31133@@ -1362,14 +1348,10 @@ static int i2o_seq_show_uinfo(struct seq
31134 return 0;
31135 }
31136
31137- seq_printf(seq, "Device name : %s\n",
31138- chtostr(result.device_name, 64));
31139- seq_printf(seq, "Service name : %s\n",
31140- chtostr(result.service_name, 64));
31141- seq_printf(seq, "Physical name : %s\n",
31142- chtostr(result.physical_location, 64));
31143- seq_printf(seq, "Instance number : %s\n",
31144- chtostr(result.instance_number, 4));
31145+ seq_printf(seq, "Device name : %.64s\n", result.device_name);
31146+ seq_printf(seq, "Service name : %.64s\n", result.service_name);
31147+ seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
31148+ seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
31149
31150 return 0;
31151 }
31152diff -urNp linux-2.6.32.41/drivers/message/i2o/iop.c linux-2.6.32.41/drivers/message/i2o/iop.c
31153--- linux-2.6.32.41/drivers/message/i2o/iop.c 2011-03-27 14:31:47.000000000 -0400
31154+++ linux-2.6.32.41/drivers/message/i2o/iop.c 2011-05-04 17:56:28.000000000 -0400
31155@@ -110,10 +110,10 @@ u32 i2o_cntxt_list_add(struct i2o_contro
31156
31157 spin_lock_irqsave(&c->context_list_lock, flags);
31158
31159- if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
31160- atomic_inc(&c->context_list_counter);
31161+ if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
31162+ atomic_inc_unchecked(&c->context_list_counter);
31163
31164- entry->context = atomic_read(&c->context_list_counter);
31165+ entry->context = atomic_read_unchecked(&c->context_list_counter);
31166
31167 list_add(&entry->list, &c->context_list);
31168
31169@@ -1076,7 +1076,7 @@ struct i2o_controller *i2o_iop_alloc(voi
31170
31171 #if BITS_PER_LONG == 64
31172 spin_lock_init(&c->context_list_lock);
31173- atomic_set(&c->context_list_counter, 0);
31174+ atomic_set_unchecked(&c->context_list_counter, 0);
31175 INIT_LIST_HEAD(&c->context_list);
31176 #endif
31177
31178diff -urNp linux-2.6.32.41/drivers/mfd/wm8350-i2c.c linux-2.6.32.41/drivers/mfd/wm8350-i2c.c
31179--- linux-2.6.32.41/drivers/mfd/wm8350-i2c.c 2011-03-27 14:31:47.000000000 -0400
31180+++ linux-2.6.32.41/drivers/mfd/wm8350-i2c.c 2011-05-16 21:46:57.000000000 -0400
31181@@ -43,6 +43,8 @@ static int wm8350_i2c_write_device(struc
31182 u8 msg[(WM8350_MAX_REGISTER << 1) + 1];
31183 int ret;
31184
31185+ pax_track_stack();
31186+
31187 if (bytes > ((WM8350_MAX_REGISTER << 1) + 1))
31188 return -EINVAL;
31189
31190diff -urNp linux-2.6.32.41/drivers/misc/kgdbts.c linux-2.6.32.41/drivers/misc/kgdbts.c
31191--- linux-2.6.32.41/drivers/misc/kgdbts.c 2011-03-27 14:31:47.000000000 -0400
31192+++ linux-2.6.32.41/drivers/misc/kgdbts.c 2011-04-17 15:56:46.000000000 -0400
31193@@ -118,7 +118,7 @@
31194 } while (0)
31195 #define MAX_CONFIG_LEN 40
31196
31197-static struct kgdb_io kgdbts_io_ops;
31198+static const struct kgdb_io kgdbts_io_ops;
31199 static char get_buf[BUFMAX];
31200 static int get_buf_cnt;
31201 static char put_buf[BUFMAX];
31202@@ -1102,7 +1102,7 @@ static void kgdbts_post_exp_handler(void
31203 module_put(THIS_MODULE);
31204 }
31205
31206-static struct kgdb_io kgdbts_io_ops = {
31207+static const struct kgdb_io kgdbts_io_ops = {
31208 .name = "kgdbts",
31209 .read_char = kgdbts_get_char,
31210 .write_char = kgdbts_put_char,
31211diff -urNp linux-2.6.32.41/drivers/misc/sgi-gru/gruhandles.c linux-2.6.32.41/drivers/misc/sgi-gru/gruhandles.c
31212--- linux-2.6.32.41/drivers/misc/sgi-gru/gruhandles.c 2011-03-27 14:31:47.000000000 -0400
31213+++ linux-2.6.32.41/drivers/misc/sgi-gru/gruhandles.c 2011-04-17 15:56:46.000000000 -0400
31214@@ -39,8 +39,8 @@ struct mcs_op_statistic mcs_op_statistic
31215
31216 static void update_mcs_stats(enum mcs_op op, unsigned long clks)
31217 {
31218- atomic_long_inc(&mcs_op_statistics[op].count);
31219- atomic_long_add(clks, &mcs_op_statistics[op].total);
31220+ atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
31221+ atomic_long_add_unchecked(clks, &mcs_op_statistics[op].total);
31222 if (mcs_op_statistics[op].max < clks)
31223 mcs_op_statistics[op].max = clks;
31224 }
31225diff -urNp linux-2.6.32.41/drivers/misc/sgi-gru/gruprocfs.c linux-2.6.32.41/drivers/misc/sgi-gru/gruprocfs.c
31226--- linux-2.6.32.41/drivers/misc/sgi-gru/gruprocfs.c 2011-03-27 14:31:47.000000000 -0400
31227+++ linux-2.6.32.41/drivers/misc/sgi-gru/gruprocfs.c 2011-04-17 15:56:46.000000000 -0400
31228@@ -32,9 +32,9 @@
31229
31230 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
31231
31232-static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
31233+static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
31234 {
31235- unsigned long val = atomic_long_read(v);
31236+ unsigned long val = atomic_long_read_unchecked(v);
31237
31238 if (val)
31239 seq_printf(s, "%16lu %s\n", val, id);
31240@@ -136,8 +136,8 @@ static int mcs_statistics_show(struct se
31241 "cch_interrupt_sync", "cch_deallocate", "tgh_invalidate"};
31242
31243 for (op = 0; op < mcsop_last; op++) {
31244- count = atomic_long_read(&mcs_op_statistics[op].count);
31245- total = atomic_long_read(&mcs_op_statistics[op].total);
31246+ count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
31247+ total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
31248 max = mcs_op_statistics[op].max;
31249 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
31250 count ? total / count : 0, max);
31251diff -urNp linux-2.6.32.41/drivers/misc/sgi-gru/grutables.h linux-2.6.32.41/drivers/misc/sgi-gru/grutables.h
31252--- linux-2.6.32.41/drivers/misc/sgi-gru/grutables.h 2011-03-27 14:31:47.000000000 -0400
31253+++ linux-2.6.32.41/drivers/misc/sgi-gru/grutables.h 2011-04-17 15:56:46.000000000 -0400
31254@@ -167,84 +167,84 @@ extern unsigned int gru_max_gids;
31255 * GRU statistics.
31256 */
31257 struct gru_stats_s {
31258- atomic_long_t vdata_alloc;
31259- atomic_long_t vdata_free;
31260- atomic_long_t gts_alloc;
31261- atomic_long_t gts_free;
31262- atomic_long_t vdata_double_alloc;
31263- atomic_long_t gts_double_allocate;
31264- atomic_long_t assign_context;
31265- atomic_long_t assign_context_failed;
31266- atomic_long_t free_context;
31267- atomic_long_t load_user_context;
31268- atomic_long_t load_kernel_context;
31269- atomic_long_t lock_kernel_context;
31270- atomic_long_t unlock_kernel_context;
31271- atomic_long_t steal_user_context;
31272- atomic_long_t steal_kernel_context;
31273- atomic_long_t steal_context_failed;
31274- atomic_long_t nopfn;
31275- atomic_long_t break_cow;
31276- atomic_long_t asid_new;
31277- atomic_long_t asid_next;
31278- atomic_long_t asid_wrap;
31279- atomic_long_t asid_reuse;
31280- atomic_long_t intr;
31281- atomic_long_t intr_mm_lock_failed;
31282- atomic_long_t call_os;
31283- atomic_long_t call_os_offnode_reference;
31284- atomic_long_t call_os_check_for_bug;
31285- atomic_long_t call_os_wait_queue;
31286- atomic_long_t user_flush_tlb;
31287- atomic_long_t user_unload_context;
31288- atomic_long_t user_exception;
31289- atomic_long_t set_context_option;
31290- atomic_long_t migrate_check;
31291- atomic_long_t migrated_retarget;
31292- atomic_long_t migrated_unload;
31293- atomic_long_t migrated_unload_delay;
31294- atomic_long_t migrated_nopfn_retarget;
31295- atomic_long_t migrated_nopfn_unload;
31296- atomic_long_t tlb_dropin;
31297- atomic_long_t tlb_dropin_fail_no_asid;
31298- atomic_long_t tlb_dropin_fail_upm;
31299- atomic_long_t tlb_dropin_fail_invalid;
31300- atomic_long_t tlb_dropin_fail_range_active;
31301- atomic_long_t tlb_dropin_fail_idle;
31302- atomic_long_t tlb_dropin_fail_fmm;
31303- atomic_long_t tlb_dropin_fail_no_exception;
31304- atomic_long_t tlb_dropin_fail_no_exception_war;
31305- atomic_long_t tfh_stale_on_fault;
31306- atomic_long_t mmu_invalidate_range;
31307- atomic_long_t mmu_invalidate_page;
31308- atomic_long_t mmu_clear_flush_young;
31309- atomic_long_t flush_tlb;
31310- atomic_long_t flush_tlb_gru;
31311- atomic_long_t flush_tlb_gru_tgh;
31312- atomic_long_t flush_tlb_gru_zero_asid;
31313-
31314- atomic_long_t copy_gpa;
31315-
31316- atomic_long_t mesq_receive;
31317- atomic_long_t mesq_receive_none;
31318- atomic_long_t mesq_send;
31319- atomic_long_t mesq_send_failed;
31320- atomic_long_t mesq_noop;
31321- atomic_long_t mesq_send_unexpected_error;
31322- atomic_long_t mesq_send_lb_overflow;
31323- atomic_long_t mesq_send_qlimit_reached;
31324- atomic_long_t mesq_send_amo_nacked;
31325- atomic_long_t mesq_send_put_nacked;
31326- atomic_long_t mesq_qf_not_full;
31327- atomic_long_t mesq_qf_locked;
31328- atomic_long_t mesq_qf_noop_not_full;
31329- atomic_long_t mesq_qf_switch_head_failed;
31330- atomic_long_t mesq_qf_unexpected_error;
31331- atomic_long_t mesq_noop_unexpected_error;
31332- atomic_long_t mesq_noop_lb_overflow;
31333- atomic_long_t mesq_noop_qlimit_reached;
31334- atomic_long_t mesq_noop_amo_nacked;
31335- atomic_long_t mesq_noop_put_nacked;
31336+ atomic_long_unchecked_t vdata_alloc;
31337+ atomic_long_unchecked_t vdata_free;
31338+ atomic_long_unchecked_t gts_alloc;
31339+ atomic_long_unchecked_t gts_free;
31340+ atomic_long_unchecked_t vdata_double_alloc;
31341+ atomic_long_unchecked_t gts_double_allocate;
31342+ atomic_long_unchecked_t assign_context;
31343+ atomic_long_unchecked_t assign_context_failed;
31344+ atomic_long_unchecked_t free_context;
31345+ atomic_long_unchecked_t load_user_context;
31346+ atomic_long_unchecked_t load_kernel_context;
31347+ atomic_long_unchecked_t lock_kernel_context;
31348+ atomic_long_unchecked_t unlock_kernel_context;
31349+ atomic_long_unchecked_t steal_user_context;
31350+ atomic_long_unchecked_t steal_kernel_context;
31351+ atomic_long_unchecked_t steal_context_failed;
31352+ atomic_long_unchecked_t nopfn;
31353+ atomic_long_unchecked_t break_cow;
31354+ atomic_long_unchecked_t asid_new;
31355+ atomic_long_unchecked_t asid_next;
31356+ atomic_long_unchecked_t asid_wrap;
31357+ atomic_long_unchecked_t asid_reuse;
31358+ atomic_long_unchecked_t intr;
31359+ atomic_long_unchecked_t intr_mm_lock_failed;
31360+ atomic_long_unchecked_t call_os;
31361+ atomic_long_unchecked_t call_os_offnode_reference;
31362+ atomic_long_unchecked_t call_os_check_for_bug;
31363+ atomic_long_unchecked_t call_os_wait_queue;
31364+ atomic_long_unchecked_t user_flush_tlb;
31365+ atomic_long_unchecked_t user_unload_context;
31366+ atomic_long_unchecked_t user_exception;
31367+ atomic_long_unchecked_t set_context_option;
31368+ atomic_long_unchecked_t migrate_check;
31369+ atomic_long_unchecked_t migrated_retarget;
31370+ atomic_long_unchecked_t migrated_unload;
31371+ atomic_long_unchecked_t migrated_unload_delay;
31372+ atomic_long_unchecked_t migrated_nopfn_retarget;
31373+ atomic_long_unchecked_t migrated_nopfn_unload;
31374+ atomic_long_unchecked_t tlb_dropin;
31375+ atomic_long_unchecked_t tlb_dropin_fail_no_asid;
31376+ atomic_long_unchecked_t tlb_dropin_fail_upm;
31377+ atomic_long_unchecked_t tlb_dropin_fail_invalid;
31378+ atomic_long_unchecked_t tlb_dropin_fail_range_active;
31379+ atomic_long_unchecked_t tlb_dropin_fail_idle;
31380+ atomic_long_unchecked_t tlb_dropin_fail_fmm;
31381+ atomic_long_unchecked_t tlb_dropin_fail_no_exception;
31382+ atomic_long_unchecked_t tlb_dropin_fail_no_exception_war;
31383+ atomic_long_unchecked_t tfh_stale_on_fault;
31384+ atomic_long_unchecked_t mmu_invalidate_range;
31385+ atomic_long_unchecked_t mmu_invalidate_page;
31386+ atomic_long_unchecked_t mmu_clear_flush_young;
31387+ atomic_long_unchecked_t flush_tlb;
31388+ atomic_long_unchecked_t flush_tlb_gru;
31389+ atomic_long_unchecked_t flush_tlb_gru_tgh;
31390+ atomic_long_unchecked_t flush_tlb_gru_zero_asid;
31391+
31392+ atomic_long_unchecked_t copy_gpa;
31393+
31394+ atomic_long_unchecked_t mesq_receive;
31395+ atomic_long_unchecked_t mesq_receive_none;
31396+ atomic_long_unchecked_t mesq_send;
31397+ atomic_long_unchecked_t mesq_send_failed;
31398+ atomic_long_unchecked_t mesq_noop;
31399+ atomic_long_unchecked_t mesq_send_unexpected_error;
31400+ atomic_long_unchecked_t mesq_send_lb_overflow;
31401+ atomic_long_unchecked_t mesq_send_qlimit_reached;
31402+ atomic_long_unchecked_t mesq_send_amo_nacked;
31403+ atomic_long_unchecked_t mesq_send_put_nacked;
31404+ atomic_long_unchecked_t mesq_qf_not_full;
31405+ atomic_long_unchecked_t mesq_qf_locked;
31406+ atomic_long_unchecked_t mesq_qf_noop_not_full;
31407+ atomic_long_unchecked_t mesq_qf_switch_head_failed;
31408+ atomic_long_unchecked_t mesq_qf_unexpected_error;
31409+ atomic_long_unchecked_t mesq_noop_unexpected_error;
31410+ atomic_long_unchecked_t mesq_noop_lb_overflow;
31411+ atomic_long_unchecked_t mesq_noop_qlimit_reached;
31412+ atomic_long_unchecked_t mesq_noop_amo_nacked;
31413+ atomic_long_unchecked_t mesq_noop_put_nacked;
31414
31415 };
31416
31417@@ -252,8 +252,8 @@ enum mcs_op {cchop_allocate, cchop_start
31418 cchop_deallocate, tghop_invalidate, mcsop_last};
31419
31420 struct mcs_op_statistic {
31421- atomic_long_t count;
31422- atomic_long_t total;
31423+ atomic_long_unchecked_t count;
31424+ atomic_long_unchecked_t total;
31425 unsigned long max;
31426 };
31427
31428@@ -276,7 +276,7 @@ extern struct mcs_op_statistic mcs_op_st
31429
31430 #define STAT(id) do { \
31431 if (gru_options & OPT_STATS) \
31432- atomic_long_inc(&gru_stats.id); \
31433+ atomic_long_inc_unchecked(&gru_stats.id); \
31434 } while (0)
31435
31436 #ifdef CONFIG_SGI_GRU_DEBUG
31437diff -urNp linux-2.6.32.41/drivers/mtd/chips/cfi_cmdset_0001.c linux-2.6.32.41/drivers/mtd/chips/cfi_cmdset_0001.c
31438--- linux-2.6.32.41/drivers/mtd/chips/cfi_cmdset_0001.c 2011-03-27 14:31:47.000000000 -0400
31439+++ linux-2.6.32.41/drivers/mtd/chips/cfi_cmdset_0001.c 2011-05-16 21:46:57.000000000 -0400
31440@@ -743,6 +743,8 @@ static int chip_ready (struct map_info *
31441 struct cfi_pri_intelext *cfip = cfi->cmdset_priv;
31442 unsigned long timeo = jiffies + HZ;
31443
31444+ pax_track_stack();
31445+
31446 /* Prevent setting state FL_SYNCING for chip in suspended state. */
31447 if (mode == FL_SYNCING && chip->oldstate != FL_READY)
31448 goto sleep;
31449@@ -1642,6 +1644,8 @@ static int __xipram do_write_buffer(stru
31450 unsigned long initial_adr;
31451 int initial_len = len;
31452
31453+ pax_track_stack();
31454+
31455 wbufsize = cfi_interleave(cfi) << cfi->cfiq->MaxBufWriteSize;
31456 adr += chip->start;
31457 initial_adr = adr;
31458@@ -1860,6 +1864,8 @@ static int __xipram do_erase_oneblock(st
31459 int retries = 3;
31460 int ret;
31461
31462+ pax_track_stack();
31463+
31464 adr += chip->start;
31465
31466 retry:
31467diff -urNp linux-2.6.32.41/drivers/mtd/chips/cfi_cmdset_0020.c linux-2.6.32.41/drivers/mtd/chips/cfi_cmdset_0020.c
31468--- linux-2.6.32.41/drivers/mtd/chips/cfi_cmdset_0020.c 2011-03-27 14:31:47.000000000 -0400
31469+++ linux-2.6.32.41/drivers/mtd/chips/cfi_cmdset_0020.c 2011-05-16 21:46:57.000000000 -0400
31470@@ -255,6 +255,8 @@ static inline int do_read_onechip(struct
31471 unsigned long cmd_addr;
31472 struct cfi_private *cfi = map->fldrv_priv;
31473
31474+ pax_track_stack();
31475+
31476 adr += chip->start;
31477
31478 /* Ensure cmd read/writes are aligned. */
31479@@ -428,6 +430,8 @@ static inline int do_write_buffer(struct
31480 DECLARE_WAITQUEUE(wait, current);
31481 int wbufsize, z;
31482
31483+ pax_track_stack();
31484+
31485 /* M58LW064A requires bus alignment for buffer wriets -- saw */
31486 if (adr & (map_bankwidth(map)-1))
31487 return -EINVAL;
31488@@ -742,6 +746,8 @@ static inline int do_erase_oneblock(stru
31489 DECLARE_WAITQUEUE(wait, current);
31490 int ret = 0;
31491
31492+ pax_track_stack();
31493+
31494 adr += chip->start;
31495
31496 /* Let's determine this according to the interleave only once */
31497@@ -1047,6 +1053,8 @@ static inline int do_lock_oneblock(struc
31498 unsigned long timeo = jiffies + HZ;
31499 DECLARE_WAITQUEUE(wait, current);
31500
31501+ pax_track_stack();
31502+
31503 adr += chip->start;
31504
31505 /* Let's determine this according to the interleave only once */
31506@@ -1196,6 +1204,8 @@ static inline int do_unlock_oneblock(str
31507 unsigned long timeo = jiffies + HZ;
31508 DECLARE_WAITQUEUE(wait, current);
31509
31510+ pax_track_stack();
31511+
31512 adr += chip->start;
31513
31514 /* Let's determine this according to the interleave only once */
31515diff -urNp linux-2.6.32.41/drivers/mtd/devices/doc2000.c linux-2.6.32.41/drivers/mtd/devices/doc2000.c
31516--- linux-2.6.32.41/drivers/mtd/devices/doc2000.c 2011-03-27 14:31:47.000000000 -0400
31517+++ linux-2.6.32.41/drivers/mtd/devices/doc2000.c 2011-04-17 15:56:46.000000000 -0400
31518@@ -776,7 +776,7 @@ static int doc_write(struct mtd_info *mt
31519
31520 /* The ECC will not be calculated correctly if less than 512 is written */
31521 /* DBB-
31522- if (len != 0x200 && eccbuf)
31523+ if (len != 0x200)
31524 printk(KERN_WARNING
31525 "ECC needs a full sector write (adr: %lx size %lx)\n",
31526 (long) to, (long) len);
31527diff -urNp linux-2.6.32.41/drivers/mtd/devices/doc2001.c linux-2.6.32.41/drivers/mtd/devices/doc2001.c
31528--- linux-2.6.32.41/drivers/mtd/devices/doc2001.c 2011-03-27 14:31:47.000000000 -0400
31529+++ linux-2.6.32.41/drivers/mtd/devices/doc2001.c 2011-04-17 15:56:46.000000000 -0400
31530@@ -393,7 +393,7 @@ static int doc_read (struct mtd_info *mt
31531 struct Nand *mychip = &this->chips[from >> (this->chipshift)];
31532
31533 /* Don't allow read past end of device */
31534- if (from >= this->totlen)
31535+ if (from >= this->totlen || !len)
31536 return -EINVAL;
31537
31538 /* Don't allow a single read to cross a 512-byte block boundary */
31539diff -urNp linux-2.6.32.41/drivers/mtd/ftl.c linux-2.6.32.41/drivers/mtd/ftl.c
31540--- linux-2.6.32.41/drivers/mtd/ftl.c 2011-03-27 14:31:47.000000000 -0400
31541+++ linux-2.6.32.41/drivers/mtd/ftl.c 2011-05-16 21:46:57.000000000 -0400
31542@@ -474,6 +474,8 @@ static int copy_erase_unit(partition_t *
31543 loff_t offset;
31544 uint16_t srcunitswap = cpu_to_le16(srcunit);
31545
31546+ pax_track_stack();
31547+
31548 eun = &part->EUNInfo[srcunit];
31549 xfer = &part->XferInfo[xferunit];
31550 DEBUG(2, "ftl_cs: copying block 0x%x to 0x%x\n",
31551diff -urNp linux-2.6.32.41/drivers/mtd/inftlcore.c linux-2.6.32.41/drivers/mtd/inftlcore.c
31552--- linux-2.6.32.41/drivers/mtd/inftlcore.c 2011-03-27 14:31:47.000000000 -0400
31553+++ linux-2.6.32.41/drivers/mtd/inftlcore.c 2011-05-16 21:46:57.000000000 -0400
31554@@ -260,6 +260,8 @@ static u16 INFTL_foldchain(struct INFTLr
31555 struct inftl_oob oob;
31556 size_t retlen;
31557
31558+ pax_track_stack();
31559+
31560 DEBUG(MTD_DEBUG_LEVEL3, "INFTL: INFTL_foldchain(inftl=%p,thisVUC=%d,"
31561 "pending=%d)\n", inftl, thisVUC, pendingblock);
31562
31563diff -urNp linux-2.6.32.41/drivers/mtd/inftlmount.c linux-2.6.32.41/drivers/mtd/inftlmount.c
31564--- linux-2.6.32.41/drivers/mtd/inftlmount.c 2011-03-27 14:31:47.000000000 -0400
31565+++ linux-2.6.32.41/drivers/mtd/inftlmount.c 2011-05-16 21:46:57.000000000 -0400
31566@@ -54,6 +54,8 @@ static int find_boot_record(struct INFTL
31567 struct INFTLPartition *ip;
31568 size_t retlen;
31569
31570+ pax_track_stack();
31571+
31572 DEBUG(MTD_DEBUG_LEVEL3, "INFTL: find_boot_record(inftl=%p)\n", inftl);
31573
31574 /*
31575diff -urNp linux-2.6.32.41/drivers/mtd/lpddr/qinfo_probe.c linux-2.6.32.41/drivers/mtd/lpddr/qinfo_probe.c
31576--- linux-2.6.32.41/drivers/mtd/lpddr/qinfo_probe.c 2011-03-27 14:31:47.000000000 -0400
31577+++ linux-2.6.32.41/drivers/mtd/lpddr/qinfo_probe.c 2011-05-16 21:46:57.000000000 -0400
31578@@ -106,6 +106,8 @@ static int lpddr_pfow_present(struct map
31579 {
31580 map_word pfow_val[4];
31581
31582+ pax_track_stack();
31583+
31584 /* Check identification string */
31585 pfow_val[0] = map_read(map, map->pfow_base + PFOW_QUERY_STRING_P);
31586 pfow_val[1] = map_read(map, map->pfow_base + PFOW_QUERY_STRING_F);
31587diff -urNp linux-2.6.32.41/drivers/mtd/mtdchar.c linux-2.6.32.41/drivers/mtd/mtdchar.c
31588--- linux-2.6.32.41/drivers/mtd/mtdchar.c 2011-03-27 14:31:47.000000000 -0400
31589+++ linux-2.6.32.41/drivers/mtd/mtdchar.c 2011-05-16 21:46:57.000000000 -0400
31590@@ -460,6 +460,8 @@ static int mtd_ioctl(struct inode *inode
31591 u_long size;
31592 struct mtd_info_user info;
31593
31594+ pax_track_stack();
31595+
31596 DEBUG(MTD_DEBUG_LEVEL0, "MTD_ioctl\n");
31597
31598 size = (cmd & IOCSIZE_MASK) >> IOCSIZE_SHIFT;
31599diff -urNp linux-2.6.32.41/drivers/mtd/nftlcore.c linux-2.6.32.41/drivers/mtd/nftlcore.c
31600--- linux-2.6.32.41/drivers/mtd/nftlcore.c 2011-03-27 14:31:47.000000000 -0400
31601+++ linux-2.6.32.41/drivers/mtd/nftlcore.c 2011-05-16 21:46:57.000000000 -0400
31602@@ -254,6 +254,8 @@ static u16 NFTL_foldchain (struct NFTLre
31603 int inplace = 1;
31604 size_t retlen;
31605
31606+ pax_track_stack();
31607+
31608 memset(BlockMap, 0xff, sizeof(BlockMap));
31609 memset(BlockFreeFound, 0, sizeof(BlockFreeFound));
31610
31611diff -urNp linux-2.6.32.41/drivers/mtd/nftlmount.c linux-2.6.32.41/drivers/mtd/nftlmount.c
31612--- linux-2.6.32.41/drivers/mtd/nftlmount.c 2011-03-27 14:31:47.000000000 -0400
31613+++ linux-2.6.32.41/drivers/mtd/nftlmount.c 2011-05-18 20:09:37.000000000 -0400
31614@@ -23,6 +23,7 @@
31615 #include <asm/errno.h>
31616 #include <linux/delay.h>
31617 #include <linux/slab.h>
31618+#include <linux/sched.h>
31619 #include <linux/mtd/mtd.h>
31620 #include <linux/mtd/nand.h>
31621 #include <linux/mtd/nftl.h>
31622@@ -44,6 +45,8 @@ static int find_boot_record(struct NFTLr
31623 struct mtd_info *mtd = nftl->mbd.mtd;
31624 unsigned int i;
31625
31626+ pax_track_stack();
31627+
31628 /* Assume logical EraseSize == physical erasesize for starting the scan.
31629 We'll sort it out later if we find a MediaHeader which says otherwise */
31630 /* Actually, we won't. The new DiskOnChip driver has already scanned
31631diff -urNp linux-2.6.32.41/drivers/mtd/ubi/build.c linux-2.6.32.41/drivers/mtd/ubi/build.c
31632--- linux-2.6.32.41/drivers/mtd/ubi/build.c 2011-03-27 14:31:47.000000000 -0400
31633+++ linux-2.6.32.41/drivers/mtd/ubi/build.c 2011-04-17 15:56:46.000000000 -0400
31634@@ -1255,7 +1255,7 @@ module_exit(ubi_exit);
31635 static int __init bytes_str_to_int(const char *str)
31636 {
31637 char *endp;
31638- unsigned long result;
31639+ unsigned long result, scale = 1;
31640
31641 result = simple_strtoul(str, &endp, 0);
31642 if (str == endp || result >= INT_MAX) {
31643@@ -1266,11 +1266,11 @@ static int __init bytes_str_to_int(const
31644
31645 switch (*endp) {
31646 case 'G':
31647- result *= 1024;
31648+ scale *= 1024;
31649 case 'M':
31650- result *= 1024;
31651+ scale *= 1024;
31652 case 'K':
31653- result *= 1024;
31654+ scale *= 1024;
31655 if (endp[1] == 'i' && endp[2] == 'B')
31656 endp += 2;
31657 case '\0':
31658@@ -1281,7 +1281,13 @@ static int __init bytes_str_to_int(const
31659 return -EINVAL;
31660 }
31661
31662- return result;
31663+ if ((intoverflow_t)result*scale >= INT_MAX) {
31664+ printk(KERN_ERR "UBI error: incorrect bytes count: \"%s\"\n",
31665+ str);
31666+ return -EINVAL;
31667+ }
31668+
31669+ return result*scale;
31670 }
31671
31672 /**
31673diff -urNp linux-2.6.32.41/drivers/net/bnx2.c linux-2.6.32.41/drivers/net/bnx2.c
31674--- linux-2.6.32.41/drivers/net/bnx2.c 2011-03-27 14:31:47.000000000 -0400
31675+++ linux-2.6.32.41/drivers/net/bnx2.c 2011-05-16 21:46:57.000000000 -0400
31676@@ -5809,6 +5809,8 @@ bnx2_test_nvram(struct bnx2 *bp)
31677 int rc = 0;
31678 u32 magic, csum;
31679
31680+ pax_track_stack();
31681+
31682 if ((rc = bnx2_nvram_read(bp, 0, data, 4)) != 0)
31683 goto test_nvram_done;
31684
31685diff -urNp linux-2.6.32.41/drivers/net/cxgb3/t3_hw.c linux-2.6.32.41/drivers/net/cxgb3/t3_hw.c
31686--- linux-2.6.32.41/drivers/net/cxgb3/t3_hw.c 2011-03-27 14:31:47.000000000 -0400
31687+++ linux-2.6.32.41/drivers/net/cxgb3/t3_hw.c 2011-05-16 21:46:57.000000000 -0400
31688@@ -699,6 +699,8 @@ static int get_vpd_params(struct adapter
31689 int i, addr, ret;
31690 struct t3_vpd vpd;
31691
31692+ pax_track_stack();
31693+
31694 /*
31695 * Card information is normally at VPD_BASE but some early cards had
31696 * it at 0.
31697diff -urNp linux-2.6.32.41/drivers/net/e1000e/82571.c linux-2.6.32.41/drivers/net/e1000e/82571.c
31698--- linux-2.6.32.41/drivers/net/e1000e/82571.c 2011-03-27 14:31:47.000000000 -0400
31699+++ linux-2.6.32.41/drivers/net/e1000e/82571.c 2011-04-17 15:56:46.000000000 -0400
31700@@ -212,6 +212,7 @@ static s32 e1000_init_mac_params_82571(s
31701 {
31702 struct e1000_hw *hw = &adapter->hw;
31703 struct e1000_mac_info *mac = &hw->mac;
31704+ /* cannot be const */
31705 struct e1000_mac_operations *func = &mac->ops;
31706 u32 swsm = 0;
31707 u32 swsm2 = 0;
31708@@ -1656,7 +1657,7 @@ static void e1000_clear_hw_cntrs_82571(s
31709 temp = er32(ICRXDMTC);
31710 }
31711
31712-static struct e1000_mac_operations e82571_mac_ops = {
31713+static const struct e1000_mac_operations e82571_mac_ops = {
31714 /* .check_mng_mode: mac type dependent */
31715 /* .check_for_link: media type dependent */
31716 .id_led_init = e1000e_id_led_init,
31717@@ -1674,7 +1675,7 @@ static struct e1000_mac_operations e8257
31718 .setup_led = e1000e_setup_led_generic,
31719 };
31720
31721-static struct e1000_phy_operations e82_phy_ops_igp = {
31722+static const struct e1000_phy_operations e82_phy_ops_igp = {
31723 .acquire_phy = e1000_get_hw_semaphore_82571,
31724 .check_reset_block = e1000e_check_reset_block_generic,
31725 .commit_phy = NULL,
31726@@ -1691,7 +1692,7 @@ static struct e1000_phy_operations e82_p
31727 .cfg_on_link_up = NULL,
31728 };
31729
31730-static struct e1000_phy_operations e82_phy_ops_m88 = {
31731+static const struct e1000_phy_operations e82_phy_ops_m88 = {
31732 .acquire_phy = e1000_get_hw_semaphore_82571,
31733 .check_reset_block = e1000e_check_reset_block_generic,
31734 .commit_phy = e1000e_phy_sw_reset,
31735@@ -1708,7 +1709,7 @@ static struct e1000_phy_operations e82_p
31736 .cfg_on_link_up = NULL,
31737 };
31738
31739-static struct e1000_phy_operations e82_phy_ops_bm = {
31740+static const struct e1000_phy_operations e82_phy_ops_bm = {
31741 .acquire_phy = e1000_get_hw_semaphore_82571,
31742 .check_reset_block = e1000e_check_reset_block_generic,
31743 .commit_phy = e1000e_phy_sw_reset,
31744@@ -1725,7 +1726,7 @@ static struct e1000_phy_operations e82_p
31745 .cfg_on_link_up = NULL,
31746 };
31747
31748-static struct e1000_nvm_operations e82571_nvm_ops = {
31749+static const struct e1000_nvm_operations e82571_nvm_ops = {
31750 .acquire_nvm = e1000_acquire_nvm_82571,
31751 .read_nvm = e1000e_read_nvm_eerd,
31752 .release_nvm = e1000_release_nvm_82571,
31753diff -urNp linux-2.6.32.41/drivers/net/e1000e/e1000.h linux-2.6.32.41/drivers/net/e1000e/e1000.h
31754--- linux-2.6.32.41/drivers/net/e1000e/e1000.h 2011-03-27 14:31:47.000000000 -0400
31755+++ linux-2.6.32.41/drivers/net/e1000e/e1000.h 2011-04-17 15:56:46.000000000 -0400
31756@@ -375,9 +375,9 @@ struct e1000_info {
31757 u32 pba;
31758 u32 max_hw_frame_size;
31759 s32 (*get_variants)(struct e1000_adapter *);
31760- struct e1000_mac_operations *mac_ops;
31761- struct e1000_phy_operations *phy_ops;
31762- struct e1000_nvm_operations *nvm_ops;
31763+ const struct e1000_mac_operations *mac_ops;
31764+ const struct e1000_phy_operations *phy_ops;
31765+ const struct e1000_nvm_operations *nvm_ops;
31766 };
31767
31768 /* hardware capability, feature, and workaround flags */
31769diff -urNp linux-2.6.32.41/drivers/net/e1000e/es2lan.c linux-2.6.32.41/drivers/net/e1000e/es2lan.c
31770--- linux-2.6.32.41/drivers/net/e1000e/es2lan.c 2011-03-27 14:31:47.000000000 -0400
31771+++ linux-2.6.32.41/drivers/net/e1000e/es2lan.c 2011-04-17 15:56:46.000000000 -0400
31772@@ -207,6 +207,7 @@ static s32 e1000_init_mac_params_80003es
31773 {
31774 struct e1000_hw *hw = &adapter->hw;
31775 struct e1000_mac_info *mac = &hw->mac;
31776+ /* cannot be const */
31777 struct e1000_mac_operations *func = &mac->ops;
31778
31779 /* Set media type */
31780@@ -1365,7 +1366,7 @@ static void e1000_clear_hw_cntrs_80003es
31781 temp = er32(ICRXDMTC);
31782 }
31783
31784-static struct e1000_mac_operations es2_mac_ops = {
31785+static const struct e1000_mac_operations es2_mac_ops = {
31786 .id_led_init = e1000e_id_led_init,
31787 .check_mng_mode = e1000e_check_mng_mode_generic,
31788 /* check_for_link dependent on media type */
31789@@ -1383,7 +1384,7 @@ static struct e1000_mac_operations es2_m
31790 .setup_led = e1000e_setup_led_generic,
31791 };
31792
31793-static struct e1000_phy_operations es2_phy_ops = {
31794+static const struct e1000_phy_operations es2_phy_ops = {
31795 .acquire_phy = e1000_acquire_phy_80003es2lan,
31796 .check_reset_block = e1000e_check_reset_block_generic,
31797 .commit_phy = e1000e_phy_sw_reset,
31798@@ -1400,7 +1401,7 @@ static struct e1000_phy_operations es2_p
31799 .cfg_on_link_up = e1000_cfg_on_link_up_80003es2lan,
31800 };
31801
31802-static struct e1000_nvm_operations es2_nvm_ops = {
31803+static const struct e1000_nvm_operations es2_nvm_ops = {
31804 .acquire_nvm = e1000_acquire_nvm_80003es2lan,
31805 .read_nvm = e1000e_read_nvm_eerd,
31806 .release_nvm = e1000_release_nvm_80003es2lan,
31807diff -urNp linux-2.6.32.41/drivers/net/e1000e/hw.h linux-2.6.32.41/drivers/net/e1000e/hw.h
31808--- linux-2.6.32.41/drivers/net/e1000e/hw.h 2011-03-27 14:31:47.000000000 -0400
31809+++ linux-2.6.32.41/drivers/net/e1000e/hw.h 2011-04-17 15:56:46.000000000 -0400
31810@@ -756,34 +756,34 @@ struct e1000_mac_operations {
31811
31812 /* Function pointers for the PHY. */
31813 struct e1000_phy_operations {
31814- s32 (*acquire_phy)(struct e1000_hw *);
31815- s32 (*check_polarity)(struct e1000_hw *);
31816- s32 (*check_reset_block)(struct e1000_hw *);
31817- s32 (*commit_phy)(struct e1000_hw *);
31818- s32 (*force_speed_duplex)(struct e1000_hw *);
31819- s32 (*get_cfg_done)(struct e1000_hw *hw);
31820- s32 (*get_cable_length)(struct e1000_hw *);
31821- s32 (*get_phy_info)(struct e1000_hw *);
31822- s32 (*read_phy_reg)(struct e1000_hw *, u32, u16 *);
31823- s32 (*read_phy_reg_locked)(struct e1000_hw *, u32, u16 *);
31824- void (*release_phy)(struct e1000_hw *);
31825- s32 (*reset_phy)(struct e1000_hw *);
31826- s32 (*set_d0_lplu_state)(struct e1000_hw *, bool);
31827- s32 (*set_d3_lplu_state)(struct e1000_hw *, bool);
31828- s32 (*write_phy_reg)(struct e1000_hw *, u32, u16);
31829- s32 (*write_phy_reg_locked)(struct e1000_hw *, u32, u16);
31830- s32 (*cfg_on_link_up)(struct e1000_hw *);
31831+ s32 (* acquire_phy)(struct e1000_hw *);
31832+ s32 (* check_polarity)(struct e1000_hw *);
31833+ s32 (* check_reset_block)(struct e1000_hw *);
31834+ s32 (* commit_phy)(struct e1000_hw *);
31835+ s32 (* force_speed_duplex)(struct e1000_hw *);
31836+ s32 (* get_cfg_done)(struct e1000_hw *hw);
31837+ s32 (* get_cable_length)(struct e1000_hw *);
31838+ s32 (* get_phy_info)(struct e1000_hw *);
31839+ s32 (* read_phy_reg)(struct e1000_hw *, u32, u16 *);
31840+ s32 (* read_phy_reg_locked)(struct e1000_hw *, u32, u16 *);
31841+ void (* release_phy)(struct e1000_hw *);
31842+ s32 (* reset_phy)(struct e1000_hw *);
31843+ s32 (* set_d0_lplu_state)(struct e1000_hw *, bool);
31844+ s32 (* set_d3_lplu_state)(struct e1000_hw *, bool);
31845+ s32 (* write_phy_reg)(struct e1000_hw *, u32, u16);
31846+ s32 (* write_phy_reg_locked)(struct e1000_hw *, u32, u16);
31847+ s32 (* cfg_on_link_up)(struct e1000_hw *);
31848 };
31849
31850 /* Function pointers for the NVM. */
31851 struct e1000_nvm_operations {
31852- s32 (*acquire_nvm)(struct e1000_hw *);
31853- s32 (*read_nvm)(struct e1000_hw *, u16, u16, u16 *);
31854- void (*release_nvm)(struct e1000_hw *);
31855- s32 (*update_nvm)(struct e1000_hw *);
31856- s32 (*valid_led_default)(struct e1000_hw *, u16 *);
31857- s32 (*validate_nvm)(struct e1000_hw *);
31858- s32 (*write_nvm)(struct e1000_hw *, u16, u16, u16 *);
31859+ s32 (* const acquire_nvm)(struct e1000_hw *);
31860+ s32 (* const read_nvm)(struct e1000_hw *, u16, u16, u16 *);
31861+ void (* const release_nvm)(struct e1000_hw *);
31862+ s32 (* const update_nvm)(struct e1000_hw *);
31863+ s32 (* const valid_led_default)(struct e1000_hw *, u16 *);
31864+ s32 (* const validate_nvm)(struct e1000_hw *);
31865+ s32 (* const write_nvm)(struct e1000_hw *, u16, u16, u16 *);
31866 };
31867
31868 struct e1000_mac_info {
31869diff -urNp linux-2.6.32.41/drivers/net/e1000e/ich8lan.c linux-2.6.32.41/drivers/net/e1000e/ich8lan.c
31870--- linux-2.6.32.41/drivers/net/e1000e/ich8lan.c 2011-05-10 22:12:01.000000000 -0400
31871+++ linux-2.6.32.41/drivers/net/e1000e/ich8lan.c 2011-05-10 22:12:32.000000000 -0400
31872@@ -3463,7 +3463,7 @@ static void e1000_clear_hw_cntrs_ich8lan
31873 }
31874 }
31875
31876-static struct e1000_mac_operations ich8_mac_ops = {
31877+static const struct e1000_mac_operations ich8_mac_ops = {
31878 .id_led_init = e1000e_id_led_init,
31879 .check_mng_mode = e1000_check_mng_mode_ich8lan,
31880 .check_for_link = e1000_check_for_copper_link_ich8lan,
31881@@ -3481,7 +3481,7 @@ static struct e1000_mac_operations ich8_
31882 /* id_led_init dependent on mac type */
31883 };
31884
31885-static struct e1000_phy_operations ich8_phy_ops = {
31886+static const struct e1000_phy_operations ich8_phy_ops = {
31887 .acquire_phy = e1000_acquire_swflag_ich8lan,
31888 .check_reset_block = e1000_check_reset_block_ich8lan,
31889 .commit_phy = NULL,
31890@@ -3497,7 +3497,7 @@ static struct e1000_phy_operations ich8_
31891 .write_phy_reg = e1000e_write_phy_reg_igp,
31892 };
31893
31894-static struct e1000_nvm_operations ich8_nvm_ops = {
31895+static const struct e1000_nvm_operations ich8_nvm_ops = {
31896 .acquire_nvm = e1000_acquire_nvm_ich8lan,
31897 .read_nvm = e1000_read_nvm_ich8lan,
31898 .release_nvm = e1000_release_nvm_ich8lan,
31899diff -urNp linux-2.6.32.41/drivers/net/hamradio/6pack.c linux-2.6.32.41/drivers/net/hamradio/6pack.c
31900--- linux-2.6.32.41/drivers/net/hamradio/6pack.c 2011-03-27 14:31:47.000000000 -0400
31901+++ linux-2.6.32.41/drivers/net/hamradio/6pack.c 2011-05-16 21:46:57.000000000 -0400
31902@@ -461,6 +461,8 @@ static void sixpack_receive_buf(struct t
31903 unsigned char buf[512];
31904 int count1;
31905
31906+ pax_track_stack();
31907+
31908 if (!count)
31909 return;
31910
31911diff -urNp linux-2.6.32.41/drivers/net/ibmveth.c linux-2.6.32.41/drivers/net/ibmveth.c
31912--- linux-2.6.32.41/drivers/net/ibmveth.c 2011-03-27 14:31:47.000000000 -0400
31913+++ linux-2.6.32.41/drivers/net/ibmveth.c 2011-04-17 15:56:46.000000000 -0400
31914@@ -1577,7 +1577,7 @@ static struct attribute * veth_pool_attr
31915 NULL,
31916 };
31917
31918-static struct sysfs_ops veth_pool_ops = {
31919+static const struct sysfs_ops veth_pool_ops = {
31920 .show = veth_pool_show,
31921 .store = veth_pool_store,
31922 };
31923diff -urNp linux-2.6.32.41/drivers/net/igb/e1000_82575.c linux-2.6.32.41/drivers/net/igb/e1000_82575.c
31924--- linux-2.6.32.41/drivers/net/igb/e1000_82575.c 2011-03-27 14:31:47.000000000 -0400
31925+++ linux-2.6.32.41/drivers/net/igb/e1000_82575.c 2011-04-17 15:56:46.000000000 -0400
31926@@ -1410,7 +1410,7 @@ void igb_vmdq_set_replication_pf(struct
31927 wr32(E1000_VT_CTL, vt_ctl);
31928 }
31929
31930-static struct e1000_mac_operations e1000_mac_ops_82575 = {
31931+static const struct e1000_mac_operations e1000_mac_ops_82575 = {
31932 .reset_hw = igb_reset_hw_82575,
31933 .init_hw = igb_init_hw_82575,
31934 .check_for_link = igb_check_for_link_82575,
31935@@ -1419,13 +1419,13 @@ static struct e1000_mac_operations e1000
31936 .get_speed_and_duplex = igb_get_speed_and_duplex_copper,
31937 };
31938
31939-static struct e1000_phy_operations e1000_phy_ops_82575 = {
31940+static const struct e1000_phy_operations e1000_phy_ops_82575 = {
31941 .acquire = igb_acquire_phy_82575,
31942 .get_cfg_done = igb_get_cfg_done_82575,
31943 .release = igb_release_phy_82575,
31944 };
31945
31946-static struct e1000_nvm_operations e1000_nvm_ops_82575 = {
31947+static const struct e1000_nvm_operations e1000_nvm_ops_82575 = {
31948 .acquire = igb_acquire_nvm_82575,
31949 .read = igb_read_nvm_eerd,
31950 .release = igb_release_nvm_82575,
31951diff -urNp linux-2.6.32.41/drivers/net/igb/e1000_hw.h linux-2.6.32.41/drivers/net/igb/e1000_hw.h
31952--- linux-2.6.32.41/drivers/net/igb/e1000_hw.h 2011-03-27 14:31:47.000000000 -0400
31953+++ linux-2.6.32.41/drivers/net/igb/e1000_hw.h 2011-04-17 15:56:46.000000000 -0400
31954@@ -305,17 +305,17 @@ struct e1000_phy_operations {
31955 };
31956
31957 struct e1000_nvm_operations {
31958- s32 (*acquire)(struct e1000_hw *);
31959- s32 (*read)(struct e1000_hw *, u16, u16, u16 *);
31960- void (*release)(struct e1000_hw *);
31961- s32 (*write)(struct e1000_hw *, u16, u16, u16 *);
31962+ s32 (* const acquire)(struct e1000_hw *);
31963+ s32 (* const read)(struct e1000_hw *, u16, u16, u16 *);
31964+ void (* const release)(struct e1000_hw *);
31965+ s32 (* const write)(struct e1000_hw *, u16, u16, u16 *);
31966 };
31967
31968 struct e1000_info {
31969 s32 (*get_invariants)(struct e1000_hw *);
31970- struct e1000_mac_operations *mac_ops;
31971- struct e1000_phy_operations *phy_ops;
31972- struct e1000_nvm_operations *nvm_ops;
31973+ const struct e1000_mac_operations *mac_ops;
31974+ const struct e1000_phy_operations *phy_ops;
31975+ const struct e1000_nvm_operations *nvm_ops;
31976 };
31977
31978 extern const struct e1000_info e1000_82575_info;
31979diff -urNp linux-2.6.32.41/drivers/net/iseries_veth.c linux-2.6.32.41/drivers/net/iseries_veth.c
31980--- linux-2.6.32.41/drivers/net/iseries_veth.c 2011-03-27 14:31:47.000000000 -0400
31981+++ linux-2.6.32.41/drivers/net/iseries_veth.c 2011-04-17 15:56:46.000000000 -0400
31982@@ -384,7 +384,7 @@ static struct attribute *veth_cnx_defaul
31983 NULL
31984 };
31985
31986-static struct sysfs_ops veth_cnx_sysfs_ops = {
31987+static const struct sysfs_ops veth_cnx_sysfs_ops = {
31988 .show = veth_cnx_attribute_show
31989 };
31990
31991@@ -441,7 +441,7 @@ static struct attribute *veth_port_defau
31992 NULL
31993 };
31994
31995-static struct sysfs_ops veth_port_sysfs_ops = {
31996+static const struct sysfs_ops veth_port_sysfs_ops = {
31997 .show = veth_port_attribute_show
31998 };
31999
32000diff -urNp linux-2.6.32.41/drivers/net/ixgb/ixgb_main.c linux-2.6.32.41/drivers/net/ixgb/ixgb_main.c
32001--- linux-2.6.32.41/drivers/net/ixgb/ixgb_main.c 2011-03-27 14:31:47.000000000 -0400
32002+++ linux-2.6.32.41/drivers/net/ixgb/ixgb_main.c 2011-05-16 21:46:57.000000000 -0400
32003@@ -1052,6 +1052,8 @@ ixgb_set_multi(struct net_device *netdev
32004 u32 rctl;
32005 int i;
32006
32007+ pax_track_stack();
32008+
32009 /* Check for Promiscuous and All Multicast modes */
32010
32011 rctl = IXGB_READ_REG(hw, RCTL);
32012diff -urNp linux-2.6.32.41/drivers/net/ixgb/ixgb_param.c linux-2.6.32.41/drivers/net/ixgb/ixgb_param.c
32013--- linux-2.6.32.41/drivers/net/ixgb/ixgb_param.c 2011-03-27 14:31:47.000000000 -0400
32014+++ linux-2.6.32.41/drivers/net/ixgb/ixgb_param.c 2011-05-16 21:46:57.000000000 -0400
32015@@ -260,6 +260,9 @@ void __devinit
32016 ixgb_check_options(struct ixgb_adapter *adapter)
32017 {
32018 int bd = adapter->bd_number;
32019+
32020+ pax_track_stack();
32021+
32022 if (bd >= IXGB_MAX_NIC) {
32023 printk(KERN_NOTICE
32024 "Warning: no configuration for board #%i\n", bd);
32025diff -urNp linux-2.6.32.41/drivers/net/mlx4/main.c linux-2.6.32.41/drivers/net/mlx4/main.c
32026--- linux-2.6.32.41/drivers/net/mlx4/main.c 2011-03-27 14:31:47.000000000 -0400
32027+++ linux-2.6.32.41/drivers/net/mlx4/main.c 2011-05-18 20:09:37.000000000 -0400
32028@@ -38,6 +38,7 @@
32029 #include <linux/errno.h>
32030 #include <linux/pci.h>
32031 #include <linux/dma-mapping.h>
32032+#include <linux/sched.h>
32033
32034 #include <linux/mlx4/device.h>
32035 #include <linux/mlx4/doorbell.h>
32036@@ -730,6 +731,8 @@ static int mlx4_init_hca(struct mlx4_dev
32037 u64 icm_size;
32038 int err;
32039
32040+ pax_track_stack();
32041+
32042 err = mlx4_QUERY_FW(dev);
32043 if (err) {
32044 if (err == -EACCES)
32045diff -urNp linux-2.6.32.41/drivers/net/niu.c linux-2.6.32.41/drivers/net/niu.c
32046--- linux-2.6.32.41/drivers/net/niu.c 2011-05-10 22:12:01.000000000 -0400
32047+++ linux-2.6.32.41/drivers/net/niu.c 2011-05-16 21:46:57.000000000 -0400
32048@@ -9128,6 +9128,8 @@ static void __devinit niu_try_msix(struc
32049 int i, num_irqs, err;
32050 u8 first_ldg;
32051
32052+ pax_track_stack();
32053+
32054 first_ldg = (NIU_NUM_LDG / parent->num_ports) * np->port;
32055 for (i = 0; i < (NIU_NUM_LDG / parent->num_ports); i++)
32056 ldg_num_map[i] = first_ldg + i;
32057diff -urNp linux-2.6.32.41/drivers/net/pcnet32.c linux-2.6.32.41/drivers/net/pcnet32.c
32058--- linux-2.6.32.41/drivers/net/pcnet32.c 2011-03-27 14:31:47.000000000 -0400
32059+++ linux-2.6.32.41/drivers/net/pcnet32.c 2011-04-17 15:56:46.000000000 -0400
32060@@ -79,7 +79,7 @@ static int cards_found;
32061 /*
32062 * VLB I/O addresses
32063 */
32064-static unsigned int pcnet32_portlist[] __initdata =
32065+static unsigned int pcnet32_portlist[] __devinitdata =
32066 { 0x300, 0x320, 0x340, 0x360, 0 };
32067
32068 static int pcnet32_debug = 0;
32069diff -urNp linux-2.6.32.41/drivers/net/tg3.h linux-2.6.32.41/drivers/net/tg3.h
32070--- linux-2.6.32.41/drivers/net/tg3.h 2011-03-27 14:31:47.000000000 -0400
32071+++ linux-2.6.32.41/drivers/net/tg3.h 2011-04-17 15:56:46.000000000 -0400
32072@@ -95,6 +95,7 @@
32073 #define CHIPREV_ID_5750_A0 0x4000
32074 #define CHIPREV_ID_5750_A1 0x4001
32075 #define CHIPREV_ID_5750_A3 0x4003
32076+#define CHIPREV_ID_5750_C1 0x4201
32077 #define CHIPREV_ID_5750_C2 0x4202
32078 #define CHIPREV_ID_5752_A0_HW 0x5000
32079 #define CHIPREV_ID_5752_A0 0x6000
32080diff -urNp linux-2.6.32.41/drivers/net/tulip/de2104x.c linux-2.6.32.41/drivers/net/tulip/de2104x.c
32081--- linux-2.6.32.41/drivers/net/tulip/de2104x.c 2011-03-27 14:31:47.000000000 -0400
32082+++ linux-2.6.32.41/drivers/net/tulip/de2104x.c 2011-05-16 21:46:57.000000000 -0400
32083@@ -1785,6 +1785,8 @@ static void __devinit de21041_get_srom_i
32084 struct de_srom_info_leaf *il;
32085 void *bufp;
32086
32087+ pax_track_stack();
32088+
32089 /* download entire eeprom */
32090 for (i = 0; i < DE_EEPROM_WORDS; i++)
32091 ((__le16 *)ee_data)[i] =
32092diff -urNp linux-2.6.32.41/drivers/net/tulip/de4x5.c linux-2.6.32.41/drivers/net/tulip/de4x5.c
32093--- linux-2.6.32.41/drivers/net/tulip/de4x5.c 2011-03-27 14:31:47.000000000 -0400
32094+++ linux-2.6.32.41/drivers/net/tulip/de4x5.c 2011-04-17 15:56:46.000000000 -0400
32095@@ -5472,7 +5472,7 @@ de4x5_ioctl(struct net_device *dev, stru
32096 for (i=0; i<ETH_ALEN; i++) {
32097 tmp.addr[i] = dev->dev_addr[i];
32098 }
32099- if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
32100+ if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
32101 break;
32102
32103 case DE4X5_SET_HWADDR: /* Set the hardware address */
32104@@ -5512,7 +5512,7 @@ de4x5_ioctl(struct net_device *dev, stru
32105 spin_lock_irqsave(&lp->lock, flags);
32106 memcpy(&statbuf, &lp->pktStats, ioc->len);
32107 spin_unlock_irqrestore(&lp->lock, flags);
32108- if (copy_to_user(ioc->data, &statbuf, ioc->len))
32109+ if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
32110 return -EFAULT;
32111 break;
32112 }
32113diff -urNp linux-2.6.32.41/drivers/net/usb/hso.c linux-2.6.32.41/drivers/net/usb/hso.c
32114--- linux-2.6.32.41/drivers/net/usb/hso.c 2011-03-27 14:31:47.000000000 -0400
32115+++ linux-2.6.32.41/drivers/net/usb/hso.c 2011-04-17 15:56:46.000000000 -0400
32116@@ -71,7 +71,7 @@
32117 #include <asm/byteorder.h>
32118 #include <linux/serial_core.h>
32119 #include <linux/serial.h>
32120-
32121+#include <asm/local.h>
32122
32123 #define DRIVER_VERSION "1.2"
32124 #define MOD_AUTHOR "Option Wireless"
32125@@ -258,7 +258,7 @@ struct hso_serial {
32126
32127 /* from usb_serial_port */
32128 struct tty_struct *tty;
32129- int open_count;
32130+ local_t open_count;
32131 spinlock_t serial_lock;
32132
32133 int (*write_data) (struct hso_serial *serial);
32134@@ -1180,7 +1180,7 @@ static void put_rxbuf_data_and_resubmit_
32135 struct urb *urb;
32136
32137 urb = serial->rx_urb[0];
32138- if (serial->open_count > 0) {
32139+ if (local_read(&serial->open_count) > 0) {
32140 count = put_rxbuf_data(urb, serial);
32141 if (count == -1)
32142 return;
32143@@ -1216,7 +1216,7 @@ static void hso_std_serial_read_bulk_cal
32144 DUMP1(urb->transfer_buffer, urb->actual_length);
32145
32146 /* Anyone listening? */
32147- if (serial->open_count == 0)
32148+ if (local_read(&serial->open_count) == 0)
32149 return;
32150
32151 if (status == 0) {
32152@@ -1311,8 +1311,7 @@ static int hso_serial_open(struct tty_st
32153 spin_unlock_irq(&serial->serial_lock);
32154
32155 /* check for port already opened, if not set the termios */
32156- serial->open_count++;
32157- if (serial->open_count == 1) {
32158+ if (local_inc_return(&serial->open_count) == 1) {
32159 tty->low_latency = 1;
32160 serial->rx_state = RX_IDLE;
32161 /* Force default termio settings */
32162@@ -1325,7 +1324,7 @@ static int hso_serial_open(struct tty_st
32163 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
32164 if (result) {
32165 hso_stop_serial_device(serial->parent);
32166- serial->open_count--;
32167+ local_dec(&serial->open_count);
32168 kref_put(&serial->parent->ref, hso_serial_ref_free);
32169 }
32170 } else {
32171@@ -1362,10 +1361,10 @@ static void hso_serial_close(struct tty_
32172
32173 /* reset the rts and dtr */
32174 /* do the actual close */
32175- serial->open_count--;
32176+ local_dec(&serial->open_count);
32177
32178- if (serial->open_count <= 0) {
32179- serial->open_count = 0;
32180+ if (local_read(&serial->open_count) <= 0) {
32181+ local_set(&serial->open_count, 0);
32182 spin_lock_irq(&serial->serial_lock);
32183 if (serial->tty == tty) {
32184 serial->tty->driver_data = NULL;
32185@@ -1447,7 +1446,7 @@ static void hso_serial_set_termios(struc
32186
32187 /* the actual setup */
32188 spin_lock_irqsave(&serial->serial_lock, flags);
32189- if (serial->open_count)
32190+ if (local_read(&serial->open_count))
32191 _hso_serial_set_termios(tty, old);
32192 else
32193 tty->termios = old;
32194@@ -3097,7 +3096,7 @@ static int hso_resume(struct usb_interfa
32195 /* Start all serial ports */
32196 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
32197 if (serial_table[i] && (serial_table[i]->interface == iface)) {
32198- if (dev2ser(serial_table[i])->open_count) {
32199+ if (local_read(&dev2ser(serial_table[i])->open_count)) {
32200 result =
32201 hso_start_serial_device(serial_table[i], GFP_NOIO);
32202 hso_kick_transmit(dev2ser(serial_table[i]));
32203diff -urNp linux-2.6.32.41/drivers/net/vxge/vxge-main.c linux-2.6.32.41/drivers/net/vxge/vxge-main.c
32204--- linux-2.6.32.41/drivers/net/vxge/vxge-main.c 2011-03-27 14:31:47.000000000 -0400
32205+++ linux-2.6.32.41/drivers/net/vxge/vxge-main.c 2011-05-16 21:46:57.000000000 -0400
32206@@ -93,6 +93,8 @@ static inline void VXGE_COMPLETE_VPATH_T
32207 struct sk_buff *completed[NR_SKB_COMPLETED];
32208 int more;
32209
32210+ pax_track_stack();
32211+
32212 do {
32213 more = 0;
32214 skb_ptr = completed;
32215@@ -1779,6 +1781,8 @@ static enum vxge_hw_status vxge_rth_conf
32216 u8 mtable[256] = {0}; /* CPU to vpath mapping */
32217 int index;
32218
32219+ pax_track_stack();
32220+
32221 /*
32222 * Filling
32223 * - itable with bucket numbers
32224diff -urNp linux-2.6.32.41/drivers/net/wan/cycx_x25.c linux-2.6.32.41/drivers/net/wan/cycx_x25.c
32225--- linux-2.6.32.41/drivers/net/wan/cycx_x25.c 2011-03-27 14:31:47.000000000 -0400
32226+++ linux-2.6.32.41/drivers/net/wan/cycx_x25.c 2011-05-16 21:46:57.000000000 -0400
32227@@ -1017,6 +1017,8 @@ static void hex_dump(char *msg, unsigned
32228 unsigned char hex[1024],
32229 * phex = hex;
32230
32231+ pax_track_stack();
32232+
32233 if (len >= (sizeof(hex) / 2))
32234 len = (sizeof(hex) / 2) - 1;
32235
32236diff -urNp linux-2.6.32.41/drivers/net/wimax/i2400m/usb-fw.c linux-2.6.32.41/drivers/net/wimax/i2400m/usb-fw.c
32237--- linux-2.6.32.41/drivers/net/wimax/i2400m/usb-fw.c 2011-03-27 14:31:47.000000000 -0400
32238+++ linux-2.6.32.41/drivers/net/wimax/i2400m/usb-fw.c 2011-05-16 21:46:57.000000000 -0400
32239@@ -263,6 +263,8 @@ ssize_t i2400mu_bus_bm_wait_for_ack(stru
32240 int do_autopm = 1;
32241 DECLARE_COMPLETION_ONSTACK(notif_completion);
32242
32243+ pax_track_stack();
32244+
32245 d_fnstart(8, dev, "(i2400m %p ack %p size %zu)\n",
32246 i2400m, ack, ack_size);
32247 BUG_ON(_ack == i2400m->bm_ack_buf);
32248diff -urNp linux-2.6.32.41/drivers/net/wireless/airo.c linux-2.6.32.41/drivers/net/wireless/airo.c
32249--- linux-2.6.32.41/drivers/net/wireless/airo.c 2011-03-27 14:31:47.000000000 -0400
32250+++ linux-2.6.32.41/drivers/net/wireless/airo.c 2011-05-16 21:46:57.000000000 -0400
32251@@ -3003,6 +3003,8 @@ static void airo_process_scan_results (s
32252 BSSListElement * loop_net;
32253 BSSListElement * tmp_net;
32254
32255+ pax_track_stack();
32256+
32257 /* Blow away current list of scan results */
32258 list_for_each_entry_safe (loop_net, tmp_net, &ai->network_list, list) {
32259 list_move_tail (&loop_net->list, &ai->network_free_list);
32260@@ -3783,6 +3785,8 @@ static u16 setup_card(struct airo_info *
32261 WepKeyRid wkr;
32262 int rc;
32263
32264+ pax_track_stack();
32265+
32266 memset( &mySsid, 0, sizeof( mySsid ) );
32267 kfree (ai->flash);
32268 ai->flash = NULL;
32269@@ -4758,6 +4762,8 @@ static int proc_stats_rid_open( struct i
32270 __le32 *vals = stats.vals;
32271 int len;
32272
32273+ pax_track_stack();
32274+
32275 if ((file->private_data = kzalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL)
32276 return -ENOMEM;
32277 data = (struct proc_data *)file->private_data;
32278@@ -5487,6 +5493,8 @@ static int proc_BSSList_open( struct ino
32279 /* If doLoseSync is not 1, we won't do a Lose Sync */
32280 int doLoseSync = -1;
32281
32282+ pax_track_stack();
32283+
32284 if ((file->private_data = kzalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL)
32285 return -ENOMEM;
32286 data = (struct proc_data *)file->private_data;
32287@@ -7193,6 +7201,8 @@ static int airo_get_aplist(struct net_de
32288 int i;
32289 int loseSync = capable(CAP_NET_ADMIN) ? 1: -1;
32290
32291+ pax_track_stack();
32292+
32293 qual = kmalloc(IW_MAX_AP * sizeof(*qual), GFP_KERNEL);
32294 if (!qual)
32295 return -ENOMEM;
32296@@ -7753,6 +7763,8 @@ static void airo_read_wireless_stats(str
32297 CapabilityRid cap_rid;
32298 __le32 *vals = stats_rid.vals;
32299
32300+ pax_track_stack();
32301+
32302 /* Get stats out of the card */
32303 clear_bit(JOB_WSTATS, &local->jobs);
32304 if (local->power.event) {
32305diff -urNp linux-2.6.32.41/drivers/net/wireless/ath/ath5k/debug.c linux-2.6.32.41/drivers/net/wireless/ath/ath5k/debug.c
32306--- linux-2.6.32.41/drivers/net/wireless/ath/ath5k/debug.c 2011-03-27 14:31:47.000000000 -0400
32307+++ linux-2.6.32.41/drivers/net/wireless/ath/ath5k/debug.c 2011-05-16 21:46:57.000000000 -0400
32308@@ -205,6 +205,8 @@ static ssize_t read_file_beacon(struct f
32309 unsigned int v;
32310 u64 tsf;
32311
32312+ pax_track_stack();
32313+
32314 v = ath5k_hw_reg_read(sc->ah, AR5K_BEACON);
32315 len += snprintf(buf+len, sizeof(buf)-len,
32316 "%-24s0x%08x\tintval: %d\tTIM: 0x%x\n",
32317@@ -318,6 +320,8 @@ static ssize_t read_file_debug(struct fi
32318 unsigned int len = 0;
32319 unsigned int i;
32320
32321+ pax_track_stack();
32322+
32323 len += snprintf(buf+len, sizeof(buf)-len,
32324 "DEBUG LEVEL: 0x%08x\n\n", sc->debug.level);
32325
32326diff -urNp linux-2.6.32.41/drivers/net/wireless/ath/ath9k/debug.c linux-2.6.32.41/drivers/net/wireless/ath/ath9k/debug.c
32327--- linux-2.6.32.41/drivers/net/wireless/ath/ath9k/debug.c 2011-03-27 14:31:47.000000000 -0400
32328+++ linux-2.6.32.41/drivers/net/wireless/ath/ath9k/debug.c 2011-05-16 21:46:57.000000000 -0400
32329@@ -220,6 +220,8 @@ static ssize_t read_file_interrupt(struc
32330 char buf[512];
32331 unsigned int len = 0;
32332
32333+ pax_track_stack();
32334+
32335 len += snprintf(buf + len, sizeof(buf) - len,
32336 "%8s: %10u\n", "RX", sc->debug.stats.istats.rxok);
32337 len += snprintf(buf + len, sizeof(buf) - len,
32338@@ -360,6 +362,8 @@ static ssize_t read_file_wiphy(struct fi
32339 int i;
32340 u8 addr[ETH_ALEN];
32341
32342+ pax_track_stack();
32343+
32344 len += snprintf(buf + len, sizeof(buf) - len,
32345 "primary: %s (%s chan=%d ht=%d)\n",
32346 wiphy_name(sc->pri_wiphy->hw->wiphy),
32347diff -urNp linux-2.6.32.41/drivers/net/wireless/b43/debugfs.c linux-2.6.32.41/drivers/net/wireless/b43/debugfs.c
32348--- linux-2.6.32.41/drivers/net/wireless/b43/debugfs.c 2011-03-27 14:31:47.000000000 -0400
32349+++ linux-2.6.32.41/drivers/net/wireless/b43/debugfs.c 2011-04-17 15:56:46.000000000 -0400
32350@@ -43,7 +43,7 @@ static struct dentry *rootdir;
32351 struct b43_debugfs_fops {
32352 ssize_t (*read)(struct b43_wldev *dev, char *buf, size_t bufsize);
32353 int (*write)(struct b43_wldev *dev, const char *buf, size_t count);
32354- struct file_operations fops;
32355+ const struct file_operations fops;
32356 /* Offset of struct b43_dfs_file in struct b43_dfsentry */
32357 size_t file_struct_offset;
32358 };
32359diff -urNp linux-2.6.32.41/drivers/net/wireless/b43legacy/debugfs.c linux-2.6.32.41/drivers/net/wireless/b43legacy/debugfs.c
32360--- linux-2.6.32.41/drivers/net/wireless/b43legacy/debugfs.c 2011-03-27 14:31:47.000000000 -0400
32361+++ linux-2.6.32.41/drivers/net/wireless/b43legacy/debugfs.c 2011-04-17 15:56:46.000000000 -0400
32362@@ -44,7 +44,7 @@ static struct dentry *rootdir;
32363 struct b43legacy_debugfs_fops {
32364 ssize_t (*read)(struct b43legacy_wldev *dev, char *buf, size_t bufsize);
32365 int (*write)(struct b43legacy_wldev *dev, const char *buf, size_t count);
32366- struct file_operations fops;
32367+ const struct file_operations fops;
32368 /* Offset of struct b43legacy_dfs_file in struct b43legacy_dfsentry */
32369 size_t file_struct_offset;
32370 /* Take wl->irq_lock before calling read/write? */
32371diff -urNp linux-2.6.32.41/drivers/net/wireless/ipw2x00/ipw2100.c linux-2.6.32.41/drivers/net/wireless/ipw2x00/ipw2100.c
32372--- linux-2.6.32.41/drivers/net/wireless/ipw2x00/ipw2100.c 2011-03-27 14:31:47.000000000 -0400
32373+++ linux-2.6.32.41/drivers/net/wireless/ipw2x00/ipw2100.c 2011-05-16 21:46:57.000000000 -0400
32374@@ -2014,6 +2014,8 @@ static int ipw2100_set_essid(struct ipw2
32375 int err;
32376 DECLARE_SSID_BUF(ssid);
32377
32378+ pax_track_stack();
32379+
32380 IPW_DEBUG_HC("SSID: '%s'\n", print_ssid(ssid, essid, ssid_len));
32381
32382 if (ssid_len)
32383@@ -5380,6 +5382,8 @@ static int ipw2100_set_key(struct ipw210
32384 struct ipw2100_wep_key *wep_key = (void *)cmd.host_command_parameters;
32385 int err;
32386
32387+ pax_track_stack();
32388+
32389 IPW_DEBUG_HC("WEP_KEY_INFO: index = %d, len = %d/%d\n",
32390 idx, keylen, len);
32391
32392diff -urNp linux-2.6.32.41/drivers/net/wireless/ipw2x00/libipw_rx.c linux-2.6.32.41/drivers/net/wireless/ipw2x00/libipw_rx.c
32393--- linux-2.6.32.41/drivers/net/wireless/ipw2x00/libipw_rx.c 2011-03-27 14:31:47.000000000 -0400
32394+++ linux-2.6.32.41/drivers/net/wireless/ipw2x00/libipw_rx.c 2011-05-16 21:46:57.000000000 -0400
32395@@ -1566,6 +1566,8 @@ static void libipw_process_probe_respons
32396 unsigned long flags;
32397 DECLARE_SSID_BUF(ssid);
32398
32399+ pax_track_stack();
32400+
32401 LIBIPW_DEBUG_SCAN("'%s' (%pM"
32402 "): %c%c%c%c %c%c%c%c-%c%c%c%c %c%c%c%c\n",
32403 print_ssid(ssid, info_element->data, info_element->len),
32404diff -urNp linux-2.6.32.41/drivers/net/wireless/iwlwifi/iwl-1000.c linux-2.6.32.41/drivers/net/wireless/iwlwifi/iwl-1000.c
32405--- linux-2.6.32.41/drivers/net/wireless/iwlwifi/iwl-1000.c 2011-03-27 14:31:47.000000000 -0400
32406+++ linux-2.6.32.41/drivers/net/wireless/iwlwifi/iwl-1000.c 2011-04-17 15:56:46.000000000 -0400
32407@@ -137,7 +137,7 @@ static struct iwl_lib_ops iwl1000_lib =
32408 },
32409 };
32410
32411-static struct iwl_ops iwl1000_ops = {
32412+static const struct iwl_ops iwl1000_ops = {
32413 .ucode = &iwl5000_ucode,
32414 .lib = &iwl1000_lib,
32415 .hcmd = &iwl5000_hcmd,
32416diff -urNp linux-2.6.32.41/drivers/net/wireless/iwlwifi/iwl-3945.c linux-2.6.32.41/drivers/net/wireless/iwlwifi/iwl-3945.c
32417--- linux-2.6.32.41/drivers/net/wireless/iwlwifi/iwl-3945.c 2011-03-27 14:31:47.000000000 -0400
32418+++ linux-2.6.32.41/drivers/net/wireless/iwlwifi/iwl-3945.c 2011-04-17 15:56:46.000000000 -0400
32419@@ -2874,7 +2874,7 @@ static struct iwl_hcmd_utils_ops iwl3945
32420 .build_addsta_hcmd = iwl3945_build_addsta_hcmd,
32421 };
32422
32423-static struct iwl_ops iwl3945_ops = {
32424+static const struct iwl_ops iwl3945_ops = {
32425 .ucode = &iwl3945_ucode,
32426 .lib = &iwl3945_lib,
32427 .hcmd = &iwl3945_hcmd,
32428diff -urNp linux-2.6.32.41/drivers/net/wireless/iwlwifi/iwl-4965.c linux-2.6.32.41/drivers/net/wireless/iwlwifi/iwl-4965.c
32429--- linux-2.6.32.41/drivers/net/wireless/iwlwifi/iwl-4965.c 2011-03-27 14:31:47.000000000 -0400
32430+++ linux-2.6.32.41/drivers/net/wireless/iwlwifi/iwl-4965.c 2011-04-17 15:56:46.000000000 -0400
32431@@ -2345,7 +2345,7 @@ static struct iwl_lib_ops iwl4965_lib =
32432 },
32433 };
32434
32435-static struct iwl_ops iwl4965_ops = {
32436+static const struct iwl_ops iwl4965_ops = {
32437 .ucode = &iwl4965_ucode,
32438 .lib = &iwl4965_lib,
32439 .hcmd = &iwl4965_hcmd,
32440diff -urNp linux-2.6.32.41/drivers/net/wireless/iwlwifi/iwl-5000.c linux-2.6.32.41/drivers/net/wireless/iwlwifi/iwl-5000.c
32441--- linux-2.6.32.41/drivers/net/wireless/iwlwifi/iwl-5000.c 2011-05-10 22:12:01.000000000 -0400
32442+++ linux-2.6.32.41/drivers/net/wireless/iwlwifi/iwl-5000.c 2011-05-10 22:12:32.000000000 -0400
32443@@ -1633,14 +1633,14 @@ static struct iwl_lib_ops iwl5150_lib =
32444 },
32445 };
32446
32447-struct iwl_ops iwl5000_ops = {
32448+const struct iwl_ops iwl5000_ops = {
32449 .ucode = &iwl5000_ucode,
32450 .lib = &iwl5000_lib,
32451 .hcmd = &iwl5000_hcmd,
32452 .utils = &iwl5000_hcmd_utils,
32453 };
32454
32455-static struct iwl_ops iwl5150_ops = {
32456+static const struct iwl_ops iwl5150_ops = {
32457 .ucode = &iwl5000_ucode,
32458 .lib = &iwl5150_lib,
32459 .hcmd = &iwl5000_hcmd,
32460diff -urNp linux-2.6.32.41/drivers/net/wireless/iwlwifi/iwl-6000.c linux-2.6.32.41/drivers/net/wireless/iwlwifi/iwl-6000.c
32461--- linux-2.6.32.41/drivers/net/wireless/iwlwifi/iwl-6000.c 2011-03-27 14:31:47.000000000 -0400
32462+++ linux-2.6.32.41/drivers/net/wireless/iwlwifi/iwl-6000.c 2011-04-17 15:56:46.000000000 -0400
32463@@ -146,7 +146,7 @@ static struct iwl_hcmd_utils_ops iwl6000
32464 .calc_rssi = iwl5000_calc_rssi,
32465 };
32466
32467-static struct iwl_ops iwl6000_ops = {
32468+static const struct iwl_ops iwl6000_ops = {
32469 .ucode = &iwl5000_ucode,
32470 .lib = &iwl6000_lib,
32471 .hcmd = &iwl5000_hcmd,
32472diff -urNp linux-2.6.32.41/drivers/net/wireless/iwlwifi/iwl-agn-rs.c linux-2.6.32.41/drivers/net/wireless/iwlwifi/iwl-agn-rs.c
32473--- linux-2.6.32.41/drivers/net/wireless/iwlwifi/iwl-agn-rs.c 2011-03-27 14:31:47.000000000 -0400
32474+++ linux-2.6.32.41/drivers/net/wireless/iwlwifi/iwl-agn-rs.c 2011-05-16 21:46:57.000000000 -0400
32475@@ -857,6 +857,8 @@ static void rs_tx_status(void *priv_r, s
32476 u8 active_index = 0;
32477 s32 tpt = 0;
32478
32479+ pax_track_stack();
32480+
32481 IWL_DEBUG_RATE_LIMIT(priv, "get frame ack response, update rate scale window\n");
32482
32483 if (!ieee80211_is_data(hdr->frame_control) ||
32484@@ -2722,6 +2724,8 @@ static void rs_fill_link_cmd(struct iwl_
32485 u8 valid_tx_ant = 0;
32486 struct iwl_link_quality_cmd *lq_cmd = &lq_sta->lq;
32487
32488+ pax_track_stack();
32489+
32490 /* Override starting rate (index 0) if needed for debug purposes */
32491 rs_dbgfs_set_mcs(lq_sta, &new_rate, index);
32492
32493diff -urNp linux-2.6.32.41/drivers/net/wireless/iwlwifi/iwl-debugfs.c linux-2.6.32.41/drivers/net/wireless/iwlwifi/iwl-debugfs.c
32494--- linux-2.6.32.41/drivers/net/wireless/iwlwifi/iwl-debugfs.c 2011-03-27 14:31:47.000000000 -0400
32495+++ linux-2.6.32.41/drivers/net/wireless/iwlwifi/iwl-debugfs.c 2011-05-16 21:46:57.000000000 -0400
32496@@ -524,6 +524,8 @@ static ssize_t iwl_dbgfs_status_read(str
32497 int pos = 0;
32498 const size_t bufsz = sizeof(buf);
32499
32500+ pax_track_stack();
32501+
32502 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_HCMD_ACTIVE:\t %d\n",
32503 test_bit(STATUS_HCMD_ACTIVE, &priv->status));
32504 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_HCMD_SYNC_ACTIVE: %d\n",
32505@@ -658,6 +660,8 @@ static ssize_t iwl_dbgfs_qos_read(struct
32506 const size_t bufsz = sizeof(buf);
32507 ssize_t ret;
32508
32509+ pax_track_stack();
32510+
32511 for (i = 0; i < AC_NUM; i++) {
32512 pos += scnprintf(buf + pos, bufsz - pos,
32513 "\tcw_min\tcw_max\taifsn\ttxop\n");
32514diff -urNp linux-2.6.32.41/drivers/net/wireless/iwlwifi/iwl-debug.h linux-2.6.32.41/drivers/net/wireless/iwlwifi/iwl-debug.h
32515--- linux-2.6.32.41/drivers/net/wireless/iwlwifi/iwl-debug.h 2011-03-27 14:31:47.000000000 -0400
32516+++ linux-2.6.32.41/drivers/net/wireless/iwlwifi/iwl-debug.h 2011-04-17 15:56:46.000000000 -0400
32517@@ -118,8 +118,8 @@ void iwl_dbgfs_unregister(struct iwl_pri
32518 #endif
32519
32520 #else
32521-#define IWL_DEBUG(__priv, level, fmt, args...)
32522-#define IWL_DEBUG_LIMIT(__priv, level, fmt, args...)
32523+#define IWL_DEBUG(__priv, level, fmt, args...) do {} while (0)
32524+#define IWL_DEBUG_LIMIT(__priv, level, fmt, args...) do {} while (0)
32525 static inline void iwl_print_hex_dump(struct iwl_priv *priv, int level,
32526 void *p, u32 len)
32527 {}
32528diff -urNp linux-2.6.32.41/drivers/net/wireless/iwlwifi/iwl-dev.h linux-2.6.32.41/drivers/net/wireless/iwlwifi/iwl-dev.h
32529--- linux-2.6.32.41/drivers/net/wireless/iwlwifi/iwl-dev.h 2011-03-27 14:31:47.000000000 -0400
32530+++ linux-2.6.32.41/drivers/net/wireless/iwlwifi/iwl-dev.h 2011-04-17 15:56:46.000000000 -0400
32531@@ -68,7 +68,7 @@ struct iwl_tx_queue;
32532
32533 /* shared structures from iwl-5000.c */
32534 extern struct iwl_mod_params iwl50_mod_params;
32535-extern struct iwl_ops iwl5000_ops;
32536+extern const struct iwl_ops iwl5000_ops;
32537 extern struct iwl_ucode_ops iwl5000_ucode;
32538 extern struct iwl_lib_ops iwl5000_lib;
32539 extern struct iwl_hcmd_ops iwl5000_hcmd;
32540diff -urNp linux-2.6.32.41/drivers/net/wireless/iwmc3200wifi/debugfs.c linux-2.6.32.41/drivers/net/wireless/iwmc3200wifi/debugfs.c
32541--- linux-2.6.32.41/drivers/net/wireless/iwmc3200wifi/debugfs.c 2011-03-27 14:31:47.000000000 -0400
32542+++ linux-2.6.32.41/drivers/net/wireless/iwmc3200wifi/debugfs.c 2011-05-16 21:46:57.000000000 -0400
32543@@ -299,6 +299,8 @@ static ssize_t iwm_debugfs_fw_err_read(s
32544 int buf_len = 512;
32545 size_t len = 0;
32546
32547+ pax_track_stack();
32548+
32549 if (*ppos != 0)
32550 return 0;
32551 if (count < sizeof(buf))
32552diff -urNp linux-2.6.32.41/drivers/net/wireless/libertas/debugfs.c linux-2.6.32.41/drivers/net/wireless/libertas/debugfs.c
32553--- linux-2.6.32.41/drivers/net/wireless/libertas/debugfs.c 2011-03-27 14:31:47.000000000 -0400
32554+++ linux-2.6.32.41/drivers/net/wireless/libertas/debugfs.c 2011-04-17 15:56:46.000000000 -0400
32555@@ -708,7 +708,7 @@ out_unlock:
32556 struct lbs_debugfs_files {
32557 const char *name;
32558 int perm;
32559- struct file_operations fops;
32560+ const struct file_operations fops;
32561 };
32562
32563 static const struct lbs_debugfs_files debugfs_files[] = {
32564diff -urNp linux-2.6.32.41/drivers/net/wireless/rndis_wlan.c linux-2.6.32.41/drivers/net/wireless/rndis_wlan.c
32565--- linux-2.6.32.41/drivers/net/wireless/rndis_wlan.c 2011-03-27 14:31:47.000000000 -0400
32566+++ linux-2.6.32.41/drivers/net/wireless/rndis_wlan.c 2011-04-17 15:56:46.000000000 -0400
32567@@ -1176,7 +1176,7 @@ static int set_rts_threshold(struct usbn
32568
32569 devdbg(usbdev, "set_rts_threshold %i", rts_threshold);
32570
32571- if (rts_threshold < 0 || rts_threshold > 2347)
32572+ if (rts_threshold > 2347)
32573 rts_threshold = 2347;
32574
32575 tmp = cpu_to_le32(rts_threshold);
32576diff -urNp linux-2.6.32.41/drivers/oprofile/buffer_sync.c linux-2.6.32.41/drivers/oprofile/buffer_sync.c
32577--- linux-2.6.32.41/drivers/oprofile/buffer_sync.c 2011-03-27 14:31:47.000000000 -0400
32578+++ linux-2.6.32.41/drivers/oprofile/buffer_sync.c 2011-04-17 15:56:46.000000000 -0400
32579@@ -341,7 +341,7 @@ static void add_data(struct op_entry *en
32580 if (cookie == NO_COOKIE)
32581 offset = pc;
32582 if (cookie == INVALID_COOKIE) {
32583- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
32584+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
32585 offset = pc;
32586 }
32587 if (cookie != last_cookie) {
32588@@ -385,14 +385,14 @@ add_sample(struct mm_struct *mm, struct
32589 /* add userspace sample */
32590
32591 if (!mm) {
32592- atomic_inc(&oprofile_stats.sample_lost_no_mm);
32593+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
32594 return 0;
32595 }
32596
32597 cookie = lookup_dcookie(mm, s->eip, &offset);
32598
32599 if (cookie == INVALID_COOKIE) {
32600- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
32601+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
32602 return 0;
32603 }
32604
32605@@ -561,7 +561,7 @@ void sync_buffer(int cpu)
32606 /* ignore backtraces if failed to add a sample */
32607 if (state == sb_bt_start) {
32608 state = sb_bt_ignore;
32609- atomic_inc(&oprofile_stats.bt_lost_no_mapping);
32610+ atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
32611 }
32612 }
32613 release_mm(mm);
32614diff -urNp linux-2.6.32.41/drivers/oprofile/event_buffer.c linux-2.6.32.41/drivers/oprofile/event_buffer.c
32615--- linux-2.6.32.41/drivers/oprofile/event_buffer.c 2011-03-27 14:31:47.000000000 -0400
32616+++ linux-2.6.32.41/drivers/oprofile/event_buffer.c 2011-04-17 15:56:46.000000000 -0400
32617@@ -53,7 +53,7 @@ void add_event_entry(unsigned long value
32618 }
32619
32620 if (buffer_pos == buffer_size) {
32621- atomic_inc(&oprofile_stats.event_lost_overflow);
32622+ atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
32623 return;
32624 }
32625
32626diff -urNp linux-2.6.32.41/drivers/oprofile/oprof.c linux-2.6.32.41/drivers/oprofile/oprof.c
32627--- linux-2.6.32.41/drivers/oprofile/oprof.c 2011-03-27 14:31:47.000000000 -0400
32628+++ linux-2.6.32.41/drivers/oprofile/oprof.c 2011-04-17 15:56:46.000000000 -0400
32629@@ -110,7 +110,7 @@ static void switch_worker(struct work_st
32630 if (oprofile_ops.switch_events())
32631 return;
32632
32633- atomic_inc(&oprofile_stats.multiplex_counter);
32634+ atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
32635 start_switch_worker();
32636 }
32637
32638diff -urNp linux-2.6.32.41/drivers/oprofile/oprofilefs.c linux-2.6.32.41/drivers/oprofile/oprofilefs.c
32639--- linux-2.6.32.41/drivers/oprofile/oprofilefs.c 2011-03-27 14:31:47.000000000 -0400
32640+++ linux-2.6.32.41/drivers/oprofile/oprofilefs.c 2011-04-17 15:56:46.000000000 -0400
32641@@ -187,7 +187,7 @@ static const struct file_operations atom
32642
32643
32644 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
32645- char const *name, atomic_t *val)
32646+ char const *name, atomic_unchecked_t *val)
32647 {
32648 struct dentry *d = __oprofilefs_create_file(sb, root, name,
32649 &atomic_ro_fops, 0444);
32650diff -urNp linux-2.6.32.41/drivers/oprofile/oprofile_stats.c linux-2.6.32.41/drivers/oprofile/oprofile_stats.c
32651--- linux-2.6.32.41/drivers/oprofile/oprofile_stats.c 2011-03-27 14:31:47.000000000 -0400
32652+++ linux-2.6.32.41/drivers/oprofile/oprofile_stats.c 2011-04-17 15:56:46.000000000 -0400
32653@@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
32654 cpu_buf->sample_invalid_eip = 0;
32655 }
32656
32657- atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
32658- atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
32659- atomic_set(&oprofile_stats.event_lost_overflow, 0);
32660- atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
32661- atomic_set(&oprofile_stats.multiplex_counter, 0);
32662+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
32663+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
32664+ atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
32665+ atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
32666+ atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
32667 }
32668
32669
32670diff -urNp linux-2.6.32.41/drivers/oprofile/oprofile_stats.h linux-2.6.32.41/drivers/oprofile/oprofile_stats.h
32671--- linux-2.6.32.41/drivers/oprofile/oprofile_stats.h 2011-03-27 14:31:47.000000000 -0400
32672+++ linux-2.6.32.41/drivers/oprofile/oprofile_stats.h 2011-04-17 15:56:46.000000000 -0400
32673@@ -13,11 +13,11 @@
32674 #include <asm/atomic.h>
32675
32676 struct oprofile_stat_struct {
32677- atomic_t sample_lost_no_mm;
32678- atomic_t sample_lost_no_mapping;
32679- atomic_t bt_lost_no_mapping;
32680- atomic_t event_lost_overflow;
32681- atomic_t multiplex_counter;
32682+ atomic_unchecked_t sample_lost_no_mm;
32683+ atomic_unchecked_t sample_lost_no_mapping;
32684+ atomic_unchecked_t bt_lost_no_mapping;
32685+ atomic_unchecked_t event_lost_overflow;
32686+ atomic_unchecked_t multiplex_counter;
32687 };
32688
32689 extern struct oprofile_stat_struct oprofile_stats;
32690diff -urNp linux-2.6.32.41/drivers/parisc/pdc_stable.c linux-2.6.32.41/drivers/parisc/pdc_stable.c
32691--- linux-2.6.32.41/drivers/parisc/pdc_stable.c 2011-03-27 14:31:47.000000000 -0400
32692+++ linux-2.6.32.41/drivers/parisc/pdc_stable.c 2011-04-17 15:56:46.000000000 -0400
32693@@ -481,7 +481,7 @@ pdcspath_attr_store(struct kobject *kobj
32694 return ret;
32695 }
32696
32697-static struct sysfs_ops pdcspath_attr_ops = {
32698+static const struct sysfs_ops pdcspath_attr_ops = {
32699 .show = pdcspath_attr_show,
32700 .store = pdcspath_attr_store,
32701 };
32702diff -urNp linux-2.6.32.41/drivers/parport/procfs.c linux-2.6.32.41/drivers/parport/procfs.c
32703--- linux-2.6.32.41/drivers/parport/procfs.c 2011-03-27 14:31:47.000000000 -0400
32704+++ linux-2.6.32.41/drivers/parport/procfs.c 2011-04-17 15:56:46.000000000 -0400
32705@@ -64,7 +64,7 @@ static int do_active_device(ctl_table *t
32706
32707 *ppos += len;
32708
32709- return copy_to_user(result, buffer, len) ? -EFAULT : 0;
32710+ return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
32711 }
32712
32713 #ifdef CONFIG_PARPORT_1284
32714@@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table
32715
32716 *ppos += len;
32717
32718- return copy_to_user (result, buffer, len) ? -EFAULT : 0;
32719+ return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
32720 }
32721 #endif /* IEEE1284.3 support. */
32722
32723diff -urNp linux-2.6.32.41/drivers/pci/hotplug/acpiphp_glue.c linux-2.6.32.41/drivers/pci/hotplug/acpiphp_glue.c
32724--- linux-2.6.32.41/drivers/pci/hotplug/acpiphp_glue.c 2011-03-27 14:31:47.000000000 -0400
32725+++ linux-2.6.32.41/drivers/pci/hotplug/acpiphp_glue.c 2011-04-17 15:56:46.000000000 -0400
32726@@ -111,7 +111,7 @@ static int post_dock_fixups(struct notif
32727 }
32728
32729
32730-static struct acpi_dock_ops acpiphp_dock_ops = {
32731+static const struct acpi_dock_ops acpiphp_dock_ops = {
32732 .handler = handle_hotplug_event_func,
32733 };
32734
32735diff -urNp linux-2.6.32.41/drivers/pci/hotplug/cpqphp_nvram.c linux-2.6.32.41/drivers/pci/hotplug/cpqphp_nvram.c
32736--- linux-2.6.32.41/drivers/pci/hotplug/cpqphp_nvram.c 2011-03-27 14:31:47.000000000 -0400
32737+++ linux-2.6.32.41/drivers/pci/hotplug/cpqphp_nvram.c 2011-04-17 15:56:46.000000000 -0400
32738@@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_
32739
32740 void compaq_nvram_init (void __iomem *rom_start)
32741 {
32742+
32743+#ifndef CONFIG_PAX_KERNEXEC
32744 if (rom_start) {
32745 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
32746 }
32747+#endif
32748+
32749 dbg("int15 entry = %p\n", compaq_int15_entry_point);
32750
32751 /* initialize our int15 lock */
32752diff -urNp linux-2.6.32.41/drivers/pci/hotplug/fakephp.c linux-2.6.32.41/drivers/pci/hotplug/fakephp.c
32753--- linux-2.6.32.41/drivers/pci/hotplug/fakephp.c 2011-03-27 14:31:47.000000000 -0400
32754+++ linux-2.6.32.41/drivers/pci/hotplug/fakephp.c 2011-04-17 15:56:46.000000000 -0400
32755@@ -73,7 +73,7 @@ static void legacy_release(struct kobjec
32756 }
32757
32758 static struct kobj_type legacy_ktype = {
32759- .sysfs_ops = &(struct sysfs_ops){
32760+ .sysfs_ops = &(const struct sysfs_ops){
32761 .store = legacy_store, .show = legacy_show
32762 },
32763 .release = &legacy_release,
32764diff -urNp linux-2.6.32.41/drivers/pci/intel-iommu.c linux-2.6.32.41/drivers/pci/intel-iommu.c
32765--- linux-2.6.32.41/drivers/pci/intel-iommu.c 2011-05-10 22:12:01.000000000 -0400
32766+++ linux-2.6.32.41/drivers/pci/intel-iommu.c 2011-05-10 22:12:33.000000000 -0400
32767@@ -2643,7 +2643,7 @@ error:
32768 return 0;
32769 }
32770
32771-static dma_addr_t intel_map_page(struct device *dev, struct page *page,
32772+dma_addr_t intel_map_page(struct device *dev, struct page *page,
32773 unsigned long offset, size_t size,
32774 enum dma_data_direction dir,
32775 struct dma_attrs *attrs)
32776@@ -2719,7 +2719,7 @@ static void add_unmap(struct dmar_domain
32777 spin_unlock_irqrestore(&async_umap_flush_lock, flags);
32778 }
32779
32780-static void intel_unmap_page(struct device *dev, dma_addr_t dev_addr,
32781+void intel_unmap_page(struct device *dev, dma_addr_t dev_addr,
32782 size_t size, enum dma_data_direction dir,
32783 struct dma_attrs *attrs)
32784 {
32785@@ -2768,7 +2768,7 @@ static void intel_unmap_page(struct devi
32786 }
32787 }
32788
32789-static void *intel_alloc_coherent(struct device *hwdev, size_t size,
32790+void *intel_alloc_coherent(struct device *hwdev, size_t size,
32791 dma_addr_t *dma_handle, gfp_t flags)
32792 {
32793 void *vaddr;
32794@@ -2800,7 +2800,7 @@ static void *intel_alloc_coherent(struct
32795 return NULL;
32796 }
32797
32798-static void intel_free_coherent(struct device *hwdev, size_t size, void *vaddr,
32799+void intel_free_coherent(struct device *hwdev, size_t size, void *vaddr,
32800 dma_addr_t dma_handle)
32801 {
32802 int order;
32803@@ -2812,7 +2812,7 @@ static void intel_free_coherent(struct d
32804 free_pages((unsigned long)vaddr, order);
32805 }
32806
32807-static void intel_unmap_sg(struct device *hwdev, struct scatterlist *sglist,
32808+void intel_unmap_sg(struct device *hwdev, struct scatterlist *sglist,
32809 int nelems, enum dma_data_direction dir,
32810 struct dma_attrs *attrs)
32811 {
32812@@ -2872,7 +2872,7 @@ static int intel_nontranslate_map_sg(str
32813 return nelems;
32814 }
32815
32816-static int intel_map_sg(struct device *hwdev, struct scatterlist *sglist, int nelems,
32817+int intel_map_sg(struct device *hwdev, struct scatterlist *sglist, int nelems,
32818 enum dma_data_direction dir, struct dma_attrs *attrs)
32819 {
32820 int i;
32821@@ -2941,12 +2941,12 @@ static int intel_map_sg(struct device *h
32822 return nelems;
32823 }
32824
32825-static int intel_mapping_error(struct device *dev, dma_addr_t dma_addr)
32826+int intel_mapping_error(struct device *dev, dma_addr_t dma_addr)
32827 {
32828 return !dma_addr;
32829 }
32830
32831-struct dma_map_ops intel_dma_ops = {
32832+const struct dma_map_ops intel_dma_ops = {
32833 .alloc_coherent = intel_alloc_coherent,
32834 .free_coherent = intel_free_coherent,
32835 .map_sg = intel_map_sg,
32836diff -urNp linux-2.6.32.41/drivers/pci/pcie/aspm.c linux-2.6.32.41/drivers/pci/pcie/aspm.c
32837--- linux-2.6.32.41/drivers/pci/pcie/aspm.c 2011-03-27 14:31:47.000000000 -0400
32838+++ linux-2.6.32.41/drivers/pci/pcie/aspm.c 2011-04-17 15:56:46.000000000 -0400
32839@@ -27,9 +27,9 @@
32840 #define MODULE_PARAM_PREFIX "pcie_aspm."
32841
32842 /* Note: those are not register definitions */
32843-#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
32844-#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
32845-#define ASPM_STATE_L1 (4) /* L1 state */
32846+#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
32847+#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
32848+#define ASPM_STATE_L1 (4U) /* L1 state */
32849 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
32850 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
32851
32852diff -urNp linux-2.6.32.41/drivers/pci/probe.c linux-2.6.32.41/drivers/pci/probe.c
32853--- linux-2.6.32.41/drivers/pci/probe.c 2011-03-27 14:31:47.000000000 -0400
32854+++ linux-2.6.32.41/drivers/pci/probe.c 2011-04-17 15:56:46.000000000 -0400
32855@@ -62,14 +62,14 @@ static ssize_t pci_bus_show_cpuaffinity(
32856 return ret;
32857 }
32858
32859-static ssize_t inline pci_bus_show_cpumaskaffinity(struct device *dev,
32860+static inline ssize_t pci_bus_show_cpumaskaffinity(struct device *dev,
32861 struct device_attribute *attr,
32862 char *buf)
32863 {
32864 return pci_bus_show_cpuaffinity(dev, 0, attr, buf);
32865 }
32866
32867-static ssize_t inline pci_bus_show_cpulistaffinity(struct device *dev,
32868+static inline ssize_t pci_bus_show_cpulistaffinity(struct device *dev,
32869 struct device_attribute *attr,
32870 char *buf)
32871 {
32872diff -urNp linux-2.6.32.41/drivers/pci/proc.c linux-2.6.32.41/drivers/pci/proc.c
32873--- linux-2.6.32.41/drivers/pci/proc.c 2011-03-27 14:31:47.000000000 -0400
32874+++ linux-2.6.32.41/drivers/pci/proc.c 2011-04-17 15:56:46.000000000 -0400
32875@@ -480,7 +480,16 @@ static const struct file_operations proc
32876 static int __init pci_proc_init(void)
32877 {
32878 struct pci_dev *dev = NULL;
32879+
32880+#ifdef CONFIG_GRKERNSEC_PROC_ADD
32881+#ifdef CONFIG_GRKERNSEC_PROC_USER
32882+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
32883+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
32884+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
32885+#endif
32886+#else
32887 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
32888+#endif
32889 proc_create("devices", 0, proc_bus_pci_dir,
32890 &proc_bus_pci_dev_operations);
32891 proc_initialized = 1;
32892diff -urNp linux-2.6.32.41/drivers/pci/slot.c linux-2.6.32.41/drivers/pci/slot.c
32893--- linux-2.6.32.41/drivers/pci/slot.c 2011-03-27 14:31:47.000000000 -0400
32894+++ linux-2.6.32.41/drivers/pci/slot.c 2011-04-17 15:56:46.000000000 -0400
32895@@ -29,7 +29,7 @@ static ssize_t pci_slot_attr_store(struc
32896 return attribute->store ? attribute->store(slot, buf, len) : -EIO;
32897 }
32898
32899-static struct sysfs_ops pci_slot_sysfs_ops = {
32900+static const struct sysfs_ops pci_slot_sysfs_ops = {
32901 .show = pci_slot_attr_show,
32902 .store = pci_slot_attr_store,
32903 };
32904diff -urNp linux-2.6.32.41/drivers/pcmcia/pcmcia_ioctl.c linux-2.6.32.41/drivers/pcmcia/pcmcia_ioctl.c
32905--- linux-2.6.32.41/drivers/pcmcia/pcmcia_ioctl.c 2011-03-27 14:31:47.000000000 -0400
32906+++ linux-2.6.32.41/drivers/pcmcia/pcmcia_ioctl.c 2011-04-17 15:56:46.000000000 -0400
32907@@ -819,7 +819,7 @@ static int ds_ioctl(struct inode * inode
32908 return -EFAULT;
32909 }
32910 }
32911- buf = kmalloc(sizeof(ds_ioctl_arg_t), GFP_KERNEL);
32912+ buf = kzalloc(sizeof(ds_ioctl_arg_t), GFP_KERNEL);
32913 if (!buf)
32914 return -ENOMEM;
32915
32916diff -urNp linux-2.6.32.41/drivers/platform/x86/acer-wmi.c linux-2.6.32.41/drivers/platform/x86/acer-wmi.c
32917--- linux-2.6.32.41/drivers/platform/x86/acer-wmi.c 2011-03-27 14:31:47.000000000 -0400
32918+++ linux-2.6.32.41/drivers/platform/x86/acer-wmi.c 2011-04-17 15:56:46.000000000 -0400
32919@@ -918,7 +918,7 @@ static int update_bl_status(struct backl
32920 return 0;
32921 }
32922
32923-static struct backlight_ops acer_bl_ops = {
32924+static const struct backlight_ops acer_bl_ops = {
32925 .get_brightness = read_brightness,
32926 .update_status = update_bl_status,
32927 };
32928diff -urNp linux-2.6.32.41/drivers/platform/x86/asus_acpi.c linux-2.6.32.41/drivers/platform/x86/asus_acpi.c
32929--- linux-2.6.32.41/drivers/platform/x86/asus_acpi.c 2011-03-27 14:31:47.000000000 -0400
32930+++ linux-2.6.32.41/drivers/platform/x86/asus_acpi.c 2011-04-17 15:56:46.000000000 -0400
32931@@ -1396,7 +1396,7 @@ static int asus_hotk_remove(struct acpi_
32932 return 0;
32933 }
32934
32935-static struct backlight_ops asus_backlight_data = {
32936+static const struct backlight_ops asus_backlight_data = {
32937 .get_brightness = read_brightness,
32938 .update_status = set_brightness_status,
32939 };
32940diff -urNp linux-2.6.32.41/drivers/platform/x86/asus-laptop.c linux-2.6.32.41/drivers/platform/x86/asus-laptop.c
32941--- linux-2.6.32.41/drivers/platform/x86/asus-laptop.c 2011-03-27 14:31:47.000000000 -0400
32942+++ linux-2.6.32.41/drivers/platform/x86/asus-laptop.c 2011-04-17 15:56:46.000000000 -0400
32943@@ -250,7 +250,7 @@ static struct backlight_device *asus_bac
32944 */
32945 static int read_brightness(struct backlight_device *bd);
32946 static int update_bl_status(struct backlight_device *bd);
32947-static struct backlight_ops asusbl_ops = {
32948+static const struct backlight_ops asusbl_ops = {
32949 .get_brightness = read_brightness,
32950 .update_status = update_bl_status,
32951 };
32952diff -urNp linux-2.6.32.41/drivers/platform/x86/compal-laptop.c linux-2.6.32.41/drivers/platform/x86/compal-laptop.c
32953--- linux-2.6.32.41/drivers/platform/x86/compal-laptop.c 2011-03-27 14:31:47.000000000 -0400
32954+++ linux-2.6.32.41/drivers/platform/x86/compal-laptop.c 2011-04-17 15:56:46.000000000 -0400
32955@@ -163,7 +163,7 @@ static int bl_update_status(struct backl
32956 return set_lcd_level(b->props.brightness);
32957 }
32958
32959-static struct backlight_ops compalbl_ops = {
32960+static const struct backlight_ops compalbl_ops = {
32961 .get_brightness = bl_get_brightness,
32962 .update_status = bl_update_status,
32963 };
32964diff -urNp linux-2.6.32.41/drivers/platform/x86/dell-laptop.c linux-2.6.32.41/drivers/platform/x86/dell-laptop.c
32965--- linux-2.6.32.41/drivers/platform/x86/dell-laptop.c 2011-05-10 22:12:01.000000000 -0400
32966+++ linux-2.6.32.41/drivers/platform/x86/dell-laptop.c 2011-05-10 22:12:33.000000000 -0400
32967@@ -318,7 +318,7 @@ static int dell_get_intensity(struct bac
32968 return buffer.output[1];
32969 }
32970
32971-static struct backlight_ops dell_ops = {
32972+static const struct backlight_ops dell_ops = {
32973 .get_brightness = dell_get_intensity,
32974 .update_status = dell_send_intensity,
32975 };
32976diff -urNp linux-2.6.32.41/drivers/platform/x86/eeepc-laptop.c linux-2.6.32.41/drivers/platform/x86/eeepc-laptop.c
32977--- linux-2.6.32.41/drivers/platform/x86/eeepc-laptop.c 2011-03-27 14:31:47.000000000 -0400
32978+++ linux-2.6.32.41/drivers/platform/x86/eeepc-laptop.c 2011-04-17 15:56:46.000000000 -0400
32979@@ -245,7 +245,7 @@ static struct device *eeepc_hwmon_device
32980 */
32981 static int read_brightness(struct backlight_device *bd);
32982 static int update_bl_status(struct backlight_device *bd);
32983-static struct backlight_ops eeepcbl_ops = {
32984+static const struct backlight_ops eeepcbl_ops = {
32985 .get_brightness = read_brightness,
32986 .update_status = update_bl_status,
32987 };
32988diff -urNp linux-2.6.32.41/drivers/platform/x86/fujitsu-laptop.c linux-2.6.32.41/drivers/platform/x86/fujitsu-laptop.c
32989--- linux-2.6.32.41/drivers/platform/x86/fujitsu-laptop.c 2011-03-27 14:31:47.000000000 -0400
32990+++ linux-2.6.32.41/drivers/platform/x86/fujitsu-laptop.c 2011-04-17 15:56:46.000000000 -0400
32991@@ -436,7 +436,7 @@ static int bl_update_status(struct backl
32992 return ret;
32993 }
32994
32995-static struct backlight_ops fujitsubl_ops = {
32996+static const struct backlight_ops fujitsubl_ops = {
32997 .get_brightness = bl_get_brightness,
32998 .update_status = bl_update_status,
32999 };
33000diff -urNp linux-2.6.32.41/drivers/platform/x86/msi-laptop.c linux-2.6.32.41/drivers/platform/x86/msi-laptop.c
33001--- linux-2.6.32.41/drivers/platform/x86/msi-laptop.c 2011-03-27 14:31:47.000000000 -0400
33002+++ linux-2.6.32.41/drivers/platform/x86/msi-laptop.c 2011-04-17 15:56:46.000000000 -0400
33003@@ -161,7 +161,7 @@ static int bl_update_status(struct backl
33004 return set_lcd_level(b->props.brightness);
33005 }
33006
33007-static struct backlight_ops msibl_ops = {
33008+static const struct backlight_ops msibl_ops = {
33009 .get_brightness = bl_get_brightness,
33010 .update_status = bl_update_status,
33011 };
33012diff -urNp linux-2.6.32.41/drivers/platform/x86/panasonic-laptop.c linux-2.6.32.41/drivers/platform/x86/panasonic-laptop.c
33013--- linux-2.6.32.41/drivers/platform/x86/panasonic-laptop.c 2011-03-27 14:31:47.000000000 -0400
33014+++ linux-2.6.32.41/drivers/platform/x86/panasonic-laptop.c 2011-04-17 15:56:46.000000000 -0400
33015@@ -352,7 +352,7 @@ static int bl_set_status(struct backligh
33016 return acpi_pcc_write_sset(pcc, SINF_DC_CUR_BRIGHT, bright);
33017 }
33018
33019-static struct backlight_ops pcc_backlight_ops = {
33020+static const struct backlight_ops pcc_backlight_ops = {
33021 .get_brightness = bl_get,
33022 .update_status = bl_set_status,
33023 };
33024diff -urNp linux-2.6.32.41/drivers/platform/x86/sony-laptop.c linux-2.6.32.41/drivers/platform/x86/sony-laptop.c
33025--- linux-2.6.32.41/drivers/platform/x86/sony-laptop.c 2011-03-27 14:31:47.000000000 -0400
33026+++ linux-2.6.32.41/drivers/platform/x86/sony-laptop.c 2011-04-17 15:56:46.000000000 -0400
33027@@ -850,7 +850,7 @@ static int sony_backlight_get_brightness
33028 }
33029
33030 static struct backlight_device *sony_backlight_device;
33031-static struct backlight_ops sony_backlight_ops = {
33032+static const struct backlight_ops sony_backlight_ops = {
33033 .update_status = sony_backlight_update_status,
33034 .get_brightness = sony_backlight_get_brightness,
33035 };
33036diff -urNp linux-2.6.32.41/drivers/platform/x86/thinkpad_acpi.c linux-2.6.32.41/drivers/platform/x86/thinkpad_acpi.c
33037--- linux-2.6.32.41/drivers/platform/x86/thinkpad_acpi.c 2011-03-27 14:31:47.000000000 -0400
33038+++ linux-2.6.32.41/drivers/platform/x86/thinkpad_acpi.c 2011-04-17 15:56:46.000000000 -0400
33039@@ -6122,7 +6122,7 @@ static void tpacpi_brightness_notify_cha
33040 BACKLIGHT_UPDATE_HOTKEY);
33041 }
33042
33043-static struct backlight_ops ibm_backlight_data = {
33044+static const struct backlight_ops ibm_backlight_data = {
33045 .get_brightness = brightness_get,
33046 .update_status = brightness_update_status,
33047 };
33048diff -urNp linux-2.6.32.41/drivers/platform/x86/toshiba_acpi.c linux-2.6.32.41/drivers/platform/x86/toshiba_acpi.c
33049--- linux-2.6.32.41/drivers/platform/x86/toshiba_acpi.c 2011-03-27 14:31:47.000000000 -0400
33050+++ linux-2.6.32.41/drivers/platform/x86/toshiba_acpi.c 2011-04-17 15:56:46.000000000 -0400
33051@@ -671,7 +671,7 @@ static acpi_status remove_device(void)
33052 return AE_OK;
33053 }
33054
33055-static struct backlight_ops toshiba_backlight_data = {
33056+static const struct backlight_ops toshiba_backlight_data = {
33057 .get_brightness = get_lcd,
33058 .update_status = set_lcd_status,
33059 };
33060diff -urNp linux-2.6.32.41/drivers/pnp/pnpbios/bioscalls.c linux-2.6.32.41/drivers/pnp/pnpbios/bioscalls.c
33061--- linux-2.6.32.41/drivers/pnp/pnpbios/bioscalls.c 2011-03-27 14:31:47.000000000 -0400
33062+++ linux-2.6.32.41/drivers/pnp/pnpbios/bioscalls.c 2011-04-17 15:56:46.000000000 -0400
33063@@ -60,7 +60,7 @@ do { \
33064 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
33065 } while(0)
33066
33067-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
33068+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
33069 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
33070
33071 /*
33072@@ -97,7 +97,10 @@ static inline u16 call_pnp_bios(u16 func
33073
33074 cpu = get_cpu();
33075 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
33076+
33077+ pax_open_kernel();
33078 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
33079+ pax_close_kernel();
33080
33081 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
33082 spin_lock_irqsave(&pnp_bios_lock, flags);
33083@@ -135,7 +138,10 @@ static inline u16 call_pnp_bios(u16 func
33084 :"memory");
33085 spin_unlock_irqrestore(&pnp_bios_lock, flags);
33086
33087+ pax_open_kernel();
33088 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
33089+ pax_close_kernel();
33090+
33091 put_cpu();
33092
33093 /* If we get here and this is set then the PnP BIOS faulted on us. */
33094@@ -469,7 +475,7 @@ int pnp_bios_read_escd(char *data, u32 n
33095 return status;
33096 }
33097
33098-void pnpbios_calls_init(union pnp_bios_install_struct *header)
33099+void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
33100 {
33101 int i;
33102
33103@@ -477,6 +483,8 @@ void pnpbios_calls_init(union pnp_bios_i
33104 pnp_bios_callpoint.offset = header->fields.pm16offset;
33105 pnp_bios_callpoint.segment = PNP_CS16;
33106
33107+ pax_open_kernel();
33108+
33109 for_each_possible_cpu(i) {
33110 struct desc_struct *gdt = get_cpu_gdt_table(i);
33111 if (!gdt)
33112@@ -488,4 +496,6 @@ void pnpbios_calls_init(union pnp_bios_i
33113 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
33114 (unsigned long)__va(header->fields.pm16dseg));
33115 }
33116+
33117+ pax_close_kernel();
33118 }
33119diff -urNp linux-2.6.32.41/drivers/pnp/resource.c linux-2.6.32.41/drivers/pnp/resource.c
33120--- linux-2.6.32.41/drivers/pnp/resource.c 2011-03-27 14:31:47.000000000 -0400
33121+++ linux-2.6.32.41/drivers/pnp/resource.c 2011-04-17 15:56:46.000000000 -0400
33122@@ -355,7 +355,7 @@ int pnp_check_irq(struct pnp_dev *dev, s
33123 return 1;
33124
33125 /* check if the resource is valid */
33126- if (*irq < 0 || *irq > 15)
33127+ if (*irq > 15)
33128 return 0;
33129
33130 /* check if the resource is reserved */
33131@@ -419,7 +419,7 @@ int pnp_check_dma(struct pnp_dev *dev, s
33132 return 1;
33133
33134 /* check if the resource is valid */
33135- if (*dma < 0 || *dma == 4 || *dma > 7)
33136+ if (*dma == 4 || *dma > 7)
33137 return 0;
33138
33139 /* check if the resource is reserved */
33140diff -urNp linux-2.6.32.41/drivers/rtc/rtc-dev.c linux-2.6.32.41/drivers/rtc/rtc-dev.c
33141--- linux-2.6.32.41/drivers/rtc/rtc-dev.c 2011-03-27 14:31:47.000000000 -0400
33142+++ linux-2.6.32.41/drivers/rtc/rtc-dev.c 2011-04-17 15:56:46.000000000 -0400
33143@@ -14,6 +14,7 @@
33144 #include <linux/module.h>
33145 #include <linux/rtc.h>
33146 #include <linux/sched.h>
33147+#include <linux/grsecurity.h>
33148 #include "rtc-core.h"
33149
33150 static dev_t rtc_devt;
33151@@ -357,6 +358,8 @@ static long rtc_dev_ioctl(struct file *f
33152 if (copy_from_user(&tm, uarg, sizeof(tm)))
33153 return -EFAULT;
33154
33155+ gr_log_timechange();
33156+
33157 return rtc_set_time(rtc, &tm);
33158
33159 case RTC_PIE_ON:
33160diff -urNp linux-2.6.32.41/drivers/s390/cio/qdio_perf.c linux-2.6.32.41/drivers/s390/cio/qdio_perf.c
33161--- linux-2.6.32.41/drivers/s390/cio/qdio_perf.c 2011-03-27 14:31:47.000000000 -0400
33162+++ linux-2.6.32.41/drivers/s390/cio/qdio_perf.c 2011-04-17 15:56:46.000000000 -0400
33163@@ -31,51 +31,51 @@ static struct proc_dir_entry *qdio_perf_
33164 static int qdio_perf_proc_show(struct seq_file *m, void *v)
33165 {
33166 seq_printf(m, "Number of qdio interrupts\t\t\t: %li\n",
33167- (long)atomic_long_read(&perf_stats.qdio_int));
33168+ (long)atomic_long_read_unchecked(&perf_stats.qdio_int));
33169 seq_printf(m, "Number of PCI interrupts\t\t\t: %li\n",
33170- (long)atomic_long_read(&perf_stats.pci_int));
33171+ (long)atomic_long_read_unchecked(&perf_stats.pci_int));
33172 seq_printf(m, "Number of adapter interrupts\t\t\t: %li\n",
33173- (long)atomic_long_read(&perf_stats.thin_int));
33174+ (long)atomic_long_read_unchecked(&perf_stats.thin_int));
33175 seq_printf(m, "\n");
33176 seq_printf(m, "Inbound tasklet runs\t\t\t\t: %li\n",
33177- (long)atomic_long_read(&perf_stats.tasklet_inbound));
33178+ (long)atomic_long_read_unchecked(&perf_stats.tasklet_inbound));
33179 seq_printf(m, "Outbound tasklet runs\t\t\t\t: %li\n",
33180- (long)atomic_long_read(&perf_stats.tasklet_outbound));
33181+ (long)atomic_long_read_unchecked(&perf_stats.tasklet_outbound));
33182 seq_printf(m, "Adapter interrupt tasklet runs/loops\t\t: %li/%li\n",
33183- (long)atomic_long_read(&perf_stats.tasklet_thinint),
33184- (long)atomic_long_read(&perf_stats.tasklet_thinint_loop));
33185+ (long)atomic_long_read_unchecked(&perf_stats.tasklet_thinint),
33186+ (long)atomic_long_read_unchecked(&perf_stats.tasklet_thinint_loop));
33187 seq_printf(m, "Adapter interrupt inbound tasklet runs/loops\t: %li/%li\n",
33188- (long)atomic_long_read(&perf_stats.thinint_inbound),
33189- (long)atomic_long_read(&perf_stats.thinint_inbound_loop));
33190+ (long)atomic_long_read_unchecked(&perf_stats.thinint_inbound),
33191+ (long)atomic_long_read_unchecked(&perf_stats.thinint_inbound_loop));
33192 seq_printf(m, "\n");
33193 seq_printf(m, "Number of SIGA In issued\t\t\t: %li\n",
33194- (long)atomic_long_read(&perf_stats.siga_in));
33195+ (long)atomic_long_read_unchecked(&perf_stats.siga_in));
33196 seq_printf(m, "Number of SIGA Out issued\t\t\t: %li\n",
33197- (long)atomic_long_read(&perf_stats.siga_out));
33198+ (long)atomic_long_read_unchecked(&perf_stats.siga_out));
33199 seq_printf(m, "Number of SIGA Sync issued\t\t\t: %li\n",
33200- (long)atomic_long_read(&perf_stats.siga_sync));
33201+ (long)atomic_long_read_unchecked(&perf_stats.siga_sync));
33202 seq_printf(m, "\n");
33203 seq_printf(m, "Number of inbound transfers\t\t\t: %li\n",
33204- (long)atomic_long_read(&perf_stats.inbound_handler));
33205+ (long)atomic_long_read_unchecked(&perf_stats.inbound_handler));
33206 seq_printf(m, "Number of outbound transfers\t\t\t: %li\n",
33207- (long)atomic_long_read(&perf_stats.outbound_handler));
33208+ (long)atomic_long_read_unchecked(&perf_stats.outbound_handler));
33209 seq_printf(m, "\n");
33210 seq_printf(m, "Number of fast requeues (outg. SBAL w/o SIGA)\t: %li\n",
33211- (long)atomic_long_read(&perf_stats.fast_requeue));
33212+ (long)atomic_long_read_unchecked(&perf_stats.fast_requeue));
33213 seq_printf(m, "Number of outbound target full condition\t: %li\n",
33214- (long)atomic_long_read(&perf_stats.outbound_target_full));
33215+ (long)atomic_long_read_unchecked(&perf_stats.outbound_target_full));
33216 seq_printf(m, "Number of outbound tasklet mod_timer calls\t: %li\n",
33217- (long)atomic_long_read(&perf_stats.debug_tl_out_timer));
33218+ (long)atomic_long_read_unchecked(&perf_stats.debug_tl_out_timer));
33219 seq_printf(m, "Number of stop polling calls\t\t\t: %li\n",
33220- (long)atomic_long_read(&perf_stats.debug_stop_polling));
33221+ (long)atomic_long_read_unchecked(&perf_stats.debug_stop_polling));
33222 seq_printf(m, "AI inbound tasklet loops after stop polling\t: %li\n",
33223- (long)atomic_long_read(&perf_stats.thinint_inbound_loop2));
33224+ (long)atomic_long_read_unchecked(&perf_stats.thinint_inbound_loop2));
33225 seq_printf(m, "QEBSM EQBS total/incomplete\t\t\t: %li/%li\n",
33226- (long)atomic_long_read(&perf_stats.debug_eqbs_all),
33227- (long)atomic_long_read(&perf_stats.debug_eqbs_incomplete));
33228+ (long)atomic_long_read_unchecked(&perf_stats.debug_eqbs_all),
33229+ (long)atomic_long_read_unchecked(&perf_stats.debug_eqbs_incomplete));
33230 seq_printf(m, "QEBSM SQBS total/incomplete\t\t\t: %li/%li\n",
33231- (long)atomic_long_read(&perf_stats.debug_sqbs_all),
33232- (long)atomic_long_read(&perf_stats.debug_sqbs_incomplete));
33233+ (long)atomic_long_read_unchecked(&perf_stats.debug_sqbs_all),
33234+ (long)atomic_long_read_unchecked(&perf_stats.debug_sqbs_incomplete));
33235 seq_printf(m, "\n");
33236 return 0;
33237 }
33238diff -urNp linux-2.6.32.41/drivers/s390/cio/qdio_perf.h linux-2.6.32.41/drivers/s390/cio/qdio_perf.h
33239--- linux-2.6.32.41/drivers/s390/cio/qdio_perf.h 2011-03-27 14:31:47.000000000 -0400
33240+++ linux-2.6.32.41/drivers/s390/cio/qdio_perf.h 2011-04-17 15:56:46.000000000 -0400
33241@@ -13,46 +13,46 @@
33242
33243 struct qdio_perf_stats {
33244 /* interrupt handler calls */
33245- atomic_long_t qdio_int;
33246- atomic_long_t pci_int;
33247- atomic_long_t thin_int;
33248+ atomic_long_unchecked_t qdio_int;
33249+ atomic_long_unchecked_t pci_int;
33250+ atomic_long_unchecked_t thin_int;
33251
33252 /* tasklet runs */
33253- atomic_long_t tasklet_inbound;
33254- atomic_long_t tasklet_outbound;
33255- atomic_long_t tasklet_thinint;
33256- atomic_long_t tasklet_thinint_loop;
33257- atomic_long_t thinint_inbound;
33258- atomic_long_t thinint_inbound_loop;
33259- atomic_long_t thinint_inbound_loop2;
33260+ atomic_long_unchecked_t tasklet_inbound;
33261+ atomic_long_unchecked_t tasklet_outbound;
33262+ atomic_long_unchecked_t tasklet_thinint;
33263+ atomic_long_unchecked_t tasklet_thinint_loop;
33264+ atomic_long_unchecked_t thinint_inbound;
33265+ atomic_long_unchecked_t thinint_inbound_loop;
33266+ atomic_long_unchecked_t thinint_inbound_loop2;
33267
33268 /* signal adapter calls */
33269- atomic_long_t siga_out;
33270- atomic_long_t siga_in;
33271- atomic_long_t siga_sync;
33272+ atomic_long_unchecked_t siga_out;
33273+ atomic_long_unchecked_t siga_in;
33274+ atomic_long_unchecked_t siga_sync;
33275
33276 /* misc */
33277- atomic_long_t inbound_handler;
33278- atomic_long_t outbound_handler;
33279- atomic_long_t fast_requeue;
33280- atomic_long_t outbound_target_full;
33281+ atomic_long_unchecked_t inbound_handler;
33282+ atomic_long_unchecked_t outbound_handler;
33283+ atomic_long_unchecked_t fast_requeue;
33284+ atomic_long_unchecked_t outbound_target_full;
33285
33286 /* for debugging */
33287- atomic_long_t debug_tl_out_timer;
33288- atomic_long_t debug_stop_polling;
33289- atomic_long_t debug_eqbs_all;
33290- atomic_long_t debug_eqbs_incomplete;
33291- atomic_long_t debug_sqbs_all;
33292- atomic_long_t debug_sqbs_incomplete;
33293+ atomic_long_unchecked_t debug_tl_out_timer;
33294+ atomic_long_unchecked_t debug_stop_polling;
33295+ atomic_long_unchecked_t debug_eqbs_all;
33296+ atomic_long_unchecked_t debug_eqbs_incomplete;
33297+ atomic_long_unchecked_t debug_sqbs_all;
33298+ atomic_long_unchecked_t debug_sqbs_incomplete;
33299 };
33300
33301 extern struct qdio_perf_stats perf_stats;
33302 extern int qdio_performance_stats;
33303
33304-static inline void qdio_perf_stat_inc(atomic_long_t *count)
33305+static inline void qdio_perf_stat_inc(atomic_long_unchecked_t *count)
33306 {
33307 if (qdio_performance_stats)
33308- atomic_long_inc(count);
33309+ atomic_long_inc_unchecked(count);
33310 }
33311
33312 int qdio_setup_perf_stats(void);
33313diff -urNp linux-2.6.32.41/drivers/scsi/aacraid/commctrl.c linux-2.6.32.41/drivers/scsi/aacraid/commctrl.c
33314--- linux-2.6.32.41/drivers/scsi/aacraid/commctrl.c 2011-03-27 14:31:47.000000000 -0400
33315+++ linux-2.6.32.41/drivers/scsi/aacraid/commctrl.c 2011-05-16 21:46:57.000000000 -0400
33316@@ -481,6 +481,7 @@ static int aac_send_raw_srb(struct aac_d
33317 u32 actual_fibsize64, actual_fibsize = 0;
33318 int i;
33319
33320+ pax_track_stack();
33321
33322 if (dev->in_reset) {
33323 dprintk((KERN_DEBUG"aacraid: send raw srb -EBUSY\n"));
33324diff -urNp linux-2.6.32.41/drivers/scsi/aic94xx/aic94xx_init.c linux-2.6.32.41/drivers/scsi/aic94xx/aic94xx_init.c
33325--- linux-2.6.32.41/drivers/scsi/aic94xx/aic94xx_init.c 2011-03-27 14:31:47.000000000 -0400
33326+++ linux-2.6.32.41/drivers/scsi/aic94xx/aic94xx_init.c 2011-04-17 15:56:46.000000000 -0400
33327@@ -485,7 +485,7 @@ static ssize_t asd_show_update_bios(stru
33328 flash_error_table[i].reason);
33329 }
33330
33331-static DEVICE_ATTR(update_bios, S_IRUGO|S_IWUGO,
33332+static DEVICE_ATTR(update_bios, S_IRUGO|S_IWUSR,
33333 asd_show_update_bios, asd_store_update_bios);
33334
33335 static int asd_create_dev_attrs(struct asd_ha_struct *asd_ha)
33336diff -urNp linux-2.6.32.41/drivers/scsi/BusLogic.c linux-2.6.32.41/drivers/scsi/BusLogic.c
33337--- linux-2.6.32.41/drivers/scsi/BusLogic.c 2011-03-27 14:31:47.000000000 -0400
33338+++ linux-2.6.32.41/drivers/scsi/BusLogic.c 2011-05-16 21:46:57.000000000 -0400
33339@@ -961,6 +961,8 @@ static int __init BusLogic_InitializeFla
33340 static void __init BusLogic_InitializeProbeInfoList(struct BusLogic_HostAdapter
33341 *PrototypeHostAdapter)
33342 {
33343+ pax_track_stack();
33344+
33345 /*
33346 If a PCI BIOS is present, interrogate it for MultiMaster and FlashPoint
33347 Host Adapters; otherwise, default to the standard ISA MultiMaster probe.
33348diff -urNp linux-2.6.32.41/drivers/scsi/dpt_i2o.c linux-2.6.32.41/drivers/scsi/dpt_i2o.c
33349--- linux-2.6.32.41/drivers/scsi/dpt_i2o.c 2011-03-27 14:31:47.000000000 -0400
33350+++ linux-2.6.32.41/drivers/scsi/dpt_i2o.c 2011-05-16 21:46:57.000000000 -0400
33351@@ -1804,6 +1804,8 @@ static int adpt_i2o_passthru(adpt_hba* p
33352 dma_addr_t addr;
33353 ulong flags = 0;
33354
33355+ pax_track_stack();
33356+
33357 memset(&msg, 0, MAX_MESSAGE_SIZE*4);
33358 // get user msg size in u32s
33359 if(get_user(size, &user_msg[0])){
33360@@ -2297,6 +2299,8 @@ static s32 adpt_scsi_to_i2o(adpt_hba* pH
33361 s32 rcode;
33362 dma_addr_t addr;
33363
33364+ pax_track_stack();
33365+
33366 memset(msg, 0 , sizeof(msg));
33367 len = scsi_bufflen(cmd);
33368 direction = 0x00000000;
33369diff -urNp linux-2.6.32.41/drivers/scsi/eata.c linux-2.6.32.41/drivers/scsi/eata.c
33370--- linux-2.6.32.41/drivers/scsi/eata.c 2011-03-27 14:31:47.000000000 -0400
33371+++ linux-2.6.32.41/drivers/scsi/eata.c 2011-05-16 21:46:57.000000000 -0400
33372@@ -1087,6 +1087,8 @@ static int port_detect(unsigned long por
33373 struct hostdata *ha;
33374 char name[16];
33375
33376+ pax_track_stack();
33377+
33378 sprintf(name, "%s%d", driver_name, j);
33379
33380 if (!request_region(port_base, REGION_SIZE, driver_name)) {
33381diff -urNp linux-2.6.32.41/drivers/scsi/fcoe/libfcoe.c linux-2.6.32.41/drivers/scsi/fcoe/libfcoe.c
33382--- linux-2.6.32.41/drivers/scsi/fcoe/libfcoe.c 2011-03-27 14:31:47.000000000 -0400
33383+++ linux-2.6.32.41/drivers/scsi/fcoe/libfcoe.c 2011-05-16 21:46:57.000000000 -0400
33384@@ -809,6 +809,8 @@ static void fcoe_ctlr_recv_els(struct fc
33385 size_t rlen;
33386 size_t dlen;
33387
33388+ pax_track_stack();
33389+
33390 fiph = (struct fip_header *)skb->data;
33391 sub = fiph->fip_subcode;
33392 if (sub != FIP_SC_REQ && sub != FIP_SC_REP)
33393diff -urNp linux-2.6.32.41/drivers/scsi/gdth.c linux-2.6.32.41/drivers/scsi/gdth.c
33394--- linux-2.6.32.41/drivers/scsi/gdth.c 2011-03-27 14:31:47.000000000 -0400
33395+++ linux-2.6.32.41/drivers/scsi/gdth.c 2011-05-16 21:46:57.000000000 -0400
33396@@ -4102,6 +4102,8 @@ static int ioc_lockdrv(void __user *arg)
33397 ulong flags;
33398 gdth_ha_str *ha;
33399
33400+ pax_track_stack();
33401+
33402 if (copy_from_user(&ldrv, arg, sizeof(gdth_ioctl_lockdrv)))
33403 return -EFAULT;
33404 ha = gdth_find_ha(ldrv.ionode);
33405@@ -4134,6 +4136,8 @@ static int ioc_resetdrv(void __user *arg
33406 gdth_ha_str *ha;
33407 int rval;
33408
33409+ pax_track_stack();
33410+
33411 if (copy_from_user(&res, arg, sizeof(gdth_ioctl_reset)) ||
33412 res.number >= MAX_HDRIVES)
33413 return -EFAULT;
33414@@ -4169,6 +4173,8 @@ static int ioc_general(void __user *arg,
33415 gdth_ha_str *ha;
33416 int rval;
33417
33418+ pax_track_stack();
33419+
33420 if (copy_from_user(&gen, arg, sizeof(gdth_ioctl_general)))
33421 return -EFAULT;
33422 ha = gdth_find_ha(gen.ionode);
33423@@ -4625,6 +4631,9 @@ static void gdth_flush(gdth_ha_str *ha)
33424 int i;
33425 gdth_cmd_str gdtcmd;
33426 char cmnd[MAX_COMMAND_SIZE];
33427+
33428+ pax_track_stack();
33429+
33430 memset(cmnd, 0xff, MAX_COMMAND_SIZE);
33431
33432 TRACE2(("gdth_flush() hanum %d\n", ha->hanum));
33433diff -urNp linux-2.6.32.41/drivers/scsi/gdth_proc.c linux-2.6.32.41/drivers/scsi/gdth_proc.c
33434--- linux-2.6.32.41/drivers/scsi/gdth_proc.c 2011-03-27 14:31:47.000000000 -0400
33435+++ linux-2.6.32.41/drivers/scsi/gdth_proc.c 2011-05-16 21:46:57.000000000 -0400
33436@@ -46,6 +46,9 @@ static int gdth_set_asc_info(struct Scsi
33437 ulong64 paddr;
33438
33439 char cmnd[MAX_COMMAND_SIZE];
33440+
33441+ pax_track_stack();
33442+
33443 memset(cmnd, 0xff, 12);
33444 memset(&gdtcmd, 0, sizeof(gdth_cmd_str));
33445
33446@@ -174,6 +177,8 @@ static int gdth_get_info(char *buffer,ch
33447 gdth_hget_str *phg;
33448 char cmnd[MAX_COMMAND_SIZE];
33449
33450+ pax_track_stack();
33451+
33452 gdtcmd = kmalloc(sizeof(*gdtcmd), GFP_KERNEL);
33453 estr = kmalloc(sizeof(*estr), GFP_KERNEL);
33454 if (!gdtcmd || !estr)
33455diff -urNp linux-2.6.32.41/drivers/scsi/hosts.c linux-2.6.32.41/drivers/scsi/hosts.c
33456--- linux-2.6.32.41/drivers/scsi/hosts.c 2011-03-27 14:31:47.000000000 -0400
33457+++ linux-2.6.32.41/drivers/scsi/hosts.c 2011-05-04 17:56:28.000000000 -0400
33458@@ -40,7 +40,7 @@
33459 #include "scsi_logging.h"
33460
33461
33462-static atomic_t scsi_host_next_hn; /* host_no for next new host */
33463+static atomic_unchecked_t scsi_host_next_hn; /* host_no for next new host */
33464
33465
33466 static void scsi_host_cls_release(struct device *dev)
33467@@ -344,7 +344,7 @@ struct Scsi_Host *scsi_host_alloc(struct
33468 * subtract one because we increment first then return, but we need to
33469 * know what the next host number was before increment
33470 */
33471- shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
33472+ shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
33473 shost->dma_channel = 0xff;
33474
33475 /* These three are default values which can be overridden */
33476diff -urNp linux-2.6.32.41/drivers/scsi/ipr.c linux-2.6.32.41/drivers/scsi/ipr.c
33477--- linux-2.6.32.41/drivers/scsi/ipr.c 2011-03-27 14:31:47.000000000 -0400
33478+++ linux-2.6.32.41/drivers/scsi/ipr.c 2011-04-17 15:56:46.000000000 -0400
33479@@ -5286,7 +5286,7 @@ static bool ipr_qc_fill_rtf(struct ata_q
33480 return true;
33481 }
33482
33483-static struct ata_port_operations ipr_sata_ops = {
33484+static const struct ata_port_operations ipr_sata_ops = {
33485 .phy_reset = ipr_ata_phy_reset,
33486 .hardreset = ipr_sata_reset,
33487 .post_internal_cmd = ipr_ata_post_internal,
33488diff -urNp linux-2.6.32.41/drivers/scsi/libfc/fc_exch.c linux-2.6.32.41/drivers/scsi/libfc/fc_exch.c
33489--- linux-2.6.32.41/drivers/scsi/libfc/fc_exch.c 2011-03-27 14:31:47.000000000 -0400
33490+++ linux-2.6.32.41/drivers/scsi/libfc/fc_exch.c 2011-04-17 15:56:46.000000000 -0400
33491@@ -86,12 +86,12 @@ struct fc_exch_mgr {
33492 * all together if not used XXX
33493 */
33494 struct {
33495- atomic_t no_free_exch;
33496- atomic_t no_free_exch_xid;
33497- atomic_t xid_not_found;
33498- atomic_t xid_busy;
33499- atomic_t seq_not_found;
33500- atomic_t non_bls_resp;
33501+ atomic_unchecked_t no_free_exch;
33502+ atomic_unchecked_t no_free_exch_xid;
33503+ atomic_unchecked_t xid_not_found;
33504+ atomic_unchecked_t xid_busy;
33505+ atomic_unchecked_t seq_not_found;
33506+ atomic_unchecked_t non_bls_resp;
33507 } stats;
33508 };
33509 #define fc_seq_exch(sp) container_of(sp, struct fc_exch, seq)
33510@@ -510,7 +510,7 @@ static struct fc_exch *fc_exch_em_alloc(
33511 /* allocate memory for exchange */
33512 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
33513 if (!ep) {
33514- atomic_inc(&mp->stats.no_free_exch);
33515+ atomic_inc_unchecked(&mp->stats.no_free_exch);
33516 goto out;
33517 }
33518 memset(ep, 0, sizeof(*ep));
33519@@ -557,7 +557,7 @@ out:
33520 return ep;
33521 err:
33522 spin_unlock_bh(&pool->lock);
33523- atomic_inc(&mp->stats.no_free_exch_xid);
33524+ atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
33525 mempool_free(ep, mp->ep_pool);
33526 return NULL;
33527 }
33528@@ -690,7 +690,7 @@ static enum fc_pf_rjt_reason fc_seq_look
33529 xid = ntohs(fh->fh_ox_id); /* we originated exch */
33530 ep = fc_exch_find(mp, xid);
33531 if (!ep) {
33532- atomic_inc(&mp->stats.xid_not_found);
33533+ atomic_inc_unchecked(&mp->stats.xid_not_found);
33534 reject = FC_RJT_OX_ID;
33535 goto out;
33536 }
33537@@ -720,7 +720,7 @@ static enum fc_pf_rjt_reason fc_seq_look
33538 ep = fc_exch_find(mp, xid);
33539 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
33540 if (ep) {
33541- atomic_inc(&mp->stats.xid_busy);
33542+ atomic_inc_unchecked(&mp->stats.xid_busy);
33543 reject = FC_RJT_RX_ID;
33544 goto rel;
33545 }
33546@@ -731,7 +731,7 @@ static enum fc_pf_rjt_reason fc_seq_look
33547 }
33548 xid = ep->xid; /* get our XID */
33549 } else if (!ep) {
33550- atomic_inc(&mp->stats.xid_not_found);
33551+ atomic_inc_unchecked(&mp->stats.xid_not_found);
33552 reject = FC_RJT_RX_ID; /* XID not found */
33553 goto out;
33554 }
33555@@ -752,7 +752,7 @@ static enum fc_pf_rjt_reason fc_seq_look
33556 } else {
33557 sp = &ep->seq;
33558 if (sp->id != fh->fh_seq_id) {
33559- atomic_inc(&mp->stats.seq_not_found);
33560+ atomic_inc_unchecked(&mp->stats.seq_not_found);
33561 reject = FC_RJT_SEQ_ID; /* sequence/exch should exist */
33562 goto rel;
33563 }
33564@@ -1163,22 +1163,22 @@ static void fc_exch_recv_seq_resp(struct
33565
33566 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
33567 if (!ep) {
33568- atomic_inc(&mp->stats.xid_not_found);
33569+ atomic_inc_unchecked(&mp->stats.xid_not_found);
33570 goto out;
33571 }
33572 if (ep->esb_stat & ESB_ST_COMPLETE) {
33573- atomic_inc(&mp->stats.xid_not_found);
33574+ atomic_inc_unchecked(&mp->stats.xid_not_found);
33575 goto out;
33576 }
33577 if (ep->rxid == FC_XID_UNKNOWN)
33578 ep->rxid = ntohs(fh->fh_rx_id);
33579 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
33580- atomic_inc(&mp->stats.xid_not_found);
33581+ atomic_inc_unchecked(&mp->stats.xid_not_found);
33582 goto rel;
33583 }
33584 if (ep->did != ntoh24(fh->fh_s_id) &&
33585 ep->did != FC_FID_FLOGI) {
33586- atomic_inc(&mp->stats.xid_not_found);
33587+ atomic_inc_unchecked(&mp->stats.xid_not_found);
33588 goto rel;
33589 }
33590 sof = fr_sof(fp);
33591@@ -1189,7 +1189,7 @@ static void fc_exch_recv_seq_resp(struct
33592 } else {
33593 sp = &ep->seq;
33594 if (sp->id != fh->fh_seq_id) {
33595- atomic_inc(&mp->stats.seq_not_found);
33596+ atomic_inc_unchecked(&mp->stats.seq_not_found);
33597 goto rel;
33598 }
33599 }
33600@@ -1249,9 +1249,9 @@ static void fc_exch_recv_resp(struct fc_
33601 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
33602
33603 if (!sp)
33604- atomic_inc(&mp->stats.xid_not_found);
33605+ atomic_inc_unchecked(&mp->stats.xid_not_found);
33606 else
33607- atomic_inc(&mp->stats.non_bls_resp);
33608+ atomic_inc_unchecked(&mp->stats.non_bls_resp);
33609
33610 fc_frame_free(fp);
33611 }
33612diff -urNp linux-2.6.32.41/drivers/scsi/libsas/sas_ata.c linux-2.6.32.41/drivers/scsi/libsas/sas_ata.c
33613--- linux-2.6.32.41/drivers/scsi/libsas/sas_ata.c 2011-03-27 14:31:47.000000000 -0400
33614+++ linux-2.6.32.41/drivers/scsi/libsas/sas_ata.c 2011-04-23 12:56:11.000000000 -0400
33615@@ -343,7 +343,7 @@ static int sas_ata_scr_read(struct ata_l
33616 }
33617 }
33618
33619-static struct ata_port_operations sas_sata_ops = {
33620+static const struct ata_port_operations sas_sata_ops = {
33621 .phy_reset = sas_ata_phy_reset,
33622 .post_internal_cmd = sas_ata_post_internal,
33623 .qc_defer = ata_std_qc_defer,
33624diff -urNp linux-2.6.32.41/drivers/scsi/lpfc/lpfc_debugfs.c linux-2.6.32.41/drivers/scsi/lpfc/lpfc_debugfs.c
33625--- linux-2.6.32.41/drivers/scsi/lpfc/lpfc_debugfs.c 2011-03-27 14:31:47.000000000 -0400
33626+++ linux-2.6.32.41/drivers/scsi/lpfc/lpfc_debugfs.c 2011-05-16 21:46:57.000000000 -0400
33627@@ -124,7 +124,7 @@ struct lpfc_debug {
33628 int len;
33629 };
33630
33631-static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
33632+static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
33633 static unsigned long lpfc_debugfs_start_time = 0L;
33634
33635 /**
33636@@ -158,7 +158,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_v
33637 lpfc_debugfs_enable = 0;
33638
33639 len = 0;
33640- index = (atomic_read(&vport->disc_trc_cnt) + 1) &
33641+ index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
33642 (lpfc_debugfs_max_disc_trc - 1);
33643 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
33644 dtp = vport->disc_trc + i;
33645@@ -219,7 +219,7 @@ lpfc_debugfs_slow_ring_trc_data(struct l
33646 lpfc_debugfs_enable = 0;
33647
33648 len = 0;
33649- index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
33650+ index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
33651 (lpfc_debugfs_max_slow_ring_trc - 1);
33652 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
33653 dtp = phba->slow_ring_trc + i;
33654@@ -397,6 +397,8 @@ lpfc_debugfs_dumpHBASlim_data(struct lpf
33655 uint32_t *ptr;
33656 char buffer[1024];
33657
33658+ pax_track_stack();
33659+
33660 off = 0;
33661 spin_lock_irq(&phba->hbalock);
33662
33663@@ -634,14 +636,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport
33664 !vport || !vport->disc_trc)
33665 return;
33666
33667- index = atomic_inc_return(&vport->disc_trc_cnt) &
33668+ index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
33669 (lpfc_debugfs_max_disc_trc - 1);
33670 dtp = vport->disc_trc + index;
33671 dtp->fmt = fmt;
33672 dtp->data1 = data1;
33673 dtp->data2 = data2;
33674 dtp->data3 = data3;
33675- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
33676+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
33677 dtp->jif = jiffies;
33678 #endif
33679 return;
33680@@ -672,14 +674,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_h
33681 !phba || !phba->slow_ring_trc)
33682 return;
33683
33684- index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
33685+ index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
33686 (lpfc_debugfs_max_slow_ring_trc - 1);
33687 dtp = phba->slow_ring_trc + index;
33688 dtp->fmt = fmt;
33689 dtp->data1 = data1;
33690 dtp->data2 = data2;
33691 dtp->data3 = data3;
33692- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
33693+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
33694 dtp->jif = jiffies;
33695 #endif
33696 return;
33697@@ -1364,7 +1366,7 @@ lpfc_debugfs_initialize(struct lpfc_vpor
33698 "slow_ring buffer\n");
33699 goto debug_failed;
33700 }
33701- atomic_set(&phba->slow_ring_trc_cnt, 0);
33702+ atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
33703 memset(phba->slow_ring_trc, 0,
33704 (sizeof(struct lpfc_debugfs_trc) *
33705 lpfc_debugfs_max_slow_ring_trc));
33706@@ -1410,7 +1412,7 @@ lpfc_debugfs_initialize(struct lpfc_vpor
33707 "buffer\n");
33708 goto debug_failed;
33709 }
33710- atomic_set(&vport->disc_trc_cnt, 0);
33711+ atomic_set_unchecked(&vport->disc_trc_cnt, 0);
33712
33713 snprintf(name, sizeof(name), "discovery_trace");
33714 vport->debug_disc_trc =
33715diff -urNp linux-2.6.32.41/drivers/scsi/lpfc/lpfc.h linux-2.6.32.41/drivers/scsi/lpfc/lpfc.h
33716--- linux-2.6.32.41/drivers/scsi/lpfc/lpfc.h 2011-03-27 14:31:47.000000000 -0400
33717+++ linux-2.6.32.41/drivers/scsi/lpfc/lpfc.h 2011-05-04 17:56:28.000000000 -0400
33718@@ -400,7 +400,7 @@ struct lpfc_vport {
33719 struct dentry *debug_nodelist;
33720 struct dentry *vport_debugfs_root;
33721 struct lpfc_debugfs_trc *disc_trc;
33722- atomic_t disc_trc_cnt;
33723+ atomic_unchecked_t disc_trc_cnt;
33724 #endif
33725 uint8_t stat_data_enabled;
33726 uint8_t stat_data_blocked;
33727@@ -725,8 +725,8 @@ struct lpfc_hba {
33728 struct timer_list fabric_block_timer;
33729 unsigned long bit_flags;
33730 #define FABRIC_COMANDS_BLOCKED 0
33731- atomic_t num_rsrc_err;
33732- atomic_t num_cmd_success;
33733+ atomic_unchecked_t num_rsrc_err;
33734+ atomic_unchecked_t num_cmd_success;
33735 unsigned long last_rsrc_error_time;
33736 unsigned long last_ramp_down_time;
33737 unsigned long last_ramp_up_time;
33738@@ -740,7 +740,7 @@ struct lpfc_hba {
33739 struct dentry *debug_dumpDif; /* BlockGuard BPL*/
33740 struct dentry *debug_slow_ring_trc;
33741 struct lpfc_debugfs_trc *slow_ring_trc;
33742- atomic_t slow_ring_trc_cnt;
33743+ atomic_unchecked_t slow_ring_trc_cnt;
33744 #endif
33745
33746 /* Used for deferred freeing of ELS data buffers */
33747diff -urNp linux-2.6.32.41/drivers/scsi/lpfc/lpfc_scsi.c linux-2.6.32.41/drivers/scsi/lpfc/lpfc_scsi.c
33748--- linux-2.6.32.41/drivers/scsi/lpfc/lpfc_scsi.c 2011-03-27 14:31:47.000000000 -0400
33749+++ linux-2.6.32.41/drivers/scsi/lpfc/lpfc_scsi.c 2011-05-04 17:56:28.000000000 -0400
33750@@ -259,7 +259,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hb
33751 uint32_t evt_posted;
33752
33753 spin_lock_irqsave(&phba->hbalock, flags);
33754- atomic_inc(&phba->num_rsrc_err);
33755+ atomic_inc_unchecked(&phba->num_rsrc_err);
33756 phba->last_rsrc_error_time = jiffies;
33757
33758 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
33759@@ -300,7 +300,7 @@ lpfc_rampup_queue_depth(struct lpfc_vpor
33760 unsigned long flags;
33761 struct lpfc_hba *phba = vport->phba;
33762 uint32_t evt_posted;
33763- atomic_inc(&phba->num_cmd_success);
33764+ atomic_inc_unchecked(&phba->num_cmd_success);
33765
33766 if (vport->cfg_lun_queue_depth <= queue_depth)
33767 return;
33768@@ -343,8 +343,8 @@ lpfc_ramp_down_queue_handler(struct lpfc
33769 int i;
33770 struct lpfc_rport_data *rdata;
33771
33772- num_rsrc_err = atomic_read(&phba->num_rsrc_err);
33773- num_cmd_success = atomic_read(&phba->num_cmd_success);
33774+ num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
33775+ num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
33776
33777 vports = lpfc_create_vport_work_array(phba);
33778 if (vports != NULL)
33779@@ -378,8 +378,8 @@ lpfc_ramp_down_queue_handler(struct lpfc
33780 }
33781 }
33782 lpfc_destroy_vport_work_array(phba, vports);
33783- atomic_set(&phba->num_rsrc_err, 0);
33784- atomic_set(&phba->num_cmd_success, 0);
33785+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
33786+ atomic_set_unchecked(&phba->num_cmd_success, 0);
33787 }
33788
33789 /**
33790@@ -427,8 +427,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_h
33791 }
33792 }
33793 lpfc_destroy_vport_work_array(phba, vports);
33794- atomic_set(&phba->num_rsrc_err, 0);
33795- atomic_set(&phba->num_cmd_success, 0);
33796+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
33797+ atomic_set_unchecked(&phba->num_cmd_success, 0);
33798 }
33799
33800 /**
33801diff -urNp linux-2.6.32.41/drivers/scsi/megaraid/megaraid_mbox.c linux-2.6.32.41/drivers/scsi/megaraid/megaraid_mbox.c
33802--- linux-2.6.32.41/drivers/scsi/megaraid/megaraid_mbox.c 2011-03-27 14:31:47.000000000 -0400
33803+++ linux-2.6.32.41/drivers/scsi/megaraid/megaraid_mbox.c 2011-05-16 21:46:57.000000000 -0400
33804@@ -3503,6 +3503,8 @@ megaraid_cmm_register(adapter_t *adapter
33805 int rval;
33806 int i;
33807
33808+ pax_track_stack();
33809+
33810 // Allocate memory for the base list of scb for management module.
33811 adapter->uscb_list = kcalloc(MBOX_MAX_USER_CMDS, sizeof(scb_t), GFP_KERNEL);
33812
33813diff -urNp linux-2.6.32.41/drivers/scsi/osd/osd_initiator.c linux-2.6.32.41/drivers/scsi/osd/osd_initiator.c
33814--- linux-2.6.32.41/drivers/scsi/osd/osd_initiator.c 2011-03-27 14:31:47.000000000 -0400
33815+++ linux-2.6.32.41/drivers/scsi/osd/osd_initiator.c 2011-05-16 21:46:57.000000000 -0400
33816@@ -94,6 +94,8 @@ static int _osd_print_system_info(struct
33817 int nelem = ARRAY_SIZE(get_attrs), a = 0;
33818 int ret;
33819
33820+ pax_track_stack();
33821+
33822 or = osd_start_request(od, GFP_KERNEL);
33823 if (!or)
33824 return -ENOMEM;
33825diff -urNp linux-2.6.32.41/drivers/scsi/pmcraid.c linux-2.6.32.41/drivers/scsi/pmcraid.c
33826--- linux-2.6.32.41/drivers/scsi/pmcraid.c 2011-05-10 22:12:01.000000000 -0400
33827+++ linux-2.6.32.41/drivers/scsi/pmcraid.c 2011-05-10 22:12:33.000000000 -0400
33828@@ -189,8 +189,8 @@ static int pmcraid_slave_alloc(struct sc
33829 res->scsi_dev = scsi_dev;
33830 scsi_dev->hostdata = res;
33831 res->change_detected = 0;
33832- atomic_set(&res->read_failures, 0);
33833- atomic_set(&res->write_failures, 0);
33834+ atomic_set_unchecked(&res->read_failures, 0);
33835+ atomic_set_unchecked(&res->write_failures, 0);
33836 rc = 0;
33837 }
33838 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
33839@@ -2396,9 +2396,9 @@ static int pmcraid_error_handler(struct
33840
33841 /* If this was a SCSI read/write command keep count of errors */
33842 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
33843- atomic_inc(&res->read_failures);
33844+ atomic_inc_unchecked(&res->read_failures);
33845 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
33846- atomic_inc(&res->write_failures);
33847+ atomic_inc_unchecked(&res->write_failures);
33848
33849 if (!RES_IS_GSCSI(res->cfg_entry) &&
33850 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
33851@@ -4113,7 +4113,7 @@ static void pmcraid_worker_function(stru
33852
33853 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
33854 /* add resources only after host is added into system */
33855- if (!atomic_read(&pinstance->expose_resources))
33856+ if (!atomic_read_unchecked(&pinstance->expose_resources))
33857 return;
33858
33859 spin_lock_irqsave(&pinstance->resource_lock, lock_flags);
33860@@ -4847,7 +4847,7 @@ static int __devinit pmcraid_init_instan
33861 init_waitqueue_head(&pinstance->reset_wait_q);
33862
33863 atomic_set(&pinstance->outstanding_cmds, 0);
33864- atomic_set(&pinstance->expose_resources, 0);
33865+ atomic_set_unchecked(&pinstance->expose_resources, 0);
33866
33867 INIT_LIST_HEAD(&pinstance->free_res_q);
33868 INIT_LIST_HEAD(&pinstance->used_res_q);
33869@@ -5499,7 +5499,7 @@ static int __devinit pmcraid_probe(
33870 /* Schedule worker thread to handle CCN and take care of adding and
33871 * removing devices to OS
33872 */
33873- atomic_set(&pinstance->expose_resources, 1);
33874+ atomic_set_unchecked(&pinstance->expose_resources, 1);
33875 schedule_work(&pinstance->worker_q);
33876 return rc;
33877
33878diff -urNp linux-2.6.32.41/drivers/scsi/pmcraid.h linux-2.6.32.41/drivers/scsi/pmcraid.h
33879--- linux-2.6.32.41/drivers/scsi/pmcraid.h 2011-03-27 14:31:47.000000000 -0400
33880+++ linux-2.6.32.41/drivers/scsi/pmcraid.h 2011-05-04 17:56:28.000000000 -0400
33881@@ -690,7 +690,7 @@ struct pmcraid_instance {
33882 atomic_t outstanding_cmds;
33883
33884 /* should add/delete resources to mid-layer now ?*/
33885- atomic_t expose_resources;
33886+ atomic_unchecked_t expose_resources;
33887
33888 /* Tasklet to handle deferred processing */
33889 struct tasklet_struct isr_tasklet[PMCRAID_NUM_MSIX_VECTORS];
33890@@ -727,8 +727,8 @@ struct pmcraid_resource_entry {
33891 struct list_head queue; /* link to "to be exposed" resources */
33892 struct pmcraid_config_table_entry cfg_entry;
33893 struct scsi_device *scsi_dev; /* Link scsi_device structure */
33894- atomic_t read_failures; /* count of failed READ commands */
33895- atomic_t write_failures; /* count of failed WRITE commands */
33896+ atomic_unchecked_t read_failures; /* count of failed READ commands */
33897+ atomic_unchecked_t write_failures; /* count of failed WRITE commands */
33898
33899 /* To indicate add/delete/modify during CCN */
33900 u8 change_detected;
33901diff -urNp linux-2.6.32.41/drivers/scsi/qla4xxx/ql4_def.h linux-2.6.32.41/drivers/scsi/qla4xxx/ql4_def.h
33902--- linux-2.6.32.41/drivers/scsi/qla4xxx/ql4_def.h 2011-03-27 14:31:47.000000000 -0400
33903+++ linux-2.6.32.41/drivers/scsi/qla4xxx/ql4_def.h 2011-05-04 17:56:28.000000000 -0400
33904@@ -240,7 +240,7 @@ struct ddb_entry {
33905 atomic_t retry_relogin_timer; /* Min Time between relogins
33906 * (4000 only) */
33907 atomic_t relogin_timer; /* Max Time to wait for relogin to complete */
33908- atomic_t relogin_retry_count; /* Num of times relogin has been
33909+ atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
33910 * retried */
33911
33912 uint16_t port;
33913diff -urNp linux-2.6.32.41/drivers/scsi/qla4xxx/ql4_init.c linux-2.6.32.41/drivers/scsi/qla4xxx/ql4_init.c
33914--- linux-2.6.32.41/drivers/scsi/qla4xxx/ql4_init.c 2011-03-27 14:31:47.000000000 -0400
33915+++ linux-2.6.32.41/drivers/scsi/qla4xxx/ql4_init.c 2011-05-04 17:56:28.000000000 -0400
33916@@ -482,7 +482,7 @@ static struct ddb_entry * qla4xxx_alloc_
33917 atomic_set(&ddb_entry->port_down_timer, ha->port_down_retry_count);
33918 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
33919 atomic_set(&ddb_entry->relogin_timer, 0);
33920- atomic_set(&ddb_entry->relogin_retry_count, 0);
33921+ atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
33922 atomic_set(&ddb_entry->state, DDB_STATE_ONLINE);
33923 list_add_tail(&ddb_entry->list, &ha->ddb_list);
33924 ha->fw_ddb_index_map[fw_ddb_index] = ddb_entry;
33925@@ -1308,7 +1308,7 @@ int qla4xxx_process_ddb_changed(struct s
33926 atomic_set(&ddb_entry->state, DDB_STATE_ONLINE);
33927 atomic_set(&ddb_entry->port_down_timer,
33928 ha->port_down_retry_count);
33929- atomic_set(&ddb_entry->relogin_retry_count, 0);
33930+ atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
33931 atomic_set(&ddb_entry->relogin_timer, 0);
33932 clear_bit(DF_RELOGIN, &ddb_entry->flags);
33933 clear_bit(DF_NO_RELOGIN, &ddb_entry->flags);
33934diff -urNp linux-2.6.32.41/drivers/scsi/qla4xxx/ql4_os.c linux-2.6.32.41/drivers/scsi/qla4xxx/ql4_os.c
33935--- linux-2.6.32.41/drivers/scsi/qla4xxx/ql4_os.c 2011-03-27 14:31:47.000000000 -0400
33936+++ linux-2.6.32.41/drivers/scsi/qla4xxx/ql4_os.c 2011-05-04 17:56:28.000000000 -0400
33937@@ -641,13 +641,13 @@ static void qla4xxx_timer(struct scsi_ql
33938 ddb_entry->fw_ddb_device_state ==
33939 DDB_DS_SESSION_FAILED) {
33940 /* Reset retry relogin timer */
33941- atomic_inc(&ddb_entry->relogin_retry_count);
33942+ atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
33943 DEBUG2(printk("scsi%ld: index[%d] relogin"
33944 " timed out-retrying"
33945 " relogin (%d)\n",
33946 ha->host_no,
33947 ddb_entry->fw_ddb_index,
33948- atomic_read(&ddb_entry->
33949+ atomic_read_unchecked(&ddb_entry->
33950 relogin_retry_count))
33951 );
33952 start_dpc++;
33953diff -urNp linux-2.6.32.41/drivers/scsi/scsi.c linux-2.6.32.41/drivers/scsi/scsi.c
33954--- linux-2.6.32.41/drivers/scsi/scsi.c 2011-03-27 14:31:47.000000000 -0400
33955+++ linux-2.6.32.41/drivers/scsi/scsi.c 2011-05-04 17:56:28.000000000 -0400
33956@@ -652,7 +652,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *
33957 unsigned long timeout;
33958 int rtn = 0;
33959
33960- atomic_inc(&cmd->device->iorequest_cnt);
33961+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
33962
33963 /* check if the device is still usable */
33964 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
33965diff -urNp linux-2.6.32.41/drivers/scsi/scsi_debug.c linux-2.6.32.41/drivers/scsi/scsi_debug.c
33966--- linux-2.6.32.41/drivers/scsi/scsi_debug.c 2011-03-27 14:31:47.000000000 -0400
33967+++ linux-2.6.32.41/drivers/scsi/scsi_debug.c 2011-05-16 21:46:57.000000000 -0400
33968@@ -1395,6 +1395,8 @@ static int resp_mode_select(struct scsi_
33969 unsigned char arr[SDEBUG_MAX_MSELECT_SZ];
33970 unsigned char *cmd = (unsigned char *)scp->cmnd;
33971
33972+ pax_track_stack();
33973+
33974 if ((errsts = check_readiness(scp, 1, devip)))
33975 return errsts;
33976 memset(arr, 0, sizeof(arr));
33977@@ -1492,6 +1494,8 @@ static int resp_log_sense(struct scsi_cm
33978 unsigned char arr[SDEBUG_MAX_LSENSE_SZ];
33979 unsigned char *cmd = (unsigned char *)scp->cmnd;
33980
33981+ pax_track_stack();
33982+
33983 if ((errsts = check_readiness(scp, 1, devip)))
33984 return errsts;
33985 memset(arr, 0, sizeof(arr));
33986diff -urNp linux-2.6.32.41/drivers/scsi/scsi_lib.c linux-2.6.32.41/drivers/scsi/scsi_lib.c
33987--- linux-2.6.32.41/drivers/scsi/scsi_lib.c 2011-05-10 22:12:01.000000000 -0400
33988+++ linux-2.6.32.41/drivers/scsi/scsi_lib.c 2011-05-10 22:12:33.000000000 -0400
33989@@ -1384,7 +1384,7 @@ static void scsi_kill_request(struct req
33990
33991 scsi_init_cmd_errh(cmd);
33992 cmd->result = DID_NO_CONNECT << 16;
33993- atomic_inc(&cmd->device->iorequest_cnt);
33994+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
33995
33996 /*
33997 * SCSI request completion path will do scsi_device_unbusy(),
33998@@ -1415,9 +1415,9 @@ static void scsi_softirq_done(struct req
33999 */
34000 cmd->serial_number = 0;
34001
34002- atomic_inc(&cmd->device->iodone_cnt);
34003+ atomic_inc_unchecked(&cmd->device->iodone_cnt);
34004 if (cmd->result)
34005- atomic_inc(&cmd->device->ioerr_cnt);
34006+ atomic_inc_unchecked(&cmd->device->ioerr_cnt);
34007
34008 disposition = scsi_decide_disposition(cmd);
34009 if (disposition != SUCCESS &&
34010diff -urNp linux-2.6.32.41/drivers/scsi/scsi_sysfs.c linux-2.6.32.41/drivers/scsi/scsi_sysfs.c
34011--- linux-2.6.32.41/drivers/scsi/scsi_sysfs.c 2011-05-10 22:12:01.000000000 -0400
34012+++ linux-2.6.32.41/drivers/scsi/scsi_sysfs.c 2011-05-10 22:12:33.000000000 -0400
34013@@ -661,7 +661,7 @@ show_iostat_##field(struct device *dev,
34014 char *buf) \
34015 { \
34016 struct scsi_device *sdev = to_scsi_device(dev); \
34017- unsigned long long count = atomic_read(&sdev->field); \
34018+ unsigned long long count = atomic_read_unchecked(&sdev->field); \
34019 return snprintf(buf, 20, "0x%llx\n", count); \
34020 } \
34021 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
34022diff -urNp linux-2.6.32.41/drivers/scsi/scsi_transport_fc.c linux-2.6.32.41/drivers/scsi/scsi_transport_fc.c
34023--- linux-2.6.32.41/drivers/scsi/scsi_transport_fc.c 2011-03-27 14:31:47.000000000 -0400
34024+++ linux-2.6.32.41/drivers/scsi/scsi_transport_fc.c 2011-05-04 17:56:28.000000000 -0400
34025@@ -480,7 +480,7 @@ MODULE_PARM_DESC(dev_loss_tmo,
34026 * Netlink Infrastructure
34027 */
34028
34029-static atomic_t fc_event_seq;
34030+static atomic_unchecked_t fc_event_seq;
34031
34032 /**
34033 * fc_get_event_number - Obtain the next sequential FC event number
34034@@ -493,7 +493,7 @@ static atomic_t fc_event_seq;
34035 u32
34036 fc_get_event_number(void)
34037 {
34038- return atomic_add_return(1, &fc_event_seq);
34039+ return atomic_add_return_unchecked(1, &fc_event_seq);
34040 }
34041 EXPORT_SYMBOL(fc_get_event_number);
34042
34043@@ -641,7 +641,7 @@ static __init int fc_transport_init(void
34044 {
34045 int error;
34046
34047- atomic_set(&fc_event_seq, 0);
34048+ atomic_set_unchecked(&fc_event_seq, 0);
34049
34050 error = transport_class_register(&fc_host_class);
34051 if (error)
34052diff -urNp linux-2.6.32.41/drivers/scsi/scsi_transport_iscsi.c linux-2.6.32.41/drivers/scsi/scsi_transport_iscsi.c
34053--- linux-2.6.32.41/drivers/scsi/scsi_transport_iscsi.c 2011-03-27 14:31:47.000000000 -0400
34054+++ linux-2.6.32.41/drivers/scsi/scsi_transport_iscsi.c 2011-05-04 17:56:28.000000000 -0400
34055@@ -81,7 +81,7 @@ struct iscsi_internal {
34056 struct device_attribute *session_attrs[ISCSI_SESSION_ATTRS + 1];
34057 };
34058
34059-static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
34060+static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
34061 static struct workqueue_struct *iscsi_eh_timer_workq;
34062
34063 /*
34064@@ -728,7 +728,7 @@ int iscsi_add_session(struct iscsi_cls_s
34065 int err;
34066
34067 ihost = shost->shost_data;
34068- session->sid = atomic_add_return(1, &iscsi_session_nr);
34069+ session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
34070
34071 if (id == ISCSI_MAX_TARGET) {
34072 for (id = 0; id < ISCSI_MAX_TARGET; id++) {
34073@@ -2060,7 +2060,7 @@ static __init int iscsi_transport_init(v
34074 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
34075 ISCSI_TRANSPORT_VERSION);
34076
34077- atomic_set(&iscsi_session_nr, 0);
34078+ atomic_set_unchecked(&iscsi_session_nr, 0);
34079
34080 err = class_register(&iscsi_transport_class);
34081 if (err)
34082diff -urNp linux-2.6.32.41/drivers/scsi/scsi_transport_srp.c linux-2.6.32.41/drivers/scsi/scsi_transport_srp.c
34083--- linux-2.6.32.41/drivers/scsi/scsi_transport_srp.c 2011-03-27 14:31:47.000000000 -0400
34084+++ linux-2.6.32.41/drivers/scsi/scsi_transport_srp.c 2011-05-04 17:56:28.000000000 -0400
34085@@ -33,7 +33,7 @@
34086 #include "scsi_transport_srp_internal.h"
34087
34088 struct srp_host_attrs {
34089- atomic_t next_port_id;
34090+ atomic_unchecked_t next_port_id;
34091 };
34092 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
34093
34094@@ -62,7 +62,7 @@ static int srp_host_setup(struct transpo
34095 struct Scsi_Host *shost = dev_to_shost(dev);
34096 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
34097
34098- atomic_set(&srp_host->next_port_id, 0);
34099+ atomic_set_unchecked(&srp_host->next_port_id, 0);
34100 return 0;
34101 }
34102
34103@@ -211,7 +211,7 @@ struct srp_rport *srp_rport_add(struct S
34104 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
34105 rport->roles = ids->roles;
34106
34107- id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
34108+ id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
34109 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
34110
34111 transport_setup_device(&rport->dev);
34112diff -urNp linux-2.6.32.41/drivers/scsi/sg.c linux-2.6.32.41/drivers/scsi/sg.c
34113--- linux-2.6.32.41/drivers/scsi/sg.c 2011-03-27 14:31:47.000000000 -0400
34114+++ linux-2.6.32.41/drivers/scsi/sg.c 2011-04-17 15:56:46.000000000 -0400
34115@@ -2292,7 +2292,7 @@ struct sg_proc_leaf {
34116 const struct file_operations * fops;
34117 };
34118
34119-static struct sg_proc_leaf sg_proc_leaf_arr[] = {
34120+static const struct sg_proc_leaf sg_proc_leaf_arr[] = {
34121 {"allow_dio", &adio_fops},
34122 {"debug", &debug_fops},
34123 {"def_reserved_size", &dressz_fops},
34124@@ -2307,7 +2307,7 @@ sg_proc_init(void)
34125 {
34126 int k, mask;
34127 int num_leaves = ARRAY_SIZE(sg_proc_leaf_arr);
34128- struct sg_proc_leaf * leaf;
34129+ const struct sg_proc_leaf * leaf;
34130
34131 sg_proc_sgp = proc_mkdir(sg_proc_sg_dirname, NULL);
34132 if (!sg_proc_sgp)
34133diff -urNp linux-2.6.32.41/drivers/scsi/sym53c8xx_2/sym_glue.c linux-2.6.32.41/drivers/scsi/sym53c8xx_2/sym_glue.c
34134--- linux-2.6.32.41/drivers/scsi/sym53c8xx_2/sym_glue.c 2011-03-27 14:31:47.000000000 -0400
34135+++ linux-2.6.32.41/drivers/scsi/sym53c8xx_2/sym_glue.c 2011-05-16 21:46:57.000000000 -0400
34136@@ -1754,6 +1754,8 @@ static int __devinit sym2_probe(struct p
34137 int do_iounmap = 0;
34138 int do_disable_device = 1;
34139
34140+ pax_track_stack();
34141+
34142 memset(&sym_dev, 0, sizeof(sym_dev));
34143 memset(&nvram, 0, sizeof(nvram));
34144 sym_dev.pdev = pdev;
34145diff -urNp linux-2.6.32.41/drivers/serial/kgdboc.c linux-2.6.32.41/drivers/serial/kgdboc.c
34146--- linux-2.6.32.41/drivers/serial/kgdboc.c 2011-03-27 14:31:47.000000000 -0400
34147+++ linux-2.6.32.41/drivers/serial/kgdboc.c 2011-04-17 15:56:46.000000000 -0400
34148@@ -18,7 +18,7 @@
34149
34150 #define MAX_CONFIG_LEN 40
34151
34152-static struct kgdb_io kgdboc_io_ops;
34153+static const struct kgdb_io kgdboc_io_ops;
34154
34155 /* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
34156 static int configured = -1;
34157@@ -154,7 +154,7 @@ static void kgdboc_post_exp_handler(void
34158 module_put(THIS_MODULE);
34159 }
34160
34161-static struct kgdb_io kgdboc_io_ops = {
34162+static const struct kgdb_io kgdboc_io_ops = {
34163 .name = "kgdboc",
34164 .read_char = kgdboc_get_char,
34165 .write_char = kgdboc_put_char,
34166diff -urNp linux-2.6.32.41/drivers/spi/spi.c linux-2.6.32.41/drivers/spi/spi.c
34167--- linux-2.6.32.41/drivers/spi/spi.c 2011-03-27 14:31:47.000000000 -0400
34168+++ linux-2.6.32.41/drivers/spi/spi.c 2011-05-04 17:56:28.000000000 -0400
34169@@ -774,7 +774,7 @@ int spi_sync(struct spi_device *spi, str
34170 EXPORT_SYMBOL_GPL(spi_sync);
34171
34172 /* portable code must never pass more than 32 bytes */
34173-#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
34174+#define SPI_BUFSIZ max(32U,SMP_CACHE_BYTES)
34175
34176 static u8 *buf;
34177
34178diff -urNp linux-2.6.32.41/drivers/staging/android/binder.c linux-2.6.32.41/drivers/staging/android/binder.c
34179--- linux-2.6.32.41/drivers/staging/android/binder.c 2011-03-27 14:31:47.000000000 -0400
34180+++ linux-2.6.32.41/drivers/staging/android/binder.c 2011-04-17 15:56:46.000000000 -0400
34181@@ -2756,7 +2756,7 @@ static void binder_vma_close(struct vm_a
34182 binder_defer_work(proc, BINDER_DEFERRED_PUT_FILES);
34183 }
34184
34185-static struct vm_operations_struct binder_vm_ops = {
34186+static const struct vm_operations_struct binder_vm_ops = {
34187 .open = binder_vma_open,
34188 .close = binder_vma_close,
34189 };
34190diff -urNp linux-2.6.32.41/drivers/staging/b3dfg/b3dfg.c linux-2.6.32.41/drivers/staging/b3dfg/b3dfg.c
34191--- linux-2.6.32.41/drivers/staging/b3dfg/b3dfg.c 2011-03-27 14:31:47.000000000 -0400
34192+++ linux-2.6.32.41/drivers/staging/b3dfg/b3dfg.c 2011-04-17 15:56:46.000000000 -0400
34193@@ -455,7 +455,7 @@ static int b3dfg_vma_fault(struct vm_are
34194 return VM_FAULT_NOPAGE;
34195 }
34196
34197-static struct vm_operations_struct b3dfg_vm_ops = {
34198+static const struct vm_operations_struct b3dfg_vm_ops = {
34199 .fault = b3dfg_vma_fault,
34200 };
34201
34202@@ -848,7 +848,7 @@ static int b3dfg_mmap(struct file *filp,
34203 return r;
34204 }
34205
34206-static struct file_operations b3dfg_fops = {
34207+static const struct file_operations b3dfg_fops = {
34208 .owner = THIS_MODULE,
34209 .open = b3dfg_open,
34210 .release = b3dfg_release,
34211diff -urNp linux-2.6.32.41/drivers/staging/comedi/comedi_fops.c linux-2.6.32.41/drivers/staging/comedi/comedi_fops.c
34212--- linux-2.6.32.41/drivers/staging/comedi/comedi_fops.c 2011-03-27 14:31:47.000000000 -0400
34213+++ linux-2.6.32.41/drivers/staging/comedi/comedi_fops.c 2011-04-17 15:56:46.000000000 -0400
34214@@ -1389,7 +1389,7 @@ void comedi_unmap(struct vm_area_struct
34215 mutex_unlock(&dev->mutex);
34216 }
34217
34218-static struct vm_operations_struct comedi_vm_ops = {
34219+static const struct vm_operations_struct comedi_vm_ops = {
34220 .close = comedi_unmap,
34221 };
34222
34223diff -urNp linux-2.6.32.41/drivers/staging/dream/qdsp5/adsp_driver.c linux-2.6.32.41/drivers/staging/dream/qdsp5/adsp_driver.c
34224--- linux-2.6.32.41/drivers/staging/dream/qdsp5/adsp_driver.c 2011-03-27 14:31:47.000000000 -0400
34225+++ linux-2.6.32.41/drivers/staging/dream/qdsp5/adsp_driver.c 2011-04-17 15:56:46.000000000 -0400
34226@@ -576,7 +576,7 @@ static struct adsp_device *inode_to_devi
34227 static dev_t adsp_devno;
34228 static struct class *adsp_class;
34229
34230-static struct file_operations adsp_fops = {
34231+static const struct file_operations adsp_fops = {
34232 .owner = THIS_MODULE,
34233 .open = adsp_open,
34234 .unlocked_ioctl = adsp_ioctl,
34235diff -urNp linux-2.6.32.41/drivers/staging/dream/qdsp5/audio_aac.c linux-2.6.32.41/drivers/staging/dream/qdsp5/audio_aac.c
34236--- linux-2.6.32.41/drivers/staging/dream/qdsp5/audio_aac.c 2011-03-27 14:31:47.000000000 -0400
34237+++ linux-2.6.32.41/drivers/staging/dream/qdsp5/audio_aac.c 2011-04-17 15:56:46.000000000 -0400
34238@@ -1022,7 +1022,7 @@ done:
34239 return rc;
34240 }
34241
34242-static struct file_operations audio_aac_fops = {
34243+static const struct file_operations audio_aac_fops = {
34244 .owner = THIS_MODULE,
34245 .open = audio_open,
34246 .release = audio_release,
34247diff -urNp linux-2.6.32.41/drivers/staging/dream/qdsp5/audio_amrnb.c linux-2.6.32.41/drivers/staging/dream/qdsp5/audio_amrnb.c
34248--- linux-2.6.32.41/drivers/staging/dream/qdsp5/audio_amrnb.c 2011-03-27 14:31:47.000000000 -0400
34249+++ linux-2.6.32.41/drivers/staging/dream/qdsp5/audio_amrnb.c 2011-04-17 15:56:46.000000000 -0400
34250@@ -833,7 +833,7 @@ done:
34251 return rc;
34252 }
34253
34254-static struct file_operations audio_amrnb_fops = {
34255+static const struct file_operations audio_amrnb_fops = {
34256 .owner = THIS_MODULE,
34257 .open = audamrnb_open,
34258 .release = audamrnb_release,
34259diff -urNp linux-2.6.32.41/drivers/staging/dream/qdsp5/audio_evrc.c linux-2.6.32.41/drivers/staging/dream/qdsp5/audio_evrc.c
34260--- linux-2.6.32.41/drivers/staging/dream/qdsp5/audio_evrc.c 2011-03-27 14:31:47.000000000 -0400
34261+++ linux-2.6.32.41/drivers/staging/dream/qdsp5/audio_evrc.c 2011-04-17 15:56:46.000000000 -0400
34262@@ -805,7 +805,7 @@ dma_fail:
34263 return rc;
34264 }
34265
34266-static struct file_operations audio_evrc_fops = {
34267+static const struct file_operations audio_evrc_fops = {
34268 .owner = THIS_MODULE,
34269 .open = audevrc_open,
34270 .release = audevrc_release,
34271diff -urNp linux-2.6.32.41/drivers/staging/dream/qdsp5/audio_in.c linux-2.6.32.41/drivers/staging/dream/qdsp5/audio_in.c
34272--- linux-2.6.32.41/drivers/staging/dream/qdsp5/audio_in.c 2011-03-27 14:31:47.000000000 -0400
34273+++ linux-2.6.32.41/drivers/staging/dream/qdsp5/audio_in.c 2011-04-17 15:56:46.000000000 -0400
34274@@ -913,7 +913,7 @@ static int audpre_open(struct inode *ino
34275 return 0;
34276 }
34277
34278-static struct file_operations audio_fops = {
34279+static const struct file_operations audio_fops = {
34280 .owner = THIS_MODULE,
34281 .open = audio_in_open,
34282 .release = audio_in_release,
34283@@ -922,7 +922,7 @@ static struct file_operations audio_fops
34284 .unlocked_ioctl = audio_in_ioctl,
34285 };
34286
34287-static struct file_operations audpre_fops = {
34288+static const struct file_operations audpre_fops = {
34289 .owner = THIS_MODULE,
34290 .open = audpre_open,
34291 .unlocked_ioctl = audpre_ioctl,
34292diff -urNp linux-2.6.32.41/drivers/staging/dream/qdsp5/audio_mp3.c linux-2.6.32.41/drivers/staging/dream/qdsp5/audio_mp3.c
34293--- linux-2.6.32.41/drivers/staging/dream/qdsp5/audio_mp3.c 2011-03-27 14:31:47.000000000 -0400
34294+++ linux-2.6.32.41/drivers/staging/dream/qdsp5/audio_mp3.c 2011-04-17 15:56:46.000000000 -0400
34295@@ -941,7 +941,7 @@ done:
34296 return rc;
34297 }
34298
34299-static struct file_operations audio_mp3_fops = {
34300+static const struct file_operations audio_mp3_fops = {
34301 .owner = THIS_MODULE,
34302 .open = audio_open,
34303 .release = audio_release,
34304diff -urNp linux-2.6.32.41/drivers/staging/dream/qdsp5/audio_out.c linux-2.6.32.41/drivers/staging/dream/qdsp5/audio_out.c
34305--- linux-2.6.32.41/drivers/staging/dream/qdsp5/audio_out.c 2011-03-27 14:31:47.000000000 -0400
34306+++ linux-2.6.32.41/drivers/staging/dream/qdsp5/audio_out.c 2011-04-17 15:56:46.000000000 -0400
34307@@ -810,7 +810,7 @@ static int audpp_open(struct inode *inod
34308 return 0;
34309 }
34310
34311-static struct file_operations audio_fops = {
34312+static const struct file_operations audio_fops = {
34313 .owner = THIS_MODULE,
34314 .open = audio_open,
34315 .release = audio_release,
34316@@ -819,7 +819,7 @@ static struct file_operations audio_fops
34317 .unlocked_ioctl = audio_ioctl,
34318 };
34319
34320-static struct file_operations audpp_fops = {
34321+static const struct file_operations audpp_fops = {
34322 .owner = THIS_MODULE,
34323 .open = audpp_open,
34324 .unlocked_ioctl = audpp_ioctl,
34325diff -urNp linux-2.6.32.41/drivers/staging/dream/qdsp5/audio_qcelp.c linux-2.6.32.41/drivers/staging/dream/qdsp5/audio_qcelp.c
34326--- linux-2.6.32.41/drivers/staging/dream/qdsp5/audio_qcelp.c 2011-03-27 14:31:47.000000000 -0400
34327+++ linux-2.6.32.41/drivers/staging/dream/qdsp5/audio_qcelp.c 2011-04-17 15:56:46.000000000 -0400
34328@@ -816,7 +816,7 @@ err:
34329 return rc;
34330 }
34331
34332-static struct file_operations audio_qcelp_fops = {
34333+static const struct file_operations audio_qcelp_fops = {
34334 .owner = THIS_MODULE,
34335 .open = audqcelp_open,
34336 .release = audqcelp_release,
34337diff -urNp linux-2.6.32.41/drivers/staging/dream/qdsp5/snd.c linux-2.6.32.41/drivers/staging/dream/qdsp5/snd.c
34338--- linux-2.6.32.41/drivers/staging/dream/qdsp5/snd.c 2011-03-27 14:31:47.000000000 -0400
34339+++ linux-2.6.32.41/drivers/staging/dream/qdsp5/snd.c 2011-04-17 15:56:46.000000000 -0400
34340@@ -242,7 +242,7 @@ err:
34341 return rc;
34342 }
34343
34344-static struct file_operations snd_fops = {
34345+static const struct file_operations snd_fops = {
34346 .owner = THIS_MODULE,
34347 .open = snd_open,
34348 .release = snd_release,
34349diff -urNp linux-2.6.32.41/drivers/staging/dream/smd/smd_qmi.c linux-2.6.32.41/drivers/staging/dream/smd/smd_qmi.c
34350--- linux-2.6.32.41/drivers/staging/dream/smd/smd_qmi.c 2011-03-27 14:31:47.000000000 -0400
34351+++ linux-2.6.32.41/drivers/staging/dream/smd/smd_qmi.c 2011-04-17 15:56:46.000000000 -0400
34352@@ -793,7 +793,7 @@ static int qmi_release(struct inode *ip,
34353 return 0;
34354 }
34355
34356-static struct file_operations qmi_fops = {
34357+static const struct file_operations qmi_fops = {
34358 .owner = THIS_MODULE,
34359 .read = qmi_read,
34360 .write = qmi_write,
34361diff -urNp linux-2.6.32.41/drivers/staging/dream/smd/smd_rpcrouter_device.c linux-2.6.32.41/drivers/staging/dream/smd/smd_rpcrouter_device.c
34362--- linux-2.6.32.41/drivers/staging/dream/smd/smd_rpcrouter_device.c 2011-03-27 14:31:47.000000000 -0400
34363+++ linux-2.6.32.41/drivers/staging/dream/smd/smd_rpcrouter_device.c 2011-04-17 15:56:46.000000000 -0400
34364@@ -214,7 +214,7 @@ static long rpcrouter_ioctl(struct file
34365 return rc;
34366 }
34367
34368-static struct file_operations rpcrouter_server_fops = {
34369+static const struct file_operations rpcrouter_server_fops = {
34370 .owner = THIS_MODULE,
34371 .open = rpcrouter_open,
34372 .release = rpcrouter_release,
34373@@ -224,7 +224,7 @@ static struct file_operations rpcrouter_
34374 .unlocked_ioctl = rpcrouter_ioctl,
34375 };
34376
34377-static struct file_operations rpcrouter_router_fops = {
34378+static const struct file_operations rpcrouter_router_fops = {
34379 .owner = THIS_MODULE,
34380 .open = rpcrouter_open,
34381 .release = rpcrouter_release,
34382diff -urNp linux-2.6.32.41/drivers/staging/dst/dcore.c linux-2.6.32.41/drivers/staging/dst/dcore.c
34383--- linux-2.6.32.41/drivers/staging/dst/dcore.c 2011-03-27 14:31:47.000000000 -0400
34384+++ linux-2.6.32.41/drivers/staging/dst/dcore.c 2011-04-17 15:56:46.000000000 -0400
34385@@ -149,7 +149,7 @@ static int dst_bdev_release(struct gendi
34386 return 0;
34387 }
34388
34389-static struct block_device_operations dst_blk_ops = {
34390+static const struct block_device_operations dst_blk_ops = {
34391 .open = dst_bdev_open,
34392 .release = dst_bdev_release,
34393 .owner = THIS_MODULE,
34394@@ -588,7 +588,7 @@ static struct dst_node *dst_alloc_node(s
34395 n->size = ctl->size;
34396
34397 atomic_set(&n->refcnt, 1);
34398- atomic_long_set(&n->gen, 0);
34399+ atomic_long_set_unchecked(&n->gen, 0);
34400 snprintf(n->name, sizeof(n->name), "%s", ctl->name);
34401
34402 err = dst_node_sysfs_init(n);
34403diff -urNp linux-2.6.32.41/drivers/staging/dst/trans.c linux-2.6.32.41/drivers/staging/dst/trans.c
34404--- linux-2.6.32.41/drivers/staging/dst/trans.c 2011-03-27 14:31:47.000000000 -0400
34405+++ linux-2.6.32.41/drivers/staging/dst/trans.c 2011-04-17 15:56:46.000000000 -0400
34406@@ -169,7 +169,7 @@ int dst_process_bio(struct dst_node *n,
34407 t->error = 0;
34408 t->retries = 0;
34409 atomic_set(&t->refcnt, 1);
34410- t->gen = atomic_long_inc_return(&n->gen);
34411+ t->gen = atomic_long_inc_return_unchecked(&n->gen);
34412
34413 t->enc = bio_data_dir(bio);
34414 dst_bio_to_cmd(bio, &t->cmd, DST_IO, t->gen);
34415diff -urNp linux-2.6.32.41/drivers/staging/et131x/et1310_tx.c linux-2.6.32.41/drivers/staging/et131x/et1310_tx.c
34416--- linux-2.6.32.41/drivers/staging/et131x/et1310_tx.c 2011-03-27 14:31:47.000000000 -0400
34417+++ linux-2.6.32.41/drivers/staging/et131x/et1310_tx.c 2011-05-04 17:56:28.000000000 -0400
34418@@ -710,11 +710,11 @@ inline void et131x_free_send_packet(stru
34419 struct net_device_stats *stats = &etdev->net_stats;
34420
34421 if (pMpTcb->Flags & fMP_DEST_BROAD)
34422- atomic_inc(&etdev->Stats.brdcstxmt);
34423+ atomic_inc_unchecked(&etdev->Stats.brdcstxmt);
34424 else if (pMpTcb->Flags & fMP_DEST_MULTI)
34425- atomic_inc(&etdev->Stats.multixmt);
34426+ atomic_inc_unchecked(&etdev->Stats.multixmt);
34427 else
34428- atomic_inc(&etdev->Stats.unixmt);
34429+ atomic_inc_unchecked(&etdev->Stats.unixmt);
34430
34431 if (pMpTcb->Packet) {
34432 stats->tx_bytes += pMpTcb->Packet->len;
34433diff -urNp linux-2.6.32.41/drivers/staging/et131x/et131x_adapter.h linux-2.6.32.41/drivers/staging/et131x/et131x_adapter.h
34434--- linux-2.6.32.41/drivers/staging/et131x/et131x_adapter.h 2011-03-27 14:31:47.000000000 -0400
34435+++ linux-2.6.32.41/drivers/staging/et131x/et131x_adapter.h 2011-05-04 17:56:28.000000000 -0400
34436@@ -145,11 +145,11 @@ typedef struct _ce_stats_t {
34437 * operations
34438 */
34439 u32 unircv; /* # multicast packets received */
34440- atomic_t unixmt; /* # multicast packets for Tx */
34441+ atomic_unchecked_t unixmt; /* # multicast packets for Tx */
34442 u32 multircv; /* # multicast packets received */
34443- atomic_t multixmt; /* # multicast packets for Tx */
34444+ atomic_unchecked_t multixmt; /* # multicast packets for Tx */
34445 u32 brdcstrcv; /* # broadcast packets received */
34446- atomic_t brdcstxmt; /* # broadcast packets for Tx */
34447+ atomic_unchecked_t brdcstxmt; /* # broadcast packets for Tx */
34448 u32 norcvbuf; /* # Rx packets discarded */
34449 u32 noxmtbuf; /* # Tx packets discarded */
34450
34451diff -urNp linux-2.6.32.41/drivers/staging/go7007/go7007-v4l2.c linux-2.6.32.41/drivers/staging/go7007/go7007-v4l2.c
34452--- linux-2.6.32.41/drivers/staging/go7007/go7007-v4l2.c 2011-03-27 14:31:47.000000000 -0400
34453+++ linux-2.6.32.41/drivers/staging/go7007/go7007-v4l2.c 2011-04-17 15:56:46.000000000 -0400
34454@@ -1700,7 +1700,7 @@ static int go7007_vm_fault(struct vm_are
34455 return 0;
34456 }
34457
34458-static struct vm_operations_struct go7007_vm_ops = {
34459+static const struct vm_operations_struct go7007_vm_ops = {
34460 .open = go7007_vm_open,
34461 .close = go7007_vm_close,
34462 .fault = go7007_vm_fault,
34463diff -urNp linux-2.6.32.41/drivers/staging/hv/blkvsc_drv.c linux-2.6.32.41/drivers/staging/hv/blkvsc_drv.c
34464--- linux-2.6.32.41/drivers/staging/hv/blkvsc_drv.c 2011-03-27 14:31:47.000000000 -0400
34465+++ linux-2.6.32.41/drivers/staging/hv/blkvsc_drv.c 2011-04-17 15:56:46.000000000 -0400
34466@@ -153,7 +153,7 @@ static int blkvsc_ringbuffer_size = BLKV
34467 /* The one and only one */
34468 static struct blkvsc_driver_context g_blkvsc_drv;
34469
34470-static struct block_device_operations block_ops = {
34471+static const struct block_device_operations block_ops = {
34472 .owner = THIS_MODULE,
34473 .open = blkvsc_open,
34474 .release = blkvsc_release,
34475diff -urNp linux-2.6.32.41/drivers/staging/hv/Channel.c linux-2.6.32.41/drivers/staging/hv/Channel.c
34476--- linux-2.6.32.41/drivers/staging/hv/Channel.c 2011-04-17 17:00:52.000000000 -0400
34477+++ linux-2.6.32.41/drivers/staging/hv/Channel.c 2011-05-04 17:56:28.000000000 -0400
34478@@ -464,8 +464,8 @@ int VmbusChannelEstablishGpadl(struct vm
34479
34480 DPRINT_ENTER(VMBUS);
34481
34482- nextGpadlHandle = atomic_read(&gVmbusConnection.NextGpadlHandle);
34483- atomic_inc(&gVmbusConnection.NextGpadlHandle);
34484+ nextGpadlHandle = atomic_read_unchecked(&gVmbusConnection.NextGpadlHandle);
34485+ atomic_inc_unchecked(&gVmbusConnection.NextGpadlHandle);
34486
34487 VmbusChannelCreateGpadlHeader(Kbuffer, Size, &msgInfo, &msgCount);
34488 ASSERT(msgInfo != NULL);
34489diff -urNp linux-2.6.32.41/drivers/staging/hv/Hv.c linux-2.6.32.41/drivers/staging/hv/Hv.c
34490--- linux-2.6.32.41/drivers/staging/hv/Hv.c 2011-03-27 14:31:47.000000000 -0400
34491+++ linux-2.6.32.41/drivers/staging/hv/Hv.c 2011-04-17 15:56:46.000000000 -0400
34492@@ -161,7 +161,7 @@ static u64 HvDoHypercall(u64 Control, vo
34493 u64 outputAddress = (Output) ? virt_to_phys(Output) : 0;
34494 u32 outputAddressHi = outputAddress >> 32;
34495 u32 outputAddressLo = outputAddress & 0xFFFFFFFF;
34496- volatile void *hypercallPage = gHvContext.HypercallPage;
34497+ volatile void *hypercallPage = ktva_ktla(gHvContext.HypercallPage);
34498
34499 DPRINT_DBG(VMBUS, "Hypercall <control %llx input %p output %p>",
34500 Control, Input, Output);
34501diff -urNp linux-2.6.32.41/drivers/staging/hv/vmbus_drv.c linux-2.6.32.41/drivers/staging/hv/vmbus_drv.c
34502--- linux-2.6.32.41/drivers/staging/hv/vmbus_drv.c 2011-03-27 14:31:47.000000000 -0400
34503+++ linux-2.6.32.41/drivers/staging/hv/vmbus_drv.c 2011-05-04 17:56:28.000000000 -0400
34504@@ -532,7 +532,7 @@ static int vmbus_child_device_register(s
34505 to_device_context(root_device_obj);
34506 struct device_context *child_device_ctx =
34507 to_device_context(child_device_obj);
34508- static atomic_t device_num = ATOMIC_INIT(0);
34509+ static atomic_unchecked_t device_num = ATOMIC_INIT(0);
34510
34511 DPRINT_ENTER(VMBUS_DRV);
34512
34513@@ -541,7 +541,7 @@ static int vmbus_child_device_register(s
34514
34515 /* Set the device name. Otherwise, device_register() will fail. */
34516 dev_set_name(&child_device_ctx->device, "vmbus_0_%d",
34517- atomic_inc_return(&device_num));
34518+ atomic_inc_return_unchecked(&device_num));
34519
34520 /* The new device belongs to this bus */
34521 child_device_ctx->device.bus = &g_vmbus_drv.bus; /* device->dev.bus; */
34522diff -urNp linux-2.6.32.41/drivers/staging/hv/VmbusPrivate.h linux-2.6.32.41/drivers/staging/hv/VmbusPrivate.h
34523--- linux-2.6.32.41/drivers/staging/hv/VmbusPrivate.h 2011-04-17 17:00:52.000000000 -0400
34524+++ linux-2.6.32.41/drivers/staging/hv/VmbusPrivate.h 2011-05-04 17:56:28.000000000 -0400
34525@@ -59,7 +59,7 @@ enum VMBUS_CONNECT_STATE {
34526 struct VMBUS_CONNECTION {
34527 enum VMBUS_CONNECT_STATE ConnectState;
34528
34529- atomic_t NextGpadlHandle;
34530+ atomic_unchecked_t NextGpadlHandle;
34531
34532 /*
34533 * Represents channel interrupts. Each bit position represents a
34534diff -urNp linux-2.6.32.41/drivers/staging/octeon/ethernet.c linux-2.6.32.41/drivers/staging/octeon/ethernet.c
34535--- linux-2.6.32.41/drivers/staging/octeon/ethernet.c 2011-03-27 14:31:47.000000000 -0400
34536+++ linux-2.6.32.41/drivers/staging/octeon/ethernet.c 2011-05-04 17:56:28.000000000 -0400
34537@@ -294,11 +294,11 @@ static struct net_device_stats *cvm_oct_
34538 * since the RX tasklet also increments it.
34539 */
34540 #ifdef CONFIG_64BIT
34541- atomic64_add(rx_status.dropped_packets,
34542- (atomic64_t *)&priv->stats.rx_dropped);
34543+ atomic64_add_unchecked(rx_status.dropped_packets,
34544+ (atomic64_unchecked_t *)&priv->stats.rx_dropped);
34545 #else
34546- atomic_add(rx_status.dropped_packets,
34547- (atomic_t *)&priv->stats.rx_dropped);
34548+ atomic_add_unchecked(rx_status.dropped_packets,
34549+ (atomic_unchecked_t *)&priv->stats.rx_dropped);
34550 #endif
34551 }
34552
34553diff -urNp linux-2.6.32.41/drivers/staging/octeon/ethernet-rx.c linux-2.6.32.41/drivers/staging/octeon/ethernet-rx.c
34554--- linux-2.6.32.41/drivers/staging/octeon/ethernet-rx.c 2011-03-27 14:31:47.000000000 -0400
34555+++ linux-2.6.32.41/drivers/staging/octeon/ethernet-rx.c 2011-05-04 17:56:28.000000000 -0400
34556@@ -406,11 +406,11 @@ void cvm_oct_tasklet_rx(unsigned long un
34557 /* Increment RX stats for virtual ports */
34558 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
34559 #ifdef CONFIG_64BIT
34560- atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
34561- atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
34562+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
34563+ atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
34564 #else
34565- atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
34566- atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
34567+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
34568+ atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
34569 #endif
34570 }
34571 netif_receive_skb(skb);
34572@@ -424,9 +424,9 @@ void cvm_oct_tasklet_rx(unsigned long un
34573 dev->name);
34574 */
34575 #ifdef CONFIG_64BIT
34576- atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
34577+ atomic64_add_unchecked(1, (atomic64_t *)&priv->stats.rx_dropped);
34578 #else
34579- atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
34580+ atomic_add_unchecked(1, (atomic_t *)&priv->stats.rx_dropped);
34581 #endif
34582 dev_kfree_skb_irq(skb);
34583 }
34584diff -urNp linux-2.6.32.41/drivers/staging/panel/panel.c linux-2.6.32.41/drivers/staging/panel/panel.c
34585--- linux-2.6.32.41/drivers/staging/panel/panel.c 2011-03-27 14:31:47.000000000 -0400
34586+++ linux-2.6.32.41/drivers/staging/panel/panel.c 2011-04-17 15:56:46.000000000 -0400
34587@@ -1305,7 +1305,7 @@ static int lcd_release(struct inode *ino
34588 return 0;
34589 }
34590
34591-static struct file_operations lcd_fops = {
34592+static const struct file_operations lcd_fops = {
34593 .write = lcd_write,
34594 .open = lcd_open,
34595 .release = lcd_release,
34596@@ -1565,7 +1565,7 @@ static int keypad_release(struct inode *
34597 return 0;
34598 }
34599
34600-static struct file_operations keypad_fops = {
34601+static const struct file_operations keypad_fops = {
34602 .read = keypad_read, /* read */
34603 .open = keypad_open, /* open */
34604 .release = keypad_release, /* close */
34605diff -urNp linux-2.6.32.41/drivers/staging/phison/phison.c linux-2.6.32.41/drivers/staging/phison/phison.c
34606--- linux-2.6.32.41/drivers/staging/phison/phison.c 2011-03-27 14:31:47.000000000 -0400
34607+++ linux-2.6.32.41/drivers/staging/phison/phison.c 2011-04-17 15:56:46.000000000 -0400
34608@@ -43,7 +43,7 @@ static struct scsi_host_template phison_
34609 ATA_BMDMA_SHT(DRV_NAME),
34610 };
34611
34612-static struct ata_port_operations phison_ops = {
34613+static const struct ata_port_operations phison_ops = {
34614 .inherits = &ata_bmdma_port_ops,
34615 .prereset = phison_pre_reset,
34616 };
34617diff -urNp linux-2.6.32.41/drivers/staging/poch/poch.c linux-2.6.32.41/drivers/staging/poch/poch.c
34618--- linux-2.6.32.41/drivers/staging/poch/poch.c 2011-03-27 14:31:47.000000000 -0400
34619+++ linux-2.6.32.41/drivers/staging/poch/poch.c 2011-04-17 15:56:46.000000000 -0400
34620@@ -1057,7 +1057,7 @@ static int poch_ioctl(struct inode *inod
34621 return 0;
34622 }
34623
34624-static struct file_operations poch_fops = {
34625+static const struct file_operations poch_fops = {
34626 .owner = THIS_MODULE,
34627 .open = poch_open,
34628 .release = poch_release,
34629diff -urNp linux-2.6.32.41/drivers/staging/pohmelfs/inode.c linux-2.6.32.41/drivers/staging/pohmelfs/inode.c
34630--- linux-2.6.32.41/drivers/staging/pohmelfs/inode.c 2011-03-27 14:31:47.000000000 -0400
34631+++ linux-2.6.32.41/drivers/staging/pohmelfs/inode.c 2011-05-04 17:56:20.000000000 -0400
34632@@ -1850,7 +1850,7 @@ static int pohmelfs_fill_super(struct su
34633 mutex_init(&psb->mcache_lock);
34634 psb->mcache_root = RB_ROOT;
34635 psb->mcache_timeout = msecs_to_jiffies(5000);
34636- atomic_long_set(&psb->mcache_gen, 0);
34637+ atomic_long_set_unchecked(&psb->mcache_gen, 0);
34638
34639 psb->trans_max_pages = 100;
34640
34641@@ -1865,7 +1865,7 @@ static int pohmelfs_fill_super(struct su
34642 INIT_LIST_HEAD(&psb->crypto_ready_list);
34643 INIT_LIST_HEAD(&psb->crypto_active_list);
34644
34645- atomic_set(&psb->trans_gen, 1);
34646+ atomic_set_unchecked(&psb->trans_gen, 1);
34647 atomic_long_set(&psb->total_inodes, 0);
34648
34649 mutex_init(&psb->state_lock);
34650diff -urNp linux-2.6.32.41/drivers/staging/pohmelfs/mcache.c linux-2.6.32.41/drivers/staging/pohmelfs/mcache.c
34651--- linux-2.6.32.41/drivers/staging/pohmelfs/mcache.c 2011-03-27 14:31:47.000000000 -0400
34652+++ linux-2.6.32.41/drivers/staging/pohmelfs/mcache.c 2011-04-17 15:56:46.000000000 -0400
34653@@ -121,7 +121,7 @@ struct pohmelfs_mcache *pohmelfs_mcache_
34654 m->data = data;
34655 m->start = start;
34656 m->size = size;
34657- m->gen = atomic_long_inc_return(&psb->mcache_gen);
34658+ m->gen = atomic_long_inc_return_unchecked(&psb->mcache_gen);
34659
34660 mutex_lock(&psb->mcache_lock);
34661 err = pohmelfs_mcache_insert(psb, m);
34662diff -urNp linux-2.6.32.41/drivers/staging/pohmelfs/netfs.h linux-2.6.32.41/drivers/staging/pohmelfs/netfs.h
34663--- linux-2.6.32.41/drivers/staging/pohmelfs/netfs.h 2011-03-27 14:31:47.000000000 -0400
34664+++ linux-2.6.32.41/drivers/staging/pohmelfs/netfs.h 2011-05-04 17:56:20.000000000 -0400
34665@@ -570,14 +570,14 @@ struct pohmelfs_config;
34666 struct pohmelfs_sb {
34667 struct rb_root mcache_root;
34668 struct mutex mcache_lock;
34669- atomic_long_t mcache_gen;
34670+ atomic_long_unchecked_t mcache_gen;
34671 unsigned long mcache_timeout;
34672
34673 unsigned int idx;
34674
34675 unsigned int trans_retries;
34676
34677- atomic_t trans_gen;
34678+ atomic_unchecked_t trans_gen;
34679
34680 unsigned int crypto_attached_size;
34681 unsigned int crypto_align_size;
34682diff -urNp linux-2.6.32.41/drivers/staging/pohmelfs/trans.c linux-2.6.32.41/drivers/staging/pohmelfs/trans.c
34683--- linux-2.6.32.41/drivers/staging/pohmelfs/trans.c 2011-03-27 14:31:47.000000000 -0400
34684+++ linux-2.6.32.41/drivers/staging/pohmelfs/trans.c 2011-05-04 17:56:28.000000000 -0400
34685@@ -492,7 +492,7 @@ int netfs_trans_finish(struct netfs_tran
34686 int err;
34687 struct netfs_cmd *cmd = t->iovec.iov_base;
34688
34689- t->gen = atomic_inc_return(&psb->trans_gen);
34690+ t->gen = atomic_inc_return_unchecked(&psb->trans_gen);
34691
34692 cmd->size = t->iovec.iov_len - sizeof(struct netfs_cmd) +
34693 t->attached_size + t->attached_pages * sizeof(struct netfs_cmd);
34694diff -urNp linux-2.6.32.41/drivers/staging/sep/sep_driver.c linux-2.6.32.41/drivers/staging/sep/sep_driver.c
34695--- linux-2.6.32.41/drivers/staging/sep/sep_driver.c 2011-03-27 14:31:47.000000000 -0400
34696+++ linux-2.6.32.41/drivers/staging/sep/sep_driver.c 2011-04-17 15:56:46.000000000 -0400
34697@@ -2603,7 +2603,7 @@ static struct pci_driver sep_pci_driver
34698 static dev_t sep_devno;
34699
34700 /* the files operations structure of the driver */
34701-static struct file_operations sep_file_operations = {
34702+static const struct file_operations sep_file_operations = {
34703 .owner = THIS_MODULE,
34704 .ioctl = sep_ioctl,
34705 .poll = sep_poll,
34706diff -urNp linux-2.6.32.41/drivers/staging/usbip/vhci.h linux-2.6.32.41/drivers/staging/usbip/vhci.h
34707--- linux-2.6.32.41/drivers/staging/usbip/vhci.h 2011-03-27 14:31:47.000000000 -0400
34708+++ linux-2.6.32.41/drivers/staging/usbip/vhci.h 2011-05-04 17:56:28.000000000 -0400
34709@@ -92,7 +92,7 @@ struct vhci_hcd {
34710 unsigned resuming:1;
34711 unsigned long re_timeout;
34712
34713- atomic_t seqnum;
34714+ atomic_unchecked_t seqnum;
34715
34716 /*
34717 * NOTE:
34718diff -urNp linux-2.6.32.41/drivers/staging/usbip/vhci_hcd.c linux-2.6.32.41/drivers/staging/usbip/vhci_hcd.c
34719--- linux-2.6.32.41/drivers/staging/usbip/vhci_hcd.c 2011-05-10 22:12:01.000000000 -0400
34720+++ linux-2.6.32.41/drivers/staging/usbip/vhci_hcd.c 2011-05-10 22:12:33.000000000 -0400
34721@@ -534,7 +534,7 @@ static void vhci_tx_urb(struct urb *urb)
34722 return;
34723 }
34724
34725- priv->seqnum = atomic_inc_return(&the_controller->seqnum);
34726+ priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
34727 if (priv->seqnum == 0xffff)
34728 usbip_uinfo("seqnum max\n");
34729
34730@@ -793,7 +793,7 @@ static int vhci_urb_dequeue(struct usb_h
34731 return -ENOMEM;
34732 }
34733
34734- unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
34735+ unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
34736 if (unlink->seqnum == 0xffff)
34737 usbip_uinfo("seqnum max\n");
34738
34739@@ -988,7 +988,7 @@ static int vhci_start(struct usb_hcd *hc
34740 vdev->rhport = rhport;
34741 }
34742
34743- atomic_set(&vhci->seqnum, 0);
34744+ atomic_set_unchecked(&vhci->seqnum, 0);
34745 spin_lock_init(&vhci->lock);
34746
34747
34748diff -urNp linux-2.6.32.41/drivers/staging/usbip/vhci_rx.c linux-2.6.32.41/drivers/staging/usbip/vhci_rx.c
34749--- linux-2.6.32.41/drivers/staging/usbip/vhci_rx.c 2011-04-17 17:00:52.000000000 -0400
34750+++ linux-2.6.32.41/drivers/staging/usbip/vhci_rx.c 2011-05-04 17:56:28.000000000 -0400
34751@@ -78,7 +78,7 @@ static void vhci_recv_ret_submit(struct
34752 usbip_uerr("cannot find a urb of seqnum %u\n",
34753 pdu->base.seqnum);
34754 usbip_uinfo("max seqnum %d\n",
34755- atomic_read(&the_controller->seqnum));
34756+ atomic_read_unchecked(&the_controller->seqnum));
34757 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
34758 return;
34759 }
34760diff -urNp linux-2.6.32.41/drivers/staging/vme/devices/vme_user.c linux-2.6.32.41/drivers/staging/vme/devices/vme_user.c
34761--- linux-2.6.32.41/drivers/staging/vme/devices/vme_user.c 2011-03-27 14:31:47.000000000 -0400
34762+++ linux-2.6.32.41/drivers/staging/vme/devices/vme_user.c 2011-04-17 15:56:46.000000000 -0400
34763@@ -136,7 +136,7 @@ static int vme_user_ioctl(struct inode *
34764 static int __init vme_user_probe(struct device *, int, int);
34765 static int __exit vme_user_remove(struct device *, int, int);
34766
34767-static struct file_operations vme_user_fops = {
34768+static const struct file_operations vme_user_fops = {
34769 .open = vme_user_open,
34770 .release = vme_user_release,
34771 .read = vme_user_read,
34772diff -urNp linux-2.6.32.41/drivers/telephony/ixj.c linux-2.6.32.41/drivers/telephony/ixj.c
34773--- linux-2.6.32.41/drivers/telephony/ixj.c 2011-03-27 14:31:47.000000000 -0400
34774+++ linux-2.6.32.41/drivers/telephony/ixj.c 2011-05-16 21:46:57.000000000 -0400
34775@@ -4976,6 +4976,8 @@ static int ixj_daa_cid_read(IXJ *j)
34776 bool mContinue;
34777 char *pIn, *pOut;
34778
34779+ pax_track_stack();
34780+
34781 if (!SCI_Prepare(j))
34782 return 0;
34783
34784diff -urNp linux-2.6.32.41/drivers/uio/uio.c linux-2.6.32.41/drivers/uio/uio.c
34785--- linux-2.6.32.41/drivers/uio/uio.c 2011-03-27 14:31:47.000000000 -0400
34786+++ linux-2.6.32.41/drivers/uio/uio.c 2011-05-04 17:56:20.000000000 -0400
34787@@ -23,6 +23,7 @@
34788 #include <linux/string.h>
34789 #include <linux/kobject.h>
34790 #include <linux/uio_driver.h>
34791+#include <asm/local.h>
34792
34793 #define UIO_MAX_DEVICES 255
34794
34795@@ -30,10 +31,10 @@ struct uio_device {
34796 struct module *owner;
34797 struct device *dev;
34798 int minor;
34799- atomic_t event;
34800+ atomic_unchecked_t event;
34801 struct fasync_struct *async_queue;
34802 wait_queue_head_t wait;
34803- int vma_count;
34804+ local_t vma_count;
34805 struct uio_info *info;
34806 struct kobject *map_dir;
34807 struct kobject *portio_dir;
34808@@ -129,7 +130,7 @@ static ssize_t map_type_show(struct kobj
34809 return entry->show(mem, buf);
34810 }
34811
34812-static struct sysfs_ops map_sysfs_ops = {
34813+static const struct sysfs_ops map_sysfs_ops = {
34814 .show = map_type_show,
34815 };
34816
34817@@ -217,7 +218,7 @@ static ssize_t portio_type_show(struct k
34818 return entry->show(port, buf);
34819 }
34820
34821-static struct sysfs_ops portio_sysfs_ops = {
34822+static const struct sysfs_ops portio_sysfs_ops = {
34823 .show = portio_type_show,
34824 };
34825
34826@@ -255,7 +256,7 @@ static ssize_t show_event(struct device
34827 struct uio_device *idev = dev_get_drvdata(dev);
34828 if (idev)
34829 return sprintf(buf, "%u\n",
34830- (unsigned int)atomic_read(&idev->event));
34831+ (unsigned int)atomic_read_unchecked(&idev->event));
34832 else
34833 return -ENODEV;
34834 }
34835@@ -424,7 +425,7 @@ void uio_event_notify(struct uio_info *i
34836 {
34837 struct uio_device *idev = info->uio_dev;
34838
34839- atomic_inc(&idev->event);
34840+ atomic_inc_unchecked(&idev->event);
34841 wake_up_interruptible(&idev->wait);
34842 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
34843 }
34844@@ -477,7 +478,7 @@ static int uio_open(struct inode *inode,
34845 }
34846
34847 listener->dev = idev;
34848- listener->event_count = atomic_read(&idev->event);
34849+ listener->event_count = atomic_read_unchecked(&idev->event);
34850 filep->private_data = listener;
34851
34852 if (idev->info->open) {
34853@@ -528,7 +529,7 @@ static unsigned int uio_poll(struct file
34854 return -EIO;
34855
34856 poll_wait(filep, &idev->wait, wait);
34857- if (listener->event_count != atomic_read(&idev->event))
34858+ if (listener->event_count != atomic_read_unchecked(&idev->event))
34859 return POLLIN | POLLRDNORM;
34860 return 0;
34861 }
34862@@ -553,7 +554,7 @@ static ssize_t uio_read(struct file *fil
34863 do {
34864 set_current_state(TASK_INTERRUPTIBLE);
34865
34866- event_count = atomic_read(&idev->event);
34867+ event_count = atomic_read_unchecked(&idev->event);
34868 if (event_count != listener->event_count) {
34869 if (copy_to_user(buf, &event_count, count))
34870 retval = -EFAULT;
34871@@ -624,13 +625,13 @@ static int uio_find_mem_index(struct vm_
34872 static void uio_vma_open(struct vm_area_struct *vma)
34873 {
34874 struct uio_device *idev = vma->vm_private_data;
34875- idev->vma_count++;
34876+ local_inc(&idev->vma_count);
34877 }
34878
34879 static void uio_vma_close(struct vm_area_struct *vma)
34880 {
34881 struct uio_device *idev = vma->vm_private_data;
34882- idev->vma_count--;
34883+ local_dec(&idev->vma_count);
34884 }
34885
34886 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
34887@@ -840,7 +841,7 @@ int __uio_register_device(struct module
34888 idev->owner = owner;
34889 idev->info = info;
34890 init_waitqueue_head(&idev->wait);
34891- atomic_set(&idev->event, 0);
34892+ atomic_set_unchecked(&idev->event, 0);
34893
34894 ret = uio_get_minor(idev);
34895 if (ret)
34896diff -urNp linux-2.6.32.41/drivers/usb/atm/usbatm.c linux-2.6.32.41/drivers/usb/atm/usbatm.c
34897--- linux-2.6.32.41/drivers/usb/atm/usbatm.c 2011-03-27 14:31:47.000000000 -0400
34898+++ linux-2.6.32.41/drivers/usb/atm/usbatm.c 2011-04-17 15:56:46.000000000 -0400
34899@@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(stru
34900 if (printk_ratelimit())
34901 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
34902 __func__, vpi, vci);
34903- atomic_inc(&vcc->stats->rx_err);
34904+ atomic_inc_unchecked(&vcc->stats->rx_err);
34905 return;
34906 }
34907
34908@@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(stru
34909 if (length > ATM_MAX_AAL5_PDU) {
34910 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
34911 __func__, length, vcc);
34912- atomic_inc(&vcc->stats->rx_err);
34913+ atomic_inc_unchecked(&vcc->stats->rx_err);
34914 goto out;
34915 }
34916
34917@@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(stru
34918 if (sarb->len < pdu_length) {
34919 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
34920 __func__, pdu_length, sarb->len, vcc);
34921- atomic_inc(&vcc->stats->rx_err);
34922+ atomic_inc_unchecked(&vcc->stats->rx_err);
34923 goto out;
34924 }
34925
34926 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
34927 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
34928 __func__, vcc);
34929- atomic_inc(&vcc->stats->rx_err);
34930+ atomic_inc_unchecked(&vcc->stats->rx_err);
34931 goto out;
34932 }
34933
34934@@ -387,7 +387,7 @@ static void usbatm_extract_one_cell(stru
34935 if (printk_ratelimit())
34936 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
34937 __func__, length);
34938- atomic_inc(&vcc->stats->rx_drop);
34939+ atomic_inc_unchecked(&vcc->stats->rx_drop);
34940 goto out;
34941 }
34942
34943@@ -412,7 +412,7 @@ static void usbatm_extract_one_cell(stru
34944
34945 vcc->push(vcc, skb);
34946
34947- atomic_inc(&vcc->stats->rx);
34948+ atomic_inc_unchecked(&vcc->stats->rx);
34949 out:
34950 skb_trim(sarb, 0);
34951 }
34952@@ -616,7 +616,7 @@ static void usbatm_tx_process(unsigned l
34953 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
34954
34955 usbatm_pop(vcc, skb);
34956- atomic_inc(&vcc->stats->tx);
34957+ atomic_inc_unchecked(&vcc->stats->tx);
34958
34959 skb = skb_dequeue(&instance->sndqueue);
34960 }
34961@@ -775,11 +775,11 @@ static int usbatm_atm_proc_read(struct a
34962 if (!left--)
34963 return sprintf(page,
34964 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
34965- atomic_read(&atm_dev->stats.aal5.tx),
34966- atomic_read(&atm_dev->stats.aal5.tx_err),
34967- atomic_read(&atm_dev->stats.aal5.rx),
34968- atomic_read(&atm_dev->stats.aal5.rx_err),
34969- atomic_read(&atm_dev->stats.aal5.rx_drop));
34970+ atomic_read_unchecked(&atm_dev->stats.aal5.tx),
34971+ atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
34972+ atomic_read_unchecked(&atm_dev->stats.aal5.rx),
34973+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
34974+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
34975
34976 if (!left--) {
34977 if (instance->disconnected)
34978diff -urNp linux-2.6.32.41/drivers/usb/class/cdc-wdm.c linux-2.6.32.41/drivers/usb/class/cdc-wdm.c
34979--- linux-2.6.32.41/drivers/usb/class/cdc-wdm.c 2011-03-27 14:31:47.000000000 -0400
34980+++ linux-2.6.32.41/drivers/usb/class/cdc-wdm.c 2011-04-17 15:56:46.000000000 -0400
34981@@ -314,7 +314,7 @@ static ssize_t wdm_write
34982 if (r < 0)
34983 goto outnp;
34984
34985- if (!file->f_flags && O_NONBLOCK)
34986+ if (!(file->f_flags & O_NONBLOCK))
34987 r = wait_event_interruptible(desc->wait, !test_bit(WDM_IN_USE,
34988 &desc->flags));
34989 else
34990diff -urNp linux-2.6.32.41/drivers/usb/core/hcd.c linux-2.6.32.41/drivers/usb/core/hcd.c
34991--- linux-2.6.32.41/drivers/usb/core/hcd.c 2011-03-27 14:31:47.000000000 -0400
34992+++ linux-2.6.32.41/drivers/usb/core/hcd.c 2011-04-17 15:56:46.000000000 -0400
34993@@ -2216,7 +2216,7 @@ EXPORT_SYMBOL_GPL(usb_hcd_platform_shutd
34994
34995 #if defined(CONFIG_USB_MON) || defined(CONFIG_USB_MON_MODULE)
34996
34997-struct usb_mon_operations *mon_ops;
34998+const struct usb_mon_operations *mon_ops;
34999
35000 /*
35001 * The registration is unlocked.
35002@@ -2226,7 +2226,7 @@ struct usb_mon_operations *mon_ops;
35003 * symbols from usbcore, usbcore gets referenced and cannot be unloaded first.
35004 */
35005
35006-int usb_mon_register (struct usb_mon_operations *ops)
35007+int usb_mon_register (const struct usb_mon_operations *ops)
35008 {
35009
35010 if (mon_ops)
35011diff -urNp linux-2.6.32.41/drivers/usb/core/hcd.h linux-2.6.32.41/drivers/usb/core/hcd.h
35012--- linux-2.6.32.41/drivers/usb/core/hcd.h 2011-03-27 14:31:47.000000000 -0400
35013+++ linux-2.6.32.41/drivers/usb/core/hcd.h 2011-04-17 15:56:46.000000000 -0400
35014@@ -486,13 +486,13 @@ static inline void usbfs_cleanup(void) {
35015 #if defined(CONFIG_USB_MON) || defined(CONFIG_USB_MON_MODULE)
35016
35017 struct usb_mon_operations {
35018- void (*urb_submit)(struct usb_bus *bus, struct urb *urb);
35019- void (*urb_submit_error)(struct usb_bus *bus, struct urb *urb, int err);
35020- void (*urb_complete)(struct usb_bus *bus, struct urb *urb, int status);
35021+ void (* const urb_submit)(struct usb_bus *bus, struct urb *urb);
35022+ void (* const urb_submit_error)(struct usb_bus *bus, struct urb *urb, int err);
35023+ void (* const urb_complete)(struct usb_bus *bus, struct urb *urb, int status);
35024 /* void (*urb_unlink)(struct usb_bus *bus, struct urb *urb); */
35025 };
35026
35027-extern struct usb_mon_operations *mon_ops;
35028+extern const struct usb_mon_operations *mon_ops;
35029
35030 static inline void usbmon_urb_submit(struct usb_bus *bus, struct urb *urb)
35031 {
35032@@ -514,7 +514,7 @@ static inline void usbmon_urb_complete(s
35033 (*mon_ops->urb_complete)(bus, urb, status);
35034 }
35035
35036-int usb_mon_register(struct usb_mon_operations *ops);
35037+int usb_mon_register(const struct usb_mon_operations *ops);
35038 void usb_mon_deregister(void);
35039
35040 #else
35041diff -urNp linux-2.6.32.41/drivers/usb/core/message.c linux-2.6.32.41/drivers/usb/core/message.c
35042--- linux-2.6.32.41/drivers/usb/core/message.c 2011-03-27 14:31:47.000000000 -0400
35043+++ linux-2.6.32.41/drivers/usb/core/message.c 2011-04-17 15:56:46.000000000 -0400
35044@@ -914,8 +914,8 @@ char *usb_cache_string(struct usb_device
35045 buf = kmalloc(MAX_USB_STRING_SIZE, GFP_NOIO);
35046 if (buf) {
35047 len = usb_string(udev, index, buf, MAX_USB_STRING_SIZE);
35048- if (len > 0) {
35049- smallbuf = kmalloc(++len, GFP_NOIO);
35050+ if (len++ > 0) {
35051+ smallbuf = kmalloc(len, GFP_NOIO);
35052 if (!smallbuf)
35053 return buf;
35054 memcpy(smallbuf, buf, len);
35055diff -urNp linux-2.6.32.41/drivers/usb/misc/appledisplay.c linux-2.6.32.41/drivers/usb/misc/appledisplay.c
35056--- linux-2.6.32.41/drivers/usb/misc/appledisplay.c 2011-03-27 14:31:47.000000000 -0400
35057+++ linux-2.6.32.41/drivers/usb/misc/appledisplay.c 2011-04-17 15:56:46.000000000 -0400
35058@@ -178,7 +178,7 @@ static int appledisplay_bl_get_brightnes
35059 return pdata->msgdata[1];
35060 }
35061
35062-static struct backlight_ops appledisplay_bl_data = {
35063+static const struct backlight_ops appledisplay_bl_data = {
35064 .get_brightness = appledisplay_bl_get_brightness,
35065 .update_status = appledisplay_bl_update_status,
35066 };
35067diff -urNp linux-2.6.32.41/drivers/usb/mon/mon_main.c linux-2.6.32.41/drivers/usb/mon/mon_main.c
35068--- linux-2.6.32.41/drivers/usb/mon/mon_main.c 2011-03-27 14:31:47.000000000 -0400
35069+++ linux-2.6.32.41/drivers/usb/mon/mon_main.c 2011-04-17 15:56:46.000000000 -0400
35070@@ -238,7 +238,7 @@ static struct notifier_block mon_nb = {
35071 /*
35072 * Ops
35073 */
35074-static struct usb_mon_operations mon_ops_0 = {
35075+static const struct usb_mon_operations mon_ops_0 = {
35076 .urb_submit = mon_submit,
35077 .urb_submit_error = mon_submit_error,
35078 .urb_complete = mon_complete,
35079diff -urNp linux-2.6.32.41/drivers/usb/wusbcore/wa-hc.h linux-2.6.32.41/drivers/usb/wusbcore/wa-hc.h
35080--- linux-2.6.32.41/drivers/usb/wusbcore/wa-hc.h 2011-03-27 14:31:47.000000000 -0400
35081+++ linux-2.6.32.41/drivers/usb/wusbcore/wa-hc.h 2011-05-04 17:56:28.000000000 -0400
35082@@ -192,7 +192,7 @@ struct wahc {
35083 struct list_head xfer_delayed_list;
35084 spinlock_t xfer_list_lock;
35085 struct work_struct xfer_work;
35086- atomic_t xfer_id_count;
35087+ atomic_unchecked_t xfer_id_count;
35088 };
35089
35090
35091@@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *
35092 INIT_LIST_HEAD(&wa->xfer_delayed_list);
35093 spin_lock_init(&wa->xfer_list_lock);
35094 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
35095- atomic_set(&wa->xfer_id_count, 1);
35096+ atomic_set_unchecked(&wa->xfer_id_count, 1);
35097 }
35098
35099 /**
35100diff -urNp linux-2.6.32.41/drivers/usb/wusbcore/wa-xfer.c linux-2.6.32.41/drivers/usb/wusbcore/wa-xfer.c
35101--- linux-2.6.32.41/drivers/usb/wusbcore/wa-xfer.c 2011-03-27 14:31:47.000000000 -0400
35102+++ linux-2.6.32.41/drivers/usb/wusbcore/wa-xfer.c 2011-05-04 17:56:28.000000000 -0400
35103@@ -293,7 +293,7 @@ out:
35104 */
35105 static void wa_xfer_id_init(struct wa_xfer *xfer)
35106 {
35107- xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
35108+ xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
35109 }
35110
35111 /*
35112diff -urNp linux-2.6.32.41/drivers/uwb/wlp/messages.c linux-2.6.32.41/drivers/uwb/wlp/messages.c
35113--- linux-2.6.32.41/drivers/uwb/wlp/messages.c 2011-03-27 14:31:47.000000000 -0400
35114+++ linux-2.6.32.41/drivers/uwb/wlp/messages.c 2011-04-17 15:56:46.000000000 -0400
35115@@ -903,7 +903,7 @@ int wlp_parse_f0(struct wlp *wlp, struct
35116 size_t len = skb->len;
35117 size_t used;
35118 ssize_t result;
35119- struct wlp_nonce enonce, rnonce;
35120+ struct wlp_nonce enonce = {{0}}, rnonce = {{0}};
35121 enum wlp_assc_error assc_err;
35122 char enonce_buf[WLP_WSS_NONCE_STRSIZE];
35123 char rnonce_buf[WLP_WSS_NONCE_STRSIZE];
35124diff -urNp linux-2.6.32.41/drivers/uwb/wlp/sysfs.c linux-2.6.32.41/drivers/uwb/wlp/sysfs.c
35125--- linux-2.6.32.41/drivers/uwb/wlp/sysfs.c 2011-03-27 14:31:47.000000000 -0400
35126+++ linux-2.6.32.41/drivers/uwb/wlp/sysfs.c 2011-04-17 15:56:46.000000000 -0400
35127@@ -615,8 +615,7 @@ ssize_t wlp_wss_attr_store(struct kobjec
35128 return ret;
35129 }
35130
35131-static
35132-struct sysfs_ops wss_sysfs_ops = {
35133+static const struct sysfs_ops wss_sysfs_ops = {
35134 .show = wlp_wss_attr_show,
35135 .store = wlp_wss_attr_store,
35136 };
35137diff -urNp linux-2.6.32.41/drivers/video/atmel_lcdfb.c linux-2.6.32.41/drivers/video/atmel_lcdfb.c
35138--- linux-2.6.32.41/drivers/video/atmel_lcdfb.c 2011-03-27 14:31:47.000000000 -0400
35139+++ linux-2.6.32.41/drivers/video/atmel_lcdfb.c 2011-04-17 15:56:46.000000000 -0400
35140@@ -110,7 +110,7 @@ static int atmel_bl_get_brightness(struc
35141 return lcdc_readl(sinfo, ATMEL_LCDC_CONTRAST_VAL);
35142 }
35143
35144-static struct backlight_ops atmel_lcdc_bl_ops = {
35145+static const struct backlight_ops atmel_lcdc_bl_ops = {
35146 .update_status = atmel_bl_update_status,
35147 .get_brightness = atmel_bl_get_brightness,
35148 };
35149diff -urNp linux-2.6.32.41/drivers/video/aty/aty128fb.c linux-2.6.32.41/drivers/video/aty/aty128fb.c
35150--- linux-2.6.32.41/drivers/video/aty/aty128fb.c 2011-03-27 14:31:47.000000000 -0400
35151+++ linux-2.6.32.41/drivers/video/aty/aty128fb.c 2011-04-17 15:56:46.000000000 -0400
35152@@ -1787,7 +1787,7 @@ static int aty128_bl_get_brightness(stru
35153 return bd->props.brightness;
35154 }
35155
35156-static struct backlight_ops aty128_bl_data = {
35157+static const struct backlight_ops aty128_bl_data = {
35158 .get_brightness = aty128_bl_get_brightness,
35159 .update_status = aty128_bl_update_status,
35160 };
35161diff -urNp linux-2.6.32.41/drivers/video/aty/atyfb_base.c linux-2.6.32.41/drivers/video/aty/atyfb_base.c
35162--- linux-2.6.32.41/drivers/video/aty/atyfb_base.c 2011-03-27 14:31:47.000000000 -0400
35163+++ linux-2.6.32.41/drivers/video/aty/atyfb_base.c 2011-04-17 15:56:46.000000000 -0400
35164@@ -2225,7 +2225,7 @@ static int aty_bl_get_brightness(struct
35165 return bd->props.brightness;
35166 }
35167
35168-static struct backlight_ops aty_bl_data = {
35169+static const struct backlight_ops aty_bl_data = {
35170 .get_brightness = aty_bl_get_brightness,
35171 .update_status = aty_bl_update_status,
35172 };
35173diff -urNp linux-2.6.32.41/drivers/video/aty/radeon_backlight.c linux-2.6.32.41/drivers/video/aty/radeon_backlight.c
35174--- linux-2.6.32.41/drivers/video/aty/radeon_backlight.c 2011-03-27 14:31:47.000000000 -0400
35175+++ linux-2.6.32.41/drivers/video/aty/radeon_backlight.c 2011-04-17 15:56:46.000000000 -0400
35176@@ -127,7 +127,7 @@ static int radeon_bl_get_brightness(stru
35177 return bd->props.brightness;
35178 }
35179
35180-static struct backlight_ops radeon_bl_data = {
35181+static const struct backlight_ops radeon_bl_data = {
35182 .get_brightness = radeon_bl_get_brightness,
35183 .update_status = radeon_bl_update_status,
35184 };
35185diff -urNp linux-2.6.32.41/drivers/video/backlight/adp5520_bl.c linux-2.6.32.41/drivers/video/backlight/adp5520_bl.c
35186--- linux-2.6.32.41/drivers/video/backlight/adp5520_bl.c 2011-03-27 14:31:47.000000000 -0400
35187+++ linux-2.6.32.41/drivers/video/backlight/adp5520_bl.c 2011-04-17 15:56:46.000000000 -0400
35188@@ -84,7 +84,7 @@ static int adp5520_bl_get_brightness(str
35189 return error ? data->current_brightness : reg_val;
35190 }
35191
35192-static struct backlight_ops adp5520_bl_ops = {
35193+static const struct backlight_ops adp5520_bl_ops = {
35194 .update_status = adp5520_bl_update_status,
35195 .get_brightness = adp5520_bl_get_brightness,
35196 };
35197diff -urNp linux-2.6.32.41/drivers/video/backlight/adx_bl.c linux-2.6.32.41/drivers/video/backlight/adx_bl.c
35198--- linux-2.6.32.41/drivers/video/backlight/adx_bl.c 2011-03-27 14:31:47.000000000 -0400
35199+++ linux-2.6.32.41/drivers/video/backlight/adx_bl.c 2011-04-17 15:56:46.000000000 -0400
35200@@ -61,7 +61,7 @@ static int adx_backlight_check_fb(struct
35201 return 1;
35202 }
35203
35204-static struct backlight_ops adx_backlight_ops = {
35205+static const struct backlight_ops adx_backlight_ops = {
35206 .options = 0,
35207 .update_status = adx_backlight_update_status,
35208 .get_brightness = adx_backlight_get_brightness,
35209diff -urNp linux-2.6.32.41/drivers/video/backlight/atmel-pwm-bl.c linux-2.6.32.41/drivers/video/backlight/atmel-pwm-bl.c
35210--- linux-2.6.32.41/drivers/video/backlight/atmel-pwm-bl.c 2011-03-27 14:31:47.000000000 -0400
35211+++ linux-2.6.32.41/drivers/video/backlight/atmel-pwm-bl.c 2011-04-17 15:56:46.000000000 -0400
35212@@ -113,7 +113,7 @@ static int atmel_pwm_bl_init_pwm(struct
35213 return pwm_channel_enable(&pwmbl->pwmc);
35214 }
35215
35216-static struct backlight_ops atmel_pwm_bl_ops = {
35217+static const struct backlight_ops atmel_pwm_bl_ops = {
35218 .get_brightness = atmel_pwm_bl_get_intensity,
35219 .update_status = atmel_pwm_bl_set_intensity,
35220 };
35221diff -urNp linux-2.6.32.41/drivers/video/backlight/backlight.c linux-2.6.32.41/drivers/video/backlight/backlight.c
35222--- linux-2.6.32.41/drivers/video/backlight/backlight.c 2011-03-27 14:31:47.000000000 -0400
35223+++ linux-2.6.32.41/drivers/video/backlight/backlight.c 2011-04-17 15:56:46.000000000 -0400
35224@@ -269,7 +269,7 @@ EXPORT_SYMBOL(backlight_force_update);
35225 * ERR_PTR() or a pointer to the newly allocated device.
35226 */
35227 struct backlight_device *backlight_device_register(const char *name,
35228- struct device *parent, void *devdata, struct backlight_ops *ops)
35229+ struct device *parent, void *devdata, const struct backlight_ops *ops)
35230 {
35231 struct backlight_device *new_bd;
35232 int rc;
35233diff -urNp linux-2.6.32.41/drivers/video/backlight/corgi_lcd.c linux-2.6.32.41/drivers/video/backlight/corgi_lcd.c
35234--- linux-2.6.32.41/drivers/video/backlight/corgi_lcd.c 2011-03-27 14:31:47.000000000 -0400
35235+++ linux-2.6.32.41/drivers/video/backlight/corgi_lcd.c 2011-04-17 15:56:46.000000000 -0400
35236@@ -451,7 +451,7 @@ void corgi_lcd_limit_intensity(int limit
35237 }
35238 EXPORT_SYMBOL(corgi_lcd_limit_intensity);
35239
35240-static struct backlight_ops corgi_bl_ops = {
35241+static const struct backlight_ops corgi_bl_ops = {
35242 .get_brightness = corgi_bl_get_intensity,
35243 .update_status = corgi_bl_update_status,
35244 };
35245diff -urNp linux-2.6.32.41/drivers/video/backlight/cr_bllcd.c linux-2.6.32.41/drivers/video/backlight/cr_bllcd.c
35246--- linux-2.6.32.41/drivers/video/backlight/cr_bllcd.c 2011-03-27 14:31:47.000000000 -0400
35247+++ linux-2.6.32.41/drivers/video/backlight/cr_bllcd.c 2011-04-17 15:56:46.000000000 -0400
35248@@ -108,7 +108,7 @@ static int cr_backlight_get_intensity(st
35249 return intensity;
35250 }
35251
35252-static struct backlight_ops cr_backlight_ops = {
35253+static const struct backlight_ops cr_backlight_ops = {
35254 .get_brightness = cr_backlight_get_intensity,
35255 .update_status = cr_backlight_set_intensity,
35256 };
35257diff -urNp linux-2.6.32.41/drivers/video/backlight/da903x_bl.c linux-2.6.32.41/drivers/video/backlight/da903x_bl.c
35258--- linux-2.6.32.41/drivers/video/backlight/da903x_bl.c 2011-03-27 14:31:47.000000000 -0400
35259+++ linux-2.6.32.41/drivers/video/backlight/da903x_bl.c 2011-04-17 15:56:46.000000000 -0400
35260@@ -94,7 +94,7 @@ static int da903x_backlight_get_brightne
35261 return data->current_brightness;
35262 }
35263
35264-static struct backlight_ops da903x_backlight_ops = {
35265+static const struct backlight_ops da903x_backlight_ops = {
35266 .update_status = da903x_backlight_update_status,
35267 .get_brightness = da903x_backlight_get_brightness,
35268 };
35269diff -urNp linux-2.6.32.41/drivers/video/backlight/generic_bl.c linux-2.6.32.41/drivers/video/backlight/generic_bl.c
35270--- linux-2.6.32.41/drivers/video/backlight/generic_bl.c 2011-03-27 14:31:47.000000000 -0400
35271+++ linux-2.6.32.41/drivers/video/backlight/generic_bl.c 2011-04-17 15:56:46.000000000 -0400
35272@@ -70,7 +70,7 @@ void corgibl_limit_intensity(int limit)
35273 }
35274 EXPORT_SYMBOL(corgibl_limit_intensity);
35275
35276-static struct backlight_ops genericbl_ops = {
35277+static const struct backlight_ops genericbl_ops = {
35278 .options = BL_CORE_SUSPENDRESUME,
35279 .get_brightness = genericbl_get_intensity,
35280 .update_status = genericbl_send_intensity,
35281diff -urNp linux-2.6.32.41/drivers/video/backlight/hp680_bl.c linux-2.6.32.41/drivers/video/backlight/hp680_bl.c
35282--- linux-2.6.32.41/drivers/video/backlight/hp680_bl.c 2011-03-27 14:31:47.000000000 -0400
35283+++ linux-2.6.32.41/drivers/video/backlight/hp680_bl.c 2011-04-17 15:56:46.000000000 -0400
35284@@ -98,7 +98,7 @@ static int hp680bl_get_intensity(struct
35285 return current_intensity;
35286 }
35287
35288-static struct backlight_ops hp680bl_ops = {
35289+static const struct backlight_ops hp680bl_ops = {
35290 .get_brightness = hp680bl_get_intensity,
35291 .update_status = hp680bl_set_intensity,
35292 };
35293diff -urNp linux-2.6.32.41/drivers/video/backlight/jornada720_bl.c linux-2.6.32.41/drivers/video/backlight/jornada720_bl.c
35294--- linux-2.6.32.41/drivers/video/backlight/jornada720_bl.c 2011-03-27 14:31:47.000000000 -0400
35295+++ linux-2.6.32.41/drivers/video/backlight/jornada720_bl.c 2011-04-17 15:56:46.000000000 -0400
35296@@ -93,7 +93,7 @@ out:
35297 return ret;
35298 }
35299
35300-static struct backlight_ops jornada_bl_ops = {
35301+static const struct backlight_ops jornada_bl_ops = {
35302 .get_brightness = jornada_bl_get_brightness,
35303 .update_status = jornada_bl_update_status,
35304 .options = BL_CORE_SUSPENDRESUME,
35305diff -urNp linux-2.6.32.41/drivers/video/backlight/kb3886_bl.c linux-2.6.32.41/drivers/video/backlight/kb3886_bl.c
35306--- linux-2.6.32.41/drivers/video/backlight/kb3886_bl.c 2011-03-27 14:31:47.000000000 -0400
35307+++ linux-2.6.32.41/drivers/video/backlight/kb3886_bl.c 2011-04-17 15:56:46.000000000 -0400
35308@@ -134,7 +134,7 @@ static int kb3886bl_get_intensity(struct
35309 return kb3886bl_intensity;
35310 }
35311
35312-static struct backlight_ops kb3886bl_ops = {
35313+static const struct backlight_ops kb3886bl_ops = {
35314 .get_brightness = kb3886bl_get_intensity,
35315 .update_status = kb3886bl_send_intensity,
35316 };
35317diff -urNp linux-2.6.32.41/drivers/video/backlight/locomolcd.c linux-2.6.32.41/drivers/video/backlight/locomolcd.c
35318--- linux-2.6.32.41/drivers/video/backlight/locomolcd.c 2011-03-27 14:31:47.000000000 -0400
35319+++ linux-2.6.32.41/drivers/video/backlight/locomolcd.c 2011-04-17 15:56:46.000000000 -0400
35320@@ -141,7 +141,7 @@ static int locomolcd_get_intensity(struc
35321 return current_intensity;
35322 }
35323
35324-static struct backlight_ops locomobl_data = {
35325+static const struct backlight_ops locomobl_data = {
35326 .get_brightness = locomolcd_get_intensity,
35327 .update_status = locomolcd_set_intensity,
35328 };
35329diff -urNp linux-2.6.32.41/drivers/video/backlight/mbp_nvidia_bl.c linux-2.6.32.41/drivers/video/backlight/mbp_nvidia_bl.c
35330--- linux-2.6.32.41/drivers/video/backlight/mbp_nvidia_bl.c 2011-05-10 22:12:01.000000000 -0400
35331+++ linux-2.6.32.41/drivers/video/backlight/mbp_nvidia_bl.c 2011-05-10 22:12:33.000000000 -0400
35332@@ -33,7 +33,7 @@ struct dmi_match_data {
35333 unsigned long iostart;
35334 unsigned long iolen;
35335 /* Backlight operations structure. */
35336- struct backlight_ops backlight_ops;
35337+ const struct backlight_ops backlight_ops;
35338 };
35339
35340 /* Module parameters. */
35341diff -urNp linux-2.6.32.41/drivers/video/backlight/omap1_bl.c linux-2.6.32.41/drivers/video/backlight/omap1_bl.c
35342--- linux-2.6.32.41/drivers/video/backlight/omap1_bl.c 2011-03-27 14:31:47.000000000 -0400
35343+++ linux-2.6.32.41/drivers/video/backlight/omap1_bl.c 2011-04-17 15:56:46.000000000 -0400
35344@@ -125,7 +125,7 @@ static int omapbl_get_intensity(struct b
35345 return bl->current_intensity;
35346 }
35347
35348-static struct backlight_ops omapbl_ops = {
35349+static const struct backlight_ops omapbl_ops = {
35350 .get_brightness = omapbl_get_intensity,
35351 .update_status = omapbl_update_status,
35352 };
35353diff -urNp linux-2.6.32.41/drivers/video/backlight/progear_bl.c linux-2.6.32.41/drivers/video/backlight/progear_bl.c
35354--- linux-2.6.32.41/drivers/video/backlight/progear_bl.c 2011-03-27 14:31:47.000000000 -0400
35355+++ linux-2.6.32.41/drivers/video/backlight/progear_bl.c 2011-04-17 15:56:46.000000000 -0400
35356@@ -54,7 +54,7 @@ static int progearbl_get_intensity(struc
35357 return intensity - HW_LEVEL_MIN;
35358 }
35359
35360-static struct backlight_ops progearbl_ops = {
35361+static const struct backlight_ops progearbl_ops = {
35362 .get_brightness = progearbl_get_intensity,
35363 .update_status = progearbl_set_intensity,
35364 };
35365diff -urNp linux-2.6.32.41/drivers/video/backlight/pwm_bl.c linux-2.6.32.41/drivers/video/backlight/pwm_bl.c
35366--- linux-2.6.32.41/drivers/video/backlight/pwm_bl.c 2011-03-27 14:31:47.000000000 -0400
35367+++ linux-2.6.32.41/drivers/video/backlight/pwm_bl.c 2011-04-17 15:56:46.000000000 -0400
35368@@ -56,7 +56,7 @@ static int pwm_backlight_get_brightness(
35369 return bl->props.brightness;
35370 }
35371
35372-static struct backlight_ops pwm_backlight_ops = {
35373+static const struct backlight_ops pwm_backlight_ops = {
35374 .update_status = pwm_backlight_update_status,
35375 .get_brightness = pwm_backlight_get_brightness,
35376 };
35377diff -urNp linux-2.6.32.41/drivers/video/backlight/tosa_bl.c linux-2.6.32.41/drivers/video/backlight/tosa_bl.c
35378--- linux-2.6.32.41/drivers/video/backlight/tosa_bl.c 2011-03-27 14:31:47.000000000 -0400
35379+++ linux-2.6.32.41/drivers/video/backlight/tosa_bl.c 2011-04-17 15:56:46.000000000 -0400
35380@@ -72,7 +72,7 @@ static int tosa_bl_get_brightness(struct
35381 return props->brightness;
35382 }
35383
35384-static struct backlight_ops bl_ops = {
35385+static const struct backlight_ops bl_ops = {
35386 .get_brightness = tosa_bl_get_brightness,
35387 .update_status = tosa_bl_update_status,
35388 };
35389diff -urNp linux-2.6.32.41/drivers/video/backlight/wm831x_bl.c linux-2.6.32.41/drivers/video/backlight/wm831x_bl.c
35390--- linux-2.6.32.41/drivers/video/backlight/wm831x_bl.c 2011-03-27 14:31:47.000000000 -0400
35391+++ linux-2.6.32.41/drivers/video/backlight/wm831x_bl.c 2011-04-17 15:56:46.000000000 -0400
35392@@ -112,7 +112,7 @@ static int wm831x_backlight_get_brightne
35393 return data->current_brightness;
35394 }
35395
35396-static struct backlight_ops wm831x_backlight_ops = {
35397+static const struct backlight_ops wm831x_backlight_ops = {
35398 .options = BL_CORE_SUSPENDRESUME,
35399 .update_status = wm831x_backlight_update_status,
35400 .get_brightness = wm831x_backlight_get_brightness,
35401diff -urNp linux-2.6.32.41/drivers/video/bf54x-lq043fb.c linux-2.6.32.41/drivers/video/bf54x-lq043fb.c
35402--- linux-2.6.32.41/drivers/video/bf54x-lq043fb.c 2011-03-27 14:31:47.000000000 -0400
35403+++ linux-2.6.32.41/drivers/video/bf54x-lq043fb.c 2011-04-17 15:56:46.000000000 -0400
35404@@ -463,7 +463,7 @@ static int bl_get_brightness(struct back
35405 return 0;
35406 }
35407
35408-static struct backlight_ops bfin_lq043fb_bl_ops = {
35409+static const struct backlight_ops bfin_lq043fb_bl_ops = {
35410 .get_brightness = bl_get_brightness,
35411 };
35412
35413diff -urNp linux-2.6.32.41/drivers/video/bfin-t350mcqb-fb.c linux-2.6.32.41/drivers/video/bfin-t350mcqb-fb.c
35414--- linux-2.6.32.41/drivers/video/bfin-t350mcqb-fb.c 2011-03-27 14:31:47.000000000 -0400
35415+++ linux-2.6.32.41/drivers/video/bfin-t350mcqb-fb.c 2011-04-17 15:56:46.000000000 -0400
35416@@ -381,7 +381,7 @@ static int bl_get_brightness(struct back
35417 return 0;
35418 }
35419
35420-static struct backlight_ops bfin_lq043fb_bl_ops = {
35421+static const struct backlight_ops bfin_lq043fb_bl_ops = {
35422 .get_brightness = bl_get_brightness,
35423 };
35424
35425diff -urNp linux-2.6.32.41/drivers/video/fbcmap.c linux-2.6.32.41/drivers/video/fbcmap.c
35426--- linux-2.6.32.41/drivers/video/fbcmap.c 2011-03-27 14:31:47.000000000 -0400
35427+++ linux-2.6.32.41/drivers/video/fbcmap.c 2011-04-17 15:56:46.000000000 -0400
35428@@ -266,8 +266,7 @@ int fb_set_user_cmap(struct fb_cmap_user
35429 rc = -ENODEV;
35430 goto out;
35431 }
35432- if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
35433- !info->fbops->fb_setcmap)) {
35434+ if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
35435 rc = -EINVAL;
35436 goto out1;
35437 }
35438diff -urNp linux-2.6.32.41/drivers/video/fbmem.c linux-2.6.32.41/drivers/video/fbmem.c
35439--- linux-2.6.32.41/drivers/video/fbmem.c 2011-03-27 14:31:47.000000000 -0400
35440+++ linux-2.6.32.41/drivers/video/fbmem.c 2011-05-16 21:46:57.000000000 -0400
35441@@ -403,7 +403,7 @@ static void fb_do_show_logo(struct fb_in
35442 image->dx += image->width + 8;
35443 }
35444 } else if (rotate == FB_ROTATE_UD) {
35445- for (x = 0; x < num && image->dx >= 0; x++) {
35446+ for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
35447 info->fbops->fb_imageblit(info, image);
35448 image->dx -= image->width + 8;
35449 }
35450@@ -415,7 +415,7 @@ static void fb_do_show_logo(struct fb_in
35451 image->dy += image->height + 8;
35452 }
35453 } else if (rotate == FB_ROTATE_CCW) {
35454- for (x = 0; x < num && image->dy >= 0; x++) {
35455+ for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
35456 info->fbops->fb_imageblit(info, image);
35457 image->dy -= image->height + 8;
35458 }
35459@@ -915,6 +915,8 @@ fb_set_var(struct fb_info *info, struct
35460 int flags = info->flags;
35461 int ret = 0;
35462
35463+ pax_track_stack();
35464+
35465 if (var->activate & FB_ACTIVATE_INV_MODE) {
35466 struct fb_videomode mode1, mode2;
35467
35468@@ -1040,6 +1042,8 @@ static long do_fb_ioctl(struct fb_info *
35469 void __user *argp = (void __user *)arg;
35470 long ret = 0;
35471
35472+ pax_track_stack();
35473+
35474 switch (cmd) {
35475 case FBIOGET_VSCREENINFO:
35476 if (!lock_fb_info(info))
35477@@ -1119,7 +1123,7 @@ static long do_fb_ioctl(struct fb_info *
35478 return -EFAULT;
35479 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
35480 return -EINVAL;
35481- if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
35482+ if (con2fb.framebuffer >= FB_MAX)
35483 return -EINVAL;
35484 if (!registered_fb[con2fb.framebuffer])
35485 request_module("fb%d", con2fb.framebuffer);
35486diff -urNp linux-2.6.32.41/drivers/video/i810/i810_accel.c linux-2.6.32.41/drivers/video/i810/i810_accel.c
35487--- linux-2.6.32.41/drivers/video/i810/i810_accel.c 2011-03-27 14:31:47.000000000 -0400
35488+++ linux-2.6.32.41/drivers/video/i810/i810_accel.c 2011-04-17 15:56:46.000000000 -0400
35489@@ -73,6 +73,7 @@ static inline int wait_for_space(struct
35490 }
35491 }
35492 printk("ringbuffer lockup!!!\n");
35493+ printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
35494 i810_report_error(mmio);
35495 par->dev_flags |= LOCKUP;
35496 info->pixmap.scan_align = 1;
35497diff -urNp linux-2.6.32.41/drivers/video/nvidia/nv_backlight.c linux-2.6.32.41/drivers/video/nvidia/nv_backlight.c
35498--- linux-2.6.32.41/drivers/video/nvidia/nv_backlight.c 2011-03-27 14:31:47.000000000 -0400
35499+++ linux-2.6.32.41/drivers/video/nvidia/nv_backlight.c 2011-04-17 15:56:46.000000000 -0400
35500@@ -87,7 +87,7 @@ static int nvidia_bl_get_brightness(stru
35501 return bd->props.brightness;
35502 }
35503
35504-static struct backlight_ops nvidia_bl_ops = {
35505+static const struct backlight_ops nvidia_bl_ops = {
35506 .get_brightness = nvidia_bl_get_brightness,
35507 .update_status = nvidia_bl_update_status,
35508 };
35509diff -urNp linux-2.6.32.41/drivers/video/riva/fbdev.c linux-2.6.32.41/drivers/video/riva/fbdev.c
35510--- linux-2.6.32.41/drivers/video/riva/fbdev.c 2011-03-27 14:31:47.000000000 -0400
35511+++ linux-2.6.32.41/drivers/video/riva/fbdev.c 2011-04-17 15:56:46.000000000 -0400
35512@@ -331,7 +331,7 @@ static int riva_bl_get_brightness(struct
35513 return bd->props.brightness;
35514 }
35515
35516-static struct backlight_ops riva_bl_ops = {
35517+static const struct backlight_ops riva_bl_ops = {
35518 .get_brightness = riva_bl_get_brightness,
35519 .update_status = riva_bl_update_status,
35520 };
35521diff -urNp linux-2.6.32.41/drivers/video/uvesafb.c linux-2.6.32.41/drivers/video/uvesafb.c
35522--- linux-2.6.32.41/drivers/video/uvesafb.c 2011-03-27 14:31:47.000000000 -0400
35523+++ linux-2.6.32.41/drivers/video/uvesafb.c 2011-04-17 15:56:46.000000000 -0400
35524@@ -18,6 +18,7 @@
35525 #include <linux/fb.h>
35526 #include <linux/io.h>
35527 #include <linux/mutex.h>
35528+#include <linux/moduleloader.h>
35529 #include <video/edid.h>
35530 #include <video/uvesafb.h>
35531 #ifdef CONFIG_X86
35532@@ -120,7 +121,7 @@ static int uvesafb_helper_start(void)
35533 NULL,
35534 };
35535
35536- return call_usermodehelper(v86d_path, argv, envp, 1);
35537+ return call_usermodehelper(v86d_path, argv, envp, UMH_WAIT_PROC);
35538 }
35539
35540 /*
35541@@ -568,10 +569,32 @@ static int __devinit uvesafb_vbe_getpmi(
35542 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
35543 par->pmi_setpal = par->ypan = 0;
35544 } else {
35545+
35546+#ifdef CONFIG_PAX_KERNEXEC
35547+#ifdef CONFIG_MODULES
35548+ par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
35549+#endif
35550+ if (!par->pmi_code) {
35551+ par->pmi_setpal = par->ypan = 0;
35552+ return 0;
35553+ }
35554+#endif
35555+
35556 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
35557 + task->t.regs.edi);
35558+
35559+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
35560+ pax_open_kernel();
35561+ memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
35562+ pax_close_kernel();
35563+
35564+ par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
35565+ par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
35566+#else
35567 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
35568 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
35569+#endif
35570+
35571 printk(KERN_INFO "uvesafb: protected mode interface info at "
35572 "%04x:%04x\n",
35573 (u16)task->t.regs.es, (u16)task->t.regs.edi);
35574@@ -1799,6 +1822,11 @@ out:
35575 if (par->vbe_modes)
35576 kfree(par->vbe_modes);
35577
35578+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
35579+ if (par->pmi_code)
35580+ module_free_exec(NULL, par->pmi_code);
35581+#endif
35582+
35583 framebuffer_release(info);
35584 return err;
35585 }
35586@@ -1825,6 +1853,12 @@ static int uvesafb_remove(struct platfor
35587 kfree(par->vbe_state_orig);
35588 if (par->vbe_state_saved)
35589 kfree(par->vbe_state_saved);
35590+
35591+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
35592+ if (par->pmi_code)
35593+ module_free_exec(NULL, par->pmi_code);
35594+#endif
35595+
35596 }
35597
35598 framebuffer_release(info);
35599diff -urNp linux-2.6.32.41/drivers/video/vesafb.c linux-2.6.32.41/drivers/video/vesafb.c
35600--- linux-2.6.32.41/drivers/video/vesafb.c 2011-03-27 14:31:47.000000000 -0400
35601+++ linux-2.6.32.41/drivers/video/vesafb.c 2011-04-17 15:56:46.000000000 -0400
35602@@ -9,6 +9,7 @@
35603 */
35604
35605 #include <linux/module.h>
35606+#include <linux/moduleloader.h>
35607 #include <linux/kernel.h>
35608 #include <linux/errno.h>
35609 #include <linux/string.h>
35610@@ -53,8 +54,8 @@ static int vram_remap __initdata; /*
35611 static int vram_total __initdata; /* Set total amount of memory */
35612 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
35613 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
35614-static void (*pmi_start)(void) __read_mostly;
35615-static void (*pmi_pal) (void) __read_mostly;
35616+static void (*pmi_start)(void) __read_only;
35617+static void (*pmi_pal) (void) __read_only;
35618 static int depth __read_mostly;
35619 static int vga_compat __read_mostly;
35620 /* --------------------------------------------------------------------- */
35621@@ -233,6 +234,7 @@ static int __init vesafb_probe(struct pl
35622 unsigned int size_vmode;
35623 unsigned int size_remap;
35624 unsigned int size_total;
35625+ void *pmi_code = NULL;
35626
35627 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
35628 return -ENODEV;
35629@@ -275,10 +277,6 @@ static int __init vesafb_probe(struct pl
35630 size_remap = size_total;
35631 vesafb_fix.smem_len = size_remap;
35632
35633-#ifndef __i386__
35634- screen_info.vesapm_seg = 0;
35635-#endif
35636-
35637 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
35638 printk(KERN_WARNING
35639 "vesafb: cannot reserve video memory at 0x%lx\n",
35640@@ -315,9 +313,21 @@ static int __init vesafb_probe(struct pl
35641 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
35642 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
35643
35644+#ifdef __i386__
35645+
35646+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
35647+ pmi_code = module_alloc_exec(screen_info.vesapm_size);
35648+ if (!pmi_code)
35649+#elif !defined(CONFIG_PAX_KERNEXEC)
35650+ if (0)
35651+#endif
35652+
35653+#endif
35654+ screen_info.vesapm_seg = 0;
35655+
35656 if (screen_info.vesapm_seg) {
35657- printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
35658- screen_info.vesapm_seg,screen_info.vesapm_off);
35659+ printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
35660+ screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
35661 }
35662
35663 if (screen_info.vesapm_seg < 0xc000)
35664@@ -325,9 +335,25 @@ static int __init vesafb_probe(struct pl
35665
35666 if (ypan || pmi_setpal) {
35667 unsigned short *pmi_base;
35668- pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
35669- pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
35670- pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
35671+
35672+ pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
35673+
35674+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
35675+ pax_open_kernel();
35676+ memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
35677+#else
35678+ pmi_code = pmi_base;
35679+#endif
35680+
35681+ pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
35682+ pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
35683+
35684+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
35685+ pmi_start = ktva_ktla(pmi_start);
35686+ pmi_pal = ktva_ktla(pmi_pal);
35687+ pax_close_kernel();
35688+#endif
35689+
35690 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
35691 if (pmi_base[3]) {
35692 printk(KERN_INFO "vesafb: pmi: ports = ");
35693@@ -469,6 +495,11 @@ static int __init vesafb_probe(struct pl
35694 info->node, info->fix.id);
35695 return 0;
35696 err:
35697+
35698+#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
35699+ module_free_exec(NULL, pmi_code);
35700+#endif
35701+
35702 if (info->screen_base)
35703 iounmap(info->screen_base);
35704 framebuffer_release(info);
35705diff -urNp linux-2.6.32.41/drivers/xen/sys-hypervisor.c linux-2.6.32.41/drivers/xen/sys-hypervisor.c
35706--- linux-2.6.32.41/drivers/xen/sys-hypervisor.c 2011-03-27 14:31:47.000000000 -0400
35707+++ linux-2.6.32.41/drivers/xen/sys-hypervisor.c 2011-04-17 15:56:46.000000000 -0400
35708@@ -425,7 +425,7 @@ static ssize_t hyp_sysfs_store(struct ko
35709 return 0;
35710 }
35711
35712-static struct sysfs_ops hyp_sysfs_ops = {
35713+static const struct sysfs_ops hyp_sysfs_ops = {
35714 .show = hyp_sysfs_show,
35715 .store = hyp_sysfs_store,
35716 };
35717diff -urNp linux-2.6.32.41/fs/9p/vfs_inode.c linux-2.6.32.41/fs/9p/vfs_inode.c
35718--- linux-2.6.32.41/fs/9p/vfs_inode.c 2011-03-27 14:31:47.000000000 -0400
35719+++ linux-2.6.32.41/fs/9p/vfs_inode.c 2011-04-17 15:56:46.000000000 -0400
35720@@ -1079,7 +1079,7 @@ static void *v9fs_vfs_follow_link(struct
35721 static void
35722 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
35723 {
35724- char *s = nd_get_link(nd);
35725+ const char *s = nd_get_link(nd);
35726
35727 P9_DPRINTK(P9_DEBUG_VFS, " %s %s\n", dentry->d_name.name,
35728 IS_ERR(s) ? "<error>" : s);
35729diff -urNp linux-2.6.32.41/fs/aio.c linux-2.6.32.41/fs/aio.c
35730--- linux-2.6.32.41/fs/aio.c 2011-03-27 14:31:47.000000000 -0400
35731+++ linux-2.6.32.41/fs/aio.c 2011-06-04 20:40:21.000000000 -0400
35732@@ -115,7 +115,7 @@ static int aio_setup_ring(struct kioctx
35733 size += sizeof(struct io_event) * nr_events;
35734 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
35735
35736- if (nr_pages < 0)
35737+ if (nr_pages <= 0)
35738 return -EINVAL;
35739
35740 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
35741@@ -1089,6 +1089,8 @@ static int read_events(struct kioctx *ct
35742 struct aio_timeout to;
35743 int retry = 0;
35744
35745+ pax_track_stack();
35746+
35747 /* needed to zero any padding within an entry (there shouldn't be
35748 * any, but C is fun!
35749 */
35750@@ -1382,13 +1384,18 @@ static ssize_t aio_fsync(struct kiocb *i
35751 static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb)
35752 {
35753 ssize_t ret;
35754+ struct iovec iovstack;
35755
35756 ret = rw_copy_check_uvector(type, (struct iovec __user *)kiocb->ki_buf,
35757 kiocb->ki_nbytes, 1,
35758- &kiocb->ki_inline_vec, &kiocb->ki_iovec);
35759+ &iovstack, &kiocb->ki_iovec);
35760 if (ret < 0)
35761 goto out;
35762
35763+ if (kiocb->ki_iovec == &iovstack) {
35764+ kiocb->ki_inline_vec = iovstack;
35765+ kiocb->ki_iovec = &kiocb->ki_inline_vec;
35766+ }
35767 kiocb->ki_nr_segs = kiocb->ki_nbytes;
35768 kiocb->ki_cur_seg = 0;
35769 /* ki_nbytes/left now reflect bytes instead of segs */
35770diff -urNp linux-2.6.32.41/fs/attr.c linux-2.6.32.41/fs/attr.c
35771--- linux-2.6.32.41/fs/attr.c 2011-03-27 14:31:47.000000000 -0400
35772+++ linux-2.6.32.41/fs/attr.c 2011-04-17 15:56:46.000000000 -0400
35773@@ -83,6 +83,7 @@ int inode_newsize_ok(const struct inode
35774 unsigned long limit;
35775
35776 limit = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
35777+ gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
35778 if (limit != RLIM_INFINITY && offset > limit)
35779 goto out_sig;
35780 if (offset > inode->i_sb->s_maxbytes)
35781diff -urNp linux-2.6.32.41/fs/autofs/root.c linux-2.6.32.41/fs/autofs/root.c
35782--- linux-2.6.32.41/fs/autofs/root.c 2011-03-27 14:31:47.000000000 -0400
35783+++ linux-2.6.32.41/fs/autofs/root.c 2011-04-17 15:56:46.000000000 -0400
35784@@ -299,7 +299,8 @@ static int autofs_root_symlink(struct in
35785 set_bit(n,sbi->symlink_bitmap);
35786 sl = &sbi->symlink[n];
35787 sl->len = strlen(symname);
35788- sl->data = kmalloc(slsize = sl->len+1, GFP_KERNEL);
35789+ slsize = sl->len+1;
35790+ sl->data = kmalloc(slsize, GFP_KERNEL);
35791 if (!sl->data) {
35792 clear_bit(n,sbi->symlink_bitmap);
35793 unlock_kernel();
35794diff -urNp linux-2.6.32.41/fs/autofs4/symlink.c linux-2.6.32.41/fs/autofs4/symlink.c
35795--- linux-2.6.32.41/fs/autofs4/symlink.c 2011-03-27 14:31:47.000000000 -0400
35796+++ linux-2.6.32.41/fs/autofs4/symlink.c 2011-04-17 15:56:46.000000000 -0400
35797@@ -15,7 +15,7 @@
35798 static void *autofs4_follow_link(struct dentry *dentry, struct nameidata *nd)
35799 {
35800 struct autofs_info *ino = autofs4_dentry_ino(dentry);
35801- nd_set_link(nd, (char *)ino->u.symlink);
35802+ nd_set_link(nd, ino->u.symlink);
35803 return NULL;
35804 }
35805
35806diff -urNp linux-2.6.32.41/fs/befs/linuxvfs.c linux-2.6.32.41/fs/befs/linuxvfs.c
35807--- linux-2.6.32.41/fs/befs/linuxvfs.c 2011-03-27 14:31:47.000000000 -0400
35808+++ linux-2.6.32.41/fs/befs/linuxvfs.c 2011-04-17 15:56:46.000000000 -0400
35809@@ -493,7 +493,7 @@ static void befs_put_link(struct dentry
35810 {
35811 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
35812 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
35813- char *link = nd_get_link(nd);
35814+ const char *link = nd_get_link(nd);
35815 if (!IS_ERR(link))
35816 kfree(link);
35817 }
35818diff -urNp linux-2.6.32.41/fs/binfmt_aout.c linux-2.6.32.41/fs/binfmt_aout.c
35819--- linux-2.6.32.41/fs/binfmt_aout.c 2011-03-27 14:31:47.000000000 -0400
35820+++ linux-2.6.32.41/fs/binfmt_aout.c 2011-04-17 15:56:46.000000000 -0400
35821@@ -16,6 +16,7 @@
35822 #include <linux/string.h>
35823 #include <linux/fs.h>
35824 #include <linux/file.h>
35825+#include <linux/security.h>
35826 #include <linux/stat.h>
35827 #include <linux/fcntl.h>
35828 #include <linux/ptrace.h>
35829@@ -102,6 +103,8 @@ static int aout_core_dump(long signr, st
35830 #endif
35831 # define START_STACK(u) (u.start_stack)
35832
35833+ memset(&dump, 0, sizeof(dump));
35834+
35835 fs = get_fs();
35836 set_fs(KERNEL_DS);
35837 has_dumped = 1;
35838@@ -113,10 +116,12 @@ static int aout_core_dump(long signr, st
35839
35840 /* If the size of the dump file exceeds the rlimit, then see what would happen
35841 if we wrote the stack, but not the data area. */
35842+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
35843 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > limit)
35844 dump.u_dsize = 0;
35845
35846 /* Make sure we have enough room to write the stack and data areas. */
35847+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
35848 if ((dump.u_ssize + 1) * PAGE_SIZE > limit)
35849 dump.u_ssize = 0;
35850
35851@@ -146,9 +151,7 @@ static int aout_core_dump(long signr, st
35852 dump_size = dump.u_ssize << PAGE_SHIFT;
35853 DUMP_WRITE(dump_start,dump_size);
35854 }
35855-/* Finally dump the task struct. Not be used by gdb, but could be useful */
35856- set_fs(KERNEL_DS);
35857- DUMP_WRITE(current,sizeof(*current));
35858+/* Finally, let's not dump the task struct. Not be used by gdb, but could be useful to an attacker */
35859 end_coredump:
35860 set_fs(fs);
35861 return has_dumped;
35862@@ -249,6 +252,8 @@ static int load_aout_binary(struct linux
35863 rlim = current->signal->rlim[RLIMIT_DATA].rlim_cur;
35864 if (rlim >= RLIM_INFINITY)
35865 rlim = ~0;
35866+
35867+ gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
35868 if (ex.a_data + ex.a_bss > rlim)
35869 return -ENOMEM;
35870
35871@@ -277,6 +282,27 @@ static int load_aout_binary(struct linux
35872 install_exec_creds(bprm);
35873 current->flags &= ~PF_FORKNOEXEC;
35874
35875+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
35876+ current->mm->pax_flags = 0UL;
35877+#endif
35878+
35879+#ifdef CONFIG_PAX_PAGEEXEC
35880+ if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
35881+ current->mm->pax_flags |= MF_PAX_PAGEEXEC;
35882+
35883+#ifdef CONFIG_PAX_EMUTRAMP
35884+ if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
35885+ current->mm->pax_flags |= MF_PAX_EMUTRAMP;
35886+#endif
35887+
35888+#ifdef CONFIG_PAX_MPROTECT
35889+ if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
35890+ current->mm->pax_flags |= MF_PAX_MPROTECT;
35891+#endif
35892+
35893+ }
35894+#endif
35895+
35896 if (N_MAGIC(ex) == OMAGIC) {
35897 unsigned long text_addr, map_size;
35898 loff_t pos;
35899@@ -349,7 +375,7 @@ static int load_aout_binary(struct linux
35900
35901 down_write(&current->mm->mmap_sem);
35902 error = do_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
35903- PROT_READ | PROT_WRITE | PROT_EXEC,
35904+ PROT_READ | PROT_WRITE,
35905 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
35906 fd_offset + ex.a_text);
35907 up_write(&current->mm->mmap_sem);
35908diff -urNp linux-2.6.32.41/fs/binfmt_elf.c linux-2.6.32.41/fs/binfmt_elf.c
35909--- linux-2.6.32.41/fs/binfmt_elf.c 2011-03-27 14:31:47.000000000 -0400
35910+++ linux-2.6.32.41/fs/binfmt_elf.c 2011-05-16 21:46:57.000000000 -0400
35911@@ -50,6 +50,10 @@ static int elf_core_dump(long signr, str
35912 #define elf_core_dump NULL
35913 #endif
35914
35915+#ifdef CONFIG_PAX_MPROTECT
35916+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
35917+#endif
35918+
35919 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
35920 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
35921 #else
35922@@ -69,6 +73,11 @@ static struct linux_binfmt elf_format =
35923 .load_binary = load_elf_binary,
35924 .load_shlib = load_elf_library,
35925 .core_dump = elf_core_dump,
35926+
35927+#ifdef CONFIG_PAX_MPROTECT
35928+ .handle_mprotect= elf_handle_mprotect,
35929+#endif
35930+
35931 .min_coredump = ELF_EXEC_PAGESIZE,
35932 .hasvdso = 1
35933 };
35934@@ -77,6 +86,8 @@ static struct linux_binfmt elf_format =
35935
35936 static int set_brk(unsigned long start, unsigned long end)
35937 {
35938+ unsigned long e = end;
35939+
35940 start = ELF_PAGEALIGN(start);
35941 end = ELF_PAGEALIGN(end);
35942 if (end > start) {
35943@@ -87,7 +98,7 @@ static int set_brk(unsigned long start,
35944 if (BAD_ADDR(addr))
35945 return addr;
35946 }
35947- current->mm->start_brk = current->mm->brk = end;
35948+ current->mm->start_brk = current->mm->brk = e;
35949 return 0;
35950 }
35951
35952@@ -148,12 +159,15 @@ create_elf_tables(struct linux_binprm *b
35953 elf_addr_t __user *u_rand_bytes;
35954 const char *k_platform = ELF_PLATFORM;
35955 const char *k_base_platform = ELF_BASE_PLATFORM;
35956- unsigned char k_rand_bytes[16];
35957+ u32 k_rand_bytes[4];
35958 int items;
35959 elf_addr_t *elf_info;
35960 int ei_index = 0;
35961 const struct cred *cred = current_cred();
35962 struct vm_area_struct *vma;
35963+ unsigned long saved_auxv[AT_VECTOR_SIZE];
35964+
35965+ pax_track_stack();
35966
35967 /*
35968 * In some cases (e.g. Hyper-Threading), we want to avoid L1
35969@@ -195,8 +209,12 @@ create_elf_tables(struct linux_binprm *b
35970 * Generate 16 random bytes for userspace PRNG seeding.
35971 */
35972 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
35973- u_rand_bytes = (elf_addr_t __user *)
35974- STACK_ALLOC(p, sizeof(k_rand_bytes));
35975+ srandom32(k_rand_bytes[0] ^ random32());
35976+ srandom32(k_rand_bytes[1] ^ random32());
35977+ srandom32(k_rand_bytes[2] ^ random32());
35978+ srandom32(k_rand_bytes[3] ^ random32());
35979+ p = STACK_ROUND(p, sizeof(k_rand_bytes));
35980+ u_rand_bytes = (elf_addr_t __user *) p;
35981 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
35982 return -EFAULT;
35983
35984@@ -308,9 +326,11 @@ create_elf_tables(struct linux_binprm *b
35985 return -EFAULT;
35986 current->mm->env_end = p;
35987
35988+ memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
35989+
35990 /* Put the elf_info on the stack in the right place. */
35991 sp = (elf_addr_t __user *)envp + 1;
35992- if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
35993+ if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
35994 return -EFAULT;
35995 return 0;
35996 }
35997@@ -385,10 +405,10 @@ static unsigned long load_elf_interp(str
35998 {
35999 struct elf_phdr *elf_phdata;
36000 struct elf_phdr *eppnt;
36001- unsigned long load_addr = 0;
36002+ unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
36003 int load_addr_set = 0;
36004 unsigned long last_bss = 0, elf_bss = 0;
36005- unsigned long error = ~0UL;
36006+ unsigned long error = -EINVAL;
36007 unsigned long total_size;
36008 int retval, i, size;
36009
36010@@ -434,6 +454,11 @@ static unsigned long load_elf_interp(str
36011 goto out_close;
36012 }
36013
36014+#ifdef CONFIG_PAX_SEGMEXEC
36015+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
36016+ pax_task_size = SEGMEXEC_TASK_SIZE;
36017+#endif
36018+
36019 eppnt = elf_phdata;
36020 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
36021 if (eppnt->p_type == PT_LOAD) {
36022@@ -477,8 +502,8 @@ static unsigned long load_elf_interp(str
36023 k = load_addr + eppnt->p_vaddr;
36024 if (BAD_ADDR(k) ||
36025 eppnt->p_filesz > eppnt->p_memsz ||
36026- eppnt->p_memsz > TASK_SIZE ||
36027- TASK_SIZE - eppnt->p_memsz < k) {
36028+ eppnt->p_memsz > pax_task_size ||
36029+ pax_task_size - eppnt->p_memsz < k) {
36030 error = -ENOMEM;
36031 goto out_close;
36032 }
36033@@ -532,6 +557,194 @@ out:
36034 return error;
36035 }
36036
36037+#if (defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS)) && defined(CONFIG_PAX_SOFTMODE)
36038+static unsigned long pax_parse_softmode(const struct elf_phdr * const elf_phdata)
36039+{
36040+ unsigned long pax_flags = 0UL;
36041+
36042+#ifdef CONFIG_PAX_PAGEEXEC
36043+ if (elf_phdata->p_flags & PF_PAGEEXEC)
36044+ pax_flags |= MF_PAX_PAGEEXEC;
36045+#endif
36046+
36047+#ifdef CONFIG_PAX_SEGMEXEC
36048+ if (elf_phdata->p_flags & PF_SEGMEXEC)
36049+ pax_flags |= MF_PAX_SEGMEXEC;
36050+#endif
36051+
36052+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
36053+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
36054+ if (nx_enabled)
36055+ pax_flags &= ~MF_PAX_SEGMEXEC;
36056+ else
36057+ pax_flags &= ~MF_PAX_PAGEEXEC;
36058+ }
36059+#endif
36060+
36061+#ifdef CONFIG_PAX_EMUTRAMP
36062+ if (elf_phdata->p_flags & PF_EMUTRAMP)
36063+ pax_flags |= MF_PAX_EMUTRAMP;
36064+#endif
36065+
36066+#ifdef CONFIG_PAX_MPROTECT
36067+ if (elf_phdata->p_flags & PF_MPROTECT)
36068+ pax_flags |= MF_PAX_MPROTECT;
36069+#endif
36070+
36071+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
36072+ if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
36073+ pax_flags |= MF_PAX_RANDMMAP;
36074+#endif
36075+
36076+ return pax_flags;
36077+}
36078+#endif
36079+
36080+#ifdef CONFIG_PAX_PT_PAX_FLAGS
36081+static unsigned long pax_parse_hardmode(const struct elf_phdr * const elf_phdata)
36082+{
36083+ unsigned long pax_flags = 0UL;
36084+
36085+#ifdef CONFIG_PAX_PAGEEXEC
36086+ if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
36087+ pax_flags |= MF_PAX_PAGEEXEC;
36088+#endif
36089+
36090+#ifdef CONFIG_PAX_SEGMEXEC
36091+ if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
36092+ pax_flags |= MF_PAX_SEGMEXEC;
36093+#endif
36094+
36095+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
36096+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
36097+ if (nx_enabled)
36098+ pax_flags &= ~MF_PAX_SEGMEXEC;
36099+ else
36100+ pax_flags &= ~MF_PAX_PAGEEXEC;
36101+ }
36102+#endif
36103+
36104+#ifdef CONFIG_PAX_EMUTRAMP
36105+ if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
36106+ pax_flags |= MF_PAX_EMUTRAMP;
36107+#endif
36108+
36109+#ifdef CONFIG_PAX_MPROTECT
36110+ if (!(elf_phdata->p_flags & PF_NOMPROTECT))
36111+ pax_flags |= MF_PAX_MPROTECT;
36112+#endif
36113+
36114+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
36115+ if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
36116+ pax_flags |= MF_PAX_RANDMMAP;
36117+#endif
36118+
36119+ return pax_flags;
36120+}
36121+#endif
36122+
36123+#ifdef CONFIG_PAX_EI_PAX
36124+static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
36125+{
36126+ unsigned long pax_flags = 0UL;
36127+
36128+#ifdef CONFIG_PAX_PAGEEXEC
36129+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
36130+ pax_flags |= MF_PAX_PAGEEXEC;
36131+#endif
36132+
36133+#ifdef CONFIG_PAX_SEGMEXEC
36134+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
36135+ pax_flags |= MF_PAX_SEGMEXEC;
36136+#endif
36137+
36138+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
36139+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
36140+ if (nx_enabled)
36141+ pax_flags &= ~MF_PAX_SEGMEXEC;
36142+ else
36143+ pax_flags &= ~MF_PAX_PAGEEXEC;
36144+ }
36145+#endif
36146+
36147+#ifdef CONFIG_PAX_EMUTRAMP
36148+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
36149+ pax_flags |= MF_PAX_EMUTRAMP;
36150+#endif
36151+
36152+#ifdef CONFIG_PAX_MPROTECT
36153+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
36154+ pax_flags |= MF_PAX_MPROTECT;
36155+#endif
36156+
36157+#ifdef CONFIG_PAX_ASLR
36158+ if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
36159+ pax_flags |= MF_PAX_RANDMMAP;
36160+#endif
36161+
36162+ return pax_flags;
36163+}
36164+#endif
36165+
36166+#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS)
36167+static long pax_parse_elf_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
36168+{
36169+ unsigned long pax_flags = 0UL;
36170+
36171+#ifdef CONFIG_PAX_PT_PAX_FLAGS
36172+ unsigned long i;
36173+ int found_flags = 0;
36174+#endif
36175+
36176+#ifdef CONFIG_PAX_EI_PAX
36177+ pax_flags = pax_parse_ei_pax(elf_ex);
36178+#endif
36179+
36180+#ifdef CONFIG_PAX_PT_PAX_FLAGS
36181+ for (i = 0UL; i < elf_ex->e_phnum; i++)
36182+ if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
36183+ if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
36184+ ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
36185+ ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
36186+ ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
36187+ ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
36188+ return -EINVAL;
36189+
36190+#ifdef CONFIG_PAX_SOFTMODE
36191+ if (pax_softmode)
36192+ pax_flags = pax_parse_softmode(&elf_phdata[i]);
36193+ else
36194+#endif
36195+
36196+ pax_flags = pax_parse_hardmode(&elf_phdata[i]);
36197+ found_flags = 1;
36198+ break;
36199+ }
36200+#endif
36201+
36202+#if !defined(CONFIG_PAX_EI_PAX) && defined(CONFIG_PAX_PT_PAX_FLAGS)
36203+ if (found_flags == 0) {
36204+ struct elf_phdr phdr;
36205+ memset(&phdr, 0, sizeof(phdr));
36206+ phdr.p_flags = PF_NOEMUTRAMP;
36207+#ifdef CONFIG_PAX_SOFTMODE
36208+ if (pax_softmode)
36209+ pax_flags = pax_parse_softmode(&phdr);
36210+ else
36211+#endif
36212+ pax_flags = pax_parse_hardmode(&phdr);
36213+ }
36214+#endif
36215+
36216+
36217+ if (0 > pax_check_flags(&pax_flags))
36218+ return -EINVAL;
36219+
36220+ current->mm->pax_flags = pax_flags;
36221+ return 0;
36222+}
36223+#endif
36224+
36225 /*
36226 * These are the functions used to load ELF style executables and shared
36227 * libraries. There is no binary dependent code anywhere else.
36228@@ -548,6 +761,11 @@ static unsigned long randomize_stack_top
36229 {
36230 unsigned int random_variable = 0;
36231
36232+#ifdef CONFIG_PAX_RANDUSTACK
36233+ if (randomize_va_space)
36234+ return stack_top - current->mm->delta_stack;
36235+#endif
36236+
36237 if ((current->flags & PF_RANDOMIZE) &&
36238 !(current->personality & ADDR_NO_RANDOMIZE)) {
36239 random_variable = get_random_int() & STACK_RND_MASK;
36240@@ -566,7 +784,7 @@ static int load_elf_binary(struct linux_
36241 unsigned long load_addr = 0, load_bias = 0;
36242 int load_addr_set = 0;
36243 char * elf_interpreter = NULL;
36244- unsigned long error;
36245+ unsigned long error = 0;
36246 struct elf_phdr *elf_ppnt, *elf_phdata;
36247 unsigned long elf_bss, elf_brk;
36248 int retval, i;
36249@@ -576,11 +794,11 @@ static int load_elf_binary(struct linux_
36250 unsigned long start_code, end_code, start_data, end_data;
36251 unsigned long reloc_func_desc = 0;
36252 int executable_stack = EXSTACK_DEFAULT;
36253- unsigned long def_flags = 0;
36254 struct {
36255 struct elfhdr elf_ex;
36256 struct elfhdr interp_elf_ex;
36257 } *loc;
36258+ unsigned long pax_task_size = TASK_SIZE;
36259
36260 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
36261 if (!loc) {
36262@@ -718,11 +936,80 @@ static int load_elf_binary(struct linux_
36263
36264 /* OK, This is the point of no return */
36265 current->flags &= ~PF_FORKNOEXEC;
36266- current->mm->def_flags = def_flags;
36267+
36268+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
36269+ current->mm->pax_flags = 0UL;
36270+#endif
36271+
36272+#ifdef CONFIG_PAX_DLRESOLVE
36273+ current->mm->call_dl_resolve = 0UL;
36274+#endif
36275+
36276+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
36277+ current->mm->call_syscall = 0UL;
36278+#endif
36279+
36280+#ifdef CONFIG_PAX_ASLR
36281+ current->mm->delta_mmap = 0UL;
36282+ current->mm->delta_stack = 0UL;
36283+#endif
36284+
36285+ current->mm->def_flags = 0;
36286+
36287+#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS)
36288+ if (0 > pax_parse_elf_flags(&loc->elf_ex, elf_phdata)) {
36289+ send_sig(SIGKILL, current, 0);
36290+ goto out_free_dentry;
36291+ }
36292+#endif
36293+
36294+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
36295+ pax_set_initial_flags(bprm);
36296+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
36297+ if (pax_set_initial_flags_func)
36298+ (pax_set_initial_flags_func)(bprm);
36299+#endif
36300+
36301+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
36302+ if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !nx_enabled) {
36303+ current->mm->context.user_cs_limit = PAGE_SIZE;
36304+ current->mm->def_flags |= VM_PAGEEXEC;
36305+ }
36306+#endif
36307+
36308+#ifdef CONFIG_PAX_SEGMEXEC
36309+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
36310+ current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
36311+ current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
36312+ pax_task_size = SEGMEXEC_TASK_SIZE;
36313+ }
36314+#endif
36315+
36316+#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
36317+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
36318+ set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
36319+ put_cpu();
36320+ }
36321+#endif
36322
36323 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
36324 may depend on the personality. */
36325 SET_PERSONALITY(loc->elf_ex);
36326+
36327+#ifdef CONFIG_PAX_ASLR
36328+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
36329+ current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
36330+ current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
36331+ }
36332+#endif
36333+
36334+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
36335+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
36336+ executable_stack = EXSTACK_DISABLE_X;
36337+ current->personality &= ~READ_IMPLIES_EXEC;
36338+ } else
36339+#endif
36340+
36341 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
36342 current->personality |= READ_IMPLIES_EXEC;
36343
36344@@ -804,6 +1091,20 @@ static int load_elf_binary(struct linux_
36345 #else
36346 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
36347 #endif
36348+
36349+#ifdef CONFIG_PAX_RANDMMAP
36350+ /* PaX: randomize base address at the default exe base if requested */
36351+ if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
36352+#ifdef CONFIG_SPARC64
36353+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
36354+#else
36355+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
36356+#endif
36357+ load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
36358+ elf_flags |= MAP_FIXED;
36359+ }
36360+#endif
36361+
36362 }
36363
36364 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
36365@@ -836,9 +1137,9 @@ static int load_elf_binary(struct linux_
36366 * allowed task size. Note that p_filesz must always be
36367 * <= p_memsz so it is only necessary to check p_memsz.
36368 */
36369- if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
36370- elf_ppnt->p_memsz > TASK_SIZE ||
36371- TASK_SIZE - elf_ppnt->p_memsz < k) {
36372+ if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
36373+ elf_ppnt->p_memsz > pax_task_size ||
36374+ pax_task_size - elf_ppnt->p_memsz < k) {
36375 /* set_brk can never work. Avoid overflows. */
36376 send_sig(SIGKILL, current, 0);
36377 retval = -EINVAL;
36378@@ -866,6 +1167,11 @@ static int load_elf_binary(struct linux_
36379 start_data += load_bias;
36380 end_data += load_bias;
36381
36382+#ifdef CONFIG_PAX_RANDMMAP
36383+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
36384+ elf_brk += PAGE_SIZE + ((pax_get_random_long() & ~PAGE_MASK) << 4);
36385+#endif
36386+
36387 /* Calling set_brk effectively mmaps the pages that we need
36388 * for the bss and break sections. We must do this before
36389 * mapping in the interpreter, to make sure it doesn't wind
36390@@ -877,9 +1183,11 @@ static int load_elf_binary(struct linux_
36391 goto out_free_dentry;
36392 }
36393 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
36394- send_sig(SIGSEGV, current, 0);
36395- retval = -EFAULT; /* Nobody gets to see this, but.. */
36396- goto out_free_dentry;
36397+ /*
36398+ * This bss-zeroing can fail if the ELF
36399+ * file specifies odd protections. So
36400+ * we don't check the return value
36401+ */
36402 }
36403
36404 if (elf_interpreter) {
36405@@ -1112,8 +1420,10 @@ static int dump_seek(struct file *file,
36406 unsigned long n = off;
36407 if (n > PAGE_SIZE)
36408 n = PAGE_SIZE;
36409- if (!dump_write(file, buf, n))
36410+ if (!dump_write(file, buf, n)) {
36411+ free_page((unsigned long)buf);
36412 return 0;
36413+ }
36414 off -= n;
36415 }
36416 free_page((unsigned long)buf);
36417@@ -1125,7 +1435,7 @@ static int dump_seek(struct file *file,
36418 * Decide what to dump of a segment, part, all or none.
36419 */
36420 static unsigned long vma_dump_size(struct vm_area_struct *vma,
36421- unsigned long mm_flags)
36422+ unsigned long mm_flags, long signr)
36423 {
36424 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
36425
36426@@ -1159,7 +1469,7 @@ static unsigned long vma_dump_size(struc
36427 if (vma->vm_file == NULL)
36428 return 0;
36429
36430- if (FILTER(MAPPED_PRIVATE))
36431+ if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
36432 goto whole;
36433
36434 /*
36435@@ -1255,8 +1565,11 @@ static int writenote(struct memelfnote *
36436 #undef DUMP_WRITE
36437
36438 #define DUMP_WRITE(addr, nr) \
36439+ do { \
36440+ gr_learn_resource(current, RLIMIT_CORE, size + (nr), 1); \
36441 if ((size += (nr)) > limit || !dump_write(file, (addr), (nr))) \
36442- goto end_coredump;
36443+ goto end_coredump; \
36444+ } while (0);
36445
36446 static void fill_elf_header(struct elfhdr *elf, int segs,
36447 u16 machine, u32 flags, u8 osabi)
36448@@ -1385,9 +1698,9 @@ static void fill_auxv_note(struct memelf
36449 {
36450 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
36451 int i = 0;
36452- do
36453+ do {
36454 i += 2;
36455- while (auxv[i - 2] != AT_NULL);
36456+ } while (auxv[i - 2] != AT_NULL);
36457 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
36458 }
36459
36460@@ -1973,7 +2286,7 @@ static int elf_core_dump(long signr, str
36461 phdr.p_offset = offset;
36462 phdr.p_vaddr = vma->vm_start;
36463 phdr.p_paddr = 0;
36464- phdr.p_filesz = vma_dump_size(vma, mm_flags);
36465+ phdr.p_filesz = vma_dump_size(vma, mm_flags, signr);
36466 phdr.p_memsz = vma->vm_end - vma->vm_start;
36467 offset += phdr.p_filesz;
36468 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
36469@@ -2006,7 +2319,7 @@ static int elf_core_dump(long signr, str
36470 unsigned long addr;
36471 unsigned long end;
36472
36473- end = vma->vm_start + vma_dump_size(vma, mm_flags);
36474+ end = vma->vm_start + vma_dump_size(vma, mm_flags, signr);
36475
36476 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
36477 struct page *page;
36478@@ -2015,6 +2328,7 @@ static int elf_core_dump(long signr, str
36479 page = get_dump_page(addr);
36480 if (page) {
36481 void *kaddr = kmap(page);
36482+ gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
36483 stop = ((size += PAGE_SIZE) > limit) ||
36484 !dump_write(file, kaddr, PAGE_SIZE);
36485 kunmap(page);
36486@@ -2042,6 +2356,97 @@ out:
36487
36488 #endif /* USE_ELF_CORE_DUMP */
36489
36490+#ifdef CONFIG_PAX_MPROTECT
36491+/* PaX: non-PIC ELF libraries need relocations on their executable segments
36492+ * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
36493+ * we'll remove VM_MAYWRITE for good on RELRO segments.
36494+ *
36495+ * The checks favour ld-linux.so behaviour which operates on a per ELF segment
36496+ * basis because we want to allow the common case and not the special ones.
36497+ */
36498+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
36499+{
36500+ struct elfhdr elf_h;
36501+ struct elf_phdr elf_p;
36502+ unsigned long i;
36503+ unsigned long oldflags;
36504+ bool is_textrel_rw, is_textrel_rx, is_relro;
36505+
36506+ if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
36507+ return;
36508+
36509+ oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
36510+ newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
36511+
36512+#ifdef CONFIG_PAX_ELFRELOCS
36513+ /* possible TEXTREL */
36514+ is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
36515+ 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);
36516+#else
36517+ is_textrel_rw = false;
36518+ is_textrel_rx = false;
36519+#endif
36520+
36521+ /* possible RELRO */
36522+ is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
36523+
36524+ if (!is_textrel_rw && !is_textrel_rx && !is_relro)
36525+ return;
36526+
36527+ if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
36528+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
36529+
36530+#ifdef CONFIG_PAX_ETEXECRELOCS
36531+ ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
36532+#else
36533+ ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
36534+#endif
36535+
36536+ (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
36537+ !elf_check_arch(&elf_h) ||
36538+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
36539+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
36540+ return;
36541+
36542+ for (i = 0UL; i < elf_h.e_phnum; i++) {
36543+ if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
36544+ return;
36545+ switch (elf_p.p_type) {
36546+ case PT_DYNAMIC:
36547+ if (!is_textrel_rw && !is_textrel_rx)
36548+ continue;
36549+ i = 0UL;
36550+ while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
36551+ elf_dyn dyn;
36552+
36553+ if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
36554+ return;
36555+ if (dyn.d_tag == DT_NULL)
36556+ return;
36557+ if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
36558+ gr_log_textrel(vma);
36559+ if (is_textrel_rw)
36560+ vma->vm_flags |= VM_MAYWRITE;
36561+ else
36562+ /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
36563+ vma->vm_flags &= ~VM_MAYWRITE;
36564+ return;
36565+ }
36566+ i++;
36567+ }
36568+ return;
36569+
36570+ case PT_GNU_RELRO:
36571+ if (!is_relro)
36572+ continue;
36573+ if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
36574+ vma->vm_flags &= ~VM_MAYWRITE;
36575+ return;
36576+ }
36577+ }
36578+}
36579+#endif
36580+
36581 static int __init init_elf_binfmt(void)
36582 {
36583 return register_binfmt(&elf_format);
36584diff -urNp linux-2.6.32.41/fs/binfmt_flat.c linux-2.6.32.41/fs/binfmt_flat.c
36585--- linux-2.6.32.41/fs/binfmt_flat.c 2011-03-27 14:31:47.000000000 -0400
36586+++ linux-2.6.32.41/fs/binfmt_flat.c 2011-04-17 15:56:46.000000000 -0400
36587@@ -564,7 +564,9 @@ static int load_flat_file(struct linux_b
36588 realdatastart = (unsigned long) -ENOMEM;
36589 printk("Unable to allocate RAM for process data, errno %d\n",
36590 (int)-realdatastart);
36591+ down_write(&current->mm->mmap_sem);
36592 do_munmap(current->mm, textpos, text_len);
36593+ up_write(&current->mm->mmap_sem);
36594 ret = realdatastart;
36595 goto err;
36596 }
36597@@ -588,8 +590,10 @@ static int load_flat_file(struct linux_b
36598 }
36599 if (IS_ERR_VALUE(result)) {
36600 printk("Unable to read data+bss, errno %d\n", (int)-result);
36601+ down_write(&current->mm->mmap_sem);
36602 do_munmap(current->mm, textpos, text_len);
36603 do_munmap(current->mm, realdatastart, data_len + extra);
36604+ up_write(&current->mm->mmap_sem);
36605 ret = result;
36606 goto err;
36607 }
36608@@ -658,8 +662,10 @@ static int load_flat_file(struct linux_b
36609 }
36610 if (IS_ERR_VALUE(result)) {
36611 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
36612+ down_write(&current->mm->mmap_sem);
36613 do_munmap(current->mm, textpos, text_len + data_len + extra +
36614 MAX_SHARED_LIBS * sizeof(unsigned long));
36615+ up_write(&current->mm->mmap_sem);
36616 ret = result;
36617 goto err;
36618 }
36619diff -urNp linux-2.6.32.41/fs/bio.c linux-2.6.32.41/fs/bio.c
36620--- linux-2.6.32.41/fs/bio.c 2011-03-27 14:31:47.000000000 -0400
36621+++ linux-2.6.32.41/fs/bio.c 2011-04-17 15:56:46.000000000 -0400
36622@@ -78,7 +78,7 @@ static struct kmem_cache *bio_find_or_cr
36623
36624 i = 0;
36625 while (i < bio_slab_nr) {
36626- struct bio_slab *bslab = &bio_slabs[i];
36627+ bslab = &bio_slabs[i];
36628
36629 if (!bslab->slab && entry == -1)
36630 entry = i;
36631@@ -1236,7 +1236,7 @@ static void bio_copy_kern_endio(struct b
36632 const int read = bio_data_dir(bio) == READ;
36633 struct bio_map_data *bmd = bio->bi_private;
36634 int i;
36635- char *p = bmd->sgvecs[0].iov_base;
36636+ char *p = (__force char *)bmd->sgvecs[0].iov_base;
36637
36638 __bio_for_each_segment(bvec, bio, i, 0) {
36639 char *addr = page_address(bvec->bv_page);
36640diff -urNp linux-2.6.32.41/fs/block_dev.c linux-2.6.32.41/fs/block_dev.c
36641--- linux-2.6.32.41/fs/block_dev.c 2011-03-27 14:31:47.000000000 -0400
36642+++ linux-2.6.32.41/fs/block_dev.c 2011-04-17 15:56:46.000000000 -0400
36643@@ -664,7 +664,7 @@ int bd_claim(struct block_device *bdev,
36644 else if (bdev->bd_contains == bdev)
36645 res = 0; /* is a whole device which isn't held */
36646
36647- else if (bdev->bd_contains->bd_holder == bd_claim)
36648+ else if (bdev->bd_contains->bd_holder == (void *)bd_claim)
36649 res = 0; /* is a partition of a device that is being partitioned */
36650 else if (bdev->bd_contains->bd_holder != NULL)
36651 res = -EBUSY; /* is a partition of a held device */
36652diff -urNp linux-2.6.32.41/fs/btrfs/ctree.c linux-2.6.32.41/fs/btrfs/ctree.c
36653--- linux-2.6.32.41/fs/btrfs/ctree.c 2011-03-27 14:31:47.000000000 -0400
36654+++ linux-2.6.32.41/fs/btrfs/ctree.c 2011-04-17 15:56:46.000000000 -0400
36655@@ -461,9 +461,12 @@ static noinline int __btrfs_cow_block(st
36656 free_extent_buffer(buf);
36657 add_root_to_dirty_list(root);
36658 } else {
36659- if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
36660- parent_start = parent->start;
36661- else
36662+ if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
36663+ if (parent)
36664+ parent_start = parent->start;
36665+ else
36666+ parent_start = 0;
36667+ } else
36668 parent_start = 0;
36669
36670 WARN_ON(trans->transid != btrfs_header_generation(parent));
36671@@ -3645,7 +3648,6 @@ setup_items_for_insert(struct btrfs_tran
36672
36673 ret = 0;
36674 if (slot == 0) {
36675- struct btrfs_disk_key disk_key;
36676 btrfs_cpu_key_to_disk(&disk_key, cpu_key);
36677 ret = fixup_low_keys(trans, root, path, &disk_key, 1);
36678 }
36679diff -urNp linux-2.6.32.41/fs/btrfs/disk-io.c linux-2.6.32.41/fs/btrfs/disk-io.c
36680--- linux-2.6.32.41/fs/btrfs/disk-io.c 2011-04-17 17:00:52.000000000 -0400
36681+++ linux-2.6.32.41/fs/btrfs/disk-io.c 2011-04-17 17:03:11.000000000 -0400
36682@@ -39,7 +39,7 @@
36683 #include "tree-log.h"
36684 #include "free-space-cache.h"
36685
36686-static struct extent_io_ops btree_extent_io_ops;
36687+static const struct extent_io_ops btree_extent_io_ops;
36688 static void end_workqueue_fn(struct btrfs_work *work);
36689 static void free_fs_root(struct btrfs_root *root);
36690
36691@@ -2607,7 +2607,7 @@ out:
36692 return 0;
36693 }
36694
36695-static struct extent_io_ops btree_extent_io_ops = {
36696+static const struct extent_io_ops btree_extent_io_ops = {
36697 .write_cache_pages_lock_hook = btree_lock_page_hook,
36698 .readpage_end_io_hook = btree_readpage_end_io_hook,
36699 .submit_bio_hook = btree_submit_bio_hook,
36700diff -urNp linux-2.6.32.41/fs/btrfs/extent_io.h linux-2.6.32.41/fs/btrfs/extent_io.h
36701--- linux-2.6.32.41/fs/btrfs/extent_io.h 2011-03-27 14:31:47.000000000 -0400
36702+++ linux-2.6.32.41/fs/btrfs/extent_io.h 2011-04-17 15:56:46.000000000 -0400
36703@@ -49,36 +49,36 @@ typedef int (extent_submit_bio_hook_t)(s
36704 struct bio *bio, int mirror_num,
36705 unsigned long bio_flags);
36706 struct extent_io_ops {
36707- int (*fill_delalloc)(struct inode *inode, struct page *locked_page,
36708+ int (* const fill_delalloc)(struct inode *inode, struct page *locked_page,
36709 u64 start, u64 end, int *page_started,
36710 unsigned long *nr_written);
36711- int (*writepage_start_hook)(struct page *page, u64 start, u64 end);
36712- int (*writepage_io_hook)(struct page *page, u64 start, u64 end);
36713+ int (* const writepage_start_hook)(struct page *page, u64 start, u64 end);
36714+ int (* const writepage_io_hook)(struct page *page, u64 start, u64 end);
36715 extent_submit_bio_hook_t *submit_bio_hook;
36716- int (*merge_bio_hook)(struct page *page, unsigned long offset,
36717+ int (* const merge_bio_hook)(struct page *page, unsigned long offset,
36718 size_t size, struct bio *bio,
36719 unsigned long bio_flags);
36720- int (*readpage_io_hook)(struct page *page, u64 start, u64 end);
36721- int (*readpage_io_failed_hook)(struct bio *bio, struct page *page,
36722+ int (* const readpage_io_hook)(struct page *page, u64 start, u64 end);
36723+ int (* const readpage_io_failed_hook)(struct bio *bio, struct page *page,
36724 u64 start, u64 end,
36725 struct extent_state *state);
36726- int (*writepage_io_failed_hook)(struct bio *bio, struct page *page,
36727+ int (* const writepage_io_failed_hook)(struct bio *bio, struct page *page,
36728 u64 start, u64 end,
36729 struct extent_state *state);
36730- int (*readpage_end_io_hook)(struct page *page, u64 start, u64 end,
36731+ int (* const readpage_end_io_hook)(struct page *page, u64 start, u64 end,
36732 struct extent_state *state);
36733- int (*writepage_end_io_hook)(struct page *page, u64 start, u64 end,
36734+ int (* const writepage_end_io_hook)(struct page *page, u64 start, u64 end,
36735 struct extent_state *state, int uptodate);
36736- int (*set_bit_hook)(struct inode *inode, u64 start, u64 end,
36737+ int (* const set_bit_hook)(struct inode *inode, u64 start, u64 end,
36738 unsigned long old, unsigned long bits);
36739- int (*clear_bit_hook)(struct inode *inode, struct extent_state *state,
36740+ int (* const clear_bit_hook)(struct inode *inode, struct extent_state *state,
36741 unsigned long bits);
36742- int (*merge_extent_hook)(struct inode *inode,
36743+ int (* const merge_extent_hook)(struct inode *inode,
36744 struct extent_state *new,
36745 struct extent_state *other);
36746- int (*split_extent_hook)(struct inode *inode,
36747+ int (* const split_extent_hook)(struct inode *inode,
36748 struct extent_state *orig, u64 split);
36749- int (*write_cache_pages_lock_hook)(struct page *page);
36750+ int (* const write_cache_pages_lock_hook)(struct page *page);
36751 };
36752
36753 struct extent_io_tree {
36754@@ -88,7 +88,7 @@ struct extent_io_tree {
36755 u64 dirty_bytes;
36756 spinlock_t lock;
36757 spinlock_t buffer_lock;
36758- struct extent_io_ops *ops;
36759+ const struct extent_io_ops *ops;
36760 };
36761
36762 struct extent_state {
36763diff -urNp linux-2.6.32.41/fs/btrfs/free-space-cache.c linux-2.6.32.41/fs/btrfs/free-space-cache.c
36764--- linux-2.6.32.41/fs/btrfs/free-space-cache.c 2011-03-27 14:31:47.000000000 -0400
36765+++ linux-2.6.32.41/fs/btrfs/free-space-cache.c 2011-04-17 15:56:46.000000000 -0400
36766@@ -1074,8 +1074,6 @@ u64 btrfs_alloc_from_cluster(struct btrf
36767
36768 while(1) {
36769 if (entry->bytes < bytes || entry->offset < min_start) {
36770- struct rb_node *node;
36771-
36772 node = rb_next(&entry->offset_index);
36773 if (!node)
36774 break;
36775@@ -1226,7 +1224,7 @@ again:
36776 */
36777 while (entry->bitmap || found_bitmap ||
36778 (!entry->bitmap && entry->bytes < min_bytes)) {
36779- struct rb_node *node = rb_next(&entry->offset_index);
36780+ node = rb_next(&entry->offset_index);
36781
36782 if (entry->bitmap && entry->bytes > bytes + empty_size) {
36783 ret = btrfs_bitmap_cluster(block_group, entry, cluster,
36784diff -urNp linux-2.6.32.41/fs/btrfs/inode.c linux-2.6.32.41/fs/btrfs/inode.c
36785--- linux-2.6.32.41/fs/btrfs/inode.c 2011-03-27 14:31:47.000000000 -0400
36786+++ linux-2.6.32.41/fs/btrfs/inode.c 2011-04-17 15:56:46.000000000 -0400
36787@@ -63,7 +63,7 @@ static const struct inode_operations btr
36788 static const struct address_space_operations btrfs_aops;
36789 static const struct address_space_operations btrfs_symlink_aops;
36790 static const struct file_operations btrfs_dir_file_operations;
36791-static struct extent_io_ops btrfs_extent_io_ops;
36792+static const struct extent_io_ops btrfs_extent_io_ops;
36793
36794 static struct kmem_cache *btrfs_inode_cachep;
36795 struct kmem_cache *btrfs_trans_handle_cachep;
36796@@ -5410,7 +5410,7 @@ fail:
36797 return -ENOMEM;
36798 }
36799
36800-static int btrfs_getattr(struct vfsmount *mnt,
36801+int btrfs_getattr(struct vfsmount *mnt,
36802 struct dentry *dentry, struct kstat *stat)
36803 {
36804 struct inode *inode = dentry->d_inode;
36805@@ -5422,6 +5422,14 @@ static int btrfs_getattr(struct vfsmount
36806 return 0;
36807 }
36808
36809+EXPORT_SYMBOL(btrfs_getattr);
36810+
36811+dev_t get_btrfs_dev_from_inode(struct inode *inode)
36812+{
36813+ return BTRFS_I(inode)->root->anon_super.s_dev;
36814+}
36815+EXPORT_SYMBOL(get_btrfs_dev_from_inode);
36816+
36817 static int btrfs_rename(struct inode *old_dir, struct dentry *old_dentry,
36818 struct inode *new_dir, struct dentry *new_dentry)
36819 {
36820@@ -5972,7 +5980,7 @@ static const struct file_operations btrf
36821 .fsync = btrfs_sync_file,
36822 };
36823
36824-static struct extent_io_ops btrfs_extent_io_ops = {
36825+static const struct extent_io_ops btrfs_extent_io_ops = {
36826 .fill_delalloc = run_delalloc_range,
36827 .submit_bio_hook = btrfs_submit_bio_hook,
36828 .merge_bio_hook = btrfs_merge_bio_hook,
36829diff -urNp linux-2.6.32.41/fs/btrfs/relocation.c linux-2.6.32.41/fs/btrfs/relocation.c
36830--- linux-2.6.32.41/fs/btrfs/relocation.c 2011-03-27 14:31:47.000000000 -0400
36831+++ linux-2.6.32.41/fs/btrfs/relocation.c 2011-04-17 15:56:46.000000000 -0400
36832@@ -884,7 +884,7 @@ static int __update_reloc_root(struct bt
36833 }
36834 spin_unlock(&rc->reloc_root_tree.lock);
36835
36836- BUG_ON((struct btrfs_root *)node->data != root);
36837+ BUG_ON(!node || (struct btrfs_root *)node->data != root);
36838
36839 if (!del) {
36840 spin_lock(&rc->reloc_root_tree.lock);
36841diff -urNp linux-2.6.32.41/fs/btrfs/sysfs.c linux-2.6.32.41/fs/btrfs/sysfs.c
36842--- linux-2.6.32.41/fs/btrfs/sysfs.c 2011-03-27 14:31:47.000000000 -0400
36843+++ linux-2.6.32.41/fs/btrfs/sysfs.c 2011-04-17 15:56:46.000000000 -0400
36844@@ -164,12 +164,12 @@ static void btrfs_root_release(struct ko
36845 complete(&root->kobj_unregister);
36846 }
36847
36848-static struct sysfs_ops btrfs_super_attr_ops = {
36849+static const struct sysfs_ops btrfs_super_attr_ops = {
36850 .show = btrfs_super_attr_show,
36851 .store = btrfs_super_attr_store,
36852 };
36853
36854-static struct sysfs_ops btrfs_root_attr_ops = {
36855+static const struct sysfs_ops btrfs_root_attr_ops = {
36856 .show = btrfs_root_attr_show,
36857 .store = btrfs_root_attr_store,
36858 };
36859diff -urNp linux-2.6.32.41/fs/buffer.c linux-2.6.32.41/fs/buffer.c
36860--- linux-2.6.32.41/fs/buffer.c 2011-03-27 14:31:47.000000000 -0400
36861+++ linux-2.6.32.41/fs/buffer.c 2011-04-17 15:56:46.000000000 -0400
36862@@ -25,6 +25,7 @@
36863 #include <linux/percpu.h>
36864 #include <linux/slab.h>
36865 #include <linux/capability.h>
36866+#include <linux/security.h>
36867 #include <linux/blkdev.h>
36868 #include <linux/file.h>
36869 #include <linux/quotaops.h>
36870diff -urNp linux-2.6.32.41/fs/cachefiles/bind.c linux-2.6.32.41/fs/cachefiles/bind.c
36871--- linux-2.6.32.41/fs/cachefiles/bind.c 2011-03-27 14:31:47.000000000 -0400
36872+++ linux-2.6.32.41/fs/cachefiles/bind.c 2011-04-17 15:56:46.000000000 -0400
36873@@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachef
36874 args);
36875
36876 /* start by checking things over */
36877- ASSERT(cache->fstop_percent >= 0 &&
36878- cache->fstop_percent < cache->fcull_percent &&
36879+ ASSERT(cache->fstop_percent < cache->fcull_percent &&
36880 cache->fcull_percent < cache->frun_percent &&
36881 cache->frun_percent < 100);
36882
36883- ASSERT(cache->bstop_percent >= 0 &&
36884- cache->bstop_percent < cache->bcull_percent &&
36885+ ASSERT(cache->bstop_percent < cache->bcull_percent &&
36886 cache->bcull_percent < cache->brun_percent &&
36887 cache->brun_percent < 100);
36888
36889diff -urNp linux-2.6.32.41/fs/cachefiles/daemon.c linux-2.6.32.41/fs/cachefiles/daemon.c
36890--- linux-2.6.32.41/fs/cachefiles/daemon.c 2011-03-27 14:31:47.000000000 -0400
36891+++ linux-2.6.32.41/fs/cachefiles/daemon.c 2011-04-17 15:56:46.000000000 -0400
36892@@ -220,7 +220,7 @@ static ssize_t cachefiles_daemon_write(s
36893 if (test_bit(CACHEFILES_DEAD, &cache->flags))
36894 return -EIO;
36895
36896- if (datalen < 0 || datalen > PAGE_SIZE - 1)
36897+ if (datalen > PAGE_SIZE - 1)
36898 return -EOPNOTSUPP;
36899
36900 /* drag the command string into the kernel so we can parse it */
36901@@ -385,7 +385,7 @@ static int cachefiles_daemon_fstop(struc
36902 if (args[0] != '%' || args[1] != '\0')
36903 return -EINVAL;
36904
36905- if (fstop < 0 || fstop >= cache->fcull_percent)
36906+ if (fstop >= cache->fcull_percent)
36907 return cachefiles_daemon_range_error(cache, args);
36908
36909 cache->fstop_percent = fstop;
36910@@ -457,7 +457,7 @@ static int cachefiles_daemon_bstop(struc
36911 if (args[0] != '%' || args[1] != '\0')
36912 return -EINVAL;
36913
36914- if (bstop < 0 || bstop >= cache->bcull_percent)
36915+ if (bstop >= cache->bcull_percent)
36916 return cachefiles_daemon_range_error(cache, args);
36917
36918 cache->bstop_percent = bstop;
36919diff -urNp linux-2.6.32.41/fs/cachefiles/internal.h linux-2.6.32.41/fs/cachefiles/internal.h
36920--- linux-2.6.32.41/fs/cachefiles/internal.h 2011-03-27 14:31:47.000000000 -0400
36921+++ linux-2.6.32.41/fs/cachefiles/internal.h 2011-05-04 17:56:28.000000000 -0400
36922@@ -56,7 +56,7 @@ struct cachefiles_cache {
36923 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
36924 struct rb_root active_nodes; /* active nodes (can't be culled) */
36925 rwlock_t active_lock; /* lock for active_nodes */
36926- atomic_t gravecounter; /* graveyard uniquifier */
36927+ atomic_unchecked_t gravecounter; /* graveyard uniquifier */
36928 unsigned frun_percent; /* when to stop culling (% files) */
36929 unsigned fcull_percent; /* when to start culling (% files) */
36930 unsigned fstop_percent; /* when to stop allocating (% files) */
36931@@ -168,19 +168,19 @@ extern int cachefiles_check_in_use(struc
36932 * proc.c
36933 */
36934 #ifdef CONFIG_CACHEFILES_HISTOGRAM
36935-extern atomic_t cachefiles_lookup_histogram[HZ];
36936-extern atomic_t cachefiles_mkdir_histogram[HZ];
36937-extern atomic_t cachefiles_create_histogram[HZ];
36938+extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
36939+extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
36940+extern atomic_unchecked_t cachefiles_create_histogram[HZ];
36941
36942 extern int __init cachefiles_proc_init(void);
36943 extern void cachefiles_proc_cleanup(void);
36944 static inline
36945-void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
36946+void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
36947 {
36948 unsigned long jif = jiffies - start_jif;
36949 if (jif >= HZ)
36950 jif = HZ - 1;
36951- atomic_inc(&histogram[jif]);
36952+ atomic_inc_unchecked(&histogram[jif]);
36953 }
36954
36955 #else
36956diff -urNp linux-2.6.32.41/fs/cachefiles/namei.c linux-2.6.32.41/fs/cachefiles/namei.c
36957--- linux-2.6.32.41/fs/cachefiles/namei.c 2011-03-27 14:31:47.000000000 -0400
36958+++ linux-2.6.32.41/fs/cachefiles/namei.c 2011-05-04 17:56:28.000000000 -0400
36959@@ -250,7 +250,7 @@ try_again:
36960 /* first step is to make up a grave dentry in the graveyard */
36961 sprintf(nbuffer, "%08x%08x",
36962 (uint32_t) get_seconds(),
36963- (uint32_t) atomic_inc_return(&cache->gravecounter));
36964+ (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
36965
36966 /* do the multiway lock magic */
36967 trap = lock_rename(cache->graveyard, dir);
36968diff -urNp linux-2.6.32.41/fs/cachefiles/proc.c linux-2.6.32.41/fs/cachefiles/proc.c
36969--- linux-2.6.32.41/fs/cachefiles/proc.c 2011-03-27 14:31:47.000000000 -0400
36970+++ linux-2.6.32.41/fs/cachefiles/proc.c 2011-05-04 17:56:28.000000000 -0400
36971@@ -14,9 +14,9 @@
36972 #include <linux/seq_file.h>
36973 #include "internal.h"
36974
36975-atomic_t cachefiles_lookup_histogram[HZ];
36976-atomic_t cachefiles_mkdir_histogram[HZ];
36977-atomic_t cachefiles_create_histogram[HZ];
36978+atomic_unchecked_t cachefiles_lookup_histogram[HZ];
36979+atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
36980+atomic_unchecked_t cachefiles_create_histogram[HZ];
36981
36982 /*
36983 * display the latency histogram
36984@@ -35,9 +35,9 @@ static int cachefiles_histogram_show(str
36985 return 0;
36986 default:
36987 index = (unsigned long) v - 3;
36988- x = atomic_read(&cachefiles_lookup_histogram[index]);
36989- y = atomic_read(&cachefiles_mkdir_histogram[index]);
36990- z = atomic_read(&cachefiles_create_histogram[index]);
36991+ x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
36992+ y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
36993+ z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
36994 if (x == 0 && y == 0 && z == 0)
36995 return 0;
36996
36997diff -urNp linux-2.6.32.41/fs/cachefiles/rdwr.c linux-2.6.32.41/fs/cachefiles/rdwr.c
36998--- linux-2.6.32.41/fs/cachefiles/rdwr.c 2011-03-27 14:31:47.000000000 -0400
36999+++ linux-2.6.32.41/fs/cachefiles/rdwr.c 2011-04-17 15:56:46.000000000 -0400
37000@@ -946,7 +946,7 @@ int cachefiles_write_page(struct fscache
37001 old_fs = get_fs();
37002 set_fs(KERNEL_DS);
37003 ret = file->f_op->write(
37004- file, (const void __user *) data, len, &pos);
37005+ file, (__force const void __user *) data, len, &pos);
37006 set_fs(old_fs);
37007 kunmap(page);
37008 if (ret != len)
37009diff -urNp linux-2.6.32.41/fs/cifs/cifs_debug.c linux-2.6.32.41/fs/cifs/cifs_debug.c
37010--- linux-2.6.32.41/fs/cifs/cifs_debug.c 2011-03-27 14:31:47.000000000 -0400
37011+++ linux-2.6.32.41/fs/cifs/cifs_debug.c 2011-05-04 17:56:28.000000000 -0400
37012@@ -256,25 +256,25 @@ static ssize_t cifs_stats_proc_write(str
37013 tcon = list_entry(tmp3,
37014 struct cifsTconInfo,
37015 tcon_list);
37016- atomic_set(&tcon->num_smbs_sent, 0);
37017- atomic_set(&tcon->num_writes, 0);
37018- atomic_set(&tcon->num_reads, 0);
37019- atomic_set(&tcon->num_oplock_brks, 0);
37020- atomic_set(&tcon->num_opens, 0);
37021- atomic_set(&tcon->num_posixopens, 0);
37022- atomic_set(&tcon->num_posixmkdirs, 0);
37023- atomic_set(&tcon->num_closes, 0);
37024- atomic_set(&tcon->num_deletes, 0);
37025- atomic_set(&tcon->num_mkdirs, 0);
37026- atomic_set(&tcon->num_rmdirs, 0);
37027- atomic_set(&tcon->num_renames, 0);
37028- atomic_set(&tcon->num_t2renames, 0);
37029- atomic_set(&tcon->num_ffirst, 0);
37030- atomic_set(&tcon->num_fnext, 0);
37031- atomic_set(&tcon->num_fclose, 0);
37032- atomic_set(&tcon->num_hardlinks, 0);
37033- atomic_set(&tcon->num_symlinks, 0);
37034- atomic_set(&tcon->num_locks, 0);
37035+ atomic_set_unchecked(&tcon->num_smbs_sent, 0);
37036+ atomic_set_unchecked(&tcon->num_writes, 0);
37037+ atomic_set_unchecked(&tcon->num_reads, 0);
37038+ atomic_set_unchecked(&tcon->num_oplock_brks, 0);
37039+ atomic_set_unchecked(&tcon->num_opens, 0);
37040+ atomic_set_unchecked(&tcon->num_posixopens, 0);
37041+ atomic_set_unchecked(&tcon->num_posixmkdirs, 0);
37042+ atomic_set_unchecked(&tcon->num_closes, 0);
37043+ atomic_set_unchecked(&tcon->num_deletes, 0);
37044+ atomic_set_unchecked(&tcon->num_mkdirs, 0);
37045+ atomic_set_unchecked(&tcon->num_rmdirs, 0);
37046+ atomic_set_unchecked(&tcon->num_renames, 0);
37047+ atomic_set_unchecked(&tcon->num_t2renames, 0);
37048+ atomic_set_unchecked(&tcon->num_ffirst, 0);
37049+ atomic_set_unchecked(&tcon->num_fnext, 0);
37050+ atomic_set_unchecked(&tcon->num_fclose, 0);
37051+ atomic_set_unchecked(&tcon->num_hardlinks, 0);
37052+ atomic_set_unchecked(&tcon->num_symlinks, 0);
37053+ atomic_set_unchecked(&tcon->num_locks, 0);
37054 }
37055 }
37056 }
37057@@ -334,41 +334,41 @@ static int cifs_stats_proc_show(struct s
37058 if (tcon->need_reconnect)
37059 seq_puts(m, "\tDISCONNECTED ");
37060 seq_printf(m, "\nSMBs: %d Oplock Breaks: %d",
37061- atomic_read(&tcon->num_smbs_sent),
37062- atomic_read(&tcon->num_oplock_brks));
37063+ atomic_read_unchecked(&tcon->num_smbs_sent),
37064+ atomic_read_unchecked(&tcon->num_oplock_brks));
37065 seq_printf(m, "\nReads: %d Bytes: %lld",
37066- atomic_read(&tcon->num_reads),
37067+ atomic_read_unchecked(&tcon->num_reads),
37068 (long long)(tcon->bytes_read));
37069 seq_printf(m, "\nWrites: %d Bytes: %lld",
37070- atomic_read(&tcon->num_writes),
37071+ atomic_read_unchecked(&tcon->num_writes),
37072 (long long)(tcon->bytes_written));
37073 seq_printf(m, "\nFlushes: %d",
37074- atomic_read(&tcon->num_flushes));
37075+ atomic_read_unchecked(&tcon->num_flushes));
37076 seq_printf(m, "\nLocks: %d HardLinks: %d "
37077 "Symlinks: %d",
37078- atomic_read(&tcon->num_locks),
37079- atomic_read(&tcon->num_hardlinks),
37080- atomic_read(&tcon->num_symlinks));
37081+ atomic_read_unchecked(&tcon->num_locks),
37082+ atomic_read_unchecked(&tcon->num_hardlinks),
37083+ atomic_read_unchecked(&tcon->num_symlinks));
37084 seq_printf(m, "\nOpens: %d Closes: %d "
37085 "Deletes: %d",
37086- atomic_read(&tcon->num_opens),
37087- atomic_read(&tcon->num_closes),
37088- atomic_read(&tcon->num_deletes));
37089+ atomic_read_unchecked(&tcon->num_opens),
37090+ atomic_read_unchecked(&tcon->num_closes),
37091+ atomic_read_unchecked(&tcon->num_deletes));
37092 seq_printf(m, "\nPosix Opens: %d "
37093 "Posix Mkdirs: %d",
37094- atomic_read(&tcon->num_posixopens),
37095- atomic_read(&tcon->num_posixmkdirs));
37096+ atomic_read_unchecked(&tcon->num_posixopens),
37097+ atomic_read_unchecked(&tcon->num_posixmkdirs));
37098 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
37099- atomic_read(&tcon->num_mkdirs),
37100- atomic_read(&tcon->num_rmdirs));
37101+ atomic_read_unchecked(&tcon->num_mkdirs),
37102+ atomic_read_unchecked(&tcon->num_rmdirs));
37103 seq_printf(m, "\nRenames: %d T2 Renames %d",
37104- atomic_read(&tcon->num_renames),
37105- atomic_read(&tcon->num_t2renames));
37106+ atomic_read_unchecked(&tcon->num_renames),
37107+ atomic_read_unchecked(&tcon->num_t2renames));
37108 seq_printf(m, "\nFindFirst: %d FNext %d "
37109 "FClose %d",
37110- atomic_read(&tcon->num_ffirst),
37111- atomic_read(&tcon->num_fnext),
37112- atomic_read(&tcon->num_fclose));
37113+ atomic_read_unchecked(&tcon->num_ffirst),
37114+ atomic_read_unchecked(&tcon->num_fnext),
37115+ atomic_read_unchecked(&tcon->num_fclose));
37116 }
37117 }
37118 }
37119diff -urNp linux-2.6.32.41/fs/cifs/cifsglob.h linux-2.6.32.41/fs/cifs/cifsglob.h
37120--- linux-2.6.32.41/fs/cifs/cifsglob.h 2011-03-27 14:31:47.000000000 -0400
37121+++ linux-2.6.32.41/fs/cifs/cifsglob.h 2011-05-04 17:56:28.000000000 -0400
37122@@ -252,28 +252,28 @@ struct cifsTconInfo {
37123 __u16 Flags; /* optional support bits */
37124 enum statusEnum tidStatus;
37125 #ifdef CONFIG_CIFS_STATS
37126- atomic_t num_smbs_sent;
37127- atomic_t num_writes;
37128- atomic_t num_reads;
37129- atomic_t num_flushes;
37130- atomic_t num_oplock_brks;
37131- atomic_t num_opens;
37132- atomic_t num_closes;
37133- atomic_t num_deletes;
37134- atomic_t num_mkdirs;
37135- atomic_t num_posixopens;
37136- atomic_t num_posixmkdirs;
37137- atomic_t num_rmdirs;
37138- atomic_t num_renames;
37139- atomic_t num_t2renames;
37140- atomic_t num_ffirst;
37141- atomic_t num_fnext;
37142- atomic_t num_fclose;
37143- atomic_t num_hardlinks;
37144- atomic_t num_symlinks;
37145- atomic_t num_locks;
37146- atomic_t num_acl_get;
37147- atomic_t num_acl_set;
37148+ atomic_unchecked_t num_smbs_sent;
37149+ atomic_unchecked_t num_writes;
37150+ atomic_unchecked_t num_reads;
37151+ atomic_unchecked_t num_flushes;
37152+ atomic_unchecked_t num_oplock_brks;
37153+ atomic_unchecked_t num_opens;
37154+ atomic_unchecked_t num_closes;
37155+ atomic_unchecked_t num_deletes;
37156+ atomic_unchecked_t num_mkdirs;
37157+ atomic_unchecked_t num_posixopens;
37158+ atomic_unchecked_t num_posixmkdirs;
37159+ atomic_unchecked_t num_rmdirs;
37160+ atomic_unchecked_t num_renames;
37161+ atomic_unchecked_t num_t2renames;
37162+ atomic_unchecked_t num_ffirst;
37163+ atomic_unchecked_t num_fnext;
37164+ atomic_unchecked_t num_fclose;
37165+ atomic_unchecked_t num_hardlinks;
37166+ atomic_unchecked_t num_symlinks;
37167+ atomic_unchecked_t num_locks;
37168+ atomic_unchecked_t num_acl_get;
37169+ atomic_unchecked_t num_acl_set;
37170 #ifdef CONFIG_CIFS_STATS2
37171 unsigned long long time_writes;
37172 unsigned long long time_reads;
37173@@ -414,7 +414,7 @@ static inline char CIFS_DIR_SEP(const st
37174 }
37175
37176 #ifdef CONFIG_CIFS_STATS
37177-#define cifs_stats_inc atomic_inc
37178+#define cifs_stats_inc atomic_inc_unchecked
37179
37180 static inline void cifs_stats_bytes_written(struct cifsTconInfo *tcon,
37181 unsigned int bytes)
37182diff -urNp linux-2.6.32.41/fs/cifs/link.c linux-2.6.32.41/fs/cifs/link.c
37183--- linux-2.6.32.41/fs/cifs/link.c 2011-03-27 14:31:47.000000000 -0400
37184+++ linux-2.6.32.41/fs/cifs/link.c 2011-04-17 15:56:46.000000000 -0400
37185@@ -215,7 +215,7 @@ cifs_symlink(struct inode *inode, struct
37186
37187 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
37188 {
37189- char *p = nd_get_link(nd);
37190+ const char *p = nd_get_link(nd);
37191 if (!IS_ERR(p))
37192 kfree(p);
37193 }
37194diff -urNp linux-2.6.32.41/fs/coda/cache.c linux-2.6.32.41/fs/coda/cache.c
37195--- linux-2.6.32.41/fs/coda/cache.c 2011-03-27 14:31:47.000000000 -0400
37196+++ linux-2.6.32.41/fs/coda/cache.c 2011-05-04 17:56:28.000000000 -0400
37197@@ -24,14 +24,14 @@
37198 #include <linux/coda_fs_i.h>
37199 #include <linux/coda_cache.h>
37200
37201-static atomic_t permission_epoch = ATOMIC_INIT(0);
37202+static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
37203
37204 /* replace or extend an acl cache hit */
37205 void coda_cache_enter(struct inode *inode, int mask)
37206 {
37207 struct coda_inode_info *cii = ITOC(inode);
37208
37209- cii->c_cached_epoch = atomic_read(&permission_epoch);
37210+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
37211 if (cii->c_uid != current_fsuid()) {
37212 cii->c_uid = current_fsuid();
37213 cii->c_cached_perm = mask;
37214@@ -43,13 +43,13 @@ void coda_cache_enter(struct inode *inod
37215 void coda_cache_clear_inode(struct inode *inode)
37216 {
37217 struct coda_inode_info *cii = ITOC(inode);
37218- cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
37219+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
37220 }
37221
37222 /* remove all acl caches */
37223 void coda_cache_clear_all(struct super_block *sb)
37224 {
37225- atomic_inc(&permission_epoch);
37226+ atomic_inc_unchecked(&permission_epoch);
37227 }
37228
37229
37230@@ -61,7 +61,7 @@ int coda_cache_check(struct inode *inode
37231
37232 hit = (mask & cii->c_cached_perm) == mask &&
37233 cii->c_uid == current_fsuid() &&
37234- cii->c_cached_epoch == atomic_read(&permission_epoch);
37235+ cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
37236
37237 return hit;
37238 }
37239diff -urNp linux-2.6.32.41/fs/compat_binfmt_elf.c linux-2.6.32.41/fs/compat_binfmt_elf.c
37240--- linux-2.6.32.41/fs/compat_binfmt_elf.c 2011-03-27 14:31:47.000000000 -0400
37241+++ linux-2.6.32.41/fs/compat_binfmt_elf.c 2011-04-17 15:56:46.000000000 -0400
37242@@ -29,10 +29,12 @@
37243 #undef elfhdr
37244 #undef elf_phdr
37245 #undef elf_note
37246+#undef elf_dyn
37247 #undef elf_addr_t
37248 #define elfhdr elf32_hdr
37249 #define elf_phdr elf32_phdr
37250 #define elf_note elf32_note
37251+#define elf_dyn Elf32_Dyn
37252 #define elf_addr_t Elf32_Addr
37253
37254 /*
37255diff -urNp linux-2.6.32.41/fs/compat.c linux-2.6.32.41/fs/compat.c
37256--- linux-2.6.32.41/fs/compat.c 2011-04-17 17:00:52.000000000 -0400
37257+++ linux-2.6.32.41/fs/compat.c 2011-05-16 21:46:57.000000000 -0400
37258@@ -830,6 +830,7 @@ struct compat_old_linux_dirent {
37259
37260 struct compat_readdir_callback {
37261 struct compat_old_linux_dirent __user *dirent;
37262+ struct file * file;
37263 int result;
37264 };
37265
37266@@ -847,6 +848,10 @@ static int compat_fillonedir(void *__buf
37267 buf->result = -EOVERFLOW;
37268 return -EOVERFLOW;
37269 }
37270+
37271+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
37272+ return 0;
37273+
37274 buf->result++;
37275 dirent = buf->dirent;
37276 if (!access_ok(VERIFY_WRITE, dirent,
37277@@ -879,6 +884,7 @@ asmlinkage long compat_sys_old_readdir(u
37278
37279 buf.result = 0;
37280 buf.dirent = dirent;
37281+ buf.file = file;
37282
37283 error = vfs_readdir(file, compat_fillonedir, &buf);
37284 if (buf.result)
37285@@ -899,6 +905,7 @@ struct compat_linux_dirent {
37286 struct compat_getdents_callback {
37287 struct compat_linux_dirent __user *current_dir;
37288 struct compat_linux_dirent __user *previous;
37289+ struct file * file;
37290 int count;
37291 int error;
37292 };
37293@@ -919,6 +926,10 @@ static int compat_filldir(void *__buf, c
37294 buf->error = -EOVERFLOW;
37295 return -EOVERFLOW;
37296 }
37297+
37298+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
37299+ return 0;
37300+
37301 dirent = buf->previous;
37302 if (dirent) {
37303 if (__put_user(offset, &dirent->d_off))
37304@@ -966,6 +977,7 @@ asmlinkage long compat_sys_getdents(unsi
37305 buf.previous = NULL;
37306 buf.count = count;
37307 buf.error = 0;
37308+ buf.file = file;
37309
37310 error = vfs_readdir(file, compat_filldir, &buf);
37311 if (error >= 0)
37312@@ -987,6 +999,7 @@ out:
37313 struct compat_getdents_callback64 {
37314 struct linux_dirent64 __user *current_dir;
37315 struct linux_dirent64 __user *previous;
37316+ struct file * file;
37317 int count;
37318 int error;
37319 };
37320@@ -1003,6 +1016,10 @@ static int compat_filldir64(void * __buf
37321 buf->error = -EINVAL; /* only used if we fail.. */
37322 if (reclen > buf->count)
37323 return -EINVAL;
37324+
37325+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
37326+ return 0;
37327+
37328 dirent = buf->previous;
37329
37330 if (dirent) {
37331@@ -1054,6 +1071,7 @@ asmlinkage long compat_sys_getdents64(un
37332 buf.previous = NULL;
37333 buf.count = count;
37334 buf.error = 0;
37335+ buf.file = file;
37336
37337 error = vfs_readdir(file, compat_filldir64, &buf);
37338 if (error >= 0)
37339@@ -1098,7 +1116,7 @@ static ssize_t compat_do_readv_writev(in
37340 * verify all the pointers
37341 */
37342 ret = -EINVAL;
37343- if ((nr_segs > UIO_MAXIOV) || (nr_segs <= 0))
37344+ if (nr_segs > UIO_MAXIOV)
37345 goto out;
37346 if (!file->f_op)
37347 goto out;
37348@@ -1463,6 +1481,11 @@ int compat_do_execve(char * filename,
37349 compat_uptr_t __user *envp,
37350 struct pt_regs * regs)
37351 {
37352+#ifdef CONFIG_GRKERNSEC
37353+ struct file *old_exec_file;
37354+ struct acl_subject_label *old_acl;
37355+ struct rlimit old_rlim[RLIM_NLIMITS];
37356+#endif
37357 struct linux_binprm *bprm;
37358 struct file *file;
37359 struct files_struct *displaced;
37360@@ -1499,6 +1522,19 @@ int compat_do_execve(char * filename,
37361 bprm->filename = filename;
37362 bprm->interp = filename;
37363
37364+ if (gr_process_user_ban()) {
37365+ retval = -EPERM;
37366+ goto out_file;
37367+ }
37368+
37369+ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
37370+ retval = -EAGAIN;
37371+ if (gr_handle_nproc())
37372+ goto out_file;
37373+ retval = -EACCES;
37374+ if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt))
37375+ goto out_file;
37376+
37377 retval = bprm_mm_init(bprm);
37378 if (retval)
37379 goto out_file;
37380@@ -1528,9 +1564,40 @@ int compat_do_execve(char * filename,
37381 if (retval < 0)
37382 goto out;
37383
37384+ if (!gr_tpe_allow(file)) {
37385+ retval = -EACCES;
37386+ goto out;
37387+ }
37388+
37389+ if (gr_check_crash_exec(file)) {
37390+ retval = -EACCES;
37391+ goto out;
37392+ }
37393+
37394+ gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
37395+
37396+ gr_handle_exec_args_compat(bprm, argv);
37397+
37398+#ifdef CONFIG_GRKERNSEC
37399+ old_acl = current->acl;
37400+ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
37401+ old_exec_file = current->exec_file;
37402+ get_file(file);
37403+ current->exec_file = file;
37404+#endif
37405+
37406+ retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
37407+ bprm->unsafe & LSM_UNSAFE_SHARE);
37408+ if (retval < 0)
37409+ goto out_fail;
37410+
37411 retval = search_binary_handler(bprm, regs);
37412 if (retval < 0)
37413- goto out;
37414+ goto out_fail;
37415+#ifdef CONFIG_GRKERNSEC
37416+ if (old_exec_file)
37417+ fput(old_exec_file);
37418+#endif
37419
37420 /* execve succeeded */
37421 current->fs->in_exec = 0;
37422@@ -1541,6 +1608,14 @@ int compat_do_execve(char * filename,
37423 put_files_struct(displaced);
37424 return retval;
37425
37426+out_fail:
37427+#ifdef CONFIG_GRKERNSEC
37428+ current->acl = old_acl;
37429+ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
37430+ fput(current->exec_file);
37431+ current->exec_file = old_exec_file;
37432+#endif
37433+
37434 out:
37435 if (bprm->mm) {
37436 acct_arg_size(bprm, 0);
37437@@ -1711,6 +1786,8 @@ int compat_core_sys_select(int n, compat
37438 struct fdtable *fdt;
37439 long stack_fds[SELECT_STACK_ALLOC/sizeof(long)];
37440
37441+ pax_track_stack();
37442+
37443 if (n < 0)
37444 goto out_nofds;
37445
37446diff -urNp linux-2.6.32.41/fs/compat_ioctl.c linux-2.6.32.41/fs/compat_ioctl.c
37447--- linux-2.6.32.41/fs/compat_ioctl.c 2011-03-27 14:31:47.000000000 -0400
37448+++ linux-2.6.32.41/fs/compat_ioctl.c 2011-04-23 12:56:11.000000000 -0400
37449@@ -234,6 +234,8 @@ static int do_video_set_spu_palette(unsi
37450 up = (struct compat_video_spu_palette __user *) arg;
37451 err = get_user(palp, &up->palette);
37452 err |= get_user(length, &up->length);
37453+ if (err)
37454+ return -EFAULT;
37455
37456 up_native = compat_alloc_user_space(sizeof(struct video_spu_palette));
37457 err = put_user(compat_ptr(palp), &up_native->palette);
37458diff -urNp linux-2.6.32.41/fs/configfs/dir.c linux-2.6.32.41/fs/configfs/dir.c
37459--- linux-2.6.32.41/fs/configfs/dir.c 2011-03-27 14:31:47.000000000 -0400
37460+++ linux-2.6.32.41/fs/configfs/dir.c 2011-05-11 18:25:15.000000000 -0400
37461@@ -1572,7 +1572,8 @@ static int configfs_readdir(struct file
37462 }
37463 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
37464 struct configfs_dirent *next;
37465- const char * name;
37466+ const unsigned char * name;
37467+ char d_name[sizeof(next->s_dentry->d_iname)];
37468 int len;
37469
37470 next = list_entry(p, struct configfs_dirent,
37471@@ -1581,7 +1582,12 @@ static int configfs_readdir(struct file
37472 continue;
37473
37474 name = configfs_get_name(next);
37475- len = strlen(name);
37476+ if (next->s_dentry && name == next->s_dentry->d_iname) {
37477+ len = next->s_dentry->d_name.len;
37478+ memcpy(d_name, name, len);
37479+ name = d_name;
37480+ } else
37481+ len = strlen(name);
37482 if (next->s_dentry)
37483 ino = next->s_dentry->d_inode->i_ino;
37484 else
37485diff -urNp linux-2.6.32.41/fs/dcache.c linux-2.6.32.41/fs/dcache.c
37486--- linux-2.6.32.41/fs/dcache.c 2011-03-27 14:31:47.000000000 -0400
37487+++ linux-2.6.32.41/fs/dcache.c 2011-04-23 13:32:21.000000000 -0400
37488@@ -45,8 +45,6 @@ EXPORT_SYMBOL(dcache_lock);
37489
37490 static struct kmem_cache *dentry_cache __read_mostly;
37491
37492-#define DNAME_INLINE_LEN (sizeof(struct dentry)-offsetof(struct dentry,d_iname))
37493-
37494 /*
37495 * This is the single most critical data structure when it comes
37496 * to the dcache: the hashtable for lookups. Somebody should try
37497@@ -2319,7 +2317,7 @@ void __init vfs_caches_init(unsigned lon
37498 mempages -= reserve;
37499
37500 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
37501- SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
37502+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
37503
37504 dcache_init();
37505 inode_init();
37506diff -urNp linux-2.6.32.41/fs/dlm/lockspace.c linux-2.6.32.41/fs/dlm/lockspace.c
37507--- linux-2.6.32.41/fs/dlm/lockspace.c 2011-03-27 14:31:47.000000000 -0400
37508+++ linux-2.6.32.41/fs/dlm/lockspace.c 2011-04-17 15:56:46.000000000 -0400
37509@@ -148,7 +148,7 @@ static void lockspace_kobj_release(struc
37510 kfree(ls);
37511 }
37512
37513-static struct sysfs_ops dlm_attr_ops = {
37514+static const struct sysfs_ops dlm_attr_ops = {
37515 .show = dlm_attr_show,
37516 .store = dlm_attr_store,
37517 };
37518diff -urNp linux-2.6.32.41/fs/ecryptfs/inode.c linux-2.6.32.41/fs/ecryptfs/inode.c
37519--- linux-2.6.32.41/fs/ecryptfs/inode.c 2011-03-27 14:31:47.000000000 -0400
37520+++ linux-2.6.32.41/fs/ecryptfs/inode.c 2011-04-17 15:56:46.000000000 -0400
37521@@ -660,7 +660,7 @@ static int ecryptfs_readlink_lower(struc
37522 old_fs = get_fs();
37523 set_fs(get_ds());
37524 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
37525- (char __user *)lower_buf,
37526+ (__force char __user *)lower_buf,
37527 lower_bufsiz);
37528 set_fs(old_fs);
37529 if (rc < 0)
37530@@ -706,7 +706,7 @@ static void *ecryptfs_follow_link(struct
37531 }
37532 old_fs = get_fs();
37533 set_fs(get_ds());
37534- rc = dentry->d_inode->i_op->readlink(dentry, (char __user *)buf, len);
37535+ rc = dentry->d_inode->i_op->readlink(dentry, (__force char __user *)buf, len);
37536 set_fs(old_fs);
37537 if (rc < 0)
37538 goto out_free;
37539diff -urNp linux-2.6.32.41/fs/exec.c linux-2.6.32.41/fs/exec.c
37540--- linux-2.6.32.41/fs/exec.c 2011-04-17 17:00:52.000000000 -0400
37541+++ linux-2.6.32.41/fs/exec.c 2011-06-04 20:41:36.000000000 -0400
37542@@ -56,12 +56,24 @@
37543 #include <linux/fsnotify.h>
37544 #include <linux/fs_struct.h>
37545 #include <linux/pipe_fs_i.h>
37546+#include <linux/random.h>
37547+#include <linux/seq_file.h>
37548+
37549+#ifdef CONFIG_PAX_REFCOUNT
37550+#include <linux/kallsyms.h>
37551+#include <linux/kdebug.h>
37552+#endif
37553
37554 #include <asm/uaccess.h>
37555 #include <asm/mmu_context.h>
37556 #include <asm/tlb.h>
37557 #include "internal.h"
37558
37559+#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
37560+void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
37561+EXPORT_SYMBOL(pax_set_initial_flags_func);
37562+#endif
37563+
37564 int core_uses_pid;
37565 char core_pattern[CORENAME_MAX_SIZE] = "core";
37566 unsigned int core_pipe_limit;
37567@@ -115,7 +127,7 @@ SYSCALL_DEFINE1(uselib, const char __use
37568 goto out;
37569
37570 file = do_filp_open(AT_FDCWD, tmp,
37571- O_LARGEFILE | O_RDONLY | FMODE_EXEC, 0,
37572+ O_LARGEFILE | O_RDONLY | FMODE_EXEC | FMODE_GREXEC, 0,
37573 MAY_READ | MAY_EXEC | MAY_OPEN);
37574 putname(tmp);
37575 error = PTR_ERR(file);
37576@@ -178,18 +190,10 @@ struct page *get_arg_page(struct linux_b
37577 int write)
37578 {
37579 struct page *page;
37580- int ret;
37581
37582-#ifdef CONFIG_STACK_GROWSUP
37583- if (write) {
37584- ret = expand_stack_downwards(bprm->vma, pos);
37585- if (ret < 0)
37586- return NULL;
37587- }
37588-#endif
37589- ret = get_user_pages(current, bprm->mm, pos,
37590- 1, write, 1, &page, NULL);
37591- if (ret <= 0)
37592+ if (0 > expand_stack_downwards(bprm->vma, pos))
37593+ return NULL;
37594+ if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
37595 return NULL;
37596
37597 if (write) {
37598@@ -263,6 +267,11 @@ static int __bprm_mm_init(struct linux_b
37599 vma->vm_end = STACK_TOP_MAX;
37600 vma->vm_start = vma->vm_end - PAGE_SIZE;
37601 vma->vm_flags = VM_STACK_FLAGS;
37602+
37603+#ifdef CONFIG_PAX_SEGMEXEC
37604+ vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
37605+#endif
37606+
37607 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
37608
37609 err = security_file_mmap(NULL, 0, 0, 0, vma->vm_start, 1);
37610@@ -276,6 +285,12 @@ static int __bprm_mm_init(struct linux_b
37611 mm->stack_vm = mm->total_vm = 1;
37612 up_write(&mm->mmap_sem);
37613 bprm->p = vma->vm_end - sizeof(void *);
37614+
37615+#ifdef CONFIG_PAX_RANDUSTACK
37616+ if (randomize_va_space)
37617+ bprm->p ^= (pax_get_random_long() & ~15) & ~PAGE_MASK;
37618+#endif
37619+
37620 return 0;
37621 err:
37622 up_write(&mm->mmap_sem);
37623@@ -510,7 +525,7 @@ int copy_strings_kernel(int argc,char **
37624 int r;
37625 mm_segment_t oldfs = get_fs();
37626 set_fs(KERNEL_DS);
37627- r = copy_strings(argc, (char __user * __user *)argv, bprm);
37628+ r = copy_strings(argc, (__force char __user * __user *)argv, bprm);
37629 set_fs(oldfs);
37630 return r;
37631 }
37632@@ -540,7 +555,8 @@ static int shift_arg_pages(struct vm_are
37633 unsigned long new_end = old_end - shift;
37634 struct mmu_gather *tlb;
37635
37636- BUG_ON(new_start > new_end);
37637+ if (new_start >= new_end || new_start < mmap_min_addr)
37638+ return -ENOMEM;
37639
37640 /*
37641 * ensure there are no vmas between where we want to go
37642@@ -549,6 +565,10 @@ static int shift_arg_pages(struct vm_are
37643 if (vma != find_vma(mm, new_start))
37644 return -EFAULT;
37645
37646+#ifdef CONFIG_PAX_SEGMEXEC
37647+ BUG_ON(pax_find_mirror_vma(vma));
37648+#endif
37649+
37650 /*
37651 * cover the whole range: [new_start, old_end)
37652 */
37653@@ -630,10 +650,6 @@ int setup_arg_pages(struct linux_binprm
37654 stack_top = arch_align_stack(stack_top);
37655 stack_top = PAGE_ALIGN(stack_top);
37656
37657- if (unlikely(stack_top < mmap_min_addr) ||
37658- unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
37659- return -ENOMEM;
37660-
37661 stack_shift = vma->vm_end - stack_top;
37662
37663 bprm->p -= stack_shift;
37664@@ -645,6 +661,14 @@ int setup_arg_pages(struct linux_binprm
37665 bprm->exec -= stack_shift;
37666
37667 down_write(&mm->mmap_sem);
37668+
37669+ /* Move stack pages down in memory. */
37670+ if (stack_shift) {
37671+ ret = shift_arg_pages(vma, stack_shift);
37672+ if (ret)
37673+ goto out_unlock;
37674+ }
37675+
37676 vm_flags = VM_STACK_FLAGS;
37677
37678 /*
37679@@ -658,19 +682,24 @@ int setup_arg_pages(struct linux_binprm
37680 vm_flags &= ~VM_EXEC;
37681 vm_flags |= mm->def_flags;
37682
37683+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
37684+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
37685+ vm_flags &= ~VM_EXEC;
37686+
37687+#ifdef CONFIG_PAX_MPROTECT
37688+ if (mm->pax_flags & MF_PAX_MPROTECT)
37689+ vm_flags &= ~VM_MAYEXEC;
37690+#endif
37691+
37692+ }
37693+#endif
37694+
37695 ret = mprotect_fixup(vma, &prev, vma->vm_start, vma->vm_end,
37696 vm_flags);
37697 if (ret)
37698 goto out_unlock;
37699 BUG_ON(prev != vma);
37700
37701- /* Move stack pages down in memory. */
37702- if (stack_shift) {
37703- ret = shift_arg_pages(vma, stack_shift);
37704- if (ret)
37705- goto out_unlock;
37706- }
37707-
37708 stack_expand = EXTRA_STACK_VM_PAGES * PAGE_SIZE;
37709 stack_size = vma->vm_end - vma->vm_start;
37710 /*
37711@@ -707,7 +736,7 @@ struct file *open_exec(const char *name)
37712 int err;
37713
37714 file = do_filp_open(AT_FDCWD, name,
37715- O_LARGEFILE | O_RDONLY | FMODE_EXEC, 0,
37716+ O_LARGEFILE | O_RDONLY | FMODE_EXEC | FMODE_GREXEC, 0,
37717 MAY_EXEC | MAY_OPEN);
37718 if (IS_ERR(file))
37719 goto out;
37720@@ -744,7 +773,7 @@ int kernel_read(struct file *file, loff_
37721 old_fs = get_fs();
37722 set_fs(get_ds());
37723 /* The cast to a user pointer is valid due to the set_fs() */
37724- result = vfs_read(file, (void __user *)addr, count, &pos);
37725+ result = vfs_read(file, (__force void __user *)addr, count, &pos);
37726 set_fs(old_fs);
37727 return result;
37728 }
37729@@ -1151,7 +1180,7 @@ int check_unsafe_exec(struct linux_binpr
37730 }
37731 rcu_read_unlock();
37732
37733- if (p->fs->users > n_fs) {
37734+ if (atomic_read(&p->fs->users) > n_fs) {
37735 bprm->unsafe |= LSM_UNSAFE_SHARE;
37736 } else {
37737 res = -EAGAIN;
37738@@ -1350,6 +1379,11 @@ int do_execve(char * filename,
37739 char __user *__user *envp,
37740 struct pt_regs * regs)
37741 {
37742+#ifdef CONFIG_GRKERNSEC
37743+ struct file *old_exec_file;
37744+ struct acl_subject_label *old_acl;
37745+ struct rlimit old_rlim[RLIM_NLIMITS];
37746+#endif
37747 struct linux_binprm *bprm;
37748 struct file *file;
37749 struct files_struct *displaced;
37750@@ -1386,6 +1420,23 @@ int do_execve(char * filename,
37751 bprm->filename = filename;
37752 bprm->interp = filename;
37753
37754+ if (gr_process_user_ban()) {
37755+ retval = -EPERM;
37756+ goto out_file;
37757+ }
37758+
37759+ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
37760+
37761+ if (gr_handle_nproc()) {
37762+ retval = -EAGAIN;
37763+ goto out_file;
37764+ }
37765+
37766+ if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
37767+ retval = -EACCES;
37768+ goto out_file;
37769+ }
37770+
37771 retval = bprm_mm_init(bprm);
37772 if (retval)
37773 goto out_file;
37774@@ -1415,10 +1466,41 @@ int do_execve(char * filename,
37775 if (retval < 0)
37776 goto out;
37777
37778+ if (!gr_tpe_allow(file)) {
37779+ retval = -EACCES;
37780+ goto out;
37781+ }
37782+
37783+ if (gr_check_crash_exec(file)) {
37784+ retval = -EACCES;
37785+ goto out;
37786+ }
37787+
37788+ gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
37789+
37790+ gr_handle_exec_args(bprm, (const char __user *const __user *)argv);
37791+
37792+#ifdef CONFIG_GRKERNSEC
37793+ old_acl = current->acl;
37794+ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
37795+ old_exec_file = current->exec_file;
37796+ get_file(file);
37797+ current->exec_file = file;
37798+#endif
37799+
37800+ retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
37801+ bprm->unsafe & LSM_UNSAFE_SHARE);
37802+ if (retval < 0)
37803+ goto out_fail;
37804+
37805 current->flags &= ~PF_KTHREAD;
37806 retval = search_binary_handler(bprm,regs);
37807 if (retval < 0)
37808- goto out;
37809+ goto out_fail;
37810+#ifdef CONFIG_GRKERNSEC
37811+ if (old_exec_file)
37812+ fput(old_exec_file);
37813+#endif
37814
37815 /* execve succeeded */
37816 current->fs->in_exec = 0;
37817@@ -1429,6 +1511,14 @@ int do_execve(char * filename,
37818 put_files_struct(displaced);
37819 return retval;
37820
37821+out_fail:
37822+#ifdef CONFIG_GRKERNSEC
37823+ current->acl = old_acl;
37824+ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
37825+ fput(current->exec_file);
37826+ current->exec_file = old_exec_file;
37827+#endif
37828+
37829 out:
37830 if (bprm->mm) {
37831 acct_arg_size(bprm, 0);
37832@@ -1594,6 +1684,220 @@ out:
37833 return ispipe;
37834 }
37835
37836+int pax_check_flags(unsigned long *flags)
37837+{
37838+ int retval = 0;
37839+
37840+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
37841+ if (*flags & MF_PAX_SEGMEXEC)
37842+ {
37843+ *flags &= ~MF_PAX_SEGMEXEC;
37844+ retval = -EINVAL;
37845+ }
37846+#endif
37847+
37848+ if ((*flags & MF_PAX_PAGEEXEC)
37849+
37850+#ifdef CONFIG_PAX_PAGEEXEC
37851+ && (*flags & MF_PAX_SEGMEXEC)
37852+#endif
37853+
37854+ )
37855+ {
37856+ *flags &= ~MF_PAX_PAGEEXEC;
37857+ retval = -EINVAL;
37858+ }
37859+
37860+ if ((*flags & MF_PAX_MPROTECT)
37861+
37862+#ifdef CONFIG_PAX_MPROTECT
37863+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
37864+#endif
37865+
37866+ )
37867+ {
37868+ *flags &= ~MF_PAX_MPROTECT;
37869+ retval = -EINVAL;
37870+ }
37871+
37872+ if ((*flags & MF_PAX_EMUTRAMP)
37873+
37874+#ifdef CONFIG_PAX_EMUTRAMP
37875+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
37876+#endif
37877+
37878+ )
37879+ {
37880+ *flags &= ~MF_PAX_EMUTRAMP;
37881+ retval = -EINVAL;
37882+ }
37883+
37884+ return retval;
37885+}
37886+
37887+EXPORT_SYMBOL(pax_check_flags);
37888+
37889+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
37890+void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
37891+{
37892+ struct task_struct *tsk = current;
37893+ struct mm_struct *mm = current->mm;
37894+ char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
37895+ char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
37896+ char *path_exec = NULL;
37897+ char *path_fault = NULL;
37898+ unsigned long start = 0UL, end = 0UL, offset = 0UL;
37899+
37900+ if (buffer_exec && buffer_fault) {
37901+ struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
37902+
37903+ down_read(&mm->mmap_sem);
37904+ vma = mm->mmap;
37905+ while (vma && (!vma_exec || !vma_fault)) {
37906+ if ((vma->vm_flags & VM_EXECUTABLE) && vma->vm_file)
37907+ vma_exec = vma;
37908+ if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
37909+ vma_fault = vma;
37910+ vma = vma->vm_next;
37911+ }
37912+ if (vma_exec) {
37913+ path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
37914+ if (IS_ERR(path_exec))
37915+ path_exec = "<path too long>";
37916+ else {
37917+ path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
37918+ if (path_exec) {
37919+ *path_exec = 0;
37920+ path_exec = buffer_exec;
37921+ } else
37922+ path_exec = "<path too long>";
37923+ }
37924+ }
37925+ if (vma_fault) {
37926+ start = vma_fault->vm_start;
37927+ end = vma_fault->vm_end;
37928+ offset = vma_fault->vm_pgoff << PAGE_SHIFT;
37929+ if (vma_fault->vm_file) {
37930+ path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
37931+ if (IS_ERR(path_fault))
37932+ path_fault = "<path too long>";
37933+ else {
37934+ path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
37935+ if (path_fault) {
37936+ *path_fault = 0;
37937+ path_fault = buffer_fault;
37938+ } else
37939+ path_fault = "<path too long>";
37940+ }
37941+ } else
37942+ path_fault = "<anonymous mapping>";
37943+ }
37944+ up_read(&mm->mmap_sem);
37945+ }
37946+ if (tsk->signal->curr_ip)
37947+ printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
37948+ else
37949+ printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
37950+ printk(KERN_ERR "PAX: terminating task: %s(%s):%d, uid/euid: %u/%u, "
37951+ "PC: %p, SP: %p\n", path_exec, tsk->comm, task_pid_nr(tsk),
37952+ task_uid(tsk), task_euid(tsk), pc, sp);
37953+ free_page((unsigned long)buffer_exec);
37954+ free_page((unsigned long)buffer_fault);
37955+ pax_report_insns(pc, sp);
37956+ do_coredump(SIGKILL, SIGKILL, regs);
37957+}
37958+#endif
37959+
37960+#ifdef CONFIG_PAX_REFCOUNT
37961+void pax_report_refcount_overflow(struct pt_regs *regs)
37962+{
37963+ if (current->signal->curr_ip)
37964+ printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
37965+ &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
37966+ else
37967+ printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
37968+ current->comm, task_pid_nr(current), current_uid(), current_euid());
37969+ print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
37970+ show_regs(regs);
37971+ force_sig_specific(SIGKILL, current);
37972+}
37973+#endif
37974+
37975+#ifdef CONFIG_PAX_USERCOPY
37976+/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
37977+int object_is_on_stack(const void *obj, unsigned long len)
37978+{
37979+ const void * const stack = task_stack_page(current);
37980+ const void * const stackend = stack + THREAD_SIZE;
37981+
37982+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
37983+ const void *frame = NULL;
37984+ const void *oldframe;
37985+#endif
37986+
37987+ if (obj + len < obj)
37988+ return -1;
37989+
37990+ if (obj + len <= stack || stackend <= obj)
37991+ return 0;
37992+
37993+ if (obj < stack || stackend < obj + len)
37994+ return -1;
37995+
37996+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
37997+ oldframe = __builtin_frame_address(1);
37998+ if (oldframe)
37999+ frame = __builtin_frame_address(2);
38000+ /*
38001+ low ----------------------------------------------> high
38002+ [saved bp][saved ip][args][local vars][saved bp][saved ip]
38003+ ^----------------^
38004+ allow copies only within here
38005+ */
38006+ while (stack <= frame && frame < stackend) {
38007+ /* if obj + len extends past the last frame, this
38008+ check won't pass and the next frame will be 0,
38009+ causing us to bail out and correctly report
38010+ the copy as invalid
38011+ */
38012+ if (obj + len <= frame)
38013+ return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
38014+ oldframe = frame;
38015+ frame = *(const void * const *)frame;
38016+ }
38017+ return -1;
38018+#else
38019+ return 1;
38020+#endif
38021+}
38022+
38023+
38024+void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type)
38025+{
38026+ if (current->signal->curr_ip)
38027+ printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
38028+ &current->signal->curr_ip, to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
38029+ else
38030+ printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
38031+ to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
38032+
38033+ dump_stack();
38034+ gr_handle_kernel_exploit();
38035+ do_group_exit(SIGKILL);
38036+}
38037+#endif
38038+
38039+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
38040+void pax_track_stack(void)
38041+{
38042+ unsigned long sp = (unsigned long)&sp;
38043+ if (sp < current_thread_info()->lowest_stack &&
38044+ sp > (unsigned long)task_stack_page(current))
38045+ current_thread_info()->lowest_stack = sp;
38046+}
38047+EXPORT_SYMBOL(pax_track_stack);
38048+#endif
38049+
38050 static int zap_process(struct task_struct *start)
38051 {
38052 struct task_struct *t;
38053@@ -1796,17 +2100,17 @@ static void wait_for_dump_helpers(struct
38054 pipe = file->f_path.dentry->d_inode->i_pipe;
38055
38056 pipe_lock(pipe);
38057- pipe->readers++;
38058- pipe->writers--;
38059+ atomic_inc(&pipe->readers);
38060+ atomic_dec(&pipe->writers);
38061
38062- while ((pipe->readers > 1) && (!signal_pending(current))) {
38063+ while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
38064 wake_up_interruptible_sync(&pipe->wait);
38065 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
38066 pipe_wait(pipe);
38067 }
38068
38069- pipe->readers--;
38070- pipe->writers++;
38071+ atomic_dec(&pipe->readers);
38072+ atomic_inc(&pipe->writers);
38073 pipe_unlock(pipe);
38074
38075 }
38076@@ -1829,10 +2133,13 @@ void do_coredump(long signr, int exit_co
38077 char **helper_argv = NULL;
38078 int helper_argc = 0;
38079 int dump_count = 0;
38080- static atomic_t core_dump_count = ATOMIC_INIT(0);
38081+ static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
38082
38083 audit_core_dumps(signr);
38084
38085+ if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
38086+ gr_handle_brute_attach(current, mm->flags);
38087+
38088 binfmt = mm->binfmt;
38089 if (!binfmt || !binfmt->core_dump)
38090 goto fail;
38091@@ -1877,6 +2184,8 @@ void do_coredump(long signr, int exit_co
38092 */
38093 clear_thread_flag(TIF_SIGPENDING);
38094
38095+ gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
38096+
38097 /*
38098 * lock_kernel() because format_corename() is controlled by sysctl, which
38099 * uses lock_kernel()
38100@@ -1911,7 +2220,7 @@ void do_coredump(long signr, int exit_co
38101 goto fail_unlock;
38102 }
38103
38104- dump_count = atomic_inc_return(&core_dump_count);
38105+ dump_count = atomic_inc_return_unchecked(&core_dump_count);
38106 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
38107 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
38108 task_tgid_vnr(current), current->comm);
38109@@ -1975,7 +2284,7 @@ close_fail:
38110 filp_close(file, NULL);
38111 fail_dropcount:
38112 if (dump_count)
38113- atomic_dec(&core_dump_count);
38114+ atomic_dec_unchecked(&core_dump_count);
38115 fail_unlock:
38116 if (helper_argv)
38117 argv_free(helper_argv);
38118diff -urNp linux-2.6.32.41/fs/ext2/balloc.c linux-2.6.32.41/fs/ext2/balloc.c
38119--- linux-2.6.32.41/fs/ext2/balloc.c 2011-03-27 14:31:47.000000000 -0400
38120+++ linux-2.6.32.41/fs/ext2/balloc.c 2011-04-17 15:56:46.000000000 -0400
38121@@ -1192,7 +1192,7 @@ static int ext2_has_free_blocks(struct e
38122
38123 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
38124 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
38125- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
38126+ if (free_blocks < root_blocks + 1 && !capable_nolog(CAP_SYS_RESOURCE) &&
38127 sbi->s_resuid != current_fsuid() &&
38128 (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
38129 return 0;
38130diff -urNp linux-2.6.32.41/fs/ext3/balloc.c linux-2.6.32.41/fs/ext3/balloc.c
38131--- linux-2.6.32.41/fs/ext3/balloc.c 2011-03-27 14:31:47.000000000 -0400
38132+++ linux-2.6.32.41/fs/ext3/balloc.c 2011-04-17 15:56:46.000000000 -0400
38133@@ -1421,7 +1421,7 @@ static int ext3_has_free_blocks(struct e
38134
38135 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
38136 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
38137- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
38138+ if (free_blocks < root_blocks + 1 && !capable_nolog(CAP_SYS_RESOURCE) &&
38139 sbi->s_resuid != current_fsuid() &&
38140 (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
38141 return 0;
38142diff -urNp linux-2.6.32.41/fs/ext4/balloc.c linux-2.6.32.41/fs/ext4/balloc.c
38143--- linux-2.6.32.41/fs/ext4/balloc.c 2011-03-27 14:31:47.000000000 -0400
38144+++ linux-2.6.32.41/fs/ext4/balloc.c 2011-04-17 15:56:46.000000000 -0400
38145@@ -570,7 +570,7 @@ int ext4_has_free_blocks(struct ext4_sb_
38146 /* Hm, nope. Are (enough) root reserved blocks available? */
38147 if (sbi->s_resuid == current_fsuid() ||
38148 ((sbi->s_resgid != 0) && in_group_p(sbi->s_resgid)) ||
38149- capable(CAP_SYS_RESOURCE)) {
38150+ capable_nolog(CAP_SYS_RESOURCE)) {
38151 if (free_blocks >= (nblocks + dirty_blocks))
38152 return 1;
38153 }
38154diff -urNp linux-2.6.32.41/fs/ext4/ext4.h linux-2.6.32.41/fs/ext4/ext4.h
38155--- linux-2.6.32.41/fs/ext4/ext4.h 2011-03-27 14:31:47.000000000 -0400
38156+++ linux-2.6.32.41/fs/ext4/ext4.h 2011-04-17 15:56:46.000000000 -0400
38157@@ -1078,19 +1078,19 @@ struct ext4_sb_info {
38158
38159 /* stats for buddy allocator */
38160 spinlock_t s_mb_pa_lock;
38161- atomic_t s_bal_reqs; /* number of reqs with len > 1 */
38162- atomic_t s_bal_success; /* we found long enough chunks */
38163- atomic_t s_bal_allocated; /* in blocks */
38164- atomic_t s_bal_ex_scanned; /* total extents scanned */
38165- atomic_t s_bal_goals; /* goal hits */
38166- atomic_t s_bal_breaks; /* too long searches */
38167- atomic_t s_bal_2orders; /* 2^order hits */
38168+ atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
38169+ atomic_unchecked_t s_bal_success; /* we found long enough chunks */
38170+ atomic_unchecked_t s_bal_allocated; /* in blocks */
38171+ atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
38172+ atomic_unchecked_t s_bal_goals; /* goal hits */
38173+ atomic_unchecked_t s_bal_breaks; /* too long searches */
38174+ atomic_unchecked_t s_bal_2orders; /* 2^order hits */
38175 spinlock_t s_bal_lock;
38176 unsigned long s_mb_buddies_generated;
38177 unsigned long long s_mb_generation_time;
38178- atomic_t s_mb_lost_chunks;
38179- atomic_t s_mb_preallocated;
38180- atomic_t s_mb_discarded;
38181+ atomic_unchecked_t s_mb_lost_chunks;
38182+ atomic_unchecked_t s_mb_preallocated;
38183+ atomic_unchecked_t s_mb_discarded;
38184 atomic_t s_lock_busy;
38185
38186 /* locality groups */
38187diff -urNp linux-2.6.32.41/fs/ext4/mballoc.c linux-2.6.32.41/fs/ext4/mballoc.c
38188--- linux-2.6.32.41/fs/ext4/mballoc.c 2011-03-27 14:31:47.000000000 -0400
38189+++ linux-2.6.32.41/fs/ext4/mballoc.c 2011-05-16 21:46:57.000000000 -0400
38190@@ -1753,7 +1753,7 @@ void ext4_mb_simple_scan_group(struct ex
38191 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
38192
38193 if (EXT4_SB(sb)->s_mb_stats)
38194- atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
38195+ atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
38196
38197 break;
38198 }
38199@@ -2129,7 +2129,7 @@ repeat:
38200 ac->ac_status = AC_STATUS_CONTINUE;
38201 ac->ac_flags |= EXT4_MB_HINT_FIRST;
38202 cr = 3;
38203- atomic_inc(&sbi->s_mb_lost_chunks);
38204+ atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
38205 goto repeat;
38206 }
38207 }
38208@@ -2172,6 +2172,8 @@ static int ext4_mb_seq_groups_show(struc
38209 ext4_grpblk_t counters[16];
38210 } sg;
38211
38212+ pax_track_stack();
38213+
38214 group--;
38215 if (group == 0)
38216 seq_printf(seq, "#%-5s: %-5s %-5s %-5s "
38217@@ -2532,25 +2534,25 @@ int ext4_mb_release(struct super_block *
38218 if (sbi->s_mb_stats) {
38219 printk(KERN_INFO
38220 "EXT4-fs: mballoc: %u blocks %u reqs (%u success)\n",
38221- atomic_read(&sbi->s_bal_allocated),
38222- atomic_read(&sbi->s_bal_reqs),
38223- atomic_read(&sbi->s_bal_success));
38224+ atomic_read_unchecked(&sbi->s_bal_allocated),
38225+ atomic_read_unchecked(&sbi->s_bal_reqs),
38226+ atomic_read_unchecked(&sbi->s_bal_success));
38227 printk(KERN_INFO
38228 "EXT4-fs: mballoc: %u extents scanned, %u goal hits, "
38229 "%u 2^N hits, %u breaks, %u lost\n",
38230- atomic_read(&sbi->s_bal_ex_scanned),
38231- atomic_read(&sbi->s_bal_goals),
38232- atomic_read(&sbi->s_bal_2orders),
38233- atomic_read(&sbi->s_bal_breaks),
38234- atomic_read(&sbi->s_mb_lost_chunks));
38235+ atomic_read_unchecked(&sbi->s_bal_ex_scanned),
38236+ atomic_read_unchecked(&sbi->s_bal_goals),
38237+ atomic_read_unchecked(&sbi->s_bal_2orders),
38238+ atomic_read_unchecked(&sbi->s_bal_breaks),
38239+ atomic_read_unchecked(&sbi->s_mb_lost_chunks));
38240 printk(KERN_INFO
38241 "EXT4-fs: mballoc: %lu generated and it took %Lu\n",
38242 sbi->s_mb_buddies_generated++,
38243 sbi->s_mb_generation_time);
38244 printk(KERN_INFO
38245 "EXT4-fs: mballoc: %u preallocated, %u discarded\n",
38246- atomic_read(&sbi->s_mb_preallocated),
38247- atomic_read(&sbi->s_mb_discarded));
38248+ atomic_read_unchecked(&sbi->s_mb_preallocated),
38249+ atomic_read_unchecked(&sbi->s_mb_discarded));
38250 }
38251
38252 free_percpu(sbi->s_locality_groups);
38253@@ -3032,16 +3034,16 @@ static void ext4_mb_collect_stats(struct
38254 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
38255
38256 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
38257- atomic_inc(&sbi->s_bal_reqs);
38258- atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
38259+ atomic_inc_unchecked(&sbi->s_bal_reqs);
38260+ atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
38261 if (ac->ac_o_ex.fe_len >= ac->ac_g_ex.fe_len)
38262- atomic_inc(&sbi->s_bal_success);
38263- atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
38264+ atomic_inc_unchecked(&sbi->s_bal_success);
38265+ atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
38266 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
38267 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
38268- atomic_inc(&sbi->s_bal_goals);
38269+ atomic_inc_unchecked(&sbi->s_bal_goals);
38270 if (ac->ac_found > sbi->s_mb_max_to_scan)
38271- atomic_inc(&sbi->s_bal_breaks);
38272+ atomic_inc_unchecked(&sbi->s_bal_breaks);
38273 }
38274
38275 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
38276@@ -3441,7 +3443,7 @@ ext4_mb_new_inode_pa(struct ext4_allocat
38277 trace_ext4_mb_new_inode_pa(ac, pa);
38278
38279 ext4_mb_use_inode_pa(ac, pa);
38280- atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
38281+ atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
38282
38283 ei = EXT4_I(ac->ac_inode);
38284 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
38285@@ -3501,7 +3503,7 @@ ext4_mb_new_group_pa(struct ext4_allocat
38286 trace_ext4_mb_new_group_pa(ac, pa);
38287
38288 ext4_mb_use_group_pa(ac, pa);
38289- atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
38290+ atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
38291
38292 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
38293 lg = ac->ac_lg;
38294@@ -3605,7 +3607,7 @@ ext4_mb_release_inode_pa(struct ext4_bud
38295 * from the bitmap and continue.
38296 */
38297 }
38298- atomic_add(free, &sbi->s_mb_discarded);
38299+ atomic_add_unchecked(free, &sbi->s_mb_discarded);
38300
38301 return err;
38302 }
38303@@ -3624,7 +3626,7 @@ ext4_mb_release_group_pa(struct ext4_bud
38304 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
38305 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
38306 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
38307- atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
38308+ atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
38309
38310 if (ac) {
38311 ac->ac_sb = sb;
38312diff -urNp linux-2.6.32.41/fs/ext4/super.c linux-2.6.32.41/fs/ext4/super.c
38313--- linux-2.6.32.41/fs/ext4/super.c 2011-03-27 14:31:47.000000000 -0400
38314+++ linux-2.6.32.41/fs/ext4/super.c 2011-04-17 15:56:46.000000000 -0400
38315@@ -2287,7 +2287,7 @@ static void ext4_sb_release(struct kobje
38316 }
38317
38318
38319-static struct sysfs_ops ext4_attr_ops = {
38320+static const struct sysfs_ops ext4_attr_ops = {
38321 .show = ext4_attr_show,
38322 .store = ext4_attr_store,
38323 };
38324diff -urNp linux-2.6.32.41/fs/fcntl.c linux-2.6.32.41/fs/fcntl.c
38325--- linux-2.6.32.41/fs/fcntl.c 2011-03-27 14:31:47.000000000 -0400
38326+++ linux-2.6.32.41/fs/fcntl.c 2011-04-17 15:56:46.000000000 -0400
38327@@ -223,6 +223,11 @@ int __f_setown(struct file *filp, struct
38328 if (err)
38329 return err;
38330
38331+ if (gr_handle_chroot_fowner(pid, type))
38332+ return -ENOENT;
38333+ if (gr_check_protected_task_fowner(pid, type))
38334+ return -EACCES;
38335+
38336 f_modown(filp, pid, type, force);
38337 return 0;
38338 }
38339@@ -344,6 +349,7 @@ static long do_fcntl(int fd, unsigned in
38340 switch (cmd) {
38341 case F_DUPFD:
38342 case F_DUPFD_CLOEXEC:
38343+ gr_learn_resource(current, RLIMIT_NOFILE, arg, 0);
38344 if (arg >= current->signal->rlim[RLIMIT_NOFILE].rlim_cur)
38345 break;
38346 err = alloc_fd(arg, cmd == F_DUPFD_CLOEXEC ? O_CLOEXEC : 0);
38347diff -urNp linux-2.6.32.41/fs/fifo.c linux-2.6.32.41/fs/fifo.c
38348--- linux-2.6.32.41/fs/fifo.c 2011-03-27 14:31:47.000000000 -0400
38349+++ linux-2.6.32.41/fs/fifo.c 2011-04-17 15:56:46.000000000 -0400
38350@@ -59,10 +59,10 @@ static int fifo_open(struct inode *inode
38351 */
38352 filp->f_op = &read_pipefifo_fops;
38353 pipe->r_counter++;
38354- if (pipe->readers++ == 0)
38355+ if (atomic_inc_return(&pipe->readers) == 1)
38356 wake_up_partner(inode);
38357
38358- if (!pipe->writers) {
38359+ if (!atomic_read(&pipe->writers)) {
38360 if ((filp->f_flags & O_NONBLOCK)) {
38361 /* suppress POLLHUP until we have
38362 * seen a writer */
38363@@ -83,15 +83,15 @@ static int fifo_open(struct inode *inode
38364 * errno=ENXIO when there is no process reading the FIFO.
38365 */
38366 ret = -ENXIO;
38367- if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
38368+ if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
38369 goto err;
38370
38371 filp->f_op = &write_pipefifo_fops;
38372 pipe->w_counter++;
38373- if (!pipe->writers++)
38374+ if (atomic_inc_return(&pipe->writers) == 1)
38375 wake_up_partner(inode);
38376
38377- if (!pipe->readers) {
38378+ if (!atomic_read(&pipe->readers)) {
38379 wait_for_partner(inode, &pipe->r_counter);
38380 if (signal_pending(current))
38381 goto err_wr;
38382@@ -107,11 +107,11 @@ static int fifo_open(struct inode *inode
38383 */
38384 filp->f_op = &rdwr_pipefifo_fops;
38385
38386- pipe->readers++;
38387- pipe->writers++;
38388+ atomic_inc(&pipe->readers);
38389+ atomic_inc(&pipe->writers);
38390 pipe->r_counter++;
38391 pipe->w_counter++;
38392- if (pipe->readers == 1 || pipe->writers == 1)
38393+ if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
38394 wake_up_partner(inode);
38395 break;
38396
38397@@ -125,19 +125,19 @@ static int fifo_open(struct inode *inode
38398 return 0;
38399
38400 err_rd:
38401- if (!--pipe->readers)
38402+ if (atomic_dec_and_test(&pipe->readers))
38403 wake_up_interruptible(&pipe->wait);
38404 ret = -ERESTARTSYS;
38405 goto err;
38406
38407 err_wr:
38408- if (!--pipe->writers)
38409+ if (atomic_dec_and_test(&pipe->writers))
38410 wake_up_interruptible(&pipe->wait);
38411 ret = -ERESTARTSYS;
38412 goto err;
38413
38414 err:
38415- if (!pipe->readers && !pipe->writers)
38416+ if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
38417 free_pipe_info(inode);
38418
38419 err_nocleanup:
38420diff -urNp linux-2.6.32.41/fs/file.c linux-2.6.32.41/fs/file.c
38421--- linux-2.6.32.41/fs/file.c 2011-03-27 14:31:47.000000000 -0400
38422+++ linux-2.6.32.41/fs/file.c 2011-04-17 15:56:46.000000000 -0400
38423@@ -14,6 +14,7 @@
38424 #include <linux/slab.h>
38425 #include <linux/vmalloc.h>
38426 #include <linux/file.h>
38427+#include <linux/security.h>
38428 #include <linux/fdtable.h>
38429 #include <linux/bitops.h>
38430 #include <linux/interrupt.h>
38431@@ -257,6 +258,8 @@ int expand_files(struct files_struct *fi
38432 * N.B. For clone tasks sharing a files structure, this test
38433 * will limit the total number of files that can be opened.
38434 */
38435+
38436+ gr_learn_resource(current, RLIMIT_NOFILE, nr, 0);
38437 if (nr >= current->signal->rlim[RLIMIT_NOFILE].rlim_cur)
38438 return -EMFILE;
38439
38440diff -urNp linux-2.6.32.41/fs/filesystems.c linux-2.6.32.41/fs/filesystems.c
38441--- linux-2.6.32.41/fs/filesystems.c 2011-03-27 14:31:47.000000000 -0400
38442+++ linux-2.6.32.41/fs/filesystems.c 2011-04-17 15:56:46.000000000 -0400
38443@@ -272,7 +272,12 @@ struct file_system_type *get_fs_type(con
38444 int len = dot ? dot - name : strlen(name);
38445
38446 fs = __get_fs_type(name, len);
38447+
38448+#ifdef CONFIG_GRKERNSEC_MODHARDEN
38449+ if (!fs && (___request_module(true, "grsec_modharden_fs", "%.*s", len, name) == 0))
38450+#else
38451 if (!fs && (request_module("%.*s", len, name) == 0))
38452+#endif
38453 fs = __get_fs_type(name, len);
38454
38455 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
38456diff -urNp linux-2.6.32.41/fs/fscache/cookie.c linux-2.6.32.41/fs/fscache/cookie.c
38457--- linux-2.6.32.41/fs/fscache/cookie.c 2011-03-27 14:31:47.000000000 -0400
38458+++ linux-2.6.32.41/fs/fscache/cookie.c 2011-05-04 17:56:28.000000000 -0400
38459@@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire
38460 parent ? (char *) parent->def->name : "<no-parent>",
38461 def->name, netfs_data);
38462
38463- fscache_stat(&fscache_n_acquires);
38464+ fscache_stat_unchecked(&fscache_n_acquires);
38465
38466 /* if there's no parent cookie, then we don't create one here either */
38467 if (!parent) {
38468- fscache_stat(&fscache_n_acquires_null);
38469+ fscache_stat_unchecked(&fscache_n_acquires_null);
38470 _leave(" [no parent]");
38471 return NULL;
38472 }
38473@@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire
38474 /* allocate and initialise a cookie */
38475 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
38476 if (!cookie) {
38477- fscache_stat(&fscache_n_acquires_oom);
38478+ fscache_stat_unchecked(&fscache_n_acquires_oom);
38479 _leave(" [ENOMEM]");
38480 return NULL;
38481 }
38482@@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire
38483
38484 switch (cookie->def->type) {
38485 case FSCACHE_COOKIE_TYPE_INDEX:
38486- fscache_stat(&fscache_n_cookie_index);
38487+ fscache_stat_unchecked(&fscache_n_cookie_index);
38488 break;
38489 case FSCACHE_COOKIE_TYPE_DATAFILE:
38490- fscache_stat(&fscache_n_cookie_data);
38491+ fscache_stat_unchecked(&fscache_n_cookie_data);
38492 break;
38493 default:
38494- fscache_stat(&fscache_n_cookie_special);
38495+ fscache_stat_unchecked(&fscache_n_cookie_special);
38496 break;
38497 }
38498
38499@@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire
38500 if (fscache_acquire_non_index_cookie(cookie) < 0) {
38501 atomic_dec(&parent->n_children);
38502 __fscache_cookie_put(cookie);
38503- fscache_stat(&fscache_n_acquires_nobufs);
38504+ fscache_stat_unchecked(&fscache_n_acquires_nobufs);
38505 _leave(" = NULL");
38506 return NULL;
38507 }
38508 }
38509
38510- fscache_stat(&fscache_n_acquires_ok);
38511+ fscache_stat_unchecked(&fscache_n_acquires_ok);
38512 _leave(" = %p", cookie);
38513 return cookie;
38514 }
38515@@ -168,7 +168,7 @@ static int fscache_acquire_non_index_coo
38516 cache = fscache_select_cache_for_object(cookie->parent);
38517 if (!cache) {
38518 up_read(&fscache_addremove_sem);
38519- fscache_stat(&fscache_n_acquires_no_cache);
38520+ fscache_stat_unchecked(&fscache_n_acquires_no_cache);
38521 _leave(" = -ENOMEDIUM [no cache]");
38522 return -ENOMEDIUM;
38523 }
38524@@ -256,12 +256,12 @@ static int fscache_alloc_object(struct f
38525 object = cache->ops->alloc_object(cache, cookie);
38526 fscache_stat_d(&fscache_n_cop_alloc_object);
38527 if (IS_ERR(object)) {
38528- fscache_stat(&fscache_n_object_no_alloc);
38529+ fscache_stat_unchecked(&fscache_n_object_no_alloc);
38530 ret = PTR_ERR(object);
38531 goto error;
38532 }
38533
38534- fscache_stat(&fscache_n_object_alloc);
38535+ fscache_stat_unchecked(&fscache_n_object_alloc);
38536
38537 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
38538
38539@@ -377,10 +377,10 @@ void __fscache_update_cookie(struct fsca
38540 struct fscache_object *object;
38541 struct hlist_node *_p;
38542
38543- fscache_stat(&fscache_n_updates);
38544+ fscache_stat_unchecked(&fscache_n_updates);
38545
38546 if (!cookie) {
38547- fscache_stat(&fscache_n_updates_null);
38548+ fscache_stat_unchecked(&fscache_n_updates_null);
38549 _leave(" [no cookie]");
38550 return;
38551 }
38552@@ -414,12 +414,12 @@ void __fscache_relinquish_cookie(struct
38553 struct fscache_object *object;
38554 unsigned long event;
38555
38556- fscache_stat(&fscache_n_relinquishes);
38557+ fscache_stat_unchecked(&fscache_n_relinquishes);
38558 if (retire)
38559- fscache_stat(&fscache_n_relinquishes_retire);
38560+ fscache_stat_unchecked(&fscache_n_relinquishes_retire);
38561
38562 if (!cookie) {
38563- fscache_stat(&fscache_n_relinquishes_null);
38564+ fscache_stat_unchecked(&fscache_n_relinquishes_null);
38565 _leave(" [no cookie]");
38566 return;
38567 }
38568@@ -435,7 +435,7 @@ void __fscache_relinquish_cookie(struct
38569
38570 /* wait for the cookie to finish being instantiated (or to fail) */
38571 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
38572- fscache_stat(&fscache_n_relinquishes_waitcrt);
38573+ fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
38574 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
38575 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
38576 }
38577diff -urNp linux-2.6.32.41/fs/fscache/internal.h linux-2.6.32.41/fs/fscache/internal.h
38578--- linux-2.6.32.41/fs/fscache/internal.h 2011-03-27 14:31:47.000000000 -0400
38579+++ linux-2.6.32.41/fs/fscache/internal.h 2011-05-04 17:56:28.000000000 -0400
38580@@ -136,94 +136,94 @@ extern void fscache_proc_cleanup(void);
38581 extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
38582 extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
38583
38584-extern atomic_t fscache_n_op_pend;
38585-extern atomic_t fscache_n_op_run;
38586-extern atomic_t fscache_n_op_enqueue;
38587-extern atomic_t fscache_n_op_deferred_release;
38588-extern atomic_t fscache_n_op_release;
38589-extern atomic_t fscache_n_op_gc;
38590-extern atomic_t fscache_n_op_cancelled;
38591-extern atomic_t fscache_n_op_rejected;
38592-
38593-extern atomic_t fscache_n_attr_changed;
38594-extern atomic_t fscache_n_attr_changed_ok;
38595-extern atomic_t fscache_n_attr_changed_nobufs;
38596-extern atomic_t fscache_n_attr_changed_nomem;
38597-extern atomic_t fscache_n_attr_changed_calls;
38598-
38599-extern atomic_t fscache_n_allocs;
38600-extern atomic_t fscache_n_allocs_ok;
38601-extern atomic_t fscache_n_allocs_wait;
38602-extern atomic_t fscache_n_allocs_nobufs;
38603-extern atomic_t fscache_n_allocs_intr;
38604-extern atomic_t fscache_n_allocs_object_dead;
38605-extern atomic_t fscache_n_alloc_ops;
38606-extern atomic_t fscache_n_alloc_op_waits;
38607-
38608-extern atomic_t fscache_n_retrievals;
38609-extern atomic_t fscache_n_retrievals_ok;
38610-extern atomic_t fscache_n_retrievals_wait;
38611-extern atomic_t fscache_n_retrievals_nodata;
38612-extern atomic_t fscache_n_retrievals_nobufs;
38613-extern atomic_t fscache_n_retrievals_intr;
38614-extern atomic_t fscache_n_retrievals_nomem;
38615-extern atomic_t fscache_n_retrievals_object_dead;
38616-extern atomic_t fscache_n_retrieval_ops;
38617-extern atomic_t fscache_n_retrieval_op_waits;
38618-
38619-extern atomic_t fscache_n_stores;
38620-extern atomic_t fscache_n_stores_ok;
38621-extern atomic_t fscache_n_stores_again;
38622-extern atomic_t fscache_n_stores_nobufs;
38623-extern atomic_t fscache_n_stores_oom;
38624-extern atomic_t fscache_n_store_ops;
38625-extern atomic_t fscache_n_store_calls;
38626-extern atomic_t fscache_n_store_pages;
38627-extern atomic_t fscache_n_store_radix_deletes;
38628-extern atomic_t fscache_n_store_pages_over_limit;
38629-
38630-extern atomic_t fscache_n_store_vmscan_not_storing;
38631-extern atomic_t fscache_n_store_vmscan_gone;
38632-extern atomic_t fscache_n_store_vmscan_busy;
38633-extern atomic_t fscache_n_store_vmscan_cancelled;
38634-
38635-extern atomic_t fscache_n_marks;
38636-extern atomic_t fscache_n_uncaches;
38637-
38638-extern atomic_t fscache_n_acquires;
38639-extern atomic_t fscache_n_acquires_null;
38640-extern atomic_t fscache_n_acquires_no_cache;
38641-extern atomic_t fscache_n_acquires_ok;
38642-extern atomic_t fscache_n_acquires_nobufs;
38643-extern atomic_t fscache_n_acquires_oom;
38644-
38645-extern atomic_t fscache_n_updates;
38646-extern atomic_t fscache_n_updates_null;
38647-extern atomic_t fscache_n_updates_run;
38648-
38649-extern atomic_t fscache_n_relinquishes;
38650-extern atomic_t fscache_n_relinquishes_null;
38651-extern atomic_t fscache_n_relinquishes_waitcrt;
38652-extern atomic_t fscache_n_relinquishes_retire;
38653-
38654-extern atomic_t fscache_n_cookie_index;
38655-extern atomic_t fscache_n_cookie_data;
38656-extern atomic_t fscache_n_cookie_special;
38657-
38658-extern atomic_t fscache_n_object_alloc;
38659-extern atomic_t fscache_n_object_no_alloc;
38660-extern atomic_t fscache_n_object_lookups;
38661-extern atomic_t fscache_n_object_lookups_negative;
38662-extern atomic_t fscache_n_object_lookups_positive;
38663-extern atomic_t fscache_n_object_lookups_timed_out;
38664-extern atomic_t fscache_n_object_created;
38665-extern atomic_t fscache_n_object_avail;
38666-extern atomic_t fscache_n_object_dead;
38667-
38668-extern atomic_t fscache_n_checkaux_none;
38669-extern atomic_t fscache_n_checkaux_okay;
38670-extern atomic_t fscache_n_checkaux_update;
38671-extern atomic_t fscache_n_checkaux_obsolete;
38672+extern atomic_unchecked_t fscache_n_op_pend;
38673+extern atomic_unchecked_t fscache_n_op_run;
38674+extern atomic_unchecked_t fscache_n_op_enqueue;
38675+extern atomic_unchecked_t fscache_n_op_deferred_release;
38676+extern atomic_unchecked_t fscache_n_op_release;
38677+extern atomic_unchecked_t fscache_n_op_gc;
38678+extern atomic_unchecked_t fscache_n_op_cancelled;
38679+extern atomic_unchecked_t fscache_n_op_rejected;
38680+
38681+extern atomic_unchecked_t fscache_n_attr_changed;
38682+extern atomic_unchecked_t fscache_n_attr_changed_ok;
38683+extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
38684+extern atomic_unchecked_t fscache_n_attr_changed_nomem;
38685+extern atomic_unchecked_t fscache_n_attr_changed_calls;
38686+
38687+extern atomic_unchecked_t fscache_n_allocs;
38688+extern atomic_unchecked_t fscache_n_allocs_ok;
38689+extern atomic_unchecked_t fscache_n_allocs_wait;
38690+extern atomic_unchecked_t fscache_n_allocs_nobufs;
38691+extern atomic_unchecked_t fscache_n_allocs_intr;
38692+extern atomic_unchecked_t fscache_n_allocs_object_dead;
38693+extern atomic_unchecked_t fscache_n_alloc_ops;
38694+extern atomic_unchecked_t fscache_n_alloc_op_waits;
38695+
38696+extern atomic_unchecked_t fscache_n_retrievals;
38697+extern atomic_unchecked_t fscache_n_retrievals_ok;
38698+extern atomic_unchecked_t fscache_n_retrievals_wait;
38699+extern atomic_unchecked_t fscache_n_retrievals_nodata;
38700+extern atomic_unchecked_t fscache_n_retrievals_nobufs;
38701+extern atomic_unchecked_t fscache_n_retrievals_intr;
38702+extern atomic_unchecked_t fscache_n_retrievals_nomem;
38703+extern atomic_unchecked_t fscache_n_retrievals_object_dead;
38704+extern atomic_unchecked_t fscache_n_retrieval_ops;
38705+extern atomic_unchecked_t fscache_n_retrieval_op_waits;
38706+
38707+extern atomic_unchecked_t fscache_n_stores;
38708+extern atomic_unchecked_t fscache_n_stores_ok;
38709+extern atomic_unchecked_t fscache_n_stores_again;
38710+extern atomic_unchecked_t fscache_n_stores_nobufs;
38711+extern atomic_unchecked_t fscache_n_stores_oom;
38712+extern atomic_unchecked_t fscache_n_store_ops;
38713+extern atomic_unchecked_t fscache_n_store_calls;
38714+extern atomic_unchecked_t fscache_n_store_pages;
38715+extern atomic_unchecked_t fscache_n_store_radix_deletes;
38716+extern atomic_unchecked_t fscache_n_store_pages_over_limit;
38717+
38718+extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
38719+extern atomic_unchecked_t fscache_n_store_vmscan_gone;
38720+extern atomic_unchecked_t fscache_n_store_vmscan_busy;
38721+extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
38722+
38723+extern atomic_unchecked_t fscache_n_marks;
38724+extern atomic_unchecked_t fscache_n_uncaches;
38725+
38726+extern atomic_unchecked_t fscache_n_acquires;
38727+extern atomic_unchecked_t fscache_n_acquires_null;
38728+extern atomic_unchecked_t fscache_n_acquires_no_cache;
38729+extern atomic_unchecked_t fscache_n_acquires_ok;
38730+extern atomic_unchecked_t fscache_n_acquires_nobufs;
38731+extern atomic_unchecked_t fscache_n_acquires_oom;
38732+
38733+extern atomic_unchecked_t fscache_n_updates;
38734+extern atomic_unchecked_t fscache_n_updates_null;
38735+extern atomic_unchecked_t fscache_n_updates_run;
38736+
38737+extern atomic_unchecked_t fscache_n_relinquishes;
38738+extern atomic_unchecked_t fscache_n_relinquishes_null;
38739+extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
38740+extern atomic_unchecked_t fscache_n_relinquishes_retire;
38741+
38742+extern atomic_unchecked_t fscache_n_cookie_index;
38743+extern atomic_unchecked_t fscache_n_cookie_data;
38744+extern atomic_unchecked_t fscache_n_cookie_special;
38745+
38746+extern atomic_unchecked_t fscache_n_object_alloc;
38747+extern atomic_unchecked_t fscache_n_object_no_alloc;
38748+extern atomic_unchecked_t fscache_n_object_lookups;
38749+extern atomic_unchecked_t fscache_n_object_lookups_negative;
38750+extern atomic_unchecked_t fscache_n_object_lookups_positive;
38751+extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
38752+extern atomic_unchecked_t fscache_n_object_created;
38753+extern atomic_unchecked_t fscache_n_object_avail;
38754+extern atomic_unchecked_t fscache_n_object_dead;
38755+
38756+extern atomic_unchecked_t fscache_n_checkaux_none;
38757+extern atomic_unchecked_t fscache_n_checkaux_okay;
38758+extern atomic_unchecked_t fscache_n_checkaux_update;
38759+extern atomic_unchecked_t fscache_n_checkaux_obsolete;
38760
38761 extern atomic_t fscache_n_cop_alloc_object;
38762 extern atomic_t fscache_n_cop_lookup_object;
38763@@ -247,6 +247,11 @@ static inline void fscache_stat(atomic_t
38764 atomic_inc(stat);
38765 }
38766
38767+static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
38768+{
38769+ atomic_inc_unchecked(stat);
38770+}
38771+
38772 static inline void fscache_stat_d(atomic_t *stat)
38773 {
38774 atomic_dec(stat);
38775@@ -259,6 +264,7 @@ extern const struct file_operations fsca
38776
38777 #define __fscache_stat(stat) (NULL)
38778 #define fscache_stat(stat) do {} while (0)
38779+#define fscache_stat_unchecked(stat) do {} while (0)
38780 #define fscache_stat_d(stat) do {} while (0)
38781 #endif
38782
38783diff -urNp linux-2.6.32.41/fs/fscache/object.c linux-2.6.32.41/fs/fscache/object.c
38784--- linux-2.6.32.41/fs/fscache/object.c 2011-03-27 14:31:47.000000000 -0400
38785+++ linux-2.6.32.41/fs/fscache/object.c 2011-05-04 17:56:28.000000000 -0400
38786@@ -144,7 +144,7 @@ static void fscache_object_state_machine
38787 /* update the object metadata on disk */
38788 case FSCACHE_OBJECT_UPDATING:
38789 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
38790- fscache_stat(&fscache_n_updates_run);
38791+ fscache_stat_unchecked(&fscache_n_updates_run);
38792 fscache_stat(&fscache_n_cop_update_object);
38793 object->cache->ops->update_object(object);
38794 fscache_stat_d(&fscache_n_cop_update_object);
38795@@ -233,7 +233,7 @@ static void fscache_object_state_machine
38796 spin_lock(&object->lock);
38797 object->state = FSCACHE_OBJECT_DEAD;
38798 spin_unlock(&object->lock);
38799- fscache_stat(&fscache_n_object_dead);
38800+ fscache_stat_unchecked(&fscache_n_object_dead);
38801 goto terminal_transit;
38802
38803 /* handle the parent cache of this object being withdrawn from
38804@@ -248,7 +248,7 @@ static void fscache_object_state_machine
38805 spin_lock(&object->lock);
38806 object->state = FSCACHE_OBJECT_DEAD;
38807 spin_unlock(&object->lock);
38808- fscache_stat(&fscache_n_object_dead);
38809+ fscache_stat_unchecked(&fscache_n_object_dead);
38810 goto terminal_transit;
38811
38812 /* complain about the object being woken up once it is
38813@@ -492,7 +492,7 @@ static void fscache_lookup_object(struct
38814 parent->cookie->def->name, cookie->def->name,
38815 object->cache->tag->name);
38816
38817- fscache_stat(&fscache_n_object_lookups);
38818+ fscache_stat_unchecked(&fscache_n_object_lookups);
38819 fscache_stat(&fscache_n_cop_lookup_object);
38820 ret = object->cache->ops->lookup_object(object);
38821 fscache_stat_d(&fscache_n_cop_lookup_object);
38822@@ -503,7 +503,7 @@ static void fscache_lookup_object(struct
38823 if (ret == -ETIMEDOUT) {
38824 /* probably stuck behind another object, so move this one to
38825 * the back of the queue */
38826- fscache_stat(&fscache_n_object_lookups_timed_out);
38827+ fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
38828 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
38829 }
38830
38831@@ -526,7 +526,7 @@ void fscache_object_lookup_negative(stru
38832
38833 spin_lock(&object->lock);
38834 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
38835- fscache_stat(&fscache_n_object_lookups_negative);
38836+ fscache_stat_unchecked(&fscache_n_object_lookups_negative);
38837
38838 /* transit here to allow write requests to begin stacking up
38839 * and read requests to begin returning ENODATA */
38840@@ -572,7 +572,7 @@ void fscache_obtained_object(struct fsca
38841 * result, in which case there may be data available */
38842 spin_lock(&object->lock);
38843 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
38844- fscache_stat(&fscache_n_object_lookups_positive);
38845+ fscache_stat_unchecked(&fscache_n_object_lookups_positive);
38846
38847 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
38848
38849@@ -586,7 +586,7 @@ void fscache_obtained_object(struct fsca
38850 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
38851 } else {
38852 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
38853- fscache_stat(&fscache_n_object_created);
38854+ fscache_stat_unchecked(&fscache_n_object_created);
38855
38856 object->state = FSCACHE_OBJECT_AVAILABLE;
38857 spin_unlock(&object->lock);
38858@@ -633,7 +633,7 @@ static void fscache_object_available(str
38859 fscache_enqueue_dependents(object);
38860
38861 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
38862- fscache_stat(&fscache_n_object_avail);
38863+ fscache_stat_unchecked(&fscache_n_object_avail);
38864
38865 _leave("");
38866 }
38867@@ -861,7 +861,7 @@ enum fscache_checkaux fscache_check_aux(
38868 enum fscache_checkaux result;
38869
38870 if (!object->cookie->def->check_aux) {
38871- fscache_stat(&fscache_n_checkaux_none);
38872+ fscache_stat_unchecked(&fscache_n_checkaux_none);
38873 return FSCACHE_CHECKAUX_OKAY;
38874 }
38875
38876@@ -870,17 +870,17 @@ enum fscache_checkaux fscache_check_aux(
38877 switch (result) {
38878 /* entry okay as is */
38879 case FSCACHE_CHECKAUX_OKAY:
38880- fscache_stat(&fscache_n_checkaux_okay);
38881+ fscache_stat_unchecked(&fscache_n_checkaux_okay);
38882 break;
38883
38884 /* entry requires update */
38885 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
38886- fscache_stat(&fscache_n_checkaux_update);
38887+ fscache_stat_unchecked(&fscache_n_checkaux_update);
38888 break;
38889
38890 /* entry requires deletion */
38891 case FSCACHE_CHECKAUX_OBSOLETE:
38892- fscache_stat(&fscache_n_checkaux_obsolete);
38893+ fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
38894 break;
38895
38896 default:
38897diff -urNp linux-2.6.32.41/fs/fscache/operation.c linux-2.6.32.41/fs/fscache/operation.c
38898--- linux-2.6.32.41/fs/fscache/operation.c 2011-03-27 14:31:47.000000000 -0400
38899+++ linux-2.6.32.41/fs/fscache/operation.c 2011-05-04 17:56:28.000000000 -0400
38900@@ -16,7 +16,7 @@
38901 #include <linux/seq_file.h>
38902 #include "internal.h"
38903
38904-atomic_t fscache_op_debug_id;
38905+atomic_unchecked_t fscache_op_debug_id;
38906 EXPORT_SYMBOL(fscache_op_debug_id);
38907
38908 /**
38909@@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fs
38910 ASSERTCMP(op->object->state, >=, FSCACHE_OBJECT_AVAILABLE);
38911 ASSERTCMP(atomic_read(&op->usage), >, 0);
38912
38913- fscache_stat(&fscache_n_op_enqueue);
38914+ fscache_stat_unchecked(&fscache_n_op_enqueue);
38915 switch (op->flags & FSCACHE_OP_TYPE) {
38916 case FSCACHE_OP_FAST:
38917 _debug("queue fast");
38918@@ -76,7 +76,7 @@ static void fscache_run_op(struct fscach
38919 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
38920 if (op->processor)
38921 fscache_enqueue_operation(op);
38922- fscache_stat(&fscache_n_op_run);
38923+ fscache_stat_unchecked(&fscache_n_op_run);
38924 }
38925
38926 /*
38927@@ -107,11 +107,11 @@ int fscache_submit_exclusive_op(struct f
38928 if (object->n_ops > 0) {
38929 atomic_inc(&op->usage);
38930 list_add_tail(&op->pend_link, &object->pending_ops);
38931- fscache_stat(&fscache_n_op_pend);
38932+ fscache_stat_unchecked(&fscache_n_op_pend);
38933 } else if (!list_empty(&object->pending_ops)) {
38934 atomic_inc(&op->usage);
38935 list_add_tail(&op->pend_link, &object->pending_ops);
38936- fscache_stat(&fscache_n_op_pend);
38937+ fscache_stat_unchecked(&fscache_n_op_pend);
38938 fscache_start_operations(object);
38939 } else {
38940 ASSERTCMP(object->n_in_progress, ==, 0);
38941@@ -127,7 +127,7 @@ int fscache_submit_exclusive_op(struct f
38942 object->n_exclusive++; /* reads and writes must wait */
38943 atomic_inc(&op->usage);
38944 list_add_tail(&op->pend_link, &object->pending_ops);
38945- fscache_stat(&fscache_n_op_pend);
38946+ fscache_stat_unchecked(&fscache_n_op_pend);
38947 ret = 0;
38948 } else {
38949 /* not allowed to submit ops in any other state */
38950@@ -214,11 +214,11 @@ int fscache_submit_op(struct fscache_obj
38951 if (object->n_exclusive > 0) {
38952 atomic_inc(&op->usage);
38953 list_add_tail(&op->pend_link, &object->pending_ops);
38954- fscache_stat(&fscache_n_op_pend);
38955+ fscache_stat_unchecked(&fscache_n_op_pend);
38956 } else if (!list_empty(&object->pending_ops)) {
38957 atomic_inc(&op->usage);
38958 list_add_tail(&op->pend_link, &object->pending_ops);
38959- fscache_stat(&fscache_n_op_pend);
38960+ fscache_stat_unchecked(&fscache_n_op_pend);
38961 fscache_start_operations(object);
38962 } else {
38963 ASSERTCMP(object->n_exclusive, ==, 0);
38964@@ -230,12 +230,12 @@ int fscache_submit_op(struct fscache_obj
38965 object->n_ops++;
38966 atomic_inc(&op->usage);
38967 list_add_tail(&op->pend_link, &object->pending_ops);
38968- fscache_stat(&fscache_n_op_pend);
38969+ fscache_stat_unchecked(&fscache_n_op_pend);
38970 ret = 0;
38971 } else if (object->state == FSCACHE_OBJECT_DYING ||
38972 object->state == FSCACHE_OBJECT_LC_DYING ||
38973 object->state == FSCACHE_OBJECT_WITHDRAWING) {
38974- fscache_stat(&fscache_n_op_rejected);
38975+ fscache_stat_unchecked(&fscache_n_op_rejected);
38976 ret = -ENOBUFS;
38977 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
38978 fscache_report_unexpected_submission(object, op, ostate);
38979@@ -305,7 +305,7 @@ int fscache_cancel_op(struct fscache_ope
38980
38981 ret = -EBUSY;
38982 if (!list_empty(&op->pend_link)) {
38983- fscache_stat(&fscache_n_op_cancelled);
38984+ fscache_stat_unchecked(&fscache_n_op_cancelled);
38985 list_del_init(&op->pend_link);
38986 object->n_ops--;
38987 if (test_bit(FSCACHE_OP_EXCLUSIVE, &op->flags))
38988@@ -344,7 +344,7 @@ void fscache_put_operation(struct fscach
38989 if (test_and_set_bit(FSCACHE_OP_DEAD, &op->flags))
38990 BUG();
38991
38992- fscache_stat(&fscache_n_op_release);
38993+ fscache_stat_unchecked(&fscache_n_op_release);
38994
38995 if (op->release) {
38996 op->release(op);
38997@@ -361,7 +361,7 @@ void fscache_put_operation(struct fscach
38998 * lock, and defer it otherwise */
38999 if (!spin_trylock(&object->lock)) {
39000 _debug("defer put");
39001- fscache_stat(&fscache_n_op_deferred_release);
39002+ fscache_stat_unchecked(&fscache_n_op_deferred_release);
39003
39004 cache = object->cache;
39005 spin_lock(&cache->op_gc_list_lock);
39006@@ -423,7 +423,7 @@ void fscache_operation_gc(struct work_st
39007
39008 _debug("GC DEFERRED REL OBJ%x OP%x",
39009 object->debug_id, op->debug_id);
39010- fscache_stat(&fscache_n_op_gc);
39011+ fscache_stat_unchecked(&fscache_n_op_gc);
39012
39013 ASSERTCMP(atomic_read(&op->usage), ==, 0);
39014
39015diff -urNp linux-2.6.32.41/fs/fscache/page.c linux-2.6.32.41/fs/fscache/page.c
39016--- linux-2.6.32.41/fs/fscache/page.c 2011-03-27 14:31:47.000000000 -0400
39017+++ linux-2.6.32.41/fs/fscache/page.c 2011-05-04 17:56:28.000000000 -0400
39018@@ -59,7 +59,7 @@ bool __fscache_maybe_release_page(struct
39019 val = radix_tree_lookup(&cookie->stores, page->index);
39020 if (!val) {
39021 rcu_read_unlock();
39022- fscache_stat(&fscache_n_store_vmscan_not_storing);
39023+ fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
39024 __fscache_uncache_page(cookie, page);
39025 return true;
39026 }
39027@@ -89,11 +89,11 @@ bool __fscache_maybe_release_page(struct
39028 spin_unlock(&cookie->stores_lock);
39029
39030 if (xpage) {
39031- fscache_stat(&fscache_n_store_vmscan_cancelled);
39032- fscache_stat(&fscache_n_store_radix_deletes);
39033+ fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
39034+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
39035 ASSERTCMP(xpage, ==, page);
39036 } else {
39037- fscache_stat(&fscache_n_store_vmscan_gone);
39038+ fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
39039 }
39040
39041 wake_up_bit(&cookie->flags, 0);
39042@@ -106,7 +106,7 @@ page_busy:
39043 /* we might want to wait here, but that could deadlock the allocator as
39044 * the slow-work threads writing to the cache may all end up sleeping
39045 * on memory allocation */
39046- fscache_stat(&fscache_n_store_vmscan_busy);
39047+ fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
39048 return false;
39049 }
39050 EXPORT_SYMBOL(__fscache_maybe_release_page);
39051@@ -130,7 +130,7 @@ static void fscache_end_page_write(struc
39052 FSCACHE_COOKIE_STORING_TAG);
39053 if (!radix_tree_tag_get(&cookie->stores, page->index,
39054 FSCACHE_COOKIE_PENDING_TAG)) {
39055- fscache_stat(&fscache_n_store_radix_deletes);
39056+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
39057 xpage = radix_tree_delete(&cookie->stores, page->index);
39058 }
39059 spin_unlock(&cookie->stores_lock);
39060@@ -151,7 +151,7 @@ static void fscache_attr_changed_op(stru
39061
39062 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
39063
39064- fscache_stat(&fscache_n_attr_changed_calls);
39065+ fscache_stat_unchecked(&fscache_n_attr_changed_calls);
39066
39067 if (fscache_object_is_active(object)) {
39068 fscache_set_op_state(op, "CallFS");
39069@@ -178,11 +178,11 @@ int __fscache_attr_changed(struct fscach
39070
39071 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
39072
39073- fscache_stat(&fscache_n_attr_changed);
39074+ fscache_stat_unchecked(&fscache_n_attr_changed);
39075
39076 op = kzalloc(sizeof(*op), GFP_KERNEL);
39077 if (!op) {
39078- fscache_stat(&fscache_n_attr_changed_nomem);
39079+ fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
39080 _leave(" = -ENOMEM");
39081 return -ENOMEM;
39082 }
39083@@ -202,7 +202,7 @@ int __fscache_attr_changed(struct fscach
39084 if (fscache_submit_exclusive_op(object, op) < 0)
39085 goto nobufs;
39086 spin_unlock(&cookie->lock);
39087- fscache_stat(&fscache_n_attr_changed_ok);
39088+ fscache_stat_unchecked(&fscache_n_attr_changed_ok);
39089 fscache_put_operation(op);
39090 _leave(" = 0");
39091 return 0;
39092@@ -210,7 +210,7 @@ int __fscache_attr_changed(struct fscach
39093 nobufs:
39094 spin_unlock(&cookie->lock);
39095 kfree(op);
39096- fscache_stat(&fscache_n_attr_changed_nobufs);
39097+ fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
39098 _leave(" = %d", -ENOBUFS);
39099 return -ENOBUFS;
39100 }
39101@@ -264,7 +264,7 @@ static struct fscache_retrieval *fscache
39102 /* allocate a retrieval operation and attempt to submit it */
39103 op = kzalloc(sizeof(*op), GFP_NOIO);
39104 if (!op) {
39105- fscache_stat(&fscache_n_retrievals_nomem);
39106+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
39107 return NULL;
39108 }
39109
39110@@ -294,13 +294,13 @@ static int fscache_wait_for_deferred_loo
39111 return 0;
39112 }
39113
39114- fscache_stat(&fscache_n_retrievals_wait);
39115+ fscache_stat_unchecked(&fscache_n_retrievals_wait);
39116
39117 jif = jiffies;
39118 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
39119 fscache_wait_bit_interruptible,
39120 TASK_INTERRUPTIBLE) != 0) {
39121- fscache_stat(&fscache_n_retrievals_intr);
39122+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
39123 _leave(" = -ERESTARTSYS");
39124 return -ERESTARTSYS;
39125 }
39126@@ -318,8 +318,8 @@ static int fscache_wait_for_deferred_loo
39127 */
39128 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
39129 struct fscache_retrieval *op,
39130- atomic_t *stat_op_waits,
39131- atomic_t *stat_object_dead)
39132+ atomic_unchecked_t *stat_op_waits,
39133+ atomic_unchecked_t *stat_object_dead)
39134 {
39135 int ret;
39136
39137@@ -327,7 +327,7 @@ static int fscache_wait_for_retrieval_ac
39138 goto check_if_dead;
39139
39140 _debug(">>> WT");
39141- fscache_stat(stat_op_waits);
39142+ fscache_stat_unchecked(stat_op_waits);
39143 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
39144 fscache_wait_bit_interruptible,
39145 TASK_INTERRUPTIBLE) < 0) {
39146@@ -344,7 +344,7 @@ static int fscache_wait_for_retrieval_ac
39147
39148 check_if_dead:
39149 if (unlikely(fscache_object_is_dead(object))) {
39150- fscache_stat(stat_object_dead);
39151+ fscache_stat_unchecked(stat_object_dead);
39152 return -ENOBUFS;
39153 }
39154 return 0;
39155@@ -371,7 +371,7 @@ int __fscache_read_or_alloc_page(struct
39156
39157 _enter("%p,%p,,,", cookie, page);
39158
39159- fscache_stat(&fscache_n_retrievals);
39160+ fscache_stat_unchecked(&fscache_n_retrievals);
39161
39162 if (hlist_empty(&cookie->backing_objects))
39163 goto nobufs;
39164@@ -405,7 +405,7 @@ int __fscache_read_or_alloc_page(struct
39165 goto nobufs_unlock;
39166 spin_unlock(&cookie->lock);
39167
39168- fscache_stat(&fscache_n_retrieval_ops);
39169+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
39170
39171 /* pin the netfs read context in case we need to do the actual netfs
39172 * read because we've encountered a cache read failure */
39173@@ -435,15 +435,15 @@ int __fscache_read_or_alloc_page(struct
39174
39175 error:
39176 if (ret == -ENOMEM)
39177- fscache_stat(&fscache_n_retrievals_nomem);
39178+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
39179 else if (ret == -ERESTARTSYS)
39180- fscache_stat(&fscache_n_retrievals_intr);
39181+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
39182 else if (ret == -ENODATA)
39183- fscache_stat(&fscache_n_retrievals_nodata);
39184+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
39185 else if (ret < 0)
39186- fscache_stat(&fscache_n_retrievals_nobufs);
39187+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
39188 else
39189- fscache_stat(&fscache_n_retrievals_ok);
39190+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
39191
39192 fscache_put_retrieval(op);
39193 _leave(" = %d", ret);
39194@@ -453,7 +453,7 @@ nobufs_unlock:
39195 spin_unlock(&cookie->lock);
39196 kfree(op);
39197 nobufs:
39198- fscache_stat(&fscache_n_retrievals_nobufs);
39199+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
39200 _leave(" = -ENOBUFS");
39201 return -ENOBUFS;
39202 }
39203@@ -491,7 +491,7 @@ int __fscache_read_or_alloc_pages(struct
39204
39205 _enter("%p,,%d,,,", cookie, *nr_pages);
39206
39207- fscache_stat(&fscache_n_retrievals);
39208+ fscache_stat_unchecked(&fscache_n_retrievals);
39209
39210 if (hlist_empty(&cookie->backing_objects))
39211 goto nobufs;
39212@@ -522,7 +522,7 @@ int __fscache_read_or_alloc_pages(struct
39213 goto nobufs_unlock;
39214 spin_unlock(&cookie->lock);
39215
39216- fscache_stat(&fscache_n_retrieval_ops);
39217+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
39218
39219 /* pin the netfs read context in case we need to do the actual netfs
39220 * read because we've encountered a cache read failure */
39221@@ -552,15 +552,15 @@ int __fscache_read_or_alloc_pages(struct
39222
39223 error:
39224 if (ret == -ENOMEM)
39225- fscache_stat(&fscache_n_retrievals_nomem);
39226+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
39227 else if (ret == -ERESTARTSYS)
39228- fscache_stat(&fscache_n_retrievals_intr);
39229+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
39230 else if (ret == -ENODATA)
39231- fscache_stat(&fscache_n_retrievals_nodata);
39232+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
39233 else if (ret < 0)
39234- fscache_stat(&fscache_n_retrievals_nobufs);
39235+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
39236 else
39237- fscache_stat(&fscache_n_retrievals_ok);
39238+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
39239
39240 fscache_put_retrieval(op);
39241 _leave(" = %d", ret);
39242@@ -570,7 +570,7 @@ nobufs_unlock:
39243 spin_unlock(&cookie->lock);
39244 kfree(op);
39245 nobufs:
39246- fscache_stat(&fscache_n_retrievals_nobufs);
39247+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
39248 _leave(" = -ENOBUFS");
39249 return -ENOBUFS;
39250 }
39251@@ -594,7 +594,7 @@ int __fscache_alloc_page(struct fscache_
39252
39253 _enter("%p,%p,,,", cookie, page);
39254
39255- fscache_stat(&fscache_n_allocs);
39256+ fscache_stat_unchecked(&fscache_n_allocs);
39257
39258 if (hlist_empty(&cookie->backing_objects))
39259 goto nobufs;
39260@@ -621,7 +621,7 @@ int __fscache_alloc_page(struct fscache_
39261 goto nobufs_unlock;
39262 spin_unlock(&cookie->lock);
39263
39264- fscache_stat(&fscache_n_alloc_ops);
39265+ fscache_stat_unchecked(&fscache_n_alloc_ops);
39266
39267 ret = fscache_wait_for_retrieval_activation(
39268 object, op,
39269@@ -637,11 +637,11 @@ int __fscache_alloc_page(struct fscache_
39270
39271 error:
39272 if (ret == -ERESTARTSYS)
39273- fscache_stat(&fscache_n_allocs_intr);
39274+ fscache_stat_unchecked(&fscache_n_allocs_intr);
39275 else if (ret < 0)
39276- fscache_stat(&fscache_n_allocs_nobufs);
39277+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
39278 else
39279- fscache_stat(&fscache_n_allocs_ok);
39280+ fscache_stat_unchecked(&fscache_n_allocs_ok);
39281
39282 fscache_put_retrieval(op);
39283 _leave(" = %d", ret);
39284@@ -651,7 +651,7 @@ nobufs_unlock:
39285 spin_unlock(&cookie->lock);
39286 kfree(op);
39287 nobufs:
39288- fscache_stat(&fscache_n_allocs_nobufs);
39289+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
39290 _leave(" = -ENOBUFS");
39291 return -ENOBUFS;
39292 }
39293@@ -694,7 +694,7 @@ static void fscache_write_op(struct fsca
39294
39295 spin_lock(&cookie->stores_lock);
39296
39297- fscache_stat(&fscache_n_store_calls);
39298+ fscache_stat_unchecked(&fscache_n_store_calls);
39299
39300 /* find a page to store */
39301 page = NULL;
39302@@ -705,7 +705,7 @@ static void fscache_write_op(struct fsca
39303 page = results[0];
39304 _debug("gang %d [%lx]", n, page->index);
39305 if (page->index > op->store_limit) {
39306- fscache_stat(&fscache_n_store_pages_over_limit);
39307+ fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
39308 goto superseded;
39309 }
39310
39311@@ -721,7 +721,7 @@ static void fscache_write_op(struct fsca
39312
39313 if (page) {
39314 fscache_set_op_state(&op->op, "Store");
39315- fscache_stat(&fscache_n_store_pages);
39316+ fscache_stat_unchecked(&fscache_n_store_pages);
39317 fscache_stat(&fscache_n_cop_write_page);
39318 ret = object->cache->ops->write_page(op, page);
39319 fscache_stat_d(&fscache_n_cop_write_page);
39320@@ -792,7 +792,7 @@ int __fscache_write_page(struct fscache_
39321 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
39322 ASSERT(PageFsCache(page));
39323
39324- fscache_stat(&fscache_n_stores);
39325+ fscache_stat_unchecked(&fscache_n_stores);
39326
39327 op = kzalloc(sizeof(*op), GFP_NOIO);
39328 if (!op)
39329@@ -844,7 +844,7 @@ int __fscache_write_page(struct fscache_
39330 spin_unlock(&cookie->stores_lock);
39331 spin_unlock(&object->lock);
39332
39333- op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
39334+ op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
39335 op->store_limit = object->store_limit;
39336
39337 if (fscache_submit_op(object, &op->op) < 0)
39338@@ -852,8 +852,8 @@ int __fscache_write_page(struct fscache_
39339
39340 spin_unlock(&cookie->lock);
39341 radix_tree_preload_end();
39342- fscache_stat(&fscache_n_store_ops);
39343- fscache_stat(&fscache_n_stores_ok);
39344+ fscache_stat_unchecked(&fscache_n_store_ops);
39345+ fscache_stat_unchecked(&fscache_n_stores_ok);
39346
39347 /* the slow work queue now carries its own ref on the object */
39348 fscache_put_operation(&op->op);
39349@@ -861,14 +861,14 @@ int __fscache_write_page(struct fscache_
39350 return 0;
39351
39352 already_queued:
39353- fscache_stat(&fscache_n_stores_again);
39354+ fscache_stat_unchecked(&fscache_n_stores_again);
39355 already_pending:
39356 spin_unlock(&cookie->stores_lock);
39357 spin_unlock(&object->lock);
39358 spin_unlock(&cookie->lock);
39359 radix_tree_preload_end();
39360 kfree(op);
39361- fscache_stat(&fscache_n_stores_ok);
39362+ fscache_stat_unchecked(&fscache_n_stores_ok);
39363 _leave(" = 0");
39364 return 0;
39365
39366@@ -886,14 +886,14 @@ nobufs:
39367 spin_unlock(&cookie->lock);
39368 radix_tree_preload_end();
39369 kfree(op);
39370- fscache_stat(&fscache_n_stores_nobufs);
39371+ fscache_stat_unchecked(&fscache_n_stores_nobufs);
39372 _leave(" = -ENOBUFS");
39373 return -ENOBUFS;
39374
39375 nomem_free:
39376 kfree(op);
39377 nomem:
39378- fscache_stat(&fscache_n_stores_oom);
39379+ fscache_stat_unchecked(&fscache_n_stores_oom);
39380 _leave(" = -ENOMEM");
39381 return -ENOMEM;
39382 }
39383@@ -911,7 +911,7 @@ void __fscache_uncache_page(struct fscac
39384 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
39385 ASSERTCMP(page, !=, NULL);
39386
39387- fscache_stat(&fscache_n_uncaches);
39388+ fscache_stat_unchecked(&fscache_n_uncaches);
39389
39390 /* cache withdrawal may beat us to it */
39391 if (!PageFsCache(page))
39392@@ -964,7 +964,7 @@ void fscache_mark_pages_cached(struct fs
39393 unsigned long loop;
39394
39395 #ifdef CONFIG_FSCACHE_STATS
39396- atomic_add(pagevec->nr, &fscache_n_marks);
39397+ atomic_add_unchecked(pagevec->nr, &fscache_n_marks);
39398 #endif
39399
39400 for (loop = 0; loop < pagevec->nr; loop++) {
39401diff -urNp linux-2.6.32.41/fs/fscache/stats.c linux-2.6.32.41/fs/fscache/stats.c
39402--- linux-2.6.32.41/fs/fscache/stats.c 2011-03-27 14:31:47.000000000 -0400
39403+++ linux-2.6.32.41/fs/fscache/stats.c 2011-05-04 17:56:28.000000000 -0400
39404@@ -18,95 +18,95 @@
39405 /*
39406 * operation counters
39407 */
39408-atomic_t fscache_n_op_pend;
39409-atomic_t fscache_n_op_run;
39410-atomic_t fscache_n_op_enqueue;
39411-atomic_t fscache_n_op_requeue;
39412-atomic_t fscache_n_op_deferred_release;
39413-atomic_t fscache_n_op_release;
39414-atomic_t fscache_n_op_gc;
39415-atomic_t fscache_n_op_cancelled;
39416-atomic_t fscache_n_op_rejected;
39417-
39418-atomic_t fscache_n_attr_changed;
39419-atomic_t fscache_n_attr_changed_ok;
39420-atomic_t fscache_n_attr_changed_nobufs;
39421-atomic_t fscache_n_attr_changed_nomem;
39422-atomic_t fscache_n_attr_changed_calls;
39423-
39424-atomic_t fscache_n_allocs;
39425-atomic_t fscache_n_allocs_ok;
39426-atomic_t fscache_n_allocs_wait;
39427-atomic_t fscache_n_allocs_nobufs;
39428-atomic_t fscache_n_allocs_intr;
39429-atomic_t fscache_n_allocs_object_dead;
39430-atomic_t fscache_n_alloc_ops;
39431-atomic_t fscache_n_alloc_op_waits;
39432-
39433-atomic_t fscache_n_retrievals;
39434-atomic_t fscache_n_retrievals_ok;
39435-atomic_t fscache_n_retrievals_wait;
39436-atomic_t fscache_n_retrievals_nodata;
39437-atomic_t fscache_n_retrievals_nobufs;
39438-atomic_t fscache_n_retrievals_intr;
39439-atomic_t fscache_n_retrievals_nomem;
39440-atomic_t fscache_n_retrievals_object_dead;
39441-atomic_t fscache_n_retrieval_ops;
39442-atomic_t fscache_n_retrieval_op_waits;
39443-
39444-atomic_t fscache_n_stores;
39445-atomic_t fscache_n_stores_ok;
39446-atomic_t fscache_n_stores_again;
39447-atomic_t fscache_n_stores_nobufs;
39448-atomic_t fscache_n_stores_oom;
39449-atomic_t fscache_n_store_ops;
39450-atomic_t fscache_n_store_calls;
39451-atomic_t fscache_n_store_pages;
39452-atomic_t fscache_n_store_radix_deletes;
39453-atomic_t fscache_n_store_pages_over_limit;
39454-
39455-atomic_t fscache_n_store_vmscan_not_storing;
39456-atomic_t fscache_n_store_vmscan_gone;
39457-atomic_t fscache_n_store_vmscan_busy;
39458-atomic_t fscache_n_store_vmscan_cancelled;
39459-
39460-atomic_t fscache_n_marks;
39461-atomic_t fscache_n_uncaches;
39462-
39463-atomic_t fscache_n_acquires;
39464-atomic_t fscache_n_acquires_null;
39465-atomic_t fscache_n_acquires_no_cache;
39466-atomic_t fscache_n_acquires_ok;
39467-atomic_t fscache_n_acquires_nobufs;
39468-atomic_t fscache_n_acquires_oom;
39469-
39470-atomic_t fscache_n_updates;
39471-atomic_t fscache_n_updates_null;
39472-atomic_t fscache_n_updates_run;
39473-
39474-atomic_t fscache_n_relinquishes;
39475-atomic_t fscache_n_relinquishes_null;
39476-atomic_t fscache_n_relinquishes_waitcrt;
39477-atomic_t fscache_n_relinquishes_retire;
39478-
39479-atomic_t fscache_n_cookie_index;
39480-atomic_t fscache_n_cookie_data;
39481-atomic_t fscache_n_cookie_special;
39482-
39483-atomic_t fscache_n_object_alloc;
39484-atomic_t fscache_n_object_no_alloc;
39485-atomic_t fscache_n_object_lookups;
39486-atomic_t fscache_n_object_lookups_negative;
39487-atomic_t fscache_n_object_lookups_positive;
39488-atomic_t fscache_n_object_lookups_timed_out;
39489-atomic_t fscache_n_object_created;
39490-atomic_t fscache_n_object_avail;
39491-atomic_t fscache_n_object_dead;
39492-
39493-atomic_t fscache_n_checkaux_none;
39494-atomic_t fscache_n_checkaux_okay;
39495-atomic_t fscache_n_checkaux_update;
39496-atomic_t fscache_n_checkaux_obsolete;
39497+atomic_unchecked_t fscache_n_op_pend;
39498+atomic_unchecked_t fscache_n_op_run;
39499+atomic_unchecked_t fscache_n_op_enqueue;
39500+atomic_unchecked_t fscache_n_op_requeue;
39501+atomic_unchecked_t fscache_n_op_deferred_release;
39502+atomic_unchecked_t fscache_n_op_release;
39503+atomic_unchecked_t fscache_n_op_gc;
39504+atomic_unchecked_t fscache_n_op_cancelled;
39505+atomic_unchecked_t fscache_n_op_rejected;
39506+
39507+atomic_unchecked_t fscache_n_attr_changed;
39508+atomic_unchecked_t fscache_n_attr_changed_ok;
39509+atomic_unchecked_t fscache_n_attr_changed_nobufs;
39510+atomic_unchecked_t fscache_n_attr_changed_nomem;
39511+atomic_unchecked_t fscache_n_attr_changed_calls;
39512+
39513+atomic_unchecked_t fscache_n_allocs;
39514+atomic_unchecked_t fscache_n_allocs_ok;
39515+atomic_unchecked_t fscache_n_allocs_wait;
39516+atomic_unchecked_t fscache_n_allocs_nobufs;
39517+atomic_unchecked_t fscache_n_allocs_intr;
39518+atomic_unchecked_t fscache_n_allocs_object_dead;
39519+atomic_unchecked_t fscache_n_alloc_ops;
39520+atomic_unchecked_t fscache_n_alloc_op_waits;
39521+
39522+atomic_unchecked_t fscache_n_retrievals;
39523+atomic_unchecked_t fscache_n_retrievals_ok;
39524+atomic_unchecked_t fscache_n_retrievals_wait;
39525+atomic_unchecked_t fscache_n_retrievals_nodata;
39526+atomic_unchecked_t fscache_n_retrievals_nobufs;
39527+atomic_unchecked_t fscache_n_retrievals_intr;
39528+atomic_unchecked_t fscache_n_retrievals_nomem;
39529+atomic_unchecked_t fscache_n_retrievals_object_dead;
39530+atomic_unchecked_t fscache_n_retrieval_ops;
39531+atomic_unchecked_t fscache_n_retrieval_op_waits;
39532+
39533+atomic_unchecked_t fscache_n_stores;
39534+atomic_unchecked_t fscache_n_stores_ok;
39535+atomic_unchecked_t fscache_n_stores_again;
39536+atomic_unchecked_t fscache_n_stores_nobufs;
39537+atomic_unchecked_t fscache_n_stores_oom;
39538+atomic_unchecked_t fscache_n_store_ops;
39539+atomic_unchecked_t fscache_n_store_calls;
39540+atomic_unchecked_t fscache_n_store_pages;
39541+atomic_unchecked_t fscache_n_store_radix_deletes;
39542+atomic_unchecked_t fscache_n_store_pages_over_limit;
39543+
39544+atomic_unchecked_t fscache_n_store_vmscan_not_storing;
39545+atomic_unchecked_t fscache_n_store_vmscan_gone;
39546+atomic_unchecked_t fscache_n_store_vmscan_busy;
39547+atomic_unchecked_t fscache_n_store_vmscan_cancelled;
39548+
39549+atomic_unchecked_t fscache_n_marks;
39550+atomic_unchecked_t fscache_n_uncaches;
39551+
39552+atomic_unchecked_t fscache_n_acquires;
39553+atomic_unchecked_t fscache_n_acquires_null;
39554+atomic_unchecked_t fscache_n_acquires_no_cache;
39555+atomic_unchecked_t fscache_n_acquires_ok;
39556+atomic_unchecked_t fscache_n_acquires_nobufs;
39557+atomic_unchecked_t fscache_n_acquires_oom;
39558+
39559+atomic_unchecked_t fscache_n_updates;
39560+atomic_unchecked_t fscache_n_updates_null;
39561+atomic_unchecked_t fscache_n_updates_run;
39562+
39563+atomic_unchecked_t fscache_n_relinquishes;
39564+atomic_unchecked_t fscache_n_relinquishes_null;
39565+atomic_unchecked_t fscache_n_relinquishes_waitcrt;
39566+atomic_unchecked_t fscache_n_relinquishes_retire;
39567+
39568+atomic_unchecked_t fscache_n_cookie_index;
39569+atomic_unchecked_t fscache_n_cookie_data;
39570+atomic_unchecked_t fscache_n_cookie_special;
39571+
39572+atomic_unchecked_t fscache_n_object_alloc;
39573+atomic_unchecked_t fscache_n_object_no_alloc;
39574+atomic_unchecked_t fscache_n_object_lookups;
39575+atomic_unchecked_t fscache_n_object_lookups_negative;
39576+atomic_unchecked_t fscache_n_object_lookups_positive;
39577+atomic_unchecked_t fscache_n_object_lookups_timed_out;
39578+atomic_unchecked_t fscache_n_object_created;
39579+atomic_unchecked_t fscache_n_object_avail;
39580+atomic_unchecked_t fscache_n_object_dead;
39581+
39582+atomic_unchecked_t fscache_n_checkaux_none;
39583+atomic_unchecked_t fscache_n_checkaux_okay;
39584+atomic_unchecked_t fscache_n_checkaux_update;
39585+atomic_unchecked_t fscache_n_checkaux_obsolete;
39586
39587 atomic_t fscache_n_cop_alloc_object;
39588 atomic_t fscache_n_cop_lookup_object;
39589@@ -133,113 +133,113 @@ static int fscache_stats_show(struct seq
39590 seq_puts(m, "FS-Cache statistics\n");
39591
39592 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
39593- atomic_read(&fscache_n_cookie_index),
39594- atomic_read(&fscache_n_cookie_data),
39595- atomic_read(&fscache_n_cookie_special));
39596+ atomic_read_unchecked(&fscache_n_cookie_index),
39597+ atomic_read_unchecked(&fscache_n_cookie_data),
39598+ atomic_read_unchecked(&fscache_n_cookie_special));
39599
39600 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
39601- atomic_read(&fscache_n_object_alloc),
39602- atomic_read(&fscache_n_object_no_alloc),
39603- atomic_read(&fscache_n_object_avail),
39604- atomic_read(&fscache_n_object_dead));
39605+ atomic_read_unchecked(&fscache_n_object_alloc),
39606+ atomic_read_unchecked(&fscache_n_object_no_alloc),
39607+ atomic_read_unchecked(&fscache_n_object_avail),
39608+ atomic_read_unchecked(&fscache_n_object_dead));
39609 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
39610- atomic_read(&fscache_n_checkaux_none),
39611- atomic_read(&fscache_n_checkaux_okay),
39612- atomic_read(&fscache_n_checkaux_update),
39613- atomic_read(&fscache_n_checkaux_obsolete));
39614+ atomic_read_unchecked(&fscache_n_checkaux_none),
39615+ atomic_read_unchecked(&fscache_n_checkaux_okay),
39616+ atomic_read_unchecked(&fscache_n_checkaux_update),
39617+ atomic_read_unchecked(&fscache_n_checkaux_obsolete));
39618
39619 seq_printf(m, "Pages : mrk=%u unc=%u\n",
39620- atomic_read(&fscache_n_marks),
39621- atomic_read(&fscache_n_uncaches));
39622+ atomic_read_unchecked(&fscache_n_marks),
39623+ atomic_read_unchecked(&fscache_n_uncaches));
39624
39625 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
39626 " oom=%u\n",
39627- atomic_read(&fscache_n_acquires),
39628- atomic_read(&fscache_n_acquires_null),
39629- atomic_read(&fscache_n_acquires_no_cache),
39630- atomic_read(&fscache_n_acquires_ok),
39631- atomic_read(&fscache_n_acquires_nobufs),
39632- atomic_read(&fscache_n_acquires_oom));
39633+ atomic_read_unchecked(&fscache_n_acquires),
39634+ atomic_read_unchecked(&fscache_n_acquires_null),
39635+ atomic_read_unchecked(&fscache_n_acquires_no_cache),
39636+ atomic_read_unchecked(&fscache_n_acquires_ok),
39637+ atomic_read_unchecked(&fscache_n_acquires_nobufs),
39638+ atomic_read_unchecked(&fscache_n_acquires_oom));
39639
39640 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
39641- atomic_read(&fscache_n_object_lookups),
39642- atomic_read(&fscache_n_object_lookups_negative),
39643- atomic_read(&fscache_n_object_lookups_positive),
39644- atomic_read(&fscache_n_object_lookups_timed_out),
39645- atomic_read(&fscache_n_object_created));
39646+ atomic_read_unchecked(&fscache_n_object_lookups),
39647+ atomic_read_unchecked(&fscache_n_object_lookups_negative),
39648+ atomic_read_unchecked(&fscache_n_object_lookups_positive),
39649+ atomic_read_unchecked(&fscache_n_object_lookups_timed_out),
39650+ atomic_read_unchecked(&fscache_n_object_created));
39651
39652 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
39653- atomic_read(&fscache_n_updates),
39654- atomic_read(&fscache_n_updates_null),
39655- atomic_read(&fscache_n_updates_run));
39656+ atomic_read_unchecked(&fscache_n_updates),
39657+ atomic_read_unchecked(&fscache_n_updates_null),
39658+ atomic_read_unchecked(&fscache_n_updates_run));
39659
39660 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
39661- atomic_read(&fscache_n_relinquishes),
39662- atomic_read(&fscache_n_relinquishes_null),
39663- atomic_read(&fscache_n_relinquishes_waitcrt),
39664- atomic_read(&fscache_n_relinquishes_retire));
39665+ atomic_read_unchecked(&fscache_n_relinquishes),
39666+ atomic_read_unchecked(&fscache_n_relinquishes_null),
39667+ atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
39668+ atomic_read_unchecked(&fscache_n_relinquishes_retire));
39669
39670 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
39671- atomic_read(&fscache_n_attr_changed),
39672- atomic_read(&fscache_n_attr_changed_ok),
39673- atomic_read(&fscache_n_attr_changed_nobufs),
39674- atomic_read(&fscache_n_attr_changed_nomem),
39675- atomic_read(&fscache_n_attr_changed_calls));
39676+ atomic_read_unchecked(&fscache_n_attr_changed),
39677+ atomic_read_unchecked(&fscache_n_attr_changed_ok),
39678+ atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
39679+ atomic_read_unchecked(&fscache_n_attr_changed_nomem),
39680+ atomic_read_unchecked(&fscache_n_attr_changed_calls));
39681
39682 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
39683- atomic_read(&fscache_n_allocs),
39684- atomic_read(&fscache_n_allocs_ok),
39685- atomic_read(&fscache_n_allocs_wait),
39686- atomic_read(&fscache_n_allocs_nobufs),
39687- atomic_read(&fscache_n_allocs_intr));
39688+ atomic_read_unchecked(&fscache_n_allocs),
39689+ atomic_read_unchecked(&fscache_n_allocs_ok),
39690+ atomic_read_unchecked(&fscache_n_allocs_wait),
39691+ atomic_read_unchecked(&fscache_n_allocs_nobufs),
39692+ atomic_read_unchecked(&fscache_n_allocs_intr));
39693 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
39694- atomic_read(&fscache_n_alloc_ops),
39695- atomic_read(&fscache_n_alloc_op_waits),
39696- atomic_read(&fscache_n_allocs_object_dead));
39697+ atomic_read_unchecked(&fscache_n_alloc_ops),
39698+ atomic_read_unchecked(&fscache_n_alloc_op_waits),
39699+ atomic_read_unchecked(&fscache_n_allocs_object_dead));
39700
39701 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
39702 " int=%u oom=%u\n",
39703- atomic_read(&fscache_n_retrievals),
39704- atomic_read(&fscache_n_retrievals_ok),
39705- atomic_read(&fscache_n_retrievals_wait),
39706- atomic_read(&fscache_n_retrievals_nodata),
39707- atomic_read(&fscache_n_retrievals_nobufs),
39708- atomic_read(&fscache_n_retrievals_intr),
39709- atomic_read(&fscache_n_retrievals_nomem));
39710+ atomic_read_unchecked(&fscache_n_retrievals),
39711+ atomic_read_unchecked(&fscache_n_retrievals_ok),
39712+ atomic_read_unchecked(&fscache_n_retrievals_wait),
39713+ atomic_read_unchecked(&fscache_n_retrievals_nodata),
39714+ atomic_read_unchecked(&fscache_n_retrievals_nobufs),
39715+ atomic_read_unchecked(&fscache_n_retrievals_intr),
39716+ atomic_read_unchecked(&fscache_n_retrievals_nomem));
39717 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
39718- atomic_read(&fscache_n_retrieval_ops),
39719- atomic_read(&fscache_n_retrieval_op_waits),
39720- atomic_read(&fscache_n_retrievals_object_dead));
39721+ atomic_read_unchecked(&fscache_n_retrieval_ops),
39722+ atomic_read_unchecked(&fscache_n_retrieval_op_waits),
39723+ atomic_read_unchecked(&fscache_n_retrievals_object_dead));
39724
39725 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
39726- atomic_read(&fscache_n_stores),
39727- atomic_read(&fscache_n_stores_ok),
39728- atomic_read(&fscache_n_stores_again),
39729- atomic_read(&fscache_n_stores_nobufs),
39730- atomic_read(&fscache_n_stores_oom));
39731+ atomic_read_unchecked(&fscache_n_stores),
39732+ atomic_read_unchecked(&fscache_n_stores_ok),
39733+ atomic_read_unchecked(&fscache_n_stores_again),
39734+ atomic_read_unchecked(&fscache_n_stores_nobufs),
39735+ atomic_read_unchecked(&fscache_n_stores_oom));
39736 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
39737- atomic_read(&fscache_n_store_ops),
39738- atomic_read(&fscache_n_store_calls),
39739- atomic_read(&fscache_n_store_pages),
39740- atomic_read(&fscache_n_store_radix_deletes),
39741- atomic_read(&fscache_n_store_pages_over_limit));
39742+ atomic_read_unchecked(&fscache_n_store_ops),
39743+ atomic_read_unchecked(&fscache_n_store_calls),
39744+ atomic_read_unchecked(&fscache_n_store_pages),
39745+ atomic_read_unchecked(&fscache_n_store_radix_deletes),
39746+ atomic_read_unchecked(&fscache_n_store_pages_over_limit));
39747
39748 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u\n",
39749- atomic_read(&fscache_n_store_vmscan_not_storing),
39750- atomic_read(&fscache_n_store_vmscan_gone),
39751- atomic_read(&fscache_n_store_vmscan_busy),
39752- atomic_read(&fscache_n_store_vmscan_cancelled));
39753+ atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
39754+ atomic_read_unchecked(&fscache_n_store_vmscan_gone),
39755+ atomic_read_unchecked(&fscache_n_store_vmscan_busy),
39756+ atomic_read_unchecked(&fscache_n_store_vmscan_cancelled));
39757
39758 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
39759- atomic_read(&fscache_n_op_pend),
39760- atomic_read(&fscache_n_op_run),
39761- atomic_read(&fscache_n_op_enqueue),
39762- atomic_read(&fscache_n_op_cancelled),
39763- atomic_read(&fscache_n_op_rejected));
39764+ atomic_read_unchecked(&fscache_n_op_pend),
39765+ atomic_read_unchecked(&fscache_n_op_run),
39766+ atomic_read_unchecked(&fscache_n_op_enqueue),
39767+ atomic_read_unchecked(&fscache_n_op_cancelled),
39768+ atomic_read_unchecked(&fscache_n_op_rejected));
39769 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
39770- atomic_read(&fscache_n_op_deferred_release),
39771- atomic_read(&fscache_n_op_release),
39772- atomic_read(&fscache_n_op_gc));
39773+ atomic_read_unchecked(&fscache_n_op_deferred_release),
39774+ atomic_read_unchecked(&fscache_n_op_release),
39775+ atomic_read_unchecked(&fscache_n_op_gc));
39776
39777 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
39778 atomic_read(&fscache_n_cop_alloc_object),
39779diff -urNp linux-2.6.32.41/fs/fs_struct.c linux-2.6.32.41/fs/fs_struct.c
39780--- linux-2.6.32.41/fs/fs_struct.c 2011-03-27 14:31:47.000000000 -0400
39781+++ linux-2.6.32.41/fs/fs_struct.c 2011-04-17 15:56:46.000000000 -0400
39782@@ -4,6 +4,7 @@
39783 #include <linux/path.h>
39784 #include <linux/slab.h>
39785 #include <linux/fs_struct.h>
39786+#include <linux/grsecurity.h>
39787
39788 /*
39789 * Replace the fs->{rootmnt,root} with {mnt,dentry}. Put the old values.
39790@@ -17,6 +18,7 @@ void set_fs_root(struct fs_struct *fs, s
39791 old_root = fs->root;
39792 fs->root = *path;
39793 path_get(path);
39794+ gr_set_chroot_entries(current, path);
39795 write_unlock(&fs->lock);
39796 if (old_root.dentry)
39797 path_put(&old_root);
39798@@ -56,6 +58,7 @@ void chroot_fs_refs(struct path *old_roo
39799 && fs->root.mnt == old_root->mnt) {
39800 path_get(new_root);
39801 fs->root = *new_root;
39802+ gr_set_chroot_entries(p, new_root);
39803 count++;
39804 }
39805 if (fs->pwd.dentry == old_root->dentry
39806@@ -89,7 +92,8 @@ void exit_fs(struct task_struct *tsk)
39807 task_lock(tsk);
39808 write_lock(&fs->lock);
39809 tsk->fs = NULL;
39810- kill = !--fs->users;
39811+ gr_clear_chroot_entries(tsk);
39812+ kill = !atomic_dec_return(&fs->users);
39813 write_unlock(&fs->lock);
39814 task_unlock(tsk);
39815 if (kill)
39816@@ -102,7 +106,7 @@ struct fs_struct *copy_fs_struct(struct
39817 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
39818 /* We don't need to lock fs - think why ;-) */
39819 if (fs) {
39820- fs->users = 1;
39821+ atomic_set(&fs->users, 1);
39822 fs->in_exec = 0;
39823 rwlock_init(&fs->lock);
39824 fs->umask = old->umask;
39825@@ -127,8 +131,9 @@ int unshare_fs_struct(void)
39826
39827 task_lock(current);
39828 write_lock(&fs->lock);
39829- kill = !--fs->users;
39830+ kill = !atomic_dec_return(&fs->users);
39831 current->fs = new_fs;
39832+ gr_set_chroot_entries(current, &new_fs->root);
39833 write_unlock(&fs->lock);
39834 task_unlock(current);
39835
39836@@ -147,7 +152,7 @@ EXPORT_SYMBOL(current_umask);
39837
39838 /* to be mentioned only in INIT_TASK */
39839 struct fs_struct init_fs = {
39840- .users = 1,
39841+ .users = ATOMIC_INIT(1),
39842 .lock = __RW_LOCK_UNLOCKED(init_fs.lock),
39843 .umask = 0022,
39844 };
39845@@ -162,12 +167,13 @@ void daemonize_fs_struct(void)
39846 task_lock(current);
39847
39848 write_lock(&init_fs.lock);
39849- init_fs.users++;
39850+ atomic_inc(&init_fs.users);
39851 write_unlock(&init_fs.lock);
39852
39853 write_lock(&fs->lock);
39854 current->fs = &init_fs;
39855- kill = !--fs->users;
39856+ gr_set_chroot_entries(current, &current->fs->root);
39857+ kill = !atomic_dec_return(&fs->users);
39858 write_unlock(&fs->lock);
39859
39860 task_unlock(current);
39861diff -urNp linux-2.6.32.41/fs/fuse/cuse.c linux-2.6.32.41/fs/fuse/cuse.c
39862--- linux-2.6.32.41/fs/fuse/cuse.c 2011-03-27 14:31:47.000000000 -0400
39863+++ linux-2.6.32.41/fs/fuse/cuse.c 2011-04-17 15:56:46.000000000 -0400
39864@@ -528,8 +528,18 @@ static int cuse_channel_release(struct i
39865 return rc;
39866 }
39867
39868-static struct file_operations cuse_channel_fops; /* initialized during init */
39869-
39870+static const struct file_operations cuse_channel_fops = { /* initialized during init */
39871+ .owner = THIS_MODULE,
39872+ .llseek = no_llseek,
39873+ .read = do_sync_read,
39874+ .aio_read = fuse_dev_read,
39875+ .write = do_sync_write,
39876+ .aio_write = fuse_dev_write,
39877+ .poll = fuse_dev_poll,
39878+ .open = cuse_channel_open,
39879+ .release = cuse_channel_release,
39880+ .fasync = fuse_dev_fasync,
39881+};
39882
39883 /**************************************************************************
39884 * Misc stuff and module initializatiion
39885@@ -575,12 +585,6 @@ static int __init cuse_init(void)
39886 for (i = 0; i < CUSE_CONNTBL_LEN; i++)
39887 INIT_LIST_HEAD(&cuse_conntbl[i]);
39888
39889- /* inherit and extend fuse_dev_operations */
39890- cuse_channel_fops = fuse_dev_operations;
39891- cuse_channel_fops.owner = THIS_MODULE;
39892- cuse_channel_fops.open = cuse_channel_open;
39893- cuse_channel_fops.release = cuse_channel_release;
39894-
39895 cuse_class = class_create(THIS_MODULE, "cuse");
39896 if (IS_ERR(cuse_class))
39897 return PTR_ERR(cuse_class);
39898diff -urNp linux-2.6.32.41/fs/fuse/dev.c linux-2.6.32.41/fs/fuse/dev.c
39899--- linux-2.6.32.41/fs/fuse/dev.c 2011-03-27 14:31:47.000000000 -0400
39900+++ linux-2.6.32.41/fs/fuse/dev.c 2011-04-17 15:56:46.000000000 -0400
39901@@ -745,7 +745,7 @@ __releases(&fc->lock)
39902 * request_end(). Otherwise add it to the processing list, and set
39903 * the 'sent' flag.
39904 */
39905-static ssize_t fuse_dev_read(struct kiocb *iocb, const struct iovec *iov,
39906+ssize_t fuse_dev_read(struct kiocb *iocb, const struct iovec *iov,
39907 unsigned long nr_segs, loff_t pos)
39908 {
39909 int err;
39910@@ -827,6 +827,7 @@ static ssize_t fuse_dev_read(struct kioc
39911 spin_unlock(&fc->lock);
39912 return err;
39913 }
39914+EXPORT_SYMBOL_GPL(fuse_dev_read);
39915
39916 static int fuse_notify_poll(struct fuse_conn *fc, unsigned int size,
39917 struct fuse_copy_state *cs)
39918@@ -885,7 +886,7 @@ static int fuse_notify_inval_entry(struc
39919 {
39920 struct fuse_notify_inval_entry_out outarg;
39921 int err = -EINVAL;
39922- char buf[FUSE_NAME_MAX+1];
39923+ char *buf = NULL;
39924 struct qstr name;
39925
39926 if (size < sizeof(outarg))
39927@@ -899,6 +900,11 @@ static int fuse_notify_inval_entry(struc
39928 if (outarg.namelen > FUSE_NAME_MAX)
39929 goto err;
39930
39931+ err = -ENOMEM;
39932+ buf = kmalloc(FUSE_NAME_MAX+1, GFP_KERNEL);
39933+ if (!buf)
39934+ goto err;
39935+
39936 name.name = buf;
39937 name.len = outarg.namelen;
39938 err = fuse_copy_one(cs, buf, outarg.namelen + 1);
39939@@ -910,17 +916,15 @@ static int fuse_notify_inval_entry(struc
39940
39941 down_read(&fc->killsb);
39942 err = -ENOENT;
39943- if (!fc->sb)
39944- goto err_unlock;
39945-
39946- err = fuse_reverse_inval_entry(fc->sb, outarg.parent, &name);
39947-
39948-err_unlock:
39949+ if (fc->sb)
39950+ err = fuse_reverse_inval_entry(fc->sb, outarg.parent, &name);
39951 up_read(&fc->killsb);
39952+ kfree(buf);
39953 return err;
39954
39955 err:
39956 fuse_copy_finish(cs);
39957+ kfree(buf);
39958 return err;
39959 }
39960
39961@@ -987,7 +991,7 @@ static int copy_out_args(struct fuse_cop
39962 * it from the list and copy the rest of the buffer to the request.
39963 * The request is finished by calling request_end()
39964 */
39965-static ssize_t fuse_dev_write(struct kiocb *iocb, const struct iovec *iov,
39966+ssize_t fuse_dev_write(struct kiocb *iocb, const struct iovec *iov,
39967 unsigned long nr_segs, loff_t pos)
39968 {
39969 int err;
39970@@ -1083,8 +1087,9 @@ static ssize_t fuse_dev_write(struct kio
39971 fuse_copy_finish(&cs);
39972 return err;
39973 }
39974+EXPORT_SYMBOL_GPL(fuse_dev_write);
39975
39976-static unsigned fuse_dev_poll(struct file *file, poll_table *wait)
39977+unsigned fuse_dev_poll(struct file *file, poll_table *wait)
39978 {
39979 unsigned mask = POLLOUT | POLLWRNORM;
39980 struct fuse_conn *fc = fuse_get_conn(file);
39981@@ -1102,6 +1107,7 @@ static unsigned fuse_dev_poll(struct fil
39982
39983 return mask;
39984 }
39985+EXPORT_SYMBOL_GPL(fuse_dev_poll);
39986
39987 /*
39988 * Abort all requests on the given list (pending or processing)
39989@@ -1218,7 +1224,7 @@ int fuse_dev_release(struct inode *inode
39990 }
39991 EXPORT_SYMBOL_GPL(fuse_dev_release);
39992
39993-static int fuse_dev_fasync(int fd, struct file *file, int on)
39994+int fuse_dev_fasync(int fd, struct file *file, int on)
39995 {
39996 struct fuse_conn *fc = fuse_get_conn(file);
39997 if (!fc)
39998@@ -1227,6 +1233,7 @@ static int fuse_dev_fasync(int fd, struc
39999 /* No locking - fasync_helper does its own locking */
40000 return fasync_helper(fd, file, on, &fc->fasync);
40001 }
40002+EXPORT_SYMBOL_GPL(fuse_dev_fasync);
40003
40004 const struct file_operations fuse_dev_operations = {
40005 .owner = THIS_MODULE,
40006diff -urNp linux-2.6.32.41/fs/fuse/dir.c linux-2.6.32.41/fs/fuse/dir.c
40007--- linux-2.6.32.41/fs/fuse/dir.c 2011-03-27 14:31:47.000000000 -0400
40008+++ linux-2.6.32.41/fs/fuse/dir.c 2011-04-17 15:56:46.000000000 -0400
40009@@ -1127,7 +1127,7 @@ static char *read_link(struct dentry *de
40010 return link;
40011 }
40012
40013-static void free_link(char *link)
40014+static void free_link(const char *link)
40015 {
40016 if (!IS_ERR(link))
40017 free_page((unsigned long) link);
40018diff -urNp linux-2.6.32.41/fs/fuse/fuse_i.h linux-2.6.32.41/fs/fuse/fuse_i.h
40019--- linux-2.6.32.41/fs/fuse/fuse_i.h 2011-03-27 14:31:47.000000000 -0400
40020+++ linux-2.6.32.41/fs/fuse/fuse_i.h 2011-04-17 15:56:46.000000000 -0400
40021@@ -525,6 +525,16 @@ extern const struct file_operations fuse
40022
40023 extern const struct dentry_operations fuse_dentry_operations;
40024
40025+extern ssize_t fuse_dev_read(struct kiocb *iocb, const struct iovec *iov,
40026+ unsigned long nr_segs, loff_t pos);
40027+
40028+extern ssize_t fuse_dev_write(struct kiocb *iocb, const struct iovec *iov,
40029+ unsigned long nr_segs, loff_t pos);
40030+
40031+extern unsigned fuse_dev_poll(struct file *file, poll_table *wait);
40032+
40033+extern int fuse_dev_fasync(int fd, struct file *file, int on);
40034+
40035 /**
40036 * Inode to nodeid comparison.
40037 */
40038diff -urNp linux-2.6.32.41/fs/gfs2/ops_inode.c linux-2.6.32.41/fs/gfs2/ops_inode.c
40039--- linux-2.6.32.41/fs/gfs2/ops_inode.c 2011-03-27 14:31:47.000000000 -0400
40040+++ linux-2.6.32.41/fs/gfs2/ops_inode.c 2011-05-16 21:46:57.000000000 -0400
40041@@ -752,6 +752,8 @@ static int gfs2_rename(struct inode *odi
40042 unsigned int x;
40043 int error;
40044
40045+ pax_track_stack();
40046+
40047 if (ndentry->d_inode) {
40048 nip = GFS2_I(ndentry->d_inode);
40049 if (ip == nip)
40050diff -urNp linux-2.6.32.41/fs/gfs2/sys.c linux-2.6.32.41/fs/gfs2/sys.c
40051--- linux-2.6.32.41/fs/gfs2/sys.c 2011-03-27 14:31:47.000000000 -0400
40052+++ linux-2.6.32.41/fs/gfs2/sys.c 2011-04-17 15:56:46.000000000 -0400
40053@@ -49,7 +49,7 @@ static ssize_t gfs2_attr_store(struct ko
40054 return a->store ? a->store(sdp, buf, len) : len;
40055 }
40056
40057-static struct sysfs_ops gfs2_attr_ops = {
40058+static const struct sysfs_ops gfs2_attr_ops = {
40059 .show = gfs2_attr_show,
40060 .store = gfs2_attr_store,
40061 };
40062@@ -584,7 +584,7 @@ static int gfs2_uevent(struct kset *kset
40063 return 0;
40064 }
40065
40066-static struct kset_uevent_ops gfs2_uevent_ops = {
40067+static const struct kset_uevent_ops gfs2_uevent_ops = {
40068 .uevent = gfs2_uevent,
40069 };
40070
40071diff -urNp linux-2.6.32.41/fs/hfsplus/catalog.c linux-2.6.32.41/fs/hfsplus/catalog.c
40072--- linux-2.6.32.41/fs/hfsplus/catalog.c 2011-03-27 14:31:47.000000000 -0400
40073+++ linux-2.6.32.41/fs/hfsplus/catalog.c 2011-05-16 21:46:57.000000000 -0400
40074@@ -157,6 +157,8 @@ int hfsplus_find_cat(struct super_block
40075 int err;
40076 u16 type;
40077
40078+ pax_track_stack();
40079+
40080 hfsplus_cat_build_key(sb, fd->search_key, cnid, NULL);
40081 err = hfs_brec_read(fd, &tmp, sizeof(hfsplus_cat_entry));
40082 if (err)
40083@@ -186,6 +188,8 @@ int hfsplus_create_cat(u32 cnid, struct
40084 int entry_size;
40085 int err;
40086
40087+ pax_track_stack();
40088+
40089 dprint(DBG_CAT_MOD, "create_cat: %s,%u(%d)\n", str->name, cnid, inode->i_nlink);
40090 sb = dir->i_sb;
40091 hfs_find_init(HFSPLUS_SB(sb).cat_tree, &fd);
40092@@ -318,6 +322,8 @@ int hfsplus_rename_cat(u32 cnid,
40093 int entry_size, type;
40094 int err = 0;
40095
40096+ pax_track_stack();
40097+
40098 dprint(DBG_CAT_MOD, "rename_cat: %u - %lu,%s - %lu,%s\n", cnid, src_dir->i_ino, src_name->name,
40099 dst_dir->i_ino, dst_name->name);
40100 sb = src_dir->i_sb;
40101diff -urNp linux-2.6.32.41/fs/hfsplus/dir.c linux-2.6.32.41/fs/hfsplus/dir.c
40102--- linux-2.6.32.41/fs/hfsplus/dir.c 2011-03-27 14:31:47.000000000 -0400
40103+++ linux-2.6.32.41/fs/hfsplus/dir.c 2011-05-16 21:46:57.000000000 -0400
40104@@ -121,6 +121,8 @@ static int hfsplus_readdir(struct file *
40105 struct hfsplus_readdir_data *rd;
40106 u16 type;
40107
40108+ pax_track_stack();
40109+
40110 if (filp->f_pos >= inode->i_size)
40111 return 0;
40112
40113diff -urNp linux-2.6.32.41/fs/hfsplus/inode.c linux-2.6.32.41/fs/hfsplus/inode.c
40114--- linux-2.6.32.41/fs/hfsplus/inode.c 2011-03-27 14:31:47.000000000 -0400
40115+++ linux-2.6.32.41/fs/hfsplus/inode.c 2011-05-16 21:46:57.000000000 -0400
40116@@ -399,6 +399,8 @@ int hfsplus_cat_read_inode(struct inode
40117 int res = 0;
40118 u16 type;
40119
40120+ pax_track_stack();
40121+
40122 type = hfs_bnode_read_u16(fd->bnode, fd->entryoffset);
40123
40124 HFSPLUS_I(inode).dev = 0;
40125@@ -461,6 +463,8 @@ int hfsplus_cat_write_inode(struct inode
40126 struct hfs_find_data fd;
40127 hfsplus_cat_entry entry;
40128
40129+ pax_track_stack();
40130+
40131 if (HFSPLUS_IS_RSRC(inode))
40132 main_inode = HFSPLUS_I(inode).rsrc_inode;
40133
40134diff -urNp linux-2.6.32.41/fs/hfsplus/ioctl.c linux-2.6.32.41/fs/hfsplus/ioctl.c
40135--- linux-2.6.32.41/fs/hfsplus/ioctl.c 2011-03-27 14:31:47.000000000 -0400
40136+++ linux-2.6.32.41/fs/hfsplus/ioctl.c 2011-05-16 21:46:57.000000000 -0400
40137@@ -101,6 +101,8 @@ int hfsplus_setxattr(struct dentry *dent
40138 struct hfsplus_cat_file *file;
40139 int res;
40140
40141+ pax_track_stack();
40142+
40143 if (!S_ISREG(inode->i_mode) || HFSPLUS_IS_RSRC(inode))
40144 return -EOPNOTSUPP;
40145
40146@@ -143,6 +145,8 @@ ssize_t hfsplus_getxattr(struct dentry *
40147 struct hfsplus_cat_file *file;
40148 ssize_t res = 0;
40149
40150+ pax_track_stack();
40151+
40152 if (!S_ISREG(inode->i_mode) || HFSPLUS_IS_RSRC(inode))
40153 return -EOPNOTSUPP;
40154
40155diff -urNp linux-2.6.32.41/fs/hfsplus/super.c linux-2.6.32.41/fs/hfsplus/super.c
40156--- linux-2.6.32.41/fs/hfsplus/super.c 2011-03-27 14:31:47.000000000 -0400
40157+++ linux-2.6.32.41/fs/hfsplus/super.c 2011-05-16 21:46:57.000000000 -0400
40158@@ -312,6 +312,8 @@ static int hfsplus_fill_super(struct sup
40159 struct nls_table *nls = NULL;
40160 int err = -EINVAL;
40161
40162+ pax_track_stack();
40163+
40164 sbi = kzalloc(sizeof(*sbi), GFP_KERNEL);
40165 if (!sbi)
40166 return -ENOMEM;
40167diff -urNp linux-2.6.32.41/fs/hugetlbfs/inode.c linux-2.6.32.41/fs/hugetlbfs/inode.c
40168--- linux-2.6.32.41/fs/hugetlbfs/inode.c 2011-03-27 14:31:47.000000000 -0400
40169+++ linux-2.6.32.41/fs/hugetlbfs/inode.c 2011-04-17 15:56:46.000000000 -0400
40170@@ -909,7 +909,7 @@ static struct file_system_type hugetlbfs
40171 .kill_sb = kill_litter_super,
40172 };
40173
40174-static struct vfsmount *hugetlbfs_vfsmount;
40175+struct vfsmount *hugetlbfs_vfsmount;
40176
40177 static int can_do_hugetlb_shm(void)
40178 {
40179diff -urNp linux-2.6.32.41/fs/ioctl.c linux-2.6.32.41/fs/ioctl.c
40180--- linux-2.6.32.41/fs/ioctl.c 2011-03-27 14:31:47.000000000 -0400
40181+++ linux-2.6.32.41/fs/ioctl.c 2011-04-17 15:56:46.000000000 -0400
40182@@ -97,7 +97,7 @@ int fiemap_fill_next_extent(struct fiema
40183 u64 phys, u64 len, u32 flags)
40184 {
40185 struct fiemap_extent extent;
40186- struct fiemap_extent *dest = fieinfo->fi_extents_start;
40187+ struct fiemap_extent __user *dest = fieinfo->fi_extents_start;
40188
40189 /* only count the extents */
40190 if (fieinfo->fi_extents_max == 0) {
40191@@ -207,7 +207,7 @@ static int ioctl_fiemap(struct file *fil
40192
40193 fieinfo.fi_flags = fiemap.fm_flags;
40194 fieinfo.fi_extents_max = fiemap.fm_extent_count;
40195- fieinfo.fi_extents_start = (struct fiemap_extent *)(arg + sizeof(fiemap));
40196+ fieinfo.fi_extents_start = (struct fiemap_extent __user *)(arg + sizeof(fiemap));
40197
40198 if (fiemap.fm_extent_count != 0 &&
40199 !access_ok(VERIFY_WRITE, fieinfo.fi_extents_start,
40200@@ -220,7 +220,7 @@ static int ioctl_fiemap(struct file *fil
40201 error = inode->i_op->fiemap(inode, &fieinfo, fiemap.fm_start, len);
40202 fiemap.fm_flags = fieinfo.fi_flags;
40203 fiemap.fm_mapped_extents = fieinfo.fi_extents_mapped;
40204- if (copy_to_user((char *)arg, &fiemap, sizeof(fiemap)))
40205+ if (copy_to_user((__force char __user *)arg, &fiemap, sizeof(fiemap)))
40206 error = -EFAULT;
40207
40208 return error;
40209diff -urNp linux-2.6.32.41/fs/jbd/checkpoint.c linux-2.6.32.41/fs/jbd/checkpoint.c
40210--- linux-2.6.32.41/fs/jbd/checkpoint.c 2011-03-27 14:31:47.000000000 -0400
40211+++ linux-2.6.32.41/fs/jbd/checkpoint.c 2011-05-16 21:46:57.000000000 -0400
40212@@ -348,6 +348,8 @@ int log_do_checkpoint(journal_t *journal
40213 tid_t this_tid;
40214 int result;
40215
40216+ pax_track_stack();
40217+
40218 jbd_debug(1, "Start checkpoint\n");
40219
40220 /*
40221diff -urNp linux-2.6.32.41/fs/jffs2/compr_rtime.c linux-2.6.32.41/fs/jffs2/compr_rtime.c
40222--- linux-2.6.32.41/fs/jffs2/compr_rtime.c 2011-03-27 14:31:47.000000000 -0400
40223+++ linux-2.6.32.41/fs/jffs2/compr_rtime.c 2011-05-16 21:46:57.000000000 -0400
40224@@ -37,6 +37,8 @@ static int jffs2_rtime_compress(unsigned
40225 int outpos = 0;
40226 int pos=0;
40227
40228+ pax_track_stack();
40229+
40230 memset(positions,0,sizeof(positions));
40231
40232 while (pos < (*sourcelen) && outpos <= (*dstlen)-2) {
40233@@ -79,6 +81,8 @@ static int jffs2_rtime_decompress(unsign
40234 int outpos = 0;
40235 int pos=0;
40236
40237+ pax_track_stack();
40238+
40239 memset(positions,0,sizeof(positions));
40240
40241 while (outpos<destlen) {
40242diff -urNp linux-2.6.32.41/fs/jffs2/compr_rubin.c linux-2.6.32.41/fs/jffs2/compr_rubin.c
40243--- linux-2.6.32.41/fs/jffs2/compr_rubin.c 2011-03-27 14:31:47.000000000 -0400
40244+++ linux-2.6.32.41/fs/jffs2/compr_rubin.c 2011-05-16 21:46:57.000000000 -0400
40245@@ -314,6 +314,8 @@ static int jffs2_dynrubin_compress(unsig
40246 int ret;
40247 uint32_t mysrclen, mydstlen;
40248
40249+ pax_track_stack();
40250+
40251 mysrclen = *sourcelen;
40252 mydstlen = *dstlen - 8;
40253
40254diff -urNp linux-2.6.32.41/fs/jffs2/erase.c linux-2.6.32.41/fs/jffs2/erase.c
40255--- linux-2.6.32.41/fs/jffs2/erase.c 2011-03-27 14:31:47.000000000 -0400
40256+++ linux-2.6.32.41/fs/jffs2/erase.c 2011-04-17 15:56:46.000000000 -0400
40257@@ -434,7 +434,8 @@ static void jffs2_mark_erased_block(stru
40258 struct jffs2_unknown_node marker = {
40259 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
40260 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
40261- .totlen = cpu_to_je32(c->cleanmarker_size)
40262+ .totlen = cpu_to_je32(c->cleanmarker_size),
40263+ .hdr_crc = cpu_to_je32(0)
40264 };
40265
40266 jffs2_prealloc_raw_node_refs(c, jeb, 1);
40267diff -urNp linux-2.6.32.41/fs/jffs2/wbuf.c linux-2.6.32.41/fs/jffs2/wbuf.c
40268--- linux-2.6.32.41/fs/jffs2/wbuf.c 2011-03-27 14:31:47.000000000 -0400
40269+++ linux-2.6.32.41/fs/jffs2/wbuf.c 2011-04-17 15:56:46.000000000 -0400
40270@@ -1012,7 +1012,8 @@ static const struct jffs2_unknown_node o
40271 {
40272 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
40273 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
40274- .totlen = constant_cpu_to_je32(8)
40275+ .totlen = constant_cpu_to_je32(8),
40276+ .hdr_crc = constant_cpu_to_je32(0)
40277 };
40278
40279 /*
40280diff -urNp linux-2.6.32.41/fs/jffs2/xattr.c linux-2.6.32.41/fs/jffs2/xattr.c
40281--- linux-2.6.32.41/fs/jffs2/xattr.c 2011-03-27 14:31:47.000000000 -0400
40282+++ linux-2.6.32.41/fs/jffs2/xattr.c 2011-05-16 21:46:57.000000000 -0400
40283@@ -773,6 +773,8 @@ void jffs2_build_xattr_subsystem(struct
40284
40285 BUG_ON(!(c->flags & JFFS2_SB_FLAG_BUILDING));
40286
40287+ pax_track_stack();
40288+
40289 /* Phase.1 : Merge same xref */
40290 for (i=0; i < XREF_TMPHASH_SIZE; i++)
40291 xref_tmphash[i] = NULL;
40292diff -urNp linux-2.6.32.41/fs/jfs/super.c linux-2.6.32.41/fs/jfs/super.c
40293--- linux-2.6.32.41/fs/jfs/super.c 2011-03-27 14:31:47.000000000 -0400
40294+++ linux-2.6.32.41/fs/jfs/super.c 2011-06-07 18:06:04.000000000 -0400
40295@@ -793,7 +793,7 @@ static int __init init_jfs_fs(void)
40296
40297 jfs_inode_cachep =
40298 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
40299- SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
40300+ SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
40301 init_once);
40302 if (jfs_inode_cachep == NULL)
40303 return -ENOMEM;
40304diff -urNp linux-2.6.32.41/fs/Kconfig.binfmt linux-2.6.32.41/fs/Kconfig.binfmt
40305--- linux-2.6.32.41/fs/Kconfig.binfmt 2011-03-27 14:31:47.000000000 -0400
40306+++ linux-2.6.32.41/fs/Kconfig.binfmt 2011-04-17 15:56:46.000000000 -0400
40307@@ -86,7 +86,7 @@ config HAVE_AOUT
40308
40309 config BINFMT_AOUT
40310 tristate "Kernel support for a.out and ECOFF binaries"
40311- depends on HAVE_AOUT
40312+ depends on HAVE_AOUT && BROKEN
40313 ---help---
40314 A.out (Assembler.OUTput) is a set of formats for libraries and
40315 executables used in the earliest versions of UNIX. Linux used
40316diff -urNp linux-2.6.32.41/fs/libfs.c linux-2.6.32.41/fs/libfs.c
40317--- linux-2.6.32.41/fs/libfs.c 2011-03-27 14:31:47.000000000 -0400
40318+++ linux-2.6.32.41/fs/libfs.c 2011-05-11 18:25:15.000000000 -0400
40319@@ -157,12 +157,20 @@ int dcache_readdir(struct file * filp, v
40320
40321 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
40322 struct dentry *next;
40323+ char d_name[sizeof(next->d_iname)];
40324+ const unsigned char *name;
40325+
40326 next = list_entry(p, struct dentry, d_u.d_child);
40327 if (d_unhashed(next) || !next->d_inode)
40328 continue;
40329
40330 spin_unlock(&dcache_lock);
40331- if (filldir(dirent, next->d_name.name,
40332+ name = next->d_name.name;
40333+ if (name == next->d_iname) {
40334+ memcpy(d_name, name, next->d_name.len);
40335+ name = d_name;
40336+ }
40337+ if (filldir(dirent, name,
40338 next->d_name.len, filp->f_pos,
40339 next->d_inode->i_ino,
40340 dt_type(next->d_inode)) < 0)
40341diff -urNp linux-2.6.32.41/fs/lockd/clntproc.c linux-2.6.32.41/fs/lockd/clntproc.c
40342--- linux-2.6.32.41/fs/lockd/clntproc.c 2011-03-27 14:31:47.000000000 -0400
40343+++ linux-2.6.32.41/fs/lockd/clntproc.c 2011-05-16 21:46:57.000000000 -0400
40344@@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt
40345 /*
40346 * Cookie counter for NLM requests
40347 */
40348-static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
40349+static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
40350
40351 void nlmclnt_next_cookie(struct nlm_cookie *c)
40352 {
40353- u32 cookie = atomic_inc_return(&nlm_cookie);
40354+ u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
40355
40356 memcpy(c->data, &cookie, 4);
40357 c->len=4;
40358@@ -621,6 +621,8 @@ nlmclnt_reclaim(struct nlm_host *host, s
40359 struct nlm_rqst reqst, *req;
40360 int status;
40361
40362+ pax_track_stack();
40363+
40364 req = &reqst;
40365 memset(req, 0, sizeof(*req));
40366 locks_init_lock(&req->a_args.lock.fl);
40367diff -urNp linux-2.6.32.41/fs/lockd/svc.c linux-2.6.32.41/fs/lockd/svc.c
40368--- linux-2.6.32.41/fs/lockd/svc.c 2011-03-27 14:31:47.000000000 -0400
40369+++ linux-2.6.32.41/fs/lockd/svc.c 2011-04-17 15:56:46.000000000 -0400
40370@@ -43,7 +43,7 @@
40371
40372 static struct svc_program nlmsvc_program;
40373
40374-struct nlmsvc_binding * nlmsvc_ops;
40375+const struct nlmsvc_binding * nlmsvc_ops;
40376 EXPORT_SYMBOL_GPL(nlmsvc_ops);
40377
40378 static DEFINE_MUTEX(nlmsvc_mutex);
40379diff -urNp linux-2.6.32.41/fs/locks.c linux-2.6.32.41/fs/locks.c
40380--- linux-2.6.32.41/fs/locks.c 2011-03-27 14:31:47.000000000 -0400
40381+++ linux-2.6.32.41/fs/locks.c 2011-04-17 15:56:46.000000000 -0400
40382@@ -2007,16 +2007,16 @@ void locks_remove_flock(struct file *fil
40383 return;
40384
40385 if (filp->f_op && filp->f_op->flock) {
40386- struct file_lock fl = {
40387+ struct file_lock flock = {
40388 .fl_pid = current->tgid,
40389 .fl_file = filp,
40390 .fl_flags = FL_FLOCK,
40391 .fl_type = F_UNLCK,
40392 .fl_end = OFFSET_MAX,
40393 };
40394- filp->f_op->flock(filp, F_SETLKW, &fl);
40395- if (fl.fl_ops && fl.fl_ops->fl_release_private)
40396- fl.fl_ops->fl_release_private(&fl);
40397+ filp->f_op->flock(filp, F_SETLKW, &flock);
40398+ if (flock.fl_ops && flock.fl_ops->fl_release_private)
40399+ flock.fl_ops->fl_release_private(&flock);
40400 }
40401
40402 lock_kernel();
40403diff -urNp linux-2.6.32.41/fs/namei.c linux-2.6.32.41/fs/namei.c
40404--- linux-2.6.32.41/fs/namei.c 2011-03-27 14:31:47.000000000 -0400
40405+++ linux-2.6.32.41/fs/namei.c 2011-05-16 21:46:57.000000000 -0400
40406@@ -224,14 +224,6 @@ int generic_permission(struct inode *ino
40407 return ret;
40408
40409 /*
40410- * Read/write DACs are always overridable.
40411- * Executable DACs are overridable if at least one exec bit is set.
40412- */
40413- if (!(mask & MAY_EXEC) || execute_ok(inode))
40414- if (capable(CAP_DAC_OVERRIDE))
40415- return 0;
40416-
40417- /*
40418 * Searching includes executable on directories, else just read.
40419 */
40420 mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
40421@@ -239,6 +231,14 @@ int generic_permission(struct inode *ino
40422 if (capable(CAP_DAC_READ_SEARCH))
40423 return 0;
40424
40425+ /*
40426+ * Read/write DACs are always overridable.
40427+ * Executable DACs are overridable if at least one exec bit is set.
40428+ */
40429+ if (!(mask & MAY_EXEC) || execute_ok(inode))
40430+ if (capable(CAP_DAC_OVERRIDE))
40431+ return 0;
40432+
40433 return -EACCES;
40434 }
40435
40436@@ -458,7 +458,8 @@ static int exec_permission_lite(struct i
40437 if (!ret)
40438 goto ok;
40439
40440- if (capable(CAP_DAC_OVERRIDE) || capable(CAP_DAC_READ_SEARCH))
40441+ if (capable_nolog(CAP_DAC_OVERRIDE) || capable(CAP_DAC_READ_SEARCH) ||
40442+ capable(CAP_DAC_OVERRIDE))
40443 goto ok;
40444
40445 return ret;
40446@@ -638,7 +639,7 @@ static __always_inline int __do_follow_l
40447 cookie = dentry->d_inode->i_op->follow_link(dentry, nd);
40448 error = PTR_ERR(cookie);
40449 if (!IS_ERR(cookie)) {
40450- char *s = nd_get_link(nd);
40451+ const char *s = nd_get_link(nd);
40452 error = 0;
40453 if (s)
40454 error = __vfs_follow_link(nd, s);
40455@@ -669,6 +670,13 @@ static inline int do_follow_link(struct
40456 err = security_inode_follow_link(path->dentry, nd);
40457 if (err)
40458 goto loop;
40459+
40460+ if (gr_handle_follow_link(path->dentry->d_parent->d_inode,
40461+ path->dentry->d_inode, path->dentry, nd->path.mnt)) {
40462+ err = -EACCES;
40463+ goto loop;
40464+ }
40465+
40466 current->link_count++;
40467 current->total_link_count++;
40468 nd->depth++;
40469@@ -1016,11 +1024,18 @@ return_reval:
40470 break;
40471 }
40472 return_base:
40473+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
40474+ path_put(&nd->path);
40475+ return -ENOENT;
40476+ }
40477 return 0;
40478 out_dput:
40479 path_put_conditional(&next, nd);
40480 break;
40481 }
40482+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt))
40483+ err = -ENOENT;
40484+
40485 path_put(&nd->path);
40486 return_err:
40487 return err;
40488@@ -1091,13 +1106,20 @@ static int do_path_lookup(int dfd, const
40489 int retval = path_init(dfd, name, flags, nd);
40490 if (!retval)
40491 retval = path_walk(name, nd);
40492- if (unlikely(!retval && !audit_dummy_context() && nd->path.dentry &&
40493- nd->path.dentry->d_inode))
40494- audit_inode(name, nd->path.dentry);
40495+
40496+ if (likely(!retval)) {
40497+ if (nd->path.dentry && nd->path.dentry->d_inode) {
40498+ if (*name != '/' && !gr_chroot_fchdir(nd->path.dentry, nd->path.mnt))
40499+ retval = -ENOENT;
40500+ if (!audit_dummy_context())
40501+ audit_inode(name, nd->path.dentry);
40502+ }
40503+ }
40504 if (nd->root.mnt) {
40505 path_put(&nd->root);
40506 nd->root.mnt = NULL;
40507 }
40508+
40509 return retval;
40510 }
40511
40512@@ -1576,6 +1598,20 @@ int may_open(struct path *path, int acc_
40513 if (error)
40514 goto err_out;
40515
40516+
40517+ if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode)) {
40518+ error = -EPERM;
40519+ goto err_out;
40520+ }
40521+ if (gr_handle_rawio(inode)) {
40522+ error = -EPERM;
40523+ goto err_out;
40524+ }
40525+ if (!gr_acl_handle_open(dentry, path->mnt, flag)) {
40526+ error = -EACCES;
40527+ goto err_out;
40528+ }
40529+
40530 if (flag & O_TRUNC) {
40531 error = get_write_access(inode);
40532 if (error)
40533@@ -1621,12 +1657,19 @@ static int __open_namei_create(struct na
40534 int error;
40535 struct dentry *dir = nd->path.dentry;
40536
40537+ if (!gr_acl_handle_creat(path->dentry, nd->path.dentry, nd->path.mnt, flag, mode)) {
40538+ error = -EACCES;
40539+ goto out_unlock;
40540+ }
40541+
40542 if (!IS_POSIXACL(dir->d_inode))
40543 mode &= ~current_umask();
40544 error = security_path_mknod(&nd->path, path->dentry, mode, 0);
40545 if (error)
40546 goto out_unlock;
40547 error = vfs_create(dir->d_inode, path->dentry, mode, nd);
40548+ if (!error)
40549+ gr_handle_create(path->dentry, nd->path.mnt);
40550 out_unlock:
40551 mutex_unlock(&dir->d_inode->i_mutex);
40552 dput(nd->path.dentry);
40553@@ -1709,6 +1752,22 @@ struct file *do_filp_open(int dfd, const
40554 &nd, flag);
40555 if (error)
40556 return ERR_PTR(error);
40557+
40558+ if (gr_handle_rofs_blockwrite(nd.path.dentry, nd.path.mnt, acc_mode)) {
40559+ error = -EPERM;
40560+ goto exit;
40561+ }
40562+
40563+ if (gr_handle_rawio(nd.path.dentry->d_inode)) {
40564+ error = -EPERM;
40565+ goto exit;
40566+ }
40567+
40568+ if (!gr_acl_handle_open(nd.path.dentry, nd.path.mnt, flag)) {
40569+ error = -EACCES;
40570+ goto exit;
40571+ }
40572+
40573 goto ok;
40574 }
40575
40576@@ -1795,6 +1854,14 @@ do_last:
40577 /*
40578 * It already exists.
40579 */
40580+
40581+ /* only check if O_CREAT is specified, all other checks need
40582+ to go into may_open */
40583+ if (gr_handle_fifo(path.dentry, path.mnt, dir, flag, acc_mode)) {
40584+ error = -EACCES;
40585+ goto exit_mutex_unlock;
40586+ }
40587+
40588 mutex_unlock(&dir->d_inode->i_mutex);
40589 audit_inode(pathname, path.dentry);
40590
40591@@ -1887,6 +1954,13 @@ do_link:
40592 error = security_inode_follow_link(path.dentry, &nd);
40593 if (error)
40594 goto exit_dput;
40595+
40596+ if (gr_handle_follow_link(path.dentry->d_parent->d_inode, path.dentry->d_inode,
40597+ path.dentry, nd.path.mnt)) {
40598+ error = -EACCES;
40599+ goto exit_dput;
40600+ }
40601+
40602 error = __do_follow_link(&path, &nd);
40603 if (error) {
40604 /* Does someone understand code flow here? Or it is only
40605@@ -2061,6 +2135,17 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const
40606 error = may_mknod(mode);
40607 if (error)
40608 goto out_dput;
40609+
40610+ if (gr_handle_chroot_mknod(dentry, nd.path.mnt, mode)) {
40611+ error = -EPERM;
40612+ goto out_dput;
40613+ }
40614+
40615+ if (!gr_acl_handle_mknod(dentry, nd.path.dentry, nd.path.mnt, mode)) {
40616+ error = -EACCES;
40617+ goto out_dput;
40618+ }
40619+
40620 error = mnt_want_write(nd.path.mnt);
40621 if (error)
40622 goto out_dput;
40623@@ -2081,6 +2166,9 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const
40624 }
40625 out_drop_write:
40626 mnt_drop_write(nd.path.mnt);
40627+
40628+ if (!error)
40629+ gr_handle_create(dentry, nd.path.mnt);
40630 out_dput:
40631 dput(dentry);
40632 out_unlock:
40633@@ -2134,6 +2222,11 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const
40634 if (IS_ERR(dentry))
40635 goto out_unlock;
40636
40637+ if (!gr_acl_handle_mkdir(dentry, nd.path.dentry, nd.path.mnt)) {
40638+ error = -EACCES;
40639+ goto out_dput;
40640+ }
40641+
40642 if (!IS_POSIXACL(nd.path.dentry->d_inode))
40643 mode &= ~current_umask();
40644 error = mnt_want_write(nd.path.mnt);
40645@@ -2145,6 +2238,10 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const
40646 error = vfs_mkdir(nd.path.dentry->d_inode, dentry, mode);
40647 out_drop_write:
40648 mnt_drop_write(nd.path.mnt);
40649+
40650+ if (!error)
40651+ gr_handle_create(dentry, nd.path.mnt);
40652+
40653 out_dput:
40654 dput(dentry);
40655 out_unlock:
40656@@ -2226,6 +2323,8 @@ static long do_rmdir(int dfd, const char
40657 char * name;
40658 struct dentry *dentry;
40659 struct nameidata nd;
40660+ ino_t saved_ino = 0;
40661+ dev_t saved_dev = 0;
40662
40663 error = user_path_parent(dfd, pathname, &nd, &name);
40664 if (error)
40665@@ -2250,6 +2349,19 @@ static long do_rmdir(int dfd, const char
40666 error = PTR_ERR(dentry);
40667 if (IS_ERR(dentry))
40668 goto exit2;
40669+
40670+ if (dentry->d_inode != NULL) {
40671+ if (dentry->d_inode->i_nlink <= 1) {
40672+ saved_ino = dentry->d_inode->i_ino;
40673+ saved_dev = gr_get_dev_from_dentry(dentry);
40674+ }
40675+
40676+ if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
40677+ error = -EACCES;
40678+ goto exit3;
40679+ }
40680+ }
40681+
40682 error = mnt_want_write(nd.path.mnt);
40683 if (error)
40684 goto exit3;
40685@@ -2257,6 +2369,8 @@ static long do_rmdir(int dfd, const char
40686 if (error)
40687 goto exit4;
40688 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
40689+ if (!error && (saved_dev || saved_ino))
40690+ gr_handle_delete(saved_ino, saved_dev);
40691 exit4:
40692 mnt_drop_write(nd.path.mnt);
40693 exit3:
40694@@ -2318,6 +2432,8 @@ static long do_unlinkat(int dfd, const c
40695 struct dentry *dentry;
40696 struct nameidata nd;
40697 struct inode *inode = NULL;
40698+ ino_t saved_ino = 0;
40699+ dev_t saved_dev = 0;
40700
40701 error = user_path_parent(dfd, pathname, &nd, &name);
40702 if (error)
40703@@ -2337,8 +2453,19 @@ static long do_unlinkat(int dfd, const c
40704 if (nd.last.name[nd.last.len])
40705 goto slashes;
40706 inode = dentry->d_inode;
40707- if (inode)
40708+ if (inode) {
40709+ if (inode->i_nlink <= 1) {
40710+ saved_ino = inode->i_ino;
40711+ saved_dev = gr_get_dev_from_dentry(dentry);
40712+ }
40713+
40714 atomic_inc(&inode->i_count);
40715+
40716+ if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
40717+ error = -EACCES;
40718+ goto exit2;
40719+ }
40720+ }
40721 error = mnt_want_write(nd.path.mnt);
40722 if (error)
40723 goto exit2;
40724@@ -2346,6 +2473,8 @@ static long do_unlinkat(int dfd, const c
40725 if (error)
40726 goto exit3;
40727 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
40728+ if (!error && (saved_ino || saved_dev))
40729+ gr_handle_delete(saved_ino, saved_dev);
40730 exit3:
40731 mnt_drop_write(nd.path.mnt);
40732 exit2:
40733@@ -2424,6 +2553,11 @@ SYSCALL_DEFINE3(symlinkat, const char __
40734 if (IS_ERR(dentry))
40735 goto out_unlock;
40736
40737+ if (!gr_acl_handle_symlink(dentry, nd.path.dentry, nd.path.mnt, from)) {
40738+ error = -EACCES;
40739+ goto out_dput;
40740+ }
40741+
40742 error = mnt_want_write(nd.path.mnt);
40743 if (error)
40744 goto out_dput;
40745@@ -2431,6 +2565,8 @@ SYSCALL_DEFINE3(symlinkat, const char __
40746 if (error)
40747 goto out_drop_write;
40748 error = vfs_symlink(nd.path.dentry->d_inode, dentry, from);
40749+ if (!error)
40750+ gr_handle_create(dentry, nd.path.mnt);
40751 out_drop_write:
40752 mnt_drop_write(nd.path.mnt);
40753 out_dput:
40754@@ -2524,6 +2660,20 @@ SYSCALL_DEFINE5(linkat, int, olddfd, con
40755 error = PTR_ERR(new_dentry);
40756 if (IS_ERR(new_dentry))
40757 goto out_unlock;
40758+
40759+ if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
40760+ old_path.dentry->d_inode,
40761+ old_path.dentry->d_inode->i_mode, to)) {
40762+ error = -EACCES;
40763+ goto out_dput;
40764+ }
40765+
40766+ if (!gr_acl_handle_link(new_dentry, nd.path.dentry, nd.path.mnt,
40767+ old_path.dentry, old_path.mnt, to)) {
40768+ error = -EACCES;
40769+ goto out_dput;
40770+ }
40771+
40772 error = mnt_want_write(nd.path.mnt);
40773 if (error)
40774 goto out_dput;
40775@@ -2531,6 +2681,8 @@ SYSCALL_DEFINE5(linkat, int, olddfd, con
40776 if (error)
40777 goto out_drop_write;
40778 error = vfs_link(old_path.dentry, nd.path.dentry->d_inode, new_dentry);
40779+ if (!error)
40780+ gr_handle_create(new_dentry, nd.path.mnt);
40781 out_drop_write:
40782 mnt_drop_write(nd.path.mnt);
40783 out_dput:
40784@@ -2708,6 +2860,8 @@ SYSCALL_DEFINE4(renameat, int, olddfd, c
40785 char *to;
40786 int error;
40787
40788+ pax_track_stack();
40789+
40790 error = user_path_parent(olddfd, oldname, &oldnd, &from);
40791 if (error)
40792 goto exit;
40793@@ -2764,6 +2918,12 @@ SYSCALL_DEFINE4(renameat, int, olddfd, c
40794 if (new_dentry == trap)
40795 goto exit5;
40796
40797+ error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
40798+ old_dentry, old_dir->d_inode, oldnd.path.mnt,
40799+ to);
40800+ if (error)
40801+ goto exit5;
40802+
40803 error = mnt_want_write(oldnd.path.mnt);
40804 if (error)
40805 goto exit5;
40806@@ -2773,6 +2933,9 @@ SYSCALL_DEFINE4(renameat, int, olddfd, c
40807 goto exit6;
40808 error = vfs_rename(old_dir->d_inode, old_dentry,
40809 new_dir->d_inode, new_dentry);
40810+ if (!error)
40811+ gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
40812+ new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
40813 exit6:
40814 mnt_drop_write(oldnd.path.mnt);
40815 exit5:
40816@@ -2798,6 +2961,8 @@ SYSCALL_DEFINE2(rename, const char __use
40817
40818 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
40819 {
40820+ char tmpbuf[64];
40821+ const char *newlink;
40822 int len;
40823
40824 len = PTR_ERR(link);
40825@@ -2807,7 +2972,14 @@ int vfs_readlink(struct dentry *dentry,
40826 len = strlen(link);
40827 if (len > (unsigned) buflen)
40828 len = buflen;
40829- if (copy_to_user(buffer, link, len))
40830+
40831+ if (len < sizeof(tmpbuf)) {
40832+ memcpy(tmpbuf, link, len);
40833+ newlink = tmpbuf;
40834+ } else
40835+ newlink = link;
40836+
40837+ if (copy_to_user(buffer, newlink, len))
40838 len = -EFAULT;
40839 out:
40840 return len;
40841diff -urNp linux-2.6.32.41/fs/namespace.c linux-2.6.32.41/fs/namespace.c
40842--- linux-2.6.32.41/fs/namespace.c 2011-03-27 14:31:47.000000000 -0400
40843+++ linux-2.6.32.41/fs/namespace.c 2011-04-17 15:56:46.000000000 -0400
40844@@ -1083,6 +1083,9 @@ static int do_umount(struct vfsmount *mn
40845 if (!(sb->s_flags & MS_RDONLY))
40846 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
40847 up_write(&sb->s_umount);
40848+
40849+ gr_log_remount(mnt->mnt_devname, retval);
40850+
40851 return retval;
40852 }
40853
40854@@ -1104,6 +1107,9 @@ static int do_umount(struct vfsmount *mn
40855 security_sb_umount_busy(mnt);
40856 up_write(&namespace_sem);
40857 release_mounts(&umount_list);
40858+
40859+ gr_log_unmount(mnt->mnt_devname, retval);
40860+
40861 return retval;
40862 }
40863
40864@@ -1962,6 +1968,16 @@ long do_mount(char *dev_name, char *dir_
40865 if (retval)
40866 goto dput_out;
40867
40868+ if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
40869+ retval = -EPERM;
40870+ goto dput_out;
40871+ }
40872+
40873+ if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
40874+ retval = -EPERM;
40875+ goto dput_out;
40876+ }
40877+
40878 if (flags & MS_REMOUNT)
40879 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
40880 data_page);
40881@@ -1976,6 +1992,9 @@ long do_mount(char *dev_name, char *dir_
40882 dev_name, data_page);
40883 dput_out:
40884 path_put(&path);
40885+
40886+ gr_log_mount(dev_name, dir_name, retval);
40887+
40888 return retval;
40889 }
40890
40891@@ -2182,6 +2201,12 @@ SYSCALL_DEFINE2(pivot_root, const char _
40892 goto out1;
40893 }
40894
40895+ if (gr_handle_chroot_pivot()) {
40896+ error = -EPERM;
40897+ path_put(&old);
40898+ goto out1;
40899+ }
40900+
40901 read_lock(&current->fs->lock);
40902 root = current->fs->root;
40903 path_get(&current->fs->root);
40904diff -urNp linux-2.6.32.41/fs/ncpfs/dir.c linux-2.6.32.41/fs/ncpfs/dir.c
40905--- linux-2.6.32.41/fs/ncpfs/dir.c 2011-03-27 14:31:47.000000000 -0400
40906+++ linux-2.6.32.41/fs/ncpfs/dir.c 2011-05-16 21:46:57.000000000 -0400
40907@@ -275,6 +275,8 @@ __ncp_lookup_validate(struct dentry *den
40908 int res, val = 0, len;
40909 __u8 __name[NCP_MAXPATHLEN + 1];
40910
40911+ pax_track_stack();
40912+
40913 parent = dget_parent(dentry);
40914 dir = parent->d_inode;
40915
40916@@ -799,6 +801,8 @@ static struct dentry *ncp_lookup(struct
40917 int error, res, len;
40918 __u8 __name[NCP_MAXPATHLEN + 1];
40919
40920+ pax_track_stack();
40921+
40922 lock_kernel();
40923 error = -EIO;
40924 if (!ncp_conn_valid(server))
40925@@ -883,10 +887,12 @@ int ncp_create_new(struct inode *dir, st
40926 int error, result, len;
40927 int opmode;
40928 __u8 __name[NCP_MAXPATHLEN + 1];
40929-
40930+
40931 PPRINTK("ncp_create_new: creating %s/%s, mode=%x\n",
40932 dentry->d_parent->d_name.name, dentry->d_name.name, mode);
40933
40934+ pax_track_stack();
40935+
40936 error = -EIO;
40937 lock_kernel();
40938 if (!ncp_conn_valid(server))
40939@@ -952,6 +958,8 @@ static int ncp_mkdir(struct inode *dir,
40940 int error, len;
40941 __u8 __name[NCP_MAXPATHLEN + 1];
40942
40943+ pax_track_stack();
40944+
40945 DPRINTK("ncp_mkdir: making %s/%s\n",
40946 dentry->d_parent->d_name.name, dentry->d_name.name);
40947
40948@@ -960,6 +968,8 @@ static int ncp_mkdir(struct inode *dir,
40949 if (!ncp_conn_valid(server))
40950 goto out;
40951
40952+ pax_track_stack();
40953+
40954 ncp_age_dentry(server, dentry);
40955 len = sizeof(__name);
40956 error = ncp_io2vol(server, __name, &len, dentry->d_name.name,
40957@@ -1114,6 +1124,8 @@ static int ncp_rename(struct inode *old_
40958 int old_len, new_len;
40959 __u8 __old_name[NCP_MAXPATHLEN + 1], __new_name[NCP_MAXPATHLEN + 1];
40960
40961+ pax_track_stack();
40962+
40963 DPRINTK("ncp_rename: %s/%s to %s/%s\n",
40964 old_dentry->d_parent->d_name.name, old_dentry->d_name.name,
40965 new_dentry->d_parent->d_name.name, new_dentry->d_name.name);
40966diff -urNp linux-2.6.32.41/fs/ncpfs/inode.c linux-2.6.32.41/fs/ncpfs/inode.c
40967--- linux-2.6.32.41/fs/ncpfs/inode.c 2011-03-27 14:31:47.000000000 -0400
40968+++ linux-2.6.32.41/fs/ncpfs/inode.c 2011-05-16 21:46:57.000000000 -0400
40969@@ -445,6 +445,8 @@ static int ncp_fill_super(struct super_b
40970 #endif
40971 struct ncp_entry_info finfo;
40972
40973+ pax_track_stack();
40974+
40975 data.wdog_pid = NULL;
40976 server = kzalloc(sizeof(struct ncp_server), GFP_KERNEL);
40977 if (!server)
40978diff -urNp linux-2.6.32.41/fs/nfs/inode.c linux-2.6.32.41/fs/nfs/inode.c
40979--- linux-2.6.32.41/fs/nfs/inode.c 2011-05-10 22:12:01.000000000 -0400
40980+++ linux-2.6.32.41/fs/nfs/inode.c 2011-05-10 22:12:33.000000000 -0400
40981@@ -973,16 +973,16 @@ static int nfs_size_need_update(const st
40982 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
40983 }
40984
40985-static atomic_long_t nfs_attr_generation_counter;
40986+static atomic_long_unchecked_t nfs_attr_generation_counter;
40987
40988 static unsigned long nfs_read_attr_generation_counter(void)
40989 {
40990- return atomic_long_read(&nfs_attr_generation_counter);
40991+ return atomic_long_read_unchecked(&nfs_attr_generation_counter);
40992 }
40993
40994 unsigned long nfs_inc_attr_generation_counter(void)
40995 {
40996- return atomic_long_inc_return(&nfs_attr_generation_counter);
40997+ return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
40998 }
40999
41000 void nfs_fattr_init(struct nfs_fattr *fattr)
41001diff -urNp linux-2.6.32.41/fs/nfsd/lockd.c linux-2.6.32.41/fs/nfsd/lockd.c
41002--- linux-2.6.32.41/fs/nfsd/lockd.c 2011-04-17 17:00:52.000000000 -0400
41003+++ linux-2.6.32.41/fs/nfsd/lockd.c 2011-04-17 17:03:15.000000000 -0400
41004@@ -66,7 +66,7 @@ nlm_fclose(struct file *filp)
41005 fput(filp);
41006 }
41007
41008-static struct nlmsvc_binding nfsd_nlm_ops = {
41009+static const struct nlmsvc_binding nfsd_nlm_ops = {
41010 .fopen = nlm_fopen, /* open file for locking */
41011 .fclose = nlm_fclose, /* close file */
41012 };
41013diff -urNp linux-2.6.32.41/fs/nfsd/nfs4state.c linux-2.6.32.41/fs/nfsd/nfs4state.c
41014--- linux-2.6.32.41/fs/nfsd/nfs4state.c 2011-03-27 14:31:47.000000000 -0400
41015+++ linux-2.6.32.41/fs/nfsd/nfs4state.c 2011-05-16 21:46:57.000000000 -0400
41016@@ -3457,6 +3457,8 @@ nfsd4_lock(struct svc_rqst *rqstp, struc
41017 unsigned int cmd;
41018 int err;
41019
41020+ pax_track_stack();
41021+
41022 dprintk("NFSD: nfsd4_lock: start=%Ld length=%Ld\n",
41023 (long long) lock->lk_offset,
41024 (long long) lock->lk_length);
41025diff -urNp linux-2.6.32.41/fs/nfsd/nfs4xdr.c linux-2.6.32.41/fs/nfsd/nfs4xdr.c
41026--- linux-2.6.32.41/fs/nfsd/nfs4xdr.c 2011-03-27 14:31:47.000000000 -0400
41027+++ linux-2.6.32.41/fs/nfsd/nfs4xdr.c 2011-05-16 21:46:57.000000000 -0400
41028@@ -1751,6 +1751,8 @@ nfsd4_encode_fattr(struct svc_fh *fhp, s
41029 struct nfsd4_compoundres *resp = rqstp->rq_resp;
41030 u32 minorversion = resp->cstate.minorversion;
41031
41032+ pax_track_stack();
41033+
41034 BUG_ON(bmval1 & NFSD_WRITEONLY_ATTRS_WORD1);
41035 BUG_ON(bmval0 & ~nfsd_suppattrs0(minorversion));
41036 BUG_ON(bmval1 & ~nfsd_suppattrs1(minorversion));
41037diff -urNp linux-2.6.32.41/fs/nfsd/vfs.c linux-2.6.32.41/fs/nfsd/vfs.c
41038--- linux-2.6.32.41/fs/nfsd/vfs.c 2011-05-10 22:12:01.000000000 -0400
41039+++ linux-2.6.32.41/fs/nfsd/vfs.c 2011-05-10 22:12:33.000000000 -0400
41040@@ -937,7 +937,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, st
41041 } else {
41042 oldfs = get_fs();
41043 set_fs(KERNEL_DS);
41044- host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
41045+ host_err = vfs_readv(file, (__force struct iovec __user *)vec, vlen, &offset);
41046 set_fs(oldfs);
41047 }
41048
41049@@ -1060,7 +1060,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, s
41050
41051 /* Write the data. */
41052 oldfs = get_fs(); set_fs(KERNEL_DS);
41053- host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &offset);
41054+ host_err = vfs_writev(file, (__force struct iovec __user *)vec, vlen, &offset);
41055 set_fs(oldfs);
41056 if (host_err < 0)
41057 goto out_nfserr;
41058@@ -1542,7 +1542,7 @@ nfsd_readlink(struct svc_rqst *rqstp, st
41059 */
41060
41061 oldfs = get_fs(); set_fs(KERNEL_DS);
41062- host_err = inode->i_op->readlink(dentry, buf, *lenp);
41063+ host_err = inode->i_op->readlink(dentry, (__force char __user *)buf, *lenp);
41064 set_fs(oldfs);
41065
41066 if (host_err < 0)
41067diff -urNp linux-2.6.32.41/fs/nilfs2/ioctl.c linux-2.6.32.41/fs/nilfs2/ioctl.c
41068--- linux-2.6.32.41/fs/nilfs2/ioctl.c 2011-03-27 14:31:47.000000000 -0400
41069+++ linux-2.6.32.41/fs/nilfs2/ioctl.c 2011-05-04 17:56:28.000000000 -0400
41070@@ -480,7 +480,7 @@ static int nilfs_ioctl_clean_segments(st
41071 unsigned int cmd, void __user *argp)
41072 {
41073 struct nilfs_argv argv[5];
41074- const static size_t argsz[5] = {
41075+ static const size_t argsz[5] = {
41076 sizeof(struct nilfs_vdesc),
41077 sizeof(struct nilfs_period),
41078 sizeof(__u64),
41079diff -urNp linux-2.6.32.41/fs/notify/dnotify/dnotify.c linux-2.6.32.41/fs/notify/dnotify/dnotify.c
41080--- linux-2.6.32.41/fs/notify/dnotify/dnotify.c 2011-03-27 14:31:47.000000000 -0400
41081+++ linux-2.6.32.41/fs/notify/dnotify/dnotify.c 2011-04-17 15:56:46.000000000 -0400
41082@@ -173,7 +173,7 @@ static void dnotify_free_mark(struct fsn
41083 kmem_cache_free(dnotify_mark_entry_cache, dnentry);
41084 }
41085
41086-static struct fsnotify_ops dnotify_fsnotify_ops = {
41087+static const struct fsnotify_ops dnotify_fsnotify_ops = {
41088 .handle_event = dnotify_handle_event,
41089 .should_send_event = dnotify_should_send_event,
41090 .free_group_priv = NULL,
41091diff -urNp linux-2.6.32.41/fs/notify/notification.c linux-2.6.32.41/fs/notify/notification.c
41092--- linux-2.6.32.41/fs/notify/notification.c 2011-03-27 14:31:47.000000000 -0400
41093+++ linux-2.6.32.41/fs/notify/notification.c 2011-05-04 17:56:28.000000000 -0400
41094@@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event
41095 * get set to 0 so it will never get 'freed'
41096 */
41097 static struct fsnotify_event q_overflow_event;
41098-static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
41099+static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
41100
41101 /**
41102 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
41103@@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = A
41104 */
41105 u32 fsnotify_get_cookie(void)
41106 {
41107- return atomic_inc_return(&fsnotify_sync_cookie);
41108+ return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
41109 }
41110 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
41111
41112diff -urNp linux-2.6.32.41/fs/ntfs/dir.c linux-2.6.32.41/fs/ntfs/dir.c
41113--- linux-2.6.32.41/fs/ntfs/dir.c 2011-03-27 14:31:47.000000000 -0400
41114+++ linux-2.6.32.41/fs/ntfs/dir.c 2011-04-17 15:56:46.000000000 -0400
41115@@ -1328,7 +1328,7 @@ find_next_index_buffer:
41116 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
41117 ~(s64)(ndir->itype.index.block_size - 1)));
41118 /* Bounds checks. */
41119- if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
41120+ if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
41121 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
41122 "inode 0x%lx or driver bug.", vdir->i_ino);
41123 goto err_out;
41124diff -urNp linux-2.6.32.41/fs/ntfs/file.c linux-2.6.32.41/fs/ntfs/file.c
41125--- linux-2.6.32.41/fs/ntfs/file.c 2011-03-27 14:31:47.000000000 -0400
41126+++ linux-2.6.32.41/fs/ntfs/file.c 2011-04-17 15:56:46.000000000 -0400
41127@@ -2243,6 +2243,6 @@ const struct inode_operations ntfs_file_
41128 #endif /* NTFS_RW */
41129 };
41130
41131-const struct file_operations ntfs_empty_file_ops = {};
41132+const struct file_operations ntfs_empty_file_ops __read_only;
41133
41134-const struct inode_operations ntfs_empty_inode_ops = {};
41135+const struct inode_operations ntfs_empty_inode_ops __read_only;
41136diff -urNp linux-2.6.32.41/fs/ocfs2/cluster/masklog.c linux-2.6.32.41/fs/ocfs2/cluster/masklog.c
41137--- linux-2.6.32.41/fs/ocfs2/cluster/masklog.c 2011-03-27 14:31:47.000000000 -0400
41138+++ linux-2.6.32.41/fs/ocfs2/cluster/masklog.c 2011-04-17 15:56:46.000000000 -0400
41139@@ -135,7 +135,7 @@ static ssize_t mlog_store(struct kobject
41140 return mlog_mask_store(mlog_attr->mask, buf, count);
41141 }
41142
41143-static struct sysfs_ops mlog_attr_ops = {
41144+static const struct sysfs_ops mlog_attr_ops = {
41145 .show = mlog_show,
41146 .store = mlog_store,
41147 };
41148diff -urNp linux-2.6.32.41/fs/ocfs2/localalloc.c linux-2.6.32.41/fs/ocfs2/localalloc.c
41149--- linux-2.6.32.41/fs/ocfs2/localalloc.c 2011-03-27 14:31:47.000000000 -0400
41150+++ linux-2.6.32.41/fs/ocfs2/localalloc.c 2011-04-17 15:56:46.000000000 -0400
41151@@ -1188,7 +1188,7 @@ static int ocfs2_local_alloc_slide_windo
41152 goto bail;
41153 }
41154
41155- atomic_inc(&osb->alloc_stats.moves);
41156+ atomic_inc_unchecked(&osb->alloc_stats.moves);
41157
41158 status = 0;
41159 bail:
41160diff -urNp linux-2.6.32.41/fs/ocfs2/namei.c linux-2.6.32.41/fs/ocfs2/namei.c
41161--- linux-2.6.32.41/fs/ocfs2/namei.c 2011-03-27 14:31:47.000000000 -0400
41162+++ linux-2.6.32.41/fs/ocfs2/namei.c 2011-05-16 21:46:57.000000000 -0400
41163@@ -1043,6 +1043,8 @@ static int ocfs2_rename(struct inode *ol
41164 struct ocfs2_dir_lookup_result orphan_insert = { NULL, };
41165 struct ocfs2_dir_lookup_result target_insert = { NULL, };
41166
41167+ pax_track_stack();
41168+
41169 /* At some point it might be nice to break this function up a
41170 * bit. */
41171
41172diff -urNp linux-2.6.32.41/fs/ocfs2/ocfs2.h linux-2.6.32.41/fs/ocfs2/ocfs2.h
41173--- linux-2.6.32.41/fs/ocfs2/ocfs2.h 2011-03-27 14:31:47.000000000 -0400
41174+++ linux-2.6.32.41/fs/ocfs2/ocfs2.h 2011-04-17 15:56:46.000000000 -0400
41175@@ -217,11 +217,11 @@ enum ocfs2_vol_state
41176
41177 struct ocfs2_alloc_stats
41178 {
41179- atomic_t moves;
41180- atomic_t local_data;
41181- atomic_t bitmap_data;
41182- atomic_t bg_allocs;
41183- atomic_t bg_extends;
41184+ atomic_unchecked_t moves;
41185+ atomic_unchecked_t local_data;
41186+ atomic_unchecked_t bitmap_data;
41187+ atomic_unchecked_t bg_allocs;
41188+ atomic_unchecked_t bg_extends;
41189 };
41190
41191 enum ocfs2_local_alloc_state
41192diff -urNp linux-2.6.32.41/fs/ocfs2/suballoc.c linux-2.6.32.41/fs/ocfs2/suballoc.c
41193--- linux-2.6.32.41/fs/ocfs2/suballoc.c 2011-03-27 14:31:47.000000000 -0400
41194+++ linux-2.6.32.41/fs/ocfs2/suballoc.c 2011-04-17 15:56:46.000000000 -0400
41195@@ -623,7 +623,7 @@ static int ocfs2_reserve_suballoc_bits(s
41196 mlog_errno(status);
41197 goto bail;
41198 }
41199- atomic_inc(&osb->alloc_stats.bg_extends);
41200+ atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
41201
41202 /* You should never ask for this much metadata */
41203 BUG_ON(bits_wanted >
41204@@ -1654,7 +1654,7 @@ int ocfs2_claim_metadata(struct ocfs2_su
41205 mlog_errno(status);
41206 goto bail;
41207 }
41208- atomic_inc(&osb->alloc_stats.bg_allocs);
41209+ atomic_inc_unchecked(&osb->alloc_stats.bg_allocs);
41210
41211 *blkno_start = bg_blkno + (u64) *suballoc_bit_start;
41212 ac->ac_bits_given += (*num_bits);
41213@@ -1728,7 +1728,7 @@ int ocfs2_claim_new_inode(struct ocfs2_s
41214 mlog_errno(status);
41215 goto bail;
41216 }
41217- atomic_inc(&osb->alloc_stats.bg_allocs);
41218+ atomic_inc_unchecked(&osb->alloc_stats.bg_allocs);
41219
41220 BUG_ON(num_bits != 1);
41221
41222@@ -1830,7 +1830,7 @@ int __ocfs2_claim_clusters(struct ocfs2_
41223 cluster_start,
41224 num_clusters);
41225 if (!status)
41226- atomic_inc(&osb->alloc_stats.local_data);
41227+ atomic_inc_unchecked(&osb->alloc_stats.local_data);
41228 } else {
41229 if (min_clusters > (osb->bitmap_cpg - 1)) {
41230 /* The only paths asking for contiguousness
41231@@ -1858,7 +1858,7 @@ int __ocfs2_claim_clusters(struct ocfs2_
41232 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
41233 bg_blkno,
41234 bg_bit_off);
41235- atomic_inc(&osb->alloc_stats.bitmap_data);
41236+ atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
41237 }
41238 }
41239 if (status < 0) {
41240diff -urNp linux-2.6.32.41/fs/ocfs2/super.c linux-2.6.32.41/fs/ocfs2/super.c
41241--- linux-2.6.32.41/fs/ocfs2/super.c 2011-03-27 14:31:47.000000000 -0400
41242+++ linux-2.6.32.41/fs/ocfs2/super.c 2011-04-17 15:56:46.000000000 -0400
41243@@ -284,11 +284,11 @@ static int ocfs2_osb_dump(struct ocfs2_s
41244 "%10s => GlobalAllocs: %d LocalAllocs: %d "
41245 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
41246 "Stats",
41247- atomic_read(&osb->alloc_stats.bitmap_data),
41248- atomic_read(&osb->alloc_stats.local_data),
41249- atomic_read(&osb->alloc_stats.bg_allocs),
41250- atomic_read(&osb->alloc_stats.moves),
41251- atomic_read(&osb->alloc_stats.bg_extends));
41252+ atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
41253+ atomic_read_unchecked(&osb->alloc_stats.local_data),
41254+ atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
41255+ atomic_read_unchecked(&osb->alloc_stats.moves),
41256+ atomic_read_unchecked(&osb->alloc_stats.bg_extends));
41257
41258 out += snprintf(buf + out, len - out,
41259 "%10s => State: %u Descriptor: %llu Size: %u bits "
41260@@ -2002,11 +2002,11 @@ static int ocfs2_initialize_super(struct
41261 spin_lock_init(&osb->osb_xattr_lock);
41262 ocfs2_init_inode_steal_slot(osb);
41263
41264- atomic_set(&osb->alloc_stats.moves, 0);
41265- atomic_set(&osb->alloc_stats.local_data, 0);
41266- atomic_set(&osb->alloc_stats.bitmap_data, 0);
41267- atomic_set(&osb->alloc_stats.bg_allocs, 0);
41268- atomic_set(&osb->alloc_stats.bg_extends, 0);
41269+ atomic_set_unchecked(&osb->alloc_stats.moves, 0);
41270+ atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
41271+ atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
41272+ atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
41273+ atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
41274
41275 /* Copy the blockcheck stats from the superblock probe */
41276 osb->osb_ecc_stats = *stats;
41277diff -urNp linux-2.6.32.41/fs/open.c linux-2.6.32.41/fs/open.c
41278--- linux-2.6.32.41/fs/open.c 2011-03-27 14:31:47.000000000 -0400
41279+++ linux-2.6.32.41/fs/open.c 2011-04-17 15:56:46.000000000 -0400
41280@@ -275,6 +275,10 @@ static long do_sys_truncate(const char _
41281 error = locks_verify_truncate(inode, NULL, length);
41282 if (!error)
41283 error = security_path_truncate(&path, length, 0);
41284+
41285+ if (!error && !gr_acl_handle_truncate(path.dentry, path.mnt))
41286+ error = -EACCES;
41287+
41288 if (!error) {
41289 vfs_dq_init(inode);
41290 error = do_truncate(path.dentry, length, 0, NULL);
41291@@ -511,6 +515,9 @@ SYSCALL_DEFINE3(faccessat, int, dfd, con
41292 if (__mnt_is_readonly(path.mnt))
41293 res = -EROFS;
41294
41295+ if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
41296+ res = -EACCES;
41297+
41298 out_path_release:
41299 path_put(&path);
41300 out:
41301@@ -537,6 +544,8 @@ SYSCALL_DEFINE1(chdir, const char __user
41302 if (error)
41303 goto dput_and_out;
41304
41305+ gr_log_chdir(path.dentry, path.mnt);
41306+
41307 set_fs_pwd(current->fs, &path);
41308
41309 dput_and_out:
41310@@ -563,6 +572,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd
41311 goto out_putf;
41312
41313 error = inode_permission(inode, MAY_EXEC | MAY_ACCESS);
41314+
41315+ if (!error && !gr_chroot_fchdir(file->f_path.dentry, file->f_path.mnt))
41316+ error = -EPERM;
41317+
41318+ if (!error)
41319+ gr_log_chdir(file->f_path.dentry, file->f_path.mnt);
41320+
41321 if (!error)
41322 set_fs_pwd(current->fs, &file->f_path);
41323 out_putf:
41324@@ -588,7 +604,18 @@ SYSCALL_DEFINE1(chroot, const char __use
41325 if (!capable(CAP_SYS_CHROOT))
41326 goto dput_and_out;
41327
41328+ if (gr_handle_chroot_chroot(path.dentry, path.mnt))
41329+ goto dput_and_out;
41330+
41331+ if (gr_handle_chroot_caps(&path)) {
41332+ error = -ENOMEM;
41333+ goto dput_and_out;
41334+ }
41335+
41336 set_fs_root(current->fs, &path);
41337+
41338+ gr_handle_chroot_chdir(&path);
41339+
41340 error = 0;
41341 dput_and_out:
41342 path_put(&path);
41343@@ -616,12 +643,27 @@ SYSCALL_DEFINE2(fchmod, unsigned int, fd
41344 err = mnt_want_write_file(file);
41345 if (err)
41346 goto out_putf;
41347+
41348 mutex_lock(&inode->i_mutex);
41349+
41350+ if (!gr_acl_handle_fchmod(dentry, file->f_path.mnt, mode)) {
41351+ err = -EACCES;
41352+ goto out_unlock;
41353+ }
41354+
41355 if (mode == (mode_t) -1)
41356 mode = inode->i_mode;
41357+
41358+ if (gr_handle_chroot_chmod(dentry, file->f_path.mnt, mode)) {
41359+ err = -EPERM;
41360+ goto out_unlock;
41361+ }
41362+
41363 newattrs.ia_mode = (mode & S_IALLUGO) | (inode->i_mode & ~S_IALLUGO);
41364 newattrs.ia_valid = ATTR_MODE | ATTR_CTIME;
41365 err = notify_change(dentry, &newattrs);
41366+
41367+out_unlock:
41368 mutex_unlock(&inode->i_mutex);
41369 mnt_drop_write(file->f_path.mnt);
41370 out_putf:
41371@@ -645,12 +687,27 @@ SYSCALL_DEFINE3(fchmodat, int, dfd, cons
41372 error = mnt_want_write(path.mnt);
41373 if (error)
41374 goto dput_and_out;
41375+
41376 mutex_lock(&inode->i_mutex);
41377+
41378+ if (!gr_acl_handle_chmod(path.dentry, path.mnt, mode)) {
41379+ error = -EACCES;
41380+ goto out_unlock;
41381+ }
41382+
41383 if (mode == (mode_t) -1)
41384 mode = inode->i_mode;
41385+
41386+ if (gr_handle_chroot_chmod(path.dentry, path.mnt, mode)) {
41387+ error = -EACCES;
41388+ goto out_unlock;
41389+ }
41390+
41391 newattrs.ia_mode = (mode & S_IALLUGO) | (inode->i_mode & ~S_IALLUGO);
41392 newattrs.ia_valid = ATTR_MODE | ATTR_CTIME;
41393 error = notify_change(path.dentry, &newattrs);
41394+
41395+out_unlock:
41396 mutex_unlock(&inode->i_mutex);
41397 mnt_drop_write(path.mnt);
41398 dput_and_out:
41399@@ -664,12 +721,15 @@ SYSCALL_DEFINE2(chmod, const char __user
41400 return sys_fchmodat(AT_FDCWD, filename, mode);
41401 }
41402
41403-static int chown_common(struct dentry * dentry, uid_t user, gid_t group)
41404+static int chown_common(struct dentry * dentry, uid_t user, gid_t group, struct vfsmount *mnt)
41405 {
41406 struct inode *inode = dentry->d_inode;
41407 int error;
41408 struct iattr newattrs;
41409
41410+ if (!gr_acl_handle_chown(dentry, mnt))
41411+ return -EACCES;
41412+
41413 newattrs.ia_valid = ATTR_CTIME;
41414 if (user != (uid_t) -1) {
41415 newattrs.ia_valid |= ATTR_UID;
41416@@ -700,7 +760,7 @@ SYSCALL_DEFINE3(chown, const char __user
41417 error = mnt_want_write(path.mnt);
41418 if (error)
41419 goto out_release;
41420- error = chown_common(path.dentry, user, group);
41421+ error = chown_common(path.dentry, user, group, path.mnt);
41422 mnt_drop_write(path.mnt);
41423 out_release:
41424 path_put(&path);
41425@@ -725,7 +785,7 @@ SYSCALL_DEFINE5(fchownat, int, dfd, cons
41426 error = mnt_want_write(path.mnt);
41427 if (error)
41428 goto out_release;
41429- error = chown_common(path.dentry, user, group);
41430+ error = chown_common(path.dentry, user, group, path.mnt);
41431 mnt_drop_write(path.mnt);
41432 out_release:
41433 path_put(&path);
41434@@ -744,7 +804,7 @@ SYSCALL_DEFINE3(lchown, const char __use
41435 error = mnt_want_write(path.mnt);
41436 if (error)
41437 goto out_release;
41438- error = chown_common(path.dentry, user, group);
41439+ error = chown_common(path.dentry, user, group, path.mnt);
41440 mnt_drop_write(path.mnt);
41441 out_release:
41442 path_put(&path);
41443@@ -767,7 +827,7 @@ SYSCALL_DEFINE3(fchown, unsigned int, fd
41444 goto out_fput;
41445 dentry = file->f_path.dentry;
41446 audit_inode(NULL, dentry);
41447- error = chown_common(dentry, user, group);
41448+ error = chown_common(dentry, user, group, file->f_path.mnt);
41449 mnt_drop_write(file->f_path.mnt);
41450 out_fput:
41451 fput(file);
41452@@ -1036,7 +1096,10 @@ long do_sys_open(int dfd, const char __u
41453 if (!IS_ERR(tmp)) {
41454 fd = get_unused_fd_flags(flags);
41455 if (fd >= 0) {
41456- struct file *f = do_filp_open(dfd, tmp, flags, mode, 0);
41457+ struct file *f;
41458+ /* don't allow to be set by userland */
41459+ flags &= ~FMODE_GREXEC;
41460+ f = do_filp_open(dfd, tmp, flags, mode, 0);
41461 if (IS_ERR(f)) {
41462 put_unused_fd(fd);
41463 fd = PTR_ERR(f);
41464diff -urNp linux-2.6.32.41/fs/partitions/ldm.c linux-2.6.32.41/fs/partitions/ldm.c
41465--- linux-2.6.32.41/fs/partitions/ldm.c 2011-05-10 22:12:01.000000000 -0400
41466+++ linux-2.6.32.41/fs/partitions/ldm.c 2011-04-18 19:31:12.000000000 -0400
41467@@ -1311,6 +1311,7 @@ static bool ldm_frag_add (const u8 *data
41468 ldm_error ("A VBLK claims to have %d parts.", num);
41469 return false;
41470 }
41471+
41472 if (rec >= num) {
41473 ldm_error("REC value (%d) exceeds NUM value (%d)", rec, num);
41474 return false;
41475@@ -1322,7 +1323,7 @@ static bool ldm_frag_add (const u8 *data
41476 goto found;
41477 }
41478
41479- f = kmalloc (sizeof (*f) + size*num, GFP_KERNEL);
41480+ f = kmalloc (size*num + sizeof (*f), GFP_KERNEL);
41481 if (!f) {
41482 ldm_crit ("Out of memory.");
41483 return false;
41484diff -urNp linux-2.6.32.41/fs/partitions/mac.c linux-2.6.32.41/fs/partitions/mac.c
41485--- linux-2.6.32.41/fs/partitions/mac.c 2011-03-27 14:31:47.000000000 -0400
41486+++ linux-2.6.32.41/fs/partitions/mac.c 2011-04-17 15:56:46.000000000 -0400
41487@@ -59,11 +59,11 @@ int mac_partition(struct parsed_partitio
41488 return 0; /* not a MacOS disk */
41489 }
41490 blocks_in_map = be32_to_cpu(part->map_count);
41491+ printk(" [mac]");
41492 if (blocks_in_map < 0 || blocks_in_map >= DISK_MAX_PARTS) {
41493 put_dev_sector(sect);
41494 return 0;
41495 }
41496- printk(" [mac]");
41497 for (slot = 1; slot <= blocks_in_map; ++slot) {
41498 int pos = slot * secsize;
41499 put_dev_sector(sect);
41500diff -urNp linux-2.6.32.41/fs/pipe.c linux-2.6.32.41/fs/pipe.c
41501--- linux-2.6.32.41/fs/pipe.c 2011-03-27 14:31:47.000000000 -0400
41502+++ linux-2.6.32.41/fs/pipe.c 2011-04-23 13:37:17.000000000 -0400
41503@@ -401,9 +401,9 @@ redo:
41504 }
41505 if (bufs) /* More to do? */
41506 continue;
41507- if (!pipe->writers)
41508+ if (!atomic_read(&pipe->writers))
41509 break;
41510- if (!pipe->waiting_writers) {
41511+ if (!atomic_read(&pipe->waiting_writers)) {
41512 /* syscall merging: Usually we must not sleep
41513 * if O_NONBLOCK is set, or if we got some data.
41514 * But if a writer sleeps in kernel space, then
41515@@ -462,7 +462,7 @@ pipe_write(struct kiocb *iocb, const str
41516 mutex_lock(&inode->i_mutex);
41517 pipe = inode->i_pipe;
41518
41519- if (!pipe->readers) {
41520+ if (!atomic_read(&pipe->readers)) {
41521 send_sig(SIGPIPE, current, 0);
41522 ret = -EPIPE;
41523 goto out;
41524@@ -511,7 +511,7 @@ redo1:
41525 for (;;) {
41526 int bufs;
41527
41528- if (!pipe->readers) {
41529+ if (!atomic_read(&pipe->readers)) {
41530 send_sig(SIGPIPE, current, 0);
41531 if (!ret)
41532 ret = -EPIPE;
41533@@ -597,9 +597,9 @@ redo2:
41534 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
41535 do_wakeup = 0;
41536 }
41537- pipe->waiting_writers++;
41538+ atomic_inc(&pipe->waiting_writers);
41539 pipe_wait(pipe);
41540- pipe->waiting_writers--;
41541+ atomic_dec(&pipe->waiting_writers);
41542 }
41543 out:
41544 mutex_unlock(&inode->i_mutex);
41545@@ -666,7 +666,7 @@ pipe_poll(struct file *filp, poll_table
41546 mask = 0;
41547 if (filp->f_mode & FMODE_READ) {
41548 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
41549- if (!pipe->writers && filp->f_version != pipe->w_counter)
41550+ if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
41551 mask |= POLLHUP;
41552 }
41553
41554@@ -676,7 +676,7 @@ pipe_poll(struct file *filp, poll_table
41555 * Most Unices do not set POLLERR for FIFOs but on Linux they
41556 * behave exactly like pipes for poll().
41557 */
41558- if (!pipe->readers)
41559+ if (!atomic_read(&pipe->readers))
41560 mask |= POLLERR;
41561 }
41562
41563@@ -690,10 +690,10 @@ pipe_release(struct inode *inode, int de
41564
41565 mutex_lock(&inode->i_mutex);
41566 pipe = inode->i_pipe;
41567- pipe->readers -= decr;
41568- pipe->writers -= decw;
41569+ atomic_sub(decr, &pipe->readers);
41570+ atomic_sub(decw, &pipe->writers);
41571
41572- if (!pipe->readers && !pipe->writers) {
41573+ if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
41574 free_pipe_info(inode);
41575 } else {
41576 wake_up_interruptible_sync(&pipe->wait);
41577@@ -783,7 +783,7 @@ pipe_read_open(struct inode *inode, stru
41578
41579 if (inode->i_pipe) {
41580 ret = 0;
41581- inode->i_pipe->readers++;
41582+ atomic_inc(&inode->i_pipe->readers);
41583 }
41584
41585 mutex_unlock(&inode->i_mutex);
41586@@ -800,7 +800,7 @@ pipe_write_open(struct inode *inode, str
41587
41588 if (inode->i_pipe) {
41589 ret = 0;
41590- inode->i_pipe->writers++;
41591+ atomic_inc(&inode->i_pipe->writers);
41592 }
41593
41594 mutex_unlock(&inode->i_mutex);
41595@@ -818,9 +818,9 @@ pipe_rdwr_open(struct inode *inode, stru
41596 if (inode->i_pipe) {
41597 ret = 0;
41598 if (filp->f_mode & FMODE_READ)
41599- inode->i_pipe->readers++;
41600+ atomic_inc(&inode->i_pipe->readers);
41601 if (filp->f_mode & FMODE_WRITE)
41602- inode->i_pipe->writers++;
41603+ atomic_inc(&inode->i_pipe->writers);
41604 }
41605
41606 mutex_unlock(&inode->i_mutex);
41607@@ -905,7 +905,7 @@ void free_pipe_info(struct inode *inode)
41608 inode->i_pipe = NULL;
41609 }
41610
41611-static struct vfsmount *pipe_mnt __read_mostly;
41612+struct vfsmount *pipe_mnt __read_mostly;
41613 static int pipefs_delete_dentry(struct dentry *dentry)
41614 {
41615 /*
41616@@ -945,7 +945,8 @@ static struct inode * get_pipe_inode(voi
41617 goto fail_iput;
41618 inode->i_pipe = pipe;
41619
41620- pipe->readers = pipe->writers = 1;
41621+ atomic_set(&pipe->readers, 1);
41622+ atomic_set(&pipe->writers, 1);
41623 inode->i_fop = &rdwr_pipefifo_fops;
41624
41625 /*
41626diff -urNp linux-2.6.32.41/fs/proc/array.c linux-2.6.32.41/fs/proc/array.c
41627--- linux-2.6.32.41/fs/proc/array.c 2011-03-27 14:31:47.000000000 -0400
41628+++ linux-2.6.32.41/fs/proc/array.c 2011-05-16 21:46:57.000000000 -0400
41629@@ -60,6 +60,7 @@
41630 #include <linux/tty.h>
41631 #include <linux/string.h>
41632 #include <linux/mman.h>
41633+#include <linux/grsecurity.h>
41634 #include <linux/proc_fs.h>
41635 #include <linux/ioport.h>
41636 #include <linux/uaccess.h>
41637@@ -321,6 +322,21 @@ static inline void task_context_switch_c
41638 p->nivcsw);
41639 }
41640
41641+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
41642+static inline void task_pax(struct seq_file *m, struct task_struct *p)
41643+{
41644+ if (p->mm)
41645+ seq_printf(m, "PaX:\t%c%c%c%c%c\n",
41646+ p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
41647+ p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
41648+ p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
41649+ p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
41650+ p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
41651+ else
41652+ seq_printf(m, "PaX:\t-----\n");
41653+}
41654+#endif
41655+
41656 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
41657 struct pid *pid, struct task_struct *task)
41658 {
41659@@ -337,9 +353,24 @@ int proc_pid_status(struct seq_file *m,
41660 task_cap(m, task);
41661 cpuset_task_status_allowed(m, task);
41662 task_context_switch_counts(m, task);
41663+
41664+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
41665+ task_pax(m, task);
41666+#endif
41667+
41668+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
41669+ task_grsec_rbac(m, task);
41670+#endif
41671+
41672 return 0;
41673 }
41674
41675+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
41676+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
41677+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
41678+ _mm->pax_flags & MF_PAX_SEGMEXEC))
41679+#endif
41680+
41681 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
41682 struct pid *pid, struct task_struct *task, int whole)
41683 {
41684@@ -358,9 +389,11 @@ static int do_task_stat(struct seq_file
41685 cputime_t cutime, cstime, utime, stime;
41686 cputime_t cgtime, gtime;
41687 unsigned long rsslim = 0;
41688- char tcomm[sizeof(task->comm)];
41689+ char tcomm[sizeof(task->comm)] = { 0 };
41690 unsigned long flags;
41691
41692+ pax_track_stack();
41693+
41694 state = *get_task_state(task);
41695 vsize = eip = esp = 0;
41696 permitted = ptrace_may_access(task, PTRACE_MODE_READ);
41697@@ -433,6 +466,19 @@ static int do_task_stat(struct seq_file
41698 gtime = task_gtime(task);
41699 }
41700
41701+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
41702+ if (PAX_RAND_FLAGS(mm)) {
41703+ eip = 0;
41704+ esp = 0;
41705+ wchan = 0;
41706+ }
41707+#endif
41708+#ifdef CONFIG_GRKERNSEC_HIDESYM
41709+ wchan = 0;
41710+ eip =0;
41711+ esp =0;
41712+#endif
41713+
41714 /* scale priority and nice values from timeslices to -20..20 */
41715 /* to make it look like a "normal" Unix priority/nice value */
41716 priority = task_prio(task);
41717@@ -473,9 +519,15 @@ static int do_task_stat(struct seq_file
41718 vsize,
41719 mm ? get_mm_rss(mm) : 0,
41720 rsslim,
41721+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
41722+ PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0),
41723+ PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0),
41724+ PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0),
41725+#else
41726 mm ? (permitted ? mm->start_code : 1) : 0,
41727 mm ? (permitted ? mm->end_code : 1) : 0,
41728 (permitted && mm) ? mm->start_stack : 0,
41729+#endif
41730 esp,
41731 eip,
41732 /* The signal information here is obsolete.
41733@@ -528,3 +580,18 @@ int proc_pid_statm(struct seq_file *m, s
41734
41735 return 0;
41736 }
41737+
41738+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
41739+int proc_pid_ipaddr(struct task_struct *task, char *buffer)
41740+{
41741+ u32 curr_ip = 0;
41742+ unsigned long flags;
41743+
41744+ if (lock_task_sighand(task, &flags)) {
41745+ curr_ip = task->signal->curr_ip;
41746+ unlock_task_sighand(task, &flags);
41747+ }
41748+
41749+ return sprintf(buffer, "%pI4\n", &curr_ip);
41750+}
41751+#endif
41752diff -urNp linux-2.6.32.41/fs/proc/base.c linux-2.6.32.41/fs/proc/base.c
41753--- linux-2.6.32.41/fs/proc/base.c 2011-04-22 19:16:29.000000000 -0400
41754+++ linux-2.6.32.41/fs/proc/base.c 2011-06-04 21:20:50.000000000 -0400
41755@@ -102,6 +102,22 @@ struct pid_entry {
41756 union proc_op op;
41757 };
41758
41759+struct getdents_callback {
41760+ struct linux_dirent __user * current_dir;
41761+ struct linux_dirent __user * previous;
41762+ struct file * file;
41763+ int count;
41764+ int error;
41765+};
41766+
41767+static int gr_fake_filldir(void * __buf, const char *name, int namlen,
41768+ loff_t offset, u64 ino, unsigned int d_type)
41769+{
41770+ struct getdents_callback * buf = (struct getdents_callback *) __buf;
41771+ buf->error = -EINVAL;
41772+ return 0;
41773+}
41774+
41775 #define NOD(NAME, MODE, IOP, FOP, OP) { \
41776 .name = (NAME), \
41777 .len = sizeof(NAME) - 1, \
41778@@ -213,6 +229,9 @@ static int check_mem_permission(struct t
41779 if (task == current)
41780 return 0;
41781
41782+ if (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))
41783+ return -EPERM;
41784+
41785 /*
41786 * If current is actively ptrace'ing, and would also be
41787 * permitted to freshly attach with ptrace now, permit it.
41788@@ -260,6 +279,9 @@ static int proc_pid_cmdline(struct task_
41789 if (!mm->arg_end)
41790 goto out_mm; /* Shh! No looking before we're done */
41791
41792+ if (gr_acl_handle_procpidmem(task))
41793+ goto out_mm;
41794+
41795 len = mm->arg_end - mm->arg_start;
41796
41797 if (len > PAGE_SIZE)
41798@@ -287,12 +309,28 @@ out:
41799 return res;
41800 }
41801
41802+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
41803+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
41804+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
41805+ _mm->pax_flags & MF_PAX_SEGMEXEC))
41806+#endif
41807+
41808 static int proc_pid_auxv(struct task_struct *task, char *buffer)
41809 {
41810 int res = 0;
41811 struct mm_struct *mm = get_task_mm(task);
41812 if (mm) {
41813 unsigned int nwords = 0;
41814+
41815+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
41816+ /* allow if we're currently ptracing this task */
41817+ if (PAX_RAND_FLAGS(mm) &&
41818+ (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
41819+ mmput(mm);
41820+ return res;
41821+ }
41822+#endif
41823+
41824 do {
41825 nwords += 2;
41826 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
41827@@ -306,7 +344,7 @@ static int proc_pid_auxv(struct task_str
41828 }
41829
41830
41831-#ifdef CONFIG_KALLSYMS
41832+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
41833 /*
41834 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
41835 * Returns the resolved symbol. If that fails, simply return the address.
41836@@ -328,7 +366,7 @@ static int proc_pid_wchan(struct task_st
41837 }
41838 #endif /* CONFIG_KALLSYMS */
41839
41840-#ifdef CONFIG_STACKTRACE
41841+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
41842
41843 #define MAX_STACK_TRACE_DEPTH 64
41844
41845@@ -522,7 +560,7 @@ static int proc_pid_limits(struct task_s
41846 return count;
41847 }
41848
41849-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
41850+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
41851 static int proc_pid_syscall(struct task_struct *task, char *buffer)
41852 {
41853 long nr;
41854@@ -547,7 +585,7 @@ static int proc_pid_syscall(struct task_
41855 /************************************************************************/
41856
41857 /* permission checks */
41858-static int proc_fd_access_allowed(struct inode *inode)
41859+static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
41860 {
41861 struct task_struct *task;
41862 int allowed = 0;
41863@@ -557,7 +595,10 @@ static int proc_fd_access_allowed(struct
41864 */
41865 task = get_proc_task(inode);
41866 if (task) {
41867- allowed = ptrace_may_access(task, PTRACE_MODE_READ);
41868+ if (log)
41869+ allowed = ptrace_may_access_log(task, PTRACE_MODE_READ);
41870+ else
41871+ allowed = ptrace_may_access(task, PTRACE_MODE_READ);
41872 put_task_struct(task);
41873 }
41874 return allowed;
41875@@ -936,6 +977,9 @@ static ssize_t environ_read(struct file
41876 if (!task)
41877 goto out_no_task;
41878
41879+ if (gr_acl_handle_procpidmem(task))
41880+ goto out;
41881+
41882 if (!ptrace_may_access(task, PTRACE_MODE_READ))
41883 goto out;
41884
41885@@ -1350,7 +1394,7 @@ static void *proc_pid_follow_link(struct
41886 path_put(&nd->path);
41887
41888 /* Are we allowed to snoop on the tasks file descriptors? */
41889- if (!proc_fd_access_allowed(inode))
41890+ if (!proc_fd_access_allowed(inode,0))
41891 goto out;
41892
41893 error = PROC_I(inode)->op.proc_get_link(inode, &nd->path);
41894@@ -1390,8 +1434,18 @@ static int proc_pid_readlink(struct dent
41895 struct path path;
41896
41897 /* Are we allowed to snoop on the tasks file descriptors? */
41898- if (!proc_fd_access_allowed(inode))
41899- goto out;
41900+ /* logging this is needed for learning on chromium to work properly,
41901+ but we don't want to flood the logs from 'ps' which does a readlink
41902+ on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
41903+ CAP_SYS_PTRACE as it's not necessary for its basic functionality
41904+ */
41905+ if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
41906+ if (!proc_fd_access_allowed(inode,0))
41907+ goto out;
41908+ } else {
41909+ if (!proc_fd_access_allowed(inode,1))
41910+ goto out;
41911+ }
41912
41913 error = PROC_I(inode)->op.proc_get_link(inode, &path);
41914 if (error)
41915@@ -1456,7 +1510,11 @@ static struct inode *proc_pid_make_inode
41916 rcu_read_lock();
41917 cred = __task_cred(task);
41918 inode->i_uid = cred->euid;
41919+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
41920+ inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
41921+#else
41922 inode->i_gid = cred->egid;
41923+#endif
41924 rcu_read_unlock();
41925 }
41926 security_task_to_inode(task, inode);
41927@@ -1474,6 +1532,9 @@ static int pid_getattr(struct vfsmount *
41928 struct inode *inode = dentry->d_inode;
41929 struct task_struct *task;
41930 const struct cred *cred;
41931+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
41932+ const struct cred *tmpcred = current_cred();
41933+#endif
41934
41935 generic_fillattr(inode, stat);
41936
41937@@ -1481,13 +1542,41 @@ static int pid_getattr(struct vfsmount *
41938 stat->uid = 0;
41939 stat->gid = 0;
41940 task = pid_task(proc_pid(inode), PIDTYPE_PID);
41941+
41942+ if (task && (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))) {
41943+ rcu_read_unlock();
41944+ return -ENOENT;
41945+ }
41946+
41947 if (task) {
41948+ cred = __task_cred(task);
41949+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
41950+ if (!tmpcred->uid || (tmpcred->uid == cred->uid)
41951+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
41952+ || in_group_p(CONFIG_GRKERNSEC_PROC_GID)
41953+#endif
41954+ ) {
41955+#endif
41956 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
41957+#ifdef CONFIG_GRKERNSEC_PROC_USER
41958+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
41959+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
41960+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
41961+#endif
41962 task_dumpable(task)) {
41963- cred = __task_cred(task);
41964 stat->uid = cred->euid;
41965+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
41966+ stat->gid = CONFIG_GRKERNSEC_PROC_GID;
41967+#else
41968 stat->gid = cred->egid;
41969+#endif
41970 }
41971+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
41972+ } else {
41973+ rcu_read_unlock();
41974+ return -ENOENT;
41975+ }
41976+#endif
41977 }
41978 rcu_read_unlock();
41979 return 0;
41980@@ -1518,11 +1607,20 @@ static int pid_revalidate(struct dentry
41981
41982 if (task) {
41983 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
41984+#ifdef CONFIG_GRKERNSEC_PROC_USER
41985+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
41986+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
41987+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
41988+#endif
41989 task_dumpable(task)) {
41990 rcu_read_lock();
41991 cred = __task_cred(task);
41992 inode->i_uid = cred->euid;
41993+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
41994+ inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
41995+#else
41996 inode->i_gid = cred->egid;
41997+#endif
41998 rcu_read_unlock();
41999 } else {
42000 inode->i_uid = 0;
42001@@ -1643,7 +1741,8 @@ static int proc_fd_info(struct inode *in
42002 int fd = proc_fd(inode);
42003
42004 if (task) {
42005- files = get_files_struct(task);
42006+ if (!gr_acl_handle_procpidmem(task))
42007+ files = get_files_struct(task);
42008 put_task_struct(task);
42009 }
42010 if (files) {
42011@@ -1895,12 +1994,22 @@ static const struct file_operations proc
42012 static int proc_fd_permission(struct inode *inode, int mask)
42013 {
42014 int rv;
42015+ struct task_struct *task;
42016
42017 rv = generic_permission(inode, mask, NULL);
42018- if (rv == 0)
42019- return 0;
42020+
42021 if (task_pid(current) == proc_pid(inode))
42022 rv = 0;
42023+
42024+ task = get_proc_task(inode);
42025+ if (task == NULL)
42026+ return rv;
42027+
42028+ if (gr_acl_handle_procpidmem(task))
42029+ rv = -EACCES;
42030+
42031+ put_task_struct(task);
42032+
42033 return rv;
42034 }
42035
42036@@ -2009,6 +2118,9 @@ static struct dentry *proc_pident_lookup
42037 if (!task)
42038 goto out_no_task;
42039
42040+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
42041+ goto out;
42042+
42043 /*
42044 * Yes, it does not scale. And it should not. Don't add
42045 * new entries into /proc/<tgid>/ without very good reasons.
42046@@ -2053,6 +2165,9 @@ static int proc_pident_readdir(struct fi
42047 if (!task)
42048 goto out_no_task;
42049
42050+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
42051+ goto out;
42052+
42053 ret = 0;
42054 i = filp->f_pos;
42055 switch (i) {
42056@@ -2320,7 +2435,7 @@ static void *proc_self_follow_link(struc
42057 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
42058 void *cookie)
42059 {
42060- char *s = nd_get_link(nd);
42061+ const char *s = nd_get_link(nd);
42062 if (!IS_ERR(s))
42063 __putname(s);
42064 }
42065@@ -2519,7 +2634,7 @@ static const struct pid_entry tgid_base_
42066 #ifdef CONFIG_SCHED_DEBUG
42067 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
42068 #endif
42069-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
42070+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
42071 INF("syscall", S_IRUSR, proc_pid_syscall),
42072 #endif
42073 INF("cmdline", S_IRUGO, proc_pid_cmdline),
42074@@ -2544,10 +2659,10 @@ static const struct pid_entry tgid_base_
42075 #ifdef CONFIG_SECURITY
42076 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
42077 #endif
42078-#ifdef CONFIG_KALLSYMS
42079+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
42080 INF("wchan", S_IRUGO, proc_pid_wchan),
42081 #endif
42082-#ifdef CONFIG_STACKTRACE
42083+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
42084 ONE("stack", S_IRUSR, proc_pid_stack),
42085 #endif
42086 #ifdef CONFIG_SCHEDSTATS
42087@@ -2577,6 +2692,9 @@ static const struct pid_entry tgid_base_
42088 #ifdef CONFIG_TASK_IO_ACCOUNTING
42089 INF("io", S_IRUGO, proc_tgid_io_accounting),
42090 #endif
42091+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
42092+ INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
42093+#endif
42094 };
42095
42096 static int proc_tgid_base_readdir(struct file * filp,
42097@@ -2701,7 +2819,14 @@ static struct dentry *proc_pid_instantia
42098 if (!inode)
42099 goto out;
42100
42101+#ifdef CONFIG_GRKERNSEC_PROC_USER
42102+ inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
42103+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
42104+ inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
42105+ inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
42106+#else
42107 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
42108+#endif
42109 inode->i_op = &proc_tgid_base_inode_operations;
42110 inode->i_fop = &proc_tgid_base_operations;
42111 inode->i_flags|=S_IMMUTABLE;
42112@@ -2743,7 +2868,11 @@ struct dentry *proc_pid_lookup(struct in
42113 if (!task)
42114 goto out;
42115
42116+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
42117+ goto out_put_task;
42118+
42119 result = proc_pid_instantiate(dir, dentry, task, NULL);
42120+out_put_task:
42121 put_task_struct(task);
42122 out:
42123 return result;
42124@@ -2808,6 +2937,11 @@ int proc_pid_readdir(struct file * filp,
42125 {
42126 unsigned int nr;
42127 struct task_struct *reaper;
42128+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
42129+ const struct cred *tmpcred = current_cred();
42130+ const struct cred *itercred;
42131+#endif
42132+ filldir_t __filldir = filldir;
42133 struct tgid_iter iter;
42134 struct pid_namespace *ns;
42135
42136@@ -2831,8 +2965,27 @@ int proc_pid_readdir(struct file * filp,
42137 for (iter = next_tgid(ns, iter);
42138 iter.task;
42139 iter.tgid += 1, iter = next_tgid(ns, iter)) {
42140+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
42141+ rcu_read_lock();
42142+ itercred = __task_cred(iter.task);
42143+#endif
42144+ if (gr_pid_is_chrooted(iter.task) || gr_check_hidden_task(iter.task)
42145+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
42146+ || (tmpcred->uid && (itercred->uid != tmpcred->uid)
42147+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
42148+ && !in_group_p(CONFIG_GRKERNSEC_PROC_GID)
42149+#endif
42150+ )
42151+#endif
42152+ )
42153+ __filldir = &gr_fake_filldir;
42154+ else
42155+ __filldir = filldir;
42156+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
42157+ rcu_read_unlock();
42158+#endif
42159 filp->f_pos = iter.tgid + TGID_OFFSET;
42160- if (proc_pid_fill_cache(filp, dirent, filldir, iter) < 0) {
42161+ if (proc_pid_fill_cache(filp, dirent, __filldir, iter) < 0) {
42162 put_task_struct(iter.task);
42163 goto out;
42164 }
42165@@ -2858,7 +3011,7 @@ static const struct pid_entry tid_base_s
42166 #ifdef CONFIG_SCHED_DEBUG
42167 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
42168 #endif
42169-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
42170+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
42171 INF("syscall", S_IRUSR, proc_pid_syscall),
42172 #endif
42173 INF("cmdline", S_IRUGO, proc_pid_cmdline),
42174@@ -2882,10 +3035,10 @@ static const struct pid_entry tid_base_s
42175 #ifdef CONFIG_SECURITY
42176 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
42177 #endif
42178-#ifdef CONFIG_KALLSYMS
42179+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
42180 INF("wchan", S_IRUGO, proc_pid_wchan),
42181 #endif
42182-#ifdef CONFIG_STACKTRACE
42183+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
42184 ONE("stack", S_IRUSR, proc_pid_stack),
42185 #endif
42186 #ifdef CONFIG_SCHEDSTATS
42187diff -urNp linux-2.6.32.41/fs/proc/cmdline.c linux-2.6.32.41/fs/proc/cmdline.c
42188--- linux-2.6.32.41/fs/proc/cmdline.c 2011-03-27 14:31:47.000000000 -0400
42189+++ linux-2.6.32.41/fs/proc/cmdline.c 2011-04-17 15:56:46.000000000 -0400
42190@@ -23,7 +23,11 @@ static const struct file_operations cmdl
42191
42192 static int __init proc_cmdline_init(void)
42193 {
42194+#ifdef CONFIG_GRKERNSEC_PROC_ADD
42195+ proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
42196+#else
42197 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
42198+#endif
42199 return 0;
42200 }
42201 module_init(proc_cmdline_init);
42202diff -urNp linux-2.6.32.41/fs/proc/devices.c linux-2.6.32.41/fs/proc/devices.c
42203--- linux-2.6.32.41/fs/proc/devices.c 2011-03-27 14:31:47.000000000 -0400
42204+++ linux-2.6.32.41/fs/proc/devices.c 2011-04-17 15:56:46.000000000 -0400
42205@@ -64,7 +64,11 @@ static const struct file_operations proc
42206
42207 static int __init proc_devices_init(void)
42208 {
42209+#ifdef CONFIG_GRKERNSEC_PROC_ADD
42210+ proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
42211+#else
42212 proc_create("devices", 0, NULL, &proc_devinfo_operations);
42213+#endif
42214 return 0;
42215 }
42216 module_init(proc_devices_init);
42217diff -urNp linux-2.6.32.41/fs/proc/inode.c linux-2.6.32.41/fs/proc/inode.c
42218--- linux-2.6.32.41/fs/proc/inode.c 2011-03-27 14:31:47.000000000 -0400
42219+++ linux-2.6.32.41/fs/proc/inode.c 2011-04-17 15:56:46.000000000 -0400
42220@@ -457,7 +457,11 @@ struct inode *proc_get_inode(struct supe
42221 if (de->mode) {
42222 inode->i_mode = de->mode;
42223 inode->i_uid = de->uid;
42224+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
42225+ inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
42226+#else
42227 inode->i_gid = de->gid;
42228+#endif
42229 }
42230 if (de->size)
42231 inode->i_size = de->size;
42232diff -urNp linux-2.6.32.41/fs/proc/internal.h linux-2.6.32.41/fs/proc/internal.h
42233--- linux-2.6.32.41/fs/proc/internal.h 2011-03-27 14:31:47.000000000 -0400
42234+++ linux-2.6.32.41/fs/proc/internal.h 2011-04-17 15:56:46.000000000 -0400
42235@@ -51,6 +51,9 @@ extern int proc_pid_status(struct seq_fi
42236 struct pid *pid, struct task_struct *task);
42237 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
42238 struct pid *pid, struct task_struct *task);
42239+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
42240+extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
42241+#endif
42242 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
42243
42244 extern const struct file_operations proc_maps_operations;
42245diff -urNp linux-2.6.32.41/fs/proc/Kconfig linux-2.6.32.41/fs/proc/Kconfig
42246--- linux-2.6.32.41/fs/proc/Kconfig 2011-03-27 14:31:47.000000000 -0400
42247+++ linux-2.6.32.41/fs/proc/Kconfig 2011-04-17 15:56:46.000000000 -0400
42248@@ -30,12 +30,12 @@ config PROC_FS
42249
42250 config PROC_KCORE
42251 bool "/proc/kcore support" if !ARM
42252- depends on PROC_FS && MMU
42253+ depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
42254
42255 config PROC_VMCORE
42256 bool "/proc/vmcore support (EXPERIMENTAL)"
42257- depends on PROC_FS && CRASH_DUMP
42258- default y
42259+ depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
42260+ default n
42261 help
42262 Exports the dump image of crashed kernel in ELF format.
42263
42264@@ -59,8 +59,8 @@ config PROC_SYSCTL
42265 limited in memory.
42266
42267 config PROC_PAGE_MONITOR
42268- default y
42269- depends on PROC_FS && MMU
42270+ default n
42271+ depends on PROC_FS && MMU && !GRKERNSEC
42272 bool "Enable /proc page monitoring" if EMBEDDED
42273 help
42274 Various /proc files exist to monitor process memory utilization:
42275diff -urNp linux-2.6.32.41/fs/proc/kcore.c linux-2.6.32.41/fs/proc/kcore.c
42276--- linux-2.6.32.41/fs/proc/kcore.c 2011-03-27 14:31:47.000000000 -0400
42277+++ linux-2.6.32.41/fs/proc/kcore.c 2011-05-16 21:46:57.000000000 -0400
42278@@ -320,6 +320,8 @@ static void elf_kcore_store_hdr(char *bu
42279 off_t offset = 0;
42280 struct kcore_list *m;
42281
42282+ pax_track_stack();
42283+
42284 /* setup ELF header */
42285 elf = (struct elfhdr *) bufp;
42286 bufp += sizeof(struct elfhdr);
42287@@ -477,9 +479,10 @@ read_kcore(struct file *file, char __use
42288 * the addresses in the elf_phdr on our list.
42289 */
42290 start = kc_offset_to_vaddr(*fpos - elf_buflen);
42291- if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
42292+ tsz = PAGE_SIZE - (start & ~PAGE_MASK);
42293+ if (tsz > buflen)
42294 tsz = buflen;
42295-
42296+
42297 while (buflen) {
42298 struct kcore_list *m;
42299
42300@@ -508,20 +511,23 @@ read_kcore(struct file *file, char __use
42301 kfree(elf_buf);
42302 } else {
42303 if (kern_addr_valid(start)) {
42304- unsigned long n;
42305+ char *elf_buf;
42306+ mm_segment_t oldfs;
42307
42308- n = copy_to_user(buffer, (char *)start, tsz);
42309- /*
42310- * We cannot distingush between fault on source
42311- * and fault on destination. When this happens
42312- * we clear too and hope it will trigger the
42313- * EFAULT again.
42314- */
42315- if (n) {
42316- if (clear_user(buffer + tsz - n,
42317- n))
42318+ elf_buf = kmalloc(tsz, GFP_KERNEL);
42319+ if (!elf_buf)
42320+ return -ENOMEM;
42321+ oldfs = get_fs();
42322+ set_fs(KERNEL_DS);
42323+ if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
42324+ set_fs(oldfs);
42325+ if (copy_to_user(buffer, elf_buf, tsz)) {
42326+ kfree(elf_buf);
42327 return -EFAULT;
42328+ }
42329 }
42330+ set_fs(oldfs);
42331+ kfree(elf_buf);
42332 } else {
42333 if (clear_user(buffer, tsz))
42334 return -EFAULT;
42335@@ -541,6 +547,9 @@ read_kcore(struct file *file, char __use
42336
42337 static int open_kcore(struct inode *inode, struct file *filp)
42338 {
42339+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
42340+ return -EPERM;
42341+#endif
42342 if (!capable(CAP_SYS_RAWIO))
42343 return -EPERM;
42344 if (kcore_need_update)
42345diff -urNp linux-2.6.32.41/fs/proc/meminfo.c linux-2.6.32.41/fs/proc/meminfo.c
42346--- linux-2.6.32.41/fs/proc/meminfo.c 2011-03-27 14:31:47.000000000 -0400
42347+++ linux-2.6.32.41/fs/proc/meminfo.c 2011-05-16 21:46:57.000000000 -0400
42348@@ -29,6 +29,8 @@ static int meminfo_proc_show(struct seq_
42349 unsigned long pages[NR_LRU_LISTS];
42350 int lru;
42351
42352+ pax_track_stack();
42353+
42354 /*
42355 * display in kilobytes.
42356 */
42357@@ -149,7 +151,7 @@ static int meminfo_proc_show(struct seq_
42358 vmi.used >> 10,
42359 vmi.largest_chunk >> 10
42360 #ifdef CONFIG_MEMORY_FAILURE
42361- ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10)
42362+ ,atomic_long_read_unchecked(&mce_bad_pages) << (PAGE_SHIFT - 10)
42363 #endif
42364 );
42365
42366diff -urNp linux-2.6.32.41/fs/proc/nommu.c linux-2.6.32.41/fs/proc/nommu.c
42367--- linux-2.6.32.41/fs/proc/nommu.c 2011-03-27 14:31:47.000000000 -0400
42368+++ linux-2.6.32.41/fs/proc/nommu.c 2011-04-17 15:56:46.000000000 -0400
42369@@ -67,7 +67,7 @@ static int nommu_region_show(struct seq_
42370 if (len < 1)
42371 len = 1;
42372 seq_printf(m, "%*c", len, ' ');
42373- seq_path(m, &file->f_path, "");
42374+ seq_path(m, &file->f_path, "\n\\");
42375 }
42376
42377 seq_putc(m, '\n');
42378diff -urNp linux-2.6.32.41/fs/proc/proc_net.c linux-2.6.32.41/fs/proc/proc_net.c
42379--- linux-2.6.32.41/fs/proc/proc_net.c 2011-03-27 14:31:47.000000000 -0400
42380+++ linux-2.6.32.41/fs/proc/proc_net.c 2011-04-17 15:56:46.000000000 -0400
42381@@ -104,6 +104,17 @@ static struct net *get_proc_task_net(str
42382 struct task_struct *task;
42383 struct nsproxy *ns;
42384 struct net *net = NULL;
42385+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
42386+ const struct cred *cred = current_cred();
42387+#endif
42388+
42389+#ifdef CONFIG_GRKERNSEC_PROC_USER
42390+ if (cred->fsuid)
42391+ return net;
42392+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
42393+ if (cred->fsuid && !in_group_p(CONFIG_GRKERNSEC_PROC_GID))
42394+ return net;
42395+#endif
42396
42397 rcu_read_lock();
42398 task = pid_task(proc_pid(dir), PIDTYPE_PID);
42399diff -urNp linux-2.6.32.41/fs/proc/proc_sysctl.c linux-2.6.32.41/fs/proc/proc_sysctl.c
42400--- linux-2.6.32.41/fs/proc/proc_sysctl.c 2011-03-27 14:31:47.000000000 -0400
42401+++ linux-2.6.32.41/fs/proc/proc_sysctl.c 2011-04-17 15:56:46.000000000 -0400
42402@@ -7,6 +7,8 @@
42403 #include <linux/security.h>
42404 #include "internal.h"
42405
42406+extern __u32 gr_handle_sysctl(const struct ctl_table *table, const int op);
42407+
42408 static const struct dentry_operations proc_sys_dentry_operations;
42409 static const struct file_operations proc_sys_file_operations;
42410 static const struct inode_operations proc_sys_inode_operations;
42411@@ -109,6 +111,9 @@ static struct dentry *proc_sys_lookup(st
42412 if (!p)
42413 goto out;
42414
42415+ if (gr_handle_sysctl(p, MAY_EXEC))
42416+ goto out;
42417+
42418 err = ERR_PTR(-ENOMEM);
42419 inode = proc_sys_make_inode(dir->i_sb, h ? h : head, p);
42420 if (h)
42421@@ -228,6 +233,9 @@ static int scan(struct ctl_table_header
42422 if (*pos < file->f_pos)
42423 continue;
42424
42425+ if (gr_handle_sysctl(table, 0))
42426+ continue;
42427+
42428 res = proc_sys_fill_cache(file, dirent, filldir, head, table);
42429 if (res)
42430 return res;
42431@@ -344,6 +352,9 @@ static int proc_sys_getattr(struct vfsmo
42432 if (IS_ERR(head))
42433 return PTR_ERR(head);
42434
42435+ if (table && gr_handle_sysctl(table, MAY_EXEC))
42436+ return -ENOENT;
42437+
42438 generic_fillattr(inode, stat);
42439 if (table)
42440 stat->mode = (stat->mode & S_IFMT) | table->mode;
42441diff -urNp linux-2.6.32.41/fs/proc/root.c linux-2.6.32.41/fs/proc/root.c
42442--- linux-2.6.32.41/fs/proc/root.c 2011-03-27 14:31:47.000000000 -0400
42443+++ linux-2.6.32.41/fs/proc/root.c 2011-04-17 15:56:46.000000000 -0400
42444@@ -134,7 +134,15 @@ void __init proc_root_init(void)
42445 #ifdef CONFIG_PROC_DEVICETREE
42446 proc_device_tree_init();
42447 #endif
42448+#ifdef CONFIG_GRKERNSEC_PROC_ADD
42449+#ifdef CONFIG_GRKERNSEC_PROC_USER
42450+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
42451+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
42452+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
42453+#endif
42454+#else
42455 proc_mkdir("bus", NULL);
42456+#endif
42457 proc_sys_init();
42458 }
42459
42460diff -urNp linux-2.6.32.41/fs/proc/task_mmu.c linux-2.6.32.41/fs/proc/task_mmu.c
42461--- linux-2.6.32.41/fs/proc/task_mmu.c 2011-03-27 14:31:47.000000000 -0400
42462+++ linux-2.6.32.41/fs/proc/task_mmu.c 2011-04-23 13:38:09.000000000 -0400
42463@@ -46,15 +46,26 @@ void task_mem(struct seq_file *m, struct
42464 "VmStk:\t%8lu kB\n"
42465 "VmExe:\t%8lu kB\n"
42466 "VmLib:\t%8lu kB\n"
42467- "VmPTE:\t%8lu kB\n",
42468- hiwater_vm << (PAGE_SHIFT-10),
42469+ "VmPTE:\t%8lu kB\n"
42470+
42471+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
42472+ "CsBase:\t%8lx\nCsLim:\t%8lx\n"
42473+#endif
42474+
42475+ ,hiwater_vm << (PAGE_SHIFT-10),
42476 (total_vm - mm->reserved_vm) << (PAGE_SHIFT-10),
42477 mm->locked_vm << (PAGE_SHIFT-10),
42478 hiwater_rss << (PAGE_SHIFT-10),
42479 total_rss << (PAGE_SHIFT-10),
42480 data << (PAGE_SHIFT-10),
42481 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
42482- (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10);
42483+ (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10
42484+
42485+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
42486+ , mm->context.user_cs_base, mm->context.user_cs_limit
42487+#endif
42488+
42489+ );
42490 }
42491
42492 unsigned long task_vsize(struct mm_struct *mm)
42493@@ -175,7 +186,8 @@ static void m_stop(struct seq_file *m, v
42494 struct proc_maps_private *priv = m->private;
42495 struct vm_area_struct *vma = v;
42496
42497- vma_stop(priv, vma);
42498+ if (!IS_ERR(vma))
42499+ vma_stop(priv, vma);
42500 if (priv->task)
42501 put_task_struct(priv->task);
42502 }
42503@@ -199,6 +211,12 @@ static int do_maps_open(struct inode *in
42504 return ret;
42505 }
42506
42507+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
42508+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
42509+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
42510+ _mm->pax_flags & MF_PAX_SEGMEXEC))
42511+#endif
42512+
42513 static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
42514 {
42515 struct mm_struct *mm = vma->vm_mm;
42516@@ -206,7 +224,6 @@ static void show_map_vma(struct seq_file
42517 int flags = vma->vm_flags;
42518 unsigned long ino = 0;
42519 unsigned long long pgoff = 0;
42520- unsigned long start;
42521 dev_t dev = 0;
42522 int len;
42523
42524@@ -217,20 +234,23 @@ static void show_map_vma(struct seq_file
42525 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
42526 }
42527
42528- /* We don't show the stack guard page in /proc/maps */
42529- start = vma->vm_start;
42530- if (vma->vm_flags & VM_GROWSDOWN)
42531- if (!vma_stack_continue(vma->vm_prev, vma->vm_start))
42532- start += PAGE_SIZE;
42533-
42534 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
42535- start,
42536+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
42537+ PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start,
42538+ PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end,
42539+#else
42540+ vma->vm_start,
42541 vma->vm_end,
42542+#endif
42543 flags & VM_READ ? 'r' : '-',
42544 flags & VM_WRITE ? 'w' : '-',
42545 flags & VM_EXEC ? 'x' : '-',
42546 flags & VM_MAYSHARE ? 's' : 'p',
42547+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
42548+ PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
42549+#else
42550 pgoff,
42551+#endif
42552 MAJOR(dev), MINOR(dev), ino, &len);
42553
42554 /*
42555@@ -239,7 +259,7 @@ static void show_map_vma(struct seq_file
42556 */
42557 if (file) {
42558 pad_len_spaces(m, len);
42559- seq_path(m, &file->f_path, "\n");
42560+ seq_path(m, &file->f_path, "\n\\");
42561 } else {
42562 const char *name = arch_vma_name(vma);
42563 if (!name) {
42564@@ -247,8 +267,9 @@ static void show_map_vma(struct seq_file
42565 if (vma->vm_start <= mm->brk &&
42566 vma->vm_end >= mm->start_brk) {
42567 name = "[heap]";
42568- } else if (vma->vm_start <= mm->start_stack &&
42569- vma->vm_end >= mm->start_stack) {
42570+ } else if ((vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
42571+ (vma->vm_start <= mm->start_stack &&
42572+ vma->vm_end >= mm->start_stack)) {
42573 name = "[stack]";
42574 }
42575 } else {
42576@@ -391,9 +412,16 @@ static int show_smap(struct seq_file *m,
42577 };
42578
42579 memset(&mss, 0, sizeof mss);
42580- mss.vma = vma;
42581- if (vma->vm_mm && !is_vm_hugetlb_page(vma))
42582- walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
42583+
42584+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
42585+ if (!PAX_RAND_FLAGS(vma->vm_mm)) {
42586+#endif
42587+ mss.vma = vma;
42588+ if (vma->vm_mm && !is_vm_hugetlb_page(vma))
42589+ walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
42590+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
42591+ }
42592+#endif
42593
42594 show_map_vma(m, vma);
42595
42596@@ -409,7 +437,11 @@ static int show_smap(struct seq_file *m,
42597 "Swap: %8lu kB\n"
42598 "KernelPageSize: %8lu kB\n"
42599 "MMUPageSize: %8lu kB\n",
42600+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
42601+ PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
42602+#else
42603 (vma->vm_end - vma->vm_start) >> 10,
42604+#endif
42605 mss.resident >> 10,
42606 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
42607 mss.shared_clean >> 10,
42608diff -urNp linux-2.6.32.41/fs/proc/task_nommu.c linux-2.6.32.41/fs/proc/task_nommu.c
42609--- linux-2.6.32.41/fs/proc/task_nommu.c 2011-03-27 14:31:47.000000000 -0400
42610+++ linux-2.6.32.41/fs/proc/task_nommu.c 2011-04-17 15:56:46.000000000 -0400
42611@@ -50,7 +50,7 @@ void task_mem(struct seq_file *m, struct
42612 else
42613 bytes += kobjsize(mm);
42614
42615- if (current->fs && current->fs->users > 1)
42616+ if (current->fs && atomic_read(&current->fs->users) > 1)
42617 sbytes += kobjsize(current->fs);
42618 else
42619 bytes += kobjsize(current->fs);
42620@@ -154,7 +154,7 @@ static int nommu_vma_show(struct seq_fil
42621 if (len < 1)
42622 len = 1;
42623 seq_printf(m, "%*c", len, ' ');
42624- seq_path(m, &file->f_path, "");
42625+ seq_path(m, &file->f_path, "\n\\");
42626 }
42627
42628 seq_putc(m, '\n');
42629diff -urNp linux-2.6.32.41/fs/readdir.c linux-2.6.32.41/fs/readdir.c
42630--- linux-2.6.32.41/fs/readdir.c 2011-03-27 14:31:47.000000000 -0400
42631+++ linux-2.6.32.41/fs/readdir.c 2011-04-17 15:56:46.000000000 -0400
42632@@ -16,6 +16,7 @@
42633 #include <linux/security.h>
42634 #include <linux/syscalls.h>
42635 #include <linux/unistd.h>
42636+#include <linux/namei.h>
42637
42638 #include <asm/uaccess.h>
42639
42640@@ -67,6 +68,7 @@ struct old_linux_dirent {
42641
42642 struct readdir_callback {
42643 struct old_linux_dirent __user * dirent;
42644+ struct file * file;
42645 int result;
42646 };
42647
42648@@ -84,6 +86,10 @@ static int fillonedir(void * __buf, cons
42649 buf->result = -EOVERFLOW;
42650 return -EOVERFLOW;
42651 }
42652+
42653+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
42654+ return 0;
42655+
42656 buf->result++;
42657 dirent = buf->dirent;
42658 if (!access_ok(VERIFY_WRITE, dirent,
42659@@ -116,6 +122,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned in
42660
42661 buf.result = 0;
42662 buf.dirent = dirent;
42663+ buf.file = file;
42664
42665 error = vfs_readdir(file, fillonedir, &buf);
42666 if (buf.result)
42667@@ -142,6 +149,7 @@ struct linux_dirent {
42668 struct getdents_callback {
42669 struct linux_dirent __user * current_dir;
42670 struct linux_dirent __user * previous;
42671+ struct file * file;
42672 int count;
42673 int error;
42674 };
42675@@ -162,6 +170,10 @@ static int filldir(void * __buf, const c
42676 buf->error = -EOVERFLOW;
42677 return -EOVERFLOW;
42678 }
42679+
42680+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
42681+ return 0;
42682+
42683 dirent = buf->previous;
42684 if (dirent) {
42685 if (__put_user(offset, &dirent->d_off))
42686@@ -209,6 +221,7 @@ SYSCALL_DEFINE3(getdents, unsigned int,
42687 buf.previous = NULL;
42688 buf.count = count;
42689 buf.error = 0;
42690+ buf.file = file;
42691
42692 error = vfs_readdir(file, filldir, &buf);
42693 if (error >= 0)
42694@@ -228,6 +241,7 @@ out:
42695 struct getdents_callback64 {
42696 struct linux_dirent64 __user * current_dir;
42697 struct linux_dirent64 __user * previous;
42698+ struct file *file;
42699 int count;
42700 int error;
42701 };
42702@@ -242,6 +256,10 @@ static int filldir64(void * __buf, const
42703 buf->error = -EINVAL; /* only used if we fail.. */
42704 if (reclen > buf->count)
42705 return -EINVAL;
42706+
42707+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
42708+ return 0;
42709+
42710 dirent = buf->previous;
42711 if (dirent) {
42712 if (__put_user(offset, &dirent->d_off))
42713@@ -289,6 +307,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int
42714
42715 buf.current_dir = dirent;
42716 buf.previous = NULL;
42717+ buf.file = file;
42718 buf.count = count;
42719 buf.error = 0;
42720
42721diff -urNp linux-2.6.32.41/fs/reiserfs/dir.c linux-2.6.32.41/fs/reiserfs/dir.c
42722--- linux-2.6.32.41/fs/reiserfs/dir.c 2011-03-27 14:31:47.000000000 -0400
42723+++ linux-2.6.32.41/fs/reiserfs/dir.c 2011-05-16 21:46:57.000000000 -0400
42724@@ -66,6 +66,8 @@ int reiserfs_readdir_dentry(struct dentr
42725 struct reiserfs_dir_entry de;
42726 int ret = 0;
42727
42728+ pax_track_stack();
42729+
42730 reiserfs_write_lock(inode->i_sb);
42731
42732 reiserfs_check_lock_depth(inode->i_sb, "readdir");
42733diff -urNp linux-2.6.32.41/fs/reiserfs/do_balan.c linux-2.6.32.41/fs/reiserfs/do_balan.c
42734--- linux-2.6.32.41/fs/reiserfs/do_balan.c 2011-03-27 14:31:47.000000000 -0400
42735+++ linux-2.6.32.41/fs/reiserfs/do_balan.c 2011-04-17 15:56:46.000000000 -0400
42736@@ -2058,7 +2058,7 @@ void do_balance(struct tree_balance *tb,
42737 return;
42738 }
42739
42740- atomic_inc(&(fs_generation(tb->tb_sb)));
42741+ atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
42742 do_balance_starts(tb);
42743
42744 /* balance leaf returns 0 except if combining L R and S into
42745diff -urNp linux-2.6.32.41/fs/reiserfs/item_ops.c linux-2.6.32.41/fs/reiserfs/item_ops.c
42746--- linux-2.6.32.41/fs/reiserfs/item_ops.c 2011-03-27 14:31:47.000000000 -0400
42747+++ linux-2.6.32.41/fs/reiserfs/item_ops.c 2011-04-17 15:56:46.000000000 -0400
42748@@ -102,7 +102,7 @@ static void sd_print_vi(struct virtual_i
42749 vi->vi_index, vi->vi_type, vi->vi_ih);
42750 }
42751
42752-static struct item_operations stat_data_ops = {
42753+static const struct item_operations stat_data_ops = {
42754 .bytes_number = sd_bytes_number,
42755 .decrement_key = sd_decrement_key,
42756 .is_left_mergeable = sd_is_left_mergeable,
42757@@ -196,7 +196,7 @@ static void direct_print_vi(struct virtu
42758 vi->vi_index, vi->vi_type, vi->vi_ih);
42759 }
42760
42761-static struct item_operations direct_ops = {
42762+static const struct item_operations direct_ops = {
42763 .bytes_number = direct_bytes_number,
42764 .decrement_key = direct_decrement_key,
42765 .is_left_mergeable = direct_is_left_mergeable,
42766@@ -341,7 +341,7 @@ static void indirect_print_vi(struct vir
42767 vi->vi_index, vi->vi_type, vi->vi_ih);
42768 }
42769
42770-static struct item_operations indirect_ops = {
42771+static const struct item_operations indirect_ops = {
42772 .bytes_number = indirect_bytes_number,
42773 .decrement_key = indirect_decrement_key,
42774 .is_left_mergeable = indirect_is_left_mergeable,
42775@@ -628,7 +628,7 @@ static void direntry_print_vi(struct vir
42776 printk("\n");
42777 }
42778
42779-static struct item_operations direntry_ops = {
42780+static const struct item_operations direntry_ops = {
42781 .bytes_number = direntry_bytes_number,
42782 .decrement_key = direntry_decrement_key,
42783 .is_left_mergeable = direntry_is_left_mergeable,
42784@@ -724,7 +724,7 @@ static void errcatch_print_vi(struct vir
42785 "Invalid item type observed, run fsck ASAP");
42786 }
42787
42788-static struct item_operations errcatch_ops = {
42789+static const struct item_operations errcatch_ops = {
42790 errcatch_bytes_number,
42791 errcatch_decrement_key,
42792 errcatch_is_left_mergeable,
42793@@ -746,7 +746,7 @@ static struct item_operations errcatch_o
42794 #error Item types must use disk-format assigned values.
42795 #endif
42796
42797-struct item_operations *item_ops[TYPE_ANY + 1] = {
42798+const struct item_operations * const item_ops[TYPE_ANY + 1] = {
42799 &stat_data_ops,
42800 &indirect_ops,
42801 &direct_ops,
42802diff -urNp linux-2.6.32.41/fs/reiserfs/journal.c linux-2.6.32.41/fs/reiserfs/journal.c
42803--- linux-2.6.32.41/fs/reiserfs/journal.c 2011-03-27 14:31:47.000000000 -0400
42804+++ linux-2.6.32.41/fs/reiserfs/journal.c 2011-05-16 21:46:57.000000000 -0400
42805@@ -2329,6 +2329,8 @@ static struct buffer_head *reiserfs_brea
42806 struct buffer_head *bh;
42807 int i, j;
42808
42809+ pax_track_stack();
42810+
42811 bh = __getblk(dev, block, bufsize);
42812 if (buffer_uptodate(bh))
42813 return (bh);
42814diff -urNp linux-2.6.32.41/fs/reiserfs/namei.c linux-2.6.32.41/fs/reiserfs/namei.c
42815--- linux-2.6.32.41/fs/reiserfs/namei.c 2011-03-27 14:31:47.000000000 -0400
42816+++ linux-2.6.32.41/fs/reiserfs/namei.c 2011-05-16 21:46:57.000000000 -0400
42817@@ -1214,6 +1214,8 @@ static int reiserfs_rename(struct inode
42818 unsigned long savelink = 1;
42819 struct timespec ctime;
42820
42821+ pax_track_stack();
42822+
42823 /* three balancings: (1) old name removal, (2) new name insertion
42824 and (3) maybe "save" link insertion
42825 stat data updates: (1) old directory,
42826diff -urNp linux-2.6.32.41/fs/reiserfs/procfs.c linux-2.6.32.41/fs/reiserfs/procfs.c
42827--- linux-2.6.32.41/fs/reiserfs/procfs.c 2011-03-27 14:31:47.000000000 -0400
42828+++ linux-2.6.32.41/fs/reiserfs/procfs.c 2011-05-16 21:46:57.000000000 -0400
42829@@ -123,7 +123,7 @@ static int show_super(struct seq_file *m
42830 "SMALL_TAILS " : "NO_TAILS ",
42831 replay_only(sb) ? "REPLAY_ONLY " : "",
42832 convert_reiserfs(sb) ? "CONV " : "",
42833- atomic_read(&r->s_generation_counter),
42834+ atomic_read_unchecked(&r->s_generation_counter),
42835 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
42836 SF(s_do_balance), SF(s_unneeded_left_neighbor),
42837 SF(s_good_search_by_key_reada), SF(s_bmaps),
42838@@ -309,6 +309,8 @@ static int show_journal(struct seq_file
42839 struct journal_params *jp = &rs->s_v1.s_journal;
42840 char b[BDEVNAME_SIZE];
42841
42842+ pax_track_stack();
42843+
42844 seq_printf(m, /* on-disk fields */
42845 "jp_journal_1st_block: \t%i\n"
42846 "jp_journal_dev: \t%s[%x]\n"
42847diff -urNp linux-2.6.32.41/fs/reiserfs/stree.c linux-2.6.32.41/fs/reiserfs/stree.c
42848--- linux-2.6.32.41/fs/reiserfs/stree.c 2011-03-27 14:31:47.000000000 -0400
42849+++ linux-2.6.32.41/fs/reiserfs/stree.c 2011-05-16 21:46:57.000000000 -0400
42850@@ -1159,6 +1159,8 @@ int reiserfs_delete_item(struct reiserfs
42851 int iter = 0;
42852 #endif
42853
42854+ pax_track_stack();
42855+
42856 BUG_ON(!th->t_trans_id);
42857
42858 init_tb_struct(th, &s_del_balance, sb, path,
42859@@ -1296,6 +1298,8 @@ void reiserfs_delete_solid_item(struct r
42860 int retval;
42861 int quota_cut_bytes = 0;
42862
42863+ pax_track_stack();
42864+
42865 BUG_ON(!th->t_trans_id);
42866
42867 le_key2cpu_key(&cpu_key, key);
42868@@ -1525,6 +1529,8 @@ int reiserfs_cut_from_item(struct reiser
42869 int quota_cut_bytes;
42870 loff_t tail_pos = 0;
42871
42872+ pax_track_stack();
42873+
42874 BUG_ON(!th->t_trans_id);
42875
42876 init_tb_struct(th, &s_cut_balance, inode->i_sb, path,
42877@@ -1920,6 +1926,8 @@ int reiserfs_paste_into_item(struct reis
42878 int retval;
42879 int fs_gen;
42880
42881+ pax_track_stack();
42882+
42883 BUG_ON(!th->t_trans_id);
42884
42885 fs_gen = get_generation(inode->i_sb);
42886@@ -2007,6 +2015,8 @@ int reiserfs_insert_item(struct reiserfs
42887 int fs_gen = 0;
42888 int quota_bytes = 0;
42889
42890+ pax_track_stack();
42891+
42892 BUG_ON(!th->t_trans_id);
42893
42894 if (inode) { /* Do we count quotas for item? */
42895diff -urNp linux-2.6.32.41/fs/reiserfs/super.c linux-2.6.32.41/fs/reiserfs/super.c
42896--- linux-2.6.32.41/fs/reiserfs/super.c 2011-03-27 14:31:47.000000000 -0400
42897+++ linux-2.6.32.41/fs/reiserfs/super.c 2011-05-16 21:46:57.000000000 -0400
42898@@ -912,6 +912,8 @@ static int reiserfs_parse_options(struct
42899 {.option_name = NULL}
42900 };
42901
42902+ pax_track_stack();
42903+
42904 *blocks = 0;
42905 if (!options || !*options)
42906 /* use default configuration: create tails, journaling on, no
42907diff -urNp linux-2.6.32.41/fs/select.c linux-2.6.32.41/fs/select.c
42908--- linux-2.6.32.41/fs/select.c 2011-03-27 14:31:47.000000000 -0400
42909+++ linux-2.6.32.41/fs/select.c 2011-05-16 21:46:57.000000000 -0400
42910@@ -20,6 +20,7 @@
42911 #include <linux/module.h>
42912 #include <linux/slab.h>
42913 #include <linux/poll.h>
42914+#include <linux/security.h>
42915 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
42916 #include <linux/file.h>
42917 #include <linux/fdtable.h>
42918@@ -401,6 +402,8 @@ int do_select(int n, fd_set_bits *fds, s
42919 int retval, i, timed_out = 0;
42920 unsigned long slack = 0;
42921
42922+ pax_track_stack();
42923+
42924 rcu_read_lock();
42925 retval = max_select_fd(n, fds);
42926 rcu_read_unlock();
42927@@ -529,6 +532,8 @@ int core_sys_select(int n, fd_set __user
42928 /* Allocate small arguments on the stack to save memory and be faster */
42929 long stack_fds[SELECT_STACK_ALLOC/sizeof(long)];
42930
42931+ pax_track_stack();
42932+
42933 ret = -EINVAL;
42934 if (n < 0)
42935 goto out_nofds;
42936@@ -821,6 +826,9 @@ int do_sys_poll(struct pollfd __user *uf
42937 struct poll_list *walk = head;
42938 unsigned long todo = nfds;
42939
42940+ pax_track_stack();
42941+
42942+ gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
42943 if (nfds > current->signal->rlim[RLIMIT_NOFILE].rlim_cur)
42944 return -EINVAL;
42945
42946diff -urNp linux-2.6.32.41/fs/seq_file.c linux-2.6.32.41/fs/seq_file.c
42947--- linux-2.6.32.41/fs/seq_file.c 2011-03-27 14:31:47.000000000 -0400
42948+++ linux-2.6.32.41/fs/seq_file.c 2011-04-17 15:56:46.000000000 -0400
42949@@ -76,7 +76,8 @@ static int traverse(struct seq_file *m,
42950 return 0;
42951 }
42952 if (!m->buf) {
42953- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
42954+ m->size = PAGE_SIZE;
42955+ m->buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
42956 if (!m->buf)
42957 return -ENOMEM;
42958 }
42959@@ -116,7 +117,8 @@ static int traverse(struct seq_file *m,
42960 Eoverflow:
42961 m->op->stop(m, p);
42962 kfree(m->buf);
42963- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
42964+ m->size <<= 1;
42965+ m->buf = kmalloc(m->size, GFP_KERNEL);
42966 return !m->buf ? -ENOMEM : -EAGAIN;
42967 }
42968
42969@@ -169,7 +171,8 @@ ssize_t seq_read(struct file *file, char
42970 m->version = file->f_version;
42971 /* grab buffer if we didn't have one */
42972 if (!m->buf) {
42973- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
42974+ m->size = PAGE_SIZE;
42975+ m->buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
42976 if (!m->buf)
42977 goto Enomem;
42978 }
42979@@ -210,7 +213,8 @@ ssize_t seq_read(struct file *file, char
42980 goto Fill;
42981 m->op->stop(m, p);
42982 kfree(m->buf);
42983- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
42984+ m->size <<= 1;
42985+ m->buf = kmalloc(m->size, GFP_KERNEL);
42986 if (!m->buf)
42987 goto Enomem;
42988 m->count = 0;
42989diff -urNp linux-2.6.32.41/fs/smbfs/symlink.c linux-2.6.32.41/fs/smbfs/symlink.c
42990--- linux-2.6.32.41/fs/smbfs/symlink.c 2011-03-27 14:31:47.000000000 -0400
42991+++ linux-2.6.32.41/fs/smbfs/symlink.c 2011-04-17 15:56:46.000000000 -0400
42992@@ -55,7 +55,7 @@ static void *smb_follow_link(struct dent
42993
42994 static void smb_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
42995 {
42996- char *s = nd_get_link(nd);
42997+ const char *s = nd_get_link(nd);
42998 if (!IS_ERR(s))
42999 __putname(s);
43000 }
43001diff -urNp linux-2.6.32.41/fs/splice.c linux-2.6.32.41/fs/splice.c
43002--- linux-2.6.32.41/fs/splice.c 2011-03-27 14:31:47.000000000 -0400
43003+++ linux-2.6.32.41/fs/splice.c 2011-05-16 21:46:57.000000000 -0400
43004@@ -185,7 +185,7 @@ ssize_t splice_to_pipe(struct pipe_inode
43005 pipe_lock(pipe);
43006
43007 for (;;) {
43008- if (!pipe->readers) {
43009+ if (!atomic_read(&pipe->readers)) {
43010 send_sig(SIGPIPE, current, 0);
43011 if (!ret)
43012 ret = -EPIPE;
43013@@ -239,9 +239,9 @@ ssize_t splice_to_pipe(struct pipe_inode
43014 do_wakeup = 0;
43015 }
43016
43017- pipe->waiting_writers++;
43018+ atomic_inc(&pipe->waiting_writers);
43019 pipe_wait(pipe);
43020- pipe->waiting_writers--;
43021+ atomic_dec(&pipe->waiting_writers);
43022 }
43023
43024 pipe_unlock(pipe);
43025@@ -285,6 +285,8 @@ __generic_file_splice_read(struct file *
43026 .spd_release = spd_release_page,
43027 };
43028
43029+ pax_track_stack();
43030+
43031 index = *ppos >> PAGE_CACHE_SHIFT;
43032 loff = *ppos & ~PAGE_CACHE_MASK;
43033 req_pages = (len + loff + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
43034@@ -521,7 +523,7 @@ static ssize_t kernel_readv(struct file
43035 old_fs = get_fs();
43036 set_fs(get_ds());
43037 /* The cast to a user pointer is valid due to the set_fs() */
43038- res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
43039+ res = vfs_readv(file, (__force const struct iovec __user *)vec, vlen, &pos);
43040 set_fs(old_fs);
43041
43042 return res;
43043@@ -536,7 +538,7 @@ static ssize_t kernel_write(struct file
43044 old_fs = get_fs();
43045 set_fs(get_ds());
43046 /* The cast to a user pointer is valid due to the set_fs() */
43047- res = vfs_write(file, (const char __user *)buf, count, &pos);
43048+ res = vfs_write(file, (__force const char __user *)buf, count, &pos);
43049 set_fs(old_fs);
43050
43051 return res;
43052@@ -565,6 +567,8 @@ ssize_t default_file_splice_read(struct
43053 .spd_release = spd_release_page,
43054 };
43055
43056+ pax_track_stack();
43057+
43058 index = *ppos >> PAGE_CACHE_SHIFT;
43059 offset = *ppos & ~PAGE_CACHE_MASK;
43060 nr_pages = (len + offset + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
43061@@ -578,7 +582,7 @@ ssize_t default_file_splice_read(struct
43062 goto err;
43063
43064 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
43065- vec[i].iov_base = (void __user *) page_address(page);
43066+ vec[i].iov_base = (__force void __user *) page_address(page);
43067 vec[i].iov_len = this_len;
43068 pages[i] = page;
43069 spd.nr_pages++;
43070@@ -800,10 +804,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
43071 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
43072 {
43073 while (!pipe->nrbufs) {
43074- if (!pipe->writers)
43075+ if (!atomic_read(&pipe->writers))
43076 return 0;
43077
43078- if (!pipe->waiting_writers && sd->num_spliced)
43079+ if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
43080 return 0;
43081
43082 if (sd->flags & SPLICE_F_NONBLOCK)
43083@@ -1140,7 +1144,7 @@ ssize_t splice_direct_to_actor(struct fi
43084 * out of the pipe right after the splice_to_pipe(). So set
43085 * PIPE_READERS appropriately.
43086 */
43087- pipe->readers = 1;
43088+ atomic_set(&pipe->readers, 1);
43089
43090 current->splice_pipe = pipe;
43091 }
43092@@ -1592,6 +1596,8 @@ static long vmsplice_to_pipe(struct file
43093 .spd_release = spd_release_page,
43094 };
43095
43096+ pax_track_stack();
43097+
43098 pipe = pipe_info(file->f_path.dentry->d_inode);
43099 if (!pipe)
43100 return -EBADF;
43101@@ -1700,9 +1706,9 @@ static int ipipe_prep(struct pipe_inode_
43102 ret = -ERESTARTSYS;
43103 break;
43104 }
43105- if (!pipe->writers)
43106+ if (!atomic_read(&pipe->writers))
43107 break;
43108- if (!pipe->waiting_writers) {
43109+ if (!atomic_read(&pipe->waiting_writers)) {
43110 if (flags & SPLICE_F_NONBLOCK) {
43111 ret = -EAGAIN;
43112 break;
43113@@ -1734,7 +1740,7 @@ static int opipe_prep(struct pipe_inode_
43114 pipe_lock(pipe);
43115
43116 while (pipe->nrbufs >= PIPE_BUFFERS) {
43117- if (!pipe->readers) {
43118+ if (!atomic_read(&pipe->readers)) {
43119 send_sig(SIGPIPE, current, 0);
43120 ret = -EPIPE;
43121 break;
43122@@ -1747,9 +1753,9 @@ static int opipe_prep(struct pipe_inode_
43123 ret = -ERESTARTSYS;
43124 break;
43125 }
43126- pipe->waiting_writers++;
43127+ atomic_inc(&pipe->waiting_writers);
43128 pipe_wait(pipe);
43129- pipe->waiting_writers--;
43130+ atomic_dec(&pipe->waiting_writers);
43131 }
43132
43133 pipe_unlock(pipe);
43134@@ -1785,14 +1791,14 @@ retry:
43135 pipe_double_lock(ipipe, opipe);
43136
43137 do {
43138- if (!opipe->readers) {
43139+ if (!atomic_read(&opipe->readers)) {
43140 send_sig(SIGPIPE, current, 0);
43141 if (!ret)
43142 ret = -EPIPE;
43143 break;
43144 }
43145
43146- if (!ipipe->nrbufs && !ipipe->writers)
43147+ if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
43148 break;
43149
43150 /*
43151@@ -1892,7 +1898,7 @@ static int link_pipe(struct pipe_inode_i
43152 pipe_double_lock(ipipe, opipe);
43153
43154 do {
43155- if (!opipe->readers) {
43156+ if (!atomic_read(&opipe->readers)) {
43157 send_sig(SIGPIPE, current, 0);
43158 if (!ret)
43159 ret = -EPIPE;
43160@@ -1937,7 +1943,7 @@ static int link_pipe(struct pipe_inode_i
43161 * return EAGAIN if we have the potential of some data in the
43162 * future, otherwise just return 0
43163 */
43164- if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
43165+ if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
43166 ret = -EAGAIN;
43167
43168 pipe_unlock(ipipe);
43169diff -urNp linux-2.6.32.41/fs/sysfs/file.c linux-2.6.32.41/fs/sysfs/file.c
43170--- linux-2.6.32.41/fs/sysfs/file.c 2011-03-27 14:31:47.000000000 -0400
43171+++ linux-2.6.32.41/fs/sysfs/file.c 2011-05-04 17:56:20.000000000 -0400
43172@@ -44,7 +44,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent
43173
43174 struct sysfs_open_dirent {
43175 atomic_t refcnt;
43176- atomic_t event;
43177+ atomic_unchecked_t event;
43178 wait_queue_head_t poll;
43179 struct list_head buffers; /* goes through sysfs_buffer.list */
43180 };
43181@@ -53,7 +53,7 @@ struct sysfs_buffer {
43182 size_t count;
43183 loff_t pos;
43184 char * page;
43185- struct sysfs_ops * ops;
43186+ const struct sysfs_ops * ops;
43187 struct mutex mutex;
43188 int needs_read_fill;
43189 int event;
43190@@ -75,7 +75,7 @@ static int fill_read_buffer(struct dentr
43191 {
43192 struct sysfs_dirent *attr_sd = dentry->d_fsdata;
43193 struct kobject *kobj = attr_sd->s_parent->s_dir.kobj;
43194- struct sysfs_ops * ops = buffer->ops;
43195+ const struct sysfs_ops * ops = buffer->ops;
43196 int ret = 0;
43197 ssize_t count;
43198
43199@@ -88,7 +88,7 @@ static int fill_read_buffer(struct dentr
43200 if (!sysfs_get_active_two(attr_sd))
43201 return -ENODEV;
43202
43203- buffer->event = atomic_read(&attr_sd->s_attr.open->event);
43204+ buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
43205 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
43206
43207 sysfs_put_active_two(attr_sd);
43208@@ -199,7 +199,7 @@ flush_write_buffer(struct dentry * dentr
43209 {
43210 struct sysfs_dirent *attr_sd = dentry->d_fsdata;
43211 struct kobject *kobj = attr_sd->s_parent->s_dir.kobj;
43212- struct sysfs_ops * ops = buffer->ops;
43213+ const struct sysfs_ops * ops = buffer->ops;
43214 int rc;
43215
43216 /* need attr_sd for attr and ops, its parent for kobj */
43217@@ -294,7 +294,7 @@ static int sysfs_get_open_dirent(struct
43218 return -ENOMEM;
43219
43220 atomic_set(&new_od->refcnt, 0);
43221- atomic_set(&new_od->event, 1);
43222+ atomic_set_unchecked(&new_od->event, 1);
43223 init_waitqueue_head(&new_od->poll);
43224 INIT_LIST_HEAD(&new_od->buffers);
43225 goto retry;
43226@@ -335,7 +335,7 @@ static int sysfs_open_file(struct inode
43227 struct sysfs_dirent *attr_sd = file->f_path.dentry->d_fsdata;
43228 struct kobject *kobj = attr_sd->s_parent->s_dir.kobj;
43229 struct sysfs_buffer *buffer;
43230- struct sysfs_ops *ops;
43231+ const struct sysfs_ops *ops;
43232 int error = -EACCES;
43233 char *p;
43234
43235@@ -444,7 +444,7 @@ static unsigned int sysfs_poll(struct fi
43236
43237 sysfs_put_active_two(attr_sd);
43238
43239- if (buffer->event != atomic_read(&od->event))
43240+ if (buffer->event != atomic_read_unchecked(&od->event))
43241 goto trigger;
43242
43243 return DEFAULT_POLLMASK;
43244@@ -463,7 +463,7 @@ void sysfs_notify_dirent(struct sysfs_di
43245
43246 od = sd->s_attr.open;
43247 if (od) {
43248- atomic_inc(&od->event);
43249+ atomic_inc_unchecked(&od->event);
43250 wake_up_interruptible(&od->poll);
43251 }
43252
43253diff -urNp linux-2.6.32.41/fs/sysfs/mount.c linux-2.6.32.41/fs/sysfs/mount.c
43254--- linux-2.6.32.41/fs/sysfs/mount.c 2011-03-27 14:31:47.000000000 -0400
43255+++ linux-2.6.32.41/fs/sysfs/mount.c 2011-04-17 15:56:46.000000000 -0400
43256@@ -36,7 +36,11 @@ struct sysfs_dirent sysfs_root = {
43257 .s_name = "",
43258 .s_count = ATOMIC_INIT(1),
43259 .s_flags = SYSFS_DIR,
43260+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
43261+ .s_mode = S_IFDIR | S_IRWXU,
43262+#else
43263 .s_mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
43264+#endif
43265 .s_ino = 1,
43266 };
43267
43268diff -urNp linux-2.6.32.41/fs/sysfs/symlink.c linux-2.6.32.41/fs/sysfs/symlink.c
43269--- linux-2.6.32.41/fs/sysfs/symlink.c 2011-03-27 14:31:47.000000000 -0400
43270+++ linux-2.6.32.41/fs/sysfs/symlink.c 2011-04-17 15:56:46.000000000 -0400
43271@@ -204,7 +204,7 @@ static void *sysfs_follow_link(struct de
43272
43273 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
43274 {
43275- char *page = nd_get_link(nd);
43276+ const char *page = nd_get_link(nd);
43277 if (!IS_ERR(page))
43278 free_page((unsigned long)page);
43279 }
43280diff -urNp linux-2.6.32.41/fs/udf/balloc.c linux-2.6.32.41/fs/udf/balloc.c
43281--- linux-2.6.32.41/fs/udf/balloc.c 2011-03-27 14:31:47.000000000 -0400
43282+++ linux-2.6.32.41/fs/udf/balloc.c 2011-04-17 15:56:46.000000000 -0400
43283@@ -172,9 +172,7 @@ static void udf_bitmap_free_blocks(struc
43284
43285 mutex_lock(&sbi->s_alloc_mutex);
43286 partmap = &sbi->s_partmaps[bloc->partitionReferenceNum];
43287- if (bloc->logicalBlockNum < 0 ||
43288- (bloc->logicalBlockNum + count) >
43289- partmap->s_partition_len) {
43290+ if ((bloc->logicalBlockNum + count) > partmap->s_partition_len) {
43291 udf_debug("%d < %d || %d + %d > %d\n",
43292 bloc->logicalBlockNum, 0, bloc->logicalBlockNum,
43293 count, partmap->s_partition_len);
43294@@ -436,9 +434,7 @@ static void udf_table_free_blocks(struct
43295
43296 mutex_lock(&sbi->s_alloc_mutex);
43297 partmap = &sbi->s_partmaps[bloc->partitionReferenceNum];
43298- if (bloc->logicalBlockNum < 0 ||
43299- (bloc->logicalBlockNum + count) >
43300- partmap->s_partition_len) {
43301+ if ((bloc->logicalBlockNum + count) > partmap->s_partition_len) {
43302 udf_debug("%d < %d || %d + %d > %d\n",
43303 bloc.logicalBlockNum, 0, bloc.logicalBlockNum, count,
43304 partmap->s_partition_len);
43305diff -urNp linux-2.6.32.41/fs/udf/inode.c linux-2.6.32.41/fs/udf/inode.c
43306--- linux-2.6.32.41/fs/udf/inode.c 2011-03-27 14:31:47.000000000 -0400
43307+++ linux-2.6.32.41/fs/udf/inode.c 2011-05-16 21:46:57.000000000 -0400
43308@@ -484,6 +484,8 @@ static struct buffer_head *inode_getblk(
43309 int goal = 0, pgoal = iinfo->i_location.logicalBlockNum;
43310 int lastblock = 0;
43311
43312+ pax_track_stack();
43313+
43314 prev_epos.offset = udf_file_entry_alloc_offset(inode);
43315 prev_epos.block = iinfo->i_location;
43316 prev_epos.bh = NULL;
43317diff -urNp linux-2.6.32.41/fs/udf/misc.c linux-2.6.32.41/fs/udf/misc.c
43318--- linux-2.6.32.41/fs/udf/misc.c 2011-03-27 14:31:47.000000000 -0400
43319+++ linux-2.6.32.41/fs/udf/misc.c 2011-04-23 12:56:11.000000000 -0400
43320@@ -286,7 +286,7 @@ void udf_new_tag(char *data, uint16_t id
43321
43322 u8 udf_tag_checksum(const struct tag *t)
43323 {
43324- u8 *data = (u8 *)t;
43325+ const u8 *data = (const u8 *)t;
43326 u8 checksum = 0;
43327 int i;
43328 for (i = 0; i < sizeof(struct tag); ++i)
43329diff -urNp linux-2.6.32.41/fs/utimes.c linux-2.6.32.41/fs/utimes.c
43330--- linux-2.6.32.41/fs/utimes.c 2011-03-27 14:31:47.000000000 -0400
43331+++ linux-2.6.32.41/fs/utimes.c 2011-04-17 15:56:46.000000000 -0400
43332@@ -1,6 +1,7 @@
43333 #include <linux/compiler.h>
43334 #include <linux/file.h>
43335 #include <linux/fs.h>
43336+#include <linux/security.h>
43337 #include <linux/linkage.h>
43338 #include <linux/mount.h>
43339 #include <linux/namei.h>
43340@@ -101,6 +102,12 @@ static int utimes_common(struct path *pa
43341 goto mnt_drop_write_and_out;
43342 }
43343 }
43344+
43345+ if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
43346+ error = -EACCES;
43347+ goto mnt_drop_write_and_out;
43348+ }
43349+
43350 mutex_lock(&inode->i_mutex);
43351 error = notify_change(path->dentry, &newattrs);
43352 mutex_unlock(&inode->i_mutex);
43353diff -urNp linux-2.6.32.41/fs/xattr_acl.c linux-2.6.32.41/fs/xattr_acl.c
43354--- linux-2.6.32.41/fs/xattr_acl.c 2011-03-27 14:31:47.000000000 -0400
43355+++ linux-2.6.32.41/fs/xattr_acl.c 2011-04-17 15:56:46.000000000 -0400
43356@@ -17,8 +17,8 @@
43357 struct posix_acl *
43358 posix_acl_from_xattr(const void *value, size_t size)
43359 {
43360- posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
43361- posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
43362+ const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
43363+ const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
43364 int count;
43365 struct posix_acl *acl;
43366 struct posix_acl_entry *acl_e;
43367diff -urNp linux-2.6.32.41/fs/xattr.c linux-2.6.32.41/fs/xattr.c
43368--- linux-2.6.32.41/fs/xattr.c 2011-03-27 14:31:47.000000000 -0400
43369+++ linux-2.6.32.41/fs/xattr.c 2011-04-17 15:56:46.000000000 -0400
43370@@ -247,7 +247,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
43371 * Extended attribute SET operations
43372 */
43373 static long
43374-setxattr(struct dentry *d, const char __user *name, const void __user *value,
43375+setxattr(struct path *path, const char __user *name, const void __user *value,
43376 size_t size, int flags)
43377 {
43378 int error;
43379@@ -271,7 +271,13 @@ setxattr(struct dentry *d, const char __
43380 return PTR_ERR(kvalue);
43381 }
43382
43383- error = vfs_setxattr(d, kname, kvalue, size, flags);
43384+ if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
43385+ error = -EACCES;
43386+ goto out;
43387+ }
43388+
43389+ error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
43390+out:
43391 kfree(kvalue);
43392 return error;
43393 }
43394@@ -288,7 +294,7 @@ SYSCALL_DEFINE5(setxattr, const char __u
43395 return error;
43396 error = mnt_want_write(path.mnt);
43397 if (!error) {
43398- error = setxattr(path.dentry, name, value, size, flags);
43399+ error = setxattr(&path, name, value, size, flags);
43400 mnt_drop_write(path.mnt);
43401 }
43402 path_put(&path);
43403@@ -307,7 +313,7 @@ SYSCALL_DEFINE5(lsetxattr, const char __
43404 return error;
43405 error = mnt_want_write(path.mnt);
43406 if (!error) {
43407- error = setxattr(path.dentry, name, value, size, flags);
43408+ error = setxattr(&path, name, value, size, flags);
43409 mnt_drop_write(path.mnt);
43410 }
43411 path_put(&path);
43412@@ -318,17 +324,15 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, cons
43413 const void __user *,value, size_t, size, int, flags)
43414 {
43415 struct file *f;
43416- struct dentry *dentry;
43417 int error = -EBADF;
43418
43419 f = fget(fd);
43420 if (!f)
43421 return error;
43422- dentry = f->f_path.dentry;
43423- audit_inode(NULL, dentry);
43424+ audit_inode(NULL, f->f_path.dentry);
43425 error = mnt_want_write_file(f);
43426 if (!error) {
43427- error = setxattr(dentry, name, value, size, flags);
43428+ error = setxattr(&f->f_path, name, value, size, flags);
43429 mnt_drop_write(f->f_path.mnt);
43430 }
43431 fput(f);
43432diff -urNp linux-2.6.32.41/fs/xfs/linux-2.6/xfs_ioctl32.c linux-2.6.32.41/fs/xfs/linux-2.6/xfs_ioctl32.c
43433--- linux-2.6.32.41/fs/xfs/linux-2.6/xfs_ioctl32.c 2011-03-27 14:31:47.000000000 -0400
43434+++ linux-2.6.32.41/fs/xfs/linux-2.6/xfs_ioctl32.c 2011-04-17 15:56:46.000000000 -0400
43435@@ -75,6 +75,7 @@ xfs_compat_ioc_fsgeometry_v1(
43436 xfs_fsop_geom_t fsgeo;
43437 int error;
43438
43439+ memset(&fsgeo, 0, sizeof(fsgeo));
43440 error = xfs_fs_geometry(mp, &fsgeo, 3);
43441 if (error)
43442 return -error;
43443diff -urNp linux-2.6.32.41/fs/xfs/linux-2.6/xfs_ioctl.c linux-2.6.32.41/fs/xfs/linux-2.6/xfs_ioctl.c
43444--- linux-2.6.32.41/fs/xfs/linux-2.6/xfs_ioctl.c 2011-04-17 17:00:52.000000000 -0400
43445+++ linux-2.6.32.41/fs/xfs/linux-2.6/xfs_ioctl.c 2011-04-17 20:07:09.000000000 -0400
43446@@ -134,7 +134,7 @@ xfs_find_handle(
43447 }
43448
43449 error = -EFAULT;
43450- if (copy_to_user(hreq->ohandle, &handle, hsize) ||
43451+ if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
43452 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
43453 goto out_put;
43454
43455@@ -423,7 +423,7 @@ xfs_attrlist_by_handle(
43456 if (IS_ERR(dentry))
43457 return PTR_ERR(dentry);
43458
43459- kbuf = kmalloc(al_hreq.buflen, GFP_KERNEL);
43460+ kbuf = kzalloc(al_hreq.buflen, GFP_KERNEL);
43461 if (!kbuf)
43462 goto out_dput;
43463
43464@@ -697,7 +697,7 @@ xfs_ioc_fsgeometry_v1(
43465 xfs_mount_t *mp,
43466 void __user *arg)
43467 {
43468- xfs_fsop_geom_t fsgeo;
43469+ xfs_fsop_geom_t fsgeo;
43470 int error;
43471
43472 error = xfs_fs_geometry(mp, &fsgeo, 3);
43473diff -urNp linux-2.6.32.41/fs/xfs/linux-2.6/xfs_iops.c linux-2.6.32.41/fs/xfs/linux-2.6/xfs_iops.c
43474--- linux-2.6.32.41/fs/xfs/linux-2.6/xfs_iops.c 2011-03-27 14:31:47.000000000 -0400
43475+++ linux-2.6.32.41/fs/xfs/linux-2.6/xfs_iops.c 2011-04-17 15:56:46.000000000 -0400
43476@@ -468,7 +468,7 @@ xfs_vn_put_link(
43477 struct nameidata *nd,
43478 void *p)
43479 {
43480- char *s = nd_get_link(nd);
43481+ const char *s = nd_get_link(nd);
43482
43483 if (!IS_ERR(s))
43484 kfree(s);
43485diff -urNp linux-2.6.32.41/fs/xfs/xfs_bmap.c linux-2.6.32.41/fs/xfs/xfs_bmap.c
43486--- linux-2.6.32.41/fs/xfs/xfs_bmap.c 2011-03-27 14:31:47.000000000 -0400
43487+++ linux-2.6.32.41/fs/xfs/xfs_bmap.c 2011-04-17 15:56:46.000000000 -0400
43488@@ -360,7 +360,7 @@ xfs_bmap_validate_ret(
43489 int nmap,
43490 int ret_nmap);
43491 #else
43492-#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
43493+#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
43494 #endif /* DEBUG */
43495
43496 #if defined(XFS_RW_TRACE)
43497diff -urNp linux-2.6.32.41/fs/xfs/xfs_dir2_sf.c linux-2.6.32.41/fs/xfs/xfs_dir2_sf.c
43498--- linux-2.6.32.41/fs/xfs/xfs_dir2_sf.c 2011-03-27 14:31:47.000000000 -0400
43499+++ linux-2.6.32.41/fs/xfs/xfs_dir2_sf.c 2011-04-18 22:07:30.000000000 -0400
43500@@ -779,7 +779,15 @@ xfs_dir2_sf_getdents(
43501 }
43502
43503 ino = xfs_dir2_sf_get_inumber(sfp, xfs_dir2_sf_inumberp(sfep));
43504- if (filldir(dirent, sfep->name, sfep->namelen,
43505+ if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
43506+ char name[sfep->namelen];
43507+ memcpy(name, sfep->name, sfep->namelen);
43508+ if (filldir(dirent, name, sfep->namelen,
43509+ off & 0x7fffffff, ino, DT_UNKNOWN)) {
43510+ *offset = off & 0x7fffffff;
43511+ return 0;
43512+ }
43513+ } else if (filldir(dirent, sfep->name, sfep->namelen,
43514 off & 0x7fffffff, ino, DT_UNKNOWN)) {
43515 *offset = off & 0x7fffffff;
43516 return 0;
43517diff -urNp linux-2.6.32.41/grsecurity/gracl_alloc.c linux-2.6.32.41/grsecurity/gracl_alloc.c
43518--- linux-2.6.32.41/grsecurity/gracl_alloc.c 1969-12-31 19:00:00.000000000 -0500
43519+++ linux-2.6.32.41/grsecurity/gracl_alloc.c 2011-04-17 15:56:46.000000000 -0400
43520@@ -0,0 +1,105 @@
43521+#include <linux/kernel.h>
43522+#include <linux/mm.h>
43523+#include <linux/slab.h>
43524+#include <linux/vmalloc.h>
43525+#include <linux/gracl.h>
43526+#include <linux/grsecurity.h>
43527+
43528+static unsigned long alloc_stack_next = 1;
43529+static unsigned long alloc_stack_size = 1;
43530+static void **alloc_stack;
43531+
43532+static __inline__ int
43533+alloc_pop(void)
43534+{
43535+ if (alloc_stack_next == 1)
43536+ return 0;
43537+
43538+ kfree(alloc_stack[alloc_stack_next - 2]);
43539+
43540+ alloc_stack_next--;
43541+
43542+ return 1;
43543+}
43544+
43545+static __inline__ int
43546+alloc_push(void *buf)
43547+{
43548+ if (alloc_stack_next >= alloc_stack_size)
43549+ return 1;
43550+
43551+ alloc_stack[alloc_stack_next - 1] = buf;
43552+
43553+ alloc_stack_next++;
43554+
43555+ return 0;
43556+}
43557+
43558+void *
43559+acl_alloc(unsigned long len)
43560+{
43561+ void *ret = NULL;
43562+
43563+ if (!len || len > PAGE_SIZE)
43564+ goto out;
43565+
43566+ ret = kmalloc(len, GFP_KERNEL);
43567+
43568+ if (ret) {
43569+ if (alloc_push(ret)) {
43570+ kfree(ret);
43571+ ret = NULL;
43572+ }
43573+ }
43574+
43575+out:
43576+ return ret;
43577+}
43578+
43579+void *
43580+acl_alloc_num(unsigned long num, unsigned long len)
43581+{
43582+ if (!len || (num > (PAGE_SIZE / len)))
43583+ return NULL;
43584+
43585+ return acl_alloc(num * len);
43586+}
43587+
43588+void
43589+acl_free_all(void)
43590+{
43591+ if (gr_acl_is_enabled() || !alloc_stack)
43592+ return;
43593+
43594+ while (alloc_pop()) ;
43595+
43596+ if (alloc_stack) {
43597+ if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
43598+ kfree(alloc_stack);
43599+ else
43600+ vfree(alloc_stack);
43601+ }
43602+
43603+ alloc_stack = NULL;
43604+ alloc_stack_size = 1;
43605+ alloc_stack_next = 1;
43606+
43607+ return;
43608+}
43609+
43610+int
43611+acl_alloc_stack_init(unsigned long size)
43612+{
43613+ if ((size * sizeof (void *)) <= PAGE_SIZE)
43614+ alloc_stack =
43615+ (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
43616+ else
43617+ alloc_stack = (void **) vmalloc(size * sizeof (void *));
43618+
43619+ alloc_stack_size = size;
43620+
43621+ if (!alloc_stack)
43622+ return 0;
43623+ else
43624+ return 1;
43625+}
43626diff -urNp linux-2.6.32.41/grsecurity/gracl.c linux-2.6.32.41/grsecurity/gracl.c
43627--- linux-2.6.32.41/grsecurity/gracl.c 1969-12-31 19:00:00.000000000 -0500
43628+++ linux-2.6.32.41/grsecurity/gracl.c 2011-05-24 20:26:07.000000000 -0400
43629@@ -0,0 +1,4079 @@
43630+#include <linux/kernel.h>
43631+#include <linux/module.h>
43632+#include <linux/sched.h>
43633+#include <linux/mm.h>
43634+#include <linux/file.h>
43635+#include <linux/fs.h>
43636+#include <linux/namei.h>
43637+#include <linux/mount.h>
43638+#include <linux/tty.h>
43639+#include <linux/proc_fs.h>
43640+#include <linux/smp_lock.h>
43641+#include <linux/slab.h>
43642+#include <linux/vmalloc.h>
43643+#include <linux/types.h>
43644+#include <linux/sysctl.h>
43645+#include <linux/netdevice.h>
43646+#include <linux/ptrace.h>
43647+#include <linux/gracl.h>
43648+#include <linux/gralloc.h>
43649+#include <linux/grsecurity.h>
43650+#include <linux/grinternal.h>
43651+#include <linux/pid_namespace.h>
43652+#include <linux/fdtable.h>
43653+#include <linux/percpu.h>
43654+
43655+#include <asm/uaccess.h>
43656+#include <asm/errno.h>
43657+#include <asm/mman.h>
43658+
43659+static struct acl_role_db acl_role_set;
43660+static struct name_db name_set;
43661+static struct inodev_db inodev_set;
43662+
43663+/* for keeping track of userspace pointers used for subjects, so we
43664+ can share references in the kernel as well
43665+*/
43666+
43667+static struct dentry *real_root;
43668+static struct vfsmount *real_root_mnt;
43669+
43670+static struct acl_subj_map_db subj_map_set;
43671+
43672+static struct acl_role_label *default_role;
43673+
43674+static struct acl_role_label *role_list;
43675+
43676+static u16 acl_sp_role_value;
43677+
43678+extern char *gr_shared_page[4];
43679+static DEFINE_MUTEX(gr_dev_mutex);
43680+DEFINE_RWLOCK(gr_inode_lock);
43681+
43682+struct gr_arg *gr_usermode;
43683+
43684+static unsigned int gr_status __read_only = GR_STATUS_INIT;
43685+
43686+extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
43687+extern void gr_clear_learn_entries(void);
43688+
43689+#ifdef CONFIG_GRKERNSEC_RESLOG
43690+extern void gr_log_resource(const struct task_struct *task,
43691+ const int res, const unsigned long wanted, const int gt);
43692+#endif
43693+
43694+unsigned char *gr_system_salt;
43695+unsigned char *gr_system_sum;
43696+
43697+static struct sprole_pw **acl_special_roles = NULL;
43698+static __u16 num_sprole_pws = 0;
43699+
43700+static struct acl_role_label *kernel_role = NULL;
43701+
43702+static unsigned int gr_auth_attempts = 0;
43703+static unsigned long gr_auth_expires = 0UL;
43704+
43705+#ifdef CONFIG_NET
43706+extern struct vfsmount *sock_mnt;
43707+#endif
43708+extern struct vfsmount *pipe_mnt;
43709+extern struct vfsmount *shm_mnt;
43710+#ifdef CONFIG_HUGETLBFS
43711+extern struct vfsmount *hugetlbfs_vfsmount;
43712+#endif
43713+
43714+static struct acl_object_label *fakefs_obj;
43715+
43716+extern int gr_init_uidset(void);
43717+extern void gr_free_uidset(void);
43718+extern void gr_remove_uid(uid_t uid);
43719+extern int gr_find_uid(uid_t uid);
43720+
43721+__inline__ int
43722+gr_acl_is_enabled(void)
43723+{
43724+ return (gr_status & GR_READY);
43725+}
43726+
43727+#ifdef CONFIG_BTRFS_FS
43728+extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
43729+extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
43730+#endif
43731+
43732+static inline dev_t __get_dev(const struct dentry *dentry)
43733+{
43734+#ifdef CONFIG_BTRFS_FS
43735+ if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
43736+ return get_btrfs_dev_from_inode(dentry->d_inode);
43737+ else
43738+#endif
43739+ return dentry->d_inode->i_sb->s_dev;
43740+}
43741+
43742+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
43743+{
43744+ return __get_dev(dentry);
43745+}
43746+
43747+static char gr_task_roletype_to_char(struct task_struct *task)
43748+{
43749+ switch (task->role->roletype &
43750+ (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
43751+ GR_ROLE_SPECIAL)) {
43752+ case GR_ROLE_DEFAULT:
43753+ return 'D';
43754+ case GR_ROLE_USER:
43755+ return 'U';
43756+ case GR_ROLE_GROUP:
43757+ return 'G';
43758+ case GR_ROLE_SPECIAL:
43759+ return 'S';
43760+ }
43761+
43762+ return 'X';
43763+}
43764+
43765+char gr_roletype_to_char(void)
43766+{
43767+ return gr_task_roletype_to_char(current);
43768+}
43769+
43770+__inline__ int
43771+gr_acl_tpe_check(void)
43772+{
43773+ if (unlikely(!(gr_status & GR_READY)))
43774+ return 0;
43775+ if (current->role->roletype & GR_ROLE_TPE)
43776+ return 1;
43777+ else
43778+ return 0;
43779+}
43780+
43781+int
43782+gr_handle_rawio(const struct inode *inode)
43783+{
43784+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
43785+ if (inode && S_ISBLK(inode->i_mode) &&
43786+ grsec_enable_chroot_caps && proc_is_chrooted(current) &&
43787+ !capable(CAP_SYS_RAWIO))
43788+ return 1;
43789+#endif
43790+ return 0;
43791+}
43792+
43793+static int
43794+gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
43795+{
43796+ if (likely(lena != lenb))
43797+ return 0;
43798+
43799+ return !memcmp(a, b, lena);
43800+}
43801+
43802+/* this must be called with vfsmount_lock and dcache_lock held */
43803+
43804+static char * __our_d_path(struct dentry *dentry, struct vfsmount *vfsmnt,
43805+ struct dentry *root, struct vfsmount *rootmnt,
43806+ char *buffer, int buflen)
43807+{
43808+ char * end = buffer+buflen;
43809+ char * retval;
43810+ int namelen;
43811+
43812+ *--end = '\0';
43813+ buflen--;
43814+
43815+ if (buflen < 1)
43816+ goto Elong;
43817+ /* Get '/' right */
43818+ retval = end-1;
43819+ *retval = '/';
43820+
43821+ for (;;) {
43822+ struct dentry * parent;
43823+
43824+ if (dentry == root && vfsmnt == rootmnt)
43825+ break;
43826+ if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
43827+ /* Global root? */
43828+ if (vfsmnt->mnt_parent == vfsmnt)
43829+ goto global_root;
43830+ dentry = vfsmnt->mnt_mountpoint;
43831+ vfsmnt = vfsmnt->mnt_parent;
43832+ continue;
43833+ }
43834+ parent = dentry->d_parent;
43835+ prefetch(parent);
43836+ namelen = dentry->d_name.len;
43837+ buflen -= namelen + 1;
43838+ if (buflen < 0)
43839+ goto Elong;
43840+ end -= namelen;
43841+ memcpy(end, dentry->d_name.name, namelen);
43842+ *--end = '/';
43843+ retval = end;
43844+ dentry = parent;
43845+ }
43846+
43847+out:
43848+ return retval;
43849+
43850+global_root:
43851+ namelen = dentry->d_name.len;
43852+ buflen -= namelen;
43853+ if (buflen < 0)
43854+ goto Elong;
43855+ retval -= namelen-1; /* hit the slash */
43856+ memcpy(retval, dentry->d_name.name, namelen);
43857+ goto out;
43858+Elong:
43859+ retval = ERR_PTR(-ENAMETOOLONG);
43860+ goto out;
43861+}
43862+
43863+static char *
43864+gen_full_path(struct dentry *dentry, struct vfsmount *vfsmnt,
43865+ struct dentry *root, struct vfsmount *rootmnt, char *buf, int buflen)
43866+{
43867+ char *retval;
43868+
43869+ retval = __our_d_path(dentry, vfsmnt, root, rootmnt, buf, buflen);
43870+ if (unlikely(IS_ERR(retval)))
43871+ retval = strcpy(buf, "<path too long>");
43872+ else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
43873+ retval[1] = '\0';
43874+
43875+ return retval;
43876+}
43877+
43878+static char *
43879+__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
43880+ char *buf, int buflen)
43881+{
43882+ char *res;
43883+
43884+ /* we can use real_root, real_root_mnt, because this is only called
43885+ by the RBAC system */
43886+ res = gen_full_path((struct dentry *)dentry, (struct vfsmount *)vfsmnt, real_root, real_root_mnt, buf, buflen);
43887+
43888+ return res;
43889+}
43890+
43891+static char *
43892+d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
43893+ char *buf, int buflen)
43894+{
43895+ char *res;
43896+ struct dentry *root;
43897+ struct vfsmount *rootmnt;
43898+ struct task_struct *reaper = &init_task;
43899+
43900+ /* we can't use real_root, real_root_mnt, because they belong only to the RBAC system */
43901+ read_lock(&reaper->fs->lock);
43902+ root = dget(reaper->fs->root.dentry);
43903+ rootmnt = mntget(reaper->fs->root.mnt);
43904+ read_unlock(&reaper->fs->lock);
43905+
43906+ spin_lock(&dcache_lock);
43907+ spin_lock(&vfsmount_lock);
43908+ res = gen_full_path((struct dentry *)dentry, (struct vfsmount *)vfsmnt, root, rootmnt, buf, buflen);
43909+ spin_unlock(&vfsmount_lock);
43910+ spin_unlock(&dcache_lock);
43911+
43912+ dput(root);
43913+ mntput(rootmnt);
43914+ return res;
43915+}
43916+
43917+static char *
43918+gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
43919+{
43920+ char *ret;
43921+ spin_lock(&dcache_lock);
43922+ spin_lock(&vfsmount_lock);
43923+ ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
43924+ PAGE_SIZE);
43925+ spin_unlock(&vfsmount_lock);
43926+ spin_unlock(&dcache_lock);
43927+ return ret;
43928+}
43929+
43930+char *
43931+gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
43932+{
43933+ return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
43934+ PAGE_SIZE);
43935+}
43936+
43937+char *
43938+gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
43939+{
43940+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
43941+ PAGE_SIZE);
43942+}
43943+
43944+char *
43945+gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
43946+{
43947+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
43948+ PAGE_SIZE);
43949+}
43950+
43951+char *
43952+gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
43953+{
43954+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
43955+ PAGE_SIZE);
43956+}
43957+
43958+char *
43959+gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
43960+{
43961+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
43962+ PAGE_SIZE);
43963+}
43964+
43965+__inline__ __u32
43966+to_gr_audit(const __u32 reqmode)
43967+{
43968+ /* masks off auditable permission flags, then shifts them to create
43969+ auditing flags, and adds the special case of append auditing if
43970+ we're requesting write */
43971+ return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
43972+}
43973+
43974+struct acl_subject_label *
43975+lookup_subject_map(const struct acl_subject_label *userp)
43976+{
43977+ unsigned int index = shash(userp, subj_map_set.s_size);
43978+ struct subject_map *match;
43979+
43980+ match = subj_map_set.s_hash[index];
43981+
43982+ while (match && match->user != userp)
43983+ match = match->next;
43984+
43985+ if (match != NULL)
43986+ return match->kernel;
43987+ else
43988+ return NULL;
43989+}
43990+
43991+static void
43992+insert_subj_map_entry(struct subject_map *subjmap)
43993+{
43994+ unsigned int index = shash(subjmap->user, subj_map_set.s_size);
43995+ struct subject_map **curr;
43996+
43997+ subjmap->prev = NULL;
43998+
43999+ curr = &subj_map_set.s_hash[index];
44000+ if (*curr != NULL)
44001+ (*curr)->prev = subjmap;
44002+
44003+ subjmap->next = *curr;
44004+ *curr = subjmap;
44005+
44006+ return;
44007+}
44008+
44009+static struct acl_role_label *
44010+lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
44011+ const gid_t gid)
44012+{
44013+ unsigned int index = rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
44014+ struct acl_role_label *match;
44015+ struct role_allowed_ip *ipp;
44016+ unsigned int x;
44017+ u32 curr_ip = task->signal->curr_ip;
44018+
44019+ task->signal->saved_ip = curr_ip;
44020+
44021+ match = acl_role_set.r_hash[index];
44022+
44023+ while (match) {
44024+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
44025+ for (x = 0; x < match->domain_child_num; x++) {
44026+ if (match->domain_children[x] == uid)
44027+ goto found;
44028+ }
44029+ } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
44030+ break;
44031+ match = match->next;
44032+ }
44033+found:
44034+ if (match == NULL) {
44035+ try_group:
44036+ index = rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
44037+ match = acl_role_set.r_hash[index];
44038+
44039+ while (match) {
44040+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
44041+ for (x = 0; x < match->domain_child_num; x++) {
44042+ if (match->domain_children[x] == gid)
44043+ goto found2;
44044+ }
44045+ } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
44046+ break;
44047+ match = match->next;
44048+ }
44049+found2:
44050+ if (match == NULL)
44051+ match = default_role;
44052+ if (match->allowed_ips == NULL)
44053+ return match;
44054+ else {
44055+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
44056+ if (likely
44057+ ((ntohl(curr_ip) & ipp->netmask) ==
44058+ (ntohl(ipp->addr) & ipp->netmask)))
44059+ return match;
44060+ }
44061+ match = default_role;
44062+ }
44063+ } else if (match->allowed_ips == NULL) {
44064+ return match;
44065+ } else {
44066+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
44067+ if (likely
44068+ ((ntohl(curr_ip) & ipp->netmask) ==
44069+ (ntohl(ipp->addr) & ipp->netmask)))
44070+ return match;
44071+ }
44072+ goto try_group;
44073+ }
44074+
44075+ return match;
44076+}
44077+
44078+struct acl_subject_label *
44079+lookup_acl_subj_label(const ino_t ino, const dev_t dev,
44080+ const struct acl_role_label *role)
44081+{
44082+ unsigned int index = fhash(ino, dev, role->subj_hash_size);
44083+ struct acl_subject_label *match;
44084+
44085+ match = role->subj_hash[index];
44086+
44087+ while (match && (match->inode != ino || match->device != dev ||
44088+ (match->mode & GR_DELETED))) {
44089+ match = match->next;
44090+ }
44091+
44092+ if (match && !(match->mode & GR_DELETED))
44093+ return match;
44094+ else
44095+ return NULL;
44096+}
44097+
44098+struct acl_subject_label *
44099+lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
44100+ const struct acl_role_label *role)
44101+{
44102+ unsigned int index = fhash(ino, dev, role->subj_hash_size);
44103+ struct acl_subject_label *match;
44104+
44105+ match = role->subj_hash[index];
44106+
44107+ while (match && (match->inode != ino || match->device != dev ||
44108+ !(match->mode & GR_DELETED))) {
44109+ match = match->next;
44110+ }
44111+
44112+ if (match && (match->mode & GR_DELETED))
44113+ return match;
44114+ else
44115+ return NULL;
44116+}
44117+
44118+static struct acl_object_label *
44119+lookup_acl_obj_label(const ino_t ino, const dev_t dev,
44120+ const struct acl_subject_label *subj)
44121+{
44122+ unsigned int index = fhash(ino, dev, subj->obj_hash_size);
44123+ struct acl_object_label *match;
44124+
44125+ match = subj->obj_hash[index];
44126+
44127+ while (match && (match->inode != ino || match->device != dev ||
44128+ (match->mode & GR_DELETED))) {
44129+ match = match->next;
44130+ }
44131+
44132+ if (match && !(match->mode & GR_DELETED))
44133+ return match;
44134+ else
44135+ return NULL;
44136+}
44137+
44138+static struct acl_object_label *
44139+lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
44140+ const struct acl_subject_label *subj)
44141+{
44142+ unsigned int index = fhash(ino, dev, subj->obj_hash_size);
44143+ struct acl_object_label *match;
44144+
44145+ match = subj->obj_hash[index];
44146+
44147+ while (match && (match->inode != ino || match->device != dev ||
44148+ !(match->mode & GR_DELETED))) {
44149+ match = match->next;
44150+ }
44151+
44152+ if (match && (match->mode & GR_DELETED))
44153+ return match;
44154+
44155+ match = subj->obj_hash[index];
44156+
44157+ while (match && (match->inode != ino || match->device != dev ||
44158+ (match->mode & GR_DELETED))) {
44159+ match = match->next;
44160+ }
44161+
44162+ if (match && !(match->mode & GR_DELETED))
44163+ return match;
44164+ else
44165+ return NULL;
44166+}
44167+
44168+static struct name_entry *
44169+lookup_name_entry(const char *name)
44170+{
44171+ unsigned int len = strlen(name);
44172+ unsigned int key = full_name_hash(name, len);
44173+ unsigned int index = key % name_set.n_size;
44174+ struct name_entry *match;
44175+
44176+ match = name_set.n_hash[index];
44177+
44178+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
44179+ match = match->next;
44180+
44181+ return match;
44182+}
44183+
44184+static struct name_entry *
44185+lookup_name_entry_create(const char *name)
44186+{
44187+ unsigned int len = strlen(name);
44188+ unsigned int key = full_name_hash(name, len);
44189+ unsigned int index = key % name_set.n_size;
44190+ struct name_entry *match;
44191+
44192+ match = name_set.n_hash[index];
44193+
44194+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
44195+ !match->deleted))
44196+ match = match->next;
44197+
44198+ if (match && match->deleted)
44199+ return match;
44200+
44201+ match = name_set.n_hash[index];
44202+
44203+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
44204+ match->deleted))
44205+ match = match->next;
44206+
44207+ if (match && !match->deleted)
44208+ return match;
44209+ else
44210+ return NULL;
44211+}
44212+
44213+static struct inodev_entry *
44214+lookup_inodev_entry(const ino_t ino, const dev_t dev)
44215+{
44216+ unsigned int index = fhash(ino, dev, inodev_set.i_size);
44217+ struct inodev_entry *match;
44218+
44219+ match = inodev_set.i_hash[index];
44220+
44221+ while (match && (match->nentry->inode != ino || match->nentry->device != dev))
44222+ match = match->next;
44223+
44224+ return match;
44225+}
44226+
44227+static void
44228+insert_inodev_entry(struct inodev_entry *entry)
44229+{
44230+ unsigned int index = fhash(entry->nentry->inode, entry->nentry->device,
44231+ inodev_set.i_size);
44232+ struct inodev_entry **curr;
44233+
44234+ entry->prev = NULL;
44235+
44236+ curr = &inodev_set.i_hash[index];
44237+ if (*curr != NULL)
44238+ (*curr)->prev = entry;
44239+
44240+ entry->next = *curr;
44241+ *curr = entry;
44242+
44243+ return;
44244+}
44245+
44246+static void
44247+__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
44248+{
44249+ unsigned int index =
44250+ rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
44251+ struct acl_role_label **curr;
44252+ struct acl_role_label *tmp;
44253+
44254+ curr = &acl_role_set.r_hash[index];
44255+
44256+ /* if role was already inserted due to domains and already has
44257+ a role in the same bucket as it attached, then we need to
44258+ combine these two buckets
44259+ */
44260+ if (role->next) {
44261+ tmp = role->next;
44262+ while (tmp->next)
44263+ tmp = tmp->next;
44264+ tmp->next = *curr;
44265+ } else
44266+ role->next = *curr;
44267+ *curr = role;
44268+
44269+ return;
44270+}
44271+
44272+static void
44273+insert_acl_role_label(struct acl_role_label *role)
44274+{
44275+ int i;
44276+
44277+ if (role_list == NULL) {
44278+ role_list = role;
44279+ role->prev = NULL;
44280+ } else {
44281+ role->prev = role_list;
44282+ role_list = role;
44283+ }
44284+
44285+ /* used for hash chains */
44286+ role->next = NULL;
44287+
44288+ if (role->roletype & GR_ROLE_DOMAIN) {
44289+ for (i = 0; i < role->domain_child_num; i++)
44290+ __insert_acl_role_label(role, role->domain_children[i]);
44291+ } else
44292+ __insert_acl_role_label(role, role->uidgid);
44293+}
44294+
44295+static int
44296+insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
44297+{
44298+ struct name_entry **curr, *nentry;
44299+ struct inodev_entry *ientry;
44300+ unsigned int len = strlen(name);
44301+ unsigned int key = full_name_hash(name, len);
44302+ unsigned int index = key % name_set.n_size;
44303+
44304+ curr = &name_set.n_hash[index];
44305+
44306+ while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
44307+ curr = &((*curr)->next);
44308+
44309+ if (*curr != NULL)
44310+ return 1;
44311+
44312+ nentry = acl_alloc(sizeof (struct name_entry));
44313+ if (nentry == NULL)
44314+ return 0;
44315+ ientry = acl_alloc(sizeof (struct inodev_entry));
44316+ if (ientry == NULL)
44317+ return 0;
44318+ ientry->nentry = nentry;
44319+
44320+ nentry->key = key;
44321+ nentry->name = name;
44322+ nentry->inode = inode;
44323+ nentry->device = device;
44324+ nentry->len = len;
44325+ nentry->deleted = deleted;
44326+
44327+ nentry->prev = NULL;
44328+ curr = &name_set.n_hash[index];
44329+ if (*curr != NULL)
44330+ (*curr)->prev = nentry;
44331+ nentry->next = *curr;
44332+ *curr = nentry;
44333+
44334+ /* insert us into the table searchable by inode/dev */
44335+ insert_inodev_entry(ientry);
44336+
44337+ return 1;
44338+}
44339+
44340+static void
44341+insert_acl_obj_label(struct acl_object_label *obj,
44342+ struct acl_subject_label *subj)
44343+{
44344+ unsigned int index =
44345+ fhash(obj->inode, obj->device, subj->obj_hash_size);
44346+ struct acl_object_label **curr;
44347+
44348+
44349+ obj->prev = NULL;
44350+
44351+ curr = &subj->obj_hash[index];
44352+ if (*curr != NULL)
44353+ (*curr)->prev = obj;
44354+
44355+ obj->next = *curr;
44356+ *curr = obj;
44357+
44358+ return;
44359+}
44360+
44361+static void
44362+insert_acl_subj_label(struct acl_subject_label *obj,
44363+ struct acl_role_label *role)
44364+{
44365+ unsigned int index = fhash(obj->inode, obj->device, role->subj_hash_size);
44366+ struct acl_subject_label **curr;
44367+
44368+ obj->prev = NULL;
44369+
44370+ curr = &role->subj_hash[index];
44371+ if (*curr != NULL)
44372+ (*curr)->prev = obj;
44373+
44374+ obj->next = *curr;
44375+ *curr = obj;
44376+
44377+ return;
44378+}
44379+
44380+/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
44381+
44382+static void *
44383+create_table(__u32 * len, int elementsize)
44384+{
44385+ unsigned int table_sizes[] = {
44386+ 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
44387+ 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
44388+ 4194301, 8388593, 16777213, 33554393, 67108859
44389+ };
44390+ void *newtable = NULL;
44391+ unsigned int pwr = 0;
44392+
44393+ while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
44394+ table_sizes[pwr] <= *len)
44395+ pwr++;
44396+
44397+ if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
44398+ return newtable;
44399+
44400+ if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
44401+ newtable =
44402+ kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
44403+ else
44404+ newtable = vmalloc(table_sizes[pwr] * elementsize);
44405+
44406+ *len = table_sizes[pwr];
44407+
44408+ return newtable;
44409+}
44410+
44411+static int
44412+init_variables(const struct gr_arg *arg)
44413+{
44414+ struct task_struct *reaper = &init_task;
44415+ unsigned int stacksize;
44416+
44417+ subj_map_set.s_size = arg->role_db.num_subjects;
44418+ acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
44419+ name_set.n_size = arg->role_db.num_objects;
44420+ inodev_set.i_size = arg->role_db.num_objects;
44421+
44422+ if (!subj_map_set.s_size || !acl_role_set.r_size ||
44423+ !name_set.n_size || !inodev_set.i_size)
44424+ return 1;
44425+
44426+ if (!gr_init_uidset())
44427+ return 1;
44428+
44429+ /* set up the stack that holds allocation info */
44430+
44431+ stacksize = arg->role_db.num_pointers + 5;
44432+
44433+ if (!acl_alloc_stack_init(stacksize))
44434+ return 1;
44435+
44436+ /* grab reference for the real root dentry and vfsmount */
44437+ read_lock(&reaper->fs->lock);
44438+ real_root = dget(reaper->fs->root.dentry);
44439+ real_root_mnt = mntget(reaper->fs->root.mnt);
44440+ read_unlock(&reaper->fs->lock);
44441+
44442+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
44443+ printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root), real_root->d_inode->i_ino);
44444+#endif
44445+
44446+ fakefs_obj = acl_alloc(sizeof(struct acl_object_label));
44447+ if (fakefs_obj == NULL)
44448+ return 1;
44449+ fakefs_obj->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
44450+
44451+ subj_map_set.s_hash =
44452+ (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
44453+ acl_role_set.r_hash =
44454+ (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
44455+ name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
44456+ inodev_set.i_hash =
44457+ (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
44458+
44459+ if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
44460+ !name_set.n_hash || !inodev_set.i_hash)
44461+ return 1;
44462+
44463+ memset(subj_map_set.s_hash, 0,
44464+ sizeof(struct subject_map *) * subj_map_set.s_size);
44465+ memset(acl_role_set.r_hash, 0,
44466+ sizeof (struct acl_role_label *) * acl_role_set.r_size);
44467+ memset(name_set.n_hash, 0,
44468+ sizeof (struct name_entry *) * name_set.n_size);
44469+ memset(inodev_set.i_hash, 0,
44470+ sizeof (struct inodev_entry *) * inodev_set.i_size);
44471+
44472+ return 0;
44473+}
44474+
44475+/* free information not needed after startup
44476+ currently contains user->kernel pointer mappings for subjects
44477+*/
44478+
44479+static void
44480+free_init_variables(void)
44481+{
44482+ __u32 i;
44483+
44484+ if (subj_map_set.s_hash) {
44485+ for (i = 0; i < subj_map_set.s_size; i++) {
44486+ if (subj_map_set.s_hash[i]) {
44487+ kfree(subj_map_set.s_hash[i]);
44488+ subj_map_set.s_hash[i] = NULL;
44489+ }
44490+ }
44491+
44492+ if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
44493+ PAGE_SIZE)
44494+ kfree(subj_map_set.s_hash);
44495+ else
44496+ vfree(subj_map_set.s_hash);
44497+ }
44498+
44499+ return;
44500+}
44501+
44502+static void
44503+free_variables(void)
44504+{
44505+ struct acl_subject_label *s;
44506+ struct acl_role_label *r;
44507+ struct task_struct *task, *task2;
44508+ unsigned int x;
44509+
44510+ gr_clear_learn_entries();
44511+
44512+ read_lock(&tasklist_lock);
44513+ do_each_thread(task2, task) {
44514+ task->acl_sp_role = 0;
44515+ task->acl_role_id = 0;
44516+ task->acl = NULL;
44517+ task->role = NULL;
44518+ } while_each_thread(task2, task);
44519+ read_unlock(&tasklist_lock);
44520+
44521+ /* release the reference to the real root dentry and vfsmount */
44522+ if (real_root)
44523+ dput(real_root);
44524+ real_root = NULL;
44525+ if (real_root_mnt)
44526+ mntput(real_root_mnt);
44527+ real_root_mnt = NULL;
44528+
44529+ /* free all object hash tables */
44530+
44531+ FOR_EACH_ROLE_START(r)
44532+ if (r->subj_hash == NULL)
44533+ goto next_role;
44534+ FOR_EACH_SUBJECT_START(r, s, x)
44535+ if (s->obj_hash == NULL)
44536+ break;
44537+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
44538+ kfree(s->obj_hash);
44539+ else
44540+ vfree(s->obj_hash);
44541+ FOR_EACH_SUBJECT_END(s, x)
44542+ FOR_EACH_NESTED_SUBJECT_START(r, s)
44543+ if (s->obj_hash == NULL)
44544+ break;
44545+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
44546+ kfree(s->obj_hash);
44547+ else
44548+ vfree(s->obj_hash);
44549+ FOR_EACH_NESTED_SUBJECT_END(s)
44550+ if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
44551+ kfree(r->subj_hash);
44552+ else
44553+ vfree(r->subj_hash);
44554+ r->subj_hash = NULL;
44555+next_role:
44556+ FOR_EACH_ROLE_END(r)
44557+
44558+ acl_free_all();
44559+
44560+ if (acl_role_set.r_hash) {
44561+ if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
44562+ PAGE_SIZE)
44563+ kfree(acl_role_set.r_hash);
44564+ else
44565+ vfree(acl_role_set.r_hash);
44566+ }
44567+ if (name_set.n_hash) {
44568+ if ((name_set.n_size * sizeof (struct name_entry *)) <=
44569+ PAGE_SIZE)
44570+ kfree(name_set.n_hash);
44571+ else
44572+ vfree(name_set.n_hash);
44573+ }
44574+
44575+ if (inodev_set.i_hash) {
44576+ if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
44577+ PAGE_SIZE)
44578+ kfree(inodev_set.i_hash);
44579+ else
44580+ vfree(inodev_set.i_hash);
44581+ }
44582+
44583+ gr_free_uidset();
44584+
44585+ memset(&name_set, 0, sizeof (struct name_db));
44586+ memset(&inodev_set, 0, sizeof (struct inodev_db));
44587+ memset(&acl_role_set, 0, sizeof (struct acl_role_db));
44588+ memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
44589+
44590+ default_role = NULL;
44591+ role_list = NULL;
44592+
44593+ return;
44594+}
44595+
44596+static __u32
44597+count_user_objs(struct acl_object_label *userp)
44598+{
44599+ struct acl_object_label o_tmp;
44600+ __u32 num = 0;
44601+
44602+ while (userp) {
44603+ if (copy_from_user(&o_tmp, userp,
44604+ sizeof (struct acl_object_label)))
44605+ break;
44606+
44607+ userp = o_tmp.prev;
44608+ num++;
44609+ }
44610+
44611+ return num;
44612+}
44613+
44614+static struct acl_subject_label *
44615+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role);
44616+
44617+static int
44618+copy_user_glob(struct acl_object_label *obj)
44619+{
44620+ struct acl_object_label *g_tmp, **guser;
44621+ unsigned int len;
44622+ char *tmp;
44623+
44624+ if (obj->globbed == NULL)
44625+ return 0;
44626+
44627+ guser = &obj->globbed;
44628+ while (*guser) {
44629+ g_tmp = (struct acl_object_label *)
44630+ acl_alloc(sizeof (struct acl_object_label));
44631+ if (g_tmp == NULL)
44632+ return -ENOMEM;
44633+
44634+ if (copy_from_user(g_tmp, *guser,
44635+ sizeof (struct acl_object_label)))
44636+ return -EFAULT;
44637+
44638+ len = strnlen_user(g_tmp->filename, PATH_MAX);
44639+
44640+ if (!len || len >= PATH_MAX)
44641+ return -EINVAL;
44642+
44643+ if ((tmp = (char *) acl_alloc(len)) == NULL)
44644+ return -ENOMEM;
44645+
44646+ if (copy_from_user(tmp, g_tmp->filename, len))
44647+ return -EFAULT;
44648+ tmp[len-1] = '\0';
44649+ g_tmp->filename = tmp;
44650+
44651+ *guser = g_tmp;
44652+ guser = &(g_tmp->next);
44653+ }
44654+
44655+ return 0;
44656+}
44657+
44658+static int
44659+copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
44660+ struct acl_role_label *role)
44661+{
44662+ struct acl_object_label *o_tmp;
44663+ unsigned int len;
44664+ int ret;
44665+ char *tmp;
44666+
44667+ while (userp) {
44668+ if ((o_tmp = (struct acl_object_label *)
44669+ acl_alloc(sizeof (struct acl_object_label))) == NULL)
44670+ return -ENOMEM;
44671+
44672+ if (copy_from_user(o_tmp, userp,
44673+ sizeof (struct acl_object_label)))
44674+ return -EFAULT;
44675+
44676+ userp = o_tmp->prev;
44677+
44678+ len = strnlen_user(o_tmp->filename, PATH_MAX);
44679+
44680+ if (!len || len >= PATH_MAX)
44681+ return -EINVAL;
44682+
44683+ if ((tmp = (char *) acl_alloc(len)) == NULL)
44684+ return -ENOMEM;
44685+
44686+ if (copy_from_user(tmp, o_tmp->filename, len))
44687+ return -EFAULT;
44688+ tmp[len-1] = '\0';
44689+ o_tmp->filename = tmp;
44690+
44691+ insert_acl_obj_label(o_tmp, subj);
44692+ if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
44693+ o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
44694+ return -ENOMEM;
44695+
44696+ ret = copy_user_glob(o_tmp);
44697+ if (ret)
44698+ return ret;
44699+
44700+ if (o_tmp->nested) {
44701+ o_tmp->nested = do_copy_user_subj(o_tmp->nested, role);
44702+ if (IS_ERR(o_tmp->nested))
44703+ return PTR_ERR(o_tmp->nested);
44704+
44705+ /* insert into nested subject list */
44706+ o_tmp->nested->next = role->hash->first;
44707+ role->hash->first = o_tmp->nested;
44708+ }
44709+ }
44710+
44711+ return 0;
44712+}
44713+
44714+static __u32
44715+count_user_subjs(struct acl_subject_label *userp)
44716+{
44717+ struct acl_subject_label s_tmp;
44718+ __u32 num = 0;
44719+
44720+ while (userp) {
44721+ if (copy_from_user(&s_tmp, userp,
44722+ sizeof (struct acl_subject_label)))
44723+ break;
44724+
44725+ userp = s_tmp.prev;
44726+ /* do not count nested subjects against this count, since
44727+ they are not included in the hash table, but are
44728+ attached to objects. We have already counted
44729+ the subjects in userspace for the allocation
44730+ stack
44731+ */
44732+ if (!(s_tmp.mode & GR_NESTED))
44733+ num++;
44734+ }
44735+
44736+ return num;
44737+}
44738+
44739+static int
44740+copy_user_allowedips(struct acl_role_label *rolep)
44741+{
44742+ struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
44743+
44744+ ruserip = rolep->allowed_ips;
44745+
44746+ while (ruserip) {
44747+ rlast = rtmp;
44748+
44749+ if ((rtmp = (struct role_allowed_ip *)
44750+ acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
44751+ return -ENOMEM;
44752+
44753+ if (copy_from_user(rtmp, ruserip,
44754+ sizeof (struct role_allowed_ip)))
44755+ return -EFAULT;
44756+
44757+ ruserip = rtmp->prev;
44758+
44759+ if (!rlast) {
44760+ rtmp->prev = NULL;
44761+ rolep->allowed_ips = rtmp;
44762+ } else {
44763+ rlast->next = rtmp;
44764+ rtmp->prev = rlast;
44765+ }
44766+
44767+ if (!ruserip)
44768+ rtmp->next = NULL;
44769+ }
44770+
44771+ return 0;
44772+}
44773+
44774+static int
44775+copy_user_transitions(struct acl_role_label *rolep)
44776+{
44777+ struct role_transition *rusertp, *rtmp = NULL, *rlast;
44778+
44779+ unsigned int len;
44780+ char *tmp;
44781+
44782+ rusertp = rolep->transitions;
44783+
44784+ while (rusertp) {
44785+ rlast = rtmp;
44786+
44787+ if ((rtmp = (struct role_transition *)
44788+ acl_alloc(sizeof (struct role_transition))) == NULL)
44789+ return -ENOMEM;
44790+
44791+ if (copy_from_user(rtmp, rusertp,
44792+ sizeof (struct role_transition)))
44793+ return -EFAULT;
44794+
44795+ rusertp = rtmp->prev;
44796+
44797+ len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
44798+
44799+ if (!len || len >= GR_SPROLE_LEN)
44800+ return -EINVAL;
44801+
44802+ if ((tmp = (char *) acl_alloc(len)) == NULL)
44803+ return -ENOMEM;
44804+
44805+ if (copy_from_user(tmp, rtmp->rolename, len))
44806+ return -EFAULT;
44807+ tmp[len-1] = '\0';
44808+ rtmp->rolename = tmp;
44809+
44810+ if (!rlast) {
44811+ rtmp->prev = NULL;
44812+ rolep->transitions = rtmp;
44813+ } else {
44814+ rlast->next = rtmp;
44815+ rtmp->prev = rlast;
44816+ }
44817+
44818+ if (!rusertp)
44819+ rtmp->next = NULL;
44820+ }
44821+
44822+ return 0;
44823+}
44824+
44825+static struct acl_subject_label *
44826+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role)
44827+{
44828+ struct acl_subject_label *s_tmp = NULL, *s_tmp2;
44829+ unsigned int len;
44830+ char *tmp;
44831+ __u32 num_objs;
44832+ struct acl_ip_label **i_tmp, *i_utmp2;
44833+ struct gr_hash_struct ghash;
44834+ struct subject_map *subjmap;
44835+ unsigned int i_num;
44836+ int err;
44837+
44838+ s_tmp = lookup_subject_map(userp);
44839+
44840+ /* we've already copied this subject into the kernel, just return
44841+ the reference to it, and don't copy it over again
44842+ */
44843+ if (s_tmp)
44844+ return(s_tmp);
44845+
44846+ if ((s_tmp = (struct acl_subject_label *)
44847+ acl_alloc(sizeof (struct acl_subject_label))) == NULL)
44848+ return ERR_PTR(-ENOMEM);
44849+
44850+ subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
44851+ if (subjmap == NULL)
44852+ return ERR_PTR(-ENOMEM);
44853+
44854+ subjmap->user = userp;
44855+ subjmap->kernel = s_tmp;
44856+ insert_subj_map_entry(subjmap);
44857+
44858+ if (copy_from_user(s_tmp, userp,
44859+ sizeof (struct acl_subject_label)))
44860+ return ERR_PTR(-EFAULT);
44861+
44862+ len = strnlen_user(s_tmp->filename, PATH_MAX);
44863+
44864+ if (!len || len >= PATH_MAX)
44865+ return ERR_PTR(-EINVAL);
44866+
44867+ if ((tmp = (char *) acl_alloc(len)) == NULL)
44868+ return ERR_PTR(-ENOMEM);
44869+
44870+ if (copy_from_user(tmp, s_tmp->filename, len))
44871+ return ERR_PTR(-EFAULT);
44872+ tmp[len-1] = '\0';
44873+ s_tmp->filename = tmp;
44874+
44875+ if (!strcmp(s_tmp->filename, "/"))
44876+ role->root_label = s_tmp;
44877+
44878+ if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
44879+ return ERR_PTR(-EFAULT);
44880+
44881+ /* copy user and group transition tables */
44882+
44883+ if (s_tmp->user_trans_num) {
44884+ uid_t *uidlist;
44885+
44886+ uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
44887+ if (uidlist == NULL)
44888+ return ERR_PTR(-ENOMEM);
44889+ if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
44890+ return ERR_PTR(-EFAULT);
44891+
44892+ s_tmp->user_transitions = uidlist;
44893+ }
44894+
44895+ if (s_tmp->group_trans_num) {
44896+ gid_t *gidlist;
44897+
44898+ gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
44899+ if (gidlist == NULL)
44900+ return ERR_PTR(-ENOMEM);
44901+ if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
44902+ return ERR_PTR(-EFAULT);
44903+
44904+ s_tmp->group_transitions = gidlist;
44905+ }
44906+
44907+ /* set up object hash table */
44908+ num_objs = count_user_objs(ghash.first);
44909+
44910+ s_tmp->obj_hash_size = num_objs;
44911+ s_tmp->obj_hash =
44912+ (struct acl_object_label **)
44913+ create_table(&(s_tmp->obj_hash_size), sizeof(void *));
44914+
44915+ if (!s_tmp->obj_hash)
44916+ return ERR_PTR(-ENOMEM);
44917+
44918+ memset(s_tmp->obj_hash, 0,
44919+ s_tmp->obj_hash_size *
44920+ sizeof (struct acl_object_label *));
44921+
44922+ /* add in objects */
44923+ err = copy_user_objs(ghash.first, s_tmp, role);
44924+
44925+ if (err)
44926+ return ERR_PTR(err);
44927+
44928+ /* set pointer for parent subject */
44929+ if (s_tmp->parent_subject) {
44930+ s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role);
44931+
44932+ if (IS_ERR(s_tmp2))
44933+ return s_tmp2;
44934+
44935+ s_tmp->parent_subject = s_tmp2;
44936+ }
44937+
44938+ /* add in ip acls */
44939+
44940+ if (!s_tmp->ip_num) {
44941+ s_tmp->ips = NULL;
44942+ goto insert;
44943+ }
44944+
44945+ i_tmp =
44946+ (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
44947+ sizeof (struct acl_ip_label *));
44948+
44949+ if (!i_tmp)
44950+ return ERR_PTR(-ENOMEM);
44951+
44952+ for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
44953+ *(i_tmp + i_num) =
44954+ (struct acl_ip_label *)
44955+ acl_alloc(sizeof (struct acl_ip_label));
44956+ if (!*(i_tmp + i_num))
44957+ return ERR_PTR(-ENOMEM);
44958+
44959+ if (copy_from_user
44960+ (&i_utmp2, s_tmp->ips + i_num,
44961+ sizeof (struct acl_ip_label *)))
44962+ return ERR_PTR(-EFAULT);
44963+
44964+ if (copy_from_user
44965+ (*(i_tmp + i_num), i_utmp2,
44966+ sizeof (struct acl_ip_label)))
44967+ return ERR_PTR(-EFAULT);
44968+
44969+ if ((*(i_tmp + i_num))->iface == NULL)
44970+ continue;
44971+
44972+ len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
44973+ if (!len || len >= IFNAMSIZ)
44974+ return ERR_PTR(-EINVAL);
44975+ tmp = acl_alloc(len);
44976+ if (tmp == NULL)
44977+ return ERR_PTR(-ENOMEM);
44978+ if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
44979+ return ERR_PTR(-EFAULT);
44980+ (*(i_tmp + i_num))->iface = tmp;
44981+ }
44982+
44983+ s_tmp->ips = i_tmp;
44984+
44985+insert:
44986+ if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
44987+ s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
44988+ return ERR_PTR(-ENOMEM);
44989+
44990+ return s_tmp;
44991+}
44992+
44993+static int
44994+copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
44995+{
44996+ struct acl_subject_label s_pre;
44997+ struct acl_subject_label * ret;
44998+ int err;
44999+
45000+ while (userp) {
45001+ if (copy_from_user(&s_pre, userp,
45002+ sizeof (struct acl_subject_label)))
45003+ return -EFAULT;
45004+
45005+ /* do not add nested subjects here, add
45006+ while parsing objects
45007+ */
45008+
45009+ if (s_pre.mode & GR_NESTED) {
45010+ userp = s_pre.prev;
45011+ continue;
45012+ }
45013+
45014+ ret = do_copy_user_subj(userp, role);
45015+
45016+ err = PTR_ERR(ret);
45017+ if (IS_ERR(ret))
45018+ return err;
45019+
45020+ insert_acl_subj_label(ret, role);
45021+
45022+ userp = s_pre.prev;
45023+ }
45024+
45025+ return 0;
45026+}
45027+
45028+static int
45029+copy_user_acl(struct gr_arg *arg)
45030+{
45031+ struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
45032+ struct sprole_pw *sptmp;
45033+ struct gr_hash_struct *ghash;
45034+ uid_t *domainlist;
45035+ unsigned int r_num;
45036+ unsigned int len;
45037+ char *tmp;
45038+ int err = 0;
45039+ __u16 i;
45040+ __u32 num_subjs;
45041+
45042+ /* we need a default and kernel role */
45043+ if (arg->role_db.num_roles < 2)
45044+ return -EINVAL;
45045+
45046+ /* copy special role authentication info from userspace */
45047+
45048+ num_sprole_pws = arg->num_sprole_pws;
45049+ acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
45050+
45051+ if (!acl_special_roles) {
45052+ err = -ENOMEM;
45053+ goto cleanup;
45054+ }
45055+
45056+ for (i = 0; i < num_sprole_pws; i++) {
45057+ sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
45058+ if (!sptmp) {
45059+ err = -ENOMEM;
45060+ goto cleanup;
45061+ }
45062+ if (copy_from_user(sptmp, arg->sprole_pws + i,
45063+ sizeof (struct sprole_pw))) {
45064+ err = -EFAULT;
45065+ goto cleanup;
45066+ }
45067+
45068+ len =
45069+ strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
45070+
45071+ if (!len || len >= GR_SPROLE_LEN) {
45072+ err = -EINVAL;
45073+ goto cleanup;
45074+ }
45075+
45076+ if ((tmp = (char *) acl_alloc(len)) == NULL) {
45077+ err = -ENOMEM;
45078+ goto cleanup;
45079+ }
45080+
45081+ if (copy_from_user(tmp, sptmp->rolename, len)) {
45082+ err = -EFAULT;
45083+ goto cleanup;
45084+ }
45085+ tmp[len-1] = '\0';
45086+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
45087+ printk(KERN_ALERT "Copying special role %s\n", tmp);
45088+#endif
45089+ sptmp->rolename = tmp;
45090+ acl_special_roles[i] = sptmp;
45091+ }
45092+
45093+ r_utmp = (struct acl_role_label **) arg->role_db.r_table;
45094+
45095+ for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
45096+ r_tmp = acl_alloc(sizeof (struct acl_role_label));
45097+
45098+ if (!r_tmp) {
45099+ err = -ENOMEM;
45100+ goto cleanup;
45101+ }
45102+
45103+ if (copy_from_user(&r_utmp2, r_utmp + r_num,
45104+ sizeof (struct acl_role_label *))) {
45105+ err = -EFAULT;
45106+ goto cleanup;
45107+ }
45108+
45109+ if (copy_from_user(r_tmp, r_utmp2,
45110+ sizeof (struct acl_role_label))) {
45111+ err = -EFAULT;
45112+ goto cleanup;
45113+ }
45114+
45115+ len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
45116+
45117+ if (!len || len >= PATH_MAX) {
45118+ err = -EINVAL;
45119+ goto cleanup;
45120+ }
45121+
45122+ if ((tmp = (char *) acl_alloc(len)) == NULL) {
45123+ err = -ENOMEM;
45124+ goto cleanup;
45125+ }
45126+ if (copy_from_user(tmp, r_tmp->rolename, len)) {
45127+ err = -EFAULT;
45128+ goto cleanup;
45129+ }
45130+ tmp[len-1] = '\0';
45131+ r_tmp->rolename = tmp;
45132+
45133+ if (!strcmp(r_tmp->rolename, "default")
45134+ && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
45135+ default_role = r_tmp;
45136+ } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
45137+ kernel_role = r_tmp;
45138+ }
45139+
45140+ if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL) {
45141+ err = -ENOMEM;
45142+ goto cleanup;
45143+ }
45144+ if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct))) {
45145+ err = -EFAULT;
45146+ goto cleanup;
45147+ }
45148+
45149+ r_tmp->hash = ghash;
45150+
45151+ num_subjs = count_user_subjs(r_tmp->hash->first);
45152+
45153+ r_tmp->subj_hash_size = num_subjs;
45154+ r_tmp->subj_hash =
45155+ (struct acl_subject_label **)
45156+ create_table(&(r_tmp->subj_hash_size), sizeof(void *));
45157+
45158+ if (!r_tmp->subj_hash) {
45159+ err = -ENOMEM;
45160+ goto cleanup;
45161+ }
45162+
45163+ err = copy_user_allowedips(r_tmp);
45164+ if (err)
45165+ goto cleanup;
45166+
45167+ /* copy domain info */
45168+ if (r_tmp->domain_children != NULL) {
45169+ domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
45170+ if (domainlist == NULL) {
45171+ err = -ENOMEM;
45172+ goto cleanup;
45173+ }
45174+ if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t))) {
45175+ err = -EFAULT;
45176+ goto cleanup;
45177+ }
45178+ r_tmp->domain_children = domainlist;
45179+ }
45180+
45181+ err = copy_user_transitions(r_tmp);
45182+ if (err)
45183+ goto cleanup;
45184+
45185+ memset(r_tmp->subj_hash, 0,
45186+ r_tmp->subj_hash_size *
45187+ sizeof (struct acl_subject_label *));
45188+
45189+ err = copy_user_subjs(r_tmp->hash->first, r_tmp);
45190+
45191+ if (err)
45192+ goto cleanup;
45193+
45194+ /* set nested subject list to null */
45195+ r_tmp->hash->first = NULL;
45196+
45197+ insert_acl_role_label(r_tmp);
45198+ }
45199+
45200+ goto return_err;
45201+ cleanup:
45202+ free_variables();
45203+ return_err:
45204+ return err;
45205+
45206+}
45207+
45208+static int
45209+gracl_init(struct gr_arg *args)
45210+{
45211+ int error = 0;
45212+
45213+ memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
45214+ memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
45215+
45216+ if (init_variables(args)) {
45217+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
45218+ error = -ENOMEM;
45219+ free_variables();
45220+ goto out;
45221+ }
45222+
45223+ error = copy_user_acl(args);
45224+ free_init_variables();
45225+ if (error) {
45226+ free_variables();
45227+ goto out;
45228+ }
45229+
45230+ if ((error = gr_set_acls(0))) {
45231+ free_variables();
45232+ goto out;
45233+ }
45234+
45235+ pax_open_kernel();
45236+ gr_status |= GR_READY;
45237+ pax_close_kernel();
45238+
45239+ out:
45240+ return error;
45241+}
45242+
45243+/* derived from glibc fnmatch() 0: match, 1: no match*/
45244+
45245+static int
45246+glob_match(const char *p, const char *n)
45247+{
45248+ char c;
45249+
45250+ while ((c = *p++) != '\0') {
45251+ switch (c) {
45252+ case '?':
45253+ if (*n == '\0')
45254+ return 1;
45255+ else if (*n == '/')
45256+ return 1;
45257+ break;
45258+ case '\\':
45259+ if (*n != c)
45260+ return 1;
45261+ break;
45262+ case '*':
45263+ for (c = *p++; c == '?' || c == '*'; c = *p++) {
45264+ if (*n == '/')
45265+ return 1;
45266+ else if (c == '?') {
45267+ if (*n == '\0')
45268+ return 1;
45269+ else
45270+ ++n;
45271+ }
45272+ }
45273+ if (c == '\0') {
45274+ return 0;
45275+ } else {
45276+ const char *endp;
45277+
45278+ if ((endp = strchr(n, '/')) == NULL)
45279+ endp = n + strlen(n);
45280+
45281+ if (c == '[') {
45282+ for (--p; n < endp; ++n)
45283+ if (!glob_match(p, n))
45284+ return 0;
45285+ } else if (c == '/') {
45286+ while (*n != '\0' && *n != '/')
45287+ ++n;
45288+ if (*n == '/' && !glob_match(p, n + 1))
45289+ return 0;
45290+ } else {
45291+ for (--p; n < endp; ++n)
45292+ if (*n == c && !glob_match(p, n))
45293+ return 0;
45294+ }
45295+
45296+ return 1;
45297+ }
45298+ case '[':
45299+ {
45300+ int not;
45301+ char cold;
45302+
45303+ if (*n == '\0' || *n == '/')
45304+ return 1;
45305+
45306+ not = (*p == '!' || *p == '^');
45307+ if (not)
45308+ ++p;
45309+
45310+ c = *p++;
45311+ for (;;) {
45312+ unsigned char fn = (unsigned char)*n;
45313+
45314+ if (c == '\0')
45315+ return 1;
45316+ else {
45317+ if (c == fn)
45318+ goto matched;
45319+ cold = c;
45320+ c = *p++;
45321+
45322+ if (c == '-' && *p != ']') {
45323+ unsigned char cend = *p++;
45324+
45325+ if (cend == '\0')
45326+ return 1;
45327+
45328+ if (cold <= fn && fn <= cend)
45329+ goto matched;
45330+
45331+ c = *p++;
45332+ }
45333+ }
45334+
45335+ if (c == ']')
45336+ break;
45337+ }
45338+ if (!not)
45339+ return 1;
45340+ break;
45341+ matched:
45342+ while (c != ']') {
45343+ if (c == '\0')
45344+ return 1;
45345+
45346+ c = *p++;
45347+ }
45348+ if (not)
45349+ return 1;
45350+ }
45351+ break;
45352+ default:
45353+ if (c != *n)
45354+ return 1;
45355+ }
45356+
45357+ ++n;
45358+ }
45359+
45360+ if (*n == '\0')
45361+ return 0;
45362+
45363+ if (*n == '/')
45364+ return 0;
45365+
45366+ return 1;
45367+}
45368+
45369+static struct acl_object_label *
45370+chk_glob_label(struct acl_object_label *globbed,
45371+ struct dentry *dentry, struct vfsmount *mnt, char **path)
45372+{
45373+ struct acl_object_label *tmp;
45374+
45375+ if (*path == NULL)
45376+ *path = gr_to_filename_nolock(dentry, mnt);
45377+
45378+ tmp = globbed;
45379+
45380+ while (tmp) {
45381+ if (!glob_match(tmp->filename, *path))
45382+ return tmp;
45383+ tmp = tmp->next;
45384+ }
45385+
45386+ return NULL;
45387+}
45388+
45389+static struct acl_object_label *
45390+__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
45391+ const ino_t curr_ino, const dev_t curr_dev,
45392+ const struct acl_subject_label *subj, char **path, const int checkglob)
45393+{
45394+ struct acl_subject_label *tmpsubj;
45395+ struct acl_object_label *retval;
45396+ struct acl_object_label *retval2;
45397+
45398+ tmpsubj = (struct acl_subject_label *) subj;
45399+ read_lock(&gr_inode_lock);
45400+ do {
45401+ retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
45402+ if (retval) {
45403+ if (checkglob && retval->globbed) {
45404+ retval2 = chk_glob_label(retval->globbed, (struct dentry *)orig_dentry,
45405+ (struct vfsmount *)orig_mnt, path);
45406+ if (retval2)
45407+ retval = retval2;
45408+ }
45409+ break;
45410+ }
45411+ } while ((tmpsubj = tmpsubj->parent_subject));
45412+ read_unlock(&gr_inode_lock);
45413+
45414+ return retval;
45415+}
45416+
45417+static __inline__ struct acl_object_label *
45418+full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
45419+ const struct dentry *curr_dentry,
45420+ const struct acl_subject_label *subj, char **path, const int checkglob)
45421+{
45422+ int newglob = checkglob;
45423+
45424+ /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
45425+ as we don't want a / * rule to match instead of the / object
45426+ don't do this for create lookups that call this function though, since they're looking up
45427+ on the parent and thus need globbing checks on all paths
45428+ */
45429+ if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
45430+ newglob = GR_NO_GLOB;
45431+
45432+ return __full_lookup(orig_dentry, orig_mnt,
45433+ curr_dentry->d_inode->i_ino,
45434+ __get_dev(curr_dentry), subj, path, newglob);
45435+}
45436+
45437+static struct acl_object_label *
45438+__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
45439+ const struct acl_subject_label *subj, char *path, const int checkglob)
45440+{
45441+ struct dentry *dentry = (struct dentry *) l_dentry;
45442+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
45443+ struct acl_object_label *retval;
45444+
45445+ spin_lock(&dcache_lock);
45446+ spin_lock(&vfsmount_lock);
45447+
45448+ if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
45449+#ifdef CONFIG_NET
45450+ mnt == sock_mnt ||
45451+#endif
45452+#ifdef CONFIG_HUGETLBFS
45453+ (mnt == hugetlbfs_vfsmount && dentry->d_inode->i_nlink == 0) ||
45454+#endif
45455+ /* ignore Eric Biederman */
45456+ IS_PRIVATE(l_dentry->d_inode))) {
45457+ retval = fakefs_obj;
45458+ goto out;
45459+ }
45460+
45461+ for (;;) {
45462+ if (dentry == real_root && mnt == real_root_mnt)
45463+ break;
45464+
45465+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
45466+ if (mnt->mnt_parent == mnt)
45467+ break;
45468+
45469+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
45470+ if (retval != NULL)
45471+ goto out;
45472+
45473+ dentry = mnt->mnt_mountpoint;
45474+ mnt = mnt->mnt_parent;
45475+ continue;
45476+ }
45477+
45478+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
45479+ if (retval != NULL)
45480+ goto out;
45481+
45482+ dentry = dentry->d_parent;
45483+ }
45484+
45485+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
45486+
45487+ if (retval == NULL)
45488+ retval = full_lookup(l_dentry, l_mnt, real_root, subj, &path, checkglob);
45489+out:
45490+ spin_unlock(&vfsmount_lock);
45491+ spin_unlock(&dcache_lock);
45492+
45493+ BUG_ON(retval == NULL);
45494+
45495+ return retval;
45496+}
45497+
45498+static __inline__ struct acl_object_label *
45499+chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
45500+ const struct acl_subject_label *subj)
45501+{
45502+ char *path = NULL;
45503+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
45504+}
45505+
45506+static __inline__ struct acl_object_label *
45507+chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
45508+ const struct acl_subject_label *subj)
45509+{
45510+ char *path = NULL;
45511+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
45512+}
45513+
45514+static __inline__ struct acl_object_label *
45515+chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
45516+ const struct acl_subject_label *subj, char *path)
45517+{
45518+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
45519+}
45520+
45521+static struct acl_subject_label *
45522+chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
45523+ const struct acl_role_label *role)
45524+{
45525+ struct dentry *dentry = (struct dentry *) l_dentry;
45526+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
45527+ struct acl_subject_label *retval;
45528+
45529+ spin_lock(&dcache_lock);
45530+ spin_lock(&vfsmount_lock);
45531+
45532+ for (;;) {
45533+ if (dentry == real_root && mnt == real_root_mnt)
45534+ break;
45535+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
45536+ if (mnt->mnt_parent == mnt)
45537+ break;
45538+
45539+ read_lock(&gr_inode_lock);
45540+ retval =
45541+ lookup_acl_subj_label(dentry->d_inode->i_ino,
45542+ __get_dev(dentry), role);
45543+ read_unlock(&gr_inode_lock);
45544+ if (retval != NULL)
45545+ goto out;
45546+
45547+ dentry = mnt->mnt_mountpoint;
45548+ mnt = mnt->mnt_parent;
45549+ continue;
45550+ }
45551+
45552+ read_lock(&gr_inode_lock);
45553+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
45554+ __get_dev(dentry), role);
45555+ read_unlock(&gr_inode_lock);
45556+ if (retval != NULL)
45557+ goto out;
45558+
45559+ dentry = dentry->d_parent;
45560+ }
45561+
45562+ read_lock(&gr_inode_lock);
45563+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
45564+ __get_dev(dentry), role);
45565+ read_unlock(&gr_inode_lock);
45566+
45567+ if (unlikely(retval == NULL)) {
45568+ read_lock(&gr_inode_lock);
45569+ retval = lookup_acl_subj_label(real_root->d_inode->i_ino,
45570+ __get_dev(real_root), role);
45571+ read_unlock(&gr_inode_lock);
45572+ }
45573+out:
45574+ spin_unlock(&vfsmount_lock);
45575+ spin_unlock(&dcache_lock);
45576+
45577+ BUG_ON(retval == NULL);
45578+
45579+ return retval;
45580+}
45581+
45582+static void
45583+gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
45584+{
45585+ struct task_struct *task = current;
45586+ const struct cred *cred = current_cred();
45587+
45588+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
45589+ cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
45590+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
45591+ 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
45592+
45593+ return;
45594+}
45595+
45596+static void
45597+gr_log_learn_sysctl(const char *path, const __u32 mode)
45598+{
45599+ struct task_struct *task = current;
45600+ const struct cred *cred = current_cred();
45601+
45602+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
45603+ cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
45604+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
45605+ 1UL, 1UL, path, (unsigned long) mode, &task->signal->saved_ip);
45606+
45607+ return;
45608+}
45609+
45610+static void
45611+gr_log_learn_id_change(const char type, const unsigned int real,
45612+ const unsigned int effective, const unsigned int fs)
45613+{
45614+ struct task_struct *task = current;
45615+ const struct cred *cred = current_cred();
45616+
45617+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
45618+ cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
45619+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
45620+ type, real, effective, fs, &task->signal->saved_ip);
45621+
45622+ return;
45623+}
45624+
45625+__u32
45626+gr_check_link(const struct dentry * new_dentry,
45627+ const struct dentry * parent_dentry,
45628+ const struct vfsmount * parent_mnt,
45629+ const struct dentry * old_dentry, const struct vfsmount * old_mnt)
45630+{
45631+ struct acl_object_label *obj;
45632+ __u32 oldmode, newmode;
45633+ __u32 needmode;
45634+
45635+ if (unlikely(!(gr_status & GR_READY)))
45636+ return (GR_CREATE | GR_LINK);
45637+
45638+ obj = chk_obj_label(old_dentry, old_mnt, current->acl);
45639+ oldmode = obj->mode;
45640+
45641+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
45642+ oldmode |= (GR_CREATE | GR_LINK);
45643+
45644+ needmode = GR_CREATE | GR_AUDIT_CREATE | GR_SUPPRESS;
45645+ if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID))
45646+ needmode |= GR_SETID | GR_AUDIT_SETID;
45647+
45648+ newmode =
45649+ gr_check_create(new_dentry, parent_dentry, parent_mnt,
45650+ oldmode | needmode);
45651+
45652+ needmode = newmode & (GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC |
45653+ GR_SETID | GR_READ | GR_FIND | GR_DELETE |
45654+ GR_INHERIT | GR_AUDIT_INHERIT);
45655+
45656+ if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID) && !(newmode & GR_SETID))
45657+ goto bad;
45658+
45659+ if ((oldmode & needmode) != needmode)
45660+ goto bad;
45661+
45662+ needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
45663+ if ((newmode & needmode) != needmode)
45664+ goto bad;
45665+
45666+ if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
45667+ return newmode;
45668+bad:
45669+ needmode = oldmode;
45670+ if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID))
45671+ needmode |= GR_SETID;
45672+
45673+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
45674+ gr_log_learn(old_dentry, old_mnt, needmode);
45675+ return (GR_CREATE | GR_LINK);
45676+ } else if (newmode & GR_SUPPRESS)
45677+ return GR_SUPPRESS;
45678+ else
45679+ return 0;
45680+}
45681+
45682+__u32
45683+gr_search_file(const struct dentry * dentry, const __u32 mode,
45684+ const struct vfsmount * mnt)
45685+{
45686+ __u32 retval = mode;
45687+ struct acl_subject_label *curracl;
45688+ struct acl_object_label *currobj;
45689+
45690+ if (unlikely(!(gr_status & GR_READY)))
45691+ return (mode & ~GR_AUDITS);
45692+
45693+ curracl = current->acl;
45694+
45695+ currobj = chk_obj_label(dentry, mnt, curracl);
45696+ retval = currobj->mode & mode;
45697+
45698+ /* if we're opening a specified transfer file for writing
45699+ (e.g. /dev/initctl), then transfer our role to init
45700+ */
45701+ if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
45702+ current->role->roletype & GR_ROLE_PERSIST)) {
45703+ struct task_struct *task = init_pid_ns.child_reaper;
45704+
45705+ if (task->role != current->role) {
45706+ task->acl_sp_role = 0;
45707+ task->acl_role_id = current->acl_role_id;
45708+ task->role = current->role;
45709+ rcu_read_lock();
45710+ read_lock(&grsec_exec_file_lock);
45711+ gr_apply_subject_to_task(task);
45712+ read_unlock(&grsec_exec_file_lock);
45713+ rcu_read_unlock();
45714+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
45715+ }
45716+ }
45717+
45718+ if (unlikely
45719+ ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
45720+ && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
45721+ __u32 new_mode = mode;
45722+
45723+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
45724+
45725+ retval = new_mode;
45726+
45727+ if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
45728+ new_mode |= GR_INHERIT;
45729+
45730+ if (!(mode & GR_NOLEARN))
45731+ gr_log_learn(dentry, mnt, new_mode);
45732+ }
45733+
45734+ return retval;
45735+}
45736+
45737+__u32
45738+gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
45739+ const struct vfsmount * mnt, const __u32 mode)
45740+{
45741+ struct name_entry *match;
45742+ struct acl_object_label *matchpo;
45743+ struct acl_subject_label *curracl;
45744+ char *path;
45745+ __u32 retval;
45746+
45747+ if (unlikely(!(gr_status & GR_READY)))
45748+ return (mode & ~GR_AUDITS);
45749+
45750+ preempt_disable();
45751+ path = gr_to_filename_rbac(new_dentry, mnt);
45752+ match = lookup_name_entry_create(path);
45753+
45754+ if (!match)
45755+ goto check_parent;
45756+
45757+ curracl = current->acl;
45758+
45759+ read_lock(&gr_inode_lock);
45760+ matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
45761+ read_unlock(&gr_inode_lock);
45762+
45763+ if (matchpo) {
45764+ if ((matchpo->mode & mode) !=
45765+ (mode & ~(GR_AUDITS | GR_SUPPRESS))
45766+ && curracl->mode & (GR_LEARN | GR_INHERITLEARN)) {
45767+ __u32 new_mode = mode;
45768+
45769+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
45770+
45771+ gr_log_learn(new_dentry, mnt, new_mode);
45772+
45773+ preempt_enable();
45774+ return new_mode;
45775+ }
45776+ preempt_enable();
45777+ return (matchpo->mode & mode);
45778+ }
45779+
45780+ check_parent:
45781+ curracl = current->acl;
45782+
45783+ matchpo = chk_obj_create_label(parent, mnt, curracl, path);
45784+ retval = matchpo->mode & mode;
45785+
45786+ if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
45787+ && (curracl->mode & (GR_LEARN | GR_INHERITLEARN))) {
45788+ __u32 new_mode = mode;
45789+
45790+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
45791+
45792+ gr_log_learn(new_dentry, mnt, new_mode);
45793+ preempt_enable();
45794+ return new_mode;
45795+ }
45796+
45797+ preempt_enable();
45798+ return retval;
45799+}
45800+
45801+int
45802+gr_check_hidden_task(const struct task_struct *task)
45803+{
45804+ if (unlikely(!(gr_status & GR_READY)))
45805+ return 0;
45806+
45807+ if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
45808+ return 1;
45809+
45810+ return 0;
45811+}
45812+
45813+int
45814+gr_check_protected_task(const struct task_struct *task)
45815+{
45816+ if (unlikely(!(gr_status & GR_READY) || !task))
45817+ return 0;
45818+
45819+ if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
45820+ task->acl != current->acl)
45821+ return 1;
45822+
45823+ return 0;
45824+}
45825+
45826+int
45827+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
45828+{
45829+ struct task_struct *p;
45830+ int ret = 0;
45831+
45832+ if (unlikely(!(gr_status & GR_READY) || !pid))
45833+ return ret;
45834+
45835+ read_lock(&tasklist_lock);
45836+ do_each_pid_task(pid, type, p) {
45837+ if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
45838+ p->acl != current->acl) {
45839+ ret = 1;
45840+ goto out;
45841+ }
45842+ } while_each_pid_task(pid, type, p);
45843+out:
45844+ read_unlock(&tasklist_lock);
45845+
45846+ return ret;
45847+}
45848+
45849+void
45850+gr_copy_label(struct task_struct *tsk)
45851+{
45852+ tsk->signal->used_accept = 0;
45853+ tsk->acl_sp_role = 0;
45854+ tsk->acl_role_id = current->acl_role_id;
45855+ tsk->acl = current->acl;
45856+ tsk->role = current->role;
45857+ tsk->signal->curr_ip = current->signal->curr_ip;
45858+ tsk->signal->saved_ip = current->signal->saved_ip;
45859+ if (current->exec_file)
45860+ get_file(current->exec_file);
45861+ tsk->exec_file = current->exec_file;
45862+ tsk->is_writable = current->is_writable;
45863+ if (unlikely(current->signal->used_accept)) {
45864+ current->signal->curr_ip = 0;
45865+ current->signal->saved_ip = 0;
45866+ }
45867+
45868+ return;
45869+}
45870+
45871+static void
45872+gr_set_proc_res(struct task_struct *task)
45873+{
45874+ struct acl_subject_label *proc;
45875+ unsigned short i;
45876+
45877+ proc = task->acl;
45878+
45879+ if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
45880+ return;
45881+
45882+ for (i = 0; i < RLIM_NLIMITS; i++) {
45883+ if (!(proc->resmask & (1 << i)))
45884+ continue;
45885+
45886+ task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
45887+ task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
45888+ }
45889+
45890+ return;
45891+}
45892+
45893+extern int __gr_process_user_ban(struct user_struct *user);
45894+
45895+int
45896+gr_check_user_change(int real, int effective, int fs)
45897+{
45898+ unsigned int i;
45899+ __u16 num;
45900+ uid_t *uidlist;
45901+ int curuid;
45902+ int realok = 0;
45903+ int effectiveok = 0;
45904+ int fsok = 0;
45905+
45906+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
45907+ struct user_struct *user;
45908+
45909+ if (real == -1)
45910+ goto skipit;
45911+
45912+ user = find_user(real);
45913+ if (user == NULL)
45914+ goto skipit;
45915+
45916+ if (__gr_process_user_ban(user)) {
45917+ /* for find_user */
45918+ free_uid(user);
45919+ return 1;
45920+ }
45921+
45922+ /* for find_user */
45923+ free_uid(user);
45924+
45925+skipit:
45926+#endif
45927+
45928+ if (unlikely(!(gr_status & GR_READY)))
45929+ return 0;
45930+
45931+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
45932+ gr_log_learn_id_change('u', real, effective, fs);
45933+
45934+ num = current->acl->user_trans_num;
45935+ uidlist = current->acl->user_transitions;
45936+
45937+ if (uidlist == NULL)
45938+ return 0;
45939+
45940+ if (real == -1)
45941+ realok = 1;
45942+ if (effective == -1)
45943+ effectiveok = 1;
45944+ if (fs == -1)
45945+ fsok = 1;
45946+
45947+ if (current->acl->user_trans_type & GR_ID_ALLOW) {
45948+ for (i = 0; i < num; i++) {
45949+ curuid = (int)uidlist[i];
45950+ if (real == curuid)
45951+ realok = 1;
45952+ if (effective == curuid)
45953+ effectiveok = 1;
45954+ if (fs == curuid)
45955+ fsok = 1;
45956+ }
45957+ } else if (current->acl->user_trans_type & GR_ID_DENY) {
45958+ for (i = 0; i < num; i++) {
45959+ curuid = (int)uidlist[i];
45960+ if (real == curuid)
45961+ break;
45962+ if (effective == curuid)
45963+ break;
45964+ if (fs == curuid)
45965+ break;
45966+ }
45967+ /* not in deny list */
45968+ if (i == num) {
45969+ realok = 1;
45970+ effectiveok = 1;
45971+ fsok = 1;
45972+ }
45973+ }
45974+
45975+ if (realok && effectiveok && fsok)
45976+ return 0;
45977+ else {
45978+ gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
45979+ return 1;
45980+ }
45981+}
45982+
45983+int
45984+gr_check_group_change(int real, int effective, int fs)
45985+{
45986+ unsigned int i;
45987+ __u16 num;
45988+ gid_t *gidlist;
45989+ int curgid;
45990+ int realok = 0;
45991+ int effectiveok = 0;
45992+ int fsok = 0;
45993+
45994+ if (unlikely(!(gr_status & GR_READY)))
45995+ return 0;
45996+
45997+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
45998+ gr_log_learn_id_change('g', real, effective, fs);
45999+
46000+ num = current->acl->group_trans_num;
46001+ gidlist = current->acl->group_transitions;
46002+
46003+ if (gidlist == NULL)
46004+ return 0;
46005+
46006+ if (real == -1)
46007+ realok = 1;
46008+ if (effective == -1)
46009+ effectiveok = 1;
46010+ if (fs == -1)
46011+ fsok = 1;
46012+
46013+ if (current->acl->group_trans_type & GR_ID_ALLOW) {
46014+ for (i = 0; i < num; i++) {
46015+ curgid = (int)gidlist[i];
46016+ if (real == curgid)
46017+ realok = 1;
46018+ if (effective == curgid)
46019+ effectiveok = 1;
46020+ if (fs == curgid)
46021+ fsok = 1;
46022+ }
46023+ } else if (current->acl->group_trans_type & GR_ID_DENY) {
46024+ for (i = 0; i < num; i++) {
46025+ curgid = (int)gidlist[i];
46026+ if (real == curgid)
46027+ break;
46028+ if (effective == curgid)
46029+ break;
46030+ if (fs == curgid)
46031+ break;
46032+ }
46033+ /* not in deny list */
46034+ if (i == num) {
46035+ realok = 1;
46036+ effectiveok = 1;
46037+ fsok = 1;
46038+ }
46039+ }
46040+
46041+ if (realok && effectiveok && fsok)
46042+ return 0;
46043+ else {
46044+ gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
46045+ return 1;
46046+ }
46047+}
46048+
46049+void
46050+gr_set_role_label(struct task_struct *task, const uid_t uid, const uid_t gid)
46051+{
46052+ struct acl_role_label *role = task->role;
46053+ struct acl_subject_label *subj = NULL;
46054+ struct acl_object_label *obj;
46055+ struct file *filp;
46056+
46057+ if (unlikely(!(gr_status & GR_READY)))
46058+ return;
46059+
46060+ filp = task->exec_file;
46061+
46062+ /* kernel process, we'll give them the kernel role */
46063+ if (unlikely(!filp)) {
46064+ task->role = kernel_role;
46065+ task->acl = kernel_role->root_label;
46066+ return;
46067+ } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
46068+ role = lookup_acl_role_label(task, uid, gid);
46069+
46070+ /* perform subject lookup in possibly new role
46071+ we can use this result below in the case where role == task->role
46072+ */
46073+ subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
46074+
46075+ /* if we changed uid/gid, but result in the same role
46076+ and are using inheritance, don't lose the inherited subject
46077+ if current subject is other than what normal lookup
46078+ would result in, we arrived via inheritance, don't
46079+ lose subject
46080+ */
46081+ if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
46082+ (subj == task->acl)))
46083+ task->acl = subj;
46084+
46085+ task->role = role;
46086+
46087+ task->is_writable = 0;
46088+
46089+ /* ignore additional mmap checks for processes that are writable
46090+ by the default ACL */
46091+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
46092+ if (unlikely(obj->mode & GR_WRITE))
46093+ task->is_writable = 1;
46094+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
46095+ if (unlikely(obj->mode & GR_WRITE))
46096+ task->is_writable = 1;
46097+
46098+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
46099+ printk(KERN_ALERT "Set role label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
46100+#endif
46101+
46102+ gr_set_proc_res(task);
46103+
46104+ return;
46105+}
46106+
46107+int
46108+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
46109+ const int unsafe_share)
46110+{
46111+ struct task_struct *task = current;
46112+ struct acl_subject_label *newacl;
46113+ struct acl_object_label *obj;
46114+ __u32 retmode;
46115+
46116+ if (unlikely(!(gr_status & GR_READY)))
46117+ return 0;
46118+
46119+ newacl = chk_subj_label(dentry, mnt, task->role);
46120+
46121+ task_lock(task);
46122+ if ((((task->ptrace & PT_PTRACED) || unsafe_share) &&
46123+ !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
46124+ !(task->role->roletype & GR_ROLE_GOD) &&
46125+ !gr_search_file(dentry, GR_PTRACERD, mnt) &&
46126+ !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN)))) {
46127+ task_unlock(task);
46128+ if (unsafe_share)
46129+ gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
46130+ else
46131+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
46132+ return -EACCES;
46133+ }
46134+ task_unlock(task);
46135+
46136+ obj = chk_obj_label(dentry, mnt, task->acl);
46137+ retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
46138+
46139+ if (!(task->acl->mode & GR_INHERITLEARN) &&
46140+ ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
46141+ if (obj->nested)
46142+ task->acl = obj->nested;
46143+ else
46144+ task->acl = newacl;
46145+ } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
46146+ gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
46147+
46148+ task->is_writable = 0;
46149+
46150+ /* ignore additional mmap checks for processes that are writable
46151+ by the default ACL */
46152+ obj = chk_obj_label(dentry, mnt, default_role->root_label);
46153+ if (unlikely(obj->mode & GR_WRITE))
46154+ task->is_writable = 1;
46155+ obj = chk_obj_label(dentry, mnt, task->role->root_label);
46156+ if (unlikely(obj->mode & GR_WRITE))
46157+ task->is_writable = 1;
46158+
46159+ gr_set_proc_res(task);
46160+
46161+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
46162+ printk(KERN_ALERT "Set subject label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
46163+#endif
46164+ return 0;
46165+}
46166+
46167+/* always called with valid inodev ptr */
46168+static void
46169+do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
46170+{
46171+ struct acl_object_label *matchpo;
46172+ struct acl_subject_label *matchps;
46173+ struct acl_subject_label *subj;
46174+ struct acl_role_label *role;
46175+ unsigned int x;
46176+
46177+ FOR_EACH_ROLE_START(role)
46178+ FOR_EACH_SUBJECT_START(role, subj, x)
46179+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
46180+ matchpo->mode |= GR_DELETED;
46181+ FOR_EACH_SUBJECT_END(subj,x)
46182+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
46183+ if (subj->inode == ino && subj->device == dev)
46184+ subj->mode |= GR_DELETED;
46185+ FOR_EACH_NESTED_SUBJECT_END(subj)
46186+ if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
46187+ matchps->mode |= GR_DELETED;
46188+ FOR_EACH_ROLE_END(role)
46189+
46190+ inodev->nentry->deleted = 1;
46191+
46192+ return;
46193+}
46194+
46195+void
46196+gr_handle_delete(const ino_t ino, const dev_t dev)
46197+{
46198+ struct inodev_entry *inodev;
46199+
46200+ if (unlikely(!(gr_status & GR_READY)))
46201+ return;
46202+
46203+ write_lock(&gr_inode_lock);
46204+ inodev = lookup_inodev_entry(ino, dev);
46205+ if (inodev != NULL)
46206+ do_handle_delete(inodev, ino, dev);
46207+ write_unlock(&gr_inode_lock);
46208+
46209+ return;
46210+}
46211+
46212+static void
46213+update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
46214+ const ino_t newinode, const dev_t newdevice,
46215+ struct acl_subject_label *subj)
46216+{
46217+ unsigned int index = fhash(oldinode, olddevice, subj->obj_hash_size);
46218+ struct acl_object_label *match;
46219+
46220+ match = subj->obj_hash[index];
46221+
46222+ while (match && (match->inode != oldinode ||
46223+ match->device != olddevice ||
46224+ !(match->mode & GR_DELETED)))
46225+ match = match->next;
46226+
46227+ if (match && (match->inode == oldinode)
46228+ && (match->device == olddevice)
46229+ && (match->mode & GR_DELETED)) {
46230+ if (match->prev == NULL) {
46231+ subj->obj_hash[index] = match->next;
46232+ if (match->next != NULL)
46233+ match->next->prev = NULL;
46234+ } else {
46235+ match->prev->next = match->next;
46236+ if (match->next != NULL)
46237+ match->next->prev = match->prev;
46238+ }
46239+ match->prev = NULL;
46240+ match->next = NULL;
46241+ match->inode = newinode;
46242+ match->device = newdevice;
46243+ match->mode &= ~GR_DELETED;
46244+
46245+ insert_acl_obj_label(match, subj);
46246+ }
46247+
46248+ return;
46249+}
46250+
46251+static void
46252+update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
46253+ const ino_t newinode, const dev_t newdevice,
46254+ struct acl_role_label *role)
46255+{
46256+ unsigned int index = fhash(oldinode, olddevice, role->subj_hash_size);
46257+ struct acl_subject_label *match;
46258+
46259+ match = role->subj_hash[index];
46260+
46261+ while (match && (match->inode != oldinode ||
46262+ match->device != olddevice ||
46263+ !(match->mode & GR_DELETED)))
46264+ match = match->next;
46265+
46266+ if (match && (match->inode == oldinode)
46267+ && (match->device == olddevice)
46268+ && (match->mode & GR_DELETED)) {
46269+ if (match->prev == NULL) {
46270+ role->subj_hash[index] = match->next;
46271+ if (match->next != NULL)
46272+ match->next->prev = NULL;
46273+ } else {
46274+ match->prev->next = match->next;
46275+ if (match->next != NULL)
46276+ match->next->prev = match->prev;
46277+ }
46278+ match->prev = NULL;
46279+ match->next = NULL;
46280+ match->inode = newinode;
46281+ match->device = newdevice;
46282+ match->mode &= ~GR_DELETED;
46283+
46284+ insert_acl_subj_label(match, role);
46285+ }
46286+
46287+ return;
46288+}
46289+
46290+static void
46291+update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
46292+ const ino_t newinode, const dev_t newdevice)
46293+{
46294+ unsigned int index = fhash(oldinode, olddevice, inodev_set.i_size);
46295+ struct inodev_entry *match;
46296+
46297+ match = inodev_set.i_hash[index];
46298+
46299+ while (match && (match->nentry->inode != oldinode ||
46300+ match->nentry->device != olddevice || !match->nentry->deleted))
46301+ match = match->next;
46302+
46303+ if (match && (match->nentry->inode == oldinode)
46304+ && (match->nentry->device == olddevice) &&
46305+ match->nentry->deleted) {
46306+ if (match->prev == NULL) {
46307+ inodev_set.i_hash[index] = match->next;
46308+ if (match->next != NULL)
46309+ match->next->prev = NULL;
46310+ } else {
46311+ match->prev->next = match->next;
46312+ if (match->next != NULL)
46313+ match->next->prev = match->prev;
46314+ }
46315+ match->prev = NULL;
46316+ match->next = NULL;
46317+ match->nentry->inode = newinode;
46318+ match->nentry->device = newdevice;
46319+ match->nentry->deleted = 0;
46320+
46321+ insert_inodev_entry(match);
46322+ }
46323+
46324+ return;
46325+}
46326+
46327+static void
46328+do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
46329+ const struct vfsmount *mnt)
46330+{
46331+ struct acl_subject_label *subj;
46332+ struct acl_role_label *role;
46333+ unsigned int x;
46334+ ino_t inode = dentry->d_inode->i_ino;
46335+ dev_t dev = __get_dev(dentry);
46336+
46337+ FOR_EACH_ROLE_START(role)
46338+ update_acl_subj_label(matchn->inode, matchn->device,
46339+ inode, dev, role);
46340+
46341+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
46342+ if ((subj->inode == inode) && (subj->device == dev)) {
46343+ subj->inode = inode;
46344+ subj->device = dev;
46345+ }
46346+ FOR_EACH_NESTED_SUBJECT_END(subj)
46347+ FOR_EACH_SUBJECT_START(role, subj, x)
46348+ update_acl_obj_label(matchn->inode, matchn->device,
46349+ inode, dev, subj);
46350+ FOR_EACH_SUBJECT_END(subj,x)
46351+ FOR_EACH_ROLE_END(role)
46352+
46353+ update_inodev_entry(matchn->inode, matchn->device, inode, dev);
46354+
46355+ return;
46356+}
46357+
46358+void
46359+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
46360+{
46361+ struct name_entry *matchn;
46362+
46363+ if (unlikely(!(gr_status & GR_READY)))
46364+ return;
46365+
46366+ preempt_disable();
46367+ matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
46368+
46369+ if (unlikely((unsigned long)matchn)) {
46370+ write_lock(&gr_inode_lock);
46371+ do_handle_create(matchn, dentry, mnt);
46372+ write_unlock(&gr_inode_lock);
46373+ }
46374+ preempt_enable();
46375+
46376+ return;
46377+}
46378+
46379+void
46380+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
46381+ struct dentry *old_dentry,
46382+ struct dentry *new_dentry,
46383+ struct vfsmount *mnt, const __u8 replace)
46384+{
46385+ struct name_entry *matchn;
46386+ struct inodev_entry *inodev;
46387+ ino_t oldinode = old_dentry->d_inode->i_ino;
46388+ dev_t olddev = __get_dev(old_dentry);
46389+
46390+ /* vfs_rename swaps the name and parent link for old_dentry and
46391+ new_dentry
46392+ at this point, old_dentry has the new name, parent link, and inode
46393+ for the renamed file
46394+ if a file is being replaced by a rename, new_dentry has the inode
46395+ and name for the replaced file
46396+ */
46397+
46398+ if (unlikely(!(gr_status & GR_READY)))
46399+ return;
46400+
46401+ preempt_disable();
46402+ matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
46403+
46404+ /* we wouldn't have to check d_inode if it weren't for
46405+ NFS silly-renaming
46406+ */
46407+
46408+ write_lock(&gr_inode_lock);
46409+ if (unlikely(replace && new_dentry->d_inode)) {
46410+ ino_t newinode = new_dentry->d_inode->i_ino;
46411+ dev_t newdev = __get_dev(new_dentry);
46412+ inodev = lookup_inodev_entry(newinode, newdev);
46413+ if (inodev != NULL && (new_dentry->d_inode->i_nlink <= 1))
46414+ do_handle_delete(inodev, newinode, newdev);
46415+ }
46416+
46417+ inodev = lookup_inodev_entry(oldinode, olddev);
46418+ if (inodev != NULL && (old_dentry->d_inode->i_nlink <= 1))
46419+ do_handle_delete(inodev, oldinode, olddev);
46420+
46421+ if (unlikely((unsigned long)matchn))
46422+ do_handle_create(matchn, old_dentry, mnt);
46423+
46424+ write_unlock(&gr_inode_lock);
46425+ preempt_enable();
46426+
46427+ return;
46428+}
46429+
46430+static int
46431+lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
46432+ unsigned char **sum)
46433+{
46434+ struct acl_role_label *r;
46435+ struct role_allowed_ip *ipp;
46436+ struct role_transition *trans;
46437+ unsigned int i;
46438+ int found = 0;
46439+ u32 curr_ip = current->signal->curr_ip;
46440+
46441+ current->signal->saved_ip = curr_ip;
46442+
46443+ /* check transition table */
46444+
46445+ for (trans = current->role->transitions; trans; trans = trans->next) {
46446+ if (!strcmp(rolename, trans->rolename)) {
46447+ found = 1;
46448+ break;
46449+ }
46450+ }
46451+
46452+ if (!found)
46453+ return 0;
46454+
46455+ /* handle special roles that do not require authentication
46456+ and check ip */
46457+
46458+ FOR_EACH_ROLE_START(r)
46459+ if (!strcmp(rolename, r->rolename) &&
46460+ (r->roletype & GR_ROLE_SPECIAL)) {
46461+ found = 0;
46462+ if (r->allowed_ips != NULL) {
46463+ for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
46464+ if ((ntohl(curr_ip) & ipp->netmask) ==
46465+ (ntohl(ipp->addr) & ipp->netmask))
46466+ found = 1;
46467+ }
46468+ } else
46469+ found = 2;
46470+ if (!found)
46471+ return 0;
46472+
46473+ if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
46474+ ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
46475+ *salt = NULL;
46476+ *sum = NULL;
46477+ return 1;
46478+ }
46479+ }
46480+ FOR_EACH_ROLE_END(r)
46481+
46482+ for (i = 0; i < num_sprole_pws; i++) {
46483+ if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
46484+ *salt = acl_special_roles[i]->salt;
46485+ *sum = acl_special_roles[i]->sum;
46486+ return 1;
46487+ }
46488+ }
46489+
46490+ return 0;
46491+}
46492+
46493+static void
46494+assign_special_role(char *rolename)
46495+{
46496+ struct acl_object_label *obj;
46497+ struct acl_role_label *r;
46498+ struct acl_role_label *assigned = NULL;
46499+ struct task_struct *tsk;
46500+ struct file *filp;
46501+
46502+ FOR_EACH_ROLE_START(r)
46503+ if (!strcmp(rolename, r->rolename) &&
46504+ (r->roletype & GR_ROLE_SPECIAL)) {
46505+ assigned = r;
46506+ break;
46507+ }
46508+ FOR_EACH_ROLE_END(r)
46509+
46510+ if (!assigned)
46511+ return;
46512+
46513+ read_lock(&tasklist_lock);
46514+ read_lock(&grsec_exec_file_lock);
46515+
46516+ tsk = current->real_parent;
46517+ if (tsk == NULL)
46518+ goto out_unlock;
46519+
46520+ filp = tsk->exec_file;
46521+ if (filp == NULL)
46522+ goto out_unlock;
46523+
46524+ tsk->is_writable = 0;
46525+
46526+ tsk->acl_sp_role = 1;
46527+ tsk->acl_role_id = ++acl_sp_role_value;
46528+ tsk->role = assigned;
46529+ tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
46530+
46531+ /* ignore additional mmap checks for processes that are writable
46532+ by the default ACL */
46533+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
46534+ if (unlikely(obj->mode & GR_WRITE))
46535+ tsk->is_writable = 1;
46536+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
46537+ if (unlikely(obj->mode & GR_WRITE))
46538+ tsk->is_writable = 1;
46539+
46540+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
46541+ printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename, tsk->acl->filename, tsk->comm, tsk->pid);
46542+#endif
46543+
46544+out_unlock:
46545+ read_unlock(&grsec_exec_file_lock);
46546+ read_unlock(&tasklist_lock);
46547+ return;
46548+}
46549+
46550+int gr_check_secure_terminal(struct task_struct *task)
46551+{
46552+ struct task_struct *p, *p2, *p3;
46553+ struct files_struct *files;
46554+ struct fdtable *fdt;
46555+ struct file *our_file = NULL, *file;
46556+ int i;
46557+
46558+ if (task->signal->tty == NULL)
46559+ return 1;
46560+
46561+ files = get_files_struct(task);
46562+ if (files != NULL) {
46563+ rcu_read_lock();
46564+ fdt = files_fdtable(files);
46565+ for (i=0; i < fdt->max_fds; i++) {
46566+ file = fcheck_files(files, i);
46567+ if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
46568+ get_file(file);
46569+ our_file = file;
46570+ }
46571+ }
46572+ rcu_read_unlock();
46573+ put_files_struct(files);
46574+ }
46575+
46576+ if (our_file == NULL)
46577+ return 1;
46578+
46579+ read_lock(&tasklist_lock);
46580+ do_each_thread(p2, p) {
46581+ files = get_files_struct(p);
46582+ if (files == NULL ||
46583+ (p->signal && p->signal->tty == task->signal->tty)) {
46584+ if (files != NULL)
46585+ put_files_struct(files);
46586+ continue;
46587+ }
46588+ rcu_read_lock();
46589+ fdt = files_fdtable(files);
46590+ for (i=0; i < fdt->max_fds; i++) {
46591+ file = fcheck_files(files, i);
46592+ if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
46593+ file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
46594+ p3 = task;
46595+ while (p3->pid > 0) {
46596+ if (p3 == p)
46597+ break;
46598+ p3 = p3->real_parent;
46599+ }
46600+ if (p3 == p)
46601+ break;
46602+ gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
46603+ gr_handle_alertkill(p);
46604+ rcu_read_unlock();
46605+ put_files_struct(files);
46606+ read_unlock(&tasklist_lock);
46607+ fput(our_file);
46608+ return 0;
46609+ }
46610+ }
46611+ rcu_read_unlock();
46612+ put_files_struct(files);
46613+ } while_each_thread(p2, p);
46614+ read_unlock(&tasklist_lock);
46615+
46616+ fput(our_file);
46617+ return 1;
46618+}
46619+
46620+ssize_t
46621+write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
46622+{
46623+ struct gr_arg_wrapper uwrap;
46624+ unsigned char *sprole_salt = NULL;
46625+ unsigned char *sprole_sum = NULL;
46626+ int error = sizeof (struct gr_arg_wrapper);
46627+ int error2 = 0;
46628+
46629+ mutex_lock(&gr_dev_mutex);
46630+
46631+ if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
46632+ error = -EPERM;
46633+ goto out;
46634+ }
46635+
46636+ if (count != sizeof (struct gr_arg_wrapper)) {
46637+ gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
46638+ error = -EINVAL;
46639+ goto out;
46640+ }
46641+
46642+
46643+ if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
46644+ gr_auth_expires = 0;
46645+ gr_auth_attempts = 0;
46646+ }
46647+
46648+ if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
46649+ error = -EFAULT;
46650+ goto out;
46651+ }
46652+
46653+ if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
46654+ error = -EINVAL;
46655+ goto out;
46656+ }
46657+
46658+ if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
46659+ error = -EFAULT;
46660+ goto out;
46661+ }
46662+
46663+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
46664+ gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
46665+ time_after(gr_auth_expires, get_seconds())) {
46666+ error = -EBUSY;
46667+ goto out;
46668+ }
46669+
46670+ /* if non-root trying to do anything other than use a special role,
46671+ do not attempt authentication, do not count towards authentication
46672+ locking
46673+ */
46674+
46675+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
46676+ gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
46677+ current_uid()) {
46678+ error = -EPERM;
46679+ goto out;
46680+ }
46681+
46682+ /* ensure pw and special role name are null terminated */
46683+
46684+ gr_usermode->pw[GR_PW_LEN - 1] = '\0';
46685+ gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
46686+
46687+ /* Okay.
46688+ * We have our enough of the argument structure..(we have yet
46689+ * to copy_from_user the tables themselves) . Copy the tables
46690+ * only if we need them, i.e. for loading operations. */
46691+
46692+ switch (gr_usermode->mode) {
46693+ case GR_STATUS:
46694+ if (gr_status & GR_READY) {
46695+ error = 1;
46696+ if (!gr_check_secure_terminal(current))
46697+ error = 3;
46698+ } else
46699+ error = 2;
46700+ goto out;
46701+ case GR_SHUTDOWN:
46702+ if ((gr_status & GR_READY)
46703+ && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
46704+ pax_open_kernel();
46705+ gr_status &= ~GR_READY;
46706+ pax_close_kernel();
46707+
46708+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
46709+ free_variables();
46710+ memset(gr_usermode, 0, sizeof (struct gr_arg));
46711+ memset(gr_system_salt, 0, GR_SALT_LEN);
46712+ memset(gr_system_sum, 0, GR_SHA_LEN);
46713+ } else if (gr_status & GR_READY) {
46714+ gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
46715+ error = -EPERM;
46716+ } else {
46717+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
46718+ error = -EAGAIN;
46719+ }
46720+ break;
46721+ case GR_ENABLE:
46722+ if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
46723+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
46724+ else {
46725+ if (gr_status & GR_READY)
46726+ error = -EAGAIN;
46727+ else
46728+ error = error2;
46729+ gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
46730+ }
46731+ break;
46732+ case GR_RELOAD:
46733+ if (!(gr_status & GR_READY)) {
46734+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
46735+ error = -EAGAIN;
46736+ } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
46737+ lock_kernel();
46738+
46739+ pax_open_kernel();
46740+ gr_status &= ~GR_READY;
46741+ pax_close_kernel();
46742+
46743+ free_variables();
46744+ if (!(error2 = gracl_init(gr_usermode))) {
46745+ unlock_kernel();
46746+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
46747+ } else {
46748+ unlock_kernel();
46749+ error = error2;
46750+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
46751+ }
46752+ } else {
46753+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
46754+ error = -EPERM;
46755+ }
46756+ break;
46757+ case GR_SEGVMOD:
46758+ if (unlikely(!(gr_status & GR_READY))) {
46759+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
46760+ error = -EAGAIN;
46761+ break;
46762+ }
46763+
46764+ if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
46765+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
46766+ if (gr_usermode->segv_device && gr_usermode->segv_inode) {
46767+ struct acl_subject_label *segvacl;
46768+ segvacl =
46769+ lookup_acl_subj_label(gr_usermode->segv_inode,
46770+ gr_usermode->segv_device,
46771+ current->role);
46772+ if (segvacl) {
46773+ segvacl->crashes = 0;
46774+ segvacl->expires = 0;
46775+ }
46776+ } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
46777+ gr_remove_uid(gr_usermode->segv_uid);
46778+ }
46779+ } else {
46780+ gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
46781+ error = -EPERM;
46782+ }
46783+ break;
46784+ case GR_SPROLE:
46785+ case GR_SPROLEPAM:
46786+ if (unlikely(!(gr_status & GR_READY))) {
46787+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
46788+ error = -EAGAIN;
46789+ break;
46790+ }
46791+
46792+ if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
46793+ current->role->expires = 0;
46794+ current->role->auth_attempts = 0;
46795+ }
46796+
46797+ if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
46798+ time_after(current->role->expires, get_seconds())) {
46799+ error = -EBUSY;
46800+ goto out;
46801+ }
46802+
46803+ if (lookup_special_role_auth
46804+ (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
46805+ && ((!sprole_salt && !sprole_sum)
46806+ || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
46807+ char *p = "";
46808+ assign_special_role(gr_usermode->sp_role);
46809+ read_lock(&tasklist_lock);
46810+ if (current->real_parent)
46811+ p = current->real_parent->role->rolename;
46812+ read_unlock(&tasklist_lock);
46813+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
46814+ p, acl_sp_role_value);
46815+ } else {
46816+ gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
46817+ error = -EPERM;
46818+ if(!(current->role->auth_attempts++))
46819+ current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
46820+
46821+ goto out;
46822+ }
46823+ break;
46824+ case GR_UNSPROLE:
46825+ if (unlikely(!(gr_status & GR_READY))) {
46826+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
46827+ error = -EAGAIN;
46828+ break;
46829+ }
46830+
46831+ if (current->role->roletype & GR_ROLE_SPECIAL) {
46832+ char *p = "";
46833+ int i = 0;
46834+
46835+ read_lock(&tasklist_lock);
46836+ if (current->real_parent) {
46837+ p = current->real_parent->role->rolename;
46838+ i = current->real_parent->acl_role_id;
46839+ }
46840+ read_unlock(&tasklist_lock);
46841+
46842+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
46843+ gr_set_acls(1);
46844+ } else {
46845+ error = -EPERM;
46846+ goto out;
46847+ }
46848+ break;
46849+ default:
46850+ gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
46851+ error = -EINVAL;
46852+ break;
46853+ }
46854+
46855+ if (error != -EPERM)
46856+ goto out;
46857+
46858+ if(!(gr_auth_attempts++))
46859+ gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
46860+
46861+ out:
46862+ mutex_unlock(&gr_dev_mutex);
46863+ return error;
46864+}
46865+
46866+/* must be called with
46867+ rcu_read_lock();
46868+ read_lock(&tasklist_lock);
46869+ read_lock(&grsec_exec_file_lock);
46870+*/
46871+int gr_apply_subject_to_task(struct task_struct *task)
46872+{
46873+ struct acl_object_label *obj;
46874+ char *tmpname;
46875+ struct acl_subject_label *tmpsubj;
46876+ struct file *filp;
46877+ struct name_entry *nmatch;
46878+
46879+ filp = task->exec_file;
46880+ if (filp == NULL)
46881+ return 0;
46882+
46883+ /* the following is to apply the correct subject
46884+ on binaries running when the RBAC system
46885+ is enabled, when the binaries have been
46886+ replaced or deleted since their execution
46887+ -----
46888+ when the RBAC system starts, the inode/dev
46889+ from exec_file will be one the RBAC system
46890+ is unaware of. It only knows the inode/dev
46891+ of the present file on disk, or the absence
46892+ of it.
46893+ */
46894+ preempt_disable();
46895+ tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
46896+
46897+ nmatch = lookup_name_entry(tmpname);
46898+ preempt_enable();
46899+ tmpsubj = NULL;
46900+ if (nmatch) {
46901+ if (nmatch->deleted)
46902+ tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
46903+ else
46904+ tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
46905+ if (tmpsubj != NULL)
46906+ task->acl = tmpsubj;
46907+ }
46908+ if (tmpsubj == NULL)
46909+ task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
46910+ task->role);
46911+ if (task->acl) {
46912+ struct acl_subject_label *curr;
46913+ curr = task->acl;
46914+
46915+ task->is_writable = 0;
46916+ /* ignore additional mmap checks for processes that are writable
46917+ by the default ACL */
46918+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
46919+ if (unlikely(obj->mode & GR_WRITE))
46920+ task->is_writable = 1;
46921+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
46922+ if (unlikely(obj->mode & GR_WRITE))
46923+ task->is_writable = 1;
46924+
46925+ gr_set_proc_res(task);
46926+
46927+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
46928+ printk(KERN_ALERT "gr_set_acls for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
46929+#endif
46930+ } else {
46931+ return 1;
46932+ }
46933+
46934+ return 0;
46935+}
46936+
46937+int
46938+gr_set_acls(const int type)
46939+{
46940+ struct task_struct *task, *task2;
46941+ struct acl_role_label *role = current->role;
46942+ __u16 acl_role_id = current->acl_role_id;
46943+ const struct cred *cred;
46944+ int ret;
46945+
46946+ rcu_read_lock();
46947+ read_lock(&tasklist_lock);
46948+ read_lock(&grsec_exec_file_lock);
46949+ do_each_thread(task2, task) {
46950+ /* check to see if we're called from the exit handler,
46951+ if so, only replace ACLs that have inherited the admin
46952+ ACL */
46953+
46954+ if (type && (task->role != role ||
46955+ task->acl_role_id != acl_role_id))
46956+ continue;
46957+
46958+ task->acl_role_id = 0;
46959+ task->acl_sp_role = 0;
46960+
46961+ if (task->exec_file) {
46962+ cred = __task_cred(task);
46963+ task->role = lookup_acl_role_label(task, cred->uid, cred->gid);
46964+
46965+ ret = gr_apply_subject_to_task(task);
46966+ if (ret) {
46967+ read_unlock(&grsec_exec_file_lock);
46968+ read_unlock(&tasklist_lock);
46969+ rcu_read_unlock();
46970+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task->pid);
46971+ return ret;
46972+ }
46973+ } else {
46974+ // it's a kernel process
46975+ task->role = kernel_role;
46976+ task->acl = kernel_role->root_label;
46977+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
46978+ task->acl->mode &= ~GR_PROCFIND;
46979+#endif
46980+ }
46981+ } while_each_thread(task2, task);
46982+ read_unlock(&grsec_exec_file_lock);
46983+ read_unlock(&tasklist_lock);
46984+ rcu_read_unlock();
46985+
46986+ return 0;
46987+}
46988+
46989+void
46990+gr_learn_resource(const struct task_struct *task,
46991+ const int res, const unsigned long wanted, const int gt)
46992+{
46993+ struct acl_subject_label *acl;
46994+ const struct cred *cred;
46995+
46996+ if (unlikely((gr_status & GR_READY) &&
46997+ task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
46998+ goto skip_reslog;
46999+
47000+#ifdef CONFIG_GRKERNSEC_RESLOG
47001+ gr_log_resource(task, res, wanted, gt);
47002+#endif
47003+ skip_reslog:
47004+
47005+ if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
47006+ return;
47007+
47008+ acl = task->acl;
47009+
47010+ if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
47011+ !(acl->resmask & (1 << (unsigned short) res))))
47012+ return;
47013+
47014+ if (wanted >= acl->res[res].rlim_cur) {
47015+ unsigned long res_add;
47016+
47017+ res_add = wanted;
47018+ switch (res) {
47019+ case RLIMIT_CPU:
47020+ res_add += GR_RLIM_CPU_BUMP;
47021+ break;
47022+ case RLIMIT_FSIZE:
47023+ res_add += GR_RLIM_FSIZE_BUMP;
47024+ break;
47025+ case RLIMIT_DATA:
47026+ res_add += GR_RLIM_DATA_BUMP;
47027+ break;
47028+ case RLIMIT_STACK:
47029+ res_add += GR_RLIM_STACK_BUMP;
47030+ break;
47031+ case RLIMIT_CORE:
47032+ res_add += GR_RLIM_CORE_BUMP;
47033+ break;
47034+ case RLIMIT_RSS:
47035+ res_add += GR_RLIM_RSS_BUMP;
47036+ break;
47037+ case RLIMIT_NPROC:
47038+ res_add += GR_RLIM_NPROC_BUMP;
47039+ break;
47040+ case RLIMIT_NOFILE:
47041+ res_add += GR_RLIM_NOFILE_BUMP;
47042+ break;
47043+ case RLIMIT_MEMLOCK:
47044+ res_add += GR_RLIM_MEMLOCK_BUMP;
47045+ break;
47046+ case RLIMIT_AS:
47047+ res_add += GR_RLIM_AS_BUMP;
47048+ break;
47049+ case RLIMIT_LOCKS:
47050+ res_add += GR_RLIM_LOCKS_BUMP;
47051+ break;
47052+ case RLIMIT_SIGPENDING:
47053+ res_add += GR_RLIM_SIGPENDING_BUMP;
47054+ break;
47055+ case RLIMIT_MSGQUEUE:
47056+ res_add += GR_RLIM_MSGQUEUE_BUMP;
47057+ break;
47058+ case RLIMIT_NICE:
47059+ res_add += GR_RLIM_NICE_BUMP;
47060+ break;
47061+ case RLIMIT_RTPRIO:
47062+ res_add += GR_RLIM_RTPRIO_BUMP;
47063+ break;
47064+ case RLIMIT_RTTIME:
47065+ res_add += GR_RLIM_RTTIME_BUMP;
47066+ break;
47067+ }
47068+
47069+ acl->res[res].rlim_cur = res_add;
47070+
47071+ if (wanted > acl->res[res].rlim_max)
47072+ acl->res[res].rlim_max = res_add;
47073+
47074+ /* only log the subject filename, since resource logging is supported for
47075+ single-subject learning only */
47076+ rcu_read_lock();
47077+ cred = __task_cred(task);
47078+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
47079+ task->role->roletype, cred->uid, cred->gid, acl->filename,
47080+ acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
47081+ "", (unsigned long) res, &task->signal->saved_ip);
47082+ rcu_read_unlock();
47083+ }
47084+
47085+ return;
47086+}
47087+
47088+#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
47089+void
47090+pax_set_initial_flags(struct linux_binprm *bprm)
47091+{
47092+ struct task_struct *task = current;
47093+ struct acl_subject_label *proc;
47094+ unsigned long flags;
47095+
47096+ if (unlikely(!(gr_status & GR_READY)))
47097+ return;
47098+
47099+ flags = pax_get_flags(task);
47100+
47101+ proc = task->acl;
47102+
47103+ if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
47104+ flags &= ~MF_PAX_PAGEEXEC;
47105+ if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
47106+ flags &= ~MF_PAX_SEGMEXEC;
47107+ if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
47108+ flags &= ~MF_PAX_RANDMMAP;
47109+ if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
47110+ flags &= ~MF_PAX_EMUTRAMP;
47111+ if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
47112+ flags &= ~MF_PAX_MPROTECT;
47113+
47114+ if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
47115+ flags |= MF_PAX_PAGEEXEC;
47116+ if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
47117+ flags |= MF_PAX_SEGMEXEC;
47118+ if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
47119+ flags |= MF_PAX_RANDMMAP;
47120+ if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
47121+ flags |= MF_PAX_EMUTRAMP;
47122+ if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
47123+ flags |= MF_PAX_MPROTECT;
47124+
47125+ pax_set_flags(task, flags);
47126+
47127+ return;
47128+}
47129+#endif
47130+
47131+#ifdef CONFIG_SYSCTL
47132+/* Eric Biederman likes breaking userland ABI and every inode-based security
47133+ system to save 35kb of memory */
47134+
47135+/* we modify the passed in filename, but adjust it back before returning */
47136+static struct acl_object_label *gr_lookup_by_name(char *name, unsigned int len)
47137+{
47138+ struct name_entry *nmatch;
47139+ char *p, *lastp = NULL;
47140+ struct acl_object_label *obj = NULL, *tmp;
47141+ struct acl_subject_label *tmpsubj;
47142+ char c = '\0';
47143+
47144+ read_lock(&gr_inode_lock);
47145+
47146+ p = name + len - 1;
47147+ do {
47148+ nmatch = lookup_name_entry(name);
47149+ if (lastp != NULL)
47150+ *lastp = c;
47151+
47152+ if (nmatch == NULL)
47153+ goto next_component;
47154+ tmpsubj = current->acl;
47155+ do {
47156+ obj = lookup_acl_obj_label(nmatch->inode, nmatch->device, tmpsubj);
47157+ if (obj != NULL) {
47158+ tmp = obj->globbed;
47159+ while (tmp) {
47160+ if (!glob_match(tmp->filename, name)) {
47161+ obj = tmp;
47162+ goto found_obj;
47163+ }
47164+ tmp = tmp->next;
47165+ }
47166+ goto found_obj;
47167+ }
47168+ } while ((tmpsubj = tmpsubj->parent_subject));
47169+next_component:
47170+ /* end case */
47171+ if (p == name)
47172+ break;
47173+
47174+ while (*p != '/')
47175+ p--;
47176+ if (p == name)
47177+ lastp = p + 1;
47178+ else {
47179+ lastp = p;
47180+ p--;
47181+ }
47182+ c = *lastp;
47183+ *lastp = '\0';
47184+ } while (1);
47185+found_obj:
47186+ read_unlock(&gr_inode_lock);
47187+ /* obj returned will always be non-null */
47188+ return obj;
47189+}
47190+
47191+/* returns 0 when allowing, non-zero on error
47192+ op of 0 is used for readdir, so we don't log the names of hidden files
47193+*/
47194+__u32
47195+gr_handle_sysctl(const struct ctl_table *table, const int op)
47196+{
47197+ ctl_table *tmp;
47198+ const char *proc_sys = "/proc/sys";
47199+ char *path;
47200+ struct acl_object_label *obj;
47201+ unsigned short len = 0, pos = 0, depth = 0, i;
47202+ __u32 err = 0;
47203+ __u32 mode = 0;
47204+
47205+ if (unlikely(!(gr_status & GR_READY)))
47206+ return 0;
47207+
47208+ /* for now, ignore operations on non-sysctl entries if it's not a
47209+ readdir*/
47210+ if (table->child != NULL && op != 0)
47211+ return 0;
47212+
47213+ mode |= GR_FIND;
47214+ /* it's only a read if it's an entry, read on dirs is for readdir */
47215+ if (op & MAY_READ)
47216+ mode |= GR_READ;
47217+ if (op & MAY_WRITE)
47218+ mode |= GR_WRITE;
47219+
47220+ preempt_disable();
47221+
47222+ path = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
47223+
47224+ /* it's only a read/write if it's an actual entry, not a dir
47225+ (which are opened for readdir)
47226+ */
47227+
47228+ /* convert the requested sysctl entry into a pathname */
47229+
47230+ for (tmp = (ctl_table *)table; tmp != NULL; tmp = tmp->parent) {
47231+ len += strlen(tmp->procname);
47232+ len++;
47233+ depth++;
47234+ }
47235+
47236+ if ((len + depth + strlen(proc_sys) + 1) > PAGE_SIZE) {
47237+ /* deny */
47238+ goto out;
47239+ }
47240+
47241+ memset(path, 0, PAGE_SIZE);
47242+
47243+ memcpy(path, proc_sys, strlen(proc_sys));
47244+
47245+ pos += strlen(proc_sys);
47246+
47247+ for (; depth > 0; depth--) {
47248+ path[pos] = '/';
47249+ pos++;
47250+ for (i = 1, tmp = (ctl_table *)table; tmp != NULL; tmp = tmp->parent) {
47251+ if (depth == i) {
47252+ memcpy(path + pos, tmp->procname,
47253+ strlen(tmp->procname));
47254+ pos += strlen(tmp->procname);
47255+ }
47256+ i++;
47257+ }
47258+ }
47259+
47260+ obj = gr_lookup_by_name(path, pos);
47261+ err = obj->mode & (mode | to_gr_audit(mode) | GR_SUPPRESS);
47262+
47263+ if (unlikely((current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) &&
47264+ ((err & mode) != mode))) {
47265+ __u32 new_mode = mode;
47266+
47267+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
47268+
47269+ err = 0;
47270+ gr_log_learn_sysctl(path, new_mode);
47271+ } else if (!(err & GR_FIND) && !(err & GR_SUPPRESS) && op != 0) {
47272+ gr_log_hidden_sysctl(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, path);
47273+ err = -ENOENT;
47274+ } else if (!(err & GR_FIND)) {
47275+ err = -ENOENT;
47276+ } else if (((err & mode) & ~GR_FIND) != (mode & ~GR_FIND) && !(err & GR_SUPPRESS)) {
47277+ gr_log_str4(GR_DONT_AUDIT, GR_SYSCTL_ACL_MSG, "denied",
47278+ path, (mode & GR_READ) ? " reading" : "",
47279+ (mode & GR_WRITE) ? " writing" : "");
47280+ err = -EACCES;
47281+ } else if ((err & mode) != mode) {
47282+ err = -EACCES;
47283+ } else if ((((err & mode) & ~GR_FIND) == (mode & ~GR_FIND)) && (err & GR_AUDITS)) {
47284+ gr_log_str4(GR_DO_AUDIT, GR_SYSCTL_ACL_MSG, "successful",
47285+ path, (mode & GR_READ) ? " reading" : "",
47286+ (mode & GR_WRITE) ? " writing" : "");
47287+ err = 0;
47288+ } else
47289+ err = 0;
47290+
47291+ out:
47292+ preempt_enable();
47293+
47294+ return err;
47295+}
47296+#endif
47297+
47298+int
47299+gr_handle_proc_ptrace(struct task_struct *task)
47300+{
47301+ struct file *filp;
47302+ struct task_struct *tmp = task;
47303+ struct task_struct *curtemp = current;
47304+ __u32 retmode;
47305+
47306+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
47307+ if (unlikely(!(gr_status & GR_READY)))
47308+ return 0;
47309+#endif
47310+
47311+ read_lock(&tasklist_lock);
47312+ read_lock(&grsec_exec_file_lock);
47313+ filp = task->exec_file;
47314+
47315+ while (tmp->pid > 0) {
47316+ if (tmp == curtemp)
47317+ break;
47318+ tmp = tmp->real_parent;
47319+ }
47320+
47321+ if (!filp || (tmp->pid == 0 && ((grsec_enable_harden_ptrace && current_uid() && !(gr_status & GR_READY)) ||
47322+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
47323+ read_unlock(&grsec_exec_file_lock);
47324+ read_unlock(&tasklist_lock);
47325+ return 1;
47326+ }
47327+
47328+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
47329+ if (!(gr_status & GR_READY)) {
47330+ read_unlock(&grsec_exec_file_lock);
47331+ read_unlock(&tasklist_lock);
47332+ return 0;
47333+ }
47334+#endif
47335+
47336+ retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
47337+ read_unlock(&grsec_exec_file_lock);
47338+ read_unlock(&tasklist_lock);
47339+
47340+ if (retmode & GR_NOPTRACE)
47341+ return 1;
47342+
47343+ if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
47344+ && (current->acl != task->acl || (current->acl != current->role->root_label
47345+ && current->pid != task->pid)))
47346+ return 1;
47347+
47348+ return 0;
47349+}
47350+
47351+void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
47352+{
47353+ if (unlikely(!(gr_status & GR_READY)))
47354+ return;
47355+
47356+ if (!(current->role->roletype & GR_ROLE_GOD))
47357+ return;
47358+
47359+ seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
47360+ p->role->rolename, gr_task_roletype_to_char(p),
47361+ p->acl->filename);
47362+}
47363+
47364+int
47365+gr_handle_ptrace(struct task_struct *task, const long request)
47366+{
47367+ struct task_struct *tmp = task;
47368+ struct task_struct *curtemp = current;
47369+ __u32 retmode;
47370+
47371+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
47372+ if (unlikely(!(gr_status & GR_READY)))
47373+ return 0;
47374+#endif
47375+
47376+ read_lock(&tasklist_lock);
47377+ while (tmp->pid > 0) {
47378+ if (tmp == curtemp)
47379+ break;
47380+ tmp = tmp->real_parent;
47381+ }
47382+
47383+ if (tmp->pid == 0 && ((grsec_enable_harden_ptrace && current_uid() && !(gr_status & GR_READY)) ||
47384+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
47385+ read_unlock(&tasklist_lock);
47386+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
47387+ return 1;
47388+ }
47389+ read_unlock(&tasklist_lock);
47390+
47391+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
47392+ if (!(gr_status & GR_READY))
47393+ return 0;
47394+#endif
47395+
47396+ read_lock(&grsec_exec_file_lock);
47397+ if (unlikely(!task->exec_file)) {
47398+ read_unlock(&grsec_exec_file_lock);
47399+ return 0;
47400+ }
47401+
47402+ retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
47403+ read_unlock(&grsec_exec_file_lock);
47404+
47405+ if (retmode & GR_NOPTRACE) {
47406+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
47407+ return 1;
47408+ }
47409+
47410+ if (retmode & GR_PTRACERD) {
47411+ switch (request) {
47412+ case PTRACE_POKETEXT:
47413+ case PTRACE_POKEDATA:
47414+ case PTRACE_POKEUSR:
47415+#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
47416+ case PTRACE_SETREGS:
47417+ case PTRACE_SETFPREGS:
47418+#endif
47419+#ifdef CONFIG_X86
47420+ case PTRACE_SETFPXREGS:
47421+#endif
47422+#ifdef CONFIG_ALTIVEC
47423+ case PTRACE_SETVRREGS:
47424+#endif
47425+ return 1;
47426+ default:
47427+ return 0;
47428+ }
47429+ } else if (!(current->acl->mode & GR_POVERRIDE) &&
47430+ !(current->role->roletype & GR_ROLE_GOD) &&
47431+ (current->acl != task->acl)) {
47432+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
47433+ return 1;
47434+ }
47435+
47436+ return 0;
47437+}
47438+
47439+static int is_writable_mmap(const struct file *filp)
47440+{
47441+ struct task_struct *task = current;
47442+ struct acl_object_label *obj, *obj2;
47443+
47444+ if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
47445+ !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))) {
47446+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
47447+ obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
47448+ task->role->root_label);
47449+ if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
47450+ gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
47451+ return 1;
47452+ }
47453+ }
47454+ return 0;
47455+}
47456+
47457+int
47458+gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
47459+{
47460+ __u32 mode;
47461+
47462+ if (unlikely(!file || !(prot & PROT_EXEC)))
47463+ return 1;
47464+
47465+ if (is_writable_mmap(file))
47466+ return 0;
47467+
47468+ mode =
47469+ gr_search_file(file->f_path.dentry,
47470+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
47471+ file->f_path.mnt);
47472+
47473+ if (!gr_tpe_allow(file))
47474+ return 0;
47475+
47476+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
47477+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
47478+ return 0;
47479+ } else if (unlikely(!(mode & GR_EXEC))) {
47480+ return 0;
47481+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
47482+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
47483+ return 1;
47484+ }
47485+
47486+ return 1;
47487+}
47488+
47489+int
47490+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
47491+{
47492+ __u32 mode;
47493+
47494+ if (unlikely(!file || !(prot & PROT_EXEC)))
47495+ return 1;
47496+
47497+ if (is_writable_mmap(file))
47498+ return 0;
47499+
47500+ mode =
47501+ gr_search_file(file->f_path.dentry,
47502+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
47503+ file->f_path.mnt);
47504+
47505+ if (!gr_tpe_allow(file))
47506+ return 0;
47507+
47508+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
47509+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
47510+ return 0;
47511+ } else if (unlikely(!(mode & GR_EXEC))) {
47512+ return 0;
47513+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
47514+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
47515+ return 1;
47516+ }
47517+
47518+ return 1;
47519+}
47520+
47521+void
47522+gr_acl_handle_psacct(struct task_struct *task, const long code)
47523+{
47524+ unsigned long runtime;
47525+ unsigned long cputime;
47526+ unsigned int wday, cday;
47527+ __u8 whr, chr;
47528+ __u8 wmin, cmin;
47529+ __u8 wsec, csec;
47530+ struct timespec timeval;
47531+
47532+ if (unlikely(!(gr_status & GR_READY) || !task->acl ||
47533+ !(task->acl->mode & GR_PROCACCT)))
47534+ return;
47535+
47536+ do_posix_clock_monotonic_gettime(&timeval);
47537+ runtime = timeval.tv_sec - task->start_time.tv_sec;
47538+ wday = runtime / (3600 * 24);
47539+ runtime -= wday * (3600 * 24);
47540+ whr = runtime / 3600;
47541+ runtime -= whr * 3600;
47542+ wmin = runtime / 60;
47543+ runtime -= wmin * 60;
47544+ wsec = runtime;
47545+
47546+ cputime = (task->utime + task->stime) / HZ;
47547+ cday = cputime / (3600 * 24);
47548+ cputime -= cday * (3600 * 24);
47549+ chr = cputime / 3600;
47550+ cputime -= chr * 3600;
47551+ cmin = cputime / 60;
47552+ cputime -= cmin * 60;
47553+ csec = cputime;
47554+
47555+ gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
47556+
47557+ return;
47558+}
47559+
47560+void gr_set_kernel_label(struct task_struct *task)
47561+{
47562+ if (gr_status & GR_READY) {
47563+ task->role = kernel_role;
47564+ task->acl = kernel_role->root_label;
47565+ }
47566+ return;
47567+}
47568+
47569+#ifdef CONFIG_TASKSTATS
47570+int gr_is_taskstats_denied(int pid)
47571+{
47572+ struct task_struct *task;
47573+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
47574+ const struct cred *cred;
47575+#endif
47576+ int ret = 0;
47577+
47578+ /* restrict taskstats viewing to un-chrooted root users
47579+ who have the 'view' subject flag if the RBAC system is enabled
47580+ */
47581+
47582+ rcu_read_lock();
47583+ read_lock(&tasklist_lock);
47584+ task = find_task_by_vpid(pid);
47585+ if (task) {
47586+#ifdef CONFIG_GRKERNSEC_CHROOT
47587+ if (proc_is_chrooted(task))
47588+ ret = -EACCES;
47589+#endif
47590+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
47591+ cred = __task_cred(task);
47592+#ifdef CONFIG_GRKERNSEC_PROC_USER
47593+ if (cred->uid != 0)
47594+ ret = -EACCES;
47595+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
47596+ if (cred->uid != 0 && !groups_search(cred->group_info, CONFIG_GRKERNSEC_PROC_GID))
47597+ ret = -EACCES;
47598+#endif
47599+#endif
47600+ if (gr_status & GR_READY) {
47601+ if (!(task->acl->mode & GR_VIEW))
47602+ ret = -EACCES;
47603+ }
47604+ } else
47605+ ret = -ENOENT;
47606+
47607+ read_unlock(&tasklist_lock);
47608+ rcu_read_unlock();
47609+
47610+ return ret;
47611+}
47612+#endif
47613+
47614+/* AUXV entries are filled via a descendant of search_binary_handler
47615+ after we've already applied the subject for the target
47616+*/
47617+int gr_acl_enable_at_secure(void)
47618+{
47619+ if (unlikely(!(gr_status & GR_READY)))
47620+ return 0;
47621+
47622+ if (current->acl->mode & GR_ATSECURE)
47623+ return 1;
47624+
47625+ return 0;
47626+}
47627+
47628+int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
47629+{
47630+ struct task_struct *task = current;
47631+ struct dentry *dentry = file->f_path.dentry;
47632+ struct vfsmount *mnt = file->f_path.mnt;
47633+ struct acl_object_label *obj, *tmp;
47634+ struct acl_subject_label *subj;
47635+ unsigned int bufsize;
47636+ int is_not_root;
47637+ char *path;
47638+ dev_t dev = __get_dev(dentry);
47639+
47640+ if (unlikely(!(gr_status & GR_READY)))
47641+ return 1;
47642+
47643+ if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
47644+ return 1;
47645+
47646+ /* ignore Eric Biederman */
47647+ if (IS_PRIVATE(dentry->d_inode))
47648+ return 1;
47649+
47650+ subj = task->acl;
47651+ do {
47652+ obj = lookup_acl_obj_label(ino, dev, subj);
47653+ if (obj != NULL)
47654+ return (obj->mode & GR_FIND) ? 1 : 0;
47655+ } while ((subj = subj->parent_subject));
47656+
47657+ /* this is purely an optimization since we're looking for an object
47658+ for the directory we're doing a readdir on
47659+ if it's possible for any globbed object to match the entry we're
47660+ filling into the directory, then the object we find here will be
47661+ an anchor point with attached globbed objects
47662+ */
47663+ obj = chk_obj_label_noglob(dentry, mnt, task->acl);
47664+ if (obj->globbed == NULL)
47665+ return (obj->mode & GR_FIND) ? 1 : 0;
47666+
47667+ is_not_root = ((obj->filename[0] == '/') &&
47668+ (obj->filename[1] == '\0')) ? 0 : 1;
47669+ bufsize = PAGE_SIZE - namelen - is_not_root;
47670+
47671+ /* check bufsize > PAGE_SIZE || bufsize == 0 */
47672+ if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
47673+ return 1;
47674+
47675+ preempt_disable();
47676+ path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
47677+ bufsize);
47678+
47679+ bufsize = strlen(path);
47680+
47681+ /* if base is "/", don't append an additional slash */
47682+ if (is_not_root)
47683+ *(path + bufsize) = '/';
47684+ memcpy(path + bufsize + is_not_root, name, namelen);
47685+ *(path + bufsize + namelen + is_not_root) = '\0';
47686+
47687+ tmp = obj->globbed;
47688+ while (tmp) {
47689+ if (!glob_match(tmp->filename, path)) {
47690+ preempt_enable();
47691+ return (tmp->mode & GR_FIND) ? 1 : 0;
47692+ }
47693+ tmp = tmp->next;
47694+ }
47695+ preempt_enable();
47696+ return (obj->mode & GR_FIND) ? 1 : 0;
47697+}
47698+
47699+#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
47700+EXPORT_SYMBOL(gr_acl_is_enabled);
47701+#endif
47702+EXPORT_SYMBOL(gr_learn_resource);
47703+EXPORT_SYMBOL(gr_set_kernel_label);
47704+#ifdef CONFIG_SECURITY
47705+EXPORT_SYMBOL(gr_check_user_change);
47706+EXPORT_SYMBOL(gr_check_group_change);
47707+#endif
47708+
47709diff -urNp linux-2.6.32.41/grsecurity/gracl_cap.c linux-2.6.32.41/grsecurity/gracl_cap.c
47710--- linux-2.6.32.41/grsecurity/gracl_cap.c 1969-12-31 19:00:00.000000000 -0500
47711+++ linux-2.6.32.41/grsecurity/gracl_cap.c 2011-04-17 15:56:46.000000000 -0400
47712@@ -0,0 +1,138 @@
47713+#include <linux/kernel.h>
47714+#include <linux/module.h>
47715+#include <linux/sched.h>
47716+#include <linux/gracl.h>
47717+#include <linux/grsecurity.h>
47718+#include <linux/grinternal.h>
47719+
47720+static const char *captab_log[] = {
47721+ "CAP_CHOWN",
47722+ "CAP_DAC_OVERRIDE",
47723+ "CAP_DAC_READ_SEARCH",
47724+ "CAP_FOWNER",
47725+ "CAP_FSETID",
47726+ "CAP_KILL",
47727+ "CAP_SETGID",
47728+ "CAP_SETUID",
47729+ "CAP_SETPCAP",
47730+ "CAP_LINUX_IMMUTABLE",
47731+ "CAP_NET_BIND_SERVICE",
47732+ "CAP_NET_BROADCAST",
47733+ "CAP_NET_ADMIN",
47734+ "CAP_NET_RAW",
47735+ "CAP_IPC_LOCK",
47736+ "CAP_IPC_OWNER",
47737+ "CAP_SYS_MODULE",
47738+ "CAP_SYS_RAWIO",
47739+ "CAP_SYS_CHROOT",
47740+ "CAP_SYS_PTRACE",
47741+ "CAP_SYS_PACCT",
47742+ "CAP_SYS_ADMIN",
47743+ "CAP_SYS_BOOT",
47744+ "CAP_SYS_NICE",
47745+ "CAP_SYS_RESOURCE",
47746+ "CAP_SYS_TIME",
47747+ "CAP_SYS_TTY_CONFIG",
47748+ "CAP_MKNOD",
47749+ "CAP_LEASE",
47750+ "CAP_AUDIT_WRITE",
47751+ "CAP_AUDIT_CONTROL",
47752+ "CAP_SETFCAP",
47753+ "CAP_MAC_OVERRIDE",
47754+ "CAP_MAC_ADMIN"
47755+};
47756+
47757+EXPORT_SYMBOL(gr_is_capable);
47758+EXPORT_SYMBOL(gr_is_capable_nolog);
47759+
47760+int
47761+gr_is_capable(const int cap)
47762+{
47763+ struct task_struct *task = current;
47764+ const struct cred *cred = current_cred();
47765+ struct acl_subject_label *curracl;
47766+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
47767+ kernel_cap_t cap_audit = __cap_empty_set;
47768+
47769+ if (!gr_acl_is_enabled())
47770+ return 1;
47771+
47772+ curracl = task->acl;
47773+
47774+ cap_drop = curracl->cap_lower;
47775+ cap_mask = curracl->cap_mask;
47776+ cap_audit = curracl->cap_invert_audit;
47777+
47778+ while ((curracl = curracl->parent_subject)) {
47779+ /* if the cap isn't specified in the current computed mask but is specified in the
47780+ current level subject, and is lowered in the current level subject, then add
47781+ it to the set of dropped capabilities
47782+ otherwise, add the current level subject's mask to the current computed mask
47783+ */
47784+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
47785+ cap_raise(cap_mask, cap);
47786+ if (cap_raised(curracl->cap_lower, cap))
47787+ cap_raise(cap_drop, cap);
47788+ if (cap_raised(curracl->cap_invert_audit, cap))
47789+ cap_raise(cap_audit, cap);
47790+ }
47791+ }
47792+
47793+ if (!cap_raised(cap_drop, cap)) {
47794+ if (cap_raised(cap_audit, cap))
47795+ gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
47796+ return 1;
47797+ }
47798+
47799+ curracl = task->acl;
47800+
47801+ if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
47802+ && cap_raised(cred->cap_effective, cap)) {
47803+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
47804+ task->role->roletype, cred->uid,
47805+ cred->gid, task->exec_file ?
47806+ gr_to_filename(task->exec_file->f_path.dentry,
47807+ task->exec_file->f_path.mnt) : curracl->filename,
47808+ curracl->filename, 0UL,
47809+ 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
47810+ return 1;
47811+ }
47812+
47813+ if ((cap >= 0) && (cap < (sizeof(captab_log)/sizeof(captab_log[0]))) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
47814+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
47815+ return 0;
47816+}
47817+
47818+int
47819+gr_is_capable_nolog(const int cap)
47820+{
47821+ struct acl_subject_label *curracl;
47822+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
47823+
47824+ if (!gr_acl_is_enabled())
47825+ return 1;
47826+
47827+ curracl = current->acl;
47828+
47829+ cap_drop = curracl->cap_lower;
47830+ cap_mask = curracl->cap_mask;
47831+
47832+ while ((curracl = curracl->parent_subject)) {
47833+ /* if the cap isn't specified in the current computed mask but is specified in the
47834+ current level subject, and is lowered in the current level subject, then add
47835+ it to the set of dropped capabilities
47836+ otherwise, add the current level subject's mask to the current computed mask
47837+ */
47838+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
47839+ cap_raise(cap_mask, cap);
47840+ if (cap_raised(curracl->cap_lower, cap))
47841+ cap_raise(cap_drop, cap);
47842+ }
47843+ }
47844+
47845+ if (!cap_raised(cap_drop, cap))
47846+ return 1;
47847+
47848+ return 0;
47849+}
47850+
47851diff -urNp linux-2.6.32.41/grsecurity/gracl_fs.c linux-2.6.32.41/grsecurity/gracl_fs.c
47852--- linux-2.6.32.41/grsecurity/gracl_fs.c 1969-12-31 19:00:00.000000000 -0500
47853+++ linux-2.6.32.41/grsecurity/gracl_fs.c 2011-04-17 15:56:46.000000000 -0400
47854@@ -0,0 +1,431 @@
47855+#include <linux/kernel.h>
47856+#include <linux/sched.h>
47857+#include <linux/types.h>
47858+#include <linux/fs.h>
47859+#include <linux/file.h>
47860+#include <linux/stat.h>
47861+#include <linux/grsecurity.h>
47862+#include <linux/grinternal.h>
47863+#include <linux/gracl.h>
47864+
47865+__u32
47866+gr_acl_handle_hidden_file(const struct dentry * dentry,
47867+ const struct vfsmount * mnt)
47868+{
47869+ __u32 mode;
47870+
47871+ if (unlikely(!dentry->d_inode))
47872+ return GR_FIND;
47873+
47874+ mode =
47875+ gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
47876+
47877+ if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
47878+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
47879+ return mode;
47880+ } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
47881+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
47882+ return 0;
47883+ } else if (unlikely(!(mode & GR_FIND)))
47884+ return 0;
47885+
47886+ return GR_FIND;
47887+}
47888+
47889+__u32
47890+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
47891+ const int fmode)
47892+{
47893+ __u32 reqmode = GR_FIND;
47894+ __u32 mode;
47895+
47896+ if (unlikely(!dentry->d_inode))
47897+ return reqmode;
47898+
47899+ if (unlikely(fmode & O_APPEND))
47900+ reqmode |= GR_APPEND;
47901+ else if (unlikely(fmode & FMODE_WRITE))
47902+ reqmode |= GR_WRITE;
47903+ if (likely((fmode & FMODE_READ) && !(fmode & O_DIRECTORY)))
47904+ reqmode |= GR_READ;
47905+ if ((fmode & FMODE_GREXEC) && (fmode & FMODE_EXEC))
47906+ reqmode &= ~GR_READ;
47907+ mode =
47908+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
47909+ mnt);
47910+
47911+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
47912+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
47913+ reqmode & GR_READ ? " reading" : "",
47914+ reqmode & GR_WRITE ? " writing" : reqmode &
47915+ GR_APPEND ? " appending" : "");
47916+ return reqmode;
47917+ } else
47918+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
47919+ {
47920+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
47921+ reqmode & GR_READ ? " reading" : "",
47922+ reqmode & GR_WRITE ? " writing" : reqmode &
47923+ GR_APPEND ? " appending" : "");
47924+ return 0;
47925+ } else if (unlikely((mode & reqmode) != reqmode))
47926+ return 0;
47927+
47928+ return reqmode;
47929+}
47930+
47931+__u32
47932+gr_acl_handle_creat(const struct dentry * dentry,
47933+ const struct dentry * p_dentry,
47934+ const struct vfsmount * p_mnt, const int fmode,
47935+ const int imode)
47936+{
47937+ __u32 reqmode = GR_WRITE | GR_CREATE;
47938+ __u32 mode;
47939+
47940+ if (unlikely(fmode & O_APPEND))
47941+ reqmode |= GR_APPEND;
47942+ if (unlikely((fmode & FMODE_READ) && !(fmode & O_DIRECTORY)))
47943+ reqmode |= GR_READ;
47944+ if (unlikely((fmode & O_CREAT) && (imode & (S_ISUID | S_ISGID))))
47945+ reqmode |= GR_SETID;
47946+
47947+ mode =
47948+ gr_check_create(dentry, p_dentry, p_mnt,
47949+ reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
47950+
47951+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
47952+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
47953+ reqmode & GR_READ ? " reading" : "",
47954+ reqmode & GR_WRITE ? " writing" : reqmode &
47955+ GR_APPEND ? " appending" : "");
47956+ return reqmode;
47957+ } else
47958+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
47959+ {
47960+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
47961+ reqmode & GR_READ ? " reading" : "",
47962+ reqmode & GR_WRITE ? " writing" : reqmode &
47963+ GR_APPEND ? " appending" : "");
47964+ return 0;
47965+ } else if (unlikely((mode & reqmode) != reqmode))
47966+ return 0;
47967+
47968+ return reqmode;
47969+}
47970+
47971+__u32
47972+gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
47973+ const int fmode)
47974+{
47975+ __u32 mode, reqmode = GR_FIND;
47976+
47977+ if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
47978+ reqmode |= GR_EXEC;
47979+ if (fmode & S_IWOTH)
47980+ reqmode |= GR_WRITE;
47981+ if (fmode & S_IROTH)
47982+ reqmode |= GR_READ;
47983+
47984+ mode =
47985+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
47986+ mnt);
47987+
47988+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
47989+ gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
47990+ reqmode & GR_READ ? " reading" : "",
47991+ reqmode & GR_WRITE ? " writing" : "",
47992+ reqmode & GR_EXEC ? " executing" : "");
47993+ return reqmode;
47994+ } else
47995+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
47996+ {
47997+ gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
47998+ reqmode & GR_READ ? " reading" : "",
47999+ reqmode & GR_WRITE ? " writing" : "",
48000+ reqmode & GR_EXEC ? " executing" : "");
48001+ return 0;
48002+ } else if (unlikely((mode & reqmode) != reqmode))
48003+ return 0;
48004+
48005+ return reqmode;
48006+}
48007+
48008+static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
48009+{
48010+ __u32 mode;
48011+
48012+ mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
48013+
48014+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
48015+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
48016+ return mode;
48017+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
48018+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
48019+ return 0;
48020+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
48021+ return 0;
48022+
48023+ return (reqmode);
48024+}
48025+
48026+__u32
48027+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
48028+{
48029+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
48030+}
48031+
48032+__u32
48033+gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
48034+{
48035+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
48036+}
48037+
48038+__u32
48039+gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
48040+{
48041+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
48042+}
48043+
48044+__u32
48045+gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
48046+{
48047+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
48048+}
48049+
48050+__u32
48051+gr_acl_handle_fchmod(const struct dentry *dentry, const struct vfsmount *mnt,
48052+ mode_t mode)
48053+{
48054+ if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
48055+ return 1;
48056+
48057+ if (unlikely((mode != (mode_t)-1) && (mode & (S_ISUID | S_ISGID)))) {
48058+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
48059+ GR_FCHMOD_ACL_MSG);
48060+ } else {
48061+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_FCHMOD_ACL_MSG);
48062+ }
48063+}
48064+
48065+__u32
48066+gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
48067+ mode_t mode)
48068+{
48069+ if (unlikely((mode != (mode_t)-1) && (mode & (S_ISUID | S_ISGID)))) {
48070+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
48071+ GR_CHMOD_ACL_MSG);
48072+ } else {
48073+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
48074+ }
48075+}
48076+
48077+__u32
48078+gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
48079+{
48080+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
48081+}
48082+
48083+__u32
48084+gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
48085+{
48086+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
48087+}
48088+
48089+__u32
48090+gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
48091+{
48092+ return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
48093+}
48094+
48095+__u32
48096+gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
48097+{
48098+ return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
48099+ GR_UNIXCONNECT_ACL_MSG);
48100+}
48101+
48102+/* hardlinks require at minimum create permission,
48103+ any additional privilege required is based on the
48104+ privilege of the file being linked to
48105+*/
48106+__u32
48107+gr_acl_handle_link(const struct dentry * new_dentry,
48108+ const struct dentry * parent_dentry,
48109+ const struct vfsmount * parent_mnt,
48110+ const struct dentry * old_dentry,
48111+ const struct vfsmount * old_mnt, const char *to)
48112+{
48113+ __u32 mode;
48114+ __u32 needmode = GR_CREATE | GR_LINK;
48115+ __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
48116+
48117+ mode =
48118+ gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
48119+ old_mnt);
48120+
48121+ if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
48122+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
48123+ return mode;
48124+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
48125+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
48126+ return 0;
48127+ } else if (unlikely((mode & needmode) != needmode))
48128+ return 0;
48129+
48130+ return 1;
48131+}
48132+
48133+__u32
48134+gr_acl_handle_symlink(const struct dentry * new_dentry,
48135+ const struct dentry * parent_dentry,
48136+ const struct vfsmount * parent_mnt, const char *from)
48137+{
48138+ __u32 needmode = GR_WRITE | GR_CREATE;
48139+ __u32 mode;
48140+
48141+ mode =
48142+ gr_check_create(new_dentry, parent_dentry, parent_mnt,
48143+ GR_CREATE | GR_AUDIT_CREATE |
48144+ GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
48145+
48146+ if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
48147+ gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
48148+ return mode;
48149+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
48150+ gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
48151+ return 0;
48152+ } else if (unlikely((mode & needmode) != needmode))
48153+ return 0;
48154+
48155+ return (GR_WRITE | GR_CREATE);
48156+}
48157+
48158+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)
48159+{
48160+ __u32 mode;
48161+
48162+ mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
48163+
48164+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
48165+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
48166+ return mode;
48167+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
48168+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
48169+ return 0;
48170+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
48171+ return 0;
48172+
48173+ return (reqmode);
48174+}
48175+
48176+__u32
48177+gr_acl_handle_mknod(const struct dentry * new_dentry,
48178+ const struct dentry * parent_dentry,
48179+ const struct vfsmount * parent_mnt,
48180+ const int mode)
48181+{
48182+ __u32 reqmode = GR_WRITE | GR_CREATE;
48183+ if (unlikely(mode & (S_ISUID | S_ISGID)))
48184+ reqmode |= GR_SETID;
48185+
48186+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
48187+ reqmode, GR_MKNOD_ACL_MSG);
48188+}
48189+
48190+__u32
48191+gr_acl_handle_mkdir(const struct dentry *new_dentry,
48192+ const struct dentry *parent_dentry,
48193+ const struct vfsmount *parent_mnt)
48194+{
48195+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
48196+ GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
48197+}
48198+
48199+#define RENAME_CHECK_SUCCESS(old, new) \
48200+ (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
48201+ ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
48202+
48203+int
48204+gr_acl_handle_rename(struct dentry *new_dentry,
48205+ struct dentry *parent_dentry,
48206+ const struct vfsmount *parent_mnt,
48207+ struct dentry *old_dentry,
48208+ struct inode *old_parent_inode,
48209+ struct vfsmount *old_mnt, const char *newname)
48210+{
48211+ __u32 comp1, comp2;
48212+ int error = 0;
48213+
48214+ if (unlikely(!gr_acl_is_enabled()))
48215+ return 0;
48216+
48217+ if (!new_dentry->d_inode) {
48218+ comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
48219+ GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
48220+ GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
48221+ comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
48222+ GR_DELETE | GR_AUDIT_DELETE |
48223+ GR_AUDIT_READ | GR_AUDIT_WRITE |
48224+ GR_SUPPRESS, old_mnt);
48225+ } else {
48226+ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
48227+ GR_CREATE | GR_DELETE |
48228+ GR_AUDIT_CREATE | GR_AUDIT_DELETE |
48229+ GR_AUDIT_READ | GR_AUDIT_WRITE |
48230+ GR_SUPPRESS, parent_mnt);
48231+ comp2 =
48232+ gr_search_file(old_dentry,
48233+ GR_READ | GR_WRITE | GR_AUDIT_READ |
48234+ GR_DELETE | GR_AUDIT_DELETE |
48235+ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
48236+ }
48237+
48238+ if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
48239+ ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
48240+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
48241+ else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
48242+ && !(comp2 & GR_SUPPRESS)) {
48243+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
48244+ error = -EACCES;
48245+ } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
48246+ error = -EACCES;
48247+
48248+ return error;
48249+}
48250+
48251+void
48252+gr_acl_handle_exit(void)
48253+{
48254+ u16 id;
48255+ char *rolename;
48256+ struct file *exec_file;
48257+
48258+ if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
48259+ !(current->role->roletype & GR_ROLE_PERSIST))) {
48260+ id = current->acl_role_id;
48261+ rolename = current->role->rolename;
48262+ gr_set_acls(1);
48263+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
48264+ }
48265+
48266+ write_lock(&grsec_exec_file_lock);
48267+ exec_file = current->exec_file;
48268+ current->exec_file = NULL;
48269+ write_unlock(&grsec_exec_file_lock);
48270+
48271+ if (exec_file)
48272+ fput(exec_file);
48273+}
48274+
48275+int
48276+gr_acl_handle_procpidmem(const struct task_struct *task)
48277+{
48278+ if (unlikely(!gr_acl_is_enabled()))
48279+ return 0;
48280+
48281+ if (task != current && task->acl->mode & GR_PROTPROCFD)
48282+ return -EACCES;
48283+
48284+ return 0;
48285+}
48286diff -urNp linux-2.6.32.41/grsecurity/gracl_ip.c linux-2.6.32.41/grsecurity/gracl_ip.c
48287--- linux-2.6.32.41/grsecurity/gracl_ip.c 1969-12-31 19:00:00.000000000 -0500
48288+++ linux-2.6.32.41/grsecurity/gracl_ip.c 2011-04-17 15:56:46.000000000 -0400
48289@@ -0,0 +1,382 @@
48290+#include <linux/kernel.h>
48291+#include <asm/uaccess.h>
48292+#include <asm/errno.h>
48293+#include <net/sock.h>
48294+#include <linux/file.h>
48295+#include <linux/fs.h>
48296+#include <linux/net.h>
48297+#include <linux/in.h>
48298+#include <linux/skbuff.h>
48299+#include <linux/ip.h>
48300+#include <linux/udp.h>
48301+#include <linux/smp_lock.h>
48302+#include <linux/types.h>
48303+#include <linux/sched.h>
48304+#include <linux/netdevice.h>
48305+#include <linux/inetdevice.h>
48306+#include <linux/gracl.h>
48307+#include <linux/grsecurity.h>
48308+#include <linux/grinternal.h>
48309+
48310+#define GR_BIND 0x01
48311+#define GR_CONNECT 0x02
48312+#define GR_INVERT 0x04
48313+#define GR_BINDOVERRIDE 0x08
48314+#define GR_CONNECTOVERRIDE 0x10
48315+#define GR_SOCK_FAMILY 0x20
48316+
48317+static const char * gr_protocols[IPPROTO_MAX] = {
48318+ "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
48319+ "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
48320+ "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
48321+ "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
48322+ "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
48323+ "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
48324+ "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
48325+ "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
48326+ "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
48327+ "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
48328+ "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
48329+ "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
48330+ "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
48331+ "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
48332+ "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
48333+ "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
48334+ "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
48335+ "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
48336+ "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
48337+ "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
48338+ "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
48339+ "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
48340+ "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
48341+ "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
48342+ "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
48343+ "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
48344+ "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
48345+ "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
48346+ "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
48347+ "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
48348+ "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
48349+ "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
48350+ };
48351+
48352+static const char * gr_socktypes[SOCK_MAX] = {
48353+ "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
48354+ "unknown:7", "unknown:8", "unknown:9", "packet"
48355+ };
48356+
48357+static const char * gr_sockfamilies[AF_MAX+1] = {
48358+ "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
48359+ "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
48360+ "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
48361+ "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154"
48362+ };
48363+
48364+const char *
48365+gr_proto_to_name(unsigned char proto)
48366+{
48367+ return gr_protocols[proto];
48368+}
48369+
48370+const char *
48371+gr_socktype_to_name(unsigned char type)
48372+{
48373+ return gr_socktypes[type];
48374+}
48375+
48376+const char *
48377+gr_sockfamily_to_name(unsigned char family)
48378+{
48379+ return gr_sockfamilies[family];
48380+}
48381+
48382+int
48383+gr_search_socket(const int domain, const int type, const int protocol)
48384+{
48385+ struct acl_subject_label *curr;
48386+ const struct cred *cred = current_cred();
48387+
48388+ if (unlikely(!gr_acl_is_enabled()))
48389+ goto exit;
48390+
48391+ if ((domain < 0) || (type < 0) || (protocol < 0) ||
48392+ (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
48393+ goto exit; // let the kernel handle it
48394+
48395+ curr = current->acl;
48396+
48397+ if (curr->sock_families[domain / 32] & (1 << (domain % 32))) {
48398+ /* the family is allowed, if this is PF_INET allow it only if
48399+ the extra sock type/protocol checks pass */
48400+ if (domain == PF_INET)
48401+ goto inet_check;
48402+ goto exit;
48403+ } else {
48404+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
48405+ __u32 fakeip = 0;
48406+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
48407+ current->role->roletype, cred->uid,
48408+ cred->gid, current->exec_file ?
48409+ gr_to_filename(current->exec_file->f_path.dentry,
48410+ current->exec_file->f_path.mnt) :
48411+ curr->filename, curr->filename,
48412+ &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
48413+ &current->signal->saved_ip);
48414+ goto exit;
48415+ }
48416+ goto exit_fail;
48417+ }
48418+
48419+inet_check:
48420+ /* the rest of this checking is for IPv4 only */
48421+ if (!curr->ips)
48422+ goto exit;
48423+
48424+ if ((curr->ip_type & (1 << type)) &&
48425+ (curr->ip_proto[protocol / 32] & (1 << (protocol % 32))))
48426+ goto exit;
48427+
48428+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
48429+ /* we don't place acls on raw sockets , and sometimes
48430+ dgram/ip sockets are opened for ioctl and not
48431+ bind/connect, so we'll fake a bind learn log */
48432+ if (type == SOCK_RAW || type == SOCK_PACKET) {
48433+ __u32 fakeip = 0;
48434+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
48435+ current->role->roletype, cred->uid,
48436+ cred->gid, current->exec_file ?
48437+ gr_to_filename(current->exec_file->f_path.dentry,
48438+ current->exec_file->f_path.mnt) :
48439+ curr->filename, curr->filename,
48440+ &fakeip, 0, type,
48441+ protocol, GR_CONNECT, &current->signal->saved_ip);
48442+ } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
48443+ __u32 fakeip = 0;
48444+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
48445+ current->role->roletype, cred->uid,
48446+ cred->gid, current->exec_file ?
48447+ gr_to_filename(current->exec_file->f_path.dentry,
48448+ current->exec_file->f_path.mnt) :
48449+ curr->filename, curr->filename,
48450+ &fakeip, 0, type,
48451+ protocol, GR_BIND, &current->signal->saved_ip);
48452+ }
48453+ /* we'll log when they use connect or bind */
48454+ goto exit;
48455+ }
48456+
48457+exit_fail:
48458+ if (domain == PF_INET)
48459+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
48460+ gr_socktype_to_name(type), gr_proto_to_name(protocol));
48461+ else
48462+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
48463+ gr_socktype_to_name(type), protocol);
48464+
48465+ return 0;
48466+exit:
48467+ return 1;
48468+}
48469+
48470+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)
48471+{
48472+ if ((ip->mode & mode) &&
48473+ (ip_port >= ip->low) &&
48474+ (ip_port <= ip->high) &&
48475+ ((ntohl(ip_addr) & our_netmask) ==
48476+ (ntohl(our_addr) & our_netmask))
48477+ && (ip->proto[protocol / 32] & (1 << (protocol % 32)))
48478+ && (ip->type & (1 << type))) {
48479+ if (ip->mode & GR_INVERT)
48480+ return 2; // specifically denied
48481+ else
48482+ return 1; // allowed
48483+ }
48484+
48485+ return 0; // not specifically allowed, may continue parsing
48486+}
48487+
48488+static int
48489+gr_search_connectbind(const int full_mode, struct sock *sk,
48490+ struct sockaddr_in *addr, const int type)
48491+{
48492+ char iface[IFNAMSIZ] = {0};
48493+ struct acl_subject_label *curr;
48494+ struct acl_ip_label *ip;
48495+ struct inet_sock *isk;
48496+ struct net_device *dev;
48497+ struct in_device *idev;
48498+ unsigned long i;
48499+ int ret;
48500+ int mode = full_mode & (GR_BIND | GR_CONNECT);
48501+ __u32 ip_addr = 0;
48502+ __u32 our_addr;
48503+ __u32 our_netmask;
48504+ char *p;
48505+ __u16 ip_port = 0;
48506+ const struct cred *cred = current_cred();
48507+
48508+ if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
48509+ return 0;
48510+
48511+ curr = current->acl;
48512+ isk = inet_sk(sk);
48513+
48514+ /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
48515+ if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
48516+ addr->sin_addr.s_addr = curr->inaddr_any_override;
48517+ if ((full_mode & GR_CONNECT) && isk->saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
48518+ struct sockaddr_in saddr;
48519+ int err;
48520+
48521+ saddr.sin_family = AF_INET;
48522+ saddr.sin_addr.s_addr = curr->inaddr_any_override;
48523+ saddr.sin_port = isk->sport;
48524+
48525+ err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
48526+ if (err)
48527+ return err;
48528+
48529+ err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
48530+ if (err)
48531+ return err;
48532+ }
48533+
48534+ if (!curr->ips)
48535+ return 0;
48536+
48537+ ip_addr = addr->sin_addr.s_addr;
48538+ ip_port = ntohs(addr->sin_port);
48539+
48540+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
48541+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
48542+ current->role->roletype, cred->uid,
48543+ cred->gid, current->exec_file ?
48544+ gr_to_filename(current->exec_file->f_path.dentry,
48545+ current->exec_file->f_path.mnt) :
48546+ curr->filename, curr->filename,
48547+ &ip_addr, ip_port, type,
48548+ sk->sk_protocol, mode, &current->signal->saved_ip);
48549+ return 0;
48550+ }
48551+
48552+ for (i = 0; i < curr->ip_num; i++) {
48553+ ip = *(curr->ips + i);
48554+ if (ip->iface != NULL) {
48555+ strncpy(iface, ip->iface, IFNAMSIZ - 1);
48556+ p = strchr(iface, ':');
48557+ if (p != NULL)
48558+ *p = '\0';
48559+ dev = dev_get_by_name(sock_net(sk), iface);
48560+ if (dev == NULL)
48561+ continue;
48562+ idev = in_dev_get(dev);
48563+ if (idev == NULL) {
48564+ dev_put(dev);
48565+ continue;
48566+ }
48567+ rcu_read_lock();
48568+ for_ifa(idev) {
48569+ if (!strcmp(ip->iface, ifa->ifa_label)) {
48570+ our_addr = ifa->ifa_address;
48571+ our_netmask = 0xffffffff;
48572+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
48573+ if (ret == 1) {
48574+ rcu_read_unlock();
48575+ in_dev_put(idev);
48576+ dev_put(dev);
48577+ return 0;
48578+ } else if (ret == 2) {
48579+ rcu_read_unlock();
48580+ in_dev_put(idev);
48581+ dev_put(dev);
48582+ goto denied;
48583+ }
48584+ }
48585+ } endfor_ifa(idev);
48586+ rcu_read_unlock();
48587+ in_dev_put(idev);
48588+ dev_put(dev);
48589+ } else {
48590+ our_addr = ip->addr;
48591+ our_netmask = ip->netmask;
48592+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
48593+ if (ret == 1)
48594+ return 0;
48595+ else if (ret == 2)
48596+ goto denied;
48597+ }
48598+ }
48599+
48600+denied:
48601+ if (mode == GR_BIND)
48602+ 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));
48603+ else if (mode == GR_CONNECT)
48604+ 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));
48605+
48606+ return -EACCES;
48607+}
48608+
48609+int
48610+gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
48611+{
48612+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
48613+}
48614+
48615+int
48616+gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
48617+{
48618+ return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
48619+}
48620+
48621+int gr_search_listen(struct socket *sock)
48622+{
48623+ struct sock *sk = sock->sk;
48624+ struct sockaddr_in addr;
48625+
48626+ addr.sin_addr.s_addr = inet_sk(sk)->saddr;
48627+ addr.sin_port = inet_sk(sk)->sport;
48628+
48629+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
48630+}
48631+
48632+int gr_search_accept(struct socket *sock)
48633+{
48634+ struct sock *sk = sock->sk;
48635+ struct sockaddr_in addr;
48636+
48637+ addr.sin_addr.s_addr = inet_sk(sk)->saddr;
48638+ addr.sin_port = inet_sk(sk)->sport;
48639+
48640+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
48641+}
48642+
48643+int
48644+gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
48645+{
48646+ if (addr)
48647+ return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
48648+ else {
48649+ struct sockaddr_in sin;
48650+ const struct inet_sock *inet = inet_sk(sk);
48651+
48652+ sin.sin_addr.s_addr = inet->daddr;
48653+ sin.sin_port = inet->dport;
48654+
48655+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
48656+ }
48657+}
48658+
48659+int
48660+gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
48661+{
48662+ struct sockaddr_in sin;
48663+
48664+ if (unlikely(skb->len < sizeof (struct udphdr)))
48665+ return 0; // skip this packet
48666+
48667+ sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
48668+ sin.sin_port = udp_hdr(skb)->source;
48669+
48670+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
48671+}
48672diff -urNp linux-2.6.32.41/grsecurity/gracl_learn.c linux-2.6.32.41/grsecurity/gracl_learn.c
48673--- linux-2.6.32.41/grsecurity/gracl_learn.c 1969-12-31 19:00:00.000000000 -0500
48674+++ linux-2.6.32.41/grsecurity/gracl_learn.c 2011-04-17 15:56:46.000000000 -0400
48675@@ -0,0 +1,211 @@
48676+#include <linux/kernel.h>
48677+#include <linux/mm.h>
48678+#include <linux/sched.h>
48679+#include <linux/poll.h>
48680+#include <linux/smp_lock.h>
48681+#include <linux/string.h>
48682+#include <linux/file.h>
48683+#include <linux/types.h>
48684+#include <linux/vmalloc.h>
48685+#include <linux/grinternal.h>
48686+
48687+extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
48688+ size_t count, loff_t *ppos);
48689+extern int gr_acl_is_enabled(void);
48690+
48691+static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
48692+static int gr_learn_attached;
48693+
48694+/* use a 512k buffer */
48695+#define LEARN_BUFFER_SIZE (512 * 1024)
48696+
48697+static DEFINE_SPINLOCK(gr_learn_lock);
48698+static DEFINE_MUTEX(gr_learn_user_mutex);
48699+
48700+/* we need to maintain two buffers, so that the kernel context of grlearn
48701+ uses a semaphore around the userspace copying, and the other kernel contexts
48702+ use a spinlock when copying into the buffer, since they cannot sleep
48703+*/
48704+static char *learn_buffer;
48705+static char *learn_buffer_user;
48706+static int learn_buffer_len;
48707+static int learn_buffer_user_len;
48708+
48709+static ssize_t
48710+read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
48711+{
48712+ DECLARE_WAITQUEUE(wait, current);
48713+ ssize_t retval = 0;
48714+
48715+ add_wait_queue(&learn_wait, &wait);
48716+ set_current_state(TASK_INTERRUPTIBLE);
48717+ do {
48718+ mutex_lock(&gr_learn_user_mutex);
48719+ spin_lock(&gr_learn_lock);
48720+ if (learn_buffer_len)
48721+ break;
48722+ spin_unlock(&gr_learn_lock);
48723+ mutex_unlock(&gr_learn_user_mutex);
48724+ if (file->f_flags & O_NONBLOCK) {
48725+ retval = -EAGAIN;
48726+ goto out;
48727+ }
48728+ if (signal_pending(current)) {
48729+ retval = -ERESTARTSYS;
48730+ goto out;
48731+ }
48732+
48733+ schedule();
48734+ } while (1);
48735+
48736+ memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
48737+ learn_buffer_user_len = learn_buffer_len;
48738+ retval = learn_buffer_len;
48739+ learn_buffer_len = 0;
48740+
48741+ spin_unlock(&gr_learn_lock);
48742+
48743+ if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
48744+ retval = -EFAULT;
48745+
48746+ mutex_unlock(&gr_learn_user_mutex);
48747+out:
48748+ set_current_state(TASK_RUNNING);
48749+ remove_wait_queue(&learn_wait, &wait);
48750+ return retval;
48751+}
48752+
48753+static unsigned int
48754+poll_learn(struct file * file, poll_table * wait)
48755+{
48756+ poll_wait(file, &learn_wait, wait);
48757+
48758+ if (learn_buffer_len)
48759+ return (POLLIN | POLLRDNORM);
48760+
48761+ return 0;
48762+}
48763+
48764+void
48765+gr_clear_learn_entries(void)
48766+{
48767+ char *tmp;
48768+
48769+ mutex_lock(&gr_learn_user_mutex);
48770+ if (learn_buffer != NULL) {
48771+ spin_lock(&gr_learn_lock);
48772+ tmp = learn_buffer;
48773+ learn_buffer = NULL;
48774+ spin_unlock(&gr_learn_lock);
48775+ vfree(learn_buffer);
48776+ }
48777+ if (learn_buffer_user != NULL) {
48778+ vfree(learn_buffer_user);
48779+ learn_buffer_user = NULL;
48780+ }
48781+ learn_buffer_len = 0;
48782+ mutex_unlock(&gr_learn_user_mutex);
48783+
48784+ return;
48785+}
48786+
48787+void
48788+gr_add_learn_entry(const char *fmt, ...)
48789+{
48790+ va_list args;
48791+ unsigned int len;
48792+
48793+ if (!gr_learn_attached)
48794+ return;
48795+
48796+ spin_lock(&gr_learn_lock);
48797+
48798+ /* leave a gap at the end so we know when it's "full" but don't have to
48799+ compute the exact length of the string we're trying to append
48800+ */
48801+ if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
48802+ spin_unlock(&gr_learn_lock);
48803+ wake_up_interruptible(&learn_wait);
48804+ return;
48805+ }
48806+ if (learn_buffer == NULL) {
48807+ spin_unlock(&gr_learn_lock);
48808+ return;
48809+ }
48810+
48811+ va_start(args, fmt);
48812+ len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
48813+ va_end(args);
48814+
48815+ learn_buffer_len += len + 1;
48816+
48817+ spin_unlock(&gr_learn_lock);
48818+ wake_up_interruptible(&learn_wait);
48819+
48820+ return;
48821+}
48822+
48823+static int
48824+open_learn(struct inode *inode, struct file *file)
48825+{
48826+ if (file->f_mode & FMODE_READ && gr_learn_attached)
48827+ return -EBUSY;
48828+ if (file->f_mode & FMODE_READ) {
48829+ int retval = 0;
48830+ mutex_lock(&gr_learn_user_mutex);
48831+ if (learn_buffer == NULL)
48832+ learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
48833+ if (learn_buffer_user == NULL)
48834+ learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
48835+ if (learn_buffer == NULL) {
48836+ retval = -ENOMEM;
48837+ goto out_error;
48838+ }
48839+ if (learn_buffer_user == NULL) {
48840+ retval = -ENOMEM;
48841+ goto out_error;
48842+ }
48843+ learn_buffer_len = 0;
48844+ learn_buffer_user_len = 0;
48845+ gr_learn_attached = 1;
48846+out_error:
48847+ mutex_unlock(&gr_learn_user_mutex);
48848+ return retval;
48849+ }
48850+ return 0;
48851+}
48852+
48853+static int
48854+close_learn(struct inode *inode, struct file *file)
48855+{
48856+ char *tmp;
48857+
48858+ if (file->f_mode & FMODE_READ) {
48859+ mutex_lock(&gr_learn_user_mutex);
48860+ if (learn_buffer != NULL) {
48861+ spin_lock(&gr_learn_lock);
48862+ tmp = learn_buffer;
48863+ learn_buffer = NULL;
48864+ spin_unlock(&gr_learn_lock);
48865+ vfree(tmp);
48866+ }
48867+ if (learn_buffer_user != NULL) {
48868+ vfree(learn_buffer_user);
48869+ learn_buffer_user = NULL;
48870+ }
48871+ learn_buffer_len = 0;
48872+ learn_buffer_user_len = 0;
48873+ gr_learn_attached = 0;
48874+ mutex_unlock(&gr_learn_user_mutex);
48875+ }
48876+
48877+ return 0;
48878+}
48879+
48880+const struct file_operations grsec_fops = {
48881+ .read = read_learn,
48882+ .write = write_grsec_handler,
48883+ .open = open_learn,
48884+ .release = close_learn,
48885+ .poll = poll_learn,
48886+};
48887diff -urNp linux-2.6.32.41/grsecurity/gracl_res.c linux-2.6.32.41/grsecurity/gracl_res.c
48888--- linux-2.6.32.41/grsecurity/gracl_res.c 1969-12-31 19:00:00.000000000 -0500
48889+++ linux-2.6.32.41/grsecurity/gracl_res.c 2011-04-17 15:56:46.000000000 -0400
48890@@ -0,0 +1,67 @@
48891+#include <linux/kernel.h>
48892+#include <linux/sched.h>
48893+#include <linux/gracl.h>
48894+#include <linux/grinternal.h>
48895+
48896+static const char *restab_log[] = {
48897+ [RLIMIT_CPU] = "RLIMIT_CPU",
48898+ [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
48899+ [RLIMIT_DATA] = "RLIMIT_DATA",
48900+ [RLIMIT_STACK] = "RLIMIT_STACK",
48901+ [RLIMIT_CORE] = "RLIMIT_CORE",
48902+ [RLIMIT_RSS] = "RLIMIT_RSS",
48903+ [RLIMIT_NPROC] = "RLIMIT_NPROC",
48904+ [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
48905+ [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
48906+ [RLIMIT_AS] = "RLIMIT_AS",
48907+ [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
48908+ [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
48909+ [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
48910+ [RLIMIT_NICE] = "RLIMIT_NICE",
48911+ [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
48912+ [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
48913+ [GR_CRASH_RES] = "RLIMIT_CRASH"
48914+};
48915+
48916+void
48917+gr_log_resource(const struct task_struct *task,
48918+ const int res, const unsigned long wanted, const int gt)
48919+{
48920+ const struct cred *cred;
48921+ unsigned long rlim;
48922+
48923+ if (!gr_acl_is_enabled() && !grsec_resource_logging)
48924+ return;
48925+
48926+ // not yet supported resource
48927+ if (unlikely(!restab_log[res]))
48928+ return;
48929+
48930+ if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
48931+ rlim = task->signal->rlim[res].rlim_max;
48932+ else
48933+ rlim = task->signal->rlim[res].rlim_cur;
48934+ if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
48935+ return;
48936+
48937+ rcu_read_lock();
48938+ cred = __task_cred(task);
48939+
48940+ if (res == RLIMIT_NPROC &&
48941+ (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
48942+ cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
48943+ goto out_rcu_unlock;
48944+ else if (res == RLIMIT_MEMLOCK &&
48945+ cap_raised(cred->cap_effective, CAP_IPC_LOCK))
48946+ goto out_rcu_unlock;
48947+ else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
48948+ goto out_rcu_unlock;
48949+ rcu_read_unlock();
48950+
48951+ gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
48952+
48953+ return;
48954+out_rcu_unlock:
48955+ rcu_read_unlock();
48956+ return;
48957+}
48958diff -urNp linux-2.6.32.41/grsecurity/gracl_segv.c linux-2.6.32.41/grsecurity/gracl_segv.c
48959--- linux-2.6.32.41/grsecurity/gracl_segv.c 1969-12-31 19:00:00.000000000 -0500
48960+++ linux-2.6.32.41/grsecurity/gracl_segv.c 2011-04-17 15:56:46.000000000 -0400
48961@@ -0,0 +1,284 @@
48962+#include <linux/kernel.h>
48963+#include <linux/mm.h>
48964+#include <asm/uaccess.h>
48965+#include <asm/errno.h>
48966+#include <asm/mman.h>
48967+#include <net/sock.h>
48968+#include <linux/file.h>
48969+#include <linux/fs.h>
48970+#include <linux/net.h>
48971+#include <linux/in.h>
48972+#include <linux/smp_lock.h>
48973+#include <linux/slab.h>
48974+#include <linux/types.h>
48975+#include <linux/sched.h>
48976+#include <linux/timer.h>
48977+#include <linux/gracl.h>
48978+#include <linux/grsecurity.h>
48979+#include <linux/grinternal.h>
48980+
48981+static struct crash_uid *uid_set;
48982+static unsigned short uid_used;
48983+static DEFINE_SPINLOCK(gr_uid_lock);
48984+extern rwlock_t gr_inode_lock;
48985+extern struct acl_subject_label *
48986+ lookup_acl_subj_label(const ino_t inode, const dev_t dev,
48987+ struct acl_role_label *role);
48988+extern int gr_fake_force_sig(int sig, struct task_struct *t);
48989+
48990+int
48991+gr_init_uidset(void)
48992+{
48993+ uid_set =
48994+ kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
48995+ uid_used = 0;
48996+
48997+ return uid_set ? 1 : 0;
48998+}
48999+
49000+void
49001+gr_free_uidset(void)
49002+{
49003+ if (uid_set)
49004+ kfree(uid_set);
49005+
49006+ return;
49007+}
49008+
49009+int
49010+gr_find_uid(const uid_t uid)
49011+{
49012+ struct crash_uid *tmp = uid_set;
49013+ uid_t buid;
49014+ int low = 0, high = uid_used - 1, mid;
49015+
49016+ while (high >= low) {
49017+ mid = (low + high) >> 1;
49018+ buid = tmp[mid].uid;
49019+ if (buid == uid)
49020+ return mid;
49021+ if (buid > uid)
49022+ high = mid - 1;
49023+ if (buid < uid)
49024+ low = mid + 1;
49025+ }
49026+
49027+ return -1;
49028+}
49029+
49030+static __inline__ void
49031+gr_insertsort(void)
49032+{
49033+ unsigned short i, j;
49034+ struct crash_uid index;
49035+
49036+ for (i = 1; i < uid_used; i++) {
49037+ index = uid_set[i];
49038+ j = i;
49039+ while ((j > 0) && uid_set[j - 1].uid > index.uid) {
49040+ uid_set[j] = uid_set[j - 1];
49041+ j--;
49042+ }
49043+ uid_set[j] = index;
49044+ }
49045+
49046+ return;
49047+}
49048+
49049+static __inline__ void
49050+gr_insert_uid(const uid_t uid, const unsigned long expires)
49051+{
49052+ int loc;
49053+
49054+ if (uid_used == GR_UIDTABLE_MAX)
49055+ return;
49056+
49057+ loc = gr_find_uid(uid);
49058+
49059+ if (loc >= 0) {
49060+ uid_set[loc].expires = expires;
49061+ return;
49062+ }
49063+
49064+ uid_set[uid_used].uid = uid;
49065+ uid_set[uid_used].expires = expires;
49066+ uid_used++;
49067+
49068+ gr_insertsort();
49069+
49070+ return;
49071+}
49072+
49073+void
49074+gr_remove_uid(const unsigned short loc)
49075+{
49076+ unsigned short i;
49077+
49078+ for (i = loc + 1; i < uid_used; i++)
49079+ uid_set[i - 1] = uid_set[i];
49080+
49081+ uid_used--;
49082+
49083+ return;
49084+}
49085+
49086+int
49087+gr_check_crash_uid(const uid_t uid)
49088+{
49089+ int loc;
49090+ int ret = 0;
49091+
49092+ if (unlikely(!gr_acl_is_enabled()))
49093+ return 0;
49094+
49095+ spin_lock(&gr_uid_lock);
49096+ loc = gr_find_uid(uid);
49097+
49098+ if (loc < 0)
49099+ goto out_unlock;
49100+
49101+ if (time_before_eq(uid_set[loc].expires, get_seconds()))
49102+ gr_remove_uid(loc);
49103+ else
49104+ ret = 1;
49105+
49106+out_unlock:
49107+ spin_unlock(&gr_uid_lock);
49108+ return ret;
49109+}
49110+
49111+static __inline__ int
49112+proc_is_setxid(const struct cred *cred)
49113+{
49114+ if (cred->uid != cred->euid || cred->uid != cred->suid ||
49115+ cred->uid != cred->fsuid)
49116+ return 1;
49117+ if (cred->gid != cred->egid || cred->gid != cred->sgid ||
49118+ cred->gid != cred->fsgid)
49119+ return 1;
49120+
49121+ return 0;
49122+}
49123+
49124+void
49125+gr_handle_crash(struct task_struct *task, const int sig)
49126+{
49127+ struct acl_subject_label *curr;
49128+ struct acl_subject_label *curr2;
49129+ struct task_struct *tsk, *tsk2;
49130+ const struct cred *cred;
49131+ const struct cred *cred2;
49132+
49133+ if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
49134+ return;
49135+
49136+ if (unlikely(!gr_acl_is_enabled()))
49137+ return;
49138+
49139+ curr = task->acl;
49140+
49141+ if (!(curr->resmask & (1 << GR_CRASH_RES)))
49142+ return;
49143+
49144+ if (time_before_eq(curr->expires, get_seconds())) {
49145+ curr->expires = 0;
49146+ curr->crashes = 0;
49147+ }
49148+
49149+ curr->crashes++;
49150+
49151+ if (!curr->expires)
49152+ curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
49153+
49154+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
49155+ time_after(curr->expires, get_seconds())) {
49156+ rcu_read_lock();
49157+ cred = __task_cred(task);
49158+ if (cred->uid && proc_is_setxid(cred)) {
49159+ gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
49160+ spin_lock(&gr_uid_lock);
49161+ gr_insert_uid(cred->uid, curr->expires);
49162+ spin_unlock(&gr_uid_lock);
49163+ curr->expires = 0;
49164+ curr->crashes = 0;
49165+ read_lock(&tasklist_lock);
49166+ do_each_thread(tsk2, tsk) {
49167+ cred2 = __task_cred(tsk);
49168+ if (tsk != task && cred2->uid == cred->uid)
49169+ gr_fake_force_sig(SIGKILL, tsk);
49170+ } while_each_thread(tsk2, tsk);
49171+ read_unlock(&tasklist_lock);
49172+ } else {
49173+ gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
49174+ read_lock(&tasklist_lock);
49175+ do_each_thread(tsk2, tsk) {
49176+ if (likely(tsk != task)) {
49177+ curr2 = tsk->acl;
49178+
49179+ if (curr2->device == curr->device &&
49180+ curr2->inode == curr->inode)
49181+ gr_fake_force_sig(SIGKILL, tsk);
49182+ }
49183+ } while_each_thread(tsk2, tsk);
49184+ read_unlock(&tasklist_lock);
49185+ }
49186+ rcu_read_unlock();
49187+ }
49188+
49189+ return;
49190+}
49191+
49192+int
49193+gr_check_crash_exec(const struct file *filp)
49194+{
49195+ struct acl_subject_label *curr;
49196+
49197+ if (unlikely(!gr_acl_is_enabled()))
49198+ return 0;
49199+
49200+ read_lock(&gr_inode_lock);
49201+ curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
49202+ filp->f_path.dentry->d_inode->i_sb->s_dev,
49203+ current->role);
49204+ read_unlock(&gr_inode_lock);
49205+
49206+ if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) ||
49207+ (!curr->crashes && !curr->expires))
49208+ return 0;
49209+
49210+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
49211+ time_after(curr->expires, get_seconds()))
49212+ return 1;
49213+ else if (time_before_eq(curr->expires, get_seconds())) {
49214+ curr->crashes = 0;
49215+ curr->expires = 0;
49216+ }
49217+
49218+ return 0;
49219+}
49220+
49221+void
49222+gr_handle_alertkill(struct task_struct *task)
49223+{
49224+ struct acl_subject_label *curracl;
49225+ __u32 curr_ip;
49226+ struct task_struct *p, *p2;
49227+
49228+ if (unlikely(!gr_acl_is_enabled()))
49229+ return;
49230+
49231+ curracl = task->acl;
49232+ curr_ip = task->signal->curr_ip;
49233+
49234+ if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
49235+ read_lock(&tasklist_lock);
49236+ do_each_thread(p2, p) {
49237+ if (p->signal->curr_ip == curr_ip)
49238+ gr_fake_force_sig(SIGKILL, p);
49239+ } while_each_thread(p2, p);
49240+ read_unlock(&tasklist_lock);
49241+ } else if (curracl->mode & GR_KILLPROC)
49242+ gr_fake_force_sig(SIGKILL, task);
49243+
49244+ return;
49245+}
49246diff -urNp linux-2.6.32.41/grsecurity/gracl_shm.c linux-2.6.32.41/grsecurity/gracl_shm.c
49247--- linux-2.6.32.41/grsecurity/gracl_shm.c 1969-12-31 19:00:00.000000000 -0500
49248+++ linux-2.6.32.41/grsecurity/gracl_shm.c 2011-04-17 15:56:46.000000000 -0400
49249@@ -0,0 +1,40 @@
49250+#include <linux/kernel.h>
49251+#include <linux/mm.h>
49252+#include <linux/sched.h>
49253+#include <linux/file.h>
49254+#include <linux/ipc.h>
49255+#include <linux/gracl.h>
49256+#include <linux/grsecurity.h>
49257+#include <linux/grinternal.h>
49258+
49259+int
49260+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
49261+ const time_t shm_createtime, const uid_t cuid, const int shmid)
49262+{
49263+ struct task_struct *task;
49264+
49265+ if (!gr_acl_is_enabled())
49266+ return 1;
49267+
49268+ rcu_read_lock();
49269+ read_lock(&tasklist_lock);
49270+
49271+ task = find_task_by_vpid(shm_cprid);
49272+
49273+ if (unlikely(!task))
49274+ task = find_task_by_vpid(shm_lapid);
49275+
49276+ if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
49277+ (task->pid == shm_lapid)) &&
49278+ (task->acl->mode & GR_PROTSHM) &&
49279+ (task->acl != current->acl))) {
49280+ read_unlock(&tasklist_lock);
49281+ rcu_read_unlock();
49282+ gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, cuid, shm_cprid, shmid);
49283+ return 0;
49284+ }
49285+ read_unlock(&tasklist_lock);
49286+ rcu_read_unlock();
49287+
49288+ return 1;
49289+}
49290diff -urNp linux-2.6.32.41/grsecurity/grsec_chdir.c linux-2.6.32.41/grsecurity/grsec_chdir.c
49291--- linux-2.6.32.41/grsecurity/grsec_chdir.c 1969-12-31 19:00:00.000000000 -0500
49292+++ linux-2.6.32.41/grsecurity/grsec_chdir.c 2011-04-17 15:56:46.000000000 -0400
49293@@ -0,0 +1,19 @@
49294+#include <linux/kernel.h>
49295+#include <linux/sched.h>
49296+#include <linux/fs.h>
49297+#include <linux/file.h>
49298+#include <linux/grsecurity.h>
49299+#include <linux/grinternal.h>
49300+
49301+void
49302+gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
49303+{
49304+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
49305+ if ((grsec_enable_chdir && grsec_enable_group &&
49306+ in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
49307+ !grsec_enable_group)) {
49308+ gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
49309+ }
49310+#endif
49311+ return;
49312+}
49313diff -urNp linux-2.6.32.41/grsecurity/grsec_chroot.c linux-2.6.32.41/grsecurity/grsec_chroot.c
49314--- linux-2.6.32.41/grsecurity/grsec_chroot.c 1969-12-31 19:00:00.000000000 -0500
49315+++ linux-2.6.32.41/grsecurity/grsec_chroot.c 2011-04-17 15:56:46.000000000 -0400
49316@@ -0,0 +1,395 @@
49317+#include <linux/kernel.h>
49318+#include <linux/module.h>
49319+#include <linux/sched.h>
49320+#include <linux/file.h>
49321+#include <linux/fs.h>
49322+#include <linux/mount.h>
49323+#include <linux/types.h>
49324+#include <linux/pid_namespace.h>
49325+#include <linux/grsecurity.h>
49326+#include <linux/grinternal.h>
49327+
49328+void gr_set_chroot_entries(struct task_struct *task, struct path *path)
49329+{
49330+#ifdef CONFIG_GRKERNSEC
49331+ if (task->pid > 1 && path->dentry != init_task.fs->root.dentry &&
49332+ path->dentry != task->nsproxy->mnt_ns->root->mnt_root)
49333+ task->gr_is_chrooted = 1;
49334+ else
49335+ task->gr_is_chrooted = 0;
49336+
49337+ task->gr_chroot_dentry = path->dentry;
49338+#endif
49339+ return;
49340+}
49341+
49342+void gr_clear_chroot_entries(struct task_struct *task)
49343+{
49344+#ifdef CONFIG_GRKERNSEC
49345+ task->gr_is_chrooted = 0;
49346+ task->gr_chroot_dentry = NULL;
49347+#endif
49348+ return;
49349+}
49350+
49351+int
49352+gr_handle_chroot_unix(const pid_t pid)
49353+{
49354+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
49355+ struct pid *spid = NULL;
49356+
49357+ if (unlikely(!grsec_enable_chroot_unix))
49358+ return 1;
49359+
49360+ if (likely(!proc_is_chrooted(current)))
49361+ return 1;
49362+
49363+ rcu_read_lock();
49364+ read_lock(&tasklist_lock);
49365+
49366+ spid = find_vpid(pid);
49367+ if (spid) {
49368+ struct task_struct *p;
49369+ p = pid_task(spid, PIDTYPE_PID);
49370+ if (unlikely(p && !have_same_root(current, p))) {
49371+ read_unlock(&tasklist_lock);
49372+ rcu_read_unlock();
49373+ gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
49374+ return 0;
49375+ }
49376+ }
49377+ read_unlock(&tasklist_lock);
49378+ rcu_read_unlock();
49379+#endif
49380+ return 1;
49381+}
49382+
49383+int
49384+gr_handle_chroot_nice(void)
49385+{
49386+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
49387+ if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
49388+ gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
49389+ return -EPERM;
49390+ }
49391+#endif
49392+ return 0;
49393+}
49394+
49395+int
49396+gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
49397+{
49398+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
49399+ if (grsec_enable_chroot_nice && (niceval < task_nice(p))
49400+ && proc_is_chrooted(current)) {
49401+ gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, p->pid);
49402+ return -EACCES;
49403+ }
49404+#endif
49405+ return 0;
49406+}
49407+
49408+int
49409+gr_handle_chroot_rawio(const struct inode *inode)
49410+{
49411+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
49412+ if (grsec_enable_chroot_caps && proc_is_chrooted(current) &&
49413+ inode && S_ISBLK(inode->i_mode) && !capable(CAP_SYS_RAWIO))
49414+ return 1;
49415+#endif
49416+ return 0;
49417+}
49418+
49419+int
49420+gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
49421+{
49422+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
49423+ struct task_struct *p;
49424+ int ret = 0;
49425+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
49426+ return ret;
49427+
49428+ read_lock(&tasklist_lock);
49429+ do_each_pid_task(pid, type, p) {
49430+ if (!have_same_root(current, p)) {
49431+ ret = 1;
49432+ goto out;
49433+ }
49434+ } while_each_pid_task(pid, type, p);
49435+out:
49436+ read_unlock(&tasklist_lock);
49437+ return ret;
49438+#endif
49439+ return 0;
49440+}
49441+
49442+int
49443+gr_pid_is_chrooted(struct task_struct *p)
49444+{
49445+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
49446+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
49447+ return 0;
49448+
49449+ if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
49450+ !have_same_root(current, p)) {
49451+ return 1;
49452+ }
49453+#endif
49454+ return 0;
49455+}
49456+
49457+EXPORT_SYMBOL(gr_pid_is_chrooted);
49458+
49459+#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
49460+int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
49461+{
49462+ struct dentry *dentry = (struct dentry *)u_dentry;
49463+ struct vfsmount *mnt = (struct vfsmount *)u_mnt;
49464+ struct dentry *realroot;
49465+ struct vfsmount *realrootmnt;
49466+ struct dentry *currentroot;
49467+ struct vfsmount *currentmnt;
49468+ struct task_struct *reaper = &init_task;
49469+ int ret = 1;
49470+
49471+ read_lock(&reaper->fs->lock);
49472+ realrootmnt = mntget(reaper->fs->root.mnt);
49473+ realroot = dget(reaper->fs->root.dentry);
49474+ read_unlock(&reaper->fs->lock);
49475+
49476+ read_lock(&current->fs->lock);
49477+ currentmnt = mntget(current->fs->root.mnt);
49478+ currentroot = dget(current->fs->root.dentry);
49479+ read_unlock(&current->fs->lock);
49480+
49481+ spin_lock(&dcache_lock);
49482+ for (;;) {
49483+ if (unlikely((dentry == realroot && mnt == realrootmnt)
49484+ || (dentry == currentroot && mnt == currentmnt)))
49485+ break;
49486+ if (unlikely(dentry == mnt->mnt_root || IS_ROOT(dentry))) {
49487+ if (mnt->mnt_parent == mnt)
49488+ break;
49489+ dentry = mnt->mnt_mountpoint;
49490+ mnt = mnt->mnt_parent;
49491+ continue;
49492+ }
49493+ dentry = dentry->d_parent;
49494+ }
49495+ spin_unlock(&dcache_lock);
49496+
49497+ dput(currentroot);
49498+ mntput(currentmnt);
49499+
49500+ /* access is outside of chroot */
49501+ if (dentry == realroot && mnt == realrootmnt)
49502+ ret = 0;
49503+
49504+ dput(realroot);
49505+ mntput(realrootmnt);
49506+ return ret;
49507+}
49508+#endif
49509+
49510+int
49511+gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
49512+{
49513+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
49514+ if (!grsec_enable_chroot_fchdir)
49515+ return 1;
49516+
49517+ if (!proc_is_chrooted(current))
49518+ return 1;
49519+ else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
49520+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
49521+ return 0;
49522+ }
49523+#endif
49524+ return 1;
49525+}
49526+
49527+int
49528+gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
49529+ const time_t shm_createtime)
49530+{
49531+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
49532+ struct pid *pid = NULL;
49533+ time_t starttime;
49534+
49535+ if (unlikely(!grsec_enable_chroot_shmat))
49536+ return 1;
49537+
49538+ if (likely(!proc_is_chrooted(current)))
49539+ return 1;
49540+
49541+ rcu_read_lock();
49542+ read_lock(&tasklist_lock);
49543+
49544+ pid = find_vpid(shm_cprid);
49545+ if (pid) {
49546+ struct task_struct *p;
49547+ p = pid_task(pid, PIDTYPE_PID);
49548+ if (p == NULL)
49549+ goto unlock;
49550+ starttime = p->start_time.tv_sec;
49551+ if (unlikely(!have_same_root(current, p) &&
49552+ time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime))) {
49553+ read_unlock(&tasklist_lock);
49554+ rcu_read_unlock();
49555+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
49556+ return 0;
49557+ }
49558+ } else {
49559+ pid = find_vpid(shm_lapid);
49560+ if (pid) {
49561+ struct task_struct *p;
49562+ p = pid_task(pid, PIDTYPE_PID);
49563+ if (p == NULL)
49564+ goto unlock;
49565+ if (unlikely(!have_same_root(current, p))) {
49566+ read_unlock(&tasklist_lock);
49567+ rcu_read_unlock();
49568+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
49569+ return 0;
49570+ }
49571+ }
49572+ }
49573+
49574+unlock:
49575+ read_unlock(&tasklist_lock);
49576+ rcu_read_unlock();
49577+#endif
49578+ return 1;
49579+}
49580+
49581+void
49582+gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
49583+{
49584+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
49585+ if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
49586+ gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
49587+#endif
49588+ return;
49589+}
49590+
49591+int
49592+gr_handle_chroot_mknod(const struct dentry *dentry,
49593+ const struct vfsmount *mnt, const int mode)
49594+{
49595+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
49596+ if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
49597+ proc_is_chrooted(current)) {
49598+ gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
49599+ return -EPERM;
49600+ }
49601+#endif
49602+ return 0;
49603+}
49604+
49605+int
49606+gr_handle_chroot_mount(const struct dentry *dentry,
49607+ const struct vfsmount *mnt, const char *dev_name)
49608+{
49609+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
49610+ if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
49611+ gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name, dentry, mnt);
49612+ return -EPERM;
49613+ }
49614+#endif
49615+ return 0;
49616+}
49617+
49618+int
49619+gr_handle_chroot_pivot(void)
49620+{
49621+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
49622+ if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
49623+ gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
49624+ return -EPERM;
49625+ }
49626+#endif
49627+ return 0;
49628+}
49629+
49630+int
49631+gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
49632+{
49633+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
49634+ if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
49635+ !gr_is_outside_chroot(dentry, mnt)) {
49636+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
49637+ return -EPERM;
49638+ }
49639+#endif
49640+ return 0;
49641+}
49642+
49643+int
49644+gr_handle_chroot_caps(struct path *path)
49645+{
49646+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
49647+ if (grsec_enable_chroot_caps && current->pid > 1 && current->fs != NULL &&
49648+ (init_task.fs->root.dentry != path->dentry) &&
49649+ (current->nsproxy->mnt_ns->root->mnt_root != path->dentry)) {
49650+
49651+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
49652+ const struct cred *old = current_cred();
49653+ struct cred *new = prepare_creds();
49654+ if (new == NULL)
49655+ return 1;
49656+
49657+ new->cap_permitted = cap_drop(old->cap_permitted,
49658+ chroot_caps);
49659+ new->cap_inheritable = cap_drop(old->cap_inheritable,
49660+ chroot_caps);
49661+ new->cap_effective = cap_drop(old->cap_effective,
49662+ chroot_caps);
49663+
49664+ commit_creds(new);
49665+
49666+ return 0;
49667+ }
49668+#endif
49669+ return 0;
49670+}
49671+
49672+int
49673+gr_handle_chroot_sysctl(const int op)
49674+{
49675+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
49676+ if (grsec_enable_chroot_sysctl && proc_is_chrooted(current)
49677+ && (op & MAY_WRITE))
49678+ return -EACCES;
49679+#endif
49680+ return 0;
49681+}
49682+
49683+void
49684+gr_handle_chroot_chdir(struct path *path)
49685+{
49686+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
49687+ if (grsec_enable_chroot_chdir)
49688+ set_fs_pwd(current->fs, path);
49689+#endif
49690+ return;
49691+}
49692+
49693+int
49694+gr_handle_chroot_chmod(const struct dentry *dentry,
49695+ const struct vfsmount *mnt, const int mode)
49696+{
49697+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
49698+ /* allow chmod +s on directories, but not on files */
49699+ if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
49700+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
49701+ proc_is_chrooted(current)) {
49702+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
49703+ return -EPERM;
49704+ }
49705+#endif
49706+ return 0;
49707+}
49708+
49709+#ifdef CONFIG_SECURITY
49710+EXPORT_SYMBOL(gr_handle_chroot_caps);
49711+#endif
49712diff -urNp linux-2.6.32.41/grsecurity/grsec_disabled.c linux-2.6.32.41/grsecurity/grsec_disabled.c
49713--- linux-2.6.32.41/grsecurity/grsec_disabled.c 1969-12-31 19:00:00.000000000 -0500
49714+++ linux-2.6.32.41/grsecurity/grsec_disabled.c 2011-04-17 15:56:46.000000000 -0400
49715@@ -0,0 +1,447 @@
49716+#include <linux/kernel.h>
49717+#include <linux/module.h>
49718+#include <linux/sched.h>
49719+#include <linux/file.h>
49720+#include <linux/fs.h>
49721+#include <linux/kdev_t.h>
49722+#include <linux/net.h>
49723+#include <linux/in.h>
49724+#include <linux/ip.h>
49725+#include <linux/skbuff.h>
49726+#include <linux/sysctl.h>
49727+
49728+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
49729+void
49730+pax_set_initial_flags(struct linux_binprm *bprm)
49731+{
49732+ return;
49733+}
49734+#endif
49735+
49736+#ifdef CONFIG_SYSCTL
49737+__u32
49738+gr_handle_sysctl(const struct ctl_table * table, const int op)
49739+{
49740+ return 0;
49741+}
49742+#endif
49743+
49744+#ifdef CONFIG_TASKSTATS
49745+int gr_is_taskstats_denied(int pid)
49746+{
49747+ return 0;
49748+}
49749+#endif
49750+
49751+int
49752+gr_acl_is_enabled(void)
49753+{
49754+ return 0;
49755+}
49756+
49757+int
49758+gr_handle_rawio(const struct inode *inode)
49759+{
49760+ return 0;
49761+}
49762+
49763+void
49764+gr_acl_handle_psacct(struct task_struct *task, const long code)
49765+{
49766+ return;
49767+}
49768+
49769+int
49770+gr_handle_ptrace(struct task_struct *task, const long request)
49771+{
49772+ return 0;
49773+}
49774+
49775+int
49776+gr_handle_proc_ptrace(struct task_struct *task)
49777+{
49778+ return 0;
49779+}
49780+
49781+void
49782+gr_learn_resource(const struct task_struct *task,
49783+ const int res, const unsigned long wanted, const int gt)
49784+{
49785+ return;
49786+}
49787+
49788+int
49789+gr_set_acls(const int type)
49790+{
49791+ return 0;
49792+}
49793+
49794+int
49795+gr_check_hidden_task(const struct task_struct *tsk)
49796+{
49797+ return 0;
49798+}
49799+
49800+int
49801+gr_check_protected_task(const struct task_struct *task)
49802+{
49803+ return 0;
49804+}
49805+
49806+int
49807+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
49808+{
49809+ return 0;
49810+}
49811+
49812+void
49813+gr_copy_label(struct task_struct *tsk)
49814+{
49815+ return;
49816+}
49817+
49818+void
49819+gr_set_pax_flags(struct task_struct *task)
49820+{
49821+ return;
49822+}
49823+
49824+int
49825+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
49826+ const int unsafe_share)
49827+{
49828+ return 0;
49829+}
49830+
49831+void
49832+gr_handle_delete(const ino_t ino, const dev_t dev)
49833+{
49834+ return;
49835+}
49836+
49837+void
49838+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
49839+{
49840+ return;
49841+}
49842+
49843+void
49844+gr_handle_crash(struct task_struct *task, const int sig)
49845+{
49846+ return;
49847+}
49848+
49849+int
49850+gr_check_crash_exec(const struct file *filp)
49851+{
49852+ return 0;
49853+}
49854+
49855+int
49856+gr_check_crash_uid(const uid_t uid)
49857+{
49858+ return 0;
49859+}
49860+
49861+void
49862+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
49863+ struct dentry *old_dentry,
49864+ struct dentry *new_dentry,
49865+ struct vfsmount *mnt, const __u8 replace)
49866+{
49867+ return;
49868+}
49869+
49870+int
49871+gr_search_socket(const int family, const int type, const int protocol)
49872+{
49873+ return 1;
49874+}
49875+
49876+int
49877+gr_search_connectbind(const int mode, const struct socket *sock,
49878+ const struct sockaddr_in *addr)
49879+{
49880+ return 0;
49881+}
49882+
49883+int
49884+gr_is_capable(const int cap)
49885+{
49886+ return 1;
49887+}
49888+
49889+int
49890+gr_is_capable_nolog(const int cap)
49891+{
49892+ return 1;
49893+}
49894+
49895+void
49896+gr_handle_alertkill(struct task_struct *task)
49897+{
49898+ return;
49899+}
49900+
49901+__u32
49902+gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
49903+{
49904+ return 1;
49905+}
49906+
49907+__u32
49908+gr_acl_handle_hidden_file(const struct dentry * dentry,
49909+ const struct vfsmount * mnt)
49910+{
49911+ return 1;
49912+}
49913+
49914+__u32
49915+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
49916+ const int fmode)
49917+{
49918+ return 1;
49919+}
49920+
49921+__u32
49922+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
49923+{
49924+ return 1;
49925+}
49926+
49927+__u32
49928+gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
49929+{
49930+ return 1;
49931+}
49932+
49933+int
49934+gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
49935+ unsigned int *vm_flags)
49936+{
49937+ return 1;
49938+}
49939+
49940+__u32
49941+gr_acl_handle_truncate(const struct dentry * dentry,
49942+ const struct vfsmount * mnt)
49943+{
49944+ return 1;
49945+}
49946+
49947+__u32
49948+gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
49949+{
49950+ return 1;
49951+}
49952+
49953+__u32
49954+gr_acl_handle_access(const struct dentry * dentry,
49955+ const struct vfsmount * mnt, const int fmode)
49956+{
49957+ return 1;
49958+}
49959+
49960+__u32
49961+gr_acl_handle_fchmod(const struct dentry * dentry, const struct vfsmount * mnt,
49962+ mode_t mode)
49963+{
49964+ return 1;
49965+}
49966+
49967+__u32
49968+gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
49969+ mode_t mode)
49970+{
49971+ return 1;
49972+}
49973+
49974+__u32
49975+gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
49976+{
49977+ return 1;
49978+}
49979+
49980+__u32
49981+gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
49982+{
49983+ return 1;
49984+}
49985+
49986+void
49987+grsecurity_init(void)
49988+{
49989+ return;
49990+}
49991+
49992+__u32
49993+gr_acl_handle_mknod(const struct dentry * new_dentry,
49994+ const struct dentry * parent_dentry,
49995+ const struct vfsmount * parent_mnt,
49996+ const int mode)
49997+{
49998+ return 1;
49999+}
50000+
50001+__u32
50002+gr_acl_handle_mkdir(const struct dentry * new_dentry,
50003+ const struct dentry * parent_dentry,
50004+ const struct vfsmount * parent_mnt)
50005+{
50006+ return 1;
50007+}
50008+
50009+__u32
50010+gr_acl_handle_symlink(const struct dentry * new_dentry,
50011+ const struct dentry * parent_dentry,
50012+ const struct vfsmount * parent_mnt, const char *from)
50013+{
50014+ return 1;
50015+}
50016+
50017+__u32
50018+gr_acl_handle_link(const struct dentry * new_dentry,
50019+ const struct dentry * parent_dentry,
50020+ const struct vfsmount * parent_mnt,
50021+ const struct dentry * old_dentry,
50022+ const struct vfsmount * old_mnt, const char *to)
50023+{
50024+ return 1;
50025+}
50026+
50027+int
50028+gr_acl_handle_rename(const struct dentry *new_dentry,
50029+ const struct dentry *parent_dentry,
50030+ const struct vfsmount *parent_mnt,
50031+ const struct dentry *old_dentry,
50032+ const struct inode *old_parent_inode,
50033+ const struct vfsmount *old_mnt, const char *newname)
50034+{
50035+ return 0;
50036+}
50037+
50038+int
50039+gr_acl_handle_filldir(const struct file *file, const char *name,
50040+ const int namelen, const ino_t ino)
50041+{
50042+ return 1;
50043+}
50044+
50045+int
50046+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
50047+ const time_t shm_createtime, const uid_t cuid, const int shmid)
50048+{
50049+ return 1;
50050+}
50051+
50052+int
50053+gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
50054+{
50055+ return 0;
50056+}
50057+
50058+int
50059+gr_search_accept(const struct socket *sock)
50060+{
50061+ return 0;
50062+}
50063+
50064+int
50065+gr_search_listen(const struct socket *sock)
50066+{
50067+ return 0;
50068+}
50069+
50070+int
50071+gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
50072+{
50073+ return 0;
50074+}
50075+
50076+__u32
50077+gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
50078+{
50079+ return 1;
50080+}
50081+
50082+__u32
50083+gr_acl_handle_creat(const struct dentry * dentry,
50084+ const struct dentry * p_dentry,
50085+ const struct vfsmount * p_mnt, const int fmode,
50086+ const int imode)
50087+{
50088+ return 1;
50089+}
50090+
50091+void
50092+gr_acl_handle_exit(void)
50093+{
50094+ return;
50095+}
50096+
50097+int
50098+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
50099+{
50100+ return 1;
50101+}
50102+
50103+void
50104+gr_set_role_label(const uid_t uid, const gid_t gid)
50105+{
50106+ return;
50107+}
50108+
50109+int
50110+gr_acl_handle_procpidmem(const struct task_struct *task)
50111+{
50112+ return 0;
50113+}
50114+
50115+int
50116+gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
50117+{
50118+ return 0;
50119+}
50120+
50121+int
50122+gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
50123+{
50124+ return 0;
50125+}
50126+
50127+void
50128+gr_set_kernel_label(struct task_struct *task)
50129+{
50130+ return;
50131+}
50132+
50133+int
50134+gr_check_user_change(int real, int effective, int fs)
50135+{
50136+ return 0;
50137+}
50138+
50139+int
50140+gr_check_group_change(int real, int effective, int fs)
50141+{
50142+ return 0;
50143+}
50144+
50145+int gr_acl_enable_at_secure(void)
50146+{
50147+ return 0;
50148+}
50149+
50150+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
50151+{
50152+ return dentry->d_inode->i_sb->s_dev;
50153+}
50154+
50155+EXPORT_SYMBOL(gr_is_capable);
50156+EXPORT_SYMBOL(gr_is_capable_nolog);
50157+EXPORT_SYMBOL(gr_learn_resource);
50158+EXPORT_SYMBOL(gr_set_kernel_label);
50159+#ifdef CONFIG_SECURITY
50160+EXPORT_SYMBOL(gr_check_user_change);
50161+EXPORT_SYMBOL(gr_check_group_change);
50162+#endif
50163diff -urNp linux-2.6.32.41/grsecurity/grsec_exec.c linux-2.6.32.41/grsecurity/grsec_exec.c
50164--- linux-2.6.32.41/grsecurity/grsec_exec.c 1969-12-31 19:00:00.000000000 -0500
50165+++ linux-2.6.32.41/grsecurity/grsec_exec.c 2011-04-17 15:56:46.000000000 -0400
50166@@ -0,0 +1,148 @@
50167+#include <linux/kernel.h>
50168+#include <linux/sched.h>
50169+#include <linux/file.h>
50170+#include <linux/binfmts.h>
50171+#include <linux/smp_lock.h>
50172+#include <linux/fs.h>
50173+#include <linux/types.h>
50174+#include <linux/grdefs.h>
50175+#include <linux/grinternal.h>
50176+#include <linux/capability.h>
50177+#include <linux/compat.h>
50178+
50179+#include <asm/uaccess.h>
50180+
50181+#ifdef CONFIG_GRKERNSEC_EXECLOG
50182+static char gr_exec_arg_buf[132];
50183+static DEFINE_MUTEX(gr_exec_arg_mutex);
50184+#endif
50185+
50186+int
50187+gr_handle_nproc(void)
50188+{
50189+#ifdef CONFIG_GRKERNSEC_EXECVE
50190+ const struct cred *cred = current_cred();
50191+ if (grsec_enable_execve && cred->user &&
50192+ (atomic_read(&cred->user->processes) >
50193+ current->signal->rlim[RLIMIT_NPROC].rlim_cur) &&
50194+ !capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE)) {
50195+ gr_log_noargs(GR_DONT_AUDIT, GR_NPROC_MSG);
50196+ return -EAGAIN;
50197+ }
50198+#endif
50199+ return 0;
50200+}
50201+
50202+void
50203+gr_handle_exec_args(struct linux_binprm *bprm, const char __user *const __user *argv)
50204+{
50205+#ifdef CONFIG_GRKERNSEC_EXECLOG
50206+ char *grarg = gr_exec_arg_buf;
50207+ unsigned int i, x, execlen = 0;
50208+ char c;
50209+
50210+ if (!((grsec_enable_execlog && grsec_enable_group &&
50211+ in_group_p(grsec_audit_gid))
50212+ || (grsec_enable_execlog && !grsec_enable_group)))
50213+ return;
50214+
50215+ mutex_lock(&gr_exec_arg_mutex);
50216+ memset(grarg, 0, sizeof(gr_exec_arg_buf));
50217+
50218+ if (unlikely(argv == NULL))
50219+ goto log;
50220+
50221+ for (i = 0; i < bprm->argc && execlen < 128; i++) {
50222+ const char __user *p;
50223+ unsigned int len;
50224+
50225+ if (copy_from_user(&p, argv + i, sizeof(p)))
50226+ goto log;
50227+ if (!p)
50228+ goto log;
50229+ len = strnlen_user(p, 128 - execlen);
50230+ if (len > 128 - execlen)
50231+ len = 128 - execlen;
50232+ else if (len > 0)
50233+ len--;
50234+ if (copy_from_user(grarg + execlen, p, len))
50235+ goto log;
50236+
50237+ /* rewrite unprintable characters */
50238+ for (x = 0; x < len; x++) {
50239+ c = *(grarg + execlen + x);
50240+ if (c < 32 || c > 126)
50241+ *(grarg + execlen + x) = ' ';
50242+ }
50243+
50244+ execlen += len;
50245+ *(grarg + execlen) = ' ';
50246+ *(grarg + execlen + 1) = '\0';
50247+ execlen++;
50248+ }
50249+
50250+ log:
50251+ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
50252+ bprm->file->f_path.mnt, grarg);
50253+ mutex_unlock(&gr_exec_arg_mutex);
50254+#endif
50255+ return;
50256+}
50257+
50258+#ifdef CONFIG_COMPAT
50259+void
50260+gr_handle_exec_args_compat(struct linux_binprm *bprm, compat_uptr_t __user *argv)
50261+{
50262+#ifdef CONFIG_GRKERNSEC_EXECLOG
50263+ char *grarg = gr_exec_arg_buf;
50264+ unsigned int i, x, execlen = 0;
50265+ char c;
50266+
50267+ if (!((grsec_enable_execlog && grsec_enable_group &&
50268+ in_group_p(grsec_audit_gid))
50269+ || (grsec_enable_execlog && !grsec_enable_group)))
50270+ return;
50271+
50272+ mutex_lock(&gr_exec_arg_mutex);
50273+ memset(grarg, 0, sizeof(gr_exec_arg_buf));
50274+
50275+ if (unlikely(argv == NULL))
50276+ goto log;
50277+
50278+ for (i = 0; i < bprm->argc && execlen < 128; i++) {
50279+ compat_uptr_t p;
50280+ unsigned int len;
50281+
50282+ if (get_user(p, argv + i))
50283+ goto log;
50284+ len = strnlen_user(compat_ptr(p), 128 - execlen);
50285+ if (len > 128 - execlen)
50286+ len = 128 - execlen;
50287+ else if (len > 0)
50288+ len--;
50289+ else
50290+ goto log;
50291+ if (copy_from_user(grarg + execlen, compat_ptr(p), len))
50292+ goto log;
50293+
50294+ /* rewrite unprintable characters */
50295+ for (x = 0; x < len; x++) {
50296+ c = *(grarg + execlen + x);
50297+ if (c < 32 || c > 126)
50298+ *(grarg + execlen + x) = ' ';
50299+ }
50300+
50301+ execlen += len;
50302+ *(grarg + execlen) = ' ';
50303+ *(grarg + execlen + 1) = '\0';
50304+ execlen++;
50305+ }
50306+
50307+ log:
50308+ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
50309+ bprm->file->f_path.mnt, grarg);
50310+ mutex_unlock(&gr_exec_arg_mutex);
50311+#endif
50312+ return;
50313+}
50314+#endif
50315diff -urNp linux-2.6.32.41/grsecurity/grsec_fifo.c linux-2.6.32.41/grsecurity/grsec_fifo.c
50316--- linux-2.6.32.41/grsecurity/grsec_fifo.c 1969-12-31 19:00:00.000000000 -0500
50317+++ linux-2.6.32.41/grsecurity/grsec_fifo.c 2011-04-17 15:56:46.000000000 -0400
50318@@ -0,0 +1,24 @@
50319+#include <linux/kernel.h>
50320+#include <linux/sched.h>
50321+#include <linux/fs.h>
50322+#include <linux/file.h>
50323+#include <linux/grinternal.h>
50324+
50325+int
50326+gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
50327+ const struct dentry *dir, const int flag, const int acc_mode)
50328+{
50329+#ifdef CONFIG_GRKERNSEC_FIFO
50330+ const struct cred *cred = current_cred();
50331+
50332+ if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
50333+ !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
50334+ (dentry->d_inode->i_uid != dir->d_inode->i_uid) &&
50335+ (cred->fsuid != dentry->d_inode->i_uid)) {
50336+ if (!inode_permission(dentry->d_inode, acc_mode))
50337+ gr_log_fs_int2(GR_DONT_AUDIT, GR_FIFO_MSG, dentry, mnt, dentry->d_inode->i_uid, dentry->d_inode->i_gid);
50338+ return -EACCES;
50339+ }
50340+#endif
50341+ return 0;
50342+}
50343diff -urNp linux-2.6.32.41/grsecurity/grsec_fork.c linux-2.6.32.41/grsecurity/grsec_fork.c
50344--- linux-2.6.32.41/grsecurity/grsec_fork.c 1969-12-31 19:00:00.000000000 -0500
50345+++ linux-2.6.32.41/grsecurity/grsec_fork.c 2011-04-17 15:56:46.000000000 -0400
50346@@ -0,0 +1,23 @@
50347+#include <linux/kernel.h>
50348+#include <linux/sched.h>
50349+#include <linux/grsecurity.h>
50350+#include <linux/grinternal.h>
50351+#include <linux/errno.h>
50352+
50353+void
50354+gr_log_forkfail(const int retval)
50355+{
50356+#ifdef CONFIG_GRKERNSEC_FORKFAIL
50357+ if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
50358+ switch (retval) {
50359+ case -EAGAIN:
50360+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
50361+ break;
50362+ case -ENOMEM:
50363+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
50364+ break;
50365+ }
50366+ }
50367+#endif
50368+ return;
50369+}
50370diff -urNp linux-2.6.32.41/grsecurity/grsec_init.c linux-2.6.32.41/grsecurity/grsec_init.c
50371--- linux-2.6.32.41/grsecurity/grsec_init.c 1969-12-31 19:00:00.000000000 -0500
50372+++ linux-2.6.32.41/grsecurity/grsec_init.c 2011-04-17 15:56:46.000000000 -0400
50373@@ -0,0 +1,270 @@
50374+#include <linux/kernel.h>
50375+#include <linux/sched.h>
50376+#include <linux/mm.h>
50377+#include <linux/smp_lock.h>
50378+#include <linux/gracl.h>
50379+#include <linux/slab.h>
50380+#include <linux/vmalloc.h>
50381+#include <linux/percpu.h>
50382+#include <linux/module.h>
50383+
50384+int grsec_enable_link;
50385+int grsec_enable_dmesg;
50386+int grsec_enable_harden_ptrace;
50387+int grsec_enable_fifo;
50388+int grsec_enable_execve;
50389+int grsec_enable_execlog;
50390+int grsec_enable_signal;
50391+int grsec_enable_forkfail;
50392+int grsec_enable_audit_ptrace;
50393+int grsec_enable_time;
50394+int grsec_enable_audit_textrel;
50395+int grsec_enable_group;
50396+int grsec_audit_gid;
50397+int grsec_enable_chdir;
50398+int grsec_enable_mount;
50399+int grsec_enable_rofs;
50400+int grsec_enable_chroot_findtask;
50401+int grsec_enable_chroot_mount;
50402+int grsec_enable_chroot_shmat;
50403+int grsec_enable_chroot_fchdir;
50404+int grsec_enable_chroot_double;
50405+int grsec_enable_chroot_pivot;
50406+int grsec_enable_chroot_chdir;
50407+int grsec_enable_chroot_chmod;
50408+int grsec_enable_chroot_mknod;
50409+int grsec_enable_chroot_nice;
50410+int grsec_enable_chroot_execlog;
50411+int grsec_enable_chroot_caps;
50412+int grsec_enable_chroot_sysctl;
50413+int grsec_enable_chroot_unix;
50414+int grsec_enable_tpe;
50415+int grsec_tpe_gid;
50416+int grsec_enable_blackhole;
50417+#ifdef CONFIG_IPV6_MODULE
50418+EXPORT_SYMBOL(grsec_enable_blackhole);
50419+#endif
50420+int grsec_lastack_retries;
50421+int grsec_enable_tpe_all;
50422+int grsec_enable_tpe_invert;
50423+int grsec_enable_socket_all;
50424+int grsec_socket_all_gid;
50425+int grsec_enable_socket_client;
50426+int grsec_socket_client_gid;
50427+int grsec_enable_socket_server;
50428+int grsec_socket_server_gid;
50429+int grsec_resource_logging;
50430+int grsec_disable_privio;
50431+int grsec_enable_log_rwxmaps;
50432+int grsec_lock;
50433+
50434+DEFINE_SPINLOCK(grsec_alert_lock);
50435+unsigned long grsec_alert_wtime = 0;
50436+unsigned long grsec_alert_fyet = 0;
50437+
50438+DEFINE_SPINLOCK(grsec_audit_lock);
50439+
50440+DEFINE_RWLOCK(grsec_exec_file_lock);
50441+
50442+char *gr_shared_page[4];
50443+
50444+char *gr_alert_log_fmt;
50445+char *gr_audit_log_fmt;
50446+char *gr_alert_log_buf;
50447+char *gr_audit_log_buf;
50448+
50449+extern struct gr_arg *gr_usermode;
50450+extern unsigned char *gr_system_salt;
50451+extern unsigned char *gr_system_sum;
50452+
50453+void __init
50454+grsecurity_init(void)
50455+{
50456+ int j;
50457+ /* create the per-cpu shared pages */
50458+
50459+#ifdef CONFIG_X86
50460+ memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
50461+#endif
50462+
50463+ for (j = 0; j < 4; j++) {
50464+ gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
50465+ if (gr_shared_page[j] == NULL) {
50466+ panic("Unable to allocate grsecurity shared page");
50467+ return;
50468+ }
50469+ }
50470+
50471+ /* allocate log buffers */
50472+ gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
50473+ if (!gr_alert_log_fmt) {
50474+ panic("Unable to allocate grsecurity alert log format buffer");
50475+ return;
50476+ }
50477+ gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
50478+ if (!gr_audit_log_fmt) {
50479+ panic("Unable to allocate grsecurity audit log format buffer");
50480+ return;
50481+ }
50482+ gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
50483+ if (!gr_alert_log_buf) {
50484+ panic("Unable to allocate grsecurity alert log buffer");
50485+ return;
50486+ }
50487+ gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
50488+ if (!gr_audit_log_buf) {
50489+ panic("Unable to allocate grsecurity audit log buffer");
50490+ return;
50491+ }
50492+
50493+ /* allocate memory for authentication structure */
50494+ gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
50495+ gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
50496+ gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
50497+
50498+ if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
50499+ panic("Unable to allocate grsecurity authentication structure");
50500+ return;
50501+ }
50502+
50503+
50504+#ifdef CONFIG_GRKERNSEC_IO
50505+#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
50506+ grsec_disable_privio = 1;
50507+#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
50508+ grsec_disable_privio = 1;
50509+#else
50510+ grsec_disable_privio = 0;
50511+#endif
50512+#endif
50513+
50514+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
50515+ /* for backward compatibility, tpe_invert always defaults to on if
50516+ enabled in the kernel
50517+ */
50518+ grsec_enable_tpe_invert = 1;
50519+#endif
50520+
50521+#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
50522+#ifndef CONFIG_GRKERNSEC_SYSCTL
50523+ grsec_lock = 1;
50524+#endif
50525+
50526+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
50527+ grsec_enable_audit_textrel = 1;
50528+#endif
50529+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
50530+ grsec_enable_log_rwxmaps = 1;
50531+#endif
50532+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
50533+ grsec_enable_group = 1;
50534+ grsec_audit_gid = CONFIG_GRKERNSEC_AUDIT_GID;
50535+#endif
50536+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
50537+ grsec_enable_chdir = 1;
50538+#endif
50539+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
50540+ grsec_enable_harden_ptrace = 1;
50541+#endif
50542+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
50543+ grsec_enable_mount = 1;
50544+#endif
50545+#ifdef CONFIG_GRKERNSEC_LINK
50546+ grsec_enable_link = 1;
50547+#endif
50548+#ifdef CONFIG_GRKERNSEC_DMESG
50549+ grsec_enable_dmesg = 1;
50550+#endif
50551+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
50552+ grsec_enable_blackhole = 1;
50553+ grsec_lastack_retries = 4;
50554+#endif
50555+#ifdef CONFIG_GRKERNSEC_FIFO
50556+ grsec_enable_fifo = 1;
50557+#endif
50558+#ifdef CONFIG_GRKERNSEC_EXECVE
50559+ grsec_enable_execve = 1;
50560+#endif
50561+#ifdef CONFIG_GRKERNSEC_EXECLOG
50562+ grsec_enable_execlog = 1;
50563+#endif
50564+#ifdef CONFIG_GRKERNSEC_SIGNAL
50565+ grsec_enable_signal = 1;
50566+#endif
50567+#ifdef CONFIG_GRKERNSEC_FORKFAIL
50568+ grsec_enable_forkfail = 1;
50569+#endif
50570+#ifdef CONFIG_GRKERNSEC_TIME
50571+ grsec_enable_time = 1;
50572+#endif
50573+#ifdef CONFIG_GRKERNSEC_RESLOG
50574+ grsec_resource_logging = 1;
50575+#endif
50576+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
50577+ grsec_enable_chroot_findtask = 1;
50578+#endif
50579+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
50580+ grsec_enable_chroot_unix = 1;
50581+#endif
50582+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
50583+ grsec_enable_chroot_mount = 1;
50584+#endif
50585+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
50586+ grsec_enable_chroot_fchdir = 1;
50587+#endif
50588+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
50589+ grsec_enable_chroot_shmat = 1;
50590+#endif
50591+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
50592+ grsec_enable_audit_ptrace = 1;
50593+#endif
50594+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
50595+ grsec_enable_chroot_double = 1;
50596+#endif
50597+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
50598+ grsec_enable_chroot_pivot = 1;
50599+#endif
50600+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
50601+ grsec_enable_chroot_chdir = 1;
50602+#endif
50603+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
50604+ grsec_enable_chroot_chmod = 1;
50605+#endif
50606+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
50607+ grsec_enable_chroot_mknod = 1;
50608+#endif
50609+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
50610+ grsec_enable_chroot_nice = 1;
50611+#endif
50612+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
50613+ grsec_enable_chroot_execlog = 1;
50614+#endif
50615+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
50616+ grsec_enable_chroot_caps = 1;
50617+#endif
50618+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
50619+ grsec_enable_chroot_sysctl = 1;
50620+#endif
50621+#ifdef CONFIG_GRKERNSEC_TPE
50622+ grsec_enable_tpe = 1;
50623+ grsec_tpe_gid = CONFIG_GRKERNSEC_TPE_GID;
50624+#ifdef CONFIG_GRKERNSEC_TPE_ALL
50625+ grsec_enable_tpe_all = 1;
50626+#endif
50627+#endif
50628+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
50629+ grsec_enable_socket_all = 1;
50630+ grsec_socket_all_gid = CONFIG_GRKERNSEC_SOCKET_ALL_GID;
50631+#endif
50632+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
50633+ grsec_enable_socket_client = 1;
50634+ grsec_socket_client_gid = CONFIG_GRKERNSEC_SOCKET_CLIENT_GID;
50635+#endif
50636+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
50637+ grsec_enable_socket_server = 1;
50638+ grsec_socket_server_gid = CONFIG_GRKERNSEC_SOCKET_SERVER_GID;
50639+#endif
50640+#endif
50641+
50642+ return;
50643+}
50644diff -urNp linux-2.6.32.41/grsecurity/grsec_link.c linux-2.6.32.41/grsecurity/grsec_link.c
50645--- linux-2.6.32.41/grsecurity/grsec_link.c 1969-12-31 19:00:00.000000000 -0500
50646+++ linux-2.6.32.41/grsecurity/grsec_link.c 2011-04-17 15:56:46.000000000 -0400
50647@@ -0,0 +1,43 @@
50648+#include <linux/kernel.h>
50649+#include <linux/sched.h>
50650+#include <linux/fs.h>
50651+#include <linux/file.h>
50652+#include <linux/grinternal.h>
50653+
50654+int
50655+gr_handle_follow_link(const struct inode *parent,
50656+ const struct inode *inode,
50657+ const struct dentry *dentry, const struct vfsmount *mnt)
50658+{
50659+#ifdef CONFIG_GRKERNSEC_LINK
50660+ const struct cred *cred = current_cred();
50661+
50662+ if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
50663+ (parent->i_mode & S_ISVTX) && (parent->i_uid != inode->i_uid) &&
50664+ (parent->i_mode & S_IWOTH) && (cred->fsuid != inode->i_uid)) {
50665+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
50666+ return -EACCES;
50667+ }
50668+#endif
50669+ return 0;
50670+}
50671+
50672+int
50673+gr_handle_hardlink(const struct dentry *dentry,
50674+ const struct vfsmount *mnt,
50675+ struct inode *inode, const int mode, const char *to)
50676+{
50677+#ifdef CONFIG_GRKERNSEC_LINK
50678+ const struct cred *cred = current_cred();
50679+
50680+ if (grsec_enable_link && cred->fsuid != inode->i_uid &&
50681+ (!S_ISREG(mode) || (mode & S_ISUID) ||
50682+ ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP)) ||
50683+ (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
50684+ !capable(CAP_FOWNER) && cred->uid) {
50685+ gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to);
50686+ return -EPERM;
50687+ }
50688+#endif
50689+ return 0;
50690+}
50691diff -urNp linux-2.6.32.41/grsecurity/grsec_log.c linux-2.6.32.41/grsecurity/grsec_log.c
50692--- linux-2.6.32.41/grsecurity/grsec_log.c 1969-12-31 19:00:00.000000000 -0500
50693+++ linux-2.6.32.41/grsecurity/grsec_log.c 2011-05-10 21:58:49.000000000 -0400
50694@@ -0,0 +1,310 @@
50695+#include <linux/kernel.h>
50696+#include <linux/sched.h>
50697+#include <linux/file.h>
50698+#include <linux/tty.h>
50699+#include <linux/fs.h>
50700+#include <linux/grinternal.h>
50701+
50702+#ifdef CONFIG_TREE_PREEMPT_RCU
50703+#define DISABLE_PREEMPT() preempt_disable()
50704+#define ENABLE_PREEMPT() preempt_enable()
50705+#else
50706+#define DISABLE_PREEMPT()
50707+#define ENABLE_PREEMPT()
50708+#endif
50709+
50710+#define BEGIN_LOCKS(x) \
50711+ DISABLE_PREEMPT(); \
50712+ rcu_read_lock(); \
50713+ read_lock(&tasklist_lock); \
50714+ read_lock(&grsec_exec_file_lock); \
50715+ if (x != GR_DO_AUDIT) \
50716+ spin_lock(&grsec_alert_lock); \
50717+ else \
50718+ spin_lock(&grsec_audit_lock)
50719+
50720+#define END_LOCKS(x) \
50721+ if (x != GR_DO_AUDIT) \
50722+ spin_unlock(&grsec_alert_lock); \
50723+ else \
50724+ spin_unlock(&grsec_audit_lock); \
50725+ read_unlock(&grsec_exec_file_lock); \
50726+ read_unlock(&tasklist_lock); \
50727+ rcu_read_unlock(); \
50728+ ENABLE_PREEMPT(); \
50729+ if (x == GR_DONT_AUDIT) \
50730+ gr_handle_alertkill(current)
50731+
50732+enum {
50733+ FLOODING,
50734+ NO_FLOODING
50735+};
50736+
50737+extern char *gr_alert_log_fmt;
50738+extern char *gr_audit_log_fmt;
50739+extern char *gr_alert_log_buf;
50740+extern char *gr_audit_log_buf;
50741+
50742+static int gr_log_start(int audit)
50743+{
50744+ char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
50745+ char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
50746+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
50747+
50748+ if (audit == GR_DO_AUDIT)
50749+ goto set_fmt;
50750+
50751+ if (!grsec_alert_wtime || jiffies - grsec_alert_wtime > CONFIG_GRKERNSEC_FLOODTIME * HZ) {
50752+ grsec_alert_wtime = jiffies;
50753+ grsec_alert_fyet = 0;
50754+ } else if ((jiffies - grsec_alert_wtime < CONFIG_GRKERNSEC_FLOODTIME * HZ) && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
50755+ grsec_alert_fyet++;
50756+ } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
50757+ grsec_alert_wtime = jiffies;
50758+ grsec_alert_fyet++;
50759+ printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
50760+ return FLOODING;
50761+ } else return FLOODING;
50762+
50763+set_fmt:
50764+ memset(buf, 0, PAGE_SIZE);
50765+ if (current->signal->curr_ip && gr_acl_is_enabled()) {
50766+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
50767+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
50768+ } else if (current->signal->curr_ip) {
50769+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
50770+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
50771+ } else if (gr_acl_is_enabled()) {
50772+ sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
50773+ snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
50774+ } else {
50775+ sprintf(fmt, "%s%s", loglevel, "grsec: ");
50776+ strcpy(buf, fmt);
50777+ }
50778+
50779+ return NO_FLOODING;
50780+}
50781+
50782+static void gr_log_middle(int audit, const char *msg, va_list ap)
50783+ __attribute__ ((format (printf, 2, 0)));
50784+
50785+static void gr_log_middle(int audit, const char *msg, va_list ap)
50786+{
50787+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
50788+ unsigned int len = strlen(buf);
50789+
50790+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
50791+
50792+ return;
50793+}
50794+
50795+static void gr_log_middle_varargs(int audit, const char *msg, ...)
50796+ __attribute__ ((format (printf, 2, 3)));
50797+
50798+static void gr_log_middle_varargs(int audit, const char *msg, ...)
50799+{
50800+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
50801+ unsigned int len = strlen(buf);
50802+ va_list ap;
50803+
50804+ va_start(ap, msg);
50805+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
50806+ va_end(ap);
50807+
50808+ return;
50809+}
50810+
50811+static void gr_log_end(int audit)
50812+{
50813+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
50814+ unsigned int len = strlen(buf);
50815+
50816+ snprintf(buf + len, PAGE_SIZE - len - 1, DEFAULTSECMSG, DEFAULTSECARGS(current, current_cred(), __task_cred(current->real_parent)));
50817+ printk("%s\n", buf);
50818+
50819+ return;
50820+}
50821+
50822+void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
50823+{
50824+ int logtype;
50825+ char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
50826+ char *str1 = NULL, *str2 = NULL, *str3 = NULL;
50827+ void *voidptr = NULL;
50828+ int num1 = 0, num2 = 0;
50829+ unsigned long ulong1 = 0, ulong2 = 0;
50830+ struct dentry *dentry = NULL;
50831+ struct vfsmount *mnt = NULL;
50832+ struct file *file = NULL;
50833+ struct task_struct *task = NULL;
50834+ const struct cred *cred, *pcred;
50835+ va_list ap;
50836+
50837+ BEGIN_LOCKS(audit);
50838+ logtype = gr_log_start(audit);
50839+ if (logtype == FLOODING) {
50840+ END_LOCKS(audit);
50841+ return;
50842+ }
50843+ va_start(ap, argtypes);
50844+ switch (argtypes) {
50845+ case GR_TTYSNIFF:
50846+ task = va_arg(ap, struct task_struct *);
50847+ 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);
50848+ break;
50849+ case GR_SYSCTL_HIDDEN:
50850+ str1 = va_arg(ap, char *);
50851+ gr_log_middle_varargs(audit, msg, result, str1);
50852+ break;
50853+ case GR_RBAC:
50854+ dentry = va_arg(ap, struct dentry *);
50855+ mnt = va_arg(ap, struct vfsmount *);
50856+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
50857+ break;
50858+ case GR_RBAC_STR:
50859+ dentry = va_arg(ap, struct dentry *);
50860+ mnt = va_arg(ap, struct vfsmount *);
50861+ str1 = va_arg(ap, char *);
50862+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
50863+ break;
50864+ case GR_STR_RBAC:
50865+ str1 = va_arg(ap, char *);
50866+ dentry = va_arg(ap, struct dentry *);
50867+ mnt = va_arg(ap, struct vfsmount *);
50868+ gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
50869+ break;
50870+ case GR_RBAC_MODE2:
50871+ dentry = va_arg(ap, struct dentry *);
50872+ mnt = va_arg(ap, struct vfsmount *);
50873+ str1 = va_arg(ap, char *);
50874+ str2 = va_arg(ap, char *);
50875+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
50876+ break;
50877+ case GR_RBAC_MODE3:
50878+ dentry = va_arg(ap, struct dentry *);
50879+ mnt = va_arg(ap, struct vfsmount *);
50880+ str1 = va_arg(ap, char *);
50881+ str2 = va_arg(ap, char *);
50882+ str3 = va_arg(ap, char *);
50883+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
50884+ break;
50885+ case GR_FILENAME:
50886+ dentry = va_arg(ap, struct dentry *);
50887+ mnt = va_arg(ap, struct vfsmount *);
50888+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
50889+ break;
50890+ case GR_STR_FILENAME:
50891+ str1 = va_arg(ap, char *);
50892+ dentry = va_arg(ap, struct dentry *);
50893+ mnt = va_arg(ap, struct vfsmount *);
50894+ gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
50895+ break;
50896+ case GR_FILENAME_STR:
50897+ dentry = va_arg(ap, struct dentry *);
50898+ mnt = va_arg(ap, struct vfsmount *);
50899+ str1 = va_arg(ap, char *);
50900+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
50901+ break;
50902+ case GR_FILENAME_TWO_INT:
50903+ dentry = va_arg(ap, struct dentry *);
50904+ mnt = va_arg(ap, struct vfsmount *);
50905+ num1 = va_arg(ap, int);
50906+ num2 = va_arg(ap, int);
50907+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
50908+ break;
50909+ case GR_FILENAME_TWO_INT_STR:
50910+ dentry = va_arg(ap, struct dentry *);
50911+ mnt = va_arg(ap, struct vfsmount *);
50912+ num1 = va_arg(ap, int);
50913+ num2 = va_arg(ap, int);
50914+ str1 = va_arg(ap, char *);
50915+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
50916+ break;
50917+ case GR_TEXTREL:
50918+ file = va_arg(ap, struct file *);
50919+ ulong1 = va_arg(ap, unsigned long);
50920+ ulong2 = va_arg(ap, unsigned long);
50921+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
50922+ break;
50923+ case GR_PTRACE:
50924+ task = va_arg(ap, struct task_struct *);
50925+ 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);
50926+ break;
50927+ case GR_RESOURCE:
50928+ task = va_arg(ap, struct task_struct *);
50929+ cred = __task_cred(task);
50930+ pcred = __task_cred(task->real_parent);
50931+ ulong1 = va_arg(ap, unsigned long);
50932+ str1 = va_arg(ap, char *);
50933+ ulong2 = va_arg(ap, unsigned long);
50934+ 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);
50935+ break;
50936+ case GR_CAP:
50937+ task = va_arg(ap, struct task_struct *);
50938+ cred = __task_cred(task);
50939+ pcred = __task_cred(task->real_parent);
50940+ str1 = va_arg(ap, char *);
50941+ 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);
50942+ break;
50943+ case GR_SIG:
50944+ str1 = va_arg(ap, char *);
50945+ voidptr = va_arg(ap, void *);
50946+ gr_log_middle_varargs(audit, msg, str1, voidptr);
50947+ break;
50948+ case GR_SIG2:
50949+ task = va_arg(ap, struct task_struct *);
50950+ cred = __task_cred(task);
50951+ pcred = __task_cred(task->real_parent);
50952+ num1 = va_arg(ap, int);
50953+ 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);
50954+ break;
50955+ case GR_CRASH1:
50956+ task = va_arg(ap, struct task_struct *);
50957+ cred = __task_cred(task);
50958+ pcred = __task_cred(task->real_parent);
50959+ ulong1 = va_arg(ap, unsigned long);
50960+ 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);
50961+ break;
50962+ case GR_CRASH2:
50963+ task = va_arg(ap, struct task_struct *);
50964+ cred = __task_cred(task);
50965+ pcred = __task_cred(task->real_parent);
50966+ ulong1 = va_arg(ap, unsigned long);
50967+ 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);
50968+ break;
50969+ case GR_RWXMAP:
50970+ file = va_arg(ap, struct file *);
50971+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
50972+ break;
50973+ case GR_PSACCT:
50974+ {
50975+ unsigned int wday, cday;
50976+ __u8 whr, chr;
50977+ __u8 wmin, cmin;
50978+ __u8 wsec, csec;
50979+ char cur_tty[64] = { 0 };
50980+ char parent_tty[64] = { 0 };
50981+
50982+ task = va_arg(ap, struct task_struct *);
50983+ wday = va_arg(ap, unsigned int);
50984+ cday = va_arg(ap, unsigned int);
50985+ whr = va_arg(ap, int);
50986+ chr = va_arg(ap, int);
50987+ wmin = va_arg(ap, int);
50988+ cmin = va_arg(ap, int);
50989+ wsec = va_arg(ap, int);
50990+ csec = va_arg(ap, int);
50991+ ulong1 = va_arg(ap, unsigned long);
50992+ cred = __task_cred(task);
50993+ pcred = __task_cred(task->real_parent);
50994+
50995+ 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);
50996+ }
50997+ break;
50998+ default:
50999+ gr_log_middle(audit, msg, ap);
51000+ }
51001+ va_end(ap);
51002+ gr_log_end(audit);
51003+ END_LOCKS(audit);
51004+}
51005diff -urNp linux-2.6.32.41/grsecurity/grsec_mem.c linux-2.6.32.41/grsecurity/grsec_mem.c
51006--- linux-2.6.32.41/grsecurity/grsec_mem.c 1969-12-31 19:00:00.000000000 -0500
51007+++ linux-2.6.32.41/grsecurity/grsec_mem.c 2011-04-17 15:56:46.000000000 -0400
51008@@ -0,0 +1,33 @@
51009+#include <linux/kernel.h>
51010+#include <linux/sched.h>
51011+#include <linux/mm.h>
51012+#include <linux/mman.h>
51013+#include <linux/grinternal.h>
51014+
51015+void
51016+gr_handle_ioperm(void)
51017+{
51018+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
51019+ return;
51020+}
51021+
51022+void
51023+gr_handle_iopl(void)
51024+{
51025+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
51026+ return;
51027+}
51028+
51029+void
51030+gr_handle_mem_readwrite(u64 from, u64 to)
51031+{
51032+ gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
51033+ return;
51034+}
51035+
51036+void
51037+gr_handle_vm86(void)
51038+{
51039+ gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
51040+ return;
51041+}
51042diff -urNp linux-2.6.32.41/grsecurity/grsec_mount.c linux-2.6.32.41/grsecurity/grsec_mount.c
51043--- linux-2.6.32.41/grsecurity/grsec_mount.c 1969-12-31 19:00:00.000000000 -0500
51044+++ linux-2.6.32.41/grsecurity/grsec_mount.c 2011-04-17 15:56:46.000000000 -0400
51045@@ -0,0 +1,62 @@
51046+#include <linux/kernel.h>
51047+#include <linux/sched.h>
51048+#include <linux/mount.h>
51049+#include <linux/grsecurity.h>
51050+#include <linux/grinternal.h>
51051+
51052+void
51053+gr_log_remount(const char *devname, const int retval)
51054+{
51055+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
51056+ if (grsec_enable_mount && (retval >= 0))
51057+ gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
51058+#endif
51059+ return;
51060+}
51061+
51062+void
51063+gr_log_unmount(const char *devname, const int retval)
51064+{
51065+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
51066+ if (grsec_enable_mount && (retval >= 0))
51067+ gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
51068+#endif
51069+ return;
51070+}
51071+
51072+void
51073+gr_log_mount(const char *from, const char *to, const int retval)
51074+{
51075+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
51076+ if (grsec_enable_mount && (retval >= 0))
51077+ gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from, to);
51078+#endif
51079+ return;
51080+}
51081+
51082+int
51083+gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
51084+{
51085+#ifdef CONFIG_GRKERNSEC_ROFS
51086+ if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
51087+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
51088+ return -EPERM;
51089+ } else
51090+ return 0;
51091+#endif
51092+ return 0;
51093+}
51094+
51095+int
51096+gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
51097+{
51098+#ifdef CONFIG_GRKERNSEC_ROFS
51099+ if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
51100+ dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
51101+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
51102+ return -EPERM;
51103+ } else
51104+ return 0;
51105+#endif
51106+ return 0;
51107+}
51108diff -urNp linux-2.6.32.41/grsecurity/grsec_pax.c linux-2.6.32.41/grsecurity/grsec_pax.c
51109--- linux-2.6.32.41/grsecurity/grsec_pax.c 1969-12-31 19:00:00.000000000 -0500
51110+++ linux-2.6.32.41/grsecurity/grsec_pax.c 2011-04-17 15:56:46.000000000 -0400
51111@@ -0,0 +1,36 @@
51112+#include <linux/kernel.h>
51113+#include <linux/sched.h>
51114+#include <linux/mm.h>
51115+#include <linux/file.h>
51116+#include <linux/grinternal.h>
51117+#include <linux/grsecurity.h>
51118+
51119+void
51120+gr_log_textrel(struct vm_area_struct * vma)
51121+{
51122+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
51123+ if (grsec_enable_audit_textrel)
51124+ gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
51125+#endif
51126+ return;
51127+}
51128+
51129+void
51130+gr_log_rwxmmap(struct file *file)
51131+{
51132+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
51133+ if (grsec_enable_log_rwxmaps)
51134+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
51135+#endif
51136+ return;
51137+}
51138+
51139+void
51140+gr_log_rwxmprotect(struct file *file)
51141+{
51142+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
51143+ if (grsec_enable_log_rwxmaps)
51144+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
51145+#endif
51146+ return;
51147+}
51148diff -urNp linux-2.6.32.41/grsecurity/grsec_ptrace.c linux-2.6.32.41/grsecurity/grsec_ptrace.c
51149--- linux-2.6.32.41/grsecurity/grsec_ptrace.c 1969-12-31 19:00:00.000000000 -0500
51150+++ linux-2.6.32.41/grsecurity/grsec_ptrace.c 2011-04-17 15:56:46.000000000 -0400
51151@@ -0,0 +1,14 @@
51152+#include <linux/kernel.h>
51153+#include <linux/sched.h>
51154+#include <linux/grinternal.h>
51155+#include <linux/grsecurity.h>
51156+
51157+void
51158+gr_audit_ptrace(struct task_struct *task)
51159+{
51160+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
51161+ if (grsec_enable_audit_ptrace)
51162+ gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
51163+#endif
51164+ return;
51165+}
51166diff -urNp linux-2.6.32.41/grsecurity/grsec_sig.c linux-2.6.32.41/grsecurity/grsec_sig.c
51167--- linux-2.6.32.41/grsecurity/grsec_sig.c 1969-12-31 19:00:00.000000000 -0500
51168+++ linux-2.6.32.41/grsecurity/grsec_sig.c 2011-05-17 17:30:04.000000000 -0400
51169@@ -0,0 +1,202 @@
51170+#include <linux/kernel.h>
51171+#include <linux/sched.h>
51172+#include <linux/delay.h>
51173+#include <linux/grsecurity.h>
51174+#include <linux/grinternal.h>
51175+#include <linux/hardirq.h>
51176+
51177+char *signames[] = {
51178+ [SIGSEGV] = "Segmentation fault",
51179+ [SIGILL] = "Illegal instruction",
51180+ [SIGABRT] = "Abort",
51181+ [SIGBUS] = "Invalid alignment/Bus error"
51182+};
51183+
51184+void
51185+gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
51186+{
51187+#ifdef CONFIG_GRKERNSEC_SIGNAL
51188+ if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
51189+ (sig == SIGABRT) || (sig == SIGBUS))) {
51190+ if (t->pid == current->pid) {
51191+ gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
51192+ } else {
51193+ gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
51194+ }
51195+ }
51196+#endif
51197+ return;
51198+}
51199+
51200+int
51201+gr_handle_signal(const struct task_struct *p, const int sig)
51202+{
51203+#ifdef CONFIG_GRKERNSEC
51204+ if (current->pid > 1 && gr_check_protected_task(p)) {
51205+ gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
51206+ return -EPERM;
51207+ } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
51208+ return -EPERM;
51209+ }
51210+#endif
51211+ return 0;
51212+}
51213+
51214+#ifdef CONFIG_GRKERNSEC
51215+extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
51216+
51217+int gr_fake_force_sig(int sig, struct task_struct *t)
51218+{
51219+ unsigned long int flags;
51220+ int ret, blocked, ignored;
51221+ struct k_sigaction *action;
51222+
51223+ spin_lock_irqsave(&t->sighand->siglock, flags);
51224+ action = &t->sighand->action[sig-1];
51225+ ignored = action->sa.sa_handler == SIG_IGN;
51226+ blocked = sigismember(&t->blocked, sig);
51227+ if (blocked || ignored) {
51228+ action->sa.sa_handler = SIG_DFL;
51229+ if (blocked) {
51230+ sigdelset(&t->blocked, sig);
51231+ recalc_sigpending_and_wake(t);
51232+ }
51233+ }
51234+ if (action->sa.sa_handler == SIG_DFL)
51235+ t->signal->flags &= ~SIGNAL_UNKILLABLE;
51236+ ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
51237+
51238+ spin_unlock_irqrestore(&t->sighand->siglock, flags);
51239+
51240+ return ret;
51241+}
51242+#endif
51243+
51244+#ifdef CONFIG_GRKERNSEC_BRUTE
51245+#define GR_USER_BAN_TIME (15 * 60)
51246+
51247+static int __get_dumpable(unsigned long mm_flags)
51248+{
51249+ int ret;
51250+
51251+ ret = mm_flags & MMF_DUMPABLE_MASK;
51252+ return (ret >= 2) ? 2 : ret;
51253+}
51254+#endif
51255+
51256+void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags)
51257+{
51258+#ifdef CONFIG_GRKERNSEC_BRUTE
51259+ uid_t uid = 0;
51260+
51261+ rcu_read_lock();
51262+ read_lock(&tasklist_lock);
51263+ read_lock(&grsec_exec_file_lock);
51264+ if (p->real_parent && p->real_parent->exec_file == p->exec_file)
51265+ p->real_parent->brute = 1;
51266+ else {
51267+ const struct cred *cred = __task_cred(p), *cred2;
51268+ struct task_struct *tsk, *tsk2;
51269+
51270+ if (!__get_dumpable(mm_flags) && cred->uid) {
51271+ struct user_struct *user;
51272+
51273+ uid = cred->uid;
51274+
51275+ /* this is put upon execution past expiration */
51276+ user = find_user(uid);
51277+ if (user == NULL)
51278+ goto unlock;
51279+ user->banned = 1;
51280+ user->ban_expires = get_seconds() + GR_USER_BAN_TIME;
51281+ if (user->ban_expires == ~0UL)
51282+ user->ban_expires--;
51283+
51284+ do_each_thread(tsk2, tsk) {
51285+ cred2 = __task_cred(tsk);
51286+ if (tsk != p && cred2->uid == uid)
51287+ gr_fake_force_sig(SIGKILL, tsk);
51288+ } while_each_thread(tsk2, tsk);
51289+ }
51290+ }
51291+unlock:
51292+ read_unlock(&grsec_exec_file_lock);
51293+ read_unlock(&tasklist_lock);
51294+ rcu_read_unlock();
51295+
51296+ if (uid)
51297+ printk(KERN_ALERT "grsec: bruteforce prevention initiated against uid %u, banning for %d minutes\n", uid, GR_USER_BAN_TIME / 60);
51298+#endif
51299+ return;
51300+}
51301+
51302+void gr_handle_brute_check(void)
51303+{
51304+#ifdef CONFIG_GRKERNSEC_BRUTE
51305+ if (current->brute)
51306+ msleep(30 * 1000);
51307+#endif
51308+ return;
51309+}
51310+
51311+void gr_handle_kernel_exploit(void)
51312+{
51313+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
51314+ const struct cred *cred;
51315+ struct task_struct *tsk, *tsk2;
51316+ struct user_struct *user;
51317+ uid_t uid;
51318+
51319+ if (in_irq() || in_serving_softirq() || in_nmi())
51320+ panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
51321+
51322+ uid = current_uid();
51323+
51324+ if (uid == 0)
51325+ panic("grsec: halting the system due to suspicious kernel crash caused by root");
51326+ else {
51327+ /* kill all the processes of this user, hold a reference
51328+ to their creds struct, and prevent them from creating
51329+ another process until system reset
51330+ */
51331+ printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n", uid);
51332+ /* we intentionally leak this ref */
51333+ user = get_uid(current->cred->user);
51334+ if (user) {
51335+ user->banned = 1;
51336+ user->ban_expires = ~0UL;
51337+ }
51338+
51339+ read_lock(&tasklist_lock);
51340+ do_each_thread(tsk2, tsk) {
51341+ cred = __task_cred(tsk);
51342+ if (cred->uid == uid)
51343+ gr_fake_force_sig(SIGKILL, tsk);
51344+ } while_each_thread(tsk2, tsk);
51345+ read_unlock(&tasklist_lock);
51346+ }
51347+#endif
51348+}
51349+
51350+int __gr_process_user_ban(struct user_struct *user)
51351+{
51352+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
51353+ if (unlikely(user->banned)) {
51354+ if (user->ban_expires != ~0UL && time_after_eq(get_seconds(), user->ban_expires)) {
51355+ user->banned = 0;
51356+ user->ban_expires = 0;
51357+ free_uid(user);
51358+ } else
51359+ return -EPERM;
51360+ }
51361+#endif
51362+ return 0;
51363+}
51364+
51365+int gr_process_user_ban(void)
51366+{
51367+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
51368+ return __gr_process_user_ban(current->cred->user);
51369+#endif
51370+ return 0;
51371+}
51372diff -urNp linux-2.6.32.41/grsecurity/grsec_sock.c linux-2.6.32.41/grsecurity/grsec_sock.c
51373--- linux-2.6.32.41/grsecurity/grsec_sock.c 1969-12-31 19:00:00.000000000 -0500
51374+++ linux-2.6.32.41/grsecurity/grsec_sock.c 2011-04-17 15:56:46.000000000 -0400
51375@@ -0,0 +1,275 @@
51376+#include <linux/kernel.h>
51377+#include <linux/module.h>
51378+#include <linux/sched.h>
51379+#include <linux/file.h>
51380+#include <linux/net.h>
51381+#include <linux/in.h>
51382+#include <linux/ip.h>
51383+#include <net/sock.h>
51384+#include <net/inet_sock.h>
51385+#include <linux/grsecurity.h>
51386+#include <linux/grinternal.h>
51387+#include <linux/gracl.h>
51388+
51389+kernel_cap_t gr_cap_rtnetlink(struct sock *sock);
51390+EXPORT_SYMBOL(gr_cap_rtnetlink);
51391+
51392+extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
51393+extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
51394+
51395+EXPORT_SYMBOL(gr_search_udp_recvmsg);
51396+EXPORT_SYMBOL(gr_search_udp_sendmsg);
51397+
51398+#ifdef CONFIG_UNIX_MODULE
51399+EXPORT_SYMBOL(gr_acl_handle_unix);
51400+EXPORT_SYMBOL(gr_acl_handle_mknod);
51401+EXPORT_SYMBOL(gr_handle_chroot_unix);
51402+EXPORT_SYMBOL(gr_handle_create);
51403+#endif
51404+
51405+#ifdef CONFIG_GRKERNSEC
51406+#define gr_conn_table_size 32749
51407+struct conn_table_entry {
51408+ struct conn_table_entry *next;
51409+ struct signal_struct *sig;
51410+};
51411+
51412+struct conn_table_entry *gr_conn_table[gr_conn_table_size];
51413+DEFINE_SPINLOCK(gr_conn_table_lock);
51414+
51415+extern const char * gr_socktype_to_name(unsigned char type);
51416+extern const char * gr_proto_to_name(unsigned char proto);
51417+extern const char * gr_sockfamily_to_name(unsigned char family);
51418+
51419+static __inline__ int
51420+conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
51421+{
51422+ return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
51423+}
51424+
51425+static __inline__ int
51426+conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
51427+ __u16 sport, __u16 dport)
51428+{
51429+ if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
51430+ sig->gr_sport == sport && sig->gr_dport == dport))
51431+ return 1;
51432+ else
51433+ return 0;
51434+}
51435+
51436+static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
51437+{
51438+ struct conn_table_entry **match;
51439+ unsigned int index;
51440+
51441+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
51442+ sig->gr_sport, sig->gr_dport,
51443+ gr_conn_table_size);
51444+
51445+ newent->sig = sig;
51446+
51447+ match = &gr_conn_table[index];
51448+ newent->next = *match;
51449+ *match = newent;
51450+
51451+ return;
51452+}
51453+
51454+static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
51455+{
51456+ struct conn_table_entry *match, *last = NULL;
51457+ unsigned int index;
51458+
51459+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
51460+ sig->gr_sport, sig->gr_dport,
51461+ gr_conn_table_size);
51462+
51463+ match = gr_conn_table[index];
51464+ while (match && !conn_match(match->sig,
51465+ sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
51466+ sig->gr_dport)) {
51467+ last = match;
51468+ match = match->next;
51469+ }
51470+
51471+ if (match) {
51472+ if (last)
51473+ last->next = match->next;
51474+ else
51475+ gr_conn_table[index] = NULL;
51476+ kfree(match);
51477+ }
51478+
51479+ return;
51480+}
51481+
51482+static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
51483+ __u16 sport, __u16 dport)
51484+{
51485+ struct conn_table_entry *match;
51486+ unsigned int index;
51487+
51488+ index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
51489+
51490+ match = gr_conn_table[index];
51491+ while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
51492+ match = match->next;
51493+
51494+ if (match)
51495+ return match->sig;
51496+ else
51497+ return NULL;
51498+}
51499+
51500+#endif
51501+
51502+void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
51503+{
51504+#ifdef CONFIG_GRKERNSEC
51505+ struct signal_struct *sig = task->signal;
51506+ struct conn_table_entry *newent;
51507+
51508+ newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
51509+ if (newent == NULL)
51510+ return;
51511+ /* no bh lock needed since we are called with bh disabled */
51512+ spin_lock(&gr_conn_table_lock);
51513+ gr_del_task_from_ip_table_nolock(sig);
51514+ sig->gr_saddr = inet->rcv_saddr;
51515+ sig->gr_daddr = inet->daddr;
51516+ sig->gr_sport = inet->sport;
51517+ sig->gr_dport = inet->dport;
51518+ gr_add_to_task_ip_table_nolock(sig, newent);
51519+ spin_unlock(&gr_conn_table_lock);
51520+#endif
51521+ return;
51522+}
51523+
51524+void gr_del_task_from_ip_table(struct task_struct *task)
51525+{
51526+#ifdef CONFIG_GRKERNSEC
51527+ spin_lock_bh(&gr_conn_table_lock);
51528+ gr_del_task_from_ip_table_nolock(task->signal);
51529+ spin_unlock_bh(&gr_conn_table_lock);
51530+#endif
51531+ return;
51532+}
51533+
51534+void
51535+gr_attach_curr_ip(const struct sock *sk)
51536+{
51537+#ifdef CONFIG_GRKERNSEC
51538+ struct signal_struct *p, *set;
51539+ const struct inet_sock *inet = inet_sk(sk);
51540+
51541+ if (unlikely(sk->sk_protocol != IPPROTO_TCP))
51542+ return;
51543+
51544+ set = current->signal;
51545+
51546+ spin_lock_bh(&gr_conn_table_lock);
51547+ p = gr_lookup_task_ip_table(inet->daddr, inet->rcv_saddr,
51548+ inet->dport, inet->sport);
51549+ if (unlikely(p != NULL)) {
51550+ set->curr_ip = p->curr_ip;
51551+ set->used_accept = 1;
51552+ gr_del_task_from_ip_table_nolock(p);
51553+ spin_unlock_bh(&gr_conn_table_lock);
51554+ return;
51555+ }
51556+ spin_unlock_bh(&gr_conn_table_lock);
51557+
51558+ set->curr_ip = inet->daddr;
51559+ set->used_accept = 1;
51560+#endif
51561+ return;
51562+}
51563+
51564+int
51565+gr_handle_sock_all(const int family, const int type, const int protocol)
51566+{
51567+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
51568+ if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
51569+ (family != AF_UNIX)) {
51570+ if (family == AF_INET)
51571+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
51572+ else
51573+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
51574+ return -EACCES;
51575+ }
51576+#endif
51577+ return 0;
51578+}
51579+
51580+int
51581+gr_handle_sock_server(const struct sockaddr *sck)
51582+{
51583+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
51584+ if (grsec_enable_socket_server &&
51585+ in_group_p(grsec_socket_server_gid) &&
51586+ sck && (sck->sa_family != AF_UNIX) &&
51587+ (sck->sa_family != AF_LOCAL)) {
51588+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
51589+ return -EACCES;
51590+ }
51591+#endif
51592+ return 0;
51593+}
51594+
51595+int
51596+gr_handle_sock_server_other(const struct sock *sck)
51597+{
51598+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
51599+ if (grsec_enable_socket_server &&
51600+ in_group_p(grsec_socket_server_gid) &&
51601+ sck && (sck->sk_family != AF_UNIX) &&
51602+ (sck->sk_family != AF_LOCAL)) {
51603+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
51604+ return -EACCES;
51605+ }
51606+#endif
51607+ return 0;
51608+}
51609+
51610+int
51611+gr_handle_sock_client(const struct sockaddr *sck)
51612+{
51613+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
51614+ if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
51615+ sck && (sck->sa_family != AF_UNIX) &&
51616+ (sck->sa_family != AF_LOCAL)) {
51617+ gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
51618+ return -EACCES;
51619+ }
51620+#endif
51621+ return 0;
51622+}
51623+
51624+kernel_cap_t
51625+gr_cap_rtnetlink(struct sock *sock)
51626+{
51627+#ifdef CONFIG_GRKERNSEC
51628+ if (!gr_acl_is_enabled())
51629+ return current_cap();
51630+ else if (sock->sk_protocol == NETLINK_ISCSI &&
51631+ cap_raised(current_cap(), CAP_SYS_ADMIN) &&
51632+ gr_is_capable(CAP_SYS_ADMIN))
51633+ return current_cap();
51634+ else if (sock->sk_protocol == NETLINK_AUDIT &&
51635+ cap_raised(current_cap(), CAP_AUDIT_WRITE) &&
51636+ gr_is_capable(CAP_AUDIT_WRITE) &&
51637+ cap_raised(current_cap(), CAP_AUDIT_CONTROL) &&
51638+ gr_is_capable(CAP_AUDIT_CONTROL))
51639+ return current_cap();
51640+ else if (cap_raised(current_cap(), CAP_NET_ADMIN) &&
51641+ ((sock->sk_protocol == NETLINK_ROUTE) ?
51642+ gr_is_capable_nolog(CAP_NET_ADMIN) :
51643+ gr_is_capable(CAP_NET_ADMIN)))
51644+ return current_cap();
51645+ else
51646+ return __cap_empty_set;
51647+#else
51648+ return current_cap();
51649+#endif
51650+}
51651diff -urNp linux-2.6.32.41/grsecurity/grsec_sysctl.c linux-2.6.32.41/grsecurity/grsec_sysctl.c
51652--- linux-2.6.32.41/grsecurity/grsec_sysctl.c 1969-12-31 19:00:00.000000000 -0500
51653+++ linux-2.6.32.41/grsecurity/grsec_sysctl.c 2011-04-17 15:56:46.000000000 -0400
51654@@ -0,0 +1,479 @@
51655+#include <linux/kernel.h>
51656+#include <linux/sched.h>
51657+#include <linux/sysctl.h>
51658+#include <linux/grsecurity.h>
51659+#include <linux/grinternal.h>
51660+
51661+int
51662+gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
51663+{
51664+#ifdef CONFIG_GRKERNSEC_SYSCTL
51665+ if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
51666+ gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
51667+ return -EACCES;
51668+ }
51669+#endif
51670+ return 0;
51671+}
51672+
51673+#ifdef CONFIG_GRKERNSEC_ROFS
51674+static int __maybe_unused one = 1;
51675+#endif
51676+
51677+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
51678+ctl_table grsecurity_table[] = {
51679+#ifdef CONFIG_GRKERNSEC_SYSCTL
51680+#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
51681+#ifdef CONFIG_GRKERNSEC_IO
51682+ {
51683+ .ctl_name = CTL_UNNUMBERED,
51684+ .procname = "disable_priv_io",
51685+ .data = &grsec_disable_privio,
51686+ .maxlen = sizeof(int),
51687+ .mode = 0600,
51688+ .proc_handler = &proc_dointvec,
51689+ },
51690+#endif
51691+#endif
51692+#ifdef CONFIG_GRKERNSEC_LINK
51693+ {
51694+ .ctl_name = CTL_UNNUMBERED,
51695+ .procname = "linking_restrictions",
51696+ .data = &grsec_enable_link,
51697+ .maxlen = sizeof(int),
51698+ .mode = 0600,
51699+ .proc_handler = &proc_dointvec,
51700+ },
51701+#endif
51702+#ifdef CONFIG_GRKERNSEC_FIFO
51703+ {
51704+ .ctl_name = CTL_UNNUMBERED,
51705+ .procname = "fifo_restrictions",
51706+ .data = &grsec_enable_fifo,
51707+ .maxlen = sizeof(int),
51708+ .mode = 0600,
51709+ .proc_handler = &proc_dointvec,
51710+ },
51711+#endif
51712+#ifdef CONFIG_GRKERNSEC_EXECVE
51713+ {
51714+ .ctl_name = CTL_UNNUMBERED,
51715+ .procname = "execve_limiting",
51716+ .data = &grsec_enable_execve,
51717+ .maxlen = sizeof(int),
51718+ .mode = 0600,
51719+ .proc_handler = &proc_dointvec,
51720+ },
51721+#endif
51722+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
51723+ {
51724+ .ctl_name = CTL_UNNUMBERED,
51725+ .procname = "ip_blackhole",
51726+ .data = &grsec_enable_blackhole,
51727+ .maxlen = sizeof(int),
51728+ .mode = 0600,
51729+ .proc_handler = &proc_dointvec,
51730+ },
51731+ {
51732+ .ctl_name = CTL_UNNUMBERED,
51733+ .procname = "lastack_retries",
51734+ .data = &grsec_lastack_retries,
51735+ .maxlen = sizeof(int),
51736+ .mode = 0600,
51737+ .proc_handler = &proc_dointvec,
51738+ },
51739+#endif
51740+#ifdef CONFIG_GRKERNSEC_EXECLOG
51741+ {
51742+ .ctl_name = CTL_UNNUMBERED,
51743+ .procname = "exec_logging",
51744+ .data = &grsec_enable_execlog,
51745+ .maxlen = sizeof(int),
51746+ .mode = 0600,
51747+ .proc_handler = &proc_dointvec,
51748+ },
51749+#endif
51750+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
51751+ {
51752+ .ctl_name = CTL_UNNUMBERED,
51753+ .procname = "rwxmap_logging",
51754+ .data = &grsec_enable_log_rwxmaps,
51755+ .maxlen = sizeof(int),
51756+ .mode = 0600,
51757+ .proc_handler = &proc_dointvec,
51758+ },
51759+#endif
51760+#ifdef CONFIG_GRKERNSEC_SIGNAL
51761+ {
51762+ .ctl_name = CTL_UNNUMBERED,
51763+ .procname = "signal_logging",
51764+ .data = &grsec_enable_signal,
51765+ .maxlen = sizeof(int),
51766+ .mode = 0600,
51767+ .proc_handler = &proc_dointvec,
51768+ },
51769+#endif
51770+#ifdef CONFIG_GRKERNSEC_FORKFAIL
51771+ {
51772+ .ctl_name = CTL_UNNUMBERED,
51773+ .procname = "forkfail_logging",
51774+ .data = &grsec_enable_forkfail,
51775+ .maxlen = sizeof(int),
51776+ .mode = 0600,
51777+ .proc_handler = &proc_dointvec,
51778+ },
51779+#endif
51780+#ifdef CONFIG_GRKERNSEC_TIME
51781+ {
51782+ .ctl_name = CTL_UNNUMBERED,
51783+ .procname = "timechange_logging",
51784+ .data = &grsec_enable_time,
51785+ .maxlen = sizeof(int),
51786+ .mode = 0600,
51787+ .proc_handler = &proc_dointvec,
51788+ },
51789+#endif
51790+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
51791+ {
51792+ .ctl_name = CTL_UNNUMBERED,
51793+ .procname = "chroot_deny_shmat",
51794+ .data = &grsec_enable_chroot_shmat,
51795+ .maxlen = sizeof(int),
51796+ .mode = 0600,
51797+ .proc_handler = &proc_dointvec,
51798+ },
51799+#endif
51800+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
51801+ {
51802+ .ctl_name = CTL_UNNUMBERED,
51803+ .procname = "chroot_deny_unix",
51804+ .data = &grsec_enable_chroot_unix,
51805+ .maxlen = sizeof(int),
51806+ .mode = 0600,
51807+ .proc_handler = &proc_dointvec,
51808+ },
51809+#endif
51810+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
51811+ {
51812+ .ctl_name = CTL_UNNUMBERED,
51813+ .procname = "chroot_deny_mount",
51814+ .data = &grsec_enable_chroot_mount,
51815+ .maxlen = sizeof(int),
51816+ .mode = 0600,
51817+ .proc_handler = &proc_dointvec,
51818+ },
51819+#endif
51820+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
51821+ {
51822+ .ctl_name = CTL_UNNUMBERED,
51823+ .procname = "chroot_deny_fchdir",
51824+ .data = &grsec_enable_chroot_fchdir,
51825+ .maxlen = sizeof(int),
51826+ .mode = 0600,
51827+ .proc_handler = &proc_dointvec,
51828+ },
51829+#endif
51830+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
51831+ {
51832+ .ctl_name = CTL_UNNUMBERED,
51833+ .procname = "chroot_deny_chroot",
51834+ .data = &grsec_enable_chroot_double,
51835+ .maxlen = sizeof(int),
51836+ .mode = 0600,
51837+ .proc_handler = &proc_dointvec,
51838+ },
51839+#endif
51840+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
51841+ {
51842+ .ctl_name = CTL_UNNUMBERED,
51843+ .procname = "chroot_deny_pivot",
51844+ .data = &grsec_enable_chroot_pivot,
51845+ .maxlen = sizeof(int),
51846+ .mode = 0600,
51847+ .proc_handler = &proc_dointvec,
51848+ },
51849+#endif
51850+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
51851+ {
51852+ .ctl_name = CTL_UNNUMBERED,
51853+ .procname = "chroot_enforce_chdir",
51854+ .data = &grsec_enable_chroot_chdir,
51855+ .maxlen = sizeof(int),
51856+ .mode = 0600,
51857+ .proc_handler = &proc_dointvec,
51858+ },
51859+#endif
51860+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
51861+ {
51862+ .ctl_name = CTL_UNNUMBERED,
51863+ .procname = "chroot_deny_chmod",
51864+ .data = &grsec_enable_chroot_chmod,
51865+ .maxlen = sizeof(int),
51866+ .mode = 0600,
51867+ .proc_handler = &proc_dointvec,
51868+ },
51869+#endif
51870+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
51871+ {
51872+ .ctl_name = CTL_UNNUMBERED,
51873+ .procname = "chroot_deny_mknod",
51874+ .data = &grsec_enable_chroot_mknod,
51875+ .maxlen = sizeof(int),
51876+ .mode = 0600,
51877+ .proc_handler = &proc_dointvec,
51878+ },
51879+#endif
51880+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
51881+ {
51882+ .ctl_name = CTL_UNNUMBERED,
51883+ .procname = "chroot_restrict_nice",
51884+ .data = &grsec_enable_chroot_nice,
51885+ .maxlen = sizeof(int),
51886+ .mode = 0600,
51887+ .proc_handler = &proc_dointvec,
51888+ },
51889+#endif
51890+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
51891+ {
51892+ .ctl_name = CTL_UNNUMBERED,
51893+ .procname = "chroot_execlog",
51894+ .data = &grsec_enable_chroot_execlog,
51895+ .maxlen = sizeof(int),
51896+ .mode = 0600,
51897+ .proc_handler = &proc_dointvec,
51898+ },
51899+#endif
51900+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
51901+ {
51902+ .ctl_name = CTL_UNNUMBERED,
51903+ .procname = "chroot_caps",
51904+ .data = &grsec_enable_chroot_caps,
51905+ .maxlen = sizeof(int),
51906+ .mode = 0600,
51907+ .proc_handler = &proc_dointvec,
51908+ },
51909+#endif
51910+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
51911+ {
51912+ .ctl_name = CTL_UNNUMBERED,
51913+ .procname = "chroot_deny_sysctl",
51914+ .data = &grsec_enable_chroot_sysctl,
51915+ .maxlen = sizeof(int),
51916+ .mode = 0600,
51917+ .proc_handler = &proc_dointvec,
51918+ },
51919+#endif
51920+#ifdef CONFIG_GRKERNSEC_TPE
51921+ {
51922+ .ctl_name = CTL_UNNUMBERED,
51923+ .procname = "tpe",
51924+ .data = &grsec_enable_tpe,
51925+ .maxlen = sizeof(int),
51926+ .mode = 0600,
51927+ .proc_handler = &proc_dointvec,
51928+ },
51929+ {
51930+ .ctl_name = CTL_UNNUMBERED,
51931+ .procname = "tpe_gid",
51932+ .data = &grsec_tpe_gid,
51933+ .maxlen = sizeof(int),
51934+ .mode = 0600,
51935+ .proc_handler = &proc_dointvec,
51936+ },
51937+#endif
51938+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
51939+ {
51940+ .ctl_name = CTL_UNNUMBERED,
51941+ .procname = "tpe_invert",
51942+ .data = &grsec_enable_tpe_invert,
51943+ .maxlen = sizeof(int),
51944+ .mode = 0600,
51945+ .proc_handler = &proc_dointvec,
51946+ },
51947+#endif
51948+#ifdef CONFIG_GRKERNSEC_TPE_ALL
51949+ {
51950+ .ctl_name = CTL_UNNUMBERED,
51951+ .procname = "tpe_restrict_all",
51952+ .data = &grsec_enable_tpe_all,
51953+ .maxlen = sizeof(int),
51954+ .mode = 0600,
51955+ .proc_handler = &proc_dointvec,
51956+ },
51957+#endif
51958+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
51959+ {
51960+ .ctl_name = CTL_UNNUMBERED,
51961+ .procname = "socket_all",
51962+ .data = &grsec_enable_socket_all,
51963+ .maxlen = sizeof(int),
51964+ .mode = 0600,
51965+ .proc_handler = &proc_dointvec,
51966+ },
51967+ {
51968+ .ctl_name = CTL_UNNUMBERED,
51969+ .procname = "socket_all_gid",
51970+ .data = &grsec_socket_all_gid,
51971+ .maxlen = sizeof(int),
51972+ .mode = 0600,
51973+ .proc_handler = &proc_dointvec,
51974+ },
51975+#endif
51976+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
51977+ {
51978+ .ctl_name = CTL_UNNUMBERED,
51979+ .procname = "socket_client",
51980+ .data = &grsec_enable_socket_client,
51981+ .maxlen = sizeof(int),
51982+ .mode = 0600,
51983+ .proc_handler = &proc_dointvec,
51984+ },
51985+ {
51986+ .ctl_name = CTL_UNNUMBERED,
51987+ .procname = "socket_client_gid",
51988+ .data = &grsec_socket_client_gid,
51989+ .maxlen = sizeof(int),
51990+ .mode = 0600,
51991+ .proc_handler = &proc_dointvec,
51992+ },
51993+#endif
51994+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
51995+ {
51996+ .ctl_name = CTL_UNNUMBERED,
51997+ .procname = "socket_server",
51998+ .data = &grsec_enable_socket_server,
51999+ .maxlen = sizeof(int),
52000+ .mode = 0600,
52001+ .proc_handler = &proc_dointvec,
52002+ },
52003+ {
52004+ .ctl_name = CTL_UNNUMBERED,
52005+ .procname = "socket_server_gid",
52006+ .data = &grsec_socket_server_gid,
52007+ .maxlen = sizeof(int),
52008+ .mode = 0600,
52009+ .proc_handler = &proc_dointvec,
52010+ },
52011+#endif
52012+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
52013+ {
52014+ .ctl_name = CTL_UNNUMBERED,
52015+ .procname = "audit_group",
52016+ .data = &grsec_enable_group,
52017+ .maxlen = sizeof(int),
52018+ .mode = 0600,
52019+ .proc_handler = &proc_dointvec,
52020+ },
52021+ {
52022+ .ctl_name = CTL_UNNUMBERED,
52023+ .procname = "audit_gid",
52024+ .data = &grsec_audit_gid,
52025+ .maxlen = sizeof(int),
52026+ .mode = 0600,
52027+ .proc_handler = &proc_dointvec,
52028+ },
52029+#endif
52030+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
52031+ {
52032+ .ctl_name = CTL_UNNUMBERED,
52033+ .procname = "audit_chdir",
52034+ .data = &grsec_enable_chdir,
52035+ .maxlen = sizeof(int),
52036+ .mode = 0600,
52037+ .proc_handler = &proc_dointvec,
52038+ },
52039+#endif
52040+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
52041+ {
52042+ .ctl_name = CTL_UNNUMBERED,
52043+ .procname = "audit_mount",
52044+ .data = &grsec_enable_mount,
52045+ .maxlen = sizeof(int),
52046+ .mode = 0600,
52047+ .proc_handler = &proc_dointvec,
52048+ },
52049+#endif
52050+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
52051+ {
52052+ .ctl_name = CTL_UNNUMBERED,
52053+ .procname = "audit_textrel",
52054+ .data = &grsec_enable_audit_textrel,
52055+ .maxlen = sizeof(int),
52056+ .mode = 0600,
52057+ .proc_handler = &proc_dointvec,
52058+ },
52059+#endif
52060+#ifdef CONFIG_GRKERNSEC_DMESG
52061+ {
52062+ .ctl_name = CTL_UNNUMBERED,
52063+ .procname = "dmesg",
52064+ .data = &grsec_enable_dmesg,
52065+ .maxlen = sizeof(int),
52066+ .mode = 0600,
52067+ .proc_handler = &proc_dointvec,
52068+ },
52069+#endif
52070+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
52071+ {
52072+ .ctl_name = CTL_UNNUMBERED,
52073+ .procname = "chroot_findtask",
52074+ .data = &grsec_enable_chroot_findtask,
52075+ .maxlen = sizeof(int),
52076+ .mode = 0600,
52077+ .proc_handler = &proc_dointvec,
52078+ },
52079+#endif
52080+#ifdef CONFIG_GRKERNSEC_RESLOG
52081+ {
52082+ .ctl_name = CTL_UNNUMBERED,
52083+ .procname = "resource_logging",
52084+ .data = &grsec_resource_logging,
52085+ .maxlen = sizeof(int),
52086+ .mode = 0600,
52087+ .proc_handler = &proc_dointvec,
52088+ },
52089+#endif
52090+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
52091+ {
52092+ .ctl_name = CTL_UNNUMBERED,
52093+ .procname = "audit_ptrace",
52094+ .data = &grsec_enable_audit_ptrace,
52095+ .maxlen = sizeof(int),
52096+ .mode = 0600,
52097+ .proc_handler = &proc_dointvec,
52098+ },
52099+#endif
52100+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
52101+ {
52102+ .ctl_name = CTL_UNNUMBERED,
52103+ .procname = "harden_ptrace",
52104+ .data = &grsec_enable_harden_ptrace,
52105+ .maxlen = sizeof(int),
52106+ .mode = 0600,
52107+ .proc_handler = &proc_dointvec,
52108+ },
52109+#endif
52110+ {
52111+ .ctl_name = CTL_UNNUMBERED,
52112+ .procname = "grsec_lock",
52113+ .data = &grsec_lock,
52114+ .maxlen = sizeof(int),
52115+ .mode = 0600,
52116+ .proc_handler = &proc_dointvec,
52117+ },
52118+#endif
52119+#ifdef CONFIG_GRKERNSEC_ROFS
52120+ {
52121+ .ctl_name = CTL_UNNUMBERED,
52122+ .procname = "romount_protect",
52123+ .data = &grsec_enable_rofs,
52124+ .maxlen = sizeof(int),
52125+ .mode = 0600,
52126+ .proc_handler = &proc_dointvec_minmax,
52127+ .extra1 = &one,
52128+ .extra2 = &one,
52129+ },
52130+#endif
52131+ { .ctl_name = 0 }
52132+};
52133+#endif
52134diff -urNp linux-2.6.32.41/grsecurity/grsec_time.c linux-2.6.32.41/grsecurity/grsec_time.c
52135--- linux-2.6.32.41/grsecurity/grsec_time.c 1969-12-31 19:00:00.000000000 -0500
52136+++ linux-2.6.32.41/grsecurity/grsec_time.c 2011-04-17 15:56:46.000000000 -0400
52137@@ -0,0 +1,16 @@
52138+#include <linux/kernel.h>
52139+#include <linux/sched.h>
52140+#include <linux/grinternal.h>
52141+#include <linux/module.h>
52142+
52143+void
52144+gr_log_timechange(void)
52145+{
52146+#ifdef CONFIG_GRKERNSEC_TIME
52147+ if (grsec_enable_time)
52148+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
52149+#endif
52150+ return;
52151+}
52152+
52153+EXPORT_SYMBOL(gr_log_timechange);
52154diff -urNp linux-2.6.32.41/grsecurity/grsec_tpe.c linux-2.6.32.41/grsecurity/grsec_tpe.c
52155--- linux-2.6.32.41/grsecurity/grsec_tpe.c 1969-12-31 19:00:00.000000000 -0500
52156+++ linux-2.6.32.41/grsecurity/grsec_tpe.c 2011-04-17 15:56:46.000000000 -0400
52157@@ -0,0 +1,39 @@
52158+#include <linux/kernel.h>
52159+#include <linux/sched.h>
52160+#include <linux/file.h>
52161+#include <linux/fs.h>
52162+#include <linux/grinternal.h>
52163+
52164+extern int gr_acl_tpe_check(void);
52165+
52166+int
52167+gr_tpe_allow(const struct file *file)
52168+{
52169+#ifdef CONFIG_GRKERNSEC
52170+ struct inode *inode = file->f_path.dentry->d_parent->d_inode;
52171+ const struct cred *cred = current_cred();
52172+
52173+ if (cred->uid && ((grsec_enable_tpe &&
52174+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
52175+ ((grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid)) ||
52176+ (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid)))
52177+#else
52178+ in_group_p(grsec_tpe_gid)
52179+#endif
52180+ ) || gr_acl_tpe_check()) &&
52181+ (inode->i_uid || (!inode->i_uid && ((inode->i_mode & S_IWGRP) ||
52182+ (inode->i_mode & S_IWOTH))))) {
52183+ gr_log_fs_generic(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, file->f_path.dentry, file->f_path.mnt);
52184+ return 0;
52185+ }
52186+#ifdef CONFIG_GRKERNSEC_TPE_ALL
52187+ if (cred->uid && grsec_enable_tpe && grsec_enable_tpe_all &&
52188+ ((inode->i_uid && (inode->i_uid != cred->uid)) ||
52189+ (inode->i_mode & S_IWGRP) || (inode->i_mode & S_IWOTH))) {
52190+ gr_log_fs_generic(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, file->f_path.dentry, file->f_path.mnt);
52191+ return 0;
52192+ }
52193+#endif
52194+#endif
52195+ return 1;
52196+}
52197diff -urNp linux-2.6.32.41/grsecurity/grsum.c linux-2.6.32.41/grsecurity/grsum.c
52198--- linux-2.6.32.41/grsecurity/grsum.c 1969-12-31 19:00:00.000000000 -0500
52199+++ linux-2.6.32.41/grsecurity/grsum.c 2011-04-17 15:56:46.000000000 -0400
52200@@ -0,0 +1,61 @@
52201+#include <linux/err.h>
52202+#include <linux/kernel.h>
52203+#include <linux/sched.h>
52204+#include <linux/mm.h>
52205+#include <linux/scatterlist.h>
52206+#include <linux/crypto.h>
52207+#include <linux/gracl.h>
52208+
52209+
52210+#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
52211+#error "crypto and sha256 must be built into the kernel"
52212+#endif
52213+
52214+int
52215+chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
52216+{
52217+ char *p;
52218+ struct crypto_hash *tfm;
52219+ struct hash_desc desc;
52220+ struct scatterlist sg;
52221+ unsigned char temp_sum[GR_SHA_LEN];
52222+ volatile int retval = 0;
52223+ volatile int dummy = 0;
52224+ unsigned int i;
52225+
52226+ sg_init_table(&sg, 1);
52227+
52228+ tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
52229+ if (IS_ERR(tfm)) {
52230+ /* should never happen, since sha256 should be built in */
52231+ return 1;
52232+ }
52233+
52234+ desc.tfm = tfm;
52235+ desc.flags = 0;
52236+
52237+ crypto_hash_init(&desc);
52238+
52239+ p = salt;
52240+ sg_set_buf(&sg, p, GR_SALT_LEN);
52241+ crypto_hash_update(&desc, &sg, sg.length);
52242+
52243+ p = entry->pw;
52244+ sg_set_buf(&sg, p, strlen(p));
52245+
52246+ crypto_hash_update(&desc, &sg, sg.length);
52247+
52248+ crypto_hash_final(&desc, temp_sum);
52249+
52250+ memset(entry->pw, 0, GR_PW_LEN);
52251+
52252+ for (i = 0; i < GR_SHA_LEN; i++)
52253+ if (sum[i] != temp_sum[i])
52254+ retval = 1;
52255+ else
52256+ dummy = 1; // waste a cycle
52257+
52258+ crypto_free_hash(tfm);
52259+
52260+ return retval;
52261+}
52262diff -urNp linux-2.6.32.41/grsecurity/Kconfig linux-2.6.32.41/grsecurity/Kconfig
52263--- linux-2.6.32.41/grsecurity/Kconfig 1969-12-31 19:00:00.000000000 -0500
52264+++ linux-2.6.32.41/grsecurity/Kconfig 2011-04-17 15:56:46.000000000 -0400
52265@@ -0,0 +1,1045 @@
52266+#
52267+# grecurity configuration
52268+#
52269+
52270+menu "Grsecurity"
52271+
52272+config GRKERNSEC
52273+ bool "Grsecurity"
52274+ select CRYPTO
52275+ select CRYPTO_SHA256
52276+ help
52277+ If you say Y here, you will be able to configure many features
52278+ that will enhance the security of your system. It is highly
52279+ recommended that you say Y here and read through the help
52280+ for each option so that you fully understand the features and
52281+ can evaluate their usefulness for your machine.
52282+
52283+choice
52284+ prompt "Security Level"
52285+ depends on GRKERNSEC
52286+ default GRKERNSEC_CUSTOM
52287+
52288+config GRKERNSEC_LOW
52289+ bool "Low"
52290+ select GRKERNSEC_LINK
52291+ select GRKERNSEC_FIFO
52292+ select GRKERNSEC_EXECVE
52293+ select GRKERNSEC_RANDNET
52294+ select GRKERNSEC_DMESG
52295+ select GRKERNSEC_CHROOT
52296+ select GRKERNSEC_CHROOT_CHDIR
52297+
52298+ help
52299+ If you choose this option, several of the grsecurity options will
52300+ be enabled that will give you greater protection against a number
52301+ of attacks, while assuring that none of your software will have any
52302+ conflicts with the additional security measures. If you run a lot
52303+ of unusual software, or you are having problems with the higher
52304+ security levels, you should say Y here. With this option, the
52305+ following features are enabled:
52306+
52307+ - Linking restrictions
52308+ - FIFO restrictions
52309+ - Enforcing RLIMIT_NPROC on execve
52310+ - Restricted dmesg
52311+ - Enforced chdir("/") on chroot
52312+ - Runtime module disabling
52313+
52314+config GRKERNSEC_MEDIUM
52315+ bool "Medium"
52316+ select PAX
52317+ select PAX_EI_PAX
52318+ select PAX_PT_PAX_FLAGS
52319+ select PAX_HAVE_ACL_FLAGS
52320+ select GRKERNSEC_PROC_MEMMAP if (PAX_NOEXEC || PAX_ASLR)
52321+ select GRKERNSEC_CHROOT
52322+ select GRKERNSEC_CHROOT_SYSCTL
52323+ select GRKERNSEC_LINK
52324+ select GRKERNSEC_FIFO
52325+ select GRKERNSEC_EXECVE
52326+ select GRKERNSEC_DMESG
52327+ select GRKERNSEC_RANDNET
52328+ select GRKERNSEC_FORKFAIL
52329+ select GRKERNSEC_TIME
52330+ select GRKERNSEC_SIGNAL
52331+ select GRKERNSEC_CHROOT
52332+ select GRKERNSEC_CHROOT_UNIX
52333+ select GRKERNSEC_CHROOT_MOUNT
52334+ select GRKERNSEC_CHROOT_PIVOT
52335+ select GRKERNSEC_CHROOT_DOUBLE
52336+ select GRKERNSEC_CHROOT_CHDIR
52337+ select GRKERNSEC_CHROOT_MKNOD
52338+ select GRKERNSEC_PROC
52339+ select GRKERNSEC_PROC_USERGROUP
52340+ select PAX_RANDUSTACK
52341+ select PAX_ASLR
52342+ select PAX_RANDMMAP
52343+ select PAX_REFCOUNT if (X86 || SPARC64)
52344+ select PAX_USERCOPY if ((X86 || SPARC32 || SPARC64 || PPC) && (SLAB || SLUB || SLOB))
52345+
52346+ help
52347+ If you say Y here, several features in addition to those included
52348+ in the low additional security level will be enabled. These
52349+ features provide even more security to your system, though in rare
52350+ cases they may be incompatible with very old or poorly written
52351+ software. If you enable this option, make sure that your auth
52352+ service (identd) is running as gid 1001. With this option,
52353+ the following features (in addition to those provided in the
52354+ low additional security level) will be enabled:
52355+
52356+ - Failed fork logging
52357+ - Time change logging
52358+ - Signal logging
52359+ - Deny mounts in chroot
52360+ - Deny double chrooting
52361+ - Deny sysctl writes in chroot
52362+ - Deny mknod in chroot
52363+ - Deny access to abstract AF_UNIX sockets out of chroot
52364+ - Deny pivot_root in chroot
52365+ - Denied writes of /dev/kmem, /dev/mem, and /dev/port
52366+ - /proc restrictions with special GID set to 10 (usually wheel)
52367+ - Address Space Layout Randomization (ASLR)
52368+ - Prevent exploitation of most refcount overflows
52369+ - Bounds checking of copying between the kernel and userland
52370+
52371+config GRKERNSEC_HIGH
52372+ bool "High"
52373+ select GRKERNSEC_LINK
52374+ select GRKERNSEC_FIFO
52375+ select GRKERNSEC_EXECVE
52376+ select GRKERNSEC_DMESG
52377+ select GRKERNSEC_FORKFAIL
52378+ select GRKERNSEC_TIME
52379+ select GRKERNSEC_SIGNAL
52380+ select GRKERNSEC_CHROOT
52381+ select GRKERNSEC_CHROOT_SHMAT
52382+ select GRKERNSEC_CHROOT_UNIX
52383+ select GRKERNSEC_CHROOT_MOUNT
52384+ select GRKERNSEC_CHROOT_FCHDIR
52385+ select GRKERNSEC_CHROOT_PIVOT
52386+ select GRKERNSEC_CHROOT_DOUBLE
52387+ select GRKERNSEC_CHROOT_CHDIR
52388+ select GRKERNSEC_CHROOT_MKNOD
52389+ select GRKERNSEC_CHROOT_CAPS
52390+ select GRKERNSEC_CHROOT_SYSCTL
52391+ select GRKERNSEC_CHROOT_FINDTASK
52392+ select GRKERNSEC_SYSFS_RESTRICT
52393+ select GRKERNSEC_PROC
52394+ select GRKERNSEC_PROC_MEMMAP if (PAX_NOEXEC || PAX_ASLR)
52395+ select GRKERNSEC_HIDESYM
52396+ select GRKERNSEC_BRUTE
52397+ select GRKERNSEC_PROC_USERGROUP
52398+ select GRKERNSEC_KMEM
52399+ select GRKERNSEC_RESLOG
52400+ select GRKERNSEC_RANDNET
52401+ select GRKERNSEC_PROC_ADD
52402+ select GRKERNSEC_CHROOT_CHMOD
52403+ select GRKERNSEC_CHROOT_NICE
52404+ select GRKERNSEC_AUDIT_MOUNT
52405+ select GRKERNSEC_MODHARDEN if (MODULES)
52406+ select GRKERNSEC_HARDEN_PTRACE
52407+ select GRKERNSEC_VM86 if (X86_32)
52408+ select GRKERNSEC_KERN_LOCKOUT if (X86)
52409+ select PAX
52410+ select PAX_RANDUSTACK
52411+ select PAX_ASLR
52412+ select PAX_RANDMMAP
52413+ select PAX_NOEXEC
52414+ select PAX_MPROTECT
52415+ select PAX_EI_PAX
52416+ select PAX_PT_PAX_FLAGS
52417+ select PAX_HAVE_ACL_FLAGS
52418+ select PAX_KERNEXEC if ((PPC || X86) && (!X86_32 || X86_WP_WORKS_OK) && !XEN)
52419+ select PAX_MEMORY_UDEREF if (X86 && !XEN)
52420+ select PAX_RANDKSTACK if (X86_TSC && X86)
52421+ select PAX_SEGMEXEC if (X86_32)
52422+ select PAX_PAGEEXEC
52423+ select PAX_EMUPLT if (ALPHA || PARISC || SPARC32 || SPARC64)
52424+ select PAX_EMUTRAMP if (PARISC)
52425+ select PAX_EMUSIGRT if (PARISC)
52426+ select PAX_ETEXECRELOCS if (ALPHA || IA64 || PARISC)
52427+ select PAX_ELFRELOCS if (PAX_ETEXECRELOCS || (IA64 || PPC || X86))
52428+ select PAX_REFCOUNT if (X86 || SPARC64)
52429+ select PAX_USERCOPY if ((X86 || PPC || SPARC32 || SPARC64) && (SLAB || SLUB || SLOB))
52430+ help
52431+ If you say Y here, many of the features of grsecurity will be
52432+ enabled, which will protect you against many kinds of attacks
52433+ against your system. The heightened security comes at a cost
52434+ of an increased chance of incompatibilities with rare software
52435+ on your machine. Since this security level enables PaX, you should
52436+ view <http://pax.grsecurity.net> and read about the PaX
52437+ project. While you are there, download chpax and run it on
52438+ binaries that cause problems with PaX. Also remember that
52439+ since the /proc restrictions are enabled, you must run your
52440+ identd as gid 1001. This security level enables the following
52441+ features in addition to those listed in the low and medium
52442+ security levels:
52443+
52444+ - Additional /proc restrictions
52445+ - Chmod restrictions in chroot
52446+ - No signals, ptrace, or viewing of processes outside of chroot
52447+ - Capability restrictions in chroot
52448+ - Deny fchdir out of chroot
52449+ - Priority restrictions in chroot
52450+ - Segmentation-based implementation of PaX
52451+ - Mprotect restrictions
52452+ - Removal of addresses from /proc/<pid>/[smaps|maps|stat]
52453+ - Kernel stack randomization
52454+ - Mount/unmount/remount logging
52455+ - Kernel symbol hiding
52456+ - Prevention of memory exhaustion-based exploits
52457+ - Hardening of module auto-loading
52458+ - Ptrace restrictions
52459+ - Restricted vm86 mode
52460+ - Restricted sysfs/debugfs
52461+ - Active kernel exploit response
52462+
52463+config GRKERNSEC_CUSTOM
52464+ bool "Custom"
52465+ help
52466+ If you say Y here, you will be able to configure every grsecurity
52467+ option, which allows you to enable many more features that aren't
52468+ covered in the basic security levels. These additional features
52469+ include TPE, socket restrictions, and the sysctl system for
52470+ grsecurity. It is advised that you read through the help for
52471+ each option to determine its usefulness in your situation.
52472+
52473+endchoice
52474+
52475+menu "Address Space Protection"
52476+depends on GRKERNSEC
52477+
52478+config GRKERNSEC_KMEM
52479+ bool "Deny writing to /dev/kmem, /dev/mem, and /dev/port"
52480+ select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
52481+ help
52482+ If you say Y here, /dev/kmem and /dev/mem won't be allowed to
52483+ be written to via mmap or otherwise to modify the running kernel.
52484+ /dev/port will also not be allowed to be opened. If you have module
52485+ support disabled, enabling this will close up four ways that are
52486+ currently used to insert malicious code into the running kernel.
52487+ Even with all these features enabled, we still highly recommend that
52488+ you use the RBAC system, as it is still possible for an attacker to
52489+ modify the running kernel through privileged I/O granted by ioperm/iopl.
52490+ If you are not using XFree86, you may be able to stop this additional
52491+ case by enabling the 'Disable privileged I/O' option. Though nothing
52492+ legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
52493+ but only to video memory, which is the only writing we allow in this
52494+ case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
52495+ not be allowed to mprotect it with PROT_WRITE later.
52496+ It is highly recommended that you say Y here if you meet all the
52497+ conditions above.
52498+
52499+config GRKERNSEC_VM86
52500+ bool "Restrict VM86 mode"
52501+ depends on X86_32
52502+
52503+ help
52504+ If you say Y here, only processes with CAP_SYS_RAWIO will be able to
52505+ make use of a special execution mode on 32bit x86 processors called
52506+ Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
52507+ video cards and will still work with this option enabled. The purpose
52508+ of the option is to prevent exploitation of emulation errors in
52509+ virtualization of vm86 mode like the one discovered in VMWare in 2009.
52510+ Nearly all users should be able to enable this option.
52511+
52512+config GRKERNSEC_IO
52513+ bool "Disable privileged I/O"
52514+ depends on X86
52515+ select RTC_CLASS
52516+ select RTC_INTF_DEV
52517+ select RTC_DRV_CMOS
52518+
52519+ help
52520+ If you say Y here, all ioperm and iopl calls will return an error.
52521+ Ioperm and iopl can be used to modify the running kernel.
52522+ Unfortunately, some programs need this access to operate properly,
52523+ the most notable of which are XFree86 and hwclock. hwclock can be
52524+ remedied by having RTC support in the kernel, so real-time
52525+ clock support is enabled if this option is enabled, to ensure
52526+ that hwclock operates correctly. XFree86 still will not
52527+ operate correctly with this option enabled, so DO NOT CHOOSE Y
52528+ IF YOU USE XFree86. If you use XFree86 and you still want to
52529+ protect your kernel against modification, use the RBAC system.
52530+
52531+config GRKERNSEC_PROC_MEMMAP
52532+ bool "Remove addresses from /proc/<pid>/[smaps|maps|stat]"
52533+ default y if (PAX_NOEXEC || PAX_ASLR)
52534+ depends on PAX_NOEXEC || PAX_ASLR
52535+ help
52536+ If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
52537+ give no information about the addresses of its mappings if
52538+ PaX features that rely on random addresses are enabled on the task.
52539+ If you use PaX it is greatly recommended that you say Y here as it
52540+ closes up a hole that makes the full ASLR useless for suid
52541+ binaries.
52542+
52543+config GRKERNSEC_BRUTE
52544+ bool "Deter exploit bruteforcing"
52545+ help
52546+ If you say Y here, attempts to bruteforce exploits against forking
52547+ daemons such as apache or sshd, as well as against suid/sgid binaries
52548+ will be deterred. When a child of a forking daemon is killed by PaX
52549+ or crashes due to an illegal instruction or other suspicious signal,
52550+ the parent process will be delayed 30 seconds upon every subsequent
52551+ fork until the administrator is able to assess the situation and
52552+ restart the daemon.
52553+ In the suid/sgid case, the attempt is logged, the user has all their
52554+ processes terminated, and they are prevented from executing any further
52555+ processes for 15 minutes.
52556+ It is recommended that you also enable signal logging in the auditing
52557+ section so that logs are generated when a process triggers a suspicious
52558+ signal.
52559+
52560+config GRKERNSEC_MODHARDEN
52561+ bool "Harden module auto-loading"
52562+ depends on MODULES
52563+ help
52564+ If you say Y here, module auto-loading in response to use of some
52565+ feature implemented by an unloaded module will be restricted to
52566+ root users. Enabling this option helps defend against attacks
52567+ by unprivileged users who abuse the auto-loading behavior to
52568+ cause a vulnerable module to load that is then exploited.
52569+
52570+ If this option prevents a legitimate use of auto-loading for a
52571+ non-root user, the administrator can execute modprobe manually
52572+ with the exact name of the module mentioned in the alert log.
52573+ Alternatively, the administrator can add the module to the list
52574+ of modules loaded at boot by modifying init scripts.
52575+
52576+ Modification of init scripts will most likely be needed on
52577+ Ubuntu servers with encrypted home directory support enabled,
52578+ as the first non-root user logging in will cause the ecb(aes),
52579+ ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
52580+
52581+config GRKERNSEC_HIDESYM
52582+ bool "Hide kernel symbols"
52583+ help
52584+ If you say Y here, getting information on loaded modules, and
52585+ displaying all kernel symbols through a syscall will be restricted
52586+ to users with CAP_SYS_MODULE. For software compatibility reasons,
52587+ /proc/kallsyms will be restricted to the root user. The RBAC
52588+ system can hide that entry even from root.
52589+
52590+ This option also prevents leaking of kernel addresses through
52591+ several /proc entries.
52592+
52593+ Note that this option is only effective provided the following
52594+ conditions are met:
52595+ 1) The kernel using grsecurity is not precompiled by some distribution
52596+ 2) You have also enabled GRKERNSEC_DMESG
52597+ 3) You are using the RBAC system and hiding other files such as your
52598+ kernel image and System.map. Alternatively, enabling this option
52599+ causes the permissions on /boot, /lib/modules, and the kernel
52600+ source directory to change at compile time to prevent
52601+ reading by non-root users.
52602+ If the above conditions are met, this option will aid in providing a
52603+ useful protection against local kernel exploitation of overflows
52604+ and arbitrary read/write vulnerabilities.
52605+
52606+config GRKERNSEC_KERN_LOCKOUT
52607+ bool "Active kernel exploit response"
52608+ depends on X86
52609+ help
52610+ If you say Y here, when a PaX alert is triggered due to suspicious
52611+ activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
52612+ or an OOPs occurs due to bad memory accesses, instead of just
52613+ terminating the offending process (and potentially allowing
52614+ a subsequent exploit from the same user), we will take one of two
52615+ actions:
52616+ If the user was root, we will panic the system
52617+ If the user was non-root, we will log the attempt, terminate
52618+ all processes owned by the user, then prevent them from creating
52619+ any new processes until the system is restarted
52620+ This deters repeated kernel exploitation/bruteforcing attempts
52621+ and is useful for later forensics.
52622+
52623+endmenu
52624+menu "Role Based Access Control Options"
52625+depends on GRKERNSEC
52626+
52627+config GRKERNSEC_RBAC_DEBUG
52628+ bool
52629+
52630+config GRKERNSEC_NO_RBAC
52631+ bool "Disable RBAC system"
52632+ help
52633+ If you say Y here, the /dev/grsec device will be removed from the kernel,
52634+ preventing the RBAC system from being enabled. You should only say Y
52635+ here if you have no intention of using the RBAC system, so as to prevent
52636+ an attacker with root access from misusing the RBAC system to hide files
52637+ and processes when loadable module support and /dev/[k]mem have been
52638+ locked down.
52639+
52640+config GRKERNSEC_ACL_HIDEKERN
52641+ bool "Hide kernel processes"
52642+ help
52643+ If you say Y here, all kernel threads will be hidden to all
52644+ processes but those whose subject has the "view hidden processes"
52645+ flag.
52646+
52647+config GRKERNSEC_ACL_MAXTRIES
52648+ int "Maximum tries before password lockout"
52649+ default 3
52650+ help
52651+ This option enforces the maximum number of times a user can attempt
52652+ to authorize themselves with the grsecurity RBAC system before being
52653+ denied the ability to attempt authorization again for a specified time.
52654+ The lower the number, the harder it will be to brute-force a password.
52655+
52656+config GRKERNSEC_ACL_TIMEOUT
52657+ int "Time to wait after max password tries, in seconds"
52658+ default 30
52659+ help
52660+ This option specifies the time the user must wait after attempting to
52661+ authorize to the RBAC system with the maximum number of invalid
52662+ passwords. The higher the number, the harder it will be to brute-force
52663+ a password.
52664+
52665+endmenu
52666+menu "Filesystem Protections"
52667+depends on GRKERNSEC
52668+
52669+config GRKERNSEC_PROC
52670+ bool "Proc restrictions"
52671+ help
52672+ If you say Y here, the permissions of the /proc filesystem
52673+ will be altered to enhance system security and privacy. You MUST
52674+ choose either a user only restriction or a user and group restriction.
52675+ Depending upon the option you choose, you can either restrict users to
52676+ see only the processes they themselves run, or choose a group that can
52677+ view all processes and files normally restricted to root if you choose
52678+ the "restrict to user only" option. NOTE: If you're running identd as
52679+ a non-root user, you will have to run it as the group you specify here.
52680+
52681+config GRKERNSEC_PROC_USER
52682+ bool "Restrict /proc to user only"
52683+ depends on GRKERNSEC_PROC
52684+ help
52685+ If you say Y here, non-root users will only be able to view their own
52686+ processes, and restricts them from viewing network-related information,
52687+ and viewing kernel symbol and module information.
52688+
52689+config GRKERNSEC_PROC_USERGROUP
52690+ bool "Allow special group"
52691+ depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
52692+ help
52693+ If you say Y here, you will be able to select a group that will be
52694+ able to view all processes and network-related information. If you've
52695+ enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
52696+ remain hidden. This option is useful if you want to run identd as
52697+ a non-root user.
52698+
52699+config GRKERNSEC_PROC_GID
52700+ int "GID for special group"
52701+ depends on GRKERNSEC_PROC_USERGROUP
52702+ default 1001
52703+
52704+config GRKERNSEC_PROC_ADD
52705+ bool "Additional restrictions"
52706+ depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
52707+ help
52708+ If you say Y here, additional restrictions will be placed on
52709+ /proc that keep normal users from viewing device information and
52710+ slabinfo information that could be useful for exploits.
52711+
52712+config GRKERNSEC_LINK
52713+ bool "Linking restrictions"
52714+ help
52715+ If you say Y here, /tmp race exploits will be prevented, since users
52716+ will no longer be able to follow symlinks owned by other users in
52717+ world-writable +t directories (e.g. /tmp), unless the owner of the
52718+ symlink is the owner of the directory. users will also not be
52719+ able to hardlink to files they do not own. If the sysctl option is
52720+ enabled, a sysctl option with name "linking_restrictions" is created.
52721+
52722+config GRKERNSEC_FIFO
52723+ bool "FIFO restrictions"
52724+ help
52725+ If you say Y here, users will not be able to write to FIFOs they don't
52726+ own in world-writable +t directories (e.g. /tmp), unless the owner of
52727+ the FIFO is the same owner of the directory it's held in. If the sysctl
52728+ option is enabled, a sysctl option with name "fifo_restrictions" is
52729+ created.
52730+
52731+config GRKERNSEC_SYSFS_RESTRICT
52732+ bool "Sysfs/debugfs restriction"
52733+ depends on SYSFS
52734+ help
52735+ If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
52736+ any filesystem normally mounted under it (e.g. debugfs) will only
52737+ be accessible by root. These filesystems generally provide access
52738+ to hardware and debug information that isn't appropriate for unprivileged
52739+ users of the system. Sysfs and debugfs have also become a large source
52740+ of new vulnerabilities, ranging from infoleaks to local compromise.
52741+ There has been very little oversight with an eye toward security involved
52742+ in adding new exporters of information to these filesystems, so their
52743+ use is discouraged.
52744+ This option is equivalent to a chmod 0700 of the mount paths.
52745+
52746+config GRKERNSEC_ROFS
52747+ bool "Runtime read-only mount protection"
52748+ help
52749+ If you say Y here, a sysctl option with name "romount_protect" will
52750+ be created. By setting this option to 1 at runtime, filesystems
52751+ will be protected in the following ways:
52752+ * No new writable mounts will be allowed
52753+ * Existing read-only mounts won't be able to be remounted read/write
52754+ * Write operations will be denied on all block devices
52755+ This option acts independently of grsec_lock: once it is set to 1,
52756+ it cannot be turned off. Therefore, please be mindful of the resulting
52757+ behavior if this option is enabled in an init script on a read-only
52758+ filesystem. This feature is mainly intended for secure embedded systems.
52759+
52760+config GRKERNSEC_CHROOT
52761+ bool "Chroot jail restrictions"
52762+ help
52763+ If you say Y here, you will be able to choose several options that will
52764+ make breaking out of a chrooted jail much more difficult. If you
52765+ encounter no software incompatibilities with the following options, it
52766+ is recommended that you enable each one.
52767+
52768+config GRKERNSEC_CHROOT_MOUNT
52769+ bool "Deny mounts"
52770+ depends on GRKERNSEC_CHROOT
52771+ help
52772+ If you say Y here, processes inside a chroot will not be able to
52773+ mount or remount filesystems. If the sysctl option is enabled, a
52774+ sysctl option with name "chroot_deny_mount" is created.
52775+
52776+config GRKERNSEC_CHROOT_DOUBLE
52777+ bool "Deny double-chroots"
52778+ depends on GRKERNSEC_CHROOT
52779+ help
52780+ If you say Y here, processes inside a chroot will not be able to chroot
52781+ again outside the chroot. This is a widely used method of breaking
52782+ out of a chroot jail and should not be allowed. If the sysctl
52783+ option is enabled, a sysctl option with name
52784+ "chroot_deny_chroot" is created.
52785+
52786+config GRKERNSEC_CHROOT_PIVOT
52787+ bool "Deny pivot_root in chroot"
52788+ depends on GRKERNSEC_CHROOT
52789+ help
52790+ If you say Y here, processes inside a chroot will not be able to use
52791+ a function called pivot_root() that was introduced in Linux 2.3.41. It
52792+ works similar to chroot in that it changes the root filesystem. This
52793+ function could be misused in a chrooted process to attempt to break out
52794+ of the chroot, and therefore should not be allowed. If the sysctl
52795+ option is enabled, a sysctl option with name "chroot_deny_pivot" is
52796+ created.
52797+
52798+config GRKERNSEC_CHROOT_CHDIR
52799+ bool "Enforce chdir(\"/\") on all chroots"
52800+ depends on GRKERNSEC_CHROOT
52801+ help
52802+ If you say Y here, the current working directory of all newly-chrooted
52803+ applications will be set to the the root directory of the chroot.
52804+ The man page on chroot(2) states:
52805+ Note that this call does not change the current working
52806+ directory, so that `.' can be outside the tree rooted at
52807+ `/'. In particular, the super-user can escape from a
52808+ `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
52809+
52810+ It is recommended that you say Y here, since it's not known to break
52811+ any software. If the sysctl option is enabled, a sysctl option with
52812+ name "chroot_enforce_chdir" is created.
52813+
52814+config GRKERNSEC_CHROOT_CHMOD
52815+ bool "Deny (f)chmod +s"
52816+ depends on GRKERNSEC_CHROOT
52817+ help
52818+ If you say Y here, processes inside a chroot will not be able to chmod
52819+ or fchmod files to make them have suid or sgid bits. This protects
52820+ against another published method of breaking a chroot. If the sysctl
52821+ option is enabled, a sysctl option with name "chroot_deny_chmod" is
52822+ created.
52823+
52824+config GRKERNSEC_CHROOT_FCHDIR
52825+ bool "Deny fchdir out of chroot"
52826+ depends on GRKERNSEC_CHROOT
52827+ help
52828+ If you say Y here, a well-known method of breaking chroots by fchdir'ing
52829+ to a file descriptor of the chrooting process that points to a directory
52830+ outside the filesystem will be stopped. If the sysctl option
52831+ is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
52832+
52833+config GRKERNSEC_CHROOT_MKNOD
52834+ bool "Deny mknod"
52835+ depends on GRKERNSEC_CHROOT
52836+ help
52837+ If you say Y here, processes inside a chroot will not be allowed to
52838+ mknod. The problem with using mknod inside a chroot is that it
52839+ would allow an attacker to create a device entry that is the same
52840+ as one on the physical root of your system, which could range from
52841+ anything from the console device to a device for your harddrive (which
52842+ they could then use to wipe the drive or steal data). It is recommended
52843+ that you say Y here, unless you run into software incompatibilities.
52844+ If the sysctl option is enabled, a sysctl option with name
52845+ "chroot_deny_mknod" is created.
52846+
52847+config GRKERNSEC_CHROOT_SHMAT
52848+ bool "Deny shmat() out of chroot"
52849+ depends on GRKERNSEC_CHROOT
52850+ help
52851+ If you say Y here, processes inside a chroot will not be able to attach
52852+ to shared memory segments that were created outside of the chroot jail.
52853+ It is recommended that you say Y here. If the sysctl option is enabled,
52854+ a sysctl option with name "chroot_deny_shmat" is created.
52855+
52856+config GRKERNSEC_CHROOT_UNIX
52857+ bool "Deny access to abstract AF_UNIX sockets out of chroot"
52858+ depends on GRKERNSEC_CHROOT
52859+ help
52860+ If you say Y here, processes inside a chroot will not be able to
52861+ connect to abstract (meaning not belonging to a filesystem) Unix
52862+ domain sockets that were bound outside of a chroot. It is recommended
52863+ that you say Y here. If the sysctl option is enabled, a sysctl option
52864+ with name "chroot_deny_unix" is created.
52865+
52866+config GRKERNSEC_CHROOT_FINDTASK
52867+ bool "Protect outside processes"
52868+ depends on GRKERNSEC_CHROOT
52869+ help
52870+ If you say Y here, processes inside a chroot will not be able to
52871+ kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
52872+ getsid, or view any process outside of the chroot. If the sysctl
52873+ option is enabled, a sysctl option with name "chroot_findtask" is
52874+ created.
52875+
52876+config GRKERNSEC_CHROOT_NICE
52877+ bool "Restrict priority changes"
52878+ depends on GRKERNSEC_CHROOT
52879+ help
52880+ If you say Y here, processes inside a chroot will not be able to raise
52881+ the priority of processes in the chroot, or alter the priority of
52882+ processes outside the chroot. This provides more security than simply
52883+ removing CAP_SYS_NICE from the process' capability set. If the
52884+ sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
52885+ is created.
52886+
52887+config GRKERNSEC_CHROOT_SYSCTL
52888+ bool "Deny sysctl writes"
52889+ depends on GRKERNSEC_CHROOT
52890+ help
52891+ If you say Y here, an attacker in a chroot will not be able to
52892+ write to sysctl entries, either by sysctl(2) or through a /proc
52893+ interface. It is strongly recommended that you say Y here. If the
52894+ sysctl option is enabled, a sysctl option with name
52895+ "chroot_deny_sysctl" is created.
52896+
52897+config GRKERNSEC_CHROOT_CAPS
52898+ bool "Capability restrictions"
52899+ depends on GRKERNSEC_CHROOT
52900+ help
52901+ If you say Y here, the capabilities on all root processes within a
52902+ chroot jail will be lowered to stop module insertion, raw i/o,
52903+ system and net admin tasks, rebooting the system, modifying immutable
52904+ files, modifying IPC owned by another, and changing the system time.
52905+ This is left an option because it can break some apps. Disable this
52906+ if your chrooted apps are having problems performing those kinds of
52907+ tasks. If the sysctl option is enabled, a sysctl option with
52908+ name "chroot_caps" is created.
52909+
52910+endmenu
52911+menu "Kernel Auditing"
52912+depends on GRKERNSEC
52913+
52914+config GRKERNSEC_AUDIT_GROUP
52915+ bool "Single group for auditing"
52916+ help
52917+ If you say Y here, the exec, chdir, and (un)mount logging features
52918+ will only operate on a group you specify. This option is recommended
52919+ if you only want to watch certain users instead of having a large
52920+ amount of logs from the entire system. If the sysctl option is enabled,
52921+ a sysctl option with name "audit_group" is created.
52922+
52923+config GRKERNSEC_AUDIT_GID
52924+ int "GID for auditing"
52925+ depends on GRKERNSEC_AUDIT_GROUP
52926+ default 1007
52927+
52928+config GRKERNSEC_EXECLOG
52929+ bool "Exec logging"
52930+ help
52931+ If you say Y here, all execve() calls will be logged (since the
52932+ other exec*() calls are frontends to execve(), all execution
52933+ will be logged). Useful for shell-servers that like to keep track
52934+ of their users. If the sysctl option is enabled, a sysctl option with
52935+ name "exec_logging" is created.
52936+ WARNING: This option when enabled will produce a LOT of logs, especially
52937+ on an active system.
52938+
52939+config GRKERNSEC_RESLOG
52940+ bool "Resource logging"
52941+ help
52942+ If you say Y here, all attempts to overstep resource limits will
52943+ be logged with the resource name, the requested size, and the current
52944+ limit. It is highly recommended that you say Y here. If the sysctl
52945+ option is enabled, a sysctl option with name "resource_logging" is
52946+ created. If the RBAC system is enabled, the sysctl value is ignored.
52947+
52948+config GRKERNSEC_CHROOT_EXECLOG
52949+ bool "Log execs within chroot"
52950+ help
52951+ If you say Y here, all executions inside a chroot jail will be logged
52952+ to syslog. This can cause a large amount of logs if certain
52953+ applications (eg. djb's daemontools) are installed on the system, and
52954+ is therefore left as an option. If the sysctl option is enabled, a
52955+ sysctl option with name "chroot_execlog" is created.
52956+
52957+config GRKERNSEC_AUDIT_PTRACE
52958+ bool "Ptrace logging"
52959+ help
52960+ If you say Y here, all attempts to attach to a process via ptrace
52961+ will be logged. If the sysctl option is enabled, a sysctl option
52962+ with name "audit_ptrace" is created.
52963+
52964+config GRKERNSEC_AUDIT_CHDIR
52965+ bool "Chdir logging"
52966+ help
52967+ If you say Y here, all chdir() calls will be logged. If the sysctl
52968+ option is enabled, a sysctl option with name "audit_chdir" is created.
52969+
52970+config GRKERNSEC_AUDIT_MOUNT
52971+ bool "(Un)Mount logging"
52972+ help
52973+ If you say Y here, all mounts and unmounts will be logged. If the
52974+ sysctl option is enabled, a sysctl option with name "audit_mount" is
52975+ created.
52976+
52977+config GRKERNSEC_SIGNAL
52978+ bool "Signal logging"
52979+ help
52980+ If you say Y here, certain important signals will be logged, such as
52981+ SIGSEGV, which will as a result inform you of when a error in a program
52982+ occurred, which in some cases could mean a possible exploit attempt.
52983+ If the sysctl option is enabled, a sysctl option with name
52984+ "signal_logging" is created.
52985+
52986+config GRKERNSEC_FORKFAIL
52987+ bool "Fork failure logging"
52988+ help
52989+ If you say Y here, all failed fork() attempts will be logged.
52990+ This could suggest a fork bomb, or someone attempting to overstep
52991+ their process limit. If the sysctl option is enabled, a sysctl option
52992+ with name "forkfail_logging" is created.
52993+
52994+config GRKERNSEC_TIME
52995+ bool "Time change logging"
52996+ help
52997+ If you say Y here, any changes of the system clock will be logged.
52998+ If the sysctl option is enabled, a sysctl option with name
52999+ "timechange_logging" is created.
53000+
53001+config GRKERNSEC_PROC_IPADDR
53002+ bool "/proc/<pid>/ipaddr support"
53003+ help
53004+ If you say Y here, a new entry will be added to each /proc/<pid>
53005+ directory that contains the IP address of the person using the task.
53006+ The IP is carried across local TCP and AF_UNIX stream sockets.
53007+ This information can be useful for IDS/IPSes to perform remote response
53008+ to a local attack. The entry is readable by only the owner of the
53009+ process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
53010+ the RBAC system), and thus does not create privacy concerns.
53011+
53012+config GRKERNSEC_RWXMAP_LOG
53013+ bool 'Denied RWX mmap/mprotect logging'
53014+ depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
53015+ help
53016+ If you say Y here, calls to mmap() and mprotect() with explicit
53017+ usage of PROT_WRITE and PROT_EXEC together will be logged when
53018+ denied by the PAX_MPROTECT feature. If the sysctl option is
53019+ enabled, a sysctl option with name "rwxmap_logging" is created.
53020+
53021+config GRKERNSEC_AUDIT_TEXTREL
53022+ bool 'ELF text relocations logging (READ HELP)'
53023+ depends on PAX_MPROTECT
53024+ help
53025+ If you say Y here, text relocations will be logged with the filename
53026+ of the offending library or binary. The purpose of the feature is
53027+ to help Linux distribution developers get rid of libraries and
53028+ binaries that need text relocations which hinder the future progress
53029+ of PaX. Only Linux distribution developers should say Y here, and
53030+ never on a production machine, as this option creates an information
53031+ leak that could aid an attacker in defeating the randomization of
53032+ a single memory region. If the sysctl option is enabled, a sysctl
53033+ option with name "audit_textrel" is created.
53034+
53035+endmenu
53036+
53037+menu "Executable Protections"
53038+depends on GRKERNSEC
53039+
53040+config GRKERNSEC_EXECVE
53041+ bool "Enforce RLIMIT_NPROC on execs"
53042+ help
53043+ If you say Y here, users with a resource limit on processes will
53044+ have the value checked during execve() calls. The current system
53045+ only checks the system limit during fork() calls. If the sysctl option
53046+ is enabled, a sysctl option with name "execve_limiting" is created.
53047+
53048+config GRKERNSEC_DMESG
53049+ bool "Dmesg(8) restriction"
53050+ help
53051+ If you say Y here, non-root users will not be able to use dmesg(8)
53052+ to view up to the last 4kb of messages in the kernel's log buffer.
53053+ The kernel's log buffer often contains kernel addresses and other
53054+ identifying information useful to an attacker in fingerprinting a
53055+ system for a targeted exploit.
53056+ If the sysctl option is enabled, a sysctl option with name "dmesg" is
53057+ created.
53058+
53059+config GRKERNSEC_HARDEN_PTRACE
53060+ bool "Deter ptrace-based process snooping"
53061+ help
53062+ If you say Y here, TTY sniffers and other malicious monitoring
53063+ programs implemented through ptrace will be defeated. If you
53064+ have been using the RBAC system, this option has already been
53065+ enabled for several years for all users, with the ability to make
53066+ fine-grained exceptions.
53067+
53068+ This option only affects the ability of non-root users to ptrace
53069+ processes that are not a descendent of the ptracing process.
53070+ This means that strace ./binary and gdb ./binary will still work,
53071+ but attaching to arbitrary processes will not. If the sysctl
53072+ option is enabled, a sysctl option with name "harden_ptrace" is
53073+ created.
53074+
53075+config GRKERNSEC_TPE
53076+ bool "Trusted Path Execution (TPE)"
53077+ help
53078+ If you say Y here, you will be able to choose a gid to add to the
53079+ supplementary groups of users you want to mark as "untrusted."
53080+ These users will not be able to execute any files that are not in
53081+ root-owned directories writable only by root. If the sysctl option
53082+ is enabled, a sysctl option with name "tpe" is created.
53083+
53084+config GRKERNSEC_TPE_ALL
53085+ bool "Partially restrict all non-root users"
53086+ depends on GRKERNSEC_TPE
53087+ help
53088+ If you say Y here, all non-root users will be covered under
53089+ a weaker TPE restriction. This is separate from, and in addition to,
53090+ the main TPE options that you have selected elsewhere. Thus, if a
53091+ "trusted" GID is chosen, this restriction applies to even that GID.
53092+ Under this restriction, all non-root users will only be allowed to
53093+ execute files in directories they own that are not group or
53094+ world-writable, or in directories owned by root and writable only by
53095+ root. If the sysctl option is enabled, a sysctl option with name
53096+ "tpe_restrict_all" is created.
53097+
53098+config GRKERNSEC_TPE_INVERT
53099+ bool "Invert GID option"
53100+ depends on GRKERNSEC_TPE
53101+ help
53102+ If you say Y here, the group you specify in the TPE configuration will
53103+ decide what group TPE restrictions will be *disabled* for. This
53104+ option is useful if you want TPE restrictions to be applied to most
53105+ users on the system. If the sysctl option is enabled, a sysctl option
53106+ with name "tpe_invert" is created. Unlike other sysctl options, this
53107+ entry will default to on for backward-compatibility.
53108+
53109+config GRKERNSEC_TPE_GID
53110+ int "GID for untrusted users"
53111+ depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
53112+ default 1005
53113+ help
53114+ Setting this GID determines what group TPE restrictions will be
53115+ *enabled* for. If the sysctl option is enabled, a sysctl option
53116+ with name "tpe_gid" is created.
53117+
53118+config GRKERNSEC_TPE_GID
53119+ int "GID for trusted users"
53120+ depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
53121+ default 1005
53122+ help
53123+ Setting this GID determines what group TPE restrictions will be
53124+ *disabled* for. If the sysctl option is enabled, a sysctl option
53125+ with name "tpe_gid" is created.
53126+
53127+endmenu
53128+menu "Network Protections"
53129+depends on GRKERNSEC
53130+
53131+config GRKERNSEC_RANDNET
53132+ bool "Larger entropy pools"
53133+ help
53134+ If you say Y here, the entropy pools used for many features of Linux
53135+ and grsecurity will be doubled in size. Since several grsecurity
53136+ features use additional randomness, it is recommended that you say Y
53137+ here. Saying Y here has a similar effect as modifying
53138+ /proc/sys/kernel/random/poolsize.
53139+
53140+config GRKERNSEC_BLACKHOLE
53141+ bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
53142+ help
53143+ If you say Y here, neither TCP resets nor ICMP
53144+ destination-unreachable packets will be sent in response to packets
53145+ sent to ports for which no associated listening process exists.
53146+ This feature supports both IPV4 and IPV6 and exempts the
53147+ loopback interface from blackholing. Enabling this feature
53148+ makes a host more resilient to DoS attacks and reduces network
53149+ visibility against scanners.
53150+
53151+ The blackhole feature as-implemented is equivalent to the FreeBSD
53152+ blackhole feature, as it prevents RST responses to all packets, not
53153+ just SYNs. Under most application behavior this causes no
53154+ problems, but applications (like haproxy) may not close certain
53155+ connections in a way that cleanly terminates them on the remote
53156+ end, leaving the remote host in LAST_ACK state. Because of this
53157+ side-effect and to prevent intentional LAST_ACK DoSes, this
53158+ feature also adds automatic mitigation against such attacks.
53159+ The mitigation drastically reduces the amount of time a socket
53160+ can spend in LAST_ACK state. If you're using haproxy and not
53161+ all servers it connects to have this option enabled, consider
53162+ disabling this feature on the haproxy host.
53163+
53164+ If the sysctl option is enabled, two sysctl options with names
53165+ "ip_blackhole" and "lastack_retries" will be created.
53166+ While "ip_blackhole" takes the standard zero/non-zero on/off
53167+ toggle, "lastack_retries" uses the same kinds of values as
53168+ "tcp_retries1" and "tcp_retries2". The default value of 4
53169+ prevents a socket from lasting more than 45 seconds in LAST_ACK
53170+ state.
53171+
53172+config GRKERNSEC_SOCKET
53173+ bool "Socket restrictions"
53174+ help
53175+ If you say Y here, you will be able to choose from several options.
53176+ If you assign a GID on your system and add it to the supplementary
53177+ groups of users you want to restrict socket access to, this patch
53178+ will perform up to three things, based on the option(s) you choose.
53179+
53180+config GRKERNSEC_SOCKET_ALL
53181+ bool "Deny any sockets to group"
53182+ depends on GRKERNSEC_SOCKET
53183+ help
53184+ If you say Y here, you will be able to choose a GID of whose users will
53185+ be unable to connect to other hosts from your machine or run server
53186+ applications from your machine. If the sysctl option is enabled, a
53187+ sysctl option with name "socket_all" is created.
53188+
53189+config GRKERNSEC_SOCKET_ALL_GID
53190+ int "GID to deny all sockets for"
53191+ depends on GRKERNSEC_SOCKET_ALL
53192+ default 1004
53193+ help
53194+ Here you can choose the GID to disable socket access for. Remember to
53195+ add the users you want socket access disabled for to the GID
53196+ specified here. If the sysctl option is enabled, a sysctl option
53197+ with name "socket_all_gid" is created.
53198+
53199+config GRKERNSEC_SOCKET_CLIENT
53200+ bool "Deny client sockets to group"
53201+ depends on GRKERNSEC_SOCKET
53202+ help
53203+ If you say Y here, you will be able to choose a GID of whose users will
53204+ be unable to connect to other hosts from your machine, but will be
53205+ able to run servers. If this option is enabled, all users in the group
53206+ you specify will have to use passive mode when initiating ftp transfers
53207+ from the shell on your machine. If the sysctl option is enabled, a
53208+ sysctl option with name "socket_client" is created.
53209+
53210+config GRKERNSEC_SOCKET_CLIENT_GID
53211+ int "GID to deny client sockets for"
53212+ depends on GRKERNSEC_SOCKET_CLIENT
53213+ default 1003
53214+ help
53215+ Here you can choose the GID to disable client socket access for.
53216+ Remember to add the users you want client socket access disabled for to
53217+ the GID specified here. If the sysctl option is enabled, a sysctl
53218+ option with name "socket_client_gid" is created.
53219+
53220+config GRKERNSEC_SOCKET_SERVER
53221+ bool "Deny server sockets to group"
53222+ depends on GRKERNSEC_SOCKET
53223+ help
53224+ If you say Y here, you will be able to choose a GID of whose users will
53225+ be unable to run server applications from your machine. If the sysctl
53226+ option is enabled, a sysctl option with name "socket_server" is created.
53227+
53228+config GRKERNSEC_SOCKET_SERVER_GID
53229+ int "GID to deny server sockets for"
53230+ depends on GRKERNSEC_SOCKET_SERVER
53231+ default 1002
53232+ help
53233+ Here you can choose the GID to disable server socket access for.
53234+ Remember to add the users you want server socket access disabled for to
53235+ the GID specified here. If the sysctl option is enabled, a sysctl
53236+ option with name "socket_server_gid" is created.
53237+
53238+endmenu
53239+menu "Sysctl support"
53240+depends on GRKERNSEC && SYSCTL
53241+
53242+config GRKERNSEC_SYSCTL
53243+ bool "Sysctl support"
53244+ help
53245+ If you say Y here, you will be able to change the options that
53246+ grsecurity runs with at bootup, without having to recompile your
53247+ kernel. You can echo values to files in /proc/sys/kernel/grsecurity
53248+ to enable (1) or disable (0) various features. All the sysctl entries
53249+ are mutable until the "grsec_lock" entry is set to a non-zero value.
53250+ All features enabled in the kernel configuration are disabled at boot
53251+ if you do not say Y to the "Turn on features by default" option.
53252+ All options should be set at startup, and the grsec_lock entry should
53253+ be set to a non-zero value after all the options are set.
53254+ *THIS IS EXTREMELY IMPORTANT*
53255+
53256+config GRKERNSEC_SYSCTL_DISTRO
53257+ bool "Extra sysctl support for distro makers (READ HELP)"
53258+ depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
53259+ help
53260+ If you say Y here, additional sysctl options will be created
53261+ for features that affect processes running as root. Therefore,
53262+ it is critical when using this option that the grsec_lock entry be
53263+ enabled after boot. Only distros with prebuilt kernel packages
53264+ with this option enabled that can ensure grsec_lock is enabled
53265+ after boot should use this option.
53266+ *Failure to set grsec_lock after boot makes all grsec features
53267+ this option covers useless*
53268+
53269+ Currently this option creates the following sysctl entries:
53270+ "Disable Privileged I/O": "disable_priv_io"
53271+
53272+config GRKERNSEC_SYSCTL_ON
53273+ bool "Turn on features by default"
53274+ depends on GRKERNSEC_SYSCTL
53275+ help
53276+ If you say Y here, instead of having all features enabled in the
53277+ kernel configuration disabled at boot time, the features will be
53278+ enabled at boot time. It is recommended you say Y here unless
53279+ there is some reason you would want all sysctl-tunable features to
53280+ be disabled by default. As mentioned elsewhere, it is important
53281+ to enable the grsec_lock entry once you have finished modifying
53282+ the sysctl entries.
53283+
53284+endmenu
53285+menu "Logging Options"
53286+depends on GRKERNSEC
53287+
53288+config GRKERNSEC_FLOODTIME
53289+ int "Seconds in between log messages (minimum)"
53290+ default 10
53291+ help
53292+ This option allows you to enforce the number of seconds between
53293+ grsecurity log messages. The default should be suitable for most
53294+ people, however, if you choose to change it, choose a value small enough
53295+ to allow informative logs to be produced, but large enough to
53296+ prevent flooding.
53297+
53298+config GRKERNSEC_FLOODBURST
53299+ int "Number of messages in a burst (maximum)"
53300+ default 4
53301+ help
53302+ This option allows you to choose the maximum number of messages allowed
53303+ within the flood time interval you chose in a separate option. The
53304+ default should be suitable for most people, however if you find that
53305+ many of your logs are being interpreted as flooding, you may want to
53306+ raise this value.
53307+
53308+endmenu
53309+
53310+endmenu
53311diff -urNp linux-2.6.32.41/grsecurity/Makefile linux-2.6.32.41/grsecurity/Makefile
53312--- linux-2.6.32.41/grsecurity/Makefile 1969-12-31 19:00:00.000000000 -0500
53313+++ linux-2.6.32.41/grsecurity/Makefile 2011-05-24 20:27:46.000000000 -0400
53314@@ -0,0 +1,33 @@
53315+# grsecurity's ACL system was originally written in 2001 by Michael Dalton
53316+# during 2001-2009 it has been completely redesigned by Brad Spengler
53317+# into an RBAC system
53318+#
53319+# All code in this directory and various hooks inserted throughout the kernel
53320+# are copyright Brad Spengler - Open Source Security, Inc., and released
53321+# under the GPL v2 or higher
53322+
53323+obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
53324+ grsec_mount.o grsec_sig.o grsec_sock.o grsec_sysctl.o \
53325+ grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
53326+
53327+obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
53328+ gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
53329+ gracl_learn.o grsec_log.o
53330+obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
53331+
53332+ifdef CONFIG_NET
53333+obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
53334+endif
53335+
53336+ifndef CONFIG_GRKERNSEC
53337+obj-y += grsec_disabled.o
53338+endif
53339+
53340+ifdef CONFIG_GRKERNSEC_HIDESYM
53341+extra-y := grsec_hidesym.o
53342+$(obj)/grsec_hidesym.o:
53343+ @-chmod -f 500 /boot
53344+ @-chmod -f 500 /lib/modules
53345+ @-chmod -f 700 .
53346+ @echo ' grsec: protected kernel image paths'
53347+endif
53348diff -urNp linux-2.6.32.41/include/acpi/acpi_drivers.h linux-2.6.32.41/include/acpi/acpi_drivers.h
53349--- linux-2.6.32.41/include/acpi/acpi_drivers.h 2011-03-27 14:31:47.000000000 -0400
53350+++ linux-2.6.32.41/include/acpi/acpi_drivers.h 2011-04-17 15:56:46.000000000 -0400
53351@@ -119,8 +119,8 @@ int acpi_processor_set_thermal_limit(acp
53352 Dock Station
53353 -------------------------------------------------------------------------- */
53354 struct acpi_dock_ops {
53355- acpi_notify_handler handler;
53356- acpi_notify_handler uevent;
53357+ const acpi_notify_handler handler;
53358+ const acpi_notify_handler uevent;
53359 };
53360
53361 #if defined(CONFIG_ACPI_DOCK) || defined(CONFIG_ACPI_DOCK_MODULE)
53362@@ -128,7 +128,7 @@ extern int is_dock_device(acpi_handle ha
53363 extern int register_dock_notifier(struct notifier_block *nb);
53364 extern void unregister_dock_notifier(struct notifier_block *nb);
53365 extern int register_hotplug_dock_device(acpi_handle handle,
53366- struct acpi_dock_ops *ops,
53367+ const struct acpi_dock_ops *ops,
53368 void *context);
53369 extern void unregister_hotplug_dock_device(acpi_handle handle);
53370 #else
53371@@ -144,7 +144,7 @@ static inline void unregister_dock_notif
53372 {
53373 }
53374 static inline int register_hotplug_dock_device(acpi_handle handle,
53375- struct acpi_dock_ops *ops,
53376+ const struct acpi_dock_ops *ops,
53377 void *context)
53378 {
53379 return -ENODEV;
53380diff -urNp linux-2.6.32.41/include/asm-generic/atomic-long.h linux-2.6.32.41/include/asm-generic/atomic-long.h
53381--- linux-2.6.32.41/include/asm-generic/atomic-long.h 2011-03-27 14:31:47.000000000 -0400
53382+++ linux-2.6.32.41/include/asm-generic/atomic-long.h 2011-05-16 21:46:57.000000000 -0400
53383@@ -22,6 +22,12 @@
53384
53385 typedef atomic64_t atomic_long_t;
53386
53387+#ifdef CONFIG_PAX_REFCOUNT
53388+typedef atomic64_unchecked_t atomic_long_unchecked_t;
53389+#else
53390+typedef atomic64_t atomic_long_unchecked_t;
53391+#endif
53392+
53393 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
53394
53395 static inline long atomic_long_read(atomic_long_t *l)
53396@@ -31,6 +37,15 @@ static inline long atomic_long_read(atom
53397 return (long)atomic64_read(v);
53398 }
53399
53400+#ifdef CONFIG_PAX_REFCOUNT
53401+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
53402+{
53403+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
53404+
53405+ return (long)atomic64_read_unchecked(v);
53406+}
53407+#endif
53408+
53409 static inline void atomic_long_set(atomic_long_t *l, long i)
53410 {
53411 atomic64_t *v = (atomic64_t *)l;
53412@@ -38,6 +53,15 @@ static inline void atomic_long_set(atomi
53413 atomic64_set(v, i);
53414 }
53415
53416+#ifdef CONFIG_PAX_REFCOUNT
53417+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
53418+{
53419+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
53420+
53421+ atomic64_set_unchecked(v, i);
53422+}
53423+#endif
53424+
53425 static inline void atomic_long_inc(atomic_long_t *l)
53426 {
53427 atomic64_t *v = (atomic64_t *)l;
53428@@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomi
53429 atomic64_inc(v);
53430 }
53431
53432+#ifdef CONFIG_PAX_REFCOUNT
53433+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
53434+{
53435+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
53436+
53437+ atomic64_inc_unchecked(v);
53438+}
53439+#endif
53440+
53441 static inline void atomic_long_dec(atomic_long_t *l)
53442 {
53443 atomic64_t *v = (atomic64_t *)l;
53444@@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomi
53445 atomic64_dec(v);
53446 }
53447
53448+#ifdef CONFIG_PAX_REFCOUNT
53449+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
53450+{
53451+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
53452+
53453+ atomic64_dec_unchecked(v);
53454+}
53455+#endif
53456+
53457 static inline void atomic_long_add(long i, atomic_long_t *l)
53458 {
53459 atomic64_t *v = (atomic64_t *)l;
53460@@ -59,6 +101,15 @@ static inline void atomic_long_add(long
53461 atomic64_add(i, v);
53462 }
53463
53464+#ifdef CONFIG_PAX_REFCOUNT
53465+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
53466+{
53467+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
53468+
53469+ atomic64_add_unchecked(i, v);
53470+}
53471+#endif
53472+
53473 static inline void atomic_long_sub(long i, atomic_long_t *l)
53474 {
53475 atomic64_t *v = (atomic64_t *)l;
53476@@ -115,6 +166,15 @@ static inline long atomic_long_inc_retur
53477 return (long)atomic64_inc_return(v);
53478 }
53479
53480+#ifdef CONFIG_PAX_REFCOUNT
53481+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
53482+{
53483+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
53484+
53485+ return (long)atomic64_inc_return_unchecked(v);
53486+}
53487+#endif
53488+
53489 static inline long atomic_long_dec_return(atomic_long_t *l)
53490 {
53491 atomic64_t *v = (atomic64_t *)l;
53492@@ -140,6 +200,12 @@ static inline long atomic_long_add_unles
53493
53494 typedef atomic_t atomic_long_t;
53495
53496+#ifdef CONFIG_PAX_REFCOUNT
53497+typedef atomic_unchecked_t atomic_long_unchecked_t;
53498+#else
53499+typedef atomic_t atomic_long_unchecked_t;
53500+#endif
53501+
53502 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
53503 static inline long atomic_long_read(atomic_long_t *l)
53504 {
53505@@ -148,6 +214,15 @@ static inline long atomic_long_read(atom
53506 return (long)atomic_read(v);
53507 }
53508
53509+#ifdef CONFIG_PAX_REFCOUNT
53510+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
53511+{
53512+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
53513+
53514+ return (long)atomic_read_unchecked(v);
53515+}
53516+#endif
53517+
53518 static inline void atomic_long_set(atomic_long_t *l, long i)
53519 {
53520 atomic_t *v = (atomic_t *)l;
53521@@ -155,6 +230,15 @@ static inline void atomic_long_set(atomi
53522 atomic_set(v, i);
53523 }
53524
53525+#ifdef CONFIG_PAX_REFCOUNT
53526+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
53527+{
53528+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
53529+
53530+ atomic_set_unchecked(v, i);
53531+}
53532+#endif
53533+
53534 static inline void atomic_long_inc(atomic_long_t *l)
53535 {
53536 atomic_t *v = (atomic_t *)l;
53537@@ -162,6 +246,15 @@ static inline void atomic_long_inc(atomi
53538 atomic_inc(v);
53539 }
53540
53541+#ifdef CONFIG_PAX_REFCOUNT
53542+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
53543+{
53544+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
53545+
53546+ atomic_inc_unchecked(v);
53547+}
53548+#endif
53549+
53550 static inline void atomic_long_dec(atomic_long_t *l)
53551 {
53552 atomic_t *v = (atomic_t *)l;
53553@@ -169,6 +262,15 @@ static inline void atomic_long_dec(atomi
53554 atomic_dec(v);
53555 }
53556
53557+#ifdef CONFIG_PAX_REFCOUNT
53558+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
53559+{
53560+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
53561+
53562+ atomic_dec_unchecked(v);
53563+}
53564+#endif
53565+
53566 static inline void atomic_long_add(long i, atomic_long_t *l)
53567 {
53568 atomic_t *v = (atomic_t *)l;
53569@@ -176,6 +278,15 @@ static inline void atomic_long_add(long
53570 atomic_add(i, v);
53571 }
53572
53573+#ifdef CONFIG_PAX_REFCOUNT
53574+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
53575+{
53576+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
53577+
53578+ atomic_add_unchecked(i, v);
53579+}
53580+#endif
53581+
53582 static inline void atomic_long_sub(long i, atomic_long_t *l)
53583 {
53584 atomic_t *v = (atomic_t *)l;
53585@@ -232,6 +343,15 @@ static inline long atomic_long_inc_retur
53586 return (long)atomic_inc_return(v);
53587 }
53588
53589+#ifdef CONFIG_PAX_REFCOUNT
53590+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
53591+{
53592+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
53593+
53594+ return (long)atomic_inc_return_unchecked(v);
53595+}
53596+#endif
53597+
53598 static inline long atomic_long_dec_return(atomic_long_t *l)
53599 {
53600 atomic_t *v = (atomic_t *)l;
53601@@ -255,4 +375,47 @@ static inline long atomic_long_add_unles
53602
53603 #endif /* BITS_PER_LONG == 64 */
53604
53605+#ifdef CONFIG_PAX_REFCOUNT
53606+static inline void pax_refcount_needs_these_functions(void)
53607+{
53608+ atomic_read_unchecked((atomic_unchecked_t *)NULL);
53609+ atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
53610+ atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
53611+ atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
53612+ atomic_inc_unchecked((atomic_unchecked_t *)NULL);
53613+ atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
53614+ atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
53615+ atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
53616+ atomic_dec_unchecked((atomic_unchecked_t *)NULL);
53617+ atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
53618+ atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
53619+
53620+ atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
53621+ atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
53622+ atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
53623+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
53624+ atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
53625+ atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
53626+}
53627+#else
53628+#define atomic_read_unchecked(v) atomic_read(v)
53629+#define atomic_set_unchecked(v, i) atomic_set((v), (i))
53630+#define atomic_add_unchecked(i, v) atomic_add((i), (v))
53631+#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
53632+#define atomic_inc_unchecked(v) atomic_inc(v)
53633+#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
53634+#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
53635+#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
53636+#define atomic_dec_unchecked(v) atomic_dec(v)
53637+#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
53638+#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
53639+
53640+#define atomic_long_read_unchecked(v) atomic_long_read(v)
53641+#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
53642+#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
53643+#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
53644+#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
53645+#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
53646+#endif
53647+
53648 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
53649diff -urNp linux-2.6.32.41/include/asm-generic/cache.h linux-2.6.32.41/include/asm-generic/cache.h
53650--- linux-2.6.32.41/include/asm-generic/cache.h 2011-03-27 14:31:47.000000000 -0400
53651+++ linux-2.6.32.41/include/asm-generic/cache.h 2011-05-04 17:56:28.000000000 -0400
53652@@ -6,7 +6,7 @@
53653 * cache lines need to provide their own cache.h.
53654 */
53655
53656-#define L1_CACHE_SHIFT 5
53657-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
53658+#define L1_CACHE_SHIFT 5U
53659+#define L1_CACHE_BYTES (1U << L1_CACHE_SHIFT)
53660
53661 #endif /* __ASM_GENERIC_CACHE_H */
53662diff -urNp linux-2.6.32.41/include/asm-generic/dma-mapping-common.h linux-2.6.32.41/include/asm-generic/dma-mapping-common.h
53663--- linux-2.6.32.41/include/asm-generic/dma-mapping-common.h 2011-03-27 14:31:47.000000000 -0400
53664+++ linux-2.6.32.41/include/asm-generic/dma-mapping-common.h 2011-04-17 15:56:46.000000000 -0400
53665@@ -11,7 +11,7 @@ static inline dma_addr_t dma_map_single_
53666 enum dma_data_direction dir,
53667 struct dma_attrs *attrs)
53668 {
53669- struct dma_map_ops *ops = get_dma_ops(dev);
53670+ const struct dma_map_ops *ops = get_dma_ops(dev);
53671 dma_addr_t addr;
53672
53673 kmemcheck_mark_initialized(ptr, size);
53674@@ -30,7 +30,7 @@ static inline void dma_unmap_single_attr
53675 enum dma_data_direction dir,
53676 struct dma_attrs *attrs)
53677 {
53678- struct dma_map_ops *ops = get_dma_ops(dev);
53679+ const struct dma_map_ops *ops = get_dma_ops(dev);
53680
53681 BUG_ON(!valid_dma_direction(dir));
53682 if (ops->unmap_page)
53683@@ -42,7 +42,7 @@ static inline int dma_map_sg_attrs(struc
53684 int nents, enum dma_data_direction dir,
53685 struct dma_attrs *attrs)
53686 {
53687- struct dma_map_ops *ops = get_dma_ops(dev);
53688+ const struct dma_map_ops *ops = get_dma_ops(dev);
53689 int i, ents;
53690 struct scatterlist *s;
53691
53692@@ -59,7 +59,7 @@ static inline void dma_unmap_sg_attrs(st
53693 int nents, enum dma_data_direction dir,
53694 struct dma_attrs *attrs)
53695 {
53696- struct dma_map_ops *ops = get_dma_ops(dev);
53697+ const struct dma_map_ops *ops = get_dma_ops(dev);
53698
53699 BUG_ON(!valid_dma_direction(dir));
53700 debug_dma_unmap_sg(dev, sg, nents, dir);
53701@@ -71,7 +71,7 @@ static inline dma_addr_t dma_map_page(st
53702 size_t offset, size_t size,
53703 enum dma_data_direction dir)
53704 {
53705- struct dma_map_ops *ops = get_dma_ops(dev);
53706+ const struct dma_map_ops *ops = get_dma_ops(dev);
53707 dma_addr_t addr;
53708
53709 kmemcheck_mark_initialized(page_address(page) + offset, size);
53710@@ -85,7 +85,7 @@ static inline dma_addr_t dma_map_page(st
53711 static inline void dma_unmap_page(struct device *dev, dma_addr_t addr,
53712 size_t size, enum dma_data_direction dir)
53713 {
53714- struct dma_map_ops *ops = get_dma_ops(dev);
53715+ const struct dma_map_ops *ops = get_dma_ops(dev);
53716
53717 BUG_ON(!valid_dma_direction(dir));
53718 if (ops->unmap_page)
53719@@ -97,7 +97,7 @@ static inline void dma_sync_single_for_c
53720 size_t size,
53721 enum dma_data_direction dir)
53722 {
53723- struct dma_map_ops *ops = get_dma_ops(dev);
53724+ const struct dma_map_ops *ops = get_dma_ops(dev);
53725
53726 BUG_ON(!valid_dma_direction(dir));
53727 if (ops->sync_single_for_cpu)
53728@@ -109,7 +109,7 @@ static inline void dma_sync_single_for_d
53729 dma_addr_t addr, size_t size,
53730 enum dma_data_direction dir)
53731 {
53732- struct dma_map_ops *ops = get_dma_ops(dev);
53733+ const struct dma_map_ops *ops = get_dma_ops(dev);
53734
53735 BUG_ON(!valid_dma_direction(dir));
53736 if (ops->sync_single_for_device)
53737@@ -123,7 +123,7 @@ static inline void dma_sync_single_range
53738 size_t size,
53739 enum dma_data_direction dir)
53740 {
53741- struct dma_map_ops *ops = get_dma_ops(dev);
53742+ const struct dma_map_ops *ops = get_dma_ops(dev);
53743
53744 BUG_ON(!valid_dma_direction(dir));
53745 if (ops->sync_single_range_for_cpu) {
53746@@ -140,7 +140,7 @@ static inline void dma_sync_single_range
53747 size_t size,
53748 enum dma_data_direction dir)
53749 {
53750- struct dma_map_ops *ops = get_dma_ops(dev);
53751+ const struct dma_map_ops *ops = get_dma_ops(dev);
53752
53753 BUG_ON(!valid_dma_direction(dir));
53754 if (ops->sync_single_range_for_device) {
53755@@ -155,7 +155,7 @@ static inline void
53756 dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg,
53757 int nelems, enum dma_data_direction dir)
53758 {
53759- struct dma_map_ops *ops = get_dma_ops(dev);
53760+ const struct dma_map_ops *ops = get_dma_ops(dev);
53761
53762 BUG_ON(!valid_dma_direction(dir));
53763 if (ops->sync_sg_for_cpu)
53764@@ -167,7 +167,7 @@ static inline void
53765 dma_sync_sg_for_device(struct device *dev, struct scatterlist *sg,
53766 int nelems, enum dma_data_direction dir)
53767 {
53768- struct dma_map_ops *ops = get_dma_ops(dev);
53769+ const struct dma_map_ops *ops = get_dma_ops(dev);
53770
53771 BUG_ON(!valid_dma_direction(dir));
53772 if (ops->sync_sg_for_device)
53773diff -urNp linux-2.6.32.41/include/asm-generic/futex.h linux-2.6.32.41/include/asm-generic/futex.h
53774--- linux-2.6.32.41/include/asm-generic/futex.h 2011-03-27 14:31:47.000000000 -0400
53775+++ linux-2.6.32.41/include/asm-generic/futex.h 2011-04-17 15:56:46.000000000 -0400
53776@@ -6,7 +6,7 @@
53777 #include <asm/errno.h>
53778
53779 static inline int
53780-futex_atomic_op_inuser (int encoded_op, int __user *uaddr)
53781+futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
53782 {
53783 int op = (encoded_op >> 28) & 7;
53784 int cmp = (encoded_op >> 24) & 15;
53785@@ -48,7 +48,7 @@ futex_atomic_op_inuser (int encoded_op,
53786 }
53787
53788 static inline int
53789-futex_atomic_cmpxchg_inatomic(int __user *uaddr, int oldval, int newval)
53790+futex_atomic_cmpxchg_inatomic(u32 __user *uaddr, int oldval, int newval)
53791 {
53792 return -ENOSYS;
53793 }
53794diff -urNp linux-2.6.32.41/include/asm-generic/int-l64.h linux-2.6.32.41/include/asm-generic/int-l64.h
53795--- linux-2.6.32.41/include/asm-generic/int-l64.h 2011-03-27 14:31:47.000000000 -0400
53796+++ linux-2.6.32.41/include/asm-generic/int-l64.h 2011-04-17 15:56:46.000000000 -0400
53797@@ -46,6 +46,8 @@ typedef unsigned int u32;
53798 typedef signed long s64;
53799 typedef unsigned long u64;
53800
53801+typedef unsigned int intoverflow_t __attribute__ ((mode(TI)));
53802+
53803 #define S8_C(x) x
53804 #define U8_C(x) x ## U
53805 #define S16_C(x) x
53806diff -urNp linux-2.6.32.41/include/asm-generic/int-ll64.h linux-2.6.32.41/include/asm-generic/int-ll64.h
53807--- linux-2.6.32.41/include/asm-generic/int-ll64.h 2011-03-27 14:31:47.000000000 -0400
53808+++ linux-2.6.32.41/include/asm-generic/int-ll64.h 2011-04-17 15:56:46.000000000 -0400
53809@@ -51,6 +51,8 @@ typedef unsigned int u32;
53810 typedef signed long long s64;
53811 typedef unsigned long long u64;
53812
53813+typedef unsigned long long intoverflow_t;
53814+
53815 #define S8_C(x) x
53816 #define U8_C(x) x ## U
53817 #define S16_C(x) x
53818diff -urNp linux-2.6.32.41/include/asm-generic/kmap_types.h linux-2.6.32.41/include/asm-generic/kmap_types.h
53819--- linux-2.6.32.41/include/asm-generic/kmap_types.h 2011-03-27 14:31:47.000000000 -0400
53820+++ linux-2.6.32.41/include/asm-generic/kmap_types.h 2011-04-17 15:56:46.000000000 -0400
53821@@ -28,7 +28,8 @@ KMAP_D(15) KM_UML_USERCOPY,
53822 KMAP_D(16) KM_IRQ_PTE,
53823 KMAP_D(17) KM_NMI,
53824 KMAP_D(18) KM_NMI_PTE,
53825-KMAP_D(19) KM_TYPE_NR
53826+KMAP_D(19) KM_CLEARPAGE,
53827+KMAP_D(20) KM_TYPE_NR
53828 };
53829
53830 #undef KMAP_D
53831diff -urNp linux-2.6.32.41/include/asm-generic/pgtable.h linux-2.6.32.41/include/asm-generic/pgtable.h
53832--- linux-2.6.32.41/include/asm-generic/pgtable.h 2011-03-27 14:31:47.000000000 -0400
53833+++ linux-2.6.32.41/include/asm-generic/pgtable.h 2011-04-17 15:56:46.000000000 -0400
53834@@ -344,6 +344,14 @@ extern void untrack_pfn_vma(struct vm_ar
53835 unsigned long size);
53836 #endif
53837
53838+#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
53839+static inline unsigned long pax_open_kernel(void) { return 0; }
53840+#endif
53841+
53842+#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
53843+static inline unsigned long pax_close_kernel(void) { return 0; }
53844+#endif
53845+
53846 #endif /* !__ASSEMBLY__ */
53847
53848 #endif /* _ASM_GENERIC_PGTABLE_H */
53849diff -urNp linux-2.6.32.41/include/asm-generic/pgtable-nopmd.h linux-2.6.32.41/include/asm-generic/pgtable-nopmd.h
53850--- linux-2.6.32.41/include/asm-generic/pgtable-nopmd.h 2011-03-27 14:31:47.000000000 -0400
53851+++ linux-2.6.32.41/include/asm-generic/pgtable-nopmd.h 2011-04-17 15:56:46.000000000 -0400
53852@@ -1,14 +1,19 @@
53853 #ifndef _PGTABLE_NOPMD_H
53854 #define _PGTABLE_NOPMD_H
53855
53856-#ifndef __ASSEMBLY__
53857-
53858 #include <asm-generic/pgtable-nopud.h>
53859
53860-struct mm_struct;
53861-
53862 #define __PAGETABLE_PMD_FOLDED
53863
53864+#define PMD_SHIFT PUD_SHIFT
53865+#define PTRS_PER_PMD 1
53866+#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
53867+#define PMD_MASK (~(PMD_SIZE-1))
53868+
53869+#ifndef __ASSEMBLY__
53870+
53871+struct mm_struct;
53872+
53873 /*
53874 * Having the pmd type consist of a pud gets the size right, and allows
53875 * us to conceptually access the pud entry that this pmd is folded into
53876@@ -16,11 +21,6 @@ struct mm_struct;
53877 */
53878 typedef struct { pud_t pud; } pmd_t;
53879
53880-#define PMD_SHIFT PUD_SHIFT
53881-#define PTRS_PER_PMD 1
53882-#define PMD_SIZE (1UL << PMD_SHIFT)
53883-#define PMD_MASK (~(PMD_SIZE-1))
53884-
53885 /*
53886 * The "pud_xxx()" functions here are trivial for a folded two-level
53887 * setup: the pmd is never bad, and a pmd always exists (as it's folded
53888diff -urNp linux-2.6.32.41/include/asm-generic/pgtable-nopud.h linux-2.6.32.41/include/asm-generic/pgtable-nopud.h
53889--- linux-2.6.32.41/include/asm-generic/pgtable-nopud.h 2011-03-27 14:31:47.000000000 -0400
53890+++ linux-2.6.32.41/include/asm-generic/pgtable-nopud.h 2011-04-17 15:56:46.000000000 -0400
53891@@ -1,10 +1,15 @@
53892 #ifndef _PGTABLE_NOPUD_H
53893 #define _PGTABLE_NOPUD_H
53894
53895-#ifndef __ASSEMBLY__
53896-
53897 #define __PAGETABLE_PUD_FOLDED
53898
53899+#define PUD_SHIFT PGDIR_SHIFT
53900+#define PTRS_PER_PUD 1
53901+#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
53902+#define PUD_MASK (~(PUD_SIZE-1))
53903+
53904+#ifndef __ASSEMBLY__
53905+
53906 /*
53907 * Having the pud type consist of a pgd gets the size right, and allows
53908 * us to conceptually access the pgd entry that this pud is folded into
53909@@ -12,11 +17,6 @@
53910 */
53911 typedef struct { pgd_t pgd; } pud_t;
53912
53913-#define PUD_SHIFT PGDIR_SHIFT
53914-#define PTRS_PER_PUD 1
53915-#define PUD_SIZE (1UL << PUD_SHIFT)
53916-#define PUD_MASK (~(PUD_SIZE-1))
53917-
53918 /*
53919 * The "pgd_xxx()" functions here are trivial for a folded two-level
53920 * setup: the pud is never bad, and a pud always exists (as it's folded
53921diff -urNp linux-2.6.32.41/include/asm-generic/vmlinux.lds.h linux-2.6.32.41/include/asm-generic/vmlinux.lds.h
53922--- linux-2.6.32.41/include/asm-generic/vmlinux.lds.h 2011-03-27 14:31:47.000000000 -0400
53923+++ linux-2.6.32.41/include/asm-generic/vmlinux.lds.h 2011-04-17 15:56:46.000000000 -0400
53924@@ -199,6 +199,7 @@
53925 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
53926 VMLINUX_SYMBOL(__start_rodata) = .; \
53927 *(.rodata) *(.rodata.*) \
53928+ *(.data.read_only) \
53929 *(__vermagic) /* Kernel version magic */ \
53930 *(__markers_strings) /* Markers: strings */ \
53931 *(__tracepoints_strings)/* Tracepoints: strings */ \
53932@@ -656,22 +657,24 @@
53933 * section in the linker script will go there too. @phdr should have
53934 * a leading colon.
53935 *
53936- * Note that this macros defines __per_cpu_load as an absolute symbol.
53937+ * Note that this macros defines per_cpu_load as an absolute symbol.
53938 * If there is no need to put the percpu section at a predetermined
53939 * address, use PERCPU().
53940 */
53941 #define PERCPU_VADDR(vaddr, phdr) \
53942- VMLINUX_SYMBOL(__per_cpu_load) = .; \
53943- .data.percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
53944+ per_cpu_load = .; \
53945+ .data.percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
53946 - LOAD_OFFSET) { \
53947+ VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
53948 VMLINUX_SYMBOL(__per_cpu_start) = .; \
53949 *(.data.percpu.first) \
53950- *(.data.percpu.page_aligned) \
53951 *(.data.percpu) \
53952+ . = ALIGN(PAGE_SIZE); \
53953+ *(.data.percpu.page_aligned) \
53954 *(.data.percpu.shared_aligned) \
53955 VMLINUX_SYMBOL(__per_cpu_end) = .; \
53956 } phdr \
53957- . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data.percpu);
53958+ . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data.percpu);
53959
53960 /**
53961 * PERCPU - define output section for percpu area, simple version
53962diff -urNp linux-2.6.32.41/include/drm/drmP.h linux-2.6.32.41/include/drm/drmP.h
53963--- linux-2.6.32.41/include/drm/drmP.h 2011-03-27 14:31:47.000000000 -0400
53964+++ linux-2.6.32.41/include/drm/drmP.h 2011-04-17 15:56:46.000000000 -0400
53965@@ -71,6 +71,7 @@
53966 #include <linux/workqueue.h>
53967 #include <linux/poll.h>
53968 #include <asm/pgalloc.h>
53969+#include <asm/local.h>
53970 #include "drm.h"
53971
53972 #include <linux/idr.h>
53973@@ -814,7 +815,7 @@ struct drm_driver {
53974 void (*vgaarb_irq)(struct drm_device *dev, bool state);
53975
53976 /* Driver private ops for this object */
53977- struct vm_operations_struct *gem_vm_ops;
53978+ const struct vm_operations_struct *gem_vm_ops;
53979
53980 int major;
53981 int minor;
53982@@ -917,7 +918,7 @@ struct drm_device {
53983
53984 /** \name Usage Counters */
53985 /*@{ */
53986- int open_count; /**< Outstanding files open */
53987+ local_t open_count; /**< Outstanding files open */
53988 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
53989 atomic_t vma_count; /**< Outstanding vma areas open */
53990 int buf_use; /**< Buffers in use -- cannot alloc */
53991@@ -928,7 +929,7 @@ struct drm_device {
53992 /*@{ */
53993 unsigned long counters;
53994 enum drm_stat_type types[15];
53995- atomic_t counts[15];
53996+ atomic_unchecked_t counts[15];
53997 /*@} */
53998
53999 struct list_head filelist;
54000@@ -1016,7 +1017,7 @@ struct drm_device {
54001 struct pci_controller *hose;
54002 #endif
54003 struct drm_sg_mem *sg; /**< Scatter gather memory */
54004- unsigned int num_crtcs; /**< Number of CRTCs on this device */
54005+ unsigned int num_crtcs; /**< Number of CRTCs on this device */
54006 void *dev_private; /**< device private data */
54007 void *mm_private;
54008 struct address_space *dev_mapping;
54009@@ -1042,11 +1043,11 @@ struct drm_device {
54010 spinlock_t object_name_lock;
54011 struct idr object_name_idr;
54012 atomic_t object_count;
54013- atomic_t object_memory;
54014+ atomic_unchecked_t object_memory;
54015 atomic_t pin_count;
54016- atomic_t pin_memory;
54017+ atomic_unchecked_t pin_memory;
54018 atomic_t gtt_count;
54019- atomic_t gtt_memory;
54020+ atomic_unchecked_t gtt_memory;
54021 uint32_t gtt_total;
54022 uint32_t invalidate_domains; /* domains pending invalidation */
54023 uint32_t flush_domains; /* domains pending flush */
54024diff -urNp linux-2.6.32.41/include/linux/a.out.h linux-2.6.32.41/include/linux/a.out.h
54025--- linux-2.6.32.41/include/linux/a.out.h 2011-03-27 14:31:47.000000000 -0400
54026+++ linux-2.6.32.41/include/linux/a.out.h 2011-04-17 15:56:46.000000000 -0400
54027@@ -39,6 +39,14 @@ enum machine_type {
54028 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
54029 };
54030
54031+/* Constants for the N_FLAGS field */
54032+#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
54033+#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
54034+#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
54035+#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
54036+/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
54037+#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
54038+
54039 #if !defined (N_MAGIC)
54040 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
54041 #endif
54042diff -urNp linux-2.6.32.41/include/linux/atmdev.h linux-2.6.32.41/include/linux/atmdev.h
54043--- linux-2.6.32.41/include/linux/atmdev.h 2011-03-27 14:31:47.000000000 -0400
54044+++ linux-2.6.32.41/include/linux/atmdev.h 2011-04-17 15:56:46.000000000 -0400
54045@@ -237,7 +237,7 @@ struct compat_atm_iobuf {
54046 #endif
54047
54048 struct k_atm_aal_stats {
54049-#define __HANDLE_ITEM(i) atomic_t i
54050+#define __HANDLE_ITEM(i) atomic_unchecked_t i
54051 __AAL_STAT_ITEMS
54052 #undef __HANDLE_ITEM
54053 };
54054diff -urNp linux-2.6.32.41/include/linux/backlight.h linux-2.6.32.41/include/linux/backlight.h
54055--- linux-2.6.32.41/include/linux/backlight.h 2011-03-27 14:31:47.000000000 -0400
54056+++ linux-2.6.32.41/include/linux/backlight.h 2011-04-17 15:56:46.000000000 -0400
54057@@ -36,18 +36,18 @@ struct backlight_device;
54058 struct fb_info;
54059
54060 struct backlight_ops {
54061- unsigned int options;
54062+ const unsigned int options;
54063
54064 #define BL_CORE_SUSPENDRESUME (1 << 0)
54065
54066 /* Notify the backlight driver some property has changed */
54067- int (*update_status)(struct backlight_device *);
54068+ int (* const update_status)(struct backlight_device *);
54069 /* Return the current backlight brightness (accounting for power,
54070 fb_blank etc.) */
54071- int (*get_brightness)(struct backlight_device *);
54072+ int (* const get_brightness)(struct backlight_device *);
54073 /* Check if given framebuffer device is the one bound to this backlight;
54074 return 0 if not, !=0 if it is. If NULL, backlight always matches the fb. */
54075- int (*check_fb)(struct fb_info *);
54076+ int (* const check_fb)(struct fb_info *);
54077 };
54078
54079 /* This structure defines all the properties of a backlight */
54080@@ -86,7 +86,7 @@ struct backlight_device {
54081 registered this device has been unloaded, and if class_get_devdata()
54082 points to something in the body of that driver, it is also invalid. */
54083 struct mutex ops_lock;
54084- struct backlight_ops *ops;
54085+ const struct backlight_ops *ops;
54086
54087 /* The framebuffer notifier block */
54088 struct notifier_block fb_notif;
54089@@ -103,7 +103,7 @@ static inline void backlight_update_stat
54090 }
54091
54092 extern struct backlight_device *backlight_device_register(const char *name,
54093- struct device *dev, void *devdata, struct backlight_ops *ops);
54094+ struct device *dev, void *devdata, const struct backlight_ops *ops);
54095 extern void backlight_device_unregister(struct backlight_device *bd);
54096 extern void backlight_force_update(struct backlight_device *bd,
54097 enum backlight_update_reason reason);
54098diff -urNp linux-2.6.32.41/include/linux/binfmts.h linux-2.6.32.41/include/linux/binfmts.h
54099--- linux-2.6.32.41/include/linux/binfmts.h 2011-04-17 17:00:52.000000000 -0400
54100+++ linux-2.6.32.41/include/linux/binfmts.h 2011-04-17 15:56:46.000000000 -0400
54101@@ -83,6 +83,7 @@ struct linux_binfmt {
54102 int (*load_binary)(struct linux_binprm *, struct pt_regs * regs);
54103 int (*load_shlib)(struct file *);
54104 int (*core_dump)(long signr, struct pt_regs *regs, struct file *file, unsigned long limit);
54105+ void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
54106 unsigned long min_coredump; /* minimal dump size */
54107 int hasvdso;
54108 };
54109diff -urNp linux-2.6.32.41/include/linux/blkdev.h linux-2.6.32.41/include/linux/blkdev.h
54110--- linux-2.6.32.41/include/linux/blkdev.h 2011-03-27 14:31:47.000000000 -0400
54111+++ linux-2.6.32.41/include/linux/blkdev.h 2011-04-17 15:56:46.000000000 -0400
54112@@ -1265,19 +1265,19 @@ static inline int blk_integrity_rq(struc
54113 #endif /* CONFIG_BLK_DEV_INTEGRITY */
54114
54115 struct block_device_operations {
54116- int (*open) (struct block_device *, fmode_t);
54117- int (*release) (struct gendisk *, fmode_t);
54118- int (*locked_ioctl) (struct block_device *, fmode_t, unsigned, unsigned long);
54119- int (*ioctl) (struct block_device *, fmode_t, unsigned, unsigned long);
54120- int (*compat_ioctl) (struct block_device *, fmode_t, unsigned, unsigned long);
54121- int (*direct_access) (struct block_device *, sector_t,
54122+ int (* const open) (struct block_device *, fmode_t);
54123+ int (* const release) (struct gendisk *, fmode_t);
54124+ int (* const locked_ioctl) (struct block_device *, fmode_t, unsigned, unsigned long);
54125+ int (* const ioctl) (struct block_device *, fmode_t, unsigned, unsigned long);
54126+ int (* const compat_ioctl) (struct block_device *, fmode_t, unsigned, unsigned long);
54127+ int (* const direct_access) (struct block_device *, sector_t,
54128 void **, unsigned long *);
54129- int (*media_changed) (struct gendisk *);
54130- unsigned long long (*set_capacity) (struct gendisk *,
54131+ int (* const media_changed) (struct gendisk *);
54132+ unsigned long long (* const set_capacity) (struct gendisk *,
54133 unsigned long long);
54134- int (*revalidate_disk) (struct gendisk *);
54135- int (*getgeo)(struct block_device *, struct hd_geometry *);
54136- struct module *owner;
54137+ int (* const revalidate_disk) (struct gendisk *);
54138+ int (*const getgeo)(struct block_device *, struct hd_geometry *);
54139+ struct module * const owner;
54140 };
54141
54142 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
54143diff -urNp linux-2.6.32.41/include/linux/blktrace_api.h linux-2.6.32.41/include/linux/blktrace_api.h
54144--- linux-2.6.32.41/include/linux/blktrace_api.h 2011-03-27 14:31:47.000000000 -0400
54145+++ linux-2.6.32.41/include/linux/blktrace_api.h 2011-05-04 17:56:28.000000000 -0400
54146@@ -160,7 +160,7 @@ struct blk_trace {
54147 struct dentry *dir;
54148 struct dentry *dropped_file;
54149 struct dentry *msg_file;
54150- atomic_t dropped;
54151+ atomic_unchecked_t dropped;
54152 };
54153
54154 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
54155diff -urNp linux-2.6.32.41/include/linux/byteorder/little_endian.h linux-2.6.32.41/include/linux/byteorder/little_endian.h
54156--- linux-2.6.32.41/include/linux/byteorder/little_endian.h 2011-03-27 14:31:47.000000000 -0400
54157+++ linux-2.6.32.41/include/linux/byteorder/little_endian.h 2011-04-17 15:56:46.000000000 -0400
54158@@ -42,51 +42,51 @@
54159
54160 static inline __le64 __cpu_to_le64p(const __u64 *p)
54161 {
54162- return (__force __le64)*p;
54163+ return (__force const __le64)*p;
54164 }
54165 static inline __u64 __le64_to_cpup(const __le64 *p)
54166 {
54167- return (__force __u64)*p;
54168+ return (__force const __u64)*p;
54169 }
54170 static inline __le32 __cpu_to_le32p(const __u32 *p)
54171 {
54172- return (__force __le32)*p;
54173+ return (__force const __le32)*p;
54174 }
54175 static inline __u32 __le32_to_cpup(const __le32 *p)
54176 {
54177- return (__force __u32)*p;
54178+ return (__force const __u32)*p;
54179 }
54180 static inline __le16 __cpu_to_le16p(const __u16 *p)
54181 {
54182- return (__force __le16)*p;
54183+ return (__force const __le16)*p;
54184 }
54185 static inline __u16 __le16_to_cpup(const __le16 *p)
54186 {
54187- return (__force __u16)*p;
54188+ return (__force const __u16)*p;
54189 }
54190 static inline __be64 __cpu_to_be64p(const __u64 *p)
54191 {
54192- return (__force __be64)__swab64p(p);
54193+ return (__force const __be64)__swab64p(p);
54194 }
54195 static inline __u64 __be64_to_cpup(const __be64 *p)
54196 {
54197- return __swab64p((__u64 *)p);
54198+ return __swab64p((const __u64 *)p);
54199 }
54200 static inline __be32 __cpu_to_be32p(const __u32 *p)
54201 {
54202- return (__force __be32)__swab32p(p);
54203+ return (__force const __be32)__swab32p(p);
54204 }
54205 static inline __u32 __be32_to_cpup(const __be32 *p)
54206 {
54207- return __swab32p((__u32 *)p);
54208+ return __swab32p((const __u32 *)p);
54209 }
54210 static inline __be16 __cpu_to_be16p(const __u16 *p)
54211 {
54212- return (__force __be16)__swab16p(p);
54213+ return (__force const __be16)__swab16p(p);
54214 }
54215 static inline __u16 __be16_to_cpup(const __be16 *p)
54216 {
54217- return __swab16p((__u16 *)p);
54218+ return __swab16p((const __u16 *)p);
54219 }
54220 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
54221 #define __le64_to_cpus(x) do { (void)(x); } while (0)
54222diff -urNp linux-2.6.32.41/include/linux/cache.h linux-2.6.32.41/include/linux/cache.h
54223--- linux-2.6.32.41/include/linux/cache.h 2011-03-27 14:31:47.000000000 -0400
54224+++ linux-2.6.32.41/include/linux/cache.h 2011-04-17 15:56:46.000000000 -0400
54225@@ -16,6 +16,10 @@
54226 #define __read_mostly
54227 #endif
54228
54229+#ifndef __read_only
54230+#define __read_only __read_mostly
54231+#endif
54232+
54233 #ifndef ____cacheline_aligned
54234 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
54235 #endif
54236diff -urNp linux-2.6.32.41/include/linux/capability.h linux-2.6.32.41/include/linux/capability.h
54237--- linux-2.6.32.41/include/linux/capability.h 2011-03-27 14:31:47.000000000 -0400
54238+++ linux-2.6.32.41/include/linux/capability.h 2011-04-17 15:56:46.000000000 -0400
54239@@ -563,6 +563,7 @@ extern const kernel_cap_t __cap_init_eff
54240 (security_real_capable_noaudit((t), (cap)) == 0)
54241
54242 extern int capable(int cap);
54243+int capable_nolog(int cap);
54244
54245 /* audit system wants to get cap info from files as well */
54246 struct dentry;
54247diff -urNp linux-2.6.32.41/include/linux/compiler-gcc4.h linux-2.6.32.41/include/linux/compiler-gcc4.h
54248--- linux-2.6.32.41/include/linux/compiler-gcc4.h 2011-03-27 14:31:47.000000000 -0400
54249+++ linux-2.6.32.41/include/linux/compiler-gcc4.h 2011-04-17 15:56:46.000000000 -0400
54250@@ -36,4 +36,8 @@
54251 the kernel context */
54252 #define __cold __attribute__((__cold__))
54253
54254+#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
54255+#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
54256+#define __bos0(ptr) __bos((ptr), 0)
54257+#define __bos1(ptr) __bos((ptr), 1)
54258 #endif
54259diff -urNp linux-2.6.32.41/include/linux/compiler.h linux-2.6.32.41/include/linux/compiler.h
54260--- linux-2.6.32.41/include/linux/compiler.h 2011-03-27 14:31:47.000000000 -0400
54261+++ linux-2.6.32.41/include/linux/compiler.h 2011-04-17 15:56:46.000000000 -0400
54262@@ -256,6 +256,22 @@ void ftrace_likely_update(struct ftrace_
54263 #define __cold
54264 #endif
54265
54266+#ifndef __alloc_size
54267+#define __alloc_size
54268+#endif
54269+
54270+#ifndef __bos
54271+#define __bos
54272+#endif
54273+
54274+#ifndef __bos0
54275+#define __bos0
54276+#endif
54277+
54278+#ifndef __bos1
54279+#define __bos1
54280+#endif
54281+
54282 /* Simple shorthand for a section definition */
54283 #ifndef __section
54284 # define __section(S) __attribute__ ((__section__(#S)))
54285@@ -278,6 +294,7 @@ void ftrace_likely_update(struct ftrace_
54286 * use is to mediate communication between process-level code and irq/NMI
54287 * handlers, all running on the same CPU.
54288 */
54289-#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
54290+#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
54291+#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
54292
54293 #endif /* __LINUX_COMPILER_H */
54294diff -urNp linux-2.6.32.41/include/linux/dcache.h linux-2.6.32.41/include/linux/dcache.h
54295--- linux-2.6.32.41/include/linux/dcache.h 2011-03-27 14:31:47.000000000 -0400
54296+++ linux-2.6.32.41/include/linux/dcache.h 2011-04-23 13:34:46.000000000 -0400
54297@@ -119,6 +119,8 @@ struct dentry {
54298 unsigned char d_iname[DNAME_INLINE_LEN_MIN]; /* small names */
54299 };
54300
54301+#define DNAME_INLINE_LEN (sizeof(struct dentry)-offsetof(struct dentry,d_iname))
54302+
54303 /*
54304 * dentry->d_lock spinlock nesting subclasses:
54305 *
54306diff -urNp linux-2.6.32.41/include/linux/decompress/mm.h linux-2.6.32.41/include/linux/decompress/mm.h
54307--- linux-2.6.32.41/include/linux/decompress/mm.h 2011-03-27 14:31:47.000000000 -0400
54308+++ linux-2.6.32.41/include/linux/decompress/mm.h 2011-04-17 15:56:46.000000000 -0400
54309@@ -78,7 +78,7 @@ static void free(void *where)
54310 * warnings when not needed (indeed large_malloc / large_free are not
54311 * needed by inflate */
54312
54313-#define malloc(a) kmalloc(a, GFP_KERNEL)
54314+#define malloc(a) kmalloc((a), GFP_KERNEL)
54315 #define free(a) kfree(a)
54316
54317 #define large_malloc(a) vmalloc(a)
54318diff -urNp linux-2.6.32.41/include/linux/dma-mapping.h linux-2.6.32.41/include/linux/dma-mapping.h
54319--- linux-2.6.32.41/include/linux/dma-mapping.h 2011-03-27 14:31:47.000000000 -0400
54320+++ linux-2.6.32.41/include/linux/dma-mapping.h 2011-04-17 15:56:46.000000000 -0400
54321@@ -16,50 +16,50 @@ enum dma_data_direction {
54322 };
54323
54324 struct dma_map_ops {
54325- void* (*alloc_coherent)(struct device *dev, size_t size,
54326+ void* (* const alloc_coherent)(struct device *dev, size_t size,
54327 dma_addr_t *dma_handle, gfp_t gfp);
54328- void (*free_coherent)(struct device *dev, size_t size,
54329+ void (* const free_coherent)(struct device *dev, size_t size,
54330 void *vaddr, dma_addr_t dma_handle);
54331- dma_addr_t (*map_page)(struct device *dev, struct page *page,
54332+ dma_addr_t (* const map_page)(struct device *dev, struct page *page,
54333 unsigned long offset, size_t size,
54334 enum dma_data_direction dir,
54335 struct dma_attrs *attrs);
54336- void (*unmap_page)(struct device *dev, dma_addr_t dma_handle,
54337+ void (* const unmap_page)(struct device *dev, dma_addr_t dma_handle,
54338 size_t size, enum dma_data_direction dir,
54339 struct dma_attrs *attrs);
54340- int (*map_sg)(struct device *dev, struct scatterlist *sg,
54341+ int (* const map_sg)(struct device *dev, struct scatterlist *sg,
54342 int nents, enum dma_data_direction dir,
54343 struct dma_attrs *attrs);
54344- void (*unmap_sg)(struct device *dev,
54345+ void (* const unmap_sg)(struct device *dev,
54346 struct scatterlist *sg, int nents,
54347 enum dma_data_direction dir,
54348 struct dma_attrs *attrs);
54349- void (*sync_single_for_cpu)(struct device *dev,
54350+ void (* const sync_single_for_cpu)(struct device *dev,
54351 dma_addr_t dma_handle, size_t size,
54352 enum dma_data_direction dir);
54353- void (*sync_single_for_device)(struct device *dev,
54354+ void (* const sync_single_for_device)(struct device *dev,
54355 dma_addr_t dma_handle, size_t size,
54356 enum dma_data_direction dir);
54357- void (*sync_single_range_for_cpu)(struct device *dev,
54358+ void (* const sync_single_range_for_cpu)(struct device *dev,
54359 dma_addr_t dma_handle,
54360 unsigned long offset,
54361 size_t size,
54362 enum dma_data_direction dir);
54363- void (*sync_single_range_for_device)(struct device *dev,
54364+ void (* const sync_single_range_for_device)(struct device *dev,
54365 dma_addr_t dma_handle,
54366 unsigned long offset,
54367 size_t size,
54368 enum dma_data_direction dir);
54369- void (*sync_sg_for_cpu)(struct device *dev,
54370+ void (* const sync_sg_for_cpu)(struct device *dev,
54371 struct scatterlist *sg, int nents,
54372 enum dma_data_direction dir);
54373- void (*sync_sg_for_device)(struct device *dev,
54374+ void (* const sync_sg_for_device)(struct device *dev,
54375 struct scatterlist *sg, int nents,
54376 enum dma_data_direction dir);
54377- int (*mapping_error)(struct device *dev, dma_addr_t dma_addr);
54378- int (*dma_supported)(struct device *dev, u64 mask);
54379+ int (* const mapping_error)(struct device *dev, dma_addr_t dma_addr);
54380+ int (* const dma_supported)(struct device *dev, u64 mask);
54381 int (*set_dma_mask)(struct device *dev, u64 mask);
54382- int is_phys;
54383+ const int is_phys;
54384 };
54385
54386 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
54387diff -urNp linux-2.6.32.41/include/linux/dst.h linux-2.6.32.41/include/linux/dst.h
54388--- linux-2.6.32.41/include/linux/dst.h 2011-03-27 14:31:47.000000000 -0400
54389+++ linux-2.6.32.41/include/linux/dst.h 2011-04-17 15:56:46.000000000 -0400
54390@@ -380,7 +380,7 @@ struct dst_node
54391 struct thread_pool *pool;
54392
54393 /* Transaction IDs live here */
54394- atomic_long_t gen;
54395+ atomic_long_unchecked_t gen;
54396
54397 /*
54398 * How frequently and how many times transaction
54399diff -urNp linux-2.6.32.41/include/linux/elf.h linux-2.6.32.41/include/linux/elf.h
54400--- linux-2.6.32.41/include/linux/elf.h 2011-03-27 14:31:47.000000000 -0400
54401+++ linux-2.6.32.41/include/linux/elf.h 2011-04-17 15:56:46.000000000 -0400
54402@@ -49,6 +49,17 @@ typedef __s64 Elf64_Sxword;
54403 #define PT_GNU_EH_FRAME 0x6474e550
54404
54405 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
54406+#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
54407+
54408+#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
54409+
54410+/* Constants for the e_flags field */
54411+#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
54412+#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
54413+#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
54414+#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
54415+/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
54416+#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
54417
54418 /* These constants define the different elf file types */
54419 #define ET_NONE 0
54420@@ -84,6 +95,8 @@ typedef __s64 Elf64_Sxword;
54421 #define DT_DEBUG 21
54422 #define DT_TEXTREL 22
54423 #define DT_JMPREL 23
54424+#define DT_FLAGS 30
54425+ #define DF_TEXTREL 0x00000004
54426 #define DT_ENCODING 32
54427 #define OLD_DT_LOOS 0x60000000
54428 #define DT_LOOS 0x6000000d
54429@@ -230,6 +243,19 @@ typedef struct elf64_hdr {
54430 #define PF_W 0x2
54431 #define PF_X 0x1
54432
54433+#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
54434+#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
54435+#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
54436+#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
54437+#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
54438+#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
54439+/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
54440+/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
54441+#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
54442+#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
54443+#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
54444+#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
54445+
54446 typedef struct elf32_phdr{
54447 Elf32_Word p_type;
54448 Elf32_Off p_offset;
54449@@ -322,6 +348,8 @@ typedef struct elf64_shdr {
54450 #define EI_OSABI 7
54451 #define EI_PAD 8
54452
54453+#define EI_PAX 14
54454+
54455 #define ELFMAG0 0x7f /* EI_MAG */
54456 #define ELFMAG1 'E'
54457 #define ELFMAG2 'L'
54458@@ -386,6 +414,7 @@ extern Elf32_Dyn _DYNAMIC [];
54459 #define elf_phdr elf32_phdr
54460 #define elf_note elf32_note
54461 #define elf_addr_t Elf32_Off
54462+#define elf_dyn Elf32_Dyn
54463
54464 #else
54465
54466@@ -394,6 +423,7 @@ extern Elf64_Dyn _DYNAMIC [];
54467 #define elf_phdr elf64_phdr
54468 #define elf_note elf64_note
54469 #define elf_addr_t Elf64_Off
54470+#define elf_dyn Elf64_Dyn
54471
54472 #endif
54473
54474diff -urNp linux-2.6.32.41/include/linux/fscache-cache.h linux-2.6.32.41/include/linux/fscache-cache.h
54475--- linux-2.6.32.41/include/linux/fscache-cache.h 2011-03-27 14:31:47.000000000 -0400
54476+++ linux-2.6.32.41/include/linux/fscache-cache.h 2011-05-04 17:56:28.000000000 -0400
54477@@ -116,7 +116,7 @@ struct fscache_operation {
54478 #endif
54479 };
54480
54481-extern atomic_t fscache_op_debug_id;
54482+extern atomic_unchecked_t fscache_op_debug_id;
54483 extern const struct slow_work_ops fscache_op_slow_work_ops;
54484
54485 extern void fscache_enqueue_operation(struct fscache_operation *);
54486@@ -134,7 +134,7 @@ static inline void fscache_operation_ini
54487 fscache_operation_release_t release)
54488 {
54489 atomic_set(&op->usage, 1);
54490- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
54491+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
54492 op->release = release;
54493 INIT_LIST_HEAD(&op->pend_link);
54494 fscache_set_op_state(op, "Init");
54495diff -urNp linux-2.6.32.41/include/linux/fs.h linux-2.6.32.41/include/linux/fs.h
54496--- linux-2.6.32.41/include/linux/fs.h 2011-03-27 14:31:47.000000000 -0400
54497+++ linux-2.6.32.41/include/linux/fs.h 2011-04-17 15:56:46.000000000 -0400
54498@@ -90,6 +90,11 @@ struct inodes_stat_t {
54499 /* Expect random access pattern */
54500 #define FMODE_RANDOM ((__force fmode_t)4096)
54501
54502+/* Hack for grsec so as not to require read permission simply to execute
54503+ * a binary
54504+ */
54505+#define FMODE_GREXEC ((__force fmode_t)0x2000000)
54506+
54507 /*
54508 * The below are the various read and write types that we support. Some of
54509 * them include behavioral modifiers that send information down to the
54510@@ -568,41 +573,41 @@ typedef int (*read_actor_t)(read_descrip
54511 unsigned long, unsigned long);
54512
54513 struct address_space_operations {
54514- int (*writepage)(struct page *page, struct writeback_control *wbc);
54515- int (*readpage)(struct file *, struct page *);
54516- void (*sync_page)(struct page *);
54517+ int (* const writepage)(struct page *page, struct writeback_control *wbc);
54518+ int (* const readpage)(struct file *, struct page *);
54519+ void (* const sync_page)(struct page *);
54520
54521 /* Write back some dirty pages from this mapping. */
54522- int (*writepages)(struct address_space *, struct writeback_control *);
54523+ int (* const writepages)(struct address_space *, struct writeback_control *);
54524
54525 /* Set a page dirty. Return true if this dirtied it */
54526- int (*set_page_dirty)(struct page *page);
54527+ int (* const set_page_dirty)(struct page *page);
54528
54529- int (*readpages)(struct file *filp, struct address_space *mapping,
54530+ int (* const readpages)(struct file *filp, struct address_space *mapping,
54531 struct list_head *pages, unsigned nr_pages);
54532
54533- int (*write_begin)(struct file *, struct address_space *mapping,
54534+ int (* const write_begin)(struct file *, struct address_space *mapping,
54535 loff_t pos, unsigned len, unsigned flags,
54536 struct page **pagep, void **fsdata);
54537- int (*write_end)(struct file *, struct address_space *mapping,
54538+ int (* const write_end)(struct file *, struct address_space *mapping,
54539 loff_t pos, unsigned len, unsigned copied,
54540 struct page *page, void *fsdata);
54541
54542 /* Unfortunately this kludge is needed for FIBMAP. Don't use it */
54543- sector_t (*bmap)(struct address_space *, sector_t);
54544- void (*invalidatepage) (struct page *, unsigned long);
54545- int (*releasepage) (struct page *, gfp_t);
54546- ssize_t (*direct_IO)(int, struct kiocb *, const struct iovec *iov,
54547+ sector_t (* const bmap)(struct address_space *, sector_t);
54548+ void (* const invalidatepage) (struct page *, unsigned long);
54549+ int (* const releasepage) (struct page *, gfp_t);
54550+ ssize_t (* const direct_IO)(int, struct kiocb *, const struct iovec *iov,
54551 loff_t offset, unsigned long nr_segs);
54552- int (*get_xip_mem)(struct address_space *, pgoff_t, int,
54553+ int (* const get_xip_mem)(struct address_space *, pgoff_t, int,
54554 void **, unsigned long *);
54555 /* migrate the contents of a page to the specified target */
54556- int (*migratepage) (struct address_space *,
54557+ int (* const migratepage) (struct address_space *,
54558 struct page *, struct page *);
54559- int (*launder_page) (struct page *);
54560- int (*is_partially_uptodate) (struct page *, read_descriptor_t *,
54561+ int (* const launder_page) (struct page *);
54562+ int (* const is_partially_uptodate) (struct page *, read_descriptor_t *,
54563 unsigned long);
54564- int (*error_remove_page)(struct address_space *, struct page *);
54565+ int (* const error_remove_page)(struct address_space *, struct page *);
54566 };
54567
54568 /*
54569@@ -1030,19 +1035,19 @@ static inline int file_check_writeable(s
54570 typedef struct files_struct *fl_owner_t;
54571
54572 struct file_lock_operations {
54573- void (*fl_copy_lock)(struct file_lock *, struct file_lock *);
54574- void (*fl_release_private)(struct file_lock *);
54575+ void (* const fl_copy_lock)(struct file_lock *, struct file_lock *);
54576+ void (* const fl_release_private)(struct file_lock *);
54577 };
54578
54579 struct lock_manager_operations {
54580- int (*fl_compare_owner)(struct file_lock *, struct file_lock *);
54581- void (*fl_notify)(struct file_lock *); /* unblock callback */
54582- int (*fl_grant)(struct file_lock *, struct file_lock *, int);
54583- void (*fl_copy_lock)(struct file_lock *, struct file_lock *);
54584- void (*fl_release_private)(struct file_lock *);
54585- void (*fl_break)(struct file_lock *);
54586- int (*fl_mylease)(struct file_lock *, struct file_lock *);
54587- int (*fl_change)(struct file_lock **, int);
54588+ int (* const fl_compare_owner)(struct file_lock *, struct file_lock *);
54589+ void (* const fl_notify)(struct file_lock *); /* unblock callback */
54590+ int (* const fl_grant)(struct file_lock *, struct file_lock *, int);
54591+ void (* const fl_copy_lock)(struct file_lock *, struct file_lock *);
54592+ void (* const fl_release_private)(struct file_lock *);
54593+ void (* const fl_break)(struct file_lock *);
54594+ int (* const fl_mylease)(struct file_lock *, struct file_lock *);
54595+ int (* const fl_change)(struct file_lock **, int);
54596 };
54597
54598 struct lock_manager {
54599@@ -1441,7 +1446,7 @@ struct fiemap_extent_info {
54600 unsigned int fi_flags; /* Flags as passed from user */
54601 unsigned int fi_extents_mapped; /* Number of mapped extents */
54602 unsigned int fi_extents_max; /* Size of fiemap_extent array */
54603- struct fiemap_extent *fi_extents_start; /* Start of fiemap_extent
54604+ struct fiemap_extent __user *fi_extents_start; /* Start of fiemap_extent
54605 * array */
54606 };
54607 int fiemap_fill_next_extent(struct fiemap_extent_info *info, u64 logical,
54608@@ -1558,30 +1563,30 @@ extern ssize_t vfs_writev(struct file *,
54609 unsigned long, loff_t *);
54610
54611 struct super_operations {
54612- struct inode *(*alloc_inode)(struct super_block *sb);
54613- void (*destroy_inode)(struct inode *);
54614+ struct inode *(* const alloc_inode)(struct super_block *sb);
54615+ void (* const destroy_inode)(struct inode *);
54616
54617- void (*dirty_inode) (struct inode *);
54618- int (*write_inode) (struct inode *, int);
54619- void (*drop_inode) (struct inode *);
54620- void (*delete_inode) (struct inode *);
54621- void (*put_super) (struct super_block *);
54622- void (*write_super) (struct super_block *);
54623- int (*sync_fs)(struct super_block *sb, int wait);
54624- int (*freeze_fs) (struct super_block *);
54625- int (*unfreeze_fs) (struct super_block *);
54626- int (*statfs) (struct dentry *, struct kstatfs *);
54627- int (*remount_fs) (struct super_block *, int *, char *);
54628- void (*clear_inode) (struct inode *);
54629- void (*umount_begin) (struct super_block *);
54630+ void (* const dirty_inode) (struct inode *);
54631+ int (* const write_inode) (struct inode *, int);
54632+ void (* const drop_inode) (struct inode *);
54633+ void (* const delete_inode) (struct inode *);
54634+ void (* const put_super) (struct super_block *);
54635+ void (* const write_super) (struct super_block *);
54636+ int (* const sync_fs)(struct super_block *sb, int wait);
54637+ int (* const freeze_fs) (struct super_block *);
54638+ int (* const unfreeze_fs) (struct super_block *);
54639+ int (* const statfs) (struct dentry *, struct kstatfs *);
54640+ int (* const remount_fs) (struct super_block *, int *, char *);
54641+ void (* const clear_inode) (struct inode *);
54642+ void (* const umount_begin) (struct super_block *);
54643
54644- int (*show_options)(struct seq_file *, struct vfsmount *);
54645- int (*show_stats)(struct seq_file *, struct vfsmount *);
54646+ int (* const show_options)(struct seq_file *, struct vfsmount *);
54647+ int (* const show_stats)(struct seq_file *, struct vfsmount *);
54648 #ifdef CONFIG_QUOTA
54649- ssize_t (*quota_read)(struct super_block *, int, char *, size_t, loff_t);
54650- ssize_t (*quota_write)(struct super_block *, int, const char *, size_t, loff_t);
54651+ ssize_t (* const quota_read)(struct super_block *, int, char *, size_t, loff_t);
54652+ ssize_t (* const quota_write)(struct super_block *, int, const char *, size_t, loff_t);
54653 #endif
54654- int (*bdev_try_to_free_page)(struct super_block*, struct page*, gfp_t);
54655+ int (* const bdev_try_to_free_page)(struct super_block*, struct page*, gfp_t);
54656 };
54657
54658 /*
54659diff -urNp linux-2.6.32.41/include/linux/fs_struct.h linux-2.6.32.41/include/linux/fs_struct.h
54660--- linux-2.6.32.41/include/linux/fs_struct.h 2011-03-27 14:31:47.000000000 -0400
54661+++ linux-2.6.32.41/include/linux/fs_struct.h 2011-04-17 15:56:46.000000000 -0400
54662@@ -4,7 +4,7 @@
54663 #include <linux/path.h>
54664
54665 struct fs_struct {
54666- int users;
54667+ atomic_t users;
54668 rwlock_t lock;
54669 int umask;
54670 int in_exec;
54671diff -urNp linux-2.6.32.41/include/linux/ftrace_event.h linux-2.6.32.41/include/linux/ftrace_event.h
54672--- linux-2.6.32.41/include/linux/ftrace_event.h 2011-03-27 14:31:47.000000000 -0400
54673+++ linux-2.6.32.41/include/linux/ftrace_event.h 2011-05-04 17:56:28.000000000 -0400
54674@@ -163,7 +163,7 @@ extern int trace_define_field(struct ftr
54675 int filter_type);
54676 extern int trace_define_common_fields(struct ftrace_event_call *call);
54677
54678-#define is_signed_type(type) (((type)(-1)) < 0)
54679+#define is_signed_type(type) (((type)(-1)) < (type)1)
54680
54681 int trace_set_clr_event(const char *system, const char *event, int set);
54682
54683diff -urNp linux-2.6.32.41/include/linux/genhd.h linux-2.6.32.41/include/linux/genhd.h
54684--- linux-2.6.32.41/include/linux/genhd.h 2011-03-27 14:31:47.000000000 -0400
54685+++ linux-2.6.32.41/include/linux/genhd.h 2011-04-17 15:56:46.000000000 -0400
54686@@ -161,7 +161,7 @@ struct gendisk {
54687
54688 struct timer_rand_state *random;
54689
54690- atomic_t sync_io; /* RAID */
54691+ atomic_unchecked_t sync_io; /* RAID */
54692 struct work_struct async_notify;
54693 #ifdef CONFIG_BLK_DEV_INTEGRITY
54694 struct blk_integrity *integrity;
54695diff -urNp linux-2.6.32.41/include/linux/gracl.h linux-2.6.32.41/include/linux/gracl.h
54696--- linux-2.6.32.41/include/linux/gracl.h 1969-12-31 19:00:00.000000000 -0500
54697+++ linux-2.6.32.41/include/linux/gracl.h 2011-04-17 15:56:46.000000000 -0400
54698@@ -0,0 +1,317 @@
54699+#ifndef GR_ACL_H
54700+#define GR_ACL_H
54701+
54702+#include <linux/grdefs.h>
54703+#include <linux/resource.h>
54704+#include <linux/capability.h>
54705+#include <linux/dcache.h>
54706+#include <asm/resource.h>
54707+
54708+/* Major status information */
54709+
54710+#define GR_VERSION "grsecurity 2.2.2"
54711+#define GRSECURITY_VERSION 0x2202
54712+
54713+enum {
54714+ GR_SHUTDOWN = 0,
54715+ GR_ENABLE = 1,
54716+ GR_SPROLE = 2,
54717+ GR_RELOAD = 3,
54718+ GR_SEGVMOD = 4,
54719+ GR_STATUS = 5,
54720+ GR_UNSPROLE = 6,
54721+ GR_PASSSET = 7,
54722+ GR_SPROLEPAM = 8,
54723+};
54724+
54725+/* Password setup definitions
54726+ * kernel/grhash.c */
54727+enum {
54728+ GR_PW_LEN = 128,
54729+ GR_SALT_LEN = 16,
54730+ GR_SHA_LEN = 32,
54731+};
54732+
54733+enum {
54734+ GR_SPROLE_LEN = 64,
54735+};
54736+
54737+enum {
54738+ GR_NO_GLOB = 0,
54739+ GR_REG_GLOB,
54740+ GR_CREATE_GLOB
54741+};
54742+
54743+#define GR_NLIMITS 32
54744+
54745+/* Begin Data Structures */
54746+
54747+struct sprole_pw {
54748+ unsigned char *rolename;
54749+ unsigned char salt[GR_SALT_LEN];
54750+ unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
54751+};
54752+
54753+struct name_entry {
54754+ __u32 key;
54755+ ino_t inode;
54756+ dev_t device;
54757+ char *name;
54758+ __u16 len;
54759+ __u8 deleted;
54760+ struct name_entry *prev;
54761+ struct name_entry *next;
54762+};
54763+
54764+struct inodev_entry {
54765+ struct name_entry *nentry;
54766+ struct inodev_entry *prev;
54767+ struct inodev_entry *next;
54768+};
54769+
54770+struct acl_role_db {
54771+ struct acl_role_label **r_hash;
54772+ __u32 r_size;
54773+};
54774+
54775+struct inodev_db {
54776+ struct inodev_entry **i_hash;
54777+ __u32 i_size;
54778+};
54779+
54780+struct name_db {
54781+ struct name_entry **n_hash;
54782+ __u32 n_size;
54783+};
54784+
54785+struct crash_uid {
54786+ uid_t uid;
54787+ unsigned long expires;
54788+};
54789+
54790+struct gr_hash_struct {
54791+ void **table;
54792+ void **nametable;
54793+ void *first;
54794+ __u32 table_size;
54795+ __u32 used_size;
54796+ int type;
54797+};
54798+
54799+/* Userspace Grsecurity ACL data structures */
54800+
54801+struct acl_subject_label {
54802+ char *filename;
54803+ ino_t inode;
54804+ dev_t device;
54805+ __u32 mode;
54806+ kernel_cap_t cap_mask;
54807+ kernel_cap_t cap_lower;
54808+ kernel_cap_t cap_invert_audit;
54809+
54810+ struct rlimit res[GR_NLIMITS];
54811+ __u32 resmask;
54812+
54813+ __u8 user_trans_type;
54814+ __u8 group_trans_type;
54815+ uid_t *user_transitions;
54816+ gid_t *group_transitions;
54817+ __u16 user_trans_num;
54818+ __u16 group_trans_num;
54819+
54820+ __u32 sock_families[2];
54821+ __u32 ip_proto[8];
54822+ __u32 ip_type;
54823+ struct acl_ip_label **ips;
54824+ __u32 ip_num;
54825+ __u32 inaddr_any_override;
54826+
54827+ __u32 crashes;
54828+ unsigned long expires;
54829+
54830+ struct acl_subject_label *parent_subject;
54831+ struct gr_hash_struct *hash;
54832+ struct acl_subject_label *prev;
54833+ struct acl_subject_label *next;
54834+
54835+ struct acl_object_label **obj_hash;
54836+ __u32 obj_hash_size;
54837+ __u16 pax_flags;
54838+};
54839+
54840+struct role_allowed_ip {
54841+ __u32 addr;
54842+ __u32 netmask;
54843+
54844+ struct role_allowed_ip *prev;
54845+ struct role_allowed_ip *next;
54846+};
54847+
54848+struct role_transition {
54849+ char *rolename;
54850+
54851+ struct role_transition *prev;
54852+ struct role_transition *next;
54853+};
54854+
54855+struct acl_role_label {
54856+ char *rolename;
54857+ uid_t uidgid;
54858+ __u16 roletype;
54859+
54860+ __u16 auth_attempts;
54861+ unsigned long expires;
54862+
54863+ struct acl_subject_label *root_label;
54864+ struct gr_hash_struct *hash;
54865+
54866+ struct acl_role_label *prev;
54867+ struct acl_role_label *next;
54868+
54869+ struct role_transition *transitions;
54870+ struct role_allowed_ip *allowed_ips;
54871+ uid_t *domain_children;
54872+ __u16 domain_child_num;
54873+
54874+ struct acl_subject_label **subj_hash;
54875+ __u32 subj_hash_size;
54876+};
54877+
54878+struct user_acl_role_db {
54879+ struct acl_role_label **r_table;
54880+ __u32 num_pointers; /* Number of allocations to track */
54881+ __u32 num_roles; /* Number of roles */
54882+ __u32 num_domain_children; /* Number of domain children */
54883+ __u32 num_subjects; /* Number of subjects */
54884+ __u32 num_objects; /* Number of objects */
54885+};
54886+
54887+struct acl_object_label {
54888+ char *filename;
54889+ ino_t inode;
54890+ dev_t device;
54891+ __u32 mode;
54892+
54893+ struct acl_subject_label *nested;
54894+ struct acl_object_label *globbed;
54895+
54896+ /* next two structures not used */
54897+
54898+ struct acl_object_label *prev;
54899+ struct acl_object_label *next;
54900+};
54901+
54902+struct acl_ip_label {
54903+ char *iface;
54904+ __u32 addr;
54905+ __u32 netmask;
54906+ __u16 low, high;
54907+ __u8 mode;
54908+ __u32 type;
54909+ __u32 proto[8];
54910+
54911+ /* next two structures not used */
54912+
54913+ struct acl_ip_label *prev;
54914+ struct acl_ip_label *next;
54915+};
54916+
54917+struct gr_arg {
54918+ struct user_acl_role_db role_db;
54919+ unsigned char pw[GR_PW_LEN];
54920+ unsigned char salt[GR_SALT_LEN];
54921+ unsigned char sum[GR_SHA_LEN];
54922+ unsigned char sp_role[GR_SPROLE_LEN];
54923+ struct sprole_pw *sprole_pws;
54924+ dev_t segv_device;
54925+ ino_t segv_inode;
54926+ uid_t segv_uid;
54927+ __u16 num_sprole_pws;
54928+ __u16 mode;
54929+};
54930+
54931+struct gr_arg_wrapper {
54932+ struct gr_arg *arg;
54933+ __u32 version;
54934+ __u32 size;
54935+};
54936+
54937+struct subject_map {
54938+ struct acl_subject_label *user;
54939+ struct acl_subject_label *kernel;
54940+ struct subject_map *prev;
54941+ struct subject_map *next;
54942+};
54943+
54944+struct acl_subj_map_db {
54945+ struct subject_map **s_hash;
54946+ __u32 s_size;
54947+};
54948+
54949+/* End Data Structures Section */
54950+
54951+/* Hash functions generated by empirical testing by Brad Spengler
54952+ Makes good use of the low bits of the inode. Generally 0-1 times
54953+ in loop for successful match. 0-3 for unsuccessful match.
54954+ Shift/add algorithm with modulus of table size and an XOR*/
54955+
54956+static __inline__ unsigned int
54957+rhash(const uid_t uid, const __u16 type, const unsigned int sz)
54958+{
54959+ return ((((uid + type) << (16 + type)) ^ uid) % sz);
54960+}
54961+
54962+ static __inline__ unsigned int
54963+shash(const struct acl_subject_label *userp, const unsigned int sz)
54964+{
54965+ return ((const unsigned long)userp % sz);
54966+}
54967+
54968+static __inline__ unsigned int
54969+fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
54970+{
54971+ return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
54972+}
54973+
54974+static __inline__ unsigned int
54975+nhash(const char *name, const __u16 len, const unsigned int sz)
54976+{
54977+ return full_name_hash((const unsigned char *)name, len) % sz;
54978+}
54979+
54980+#define FOR_EACH_ROLE_START(role) \
54981+ role = role_list; \
54982+ while (role) {
54983+
54984+#define FOR_EACH_ROLE_END(role) \
54985+ role = role->prev; \
54986+ }
54987+
54988+#define FOR_EACH_SUBJECT_START(role,subj,iter) \
54989+ subj = NULL; \
54990+ iter = 0; \
54991+ while (iter < role->subj_hash_size) { \
54992+ if (subj == NULL) \
54993+ subj = role->subj_hash[iter]; \
54994+ if (subj == NULL) { \
54995+ iter++; \
54996+ continue; \
54997+ }
54998+
54999+#define FOR_EACH_SUBJECT_END(subj,iter) \
55000+ subj = subj->next; \
55001+ if (subj == NULL) \
55002+ iter++; \
55003+ }
55004+
55005+
55006+#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
55007+ subj = role->hash->first; \
55008+ while (subj != NULL) {
55009+
55010+#define FOR_EACH_NESTED_SUBJECT_END(subj) \
55011+ subj = subj->next; \
55012+ }
55013+
55014+#endif
55015+
55016diff -urNp linux-2.6.32.41/include/linux/gralloc.h linux-2.6.32.41/include/linux/gralloc.h
55017--- linux-2.6.32.41/include/linux/gralloc.h 1969-12-31 19:00:00.000000000 -0500
55018+++ linux-2.6.32.41/include/linux/gralloc.h 2011-04-17 15:56:46.000000000 -0400
55019@@ -0,0 +1,9 @@
55020+#ifndef __GRALLOC_H
55021+#define __GRALLOC_H
55022+
55023+void acl_free_all(void);
55024+int acl_alloc_stack_init(unsigned long size);
55025+void *acl_alloc(unsigned long len);
55026+void *acl_alloc_num(unsigned long num, unsigned long len);
55027+
55028+#endif
55029diff -urNp linux-2.6.32.41/include/linux/grdefs.h linux-2.6.32.41/include/linux/grdefs.h
55030--- linux-2.6.32.41/include/linux/grdefs.h 1969-12-31 19:00:00.000000000 -0500
55031+++ linux-2.6.32.41/include/linux/grdefs.h 2011-04-17 15:56:46.000000000 -0400
55032@@ -0,0 +1,139 @@
55033+#ifndef GRDEFS_H
55034+#define GRDEFS_H
55035+
55036+/* Begin grsecurity status declarations */
55037+
55038+enum {
55039+ GR_READY = 0x01,
55040+ GR_STATUS_INIT = 0x00 // disabled state
55041+};
55042+
55043+/* Begin ACL declarations */
55044+
55045+/* Role flags */
55046+
55047+enum {
55048+ GR_ROLE_USER = 0x0001,
55049+ GR_ROLE_GROUP = 0x0002,
55050+ GR_ROLE_DEFAULT = 0x0004,
55051+ GR_ROLE_SPECIAL = 0x0008,
55052+ GR_ROLE_AUTH = 0x0010,
55053+ GR_ROLE_NOPW = 0x0020,
55054+ GR_ROLE_GOD = 0x0040,
55055+ GR_ROLE_LEARN = 0x0080,
55056+ GR_ROLE_TPE = 0x0100,
55057+ GR_ROLE_DOMAIN = 0x0200,
55058+ GR_ROLE_PAM = 0x0400,
55059+ GR_ROLE_PERSIST = 0x800
55060+};
55061+
55062+/* ACL Subject and Object mode flags */
55063+enum {
55064+ GR_DELETED = 0x80000000
55065+};
55066+
55067+/* ACL Object-only mode flags */
55068+enum {
55069+ GR_READ = 0x00000001,
55070+ GR_APPEND = 0x00000002,
55071+ GR_WRITE = 0x00000004,
55072+ GR_EXEC = 0x00000008,
55073+ GR_FIND = 0x00000010,
55074+ GR_INHERIT = 0x00000020,
55075+ GR_SETID = 0x00000040,
55076+ GR_CREATE = 0x00000080,
55077+ GR_DELETE = 0x00000100,
55078+ GR_LINK = 0x00000200,
55079+ GR_AUDIT_READ = 0x00000400,
55080+ GR_AUDIT_APPEND = 0x00000800,
55081+ GR_AUDIT_WRITE = 0x00001000,
55082+ GR_AUDIT_EXEC = 0x00002000,
55083+ GR_AUDIT_FIND = 0x00004000,
55084+ GR_AUDIT_INHERIT= 0x00008000,
55085+ GR_AUDIT_SETID = 0x00010000,
55086+ GR_AUDIT_CREATE = 0x00020000,
55087+ GR_AUDIT_DELETE = 0x00040000,
55088+ GR_AUDIT_LINK = 0x00080000,
55089+ GR_PTRACERD = 0x00100000,
55090+ GR_NOPTRACE = 0x00200000,
55091+ GR_SUPPRESS = 0x00400000,
55092+ GR_NOLEARN = 0x00800000,
55093+ GR_INIT_TRANSFER= 0x01000000
55094+};
55095+
55096+#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
55097+ GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
55098+ GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
55099+
55100+/* ACL subject-only mode flags */
55101+enum {
55102+ GR_KILL = 0x00000001,
55103+ GR_VIEW = 0x00000002,
55104+ GR_PROTECTED = 0x00000004,
55105+ GR_LEARN = 0x00000008,
55106+ GR_OVERRIDE = 0x00000010,
55107+ /* just a placeholder, this mode is only used in userspace */
55108+ GR_DUMMY = 0x00000020,
55109+ GR_PROTSHM = 0x00000040,
55110+ GR_KILLPROC = 0x00000080,
55111+ GR_KILLIPPROC = 0x00000100,
55112+ /* just a placeholder, this mode is only used in userspace */
55113+ GR_NOTROJAN = 0x00000200,
55114+ GR_PROTPROCFD = 0x00000400,
55115+ GR_PROCACCT = 0x00000800,
55116+ GR_RELAXPTRACE = 0x00001000,
55117+ GR_NESTED = 0x00002000,
55118+ GR_INHERITLEARN = 0x00004000,
55119+ GR_PROCFIND = 0x00008000,
55120+ GR_POVERRIDE = 0x00010000,
55121+ GR_KERNELAUTH = 0x00020000,
55122+ GR_ATSECURE = 0x00040000
55123+};
55124+
55125+enum {
55126+ GR_PAX_ENABLE_SEGMEXEC = 0x0001,
55127+ GR_PAX_ENABLE_PAGEEXEC = 0x0002,
55128+ GR_PAX_ENABLE_MPROTECT = 0x0004,
55129+ GR_PAX_ENABLE_RANDMMAP = 0x0008,
55130+ GR_PAX_ENABLE_EMUTRAMP = 0x0010,
55131+ GR_PAX_DISABLE_SEGMEXEC = 0x0100,
55132+ GR_PAX_DISABLE_PAGEEXEC = 0x0200,
55133+ GR_PAX_DISABLE_MPROTECT = 0x0400,
55134+ GR_PAX_DISABLE_RANDMMAP = 0x0800,
55135+ GR_PAX_DISABLE_EMUTRAMP = 0x1000,
55136+};
55137+
55138+enum {
55139+ GR_ID_USER = 0x01,
55140+ GR_ID_GROUP = 0x02,
55141+};
55142+
55143+enum {
55144+ GR_ID_ALLOW = 0x01,
55145+ GR_ID_DENY = 0x02,
55146+};
55147+
55148+#define GR_CRASH_RES 31
55149+#define GR_UIDTABLE_MAX 500
55150+
55151+/* begin resource learning section */
55152+enum {
55153+ GR_RLIM_CPU_BUMP = 60,
55154+ GR_RLIM_FSIZE_BUMP = 50000,
55155+ GR_RLIM_DATA_BUMP = 10000,
55156+ GR_RLIM_STACK_BUMP = 1000,
55157+ GR_RLIM_CORE_BUMP = 10000,
55158+ GR_RLIM_RSS_BUMP = 500000,
55159+ GR_RLIM_NPROC_BUMP = 1,
55160+ GR_RLIM_NOFILE_BUMP = 5,
55161+ GR_RLIM_MEMLOCK_BUMP = 50000,
55162+ GR_RLIM_AS_BUMP = 500000,
55163+ GR_RLIM_LOCKS_BUMP = 2,
55164+ GR_RLIM_SIGPENDING_BUMP = 5,
55165+ GR_RLIM_MSGQUEUE_BUMP = 10000,
55166+ GR_RLIM_NICE_BUMP = 1,
55167+ GR_RLIM_RTPRIO_BUMP = 1,
55168+ GR_RLIM_RTTIME_BUMP = 1000000
55169+};
55170+
55171+#endif
55172diff -urNp linux-2.6.32.41/include/linux/grinternal.h linux-2.6.32.41/include/linux/grinternal.h
55173--- linux-2.6.32.41/include/linux/grinternal.h 1969-12-31 19:00:00.000000000 -0500
55174+++ linux-2.6.32.41/include/linux/grinternal.h 2011-04-17 15:56:46.000000000 -0400
55175@@ -0,0 +1,218 @@
55176+#ifndef __GRINTERNAL_H
55177+#define __GRINTERNAL_H
55178+
55179+#ifdef CONFIG_GRKERNSEC
55180+
55181+#include <linux/fs.h>
55182+#include <linux/mnt_namespace.h>
55183+#include <linux/nsproxy.h>
55184+#include <linux/gracl.h>
55185+#include <linux/grdefs.h>
55186+#include <linux/grmsg.h>
55187+
55188+void gr_add_learn_entry(const char *fmt, ...)
55189+ __attribute__ ((format (printf, 1, 2)));
55190+__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
55191+ const struct vfsmount *mnt);
55192+__u32 gr_check_create(const struct dentry *new_dentry,
55193+ const struct dentry *parent,
55194+ const struct vfsmount *mnt, const __u32 mode);
55195+int gr_check_protected_task(const struct task_struct *task);
55196+__u32 to_gr_audit(const __u32 reqmode);
55197+int gr_set_acls(const int type);
55198+int gr_apply_subject_to_task(struct task_struct *task);
55199+int gr_acl_is_enabled(void);
55200+char gr_roletype_to_char(void);
55201+
55202+void gr_handle_alertkill(struct task_struct *task);
55203+char *gr_to_filename(const struct dentry *dentry,
55204+ const struct vfsmount *mnt);
55205+char *gr_to_filename1(const struct dentry *dentry,
55206+ const struct vfsmount *mnt);
55207+char *gr_to_filename2(const struct dentry *dentry,
55208+ const struct vfsmount *mnt);
55209+char *gr_to_filename3(const struct dentry *dentry,
55210+ const struct vfsmount *mnt);
55211+
55212+extern int grsec_enable_harden_ptrace;
55213+extern int grsec_enable_link;
55214+extern int grsec_enable_fifo;
55215+extern int grsec_enable_execve;
55216+extern int grsec_enable_shm;
55217+extern int grsec_enable_execlog;
55218+extern int grsec_enable_signal;
55219+extern int grsec_enable_audit_ptrace;
55220+extern int grsec_enable_forkfail;
55221+extern int grsec_enable_time;
55222+extern int grsec_enable_rofs;
55223+extern int grsec_enable_chroot_shmat;
55224+extern int grsec_enable_chroot_findtask;
55225+extern int grsec_enable_chroot_mount;
55226+extern int grsec_enable_chroot_double;
55227+extern int grsec_enable_chroot_pivot;
55228+extern int grsec_enable_chroot_chdir;
55229+extern int grsec_enable_chroot_chmod;
55230+extern int grsec_enable_chroot_mknod;
55231+extern int grsec_enable_chroot_fchdir;
55232+extern int grsec_enable_chroot_nice;
55233+extern int grsec_enable_chroot_execlog;
55234+extern int grsec_enable_chroot_caps;
55235+extern int grsec_enable_chroot_sysctl;
55236+extern int grsec_enable_chroot_unix;
55237+extern int grsec_enable_tpe;
55238+extern int grsec_tpe_gid;
55239+extern int grsec_enable_tpe_all;
55240+extern int grsec_enable_tpe_invert;
55241+extern int grsec_enable_socket_all;
55242+extern int grsec_socket_all_gid;
55243+extern int grsec_enable_socket_client;
55244+extern int grsec_socket_client_gid;
55245+extern int grsec_enable_socket_server;
55246+extern int grsec_socket_server_gid;
55247+extern int grsec_audit_gid;
55248+extern int grsec_enable_group;
55249+extern int grsec_enable_audit_textrel;
55250+extern int grsec_enable_log_rwxmaps;
55251+extern int grsec_enable_mount;
55252+extern int grsec_enable_chdir;
55253+extern int grsec_resource_logging;
55254+extern int grsec_enable_blackhole;
55255+extern int grsec_lastack_retries;
55256+extern int grsec_lock;
55257+
55258+extern spinlock_t grsec_alert_lock;
55259+extern unsigned long grsec_alert_wtime;
55260+extern unsigned long grsec_alert_fyet;
55261+
55262+extern spinlock_t grsec_audit_lock;
55263+
55264+extern rwlock_t grsec_exec_file_lock;
55265+
55266+#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
55267+ gr_to_filename2((tsk)->exec_file->f_path.dentry, \
55268+ (tsk)->exec_file->f_vfsmnt) : "/")
55269+
55270+#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
55271+ gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
55272+ (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
55273+
55274+#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
55275+ gr_to_filename((tsk)->exec_file->f_path.dentry, \
55276+ (tsk)->exec_file->f_vfsmnt) : "/")
55277+
55278+#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
55279+ gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
55280+ (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
55281+
55282+#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
55283+
55284+#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
55285+
55286+#define DEFAULTSECARGS(task, cred, pcred) gr_task_fullpath(task), (task)->comm, \
55287+ (task)->pid, (cred)->uid, \
55288+ (cred)->euid, (cred)->gid, (cred)->egid, \
55289+ gr_parent_task_fullpath(task), \
55290+ (task)->real_parent->comm, (task)->real_parent->pid, \
55291+ (pcred)->uid, (pcred)->euid, \
55292+ (pcred)->gid, (pcred)->egid
55293+
55294+#define GR_CHROOT_CAPS {{ \
55295+ CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
55296+ CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
55297+ CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
55298+ CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
55299+ CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
55300+ CAP_TO_MASK(CAP_IPC_OWNER) , 0 }}
55301+
55302+#define security_learn(normal_msg,args...) \
55303+({ \
55304+ read_lock(&grsec_exec_file_lock); \
55305+ gr_add_learn_entry(normal_msg "\n", ## args); \
55306+ read_unlock(&grsec_exec_file_lock); \
55307+})
55308+
55309+enum {
55310+ GR_DO_AUDIT,
55311+ GR_DONT_AUDIT,
55312+ GR_DONT_AUDIT_GOOD
55313+};
55314+
55315+enum {
55316+ GR_TTYSNIFF,
55317+ GR_RBAC,
55318+ GR_RBAC_STR,
55319+ GR_STR_RBAC,
55320+ GR_RBAC_MODE2,
55321+ GR_RBAC_MODE3,
55322+ GR_FILENAME,
55323+ GR_SYSCTL_HIDDEN,
55324+ GR_NOARGS,
55325+ GR_ONE_INT,
55326+ GR_ONE_INT_TWO_STR,
55327+ GR_ONE_STR,
55328+ GR_STR_INT,
55329+ GR_TWO_STR_INT,
55330+ GR_TWO_INT,
55331+ GR_TWO_U64,
55332+ GR_THREE_INT,
55333+ GR_FIVE_INT_TWO_STR,
55334+ GR_TWO_STR,
55335+ GR_THREE_STR,
55336+ GR_FOUR_STR,
55337+ GR_STR_FILENAME,
55338+ GR_FILENAME_STR,
55339+ GR_FILENAME_TWO_INT,
55340+ GR_FILENAME_TWO_INT_STR,
55341+ GR_TEXTREL,
55342+ GR_PTRACE,
55343+ GR_RESOURCE,
55344+ GR_CAP,
55345+ GR_SIG,
55346+ GR_SIG2,
55347+ GR_CRASH1,
55348+ GR_CRASH2,
55349+ GR_PSACCT,
55350+ GR_RWXMAP
55351+};
55352+
55353+#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
55354+#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
55355+#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
55356+#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
55357+#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
55358+#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
55359+#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)
55360+#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
55361+#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
55362+#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
55363+#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
55364+#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
55365+#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
55366+#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
55367+#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
55368+#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
55369+#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)
55370+#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
55371+#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
55372+#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
55373+#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
55374+#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
55375+#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
55376+#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
55377+#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)
55378+#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
55379+#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
55380+#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
55381+#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
55382+#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
55383+#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
55384+#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
55385+#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
55386+#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)
55387+#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
55388+
55389+void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
55390+
55391+#endif
55392+
55393+#endif
55394diff -urNp linux-2.6.32.41/include/linux/grmsg.h linux-2.6.32.41/include/linux/grmsg.h
55395--- linux-2.6.32.41/include/linux/grmsg.h 1969-12-31 19:00:00.000000000 -0500
55396+++ linux-2.6.32.41/include/linux/grmsg.h 2011-04-17 15:56:46.000000000 -0400
55397@@ -0,0 +1,108 @@
55398+#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"
55399+#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"
55400+#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
55401+#define GR_STOPMOD_MSG "denied modification of module state by "
55402+#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
55403+#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
55404+#define GR_IOPERM_MSG "denied use of ioperm() by "
55405+#define GR_IOPL_MSG "denied use of iopl() by "
55406+#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
55407+#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
55408+#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
55409+#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
55410+#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
55411+#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"
55412+#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"
55413+#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
55414+#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
55415+#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
55416+#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
55417+#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
55418+#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
55419+#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
55420+#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
55421+#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
55422+#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
55423+#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
55424+#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
55425+#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
55426+#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
55427+#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
55428+#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
55429+#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
55430+#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
55431+#define GR_NPROC_MSG "denied overstep of process limit by "
55432+#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
55433+#define GR_EXEC_TPE_MSG "denied untrusted exec of %.950s by "
55434+#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
55435+#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
55436+#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
55437+#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
55438+#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
55439+#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
55440+#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
55441+#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
55442+#define GR_FCHMOD_ACL_MSG "%s fchmod of %.950s by "
55443+#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
55444+#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
55445+#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
55446+#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
55447+#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
55448+#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
55449+#define GR_INITF_ACL_MSG "init_variables() failed %s by "
55450+#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"
55451+#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbaged by "
55452+#define GR_SHUTS_ACL_MSG "shutdown auth success for "
55453+#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
55454+#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
55455+#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
55456+#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
55457+#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
55458+#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
55459+#define GR_ENABLEF_ACL_MSG "unable to load %s for "
55460+#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
55461+#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
55462+#define GR_RELOADF_ACL_MSG "failed reload of %s for "
55463+#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
55464+#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
55465+#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
55466+#define GR_SPROLEF_ACL_MSG "special role %s failure for "
55467+#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
55468+#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
55469+#define GR_INVMODE_ACL_MSG "invalid mode %d by "
55470+#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
55471+#define GR_FAILFORK_MSG "failed fork with errno %s by "
55472+#define GR_NICE_CHROOT_MSG "denied priority change by "
55473+#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
55474+#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
55475+#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
55476+#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
55477+#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
55478+#define GR_TIME_MSG "time set by "
55479+#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
55480+#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
55481+#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
55482+#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
55483+#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
55484+#define GR_BIND_MSG "denied bind() by "
55485+#define GR_CONNECT_MSG "denied connect() by "
55486+#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
55487+#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
55488+#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"
55489+#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
55490+#define GR_CAP_ACL_MSG "use of %s denied for "
55491+#define GR_CAP_ACL_MSG2 "use of %s permitted for "
55492+#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
55493+#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
55494+#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
55495+#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
55496+#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
55497+#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
55498+#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
55499+#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
55500+#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
55501+#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
55502+#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
55503+#define GR_VM86_MSG "denied use of vm86 by "
55504+#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
55505+#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
55506diff -urNp linux-2.6.32.41/include/linux/grsecurity.h linux-2.6.32.41/include/linux/grsecurity.h
55507--- linux-2.6.32.41/include/linux/grsecurity.h 1969-12-31 19:00:00.000000000 -0500
55508+++ linux-2.6.32.41/include/linux/grsecurity.h 2011-04-17 15:56:46.000000000 -0400
55509@@ -0,0 +1,212 @@
55510+#ifndef GR_SECURITY_H
55511+#define GR_SECURITY_H
55512+#include <linux/fs.h>
55513+#include <linux/fs_struct.h>
55514+#include <linux/binfmts.h>
55515+#include <linux/gracl.h>
55516+#include <linux/compat.h>
55517+
55518+/* notify of brain-dead configs */
55519+#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
55520+#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
55521+#endif
55522+#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_EI_PAX) && !defined(CONFIG_PAX_PT_PAX_FLAGS)
55523+#error "CONFIG_PAX_NOEXEC enabled, but neither CONFIG_PAX_EI_PAX nor CONFIG_PAX_PT_PAX_FLAGS are enabled."
55524+#endif
55525+#if defined(CONFIG_PAX_ASLR) && (defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)) && !defined(CONFIG_PAX_EI_PAX) && !defined(CONFIG_PAX_PT_PAX_FLAGS)
55526+#error "CONFIG_PAX_ASLR enabled, but neither CONFIG_PAX_EI_PAX nor CONFIG_PAX_PT_PAX_FLAGS are enabled."
55527+#endif
55528+#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
55529+#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
55530+#endif
55531+#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
55532+#error "CONFIG_PAX enabled, but no PaX options are enabled."
55533+#endif
55534+
55535+void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags);
55536+void gr_handle_brute_check(void);
55537+void gr_handle_kernel_exploit(void);
55538+int gr_process_user_ban(void);
55539+
55540+char gr_roletype_to_char(void);
55541+
55542+int gr_acl_enable_at_secure(void);
55543+
55544+int gr_check_user_change(int real, int effective, int fs);
55545+int gr_check_group_change(int real, int effective, int fs);
55546+
55547+void gr_del_task_from_ip_table(struct task_struct *p);
55548+
55549+int gr_pid_is_chrooted(struct task_struct *p);
55550+int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
55551+int gr_handle_chroot_nice(void);
55552+int gr_handle_chroot_sysctl(const int op);
55553+int gr_handle_chroot_setpriority(struct task_struct *p,
55554+ const int niceval);
55555+int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
55556+int gr_handle_chroot_chroot(const struct dentry *dentry,
55557+ const struct vfsmount *mnt);
55558+int gr_handle_chroot_caps(struct path *path);
55559+void gr_handle_chroot_chdir(struct path *path);
55560+int gr_handle_chroot_chmod(const struct dentry *dentry,
55561+ const struct vfsmount *mnt, const int mode);
55562+int gr_handle_chroot_mknod(const struct dentry *dentry,
55563+ const struct vfsmount *mnt, const int mode);
55564+int gr_handle_chroot_mount(const struct dentry *dentry,
55565+ const struct vfsmount *mnt,
55566+ const char *dev_name);
55567+int gr_handle_chroot_pivot(void);
55568+int gr_handle_chroot_unix(const pid_t pid);
55569+
55570+int gr_handle_rawio(const struct inode *inode);
55571+int gr_handle_nproc(void);
55572+
55573+void gr_handle_ioperm(void);
55574+void gr_handle_iopl(void);
55575+
55576+int gr_tpe_allow(const struct file *file);
55577+
55578+void gr_set_chroot_entries(struct task_struct *task, struct path *path);
55579+void gr_clear_chroot_entries(struct task_struct *task);
55580+
55581+void gr_log_forkfail(const int retval);
55582+void gr_log_timechange(void);
55583+void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
55584+void gr_log_chdir(const struct dentry *dentry,
55585+ const struct vfsmount *mnt);
55586+void gr_log_chroot_exec(const struct dentry *dentry,
55587+ const struct vfsmount *mnt);
55588+void gr_handle_exec_args(struct linux_binprm *bprm, const char __user *const __user *argv);
55589+#ifdef CONFIG_COMPAT
55590+void gr_handle_exec_args_compat(struct linux_binprm *bprm, compat_uptr_t __user *argv);
55591+#endif
55592+void gr_log_remount(const char *devname, const int retval);
55593+void gr_log_unmount(const char *devname, const int retval);
55594+void gr_log_mount(const char *from, const char *to, const int retval);
55595+void gr_log_textrel(struct vm_area_struct *vma);
55596+void gr_log_rwxmmap(struct file *file);
55597+void gr_log_rwxmprotect(struct file *file);
55598+
55599+int gr_handle_follow_link(const struct inode *parent,
55600+ const struct inode *inode,
55601+ const struct dentry *dentry,
55602+ const struct vfsmount *mnt);
55603+int gr_handle_fifo(const struct dentry *dentry,
55604+ const struct vfsmount *mnt,
55605+ const struct dentry *dir, const int flag,
55606+ const int acc_mode);
55607+int gr_handle_hardlink(const struct dentry *dentry,
55608+ const struct vfsmount *mnt,
55609+ struct inode *inode,
55610+ const int mode, const char *to);
55611+
55612+int gr_is_capable(const int cap);
55613+int gr_is_capable_nolog(const int cap);
55614+void gr_learn_resource(const struct task_struct *task, const int limit,
55615+ const unsigned long wanted, const int gt);
55616+void gr_copy_label(struct task_struct *tsk);
55617+void gr_handle_crash(struct task_struct *task, const int sig);
55618+int gr_handle_signal(const struct task_struct *p, const int sig);
55619+int gr_check_crash_uid(const uid_t uid);
55620+int gr_check_protected_task(const struct task_struct *task);
55621+int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
55622+int gr_acl_handle_mmap(const struct file *file,
55623+ const unsigned long prot);
55624+int gr_acl_handle_mprotect(const struct file *file,
55625+ const unsigned long prot);
55626+int gr_check_hidden_task(const struct task_struct *tsk);
55627+__u32 gr_acl_handle_truncate(const struct dentry *dentry,
55628+ const struct vfsmount *mnt);
55629+__u32 gr_acl_handle_utime(const struct dentry *dentry,
55630+ const struct vfsmount *mnt);
55631+__u32 gr_acl_handle_access(const struct dentry *dentry,
55632+ const struct vfsmount *mnt, const int fmode);
55633+__u32 gr_acl_handle_fchmod(const struct dentry *dentry,
55634+ const struct vfsmount *mnt, mode_t mode);
55635+__u32 gr_acl_handle_chmod(const struct dentry *dentry,
55636+ const struct vfsmount *mnt, mode_t mode);
55637+__u32 gr_acl_handle_chown(const struct dentry *dentry,
55638+ const struct vfsmount *mnt);
55639+__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
55640+ const struct vfsmount *mnt);
55641+int gr_handle_ptrace(struct task_struct *task, const long request);
55642+int gr_handle_proc_ptrace(struct task_struct *task);
55643+__u32 gr_acl_handle_execve(const struct dentry *dentry,
55644+ const struct vfsmount *mnt);
55645+int gr_check_crash_exec(const struct file *filp);
55646+int gr_acl_is_enabled(void);
55647+void gr_set_kernel_label(struct task_struct *task);
55648+void gr_set_role_label(struct task_struct *task, const uid_t uid,
55649+ const gid_t gid);
55650+int gr_set_proc_label(const struct dentry *dentry,
55651+ const struct vfsmount *mnt,
55652+ const int unsafe_share);
55653+__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
55654+ const struct vfsmount *mnt);
55655+__u32 gr_acl_handle_open(const struct dentry *dentry,
55656+ const struct vfsmount *mnt, const int fmode);
55657+__u32 gr_acl_handle_creat(const struct dentry *dentry,
55658+ const struct dentry *p_dentry,
55659+ const struct vfsmount *p_mnt, const int fmode,
55660+ const int imode);
55661+void gr_handle_create(const struct dentry *dentry,
55662+ const struct vfsmount *mnt);
55663+__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
55664+ const struct dentry *parent_dentry,
55665+ const struct vfsmount *parent_mnt,
55666+ const int mode);
55667+__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
55668+ const struct dentry *parent_dentry,
55669+ const struct vfsmount *parent_mnt);
55670+__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
55671+ const struct vfsmount *mnt);
55672+void gr_handle_delete(const ino_t ino, const dev_t dev);
55673+__u32 gr_acl_handle_unlink(const struct dentry *dentry,
55674+ const struct vfsmount *mnt);
55675+__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
55676+ const struct dentry *parent_dentry,
55677+ const struct vfsmount *parent_mnt,
55678+ const char *from);
55679+__u32 gr_acl_handle_link(const struct dentry *new_dentry,
55680+ const struct dentry *parent_dentry,
55681+ const struct vfsmount *parent_mnt,
55682+ const struct dentry *old_dentry,
55683+ const struct vfsmount *old_mnt, const char *to);
55684+int gr_acl_handle_rename(struct dentry *new_dentry,
55685+ struct dentry *parent_dentry,
55686+ const struct vfsmount *parent_mnt,
55687+ struct dentry *old_dentry,
55688+ struct inode *old_parent_inode,
55689+ struct vfsmount *old_mnt, const char *newname);
55690+void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
55691+ struct dentry *old_dentry,
55692+ struct dentry *new_dentry,
55693+ struct vfsmount *mnt, const __u8 replace);
55694+__u32 gr_check_link(const struct dentry *new_dentry,
55695+ const struct dentry *parent_dentry,
55696+ const struct vfsmount *parent_mnt,
55697+ const struct dentry *old_dentry,
55698+ const struct vfsmount *old_mnt);
55699+int gr_acl_handle_filldir(const struct file *file, const char *name,
55700+ const unsigned int namelen, const ino_t ino);
55701+
55702+__u32 gr_acl_handle_unix(const struct dentry *dentry,
55703+ const struct vfsmount *mnt);
55704+void gr_acl_handle_exit(void);
55705+void gr_acl_handle_psacct(struct task_struct *task, const long code);
55706+int gr_acl_handle_procpidmem(const struct task_struct *task);
55707+int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
55708+int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
55709+void gr_audit_ptrace(struct task_struct *task);
55710+dev_t gr_get_dev_from_dentry(struct dentry *dentry);
55711+
55712+#ifdef CONFIG_GRKERNSEC
55713+void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
55714+void gr_handle_vm86(void);
55715+void gr_handle_mem_readwrite(u64 from, u64 to);
55716+
55717+extern int grsec_enable_dmesg;
55718+extern int grsec_disable_privio;
55719+#endif
55720+
55721+#endif
55722diff -urNp linux-2.6.32.41/include/linux/hdpu_features.h linux-2.6.32.41/include/linux/hdpu_features.h
55723--- linux-2.6.32.41/include/linux/hdpu_features.h 2011-03-27 14:31:47.000000000 -0400
55724+++ linux-2.6.32.41/include/linux/hdpu_features.h 2011-04-17 15:56:46.000000000 -0400
55725@@ -3,7 +3,7 @@
55726 struct cpustate_t {
55727 spinlock_t lock;
55728 int excl;
55729- int open_count;
55730+ atomic_t open_count;
55731 unsigned char cached_val;
55732 int inited;
55733 unsigned long *set_addr;
55734diff -urNp linux-2.6.32.41/include/linux/highmem.h linux-2.6.32.41/include/linux/highmem.h
55735--- linux-2.6.32.41/include/linux/highmem.h 2011-03-27 14:31:47.000000000 -0400
55736+++ linux-2.6.32.41/include/linux/highmem.h 2011-04-17 15:56:46.000000000 -0400
55737@@ -137,6 +137,18 @@ static inline void clear_highpage(struct
55738 kunmap_atomic(kaddr, KM_USER0);
55739 }
55740
55741+static inline void sanitize_highpage(struct page *page)
55742+{
55743+ void *kaddr;
55744+ unsigned long flags;
55745+
55746+ local_irq_save(flags);
55747+ kaddr = kmap_atomic(page, KM_CLEARPAGE);
55748+ clear_page(kaddr);
55749+ kunmap_atomic(kaddr, KM_CLEARPAGE);
55750+ local_irq_restore(flags);
55751+}
55752+
55753 static inline void zero_user_segments(struct page *page,
55754 unsigned start1, unsigned end1,
55755 unsigned start2, unsigned end2)
55756diff -urNp linux-2.6.32.41/include/linux/i2o.h linux-2.6.32.41/include/linux/i2o.h
55757--- linux-2.6.32.41/include/linux/i2o.h 2011-03-27 14:31:47.000000000 -0400
55758+++ linux-2.6.32.41/include/linux/i2o.h 2011-05-04 17:56:28.000000000 -0400
55759@@ -564,7 +564,7 @@ struct i2o_controller {
55760 struct i2o_device *exec; /* Executive */
55761 #if BITS_PER_LONG == 64
55762 spinlock_t context_list_lock; /* lock for context_list */
55763- atomic_t context_list_counter; /* needed for unique contexts */
55764+ atomic_unchecked_t context_list_counter; /* needed for unique contexts */
55765 struct list_head context_list; /* list of context id's
55766 and pointers */
55767 #endif
55768diff -urNp linux-2.6.32.41/include/linux/init_task.h linux-2.6.32.41/include/linux/init_task.h
55769--- linux-2.6.32.41/include/linux/init_task.h 2011-03-27 14:31:47.000000000 -0400
55770+++ linux-2.6.32.41/include/linux/init_task.h 2011-05-18 20:44:59.000000000 -0400
55771@@ -83,6 +83,12 @@ extern struct group_info init_groups;
55772 #define INIT_IDS
55773 #endif
55774
55775+#ifdef CONFIG_X86
55776+#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
55777+#else
55778+#define INIT_TASK_THREAD_INFO
55779+#endif
55780+
55781 #ifdef CONFIG_SECURITY_FILE_CAPABILITIES
55782 /*
55783 * Because of the reduced scope of CAP_SETPCAP when filesystem
55784@@ -156,6 +162,7 @@ extern struct cred init_cred;
55785 __MUTEX_INITIALIZER(tsk.cred_guard_mutex), \
55786 .comm = "swapper", \
55787 .thread = INIT_THREAD, \
55788+ INIT_TASK_THREAD_INFO \
55789 .fs = &init_fs, \
55790 .files = &init_files, \
55791 .signal = &init_signals, \
55792diff -urNp linux-2.6.32.41/include/linux/interrupt.h linux-2.6.32.41/include/linux/interrupt.h
55793--- linux-2.6.32.41/include/linux/interrupt.h 2011-03-27 14:31:47.000000000 -0400
55794+++ linux-2.6.32.41/include/linux/interrupt.h 2011-04-17 15:56:46.000000000 -0400
55795@@ -362,7 +362,7 @@ enum
55796 /* map softirq index to softirq name. update 'softirq_to_name' in
55797 * kernel/softirq.c when adding a new softirq.
55798 */
55799-extern char *softirq_to_name[NR_SOFTIRQS];
55800+extern const char * const softirq_to_name[NR_SOFTIRQS];
55801
55802 /* softirq mask and active fields moved to irq_cpustat_t in
55803 * asm/hardirq.h to get better cache usage. KAO
55804@@ -370,12 +370,12 @@ extern char *softirq_to_name[NR_SOFTIRQS
55805
55806 struct softirq_action
55807 {
55808- void (*action)(struct softirq_action *);
55809+ void (*action)(void);
55810 };
55811
55812 asmlinkage void do_softirq(void);
55813 asmlinkage void __do_softirq(void);
55814-extern void open_softirq(int nr, void (*action)(struct softirq_action *));
55815+extern void open_softirq(int nr, void (*action)(void));
55816 extern void softirq_init(void);
55817 #define __raise_softirq_irqoff(nr) do { or_softirq_pending(1UL << (nr)); } while (0)
55818 extern void raise_softirq_irqoff(unsigned int nr);
55819diff -urNp linux-2.6.32.41/include/linux/irq.h linux-2.6.32.41/include/linux/irq.h
55820--- linux-2.6.32.41/include/linux/irq.h 2011-03-27 14:31:47.000000000 -0400
55821+++ linux-2.6.32.41/include/linux/irq.h 2011-04-17 15:56:46.000000000 -0400
55822@@ -438,12 +438,12 @@ extern int set_irq_msi(unsigned int irq,
55823 static inline bool alloc_desc_masks(struct irq_desc *desc, int node,
55824 bool boot)
55825 {
55826+#ifdef CONFIG_CPUMASK_OFFSTACK
55827 gfp_t gfp = GFP_ATOMIC;
55828
55829 if (boot)
55830 gfp = GFP_NOWAIT;
55831
55832-#ifdef CONFIG_CPUMASK_OFFSTACK
55833 if (!alloc_cpumask_var_node(&desc->affinity, gfp, node))
55834 return false;
55835
55836diff -urNp linux-2.6.32.41/include/linux/kallsyms.h linux-2.6.32.41/include/linux/kallsyms.h
55837--- linux-2.6.32.41/include/linux/kallsyms.h 2011-03-27 14:31:47.000000000 -0400
55838+++ linux-2.6.32.41/include/linux/kallsyms.h 2011-04-17 15:56:46.000000000 -0400
55839@@ -15,7 +15,8 @@
55840
55841 struct module;
55842
55843-#ifdef CONFIG_KALLSYMS
55844+#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
55845+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
55846 /* Lookup the address for a symbol. Returns 0 if not found. */
55847 unsigned long kallsyms_lookup_name(const char *name);
55848
55849@@ -92,6 +93,15 @@ static inline int lookup_symbol_attrs(un
55850 /* Stupid that this does nothing, but I didn't create this mess. */
55851 #define __print_symbol(fmt, addr)
55852 #endif /*CONFIG_KALLSYMS*/
55853+#else /* when included by kallsyms.c, vsnprintf.c, or
55854+ arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
55855+extern void __print_symbol(const char *fmt, unsigned long address);
55856+extern int sprint_symbol(char *buffer, unsigned long address);
55857+const char *kallsyms_lookup(unsigned long addr,
55858+ unsigned long *symbolsize,
55859+ unsigned long *offset,
55860+ char **modname, char *namebuf);
55861+#endif
55862
55863 /* This macro allows us to keep printk typechecking */
55864 static void __check_printsym_format(const char *fmt, ...)
55865diff -urNp linux-2.6.32.41/include/linux/kgdb.h linux-2.6.32.41/include/linux/kgdb.h
55866--- linux-2.6.32.41/include/linux/kgdb.h 2011-03-27 14:31:47.000000000 -0400
55867+++ linux-2.6.32.41/include/linux/kgdb.h 2011-05-04 17:56:20.000000000 -0400
55868@@ -74,8 +74,8 @@ void kgdb_breakpoint(void);
55869
55870 extern int kgdb_connected;
55871
55872-extern atomic_t kgdb_setting_breakpoint;
55873-extern atomic_t kgdb_cpu_doing_single_step;
55874+extern atomic_unchecked_t kgdb_setting_breakpoint;
55875+extern atomic_unchecked_t kgdb_cpu_doing_single_step;
55876
55877 extern struct task_struct *kgdb_usethread;
55878 extern struct task_struct *kgdb_contthread;
55879@@ -251,20 +251,20 @@ struct kgdb_arch {
55880 */
55881 struct kgdb_io {
55882 const char *name;
55883- int (*read_char) (void);
55884- void (*write_char) (u8);
55885- void (*flush) (void);
55886- int (*init) (void);
55887- void (*pre_exception) (void);
55888- void (*post_exception) (void);
55889+ int (* const read_char) (void);
55890+ void (* const write_char) (u8);
55891+ void (* const flush) (void);
55892+ int (* const init) (void);
55893+ void (* const pre_exception) (void);
55894+ void (* const post_exception) (void);
55895 };
55896
55897-extern struct kgdb_arch arch_kgdb_ops;
55898+extern const struct kgdb_arch arch_kgdb_ops;
55899
55900 extern unsigned long __weak kgdb_arch_pc(int exception, struct pt_regs *regs);
55901
55902-extern int kgdb_register_io_module(struct kgdb_io *local_kgdb_io_ops);
55903-extern void kgdb_unregister_io_module(struct kgdb_io *local_kgdb_io_ops);
55904+extern int kgdb_register_io_module(const struct kgdb_io *local_kgdb_io_ops);
55905+extern void kgdb_unregister_io_module(const struct kgdb_io *local_kgdb_io_ops);
55906
55907 extern int kgdb_hex2long(char **ptr, unsigned long *long_val);
55908 extern int kgdb_mem2hex(char *mem, char *buf, int count);
55909diff -urNp linux-2.6.32.41/include/linux/kmod.h linux-2.6.32.41/include/linux/kmod.h
55910--- linux-2.6.32.41/include/linux/kmod.h 2011-03-27 14:31:47.000000000 -0400
55911+++ linux-2.6.32.41/include/linux/kmod.h 2011-04-17 15:56:46.000000000 -0400
55912@@ -31,6 +31,8 @@
55913 * usually useless though. */
55914 extern int __request_module(bool wait, const char *name, ...) \
55915 __attribute__((format(printf, 2, 3)));
55916+extern int ___request_module(bool wait, char *param_name, const char *name, ...) \
55917+ __attribute__((format(printf, 3, 4)));
55918 #define request_module(mod...) __request_module(true, mod)
55919 #define request_module_nowait(mod...) __request_module(false, mod)
55920 #define try_then_request_module(x, mod...) \
55921diff -urNp linux-2.6.32.41/include/linux/kobject.h linux-2.6.32.41/include/linux/kobject.h
55922--- linux-2.6.32.41/include/linux/kobject.h 2011-03-27 14:31:47.000000000 -0400
55923+++ linux-2.6.32.41/include/linux/kobject.h 2011-04-17 15:56:46.000000000 -0400
55924@@ -106,7 +106,7 @@ extern char *kobject_get_path(struct kob
55925
55926 struct kobj_type {
55927 void (*release)(struct kobject *kobj);
55928- struct sysfs_ops *sysfs_ops;
55929+ const struct sysfs_ops *sysfs_ops;
55930 struct attribute **default_attrs;
55931 };
55932
55933@@ -118,9 +118,9 @@ struct kobj_uevent_env {
55934 };
55935
55936 struct kset_uevent_ops {
55937- int (*filter)(struct kset *kset, struct kobject *kobj);
55938- const char *(*name)(struct kset *kset, struct kobject *kobj);
55939- int (*uevent)(struct kset *kset, struct kobject *kobj,
55940+ int (* const filter)(struct kset *kset, struct kobject *kobj);
55941+ const char *(* const name)(struct kset *kset, struct kobject *kobj);
55942+ int (* const uevent)(struct kset *kset, struct kobject *kobj,
55943 struct kobj_uevent_env *env);
55944 };
55945
55946@@ -132,7 +132,7 @@ struct kobj_attribute {
55947 const char *buf, size_t count);
55948 };
55949
55950-extern struct sysfs_ops kobj_sysfs_ops;
55951+extern const struct sysfs_ops kobj_sysfs_ops;
55952
55953 /**
55954 * struct kset - a set of kobjects of a specific type, belonging to a specific subsystem.
55955@@ -155,14 +155,14 @@ struct kset {
55956 struct list_head list;
55957 spinlock_t list_lock;
55958 struct kobject kobj;
55959- struct kset_uevent_ops *uevent_ops;
55960+ const struct kset_uevent_ops *uevent_ops;
55961 };
55962
55963 extern void kset_init(struct kset *kset);
55964 extern int __must_check kset_register(struct kset *kset);
55965 extern void kset_unregister(struct kset *kset);
55966 extern struct kset * __must_check kset_create_and_add(const char *name,
55967- struct kset_uevent_ops *u,
55968+ const struct kset_uevent_ops *u,
55969 struct kobject *parent_kobj);
55970
55971 static inline struct kset *to_kset(struct kobject *kobj)
55972diff -urNp linux-2.6.32.41/include/linux/kvm_host.h linux-2.6.32.41/include/linux/kvm_host.h
55973--- linux-2.6.32.41/include/linux/kvm_host.h 2011-03-27 14:31:47.000000000 -0400
55974+++ linux-2.6.32.41/include/linux/kvm_host.h 2011-04-17 15:56:46.000000000 -0400
55975@@ -210,7 +210,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vc
55976 void vcpu_load(struct kvm_vcpu *vcpu);
55977 void vcpu_put(struct kvm_vcpu *vcpu);
55978
55979-int kvm_init(void *opaque, unsigned int vcpu_size,
55980+int kvm_init(const void *opaque, unsigned int vcpu_size,
55981 struct module *module);
55982 void kvm_exit(void);
55983
55984@@ -316,7 +316,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(
55985 struct kvm_guest_debug *dbg);
55986 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
55987
55988-int kvm_arch_init(void *opaque);
55989+int kvm_arch_init(const void *opaque);
55990 void kvm_arch_exit(void);
55991
55992 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
55993diff -urNp linux-2.6.32.41/include/linux/libata.h linux-2.6.32.41/include/linux/libata.h
55994--- linux-2.6.32.41/include/linux/libata.h 2011-03-27 14:31:47.000000000 -0400
55995+++ linux-2.6.32.41/include/linux/libata.h 2011-04-23 12:56:11.000000000 -0400
55996@@ -525,11 +525,11 @@ struct ata_ioports {
55997
55998 struct ata_host {
55999 spinlock_t lock;
56000- struct device *dev;
56001+ struct device *dev;
56002 void __iomem * const *iomap;
56003 unsigned int n_ports;
56004 void *private_data;
56005- struct ata_port_operations *ops;
56006+ const struct ata_port_operations *ops;
56007 unsigned long flags;
56008 #ifdef CONFIG_ATA_ACPI
56009 acpi_handle acpi_handle;
56010@@ -710,7 +710,7 @@ struct ata_link {
56011
56012 struct ata_port {
56013 struct Scsi_Host *scsi_host; /* our co-allocated scsi host */
56014- struct ata_port_operations *ops;
56015+ const struct ata_port_operations *ops;
56016 spinlock_t *lock;
56017 /* Flags owned by the EH context. Only EH should touch these once the
56018 port is active */
56019@@ -892,7 +892,7 @@ struct ata_port_info {
56020 unsigned long pio_mask;
56021 unsigned long mwdma_mask;
56022 unsigned long udma_mask;
56023- struct ata_port_operations *port_ops;
56024+ const struct ata_port_operations *port_ops;
56025 void *private_data;
56026 };
56027
56028@@ -916,7 +916,7 @@ extern const unsigned long sata_deb_timi
56029 extern const unsigned long sata_deb_timing_hotplug[];
56030 extern const unsigned long sata_deb_timing_long[];
56031
56032-extern struct ata_port_operations ata_dummy_port_ops;
56033+extern const struct ata_port_operations ata_dummy_port_ops;
56034 extern const struct ata_port_info ata_dummy_port_info;
56035
56036 static inline const unsigned long *
56037@@ -962,7 +962,7 @@ extern int ata_host_activate(struct ata_
56038 struct scsi_host_template *sht);
56039 extern void ata_host_detach(struct ata_host *host);
56040 extern void ata_host_init(struct ata_host *, struct device *,
56041- unsigned long, struct ata_port_operations *);
56042+ unsigned long, const struct ata_port_operations *);
56043 extern int ata_scsi_detect(struct scsi_host_template *sht);
56044 extern int ata_scsi_ioctl(struct scsi_device *dev, int cmd, void __user *arg);
56045 extern int ata_scsi_queuecmd(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *));
56046diff -urNp linux-2.6.32.41/include/linux/lockd/bind.h linux-2.6.32.41/include/linux/lockd/bind.h
56047--- linux-2.6.32.41/include/linux/lockd/bind.h 2011-03-27 14:31:47.000000000 -0400
56048+++ linux-2.6.32.41/include/linux/lockd/bind.h 2011-04-17 15:56:46.000000000 -0400
56049@@ -23,13 +23,13 @@ struct svc_rqst;
56050 * This is the set of functions for lockd->nfsd communication
56051 */
56052 struct nlmsvc_binding {
56053- __be32 (*fopen)(struct svc_rqst *,
56054+ __be32 (* const fopen)(struct svc_rqst *,
56055 struct nfs_fh *,
56056 struct file **);
56057- void (*fclose)(struct file *);
56058+ void (* const fclose)(struct file *);
56059 };
56060
56061-extern struct nlmsvc_binding * nlmsvc_ops;
56062+extern const struct nlmsvc_binding * nlmsvc_ops;
56063
56064 /*
56065 * Similar to nfs_client_initdata, but without the NFS-specific
56066diff -urNp linux-2.6.32.41/include/linux/mm.h linux-2.6.32.41/include/linux/mm.h
56067--- linux-2.6.32.41/include/linux/mm.h 2011-03-27 14:31:47.000000000 -0400
56068+++ linux-2.6.32.41/include/linux/mm.h 2011-04-17 15:56:46.000000000 -0400
56069@@ -106,7 +106,14 @@ extern unsigned int kobjsize(const void
56070
56071 #define VM_CAN_NONLINEAR 0x08000000 /* Has ->fault & does nonlinear pages */
56072 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
56073+
56074+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
56075+#define VM_SAO 0x00000000 /* Strong Access Ordering (powerpc) */
56076+#define VM_PAGEEXEC 0x20000000 /* vma->vm_page_prot needs special handling */
56077+#else
56078 #define VM_SAO 0x20000000 /* Strong Access Ordering (powerpc) */
56079+#endif
56080+
56081 #define VM_PFN_AT_MMAP 0x40000000 /* PFNMAP vma that is fully mapped at mmap time */
56082 #define VM_MERGEABLE 0x80000000 /* KSM may merge identical pages */
56083
56084@@ -841,12 +848,6 @@ int set_page_dirty(struct page *page);
56085 int set_page_dirty_lock(struct page *page);
56086 int clear_page_dirty_for_io(struct page *page);
56087
56088-/* Is the vma a continuation of the stack vma above it? */
56089-static inline int vma_stack_continue(struct vm_area_struct *vma, unsigned long addr)
56090-{
56091- return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
56092-}
56093-
56094 extern unsigned long move_page_tables(struct vm_area_struct *vma,
56095 unsigned long old_addr, struct vm_area_struct *new_vma,
56096 unsigned long new_addr, unsigned long len);
56097@@ -890,6 +891,8 @@ struct shrinker {
56098 extern void register_shrinker(struct shrinker *);
56099 extern void unregister_shrinker(struct shrinker *);
56100
56101+pgprot_t vm_get_page_prot(unsigned long vm_flags);
56102+
56103 int vma_wants_writenotify(struct vm_area_struct *vma);
56104
56105 extern pte_t *get_locked_pte(struct mm_struct *mm, unsigned long addr, spinlock_t **ptl);
56106@@ -1162,6 +1165,7 @@ out:
56107 }
56108
56109 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
56110+extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
56111
56112 extern unsigned long do_brk(unsigned long, unsigned long);
56113
56114@@ -1218,6 +1222,10 @@ extern struct vm_area_struct * find_vma(
56115 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
56116 struct vm_area_struct **pprev);
56117
56118+extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
56119+extern void pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
56120+extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
56121+
56122 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
56123 NULL if none. Assume start_addr < end_addr. */
56124 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
56125@@ -1234,7 +1242,6 @@ static inline unsigned long vma_pages(st
56126 return (vma->vm_end - vma->vm_start) >> PAGE_SHIFT;
56127 }
56128
56129-pgprot_t vm_get_page_prot(unsigned long vm_flags);
56130 struct vm_area_struct *find_extend_vma(struct mm_struct *, unsigned long addr);
56131 int remap_pfn_range(struct vm_area_struct *, unsigned long addr,
56132 unsigned long pfn, unsigned long size, pgprot_t);
56133@@ -1332,7 +1339,13 @@ extern void memory_failure(unsigned long
56134 extern int __memory_failure(unsigned long pfn, int trapno, int ref);
56135 extern int sysctl_memory_failure_early_kill;
56136 extern int sysctl_memory_failure_recovery;
56137-extern atomic_long_t mce_bad_pages;
56138+extern atomic_long_unchecked_t mce_bad_pages;
56139+
56140+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
56141+extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
56142+#else
56143+static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
56144+#endif
56145
56146 #endif /* __KERNEL__ */
56147 #endif /* _LINUX_MM_H */
56148diff -urNp linux-2.6.32.41/include/linux/mm_types.h linux-2.6.32.41/include/linux/mm_types.h
56149--- linux-2.6.32.41/include/linux/mm_types.h 2011-03-27 14:31:47.000000000 -0400
56150+++ linux-2.6.32.41/include/linux/mm_types.h 2011-04-17 15:56:46.000000000 -0400
56151@@ -186,6 +186,8 @@ struct vm_area_struct {
56152 #ifdef CONFIG_NUMA
56153 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
56154 #endif
56155+
56156+ struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
56157 };
56158
56159 struct core_thread {
56160@@ -287,6 +289,24 @@ struct mm_struct {
56161 #ifdef CONFIG_MMU_NOTIFIER
56162 struct mmu_notifier_mm *mmu_notifier_mm;
56163 #endif
56164+
56165+#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS) || defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
56166+ unsigned long pax_flags;
56167+#endif
56168+
56169+#ifdef CONFIG_PAX_DLRESOLVE
56170+ unsigned long call_dl_resolve;
56171+#endif
56172+
56173+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
56174+ unsigned long call_syscall;
56175+#endif
56176+
56177+#ifdef CONFIG_PAX_ASLR
56178+ unsigned long delta_mmap; /* randomized offset */
56179+ unsigned long delta_stack; /* randomized offset */
56180+#endif
56181+
56182 };
56183
56184 /* Future-safe accessor for struct mm_struct's cpu_vm_mask. */
56185diff -urNp linux-2.6.32.41/include/linux/mmu_notifier.h linux-2.6.32.41/include/linux/mmu_notifier.h
56186--- linux-2.6.32.41/include/linux/mmu_notifier.h 2011-03-27 14:31:47.000000000 -0400
56187+++ linux-2.6.32.41/include/linux/mmu_notifier.h 2011-04-17 15:56:46.000000000 -0400
56188@@ -235,12 +235,12 @@ static inline void mmu_notifier_mm_destr
56189 */
56190 #define ptep_clear_flush_notify(__vma, __address, __ptep) \
56191 ({ \
56192- pte_t __pte; \
56193+ pte_t ___pte; \
56194 struct vm_area_struct *___vma = __vma; \
56195 unsigned long ___address = __address; \
56196- __pte = ptep_clear_flush(___vma, ___address, __ptep); \
56197+ ___pte = ptep_clear_flush(___vma, ___address, __ptep); \
56198 mmu_notifier_invalidate_page(___vma->vm_mm, ___address); \
56199- __pte; \
56200+ ___pte; \
56201 })
56202
56203 #define ptep_clear_flush_young_notify(__vma, __address, __ptep) \
56204diff -urNp linux-2.6.32.41/include/linux/mmzone.h linux-2.6.32.41/include/linux/mmzone.h
56205--- linux-2.6.32.41/include/linux/mmzone.h 2011-03-27 14:31:47.000000000 -0400
56206+++ linux-2.6.32.41/include/linux/mmzone.h 2011-04-17 15:56:46.000000000 -0400
56207@@ -350,7 +350,7 @@ struct zone {
56208 unsigned long flags; /* zone flags, see below */
56209
56210 /* Zone statistics */
56211- atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
56212+ atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
56213
56214 /*
56215 * prev_priority holds the scanning priority for this zone. It is
56216diff -urNp linux-2.6.32.41/include/linux/mod_devicetable.h linux-2.6.32.41/include/linux/mod_devicetable.h
56217--- linux-2.6.32.41/include/linux/mod_devicetable.h 2011-03-27 14:31:47.000000000 -0400
56218+++ linux-2.6.32.41/include/linux/mod_devicetable.h 2011-04-17 15:56:46.000000000 -0400
56219@@ -12,7 +12,7 @@
56220 typedef unsigned long kernel_ulong_t;
56221 #endif
56222
56223-#define PCI_ANY_ID (~0)
56224+#define PCI_ANY_ID ((__u16)~0)
56225
56226 struct pci_device_id {
56227 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
56228@@ -131,7 +131,7 @@ struct usb_device_id {
56229 #define USB_DEVICE_ID_MATCH_INT_SUBCLASS 0x0100
56230 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
56231
56232-#define HID_ANY_ID (~0)
56233+#define HID_ANY_ID (~0U)
56234
56235 struct hid_device_id {
56236 __u16 bus;
56237diff -urNp linux-2.6.32.41/include/linux/module.h linux-2.6.32.41/include/linux/module.h
56238--- linux-2.6.32.41/include/linux/module.h 2011-03-27 14:31:47.000000000 -0400
56239+++ linux-2.6.32.41/include/linux/module.h 2011-04-17 15:56:46.000000000 -0400
56240@@ -287,16 +287,16 @@ struct module
56241 int (*init)(void);
56242
56243 /* If this is non-NULL, vfree after init() returns */
56244- void *module_init;
56245+ void *module_init_rx, *module_init_rw;
56246
56247 /* Here is the actual code + data, vfree'd on unload. */
56248- void *module_core;
56249+ void *module_core_rx, *module_core_rw;
56250
56251 /* Here are the sizes of the init and core sections */
56252- unsigned int init_size, core_size;
56253+ unsigned int init_size_rw, core_size_rw;
56254
56255 /* The size of the executable code in each section. */
56256- unsigned int init_text_size, core_text_size;
56257+ unsigned int init_size_rx, core_size_rx;
56258
56259 /* Arch-specific module values */
56260 struct mod_arch_specific arch;
56261@@ -393,16 +393,46 @@ struct module *__module_address(unsigned
56262 bool is_module_address(unsigned long addr);
56263 bool is_module_text_address(unsigned long addr);
56264
56265+static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
56266+{
56267+
56268+#ifdef CONFIG_PAX_KERNEXEC
56269+ if (ktla_ktva(addr) >= (unsigned long)start &&
56270+ ktla_ktva(addr) < (unsigned long)start + size)
56271+ return 1;
56272+#endif
56273+
56274+ return ((void *)addr >= start && (void *)addr < start + size);
56275+}
56276+
56277+static inline int within_module_core_rx(unsigned long addr, struct module *mod)
56278+{
56279+ return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
56280+}
56281+
56282+static inline int within_module_core_rw(unsigned long addr, struct module *mod)
56283+{
56284+ return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
56285+}
56286+
56287+static inline int within_module_init_rx(unsigned long addr, struct module *mod)
56288+{
56289+ return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
56290+}
56291+
56292+static inline int within_module_init_rw(unsigned long addr, struct module *mod)
56293+{
56294+ return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
56295+}
56296+
56297 static inline int within_module_core(unsigned long addr, struct module *mod)
56298 {
56299- return (unsigned long)mod->module_core <= addr &&
56300- addr < (unsigned long)mod->module_core + mod->core_size;
56301+ return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
56302 }
56303
56304 static inline int within_module_init(unsigned long addr, struct module *mod)
56305 {
56306- return (unsigned long)mod->module_init <= addr &&
56307- addr < (unsigned long)mod->module_init + mod->init_size;
56308+ return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
56309 }
56310
56311 /* Search for module by name: must hold module_mutex. */
56312diff -urNp linux-2.6.32.41/include/linux/moduleloader.h linux-2.6.32.41/include/linux/moduleloader.h
56313--- linux-2.6.32.41/include/linux/moduleloader.h 2011-03-27 14:31:47.000000000 -0400
56314+++ linux-2.6.32.41/include/linux/moduleloader.h 2011-04-17 15:56:46.000000000 -0400
56315@@ -20,9 +20,21 @@ unsigned int arch_mod_section_prepend(st
56316 sections. Returns NULL on failure. */
56317 void *module_alloc(unsigned long size);
56318
56319+#ifdef CONFIG_PAX_KERNEXEC
56320+void *module_alloc_exec(unsigned long size);
56321+#else
56322+#define module_alloc_exec(x) module_alloc(x)
56323+#endif
56324+
56325 /* Free memory returned from module_alloc. */
56326 void module_free(struct module *mod, void *module_region);
56327
56328+#ifdef CONFIG_PAX_KERNEXEC
56329+void module_free_exec(struct module *mod, void *module_region);
56330+#else
56331+#define module_free_exec(x, y) module_free((x), (y))
56332+#endif
56333+
56334 /* Apply the given relocation to the (simplified) ELF. Return -error
56335 or 0. */
56336 int apply_relocate(Elf_Shdr *sechdrs,
56337diff -urNp linux-2.6.32.41/include/linux/moduleparam.h linux-2.6.32.41/include/linux/moduleparam.h
56338--- linux-2.6.32.41/include/linux/moduleparam.h 2011-03-27 14:31:47.000000000 -0400
56339+++ linux-2.6.32.41/include/linux/moduleparam.h 2011-04-17 15:56:46.000000000 -0400
56340@@ -132,7 +132,7 @@ struct kparam_array
56341
56342 /* Actually copy string: maxlen param is usually sizeof(string). */
56343 #define module_param_string(name, string, len, perm) \
56344- static const struct kparam_string __param_string_##name \
56345+ static const struct kparam_string __param_string_##name __used \
56346 = { len, string }; \
56347 __module_param_call(MODULE_PARAM_PREFIX, name, \
56348 param_set_copystring, param_get_string, \
56349@@ -211,7 +211,7 @@ extern int param_get_invbool(char *buffe
56350
56351 /* Comma-separated array: *nump is set to number they actually specified. */
56352 #define module_param_array_named(name, array, type, nump, perm) \
56353- static const struct kparam_array __param_arr_##name \
56354+ static const struct kparam_array __param_arr_##name __used \
56355 = { ARRAY_SIZE(array), nump, param_set_##type, param_get_##type,\
56356 sizeof(array[0]), array }; \
56357 __module_param_call(MODULE_PARAM_PREFIX, name, \
56358diff -urNp linux-2.6.32.41/include/linux/mutex.h linux-2.6.32.41/include/linux/mutex.h
56359--- linux-2.6.32.41/include/linux/mutex.h 2011-03-27 14:31:47.000000000 -0400
56360+++ linux-2.6.32.41/include/linux/mutex.h 2011-04-17 15:56:46.000000000 -0400
56361@@ -51,7 +51,7 @@ struct mutex {
56362 spinlock_t wait_lock;
56363 struct list_head wait_list;
56364 #if defined(CONFIG_DEBUG_MUTEXES) || defined(CONFIG_SMP)
56365- struct thread_info *owner;
56366+ struct task_struct *owner;
56367 #endif
56368 #ifdef CONFIG_DEBUG_MUTEXES
56369 const char *name;
56370diff -urNp linux-2.6.32.41/include/linux/namei.h linux-2.6.32.41/include/linux/namei.h
56371--- linux-2.6.32.41/include/linux/namei.h 2011-03-27 14:31:47.000000000 -0400
56372+++ linux-2.6.32.41/include/linux/namei.h 2011-04-17 15:56:46.000000000 -0400
56373@@ -22,7 +22,7 @@ struct nameidata {
56374 unsigned int flags;
56375 int last_type;
56376 unsigned depth;
56377- char *saved_names[MAX_NESTED_LINKS + 1];
56378+ const char *saved_names[MAX_NESTED_LINKS + 1];
56379
56380 /* Intent data */
56381 union {
56382@@ -84,12 +84,12 @@ extern int follow_up(struct path *);
56383 extern struct dentry *lock_rename(struct dentry *, struct dentry *);
56384 extern void unlock_rename(struct dentry *, struct dentry *);
56385
56386-static inline void nd_set_link(struct nameidata *nd, char *path)
56387+static inline void nd_set_link(struct nameidata *nd, const char *path)
56388 {
56389 nd->saved_names[nd->depth] = path;
56390 }
56391
56392-static inline char *nd_get_link(struct nameidata *nd)
56393+static inline const char *nd_get_link(const struct nameidata *nd)
56394 {
56395 return nd->saved_names[nd->depth];
56396 }
56397diff -urNp linux-2.6.32.41/include/linux/netfilter/xt_gradm.h linux-2.6.32.41/include/linux/netfilter/xt_gradm.h
56398--- linux-2.6.32.41/include/linux/netfilter/xt_gradm.h 1969-12-31 19:00:00.000000000 -0500
56399+++ linux-2.6.32.41/include/linux/netfilter/xt_gradm.h 2011-04-17 15:56:46.000000000 -0400
56400@@ -0,0 +1,9 @@
56401+#ifndef _LINUX_NETFILTER_XT_GRADM_H
56402+#define _LINUX_NETFILTER_XT_GRADM_H 1
56403+
56404+struct xt_gradm_mtinfo {
56405+ __u16 flags;
56406+ __u16 invflags;
56407+};
56408+
56409+#endif
56410diff -urNp linux-2.6.32.41/include/linux/nodemask.h linux-2.6.32.41/include/linux/nodemask.h
56411--- linux-2.6.32.41/include/linux/nodemask.h 2011-03-27 14:31:47.000000000 -0400
56412+++ linux-2.6.32.41/include/linux/nodemask.h 2011-04-17 15:56:46.000000000 -0400
56413@@ -464,11 +464,11 @@ static inline int num_node_state(enum no
56414
56415 #define any_online_node(mask) \
56416 ({ \
56417- int node; \
56418- for_each_node_mask(node, (mask)) \
56419- if (node_online(node)) \
56420+ int __node; \
56421+ for_each_node_mask(__node, (mask)) \
56422+ if (node_online(__node)) \
56423 break; \
56424- node; \
56425+ __node; \
56426 })
56427
56428 #define num_online_nodes() num_node_state(N_ONLINE)
56429diff -urNp linux-2.6.32.41/include/linux/oprofile.h linux-2.6.32.41/include/linux/oprofile.h
56430--- linux-2.6.32.41/include/linux/oprofile.h 2011-03-27 14:31:47.000000000 -0400
56431+++ linux-2.6.32.41/include/linux/oprofile.h 2011-04-17 15:56:46.000000000 -0400
56432@@ -129,9 +129,9 @@ int oprofilefs_create_ulong(struct super
56433 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
56434 char const * name, ulong * val);
56435
56436-/** Create a file for read-only access to an atomic_t. */
56437+/** Create a file for read-only access to an atomic_unchecked_t. */
56438 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
56439- char const * name, atomic_t * val);
56440+ char const * name, atomic_unchecked_t * val);
56441
56442 /** create a directory */
56443 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
56444diff -urNp linux-2.6.32.41/include/linux/perf_event.h linux-2.6.32.41/include/linux/perf_event.h
56445--- linux-2.6.32.41/include/linux/perf_event.h 2011-03-27 14:31:47.000000000 -0400
56446+++ linux-2.6.32.41/include/linux/perf_event.h 2011-05-04 17:56:28.000000000 -0400
56447@@ -476,7 +476,7 @@ struct hw_perf_event {
56448 struct hrtimer hrtimer;
56449 };
56450 };
56451- atomic64_t prev_count;
56452+ atomic64_unchecked_t prev_count;
56453 u64 sample_period;
56454 u64 last_period;
56455 atomic64_t period_left;
56456@@ -557,7 +557,7 @@ struct perf_event {
56457 const struct pmu *pmu;
56458
56459 enum perf_event_active_state state;
56460- atomic64_t count;
56461+ atomic64_unchecked_t count;
56462
56463 /*
56464 * These are the total time in nanoseconds that the event
56465@@ -595,8 +595,8 @@ struct perf_event {
56466 * These accumulate total time (in nanoseconds) that children
56467 * events have been enabled and running, respectively.
56468 */
56469- atomic64_t child_total_time_enabled;
56470- atomic64_t child_total_time_running;
56471+ atomic64_unchecked_t child_total_time_enabled;
56472+ atomic64_unchecked_t child_total_time_running;
56473
56474 /*
56475 * Protect attach/detach and child_list:
56476diff -urNp linux-2.6.32.41/include/linux/pipe_fs_i.h linux-2.6.32.41/include/linux/pipe_fs_i.h
56477--- linux-2.6.32.41/include/linux/pipe_fs_i.h 2011-03-27 14:31:47.000000000 -0400
56478+++ linux-2.6.32.41/include/linux/pipe_fs_i.h 2011-04-17 15:56:46.000000000 -0400
56479@@ -46,9 +46,9 @@ struct pipe_inode_info {
56480 wait_queue_head_t wait;
56481 unsigned int nrbufs, curbuf;
56482 struct page *tmp_page;
56483- unsigned int readers;
56484- unsigned int writers;
56485- unsigned int waiting_writers;
56486+ atomic_t readers;
56487+ atomic_t writers;
56488+ atomic_t waiting_writers;
56489 unsigned int r_counter;
56490 unsigned int w_counter;
56491 struct fasync_struct *fasync_readers;
56492diff -urNp linux-2.6.32.41/include/linux/poison.h linux-2.6.32.41/include/linux/poison.h
56493--- linux-2.6.32.41/include/linux/poison.h 2011-03-27 14:31:47.000000000 -0400
56494+++ linux-2.6.32.41/include/linux/poison.h 2011-04-17 15:56:46.000000000 -0400
56495@@ -19,8 +19,8 @@
56496 * under normal circumstances, used to verify that nobody uses
56497 * non-initialized list entries.
56498 */
56499-#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
56500-#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
56501+#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
56502+#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
56503
56504 /********** include/linux/timer.h **********/
56505 /*
56506diff -urNp linux-2.6.32.41/include/linux/proc_fs.h linux-2.6.32.41/include/linux/proc_fs.h
56507--- linux-2.6.32.41/include/linux/proc_fs.h 2011-03-27 14:31:47.000000000 -0400
56508+++ linux-2.6.32.41/include/linux/proc_fs.h 2011-04-17 15:56:46.000000000 -0400
56509@@ -155,6 +155,19 @@ static inline struct proc_dir_entry *pro
56510 return proc_create_data(name, mode, parent, proc_fops, NULL);
56511 }
56512
56513+static inline struct proc_dir_entry *proc_create_grsec(const char *name, mode_t mode,
56514+ struct proc_dir_entry *parent, const struct file_operations *proc_fops)
56515+{
56516+#ifdef CONFIG_GRKERNSEC_PROC_USER
56517+ return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
56518+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
56519+ return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
56520+#else
56521+ return proc_create_data(name, mode, parent, proc_fops, NULL);
56522+#endif
56523+}
56524+
56525+
56526 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
56527 mode_t mode, struct proc_dir_entry *base,
56528 read_proc_t *read_proc, void * data)
56529diff -urNp linux-2.6.32.41/include/linux/ptrace.h linux-2.6.32.41/include/linux/ptrace.h
56530--- linux-2.6.32.41/include/linux/ptrace.h 2011-03-27 14:31:47.000000000 -0400
56531+++ linux-2.6.32.41/include/linux/ptrace.h 2011-04-17 15:56:46.000000000 -0400
56532@@ -96,10 +96,10 @@ extern void __ptrace_unlink(struct task_
56533 extern void exit_ptrace(struct task_struct *tracer);
56534 #define PTRACE_MODE_READ 1
56535 #define PTRACE_MODE_ATTACH 2
56536-/* Returns 0 on success, -errno on denial. */
56537-extern int __ptrace_may_access(struct task_struct *task, unsigned int mode);
56538 /* Returns true on success, false on denial. */
56539 extern bool ptrace_may_access(struct task_struct *task, unsigned int mode);
56540+/* Returns true on success, false on denial. */
56541+extern bool ptrace_may_access_log(struct task_struct *task, unsigned int mode);
56542
56543 static inline int ptrace_reparented(struct task_struct *child)
56544 {
56545diff -urNp linux-2.6.32.41/include/linux/random.h linux-2.6.32.41/include/linux/random.h
56546--- linux-2.6.32.41/include/linux/random.h 2011-03-27 14:31:47.000000000 -0400
56547+++ linux-2.6.32.41/include/linux/random.h 2011-04-17 15:56:46.000000000 -0400
56548@@ -74,6 +74,11 @@ unsigned long randomize_range(unsigned l
56549 u32 random32(void);
56550 void srandom32(u32 seed);
56551
56552+static inline unsigned long pax_get_random_long(void)
56553+{
56554+ return random32() + (sizeof(long) > 4 ? (unsigned long)random32() << 32 : 0);
56555+}
56556+
56557 #endif /* __KERNEL___ */
56558
56559 #endif /* _LINUX_RANDOM_H */
56560diff -urNp linux-2.6.32.41/include/linux/reboot.h linux-2.6.32.41/include/linux/reboot.h
56561--- linux-2.6.32.41/include/linux/reboot.h 2011-03-27 14:31:47.000000000 -0400
56562+++ linux-2.6.32.41/include/linux/reboot.h 2011-05-22 23:02:06.000000000 -0400
56563@@ -47,9 +47,9 @@ extern int unregister_reboot_notifier(st
56564 * Architecture-specific implementations of sys_reboot commands.
56565 */
56566
56567-extern void machine_restart(char *cmd);
56568-extern void machine_halt(void);
56569-extern void machine_power_off(void);
56570+extern void machine_restart(char *cmd) __noreturn;
56571+extern void machine_halt(void) __noreturn;
56572+extern void machine_power_off(void) __noreturn;
56573
56574 extern void machine_shutdown(void);
56575 struct pt_regs;
56576@@ -60,9 +60,9 @@ extern void machine_crash_shutdown(struc
56577 */
56578
56579 extern void kernel_restart_prepare(char *cmd);
56580-extern void kernel_restart(char *cmd);
56581-extern void kernel_halt(void);
56582-extern void kernel_power_off(void);
56583+extern void kernel_restart(char *cmd) __noreturn;
56584+extern void kernel_halt(void) __noreturn;
56585+extern void kernel_power_off(void) __noreturn;
56586
56587 void ctrl_alt_del(void);
56588
56589@@ -75,7 +75,7 @@ extern int orderly_poweroff(bool force);
56590 * Emergency restart, callable from an interrupt handler.
56591 */
56592
56593-extern void emergency_restart(void);
56594+extern void emergency_restart(void) __noreturn;
56595 #include <asm/emergency-restart.h>
56596
56597 #endif
56598diff -urNp linux-2.6.32.41/include/linux/reiserfs_fs.h linux-2.6.32.41/include/linux/reiserfs_fs.h
56599--- linux-2.6.32.41/include/linux/reiserfs_fs.h 2011-03-27 14:31:47.000000000 -0400
56600+++ linux-2.6.32.41/include/linux/reiserfs_fs.h 2011-04-17 15:56:46.000000000 -0400
56601@@ -1326,7 +1326,7 @@ static inline loff_t max_reiserfs_offset
56602 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
56603
56604 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
56605-#define get_generation(s) atomic_read (&fs_generation(s))
56606+#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
56607 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
56608 #define __fs_changed(gen,s) (gen != get_generation (s))
56609 #define fs_changed(gen,s) ({cond_resched(); __fs_changed(gen, s);})
56610@@ -1534,24 +1534,24 @@ static inline struct super_block *sb_fro
56611 */
56612
56613 struct item_operations {
56614- int (*bytes_number) (struct item_head * ih, int block_size);
56615- void (*decrement_key) (struct cpu_key *);
56616- int (*is_left_mergeable) (struct reiserfs_key * ih,
56617+ int (* const bytes_number) (struct item_head * ih, int block_size);
56618+ void (* const decrement_key) (struct cpu_key *);
56619+ int (* const is_left_mergeable) (struct reiserfs_key * ih,
56620 unsigned long bsize);
56621- void (*print_item) (struct item_head *, char *item);
56622- void (*check_item) (struct item_head *, char *item);
56623+ void (* const print_item) (struct item_head *, char *item);
56624+ void (* const check_item) (struct item_head *, char *item);
56625
56626- int (*create_vi) (struct virtual_node * vn, struct virtual_item * vi,
56627+ int (* const create_vi) (struct virtual_node * vn, struct virtual_item * vi,
56628 int is_affected, int insert_size);
56629- int (*check_left) (struct virtual_item * vi, int free,
56630+ int (* const check_left) (struct virtual_item * vi, int free,
56631 int start_skip, int end_skip);
56632- int (*check_right) (struct virtual_item * vi, int free);
56633- int (*part_size) (struct virtual_item * vi, int from, int to);
56634- int (*unit_num) (struct virtual_item * vi);
56635- void (*print_vi) (struct virtual_item * vi);
56636+ int (* const check_right) (struct virtual_item * vi, int free);
56637+ int (* const part_size) (struct virtual_item * vi, int from, int to);
56638+ int (* const unit_num) (struct virtual_item * vi);
56639+ void (* const print_vi) (struct virtual_item * vi);
56640 };
56641
56642-extern struct item_operations *item_ops[TYPE_ANY + 1];
56643+extern const struct item_operations * const item_ops[TYPE_ANY + 1];
56644
56645 #define op_bytes_number(ih,bsize) item_ops[le_ih_k_type (ih)]->bytes_number (ih, bsize)
56646 #define op_is_left_mergeable(key,bsize) item_ops[le_key_k_type (le_key_version (key), key)]->is_left_mergeable (key, bsize)
56647diff -urNp linux-2.6.32.41/include/linux/reiserfs_fs_sb.h linux-2.6.32.41/include/linux/reiserfs_fs_sb.h
56648--- linux-2.6.32.41/include/linux/reiserfs_fs_sb.h 2011-03-27 14:31:47.000000000 -0400
56649+++ linux-2.6.32.41/include/linux/reiserfs_fs_sb.h 2011-04-17 15:56:46.000000000 -0400
56650@@ -377,7 +377,7 @@ struct reiserfs_sb_info {
56651 /* Comment? -Hans */
56652 wait_queue_head_t s_wait;
56653 /* To be obsoleted soon by per buffer seals.. -Hans */
56654- atomic_t s_generation_counter; // increased by one every time the
56655+ atomic_unchecked_t s_generation_counter; // increased by one every time the
56656 // tree gets re-balanced
56657 unsigned long s_properties; /* File system properties. Currently holds
56658 on-disk FS format */
56659diff -urNp linux-2.6.32.41/include/linux/sched.h linux-2.6.32.41/include/linux/sched.h
56660--- linux-2.6.32.41/include/linux/sched.h 2011-03-27 14:31:47.000000000 -0400
56661+++ linux-2.6.32.41/include/linux/sched.h 2011-06-04 20:42:54.000000000 -0400
56662@@ -101,6 +101,7 @@ struct bio;
56663 struct fs_struct;
56664 struct bts_context;
56665 struct perf_event_context;
56666+struct linux_binprm;
56667
56668 /*
56669 * List of flags we want to share for kernel threads,
56670@@ -350,7 +351,7 @@ extern signed long schedule_timeout_kill
56671 extern signed long schedule_timeout_uninterruptible(signed long timeout);
56672 asmlinkage void __schedule(void);
56673 asmlinkage void schedule(void);
56674-extern int mutex_spin_on_owner(struct mutex *lock, struct thread_info *owner);
56675+extern int mutex_spin_on_owner(struct mutex *lock, struct task_struct *owner);
56676
56677 struct nsproxy;
56678 struct user_namespace;
56679@@ -371,9 +372,12 @@ struct user_namespace;
56680 #define DEFAULT_MAX_MAP_COUNT (USHORT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
56681
56682 extern int sysctl_max_map_count;
56683+extern unsigned long sysctl_heap_stack_gap;
56684
56685 #include <linux/aio.h>
56686
56687+extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len);
56688+extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len);
56689 extern unsigned long
56690 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
56691 unsigned long, unsigned long);
56692@@ -666,6 +670,16 @@ struct signal_struct {
56693 struct tty_audit_buf *tty_audit_buf;
56694 #endif
56695
56696+#ifdef CONFIG_GRKERNSEC
56697+ u32 curr_ip;
56698+ u32 saved_ip;
56699+ u32 gr_saddr;
56700+ u32 gr_daddr;
56701+ u16 gr_sport;
56702+ u16 gr_dport;
56703+ u8 used_accept:1;
56704+#endif
56705+
56706 int oom_adj; /* OOM kill score adjustment (bit shift) */
56707 };
56708
56709@@ -723,6 +737,11 @@ struct user_struct {
56710 struct key *session_keyring; /* UID's default session keyring */
56711 #endif
56712
56713+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
56714+ unsigned int banned;
56715+ unsigned long ban_expires;
56716+#endif
56717+
56718 /* Hash table maintenance information */
56719 struct hlist_node uidhash_node;
56720 uid_t uid;
56721@@ -1328,8 +1347,8 @@ struct task_struct {
56722 struct list_head thread_group;
56723
56724 struct completion *vfork_done; /* for vfork() */
56725- int __user *set_child_tid; /* CLONE_CHILD_SETTID */
56726- int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
56727+ pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
56728+ pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
56729
56730 cputime_t utime, stime, utimescaled, stimescaled;
56731 cputime_t gtime;
56732@@ -1343,16 +1362,6 @@ struct task_struct {
56733 struct task_cputime cputime_expires;
56734 struct list_head cpu_timers[3];
56735
56736-/* process credentials */
56737- const struct cred *real_cred; /* objective and real subjective task
56738- * credentials (COW) */
56739- const struct cred *cred; /* effective (overridable) subjective task
56740- * credentials (COW) */
56741- struct mutex cred_guard_mutex; /* guard against foreign influences on
56742- * credential calculations
56743- * (notably. ptrace) */
56744- struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */
56745-
56746 char comm[TASK_COMM_LEN]; /* executable name excluding path
56747 - access with [gs]et_task_comm (which lock
56748 it with task_lock())
56749@@ -1369,6 +1378,10 @@ struct task_struct {
56750 #endif
56751 /* CPU-specific state of this task */
56752 struct thread_struct thread;
56753+/* thread_info moved to task_struct */
56754+#ifdef CONFIG_X86
56755+ struct thread_info tinfo;
56756+#endif
56757 /* filesystem information */
56758 struct fs_struct *fs;
56759 /* open file information */
56760@@ -1436,6 +1449,15 @@ struct task_struct {
56761 int hardirq_context;
56762 int softirq_context;
56763 #endif
56764+
56765+/* process credentials */
56766+ const struct cred *real_cred; /* objective and real subjective task
56767+ * credentials (COW) */
56768+ struct mutex cred_guard_mutex; /* guard against foreign influences on
56769+ * credential calculations
56770+ * (notably. ptrace) */
56771+ struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */
56772+
56773 #ifdef CONFIG_LOCKDEP
56774 # define MAX_LOCK_DEPTH 48UL
56775 u64 curr_chain_key;
56776@@ -1456,6 +1478,9 @@ struct task_struct {
56777
56778 struct backing_dev_info *backing_dev_info;
56779
56780+ const struct cred *cred; /* effective (overridable) subjective task
56781+ * credentials (COW) */
56782+
56783 struct io_context *io_context;
56784
56785 unsigned long ptrace_message;
56786@@ -1519,6 +1544,21 @@ struct task_struct {
56787 unsigned long default_timer_slack_ns;
56788
56789 struct list_head *scm_work_list;
56790+
56791+#ifdef CONFIG_GRKERNSEC
56792+ /* grsecurity */
56793+ struct dentry *gr_chroot_dentry;
56794+ struct acl_subject_label *acl;
56795+ struct acl_role_label *role;
56796+ struct file *exec_file;
56797+ u16 acl_role_id;
56798+ /* is this the task that authenticated to the special role */
56799+ u8 acl_sp_role;
56800+ u8 is_writable;
56801+ u8 brute;
56802+ u8 gr_is_chrooted;
56803+#endif
56804+
56805 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
56806 /* Index of current stored adress in ret_stack */
56807 int curr_ret_stack;
56808@@ -1542,6 +1582,57 @@ struct task_struct {
56809 #endif /* CONFIG_TRACING */
56810 };
56811
56812+#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
56813+#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
56814+#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
56815+#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
56816+/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
56817+#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
56818+
56819+#ifdef CONFIG_PAX_SOFTMODE
56820+extern unsigned int pax_softmode;
56821+#endif
56822+
56823+extern int pax_check_flags(unsigned long *);
56824+
56825+/* if tsk != current then task_lock must be held on it */
56826+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
56827+static inline unsigned long pax_get_flags(struct task_struct *tsk)
56828+{
56829+ if (likely(tsk->mm))
56830+ return tsk->mm->pax_flags;
56831+ else
56832+ return 0UL;
56833+}
56834+
56835+/* if tsk != current then task_lock must be held on it */
56836+static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
56837+{
56838+ if (likely(tsk->mm)) {
56839+ tsk->mm->pax_flags = flags;
56840+ return 0;
56841+ }
56842+ return -EINVAL;
56843+}
56844+#endif
56845+
56846+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
56847+extern void pax_set_initial_flags(struct linux_binprm *bprm);
56848+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
56849+extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
56850+#endif
56851+
56852+void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
56853+void pax_report_insns(void *pc, void *sp);
56854+void pax_report_refcount_overflow(struct pt_regs *regs);
56855+void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type);
56856+
56857+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
56858+extern void pax_track_stack(void);
56859+#else
56860+static inline void pax_track_stack(void) {}
56861+#endif
56862+
56863 /* Future-safe accessor for struct task_struct's cpus_allowed. */
56864 #define tsk_cpumask(tsk) (&(tsk)->cpus_allowed)
56865
56866@@ -1978,7 +2069,9 @@ void yield(void);
56867 extern struct exec_domain default_exec_domain;
56868
56869 union thread_union {
56870+#ifndef CONFIG_X86
56871 struct thread_info thread_info;
56872+#endif
56873 unsigned long stack[THREAD_SIZE/sizeof(long)];
56874 };
56875
56876@@ -2155,7 +2248,7 @@ extern void __cleanup_sighand(struct sig
56877 extern void exit_itimers(struct signal_struct *);
56878 extern void flush_itimer_signals(void);
56879
56880-extern NORET_TYPE void do_group_exit(int);
56881+extern NORET_TYPE void do_group_exit(int) ATTRIB_NORET;
56882
56883 extern void daemonize(const char *, ...);
56884 extern int allow_signal(int);
56885@@ -2284,13 +2377,17 @@ static inline unsigned long *end_of_stac
56886
56887 #endif
56888
56889-static inline int object_is_on_stack(void *obj)
56890+static inline int object_starts_on_stack(void *obj)
56891 {
56892- void *stack = task_stack_page(current);
56893+ const void *stack = task_stack_page(current);
56894
56895 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
56896 }
56897
56898+#ifdef CONFIG_PAX_USERCOPY
56899+extern int object_is_on_stack(const void *obj, unsigned long len);
56900+#endif
56901+
56902 extern void thread_info_cache_init(void);
56903
56904 #ifdef CONFIG_DEBUG_STACK_USAGE
56905diff -urNp linux-2.6.32.41/include/linux/screen_info.h linux-2.6.32.41/include/linux/screen_info.h
56906--- linux-2.6.32.41/include/linux/screen_info.h 2011-03-27 14:31:47.000000000 -0400
56907+++ linux-2.6.32.41/include/linux/screen_info.h 2011-04-17 15:56:46.000000000 -0400
56908@@ -42,7 +42,8 @@ struct screen_info {
56909 __u16 pages; /* 0x32 */
56910 __u16 vesa_attributes; /* 0x34 */
56911 __u32 capabilities; /* 0x36 */
56912- __u8 _reserved[6]; /* 0x3a */
56913+ __u16 vesapm_size; /* 0x3a */
56914+ __u8 _reserved[4]; /* 0x3c */
56915 } __attribute__((packed));
56916
56917 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
56918diff -urNp linux-2.6.32.41/include/linux/security.h linux-2.6.32.41/include/linux/security.h
56919--- linux-2.6.32.41/include/linux/security.h 2011-03-27 14:31:47.000000000 -0400
56920+++ linux-2.6.32.41/include/linux/security.h 2011-04-17 15:56:46.000000000 -0400
56921@@ -34,6 +34,7 @@
56922 #include <linux/key.h>
56923 #include <linux/xfrm.h>
56924 #include <linux/gfp.h>
56925+#include <linux/grsecurity.h>
56926 #include <net/flow.h>
56927
56928 /* Maximum number of letters for an LSM name string */
56929diff -urNp linux-2.6.32.41/include/linux/shm.h linux-2.6.32.41/include/linux/shm.h
56930--- linux-2.6.32.41/include/linux/shm.h 2011-03-27 14:31:47.000000000 -0400
56931+++ linux-2.6.32.41/include/linux/shm.h 2011-04-17 15:56:46.000000000 -0400
56932@@ -95,6 +95,10 @@ struct shmid_kernel /* private to the ke
56933 pid_t shm_cprid;
56934 pid_t shm_lprid;
56935 struct user_struct *mlock_user;
56936+#ifdef CONFIG_GRKERNSEC
56937+ time_t shm_createtime;
56938+ pid_t shm_lapid;
56939+#endif
56940 };
56941
56942 /* shm_mode upper byte flags */
56943diff -urNp linux-2.6.32.41/include/linux/skbuff.h linux-2.6.32.41/include/linux/skbuff.h
56944--- linux-2.6.32.41/include/linux/skbuff.h 2011-03-27 14:31:47.000000000 -0400
56945+++ linux-2.6.32.41/include/linux/skbuff.h 2011-05-04 17:56:20.000000000 -0400
56946@@ -544,7 +544,7 @@ static inline union skb_shared_tx *skb_t
56947 */
56948 static inline int skb_queue_empty(const struct sk_buff_head *list)
56949 {
56950- return list->next == (struct sk_buff *)list;
56951+ return list->next == (const struct sk_buff *)list;
56952 }
56953
56954 /**
56955@@ -557,7 +557,7 @@ static inline int skb_queue_empty(const
56956 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
56957 const struct sk_buff *skb)
56958 {
56959- return (skb->next == (struct sk_buff *) list);
56960+ return (skb->next == (const struct sk_buff *) list);
56961 }
56962
56963 /**
56964@@ -570,7 +570,7 @@ static inline bool skb_queue_is_last(con
56965 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
56966 const struct sk_buff *skb)
56967 {
56968- return (skb->prev == (struct sk_buff *) list);
56969+ return (skb->prev == (const struct sk_buff *) list);
56970 }
56971
56972 /**
56973@@ -1367,7 +1367,7 @@ static inline int skb_network_offset(con
56974 * headroom, you should not reduce this.
56975 */
56976 #ifndef NET_SKB_PAD
56977-#define NET_SKB_PAD 32
56978+#define NET_SKB_PAD (_AC(32,U))
56979 #endif
56980
56981 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
56982diff -urNp linux-2.6.32.41/include/linux/slab_def.h linux-2.6.32.41/include/linux/slab_def.h
56983--- linux-2.6.32.41/include/linux/slab_def.h 2011-03-27 14:31:47.000000000 -0400
56984+++ linux-2.6.32.41/include/linux/slab_def.h 2011-05-04 17:56:28.000000000 -0400
56985@@ -69,10 +69,10 @@ struct kmem_cache {
56986 unsigned long node_allocs;
56987 unsigned long node_frees;
56988 unsigned long node_overflow;
56989- atomic_t allochit;
56990- atomic_t allocmiss;
56991- atomic_t freehit;
56992- atomic_t freemiss;
56993+ atomic_unchecked_t allochit;
56994+ atomic_unchecked_t allocmiss;
56995+ atomic_unchecked_t freehit;
56996+ atomic_unchecked_t freemiss;
56997
56998 /*
56999 * If debugging is enabled, then the allocator can add additional
57000diff -urNp linux-2.6.32.41/include/linux/slab.h linux-2.6.32.41/include/linux/slab.h
57001--- linux-2.6.32.41/include/linux/slab.h 2011-03-27 14:31:47.000000000 -0400
57002+++ linux-2.6.32.41/include/linux/slab.h 2011-04-17 15:56:46.000000000 -0400
57003@@ -11,12 +11,20 @@
57004
57005 #include <linux/gfp.h>
57006 #include <linux/types.h>
57007+#include <linux/err.h>
57008
57009 /*
57010 * Flags to pass to kmem_cache_create().
57011 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
57012 */
57013 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
57014+
57015+#ifdef CONFIG_PAX_USERCOPY
57016+#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
57017+#else
57018+#define SLAB_USERCOPY 0x00000000UL
57019+#endif
57020+
57021 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
57022 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
57023 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
57024@@ -82,10 +90,13 @@
57025 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
57026 * Both make kfree a no-op.
57027 */
57028-#define ZERO_SIZE_PTR ((void *)16)
57029+#define ZERO_SIZE_PTR \
57030+({ \
57031+ BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
57032+ (void *)(-MAX_ERRNO-1L); \
57033+})
57034
57035-#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
57036- (unsigned long)ZERO_SIZE_PTR)
57037+#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
57038
57039 /*
57040 * struct kmem_cache related prototypes
57041@@ -138,6 +149,7 @@ void * __must_check krealloc(const void
57042 void kfree(const void *);
57043 void kzfree(const void *);
57044 size_t ksize(const void *);
57045+void check_object_size(const void *ptr, unsigned long n, bool to);
57046
57047 /*
57048 * Allocator specific definitions. These are mainly used to establish optimized
57049@@ -328,4 +340,37 @@ static inline void *kzalloc_node(size_t
57050
57051 void __init kmem_cache_init_late(void);
57052
57053+#define kmalloc(x, y) \
57054+({ \
57055+ void *___retval; \
57056+ intoverflow_t ___x = (intoverflow_t)x; \
57057+ if (WARN(___x > ULONG_MAX, "kmalloc size overflow\n"))\
57058+ ___retval = NULL; \
57059+ else \
57060+ ___retval = kmalloc((size_t)___x, (y)); \
57061+ ___retval; \
57062+})
57063+
57064+#define kmalloc_node(x, y, z) \
57065+({ \
57066+ void *___retval; \
57067+ intoverflow_t ___x = (intoverflow_t)x; \
57068+ if (WARN(___x > ULONG_MAX, "kmalloc_node size overflow\n"))\
57069+ ___retval = NULL; \
57070+ else \
57071+ ___retval = kmalloc_node((size_t)___x, (y), (z));\
57072+ ___retval; \
57073+})
57074+
57075+#define kzalloc(x, y) \
57076+({ \
57077+ void *___retval; \
57078+ intoverflow_t ___x = (intoverflow_t)x; \
57079+ if (WARN(___x > ULONG_MAX, "kzalloc size overflow\n"))\
57080+ ___retval = NULL; \
57081+ else \
57082+ ___retval = kzalloc((size_t)___x, (y)); \
57083+ ___retval; \
57084+})
57085+
57086 #endif /* _LINUX_SLAB_H */
57087diff -urNp linux-2.6.32.41/include/linux/slub_def.h linux-2.6.32.41/include/linux/slub_def.h
57088--- linux-2.6.32.41/include/linux/slub_def.h 2011-03-27 14:31:47.000000000 -0400
57089+++ linux-2.6.32.41/include/linux/slub_def.h 2011-04-17 15:56:46.000000000 -0400
57090@@ -86,7 +86,7 @@ struct kmem_cache {
57091 struct kmem_cache_order_objects max;
57092 struct kmem_cache_order_objects min;
57093 gfp_t allocflags; /* gfp flags to use on each alloc */
57094- int refcount; /* Refcount for slab cache destroy */
57095+ atomic_t refcount; /* Refcount for slab cache destroy */
57096 void (*ctor)(void *);
57097 int inuse; /* Offset to metadata */
57098 int align; /* Alignment */
57099diff -urNp linux-2.6.32.41/include/linux/sonet.h linux-2.6.32.41/include/linux/sonet.h
57100--- linux-2.6.32.41/include/linux/sonet.h 2011-03-27 14:31:47.000000000 -0400
57101+++ linux-2.6.32.41/include/linux/sonet.h 2011-04-17 15:56:46.000000000 -0400
57102@@ -61,7 +61,7 @@ struct sonet_stats {
57103 #include <asm/atomic.h>
57104
57105 struct k_sonet_stats {
57106-#define __HANDLE_ITEM(i) atomic_t i
57107+#define __HANDLE_ITEM(i) atomic_unchecked_t i
57108 __SONET_ITEMS
57109 #undef __HANDLE_ITEM
57110 };
57111diff -urNp linux-2.6.32.41/include/linux/sunrpc/clnt.h linux-2.6.32.41/include/linux/sunrpc/clnt.h
57112--- linux-2.6.32.41/include/linux/sunrpc/clnt.h 2011-03-27 14:31:47.000000000 -0400
57113+++ linux-2.6.32.41/include/linux/sunrpc/clnt.h 2011-04-17 15:56:46.000000000 -0400
57114@@ -167,9 +167,9 @@ static inline unsigned short rpc_get_por
57115 {
57116 switch (sap->sa_family) {
57117 case AF_INET:
57118- return ntohs(((struct sockaddr_in *)sap)->sin_port);
57119+ return ntohs(((const struct sockaddr_in *)sap)->sin_port);
57120 case AF_INET6:
57121- return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
57122+ return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
57123 }
57124 return 0;
57125 }
57126@@ -202,7 +202,7 @@ static inline bool __rpc_cmp_addr4(const
57127 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
57128 const struct sockaddr *src)
57129 {
57130- const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
57131+ const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
57132 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
57133
57134 dsin->sin_family = ssin->sin_family;
57135@@ -299,7 +299,7 @@ static inline u32 rpc_get_scope_id(const
57136 if (sa->sa_family != AF_INET6)
57137 return 0;
57138
57139- return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
57140+ return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
57141 }
57142
57143 #endif /* __KERNEL__ */
57144diff -urNp linux-2.6.32.41/include/linux/sunrpc/svc_rdma.h linux-2.6.32.41/include/linux/sunrpc/svc_rdma.h
57145--- linux-2.6.32.41/include/linux/sunrpc/svc_rdma.h 2011-03-27 14:31:47.000000000 -0400
57146+++ linux-2.6.32.41/include/linux/sunrpc/svc_rdma.h 2011-05-04 17:56:28.000000000 -0400
57147@@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
57148 extern unsigned int svcrdma_max_requests;
57149 extern unsigned int svcrdma_max_req_size;
57150
57151-extern atomic_t rdma_stat_recv;
57152-extern atomic_t rdma_stat_read;
57153-extern atomic_t rdma_stat_write;
57154-extern atomic_t rdma_stat_sq_starve;
57155-extern atomic_t rdma_stat_rq_starve;
57156-extern atomic_t rdma_stat_rq_poll;
57157-extern atomic_t rdma_stat_rq_prod;
57158-extern atomic_t rdma_stat_sq_poll;
57159-extern atomic_t rdma_stat_sq_prod;
57160+extern atomic_unchecked_t rdma_stat_recv;
57161+extern atomic_unchecked_t rdma_stat_read;
57162+extern atomic_unchecked_t rdma_stat_write;
57163+extern atomic_unchecked_t rdma_stat_sq_starve;
57164+extern atomic_unchecked_t rdma_stat_rq_starve;
57165+extern atomic_unchecked_t rdma_stat_rq_poll;
57166+extern atomic_unchecked_t rdma_stat_rq_prod;
57167+extern atomic_unchecked_t rdma_stat_sq_poll;
57168+extern atomic_unchecked_t rdma_stat_sq_prod;
57169
57170 #define RPCRDMA_VERSION 1
57171
57172diff -urNp linux-2.6.32.41/include/linux/suspend.h linux-2.6.32.41/include/linux/suspend.h
57173--- linux-2.6.32.41/include/linux/suspend.h 2011-03-27 14:31:47.000000000 -0400
57174+++ linux-2.6.32.41/include/linux/suspend.h 2011-04-17 15:56:46.000000000 -0400
57175@@ -104,15 +104,15 @@ typedef int __bitwise suspend_state_t;
57176 * which require special recovery actions in that situation.
57177 */
57178 struct platform_suspend_ops {
57179- int (*valid)(suspend_state_t state);
57180- int (*begin)(suspend_state_t state);
57181- int (*prepare)(void);
57182- int (*prepare_late)(void);
57183- int (*enter)(suspend_state_t state);
57184- void (*wake)(void);
57185- void (*finish)(void);
57186- void (*end)(void);
57187- void (*recover)(void);
57188+ int (* const valid)(suspend_state_t state);
57189+ int (* const begin)(suspend_state_t state);
57190+ int (* const prepare)(void);
57191+ int (* const prepare_late)(void);
57192+ int (* const enter)(suspend_state_t state);
57193+ void (* const wake)(void);
57194+ void (* const finish)(void);
57195+ void (* const end)(void);
57196+ void (* const recover)(void);
57197 };
57198
57199 #ifdef CONFIG_SUSPEND
57200@@ -120,7 +120,7 @@ struct platform_suspend_ops {
57201 * suspend_set_ops - set platform dependent suspend operations
57202 * @ops: The new suspend operations to set.
57203 */
57204-extern void suspend_set_ops(struct platform_suspend_ops *ops);
57205+extern void suspend_set_ops(const struct platform_suspend_ops *ops);
57206 extern int suspend_valid_only_mem(suspend_state_t state);
57207
57208 /**
57209@@ -145,7 +145,7 @@ extern int pm_suspend(suspend_state_t st
57210 #else /* !CONFIG_SUSPEND */
57211 #define suspend_valid_only_mem NULL
57212
57213-static inline void suspend_set_ops(struct platform_suspend_ops *ops) {}
57214+static inline void suspend_set_ops(const struct platform_suspend_ops *ops) {}
57215 static inline int pm_suspend(suspend_state_t state) { return -ENOSYS; }
57216 #endif /* !CONFIG_SUSPEND */
57217
57218@@ -215,16 +215,16 @@ extern void mark_free_pages(struct zone
57219 * platforms which require special recovery actions in that situation.
57220 */
57221 struct platform_hibernation_ops {
57222- int (*begin)(void);
57223- void (*end)(void);
57224- int (*pre_snapshot)(void);
57225- void (*finish)(void);
57226- int (*prepare)(void);
57227- int (*enter)(void);
57228- void (*leave)(void);
57229- int (*pre_restore)(void);
57230- void (*restore_cleanup)(void);
57231- void (*recover)(void);
57232+ int (* const begin)(void);
57233+ void (* const end)(void);
57234+ int (* const pre_snapshot)(void);
57235+ void (* const finish)(void);
57236+ int (* const prepare)(void);
57237+ int (* const enter)(void);
57238+ void (* const leave)(void);
57239+ int (* const pre_restore)(void);
57240+ void (* const restore_cleanup)(void);
57241+ void (* const recover)(void);
57242 };
57243
57244 #ifdef CONFIG_HIBERNATION
57245@@ -243,7 +243,7 @@ extern void swsusp_set_page_free(struct
57246 extern void swsusp_unset_page_free(struct page *);
57247 extern unsigned long get_safe_page(gfp_t gfp_mask);
57248
57249-extern void hibernation_set_ops(struct platform_hibernation_ops *ops);
57250+extern void hibernation_set_ops(const struct platform_hibernation_ops *ops);
57251 extern int hibernate(void);
57252 extern bool system_entering_hibernation(void);
57253 #else /* CONFIG_HIBERNATION */
57254@@ -251,7 +251,7 @@ static inline int swsusp_page_is_forbidd
57255 static inline void swsusp_set_page_free(struct page *p) {}
57256 static inline void swsusp_unset_page_free(struct page *p) {}
57257
57258-static inline void hibernation_set_ops(struct platform_hibernation_ops *ops) {}
57259+static inline void hibernation_set_ops(const struct platform_hibernation_ops *ops) {}
57260 static inline int hibernate(void) { return -ENOSYS; }
57261 static inline bool system_entering_hibernation(void) { return false; }
57262 #endif /* CONFIG_HIBERNATION */
57263diff -urNp linux-2.6.32.41/include/linux/sysctl.h linux-2.6.32.41/include/linux/sysctl.h
57264--- linux-2.6.32.41/include/linux/sysctl.h 2011-03-27 14:31:47.000000000 -0400
57265+++ linux-2.6.32.41/include/linux/sysctl.h 2011-04-17 15:56:46.000000000 -0400
57266@@ -164,7 +164,11 @@ enum
57267 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
57268 };
57269
57270-
57271+#ifdef CONFIG_PAX_SOFTMODE
57272+enum {
57273+ PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
57274+};
57275+#endif
57276
57277 /* CTL_VM names: */
57278 enum
57279@@ -982,6 +986,8 @@ typedef int proc_handler (struct ctl_tab
57280
57281 extern int proc_dostring(struct ctl_table *, int,
57282 void __user *, size_t *, loff_t *);
57283+extern int proc_dostring_modpriv(struct ctl_table *, int,
57284+ void __user *, size_t *, loff_t *);
57285 extern int proc_dointvec(struct ctl_table *, int,
57286 void __user *, size_t *, loff_t *);
57287 extern int proc_dointvec_minmax(struct ctl_table *, int,
57288@@ -1003,6 +1009,7 @@ extern int do_sysctl (int __user *name,
57289
57290 extern ctl_handler sysctl_data;
57291 extern ctl_handler sysctl_string;
57292+extern ctl_handler sysctl_string_modpriv;
57293 extern ctl_handler sysctl_intvec;
57294 extern ctl_handler sysctl_jiffies;
57295 extern ctl_handler sysctl_ms_jiffies;
57296diff -urNp linux-2.6.32.41/include/linux/sysfs.h linux-2.6.32.41/include/linux/sysfs.h
57297--- linux-2.6.32.41/include/linux/sysfs.h 2011-03-27 14:31:47.000000000 -0400
57298+++ linux-2.6.32.41/include/linux/sysfs.h 2011-04-17 15:56:46.000000000 -0400
57299@@ -75,8 +75,8 @@ struct bin_attribute {
57300 };
57301
57302 struct sysfs_ops {
57303- ssize_t (*show)(struct kobject *, struct attribute *,char *);
57304- ssize_t (*store)(struct kobject *,struct attribute *,const char *, size_t);
57305+ ssize_t (* const show)(struct kobject *, struct attribute *,char *);
57306+ ssize_t (* const store)(struct kobject *,struct attribute *,const char *, size_t);
57307 };
57308
57309 struct sysfs_dirent;
57310diff -urNp linux-2.6.32.41/include/linux/thread_info.h linux-2.6.32.41/include/linux/thread_info.h
57311--- linux-2.6.32.41/include/linux/thread_info.h 2011-03-27 14:31:47.000000000 -0400
57312+++ linux-2.6.32.41/include/linux/thread_info.h 2011-04-17 15:56:46.000000000 -0400
57313@@ -23,7 +23,7 @@ struct restart_block {
57314 };
57315 /* For futex_wait and futex_wait_requeue_pi */
57316 struct {
57317- u32 *uaddr;
57318+ u32 __user *uaddr;
57319 u32 val;
57320 u32 flags;
57321 u32 bitset;
57322diff -urNp linux-2.6.32.41/include/linux/tty.h linux-2.6.32.41/include/linux/tty.h
57323--- linux-2.6.32.41/include/linux/tty.h 2011-03-27 14:31:47.000000000 -0400
57324+++ linux-2.6.32.41/include/linux/tty.h 2011-04-17 15:56:46.000000000 -0400
57325@@ -13,6 +13,7 @@
57326 #include <linux/tty_driver.h>
57327 #include <linux/tty_ldisc.h>
57328 #include <linux/mutex.h>
57329+#include <linux/poll.h>
57330
57331 #include <asm/system.h>
57332
57333@@ -443,7 +444,6 @@ extern int tty_perform_flush(struct tty_
57334 extern dev_t tty_devnum(struct tty_struct *tty);
57335 extern void proc_clear_tty(struct task_struct *p);
57336 extern struct tty_struct *get_current_tty(void);
57337-extern void tty_default_fops(struct file_operations *fops);
57338 extern struct tty_struct *alloc_tty_struct(void);
57339 extern void free_tty_struct(struct tty_struct *tty);
57340 extern void initialize_tty_struct(struct tty_struct *tty,
57341@@ -493,6 +493,18 @@ extern void tty_ldisc_begin(void);
57342 /* This last one is just for the tty layer internals and shouldn't be used elsewhere */
57343 extern void tty_ldisc_enable(struct tty_struct *tty);
57344
57345+/* tty_io.c */
57346+extern ssize_t tty_read(struct file *, char __user *, size_t, loff_t *);
57347+extern ssize_t tty_write(struct file *, const char __user *, size_t, loff_t *);
57348+extern unsigned int tty_poll(struct file *, poll_table *);
57349+#ifdef CONFIG_COMPAT
57350+extern long tty_compat_ioctl(struct file *file, unsigned int cmd,
57351+ unsigned long arg);
57352+#else
57353+#define tty_compat_ioctl NULL
57354+#endif
57355+extern int tty_release(struct inode *, struct file *);
57356+extern int tty_fasync(int fd, struct file *filp, int on);
57357
57358 /* n_tty.c */
57359 extern struct tty_ldisc_ops tty_ldisc_N_TTY;
57360diff -urNp linux-2.6.32.41/include/linux/tty_ldisc.h linux-2.6.32.41/include/linux/tty_ldisc.h
57361--- linux-2.6.32.41/include/linux/tty_ldisc.h 2011-03-27 14:31:47.000000000 -0400
57362+++ linux-2.6.32.41/include/linux/tty_ldisc.h 2011-04-17 15:56:46.000000000 -0400
57363@@ -139,7 +139,7 @@ struct tty_ldisc_ops {
57364
57365 struct module *owner;
57366
57367- int refcount;
57368+ atomic_t refcount;
57369 };
57370
57371 struct tty_ldisc {
57372diff -urNp linux-2.6.32.41/include/linux/types.h linux-2.6.32.41/include/linux/types.h
57373--- linux-2.6.32.41/include/linux/types.h 2011-03-27 14:31:47.000000000 -0400
57374+++ linux-2.6.32.41/include/linux/types.h 2011-04-17 15:56:46.000000000 -0400
57375@@ -191,10 +191,26 @@ typedef struct {
57376 volatile int counter;
57377 } atomic_t;
57378
57379+#ifdef CONFIG_PAX_REFCOUNT
57380+typedef struct {
57381+ volatile int counter;
57382+} atomic_unchecked_t;
57383+#else
57384+typedef atomic_t atomic_unchecked_t;
57385+#endif
57386+
57387 #ifdef CONFIG_64BIT
57388 typedef struct {
57389 volatile long counter;
57390 } atomic64_t;
57391+
57392+#ifdef CONFIG_PAX_REFCOUNT
57393+typedef struct {
57394+ volatile long counter;
57395+} atomic64_unchecked_t;
57396+#else
57397+typedef atomic64_t atomic64_unchecked_t;
57398+#endif
57399 #endif
57400
57401 struct ustat {
57402diff -urNp linux-2.6.32.41/include/linux/uaccess.h linux-2.6.32.41/include/linux/uaccess.h
57403--- linux-2.6.32.41/include/linux/uaccess.h 2011-03-27 14:31:47.000000000 -0400
57404+++ linux-2.6.32.41/include/linux/uaccess.h 2011-04-17 15:56:46.000000000 -0400
57405@@ -76,11 +76,11 @@ static inline unsigned long __copy_from_
57406 long ret; \
57407 mm_segment_t old_fs = get_fs(); \
57408 \
57409- set_fs(KERNEL_DS); \
57410 pagefault_disable(); \
57411+ set_fs(KERNEL_DS); \
57412 ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
57413- pagefault_enable(); \
57414 set_fs(old_fs); \
57415+ pagefault_enable(); \
57416 ret; \
57417 })
57418
57419@@ -93,7 +93,7 @@ static inline unsigned long __copy_from_
57420 * Safely read from address @src to the buffer at @dst. If a kernel fault
57421 * happens, handle that and return -EFAULT.
57422 */
57423-extern long probe_kernel_read(void *dst, void *src, size_t size);
57424+extern long probe_kernel_read(void *dst, const void *src, size_t size);
57425
57426 /*
57427 * probe_kernel_write(): safely attempt to write to a location
57428@@ -104,6 +104,6 @@ extern long probe_kernel_read(void *dst,
57429 * Safely write to address @dst from the buffer at @src. If a kernel fault
57430 * happens, handle that and return -EFAULT.
57431 */
57432-extern long probe_kernel_write(void *dst, void *src, size_t size);
57433+extern long probe_kernel_write(void *dst, const void *src, size_t size);
57434
57435 #endif /* __LINUX_UACCESS_H__ */
57436diff -urNp linux-2.6.32.41/include/linux/unaligned/access_ok.h linux-2.6.32.41/include/linux/unaligned/access_ok.h
57437--- linux-2.6.32.41/include/linux/unaligned/access_ok.h 2011-03-27 14:31:47.000000000 -0400
57438+++ linux-2.6.32.41/include/linux/unaligned/access_ok.h 2011-04-17 15:56:46.000000000 -0400
57439@@ -6,32 +6,32 @@
57440
57441 static inline u16 get_unaligned_le16(const void *p)
57442 {
57443- return le16_to_cpup((__le16 *)p);
57444+ return le16_to_cpup((const __le16 *)p);
57445 }
57446
57447 static inline u32 get_unaligned_le32(const void *p)
57448 {
57449- return le32_to_cpup((__le32 *)p);
57450+ return le32_to_cpup((const __le32 *)p);
57451 }
57452
57453 static inline u64 get_unaligned_le64(const void *p)
57454 {
57455- return le64_to_cpup((__le64 *)p);
57456+ return le64_to_cpup((const __le64 *)p);
57457 }
57458
57459 static inline u16 get_unaligned_be16(const void *p)
57460 {
57461- return be16_to_cpup((__be16 *)p);
57462+ return be16_to_cpup((const __be16 *)p);
57463 }
57464
57465 static inline u32 get_unaligned_be32(const void *p)
57466 {
57467- return be32_to_cpup((__be32 *)p);
57468+ return be32_to_cpup((const __be32 *)p);
57469 }
57470
57471 static inline u64 get_unaligned_be64(const void *p)
57472 {
57473- return be64_to_cpup((__be64 *)p);
57474+ return be64_to_cpup((const __be64 *)p);
57475 }
57476
57477 static inline void put_unaligned_le16(u16 val, void *p)
57478diff -urNp linux-2.6.32.41/include/linux/vmalloc.h linux-2.6.32.41/include/linux/vmalloc.h
57479--- linux-2.6.32.41/include/linux/vmalloc.h 2011-03-27 14:31:47.000000000 -0400
57480+++ linux-2.6.32.41/include/linux/vmalloc.h 2011-04-17 15:56:46.000000000 -0400
57481@@ -13,6 +13,11 @@ struct vm_area_struct; /* vma defining
57482 #define VM_MAP 0x00000004 /* vmap()ed pages */
57483 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
57484 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
57485+
57486+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
57487+#define VM_KERNEXEC 0x00000020 /* allocate from executable kernel memory range */
57488+#endif
57489+
57490 /* bits [20..32] reserved for arch specific ioremap internals */
57491
57492 /*
57493@@ -123,4 +128,81 @@ struct vm_struct **pcpu_get_vm_areas(con
57494
57495 void pcpu_free_vm_areas(struct vm_struct **vms, int nr_vms);
57496
57497+#define vmalloc(x) \
57498+({ \
57499+ void *___retval; \
57500+ intoverflow_t ___x = (intoverflow_t)x; \
57501+ if (WARN(___x > ULONG_MAX, "vmalloc size overflow\n")) \
57502+ ___retval = NULL; \
57503+ else \
57504+ ___retval = vmalloc((unsigned long)___x); \
57505+ ___retval; \
57506+})
57507+
57508+#define __vmalloc(x, y, z) \
57509+({ \
57510+ void *___retval; \
57511+ intoverflow_t ___x = (intoverflow_t)x; \
57512+ if (WARN(___x > ULONG_MAX, "__vmalloc size overflow\n"))\
57513+ ___retval = NULL; \
57514+ else \
57515+ ___retval = __vmalloc((unsigned long)___x, (y), (z));\
57516+ ___retval; \
57517+})
57518+
57519+#define vmalloc_user(x) \
57520+({ \
57521+ void *___retval; \
57522+ intoverflow_t ___x = (intoverflow_t)x; \
57523+ if (WARN(___x > ULONG_MAX, "vmalloc_user size overflow\n"))\
57524+ ___retval = NULL; \
57525+ else \
57526+ ___retval = vmalloc_user((unsigned long)___x); \
57527+ ___retval; \
57528+})
57529+
57530+#define vmalloc_exec(x) \
57531+({ \
57532+ void *___retval; \
57533+ intoverflow_t ___x = (intoverflow_t)x; \
57534+ if (WARN(___x > ULONG_MAX, "vmalloc_exec size overflow\n"))\
57535+ ___retval = NULL; \
57536+ else \
57537+ ___retval = vmalloc_exec((unsigned long)___x); \
57538+ ___retval; \
57539+})
57540+
57541+#define vmalloc_node(x, y) \
57542+({ \
57543+ void *___retval; \
57544+ intoverflow_t ___x = (intoverflow_t)x; \
57545+ if (WARN(___x > ULONG_MAX, "vmalloc_node size overflow\n"))\
57546+ ___retval = NULL; \
57547+ else \
57548+ ___retval = vmalloc_node((unsigned long)___x, (y));\
57549+ ___retval; \
57550+})
57551+
57552+#define vmalloc_32(x) \
57553+({ \
57554+ void *___retval; \
57555+ intoverflow_t ___x = (intoverflow_t)x; \
57556+ if (WARN(___x > ULONG_MAX, "vmalloc_32 size overflow\n"))\
57557+ ___retval = NULL; \
57558+ else \
57559+ ___retval = vmalloc_32((unsigned long)___x); \
57560+ ___retval; \
57561+})
57562+
57563+#define vmalloc_32_user(x) \
57564+({ \
57565+ void *___retval; \
57566+ intoverflow_t ___x = (intoverflow_t)x; \
57567+ if (WARN(___x > ULONG_MAX, "vmalloc_32_user size overflow\n"))\
57568+ ___retval = NULL; \
57569+ else \
57570+ ___retval = vmalloc_32_user((unsigned long)___x);\
57571+ ___retval; \
57572+})
57573+
57574 #endif /* _LINUX_VMALLOC_H */
57575diff -urNp linux-2.6.32.41/include/linux/vmstat.h linux-2.6.32.41/include/linux/vmstat.h
57576--- linux-2.6.32.41/include/linux/vmstat.h 2011-03-27 14:31:47.000000000 -0400
57577+++ linux-2.6.32.41/include/linux/vmstat.h 2011-04-17 15:56:46.000000000 -0400
57578@@ -136,18 +136,18 @@ static inline void vm_events_fold_cpu(in
57579 /*
57580 * Zone based page accounting with per cpu differentials.
57581 */
57582-extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
57583+extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
57584
57585 static inline void zone_page_state_add(long x, struct zone *zone,
57586 enum zone_stat_item item)
57587 {
57588- atomic_long_add(x, &zone->vm_stat[item]);
57589- atomic_long_add(x, &vm_stat[item]);
57590+ atomic_long_add_unchecked(x, &zone->vm_stat[item]);
57591+ atomic_long_add_unchecked(x, &vm_stat[item]);
57592 }
57593
57594 static inline unsigned long global_page_state(enum zone_stat_item item)
57595 {
57596- long x = atomic_long_read(&vm_stat[item]);
57597+ long x = atomic_long_read_unchecked(&vm_stat[item]);
57598 #ifdef CONFIG_SMP
57599 if (x < 0)
57600 x = 0;
57601@@ -158,7 +158,7 @@ static inline unsigned long global_page_
57602 static inline unsigned long zone_page_state(struct zone *zone,
57603 enum zone_stat_item item)
57604 {
57605- long x = atomic_long_read(&zone->vm_stat[item]);
57606+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
57607 #ifdef CONFIG_SMP
57608 if (x < 0)
57609 x = 0;
57610@@ -175,7 +175,7 @@ static inline unsigned long zone_page_st
57611 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
57612 enum zone_stat_item item)
57613 {
57614- long x = atomic_long_read(&zone->vm_stat[item]);
57615+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
57616
57617 #ifdef CONFIG_SMP
57618 int cpu;
57619@@ -264,8 +264,8 @@ static inline void __mod_zone_page_state
57620
57621 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
57622 {
57623- atomic_long_inc(&zone->vm_stat[item]);
57624- atomic_long_inc(&vm_stat[item]);
57625+ atomic_long_inc_unchecked(&zone->vm_stat[item]);
57626+ atomic_long_inc_unchecked(&vm_stat[item]);
57627 }
57628
57629 static inline void __inc_zone_page_state(struct page *page,
57630@@ -276,8 +276,8 @@ static inline void __inc_zone_page_state
57631
57632 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
57633 {
57634- atomic_long_dec(&zone->vm_stat[item]);
57635- atomic_long_dec(&vm_stat[item]);
57636+ atomic_long_dec_unchecked(&zone->vm_stat[item]);
57637+ atomic_long_dec_unchecked(&vm_stat[item]);
57638 }
57639
57640 static inline void __dec_zone_page_state(struct page *page,
57641diff -urNp linux-2.6.32.41/include/media/v4l2-device.h linux-2.6.32.41/include/media/v4l2-device.h
57642--- linux-2.6.32.41/include/media/v4l2-device.h 2011-03-27 14:31:47.000000000 -0400
57643+++ linux-2.6.32.41/include/media/v4l2-device.h 2011-05-04 17:56:28.000000000 -0400
57644@@ -71,7 +71,7 @@ int __must_check v4l2_device_register(st
57645 this function returns 0. If the name ends with a digit (e.g. cx18),
57646 then the name will be set to cx18-0 since cx180 looks really odd. */
57647 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
57648- atomic_t *instance);
57649+ atomic_unchecked_t *instance);
57650
57651 /* Set v4l2_dev->dev to NULL. Call when the USB parent disconnects.
57652 Since the parent disappears this ensures that v4l2_dev doesn't have an
57653diff -urNp linux-2.6.32.41/include/net/flow.h linux-2.6.32.41/include/net/flow.h
57654--- linux-2.6.32.41/include/net/flow.h 2011-03-27 14:31:47.000000000 -0400
57655+++ linux-2.6.32.41/include/net/flow.h 2011-05-04 17:56:28.000000000 -0400
57656@@ -92,7 +92,7 @@ typedef int (*flow_resolve_t)(struct net
57657 extern void *flow_cache_lookup(struct net *net, struct flowi *key, u16 family,
57658 u8 dir, flow_resolve_t resolver);
57659 extern void flow_cache_flush(void);
57660-extern atomic_t flow_cache_genid;
57661+extern atomic_unchecked_t flow_cache_genid;
57662
57663 static inline int flow_cache_uli_match(struct flowi *fl1, struct flowi *fl2)
57664 {
57665diff -urNp linux-2.6.32.41/include/net/inetpeer.h linux-2.6.32.41/include/net/inetpeer.h
57666--- linux-2.6.32.41/include/net/inetpeer.h 2011-03-27 14:31:47.000000000 -0400
57667+++ linux-2.6.32.41/include/net/inetpeer.h 2011-04-17 15:56:46.000000000 -0400
57668@@ -24,7 +24,7 @@ struct inet_peer
57669 __u32 dtime; /* the time of last use of not
57670 * referenced entries */
57671 atomic_t refcnt;
57672- atomic_t rid; /* Frag reception counter */
57673+ atomic_unchecked_t rid; /* Frag reception counter */
57674 __u32 tcp_ts;
57675 unsigned long tcp_ts_stamp;
57676 };
57677diff -urNp linux-2.6.32.41/include/net/ip_vs.h linux-2.6.32.41/include/net/ip_vs.h
57678--- linux-2.6.32.41/include/net/ip_vs.h 2011-03-27 14:31:47.000000000 -0400
57679+++ linux-2.6.32.41/include/net/ip_vs.h 2011-05-04 17:56:28.000000000 -0400
57680@@ -365,7 +365,7 @@ struct ip_vs_conn {
57681 struct ip_vs_conn *control; /* Master control connection */
57682 atomic_t n_control; /* Number of controlled ones */
57683 struct ip_vs_dest *dest; /* real server */
57684- atomic_t in_pkts; /* incoming packet counter */
57685+ atomic_unchecked_t in_pkts; /* incoming packet counter */
57686
57687 /* packet transmitter for different forwarding methods. If it
57688 mangles the packet, it must return NF_DROP or better NF_STOLEN,
57689@@ -466,7 +466,7 @@ struct ip_vs_dest {
57690 union nf_inet_addr addr; /* IP address of the server */
57691 __be16 port; /* port number of the server */
57692 volatile unsigned flags; /* dest status flags */
57693- atomic_t conn_flags; /* flags to copy to conn */
57694+ atomic_unchecked_t conn_flags; /* flags to copy to conn */
57695 atomic_t weight; /* server weight */
57696
57697 atomic_t refcnt; /* reference counter */
57698diff -urNp linux-2.6.32.41/include/net/irda/ircomm_tty.h linux-2.6.32.41/include/net/irda/ircomm_tty.h
57699--- linux-2.6.32.41/include/net/irda/ircomm_tty.h 2011-03-27 14:31:47.000000000 -0400
57700+++ linux-2.6.32.41/include/net/irda/ircomm_tty.h 2011-04-17 15:56:46.000000000 -0400
57701@@ -35,6 +35,7 @@
57702 #include <linux/termios.h>
57703 #include <linux/timer.h>
57704 #include <linux/tty.h> /* struct tty_struct */
57705+#include <asm/local.h>
57706
57707 #include <net/irda/irias_object.h>
57708 #include <net/irda/ircomm_core.h>
57709@@ -105,8 +106,8 @@ struct ircomm_tty_cb {
57710 unsigned short close_delay;
57711 unsigned short closing_wait; /* time to wait before closing */
57712
57713- int open_count;
57714- int blocked_open; /* # of blocked opens */
57715+ local_t open_count;
57716+ local_t blocked_open; /* # of blocked opens */
57717
57718 /* Protect concurent access to :
57719 * o self->open_count
57720diff -urNp linux-2.6.32.41/include/net/iucv/af_iucv.h linux-2.6.32.41/include/net/iucv/af_iucv.h
57721--- linux-2.6.32.41/include/net/iucv/af_iucv.h 2011-03-27 14:31:47.000000000 -0400
57722+++ linux-2.6.32.41/include/net/iucv/af_iucv.h 2011-05-04 17:56:28.000000000 -0400
57723@@ -87,7 +87,7 @@ struct iucv_sock {
57724 struct iucv_sock_list {
57725 struct hlist_head head;
57726 rwlock_t lock;
57727- atomic_t autobind_name;
57728+ atomic_unchecked_t autobind_name;
57729 };
57730
57731 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
57732diff -urNp linux-2.6.32.41/include/net/neighbour.h linux-2.6.32.41/include/net/neighbour.h
57733--- linux-2.6.32.41/include/net/neighbour.h 2011-03-27 14:31:47.000000000 -0400
57734+++ linux-2.6.32.41/include/net/neighbour.h 2011-04-17 15:56:46.000000000 -0400
57735@@ -125,12 +125,12 @@ struct neighbour
57736 struct neigh_ops
57737 {
57738 int family;
57739- void (*solicit)(struct neighbour *, struct sk_buff*);
57740- void (*error_report)(struct neighbour *, struct sk_buff*);
57741- int (*output)(struct sk_buff*);
57742- int (*connected_output)(struct sk_buff*);
57743- int (*hh_output)(struct sk_buff*);
57744- int (*queue_xmit)(struct sk_buff*);
57745+ void (* const solicit)(struct neighbour *, struct sk_buff*);
57746+ void (* const error_report)(struct neighbour *, struct sk_buff*);
57747+ int (* const output)(struct sk_buff*);
57748+ int (* const connected_output)(struct sk_buff*);
57749+ int (* const hh_output)(struct sk_buff*);
57750+ int (* const queue_xmit)(struct sk_buff*);
57751 };
57752
57753 struct pneigh_entry
57754diff -urNp linux-2.6.32.41/include/net/netlink.h linux-2.6.32.41/include/net/netlink.h
57755--- linux-2.6.32.41/include/net/netlink.h 2011-03-27 14:31:47.000000000 -0400
57756+++ linux-2.6.32.41/include/net/netlink.h 2011-04-17 15:56:46.000000000 -0400
57757@@ -558,7 +558,7 @@ static inline void *nlmsg_get_pos(struct
57758 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
57759 {
57760 if (mark)
57761- skb_trim(skb, (unsigned char *) mark - skb->data);
57762+ skb_trim(skb, (const unsigned char *) mark - skb->data);
57763 }
57764
57765 /**
57766diff -urNp linux-2.6.32.41/include/net/netns/ipv4.h linux-2.6.32.41/include/net/netns/ipv4.h
57767--- linux-2.6.32.41/include/net/netns/ipv4.h 2011-03-27 14:31:47.000000000 -0400
57768+++ linux-2.6.32.41/include/net/netns/ipv4.h 2011-05-04 17:56:28.000000000 -0400
57769@@ -54,7 +54,7 @@ struct netns_ipv4 {
57770 int current_rt_cache_rebuild_count;
57771
57772 struct timer_list rt_secret_timer;
57773- atomic_t rt_genid;
57774+ atomic_unchecked_t rt_genid;
57775
57776 #ifdef CONFIG_IP_MROUTE
57777 struct sock *mroute_sk;
57778diff -urNp linux-2.6.32.41/include/net/sctp/sctp.h linux-2.6.32.41/include/net/sctp/sctp.h
57779--- linux-2.6.32.41/include/net/sctp/sctp.h 2011-03-27 14:31:47.000000000 -0400
57780+++ linux-2.6.32.41/include/net/sctp/sctp.h 2011-04-17 15:56:46.000000000 -0400
57781@@ -305,8 +305,8 @@ extern int sctp_debug_flag;
57782
57783 #else /* SCTP_DEBUG */
57784
57785-#define SCTP_DEBUG_PRINTK(whatever...)
57786-#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
57787+#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
57788+#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
57789 #define SCTP_ENABLE_DEBUG
57790 #define SCTP_DISABLE_DEBUG
57791 #define SCTP_ASSERT(expr, str, func)
57792diff -urNp linux-2.6.32.41/include/net/sock.h linux-2.6.32.41/include/net/sock.h
57793--- linux-2.6.32.41/include/net/sock.h 2011-03-27 14:31:47.000000000 -0400
57794+++ linux-2.6.32.41/include/net/sock.h 2011-05-04 17:56:28.000000000 -0400
57795@@ -272,7 +272,7 @@ struct sock {
57796 rwlock_t sk_callback_lock;
57797 int sk_err,
57798 sk_err_soft;
57799- atomic_t sk_drops;
57800+ atomic_unchecked_t sk_drops;
57801 unsigned short sk_ack_backlog;
57802 unsigned short sk_max_ack_backlog;
57803 __u32 sk_priority;
57804diff -urNp linux-2.6.32.41/include/net/tcp.h linux-2.6.32.41/include/net/tcp.h
57805--- linux-2.6.32.41/include/net/tcp.h 2011-03-27 14:31:47.000000000 -0400
57806+++ linux-2.6.32.41/include/net/tcp.h 2011-04-17 15:56:46.000000000 -0400
57807@@ -1444,6 +1444,7 @@ enum tcp_seq_states {
57808 struct tcp_seq_afinfo {
57809 char *name;
57810 sa_family_t family;
57811+ /* cannot be const */
57812 struct file_operations seq_fops;
57813 struct seq_operations seq_ops;
57814 };
57815diff -urNp linux-2.6.32.41/include/net/udp.h linux-2.6.32.41/include/net/udp.h
57816--- linux-2.6.32.41/include/net/udp.h 2011-03-27 14:31:47.000000000 -0400
57817+++ linux-2.6.32.41/include/net/udp.h 2011-04-17 15:56:46.000000000 -0400
57818@@ -187,6 +187,7 @@ struct udp_seq_afinfo {
57819 char *name;
57820 sa_family_t family;
57821 struct udp_table *udp_table;
57822+ /* cannot be const */
57823 struct file_operations seq_fops;
57824 struct seq_operations seq_ops;
57825 };
57826diff -urNp linux-2.6.32.41/include/scsi/scsi_device.h linux-2.6.32.41/include/scsi/scsi_device.h
57827--- linux-2.6.32.41/include/scsi/scsi_device.h 2011-04-17 17:00:52.000000000 -0400
57828+++ linux-2.6.32.41/include/scsi/scsi_device.h 2011-05-04 17:56:28.000000000 -0400
57829@@ -156,9 +156,9 @@ struct scsi_device {
57830 unsigned int max_device_blocked; /* what device_blocked counts down from */
57831 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
57832
57833- atomic_t iorequest_cnt;
57834- atomic_t iodone_cnt;
57835- atomic_t ioerr_cnt;
57836+ atomic_unchecked_t iorequest_cnt;
57837+ atomic_unchecked_t iodone_cnt;
57838+ atomic_unchecked_t ioerr_cnt;
57839
57840 struct device sdev_gendev,
57841 sdev_dev;
57842diff -urNp linux-2.6.32.41/include/sound/ac97_codec.h linux-2.6.32.41/include/sound/ac97_codec.h
57843--- linux-2.6.32.41/include/sound/ac97_codec.h 2011-03-27 14:31:47.000000000 -0400
57844+++ linux-2.6.32.41/include/sound/ac97_codec.h 2011-04-17 15:56:46.000000000 -0400
57845@@ -419,15 +419,15 @@
57846 struct snd_ac97;
57847
57848 struct snd_ac97_build_ops {
57849- int (*build_3d) (struct snd_ac97 *ac97);
57850- int (*build_specific) (struct snd_ac97 *ac97);
57851- int (*build_spdif) (struct snd_ac97 *ac97);
57852- int (*build_post_spdif) (struct snd_ac97 *ac97);
57853+ int (* const build_3d) (struct snd_ac97 *ac97);
57854+ int (* const build_specific) (struct snd_ac97 *ac97);
57855+ int (* const build_spdif) (struct snd_ac97 *ac97);
57856+ int (* const build_post_spdif) (struct snd_ac97 *ac97);
57857 #ifdef CONFIG_PM
57858- void (*suspend) (struct snd_ac97 *ac97);
57859- void (*resume) (struct snd_ac97 *ac97);
57860+ void (* const suspend) (struct snd_ac97 *ac97);
57861+ void (* const resume) (struct snd_ac97 *ac97);
57862 #endif
57863- void (*update_jacks) (struct snd_ac97 *ac97); /* for jack-sharing */
57864+ void (* const update_jacks) (struct snd_ac97 *ac97); /* for jack-sharing */
57865 };
57866
57867 struct snd_ac97_bus_ops {
57868@@ -477,7 +477,7 @@ struct snd_ac97_template {
57869
57870 struct snd_ac97 {
57871 /* -- lowlevel (hardware) driver specific -- */
57872- struct snd_ac97_build_ops * build_ops;
57873+ const struct snd_ac97_build_ops * build_ops;
57874 void *private_data;
57875 void (*private_free) (struct snd_ac97 *ac97);
57876 /* --- */
57877diff -urNp linux-2.6.32.41/include/sound/ymfpci.h linux-2.6.32.41/include/sound/ymfpci.h
57878--- linux-2.6.32.41/include/sound/ymfpci.h 2011-03-27 14:31:47.000000000 -0400
57879+++ linux-2.6.32.41/include/sound/ymfpci.h 2011-05-04 17:56:28.000000000 -0400
57880@@ -358,7 +358,7 @@ struct snd_ymfpci {
57881 spinlock_t reg_lock;
57882 spinlock_t voice_lock;
57883 wait_queue_head_t interrupt_sleep;
57884- atomic_t interrupt_sleep_count;
57885+ atomic_unchecked_t interrupt_sleep_count;
57886 struct snd_info_entry *proc_entry;
57887 const struct firmware *dsp_microcode;
57888 const struct firmware *controller_microcode;
57889diff -urNp linux-2.6.32.41/include/trace/events/irq.h linux-2.6.32.41/include/trace/events/irq.h
57890--- linux-2.6.32.41/include/trace/events/irq.h 2011-03-27 14:31:47.000000000 -0400
57891+++ linux-2.6.32.41/include/trace/events/irq.h 2011-04-17 15:56:46.000000000 -0400
57892@@ -34,7 +34,7 @@
57893 */
57894 TRACE_EVENT(irq_handler_entry,
57895
57896- TP_PROTO(int irq, struct irqaction *action),
57897+ TP_PROTO(int irq, const struct irqaction *action),
57898
57899 TP_ARGS(irq, action),
57900
57901@@ -64,7 +64,7 @@ TRACE_EVENT(irq_handler_entry,
57902 */
57903 TRACE_EVENT(irq_handler_exit,
57904
57905- TP_PROTO(int irq, struct irqaction *action, int ret),
57906+ TP_PROTO(int irq, const struct irqaction *action, int ret),
57907
57908 TP_ARGS(irq, action, ret),
57909
57910@@ -95,7 +95,7 @@ TRACE_EVENT(irq_handler_exit,
57911 */
57912 TRACE_EVENT(softirq_entry,
57913
57914- TP_PROTO(struct softirq_action *h, struct softirq_action *vec),
57915+ TP_PROTO(const struct softirq_action *h, const struct softirq_action *vec),
57916
57917 TP_ARGS(h, vec),
57918
57919@@ -124,7 +124,7 @@ TRACE_EVENT(softirq_entry,
57920 */
57921 TRACE_EVENT(softirq_exit,
57922
57923- TP_PROTO(struct softirq_action *h, struct softirq_action *vec),
57924+ TP_PROTO(const struct softirq_action *h, const struct softirq_action *vec),
57925
57926 TP_ARGS(h, vec),
57927
57928diff -urNp linux-2.6.32.41/include/video/uvesafb.h linux-2.6.32.41/include/video/uvesafb.h
57929--- linux-2.6.32.41/include/video/uvesafb.h 2011-03-27 14:31:47.000000000 -0400
57930+++ linux-2.6.32.41/include/video/uvesafb.h 2011-04-17 15:56:46.000000000 -0400
57931@@ -177,6 +177,7 @@ struct uvesafb_par {
57932 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
57933 u8 pmi_setpal; /* PMI for palette changes */
57934 u16 *pmi_base; /* protected mode interface location */
57935+ u8 *pmi_code; /* protected mode code location */
57936 void *pmi_start;
57937 void *pmi_pal;
57938 u8 *vbe_state_orig; /*
57939diff -urNp linux-2.6.32.41/init/do_mounts.c linux-2.6.32.41/init/do_mounts.c
57940--- linux-2.6.32.41/init/do_mounts.c 2011-03-27 14:31:47.000000000 -0400
57941+++ linux-2.6.32.41/init/do_mounts.c 2011-04-17 15:56:46.000000000 -0400
57942@@ -216,11 +216,11 @@ static void __init get_fs_names(char *pa
57943
57944 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
57945 {
57946- int err = sys_mount(name, "/root", fs, flags, data);
57947+ int err = sys_mount((__force char __user *)name, (__force char __user *)"/root", (__force char __user *)fs, flags, (__force void __user *)data);
57948 if (err)
57949 return err;
57950
57951- sys_chdir("/root");
57952+ sys_chdir((__force const char __user *)"/root");
57953 ROOT_DEV = current->fs->pwd.mnt->mnt_sb->s_dev;
57954 printk("VFS: Mounted root (%s filesystem)%s on device %u:%u.\n",
57955 current->fs->pwd.mnt->mnt_sb->s_type->name,
57956@@ -311,18 +311,18 @@ void __init change_floppy(char *fmt, ...
57957 va_start(args, fmt);
57958 vsprintf(buf, fmt, args);
57959 va_end(args);
57960- fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
57961+ fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
57962 if (fd >= 0) {
57963 sys_ioctl(fd, FDEJECT, 0);
57964 sys_close(fd);
57965 }
57966 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
57967- fd = sys_open("/dev/console", O_RDWR, 0);
57968+ fd = sys_open((char __user *)"/dev/console", O_RDWR, 0);
57969 if (fd >= 0) {
57970 sys_ioctl(fd, TCGETS, (long)&termios);
57971 termios.c_lflag &= ~ICANON;
57972 sys_ioctl(fd, TCSETSF, (long)&termios);
57973- sys_read(fd, &c, 1);
57974+ sys_read(fd, (char __user *)&c, 1);
57975 termios.c_lflag |= ICANON;
57976 sys_ioctl(fd, TCSETSF, (long)&termios);
57977 sys_close(fd);
57978@@ -416,6 +416,6 @@ void __init prepare_namespace(void)
57979 mount_root();
57980 out:
57981 devtmpfs_mount("dev");
57982- sys_mount(".", "/", NULL, MS_MOVE, NULL);
57983- sys_chroot(".");
57984+ sys_mount((__force char __user *)".", (__force char __user *)"/", NULL, MS_MOVE, NULL);
57985+ sys_chroot((__force char __user *)".");
57986 }
57987diff -urNp linux-2.6.32.41/init/do_mounts.h linux-2.6.32.41/init/do_mounts.h
57988--- linux-2.6.32.41/init/do_mounts.h 2011-03-27 14:31:47.000000000 -0400
57989+++ linux-2.6.32.41/init/do_mounts.h 2011-04-17 15:56:46.000000000 -0400
57990@@ -15,15 +15,15 @@ extern int root_mountflags;
57991
57992 static inline int create_dev(char *name, dev_t dev)
57993 {
57994- sys_unlink(name);
57995- return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
57996+ sys_unlink((__force char __user *)name);
57997+ return sys_mknod((__force char __user *)name, S_IFBLK|0600, new_encode_dev(dev));
57998 }
57999
58000 #if BITS_PER_LONG == 32
58001 static inline u32 bstat(char *name)
58002 {
58003 struct stat64 stat;
58004- if (sys_stat64(name, &stat) != 0)
58005+ if (sys_stat64((__force char __user *)name, (__force struct stat64 __user *)&stat) != 0)
58006 return 0;
58007 if (!S_ISBLK(stat.st_mode))
58008 return 0;
58009diff -urNp linux-2.6.32.41/init/do_mounts_initrd.c linux-2.6.32.41/init/do_mounts_initrd.c
58010--- linux-2.6.32.41/init/do_mounts_initrd.c 2011-03-27 14:31:47.000000000 -0400
58011+++ linux-2.6.32.41/init/do_mounts_initrd.c 2011-04-17 15:56:46.000000000 -0400
58012@@ -32,7 +32,7 @@ static int __init do_linuxrc(void * shel
58013 sys_close(old_fd);sys_close(root_fd);
58014 sys_close(0);sys_close(1);sys_close(2);
58015 sys_setsid();
58016- (void) sys_open("/dev/console",O_RDWR,0);
58017+ (void) sys_open((__force const char __user *)"/dev/console",O_RDWR,0);
58018 (void) sys_dup(0);
58019 (void) sys_dup(0);
58020 return kernel_execve(shell, argv, envp_init);
58021@@ -47,13 +47,13 @@ static void __init handle_initrd(void)
58022 create_dev("/dev/root.old", Root_RAM0);
58023 /* mount initrd on rootfs' /root */
58024 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
58025- sys_mkdir("/old", 0700);
58026- root_fd = sys_open("/", 0, 0);
58027- old_fd = sys_open("/old", 0, 0);
58028+ sys_mkdir((__force const char __user *)"/old", 0700);
58029+ root_fd = sys_open((__force const char __user *)"/", 0, 0);
58030+ old_fd = sys_open((__force const char __user *)"/old", 0, 0);
58031 /* move initrd over / and chdir/chroot in initrd root */
58032- sys_chdir("/root");
58033- sys_mount(".", "/", NULL, MS_MOVE, NULL);
58034- sys_chroot(".");
58035+ sys_chdir((__force const char __user *)"/root");
58036+ sys_mount((__force char __user *)".", (__force char __user *)"/", NULL, MS_MOVE, NULL);
58037+ sys_chroot((__force const char __user *)".");
58038
58039 /*
58040 * In case that a resume from disk is carried out by linuxrc or one of
58041@@ -70,15 +70,15 @@ static void __init handle_initrd(void)
58042
58043 /* move initrd to rootfs' /old */
58044 sys_fchdir(old_fd);
58045- sys_mount("/", ".", NULL, MS_MOVE, NULL);
58046+ sys_mount((__force char __user *)"/", (__force char __user *)".", NULL, MS_MOVE, NULL);
58047 /* switch root and cwd back to / of rootfs */
58048 sys_fchdir(root_fd);
58049- sys_chroot(".");
58050+ sys_chroot((__force const char __user *)".");
58051 sys_close(old_fd);
58052 sys_close(root_fd);
58053
58054 if (new_decode_dev(real_root_dev) == Root_RAM0) {
58055- sys_chdir("/old");
58056+ sys_chdir((__force const char __user *)"/old");
58057 return;
58058 }
58059
58060@@ -86,17 +86,17 @@ static void __init handle_initrd(void)
58061 mount_root();
58062
58063 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
58064- error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
58065+ error = sys_mount((__force char __user *)"/old", (__force char __user *)"/root/initrd", NULL, MS_MOVE, NULL);
58066 if (!error)
58067 printk("okay\n");
58068 else {
58069- int fd = sys_open("/dev/root.old", O_RDWR, 0);
58070+ int fd = sys_open((__force const char __user *)"/dev/root.old", O_RDWR, 0);
58071 if (error == -ENOENT)
58072 printk("/initrd does not exist. Ignored.\n");
58073 else
58074 printk("failed\n");
58075 printk(KERN_NOTICE "Unmounting old root\n");
58076- sys_umount("/old", MNT_DETACH);
58077+ sys_umount((__force char __user *)"/old", MNT_DETACH);
58078 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
58079 if (fd < 0) {
58080 error = fd;
58081@@ -119,11 +119,11 @@ int __init initrd_load(void)
58082 * mounted in the normal path.
58083 */
58084 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
58085- sys_unlink("/initrd.image");
58086+ sys_unlink((__force const char __user *)"/initrd.image");
58087 handle_initrd();
58088 return 1;
58089 }
58090 }
58091- sys_unlink("/initrd.image");
58092+ sys_unlink((__force const char __user *)"/initrd.image");
58093 return 0;
58094 }
58095diff -urNp linux-2.6.32.41/init/do_mounts_md.c linux-2.6.32.41/init/do_mounts_md.c
58096--- linux-2.6.32.41/init/do_mounts_md.c 2011-03-27 14:31:47.000000000 -0400
58097+++ linux-2.6.32.41/init/do_mounts_md.c 2011-04-17 15:56:46.000000000 -0400
58098@@ -170,7 +170,7 @@ static void __init md_setup_drive(void)
58099 partitioned ? "_d" : "", minor,
58100 md_setup_args[ent].device_names);
58101
58102- fd = sys_open(name, 0, 0);
58103+ fd = sys_open((__force char __user *)name, 0, 0);
58104 if (fd < 0) {
58105 printk(KERN_ERR "md: open failed - cannot start "
58106 "array %s\n", name);
58107@@ -233,7 +233,7 @@ static void __init md_setup_drive(void)
58108 * array without it
58109 */
58110 sys_close(fd);
58111- fd = sys_open(name, 0, 0);
58112+ fd = sys_open((__force char __user *)name, 0, 0);
58113 sys_ioctl(fd, BLKRRPART, 0);
58114 }
58115 sys_close(fd);
58116@@ -283,7 +283,7 @@ static void __init autodetect_raid(void)
58117
58118 wait_for_device_probe();
58119
58120- fd = sys_open("/dev/md0", 0, 0);
58121+ fd = sys_open((__force char __user *)"/dev/md0", 0, 0);
58122 if (fd >= 0) {
58123 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
58124 sys_close(fd);
58125diff -urNp linux-2.6.32.41/init/initramfs.c linux-2.6.32.41/init/initramfs.c
58126--- linux-2.6.32.41/init/initramfs.c 2011-03-27 14:31:47.000000000 -0400
58127+++ linux-2.6.32.41/init/initramfs.c 2011-04-17 15:56:46.000000000 -0400
58128@@ -74,7 +74,7 @@ static void __init free_hash(void)
58129 }
58130 }
58131
58132-static long __init do_utime(char __user *filename, time_t mtime)
58133+static long __init do_utime(__force char __user *filename, time_t mtime)
58134 {
58135 struct timespec t[2];
58136
58137@@ -109,7 +109,7 @@ static void __init dir_utime(void)
58138 struct dir_entry *de, *tmp;
58139 list_for_each_entry_safe(de, tmp, &dir_list, list) {
58140 list_del(&de->list);
58141- do_utime(de->name, de->mtime);
58142+ do_utime((__force char __user *)de->name, de->mtime);
58143 kfree(de->name);
58144 kfree(de);
58145 }
58146@@ -271,7 +271,7 @@ static int __init maybe_link(void)
58147 if (nlink >= 2) {
58148 char *old = find_link(major, minor, ino, mode, collected);
58149 if (old)
58150- return (sys_link(old, collected) < 0) ? -1 : 1;
58151+ return (sys_link((__force char __user *)old, (__force char __user *)collected) < 0) ? -1 : 1;
58152 }
58153 return 0;
58154 }
58155@@ -280,11 +280,11 @@ static void __init clean_path(char *path
58156 {
58157 struct stat st;
58158
58159- if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
58160+ if (!sys_newlstat((__force char __user *)path, (__force struct stat __user *)&st) && (st.st_mode^mode) & S_IFMT) {
58161 if (S_ISDIR(st.st_mode))
58162- sys_rmdir(path);
58163+ sys_rmdir((__force char __user *)path);
58164 else
58165- sys_unlink(path);
58166+ sys_unlink((__force char __user *)path);
58167 }
58168 }
58169
58170@@ -305,7 +305,7 @@ static int __init do_name(void)
58171 int openflags = O_WRONLY|O_CREAT;
58172 if (ml != 1)
58173 openflags |= O_TRUNC;
58174- wfd = sys_open(collected, openflags, mode);
58175+ wfd = sys_open((__force char __user *)collected, openflags, mode);
58176
58177 if (wfd >= 0) {
58178 sys_fchown(wfd, uid, gid);
58179@@ -317,17 +317,17 @@ static int __init do_name(void)
58180 }
58181 }
58182 } else if (S_ISDIR(mode)) {
58183- sys_mkdir(collected, mode);
58184- sys_chown(collected, uid, gid);
58185- sys_chmod(collected, mode);
58186+ sys_mkdir((__force char __user *)collected, mode);
58187+ sys_chown((__force char __user *)collected, uid, gid);
58188+ sys_chmod((__force char __user *)collected, mode);
58189 dir_add(collected, mtime);
58190 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
58191 S_ISFIFO(mode) || S_ISSOCK(mode)) {
58192 if (maybe_link() == 0) {
58193- sys_mknod(collected, mode, rdev);
58194- sys_chown(collected, uid, gid);
58195- sys_chmod(collected, mode);
58196- do_utime(collected, mtime);
58197+ sys_mknod((__force char __user *)collected, mode, rdev);
58198+ sys_chown((__force char __user *)collected, uid, gid);
58199+ sys_chmod((__force char __user *)collected, mode);
58200+ do_utime((__force char __user *)collected, mtime);
58201 }
58202 }
58203 return 0;
58204@@ -336,15 +336,15 @@ static int __init do_name(void)
58205 static int __init do_copy(void)
58206 {
58207 if (count >= body_len) {
58208- sys_write(wfd, victim, body_len);
58209+ sys_write(wfd, (__force char __user *)victim, body_len);
58210 sys_close(wfd);
58211- do_utime(vcollected, mtime);
58212+ do_utime((__force char __user *)vcollected, mtime);
58213 kfree(vcollected);
58214 eat(body_len);
58215 state = SkipIt;
58216 return 0;
58217 } else {
58218- sys_write(wfd, victim, count);
58219+ sys_write(wfd, (__force char __user *)victim, count);
58220 body_len -= count;
58221 eat(count);
58222 return 1;
58223@@ -355,9 +355,9 @@ static int __init do_symlink(void)
58224 {
58225 collected[N_ALIGN(name_len) + body_len] = '\0';
58226 clean_path(collected, 0);
58227- sys_symlink(collected + N_ALIGN(name_len), collected);
58228- sys_lchown(collected, uid, gid);
58229- do_utime(collected, mtime);
58230+ sys_symlink((__force char __user *)collected + N_ALIGN(name_len), (__force char __user *)collected);
58231+ sys_lchown((__force char __user *)collected, uid, gid);
58232+ do_utime((__force char __user *)collected, mtime);
58233 state = SkipIt;
58234 next_state = Reset;
58235 return 0;
58236diff -urNp linux-2.6.32.41/init/Kconfig linux-2.6.32.41/init/Kconfig
58237--- linux-2.6.32.41/init/Kconfig 2011-05-10 22:12:01.000000000 -0400
58238+++ linux-2.6.32.41/init/Kconfig 2011-05-10 22:12:34.000000000 -0400
58239@@ -1004,7 +1004,7 @@ config SLUB_DEBUG
58240
58241 config COMPAT_BRK
58242 bool "Disable heap randomization"
58243- default y
58244+ default n
58245 help
58246 Randomizing heap placement makes heap exploits harder, but it
58247 also breaks ancient binaries (including anything libc5 based).
58248diff -urNp linux-2.6.32.41/init/main.c linux-2.6.32.41/init/main.c
58249--- linux-2.6.32.41/init/main.c 2011-05-10 22:12:01.000000000 -0400
58250+++ linux-2.6.32.41/init/main.c 2011-05-22 23:02:06.000000000 -0400
58251@@ -97,6 +97,7 @@ static inline void mark_rodata_ro(void)
58252 #ifdef CONFIG_TC
58253 extern void tc_init(void);
58254 #endif
58255+extern void grsecurity_init(void);
58256
58257 enum system_states system_state __read_mostly;
58258 EXPORT_SYMBOL(system_state);
58259@@ -183,6 +184,49 @@ static int __init set_reset_devices(char
58260
58261 __setup("reset_devices", set_reset_devices);
58262
58263+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
58264+extern char pax_enter_kernel_user[];
58265+extern char pax_exit_kernel_user[];
58266+extern pgdval_t clone_pgd_mask;
58267+#endif
58268+
58269+#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
58270+static int __init setup_pax_nouderef(char *str)
58271+{
58272+#ifdef CONFIG_X86_32
58273+ unsigned int cpu;
58274+ struct desc_struct *gdt;
58275+
58276+ for (cpu = 0; cpu < NR_CPUS; cpu++) {
58277+ gdt = get_cpu_gdt_table(cpu);
58278+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
58279+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
58280+ gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
58281+ gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
58282+ }
58283+ asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r" (__KERNEL_DS) : "memory");
58284+#else
58285+ memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
58286+ memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
58287+ clone_pgd_mask = ~(pgdval_t)0UL;
58288+#endif
58289+
58290+ return 0;
58291+}
58292+early_param("pax_nouderef", setup_pax_nouderef);
58293+#endif
58294+
58295+#ifdef CONFIG_PAX_SOFTMODE
58296+unsigned int pax_softmode;
58297+
58298+static int __init setup_pax_softmode(char *str)
58299+{
58300+ get_option(&str, &pax_softmode);
58301+ return 1;
58302+}
58303+__setup("pax_softmode=", setup_pax_softmode);
58304+#endif
58305+
58306 static char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
58307 char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
58308 static const char *panic_later, *panic_param;
58309@@ -705,52 +749,53 @@ int initcall_debug;
58310 core_param(initcall_debug, initcall_debug, bool, 0644);
58311
58312 static char msgbuf[64];
58313-static struct boot_trace_call call;
58314-static struct boot_trace_ret ret;
58315+static struct boot_trace_call trace_call;
58316+static struct boot_trace_ret trace_ret;
58317
58318 int do_one_initcall(initcall_t fn)
58319 {
58320 int count = preempt_count();
58321 ktime_t calltime, delta, rettime;
58322+ const char *msg1 = "", *msg2 = "";
58323
58324 if (initcall_debug) {
58325- call.caller = task_pid_nr(current);
58326- printk("calling %pF @ %i\n", fn, call.caller);
58327+ trace_call.caller = task_pid_nr(current);
58328+ printk("calling %pF @ %i\n", fn, trace_call.caller);
58329 calltime = ktime_get();
58330- trace_boot_call(&call, fn);
58331+ trace_boot_call(&trace_call, fn);
58332 enable_boot_trace();
58333 }
58334
58335- ret.result = fn();
58336+ trace_ret.result = fn();
58337
58338 if (initcall_debug) {
58339 disable_boot_trace();
58340 rettime = ktime_get();
58341 delta = ktime_sub(rettime, calltime);
58342- ret.duration = (unsigned long long) ktime_to_ns(delta) >> 10;
58343- trace_boot_ret(&ret, fn);
58344+ trace_ret.duration = (unsigned long long) ktime_to_ns(delta) >> 10;
58345+ trace_boot_ret(&trace_ret, fn);
58346 printk("initcall %pF returned %d after %Ld usecs\n", fn,
58347- ret.result, ret.duration);
58348+ trace_ret.result, trace_ret.duration);
58349 }
58350
58351 msgbuf[0] = 0;
58352
58353- if (ret.result && ret.result != -ENODEV && initcall_debug)
58354- sprintf(msgbuf, "error code %d ", ret.result);
58355+ if (trace_ret.result && trace_ret.result != -ENODEV && initcall_debug)
58356+ sprintf(msgbuf, "error code %d ", trace_ret.result);
58357
58358 if (preempt_count() != count) {
58359- strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
58360+ msg1 = " preemption imbalance";
58361 preempt_count() = count;
58362 }
58363 if (irqs_disabled()) {
58364- strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
58365+ msg2 = " disabled interrupts";
58366 local_irq_enable();
58367 }
58368- if (msgbuf[0]) {
58369- printk("initcall %pF returned with %s\n", fn, msgbuf);
58370+ if (msgbuf[0] || *msg1 || *msg2) {
58371+ printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
58372 }
58373
58374- return ret.result;
58375+ return trace_ret.result;
58376 }
58377
58378
58379@@ -893,11 +938,13 @@ static int __init kernel_init(void * unu
58380 if (!ramdisk_execute_command)
58381 ramdisk_execute_command = "/init";
58382
58383- if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
58384+ if (sys_access((__force const char __user *) ramdisk_execute_command, 0) != 0) {
58385 ramdisk_execute_command = NULL;
58386 prepare_namespace();
58387 }
58388
58389+ grsecurity_init();
58390+
58391 /*
58392 * Ok, we have completed the initial bootup, and
58393 * we're essentially up and running. Get rid of the
58394diff -urNp linux-2.6.32.41/init/noinitramfs.c linux-2.6.32.41/init/noinitramfs.c
58395--- linux-2.6.32.41/init/noinitramfs.c 2011-03-27 14:31:47.000000000 -0400
58396+++ linux-2.6.32.41/init/noinitramfs.c 2011-04-17 15:56:46.000000000 -0400
58397@@ -29,7 +29,7 @@ static int __init default_rootfs(void)
58398 {
58399 int err;
58400
58401- err = sys_mkdir("/dev", 0755);
58402+ err = sys_mkdir((const char __user *)"/dev", 0755);
58403 if (err < 0)
58404 goto out;
58405
58406@@ -39,7 +39,7 @@ static int __init default_rootfs(void)
58407 if (err < 0)
58408 goto out;
58409
58410- err = sys_mkdir("/root", 0700);
58411+ err = sys_mkdir((const char __user *)"/root", 0700);
58412 if (err < 0)
58413 goto out;
58414
58415diff -urNp linux-2.6.32.41/ipc/mqueue.c linux-2.6.32.41/ipc/mqueue.c
58416--- linux-2.6.32.41/ipc/mqueue.c 2011-03-27 14:31:47.000000000 -0400
58417+++ linux-2.6.32.41/ipc/mqueue.c 2011-04-17 15:56:46.000000000 -0400
58418@@ -150,6 +150,7 @@ static struct inode *mqueue_get_inode(st
58419 mq_bytes = (mq_msg_tblsz +
58420 (info->attr.mq_maxmsg * info->attr.mq_msgsize));
58421
58422+ gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
58423 spin_lock(&mq_lock);
58424 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
58425 u->mq_bytes + mq_bytes >
58426diff -urNp linux-2.6.32.41/ipc/sem.c linux-2.6.32.41/ipc/sem.c
58427--- linux-2.6.32.41/ipc/sem.c 2011-03-27 14:31:47.000000000 -0400
58428+++ linux-2.6.32.41/ipc/sem.c 2011-05-16 21:46:57.000000000 -0400
58429@@ -671,6 +671,8 @@ static int semctl_main(struct ipc_namesp
58430 ushort* sem_io = fast_sem_io;
58431 int nsems;
58432
58433+ pax_track_stack();
58434+
58435 sma = sem_lock_check(ns, semid);
58436 if (IS_ERR(sma))
58437 return PTR_ERR(sma);
58438@@ -1071,6 +1073,8 @@ SYSCALL_DEFINE4(semtimedop, int, semid,
58439 unsigned long jiffies_left = 0;
58440 struct ipc_namespace *ns;
58441
58442+ pax_track_stack();
58443+
58444 ns = current->nsproxy->ipc_ns;
58445
58446 if (nsops < 1 || semid < 0)
58447diff -urNp linux-2.6.32.41/ipc/shm.c linux-2.6.32.41/ipc/shm.c
58448--- linux-2.6.32.41/ipc/shm.c 2011-03-27 14:31:47.000000000 -0400
58449+++ linux-2.6.32.41/ipc/shm.c 2011-04-17 15:56:46.000000000 -0400
58450@@ -70,6 +70,14 @@ static void shm_destroy (struct ipc_name
58451 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
58452 #endif
58453
58454+#ifdef CONFIG_GRKERNSEC
58455+extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
58456+ const time_t shm_createtime, const uid_t cuid,
58457+ const int shmid);
58458+extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
58459+ const time_t shm_createtime);
58460+#endif
58461+
58462 void shm_init_ns(struct ipc_namespace *ns)
58463 {
58464 ns->shm_ctlmax = SHMMAX;
58465@@ -396,6 +404,14 @@ static int newseg(struct ipc_namespace *
58466 shp->shm_lprid = 0;
58467 shp->shm_atim = shp->shm_dtim = 0;
58468 shp->shm_ctim = get_seconds();
58469+#ifdef CONFIG_GRKERNSEC
58470+ {
58471+ struct timespec timeval;
58472+ do_posix_clock_monotonic_gettime(&timeval);
58473+
58474+ shp->shm_createtime = timeval.tv_sec;
58475+ }
58476+#endif
58477 shp->shm_segsz = size;
58478 shp->shm_nattch = 0;
58479 shp->shm_file = file;
58480@@ -880,9 +896,21 @@ long do_shmat(int shmid, char __user *sh
58481 if (err)
58482 goto out_unlock;
58483
58484+#ifdef CONFIG_GRKERNSEC
58485+ if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
58486+ shp->shm_perm.cuid, shmid) ||
58487+ !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
58488+ err = -EACCES;
58489+ goto out_unlock;
58490+ }
58491+#endif
58492+
58493 path.dentry = dget(shp->shm_file->f_path.dentry);
58494 path.mnt = shp->shm_file->f_path.mnt;
58495 shp->shm_nattch++;
58496+#ifdef CONFIG_GRKERNSEC
58497+ shp->shm_lapid = current->pid;
58498+#endif
58499 size = i_size_read(path.dentry->d_inode);
58500 shm_unlock(shp);
58501
58502diff -urNp linux-2.6.32.41/kernel/acct.c linux-2.6.32.41/kernel/acct.c
58503--- linux-2.6.32.41/kernel/acct.c 2011-03-27 14:31:47.000000000 -0400
58504+++ linux-2.6.32.41/kernel/acct.c 2011-04-17 15:56:46.000000000 -0400
58505@@ -579,7 +579,7 @@ static void do_acct_process(struct bsd_a
58506 */
58507 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
58508 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
58509- file->f_op->write(file, (char *)&ac,
58510+ file->f_op->write(file, (__force char __user *)&ac,
58511 sizeof(acct_t), &file->f_pos);
58512 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
58513 set_fs(fs);
58514diff -urNp linux-2.6.32.41/kernel/audit.c linux-2.6.32.41/kernel/audit.c
58515--- linux-2.6.32.41/kernel/audit.c 2011-03-27 14:31:47.000000000 -0400
58516+++ linux-2.6.32.41/kernel/audit.c 2011-05-04 17:56:28.000000000 -0400
58517@@ -110,7 +110,7 @@ u32 audit_sig_sid = 0;
58518 3) suppressed due to audit_rate_limit
58519 4) suppressed due to audit_backlog_limit
58520 */
58521-static atomic_t audit_lost = ATOMIC_INIT(0);
58522+static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
58523
58524 /* The netlink socket. */
58525 static struct sock *audit_sock;
58526@@ -232,7 +232,7 @@ void audit_log_lost(const char *message)
58527 unsigned long now;
58528 int print;
58529
58530- atomic_inc(&audit_lost);
58531+ atomic_inc_unchecked(&audit_lost);
58532
58533 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
58534
58535@@ -251,7 +251,7 @@ void audit_log_lost(const char *message)
58536 printk(KERN_WARNING
58537 "audit: audit_lost=%d audit_rate_limit=%d "
58538 "audit_backlog_limit=%d\n",
58539- atomic_read(&audit_lost),
58540+ atomic_read_unchecked(&audit_lost),
58541 audit_rate_limit,
58542 audit_backlog_limit);
58543 audit_panic(message);
58544@@ -691,7 +691,7 @@ static int audit_receive_msg(struct sk_b
58545 status_set.pid = audit_pid;
58546 status_set.rate_limit = audit_rate_limit;
58547 status_set.backlog_limit = audit_backlog_limit;
58548- status_set.lost = atomic_read(&audit_lost);
58549+ status_set.lost = atomic_read_unchecked(&audit_lost);
58550 status_set.backlog = skb_queue_len(&audit_skb_queue);
58551 audit_send_reply(NETLINK_CB(skb).pid, seq, AUDIT_GET, 0, 0,
58552 &status_set, sizeof(status_set));
58553@@ -891,8 +891,10 @@ static int audit_receive_msg(struct sk_b
58554 spin_unlock_irq(&tsk->sighand->siglock);
58555 }
58556 read_unlock(&tasklist_lock);
58557- audit_send_reply(NETLINK_CB(skb).pid, seq, AUDIT_TTY_GET, 0, 0,
58558- &s, sizeof(s));
58559+
58560+ if (!err)
58561+ audit_send_reply(NETLINK_CB(skb).pid, seq,
58562+ AUDIT_TTY_GET, 0, 0, &s, sizeof(s));
58563 break;
58564 }
58565 case AUDIT_TTY_SET: {
58566diff -urNp linux-2.6.32.41/kernel/auditsc.c linux-2.6.32.41/kernel/auditsc.c
58567--- linux-2.6.32.41/kernel/auditsc.c 2011-03-27 14:31:47.000000000 -0400
58568+++ linux-2.6.32.41/kernel/auditsc.c 2011-05-04 17:56:28.000000000 -0400
58569@@ -2113,7 +2113,7 @@ int auditsc_get_stamp(struct audit_conte
58570 }
58571
58572 /* global counter which is incremented every time something logs in */
58573-static atomic_t session_id = ATOMIC_INIT(0);
58574+static atomic_unchecked_t session_id = ATOMIC_INIT(0);
58575
58576 /**
58577 * audit_set_loginuid - set a task's audit_context loginuid
58578@@ -2126,7 +2126,7 @@ static atomic_t session_id = ATOMIC_INIT
58579 */
58580 int audit_set_loginuid(struct task_struct *task, uid_t loginuid)
58581 {
58582- unsigned int sessionid = atomic_inc_return(&session_id);
58583+ unsigned int sessionid = atomic_inc_return_unchecked(&session_id);
58584 struct audit_context *context = task->audit_context;
58585
58586 if (context && context->in_syscall) {
58587diff -urNp linux-2.6.32.41/kernel/capability.c linux-2.6.32.41/kernel/capability.c
58588--- linux-2.6.32.41/kernel/capability.c 2011-03-27 14:31:47.000000000 -0400
58589+++ linux-2.6.32.41/kernel/capability.c 2011-04-17 15:56:46.000000000 -0400
58590@@ -305,10 +305,26 @@ int capable(int cap)
58591 BUG();
58592 }
58593
58594- if (security_capable(cap) == 0) {
58595+ if (security_capable(cap) == 0 && gr_is_capable(cap)) {
58596 current->flags |= PF_SUPERPRIV;
58597 return 1;
58598 }
58599 return 0;
58600 }
58601+
58602+int capable_nolog(int cap)
58603+{
58604+ if (unlikely(!cap_valid(cap))) {
58605+ printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
58606+ BUG();
58607+ }
58608+
58609+ if (security_capable(cap) == 0 && gr_is_capable_nolog(cap)) {
58610+ current->flags |= PF_SUPERPRIV;
58611+ return 1;
58612+ }
58613+ return 0;
58614+}
58615+
58616 EXPORT_SYMBOL(capable);
58617+EXPORT_SYMBOL(capable_nolog);
58618diff -urNp linux-2.6.32.41/kernel/cgroup.c linux-2.6.32.41/kernel/cgroup.c
58619--- linux-2.6.32.41/kernel/cgroup.c 2011-03-27 14:31:47.000000000 -0400
58620+++ linux-2.6.32.41/kernel/cgroup.c 2011-05-16 21:46:57.000000000 -0400
58621@@ -536,6 +536,8 @@ static struct css_set *find_css_set(
58622 struct hlist_head *hhead;
58623 struct cg_cgroup_link *link;
58624
58625+ pax_track_stack();
58626+
58627 /* First see if we already have a cgroup group that matches
58628 * the desired set */
58629 read_lock(&css_set_lock);
58630diff -urNp linux-2.6.32.41/kernel/configs.c linux-2.6.32.41/kernel/configs.c
58631--- linux-2.6.32.41/kernel/configs.c 2011-03-27 14:31:47.000000000 -0400
58632+++ linux-2.6.32.41/kernel/configs.c 2011-04-17 15:56:46.000000000 -0400
58633@@ -73,8 +73,19 @@ static int __init ikconfig_init(void)
58634 struct proc_dir_entry *entry;
58635
58636 /* create the current config file */
58637+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
58638+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
58639+ entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
58640+ &ikconfig_file_ops);
58641+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
58642+ entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
58643+ &ikconfig_file_ops);
58644+#endif
58645+#else
58646 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
58647 &ikconfig_file_ops);
58648+#endif
58649+
58650 if (!entry)
58651 return -ENOMEM;
58652
58653diff -urNp linux-2.6.32.41/kernel/cpu.c linux-2.6.32.41/kernel/cpu.c
58654--- linux-2.6.32.41/kernel/cpu.c 2011-03-27 14:31:47.000000000 -0400
58655+++ linux-2.6.32.41/kernel/cpu.c 2011-04-17 15:56:46.000000000 -0400
58656@@ -19,7 +19,7 @@
58657 /* Serializes the updates to cpu_online_mask, cpu_present_mask */
58658 static DEFINE_MUTEX(cpu_add_remove_lock);
58659
58660-static __cpuinitdata RAW_NOTIFIER_HEAD(cpu_chain);
58661+static RAW_NOTIFIER_HEAD(cpu_chain);
58662
58663 /* If set, cpu_up and cpu_down will return -EBUSY and do nothing.
58664 * Should always be manipulated under cpu_add_remove_lock
58665diff -urNp linux-2.6.32.41/kernel/cred.c linux-2.6.32.41/kernel/cred.c
58666--- linux-2.6.32.41/kernel/cred.c 2011-03-27 14:31:47.000000000 -0400
58667+++ linux-2.6.32.41/kernel/cred.c 2011-05-17 19:26:34.000000000 -0400
58668@@ -160,6 +160,8 @@ static void put_cred_rcu(struct rcu_head
58669 */
58670 void __put_cred(struct cred *cred)
58671 {
58672+ pax_track_stack();
58673+
58674 kdebug("__put_cred(%p{%d,%d})", cred,
58675 atomic_read(&cred->usage),
58676 read_cred_subscribers(cred));
58677@@ -184,6 +186,8 @@ void exit_creds(struct task_struct *tsk)
58678 {
58679 struct cred *cred;
58680
58681+ pax_track_stack();
58682+
58683 kdebug("exit_creds(%u,%p,%p,{%d,%d})", tsk->pid, tsk->real_cred, tsk->cred,
58684 atomic_read(&tsk->cred->usage),
58685 read_cred_subscribers(tsk->cred));
58686@@ -222,6 +226,8 @@ const struct cred *get_task_cred(struct
58687 {
58688 const struct cred *cred;
58689
58690+ pax_track_stack();
58691+
58692 rcu_read_lock();
58693
58694 do {
58695@@ -241,6 +247,8 @@ struct cred *cred_alloc_blank(void)
58696 {
58697 struct cred *new;
58698
58699+ pax_track_stack();
58700+
58701 new = kmem_cache_zalloc(cred_jar, GFP_KERNEL);
58702 if (!new)
58703 return NULL;
58704@@ -289,6 +297,8 @@ struct cred *prepare_creds(void)
58705 const struct cred *old;
58706 struct cred *new;
58707
58708+ pax_track_stack();
58709+
58710 validate_process_creds();
58711
58712 new = kmem_cache_alloc(cred_jar, GFP_KERNEL);
58713@@ -335,6 +345,8 @@ struct cred *prepare_exec_creds(void)
58714 struct thread_group_cred *tgcred = NULL;
58715 struct cred *new;
58716
58717+ pax_track_stack();
58718+
58719 #ifdef CONFIG_KEYS
58720 tgcred = kmalloc(sizeof(*tgcred), GFP_KERNEL);
58721 if (!tgcred)
58722@@ -441,6 +453,8 @@ int copy_creds(struct task_struct *p, un
58723 struct cred *new;
58724 int ret;
58725
58726+ pax_track_stack();
58727+
58728 mutex_init(&p->cred_guard_mutex);
58729
58730 if (
58731@@ -528,6 +542,8 @@ int commit_creds(struct cred *new)
58732 struct task_struct *task = current;
58733 const struct cred *old = task->real_cred;
58734
58735+ pax_track_stack();
58736+
58737 kdebug("commit_creds(%p{%d,%d})", new,
58738 atomic_read(&new->usage),
58739 read_cred_subscribers(new));
58740@@ -544,6 +560,8 @@ int commit_creds(struct cred *new)
58741
58742 get_cred(new); /* we will require a ref for the subj creds too */
58743
58744+ gr_set_role_label(task, new->uid, new->gid);
58745+
58746 /* dumpability changes */
58747 if (old->euid != new->euid ||
58748 old->egid != new->egid ||
58749@@ -606,6 +624,8 @@ EXPORT_SYMBOL(commit_creds);
58750 */
58751 void abort_creds(struct cred *new)
58752 {
58753+ pax_track_stack();
58754+
58755 kdebug("abort_creds(%p{%d,%d})", new,
58756 atomic_read(&new->usage),
58757 read_cred_subscribers(new));
58758@@ -629,6 +649,8 @@ const struct cred *override_creds(const
58759 {
58760 const struct cred *old = current->cred;
58761
58762+ pax_track_stack();
58763+
58764 kdebug("override_creds(%p{%d,%d})", new,
58765 atomic_read(&new->usage),
58766 read_cred_subscribers(new));
58767@@ -658,6 +680,8 @@ void revert_creds(const struct cred *old
58768 {
58769 const struct cred *override = current->cred;
58770
58771+ pax_track_stack();
58772+
58773 kdebug("revert_creds(%p{%d,%d})", old,
58774 atomic_read(&old->usage),
58775 read_cred_subscribers(old));
58776@@ -704,6 +728,8 @@ struct cred *prepare_kernel_cred(struct
58777 const struct cred *old;
58778 struct cred *new;
58779
58780+ pax_track_stack();
58781+
58782 new = kmem_cache_alloc(cred_jar, GFP_KERNEL);
58783 if (!new)
58784 return NULL;
58785@@ -758,6 +784,8 @@ EXPORT_SYMBOL(prepare_kernel_cred);
58786 */
58787 int set_security_override(struct cred *new, u32 secid)
58788 {
58789+ pax_track_stack();
58790+
58791 return security_kernel_act_as(new, secid);
58792 }
58793 EXPORT_SYMBOL(set_security_override);
58794@@ -777,6 +805,8 @@ int set_security_override_from_ctx(struc
58795 u32 secid;
58796 int ret;
58797
58798+ pax_track_stack();
58799+
58800 ret = security_secctx_to_secid(secctx, strlen(secctx), &secid);
58801 if (ret < 0)
58802 return ret;
58803diff -urNp linux-2.6.32.41/kernel/exit.c linux-2.6.32.41/kernel/exit.c
58804--- linux-2.6.32.41/kernel/exit.c 2011-03-27 14:31:47.000000000 -0400
58805+++ linux-2.6.32.41/kernel/exit.c 2011-04-17 15:56:46.000000000 -0400
58806@@ -55,6 +55,10 @@
58807 #include <asm/pgtable.h>
58808 #include <asm/mmu_context.h>
58809
58810+#ifdef CONFIG_GRKERNSEC
58811+extern rwlock_t grsec_exec_file_lock;
58812+#endif
58813+
58814 static void exit_mm(struct task_struct * tsk);
58815
58816 static void __unhash_process(struct task_struct *p)
58817@@ -174,6 +178,8 @@ void release_task(struct task_struct * p
58818 struct task_struct *leader;
58819 int zap_leader;
58820 repeat:
58821+ gr_del_task_from_ip_table(p);
58822+
58823 tracehook_prepare_release_task(p);
58824 /* don't need to get the RCU readlock here - the process is dead and
58825 * can't be modifying its own credentials */
58826@@ -341,11 +347,22 @@ static void reparent_to_kthreadd(void)
58827 {
58828 write_lock_irq(&tasklist_lock);
58829
58830+#ifdef CONFIG_GRKERNSEC
58831+ write_lock(&grsec_exec_file_lock);
58832+ if (current->exec_file) {
58833+ fput(current->exec_file);
58834+ current->exec_file = NULL;
58835+ }
58836+ write_unlock(&grsec_exec_file_lock);
58837+#endif
58838+
58839 ptrace_unlink(current);
58840 /* Reparent to init */
58841 current->real_parent = current->parent = kthreadd_task;
58842 list_move_tail(&current->sibling, &current->real_parent->children);
58843
58844+ gr_set_kernel_label(current);
58845+
58846 /* Set the exit signal to SIGCHLD so we signal init on exit */
58847 current->exit_signal = SIGCHLD;
58848
58849@@ -397,7 +414,7 @@ int allow_signal(int sig)
58850 * know it'll be handled, so that they don't get converted to
58851 * SIGKILL or just silently dropped.
58852 */
58853- current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
58854+ current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
58855 recalc_sigpending();
58856 spin_unlock_irq(&current->sighand->siglock);
58857 return 0;
58858@@ -433,6 +450,17 @@ void daemonize(const char *name, ...)
58859 vsnprintf(current->comm, sizeof(current->comm), name, args);
58860 va_end(args);
58861
58862+#ifdef CONFIG_GRKERNSEC
58863+ write_lock(&grsec_exec_file_lock);
58864+ if (current->exec_file) {
58865+ fput(current->exec_file);
58866+ current->exec_file = NULL;
58867+ }
58868+ write_unlock(&grsec_exec_file_lock);
58869+#endif
58870+
58871+ gr_set_kernel_label(current);
58872+
58873 /*
58874 * If we were started as result of loading a module, close all of the
58875 * user space pages. We don't need them, and if we didn't close them
58876@@ -897,17 +925,17 @@ NORET_TYPE void do_exit(long code)
58877 struct task_struct *tsk = current;
58878 int group_dead;
58879
58880- profile_task_exit(tsk);
58881-
58882- WARN_ON(atomic_read(&tsk->fs_excl));
58883-
58884+ /*
58885+ * Check this first since set_fs() below depends on
58886+ * current_thread_info(), which we better not access when we're in
58887+ * interrupt context. Other than that, we want to do the set_fs()
58888+ * as early as possible.
58889+ */
58890 if (unlikely(in_interrupt()))
58891 panic("Aiee, killing interrupt handler!");
58892- if (unlikely(!tsk->pid))
58893- panic("Attempted to kill the idle task!");
58894
58895 /*
58896- * If do_exit is called because this processes oopsed, it's possible
58897+ * If do_exit is called because this processes Oops'ed, it's possible
58898 * that get_fs() was left as KERNEL_DS, so reset it to USER_DS before
58899 * continuing. Amongst other possible reasons, this is to prevent
58900 * mm_release()->clear_child_tid() from writing to a user-controlled
58901@@ -915,6 +943,13 @@ NORET_TYPE void do_exit(long code)
58902 */
58903 set_fs(USER_DS);
58904
58905+ profile_task_exit(tsk);
58906+
58907+ WARN_ON(atomic_read(&tsk->fs_excl));
58908+
58909+ if (unlikely(!tsk->pid))
58910+ panic("Attempted to kill the idle task!");
58911+
58912 tracehook_report_exit(&code);
58913
58914 validate_creds_for_do_exit(tsk);
58915@@ -973,6 +1008,9 @@ NORET_TYPE void do_exit(long code)
58916 tsk->exit_code = code;
58917 taskstats_exit(tsk, group_dead);
58918
58919+ gr_acl_handle_psacct(tsk, code);
58920+ gr_acl_handle_exit();
58921+
58922 exit_mm(tsk);
58923
58924 if (group_dead)
58925@@ -1188,7 +1226,7 @@ static int wait_task_zombie(struct wait_
58926
58927 if (unlikely(wo->wo_flags & WNOWAIT)) {
58928 int exit_code = p->exit_code;
58929- int why, status;
58930+ int why;
58931
58932 get_task_struct(p);
58933 read_unlock(&tasklist_lock);
58934diff -urNp linux-2.6.32.41/kernel/fork.c linux-2.6.32.41/kernel/fork.c
58935--- linux-2.6.32.41/kernel/fork.c 2011-03-27 14:31:47.000000000 -0400
58936+++ linux-2.6.32.41/kernel/fork.c 2011-04-17 15:56:46.000000000 -0400
58937@@ -253,7 +253,7 @@ static struct task_struct *dup_task_stru
58938 *stackend = STACK_END_MAGIC; /* for overflow detection */
58939
58940 #ifdef CONFIG_CC_STACKPROTECTOR
58941- tsk->stack_canary = get_random_int();
58942+ tsk->stack_canary = pax_get_random_long();
58943 #endif
58944
58945 /* One for us, one for whoever does the "release_task()" (usually parent) */
58946@@ -293,8 +293,8 @@ static int dup_mmap(struct mm_struct *mm
58947 mm->locked_vm = 0;
58948 mm->mmap = NULL;
58949 mm->mmap_cache = NULL;
58950- mm->free_area_cache = oldmm->mmap_base;
58951- mm->cached_hole_size = ~0UL;
58952+ mm->free_area_cache = oldmm->free_area_cache;
58953+ mm->cached_hole_size = oldmm->cached_hole_size;
58954 mm->map_count = 0;
58955 cpumask_clear(mm_cpumask(mm));
58956 mm->mm_rb = RB_ROOT;
58957@@ -335,6 +335,7 @@ static int dup_mmap(struct mm_struct *mm
58958 tmp->vm_flags &= ~VM_LOCKED;
58959 tmp->vm_mm = mm;
58960 tmp->vm_next = tmp->vm_prev = NULL;
58961+ tmp->vm_mirror = NULL;
58962 anon_vma_link(tmp);
58963 file = tmp->vm_file;
58964 if (file) {
58965@@ -384,6 +385,31 @@ static int dup_mmap(struct mm_struct *mm
58966 if (retval)
58967 goto out;
58968 }
58969+
58970+#ifdef CONFIG_PAX_SEGMEXEC
58971+ if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
58972+ struct vm_area_struct *mpnt_m;
58973+
58974+ for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
58975+ BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
58976+
58977+ if (!mpnt->vm_mirror)
58978+ continue;
58979+
58980+ if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
58981+ BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
58982+ mpnt->vm_mirror = mpnt_m;
58983+ } else {
58984+ BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
58985+ mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
58986+ mpnt_m->vm_mirror->vm_mirror = mpnt_m;
58987+ mpnt->vm_mirror->vm_mirror = mpnt;
58988+ }
58989+ }
58990+ BUG_ON(mpnt_m);
58991+ }
58992+#endif
58993+
58994 /* a new mm has just been created */
58995 arch_dup_mmap(oldmm, mm);
58996 retval = 0;
58997@@ -734,13 +760,14 @@ static int copy_fs(unsigned long clone_f
58998 write_unlock(&fs->lock);
58999 return -EAGAIN;
59000 }
59001- fs->users++;
59002+ atomic_inc(&fs->users);
59003 write_unlock(&fs->lock);
59004 return 0;
59005 }
59006 tsk->fs = copy_fs_struct(fs);
59007 if (!tsk->fs)
59008 return -ENOMEM;
59009+ gr_set_chroot_entries(tsk, &tsk->fs->root);
59010 return 0;
59011 }
59012
59013@@ -1033,10 +1060,13 @@ static struct task_struct *copy_process(
59014 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
59015 #endif
59016 retval = -EAGAIN;
59017+
59018+ gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
59019+
59020 if (atomic_read(&p->real_cred->user->processes) >=
59021 p->signal->rlim[RLIMIT_NPROC].rlim_cur) {
59022- if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
59023- p->real_cred->user != INIT_USER)
59024+ if (p->real_cred->user != INIT_USER &&
59025+ !capable(CAP_SYS_RESOURCE) && !capable(CAP_SYS_ADMIN))
59026 goto bad_fork_free;
59027 }
59028
59029@@ -1183,6 +1213,8 @@ static struct task_struct *copy_process(
59030 goto bad_fork_free_pid;
59031 }
59032
59033+ gr_copy_label(p);
59034+
59035 p->set_child_tid = (clone_flags & CLONE_CHILD_SETTID) ? child_tidptr : NULL;
59036 /*
59037 * Clear TID on mm_release()?
59038@@ -1333,6 +1365,8 @@ bad_fork_cleanup_count:
59039 bad_fork_free:
59040 free_task(p);
59041 fork_out:
59042+ gr_log_forkfail(retval);
59043+
59044 return ERR_PTR(retval);
59045 }
59046
59047@@ -1426,6 +1460,8 @@ long do_fork(unsigned long clone_flags,
59048 if (clone_flags & CLONE_PARENT_SETTID)
59049 put_user(nr, parent_tidptr);
59050
59051+ gr_handle_brute_check();
59052+
59053 if (clone_flags & CLONE_VFORK) {
59054 p->vfork_done = &vfork;
59055 init_completion(&vfork);
59056@@ -1558,7 +1594,7 @@ static int unshare_fs(unsigned long unsh
59057 return 0;
59058
59059 /* don't need lock here; in the worst case we'll do useless copy */
59060- if (fs->users == 1)
59061+ if (atomic_read(&fs->users) == 1)
59062 return 0;
59063
59064 *new_fsp = copy_fs_struct(fs);
59065@@ -1681,7 +1717,8 @@ SYSCALL_DEFINE1(unshare, unsigned long,
59066 fs = current->fs;
59067 write_lock(&fs->lock);
59068 current->fs = new_fs;
59069- if (--fs->users)
59070+ gr_set_chroot_entries(current, &current->fs->root);
59071+ if (atomic_dec_return(&fs->users))
59072 new_fs = NULL;
59073 else
59074 new_fs = fs;
59075diff -urNp linux-2.6.32.41/kernel/futex.c linux-2.6.32.41/kernel/futex.c
59076--- linux-2.6.32.41/kernel/futex.c 2011-03-27 14:31:47.000000000 -0400
59077+++ linux-2.6.32.41/kernel/futex.c 2011-05-16 21:46:57.000000000 -0400
59078@@ -54,6 +54,7 @@
59079 #include <linux/mount.h>
59080 #include <linux/pagemap.h>
59081 #include <linux/syscalls.h>
59082+#include <linux/ptrace.h>
59083 #include <linux/signal.h>
59084 #include <linux/module.h>
59085 #include <linux/magic.h>
59086@@ -221,6 +222,11 @@ get_futex_key(u32 __user *uaddr, int fsh
59087 struct page *page;
59088 int err;
59089
59090+#ifdef CONFIG_PAX_SEGMEXEC
59091+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
59092+ return -EFAULT;
59093+#endif
59094+
59095 /*
59096 * The futex address must be "naturally" aligned.
59097 */
59098@@ -1789,6 +1795,8 @@ static int futex_wait(u32 __user *uaddr,
59099 struct futex_q q;
59100 int ret;
59101
59102+ pax_track_stack();
59103+
59104 if (!bitset)
59105 return -EINVAL;
59106
59107@@ -1841,7 +1849,7 @@ retry:
59108
59109 restart = &current_thread_info()->restart_block;
59110 restart->fn = futex_wait_restart;
59111- restart->futex.uaddr = (u32 *)uaddr;
59112+ restart->futex.uaddr = uaddr;
59113 restart->futex.val = val;
59114 restart->futex.time = abs_time->tv64;
59115 restart->futex.bitset = bitset;
59116@@ -2203,6 +2211,8 @@ static int futex_wait_requeue_pi(u32 __u
59117 struct futex_q q;
59118 int res, ret;
59119
59120+ pax_track_stack();
59121+
59122 if (!bitset)
59123 return -EINVAL;
59124
59125@@ -2377,7 +2387,9 @@ SYSCALL_DEFINE3(get_robust_list, int, pi
59126 {
59127 struct robust_list_head __user *head;
59128 unsigned long ret;
59129+#ifndef CONFIG_GRKERNSEC_PROC_MEMMAP
59130 const struct cred *cred = current_cred(), *pcred;
59131+#endif
59132
59133 if (!futex_cmpxchg_enabled)
59134 return -ENOSYS;
59135@@ -2393,11 +2405,16 @@ SYSCALL_DEFINE3(get_robust_list, int, pi
59136 if (!p)
59137 goto err_unlock;
59138 ret = -EPERM;
59139+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59140+ if (!ptrace_may_access(p, PTRACE_MODE_READ))
59141+ goto err_unlock;
59142+#else
59143 pcred = __task_cred(p);
59144 if (cred->euid != pcred->euid &&
59145 cred->euid != pcred->uid &&
59146 !capable(CAP_SYS_PTRACE))
59147 goto err_unlock;
59148+#endif
59149 head = p->robust_list;
59150 rcu_read_unlock();
59151 }
59152@@ -2459,7 +2476,7 @@ retry:
59153 */
59154 static inline int fetch_robust_entry(struct robust_list __user **entry,
59155 struct robust_list __user * __user *head,
59156- int *pi)
59157+ unsigned int *pi)
59158 {
59159 unsigned long uentry;
59160
59161@@ -2640,6 +2657,7 @@ static int __init futex_init(void)
59162 {
59163 u32 curval;
59164 int i;
59165+ mm_segment_t oldfs;
59166
59167 /*
59168 * This will fail and we want it. Some arch implementations do
59169@@ -2651,7 +2669,10 @@ static int __init futex_init(void)
59170 * implementation, the non functional ones will return
59171 * -ENOSYS.
59172 */
59173+ oldfs = get_fs();
59174+ set_fs(USER_DS);
59175 curval = cmpxchg_futex_value_locked(NULL, 0, 0);
59176+ set_fs(oldfs);
59177 if (curval == -EFAULT)
59178 futex_cmpxchg_enabled = 1;
59179
59180diff -urNp linux-2.6.32.41/kernel/futex_compat.c linux-2.6.32.41/kernel/futex_compat.c
59181--- linux-2.6.32.41/kernel/futex_compat.c 2011-03-27 14:31:47.000000000 -0400
59182+++ linux-2.6.32.41/kernel/futex_compat.c 2011-04-17 15:56:46.000000000 -0400
59183@@ -10,6 +10,7 @@
59184 #include <linux/compat.h>
59185 #include <linux/nsproxy.h>
59186 #include <linux/futex.h>
59187+#include <linux/ptrace.h>
59188
59189 #include <asm/uaccess.h>
59190
59191@@ -135,7 +136,10 @@ compat_sys_get_robust_list(int pid, comp
59192 {
59193 struct compat_robust_list_head __user *head;
59194 unsigned long ret;
59195- const struct cred *cred = current_cred(), *pcred;
59196+#ifndef CONFIG_GRKERNSEC_PROC_MEMMAP
59197+ const struct cred *cred = current_cred();
59198+ const struct cred *pcred;
59199+#endif
59200
59201 if (!futex_cmpxchg_enabled)
59202 return -ENOSYS;
59203@@ -151,11 +155,16 @@ compat_sys_get_robust_list(int pid, comp
59204 if (!p)
59205 goto err_unlock;
59206 ret = -EPERM;
59207+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59208+ if (!ptrace_may_access(p, PTRACE_MODE_READ))
59209+ goto err_unlock;
59210+#else
59211 pcred = __task_cred(p);
59212 if (cred->euid != pcred->euid &&
59213 cred->euid != pcred->uid &&
59214 !capable(CAP_SYS_PTRACE))
59215 goto err_unlock;
59216+#endif
59217 head = p->compat_robust_list;
59218 read_unlock(&tasklist_lock);
59219 }
59220diff -urNp linux-2.6.32.41/kernel/gcov/base.c linux-2.6.32.41/kernel/gcov/base.c
59221--- linux-2.6.32.41/kernel/gcov/base.c 2011-03-27 14:31:47.000000000 -0400
59222+++ linux-2.6.32.41/kernel/gcov/base.c 2011-04-17 15:56:46.000000000 -0400
59223@@ -102,11 +102,6 @@ void gcov_enable_events(void)
59224 }
59225
59226 #ifdef CONFIG_MODULES
59227-static inline int within(void *addr, void *start, unsigned long size)
59228-{
59229- return ((addr >= start) && (addr < start + size));
59230-}
59231-
59232 /* Update list and generate events when modules are unloaded. */
59233 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
59234 void *data)
59235@@ -121,7 +116,7 @@ static int gcov_module_notifier(struct n
59236 prev = NULL;
59237 /* Remove entries located in module from linked list. */
59238 for (info = gcov_info_head; info; info = info->next) {
59239- if (within(info, mod->module_core, mod->core_size)) {
59240+ if (within_module_core_rw((unsigned long)info, mod)) {
59241 if (prev)
59242 prev->next = info->next;
59243 else
59244diff -urNp linux-2.6.32.41/kernel/hrtimer.c linux-2.6.32.41/kernel/hrtimer.c
59245--- linux-2.6.32.41/kernel/hrtimer.c 2011-03-27 14:31:47.000000000 -0400
59246+++ linux-2.6.32.41/kernel/hrtimer.c 2011-04-17 15:56:46.000000000 -0400
59247@@ -1391,7 +1391,7 @@ void hrtimer_peek_ahead_timers(void)
59248 local_irq_restore(flags);
59249 }
59250
59251-static void run_hrtimer_softirq(struct softirq_action *h)
59252+static void run_hrtimer_softirq(void)
59253 {
59254 hrtimer_peek_ahead_timers();
59255 }
59256diff -urNp linux-2.6.32.41/kernel/kallsyms.c linux-2.6.32.41/kernel/kallsyms.c
59257--- linux-2.6.32.41/kernel/kallsyms.c 2011-03-27 14:31:47.000000000 -0400
59258+++ linux-2.6.32.41/kernel/kallsyms.c 2011-04-17 15:56:46.000000000 -0400
59259@@ -11,6 +11,9 @@
59260 * Changed the compression method from stem compression to "table lookup"
59261 * compression (see scripts/kallsyms.c for a more complete description)
59262 */
59263+#ifdef CONFIG_GRKERNSEC_HIDESYM
59264+#define __INCLUDED_BY_HIDESYM 1
59265+#endif
59266 #include <linux/kallsyms.h>
59267 #include <linux/module.h>
59268 #include <linux/init.h>
59269@@ -51,12 +54,33 @@ extern const unsigned long kallsyms_mark
59270
59271 static inline int is_kernel_inittext(unsigned long addr)
59272 {
59273+ if (system_state != SYSTEM_BOOTING)
59274+ return 0;
59275+
59276 if (addr >= (unsigned long)_sinittext
59277 && addr <= (unsigned long)_einittext)
59278 return 1;
59279 return 0;
59280 }
59281
59282+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
59283+#ifdef CONFIG_MODULES
59284+static inline int is_module_text(unsigned long addr)
59285+{
59286+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
59287+ return 1;
59288+
59289+ addr = ktla_ktva(addr);
59290+ return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
59291+}
59292+#else
59293+static inline int is_module_text(unsigned long addr)
59294+{
59295+ return 0;
59296+}
59297+#endif
59298+#endif
59299+
59300 static inline int is_kernel_text(unsigned long addr)
59301 {
59302 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
59303@@ -67,13 +91,28 @@ static inline int is_kernel_text(unsigne
59304
59305 static inline int is_kernel(unsigned long addr)
59306 {
59307+
59308+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
59309+ if (is_kernel_text(addr) || is_kernel_inittext(addr))
59310+ return 1;
59311+
59312+ if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
59313+#else
59314 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
59315+#endif
59316+
59317 return 1;
59318 return in_gate_area_no_task(addr);
59319 }
59320
59321 static int is_ksym_addr(unsigned long addr)
59322 {
59323+
59324+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
59325+ if (is_module_text(addr))
59326+ return 0;
59327+#endif
59328+
59329 if (all_var)
59330 return is_kernel(addr);
59331
59332@@ -413,7 +452,6 @@ static unsigned long get_ksymbol_core(st
59333
59334 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
59335 {
59336- iter->name[0] = '\0';
59337 iter->nameoff = get_symbol_offset(new_pos);
59338 iter->pos = new_pos;
59339 }
59340@@ -461,6 +499,11 @@ static int s_show(struct seq_file *m, vo
59341 {
59342 struct kallsym_iter *iter = m->private;
59343
59344+#ifdef CONFIG_GRKERNSEC_HIDESYM
59345+ if (current_uid())
59346+ return 0;
59347+#endif
59348+
59349 /* Some debugging symbols have no name. Ignore them. */
59350 if (!iter->name[0])
59351 return 0;
59352@@ -501,7 +544,7 @@ static int kallsyms_open(struct inode *i
59353 struct kallsym_iter *iter;
59354 int ret;
59355
59356- iter = kmalloc(sizeof(*iter), GFP_KERNEL);
59357+ iter = kzalloc(sizeof(*iter), GFP_KERNEL);
59358 if (!iter)
59359 return -ENOMEM;
59360 reset_iter(iter, 0);
59361diff -urNp linux-2.6.32.41/kernel/kgdb.c linux-2.6.32.41/kernel/kgdb.c
59362--- linux-2.6.32.41/kernel/kgdb.c 2011-04-17 17:00:52.000000000 -0400
59363+++ linux-2.6.32.41/kernel/kgdb.c 2011-05-04 17:56:20.000000000 -0400
59364@@ -86,7 +86,7 @@ static int kgdb_io_module_registered;
59365 /* Guard for recursive entry */
59366 static int exception_level;
59367
59368-static struct kgdb_io *kgdb_io_ops;
59369+static const struct kgdb_io *kgdb_io_ops;
59370 static DEFINE_SPINLOCK(kgdb_registration_lock);
59371
59372 /* kgdb console driver is loaded */
59373@@ -123,7 +123,7 @@ atomic_t kgdb_active = ATOMIC_INIT(-1)
59374 */
59375 static atomic_t passive_cpu_wait[NR_CPUS];
59376 static atomic_t cpu_in_kgdb[NR_CPUS];
59377-atomic_t kgdb_setting_breakpoint;
59378+atomic_unchecked_t kgdb_setting_breakpoint;
59379
59380 struct task_struct *kgdb_usethread;
59381 struct task_struct *kgdb_contthread;
59382@@ -140,7 +140,7 @@ static unsigned long gdb_regs[(NUMREGBY
59383 sizeof(unsigned long)];
59384
59385 /* to keep track of the CPU which is doing the single stepping*/
59386-atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
59387+atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
59388
59389 /*
59390 * If you are debugging a problem where roundup (the collection of
59391@@ -815,7 +815,7 @@ static int kgdb_io_ready(int print_wait)
59392 return 0;
59393 if (kgdb_connected)
59394 return 1;
59395- if (atomic_read(&kgdb_setting_breakpoint))
59396+ if (atomic_read_unchecked(&kgdb_setting_breakpoint))
59397 return 1;
59398 if (print_wait)
59399 printk(KERN_CRIT "KGDB: Waiting for remote debugger\n");
59400@@ -1426,8 +1426,8 @@ acquirelock:
59401 * instance of the exception handler wanted to come into the
59402 * debugger on a different CPU via a single step
59403 */
59404- if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
59405- atomic_read(&kgdb_cpu_doing_single_step) != cpu) {
59406+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
59407+ atomic_read_unchecked(&kgdb_cpu_doing_single_step) != cpu) {
59408
59409 atomic_set(&kgdb_active, -1);
59410 touch_softlockup_watchdog();
59411@@ -1634,7 +1634,7 @@ static void kgdb_initial_breakpoint(void
59412 *
59413 * Register it with the KGDB core.
59414 */
59415-int kgdb_register_io_module(struct kgdb_io *new_kgdb_io_ops)
59416+int kgdb_register_io_module(const struct kgdb_io *new_kgdb_io_ops)
59417 {
59418 int err;
59419
59420@@ -1679,7 +1679,7 @@ EXPORT_SYMBOL_GPL(kgdb_register_io_modul
59421 *
59422 * Unregister it with the KGDB core.
59423 */
59424-void kgdb_unregister_io_module(struct kgdb_io *old_kgdb_io_ops)
59425+void kgdb_unregister_io_module(const struct kgdb_io *old_kgdb_io_ops)
59426 {
59427 BUG_ON(kgdb_connected);
59428
59429@@ -1712,11 +1712,11 @@ EXPORT_SYMBOL_GPL(kgdb_unregister_io_mod
59430 */
59431 void kgdb_breakpoint(void)
59432 {
59433- atomic_set(&kgdb_setting_breakpoint, 1);
59434+ atomic_set_unchecked(&kgdb_setting_breakpoint, 1);
59435 wmb(); /* Sync point before breakpoint */
59436 arch_kgdb_breakpoint();
59437 wmb(); /* Sync point after breakpoint */
59438- atomic_set(&kgdb_setting_breakpoint, 0);
59439+ atomic_set_unchecked(&kgdb_setting_breakpoint, 0);
59440 }
59441 EXPORT_SYMBOL_GPL(kgdb_breakpoint);
59442
59443diff -urNp linux-2.6.32.41/kernel/kmod.c linux-2.6.32.41/kernel/kmod.c
59444--- linux-2.6.32.41/kernel/kmod.c 2011-03-27 14:31:47.000000000 -0400
59445+++ linux-2.6.32.41/kernel/kmod.c 2011-04-17 15:56:46.000000000 -0400
59446@@ -65,13 +65,12 @@ char modprobe_path[KMOD_PATH_LEN] = "/sb
59447 * If module auto-loading support is disabled then this function
59448 * becomes a no-operation.
59449 */
59450-int __request_module(bool wait, const char *fmt, ...)
59451+static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
59452 {
59453- va_list args;
59454 char module_name[MODULE_NAME_LEN];
59455 unsigned int max_modprobes;
59456 int ret;
59457- char *argv[] = { modprobe_path, "-q", "--", module_name, NULL };
59458+ char *argv[] = { modprobe_path, "-q", "--", module_name, module_param, NULL };
59459 static char *envp[] = { "HOME=/",
59460 "TERM=linux",
59461 "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
59462@@ -84,12 +83,24 @@ int __request_module(bool wait, const ch
59463 if (ret)
59464 return ret;
59465
59466- va_start(args, fmt);
59467- ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
59468- va_end(args);
59469+ ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
59470 if (ret >= MODULE_NAME_LEN)
59471 return -ENAMETOOLONG;
59472
59473+#ifdef CONFIG_GRKERNSEC_MODHARDEN
59474+ if (!current_uid()) {
59475+ /* hack to workaround consolekit/udisks stupidity */
59476+ read_lock(&tasklist_lock);
59477+ if (!strcmp(current->comm, "mount") &&
59478+ current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
59479+ read_unlock(&tasklist_lock);
59480+ printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
59481+ return -EPERM;
59482+ }
59483+ read_unlock(&tasklist_lock);
59484+ }
59485+#endif
59486+
59487 /* If modprobe needs a service that is in a module, we get a recursive
59488 * loop. Limit the number of running kmod threads to max_threads/2 or
59489 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
59490@@ -121,6 +132,48 @@ int __request_module(bool wait, const ch
59491 atomic_dec(&kmod_concurrent);
59492 return ret;
59493 }
59494+
59495+int ___request_module(bool wait, char *module_param, const char *fmt, ...)
59496+{
59497+ va_list args;
59498+ int ret;
59499+
59500+ va_start(args, fmt);
59501+ ret = ____request_module(wait, module_param, fmt, args);
59502+ va_end(args);
59503+
59504+ return ret;
59505+}
59506+
59507+int __request_module(bool wait, const char *fmt, ...)
59508+{
59509+ va_list args;
59510+ int ret;
59511+
59512+#ifdef CONFIG_GRKERNSEC_MODHARDEN
59513+ if (current_uid()) {
59514+ char module_param[MODULE_NAME_LEN];
59515+
59516+ memset(module_param, 0, sizeof(module_param));
59517+
59518+ snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", current_uid());
59519+
59520+ va_start(args, fmt);
59521+ ret = ____request_module(wait, module_param, fmt, args);
59522+ va_end(args);
59523+
59524+ return ret;
59525+ }
59526+#endif
59527+
59528+ va_start(args, fmt);
59529+ ret = ____request_module(wait, NULL, fmt, args);
59530+ va_end(args);
59531+
59532+ return ret;
59533+}
59534+
59535+
59536 EXPORT_SYMBOL(__request_module);
59537 #endif /* CONFIG_MODULES */
59538
59539diff -urNp linux-2.6.32.41/kernel/kprobes.c linux-2.6.32.41/kernel/kprobes.c
59540--- linux-2.6.32.41/kernel/kprobes.c 2011-03-27 14:31:47.000000000 -0400
59541+++ linux-2.6.32.41/kernel/kprobes.c 2011-04-17 15:56:46.000000000 -0400
59542@@ -183,7 +183,7 @@ static kprobe_opcode_t __kprobes *__get_
59543 * kernel image and loaded module images reside. This is required
59544 * so x86_64 can correctly handle the %rip-relative fixups.
59545 */
59546- kip->insns = module_alloc(PAGE_SIZE);
59547+ kip->insns = module_alloc_exec(PAGE_SIZE);
59548 if (!kip->insns) {
59549 kfree(kip);
59550 return NULL;
59551@@ -220,7 +220,7 @@ static int __kprobes collect_one_slot(st
59552 */
59553 if (!list_is_singular(&kprobe_insn_pages)) {
59554 list_del(&kip->list);
59555- module_free(NULL, kip->insns);
59556+ module_free_exec(NULL, kip->insns);
59557 kfree(kip);
59558 }
59559 return 1;
59560@@ -1189,7 +1189,7 @@ static int __init init_kprobes(void)
59561 {
59562 int i, err = 0;
59563 unsigned long offset = 0, size = 0;
59564- char *modname, namebuf[128];
59565+ char *modname, namebuf[KSYM_NAME_LEN];
59566 const char *symbol_name;
59567 void *addr;
59568 struct kprobe_blackpoint *kb;
59569@@ -1304,7 +1304,7 @@ static int __kprobes show_kprobe_addr(st
59570 const char *sym = NULL;
59571 unsigned int i = *(loff_t *) v;
59572 unsigned long offset = 0;
59573- char *modname, namebuf[128];
59574+ char *modname, namebuf[KSYM_NAME_LEN];
59575
59576 head = &kprobe_table[i];
59577 preempt_disable();
59578diff -urNp linux-2.6.32.41/kernel/lockdep.c linux-2.6.32.41/kernel/lockdep.c
59579--- linux-2.6.32.41/kernel/lockdep.c 2011-03-27 14:31:47.000000000 -0400
59580+++ linux-2.6.32.41/kernel/lockdep.c 2011-04-17 15:56:46.000000000 -0400
59581@@ -421,20 +421,20 @@ static struct stack_trace lockdep_init_t
59582 /*
59583 * Various lockdep statistics:
59584 */
59585-atomic_t chain_lookup_hits;
59586-atomic_t chain_lookup_misses;
59587-atomic_t hardirqs_on_events;
59588-atomic_t hardirqs_off_events;
59589-atomic_t redundant_hardirqs_on;
59590-atomic_t redundant_hardirqs_off;
59591-atomic_t softirqs_on_events;
59592-atomic_t softirqs_off_events;
59593-atomic_t redundant_softirqs_on;
59594-atomic_t redundant_softirqs_off;
59595-atomic_t nr_unused_locks;
59596-atomic_t nr_cyclic_checks;
59597-atomic_t nr_find_usage_forwards_checks;
59598-atomic_t nr_find_usage_backwards_checks;
59599+atomic_unchecked_t chain_lookup_hits;
59600+atomic_unchecked_t chain_lookup_misses;
59601+atomic_unchecked_t hardirqs_on_events;
59602+atomic_unchecked_t hardirqs_off_events;
59603+atomic_unchecked_t redundant_hardirqs_on;
59604+atomic_unchecked_t redundant_hardirqs_off;
59605+atomic_unchecked_t softirqs_on_events;
59606+atomic_unchecked_t softirqs_off_events;
59607+atomic_unchecked_t redundant_softirqs_on;
59608+atomic_unchecked_t redundant_softirqs_off;
59609+atomic_unchecked_t nr_unused_locks;
59610+atomic_unchecked_t nr_cyclic_checks;
59611+atomic_unchecked_t nr_find_usage_forwards_checks;
59612+atomic_unchecked_t nr_find_usage_backwards_checks;
59613 #endif
59614
59615 /*
59616@@ -577,6 +577,10 @@ static int static_obj(void *obj)
59617 int i;
59618 #endif
59619
59620+#ifdef CONFIG_PAX_KERNEXEC
59621+ start = ktla_ktva(start);
59622+#endif
59623+
59624 /*
59625 * static variable?
59626 */
59627@@ -592,8 +596,7 @@ static int static_obj(void *obj)
59628 */
59629 for_each_possible_cpu(i) {
59630 start = (unsigned long) &__per_cpu_start + per_cpu_offset(i);
59631- end = (unsigned long) &__per_cpu_start + PERCPU_ENOUGH_ROOM
59632- + per_cpu_offset(i);
59633+ end = start + PERCPU_ENOUGH_ROOM;
59634
59635 if ((addr >= start) && (addr < end))
59636 return 1;
59637@@ -710,6 +713,7 @@ register_lock_class(struct lockdep_map *
59638 if (!static_obj(lock->key)) {
59639 debug_locks_off();
59640 printk("INFO: trying to register non-static key.\n");
59641+ printk("lock:%pS key:%pS.\n", lock, lock->key);
59642 printk("the code is fine but needs lockdep annotation.\n");
59643 printk("turning off the locking correctness validator.\n");
59644 dump_stack();
59645@@ -2751,7 +2755,7 @@ static int __lock_acquire(struct lockdep
59646 if (!class)
59647 return 0;
59648 }
59649- debug_atomic_inc((atomic_t *)&class->ops);
59650+ debug_atomic_inc((atomic_unchecked_t *)&class->ops);
59651 if (very_verbose(class)) {
59652 printk("\nacquire class [%p] %s", class->key, class->name);
59653 if (class->name_version > 1)
59654diff -urNp linux-2.6.32.41/kernel/lockdep_internals.h linux-2.6.32.41/kernel/lockdep_internals.h
59655--- linux-2.6.32.41/kernel/lockdep_internals.h 2011-03-27 14:31:47.000000000 -0400
59656+++ linux-2.6.32.41/kernel/lockdep_internals.h 2011-04-17 15:56:46.000000000 -0400
59657@@ -113,26 +113,26 @@ lockdep_count_backward_deps(struct lock_
59658 /*
59659 * Various lockdep statistics:
59660 */
59661-extern atomic_t chain_lookup_hits;
59662-extern atomic_t chain_lookup_misses;
59663-extern atomic_t hardirqs_on_events;
59664-extern atomic_t hardirqs_off_events;
59665-extern atomic_t redundant_hardirqs_on;
59666-extern atomic_t redundant_hardirqs_off;
59667-extern atomic_t softirqs_on_events;
59668-extern atomic_t softirqs_off_events;
59669-extern atomic_t redundant_softirqs_on;
59670-extern atomic_t redundant_softirqs_off;
59671-extern atomic_t nr_unused_locks;
59672-extern atomic_t nr_cyclic_checks;
59673-extern atomic_t nr_cyclic_check_recursions;
59674-extern atomic_t nr_find_usage_forwards_checks;
59675-extern atomic_t nr_find_usage_forwards_recursions;
59676-extern atomic_t nr_find_usage_backwards_checks;
59677-extern atomic_t nr_find_usage_backwards_recursions;
59678-# define debug_atomic_inc(ptr) atomic_inc(ptr)
59679-# define debug_atomic_dec(ptr) atomic_dec(ptr)
59680-# define debug_atomic_read(ptr) atomic_read(ptr)
59681+extern atomic_unchecked_t chain_lookup_hits;
59682+extern atomic_unchecked_t chain_lookup_misses;
59683+extern atomic_unchecked_t hardirqs_on_events;
59684+extern atomic_unchecked_t hardirqs_off_events;
59685+extern atomic_unchecked_t redundant_hardirqs_on;
59686+extern atomic_unchecked_t redundant_hardirqs_off;
59687+extern atomic_unchecked_t softirqs_on_events;
59688+extern atomic_unchecked_t softirqs_off_events;
59689+extern atomic_unchecked_t redundant_softirqs_on;
59690+extern atomic_unchecked_t redundant_softirqs_off;
59691+extern atomic_unchecked_t nr_unused_locks;
59692+extern atomic_unchecked_t nr_cyclic_checks;
59693+extern atomic_unchecked_t nr_cyclic_check_recursions;
59694+extern atomic_unchecked_t nr_find_usage_forwards_checks;
59695+extern atomic_unchecked_t nr_find_usage_forwards_recursions;
59696+extern atomic_unchecked_t nr_find_usage_backwards_checks;
59697+extern atomic_unchecked_t nr_find_usage_backwards_recursions;
59698+# define debug_atomic_inc(ptr) atomic_inc_unchecked(ptr)
59699+# define debug_atomic_dec(ptr) atomic_dec_unchecked(ptr)
59700+# define debug_atomic_read(ptr) atomic_read_unchecked(ptr)
59701 #else
59702 # define debug_atomic_inc(ptr) do { } while (0)
59703 # define debug_atomic_dec(ptr) do { } while (0)
59704diff -urNp linux-2.6.32.41/kernel/lockdep_proc.c linux-2.6.32.41/kernel/lockdep_proc.c
59705--- linux-2.6.32.41/kernel/lockdep_proc.c 2011-03-27 14:31:47.000000000 -0400
59706+++ linux-2.6.32.41/kernel/lockdep_proc.c 2011-04-17 15:56:46.000000000 -0400
59707@@ -39,7 +39,7 @@ static void l_stop(struct seq_file *m, v
59708
59709 static void print_name(struct seq_file *m, struct lock_class *class)
59710 {
59711- char str[128];
59712+ char str[KSYM_NAME_LEN];
59713 const char *name = class->name;
59714
59715 if (!name) {
59716diff -urNp linux-2.6.32.41/kernel/module.c linux-2.6.32.41/kernel/module.c
59717--- linux-2.6.32.41/kernel/module.c 2011-03-27 14:31:47.000000000 -0400
59718+++ linux-2.6.32.41/kernel/module.c 2011-04-29 18:52:40.000000000 -0400
59719@@ -55,6 +55,7 @@
59720 #include <linux/async.h>
59721 #include <linux/percpu.h>
59722 #include <linux/kmemleak.h>
59723+#include <linux/grsecurity.h>
59724
59725 #define CREATE_TRACE_POINTS
59726 #include <trace/events/module.h>
59727@@ -89,7 +90,8 @@ static DECLARE_WAIT_QUEUE_HEAD(module_wq
59728 static BLOCKING_NOTIFIER_HEAD(module_notify_list);
59729
59730 /* Bounds of module allocation, for speeding __module_address */
59731-static unsigned long module_addr_min = -1UL, module_addr_max = 0;
59732+static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
59733+static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
59734
59735 int register_module_notifier(struct notifier_block * nb)
59736 {
59737@@ -245,7 +247,7 @@ bool each_symbol(bool (*fn)(const struct
59738 return true;
59739
59740 list_for_each_entry_rcu(mod, &modules, list) {
59741- struct symsearch arr[] = {
59742+ struct symsearch modarr[] = {
59743 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
59744 NOT_GPL_ONLY, false },
59745 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
59746@@ -267,7 +269,7 @@ bool each_symbol(bool (*fn)(const struct
59747 #endif
59748 };
59749
59750- if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
59751+ if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
59752 return true;
59753 }
59754 return false;
59755@@ -442,7 +444,7 @@ static void *percpu_modalloc(unsigned lo
59756 void *ptr;
59757 int cpu;
59758
59759- if (align > PAGE_SIZE) {
59760+ if (align-1 >= PAGE_SIZE) {
59761 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
59762 name, align, PAGE_SIZE);
59763 align = PAGE_SIZE;
59764@@ -1158,7 +1160,7 @@ static const struct kernel_symbol *resol
59765 * /sys/module/foo/sections stuff
59766 * J. Corbet <corbet@lwn.net>
59767 */
59768-#if defined(CONFIG_KALLSYMS) && defined(CONFIG_SYSFS)
59769+#if defined(CONFIG_KALLSYMS) && defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
59770
59771 static inline bool sect_empty(const Elf_Shdr *sect)
59772 {
59773@@ -1545,7 +1547,8 @@ static void free_module(struct module *m
59774 destroy_params(mod->kp, mod->num_kp);
59775
59776 /* This may be NULL, but that's OK */
59777- module_free(mod, mod->module_init);
59778+ module_free(mod, mod->module_init_rw);
59779+ module_free_exec(mod, mod->module_init_rx);
59780 kfree(mod->args);
59781 if (mod->percpu)
59782 percpu_modfree(mod->percpu);
59783@@ -1554,10 +1557,12 @@ static void free_module(struct module *m
59784 percpu_modfree(mod->refptr);
59785 #endif
59786 /* Free lock-classes: */
59787- lockdep_free_key_range(mod->module_core, mod->core_size);
59788+ lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
59789+ lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
59790
59791 /* Finally, free the core (containing the module structure) */
59792- module_free(mod, mod->module_core);
59793+ module_free_exec(mod, mod->module_core_rx);
59794+ module_free(mod, mod->module_core_rw);
59795
59796 #ifdef CONFIG_MPU
59797 update_protections(current->mm);
59798@@ -1628,8 +1633,32 @@ static int simplify_symbols(Elf_Shdr *se
59799 unsigned int i, n = sechdrs[symindex].sh_size / sizeof(Elf_Sym);
59800 int ret = 0;
59801 const struct kernel_symbol *ksym;
59802+#ifdef CONFIG_GRKERNSEC_MODHARDEN
59803+ int is_fs_load = 0;
59804+ int register_filesystem_found = 0;
59805+ char *p;
59806+
59807+ p = strstr(mod->args, "grsec_modharden_fs");
59808+
59809+ if (p) {
59810+ char *endptr = p + strlen("grsec_modharden_fs");
59811+ /* copy \0 as well */
59812+ memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
59813+ is_fs_load = 1;
59814+ }
59815+#endif
59816+
59817
59818 for (i = 1; i < n; i++) {
59819+#ifdef CONFIG_GRKERNSEC_MODHARDEN
59820+ const char *name = strtab + sym[i].st_name;
59821+
59822+ /* it's a real shame this will never get ripped and copied
59823+ upstream! ;(
59824+ */
59825+ if (is_fs_load && !strcmp(name, "register_filesystem"))
59826+ register_filesystem_found = 1;
59827+#endif
59828 switch (sym[i].st_shndx) {
59829 case SHN_COMMON:
59830 /* We compiled with -fno-common. These are not
59831@@ -1651,7 +1680,9 @@ static int simplify_symbols(Elf_Shdr *se
59832 strtab + sym[i].st_name, mod);
59833 /* Ok if resolved. */
59834 if (ksym) {
59835+ pax_open_kernel();
59836 sym[i].st_value = ksym->value;
59837+ pax_close_kernel();
59838 break;
59839 }
59840
59841@@ -1670,11 +1701,20 @@ static int simplify_symbols(Elf_Shdr *se
59842 secbase = (unsigned long)mod->percpu;
59843 else
59844 secbase = sechdrs[sym[i].st_shndx].sh_addr;
59845+ pax_open_kernel();
59846 sym[i].st_value += secbase;
59847+ pax_close_kernel();
59848 break;
59849 }
59850 }
59851
59852+#ifdef CONFIG_GRKERNSEC_MODHARDEN
59853+ if (is_fs_load && !register_filesystem_found) {
59854+ printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
59855+ ret = -EPERM;
59856+ }
59857+#endif
59858+
59859 return ret;
59860 }
59861
59862@@ -1731,11 +1771,12 @@ static void layout_sections(struct modul
59863 || s->sh_entsize != ~0UL
59864 || strstarts(secstrings + s->sh_name, ".init"))
59865 continue;
59866- s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
59867+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
59868+ s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
59869+ else
59870+ s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
59871 DEBUGP("\t%s\n", secstrings + s->sh_name);
59872 }
59873- if (m == 0)
59874- mod->core_text_size = mod->core_size;
59875 }
59876
59877 DEBUGP("Init section allocation order:\n");
59878@@ -1748,12 +1789,13 @@ static void layout_sections(struct modul
59879 || s->sh_entsize != ~0UL
59880 || !strstarts(secstrings + s->sh_name, ".init"))
59881 continue;
59882- s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
59883- | INIT_OFFSET_MASK);
59884+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
59885+ s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
59886+ else
59887+ s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
59888+ s->sh_entsize |= INIT_OFFSET_MASK;
59889 DEBUGP("\t%s\n", secstrings + s->sh_name);
59890 }
59891- if (m == 0)
59892- mod->init_text_size = mod->init_size;
59893 }
59894 }
59895
59896@@ -1857,9 +1899,8 @@ static int is_exported(const char *name,
59897
59898 /* As per nm */
59899 static char elf_type(const Elf_Sym *sym,
59900- Elf_Shdr *sechdrs,
59901- const char *secstrings,
59902- struct module *mod)
59903+ const Elf_Shdr *sechdrs,
59904+ const char *secstrings)
59905 {
59906 if (ELF_ST_BIND(sym->st_info) == STB_WEAK) {
59907 if (ELF_ST_TYPE(sym->st_info) == STT_OBJECT)
59908@@ -1934,7 +1975,7 @@ static unsigned long layout_symtab(struc
59909
59910 /* Put symbol section at end of init part of module. */
59911 symsect->sh_flags |= SHF_ALLOC;
59912- symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
59913+ symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
59914 symindex) | INIT_OFFSET_MASK;
59915 DEBUGP("\t%s\n", secstrings + symsect->sh_name);
59916
59917@@ -1951,19 +1992,19 @@ static unsigned long layout_symtab(struc
59918 }
59919
59920 /* Append room for core symbols at end of core part. */
59921- symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
59922- mod->core_size = symoffs + ndst * sizeof(Elf_Sym);
59923+ symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
59924+ mod->core_size_rx = symoffs + ndst * sizeof(Elf_Sym);
59925
59926 /* Put string table section at end of init part of module. */
59927 strsect->sh_flags |= SHF_ALLOC;
59928- strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
59929+ strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
59930 strindex) | INIT_OFFSET_MASK;
59931 DEBUGP("\t%s\n", secstrings + strsect->sh_name);
59932
59933 /* Append room for core symbols' strings at end of core part. */
59934- *pstroffs = mod->core_size;
59935+ *pstroffs = mod->core_size_rx;
59936 __set_bit(0, strmap);
59937- mod->core_size += bitmap_weight(strmap, strsect->sh_size);
59938+ mod->core_size_rx += bitmap_weight(strmap, strsect->sh_size);
59939
59940 return symoffs;
59941 }
59942@@ -1987,12 +2028,14 @@ static void add_kallsyms(struct module *
59943 mod->num_symtab = sechdrs[symindex].sh_size / sizeof(Elf_Sym);
59944 mod->strtab = (void *)sechdrs[strindex].sh_addr;
59945
59946+ pax_open_kernel();
59947+
59948 /* Set types up while we still have access to sections. */
59949 for (i = 0; i < mod->num_symtab; i++)
59950 mod->symtab[i].st_info
59951- = elf_type(&mod->symtab[i], sechdrs, secstrings, mod);
59952+ = elf_type(&mod->symtab[i], sechdrs, secstrings);
59953
59954- mod->core_symtab = dst = mod->module_core + symoffs;
59955+ mod->core_symtab = dst = mod->module_core_rx + symoffs;
59956 src = mod->symtab;
59957 *dst = *src;
59958 for (ndst = i = 1; i < mod->num_symtab; ++i, ++src) {
59959@@ -2004,10 +2047,12 @@ static void add_kallsyms(struct module *
59960 }
59961 mod->core_num_syms = ndst;
59962
59963- mod->core_strtab = s = mod->module_core + stroffs;
59964+ mod->core_strtab = s = mod->module_core_rx + stroffs;
59965 for (*s = 0, i = 1; i < sechdrs[strindex].sh_size; ++i)
59966 if (test_bit(i, strmap))
59967 *++s = mod->strtab[i];
59968+
59969+ pax_close_kernel();
59970 }
59971 #else
59972 static inline unsigned long layout_symtab(struct module *mod,
59973@@ -2044,16 +2089,30 @@ static void dynamic_debug_setup(struct _
59974 #endif
59975 }
59976
59977-static void *module_alloc_update_bounds(unsigned long size)
59978+static void *module_alloc_update_bounds_rw(unsigned long size)
59979 {
59980 void *ret = module_alloc(size);
59981
59982 if (ret) {
59983 /* Update module bounds. */
59984- if ((unsigned long)ret < module_addr_min)
59985- module_addr_min = (unsigned long)ret;
59986- if ((unsigned long)ret + size > module_addr_max)
59987- module_addr_max = (unsigned long)ret + size;
59988+ if ((unsigned long)ret < module_addr_min_rw)
59989+ module_addr_min_rw = (unsigned long)ret;
59990+ if ((unsigned long)ret + size > module_addr_max_rw)
59991+ module_addr_max_rw = (unsigned long)ret + size;
59992+ }
59993+ return ret;
59994+}
59995+
59996+static void *module_alloc_update_bounds_rx(unsigned long size)
59997+{
59998+ void *ret = module_alloc_exec(size);
59999+
60000+ if (ret) {
60001+ /* Update module bounds. */
60002+ if ((unsigned long)ret < module_addr_min_rx)
60003+ module_addr_min_rx = (unsigned long)ret;
60004+ if ((unsigned long)ret + size > module_addr_max_rx)
60005+ module_addr_max_rx = (unsigned long)ret + size;
60006 }
60007 return ret;
60008 }
60009@@ -2065,8 +2124,8 @@ static void kmemleak_load_module(struct
60010 unsigned int i;
60011
60012 /* only scan the sections containing data */
60013- kmemleak_scan_area(mod->module_core, (unsigned long)mod -
60014- (unsigned long)mod->module_core,
60015+ kmemleak_scan_area(mod->module_core_rw, (unsigned long)mod -
60016+ (unsigned long)mod->module_core_rw,
60017 sizeof(struct module), GFP_KERNEL);
60018
60019 for (i = 1; i < hdr->e_shnum; i++) {
60020@@ -2076,8 +2135,8 @@ static void kmemleak_load_module(struct
60021 && strncmp(secstrings + sechdrs[i].sh_name, ".bss", 4) != 0)
60022 continue;
60023
60024- kmemleak_scan_area(mod->module_core, sechdrs[i].sh_addr -
60025- (unsigned long)mod->module_core,
60026+ kmemleak_scan_area(mod->module_core_rw, sechdrs[i].sh_addr -
60027+ (unsigned long)mod->module_core_rw,
60028 sechdrs[i].sh_size, GFP_KERNEL);
60029 }
60030 }
60031@@ -2263,7 +2322,7 @@ static noinline struct module *load_modu
60032 secstrings, &stroffs, strmap);
60033
60034 /* Do the allocs. */
60035- ptr = module_alloc_update_bounds(mod->core_size);
60036+ ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
60037 /*
60038 * The pointer to this block is stored in the module structure
60039 * which is inside the block. Just mark it as not being a
60040@@ -2274,23 +2333,47 @@ static noinline struct module *load_modu
60041 err = -ENOMEM;
60042 goto free_percpu;
60043 }
60044- memset(ptr, 0, mod->core_size);
60045- mod->module_core = ptr;
60046+ memset(ptr, 0, mod->core_size_rw);
60047+ mod->module_core_rw = ptr;
60048
60049- ptr = module_alloc_update_bounds(mod->init_size);
60050+ ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
60051 /*
60052 * The pointer to this block is stored in the module structure
60053 * which is inside the block. This block doesn't need to be
60054 * scanned as it contains data and code that will be freed
60055 * after the module is initialized.
60056 */
60057- kmemleak_ignore(ptr);
60058- if (!ptr && mod->init_size) {
60059+ kmemleak_not_leak(ptr);
60060+ if (!ptr && mod->init_size_rw) {
60061+ err = -ENOMEM;
60062+ goto free_core_rw;
60063+ }
60064+ memset(ptr, 0, mod->init_size_rw);
60065+ mod->module_init_rw = ptr;
60066+
60067+ ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
60068+ kmemleak_not_leak(ptr);
60069+ if (!ptr) {
60070 err = -ENOMEM;
60071- goto free_core;
60072+ goto free_init_rw;
60073 }
60074- memset(ptr, 0, mod->init_size);
60075- mod->module_init = ptr;
60076+
60077+ pax_open_kernel();
60078+ memset(ptr, 0, mod->core_size_rx);
60079+ pax_close_kernel();
60080+ mod->module_core_rx = ptr;
60081+
60082+ ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
60083+ kmemleak_not_leak(ptr);
60084+ if (!ptr && mod->init_size_rx) {
60085+ err = -ENOMEM;
60086+ goto free_core_rx;
60087+ }
60088+
60089+ pax_open_kernel();
60090+ memset(ptr, 0, mod->init_size_rx);
60091+ pax_close_kernel();
60092+ mod->module_init_rx = ptr;
60093
60094 /* Transfer each section which specifies SHF_ALLOC */
60095 DEBUGP("final section addresses:\n");
60096@@ -2300,17 +2383,45 @@ static noinline struct module *load_modu
60097 if (!(sechdrs[i].sh_flags & SHF_ALLOC))
60098 continue;
60099
60100- if (sechdrs[i].sh_entsize & INIT_OFFSET_MASK)
60101- dest = mod->module_init
60102- + (sechdrs[i].sh_entsize & ~INIT_OFFSET_MASK);
60103- else
60104- dest = mod->module_core + sechdrs[i].sh_entsize;
60105+ if (sechdrs[i].sh_entsize & INIT_OFFSET_MASK) {
60106+ if ((sechdrs[i].sh_flags & SHF_WRITE) || !(sechdrs[i].sh_flags & SHF_ALLOC))
60107+ dest = mod->module_init_rw
60108+ + (sechdrs[i].sh_entsize & ~INIT_OFFSET_MASK);
60109+ else
60110+ dest = mod->module_init_rx
60111+ + (sechdrs[i].sh_entsize & ~INIT_OFFSET_MASK);
60112+ } else {
60113+ if ((sechdrs[i].sh_flags & SHF_WRITE) || !(sechdrs[i].sh_flags & SHF_ALLOC))
60114+ dest = mod->module_core_rw + sechdrs[i].sh_entsize;
60115+ else
60116+ dest = mod->module_core_rx + sechdrs[i].sh_entsize;
60117+ }
60118+
60119+ if (sechdrs[i].sh_type != SHT_NOBITS) {
60120
60121- if (sechdrs[i].sh_type != SHT_NOBITS)
60122- memcpy(dest, (void *)sechdrs[i].sh_addr,
60123- sechdrs[i].sh_size);
60124+#ifdef CONFIG_PAX_KERNEXEC
60125+#ifdef CONFIG_X86_64
60126+ if ((sechdrs[i].sh_flags & SHF_WRITE) && (sechdrs[i].sh_flags & SHF_EXECINSTR))
60127+ set_memory_x((unsigned long)dest, (sechdrs[i].sh_size + PAGE_SIZE) >> PAGE_SHIFT);
60128+#endif
60129+ if (!(sechdrs[i].sh_flags & SHF_WRITE) && (sechdrs[i].sh_flags & SHF_ALLOC)) {
60130+ pax_open_kernel();
60131+ memcpy(dest, (void *)sechdrs[i].sh_addr, sechdrs[i].sh_size);
60132+ pax_close_kernel();
60133+ } else
60134+#endif
60135+
60136+ memcpy(dest, (void *)sechdrs[i].sh_addr, sechdrs[i].sh_size);
60137+ }
60138 /* Update sh_addr to point to copy in image. */
60139- sechdrs[i].sh_addr = (unsigned long)dest;
60140+
60141+#ifdef CONFIG_PAX_KERNEXEC
60142+ if (sechdrs[i].sh_flags & SHF_EXECINSTR)
60143+ sechdrs[i].sh_addr = ktva_ktla((unsigned long)dest);
60144+ else
60145+#endif
60146+
60147+ sechdrs[i].sh_addr = (unsigned long)dest;
60148 DEBUGP("\t0x%lx %s\n", sechdrs[i].sh_addr, secstrings + sechdrs[i].sh_name);
60149 }
60150 /* Module has been moved. */
60151@@ -2322,7 +2433,7 @@ static noinline struct module *load_modu
60152 mod->name);
60153 if (!mod->refptr) {
60154 err = -ENOMEM;
60155- goto free_init;
60156+ goto free_init_rx;
60157 }
60158 #endif
60159 /* Now we've moved module, initialize linked lists, etc. */
60160@@ -2351,6 +2462,31 @@ static noinline struct module *load_modu
60161 /* Set up MODINFO_ATTR fields */
60162 setup_modinfo(mod, sechdrs, infoindex);
60163
60164+ mod->args = args;
60165+
60166+#ifdef CONFIG_GRKERNSEC_MODHARDEN
60167+ {
60168+ char *p, *p2;
60169+
60170+ if (strstr(mod->args, "grsec_modharden_netdev")) {
60171+ 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);
60172+ err = -EPERM;
60173+ goto cleanup;
60174+ } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
60175+ p += strlen("grsec_modharden_normal");
60176+ p2 = strstr(p, "_");
60177+ if (p2) {
60178+ *p2 = '\0';
60179+ printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
60180+ *p2 = '_';
60181+ }
60182+ err = -EPERM;
60183+ goto cleanup;
60184+ }
60185+ }
60186+#endif
60187+
60188+
60189 /* Fix up syms, so that st_value is a pointer to location. */
60190 err = simplify_symbols(sechdrs, symindex, strtab, versindex, pcpuindex,
60191 mod);
60192@@ -2431,8 +2567,8 @@ static noinline struct module *load_modu
60193
60194 /* Now do relocations. */
60195 for (i = 1; i < hdr->e_shnum; i++) {
60196- const char *strtab = (char *)sechdrs[strindex].sh_addr;
60197 unsigned int info = sechdrs[i].sh_info;
60198+ strtab = (char *)sechdrs[strindex].sh_addr;
60199
60200 /* Not a valid relocation section? */
60201 if (info >= hdr->e_shnum)
60202@@ -2493,16 +2629,15 @@ static noinline struct module *load_modu
60203 * Do it before processing of module parameters, so the module
60204 * can provide parameter accessor functions of its own.
60205 */
60206- if (mod->module_init)
60207- flush_icache_range((unsigned long)mod->module_init,
60208- (unsigned long)mod->module_init
60209- + mod->init_size);
60210- flush_icache_range((unsigned long)mod->module_core,
60211- (unsigned long)mod->module_core + mod->core_size);
60212+ if (mod->module_init_rx)
60213+ flush_icache_range((unsigned long)mod->module_init_rx,
60214+ (unsigned long)mod->module_init_rx
60215+ + mod->init_size_rx);
60216+ flush_icache_range((unsigned long)mod->module_core_rx,
60217+ (unsigned long)mod->module_core_rx + mod->core_size_rx);
60218
60219 set_fs(old_fs);
60220
60221- mod->args = args;
60222 if (section_addr(hdr, sechdrs, secstrings, "__obsparm"))
60223 printk(KERN_WARNING "%s: Ignoring obsolete parameters\n",
60224 mod->name);
60225@@ -2546,12 +2681,16 @@ static noinline struct module *load_modu
60226 free_unload:
60227 module_unload_free(mod);
60228 #if defined(CONFIG_MODULE_UNLOAD) && defined(CONFIG_SMP)
60229+ free_init_rx:
60230 percpu_modfree(mod->refptr);
60231- free_init:
60232 #endif
60233- module_free(mod, mod->module_init);
60234- free_core:
60235- module_free(mod, mod->module_core);
60236+ module_free_exec(mod, mod->module_init_rx);
60237+ free_core_rx:
60238+ module_free_exec(mod, mod->module_core_rx);
60239+ free_init_rw:
60240+ module_free(mod, mod->module_init_rw);
60241+ free_core_rw:
60242+ module_free(mod, mod->module_core_rw);
60243 /* mod will be freed with core. Don't access it beyond this line! */
60244 free_percpu:
60245 if (percpu)
60246@@ -2653,10 +2792,12 @@ SYSCALL_DEFINE3(init_module, void __user
60247 mod->symtab = mod->core_symtab;
60248 mod->strtab = mod->core_strtab;
60249 #endif
60250- module_free(mod, mod->module_init);
60251- mod->module_init = NULL;
60252- mod->init_size = 0;
60253- mod->init_text_size = 0;
60254+ module_free(mod, mod->module_init_rw);
60255+ module_free_exec(mod, mod->module_init_rx);
60256+ mod->module_init_rw = NULL;
60257+ mod->module_init_rx = NULL;
60258+ mod->init_size_rw = 0;
60259+ mod->init_size_rx = 0;
60260 mutex_unlock(&module_mutex);
60261
60262 return 0;
60263@@ -2687,10 +2828,16 @@ static const char *get_ksymbol(struct mo
60264 unsigned long nextval;
60265
60266 /* At worse, next value is at end of module */
60267- if (within_module_init(addr, mod))
60268- nextval = (unsigned long)mod->module_init+mod->init_text_size;
60269+ if (within_module_init_rx(addr, mod))
60270+ nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
60271+ else if (within_module_init_rw(addr, mod))
60272+ nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
60273+ else if (within_module_core_rx(addr, mod))
60274+ nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
60275+ else if (within_module_core_rw(addr, mod))
60276+ nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
60277 else
60278- nextval = (unsigned long)mod->module_core+mod->core_text_size;
60279+ return NULL;
60280
60281 /* Scan for closest preceeding symbol, and next symbol. (ELF
60282 starts real symbols at 1). */
60283@@ -2936,7 +3083,7 @@ static int m_show(struct seq_file *m, vo
60284 char buf[8];
60285
60286 seq_printf(m, "%s %u",
60287- mod->name, mod->init_size + mod->core_size);
60288+ mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
60289 print_unload_info(m, mod);
60290
60291 /* Informative for users. */
60292@@ -2945,7 +3092,7 @@ static int m_show(struct seq_file *m, vo
60293 mod->state == MODULE_STATE_COMING ? "Loading":
60294 "Live");
60295 /* Used by oprofile and other similar tools. */
60296- seq_printf(m, " 0x%p", mod->module_core);
60297+ seq_printf(m, " 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
60298
60299 /* Taints info */
60300 if (mod->taints)
60301@@ -2981,7 +3128,17 @@ static const struct file_operations proc
60302
60303 static int __init proc_modules_init(void)
60304 {
60305+#ifndef CONFIG_GRKERNSEC_HIDESYM
60306+#ifdef CONFIG_GRKERNSEC_PROC_USER
60307+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
60308+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
60309+ proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
60310+#else
60311 proc_create("modules", 0, NULL, &proc_modules_operations);
60312+#endif
60313+#else
60314+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
60315+#endif
60316 return 0;
60317 }
60318 module_init(proc_modules_init);
60319@@ -3040,12 +3197,12 @@ struct module *__module_address(unsigned
60320 {
60321 struct module *mod;
60322
60323- if (addr < module_addr_min || addr > module_addr_max)
60324+ if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
60325+ (addr < module_addr_min_rw || addr > module_addr_max_rw))
60326 return NULL;
60327
60328 list_for_each_entry_rcu(mod, &modules, list)
60329- if (within_module_core(addr, mod)
60330- || within_module_init(addr, mod))
60331+ if (within_module_init(addr, mod) || within_module_core(addr, mod))
60332 return mod;
60333 return NULL;
60334 }
60335@@ -3079,11 +3236,20 @@ bool is_module_text_address(unsigned lon
60336 */
60337 struct module *__module_text_address(unsigned long addr)
60338 {
60339- struct module *mod = __module_address(addr);
60340+ struct module *mod;
60341+
60342+#ifdef CONFIG_X86_32
60343+ addr = ktla_ktva(addr);
60344+#endif
60345+
60346+ if (addr < module_addr_min_rx || addr > module_addr_max_rx)
60347+ return NULL;
60348+
60349+ mod = __module_address(addr);
60350+
60351 if (mod) {
60352 /* Make sure it's within the text section. */
60353- if (!within(addr, mod->module_init, mod->init_text_size)
60354- && !within(addr, mod->module_core, mod->core_text_size))
60355+ if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
60356 mod = NULL;
60357 }
60358 return mod;
60359diff -urNp linux-2.6.32.41/kernel/mutex.c linux-2.6.32.41/kernel/mutex.c
60360--- linux-2.6.32.41/kernel/mutex.c 2011-03-27 14:31:47.000000000 -0400
60361+++ linux-2.6.32.41/kernel/mutex.c 2011-04-17 15:56:46.000000000 -0400
60362@@ -169,7 +169,7 @@ __mutex_lock_common(struct mutex *lock,
60363 */
60364
60365 for (;;) {
60366- struct thread_info *owner;
60367+ struct task_struct *owner;
60368
60369 /*
60370 * If we own the BKL, then don't spin. The owner of
60371@@ -214,7 +214,7 @@ __mutex_lock_common(struct mutex *lock,
60372 spin_lock_mutex(&lock->wait_lock, flags);
60373
60374 debug_mutex_lock_common(lock, &waiter);
60375- debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
60376+ debug_mutex_add_waiter(lock, &waiter, task);
60377
60378 /* add waiting tasks to the end of the waitqueue (FIFO): */
60379 list_add_tail(&waiter.list, &lock->wait_list);
60380@@ -243,8 +243,7 @@ __mutex_lock_common(struct mutex *lock,
60381 * TASK_UNINTERRUPTIBLE case.)
60382 */
60383 if (unlikely(signal_pending_state(state, task))) {
60384- mutex_remove_waiter(lock, &waiter,
60385- task_thread_info(task));
60386+ mutex_remove_waiter(lock, &waiter, task);
60387 mutex_release(&lock->dep_map, 1, ip);
60388 spin_unlock_mutex(&lock->wait_lock, flags);
60389
60390@@ -265,7 +264,7 @@ __mutex_lock_common(struct mutex *lock,
60391 done:
60392 lock_acquired(&lock->dep_map, ip);
60393 /* got the lock - rejoice! */
60394- mutex_remove_waiter(lock, &waiter, current_thread_info());
60395+ mutex_remove_waiter(lock, &waiter, task);
60396 mutex_set_owner(lock);
60397
60398 /* set it to 0 if there are no waiters left: */
60399diff -urNp linux-2.6.32.41/kernel/mutex-debug.c linux-2.6.32.41/kernel/mutex-debug.c
60400--- linux-2.6.32.41/kernel/mutex-debug.c 2011-03-27 14:31:47.000000000 -0400
60401+++ linux-2.6.32.41/kernel/mutex-debug.c 2011-04-17 15:56:46.000000000 -0400
60402@@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mute
60403 }
60404
60405 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
60406- struct thread_info *ti)
60407+ struct task_struct *task)
60408 {
60409 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
60410
60411 /* Mark the current thread as blocked on the lock: */
60412- ti->task->blocked_on = waiter;
60413+ task->blocked_on = waiter;
60414 }
60415
60416 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
60417- struct thread_info *ti)
60418+ struct task_struct *task)
60419 {
60420 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
60421- DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
60422- DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
60423- ti->task->blocked_on = NULL;
60424+ DEBUG_LOCKS_WARN_ON(waiter->task != task);
60425+ DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
60426+ task->blocked_on = NULL;
60427
60428 list_del_init(&waiter->list);
60429 waiter->task = NULL;
60430@@ -75,7 +75,7 @@ void debug_mutex_unlock(struct mutex *lo
60431 return;
60432
60433 DEBUG_LOCKS_WARN_ON(lock->magic != lock);
60434- DEBUG_LOCKS_WARN_ON(lock->owner != current_thread_info());
60435+ DEBUG_LOCKS_WARN_ON(lock->owner != current);
60436 DEBUG_LOCKS_WARN_ON(!lock->wait_list.prev && !lock->wait_list.next);
60437 mutex_clear_owner(lock);
60438 }
60439diff -urNp linux-2.6.32.41/kernel/mutex-debug.h linux-2.6.32.41/kernel/mutex-debug.h
60440--- linux-2.6.32.41/kernel/mutex-debug.h 2011-03-27 14:31:47.000000000 -0400
60441+++ linux-2.6.32.41/kernel/mutex-debug.h 2011-04-17 15:56:46.000000000 -0400
60442@@ -20,16 +20,16 @@ extern void debug_mutex_wake_waiter(stru
60443 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
60444 extern void debug_mutex_add_waiter(struct mutex *lock,
60445 struct mutex_waiter *waiter,
60446- struct thread_info *ti);
60447+ struct task_struct *task);
60448 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
60449- struct thread_info *ti);
60450+ struct task_struct *task);
60451 extern void debug_mutex_unlock(struct mutex *lock);
60452 extern void debug_mutex_init(struct mutex *lock, const char *name,
60453 struct lock_class_key *key);
60454
60455 static inline void mutex_set_owner(struct mutex *lock)
60456 {
60457- lock->owner = current_thread_info();
60458+ lock->owner = current;
60459 }
60460
60461 static inline void mutex_clear_owner(struct mutex *lock)
60462diff -urNp linux-2.6.32.41/kernel/mutex.h linux-2.6.32.41/kernel/mutex.h
60463--- linux-2.6.32.41/kernel/mutex.h 2011-03-27 14:31:47.000000000 -0400
60464+++ linux-2.6.32.41/kernel/mutex.h 2011-04-17 15:56:46.000000000 -0400
60465@@ -19,7 +19,7 @@
60466 #ifdef CONFIG_SMP
60467 static inline void mutex_set_owner(struct mutex *lock)
60468 {
60469- lock->owner = current_thread_info();
60470+ lock->owner = current;
60471 }
60472
60473 static inline void mutex_clear_owner(struct mutex *lock)
60474diff -urNp linux-2.6.32.41/kernel/panic.c linux-2.6.32.41/kernel/panic.c
60475--- linux-2.6.32.41/kernel/panic.c 2011-03-27 14:31:47.000000000 -0400
60476+++ linux-2.6.32.41/kernel/panic.c 2011-04-17 15:56:46.000000000 -0400
60477@@ -352,7 +352,7 @@ static void warn_slowpath_common(const c
60478 const char *board;
60479
60480 printk(KERN_WARNING "------------[ cut here ]------------\n");
60481- printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
60482+ printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
60483 board = dmi_get_system_info(DMI_PRODUCT_NAME);
60484 if (board)
60485 printk(KERN_WARNING "Hardware name: %s\n", board);
60486@@ -392,7 +392,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
60487 */
60488 void __stack_chk_fail(void)
60489 {
60490- panic("stack-protector: Kernel stack is corrupted in: %p\n",
60491+ dump_stack();
60492+ panic("stack-protector: Kernel stack is corrupted in: %pA\n",
60493 __builtin_return_address(0));
60494 }
60495 EXPORT_SYMBOL(__stack_chk_fail);
60496diff -urNp linux-2.6.32.41/kernel/params.c linux-2.6.32.41/kernel/params.c
60497--- linux-2.6.32.41/kernel/params.c 2011-03-27 14:31:47.000000000 -0400
60498+++ linux-2.6.32.41/kernel/params.c 2011-04-17 15:56:46.000000000 -0400
60499@@ -725,7 +725,7 @@ static ssize_t module_attr_store(struct
60500 return ret;
60501 }
60502
60503-static struct sysfs_ops module_sysfs_ops = {
60504+static const struct sysfs_ops module_sysfs_ops = {
60505 .show = module_attr_show,
60506 .store = module_attr_store,
60507 };
60508@@ -739,7 +739,7 @@ static int uevent_filter(struct kset *ks
60509 return 0;
60510 }
60511
60512-static struct kset_uevent_ops module_uevent_ops = {
60513+static const struct kset_uevent_ops module_uevent_ops = {
60514 .filter = uevent_filter,
60515 };
60516
60517diff -urNp linux-2.6.32.41/kernel/perf_event.c linux-2.6.32.41/kernel/perf_event.c
60518--- linux-2.6.32.41/kernel/perf_event.c 2011-04-17 17:00:52.000000000 -0400
60519+++ linux-2.6.32.41/kernel/perf_event.c 2011-05-04 17:56:28.000000000 -0400
60520@@ -77,7 +77,7 @@ int sysctl_perf_event_mlock __read_mostl
60521 */
60522 int sysctl_perf_event_sample_rate __read_mostly = 100000;
60523
60524-static atomic64_t perf_event_id;
60525+static atomic64_unchecked_t perf_event_id;
60526
60527 /*
60528 * Lock for (sysadmin-configurable) event reservations:
60529@@ -1094,9 +1094,9 @@ static void __perf_event_sync_stat(struc
60530 * In order to keep per-task stats reliable we need to flip the event
60531 * values when we flip the contexts.
60532 */
60533- value = atomic64_read(&next_event->count);
60534- value = atomic64_xchg(&event->count, value);
60535- atomic64_set(&next_event->count, value);
60536+ value = atomic64_read_unchecked(&next_event->count);
60537+ value = atomic64_xchg_unchecked(&event->count, value);
60538+ atomic64_set_unchecked(&next_event->count, value);
60539
60540 swap(event->total_time_enabled, next_event->total_time_enabled);
60541 swap(event->total_time_running, next_event->total_time_running);
60542@@ -1552,7 +1552,7 @@ static u64 perf_event_read(struct perf_e
60543 update_event_times(event);
60544 }
60545
60546- return atomic64_read(&event->count);
60547+ return atomic64_read_unchecked(&event->count);
60548 }
60549
60550 /*
60551@@ -1790,11 +1790,11 @@ static int perf_event_read_group(struct
60552 values[n++] = 1 + leader->nr_siblings;
60553 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
60554 values[n++] = leader->total_time_enabled +
60555- atomic64_read(&leader->child_total_time_enabled);
60556+ atomic64_read_unchecked(&leader->child_total_time_enabled);
60557 }
60558 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
60559 values[n++] = leader->total_time_running +
60560- atomic64_read(&leader->child_total_time_running);
60561+ atomic64_read_unchecked(&leader->child_total_time_running);
60562 }
60563
60564 size = n * sizeof(u64);
60565@@ -1829,11 +1829,11 @@ static int perf_event_read_one(struct pe
60566 values[n++] = perf_event_read_value(event);
60567 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
60568 values[n++] = event->total_time_enabled +
60569- atomic64_read(&event->child_total_time_enabled);
60570+ atomic64_read_unchecked(&event->child_total_time_enabled);
60571 }
60572 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
60573 values[n++] = event->total_time_running +
60574- atomic64_read(&event->child_total_time_running);
60575+ atomic64_read_unchecked(&event->child_total_time_running);
60576 }
60577 if (read_format & PERF_FORMAT_ID)
60578 values[n++] = primary_event_id(event);
60579@@ -1903,7 +1903,7 @@ static unsigned int perf_poll(struct fil
60580 static void perf_event_reset(struct perf_event *event)
60581 {
60582 (void)perf_event_read(event);
60583- atomic64_set(&event->count, 0);
60584+ atomic64_set_unchecked(&event->count, 0);
60585 perf_event_update_userpage(event);
60586 }
60587
60588@@ -2079,15 +2079,15 @@ void perf_event_update_userpage(struct p
60589 ++userpg->lock;
60590 barrier();
60591 userpg->index = perf_event_index(event);
60592- userpg->offset = atomic64_read(&event->count);
60593+ userpg->offset = atomic64_read_unchecked(&event->count);
60594 if (event->state == PERF_EVENT_STATE_ACTIVE)
60595- userpg->offset -= atomic64_read(&event->hw.prev_count);
60596+ userpg->offset -= atomic64_read_unchecked(&event->hw.prev_count);
60597
60598 userpg->time_enabled = event->total_time_enabled +
60599- atomic64_read(&event->child_total_time_enabled);
60600+ atomic64_read_unchecked(&event->child_total_time_enabled);
60601
60602 userpg->time_running = event->total_time_running +
60603- atomic64_read(&event->child_total_time_running);
60604+ atomic64_read_unchecked(&event->child_total_time_running);
60605
60606 barrier();
60607 ++userpg->lock;
60608@@ -2903,14 +2903,14 @@ static void perf_output_read_one(struct
60609 u64 values[4];
60610 int n = 0;
60611
60612- values[n++] = atomic64_read(&event->count);
60613+ values[n++] = atomic64_read_unchecked(&event->count);
60614 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
60615 values[n++] = event->total_time_enabled +
60616- atomic64_read(&event->child_total_time_enabled);
60617+ atomic64_read_unchecked(&event->child_total_time_enabled);
60618 }
60619 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
60620 values[n++] = event->total_time_running +
60621- atomic64_read(&event->child_total_time_running);
60622+ atomic64_read_unchecked(&event->child_total_time_running);
60623 }
60624 if (read_format & PERF_FORMAT_ID)
60625 values[n++] = primary_event_id(event);
60626@@ -2940,7 +2940,7 @@ static void perf_output_read_group(struc
60627 if (leader != event)
60628 leader->pmu->read(leader);
60629
60630- values[n++] = atomic64_read(&leader->count);
60631+ values[n++] = atomic64_read_unchecked(&leader->count);
60632 if (read_format & PERF_FORMAT_ID)
60633 values[n++] = primary_event_id(leader);
60634
60635@@ -2952,7 +2952,7 @@ static void perf_output_read_group(struc
60636 if (sub != event)
60637 sub->pmu->read(sub);
60638
60639- values[n++] = atomic64_read(&sub->count);
60640+ values[n++] = atomic64_read_unchecked(&sub->count);
60641 if (read_format & PERF_FORMAT_ID)
60642 values[n++] = primary_event_id(sub);
60643
60644@@ -3787,7 +3787,7 @@ static void perf_swevent_add(struct perf
60645 {
60646 struct hw_perf_event *hwc = &event->hw;
60647
60648- atomic64_add(nr, &event->count);
60649+ atomic64_add_unchecked(nr, &event->count);
60650
60651 if (!hwc->sample_period)
60652 return;
60653@@ -4044,9 +4044,9 @@ static void cpu_clock_perf_event_update(
60654 u64 now;
60655
60656 now = cpu_clock(cpu);
60657- prev = atomic64_read(&event->hw.prev_count);
60658- atomic64_set(&event->hw.prev_count, now);
60659- atomic64_add(now - prev, &event->count);
60660+ prev = atomic64_read_unchecked(&event->hw.prev_count);
60661+ atomic64_set_unchecked(&event->hw.prev_count, now);
60662+ atomic64_add_unchecked(now - prev, &event->count);
60663 }
60664
60665 static int cpu_clock_perf_event_enable(struct perf_event *event)
60666@@ -4054,7 +4054,7 @@ static int cpu_clock_perf_event_enable(s
60667 struct hw_perf_event *hwc = &event->hw;
60668 int cpu = raw_smp_processor_id();
60669
60670- atomic64_set(&hwc->prev_count, cpu_clock(cpu));
60671+ atomic64_set_unchecked(&hwc->prev_count, cpu_clock(cpu));
60672 perf_swevent_start_hrtimer(event);
60673
60674 return 0;
60675@@ -4086,9 +4086,9 @@ static void task_clock_perf_event_update
60676 u64 prev;
60677 s64 delta;
60678
60679- prev = atomic64_xchg(&event->hw.prev_count, now);
60680+ prev = atomic64_xchg_unchecked(&event->hw.prev_count, now);
60681 delta = now - prev;
60682- atomic64_add(delta, &event->count);
60683+ atomic64_add_unchecked(delta, &event->count);
60684 }
60685
60686 static int task_clock_perf_event_enable(struct perf_event *event)
60687@@ -4098,7 +4098,7 @@ static int task_clock_perf_event_enable(
60688
60689 now = event->ctx->time;
60690
60691- atomic64_set(&hwc->prev_count, now);
60692+ atomic64_set_unchecked(&hwc->prev_count, now);
60693
60694 perf_swevent_start_hrtimer(event);
60695
60696@@ -4293,7 +4293,7 @@ perf_event_alloc(struct perf_event_attr
60697 event->parent = parent_event;
60698
60699 event->ns = get_pid_ns(current->nsproxy->pid_ns);
60700- event->id = atomic64_inc_return(&perf_event_id);
60701+ event->id = atomic64_inc_return_unchecked(&perf_event_id);
60702
60703 event->state = PERF_EVENT_STATE_INACTIVE;
60704
60705@@ -4724,15 +4724,15 @@ static void sync_child_event(struct perf
60706 if (child_event->attr.inherit_stat)
60707 perf_event_read_event(child_event, child);
60708
60709- child_val = atomic64_read(&child_event->count);
60710+ child_val = atomic64_read_unchecked(&child_event->count);
60711
60712 /*
60713 * Add back the child's count to the parent's count:
60714 */
60715- atomic64_add(child_val, &parent_event->count);
60716- atomic64_add(child_event->total_time_enabled,
60717+ atomic64_add_unchecked(child_val, &parent_event->count);
60718+ atomic64_add_unchecked(child_event->total_time_enabled,
60719 &parent_event->child_total_time_enabled);
60720- atomic64_add(child_event->total_time_running,
60721+ atomic64_add_unchecked(child_event->total_time_running,
60722 &parent_event->child_total_time_running);
60723
60724 /*
60725diff -urNp linux-2.6.32.41/kernel/pid.c linux-2.6.32.41/kernel/pid.c
60726--- linux-2.6.32.41/kernel/pid.c 2011-04-22 19:16:29.000000000 -0400
60727+++ linux-2.6.32.41/kernel/pid.c 2011-04-18 19:22:38.000000000 -0400
60728@@ -33,6 +33,7 @@
60729 #include <linux/rculist.h>
60730 #include <linux/bootmem.h>
60731 #include <linux/hash.h>
60732+#include <linux/security.h>
60733 #include <linux/pid_namespace.h>
60734 #include <linux/init_task.h>
60735 #include <linux/syscalls.h>
60736@@ -45,7 +46,7 @@ struct pid init_struct_pid = INIT_STRUCT
60737
60738 int pid_max = PID_MAX_DEFAULT;
60739
60740-#define RESERVED_PIDS 300
60741+#define RESERVED_PIDS 500
60742
60743 int pid_max_min = RESERVED_PIDS + 1;
60744 int pid_max_max = PID_MAX_LIMIT;
60745@@ -383,7 +384,14 @@ EXPORT_SYMBOL(pid_task);
60746 */
60747 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
60748 {
60749- return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
60750+ struct task_struct *task;
60751+
60752+ task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
60753+
60754+ if (gr_pid_is_chrooted(task))
60755+ return NULL;
60756+
60757+ return task;
60758 }
60759
60760 struct task_struct *find_task_by_vpid(pid_t vnr)
60761diff -urNp linux-2.6.32.41/kernel/posix-cpu-timers.c linux-2.6.32.41/kernel/posix-cpu-timers.c
60762--- linux-2.6.32.41/kernel/posix-cpu-timers.c 2011-03-27 14:31:47.000000000 -0400
60763+++ linux-2.6.32.41/kernel/posix-cpu-timers.c 2011-04-17 15:56:46.000000000 -0400
60764@@ -6,6 +6,7 @@
60765 #include <linux/posix-timers.h>
60766 #include <linux/errno.h>
60767 #include <linux/math64.h>
60768+#include <linux/security.h>
60769 #include <asm/uaccess.h>
60770 #include <linux/kernel_stat.h>
60771 #include <trace/events/timer.h>
60772diff -urNp linux-2.6.32.41/kernel/posix-timers.c linux-2.6.32.41/kernel/posix-timers.c
60773--- linux-2.6.32.41/kernel/posix-timers.c 2011-03-27 14:31:47.000000000 -0400
60774+++ linux-2.6.32.41/kernel/posix-timers.c 2011-05-16 21:46:57.000000000 -0400
60775@@ -42,6 +42,7 @@
60776 #include <linux/compiler.h>
60777 #include <linux/idr.h>
60778 #include <linux/posix-timers.h>
60779+#include <linux/grsecurity.h>
60780 #include <linux/syscalls.h>
60781 #include <linux/wait.h>
60782 #include <linux/workqueue.h>
60783@@ -296,6 +297,8 @@ static __init int init_posix_timers(void
60784 .nsleep = no_nsleep,
60785 };
60786
60787+ pax_track_stack();
60788+
60789 register_posix_clock(CLOCK_REALTIME, &clock_realtime);
60790 register_posix_clock(CLOCK_MONOTONIC, &clock_monotonic);
60791 register_posix_clock(CLOCK_MONOTONIC_RAW, &clock_monotonic_raw);
60792@@ -948,6 +951,13 @@ SYSCALL_DEFINE2(clock_settime, const clo
60793 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
60794 return -EFAULT;
60795
60796+ /* only the CLOCK_REALTIME clock can be set, all other clocks
60797+ have their clock_set fptr set to a nosettime dummy function
60798+ CLOCK_REALTIME has a NULL clock_set fptr which causes it to
60799+ call common_clock_set, which calls do_sys_settimeofday, which
60800+ we hook
60801+ */
60802+
60803 return CLOCK_DISPATCH(which_clock, clock_set, (which_clock, &new_tp));
60804 }
60805
60806diff -urNp linux-2.6.32.41/kernel/power/hibernate.c linux-2.6.32.41/kernel/power/hibernate.c
60807--- linux-2.6.32.41/kernel/power/hibernate.c 2011-03-27 14:31:47.000000000 -0400
60808+++ linux-2.6.32.41/kernel/power/hibernate.c 2011-04-17 15:56:46.000000000 -0400
60809@@ -48,14 +48,14 @@ enum {
60810
60811 static int hibernation_mode = HIBERNATION_SHUTDOWN;
60812
60813-static struct platform_hibernation_ops *hibernation_ops;
60814+static const struct platform_hibernation_ops *hibernation_ops;
60815
60816 /**
60817 * hibernation_set_ops - set the global hibernate operations
60818 * @ops: the hibernation operations to use in subsequent hibernation transitions
60819 */
60820
60821-void hibernation_set_ops(struct platform_hibernation_ops *ops)
60822+void hibernation_set_ops(const struct platform_hibernation_ops *ops)
60823 {
60824 if (ops && !(ops->begin && ops->end && ops->pre_snapshot
60825 && ops->prepare && ops->finish && ops->enter && ops->pre_restore
60826diff -urNp linux-2.6.32.41/kernel/power/poweroff.c linux-2.6.32.41/kernel/power/poweroff.c
60827--- linux-2.6.32.41/kernel/power/poweroff.c 2011-03-27 14:31:47.000000000 -0400
60828+++ linux-2.6.32.41/kernel/power/poweroff.c 2011-04-17 15:56:46.000000000 -0400
60829@@ -37,7 +37,7 @@ static struct sysrq_key_op sysrq_powerof
60830 .enable_mask = SYSRQ_ENABLE_BOOT,
60831 };
60832
60833-static int pm_sysrq_init(void)
60834+static int __init pm_sysrq_init(void)
60835 {
60836 register_sysrq_key('o', &sysrq_poweroff_op);
60837 return 0;
60838diff -urNp linux-2.6.32.41/kernel/power/process.c linux-2.6.32.41/kernel/power/process.c
60839--- linux-2.6.32.41/kernel/power/process.c 2011-03-27 14:31:47.000000000 -0400
60840+++ linux-2.6.32.41/kernel/power/process.c 2011-04-17 15:56:46.000000000 -0400
60841@@ -37,12 +37,15 @@ static int try_to_freeze_tasks(bool sig_
60842 struct timeval start, end;
60843 u64 elapsed_csecs64;
60844 unsigned int elapsed_csecs;
60845+ bool timedout = false;
60846
60847 do_gettimeofday(&start);
60848
60849 end_time = jiffies + TIMEOUT;
60850 do {
60851 todo = 0;
60852+ if (time_after(jiffies, end_time))
60853+ timedout = true;
60854 read_lock(&tasklist_lock);
60855 do_each_thread(g, p) {
60856 if (frozen(p) || !freezeable(p))
60857@@ -57,15 +60,17 @@ static int try_to_freeze_tasks(bool sig_
60858 * It is "frozen enough". If the task does wake
60859 * up, it will immediately call try_to_freeze.
60860 */
60861- if (!task_is_stopped_or_traced(p) &&
60862- !freezer_should_skip(p))
60863+ if (!task_is_stopped_or_traced(p) && !freezer_should_skip(p)) {
60864 todo++;
60865+ if (timedout) {
60866+ printk(KERN_ERR "Task refusing to freeze:\n");
60867+ sched_show_task(p);
60868+ }
60869+ }
60870 } while_each_thread(g, p);
60871 read_unlock(&tasklist_lock);
60872 yield(); /* Yield is okay here */
60873- if (time_after(jiffies, end_time))
60874- break;
60875- } while (todo);
60876+ } while (todo && !timedout);
60877
60878 do_gettimeofday(&end);
60879 elapsed_csecs64 = timeval_to_ns(&end) - timeval_to_ns(&start);
60880diff -urNp linux-2.6.32.41/kernel/power/suspend.c linux-2.6.32.41/kernel/power/suspend.c
60881--- linux-2.6.32.41/kernel/power/suspend.c 2011-03-27 14:31:47.000000000 -0400
60882+++ linux-2.6.32.41/kernel/power/suspend.c 2011-04-17 15:56:46.000000000 -0400
60883@@ -23,13 +23,13 @@ const char *const pm_states[PM_SUSPEND_M
60884 [PM_SUSPEND_MEM] = "mem",
60885 };
60886
60887-static struct platform_suspend_ops *suspend_ops;
60888+static const struct platform_suspend_ops *suspend_ops;
60889
60890 /**
60891 * suspend_set_ops - Set the global suspend method table.
60892 * @ops: Pointer to ops structure.
60893 */
60894-void suspend_set_ops(struct platform_suspend_ops *ops)
60895+void suspend_set_ops(const struct platform_suspend_ops *ops)
60896 {
60897 mutex_lock(&pm_mutex);
60898 suspend_ops = ops;
60899diff -urNp linux-2.6.32.41/kernel/printk.c linux-2.6.32.41/kernel/printk.c
60900--- linux-2.6.32.41/kernel/printk.c 2011-03-27 14:31:47.000000000 -0400
60901+++ linux-2.6.32.41/kernel/printk.c 2011-04-17 15:56:46.000000000 -0400
60902@@ -278,6 +278,11 @@ int do_syslog(int type, char __user *buf
60903 char c;
60904 int error = 0;
60905
60906+#ifdef CONFIG_GRKERNSEC_DMESG
60907+ if (grsec_enable_dmesg && !capable(CAP_SYS_ADMIN))
60908+ return -EPERM;
60909+#endif
60910+
60911 error = security_syslog(type);
60912 if (error)
60913 return error;
60914diff -urNp linux-2.6.32.41/kernel/profile.c linux-2.6.32.41/kernel/profile.c
60915--- linux-2.6.32.41/kernel/profile.c 2011-03-27 14:31:47.000000000 -0400
60916+++ linux-2.6.32.41/kernel/profile.c 2011-05-04 17:56:28.000000000 -0400
60917@@ -39,7 +39,7 @@ struct profile_hit {
60918 /* Oprofile timer tick hook */
60919 static int (*timer_hook)(struct pt_regs *) __read_mostly;
60920
60921-static atomic_t *prof_buffer;
60922+static atomic_unchecked_t *prof_buffer;
60923 static unsigned long prof_len, prof_shift;
60924
60925 int prof_on __read_mostly;
60926@@ -283,7 +283,7 @@ static void profile_flip_buffers(void)
60927 hits[i].pc = 0;
60928 continue;
60929 }
60930- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
60931+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
60932 hits[i].hits = hits[i].pc = 0;
60933 }
60934 }
60935@@ -346,9 +346,9 @@ void profile_hits(int type, void *__pc,
60936 * Add the current hit(s) and flush the write-queue out
60937 * to the global buffer:
60938 */
60939- atomic_add(nr_hits, &prof_buffer[pc]);
60940+ atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
60941 for (i = 0; i < NR_PROFILE_HIT; ++i) {
60942- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
60943+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
60944 hits[i].pc = hits[i].hits = 0;
60945 }
60946 out:
60947@@ -426,7 +426,7 @@ void profile_hits(int type, void *__pc,
60948 if (prof_on != type || !prof_buffer)
60949 return;
60950 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
60951- atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
60952+ atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
60953 }
60954 #endif /* !CONFIG_SMP */
60955 EXPORT_SYMBOL_GPL(profile_hits);
60956@@ -517,7 +517,7 @@ read_profile(struct file *file, char __u
60957 return -EFAULT;
60958 buf++; p++; count--; read++;
60959 }
60960- pnt = (char *)prof_buffer + p - sizeof(atomic_t);
60961+ pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
60962 if (copy_to_user(buf, (void *)pnt, count))
60963 return -EFAULT;
60964 read += count;
60965@@ -548,7 +548,7 @@ static ssize_t write_profile(struct file
60966 }
60967 #endif
60968 profile_discard_flip_buffers();
60969- memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
60970+ memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
60971 return count;
60972 }
60973
60974diff -urNp linux-2.6.32.41/kernel/ptrace.c linux-2.6.32.41/kernel/ptrace.c
60975--- linux-2.6.32.41/kernel/ptrace.c 2011-03-27 14:31:47.000000000 -0400
60976+++ linux-2.6.32.41/kernel/ptrace.c 2011-05-22 23:02:06.000000000 -0400
60977@@ -117,7 +117,8 @@ int ptrace_check_attach(struct task_stru
60978 return ret;
60979 }
60980
60981-int __ptrace_may_access(struct task_struct *task, unsigned int mode)
60982+static int __ptrace_may_access(struct task_struct *task, unsigned int mode,
60983+ unsigned int log)
60984 {
60985 const struct cred *cred = current_cred(), *tcred;
60986
60987@@ -141,7 +142,9 @@ int __ptrace_may_access(struct task_stru
60988 cred->gid != tcred->egid ||
60989 cred->gid != tcred->sgid ||
60990 cred->gid != tcred->gid) &&
60991- !capable(CAP_SYS_PTRACE)) {
60992+ ((!log && !capable_nolog(CAP_SYS_PTRACE)) ||
60993+ (log && !capable(CAP_SYS_PTRACE)))
60994+ ) {
60995 rcu_read_unlock();
60996 return -EPERM;
60997 }
60998@@ -149,7 +152,9 @@ int __ptrace_may_access(struct task_stru
60999 smp_rmb();
61000 if (task->mm)
61001 dumpable = get_dumpable(task->mm);
61002- if (!dumpable && !capable(CAP_SYS_PTRACE))
61003+ if (!dumpable &&
61004+ ((!log && !capable_nolog(CAP_SYS_PTRACE)) ||
61005+ (log && !capable(CAP_SYS_PTRACE))))
61006 return -EPERM;
61007
61008 return security_ptrace_access_check(task, mode);
61009@@ -159,7 +164,16 @@ bool ptrace_may_access(struct task_struc
61010 {
61011 int err;
61012 task_lock(task);
61013- err = __ptrace_may_access(task, mode);
61014+ err = __ptrace_may_access(task, mode, 0);
61015+ task_unlock(task);
61016+ return !err;
61017+}
61018+
61019+bool ptrace_may_access_log(struct task_struct *task, unsigned int mode)
61020+{
61021+ int err;
61022+ task_lock(task);
61023+ err = __ptrace_may_access(task, mode, 1);
61024 task_unlock(task);
61025 return !err;
61026 }
61027@@ -186,7 +200,7 @@ int ptrace_attach(struct task_struct *ta
61028 goto out;
61029
61030 task_lock(task);
61031- retval = __ptrace_may_access(task, PTRACE_MODE_ATTACH);
61032+ retval = __ptrace_may_access(task, PTRACE_MODE_ATTACH, 1);
61033 task_unlock(task);
61034 if (retval)
61035 goto unlock_creds;
61036@@ -199,7 +213,7 @@ int ptrace_attach(struct task_struct *ta
61037 goto unlock_tasklist;
61038
61039 task->ptrace = PT_PTRACED;
61040- if (capable(CAP_SYS_PTRACE))
61041+ if (capable_nolog(CAP_SYS_PTRACE))
61042 task->ptrace |= PT_PTRACE_CAP;
61043
61044 __ptrace_link(task, current);
61045@@ -351,6 +365,8 @@ int ptrace_readdata(struct task_struct *
61046 {
61047 int copied = 0;
61048
61049+ pax_track_stack();
61050+
61051 while (len > 0) {
61052 char buf[128];
61053 int this_len, retval;
61054@@ -376,6 +392,8 @@ int ptrace_writedata(struct task_struct
61055 {
61056 int copied = 0;
61057
61058+ pax_track_stack();
61059+
61060 while (len > 0) {
61061 char buf[128];
61062 int this_len, retval;
61063@@ -517,6 +535,8 @@ int ptrace_request(struct task_struct *c
61064 int ret = -EIO;
61065 siginfo_t siginfo;
61066
61067+ pax_track_stack();
61068+
61069 switch (request) {
61070 case PTRACE_PEEKTEXT:
61071 case PTRACE_PEEKDATA:
61072@@ -532,18 +552,18 @@ int ptrace_request(struct task_struct *c
61073 ret = ptrace_setoptions(child, data);
61074 break;
61075 case PTRACE_GETEVENTMSG:
61076- ret = put_user(child->ptrace_message, (unsigned long __user *) data);
61077+ ret = put_user(child->ptrace_message, (__force unsigned long __user *) data);
61078 break;
61079
61080 case PTRACE_GETSIGINFO:
61081 ret = ptrace_getsiginfo(child, &siginfo);
61082 if (!ret)
61083- ret = copy_siginfo_to_user((siginfo_t __user *) data,
61084+ ret = copy_siginfo_to_user((__force siginfo_t __user *) data,
61085 &siginfo);
61086 break;
61087
61088 case PTRACE_SETSIGINFO:
61089- if (copy_from_user(&siginfo, (siginfo_t __user *) data,
61090+ if (copy_from_user(&siginfo, (__force siginfo_t __user *) data,
61091 sizeof siginfo))
61092 ret = -EFAULT;
61093 else
61094@@ -621,14 +641,21 @@ SYSCALL_DEFINE4(ptrace, long, request, l
61095 goto out;
61096 }
61097
61098+ if (gr_handle_ptrace(child, request)) {
61099+ ret = -EPERM;
61100+ goto out_put_task_struct;
61101+ }
61102+
61103 if (request == PTRACE_ATTACH) {
61104 ret = ptrace_attach(child);
61105 /*
61106 * Some architectures need to do book-keeping after
61107 * a ptrace attach.
61108 */
61109- if (!ret)
61110+ if (!ret) {
61111 arch_ptrace_attach(child);
61112+ gr_audit_ptrace(child);
61113+ }
61114 goto out_put_task_struct;
61115 }
61116
61117@@ -653,7 +680,7 @@ int generic_ptrace_peekdata(struct task_
61118 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
61119 if (copied != sizeof(tmp))
61120 return -EIO;
61121- return put_user(tmp, (unsigned long __user *)data);
61122+ return put_user(tmp, (__force unsigned long __user *)data);
61123 }
61124
61125 int generic_ptrace_pokedata(struct task_struct *tsk, long addr, long data)
61126@@ -675,6 +702,8 @@ int compat_ptrace_request(struct task_st
61127 siginfo_t siginfo;
61128 int ret;
61129
61130+ pax_track_stack();
61131+
61132 switch (request) {
61133 case PTRACE_PEEKTEXT:
61134 case PTRACE_PEEKDATA:
61135@@ -740,14 +769,21 @@ asmlinkage long compat_sys_ptrace(compat
61136 goto out;
61137 }
61138
61139+ if (gr_handle_ptrace(child, request)) {
61140+ ret = -EPERM;
61141+ goto out_put_task_struct;
61142+ }
61143+
61144 if (request == PTRACE_ATTACH) {
61145 ret = ptrace_attach(child);
61146 /*
61147 * Some architectures need to do book-keeping after
61148 * a ptrace attach.
61149 */
61150- if (!ret)
61151+ if (!ret) {
61152 arch_ptrace_attach(child);
61153+ gr_audit_ptrace(child);
61154+ }
61155 goto out_put_task_struct;
61156 }
61157
61158diff -urNp linux-2.6.32.41/kernel/rcutorture.c linux-2.6.32.41/kernel/rcutorture.c
61159--- linux-2.6.32.41/kernel/rcutorture.c 2011-03-27 14:31:47.000000000 -0400
61160+++ linux-2.6.32.41/kernel/rcutorture.c 2011-05-04 17:56:28.000000000 -0400
61161@@ -118,12 +118,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_
61162 { 0 };
61163 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
61164 { 0 };
61165-static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
61166-static atomic_t n_rcu_torture_alloc;
61167-static atomic_t n_rcu_torture_alloc_fail;
61168-static atomic_t n_rcu_torture_free;
61169-static atomic_t n_rcu_torture_mberror;
61170-static atomic_t n_rcu_torture_error;
61171+static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
61172+static atomic_unchecked_t n_rcu_torture_alloc;
61173+static atomic_unchecked_t n_rcu_torture_alloc_fail;
61174+static atomic_unchecked_t n_rcu_torture_free;
61175+static atomic_unchecked_t n_rcu_torture_mberror;
61176+static atomic_unchecked_t n_rcu_torture_error;
61177 static long n_rcu_torture_timers;
61178 static struct list_head rcu_torture_removed;
61179 static cpumask_var_t shuffle_tmp_mask;
61180@@ -187,11 +187,11 @@ rcu_torture_alloc(void)
61181
61182 spin_lock_bh(&rcu_torture_lock);
61183 if (list_empty(&rcu_torture_freelist)) {
61184- atomic_inc(&n_rcu_torture_alloc_fail);
61185+ atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
61186 spin_unlock_bh(&rcu_torture_lock);
61187 return NULL;
61188 }
61189- atomic_inc(&n_rcu_torture_alloc);
61190+ atomic_inc_unchecked(&n_rcu_torture_alloc);
61191 p = rcu_torture_freelist.next;
61192 list_del_init(p);
61193 spin_unlock_bh(&rcu_torture_lock);
61194@@ -204,7 +204,7 @@ rcu_torture_alloc(void)
61195 static void
61196 rcu_torture_free(struct rcu_torture *p)
61197 {
61198- atomic_inc(&n_rcu_torture_free);
61199+ atomic_inc_unchecked(&n_rcu_torture_free);
61200 spin_lock_bh(&rcu_torture_lock);
61201 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
61202 spin_unlock_bh(&rcu_torture_lock);
61203@@ -319,7 +319,7 @@ rcu_torture_cb(struct rcu_head *p)
61204 i = rp->rtort_pipe_count;
61205 if (i > RCU_TORTURE_PIPE_LEN)
61206 i = RCU_TORTURE_PIPE_LEN;
61207- atomic_inc(&rcu_torture_wcount[i]);
61208+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
61209 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
61210 rp->rtort_mbtest = 0;
61211 rcu_torture_free(rp);
61212@@ -359,7 +359,7 @@ static void rcu_sync_torture_deferred_fr
61213 i = rp->rtort_pipe_count;
61214 if (i > RCU_TORTURE_PIPE_LEN)
61215 i = RCU_TORTURE_PIPE_LEN;
61216- atomic_inc(&rcu_torture_wcount[i]);
61217+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
61218 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
61219 rp->rtort_mbtest = 0;
61220 list_del(&rp->rtort_free);
61221@@ -653,7 +653,7 @@ rcu_torture_writer(void *arg)
61222 i = old_rp->rtort_pipe_count;
61223 if (i > RCU_TORTURE_PIPE_LEN)
61224 i = RCU_TORTURE_PIPE_LEN;
61225- atomic_inc(&rcu_torture_wcount[i]);
61226+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
61227 old_rp->rtort_pipe_count++;
61228 cur_ops->deferred_free(old_rp);
61229 }
61230@@ -718,7 +718,7 @@ static void rcu_torture_timer(unsigned l
61231 return;
61232 }
61233 if (p->rtort_mbtest == 0)
61234- atomic_inc(&n_rcu_torture_mberror);
61235+ atomic_inc_unchecked(&n_rcu_torture_mberror);
61236 spin_lock(&rand_lock);
61237 cur_ops->read_delay(&rand);
61238 n_rcu_torture_timers++;
61239@@ -776,7 +776,7 @@ rcu_torture_reader(void *arg)
61240 continue;
61241 }
61242 if (p->rtort_mbtest == 0)
61243- atomic_inc(&n_rcu_torture_mberror);
61244+ atomic_inc_unchecked(&n_rcu_torture_mberror);
61245 cur_ops->read_delay(&rand);
61246 preempt_disable();
61247 pipe_count = p->rtort_pipe_count;
61248@@ -834,17 +834,17 @@ rcu_torture_printk(char *page)
61249 rcu_torture_current,
61250 rcu_torture_current_version,
61251 list_empty(&rcu_torture_freelist),
61252- atomic_read(&n_rcu_torture_alloc),
61253- atomic_read(&n_rcu_torture_alloc_fail),
61254- atomic_read(&n_rcu_torture_free),
61255- atomic_read(&n_rcu_torture_mberror),
61256+ atomic_read_unchecked(&n_rcu_torture_alloc),
61257+ atomic_read_unchecked(&n_rcu_torture_alloc_fail),
61258+ atomic_read_unchecked(&n_rcu_torture_free),
61259+ atomic_read_unchecked(&n_rcu_torture_mberror),
61260 n_rcu_torture_timers);
61261- if (atomic_read(&n_rcu_torture_mberror) != 0)
61262+ if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0)
61263 cnt += sprintf(&page[cnt], " !!!");
61264 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
61265 if (i > 1) {
61266 cnt += sprintf(&page[cnt], "!!! ");
61267- atomic_inc(&n_rcu_torture_error);
61268+ atomic_inc_unchecked(&n_rcu_torture_error);
61269 WARN_ON_ONCE(1);
61270 }
61271 cnt += sprintf(&page[cnt], "Reader Pipe: ");
61272@@ -858,7 +858,7 @@ rcu_torture_printk(char *page)
61273 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
61274 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
61275 cnt += sprintf(&page[cnt], " %d",
61276- atomic_read(&rcu_torture_wcount[i]));
61277+ atomic_read_unchecked(&rcu_torture_wcount[i]));
61278 }
61279 cnt += sprintf(&page[cnt], "\n");
61280 if (cur_ops->stats)
61281@@ -1084,7 +1084,7 @@ rcu_torture_cleanup(void)
61282
61283 if (cur_ops->cleanup)
61284 cur_ops->cleanup();
61285- if (atomic_read(&n_rcu_torture_error))
61286+ if (atomic_read_unchecked(&n_rcu_torture_error))
61287 rcu_torture_print_module_parms("End of test: FAILURE");
61288 else
61289 rcu_torture_print_module_parms("End of test: SUCCESS");
61290@@ -1138,13 +1138,13 @@ rcu_torture_init(void)
61291
61292 rcu_torture_current = NULL;
61293 rcu_torture_current_version = 0;
61294- atomic_set(&n_rcu_torture_alloc, 0);
61295- atomic_set(&n_rcu_torture_alloc_fail, 0);
61296- atomic_set(&n_rcu_torture_free, 0);
61297- atomic_set(&n_rcu_torture_mberror, 0);
61298- atomic_set(&n_rcu_torture_error, 0);
61299+ atomic_set_unchecked(&n_rcu_torture_alloc, 0);
61300+ atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
61301+ atomic_set_unchecked(&n_rcu_torture_free, 0);
61302+ atomic_set_unchecked(&n_rcu_torture_mberror, 0);
61303+ atomic_set_unchecked(&n_rcu_torture_error, 0);
61304 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
61305- atomic_set(&rcu_torture_wcount[i], 0);
61306+ atomic_set_unchecked(&rcu_torture_wcount[i], 0);
61307 for_each_possible_cpu(cpu) {
61308 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
61309 per_cpu(rcu_torture_count, cpu)[i] = 0;
61310diff -urNp linux-2.6.32.41/kernel/rcutree.c linux-2.6.32.41/kernel/rcutree.c
61311--- linux-2.6.32.41/kernel/rcutree.c 2011-03-27 14:31:47.000000000 -0400
61312+++ linux-2.6.32.41/kernel/rcutree.c 2011-04-17 15:56:46.000000000 -0400
61313@@ -1303,7 +1303,7 @@ __rcu_process_callbacks(struct rcu_state
61314 /*
61315 * Do softirq processing for the current CPU.
61316 */
61317-static void rcu_process_callbacks(struct softirq_action *unused)
61318+static void rcu_process_callbacks(void)
61319 {
61320 /*
61321 * Memory references from any prior RCU read-side critical sections
61322diff -urNp linux-2.6.32.41/kernel/rcutree_plugin.h linux-2.6.32.41/kernel/rcutree_plugin.h
61323--- linux-2.6.32.41/kernel/rcutree_plugin.h 2011-03-27 14:31:47.000000000 -0400
61324+++ linux-2.6.32.41/kernel/rcutree_plugin.h 2011-04-17 15:56:46.000000000 -0400
61325@@ -145,7 +145,7 @@ static void rcu_preempt_note_context_swi
61326 */
61327 void __rcu_read_lock(void)
61328 {
61329- ACCESS_ONCE(current->rcu_read_lock_nesting)++;
61330+ ACCESS_ONCE_RW(current->rcu_read_lock_nesting)++;
61331 barrier(); /* needed if we ever invoke rcu_read_lock in rcutree.c */
61332 }
61333 EXPORT_SYMBOL_GPL(__rcu_read_lock);
61334@@ -251,7 +251,7 @@ void __rcu_read_unlock(void)
61335 struct task_struct *t = current;
61336
61337 barrier(); /* needed if we ever invoke rcu_read_unlock in rcutree.c */
61338- if (--ACCESS_ONCE(t->rcu_read_lock_nesting) == 0 &&
61339+ if (--ACCESS_ONCE_RW(t->rcu_read_lock_nesting) == 0 &&
61340 unlikely(ACCESS_ONCE(t->rcu_read_unlock_special)))
61341 rcu_read_unlock_special(t);
61342 }
61343diff -urNp linux-2.6.32.41/kernel/relay.c linux-2.6.32.41/kernel/relay.c
61344--- linux-2.6.32.41/kernel/relay.c 2011-03-27 14:31:47.000000000 -0400
61345+++ linux-2.6.32.41/kernel/relay.c 2011-05-16 21:46:57.000000000 -0400
61346@@ -1222,7 +1222,7 @@ static int subbuf_splice_actor(struct fi
61347 unsigned int flags,
61348 int *nonpad_ret)
61349 {
61350- unsigned int pidx, poff, total_len, subbuf_pages, nr_pages, ret;
61351+ unsigned int pidx, poff, total_len, subbuf_pages, nr_pages;
61352 struct rchan_buf *rbuf = in->private_data;
61353 unsigned int subbuf_size = rbuf->chan->subbuf_size;
61354 uint64_t pos = (uint64_t) *ppos;
61355@@ -1241,6 +1241,9 @@ static int subbuf_splice_actor(struct fi
61356 .ops = &relay_pipe_buf_ops,
61357 .spd_release = relay_page_release,
61358 };
61359+ ssize_t ret;
61360+
61361+ pax_track_stack();
61362
61363 if (rbuf->subbufs_produced == rbuf->subbufs_consumed)
61364 return 0;
61365diff -urNp linux-2.6.32.41/kernel/resource.c linux-2.6.32.41/kernel/resource.c
61366--- linux-2.6.32.41/kernel/resource.c 2011-03-27 14:31:47.000000000 -0400
61367+++ linux-2.6.32.41/kernel/resource.c 2011-04-17 15:56:46.000000000 -0400
61368@@ -132,8 +132,18 @@ static const struct file_operations proc
61369
61370 static int __init ioresources_init(void)
61371 {
61372+#ifdef CONFIG_GRKERNSEC_PROC_ADD
61373+#ifdef CONFIG_GRKERNSEC_PROC_USER
61374+ proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
61375+ proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
61376+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
61377+ proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
61378+ proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
61379+#endif
61380+#else
61381 proc_create("ioports", 0, NULL, &proc_ioports_operations);
61382 proc_create("iomem", 0, NULL, &proc_iomem_operations);
61383+#endif
61384 return 0;
61385 }
61386 __initcall(ioresources_init);
61387diff -urNp linux-2.6.32.41/kernel/rtmutex.c linux-2.6.32.41/kernel/rtmutex.c
61388--- linux-2.6.32.41/kernel/rtmutex.c 2011-03-27 14:31:47.000000000 -0400
61389+++ linux-2.6.32.41/kernel/rtmutex.c 2011-04-17 15:56:46.000000000 -0400
61390@@ -511,7 +511,7 @@ static void wakeup_next_waiter(struct rt
61391 */
61392 spin_lock_irqsave(&pendowner->pi_lock, flags);
61393
61394- WARN_ON(!pendowner->pi_blocked_on);
61395+ BUG_ON(!pendowner->pi_blocked_on);
61396 WARN_ON(pendowner->pi_blocked_on != waiter);
61397 WARN_ON(pendowner->pi_blocked_on->lock != lock);
61398
61399diff -urNp linux-2.6.32.41/kernel/rtmutex-tester.c linux-2.6.32.41/kernel/rtmutex-tester.c
61400--- linux-2.6.32.41/kernel/rtmutex-tester.c 2011-03-27 14:31:47.000000000 -0400
61401+++ linux-2.6.32.41/kernel/rtmutex-tester.c 2011-05-04 17:56:28.000000000 -0400
61402@@ -21,7 +21,7 @@
61403 #define MAX_RT_TEST_MUTEXES 8
61404
61405 static spinlock_t rttest_lock;
61406-static atomic_t rttest_event;
61407+static atomic_unchecked_t rttest_event;
61408
61409 struct test_thread_data {
61410 int opcode;
61411@@ -64,7 +64,7 @@ static int handle_op(struct test_thread_
61412
61413 case RTTEST_LOCKCONT:
61414 td->mutexes[td->opdata] = 1;
61415- td->event = atomic_add_return(1, &rttest_event);
61416+ td->event = atomic_add_return_unchecked(1, &rttest_event);
61417 return 0;
61418
61419 case RTTEST_RESET:
61420@@ -82,7 +82,7 @@ static int handle_op(struct test_thread_
61421 return 0;
61422
61423 case RTTEST_RESETEVENT:
61424- atomic_set(&rttest_event, 0);
61425+ atomic_set_unchecked(&rttest_event, 0);
61426 return 0;
61427
61428 default:
61429@@ -99,9 +99,9 @@ static int handle_op(struct test_thread_
61430 return ret;
61431
61432 td->mutexes[id] = 1;
61433- td->event = atomic_add_return(1, &rttest_event);
61434+ td->event = atomic_add_return_unchecked(1, &rttest_event);
61435 rt_mutex_lock(&mutexes[id]);
61436- td->event = atomic_add_return(1, &rttest_event);
61437+ td->event = atomic_add_return_unchecked(1, &rttest_event);
61438 td->mutexes[id] = 4;
61439 return 0;
61440
61441@@ -112,9 +112,9 @@ static int handle_op(struct test_thread_
61442 return ret;
61443
61444 td->mutexes[id] = 1;
61445- td->event = atomic_add_return(1, &rttest_event);
61446+ td->event = atomic_add_return_unchecked(1, &rttest_event);
61447 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
61448- td->event = atomic_add_return(1, &rttest_event);
61449+ td->event = atomic_add_return_unchecked(1, &rttest_event);
61450 td->mutexes[id] = ret ? 0 : 4;
61451 return ret ? -EINTR : 0;
61452
61453@@ -123,9 +123,9 @@ static int handle_op(struct test_thread_
61454 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
61455 return ret;
61456
61457- td->event = atomic_add_return(1, &rttest_event);
61458+ td->event = atomic_add_return_unchecked(1, &rttest_event);
61459 rt_mutex_unlock(&mutexes[id]);
61460- td->event = atomic_add_return(1, &rttest_event);
61461+ td->event = atomic_add_return_unchecked(1, &rttest_event);
61462 td->mutexes[id] = 0;
61463 return 0;
61464
61465@@ -187,7 +187,7 @@ void schedule_rt_mutex_test(struct rt_mu
61466 break;
61467
61468 td->mutexes[dat] = 2;
61469- td->event = atomic_add_return(1, &rttest_event);
61470+ td->event = atomic_add_return_unchecked(1, &rttest_event);
61471 break;
61472
61473 case RTTEST_LOCKBKL:
61474@@ -208,7 +208,7 @@ void schedule_rt_mutex_test(struct rt_mu
61475 return;
61476
61477 td->mutexes[dat] = 3;
61478- td->event = atomic_add_return(1, &rttest_event);
61479+ td->event = atomic_add_return_unchecked(1, &rttest_event);
61480 break;
61481
61482 case RTTEST_LOCKNOWAIT:
61483@@ -220,7 +220,7 @@ void schedule_rt_mutex_test(struct rt_mu
61484 return;
61485
61486 td->mutexes[dat] = 1;
61487- td->event = atomic_add_return(1, &rttest_event);
61488+ td->event = atomic_add_return_unchecked(1, &rttest_event);
61489 return;
61490
61491 case RTTEST_LOCKBKL:
61492diff -urNp linux-2.6.32.41/kernel/sched.c linux-2.6.32.41/kernel/sched.c
61493--- linux-2.6.32.41/kernel/sched.c 2011-03-27 14:31:47.000000000 -0400
61494+++ linux-2.6.32.41/kernel/sched.c 2011-05-22 23:02:06.000000000 -0400
61495@@ -5043,7 +5043,7 @@ out:
61496 * In CONFIG_NO_HZ case, the idle load balance owner will do the
61497 * rebalancing for all the cpus for whom scheduler ticks are stopped.
61498 */
61499-static void run_rebalance_domains(struct softirq_action *h)
61500+static void run_rebalance_domains(void)
61501 {
61502 int this_cpu = smp_processor_id();
61503 struct rq *this_rq = cpu_rq(this_cpu);
61504@@ -5700,6 +5700,8 @@ asmlinkage void __sched schedule(void)
61505 struct rq *rq;
61506 int cpu;
61507
61508+ pax_track_stack();
61509+
61510 need_resched:
61511 preempt_disable();
61512 cpu = smp_processor_id();
61513@@ -5770,7 +5772,7 @@ EXPORT_SYMBOL(schedule);
61514 * Look out! "owner" is an entirely speculative pointer
61515 * access and not reliable.
61516 */
61517-int mutex_spin_on_owner(struct mutex *lock, struct thread_info *owner)
61518+int mutex_spin_on_owner(struct mutex *lock, struct task_struct *owner)
61519 {
61520 unsigned int cpu;
61521 struct rq *rq;
61522@@ -5784,10 +5786,10 @@ int mutex_spin_on_owner(struct mutex *lo
61523 * DEBUG_PAGEALLOC could have unmapped it if
61524 * the mutex owner just released it and exited.
61525 */
61526- if (probe_kernel_address(&owner->cpu, cpu))
61527+ if (probe_kernel_address(&task_thread_info(owner)->cpu, cpu))
61528 return 0;
61529 #else
61530- cpu = owner->cpu;
61531+ cpu = task_thread_info(owner)->cpu;
61532 #endif
61533
61534 /*
61535@@ -5816,7 +5818,7 @@ int mutex_spin_on_owner(struct mutex *lo
61536 /*
61537 * Is that owner really running on that cpu?
61538 */
61539- if (task_thread_info(rq->curr) != owner || need_resched())
61540+ if (rq->curr != owner || need_resched())
61541 return 0;
61542
61543 cpu_relax();
61544@@ -6359,6 +6361,8 @@ int can_nice(const struct task_struct *p
61545 /* convert nice value [19,-20] to rlimit style value [1,40] */
61546 int nice_rlim = 20 - nice;
61547
61548+ gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
61549+
61550 return (nice_rlim <= p->signal->rlim[RLIMIT_NICE].rlim_cur ||
61551 capable(CAP_SYS_NICE));
61552 }
61553@@ -6392,7 +6396,8 @@ SYSCALL_DEFINE1(nice, int, increment)
61554 if (nice > 19)
61555 nice = 19;
61556
61557- if (increment < 0 && !can_nice(current, nice))
61558+ if (increment < 0 && (!can_nice(current, nice) ||
61559+ gr_handle_chroot_nice()))
61560 return -EPERM;
61561
61562 retval = security_task_setnice(current, nice);
61563@@ -8774,7 +8779,7 @@ static void init_sched_groups_power(int
61564 long power;
61565 int weight;
61566
61567- WARN_ON(!sd || !sd->groups);
61568+ BUG_ON(!sd || !sd->groups);
61569
61570 if (cpu != group_first_cpu(sd->groups))
61571 return;
61572diff -urNp linux-2.6.32.41/kernel/signal.c linux-2.6.32.41/kernel/signal.c
61573--- linux-2.6.32.41/kernel/signal.c 2011-04-17 17:00:52.000000000 -0400
61574+++ linux-2.6.32.41/kernel/signal.c 2011-05-22 23:02:06.000000000 -0400
61575@@ -41,12 +41,12 @@
61576
61577 static struct kmem_cache *sigqueue_cachep;
61578
61579-static void __user *sig_handler(struct task_struct *t, int sig)
61580+static __sighandler_t sig_handler(struct task_struct *t, int sig)
61581 {
61582 return t->sighand->action[sig - 1].sa.sa_handler;
61583 }
61584
61585-static int sig_handler_ignored(void __user *handler, int sig)
61586+static int sig_handler_ignored(__sighandler_t handler, int sig)
61587 {
61588 /* Is it explicitly or implicitly ignored? */
61589 return handler == SIG_IGN ||
61590@@ -56,7 +56,7 @@ static int sig_handler_ignored(void __us
61591 static int sig_task_ignored(struct task_struct *t, int sig,
61592 int from_ancestor_ns)
61593 {
61594- void __user *handler;
61595+ __sighandler_t handler;
61596
61597 handler = sig_handler(t, sig);
61598
61599@@ -207,6 +207,9 @@ static struct sigqueue *__sigqueue_alloc
61600 */
61601 user = get_uid(__task_cred(t)->user);
61602 atomic_inc(&user->sigpending);
61603+
61604+ if (!override_rlimit)
61605+ gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
61606 if (override_rlimit ||
61607 atomic_read(&user->sigpending) <=
61608 t->signal->rlim[RLIMIT_SIGPENDING].rlim_cur)
61609@@ -327,7 +330,7 @@ flush_signal_handlers(struct task_struct
61610
61611 int unhandled_signal(struct task_struct *tsk, int sig)
61612 {
61613- void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
61614+ __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
61615 if (is_global_init(tsk))
61616 return 1;
61617 if (handler != SIG_IGN && handler != SIG_DFL)
61618@@ -627,6 +630,9 @@ static int check_kill_permission(int sig
61619 }
61620 }
61621
61622+ if (gr_handle_signal(t, sig))
61623+ return -EPERM;
61624+
61625 return security_task_kill(t, info, sig, 0);
61626 }
61627
61628@@ -968,7 +974,7 @@ __group_send_sig_info(int sig, struct si
61629 return send_signal(sig, info, p, 1);
61630 }
61631
61632-static int
61633+int
61634 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
61635 {
61636 return send_signal(sig, info, t, 0);
61637@@ -1005,6 +1011,7 @@ force_sig_info(int sig, struct siginfo *
61638 unsigned long int flags;
61639 int ret, blocked, ignored;
61640 struct k_sigaction *action;
61641+ int is_unhandled = 0;
61642
61643 spin_lock_irqsave(&t->sighand->siglock, flags);
61644 action = &t->sighand->action[sig-1];
61645@@ -1019,9 +1026,18 @@ force_sig_info(int sig, struct siginfo *
61646 }
61647 if (action->sa.sa_handler == SIG_DFL)
61648 t->signal->flags &= ~SIGNAL_UNKILLABLE;
61649+ if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
61650+ is_unhandled = 1;
61651 ret = specific_send_sig_info(sig, info, t);
61652 spin_unlock_irqrestore(&t->sighand->siglock, flags);
61653
61654+ /* only deal with unhandled signals, java etc trigger SIGSEGV during
61655+ normal operation */
61656+ if (is_unhandled) {
61657+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
61658+ gr_handle_crash(t, sig);
61659+ }
61660+
61661 return ret;
61662 }
61663
61664@@ -1081,8 +1097,11 @@ int group_send_sig_info(int sig, struct
61665 {
61666 int ret = check_kill_permission(sig, info, p);
61667
61668- if (!ret && sig)
61669+ if (!ret && sig) {
61670 ret = do_send_sig_info(sig, info, p, true);
61671+ if (!ret)
61672+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
61673+ }
61674
61675 return ret;
61676 }
61677@@ -1644,6 +1663,8 @@ void ptrace_notify(int exit_code)
61678 {
61679 siginfo_t info;
61680
61681+ pax_track_stack();
61682+
61683 BUG_ON((exit_code & (0x7f | ~0xffff)) != SIGTRAP);
61684
61685 memset(&info, 0, sizeof info);
61686diff -urNp linux-2.6.32.41/kernel/smp.c linux-2.6.32.41/kernel/smp.c
61687--- linux-2.6.32.41/kernel/smp.c 2011-03-27 14:31:47.000000000 -0400
61688+++ linux-2.6.32.41/kernel/smp.c 2011-04-17 15:56:46.000000000 -0400
61689@@ -522,22 +522,22 @@ int smp_call_function(void (*func)(void
61690 }
61691 EXPORT_SYMBOL(smp_call_function);
61692
61693-void ipi_call_lock(void)
61694+void ipi_call_lock(void) __acquires(call_function.lock)
61695 {
61696 spin_lock(&call_function.lock);
61697 }
61698
61699-void ipi_call_unlock(void)
61700+void ipi_call_unlock(void) __releases(call_function.lock)
61701 {
61702 spin_unlock(&call_function.lock);
61703 }
61704
61705-void ipi_call_lock_irq(void)
61706+void ipi_call_lock_irq(void) __acquires(call_function.lock)
61707 {
61708 spin_lock_irq(&call_function.lock);
61709 }
61710
61711-void ipi_call_unlock_irq(void)
61712+void ipi_call_unlock_irq(void) __releases(call_function.lock)
61713 {
61714 spin_unlock_irq(&call_function.lock);
61715 }
61716diff -urNp linux-2.6.32.41/kernel/softirq.c linux-2.6.32.41/kernel/softirq.c
61717--- linux-2.6.32.41/kernel/softirq.c 2011-03-27 14:31:47.000000000 -0400
61718+++ linux-2.6.32.41/kernel/softirq.c 2011-04-17 15:56:46.000000000 -0400
61719@@ -56,7 +56,7 @@ static struct softirq_action softirq_vec
61720
61721 static DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
61722
61723-char *softirq_to_name[NR_SOFTIRQS] = {
61724+const char * const softirq_to_name[NR_SOFTIRQS] = {
61725 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
61726 "TASKLET", "SCHED", "HRTIMER", "RCU"
61727 };
61728@@ -206,7 +206,7 @@ EXPORT_SYMBOL(local_bh_enable_ip);
61729
61730 asmlinkage void __do_softirq(void)
61731 {
61732- struct softirq_action *h;
61733+ const struct softirq_action *h;
61734 __u32 pending;
61735 int max_restart = MAX_SOFTIRQ_RESTART;
61736 int cpu;
61737@@ -233,7 +233,7 @@ restart:
61738 kstat_incr_softirqs_this_cpu(h - softirq_vec);
61739
61740 trace_softirq_entry(h, softirq_vec);
61741- h->action(h);
61742+ h->action();
61743 trace_softirq_exit(h, softirq_vec);
61744 if (unlikely(prev_count != preempt_count())) {
61745 printk(KERN_ERR "huh, entered softirq %td %s %p"
61746@@ -363,7 +363,7 @@ void raise_softirq(unsigned int nr)
61747 local_irq_restore(flags);
61748 }
61749
61750-void open_softirq(int nr, void (*action)(struct softirq_action *))
61751+void open_softirq(int nr, void (*action)(void))
61752 {
61753 softirq_vec[nr].action = action;
61754 }
61755@@ -419,7 +419,7 @@ void __tasklet_hi_schedule_first(struct
61756
61757 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
61758
61759-static void tasklet_action(struct softirq_action *a)
61760+static void tasklet_action(void)
61761 {
61762 struct tasklet_struct *list;
61763
61764@@ -454,7 +454,7 @@ static void tasklet_action(struct softir
61765 }
61766 }
61767
61768-static void tasklet_hi_action(struct softirq_action *a)
61769+static void tasklet_hi_action(void)
61770 {
61771 struct tasklet_struct *list;
61772
61773diff -urNp linux-2.6.32.41/kernel/sys.c linux-2.6.32.41/kernel/sys.c
61774--- linux-2.6.32.41/kernel/sys.c 2011-03-27 14:31:47.000000000 -0400
61775+++ linux-2.6.32.41/kernel/sys.c 2011-04-17 15:56:46.000000000 -0400
61776@@ -133,6 +133,12 @@ static int set_one_prio(struct task_stru
61777 error = -EACCES;
61778 goto out;
61779 }
61780+
61781+ if (gr_handle_chroot_setpriority(p, niceval)) {
61782+ error = -EACCES;
61783+ goto out;
61784+ }
61785+
61786 no_nice = security_task_setnice(p, niceval);
61787 if (no_nice) {
61788 error = no_nice;
61789@@ -190,10 +196,10 @@ SYSCALL_DEFINE3(setpriority, int, which,
61790 !(user = find_user(who)))
61791 goto out_unlock; /* No processes for this user */
61792
61793- do_each_thread(g, p)
61794+ do_each_thread(g, p) {
61795 if (__task_cred(p)->uid == who)
61796 error = set_one_prio(p, niceval, error);
61797- while_each_thread(g, p);
61798+ } while_each_thread(g, p);
61799 if (who != cred->uid)
61800 free_uid(user); /* For find_user() */
61801 break;
61802@@ -253,13 +259,13 @@ SYSCALL_DEFINE2(getpriority, int, which,
61803 !(user = find_user(who)))
61804 goto out_unlock; /* No processes for this user */
61805
61806- do_each_thread(g, p)
61807+ do_each_thread(g, p) {
61808 if (__task_cred(p)->uid == who) {
61809 niceval = 20 - task_nice(p);
61810 if (niceval > retval)
61811 retval = niceval;
61812 }
61813- while_each_thread(g, p);
61814+ } while_each_thread(g, p);
61815 if (who != cred->uid)
61816 free_uid(user); /* for find_user() */
61817 break;
61818@@ -509,6 +515,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, g
61819 goto error;
61820 }
61821
61822+ if (gr_check_group_change(new->gid, new->egid, -1))
61823+ goto error;
61824+
61825 if (rgid != (gid_t) -1 ||
61826 (egid != (gid_t) -1 && egid != old->gid))
61827 new->sgid = new->egid;
61828@@ -542,6 +551,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
61829 goto error;
61830
61831 retval = -EPERM;
61832+
61833+ if (gr_check_group_change(gid, gid, gid))
61834+ goto error;
61835+
61836 if (capable(CAP_SETGID))
61837 new->gid = new->egid = new->sgid = new->fsgid = gid;
61838 else if (gid == old->gid || gid == old->sgid)
61839@@ -627,6 +640,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, u
61840 goto error;
61841 }
61842
61843+ if (gr_check_user_change(new->uid, new->euid, -1))
61844+ goto error;
61845+
61846 if (new->uid != old->uid) {
61847 retval = set_user(new);
61848 if (retval < 0)
61849@@ -675,6 +691,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
61850 goto error;
61851
61852 retval = -EPERM;
61853+
61854+ if (gr_check_crash_uid(uid))
61855+ goto error;
61856+ if (gr_check_user_change(uid, uid, uid))
61857+ goto error;
61858+
61859 if (capable(CAP_SETUID)) {
61860 new->suid = new->uid = uid;
61861 if (uid != old->uid) {
61862@@ -732,6 +754,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid,
61863 goto error;
61864 }
61865
61866+ if (gr_check_user_change(ruid, euid, -1))
61867+ goto error;
61868+
61869 if (ruid != (uid_t) -1) {
61870 new->uid = ruid;
61871 if (ruid != old->uid) {
61872@@ -800,6 +825,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid,
61873 goto error;
61874 }
61875
61876+ if (gr_check_group_change(rgid, egid, -1))
61877+ goto error;
61878+
61879 if (rgid != (gid_t) -1)
61880 new->gid = rgid;
61881 if (egid != (gid_t) -1)
61882@@ -849,6 +877,9 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
61883 if (security_task_setuid(uid, (uid_t)-1, (uid_t)-1, LSM_SETID_FS) < 0)
61884 goto error;
61885
61886+ if (gr_check_user_change(-1, -1, uid))
61887+ goto error;
61888+
61889 if (uid == old->uid || uid == old->euid ||
61890 uid == old->suid || uid == old->fsuid ||
61891 capable(CAP_SETUID)) {
61892@@ -889,6 +920,9 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
61893 if (gid == old->gid || gid == old->egid ||
61894 gid == old->sgid || gid == old->fsgid ||
61895 capable(CAP_SETGID)) {
61896+ if (gr_check_group_change(-1, -1, gid))
61897+ goto error;
61898+
61899 if (gid != old_fsgid) {
61900 new->fsgid = gid;
61901 goto change_okay;
61902@@ -1454,7 +1488,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsi
61903 error = get_dumpable(me->mm);
61904 break;
61905 case PR_SET_DUMPABLE:
61906- if (arg2 < 0 || arg2 > 1) {
61907+ if (arg2 > 1) {
61908 error = -EINVAL;
61909 break;
61910 }
61911diff -urNp linux-2.6.32.41/kernel/sysctl.c linux-2.6.32.41/kernel/sysctl.c
61912--- linux-2.6.32.41/kernel/sysctl.c 2011-03-27 14:31:47.000000000 -0400
61913+++ linux-2.6.32.41/kernel/sysctl.c 2011-04-17 15:56:46.000000000 -0400
61914@@ -63,6 +63,13 @@
61915 static int deprecated_sysctl_warning(struct __sysctl_args *args);
61916
61917 #if defined(CONFIG_SYSCTL)
61918+#include <linux/grsecurity.h>
61919+#include <linux/grinternal.h>
61920+
61921+extern __u32 gr_handle_sysctl(const ctl_table *table, const int op);
61922+extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
61923+ const int op);
61924+extern int gr_handle_chroot_sysctl(const int op);
61925
61926 /* External variables not in a header file. */
61927 extern int C_A_D;
61928@@ -168,6 +175,7 @@ static int proc_do_cad_pid(struct ctl_ta
61929 static int proc_taint(struct ctl_table *table, int write,
61930 void __user *buffer, size_t *lenp, loff_t *ppos);
61931 #endif
61932+extern ctl_table grsecurity_table[];
61933
61934 static struct ctl_table root_table[];
61935 static struct ctl_table_root sysctl_table_root;
61936@@ -200,6 +208,21 @@ extern struct ctl_table epoll_table[];
61937 int sysctl_legacy_va_layout;
61938 #endif
61939
61940+#ifdef CONFIG_PAX_SOFTMODE
61941+static ctl_table pax_table[] = {
61942+ {
61943+ .ctl_name = CTL_UNNUMBERED,
61944+ .procname = "softmode",
61945+ .data = &pax_softmode,
61946+ .maxlen = sizeof(unsigned int),
61947+ .mode = 0600,
61948+ .proc_handler = &proc_dointvec,
61949+ },
61950+
61951+ { .ctl_name = 0 }
61952+};
61953+#endif
61954+
61955 extern int prove_locking;
61956 extern int lock_stat;
61957
61958@@ -251,6 +274,24 @@ static int max_wakeup_granularity_ns = N
61959 #endif
61960
61961 static struct ctl_table kern_table[] = {
61962+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
61963+ {
61964+ .ctl_name = CTL_UNNUMBERED,
61965+ .procname = "grsecurity",
61966+ .mode = 0500,
61967+ .child = grsecurity_table,
61968+ },
61969+#endif
61970+
61971+#ifdef CONFIG_PAX_SOFTMODE
61972+ {
61973+ .ctl_name = CTL_UNNUMBERED,
61974+ .procname = "pax",
61975+ .mode = 0500,
61976+ .child = pax_table,
61977+ },
61978+#endif
61979+
61980 {
61981 .ctl_name = CTL_UNNUMBERED,
61982 .procname = "sched_child_runs_first",
61983@@ -567,8 +608,8 @@ static struct ctl_table kern_table[] = {
61984 .data = &modprobe_path,
61985 .maxlen = KMOD_PATH_LEN,
61986 .mode = 0644,
61987- .proc_handler = &proc_dostring,
61988- .strategy = &sysctl_string,
61989+ .proc_handler = &proc_dostring_modpriv,
61990+ .strategy = &sysctl_string_modpriv,
61991 },
61992 {
61993 .ctl_name = CTL_UNNUMBERED,
61994@@ -1247,6 +1288,13 @@ static struct ctl_table vm_table[] = {
61995 .mode = 0644,
61996 .proc_handler = &proc_dointvec
61997 },
61998+ {
61999+ .procname = "heap_stack_gap",
62000+ .data = &sysctl_heap_stack_gap,
62001+ .maxlen = sizeof(sysctl_heap_stack_gap),
62002+ .mode = 0644,
62003+ .proc_handler = proc_doulongvec_minmax,
62004+ },
62005 #else
62006 {
62007 .ctl_name = CTL_UNNUMBERED,
62008@@ -1803,6 +1851,8 @@ static int do_sysctl_strategy(struct ctl
62009 return 0;
62010 }
62011
62012+static int sysctl_perm_nochk(struct ctl_table_root *root, struct ctl_table *table, int op);
62013+
62014 static int parse_table(int __user *name, int nlen,
62015 void __user *oldval, size_t __user *oldlenp,
62016 void __user *newval, size_t newlen,
62017@@ -1821,7 +1871,7 @@ repeat:
62018 if (n == table->ctl_name) {
62019 int error;
62020 if (table->child) {
62021- if (sysctl_perm(root, table, MAY_EXEC))
62022+ if (sysctl_perm_nochk(root, table, MAY_EXEC))
62023 return -EPERM;
62024 name++;
62025 nlen--;
62026@@ -1906,6 +1956,33 @@ int sysctl_perm(struct ctl_table_root *r
62027 int error;
62028 int mode;
62029
62030+ if (table->parent != NULL && table->parent->procname != NULL &&
62031+ table->procname != NULL &&
62032+ gr_handle_sysctl_mod(table->parent->procname, table->procname, op))
62033+ return -EACCES;
62034+ if (gr_handle_chroot_sysctl(op))
62035+ return -EACCES;
62036+ error = gr_handle_sysctl(table, op);
62037+ if (error)
62038+ return error;
62039+
62040+ error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
62041+ if (error)
62042+ return error;
62043+
62044+ if (root->permissions)
62045+ mode = root->permissions(root, current->nsproxy, table);
62046+ else
62047+ mode = table->mode;
62048+
62049+ return test_perm(mode, op);
62050+}
62051+
62052+int sysctl_perm_nochk(struct ctl_table_root *root, struct ctl_table *table, int op)
62053+{
62054+ int error;
62055+ int mode;
62056+
62057 error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
62058 if (error)
62059 return error;
62060@@ -2335,6 +2412,16 @@ int proc_dostring(struct ctl_table *tabl
62061 buffer, lenp, ppos);
62062 }
62063
62064+int proc_dostring_modpriv(struct ctl_table *table, int write,
62065+ void __user *buffer, size_t *lenp, loff_t *ppos)
62066+{
62067+ if (write && !capable(CAP_SYS_MODULE))
62068+ return -EPERM;
62069+
62070+ return _proc_do_string(table->data, table->maxlen, write,
62071+ buffer, lenp, ppos);
62072+}
62073+
62074
62075 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
62076 int *valp,
62077@@ -2609,7 +2696,7 @@ static int __do_proc_doulongvec_minmax(v
62078 vleft = table->maxlen / sizeof(unsigned long);
62079 left = *lenp;
62080
62081- for (; left && vleft--; i++, min++, max++, first=0) {
62082+ for (; left && vleft--; i++, first=0) {
62083 if (write) {
62084 while (left) {
62085 char c;
62086@@ -2910,6 +2997,12 @@ int proc_dostring(struct ctl_table *tabl
62087 return -ENOSYS;
62088 }
62089
62090+int proc_dostring_modpriv(struct ctl_table *table, int write,
62091+ void __user *buffer, size_t *lenp, loff_t *ppos)
62092+{
62093+ return -ENOSYS;
62094+}
62095+
62096 int proc_dointvec(struct ctl_table *table, int write,
62097 void __user *buffer, size_t *lenp, loff_t *ppos)
62098 {
62099@@ -3038,6 +3131,16 @@ int sysctl_string(struct ctl_table *tabl
62100 return 1;
62101 }
62102
62103+int sysctl_string_modpriv(struct ctl_table *table,
62104+ void __user *oldval, size_t __user *oldlenp,
62105+ void __user *newval, size_t newlen)
62106+{
62107+ if (newval && newlen && !capable(CAP_SYS_MODULE))
62108+ return -EPERM;
62109+
62110+ return sysctl_string(table, oldval, oldlenp, newval, newlen);
62111+}
62112+
62113 /*
62114 * This function makes sure that all of the integers in the vector
62115 * are between the minimum and maximum values given in the arrays
62116@@ -3182,6 +3285,13 @@ int sysctl_string(struct ctl_table *tabl
62117 return -ENOSYS;
62118 }
62119
62120+int sysctl_string_modpriv(struct ctl_table *table,
62121+ void __user *oldval, size_t __user *oldlenp,
62122+ void __user *newval, size_t newlen)
62123+{
62124+ return -ENOSYS;
62125+}
62126+
62127 int sysctl_intvec(struct ctl_table *table,
62128 void __user *oldval, size_t __user *oldlenp,
62129 void __user *newval, size_t newlen)
62130@@ -3246,6 +3356,7 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
62131 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
62132 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
62133 EXPORT_SYMBOL(proc_dostring);
62134+EXPORT_SYMBOL(proc_dostring_modpriv);
62135 EXPORT_SYMBOL(proc_doulongvec_minmax);
62136 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
62137 EXPORT_SYMBOL(register_sysctl_table);
62138@@ -3254,5 +3365,6 @@ EXPORT_SYMBOL(sysctl_intvec);
62139 EXPORT_SYMBOL(sysctl_jiffies);
62140 EXPORT_SYMBOL(sysctl_ms_jiffies);
62141 EXPORT_SYMBOL(sysctl_string);
62142+EXPORT_SYMBOL(sysctl_string_modpriv);
62143 EXPORT_SYMBOL(sysctl_data);
62144 EXPORT_SYMBOL(unregister_sysctl_table);
62145diff -urNp linux-2.6.32.41/kernel/sysctl_check.c linux-2.6.32.41/kernel/sysctl_check.c
62146--- linux-2.6.32.41/kernel/sysctl_check.c 2011-03-27 14:31:47.000000000 -0400
62147+++ linux-2.6.32.41/kernel/sysctl_check.c 2011-04-17 15:56:46.000000000 -0400
62148@@ -1489,10 +1489,12 @@ int sysctl_check_table(struct nsproxy *n
62149 } else {
62150 if ((table->strategy == sysctl_data) ||
62151 (table->strategy == sysctl_string) ||
62152+ (table->strategy == sysctl_string_modpriv) ||
62153 (table->strategy == sysctl_intvec) ||
62154 (table->strategy == sysctl_jiffies) ||
62155 (table->strategy == sysctl_ms_jiffies) ||
62156 (table->proc_handler == proc_dostring) ||
62157+ (table->proc_handler == proc_dostring_modpriv) ||
62158 (table->proc_handler == proc_dointvec) ||
62159 (table->proc_handler == proc_dointvec_minmax) ||
62160 (table->proc_handler == proc_dointvec_jiffies) ||
62161diff -urNp linux-2.6.32.41/kernel/taskstats.c linux-2.6.32.41/kernel/taskstats.c
62162--- linux-2.6.32.41/kernel/taskstats.c 2011-03-27 14:31:47.000000000 -0400
62163+++ linux-2.6.32.41/kernel/taskstats.c 2011-04-17 15:56:46.000000000 -0400
62164@@ -26,9 +26,12 @@
62165 #include <linux/cgroup.h>
62166 #include <linux/fs.h>
62167 #include <linux/file.h>
62168+#include <linux/grsecurity.h>
62169 #include <net/genetlink.h>
62170 #include <asm/atomic.h>
62171
62172+extern int gr_is_taskstats_denied(int pid);
62173+
62174 /*
62175 * Maximum length of a cpumask that can be specified in
62176 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
62177@@ -433,6 +436,9 @@ static int taskstats_user_cmd(struct sk_
62178 size_t size;
62179 cpumask_var_t mask;
62180
62181+ if (gr_is_taskstats_denied(current->pid))
62182+ return -EACCES;
62183+
62184 if (!alloc_cpumask_var(&mask, GFP_KERNEL))
62185 return -ENOMEM;
62186
62187diff -urNp linux-2.6.32.41/kernel/time/tick-broadcast.c linux-2.6.32.41/kernel/time/tick-broadcast.c
62188--- linux-2.6.32.41/kernel/time/tick-broadcast.c 2011-05-23 16:56:59.000000000 -0400
62189+++ linux-2.6.32.41/kernel/time/tick-broadcast.c 2011-05-23 16:57:13.000000000 -0400
62190@@ -116,7 +116,7 @@ int tick_device_uses_broadcast(struct cl
62191 * then clear the broadcast bit.
62192 */
62193 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
62194- int cpu = smp_processor_id();
62195+ cpu = smp_processor_id();
62196
62197 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
62198 tick_broadcast_clear_oneshot(cpu);
62199diff -urNp linux-2.6.32.41/kernel/time/timekeeping.c linux-2.6.32.41/kernel/time/timekeeping.c
62200--- linux-2.6.32.41/kernel/time/timekeeping.c 2011-05-23 16:56:59.000000000 -0400
62201+++ linux-2.6.32.41/kernel/time/timekeeping.c 2011-05-23 19:09:33.000000000 -0400
62202@@ -14,6 +14,7 @@
62203 #include <linux/init.h>
62204 #include <linux/mm.h>
62205 #include <linux/sched.h>
62206+#include <linux/grsecurity.h>
62207 #include <linux/sysdev.h>
62208 #include <linux/clocksource.h>
62209 #include <linux/jiffies.h>
62210@@ -176,7 +177,7 @@ void update_xtime_cache(u64 nsec)
62211 */
62212 struct timespec ts = xtime;
62213 timespec_add_ns(&ts, nsec);
62214- ACCESS_ONCE(xtime_cache) = ts;
62215+ ACCESS_ONCE_RW(xtime_cache) = ts;
62216 }
62217
62218 /* must hold xtime_lock */
62219@@ -329,6 +330,8 @@ int do_settimeofday(struct timespec *tv)
62220 if ((unsigned long)tv->tv_nsec >= NSEC_PER_SEC)
62221 return -EINVAL;
62222
62223+ gr_log_timechange();
62224+
62225 write_seqlock_irqsave(&xtime_lock, flags);
62226
62227 timekeeping_forward_now();
62228diff -urNp linux-2.6.32.41/kernel/time/timer_list.c linux-2.6.32.41/kernel/time/timer_list.c
62229--- linux-2.6.32.41/kernel/time/timer_list.c 2011-03-27 14:31:47.000000000 -0400
62230+++ linux-2.6.32.41/kernel/time/timer_list.c 2011-04-17 15:56:46.000000000 -0400
62231@@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base,
62232
62233 static void print_name_offset(struct seq_file *m, void *sym)
62234 {
62235+#ifdef CONFIG_GRKERNSEC_HIDESYM
62236+ SEQ_printf(m, "<%p>", NULL);
62237+#else
62238 char symname[KSYM_NAME_LEN];
62239
62240 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
62241 SEQ_printf(m, "<%p>", sym);
62242 else
62243 SEQ_printf(m, "%s", symname);
62244+#endif
62245 }
62246
62247 static void
62248@@ -112,7 +116,11 @@ next_one:
62249 static void
62250 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
62251 {
62252+#ifdef CONFIG_GRKERNSEC_HIDESYM
62253+ SEQ_printf(m, " .base: %p\n", NULL);
62254+#else
62255 SEQ_printf(m, " .base: %p\n", base);
62256+#endif
62257 SEQ_printf(m, " .index: %d\n",
62258 base->index);
62259 SEQ_printf(m, " .resolution: %Lu nsecs\n",
62260@@ -289,7 +297,11 @@ static int __init init_timer_list_procfs
62261 {
62262 struct proc_dir_entry *pe;
62263
62264+#ifdef CONFIG_GRKERNSEC_PROC_ADD
62265+ pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
62266+#else
62267 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
62268+#endif
62269 if (!pe)
62270 return -ENOMEM;
62271 return 0;
62272diff -urNp linux-2.6.32.41/kernel/time/timer_stats.c linux-2.6.32.41/kernel/time/timer_stats.c
62273--- linux-2.6.32.41/kernel/time/timer_stats.c 2011-03-27 14:31:47.000000000 -0400
62274+++ linux-2.6.32.41/kernel/time/timer_stats.c 2011-05-04 17:56:28.000000000 -0400
62275@@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
62276 static unsigned long nr_entries;
62277 static struct entry entries[MAX_ENTRIES];
62278
62279-static atomic_t overflow_count;
62280+static atomic_unchecked_t overflow_count;
62281
62282 /*
62283 * The entries are in a hash-table, for fast lookup:
62284@@ -140,7 +140,7 @@ static void reset_entries(void)
62285 nr_entries = 0;
62286 memset(entries, 0, sizeof(entries));
62287 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
62288- atomic_set(&overflow_count, 0);
62289+ atomic_set_unchecked(&overflow_count, 0);
62290 }
62291
62292 static struct entry *alloc_entry(void)
62293@@ -261,7 +261,7 @@ void timer_stats_update_stats(void *time
62294 if (likely(entry))
62295 entry->count++;
62296 else
62297- atomic_inc(&overflow_count);
62298+ atomic_inc_unchecked(&overflow_count);
62299
62300 out_unlock:
62301 spin_unlock_irqrestore(lock, flags);
62302@@ -269,12 +269,16 @@ void timer_stats_update_stats(void *time
62303
62304 static void print_name_offset(struct seq_file *m, unsigned long addr)
62305 {
62306+#ifdef CONFIG_GRKERNSEC_HIDESYM
62307+ seq_printf(m, "<%p>", NULL);
62308+#else
62309 char symname[KSYM_NAME_LEN];
62310
62311 if (lookup_symbol_name(addr, symname) < 0)
62312 seq_printf(m, "<%p>", (void *)addr);
62313 else
62314 seq_printf(m, "%s", symname);
62315+#endif
62316 }
62317
62318 static int tstats_show(struct seq_file *m, void *v)
62319@@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *
62320
62321 seq_puts(m, "Timer Stats Version: v0.2\n");
62322 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
62323- if (atomic_read(&overflow_count))
62324+ if (atomic_read_unchecked(&overflow_count))
62325 seq_printf(m, "Overflow: %d entries\n",
62326- atomic_read(&overflow_count));
62327+ atomic_read_unchecked(&overflow_count));
62328
62329 for (i = 0; i < nr_entries; i++) {
62330 entry = entries + i;
62331@@ -415,7 +419,11 @@ static int __init init_tstats_procfs(voi
62332 {
62333 struct proc_dir_entry *pe;
62334
62335+#ifdef CONFIG_GRKERNSEC_PROC_ADD
62336+ pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
62337+#else
62338 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
62339+#endif
62340 if (!pe)
62341 return -ENOMEM;
62342 return 0;
62343diff -urNp linux-2.6.32.41/kernel/time.c linux-2.6.32.41/kernel/time.c
62344--- linux-2.6.32.41/kernel/time.c 2011-03-27 14:31:47.000000000 -0400
62345+++ linux-2.6.32.41/kernel/time.c 2011-04-17 15:56:46.000000000 -0400
62346@@ -165,6 +165,11 @@ int do_sys_settimeofday(struct timespec
62347 return error;
62348
62349 if (tz) {
62350+ /* we log in do_settimeofday called below, so don't log twice
62351+ */
62352+ if (!tv)
62353+ gr_log_timechange();
62354+
62355 /* SMP safe, global irq locking makes it work. */
62356 sys_tz = *tz;
62357 update_vsyscall_tz();
62358@@ -240,7 +245,7 @@ EXPORT_SYMBOL(current_fs_time);
62359 * Avoid unnecessary multiplications/divisions in the
62360 * two most common HZ cases:
62361 */
62362-unsigned int inline jiffies_to_msecs(const unsigned long j)
62363+inline unsigned int jiffies_to_msecs(const unsigned long j)
62364 {
62365 #if HZ <= MSEC_PER_SEC && !(MSEC_PER_SEC % HZ)
62366 return (MSEC_PER_SEC / HZ) * j;
62367@@ -256,7 +261,7 @@ unsigned int inline jiffies_to_msecs(con
62368 }
62369 EXPORT_SYMBOL(jiffies_to_msecs);
62370
62371-unsigned int inline jiffies_to_usecs(const unsigned long j)
62372+inline unsigned int jiffies_to_usecs(const unsigned long j)
62373 {
62374 #if HZ <= USEC_PER_SEC && !(USEC_PER_SEC % HZ)
62375 return (USEC_PER_SEC / HZ) * j;
62376diff -urNp linux-2.6.32.41/kernel/timer.c linux-2.6.32.41/kernel/timer.c
62377--- linux-2.6.32.41/kernel/timer.c 2011-03-27 14:31:47.000000000 -0400
62378+++ linux-2.6.32.41/kernel/timer.c 2011-04-17 15:56:46.000000000 -0400
62379@@ -1213,7 +1213,7 @@ void update_process_times(int user_tick)
62380 /*
62381 * This function runs timers and the timer-tq in bottom half context.
62382 */
62383-static void run_timer_softirq(struct softirq_action *h)
62384+static void run_timer_softirq(void)
62385 {
62386 struct tvec_base *base = __get_cpu_var(tvec_bases);
62387
62388diff -urNp linux-2.6.32.41/kernel/trace/blktrace.c linux-2.6.32.41/kernel/trace/blktrace.c
62389--- linux-2.6.32.41/kernel/trace/blktrace.c 2011-03-27 14:31:47.000000000 -0400
62390+++ linux-2.6.32.41/kernel/trace/blktrace.c 2011-05-04 17:56:28.000000000 -0400
62391@@ -313,7 +313,7 @@ static ssize_t blk_dropped_read(struct f
62392 struct blk_trace *bt = filp->private_data;
62393 char buf[16];
62394
62395- snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
62396+ snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
62397
62398 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
62399 }
62400@@ -376,7 +376,7 @@ static int blk_subbuf_start_callback(str
62401 return 1;
62402
62403 bt = buf->chan->private_data;
62404- atomic_inc(&bt->dropped);
62405+ atomic_inc_unchecked(&bt->dropped);
62406 return 0;
62407 }
62408
62409@@ -477,7 +477,7 @@ int do_blk_trace_setup(struct request_qu
62410
62411 bt->dir = dir;
62412 bt->dev = dev;
62413- atomic_set(&bt->dropped, 0);
62414+ atomic_set_unchecked(&bt->dropped, 0);
62415
62416 ret = -EIO;
62417 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
62418diff -urNp linux-2.6.32.41/kernel/trace/ftrace.c linux-2.6.32.41/kernel/trace/ftrace.c
62419--- linux-2.6.32.41/kernel/trace/ftrace.c 2011-03-27 14:31:47.000000000 -0400
62420+++ linux-2.6.32.41/kernel/trace/ftrace.c 2011-04-17 15:56:46.000000000 -0400
62421@@ -1100,13 +1100,18 @@ ftrace_code_disable(struct module *mod,
62422
62423 ip = rec->ip;
62424
62425+ ret = ftrace_arch_code_modify_prepare();
62426+ FTRACE_WARN_ON(ret);
62427+ if (ret)
62428+ return 0;
62429+
62430 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
62431+ FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
62432 if (ret) {
62433 ftrace_bug(ret, ip);
62434 rec->flags |= FTRACE_FL_FAILED;
62435- return 0;
62436 }
62437- return 1;
62438+ return ret ? 0 : 1;
62439 }
62440
62441 /*
62442diff -urNp linux-2.6.32.41/kernel/trace/ring_buffer.c linux-2.6.32.41/kernel/trace/ring_buffer.c
62443--- linux-2.6.32.41/kernel/trace/ring_buffer.c 2011-03-27 14:31:47.000000000 -0400
62444+++ linux-2.6.32.41/kernel/trace/ring_buffer.c 2011-04-17 15:56:46.000000000 -0400
62445@@ -606,7 +606,7 @@ static struct list_head *rb_list_head(st
62446 * the reader page). But if the next page is a header page,
62447 * its flags will be non zero.
62448 */
62449-static int inline
62450+static inline int
62451 rb_is_head_page(struct ring_buffer_per_cpu *cpu_buffer,
62452 struct buffer_page *page, struct list_head *list)
62453 {
62454diff -urNp linux-2.6.32.41/kernel/trace/trace.c linux-2.6.32.41/kernel/trace/trace.c
62455--- linux-2.6.32.41/kernel/trace/trace.c 2011-03-27 14:31:47.000000000 -0400
62456+++ linux-2.6.32.41/kernel/trace/trace.c 2011-05-16 21:46:57.000000000 -0400
62457@@ -3193,6 +3193,8 @@ static ssize_t tracing_splice_read_pipe(
62458 size_t rem;
62459 unsigned int i;
62460
62461+ pax_track_stack();
62462+
62463 /* copy the tracer to avoid using a global lock all around */
62464 mutex_lock(&trace_types_lock);
62465 if (unlikely(old_tracer != current_trace && current_trace)) {
62466@@ -3659,6 +3661,8 @@ tracing_buffers_splice_read(struct file
62467 int entries, size, i;
62468 size_t ret;
62469
62470+ pax_track_stack();
62471+
62472 if (*ppos & (PAGE_SIZE - 1)) {
62473 WARN_ONCE(1, "Ftrace: previous read must page-align\n");
62474 return -EINVAL;
62475@@ -3816,10 +3820,9 @@ static const struct file_operations trac
62476 };
62477 #endif
62478
62479-static struct dentry *d_tracer;
62480-
62481 struct dentry *tracing_init_dentry(void)
62482 {
62483+ static struct dentry *d_tracer;
62484 static int once;
62485
62486 if (d_tracer)
62487@@ -3839,10 +3842,9 @@ struct dentry *tracing_init_dentry(void)
62488 return d_tracer;
62489 }
62490
62491-static struct dentry *d_percpu;
62492-
62493 struct dentry *tracing_dentry_percpu(void)
62494 {
62495+ static struct dentry *d_percpu;
62496 static int once;
62497 struct dentry *d_tracer;
62498
62499diff -urNp linux-2.6.32.41/kernel/trace/trace_events.c linux-2.6.32.41/kernel/trace/trace_events.c
62500--- linux-2.6.32.41/kernel/trace/trace_events.c 2011-03-27 14:31:47.000000000 -0400
62501+++ linux-2.6.32.41/kernel/trace/trace_events.c 2011-04-17 15:56:46.000000000 -0400
62502@@ -951,6 +951,8 @@ static LIST_HEAD(ftrace_module_file_list
62503 * Modules must own their file_operations to keep up with
62504 * reference counting.
62505 */
62506+
62507+/* cannot be const */
62508 struct ftrace_module_file_ops {
62509 struct list_head list;
62510 struct module *mod;
62511diff -urNp linux-2.6.32.41/kernel/trace/trace_mmiotrace.c linux-2.6.32.41/kernel/trace/trace_mmiotrace.c
62512--- linux-2.6.32.41/kernel/trace/trace_mmiotrace.c 2011-03-27 14:31:47.000000000 -0400
62513+++ linux-2.6.32.41/kernel/trace/trace_mmiotrace.c 2011-05-04 17:56:28.000000000 -0400
62514@@ -23,7 +23,7 @@ struct header_iter {
62515 static struct trace_array *mmio_trace_array;
62516 static bool overrun_detected;
62517 static unsigned long prev_overruns;
62518-static atomic_t dropped_count;
62519+static atomic_unchecked_t dropped_count;
62520
62521 static void mmio_reset_data(struct trace_array *tr)
62522 {
62523@@ -126,7 +126,7 @@ static void mmio_close(struct trace_iter
62524
62525 static unsigned long count_overruns(struct trace_iterator *iter)
62526 {
62527- unsigned long cnt = atomic_xchg(&dropped_count, 0);
62528+ unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
62529 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
62530
62531 if (over > prev_overruns)
62532@@ -316,7 +316,7 @@ static void __trace_mmiotrace_rw(struct
62533 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
62534 sizeof(*entry), 0, pc);
62535 if (!event) {
62536- atomic_inc(&dropped_count);
62537+ atomic_inc_unchecked(&dropped_count);
62538 return;
62539 }
62540 entry = ring_buffer_event_data(event);
62541@@ -346,7 +346,7 @@ static void __trace_mmiotrace_map(struct
62542 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
62543 sizeof(*entry), 0, pc);
62544 if (!event) {
62545- atomic_inc(&dropped_count);
62546+ atomic_inc_unchecked(&dropped_count);
62547 return;
62548 }
62549 entry = ring_buffer_event_data(event);
62550diff -urNp linux-2.6.32.41/kernel/trace/trace_output.c linux-2.6.32.41/kernel/trace/trace_output.c
62551--- linux-2.6.32.41/kernel/trace/trace_output.c 2011-03-27 14:31:47.000000000 -0400
62552+++ linux-2.6.32.41/kernel/trace/trace_output.c 2011-04-17 15:56:46.000000000 -0400
62553@@ -237,7 +237,7 @@ int trace_seq_path(struct trace_seq *s,
62554 return 0;
62555 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
62556 if (!IS_ERR(p)) {
62557- p = mangle_path(s->buffer + s->len, p, "\n");
62558+ p = mangle_path(s->buffer + s->len, p, "\n\\");
62559 if (p) {
62560 s->len = p - s->buffer;
62561 return 1;
62562diff -urNp linux-2.6.32.41/kernel/trace/trace_stack.c linux-2.6.32.41/kernel/trace/trace_stack.c
62563--- linux-2.6.32.41/kernel/trace/trace_stack.c 2011-03-27 14:31:47.000000000 -0400
62564+++ linux-2.6.32.41/kernel/trace/trace_stack.c 2011-04-17 15:56:46.000000000 -0400
62565@@ -50,7 +50,7 @@ static inline void check_stack(void)
62566 return;
62567
62568 /* we do not handle interrupt stacks yet */
62569- if (!object_is_on_stack(&this_size))
62570+ if (!object_starts_on_stack(&this_size))
62571 return;
62572
62573 local_irq_save(flags);
62574diff -urNp linux-2.6.32.41/kernel/trace/trace_workqueue.c linux-2.6.32.41/kernel/trace/trace_workqueue.c
62575--- linux-2.6.32.41/kernel/trace/trace_workqueue.c 2011-03-27 14:31:47.000000000 -0400
62576+++ linux-2.6.32.41/kernel/trace/trace_workqueue.c 2011-04-17 15:56:46.000000000 -0400
62577@@ -21,7 +21,7 @@ struct cpu_workqueue_stats {
62578 int cpu;
62579 pid_t pid;
62580 /* Can be inserted from interrupt or user context, need to be atomic */
62581- atomic_t inserted;
62582+ atomic_unchecked_t inserted;
62583 /*
62584 * Don't need to be atomic, works are serialized in a single workqueue thread
62585 * on a single CPU.
62586@@ -58,7 +58,7 @@ probe_workqueue_insertion(struct task_st
62587 spin_lock_irqsave(&workqueue_cpu_stat(cpu)->lock, flags);
62588 list_for_each_entry(node, &workqueue_cpu_stat(cpu)->list, list) {
62589 if (node->pid == wq_thread->pid) {
62590- atomic_inc(&node->inserted);
62591+ atomic_inc_unchecked(&node->inserted);
62592 goto found;
62593 }
62594 }
62595@@ -205,7 +205,7 @@ static int workqueue_stat_show(struct se
62596 tsk = get_pid_task(pid, PIDTYPE_PID);
62597 if (tsk) {
62598 seq_printf(s, "%3d %6d %6u %s\n", cws->cpu,
62599- atomic_read(&cws->inserted), cws->executed,
62600+ atomic_read_unchecked(&cws->inserted), cws->executed,
62601 tsk->comm);
62602 put_task_struct(tsk);
62603 }
62604diff -urNp linux-2.6.32.41/kernel/user.c linux-2.6.32.41/kernel/user.c
62605--- linux-2.6.32.41/kernel/user.c 2011-03-27 14:31:47.000000000 -0400
62606+++ linux-2.6.32.41/kernel/user.c 2011-04-17 15:56:46.000000000 -0400
62607@@ -159,6 +159,7 @@ struct user_struct *alloc_uid(struct use
62608 spin_lock_irq(&uidhash_lock);
62609 up = uid_hash_find(uid, hashent);
62610 if (up) {
62611+ put_user_ns(ns);
62612 key_put(new->uid_keyring);
62613 key_put(new->session_keyring);
62614 kmem_cache_free(uid_cachep, new);
62615diff -urNp linux-2.6.32.41/lib/bug.c linux-2.6.32.41/lib/bug.c
62616--- linux-2.6.32.41/lib/bug.c 2011-03-27 14:31:47.000000000 -0400
62617+++ linux-2.6.32.41/lib/bug.c 2011-04-17 15:56:46.000000000 -0400
62618@@ -135,6 +135,8 @@ enum bug_trap_type report_bug(unsigned l
62619 return BUG_TRAP_TYPE_NONE;
62620
62621 bug = find_bug(bugaddr);
62622+ if (!bug)
62623+ return BUG_TRAP_TYPE_NONE;
62624
62625 printk(KERN_EMERG "------------[ cut here ]------------\n");
62626
62627diff -urNp linux-2.6.32.41/lib/debugobjects.c linux-2.6.32.41/lib/debugobjects.c
62628--- linux-2.6.32.41/lib/debugobjects.c 2011-03-27 14:31:47.000000000 -0400
62629+++ linux-2.6.32.41/lib/debugobjects.c 2011-04-17 15:56:46.000000000 -0400
62630@@ -277,7 +277,7 @@ static void debug_object_is_on_stack(voi
62631 if (limit > 4)
62632 return;
62633
62634- is_on_stack = object_is_on_stack(addr);
62635+ is_on_stack = object_starts_on_stack(addr);
62636 if (is_on_stack == onstack)
62637 return;
62638
62639diff -urNp linux-2.6.32.41/lib/dma-debug.c linux-2.6.32.41/lib/dma-debug.c
62640--- linux-2.6.32.41/lib/dma-debug.c 2011-03-27 14:31:47.000000000 -0400
62641+++ linux-2.6.32.41/lib/dma-debug.c 2011-04-17 15:56:46.000000000 -0400
62642@@ -861,7 +861,7 @@ out:
62643
62644 static void check_for_stack(struct device *dev, void *addr)
62645 {
62646- if (object_is_on_stack(addr))
62647+ if (object_starts_on_stack(addr))
62648 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
62649 "stack [addr=%p]\n", addr);
62650 }
62651diff -urNp linux-2.6.32.41/lib/idr.c linux-2.6.32.41/lib/idr.c
62652--- linux-2.6.32.41/lib/idr.c 2011-03-27 14:31:47.000000000 -0400
62653+++ linux-2.6.32.41/lib/idr.c 2011-04-17 15:56:46.000000000 -0400
62654@@ -156,7 +156,7 @@ static int sub_alloc(struct idr *idp, in
62655 id = (id | ((1 << (IDR_BITS * l)) - 1)) + 1;
62656
62657 /* if already at the top layer, we need to grow */
62658- if (id >= 1 << (idp->layers * IDR_BITS)) {
62659+ if (id >= (1 << (idp->layers * IDR_BITS))) {
62660 *starting_id = id;
62661 return IDR_NEED_TO_GROW;
62662 }
62663diff -urNp linux-2.6.32.41/lib/inflate.c linux-2.6.32.41/lib/inflate.c
62664--- linux-2.6.32.41/lib/inflate.c 2011-03-27 14:31:47.000000000 -0400
62665+++ linux-2.6.32.41/lib/inflate.c 2011-04-17 15:56:46.000000000 -0400
62666@@ -266,7 +266,7 @@ static void free(void *where)
62667 malloc_ptr = free_mem_ptr;
62668 }
62669 #else
62670-#define malloc(a) kmalloc(a, GFP_KERNEL)
62671+#define malloc(a) kmalloc((a), GFP_KERNEL)
62672 #define free(a) kfree(a)
62673 #endif
62674
62675diff -urNp linux-2.6.32.41/lib/Kconfig.debug linux-2.6.32.41/lib/Kconfig.debug
62676--- linux-2.6.32.41/lib/Kconfig.debug 2011-03-27 14:31:47.000000000 -0400
62677+++ linux-2.6.32.41/lib/Kconfig.debug 2011-04-17 15:56:46.000000000 -0400
62678@@ -905,7 +905,7 @@ config LATENCYTOP
62679 select STACKTRACE
62680 select SCHEDSTATS
62681 select SCHED_DEBUG
62682- depends on HAVE_LATENCYTOP_SUPPORT
62683+ depends on HAVE_LATENCYTOP_SUPPORT && !GRKERNSEC_HIDESYM
62684 help
62685 Enable this option if you want to use the LatencyTOP tool
62686 to find out which userspace is blocking on what kernel operations.
62687diff -urNp linux-2.6.32.41/lib/kobject.c linux-2.6.32.41/lib/kobject.c
62688--- linux-2.6.32.41/lib/kobject.c 2011-03-27 14:31:47.000000000 -0400
62689+++ linux-2.6.32.41/lib/kobject.c 2011-04-17 15:56:46.000000000 -0400
62690@@ -700,7 +700,7 @@ static ssize_t kobj_attr_store(struct ko
62691 return ret;
62692 }
62693
62694-struct sysfs_ops kobj_sysfs_ops = {
62695+const struct sysfs_ops kobj_sysfs_ops = {
62696 .show = kobj_attr_show,
62697 .store = kobj_attr_store,
62698 };
62699@@ -789,7 +789,7 @@ static struct kobj_type kset_ktype = {
62700 * If the kset was not able to be created, NULL will be returned.
62701 */
62702 static struct kset *kset_create(const char *name,
62703- struct kset_uevent_ops *uevent_ops,
62704+ const struct kset_uevent_ops *uevent_ops,
62705 struct kobject *parent_kobj)
62706 {
62707 struct kset *kset;
62708@@ -832,7 +832,7 @@ static struct kset *kset_create(const ch
62709 * If the kset was not able to be created, NULL will be returned.
62710 */
62711 struct kset *kset_create_and_add(const char *name,
62712- struct kset_uevent_ops *uevent_ops,
62713+ const struct kset_uevent_ops *uevent_ops,
62714 struct kobject *parent_kobj)
62715 {
62716 struct kset *kset;
62717diff -urNp linux-2.6.32.41/lib/kobject_uevent.c linux-2.6.32.41/lib/kobject_uevent.c
62718--- linux-2.6.32.41/lib/kobject_uevent.c 2011-03-27 14:31:47.000000000 -0400
62719+++ linux-2.6.32.41/lib/kobject_uevent.c 2011-04-17 15:56:46.000000000 -0400
62720@@ -95,7 +95,7 @@ int kobject_uevent_env(struct kobject *k
62721 const char *subsystem;
62722 struct kobject *top_kobj;
62723 struct kset *kset;
62724- struct kset_uevent_ops *uevent_ops;
62725+ const struct kset_uevent_ops *uevent_ops;
62726 u64 seq;
62727 int i = 0;
62728 int retval = 0;
62729diff -urNp linux-2.6.32.41/lib/kref.c linux-2.6.32.41/lib/kref.c
62730--- linux-2.6.32.41/lib/kref.c 2011-03-27 14:31:47.000000000 -0400
62731+++ linux-2.6.32.41/lib/kref.c 2011-04-17 15:56:46.000000000 -0400
62732@@ -61,7 +61,7 @@ void kref_get(struct kref *kref)
62733 */
62734 int kref_put(struct kref *kref, void (*release)(struct kref *kref))
62735 {
62736- WARN_ON(release == NULL);
62737+ BUG_ON(release == NULL);
62738 WARN_ON(release == (void (*)(struct kref *))kfree);
62739
62740 if (atomic_dec_and_test(&kref->refcount)) {
62741diff -urNp linux-2.6.32.41/lib/parser.c linux-2.6.32.41/lib/parser.c
62742--- linux-2.6.32.41/lib/parser.c 2011-03-27 14:31:47.000000000 -0400
62743+++ linux-2.6.32.41/lib/parser.c 2011-04-17 15:56:46.000000000 -0400
62744@@ -126,7 +126,7 @@ static int match_number(substring_t *s,
62745 char *buf;
62746 int ret;
62747
62748- buf = kmalloc(s->to - s->from + 1, GFP_KERNEL);
62749+ buf = kmalloc((s->to - s->from) + 1, GFP_KERNEL);
62750 if (!buf)
62751 return -ENOMEM;
62752 memcpy(buf, s->from, s->to - s->from);
62753diff -urNp linux-2.6.32.41/lib/radix-tree.c linux-2.6.32.41/lib/radix-tree.c
62754--- linux-2.6.32.41/lib/radix-tree.c 2011-03-27 14:31:47.000000000 -0400
62755+++ linux-2.6.32.41/lib/radix-tree.c 2011-04-17 15:56:46.000000000 -0400
62756@@ -81,7 +81,7 @@ struct radix_tree_preload {
62757 int nr;
62758 struct radix_tree_node *nodes[RADIX_TREE_MAX_PATH];
62759 };
62760-static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
62761+static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
62762
62763 static inline gfp_t root_gfp_mask(struct radix_tree_root *root)
62764 {
62765diff -urNp linux-2.6.32.41/lib/random32.c linux-2.6.32.41/lib/random32.c
62766--- linux-2.6.32.41/lib/random32.c 2011-03-27 14:31:47.000000000 -0400
62767+++ linux-2.6.32.41/lib/random32.c 2011-04-17 15:56:46.000000000 -0400
62768@@ -61,7 +61,7 @@ static u32 __random32(struct rnd_state *
62769 */
62770 static inline u32 __seed(u32 x, u32 m)
62771 {
62772- return (x < m) ? x + m : x;
62773+ return (x <= m) ? x + m + 1 : x;
62774 }
62775
62776 /**
62777diff -urNp linux-2.6.32.41/lib/vsprintf.c linux-2.6.32.41/lib/vsprintf.c
62778--- linux-2.6.32.41/lib/vsprintf.c 2011-03-27 14:31:47.000000000 -0400
62779+++ linux-2.6.32.41/lib/vsprintf.c 2011-04-17 15:56:46.000000000 -0400
62780@@ -16,6 +16,9 @@
62781 * - scnprintf and vscnprintf
62782 */
62783
62784+#ifdef CONFIG_GRKERNSEC_HIDESYM
62785+#define __INCLUDED_BY_HIDESYM 1
62786+#endif
62787 #include <stdarg.h>
62788 #include <linux/module.h>
62789 #include <linux/types.h>
62790@@ -546,12 +549,12 @@ static char *number(char *buf, char *end
62791 return buf;
62792 }
62793
62794-static char *string(char *buf, char *end, char *s, struct printf_spec spec)
62795+static char *string(char *buf, char *end, const char *s, struct printf_spec spec)
62796 {
62797 int len, i;
62798
62799 if ((unsigned long)s < PAGE_SIZE)
62800- s = "<NULL>";
62801+ s = "(null)";
62802
62803 len = strnlen(s, spec.precision);
62804
62805@@ -581,7 +584,7 @@ static char *symbol_string(char *buf, ch
62806 unsigned long value = (unsigned long) ptr;
62807 #ifdef CONFIG_KALLSYMS
62808 char sym[KSYM_SYMBOL_LEN];
62809- if (ext != 'f' && ext != 's')
62810+ if (ext != 'f' && ext != 's' && ext != 'a')
62811 sprint_symbol(sym, value);
62812 else
62813 kallsyms_lookup(value, NULL, NULL, NULL, sym);
62814@@ -801,6 +804,8 @@ static char *ip4_addr_string(char *buf,
62815 * - 'f' For simple symbolic function names without offset
62816 * - 'S' For symbolic direct pointers with offset
62817 * - 's' For symbolic direct pointers without offset
62818+ * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
62819+ * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
62820 * - 'R' For a struct resource pointer, it prints the range of
62821 * addresses (not the name nor the flags)
62822 * - 'M' For a 6-byte MAC address, it prints the address in the
62823@@ -822,7 +827,7 @@ static char *pointer(const char *fmt, ch
62824 struct printf_spec spec)
62825 {
62826 if (!ptr)
62827- return string(buf, end, "(null)", spec);
62828+ return string(buf, end, "(nil)", spec);
62829
62830 switch (*fmt) {
62831 case 'F':
62832@@ -831,6 +836,14 @@ static char *pointer(const char *fmt, ch
62833 case 's':
62834 /* Fallthrough */
62835 case 'S':
62836+#ifdef CONFIG_GRKERNSEC_HIDESYM
62837+ break;
62838+#else
62839+ return symbol_string(buf, end, ptr, spec, *fmt);
62840+#endif
62841+ case 'a':
62842+ /* Fallthrough */
62843+ case 'A':
62844 return symbol_string(buf, end, ptr, spec, *fmt);
62845 case 'R':
62846 return resource_string(buf, end, ptr, spec);
62847@@ -1445,7 +1458,7 @@ do { \
62848 size_t len;
62849 if ((unsigned long)save_str > (unsigned long)-PAGE_SIZE
62850 || (unsigned long)save_str < PAGE_SIZE)
62851- save_str = "<NULL>";
62852+ save_str = "(null)";
62853 len = strlen(save_str);
62854 if (str + len + 1 < end)
62855 memcpy(str, save_str, len + 1);
62856@@ -1555,11 +1568,11 @@ int bstr_printf(char *buf, size_t size,
62857 typeof(type) value; \
62858 if (sizeof(type) == 8) { \
62859 args = PTR_ALIGN(args, sizeof(u32)); \
62860- *(u32 *)&value = *(u32 *)args; \
62861- *((u32 *)&value + 1) = *(u32 *)(args + 4); \
62862+ *(u32 *)&value = *(const u32 *)args; \
62863+ *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
62864 } else { \
62865 args = PTR_ALIGN(args, sizeof(type)); \
62866- value = *(typeof(type) *)args; \
62867+ value = *(const typeof(type) *)args; \
62868 } \
62869 args += sizeof(type); \
62870 value; \
62871@@ -1622,7 +1635,7 @@ int bstr_printf(char *buf, size_t size,
62872 const char *str_arg = args;
62873 size_t len = strlen(str_arg);
62874 args += len + 1;
62875- str = string(str, end, (char *)str_arg, spec);
62876+ str = string(str, end, str_arg, spec);
62877 break;
62878 }
62879
62880diff -urNp linux-2.6.32.41/localversion-grsec linux-2.6.32.41/localversion-grsec
62881--- linux-2.6.32.41/localversion-grsec 1969-12-31 19:00:00.000000000 -0500
62882+++ linux-2.6.32.41/localversion-grsec 2011-04-17 15:56:46.000000000 -0400
62883@@ -0,0 +1 @@
62884+-grsec
62885diff -urNp linux-2.6.32.41/Makefile linux-2.6.32.41/Makefile
62886--- linux-2.6.32.41/Makefile 2011-05-23 16:56:59.000000000 -0400
62887+++ linux-2.6.32.41/Makefile 2011-06-07 18:06:04.000000000 -0400
62888@@ -221,8 +221,9 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH"
62889
62890 HOSTCC = gcc
62891 HOSTCXX = g++
62892-HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
62893-HOSTCXXFLAGS = -O2
62894+HOSTCFLAGS = -Wall -W -Wmissing-prototypes -Wstrict-prototypes -Wno-unused-parameter -Wno-missing-field-initializers -O2 -fomit-frame-pointer -fno-delete-null-pointer-checks
62895+HOSTCFLAGS += $(call cc-option, -Wno-empty-body)
62896+HOSTCXXFLAGS = -O2 -fno-delete-null-pointer-checks
62897
62898 # Decide whether to build built-in, modular, or both.
62899 # Normally, just do built-in.
62900@@ -342,10 +343,12 @@ LINUXINCLUDE := -Iinclude \
62901 KBUILD_CPPFLAGS := -D__KERNEL__
62902
62903 KBUILD_CFLAGS := -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
62904+ -W -Wno-unused-parameter -Wno-missing-field-initializers \
62905 -fno-strict-aliasing -fno-common \
62906 -Werror-implicit-function-declaration \
62907 -Wno-format-security \
62908 -fno-delete-null-pointer-checks
62909+KBUILD_CFLAGS += $(call cc-option, -Wno-empty-body)
62910 KBUILD_AFLAGS := -D__ASSEMBLY__
62911
62912 # Read KERNELRELEASE from include/config/kernel.release (if it exists)
62913@@ -403,7 +406,7 @@ endif
62914 # of make so .config is not included in this case either (for *config).
62915
62916 no-dot-config-targets := clean mrproper distclean \
62917- cscope TAGS tags help %docs check% \
62918+ cscope gtags TAGS tags help %docs check% \
62919 include/linux/version.h headers_% \
62920 kernelrelease kernelversion
62921
62922@@ -644,7 +647,7 @@ export mod_strip_cmd
62923
62924
62925 ifeq ($(KBUILD_EXTMOD),)
62926-core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
62927+core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
62928
62929 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
62930 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
62931@@ -949,7 +952,19 @@ include/config/kernel.release: include/c
62932 # version.h and scripts_basic is processed / created.
62933
62934 # Listed in dependency order
62935-PHONY += prepare archprepare prepare0 prepare1 prepare2 prepare3
62936+PHONY += prepare archprepare prepare0 prepare1 prepare2 prepare3 pax-plugin
62937+
62938+ifeq ($(CONFIG_PAX_MEMORY_STACKLEAK),y)
62939+KBUILD_CFLAGS += $(call cc-ifversion, -ge, 0405, -fplugin=$(objtree)/tools/gcc/pax_plugin.so -fplugin-arg-pax_plugin-track-lowest-sp=100)
62940+endif
62941+pax-plugin:
62942+ifneq (,$(findstring pax_plugin, $(KBUILD_CFLAGS)))
62943+ $(Q)$(MAKE) $(build)=tools/gcc
62944+else
62945+ifeq ($(CONFIG_PAX_MEMORY_STACKLEAK),y)
62946+ $(Q)echo "warning, your gcc does not support plugins, PAX_MEMORY_STACKLEAK will be less secure"
62947+endif
62948+endif
62949
62950 # prepare3 is used to check if we are building in a separate output directory,
62951 # and if so do:
62952@@ -970,7 +985,7 @@ ifneq ($(KBUILD_SRC),)
62953 endif
62954
62955 # prepare2 creates a makefile if using a separate output directory
62956-prepare2: prepare3 outputmakefile
62957+prepare2: prepare3 outputmakefile pax-plugin
62958
62959 prepare1: prepare2 include/linux/version.h include/linux/utsrelease.h \
62960 include/asm include/config/auto.conf
62961@@ -1198,7 +1213,7 @@ MRPROPER_FILES += .config .config.old in
62962 include/linux/autoconf.h include/linux/version.h \
62963 include/linux/utsrelease.h \
62964 include/linux/bounds.h include/asm*/asm-offsets.h \
62965- Module.symvers Module.markers tags TAGS cscope*
62966+ Module.symvers Module.markers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS
62967
62968 # clean - Delete most, but leave enough to build external modules
62969 #
62970@@ -1289,6 +1304,7 @@ help:
62971 @echo ' modules_prepare - Set up for building external modules'
62972 @echo ' tags/TAGS - Generate tags file for editors'
62973 @echo ' cscope - Generate cscope index'
62974+ @echo ' gtags - Generate GNU GLOBAL index'
62975 @echo ' kernelrelease - Output the release version string'
62976 @echo ' kernelversion - Output the version stored in Makefile'
62977 @echo ' headers_install - Install sanitised kernel headers to INSTALL_HDR_PATH'; \
62978@@ -1445,7 +1461,7 @@ endif # KBUILD_EXTMOD
62979 quiet_cmd_tags = GEN $@
62980 cmd_tags = $(CONFIG_SHELL) $(srctree)/scripts/tags.sh $@
62981
62982-tags TAGS cscope: FORCE
62983+tags TAGS cscope gtags: FORCE
62984 $(call cmd,tags)
62985
62986 # Scripts to check various things for consistency
62987diff -urNp linux-2.6.32.41/mm/backing-dev.c linux-2.6.32.41/mm/backing-dev.c
62988--- linux-2.6.32.41/mm/backing-dev.c 2011-03-27 14:31:47.000000000 -0400
62989+++ linux-2.6.32.41/mm/backing-dev.c 2011-05-04 17:56:28.000000000 -0400
62990@@ -484,7 +484,7 @@ static void bdi_add_to_pending(struct rc
62991 * Add the default flusher task that gets created for any bdi
62992 * that has dirty data pending writeout
62993 */
62994-void static bdi_add_default_flusher_task(struct backing_dev_info *bdi)
62995+static void bdi_add_default_flusher_task(struct backing_dev_info *bdi)
62996 {
62997 if (!bdi_cap_writeback_dirty(bdi))
62998 return;
62999diff -urNp linux-2.6.32.41/mm/filemap.c linux-2.6.32.41/mm/filemap.c
63000--- linux-2.6.32.41/mm/filemap.c 2011-03-27 14:31:47.000000000 -0400
63001+++ linux-2.6.32.41/mm/filemap.c 2011-04-17 15:56:46.000000000 -0400
63002@@ -1631,7 +1631,7 @@ int generic_file_mmap(struct file * file
63003 struct address_space *mapping = file->f_mapping;
63004
63005 if (!mapping->a_ops->readpage)
63006- return -ENOEXEC;
63007+ return -ENODEV;
63008 file_accessed(file);
63009 vma->vm_ops = &generic_file_vm_ops;
63010 vma->vm_flags |= VM_CAN_NONLINEAR;
63011@@ -2027,6 +2027,7 @@ inline int generic_write_checks(struct f
63012 *pos = i_size_read(inode);
63013
63014 if (limit != RLIM_INFINITY) {
63015+ gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
63016 if (*pos >= limit) {
63017 send_sig(SIGXFSZ, current, 0);
63018 return -EFBIG;
63019diff -urNp linux-2.6.32.41/mm/fremap.c linux-2.6.32.41/mm/fremap.c
63020--- linux-2.6.32.41/mm/fremap.c 2011-03-27 14:31:47.000000000 -0400
63021+++ linux-2.6.32.41/mm/fremap.c 2011-04-17 15:56:46.000000000 -0400
63022@@ -153,6 +153,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsign
63023 retry:
63024 vma = find_vma(mm, start);
63025
63026+#ifdef CONFIG_PAX_SEGMEXEC
63027+ if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
63028+ goto out;
63029+#endif
63030+
63031 /*
63032 * Make sure the vma is shared, that it supports prefaulting,
63033 * and that the remapped range is valid and fully within
63034@@ -221,7 +226,7 @@ SYSCALL_DEFINE5(remap_file_pages, unsign
63035 /*
63036 * drop PG_Mlocked flag for over-mapped range
63037 */
63038- unsigned int saved_flags = vma->vm_flags;
63039+ unsigned long saved_flags = vma->vm_flags;
63040 munlock_vma_pages_range(vma, start, start + size);
63041 vma->vm_flags = saved_flags;
63042 }
63043diff -urNp linux-2.6.32.41/mm/highmem.c linux-2.6.32.41/mm/highmem.c
63044--- linux-2.6.32.41/mm/highmem.c 2011-03-27 14:31:47.000000000 -0400
63045+++ linux-2.6.32.41/mm/highmem.c 2011-04-17 15:56:46.000000000 -0400
63046@@ -116,9 +116,10 @@ static void flush_all_zero_pkmaps(void)
63047 * So no dangers, even with speculative execution.
63048 */
63049 page = pte_page(pkmap_page_table[i]);
63050+ pax_open_kernel();
63051 pte_clear(&init_mm, (unsigned long)page_address(page),
63052 &pkmap_page_table[i]);
63053-
63054+ pax_close_kernel();
63055 set_page_address(page, NULL);
63056 need_flush = 1;
63057 }
63058@@ -177,9 +178,11 @@ start:
63059 }
63060 }
63061 vaddr = PKMAP_ADDR(last_pkmap_nr);
63062+
63063+ pax_open_kernel();
63064 set_pte_at(&init_mm, vaddr,
63065 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
63066-
63067+ pax_close_kernel();
63068 pkmap_count[last_pkmap_nr] = 1;
63069 set_page_address(page, (void *)vaddr);
63070
63071diff -urNp linux-2.6.32.41/mm/hugetlb.c linux-2.6.32.41/mm/hugetlb.c
63072--- linux-2.6.32.41/mm/hugetlb.c 2011-03-27 14:31:47.000000000 -0400
63073+++ linux-2.6.32.41/mm/hugetlb.c 2011-04-17 15:56:46.000000000 -0400
63074@@ -1925,6 +1925,26 @@ static int unmap_ref_private(struct mm_s
63075 return 1;
63076 }
63077
63078+#ifdef CONFIG_PAX_SEGMEXEC
63079+static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
63080+{
63081+ struct mm_struct *mm = vma->vm_mm;
63082+ struct vm_area_struct *vma_m;
63083+ unsigned long address_m;
63084+ pte_t *ptep_m;
63085+
63086+ vma_m = pax_find_mirror_vma(vma);
63087+ if (!vma_m)
63088+ return;
63089+
63090+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
63091+ address_m = address + SEGMEXEC_TASK_SIZE;
63092+ ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
63093+ get_page(page_m);
63094+ set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
63095+}
63096+#endif
63097+
63098 static int hugetlb_cow(struct mm_struct *mm, struct vm_area_struct *vma,
63099 unsigned long address, pte_t *ptep, pte_t pte,
63100 struct page *pagecache_page)
63101@@ -1996,6 +2016,11 @@ retry_avoidcopy:
63102 huge_ptep_clear_flush(vma, address, ptep);
63103 set_huge_pte_at(mm, address, ptep,
63104 make_huge_pte(vma, new_page, 1));
63105+
63106+#ifdef CONFIG_PAX_SEGMEXEC
63107+ pax_mirror_huge_pte(vma, address, new_page);
63108+#endif
63109+
63110 /* Make the old page be freed below */
63111 new_page = old_page;
63112 }
63113@@ -2127,6 +2152,10 @@ retry:
63114 && (vma->vm_flags & VM_SHARED)));
63115 set_huge_pte_at(mm, address, ptep, new_pte);
63116
63117+#ifdef CONFIG_PAX_SEGMEXEC
63118+ pax_mirror_huge_pte(vma, address, page);
63119+#endif
63120+
63121 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
63122 /* Optimization, do the COW without a second fault */
63123 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
63124@@ -2155,6 +2184,28 @@ int hugetlb_fault(struct mm_struct *mm,
63125 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
63126 struct hstate *h = hstate_vma(vma);
63127
63128+#ifdef CONFIG_PAX_SEGMEXEC
63129+ struct vm_area_struct *vma_m;
63130+
63131+ vma_m = pax_find_mirror_vma(vma);
63132+ if (vma_m) {
63133+ unsigned long address_m;
63134+
63135+ if (vma->vm_start > vma_m->vm_start) {
63136+ address_m = address;
63137+ address -= SEGMEXEC_TASK_SIZE;
63138+ vma = vma_m;
63139+ h = hstate_vma(vma);
63140+ } else
63141+ address_m = address + SEGMEXEC_TASK_SIZE;
63142+
63143+ if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
63144+ return VM_FAULT_OOM;
63145+ address_m &= HPAGE_MASK;
63146+ unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
63147+ }
63148+#endif
63149+
63150 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
63151 if (!ptep)
63152 return VM_FAULT_OOM;
63153diff -urNp linux-2.6.32.41/mm/Kconfig linux-2.6.32.41/mm/Kconfig
63154--- linux-2.6.32.41/mm/Kconfig 2011-03-27 14:31:47.000000000 -0400
63155+++ linux-2.6.32.41/mm/Kconfig 2011-04-17 15:56:46.000000000 -0400
63156@@ -228,7 +228,7 @@ config KSM
63157 config DEFAULT_MMAP_MIN_ADDR
63158 int "Low address space to protect from user allocation"
63159 depends on MMU
63160- default 4096
63161+ default 65536
63162 help
63163 This is the portion of low virtual memory which should be protected
63164 from userspace allocation. Keeping a user from writing to low pages
63165diff -urNp linux-2.6.32.41/mm/kmemleak.c linux-2.6.32.41/mm/kmemleak.c
63166--- linux-2.6.32.41/mm/kmemleak.c 2011-03-27 14:31:47.000000000 -0400
63167+++ linux-2.6.32.41/mm/kmemleak.c 2011-04-17 15:56:46.000000000 -0400
63168@@ -358,7 +358,7 @@ static void print_unreferenced(struct se
63169
63170 for (i = 0; i < object->trace_len; i++) {
63171 void *ptr = (void *)object->trace[i];
63172- seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
63173+ seq_printf(seq, " [<%p>] %pA\n", ptr, ptr);
63174 }
63175 }
63176
63177diff -urNp linux-2.6.32.41/mm/maccess.c linux-2.6.32.41/mm/maccess.c
63178--- linux-2.6.32.41/mm/maccess.c 2011-03-27 14:31:47.000000000 -0400
63179+++ linux-2.6.32.41/mm/maccess.c 2011-04-17 15:56:46.000000000 -0400
63180@@ -14,7 +14,7 @@
63181 * Safely read from address @src to the buffer at @dst. If a kernel fault
63182 * happens, handle that and return -EFAULT.
63183 */
63184-long probe_kernel_read(void *dst, void *src, size_t size)
63185+long probe_kernel_read(void *dst, const void *src, size_t size)
63186 {
63187 long ret;
63188 mm_segment_t old_fs = get_fs();
63189@@ -39,7 +39,7 @@ EXPORT_SYMBOL_GPL(probe_kernel_read);
63190 * Safely write to address @dst from the buffer at @src. If a kernel fault
63191 * happens, handle that and return -EFAULT.
63192 */
63193-long notrace __weak probe_kernel_write(void *dst, void *src, size_t size)
63194+long notrace __weak probe_kernel_write(void *dst, const void *src, size_t size)
63195 {
63196 long ret;
63197 mm_segment_t old_fs = get_fs();
63198diff -urNp linux-2.6.32.41/mm/madvise.c linux-2.6.32.41/mm/madvise.c
63199--- linux-2.6.32.41/mm/madvise.c 2011-03-27 14:31:47.000000000 -0400
63200+++ linux-2.6.32.41/mm/madvise.c 2011-04-17 15:56:46.000000000 -0400
63201@@ -44,6 +44,10 @@ static long madvise_behavior(struct vm_a
63202 pgoff_t pgoff;
63203 unsigned long new_flags = vma->vm_flags;
63204
63205+#ifdef CONFIG_PAX_SEGMEXEC
63206+ struct vm_area_struct *vma_m;
63207+#endif
63208+
63209 switch (behavior) {
63210 case MADV_NORMAL:
63211 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
63212@@ -103,6 +107,13 @@ success:
63213 /*
63214 * vm_flags is protected by the mmap_sem held in write mode.
63215 */
63216+
63217+#ifdef CONFIG_PAX_SEGMEXEC
63218+ vma_m = pax_find_mirror_vma(vma);
63219+ if (vma_m)
63220+ vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
63221+#endif
63222+
63223 vma->vm_flags = new_flags;
63224
63225 out:
63226@@ -161,6 +172,11 @@ static long madvise_dontneed(struct vm_a
63227 struct vm_area_struct ** prev,
63228 unsigned long start, unsigned long end)
63229 {
63230+
63231+#ifdef CONFIG_PAX_SEGMEXEC
63232+ struct vm_area_struct *vma_m;
63233+#endif
63234+
63235 *prev = vma;
63236 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
63237 return -EINVAL;
63238@@ -173,6 +189,21 @@ static long madvise_dontneed(struct vm_a
63239 zap_page_range(vma, start, end - start, &details);
63240 } else
63241 zap_page_range(vma, start, end - start, NULL);
63242+
63243+#ifdef CONFIG_PAX_SEGMEXEC
63244+ vma_m = pax_find_mirror_vma(vma);
63245+ if (vma_m) {
63246+ if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
63247+ struct zap_details details = {
63248+ .nonlinear_vma = vma_m,
63249+ .last_index = ULONG_MAX,
63250+ };
63251+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
63252+ } else
63253+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
63254+ }
63255+#endif
63256+
63257 return 0;
63258 }
63259
63260@@ -359,6 +390,16 @@ SYSCALL_DEFINE3(madvise, unsigned long,
63261 if (end < start)
63262 goto out;
63263
63264+#ifdef CONFIG_PAX_SEGMEXEC
63265+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
63266+ if (end > SEGMEXEC_TASK_SIZE)
63267+ goto out;
63268+ } else
63269+#endif
63270+
63271+ if (end > TASK_SIZE)
63272+ goto out;
63273+
63274 error = 0;
63275 if (end == start)
63276 goto out;
63277diff -urNp linux-2.6.32.41/mm/memory.c linux-2.6.32.41/mm/memory.c
63278--- linux-2.6.32.41/mm/memory.c 2011-03-27 14:31:47.000000000 -0400
63279+++ linux-2.6.32.41/mm/memory.c 2011-04-17 15:56:46.000000000 -0400
63280@@ -187,8 +187,12 @@ static inline void free_pmd_range(struct
63281 return;
63282
63283 pmd = pmd_offset(pud, start);
63284+
63285+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
63286 pud_clear(pud);
63287 pmd_free_tlb(tlb, pmd, start);
63288+#endif
63289+
63290 }
63291
63292 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
63293@@ -219,9 +223,12 @@ static inline void free_pud_range(struct
63294 if (end - 1 > ceiling - 1)
63295 return;
63296
63297+#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
63298 pud = pud_offset(pgd, start);
63299 pgd_clear(pgd);
63300 pud_free_tlb(tlb, pud, start);
63301+#endif
63302+
63303 }
63304
63305 /*
63306@@ -1251,10 +1258,10 @@ int __get_user_pages(struct task_struct
63307 (VM_MAYREAD | VM_MAYWRITE) : (VM_READ | VM_WRITE);
63308 i = 0;
63309
63310- do {
63311+ while (nr_pages) {
63312 struct vm_area_struct *vma;
63313
63314- vma = find_extend_vma(mm, start);
63315+ vma = find_vma(mm, start);
63316 if (!vma && in_gate_area(tsk, start)) {
63317 unsigned long pg = start & PAGE_MASK;
63318 struct vm_area_struct *gate_vma = get_gate_vma(tsk);
63319@@ -1306,7 +1313,7 @@ int __get_user_pages(struct task_struct
63320 continue;
63321 }
63322
63323- if (!vma ||
63324+ if (!vma || start < vma->vm_start ||
63325 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
63326 !(vm_flags & vma->vm_flags))
63327 return i ? : -EFAULT;
63328@@ -1381,7 +1388,7 @@ int __get_user_pages(struct task_struct
63329 start += PAGE_SIZE;
63330 nr_pages--;
63331 } while (nr_pages && start < vma->vm_end);
63332- } while (nr_pages);
63333+ }
63334 return i;
63335 }
63336
63337@@ -1526,6 +1533,10 @@ static int insert_page(struct vm_area_st
63338 page_add_file_rmap(page);
63339 set_pte_at(mm, addr, pte, mk_pte(page, prot));
63340
63341+#ifdef CONFIG_PAX_SEGMEXEC
63342+ pax_mirror_file_pte(vma, addr, page, ptl);
63343+#endif
63344+
63345 retval = 0;
63346 pte_unmap_unlock(pte, ptl);
63347 return retval;
63348@@ -1560,10 +1571,22 @@ out:
63349 int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
63350 struct page *page)
63351 {
63352+
63353+#ifdef CONFIG_PAX_SEGMEXEC
63354+ struct vm_area_struct *vma_m;
63355+#endif
63356+
63357 if (addr < vma->vm_start || addr >= vma->vm_end)
63358 return -EFAULT;
63359 if (!page_count(page))
63360 return -EINVAL;
63361+
63362+#ifdef CONFIG_PAX_SEGMEXEC
63363+ vma_m = pax_find_mirror_vma(vma);
63364+ if (vma_m)
63365+ vma_m->vm_flags |= VM_INSERTPAGE;
63366+#endif
63367+
63368 vma->vm_flags |= VM_INSERTPAGE;
63369 return insert_page(vma, addr, page, vma->vm_page_prot);
63370 }
63371@@ -1649,6 +1672,7 @@ int vm_insert_mixed(struct vm_area_struc
63372 unsigned long pfn)
63373 {
63374 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
63375+ BUG_ON(vma->vm_mirror);
63376
63377 if (addr < vma->vm_start || addr >= vma->vm_end)
63378 return -EFAULT;
63379@@ -1977,6 +2001,186 @@ static inline void cow_user_page(struct
63380 copy_user_highpage(dst, src, va, vma);
63381 }
63382
63383+#ifdef CONFIG_PAX_SEGMEXEC
63384+static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
63385+{
63386+ struct mm_struct *mm = vma->vm_mm;
63387+ spinlock_t *ptl;
63388+ pte_t *pte, entry;
63389+
63390+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
63391+ entry = *pte;
63392+ if (!pte_present(entry)) {
63393+ if (!pte_none(entry)) {
63394+ BUG_ON(pte_file(entry));
63395+ free_swap_and_cache(pte_to_swp_entry(entry));
63396+ pte_clear_not_present_full(mm, address, pte, 0);
63397+ }
63398+ } else {
63399+ struct page *page;
63400+
63401+ flush_cache_page(vma, address, pte_pfn(entry));
63402+ entry = ptep_clear_flush(vma, address, pte);
63403+ BUG_ON(pte_dirty(entry));
63404+ page = vm_normal_page(vma, address, entry);
63405+ if (page) {
63406+ update_hiwater_rss(mm);
63407+ if (PageAnon(page))
63408+ dec_mm_counter(mm, anon_rss);
63409+ else
63410+ dec_mm_counter(mm, file_rss);
63411+ page_remove_rmap(page);
63412+ page_cache_release(page);
63413+ }
63414+ }
63415+ pte_unmap_unlock(pte, ptl);
63416+}
63417+
63418+/* PaX: if vma is mirrored, synchronize the mirror's PTE
63419+ *
63420+ * the ptl of the lower mapped page is held on entry and is not released on exit
63421+ * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
63422+ */
63423+static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
63424+{
63425+ struct mm_struct *mm = vma->vm_mm;
63426+ unsigned long address_m;
63427+ spinlock_t *ptl_m;
63428+ struct vm_area_struct *vma_m;
63429+ pmd_t *pmd_m;
63430+ pte_t *pte_m, entry_m;
63431+
63432+ BUG_ON(!page_m || !PageAnon(page_m));
63433+
63434+ vma_m = pax_find_mirror_vma(vma);
63435+ if (!vma_m)
63436+ return;
63437+
63438+ BUG_ON(!PageLocked(page_m));
63439+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
63440+ address_m = address + SEGMEXEC_TASK_SIZE;
63441+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
63442+ pte_m = pte_offset_map_nested(pmd_m, address_m);
63443+ ptl_m = pte_lockptr(mm, pmd_m);
63444+ if (ptl != ptl_m) {
63445+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
63446+ if (!pte_none(*pte_m))
63447+ goto out;
63448+ }
63449+
63450+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
63451+ page_cache_get(page_m);
63452+ page_add_anon_rmap(page_m, vma_m, address_m);
63453+ inc_mm_counter(mm, anon_rss);
63454+ set_pte_at(mm, address_m, pte_m, entry_m);
63455+ update_mmu_cache(vma_m, address_m, entry_m);
63456+out:
63457+ if (ptl != ptl_m)
63458+ spin_unlock(ptl_m);
63459+ pte_unmap_nested(pte_m);
63460+ unlock_page(page_m);
63461+}
63462+
63463+void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
63464+{
63465+ struct mm_struct *mm = vma->vm_mm;
63466+ unsigned long address_m;
63467+ spinlock_t *ptl_m;
63468+ struct vm_area_struct *vma_m;
63469+ pmd_t *pmd_m;
63470+ pte_t *pte_m, entry_m;
63471+
63472+ BUG_ON(!page_m || PageAnon(page_m));
63473+
63474+ vma_m = pax_find_mirror_vma(vma);
63475+ if (!vma_m)
63476+ return;
63477+
63478+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
63479+ address_m = address + SEGMEXEC_TASK_SIZE;
63480+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
63481+ pte_m = pte_offset_map_nested(pmd_m, address_m);
63482+ ptl_m = pte_lockptr(mm, pmd_m);
63483+ if (ptl != ptl_m) {
63484+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
63485+ if (!pte_none(*pte_m))
63486+ goto out;
63487+ }
63488+
63489+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
63490+ page_cache_get(page_m);
63491+ page_add_file_rmap(page_m);
63492+ inc_mm_counter(mm, file_rss);
63493+ set_pte_at(mm, address_m, pte_m, entry_m);
63494+ update_mmu_cache(vma_m, address_m, entry_m);
63495+out:
63496+ if (ptl != ptl_m)
63497+ spin_unlock(ptl_m);
63498+ pte_unmap_nested(pte_m);
63499+}
63500+
63501+static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
63502+{
63503+ struct mm_struct *mm = vma->vm_mm;
63504+ unsigned long address_m;
63505+ spinlock_t *ptl_m;
63506+ struct vm_area_struct *vma_m;
63507+ pmd_t *pmd_m;
63508+ pte_t *pte_m, entry_m;
63509+
63510+ vma_m = pax_find_mirror_vma(vma);
63511+ if (!vma_m)
63512+ return;
63513+
63514+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
63515+ address_m = address + SEGMEXEC_TASK_SIZE;
63516+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
63517+ pte_m = pte_offset_map_nested(pmd_m, address_m);
63518+ ptl_m = pte_lockptr(mm, pmd_m);
63519+ if (ptl != ptl_m) {
63520+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
63521+ if (!pte_none(*pte_m))
63522+ goto out;
63523+ }
63524+
63525+ entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
63526+ set_pte_at(mm, address_m, pte_m, entry_m);
63527+out:
63528+ if (ptl != ptl_m)
63529+ spin_unlock(ptl_m);
63530+ pte_unmap_nested(pte_m);
63531+}
63532+
63533+static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
63534+{
63535+ struct page *page_m;
63536+ pte_t entry;
63537+
63538+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
63539+ goto out;
63540+
63541+ entry = *pte;
63542+ page_m = vm_normal_page(vma, address, entry);
63543+ if (!page_m)
63544+ pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
63545+ else if (PageAnon(page_m)) {
63546+ if (pax_find_mirror_vma(vma)) {
63547+ pte_unmap_unlock(pte, ptl);
63548+ lock_page(page_m);
63549+ pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
63550+ if (pte_same(entry, *pte))
63551+ pax_mirror_anon_pte(vma, address, page_m, ptl);
63552+ else
63553+ unlock_page(page_m);
63554+ }
63555+ } else
63556+ pax_mirror_file_pte(vma, address, page_m, ptl);
63557+
63558+out:
63559+ pte_unmap_unlock(pte, ptl);
63560+}
63561+#endif
63562+
63563 /*
63564 * This routine handles present pages, when users try to write
63565 * to a shared page. It is done by copying the page to a new address
63566@@ -2156,6 +2360,12 @@ gotten:
63567 */
63568 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
63569 if (likely(pte_same(*page_table, orig_pte))) {
63570+
63571+#ifdef CONFIG_PAX_SEGMEXEC
63572+ if (pax_find_mirror_vma(vma))
63573+ BUG_ON(!trylock_page(new_page));
63574+#endif
63575+
63576 if (old_page) {
63577 if (!PageAnon(old_page)) {
63578 dec_mm_counter(mm, file_rss);
63579@@ -2207,6 +2417,10 @@ gotten:
63580 page_remove_rmap(old_page);
63581 }
63582
63583+#ifdef CONFIG_PAX_SEGMEXEC
63584+ pax_mirror_anon_pte(vma, address, new_page, ptl);
63585+#endif
63586+
63587 /* Free the old page.. */
63588 new_page = old_page;
63589 ret |= VM_FAULT_WRITE;
63590@@ -2604,6 +2818,11 @@ static int do_swap_page(struct mm_struct
63591 swap_free(entry);
63592 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
63593 try_to_free_swap(page);
63594+
63595+#ifdef CONFIG_PAX_SEGMEXEC
63596+ if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
63597+#endif
63598+
63599 unlock_page(page);
63600
63601 if (flags & FAULT_FLAG_WRITE) {
63602@@ -2615,6 +2834,11 @@ static int do_swap_page(struct mm_struct
63603
63604 /* No need to invalidate - it was non-present before */
63605 update_mmu_cache(vma, address, pte);
63606+
63607+#ifdef CONFIG_PAX_SEGMEXEC
63608+ pax_mirror_anon_pte(vma, address, page, ptl);
63609+#endif
63610+
63611 unlock:
63612 pte_unmap_unlock(page_table, ptl);
63613 out:
63614@@ -2630,40 +2854,6 @@ out_release:
63615 }
63616
63617 /*
63618- * This is like a special single-page "expand_{down|up}wards()",
63619- * except we must first make sure that 'address{-|+}PAGE_SIZE'
63620- * doesn't hit another vma.
63621- */
63622-static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
63623-{
63624- address &= PAGE_MASK;
63625- if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
63626- struct vm_area_struct *prev = vma->vm_prev;
63627-
63628- /*
63629- * Is there a mapping abutting this one below?
63630- *
63631- * That's only ok if it's the same stack mapping
63632- * that has gotten split..
63633- */
63634- if (prev && prev->vm_end == address)
63635- return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
63636-
63637- expand_stack(vma, address - PAGE_SIZE);
63638- }
63639- if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
63640- struct vm_area_struct *next = vma->vm_next;
63641-
63642- /* As VM_GROWSDOWN but s/below/above/ */
63643- if (next && next->vm_start == address + PAGE_SIZE)
63644- return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
63645-
63646- expand_upwards(vma, address + PAGE_SIZE);
63647- }
63648- return 0;
63649-}
63650-
63651-/*
63652 * We enter with non-exclusive mmap_sem (to exclude vma changes,
63653 * but allow concurrent faults), and pte mapped but not yet locked.
63654 * We return with mmap_sem still held, but pte unmapped and unlocked.
63655@@ -2672,27 +2862,23 @@ static int do_anonymous_page(struct mm_s
63656 unsigned long address, pte_t *page_table, pmd_t *pmd,
63657 unsigned int flags)
63658 {
63659- struct page *page;
63660+ struct page *page = NULL;
63661 spinlock_t *ptl;
63662 pte_t entry;
63663
63664- pte_unmap(page_table);
63665-
63666- /* Check if we need to add a guard page to the stack */
63667- if (check_stack_guard_page(vma, address) < 0)
63668- return VM_FAULT_SIGBUS;
63669-
63670- /* Use the zero-page for reads */
63671 if (!(flags & FAULT_FLAG_WRITE)) {
63672 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
63673 vma->vm_page_prot));
63674- page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
63675+ ptl = pte_lockptr(mm, pmd);
63676+ spin_lock(ptl);
63677 if (!pte_none(*page_table))
63678 goto unlock;
63679 goto setpte;
63680 }
63681
63682 /* Allocate our own private page. */
63683+ pte_unmap(page_table);
63684+
63685 if (unlikely(anon_vma_prepare(vma)))
63686 goto oom;
63687 page = alloc_zeroed_user_highpage_movable(vma, address);
63688@@ -2711,6 +2897,11 @@ static int do_anonymous_page(struct mm_s
63689 if (!pte_none(*page_table))
63690 goto release;
63691
63692+#ifdef CONFIG_PAX_SEGMEXEC
63693+ if (pax_find_mirror_vma(vma))
63694+ BUG_ON(!trylock_page(page));
63695+#endif
63696+
63697 inc_mm_counter(mm, anon_rss);
63698 page_add_new_anon_rmap(page, vma, address);
63699 setpte:
63700@@ -2718,6 +2909,12 @@ setpte:
63701
63702 /* No need to invalidate - it was non-present before */
63703 update_mmu_cache(vma, address, entry);
63704+
63705+#ifdef CONFIG_PAX_SEGMEXEC
63706+ if (page)
63707+ pax_mirror_anon_pte(vma, address, page, ptl);
63708+#endif
63709+
63710 unlock:
63711 pte_unmap_unlock(page_table, ptl);
63712 return 0;
63713@@ -2860,6 +3057,12 @@ static int __do_fault(struct mm_struct *
63714 */
63715 /* Only go through if we didn't race with anybody else... */
63716 if (likely(pte_same(*page_table, orig_pte))) {
63717+
63718+#ifdef CONFIG_PAX_SEGMEXEC
63719+ if (anon && pax_find_mirror_vma(vma))
63720+ BUG_ON(!trylock_page(page));
63721+#endif
63722+
63723 flush_icache_page(vma, page);
63724 entry = mk_pte(page, vma->vm_page_prot);
63725 if (flags & FAULT_FLAG_WRITE)
63726@@ -2879,6 +3082,14 @@ static int __do_fault(struct mm_struct *
63727
63728 /* no need to invalidate: a not-present page won't be cached */
63729 update_mmu_cache(vma, address, entry);
63730+
63731+#ifdef CONFIG_PAX_SEGMEXEC
63732+ if (anon)
63733+ pax_mirror_anon_pte(vma, address, page, ptl);
63734+ else
63735+ pax_mirror_file_pte(vma, address, page, ptl);
63736+#endif
63737+
63738 } else {
63739 if (charged)
63740 mem_cgroup_uncharge_page(page);
63741@@ -3026,6 +3237,12 @@ static inline int handle_pte_fault(struc
63742 if (flags & FAULT_FLAG_WRITE)
63743 flush_tlb_page(vma, address);
63744 }
63745+
63746+#ifdef CONFIG_PAX_SEGMEXEC
63747+ pax_mirror_pte(vma, address, pte, pmd, ptl);
63748+ return 0;
63749+#endif
63750+
63751 unlock:
63752 pte_unmap_unlock(pte, ptl);
63753 return 0;
63754@@ -3042,6 +3259,10 @@ int handle_mm_fault(struct mm_struct *mm
63755 pmd_t *pmd;
63756 pte_t *pte;
63757
63758+#ifdef CONFIG_PAX_SEGMEXEC
63759+ struct vm_area_struct *vma_m;
63760+#endif
63761+
63762 __set_current_state(TASK_RUNNING);
63763
63764 count_vm_event(PGFAULT);
63765@@ -3049,6 +3270,34 @@ int handle_mm_fault(struct mm_struct *mm
63766 if (unlikely(is_vm_hugetlb_page(vma)))
63767 return hugetlb_fault(mm, vma, address, flags);
63768
63769+#ifdef CONFIG_PAX_SEGMEXEC
63770+ vma_m = pax_find_mirror_vma(vma);
63771+ if (vma_m) {
63772+ unsigned long address_m;
63773+ pgd_t *pgd_m;
63774+ pud_t *pud_m;
63775+ pmd_t *pmd_m;
63776+
63777+ if (vma->vm_start > vma_m->vm_start) {
63778+ address_m = address;
63779+ address -= SEGMEXEC_TASK_SIZE;
63780+ vma = vma_m;
63781+ } else
63782+ address_m = address + SEGMEXEC_TASK_SIZE;
63783+
63784+ pgd_m = pgd_offset(mm, address_m);
63785+ pud_m = pud_alloc(mm, pgd_m, address_m);
63786+ if (!pud_m)
63787+ return VM_FAULT_OOM;
63788+ pmd_m = pmd_alloc(mm, pud_m, address_m);
63789+ if (!pmd_m)
63790+ return VM_FAULT_OOM;
63791+ if (!pmd_present(*pmd_m) && __pte_alloc(mm, pmd_m, address_m))
63792+ return VM_FAULT_OOM;
63793+ pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
63794+ }
63795+#endif
63796+
63797 pgd = pgd_offset(mm, address);
63798 pud = pud_alloc(mm, pgd, address);
63799 if (!pud)
63800@@ -3146,7 +3395,7 @@ static int __init gate_vma_init(void)
63801 gate_vma.vm_start = FIXADDR_USER_START;
63802 gate_vma.vm_end = FIXADDR_USER_END;
63803 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
63804- gate_vma.vm_page_prot = __P101;
63805+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
63806 /*
63807 * Make sure the vDSO gets into every core dump.
63808 * Dumping its contents makes post-mortem fully interpretable later
63809diff -urNp linux-2.6.32.41/mm/memory-failure.c linux-2.6.32.41/mm/memory-failure.c
63810--- linux-2.6.32.41/mm/memory-failure.c 2011-03-27 14:31:47.000000000 -0400
63811+++ linux-2.6.32.41/mm/memory-failure.c 2011-04-17 15:56:46.000000000 -0400
63812@@ -46,7 +46,7 @@ int sysctl_memory_failure_early_kill __r
63813
63814 int sysctl_memory_failure_recovery __read_mostly = 1;
63815
63816-atomic_long_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
63817+atomic_long_unchecked_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
63818
63819 /*
63820 * Send all the processes who have the page mapped an ``action optional''
63821@@ -745,7 +745,7 @@ int __memory_failure(unsigned long pfn,
63822 return 0;
63823 }
63824
63825- atomic_long_add(1, &mce_bad_pages);
63826+ atomic_long_add_unchecked(1, &mce_bad_pages);
63827
63828 /*
63829 * We need/can do nothing about count=0 pages.
63830diff -urNp linux-2.6.32.41/mm/mempolicy.c linux-2.6.32.41/mm/mempolicy.c
63831--- linux-2.6.32.41/mm/mempolicy.c 2011-03-27 14:31:47.000000000 -0400
63832+++ linux-2.6.32.41/mm/mempolicy.c 2011-04-17 15:56:46.000000000 -0400
63833@@ -573,6 +573,10 @@ static int mbind_range(struct vm_area_st
63834 struct vm_area_struct *next;
63835 int err;
63836
63837+#ifdef CONFIG_PAX_SEGMEXEC
63838+ struct vm_area_struct *vma_m;
63839+#endif
63840+
63841 err = 0;
63842 for (; vma && vma->vm_start < end; vma = next) {
63843 next = vma->vm_next;
63844@@ -584,6 +588,16 @@ static int mbind_range(struct vm_area_st
63845 err = policy_vma(vma, new);
63846 if (err)
63847 break;
63848+
63849+#ifdef CONFIG_PAX_SEGMEXEC
63850+ vma_m = pax_find_mirror_vma(vma);
63851+ if (vma_m) {
63852+ err = policy_vma(vma_m, new);
63853+ if (err)
63854+ break;
63855+ }
63856+#endif
63857+
63858 }
63859 return err;
63860 }
63861@@ -1002,6 +1016,17 @@ static long do_mbind(unsigned long start
63862
63863 if (end < start)
63864 return -EINVAL;
63865+
63866+#ifdef CONFIG_PAX_SEGMEXEC
63867+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
63868+ if (end > SEGMEXEC_TASK_SIZE)
63869+ return -EINVAL;
63870+ } else
63871+#endif
63872+
63873+ if (end > TASK_SIZE)
63874+ return -EINVAL;
63875+
63876 if (end == start)
63877 return 0;
63878
63879@@ -1207,6 +1232,14 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pi
63880 if (!mm)
63881 return -EINVAL;
63882
63883+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63884+ if (mm != current->mm &&
63885+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
63886+ err = -EPERM;
63887+ goto out;
63888+ }
63889+#endif
63890+
63891 /*
63892 * Check if this process has the right to modify the specified
63893 * process. The right exists if the process has administrative
63894@@ -1216,8 +1249,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pi
63895 rcu_read_lock();
63896 tcred = __task_cred(task);
63897 if (cred->euid != tcred->suid && cred->euid != tcred->uid &&
63898- cred->uid != tcred->suid && cred->uid != tcred->uid &&
63899- !capable(CAP_SYS_NICE)) {
63900+ cred->uid != tcred->suid && !capable(CAP_SYS_NICE)) {
63901 rcu_read_unlock();
63902 err = -EPERM;
63903 goto out;
63904@@ -2396,7 +2428,7 @@ int show_numa_map(struct seq_file *m, vo
63905
63906 if (file) {
63907 seq_printf(m, " file=");
63908- seq_path(m, &file->f_path, "\n\t= ");
63909+ seq_path(m, &file->f_path, "\n\t\\= ");
63910 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
63911 seq_printf(m, " heap");
63912 } else if (vma->vm_start <= mm->start_stack &&
63913diff -urNp linux-2.6.32.41/mm/migrate.c linux-2.6.32.41/mm/migrate.c
63914--- linux-2.6.32.41/mm/migrate.c 2011-03-27 14:31:47.000000000 -0400
63915+++ linux-2.6.32.41/mm/migrate.c 2011-05-16 21:46:57.000000000 -0400
63916@@ -916,6 +916,8 @@ static int do_pages_move(struct mm_struc
63917 unsigned long chunk_start;
63918 int err;
63919
63920+ pax_track_stack();
63921+
63922 task_nodes = cpuset_mems_allowed(task);
63923
63924 err = -ENOMEM;
63925@@ -1106,6 +1108,14 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid,
63926 if (!mm)
63927 return -EINVAL;
63928
63929+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63930+ if (mm != current->mm &&
63931+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
63932+ err = -EPERM;
63933+ goto out;
63934+ }
63935+#endif
63936+
63937 /*
63938 * Check if this process has the right to modify the specified
63939 * process. The right exists if the process has administrative
63940@@ -1115,8 +1125,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid,
63941 rcu_read_lock();
63942 tcred = __task_cred(task);
63943 if (cred->euid != tcred->suid && cred->euid != tcred->uid &&
63944- cred->uid != tcred->suid && cred->uid != tcred->uid &&
63945- !capable(CAP_SYS_NICE)) {
63946+ cred->uid != tcred->suid && !capable(CAP_SYS_NICE)) {
63947 rcu_read_unlock();
63948 err = -EPERM;
63949 goto out;
63950diff -urNp linux-2.6.32.41/mm/mlock.c linux-2.6.32.41/mm/mlock.c
63951--- linux-2.6.32.41/mm/mlock.c 2011-03-27 14:31:47.000000000 -0400
63952+++ linux-2.6.32.41/mm/mlock.c 2011-04-17 15:56:46.000000000 -0400
63953@@ -13,6 +13,7 @@
63954 #include <linux/pagemap.h>
63955 #include <linux/mempolicy.h>
63956 #include <linux/syscalls.h>
63957+#include <linux/security.h>
63958 #include <linux/sched.h>
63959 #include <linux/module.h>
63960 #include <linux/rmap.h>
63961@@ -138,13 +139,6 @@ void munlock_vma_page(struct page *page)
63962 }
63963 }
63964
63965-static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
63966-{
63967- return (vma->vm_flags & VM_GROWSDOWN) &&
63968- (vma->vm_start == addr) &&
63969- !vma_stack_continue(vma->vm_prev, addr);
63970-}
63971-
63972 /**
63973 * __mlock_vma_pages_range() - mlock a range of pages in the vma.
63974 * @vma: target vma
63975@@ -177,12 +171,6 @@ static long __mlock_vma_pages_range(stru
63976 if (vma->vm_flags & VM_WRITE)
63977 gup_flags |= FOLL_WRITE;
63978
63979- /* We don't try to access the guard page of a stack vma */
63980- if (stack_guard_page(vma, start)) {
63981- addr += PAGE_SIZE;
63982- nr_pages--;
63983- }
63984-
63985 while (nr_pages > 0) {
63986 int i;
63987
63988@@ -440,7 +428,7 @@ static int do_mlock(unsigned long start,
63989 {
63990 unsigned long nstart, end, tmp;
63991 struct vm_area_struct * vma, * prev;
63992- int error;
63993+ int error = -EINVAL;
63994
63995 len = PAGE_ALIGN(len);
63996 end = start + len;
63997@@ -448,6 +436,9 @@ static int do_mlock(unsigned long start,
63998 return -EINVAL;
63999 if (end == start)
64000 return 0;
64001+ if (end > TASK_SIZE)
64002+ return -EINVAL;
64003+
64004 vma = find_vma_prev(current->mm, start, &prev);
64005 if (!vma || vma->vm_start > start)
64006 return -ENOMEM;
64007@@ -458,6 +449,11 @@ static int do_mlock(unsigned long start,
64008 for (nstart = start ; ; ) {
64009 unsigned int newflags;
64010
64011+#ifdef CONFIG_PAX_SEGMEXEC
64012+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
64013+ break;
64014+#endif
64015+
64016 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
64017
64018 newflags = vma->vm_flags | VM_LOCKED;
64019@@ -507,6 +503,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, st
64020 lock_limit >>= PAGE_SHIFT;
64021
64022 /* check against resource limits */
64023+ gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
64024 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
64025 error = do_mlock(start, len, 1);
64026 up_write(&current->mm->mmap_sem);
64027@@ -528,17 +525,23 @@ SYSCALL_DEFINE2(munlock, unsigned long,
64028 static int do_mlockall(int flags)
64029 {
64030 struct vm_area_struct * vma, * prev = NULL;
64031- unsigned int def_flags = 0;
64032
64033 if (flags & MCL_FUTURE)
64034- def_flags = VM_LOCKED;
64035- current->mm->def_flags = def_flags;
64036+ current->mm->def_flags |= VM_LOCKED;
64037+ else
64038+ current->mm->def_flags &= ~VM_LOCKED;
64039 if (flags == MCL_FUTURE)
64040 goto out;
64041
64042 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
64043- unsigned int newflags;
64044+ unsigned long newflags;
64045+
64046+#ifdef CONFIG_PAX_SEGMEXEC
64047+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
64048+ break;
64049+#endif
64050
64051+ BUG_ON(vma->vm_end > TASK_SIZE);
64052 newflags = vma->vm_flags | VM_LOCKED;
64053 if (!(flags & MCL_CURRENT))
64054 newflags &= ~VM_LOCKED;
64055@@ -570,6 +573,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
64056 lock_limit >>= PAGE_SHIFT;
64057
64058 ret = -ENOMEM;
64059+ gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
64060 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
64061 capable(CAP_IPC_LOCK))
64062 ret = do_mlockall(flags);
64063diff -urNp linux-2.6.32.41/mm/mmap.c linux-2.6.32.41/mm/mmap.c
64064--- linux-2.6.32.41/mm/mmap.c 2011-03-27 14:31:47.000000000 -0400
64065+++ linux-2.6.32.41/mm/mmap.c 2011-04-17 15:56:46.000000000 -0400
64066@@ -45,6 +45,16 @@
64067 #define arch_rebalance_pgtables(addr, len) (addr)
64068 #endif
64069
64070+static inline void verify_mm_writelocked(struct mm_struct *mm)
64071+{
64072+#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
64073+ if (unlikely(down_read_trylock(&mm->mmap_sem))) {
64074+ up_read(&mm->mmap_sem);
64075+ BUG();
64076+ }
64077+#endif
64078+}
64079+
64080 static void unmap_region(struct mm_struct *mm,
64081 struct vm_area_struct *vma, struct vm_area_struct *prev,
64082 unsigned long start, unsigned long end);
64083@@ -70,22 +80,32 @@ static void unmap_region(struct mm_struc
64084 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
64085 *
64086 */
64087-pgprot_t protection_map[16] = {
64088+pgprot_t protection_map[16] __read_only = {
64089 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
64090 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
64091 };
64092
64093 pgprot_t vm_get_page_prot(unsigned long vm_flags)
64094 {
64095- return __pgprot(pgprot_val(protection_map[vm_flags &
64096+ pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
64097 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
64098 pgprot_val(arch_vm_get_page_prot(vm_flags)));
64099+
64100+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
64101+ if (!nx_enabled &&
64102+ (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
64103+ (vm_flags & (VM_READ | VM_WRITE)))
64104+ prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
64105+#endif
64106+
64107+ return prot;
64108 }
64109 EXPORT_SYMBOL(vm_get_page_prot);
64110
64111 int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
64112 int sysctl_overcommit_ratio = 50; /* default is 50% */
64113 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
64114+unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
64115 struct percpu_counter vm_committed_as;
64116
64117 /*
64118@@ -231,6 +251,7 @@ static struct vm_area_struct *remove_vma
64119 struct vm_area_struct *next = vma->vm_next;
64120
64121 might_sleep();
64122+ BUG_ON(vma->vm_mirror);
64123 if (vma->vm_ops && vma->vm_ops->close)
64124 vma->vm_ops->close(vma);
64125 if (vma->vm_file) {
64126@@ -267,6 +288,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
64127 * not page aligned -Ram Gupta
64128 */
64129 rlim = current->signal->rlim[RLIMIT_DATA].rlim_cur;
64130+ gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
64131 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
64132 (mm->end_data - mm->start_data) > rlim)
64133 goto out;
64134@@ -704,6 +726,12 @@ static int
64135 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
64136 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
64137 {
64138+
64139+#ifdef CONFIG_PAX_SEGMEXEC
64140+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
64141+ return 0;
64142+#endif
64143+
64144 if (is_mergeable_vma(vma, file, vm_flags) &&
64145 is_mergeable_anon_vma(anon_vma, vma->anon_vma)) {
64146 if (vma->vm_pgoff == vm_pgoff)
64147@@ -723,6 +751,12 @@ static int
64148 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
64149 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
64150 {
64151+
64152+#ifdef CONFIG_PAX_SEGMEXEC
64153+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
64154+ return 0;
64155+#endif
64156+
64157 if (is_mergeable_vma(vma, file, vm_flags) &&
64158 is_mergeable_anon_vma(anon_vma, vma->anon_vma)) {
64159 pgoff_t vm_pglen;
64160@@ -765,12 +799,19 @@ can_vma_merge_after(struct vm_area_struc
64161 struct vm_area_struct *vma_merge(struct mm_struct *mm,
64162 struct vm_area_struct *prev, unsigned long addr,
64163 unsigned long end, unsigned long vm_flags,
64164- struct anon_vma *anon_vma, struct file *file,
64165+ struct anon_vma *anon_vma, struct file *file,
64166 pgoff_t pgoff, struct mempolicy *policy)
64167 {
64168 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
64169 struct vm_area_struct *area, *next;
64170
64171+#ifdef CONFIG_PAX_SEGMEXEC
64172+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
64173+ struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
64174+
64175+ BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
64176+#endif
64177+
64178 /*
64179 * We later require that vma->vm_flags == vm_flags,
64180 * so this tests vma->vm_flags & VM_SPECIAL, too.
64181@@ -786,6 +827,15 @@ struct vm_area_struct *vma_merge(struct
64182 if (next && next->vm_end == end) /* cases 6, 7, 8 */
64183 next = next->vm_next;
64184
64185+#ifdef CONFIG_PAX_SEGMEXEC
64186+ if (prev)
64187+ prev_m = pax_find_mirror_vma(prev);
64188+ if (area)
64189+ area_m = pax_find_mirror_vma(area);
64190+ if (next)
64191+ next_m = pax_find_mirror_vma(next);
64192+#endif
64193+
64194 /*
64195 * Can it merge with the predecessor?
64196 */
64197@@ -805,9 +855,24 @@ struct vm_area_struct *vma_merge(struct
64198 /* cases 1, 6 */
64199 vma_adjust(prev, prev->vm_start,
64200 next->vm_end, prev->vm_pgoff, NULL);
64201- } else /* cases 2, 5, 7 */
64202+
64203+#ifdef CONFIG_PAX_SEGMEXEC
64204+ if (prev_m)
64205+ vma_adjust(prev_m, prev_m->vm_start,
64206+ next_m->vm_end, prev_m->vm_pgoff, NULL);
64207+#endif
64208+
64209+ } else { /* cases 2, 5, 7 */
64210 vma_adjust(prev, prev->vm_start,
64211 end, prev->vm_pgoff, NULL);
64212+
64213+#ifdef CONFIG_PAX_SEGMEXEC
64214+ if (prev_m)
64215+ vma_adjust(prev_m, prev_m->vm_start,
64216+ end_m, prev_m->vm_pgoff, NULL);
64217+#endif
64218+
64219+ }
64220 return prev;
64221 }
64222
64223@@ -818,12 +883,27 @@ struct vm_area_struct *vma_merge(struct
64224 mpol_equal(policy, vma_policy(next)) &&
64225 can_vma_merge_before(next, vm_flags,
64226 anon_vma, file, pgoff+pglen)) {
64227- if (prev && addr < prev->vm_end) /* case 4 */
64228+ if (prev && addr < prev->vm_end) { /* case 4 */
64229 vma_adjust(prev, prev->vm_start,
64230 addr, prev->vm_pgoff, NULL);
64231- else /* cases 3, 8 */
64232+
64233+#ifdef CONFIG_PAX_SEGMEXEC
64234+ if (prev_m)
64235+ vma_adjust(prev_m, prev_m->vm_start,
64236+ addr_m, prev_m->vm_pgoff, NULL);
64237+#endif
64238+
64239+ } else { /* cases 3, 8 */
64240 vma_adjust(area, addr, next->vm_end,
64241 next->vm_pgoff - pglen, NULL);
64242+
64243+#ifdef CONFIG_PAX_SEGMEXEC
64244+ if (area_m)
64245+ vma_adjust(area_m, addr_m, next_m->vm_end,
64246+ next_m->vm_pgoff - pglen, NULL);
64247+#endif
64248+
64249+ }
64250 return area;
64251 }
64252
64253@@ -898,14 +978,11 @@ none:
64254 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
64255 struct file *file, long pages)
64256 {
64257- const unsigned long stack_flags
64258- = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
64259-
64260 if (file) {
64261 mm->shared_vm += pages;
64262 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
64263 mm->exec_vm += pages;
64264- } else if (flags & stack_flags)
64265+ } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
64266 mm->stack_vm += pages;
64267 if (flags & (VM_RESERVED|VM_IO))
64268 mm->reserved_vm += pages;
64269@@ -932,7 +1009,7 @@ unsigned long do_mmap_pgoff(struct file
64270 * (the exception is when the underlying filesystem is noexec
64271 * mounted, in which case we dont add PROT_EXEC.)
64272 */
64273- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
64274+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
64275 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
64276 prot |= PROT_EXEC;
64277
64278@@ -958,7 +1035,7 @@ unsigned long do_mmap_pgoff(struct file
64279 /* Obtain the address to map to. we verify (or select) it and ensure
64280 * that it represents a valid section of the address space.
64281 */
64282- addr = get_unmapped_area(file, addr, len, pgoff, flags);
64283+ addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
64284 if (addr & ~PAGE_MASK)
64285 return addr;
64286
64287@@ -969,6 +1046,36 @@ unsigned long do_mmap_pgoff(struct file
64288 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
64289 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
64290
64291+#ifdef CONFIG_PAX_MPROTECT
64292+ if (mm->pax_flags & MF_PAX_MPROTECT) {
64293+#ifndef CONFIG_PAX_MPROTECT_COMPAT
64294+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
64295+ gr_log_rwxmmap(file);
64296+
64297+#ifdef CONFIG_PAX_EMUPLT
64298+ vm_flags &= ~VM_EXEC;
64299+#else
64300+ return -EPERM;
64301+#endif
64302+
64303+ }
64304+
64305+ if (!(vm_flags & VM_EXEC))
64306+ vm_flags &= ~VM_MAYEXEC;
64307+#else
64308+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
64309+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
64310+#endif
64311+ else
64312+ vm_flags &= ~VM_MAYWRITE;
64313+ }
64314+#endif
64315+
64316+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
64317+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
64318+ vm_flags &= ~VM_PAGEEXEC;
64319+#endif
64320+
64321 if (flags & MAP_LOCKED)
64322 if (!can_do_mlock())
64323 return -EPERM;
64324@@ -980,6 +1087,7 @@ unsigned long do_mmap_pgoff(struct file
64325 locked += mm->locked_vm;
64326 lock_limit = current->signal->rlim[RLIMIT_MEMLOCK].rlim_cur;
64327 lock_limit >>= PAGE_SHIFT;
64328+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
64329 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
64330 return -EAGAIN;
64331 }
64332@@ -1053,6 +1161,9 @@ unsigned long do_mmap_pgoff(struct file
64333 if (error)
64334 return error;
64335
64336+ if (!gr_acl_handle_mmap(file, prot))
64337+ return -EACCES;
64338+
64339 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
64340 }
64341 EXPORT_SYMBOL(do_mmap_pgoff);
64342@@ -1065,10 +1176,10 @@ EXPORT_SYMBOL(do_mmap_pgoff);
64343 */
64344 int vma_wants_writenotify(struct vm_area_struct *vma)
64345 {
64346- unsigned int vm_flags = vma->vm_flags;
64347+ unsigned long vm_flags = vma->vm_flags;
64348
64349 /* If it was private or non-writable, the write bit is already clear */
64350- if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
64351+ if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
64352 return 0;
64353
64354 /* The backer wishes to know when pages are first written to? */
64355@@ -1117,14 +1228,24 @@ unsigned long mmap_region(struct file *f
64356 unsigned long charged = 0;
64357 struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
64358
64359+#ifdef CONFIG_PAX_SEGMEXEC
64360+ struct vm_area_struct *vma_m = NULL;
64361+#endif
64362+
64363+ /*
64364+ * mm->mmap_sem is required to protect against another thread
64365+ * changing the mappings in case we sleep.
64366+ */
64367+ verify_mm_writelocked(mm);
64368+
64369 /* Clear old maps */
64370 error = -ENOMEM;
64371-munmap_back:
64372 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
64373 if (vma && vma->vm_start < addr + len) {
64374 if (do_munmap(mm, addr, len))
64375 return -ENOMEM;
64376- goto munmap_back;
64377+ vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
64378+ BUG_ON(vma && vma->vm_start < addr + len);
64379 }
64380
64381 /* Check against address space limit. */
64382@@ -1173,6 +1294,16 @@ munmap_back:
64383 goto unacct_error;
64384 }
64385
64386+#ifdef CONFIG_PAX_SEGMEXEC
64387+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
64388+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
64389+ if (!vma_m) {
64390+ error = -ENOMEM;
64391+ goto free_vma;
64392+ }
64393+ }
64394+#endif
64395+
64396 vma->vm_mm = mm;
64397 vma->vm_start = addr;
64398 vma->vm_end = addr + len;
64399@@ -1195,6 +1326,19 @@ munmap_back:
64400 error = file->f_op->mmap(file, vma);
64401 if (error)
64402 goto unmap_and_free_vma;
64403+
64404+#ifdef CONFIG_PAX_SEGMEXEC
64405+ if (vma_m && (vm_flags & VM_EXECUTABLE))
64406+ added_exe_file_vma(mm);
64407+#endif
64408+
64409+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
64410+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
64411+ vma->vm_flags |= VM_PAGEEXEC;
64412+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
64413+ }
64414+#endif
64415+
64416 if (vm_flags & VM_EXECUTABLE)
64417 added_exe_file_vma(mm);
64418
64419@@ -1218,6 +1362,11 @@ munmap_back:
64420 vma_link(mm, vma, prev, rb_link, rb_parent);
64421 file = vma->vm_file;
64422
64423+#ifdef CONFIG_PAX_SEGMEXEC
64424+ if (vma_m)
64425+ pax_mirror_vma(vma_m, vma);
64426+#endif
64427+
64428 /* Once vma denies write, undo our temporary denial count */
64429 if (correct_wcount)
64430 atomic_inc(&inode->i_writecount);
64431@@ -1226,6 +1375,7 @@ out:
64432
64433 mm->total_vm += len >> PAGE_SHIFT;
64434 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
64435+ track_exec_limit(mm, addr, addr + len, vm_flags);
64436 if (vm_flags & VM_LOCKED) {
64437 /*
64438 * makes pages present; downgrades, drops, reacquires mmap_sem
64439@@ -1248,6 +1398,12 @@ unmap_and_free_vma:
64440 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
64441 charged = 0;
64442 free_vma:
64443+
64444+#ifdef CONFIG_PAX_SEGMEXEC
64445+ if (vma_m)
64446+ kmem_cache_free(vm_area_cachep, vma_m);
64447+#endif
64448+
64449 kmem_cache_free(vm_area_cachep, vma);
64450 unacct_error:
64451 if (charged)
64452@@ -1255,6 +1411,44 @@ unacct_error:
64453 return error;
64454 }
64455
64456+bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len)
64457+{
64458+ if (!vma) {
64459+#ifdef CONFIG_STACK_GROWSUP
64460+ if (addr > sysctl_heap_stack_gap)
64461+ vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
64462+ else
64463+ vma = find_vma(current->mm, 0);
64464+ if (vma && (vma->vm_flags & VM_GROWSUP))
64465+ return false;
64466+#endif
64467+ return true;
64468+ }
64469+
64470+ if (addr + len > vma->vm_start)
64471+ return false;
64472+
64473+ if (vma->vm_flags & VM_GROWSDOWN)
64474+ return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
64475+#ifdef CONFIG_STACK_GROWSUP
64476+ else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
64477+ return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
64478+#endif
64479+
64480+ return true;
64481+}
64482+
64483+unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len)
64484+{
64485+ if (vma->vm_start < len)
64486+ return -ENOMEM;
64487+ if (!(vma->vm_flags & VM_GROWSDOWN))
64488+ return vma->vm_start - len;
64489+ if (sysctl_heap_stack_gap <= vma->vm_start - len)
64490+ return vma->vm_start - len - sysctl_heap_stack_gap;
64491+ return -ENOMEM;
64492+}
64493+
64494 /* Get an address range which is currently unmapped.
64495 * For shmat() with addr=0.
64496 *
64497@@ -1281,18 +1475,23 @@ arch_get_unmapped_area(struct file *filp
64498 if (flags & MAP_FIXED)
64499 return addr;
64500
64501+#ifdef CONFIG_PAX_RANDMMAP
64502+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
64503+#endif
64504+
64505 if (addr) {
64506 addr = PAGE_ALIGN(addr);
64507- vma = find_vma(mm, addr);
64508- if (TASK_SIZE - len >= addr &&
64509- (!vma || addr + len <= vma->vm_start))
64510- return addr;
64511+ if (TASK_SIZE - len >= addr) {
64512+ vma = find_vma(mm, addr);
64513+ if (check_heap_stack_gap(vma, addr, len))
64514+ return addr;
64515+ }
64516 }
64517 if (len > mm->cached_hole_size) {
64518- start_addr = addr = mm->free_area_cache;
64519+ start_addr = addr = mm->free_area_cache;
64520 } else {
64521- start_addr = addr = TASK_UNMAPPED_BASE;
64522- mm->cached_hole_size = 0;
64523+ start_addr = addr = mm->mmap_base;
64524+ mm->cached_hole_size = 0;
64525 }
64526
64527 full_search:
64528@@ -1303,34 +1502,40 @@ full_search:
64529 * Start a new search - just in case we missed
64530 * some holes.
64531 */
64532- if (start_addr != TASK_UNMAPPED_BASE) {
64533- addr = TASK_UNMAPPED_BASE;
64534- start_addr = addr;
64535+ if (start_addr != mm->mmap_base) {
64536+ start_addr = addr = mm->mmap_base;
64537 mm->cached_hole_size = 0;
64538 goto full_search;
64539 }
64540 return -ENOMEM;
64541 }
64542- if (!vma || addr + len <= vma->vm_start) {
64543- /*
64544- * Remember the place where we stopped the search:
64545- */
64546- mm->free_area_cache = addr + len;
64547- return addr;
64548- }
64549+ if (check_heap_stack_gap(vma, addr, len))
64550+ break;
64551 if (addr + mm->cached_hole_size < vma->vm_start)
64552 mm->cached_hole_size = vma->vm_start - addr;
64553 addr = vma->vm_end;
64554 }
64555+
64556+ /*
64557+ * Remember the place where we stopped the search:
64558+ */
64559+ mm->free_area_cache = addr + len;
64560+ return addr;
64561 }
64562 #endif
64563
64564 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
64565 {
64566+
64567+#ifdef CONFIG_PAX_SEGMEXEC
64568+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
64569+ return;
64570+#endif
64571+
64572 /*
64573 * Is this a new hole at the lowest possible address?
64574 */
64575- if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache) {
64576+ if (addr >= mm->mmap_base && addr < mm->free_area_cache) {
64577 mm->free_area_cache = addr;
64578 mm->cached_hole_size = ~0UL;
64579 }
64580@@ -1348,7 +1553,7 @@ arch_get_unmapped_area_topdown(struct fi
64581 {
64582 struct vm_area_struct *vma;
64583 struct mm_struct *mm = current->mm;
64584- unsigned long addr = addr0;
64585+ unsigned long base = mm->mmap_base, addr = addr0;
64586
64587 /* requested length too big for entire address space */
64588 if (len > TASK_SIZE)
64589@@ -1357,13 +1562,18 @@ arch_get_unmapped_area_topdown(struct fi
64590 if (flags & MAP_FIXED)
64591 return addr;
64592
64593+#ifdef CONFIG_PAX_RANDMMAP
64594+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
64595+#endif
64596+
64597 /* requesting a specific address */
64598 if (addr) {
64599 addr = PAGE_ALIGN(addr);
64600- vma = find_vma(mm, addr);
64601- if (TASK_SIZE - len >= addr &&
64602- (!vma || addr + len <= vma->vm_start))
64603- return addr;
64604+ if (TASK_SIZE - len >= addr) {
64605+ vma = find_vma(mm, addr);
64606+ if (check_heap_stack_gap(vma, addr, len))
64607+ return addr;
64608+ }
64609 }
64610
64611 /* check if free_area_cache is useful for us */
64612@@ -1378,7 +1588,7 @@ arch_get_unmapped_area_topdown(struct fi
64613 /* make sure it can fit in the remaining address space */
64614 if (addr > len) {
64615 vma = find_vma(mm, addr-len);
64616- if (!vma || addr <= vma->vm_start)
64617+ if (check_heap_stack_gap(vma, addr - len, len))
64618 /* remember the address as a hint for next time */
64619 return (mm->free_area_cache = addr-len);
64620 }
64621@@ -1395,7 +1605,7 @@ arch_get_unmapped_area_topdown(struct fi
64622 * return with success:
64623 */
64624 vma = find_vma(mm, addr);
64625- if (!vma || addr+len <= vma->vm_start)
64626+ if (check_heap_stack_gap(vma, addr, len))
64627 /* remember the address as a hint for next time */
64628 return (mm->free_area_cache = addr);
64629
64630@@ -1404,8 +1614,8 @@ arch_get_unmapped_area_topdown(struct fi
64631 mm->cached_hole_size = vma->vm_start - addr;
64632
64633 /* try just below the current vma->vm_start */
64634- addr = vma->vm_start-len;
64635- } while (len < vma->vm_start);
64636+ addr = skip_heap_stack_gap(vma, len);
64637+ } while (!IS_ERR_VALUE(addr));
64638
64639 bottomup:
64640 /*
64641@@ -1414,13 +1624,21 @@ bottomup:
64642 * can happen with large stack limits and large mmap()
64643 * allocations.
64644 */
64645+ mm->mmap_base = TASK_UNMAPPED_BASE;
64646+
64647+#ifdef CONFIG_PAX_RANDMMAP
64648+ if (mm->pax_flags & MF_PAX_RANDMMAP)
64649+ mm->mmap_base += mm->delta_mmap;
64650+#endif
64651+
64652+ mm->free_area_cache = mm->mmap_base;
64653 mm->cached_hole_size = ~0UL;
64654- mm->free_area_cache = TASK_UNMAPPED_BASE;
64655 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
64656 /*
64657 * Restore the topdown base:
64658 */
64659- mm->free_area_cache = mm->mmap_base;
64660+ mm->mmap_base = base;
64661+ mm->free_area_cache = base;
64662 mm->cached_hole_size = ~0UL;
64663
64664 return addr;
64665@@ -1429,6 +1647,12 @@ bottomup:
64666
64667 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
64668 {
64669+
64670+#ifdef CONFIG_PAX_SEGMEXEC
64671+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
64672+ return;
64673+#endif
64674+
64675 /*
64676 * Is this a new hole at the highest possible address?
64677 */
64678@@ -1436,8 +1660,10 @@ void arch_unmap_area_topdown(struct mm_s
64679 mm->free_area_cache = addr;
64680
64681 /* dont allow allocations above current base */
64682- if (mm->free_area_cache > mm->mmap_base)
64683+ if (mm->free_area_cache > mm->mmap_base) {
64684 mm->free_area_cache = mm->mmap_base;
64685+ mm->cached_hole_size = ~0UL;
64686+ }
64687 }
64688
64689 unsigned long
64690@@ -1545,6 +1771,27 @@ out:
64691 return prev ? prev->vm_next : vma;
64692 }
64693
64694+#ifdef CONFIG_PAX_SEGMEXEC
64695+struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
64696+{
64697+ struct vm_area_struct *vma_m;
64698+
64699+ BUG_ON(!vma || vma->vm_start >= vma->vm_end);
64700+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
64701+ BUG_ON(vma->vm_mirror);
64702+ return NULL;
64703+ }
64704+ BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
64705+ vma_m = vma->vm_mirror;
64706+ BUG_ON(!vma_m || vma_m->vm_mirror != vma);
64707+ BUG_ON(vma->vm_file != vma_m->vm_file);
64708+ BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
64709+ BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff || vma->anon_vma != vma_m->anon_vma);
64710+ BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED | VM_RESERVED));
64711+ return vma_m;
64712+}
64713+#endif
64714+
64715 /*
64716 * Verify that the stack growth is acceptable and
64717 * update accounting. This is shared with both the
64718@@ -1561,6 +1808,7 @@ static int acct_stack_growth(struct vm_a
64719 return -ENOMEM;
64720
64721 /* Stack limit test */
64722+ gr_learn_resource(current, RLIMIT_STACK, size, 1);
64723 if (size > rlim[RLIMIT_STACK].rlim_cur)
64724 return -ENOMEM;
64725
64726@@ -1570,6 +1818,7 @@ static int acct_stack_growth(struct vm_a
64727 unsigned long limit;
64728 locked = mm->locked_vm + grow;
64729 limit = rlim[RLIMIT_MEMLOCK].rlim_cur >> PAGE_SHIFT;
64730+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
64731 if (locked > limit && !capable(CAP_IPC_LOCK))
64732 return -ENOMEM;
64733 }
64734@@ -1600,37 +1849,48 @@ static int acct_stack_growth(struct vm_a
64735 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
64736 * vma is the last one with address > vma->vm_end. Have to extend vma.
64737 */
64738+#ifndef CONFIG_IA64
64739+static
64740+#endif
64741 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
64742 {
64743 int error;
64744+ bool locknext;
64745
64746 if (!(vma->vm_flags & VM_GROWSUP))
64747 return -EFAULT;
64748
64749+ /* Also guard against wrapping around to address 0. */
64750+ if (address < PAGE_ALIGN(address+1))
64751+ address = PAGE_ALIGN(address+1);
64752+ else
64753+ return -ENOMEM;
64754+
64755 /*
64756 * We must make sure the anon_vma is allocated
64757 * so that the anon_vma locking is not a noop.
64758 */
64759 if (unlikely(anon_vma_prepare(vma)))
64760 return -ENOMEM;
64761+ locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
64762+ if (locknext && anon_vma_prepare(vma->vm_next))
64763+ return -ENOMEM;
64764 anon_vma_lock(vma);
64765+ if (locknext)
64766+ anon_vma_lock(vma->vm_next);
64767
64768 /*
64769 * vma->vm_start/vm_end cannot change under us because the caller
64770 * is required to hold the mmap_sem in read mode. We need the
64771- * anon_vma lock to serialize against concurrent expand_stacks.
64772- * Also guard against wrapping around to address 0.
64773+ * anon_vma locks to serialize against concurrent expand_stacks
64774+ * and expand_upwards.
64775 */
64776- if (address < PAGE_ALIGN(address+4))
64777- address = PAGE_ALIGN(address+4);
64778- else {
64779- anon_vma_unlock(vma);
64780- return -ENOMEM;
64781- }
64782 error = 0;
64783
64784 /* Somebody else might have raced and expanded it already */
64785- if (address > vma->vm_end) {
64786+ 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)
64787+ error = -ENOMEM;
64788+ else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
64789 unsigned long size, grow;
64790
64791 size = address - vma->vm_start;
64792@@ -1640,6 +1900,8 @@ int expand_upwards(struct vm_area_struct
64793 if (!error)
64794 vma->vm_end = address;
64795 }
64796+ if (locknext)
64797+ anon_vma_unlock(vma->vm_next);
64798 anon_vma_unlock(vma);
64799 return error;
64800 }
64801@@ -1652,6 +1914,8 @@ static int expand_downwards(struct vm_ar
64802 unsigned long address)
64803 {
64804 int error;
64805+ bool lockprev = false;
64806+ struct vm_area_struct *prev;
64807
64808 /*
64809 * We must make sure the anon_vma is allocated
64810@@ -1665,6 +1929,15 @@ static int expand_downwards(struct vm_ar
64811 if (error)
64812 return error;
64813
64814+ prev = vma->vm_prev;
64815+#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
64816+ lockprev = prev && (prev->vm_flags & VM_GROWSUP);
64817+#endif
64818+ if (lockprev && anon_vma_prepare(prev))
64819+ return -ENOMEM;
64820+ if (lockprev)
64821+ anon_vma_lock(prev);
64822+
64823 anon_vma_lock(vma);
64824
64825 /*
64826@@ -1674,9 +1947,17 @@ static int expand_downwards(struct vm_ar
64827 */
64828
64829 /* Somebody else might have raced and expanded it already */
64830- if (address < vma->vm_start) {
64831+ if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
64832+ error = -ENOMEM;
64833+ else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
64834 unsigned long size, grow;
64835
64836+#ifdef CONFIG_PAX_SEGMEXEC
64837+ struct vm_area_struct *vma_m;
64838+
64839+ vma_m = pax_find_mirror_vma(vma);
64840+#endif
64841+
64842 size = vma->vm_end - address;
64843 grow = (vma->vm_start - address) >> PAGE_SHIFT;
64844
64845@@ -1684,9 +1965,20 @@ static int expand_downwards(struct vm_ar
64846 if (!error) {
64847 vma->vm_start = address;
64848 vma->vm_pgoff -= grow;
64849+ track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
64850+
64851+#ifdef CONFIG_PAX_SEGMEXEC
64852+ if (vma_m) {
64853+ vma_m->vm_start -= grow << PAGE_SHIFT;
64854+ vma_m->vm_pgoff -= grow;
64855+ }
64856+#endif
64857+
64858 }
64859 }
64860 anon_vma_unlock(vma);
64861+ if (lockprev)
64862+ anon_vma_unlock(prev);
64863 return error;
64864 }
64865
64866@@ -1762,6 +2054,13 @@ static void remove_vma_list(struct mm_st
64867 do {
64868 long nrpages = vma_pages(vma);
64869
64870+#ifdef CONFIG_PAX_SEGMEXEC
64871+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
64872+ vma = remove_vma(vma);
64873+ continue;
64874+ }
64875+#endif
64876+
64877 mm->total_vm -= nrpages;
64878 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
64879 vma = remove_vma(vma);
64880@@ -1807,6 +2106,16 @@ detach_vmas_to_be_unmapped(struct mm_str
64881 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
64882 vma->vm_prev = NULL;
64883 do {
64884+
64885+#ifdef CONFIG_PAX_SEGMEXEC
64886+ if (vma->vm_mirror) {
64887+ BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
64888+ vma->vm_mirror->vm_mirror = NULL;
64889+ vma->vm_mirror->vm_flags &= ~VM_EXEC;
64890+ vma->vm_mirror = NULL;
64891+ }
64892+#endif
64893+
64894 rb_erase(&vma->vm_rb, &mm->mm_rb);
64895 mm->map_count--;
64896 tail_vma = vma;
64897@@ -1834,10 +2143,25 @@ int split_vma(struct mm_struct * mm, str
64898 struct mempolicy *pol;
64899 struct vm_area_struct *new;
64900
64901+#ifdef CONFIG_PAX_SEGMEXEC
64902+ struct vm_area_struct *vma_m, *new_m = NULL;
64903+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
64904+#endif
64905+
64906 if (is_vm_hugetlb_page(vma) && (addr &
64907 ~(huge_page_mask(hstate_vma(vma)))))
64908 return -EINVAL;
64909
64910+#ifdef CONFIG_PAX_SEGMEXEC
64911+ vma_m = pax_find_mirror_vma(vma);
64912+
64913+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
64914+ BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
64915+ if (mm->map_count >= sysctl_max_map_count-1)
64916+ return -ENOMEM;
64917+ } else
64918+#endif
64919+
64920 if (mm->map_count >= sysctl_max_map_count)
64921 return -ENOMEM;
64922
64923@@ -1845,6 +2169,16 @@ int split_vma(struct mm_struct * mm, str
64924 if (!new)
64925 return -ENOMEM;
64926
64927+#ifdef CONFIG_PAX_SEGMEXEC
64928+ if (vma_m) {
64929+ new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
64930+ if (!new_m) {
64931+ kmem_cache_free(vm_area_cachep, new);
64932+ return -ENOMEM;
64933+ }
64934+ }
64935+#endif
64936+
64937 /* most fields are the same, copy all, and then fixup */
64938 *new = *vma;
64939
64940@@ -1855,8 +2189,29 @@ int split_vma(struct mm_struct * mm, str
64941 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
64942 }
64943
64944+#ifdef CONFIG_PAX_SEGMEXEC
64945+ if (vma_m) {
64946+ *new_m = *vma_m;
64947+ new_m->vm_mirror = new;
64948+ new->vm_mirror = new_m;
64949+
64950+ if (new_below)
64951+ new_m->vm_end = addr_m;
64952+ else {
64953+ new_m->vm_start = addr_m;
64954+ new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
64955+ }
64956+ }
64957+#endif
64958+
64959 pol = mpol_dup(vma_policy(vma));
64960 if (IS_ERR(pol)) {
64961+
64962+#ifdef CONFIG_PAX_SEGMEXEC
64963+ if (new_m)
64964+ kmem_cache_free(vm_area_cachep, new_m);
64965+#endif
64966+
64967 kmem_cache_free(vm_area_cachep, new);
64968 return PTR_ERR(pol);
64969 }
64970@@ -1877,6 +2232,28 @@ int split_vma(struct mm_struct * mm, str
64971 else
64972 vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
64973
64974+#ifdef CONFIG_PAX_SEGMEXEC
64975+ if (vma_m) {
64976+ mpol_get(pol);
64977+ vma_set_policy(new_m, pol);
64978+
64979+ if (new_m->vm_file) {
64980+ get_file(new_m->vm_file);
64981+ if (vma_m->vm_flags & VM_EXECUTABLE)
64982+ added_exe_file_vma(mm);
64983+ }
64984+
64985+ if (new_m->vm_ops && new_m->vm_ops->open)
64986+ new_m->vm_ops->open(new_m);
64987+
64988+ if (new_below)
64989+ vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
64990+ ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
64991+ else
64992+ vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
64993+ }
64994+#endif
64995+
64996 return 0;
64997 }
64998
64999@@ -1885,11 +2262,30 @@ int split_vma(struct mm_struct * mm, str
65000 * work. This now handles partial unmappings.
65001 * Jeremy Fitzhardinge <jeremy@goop.org>
65002 */
65003+#ifdef CONFIG_PAX_SEGMEXEC
65004+int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
65005+{
65006+ int ret = __do_munmap(mm, start, len);
65007+ if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
65008+ return ret;
65009+
65010+ return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
65011+}
65012+
65013+int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
65014+#else
65015 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
65016+#endif
65017 {
65018 unsigned long end;
65019 struct vm_area_struct *vma, *prev, *last;
65020
65021+ /*
65022+ * mm->mmap_sem is required to protect against another thread
65023+ * changing the mappings in case we sleep.
65024+ */
65025+ verify_mm_writelocked(mm);
65026+
65027 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
65028 return -EINVAL;
65029
65030@@ -1953,6 +2349,8 @@ int do_munmap(struct mm_struct *mm, unsi
65031 /* Fix up all other VM information */
65032 remove_vma_list(mm, vma);
65033
65034+ track_exec_limit(mm, start, end, 0UL);
65035+
65036 return 0;
65037 }
65038
65039@@ -1965,22 +2363,18 @@ SYSCALL_DEFINE2(munmap, unsigned long, a
65040
65041 profile_munmap(addr);
65042
65043+#ifdef CONFIG_PAX_SEGMEXEC
65044+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
65045+ (len > SEGMEXEC_TASK_SIZE || addr > SEGMEXEC_TASK_SIZE-len))
65046+ return -EINVAL;
65047+#endif
65048+
65049 down_write(&mm->mmap_sem);
65050 ret = do_munmap(mm, addr, len);
65051 up_write(&mm->mmap_sem);
65052 return ret;
65053 }
65054
65055-static inline void verify_mm_writelocked(struct mm_struct *mm)
65056-{
65057-#ifdef CONFIG_DEBUG_VM
65058- if (unlikely(down_read_trylock(&mm->mmap_sem))) {
65059- WARN_ON(1);
65060- up_read(&mm->mmap_sem);
65061- }
65062-#endif
65063-}
65064-
65065 /*
65066 * this is really a simplified "do_mmap". it only handles
65067 * anonymous maps. eventually we may be able to do some
65068@@ -1994,6 +2388,7 @@ unsigned long do_brk(unsigned long addr,
65069 struct rb_node ** rb_link, * rb_parent;
65070 pgoff_t pgoff = addr >> PAGE_SHIFT;
65071 int error;
65072+ unsigned long charged;
65073
65074 len = PAGE_ALIGN(len);
65075 if (!len)
65076@@ -2005,16 +2400,30 @@ unsigned long do_brk(unsigned long addr,
65077
65078 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
65079
65080+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
65081+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
65082+ flags &= ~VM_EXEC;
65083+
65084+#ifdef CONFIG_PAX_MPROTECT
65085+ if (mm->pax_flags & MF_PAX_MPROTECT)
65086+ flags &= ~VM_MAYEXEC;
65087+#endif
65088+
65089+ }
65090+#endif
65091+
65092 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
65093 if (error & ~PAGE_MASK)
65094 return error;
65095
65096+ charged = len >> PAGE_SHIFT;
65097+
65098 /*
65099 * mlock MCL_FUTURE?
65100 */
65101 if (mm->def_flags & VM_LOCKED) {
65102 unsigned long locked, lock_limit;
65103- locked = len >> PAGE_SHIFT;
65104+ locked = charged;
65105 locked += mm->locked_vm;
65106 lock_limit = current->signal->rlim[RLIMIT_MEMLOCK].rlim_cur;
65107 lock_limit >>= PAGE_SHIFT;
65108@@ -2031,22 +2440,22 @@ unsigned long do_brk(unsigned long addr,
65109 /*
65110 * Clear old maps. this also does some error checking for us
65111 */
65112- munmap_back:
65113 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
65114 if (vma && vma->vm_start < addr + len) {
65115 if (do_munmap(mm, addr, len))
65116 return -ENOMEM;
65117- goto munmap_back;
65118+ vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
65119+ BUG_ON(vma && vma->vm_start < addr + len);
65120 }
65121
65122 /* Check against address space limits *after* clearing old maps... */
65123- if (!may_expand_vm(mm, len >> PAGE_SHIFT))
65124+ if (!may_expand_vm(mm, charged))
65125 return -ENOMEM;
65126
65127 if (mm->map_count > sysctl_max_map_count)
65128 return -ENOMEM;
65129
65130- if (security_vm_enough_memory(len >> PAGE_SHIFT))
65131+ if (security_vm_enough_memory(charged))
65132 return -ENOMEM;
65133
65134 /* Can we just expand an old private anonymous mapping? */
65135@@ -2060,7 +2469,7 @@ unsigned long do_brk(unsigned long addr,
65136 */
65137 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
65138 if (!vma) {
65139- vm_unacct_memory(len >> PAGE_SHIFT);
65140+ vm_unacct_memory(charged);
65141 return -ENOMEM;
65142 }
65143
65144@@ -2072,11 +2481,12 @@ unsigned long do_brk(unsigned long addr,
65145 vma->vm_page_prot = vm_get_page_prot(flags);
65146 vma_link(mm, vma, prev, rb_link, rb_parent);
65147 out:
65148- mm->total_vm += len >> PAGE_SHIFT;
65149+ mm->total_vm += charged;
65150 if (flags & VM_LOCKED) {
65151 if (!mlock_vma_pages_range(vma, addr, addr + len))
65152- mm->locked_vm += (len >> PAGE_SHIFT);
65153+ mm->locked_vm += charged;
65154 }
65155+ track_exec_limit(mm, addr, addr + len, flags);
65156 return addr;
65157 }
65158
65159@@ -2123,8 +2533,10 @@ void exit_mmap(struct mm_struct *mm)
65160 * Walk the list again, actually closing and freeing it,
65161 * with preemption enabled, without holding any MM locks.
65162 */
65163- while (vma)
65164+ while (vma) {
65165+ vma->vm_mirror = NULL;
65166 vma = remove_vma(vma);
65167+ }
65168
65169 BUG_ON(mm->nr_ptes > (FIRST_USER_ADDRESS+PMD_SIZE-1)>>PMD_SHIFT);
65170 }
65171@@ -2138,6 +2550,10 @@ int insert_vm_struct(struct mm_struct *
65172 struct vm_area_struct * __vma, * prev;
65173 struct rb_node ** rb_link, * rb_parent;
65174
65175+#ifdef CONFIG_PAX_SEGMEXEC
65176+ struct vm_area_struct *vma_m = NULL;
65177+#endif
65178+
65179 /*
65180 * The vm_pgoff of a purely anonymous vma should be irrelevant
65181 * until its first write fault, when page's anon_vma and index
65182@@ -2160,7 +2576,22 @@ int insert_vm_struct(struct mm_struct *
65183 if ((vma->vm_flags & VM_ACCOUNT) &&
65184 security_vm_enough_memory_mm(mm, vma_pages(vma)))
65185 return -ENOMEM;
65186+
65187+#ifdef CONFIG_PAX_SEGMEXEC
65188+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
65189+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
65190+ if (!vma_m)
65191+ return -ENOMEM;
65192+ }
65193+#endif
65194+
65195 vma_link(mm, vma, prev, rb_link, rb_parent);
65196+
65197+#ifdef CONFIG_PAX_SEGMEXEC
65198+ if (vma_m)
65199+ pax_mirror_vma(vma_m, vma);
65200+#endif
65201+
65202 return 0;
65203 }
65204
65205@@ -2178,6 +2609,8 @@ struct vm_area_struct *copy_vma(struct v
65206 struct rb_node **rb_link, *rb_parent;
65207 struct mempolicy *pol;
65208
65209+ BUG_ON(vma->vm_mirror);
65210+
65211 /*
65212 * If anonymous vma has not yet been faulted, update new pgoff
65213 * to match new location, to increase its chance of merging.
65214@@ -2221,6 +2654,35 @@ struct vm_area_struct *copy_vma(struct v
65215 return new_vma;
65216 }
65217
65218+#ifdef CONFIG_PAX_SEGMEXEC
65219+void pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
65220+{
65221+ struct vm_area_struct *prev_m;
65222+ struct rb_node **rb_link_m, *rb_parent_m;
65223+ struct mempolicy *pol_m;
65224+
65225+ BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
65226+ BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
65227+ BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
65228+ *vma_m = *vma;
65229+ pol_m = vma_policy(vma_m);
65230+ mpol_get(pol_m);
65231+ vma_set_policy(vma_m, pol_m);
65232+ vma_m->vm_start += SEGMEXEC_TASK_SIZE;
65233+ vma_m->vm_end += SEGMEXEC_TASK_SIZE;
65234+ vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
65235+ vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
65236+ if (vma_m->vm_file)
65237+ get_file(vma_m->vm_file);
65238+ if (vma_m->vm_ops && vma_m->vm_ops->open)
65239+ vma_m->vm_ops->open(vma_m);
65240+ find_vma_prepare(vma->vm_mm, vma_m->vm_start, &prev_m, &rb_link_m, &rb_parent_m);
65241+ vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
65242+ vma_m->vm_mirror = vma;
65243+ vma->vm_mirror = vma_m;
65244+}
65245+#endif
65246+
65247 /*
65248 * Return true if the calling process may expand its vm space by the passed
65249 * number of pages
65250@@ -2231,7 +2693,7 @@ int may_expand_vm(struct mm_struct *mm,
65251 unsigned long lim;
65252
65253 lim = current->signal->rlim[RLIMIT_AS].rlim_cur >> PAGE_SHIFT;
65254-
65255+ gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
65256 if (cur + npages > lim)
65257 return 0;
65258 return 1;
65259@@ -2301,6 +2763,22 @@ int install_special_mapping(struct mm_st
65260 vma->vm_start = addr;
65261 vma->vm_end = addr + len;
65262
65263+#ifdef CONFIG_PAX_MPROTECT
65264+ if (mm->pax_flags & MF_PAX_MPROTECT) {
65265+#ifndef CONFIG_PAX_MPROTECT_COMPAT
65266+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
65267+ return -EPERM;
65268+ if (!(vm_flags & VM_EXEC))
65269+ vm_flags &= ~VM_MAYEXEC;
65270+#else
65271+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
65272+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
65273+#endif
65274+ else
65275+ vm_flags &= ~VM_MAYWRITE;
65276+ }
65277+#endif
65278+
65279 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
65280 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
65281
65282diff -urNp linux-2.6.32.41/mm/mprotect.c linux-2.6.32.41/mm/mprotect.c
65283--- linux-2.6.32.41/mm/mprotect.c 2011-03-27 14:31:47.000000000 -0400
65284+++ linux-2.6.32.41/mm/mprotect.c 2011-04-17 15:56:46.000000000 -0400
65285@@ -24,10 +24,16 @@
65286 #include <linux/mmu_notifier.h>
65287 #include <linux/migrate.h>
65288 #include <linux/perf_event.h>
65289+
65290+#ifdef CONFIG_PAX_MPROTECT
65291+#include <linux/elf.h>
65292+#endif
65293+
65294 #include <asm/uaccess.h>
65295 #include <asm/pgtable.h>
65296 #include <asm/cacheflush.h>
65297 #include <asm/tlbflush.h>
65298+#include <asm/mmu_context.h>
65299
65300 #ifndef pgprot_modify
65301 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
65302@@ -132,6 +138,48 @@ static void change_protection(struct vm_
65303 flush_tlb_range(vma, start, end);
65304 }
65305
65306+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
65307+/* called while holding the mmap semaphor for writing except stack expansion */
65308+void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
65309+{
65310+ unsigned long oldlimit, newlimit = 0UL;
65311+
65312+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || nx_enabled)
65313+ return;
65314+
65315+ spin_lock(&mm->page_table_lock);
65316+ oldlimit = mm->context.user_cs_limit;
65317+ if ((prot & VM_EXEC) && oldlimit < end)
65318+ /* USER_CS limit moved up */
65319+ newlimit = end;
65320+ else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
65321+ /* USER_CS limit moved down */
65322+ newlimit = start;
65323+
65324+ if (newlimit) {
65325+ mm->context.user_cs_limit = newlimit;
65326+
65327+#ifdef CONFIG_SMP
65328+ wmb();
65329+ cpus_clear(mm->context.cpu_user_cs_mask);
65330+ cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
65331+#endif
65332+
65333+ set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
65334+ }
65335+ spin_unlock(&mm->page_table_lock);
65336+ if (newlimit == end) {
65337+ struct vm_area_struct *vma = find_vma(mm, oldlimit);
65338+
65339+ for (; vma && vma->vm_start < end; vma = vma->vm_next)
65340+ if (is_vm_hugetlb_page(vma))
65341+ hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
65342+ else
65343+ change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma));
65344+ }
65345+}
65346+#endif
65347+
65348 int
65349 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
65350 unsigned long start, unsigned long end, unsigned long newflags)
65351@@ -144,11 +192,29 @@ mprotect_fixup(struct vm_area_struct *vm
65352 int error;
65353 int dirty_accountable = 0;
65354
65355+#ifdef CONFIG_PAX_SEGMEXEC
65356+ struct vm_area_struct *vma_m = NULL;
65357+ unsigned long start_m, end_m;
65358+
65359+ start_m = start + SEGMEXEC_TASK_SIZE;
65360+ end_m = end + SEGMEXEC_TASK_SIZE;
65361+#endif
65362+
65363 if (newflags == oldflags) {
65364 *pprev = vma;
65365 return 0;
65366 }
65367
65368+ if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
65369+ struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
65370+
65371+ if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
65372+ return -ENOMEM;
65373+
65374+ if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
65375+ return -ENOMEM;
65376+ }
65377+
65378 /*
65379 * If we make a private mapping writable we increase our commit;
65380 * but (without finer accounting) cannot reduce our commit if we
65381@@ -165,6 +231,38 @@ mprotect_fixup(struct vm_area_struct *vm
65382 }
65383 }
65384
65385+#ifdef CONFIG_PAX_SEGMEXEC
65386+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
65387+ if (start != vma->vm_start) {
65388+ error = split_vma(mm, vma, start, 1);
65389+ if (error)
65390+ goto fail;
65391+ BUG_ON(!*pprev || (*pprev)->vm_next == vma);
65392+ *pprev = (*pprev)->vm_next;
65393+ }
65394+
65395+ if (end != vma->vm_end) {
65396+ error = split_vma(mm, vma, end, 0);
65397+ if (error)
65398+ goto fail;
65399+ }
65400+
65401+ if (pax_find_mirror_vma(vma)) {
65402+ error = __do_munmap(mm, start_m, end_m - start_m);
65403+ if (error)
65404+ goto fail;
65405+ } else {
65406+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
65407+ if (!vma_m) {
65408+ error = -ENOMEM;
65409+ goto fail;
65410+ }
65411+ vma->vm_flags = newflags;
65412+ pax_mirror_vma(vma_m, vma);
65413+ }
65414+ }
65415+#endif
65416+
65417 /*
65418 * First try to merge with previous and/or next vma.
65419 */
65420@@ -195,9 +293,21 @@ success:
65421 * vm_flags and vm_page_prot are protected by the mmap_sem
65422 * held in write mode.
65423 */
65424+
65425+#ifdef CONFIG_PAX_SEGMEXEC
65426+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
65427+ pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
65428+#endif
65429+
65430 vma->vm_flags = newflags;
65431+
65432+#ifdef CONFIG_PAX_MPROTECT
65433+ if (mm->binfmt && mm->binfmt->handle_mprotect)
65434+ mm->binfmt->handle_mprotect(vma, newflags);
65435+#endif
65436+
65437 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
65438- vm_get_page_prot(newflags));
65439+ vm_get_page_prot(vma->vm_flags));
65440
65441 if (vma_wants_writenotify(vma)) {
65442 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
65443@@ -239,6 +349,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long,
65444 end = start + len;
65445 if (end <= start)
65446 return -ENOMEM;
65447+
65448+#ifdef CONFIG_PAX_SEGMEXEC
65449+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
65450+ if (end > SEGMEXEC_TASK_SIZE)
65451+ return -EINVAL;
65452+ } else
65453+#endif
65454+
65455+ if (end > TASK_SIZE)
65456+ return -EINVAL;
65457+
65458 if (!arch_validate_prot(prot))
65459 return -EINVAL;
65460
65461@@ -246,7 +367,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long,
65462 /*
65463 * Does the application expect PROT_READ to imply PROT_EXEC:
65464 */
65465- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
65466+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
65467 prot |= PROT_EXEC;
65468
65469 vm_flags = calc_vm_prot_bits(prot);
65470@@ -278,6 +399,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long,
65471 if (start > vma->vm_start)
65472 prev = vma;
65473
65474+#ifdef CONFIG_PAX_MPROTECT
65475+ if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
65476+ current->mm->binfmt->handle_mprotect(vma, vm_flags);
65477+#endif
65478+
65479 for (nstart = start ; ; ) {
65480 unsigned long newflags;
65481
65482@@ -287,6 +413,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long,
65483
65484 /* newflags >> 4 shift VM_MAY% in place of VM_% */
65485 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
65486+ if (prot & (PROT_WRITE | PROT_EXEC))
65487+ gr_log_rwxmprotect(vma->vm_file);
65488+
65489+ error = -EACCES;
65490+ goto out;
65491+ }
65492+
65493+ if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
65494 error = -EACCES;
65495 goto out;
65496 }
65497@@ -301,6 +435,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long,
65498 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
65499 if (error)
65500 goto out;
65501+
65502+ track_exec_limit(current->mm, nstart, tmp, vm_flags);
65503+
65504 nstart = tmp;
65505
65506 if (nstart < prev->vm_end)
65507diff -urNp linux-2.6.32.41/mm/mremap.c linux-2.6.32.41/mm/mremap.c
65508--- linux-2.6.32.41/mm/mremap.c 2011-04-17 17:00:52.000000000 -0400
65509+++ linux-2.6.32.41/mm/mremap.c 2011-04-17 17:03:58.000000000 -0400
65510@@ -112,6 +112,12 @@ static void move_ptes(struct vm_area_str
65511 continue;
65512 pte = ptep_clear_flush(vma, old_addr, old_pte);
65513 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
65514+
65515+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
65516+ if (!nx_enabled && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
65517+ pte = pte_exprotect(pte);
65518+#endif
65519+
65520 set_pte_at(mm, new_addr, new_pte, pte);
65521 }
65522
65523@@ -271,6 +277,11 @@ static struct vm_area_struct *vma_to_res
65524 if (is_vm_hugetlb_page(vma))
65525 goto Einval;
65526
65527+#ifdef CONFIG_PAX_SEGMEXEC
65528+ if (pax_find_mirror_vma(vma))
65529+ goto Einval;
65530+#endif
65531+
65532 /* We can't remap across vm area boundaries */
65533 if (old_len > vma->vm_end - addr)
65534 goto Efault;
65535@@ -327,20 +338,25 @@ static unsigned long mremap_to(unsigned
65536 unsigned long ret = -EINVAL;
65537 unsigned long charged = 0;
65538 unsigned long map_flags;
65539+ unsigned long pax_task_size = TASK_SIZE;
65540
65541 if (new_addr & ~PAGE_MASK)
65542 goto out;
65543
65544- if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
65545+#ifdef CONFIG_PAX_SEGMEXEC
65546+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
65547+ pax_task_size = SEGMEXEC_TASK_SIZE;
65548+#endif
65549+
65550+ pax_task_size -= PAGE_SIZE;
65551+
65552+ if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
65553 goto out;
65554
65555 /* Check if the location we're moving into overlaps the
65556 * old location at all, and fail if it does.
65557 */
65558- if ((new_addr <= addr) && (new_addr+new_len) > addr)
65559- goto out;
65560-
65561- if ((addr <= new_addr) && (addr+old_len) > new_addr)
65562+ if (addr + old_len > new_addr && new_addr + new_len > addr)
65563 goto out;
65564
65565 ret = security_file_mmap(NULL, 0, 0, 0, new_addr, 1);
65566@@ -412,6 +428,7 @@ unsigned long do_mremap(unsigned long ad
65567 struct vm_area_struct *vma;
65568 unsigned long ret = -EINVAL;
65569 unsigned long charged = 0;
65570+ unsigned long pax_task_size = TASK_SIZE;
65571
65572 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
65573 goto out;
65574@@ -430,6 +447,17 @@ unsigned long do_mremap(unsigned long ad
65575 if (!new_len)
65576 goto out;
65577
65578+#ifdef CONFIG_PAX_SEGMEXEC
65579+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
65580+ pax_task_size = SEGMEXEC_TASK_SIZE;
65581+#endif
65582+
65583+ pax_task_size -= PAGE_SIZE;
65584+
65585+ if (new_len > pax_task_size || addr > pax_task_size-new_len ||
65586+ old_len > pax_task_size || addr > pax_task_size-old_len)
65587+ goto out;
65588+
65589 if (flags & MREMAP_FIXED) {
65590 if (flags & MREMAP_MAYMOVE)
65591 ret = mremap_to(addr, old_len, new_addr, new_len);
65592@@ -476,6 +504,7 @@ unsigned long do_mremap(unsigned long ad
65593 addr + new_len);
65594 }
65595 ret = addr;
65596+ track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
65597 goto out;
65598 }
65599 }
65600@@ -502,7 +531,13 @@ unsigned long do_mremap(unsigned long ad
65601 ret = security_file_mmap(NULL, 0, 0, 0, new_addr, 1);
65602 if (ret)
65603 goto out;
65604+
65605+ map_flags = vma->vm_flags;
65606 ret = move_vma(vma, addr, old_len, new_len, new_addr);
65607+ if (!(ret & ~PAGE_MASK)) {
65608+ track_exec_limit(current->mm, addr, addr + old_len, 0UL);
65609+ track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
65610+ }
65611 }
65612 out:
65613 if (ret & ~PAGE_MASK)
65614diff -urNp linux-2.6.32.41/mm/nommu.c linux-2.6.32.41/mm/nommu.c
65615--- linux-2.6.32.41/mm/nommu.c 2011-03-27 14:31:47.000000000 -0400
65616+++ linux-2.6.32.41/mm/nommu.c 2011-04-17 15:56:46.000000000 -0400
65617@@ -67,7 +67,6 @@ int sysctl_overcommit_memory = OVERCOMMI
65618 int sysctl_overcommit_ratio = 50; /* default is 50% */
65619 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
65620 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
65621-int heap_stack_gap = 0;
65622
65623 atomic_long_t mmap_pages_allocated;
65624
65625@@ -761,15 +760,6 @@ struct vm_area_struct *find_vma(struct m
65626 EXPORT_SYMBOL(find_vma);
65627
65628 /*
65629- * find a VMA
65630- * - we don't extend stack VMAs under NOMMU conditions
65631- */
65632-struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
65633-{
65634- return find_vma(mm, addr);
65635-}
65636-
65637-/*
65638 * expand a stack to a given address
65639 * - not supported under NOMMU conditions
65640 */
65641diff -urNp linux-2.6.32.41/mm/page_alloc.c linux-2.6.32.41/mm/page_alloc.c
65642--- linux-2.6.32.41/mm/page_alloc.c 2011-03-27 14:31:47.000000000 -0400
65643+++ linux-2.6.32.41/mm/page_alloc.c 2011-05-16 21:46:57.000000000 -0400
65644@@ -587,6 +587,10 @@ static void __free_pages_ok(struct page
65645 int bad = 0;
65646 int wasMlocked = __TestClearPageMlocked(page);
65647
65648+#ifdef CONFIG_PAX_MEMORY_SANITIZE
65649+ unsigned long index = 1UL << order;
65650+#endif
65651+
65652 kmemcheck_free_shadow(page, order);
65653
65654 for (i = 0 ; i < (1 << order) ; ++i)
65655@@ -599,6 +603,12 @@ static void __free_pages_ok(struct page
65656 debug_check_no_obj_freed(page_address(page),
65657 PAGE_SIZE << order);
65658 }
65659+
65660+#ifdef CONFIG_PAX_MEMORY_SANITIZE
65661+ for (; index; --index)
65662+ sanitize_highpage(page + index - 1);
65663+#endif
65664+
65665 arch_free_page(page, order);
65666 kernel_map_pages(page, 1 << order, 0);
65667
65668@@ -702,8 +712,10 @@ static int prep_new_page(struct page *pa
65669 arch_alloc_page(page, order);
65670 kernel_map_pages(page, 1 << order, 1);
65671
65672+#ifndef CONFIG_PAX_MEMORY_SANITIZE
65673 if (gfp_flags & __GFP_ZERO)
65674 prep_zero_page(page, order, gfp_flags);
65675+#endif
65676
65677 if (order && (gfp_flags & __GFP_COMP))
65678 prep_compound_page(page, order);
65679@@ -1097,6 +1109,11 @@ static void free_hot_cold_page(struct pa
65680 debug_check_no_locks_freed(page_address(page), PAGE_SIZE);
65681 debug_check_no_obj_freed(page_address(page), PAGE_SIZE);
65682 }
65683+
65684+#ifdef CONFIG_PAX_MEMORY_SANITIZE
65685+ sanitize_highpage(page);
65686+#endif
65687+
65688 arch_free_page(page, 0);
65689 kernel_map_pages(page, 1, 0);
65690
65691@@ -2179,6 +2196,8 @@ void show_free_areas(void)
65692 int cpu;
65693 struct zone *zone;
65694
65695+ pax_track_stack();
65696+
65697 for_each_populated_zone(zone) {
65698 show_node(zone);
65699 printk("%s per-cpu:\n", zone->name);
65700@@ -3736,7 +3755,7 @@ static void __init setup_usemap(struct p
65701 zone->pageblock_flags = alloc_bootmem_node(pgdat, usemapsize);
65702 }
65703 #else
65704-static void inline setup_usemap(struct pglist_data *pgdat,
65705+static inline void setup_usemap(struct pglist_data *pgdat,
65706 struct zone *zone, unsigned long zonesize) {}
65707 #endif /* CONFIG_SPARSEMEM */
65708
65709diff -urNp linux-2.6.32.41/mm/percpu.c linux-2.6.32.41/mm/percpu.c
65710--- linux-2.6.32.41/mm/percpu.c 2011-03-27 14:31:47.000000000 -0400
65711+++ linux-2.6.32.41/mm/percpu.c 2011-04-17 15:56:46.000000000 -0400
65712@@ -115,7 +115,7 @@ static unsigned int pcpu_first_unit_cpu
65713 static unsigned int pcpu_last_unit_cpu __read_mostly;
65714
65715 /* the address of the first chunk which starts with the kernel static area */
65716-void *pcpu_base_addr __read_mostly;
65717+void *pcpu_base_addr __read_only;
65718 EXPORT_SYMBOL_GPL(pcpu_base_addr);
65719
65720 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
65721diff -urNp linux-2.6.32.41/mm/rmap.c linux-2.6.32.41/mm/rmap.c
65722--- linux-2.6.32.41/mm/rmap.c 2011-03-27 14:31:47.000000000 -0400
65723+++ linux-2.6.32.41/mm/rmap.c 2011-04-17 15:56:46.000000000 -0400
65724@@ -121,6 +121,17 @@ int anon_vma_prepare(struct vm_area_stru
65725 /* page_table_lock to protect against threads */
65726 spin_lock(&mm->page_table_lock);
65727 if (likely(!vma->anon_vma)) {
65728+
65729+#ifdef CONFIG_PAX_SEGMEXEC
65730+ struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
65731+
65732+ if (vma_m) {
65733+ BUG_ON(vma_m->anon_vma);
65734+ vma_m->anon_vma = anon_vma;
65735+ list_add_tail(&vma_m->anon_vma_node, &anon_vma->head);
65736+ }
65737+#endif
65738+
65739 vma->anon_vma = anon_vma;
65740 list_add_tail(&vma->anon_vma_node, &anon_vma->head);
65741 allocated = NULL;
65742diff -urNp linux-2.6.32.41/mm/shmem.c linux-2.6.32.41/mm/shmem.c
65743--- linux-2.6.32.41/mm/shmem.c 2011-03-27 14:31:47.000000000 -0400
65744+++ linux-2.6.32.41/mm/shmem.c 2011-05-18 20:09:37.000000000 -0400
65745@@ -31,7 +31,7 @@
65746 #include <linux/swap.h>
65747 #include <linux/ima.h>
65748
65749-static struct vfsmount *shm_mnt;
65750+struct vfsmount *shm_mnt;
65751
65752 #ifdef CONFIG_SHMEM
65753 /*
65754@@ -1061,6 +1061,8 @@ static int shmem_writepage(struct page *
65755 goto unlock;
65756 }
65757 entry = shmem_swp_entry(info, index, NULL);
65758+ if (!entry)
65759+ goto unlock;
65760 if (entry->val) {
65761 /*
65762 * The more uptodate page coming down from a stacked
65763@@ -1144,6 +1146,8 @@ static struct page *shmem_swapin(swp_ent
65764 struct vm_area_struct pvma;
65765 struct page *page;
65766
65767+ pax_track_stack();
65768+
65769 spol = mpol_cond_copy(&mpol,
65770 mpol_shared_policy_lookup(&info->policy, idx));
65771
65772@@ -1962,7 +1966,7 @@ static int shmem_symlink(struct inode *d
65773
65774 info = SHMEM_I(inode);
65775 inode->i_size = len-1;
65776- if (len <= (char *)inode - (char *)info) {
65777+ if (len <= (char *)inode - (char *)info && len <= 64) {
65778 /* do it inline */
65779 memcpy(info, symname, len);
65780 inode->i_op = &shmem_symlink_inline_operations;
65781@@ -2310,8 +2314,7 @@ int shmem_fill_super(struct super_block
65782 int err = -ENOMEM;
65783
65784 /* Round up to L1_CACHE_BYTES to resist false sharing */
65785- sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
65786- L1_CACHE_BYTES), GFP_KERNEL);
65787+ sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
65788 if (!sbinfo)
65789 return -ENOMEM;
65790
65791diff -urNp linux-2.6.32.41/mm/slab.c linux-2.6.32.41/mm/slab.c
65792--- linux-2.6.32.41/mm/slab.c 2011-03-27 14:31:47.000000000 -0400
65793+++ linux-2.6.32.41/mm/slab.c 2011-05-04 17:56:20.000000000 -0400
65794@@ -174,7 +174,7 @@
65795
65796 /* Legal flag mask for kmem_cache_create(). */
65797 #if DEBUG
65798-# define CREATE_MASK (SLAB_RED_ZONE | \
65799+# define CREATE_MASK (SLAB_USERCOPY | SLAB_RED_ZONE | \
65800 SLAB_POISON | SLAB_HWCACHE_ALIGN | \
65801 SLAB_CACHE_DMA | \
65802 SLAB_STORE_USER | \
65803@@ -182,7 +182,7 @@
65804 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
65805 SLAB_DEBUG_OBJECTS | SLAB_NOLEAKTRACE | SLAB_NOTRACK)
65806 #else
65807-# define CREATE_MASK (SLAB_HWCACHE_ALIGN | \
65808+# define CREATE_MASK (SLAB_USERCOPY | SLAB_HWCACHE_ALIGN | \
65809 SLAB_CACHE_DMA | \
65810 SLAB_RECLAIM_ACCOUNT | SLAB_PANIC | \
65811 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
65812@@ -308,7 +308,7 @@ struct kmem_list3 {
65813 * Need this for bootstrapping a per node allocator.
65814 */
65815 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
65816-struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
65817+struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
65818 #define CACHE_CACHE 0
65819 #define SIZE_AC MAX_NUMNODES
65820 #define SIZE_L3 (2 * MAX_NUMNODES)
65821@@ -409,10 +409,10 @@ static void kmem_list3_init(struct kmem_
65822 if ((x)->max_freeable < i) \
65823 (x)->max_freeable = i; \
65824 } while (0)
65825-#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
65826-#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
65827-#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
65828-#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
65829+#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
65830+#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
65831+#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
65832+#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
65833 #else
65834 #define STATS_INC_ACTIVE(x) do { } while (0)
65835 #define STATS_DEC_ACTIVE(x) do { } while (0)
65836@@ -558,7 +558,7 @@ static inline void *index_to_obj(struct
65837 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
65838 */
65839 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
65840- const struct slab *slab, void *obj)
65841+ const struct slab *slab, const void *obj)
65842 {
65843 u32 offset = (obj - slab->s_mem);
65844 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
65845@@ -1453,7 +1453,7 @@ void __init kmem_cache_init(void)
65846 sizes[INDEX_AC].cs_cachep = kmem_cache_create(names[INDEX_AC].name,
65847 sizes[INDEX_AC].cs_size,
65848 ARCH_KMALLOC_MINALIGN,
65849- ARCH_KMALLOC_FLAGS|SLAB_PANIC,
65850+ ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
65851 NULL);
65852
65853 if (INDEX_AC != INDEX_L3) {
65854@@ -1461,7 +1461,7 @@ void __init kmem_cache_init(void)
65855 kmem_cache_create(names[INDEX_L3].name,
65856 sizes[INDEX_L3].cs_size,
65857 ARCH_KMALLOC_MINALIGN,
65858- ARCH_KMALLOC_FLAGS|SLAB_PANIC,
65859+ ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
65860 NULL);
65861 }
65862
65863@@ -1479,7 +1479,7 @@ void __init kmem_cache_init(void)
65864 sizes->cs_cachep = kmem_cache_create(names->name,
65865 sizes->cs_size,
65866 ARCH_KMALLOC_MINALIGN,
65867- ARCH_KMALLOC_FLAGS|SLAB_PANIC,
65868+ ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
65869 NULL);
65870 }
65871 #ifdef CONFIG_ZONE_DMA
65872@@ -4211,10 +4211,10 @@ static int s_show(struct seq_file *m, vo
65873 }
65874 /* cpu stats */
65875 {
65876- unsigned long allochit = atomic_read(&cachep->allochit);
65877- unsigned long allocmiss = atomic_read(&cachep->allocmiss);
65878- unsigned long freehit = atomic_read(&cachep->freehit);
65879- unsigned long freemiss = atomic_read(&cachep->freemiss);
65880+ unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
65881+ unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
65882+ unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
65883+ unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
65884
65885 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
65886 allochit, allocmiss, freehit, freemiss);
65887@@ -4471,15 +4471,66 @@ static const struct file_operations proc
65888
65889 static int __init slab_proc_init(void)
65890 {
65891- proc_create("slabinfo",S_IWUSR|S_IRUGO,NULL,&proc_slabinfo_operations);
65892+ mode_t gr_mode = S_IRUGO;
65893+
65894+#ifdef CONFIG_GRKERNSEC_PROC_ADD
65895+ gr_mode = S_IRUSR;
65896+#endif
65897+
65898+ proc_create("slabinfo",S_IWUSR|gr_mode,NULL,&proc_slabinfo_operations);
65899 #ifdef CONFIG_DEBUG_SLAB_LEAK
65900- proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
65901+ proc_create("slab_allocators", gr_mode, NULL, &proc_slabstats_operations);
65902 #endif
65903 return 0;
65904 }
65905 module_init(slab_proc_init);
65906 #endif
65907
65908+void check_object_size(const void *ptr, unsigned long n, bool to)
65909+{
65910+
65911+#ifdef CONFIG_PAX_USERCOPY
65912+ struct page *page;
65913+ struct kmem_cache *cachep = NULL;
65914+ struct slab *slabp;
65915+ unsigned int objnr;
65916+ unsigned long offset;
65917+
65918+ if (!n)
65919+ return;
65920+
65921+ if (ZERO_OR_NULL_PTR(ptr))
65922+ goto report;
65923+
65924+ if (!virt_addr_valid(ptr))
65925+ return;
65926+
65927+ page = virt_to_head_page(ptr);
65928+
65929+ if (!PageSlab(page)) {
65930+ if (object_is_on_stack(ptr, n) == -1)
65931+ goto report;
65932+ return;
65933+ }
65934+
65935+ cachep = page_get_cache(page);
65936+ if (!(cachep->flags & SLAB_USERCOPY))
65937+ goto report;
65938+
65939+ slabp = page_get_slab(page);
65940+ objnr = obj_to_index(cachep, slabp, ptr);
65941+ BUG_ON(objnr >= cachep->num);
65942+ offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
65943+ if (offset <= obj_size(cachep) && n <= obj_size(cachep) - offset)
65944+ return;
65945+
65946+report:
65947+ pax_report_usercopy(ptr, n, to, cachep ? cachep->name : NULL);
65948+#endif
65949+
65950+}
65951+EXPORT_SYMBOL(check_object_size);
65952+
65953 /**
65954 * ksize - get the actual amount of memory allocated for a given object
65955 * @objp: Pointer to the object
65956diff -urNp linux-2.6.32.41/mm/slob.c linux-2.6.32.41/mm/slob.c
65957--- linux-2.6.32.41/mm/slob.c 2011-03-27 14:31:47.000000000 -0400
65958+++ linux-2.6.32.41/mm/slob.c 2011-04-17 15:56:46.000000000 -0400
65959@@ -29,7 +29,7 @@
65960 * If kmalloc is asked for objects of PAGE_SIZE or larger, it calls
65961 * alloc_pages() directly, allocating compound pages so the page order
65962 * does not have to be separately tracked, and also stores the exact
65963- * allocation size in page->private so that it can be used to accurately
65964+ * allocation size in slob_page->size so that it can be used to accurately
65965 * provide ksize(). These objects are detected in kfree() because slob_page()
65966 * is false for them.
65967 *
65968@@ -58,6 +58,7 @@
65969 */
65970
65971 #include <linux/kernel.h>
65972+#include <linux/sched.h>
65973 #include <linux/slab.h>
65974 #include <linux/mm.h>
65975 #include <linux/swap.h> /* struct reclaim_state */
65976@@ -100,7 +101,8 @@ struct slob_page {
65977 unsigned long flags; /* mandatory */
65978 atomic_t _count; /* mandatory */
65979 slobidx_t units; /* free units left in page */
65980- unsigned long pad[2];
65981+ unsigned long pad[1];
65982+ unsigned long size; /* size when >=PAGE_SIZE */
65983 slob_t *free; /* first free slob_t in page */
65984 struct list_head list; /* linked list of free pages */
65985 };
65986@@ -133,7 +135,7 @@ static LIST_HEAD(free_slob_large);
65987 */
65988 static inline int is_slob_page(struct slob_page *sp)
65989 {
65990- return PageSlab((struct page *)sp);
65991+ return PageSlab((struct page *)sp) && !sp->size;
65992 }
65993
65994 static inline void set_slob_page(struct slob_page *sp)
65995@@ -148,7 +150,7 @@ static inline void clear_slob_page(struc
65996
65997 static inline struct slob_page *slob_page(const void *addr)
65998 {
65999- return (struct slob_page *)virt_to_page(addr);
66000+ return (struct slob_page *)virt_to_head_page(addr);
66001 }
66002
66003 /*
66004@@ -208,7 +210,7 @@ static void set_slob(slob_t *s, slobidx_
66005 /*
66006 * Return the size of a slob block.
66007 */
66008-static slobidx_t slob_units(slob_t *s)
66009+static slobidx_t slob_units(const slob_t *s)
66010 {
66011 if (s->units > 0)
66012 return s->units;
66013@@ -218,7 +220,7 @@ static slobidx_t slob_units(slob_t *s)
66014 /*
66015 * Return the next free slob block pointer after this one.
66016 */
66017-static slob_t *slob_next(slob_t *s)
66018+static slob_t *slob_next(const slob_t *s)
66019 {
66020 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
66021 slobidx_t next;
66022@@ -233,7 +235,7 @@ static slob_t *slob_next(slob_t *s)
66023 /*
66024 * Returns true if s is the last free block in its page.
66025 */
66026-static int slob_last(slob_t *s)
66027+static int slob_last(const slob_t *s)
66028 {
66029 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
66030 }
66031@@ -252,6 +254,7 @@ static void *slob_new_pages(gfp_t gfp, i
66032 if (!page)
66033 return NULL;
66034
66035+ set_slob_page(page);
66036 return page_address(page);
66037 }
66038
66039@@ -368,11 +371,11 @@ static void *slob_alloc(size_t size, gfp
66040 if (!b)
66041 return NULL;
66042 sp = slob_page(b);
66043- set_slob_page(sp);
66044
66045 spin_lock_irqsave(&slob_lock, flags);
66046 sp->units = SLOB_UNITS(PAGE_SIZE);
66047 sp->free = b;
66048+ sp->size = 0;
66049 INIT_LIST_HEAD(&sp->list);
66050 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
66051 set_slob_page_free(sp, slob_list);
66052@@ -475,10 +478,9 @@ out:
66053 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long)
66054 #endif
66055
66056-void *__kmalloc_node(size_t size, gfp_t gfp, int node)
66057+static void *__kmalloc_node_align(size_t size, gfp_t gfp, int node, int align)
66058 {
66059- unsigned int *m;
66060- int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
66061+ slob_t *m;
66062 void *ret;
66063
66064 lockdep_trace_alloc(gfp);
66065@@ -491,7 +493,10 @@ void *__kmalloc_node(size_t size, gfp_t
66066
66067 if (!m)
66068 return NULL;
66069- *m = size;
66070+ BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
66071+ BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
66072+ m[0].units = size;
66073+ m[1].units = align;
66074 ret = (void *)m + align;
66075
66076 trace_kmalloc_node(_RET_IP_, ret,
66077@@ -501,9 +506,9 @@ void *__kmalloc_node(size_t size, gfp_t
66078
66079 ret = slob_new_pages(gfp | __GFP_COMP, get_order(size), node);
66080 if (ret) {
66081- struct page *page;
66082- page = virt_to_page(ret);
66083- page->private = size;
66084+ struct slob_page *sp;
66085+ sp = slob_page(ret);
66086+ sp->size = size;
66087 }
66088
66089 trace_kmalloc_node(_RET_IP_, ret,
66090@@ -513,6 +518,13 @@ void *__kmalloc_node(size_t size, gfp_t
66091 kmemleak_alloc(ret, size, 1, gfp);
66092 return ret;
66093 }
66094+
66095+void *__kmalloc_node(size_t size, gfp_t gfp, int node)
66096+{
66097+ int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
66098+
66099+ return __kmalloc_node_align(size, gfp, node, align);
66100+}
66101 EXPORT_SYMBOL(__kmalloc_node);
66102
66103 void kfree(const void *block)
66104@@ -528,13 +540,81 @@ void kfree(const void *block)
66105 sp = slob_page(block);
66106 if (is_slob_page(sp)) {
66107 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
66108- unsigned int *m = (unsigned int *)(block - align);
66109- slob_free(m, *m + align);
66110- } else
66111+ slob_t *m = (slob_t *)(block - align);
66112+ slob_free(m, m[0].units + align);
66113+ } else {
66114+ clear_slob_page(sp);
66115+ free_slob_page(sp);
66116+ sp->size = 0;
66117 put_page(&sp->page);
66118+ }
66119 }
66120 EXPORT_SYMBOL(kfree);
66121
66122+void check_object_size(const void *ptr, unsigned long n, bool to)
66123+{
66124+
66125+#ifdef CONFIG_PAX_USERCOPY
66126+ struct slob_page *sp;
66127+ const slob_t *free;
66128+ const void *base;
66129+
66130+ if (!n)
66131+ return;
66132+
66133+ if (ZERO_OR_NULL_PTR(ptr))
66134+ goto report;
66135+
66136+ if (!virt_addr_valid(ptr))
66137+ return;
66138+
66139+ sp = slob_page(ptr);
66140+ if (!PageSlab((struct page*)sp)) {
66141+ if (object_is_on_stack(ptr, n) == -1)
66142+ goto report;
66143+ return;
66144+ }
66145+
66146+ if (sp->size) {
66147+ base = page_address(&sp->page);
66148+ if (base <= ptr && n <= sp->size - (ptr - base))
66149+ return;
66150+ goto report;
66151+ }
66152+
66153+ /* some tricky double walking to find the chunk */
66154+ base = (void *)((unsigned long)ptr & PAGE_MASK);
66155+ free = sp->free;
66156+
66157+ while (!slob_last(free) && (void *)free <= ptr) {
66158+ base = free + slob_units(free);
66159+ free = slob_next(free);
66160+ }
66161+
66162+ while (base < (void *)free) {
66163+ slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
66164+ int size = SLOB_UNIT * SLOB_UNITS(m + align);
66165+ int offset;
66166+
66167+ if (ptr < base + align)
66168+ goto report;
66169+
66170+ offset = ptr - base - align;
66171+ if (offset < m) {
66172+ if (n <= m - offset)
66173+ return;
66174+ goto report;
66175+ }
66176+ base += size;
66177+ }
66178+
66179+report:
66180+ pax_report_usercopy(ptr, n, to, NULL);
66181+#endif
66182+
66183+}
66184+EXPORT_SYMBOL(check_object_size);
66185+
66186 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
66187 size_t ksize(const void *block)
66188 {
66189@@ -547,10 +627,10 @@ size_t ksize(const void *block)
66190 sp = slob_page(block);
66191 if (is_slob_page(sp)) {
66192 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
66193- unsigned int *m = (unsigned int *)(block - align);
66194- return SLOB_UNITS(*m) * SLOB_UNIT;
66195+ slob_t *m = (slob_t *)(block - align);
66196+ return SLOB_UNITS(m[0].units) * SLOB_UNIT;
66197 } else
66198- return sp->page.private;
66199+ return sp->size;
66200 }
66201 EXPORT_SYMBOL(ksize);
66202
66203@@ -605,17 +685,25 @@ void *kmem_cache_alloc_node(struct kmem_
66204 {
66205 void *b;
66206
66207+#ifdef CONFIG_PAX_USERCOPY
66208+ b = __kmalloc_node_align(c->size, flags, node, c->align);
66209+#else
66210 if (c->size < PAGE_SIZE) {
66211 b = slob_alloc(c->size, flags, c->align, node);
66212 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
66213 SLOB_UNITS(c->size) * SLOB_UNIT,
66214 flags, node);
66215 } else {
66216+ struct slob_page *sp;
66217+
66218 b = slob_new_pages(flags, get_order(c->size), node);
66219+ sp = slob_page(b);
66220+ sp->size = c->size;
66221 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
66222 PAGE_SIZE << get_order(c->size),
66223 flags, node);
66224 }
66225+#endif
66226
66227 if (c->ctor)
66228 c->ctor(b);
66229@@ -627,10 +715,16 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
66230
66231 static void __kmem_cache_free(void *b, int size)
66232 {
66233- if (size < PAGE_SIZE)
66234+ struct slob_page *sp = slob_page(b);
66235+
66236+ if (is_slob_page(sp))
66237 slob_free(b, size);
66238- else
66239+ else {
66240+ clear_slob_page(sp);
66241+ free_slob_page(sp);
66242+ sp->size = 0;
66243 slob_free_pages(b, get_order(size));
66244+ }
66245 }
66246
66247 static void kmem_rcu_free(struct rcu_head *head)
66248@@ -643,15 +737,24 @@ static void kmem_rcu_free(struct rcu_hea
66249
66250 void kmem_cache_free(struct kmem_cache *c, void *b)
66251 {
66252+ int size = c->size;
66253+
66254+#ifdef CONFIG_PAX_USERCOPY
66255+ if (size + c->align < PAGE_SIZE) {
66256+ size += c->align;
66257+ b -= c->align;
66258+ }
66259+#endif
66260+
66261 kmemleak_free_recursive(b, c->flags);
66262 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
66263 struct slob_rcu *slob_rcu;
66264- slob_rcu = b + (c->size - sizeof(struct slob_rcu));
66265+ slob_rcu = b + (size - sizeof(struct slob_rcu));
66266 INIT_RCU_HEAD(&slob_rcu->head);
66267- slob_rcu->size = c->size;
66268+ slob_rcu->size = size;
66269 call_rcu(&slob_rcu->head, kmem_rcu_free);
66270 } else {
66271- __kmem_cache_free(b, c->size);
66272+ __kmem_cache_free(b, size);
66273 }
66274
66275 trace_kmem_cache_free(_RET_IP_, b);
66276diff -urNp linux-2.6.32.41/mm/slub.c linux-2.6.32.41/mm/slub.c
66277--- linux-2.6.32.41/mm/slub.c 2011-03-27 14:31:47.000000000 -0400
66278+++ linux-2.6.32.41/mm/slub.c 2011-04-17 15:56:46.000000000 -0400
66279@@ -410,7 +410,7 @@ static void print_track(const char *s, s
66280 if (!t->addr)
66281 return;
66282
66283- printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
66284+ printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
66285 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
66286 }
66287
66288@@ -1893,6 +1893,8 @@ void kmem_cache_free(struct kmem_cache *
66289
66290 page = virt_to_head_page(x);
66291
66292+ BUG_ON(!PageSlab(page));
66293+
66294 slab_free(s, page, x, _RET_IP_);
66295
66296 trace_kmem_cache_free(_RET_IP_, x);
66297@@ -1937,7 +1939,7 @@ static int slub_min_objects;
66298 * Merge control. If this is set then no merging of slab caches will occur.
66299 * (Could be removed. This was introduced to pacify the merge skeptics.)
66300 */
66301-static int slub_nomerge;
66302+static int slub_nomerge = 1;
66303
66304 /*
66305 * Calculate the order of allocation given an slab object size.
66306@@ -2493,7 +2495,7 @@ static int kmem_cache_open(struct kmem_c
66307 * list to avoid pounding the page allocator excessively.
66308 */
66309 set_min_partial(s, ilog2(s->size));
66310- s->refcount = 1;
66311+ atomic_set(&s->refcount, 1);
66312 #ifdef CONFIG_NUMA
66313 s->remote_node_defrag_ratio = 1000;
66314 #endif
66315@@ -2630,8 +2632,7 @@ static inline int kmem_cache_close(struc
66316 void kmem_cache_destroy(struct kmem_cache *s)
66317 {
66318 down_write(&slub_lock);
66319- s->refcount--;
66320- if (!s->refcount) {
66321+ if (atomic_dec_and_test(&s->refcount)) {
66322 list_del(&s->list);
66323 up_write(&slub_lock);
66324 if (kmem_cache_close(s)) {
66325@@ -2691,12 +2692,10 @@ static int __init setup_slub_nomerge(cha
66326 __setup("slub_nomerge", setup_slub_nomerge);
66327
66328 static struct kmem_cache *create_kmalloc_cache(struct kmem_cache *s,
66329- const char *name, int size, gfp_t gfp_flags)
66330+ const char *name, int size, gfp_t gfp_flags, unsigned int flags)
66331 {
66332- unsigned int flags = 0;
66333-
66334 if (gfp_flags & SLUB_DMA)
66335- flags = SLAB_CACHE_DMA;
66336+ flags |= SLAB_CACHE_DMA;
66337
66338 /*
66339 * This function is called with IRQs disabled during early-boot on
66340@@ -2915,6 +2914,46 @@ void *__kmalloc_node(size_t size, gfp_t
66341 EXPORT_SYMBOL(__kmalloc_node);
66342 #endif
66343
66344+void check_object_size(const void *ptr, unsigned long n, bool to)
66345+{
66346+
66347+#ifdef CONFIG_PAX_USERCOPY
66348+ struct page *page;
66349+ struct kmem_cache *s = NULL;
66350+ unsigned long offset;
66351+
66352+ if (!n)
66353+ return;
66354+
66355+ if (ZERO_OR_NULL_PTR(ptr))
66356+ goto report;
66357+
66358+ if (!virt_addr_valid(ptr))
66359+ return;
66360+
66361+ page = get_object_page(ptr);
66362+
66363+ if (!page) {
66364+ if (object_is_on_stack(ptr, n) == -1)
66365+ goto report;
66366+ return;
66367+ }
66368+
66369+ s = page->slab;
66370+ if (!(s->flags & SLAB_USERCOPY))
66371+ goto report;
66372+
66373+ offset = (ptr - page_address(page)) % s->size;
66374+ if (offset <= s->objsize && n <= s->objsize - offset)
66375+ return;
66376+
66377+report:
66378+ pax_report_usercopy(ptr, n, to, s ? s->name : NULL);
66379+#endif
66380+
66381+}
66382+EXPORT_SYMBOL(check_object_size);
66383+
66384 size_t ksize(const void *object)
66385 {
66386 struct page *page;
66387@@ -3185,8 +3224,8 @@ void __init kmem_cache_init(void)
66388 * kmem_cache_open for slab_state == DOWN.
66389 */
66390 create_kmalloc_cache(&kmalloc_caches[0], "kmem_cache_node",
66391- sizeof(struct kmem_cache_node), GFP_NOWAIT);
66392- kmalloc_caches[0].refcount = -1;
66393+ sizeof(struct kmem_cache_node), GFP_NOWAIT, 0);
66394+ atomic_set(&kmalloc_caches[0].refcount, -1);
66395 caches++;
66396
66397 hotplug_memory_notifier(slab_memory_callback, SLAB_CALLBACK_PRI);
66398@@ -3198,18 +3237,18 @@ void __init kmem_cache_init(void)
66399 /* Caches that are not of the two-to-the-power-of size */
66400 if (KMALLOC_MIN_SIZE <= 32) {
66401 create_kmalloc_cache(&kmalloc_caches[1],
66402- "kmalloc-96", 96, GFP_NOWAIT);
66403+ "kmalloc-96", 96, GFP_NOWAIT, SLAB_USERCOPY);
66404 caches++;
66405 }
66406 if (KMALLOC_MIN_SIZE <= 64) {
66407 create_kmalloc_cache(&kmalloc_caches[2],
66408- "kmalloc-192", 192, GFP_NOWAIT);
66409+ "kmalloc-192", 192, GFP_NOWAIT, SLAB_USERCOPY);
66410 caches++;
66411 }
66412
66413 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
66414 create_kmalloc_cache(&kmalloc_caches[i],
66415- "kmalloc", 1 << i, GFP_NOWAIT);
66416+ "kmalloc", 1 << i, GFP_NOWAIT, SLAB_USERCOPY);
66417 caches++;
66418 }
66419
66420@@ -3293,7 +3332,7 @@ static int slab_unmergeable(struct kmem_
66421 /*
66422 * We may have set a slab to be unmergeable during bootstrap.
66423 */
66424- if (s->refcount < 0)
66425+ if (atomic_read(&s->refcount) < 0)
66426 return 1;
66427
66428 return 0;
66429@@ -3353,7 +3392,7 @@ struct kmem_cache *kmem_cache_create(con
66430 if (s) {
66431 int cpu;
66432
66433- s->refcount++;
66434+ atomic_inc(&s->refcount);
66435 /*
66436 * Adjust the object sizes so that we clear
66437 * the complete object on kzalloc.
66438@@ -3372,7 +3411,7 @@ struct kmem_cache *kmem_cache_create(con
66439
66440 if (sysfs_slab_alias(s, name)) {
66441 down_write(&slub_lock);
66442- s->refcount--;
66443+ atomic_dec(&s->refcount);
66444 up_write(&slub_lock);
66445 goto err;
66446 }
66447@@ -4101,7 +4140,7 @@ SLAB_ATTR_RO(ctor);
66448
66449 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
66450 {
66451- return sprintf(buf, "%d\n", s->refcount - 1);
66452+ return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
66453 }
66454 SLAB_ATTR_RO(aliases);
66455
66456@@ -4503,7 +4542,7 @@ static void kmem_cache_release(struct ko
66457 kfree(s);
66458 }
66459
66460-static struct sysfs_ops slab_sysfs_ops = {
66461+static const struct sysfs_ops slab_sysfs_ops = {
66462 .show = slab_attr_show,
66463 .store = slab_attr_store,
66464 };
66465@@ -4522,7 +4561,7 @@ static int uevent_filter(struct kset *ks
66466 return 0;
66467 }
66468
66469-static struct kset_uevent_ops slab_uevent_ops = {
66470+static const struct kset_uevent_ops slab_uevent_ops = {
66471 .filter = uevent_filter,
66472 };
66473
66474@@ -4785,7 +4824,13 @@ static const struct file_operations proc
66475
66476 static int __init slab_proc_init(void)
66477 {
66478- proc_create("slabinfo", S_IRUGO, NULL, &proc_slabinfo_operations);
66479+ mode_t gr_mode = S_IRUGO;
66480+
66481+#ifdef CONFIG_GRKERNSEC_PROC_ADD
66482+ gr_mode = S_IRUSR;
66483+#endif
66484+
66485+ proc_create("slabinfo", gr_mode, NULL, &proc_slabinfo_operations);
66486 return 0;
66487 }
66488 module_init(slab_proc_init);
66489diff -urNp linux-2.6.32.41/mm/util.c linux-2.6.32.41/mm/util.c
66490--- linux-2.6.32.41/mm/util.c 2011-03-27 14:31:47.000000000 -0400
66491+++ linux-2.6.32.41/mm/util.c 2011-04-17 15:56:46.000000000 -0400
66492@@ -228,6 +228,12 @@ EXPORT_SYMBOL(strndup_user);
66493 void arch_pick_mmap_layout(struct mm_struct *mm)
66494 {
66495 mm->mmap_base = TASK_UNMAPPED_BASE;
66496+
66497+#ifdef CONFIG_PAX_RANDMMAP
66498+ if (mm->pax_flags & MF_PAX_RANDMMAP)
66499+ mm->mmap_base += mm->delta_mmap;
66500+#endif
66501+
66502 mm->get_unmapped_area = arch_get_unmapped_area;
66503 mm->unmap_area = arch_unmap_area;
66504 }
66505diff -urNp linux-2.6.32.41/mm/vmalloc.c linux-2.6.32.41/mm/vmalloc.c
66506--- linux-2.6.32.41/mm/vmalloc.c 2011-03-27 14:31:47.000000000 -0400
66507+++ linux-2.6.32.41/mm/vmalloc.c 2011-04-17 15:56:46.000000000 -0400
66508@@ -40,8 +40,19 @@ static void vunmap_pte_range(pmd_t *pmd,
66509
66510 pte = pte_offset_kernel(pmd, addr);
66511 do {
66512- pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
66513- WARN_ON(!pte_none(ptent) && !pte_present(ptent));
66514+
66515+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
66516+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
66517+ BUG_ON(!pte_exec(*pte));
66518+ set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
66519+ continue;
66520+ }
66521+#endif
66522+
66523+ {
66524+ pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
66525+ WARN_ON(!pte_none(ptent) && !pte_present(ptent));
66526+ }
66527 } while (pte++, addr += PAGE_SIZE, addr != end);
66528 }
66529
66530@@ -92,6 +103,7 @@ static int vmap_pte_range(pmd_t *pmd, un
66531 unsigned long end, pgprot_t prot, struct page **pages, int *nr)
66532 {
66533 pte_t *pte;
66534+ int ret = -ENOMEM;
66535
66536 /*
66537 * nr is a running index into the array which helps higher level
66538@@ -101,17 +113,32 @@ static int vmap_pte_range(pmd_t *pmd, un
66539 pte = pte_alloc_kernel(pmd, addr);
66540 if (!pte)
66541 return -ENOMEM;
66542+
66543+ pax_open_kernel();
66544 do {
66545 struct page *page = pages[*nr];
66546
66547- if (WARN_ON(!pte_none(*pte)))
66548- return -EBUSY;
66549- if (WARN_ON(!page))
66550- return -ENOMEM;
66551+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
66552+ if (!(pgprot_val(prot) & _PAGE_NX))
66553+ BUG_ON(!pte_exec(*pte) || pte_pfn(*pte) != __pa(addr) >> PAGE_SHIFT);
66554+ else
66555+#endif
66556+
66557+ if (WARN_ON(!pte_none(*pte))) {
66558+ ret = -EBUSY;
66559+ goto out;
66560+ }
66561+ if (WARN_ON(!page)) {
66562+ ret = -ENOMEM;
66563+ goto out;
66564+ }
66565 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
66566 (*nr)++;
66567 } while (pte++, addr += PAGE_SIZE, addr != end);
66568- return 0;
66569+ ret = 0;
66570+out:
66571+ pax_close_kernel();
66572+ return ret;
66573 }
66574
66575 static int vmap_pmd_range(pud_t *pud, unsigned long addr,
66576@@ -192,11 +219,20 @@ int is_vmalloc_or_module_addr(const void
66577 * and fall back on vmalloc() if that fails. Others
66578 * just put it in the vmalloc space.
66579 */
66580-#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
66581+#ifdef CONFIG_MODULES
66582+#ifdef MODULES_VADDR
66583 unsigned long addr = (unsigned long)x;
66584 if (addr >= MODULES_VADDR && addr < MODULES_END)
66585 return 1;
66586 #endif
66587+
66588+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
66589+ if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
66590+ return 1;
66591+#endif
66592+
66593+#endif
66594+
66595 return is_vmalloc_addr(x);
66596 }
66597
66598@@ -217,8 +253,14 @@ struct page *vmalloc_to_page(const void
66599
66600 if (!pgd_none(*pgd)) {
66601 pud_t *pud = pud_offset(pgd, addr);
66602+#ifdef CONFIG_X86
66603+ if (!pud_large(*pud))
66604+#endif
66605 if (!pud_none(*pud)) {
66606 pmd_t *pmd = pmd_offset(pud, addr);
66607+#ifdef CONFIG_X86
66608+ if (!pmd_large(*pmd))
66609+#endif
66610 if (!pmd_none(*pmd)) {
66611 pte_t *ptep, pte;
66612
66613@@ -292,13 +334,13 @@ static void __insert_vmap_area(struct vm
66614 struct rb_node *tmp;
66615
66616 while (*p) {
66617- struct vmap_area *tmp;
66618+ struct vmap_area *varea;
66619
66620 parent = *p;
66621- tmp = rb_entry(parent, struct vmap_area, rb_node);
66622- if (va->va_start < tmp->va_end)
66623+ varea = rb_entry(parent, struct vmap_area, rb_node);
66624+ if (va->va_start < varea->va_end)
66625 p = &(*p)->rb_left;
66626- else if (va->va_end > tmp->va_start)
66627+ else if (va->va_end > varea->va_start)
66628 p = &(*p)->rb_right;
66629 else
66630 BUG();
66631@@ -1232,6 +1274,16 @@ static struct vm_struct *__get_vm_area_n
66632 struct vm_struct *area;
66633
66634 BUG_ON(in_interrupt());
66635+
66636+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
66637+ if (flags & VM_KERNEXEC) {
66638+ if (start != VMALLOC_START || end != VMALLOC_END)
66639+ return NULL;
66640+ start = (unsigned long)MODULES_EXEC_VADDR;
66641+ end = (unsigned long)MODULES_EXEC_END;
66642+ }
66643+#endif
66644+
66645 if (flags & VM_IOREMAP) {
66646 int bit = fls(size);
66647
66648@@ -1457,6 +1509,11 @@ void *vmap(struct page **pages, unsigned
66649 if (count > totalram_pages)
66650 return NULL;
66651
66652+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
66653+ if (!(pgprot_val(prot) & _PAGE_NX))
66654+ flags |= VM_KERNEXEC;
66655+#endif
66656+
66657 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
66658 __builtin_return_address(0));
66659 if (!area)
66660@@ -1567,6 +1624,13 @@ static void *__vmalloc_node(unsigned lon
66661 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
66662 return NULL;
66663
66664+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
66665+ if (!(pgprot_val(prot) & _PAGE_NX))
66666+ area = __get_vm_area_node(size, align, VM_ALLOC | VM_KERNEXEC, VMALLOC_START, VMALLOC_END,
66667+ node, gfp_mask, caller);
66668+ else
66669+#endif
66670+
66671 area = __get_vm_area_node(size, align, VM_ALLOC, VMALLOC_START,
66672 VMALLOC_END, node, gfp_mask, caller);
66673
66674@@ -1585,6 +1649,7 @@ static void *__vmalloc_node(unsigned lon
66675 return addr;
66676 }
66677
66678+#undef __vmalloc
66679 void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot)
66680 {
66681 return __vmalloc_node(size, 1, gfp_mask, prot, -1,
66682@@ -1601,6 +1666,7 @@ EXPORT_SYMBOL(__vmalloc);
66683 * For tight control over page level allocator and protection flags
66684 * use __vmalloc() instead.
66685 */
66686+#undef vmalloc
66687 void *vmalloc(unsigned long size)
66688 {
66689 return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL,
66690@@ -1615,6 +1681,7 @@ EXPORT_SYMBOL(vmalloc);
66691 * The resulting memory area is zeroed so it can be mapped to userspace
66692 * without leaking data.
66693 */
66694+#undef vmalloc_user
66695 void *vmalloc_user(unsigned long size)
66696 {
66697 struct vm_struct *area;
66698@@ -1642,6 +1709,7 @@ EXPORT_SYMBOL(vmalloc_user);
66699 * For tight control over page level allocator and protection flags
66700 * use __vmalloc() instead.
66701 */
66702+#undef vmalloc_node
66703 void *vmalloc_node(unsigned long size, int node)
66704 {
66705 return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL,
66706@@ -1664,10 +1732,10 @@ EXPORT_SYMBOL(vmalloc_node);
66707 * For tight control over page level allocator and protection flags
66708 * use __vmalloc() instead.
66709 */
66710-
66711+#undef vmalloc_exec
66712 void *vmalloc_exec(unsigned long size)
66713 {
66714- return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
66715+ return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
66716 -1, __builtin_return_address(0));
66717 }
66718
66719@@ -1686,6 +1754,7 @@ void *vmalloc_exec(unsigned long size)
66720 * Allocate enough 32bit PA addressable pages to cover @size from the
66721 * page level allocator and map them into contiguous kernel virtual space.
66722 */
66723+#undef vmalloc_32
66724 void *vmalloc_32(unsigned long size)
66725 {
66726 return __vmalloc_node(size, 1, GFP_VMALLOC32, PAGE_KERNEL,
66727@@ -1700,6 +1769,7 @@ EXPORT_SYMBOL(vmalloc_32);
66728 * The resulting memory area is 32bit addressable and zeroed so it can be
66729 * mapped to userspace without leaking data.
66730 */
66731+#undef vmalloc_32_user
66732 void *vmalloc_32_user(unsigned long size)
66733 {
66734 struct vm_struct *area;
66735@@ -1964,6 +2034,8 @@ int remap_vmalloc_range(struct vm_area_s
66736 unsigned long uaddr = vma->vm_start;
66737 unsigned long usize = vma->vm_end - vma->vm_start;
66738
66739+ BUG_ON(vma->vm_mirror);
66740+
66741 if ((PAGE_SIZE-1) & (unsigned long)addr)
66742 return -EINVAL;
66743
66744diff -urNp linux-2.6.32.41/mm/vmstat.c linux-2.6.32.41/mm/vmstat.c
66745--- linux-2.6.32.41/mm/vmstat.c 2011-03-27 14:31:47.000000000 -0400
66746+++ linux-2.6.32.41/mm/vmstat.c 2011-04-17 15:56:46.000000000 -0400
66747@@ -74,7 +74,7 @@ void vm_events_fold_cpu(int cpu)
66748 *
66749 * vm_stat contains the global counters
66750 */
66751-atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
66752+atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
66753 EXPORT_SYMBOL(vm_stat);
66754
66755 #ifdef CONFIG_SMP
66756@@ -324,7 +324,7 @@ void refresh_cpu_vm_stats(int cpu)
66757 v = p->vm_stat_diff[i];
66758 p->vm_stat_diff[i] = 0;
66759 local_irq_restore(flags);
66760- atomic_long_add(v, &zone->vm_stat[i]);
66761+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
66762 global_diff[i] += v;
66763 #ifdef CONFIG_NUMA
66764 /* 3 seconds idle till flush */
66765@@ -362,7 +362,7 @@ void refresh_cpu_vm_stats(int cpu)
66766
66767 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
66768 if (global_diff[i])
66769- atomic_long_add(global_diff[i], &vm_stat[i]);
66770+ atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
66771 }
66772
66773 #endif
66774@@ -953,10 +953,20 @@ static int __init setup_vmstat(void)
66775 start_cpu_timer(cpu);
66776 #endif
66777 #ifdef CONFIG_PROC_FS
66778- proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
66779- proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
66780- proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
66781- proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
66782+ {
66783+ mode_t gr_mode = S_IRUGO;
66784+#ifdef CONFIG_GRKERNSEC_PROC_ADD
66785+ gr_mode = S_IRUSR;
66786+#endif
66787+ proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
66788+ proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
66789+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
66790+ proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
66791+#else
66792+ proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
66793+#endif
66794+ proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
66795+ }
66796 #endif
66797 return 0;
66798 }
66799diff -urNp linux-2.6.32.41/net/8021q/vlan.c linux-2.6.32.41/net/8021q/vlan.c
66800--- linux-2.6.32.41/net/8021q/vlan.c 2011-03-27 14:31:47.000000000 -0400
66801+++ linux-2.6.32.41/net/8021q/vlan.c 2011-04-17 15:56:46.000000000 -0400
66802@@ -622,8 +622,7 @@ static int vlan_ioctl_handler(struct net
66803 err = -EPERM;
66804 if (!capable(CAP_NET_ADMIN))
66805 break;
66806- if ((args.u.name_type >= 0) &&
66807- (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
66808+ if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
66809 struct vlan_net *vn;
66810
66811 vn = net_generic(net, vlan_net_id);
66812diff -urNp linux-2.6.32.41/net/atm/atm_misc.c linux-2.6.32.41/net/atm/atm_misc.c
66813--- linux-2.6.32.41/net/atm/atm_misc.c 2011-03-27 14:31:47.000000000 -0400
66814+++ linux-2.6.32.41/net/atm/atm_misc.c 2011-04-17 15:56:46.000000000 -0400
66815@@ -19,7 +19,7 @@ int atm_charge(struct atm_vcc *vcc,int t
66816 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
66817 return 1;
66818 atm_return(vcc,truesize);
66819- atomic_inc(&vcc->stats->rx_drop);
66820+ atomic_inc_unchecked(&vcc->stats->rx_drop);
66821 return 0;
66822 }
66823
66824@@ -41,7 +41,7 @@ struct sk_buff *atm_alloc_charge(struct
66825 }
66826 }
66827 atm_return(vcc,guess);
66828- atomic_inc(&vcc->stats->rx_drop);
66829+ atomic_inc_unchecked(&vcc->stats->rx_drop);
66830 return NULL;
66831 }
66832
66833@@ -88,7 +88,7 @@ int atm_pcr_goal(const struct atm_trafpr
66834
66835 void sonet_copy_stats(struct k_sonet_stats *from,struct sonet_stats *to)
66836 {
66837-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
66838+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
66839 __SONET_ITEMS
66840 #undef __HANDLE_ITEM
66841 }
66842@@ -96,7 +96,7 @@ void sonet_copy_stats(struct k_sonet_sta
66843
66844 void sonet_subtract_stats(struct k_sonet_stats *from,struct sonet_stats *to)
66845 {
66846-#define __HANDLE_ITEM(i) atomic_sub(to->i,&from->i)
66847+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
66848 __SONET_ITEMS
66849 #undef __HANDLE_ITEM
66850 }
66851diff -urNp linux-2.6.32.41/net/atm/mpoa_caches.c linux-2.6.32.41/net/atm/mpoa_caches.c
66852--- linux-2.6.32.41/net/atm/mpoa_caches.c 2011-03-27 14:31:47.000000000 -0400
66853+++ linux-2.6.32.41/net/atm/mpoa_caches.c 2011-05-16 21:46:57.000000000 -0400
66854@@ -498,6 +498,8 @@ static void clear_expired(struct mpoa_cl
66855 struct timeval now;
66856 struct k_message msg;
66857
66858+ pax_track_stack();
66859+
66860 do_gettimeofday(&now);
66861
66862 write_lock_irq(&client->egress_lock);
66863diff -urNp linux-2.6.32.41/net/atm/proc.c linux-2.6.32.41/net/atm/proc.c
66864--- linux-2.6.32.41/net/atm/proc.c 2011-03-27 14:31:47.000000000 -0400
66865+++ linux-2.6.32.41/net/atm/proc.c 2011-04-17 15:56:46.000000000 -0400
66866@@ -43,9 +43,9 @@ static void add_stats(struct seq_file *s
66867 const struct k_atm_aal_stats *stats)
66868 {
66869 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
66870- atomic_read(&stats->tx),atomic_read(&stats->tx_err),
66871- atomic_read(&stats->rx),atomic_read(&stats->rx_err),
66872- atomic_read(&stats->rx_drop));
66873+ atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
66874+ atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
66875+ atomic_read_unchecked(&stats->rx_drop));
66876 }
66877
66878 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
66879@@ -188,7 +188,12 @@ static void vcc_info(struct seq_file *se
66880 {
66881 struct sock *sk = sk_atm(vcc);
66882
66883+#ifdef CONFIG_GRKERNSEC_HIDESYM
66884+ seq_printf(seq, "%p ", NULL);
66885+#else
66886 seq_printf(seq, "%p ", vcc);
66887+#endif
66888+
66889 if (!vcc->dev)
66890 seq_printf(seq, "Unassigned ");
66891 else
66892@@ -214,7 +219,11 @@ static void svc_info(struct seq_file *se
66893 {
66894 if (!vcc->dev)
66895 seq_printf(seq, sizeof(void *) == 4 ?
66896+#ifdef CONFIG_GRKERNSEC_HIDESYM
66897+ "N/A@%p%10s" : "N/A@%p%2s", NULL, "");
66898+#else
66899 "N/A@%p%10s" : "N/A@%p%2s", vcc, "");
66900+#endif
66901 else
66902 seq_printf(seq, "%3d %3d %5d ",
66903 vcc->dev->number, vcc->vpi, vcc->vci);
66904diff -urNp linux-2.6.32.41/net/atm/resources.c linux-2.6.32.41/net/atm/resources.c
66905--- linux-2.6.32.41/net/atm/resources.c 2011-03-27 14:31:47.000000000 -0400
66906+++ linux-2.6.32.41/net/atm/resources.c 2011-04-17 15:56:46.000000000 -0400
66907@@ -161,7 +161,7 @@ void atm_dev_deregister(struct atm_dev *
66908 static void copy_aal_stats(struct k_atm_aal_stats *from,
66909 struct atm_aal_stats *to)
66910 {
66911-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
66912+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
66913 __AAL_STAT_ITEMS
66914 #undef __HANDLE_ITEM
66915 }
66916@@ -170,7 +170,7 @@ static void copy_aal_stats(struct k_atm_
66917 static void subtract_aal_stats(struct k_atm_aal_stats *from,
66918 struct atm_aal_stats *to)
66919 {
66920-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
66921+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
66922 __AAL_STAT_ITEMS
66923 #undef __HANDLE_ITEM
66924 }
66925diff -urNp linux-2.6.32.41/net/bridge/br_private.h linux-2.6.32.41/net/bridge/br_private.h
66926--- linux-2.6.32.41/net/bridge/br_private.h 2011-03-27 14:31:47.000000000 -0400
66927+++ linux-2.6.32.41/net/bridge/br_private.h 2011-04-17 15:56:46.000000000 -0400
66928@@ -254,7 +254,7 @@ extern void br_ifinfo_notify(int event,
66929
66930 #ifdef CONFIG_SYSFS
66931 /* br_sysfs_if.c */
66932-extern struct sysfs_ops brport_sysfs_ops;
66933+extern const struct sysfs_ops brport_sysfs_ops;
66934 extern int br_sysfs_addif(struct net_bridge_port *p);
66935
66936 /* br_sysfs_br.c */
66937diff -urNp linux-2.6.32.41/net/bridge/br_stp_if.c linux-2.6.32.41/net/bridge/br_stp_if.c
66938--- linux-2.6.32.41/net/bridge/br_stp_if.c 2011-03-27 14:31:47.000000000 -0400
66939+++ linux-2.6.32.41/net/bridge/br_stp_if.c 2011-04-17 15:56:46.000000000 -0400
66940@@ -146,7 +146,7 @@ static void br_stp_stop(struct net_bridg
66941 char *envp[] = { NULL };
66942
66943 if (br->stp_enabled == BR_USER_STP) {
66944- r = call_usermodehelper(BR_STP_PROG, argv, envp, 1);
66945+ r = call_usermodehelper(BR_STP_PROG, argv, envp, UMH_WAIT_PROC);
66946 printk(KERN_INFO "%s: userspace STP stopped, return code %d\n",
66947 br->dev->name, r);
66948
66949diff -urNp linux-2.6.32.41/net/bridge/br_sysfs_if.c linux-2.6.32.41/net/bridge/br_sysfs_if.c
66950--- linux-2.6.32.41/net/bridge/br_sysfs_if.c 2011-03-27 14:31:47.000000000 -0400
66951+++ linux-2.6.32.41/net/bridge/br_sysfs_if.c 2011-04-17 15:56:46.000000000 -0400
66952@@ -220,7 +220,7 @@ static ssize_t brport_store(struct kobje
66953 return ret;
66954 }
66955
66956-struct sysfs_ops brport_sysfs_ops = {
66957+const struct sysfs_ops brport_sysfs_ops = {
66958 .show = brport_show,
66959 .store = brport_store,
66960 };
66961diff -urNp linux-2.6.32.41/net/bridge/netfilter/ebtables.c linux-2.6.32.41/net/bridge/netfilter/ebtables.c
66962--- linux-2.6.32.41/net/bridge/netfilter/ebtables.c 2011-04-17 17:00:52.000000000 -0400
66963+++ linux-2.6.32.41/net/bridge/netfilter/ebtables.c 2011-05-16 21:46:57.000000000 -0400
66964@@ -1337,6 +1337,8 @@ static int copy_everything_to_user(struc
66965 unsigned int entries_size, nentries;
66966 char *entries;
66967
66968+ pax_track_stack();
66969+
66970 if (cmd == EBT_SO_GET_ENTRIES) {
66971 entries_size = t->private->entries_size;
66972 nentries = t->private->nentries;
66973diff -urNp linux-2.6.32.41/net/can/bcm.c linux-2.6.32.41/net/can/bcm.c
66974--- linux-2.6.32.41/net/can/bcm.c 2011-05-10 22:12:01.000000000 -0400
66975+++ linux-2.6.32.41/net/can/bcm.c 2011-05-10 22:12:34.000000000 -0400
66976@@ -164,9 +164,15 @@ static int bcm_proc_show(struct seq_file
66977 struct bcm_sock *bo = bcm_sk(sk);
66978 struct bcm_op *op;
66979
66980+#ifdef CONFIG_GRKERNSEC_HIDESYM
66981+ seq_printf(m, ">>> socket %p", NULL);
66982+ seq_printf(m, " / sk %p", NULL);
66983+ seq_printf(m, " / bo %p", NULL);
66984+#else
66985 seq_printf(m, ">>> socket %p", sk->sk_socket);
66986 seq_printf(m, " / sk %p", sk);
66987 seq_printf(m, " / bo %p", bo);
66988+#endif
66989 seq_printf(m, " / dropped %lu", bo->dropped_usr_msgs);
66990 seq_printf(m, " / bound %s", bcm_proc_getifname(ifname, bo->ifindex));
66991 seq_printf(m, " <<<\n");
66992diff -urNp linux-2.6.32.41/net/core/dev.c linux-2.6.32.41/net/core/dev.c
66993--- linux-2.6.32.41/net/core/dev.c 2011-04-17 17:00:52.000000000 -0400
66994+++ linux-2.6.32.41/net/core/dev.c 2011-04-17 17:04:18.000000000 -0400
66995@@ -1047,10 +1047,14 @@ void dev_load(struct net *net, const cha
66996 if (no_module && capable(CAP_NET_ADMIN))
66997 no_module = request_module("netdev-%s", name);
66998 if (no_module && capable(CAP_SYS_MODULE)) {
66999+#ifdef CONFIG_GRKERNSEC_MODHARDEN
67000+ ___request_module(true, "grsec_modharden_netdev", "%s", name);
67001+#else
67002 if (!request_module("%s", name))
67003 pr_err("Loading kernel module for a network device "
67004 "with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s "
67005 "instead\n", name);
67006+#endif
67007 }
67008 }
67009 EXPORT_SYMBOL(dev_load);
67010@@ -2063,7 +2067,7 @@ int netif_rx_ni(struct sk_buff *skb)
67011 }
67012 EXPORT_SYMBOL(netif_rx_ni);
67013
67014-static void net_tx_action(struct softirq_action *h)
67015+static void net_tx_action(void)
67016 {
67017 struct softnet_data *sd = &__get_cpu_var(softnet_data);
67018
67019@@ -2826,7 +2830,7 @@ void netif_napi_del(struct napi_struct *
67020 EXPORT_SYMBOL(netif_napi_del);
67021
67022
67023-static void net_rx_action(struct softirq_action *h)
67024+static void net_rx_action(void)
67025 {
67026 struct list_head *list = &__get_cpu_var(softnet_data).poll_list;
67027 unsigned long time_limit = jiffies + 2;
67028diff -urNp linux-2.6.32.41/net/core/flow.c linux-2.6.32.41/net/core/flow.c
67029--- linux-2.6.32.41/net/core/flow.c 2011-03-27 14:31:47.000000000 -0400
67030+++ linux-2.6.32.41/net/core/flow.c 2011-05-04 17:56:20.000000000 -0400
67031@@ -35,11 +35,11 @@ struct flow_cache_entry {
67032 atomic_t *object_ref;
67033 };
67034
67035-atomic_t flow_cache_genid = ATOMIC_INIT(0);
67036+atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
67037
67038 static u32 flow_hash_shift;
67039 #define flow_hash_size (1 << flow_hash_shift)
67040-static DEFINE_PER_CPU(struct flow_cache_entry **, flow_tables) = { NULL };
67041+static DEFINE_PER_CPU(struct flow_cache_entry **, flow_tables);
67042
67043 #define flow_table(cpu) (per_cpu(flow_tables, cpu))
67044
67045@@ -52,7 +52,7 @@ struct flow_percpu_info {
67046 u32 hash_rnd;
67047 int count;
67048 };
67049-static DEFINE_PER_CPU(struct flow_percpu_info, flow_hash_info) = { 0 };
67050+static DEFINE_PER_CPU(struct flow_percpu_info, flow_hash_info);
67051
67052 #define flow_hash_rnd_recalc(cpu) \
67053 (per_cpu(flow_hash_info, cpu).hash_rnd_recalc)
67054@@ -69,7 +69,7 @@ struct flow_flush_info {
67055 atomic_t cpuleft;
67056 struct completion completion;
67057 };
67058-static DEFINE_PER_CPU(struct tasklet_struct, flow_flush_tasklets) = { NULL };
67059+static DEFINE_PER_CPU(struct tasklet_struct, flow_flush_tasklets);
67060
67061 #define flow_flush_tasklet(cpu) (&per_cpu(flow_flush_tasklets, cpu))
67062
67063@@ -190,7 +190,7 @@ void *flow_cache_lookup(struct net *net,
67064 if (fle->family == family &&
67065 fle->dir == dir &&
67066 flow_key_compare(key, &fle->key) == 0) {
67067- if (fle->genid == atomic_read(&flow_cache_genid)) {
67068+ if (fle->genid == atomic_read_unchecked(&flow_cache_genid)) {
67069 void *ret = fle->object;
67070
67071 if (ret)
67072@@ -228,7 +228,7 @@ nocache:
67073 err = resolver(net, key, family, dir, &obj, &obj_ref);
67074
67075 if (fle && !err) {
67076- fle->genid = atomic_read(&flow_cache_genid);
67077+ fle->genid = atomic_read_unchecked(&flow_cache_genid);
67078
67079 if (fle->object)
67080 atomic_dec(fle->object_ref);
67081@@ -258,7 +258,7 @@ static void flow_cache_flush_tasklet(uns
67082
67083 fle = flow_table(cpu)[i];
67084 for (; fle; fle = fle->next) {
67085- unsigned genid = atomic_read(&flow_cache_genid);
67086+ unsigned genid = atomic_read_unchecked(&flow_cache_genid);
67087
67088 if (!fle->object || fle->genid == genid)
67089 continue;
67090diff -urNp linux-2.6.32.41/net/core/skbuff.c linux-2.6.32.41/net/core/skbuff.c
67091--- linux-2.6.32.41/net/core/skbuff.c 2011-03-27 14:31:47.000000000 -0400
67092+++ linux-2.6.32.41/net/core/skbuff.c 2011-05-16 21:46:57.000000000 -0400
67093@@ -1544,6 +1544,8 @@ int skb_splice_bits(struct sk_buff *skb,
67094 struct sk_buff *frag_iter;
67095 struct sock *sk = skb->sk;
67096
67097+ pax_track_stack();
67098+
67099 /*
67100 * __skb_splice_bits() only fails if the output has no room left,
67101 * so no point in going over the frag_list for the error case.
67102diff -urNp linux-2.6.32.41/net/core/sock.c linux-2.6.32.41/net/core/sock.c
67103--- linux-2.6.32.41/net/core/sock.c 2011-03-27 14:31:47.000000000 -0400
67104+++ linux-2.6.32.41/net/core/sock.c 2011-05-04 17:56:20.000000000 -0400
67105@@ -864,11 +864,15 @@ int sock_getsockopt(struct socket *sock,
67106 break;
67107
67108 case SO_PEERCRED:
67109+ {
67110+ struct ucred peercred;
67111 if (len > sizeof(sk->sk_peercred))
67112 len = sizeof(sk->sk_peercred);
67113- if (copy_to_user(optval, &sk->sk_peercred, len))
67114+ peercred = sk->sk_peercred;
67115+ if (copy_to_user(optval, &peercred, len))
67116 return -EFAULT;
67117 goto lenout;
67118+ }
67119
67120 case SO_PEERNAME:
67121 {
67122@@ -1892,7 +1896,7 @@ void sock_init_data(struct socket *sock,
67123 */
67124 smp_wmb();
67125 atomic_set(&sk->sk_refcnt, 1);
67126- atomic_set(&sk->sk_drops, 0);
67127+ atomic_set_unchecked(&sk->sk_drops, 0);
67128 }
67129 EXPORT_SYMBOL(sock_init_data);
67130
67131diff -urNp linux-2.6.32.41/net/decnet/sysctl_net_decnet.c linux-2.6.32.41/net/decnet/sysctl_net_decnet.c
67132--- linux-2.6.32.41/net/decnet/sysctl_net_decnet.c 2011-03-27 14:31:47.000000000 -0400
67133+++ linux-2.6.32.41/net/decnet/sysctl_net_decnet.c 2011-04-17 15:56:46.000000000 -0400
67134@@ -206,7 +206,7 @@ static int dn_node_address_handler(ctl_t
67135
67136 if (len > *lenp) len = *lenp;
67137
67138- if (copy_to_user(buffer, addr, len))
67139+ if (len > sizeof addr || copy_to_user(buffer, addr, len))
67140 return -EFAULT;
67141
67142 *lenp = len;
67143@@ -327,7 +327,7 @@ static int dn_def_dev_handler(ctl_table
67144
67145 if (len > *lenp) len = *lenp;
67146
67147- if (copy_to_user(buffer, devname, len))
67148+ if (len > sizeof devname || copy_to_user(buffer, devname, len))
67149 return -EFAULT;
67150
67151 *lenp = len;
67152diff -urNp linux-2.6.32.41/net/econet/Kconfig linux-2.6.32.41/net/econet/Kconfig
67153--- linux-2.6.32.41/net/econet/Kconfig 2011-03-27 14:31:47.000000000 -0400
67154+++ linux-2.6.32.41/net/econet/Kconfig 2011-04-17 15:56:46.000000000 -0400
67155@@ -4,7 +4,7 @@
67156
67157 config ECONET
67158 tristate "Acorn Econet/AUN protocols (EXPERIMENTAL)"
67159- depends on EXPERIMENTAL && INET
67160+ depends on EXPERIMENTAL && INET && BROKEN
67161 ---help---
67162 Econet is a fairly old and slow networking protocol mainly used by
67163 Acorn computers to access file and print servers. It uses native
67164diff -urNp linux-2.6.32.41/net/ieee802154/dgram.c linux-2.6.32.41/net/ieee802154/dgram.c
67165--- linux-2.6.32.41/net/ieee802154/dgram.c 2011-03-27 14:31:47.000000000 -0400
67166+++ linux-2.6.32.41/net/ieee802154/dgram.c 2011-05-04 17:56:28.000000000 -0400
67167@@ -318,7 +318,7 @@ out:
67168 static int dgram_rcv_skb(struct sock *sk, struct sk_buff *skb)
67169 {
67170 if (sock_queue_rcv_skb(sk, skb) < 0) {
67171- atomic_inc(&sk->sk_drops);
67172+ atomic_inc_unchecked(&sk->sk_drops);
67173 kfree_skb(skb);
67174 return NET_RX_DROP;
67175 }
67176diff -urNp linux-2.6.32.41/net/ieee802154/raw.c linux-2.6.32.41/net/ieee802154/raw.c
67177--- linux-2.6.32.41/net/ieee802154/raw.c 2011-03-27 14:31:47.000000000 -0400
67178+++ linux-2.6.32.41/net/ieee802154/raw.c 2011-05-04 17:56:28.000000000 -0400
67179@@ -206,7 +206,7 @@ out:
67180 static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
67181 {
67182 if (sock_queue_rcv_skb(sk, skb) < 0) {
67183- atomic_inc(&sk->sk_drops);
67184+ atomic_inc_unchecked(&sk->sk_drops);
67185 kfree_skb(skb);
67186 return NET_RX_DROP;
67187 }
67188diff -urNp linux-2.6.32.41/net/ipv4/inet_diag.c linux-2.6.32.41/net/ipv4/inet_diag.c
67189--- linux-2.6.32.41/net/ipv4/inet_diag.c 2011-04-17 17:00:52.000000000 -0400
67190+++ linux-2.6.32.41/net/ipv4/inet_diag.c 2011-04-17 17:04:18.000000000 -0400
67191@@ -113,8 +113,13 @@ static int inet_csk_diag_fill(struct soc
67192 r->idiag_retrans = 0;
67193
67194 r->id.idiag_if = sk->sk_bound_dev_if;
67195+#ifdef CONFIG_GRKERNSEC_HIDESYM
67196+ r->id.idiag_cookie[0] = 0;
67197+ r->id.idiag_cookie[1] = 0;
67198+#else
67199 r->id.idiag_cookie[0] = (u32)(unsigned long)sk;
67200 r->id.idiag_cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
67201+#endif
67202
67203 r->id.idiag_sport = inet->sport;
67204 r->id.idiag_dport = inet->dport;
67205@@ -200,8 +205,15 @@ static int inet_twsk_diag_fill(struct in
67206 r->idiag_family = tw->tw_family;
67207 r->idiag_retrans = 0;
67208 r->id.idiag_if = tw->tw_bound_dev_if;
67209+
67210+#ifdef CONFIG_GRKERNSEC_HIDESYM
67211+ r->id.idiag_cookie[0] = 0;
67212+ r->id.idiag_cookie[1] = 0;
67213+#else
67214 r->id.idiag_cookie[0] = (u32)(unsigned long)tw;
67215 r->id.idiag_cookie[1] = (u32)(((unsigned long)tw >> 31) >> 1);
67216+#endif
67217+
67218 r->id.idiag_sport = tw->tw_sport;
67219 r->id.idiag_dport = tw->tw_dport;
67220 r->id.idiag_src[0] = tw->tw_rcv_saddr;
67221@@ -284,12 +296,14 @@ static int inet_diag_get_exact(struct sk
67222 if (sk == NULL)
67223 goto unlock;
67224
67225+#ifndef CONFIG_GRKERNSEC_HIDESYM
67226 err = -ESTALE;
67227 if ((req->id.idiag_cookie[0] != INET_DIAG_NOCOOKIE ||
67228 req->id.idiag_cookie[1] != INET_DIAG_NOCOOKIE) &&
67229 ((u32)(unsigned long)sk != req->id.idiag_cookie[0] ||
67230 (u32)((((unsigned long)sk) >> 31) >> 1) != req->id.idiag_cookie[1]))
67231 goto out;
67232+#endif
67233
67234 err = -ENOMEM;
67235 rep = alloc_skb(NLMSG_SPACE((sizeof(struct inet_diag_msg) +
67236@@ -581,8 +595,14 @@ static int inet_diag_fill_req(struct sk_
67237 r->idiag_retrans = req->retrans;
67238
67239 r->id.idiag_if = sk->sk_bound_dev_if;
67240+
67241+#ifdef CONFIG_GRKERNSEC_HIDESYM
67242+ r->id.idiag_cookie[0] = 0;
67243+ r->id.idiag_cookie[1] = 0;
67244+#else
67245 r->id.idiag_cookie[0] = (u32)(unsigned long)req;
67246 r->id.idiag_cookie[1] = (u32)(((unsigned long)req >> 31) >> 1);
67247+#endif
67248
67249 tmo = req->expires - jiffies;
67250 if (tmo < 0)
67251diff -urNp linux-2.6.32.41/net/ipv4/inet_hashtables.c linux-2.6.32.41/net/ipv4/inet_hashtables.c
67252--- linux-2.6.32.41/net/ipv4/inet_hashtables.c 2011-03-27 14:31:47.000000000 -0400
67253+++ linux-2.6.32.41/net/ipv4/inet_hashtables.c 2011-04-17 15:56:46.000000000 -0400
67254@@ -18,11 +18,14 @@
67255 #include <linux/sched.h>
67256 #include <linux/slab.h>
67257 #include <linux/wait.h>
67258+#include <linux/security.h>
67259
67260 #include <net/inet_connection_sock.h>
67261 #include <net/inet_hashtables.h>
67262 #include <net/ip.h>
67263
67264+extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
67265+
67266 /*
67267 * Allocate and initialize a new local port bind bucket.
67268 * The bindhash mutex for snum's hash chain must be held here.
67269@@ -490,6 +493,8 @@ ok:
67270 }
67271 spin_unlock(&head->lock);
67272
67273+ gr_update_task_in_ip_table(current, inet_sk(sk));
67274+
67275 if (tw) {
67276 inet_twsk_deschedule(tw, death_row);
67277 inet_twsk_put(tw);
67278diff -urNp linux-2.6.32.41/net/ipv4/inetpeer.c linux-2.6.32.41/net/ipv4/inetpeer.c
67279--- linux-2.6.32.41/net/ipv4/inetpeer.c 2011-03-27 14:31:47.000000000 -0400
67280+++ linux-2.6.32.41/net/ipv4/inetpeer.c 2011-05-16 21:46:57.000000000 -0400
67281@@ -366,6 +366,8 @@ struct inet_peer *inet_getpeer(__be32 da
67282 struct inet_peer *p, *n;
67283 struct inet_peer **stack[PEER_MAXDEPTH], ***stackptr;
67284
67285+ pax_track_stack();
67286+
67287 /* Look up for the address quickly. */
67288 read_lock_bh(&peer_pool_lock);
67289 p = lookup(daddr, NULL);
67290@@ -389,7 +391,7 @@ struct inet_peer *inet_getpeer(__be32 da
67291 return NULL;
67292 n->v4daddr = daddr;
67293 atomic_set(&n->refcnt, 1);
67294- atomic_set(&n->rid, 0);
67295+ atomic_set_unchecked(&n->rid, 0);
67296 n->ip_id_count = secure_ip_id(daddr);
67297 n->tcp_ts_stamp = 0;
67298
67299diff -urNp linux-2.6.32.41/net/ipv4/ip_fragment.c linux-2.6.32.41/net/ipv4/ip_fragment.c
67300--- linux-2.6.32.41/net/ipv4/ip_fragment.c 2011-03-27 14:31:47.000000000 -0400
67301+++ linux-2.6.32.41/net/ipv4/ip_fragment.c 2011-04-17 15:56:46.000000000 -0400
67302@@ -255,7 +255,7 @@ static inline int ip_frag_too_far(struct
67303 return 0;
67304
67305 start = qp->rid;
67306- end = atomic_inc_return(&peer->rid);
67307+ end = atomic_inc_return_unchecked(&peer->rid);
67308 qp->rid = end;
67309
67310 rc = qp->q.fragments && (end - start) > max;
67311diff -urNp linux-2.6.32.41/net/ipv4/ip_sockglue.c linux-2.6.32.41/net/ipv4/ip_sockglue.c
67312--- linux-2.6.32.41/net/ipv4/ip_sockglue.c 2011-03-27 14:31:47.000000000 -0400
67313+++ linux-2.6.32.41/net/ipv4/ip_sockglue.c 2011-05-16 21:46:57.000000000 -0400
67314@@ -1015,6 +1015,8 @@ static int do_ip_getsockopt(struct sock
67315 int val;
67316 int len;
67317
67318+ pax_track_stack();
67319+
67320 if (level != SOL_IP)
67321 return -EOPNOTSUPP;
67322
67323diff -urNp linux-2.6.32.41/net/ipv4/netfilter/arp_tables.c linux-2.6.32.41/net/ipv4/netfilter/arp_tables.c
67324--- linux-2.6.32.41/net/ipv4/netfilter/arp_tables.c 2011-04-17 17:00:52.000000000 -0400
67325+++ linux-2.6.32.41/net/ipv4/netfilter/arp_tables.c 2011-04-17 17:04:18.000000000 -0400
67326@@ -934,6 +934,7 @@ static int get_info(struct net *net, voi
67327 private = &tmp;
67328 }
67329 #endif
67330+ memset(&info, 0, sizeof(info));
67331 info.valid_hooks = t->valid_hooks;
67332 memcpy(info.hook_entry, private->hook_entry,
67333 sizeof(info.hook_entry));
67334diff -urNp linux-2.6.32.41/net/ipv4/netfilter/ip_tables.c linux-2.6.32.41/net/ipv4/netfilter/ip_tables.c
67335--- linux-2.6.32.41/net/ipv4/netfilter/ip_tables.c 2011-04-17 17:00:52.000000000 -0400
67336+++ linux-2.6.32.41/net/ipv4/netfilter/ip_tables.c 2011-04-17 17:04:18.000000000 -0400
67337@@ -1141,6 +1141,7 @@ static int get_info(struct net *net, voi
67338 private = &tmp;
67339 }
67340 #endif
67341+ memset(&info, 0, sizeof(info));
67342 info.valid_hooks = t->valid_hooks;
67343 memcpy(info.hook_entry, private->hook_entry,
67344 sizeof(info.hook_entry));
67345diff -urNp linux-2.6.32.41/net/ipv4/netfilter/nf_nat_snmp_basic.c linux-2.6.32.41/net/ipv4/netfilter/nf_nat_snmp_basic.c
67346--- linux-2.6.32.41/net/ipv4/netfilter/nf_nat_snmp_basic.c 2011-03-27 14:31:47.000000000 -0400
67347+++ linux-2.6.32.41/net/ipv4/netfilter/nf_nat_snmp_basic.c 2011-04-17 15:56:46.000000000 -0400
67348@@ -397,7 +397,7 @@ static unsigned char asn1_octets_decode(
67349
67350 *len = 0;
67351
67352- *octets = kmalloc(eoc - ctx->pointer, GFP_ATOMIC);
67353+ *octets = kmalloc((eoc - ctx->pointer), GFP_ATOMIC);
67354 if (*octets == NULL) {
67355 if (net_ratelimit())
67356 printk("OOM in bsalg (%d)\n", __LINE__);
67357diff -urNp linux-2.6.32.41/net/ipv4/raw.c linux-2.6.32.41/net/ipv4/raw.c
67358--- linux-2.6.32.41/net/ipv4/raw.c 2011-03-27 14:31:47.000000000 -0400
67359+++ linux-2.6.32.41/net/ipv4/raw.c 2011-05-04 17:59:08.000000000 -0400
67360@@ -292,7 +292,7 @@ static int raw_rcv_skb(struct sock * sk,
67361 /* Charge it to the socket. */
67362
67363 if (sock_queue_rcv_skb(sk, skb) < 0) {
67364- atomic_inc(&sk->sk_drops);
67365+ atomic_inc_unchecked(&sk->sk_drops);
67366 kfree_skb(skb);
67367 return NET_RX_DROP;
67368 }
67369@@ -303,7 +303,7 @@ static int raw_rcv_skb(struct sock * sk,
67370 int raw_rcv(struct sock *sk, struct sk_buff *skb)
67371 {
67372 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
67373- atomic_inc(&sk->sk_drops);
67374+ atomic_inc_unchecked(&sk->sk_drops);
67375 kfree_skb(skb);
67376 return NET_RX_DROP;
67377 }
67378@@ -724,15 +724,22 @@ static int raw_init(struct sock *sk)
67379
67380 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
67381 {
67382+ struct icmp_filter filter;
67383+
67384+ if (optlen < 0)
67385+ return -EINVAL;
67386 if (optlen > sizeof(struct icmp_filter))
67387 optlen = sizeof(struct icmp_filter);
67388- if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
67389+ if (copy_from_user(&filter, optval, optlen))
67390 return -EFAULT;
67391+ memcpy(&raw_sk(sk)->filter, &filter, optlen);
67392+
67393 return 0;
67394 }
67395
67396 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
67397 {
67398+ struct icmp_filter filter;
67399 int len, ret = -EFAULT;
67400
67401 if (get_user(len, optlen))
67402@@ -743,8 +750,9 @@ static int raw_geticmpfilter(struct sock
67403 if (len > sizeof(struct icmp_filter))
67404 len = sizeof(struct icmp_filter);
67405 ret = -EFAULT;
67406+ memcpy(&filter, &raw_sk(sk)->filter, len);
67407 if (put_user(len, optlen) ||
67408- copy_to_user(optval, &raw_sk(sk)->filter, len))
67409+ copy_to_user(optval, &filter, len))
67410 goto out;
67411 ret = 0;
67412 out: return ret;
67413@@ -954,7 +962,13 @@ static void raw_sock_seq_show(struct seq
67414 sk_wmem_alloc_get(sp),
67415 sk_rmem_alloc_get(sp),
67416 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
67417- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
67418+ atomic_read(&sp->sk_refcnt),
67419+#ifdef CONFIG_GRKERNSEC_HIDESYM
67420+ NULL,
67421+#else
67422+ sp,
67423+#endif
67424+ atomic_read_unchecked(&sp->sk_drops));
67425 }
67426
67427 static int raw_seq_show(struct seq_file *seq, void *v)
67428diff -urNp linux-2.6.32.41/net/ipv4/route.c linux-2.6.32.41/net/ipv4/route.c
67429--- linux-2.6.32.41/net/ipv4/route.c 2011-03-27 14:31:47.000000000 -0400
67430+++ linux-2.6.32.41/net/ipv4/route.c 2011-05-04 17:56:28.000000000 -0400
67431@@ -268,7 +268,7 @@ static inline unsigned int rt_hash(__be3
67432
67433 static inline int rt_genid(struct net *net)
67434 {
67435- return atomic_read(&net->ipv4.rt_genid);
67436+ return atomic_read_unchecked(&net->ipv4.rt_genid);
67437 }
67438
67439 #ifdef CONFIG_PROC_FS
67440@@ -888,7 +888,7 @@ static void rt_cache_invalidate(struct n
67441 unsigned char shuffle;
67442
67443 get_random_bytes(&shuffle, sizeof(shuffle));
67444- atomic_add(shuffle + 1U, &net->ipv4.rt_genid);
67445+ atomic_add_unchecked(shuffle + 1U, &net->ipv4.rt_genid);
67446 }
67447
67448 /*
67449@@ -3356,7 +3356,7 @@ static __net_initdata struct pernet_oper
67450
67451 static __net_init int rt_secret_timer_init(struct net *net)
67452 {
67453- atomic_set(&net->ipv4.rt_genid,
67454+ atomic_set_unchecked(&net->ipv4.rt_genid,
67455 (int) ((num_physpages ^ (num_physpages>>8)) ^
67456 (jiffies ^ (jiffies >> 7))));
67457
67458diff -urNp linux-2.6.32.41/net/ipv4/tcp.c linux-2.6.32.41/net/ipv4/tcp.c
67459--- linux-2.6.32.41/net/ipv4/tcp.c 2011-03-27 14:31:47.000000000 -0400
67460+++ linux-2.6.32.41/net/ipv4/tcp.c 2011-05-16 21:46:57.000000000 -0400
67461@@ -2085,6 +2085,8 @@ static int do_tcp_setsockopt(struct sock
67462 int val;
67463 int err = 0;
67464
67465+ pax_track_stack();
67466+
67467 /* This is a string value all the others are int's */
67468 if (optname == TCP_CONGESTION) {
67469 char name[TCP_CA_NAME_MAX];
67470@@ -2355,6 +2357,8 @@ static int do_tcp_getsockopt(struct sock
67471 struct tcp_sock *tp = tcp_sk(sk);
67472 int val, len;
67473
67474+ pax_track_stack();
67475+
67476 if (get_user(len, optlen))
67477 return -EFAULT;
67478
67479diff -urNp linux-2.6.32.41/net/ipv4/tcp_ipv4.c linux-2.6.32.41/net/ipv4/tcp_ipv4.c
67480--- linux-2.6.32.41/net/ipv4/tcp_ipv4.c 2011-03-27 14:31:47.000000000 -0400
67481+++ linux-2.6.32.41/net/ipv4/tcp_ipv4.c 2011-04-17 15:56:46.000000000 -0400
67482@@ -84,6 +84,9 @@
67483 int sysctl_tcp_tw_reuse __read_mostly;
67484 int sysctl_tcp_low_latency __read_mostly;
67485
67486+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
67487+extern int grsec_enable_blackhole;
67488+#endif
67489
67490 #ifdef CONFIG_TCP_MD5SIG
67491 static struct tcp_md5sig_key *tcp_v4_md5_do_lookup(struct sock *sk,
67492@@ -1542,6 +1545,9 @@ int tcp_v4_do_rcv(struct sock *sk, struc
67493 return 0;
67494
67495 reset:
67496+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
67497+ if (!grsec_enable_blackhole)
67498+#endif
67499 tcp_v4_send_reset(rsk, skb);
67500 discard:
67501 kfree_skb(skb);
67502@@ -1603,12 +1609,20 @@ int tcp_v4_rcv(struct sk_buff *skb)
67503 TCP_SKB_CB(skb)->sacked = 0;
67504
67505 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
67506- if (!sk)
67507+ if (!sk) {
67508+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
67509+ ret = 1;
67510+#endif
67511 goto no_tcp_socket;
67512+ }
67513
67514 process:
67515- if (sk->sk_state == TCP_TIME_WAIT)
67516+ if (sk->sk_state == TCP_TIME_WAIT) {
67517+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
67518+ ret = 2;
67519+#endif
67520 goto do_time_wait;
67521+ }
67522
67523 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb))
67524 goto discard_and_relse;
67525@@ -1650,6 +1664,10 @@ no_tcp_socket:
67526 bad_packet:
67527 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
67528 } else {
67529+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
67530+ if (!grsec_enable_blackhole || (ret == 1 &&
67531+ (skb->dev->flags & IFF_LOOPBACK)))
67532+#endif
67533 tcp_v4_send_reset(NULL, skb);
67534 }
67535
67536@@ -2237,7 +2255,11 @@ static void get_openreq4(struct sock *sk
67537 0, /* non standard timer */
67538 0, /* open_requests have no inode */
67539 atomic_read(&sk->sk_refcnt),
67540+#ifdef CONFIG_GRKERNSEC_HIDESYM
67541+ NULL,
67542+#else
67543 req,
67544+#endif
67545 len);
67546 }
67547
67548@@ -2279,7 +2301,12 @@ static void get_tcp4_sock(struct sock *s
67549 sock_i_uid(sk),
67550 icsk->icsk_probes_out,
67551 sock_i_ino(sk),
67552- atomic_read(&sk->sk_refcnt), sk,
67553+ atomic_read(&sk->sk_refcnt),
67554+#ifdef CONFIG_GRKERNSEC_HIDESYM
67555+ NULL,
67556+#else
67557+ sk,
67558+#endif
67559 jiffies_to_clock_t(icsk->icsk_rto),
67560 jiffies_to_clock_t(icsk->icsk_ack.ato),
67561 (icsk->icsk_ack.quick << 1) | icsk->icsk_ack.pingpong,
67562@@ -2307,7 +2334,13 @@ static void get_timewait4_sock(struct in
67563 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %p%n",
67564 i, src, srcp, dest, destp, tw->tw_substate, 0, 0,
67565 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
67566- atomic_read(&tw->tw_refcnt), tw, len);
67567+ atomic_read(&tw->tw_refcnt),
67568+#ifdef CONFIG_GRKERNSEC_HIDESYM
67569+ NULL,
67570+#else
67571+ tw,
67572+#endif
67573+ len);
67574 }
67575
67576 #define TMPSZ 150
67577diff -urNp linux-2.6.32.41/net/ipv4/tcp_minisocks.c linux-2.6.32.41/net/ipv4/tcp_minisocks.c
67578--- linux-2.6.32.41/net/ipv4/tcp_minisocks.c 2011-03-27 14:31:47.000000000 -0400
67579+++ linux-2.6.32.41/net/ipv4/tcp_minisocks.c 2011-04-17 15:56:46.000000000 -0400
67580@@ -26,6 +26,10 @@
67581 #include <net/inet_common.h>
67582 #include <net/xfrm.h>
67583
67584+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
67585+extern int grsec_enable_blackhole;
67586+#endif
67587+
67588 #ifdef CONFIG_SYSCTL
67589 #define SYNC_INIT 0 /* let the user enable it */
67590 #else
67591@@ -672,6 +676,10 @@ listen_overflow:
67592
67593 embryonic_reset:
67594 NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_EMBRYONICRSTS);
67595+
67596+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
67597+ if (!grsec_enable_blackhole)
67598+#endif
67599 if (!(flg & TCP_FLAG_RST))
67600 req->rsk_ops->send_reset(sk, skb);
67601
67602diff -urNp linux-2.6.32.41/net/ipv4/tcp_output.c linux-2.6.32.41/net/ipv4/tcp_output.c
67603--- linux-2.6.32.41/net/ipv4/tcp_output.c 2011-03-27 14:31:47.000000000 -0400
67604+++ linux-2.6.32.41/net/ipv4/tcp_output.c 2011-05-16 21:46:57.000000000 -0400
67605@@ -2234,6 +2234,8 @@ struct sk_buff *tcp_make_synack(struct s
67606 __u8 *md5_hash_location;
67607 int mss;
67608
67609+ pax_track_stack();
67610+
67611 skb = sock_wmalloc(sk, MAX_TCP_HEADER + 15, 1, GFP_ATOMIC);
67612 if (skb == NULL)
67613 return NULL;
67614diff -urNp linux-2.6.32.41/net/ipv4/tcp_probe.c linux-2.6.32.41/net/ipv4/tcp_probe.c
67615--- linux-2.6.32.41/net/ipv4/tcp_probe.c 2011-03-27 14:31:47.000000000 -0400
67616+++ linux-2.6.32.41/net/ipv4/tcp_probe.c 2011-04-17 15:56:46.000000000 -0400
67617@@ -200,7 +200,7 @@ static ssize_t tcpprobe_read(struct file
67618 if (cnt + width >= len)
67619 break;
67620
67621- if (copy_to_user(buf + cnt, tbuf, width))
67622+ if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
67623 return -EFAULT;
67624 cnt += width;
67625 }
67626diff -urNp linux-2.6.32.41/net/ipv4/tcp_timer.c linux-2.6.32.41/net/ipv4/tcp_timer.c
67627--- linux-2.6.32.41/net/ipv4/tcp_timer.c 2011-03-27 14:31:47.000000000 -0400
67628+++ linux-2.6.32.41/net/ipv4/tcp_timer.c 2011-04-17 15:56:46.000000000 -0400
67629@@ -21,6 +21,10 @@
67630 #include <linux/module.h>
67631 #include <net/tcp.h>
67632
67633+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
67634+extern int grsec_lastack_retries;
67635+#endif
67636+
67637 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
67638 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
67639 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
67640@@ -164,6 +168,13 @@ static int tcp_write_timeout(struct sock
67641 }
67642 }
67643
67644+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
67645+ if ((sk->sk_state == TCP_LAST_ACK) &&
67646+ (grsec_lastack_retries > 0) &&
67647+ (grsec_lastack_retries < retry_until))
67648+ retry_until = grsec_lastack_retries;
67649+#endif
67650+
67651 if (retransmits_timed_out(sk, retry_until)) {
67652 /* Has it gone just too far? */
67653 tcp_write_err(sk);
67654diff -urNp linux-2.6.32.41/net/ipv4/udp.c linux-2.6.32.41/net/ipv4/udp.c
67655--- linux-2.6.32.41/net/ipv4/udp.c 2011-03-27 14:31:47.000000000 -0400
67656+++ linux-2.6.32.41/net/ipv4/udp.c 2011-05-04 17:57:28.000000000 -0400
67657@@ -86,6 +86,7 @@
67658 #include <linux/types.h>
67659 #include <linux/fcntl.h>
67660 #include <linux/module.h>
67661+#include <linux/security.h>
67662 #include <linux/socket.h>
67663 #include <linux/sockios.h>
67664 #include <linux/igmp.h>
67665@@ -106,6 +107,10 @@
67666 #include <net/xfrm.h>
67667 #include "udp_impl.h"
67668
67669+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
67670+extern int grsec_enable_blackhole;
67671+#endif
67672+
67673 struct udp_table udp_table;
67674 EXPORT_SYMBOL(udp_table);
67675
67676@@ -371,6 +376,9 @@ found:
67677 return s;
67678 }
67679
67680+extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
67681+extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
67682+
67683 /*
67684 * This routine is called by the ICMP module when it gets some
67685 * sort of error condition. If err < 0 then the socket should
67686@@ -639,9 +647,18 @@ int udp_sendmsg(struct kiocb *iocb, stru
67687 dport = usin->sin_port;
67688 if (dport == 0)
67689 return -EINVAL;
67690+
67691+ err = gr_search_udp_sendmsg(sk, usin);
67692+ if (err)
67693+ return err;
67694 } else {
67695 if (sk->sk_state != TCP_ESTABLISHED)
67696 return -EDESTADDRREQ;
67697+
67698+ err = gr_search_udp_sendmsg(sk, NULL);
67699+ if (err)
67700+ return err;
67701+
67702 daddr = inet->daddr;
67703 dport = inet->dport;
67704 /* Open fast path for connected socket.
67705@@ -945,6 +962,10 @@ try_again:
67706 if (!skb)
67707 goto out;
67708
67709+ err = gr_search_udp_recvmsg(sk, skb);
67710+ if (err)
67711+ goto out_free;
67712+
67713 ulen = skb->len - sizeof(struct udphdr);
67714 copied = len;
67715 if (copied > ulen)
67716@@ -1065,7 +1086,7 @@ static int __udp_queue_rcv_skb(struct so
67717 if (rc == -ENOMEM) {
67718 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
67719 is_udplite);
67720- atomic_inc(&sk->sk_drops);
67721+ atomic_inc_unchecked(&sk->sk_drops);
67722 }
67723 goto drop;
67724 }
67725@@ -1335,6 +1356,9 @@ int __udp4_lib_rcv(struct sk_buff *skb,
67726 goto csum_error;
67727
67728 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
67729+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
67730+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
67731+#endif
67732 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
67733
67734 /*
67735@@ -1755,8 +1779,13 @@ static void udp4_format_sock(struct sock
67736 sk_wmem_alloc_get(sp),
67737 sk_rmem_alloc_get(sp),
67738 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
67739- atomic_read(&sp->sk_refcnt), sp,
67740- atomic_read(&sp->sk_drops), len);
67741+ atomic_read(&sp->sk_refcnt),
67742+#ifdef CONFIG_GRKERNSEC_HIDESYM
67743+ NULL,
67744+#else
67745+ sp,
67746+#endif
67747+ atomic_read_unchecked(&sp->sk_drops), len);
67748 }
67749
67750 int udp4_seq_show(struct seq_file *seq, void *v)
67751diff -urNp linux-2.6.32.41/net/ipv6/inet6_connection_sock.c linux-2.6.32.41/net/ipv6/inet6_connection_sock.c
67752--- linux-2.6.32.41/net/ipv6/inet6_connection_sock.c 2011-03-27 14:31:47.000000000 -0400
67753+++ linux-2.6.32.41/net/ipv6/inet6_connection_sock.c 2011-05-04 17:56:28.000000000 -0400
67754@@ -152,7 +152,7 @@ void __inet6_csk_dst_store(struct sock *
67755 #ifdef CONFIG_XFRM
67756 {
67757 struct rt6_info *rt = (struct rt6_info *)dst;
67758- rt->rt6i_flow_cache_genid = atomic_read(&flow_cache_genid);
67759+ rt->rt6i_flow_cache_genid = atomic_read_unchecked(&flow_cache_genid);
67760 }
67761 #endif
67762 }
67763@@ -167,7 +167,7 @@ struct dst_entry *__inet6_csk_dst_check(
67764 #ifdef CONFIG_XFRM
67765 if (dst) {
67766 struct rt6_info *rt = (struct rt6_info *)dst;
67767- if (rt->rt6i_flow_cache_genid != atomic_read(&flow_cache_genid)) {
67768+ if (rt->rt6i_flow_cache_genid != atomic_read_unchecked(&flow_cache_genid)) {
67769 sk->sk_dst_cache = NULL;
67770 dst_release(dst);
67771 dst = NULL;
67772diff -urNp linux-2.6.32.41/net/ipv6/inet6_hashtables.c linux-2.6.32.41/net/ipv6/inet6_hashtables.c
67773--- linux-2.6.32.41/net/ipv6/inet6_hashtables.c 2011-03-27 14:31:47.000000000 -0400
67774+++ linux-2.6.32.41/net/ipv6/inet6_hashtables.c 2011-05-04 17:56:28.000000000 -0400
67775@@ -118,7 +118,7 @@ out:
67776 }
67777 EXPORT_SYMBOL(__inet6_lookup_established);
67778
67779-static int inline compute_score(struct sock *sk, struct net *net,
67780+static inline int compute_score(struct sock *sk, struct net *net,
67781 const unsigned short hnum,
67782 const struct in6_addr *daddr,
67783 const int dif)
67784diff -urNp linux-2.6.32.41/net/ipv6/ipv6_sockglue.c linux-2.6.32.41/net/ipv6/ipv6_sockglue.c
67785--- linux-2.6.32.41/net/ipv6/ipv6_sockglue.c 2011-03-27 14:31:47.000000000 -0400
67786+++ linux-2.6.32.41/net/ipv6/ipv6_sockglue.c 2011-05-16 21:46:57.000000000 -0400
67787@@ -130,6 +130,8 @@ static int do_ipv6_setsockopt(struct soc
67788 int val, valbool;
67789 int retv = -ENOPROTOOPT;
67790
67791+ pax_track_stack();
67792+
67793 if (optval == NULL)
67794 val=0;
67795 else {
67796@@ -881,6 +883,8 @@ static int do_ipv6_getsockopt(struct soc
67797 int len;
67798 int val;
67799
67800+ pax_track_stack();
67801+
67802 if (ip6_mroute_opt(optname))
67803 return ip6_mroute_getsockopt(sk, optname, optval, optlen);
67804
67805diff -urNp linux-2.6.32.41/net/ipv6/netfilter/ip6_tables.c linux-2.6.32.41/net/ipv6/netfilter/ip6_tables.c
67806--- linux-2.6.32.41/net/ipv6/netfilter/ip6_tables.c 2011-04-17 17:00:52.000000000 -0400
67807+++ linux-2.6.32.41/net/ipv6/netfilter/ip6_tables.c 2011-04-17 17:04:18.000000000 -0400
67808@@ -1173,6 +1173,7 @@ static int get_info(struct net *net, voi
67809 private = &tmp;
67810 }
67811 #endif
67812+ memset(&info, 0, sizeof(info));
67813 info.valid_hooks = t->valid_hooks;
67814 memcpy(info.hook_entry, private->hook_entry,
67815 sizeof(info.hook_entry));
67816diff -urNp linux-2.6.32.41/net/ipv6/raw.c linux-2.6.32.41/net/ipv6/raw.c
67817--- linux-2.6.32.41/net/ipv6/raw.c 2011-03-27 14:31:47.000000000 -0400
67818+++ linux-2.6.32.41/net/ipv6/raw.c 2011-05-16 21:46:57.000000000 -0400
67819@@ -375,14 +375,14 @@ static inline int rawv6_rcv_skb(struct s
67820 {
67821 if ((raw6_sk(sk)->checksum || sk->sk_filter) &&
67822 skb_checksum_complete(skb)) {
67823- atomic_inc(&sk->sk_drops);
67824+ atomic_inc_unchecked(&sk->sk_drops);
67825 kfree_skb(skb);
67826 return NET_RX_DROP;
67827 }
67828
67829 /* Charge it to the socket. */
67830 if (sock_queue_rcv_skb(sk,skb)<0) {
67831- atomic_inc(&sk->sk_drops);
67832+ atomic_inc_unchecked(&sk->sk_drops);
67833 kfree_skb(skb);
67834 return NET_RX_DROP;
67835 }
67836@@ -403,7 +403,7 @@ int rawv6_rcv(struct sock *sk, struct sk
67837 struct raw6_sock *rp = raw6_sk(sk);
67838
67839 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
67840- atomic_inc(&sk->sk_drops);
67841+ atomic_inc_unchecked(&sk->sk_drops);
67842 kfree_skb(skb);
67843 return NET_RX_DROP;
67844 }
67845@@ -427,7 +427,7 @@ int rawv6_rcv(struct sock *sk, struct sk
67846
67847 if (inet->hdrincl) {
67848 if (skb_checksum_complete(skb)) {
67849- atomic_inc(&sk->sk_drops);
67850+ atomic_inc_unchecked(&sk->sk_drops);
67851 kfree_skb(skb);
67852 return NET_RX_DROP;
67853 }
67854@@ -518,7 +518,7 @@ csum_copy_err:
67855 as some normal condition.
67856 */
67857 err = (flags&MSG_DONTWAIT) ? -EAGAIN : -EHOSTUNREACH;
67858- atomic_inc(&sk->sk_drops);
67859+ atomic_inc_unchecked(&sk->sk_drops);
67860 goto out;
67861 }
67862
67863@@ -600,7 +600,7 @@ out:
67864 return err;
67865 }
67866
67867-static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
67868+static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
67869 struct flowi *fl, struct rt6_info *rt,
67870 unsigned int flags)
67871 {
67872@@ -738,6 +738,8 @@ static int rawv6_sendmsg(struct kiocb *i
67873 u16 proto;
67874 int err;
67875
67876+ pax_track_stack();
67877+
67878 /* Rough check on arithmetic overflow,
67879 better check is made in ip6_append_data().
67880 */
67881@@ -916,12 +918,17 @@ do_confirm:
67882 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
67883 char __user *optval, int optlen)
67884 {
67885+ struct icmp6_filter filter;
67886+
67887 switch (optname) {
67888 case ICMPV6_FILTER:
67889+ if (optlen < 0)
67890+ return -EINVAL;
67891 if (optlen > sizeof(struct icmp6_filter))
67892 optlen = sizeof(struct icmp6_filter);
67893- if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
67894+ if (copy_from_user(&filter, optval, optlen))
67895 return -EFAULT;
67896+ memcpy(&raw6_sk(sk)->filter, &filter, optlen);
67897 return 0;
67898 default:
67899 return -ENOPROTOOPT;
67900@@ -933,6 +940,7 @@ static int rawv6_seticmpfilter(struct so
67901 static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
67902 char __user *optval, int __user *optlen)
67903 {
67904+ struct icmp6_filter filter;
67905 int len;
67906
67907 switch (optname) {
67908@@ -945,7 +953,8 @@ static int rawv6_geticmpfilter(struct so
67909 len = sizeof(struct icmp6_filter);
67910 if (put_user(len, optlen))
67911 return -EFAULT;
67912- if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
67913+ memcpy(&filter, &raw6_sk(sk)->filter, len);
67914+ if (copy_to_user(optval, &filter, len))
67915 return -EFAULT;
67916 return 0;
67917 default:
67918@@ -1241,7 +1250,13 @@ static void raw6_sock_seq_show(struct se
67919 0, 0L, 0,
67920 sock_i_uid(sp), 0,
67921 sock_i_ino(sp),
67922- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
67923+ atomic_read(&sp->sk_refcnt),
67924+#ifdef CONFIG_GRKERNSEC_HIDESYM
67925+ NULL,
67926+#else
67927+ sp,
67928+#endif
67929+ atomic_read_unchecked(&sp->sk_drops));
67930 }
67931
67932 static int raw6_seq_show(struct seq_file *seq, void *v)
67933diff -urNp linux-2.6.32.41/net/ipv6/tcp_ipv6.c linux-2.6.32.41/net/ipv6/tcp_ipv6.c
67934--- linux-2.6.32.41/net/ipv6/tcp_ipv6.c 2011-03-27 14:31:47.000000000 -0400
67935+++ linux-2.6.32.41/net/ipv6/tcp_ipv6.c 2011-04-17 15:56:46.000000000 -0400
67936@@ -88,6 +88,10 @@ static struct tcp_md5sig_key *tcp_v6_md5
67937 }
67938 #endif
67939
67940+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
67941+extern int grsec_enable_blackhole;
67942+#endif
67943+
67944 static void tcp_v6_hash(struct sock *sk)
67945 {
67946 if (sk->sk_state != TCP_CLOSE) {
67947@@ -1578,6 +1582,9 @@ static int tcp_v6_do_rcv(struct sock *sk
67948 return 0;
67949
67950 reset:
67951+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
67952+ if (!grsec_enable_blackhole)
67953+#endif
67954 tcp_v6_send_reset(sk, skb);
67955 discard:
67956 if (opt_skb)
67957@@ -1655,12 +1662,20 @@ static int tcp_v6_rcv(struct sk_buff *sk
67958 TCP_SKB_CB(skb)->sacked = 0;
67959
67960 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
67961- if (!sk)
67962+ if (!sk) {
67963+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
67964+ ret = 1;
67965+#endif
67966 goto no_tcp_socket;
67967+ }
67968
67969 process:
67970- if (sk->sk_state == TCP_TIME_WAIT)
67971+ if (sk->sk_state == TCP_TIME_WAIT) {
67972+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
67973+ ret = 2;
67974+#endif
67975 goto do_time_wait;
67976+ }
67977
67978 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb))
67979 goto discard_and_relse;
67980@@ -1700,6 +1715,10 @@ no_tcp_socket:
67981 bad_packet:
67982 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
67983 } else {
67984+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
67985+ if (!grsec_enable_blackhole || (ret == 1 &&
67986+ (skb->dev->flags & IFF_LOOPBACK)))
67987+#endif
67988 tcp_v6_send_reset(NULL, skb);
67989 }
67990
67991@@ -1915,7 +1934,13 @@ static void get_openreq6(struct seq_file
67992 uid,
67993 0, /* non standard timer */
67994 0, /* open_requests have no inode */
67995- 0, req);
67996+ 0,
67997+#ifdef CONFIG_GRKERNSEC_HIDESYM
67998+ NULL
67999+#else
68000+ req
68001+#endif
68002+ );
68003 }
68004
68005 static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
68006@@ -1965,7 +1990,12 @@ static void get_tcp6_sock(struct seq_fil
68007 sock_i_uid(sp),
68008 icsk->icsk_probes_out,
68009 sock_i_ino(sp),
68010- atomic_read(&sp->sk_refcnt), sp,
68011+ atomic_read(&sp->sk_refcnt),
68012+#ifdef CONFIG_GRKERNSEC_HIDESYM
68013+ NULL,
68014+#else
68015+ sp,
68016+#endif
68017 jiffies_to_clock_t(icsk->icsk_rto),
68018 jiffies_to_clock_t(icsk->icsk_ack.ato),
68019 (icsk->icsk_ack.quick << 1 ) | icsk->icsk_ack.pingpong,
68020@@ -2000,7 +2030,13 @@ static void get_timewait6_sock(struct se
68021 dest->s6_addr32[2], dest->s6_addr32[3], destp,
68022 tw->tw_substate, 0, 0,
68023 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
68024- atomic_read(&tw->tw_refcnt), tw);
68025+ atomic_read(&tw->tw_refcnt),
68026+#ifdef CONFIG_GRKERNSEC_HIDESYM
68027+ NULL
68028+#else
68029+ tw
68030+#endif
68031+ );
68032 }
68033
68034 static int tcp6_seq_show(struct seq_file *seq, void *v)
68035diff -urNp linux-2.6.32.41/net/ipv6/udp.c linux-2.6.32.41/net/ipv6/udp.c
68036--- linux-2.6.32.41/net/ipv6/udp.c 2011-03-27 14:31:47.000000000 -0400
68037+++ linux-2.6.32.41/net/ipv6/udp.c 2011-05-04 17:58:16.000000000 -0400
68038@@ -49,6 +49,10 @@
68039 #include <linux/seq_file.h>
68040 #include "udp_impl.h"
68041
68042+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
68043+extern int grsec_enable_blackhole;
68044+#endif
68045+
68046 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
68047 {
68048 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
68049@@ -388,7 +392,7 @@ int udpv6_queue_rcv_skb(struct sock * sk
68050 if (rc == -ENOMEM) {
68051 UDP6_INC_STATS_BH(sock_net(sk),
68052 UDP_MIB_RCVBUFERRORS, is_udplite);
68053- atomic_inc(&sk->sk_drops);
68054+ atomic_inc_unchecked(&sk->sk_drops);
68055 }
68056 goto drop;
68057 }
68058@@ -587,6 +591,9 @@ int __udp6_lib_rcv(struct sk_buff *skb,
68059 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS,
68060 proto == IPPROTO_UDPLITE);
68061
68062+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
68063+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
68064+#endif
68065 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0, dev);
68066
68067 kfree_skb(skb);
68068@@ -1206,8 +1213,13 @@ static void udp6_sock_seq_show(struct se
68069 0, 0L, 0,
68070 sock_i_uid(sp), 0,
68071 sock_i_ino(sp),
68072- atomic_read(&sp->sk_refcnt), sp,
68073- atomic_read(&sp->sk_drops));
68074+ atomic_read(&sp->sk_refcnt),
68075+#ifdef CONFIG_GRKERNSEC_HIDESYM
68076+ NULL,
68077+#else
68078+ sp,
68079+#endif
68080+ atomic_read_unchecked(&sp->sk_drops));
68081 }
68082
68083 int udp6_seq_show(struct seq_file *seq, void *v)
68084diff -urNp linux-2.6.32.41/net/irda/ircomm/ircomm_tty.c linux-2.6.32.41/net/irda/ircomm/ircomm_tty.c
68085--- linux-2.6.32.41/net/irda/ircomm/ircomm_tty.c 2011-03-27 14:31:47.000000000 -0400
68086+++ linux-2.6.32.41/net/irda/ircomm/ircomm_tty.c 2011-04-17 15:56:46.000000000 -0400
68087@@ -280,16 +280,16 @@ static int ircomm_tty_block_til_ready(st
68088 add_wait_queue(&self->open_wait, &wait);
68089
68090 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
68091- __FILE__,__LINE__, tty->driver->name, self->open_count );
68092+ __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
68093
68094 /* As far as I can see, we protect open_count - Jean II */
68095 spin_lock_irqsave(&self->spinlock, flags);
68096 if (!tty_hung_up_p(filp)) {
68097 extra_count = 1;
68098- self->open_count--;
68099+ local_dec(&self->open_count);
68100 }
68101 spin_unlock_irqrestore(&self->spinlock, flags);
68102- self->blocked_open++;
68103+ local_inc(&self->blocked_open);
68104
68105 while (1) {
68106 if (tty->termios->c_cflag & CBAUD) {
68107@@ -329,7 +329,7 @@ static int ircomm_tty_block_til_ready(st
68108 }
68109
68110 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
68111- __FILE__,__LINE__, tty->driver->name, self->open_count );
68112+ __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
68113
68114 schedule();
68115 }
68116@@ -340,13 +340,13 @@ static int ircomm_tty_block_til_ready(st
68117 if (extra_count) {
68118 /* ++ is not atomic, so this should be protected - Jean II */
68119 spin_lock_irqsave(&self->spinlock, flags);
68120- self->open_count++;
68121+ local_inc(&self->open_count);
68122 spin_unlock_irqrestore(&self->spinlock, flags);
68123 }
68124- self->blocked_open--;
68125+ local_dec(&self->blocked_open);
68126
68127 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
68128- __FILE__,__LINE__, tty->driver->name, self->open_count);
68129+ __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count));
68130
68131 if (!retval)
68132 self->flags |= ASYNC_NORMAL_ACTIVE;
68133@@ -415,14 +415,14 @@ static int ircomm_tty_open(struct tty_st
68134 }
68135 /* ++ is not atomic, so this should be protected - Jean II */
68136 spin_lock_irqsave(&self->spinlock, flags);
68137- self->open_count++;
68138+ local_inc(&self->open_count);
68139
68140 tty->driver_data = self;
68141 self->tty = tty;
68142 spin_unlock_irqrestore(&self->spinlock, flags);
68143
68144 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
68145- self->line, self->open_count);
68146+ self->line, local_read(&self->open_count));
68147
68148 /* Not really used by us, but lets do it anyway */
68149 self->tty->low_latency = (self->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
68150@@ -511,7 +511,7 @@ static void ircomm_tty_close(struct tty_
68151 return;
68152 }
68153
68154- if ((tty->count == 1) && (self->open_count != 1)) {
68155+ if ((tty->count == 1) && (local_read(&self->open_count) != 1)) {
68156 /*
68157 * Uh, oh. tty->count is 1, which means that the tty
68158 * structure will be freed. state->count should always
68159@@ -521,16 +521,16 @@ static void ircomm_tty_close(struct tty_
68160 */
68161 IRDA_DEBUG(0, "%s(), bad serial port count; "
68162 "tty->count is 1, state->count is %d\n", __func__ ,
68163- self->open_count);
68164- self->open_count = 1;
68165+ local_read(&self->open_count));
68166+ local_set(&self->open_count, 1);
68167 }
68168
68169- if (--self->open_count < 0) {
68170+ if (local_dec_return(&self->open_count) < 0) {
68171 IRDA_ERROR("%s(), bad serial port count for ttys%d: %d\n",
68172- __func__, self->line, self->open_count);
68173- self->open_count = 0;
68174+ __func__, self->line, local_read(&self->open_count));
68175+ local_set(&self->open_count, 0);
68176 }
68177- if (self->open_count) {
68178+ if (local_read(&self->open_count)) {
68179 spin_unlock_irqrestore(&self->spinlock, flags);
68180
68181 IRDA_DEBUG(0, "%s(), open count > 0\n", __func__ );
68182@@ -562,7 +562,7 @@ static void ircomm_tty_close(struct tty_
68183 tty->closing = 0;
68184 self->tty = NULL;
68185
68186- if (self->blocked_open) {
68187+ if (local_read(&self->blocked_open)) {
68188 if (self->close_delay)
68189 schedule_timeout_interruptible(self->close_delay);
68190 wake_up_interruptible(&self->open_wait);
68191@@ -1017,7 +1017,7 @@ static void ircomm_tty_hangup(struct tty
68192 spin_lock_irqsave(&self->spinlock, flags);
68193 self->flags &= ~ASYNC_NORMAL_ACTIVE;
68194 self->tty = NULL;
68195- self->open_count = 0;
68196+ local_set(&self->open_count, 0);
68197 spin_unlock_irqrestore(&self->spinlock, flags);
68198
68199 wake_up_interruptible(&self->open_wait);
68200@@ -1369,7 +1369,7 @@ static void ircomm_tty_line_info(struct
68201 seq_putc(m, '\n');
68202
68203 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
68204- seq_printf(m, "Open count: %d\n", self->open_count);
68205+ seq_printf(m, "Open count: %d\n", local_read(&self->open_count));
68206 seq_printf(m, "Max data size: %d\n", self->max_data_size);
68207 seq_printf(m, "Max header size: %d\n", self->max_header_size);
68208
68209diff -urNp linux-2.6.32.41/net/iucv/af_iucv.c linux-2.6.32.41/net/iucv/af_iucv.c
68210--- linux-2.6.32.41/net/iucv/af_iucv.c 2011-03-27 14:31:47.000000000 -0400
68211+++ linux-2.6.32.41/net/iucv/af_iucv.c 2011-05-04 17:56:28.000000000 -0400
68212@@ -651,10 +651,10 @@ static int iucv_sock_autobind(struct soc
68213
68214 write_lock_bh(&iucv_sk_list.lock);
68215
68216- sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
68217+ sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
68218 while (__iucv_get_sock_by_name(name)) {
68219 sprintf(name, "%08x",
68220- atomic_inc_return(&iucv_sk_list.autobind_name));
68221+ atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
68222 }
68223
68224 write_unlock_bh(&iucv_sk_list.lock);
68225diff -urNp linux-2.6.32.41/net/key/af_key.c linux-2.6.32.41/net/key/af_key.c
68226--- linux-2.6.32.41/net/key/af_key.c 2011-03-27 14:31:47.000000000 -0400
68227+++ linux-2.6.32.41/net/key/af_key.c 2011-05-16 21:46:57.000000000 -0400
68228@@ -2489,6 +2489,8 @@ static int pfkey_migrate(struct sock *sk
68229 struct xfrm_migrate m[XFRM_MAX_DEPTH];
68230 struct xfrm_kmaddress k;
68231
68232+ pax_track_stack();
68233+
68234 if (!present_and_same_family(ext_hdrs[SADB_EXT_ADDRESS_SRC - 1],
68235 ext_hdrs[SADB_EXT_ADDRESS_DST - 1]) ||
68236 !ext_hdrs[SADB_X_EXT_POLICY - 1]) {
68237@@ -3660,7 +3662,11 @@ static int pfkey_seq_show(struct seq_fil
68238 seq_printf(f ,"sk RefCnt Rmem Wmem User Inode\n");
68239 else
68240 seq_printf(f ,"%p %-6d %-6u %-6u %-6u %-6lu\n",
68241+#ifdef CONFIG_GRKERNSEC_HIDESYM
68242+ NULL,
68243+#else
68244 s,
68245+#endif
68246 atomic_read(&s->sk_refcnt),
68247 sk_rmem_alloc_get(s),
68248 sk_wmem_alloc_get(s),
68249diff -urNp linux-2.6.32.41/net/mac80211/cfg.c linux-2.6.32.41/net/mac80211/cfg.c
68250--- linux-2.6.32.41/net/mac80211/cfg.c 2011-03-27 14:31:47.000000000 -0400
68251+++ linux-2.6.32.41/net/mac80211/cfg.c 2011-04-17 15:56:46.000000000 -0400
68252@@ -1369,7 +1369,7 @@ static int ieee80211_set_bitrate_mask(st
68253 return err;
68254 }
68255
68256-struct cfg80211_ops mac80211_config_ops = {
68257+const struct cfg80211_ops mac80211_config_ops = {
68258 .add_virtual_intf = ieee80211_add_iface,
68259 .del_virtual_intf = ieee80211_del_iface,
68260 .change_virtual_intf = ieee80211_change_iface,
68261diff -urNp linux-2.6.32.41/net/mac80211/cfg.h linux-2.6.32.41/net/mac80211/cfg.h
68262--- linux-2.6.32.41/net/mac80211/cfg.h 2011-03-27 14:31:47.000000000 -0400
68263+++ linux-2.6.32.41/net/mac80211/cfg.h 2011-04-17 15:56:46.000000000 -0400
68264@@ -4,6 +4,6 @@
68265 #ifndef __CFG_H
68266 #define __CFG_H
68267
68268-extern struct cfg80211_ops mac80211_config_ops;
68269+extern const struct cfg80211_ops mac80211_config_ops;
68270
68271 #endif /* __CFG_H */
68272diff -urNp linux-2.6.32.41/net/mac80211/debugfs_key.c linux-2.6.32.41/net/mac80211/debugfs_key.c
68273--- linux-2.6.32.41/net/mac80211/debugfs_key.c 2011-03-27 14:31:47.000000000 -0400
68274+++ linux-2.6.32.41/net/mac80211/debugfs_key.c 2011-04-17 15:56:46.000000000 -0400
68275@@ -211,9 +211,13 @@ static ssize_t key_key_read(struct file
68276 size_t count, loff_t *ppos)
68277 {
68278 struct ieee80211_key *key = file->private_data;
68279- int i, res, bufsize = 2 * key->conf.keylen + 2;
68280+ int i, bufsize = 2 * key->conf.keylen + 2;
68281 char *buf = kmalloc(bufsize, GFP_KERNEL);
68282 char *p = buf;
68283+ ssize_t res;
68284+
68285+ if (buf == NULL)
68286+ return -ENOMEM;
68287
68288 for (i = 0; i < key->conf.keylen; i++)
68289 p += scnprintf(p, bufsize + buf - p, "%02x", key->conf.key[i]);
68290diff -urNp linux-2.6.32.41/net/mac80211/debugfs_sta.c linux-2.6.32.41/net/mac80211/debugfs_sta.c
68291--- linux-2.6.32.41/net/mac80211/debugfs_sta.c 2011-03-27 14:31:47.000000000 -0400
68292+++ linux-2.6.32.41/net/mac80211/debugfs_sta.c 2011-05-16 21:46:57.000000000 -0400
68293@@ -124,6 +124,8 @@ static ssize_t sta_agg_status_read(struc
68294 int i;
68295 struct sta_info *sta = file->private_data;
68296
68297+ pax_track_stack();
68298+
68299 spin_lock_bh(&sta->lock);
68300 p += scnprintf(p, sizeof(buf)+buf-p, "next dialog_token is %#02x\n",
68301 sta->ampdu_mlme.dialog_token_allocator + 1);
68302diff -urNp linux-2.6.32.41/net/mac80211/ieee80211_i.h linux-2.6.32.41/net/mac80211/ieee80211_i.h
68303--- linux-2.6.32.41/net/mac80211/ieee80211_i.h 2011-03-27 14:31:47.000000000 -0400
68304+++ linux-2.6.32.41/net/mac80211/ieee80211_i.h 2011-04-17 15:56:46.000000000 -0400
68305@@ -25,6 +25,7 @@
68306 #include <linux/etherdevice.h>
68307 #include <net/cfg80211.h>
68308 #include <net/mac80211.h>
68309+#include <asm/local.h>
68310 #include "key.h"
68311 #include "sta_info.h"
68312
68313@@ -635,7 +636,7 @@ struct ieee80211_local {
68314 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
68315 spinlock_t queue_stop_reason_lock;
68316
68317- int open_count;
68318+ local_t open_count;
68319 int monitors, cooked_mntrs;
68320 /* number of interfaces with corresponding FIF_ flags */
68321 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll;
68322diff -urNp linux-2.6.32.41/net/mac80211/iface.c linux-2.6.32.41/net/mac80211/iface.c
68323--- linux-2.6.32.41/net/mac80211/iface.c 2011-03-27 14:31:47.000000000 -0400
68324+++ linux-2.6.32.41/net/mac80211/iface.c 2011-04-17 15:56:46.000000000 -0400
68325@@ -166,7 +166,7 @@ static int ieee80211_open(struct net_dev
68326 break;
68327 }
68328
68329- if (local->open_count == 0) {
68330+ if (local_read(&local->open_count) == 0) {
68331 res = drv_start(local);
68332 if (res)
68333 goto err_del_bss;
68334@@ -196,7 +196,7 @@ static int ieee80211_open(struct net_dev
68335 * Validate the MAC address for this device.
68336 */
68337 if (!is_valid_ether_addr(dev->dev_addr)) {
68338- if (!local->open_count)
68339+ if (!local_read(&local->open_count))
68340 drv_stop(local);
68341 return -EADDRNOTAVAIL;
68342 }
68343@@ -292,7 +292,7 @@ static int ieee80211_open(struct net_dev
68344
68345 hw_reconf_flags |= __ieee80211_recalc_idle(local);
68346
68347- local->open_count++;
68348+ local_inc(&local->open_count);
68349 if (hw_reconf_flags) {
68350 ieee80211_hw_config(local, hw_reconf_flags);
68351 /*
68352@@ -320,7 +320,7 @@ static int ieee80211_open(struct net_dev
68353 err_del_interface:
68354 drv_remove_interface(local, &conf);
68355 err_stop:
68356- if (!local->open_count)
68357+ if (!local_read(&local->open_count))
68358 drv_stop(local);
68359 err_del_bss:
68360 sdata->bss = NULL;
68361@@ -420,7 +420,7 @@ static int ieee80211_stop(struct net_dev
68362 WARN_ON(!list_empty(&sdata->u.ap.vlans));
68363 }
68364
68365- local->open_count--;
68366+ local_dec(&local->open_count);
68367
68368 switch (sdata->vif.type) {
68369 case NL80211_IFTYPE_AP_VLAN:
68370@@ -526,7 +526,7 @@ static int ieee80211_stop(struct net_dev
68371
68372 ieee80211_recalc_ps(local, -1);
68373
68374- if (local->open_count == 0) {
68375+ if (local_read(&local->open_count) == 0) {
68376 ieee80211_clear_tx_pending(local);
68377 ieee80211_stop_device(local);
68378
68379diff -urNp linux-2.6.32.41/net/mac80211/main.c linux-2.6.32.41/net/mac80211/main.c
68380--- linux-2.6.32.41/net/mac80211/main.c 2011-05-10 22:12:02.000000000 -0400
68381+++ linux-2.6.32.41/net/mac80211/main.c 2011-05-10 22:12:34.000000000 -0400
68382@@ -145,7 +145,7 @@ int ieee80211_hw_config(struct ieee80211
68383 local->hw.conf.power_level = power;
68384 }
68385
68386- if (changed && local->open_count) {
68387+ if (changed && local_read(&local->open_count)) {
68388 ret = drv_config(local, changed);
68389 /*
68390 * Goal:
68391diff -urNp linux-2.6.32.41/net/mac80211/mlme.c linux-2.6.32.41/net/mac80211/mlme.c
68392--- linux-2.6.32.41/net/mac80211/mlme.c 2011-03-27 14:31:47.000000000 -0400
68393+++ linux-2.6.32.41/net/mac80211/mlme.c 2011-05-16 21:46:57.000000000 -0400
68394@@ -1438,6 +1438,8 @@ ieee80211_rx_mgmt_assoc_resp(struct ieee
68395 bool have_higher_than_11mbit = false, newsta = false;
68396 u16 ap_ht_cap_flags;
68397
68398+ pax_track_stack();
68399+
68400 /*
68401 * AssocResp and ReassocResp have identical structure, so process both
68402 * of them in this function.
68403diff -urNp linux-2.6.32.41/net/mac80211/pm.c linux-2.6.32.41/net/mac80211/pm.c
68404--- linux-2.6.32.41/net/mac80211/pm.c 2011-03-27 14:31:47.000000000 -0400
68405+++ linux-2.6.32.41/net/mac80211/pm.c 2011-04-17 15:56:46.000000000 -0400
68406@@ -107,7 +107,7 @@ int __ieee80211_suspend(struct ieee80211
68407 }
68408
68409 /* stop hardware - this must stop RX */
68410- if (local->open_count)
68411+ if (local_read(&local->open_count))
68412 ieee80211_stop_device(local);
68413
68414 local->suspended = true;
68415diff -urNp linux-2.6.32.41/net/mac80211/rate.c linux-2.6.32.41/net/mac80211/rate.c
68416--- linux-2.6.32.41/net/mac80211/rate.c 2011-03-27 14:31:47.000000000 -0400
68417+++ linux-2.6.32.41/net/mac80211/rate.c 2011-04-17 15:56:46.000000000 -0400
68418@@ -287,7 +287,7 @@ int ieee80211_init_rate_ctrl_alg(struct
68419 struct rate_control_ref *ref, *old;
68420
68421 ASSERT_RTNL();
68422- if (local->open_count)
68423+ if (local_read(&local->open_count))
68424 return -EBUSY;
68425
68426 ref = rate_control_alloc(name, local);
68427diff -urNp linux-2.6.32.41/net/mac80211/tx.c linux-2.6.32.41/net/mac80211/tx.c
68428--- linux-2.6.32.41/net/mac80211/tx.c 2011-03-27 14:31:47.000000000 -0400
68429+++ linux-2.6.32.41/net/mac80211/tx.c 2011-04-17 15:56:46.000000000 -0400
68430@@ -173,7 +173,7 @@ static __le16 ieee80211_duration(struct
68431 return cpu_to_le16(dur);
68432 }
68433
68434-static int inline is_ieee80211_device(struct ieee80211_local *local,
68435+static inline int is_ieee80211_device(struct ieee80211_local *local,
68436 struct net_device *dev)
68437 {
68438 return local == wdev_priv(dev->ieee80211_ptr);
68439diff -urNp linux-2.6.32.41/net/mac80211/util.c linux-2.6.32.41/net/mac80211/util.c
68440--- linux-2.6.32.41/net/mac80211/util.c 2011-03-27 14:31:47.000000000 -0400
68441+++ linux-2.6.32.41/net/mac80211/util.c 2011-04-17 15:56:46.000000000 -0400
68442@@ -1042,7 +1042,7 @@ int ieee80211_reconfig(struct ieee80211_
68443 local->resuming = true;
68444
68445 /* restart hardware */
68446- if (local->open_count) {
68447+ if (local_read(&local->open_count)) {
68448 /*
68449 * Upon resume hardware can sometimes be goofy due to
68450 * various platform / driver / bus issues, so restarting
68451diff -urNp linux-2.6.32.41/net/netfilter/ipvs/ip_vs_app.c linux-2.6.32.41/net/netfilter/ipvs/ip_vs_app.c
68452--- linux-2.6.32.41/net/netfilter/ipvs/ip_vs_app.c 2011-03-27 14:31:47.000000000 -0400
68453+++ linux-2.6.32.41/net/netfilter/ipvs/ip_vs_app.c 2011-05-17 19:26:34.000000000 -0400
68454@@ -564,7 +564,7 @@ static const struct file_operations ip_v
68455 .open = ip_vs_app_open,
68456 .read = seq_read,
68457 .llseek = seq_lseek,
68458- .release = seq_release,
68459+ .release = seq_release_net,
68460 };
68461 #endif
68462
68463diff -urNp linux-2.6.32.41/net/netfilter/ipvs/ip_vs_conn.c linux-2.6.32.41/net/netfilter/ipvs/ip_vs_conn.c
68464--- linux-2.6.32.41/net/netfilter/ipvs/ip_vs_conn.c 2011-03-27 14:31:47.000000000 -0400
68465+++ linux-2.6.32.41/net/netfilter/ipvs/ip_vs_conn.c 2011-05-17 19:26:34.000000000 -0400
68466@@ -453,10 +453,10 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, s
68467 /* if the connection is not template and is created
68468 * by sync, preserve the activity flag.
68469 */
68470- cp->flags |= atomic_read(&dest->conn_flags) &
68471+ cp->flags |= atomic_read_unchecked(&dest->conn_flags) &
68472 (~IP_VS_CONN_F_INACTIVE);
68473 else
68474- cp->flags |= atomic_read(&dest->conn_flags);
68475+ cp->flags |= atomic_read_unchecked(&dest->conn_flags);
68476 cp->dest = dest;
68477
68478 IP_VS_DBG_BUF(7, "Bind-dest %s c:%s:%d v:%s:%d "
68479@@ -723,7 +723,7 @@ ip_vs_conn_new(int af, int proto, const
68480 atomic_set(&cp->refcnt, 1);
68481
68482 atomic_set(&cp->n_control, 0);
68483- atomic_set(&cp->in_pkts, 0);
68484+ atomic_set_unchecked(&cp->in_pkts, 0);
68485
68486 atomic_inc(&ip_vs_conn_count);
68487 if (flags & IP_VS_CONN_F_NO_CPORT)
68488@@ -871,7 +871,7 @@ static const struct file_operations ip_v
68489 .open = ip_vs_conn_open,
68490 .read = seq_read,
68491 .llseek = seq_lseek,
68492- .release = seq_release,
68493+ .release = seq_release_net,
68494 };
68495
68496 static const char *ip_vs_origin_name(unsigned flags)
68497@@ -934,7 +934,7 @@ static const struct file_operations ip_v
68498 .open = ip_vs_conn_sync_open,
68499 .read = seq_read,
68500 .llseek = seq_lseek,
68501- .release = seq_release,
68502+ .release = seq_release_net,
68503 };
68504
68505 #endif
68506@@ -961,7 +961,7 @@ static inline int todrop_entry(struct ip
68507
68508 /* Don't drop the entry if its number of incoming packets is not
68509 located in [0, 8] */
68510- i = atomic_read(&cp->in_pkts);
68511+ i = atomic_read_unchecked(&cp->in_pkts);
68512 if (i > 8 || i < 0) return 0;
68513
68514 if (!todrop_rate[i]) return 0;
68515diff -urNp linux-2.6.32.41/net/netfilter/ipvs/ip_vs_core.c linux-2.6.32.41/net/netfilter/ipvs/ip_vs_core.c
68516--- linux-2.6.32.41/net/netfilter/ipvs/ip_vs_core.c 2011-03-27 14:31:47.000000000 -0400
68517+++ linux-2.6.32.41/net/netfilter/ipvs/ip_vs_core.c 2011-05-04 17:56:28.000000000 -0400
68518@@ -485,7 +485,7 @@ int ip_vs_leave(struct ip_vs_service *sv
68519 ret = cp->packet_xmit(skb, cp, pp);
68520 /* do not touch skb anymore */
68521
68522- atomic_inc(&cp->in_pkts);
68523+ atomic_inc_unchecked(&cp->in_pkts);
68524 ip_vs_conn_put(cp);
68525 return ret;
68526 }
68527@@ -1357,7 +1357,7 @@ ip_vs_in(unsigned int hooknum, struct sk
68528 * Sync connection if it is about to close to
68529 * encorage the standby servers to update the connections timeout
68530 */
68531- pkts = atomic_add_return(1, &cp->in_pkts);
68532+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
68533 if (af == AF_INET &&
68534 (ip_vs_sync_state & IP_VS_STATE_MASTER) &&
68535 (((cp->protocol != IPPROTO_TCP ||
68536diff -urNp linux-2.6.32.41/net/netfilter/ipvs/ip_vs_ctl.c linux-2.6.32.41/net/netfilter/ipvs/ip_vs_ctl.c
68537--- linux-2.6.32.41/net/netfilter/ipvs/ip_vs_ctl.c 2011-03-27 14:31:47.000000000 -0400
68538+++ linux-2.6.32.41/net/netfilter/ipvs/ip_vs_ctl.c 2011-05-17 19:26:34.000000000 -0400
68539@@ -792,7 +792,7 @@ __ip_vs_update_dest(struct ip_vs_service
68540 ip_vs_rs_hash(dest);
68541 write_unlock_bh(&__ip_vs_rs_lock);
68542 }
68543- atomic_set(&dest->conn_flags, conn_flags);
68544+ atomic_set_unchecked(&dest->conn_flags, conn_flags);
68545
68546 /* bind the service */
68547 if (!dest->svc) {
68548@@ -1888,7 +1888,7 @@ static int ip_vs_info_seq_show(struct se
68549 " %-7s %-6d %-10d %-10d\n",
68550 &dest->addr.in6,
68551 ntohs(dest->port),
68552- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
68553+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
68554 atomic_read(&dest->weight),
68555 atomic_read(&dest->activeconns),
68556 atomic_read(&dest->inactconns));
68557@@ -1899,7 +1899,7 @@ static int ip_vs_info_seq_show(struct se
68558 "%-7s %-6d %-10d %-10d\n",
68559 ntohl(dest->addr.ip),
68560 ntohs(dest->port),
68561- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
68562+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
68563 atomic_read(&dest->weight),
68564 atomic_read(&dest->activeconns),
68565 atomic_read(&dest->inactconns));
68566@@ -1927,7 +1927,7 @@ static const struct file_operations ip_v
68567 .open = ip_vs_info_open,
68568 .read = seq_read,
68569 .llseek = seq_lseek,
68570- .release = seq_release_private,
68571+ .release = seq_release_net,
68572 };
68573
68574 #endif
68575@@ -1976,7 +1976,7 @@ static const struct file_operations ip_v
68576 .open = ip_vs_stats_seq_open,
68577 .read = seq_read,
68578 .llseek = seq_lseek,
68579- .release = single_release,
68580+ .release = single_release_net,
68581 };
68582
68583 #endif
68584@@ -2292,7 +2292,7 @@ __ip_vs_get_dest_entries(const struct ip
68585
68586 entry.addr = dest->addr.ip;
68587 entry.port = dest->port;
68588- entry.conn_flags = atomic_read(&dest->conn_flags);
68589+ entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
68590 entry.weight = atomic_read(&dest->weight);
68591 entry.u_threshold = dest->u_threshold;
68592 entry.l_threshold = dest->l_threshold;
68593@@ -2353,6 +2353,8 @@ do_ip_vs_get_ctl(struct sock *sk, int cm
68594 unsigned char arg[128];
68595 int ret = 0;
68596
68597+ pax_track_stack();
68598+
68599 if (!capable(CAP_NET_ADMIN))
68600 return -EPERM;
68601
68602@@ -2802,7 +2804,7 @@ static int ip_vs_genl_fill_dest(struct s
68603 NLA_PUT_U16(skb, IPVS_DEST_ATTR_PORT, dest->port);
68604
68605 NLA_PUT_U32(skb, IPVS_DEST_ATTR_FWD_METHOD,
68606- atomic_read(&dest->conn_flags) & IP_VS_CONN_F_FWD_MASK);
68607+ atomic_read_unchecked(&dest->conn_flags) & IP_VS_CONN_F_FWD_MASK);
68608 NLA_PUT_U32(skb, IPVS_DEST_ATTR_WEIGHT, atomic_read(&dest->weight));
68609 NLA_PUT_U32(skb, IPVS_DEST_ATTR_U_THRESH, dest->u_threshold);
68610 NLA_PUT_U32(skb, IPVS_DEST_ATTR_L_THRESH, dest->l_threshold);
68611diff -urNp linux-2.6.32.41/net/netfilter/ipvs/ip_vs_sync.c linux-2.6.32.41/net/netfilter/ipvs/ip_vs_sync.c
68612--- linux-2.6.32.41/net/netfilter/ipvs/ip_vs_sync.c 2011-03-27 14:31:47.000000000 -0400
68613+++ linux-2.6.32.41/net/netfilter/ipvs/ip_vs_sync.c 2011-05-04 17:56:28.000000000 -0400
68614@@ -438,7 +438,7 @@ static void ip_vs_process_message(const
68615
68616 if (opt)
68617 memcpy(&cp->in_seq, opt, sizeof(*opt));
68618- atomic_set(&cp->in_pkts, sysctl_ip_vs_sync_threshold[0]);
68619+ atomic_set_unchecked(&cp->in_pkts, sysctl_ip_vs_sync_threshold[0]);
68620 cp->state = state;
68621 cp->old_state = cp->state;
68622 /*
68623diff -urNp linux-2.6.32.41/net/netfilter/ipvs/ip_vs_xmit.c linux-2.6.32.41/net/netfilter/ipvs/ip_vs_xmit.c
68624--- linux-2.6.32.41/net/netfilter/ipvs/ip_vs_xmit.c 2011-03-27 14:31:47.000000000 -0400
68625+++ linux-2.6.32.41/net/netfilter/ipvs/ip_vs_xmit.c 2011-05-04 17:56:28.000000000 -0400
68626@@ -875,7 +875,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, str
68627 else
68628 rc = NF_ACCEPT;
68629 /* do not touch skb anymore */
68630- atomic_inc(&cp->in_pkts);
68631+ atomic_inc_unchecked(&cp->in_pkts);
68632 goto out;
68633 }
68634
68635@@ -949,7 +949,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb,
68636 else
68637 rc = NF_ACCEPT;
68638 /* do not touch skb anymore */
68639- atomic_inc(&cp->in_pkts);
68640+ atomic_inc_unchecked(&cp->in_pkts);
68641 goto out;
68642 }
68643
68644diff -urNp linux-2.6.32.41/net/netfilter/Kconfig linux-2.6.32.41/net/netfilter/Kconfig
68645--- linux-2.6.32.41/net/netfilter/Kconfig 2011-03-27 14:31:47.000000000 -0400
68646+++ linux-2.6.32.41/net/netfilter/Kconfig 2011-04-17 15:56:46.000000000 -0400
68647@@ -635,6 +635,16 @@ config NETFILTER_XT_MATCH_ESP
68648
68649 To compile it as a module, choose M here. If unsure, say N.
68650
68651+config NETFILTER_XT_MATCH_GRADM
68652+ tristate '"gradm" match support'
68653+ depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
68654+ depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
68655+ ---help---
68656+ The gradm match allows to match on grsecurity RBAC being enabled.
68657+ It is useful when iptables rules are applied early on bootup to
68658+ prevent connections to the machine (except from a trusted host)
68659+ while the RBAC system is disabled.
68660+
68661 config NETFILTER_XT_MATCH_HASHLIMIT
68662 tristate '"hashlimit" match support'
68663 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
68664diff -urNp linux-2.6.32.41/net/netfilter/Makefile linux-2.6.32.41/net/netfilter/Makefile
68665--- linux-2.6.32.41/net/netfilter/Makefile 2011-03-27 14:31:47.000000000 -0400
68666+++ linux-2.6.32.41/net/netfilter/Makefile 2011-04-17 15:56:46.000000000 -0400
68667@@ -68,6 +68,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_CONNTRAC
68668 obj-$(CONFIG_NETFILTER_XT_MATCH_DCCP) += xt_dccp.o
68669 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
68670 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
68671+obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
68672 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
68673 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
68674 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
68675diff -urNp linux-2.6.32.41/net/netfilter/nf_conntrack_netlink.c linux-2.6.32.41/net/netfilter/nf_conntrack_netlink.c
68676--- linux-2.6.32.41/net/netfilter/nf_conntrack_netlink.c 2011-03-27 14:31:47.000000000 -0400
68677+++ linux-2.6.32.41/net/netfilter/nf_conntrack_netlink.c 2011-04-17 15:56:46.000000000 -0400
68678@@ -706,7 +706,7 @@ ctnetlink_parse_tuple_proto(struct nlatt
68679 static int
68680 ctnetlink_parse_tuple(const struct nlattr * const cda[],
68681 struct nf_conntrack_tuple *tuple,
68682- enum ctattr_tuple type, u_int8_t l3num)
68683+ enum ctattr_type type, u_int8_t l3num)
68684 {
68685 struct nlattr *tb[CTA_TUPLE_MAX+1];
68686 int err;
68687diff -urNp linux-2.6.32.41/net/netfilter/nfnetlink_log.c linux-2.6.32.41/net/netfilter/nfnetlink_log.c
68688--- linux-2.6.32.41/net/netfilter/nfnetlink_log.c 2011-03-27 14:31:47.000000000 -0400
68689+++ linux-2.6.32.41/net/netfilter/nfnetlink_log.c 2011-05-04 17:56:28.000000000 -0400
68690@@ -68,7 +68,7 @@ struct nfulnl_instance {
68691 };
68692
68693 static DEFINE_RWLOCK(instances_lock);
68694-static atomic_t global_seq;
68695+static atomic_unchecked_t global_seq;
68696
68697 #define INSTANCE_BUCKETS 16
68698 static struct hlist_head instance_table[INSTANCE_BUCKETS];
68699@@ -493,7 +493,7 @@ __build_packet_message(struct nfulnl_ins
68700 /* global sequence number */
68701 if (inst->flags & NFULNL_CFG_F_SEQ_GLOBAL)
68702 NLA_PUT_BE32(inst->skb, NFULA_SEQ_GLOBAL,
68703- htonl(atomic_inc_return(&global_seq)));
68704+ htonl(atomic_inc_return_unchecked(&global_seq)));
68705
68706 if (data_len) {
68707 struct nlattr *nla;
68708diff -urNp linux-2.6.32.41/net/netfilter/xt_gradm.c linux-2.6.32.41/net/netfilter/xt_gradm.c
68709--- linux-2.6.32.41/net/netfilter/xt_gradm.c 1969-12-31 19:00:00.000000000 -0500
68710+++ linux-2.6.32.41/net/netfilter/xt_gradm.c 2011-04-17 15:56:46.000000000 -0400
68711@@ -0,0 +1,51 @@
68712+/*
68713+ * gradm match for netfilter
68714