1 diff -urNp linux-2.6.37/arch/alpha/include/asm/dma-mapping.h linux-2.6.37/arch/alpha/include/asm/dma-mapping.h
2 --- linux-2.6.37/arch/alpha/include/asm/dma-mapping.h 2011-01-04 19:50:19.000000000 -0500
3 +++ linux-2.6.37/arch/alpha/include/asm/dma-mapping.h 2011-01-17 02:41:00.000000000 -0500
6 #include <linux/dma-attrs.h>
8 -extern struct dma_map_ops *dma_ops;
9 +extern const struct dma_map_ops *dma_ops;
11 -static inline struct dma_map_ops *get_dma_ops(struct device *dev)
12 +static inline const struct dma_map_ops *get_dma_ops(struct device *dev)
16 diff -urNp linux-2.6.37/arch/alpha/include/asm/elf.h linux-2.6.37/arch/alpha/include/asm/elf.h
17 --- linux-2.6.37/arch/alpha/include/asm/elf.h 2011-01-04 19:50:19.000000000 -0500
18 +++ linux-2.6.37/arch/alpha/include/asm/elf.h 2011-01-17 02:41:00.000000000 -0500
19 @@ -90,6 +90,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_N
21 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
23 +#ifdef CONFIG_PAX_ASLR
24 +#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
26 +#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
27 +#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
30 /* $0 is set by ld.so to a pointer to a function which might be
31 registered using atexit. This provides a mean for the dynamic
32 linker to call DT_FINI functions for shared libraries that have
33 diff -urNp linux-2.6.37/arch/alpha/include/asm/pgtable.h linux-2.6.37/arch/alpha/include/asm/pgtable.h
34 --- linux-2.6.37/arch/alpha/include/asm/pgtable.h 2011-01-04 19:50:19.000000000 -0500
35 +++ linux-2.6.37/arch/alpha/include/asm/pgtable.h 2011-01-17 02:41:00.000000000 -0500
36 @@ -101,6 +101,17 @@ struct vm_area_struct;
37 #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
38 #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
39 #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
41 +#ifdef CONFIG_PAX_PAGEEXEC
42 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
43 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
44 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
46 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
47 +# define PAGE_COPY_NOEXEC PAGE_COPY
48 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
51 #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
53 #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
54 diff -urNp linux-2.6.37/arch/alpha/kernel/module.c linux-2.6.37/arch/alpha/kernel/module.c
55 --- linux-2.6.37/arch/alpha/kernel/module.c 2011-01-04 19:50:19.000000000 -0500
56 +++ linux-2.6.37/arch/alpha/kernel/module.c 2011-01-17 02:41:00.000000000 -0500
57 @@ -182,7 +182,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs,
59 /* The small sections were sorted to the end of the segment.
60 The following should definitely cover them. */
61 - gp = (u64)me->module_core + me->core_size - 0x8000;
62 + gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
63 got = sechdrs[me->arch.gotsecindex].sh_addr;
65 for (i = 0; i < n; i++) {
66 diff -urNp linux-2.6.37/arch/alpha/kernel/osf_sys.c linux-2.6.37/arch/alpha/kernel/osf_sys.c
67 --- linux-2.6.37/arch/alpha/kernel/osf_sys.c 2011-01-04 19:50:19.000000000 -0500
68 +++ linux-2.6.37/arch/alpha/kernel/osf_sys.c 2011-01-17 02:41:00.000000000 -0500
69 @@ -1165,7 +1165,7 @@ arch_get_unmapped_area_1(unsigned long a
70 /* At this point: (!vma || addr < vma->vm_end). */
71 if (limit - len < addr)
73 - if (!vma || addr + len <= vma->vm_start)
74 + if (check_heap_stack_gap(vma, addr, len))
78 @@ -1201,6 +1201,10 @@ arch_get_unmapped_area(struct file *filp
79 merely specific addresses, but regions of memory -- perhaps
80 this feature should be incorporated into all ports? */
82 +#ifdef CONFIG_PAX_RANDMMAP
83 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
87 addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
88 if (addr != (unsigned long) -ENOMEM)
89 @@ -1208,8 +1212,8 @@ arch_get_unmapped_area(struct file *filp
92 /* Next, try allocating at TASK_UNMAPPED_BASE. */
93 - addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
95 + addr = arch_get_unmapped_area_1 (PAGE_ALIGN(current->mm->mmap_base), len, limit);
97 if (addr != (unsigned long) -ENOMEM)
100 diff -urNp linux-2.6.37/arch/alpha/kernel/pci_iommu.c linux-2.6.37/arch/alpha/kernel/pci_iommu.c
101 --- linux-2.6.37/arch/alpha/kernel/pci_iommu.c 2011-01-04 19:50:19.000000000 -0500
102 +++ linux-2.6.37/arch/alpha/kernel/pci_iommu.c 2011-01-17 02:41:00.000000000 -0500
103 @@ -950,7 +950,7 @@ static int alpha_pci_set_mask(struct dev
107 -struct dma_map_ops alpha_pci_ops = {
108 +const struct dma_map_ops alpha_pci_ops = {
109 .alloc_coherent = alpha_pci_alloc_coherent,
110 .free_coherent = alpha_pci_free_coherent,
111 .map_page = alpha_pci_map_page,
112 @@ -962,5 +962,5 @@ struct dma_map_ops alpha_pci_ops = {
113 .set_dma_mask = alpha_pci_set_mask,
116 -struct dma_map_ops *dma_ops = &alpha_pci_ops;
117 +const struct dma_map_ops *dma_ops = &alpha_pci_ops;
118 EXPORT_SYMBOL(dma_ops);
119 diff -urNp linux-2.6.37/arch/alpha/kernel/pci-noop.c linux-2.6.37/arch/alpha/kernel/pci-noop.c
120 --- linux-2.6.37/arch/alpha/kernel/pci-noop.c 2011-01-04 19:50:19.000000000 -0500
121 +++ linux-2.6.37/arch/alpha/kernel/pci-noop.c 2011-01-17 02:41:00.000000000 -0500
122 @@ -173,7 +173,7 @@ static int alpha_noop_set_mask(struct de
126 -struct dma_map_ops alpha_noop_ops = {
127 +const struct dma_map_ops alpha_noop_ops = {
128 .alloc_coherent = alpha_noop_alloc_coherent,
129 .free_coherent = alpha_noop_free_coherent,
130 .map_page = alpha_noop_map_page,
131 @@ -183,7 +183,7 @@ struct dma_map_ops alpha_noop_ops = {
132 .set_dma_mask = alpha_noop_set_mask,
135 -struct dma_map_ops *dma_ops = &alpha_noop_ops;
136 +const struct dma_map_ops *dma_ops = &alpha_noop_ops;
137 EXPORT_SYMBOL(dma_ops);
139 void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long maxlen)
140 diff -urNp linux-2.6.37/arch/alpha/mm/fault.c linux-2.6.37/arch/alpha/mm/fault.c
141 --- linux-2.6.37/arch/alpha/mm/fault.c 2011-01-04 19:50:19.000000000 -0500
142 +++ linux-2.6.37/arch/alpha/mm/fault.c 2011-01-17 02:41:00.000000000 -0500
143 @@ -54,6 +54,124 @@ __load_new_mm_context(struct mm_struct *
144 __reload_thread(pcb);
147 +#ifdef CONFIG_PAX_PAGEEXEC
149 + * PaX: decide what to do with offenders (regs->pc = fault address)
151 + * returns 1 when task should be killed
152 + * 2 when patched PLT trampoline was detected
153 + * 3 when unpatched PLT trampoline was detected
155 +static int pax_handle_fetch_fault(struct pt_regs *regs)
158 +#ifdef CONFIG_PAX_EMUPLT
161 + do { /* PaX: patched PLT emulation #1 */
162 + unsigned int ldah, ldq, jmp;
164 + err = get_user(ldah, (unsigned int *)regs->pc);
165 + err |= get_user(ldq, (unsigned int *)(regs->pc+4));
166 + err |= get_user(jmp, (unsigned int *)(regs->pc+8));
171 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
172 + (ldq & 0xFFFF0000U) == 0xA77B0000U &&
173 + jmp == 0x6BFB0000U)
175 + unsigned long r27, addr;
176 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
177 + unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
179 + addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
180 + err = get_user(r27, (unsigned long *)addr);
190 + do { /* PaX: patched PLT emulation #2 */
191 + unsigned int ldah, lda, br;
193 + err = get_user(ldah, (unsigned int *)regs->pc);
194 + err |= get_user(lda, (unsigned int *)(regs->pc+4));
195 + err |= get_user(br, (unsigned int *)(regs->pc+8));
200 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
201 + (lda & 0xFFFF0000U) == 0xA77B0000U &&
202 + (br & 0xFFE00000U) == 0xC3E00000U)
204 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
205 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
206 + unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
208 + regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
209 + regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
214 + do { /* PaX: unpatched PLT emulation */
217 + err = get_user(br, (unsigned int *)regs->pc);
219 + if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
220 + unsigned int br2, ldq, nop, jmp;
221 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
223 + addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
224 + err = get_user(br2, (unsigned int *)addr);
225 + err |= get_user(ldq, (unsigned int *)(addr+4));
226 + err |= get_user(nop, (unsigned int *)(addr+8));
227 + err |= get_user(jmp, (unsigned int *)(addr+12));
228 + err |= get_user(resolver, (unsigned long *)(addr+16));
233 + if (br2 == 0xC3600000U &&
234 + ldq == 0xA77B000CU &&
235 + nop == 0x47FF041FU &&
236 + jmp == 0x6B7B0000U)
238 + regs->r28 = regs->pc+4;
239 + regs->r27 = addr+16;
240 + regs->pc = resolver;
250 +void pax_report_insns(void *pc, void *sp)
254 + printk(KERN_ERR "PAX: bytes at PC: ");
255 + for (i = 0; i < 5; i++) {
257 + if (get_user(c, (unsigned int *)pc+i))
258 + printk(KERN_CONT "???????? ");
260 + printk(KERN_CONT "%08x ", c);
267 * This routine handles page faults. It determines the address,
268 @@ -131,8 +249,29 @@ do_page_fault(unsigned long address, uns
270 si_code = SEGV_ACCERR;
272 - if (!(vma->vm_flags & VM_EXEC))
273 + if (!(vma->vm_flags & VM_EXEC)) {
275 +#ifdef CONFIG_PAX_PAGEEXEC
276 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
279 + up_read(&mm->mmap_sem);
280 + switch (pax_handle_fetch_fault(regs)) {
282 +#ifdef CONFIG_PAX_EMUPLT
289 + pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
290 + do_group_exit(SIGKILL);
297 /* Allow reads even for write-only mappings */
298 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
299 diff -urNp linux-2.6.37/arch/arm/include/asm/elf.h linux-2.6.37/arch/arm/include/asm/elf.h
300 --- linux-2.6.37/arch/arm/include/asm/elf.h 2011-01-04 19:50:19.000000000 -0500
301 +++ linux-2.6.37/arch/arm/include/asm/elf.h 2011-01-17 02:41:00.000000000 -0500
302 @@ -113,7 +113,14 @@ int dump_task_regs(struct task_struct *t
303 the loader. We need to make sure that it is out of the way of the program
304 that it will "exec", and that there is sufficient room for the brk. */
306 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
307 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
309 +#ifdef CONFIG_PAX_ASLR
310 +#define PAX_ELF_ET_DYN_BASE 0x00008000UL
312 +#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
313 +#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
316 /* When the program starts, a1 contains a pointer to a function to be
317 registered with atexit, as per the SVR4 ABI. A value of 0 means we
318 @@ -123,10 +130,6 @@ int dump_task_regs(struct task_struct *t
319 extern void elf_set_personality(const struct elf32_hdr *);
320 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
323 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
324 -#define arch_randomize_brk arch_randomize_brk
326 extern int vectors_user_mapping(void);
327 #define arch_setup_additional_pages(bprm, uses_interp) vectors_user_mapping()
328 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES
329 diff -urNp linux-2.6.37/arch/arm/include/asm/kmap_types.h linux-2.6.37/arch/arm/include/asm/kmap_types.h
330 --- linux-2.6.37/arch/arm/include/asm/kmap_types.h 2011-01-04 19:50:19.000000000 -0500
331 +++ linux-2.6.37/arch/arm/include/asm/kmap_types.h 2011-01-17 02:41:00.000000000 -0500
332 @@ -21,6 +21,7 @@ enum km_type {
340 diff -urNp linux-2.6.37/arch/arm/include/asm/uaccess.h linux-2.6.37/arch/arm/include/asm/uaccess.h
341 --- linux-2.6.37/arch/arm/include/asm/uaccess.h 2011-01-04 19:50:19.000000000 -0500
342 +++ linux-2.6.37/arch/arm/include/asm/uaccess.h 2011-01-17 02:41:00.000000000 -0500
343 @@ -403,6 +403,9 @@ extern unsigned long __must_check __strn
345 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
350 if (access_ok(VERIFY_READ, from, n))
351 n = __copy_from_user(to, from, n);
352 else /* security hole - plug it */
353 @@ -412,6 +415,9 @@ static inline unsigned long __must_check
355 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
360 if (access_ok(VERIFY_WRITE, to, n))
361 n = __copy_to_user(to, from, n);
363 diff -urNp linux-2.6.37/arch/arm/kernel/kgdb.c linux-2.6.37/arch/arm/kernel/kgdb.c
364 --- linux-2.6.37/arch/arm/kernel/kgdb.c 2011-01-04 19:50:19.000000000 -0500
365 +++ linux-2.6.37/arch/arm/kernel/kgdb.c 2011-01-17 02:41:00.000000000 -0500
366 @@ -246,7 +246,7 @@ void kgdb_arch_exit(void)
367 * and we handle the normal undef case within the do_undefinstr
370 -struct kgdb_arch arch_kgdb_ops = {
371 +const struct kgdb_arch arch_kgdb_ops = {
373 .gdb_bpt_instr = {0xfe, 0xde, 0xff, 0xe7}
374 #else /* ! __ARMEB__ */
375 diff -urNp linux-2.6.37/arch/arm/kernel/process.c linux-2.6.37/arch/arm/kernel/process.c
376 --- linux-2.6.37/arch/arm/kernel/process.c 2011-01-04 19:50:19.000000000 -0500
377 +++ linux-2.6.37/arch/arm/kernel/process.c 2011-01-17 02:41:00.000000000 -0500
379 #include <linux/tick.h>
380 #include <linux/utsname.h>
381 #include <linux/uaccess.h>
382 -#include <linux/random.h>
383 #include <linux/hw_breakpoint.h>
385 #include <asm/cacheflush.h>
386 @@ -477,12 +476,6 @@ unsigned long get_wchan(struct task_stru
390 -unsigned long arch_randomize_brk(struct mm_struct *mm)
392 - unsigned long range_end = mm->brk + 0x02000000;
393 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
397 * The vectors page is always readable from user space for the
398 * atomic helpers and the signal restart code. Let's declare a mapping
399 diff -urNp linux-2.6.37/arch/arm/mach-at91/pm.c linux-2.6.37/arch/arm/mach-at91/pm.c
400 --- linux-2.6.37/arch/arm/mach-at91/pm.c 2011-01-04 19:50:19.000000000 -0500
401 +++ linux-2.6.37/arch/arm/mach-at91/pm.c 2011-01-17 02:41:00.000000000 -0500
402 @@ -301,7 +301,7 @@ static void at91_pm_end(void)
406 -static struct platform_suspend_ops at91_pm_ops ={
407 +static const struct platform_suspend_ops at91_pm_ops ={
408 .valid = at91_pm_valid_state,
409 .begin = at91_pm_begin,
410 .enter = at91_pm_enter,
411 diff -urNp linux-2.6.37/arch/arm/mach-davinci/pm.c linux-2.6.37/arch/arm/mach-davinci/pm.c
412 --- linux-2.6.37/arch/arm/mach-davinci/pm.c 2011-01-04 19:50:19.000000000 -0500
413 +++ linux-2.6.37/arch/arm/mach-davinci/pm.c 2011-01-17 02:41:00.000000000 -0500
414 @@ -110,7 +110,7 @@ static int davinci_pm_enter(suspend_stat
418 -static struct platform_suspend_ops davinci_pm_ops = {
419 +static const struct platform_suspend_ops davinci_pm_ops = {
420 .enter = davinci_pm_enter,
421 .valid = suspend_valid_only_mem,
423 diff -urNp linux-2.6.37/arch/arm/mach-imx/pm-imx27.c linux-2.6.37/arch/arm/mach-imx/pm-imx27.c
424 --- linux-2.6.37/arch/arm/mach-imx/pm-imx27.c 2011-01-04 19:50:19.000000000 -0500
425 +++ linux-2.6.37/arch/arm/mach-imx/pm-imx27.c 2011-01-17 02:41:00.000000000 -0500
426 @@ -32,7 +32,7 @@ static int mx27_suspend_enter(suspend_st
430 -static struct platform_suspend_ops mx27_suspend_ops = {
431 +static const struct platform_suspend_ops mx27_suspend_ops = {
432 .enter = mx27_suspend_enter,
433 .valid = suspend_valid_only_mem,
435 diff -urNp linux-2.6.37/arch/arm/mach-lpc32xx/pm.c linux-2.6.37/arch/arm/mach-lpc32xx/pm.c
436 --- linux-2.6.37/arch/arm/mach-lpc32xx/pm.c 2011-01-04 19:50:19.000000000 -0500
437 +++ linux-2.6.37/arch/arm/mach-lpc32xx/pm.c 2011-01-17 02:41:00.000000000 -0500
438 @@ -123,7 +123,7 @@ static int lpc32xx_pm_enter(suspend_stat
442 -static struct platform_suspend_ops lpc32xx_pm_ops = {
443 +static const struct platform_suspend_ops lpc32xx_pm_ops = {
444 .valid = suspend_valid_only_mem,
445 .enter = lpc32xx_pm_enter,
447 diff -urNp linux-2.6.37/arch/arm/mach-msm/last_radio_log.c linux-2.6.37/arch/arm/mach-msm/last_radio_log.c
448 --- linux-2.6.37/arch/arm/mach-msm/last_radio_log.c 2011-01-04 19:50:19.000000000 -0500
449 +++ linux-2.6.37/arch/arm/mach-msm/last_radio_log.c 2011-01-17 02:41:00.000000000 -0500
450 @@ -47,6 +47,7 @@ static ssize_t last_radio_log_read(struc
454 +/* cannot be const, see msm_init_last_radio_log */
455 static struct file_operations last_radio_log_fops = {
456 .read = last_radio_log_read,
457 .llseek = default_llseek,
458 diff -urNp linux-2.6.37/arch/arm/mach-omap1/pm.c linux-2.6.37/arch/arm/mach-omap1/pm.c
459 --- linux-2.6.37/arch/arm/mach-omap1/pm.c 2011-01-04 19:50:19.000000000 -0500
460 +++ linux-2.6.37/arch/arm/mach-omap1/pm.c 2011-01-17 02:41:00.000000000 -0500
461 @@ -647,7 +647,7 @@ static struct irqaction omap_wakeup_irq
465 -static struct platform_suspend_ops omap_pm_ops ={
466 +static const struct platform_suspend_ops omap_pm_ops ={
467 .prepare = omap_pm_prepare,
468 .enter = omap_pm_enter,
469 .finish = omap_pm_finish,
470 diff -urNp linux-2.6.37/arch/arm/mach-omap2/pm24xx.c linux-2.6.37/arch/arm/mach-omap2/pm24xx.c
471 --- linux-2.6.37/arch/arm/mach-omap2/pm24xx.c 2011-01-04 19:50:19.000000000 -0500
472 +++ linux-2.6.37/arch/arm/mach-omap2/pm24xx.c 2011-01-17 02:41:00.000000000 -0500
473 @@ -359,7 +359,7 @@ static void omap2_pm_end(void)
474 suspend_state = PM_SUSPEND_ON;
477 -static struct platform_suspend_ops omap_pm_ops = {
478 +static const struct platform_suspend_ops omap_pm_ops = {
479 .begin = omap2_pm_begin,
480 .prepare = omap2_pm_prepare,
481 .enter = omap2_pm_enter,
482 diff -urNp linux-2.6.37/arch/arm/mach-omap2/pm34xx.c linux-2.6.37/arch/arm/mach-omap2/pm34xx.c
483 --- linux-2.6.37/arch/arm/mach-omap2/pm34xx.c 2011-01-04 19:50:19.000000000 -0500
484 +++ linux-2.6.37/arch/arm/mach-omap2/pm34xx.c 2011-01-17 02:41:00.000000000 -0500
485 @@ -617,7 +617,7 @@ static void omap3_pm_end(void)
489 -static struct platform_suspend_ops omap_pm_ops = {
490 +static const struct platform_suspend_ops omap_pm_ops = {
491 .begin = omap3_pm_begin,
493 .prepare = omap3_pm_prepare,
494 diff -urNp linux-2.6.37/arch/arm/mach-omap2/pm44xx.c linux-2.6.37/arch/arm/mach-omap2/pm44xx.c
495 --- linux-2.6.37/arch/arm/mach-omap2/pm44xx.c 2011-01-04 19:50:19.000000000 -0500
496 +++ linux-2.6.37/arch/arm/mach-omap2/pm44xx.c 2011-01-17 02:41:00.000000000 -0500
497 @@ -75,7 +75,7 @@ static void omap4_pm_end(void)
501 -static struct platform_suspend_ops omap_pm_ops = {
502 +static const struct platform_suspend_ops omap_pm_ops = {
503 .begin = omap4_pm_begin,
505 .prepare = omap4_pm_prepare,
506 diff -urNp linux-2.6.37/arch/arm/mach-pnx4008/pm.c linux-2.6.37/arch/arm/mach-pnx4008/pm.c
507 --- linux-2.6.37/arch/arm/mach-pnx4008/pm.c 2011-01-04 19:50:19.000000000 -0500
508 +++ linux-2.6.37/arch/arm/mach-pnx4008/pm.c 2011-01-17 02:41:00.000000000 -0500
509 @@ -119,7 +119,7 @@ static int pnx4008_pm_valid(suspend_stat
510 (state == PM_SUSPEND_MEM);
513 -static struct platform_suspend_ops pnx4008_pm_ops = {
514 +static const struct platform_suspend_ops pnx4008_pm_ops = {
515 .enter = pnx4008_pm_enter,
516 .valid = pnx4008_pm_valid,
518 diff -urNp linux-2.6.37/arch/arm/mach-pxa/pm.c linux-2.6.37/arch/arm/mach-pxa/pm.c
519 --- linux-2.6.37/arch/arm/mach-pxa/pm.c 2011-01-04 19:50:19.000000000 -0500
520 +++ linux-2.6.37/arch/arm/mach-pxa/pm.c 2011-01-17 02:41:00.000000000 -0500
521 @@ -96,7 +96,7 @@ void pxa_pm_finish(void)
522 pxa_cpu_pm_fns->finish();
525 -static struct platform_suspend_ops pxa_pm_ops = {
526 +static const struct platform_suspend_ops pxa_pm_ops = {
527 .valid = pxa_pm_valid,
528 .enter = pxa_pm_enter,
529 .prepare = pxa_pm_prepare,
530 diff -urNp linux-2.6.37/arch/arm/mach-pxa/sharpsl_pm.c linux-2.6.37/arch/arm/mach-pxa/sharpsl_pm.c
531 --- linux-2.6.37/arch/arm/mach-pxa/sharpsl_pm.c 2011-01-04 19:50:19.000000000 -0500
532 +++ linux-2.6.37/arch/arm/mach-pxa/sharpsl_pm.c 2011-01-17 02:41:00.000000000 -0500
533 @@ -868,7 +868,7 @@ static void sharpsl_apm_get_power_status
537 -static struct platform_suspend_ops sharpsl_pm_ops = {
538 +static const struct platform_suspend_ops sharpsl_pm_ops = {
539 .prepare = pxa_pm_prepare,
540 .finish = pxa_pm_finish,
541 .enter = corgi_pxa_pm_enter,
542 diff -urNp linux-2.6.37/arch/arm/mach-sa1100/pm.c linux-2.6.37/arch/arm/mach-sa1100/pm.c
543 --- linux-2.6.37/arch/arm/mach-sa1100/pm.c 2011-01-04 19:50:19.000000000 -0500
544 +++ linux-2.6.37/arch/arm/mach-sa1100/pm.c 2011-01-17 02:41:00.000000000 -0500
545 @@ -120,7 +120,7 @@ unsigned long sleep_phys_sp(void *sp)
546 return virt_to_phys(sp);
549 -static struct platform_suspend_ops sa11x0_pm_ops = {
550 +static const struct platform_suspend_ops sa11x0_pm_ops = {
551 .enter = sa11x0_pm_enter,
552 .valid = suspend_valid_only_mem,
554 diff -urNp linux-2.6.37/arch/arm/mm/fault.c linux-2.6.37/arch/arm/mm/fault.c
555 --- linux-2.6.37/arch/arm/mm/fault.c 2011-01-04 19:50:19.000000000 -0500
556 +++ linux-2.6.37/arch/arm/mm/fault.c 2011-01-17 02:41:00.000000000 -0500
557 @@ -167,6 +167,13 @@ __do_user_fault(struct task_struct *tsk,
561 +#ifdef CONFIG_PAX_PAGEEXEC
562 + if (fsr & FSR_LNX_PF) {
563 + pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
564 + do_group_exit(SIGKILL);
568 tsk->thread.address = addr;
569 tsk->thread.error_code = fsr;
570 tsk->thread.trap_no = 14;
571 @@ -364,6 +371,33 @@ do_page_fault(unsigned long addr, unsign
573 #endif /* CONFIG_MMU */
575 +#ifdef CONFIG_PAX_PAGEEXEC
576 +void pax_report_insns(void *pc, void *sp)
580 + printk(KERN_ERR "PAX: bytes at PC: ");
581 + for (i = 0; i < 20; i++) {
583 + if (get_user(c, (__force unsigned char __user *)pc+i))
584 + printk(KERN_CONT "?? ");
586 + printk(KERN_CONT "%02x ", c);
590 + printk(KERN_ERR "PAX: bytes at SP-4: ");
591 + for (i = -1; i < 20; i++) {
593 + if (get_user(c, (__force unsigned long __user *)sp+i))
594 + printk(KERN_CONT "???????? ");
596 + printk(KERN_CONT "%08lx ", c);
603 * First Level Translation Fault Handler
605 diff -urNp linux-2.6.37/arch/arm/mm/mmap.c linux-2.6.37/arch/arm/mm/mmap.c
606 --- linux-2.6.37/arch/arm/mm/mmap.c 2011-01-04 19:50:19.000000000 -0500
607 +++ linux-2.6.37/arch/arm/mm/mmap.c 2011-01-17 02:41:00.000000000 -0500
608 @@ -64,6 +64,10 @@ arch_get_unmapped_area(struct file *filp
612 +#ifdef CONFIG_PAX_RANDMMAP
613 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
618 addr = COLOUR_ALIGN(addr, pgoff);
619 @@ -71,15 +75,14 @@ arch_get_unmapped_area(struct file *filp
620 addr = PAGE_ALIGN(addr);
622 vma = find_vma(mm, addr);
623 - if (TASK_SIZE - len >= addr &&
624 - (!vma || addr + len <= vma->vm_start))
625 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
628 if (len > mm->cached_hole_size) {
629 - start_addr = addr = mm->free_area_cache;
630 + start_addr = addr = mm->free_area_cache;
632 - start_addr = addr = TASK_UNMAPPED_BASE;
633 - mm->cached_hole_size = 0;
634 + start_addr = addr = mm->mmap_base;
635 + mm->cached_hole_size = 0;
637 /* 8 bits of randomness in 20 address space bits */
638 if (current->flags & PF_RANDOMIZE)
639 @@ -98,14 +101,14 @@ full_search:
640 * Start a new search - just in case we missed
643 - if (start_addr != TASK_UNMAPPED_BASE) {
644 - start_addr = addr = TASK_UNMAPPED_BASE;
645 + if (start_addr != mm->mmap_base) {
646 + start_addr = addr = mm->mmap_base;
647 mm->cached_hole_size = 0;
652 - if (!vma || addr + len <= vma->vm_start) {
653 + if (check_heap_stack_gap(vma, addr, len)) {
655 * Remember the place where we stopped the search:
657 diff -urNp linux-2.6.37/arch/arm/plat-samsung/pm.c linux-2.6.37/arch/arm/plat-samsung/pm.c
658 --- linux-2.6.37/arch/arm/plat-samsung/pm.c 2011-01-04 19:50:19.000000000 -0500
659 +++ linux-2.6.37/arch/arm/plat-samsung/pm.c 2011-01-17 02:41:00.000000000 -0500
660 @@ -355,7 +355,7 @@ static void s3c_pm_finish(void)
661 s3c_pm_check_cleanup();
664 -static struct platform_suspend_ops s3c_pm_ops = {
665 +static const struct platform_suspend_ops s3c_pm_ops = {
666 .enter = s3c_pm_enter,
667 .prepare = s3c_pm_prepare,
668 .finish = s3c_pm_finish,
669 diff -urNp linux-2.6.37/arch/avr32/include/asm/elf.h linux-2.6.37/arch/avr32/include/asm/elf.h
670 --- linux-2.6.37/arch/avr32/include/asm/elf.h 2011-01-04 19:50:19.000000000 -0500
671 +++ linux-2.6.37/arch/avr32/include/asm/elf.h 2011-01-17 02:41:00.000000000 -0500
672 @@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpreg
673 the loader. We need to make sure that it is out of the way of the program
674 that it will "exec", and that there is sufficient room for the brk. */
676 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
677 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
679 +#ifdef CONFIG_PAX_ASLR
680 +#define PAX_ELF_ET_DYN_BASE 0x00001000UL
682 +#define PAX_DELTA_MMAP_LEN 15
683 +#define PAX_DELTA_STACK_LEN 15
686 /* This yields a mask that user programs can use to figure out what
687 instruction set this CPU supports. This could be done in user space,
688 diff -urNp linux-2.6.37/arch/avr32/include/asm/kmap_types.h linux-2.6.37/arch/avr32/include/asm/kmap_types.h
689 --- linux-2.6.37/arch/avr32/include/asm/kmap_types.h 2011-01-04 19:50:19.000000000 -0500
690 +++ linux-2.6.37/arch/avr32/include/asm/kmap_types.h 2011-01-17 02:41:00.000000000 -0500
691 @@ -22,7 +22,8 @@ D(10) KM_IRQ0,
701 diff -urNp linux-2.6.37/arch/avr32/mach-at32ap/pm.c linux-2.6.37/arch/avr32/mach-at32ap/pm.c
702 --- linux-2.6.37/arch/avr32/mach-at32ap/pm.c 2011-01-04 19:50:19.000000000 -0500
703 +++ linux-2.6.37/arch/avr32/mach-at32ap/pm.c 2011-01-17 02:41:00.000000000 -0500
704 @@ -176,7 +176,7 @@ out:
708 -static struct platform_suspend_ops avr32_pm_ops = {
709 +static const struct platform_suspend_ops avr32_pm_ops = {
710 .valid = avr32_pm_valid_state,
711 .enter = avr32_pm_enter,
713 diff -urNp linux-2.6.37/arch/avr32/mm/fault.c linux-2.6.37/arch/avr32/mm/fault.c
714 --- linux-2.6.37/arch/avr32/mm/fault.c 2011-01-04 19:50:19.000000000 -0500
715 +++ linux-2.6.37/arch/avr32/mm/fault.c 2011-01-17 02:41:00.000000000 -0500
716 @@ -41,6 +41,23 @@ static inline int notify_page_fault(stru
718 int exception_trace = 1;
720 +#ifdef CONFIG_PAX_PAGEEXEC
721 +void pax_report_insns(void *pc, void *sp)
725 + printk(KERN_ERR "PAX: bytes at PC: ");
726 + for (i = 0; i < 20; i++) {
728 + if (get_user(c, (unsigned char *)pc+i))
729 + printk(KERN_CONT "???????? ");
731 + printk(KERN_CONT "%02x ", c);
738 * This routine handles page faults. It determines the address and the
739 * problem, and then passes it off to one of the appropriate routines.
740 @@ -156,6 +173,16 @@ bad_area:
741 up_read(&mm->mmap_sem);
743 if (user_mode(regs)) {
745 +#ifdef CONFIG_PAX_PAGEEXEC
746 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
747 + if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
748 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
749 + do_group_exit(SIGKILL);
754 if (exception_trace && printk_ratelimit())
755 printk("%s%s[%d]: segfault at %08lx pc %08lx "
756 "sp %08lx ecr %lu\n",
757 diff -urNp linux-2.6.37/arch/blackfin/kernel/kgdb.c linux-2.6.37/arch/blackfin/kernel/kgdb.c
758 --- linux-2.6.37/arch/blackfin/kernel/kgdb.c 2011-01-04 19:50:19.000000000 -0500
759 +++ linux-2.6.37/arch/blackfin/kernel/kgdb.c 2011-01-17 02:41:00.000000000 -0500
760 @@ -397,7 +397,7 @@ int kgdb_arch_handle_exception(int vecto
761 return -1; /* this means that we do not want to exit from the handler */
764 -struct kgdb_arch arch_kgdb_ops = {
765 +const struct kgdb_arch arch_kgdb_ops = {
766 .gdb_bpt_instr = {0xa1},
768 .flags = KGDB_HW_BREAKPOINT|KGDB_THR_PROC_SWAP,
769 diff -urNp linux-2.6.37/arch/blackfin/mach-common/pm.c linux-2.6.37/arch/blackfin/mach-common/pm.c
770 --- linux-2.6.37/arch/blackfin/mach-common/pm.c 2011-01-04 19:50:19.000000000 -0500
771 +++ linux-2.6.37/arch/blackfin/mach-common/pm.c 2011-01-17 02:41:00.000000000 -0500
772 @@ -233,7 +233,7 @@ static int bfin_pm_enter(suspend_state_t
776 -struct platform_suspend_ops bfin_pm_ops = {
777 +const struct platform_suspend_ops bfin_pm_ops = {
778 .enter = bfin_pm_enter,
779 .valid = bfin_pm_valid,
781 diff -urNp linux-2.6.37/arch/blackfin/mm/maccess.c linux-2.6.37/arch/blackfin/mm/maccess.c
782 --- linux-2.6.37/arch/blackfin/mm/maccess.c 2011-01-04 19:50:19.000000000 -0500
783 +++ linux-2.6.37/arch/blackfin/mm/maccess.c 2011-01-17 02:41:00.000000000 -0500
784 @@ -16,7 +16,7 @@ static int validate_memory_access_addres
785 return bfin_mem_access_type(addr, size);
788 -long probe_kernel_read(void *dst, void *src, size_t size)
789 +long probe_kernel_read(void *dst, const void *src, size_t size)
791 unsigned long lsrc = (unsigned long)src;
793 @@ -55,7 +55,7 @@ long probe_kernel_read(void *dst, void *
797 -long probe_kernel_write(void *dst, void *src, size_t size)
798 +long probe_kernel_write(void *dst, const void *src, size_t size)
800 unsigned long ldst = (unsigned long)dst;
802 diff -urNp linux-2.6.37/arch/frv/include/asm/kmap_types.h linux-2.6.37/arch/frv/include/asm/kmap_types.h
803 --- linux-2.6.37/arch/frv/include/asm/kmap_types.h 2011-01-04 19:50:19.000000000 -0500
804 +++ linux-2.6.37/arch/frv/include/asm/kmap_types.h 2011-01-17 02:41:00.000000000 -0500
805 @@ -23,6 +23,7 @@ enum km_type {
813 diff -urNp linux-2.6.37/arch/frv/mm/elf-fdpic.c linux-2.6.37/arch/frv/mm/elf-fdpic.c
814 --- linux-2.6.37/arch/frv/mm/elf-fdpic.c 2011-01-04 19:50:19.000000000 -0500
815 +++ linux-2.6.37/arch/frv/mm/elf-fdpic.c 2011-01-17 02:41:00.000000000 -0500
816 @@ -73,8 +73,7 @@ unsigned long arch_get_unmapped_area(str
818 addr = PAGE_ALIGN(addr);
819 vma = find_vma(current->mm, addr);
820 - if (TASK_SIZE - len >= addr &&
821 - (!vma || addr + len <= vma->vm_start))
822 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
826 @@ -89,7 +88,7 @@ unsigned long arch_get_unmapped_area(str
827 for (; vma; vma = vma->vm_next) {
830 - if (addr + len <= vma->vm_start)
831 + if (check_heap_stack_gap(vma, addr, len))
835 @@ -104,7 +103,7 @@ unsigned long arch_get_unmapped_area(str
836 for (; vma; vma = vma->vm_next) {
839 - if (addr + len <= vma->vm_start)
840 + if (check_heap_stack_gap(vma, addr, len))
844 diff -urNp linux-2.6.37/arch/ia64/hp/common/hwsw_iommu.c linux-2.6.37/arch/ia64/hp/common/hwsw_iommu.c
845 --- linux-2.6.37/arch/ia64/hp/common/hwsw_iommu.c 2011-01-04 19:50:19.000000000 -0500
846 +++ linux-2.6.37/arch/ia64/hp/common/hwsw_iommu.c 2011-01-17 02:41:00.000000000 -0500
848 #include <linux/swiotlb.h>
849 #include <asm/machvec.h>
851 -extern struct dma_map_ops sba_dma_ops, swiotlb_dma_ops;
852 +extern const struct dma_map_ops sba_dma_ops, swiotlb_dma_ops;
854 /* swiotlb declarations & definitions: */
855 extern int swiotlb_late_init_with_default_size (size_t size);
856 @@ -33,7 +33,7 @@ static inline int use_swiotlb(struct dev
857 !sba_dma_ops.dma_supported(dev, *dev->dma_mask);
860 -struct dma_map_ops *hwsw_dma_get_ops(struct device *dev)
861 +const struct dma_map_ops *hwsw_dma_get_ops(struct device *dev)
863 if (use_swiotlb(dev))
864 return &swiotlb_dma_ops;
865 diff -urNp linux-2.6.37/arch/ia64/hp/common/sba_iommu.c linux-2.6.37/arch/ia64/hp/common/sba_iommu.c
866 --- linux-2.6.37/arch/ia64/hp/common/sba_iommu.c 2011-01-04 19:50:19.000000000 -0500
867 +++ linux-2.6.37/arch/ia64/hp/common/sba_iommu.c 2011-01-17 02:41:00.000000000 -0500
868 @@ -2097,7 +2097,7 @@ static struct acpi_driver acpi_sba_ioc_d
872 -extern struct dma_map_ops swiotlb_dma_ops;
873 +extern const struct dma_map_ops swiotlb_dma_ops;
877 @@ -2211,7 +2211,7 @@ sba_page_override(char *str)
879 __setup("sbapagesize=",sba_page_override);
881 -struct dma_map_ops sba_dma_ops = {
882 +const struct dma_map_ops sba_dma_ops = {
883 .alloc_coherent = sba_alloc_coherent,
884 .free_coherent = sba_free_coherent,
885 .map_page = sba_map_page,
886 diff -urNp linux-2.6.37/arch/ia64/include/asm/dma-mapping.h linux-2.6.37/arch/ia64/include/asm/dma-mapping.h
887 --- linux-2.6.37/arch/ia64/include/asm/dma-mapping.h 2011-01-04 19:50:19.000000000 -0500
888 +++ linux-2.6.37/arch/ia64/include/asm/dma-mapping.h 2011-01-17 02:41:00.000000000 -0500
891 #define ARCH_HAS_DMA_GET_REQUIRED_MASK
893 -extern struct dma_map_ops *dma_ops;
894 +extern const struct dma_map_ops *dma_ops;
895 extern struct ia64_machine_vector ia64_mv;
896 extern void set_iommu_machvec(void);
898 @@ -24,7 +24,7 @@ extern void machvec_dma_sync_sg(struct d
899 static inline void *dma_alloc_coherent(struct device *dev, size_t size,
900 dma_addr_t *daddr, gfp_t gfp)
902 - struct dma_map_ops *ops = platform_dma_get_ops(dev);
903 + const struct dma_map_ops *ops = platform_dma_get_ops(dev);
906 caddr = ops->alloc_coherent(dev, size, daddr, gfp);
907 @@ -35,7 +35,7 @@ static inline void *dma_alloc_coherent(s
908 static inline void dma_free_coherent(struct device *dev, size_t size,
909 void *caddr, dma_addr_t daddr)
911 - struct dma_map_ops *ops = platform_dma_get_ops(dev);
912 + const struct dma_map_ops *ops = platform_dma_get_ops(dev);
913 debug_dma_free_coherent(dev, size, caddr, daddr);
914 ops->free_coherent(dev, size, caddr, daddr);
916 @@ -49,13 +49,13 @@ static inline void dma_free_coherent(str
918 static inline int dma_mapping_error(struct device *dev, dma_addr_t daddr)
920 - struct dma_map_ops *ops = platform_dma_get_ops(dev);
921 + const struct dma_map_ops *ops = platform_dma_get_ops(dev);
922 return ops->mapping_error(dev, daddr);
925 static inline int dma_supported(struct device *dev, u64 mask)
927 - struct dma_map_ops *ops = platform_dma_get_ops(dev);
928 + const struct dma_map_ops *ops = platform_dma_get_ops(dev);
929 return ops->dma_supported(dev, mask);
932 diff -urNp linux-2.6.37/arch/ia64/include/asm/elf.h linux-2.6.37/arch/ia64/include/asm/elf.h
933 --- linux-2.6.37/arch/ia64/include/asm/elf.h 2011-01-04 19:50:19.000000000 -0500
934 +++ linux-2.6.37/arch/ia64/include/asm/elf.h 2011-01-17 02:41:00.000000000 -0500
937 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
939 +#ifdef CONFIG_PAX_ASLR
940 +#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
942 +#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
943 +#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
946 #define PT_IA_64_UNWIND 0x70000001
948 /* IA-64 relocations: */
949 diff -urNp linux-2.6.37/arch/ia64/include/asm/machvec.h linux-2.6.37/arch/ia64/include/asm/machvec.h
950 --- linux-2.6.37/arch/ia64/include/asm/machvec.h 2011-01-04 19:50:19.000000000 -0500
951 +++ linux-2.6.37/arch/ia64/include/asm/machvec.h 2011-01-17 02:41:00.000000000 -0500
952 @@ -45,7 +45,7 @@ typedef void ia64_mv_kernel_launch_event
953 /* DMA-mapping interface: */
954 typedef void ia64_mv_dma_init (void);
955 typedef u64 ia64_mv_dma_get_required_mask (struct device *);
956 -typedef struct dma_map_ops *ia64_mv_dma_get_ops(struct device *);
957 +typedef const struct dma_map_ops *ia64_mv_dma_get_ops(struct device *);
960 * WARNING: The legacy I/O space is _architected_. Platforms are
961 @@ -251,7 +251,7 @@ extern void machvec_init_from_cmdline(co
962 # endif /* CONFIG_IA64_GENERIC */
964 extern void swiotlb_dma_init(void);
965 -extern struct dma_map_ops *dma_get_ops(struct device *);
966 +extern const struct dma_map_ops *dma_get_ops(struct device *);
969 * Define default versions so we can extend machvec for new platforms without having
970 diff -urNp linux-2.6.37/arch/ia64/include/asm/pgtable.h linux-2.6.37/arch/ia64/include/asm/pgtable.h
971 --- linux-2.6.37/arch/ia64/include/asm/pgtable.h 2011-01-04 19:50:19.000000000 -0500
972 +++ linux-2.6.37/arch/ia64/include/asm/pgtable.h 2011-01-17 02:41:00.000000000 -0500
974 * David Mosberger-Tang <davidm@hpl.hp.com>
978 +#include <linux/const.h>
979 #include <asm/mman.h>
980 #include <asm/page.h>
981 #include <asm/processor.h>
983 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
984 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
985 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
987 +#ifdef CONFIG_PAX_PAGEEXEC
988 +# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
989 +# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
990 +# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
992 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
993 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
994 +# define PAGE_COPY_NOEXEC PAGE_COPY
997 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
998 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
999 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
1000 diff -urNp linux-2.6.37/arch/ia64/include/asm/uaccess.h linux-2.6.37/arch/ia64/include/asm/uaccess.h
1001 --- linux-2.6.37/arch/ia64/include/asm/uaccess.h 2011-01-04 19:50:19.000000000 -0500
1002 +++ linux-2.6.37/arch/ia64/include/asm/uaccess.h 2011-01-17 02:41:00.000000000 -0500
1003 @@ -257,7 +257,7 @@ __copy_from_user (void *to, const void _
1004 const void *__cu_from = (from); \
1005 long __cu_len = (n); \
1007 - if (__access_ok(__cu_to, __cu_len, get_fs())) \
1008 + if (__cu_len > 0 && __cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) \
1009 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
1012 @@ -269,7 +269,7 @@ __copy_from_user (void *to, const void _
1013 long __cu_len = (n); \
1015 __chk_user_ptr(__cu_from); \
1016 - if (__access_ok(__cu_from, __cu_len, get_fs())) \
1017 + if (__cu_len > 0 && __cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) \
1018 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
1021 diff -urNp linux-2.6.37/arch/ia64/kernel/dma-mapping.c linux-2.6.37/arch/ia64/kernel/dma-mapping.c
1022 --- linux-2.6.37/arch/ia64/kernel/dma-mapping.c 2011-01-04 19:50:19.000000000 -0500
1023 +++ linux-2.6.37/arch/ia64/kernel/dma-mapping.c 2011-01-17 02:41:00.000000000 -0500
1025 /* Set this to 1 if there is a HW IOMMU in the system */
1026 int iommu_detected __read_mostly;
1028 -struct dma_map_ops *dma_ops;
1029 +const struct dma_map_ops *dma_ops;
1030 EXPORT_SYMBOL(dma_ops);
1032 #define PREALLOC_DMA_DEBUG_ENTRIES (1 << 16)
1033 @@ -16,7 +16,7 @@ static int __init dma_init(void)
1035 fs_initcall(dma_init);
1037 -struct dma_map_ops *dma_get_ops(struct device *dev)
1038 +const struct dma_map_ops *dma_get_ops(struct device *dev)
1042 diff -urNp linux-2.6.37/arch/ia64/kernel/module.c linux-2.6.37/arch/ia64/kernel/module.c
1043 --- linux-2.6.37/arch/ia64/kernel/module.c 2011-01-04 19:50:19.000000000 -0500
1044 +++ linux-2.6.37/arch/ia64/kernel/module.c 2011-01-17 02:41:00.000000000 -0500
1045 @@ -315,8 +315,7 @@ module_alloc (unsigned long size)
1047 module_free (struct module *mod, void *module_region)
1049 - if (mod && mod->arch.init_unw_table &&
1050 - module_region == mod->module_init) {
1051 + if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
1052 unw_remove_unwind_table(mod->arch.init_unw_table);
1053 mod->arch.init_unw_table = NULL;
1055 @@ -502,15 +501,39 @@ module_frob_arch_sections (Elf_Ehdr *ehd
1059 +in_init_rx (const struct module *mod, uint64_t addr)
1061 + return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
1065 +in_init_rw (const struct module *mod, uint64_t addr)
1067 + return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
1071 in_init (const struct module *mod, uint64_t addr)
1073 - return addr - (uint64_t) mod->module_init < mod->init_size;
1074 + return in_init_rx(mod, addr) || in_init_rw(mod, addr);
1078 +in_core_rx (const struct module *mod, uint64_t addr)
1080 + return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
1084 +in_core_rw (const struct module *mod, uint64_t addr)
1086 + return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
1090 in_core (const struct module *mod, uint64_t addr)
1092 - return addr - (uint64_t) mod->module_core < mod->core_size;
1093 + return in_core_rx(mod, addr) || in_core_rw(mod, addr);
1097 @@ -693,7 +716,14 @@ do_reloc (struct module *mod, uint8_t r_
1101 - val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
1102 + if (in_init_rx(mod, val))
1103 + val -= (uint64_t) mod->module_init_rx;
1104 + else if (in_init_rw(mod, val))
1105 + val -= (uint64_t) mod->module_init_rw;
1106 + else if (in_core_rx(mod, val))
1107 + val -= (uint64_t) mod->module_core_rx;
1108 + else if (in_core_rw(mod, val))
1109 + val -= (uint64_t) mod->module_core_rw;
1113 @@ -828,15 +858,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs,
1114 * addresses have been selected...
1117 - if (mod->core_size > MAX_LTOFF)
1118 + if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
1120 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
1121 * at the end of the module.
1123 - gp = mod->core_size - MAX_LTOFF / 2;
1124 + gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
1126 - gp = mod->core_size / 2;
1127 - gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
1128 + gp = (mod->core_size_rx + mod->core_size_rw) / 2;
1129 + gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
1131 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
1133 diff -urNp linux-2.6.37/arch/ia64/kernel/pci-dma.c linux-2.6.37/arch/ia64/kernel/pci-dma.c
1134 --- linux-2.6.37/arch/ia64/kernel/pci-dma.c 2011-01-04 19:50:19.000000000 -0500
1135 +++ linux-2.6.37/arch/ia64/kernel/pci-dma.c 2011-01-17 02:41:00.000000000 -0500
1136 @@ -43,7 +43,7 @@ struct device fallback_dev = {
1137 .dma_mask = &fallback_dev.coherent_dma_mask,
1140 -extern struct dma_map_ops intel_dma_ops;
1141 +extern const struct dma_map_ops intel_dma_ops;
1143 static int __init pci_iommu_init(void)
1145 diff -urNp linux-2.6.37/arch/ia64/kernel/pci-swiotlb.c linux-2.6.37/arch/ia64/kernel/pci-swiotlb.c
1146 --- linux-2.6.37/arch/ia64/kernel/pci-swiotlb.c 2011-01-04 19:50:19.000000000 -0500
1147 +++ linux-2.6.37/arch/ia64/kernel/pci-swiotlb.c 2011-01-17 02:41:00.000000000 -0500
1148 @@ -22,7 +22,7 @@ static void *ia64_swiotlb_alloc_coherent
1149 return swiotlb_alloc_coherent(dev, size, dma_handle, gfp);
1152 -struct dma_map_ops swiotlb_dma_ops = {
1153 +const struct dma_map_ops swiotlb_dma_ops = {
1154 .alloc_coherent = ia64_swiotlb_alloc_coherent,
1155 .free_coherent = swiotlb_free_coherent,
1156 .map_page = swiotlb_map_page,
1157 diff -urNp linux-2.6.37/arch/ia64/kernel/sys_ia64.c linux-2.6.37/arch/ia64/kernel/sys_ia64.c
1158 --- linux-2.6.37/arch/ia64/kernel/sys_ia64.c 2011-01-04 19:50:19.000000000 -0500
1159 +++ linux-2.6.37/arch/ia64/kernel/sys_ia64.c 2011-01-17 02:41:00.000000000 -0500
1160 @@ -43,6 +43,13 @@ arch_get_unmapped_area (struct file *fil
1161 if (REGION_NUMBER(addr) == RGN_HPAGE)
1165 +#ifdef CONFIG_PAX_RANDMMAP
1166 + if (mm->pax_flags & MF_PAX_RANDMMAP)
1167 + addr = mm->free_area_cache;
1172 addr = mm->free_area_cache;
1174 @@ -61,14 +68,14 @@ arch_get_unmapped_area (struct file *fil
1175 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
1176 /* At this point: (!vma || addr < vma->vm_end). */
1177 if (TASK_SIZE - len < addr || RGN_MAP_LIMIT - len < REGION_OFFSET(addr)) {
1178 - if (start_addr != TASK_UNMAPPED_BASE) {
1179 + if (start_addr != mm->mmap_base) {
1180 /* Start a new search --- just in case we missed some holes. */
1181 - addr = TASK_UNMAPPED_BASE;
1182 + addr = mm->mmap_base;
1187 - if (!vma || addr + len <= vma->vm_start) {
1188 + if (check_heap_stack_gap(vma, addr, len)) {
1189 /* Remember the address where we stopped this search: */
1190 mm->free_area_cache = addr + len;
1192 diff -urNp linux-2.6.37/arch/ia64/kernel/vmlinux.lds.S linux-2.6.37/arch/ia64/kernel/vmlinux.lds.S
1193 --- linux-2.6.37/arch/ia64/kernel/vmlinux.lds.S 2011-01-04 19:50:19.000000000 -0500
1194 +++ linux-2.6.37/arch/ia64/kernel/vmlinux.lds.S 2011-01-17 02:41:00.000000000 -0500
1195 @@ -199,7 +199,7 @@ SECTIONS {
1197 . = ALIGN(PERCPU_PAGE_SIZE);
1198 PERCPU_VADDR(PERCPU_ADDR, :percpu)
1199 - __phys_per_cpu_start = __per_cpu_load;
1200 + __phys_per_cpu_start = per_cpu_load;
1202 * ensure percpu data fits
1203 * into percpu page size
1204 diff -urNp linux-2.6.37/arch/ia64/mm/fault.c linux-2.6.37/arch/ia64/mm/fault.c
1205 --- linux-2.6.37/arch/ia64/mm/fault.c 2011-01-04 19:50:19.000000000 -0500
1206 +++ linux-2.6.37/arch/ia64/mm/fault.c 2011-01-17 02:41:00.000000000 -0500
1207 @@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned
1208 return pte_present(pte);
1211 +#ifdef CONFIG_PAX_PAGEEXEC
1212 +void pax_report_insns(void *pc, void *sp)
1216 + printk(KERN_ERR "PAX: bytes at PC: ");
1217 + for (i = 0; i < 8; i++) {
1219 + if (get_user(c, (unsigned int *)pc+i))
1220 + printk(KERN_CONT "???????? ");
1222 + printk(KERN_CONT "%08x ", c);
1229 ia64_do_page_fault (unsigned long address, unsigned long isr, struct pt_regs *regs)
1231 @@ -145,9 +162,23 @@ ia64_do_page_fault (unsigned long addres
1232 mask = ( (((isr >> IA64_ISR_X_BIT) & 1UL) << VM_EXEC_BIT)
1233 | (((isr >> IA64_ISR_W_BIT) & 1UL) << VM_WRITE_BIT));
1235 - if ((vma->vm_flags & mask) != mask)
1236 + if ((vma->vm_flags & mask) != mask) {
1238 +#ifdef CONFIG_PAX_PAGEEXEC
1239 + if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
1240 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
1243 + up_read(&mm->mmap_sem);
1244 + pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
1245 + do_group_exit(SIGKILL);
1254 * If for any reason at all we couldn't handle the fault, make
1255 * sure we exit gracefully rather than endlessly redo the
1256 diff -urNp linux-2.6.37/arch/ia64/mm/hugetlbpage.c linux-2.6.37/arch/ia64/mm/hugetlbpage.c
1257 --- linux-2.6.37/arch/ia64/mm/hugetlbpage.c 2011-01-04 19:50:19.000000000 -0500
1258 +++ linux-2.6.37/arch/ia64/mm/hugetlbpage.c 2011-01-17 02:41:00.000000000 -0500
1259 @@ -171,7 +171,7 @@ unsigned long hugetlb_get_unmapped_area(
1260 /* At this point: (!vmm || addr < vmm->vm_end). */
1261 if (REGION_OFFSET(addr) + len > RGN_MAP_LIMIT)
1263 - if (!vmm || (addr + len) <= vmm->vm_start)
1264 + if (check_heap_stack_gap(vmm, addr, len))
1266 addr = ALIGN(vmm->vm_end, HPAGE_SIZE);
1268 diff -urNp linux-2.6.37/arch/ia64/mm/init.c linux-2.6.37/arch/ia64/mm/init.c
1269 --- linux-2.6.37/arch/ia64/mm/init.c 2011-01-04 19:50:19.000000000 -0500
1270 +++ linux-2.6.37/arch/ia64/mm/init.c 2011-01-17 02:41:00.000000000 -0500
1271 @@ -122,6 +122,19 @@ ia64_init_addr_space (void)
1272 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
1273 vma->vm_end = vma->vm_start + PAGE_SIZE;
1274 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
1276 +#ifdef CONFIG_PAX_PAGEEXEC
1277 + if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
1278 + vma->vm_flags &= ~VM_EXEC;
1280 +#ifdef CONFIG_PAX_MPROTECT
1281 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
1282 + vma->vm_flags &= ~VM_MAYEXEC;
1288 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
1289 down_write(¤t->mm->mmap_sem);
1290 if (insert_vm_struct(current->mm, vma)) {
1291 diff -urNp linux-2.6.37/arch/ia64/sn/pci/pci_dma.c linux-2.6.37/arch/ia64/sn/pci/pci_dma.c
1292 --- linux-2.6.37/arch/ia64/sn/pci/pci_dma.c 2011-01-04 19:50:19.000000000 -0500
1293 +++ linux-2.6.37/arch/ia64/sn/pci/pci_dma.c 2011-01-17 02:41:00.000000000 -0500
1294 @@ -465,7 +465,7 @@ int sn_pci_legacy_write(struct pci_bus *
1298 -static struct dma_map_ops sn_dma_ops = {
1299 +static const struct dma_map_ops sn_dma_ops = {
1300 .alloc_coherent = sn_dma_alloc_coherent,
1301 .free_coherent = sn_dma_free_coherent,
1302 .map_page = sn_dma_map_page,
1303 diff -urNp linux-2.6.37/arch/m32r/lib/usercopy.c linux-2.6.37/arch/m32r/lib/usercopy.c
1304 --- linux-2.6.37/arch/m32r/lib/usercopy.c 2011-01-04 19:50:19.000000000 -0500
1305 +++ linux-2.6.37/arch/m32r/lib/usercopy.c 2011-01-17 02:41:00.000000000 -0500
1308 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
1314 if (access_ok(VERIFY_WRITE, to, n))
1315 __copy_user(to,from,n);
1316 @@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to,
1318 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
1324 if (access_ok(VERIFY_READ, from, n))
1325 __copy_user_zeroing(to,from,n);
1326 diff -urNp linux-2.6.37/arch/microblaze/include/asm/device.h linux-2.6.37/arch/microblaze/include/asm/device.h
1327 --- linux-2.6.37/arch/microblaze/include/asm/device.h 2011-01-04 19:50:19.000000000 -0500
1328 +++ linux-2.6.37/arch/microblaze/include/asm/device.h 2011-01-17 02:41:00.000000000 -0500
1329 @@ -13,7 +13,7 @@ struct device_node;
1331 struct dev_archdata {
1332 /* DMA operations on that device */
1333 - struct dma_map_ops *dma_ops;
1334 + const struct dma_map_ops *dma_ops;
1338 diff -urNp linux-2.6.37/arch/microblaze/include/asm/dma-mapping.h linux-2.6.37/arch/microblaze/include/asm/dma-mapping.h
1339 --- linux-2.6.37/arch/microblaze/include/asm/dma-mapping.h 2011-01-04 19:50:19.000000000 -0500
1340 +++ linux-2.6.37/arch/microblaze/include/asm/dma-mapping.h 2011-01-17 02:41:00.000000000 -0500
1341 @@ -43,14 +43,14 @@ static inline unsigned long device_to_ma
1342 return 0xfffffffful;
1345 -extern struct dma_map_ops *dma_ops;
1346 +extern const struct dma_map_ops *dma_ops;
1349 * Available generic sets of operations
1351 -extern struct dma_map_ops dma_direct_ops;
1352 +extern const struct dma_map_ops dma_direct_ops;
1354 -static inline struct dma_map_ops *get_dma_ops(struct device *dev)
1355 +static inline const struct dma_map_ops *get_dma_ops(struct device *dev)
1357 /* We don't handle the NULL dev case for ISA for now. We could
1358 * do it via an out of line call but it is not needed for now. The
1359 @@ -63,14 +63,14 @@ static inline struct dma_map_ops *get_dm
1360 return dev->archdata.dma_ops;
1363 -static inline void set_dma_ops(struct device *dev, struct dma_map_ops *ops)
1364 +static inline void set_dma_ops(struct device *dev, const struct dma_map_ops *ops)
1366 dev->archdata.dma_ops = ops;
1369 static inline int dma_supported(struct device *dev, u64 mask)
1371 - struct dma_map_ops *ops = get_dma_ops(dev);
1372 + const struct dma_map_ops *ops = get_dma_ops(dev);
1376 @@ -81,7 +81,7 @@ static inline int dma_supported(struct d
1378 static inline int dma_set_mask(struct device *dev, u64 dma_mask)
1380 - struct dma_map_ops *ops = get_dma_ops(dev);
1381 + const struct dma_map_ops *ops = get_dma_ops(dev);
1383 if (unlikely(ops == NULL))
1385 @@ -97,7 +97,7 @@ static inline int dma_set_mask(struct de
1387 static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
1389 - struct dma_map_ops *ops = get_dma_ops(dev);
1390 + const struct dma_map_ops *ops = get_dma_ops(dev);
1391 if (ops->mapping_error)
1392 return ops->mapping_error(dev, dma_addr);
1394 @@ -110,7 +110,7 @@ static inline int dma_mapping_error(stru
1395 static inline void *dma_alloc_coherent(struct device *dev, size_t size,
1396 dma_addr_t *dma_handle, gfp_t flag)
1398 - struct dma_map_ops *ops = get_dma_ops(dev);
1399 + const struct dma_map_ops *ops = get_dma_ops(dev);
1403 @@ -124,7 +124,7 @@ static inline void *dma_alloc_coherent(s
1404 static inline void dma_free_coherent(struct device *dev, size_t size,
1405 void *cpu_addr, dma_addr_t dma_handle)
1407 - struct dma_map_ops *ops = get_dma_ops(dev);
1408 + const struct dma_map_ops *ops = get_dma_ops(dev);
1411 debug_dma_free_coherent(dev, size, cpu_addr, dma_handle);
1412 diff -urNp linux-2.6.37/arch/microblaze/include/asm/pci.h linux-2.6.37/arch/microblaze/include/asm/pci.h
1413 --- linux-2.6.37/arch/microblaze/include/asm/pci.h 2011-01-04 19:50:19.000000000 -0500
1414 +++ linux-2.6.37/arch/microblaze/include/asm/pci.h 2011-01-17 02:41:00.000000000 -0500
1415 @@ -54,8 +54,8 @@ static inline void pcibios_penalize_isa_
1419 -extern void set_pci_dma_ops(struct dma_map_ops *dma_ops);
1420 -extern struct dma_map_ops *get_pci_dma_ops(void);
1421 +extern void set_pci_dma_ops(const struct dma_map_ops *dma_ops);
1422 +extern const struct dma_map_ops *get_pci_dma_ops(void);
1423 #else /* CONFIG_PCI */
1424 #define set_pci_dma_ops(d)
1425 #define get_pci_dma_ops() NULL
1426 diff -urNp linux-2.6.37/arch/microblaze/kernel/dma.c linux-2.6.37/arch/microblaze/kernel/dma.c
1427 --- linux-2.6.37/arch/microblaze/kernel/dma.c 2011-01-04 19:50:19.000000000 -0500
1428 +++ linux-2.6.37/arch/microblaze/kernel/dma.c 2011-01-17 02:41:00.000000000 -0500
1429 @@ -133,7 +133,7 @@ static inline void dma_direct_unmap_page
1430 __dma_sync_page(dma_address, 0 , size, direction);
1433 -struct dma_map_ops dma_direct_ops = {
1434 +const struct dma_map_ops dma_direct_ops = {
1435 .alloc_coherent = dma_direct_alloc_coherent,
1436 .free_coherent = dma_direct_free_coherent,
1437 .map_sg = dma_direct_map_sg,
1438 diff -urNp linux-2.6.37/arch/microblaze/kernel/kgdb.c linux-2.6.37/arch/microblaze/kernel/kgdb.c
1439 --- linux-2.6.37/arch/microblaze/kernel/kgdb.c 2011-01-04 19:50:19.000000000 -0500
1440 +++ linux-2.6.37/arch/microblaze/kernel/kgdb.c 2011-01-17 02:41:00.000000000 -0500
1441 @@ -141,10 +141,11 @@ void kgdb_arch_exit(void)
1445 -struct kgdb_arch arch_kgdb_ops = {
1446 +const struct kgdb_arch arch_kgdb_ops = {
1447 #ifdef __MICROBLAZEEL__
1448 .gdb_bpt_instr = {0x18, 0x00, 0x0c, 0xba}, /* brki r16, 0x18 */
1451 .gdb_bpt_instr = {0xba, 0x0c, 0x00, 0x18}, /* brki r16, 0x18 */
1454 diff -urNp linux-2.6.37/arch/microblaze/pci/pci-common.c linux-2.6.37/arch/microblaze/pci/pci-common.c
1455 --- linux-2.6.37/arch/microblaze/pci/pci-common.c 2011-01-04 19:50:19.000000000 -0500
1456 +++ linux-2.6.37/arch/microblaze/pci/pci-common.c 2011-01-17 02:41:00.000000000 -0500
1457 @@ -47,14 +47,14 @@ resource_size_t isa_mem_base;
1458 /* Default PCI flags is 0 on ppc32, modified at boot on ppc64 */
1459 unsigned int pci_flags;
1461 -static struct dma_map_ops *pci_dma_ops = &dma_direct_ops;
1462 +static const struct dma_map_ops *pci_dma_ops = &dma_direct_ops;
1464 -void set_pci_dma_ops(struct dma_map_ops *dma_ops)
1465 +void set_pci_dma_ops(const struct dma_map_ops *dma_ops)
1467 pci_dma_ops = dma_ops;
1470 -struct dma_map_ops *get_pci_dma_ops(void)
1471 +const struct dma_map_ops *get_pci_dma_ops(void)
1475 diff -urNp linux-2.6.37/arch/mips/alchemy/devboards/pm.c linux-2.6.37/arch/mips/alchemy/devboards/pm.c
1476 --- linux-2.6.37/arch/mips/alchemy/devboards/pm.c 2011-01-04 19:50:19.000000000 -0500
1477 +++ linux-2.6.37/arch/mips/alchemy/devboards/pm.c 2011-01-17 02:41:00.000000000 -0500
1478 @@ -110,7 +110,7 @@ static void db1x_pm_end(void)
1482 -static struct platform_suspend_ops db1x_pm_ops = {
1483 +static const struct platform_suspend_ops db1x_pm_ops = {
1484 .valid = suspend_valid_only_mem,
1485 .begin = db1x_pm_begin,
1486 .enter = db1x_pm_enter,
1487 diff -urNp linux-2.6.37/arch/mips/cavium-octeon/dma-octeon.c linux-2.6.37/arch/mips/cavium-octeon/dma-octeon.c
1488 --- linux-2.6.37/arch/mips/cavium-octeon/dma-octeon.c 2011-01-04 19:50:19.000000000 -0500
1489 +++ linux-2.6.37/arch/mips/cavium-octeon/dma-octeon.c 2011-01-17 02:41:00.000000000 -0500
1490 @@ -202,7 +202,7 @@ static phys_addr_t octeon_unity_dma_to_p
1493 struct octeon_dma_map_ops {
1494 - struct dma_map_ops dma_map_ops;
1495 + const struct dma_map_ops dma_map_ops;
1496 dma_addr_t (*phys_to_dma)(struct device *dev, phys_addr_t paddr);
1497 phys_addr_t (*dma_to_phys)(struct device *dev, dma_addr_t daddr);
1499 @@ -324,7 +324,7 @@ static struct octeon_dma_map_ops _octeon
1503 -struct dma_map_ops *octeon_pci_dma_map_ops;
1504 +const struct dma_map_ops *octeon_pci_dma_map_ops;
1506 void __init octeon_pci_dma_init(void)
1508 diff -urNp linux-2.6.37/arch/mips/include/asm/device.h linux-2.6.37/arch/mips/include/asm/device.h
1509 --- linux-2.6.37/arch/mips/include/asm/device.h 2011-01-04 19:50:19.000000000 -0500
1510 +++ linux-2.6.37/arch/mips/include/asm/device.h 2011-01-17 02:41:00.000000000 -0500
1511 @@ -10,7 +10,7 @@ struct dma_map_ops;
1513 struct dev_archdata {
1514 /* DMA operations on that device */
1515 - struct dma_map_ops *dma_ops;
1516 + const struct dma_map_ops *dma_ops;
1519 struct pdev_archdata {
1520 diff -urNp linux-2.6.37/arch/mips/include/asm/dma-mapping.h linux-2.6.37/arch/mips/include/asm/dma-mapping.h
1521 --- linux-2.6.37/arch/mips/include/asm/dma-mapping.h 2011-01-04 19:50:19.000000000 -0500
1522 +++ linux-2.6.37/arch/mips/include/asm/dma-mapping.h 2011-01-17 02:41:00.000000000 -0500
1525 #include <dma-coherence.h>
1527 -extern struct dma_map_ops *mips_dma_map_ops;
1528 +extern const struct dma_map_ops *mips_dma_map_ops;
1530 -static inline struct dma_map_ops *get_dma_ops(struct device *dev)
1531 +static inline const struct dma_map_ops *get_dma_ops(struct device *dev)
1533 if (dev && dev->archdata.dma_ops)
1534 return dev->archdata.dma_ops;
1535 @@ -31,13 +31,13 @@ static inline void dma_mark_clean(void *
1537 static inline int dma_supported(struct device *dev, u64 mask)
1539 - struct dma_map_ops *ops = get_dma_ops(dev);
1540 + const struct dma_map_ops *ops = get_dma_ops(dev);
1541 return ops->dma_supported(dev, mask);
1544 static inline int dma_mapping_error(struct device *dev, u64 mask)
1546 - struct dma_map_ops *ops = get_dma_ops(dev);
1547 + const struct dma_map_ops *ops = get_dma_ops(dev);
1548 return ops->mapping_error(dev, mask);
1551 @@ -59,7 +59,7 @@ static inline void *dma_alloc_coherent(s
1552 dma_addr_t *dma_handle, gfp_t gfp)
1555 - struct dma_map_ops *ops = get_dma_ops(dev);
1556 + const struct dma_map_ops *ops = get_dma_ops(dev);
1558 ret = ops->alloc_coherent(dev, size, dma_handle, gfp);
1560 @@ -71,7 +71,7 @@ static inline void *dma_alloc_coherent(s
1561 static inline void dma_free_coherent(struct device *dev, size_t size,
1562 void *vaddr, dma_addr_t dma_handle)
1564 - struct dma_map_ops *ops = get_dma_ops(dev);
1565 + const struct dma_map_ops *ops = get_dma_ops(dev);
1567 ops->free_coherent(dev, size, vaddr, dma_handle);
1569 diff -urNp linux-2.6.37/arch/mips/include/asm/elf.h linux-2.6.37/arch/mips/include/asm/elf.h
1570 --- linux-2.6.37/arch/mips/include/asm/elf.h 2011-01-04 19:50:19.000000000 -0500
1571 +++ linux-2.6.37/arch/mips/include/asm/elf.h 2011-01-17 02:41:00.000000000 -0500
1572 @@ -372,13 +372,16 @@ extern const char *__elf_platform;
1573 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1576 +#ifdef CONFIG_PAX_ASLR
1577 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT_ADDR) ? 0x00400000UL : 0x00400000UL)
1579 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT_ADDR) ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
1580 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT_ADDR) ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
1583 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
1584 struct linux_binprm;
1585 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
1589 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1590 -#define arch_randomize_brk arch_randomize_brk
1592 #endif /* _ASM_ELF_H */
1593 diff -urNp linux-2.6.37/arch/mips/include/asm/mach-cavium-octeon/dma-coherence.h linux-2.6.37/arch/mips/include/asm/mach-cavium-octeon/dma-coherence.h
1594 --- linux-2.6.37/arch/mips/include/asm/mach-cavium-octeon/dma-coherence.h 2011-01-04 19:50:19.000000000 -0500
1595 +++ linux-2.6.37/arch/mips/include/asm/mach-cavium-octeon/dma-coherence.h 2011-01-17 02:41:00.000000000 -0500
1596 @@ -66,7 +66,7 @@ dma_addr_t phys_to_dma(struct device *de
1597 phys_addr_t dma_to_phys(struct device *dev, dma_addr_t daddr);
1600 -extern struct dma_map_ops *octeon_pci_dma_map_ops;
1601 +extern const struct dma_map_ops *octeon_pci_dma_map_ops;
1602 extern char *octeon_swiotlb;
1604 #endif /* __ASM_MACH_CAVIUM_OCTEON_DMA_COHERENCE_H */
1605 diff -urNp linux-2.6.37/arch/mips/include/asm/page.h linux-2.6.37/arch/mips/include/asm/page.h
1606 --- linux-2.6.37/arch/mips/include/asm/page.h 2011-01-04 19:50:19.000000000 -0500
1607 +++ linux-2.6.37/arch/mips/include/asm/page.h 2011-01-17 02:41:00.000000000 -0500
1608 @@ -93,7 +93,7 @@ extern void copy_user_highpage(struct pa
1609 #ifdef CONFIG_CPU_MIPS32
1610 typedef struct { unsigned long pte_low, pte_high; } pte_t;
1611 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
1612 - #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
1613 + #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
1615 typedef struct { unsigned long long pte; } pte_t;
1616 #define pte_val(x) ((x).pte)
1617 diff -urNp linux-2.6.37/arch/mips/include/asm/system.h linux-2.6.37/arch/mips/include/asm/system.h
1618 --- linux-2.6.37/arch/mips/include/asm/system.h 2011-01-04 19:50:19.000000000 -0500
1619 +++ linux-2.6.37/arch/mips/include/asm/system.h 2011-01-17 02:41:00.000000000 -0500
1621 #include <asm/dsp.h>
1622 #include <asm/watch.h>
1623 #include <asm/war.h>
1624 +#include <asm/asm.h>
1628 @@ -230,6 +231,6 @@ extern void per_cpu_trap_init(void);
1630 #define __ARCH_WANT_UNLOCKED_CTXSW
1632 -extern unsigned long arch_align_stack(unsigned long sp);
1633 +#define arch_align_stack(x) ((x) & ALMASK)
1635 #endif /* _ASM_SYSTEM_H */
1636 diff -urNp linux-2.6.37/arch/mips/jz4740/pm.c linux-2.6.37/arch/mips/jz4740/pm.c
1637 --- linux-2.6.37/arch/mips/jz4740/pm.c 2011-01-04 19:50:19.000000000 -0500
1638 +++ linux-2.6.37/arch/mips/jz4740/pm.c 2011-01-17 02:41:00.000000000 -0500
1639 @@ -42,7 +42,7 @@ static int jz4740_pm_enter(suspend_state
1643 -static struct platform_suspend_ops jz4740_pm_ops = {
1644 +static const struct platform_suspend_ops jz4740_pm_ops = {
1645 .valid = suspend_valid_only_mem,
1646 .enter = jz4740_pm_enter,
1648 diff -urNp linux-2.6.37/arch/mips/kernel/binfmt_elfn32.c linux-2.6.37/arch/mips/kernel/binfmt_elfn32.c
1649 --- linux-2.6.37/arch/mips/kernel/binfmt_elfn32.c 2011-01-04 19:50:19.000000000 -0500
1650 +++ linux-2.6.37/arch/mips/kernel/binfmt_elfn32.c 2011-01-17 02:41:00.000000000 -0500
1651 @@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_N
1652 #undef ELF_ET_DYN_BASE
1653 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
1655 +#ifdef CONFIG_PAX_ASLR
1656 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT_ADDR) ? 0x00400000UL : 0x00400000UL)
1658 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT_ADDR) ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
1659 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT_ADDR) ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
1662 #include <asm/processor.h>
1663 #include <linux/module.h>
1664 #include <linux/elfcore.h>
1665 diff -urNp linux-2.6.37/arch/mips/kernel/binfmt_elfo32.c linux-2.6.37/arch/mips/kernel/binfmt_elfo32.c
1666 --- linux-2.6.37/arch/mips/kernel/binfmt_elfo32.c 2011-01-04 19:50:19.000000000 -0500
1667 +++ linux-2.6.37/arch/mips/kernel/binfmt_elfo32.c 2011-01-17 02:41:00.000000000 -0500
1668 @@ -52,6 +52,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_N
1669 #undef ELF_ET_DYN_BASE
1670 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
1672 +#ifdef CONFIG_PAX_ASLR
1673 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT_ADDR) ? 0x00400000UL : 0x00400000UL)
1675 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT_ADDR) ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
1676 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT_ADDR) ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
1679 #include <asm/processor.h>
1682 diff -urNp linux-2.6.37/arch/mips/kernel/kgdb.c linux-2.6.37/arch/mips/kernel/kgdb.c
1683 --- linux-2.6.37/arch/mips/kernel/kgdb.c 2011-01-04 19:50:19.000000000 -0500
1684 +++ linux-2.6.37/arch/mips/kernel/kgdb.c 2011-01-17 02:41:00.000000000 -0500
1685 @@ -351,6 +351,7 @@ int kgdb_arch_handle_exception(int vecto
1689 +/* cannot be const, see kgdb_arch_init */
1690 struct kgdb_arch arch_kgdb_ops;
1693 diff -urNp linux-2.6.37/arch/mips/kernel/process.c linux-2.6.37/arch/mips/kernel/process.c
1694 --- linux-2.6.37/arch/mips/kernel/process.c 2011-01-04 19:50:19.000000000 -0500
1695 +++ linux-2.6.37/arch/mips/kernel/process.c 2011-01-17 02:41:00.000000000 -0500
1696 @@ -473,15 +473,3 @@ unsigned long get_wchan(struct task_stru
1702 - * Don't forget that the stack pointer must be aligned on a 8 bytes
1703 - * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
1705 -unsigned long arch_align_stack(unsigned long sp)
1707 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
1708 - sp -= get_random_int() & ~PAGE_MASK;
1710 - return sp & ALMASK;
1712 diff -urNp linux-2.6.37/arch/mips/kernel/syscall.c linux-2.6.37/arch/mips/kernel/syscall.c
1713 --- linux-2.6.37/arch/mips/kernel/syscall.c 2011-01-04 19:50:19.000000000 -0500
1714 +++ linux-2.6.37/arch/mips/kernel/syscall.c 2011-01-17 02:41:00.000000000 -0500
1715 @@ -108,14 +108,18 @@ unsigned long arch_get_unmapped_area(str
1717 if (filp || (flags & MAP_SHARED))
1720 +#ifdef CONFIG_PAX_RANDMMAP
1721 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
1726 addr = COLOUR_ALIGN(addr, pgoff);
1728 addr = PAGE_ALIGN(addr);
1729 vmm = find_vma(current->mm, addr);
1730 - if (task_size - len >= addr &&
1731 - (!vmm || addr + len <= vmm->vm_start))
1732 + if (task_size - len >= addr && check_heap_stack_gap(vmm, addr, len))
1735 addr = current->mm->mmap_base;
1736 @@ -128,7 +132,7 @@ unsigned long arch_get_unmapped_area(str
1737 /* At this point: (!vmm || addr < vmm->vm_end). */
1738 if (task_size - len < addr)
1740 - if (!vmm || addr + len <= vmm->vm_start)
1741 + if (check_heap_stack_gap(vmm, addr, len))
1745 @@ -168,19 +172,6 @@ static inline unsigned long brk_rnd(void
1749 -unsigned long arch_randomize_brk(struct mm_struct *mm)
1751 - unsigned long base = mm->brk;
1752 - unsigned long ret;
1754 - ret = PAGE_ALIGN(base + brk_rnd());
1756 - if (ret < mm->brk)
1762 SYSCALL_DEFINE6(mips_mmap, unsigned long, addr, unsigned long, len,
1763 unsigned long, prot, unsigned long, flags, unsigned long,
1765 diff -urNp linux-2.6.37/arch/mips/loongson/common/pm.c linux-2.6.37/arch/mips/loongson/common/pm.c
1766 --- linux-2.6.37/arch/mips/loongson/common/pm.c 2011-01-04 19:50:19.000000000 -0500
1767 +++ linux-2.6.37/arch/mips/loongson/common/pm.c 2011-01-17 02:41:00.000000000 -0500
1768 @@ -147,7 +147,7 @@ static int loongson_pm_valid_state(suspe
1772 -static struct platform_suspend_ops loongson_pm_ops = {
1773 +static const struct platform_suspend_ops loongson_pm_ops = {
1774 .valid = loongson_pm_valid_state,
1775 .enter = loongson_pm_enter,
1777 diff -urNp linux-2.6.37/arch/mips/mm/dma-default.c linux-2.6.37/arch/mips/mm/dma-default.c
1778 --- linux-2.6.37/arch/mips/mm/dma-default.c 2011-01-04 19:50:19.000000000 -0500
1779 +++ linux-2.6.37/arch/mips/mm/dma-default.c 2011-01-17 02:41:00.000000000 -0500
1780 @@ -300,7 +300,7 @@ void dma_cache_sync(struct device *dev,
1782 EXPORT_SYMBOL(dma_cache_sync);
1784 -static struct dma_map_ops mips_default_dma_map_ops = {
1785 +static const struct dma_map_ops mips_default_dma_map_ops = {
1786 .alloc_coherent = mips_dma_alloc_coherent,
1787 .free_coherent = mips_dma_free_coherent,
1788 .map_page = mips_dma_map_page,
1789 @@ -315,7 +315,7 @@ static struct dma_map_ops mips_default_d
1790 .dma_supported = mips_dma_supported
1793 -struct dma_map_ops *mips_dma_map_ops = &mips_default_dma_map_ops;
1794 +const struct dma_map_ops *mips_dma_map_ops = &mips_default_dma_map_ops;
1795 EXPORT_SYMBOL(mips_dma_map_ops);
1797 #define PREALLOC_DMA_DEBUG_ENTRIES (1 << 16)
1798 diff -urNp linux-2.6.37/arch/mips/mm/fault.c linux-2.6.37/arch/mips/mm/fault.c
1799 --- linux-2.6.37/arch/mips/mm/fault.c 2011-01-04 19:50:19.000000000 -0500
1800 +++ linux-2.6.37/arch/mips/mm/fault.c 2011-01-17 02:41:00.000000000 -0500
1802 #include <asm/highmem.h> /* For VMALLOC_END */
1803 #include <linux/kdebug.h>
1805 +#ifdef CONFIG_PAX_PAGEEXEC
1806 +void pax_report_insns(void *pc, void *sp)
1810 + printk(KERN_ERR "PAX: bytes at PC: ");
1811 + for (i = 0; i < 5; i++) {
1813 + if (get_user(c, (unsigned int *)pc+i))
1814 + printk(KERN_CONT "???????? ");
1816 + printk(KERN_CONT "%08x ", c);
1823 * This routine handles page faults. It determines the address,
1824 * and the problem, and then passes it off to one of the appropriate
1825 diff -urNp linux-2.6.37/arch/parisc/include/asm/elf.h linux-2.6.37/arch/parisc/include/asm/elf.h
1826 --- linux-2.6.37/arch/parisc/include/asm/elf.h 2011-01-04 19:50:19.000000000 -0500
1827 +++ linux-2.6.37/arch/parisc/include/asm/elf.h 2011-01-17 02:41:00.000000000 -0500
1828 @@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration..
1830 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
1832 +#ifdef CONFIG_PAX_ASLR
1833 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
1835 +#define PAX_DELTA_MMAP_LEN 16
1836 +#define PAX_DELTA_STACK_LEN 16
1839 /* This yields a mask that user programs can use to figure out what
1840 instruction set this CPU supports. This could be done in user space,
1841 but it's not easy, and we've already done it here. */
1842 diff -urNp linux-2.6.37/arch/parisc/include/asm/pgtable.h linux-2.6.37/arch/parisc/include/asm/pgtable.h
1843 --- linux-2.6.37/arch/parisc/include/asm/pgtable.h 2011-01-04 19:50:19.000000000 -0500
1844 +++ linux-2.6.37/arch/parisc/include/asm/pgtable.h 2011-01-17 02:41:00.000000000 -0500
1845 @@ -207,6 +207,17 @@
1846 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
1847 #define PAGE_COPY PAGE_EXECREAD
1848 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
1850 +#ifdef CONFIG_PAX_PAGEEXEC
1851 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
1852 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
1853 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
1855 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
1856 +# define PAGE_COPY_NOEXEC PAGE_COPY
1857 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
1860 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
1861 #define PAGE_KERNEL_RO __pgprot(_PAGE_KERNEL & ~_PAGE_WRITE)
1862 #define PAGE_KERNEL_UNC __pgprot(_PAGE_KERNEL | _PAGE_NO_CACHE)
1863 diff -urNp linux-2.6.37/arch/parisc/kernel/module.c linux-2.6.37/arch/parisc/kernel/module.c
1864 --- linux-2.6.37/arch/parisc/kernel/module.c 2011-01-04 19:50:19.000000000 -0500
1865 +++ linux-2.6.37/arch/parisc/kernel/module.c 2011-01-17 02:41:00.000000000 -0500
1868 /* three functions to determine where in the module core
1869 * or init pieces the location is */
1870 +static inline int in_init_rx(struct module *me, void *loc)
1872 + return (loc >= me->module_init_rx &&
1873 + loc < (me->module_init_rx + me->init_size_rx));
1876 +static inline int in_init_rw(struct module *me, void *loc)
1878 + return (loc >= me->module_init_rw &&
1879 + loc < (me->module_init_rw + me->init_size_rw));
1882 static inline int in_init(struct module *me, void *loc)
1884 - return (loc >= me->module_init &&
1885 - loc <= (me->module_init + me->init_size));
1886 + return in_init_rx(me, loc) || in_init_rw(me, loc);
1889 +static inline int in_core_rx(struct module *me, void *loc)
1891 + return (loc >= me->module_core_rx &&
1892 + loc < (me->module_core_rx + me->core_size_rx));
1895 +static inline int in_core_rw(struct module *me, void *loc)
1897 + return (loc >= me->module_core_rw &&
1898 + loc < (me->module_core_rw + me->core_size_rw));
1901 static inline int in_core(struct module *me, void *loc)
1903 - return (loc >= me->module_core &&
1904 - loc <= (me->module_core + me->core_size));
1905 + return in_core_rx(me, loc) || in_core_rw(me, loc);
1908 static inline int in_local(struct module *me, void *loc)
1909 @@ -365,13 +387,13 @@ int module_frob_arch_sections(CONST Elf_
1912 /* align things a bit */
1913 - me->core_size = ALIGN(me->core_size, 16);
1914 - me->arch.got_offset = me->core_size;
1915 - me->core_size += gots * sizeof(struct got_entry);
1917 - me->core_size = ALIGN(me->core_size, 16);
1918 - me->arch.fdesc_offset = me->core_size;
1919 - me->core_size += fdescs * sizeof(Elf_Fdesc);
1920 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
1921 + me->arch.got_offset = me->core_size_rw;
1922 + me->core_size_rw += gots * sizeof(struct got_entry);
1924 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
1925 + me->arch.fdesc_offset = me->core_size_rw;
1926 + me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
1928 me->arch.got_max = gots;
1929 me->arch.fdesc_max = fdescs;
1930 @@ -389,7 +411,7 @@ static Elf64_Word get_got(struct module
1934 - got = me->module_core + me->arch.got_offset;
1935 + got = me->module_core_rw + me->arch.got_offset;
1936 for (i = 0; got[i].addr; i++)
1937 if (got[i].addr == value)
1939 @@ -407,7 +429,7 @@ static Elf64_Word get_got(struct module
1941 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
1943 - Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
1944 + Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
1947 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
1948 @@ -425,7 +447,7 @@ static Elf_Addr get_fdesc(struct module
1950 /* Create new one */
1951 fdesc->addr = value;
1952 - fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
1953 + fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
1954 return (Elf_Addr)fdesc;
1956 #endif /* CONFIG_64BIT */
1957 @@ -849,7 +871,7 @@ register_unwind_table(struct module *me,
1959 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
1960 end = table + sechdrs[me->arch.unwind_section].sh_size;
1961 - gp = (Elf_Addr)me->module_core + me->arch.got_offset;
1962 + gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
1964 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
1965 me->arch.unwind_section, table, end, gp);
1966 diff -urNp linux-2.6.37/arch/parisc/kernel/sys_parisc.c linux-2.6.37/arch/parisc/kernel/sys_parisc.c
1967 --- linux-2.6.37/arch/parisc/kernel/sys_parisc.c 2011-01-04 19:50:19.000000000 -0500
1968 +++ linux-2.6.37/arch/parisc/kernel/sys_parisc.c 2011-01-17 02:41:00.000000000 -0500
1969 @@ -43,7 +43,7 @@ static unsigned long get_unshared_area(u
1970 /* At this point: (!vma || addr < vma->vm_end). */
1971 if (TASK_SIZE - len < addr)
1973 - if (!vma || addr + len <= vma->vm_start)
1974 + if (check_heap_stack_gap(vma, addr, len))
1978 @@ -79,7 +79,7 @@ static unsigned long get_shared_area(str
1979 /* At this point: (!vma || addr < vma->vm_end). */
1980 if (TASK_SIZE - len < addr)
1982 - if (!vma || addr + len <= vma->vm_start)
1983 + if (check_heap_stack_gap(vma, addr, len))
1985 addr = DCACHE_ALIGN(vma->vm_end - offset) + offset;
1986 if (addr < vma->vm_end) /* handle wraparound */
1987 @@ -98,7 +98,7 @@ unsigned long arch_get_unmapped_area(str
1988 if (flags & MAP_FIXED)
1991 - addr = TASK_UNMAPPED_BASE;
1992 + addr = current->mm->mmap_base;
1995 addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
1996 diff -urNp linux-2.6.37/arch/parisc/kernel/traps.c linux-2.6.37/arch/parisc/kernel/traps.c
1997 --- linux-2.6.37/arch/parisc/kernel/traps.c 2011-01-04 19:50:19.000000000 -0500
1998 +++ linux-2.6.37/arch/parisc/kernel/traps.c 2011-01-17 02:41:00.000000000 -0500
1999 @@ -733,9 +733,7 @@ void notrace handle_interruption(int cod
2001 down_read(¤t->mm->mmap_sem);
2002 vma = find_vma(current->mm,regs->iaoq[0]);
2003 - if (vma && (regs->iaoq[0] >= vma->vm_start)
2004 - && (vma->vm_flags & VM_EXEC)) {
2006 + if (vma && (regs->iaoq[0] >= vma->vm_start)) {
2007 fault_address = regs->iaoq[0];
2008 fault_space = regs->iasq[0];
2010 diff -urNp linux-2.6.37/arch/parisc/mm/fault.c linux-2.6.37/arch/parisc/mm/fault.c
2011 --- linux-2.6.37/arch/parisc/mm/fault.c 2011-01-04 19:50:19.000000000 -0500
2012 +++ linux-2.6.37/arch/parisc/mm/fault.c 2011-01-17 02:41:00.000000000 -0500
2014 #include <linux/sched.h>
2015 #include <linux/interrupt.h>
2016 #include <linux/module.h>
2017 +#include <linux/unistd.h>
2019 #include <asm/uaccess.h>
2020 #include <asm/traps.h>
2021 @@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, ex
2022 static unsigned long
2023 parisc_acctyp(unsigned long code, unsigned int inst)
2025 - if (code == 6 || code == 16)
2026 + if (code == 6 || code == 7 || code == 16)
2029 switch (inst & 0xf0000000) {
2030 @@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsign
2034 +#ifdef CONFIG_PAX_PAGEEXEC
2036 + * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
2038 + * returns 1 when task should be killed
2039 + * 2 when rt_sigreturn trampoline was detected
2040 + * 3 when unpatched PLT trampoline was detected
2042 +static int pax_handle_fetch_fault(struct pt_regs *regs)
2045 +#ifdef CONFIG_PAX_EMUPLT
2048 + do { /* PaX: unpatched PLT emulation */
2049 + unsigned int bl, depwi;
2051 + err = get_user(bl, (unsigned int *)instruction_pointer(regs));
2052 + err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
2057 + if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
2058 + unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
2060 + err = get_user(ldw, (unsigned int *)addr);
2061 + err |= get_user(bv, (unsigned int *)(addr+4));
2062 + err |= get_user(ldw2, (unsigned int *)(addr+8));
2067 + if (ldw == 0x0E801096U &&
2068 + bv == 0xEAC0C000U &&
2069 + ldw2 == 0x0E881095U)
2071 + unsigned int resolver, map;
2073 + err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
2074 + err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
2078 + regs->gr[20] = instruction_pointer(regs)+8;
2079 + regs->gr[21] = map;
2080 + regs->gr[22] = resolver;
2081 + regs->iaoq[0] = resolver | 3UL;
2082 + regs->iaoq[1] = regs->iaoq[0] + 4;
2089 +#ifdef CONFIG_PAX_EMUTRAMP
2091 +#ifndef CONFIG_PAX_EMUSIGRT
2092 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
2096 + do { /* PaX: rt_sigreturn emulation */
2097 + unsigned int ldi1, ldi2, bel, nop;
2099 + err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
2100 + err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
2101 + err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
2102 + err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
2107 + if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
2108 + ldi2 == 0x3414015AU &&
2109 + bel == 0xE4008200U &&
2110 + nop == 0x08000240U)
2112 + regs->gr[25] = (ldi1 & 2) >> 1;
2113 + regs->gr[20] = __NR_rt_sigreturn;
2114 + regs->gr[31] = regs->iaoq[1] + 16;
2115 + regs->sr[0] = regs->iasq[1];
2116 + regs->iaoq[0] = 0x100UL;
2117 + regs->iaoq[1] = regs->iaoq[0] + 4;
2118 + regs->iasq[0] = regs->sr[2];
2119 + regs->iasq[1] = regs->sr[2];
2128 +void pax_report_insns(void *pc, void *sp)
2132 + printk(KERN_ERR "PAX: bytes at PC: ");
2133 + for (i = 0; i < 5; i++) {
2135 + if (get_user(c, (unsigned int *)pc+i))
2136 + printk(KERN_CONT "???????? ");
2138 + printk(KERN_CONT "%08x ", c);
2144 int fixup_exception(struct pt_regs *regs)
2146 const struct exception_table_entry *fix;
2147 @@ -192,8 +303,33 @@ good_area:
2149 acc_type = parisc_acctyp(code,regs->iir);
2151 - if ((vma->vm_flags & acc_type) != acc_type)
2152 + if ((vma->vm_flags & acc_type) != acc_type) {
2154 +#ifdef CONFIG_PAX_PAGEEXEC
2155 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
2156 + (address & ~3UL) == instruction_pointer(regs))
2158 + up_read(&mm->mmap_sem);
2159 + switch (pax_handle_fetch_fault(regs)) {
2161 +#ifdef CONFIG_PAX_EMUPLT
2166 +#ifdef CONFIG_PAX_EMUTRAMP
2172 + pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
2173 + do_group_exit(SIGKILL);
2181 * If for any reason at all we couldn't handle the fault, make
2182 diff -urNp linux-2.6.37/arch/powerpc/include/asm/device.h linux-2.6.37/arch/powerpc/include/asm/device.h
2183 --- linux-2.6.37/arch/powerpc/include/asm/device.h 2011-01-04 19:50:19.000000000 -0500
2184 +++ linux-2.6.37/arch/powerpc/include/asm/device.h 2011-01-17 02:41:00.000000000 -0500
2185 @@ -11,7 +11,7 @@ struct device_node;
2187 struct dev_archdata {
2188 /* DMA operations on that device */
2189 - struct dma_map_ops *dma_ops;
2190 + const struct dma_map_ops *dma_ops;
2193 * When an iommu is in use, dma_data is used as a ptr to the base of the
2194 diff -urNp linux-2.6.37/arch/powerpc/include/asm/dma-mapping.h linux-2.6.37/arch/powerpc/include/asm/dma-mapping.h
2195 --- linux-2.6.37/arch/powerpc/include/asm/dma-mapping.h 2011-01-04 19:50:19.000000000 -0500
2196 +++ linux-2.6.37/arch/powerpc/include/asm/dma-mapping.h 2011-01-17 02:41:00.000000000 -0500
2197 @@ -66,12 +66,13 @@ static inline unsigned long device_to_ma
2199 * Available generic sets of operations
2201 +/* cannot be const */
2203 -extern struct dma_map_ops dma_iommu_ops;
2204 +extern const struct dma_map_ops dma_iommu_ops;
2206 -extern struct dma_map_ops dma_direct_ops;
2207 +extern const struct dma_map_ops dma_direct_ops;
2209 -static inline struct dma_map_ops *get_dma_ops(struct device *dev)
2210 +static inline const struct dma_map_ops *get_dma_ops(struct device *dev)
2212 /* We don't handle the NULL dev case for ISA for now. We could
2213 * do it via an out of line call but it is not needed for now. The
2214 @@ -84,7 +85,7 @@ static inline struct dma_map_ops *get_dm
2215 return dev->archdata.dma_ops;
2218 -static inline void set_dma_ops(struct device *dev, struct dma_map_ops *ops)
2219 +static inline void set_dma_ops(struct device *dev, const struct dma_map_ops *ops)
2221 dev->archdata.dma_ops = ops;
2223 @@ -118,7 +119,7 @@ static inline void set_dma_offset(struct
2225 static inline int dma_supported(struct device *dev, u64 mask)
2227 - struct dma_map_ops *dma_ops = get_dma_ops(dev);
2228 + const struct dma_map_ops *dma_ops = get_dma_ops(dev);
2230 if (unlikely(dma_ops == NULL))
2232 @@ -132,7 +133,7 @@ extern int dma_set_mask(struct device *d
2233 static inline void *dma_alloc_coherent(struct device *dev, size_t size,
2234 dma_addr_t *dma_handle, gfp_t flag)
2236 - struct dma_map_ops *dma_ops = get_dma_ops(dev);
2237 + const struct dma_map_ops *dma_ops = get_dma_ops(dev);
2241 @@ -147,7 +148,7 @@ static inline void *dma_alloc_coherent(s
2242 static inline void dma_free_coherent(struct device *dev, size_t size,
2243 void *cpu_addr, dma_addr_t dma_handle)
2245 - struct dma_map_ops *dma_ops = get_dma_ops(dev);
2246 + const struct dma_map_ops *dma_ops = get_dma_ops(dev);
2250 @@ -158,7 +159,7 @@ static inline void dma_free_coherent(str
2252 static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
2254 - struct dma_map_ops *dma_ops = get_dma_ops(dev);
2255 + const struct dma_map_ops *dma_ops = get_dma_ops(dev);
2257 if (dma_ops->mapping_error)
2258 return dma_ops->mapping_error(dev, dma_addr);
2259 diff -urNp linux-2.6.37/arch/powerpc/include/asm/elf.h linux-2.6.37/arch/powerpc/include/asm/elf.h
2260 --- linux-2.6.37/arch/powerpc/include/asm/elf.h 2011-01-04 19:50:19.000000000 -0500
2261 +++ linux-2.6.37/arch/powerpc/include/asm/elf.h 2011-01-17 02:41:00.000000000 -0500
2262 @@ -178,8 +178,19 @@ typedef elf_fpreg_t elf_vsrreghalf_t32[E
2263 the loader. We need to make sure that it is out of the way of the program
2264 that it will "exec", and that there is sufficient room for the brk. */
2266 -extern unsigned long randomize_et_dyn(unsigned long base);
2267 -#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
2268 +#define ELF_ET_DYN_BASE (0x20000000)
2270 +#ifdef CONFIG_PAX_ASLR
2271 +#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
2273 +#ifdef __powerpc64__
2274 +#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
2275 +#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
2277 +#define PAX_DELTA_MMAP_LEN 15
2278 +#define PAX_DELTA_STACK_LEN 15
2283 * Our registers are always unsigned longs, whether we're a 32 bit
2284 @@ -274,9 +285,6 @@ extern int arch_setup_additional_pages(s
2285 (0x7ff >> (PAGE_SHIFT - 12)) : \
2286 (0x3ffff >> (PAGE_SHIFT - 12)))
2288 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
2289 -#define arch_randomize_brk arch_randomize_brk
2291 #endif /* __KERNEL__ */
2294 diff -urNp linux-2.6.37/arch/powerpc/include/asm/iommu.h linux-2.6.37/arch/powerpc/include/asm/iommu.h
2295 --- linux-2.6.37/arch/powerpc/include/asm/iommu.h 2011-01-04 19:50:19.000000000 -0500
2296 +++ linux-2.6.37/arch/powerpc/include/asm/iommu.h 2011-01-17 02:41:00.000000000 -0500
2297 @@ -116,6 +116,9 @@ extern void iommu_init_early_iSeries(voi
2298 extern void iommu_init_early_dart(void);
2299 extern void iommu_init_early_pasemi(void);
2302 +extern int dma_iommu_dma_supported(struct device *dev, u64 mask);
2305 extern void pci_iommu_init(void);
2306 extern void pci_direct_iommu_init(void);
2307 diff -urNp linux-2.6.37/arch/powerpc/include/asm/kmap_types.h linux-2.6.37/arch/powerpc/include/asm/kmap_types.h
2308 --- linux-2.6.37/arch/powerpc/include/asm/kmap_types.h 2011-01-04 19:50:19.000000000 -0500
2309 +++ linux-2.6.37/arch/powerpc/include/asm/kmap_types.h 2011-01-17 02:41:00.000000000 -0500
2310 @@ -27,6 +27,7 @@ enum km_type {
2318 diff -urNp linux-2.6.37/arch/powerpc/include/asm/page_64.h linux-2.6.37/arch/powerpc/include/asm/page_64.h
2319 --- linux-2.6.37/arch/powerpc/include/asm/page_64.h 2011-01-04 19:50:19.000000000 -0500
2320 +++ linux-2.6.37/arch/powerpc/include/asm/page_64.h 2011-01-17 02:41:00.000000000 -0500
2321 @@ -172,15 +172,18 @@ do { \
2322 * stack by default, so in the absense of a PT_GNU_STACK program header
2323 * we turn execute permission off.
2325 -#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
2326 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
2327 +#define VM_STACK_DEFAULT_FLAGS32 \
2328 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
2329 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
2331 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
2332 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
2334 +#ifndef CONFIG_PAX_PAGEEXEC
2335 #define VM_STACK_DEFAULT_FLAGS \
2336 (is_32bit_task() ? \
2337 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
2340 #include <asm-generic/getorder.h>
2342 diff -urNp linux-2.6.37/arch/powerpc/include/asm/page.h linux-2.6.37/arch/powerpc/include/asm/page.h
2343 --- linux-2.6.37/arch/powerpc/include/asm/page.h 2011-01-04 19:50:19.000000000 -0500
2344 +++ linux-2.6.37/arch/powerpc/include/asm/page.h 2011-01-17 02:41:00.000000000 -0500
2345 @@ -129,8 +129,9 @@ extern phys_addr_t kernstart_addr;
2346 * and needs to be executable. This means the whole heap ends
2347 * up being executable.
2349 -#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
2350 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
2351 +#define VM_DATA_DEFAULT_FLAGS32 \
2352 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
2353 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
2355 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
2356 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
2357 @@ -158,6 +159,9 @@ extern phys_addr_t kernstart_addr;
2358 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
2361 +#define ktla_ktva(addr) (addr)
2362 +#define ktva_ktla(addr) (addr)
2364 #ifndef __ASSEMBLY__
2366 #undef STRICT_MM_TYPECHECKS
2367 diff -urNp linux-2.6.37/arch/powerpc/include/asm/pci.h linux-2.6.37/arch/powerpc/include/asm/pci.h
2368 --- linux-2.6.37/arch/powerpc/include/asm/pci.h 2011-01-04 19:50:19.000000000 -0500
2369 +++ linux-2.6.37/arch/powerpc/include/asm/pci.h 2011-01-17 02:41:00.000000000 -0500
2370 @@ -65,8 +65,8 @@ static inline int pci_get_legacy_ide_irq
2374 -extern void set_pci_dma_ops(struct dma_map_ops *dma_ops);
2375 -extern struct dma_map_ops *get_pci_dma_ops(void);
2376 +extern void set_pci_dma_ops(const struct dma_map_ops *dma_ops);
2377 +extern const struct dma_map_ops *get_pci_dma_ops(void);
2378 #else /* CONFIG_PCI */
2379 #define set_pci_dma_ops(d)
2380 #define get_pci_dma_ops() NULL
2381 diff -urNp linux-2.6.37/arch/powerpc/include/asm/pte-hash32.h linux-2.6.37/arch/powerpc/include/asm/pte-hash32.h
2382 --- linux-2.6.37/arch/powerpc/include/asm/pte-hash32.h 2011-01-04 19:50:19.000000000 -0500
2383 +++ linux-2.6.37/arch/powerpc/include/asm/pte-hash32.h 2011-01-17 02:41:00.000000000 -0500
2385 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
2386 #define _PAGE_USER 0x004 /* usermode access allowed */
2387 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
2388 +#define _PAGE_EXEC _PAGE_GUARDED
2389 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
2390 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
2391 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
2392 diff -urNp linux-2.6.37/arch/powerpc/include/asm/reg.h linux-2.6.37/arch/powerpc/include/asm/reg.h
2393 --- linux-2.6.37/arch/powerpc/include/asm/reg.h 2011-01-04 19:50:19.000000000 -0500
2394 +++ linux-2.6.37/arch/powerpc/include/asm/reg.h 2011-01-17 02:41:00.000000000 -0500
2396 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
2397 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
2398 #define DSISR_NOHPTE 0x40000000 /* no translation found */
2399 +#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
2400 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
2401 #define DSISR_ISSTORE 0x02000000 /* access was a store */
2402 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
2403 diff -urNp linux-2.6.37/arch/powerpc/include/asm/swiotlb.h linux-2.6.37/arch/powerpc/include/asm/swiotlb.h
2404 --- linux-2.6.37/arch/powerpc/include/asm/swiotlb.h 2011-01-04 19:50:19.000000000 -0500
2405 +++ linux-2.6.37/arch/powerpc/include/asm/swiotlb.h 2011-01-17 02:41:00.000000000 -0500
2408 #include <linux/swiotlb.h>
2410 -extern struct dma_map_ops swiotlb_dma_ops;
2411 +extern const struct dma_map_ops swiotlb_dma_ops;
2413 static inline void dma_mark_clean(void *addr, size_t size) {}
2415 diff -urNp linux-2.6.37/arch/powerpc/include/asm/system.h linux-2.6.37/arch/powerpc/include/asm/system.h
2416 --- linux-2.6.37/arch/powerpc/include/asm/system.h 2011-01-04 19:50:19.000000000 -0500
2417 +++ linux-2.6.37/arch/powerpc/include/asm/system.h 2011-01-17 02:41:00.000000000 -0500
2418 @@ -533,7 +533,7 @@ __cmpxchg_local(volatile void *ptr, unsi
2419 #define cmpxchg64_local(ptr, o, n) __cmpxchg64_local_generic((ptr), (o), (n))
2422 -extern unsigned long arch_align_stack(unsigned long sp);
2423 +#define arch_align_stack(x) ((x) & ~0xfUL)
2425 /* Used in very early kernel initialization. */
2426 extern unsigned long reloc_offset(void);
2427 diff -urNp linux-2.6.37/arch/powerpc/include/asm/uaccess.h linux-2.6.37/arch/powerpc/include/asm/uaccess.h
2428 --- linux-2.6.37/arch/powerpc/include/asm/uaccess.h 2011-01-04 19:50:19.000000000 -0500
2429 +++ linux-2.6.37/arch/powerpc/include/asm/uaccess.h 2011-01-17 02:41:00.000000000 -0500
2431 #define VERIFY_READ 0
2432 #define VERIFY_WRITE 1
2434 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
2437 * The fs value determines whether argument validity checking should be
2438 * performed or not. If get_fs() == USER_DS, checking is performed, with
2439 @@ -327,52 +329,6 @@ do { \
2440 extern unsigned long __copy_tofrom_user(void __user *to,
2441 const void __user *from, unsigned long size);
2443 -#ifndef __powerpc64__
2445 -static inline unsigned long copy_from_user(void *to,
2446 - const void __user *from, unsigned long n)
2448 - unsigned long over;
2450 - if (access_ok(VERIFY_READ, from, n))
2451 - return __copy_tofrom_user((__force void __user *)to, from, n);
2452 - if ((unsigned long)from < TASK_SIZE) {
2453 - over = (unsigned long)from + n - TASK_SIZE;
2454 - return __copy_tofrom_user((__force void __user *)to, from,
2460 -static inline unsigned long copy_to_user(void __user *to,
2461 - const void *from, unsigned long n)
2463 - unsigned long over;
2465 - if (access_ok(VERIFY_WRITE, to, n))
2466 - return __copy_tofrom_user(to, (__force void __user *)from, n);
2467 - if ((unsigned long)to < TASK_SIZE) {
2468 - over = (unsigned long)to + n - TASK_SIZE;
2469 - return __copy_tofrom_user(to, (__force void __user *)from,
2475 -#else /* __powerpc64__ */
2477 -#define __copy_in_user(to, from, size) \
2478 - __copy_tofrom_user((to), (from), (size))
2480 -extern unsigned long copy_from_user(void *to, const void __user *from,
2482 -extern unsigned long copy_to_user(void __user *to, const void *from,
2484 -extern unsigned long copy_in_user(void __user *to, const void __user *from,
2487 -#endif /* __powerpc64__ */
2489 static inline unsigned long __copy_from_user_inatomic(void *to,
2490 const void __user *from, unsigned long n)
2492 @@ -396,6 +352,10 @@ static inline unsigned long __copy_from_
2497 + if (!__builtin_constant_p(n))
2498 + check_object_size(to, n, false);
2500 return __copy_tofrom_user((__force void __user *)to, from, n);
2503 @@ -422,6 +382,10 @@ static inline unsigned long __copy_to_us
2508 + if (!__builtin_constant_p(n))
2509 + check_object_size(from, n, true);
2511 return __copy_tofrom_user(to, (__force const void __user *)from, n);
2514 @@ -439,6 +403,92 @@ static inline unsigned long __copy_to_us
2515 return __copy_to_user_inatomic(to, from, size);
2518 +#ifndef __powerpc64__
2520 +static inline unsigned long __must_check copy_from_user(void *to,
2521 + const void __user *from, unsigned long n)
2523 + unsigned long over;
2528 + if (access_ok(VERIFY_READ, from, n)) {
2529 + if (!__builtin_constant_p(n))
2530 + check_object_size(to, n, false);
2531 + return __copy_tofrom_user((__force void __user *)to, from, n);
2533 + if ((unsigned long)from < TASK_SIZE) {
2534 + over = (unsigned long)from + n - TASK_SIZE;
2535 + if (!__builtin_constant_p(n - over))
2536 + check_object_size(to, n - over, false);
2537 + return __copy_tofrom_user((__force void __user *)to, from,
2543 +static inline unsigned long __must_check copy_to_user(void __user *to,
2544 + const void *from, unsigned long n)
2546 + unsigned long over;
2551 + if (access_ok(VERIFY_WRITE, to, n)) {
2552 + if (!__builtin_constant_p(n))
2553 + check_object_size(from, n, true);
2554 + return __copy_tofrom_user(to, (__force void __user *)from, n);
2556 + if ((unsigned long)to < TASK_SIZE) {
2557 + over = (unsigned long)to + n - TASK_SIZE;
2558 + if (!__builtin_constant_p(n))
2559 + check_object_size(from, n - over, true);
2560 + return __copy_tofrom_user(to, (__force void __user *)from,
2566 +#else /* __powerpc64__ */
2568 +#define __copy_in_user(to, from, size) \
2569 + __copy_tofrom_user((to), (from), (size))
2571 +static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
2573 + if ((long)n < 0 || n > INT_MAX)
2576 + if (!__builtin_constant_p(n))
2577 + check_object_size(to, n, false);
2579 + if (likely(access_ok(VERIFY_READ, from, n)))
2580 + n = __copy_from_user(to, from, n);
2586 +static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
2588 + if ((long)n < 0 || n > INT_MAX)
2591 + if (likely(access_ok(VERIFY_WRITE, to, n))) {
2592 + if (!__builtin_constant_p(n))
2593 + check_object_size(from, n, true);
2594 + n = __copy_to_user(to, from, n);
2599 +extern unsigned long copy_in_user(void __user *to, const void __user *from,
2602 +#endif /* __powerpc64__ */
2604 extern unsigned long __clear_user(void __user *addr, unsigned long size);
2606 static inline unsigned long clear_user(void __user *addr, unsigned long size)
2607 diff -urNp linux-2.6.37/arch/powerpc/kernel/dma.c linux-2.6.37/arch/powerpc/kernel/dma.c
2608 --- linux-2.6.37/arch/powerpc/kernel/dma.c 2011-01-04 19:50:19.000000000 -0500
2609 +++ linux-2.6.37/arch/powerpc/kernel/dma.c 2011-01-17 02:41:00.000000000 -0500
2610 @@ -136,7 +136,7 @@ static inline void dma_direct_sync_singl
2614 -struct dma_map_ops dma_direct_ops = {
2615 +const struct dma_map_ops dma_direct_ops = {
2616 .alloc_coherent = dma_direct_alloc_coherent,
2617 .free_coherent = dma_direct_free_coherent,
2618 .map_sg = dma_direct_map_sg,
2619 @@ -157,7 +157,7 @@ EXPORT_SYMBOL(dma_direct_ops);
2621 int dma_set_mask(struct device *dev, u64 dma_mask)
2623 - struct dma_map_ops *dma_ops = get_dma_ops(dev);
2624 + const struct dma_map_ops *dma_ops = get_dma_ops(dev);
2626 if (ppc_md.dma_set_mask)
2627 return ppc_md.dma_set_mask(dev, dma_mask);
2628 diff -urNp linux-2.6.37/arch/powerpc/kernel/dma-iommu.c linux-2.6.37/arch/powerpc/kernel/dma-iommu.c
2629 --- linux-2.6.37/arch/powerpc/kernel/dma-iommu.c 2011-01-04 19:50:19.000000000 -0500
2630 +++ linux-2.6.37/arch/powerpc/kernel/dma-iommu.c 2011-01-17 02:41:00.000000000 -0500
2631 @@ -70,7 +70,7 @@ static void dma_iommu_unmap_sg(struct de
2634 /* We support DMA to/from any memory page via the iommu */
2635 -static int dma_iommu_dma_supported(struct device *dev, u64 mask)
2636 +int dma_iommu_dma_supported(struct device *dev, u64 mask)
2638 struct iommu_table *tbl = get_iommu_table_base(dev);
2640 @@ -90,6 +90,7 @@ static int dma_iommu_dma_supported(struc
2644 +/* cannot be const, see arch/powerpc/platforms/cell/iommu.c */
2645 struct dma_map_ops dma_iommu_ops = {
2646 .alloc_coherent = dma_iommu_alloc_coherent,
2647 .free_coherent = dma_iommu_free_coherent,
2648 diff -urNp linux-2.6.37/arch/powerpc/kernel/dma-swiotlb.c linux-2.6.37/arch/powerpc/kernel/dma-swiotlb.c
2649 --- linux-2.6.37/arch/powerpc/kernel/dma-swiotlb.c 2011-01-04 19:50:19.000000000 -0500
2650 +++ linux-2.6.37/arch/powerpc/kernel/dma-swiotlb.c 2011-01-17 02:41:00.000000000 -0500
2651 @@ -31,7 +31,7 @@ unsigned int ppc_swiotlb_enable;
2652 * map_page, and unmap_page on highmem, use normal dma_ops
2653 * for everything else.
2655 -struct dma_map_ops swiotlb_dma_ops = {
2656 +const struct dma_map_ops swiotlb_dma_ops = {
2657 .alloc_coherent = dma_direct_alloc_coherent,
2658 .free_coherent = dma_direct_free_coherent,
2659 .map_sg = swiotlb_map_sg_attrs,
2660 diff -urNp linux-2.6.37/arch/powerpc/kernel/exceptions-64e.S linux-2.6.37/arch/powerpc/kernel/exceptions-64e.S
2661 --- linux-2.6.37/arch/powerpc/kernel/exceptions-64e.S 2011-01-04 19:50:19.000000000 -0500
2662 +++ linux-2.6.37/arch/powerpc/kernel/exceptions-64e.S 2011-01-17 02:41:00.000000000 -0500
2663 @@ -495,6 +495,7 @@ storage_fault_common:
2666 addi r3,r1,STACK_FRAME_OVERHEAD
2670 ld r14,PACA_EXGEN+EX_R14(r13)
2671 @@ -504,8 +505,7 @@ storage_fault_common:
2674 b .ret_from_except_lite
2678 addi r3,r1,STACK_FRAME_OVERHEAD
2681 diff -urNp linux-2.6.37/arch/powerpc/kernel/exceptions-64s.S linux-2.6.37/arch/powerpc/kernel/exceptions-64s.S
2682 --- linux-2.6.37/arch/powerpc/kernel/exceptions-64s.S 2011-01-04 19:50:19.000000000 -0500
2683 +++ linux-2.6.37/arch/powerpc/kernel/exceptions-64s.S 2011-01-17 02:41:00.000000000 -0500
2684 @@ -847,10 +847,10 @@ handle_page_fault:
2687 addi r3,r1,STACK_FRAME_OVERHEAD
2694 addi r3,r1,STACK_FRAME_OVERHEAD
2696 diff -urNp linux-2.6.37/arch/powerpc/kernel/ibmebus.c linux-2.6.37/arch/powerpc/kernel/ibmebus.c
2697 --- linux-2.6.37/arch/powerpc/kernel/ibmebus.c 2011-01-04 19:50:19.000000000 -0500
2698 +++ linux-2.6.37/arch/powerpc/kernel/ibmebus.c 2011-01-17 02:41:00.000000000 -0500
2699 @@ -128,7 +128,7 @@ static int ibmebus_dma_supported(struct
2703 -static struct dma_map_ops ibmebus_dma_ops = {
2704 +static const struct dma_map_ops ibmebus_dma_ops = {
2705 .alloc_coherent = ibmebus_alloc_coherent,
2706 .free_coherent = ibmebus_free_coherent,
2707 .map_sg = ibmebus_map_sg,
2708 diff -urNp linux-2.6.37/arch/powerpc/kernel/kgdb.c linux-2.6.37/arch/powerpc/kernel/kgdb.c
2709 --- linux-2.6.37/arch/powerpc/kernel/kgdb.c 2011-01-04 19:50:19.000000000 -0500
2710 +++ linux-2.6.37/arch/powerpc/kernel/kgdb.c 2011-01-17 02:41:00.000000000 -0500
2711 @@ -422,7 +422,7 @@ int kgdb_arch_handle_exception(int vecto
2715 -struct kgdb_arch arch_kgdb_ops = {
2716 +const struct kgdb_arch arch_kgdb_ops = {
2717 .gdb_bpt_instr = {0x7d, 0x82, 0x10, 0x08},
2720 diff -urNp linux-2.6.37/arch/powerpc/kernel/module_32.c linux-2.6.37/arch/powerpc/kernel/module_32.c
2721 --- linux-2.6.37/arch/powerpc/kernel/module_32.c 2011-01-04 19:50:19.000000000 -0500
2722 +++ linux-2.6.37/arch/powerpc/kernel/module_32.c 2011-01-17 02:41:00.000000000 -0500
2723 @@ -162,7 +162,7 @@ int module_frob_arch_sections(Elf32_Ehdr
2724 me->arch.core_plt_section = i;
2726 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
2727 - printk("Module doesn't contain .plt or .init.plt sections.\n");
2728 + printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
2732 @@ -203,11 +203,16 @@ static uint32_t do_plt_call(void *locati
2734 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
2735 /* Init, or core PLT? */
2736 - if (location >= mod->module_core
2737 - && location < mod->module_core + mod->core_size)
2738 + if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
2739 + (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
2740 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
2742 + else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
2743 + (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
2744 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
2746 + printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
2750 /* Find this entry, or if that fails, the next avail. entry */
2751 while (entry->jump[0]) {
2752 diff -urNp linux-2.6.37/arch/powerpc/kernel/module.c linux-2.6.37/arch/powerpc/kernel/module.c
2753 --- linux-2.6.37/arch/powerpc/kernel/module.c 2011-01-04 19:50:19.000000000 -0500
2754 +++ linux-2.6.37/arch/powerpc/kernel/module.c 2011-01-17 02:41:00.000000000 -0500
2757 LIST_HEAD(module_bug_list);
2759 +#ifdef CONFIG_PAX_KERNEXEC
2760 void *module_alloc(unsigned long size)
2765 + return vmalloc(size);
2768 +void *module_alloc_exec(unsigned long size)
2770 +void *module_alloc(unsigned long size)
2777 return vmalloc_exec(size);
2780 @@ -45,6 +58,13 @@ void module_free(struct module *mod, voi
2781 vfree(module_region);
2784 +#ifdef CONFIG_PAX_KERNEXEC
2785 +void module_free_exec(struct module *mod, void *module_region)
2787 + module_free(mod, module_region);
2791 static const Elf_Shdr *find_section(const Elf_Ehdr *hdr,
2792 const Elf_Shdr *sechdrs,
2794 diff -urNp linux-2.6.37/arch/powerpc/kernel/pci-common.c linux-2.6.37/arch/powerpc/kernel/pci-common.c
2795 --- linux-2.6.37/arch/powerpc/kernel/pci-common.c 2011-01-04 19:50:19.000000000 -0500
2796 +++ linux-2.6.37/arch/powerpc/kernel/pci-common.c 2011-01-17 02:41:00.000000000 -0500
2797 @@ -52,14 +52,14 @@ resource_size_t isa_mem_base;
2798 unsigned int ppc_pci_flags = 0;
2801 -static struct dma_map_ops *pci_dma_ops = &dma_direct_ops;
2802 +static const struct dma_map_ops *pci_dma_ops = &dma_direct_ops;
2804 -void set_pci_dma_ops(struct dma_map_ops *dma_ops)
2805 +void set_pci_dma_ops(const struct dma_map_ops *dma_ops)
2807 pci_dma_ops = dma_ops;
2810 -struct dma_map_ops *get_pci_dma_ops(void)
2811 +const struct dma_map_ops *get_pci_dma_ops(void)
2815 diff -urNp linux-2.6.37/arch/powerpc/kernel/process.c linux-2.6.37/arch/powerpc/kernel/process.c
2816 --- linux-2.6.37/arch/powerpc/kernel/process.c 2011-01-04 19:50:19.000000000 -0500
2817 +++ linux-2.6.37/arch/powerpc/kernel/process.c 2011-01-17 02:41:00.000000000 -0500
2818 @@ -653,8 +653,8 @@ void show_regs(struct pt_regs * regs)
2819 * Lookup NIP late so we have the best change of getting the
2820 * above info out without failing
2822 - printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
2823 - printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
2824 + printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
2825 + printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
2827 show_stack(current, (unsigned long *) regs->gpr[1]);
2828 if (!user_mode(regs))
2829 @@ -1144,10 +1144,10 @@ void show_stack(struct task_struct *tsk,
2831 ip = stack[STACK_FRAME_LR_SAVE];
2832 if (!firstframe || ip != lr) {
2833 - printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
2834 + printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
2835 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
2836 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
2839 (void *)current->ret_stack[curr_frame].ret);
2842 @@ -1167,7 +1167,7 @@ void show_stack(struct task_struct *tsk,
2843 struct pt_regs *regs = (struct pt_regs *)
2844 (sp + STACK_FRAME_OVERHEAD);
2846 - printk("--- Exception: %lx at %pS\n LR = %pS\n",
2847 + printk("--- Exception: %lx at %pA\n LR = %pA\n",
2848 regs->trap, (void *)regs->nip, (void *)lr);
2851 @@ -1242,58 +1242,3 @@ void thread_info_cache_init(void)
2854 #endif /* THREAD_SHIFT < PAGE_SHIFT */
2856 -unsigned long arch_align_stack(unsigned long sp)
2858 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
2859 - sp -= get_random_int() & ~PAGE_MASK;
2863 -static inline unsigned long brk_rnd(void)
2865 - unsigned long rnd = 0;
2867 - /* 8MB for 32bit, 1GB for 64bit */
2868 - if (is_32bit_task())
2869 - rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
2871 - rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
2873 - return rnd << PAGE_SHIFT;
2876 -unsigned long arch_randomize_brk(struct mm_struct *mm)
2878 - unsigned long base = mm->brk;
2879 - unsigned long ret;
2881 -#ifdef CONFIG_PPC_STD_MMU_64
2883 - * If we are using 1TB segments and we are allowed to randomise
2884 - * the heap, we can put it above 1TB so it is backed by a 1TB
2885 - * segment. Otherwise the heap will be in the bottom 1TB
2886 - * which always uses 256MB segments and this may result in a
2887 - * performance penalty.
2889 - if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
2890 - base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
2893 - ret = PAGE_ALIGN(base + brk_rnd());
2895 - if (ret < mm->brk)
2901 -unsigned long randomize_et_dyn(unsigned long base)
2903 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
2910 diff -urNp linux-2.6.37/arch/powerpc/kernel/signal_32.c linux-2.6.37/arch/powerpc/kernel/signal_32.c
2911 --- linux-2.6.37/arch/powerpc/kernel/signal_32.c 2011-01-04 19:50:19.000000000 -0500
2912 +++ linux-2.6.37/arch/powerpc/kernel/signal_32.c 2011-01-17 02:41:00.000000000 -0500
2913 @@ -858,7 +858,7 @@ int handle_rt_signal32(unsigned long sig
2914 /* Save user registers on the stack */
2915 frame = &rt_sf->uc.uc_mcontext;
2917 - if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
2918 + if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
2919 if (save_user_regs(regs, frame, 0, 1))
2921 regs->link = current->mm->context.vdso_base + vdso32_rt_sigtramp;
2922 diff -urNp linux-2.6.37/arch/powerpc/kernel/signal_64.c linux-2.6.37/arch/powerpc/kernel/signal_64.c
2923 --- linux-2.6.37/arch/powerpc/kernel/signal_64.c 2011-01-04 19:50:19.000000000 -0500
2924 +++ linux-2.6.37/arch/powerpc/kernel/signal_64.c 2011-01-17 02:41:00.000000000 -0500
2925 @@ -429,7 +429,7 @@ int handle_rt_signal64(int signr, struct
2926 current->thread.fpscr.val = 0;
2928 /* Set up to return from userspace. */
2929 - if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
2930 + if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
2931 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
2933 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
2934 diff -urNp linux-2.6.37/arch/powerpc/kernel/vdso.c linux-2.6.37/arch/powerpc/kernel/vdso.c
2935 --- linux-2.6.37/arch/powerpc/kernel/vdso.c 2011-01-04 19:50:19.000000000 -0500
2936 +++ linux-2.6.37/arch/powerpc/kernel/vdso.c 2011-01-17 02:41:00.000000000 -0500
2938 #include <asm/firmware.h>
2939 #include <asm/vdso.h>
2940 #include <asm/vdso_datapage.h>
2941 +#include <asm/mman.h>
2945 @@ -220,7 +221,7 @@ int arch_setup_additional_pages(struct l
2946 vdso_base = VDSO32_MBASE;
2949 - current->mm->context.vdso_base = 0;
2950 + current->mm->context.vdso_base = ~0UL;
2952 /* vDSO has a problem and was disabled, just don't "enable" it for the
2954 @@ -240,7 +241,7 @@ int arch_setup_additional_pages(struct l
2955 vdso_base = get_unmapped_area(NULL, vdso_base,
2956 (vdso_pages << PAGE_SHIFT) +
2957 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
2959 + 0, MAP_PRIVATE | MAP_EXECUTABLE);
2960 if (IS_ERR_VALUE(vdso_base)) {
2963 diff -urNp linux-2.6.37/arch/powerpc/kernel/vio.c linux-2.6.37/arch/powerpc/kernel/vio.c
2964 --- linux-2.6.37/arch/powerpc/kernel/vio.c 2011-01-04 19:50:19.000000000 -0500
2965 +++ linux-2.6.37/arch/powerpc/kernel/vio.c 2011-01-17 02:41:00.000000000 -0500
2966 @@ -600,11 +600,12 @@ static void vio_dma_iommu_unmap_sg(struc
2967 vio_cmo_dealloc(viodev, alloc_size);
2970 -struct dma_map_ops vio_dma_mapping_ops = {
2971 +static const struct dma_map_ops vio_dma_mapping_ops = {
2972 .alloc_coherent = vio_dma_iommu_alloc_coherent,
2973 .free_coherent = vio_dma_iommu_free_coherent,
2974 .map_sg = vio_dma_iommu_map_sg,
2975 .unmap_sg = vio_dma_iommu_unmap_sg,
2976 + .dma_supported = dma_iommu_dma_supported,
2977 .map_page = vio_dma_iommu_map_page,
2978 .unmap_page = vio_dma_iommu_unmap_page,
2980 @@ -858,7 +859,6 @@ static void vio_cmo_bus_remove(struct vi
2982 static void vio_cmo_set_dma_ops(struct vio_dev *viodev)
2984 - vio_dma_mapping_ops.dma_supported = dma_iommu_ops.dma_supported;
2985 viodev->dev.archdata.dma_ops = &vio_dma_mapping_ops;
2988 diff -urNp linux-2.6.37/arch/powerpc/lib/usercopy_64.c linux-2.6.37/arch/powerpc/lib/usercopy_64.c
2989 --- linux-2.6.37/arch/powerpc/lib/usercopy_64.c 2011-01-04 19:50:19.000000000 -0500
2990 +++ linux-2.6.37/arch/powerpc/lib/usercopy_64.c 2011-01-17 02:41:00.000000000 -0500
2992 #include <linux/module.h>
2993 #include <asm/uaccess.h>
2995 -unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
2997 - if (likely(access_ok(VERIFY_READ, from, n)))
2998 - n = __copy_from_user(to, from, n);
3004 -unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
3006 - if (likely(access_ok(VERIFY_WRITE, to, n)))
3007 - n = __copy_to_user(to, from, n);
3011 unsigned long copy_in_user(void __user *to, const void __user *from,
3014 @@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *
3018 -EXPORT_SYMBOL(copy_from_user);
3019 -EXPORT_SYMBOL(copy_to_user);
3020 EXPORT_SYMBOL(copy_in_user);
3022 diff -urNp linux-2.6.37/arch/powerpc/mm/fault.c linux-2.6.37/arch/powerpc/mm/fault.c
3023 --- linux-2.6.37/arch/powerpc/mm/fault.c 2011-01-04 19:50:19.000000000 -0500
3024 +++ linux-2.6.37/arch/powerpc/mm/fault.c 2011-01-17 02:41:00.000000000 -0500
3026 #include <linux/kdebug.h>
3027 #include <linux/perf_event.h>
3028 #include <linux/magic.h>
3029 +#include <linux/slab.h>
3030 +#include <linux/pagemap.h>
3031 +#include <linux/compiler.h>
3032 +#include <linux/unistd.h>
3034 #include <asm/firmware.h>
3035 #include <asm/page.h>
3037 #include <asm/tlbflush.h>
3038 #include <asm/siginfo.h>
3039 #include <mm/mmu_decl.h>
3040 +#include <asm/ptrace.h>
3042 #ifdef CONFIG_KPROBES
3043 static inline int notify_page_fault(struct pt_regs *regs)
3044 @@ -65,6 +70,33 @@ static inline int notify_page_fault(stru
3048 +#ifdef CONFIG_PAX_PAGEEXEC
3050 + * PaX: decide what to do with offenders (regs->nip = fault address)
3052 + * returns 1 when task should be killed
3054 +static int pax_handle_fetch_fault(struct pt_regs *regs)
3059 +void pax_report_insns(void *pc, void *sp)
3063 + printk(KERN_ERR "PAX: bytes at PC: ");
3064 + for (i = 0; i < 5; i++) {
3066 + if (get_user(c, (unsigned int __user *)pc+i))
3067 + printk(KERN_CONT "???????? ");
3069 + printk(KERN_CONT "%08x ", c);
3076 * Check whether the instruction at regs->nip is a store using
3077 * an update addressing form which will update r1.
3078 @@ -135,7 +167,7 @@ int __kprobes do_page_fault(struct pt_re
3079 * indicate errors in DSISR but can validly be set in SRR1.
3082 - error_code &= 0x48200000;
3083 + error_code &= 0x58200000;
3085 is_write = error_code & DSISR_ISSTORE;
3087 @@ -258,7 +290,7 @@ good_area:
3088 * "undefined". Of those that can be set, this is the only
3089 * one which seems bad.
3091 - if (error_code & 0x10000000)
3092 + if (error_code & DSISR_GUARDED)
3093 /* Guarded storage error. */
3095 #endif /* CONFIG_8xx */
3096 @@ -273,7 +305,7 @@ good_area:
3097 * processors use the same I/D cache coherency mechanism
3100 - if (error_code & DSISR_PROTFAULT)
3101 + if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
3103 #endif /* CONFIG_PPC_STD_MMU */
3105 @@ -342,6 +374,23 @@ bad_area:
3106 bad_area_nosemaphore:
3107 /* User mode accesses cause a SIGSEGV */
3108 if (user_mode(regs)) {
3110 +#ifdef CONFIG_PAX_PAGEEXEC
3111 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
3112 +#ifdef CONFIG_PPC_STD_MMU
3113 + if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
3115 + if (is_exec && regs->nip == address) {
3117 + switch (pax_handle_fetch_fault(regs)) {
3120 + pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
3121 + do_group_exit(SIGKILL);
3126 _exception(SIGSEGV, regs, code, address);
3129 diff -urNp linux-2.6.37/arch/powerpc/mm/mmap_64.c linux-2.6.37/arch/powerpc/mm/mmap_64.c
3130 --- linux-2.6.37/arch/powerpc/mm/mmap_64.c 2011-01-04 19:50:19.000000000 -0500
3131 +++ linux-2.6.37/arch/powerpc/mm/mmap_64.c 2011-01-17 02:41:00.000000000 -0500
3132 @@ -99,10 +99,22 @@ void arch_pick_mmap_layout(struct mm_str
3134 if (mmap_is_legacy()) {
3135 mm->mmap_base = TASK_UNMAPPED_BASE;
3137 +#ifdef CONFIG_PAX_RANDMMAP
3138 + if (mm->pax_flags & MF_PAX_RANDMMAP)
3139 + mm->mmap_base += mm->delta_mmap;
3142 mm->get_unmapped_area = arch_get_unmapped_area;
3143 mm->unmap_area = arch_unmap_area;
3145 mm->mmap_base = mmap_base();
3147 +#ifdef CONFIG_PAX_RANDMMAP
3148 + if (mm->pax_flags & MF_PAX_RANDMMAP)
3149 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
3152 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
3153 mm->unmap_area = arch_unmap_area_topdown;
3155 diff -urNp linux-2.6.37/arch/powerpc/mm/slice.c linux-2.6.37/arch/powerpc/mm/slice.c
3156 --- linux-2.6.37/arch/powerpc/mm/slice.c 2011-01-04 19:50:19.000000000 -0500
3157 +++ linux-2.6.37/arch/powerpc/mm/slice.c 2011-01-17 02:41:00.000000000 -0500
3158 @@ -98,7 +98,7 @@ static int slice_area_is_free(struct mm_
3159 if ((mm->task_size - len) < addr)
3161 vma = find_vma(mm, addr);
3162 - return (!vma || (addr + len) <= vma->vm_start);
3163 + return check_heap_stack_gap(vma, addr, len);
3166 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
3167 @@ -256,7 +256,7 @@ full_search:
3168 addr = _ALIGN_UP(addr + 1, 1ul << SLICE_HIGH_SHIFT);
3171 - if (!vma || addr + len <= vma->vm_start) {
3172 + if (check_heap_stack_gap(vma, addr, len)) {
3174 * Remember the place where we stopped the search:
3176 @@ -336,7 +336,7 @@ static unsigned long slice_find_area_top
3177 * return with success:
3179 vma = find_vma(mm, addr);
3180 - if (!vma || (addr + len) <= vma->vm_start) {
3181 + if (check_heap_stack_gap(vma, addr, len)) {
3182 /* remember the address as a hint for next time */
3184 mm->free_area_cache = addr;
3185 @@ -426,6 +426,11 @@ unsigned long slice_get_unmapped_area(un
3186 if (fixed && addr > (mm->task_size - len))
3189 +#ifdef CONFIG_PAX_RANDMMAP
3190 + if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
3194 /* If hint, make sure it matches our alignment restrictions */
3195 if (!fixed && addr) {
3196 addr = _ALIGN_UP(addr, 1ul << pshift);
3197 diff -urNp linux-2.6.37/arch/powerpc/platforms/52xx/lite5200_pm.c linux-2.6.37/arch/powerpc/platforms/52xx/lite5200_pm.c
3198 --- linux-2.6.37/arch/powerpc/platforms/52xx/lite5200_pm.c 2011-01-04 19:50:19.000000000 -0500
3199 +++ linux-2.6.37/arch/powerpc/platforms/52xx/lite5200_pm.c 2011-01-17 02:41:00.000000000 -0500
3200 @@ -232,7 +232,7 @@ static void lite5200_pm_end(void)
3201 lite5200_pm_target_state = PM_SUSPEND_ON;
3204 -static struct platform_suspend_ops lite5200_pm_ops = {
3205 +static const struct platform_suspend_ops lite5200_pm_ops = {
3206 .valid = lite5200_pm_valid,
3207 .begin = lite5200_pm_begin,
3208 .prepare = lite5200_pm_prepare,
3209 diff -urNp linux-2.6.37/arch/powerpc/platforms/52xx/mpc52xx_pm.c linux-2.6.37/arch/powerpc/platforms/52xx/mpc52xx_pm.c
3210 --- linux-2.6.37/arch/powerpc/platforms/52xx/mpc52xx_pm.c 2011-01-04 19:50:19.000000000 -0500
3211 +++ linux-2.6.37/arch/powerpc/platforms/52xx/mpc52xx_pm.c 2011-01-17 02:41:00.000000000 -0500
3212 @@ -186,7 +186,7 @@ void mpc52xx_pm_finish(void)
3216 -static struct platform_suspend_ops mpc52xx_pm_ops = {
3217 +static const struct platform_suspend_ops mpc52xx_pm_ops = {
3218 .valid = mpc52xx_pm_valid,
3219 .prepare = mpc52xx_pm_prepare,
3220 .enter = mpc52xx_pm_enter,
3221 diff -urNp linux-2.6.37/arch/powerpc/platforms/83xx/suspend.c linux-2.6.37/arch/powerpc/platforms/83xx/suspend.c
3222 --- linux-2.6.37/arch/powerpc/platforms/83xx/suspend.c 2011-01-04 19:50:19.000000000 -0500
3223 +++ linux-2.6.37/arch/powerpc/platforms/83xx/suspend.c 2011-01-17 02:41:00.000000000 -0500
3224 @@ -311,7 +311,7 @@ static int mpc83xx_is_pci_agent(void)
3228 -static struct platform_suspend_ops mpc83xx_suspend_ops = {
3229 +static const struct platform_suspend_ops mpc83xx_suspend_ops = {
3230 .valid = mpc83xx_suspend_valid,
3231 .begin = mpc83xx_suspend_begin,
3232 .enter = mpc83xx_suspend_enter,
3233 diff -urNp linux-2.6.37/arch/powerpc/platforms/cell/iommu.c linux-2.6.37/arch/powerpc/platforms/cell/iommu.c
3234 --- linux-2.6.37/arch/powerpc/platforms/cell/iommu.c 2011-01-04 19:50:19.000000000 -0500
3235 +++ linux-2.6.37/arch/powerpc/platforms/cell/iommu.c 2011-01-17 02:41:00.000000000 -0500
3236 @@ -642,7 +642,7 @@ static int dma_fixed_dma_supported(struc
3238 static int dma_set_mask_and_switch(struct device *dev, u64 dma_mask);
3240 -struct dma_map_ops dma_iommu_fixed_ops = {
3241 +const struct dma_map_ops dma_iommu_fixed_ops = {
3242 .alloc_coherent = dma_fixed_alloc_coherent,
3243 .free_coherent = dma_fixed_free_coherent,
3244 .map_sg = dma_fixed_map_sg,
3245 diff -urNp linux-2.6.37/arch/powerpc/platforms/ps3/system-bus.c linux-2.6.37/arch/powerpc/platforms/ps3/system-bus.c
3246 --- linux-2.6.37/arch/powerpc/platforms/ps3/system-bus.c 2011-01-04 19:50:19.000000000 -0500
3247 +++ linux-2.6.37/arch/powerpc/platforms/ps3/system-bus.c 2011-01-17 02:41:00.000000000 -0500
3248 @@ -695,7 +695,7 @@ static int ps3_dma_supported(struct devi
3249 return mask >= DMA_BIT_MASK(32);
3252 -static struct dma_map_ops ps3_sb_dma_ops = {
3253 +static const struct dma_map_ops ps3_sb_dma_ops = {
3254 .alloc_coherent = ps3_alloc_coherent,
3255 .free_coherent = ps3_free_coherent,
3256 .map_sg = ps3_sb_map_sg,
3257 @@ -705,7 +705,7 @@ static struct dma_map_ops ps3_sb_dma_ops
3258 .unmap_page = ps3_unmap_page,
3261 -static struct dma_map_ops ps3_ioc0_dma_ops = {
3262 +static const struct dma_map_ops ps3_ioc0_dma_ops = {
3263 .alloc_coherent = ps3_alloc_coherent,
3264 .free_coherent = ps3_free_coherent,
3265 .map_sg = ps3_ioc0_map_sg,
3266 diff -urNp linux-2.6.37/arch/powerpc/platforms/pseries/suspend.c linux-2.6.37/arch/powerpc/platforms/pseries/suspend.c
3267 --- linux-2.6.37/arch/powerpc/platforms/pseries/suspend.c 2011-01-04 19:50:19.000000000 -0500
3268 +++ linux-2.6.37/arch/powerpc/platforms/pseries/suspend.c 2011-01-17 02:41:00.000000000 -0500
3269 @@ -153,7 +153,7 @@ static struct sysdev_class suspend_sysde
3273 -static struct platform_suspend_ops pseries_suspend_ops = {
3274 +static const struct platform_suspend_ops pseries_suspend_ops = {
3275 .valid = suspend_valid_only_mem,
3276 .begin = pseries_suspend_begin,
3277 .prepare_late = pseries_prepare_late,
3278 diff -urNp linux-2.6.37/arch/powerpc/sysdev/fsl_pmc.c linux-2.6.37/arch/powerpc/sysdev/fsl_pmc.c
3279 --- linux-2.6.37/arch/powerpc/sysdev/fsl_pmc.c 2011-01-04 19:50:19.000000000 -0500
3280 +++ linux-2.6.37/arch/powerpc/sysdev/fsl_pmc.c 2011-01-17 02:41:00.000000000 -0500
3281 @@ -53,7 +53,7 @@ static int pmc_suspend_valid(suspend_sta
3285 -static struct platform_suspend_ops pmc_suspend_ops = {
3286 +static const struct platform_suspend_ops pmc_suspend_ops = {
3287 .valid = pmc_suspend_valid,
3288 .enter = pmc_suspend_enter,
3290 diff -urNp linux-2.6.37/arch/s390/include/asm/elf.h linux-2.6.37/arch/s390/include/asm/elf.h
3291 --- linux-2.6.37/arch/s390/include/asm/elf.h 2011-01-04 19:50:19.000000000 -0500
3292 +++ linux-2.6.37/arch/s390/include/asm/elf.h 2011-01-17 02:41:00.000000000 -0500
3293 @@ -163,6 +163,13 @@ extern unsigned int vdso_enabled;
3294 that it will "exec", and that there is sufficient room for the brk. */
3295 #define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
3297 +#ifdef CONFIG_PAX_ASLR
3298 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
3300 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26 )
3301 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26 )
3304 /* This yields a mask that user programs can use to figure out what
3305 instruction set this CPU supports. */
3307 diff -urNp linux-2.6.37/arch/s390/include/asm/uaccess.h linux-2.6.37/arch/s390/include/asm/uaccess.h
3308 --- linux-2.6.37/arch/s390/include/asm/uaccess.h 2011-01-04 19:50:19.000000000 -0500
3309 +++ linux-2.6.37/arch/s390/include/asm/uaccess.h 2011-01-17 02:41:00.000000000 -0500
3310 @@ -234,6 +234,10 @@ static inline unsigned long __must_check
3311 copy_to_user(void __user *to, const void *from, unsigned long n)
3318 if (access_ok(VERIFY_WRITE, to, n))
3319 n = __copy_to_user(to, from, n);
3321 @@ -259,6 +263,9 @@ copy_to_user(void __user *to, const void
3322 static inline unsigned long __must_check
3323 __copy_from_user(void *to, const void __user *from, unsigned long n)
3328 if (__builtin_constant_p(n) && (n <= 256))
3329 return uaccess.copy_from_user_small(n, from, to);
3331 @@ -293,6 +300,10 @@ copy_from_user(void *to, const void __us
3332 unsigned int sz = __compiletime_object_size(to);
3339 if (unlikely(sz != -1 && sz < n)) {
3340 copy_from_user_overflow();
3342 diff -urNp linux-2.6.37/arch/s390/Kconfig linux-2.6.37/arch/s390/Kconfig
3343 --- linux-2.6.37/arch/s390/Kconfig 2011-01-04 19:50:19.000000000 -0500
3344 +++ linux-2.6.37/arch/s390/Kconfig 2011-01-17 02:41:00.000000000 -0500
3345 @@ -242,13 +242,12 @@ config AUDIT_ARCH
3347 config S390_EXEC_PROTECT
3348 bool "Data execute protection"
3351 This option allows to enable a buffer overflow protection for user
3352 - space programs and it also selects the addressing mode option above.
3353 - The kernel parameter noexec=on will enable this feature and also
3354 - switch the addressing modes, default is disabled. Enabling this (via
3355 - kernel parameter) on machines earlier than IBM System z9 this will
3356 - reduce system performance.
3358 + Enabling this (via kernel parameter) on machines earlier than IBM
3359 + System z9 will reduce system performance.
3361 comment "Code generation options"
3363 diff -urNp linux-2.6.37/arch/s390/kernel/module.c linux-2.6.37/arch/s390/kernel/module.c
3364 --- linux-2.6.37/arch/s390/kernel/module.c 2011-01-04 19:50:19.000000000 -0500
3365 +++ linux-2.6.37/arch/s390/kernel/module.c 2011-01-17 02:41:00.000000000 -0500
3366 @@ -168,11 +168,11 @@ module_frob_arch_sections(Elf_Ehdr *hdr,
3368 /* Increase core size by size of got & plt and set start
3369 offsets for got and plt. */
3370 - me->core_size = ALIGN(me->core_size, 4);
3371 - me->arch.got_offset = me->core_size;
3372 - me->core_size += me->arch.got_size;
3373 - me->arch.plt_offset = me->core_size;
3374 - me->core_size += me->arch.plt_size;
3375 + me->core_size_rw = ALIGN(me->core_size_rw, 4);
3376 + me->arch.got_offset = me->core_size_rw;
3377 + me->core_size_rw += me->arch.got_size;
3378 + me->arch.plt_offset = me->core_size_rx;
3379 + me->core_size_rx += me->arch.plt_size;
3383 @@ -258,7 +258,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base
3384 if (info->got_initialized == 0) {
3387 - gotent = me->module_core + me->arch.got_offset +
3388 + gotent = me->module_core_rw + me->arch.got_offset +
3391 info->got_initialized = 1;
3392 @@ -282,7 +282,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base
3393 else if (r_type == R_390_GOTENT ||
3394 r_type == R_390_GOTPLTENT)
3395 *(unsigned int *) loc =
3396 - (val + (Elf_Addr) me->module_core - loc) >> 1;
3397 + (val + (Elf_Addr) me->module_core_rw - loc) >> 1;
3398 else if (r_type == R_390_GOT64 ||
3399 r_type == R_390_GOTPLT64)
3400 *(unsigned long *) loc = val;
3401 @@ -296,7 +296,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base
3402 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
3403 if (info->plt_initialized == 0) {
3405 - ip = me->module_core + me->arch.plt_offset +
3406 + ip = me->module_core_rx + me->arch.plt_offset +
3408 #ifndef CONFIG_64BIT
3409 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
3410 @@ -321,7 +321,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base
3411 val - loc + 0xffffUL < 0x1ffffeUL) ||
3412 (r_type == R_390_PLT32DBL &&
3413 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
3414 - val = (Elf_Addr) me->module_core +
3415 + val = (Elf_Addr) me->module_core_rx +
3416 me->arch.plt_offset +
3418 val += rela->r_addend - loc;
3419 @@ -343,7 +343,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base
3420 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
3421 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
3422 val = val + rela->r_addend -
3423 - ((Elf_Addr) me->module_core + me->arch.got_offset);
3424 + ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
3425 if (r_type == R_390_GOTOFF16)
3426 *(unsigned short *) loc = val;
3427 else if (r_type == R_390_GOTOFF32)
3428 @@ -353,7 +353,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base
3430 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
3431 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
3432 - val = (Elf_Addr) me->module_core + me->arch.got_offset +
3433 + val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
3434 rela->r_addend - loc;
3435 if (r_type == R_390_GOTPC)
3436 *(unsigned int *) loc = val;
3437 diff -urNp linux-2.6.37/arch/s390/kernel/setup.c linux-2.6.37/arch/s390/kernel/setup.c
3438 --- linux-2.6.37/arch/s390/kernel/setup.c 2011-01-04 19:50:19.000000000 -0500
3439 +++ linux-2.6.37/arch/s390/kernel/setup.c 2011-01-17 02:41:00.000000000 -0500
3440 @@ -281,7 +281,7 @@ static int __init early_parse_mem(char *
3442 early_param("mem", early_parse_mem);
3444 -unsigned int user_mode = HOME_SPACE_MODE;
3445 +unsigned int user_mode = SECONDARY_SPACE_MODE;
3446 EXPORT_SYMBOL_GPL(user_mode);
3448 static int set_amode_and_uaccess(unsigned long user_amode,
3449 @@ -310,17 +310,6 @@ static int set_amode_and_uaccess(unsigne
3454 - * Switch kernel/user addressing modes?
3456 -static int __init early_parse_switch_amode(char *p)
3458 - if (user_mode != SECONDARY_SPACE_MODE)
3459 - user_mode = PRIMARY_SPACE_MODE;
3462 -early_param("switch_amode", early_parse_switch_amode);
3464 static int __init early_parse_user_mode(char *p)
3466 if (p && strcmp(p, "primary") == 0)
3467 @@ -337,20 +326,6 @@ static int __init early_parse_user_mode(
3469 early_param("user_mode", early_parse_user_mode);
3471 -#ifdef CONFIG_S390_EXEC_PROTECT
3473 - * Enable execute protection?
3475 -static int __init early_parse_noexec(char *p)
3477 - if (!strncmp(p, "off", 3))
3479 - user_mode = SECONDARY_SPACE_MODE;
3482 -early_param("noexec", early_parse_noexec);
3483 -#endif /* CONFIG_S390_EXEC_PROTECT */
3485 static void setup_addressing_mode(void)
3487 if (user_mode == SECONDARY_SPACE_MODE) {
3488 diff -urNp linux-2.6.37/arch/s390/mm/maccess.c linux-2.6.37/arch/s390/mm/maccess.c
3489 --- linux-2.6.37/arch/s390/mm/maccess.c 2011-01-04 19:50:19.000000000 -0500
3490 +++ linux-2.6.37/arch/s390/mm/maccess.c 2011-01-17 02:41:00.000000000 -0500
3491 @@ -45,7 +45,7 @@ static long probe_kernel_write_odd(void
3492 return rc ? rc : count;
3495 -long probe_kernel_write(void *dst, void *src, size_t size)
3496 +long probe_kernel_write(void *dst, const void *src, size_t size)
3500 diff -urNp linux-2.6.37/arch/s390/mm/mmap.c linux-2.6.37/arch/s390/mm/mmap.c
3501 --- linux-2.6.37/arch/s390/mm/mmap.c 2011-01-04 19:50:19.000000000 -0500
3502 +++ linux-2.6.37/arch/s390/mm/mmap.c 2011-01-17 02:41:00.000000000 -0500
3503 @@ -78,10 +78,22 @@ void arch_pick_mmap_layout(struct mm_str
3505 if (mmap_is_legacy()) {
3506 mm->mmap_base = TASK_UNMAPPED_BASE;
3508 +#ifdef CONFIG_PAX_RANDMMAP
3509 + if (mm->pax_flags & MF_PAX_RANDMMAP)
3510 + mm->mmap_base += mm->delta_mmap;
3513 mm->get_unmapped_area = arch_get_unmapped_area;
3514 mm->unmap_area = arch_unmap_area;
3516 mm->mmap_base = mmap_base();
3518 +#ifdef CONFIG_PAX_RANDMMAP
3519 + if (mm->pax_flags & MF_PAX_RANDMMAP)
3520 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
3523 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
3524 mm->unmap_area = arch_unmap_area_topdown;
3526 @@ -153,10 +165,22 @@ void arch_pick_mmap_layout(struct mm_str
3528 if (mmap_is_legacy()) {
3529 mm->mmap_base = TASK_UNMAPPED_BASE;
3531 +#ifdef CONFIG_PAX_RANDMMAP
3532 + if (mm->pax_flags & MF_PAX_RANDMMAP)
3533 + mm->mmap_base += mm->delta_mmap;
3536 mm->get_unmapped_area = s390_get_unmapped_area;
3537 mm->unmap_area = arch_unmap_area;
3539 mm->mmap_base = mmap_base();
3541 +#ifdef CONFIG_PAX_RANDMMAP
3542 + if (mm->pax_flags & MF_PAX_RANDMMAP)
3543 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
3546 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
3547 mm->unmap_area = arch_unmap_area_topdown;
3549 diff -urNp linux-2.6.37/arch/score/include/asm/system.h linux-2.6.37/arch/score/include/asm/system.h
3550 --- linux-2.6.37/arch/score/include/asm/system.h 2011-01-04 19:50:19.000000000 -0500
3551 +++ linux-2.6.37/arch/score/include/asm/system.h 2011-01-17 02:41:00.000000000 -0500
3552 @@ -17,7 +17,7 @@ do { \
3553 #define finish_arch_switch(prev) do {} while (0)
3555 typedef void (*vi_handler_t)(void);
3556 -extern unsigned long arch_align_stack(unsigned long sp);
3557 +#define arch_align_stack(x) (x)
3559 #define mb() barrier()
3560 #define rmb() barrier()
3561 diff -urNp linux-2.6.37/arch/score/kernel/process.c linux-2.6.37/arch/score/kernel/process.c
3562 --- linux-2.6.37/arch/score/kernel/process.c 2011-01-04 19:50:19.000000000 -0500
3563 +++ linux-2.6.37/arch/score/kernel/process.c 2011-01-17 02:41:00.000000000 -0500
3564 @@ -161,8 +161,3 @@ unsigned long get_wchan(struct task_stru
3566 return task_pt_regs(task)->cp0_epc;
3569 -unsigned long arch_align_stack(unsigned long sp)
3573 diff -urNp linux-2.6.37/arch/sh/boards/mach-hp6xx/pm.c linux-2.6.37/arch/sh/boards/mach-hp6xx/pm.c
3574 --- linux-2.6.37/arch/sh/boards/mach-hp6xx/pm.c 2011-01-04 19:50:19.000000000 -0500
3575 +++ linux-2.6.37/arch/sh/boards/mach-hp6xx/pm.c 2011-01-17 02:41:00.000000000 -0500
3576 @@ -143,7 +143,7 @@ static int hp6x0_pm_enter(suspend_state_
3580 -static struct platform_suspend_ops hp6x0_pm_ops = {
3581 +static const struct platform_suspend_ops hp6x0_pm_ops = {
3582 .enter = hp6x0_pm_enter,
3583 .valid = suspend_valid_only_mem,
3585 diff -urNp linux-2.6.37/arch/sh/include/asm/dma-mapping.h linux-2.6.37/arch/sh/include/asm/dma-mapping.h
3586 --- linux-2.6.37/arch/sh/include/asm/dma-mapping.h 2011-01-04 19:50:19.000000000 -0500
3587 +++ linux-2.6.37/arch/sh/include/asm/dma-mapping.h 2011-01-17 02:41:00.000000000 -0500
3589 #ifndef __ASM_SH_DMA_MAPPING_H
3590 #define __ASM_SH_DMA_MAPPING_H
3592 -extern struct dma_map_ops *dma_ops;
3593 +extern const struct dma_map_ops *dma_ops;
3594 extern void no_iommu_init(void);
3596 -static inline struct dma_map_ops *get_dma_ops(struct device *dev)
3597 +static inline const struct dma_map_ops *get_dma_ops(struct device *dev)
3601 @@ -14,7 +14,7 @@ static inline struct dma_map_ops *get_dm
3603 static inline int dma_supported(struct device *dev, u64 mask)
3605 - struct dma_map_ops *ops = get_dma_ops(dev);
3606 + const struct dma_map_ops *ops = get_dma_ops(dev);
3608 if (ops->dma_supported)
3609 return ops->dma_supported(dev, mask);
3610 @@ -24,7 +24,7 @@ static inline int dma_supported(struct d
3612 static inline int dma_set_mask(struct device *dev, u64 mask)
3614 - struct dma_map_ops *ops = get_dma_ops(dev);
3615 + const struct dma_map_ops *ops = get_dma_ops(dev);
3617 if (!dev->dma_mask || !dma_supported(dev, mask))
3619 @@ -44,7 +44,7 @@ void dma_cache_sync(struct device *dev,
3621 static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
3623 - struct dma_map_ops *ops = get_dma_ops(dev);
3624 + const struct dma_map_ops *ops = get_dma_ops(dev);
3626 if (ops->mapping_error)
3627 return ops->mapping_error(dev, dma_addr);
3628 @@ -55,7 +55,7 @@ static inline int dma_mapping_error(stru
3629 static inline void *dma_alloc_coherent(struct device *dev, size_t size,
3630 dma_addr_t *dma_handle, gfp_t gfp)
3632 - struct dma_map_ops *ops = get_dma_ops(dev);
3633 + const struct dma_map_ops *ops = get_dma_ops(dev);
3636 if (dma_alloc_from_coherent(dev, size, dma_handle, &memory))
3637 @@ -72,7 +72,7 @@ static inline void *dma_alloc_coherent(s
3638 static inline void dma_free_coherent(struct device *dev, size_t size,
3639 void *vaddr, dma_addr_t dma_handle)
3641 - struct dma_map_ops *ops = get_dma_ops(dev);
3642 + const struct dma_map_ops *ops = get_dma_ops(dev);
3644 if (dma_release_from_coherent(dev, get_order(size), vaddr))
3646 diff -urNp linux-2.6.37/arch/sh/kernel/cpu/shmobile/pm.c linux-2.6.37/arch/sh/kernel/cpu/shmobile/pm.c
3647 --- linux-2.6.37/arch/sh/kernel/cpu/shmobile/pm.c 2011-01-04 19:50:19.000000000 -0500
3648 +++ linux-2.6.37/arch/sh/kernel/cpu/shmobile/pm.c 2011-01-17 02:41:00.000000000 -0500
3649 @@ -141,7 +141,7 @@ static int sh_pm_enter(suspend_state_t s
3653 -static struct platform_suspend_ops sh_pm_ops = {
3654 +static const struct platform_suspend_ops sh_pm_ops = {
3655 .enter = sh_pm_enter,
3656 .valid = suspend_valid_only_mem,
3658 diff -urNp linux-2.6.37/arch/sh/kernel/dma-nommu.c linux-2.6.37/arch/sh/kernel/dma-nommu.c
3659 --- linux-2.6.37/arch/sh/kernel/dma-nommu.c 2011-01-04 19:50:19.000000000 -0500
3660 +++ linux-2.6.37/arch/sh/kernel/dma-nommu.c 2011-01-17 02:41:00.000000000 -0500
3661 @@ -62,7 +62,7 @@ static void nommu_sync_sg(struct device
3665 -struct dma_map_ops nommu_dma_ops = {
3666 +const struct dma_map_ops nommu_dma_ops = {
3667 .alloc_coherent = dma_generic_alloc_coherent,
3668 .free_coherent = dma_generic_free_coherent,
3669 .map_page = nommu_map_page,
3670 diff -urNp linux-2.6.37/arch/sh/kernel/kgdb.c linux-2.6.37/arch/sh/kernel/kgdb.c
3671 --- linux-2.6.37/arch/sh/kernel/kgdb.c 2011-01-04 19:50:19.000000000 -0500
3672 +++ linux-2.6.37/arch/sh/kernel/kgdb.c 2011-01-17 02:41:00.000000000 -0500
3673 @@ -319,7 +319,7 @@ void kgdb_arch_exit(void)
3674 unregister_die_notifier(&kgdb_notifier);
3677 -struct kgdb_arch arch_kgdb_ops = {
3678 +const struct kgdb_arch arch_kgdb_ops = {
3679 /* Breakpoint instruction: trapa #0x3c */
3680 #ifdef CONFIG_CPU_LITTLE_ENDIAN
3681 .gdb_bpt_instr = { 0x3c, 0xc3 },
3682 diff -urNp linux-2.6.37/arch/sh/mm/consistent.c linux-2.6.37/arch/sh/mm/consistent.c
3683 --- linux-2.6.37/arch/sh/mm/consistent.c 2011-01-04 19:50:19.000000000 -0500
3684 +++ linux-2.6.37/arch/sh/mm/consistent.c 2011-01-17 02:41:00.000000000 -0500
3687 #define PREALLOC_DMA_DEBUG_ENTRIES 4096
3689 -struct dma_map_ops *dma_ops;
3690 +const struct dma_map_ops *dma_ops;
3691 EXPORT_SYMBOL(dma_ops);
3693 static int __init dma_init(void)
3694 diff -urNp linux-2.6.37/arch/sh/mm/mmap.c linux-2.6.37/arch/sh/mm/mmap.c
3695 --- linux-2.6.37/arch/sh/mm/mmap.c 2011-01-04 19:50:19.000000000 -0500
3696 +++ linux-2.6.37/arch/sh/mm/mmap.c 2011-01-17 02:41:00.000000000 -0500
3697 @@ -74,8 +74,7 @@ unsigned long arch_get_unmapped_area(str
3698 addr = PAGE_ALIGN(addr);
3700 vma = find_vma(mm, addr);
3701 - if (TASK_SIZE - len >= addr &&
3702 - (!vma || addr + len <= vma->vm_start))
3703 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
3707 @@ -106,7 +105,7 @@ full_search:
3711 - if (likely(!vma || addr + len <= vma->vm_start)) {
3712 + if (likely(check_heap_stack_gap(vma, addr, len))) {
3714 * Remember the place where we stopped the search:
3716 @@ -157,8 +156,7 @@ arch_get_unmapped_area_topdown(struct fi
3717 addr = PAGE_ALIGN(addr);
3719 vma = find_vma(mm, addr);
3720 - if (TASK_SIZE - len >= addr &&
3721 - (!vma || addr + len <= vma->vm_start))
3722 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
3726 @@ -179,7 +177,7 @@ arch_get_unmapped_area_topdown(struct fi
3727 /* make sure it can fit in the remaining address space */
3728 if (likely(addr > len)) {
3729 vma = find_vma(mm, addr-len);
3730 - if (!vma || addr <= vma->vm_start) {
3731 + if (check_heap_stack_gap(vma, addr - len, len)) {
3732 /* remember the address as a hint for next time */
3733 return (mm->free_area_cache = addr-len);
3735 @@ -199,7 +197,7 @@ arch_get_unmapped_area_topdown(struct fi
3736 * return with success:
3738 vma = find_vma(mm, addr);
3739 - if (likely(!vma || addr+len <= vma->vm_start)) {
3740 + if (likely(check_heap_stack_gap(vma, addr, len))) {
3741 /* remember the address as a hint for next time */
3742 return (mm->free_area_cache = addr);
3744 diff -urNp linux-2.6.37/arch/sparc/include/asm/atomic_64.h linux-2.6.37/arch/sparc/include/asm/atomic_64.h
3745 --- linux-2.6.37/arch/sparc/include/asm/atomic_64.h 2011-01-04 19:50:19.000000000 -0500
3746 +++ linux-2.6.37/arch/sparc/include/asm/atomic_64.h 2011-01-17 02:41:00.000000000 -0500
3748 #define ATOMIC64_INIT(i) { (i) }
3750 #define atomic_read(v) (*(volatile int *)&(v)->counter)
3751 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
3753 + return v->counter;
3755 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
3756 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
3758 + return v->counter;
3761 #define atomic_set(v, i) (((v)->counter) = i)
3762 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
3766 #define atomic64_set(v, i) (((v)->counter) = i)
3767 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
3772 extern void atomic_add(int, atomic_t *);
3773 +extern void atomic_add_unchecked(int, atomic_unchecked_t *);
3774 extern void atomic64_add(long, atomic64_t *);
3775 +extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
3776 extern void atomic_sub(int, atomic_t *);
3777 +extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
3778 extern void atomic64_sub(long, atomic64_t *);
3779 +extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
3781 extern int atomic_add_ret(int, atomic_t *);
3782 +extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
3783 extern long atomic64_add_ret(long, atomic64_t *);
3784 +extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
3785 extern int atomic_sub_ret(int, atomic_t *);
3786 extern long atomic64_sub_ret(long, atomic64_t *);
3788 @@ -33,12 +55,24 @@ extern long atomic64_sub_ret(long, atomi
3789 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
3791 #define atomic_inc_return(v) atomic_add_ret(1, v)
3792 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
3794 + return atomic_add_ret_unchecked(1, v);
3796 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
3797 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
3799 + return atomic64_add_ret_unchecked(1, v);
3802 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
3803 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
3805 #define atomic_add_return(i, v) atomic_add_ret(i, v)
3806 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
3808 + return atomic_add_ret_unchecked(i, v);
3810 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
3813 @@ -59,10 +93,26 @@ extern long atomic64_sub_ret(long, atomi
3814 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
3816 #define atomic_inc(v) atomic_add(1, v)
3817 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
3819 + atomic_add_unchecked(1, v);
3821 #define atomic64_inc(v) atomic64_add(1, v)
3822 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
3824 + atomic64_add_unchecked(1, v);
3827 #define atomic_dec(v) atomic_sub(1, v)
3828 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
3830 + atomic_sub_unchecked(1, v);
3832 #define atomic64_dec(v) atomic64_sub(1, v)
3833 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
3835 + atomic64_sub_unchecked(1, v);
3838 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
3839 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
3840 @@ -72,17 +122,28 @@ extern long atomic64_sub_ret(long, atomi
3842 static inline int atomic_add_unless(atomic_t *v, int a, int u)
3848 - if (unlikely(c == (u)))
3849 + if (unlikely(c == u))
3851 - old = atomic_cmpxchg((v), c, c + (a));
3853 + asm volatile("addcc %2, %0, %0\n"
3855 +#ifdef CONFIG_PAX_REFCOUNT
3860 + : "0" (c), "ir" (a)
3863 + old = atomic_cmpxchg(v, c, new);
3864 if (likely(old == c))
3872 #define atomic_inc_not_zero(v) atomic_add_unless((v), 1, 0)
3873 @@ -93,17 +154,28 @@ static inline int atomic_add_unless(atom
3875 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
3879 c = atomic64_read(v);
3881 - if (unlikely(c == (u)))
3882 + if (unlikely(c == u))
3884 - old = atomic64_cmpxchg((v), c, c + (a));
3886 + asm volatile("addcc %2, %0, %0\n"
3888 +#ifdef CONFIG_PAX_REFCOUNT
3893 + : "0" (c), "ir" (a)
3896 + old = atomic64_cmpxchg(v, c, new);
3897 if (likely(old == c))
3905 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
3906 diff -urNp linux-2.6.37/arch/sparc/include/asm/dma-mapping.h linux-2.6.37/arch/sparc/include/asm/dma-mapping.h
3907 --- linux-2.6.37/arch/sparc/include/asm/dma-mapping.h 2011-01-04 19:50:19.000000000 -0500
3908 +++ linux-2.6.37/arch/sparc/include/asm/dma-mapping.h 2011-01-17 02:41:00.000000000 -0500
3909 @@ -12,10 +12,10 @@ extern int dma_supported(struct device *
3910 #define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f)
3911 #define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h)
3913 -extern struct dma_map_ops *dma_ops, pci32_dma_ops;
3914 +extern const struct dma_map_ops *dma_ops, pci32_dma_ops;
3915 extern struct bus_type pci_bus_type;
3917 -static inline struct dma_map_ops *get_dma_ops(struct device *dev)
3918 +static inline const struct dma_map_ops *get_dma_ops(struct device *dev)
3920 #if defined(CONFIG_SPARC32) && defined(CONFIG_PCI)
3921 if (dev->bus == &pci_bus_type)
3922 @@ -29,7 +29,7 @@ static inline struct dma_map_ops *get_dm
3923 static inline void *dma_alloc_coherent(struct device *dev, size_t size,
3924 dma_addr_t *dma_handle, gfp_t flag)
3926 - struct dma_map_ops *ops = get_dma_ops(dev);
3927 + const struct dma_map_ops *ops = get_dma_ops(dev);
3930 cpu_addr = ops->alloc_coherent(dev, size, dma_handle, flag);
3931 @@ -40,7 +40,7 @@ static inline void *dma_alloc_coherent(s
3932 static inline void dma_free_coherent(struct device *dev, size_t size,
3933 void *cpu_addr, dma_addr_t dma_handle)
3935 - struct dma_map_ops *ops = get_dma_ops(dev);
3936 + const struct dma_map_ops *ops = get_dma_ops(dev);
3938 debug_dma_free_coherent(dev, size, cpu_addr, dma_handle);
3939 ops->free_coherent(dev, size, cpu_addr, dma_handle);
3940 diff -urNp linux-2.6.37/arch/sparc/include/asm/elf_32.h linux-2.6.37/arch/sparc/include/asm/elf_32.h
3941 --- linux-2.6.37/arch/sparc/include/asm/elf_32.h 2011-01-04 19:50:19.000000000 -0500
3942 +++ linux-2.6.37/arch/sparc/include/asm/elf_32.h 2011-01-17 02:41:00.000000000 -0500
3943 @@ -114,6 +114,13 @@ typedef struct {
3945 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
3947 +#ifdef CONFIG_PAX_ASLR
3948 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
3950 +#define PAX_DELTA_MMAP_LEN 16
3951 +#define PAX_DELTA_STACK_LEN 16
3954 /* This yields a mask that user programs can use to figure out what
3955 instruction set this cpu supports. This can NOT be done in userspace
3957 diff -urNp linux-2.6.37/arch/sparc/include/asm/elf_64.h linux-2.6.37/arch/sparc/include/asm/elf_64.h
3958 --- linux-2.6.37/arch/sparc/include/asm/elf_64.h 2011-01-04 19:50:19.000000000 -0500
3959 +++ linux-2.6.37/arch/sparc/include/asm/elf_64.h 2011-01-17 02:41:00.000000000 -0500
3960 @@ -162,6 +162,12 @@ typedef struct {
3961 #define ELF_ET_DYN_BASE 0x0000010000000000UL
3962 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
3964 +#ifdef CONFIG_PAX_ASLR
3965 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
3967 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
3968 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
3971 /* This yields a mask that user programs can use to figure out what
3972 instruction set this cpu supports. */
3973 diff -urNp linux-2.6.37/arch/sparc/include/asm/pgtable_32.h linux-2.6.37/arch/sparc/include/asm/pgtable_32.h
3974 --- linux-2.6.37/arch/sparc/include/asm/pgtable_32.h 2011-01-04 19:50:19.000000000 -0500
3975 +++ linux-2.6.37/arch/sparc/include/asm/pgtable_32.h 2011-01-17 02:41:00.000000000 -0500
3976 @@ -43,6 +43,13 @@ BTFIXUPDEF_SIMM13(user_ptrs_per_pgd)
3977 BTFIXUPDEF_INT(page_none)
3978 BTFIXUPDEF_INT(page_copy)
3979 BTFIXUPDEF_INT(page_readonly)
3981 +#ifdef CONFIG_PAX_PAGEEXEC
3982 +BTFIXUPDEF_INT(page_shared_noexec)
3983 +BTFIXUPDEF_INT(page_copy_noexec)
3984 +BTFIXUPDEF_INT(page_readonly_noexec)
3987 BTFIXUPDEF_INT(page_kernel)
3989 #define PMD_SHIFT SUN4C_PMD_SHIFT
3990 @@ -64,6 +71,16 @@ extern pgprot_t PAGE_SHARED;
3991 #define PAGE_COPY __pgprot(BTFIXUP_INT(page_copy))
3992 #define PAGE_READONLY __pgprot(BTFIXUP_INT(page_readonly))
3994 +#ifdef CONFIG_PAX_PAGEEXEC
3995 +extern pgprot_t PAGE_SHARED_NOEXEC;
3996 +# define PAGE_COPY_NOEXEC __pgprot(BTFIXUP_INT(page_copy_noexec))
3997 +# define PAGE_READONLY_NOEXEC __pgprot(BTFIXUP_INT(page_readonly_noexec))
3999 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
4000 +# define PAGE_COPY_NOEXEC PAGE_COPY
4001 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
4004 extern unsigned long page_kernel;
4007 diff -urNp linux-2.6.37/arch/sparc/include/asm/pgtsrmmu.h linux-2.6.37/arch/sparc/include/asm/pgtsrmmu.h
4008 --- linux-2.6.37/arch/sparc/include/asm/pgtsrmmu.h 2011-01-04 19:50:19.000000000 -0500
4009 +++ linux-2.6.37/arch/sparc/include/asm/pgtsrmmu.h 2011-01-17 02:41:00.000000000 -0500
4010 @@ -115,6 +115,13 @@
4011 SRMMU_EXEC | SRMMU_REF)
4012 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
4013 SRMMU_EXEC | SRMMU_REF)
4015 +#ifdef CONFIG_PAX_PAGEEXEC
4016 +#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
4017 +#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
4018 +#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
4021 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
4022 SRMMU_DIRTY | SRMMU_REF)
4024 diff -urNp linux-2.6.37/arch/sparc/include/asm/spinlock_64.h linux-2.6.37/arch/sparc/include/asm/spinlock_64.h
4025 --- linux-2.6.37/arch/sparc/include/asm/spinlock_64.h 2011-01-04 19:50:19.000000000 -0500
4026 +++ linux-2.6.37/arch/sparc/include/asm/spinlock_64.h 2011-01-17 02:41:00.000000000 -0500
4027 @@ -99,7 +99,12 @@ static void inline arch_read_lock(arch_r
4028 __asm__ __volatile__ (
4029 "1: ldsw [%2], %0\n"
4031 -"4: add %0, 1, %1\n"
4032 +"4: addcc %0, 1, %1\n"
4034 +#ifdef CONFIG_PAX_REFCOUNT
4038 " cas [%2], %0, %1\n"
4040 " bne,pn %%icc, 1b\n"
4041 @@ -112,7 +117,7 @@ static void inline arch_read_lock(arch_r
4043 : "=&r" (tmp1), "=&r" (tmp2)
4046 + : "memory", "cc");
4049 static int inline arch_read_trylock(arch_rwlock_t *lock)
4050 @@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch
4051 "1: ldsw [%2], %0\n"
4052 " brlz,a,pn %0, 2f\n"
4055 +" addcc %0, 1, %1\n"
4057 +#ifdef CONFIG_PAX_REFCOUNT
4061 " cas [%2], %0, %1\n"
4063 " bne,pn %%icc, 1b\n"
4064 @@ -142,7 +152,12 @@ static void inline arch_read_unlock(arch
4066 __asm__ __volatile__(
4067 "1: lduw [%2], %0\n"
4069 +" subcc %0, 1, %1\n"
4071 +#ifdef CONFIG_PAX_REFCOUNT
4075 " cas [%2], %0, %1\n"
4077 " bne,pn %%xcc, 1b\n"
4078 diff -urNp linux-2.6.37/arch/sparc/include/asm/uaccess_32.h linux-2.6.37/arch/sparc/include/asm/uaccess_32.h
4079 --- linux-2.6.37/arch/sparc/include/asm/uaccess_32.h 2011-01-04 19:50:19.000000000 -0500
4080 +++ linux-2.6.37/arch/sparc/include/asm/uaccess_32.h 2011-01-17 02:41:00.000000000 -0500
4081 @@ -249,27 +249,46 @@ extern unsigned long __copy_user(void __
4083 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
4085 - if (n && __access_ok((unsigned long) to, n))
4089 + if (n && __access_ok((unsigned long) to, n)) {
4090 + if (!__builtin_constant_p(n))
4091 + check_object_size(from, n, true);
4092 return __copy_user(to, (__force void __user *) from, n);
4098 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
4103 + if (!__builtin_constant_p(n))
4104 + check_object_size(from, n, true);
4106 return __copy_user(to, (__force void __user *) from, n);
4109 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
4111 - if (n && __access_ok((unsigned long) from, n))
4115 + if (n && __access_ok((unsigned long) from, n)) {
4116 + if (!__builtin_constant_p(n))
4117 + check_object_size(to, n, false);
4118 return __copy_user((__force void __user *) to, from, n);
4124 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
4129 return __copy_user((__force void __user *) to, from, n);
4132 diff -urNp linux-2.6.37/arch/sparc/include/asm/uaccess_64.h linux-2.6.37/arch/sparc/include/asm/uaccess_64.h
4133 --- linux-2.6.37/arch/sparc/include/asm/uaccess_64.h 2011-01-04 19:50:19.000000000 -0500
4134 +++ linux-2.6.37/arch/sparc/include/asm/uaccess_64.h 2011-01-17 02:41:00.000000000 -0500
4136 #include <linux/compiler.h>
4137 #include <linux/string.h>
4138 #include <linux/thread_info.h>
4139 +#include <linux/kernel.h>
4140 #include <asm/asi.h>
4141 #include <asm/system.h>
4142 #include <asm/spitfire.h>
4143 @@ -213,8 +214,15 @@ extern unsigned long copy_from_user_fixu
4144 static inline unsigned long __must_check
4145 copy_from_user(void *to, const void __user *from, unsigned long size)
4147 - unsigned long ret = ___copy_from_user(to, from, size);
4148 + unsigned long ret;
4150 + if ((long)size < 0 || size > INT_MAX)
4153 + if (!__builtin_constant_p(size))
4154 + check_object_size(to, size, false);
4156 + ret = ___copy_from_user(to, from, size);
4158 ret = copy_from_user_fixup(to, from, size);
4160 @@ -230,8 +238,15 @@ extern unsigned long copy_to_user_fixup(
4161 static inline unsigned long __must_check
4162 copy_to_user(void __user *to, const void *from, unsigned long size)
4164 - unsigned long ret = ___copy_to_user(to, from, size);
4165 + unsigned long ret;
4167 + if ((long)size < 0 || size > INT_MAX)
4170 + if (!__builtin_constant_p(size))
4171 + check_object_size(from, size, true);
4173 + ret = ___copy_to_user(to, from, size);
4175 ret = copy_to_user_fixup(to, from, size);
4177 diff -urNp linux-2.6.37/arch/sparc/include/asm/uaccess.h linux-2.6.37/arch/sparc/include/asm/uaccess.h
4178 --- linux-2.6.37/arch/sparc/include/asm/uaccess.h 2011-01-04 19:50:19.000000000 -0500
4179 +++ linux-2.6.37/arch/sparc/include/asm/uaccess.h 2011-01-17 02:41:00.000000000 -0500
4181 #ifndef ___ASM_SPARC_UACCESS_H
4182 #define ___ASM_SPARC_UACCESS_H
4185 +#ifndef __ASSEMBLY__
4186 +#include <linux/types.h>
4187 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
4191 #if defined(__sparc__) && defined(__arch64__)
4192 #include <asm/uaccess_64.h>
4194 diff -urNp linux-2.6.37/arch/sparc/kernel/iommu.c linux-2.6.37/arch/sparc/kernel/iommu.c
4195 --- linux-2.6.37/arch/sparc/kernel/iommu.c 2011-01-04 19:50:19.000000000 -0500
4196 +++ linux-2.6.37/arch/sparc/kernel/iommu.c 2011-01-17 02:41:00.000000000 -0500
4197 @@ -828,7 +828,7 @@ static void dma_4u_sync_sg_for_cpu(struc
4198 spin_unlock_irqrestore(&iommu->lock, flags);
4201 -static struct dma_map_ops sun4u_dma_ops = {
4202 +static const struct dma_map_ops sun4u_dma_ops = {
4203 .alloc_coherent = dma_4u_alloc_coherent,
4204 .free_coherent = dma_4u_free_coherent,
4205 .map_page = dma_4u_map_page,
4206 @@ -839,7 +839,7 @@ static struct dma_map_ops sun4u_dma_ops
4207 .sync_sg_for_cpu = dma_4u_sync_sg_for_cpu,
4210 -struct dma_map_ops *dma_ops = &sun4u_dma_ops;
4211 +const struct dma_map_ops *dma_ops = &sun4u_dma_ops;
4212 EXPORT_SYMBOL(dma_ops);
4214 extern int pci64_dma_supported(struct pci_dev *pdev, u64 device_mask);
4215 diff -urNp linux-2.6.37/arch/sparc/kernel/ioport.c linux-2.6.37/arch/sparc/kernel/ioport.c
4216 --- linux-2.6.37/arch/sparc/kernel/ioport.c 2011-01-04 19:50:19.000000000 -0500
4217 +++ linux-2.6.37/arch/sparc/kernel/ioport.c 2011-01-17 02:41:00.000000000 -0500
4218 @@ -397,7 +397,7 @@ static void sbus_sync_sg_for_device(stru
4222 -struct dma_map_ops sbus_dma_ops = {
4223 +const struct dma_map_ops sbus_dma_ops = {
4224 .alloc_coherent = sbus_alloc_coherent,
4225 .free_coherent = sbus_free_coherent,
4226 .map_page = sbus_map_page,
4227 @@ -408,7 +408,7 @@ struct dma_map_ops sbus_dma_ops = {
4228 .sync_sg_for_device = sbus_sync_sg_for_device,
4231 -struct dma_map_ops *dma_ops = &sbus_dma_ops;
4232 +const struct dma_map_ops *dma_ops = &sbus_dma_ops;
4233 EXPORT_SYMBOL(dma_ops);
4235 static int __init sparc_register_ioport(void)
4236 @@ -645,7 +645,7 @@ static void pci32_sync_sg_for_device(str
4240 -struct dma_map_ops pci32_dma_ops = {
4241 +const struct dma_map_ops pci32_dma_ops = {
4242 .alloc_coherent = pci32_alloc_coherent,
4243 .free_coherent = pci32_free_coherent,
4244 .map_page = pci32_map_page,
4245 diff -urNp linux-2.6.37/arch/sparc/kernel/kgdb_32.c linux-2.6.37/arch/sparc/kernel/kgdb_32.c
4246 --- linux-2.6.37/arch/sparc/kernel/kgdb_32.c 2011-01-04 19:50:19.000000000 -0500
4247 +++ linux-2.6.37/arch/sparc/kernel/kgdb_32.c 2011-01-17 02:41:00.000000000 -0500
4248 @@ -164,7 +164,7 @@ void kgdb_arch_set_pc(struct pt_regs *re
4249 regs->npc = regs->pc + 4;
4252 -struct kgdb_arch arch_kgdb_ops = {
4253 +const struct kgdb_arch arch_kgdb_ops = {
4254 /* Breakpoint instruction: ta 0x7d */
4255 .gdb_bpt_instr = { 0x91, 0xd0, 0x20, 0x7d },
4257 diff -urNp linux-2.6.37/arch/sparc/kernel/kgdb_64.c linux-2.6.37/arch/sparc/kernel/kgdb_64.c
4258 --- linux-2.6.37/arch/sparc/kernel/kgdb_64.c 2011-01-04 19:50:19.000000000 -0500
4259 +++ linux-2.6.37/arch/sparc/kernel/kgdb_64.c 2011-01-17 02:41:00.000000000 -0500
4260 @@ -187,7 +187,7 @@ void kgdb_arch_set_pc(struct pt_regs *re
4261 regs->tnpc = regs->tpc + 4;
4264 -struct kgdb_arch arch_kgdb_ops = {
4265 +const struct kgdb_arch arch_kgdb_ops = {
4266 /* Breakpoint instruction: ta 0x72 */
4267 .gdb_bpt_instr = { 0x91, 0xd0, 0x20, 0x72 },
4269 diff -urNp linux-2.6.37/arch/sparc/kernel/Makefile linux-2.6.37/arch/sparc/kernel/Makefile
4270 --- linux-2.6.37/arch/sparc/kernel/Makefile 2011-01-04 19:50:19.000000000 -0500
4271 +++ linux-2.6.37/arch/sparc/kernel/Makefile 2011-01-17 02:41:00.000000000 -0500
4276 -ccflags-y := -Werror
4277 +#ccflags-y := -Werror
4279 extra-y := head_$(BITS).o
4280 extra-y += init_task.o
4281 diff -urNp linux-2.6.37/arch/sparc/kernel/pci_sun4v.c linux-2.6.37/arch/sparc/kernel/pci_sun4v.c
4282 --- linux-2.6.37/arch/sparc/kernel/pci_sun4v.c 2011-01-04 19:50:19.000000000 -0500
4283 +++ linux-2.6.37/arch/sparc/kernel/pci_sun4v.c 2011-01-17 02:41:00.000000000 -0500
4284 @@ -525,7 +525,7 @@ static void dma_4v_unmap_sg(struct devic
4285 spin_unlock_irqrestore(&iommu->lock, flags);
4288 -static struct dma_map_ops sun4v_dma_ops = {
4289 +static const struct dma_map_ops sun4v_dma_ops = {
4290 .alloc_coherent = dma_4v_alloc_coherent,
4291 .free_coherent = dma_4v_free_coherent,
4292 .map_page = dma_4v_map_page,
4293 diff -urNp linux-2.6.37/arch/sparc/kernel/process_32.c linux-2.6.37/arch/sparc/kernel/process_32.c
4294 --- linux-2.6.37/arch/sparc/kernel/process_32.c 2011-01-04 19:50:19.000000000 -0500
4295 +++ linux-2.6.37/arch/sparc/kernel/process_32.c 2011-01-17 02:41:00.000000000 -0500
4296 @@ -196,7 +196,7 @@ void __show_backtrace(unsigned long fp)
4297 rw->ins[4], rw->ins[5],
4300 - printk("%pS\n", (void *) rw->ins[7]);
4301 + printk("%pA\n", (void *) rw->ins[7]);
4302 rw = (struct reg_window32 *) rw->ins[6];
4304 spin_unlock_irqrestore(&sparc_backtrace_lock, flags);
4305 @@ -263,14 +263,14 @@ void show_regs(struct pt_regs *r)
4307 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
4308 r->psr, r->pc, r->npc, r->y, print_tainted());
4309 - printk("PC: <%pS>\n", (void *) r->pc);
4310 + printk("PC: <%pA>\n", (void *) r->pc);
4311 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
4312 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
4313 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
4314 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
4315 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
4316 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
4317 - printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
4318 + printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
4320 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
4321 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
4322 @@ -305,7 +305,7 @@ void show_stack(struct task_struct *tsk,
4323 rw = (struct reg_window32 *) fp;
4325 printk("[%08lx : ", pc);
4326 - printk("%pS ] ", (void *) pc);
4327 + printk("%pA ] ", (void *) pc);
4329 } while (++count < 16);
4331 diff -urNp linux-2.6.37/arch/sparc/kernel/process_64.c linux-2.6.37/arch/sparc/kernel/process_64.c
4332 --- linux-2.6.37/arch/sparc/kernel/process_64.c 2011-01-04 19:50:19.000000000 -0500
4333 +++ linux-2.6.37/arch/sparc/kernel/process_64.c 2011-01-17 02:41:00.000000000 -0500
4334 @@ -180,14 +180,14 @@ static void show_regwindow(struct pt_reg
4335 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
4336 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
4337 if (regs->tstate & TSTATE_PRIV)
4338 - printk("I7: <%pS>\n", (void *) rwk->ins[7]);
4339 + printk("I7: <%pA>\n", (void *) rwk->ins[7]);
4342 void show_regs(struct pt_regs *regs)
4344 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
4345 regs->tpc, regs->tnpc, regs->y, print_tainted());
4346 - printk("TPC: <%pS>\n", (void *) regs->tpc);
4347 + printk("TPC: <%pA>\n", (void *) regs->tpc);
4348 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
4349 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
4351 @@ -200,7 +200,7 @@ void show_regs(struct pt_regs *regs)
4352 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
4353 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
4355 - printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
4356 + printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
4357 show_regwindow(regs);
4358 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
4360 @@ -285,7 +285,7 @@ void arch_trigger_all_cpu_backtrace(void
4361 ((tp && tp->task) ? tp->task->pid : -1));
4363 if (gp->tstate & TSTATE_PRIV) {
4364 - printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
4365 + printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
4369 diff -urNp linux-2.6.37/arch/sparc/kernel/sys_sparc_32.c linux-2.6.37/arch/sparc/kernel/sys_sparc_32.c
4370 --- linux-2.6.37/arch/sparc/kernel/sys_sparc_32.c 2011-01-04 19:50:19.000000000 -0500
4371 +++ linux-2.6.37/arch/sparc/kernel/sys_sparc_32.c 2011-01-17 02:41:00.000000000 -0500
4372 @@ -56,7 +56,7 @@ unsigned long arch_get_unmapped_area(str
4373 if (ARCH_SUN4C && len > 0x20000000)
4376 - addr = TASK_UNMAPPED_BASE;
4377 + addr = current->mm->mmap_base;
4379 if (flags & MAP_SHARED)
4380 addr = COLOUR_ALIGN(addr);
4381 @@ -71,7 +71,7 @@ unsigned long arch_get_unmapped_area(str
4383 if (TASK_SIZE - PAGE_SIZE - len < addr)
4385 - if (!vmm || addr + len <= vmm->vm_start)
4386 + if (check_heap_stack_gap(vmm, addr, len))
4389 if (flags & MAP_SHARED)
4390 diff -urNp linux-2.6.37/arch/sparc/kernel/sys_sparc_64.c linux-2.6.37/arch/sparc/kernel/sys_sparc_64.c
4391 --- linux-2.6.37/arch/sparc/kernel/sys_sparc_64.c 2011-01-04 19:50:19.000000000 -0500
4392 +++ linux-2.6.37/arch/sparc/kernel/sys_sparc_64.c 2011-01-17 02:41:00.000000000 -0500
4393 @@ -124,7 +124,7 @@ unsigned long arch_get_unmapped_area(str
4394 /* We do not accept a shared mapping if it would violate
4395 * cache aliasing constraints.
4397 - if ((flags & MAP_SHARED) &&
4398 + if ((filp || (flags & MAP_SHARED)) &&
4399 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
4402 @@ -139,6 +139,10 @@ unsigned long arch_get_unmapped_area(str
4403 if (filp || (flags & MAP_SHARED))
4406 +#ifdef CONFIG_PAX_RANDMMAP
4407 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4412 addr = COLOUR_ALIGN(addr, pgoff);
4413 @@ -146,15 +150,14 @@ unsigned long arch_get_unmapped_area(str
4414 addr = PAGE_ALIGN(addr);
4416 vma = find_vma(mm, addr);
4417 - if (task_size - len >= addr &&
4418 - (!vma || addr + len <= vma->vm_start))
4419 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
4423 if (len > mm->cached_hole_size) {
4424 - start_addr = addr = mm->free_area_cache;
4425 + start_addr = addr = mm->free_area_cache;
4427 - start_addr = addr = TASK_UNMAPPED_BASE;
4428 + start_addr = addr = mm->mmap_base;
4429 mm->cached_hole_size = 0;
4432 @@ -174,14 +177,14 @@ full_search:
4433 vma = find_vma(mm, VA_EXCLUDE_END);
4435 if (unlikely(task_size < addr)) {
4436 - if (start_addr != TASK_UNMAPPED_BASE) {
4437 - start_addr = addr = TASK_UNMAPPED_BASE;
4438 + if (start_addr != mm->mmap_base) {
4439 + start_addr = addr = mm->mmap_base;
4440 mm->cached_hole_size = 0;
4445 - if (likely(!vma || addr + len <= vma->vm_start)) {
4446 + if (likely(check_heap_stack_gap(vma, addr, len))) {
4448 * Remember the place where we stopped the search:
4450 @@ -215,7 +218,7 @@ arch_get_unmapped_area_topdown(struct fi
4451 /* We do not accept a shared mapping if it would violate
4452 * cache aliasing constraints.
4454 - if ((flags & MAP_SHARED) &&
4455 + if ((filp || (flags & MAP_SHARED)) &&
4456 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
4459 @@ -236,8 +239,7 @@ arch_get_unmapped_area_topdown(struct fi
4460 addr = PAGE_ALIGN(addr);
4462 vma = find_vma(mm, addr);
4463 - if (task_size - len >= addr &&
4464 - (!vma || addr + len <= vma->vm_start))
4465 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
4469 @@ -258,7 +260,7 @@ arch_get_unmapped_area_topdown(struct fi
4470 /* make sure it can fit in the remaining address space */
4471 if (likely(addr > len)) {
4472 vma = find_vma(mm, addr-len);
4473 - if (!vma || addr <= vma->vm_start) {
4474 + if (check_heap_stack_gap(vma, addr - len, len)) {
4475 /* remember the address as a hint for next time */
4476 return (mm->free_area_cache = addr-len);
4478 @@ -278,7 +280,7 @@ arch_get_unmapped_area_topdown(struct fi
4479 * return with success:
4481 vma = find_vma(mm, addr);
4482 - if (likely(!vma || addr+len <= vma->vm_start)) {
4483 + if (likely(check_heap_stack_gap(vma, addr, len))) {
4484 /* remember the address as a hint for next time */
4485 return (mm->free_area_cache = addr);
4487 @@ -385,6 +387,12 @@ void arch_pick_mmap_layout(struct mm_str
4488 gap == RLIM_INFINITY ||
4489 sysctl_legacy_va_layout) {
4490 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
4492 +#ifdef CONFIG_PAX_RANDMMAP
4493 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4494 + mm->mmap_base += mm->delta_mmap;
4497 mm->get_unmapped_area = arch_get_unmapped_area;
4498 mm->unmap_area = arch_unmap_area;
4500 @@ -397,6 +405,12 @@ void arch_pick_mmap_layout(struct mm_str
4501 gap = (task_size / 6 * 5);
4503 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
4505 +#ifdef CONFIG_PAX_RANDMMAP
4506 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4507 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4510 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4511 mm->unmap_area = arch_unmap_area_topdown;
4513 diff -urNp linux-2.6.37/arch/sparc/kernel/traps_32.c linux-2.6.37/arch/sparc/kernel/traps_32.c
4514 --- linux-2.6.37/arch/sparc/kernel/traps_32.c 2011-01-04 19:50:19.000000000 -0500
4515 +++ linux-2.6.37/arch/sparc/kernel/traps_32.c 2011-01-17 02:41:00.000000000 -0500
4516 @@ -76,7 +76,7 @@ void die_if_kernel(char *str, struct pt_
4518 (((unsigned long) rw) >= PAGE_OFFSET) &&
4519 !(((unsigned long) rw) & 0x7)) {
4520 - printk("Caller[%08lx]: %pS\n", rw->ins[7],
4521 + printk("Caller[%08lx]: %pA\n", rw->ins[7],
4522 (void *) rw->ins[7]);
4523 rw = (struct reg_window32 *)rw->ins[6];
4525 diff -urNp linux-2.6.37/arch/sparc/kernel/traps_64.c linux-2.6.37/arch/sparc/kernel/traps_64.c
4526 --- linux-2.6.37/arch/sparc/kernel/traps_64.c 2011-01-04 19:50:19.000000000 -0500
4527 +++ linux-2.6.37/arch/sparc/kernel/traps_64.c 2011-01-17 02:41:00.000000000 -0500
4528 @@ -75,7 +75,7 @@ static void dump_tl1_traplog(struct tl1_
4530 p->trapstack[i].tstate, p->trapstack[i].tpc,
4531 p->trapstack[i].tnpc, p->trapstack[i].tt);
4532 - printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
4533 + printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
4537 @@ -95,6 +95,12 @@ void bad_trap(struct pt_regs *regs, long
4540 if (regs->tstate & TSTATE_PRIV) {
4542 +#ifdef CONFIG_PAX_REFCOUNT
4544 + pax_report_refcount_overflow(regs);
4547 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
4548 die_if_kernel(buffer, regs);
4550 @@ -113,11 +119,16 @@ void bad_trap(struct pt_regs *regs, long
4551 void bad_trap_tl1(struct pt_regs *regs, long lvl)
4556 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
4557 0, lvl, SIGTRAP) == NOTIFY_STOP)
4560 +#ifdef CONFIG_PAX_REFCOUNT
4562 + pax_report_refcount_overflow(regs);
4565 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
4567 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
4568 @@ -1141,7 +1152,7 @@ static void cheetah_log_errors(struct pt
4569 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
4570 printk("%s" "ERROR(%d): ",
4571 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
4572 - printk("TPC<%pS>\n", (void *) regs->tpc);
4573 + printk("TPC<%pA>\n", (void *) regs->tpc);
4574 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
4575 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
4576 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
4577 @@ -1748,7 +1759,7 @@ void cheetah_plus_parity_error(int type,
4579 (type & 0x1) ? 'I' : 'D',
4581 - printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
4582 + printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
4583 panic("Irrecoverable Cheetah+ parity error.");
4586 @@ -1756,7 +1767,7 @@ void cheetah_plus_parity_error(int type,
4588 (type & 0x1) ? 'I' : 'D',
4590 - printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
4591 + printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
4594 struct sun4v_error_entry {
4595 @@ -1963,9 +1974,9 @@ void sun4v_itlb_error_report(struct pt_r
4597 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
4599 - printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
4600 + printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
4601 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
4602 - printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
4603 + printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
4604 (void *) regs->u_regs[UREG_I7]);
4605 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
4606 "pte[%lx] error[%lx]\n",
4607 @@ -1987,9 +1998,9 @@ void sun4v_dtlb_error_report(struct pt_r
4609 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
4611 - printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
4612 + printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
4613 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
4614 - printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
4615 + printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
4616 (void *) regs->u_regs[UREG_I7]);
4617 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
4618 "pte[%lx] error[%lx]\n",
4619 @@ -2196,13 +2207,13 @@ void show_stack(struct task_struct *tsk,
4620 fp = (unsigned long)sf->fp + STACK_BIAS;
4623 - printk(" [%016lx] %pS\n", pc, (void *) pc);
4624 + printk(" [%016lx] %pA\n", pc, (void *) pc);
4625 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
4626 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
4627 int index = tsk->curr_ret_stack;
4628 if (tsk->ret_stack && index >= graph) {
4629 pc = tsk->ret_stack[index - graph].ret;
4630 - printk(" [%016lx] %pS\n", pc, (void *) pc);
4631 + printk(" [%016lx] %pA\n", pc, (void *) pc);
4635 @@ -2255,7 +2266,7 @@ void die_if_kernel(char *str, struct pt_
4638 kstack_valid(tp, (unsigned long) rw)) {
4639 - printk("Caller[%016lx]: %pS\n", rw->ins[7],
4640 + printk("Caller[%016lx]: %pA\n", rw->ins[7],
4641 (void *) rw->ins[7]);
4643 rw = kernel_stack_up(rw);
4644 diff -urNp linux-2.6.37/arch/sparc/kernel/unaligned_64.c linux-2.6.37/arch/sparc/kernel/unaligned_64.c
4645 --- linux-2.6.37/arch/sparc/kernel/unaligned_64.c 2011-01-04 19:50:19.000000000 -0500
4646 +++ linux-2.6.37/arch/sparc/kernel/unaligned_64.c 2011-01-17 02:41:00.000000000 -0500
4647 @@ -278,7 +278,7 @@ static void log_unaligned(struct pt_regs
4648 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
4650 if (__ratelimit(&ratelimit)) {
4651 - printk("Kernel unaligned access at TPC[%lx] %pS\n",
4652 + printk("Kernel unaligned access at TPC[%lx] %pA\n",
4653 regs->tpc, (void *) regs->tpc);
4656 diff -urNp linux-2.6.37/arch/sparc/lib/atomic_64.S linux-2.6.37/arch/sparc/lib/atomic_64.S
4657 --- linux-2.6.37/arch/sparc/lib/atomic_64.S 2011-01-04 19:50:19.000000000 -0500
4658 +++ linux-2.6.37/arch/sparc/lib/atomic_64.S 2011-01-17 02:41:00.000000000 -0500
4660 atomic_add: /* %o0 = increment, %o1 = atomic_ptr */
4664 + addcc %g1, %o0, %g7
4666 +#ifdef CONFIG_PAX_REFCOUNT
4672 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
4673 @@ -28,12 +33,32 @@ atomic_add: /* %o0 = increment, %o1 = at
4674 2: BACKOFF_SPIN(%o2, %o3, 1b)
4675 .size atomic_add, .-atomic_add
4677 + .globl atomic_add_unchecked
4678 + .type atomic_add_unchecked,#function
4679 +atomic_add_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
4680 + BACKOFF_SETUP(%o2)
4683 + cas [%o1], %g1, %g7
4689 +2: BACKOFF_SPIN(%o2, %o3, 1b)
4690 + .size atomic_add_unchecked, .-atomic_add_unchecked
4693 .type atomic_sub,#function
4694 atomic_sub: /* %o0 = decrement, %o1 = atomic_ptr */
4698 + subcc %g1, %o0, %g7
4700 +#ifdef CONFIG_PAX_REFCOUNT
4706 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
4707 @@ -43,12 +68,32 @@ atomic_sub: /* %o0 = decrement, %o1 = at
4708 2: BACKOFF_SPIN(%o2, %o3, 1b)
4709 .size atomic_sub, .-atomic_sub
4711 + .globl atomic_sub_unchecked
4712 + .type atomic_sub_unchecked,#function
4713 +atomic_sub_unchecked: /* %o0 = decrement, %o1 = atomic_ptr */
4714 + BACKOFF_SETUP(%o2)
4717 + cas [%o1], %g1, %g7
4723 +2: BACKOFF_SPIN(%o2, %o3, 1b)
4724 + .size atomic_sub_unchecked, .-atomic_sub_unchecked
4726 .globl atomic_add_ret
4727 .type atomic_add_ret,#function
4728 atomic_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
4732 + addcc %g1, %o0, %g7
4734 +#ifdef CONFIG_PAX_REFCOUNT
4740 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
4741 @@ -58,12 +103,33 @@ atomic_add_ret: /* %o0 = increment, %o1
4742 2: BACKOFF_SPIN(%o2, %o3, 1b)
4743 .size atomic_add_ret, .-atomic_add_ret
4745 + .globl atomic_add_ret_unchecked
4746 + .type atomic_add_ret_unchecked,#function
4747 +atomic_add_ret_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
4748 + BACKOFF_SETUP(%o2)
4750 + addcc %g1, %o0, %g7
4751 + cas [%o1], %g1, %g7
4758 +2: BACKOFF_SPIN(%o2, %o3, 1b)
4759 + .size atomic_add_ret_unchecked, .-atomic_add_ret_unchecked
4761 .globl atomic_sub_ret
4762 .type atomic_sub_ret,#function
4763 atomic_sub_ret: /* %o0 = decrement, %o1 = atomic_ptr */
4767 + subcc %g1, %o0, %g7
4769 +#ifdef CONFIG_PAX_REFCOUNT
4775 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
4776 @@ -78,7 +144,12 @@ atomic_sub_ret: /* %o0 = decrement, %o1
4777 atomic64_add: /* %o0 = increment, %o1 = atomic_ptr */
4781 + addcc %g1, %o0, %g7
4783 +#ifdef CONFIG_PAX_REFCOUNT
4787 casx [%o1], %g1, %g7
4789 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
4790 @@ -88,12 +159,32 @@ atomic64_add: /* %o0 = increment, %o1 =
4791 2: BACKOFF_SPIN(%o2, %o3, 1b)
4792 .size atomic64_add, .-atomic64_add
4794 + .globl atomic64_add_unchecked
4795 + .type atomic64_add_unchecked,#function
4796 +atomic64_add_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
4797 + BACKOFF_SETUP(%o2)
4799 + addcc %g1, %o0, %g7
4800 + casx [%o1], %g1, %g7
4806 +2: BACKOFF_SPIN(%o2, %o3, 1b)
4807 + .size atomic64_add_unchecked, .-atomic64_add_unchecked
4810 .type atomic64_sub,#function
4811 atomic64_sub: /* %o0 = decrement, %o1 = atomic_ptr */
4815 + subcc %g1, %o0, %g7
4817 +#ifdef CONFIG_PAX_REFCOUNT
4821 casx [%o1], %g1, %g7
4823 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
4824 @@ -103,12 +194,32 @@ atomic64_sub: /* %o0 = decrement, %o1 =
4825 2: BACKOFF_SPIN(%o2, %o3, 1b)
4826 .size atomic64_sub, .-atomic64_sub
4828 + .globl atomic64_sub_unchecked
4829 + .type atomic64_sub_unchecked,#function
4830 +atomic64_sub_unchecked: /* %o0 = decrement, %o1 = atomic_ptr */
4831 + BACKOFF_SETUP(%o2)
4833 + subcc %g1, %o0, %g7
4834 + casx [%o1], %g1, %g7
4840 +2: BACKOFF_SPIN(%o2, %o3, 1b)
4841 + .size atomic64_sub_unchecked, .-atomic64_sub_unchecked
4843 .globl atomic64_add_ret
4844 .type atomic64_add_ret,#function
4845 atomic64_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
4849 + addcc %g1, %o0, %g7
4851 +#ifdef CONFIG_PAX_REFCOUNT
4855 casx [%o1], %g1, %g7
4857 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
4858 @@ -118,12 +229,33 @@ atomic64_add_ret: /* %o0 = increment, %o
4859 2: BACKOFF_SPIN(%o2, %o3, 1b)
4860 .size atomic64_add_ret, .-atomic64_add_ret
4862 + .globl atomic64_add_ret_unchecked
4863 + .type atomic64_add_ret_unchecked,#function
4864 +atomic64_add_ret_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
4865 + BACKOFF_SETUP(%o2)
4867 + addcc %g1, %o0, %g7
4868 + casx [%o1], %g1, %g7
4875 +2: BACKOFF_SPIN(%o2, %o3, 1b)
4876 + .size atomic64_add_ret_unchecked, .-atomic64_add_ret_unchecked
4878 .globl atomic64_sub_ret
4879 .type atomic64_sub_ret,#function
4880 atomic64_sub_ret: /* %o0 = decrement, %o1 = atomic_ptr */
4884 + subcc %g1, %o0, %g7
4886 +#ifdef CONFIG_PAX_REFCOUNT
4890 casx [%o1], %g1, %g7
4892 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
4893 diff -urNp linux-2.6.37/arch/sparc/lib/ksyms.c linux-2.6.37/arch/sparc/lib/ksyms.c
4894 --- linux-2.6.37/arch/sparc/lib/ksyms.c 2011-01-04 19:50:19.000000000 -0500
4895 +++ linux-2.6.37/arch/sparc/lib/ksyms.c 2011-01-17 02:41:00.000000000 -0500
4896 @@ -142,12 +142,17 @@ EXPORT_SYMBOL(__downgrade_write);
4898 /* Atomic counter implementation. */
4899 EXPORT_SYMBOL(atomic_add);
4900 +EXPORT_SYMBOL(atomic_add_unchecked);
4901 EXPORT_SYMBOL(atomic_add_ret);
4902 EXPORT_SYMBOL(atomic_sub);
4903 +EXPORT_SYMBOL(atomic_sub_unchecked);
4904 EXPORT_SYMBOL(atomic_sub_ret);
4905 EXPORT_SYMBOL(atomic64_add);
4906 +EXPORT_SYMBOL(atomic64_add_unchecked);
4907 EXPORT_SYMBOL(atomic64_add_ret);
4908 +EXPORT_SYMBOL(atomic64_add_ret_unchecked);
4909 EXPORT_SYMBOL(atomic64_sub);
4910 +EXPORT_SYMBOL(atomic64_sub_unchecked);
4911 EXPORT_SYMBOL(atomic64_sub_ret);
4913 /* Atomic bit operations. */
4914 diff -urNp linux-2.6.37/arch/sparc/Makefile linux-2.6.37/arch/sparc/Makefile
4915 --- linux-2.6.37/arch/sparc/Makefile 2011-01-04 19:50:19.000000000 -0500
4916 +++ linux-2.6.37/arch/sparc/Makefile 2011-01-17 02:41:00.000000000 -0500
4917 @@ -75,7 +75,7 @@ drivers-$(CONFIG_OPROFILE) += arch/sparc
4918 # Export what is needed by arch/sparc/boot/Makefile
4919 export VMLINUX_INIT VMLINUX_MAIN
4920 VMLINUX_INIT := $(head-y) $(init-y)
4921 -VMLINUX_MAIN := $(core-y) kernel/ mm/ fs/ ipc/ security/ crypto/ block/
4922 +VMLINUX_MAIN := $(core-y) kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
4923 VMLINUX_MAIN += $(patsubst %/, %/lib.a, $(libs-y)) $(libs-y)
4924 VMLINUX_MAIN += $(drivers-y) $(net-y)
4926 diff -urNp linux-2.6.37/arch/sparc/mm/fault_32.c linux-2.6.37/arch/sparc/mm/fault_32.c
4927 --- linux-2.6.37/arch/sparc/mm/fault_32.c 2011-01-04 19:50:19.000000000 -0500
4928 +++ linux-2.6.37/arch/sparc/mm/fault_32.c 2011-01-17 02:41:00.000000000 -0500
4930 #include <linux/interrupt.h>
4931 #include <linux/module.h>
4932 #include <linux/kdebug.h>
4933 +#include <linux/slab.h>
4934 +#include <linux/pagemap.h>
4935 +#include <linux/compiler.h>
4937 #include <asm/system.h>
4938 #include <asm/page.h>
4939 @@ -209,6 +212,268 @@ static unsigned long compute_si_addr(str
4940 return safe_compute_effective_address(regs, insn);
4943 +#ifdef CONFIG_PAX_PAGEEXEC
4944 +#ifdef CONFIG_PAX_DLRESOLVE
4945 +static void pax_emuplt_close(struct vm_area_struct *vma)
4947 + vma->vm_mm->call_dl_resolve = 0UL;
4950 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
4952 + unsigned int *kaddr;
4954 + vmf->page = alloc_page(GFP_HIGHUSER);
4956 + return VM_FAULT_OOM;
4958 + kaddr = kmap(vmf->page);
4959 + memset(kaddr, 0, PAGE_SIZE);
4960 + kaddr[0] = 0x9DE3BFA8U; /* save */
4961 + flush_dcache_page(vmf->page);
4962 + kunmap(vmf->page);
4963 + return VM_FAULT_MAJOR;
4966 +static const struct vm_operations_struct pax_vm_ops = {
4967 + .close = pax_emuplt_close,
4968 + .fault = pax_emuplt_fault
4971 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
4975 + INIT_LIST_HEAD(&vma->anon_vma_chain);
4976 + vma->vm_mm = current->mm;
4977 + vma->vm_start = addr;
4978 + vma->vm_end = addr + PAGE_SIZE;
4979 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
4980 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
4981 + vma->vm_ops = &pax_vm_ops;
4983 + ret = insert_vm_struct(current->mm, vma);
4987 + ++current->mm->total_vm;
4993 + * PaX: decide what to do with offenders (regs->pc = fault address)
4995 + * returns 1 when task should be killed
4996 + * 2 when patched PLT trampoline was detected
4997 + * 3 when unpatched PLT trampoline was detected
4999 +static int pax_handle_fetch_fault(struct pt_regs *regs)
5002 +#ifdef CONFIG_PAX_EMUPLT
5005 + do { /* PaX: patched PLT emulation #1 */
5006 + unsigned int sethi1, sethi2, jmpl;
5008 + err = get_user(sethi1, (unsigned int *)regs->pc);
5009 + err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
5010 + err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
5015 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
5016 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
5017 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
5019 + unsigned int addr;
5021 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
5022 + addr = regs->u_regs[UREG_G1];
5023 + addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
5025 + regs->npc = addr+4;
5030 + { /* PaX: patched PLT emulation #2 */
5033 + err = get_user(ba, (unsigned int *)regs->pc);
5035 + if (!err && (ba & 0xFFC00000U) == 0x30800000U) {
5036 + unsigned int addr;
5038 + addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
5040 + regs->npc = addr+4;
5045 + do { /* PaX: patched PLT emulation #3 */
5046 + unsigned int sethi, jmpl, nop;
5048 + err = get_user(sethi, (unsigned int *)regs->pc);
5049 + err |= get_user(jmpl, (unsigned int *)(regs->pc+4));
5050 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
5055 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
5056 + (jmpl & 0xFFFFE000U) == 0x81C06000U &&
5057 + nop == 0x01000000U)
5059 + unsigned int addr;
5061 + addr = (sethi & 0x003FFFFFU) << 10;
5062 + regs->u_regs[UREG_G1] = addr;
5063 + addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
5065 + regs->npc = addr+4;
5070 + do { /* PaX: unpatched PLT emulation step 1 */
5071 + unsigned int sethi, ba, nop;
5073 + err = get_user(sethi, (unsigned int *)regs->pc);
5074 + err |= get_user(ba, (unsigned int *)(regs->pc+4));
5075 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
5080 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
5081 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
5082 + nop == 0x01000000U)
5084 + unsigned int addr, save, call;
5086 + if ((ba & 0xFFC00000U) == 0x30800000U)
5087 + addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
5089 + addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
5091 + err = get_user(save, (unsigned int *)addr);
5092 + err |= get_user(call, (unsigned int *)(addr+4));
5093 + err |= get_user(nop, (unsigned int *)(addr+8));
5097 +#ifdef CONFIG_PAX_DLRESOLVE
5098 + if (save == 0x9DE3BFA8U &&
5099 + (call & 0xC0000000U) == 0x40000000U &&
5100 + nop == 0x01000000U)
5102 + struct vm_area_struct *vma;
5103 + unsigned long call_dl_resolve;
5105 + down_read(¤t->mm->mmap_sem);
5106 + call_dl_resolve = current->mm->call_dl_resolve;
5107 + up_read(¤t->mm->mmap_sem);
5108 + if (likely(call_dl_resolve))
5111 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
5113 + down_write(¤t->mm->mmap_sem);
5114 + if (current->mm->call_dl_resolve) {
5115 + call_dl_resolve = current->mm->call_dl_resolve;
5116 + up_write(¤t->mm->mmap_sem);
5118 + kmem_cache_free(vm_area_cachep, vma);
5122 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
5123 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
5124 + up_write(¤t->mm->mmap_sem);
5126 + kmem_cache_free(vm_area_cachep, vma);
5130 + if (pax_insert_vma(vma, call_dl_resolve)) {
5131 + up_write(¤t->mm->mmap_sem);
5132 + kmem_cache_free(vm_area_cachep, vma);
5136 + current->mm->call_dl_resolve = call_dl_resolve;
5137 + up_write(¤t->mm->mmap_sem);
5140 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
5141 + regs->pc = call_dl_resolve;
5142 + regs->npc = addr+4;
5147 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
5148 + if ((save & 0xFFC00000U) == 0x05000000U &&
5149 + (call & 0xFFFFE000U) == 0x85C0A000U &&
5150 + nop == 0x01000000U)
5152 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
5153 + regs->u_regs[UREG_G2] = addr + 4;
5154 + addr = (save & 0x003FFFFFU) << 10;
5155 + addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
5157 + regs->npc = addr+4;
5163 + do { /* PaX: unpatched PLT emulation step 2 */
5164 + unsigned int save, call, nop;
5166 + err = get_user(save, (unsigned int *)(regs->pc-4));
5167 + err |= get_user(call, (unsigned int *)regs->pc);
5168 + err |= get_user(nop, (unsigned int *)(regs->pc+4));
5172 + if (save == 0x9DE3BFA8U &&
5173 + (call & 0xC0000000U) == 0x40000000U &&
5174 + nop == 0x01000000U)
5176 + unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
5178 + regs->u_regs[UREG_RETPC] = regs->pc;
5179 + regs->pc = dl_resolve;
5180 + regs->npc = dl_resolve+4;
5189 +void pax_report_insns(void *pc, void *sp)
5193 + printk(KERN_ERR "PAX: bytes at PC: ");
5194 + for (i = 0; i < 8; i++) {
5196 + if (get_user(c, (unsigned int *)pc+i))
5197 + printk(KERN_CONT "???????? ");
5199 + printk(KERN_CONT "%08x ", c);
5205 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
5208 @@ -282,6 +547,24 @@ good_area:
5209 if(!(vma->vm_flags & VM_WRITE))
5213 +#ifdef CONFIG_PAX_PAGEEXEC
5214 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
5215 + up_read(&mm->mmap_sem);
5216 + switch (pax_handle_fetch_fault(regs)) {
5218 +#ifdef CONFIG_PAX_EMUPLT
5225 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
5226 + do_group_exit(SIGKILL);
5230 /* Allow reads even for write-only mappings */
5231 if(!(vma->vm_flags & (VM_READ | VM_EXEC)))
5233 diff -urNp linux-2.6.37/arch/sparc/mm/fault_64.c linux-2.6.37/arch/sparc/mm/fault_64.c
5234 --- linux-2.6.37/arch/sparc/mm/fault_64.c 2011-01-04 19:50:19.000000000 -0500
5235 +++ linux-2.6.37/arch/sparc/mm/fault_64.c 2011-01-17 02:41:00.000000000 -0500
5237 #include <linux/kprobes.h>
5238 #include <linux/kdebug.h>
5239 #include <linux/percpu.h>
5240 +#include <linux/slab.h>
5241 +#include <linux/pagemap.h>
5242 +#include <linux/compiler.h>
5244 #include <asm/page.h>
5245 #include <asm/pgtable.h>
5246 @@ -74,7 +77,7 @@ static void __kprobes bad_kernel_pc(stru
5247 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
5249 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
5250 - printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
5251 + printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
5252 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
5254 unhandled_fault(regs->tpc, current, regs);
5255 @@ -272,6 +275,457 @@ static void noinline __kprobes bogus_32b
5259 +#ifdef CONFIG_PAX_PAGEEXEC
5260 +#ifdef CONFIG_PAX_DLRESOLVE
5261 +static void pax_emuplt_close(struct vm_area_struct *vma)
5263 + vma->vm_mm->call_dl_resolve = 0UL;
5266 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
5268 + unsigned int *kaddr;
5270 + vmf->page = alloc_page(GFP_HIGHUSER);
5272 + return VM_FAULT_OOM;
5274 + kaddr = kmap(vmf->page);
5275 + memset(kaddr, 0, PAGE_SIZE);
5276 + kaddr[0] = 0x9DE3BFA8U; /* save */
5277 + flush_dcache_page(vmf->page);
5278 + kunmap(vmf->page);
5279 + return VM_FAULT_MAJOR;
5282 +static const struct vm_operations_struct pax_vm_ops = {
5283 + .close = pax_emuplt_close,
5284 + .fault = pax_emuplt_fault
5287 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
5291 + INIT_LIST_HEAD(&vma->anon_vma_chain);
5292 + vma->vm_mm = current->mm;
5293 + vma->vm_start = addr;
5294 + vma->vm_end = addr + PAGE_SIZE;
5295 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
5296 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
5297 + vma->vm_ops = &pax_vm_ops;
5299 + ret = insert_vm_struct(current->mm, vma);
5303 + ++current->mm->total_vm;
5309 + * PaX: decide what to do with offenders (regs->tpc = fault address)
5311 + * returns 1 when task should be killed
5312 + * 2 when patched PLT trampoline was detected
5313 + * 3 when unpatched PLT trampoline was detected
5315 +static int pax_handle_fetch_fault(struct pt_regs *regs)
5318 +#ifdef CONFIG_PAX_EMUPLT
5321 + do { /* PaX: patched PLT emulation #1 */
5322 + unsigned int sethi1, sethi2, jmpl;
5324 + err = get_user(sethi1, (unsigned int *)regs->tpc);
5325 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
5326 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
5331 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
5332 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
5333 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
5335 + unsigned long addr;
5337 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
5338 + addr = regs->u_regs[UREG_G1];
5339 + addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
5341 + if (test_thread_flag(TIF_32BIT))
5342 + addr &= 0xFFFFFFFFUL;
5345 + regs->tnpc = addr+4;
5350 + { /* PaX: patched PLT emulation #2 */
5353 + err = get_user(ba, (unsigned int *)regs->tpc);
5355 + if (!err && (ba & 0xFFC00000U) == 0x30800000U) {
5356 + unsigned long addr;
5358 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
5360 + if (test_thread_flag(TIF_32BIT))
5361 + addr &= 0xFFFFFFFFUL;
5364 + regs->tnpc = addr+4;
5369 + do { /* PaX: patched PLT emulation #3 */
5370 + unsigned int sethi, jmpl, nop;
5372 + err = get_user(sethi, (unsigned int *)regs->tpc);
5373 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+4));
5374 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
5379 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
5380 + (jmpl & 0xFFFFE000U) == 0x81C06000U &&
5381 + nop == 0x01000000U)
5383 + unsigned long addr;
5385 + addr = (sethi & 0x003FFFFFU) << 10;
5386 + regs->u_regs[UREG_G1] = addr;
5387 + addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
5389 + if (test_thread_flag(TIF_32BIT))
5390 + addr &= 0xFFFFFFFFUL;
5393 + regs->tnpc = addr+4;
5398 + do { /* PaX: patched PLT emulation #4 */
5399 + unsigned int sethi, mov1, call, mov2;
5401 + err = get_user(sethi, (unsigned int *)regs->tpc);
5402 + err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
5403 + err |= get_user(call, (unsigned int *)(regs->tpc+8));
5404 + err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
5409 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
5410 + mov1 == 0x8210000FU &&
5411 + (call & 0xC0000000U) == 0x40000000U &&
5412 + mov2 == 0x9E100001U)
5414 + unsigned long addr;
5416 + regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
5417 + addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
5419 + if (test_thread_flag(TIF_32BIT))
5420 + addr &= 0xFFFFFFFFUL;
5423 + regs->tnpc = addr+4;
5428 + do { /* PaX: patched PLT emulation #5 */
5429 + unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
5431 + err = get_user(sethi, (unsigned int *)regs->tpc);
5432 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
5433 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
5434 + err |= get_user(or1, (unsigned int *)(regs->tpc+12));
5435 + err |= get_user(or2, (unsigned int *)(regs->tpc+16));
5436 + err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
5437 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
5438 + err |= get_user(nop, (unsigned int *)(regs->tpc+28));
5443 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
5444 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
5445 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
5446 + (or1 & 0xFFFFE000U) == 0x82106000U &&
5447 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
5448 + sllx == 0x83287020U &&
5449 + jmpl == 0x81C04005U &&
5450 + nop == 0x01000000U)
5452 + unsigned long addr;
5454 + regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
5455 + regs->u_regs[UREG_G1] <<= 32;
5456 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
5457 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
5459 + regs->tnpc = addr+4;
5464 + do { /* PaX: patched PLT emulation #6 */
5465 + unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
5467 + err = get_user(sethi, (unsigned int *)regs->tpc);
5468 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
5469 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
5470 + err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
5471 + err |= get_user(or, (unsigned int *)(regs->tpc+16));
5472 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
5473 + err |= get_user(nop, (unsigned int *)(regs->tpc+24));
5478 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
5479 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
5480 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
5481 + sllx == 0x83287020U &&
5482 + (or & 0xFFFFE000U) == 0x8A116000U &&
5483 + jmpl == 0x81C04005U &&
5484 + nop == 0x01000000U)
5486 + unsigned long addr;
5488 + regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
5489 + regs->u_regs[UREG_G1] <<= 32;
5490 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
5491 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
5493 + regs->tnpc = addr+4;
5498 + do { /* PaX: unpatched PLT emulation step 1 */
5499 + unsigned int sethi, ba, nop;
5501 + err = get_user(sethi, (unsigned int *)regs->tpc);
5502 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
5503 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
5508 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
5509 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
5510 + nop == 0x01000000U)
5512 + unsigned long addr;
5513 + unsigned int save, call;
5514 + unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
5516 + if ((ba & 0xFFC00000U) == 0x30800000U)
5517 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
5519 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
5521 + if (test_thread_flag(TIF_32BIT))
5522 + addr &= 0xFFFFFFFFUL;
5524 + err = get_user(save, (unsigned int *)addr);
5525 + err |= get_user(call, (unsigned int *)(addr+4));
5526 + err |= get_user(nop, (unsigned int *)(addr+8));
5530 +#ifdef CONFIG_PAX_DLRESOLVE
5531 + if (save == 0x9DE3BFA8U &&
5532 + (call & 0xC0000000U) == 0x40000000U &&
5533 + nop == 0x01000000U)
5535 + struct vm_area_struct *vma;
5536 + unsigned long call_dl_resolve;
5538 + down_read(¤t->mm->mmap_sem);
5539 + call_dl_resolve = current->mm->call_dl_resolve;
5540 + up_read(¤t->mm->mmap_sem);
5541 + if (likely(call_dl_resolve))
5544 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
5546 + down_write(¤t->mm->mmap_sem);
5547 + if (current->mm->call_dl_resolve) {
5548 + call_dl_resolve = current->mm->call_dl_resolve;
5549 + up_write(¤t->mm->mmap_sem);
5551 + kmem_cache_free(vm_area_cachep, vma);
5555 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
5556 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
5557 + up_write(¤t->mm->mmap_sem);
5559 + kmem_cache_free(vm_area_cachep, vma);
5563 + if (pax_insert_vma(vma, call_dl_resolve)) {
5564 + up_write(¤t->mm->mmap_sem);
5565 + kmem_cache_free(vm_area_cachep, vma);
5569 + current->mm->call_dl_resolve = call_dl_resolve;
5570 + up_write(¤t->mm->mmap_sem);
5573 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
5574 + regs->tpc = call_dl_resolve;
5575 + regs->tnpc = addr+4;
5580 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
5581 + if ((save & 0xFFC00000U) == 0x05000000U &&
5582 + (call & 0xFFFFE000U) == 0x85C0A000U &&
5583 + nop == 0x01000000U)
5585 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
5586 + regs->u_regs[UREG_G2] = addr + 4;
5587 + addr = (save & 0x003FFFFFU) << 10;
5588 + addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
5590 + if (test_thread_flag(TIF_32BIT))
5591 + addr &= 0xFFFFFFFFUL;
5594 + regs->tnpc = addr+4;
5598 + /* PaX: 64-bit PLT stub */
5599 + err = get_user(sethi1, (unsigned int *)addr);
5600 + err |= get_user(sethi2, (unsigned int *)(addr+4));
5601 + err |= get_user(or1, (unsigned int *)(addr+8));
5602 + err |= get_user(or2, (unsigned int *)(addr+12));
5603 + err |= get_user(sllx, (unsigned int *)(addr+16));
5604 + err |= get_user(add, (unsigned int *)(addr+20));
5605 + err |= get_user(jmpl, (unsigned int *)(addr+24));
5606 + err |= get_user(nop, (unsigned int *)(addr+28));
5610 + if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
5611 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
5612 + (or1 & 0xFFFFE000U) == 0x88112000U &&
5613 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
5614 + sllx == 0x89293020U &&
5615 + add == 0x8A010005U &&
5616 + jmpl == 0x89C14000U &&
5617 + nop == 0x01000000U)
5619 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
5620 + regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
5621 + regs->u_regs[UREG_G4] <<= 32;
5622 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
5623 + regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
5624 + regs->u_regs[UREG_G4] = addr + 24;
5625 + addr = regs->u_regs[UREG_G5];
5627 + regs->tnpc = addr+4;
5633 +#ifdef CONFIG_PAX_DLRESOLVE
5634 + do { /* PaX: unpatched PLT emulation step 2 */
5635 + unsigned int save, call, nop;
5637 + err = get_user(save, (unsigned int *)(regs->tpc-4));
5638 + err |= get_user(call, (unsigned int *)regs->tpc);
5639 + err |= get_user(nop, (unsigned int *)(regs->tpc+4));
5643 + if (save == 0x9DE3BFA8U &&
5644 + (call & 0xC0000000U) == 0x40000000U &&
5645 + nop == 0x01000000U)
5647 + unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
5649 + if (test_thread_flag(TIF_32BIT))
5650 + dl_resolve &= 0xFFFFFFFFUL;
5652 + regs->u_regs[UREG_RETPC] = regs->tpc;
5653 + regs->tpc = dl_resolve;
5654 + regs->tnpc = dl_resolve+4;
5660 + do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
5661 + unsigned int sethi, ba, nop;
5663 + err = get_user(sethi, (unsigned int *)regs->tpc);
5664 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
5665 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
5670 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
5671 + (ba & 0xFFF00000U) == 0x30600000U &&
5672 + nop == 0x01000000U)
5674 + unsigned long addr;
5676 + addr = (sethi & 0x003FFFFFU) << 10;
5677 + regs->u_regs[UREG_G1] = addr;
5678 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
5680 + if (test_thread_flag(TIF_32BIT))
5681 + addr &= 0xFFFFFFFFUL;
5684 + regs->tnpc = addr+4;
5694 +void pax_report_insns(void *pc, void *sp)
5698 + printk(KERN_ERR "PAX: bytes at PC: ");
5699 + for (i = 0; i < 8; i++) {
5701 + if (get_user(c, (unsigned int *)pc+i))
5702 + printk(KERN_CONT "???????? ");
5704 + printk(KERN_CONT "%08x ", c);
5710 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
5712 struct mm_struct *mm = current->mm;
5713 @@ -340,6 +794,29 @@ asmlinkage void __kprobes do_sparc64_fau
5717 +#ifdef CONFIG_PAX_PAGEEXEC
5718 + /* PaX: detect ITLB misses on non-exec pages */
5719 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
5720 + !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
5722 + if (address != regs->tpc)
5725 + up_read(&mm->mmap_sem);
5726 + switch (pax_handle_fetch_fault(regs)) {
5728 +#ifdef CONFIG_PAX_EMUPLT
5735 + pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
5736 + do_group_exit(SIGKILL);
5740 /* Pure DTLB misses do not tell us whether the fault causing
5741 * load/store/atomic was a write or not, it only says that there
5742 * was no match. So in such a case we (carefully) read the
5743 diff -urNp linux-2.6.37/arch/sparc/mm/hugetlbpage.c linux-2.6.37/arch/sparc/mm/hugetlbpage.c
5744 --- linux-2.6.37/arch/sparc/mm/hugetlbpage.c 2011-01-04 19:50:19.000000000 -0500
5745 +++ linux-2.6.37/arch/sparc/mm/hugetlbpage.c 2011-01-17 02:41:00.000000000 -0500
5746 @@ -68,7 +68,7 @@ full_search:
5750 - if (likely(!vma || addr + len <= vma->vm_start)) {
5751 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5753 * Remember the place where we stopped the search:
5755 @@ -107,7 +107,7 @@ hugetlb_get_unmapped_area_topdown(struct
5756 /* make sure it can fit in the remaining address space */
5757 if (likely(addr > len)) {
5758 vma = find_vma(mm, addr-len);
5759 - if (!vma || addr <= vma->vm_start) {
5760 + if (check_heap_stack_gap(vma, addr - len, len)) {
5761 /* remember the address as a hint for next time */
5762 return (mm->free_area_cache = addr-len);
5764 @@ -125,7 +125,7 @@ hugetlb_get_unmapped_area_topdown(struct
5765 * return with success:
5767 vma = find_vma(mm, addr);
5768 - if (likely(!vma || addr+len <= vma->vm_start)) {
5769 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5770 /* remember the address as a hint for next time */
5771 return (mm->free_area_cache = addr);
5773 @@ -182,8 +182,7 @@ hugetlb_get_unmapped_area(struct file *f
5775 addr = ALIGN(addr, HPAGE_SIZE);
5776 vma = find_vma(mm, addr);
5777 - if (task_size - len >= addr &&
5778 - (!vma || addr + len <= vma->vm_start))
5779 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
5782 if (mm->get_unmapped_area == arch_get_unmapped_area)
5783 diff -urNp linux-2.6.37/arch/sparc/mm/init_32.c linux-2.6.37/arch/sparc/mm/init_32.c
5784 --- linux-2.6.37/arch/sparc/mm/init_32.c 2011-01-04 19:50:19.000000000 -0500
5785 +++ linux-2.6.37/arch/sparc/mm/init_32.c 2011-01-17 02:41:00.000000000 -0500
5786 @@ -318,6 +318,9 @@ extern void device_scan(void);
5787 pgprot_t PAGE_SHARED __read_mostly;
5788 EXPORT_SYMBOL(PAGE_SHARED);
5790 +pgprot_t PAGE_SHARED_NOEXEC __read_mostly;
5791 +EXPORT_SYMBOL(PAGE_SHARED_NOEXEC);
5793 void __init paging_init(void)
5795 switch(sparc_cpu_model) {
5796 @@ -346,17 +349,17 @@ void __init paging_init(void)
5798 /* Initialize the protection map with non-constant, MMU dependent values. */
5799 protection_map[0] = PAGE_NONE;
5800 - protection_map[1] = PAGE_READONLY;
5801 - protection_map[2] = PAGE_COPY;
5802 - protection_map[3] = PAGE_COPY;
5803 + protection_map[1] = PAGE_READONLY_NOEXEC;
5804 + protection_map[2] = PAGE_COPY_NOEXEC;
5805 + protection_map[3] = PAGE_COPY_NOEXEC;
5806 protection_map[4] = PAGE_READONLY;
5807 protection_map[5] = PAGE_READONLY;
5808 protection_map[6] = PAGE_COPY;
5809 protection_map[7] = PAGE_COPY;
5810 protection_map[8] = PAGE_NONE;
5811 - protection_map[9] = PAGE_READONLY;
5812 - protection_map[10] = PAGE_SHARED;
5813 - protection_map[11] = PAGE_SHARED;
5814 + protection_map[9] = PAGE_READONLY_NOEXEC;
5815 + protection_map[10] = PAGE_SHARED_NOEXEC;
5816 + protection_map[11] = PAGE_SHARED_NOEXEC;
5817 protection_map[12] = PAGE_READONLY;
5818 protection_map[13] = PAGE_READONLY;
5819 protection_map[14] = PAGE_SHARED;
5820 diff -urNp linux-2.6.37/arch/sparc/mm/Makefile linux-2.6.37/arch/sparc/mm/Makefile
5821 --- linux-2.6.37/arch/sparc/mm/Makefile 2011-01-04 19:50:19.000000000 -0500
5822 +++ linux-2.6.37/arch/sparc/mm/Makefile 2011-01-17 02:41:00.000000000 -0500
5827 -ccflags-y := -Werror
5828 +#ccflags-y := -Werror
5830 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o
5831 obj-y += fault_$(BITS).o
5832 diff -urNp linux-2.6.37/arch/sparc/mm/srmmu.c linux-2.6.37/arch/sparc/mm/srmmu.c
5833 --- linux-2.6.37/arch/sparc/mm/srmmu.c 2011-01-04 19:50:19.000000000 -0500
5834 +++ linux-2.6.37/arch/sparc/mm/srmmu.c 2011-01-17 02:41:00.000000000 -0500
5835 @@ -2200,6 +2200,13 @@ void __init ld_mmu_srmmu(void)
5836 PAGE_SHARED = pgprot_val(SRMMU_PAGE_SHARED);
5837 BTFIXUPSET_INT(page_copy, pgprot_val(SRMMU_PAGE_COPY));
5838 BTFIXUPSET_INT(page_readonly, pgprot_val(SRMMU_PAGE_RDONLY));
5840 +#ifdef CONFIG_PAX_PAGEEXEC
5841 + PAGE_SHARED_NOEXEC = pgprot_val(SRMMU_PAGE_SHARED_NOEXEC);
5842 + BTFIXUPSET_INT(page_copy_noexec, pgprot_val(SRMMU_PAGE_COPY_NOEXEC));
5843 + BTFIXUPSET_INT(page_readonly_noexec, pgprot_val(SRMMU_PAGE_RDONLY_NOEXEC));
5846 BTFIXUPSET_INT(page_kernel, pgprot_val(SRMMU_PAGE_KERNEL));
5847 page_kernel = pgprot_val(SRMMU_PAGE_KERNEL);
5849 diff -urNp linux-2.6.37/arch/um/include/asm/kmap_types.h linux-2.6.37/arch/um/include/asm/kmap_types.h
5850 --- linux-2.6.37/arch/um/include/asm/kmap_types.h 2011-01-04 19:50:19.000000000 -0500
5851 +++ linux-2.6.37/arch/um/include/asm/kmap_types.h 2011-01-17 02:41:00.000000000 -0500
5852 @@ -23,6 +23,7 @@ enum km_type {
5860 diff -urNp linux-2.6.37/arch/um/include/asm/page.h linux-2.6.37/arch/um/include/asm/page.h
5861 --- linux-2.6.37/arch/um/include/asm/page.h 2011-01-04 19:50:19.000000000 -0500
5862 +++ linux-2.6.37/arch/um/include/asm/page.h 2011-01-17 02:41:00.000000000 -0500
5864 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
5865 #define PAGE_MASK (~(PAGE_SIZE-1))
5867 +#define ktla_ktva(addr) (addr)
5868 +#define ktva_ktla(addr) (addr)
5870 #ifndef __ASSEMBLY__
5873 diff -urNp linux-2.6.37/arch/um/kernel/process.c linux-2.6.37/arch/um/kernel/process.c
5874 --- linux-2.6.37/arch/um/kernel/process.c 2011-01-04 19:50:19.000000000 -0500
5875 +++ linux-2.6.37/arch/um/kernel/process.c 2011-01-17 02:41:00.000000000 -0500
5876 @@ -404,22 +404,6 @@ int singlestepping(void * t)
5881 - * Only x86 and x86_64 have an arch_align_stack().
5882 - * All other arches have "#define arch_align_stack(x) (x)"
5883 - * in their asm/system.h
5884 - * As this is included in UML from asm-um/system-generic.h,
5885 - * we can use it to behave as the subarch does.
5887 -#ifndef arch_align_stack
5888 -unsigned long arch_align_stack(unsigned long sp)
5890 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
5891 - sp -= get_random_int() % 8192;
5896 unsigned long get_wchan(struct task_struct *p)
5898 unsigned long stack_page, sp, ip;
5899 diff -urNp linux-2.6.37/arch/um/sys-i386/syscalls.c linux-2.6.37/arch/um/sys-i386/syscalls.c
5900 --- linux-2.6.37/arch/um/sys-i386/syscalls.c 2011-01-04 19:50:19.000000000 -0500
5901 +++ linux-2.6.37/arch/um/sys-i386/syscalls.c 2011-01-17 02:41:00.000000000 -0500
5903 #include "asm/uaccess.h"
5904 #include "asm/unistd.h"
5906 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
5908 + unsigned long pax_task_size = TASK_SIZE;
5910 +#ifdef CONFIG_PAX_SEGMEXEC
5911 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
5912 + pax_task_size = SEGMEXEC_TASK_SIZE;
5915 + if (len > pax_task_size || addr > pax_task_size - len)
5922 * The prototype on i386 is:
5924 diff -urNp linux-2.6.37/arch/x86/boot/bitops.h linux-2.6.37/arch/x86/boot/bitops.h
5925 --- linux-2.6.37/arch/x86/boot/bitops.h 2011-01-04 19:50:19.000000000 -0500
5926 +++ linux-2.6.37/arch/x86/boot/bitops.h 2011-01-17 02:41:00.000000000 -0500
5927 @@ -26,7 +26,7 @@ static inline int variable_test_bit(int
5929 const u32 *p = (const u32 *)addr;
5931 - asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
5932 + asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
5936 @@ -37,7 +37,7 @@ static inline int variable_test_bit(int
5938 static inline void set_bit(int nr, void *addr)
5940 - asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
5941 + asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
5944 #endif /* BOOT_BITOPS_H */
5945 diff -urNp linux-2.6.37/arch/x86/boot/boot.h linux-2.6.37/arch/x86/boot/boot.h
5946 --- linux-2.6.37/arch/x86/boot/boot.h 2011-01-04 19:50:19.000000000 -0500
5947 +++ linux-2.6.37/arch/x86/boot/boot.h 2011-01-17 02:41:00.000000000 -0500
5948 @@ -85,7 +85,7 @@ static inline void io_delay(void)
5949 static inline u16 ds(void)
5952 - asm("movw %%ds,%0" : "=rm" (seg));
5953 + asm volatile("movw %%ds,%0" : "=rm" (seg));
5957 @@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t
5958 static inline int memcmp(const void *s1, const void *s2, size_t len)
5961 - asm("repe; cmpsb; setnz %0"
5962 + asm volatile("repe; cmpsb; setnz %0"
5963 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
5966 diff -urNp linux-2.6.37/arch/x86/boot/compressed/head_32.S linux-2.6.37/arch/x86/boot/compressed/head_32.S
5967 --- linux-2.6.37/arch/x86/boot/compressed/head_32.S 2011-01-04 19:50:19.000000000 -0500
5968 +++ linux-2.6.37/arch/x86/boot/compressed/head_32.S 2011-01-17 02:41:00.000000000 -0500
5969 @@ -76,7 +76,7 @@ ENTRY(startup_32)
5973 - movl $LOAD_PHYSICAL_ADDR, %ebx
5974 + movl $____LOAD_PHYSICAL_ADDR, %ebx
5977 /* Target address to relocate to for decompression */
5978 @@ -162,7 +162,7 @@ relocated:
5979 * and where it was actually loaded.
5982 - subl $LOAD_PHYSICAL_ADDR, %ebx
5983 + subl $____LOAD_PHYSICAL_ADDR, %ebx
5984 jz 2f /* Nothing to be done if loaded at compiled addr. */
5986 * Process relocations.
5987 @@ -170,8 +170,7 @@ relocated:
5994 addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
5997 diff -urNp linux-2.6.37/arch/x86/boot/compressed/head_64.S linux-2.6.37/arch/x86/boot/compressed/head_64.S
5998 --- linux-2.6.37/arch/x86/boot/compressed/head_64.S 2011-01-04 19:50:19.000000000 -0500
5999 +++ linux-2.6.37/arch/x86/boot/compressed/head_64.S 2011-01-17 02:41:00.000000000 -0500
6000 @@ -91,7 +91,7 @@ ENTRY(startup_32)
6004 - movl $LOAD_PHYSICAL_ADDR, %ebx
6005 + movl $____LOAD_PHYSICAL_ADDR, %ebx
6008 /* Target address to relocate to for decompression */
6009 @@ -233,7 +233,7 @@ ENTRY(startup_64)
6013 - movq $LOAD_PHYSICAL_ADDR, %rbp
6014 + movq $____LOAD_PHYSICAL_ADDR, %rbp
6017 /* Target address to relocate to for decompression */
6018 diff -urNp linux-2.6.37/arch/x86/boot/compressed/misc.c linux-2.6.37/arch/x86/boot/compressed/misc.c
6019 --- linux-2.6.37/arch/x86/boot/compressed/misc.c 2011-01-04 19:50:19.000000000 -0500
6020 +++ linux-2.6.37/arch/x86/boot/compressed/misc.c 2011-01-17 02:41:00.000000000 -0500
6021 @@ -306,7 +306,7 @@ static void parse_elf(void *output)
6023 #ifdef CONFIG_RELOCATABLE
6025 - dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
6026 + dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
6028 dest = (void *)(phdr->p_paddr);
6030 @@ -359,7 +359,7 @@ asmlinkage void decompress_kernel(void *
6031 error("Destination address too large");
6033 #ifndef CONFIG_RELOCATABLE
6034 - if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
6035 + if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
6036 error("Wrong destination address");
6039 diff -urNp linux-2.6.37/arch/x86/boot/compressed/mkpiggy.c linux-2.6.37/arch/x86/boot/compressed/mkpiggy.c
6040 --- linux-2.6.37/arch/x86/boot/compressed/mkpiggy.c 2011-01-04 19:50:19.000000000 -0500
6041 +++ linux-2.6.37/arch/x86/boot/compressed/mkpiggy.c 2011-01-17 02:41:00.000000000 -0500
6042 @@ -74,7 +74,7 @@ int main(int argc, char *argv[])
6044 offs = (olen > ilen) ? olen - ilen : 0;
6045 offs += olen >> 12; /* Add 8 bytes for each 32K block */
6046 - offs += 32*1024 + 18; /* Add 32K + 18 bytes slack */
6047 + offs += 64*1024; /* Add 64K bytes slack */
6048 offs = (offs+4095) & ~4095; /* Round to a 4K boundary */
6050 printf(".section \".rodata..compressed\",\"a\",@progbits\n");
6051 diff -urNp linux-2.6.37/arch/x86/boot/compressed/relocs.c linux-2.6.37/arch/x86/boot/compressed/relocs.c
6052 --- linux-2.6.37/arch/x86/boot/compressed/relocs.c 2011-01-04 19:50:19.000000000 -0500
6053 +++ linux-2.6.37/arch/x86/boot/compressed/relocs.c 2011-01-17 02:41:00.000000000 -0500
6056 static void die(char *fmt, ...);
6058 +#include "../../../../include/generated/autoconf.h"
6060 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
6061 static Elf32_Ehdr ehdr;
6062 +static Elf32_Phdr *phdr;
6063 static unsigned long reloc_count, reloc_idx;
6064 static unsigned long *relocs;
6066 @@ -270,9 +273,39 @@ static void read_ehdr(FILE *fp)
6070 +static void read_phdrs(FILE *fp)
6074 + phdr = calloc(ehdr.e_phnum, sizeof(Elf32_Phdr));
6076 + die("Unable to allocate %d program headers\n",
6079 + if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
6080 + die("Seek to %d failed: %s\n",
6081 + ehdr.e_phoff, strerror(errno));
6083 + if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
6084 + die("Cannot read ELF program headers: %s\n",
6087 + for(i = 0; i < ehdr.e_phnum; i++) {
6088 + phdr[i].p_type = elf32_to_cpu(phdr[i].p_type);
6089 + phdr[i].p_offset = elf32_to_cpu(phdr[i].p_offset);
6090 + phdr[i].p_vaddr = elf32_to_cpu(phdr[i].p_vaddr);
6091 + phdr[i].p_paddr = elf32_to_cpu(phdr[i].p_paddr);
6092 + phdr[i].p_filesz = elf32_to_cpu(phdr[i].p_filesz);
6093 + phdr[i].p_memsz = elf32_to_cpu(phdr[i].p_memsz);
6094 + phdr[i].p_flags = elf32_to_cpu(phdr[i].p_flags);
6095 + phdr[i].p_align = elf32_to_cpu(phdr[i].p_align);
6100 static void read_shdrs(FILE *fp)
6106 secs = calloc(ehdr.e_shnum, sizeof(struct section));
6107 @@ -307,7 +340,7 @@ static void read_shdrs(FILE *fp)
6109 static void read_strtabs(FILE *fp)
6113 for (i = 0; i < ehdr.e_shnum; i++) {
6114 struct section *sec = &secs[i];
6115 if (sec->shdr.sh_type != SHT_STRTAB) {
6116 @@ -332,7 +365,7 @@ static void read_strtabs(FILE *fp)
6118 static void read_symtabs(FILE *fp)
6122 for (i = 0; i < ehdr.e_shnum; i++) {
6123 struct section *sec = &secs[i];
6124 if (sec->shdr.sh_type != SHT_SYMTAB) {
6125 @@ -365,7 +398,9 @@ static void read_symtabs(FILE *fp)
6127 static void read_relocs(FILE *fp)
6133 for (i = 0; i < ehdr.e_shnum; i++) {
6134 struct section *sec = &secs[i];
6135 if (sec->shdr.sh_type != SHT_REL) {
6136 @@ -385,9 +420,18 @@ static void read_relocs(FILE *fp)
6137 die("Cannot read symbol table: %s\n",
6141 + for (j = 0; j < ehdr.e_phnum; j++) {
6142 + if (phdr[j].p_type != PT_LOAD )
6144 + 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)
6146 + base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
6149 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Rel); j++) {
6150 Elf32_Rel *rel = &sec->reltab[j];
6151 - rel->r_offset = elf32_to_cpu(rel->r_offset);
6152 + rel->r_offset = elf32_to_cpu(rel->r_offset) + base;
6153 rel->r_info = elf32_to_cpu(rel->r_info);
6156 @@ -396,14 +440,14 @@ static void read_relocs(FILE *fp)
6158 static void print_absolute_symbols(void)
6162 printf("Absolute symbols\n");
6163 printf(" Num: Value Size Type Bind Visibility Name\n");
6164 for (i = 0; i < ehdr.e_shnum; i++) {
6165 struct section *sec = &secs[i];
6167 Elf32_Sym *sh_symtab;
6171 if (sec->shdr.sh_type != SHT_SYMTAB) {
6173 @@ -431,14 +475,14 @@ static void print_absolute_symbols(void)
6175 static void print_absolute_relocs(void)
6177 - int i, printed = 0;
6178 + unsigned int i, printed = 0;
6180 for (i = 0; i < ehdr.e_shnum; i++) {
6181 struct section *sec = &secs[i];
6182 struct section *sec_applies, *sec_symtab;
6184 Elf32_Sym *sh_symtab;
6187 if (sec->shdr.sh_type != SHT_REL) {
6190 @@ -499,13 +543,13 @@ static void print_absolute_relocs(void)
6192 static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym))
6196 /* Walk through the relocations */
6197 for (i = 0; i < ehdr.e_shnum; i++) {
6199 Elf32_Sym *sh_symtab;
6200 struct section *sec_applies, *sec_symtab;
6203 struct section *sec = &secs[i];
6205 if (sec->shdr.sh_type != SHT_REL) {
6206 @@ -530,6 +574,22 @@ static void walk_relocs(void (*visit)(El
6207 !is_rel_reloc(sym_name(sym_strtab, sym))) {
6210 + /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
6211 + if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
6214 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
6215 + /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
6216 + if (!strcmp(sec_name(sym->st_shndx), ".module.text") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
6218 + if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
6220 + if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
6222 + if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
6229 @@ -571,7 +631,7 @@ static int cmp_relocs(const void *va, co
6231 static void emit_relocs(int as_text)
6235 /* Count how many relocations I have and allocate space for them. */
6237 walk_relocs(count_reloc);
6238 @@ -665,6 +725,7 @@ int main(int argc, char **argv)
6239 fname, strerror(errno));
6246 diff -urNp linux-2.6.37/arch/x86/boot/cpucheck.c linux-2.6.37/arch/x86/boot/cpucheck.c
6247 --- linux-2.6.37/arch/x86/boot/cpucheck.c 2011-01-04 19:50:19.000000000 -0500
6248 +++ linux-2.6.37/arch/x86/boot/cpucheck.c 2011-01-17 02:41:00.000000000 -0500
6249 @@ -74,7 +74,7 @@ static int has_fpu(void)
6250 u16 fcw = -1, fsw = -1;
6253 - asm("movl %%cr0,%0" : "=r" (cr0));
6254 + asm volatile("movl %%cr0,%0" : "=r" (cr0));
6255 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
6256 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
6257 asm volatile("movl %0,%%cr0" : : "r" (cr0));
6258 @@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
6263 + asm volatile("pushfl ; "
6267 @@ -115,7 +115,7 @@ static void get_flags(void)
6268 set_bit(X86_FEATURE_FPU, cpu.flags);
6270 if (has_eflag(X86_EFLAGS_ID)) {
6272 + asm volatile("cpuid"
6273 : "=a" (max_intel_level),
6274 "=b" (cpu_vendor[0]),
6275 "=d" (cpu_vendor[1]),
6276 @@ -124,7 +124,7 @@ static void get_flags(void)
6278 if (max_intel_level >= 0x00000001 &&
6279 max_intel_level <= 0x0000ffff) {
6281 + asm volatile("cpuid"
6283 "=c" (cpu.flags[4]),
6285 @@ -136,7 +136,7 @@ static void get_flags(void)
6286 cpu.model += ((tfms >> 16) & 0xf) << 4;
6290 + asm volatile("cpuid"
6291 : "=a" (max_amd_level)
6293 : "ebx", "ecx", "edx");
6294 @@ -144,7 +144,7 @@ static void get_flags(void)
6295 if (max_amd_level >= 0x80000001 &&
6296 max_amd_level <= 0x8000ffff) {
6297 u32 eax = 0x80000001;
6299 + asm volatile("cpuid"
6301 "=c" (cpu.flags[6]),
6303 @@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *r
6304 u32 ecx = MSR_K7_HWCR;
6307 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
6308 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
6310 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
6311 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
6313 get_flags(); /* Make sure it really did something */
6314 err = check_flags();
6315 @@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *r
6316 u32 ecx = MSR_VIA_FCR;
6319 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
6320 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
6321 eax |= (1<<1)|(1<<7);
6322 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
6323 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
6325 set_bit(X86_FEATURE_CX8, cpu.flags);
6326 err = check_flags();
6327 @@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *r
6331 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
6332 - asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
6334 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
6335 + asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
6336 + asm volatile("cpuid"
6337 : "+a" (level), "=d" (cpu.flags[0])
6339 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
6340 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
6342 err = check_flags();
6344 diff -urNp linux-2.6.37/arch/x86/boot/header.S linux-2.6.37/arch/x86/boot/header.S
6345 --- linux-2.6.37/arch/x86/boot/header.S 2011-01-04 19:50:19.000000000 -0500
6346 +++ linux-2.6.37/arch/x86/boot/header.S 2011-01-17 02:41:00.000000000 -0500
6347 @@ -224,7 +224,7 @@ setup_data: .quad 0 # 64-bit physical
6348 # single linked list of
6351 -pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
6352 +pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
6354 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
6355 #define VO_INIT_SIZE (VO__end - VO__text)
6356 diff -urNp linux-2.6.37/arch/x86/boot/memory.c linux-2.6.37/arch/x86/boot/memory.c
6357 --- linux-2.6.37/arch/x86/boot/memory.c 2011-01-04 19:50:19.000000000 -0500
6358 +++ linux-2.6.37/arch/x86/boot/memory.c 2011-01-17 02:41:00.000000000 -0500
6361 static int detect_memory_e820(void)
6364 + unsigned int count = 0;
6365 struct biosregs ireg, oreg;
6366 struct e820entry *desc = boot_params.e820_map;
6367 static struct e820entry buf; /* static so it is zeroed */
6368 diff -urNp linux-2.6.37/arch/x86/boot/video.c linux-2.6.37/arch/x86/boot/video.c
6369 --- linux-2.6.37/arch/x86/boot/video.c 2011-01-04 19:50:19.000000000 -0500
6370 +++ linux-2.6.37/arch/x86/boot/video.c 2011-01-17 02:41:00.000000000 -0500
6371 @@ -96,7 +96,7 @@ static void store_mode_params(void)
6372 static unsigned int get_entry(void)
6376 + unsigned int i, len = 0;
6380 diff -urNp linux-2.6.37/arch/x86/boot/video-vesa.c linux-2.6.37/arch/x86/boot/video-vesa.c
6381 --- linux-2.6.37/arch/x86/boot/video-vesa.c 2011-01-04 19:50:19.000000000 -0500
6382 +++ linux-2.6.37/arch/x86/boot/video-vesa.c 2011-01-17 02:41:00.000000000 -0500
6383 @@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
6385 boot_params.screen_info.vesapm_seg = oreg.es;
6386 boot_params.screen_info.vesapm_off = oreg.di;
6387 + boot_params.screen_info.vesapm_size = oreg.cx;
6391 diff -urNp linux-2.6.37/arch/x86/ia32/ia32_aout.c linux-2.6.37/arch/x86/ia32/ia32_aout.c
6392 --- linux-2.6.37/arch/x86/ia32/ia32_aout.c 2011-01-04 19:50:19.000000000 -0500
6393 +++ linux-2.6.37/arch/x86/ia32/ia32_aout.c 2011-01-17 02:41:00.000000000 -0500
6394 @@ -162,6 +162,8 @@ static int aout_core_dump(long signr, st
6395 unsigned long dump_start, dump_size;
6398 + memset(&dump, 0, sizeof(dump));
6403 diff -urNp linux-2.6.37/arch/x86/ia32/ia32entry.S linux-2.6.37/arch/x86/ia32/ia32entry.S
6404 --- linux-2.6.37/arch/x86/ia32/ia32entry.S 2011-01-04 19:50:19.000000000 -0500
6405 +++ linux-2.6.37/arch/x86/ia32/ia32entry.S 2011-01-17 02:41:00.000000000 -0500
6407 #include <asm/thread_info.h>
6408 #include <asm/segment.h>
6409 #include <asm/irqflags.h>
6410 +#include <asm/pgtable.h>
6411 #include <linux/linkage.h>
6413 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
6414 @@ -120,6 +121,11 @@ ENTRY(ia32_sysenter_target)
6416 movq PER_CPU_VAR(kernel_stack), %rsp
6417 addq $(KERNEL_STACK_OFFSET),%rsp
6419 +#ifdef CONFIG_PAX_MEMORY_UDEREF
6420 + call pax_enter_kernel_user
6424 * No need to follow this irqs on/off section: the syscall
6425 * disabled irqs, here we enable it straight after entry:
6426 @@ -150,6 +156,12 @@ ENTRY(ia32_sysenter_target)
6428 /* no need to do an access_ok check here because rbp has been
6429 32bit zero extended */
6431 +#ifdef CONFIG_PAX_MEMORY_UDEREF
6432 + mov $PAX_USER_SHADOW_BASE,%r10
6437 .section __ex_table,"a"
6438 .quad 1b,ia32_badarg
6439 @@ -172,6 +184,11 @@ sysenter_dispatch:
6440 testl $_TIF_ALLWORK_MASK,TI_flags(%r10)
6442 sysexit_from_sys_call:
6444 +#ifdef CONFIG_PAX_MEMORY_UDEREF
6445 + call pax_exit_kernel_user
6448 andl $~TS_COMPAT,TI_status(%r10)
6449 /* clear IF, that popfq doesn't enable interrupts early */
6450 andl $~0x200,EFLAGS-R11(%rsp)
6451 @@ -290,6 +307,11 @@ ENTRY(ia32_cstar_target)
6454 movq PER_CPU_VAR(kernel_stack),%rsp
6456 +#ifdef CONFIG_PAX_MEMORY_UDEREF
6457 + call pax_enter_kernel_user
6461 * No need to follow this irqs on/off section: the syscall
6462 * disabled irqs and here we enable it straight after entry:
6463 @@ -311,6 +333,12 @@ ENTRY(ia32_cstar_target)
6464 /* no need to do an access_ok check here because r8 has been
6465 32bit zero extended */
6466 /* hardware stack frame is complete now */
6468 +#ifdef CONFIG_PAX_MEMORY_UDEREF
6469 + mov $PAX_USER_SHADOW_BASE,%r10
6474 .section __ex_table,"a"
6475 .quad 1b,ia32_badarg
6476 @@ -333,6 +361,11 @@ cstar_dispatch:
6477 testl $_TIF_ALLWORK_MASK,TI_flags(%r10)
6479 sysretl_from_sys_call:
6481 +#ifdef CONFIG_PAX_MEMORY_UDEREF
6482 + call pax_exit_kernel_user
6485 andl $~TS_COMPAT,TI_status(%r10)
6486 RESTORE_ARGS 1,-ARG_SKIP,1,1,1
6487 movl RIP-ARGOFFSET(%rsp),%ecx
6488 @@ -415,6 +448,11 @@ ENTRY(ia32_syscall)
6489 CFI_REL_OFFSET rip,RIP-RIP
6490 PARAVIRT_ADJUST_EXCEPTION_FRAME
6493 +#ifdef CONFIG_PAX_MEMORY_UDEREF
6494 + call pax_enter_kernel_user
6498 * No need to follow this irqs on/off section: the syscall
6499 * disabled irqs and here we enable it straight after entry:
6500 diff -urNp linux-2.6.37/arch/x86/ia32/ia32_signal.c linux-2.6.37/arch/x86/ia32/ia32_signal.c
6501 --- linux-2.6.37/arch/x86/ia32/ia32_signal.c 2011-01-04 19:50:19.000000000 -0500
6502 +++ linux-2.6.37/arch/x86/ia32/ia32_signal.c 2011-01-17 02:41:00.000000000 -0500
6503 @@ -403,7 +403,7 @@ static void __user *get_sigframe(struct
6505 /* Align the stack pointer according to the i386 ABI,
6506 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
6507 - sp = ((sp + 4) & -16ul) - 4;
6508 + sp = ((sp - 12) & -16ul) - 4;
6509 return (void __user *) sp;
6512 @@ -461,7 +461,7 @@ int ia32_setup_frame(int sig, struct k_s
6513 * These are actually not used anymore, but left because some
6514 * gdb versions depend on them as a marker.
6516 - put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
6517 + put_user_ex(*((const u64 *)&code), (u64 *)frame->retcode);
6518 } put_user_catch(err);
6521 @@ -503,7 +503,7 @@ int ia32_setup_rt_frame(int sig, struct
6523 __NR_ia32_rt_sigreturn,
6529 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
6530 @@ -533,16 +533,18 @@ int ia32_setup_rt_frame(int sig, struct
6532 if (ka->sa.sa_flags & SA_RESTORER)
6533 restorer = ka->sa.sa_restorer;
6534 + else if (current->mm->context.vdso)
6535 + /* Return stub is in 32bit vsyscall page */
6536 + restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
6538 - restorer = VDSO32_SYMBOL(current->mm->context.vdso,
6540 + restorer = &frame->retcode;
6541 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
6544 * Not actually used anymore, but left because some gdb
6547 - put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
6548 + put_user_ex(*((const u64 *)&code), (u64 *)frame->retcode);
6549 } put_user_catch(err);
6552 diff -urNp linux-2.6.37/arch/x86/include/asm/alternative.h linux-2.6.37/arch/x86/include/asm/alternative.h
6553 --- linux-2.6.37/arch/x86/include/asm/alternative.h 2011-01-04 19:50:19.000000000 -0500
6554 +++ linux-2.6.37/arch/x86/include/asm/alternative.h 2011-01-17 02:41:00.000000000 -0500
6555 @@ -93,7 +93,7 @@ static inline int alternatives_text_rese
6556 ".section .discard,\"aw\",@progbits\n" \
6557 " .byte 0xff + (664f-663f) - (662b-661b)\n" /* rlen <= slen */ \
6559 - ".section .altinstr_replacement, \"ax\"\n" \
6560 + ".section .altinstr_replacement, \"a\"\n" \
6561 "663:\n\t" newinstr "\n664:\n" /* replacement */ \
6564 diff -urNp linux-2.6.37/arch/x86/include/asm/apm.h linux-2.6.37/arch/x86/include/asm/apm.h
6565 --- linux-2.6.37/arch/x86/include/asm/apm.h 2011-01-04 19:50:19.000000000 -0500
6566 +++ linux-2.6.37/arch/x86/include/asm/apm.h 2011-01-17 02:41:00.000000000 -0500
6567 @@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32
6568 __asm__ __volatile__(APM_DO_ZERO_SEGS
6571 - "lcall *%%cs:apm_bios_entry\n\t"
6572 + "lcall *%%ss:apm_bios_entry\n\t"
6576 @@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_as
6577 __asm__ __volatile__(APM_DO_ZERO_SEGS
6580 - "lcall *%%cs:apm_bios_entry\n\t"
6581 + "lcall *%%ss:apm_bios_entry\n\t"
6585 diff -urNp linux-2.6.37/arch/x86/include/asm/atomic64_32.h linux-2.6.37/arch/x86/include/asm/atomic64_32.h
6586 --- linux-2.6.37/arch/x86/include/asm/atomic64_32.h 2011-01-04 19:50:19.000000000 -0500
6587 +++ linux-2.6.37/arch/x86/include/asm/atomic64_32.h 2011-01-17 02:41:00.000000000 -0500
6588 @@ -12,6 +12,14 @@ typedef struct {
6589 u64 __aligned(8) counter;
6592 +#ifdef CONFIG_PAX_REFCOUNT
6594 + u64 __aligned(8) counter;
6595 +} atomic64_unchecked_t;
6597 +typedef atomic64_t atomic64_unchecked_t;
6600 #define ATOMIC64_INIT(val) { (val) }
6602 #ifdef CONFIG_X86_CMPXCHG64
6603 diff -urNp linux-2.6.37/arch/x86/include/asm/atomic64_64.h linux-2.6.37/arch/x86/include/asm/atomic64_64.h
6604 --- linux-2.6.37/arch/x86/include/asm/atomic64_64.h 2011-01-04 19:50:19.000000000 -0500
6605 +++ linux-2.6.37/arch/x86/include/asm/atomic64_64.h 2011-01-17 02:41:00.000000000 -0500
6608 static inline long atomic64_read(const atomic64_t *v)
6610 - return (*(volatile long *)&(v)->counter);
6611 + return (*(volatile const long *)&(v)->counter);
6615 + * atomic64_read_unchecked - read atomic64 variable
6616 + * @v: pointer of type atomic64_unchecked_t
6618 + * Atomically reads the value of @v.
6619 + * Doesn't imply a read memory barrier.
6621 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
6623 + return (*(volatile const long *)&(v)->counter);
6627 @@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64
6631 + * atomic64_set_unchecked - set atomic64 variable
6632 + * @v: pointer to type atomic64_unchecked_t
6633 + * @i: required value
6635 + * Atomically sets the value of @v to @i.
6637 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
6643 * atomic64_add - add integer to atomic64 variable
6644 * @i: integer value to add
6645 * @v: pointer to type atomic64_t
6646 @@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64
6648 static inline void atomic64_add(long i, atomic64_t *v)
6650 + asm volatile(LOCK_PREFIX "addq %1,%0\n"
6652 +#ifdef CONFIG_PAX_REFCOUNT
6654 + LOCK_PREFIX "subq %1,%0\n"
6656 + _ASM_EXTABLE(0b, 0b)
6659 + : "=m" (v->counter)
6660 + : "er" (i), "m" (v->counter));
6664 + * atomic64_add_unchecked - add integer to atomic64 variable
6665 + * @i: integer value to add
6666 + * @v: pointer to type atomic64_unchecked_t
6668 + * Atomically adds @i to @v.
6670 +static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
6672 asm volatile(LOCK_PREFIX "addq %1,%0"
6674 : "er" (i), "m" (v->counter));
6675 @@ -56,7 +102,29 @@ static inline void atomic64_add(long i,
6677 static inline void atomic64_sub(long i, atomic64_t *v)
6679 - asm volatile(LOCK_PREFIX "subq %1,%0"
6680 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
6682 +#ifdef CONFIG_PAX_REFCOUNT
6684 + LOCK_PREFIX "addq %1,%0\n"
6686 + _ASM_EXTABLE(0b, 0b)
6689 + : "=m" (v->counter)
6690 + : "er" (i), "m" (v->counter));
6694 + * atomic64_sub_unchecked - subtract the atomic64 variable
6695 + * @i: integer value to subtract
6696 + * @v: pointer to type atomic64_unchecked_t
6698 + * Atomically subtracts @i from @v.
6700 +static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
6702 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
6704 : "er" (i), "m" (v->counter));
6706 @@ -74,7 +142,16 @@ static inline int atomic64_sub_and_test(
6710 - asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
6711 + asm volatile(LOCK_PREFIX "subq %2,%0\n"
6713 +#ifdef CONFIG_PAX_REFCOUNT
6715 + LOCK_PREFIX "addq %2,%0\n"
6717 + _ASM_EXTABLE(0b, 0b)
6721 : "=m" (v->counter), "=qm" (c)
6722 : "er" (i), "m" (v->counter) : "memory");
6724 @@ -88,6 +165,27 @@ static inline int atomic64_sub_and_test(
6726 static inline void atomic64_inc(atomic64_t *v)
6728 + asm volatile(LOCK_PREFIX "incq %0\n"
6730 +#ifdef CONFIG_PAX_REFCOUNT
6732 + LOCK_PREFIX "decq %0\n"
6734 + _ASM_EXTABLE(0b, 0b)
6737 + : "=m" (v->counter)
6738 + : "m" (v->counter));
6742 + * atomic64_inc_unchecked - increment atomic64 variable
6743 + * @v: pointer to type atomic64_unchecked_t
6745 + * Atomically increments @v by 1.
6747 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
6749 asm volatile(LOCK_PREFIX "incq %0"
6751 : "m" (v->counter));
6752 @@ -101,7 +199,28 @@ static inline void atomic64_inc(atomic64
6754 static inline void atomic64_dec(atomic64_t *v)
6756 - asm volatile(LOCK_PREFIX "decq %0"
6757 + asm volatile(LOCK_PREFIX "decq %0\n"
6759 +#ifdef CONFIG_PAX_REFCOUNT
6761 + LOCK_PREFIX "incq %0\n"
6763 + _ASM_EXTABLE(0b, 0b)
6766 + : "=m" (v->counter)
6767 + : "m" (v->counter));
6771 + * atomic64_dec_unchecked - decrement atomic64 variable
6772 + * @v: pointer to type atomic64_t
6774 + * Atomically decrements @v by 1.
6776 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
6778 + asm volatile(LOCK_PREFIX "decq %0\n"
6780 : "m" (v->counter));
6782 @@ -118,7 +237,16 @@ static inline int atomic64_dec_and_test(
6786 - asm volatile(LOCK_PREFIX "decq %0; sete %1"
6787 + asm volatile(LOCK_PREFIX "decq %0\n"
6789 +#ifdef CONFIG_PAX_REFCOUNT
6791 + LOCK_PREFIX "incq %0\n"
6793 + _ASM_EXTABLE(0b, 0b)
6797 : "=m" (v->counter), "=qm" (c)
6798 : "m" (v->counter) : "memory");
6800 @@ -136,7 +264,16 @@ static inline int atomic64_inc_and_test(
6804 - asm volatile(LOCK_PREFIX "incq %0; sete %1"
6805 + asm volatile(LOCK_PREFIX "incq %0\n"
6807 +#ifdef CONFIG_PAX_REFCOUNT
6809 + LOCK_PREFIX "decq %0\n"
6811 + _ASM_EXTABLE(0b, 0b)
6815 : "=m" (v->counter), "=qm" (c)
6816 : "m" (v->counter) : "memory");
6818 @@ -155,7 +292,16 @@ static inline int atomic64_add_negative(
6822 - asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
6823 + asm volatile(LOCK_PREFIX "addq %2,%0\n"
6825 +#ifdef CONFIG_PAX_REFCOUNT
6827 + LOCK_PREFIX "subq %2,%0\n"
6829 + _ASM_EXTABLE(0b, 0b)
6833 : "=m" (v->counter), "=qm" (c)
6834 : "er" (i), "m" (v->counter) : "memory");
6836 @@ -171,7 +317,31 @@ static inline int atomic64_add_negative(
6837 static inline long atomic64_add_return(long i, atomic64_t *v)
6840 - asm volatile(LOCK_PREFIX "xaddq %0, %1;"
6841 + asm volatile(LOCK_PREFIX "xaddq %0, %1\n"
6843 +#ifdef CONFIG_PAX_REFCOUNT
6847 + _ASM_EXTABLE(0b, 0b)
6850 + : "+r" (i), "+m" (v->counter)
6856 + * atomic64_add_return_unchecked - add and return
6857 + * @i: integer value to add
6858 + * @v: pointer to type atomic64_unchecked_t
6860 + * Atomically adds @i to @v and returns @i + @v
6862 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
6865 + asm volatile(LOCK_PREFIX "xaddq %0, %1"
6866 : "+r" (i), "+m" (v->counter)
6869 @@ -183,6 +353,10 @@ static inline long atomic64_sub_return(l
6872 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
6873 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
6875 + return atomic64_add_return_unchecked(1, v);
6877 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
6879 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
6880 @@ -206,17 +380,30 @@ static inline long atomic64_xchg(atomic6
6882 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
6886 c = atomic64_read(v);
6888 - if (unlikely(c == (u)))
6889 + if (unlikely(c == u))
6891 - old = atomic64_cmpxchg((v), c, c + (a));
6893 + asm volatile("add %2,%0\n"
6895 +#ifdef CONFIG_PAX_REFCOUNT
6899 + _ASM_EXTABLE(0b, 0b)
6903 + : "0" (c), "ir" (a));
6905 + old = atomic64_cmpxchg(v, c, new);
6906 if (likely(old == c))
6914 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
6915 diff -urNp linux-2.6.37/arch/x86/include/asm/atomic.h linux-2.6.37/arch/x86/include/asm/atomic.h
6916 --- linux-2.6.37/arch/x86/include/asm/atomic.h 2011-01-04 19:50:19.000000000 -0500
6917 +++ linux-2.6.37/arch/x86/include/asm/atomic.h 2011-01-17 02:41:00.000000000 -0500
6920 static inline int atomic_read(const atomic_t *v)
6922 - return (*(volatile int *)&(v)->counter);
6923 + return (*(volatile const int *)&(v)->counter);
6927 + * atomic_read_unchecked - read atomic variable
6928 + * @v: pointer of type atomic_unchecked_t
6930 + * Atomically reads the value of @v.
6932 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
6934 + return (*(volatile const int *)&(v)->counter);
6938 @@ -38,6 +49,18 @@ static inline void atomic_set(atomic_t *
6942 + * atomic_set_unchecked - set atomic variable
6943 + * @v: pointer of type atomic_unchecked_t
6944 + * @i: required value
6946 + * Atomically sets the value of @v to @i.
6948 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
6954 * atomic_add - add integer to atomic variable
6955 * @i: integer value to add
6956 * @v: pointer of type atomic_t
6957 @@ -46,7 +69,29 @@ static inline void atomic_set(atomic_t *
6959 static inline void atomic_add(int i, atomic_t *v)
6961 - asm volatile(LOCK_PREFIX "addl %1,%0"
6962 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
6964 +#ifdef CONFIG_PAX_REFCOUNT
6966 + LOCK_PREFIX "subl %1,%0\n"
6968 + _ASM_EXTABLE(0b, 0b)
6971 + : "+m" (v->counter)
6976 + * atomic_add_unchecked - add integer to atomic variable
6977 + * @i: integer value to add
6978 + * @v: pointer of type atomic_unchecked_t
6980 + * Atomically adds @i to @v.
6982 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
6984 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
6988 @@ -60,7 +105,29 @@ static inline void atomic_add(int i, ato
6990 static inline void atomic_sub(int i, atomic_t *v)
6992 - asm volatile(LOCK_PREFIX "subl %1,%0"
6993 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
6995 +#ifdef CONFIG_PAX_REFCOUNT
6997 + LOCK_PREFIX "addl %1,%0\n"
6999 + _ASM_EXTABLE(0b, 0b)
7002 + : "+m" (v->counter)
7007 + * atomic_sub_unchecked - subtract integer from atomic variable
7008 + * @i: integer value to subtract
7009 + * @v: pointer of type atomic_t
7011 + * Atomically subtracts @i from @v.
7013 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
7015 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
7019 @@ -78,7 +145,16 @@ static inline int atomic_sub_and_test(in
7023 - asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
7024 + asm volatile(LOCK_PREFIX "subl %2,%0\n"
7026 +#ifdef CONFIG_PAX_REFCOUNT
7028 + LOCK_PREFIX "addl %2,%0\n"
7030 + _ASM_EXTABLE(0b, 0b)
7034 : "+m" (v->counter), "=qm" (c)
7035 : "ir" (i) : "memory");
7037 @@ -92,7 +168,27 @@ static inline int atomic_sub_and_test(in
7039 static inline void atomic_inc(atomic_t *v)
7041 - asm volatile(LOCK_PREFIX "incl %0"
7042 + asm volatile(LOCK_PREFIX "incl %0\n"
7044 +#ifdef CONFIG_PAX_REFCOUNT
7046 + LOCK_PREFIX "decl %0\n"
7048 + _ASM_EXTABLE(0b, 0b)
7051 + : "+m" (v->counter));
7055 + * atomic_inc_unchecked - increment atomic variable
7056 + * @v: pointer of type atomic_unchecked_t
7058 + * Atomically increments @v by 1.
7060 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
7062 + asm volatile(LOCK_PREFIX "incl %0\n"
7063 : "+m" (v->counter));
7066 @@ -104,7 +200,27 @@ static inline void atomic_inc(atomic_t *
7068 static inline void atomic_dec(atomic_t *v)
7070 - asm volatile(LOCK_PREFIX "decl %0"
7071 + asm volatile(LOCK_PREFIX "decl %0\n"
7073 +#ifdef CONFIG_PAX_REFCOUNT
7075 + LOCK_PREFIX "incl %0\n"
7077 + _ASM_EXTABLE(0b, 0b)
7080 + : "+m" (v->counter));
7084 + * atomic_dec_unchecked - decrement atomic variable
7085 + * @v: pointer of type atomic_t
7087 + * Atomically decrements @v by 1.
7089 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
7091 + asm volatile(LOCK_PREFIX "decl %0\n"
7092 : "+m" (v->counter));
7095 @@ -120,7 +236,16 @@ static inline int atomic_dec_and_test(at
7099 - asm volatile(LOCK_PREFIX "decl %0; sete %1"
7100 + asm volatile(LOCK_PREFIX "decl %0\n"
7102 +#ifdef CONFIG_PAX_REFCOUNT
7104 + LOCK_PREFIX "incl %0\n"
7106 + _ASM_EXTABLE(0b, 0b)
7110 : "+m" (v->counter), "=qm" (c)
7113 @@ -138,7 +263,16 @@ static inline int atomic_inc_and_test(at
7117 - asm volatile(LOCK_PREFIX "incl %0; sete %1"
7118 + asm volatile(LOCK_PREFIX "incl %0\n"
7120 +#ifdef CONFIG_PAX_REFCOUNT
7122 + LOCK_PREFIX "decl %0\n"
7124 + _ASM_EXTABLE(0b, 0b)
7128 : "+m" (v->counter), "=qm" (c)
7131 @@ -157,7 +291,16 @@ static inline int atomic_add_negative(in
7135 - asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
7136 + asm volatile(LOCK_PREFIX "addl %2,%0\n"
7138 +#ifdef CONFIG_PAX_REFCOUNT
7140 + LOCK_PREFIX "subl %2,%0\n"
7142 + _ASM_EXTABLE(0b, 0b)
7146 : "+m" (v->counter), "=qm" (c)
7147 : "ir" (i) : "memory");
7149 @@ -180,6 +323,46 @@ static inline int atomic_add_return(int
7151 /* Modern 486+ processor */
7153 + asm volatile(LOCK_PREFIX "xaddl %0, %1\n"
7155 +#ifdef CONFIG_PAX_REFCOUNT
7159 + _ASM_EXTABLE(0b, 0b)
7162 + : "+r" (i), "+m" (v->counter)
7167 +no_xadd: /* Legacy 386 processor */
7168 + local_irq_save(flags);
7169 + __i = atomic_read(v);
7170 + atomic_set(v, i + __i);
7171 + local_irq_restore(flags);
7177 + * atomic_add_return_unchecked - add integer and return
7178 + * @v: pointer of type atomic_unchecked_t
7179 + * @i: integer value to add
7181 + * Atomically adds @i to @v and returns @i + @v
7183 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
7187 + unsigned long flags;
7188 + if (unlikely(boot_cpu_data.x86 <= 3))
7191 + /* Modern 486+ processor */
7193 asm volatile(LOCK_PREFIX "xaddl %0, %1"
7194 : "+r" (i), "+m" (v->counter)
7196 @@ -208,6 +391,10 @@ static inline int atomic_sub_return(int
7199 #define atomic_inc_return(v) (atomic_add_return(1, v))
7200 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
7202 + return atomic_add_return_unchecked(1, v);
7204 #define atomic_dec_return(v) (atomic_sub_return(1, v))
7206 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
7207 @@ -231,17 +418,30 @@ static inline int atomic_xchg(atomic_t *
7209 static inline int atomic_add_unless(atomic_t *v, int a, int u)
7215 - if (unlikely(c == (u)))
7216 + if (unlikely(c == u))
7218 - old = atomic_cmpxchg((v), c, c + (a));
7220 + asm volatile("addl %2,%0\n"
7222 +#ifdef CONFIG_PAX_REFCOUNT
7226 + _ASM_EXTABLE(0b, 0b)
7230 + : "0" (c), "ir" (a));
7232 + old = atomic_cmpxchg(v, c, new);
7233 if (likely(old == c))
7241 #define atomic_inc_not_zero(v) atomic_add_unless((v), 1, 0)
7242 diff -urNp linux-2.6.37/arch/x86/include/asm/bitops.h linux-2.6.37/arch/x86/include/asm/bitops.h
7243 --- linux-2.6.37/arch/x86/include/asm/bitops.h 2011-01-04 19:50:19.000000000 -0500
7244 +++ linux-2.6.37/arch/x86/include/asm/bitops.h 2011-01-17 02:41:00.000000000 -0500
7246 * a mask operation on a byte.
7248 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
7249 -#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
7250 +#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
7251 #define CONST_MASK(nr) (1 << ((nr) & 7))
7254 diff -urNp linux-2.6.37/arch/x86/include/asm/boot.h linux-2.6.37/arch/x86/include/asm/boot.h
7255 --- linux-2.6.37/arch/x86/include/asm/boot.h 2011-01-04 19:50:19.000000000 -0500
7256 +++ linux-2.6.37/arch/x86/include/asm/boot.h 2011-01-17 02:41:00.000000000 -0500
7258 #include <asm/pgtable_types.h>
7260 /* Physical address where kernel should be loaded. */
7261 -#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
7262 +#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
7263 + (CONFIG_PHYSICAL_ALIGN - 1)) \
7264 & ~(CONFIG_PHYSICAL_ALIGN - 1))
7266 +#ifndef __ASSEMBLY__
7267 +extern unsigned char __LOAD_PHYSICAL_ADDR[];
7268 +#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
7271 /* Minimum kernel alignment, as a power of two */
7272 #ifdef CONFIG_X86_64
7273 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
7274 diff -urNp linux-2.6.37/arch/x86/include/asm/cacheflush.h linux-2.6.37/arch/x86/include/asm/cacheflush.h
7275 --- linux-2.6.37/arch/x86/include/asm/cacheflush.h 2011-01-04 19:50:19.000000000 -0500
7276 +++ linux-2.6.37/arch/x86/include/asm/cacheflush.h 2011-01-17 02:41:00.000000000 -0500
7277 @@ -66,7 +66,7 @@ static inline unsigned long get_page_mem
7278 unsigned long pg_flags = pg->flags & _PGMT_MASK;
7280 if (pg_flags == _PGMT_DEFAULT)
7283 else if (pg_flags == _PGMT_WC)
7284 return _PAGE_CACHE_WC;
7285 else if (pg_flags == _PGMT_UC_MINUS)
7286 diff -urNp linux-2.6.37/arch/x86/include/asm/cache.h linux-2.6.37/arch/x86/include/asm/cache.h
7287 --- linux-2.6.37/arch/x86/include/asm/cache.h 2011-01-04 19:50:19.000000000 -0500
7288 +++ linux-2.6.37/arch/x86/include/asm/cache.h 2011-01-17 02:41:00.000000000 -0500
7290 #define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7292 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
7293 +#define __read_only __attribute__((__section__(".data..read_only")))
7295 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
7296 #define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
7297 diff -urNp linux-2.6.37/arch/x86/include/asm/checksum_32.h linux-2.6.37/arch/x86/include/asm/checksum_32.h
7298 --- linux-2.6.37/arch/x86/include/asm/checksum_32.h 2011-01-04 19:50:19.000000000 -0500
7299 +++ linux-2.6.37/arch/x86/include/asm/checksum_32.h 2011-01-17 02:41:00.000000000 -0500
7300 @@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_gene
7301 int len, __wsum sum,
7302 int *src_err_ptr, int *dst_err_ptr);
7304 +asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
7305 + int len, __wsum sum,
7306 + int *src_err_ptr, int *dst_err_ptr);
7308 +asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
7309 + int len, __wsum sum,
7310 + int *src_err_ptr, int *dst_err_ptr);
7313 * Note: when you get a NULL pointer exception here this means someone
7314 * passed in an incorrect kernel address to one of these functions.
7315 @@ -50,7 +58,7 @@ static inline __wsum csum_partial_copy_f
7319 - return csum_partial_copy_generic((__force void *)src, dst,
7320 + return csum_partial_copy_generic_from_user((__force void *)src, dst,
7321 len, sum, err_ptr, NULL);
7324 @@ -178,7 +186,7 @@ static inline __wsum csum_and_copy_to_us
7327 if (access_ok(VERIFY_WRITE, dst, len))
7328 - return csum_partial_copy_generic(src, (__force void *)dst,
7329 + return csum_partial_copy_generic_to_user(src, (__force void *)dst,
7330 len, sum, NULL, err_ptr);
7333 diff -urNp linux-2.6.37/arch/x86/include/asm/cpufeature.h linux-2.6.37/arch/x86/include/asm/cpufeature.h
7334 --- linux-2.6.37/arch/x86/include/asm/cpufeature.h 2011-01-04 19:50:19.000000000 -0500
7335 +++ linux-2.6.37/arch/x86/include/asm/cpufeature.h 2011-01-17 02:41:00.000000000 -0500
7336 @@ -349,7 +349,7 @@ static __always_inline __pure bool __sta
7337 ".section .discard,\"aw\",@progbits\n"
7338 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
7340 - ".section .altinstr_replacement,\"ax\"\n"
7341 + ".section .altinstr_replacement,\"a\"\n"
7345 diff -urNp linux-2.6.37/arch/x86/include/asm/desc.h linux-2.6.37/arch/x86/include/asm/desc.h
7346 --- linux-2.6.37/arch/x86/include/asm/desc.h 2011-01-04 19:50:19.000000000 -0500
7347 +++ linux-2.6.37/arch/x86/include/asm/desc.h 2011-01-17 02:41:00.000000000 -0500
7349 #include <asm/desc_defs.h>
7350 #include <asm/ldt.h>
7351 #include <asm/mmu.h>
7352 +#include <asm/pgtable.h>
7353 #include <linux/smp.h>
7355 static inline void fill_ldt(struct desc_struct *desc,
7356 @@ -15,6 +16,7 @@ static inline void fill_ldt(struct desc_
7357 desc->base1 = (info->base_addr & 0x00ff0000) >> 16;
7358 desc->type = (info->read_exec_only ^ 1) << 1;
7359 desc->type |= info->contents << 2;
7360 + desc->type |= info->seg_not_present ^ 1;
7363 desc->p = info->seg_not_present ^ 1;
7364 @@ -31,16 +33,12 @@ static inline void fill_ldt(struct desc_
7367 extern struct desc_ptr idt_descr;
7368 -extern gate_desc idt_table[];
7371 - struct desc_struct gdt[GDT_ENTRIES];
7372 -} __attribute__((aligned(PAGE_SIZE)));
7373 -DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
7374 +extern gate_desc idt_table[256];
7376 +extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
7377 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
7379 - return per_cpu(gdt_page, cpu).gdt;
7380 + return cpu_gdt_table[cpu];
7383 #ifdef CONFIG_X86_64
7384 @@ -115,19 +113,24 @@ static inline void paravirt_free_ldt(str
7385 static inline void native_write_idt_entry(gate_desc *idt, int entry,
7386 const gate_desc *gate)
7388 + pax_open_kernel();
7389 memcpy(&idt[entry], gate, sizeof(*gate));
7390 + pax_close_kernel();
7393 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry,
7396 + pax_open_kernel();
7397 memcpy(&ldt[entry], desc, 8);
7398 + pax_close_kernel();
7401 static inline void native_write_gdt_entry(struct desc_struct *gdt, int entry,
7402 const void *desc, int type)
7408 size = sizeof(tss_desc);
7409 @@ -139,7 +142,10 @@ static inline void native_write_gdt_entr
7410 size = sizeof(struct desc_struct);
7414 + pax_open_kernel();
7415 memcpy(&gdt[entry], desc, size);
7416 + pax_close_kernel();
7419 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
7420 @@ -211,7 +217,9 @@ static inline void native_set_ldt(const
7422 static inline void native_load_tr_desc(void)
7424 + pax_open_kernel();
7425 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
7426 + pax_close_kernel();
7429 static inline void native_load_gdt(const struct desc_ptr *dtr)
7430 @@ -246,8 +254,10 @@ static inline void native_load_tls(struc
7432 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
7434 + pax_open_kernel();
7435 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
7436 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
7437 + pax_close_kernel();
7440 #define _LDT_empty(info) \
7441 @@ -309,7 +319,7 @@ static inline void set_desc_limit(struct
7442 desc->limit = (limit >> 16) & 0xf;
7445 -static inline void _set_gate(int gate, unsigned type, void *addr,
7446 +static inline void _set_gate(int gate, unsigned type, const void *addr,
7447 unsigned dpl, unsigned ist, unsigned seg)
7450 @@ -327,7 +337,7 @@ static inline void _set_gate(int gate, u
7451 * Pentium F0 0F bugfix can have resulted in the mapped
7452 * IDT being write-protected.
7454 -static inline void set_intr_gate(unsigned int n, void *addr)
7455 +static inline void set_intr_gate(unsigned int n, const void *addr)
7457 BUG_ON((unsigned)n > 0xFF);
7458 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
7459 @@ -356,19 +366,19 @@ static inline void alloc_intr_gate(unsig
7461 * This routine sets up an interrupt gate at directory privilege level 3.
7463 -static inline void set_system_intr_gate(unsigned int n, void *addr)
7464 +static inline void set_system_intr_gate(unsigned int n, const void *addr)
7466 BUG_ON((unsigned)n > 0xFF);
7467 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
7470 -static inline void set_system_trap_gate(unsigned int n, void *addr)
7471 +static inline void set_system_trap_gate(unsigned int n, const void *addr)
7473 BUG_ON((unsigned)n > 0xFF);
7474 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
7477 -static inline void set_trap_gate(unsigned int n, void *addr)
7478 +static inline void set_trap_gate(unsigned int n, const void *addr)
7480 BUG_ON((unsigned)n > 0xFF);
7481 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
7482 @@ -377,19 +387,31 @@ static inline void set_trap_gate(unsigne
7483 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
7485 BUG_ON((unsigned)n > 0xFF);
7486 - _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
7487 + _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
7490 -static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
7491 +static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
7493 BUG_ON((unsigned)n > 0xFF);
7494 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
7497 -static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
7498 +static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
7500 BUG_ON((unsigned)n > 0xFF);
7501 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
7504 +#ifdef CONFIG_X86_32
7505 +static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
7507 + struct desc_struct d;
7509 + if (likely(limit))
7510 + limit = (limit - 1UL) >> PAGE_SHIFT;
7511 + pack_descriptor(&d, base, limit, 0xFB, 0xC);
7512 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
7516 #endif /* _ASM_X86_DESC_H */
7517 diff -urNp linux-2.6.37/arch/x86/include/asm/device.h linux-2.6.37/arch/x86/include/asm/device.h
7518 --- linux-2.6.37/arch/x86/include/asm/device.h 2011-01-04 19:50:19.000000000 -0500
7519 +++ linux-2.6.37/arch/x86/include/asm/device.h 2011-01-17 02:41:00.000000000 -0500
7520 @@ -6,7 +6,7 @@ struct dev_archdata {
7523 #ifdef CONFIG_X86_64
7524 -struct dma_map_ops *dma_ops;
7525 + const struct dma_map_ops *dma_ops;
7527 #if defined(CONFIG_DMAR) || defined(CONFIG_AMD_IOMMU)
7528 void *iommu; /* hook for IOMMU specific extension */
7529 diff -urNp linux-2.6.37/arch/x86/include/asm/dma-mapping.h linux-2.6.37/arch/x86/include/asm/dma-mapping.h
7530 --- linux-2.6.37/arch/x86/include/asm/dma-mapping.h 2011-01-04 19:50:19.000000000 -0500
7531 +++ linux-2.6.37/arch/x86/include/asm/dma-mapping.h 2011-01-17 02:41:00.000000000 -0500
7532 @@ -26,9 +26,9 @@ extern int iommu_merge;
7533 extern struct device x86_dma_fallback_dev;
7534 extern int panic_on_overflow;
7536 -extern struct dma_map_ops *dma_ops;
7537 +extern const struct dma_map_ops *dma_ops;
7539 -static inline struct dma_map_ops *get_dma_ops(struct device *dev)
7540 +static inline const struct dma_map_ops *get_dma_ops(struct device *dev)
7542 #ifdef CONFIG_X86_32
7544 @@ -45,7 +45,7 @@ static inline struct dma_map_ops *get_dm
7545 /* Make sure we keep the same behaviour */
7546 static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
7548 - struct dma_map_ops *ops = get_dma_ops(dev);
7549 + const struct dma_map_ops *ops = get_dma_ops(dev);
7550 if (ops->mapping_error)
7551 return ops->mapping_error(dev, dma_addr);
7553 @@ -115,7 +115,7 @@ static inline void *
7554 dma_alloc_coherent(struct device *dev, size_t size, dma_addr_t *dma_handle,
7557 - struct dma_map_ops *ops = get_dma_ops(dev);
7558 + const struct dma_map_ops *ops = get_dma_ops(dev);
7561 gfp &= ~(__GFP_DMA | __GFP_HIGHMEM | __GFP_DMA32);
7562 @@ -142,7 +142,7 @@ dma_alloc_coherent(struct device *dev, s
7563 static inline void dma_free_coherent(struct device *dev, size_t size,
7564 void *vaddr, dma_addr_t bus)
7566 - struct dma_map_ops *ops = get_dma_ops(dev);
7567 + const struct dma_map_ops *ops = get_dma_ops(dev);
7569 WARN_ON(irqs_disabled()); /* for portability */
7571 diff -urNp linux-2.6.37/arch/x86/include/asm/e820.h linux-2.6.37/arch/x86/include/asm/e820.h
7572 --- linux-2.6.37/arch/x86/include/asm/e820.h 2011-01-04 19:50:19.000000000 -0500
7573 +++ linux-2.6.37/arch/x86/include/asm/e820.h 2011-01-17 02:41:00.000000000 -0500
7574 @@ -69,7 +69,7 @@ struct e820map {
7575 #define ISA_START_ADDRESS 0xa0000
7576 #define ISA_END_ADDRESS 0x100000
7578 -#define BIOS_BEGIN 0x000a0000
7579 +#define BIOS_BEGIN 0x000c0000
7580 #define BIOS_END 0x00100000
7582 #define BIOS_ROM_BASE 0xffe00000
7583 diff -urNp linux-2.6.37/arch/x86/include/asm/elf.h linux-2.6.37/arch/x86/include/asm/elf.h
7584 --- linux-2.6.37/arch/x86/include/asm/elf.h 2011-01-04 19:50:19.000000000 -0500
7585 +++ linux-2.6.37/arch/x86/include/asm/elf.h 2011-01-17 02:41:00.000000000 -0500
7586 @@ -237,7 +237,25 @@ extern int force_personality32;
7587 the loader. We need to make sure that it is out of the way of the program
7588 that it will "exec", and that there is sufficient room for the brk. */
7590 +#ifdef CONFIG_PAX_SEGMEXEC
7591 +#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
7593 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
7596 +#ifdef CONFIG_PAX_ASLR
7597 +#ifdef CONFIG_X86_32
7598 +#define PAX_ELF_ET_DYN_BASE 0x10000000UL
7600 +#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
7601 +#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
7603 +#define PAX_ELF_ET_DYN_BASE 0x400000UL
7605 +#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_IA32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
7606 +#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_IA32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
7610 /* This yields a mask that user programs can use to figure out what
7611 instruction set this CPU supports. This could be done in user space,
7612 @@ -291,8 +309,7 @@ do { \
7613 #define ARCH_DLINFO \
7616 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
7617 - (unsigned long)current->mm->context.vdso); \
7618 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso);\
7621 #define AT_SYSINFO 32
7622 @@ -303,7 +320,7 @@ do { \
7624 #endif /* !CONFIG_X86_32 */
7626 -#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
7627 +#define VDSO_CURRENT_BASE (current->mm->context.vdso)
7629 #define VDSO_ENTRY \
7630 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
7631 @@ -317,7 +334,4 @@ extern int arch_setup_additional_pages(s
7632 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
7633 #define compat_arch_setup_additional_pages syscall32_setup_pages
7635 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
7636 -#define arch_randomize_brk arch_randomize_brk
7638 #endif /* _ASM_X86_ELF_H */
7639 diff -urNp linux-2.6.37/arch/x86/include/asm/futex.h linux-2.6.37/arch/x86/include/asm/futex.h
7640 --- linux-2.6.37/arch/x86/include/asm/futex.h 2011-01-04 19:50:19.000000000 -0500
7641 +++ linux-2.6.37/arch/x86/include/asm/futex.h 2011-01-17 02:41:00.000000000 -0500
7643 #include <asm/system.h>
7645 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
7646 + typecheck(u32 *, uaddr); \
7647 asm volatile("1:\t" insn "\n" \
7648 "2:\t.section .fixup,\"ax\"\n" \
7649 "3:\tmov\t%3, %1\n" \
7652 _ASM_EXTABLE(1b, 3b) \
7653 - : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
7654 + : "=r" (oldval), "=r" (ret), "+m" (*____m(uaddr))\
7655 : "i" (-EFAULT), "0" (oparg), "1" (0))
7657 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
7658 + typecheck(u32 *, uaddr); \
7659 asm volatile("1:\tmovl %2, %0\n" \
7660 "\tmovl\t%0, %3\n" \
7663 _ASM_EXTABLE(1b, 4b) \
7664 _ASM_EXTABLE(2b, 4b) \
7665 : "=&a" (oldval), "=&r" (ret), \
7666 - "+m" (*uaddr), "=&r" (tem) \
7667 + "+m" (*(____m(uaddr))), "=&r" (tem) \
7668 : "r" (oparg), "i" (-EFAULT), "1" (0))
7670 -static inline int futex_atomic_op_inuser(int encoded_op, int __user *uaddr)
7671 +static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
7673 int op = (encoded_op >> 28) & 7;
7674 int cmp = (encoded_op >> 24) & 15;
7675 @@ -61,10 +63,10 @@ static inline int futex_atomic_op_inuser
7679 - __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
7680 + __futex_atomic_op1("xchgl %0, "__copyuser_seg"%2", ret, oldval, uaddr, oparg);
7683 - __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
7684 + __futex_atomic_op1(LOCK_PREFIX "xaddl %0, "__copyuser_seg"%2", ret, oldval,
7688 @@ -109,7 +111,7 @@ static inline int futex_atomic_op_inuser
7692 -static inline int futex_atomic_cmpxchg_inatomic(int __user *uaddr, int oldval,
7693 +static inline int futex_atomic_cmpxchg_inatomic(u32 __user *uaddr, int oldval,
7697 @@ -119,16 +121,16 @@ static inline int futex_atomic_cmpxchg_i
7701 - if (!access_ok(VERIFY_WRITE, uaddr, sizeof(int)))
7702 + if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
7705 - asm volatile("1:\t" LOCK_PREFIX "cmpxchgl %3, %1\n"
7706 + asm volatile("1:\t" LOCK_PREFIX "cmpxchgl %3, "__copyuser_seg"%1\n"
7707 "2:\t.section .fixup, \"ax\"\n"
7711 _ASM_EXTABLE(1b, 3b)
7712 - : "=a" (oldval), "+m" (*uaddr)
7713 + : "=a" (oldval), "+m" (*____m(uaddr))
7714 : "i" (-EFAULT), "r" (newval), "0" (oldval)
7717 diff -urNp linux-2.6.37/arch/x86/include/asm/i387.h linux-2.6.37/arch/x86/include/asm/i387.h
7718 --- linux-2.6.37/arch/x86/include/asm/i387.h 2011-01-04 19:50:19.000000000 -0500
7719 +++ linux-2.6.37/arch/x86/include/asm/i387.h 2011-01-17 02:41:00.000000000 -0500
7720 @@ -92,6 +92,11 @@ static inline int fxrstor_checking(struc
7724 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
7725 + if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
7726 + fx = (struct i387_fxsave_struct *)((void *)fx + PAX_USER_SHADOW_BASE);
7729 /* See comment in fxsave() below. */
7730 asm volatile("1: rex64/fxrstor (%[fx])\n\t"
7732 @@ -109,6 +114,11 @@ static inline int fxsave_user(struct i38
7736 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
7737 + if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
7738 + fx = (struct i387_fxsave_struct __user *)((void __user *)fx + PAX_USER_SHADOW_BASE);
7742 * Clear the bytes not touched by the fxsave and reserved
7744 @@ -189,13 +199,8 @@ static inline void fpu_fxsave(struct fpu
7745 #endif /* CONFIG_X86_64 */
7747 /* We need a safe address that is cheap to find and that is already
7748 - in L1 during context switch. The best choices are unfortunately
7749 - different for UP and SMP */
7751 -#define safe_address (__per_cpu_offset[0])
7753 -#define safe_address (kstat_cpu(0).cpustat.user)
7755 + in L1 during context switch. */
7756 +#define safe_address (init_tss[smp_processor_id()].x86_tss.sp0)
7759 * These must be called with preempt disabled
7760 diff -urNp linux-2.6.37/arch/x86/include/asm/io.h linux-2.6.37/arch/x86/include/asm/io.h
7761 --- linux-2.6.37/arch/x86/include/asm/io.h 2011-01-04 19:50:19.000000000 -0500
7762 +++ linux-2.6.37/arch/x86/include/asm/io.h 2011-01-17 02:41:00.000000000 -0500
7763 @@ -216,6 +216,17 @@ extern void set_iounmap_nonlazy(void);
7765 #include <linux/vmalloc.h>
7767 +#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
7768 +static inline int valid_phys_addr_range(unsigned long addr, size_t count)
7770 + return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1 << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
7773 +static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
7775 + return (pfn + (count >> PAGE_SHIFT)) < (1 << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
7779 * Convert a virtual cached pointer to an uncached pointer
7781 diff -urNp linux-2.6.37/arch/x86/include/asm/iommu.h linux-2.6.37/arch/x86/include/asm/iommu.h
7782 --- linux-2.6.37/arch/x86/include/asm/iommu.h 2011-01-04 19:50:19.000000000 -0500
7783 +++ linux-2.6.37/arch/x86/include/asm/iommu.h 2011-01-17 02:41:00.000000000 -0500
7785 #ifndef _ASM_X86_IOMMU_H
7786 #define _ASM_X86_IOMMU_H
7788 -extern struct dma_map_ops nommu_dma_ops;
7789 +extern const struct dma_map_ops nommu_dma_ops;
7790 extern int force_iommu, no_iommu;
7791 extern int iommu_detected;
7792 extern int iommu_pass_through;
7793 diff -urNp linux-2.6.37/arch/x86/include/asm/irqflags.h linux-2.6.37/arch/x86/include/asm/irqflags.h
7794 --- linux-2.6.37/arch/x86/include/asm/irqflags.h 2011-01-04 19:50:19.000000000 -0500
7795 +++ linux-2.6.37/arch/x86/include/asm/irqflags.h 2011-01-17 02:41:00.000000000 -0500
7796 @@ -140,6 +140,11 @@ static inline unsigned long arch_local_i
7800 +#define GET_CR0_INTO_RDI mov %cr0, %rdi
7801 +#define SET_RDI_INTO_CR0 mov %rdi, %cr0
7802 +#define GET_CR3_INTO_RDI mov %cr3, %rdi
7803 +#define SET_RDI_INTO_CR3 mov %rdi, %cr3
7806 #define INTERRUPT_RETURN iret
7807 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
7808 diff -urNp linux-2.6.37/arch/x86/include/asm/kvm_host.h linux-2.6.37/arch/x86/include/asm/kvm_host.h
7809 --- linux-2.6.37/arch/x86/include/asm/kvm_host.h 2011-01-04 19:50:19.000000000 -0500
7810 +++ linux-2.6.37/arch/x86/include/asm/kvm_host.h 2011-01-17 02:41:00.000000000 -0500
7811 @@ -585,7 +585,7 @@ struct kvm_x86_ops {
7812 const struct trace_print_flags *exit_reasons_str;
7815 -extern struct kvm_x86_ops *kvm_x86_ops;
7816 +extern const struct kvm_x86_ops *kvm_x86_ops;
7818 int kvm_mmu_module_init(void);
7819 void kvm_mmu_module_exit(void);
7820 diff -urNp linux-2.6.37/arch/x86/include/asm/local.h linux-2.6.37/arch/x86/include/asm/local.h
7821 --- linux-2.6.37/arch/x86/include/asm/local.h 2011-01-04 19:50:19.000000000 -0500
7822 +++ linux-2.6.37/arch/x86/include/asm/local.h 2011-01-17 02:41:00.000000000 -0500
7823 @@ -18,26 +18,58 @@ typedef struct {
7825 static inline void local_inc(local_t *l)
7827 - asm volatile(_ASM_INC "%0"
7828 + asm volatile(_ASM_INC "%0\n"
7830 +#ifdef CONFIG_PAX_REFCOUNT
7834 + _ASM_EXTABLE(0b, 0b)
7837 : "+m" (l->a.counter));
7840 static inline void local_dec(local_t *l)
7842 - asm volatile(_ASM_DEC "%0"
7843 + asm volatile(_ASM_DEC "%0\n"
7845 +#ifdef CONFIG_PAX_REFCOUNT
7849 + _ASM_EXTABLE(0b, 0b)
7852 : "+m" (l->a.counter));
7855 static inline void local_add(long i, local_t *l)
7857 - asm volatile(_ASM_ADD "%1,%0"
7858 + asm volatile(_ASM_ADD "%1,%0\n"
7860 +#ifdef CONFIG_PAX_REFCOUNT
7862 + _ASM_SUB "%1,%0\n"
7864 + _ASM_EXTABLE(0b, 0b)
7867 : "+m" (l->a.counter)
7871 static inline void local_sub(long i, local_t *l)
7873 - asm volatile(_ASM_SUB "%1,%0"
7874 + asm volatile(_ASM_SUB "%1,%0\n"
7876 +#ifdef CONFIG_PAX_REFCOUNT
7878 + _ASM_ADD "%1,%0\n"
7880 + _ASM_EXTABLE(0b, 0b)
7883 : "+m" (l->a.counter)
7886 @@ -55,7 +87,16 @@ static inline int local_sub_and_test(lon
7890 - asm volatile(_ASM_SUB "%2,%0; sete %1"
7891 + asm volatile(_ASM_SUB "%2,%0\n"
7893 +#ifdef CONFIG_PAX_REFCOUNT
7895 + _ASM_ADD "%2,%0\n"
7897 + _ASM_EXTABLE(0b, 0b)
7901 : "+m" (l->a.counter), "=qm" (c)
7902 : "ir" (i) : "memory");
7904 @@ -73,7 +114,16 @@ static inline int local_dec_and_test(loc
7908 - asm volatile(_ASM_DEC "%0; sete %1"
7909 + asm volatile(_ASM_DEC "%0\n"
7911 +#ifdef CONFIG_PAX_REFCOUNT
7915 + _ASM_EXTABLE(0b, 0b)
7919 : "+m" (l->a.counter), "=qm" (c)
7922 @@ -91,7 +141,16 @@ static inline int local_inc_and_test(loc
7926 - asm volatile(_ASM_INC "%0; sete %1"
7927 + asm volatile(_ASM_INC "%0\n"
7929 +#ifdef CONFIG_PAX_REFCOUNT
7933 + _ASM_EXTABLE(0b, 0b)
7937 : "+m" (l->a.counter), "=qm" (c)
7940 @@ -110,7 +169,16 @@ static inline int local_add_negative(lon
7944 - asm volatile(_ASM_ADD "%2,%0; sets %1"
7945 + asm volatile(_ASM_ADD "%2,%0\n"
7947 +#ifdef CONFIG_PAX_REFCOUNT
7949 + _ASM_SUB "%2,%0\n"
7951 + _ASM_EXTABLE(0b, 0b)
7955 : "+m" (l->a.counter), "=qm" (c)
7956 : "ir" (i) : "memory");
7958 @@ -133,7 +201,15 @@ static inline long local_add_return(long
7960 /* Modern 486+ processor */
7962 - asm volatile(_ASM_XADD "%0, %1;"
7963 + asm volatile(_ASM_XADD "%0, %1\n"
7965 +#ifdef CONFIG_PAX_REFCOUNT
7967 + _ASM_MOV "%0,%1\n"
7969 + _ASM_EXTABLE(0b, 0b)
7972 : "+r" (i), "+m" (l->a.counter)
7975 diff -urNp linux-2.6.37/arch/x86/include/asm/mc146818rtc.h linux-2.6.37/arch/x86/include/asm/mc146818rtc.h
7976 --- linux-2.6.37/arch/x86/include/asm/mc146818rtc.h 2011-01-04 19:50:19.000000000 -0500
7977 +++ linux-2.6.37/arch/x86/include/asm/mc146818rtc.h 2011-01-17 02:41:00.000000000 -0500
7978 @@ -81,8 +81,8 @@ static inline unsigned char current_lock
7980 #define lock_cmos_prefix(reg) do {} while (0)
7981 #define lock_cmos_suffix(reg) do {} while (0)
7982 -#define lock_cmos(reg)
7983 -#define unlock_cmos()
7984 +#define lock_cmos(reg) do {} while (0)
7985 +#define unlock_cmos() do {} while (0)
7986 #define do_i_have_lock_cmos() 0
7987 #define current_lock_cmos_reg() 0
7989 diff -urNp linux-2.6.37/arch/x86/include/asm/microcode.h linux-2.6.37/arch/x86/include/asm/microcode.h
7990 --- linux-2.6.37/arch/x86/include/asm/microcode.h 2011-01-04 19:50:19.000000000 -0500
7991 +++ linux-2.6.37/arch/x86/include/asm/microcode.h 2011-01-17 02:41:00.000000000 -0500
7992 @@ -12,13 +12,13 @@ struct device;
7993 enum ucode_state { UCODE_ERROR, UCODE_OK, UCODE_NFOUND };
7995 struct microcode_ops {
7996 - enum ucode_state (*request_microcode_user) (int cpu,
7997 + enum ucode_state (* const request_microcode_user) (int cpu,
7998 const void __user *buf, size_t size);
8000 - enum ucode_state (*request_microcode_fw) (int cpu,
8001 + enum ucode_state (* const request_microcode_fw) (int cpu,
8002 struct device *device);
8004 - void (*microcode_fini_cpu) (int cpu);
8005 + void (* const microcode_fini_cpu) (int cpu);
8008 * The generic 'microcode_core' part guarantees that
8009 @@ -38,18 +38,18 @@ struct ucode_cpu_info {
8010 extern struct ucode_cpu_info ucode_cpu_info[];
8012 #ifdef CONFIG_MICROCODE_INTEL
8013 -extern struct microcode_ops * __init init_intel_microcode(void);
8014 +extern const struct microcode_ops * __init init_intel_microcode(void);
8016 -static inline struct microcode_ops * __init init_intel_microcode(void)
8017 +static inline const struct microcode_ops * __init init_intel_microcode(void)
8021 #endif /* CONFIG_MICROCODE_INTEL */
8023 #ifdef CONFIG_MICROCODE_AMD
8024 -extern struct microcode_ops * __init init_amd_microcode(void);
8025 +extern const struct microcode_ops * __init init_amd_microcode(void);
8027 -static inline struct microcode_ops * __init init_amd_microcode(void)
8028 +static inline const struct microcode_ops * __init init_amd_microcode(void)
8032 diff -urNp linux-2.6.37/arch/x86/include/asm/mman.h linux-2.6.37/arch/x86/include/asm/mman.h
8033 --- linux-2.6.37/arch/x86/include/asm/mman.h 2011-01-04 19:50:19.000000000 -0500
8034 +++ linux-2.6.37/arch/x86/include/asm/mman.h 2011-01-17 02:41:00.000000000 -0500
8037 #include <asm-generic/mman.h>
8040 +#ifndef __ASSEMBLY__
8041 +#ifdef CONFIG_X86_32
8042 +#define arch_mmap_check i386_mmap_check
8043 +int i386_mmap_check(unsigned long addr, unsigned long len,
8044 + unsigned long flags);
8049 #endif /* _ASM_X86_MMAN_H */
8050 diff -urNp linux-2.6.37/arch/x86/include/asm/mmu_context.h linux-2.6.37/arch/x86/include/asm/mmu_context.h
8051 --- linux-2.6.37/arch/x86/include/asm/mmu_context.h 2011-01-04 19:50:19.000000000 -0500
8052 +++ linux-2.6.37/arch/x86/include/asm/mmu_context.h 2011-01-17 02:41:00.000000000 -0500
8053 @@ -24,6 +24,21 @@ void destroy_context(struct mm_struct *m
8055 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
8058 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
8062 + pax_open_kernel();
8063 + pgd = get_cpu_pgd(smp_processor_id());
8064 + for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
8065 + if (paravirt_enabled())
8066 + set_pgd(pgd+i, native_make_pgd(0));
8068 + pgd[i] = native_make_pgd(0);
8069 + pax_close_kernel();
8073 if (percpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
8074 percpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
8075 @@ -34,27 +49,70 @@ static inline void switch_mm(struct mm_s
8076 struct task_struct *tsk)
8078 unsigned cpu = smp_processor_id();
8079 +#if defined(CONFIG_X86_32) && defined(CONFIG_SMP)
8080 + int tlbstate = TLBSTATE_OK;
8083 if (likely(prev != next)) {
8084 /* stop flush ipis for the previous mm */
8085 cpumask_clear_cpu(cpu, mm_cpumask(prev));
8087 +#ifdef CONFIG_X86_32
8088 + tlbstate = percpu_read(cpu_tlbstate.state);
8090 percpu_write(cpu_tlbstate.state, TLBSTATE_OK);
8091 percpu_write(cpu_tlbstate.active_mm, next);
8093 cpumask_set_cpu(cpu, mm_cpumask(next));
8095 /* Re-load page tables */
8096 +#ifdef CONFIG_PAX_PER_CPU_PGD
8097 + pax_open_kernel();
8098 + __clone_user_pgds(get_cpu_pgd(cpu), next->pgd, USER_PGD_PTRS);
8099 + __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd, USER_PGD_PTRS);
8100 + pax_close_kernel();
8101 + load_cr3(get_cpu_pgd(cpu));
8103 load_cr3(next->pgd);
8107 * load the LDT, if the LDT is different:
8109 if (unlikely(prev->context.ldt != next->context.ldt))
8110 load_LDT_nolock(&next->context);
8113 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
8114 + if (!(__supported_pte_mask & _PAGE_NX)) {
8115 + smp_mb__before_clear_bit();
8116 + cpu_clear(cpu, prev->context.cpu_user_cs_mask);
8117 + smp_mb__after_clear_bit();
8118 + cpu_set(cpu, next->context.cpu_user_cs_mask);
8122 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
8123 + if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
8124 + prev->context.user_cs_limit != next->context.user_cs_limit))
8125 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
8127 + else if (unlikely(tlbstate != TLBSTATE_OK))
8128 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
8135 +#ifdef CONFIG_PAX_PER_CPU_PGD
8136 + pax_open_kernel();
8137 + __clone_user_pgds(get_cpu_pgd(cpu), next->pgd, USER_PGD_PTRS);
8138 + __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd, USER_PGD_PTRS);
8139 + pax_close_kernel();
8140 + load_cr3(get_cpu_pgd(cpu));
8144 percpu_write(cpu_tlbstate.state, TLBSTATE_OK);
8145 BUG_ON(percpu_read(cpu_tlbstate.active_mm) != next);
8147 @@ -63,11 +121,28 @@ static inline void switch_mm(struct mm_s
8148 * tlb flush IPI delivery. We must reload CR3
8149 * to make sure to use no freed page tables.
8152 +#ifndef CONFIG_PAX_PER_CPU_PGD
8153 load_cr3(next->pgd);
8156 load_LDT_nolock(&next->context);
8158 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
8159 + if (!(__supported_pte_mask & _PAGE_NX))
8160 + cpu_set(cpu, next->context.cpu_user_cs_mask);
8163 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
8164 +#ifdef CONFIG_PAX_PAGEEXEC
8165 + if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
8167 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
8176 #define activate_mm(prev, next) \
8177 diff -urNp linux-2.6.37/arch/x86/include/asm/mmu.h linux-2.6.37/arch/x86/include/asm/mmu.h
8178 --- linux-2.6.37/arch/x86/include/asm/mmu.h 2011-01-04 19:50:19.000000000 -0500
8179 +++ linux-2.6.37/arch/x86/include/asm/mmu.h 2011-01-17 02:41:00.000000000 -0500
8181 * we put the segment information here.
8185 + struct desc_struct *ldt;
8189 + unsigned long vdso;
8191 +#ifdef CONFIG_X86_32
8192 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
8193 + unsigned long user_cs_base;
8194 + unsigned long user_cs_limit;
8196 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
8197 + cpumask_t cpu_user_cs_mask;
8206 diff -urNp linux-2.6.37/arch/x86/include/asm/module.h linux-2.6.37/arch/x86/include/asm/module.h
8207 --- linux-2.6.37/arch/x86/include/asm/module.h 2011-01-04 19:50:19.000000000 -0500
8208 +++ linux-2.6.37/arch/x86/include/asm/module.h 2011-01-17 02:41:00.000000000 -0500
8210 #error unknown processor family
8213 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8214 +#define MODULE_PAX_UDEREF "UDEREF "
8216 +#define MODULE_PAX_UDEREF ""
8219 #ifdef CONFIG_X86_32
8220 -# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
8221 +# ifdef CONFIG_PAX_KERNEXEC
8222 +# define MODULE_PAX_KERNEXEC "KERNEXEC "
8224 +# define MODULE_PAX_KERNEXEC ""
8226 +# ifdef CONFIG_GRKERNSEC
8227 +# define MODULE_GRSEC "GRSECURITY "
8229 +# define MODULE_GRSEC ""
8231 +# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_GRSEC MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
8233 +# define MODULE_ARCH_VERMAGIC MODULE_PAX_UDEREF
8236 #endif /* _ASM_X86_MODULE_H */
8237 diff -urNp linux-2.6.37/arch/x86/include/asm/page_64_types.h linux-2.6.37/arch/x86/include/asm/page_64_types.h
8238 --- linux-2.6.37/arch/x86/include/asm/page_64_types.h 2011-01-04 19:50:19.000000000 -0500
8239 +++ linux-2.6.37/arch/x86/include/asm/page_64_types.h 2011-01-17 02:41:00.000000000 -0500
8240 @@ -56,7 +56,7 @@ void copy_page(void *to, void *from);
8242 /* duplicated to the one in bootmem.h */
8243 extern unsigned long max_pfn;
8244 -extern unsigned long phys_base;
8245 +extern const unsigned long phys_base;
8247 extern unsigned long __phys_addr(unsigned long);
8248 #define __phys_reloc_hide(x) (x)
8249 diff -urNp linux-2.6.37/arch/x86/include/asm/paravirt.h linux-2.6.37/arch/x86/include/asm/paravirt.h
8250 --- linux-2.6.37/arch/x86/include/asm/paravirt.h 2011-01-04 19:50:19.000000000 -0500
8251 +++ linux-2.6.37/arch/x86/include/asm/paravirt.h 2011-01-17 02:41:00.000000000 -0500
8252 @@ -715,6 +715,21 @@ static inline void __set_fixmap(unsigned
8253 pv_mmu_ops.set_fixmap(idx, phys, flags);
8256 +#ifdef CONFIG_PAX_KERNEXEC
8257 +static inline unsigned long pax_open_kernel(void)
8259 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
8262 +static inline unsigned long pax_close_kernel(void)
8264 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
8267 +static inline unsigned long pax_open_kernel(void) { return 0; }
8268 +static inline unsigned long pax_close_kernel(void) { return 0; }
8271 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
8273 static inline int arch_spin_is_locked(struct arch_spinlock *lock)
8274 @@ -931,7 +946,7 @@ extern void default_banner(void);
8276 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
8277 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
8278 -#define PARA_INDIRECT(addr) *%cs:addr
8279 +#define PARA_INDIRECT(addr) *%ss:addr
8282 #define INTERRUPT_RETURN \
8283 @@ -1008,6 +1023,21 @@ extern void default_banner(void);
8284 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
8286 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
8288 +#define GET_CR0_INTO_RDI \
8289 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
8292 +#define SET_RDI_INTO_CR0 \
8293 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
8295 +#define GET_CR3_INTO_RDI \
8296 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
8299 +#define SET_RDI_INTO_CR3 \
8300 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
8302 #endif /* CONFIG_X86_32 */
8304 #endif /* __ASSEMBLY__ */
8305 diff -urNp linux-2.6.37/arch/x86/include/asm/paravirt_types.h linux-2.6.37/arch/x86/include/asm/paravirt_types.h
8306 --- linux-2.6.37/arch/x86/include/asm/paravirt_types.h 2011-01-04 19:50:19.000000000 -0500
8307 +++ linux-2.6.37/arch/x86/include/asm/paravirt_types.h 2011-01-17 02:41:00.000000000 -0500
8308 @@ -311,6 +311,12 @@ struct pv_mmu_ops {
8309 an mfn. We can tell which is which from the index. */
8310 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
8311 phys_addr_t phys, pgprot_t flags);
8313 +#ifdef CONFIG_PAX_KERNEXEC
8314 + unsigned long (*pax_open_kernel)(void);
8315 + unsigned long (*pax_close_kernel)(void);
8320 struct arch_spinlock;
8321 diff -urNp linux-2.6.37/arch/x86/include/asm/pci_x86.h linux-2.6.37/arch/x86/include/asm/pci_x86.h
8322 --- linux-2.6.37/arch/x86/include/asm/pci_x86.h 2011-01-04 19:50:19.000000000 -0500
8323 +++ linux-2.6.37/arch/x86/include/asm/pci_x86.h 2011-01-17 02:41:01.000000000 -0500
8324 @@ -93,16 +93,16 @@ extern int (*pcibios_enable_irq)(struct
8325 extern void (*pcibios_disable_irq)(struct pci_dev *dev);
8327 struct pci_raw_ops {
8328 - int (*read)(unsigned int domain, unsigned int bus, unsigned int devfn,
8329 + int (* const read)(unsigned int domain, unsigned int bus, unsigned int devfn,
8330 int reg, int len, u32 *val);
8331 - int (*write)(unsigned int domain, unsigned int bus, unsigned int devfn,
8332 + int (* const write)(unsigned int domain, unsigned int bus, unsigned int devfn,
8333 int reg, int len, u32 val);
8336 -extern struct pci_raw_ops *raw_pci_ops;
8337 -extern struct pci_raw_ops *raw_pci_ext_ops;
8338 +extern const struct pci_raw_ops *raw_pci_ops;
8339 +extern const struct pci_raw_ops *raw_pci_ext_ops;
8341 -extern struct pci_raw_ops pci_direct_conf1;
8342 +extern const struct pci_raw_ops pci_direct_conf1;
8343 extern bool port_cf9_safe;
8345 /* arch_initcall level */
8346 diff -urNp linux-2.6.37/arch/x86/include/asm/pgalloc.h linux-2.6.37/arch/x86/include/asm/pgalloc.h
8347 --- linux-2.6.37/arch/x86/include/asm/pgalloc.h 2011-01-04 19:50:19.000000000 -0500
8348 +++ linux-2.6.37/arch/x86/include/asm/pgalloc.h 2011-01-17 02:41:01.000000000 -0500
8349 @@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(s
8350 pmd_t *pmd, pte_t *pte)
8352 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
8353 + set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
8356 +static inline void pmd_populate_user(struct mm_struct *mm,
8357 + pmd_t *pmd, pte_t *pte)
8359 + paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
8360 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
8363 diff -urNp linux-2.6.37/arch/x86/include/asm/pgtable-2level.h linux-2.6.37/arch/x86/include/asm/pgtable-2level.h
8364 --- linux-2.6.37/arch/x86/include/asm/pgtable-2level.h 2011-01-04 19:50:19.000000000 -0500
8365 +++ linux-2.6.37/arch/x86/include/asm/pgtable-2level.h 2011-01-17 02:41:01.000000000 -0500
8366 @@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t
8368 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
8370 + pax_open_kernel();
8372 + pax_close_kernel();
8375 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
8376 diff -urNp linux-2.6.37/arch/x86/include/asm/pgtable_32.h linux-2.6.37/arch/x86/include/asm/pgtable_32.h
8377 --- linux-2.6.37/arch/x86/include/asm/pgtable_32.h 2011-01-04 19:50:19.000000000 -0500
8378 +++ linux-2.6.37/arch/x86/include/asm/pgtable_32.h 2011-01-17 02:41:01.000000000 -0500
8381 struct vm_area_struct;
8383 -extern pgd_t swapper_pg_dir[1024];
8384 -extern pgd_t initial_page_table[1024];
8386 static inline void pgtable_cache_init(void) { }
8387 static inline void check_pgt_cache(void) { }
8388 void paging_init(void);
8389 @@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, u
8390 # include <asm/pgtable-2level.h>
8393 +extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
8394 +extern pgd_t initial_page_table[PTRS_PER_PGD];
8395 +#ifdef CONFIG_X86_PAE
8396 +extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
8399 #if defined(CONFIG_HIGHPTE)
8400 #define pte_offset_map(dir, address) \
8401 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
8402 @@ -62,7 +65,9 @@ extern void set_pmd_pfn(unsigned long, u
8403 /* Clear a kernel PTE and flush it from the TLB */
8404 #define kpte_clear_flush(ptep, vaddr) \
8406 + pax_open_kernel(); \
8407 pte_clear(&init_mm, (vaddr), (ptep)); \
8408 + pax_close_kernel(); \
8409 __flush_tlb_one((vaddr)); \
8412 @@ -74,6 +79,9 @@ do { \
8414 #endif /* !__ASSEMBLY__ */
8416 +#define HAVE_ARCH_UNMAPPED_AREA
8417 +#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
8420 * kern_addr_valid() is (1) for FLATMEM and (0) for
8421 * SPARSEMEM and DISCONTIGMEM
8422 diff -urNp linux-2.6.37/arch/x86/include/asm/pgtable_32_types.h linux-2.6.37/arch/x86/include/asm/pgtable_32_types.h
8423 --- linux-2.6.37/arch/x86/include/asm/pgtable_32_types.h 2011-01-04 19:50:19.000000000 -0500
8424 +++ linux-2.6.37/arch/x86/include/asm/pgtable_32_types.h 2011-01-17 02:41:01.000000000 -0500
8427 #ifdef CONFIG_X86_PAE
8428 # include <asm/pgtable-3level_types.h>
8429 -# define PMD_SIZE (1UL << PMD_SHIFT)
8430 +# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
8431 # define PMD_MASK (~(PMD_SIZE - 1))
8433 # include <asm/pgtable-2level_types.h>
8434 @@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set
8435 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
8438 +#ifdef CONFIG_PAX_KERNEXEC
8439 +#ifndef __ASSEMBLY__
8440 +extern unsigned char MODULES_EXEC_VADDR[];
8441 +extern unsigned char MODULES_EXEC_END[];
8443 +#include <asm/boot.h>
8444 +#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
8445 +#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
8447 +#define ktla_ktva(addr) (addr)
8448 +#define ktva_ktla(addr) (addr)
8451 #define MODULES_VADDR VMALLOC_START
8452 #define MODULES_END VMALLOC_END
8453 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
8454 diff -urNp linux-2.6.37/arch/x86/include/asm/pgtable-3level.h linux-2.6.37/arch/x86/include/asm/pgtable-3level.h
8455 --- linux-2.6.37/arch/x86/include/asm/pgtable-3level.h 2011-01-04 19:50:19.000000000 -0500
8456 +++ linux-2.6.37/arch/x86/include/asm/pgtable-3level.h 2011-01-17 02:41:01.000000000 -0500
8457 @@ -38,12 +38,16 @@ static inline void native_set_pte_atomic
8459 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
8461 + pax_open_kernel();
8462 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
8463 + pax_close_kernel();
8466 static inline void native_set_pud(pud_t *pudp, pud_t pud)
8468 + pax_open_kernel();
8469 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
8470 + pax_close_kernel();
8474 diff -urNp linux-2.6.37/arch/x86/include/asm/pgtable_64.h linux-2.6.37/arch/x86/include/asm/pgtable_64.h
8475 --- linux-2.6.37/arch/x86/include/asm/pgtable_64.h 2011-01-04 19:50:19.000000000 -0500
8476 +++ linux-2.6.37/arch/x86/include/asm/pgtable_64.h 2011-01-17 02:41:01.000000000 -0500
8479 extern pud_t level3_kernel_pgt[512];
8480 extern pud_t level3_ident_pgt[512];
8481 +extern pud_t level3_vmalloc_pgt[512];
8482 +extern pud_t level3_vmemmap_pgt[512];
8483 +extern pud_t level2_vmemmap_pgt[512];
8484 extern pmd_t level2_kernel_pgt[512];
8485 extern pmd_t level2_fixmap_pgt[512];
8486 -extern pmd_t level2_ident_pgt[512];
8487 -extern pgd_t init_level4_pgt[];
8488 +extern pmd_t level2_ident_pgt[512*2];
8489 +extern pgd_t init_level4_pgt[512];
8491 #define swapper_pg_dir init_level4_pgt
8493 @@ -74,7 +77,9 @@ static inline pte_t native_ptep_get_and_
8495 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
8497 + pax_open_kernel();
8499 + pax_close_kernel();
8502 static inline void native_pmd_clear(pmd_t *pmd)
8503 @@ -94,7 +99,9 @@ static inline void native_pud_clear(pud_
8505 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
8507 + pax_open_kernel();
8509 + pax_close_kernel();
8512 static inline void native_pgd_clear(pgd_t *pgd)
8513 diff -urNp linux-2.6.37/arch/x86/include/asm/pgtable_64_types.h linux-2.6.37/arch/x86/include/asm/pgtable_64_types.h
8514 --- linux-2.6.37/arch/x86/include/asm/pgtable_64_types.h 2011-01-04 19:50:19.000000000 -0500
8515 +++ linux-2.6.37/arch/x86/include/asm/pgtable_64_types.h 2011-01-17 02:41:01.000000000 -0500
8516 @@ -59,5 +59,10 @@ typedef struct { pteval_t pte; } pte_t;
8517 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
8518 #define MODULES_END _AC(0xffffffffff000000, UL)
8519 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
8520 +#define MODULES_EXEC_VADDR MODULES_VADDR
8521 +#define MODULES_EXEC_END MODULES_END
8523 +#define ktla_ktva(addr) (addr)
8524 +#define ktva_ktla(addr) (addr)
8526 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
8527 diff -urNp linux-2.6.37/arch/x86/include/asm/pgtable.h linux-2.6.37/arch/x86/include/asm/pgtable.h
8528 --- linux-2.6.37/arch/x86/include/asm/pgtable.h 2011-01-04 19:50:19.000000000 -0500
8529 +++ linux-2.6.37/arch/x86/include/asm/pgtable.h 2011-01-17 02:41:01.000000000 -0500
8530 @@ -78,12 +78,51 @@ extern struct mm_struct *pgd_page_get_mm
8532 #define arch_end_context_switch(prev) do {} while(0)
8534 +#define pax_open_kernel() native_pax_open_kernel()
8535 +#define pax_close_kernel() native_pax_close_kernel()
8536 #endif /* CONFIG_PARAVIRT */
8538 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
8539 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
8541 +#ifdef CONFIG_PAX_KERNEXEC
8542 +static inline unsigned long native_pax_open_kernel(void)
8544 + unsigned long cr0;
8546 + preempt_disable();
8548 + cr0 = read_cr0() ^ X86_CR0_WP;
8549 + BUG_ON(unlikely(cr0 & X86_CR0_WP));
8551 + return cr0 ^ X86_CR0_WP;
8554 +static inline unsigned long native_pax_close_kernel(void)
8556 + unsigned long cr0;
8558 + cr0 = read_cr0() ^ X86_CR0_WP;
8559 + BUG_ON(unlikely(!(cr0 & X86_CR0_WP)));
8562 + preempt_enable_no_resched();
8563 + return cr0 ^ X86_CR0_WP;
8566 +static inline unsigned long native_pax_open_kernel(void) { return 0; }
8567 +static inline unsigned long native_pax_close_kernel(void) { return 0; }
8571 * The following only work if pte_present() is true.
8572 * Undefined behaviour if not..
8574 +static inline int pte_user(pte_t pte)
8576 + return pte_val(pte) & _PAGE_USER;
8579 static inline int pte_dirty(pte_t pte)
8581 return pte_flags(pte) & _PAGE_DIRTY;
8582 @@ -171,9 +210,29 @@ static inline pte_t pte_wrprotect(pte_t
8583 return pte_clear_flags(pte, _PAGE_RW);
8586 +static inline pte_t pte_mkread(pte_t pte)
8588 + return __pte(pte_val(pte) | _PAGE_USER);
8591 static inline pte_t pte_mkexec(pte_t pte)
8593 - return pte_clear_flags(pte, _PAGE_NX);
8594 +#ifdef CONFIG_X86_PAE
8595 + if (__supported_pte_mask & _PAGE_NX)
8596 + return pte_clear_flags(pte, _PAGE_NX);
8599 + return pte_set_flags(pte, _PAGE_USER);
8602 +static inline pte_t pte_exprotect(pte_t pte)
8604 +#ifdef CONFIG_X86_PAE
8605 + if (__supported_pte_mask & _PAGE_NX)
8606 + return pte_set_flags(pte, _PAGE_NX);
8609 + return pte_clear_flags(pte, _PAGE_USER);
8612 static inline pte_t pte_mkdirty(pte_t pte)
8613 @@ -306,6 +365,15 @@ pte_t *populate_extra_pte(unsigned long
8616 #ifndef __ASSEMBLY__
8618 +#ifdef CONFIG_PAX_PER_CPU_PGD
8619 +extern pgd_t cpu_pgd[NR_CPUS][PTRS_PER_PGD];
8620 +static inline pgd_t *get_cpu_pgd(unsigned int cpu)
8622 + return cpu_pgd[cpu];
8626 #include <linux/mm_types.h>
8628 static inline int pte_none(pte_t pte)
8629 @@ -476,7 +544,7 @@ static inline pud_t *pud_offset(pgd_t *p
8631 static inline int pgd_bad(pgd_t pgd)
8633 - return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
8634 + return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
8637 static inline int pgd_none(pgd_t pgd)
8638 @@ -499,7 +567,12 @@ static inline int pgd_none(pgd_t pgd)
8639 * pgd_offset() returns a (pgd_t *)
8640 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
8642 -#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
8643 +#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
8645 +#ifdef CONFIG_PAX_PER_CPU_PGD
8646 +#define pgd_offset_cpu(cpu, address) (get_cpu_pgd(cpu) + pgd_index(address))
8650 * a shortcut which implies the use of the kernel's pgd, instead
8652 @@ -510,6 +583,20 @@ static inline int pgd_none(pgd_t pgd)
8653 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
8654 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
8656 +#ifdef CONFIG_X86_32
8657 +#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
8659 +#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
8660 +#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
8662 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8663 +#define PAX_USER_SHADOW_BASE (_AC(1,UL) << TASK_SIZE_MAX_SHIFT)
8665 +#define PAX_USER_SHADOW_BASE (_AC(0,UL))
8670 #ifndef __ASSEMBLY__
8672 extern int direct_gbpages;
8673 @@ -617,11 +704,23 @@ static inline void ptep_set_wrprotect(st
8674 * dst and src can be on the same page, but the range must not overlap,
8675 * and must not cross a page boundary.
8677 -static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
8678 +static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
8680 - memcpy(dst, src, count * sizeof(pgd_t));
8681 + pax_open_kernel();
8684 + pax_close_kernel();
8687 +#ifdef CONFIG_PAX_PER_CPU_PGD
8688 +extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src, int count);
8691 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
8692 +extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src, int count);
8694 +static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src, int count) {}
8697 #include <asm-generic/pgtable.h>
8698 #endif /* __ASSEMBLY__ */
8699 diff -urNp linux-2.6.37/arch/x86/include/asm/pgtable_types.h linux-2.6.37/arch/x86/include/asm/pgtable_types.h
8700 --- linux-2.6.37/arch/x86/include/asm/pgtable_types.h 2011-01-04 19:50:19.000000000 -0500
8701 +++ linux-2.6.37/arch/x86/include/asm/pgtable_types.h 2011-01-17 02:41:01.000000000 -0500
8703 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
8704 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
8705 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
8706 -#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
8707 +#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
8708 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
8709 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
8710 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
8711 -#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
8712 -#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
8713 +#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
8714 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
8716 /* If _PAGE_BIT_PRESENT is clear, we use these: */
8718 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
8719 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
8720 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
8721 -#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
8722 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
8723 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
8724 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
8727 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
8728 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
8730 +#elif defined(CONFIG_KMEMCHECK)
8731 #define _PAGE_NX (_AT(pteval_t, 0))
8733 +#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
8736 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
8738 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
8741 +#define PAGE_READONLY_NOEXEC PAGE_READONLY
8742 +#define PAGE_SHARED_NOEXEC PAGE_SHARED
8744 #define __PAGE_KERNEL_EXEC \
8745 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
8746 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
8748 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
8749 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
8750 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
8751 -#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
8752 -#define __PAGE_KERNEL_VSYSCALL_NOCACHE (__PAGE_KERNEL_VSYSCALL | _PAGE_PCD | _PAGE_PWT)
8753 +#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
8754 +#define __PAGE_KERNEL_VSYSCALL_NOCACHE (__PAGE_KERNEL_RO | _PAGE_PCD | _PAGE_PWT | _PAGE_USER)
8755 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
8756 #define __PAGE_KERNEL_LARGE_NOCACHE (__PAGE_KERNEL | _PAGE_CACHE_UC | _PAGE_PSE)
8757 #define __PAGE_KERNEL_LARGE_EXEC (__PAGE_KERNEL_EXEC | _PAGE_PSE)
8759 * bits are combined, this will alow user to access the high address mapped
8760 * VDSO in the presence of CONFIG_COMPAT_VDSO
8762 -#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
8763 -#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
8764 +#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
8765 +#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
8766 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
8769 @@ -202,7 +205,17 @@ static inline pgdval_t pgd_flags(pgd_t p
8771 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
8775 +#if PAGETABLE_LEVELS == 3
8776 +#include <asm-generic/pgtable-nopud.h>
8779 +#if PAGETABLE_LEVELS == 2
8780 +#include <asm-generic/pgtable-nopmd.h>
8783 +#ifndef __ASSEMBLY__
8784 #if PAGETABLE_LEVELS > 3
8785 typedef struct { pudval_t pud; } pud_t;
8787 @@ -216,8 +229,6 @@ static inline pudval_t native_pud_val(pu
8791 -#include <asm-generic/pgtable-nopud.h>
8793 static inline pudval_t native_pud_val(pud_t pud)
8795 return native_pgd_val(pud.pgd);
8796 @@ -237,8 +248,6 @@ static inline pmdval_t native_pmd_val(pm
8800 -#include <asm-generic/pgtable-nopmd.h>
8802 static inline pmdval_t native_pmd_val(pmd_t pmd)
8804 return native_pgd_val(pmd.pud.pgd);
8805 @@ -278,7 +287,6 @@ typedef struct page *pgtable_t;
8807 extern pteval_t __supported_pte_mask;
8808 extern void set_nx(void);
8809 -extern int nx_enabled;
8811 #define pgprot_writecombine pgprot_writecombine
8812 extern pgprot_t pgprot_writecombine(pgprot_t prot);
8813 diff -urNp linux-2.6.37/arch/x86/include/asm/processor.h linux-2.6.37/arch/x86/include/asm/processor.h
8814 --- linux-2.6.37/arch/x86/include/asm/processor.h 2011-01-04 19:50:19.000000000 -0500
8815 +++ linux-2.6.37/arch/x86/include/asm/processor.h 2011-01-17 02:41:01.000000000 -0500
8816 @@ -271,7 +271,7 @@ struct tss_struct {
8818 } ____cacheline_aligned;
8820 -DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
8821 +extern struct tss_struct init_tss[NR_CPUS];
8824 * Save the original ist values for checking stack pointers during debugging
8825 @@ -864,8 +864,15 @@ static inline void spin_lock_prefetch(co
8827 #define TASK_SIZE PAGE_OFFSET
8828 #define TASK_SIZE_MAX TASK_SIZE
8830 +#ifdef CONFIG_PAX_SEGMEXEC
8831 +#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
8832 +#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
8834 #define STACK_TOP TASK_SIZE
8835 -#define STACK_TOP_MAX STACK_TOP
8838 +#define STACK_TOP_MAX TASK_SIZE
8840 #define INIT_THREAD { \
8841 .sp0 = sizeof(init_stack) + (long)&init_stack, \
8842 @@ -882,7 +889,7 @@ static inline void spin_lock_prefetch(co
8844 #define INIT_TSS { \
8846 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
8847 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
8848 .ss0 = __KERNEL_DS, \
8849 .ss1 = __KERNEL_CS, \
8850 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
8851 @@ -893,11 +900,7 @@ static inline void spin_lock_prefetch(co
8852 extern unsigned long thread_saved_pc(struct task_struct *tsk);
8854 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
8855 -#define KSTK_TOP(info) \
8857 - unsigned long *__ptr = (unsigned long *)(info); \
8858 - (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
8860 +#define KSTK_TOP(info) ((info)->task.thread.sp0)
8863 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
8864 @@ -912,7 +915,7 @@ extern unsigned long thread_saved_pc(str
8865 #define task_pt_regs(task) \
8867 struct pt_regs *__regs__; \
8868 - __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
8869 + __regs__ = (struct pt_regs *)((task)->thread.sp0); \
8873 @@ -922,13 +925,13 @@ extern unsigned long thread_saved_pc(str
8875 * User space process size. 47bits minus one guard page.
8877 -#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
8878 +#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
8880 /* This decides where the kernel will search for a free chunk of vm
8881 * space during mmap's.
8883 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
8884 - 0xc0000000 : 0xFFFFe000)
8885 + 0xc0000000 : 0xFFFFf000)
8887 #define TASK_SIZE (test_thread_flag(TIF_IA32) ? \
8888 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
8889 @@ -965,6 +968,10 @@ extern void start_thread(struct pt_regs
8891 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
8893 +#ifdef CONFIG_PAX_SEGMEXEC
8894 +#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
8897 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
8899 /* Get/set a process' ability to use the timestamp counter instruction */
8900 diff -urNp linux-2.6.37/arch/x86/include/asm/ptrace.h linux-2.6.37/arch/x86/include/asm/ptrace.h
8901 --- linux-2.6.37/arch/x86/include/asm/ptrace.h 2011-01-04 19:50:19.000000000 -0500
8902 +++ linux-2.6.37/arch/x86/include/asm/ptrace.h 2011-01-17 02:41:01.000000000 -0500
8903 @@ -152,28 +152,29 @@ static inline unsigned long regs_return_
8907 - * user_mode_vm(regs) determines whether a register set came from user mode.
8908 + * user_mode(regs) determines whether a register set came from user mode.
8909 * This is true if V8086 mode was enabled OR if the register set was from
8910 * protected mode with RPL-3 CS value. This tricky test checks that with
8911 * one comparison. Many places in the kernel can bypass this full check
8912 - * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
8913 + * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
8916 -static inline int user_mode(struct pt_regs *regs)
8917 +static inline int user_mode_novm(struct pt_regs *regs)
8919 #ifdef CONFIG_X86_32
8920 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
8922 - return !!(regs->cs & 3);
8923 + return !!(regs->cs & SEGMENT_RPL_MASK);
8927 -static inline int user_mode_vm(struct pt_regs *regs)
8928 +static inline int user_mode(struct pt_regs *regs)
8930 #ifdef CONFIG_X86_32
8931 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
8934 - return user_mode(regs);
8935 + return user_mode_novm(regs);
8939 diff -urNp linux-2.6.37/arch/x86/include/asm/reboot.h linux-2.6.37/arch/x86/include/asm/reboot.h
8940 --- linux-2.6.37/arch/x86/include/asm/reboot.h 2011-01-04 19:50:19.000000000 -0500
8941 +++ linux-2.6.37/arch/x86/include/asm/reboot.h 2011-01-17 02:41:01.000000000 -0500
8942 @@ -18,7 +18,7 @@ extern struct machine_ops machine_ops;
8944 void native_machine_crash_shutdown(struct pt_regs *regs);
8945 void native_machine_shutdown(void);
8946 -void machine_real_restart(const unsigned char *code, int length);
8947 +void machine_real_restart(const unsigned char *code, unsigned int length);
8949 typedef void (*nmi_shootdown_cb)(int, struct die_args*);
8950 void nmi_shootdown_cpus(nmi_shootdown_cb callback);
8951 diff -urNp linux-2.6.37/arch/x86/include/asm/rwsem.h linux-2.6.37/arch/x86/include/asm/rwsem.h
8952 --- linux-2.6.37/arch/x86/include/asm/rwsem.h 2011-01-04 19:50:19.000000000 -0500
8953 +++ linux-2.6.37/arch/x86/include/asm/rwsem.h 2011-01-17 02:41:01.000000000 -0500
8954 @@ -118,6 +118,14 @@ static inline void __down_read(struct rw
8956 asm volatile("# beginning down_read\n\t"
8957 LOCK_PREFIX _ASM_INC "(%1)\n\t"
8959 +#ifdef CONFIG_PAX_REFCOUNT
8961 + LOCK_PREFIX _ASM_DEC "(%1)\n"
8963 + _ASM_EXTABLE(0b, 0b)
8966 /* adds 0x00000001 */
8968 " call call_rwsem_down_read_failed\n"
8969 @@ -139,6 +147,14 @@ static inline int __down_read_trylock(st
8974 +#ifdef CONFIG_PAX_REFCOUNT
8978 + _ASM_EXTABLE(0b, 0b)
8982 LOCK_PREFIX " cmpxchg %2,%0\n\t"
8984 @@ -158,6 +174,14 @@ static inline void __down_write_nested(s
8986 asm volatile("# beginning down_write\n\t"
8987 LOCK_PREFIX " xadd %1,(%2)\n\t"
8989 +#ifdef CONFIG_PAX_REFCOUNT
8993 + _ASM_EXTABLE(0b, 0b)
8996 /* adds 0xffff0001, returns the old value */
8998 /* was the count 0 before? */
8999 @@ -196,6 +220,14 @@ static inline void __up_read(struct rw_s
9001 asm volatile("# beginning __up_read\n\t"
9002 LOCK_PREFIX " xadd %1,(%2)\n\t"
9004 +#ifdef CONFIG_PAX_REFCOUNT
9008 + _ASM_EXTABLE(0b, 0b)
9011 /* subtracts 1, returns the old value */
9013 " call call_rwsem_wake\n" /* expects old value in %edx */
9014 @@ -214,6 +246,14 @@ static inline void __up_write(struct rw_
9016 asm volatile("# beginning __up_write\n\t"
9017 LOCK_PREFIX " xadd %1,(%2)\n\t"
9019 +#ifdef CONFIG_PAX_REFCOUNT
9023 + _ASM_EXTABLE(0b, 0b)
9026 /* subtracts 0xffff0001, returns the old value */
9028 " call call_rwsem_wake\n" /* expects old value in %edx */
9029 @@ -231,6 +271,14 @@ static inline void __downgrade_write(str
9031 asm volatile("# beginning __downgrade_write\n\t"
9032 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
9034 +#ifdef CONFIG_PAX_REFCOUNT
9036 + LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
9038 + _ASM_EXTABLE(0b, 0b)
9042 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
9043 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
9044 @@ -250,7 +298,15 @@ static inline void __downgrade_write(str
9045 static inline void rwsem_atomic_add(rwsem_count_t delta,
9046 struct rw_semaphore *sem)
9048 - asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
9049 + asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
9051 +#ifdef CONFIG_PAX_REFCOUNT
9053 + LOCK_PREFIX _ASM_SUB "%1,%0\n"
9055 + _ASM_EXTABLE(0b, 0b)
9061 @@ -263,7 +319,15 @@ static inline rwsem_count_t rwsem_atomic
9063 rwsem_count_t tmp = delta;
9065 - asm volatile(LOCK_PREFIX "xadd %0,%1"
9066 + asm volatile(LOCK_PREFIX "xadd %0,%1\n"
9068 +#ifdef CONFIG_PAX_REFCOUNT
9072 + _ASM_EXTABLE(0b, 0b)
9075 : "+r" (tmp), "+m" (sem->count)
9078 diff -urNp linux-2.6.37/arch/x86/include/asm/segment.h linux-2.6.37/arch/x86/include/asm/segment.h
9079 --- linux-2.6.37/arch/x86/include/asm/segment.h 2011-01-04 19:50:19.000000000 -0500
9080 +++ linux-2.6.37/arch/x86/include/asm/segment.h 2011-01-17 02:41:01.000000000 -0500
9082 * 26 - ESPFIX small SS
9083 * 27 - per-cpu [ offset to per-cpu data area ]
9084 * 28 - stack_canary-20 [ for stack protector ]
9087 + * 29 - PCI BIOS CS
9088 + * 30 - PCI BIOS DS
9089 * 31 - TSS for double fault handler
9091 #define GDT_ENTRY_TLS_MIN 6
9094 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
9096 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
9098 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
9100 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
9101 @@ -102,6 +104,12 @@
9102 #define __KERNEL_STACK_CANARY 0
9105 +#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
9106 +#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
9108 +#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
9109 +#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
9111 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
9117 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
9118 -#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
9119 +#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
9124 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS * 8 + 3)
9125 #define __USER32_DS __USER_DS
9127 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
9129 #define GDT_ENTRY_TSS 8 /* needs two entries */
9130 #define GDT_ENTRY_LDT 10 /* needs two entries */
9131 #define GDT_ENTRY_TLS_MIN 12
9135 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
9136 +#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
9137 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
9138 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
9139 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
9140 diff -urNp linux-2.6.37/arch/x86/include/asm/smp.h linux-2.6.37/arch/x86/include/asm/smp.h
9141 --- linux-2.6.37/arch/x86/include/asm/smp.h 2011-01-04 19:50:19.000000000 -0500
9142 +++ linux-2.6.37/arch/x86/include/asm/smp.h 2011-01-17 02:41:01.000000000 -0500
9143 @@ -24,7 +24,7 @@ extern unsigned int num_processors;
9144 DECLARE_PER_CPU(cpumask_var_t, cpu_sibling_map);
9145 DECLARE_PER_CPU(cpumask_var_t, cpu_core_map);
9146 DECLARE_PER_CPU(u16, cpu_llc_id);
9147 -DECLARE_PER_CPU(int, cpu_number);
9148 +DECLARE_PER_CPU(unsigned int, cpu_number);
9150 static inline struct cpumask *cpu_sibling_mask(int cpu)
9152 diff -urNp linux-2.6.37/arch/x86/include/asm/spinlock.h linux-2.6.37/arch/x86/include/asm/spinlock.h
9153 --- linux-2.6.37/arch/x86/include/asm/spinlock.h 2011-01-04 19:50:19.000000000 -0500
9154 +++ linux-2.6.37/arch/x86/include/asm/spinlock.h 2011-01-17 02:41:01.000000000 -0500
9155 @@ -249,6 +249,14 @@ static inline int arch_write_can_lock(ar
9156 static inline void arch_read_lock(arch_rwlock_t *rw)
9158 asm volatile(LOCK_PREFIX " subl $1,(%0)\n\t"
9160 +#ifdef CONFIG_PAX_REFCOUNT
9162 + LOCK_PREFIX " addl $1,(%0)\n"
9164 + _ASM_EXTABLE(0b, 0b)
9168 "call __read_lock_failed\n\t"
9170 @@ -258,6 +266,14 @@ static inline void arch_read_lock(arch_r
9171 static inline void arch_write_lock(arch_rwlock_t *rw)
9173 asm volatile(LOCK_PREFIX " subl %1,(%0)\n\t"
9175 +#ifdef CONFIG_PAX_REFCOUNT
9177 + LOCK_PREFIX " addl %1,(%0)\n"
9179 + _ASM_EXTABLE(0b, 0b)
9183 "call __write_lock_failed\n\t"
9185 @@ -286,12 +302,29 @@ static inline int arch_write_trylock(arc
9187 static inline void arch_read_unlock(arch_rwlock_t *rw)
9189 - asm volatile(LOCK_PREFIX "incl %0" :"+m" (rw->lock) : : "memory");
9190 + asm volatile(LOCK_PREFIX "incl %0\n"
9192 +#ifdef CONFIG_PAX_REFCOUNT
9194 + LOCK_PREFIX "decl %0\n"
9196 + _ASM_EXTABLE(0b, 0b)
9199 + :"+m" (rw->lock) : : "memory");
9202 static inline void arch_write_unlock(arch_rwlock_t *rw)
9204 - asm volatile(LOCK_PREFIX "addl %1, %0"
9205 + asm volatile(LOCK_PREFIX "addl %1, %0\n"
9207 +#ifdef CONFIG_PAX_REFCOUNT
9209 + LOCK_PREFIX "subl %1, %0\n"
9211 + _ASM_EXTABLE(0b, 0b)
9214 : "+m" (rw->lock) : "i" (RW_LOCK_BIAS) : "memory");
9217 diff -urNp linux-2.6.37/arch/x86/include/asm/stackprotector.h linux-2.6.37/arch/x86/include/asm/stackprotector.h
9218 --- linux-2.6.37/arch/x86/include/asm/stackprotector.h 2011-01-04 19:50:19.000000000 -0500
9219 +++ linux-2.6.37/arch/x86/include/asm/stackprotector.h 2011-01-17 02:41:01.000000000 -0500
9220 @@ -113,7 +113,7 @@ static inline void setup_stack_canary_se
9222 static inline void load_stack_canary_segment(void)
9224 -#ifdef CONFIG_X86_32
9225 +#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
9226 asm volatile ("mov %0, %%gs" : : "r" (0));
9229 diff -urNp linux-2.6.37/arch/x86/include/asm/system.h linux-2.6.37/arch/x86/include/asm/system.h
9230 --- linux-2.6.37/arch/x86/include/asm/system.h 2011-01-04 19:50:19.000000000 -0500
9231 +++ linux-2.6.37/arch/x86/include/asm/system.h 2011-01-17 02:41:01.000000000 -0500
9232 @@ -202,7 +202,7 @@ static inline unsigned long get_limit(un
9234 unsigned long __limit;
9235 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
9236 - return __limit + 1;
9240 static inline void native_clts(void)
9241 @@ -342,7 +342,7 @@ void enable_hlt(void);
9243 void cpu_idle_wait(void);
9245 -extern unsigned long arch_align_stack(unsigned long sp);
9246 +#define arch_align_stack(x) ((x) & ~0xfUL)
9247 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
9249 void default_idle(void);
9250 diff -urNp linux-2.6.37/arch/x86/include/asm/uaccess_32.h linux-2.6.37/arch/x86/include/asm/uaccess_32.h
9251 --- linux-2.6.37/arch/x86/include/asm/uaccess_32.h 2011-01-04 19:50:19.000000000 -0500
9252 +++ linux-2.6.37/arch/x86/include/asm/uaccess_32.h 2011-01-17 02:41:01.000000000 -0500
9253 @@ -44,6 +44,9 @@ unsigned long __must_check __copy_from_u
9254 static __always_inline unsigned long __must_check
9255 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
9260 if (__builtin_constant_p(n)) {
9263 @@ -62,6 +65,8 @@ __copy_to_user_inatomic(void __user *to,
9267 + if (!__builtin_constant_p(n))
9268 + check_object_size(from, n, true);
9269 return __copy_to_user_ll(to, from, n);
9272 @@ -89,6 +94,9 @@ __copy_to_user(void __user *to, const vo
9273 static __always_inline unsigned long
9274 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
9279 /* Avoid zeroing the tail if the copy fails..
9280 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
9281 * but as the zeroing behaviour is only significant when n is not
9282 @@ -138,6 +146,10 @@ static __always_inline unsigned long
9283 __copy_from_user(void *to, const void __user *from, unsigned long n)
9290 if (__builtin_constant_p(n)) {
9293 @@ -153,6 +165,8 @@ __copy_from_user(void *to, const void __
9297 + if (!__builtin_constant_p(n))
9298 + check_object_size(to, n, false);
9299 return __copy_from_user_ll(to, from, n);
9302 @@ -160,6 +174,10 @@ static __always_inline unsigned long __c
9303 const void __user *from, unsigned long n)
9310 if (__builtin_constant_p(n)) {
9313 @@ -182,15 +200,19 @@ static __always_inline unsigned long
9314 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
9317 - return __copy_from_user_ll_nocache_nozero(to, from, n);
9322 -unsigned long __must_check copy_to_user(void __user *to,
9323 - const void *from, unsigned long n);
9324 -unsigned long __must_check _copy_from_user(void *to,
9325 - const void __user *from,
9327 + return __copy_from_user_ll_nocache_nozero(to, from, n);
9330 +extern void copy_to_user_overflow(void)
9331 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
9332 + __compiletime_error("copy_to_user() buffer size is not provably correct")
9334 + __compiletime_warning("copy_to_user() buffer size is not provably correct")
9338 extern void copy_from_user_overflow(void)
9339 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
9340 @@ -200,17 +222,61 @@ extern void copy_from_user_overflow(void
9344 -static inline unsigned long __must_check copy_from_user(void *to,
9345 - const void __user *from,
9348 + * copy_to_user: - Copy a block of data into user space.
9349 + * @to: Destination address, in user space.
9350 + * @from: Source address, in kernel space.
9351 + * @n: Number of bytes to copy.
9353 + * Context: User context only. This function may sleep.
9355 + * Copy data from kernel space to user space.
9357 + * Returns number of bytes that could not be copied.
9358 + * On success, this will be zero.
9360 +static inline unsigned long __must_check
9361 +copy_to_user(void __user *to, const void *from, unsigned long n)
9363 + int sz = __compiletime_object_size(from);
9365 + if (unlikely(sz != -1 && sz < n))
9366 + copy_to_user_overflow();
9367 + else if (access_ok(VERIFY_WRITE, to, n))
9368 + n = __copy_to_user(to, from, n);
9373 + * copy_from_user: - Copy a block of data from user space.
9374 + * @to: Destination address, in kernel space.
9375 + * @from: Source address, in user space.
9376 + * @n: Number of bytes to copy.
9378 + * Context: User context only. This function may sleep.
9380 + * Copy data from user space to kernel space.
9382 + * Returns number of bytes that could not be copied.
9383 + * On success, this will be zero.
9385 + * If some data could not be copied, this function will pad the copied
9386 + * data to the requested size using zero bytes.
9388 +static inline unsigned long __must_check
9389 +copy_from_user(void *to, const void __user *from, unsigned long n)
9391 int sz = __compiletime_object_size(to);
9393 - if (likely(sz == -1 || sz >= n))
9394 - n = _copy_from_user(to, from, n);
9396 + if (unlikely(sz != -1 && sz < n))
9397 copy_from_user_overflow();
9399 + else if (access_ok(VERIFY_READ, from, n))
9400 + n = __copy_from_user(to, from, n);
9401 + else if ((long)n > 0) {
9402 + if (!__builtin_constant_p(n))
9403 + check_object_size(to, n, false);
9409 diff -urNp linux-2.6.37/arch/x86/include/asm/uaccess_64.h linux-2.6.37/arch/x86/include/asm/uaccess_64.h
9410 --- linux-2.6.37/arch/x86/include/asm/uaccess_64.h 2011-01-04 19:50:19.000000000 -0500
9411 +++ linux-2.6.37/arch/x86/include/asm/uaccess_64.h 2011-01-17 02:41:01.000000000 -0500
9413 #include <asm/alternative.h>
9414 #include <asm/cpufeature.h>
9415 #include <asm/page.h>
9416 +#include <asm/pgtable.h>
9418 +#define set_fs(x) (current_thread_info()->addr_limit = (x))
9421 * Copy To/From Userspace
9422 @@ -37,26 +40,26 @@ copy_user_generic(void *to, const void *
9426 -__must_check unsigned long
9427 -_copy_to_user(void __user *to, const void *from, unsigned len);
9428 -__must_check unsigned long
9429 -_copy_from_user(void *to, const void __user *from, unsigned len);
9430 +static __always_inline __must_check unsigned long
9431 +__copy_to_user(void __user *to, const void *from, unsigned len);
9432 +static __always_inline __must_check unsigned long
9433 +__copy_from_user(void *to, const void __user *from, unsigned len);
9434 __must_check unsigned long
9435 copy_in_user(void __user *to, const void __user *from, unsigned len);
9437 static inline unsigned long __must_check copy_from_user(void *to,
9438 const void __user *from,
9442 - int sz = __compiletime_object_size(to);
9445 - if (likely(sz == -1 || sz >= n))
9446 - n = _copy_from_user(to, from, n);
9447 -#ifdef CONFIG_DEBUG_VM
9449 - WARN(1, "Buffer overflow detected!\n");
9452 + if (access_ok(VERIFY_READ, from, n))
9453 + n = __copy_from_user(to, from, n);
9454 + else if ((int)n > 0) {
9455 + if (!__builtin_constant_p(n))
9456 + check_object_size(to, n, false);
9462 @@ -65,110 +68,174 @@ int copy_to_user(void __user *dst, const
9466 - return _copy_to_user(dst, src, size);
9467 + if (access_ok(VERIFY_WRITE, dst, size))
9468 + size = __copy_to_user(dst, src, size);
9472 static __always_inline __must_check
9473 -int __copy_from_user(void *dst, const void __user *src, unsigned size)
9474 +unsigned long __copy_from_user(void *dst, const void __user *src, unsigned size)
9477 + int sz = __compiletime_object_size(dst);
9481 - if (!__builtin_constant_p(size))
9482 - return copy_user_generic(dst, (__force void *)src, size);
9484 + if ((int)size < 0)
9487 +#ifdef CONFIG_PAX_MEMORY_UDEREF
9488 + if (!__access_ok(VERIFY_READ, src, size))
9492 + if (unlikely(sz != -1 && sz < size)) {
9493 +#ifdef CONFIG_DEBUG_VM
9494 + WARN(1, "Buffer overflow detected!\n");
9499 + if (!__builtin_constant_p(size)) {
9500 + check_object_size(dst, size, false);
9501 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
9502 + src += PAX_USER_SHADOW_BASE;
9503 + return copy_user_generic(dst, (__force const void *)src, size);
9506 - case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
9507 + case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
9508 ret, "b", "b", "=q", 1);
9510 - case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
9511 + case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
9512 ret, "w", "w", "=r", 2);
9514 - case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
9515 + case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
9516 ret, "l", "k", "=r", 4);
9518 - case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
9519 + case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
9520 ret, "q", "", "=r", 8);
9523 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
9524 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
9525 ret, "q", "", "=r", 10);
9528 __get_user_asm(*(u16 *)(8 + (char *)dst),
9529 - (u16 __user *)(8 + (char __user *)src),
9530 + (const u16 __user *)(8 + (const char __user *)src),
9531 ret, "w", "w", "=r", 2);
9534 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
9535 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
9536 ret, "q", "", "=r", 16);
9539 __get_user_asm(*(u64 *)(8 + (char *)dst),
9540 - (u64 __user *)(8 + (char __user *)src),
9541 + (const u64 __user *)(8 + (const char __user *)src),
9542 ret, "q", "", "=r", 8);
9545 - return copy_user_generic(dst, (__force void *)src, size);
9546 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
9547 + src += PAX_USER_SHADOW_BASE;
9548 + return copy_user_generic(dst, (__force const void *)src, size);
9552 static __always_inline __must_check
9553 -int __copy_to_user(void __user *dst, const void *src, unsigned size)
9554 +unsigned long __copy_to_user(void __user *dst, const void *src, unsigned size)
9557 + int sz = __compiletime_object_size(src);
9561 - if (!__builtin_constant_p(size))
9563 + if ((int)size < 0)
9566 +#ifdef CONFIG_PAX_MEMORY_UDEREF
9567 + if (!__access_ok(VERIFY_WRITE, dst, size))
9571 + if (unlikely(sz != -1 && sz < size)) {
9572 +#ifdef CONFIG_DEBUG_VM
9573 + WARN(1, "Buffer overflow detected!\n");
9578 + if (!__builtin_constant_p(size)) {
9579 + check_object_size(src, size, true);
9580 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
9581 + dst += PAX_USER_SHADOW_BASE;
9582 return copy_user_generic((__force void *)dst, src, size);
9585 - case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
9586 + case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
9587 ret, "b", "b", "iq", 1);
9589 - case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
9590 + case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
9591 ret, "w", "w", "ir", 2);
9593 - case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
9594 + case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
9595 ret, "l", "k", "ir", 4);
9597 - case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
9598 + case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
9599 ret, "q", "", "er", 8);
9602 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
9603 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
9604 ret, "q", "", "er", 10);
9608 - __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
9609 + __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
9610 ret, "w", "w", "ir", 2);
9613 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
9614 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
9615 ret, "q", "", "er", 16);
9619 - __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
9620 + __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
9621 ret, "q", "", "er", 8);
9624 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
9625 + dst += PAX_USER_SHADOW_BASE;
9626 return copy_user_generic((__force void *)dst, src, size);
9630 static __always_inline __must_check
9631 -int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
9632 +unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned size)
9638 - if (!__builtin_constant_p(size))
9640 + if ((int)size < 0)
9643 +#ifdef CONFIG_PAX_MEMORY_UDEREF
9644 + if (!__access_ok(VERIFY_READ, src, size))
9646 + if (!__access_ok(VERIFY_WRITE, dst, size))
9650 + if (!__builtin_constant_p(size)) {
9651 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
9652 + src += PAX_USER_SHADOW_BASE;
9653 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
9654 + dst += PAX_USER_SHADOW_BASE;
9655 return copy_user_generic((__force void *)dst,
9656 - (__force void *)src, size);
9657 + (__force const void *)src, size);
9662 - __get_user_asm(tmp, (u8 __user *)src,
9663 + __get_user_asm(tmp, (const u8 __user *)src,
9664 ret, "b", "b", "=q", 1);
9666 __put_user_asm(tmp, (u8 __user *)dst,
9667 @@ -177,7 +244,7 @@ int __copy_in_user(void __user *dst, con
9671 - __get_user_asm(tmp, (u16 __user *)src,
9672 + __get_user_asm(tmp, (const u16 __user *)src,
9673 ret, "w", "w", "=r", 2);
9675 __put_user_asm(tmp, (u16 __user *)dst,
9676 @@ -187,7 +254,7 @@ int __copy_in_user(void __user *dst, con
9680 - __get_user_asm(tmp, (u32 __user *)src,
9681 + __get_user_asm(tmp, (const u32 __user *)src,
9682 ret, "l", "k", "=r", 4);
9684 __put_user_asm(tmp, (u32 __user *)dst,
9685 @@ -196,7 +263,7 @@ int __copy_in_user(void __user *dst, con
9689 - __get_user_asm(tmp, (u64 __user *)src,
9690 + __get_user_asm(tmp, (const u64 __user *)src,
9691 ret, "q", "", "=r", 8);
9693 __put_user_asm(tmp, (u64 __user *)dst,
9694 @@ -204,8 +271,12 @@ int __copy_in_user(void __user *dst, con
9698 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
9699 + src += PAX_USER_SHADOW_BASE;
9700 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
9701 + dst += PAX_USER_SHADOW_BASE;
9702 return copy_user_generic((__force void *)dst,
9703 - (__force void *)src, size);
9704 + (__force const void *)src, size);
9708 @@ -222,33 +293,68 @@ __must_check unsigned long __clear_user(
9709 static __must_check __always_inline int
9710 __copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
9712 + if ((int)size < 0)
9715 +#ifdef CONFIG_PAX_MEMORY_UDEREF
9716 + if (!__access_ok(VERIFY_READ, src, size))
9720 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
9721 + src += PAX_USER_SHADOW_BASE;
9722 return copy_user_generic(dst, (__force const void *)src, size);
9725 -static __must_check __always_inline int
9726 +static __must_check __always_inline unsigned long
9727 __copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
9729 + if ((int)size < 0)
9732 +#ifdef CONFIG_PAX_MEMORY_UDEREF
9733 + if (!__access_ok(VERIFY_WRITE, dst, size))
9737 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
9738 + dst += PAX_USER_SHADOW_BASE;
9739 return copy_user_generic((__force void *)dst, src, size);
9742 -extern long __copy_user_nocache(void *dst, const void __user *src,
9743 +extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
9744 unsigned size, int zerorest);
9747 -__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
9748 +static inline unsigned long __copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
9752 + if ((int)size < 0)
9755 +#ifdef CONFIG_PAX_MEMORY_UDEREF
9756 + if (!__access_ok(VERIFY_READ, src, size))
9760 return __copy_user_nocache(dst, src, size, 1);
9764 -__copy_from_user_inatomic_nocache(void *dst, const void __user *src,
9765 +static inline unsigned long __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
9768 + if ((int)size < 0)
9771 +#ifdef CONFIG_PAX_MEMORY_UDEREF
9772 + if (!__access_ok(VERIFY_READ, src, size))
9776 return __copy_user_nocache(dst, src, size, 0);
9780 +extern unsigned long
9781 copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
9783 #endif /* _ASM_X86_UACCESS_64_H */
9784 diff -urNp linux-2.6.37/arch/x86/include/asm/uaccess.h linux-2.6.37/arch/x86/include/asm/uaccess.h
9785 --- linux-2.6.37/arch/x86/include/asm/uaccess.h 2011-01-04 19:50:19.000000000 -0500
9786 +++ linux-2.6.37/arch/x86/include/asm/uaccess.h 2011-01-17 02:41:01.000000000 -0500
9788 #include <linux/thread_info.h>
9789 #include <linux/prefetch.h>
9790 #include <linux/string.h>
9791 +#include <linux/sched.h>
9792 #include <asm/asm.h>
9793 #include <asm/page.h>
9795 #define VERIFY_READ 0
9796 #define VERIFY_WRITE 1
9798 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
9801 * The fs value determines whether argument validity checking should be
9802 * performed or not. If get_fs() == USER_DS, checking is performed, with
9805 #define get_ds() (KERNEL_DS)
9806 #define get_fs() (current_thread_info()->addr_limit)
9807 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
9808 +void __set_fs(mm_segment_t x);
9809 +void set_fs(mm_segment_t x);
9811 #define set_fs(x) (current_thread_info()->addr_limit = (x))
9814 #define segment_eq(a, b) ((a).seg == (b).seg)
9817 * checks that the pointer is in the user space range - after calling
9818 * this function, memory access functions may still return -EFAULT.
9820 -#define access_ok(type, addr, size) (likely(__range_not_ok(addr, size) == 0))
9821 +#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size) == 0))
9822 +#define access_ok(type, addr, size) \
9824 + long __size = size; \
9825 + unsigned long __addr = (unsigned long)addr; \
9826 + unsigned long __addr_ao = __addr & PAGE_MASK; \
9827 + unsigned long __end_ao = __addr + __size - 1; \
9828 + bool __ret_ao = __range_not_ok(__addr, __size) == 0; \
9829 + if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
9830 + while(__addr_ao <= __end_ao) { \
9832 + __addr_ao += PAGE_SIZE; \
9833 + if (__size > PAGE_SIZE) \
9835 + if (__get_user(__c_ao, (char __user *)__addr)) \
9837 + if (type != VERIFY_WRITE) { \
9838 + __addr = __addr_ao; \
9841 + if (__put_user(__c_ao, (char __user *)__addr)) \
9843 + __addr = __addr_ao; \
9850 * The exception table consists of pairs of addresses: the first is the
9851 @@ -183,12 +217,20 @@ extern int __get_user_bad(void);
9852 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
9853 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
9856 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
9857 +#define __copyuser_seg "%%gs:"
9858 +#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
9859 +#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
9861 +#define __copyuser_seg
9862 +#define __COPYUSER_SET_ES
9863 +#define __COPYUSER_RESTORE_ES
9866 #ifdef CONFIG_X86_32
9867 #define __put_user_asm_u64(x, addr, err, errret) \
9868 - asm volatile("1: movl %%eax,0(%2)\n" \
9869 - "2: movl %%edx,4(%2)\n" \
9870 + asm volatile("1: movl %%eax," __copyuser_seg"0(%2)\n" \
9871 + "2: movl %%edx," __copyuser_seg"4(%2)\n" \
9873 ".section .fixup,\"ax\"\n" \
9875 @@ -200,8 +242,8 @@ extern int __get_user_bad(void);
9876 : "A" (x), "r" (addr), "i" (errret), "0" (err))
9878 #define __put_user_asm_ex_u64(x, addr) \
9879 - asm volatile("1: movl %%eax,0(%1)\n" \
9880 - "2: movl %%edx,4(%1)\n" \
9881 + asm volatile("1: movl %%eax," __copyuser_seg"0(%1)\n" \
9882 + "2: movl %%edx," __copyuser_seg"4(%1)\n" \
9884 _ASM_EXTABLE(1b, 2b - 1b) \
9885 _ASM_EXTABLE(2b, 3b - 2b) \
9886 @@ -374,7 +416,7 @@ do { \
9889 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
9890 - asm volatile("1: mov"itype" %2,%"rtype"1\n" \
9891 + asm volatile("1: mov"itype" "__copyuser_seg"%2,%"rtype"1\n"\
9893 ".section .fixup,\"ax\"\n" \
9895 @@ -382,7 +424,7 @@ do { \
9898 _ASM_EXTABLE(1b, 3b) \
9899 - : "=r" (err), ltype(x) \
9900 + : "=r" (err), ltype (x) \
9901 : "m" (__m(addr)), "i" (errret), "0" (err))
9903 #define __get_user_size_ex(x, ptr, size) \
9904 @@ -407,7 +449,7 @@ do { \
9907 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
9908 - asm volatile("1: mov"itype" %1,%"rtype"0\n" \
9909 + asm volatile("1: mov"itype" "__copyuser_seg"%1,%"rtype"0\n"\
9911 _ASM_EXTABLE(1b, 2b - 1b) \
9912 : ltype(x) : "m" (__m(addr)))
9913 @@ -424,13 +466,24 @@ do { \
9915 unsigned long __gu_val; \
9916 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
9917 - (x) = (__force __typeof__(*(ptr)))__gu_val; \
9918 + (x) = (__typeof__(*(ptr)))__gu_val; \
9922 /* FIXME: this hack is definitely wrong -AK */
9923 struct __large_struct { unsigned long buf[100]; };
9924 -#define __m(x) (*(struct __large_struct __user *)(x))
9925 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
9928 + unsigned long ____x = (unsigned long)(x); \
9929 + if (____x < PAX_USER_SHADOW_BASE) \
9930 + ____x += PAX_USER_SHADOW_BASE; \
9931 + (void __user *)____x; \
9934 +#define ____m(x) (x)
9936 +#define __m(x) (*(struct __large_struct __user *)____m(x))
9939 * Tell gcc we read from memory instead of writing: this is because
9940 @@ -438,7 +491,7 @@ struct __large_struct { unsigned long bu
9943 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
9944 - asm volatile("1: mov"itype" %"rtype"1,%2\n" \
9945 + asm volatile("1: mov"itype" %"rtype"1," __copyuser_seg"%2\n"\
9947 ".section .fixup,\"ax\"\n" \
9949 @@ -446,10 +499,10 @@ struct __large_struct { unsigned long bu
9951 _ASM_EXTABLE(1b, 3b) \
9953 - : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
9954 + : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err))
9956 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
9957 - asm volatile("1: mov"itype" %"rtype"0,%1\n" \
9958 + asm volatile("1: mov"itype" %"rtype"0," __copyuser_seg"%1\n"\
9960 _ASM_EXTABLE(1b, 2b - 1b) \
9961 : : ltype(x), "m" (__m(addr)))
9962 @@ -488,8 +541,12 @@ struct __large_struct { unsigned long bu
9963 * On error, the variable @x is set to zero.
9966 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
9967 +#define __get_user(x, ptr) get_user((x), (ptr))
9969 #define __get_user(x, ptr) \
9970 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
9974 * __put_user: - Write a simple value into user space, with less checking.
9975 @@ -511,8 +568,12 @@ struct __large_struct { unsigned long bu
9976 * Returns zero on success, or -EFAULT on error.
9979 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
9980 +#define __put_user(x, ptr) put_user((x), (ptr))
9982 #define __put_user(x, ptr) \
9983 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
9986 #define __get_user_unaligned __get_user
9987 #define __put_user_unaligned __put_user
9988 @@ -530,7 +591,7 @@ struct __large_struct { unsigned long bu
9989 #define get_user_ex(x, ptr) do { \
9990 unsigned long __gue_val; \
9991 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
9992 - (x) = (__force __typeof__(*(ptr)))__gue_val; \
9993 + (x) = (__typeof__(*(ptr)))__gue_val; \
9996 #ifdef CONFIG_X86_WP_WORKS_OK
9997 @@ -567,6 +628,7 @@ extern struct movsl_mask {
9999 #define ARCH_HAS_NOCACHE_UACCESS 1
10001 +#define ARCH_HAS_SORT_EXTABLE
10002 #ifdef CONFIG_X86_32
10003 # include "uaccess_32.h"
10005 diff -urNp linux-2.6.37/arch/x86/include/asm/vgtod.h linux-2.6.37/arch/x86/include/asm/vgtod.h
10006 --- linux-2.6.37/arch/x86/include/asm/vgtod.h 2011-01-04 19:50:19.000000000 -0500
10007 +++ linux-2.6.37/arch/x86/include/asm/vgtod.h 2011-01-17 02:41:01.000000000 -0500
10008 @@ -14,6 +14,7 @@ struct vsyscall_gtod_data {
10009 int sysctl_enabled;
10010 struct timezone sys_tz;
10011 struct { /* extract of a clocksource struct */
10013 cycle_t (*vread)(void);
10014 cycle_t cycle_last;
10016 diff -urNp linux-2.6.37/arch/x86/include/asm/vsyscall.h linux-2.6.37/arch/x86/include/asm/vsyscall.h
10017 --- linux-2.6.37/arch/x86/include/asm/vsyscall.h 2011-01-04 19:50:19.000000000 -0500
10018 +++ linux-2.6.37/arch/x86/include/asm/vsyscall.h 2011-01-17 02:41:01.000000000 -0500
10019 @@ -15,9 +15,10 @@ enum vsyscall_num {
10022 #include <linux/seqlock.h>
10023 +#include <linux/getcpu.h>
10024 +#include <linux/time.h>
10026 #define __section_vgetcpu_mode __attribute__ ((unused, __section__ (".vgetcpu_mode"), aligned(16)))
10027 -#define __section_jiffies __attribute__ ((unused, __section__ (".jiffies"), aligned(16)))
10029 /* Definitions for CONFIG_GENERIC_TIME definitions */
10030 #define __section_vsyscall_gtod_data __attribute__ \
10031 @@ -31,7 +32,6 @@ enum vsyscall_num {
10032 #define VGETCPU_LSL 2
10034 extern int __vgetcpu_mode;
10035 -extern volatile unsigned long __jiffies;
10037 /* kernel space (writeable) */
10038 extern int vgetcpu_mode;
10039 @@ -39,6 +39,9 @@ extern struct timezone sys_tz;
10041 extern void map_vsyscall(void);
10043 +extern int vgettimeofday(struct timeval * tv, struct timezone * tz);
10044 +extern time_t vtime(time_t *t);
10045 +extern long vgetcpu(unsigned *cpu, unsigned *node, struct getcpu_cache *tcache);
10046 #endif /* __KERNEL__ */
10048 #endif /* _ASM_X86_VSYSCALL_H */
10049 diff -urNp linux-2.6.37/arch/x86/include/asm/xsave.h linux-2.6.37/arch/x86/include/asm/xsave.h
10050 --- linux-2.6.37/arch/x86/include/asm/xsave.h 2011-01-04 19:50:19.000000000 -0500
10051 +++ linux-2.6.37/arch/x86/include/asm/xsave.h 2011-01-17 02:41:01.000000000 -0500
10052 @@ -65,6 +65,11 @@ static inline int xsave_user(struct xsav
10056 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10057 + if ((unsigned long)buf < PAX_USER_SHADOW_BASE)
10058 + buf = (struct xsave_struct __user *)((void __user*)buf + PAX_USER_SHADOW_BASE);
10062 * Clear the xsave header first, so that reserved fields are
10063 * initialized to zero.
10064 @@ -100,6 +105,11 @@ static inline int xrestore_user(struct x
10066 u32 hmask = mask >> 32;
10068 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10069 + if ((unsigned long)xstate < PAX_USER_SHADOW_BASE)
10070 + xstate = (struct xsave_struct *)((void *)xstate + PAX_USER_SHADOW_BASE);
10073 __asm__ __volatile__("1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
10075 ".section .fixup,\"ax\"\n"
10076 diff -urNp linux-2.6.37/arch/x86/Kconfig linux-2.6.37/arch/x86/Kconfig
10077 --- linux-2.6.37/arch/x86/Kconfig 2011-01-04 19:50:19.000000000 -0500
10078 +++ linux-2.6.37/arch/x86/Kconfig 2011-01-17 02:41:01.000000000 -0500
10079 @@ -225,7 +225,7 @@ config X86_TRAMPOLINE
10081 config X86_32_LAZY_GS
10083 - depends on X86_32 && !CC_STACKPROTECTOR
10084 + depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
10086 config ARCH_HWEIGHT_CFLAGS
10088 @@ -992,7 +992,7 @@ choice
10092 - depends on !X86_NUMAQ
10093 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
10095 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
10096 However, the address space of 32-bit x86 processors is only 4
10097 @@ -1029,7 +1029,7 @@ config NOHIGHMEM
10101 - depends on !X86_NUMAQ
10102 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
10104 Select this if you have a 32-bit processor and between 1 and 4
10105 gigabytes of physical RAM.
10106 @@ -1083,7 +1083,7 @@ config PAGE_OFFSET
10108 default 0xB0000000 if VMSPLIT_3G_OPT
10109 default 0x80000000 if VMSPLIT_2G
10110 - default 0x78000000 if VMSPLIT_2G_OPT
10111 + default 0x70000000 if VMSPLIT_2G_OPT
10112 default 0x40000000 if VMSPLIT_1G
10115 @@ -1427,7 +1427,7 @@ config ARCH_USES_PG_UNCACHED
10118 bool "EFI runtime service support"
10120 + depends on ACPI && !PAX_KERNEXEC
10122 This enables the kernel to use EFI runtime services that are
10123 available (such as the EFI variable services).
10124 @@ -1457,6 +1457,7 @@ config SECCOMP
10126 config CC_STACKPROTECTOR
10127 bool "Enable -fstack-protector buffer overflow detection (EXPERIMENTAL)"
10128 + depends on X86_64 || !PAX_MEMORY_UDEREF
10130 This option turns on the -fstack-protector GCC feature. This
10131 feature puts, at the beginning of functions, a canary value on
10132 @@ -1514,6 +1515,7 @@ config KEXEC_JUMP
10133 config PHYSICAL_START
10134 hex "Physical address where the kernel is loaded" if (EMBEDDED || CRASH_DUMP)
10135 default "0x1000000"
10136 + range 0x400000 0x40000000
10138 This gives the physical address where the kernel is loaded.
10140 @@ -1577,6 +1579,7 @@ config X86_NEED_RELOCS
10141 config PHYSICAL_ALIGN
10142 hex "Alignment value to which kernel should be aligned" if X86_32
10143 default "0x1000000"
10144 + range 0x400000 0x1000000 if PAX_KERNEXEC
10145 range 0x2000 0x1000000
10147 This value puts the alignment restrictions on physical address
10148 @@ -1608,9 +1611,10 @@ config HOTPLUG_CPU
10149 Say N if you want to disable CPU hotplug.
10154 prompt "Compat VDSO support"
10155 depends on X86_32 || IA32_EMULATION
10156 + depends on !PAX_NOEXEC && !PAX_MEMORY_UDEREF
10158 Map the 32-bit VDSO to the predictable old-style address too.
10160 diff -urNp linux-2.6.37/arch/x86/Kconfig.cpu linux-2.6.37/arch/x86/Kconfig.cpu
10161 --- linux-2.6.37/arch/x86/Kconfig.cpu 2011-01-04 19:50:19.000000000 -0500
10162 +++ linux-2.6.37/arch/x86/Kconfig.cpu 2011-01-17 02:41:01.000000000 -0500
10163 @@ -336,7 +336,7 @@ config X86_PPRO_FENCE
10165 config X86_F00F_BUG
10167 - depends on M586MMX || M586TSC || M586 || M486 || M386
10168 + depends on (M586MMX || M586TSC || M586 || M486 || M386) && !PAX_KERNEXEC
10170 config X86_INVD_BUG
10172 @@ -360,7 +360,7 @@ config X86_POPAD_OK
10174 config X86_ALIGNMENT_16
10176 - depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
10177 + depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
10179 config X86_INTEL_USERCOPY
10181 @@ -406,7 +406,7 @@ config X86_CMPXCHG64
10185 - depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
10186 + depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
10188 config X86_MINIMUM_CPU_FAMILY
10190 diff -urNp linux-2.6.37/arch/x86/Kconfig.debug linux-2.6.37/arch/x86/Kconfig.debug
10191 --- linux-2.6.37/arch/x86/Kconfig.debug 2011-01-04 19:50:19.000000000 -0500
10192 +++ linux-2.6.37/arch/x86/Kconfig.debug 2011-01-17 02:41:01.000000000 -0500
10193 @@ -101,7 +101,7 @@ config X86_PTDUMP
10194 config DEBUG_RODATA
10195 bool "Write protect kernel read-only data structures"
10197 - depends on DEBUG_KERNEL
10198 + depends on DEBUG_KERNEL && BROKEN
10200 Mark the kernel read-only data as write-protected in the pagetables,
10201 in order to catch accidental (and incorrect) writes to such const
10202 diff -urNp linux-2.6.37/arch/x86/kernel/acpi/boot.c linux-2.6.37/arch/x86/kernel/acpi/boot.c
10203 --- linux-2.6.37/arch/x86/kernel/acpi/boot.c 2011-01-04 19:50:19.000000000 -0500
10204 +++ linux-2.6.37/arch/x86/kernel/acpi/boot.c 2011-01-17 02:41:01.000000000 -0500
10205 @@ -1498,7 +1498,7 @@ static struct dmi_system_id __initdata a
10206 DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq 6715b"),
10210 + { NULL, NULL, {{0, {0}}}, NULL}
10214 diff -urNp linux-2.6.37/arch/x86/kernel/acpi/sleep.c linux-2.6.37/arch/x86/kernel/acpi/sleep.c
10215 --- linux-2.6.37/arch/x86/kernel/acpi/sleep.c 2011-01-04 19:50:19.000000000 -0500
10216 +++ linux-2.6.37/arch/x86/kernel/acpi/sleep.c 2011-01-17 02:41:01.000000000 -0500
10218 #include <linux/cpumask.h>
10219 #include <asm/segment.h>
10220 #include <asm/desc.h>
10221 +#include <asm/e820.h>
10223 #ifdef CONFIG_X86_32
10224 #include <asm/pgtable.h>
10226 #include "realmode/wakeup.h"
10229 -unsigned long acpi_wakeup_address;
10230 +unsigned long acpi_wakeup_address = 0x2000;
10231 unsigned long acpi_realmode_flags;
10233 /* address in low memory of the wakeup routine. */
10234 @@ -101,8 +102,12 @@ int acpi_save_state_mem(void)
10235 header->trampoline_segment = setup_trampoline() >> 4;
10237 stack_start.sp = temp_stack + sizeof(temp_stack);
10239 + pax_open_kernel();
10240 early_gdt_descr.address =
10241 (unsigned long)get_cpu_gdt_table(smp_processor_id());
10242 + pax_close_kernel();
10244 initial_gs = per_cpu_offset(smp_processor_id());
10246 initial_code = (unsigned long)wakeup_long64;
10247 diff -urNp linux-2.6.37/arch/x86/kernel/acpi/wakeup_32.S linux-2.6.37/arch/x86/kernel/acpi/wakeup_32.S
10248 --- linux-2.6.37/arch/x86/kernel/acpi/wakeup_32.S 2011-01-04 19:50:19.000000000 -0500
10249 +++ linux-2.6.37/arch/x86/kernel/acpi/wakeup_32.S 2011-01-17 02:41:01.000000000 -0500
10250 @@ -30,13 +30,11 @@ wakeup_pmode_return:
10251 # and restore the stack ... but you need gdt for this to work
10252 movl saved_context_esp, %esp
10254 - movl %cs:saved_magic, %eax
10255 - cmpl $0x12345678, %eax
10256 + cmpl $0x12345678, saved_magic
10259 # jump to place where we left off
10260 - movl saved_eip, %eax
10266 diff -urNp linux-2.6.37/arch/x86/kernel/alternative.c linux-2.6.37/arch/x86/kernel/alternative.c
10267 --- linux-2.6.37/arch/x86/kernel/alternative.c 2011-01-04 19:50:19.000000000 -0500
10268 +++ linux-2.6.37/arch/x86/kernel/alternative.c 2011-01-17 02:41:01.000000000 -0500
10269 @@ -248,7 +248,7 @@ static void alternatives_smp_lock(const
10270 if (!*poff || ptr < text || ptr >= text_end)
10272 /* turn DS segment override prefix into lock prefix */
10273 - if (*ptr == 0x3e)
10274 + if (*ktla_ktva(ptr) == 0x3e)
10275 text_poke(ptr, ((unsigned char []){0xf0}), 1);
10277 mutex_unlock(&text_mutex);
10278 @@ -269,7 +269,7 @@ static void alternatives_smp_unlock(cons
10279 if (!*poff || ptr < text || ptr >= text_end)
10281 /* turn lock prefix into DS segment override prefix */
10282 - if (*ptr == 0xf0)
10283 + if (*ktla_ktva(ptr) == 0xf0)
10284 text_poke(ptr, ((unsigned char []){0x3E}), 1);
10286 mutex_unlock(&text_mutex);
10287 @@ -437,7 +437,7 @@ void __init_or_module apply_paravirt(str
10289 BUG_ON(p->len > MAX_PATCH_LEN);
10290 /* prep the buffer with the original instructions */
10291 - memcpy(insnbuf, p->instr, p->len);
10292 + memcpy(insnbuf, ktla_ktva(p->instr), p->len);
10293 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
10294 (unsigned long)p->instr, p->len);
10296 @@ -505,7 +505,7 @@ void __init alternative_instructions(voi
10298 free_init_pages("SMP alternatives",
10299 (unsigned long)__smp_locks,
10300 - (unsigned long)__smp_locks_end);
10301 + PAGE_ALIGN((unsigned long)__smp_locks_end));
10305 @@ -522,13 +522,17 @@ void __init alternative_instructions(voi
10306 * instructions. And on the local CPU you need to be protected again NMI or MCE
10307 * handlers seeing an inconsistent instruction while you patch.
10309 -void *__init_or_module text_poke_early(void *addr, const void *opcode,
10310 +void *__kprobes text_poke_early(void *addr, const void *opcode,
10313 unsigned long flags;
10314 local_irq_save(flags);
10315 - memcpy(addr, opcode, len);
10317 + pax_open_kernel();
10318 + memcpy(ktla_ktva(addr), opcode, len);
10320 + pax_close_kernel();
10322 local_irq_restore(flags);
10323 /* Could also do a CLFLUSH here to speed up CPU recovery; but
10324 that causes hangs on some VIA CPUs. */
10325 @@ -550,36 +554,22 @@ void *__init_or_module text_poke_early(v
10327 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
10329 - unsigned long flags;
10331 + unsigned char *vaddr = ktla_ktva(addr);
10332 struct page *pages[2];
10336 if (!core_kernel_text((unsigned long)addr)) {
10337 - pages[0] = vmalloc_to_page(addr);
10338 - pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
10339 + pages[0] = vmalloc_to_page(vaddr);
10340 + pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
10342 - pages[0] = virt_to_page(addr);
10343 + pages[0] = virt_to_page(vaddr);
10344 WARN_ON(!PageReserved(pages[0]));
10345 - pages[1] = virt_to_page(addr + PAGE_SIZE);
10346 + pages[1] = virt_to_page(vaddr + PAGE_SIZE);
10349 - local_irq_save(flags);
10350 - set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
10352 - set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
10353 - vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
10354 - memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
10355 - clear_fixmap(FIX_TEXT_POKE0);
10357 - clear_fixmap(FIX_TEXT_POKE1);
10358 - local_flush_tlb();
10360 - /* Could also do a CLFLUSH here to speed up CPU recovery; but
10361 - that causes hangs on some VIA CPUs. */
10362 + text_poke_early(addr, opcode, len);
10363 for (i = 0; i < len; i++)
10364 - BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
10365 - local_irq_restore(flags);
10366 + BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
10370 @@ -645,9 +635,9 @@ void *__kprobes text_poke_smp(void *addr
10371 #if defined(CONFIG_DYNAMIC_FTRACE) || defined(HAVE_JUMP_LABEL)
10373 #ifdef CONFIG_X86_64
10374 -unsigned char ideal_nop5[5] = { 0x66, 0x66, 0x66, 0x66, 0x90 };
10375 +unsigned char ideal_nop5[5] __read_only = { 0x66, 0x66, 0x66, 0x66, 0x90 };
10377 -unsigned char ideal_nop5[5] = { 0x3e, 0x8d, 0x74, 0x26, 0x00 };
10378 +unsigned char ideal_nop5[5] __read_only = { 0x3e, 0x8d, 0x74, 0x26, 0x00 };
10381 void __init arch_init_ideal_nop5(void)
10382 diff -urNp linux-2.6.37/arch/x86/kernel/amd_iommu.c linux-2.6.37/arch/x86/kernel/amd_iommu.c
10383 --- linux-2.6.37/arch/x86/kernel/amd_iommu.c 2011-01-04 19:50:19.000000000 -0500
10384 +++ linux-2.6.37/arch/x86/kernel/amd_iommu.c 2011-01-17 02:41:01.000000000 -0500
10385 @@ -2286,7 +2286,7 @@ static void prealloc_protection_domains(
10389 -static struct dma_map_ops amd_iommu_dma_ops = {
10390 +static const struct dma_map_ops amd_iommu_dma_ops = {
10391 .alloc_coherent = alloc_coherent,
10392 .free_coherent = free_coherent,
10393 .map_page = map_page,
10394 diff -urNp linux-2.6.37/arch/x86/kernel/apic/io_apic.c linux-2.6.37/arch/x86/kernel/apic/io_apic.c
10395 --- linux-2.6.37/arch/x86/kernel/apic/io_apic.c 2011-01-04 19:50:19.000000000 -0500
10396 +++ linux-2.6.37/arch/x86/kernel/apic/io_apic.c 2011-01-17 02:41:01.000000000 -0500
10397 @@ -597,7 +597,7 @@ struct IO_APIC_route_entry **alloc_ioapi
10398 ioapic_entries = kzalloc(sizeof(*ioapic_entries) * nr_ioapics,
10400 if (!ioapic_entries)
10404 for (apic = 0; apic < nr_ioapics; apic++) {
10405 ioapic_entries[apic] =
10406 @@ -614,7 +614,7 @@ nomem:
10407 kfree(ioapic_entries[apic]);
10408 kfree(ioapic_entries);
10415 @@ -1024,7 +1024,7 @@ int IO_APIC_get_PCI_irq_vector(int bus,
10417 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
10419 -void lock_vector_lock(void)
10420 +void lock_vector_lock(void) __acquires(vector_lock)
10422 /* Used to the online set of cpus does not change
10423 * during assign_irq_vector.
10424 @@ -1032,7 +1032,7 @@ void lock_vector_lock(void)
10425 raw_spin_lock(&vector_lock);
10428 -void unlock_vector_lock(void)
10429 +void unlock_vector_lock(void) __releases(vector_lock)
10431 raw_spin_unlock(&vector_lock);
10433 diff -urNp linux-2.6.37/arch/x86/kernel/apm_32.c linux-2.6.37/arch/x86/kernel/apm_32.c
10434 --- linux-2.6.37/arch/x86/kernel/apm_32.c 2011-01-04 19:50:19.000000000 -0500
10435 +++ linux-2.6.37/arch/x86/kernel/apm_32.c 2011-01-17 02:41:01.000000000 -0500
10436 @@ -410,7 +410,7 @@ static DEFINE_MUTEX(apm_mutex);
10437 * This is for buggy BIOS's that refer to (real mode) segment 0x40
10438 * even though they are called in protected mode.
10440 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
10441 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
10442 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
10444 static const char driver_version[] = "1.16ac"; /* no spaces */
10445 @@ -588,7 +588,10 @@ static long __apm_bios_call(void *_call)
10447 gdt = get_cpu_gdt_table(cpu);
10448 save_desc_40 = gdt[0x40 / 8];
10450 + pax_open_kernel();
10451 gdt[0x40 / 8] = bad_bios_desc;
10452 + pax_close_kernel();
10454 apm_irq_save(flags);
10456 @@ -597,7 +600,11 @@ static long __apm_bios_call(void *_call)
10458 APM_DO_RESTORE_SEGS;
10459 apm_irq_restore(flags);
10461 + pax_open_kernel();
10462 gdt[0x40 / 8] = save_desc_40;
10463 + pax_close_kernel();
10467 return call->eax & 0xff;
10468 @@ -664,7 +671,10 @@ static long __apm_bios_call_simple(void
10470 gdt = get_cpu_gdt_table(cpu);
10471 save_desc_40 = gdt[0x40 / 8];
10473 + pax_open_kernel();
10474 gdt[0x40 / 8] = bad_bios_desc;
10475 + pax_close_kernel();
10477 apm_irq_save(flags);
10479 @@ -672,7 +682,11 @@ static long __apm_bios_call_simple(void
10481 APM_DO_RESTORE_SEGS;
10482 apm_irq_restore(flags);
10484 + pax_open_kernel();
10485 gdt[0x40 / 8] = save_desc_40;
10486 + pax_close_kernel();
10491 @@ -975,7 +989,7 @@ recalc:
10493 static void apm_power_off(void)
10495 - unsigned char po_bios_call[] = {
10496 + const unsigned char po_bios_call[] = {
10497 0xb8, 0x00, 0x10, /* movw $0x1000,ax */
10498 0x8e, 0xd0, /* movw ax,ss */
10499 0xbc, 0x00, 0xf0, /* movw $0xf000,sp */
10500 @@ -1932,7 +1946,10 @@ static const struct file_operations apm_
10501 static struct miscdevice apm_device = {
10512 @@ -2253,7 +2270,7 @@ static struct dmi_system_id __initdata a
10513 { DMI_MATCH(DMI_SYS_VENDOR, "IBM"), },
10517 + { NULL, NULL, {DMI_MATCH(DMI_NONE, {0})}, NULL}
10521 @@ -2356,12 +2373,15 @@ static int __init apm_init(void)
10522 * code to that CPU.
10524 gdt = get_cpu_gdt_table(0);
10526 + pax_open_kernel();
10527 set_desc_base(&gdt[APM_CS >> 3],
10528 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
10529 set_desc_base(&gdt[APM_CS_16 >> 3],
10530 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
10531 set_desc_base(&gdt[APM_DS >> 3],
10532 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
10533 + pax_close_kernel();
10535 proc_create("apm", 0, NULL, &apm_file_ops);
10537 diff -urNp linux-2.6.37/arch/x86/kernel/asm-offsets_32.c linux-2.6.37/arch/x86/kernel/asm-offsets_32.c
10538 --- linux-2.6.37/arch/x86/kernel/asm-offsets_32.c 2011-01-04 19:50:19.000000000 -0500
10539 +++ linux-2.6.37/arch/x86/kernel/asm-offsets_32.c 2011-01-17 02:41:01.000000000 -0500
10540 @@ -113,6 +113,11 @@ void foo(void)
10541 OFFSET(PV_CPU_iret, pv_cpu_ops, iret);
10542 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
10543 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
10545 +#ifdef CONFIG_PAX_KERNEXEC
10546 + OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
10552 diff -urNp linux-2.6.37/arch/x86/kernel/asm-offsets_64.c linux-2.6.37/arch/x86/kernel/asm-offsets_64.c
10553 --- linux-2.6.37/arch/x86/kernel/asm-offsets_64.c 2011-01-04 19:50:19.000000000 -0500
10554 +++ linux-2.6.37/arch/x86/kernel/asm-offsets_64.c 2011-01-17 02:41:01.000000000 -0500
10555 @@ -63,6 +63,18 @@ int main(void)
10556 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
10557 OFFSET(PV_CPU_swapgs, pv_cpu_ops, swapgs);
10558 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
10560 +#ifdef CONFIG_PAX_KERNEXEC
10561 + OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
10562 + OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
10565 +#ifdef CONFIG_PAX_MEMORY_UDEREF
10566 + OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
10567 + OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
10568 + OFFSET(PV_MMU_set_pgd, pv_mmu_ops, set_pgd);
10574 @@ -115,6 +127,7 @@ int main(void)
10578 + DEFINE(TSS_size, sizeof(struct tss_struct));
10579 DEFINE(TSS_ist, offsetof(struct tss_struct, x86_tss.ist));
10581 DEFINE(crypto_tfm_ctx_offset, offsetof(struct crypto_tfm, __crt_ctx));
10582 diff -urNp linux-2.6.37/arch/x86/kernel/cpu/common.c linux-2.6.37/arch/x86/kernel/cpu/common.c
10583 --- linux-2.6.37/arch/x86/kernel/cpu/common.c 2011-01-04 19:50:19.000000000 -0500
10584 +++ linux-2.6.37/arch/x86/kernel/cpu/common.c 2011-01-17 02:41:01.000000000 -0500
10585 @@ -83,60 +83,6 @@ static const struct cpu_dev __cpuinitcon
10587 static const struct cpu_dev *this_cpu __cpuinitdata = &default_cpu;
10589 -DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
10590 -#ifdef CONFIG_X86_64
10592 - * We need valid kernel segments for data and code in long mode too
10593 - * IRET will check the segment types kkeil 2000/10/28
10594 - * Also sysret mandates a special GDT layout
10596 - * TLS descriptors are currently at a different place compared to i386.
10597 - * Hopefully nobody expects them at a fixed place (Wine?)
10599 - [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
10600 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
10601 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
10602 - [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
10603 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
10604 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
10606 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
10607 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
10608 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
10609 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
10611 - * Segments used for calling PnP BIOS have byte granularity.
10612 - * They code segments and data segments have fixed 64k limits,
10613 - * the transfer segment sizes are set at run time.
10615 - /* 32-bit code */
10616 - [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
10617 - /* 16-bit code */
10618 - [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
10619 - /* 16-bit data */
10620 - [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
10621 - /* 16-bit data */
10622 - [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
10623 - /* 16-bit data */
10624 - [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
10626 - * The APM segments have byte granularity and their bases
10627 - * are set at run time. All have 64k limits.
10629 - /* 32-bit code */
10630 - [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
10631 - /* 16-bit code */
10632 - [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
10634 - [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
10636 - [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
10637 - [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
10638 - GDT_STACK_CANARY_INIT
10641 -EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
10643 static int __init x86_xsave_setup(char *s)
10645 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
10646 @@ -352,7 +298,7 @@ void switch_to_new_gdt(int cpu)
10648 struct desc_ptr gdt_descr;
10650 - gdt_descr.address = (long)get_cpu_gdt_table(cpu);
10651 + gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
10652 gdt_descr.size = GDT_SIZE - 1;
10653 load_gdt(&gdt_descr);
10654 /* Reload the per-cpu base */
10655 @@ -825,6 +771,10 @@ static void __cpuinit identify_cpu(struc
10656 /* Filter out anything that depends on CPUID levels we don't have */
10657 filter_cpuid_features(c, true);
10659 +#if defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || (defined(CONFIG_PAX_MEMORY_UDEREF) && defined(CONFIG_X86_32))
10660 + setup_clear_cpu_cap(X86_FEATURE_SEP);
10663 /* If the model name is still unset, do table lookup. */
10664 if (!c->x86_model_id[0]) {
10666 @@ -1085,7 +1035,7 @@ struct pt_regs * __cpuinit idle_regs(str
10668 memset(regs, 0, sizeof(struct pt_regs));
10669 regs->fs = __KERNEL_PERCPU;
10670 - regs->gs = __KERNEL_STACK_CANARY;
10671 + savesegment(gs, regs->gs);
10675 @@ -1140,7 +1090,7 @@ void __cpuinit cpu_init(void)
10678 cpu = stack_smp_processor_id();
10679 - t = &per_cpu(init_tss, cpu);
10680 + t = init_tss + cpu;
10681 oist = &per_cpu(orig_ist, cpu);
10684 @@ -1166,7 +1116,7 @@ void __cpuinit cpu_init(void)
10685 switch_to_new_gdt(cpu);
10686 loadsegment(fs, 0);
10688 - load_idt((const struct desc_ptr *)&idt_descr);
10689 + load_idt(&idt_descr);
10691 memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
10693 @@ -1175,7 +1125,6 @@ void __cpuinit cpu_init(void)
10694 wrmsrl(MSR_KERNEL_GS_BASE, 0);
10697 - x86_configure_nx();
10701 @@ -1229,7 +1178,7 @@ void __cpuinit cpu_init(void)
10703 int cpu = smp_processor_id();
10704 struct task_struct *curr = current;
10705 - struct tss_struct *t = &per_cpu(init_tss, cpu);
10706 + struct tss_struct *t = init_tss + cpu;
10707 struct thread_struct *thread = &curr->thread;
10709 if (cpumask_test_and_set_cpu(cpu, cpu_initialized_mask)) {
10710 diff -urNp linux-2.6.37/arch/x86/kernel/cpu/cpufreq/acpi-cpufreq.c linux-2.6.37/arch/x86/kernel/cpu/cpufreq/acpi-cpufreq.c
10711 --- linux-2.6.37/arch/x86/kernel/cpu/cpufreq/acpi-cpufreq.c 2011-01-04 19:50:19.000000000 -0500
10712 +++ linux-2.6.37/arch/x86/kernel/cpu/cpufreq/acpi-cpufreq.c 2011-01-17 02:41:01.000000000 -0500
10713 @@ -481,7 +481,7 @@ static const struct dmi_system_id sw_any
10714 DMI_MATCH(DMI_PRODUCT_NAME, "X6DLP"),
10718 + { NULL, NULL, {DMI_MATCH(DMI_NONE, {0})}, NULL }
10721 static int acpi_cpufreq_blacklist(struct cpuinfo_x86 *c)
10722 diff -urNp linux-2.6.37/arch/x86/kernel/cpu/cpufreq/speedstep-centrino.c linux-2.6.37/arch/x86/kernel/cpu/cpufreq/speedstep-centrino.c
10723 --- linux-2.6.37/arch/x86/kernel/cpu/cpufreq/speedstep-centrino.c 2011-01-04 19:50:19.000000000 -0500
10724 +++ linux-2.6.37/arch/x86/kernel/cpu/cpufreq/speedstep-centrino.c 2011-01-17 02:41:01.000000000 -0500
10725 @@ -226,7 +226,7 @@ static struct cpu_model models[] =
10726 { &cpu_ids[CPU_MP4HT_D0], NULL, 0, NULL },
10727 { &cpu_ids[CPU_MP4HT_E0], NULL, 0, NULL },
10730 + { NULL, NULL, 0, NULL}
10734 diff -urNp linux-2.6.37/arch/x86/kernel/cpu/intel.c linux-2.6.37/arch/x86/kernel/cpu/intel.c
10735 --- linux-2.6.37/arch/x86/kernel/cpu/intel.c 2011-01-04 19:50:19.000000000 -0500
10736 +++ linux-2.6.37/arch/x86/kernel/cpu/intel.c 2011-01-17 02:41:01.000000000 -0500
10737 @@ -161,7 +161,7 @@ static void __cpuinit trap_init_f00f_bug
10738 * Update the IDT descriptor and reload the IDT so that
10739 * it uses the read-only mapped virtual address.
10741 - idt_descr.address = fix_to_virt(FIX_F00F_IDT);
10742 + idt_descr.address = (struct desc_struct *)fix_to_virt(FIX_F00F_IDT);
10743 load_idt(&idt_descr);
10746 diff -urNp linux-2.6.37/arch/x86/kernel/cpu/Makefile linux-2.6.37/arch/x86/kernel/cpu/Makefile
10747 --- linux-2.6.37/arch/x86/kernel/cpu/Makefile 2011-01-04 19:50:19.000000000 -0500
10748 +++ linux-2.6.37/arch/x86/kernel/cpu/Makefile 2011-01-17 02:41:01.000000000 -0500
10749 @@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
10750 CFLAGS_REMOVE_perf_event.o = -pg
10753 -# Make sure load_percpu_segment has no stackprotector
10754 -nostackp := $(call cc-option, -fno-stack-protector)
10755 -CFLAGS_common.o := $(nostackp)
10757 obj-y := intel_cacheinfo.o scattered.o topology.o
10758 obj-y += proc.o capflags.o powerflags.o common.o
10759 obj-y += vmware.o hypervisor.o sched.o mshyperv.o
10760 diff -urNp linux-2.6.37/arch/x86/kernel/cpu/mcheck/mce.c linux-2.6.37/arch/x86/kernel/cpu/mcheck/mce.c
10761 --- linux-2.6.37/arch/x86/kernel/cpu/mcheck/mce.c 2011-01-04 19:50:19.000000000 -0500
10762 +++ linux-2.6.37/arch/x86/kernel/cpu/mcheck/mce.c 2011-01-17 02:41:01.000000000 -0500
10763 @@ -219,7 +219,7 @@ static void print_mce(struct mce *m)
10764 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
10767 - if (m->cs == __KERNEL_CS)
10768 + if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
10769 print_symbol("{%s}", m->ip);
10772 @@ -1460,14 +1460,14 @@ void __cpuinit mcheck_cpu_init(struct cp
10775 static DEFINE_SPINLOCK(mce_state_lock);
10776 -static int open_count; /* #times opened */
10777 +static atomic_t open_count; /* #times opened */
10778 static int open_exclu; /* already open exclusive? */
10780 static int mce_open(struct inode *inode, struct file *file)
10782 spin_lock(&mce_state_lock);
10784 - if (open_exclu || (open_count && (file->f_flags & O_EXCL))) {
10785 + if (open_exclu || (atomic_read(&open_count) && (file->f_flags & O_EXCL))) {
10786 spin_unlock(&mce_state_lock);
10789 @@ -1475,7 +1475,7 @@ static int mce_open(struct inode *inode,
10791 if (file->f_flags & O_EXCL)
10794 + atomic_inc(&open_count);
10796 spin_unlock(&mce_state_lock);
10798 @@ -1486,7 +1486,7 @@ static int mce_release(struct inode *ino
10800 spin_lock(&mce_state_lock);
10803 + atomic_dec(&open_count);
10806 spin_unlock(&mce_state_lock);
10807 @@ -1673,6 +1673,7 @@ static struct miscdevice mce_log_device
10811 + {NULL, NULL}, NULL, NULL
10815 diff -urNp linux-2.6.37/arch/x86/kernel/cpu/mtrr/generic.c linux-2.6.37/arch/x86/kernel/cpu/mtrr/generic.c
10816 --- linux-2.6.37/arch/x86/kernel/cpu/mtrr/generic.c 2011-01-04 19:50:19.000000000 -0500
10817 +++ linux-2.6.37/arch/x86/kernel/cpu/mtrr/generic.c 2011-01-17 02:41:01.000000000 -0500
10818 @@ -28,7 +28,7 @@ static struct fixed_range_block fixed_ra
10819 { MSR_MTRRfix64K_00000, 1 }, /* one 64k MTRR */
10820 { MSR_MTRRfix16K_80000, 2 }, /* two 16k MTRRs */
10821 { MSR_MTRRfix4K_C0000, 8 }, /* eight 4k MTRRs */
10826 static unsigned long smp_changes_mask;
10827 diff -urNp linux-2.6.37/arch/x86/kernel/cpu/mtrr/main.c linux-2.6.37/arch/x86/kernel/cpu/mtrr/main.c
10828 --- linux-2.6.37/arch/x86/kernel/cpu/mtrr/main.c 2011-01-04 19:50:19.000000000 -0500
10829 +++ linux-2.6.37/arch/x86/kernel/cpu/mtrr/main.c 2011-01-17 02:41:01.000000000 -0500
10830 @@ -61,7 +61,7 @@ static DEFINE_MUTEX(mtrr_mutex);
10831 u64 size_or_mask, size_and_mask;
10832 static bool mtrr_aps_delayed_init;
10834 -static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
10835 +static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
10837 const struct mtrr_ops *mtrr_if;
10839 diff -urNp linux-2.6.37/arch/x86/kernel/cpu/mtrr/mtrr.h linux-2.6.37/arch/x86/kernel/cpu/mtrr/mtrr.h
10840 --- linux-2.6.37/arch/x86/kernel/cpu/mtrr/mtrr.h 2011-01-04 19:50:19.000000000 -0500
10841 +++ linux-2.6.37/arch/x86/kernel/cpu/mtrr/mtrr.h 2011-01-17 02:41:01.000000000 -0500
10842 @@ -12,19 +12,19 @@
10843 extern unsigned int mtrr_usage_table[MTRR_MAX_VAR_RANGES];
10847 - u32 use_intel_if;
10848 - void (*set)(unsigned int reg, unsigned long base,
10849 + const u32 vendor;
10850 + const u32 use_intel_if;
10851 + void (* const set)(unsigned int reg, unsigned long base,
10852 unsigned long size, mtrr_type type);
10853 - void (*set_all)(void);
10854 + void (* const set_all)(void);
10856 - void (*get)(unsigned int reg, unsigned long *base,
10857 + void (* const get)(unsigned int reg, unsigned long *base,
10858 unsigned long *size, mtrr_type *type);
10859 - int (*get_free_region)(unsigned long base, unsigned long size,
10860 + int (* const get_free_region)(unsigned long base, unsigned long size,
10862 - int (*validate_add_page)(unsigned long base, unsigned long size,
10863 + int (* const validate_add_page)(unsigned long base, unsigned long size,
10864 unsigned int type);
10865 - int (*have_wrcomb)(void);
10866 + int (* const have_wrcomb)(void);
10869 extern int generic_get_free_region(unsigned long base, unsigned long size,
10870 diff -urNp linux-2.6.37/arch/x86/kernel/cpu/perfctr-watchdog.c linux-2.6.37/arch/x86/kernel/cpu/perfctr-watchdog.c
10871 --- linux-2.6.37/arch/x86/kernel/cpu/perfctr-watchdog.c 2011-01-04 19:50:19.000000000 -0500
10872 +++ linux-2.6.37/arch/x86/kernel/cpu/perfctr-watchdog.c 2011-01-17 02:41:01.000000000 -0500
10873 @@ -30,11 +30,11 @@ struct nmi_watchdog_ctlblk {
10875 /* Interface defining a CPU specific perfctr watchdog */
10877 - int (*reserve)(void);
10878 - void (*unreserve)(void);
10879 - int (*setup)(unsigned nmi_hz);
10880 - void (*rearm)(struct nmi_watchdog_ctlblk *wd, unsigned nmi_hz);
10881 - void (*stop)(void);
10882 + int (* const reserve)(void);
10883 + void (* const unreserve)(void);
10884 + int (* const setup)(unsigned nmi_hz);
10885 + void (* const rearm)(struct nmi_watchdog_ctlblk *wd, unsigned nmi_hz);
10886 + void (* const stop)(void);
10890 @@ -634,6 +634,7 @@ static const struct wd_ops p4_wd_ops = {
10891 #define ARCH_PERFMON_NMI_EVENT_SEL ARCH_PERFMON_UNHALTED_CORE_CYCLES_SEL
10892 #define ARCH_PERFMON_NMI_EVENT_UMASK ARCH_PERFMON_UNHALTED_CORE_CYCLES_UMASK
10894 +/* cannot be const, see probe_nmi_watchdog */
10895 static struct wd_ops intel_arch_wd_ops;
10897 static int setup_intel_arch_watchdog(unsigned nmi_hz)
10898 @@ -686,6 +687,7 @@ static int setup_intel_arch_watchdog(uns
10902 +/* cannot be const */
10903 static struct wd_ops intel_arch_wd_ops __read_mostly = {
10904 .reserve = single_msr_reserve,
10905 .unreserve = single_msr_unreserve,
10906 diff -urNp linux-2.6.37/arch/x86/kernel/cpu/perf_event.c linux-2.6.37/arch/x86/kernel/cpu/perf_event.c
10907 --- linux-2.6.37/arch/x86/kernel/cpu/perf_event.c 2011-01-04 19:50:19.000000000 -0500
10908 +++ linux-2.6.37/arch/x86/kernel/cpu/perf_event.c 2011-01-17 02:41:01.000000000 -0500
10909 @@ -1757,7 +1757,7 @@ perf_callchain_user(struct perf_callchai
10912 perf_callchain_store(entry, frame.return_address);
10913 - fp = frame.next_frame;
10914 + fp = (__force const void __user *)frame.next_frame;
10918 diff -urNp linux-2.6.37/arch/x86/kernel/crash.c linux-2.6.37/arch/x86/kernel/crash.c
10919 --- linux-2.6.37/arch/x86/kernel/crash.c 2011-01-04 19:50:19.000000000 -0500
10920 +++ linux-2.6.37/arch/x86/kernel/crash.c 2011-01-17 02:41:01.000000000 -0500
10921 @@ -42,7 +42,7 @@ static void kdump_nmi_callback(int cpu,
10924 #ifdef CONFIG_X86_32
10925 - if (!user_mode_vm(regs)) {
10926 + if (!user_mode(regs)) {
10927 crash_fixup_ss_esp(&fixed_regs, regs);
10928 regs = &fixed_regs;
10930 diff -urNp linux-2.6.37/arch/x86/kernel/doublefault_32.c linux-2.6.37/arch/x86/kernel/doublefault_32.c
10931 --- linux-2.6.37/arch/x86/kernel/doublefault_32.c 2011-01-04 19:50:19.000000000 -0500
10932 +++ linux-2.6.37/arch/x86/kernel/doublefault_32.c 2011-01-17 02:41:01.000000000 -0500
10935 #define DOUBLEFAULT_STACKSIZE (1024)
10936 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
10937 -#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
10938 +#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
10940 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
10942 @@ -21,7 +21,7 @@ static void doublefault_fn(void)
10943 unsigned long gdt, tss;
10945 store_gdt(&gdt_desc);
10946 - gdt = gdt_desc.address;
10947 + gdt = (unsigned long)gdt_desc.address;
10949 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
10951 @@ -58,10 +58,10 @@ struct tss_struct doublefault_tss __cach
10952 /* 0x2 bit is always set */
10953 .flags = X86_EFLAGS_SF | 0x2,
10956 + .es = __KERNEL_DS,
10960 + .ds = __KERNEL_DS,
10961 .fs = __KERNEL_PERCPU,
10963 .__cr3 = __pa_nodebug(swapper_pg_dir),
10964 diff -urNp linux-2.6.37/arch/x86/kernel/dumpstack_32.c linux-2.6.37/arch/x86/kernel/dumpstack_32.c
10965 --- linux-2.6.37/arch/x86/kernel/dumpstack_32.c 2011-01-04 19:50:19.000000000 -0500
10966 +++ linux-2.6.37/arch/x86/kernel/dumpstack_32.c 2011-01-17 02:41:01.000000000 -0500
10967 @@ -105,11 +105,12 @@ void show_registers(struct pt_regs *regs
10968 * When in-kernel, we also print out the stack and code at the
10969 * time of the fault..
10971 - if (!user_mode_vm(regs)) {
10972 + if (!user_mode(regs)) {
10973 unsigned int code_prologue = code_bytes * 43 / 64;
10974 unsigned int code_len = code_bytes;
10977 + unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(smp_processor_id())[(0xffff & regs->cs) >> 3]);
10979 printk(KERN_EMERG "Stack:\n");
10980 show_stack_log_lvl(NULL, regs, ®s->sp,
10981 @@ -117,10 +118,10 @@ void show_registers(struct pt_regs *regs
10983 printk(KERN_EMERG "Code: ");
10985 - ip = (u8 *)regs->ip - code_prologue;
10986 + ip = (u8 *)regs->ip - code_prologue + cs_base;
10987 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
10988 /* try starting at IP */
10989 - ip = (u8 *)regs->ip;
10990 + ip = (u8 *)regs->ip + cs_base;
10991 code_len = code_len - code_prologue + 1;
10993 for (i = 0; i < code_len; i++, ip++) {
10994 @@ -129,7 +130,7 @@ void show_registers(struct pt_regs *regs
10995 printk(" Bad EIP value.");
10998 - if (ip == (u8 *)regs->ip)
10999 + if (ip == (u8 *)regs->ip + cs_base)
11000 printk("<%02x> ", c);
11002 printk("%02x ", c);
11003 @@ -142,6 +143,7 @@ int is_valid_bugaddr(unsigned long ip)
11005 unsigned short ud2;
11007 + ip = ktla_ktva(ip);
11008 if (ip < PAGE_OFFSET)
11010 if (probe_kernel_address((unsigned short *)ip, ud2))
11011 diff -urNp linux-2.6.37/arch/x86/kernel/dumpstack.c linux-2.6.37/arch/x86/kernel/dumpstack.c
11012 --- linux-2.6.37/arch/x86/kernel/dumpstack.c 2011-01-04 19:50:19.000000000 -0500
11013 +++ linux-2.6.37/arch/x86/kernel/dumpstack.c 2011-01-17 02:41:01.000000000 -0500
11015 * Copyright (C) 1991, 1992 Linus Torvalds
11016 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
11018 +#ifdef CONFIG_GRKERNSEC_HIDESYM
11019 +#define __INCLUDED_BY_HIDESYM 1
11021 #include <linux/kallsyms.h>
11022 #include <linux/kprobes.h>
11023 #include <linux/uaccess.h>
11024 @@ -27,7 +30,7 @@ static int die_counter;
11026 void printk_address(unsigned long address, int reliable)
11028 - printk(" [<%p>] %s%pS\n", (void *) address,
11029 + printk(" [<%p>] %s%pA\n", (void *) address,
11030 reliable ? "" : "? ", (void *) address);
11033 @@ -206,7 +209,7 @@ void dump_stack(void)
11036 printk("Pid: %d, comm: %.20s xid: #%u %s %s %.*s\n",
11037 - current->pid, current->comm, current->xid, print_tainted(),
11038 + task_pid_nr(current), current->comm, current->xid, print_tainted(),
11039 init_utsname()->release,
11040 (int)strcspn(init_utsname()->version, " "),
11041 init_utsname()->version);
11042 @@ -262,7 +265,7 @@ void __kprobes oops_end(unsigned long fl
11043 panic("Fatal exception in interrupt");
11045 panic("Fatal exception");
11047 + do_group_exit(signr);
11050 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
11051 @@ -289,7 +292,7 @@ int __kprobes __die(const char *str, str
11053 show_registers(regs);
11054 #ifdef CONFIG_X86_32
11055 - if (user_mode_vm(regs)) {
11056 + if (user_mode(regs)) {
11058 ss = regs->ss & 0xffff;
11060 @@ -317,7 +320,7 @@ void die(const char *str, struct pt_regs
11061 unsigned long flags = oops_begin();
11064 - if (!user_mode_vm(regs))
11065 + if (!user_mode(regs))
11066 report_bug(regs->ip, regs);
11068 if (__die(str, regs, err))
11069 diff -urNp linux-2.6.37/arch/x86/kernel/entry_32.S linux-2.6.37/arch/x86/kernel/entry_32.S
11070 --- linux-2.6.37/arch/x86/kernel/entry_32.S 2011-01-04 19:50:19.000000000 -0500
11071 +++ linux-2.6.37/arch/x86/kernel/entry_32.S 2011-01-17 02:41:01.000000000 -0500
11072 @@ -183,13 +183,81 @@
11073 /*CFI_REL_OFFSET gs, PT_GS*/
11075 .macro SET_KERNEL_GS reg
11077 +#ifdef CONFIG_CC_STACKPROTECTOR
11078 movl $(__KERNEL_STACK_CANARY), \reg
11079 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
11080 + movl $(__USER_DS), \reg
11088 #endif /* CONFIG_X86_32_LAZY_GS */
11091 +.macro PAX_EXIT_KERNEL
11092 +#ifdef CONFIG_PAX_KERNEXEC
11093 +#ifdef CONFIG_PARAVIRT
11094 + push %eax; push %ecx
11097 + cmp $__KERNEXEC_KERNEL_CS, %esi
11099 +#ifdef CONFIG_PARAVIRT
11100 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
11106 + ljmp $__KERNEL_CS, $1f
11108 +#ifdef CONFIG_PARAVIRT
11110 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
11115 +#ifdef CONFIG_PARAVIRT
11116 + pop %ecx; pop %eax
11121 +.macro PAX_ENTER_KERNEL
11122 +#ifdef CONFIG_PAX_KERNEXEC
11123 +#ifdef CONFIG_PARAVIRT
11124 + push %eax; push %ecx
11125 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
11133 + cmp $__KERNEL_CS, %esi
11135 + ljmp $__KERNEL_CS, $3f
11136 +1: ljmp $__KERNEXEC_KERNEL_CS, $2f
11138 +#ifdef CONFIG_PARAVIRT
11140 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
11145 +#ifdef CONFIG_PARAVIRT
11146 + pop %ecx; pop %eax
11151 +.macro __SAVE_ALL _DS
11155 @@ -212,7 +280,7 @@
11156 CFI_REL_OFFSET ecx, 0
11158 CFI_REL_OFFSET ebx, 0
11159 - movl $(__USER_DS), %edx
11163 movl $(__KERNEL_PERCPU), %edx
11164 @@ -220,6 +288,15 @@
11169 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
11170 + __SAVE_ALL __KERNEL_DS
11173 + __SAVE_ALL __USER_DS
11177 .macro RESTORE_INT_REGS
11180 @@ -330,7 +407,15 @@ check_userspace:
11181 movb PT_CS(%esp), %al
11182 andl $(X86_EFLAGS_VM | SEGMENT_RPL_MASK), %eax
11183 cmpl $USER_RPL, %eax
11185 +#ifdef CONFIG_PAX_KERNEXEC
11186 + jae resume_userspace
11189 + jmp resume_kernel
11191 jb resume_kernel # not returning to v8086 or userspace
11194 ENTRY(resume_userspace)
11196 @@ -392,10 +477,9 @@ sysenter_past_esp:
11197 /*CFI_REL_OFFSET cs, 0*/
11199 * Push current_thread_info()->sysenter_return to the stack.
11200 - * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
11201 - * pushed above; +8 corresponds to copy_thread's esp0 setting.
11203 - pushl_cfi ((TI_sysenter_return)-THREAD_SIZE_asm+8+4*4)(%esp)
11204 + GET_THREAD_INFO(%ebp)
11205 + pushl_cfi TI_sysenter_return(%ebp)
11206 CFI_REL_OFFSET eip, 0
11209 @@ -406,9 +490,19 @@ sysenter_past_esp:
11210 * Load the potential sixth argument from user stack.
11211 * Careful about security.
11213 + movl PT_OLDESP(%esp),%ebp
11215 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11216 + mov PT_OLDSS(%esp),%ds
11217 +1: movl %ds:(%ebp),%ebp
11221 cmpl $__PAGE_OFFSET-3,%ebp
11223 1: movl (%ebp),%ebp
11226 movl %ebp,PT_EBP(%esp)
11227 .section __ex_table,"a"
11229 @@ -431,12 +525,23 @@ sysenter_do_call:
11230 testl $_TIF_ALLWORK_MASK, %ecx
11234 +#ifdef CONFIG_PAX_RANDKSTACK
11236 + CFI_ADJUST_CFA_OFFSET 4
11237 + call pax_randomize_kstack
11239 + CFI_ADJUST_CFA_OFFSET -4
11242 /* if something modifies registers it must also disable sysexit */
11243 movl PT_EIP(%esp), %edx
11244 movl PT_OLDESP(%esp), %ecx
11247 1: mov PT_FS(%esp), %fs
11248 +2: mov PT_DS(%esp), %ds
11249 +3: mov PT_ES(%esp), %es
11251 ENABLE_INTERRUPTS_SYSEXIT
11253 @@ -479,11 +584,17 @@ sysexit_audit:
11256 .pushsection .fixup,"ax"
11257 -2: movl $0,PT_FS(%esp)
11258 +4: movl $0,PT_FS(%esp)
11260 +5: movl $0,PT_DS(%esp)
11262 +6: movl $0,PT_ES(%esp)
11264 .section __ex_table,"a"
11272 ENDPROC(ia32_sysenter_target)
11273 @@ -516,6 +627,10 @@ syscall_exit:
11274 testl $_TIF_ALLWORK_MASK, %ecx # current->work
11275 jne syscall_exit_work
11277 +#ifdef CONFIG_PAX_RANDKSTACK
11278 + call pax_randomize_kstack
11283 restore_all_notrace:
11284 @@ -575,14 +690,21 @@ ldt_ss:
11285 * compensating for the offset by changing to the ESPFIX segment with
11286 * a base address that matches for the difference.
11288 -#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
11289 +#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
11290 mov %esp, %edx /* load kernel esp */
11291 mov PT_OLDESP(%esp), %eax /* load userspace esp */
11292 mov %dx, %ax /* eax: new kernel esp */
11293 sub %eax, %edx /* offset (low word is 0) */
11295 + movl PER_CPU_VAR(cpu_number), %ebx
11296 + shll $PAGE_SHIFT_asm, %ebx
11297 + addl $cpu_gdt_table, %ebx
11299 + movl $cpu_gdt_table, %ebx
11302 - mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
11303 - mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
11304 + mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
11305 + mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
11306 pushl_cfi $__ESPFIX_SS
11307 pushl_cfi %eax /* new kernel esp */
11308 /* Disable interrupts, but do not irqtrace this section: we
11309 @@ -617,23 +739,17 @@ work_resched:
11311 work_notifysig: # deal with pending signals and
11312 # notify-resume requests
11315 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
11317 - jne work_notifysig_v86 # returning to kernel-space or
11318 + jz 1f # returning to kernel-space or
11321 - call do_notify_resume
11322 - jmp resume_userspace_sig
11325 -work_notifysig_v86:
11326 pushl_cfi %ecx # save ti_flags for do_notify_resume
11327 call save_v86_state # %eax contains pt_regs pointer
11335 call do_notify_resume
11336 @@ -668,6 +784,10 @@ END(syscall_exit_work)
11338 RING0_INT_FRAME # can't unwind into user space anyway
11340 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11344 GET_THREAD_INFO(%ebp)
11345 movl $-EFAULT,PT_EAX(%esp)
11346 jmp resume_userspace
11347 @@ -750,6 +870,36 @@ ptregs_clone:
11349 ENDPROC(ptregs_clone)
11352 +ENTRY(kernel_execve)
11355 + sub $PT_OLDSS+4,%esp
11359 + lea 3*4(%esp),%edi
11360 + mov $PT_OLDSS/4+1,%ecx
11366 + movl $X86_EFLAGS_IF,PT_EFLAGS(%esp)
11370 + CFI_ADJUST_CFA_OFFSET -4
11371 + GET_THREAD_INFO(%ebp)
11374 + add $PT_OLDSS+4,%esp
11375 + CFI_ADJUST_CFA_OFFSET -PT_OLDSS-4
11379 +ENDPROC(kernel_execve)
11381 .macro FIXUP_ESPFIX_STACK
11383 * Switch back for ESPFIX stack to the normal zerobased stack
11384 @@ -759,8 +909,15 @@ ENDPROC(ptregs_clone)
11385 * normal stack and adjusts ESP with the matching offset.
11387 /* fixup the stack */
11388 - mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
11389 - mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
11391 + movl PER_CPU_VAR(cpu_number), %ebx
11392 + shll $PAGE_SHIFT_asm, %ebx
11393 + addl $cpu_gdt_table, %ebx
11395 + movl $cpu_gdt_table, %ebx
11397 + mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
11398 + mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
11400 addl %esp, %eax /* the adjusted stack pointer */
11401 pushl_cfi $__KERNEL_DS
11402 @@ -1211,7 +1368,6 @@ return_to_handler:
11406 -.section .rodata,"a"
11407 #include "syscall_table_32.S"
11409 syscall_table_size=(.-sys_call_table)
11410 @@ -1257,9 +1413,12 @@ error_code:
11411 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
11414 - movl $(__USER_DS), %ecx
11415 + movl $(__KERNEL_DS), %ecx
11422 movl %esp,%eax # pt_regs pointer
11424 @@ -1344,6 +1503,9 @@ nmi_stack_correct:
11425 xorl %edx,%edx # zero error code
11426 movl %esp,%eax # pt_regs pointer
11431 jmp restore_all_notrace
11434 @@ -1380,6 +1542,9 @@ nmi_espfix_stack:
11435 FIXUP_ESPFIX_STACK # %eax == %esp
11436 xorl %edx,%edx # zero error code
11442 lss 12+4(%esp), %esp # back to espfix stack
11443 CFI_ADJUST_CFA_OFFSET -24
11444 diff -urNp linux-2.6.37/arch/x86/kernel/entry_64.S linux-2.6.37/arch/x86/kernel/entry_64.S
11445 --- linux-2.6.37/arch/x86/kernel/entry_64.S 2011-01-04 19:50:19.000000000 -0500
11446 +++ linux-2.6.37/arch/x86/kernel/entry_64.S 2011-01-17 02:41:01.000000000 -0500
11448 #include <asm/paravirt.h>
11449 #include <asm/ftrace.h>
11450 #include <asm/percpu.h>
11451 +#include <asm/pgtable.h>
11453 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
11454 #include <linux/elf-em.h>
11455 @@ -174,6 +175,189 @@ ENTRY(native_usergs_sysret64)
11456 ENDPROC(native_usergs_sysret64)
11457 #endif /* CONFIG_PARAVIRT */
11459 + .macro ljmpq sel, off
11460 +#if defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
11461 + .byte 0x48; ljmp *1234f(%rip)
11462 + .pushsection .rodata
11464 + 1234: .quad \off; .word \sel
11473 +ENTRY(pax_enter_kernel)
11475 +#ifdef CONFIG_PAX_KERNEXEC
11478 +#ifdef CONFIG_PARAVIRT
11479 + PV_SAVE_REGS(CLBR_RDI)
11486 + cmp $__KERNEL_CS,%edi
11488 + ljmpq __KERNEL_CS,3f
11489 +1: ljmpq __KERNEXEC_KERNEL_CS,2f
11490 +2: SET_RDI_INTO_CR0
11493 +#ifdef CONFIG_PARAVIRT
11494 + PV_RESTORE_REGS(CLBR_RDI)
11501 +ENDPROC(pax_enter_kernel)
11503 +ENTRY(pax_exit_kernel)
11505 +#ifdef CONFIG_PAX_KERNEXEC
11508 +#ifdef CONFIG_PARAVIRT
11509 + PV_SAVE_REGS(CLBR_RDI)
11513 + cmp $__KERNEXEC_KERNEL_CS,%edi
11517 + ljmpq __KERNEL_CS,1f
11518 +1: SET_RDI_INTO_CR0
11521 +#ifdef CONFIG_PARAVIRT
11522 + PV_RESTORE_REGS(CLBR_RDI);
11529 +ENDPROC(pax_exit_kernel)
11531 +ENTRY(pax_enter_kernel_user)
11533 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11537 +#ifdef CONFIG_PARAVIRT
11538 + PV_SAVE_REGS(CLBR_RDI)
11543 + add $__START_KERNEL_map,%rbx
11544 + sub phys_base(%rip),%rbx
11546 +#ifdef CONFIG_PARAVIRT
11548 + cmpl $0, pv_info+PARAVIRT_enabled
11551 + .rept USER_PGD_PTRS
11552 + mov i*8(%rbx),%rsi
11554 + lea i*8(%rbx),%rdi
11555 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd)
11563 + .rept USER_PGD_PTRS
11564 + movb $0,i*8(%rbx)
11568 +#ifdef CONFIG_PARAVIRT
11573 +#ifdef CONFIG_PAX_KERNEXEC
11579 +#ifdef CONFIG_PARAVIRT
11580 + PV_RESTORE_REGS(CLBR_RDI)
11588 +ENDPROC(pax_enter_kernel_user)
11590 +ENTRY(pax_exit_kernel_user)
11592 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11595 +#ifdef CONFIG_PARAVIRT
11597 + PV_SAVE_REGS(CLBR_RDI)
11600 +#ifdef CONFIG_PAX_KERNEXEC
11607 + add $__START_KERNEL_map,%rdi
11608 + sub phys_base(%rip),%rdi
11610 +#ifdef CONFIG_PARAVIRT
11611 + cmpl $0, pv_info+PARAVIRT_enabled
11615 + .rept USER_PGD_PTRS
11616 + mov i*8(%rbx),%rsi
11618 + lea i*8(%rbx),%rdi
11619 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd)
11627 + .rept USER_PGD_PTRS
11628 + movb $0x67,i*8(%rdi)
11632 +#ifdef CONFIG_PARAVIRT
11633 +2: PV_RESTORE_REGS(CLBR_RDI)
11641 +ENDPROC(pax_exit_kernel_user)
11643 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
11644 #ifdef CONFIG_TRACE_IRQFLAGS
11645 @@ -312,7 +496,7 @@ ENTRY(save_args)
11646 leaq -ARGOFFSET+16(%rsp),%rdi /* arg1 for handler */
11647 movq_cfi rbp, 8 /* push %rbp */
11648 leaq 8(%rsp), %rbp /* mov %rsp, %ebp */
11649 - testl $3, CS(%rdi)
11650 + testb $3, CS(%rdi)
11654 @@ -403,7 +587,7 @@ ENTRY(ret_from_fork)
11658 - testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
11659 + testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
11660 je int_ret_from_sys_call
11662 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
11663 @@ -462,6 +646,11 @@ ENTRY(system_call_after_swapgs)
11665 movq %rsp,PER_CPU_VAR(old_rsp)
11666 movq PER_CPU_VAR(kernel_stack),%rsp
11668 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11669 + call pax_enter_kernel_user
11673 * No need to follow this irqs off/on section - it's straight
11675 @@ -496,6 +685,11 @@ sysret_check:
11680 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11681 + call pax_exit_kernel_user
11685 * sysretq will re-enable interrupts:
11687 @@ -605,7 +799,7 @@ tracesys:
11688 GLOBAL(int_ret_from_sys_call)
11689 DISABLE_INTERRUPTS(CLBR_NONE)
11691 - testl $3,CS-ARGOFFSET(%rsp)
11692 + testb $3,CS-ARGOFFSET(%rsp)
11693 je retint_restore_args
11694 movl $_TIF_ALLWORK_MASK,%edi
11695 /* edi: mask to check */
11696 @@ -786,6 +980,16 @@ END(interrupt)
11697 CFI_ADJUST_CFA_OFFSET ORIG_RAX-ARGOFFSET+8
11700 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11701 + testb $3, CS(%rdi)
11703 + call pax_enter_kernel
11705 +1: call pax_enter_kernel_user
11708 + call pax_enter_kernel
11713 @@ -813,7 +1017,7 @@ ret_from_intr:
11714 CFI_ADJUST_CFA_OFFSET -8
11716 GET_THREAD_INFO(%rcx)
11717 - testl $3,CS-ARGOFFSET(%rsp)
11718 + testb $3,CS-ARGOFFSET(%rsp)
11721 /* Interrupt came from user space */
11722 @@ -835,12 +1039,18 @@ retint_swapgs: /* return to user-space
11723 * The iretq could re-enable interrupts:
11725 DISABLE_INTERRUPTS(CLBR_ANY)
11727 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11728 + call pax_exit_kernel_user
11735 retint_restore_args: /* return to kernel space */
11736 DISABLE_INTERRUPTS(CLBR_ANY)
11737 + call pax_exit_kernel
11739 * The iretq could re-enable interrupts:
11741 @@ -1012,6 +1222,16 @@ ENTRY(\sym)
11742 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
11745 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11746 + testb $3, CS(%rsp)
11748 + call pax_enter_kernel
11750 +1: call pax_enter_kernel_user
11753 + call pax_enter_kernel
11755 movq %rsp,%rdi /* pt_regs pointer */
11756 xorl %esi,%esi /* no error code */
11758 @@ -1029,6 +1249,16 @@ ENTRY(\sym)
11759 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
11762 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11763 + testb $3, CS(%rsp)
11765 + call pax_enter_kernel
11767 +1: call pax_enter_kernel_user
11770 + call pax_enter_kernel
11772 movq %rsp,%rdi /* pt_regs pointer */
11773 xorl %esi,%esi /* no error code */
11775 @@ -1037,7 +1267,7 @@ ENTRY(\sym)
11779 -#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
11780 +#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r12)
11781 .macro paranoidzeroentry_ist sym do_sym ist
11784 @@ -1047,8 +1277,24 @@ ENTRY(\sym)
11785 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
11788 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11789 + testb $3, CS(%rsp)
11791 + call pax_enter_kernel
11793 +1: call pax_enter_kernel_user
11796 + call pax_enter_kernel
11798 movq %rsp,%rdi /* pt_regs pointer */
11799 xorl %esi,%esi /* no error code */
11801 + imul $TSS_size, PER_CPU_VAR(cpu_number), %r12d
11802 + lea init_tss(%r12), %r12
11804 + lea init_tss(%rip), %r12
11806 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
11808 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
11809 @@ -1065,6 +1311,16 @@ ENTRY(\sym)
11810 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
11813 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11814 + testb $3, CS(%rsp)
11816 + call pax_enter_kernel
11818 +1: call pax_enter_kernel_user
11821 + call pax_enter_kernel
11823 movq %rsp,%rdi /* pt_regs pointer */
11824 movq ORIG_RAX(%rsp),%rsi /* get error code */
11825 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
11826 @@ -1084,6 +1340,16 @@ ENTRY(\sym)
11830 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11831 + testb $3, CS(%rsp)
11833 + call pax_enter_kernel
11835 +1: call pax_enter_kernel_user
11838 + call pax_enter_kernel
11840 movq %rsp,%rdi /* pt_regs pointer */
11841 movq ORIG_RAX(%rsp),%rsi /* get error code */
11842 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
11843 @@ -1343,14 +1609,27 @@ ENTRY(paranoid_exit)
11845 testl %ebx,%ebx /* swapgs needed? */
11846 jnz paranoid_restore
11847 - testl $3,CS(%rsp)
11848 + testb $3,CS(%rsp)
11849 jnz paranoid_userspace
11850 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11851 + call pax_exit_kernel
11852 + TRACE_IRQS_IRETQ 0
11853 + SWAPGS_UNSAFE_STACK
11858 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11859 + call pax_exit_kernel_user
11861 + call pax_exit_kernel
11864 SWAPGS_UNSAFE_STACK
11868 + call pax_exit_kernel
11872 @@ -1408,7 +1687,7 @@ ENTRY(error_entry)
11873 movq_cfi r14, R14+8
11874 movq_cfi r15, R15+8
11876 - testl $3,CS+8(%rsp)
11877 + testb $3,CS+8(%rsp)
11878 je error_kernelspace
11881 @@ -1472,6 +1751,16 @@ ENTRY(nmi)
11882 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
11885 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11886 + testb $3, CS(%rsp)
11888 + call pax_enter_kernel
11890 +1: call pax_enter_kernel_user
11893 + call pax_enter_kernel
11895 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
11898 @@ -1482,11 +1771,12 @@ ENTRY(nmi)
11899 DISABLE_INTERRUPTS(CLBR_NONE)
11900 testl %ebx,%ebx /* swapgs needed? */
11902 - testl $3,CS(%rsp)
11903 + testb $3,CS(%rsp)
11906 SWAPGS_UNSAFE_STACK
11908 + call pax_exit_kernel
11912 diff -urNp linux-2.6.37/arch/x86/kernel/ftrace.c linux-2.6.37/arch/x86/kernel/ftrace.c
11913 --- linux-2.6.37/arch/x86/kernel/ftrace.c 2011-01-04 19:50:19.000000000 -0500
11914 +++ linux-2.6.37/arch/x86/kernel/ftrace.c 2011-01-17 02:41:01.000000000 -0500
11915 @@ -174,7 +174,9 @@ void ftrace_nmi_enter(void)
11917 if (atomic_inc_return(&nmi_running) & MOD_CODE_WRITE_FLAG) {
11919 + pax_open_kernel();
11921 + pax_close_kernel();
11922 atomic_inc(&nmi_update_count);
11924 /* Must have previous changes seen before executions */
11925 @@ -268,6 +270,8 @@ ftrace_modify_code(unsigned long ip, uns
11927 unsigned char replaced[MCOUNT_INSN_SIZE];
11929 + ip = ktla_ktva(ip);
11932 * Note: Due to modules and __init, code can
11933 * disappear and change, we need to protect against faulting
11934 @@ -324,7 +328,7 @@ int ftrace_update_ftrace_func(ftrace_fun
11935 unsigned char old[MCOUNT_INSN_SIZE], *new;
11938 - memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
11939 + memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
11940 new = ftrace_call_replace(ip, (unsigned long)func);
11941 ret = ftrace_modify_code(ip, old, new);
11943 @@ -350,6 +354,8 @@ static int ftrace_mod_jmp(unsigned long
11945 unsigned char code[MCOUNT_INSN_SIZE];
11947 + ip = ktla_ktva(ip);
11949 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
11952 diff -urNp linux-2.6.37/arch/x86/kernel/head32.c linux-2.6.37/arch/x86/kernel/head32.c
11953 --- linux-2.6.37/arch/x86/kernel/head32.c 2011-01-04 19:50:19.000000000 -0500
11954 +++ linux-2.6.37/arch/x86/kernel/head32.c 2011-01-17 02:41:01.000000000 -0500
11956 #include <asm/io_apic.h>
11957 #include <asm/bios_ebda.h>
11958 #include <asm/tlbflush.h>
11959 +#include <asm/boot.h>
11961 static void __init i386_default_early_setup(void)
11963 @@ -43,7 +44,7 @@ void __init i386_start_kernel(void)
11964 memblock_x86_reserve_range(PAGE_SIZE, PAGE_SIZE + PAGE_SIZE, "EX TRAMPOLINE");
11967 - memblock_x86_reserve_range(__pa_symbol(&_text), __pa_symbol(&__bss_stop), "TEXT DATA BSS");
11968 + memblock_x86_reserve_range(LOAD_PHYSICAL_ADDR, __pa_symbol(&__bss_stop), "TEXT DATA BSS");
11970 #ifdef CONFIG_BLK_DEV_INITRD
11971 /* Reserve INITRD */
11972 diff -urNp linux-2.6.37/arch/x86/kernel/head_32.S linux-2.6.37/arch/x86/kernel/head_32.S
11973 --- linux-2.6.37/arch/x86/kernel/head_32.S 2011-01-04 19:50:19.000000000 -0500
11974 +++ linux-2.6.37/arch/x86/kernel/head_32.S 2011-01-17 02:41:01.000000000 -0500
11976 /* Physical address */
11977 #define pa(X) ((X) - __PAGE_OFFSET)
11979 +#ifdef CONFIG_PAX_KERNEXEC
11982 +#define ta(X) ((X) - __PAGE_OFFSET)
11986 * References to members of the new_cpu_data structure.
11989 * and small than max_low_pfn, otherwise will waste some page table entries
11992 -#if PTRS_PER_PMD > 1
11993 -#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
11995 -#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
11997 +#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
11999 /* Number of possible pages in the lowmem region */
12000 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
12001 @@ -77,6 +79,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_P
12002 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
12005 + * Real beginning of normal "text" segment
12011 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
12012 * %esi points to the real-mode code as a 32-bit pointer.
12013 * CS and DS must be 4 GB flat segments, but we don't depend on
12014 @@ -84,6 +92,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
12019 +#ifdef CONFIG_PAX_KERNEXEC
12021 +/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
12022 +.fill PAGE_SIZE-5,1,0xcc
12026 /* test KEEP_SEGMENTS flag to see if the bootloader is asking
12027 us to not reload segments */
12028 @@ -101,6 +116,57 @@ ENTRY(startup_32)
12033 + movl $pa(cpu_gdt_table),%edi
12034 + movl $__per_cpu_load,%eax
12035 + movw %ax,__KERNEL_PERCPU + 2(%edi)
12037 + movb %al,__KERNEL_PERCPU + 4(%edi)
12038 + movb %ah,__KERNEL_PERCPU + 7(%edi)
12039 + movl $__per_cpu_end - 1,%eax
12040 + subl $__per_cpu_start,%eax
12041 + movw %ax,__KERNEL_PERCPU + 0(%edi)
12044 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12045 + movl $NR_CPUS,%ecx
12046 + movl $pa(cpu_gdt_table),%edi
12048 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
12049 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
12050 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
12051 + addl $PAGE_SIZE_asm,%edi
12055 +#ifdef CONFIG_PAX_KERNEXEC
12056 + movl $pa(boot_gdt),%edi
12057 + movl $__LOAD_PHYSICAL_ADDR,%eax
12058 + movw %ax,__BOOT_CS + 2(%edi)
12060 + movb %al,__BOOT_CS + 4(%edi)
12061 + movb %ah,__BOOT_CS + 7(%edi)
12064 + ljmp $(__BOOT_CS),$1f
12067 + movl $NR_CPUS,%ecx
12068 + movl $pa(cpu_gdt_table),%edi
12069 + addl $__PAGE_OFFSET,%eax
12071 + movw %ax,__KERNEL_CS + 2(%edi)
12072 + movw %ax,__KERNEXEC_KERNEL_CS + 2(%edi)
12074 + movb %al,__KERNEL_CS + 4(%edi)
12075 + movb %al,__KERNEXEC_KERNEL_CS + 4(%edi)
12076 + movb %ah,__KERNEL_CS + 7(%edi)
12077 + movb %ah,__KERNEXEC_KERNEL_CS + 7(%edi)
12079 + addl $PAGE_SIZE_asm,%edi
12084 * Clear BSS first so that there are no surprises...
12086 @@ -150,9 +216,7 @@ ENTRY(startup_32)
12087 cmpl $num_subarch_entries, %eax
12090 - movl pa(subarch_entries)(,%eax,4), %eax
12091 - subl $__PAGE_OFFSET, %eax
12093 + jmp *pa(subarch_entries)(,%eax,4)
12097 @@ -164,10 +228,10 @@ WEAK(xen_entry)
12101 - .long default_entry /* normal x86/PC */
12102 - .long lguest_entry /* lguest hypervisor */
12103 - .long xen_entry /* Xen hypervisor */
12104 - .long default_entry /* Moorestown MID */
12105 + .long ta(default_entry) /* normal x86/PC */
12106 + .long ta(lguest_entry) /* lguest hypervisor */
12107 + .long ta(xen_entry) /* Xen hypervisor */
12108 + .long ta(default_entry) /* Moorestown MID */
12109 num_subarch_entries = (. - subarch_entries) / 4
12111 #endif /* CONFIG_PARAVIRT */
12112 @@ -227,8 +291,11 @@ default_entry:
12113 movl %eax, pa(max_pfn_mapped)
12115 /* Do early initialization of the fixmap area */
12116 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
12117 - movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
12118 +#ifdef CONFIG_COMPAT_VDSO
12119 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
12121 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
12123 #else /* Not PAE */
12125 page_pde_offset = (__PAGE_OFFSET >> 20);
12126 @@ -258,8 +325,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
12127 movl %eax, pa(max_pfn_mapped)
12129 /* Do early initialization of the fixmap area */
12130 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
12131 - movl %eax,pa(initial_page_table+0xffc)
12132 +#ifdef CONFIG_COMPAT_VDSO
12133 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
12135 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
12140 @@ -306,6 +376,7 @@ ENTRY(startup_32_smp)
12144 +#ifdef CONFIG_X86_PAE
12145 testb $X86_CR4_PAE, %al # check if PAE is enabled
12148 @@ -330,6 +401,9 @@ ENTRY(startup_32_smp)
12149 /* Make changes effective */
12152 + btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
12158 @@ -355,9 +429,7 @@ ENTRY(startup_32_smp)
12162 - jz 1f /* Initial CPU cleans BSS */
12165 + jnz checkCPUtype /* Initial CPU cleans BSS */
12166 #endif /* CONFIG_SMP */
12169 @@ -435,7 +507,7 @@ is386: movl $2,%ecx # set MP
12170 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
12171 movl %eax,%ss # after changing gdt.
12173 - movl $(__USER_DS),%eax # DS/ES contains default USER segment
12174 +# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
12178 @@ -449,15 +521,22 @@ is386: movl $2,%ecx # set MP
12182 - movl $gdt_page,%eax
12183 + movl $cpu_gdt_table,%eax
12184 movl $stack_canary,%ecx
12186 + addl $__per_cpu_load,%ecx
12188 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
12190 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
12191 movb %ch, 8 * GDT_ENTRY_STACK_CANARY + 7(%eax)
12194 movl $(__KERNEL_STACK_CANARY),%eax
12195 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
12196 + movl $(__USER_DS),%eax
12202 xorl %eax,%eax # Clear LDT
12203 @@ -468,10 +547,6 @@ is386: movl $2,%ecx # set MP
12207 - cmpb $0,%cl # the first CPU calls start_kernel
12209 - movl (stack_start), %esp
12211 #endif /* CONFIG_SMP */
12212 jmp *(initial_code)
12214 @@ -557,22 +632,22 @@ early_page_fault:
12219 #ifdef CONFIG_PRINTK
12220 + cmpl $1,%ss:early_recursion_flag
12222 + incl %ss:early_recursion_flag
12225 movl $(__KERNEL_DS),%eax
12228 - cmpl $2,early_recursion_flag
12230 - incl early_recursion_flag
12233 pushl %edx /* trapno */
12242 @@ -580,8 +655,11 @@ hlt_loop:
12243 /* This is the default interrupt "handler" :-) */
12247 #ifdef CONFIG_PRINTK
12248 + cmpl $2,%ss:early_recursion_flag
12250 + incl %ss:early_recursion_flag
12255 @@ -590,9 +668,6 @@ ignore_int:
12256 movl $(__KERNEL_DS),%eax
12259 - cmpl $2,early_recursion_flag
12261 - incl early_recursion_flag
12265 @@ -619,29 +694,42 @@ ENTRY(initial_code)
12269 -__PAGE_ALIGNED_BSS
12270 - .align PAGE_SIZE_asm
12271 #ifdef CONFIG_X86_PAE
12272 +.section .initial_pg_pmd,"a",@progbits
12273 ENTRY(initial_pg_pmd)
12274 .fill 1024*KPMDS,4,0
12276 ENTRY(initial_page_table)
12279 +.section .initial_pg_fixmap,"a",@progbits
12280 ENTRY(initial_pg_fixmap)
12282 +.section .empty_zero_page,"a",@progbits
12283 ENTRY(empty_zero_page)
12285 +.section .swapper_pg_dir,"a",@progbits
12286 ENTRY(swapper_pg_dir)
12287 +#ifdef CONFIG_X86_PAE
12294 + * The IDT has to be page-aligned to simplify the Pentium
12295 + * F0 0F bug workaround.. We have a special link segment
12298 +.section .idt,"a",@progbits
12303 * This starts the data section.
12305 #ifdef CONFIG_X86_PAE
12306 -__PAGE_ALIGNED_DATA
12307 - /* Page-aligned for the benefit of paravirt? */
12308 - .align PAGE_SIZE_asm
12309 +.section .initial_page_table,"a",@progbits
12310 ENTRY(initial_page_table)
12311 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
12313 @@ -660,15 +748,24 @@ ENTRY(initial_page_table)
12314 # error "Kernel PMDs should be 1, 2 or 3"
12316 .align PAGE_SIZE_asm /* needs to be page-sized too */
12318 +#ifdef CONFIG_PAX_PER_CPU_PGD
12329 - .long init_thread_union+THREAD_SIZE
12330 + .long init_thread_union+THREAD_SIZE-8
12335 +.section .rodata,"a",@progbits
12336 early_recursion_flag:
12339 @@ -704,7 +801,7 @@ fault_msg:
12340 .word 0 # 32 bit align gdt_desc.address
12343 - .long boot_gdt - __PAGE_OFFSET
12344 + .long pa(boot_gdt)
12346 .word 0 # 32-bit align idt_desc.address
12348 @@ -715,7 +812,7 @@ idt_descr:
12349 .word 0 # 32 bit align gdt_desc.address
12350 ENTRY(early_gdt_descr)
12351 .word GDT_ENTRIES*8-1
12352 - .long gdt_page /* Overwritten for secondary CPUs */
12353 + .long cpu_gdt_table /* Overwritten for secondary CPUs */
12356 * The boot_gdt must mirror the equivalent in setup.S and is
12357 @@ -724,5 +821,65 @@ ENTRY(early_gdt_descr)
12358 .align L1_CACHE_BYTES
12360 .fill GDT_ENTRY_BOOT_CS,8,0
12361 - .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
12362 - .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
12363 + .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
12364 + .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
12366 + .align PAGE_SIZE_asm
12367 +ENTRY(cpu_gdt_table)
12369 + .quad 0x0000000000000000 /* NULL descriptor */
12370 + .quad 0x0000000000000000 /* 0x0b reserved */
12371 + .quad 0x0000000000000000 /* 0x13 reserved */
12372 + .quad 0x0000000000000000 /* 0x1b reserved */
12374 +#ifdef CONFIG_PAX_KERNEXEC
12375 + .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
12377 + .quad 0x0000000000000000 /* 0x20 unused */
12380 + .quad 0x0000000000000000 /* 0x28 unused */
12381 + .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
12382 + .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
12383 + .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
12384 + .quad 0x0000000000000000 /* 0x4b reserved */
12385 + .quad 0x0000000000000000 /* 0x53 reserved */
12386 + .quad 0x0000000000000000 /* 0x5b reserved */
12388 + .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
12389 + .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
12390 + .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
12391 + .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
12393 + .quad 0x0000000000000000 /* 0x80 TSS descriptor */
12394 + .quad 0x0000000000000000 /* 0x88 LDT descriptor */
12397 + * Segments used for calling PnP BIOS have byte granularity.
12398 + * The code segments and data segments have fixed 64k limits,
12399 + * the transfer segment sizes are set at run time.
12401 + .quad 0x00409b000000ffff /* 0x90 32-bit code */
12402 + .quad 0x00009b000000ffff /* 0x98 16-bit code */
12403 + .quad 0x000093000000ffff /* 0xa0 16-bit data */
12404 + .quad 0x0000930000000000 /* 0xa8 16-bit data */
12405 + .quad 0x0000930000000000 /* 0xb0 16-bit data */
12408 + * The APM segments have byte granularity and their bases
12409 + * are set at run time. All have 64k limits.
12411 + .quad 0x00409b000000ffff /* 0xb8 APM CS code */
12412 + .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
12413 + .quad 0x004093000000ffff /* 0xc8 APM DS data */
12415 + .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
12416 + .quad 0x0040930000000000 /* 0xd8 - PERCPU */
12417 + .quad 0x0040910000000018 /* 0xe0 - STACK_CANARY */
12418 + .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
12419 + .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
12420 + .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
12422 + /* Be sure this is zeroed to avoid false validations in Xen */
12423 + .fill PAGE_SIZE_asm - GDT_SIZE,1,0
12425 diff -urNp linux-2.6.37/arch/x86/kernel/head_64.S linux-2.6.37/arch/x86/kernel/head_64.S
12426 --- linux-2.6.37/arch/x86/kernel/head_64.S 2011-01-04 19:50:19.000000000 -0500
12427 +++ linux-2.6.37/arch/x86/kernel/head_64.S 2011-01-17 02:41:01.000000000 -0500
12429 #include <asm/cache.h>
12430 #include <asm/processor-flags.h>
12431 #include <asm/percpu.h>
12432 +#include <asm/cpufeature.h>
12434 #ifdef CONFIG_PARAVIRT
12435 #include <asm/asm-offsets.h>
12436 @@ -38,6 +39,10 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET
12437 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
12438 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
12439 L3_START_KERNEL = pud_index(__START_KERNEL_map)
12440 +L4_VMALLOC_START = pgd_index(VMALLOC_START)
12441 +L3_VMALLOC_START = pud_index(VMALLOC_START)
12442 +L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
12443 +L3_VMEMMAP_START = pud_index(VMEMMAP_START)
12447 @@ -85,35 +90,22 @@ startup_64:
12449 addq %rbp, init_level4_pgt + 0(%rip)
12450 addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
12451 + addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
12452 + addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
12453 addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
12455 addq %rbp, level3_ident_pgt + 0(%rip)
12456 +#ifndef CONFIG_XEN
12457 + addq %rbp, level3_ident_pgt + 8(%rip)
12460 - addq %rbp, level3_kernel_pgt + (510*8)(%rip)
12461 - addq %rbp, level3_kernel_pgt + (511*8)(%rip)
12462 + addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
12464 - addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
12465 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
12466 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8+8)(%rip)
12468 - /* Add an Identity mapping if I am above 1G */
12469 - leaq _text(%rip), %rdi
12470 - andq $PMD_PAGE_MASK, %rdi
12473 - shrq $PUD_SHIFT, %rax
12474 - andq $(PTRS_PER_PUD - 1), %rax
12475 - jz ident_complete
12477 - leaq (level2_spare_pgt - __START_KERNEL_map + _KERNPG_TABLE)(%rbp), %rdx
12478 - leaq level3_ident_pgt(%rip), %rbx
12479 - movq %rdx, 0(%rbx, %rax, 8)
12482 - shrq $PMD_SHIFT, %rax
12483 - andq $(PTRS_PER_PMD - 1), %rax
12484 - leaq __PAGE_KERNEL_IDENT_LARGE_EXEC(%rdi), %rdx
12485 - leaq level2_spare_pgt(%rip), %rbx
12486 - movq %rdx, 0(%rbx, %rax, 8)
12488 + addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
12489 + addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
12492 * Fixup the kernel text+data virtual addresses. Note that
12493 @@ -161,8 +153,8 @@ ENTRY(secondary_startup_64)
12494 * after the boot processor executes this code.
12497 - /* Enable PAE mode and PGE */
12498 - movl $(X86_CR4_PAE | X86_CR4_PGE), %eax
12499 + /* Enable PAE mode and PSE/PGE */
12500 + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
12503 /* Setup early boot stage 4 level pagetables. */
12504 @@ -184,9 +176,14 @@ ENTRY(secondary_startup_64)
12505 movl $MSR_EFER, %ecx
12507 btsl $_EFER_SCE, %eax /* Enable System Call */
12508 - btl $20,%edi /* No Execute supported? */
12509 + btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
12511 btsl $_EFER_NX, %eax
12512 + leaq init_level4_pgt(%rip), %rdi
12513 + btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
12514 + btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
12515 + btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
12516 + btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
12517 1: wrmsr /* Make changes effective */
12520 @@ -270,7 +267,7 @@ ENTRY(secondary_startup_64)
12524 - .section ".init.text","ax"
12526 #ifdef CONFIG_EARLY_PRINTK
12527 .globl early_idt_handlers
12528 early_idt_handlers:
12529 @@ -315,18 +312,23 @@ ENTRY(early_idt_handler)
12530 #endif /* EARLY_PRINTK */
12535 #ifdef CONFIG_EARLY_PRINTK
12537 early_recursion_flag:
12541 + .section .rodata,"a",@progbits
12543 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
12546 -#endif /* CONFIG_EARLY_PRINTK */
12548 +#endif /* CONFIG_EARLY_PRINTK */
12550 + .section .rodata,"a",@progbits
12551 #define NEXT_PAGE(name) \
12552 .balign PAGE_SIZE; \
12554 @@ -339,7 +341,6 @@ ENTRY(name)
12560 * This default setting generates an ident mapping at address 0x100000
12561 * and a mapping for the kernel that precisely maps virtual address
12562 @@ -350,13 +351,36 @@ NEXT_PAGE(init_level4_pgt)
12563 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
12564 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
12565 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
12566 + .org init_level4_pgt + L4_VMALLOC_START*8, 0
12567 + .quad level3_vmalloc_pgt - __START_KERNEL_map + _KERNPG_TABLE
12568 + .org init_level4_pgt + L4_VMEMMAP_START*8, 0
12569 + .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
12570 .org init_level4_pgt + L4_START_KERNEL*8, 0
12571 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
12572 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
12574 +#ifdef CONFIG_PAX_PER_CPU_PGD
12575 +NEXT_PAGE(cpu_pgd)
12581 NEXT_PAGE(level3_ident_pgt)
12582 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
12586 + .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
12590 +NEXT_PAGE(level3_vmalloc_pgt)
12593 +NEXT_PAGE(level3_vmemmap_pgt)
12594 + .fill L3_VMEMMAP_START,8,0
12595 + .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
12597 NEXT_PAGE(level3_kernel_pgt)
12598 .fill L3_START_KERNEL,8,0
12599 @@ -364,20 +388,23 @@ NEXT_PAGE(level3_kernel_pgt)
12600 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
12601 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
12603 +NEXT_PAGE(level2_vmemmap_pgt)
12606 NEXT_PAGE(level2_fixmap_pgt)
12608 - .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
12609 - /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
12612 + .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
12613 + /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
12616 -NEXT_PAGE(level1_fixmap_pgt)
12617 +NEXT_PAGE(level1_vsyscall_pgt)
12620 -NEXT_PAGE(level2_ident_pgt)
12621 - /* Since I easily can, map the first 1G.
12622 + /* Since I easily can, map the first 2G.
12623 * Don't set NX because code runs from these pages.
12625 - PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
12626 +NEXT_PAGE(level2_ident_pgt)
12627 + PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
12629 NEXT_PAGE(level2_kernel_pgt)
12631 @@ -390,33 +417,55 @@ NEXT_PAGE(level2_kernel_pgt)
12632 * If you want to increase this then increase MODULES_VADDR
12635 - PMDS(0, __PAGE_KERNEL_LARGE_EXEC,
12636 - KERNEL_IMAGE_SIZE/PMD_SIZE)
12638 -NEXT_PAGE(level2_spare_pgt)
12640 + PMDS(0, __PAGE_KERNEL_LARGE_EXEC, KERNEL_IMAGE_SIZE/PMD_SIZE)
12647 +ENTRY(cpu_gdt_table)
12649 + .quad 0x0000000000000000 /* NULL descriptor */
12650 + .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
12651 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
12652 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
12653 + .quad 0x00cffb000000ffff /* __USER32_CS */
12654 + .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
12655 + .quad 0x00affb000000ffff /* __USER_CS */
12657 +#ifdef CONFIG_PAX_KERNEXEC
12658 + .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
12660 + .quad 0x0 /* unused */
12663 + .quad 0,0 /* TSS */
12664 + .quad 0,0 /* LDT */
12665 + .quad 0,0,0 /* three TLS descriptors */
12666 + .quad 0x0000f40000000000 /* node/CPU stored in limit */
12667 + /* asm/segment.h:GDT_ENTRIES must match this */
12669 + /* zero the remaining page */
12670 + .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
12674 .globl early_gdt_descr
12676 .word GDT_ENTRIES*8-1
12677 early_gdt_descr_base:
12678 - .quad INIT_PER_CPU_VAR(gdt_page)
12679 + .quad cpu_gdt_table
12682 /* This must match the first entry in level2_kernel_pgt */
12683 .quad 0x0000000000000000
12685 #include "../../x86/xen/xen-head.S"
12687 - .section .bss, "aw", @nobits
12689 + .section .rodata,"a",@progbits
12690 .align L1_CACHE_BYTES
12692 - .skip IDT_ENTRIES * 16
12697 diff -urNp linux-2.6.37/arch/x86/kernel/i386_ksyms_32.c linux-2.6.37/arch/x86/kernel/i386_ksyms_32.c
12698 --- linux-2.6.37/arch/x86/kernel/i386_ksyms_32.c 2011-01-04 19:50:19.000000000 -0500
12699 +++ linux-2.6.37/arch/x86/kernel/i386_ksyms_32.c 2011-01-17 02:41:01.000000000 -0500
12700 @@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
12701 EXPORT_SYMBOL(cmpxchg8b_emu);
12704 +EXPORT_SYMBOL_GPL(cpu_gdt_table);
12706 /* Networking helper routines. */
12707 EXPORT_SYMBOL(csum_partial_copy_generic);
12708 +EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
12709 +EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
12711 EXPORT_SYMBOL(__get_user_1);
12712 EXPORT_SYMBOL(__get_user_2);
12713 @@ -36,3 +40,7 @@ EXPORT_SYMBOL(strstr);
12715 EXPORT_SYMBOL(csum_partial);
12716 EXPORT_SYMBOL(empty_zero_page);
12718 +#ifdef CONFIG_PAX_KERNEXEC
12719 +EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
12721 diff -urNp linux-2.6.37/arch/x86/kernel/init_task.c linux-2.6.37/arch/x86/kernel/init_task.c
12722 --- linux-2.6.37/arch/x86/kernel/init_task.c 2011-01-04 19:50:19.000000000 -0500
12723 +++ linux-2.6.37/arch/x86/kernel/init_task.c 2011-01-17 02:41:01.000000000 -0500
12724 @@ -38,5 +38,5 @@ EXPORT_SYMBOL(init_task);
12725 * section. Since TSS's are completely CPU-local, we want them
12726 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
12728 -DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
12730 +struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
12731 +EXPORT_SYMBOL(init_tss);
12732 diff -urNp linux-2.6.37/arch/x86/kernel/ioport.c linux-2.6.37/arch/x86/kernel/ioport.c
12733 --- linux-2.6.37/arch/x86/kernel/ioport.c 2011-01-04 19:50:19.000000000 -0500
12734 +++ linux-2.6.37/arch/x86/kernel/ioport.c 2011-01-17 02:41:01.000000000 -0500
12736 #include <linux/sched.h>
12737 #include <linux/kernel.h>
12738 #include <linux/capability.h>
12739 +#include <linux/security.h>
12740 #include <linux/errno.h>
12741 #include <linux/types.h>
12742 #include <linux/ioport.h>
12743 @@ -41,6 +42,12 @@ asmlinkage long sys_ioperm(unsigned long
12745 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
12747 +#ifdef CONFIG_GRKERNSEC_IO
12748 + if (turn_on && grsec_disable_privio) {
12749 + gr_handle_ioperm();
12753 if (turn_on && !capable(CAP_SYS_RAWIO))
12756 @@ -67,7 +74,7 @@ asmlinkage long sys_ioperm(unsigned long
12757 * because the ->io_bitmap_max value must match the bitmap
12760 - tss = &per_cpu(init_tss, get_cpu());
12761 + tss = init_tss + get_cpu();
12763 set_bitmap(t->io_bitmap_ptr, from, num, !turn_on);
12765 @@ -112,6 +119,12 @@ long sys_iopl(unsigned int level, struct
12767 /* Trying to gain more privileges? */
12769 +#ifdef CONFIG_GRKERNSEC_IO
12770 + if (grsec_disable_privio) {
12771 + gr_handle_iopl();
12775 if (!capable(CAP_SYS_RAWIO))
12778 diff -urNp linux-2.6.37/arch/x86/kernel/irq_32.c linux-2.6.37/arch/x86/kernel/irq_32.c
12779 --- linux-2.6.37/arch/x86/kernel/irq_32.c 2011-01-04 19:50:19.000000000 -0500
12780 +++ linux-2.6.37/arch/x86/kernel/irq_32.c 2011-01-17 02:41:01.000000000 -0500
12781 @@ -91,7 +91,7 @@ execute_on_irq_stack(int overflow, struc
12784 /* build the stack frame on the IRQ stack */
12785 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
12786 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
12787 irqctx->tinfo.task = curctx->tinfo.task;
12788 irqctx->tinfo.previous_esp = current_stack_pointer;
12790 @@ -103,6 +103,10 @@ execute_on_irq_stack(int overflow, struc
12791 (irqctx->tinfo.preempt_count & ~SOFTIRQ_MASK) |
12792 (curctx->tinfo.preempt_count & SOFTIRQ_MASK);
12794 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12795 + __set_fs(irqctx->tinfo.addr_limit);
12798 if (unlikely(overflow))
12799 call_on_stack(print_stack_overflow, isp);
12801 @@ -113,6 +117,11 @@ execute_on_irq_stack(int overflow, struc
12802 : "0" (irq), "1" (desc), "2" (isp),
12803 "D" (desc->handle_irq)
12804 : "memory", "cc", "ecx");
12806 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12807 + __set_fs(curctx->tinfo.addr_limit);
12813 @@ -171,9 +180,18 @@ asmlinkage void do_softirq(void)
12814 irqctx->tinfo.previous_esp = current_stack_pointer;
12816 /* build the stack frame on the softirq stack */
12817 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
12818 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
12820 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12821 + __set_fs(irqctx->tinfo.addr_limit);
12824 call_on_stack(__do_softirq, isp);
12826 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12827 + __set_fs(curctx->addr_limit);
12831 * Shouldnt happen, we returned above if in_interrupt():
12833 diff -urNp linux-2.6.37/arch/x86/kernel/kgdb.c linux-2.6.37/arch/x86/kernel/kgdb.c
12834 --- linux-2.6.37/arch/x86/kernel/kgdb.c 2011-01-04 19:50:19.000000000 -0500
12835 +++ linux-2.6.37/arch/x86/kernel/kgdb.c 2011-01-17 02:41:01.000000000 -0500
12836 @@ -123,11 +123,11 @@ char *dbg_get_reg(int regno, void *mem,
12838 #ifdef CONFIG_X86_32
12840 - if (!user_mode_vm(regs))
12841 + if (!user_mode(regs))
12842 *(unsigned long *)mem = __KERNEL_DS;
12845 - if (!user_mode_vm(regs))
12846 + if (!user_mode(regs))
12847 *(unsigned long *)mem = kernel_stack_pointer(regs);
12850 @@ -722,7 +722,7 @@ void kgdb_arch_set_pc(struct pt_regs *re
12854 -struct kgdb_arch arch_kgdb_ops = {
12855 +const struct kgdb_arch arch_kgdb_ops = {
12856 /* Breakpoint instruction: */
12857 .gdb_bpt_instr = { 0xcc },
12858 .flags = KGDB_HW_BREAKPOINT,
12859 diff -urNp linux-2.6.37/arch/x86/kernel/kprobes.c linux-2.6.37/arch/x86/kernel/kprobes.c
12860 --- linux-2.6.37/arch/x86/kernel/kprobes.c 2011-01-04 19:50:19.000000000 -0500
12861 +++ linux-2.6.37/arch/x86/kernel/kprobes.c 2011-01-17 02:41:01.000000000 -0500
12862 @@ -115,8 +115,11 @@ static void __kprobes __synthesize_relat
12863 } __attribute__((packed)) *insn;
12865 insn = (struct __arch_relative_insn *)from;
12867 + pax_open_kernel();
12868 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
12870 + pax_close_kernel();
12873 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
12874 @@ -153,7 +156,7 @@ static int __kprobes can_boost(kprobe_op
12875 kprobe_opcode_t opcode;
12876 kprobe_opcode_t *orig_opcodes = opcodes;
12878 - if (search_exception_tables((unsigned long)opcodes))
12879 + if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
12880 return 0; /* Page fault may occur on this address. */
12883 @@ -314,7 +317,9 @@ static int __kprobes __copy_instruction(
12886 insn_get_length(&insn);
12887 + pax_open_kernel();
12888 memcpy(dest, insn.kaddr, insn.length);
12889 + pax_close_kernel();
12891 #ifdef CONFIG_X86_64
12892 if (insn_rip_relative(&insn)) {
12893 @@ -338,7 +343,9 @@ static int __kprobes __copy_instruction(
12895 BUG_ON((s64) (s32) newdisp != newdisp); /* Sanity check. */
12896 disp = (u8 *) dest + insn_offset_displacement(&insn);
12897 + pax_open_kernel();
12898 *(s32 *) disp = (s32) newdisp;
12899 + pax_close_kernel();
12902 return insn.length;
12903 @@ -352,12 +359,12 @@ static void __kprobes arch_copy_kprobe(s
12905 __copy_instruction(p->ainsn.insn, p->addr, 0);
12907 - if (can_boost(p->addr))
12908 + if (can_boost(ktla_ktva(p->addr)))
12909 p->ainsn.boostable = 0;
12911 p->ainsn.boostable = -1;
12913 - p->opcode = *p->addr;
12914 + p->opcode = *(ktla_ktva(p->addr));
12917 int __kprobes arch_prepare_kprobe(struct kprobe *p)
12918 @@ -474,7 +481,7 @@ static void __kprobes setup_singlestep(s
12919 * nor set current_kprobe, because it doesn't use single
12922 - regs->ip = (unsigned long)p->ainsn.insn;
12923 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
12924 preempt_enable_no_resched();
12927 @@ -493,7 +500,7 @@ static void __kprobes setup_singlestep(s
12928 if (p->opcode == BREAKPOINT_INSTRUCTION)
12929 regs->ip = (unsigned long)p->addr;
12931 - regs->ip = (unsigned long)p->ainsn.insn;
12932 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
12936 @@ -572,7 +579,7 @@ static int __kprobes kprobe_handler(stru
12937 setup_singlestep(p, regs, kcb, 0);
12940 - } else if (*addr != BREAKPOINT_INSTRUCTION) {
12941 + } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
12943 * The breakpoint instruction was removed right
12944 * after we hit it. Another cpu has removed
12945 @@ -817,7 +824,7 @@ static void __kprobes resume_execution(s
12946 struct pt_regs *regs, struct kprobe_ctlblk *kcb)
12948 unsigned long *tos = stack_addr(regs);
12949 - unsigned long copy_ip = (unsigned long)p->ainsn.insn;
12950 + unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
12951 unsigned long orig_ip = (unsigned long)p->addr;
12952 kprobe_opcode_t *insn = p->ainsn.insn;
12954 @@ -999,7 +1006,7 @@ int __kprobes kprobe_exceptions_notify(s
12955 struct die_args *args = data;
12956 int ret = NOTIFY_DONE;
12958 - if (args->regs && user_mode_vm(args->regs))
12959 + if (args->regs && user_mode(args->regs))
12963 @@ -1368,7 +1375,7 @@ int __kprobes arch_prepare_optimized_kpr
12964 * Verify if the address gap is in 2GB range, because this uses
12967 - rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
12968 + rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
12969 if (abs(rel) > 0x7fffffff)
12972 @@ -1389,11 +1396,11 @@ int __kprobes arch_prepare_optimized_kpr
12973 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
12975 /* Set probe function call */
12976 - synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
12977 + synthesize_relcall(buf + TMPL_CALL_IDX, ktla_ktva(optimized_callback));
12979 /* Set returning jmp instruction at the tail of out-of-line buffer */
12980 synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
12981 - (u8 *)op->kp.addr + op->optinsn.size);
12982 + (u8 *)ktla_ktva(op->kp.addr) + op->optinsn.size);
12984 flush_icache_range((unsigned long) buf,
12985 (unsigned long) buf + TMPL_END_IDX +
12986 @@ -1409,7 +1416,7 @@ int __kprobes arch_optimize_kprobe(struc
12987 ((long)op->kp.addr + RELATIVEJUMP_SIZE));
12989 /* Backup instructions which will be replaced by jump address */
12990 - memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
12991 + memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
12992 RELATIVE_ADDR_SIZE);
12994 jmp_code[0] = RELATIVEJUMP_OPCODE;
12995 diff -urNp linux-2.6.37/arch/x86/kernel/ldt.c linux-2.6.37/arch/x86/kernel/ldt.c
12996 --- linux-2.6.37/arch/x86/kernel/ldt.c 2011-01-04 19:50:19.000000000 -0500
12997 +++ linux-2.6.37/arch/x86/kernel/ldt.c 2011-01-17 02:41:01.000000000 -0500
12998 @@ -67,13 +67,13 @@ static int alloc_ldt(mm_context_t *pc, i
13003 + load_LDT_nolock(pc);
13004 if (!cpumask_equal(mm_cpumask(current->mm),
13005 cpumask_of(smp_processor_id())))
13006 smp_call_function(flush_ldt, current->mm, 1);
13010 + load_LDT_nolock(pc);
13014 @@ -95,7 +95,7 @@ static inline int copy_ldt(mm_context_t
13017 for (i = 0; i < old->size; i++)
13018 - write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
13019 + write_ldt_entry(new->ldt, i, old->ldt + i);
13023 @@ -116,6 +116,24 @@ int init_new_context(struct task_struct
13024 retval = copy_ldt(&mm->context, &old_mm->context);
13025 mutex_unlock(&old_mm->context.lock);
13028 + if (tsk == current) {
13029 + mm->context.vdso = 0;
13031 +#ifdef CONFIG_X86_32
13032 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
13033 + mm->context.user_cs_base = 0UL;
13034 + mm->context.user_cs_limit = ~0UL;
13036 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
13037 + cpus_clear(mm->context.cpu_user_cs_mask);
13048 @@ -230,6 +248,13 @@ static int write_ldt(void __user *ptr, u
13052 +#ifdef CONFIG_PAX_SEGMEXEC
13053 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
13059 fill_ldt(&ldt, &ldt_info);
13062 diff -urNp linux-2.6.37/arch/x86/kernel/machine_kexec_32.c linux-2.6.37/arch/x86/kernel/machine_kexec_32.c
13063 --- linux-2.6.37/arch/x86/kernel/machine_kexec_32.c 2011-01-04 19:50:19.000000000 -0500
13064 +++ linux-2.6.37/arch/x86/kernel/machine_kexec_32.c 2011-01-17 02:41:01.000000000 -0500
13066 #include <asm/cacheflush.h>
13067 #include <asm/debugreg.h>
13069 -static void set_idt(void *newidt, __u16 limit)
13070 +static void set_idt(struct desc_struct *newidt, __u16 limit)
13072 struct desc_ptr curidt;
13074 @@ -39,7 +39,7 @@ static void set_idt(void *newidt, __u16
13078 -static void set_gdt(void *newgdt, __u16 limit)
13079 +static void set_gdt(struct desc_struct *newgdt, __u16 limit)
13081 struct desc_ptr curgdt;
13083 @@ -217,7 +217,7 @@ void machine_kexec(struct kimage *image)
13086 control_page = page_address(image->control_code_page);
13087 - memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
13088 + memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
13090 relocate_kernel_ptr = control_page;
13091 page_list[PA_CONTROL_PAGE] = __pa(control_page);
13092 diff -urNp linux-2.6.37/arch/x86/kernel/microcode_amd.c linux-2.6.37/arch/x86/kernel/microcode_amd.c
13093 --- linux-2.6.37/arch/x86/kernel/microcode_amd.c 2011-01-04 19:50:19.000000000 -0500
13094 +++ linux-2.6.37/arch/x86/kernel/microcode_amd.c 2011-01-17 02:41:01.000000000 -0500
13095 @@ -331,7 +331,7 @@ static void microcode_fini_cpu_amd(int c
13099 -static struct microcode_ops microcode_amd_ops = {
13100 +static const struct microcode_ops microcode_amd_ops = {
13101 .request_microcode_user = request_microcode_user,
13102 .request_microcode_fw = request_microcode_fw,
13103 .collect_cpu_info = collect_cpu_info_amd,
13104 @@ -339,7 +339,7 @@ static struct microcode_ops microcode_am
13105 .microcode_fini_cpu = microcode_fini_cpu_amd,
13108 -struct microcode_ops * __init init_amd_microcode(void)
13109 +const struct microcode_ops * __init init_amd_microcode(void)
13111 return µcode_amd_ops;
13113 diff -urNp linux-2.6.37/arch/x86/kernel/microcode_core.c linux-2.6.37/arch/x86/kernel/microcode_core.c
13114 --- linux-2.6.37/arch/x86/kernel/microcode_core.c 2011-01-04 19:50:19.000000000 -0500
13115 +++ linux-2.6.37/arch/x86/kernel/microcode_core.c 2011-01-17 02:41:01.000000000 -0500
13116 @@ -92,7 +92,7 @@ MODULE_LICENSE("GPL");
13118 #define MICROCODE_VERSION "2.00"
13120 -static struct microcode_ops *microcode_ops;
13121 +static const struct microcode_ops *microcode_ops;
13125 diff -urNp linux-2.6.37/arch/x86/kernel/microcode_intel.c linux-2.6.37/arch/x86/kernel/microcode_intel.c
13126 --- linux-2.6.37/arch/x86/kernel/microcode_intel.c 2011-01-04 19:50:19.000000000 -0500
13127 +++ linux-2.6.37/arch/x86/kernel/microcode_intel.c 2011-01-17 02:41:01.000000000 -0500
13128 @@ -440,13 +440,13 @@ static enum ucode_state request_microcod
13130 static int get_ucode_user(void *to, const void *from, size_t n)
13132 - return copy_from_user(to, from, n);
13133 + return copy_from_user(to, (__force const void __user *)from, n);
13136 static enum ucode_state
13137 request_microcode_user(int cpu, const void __user *buf, size_t size)
13139 - return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
13140 + return generic_load_microcode(cpu, (__force void *)buf, size, &get_ucode_user);
13143 static void microcode_fini_cpu(int cpu)
13144 @@ -457,7 +457,7 @@ static void microcode_fini_cpu(int cpu)
13148 -static struct microcode_ops microcode_intel_ops = {
13149 +static const struct microcode_ops microcode_intel_ops = {
13150 .request_microcode_user = request_microcode_user,
13151 .request_microcode_fw = request_microcode_fw,
13152 .collect_cpu_info = collect_cpu_info,
13153 @@ -465,7 +465,7 @@ static struct microcode_ops microcode_in
13154 .microcode_fini_cpu = microcode_fini_cpu,
13157 -struct microcode_ops * __init init_intel_microcode(void)
13158 +const struct microcode_ops * __init init_intel_microcode(void)
13160 return µcode_intel_ops;
13162 diff -urNp linux-2.6.37/arch/x86/kernel/module.c linux-2.6.37/arch/x86/kernel/module.c
13163 --- linux-2.6.37/arch/x86/kernel/module.c 2011-01-04 19:50:19.000000000 -0500
13164 +++ linux-2.6.37/arch/x86/kernel/module.c 2011-01-17 02:41:01.000000000 -0500
13166 #define DEBUGP(fmt...)
13169 -void *module_alloc(unsigned long size)
13170 +static void *__module_alloc(unsigned long size, pgprot_t prot)
13172 struct vm_struct *area;
13174 @@ -49,8 +49,18 @@ void *module_alloc(unsigned long size)
13178 - return __vmalloc_area(area, GFP_KERNEL | __GFP_HIGHMEM,
13179 - PAGE_KERNEL_EXEC);
13180 + return __vmalloc_area(area, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot);
13183 +void *module_alloc(unsigned long size)
13186 +#ifdef CONFIG_PAX_KERNEXEC
13187 + return __module_alloc(size, PAGE_KERNEL);
13189 + return __module_alloc(size, PAGE_KERNEL_EXEC);
13194 /* Free memory returned from module_alloc */
13195 @@ -59,6 +69,40 @@ void module_free(struct module *mod, voi
13196 vfree(module_region);
13199 +#ifdef CONFIG_PAX_KERNEXEC
13200 +#ifdef CONFIG_X86_32
13201 +void *module_alloc_exec(unsigned long size)
13203 + struct vm_struct *area;
13208 + area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
13209 + return area ? area->addr : NULL;
13211 +EXPORT_SYMBOL(module_alloc_exec);
13213 +void module_free_exec(struct module *mod, void *module_region)
13215 + vunmap(module_region);
13217 +EXPORT_SYMBOL(module_free_exec);
13219 +void module_free_exec(struct module *mod, void *module_region)
13221 + module_free(mod, module_region);
13223 +EXPORT_SYMBOL(module_free_exec);
13225 +void *module_alloc_exec(unsigned long size)
13227 + return __module_alloc(size, PAGE_KERNEL_RX);
13229 +EXPORT_SYMBOL(module_alloc_exec);
13233 /* We don't need anything special. */
13234 int module_frob_arch_sections(Elf_Ehdr *hdr,
13236 @@ -78,14 +122,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
13238 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
13240 - uint32_t *location;
13241 + uint32_t *plocation, location;
13243 DEBUGP("Applying relocate section %u to %u\n", relsec,
13244 sechdrs[relsec].sh_info);
13245 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
13246 /* This is where to make the change */
13247 - location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
13248 - + rel[i].r_offset;
13249 + plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
13250 + location = (uint32_t)plocation;
13251 + if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
13252 + plocation = ktla_ktva((void *)plocation);
13253 /* This is the symbol it is referring to. Note that all
13254 undefined symbols have been resolved. */
13255 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
13256 @@ -94,11 +140,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
13257 switch (ELF32_R_TYPE(rel[i].r_info)) {
13259 /* We add the value into the location given */
13260 - *location += sym->st_value;
13261 + pax_open_kernel();
13262 + *plocation += sym->st_value;
13263 + pax_close_kernel();
13266 /* Add the value, subtract its postition */
13267 - *location += sym->st_value - (uint32_t)location;
13268 + pax_open_kernel();
13269 + *plocation += sym->st_value - location;
13270 + pax_close_kernel();
13273 printk(KERN_ERR "module %s: Unknown relocation: %u\n",
13274 @@ -154,21 +204,30 @@ int apply_relocate_add(Elf64_Shdr *sechd
13275 case R_X86_64_NONE:
13278 + pax_open_kernel();
13280 + pax_close_kernel();
13283 + pax_open_kernel();
13285 + pax_close_kernel();
13286 if (val != *(u32 *)loc)
13290 + pax_open_kernel();
13292 + pax_close_kernel();
13293 if ((s64)val != *(s32 *)loc)
13296 case R_X86_64_PC32:
13298 + pax_open_kernel();
13300 + pax_close_kernel();
13303 if ((s64)val != *(s32 *)loc)
13305 diff -urNp linux-2.6.37/arch/x86/kernel/paravirt.c linux-2.6.37/arch/x86/kernel/paravirt.c
13306 --- linux-2.6.37/arch/x86/kernel/paravirt.c 2011-01-04 19:50:19.000000000 -0500
13307 +++ linux-2.6.37/arch/x86/kernel/paravirt.c 2011-01-17 02:41:01.000000000 -0500
13308 @@ -122,7 +122,7 @@ unsigned paravirt_patch_jmp(void *insnbu
13309 * corresponding structure. */
13310 static void *get_call_destination(u8 type)
13312 - struct paravirt_patch_template tmpl = {
13313 + const struct paravirt_patch_template tmpl = {
13314 .pv_init_ops = pv_init_ops,
13315 .pv_time_ops = pv_time_ops,
13316 .pv_cpu_ops = pv_cpu_ops,
13317 @@ -145,14 +145,14 @@ unsigned paravirt_patch_default(u8 type,
13318 if (opfunc == NULL)
13319 /* If there's no function, patch it with a ud2a (BUG) */
13320 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
13321 - else if (opfunc == _paravirt_nop)
13322 + else if (opfunc == (void *)_paravirt_nop)
13323 /* If the operation is a nop, then nop the callsite */
13324 ret = paravirt_patch_nop();
13326 /* identity functions just return their single argument */
13327 - else if (opfunc == _paravirt_ident_32)
13328 + else if (opfunc == (void *)_paravirt_ident_32)
13329 ret = paravirt_patch_ident_32(insnbuf, len);
13330 - else if (opfunc == _paravirt_ident_64)
13331 + else if (opfunc == (void *)_paravirt_ident_64)
13332 ret = paravirt_patch_ident_64(insnbuf, len);
13334 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
13335 @@ -178,7 +178,7 @@ unsigned paravirt_patch_insns(void *insn
13336 if (insn_len > len || start == NULL)
13339 - memcpy(insnbuf, start, insn_len);
13340 + memcpy(insnbuf, ktla_ktva(start), insn_len);
13344 @@ -294,22 +294,22 @@ void arch_flush_lazy_mmu_mode(void)
13348 -struct pv_info pv_info = {
13349 +struct pv_info pv_info __read_only = {
13350 .name = "bare hardware",
13351 .paravirt_enabled = 0,
13353 .shared_kernel_pmd = 1, /* Only used when CONFIG_X86_PAE is set */
13356 -struct pv_init_ops pv_init_ops = {
13357 +struct pv_init_ops pv_init_ops __read_only = {
13358 .patch = native_patch,
13361 -struct pv_time_ops pv_time_ops = {
13362 +struct pv_time_ops pv_time_ops __read_only = {
13363 .sched_clock = native_sched_clock,
13366 -struct pv_irq_ops pv_irq_ops = {
13367 +struct pv_irq_ops pv_irq_ops __read_only = {
13368 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
13369 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
13370 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
13371 @@ -321,7 +321,7 @@ struct pv_irq_ops pv_irq_ops = {
13375 -struct pv_cpu_ops pv_cpu_ops = {
13376 +struct pv_cpu_ops pv_cpu_ops __read_only = {
13377 .cpuid = native_cpuid,
13378 .get_debugreg = native_get_debugreg,
13379 .set_debugreg = native_set_debugreg,
13380 @@ -382,7 +382,7 @@ struct pv_cpu_ops pv_cpu_ops = {
13381 .end_context_switch = paravirt_nop,
13384 -struct pv_apic_ops pv_apic_ops = {
13385 +struct pv_apic_ops pv_apic_ops __read_only = {
13386 #ifdef CONFIG_X86_LOCAL_APIC
13387 .startup_ipi_hook = paravirt_nop,
13389 @@ -396,7 +396,7 @@ struct pv_apic_ops pv_apic_ops = {
13390 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
13393 -struct pv_mmu_ops pv_mmu_ops = {
13394 +struct pv_mmu_ops pv_mmu_ops __read_only = {
13396 .read_cr2 = native_read_cr2,
13397 .write_cr2 = native_write_cr2,
13398 @@ -462,6 +462,12 @@ struct pv_mmu_ops pv_mmu_ops = {
13401 .set_fixmap = native_set_fixmap,
13403 +#ifdef CONFIG_PAX_KERNEXEC
13404 + .pax_open_kernel = native_pax_open_kernel,
13405 + .pax_close_kernel = native_pax_close_kernel,
13410 EXPORT_SYMBOL_GPL(pv_time_ops);
13411 diff -urNp linux-2.6.37/arch/x86/kernel/paravirt-spinlocks.c linux-2.6.37/arch/x86/kernel/paravirt-spinlocks.c
13412 --- linux-2.6.37/arch/x86/kernel/paravirt-spinlocks.c 2011-01-04 19:50:19.000000000 -0500
13413 +++ linux-2.6.37/arch/x86/kernel/paravirt-spinlocks.c 2011-01-17 02:41:01.000000000 -0500
13414 @@ -13,7 +13,7 @@ default_spin_lock_flags(arch_spinlock_t
13415 arch_spin_lock(lock);
13418 -struct pv_lock_ops pv_lock_ops = {
13419 +struct pv_lock_ops pv_lock_ops __read_only = {
13421 .spin_is_locked = __ticket_spin_is_locked,
13422 .spin_is_contended = __ticket_spin_is_contended,
13423 diff -urNp linux-2.6.37/arch/x86/kernel/pci-calgary_64.c linux-2.6.37/arch/x86/kernel/pci-calgary_64.c
13424 --- linux-2.6.37/arch/x86/kernel/pci-calgary_64.c 2011-01-04 19:50:19.000000000 -0500
13425 +++ linux-2.6.37/arch/x86/kernel/pci-calgary_64.c 2011-01-17 02:41:01.000000000 -0500
13426 @@ -476,7 +476,7 @@ static void calgary_free_coherent(struct
13427 free_pages((unsigned long)vaddr, get_order(size));
13430 -static struct dma_map_ops calgary_dma_ops = {
13431 +static const struct dma_map_ops calgary_dma_ops = {
13432 .alloc_coherent = calgary_alloc_coherent,
13433 .free_coherent = calgary_free_coherent,
13434 .map_sg = calgary_map_sg,
13435 diff -urNp linux-2.6.37/arch/x86/kernel/pci-dma.c linux-2.6.37/arch/x86/kernel/pci-dma.c
13436 --- linux-2.6.37/arch/x86/kernel/pci-dma.c 2011-01-04 19:50:19.000000000 -0500
13437 +++ linux-2.6.37/arch/x86/kernel/pci-dma.c 2011-01-17 02:41:01.000000000 -0500
13440 static int forbid_dac __read_mostly;
13442 -struct dma_map_ops *dma_ops = &nommu_dma_ops;
13443 +const struct dma_map_ops *dma_ops = &nommu_dma_ops;
13444 EXPORT_SYMBOL(dma_ops);
13446 static int iommu_sac_force __read_mostly;
13447 @@ -250,7 +250,7 @@ early_param("iommu", iommu_setup);
13449 int dma_supported(struct device *dev, u64 mask)
13451 - struct dma_map_ops *ops = get_dma_ops(dev);
13452 + const struct dma_map_ops *ops = get_dma_ops(dev);
13455 if (mask > 0xffffffff && forbid_dac > 0) {
13456 diff -urNp linux-2.6.37/arch/x86/kernel/pci-gart_64.c linux-2.6.37/arch/x86/kernel/pci-gart_64.c
13457 --- linux-2.6.37/arch/x86/kernel/pci-gart_64.c 2011-01-04 19:50:19.000000000 -0500
13458 +++ linux-2.6.37/arch/x86/kernel/pci-gart_64.c 2011-01-17 02:41:01.000000000 -0500
13459 @@ -706,7 +706,7 @@ static __init int init_k8_gatt(struct ag
13463 -static struct dma_map_ops gart_dma_ops = {
13464 +static const struct dma_map_ops gart_dma_ops = {
13465 .map_sg = gart_map_sg,
13466 .unmap_sg = gart_unmap_sg,
13467 .map_page = gart_map_page,
13468 diff -urNp linux-2.6.37/arch/x86/kernel/pci-nommu.c linux-2.6.37/arch/x86/kernel/pci-nommu.c
13469 --- linux-2.6.37/arch/x86/kernel/pci-nommu.c 2011-01-04 19:50:19.000000000 -0500
13470 +++ linux-2.6.37/arch/x86/kernel/pci-nommu.c 2011-01-17 02:41:01.000000000 -0500
13471 @@ -95,7 +95,7 @@ static void nommu_sync_sg_for_device(str
13472 flush_write_buffers();
13475 -struct dma_map_ops nommu_dma_ops = {
13476 +const struct dma_map_ops nommu_dma_ops = {
13477 .alloc_coherent = dma_generic_alloc_coherent,
13478 .free_coherent = nommu_free_coherent,
13479 .map_sg = nommu_map_sg,
13480 diff -urNp linux-2.6.37/arch/x86/kernel/pci-swiotlb.c linux-2.6.37/arch/x86/kernel/pci-swiotlb.c
13481 --- linux-2.6.37/arch/x86/kernel/pci-swiotlb.c 2011-01-04 19:50:19.000000000 -0500
13482 +++ linux-2.6.37/arch/x86/kernel/pci-swiotlb.c 2011-01-17 02:41:01.000000000 -0500
13483 @@ -26,7 +26,7 @@ static void *x86_swiotlb_alloc_coherent(
13484 return swiotlb_alloc_coherent(hwdev, size, dma_handle, flags);
13487 -static struct dma_map_ops swiotlb_dma_ops = {
13488 +static const struct dma_map_ops swiotlb_dma_ops = {
13489 .mapping_error = swiotlb_dma_mapping_error,
13490 .alloc_coherent = x86_swiotlb_alloc_coherent,
13491 .free_coherent = swiotlb_free_coherent,
13492 diff -urNp linux-2.6.37/arch/x86/kernel/process_32.c linux-2.6.37/arch/x86/kernel/process_32.c
13493 --- linux-2.6.37/arch/x86/kernel/process_32.c 2011-01-04 19:50:19.000000000 -0500
13494 +++ linux-2.6.37/arch/x86/kernel/process_32.c 2011-01-17 02:41:01.000000000 -0500
13495 @@ -67,6 +67,7 @@ asmlinkage void ret_from_fork(void) __as
13496 unsigned long thread_saved_pc(struct task_struct *tsk)
13498 return ((unsigned long *)tsk->thread.sp)[3];
13499 +//XXX return tsk->thread.eip;
13503 @@ -130,15 +131,14 @@ void __show_regs(struct pt_regs *regs, i
13505 unsigned short ss, gs;
13507 - if (user_mode_vm(regs)) {
13508 + if (user_mode(regs)) {
13510 ss = regs->ss & 0xffff;
13511 - gs = get_user_gs(regs);
13513 sp = kernel_stack_pointer(regs);
13514 savesegment(ss, ss);
13515 - savesegment(gs, gs);
13517 + gs = get_user_gs(regs);
13519 show_regs_common();
13521 @@ -200,7 +200,7 @@ int copy_thread(unsigned long clone_flag
13522 struct task_struct *tsk;
13525 - childregs = task_pt_regs(p);
13526 + childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
13527 *childregs = *regs;
13529 childregs->sp = sp;
13530 @@ -297,7 +297,7 @@ __switch_to(struct task_struct *prev_p,
13531 struct thread_struct *prev = &prev_p->thread,
13532 *next = &next_p->thread;
13533 int cpu = smp_processor_id();
13534 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
13535 + struct tss_struct *tss = init_tss + cpu;
13538 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
13539 @@ -332,6 +332,10 @@ __switch_to(struct task_struct *prev_p,
13541 lazy_save_gs(prev->gs);
13543 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13544 + __set_fs(task_thread_info(next_p)->addr_limit);
13548 * Load the per-thread Thread-Local Storage descriptor.
13550 @@ -408,3 +412,27 @@ unsigned long get_wchan(struct task_stru
13554 +#ifdef CONFIG_PAX_RANDKSTACK
13555 +asmlinkage void pax_randomize_kstack(void)
13557 + struct thread_struct *thread = ¤t->thread;
13558 + unsigned long time;
13560 + if (!randomize_va_space)
13565 + /* P4 seems to return a 0 LSB, ignore it */
13566 +#ifdef CONFIG_MPENTIUM4
13574 + thread->sp0 ^= time;
13575 + load_sp0(init_tss + smp_processor_id(), thread);
13578 diff -urNp linux-2.6.37/arch/x86/kernel/process_64.c linux-2.6.37/arch/x86/kernel/process_64.c
13579 --- linux-2.6.37/arch/x86/kernel/process_64.c 2011-01-04 19:50:19.000000000 -0500
13580 +++ linux-2.6.37/arch/x86/kernel/process_64.c 2011-01-17 02:41:01.000000000 -0500
13581 @@ -89,7 +89,7 @@ static void __exit_idle(void)
13582 void exit_idle(void)
13584 /* idle loop has pid 0 */
13585 - if (current->pid)
13586 + if (task_pid_nr(current))
13590 @@ -380,7 +380,7 @@ __switch_to(struct task_struct *prev_p,
13591 struct thread_struct *prev = &prev_p->thread;
13592 struct thread_struct *next = &next_p->thread;
13593 int cpu = smp_processor_id();
13594 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
13595 + struct tss_struct *tss = init_tss + cpu;
13596 unsigned fsindex, gsindex;
13599 @@ -533,12 +533,11 @@ unsigned long get_wchan(struct task_stru
13600 if (!p || p == current || p->state == TASK_RUNNING)
13602 stack = (unsigned long)task_stack_page(p);
13603 - if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
13604 + if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-8-sizeof(u64))
13606 fp = *(u64 *)(p->thread.sp);
13608 - if (fp < (unsigned long)stack ||
13609 - fp >= (unsigned long)stack+THREAD_SIZE)
13610 + if (fp < stack || fp > stack+THREAD_SIZE-8-sizeof(u64))
13612 ip = *(u64 *)(fp+8);
13613 if (!in_sched_functions(ip))
13614 diff -urNp linux-2.6.37/arch/x86/kernel/process.c linux-2.6.37/arch/x86/kernel/process.c
13615 --- linux-2.6.37/arch/x86/kernel/process.c 2011-01-04 19:50:19.000000000 -0500
13616 +++ linux-2.6.37/arch/x86/kernel/process.c 2011-01-17 02:41:01.000000000 -0500
13617 @@ -74,7 +74,7 @@ void exit_thread(void)
13618 unsigned long *bp = t->io_bitmap_ptr;
13621 - struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
13622 + struct tss_struct *tss = init_tss + get_cpu();
13624 t->io_bitmap_ptr = NULL;
13625 clear_thread_flag(TIF_IO_BITMAP);
13626 @@ -118,6 +118,9 @@ void flush_thread(void)
13628 struct task_struct *tsk = current;
13630 +#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
13631 + loadsegment(gs, 0);
13633 flush_ptrace_hw_breakpoint(tsk);
13634 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
13636 @@ -280,10 +283,10 @@ int kernel_thread(int (*fn)(void *), voi
13637 regs.di = (unsigned long) arg;
13639 #ifdef CONFIG_X86_32
13640 - regs.ds = __USER_DS;
13641 - regs.es = __USER_DS;
13642 + regs.ds = __KERNEL_DS;
13643 + regs.es = __KERNEL_DS;
13644 regs.fs = __KERNEL_PERCPU;
13645 - regs.gs = __KERNEL_STACK_CANARY;
13646 + savesegment(gs, regs.gs);
13648 regs.ss = __KERNEL_DS;
13650 @@ -658,17 +661,3 @@ static int __init idle_setup(char *str)
13653 early_param("idle", idle_setup);
13655 -unsigned long arch_align_stack(unsigned long sp)
13657 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
13658 - sp -= get_random_int() % 8192;
13659 - return sp & ~0xf;
13662 -unsigned long arch_randomize_brk(struct mm_struct *mm)
13664 - unsigned long range_end = mm->brk + 0x02000000;
13665 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
13668 diff -urNp linux-2.6.37/arch/x86/kernel/ptrace.c linux-2.6.37/arch/x86/kernel/ptrace.c
13669 --- linux-2.6.37/arch/x86/kernel/ptrace.c 2011-01-04 19:50:19.000000000 -0500
13670 +++ linux-2.6.37/arch/x86/kernel/ptrace.c 2011-01-17 02:41:01.000000000 -0500
13671 @@ -805,7 +805,7 @@ long arch_ptrace(struct task_struct *chi
13672 unsigned long addr, unsigned long data)
13675 - unsigned long __user *datap = (unsigned long __user *)data;
13676 + unsigned long __user *datap = (__force unsigned long __user *)data;
13679 /* read the word at location addr in the USER area. */
13680 @@ -890,14 +890,14 @@ long arch_ptrace(struct task_struct *chi
13681 if ((int) addr < 0)
13683 ret = do_get_thread_area(child, addr,
13684 - (struct user_desc __user *)data);
13685 + (__force struct user_desc __user *) data);
13688 case PTRACE_SET_THREAD_AREA:
13689 if ((int) addr < 0)
13691 ret = do_set_thread_area(child, addr,
13692 - (struct user_desc __user *)data, 0);
13693 + (__force struct user_desc __user *) data, 0);
13697 @@ -1314,7 +1314,7 @@ static void fill_sigtrap_info(struct tas
13698 memset(info, 0, sizeof(*info));
13699 info->si_signo = SIGTRAP;
13700 info->si_code = si_code;
13701 - info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
13702 + info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
13705 void user_single_step_siginfo(struct task_struct *tsk,
13706 diff -urNp linux-2.6.37/arch/x86/kernel/reboot.c linux-2.6.37/arch/x86/kernel/reboot.c
13707 --- linux-2.6.37/arch/x86/kernel/reboot.c 2011-01-04 19:50:19.000000000 -0500
13708 +++ linux-2.6.37/arch/x86/kernel/reboot.c 2011-01-17 02:41:01.000000000 -0500
13709 @@ -33,7 +33,7 @@ void (*pm_power_off)(void);
13710 EXPORT_SYMBOL(pm_power_off);
13712 static const struct desc_ptr no_idt = {};
13713 -static int reboot_mode;
13714 +static unsigned short reboot_mode;
13715 enum reboot_type reboot_type = BOOT_KBD;
13718 @@ -284,7 +284,7 @@ static struct dmi_system_id __initdata r
13719 DMI_MATCH(DMI_BOARD_NAME, "P4S800"),
13723 + { NULL, NULL, {{0, {0}}}, NULL}
13726 static int __init reboot_init(void)
13727 @@ -300,12 +300,12 @@ core_initcall(reboot_init);
13728 controller to pulse the CPU reset line, which is more thorough, but
13729 doesn't work with at least one type of 486 motherboard. It is easy
13730 to stop this code working; hence the copious comments. */
13731 -static const unsigned long long
13732 -real_mode_gdt_entries [3] =
13733 +static struct desc_struct
13734 +real_mode_gdt_entries [3] __read_only =
13736 - 0x0000000000000000ULL, /* Null descriptor */
13737 - 0x00009b000000ffffULL, /* 16-bit real-mode 64k code at 0x00000000 */
13738 - 0x000093000100ffffULL /* 16-bit real-mode 64k data at 0x00000100 */
13739 + GDT_ENTRY_INIT(0, 0, 0), /* Null descriptor */
13740 + GDT_ENTRY_INIT(0x9b, 0, 0xffff), /* 16-bit real-mode 64k code at 0x00000000 */
13741 + GDT_ENTRY_INIT(0x93, 0x100, 0xffff) /* 16-bit real-mode 64k data at 0x00000100 */
13744 static const struct desc_ptr
13745 @@ -354,7 +354,7 @@ static const unsigned char jump_to_bios
13746 * specified by the code and length parameters.
13747 * We assume that length will aways be less that 100!
13749 -void machine_real_restart(const unsigned char *code, int length)
13750 +void machine_real_restart(const unsigned char *code, unsigned int length)
13752 local_irq_disable();
13754 @@ -381,16 +381,15 @@ void machine_real_restart(const unsigned
13755 boot)". This seems like a fairly standard thing that gets set by
13756 REBOOT.COM programs, and the previous reset routine did this
13758 - *((unsigned short *)0x472) = reboot_mode;
13759 + *(unsigned short *)(__va(0x472)) = reboot_mode;
13761 /* For the switch to real mode, copy some code to low memory. It has
13762 to be in the first 64k because it is running in 16-bit mode, and it
13763 has to have the same physical and virtual address, because it turns
13764 off paging. Copy it near the end of the first page, out of the way
13765 of BIOS variables. */
13766 - memcpy((void *)(0x1000 - sizeof(real_mode_switch) - 100),
13767 - real_mode_switch, sizeof (real_mode_switch));
13768 - memcpy((void *)(0x1000 - 100), code, length);
13769 + memcpy(__va(0x1000 - sizeof (real_mode_switch) - 100), real_mode_switch, sizeof (real_mode_switch));
13770 + memcpy(__va(0x1000 - 100), code, length);
13772 /* Set up the IDT for real mode. */
13773 load_idt(&real_mode_idt);
13774 diff -urNp linux-2.6.37/arch/x86/kernel/setup.c linux-2.6.37/arch/x86/kernel/setup.c
13775 --- linux-2.6.37/arch/x86/kernel/setup.c 2011-01-04 19:50:19.000000000 -0500
13776 +++ linux-2.6.37/arch/x86/kernel/setup.c 2011-01-17 02:41:01.000000000 -0500
13777 @@ -654,7 +654,7 @@ static void __init trim_bios_range(void)
13778 * area (640->1Mb) as ram even though it is not.
13781 - e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
13782 + e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
13783 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
13786 @@ -790,14 +790,14 @@ void __init setup_arch(char **cmdline_p)
13788 if (!boot_params.hdr.root_flags)
13789 root_mountflags &= ~MS_RDONLY;
13790 - init_mm.start_code = (unsigned long) _text;
13791 - init_mm.end_code = (unsigned long) _etext;
13792 + init_mm.start_code = ktla_ktva((unsigned long) _text);
13793 + init_mm.end_code = ktla_ktva((unsigned long) _etext);
13794 init_mm.end_data = (unsigned long) _edata;
13795 init_mm.brk = _brk_end;
13797 - code_resource.start = virt_to_phys(_text);
13798 - code_resource.end = virt_to_phys(_etext)-1;
13799 - data_resource.start = virt_to_phys(_etext);
13800 + code_resource.start = virt_to_phys(ktla_ktva(_text));
13801 + code_resource.end = virt_to_phys(ktla_ktva(_etext))-1;
13802 + data_resource.start = virt_to_phys(_sdata);
13803 data_resource.end = virt_to_phys(_edata)-1;
13804 bss_resource.start = virt_to_phys(&__bss_start);
13805 bss_resource.end = virt_to_phys(&__bss_stop)-1;
13806 diff -urNp linux-2.6.37/arch/x86/kernel/setup_percpu.c linux-2.6.37/arch/x86/kernel/setup_percpu.c
13807 --- linux-2.6.37/arch/x86/kernel/setup_percpu.c 2011-01-04 19:50:19.000000000 -0500
13808 +++ linux-2.6.37/arch/x86/kernel/setup_percpu.c 2011-01-17 02:41:01.000000000 -0500
13809 @@ -21,19 +21,17 @@
13810 #include <asm/cpu.h>
13811 #include <asm/stackprotector.h>
13813 -DEFINE_PER_CPU(int, cpu_number);
13815 +DEFINE_PER_CPU(unsigned int, cpu_number);
13816 EXPORT_PER_CPU_SYMBOL(cpu_number);
13819 -#ifdef CONFIG_X86_64
13820 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
13822 -#define BOOT_PERCPU_OFFSET 0
13825 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
13826 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
13828 -unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
13829 +unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
13830 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
13832 EXPORT_SYMBOL(__per_cpu_offset);
13833 @@ -155,10 +153,10 @@ static inline void setup_percpu_segment(
13835 #ifdef CONFIG_X86_32
13836 struct desc_struct gdt;
13837 + unsigned long base = per_cpu_offset(cpu);
13839 - pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
13840 - 0x2 | DESCTYPE_S, 0x8);
13842 + pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
13843 + 0x83 | DESCTYPE_S, 0xC);
13844 write_gdt_entry(get_cpu_gdt_table(cpu),
13845 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
13847 @@ -207,6 +205,11 @@ void __init setup_per_cpu_areas(void)
13848 /* alrighty, percpu areas up and running */
13849 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
13850 for_each_possible_cpu(cpu) {
13851 +#ifdef CONFIG_CC_STACKPROTECTOR
13852 +#ifdef CONFIG_x86_32
13853 + unsigned long canary = per_cpu(stack_canary, cpu);
13856 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
13857 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
13858 per_cpu(cpu_number, cpu) = cpu;
13859 @@ -243,6 +246,12 @@ void __init setup_per_cpu_areas(void)
13860 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
13863 +#ifdef CONFIG_CC_STACKPROTECTOR
13864 +#ifdef CONFIG_x86_32
13865 + if (cpu == boot_cpu_id)
13866 + per_cpu(stack_canary, cpu) = canary;
13870 * Up to this point, the boot CPU has been using .init.data
13871 * area. Reload any changed state for the boot CPU.
13872 diff -urNp linux-2.6.37/arch/x86/kernel/signal.c linux-2.6.37/arch/x86/kernel/signal.c
13873 --- linux-2.6.37/arch/x86/kernel/signal.c 2011-01-04 19:50:19.000000000 -0500
13874 +++ linux-2.6.37/arch/x86/kernel/signal.c 2011-01-17 02:41:01.000000000 -0500
13875 @@ -198,7 +198,7 @@ static unsigned long align_sigframe(unsi
13876 * Align the stack pointer according to the i386 ABI,
13877 * i.e. so that on function entry ((sp + 4) & 15) == 0.
13879 - sp = ((sp + 4) & -16ul) - 4;
13880 + sp = ((sp - 12) & -16ul) - 4;
13881 #else /* !CONFIG_X86_32 */
13882 sp = round_down(sp, 16) - 8;
13884 @@ -249,11 +249,11 @@ get_sigframe(struct k_sigaction *ka, str
13885 * Return an always-bogus address instead so we will die with SIGSEGV.
13887 if (onsigstack && !likely(on_sig_stack(sp)))
13888 - return (void __user *)-1L;
13889 + return (__force void __user *)-1L;
13891 /* save i387 state */
13892 if (used_math() && save_i387_xstate(*fpstate) < 0)
13893 - return (void __user *)-1L;
13894 + return (__force void __user *)-1L;
13896 return (void __user *)sp;
13898 @@ -308,9 +308,9 @@ __setup_frame(int sig, struct k_sigactio
13901 if (current->mm->context.vdso)
13902 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
13903 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
13905 - restorer = &frame->retcode;
13906 + restorer = (void __user *)&frame->retcode;
13907 if (ka->sa.sa_flags & SA_RESTORER)
13908 restorer = ka->sa.sa_restorer;
13910 @@ -324,7 +324,7 @@ __setup_frame(int sig, struct k_sigactio
13911 * reasons and because gdb uses it as a signature to notice
13912 * signal handler stack frames.
13914 - err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
13915 + err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
13919 @@ -378,7 +378,10 @@ static int __setup_rt_frame(int sig, str
13920 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
13922 /* Set up to return from userspace. */
13923 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
13924 + if (current->mm->context.vdso)
13925 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
13927 + restorer = (void __user *)&frame->retcode;
13928 if (ka->sa.sa_flags & SA_RESTORER)
13929 restorer = ka->sa.sa_restorer;
13930 put_user_ex(restorer, &frame->pretcode);
13931 @@ -390,7 +393,7 @@ static int __setup_rt_frame(int sig, str
13932 * reasons and because gdb uses it as a signature to notice
13933 * signal handler stack frames.
13935 - put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
13936 + put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
13937 } put_user_catch(err);
13940 @@ -780,7 +783,7 @@ static void do_signal(struct pt_regs *re
13941 * X86_32: vm86 regs switched out by assembly code before reaching
13942 * here, so testing against kernel CS suffices.
13944 - if (!user_mode(regs))
13945 + if (!user_mode_novm(regs))
13948 if (current_thread_info()->status & TS_RESTORE_SIGMASK)
13949 diff -urNp linux-2.6.37/arch/x86/kernel/smpboot.c linux-2.6.37/arch/x86/kernel/smpboot.c
13950 --- linux-2.6.37/arch/x86/kernel/smpboot.c 2011-01-04 19:50:19.000000000 -0500
13951 +++ linux-2.6.37/arch/x86/kernel/smpboot.c 2011-01-17 02:41:01.000000000 -0500
13952 @@ -786,7 +786,11 @@ do_rest:
13953 (unsigned long)task_stack_page(c_idle.idle) -
13954 KERNEL_STACK_OFFSET + THREAD_SIZE;
13957 + pax_open_kernel();
13958 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
13959 + pax_close_kernel();
13961 initial_code = (unsigned long)start_secondary;
13962 stack_start.sp = (void *) c_idle.idle->thread.sp;
13964 @@ -926,6 +930,12 @@ int __cpuinit native_cpu_up(unsigned int
13966 per_cpu(cpu_state, cpu) = CPU_UP_PREPARE;
13968 +#ifdef CONFIG_PAX_PER_CPU_PGD
13969 + clone_pgd_range(get_cpu_pgd(cpu) + KERNEL_PGD_BOUNDARY,
13970 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
13971 + KERNEL_PGD_PTRS);
13974 err = do_boot_cpu(apicid, cpu);
13976 pr_debug("do_boot_cpu failed %d\n", err);
13977 diff -urNp linux-2.6.37/arch/x86/kernel/step.c linux-2.6.37/arch/x86/kernel/step.c
13978 --- linux-2.6.37/arch/x86/kernel/step.c 2011-01-04 19:50:19.000000000 -0500
13979 +++ linux-2.6.37/arch/x86/kernel/step.c 2011-01-17 02:41:01.000000000 -0500
13980 @@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struc
13981 struct desc_struct *desc;
13982 unsigned long base;
13987 mutex_lock(&child->mm->context.lock);
13988 - if (unlikely((seg >> 3) >= child->mm->context.size))
13989 + if (unlikely(seg >= child->mm->context.size))
13990 addr = -1L; /* bogus selector, access would fault */
13992 desc = child->mm->context.ldt + seg;
13993 @@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struc
13996 mutex_unlock(&child->mm->context.lock);
13998 + } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
13999 + addr = ktla_ktva(addr);
14003 @@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct t
14004 unsigned char opcode[15];
14005 unsigned long addr = convert_ip_to_linear(child, regs);
14007 + if (addr == -EINVAL)
14010 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
14011 for (i = 0; i < copied; i++) {
14012 switch (opcode[i]) {
14013 @@ -74,7 +78,7 @@ static int is_setting_trap_flag(struct t
14015 #ifdef CONFIG_X86_64
14016 case 0x40 ... 0x4f:
14017 - if (regs->cs != __USER_CS)
14018 + if ((regs->cs & 0xffff) != __USER_CS)
14019 /* 32-bit mode: register increment */
14021 /* 64-bit mode: REX prefix */
14022 diff -urNp linux-2.6.37/arch/x86/kernel/syscall_table_32.S linux-2.6.37/arch/x86/kernel/syscall_table_32.S
14023 --- linux-2.6.37/arch/x86/kernel/syscall_table_32.S 2011-01-04 19:50:19.000000000 -0500
14024 +++ linux-2.6.37/arch/x86/kernel/syscall_table_32.S 2011-01-17 02:41:01.000000000 -0500
14026 +.section .rodata,"a",@progbits
14027 ENTRY(sys_call_table)
14028 .long sys_restart_syscall /* 0 - old "setup()" system call, used for restarting */
14030 diff -urNp linux-2.6.37/arch/x86/kernel/sys_i386_32.c linux-2.6.37/arch/x86/kernel/sys_i386_32.c
14031 --- linux-2.6.37/arch/x86/kernel/sys_i386_32.c 2011-01-04 19:50:19.000000000 -0500
14032 +++ linux-2.6.37/arch/x86/kernel/sys_i386_32.c 2011-01-17 02:41:01.000000000 -0500
14033 @@ -24,17 +24,224 @@
14035 #include <asm/syscalls.h>
14038 - * Do a system call from kernel instead of calling sys_execve so we
14039 - * end up with proper pt_regs.
14041 -int kernel_execve(const char *filename,
14042 - const char *const argv[],
14043 - const char *const envp[])
14044 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
14047 - asm volatile ("int $0x80"
14049 - : "0" (__NR_execve), "b" (filename), "c" (argv), "d" (envp) : "memory");
14051 + unsigned long pax_task_size = TASK_SIZE;
14053 +#ifdef CONFIG_PAX_SEGMEXEC
14054 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
14055 + pax_task_size = SEGMEXEC_TASK_SIZE;
14058 + if (len > pax_task_size || addr > pax_task_size - len)
14065 +arch_get_unmapped_area(struct file *filp, unsigned long addr,
14066 + unsigned long len, unsigned long pgoff, unsigned long flags)
14068 + struct mm_struct *mm = current->mm;
14069 + struct vm_area_struct *vma;
14070 + unsigned long start_addr, pax_task_size = TASK_SIZE;
14072 +#ifdef CONFIG_PAX_SEGMEXEC
14073 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
14074 + pax_task_size = SEGMEXEC_TASK_SIZE;
14077 + pax_task_size -= PAGE_SIZE;
14079 + if (len > pax_task_size)
14082 + if (flags & MAP_FIXED)
14085 +#ifdef CONFIG_PAX_RANDMMAP
14086 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
14090 + addr = PAGE_ALIGN(addr);
14091 + if (pax_task_size - len >= addr) {
14092 + vma = find_vma(mm, addr);
14093 + if (check_heap_stack_gap(vma, addr, len))
14097 + if (len > mm->cached_hole_size) {
14098 + start_addr = addr = mm->free_area_cache;
14100 + start_addr = addr = mm->mmap_base;
14101 + mm->cached_hole_size = 0;
14104 +#ifdef CONFIG_PAX_PAGEEXEC
14105 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE) && start_addr >= mm->mmap_base) {
14106 + start_addr = 0x00110000UL;
14108 +#ifdef CONFIG_PAX_RANDMMAP
14109 + if (mm->pax_flags & MF_PAX_RANDMMAP)
14110 + start_addr += mm->delta_mmap & 0x03FFF000UL;
14113 + if (mm->start_brk <= start_addr && start_addr < mm->mmap_base)
14114 + start_addr = addr = mm->mmap_base;
14116 + addr = start_addr;
14121 + for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
14122 + /* At this point: (!vma || addr < vma->vm_end). */
14123 + if (pax_task_size - len < addr) {
14125 + * Start a new search - just in case we missed
14128 + if (start_addr != mm->mmap_base) {
14129 + start_addr = addr = mm->mmap_base;
14130 + mm->cached_hole_size = 0;
14131 + goto full_search;
14135 + if (check_heap_stack_gap(vma, addr, len))
14137 + if (addr + mm->cached_hole_size < vma->vm_start)
14138 + mm->cached_hole_size = vma->vm_start - addr;
14139 + addr = vma->vm_end;
14140 + if (mm->start_brk <= addr && addr < mm->mmap_base) {
14141 + start_addr = addr = mm->mmap_base;
14142 + mm->cached_hole_size = 0;
14143 + goto full_search;
14148 + * Remember the place where we stopped the search:
14150 + mm->free_area_cache = addr + len;
14155 +arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
14156 + const unsigned long len, const unsigned long pgoff,
14157 + const unsigned long flags)
14159 + struct vm_area_struct *vma;
14160 + struct mm_struct *mm = current->mm;
14161 + unsigned long base = mm->mmap_base, addr = addr0, pax_task_size = TASK_SIZE;
14163 +#ifdef CONFIG_PAX_SEGMEXEC
14164 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
14165 + pax_task_size = SEGMEXEC_TASK_SIZE;
14168 + pax_task_size -= PAGE_SIZE;
14170 + /* requested length too big for entire address space */
14171 + if (len > pax_task_size)
14174 + if (flags & MAP_FIXED)
14177 +#ifdef CONFIG_PAX_PAGEEXEC
14178 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
14182 +#ifdef CONFIG_PAX_RANDMMAP
14183 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
14186 + /* requesting a specific address */
14188 + addr = PAGE_ALIGN(addr);
14189 + if (pax_task_size - len >= addr) {
14190 + vma = find_vma(mm, addr);
14191 + if (check_heap_stack_gap(vma, addr, len))
14196 + /* check if free_area_cache is useful for us */
14197 + if (len <= mm->cached_hole_size) {
14198 + mm->cached_hole_size = 0;
14199 + mm->free_area_cache = mm->mmap_base;
14202 + /* either no address requested or can't fit in requested address hole */
14203 + addr = mm->free_area_cache;
14205 + /* make sure it can fit in the remaining address space */
14206 + if (addr > len) {
14207 + vma = find_vma(mm, addr-len);
14208 + if (check_heap_stack_gap(vma, addr - len, len))
14209 + /* remember the address as a hint for next time */
14210 + return (mm->free_area_cache = addr-len);
14213 + if (mm->mmap_base < len)
14216 + addr = mm->mmap_base-len;
14220 + * Lookup failure means no vma is above this address,
14221 + * else if new region fits below vma->vm_start,
14222 + * return with success:
14224 + vma = find_vma(mm, addr);
14225 + if (check_heap_stack_gap(vma, addr, len))
14226 + /* remember the address as a hint for next time */
14227 + return (mm->free_area_cache = addr);
14229 + /* remember the largest hole we saw so far */
14230 + if (addr + mm->cached_hole_size < vma->vm_start)
14231 + mm->cached_hole_size = vma->vm_start - addr;
14233 + /* try just below the current vma->vm_start */
14234 + addr = vma->vm_start-len;
14235 + } while (len < vma->vm_start);
14239 + * A failed mmap() very likely causes application failure,
14240 + * so fall back to the bottom-up function here. This scenario
14241 + * can happen with large stack limits and large mmap()
14245 +#ifdef CONFIG_PAX_SEGMEXEC
14246 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
14247 + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
14251 + mm->mmap_base = TASK_UNMAPPED_BASE;
14253 +#ifdef CONFIG_PAX_RANDMMAP
14254 + if (mm->pax_flags & MF_PAX_RANDMMAP)
14255 + mm->mmap_base += mm->delta_mmap;
14258 + mm->free_area_cache = mm->mmap_base;
14259 + mm->cached_hole_size = ~0UL;
14260 + addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
14262 + * Restore the topdown base:
14264 + mm->mmap_base = base;
14265 + mm->free_area_cache = base;
14266 + mm->cached_hole_size = ~0UL;
14270 diff -urNp linux-2.6.37/arch/x86/kernel/sys_x86_64.c linux-2.6.37/arch/x86/kernel/sys_x86_64.c
14271 --- linux-2.6.37/arch/x86/kernel/sys_x86_64.c 2011-01-04 19:50:19.000000000 -0500
14272 +++ linux-2.6.37/arch/x86/kernel/sys_x86_64.c 2011-01-17 02:41:01.000000000 -0500
14273 @@ -32,8 +32,8 @@ out:
14277 -static void find_start_end(unsigned long flags, unsigned long *begin,
14278 - unsigned long *end)
14279 +static void find_start_end(struct mm_struct *mm, unsigned long flags,
14280 + unsigned long *begin, unsigned long *end)
14282 if (!test_thread_flag(TIF_IA32) && (flags & MAP_32BIT)) {
14283 unsigned long new_begin;
14284 @@ -52,7 +52,7 @@ static void find_start_end(unsigned long
14285 *begin = new_begin;
14288 - *begin = TASK_UNMAPPED_BASE;
14289 + *begin = mm->mmap_base;
14293 @@ -69,16 +69,19 @@ arch_get_unmapped_area(struct file *filp
14294 if (flags & MAP_FIXED)
14297 - find_start_end(flags, &begin, &end);
14298 + find_start_end(mm, flags, &begin, &end);
14303 +#ifdef CONFIG_PAX_RANDMMAP
14304 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
14308 addr = PAGE_ALIGN(addr);
14309 vma = find_vma(mm, addr);
14310 - if (end - len >= addr &&
14311 - (!vma || addr + len <= vma->vm_start))
14312 + if (end - len >= addr && check_heap_stack_gap(vma, addr, len))
14315 if (((flags & MAP_32BIT) || test_thread_flag(TIF_IA32))
14316 @@ -106,7 +109,7 @@ full_search:
14320 - if (!vma || addr + len <= vma->vm_start) {
14321 + if (check_heap_stack_gap(vma, addr, len)) {
14323 * Remember the place where we stopped the search:
14325 @@ -128,7 +131,7 @@ arch_get_unmapped_area_topdown(struct fi
14327 struct vm_area_struct *vma;
14328 struct mm_struct *mm = current->mm;
14329 - unsigned long addr = addr0;
14330 + unsigned long base = mm->mmap_base, addr = addr0;
14332 /* requested length too big for entire address space */
14333 if (len > TASK_SIZE)
14334 @@ -141,12 +144,15 @@ arch_get_unmapped_area_topdown(struct fi
14335 if (!test_thread_flag(TIF_IA32) && (flags & MAP_32BIT))
14338 +#ifdef CONFIG_PAX_RANDMMAP
14339 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
14342 /* requesting a specific address */
14344 addr = PAGE_ALIGN(addr);
14345 vma = find_vma(mm, addr);
14346 - if (TASK_SIZE - len >= addr &&
14347 - (!vma || addr + len <= vma->vm_start))
14348 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
14352 @@ -162,7 +168,7 @@ arch_get_unmapped_area_topdown(struct fi
14353 /* make sure it can fit in the remaining address space */
14355 vma = find_vma(mm, addr-len);
14356 - if (!vma || addr <= vma->vm_start)
14357 + if (check_heap_stack_gap(vma, addr - len, len))
14358 /* remember the address as a hint for next time */
14359 return mm->free_area_cache = addr-len;
14361 @@ -179,7 +185,7 @@ arch_get_unmapped_area_topdown(struct fi
14362 * return with success:
14364 vma = find_vma(mm, addr);
14365 - if (!vma || addr+len <= vma->vm_start)
14366 + if (check_heap_stack_gap(vma, addr, len))
14367 /* remember the address as a hint for next time */
14368 return mm->free_area_cache = addr;
14370 @@ -198,13 +204,21 @@ bottomup:
14371 * can happen with large stack limits and large mmap()
14374 + mm->mmap_base = TASK_UNMAPPED_BASE;
14376 +#ifdef CONFIG_PAX_RANDMMAP
14377 + if (mm->pax_flags & MF_PAX_RANDMMAP)
14378 + mm->mmap_base += mm->delta_mmap;
14381 + mm->free_area_cache = mm->mmap_base;
14382 mm->cached_hole_size = ~0UL;
14383 - mm->free_area_cache = TASK_UNMAPPED_BASE;
14384 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
14386 * Restore the topdown base:
14388 - mm->free_area_cache = mm->mmap_base;
14389 + mm->mmap_base = base;
14390 + mm->free_area_cache = base;
14391 mm->cached_hole_size = ~0UL;
14394 diff -urNp linux-2.6.37/arch/x86/kernel/time.c linux-2.6.37/arch/x86/kernel/time.c
14395 --- linux-2.6.37/arch/x86/kernel/time.c 2011-01-04 19:50:19.000000000 -0500
14396 +++ linux-2.6.37/arch/x86/kernel/time.c 2011-01-17 02:41:01.000000000 -0500
14397 @@ -26,17 +26,13 @@
14401 -#ifdef CONFIG_X86_64
14402 -volatile unsigned long __jiffies __section_jiffies = INITIAL_JIFFIES;
14405 unsigned long profile_pc(struct pt_regs *regs)
14407 unsigned long pc = instruction_pointer(regs);
14409 - if (!user_mode_vm(regs) && in_lock_functions(pc)) {
14410 + if (!user_mode(regs) && in_lock_functions(pc)) {
14411 #ifdef CONFIG_FRAME_POINTER
14412 - return *(unsigned long *)(regs->bp + sizeof(long));
14413 + return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
14415 unsigned long *sp =
14416 (unsigned long *)kernel_stack_pointer(regs);
14417 @@ -45,11 +41,17 @@ unsigned long profile_pc(struct pt_regs
14418 * or above a saved flags. Eflags has bits 22-31 zero,
14419 * kernel addresses don't.
14422 +#ifdef CONFIG_PAX_KERNEXEC
14423 + return ktla_ktva(sp[0]);
14435 diff -urNp linux-2.6.37/arch/x86/kernel/tls.c linux-2.6.37/arch/x86/kernel/tls.c
14436 --- linux-2.6.37/arch/x86/kernel/tls.c 2011-01-04 19:50:19.000000000 -0500
14437 +++ linux-2.6.37/arch/x86/kernel/tls.c 2011-01-17 02:41:01.000000000 -0500
14438 @@ -85,6 +85,11 @@ int do_set_thread_area(struct task_struc
14439 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
14442 +#ifdef CONFIG_PAX_SEGMEXEC
14443 + if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
14447 set_tls_desc(p, idx, &info, 1);
14450 diff -urNp linux-2.6.37/arch/x86/kernel/trampoline_32.S linux-2.6.37/arch/x86/kernel/trampoline_32.S
14451 --- linux-2.6.37/arch/x86/kernel/trampoline_32.S 2011-01-04 19:50:19.000000000 -0500
14452 +++ linux-2.6.37/arch/x86/kernel/trampoline_32.S 2011-01-17 02:41:01.000000000 -0500
14454 #include <asm/segment.h>
14455 #include <asm/page_types.h>
14457 +#ifdef CONFIG_PAX_KERNEXEC
14460 +#define ta(X) ((X) - __PAGE_OFFSET)
14463 /* We can free up trampoline after bootup if cpu hotplug is not supported. */
14466 @@ -60,7 +66,7 @@ r_base = .
14467 inc %ax # protected mode (PE) bit
14468 lmsw %ax # into protected mode
14469 # flush prefetch and jump to startup_32_smp in arch/i386/kernel/head.S
14470 - ljmpl $__BOOT_CS, $(startup_32_smp-__PAGE_OFFSET)
14471 + ljmpl $__BOOT_CS, $ta(startup_32_smp)
14473 # These need to be in the same 64K segment as the above;
14474 # hence we don't use the boot_gdt_descr defined in head.S
14475 diff -urNp linux-2.6.37/arch/x86/kernel/trampoline_64.S linux-2.6.37/arch/x86/kernel/trampoline_64.S
14476 --- linux-2.6.37/arch/x86/kernel/trampoline_64.S 2011-01-04 19:50:19.000000000 -0500
14477 +++ linux-2.6.37/arch/x86/kernel/trampoline_64.S 2011-01-17 02:41:01.000000000 -0500
14478 @@ -91,7 +91,7 @@ startup_32:
14479 movl $__KERNEL_DS, %eax # Initialize the %ds segment register
14482 - movl $X86_CR4_PAE, %eax
14483 + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
14484 movl %eax, %cr4 # Enable PAE mode
14486 # Setup trampoline 4 level pagetables
14487 @@ -138,7 +138,7 @@ tidt:
14488 # so the kernel can live anywhere
14491 - .short tgdt_end - tgdt # gdt limit
14492 + .short tgdt_end - tgdt - 1 # gdt limit
14493 .long tgdt - r_base
14495 .quad 0x00cf9b000000ffff # __KERNEL32_CS
14496 diff -urNp linux-2.6.37/arch/x86/kernel/traps.c linux-2.6.37/arch/x86/kernel/traps.c
14497 --- linux-2.6.37/arch/x86/kernel/traps.c 2011-01-04 19:50:19.000000000 -0500
14498 +++ linux-2.6.37/arch/x86/kernel/traps.c 2011-01-17 02:41:01.000000000 -0500
14499 @@ -70,12 +70,6 @@ asmlinkage int system_call(void);
14501 /* Do we ignore FPU interrupts ? */
14502 char ignore_fpu_irq;
14505 - * The IDT has to be page-aligned to simplify the Pentium
14506 - * F0 0F bug workaround.
14508 -gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
14511 DECLARE_BITMAP(used_vectors, NR_VECTORS);
14512 @@ -110,13 +104,13 @@ static inline void preempt_conditional_c
14515 static void __kprobes
14516 -do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
14517 +do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
14518 long error_code, siginfo_t *info)
14520 struct task_struct *tsk = current;
14522 #ifdef CONFIG_X86_32
14523 - if (regs->flags & X86_VM_MASK) {
14524 + if (v8086_mode(regs)) {
14526 * traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
14527 * On nmi (interrupt 2), do_trap should not be called.
14528 @@ -127,7 +121,7 @@ do_trap(int trapnr, int signr, char *str
14532 - if (!user_mode(regs))
14533 + if (!user_mode_novm(regs))
14536 #ifdef CONFIG_X86_32
14537 @@ -150,7 +144,7 @@ trap_signal:
14538 printk_ratelimit()) {
14540 "%s[%d] trap %s ip:%lx sp:%lx error:%lx",
14541 - tsk->comm, tsk->pid, str,
14542 + tsk->comm, task_pid_nr(tsk), str,
14543 regs->ip, regs->sp, error_code);
14544 print_vma_addr(" in ", regs->ip);
14546 @@ -167,8 +161,20 @@ kernel_trap:
14547 if (!fixup_exception(regs)) {
14548 tsk->thread.error_code = error_code;
14549 tsk->thread.trap_no = trapnr;
14551 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
14552 + if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
14553 + str = "PAX: suspicious stack segment fault";
14556 die(str, regs, error_code);
14559 +#ifdef CONFIG_PAX_REFCOUNT
14561 + pax_report_refcount_overflow(regs);
14566 #ifdef CONFIG_X86_32
14567 @@ -257,14 +263,30 @@ do_general_protection(struct pt_regs *re
14568 conditional_sti(regs);
14570 #ifdef CONFIG_X86_32
14571 - if (regs->flags & X86_VM_MASK)
14572 + if (v8086_mode(regs))
14577 - if (!user_mode(regs))
14578 + if (!user_mode_novm(regs))
14581 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
14582 + if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
14583 + struct mm_struct *mm = tsk->mm;
14584 + unsigned long limit;
14586 + down_write(&mm->mmap_sem);
14587 + limit = mm->context.user_cs_limit;
14588 + if (limit < TASK_SIZE) {
14589 + track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
14590 + up_write(&mm->mmap_sem);
14593 + up_write(&mm->mmap_sem);
14597 tsk->thread.error_code = error_code;
14598 tsk->thread.trap_no = 13;
14600 @@ -297,6 +319,13 @@ gp_in_kernel:
14601 if (notify_die(DIE_GPF, "general protection fault", regs,
14602 error_code, 13, SIGSEGV) == NOTIFY_STOP)
14605 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
14606 + if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
14607 + die("PAX: suspicious general protection fault", regs, error_code);
14611 die("general protection fault", regs, error_code);
14614 @@ -572,7 +601,7 @@ dotraplinkage void __kprobes do_debug(st
14615 /* It's safe to allow irq's after DR6 has been saved */
14616 preempt_conditional_sti(regs);
14618 - if (regs->flags & X86_VM_MASK) {
14619 + if (v8086_mode(regs)) {
14620 handle_vm86_trap((struct kernel_vm86_regs *) regs,
14622 preempt_conditional_cli(regs);
14623 @@ -586,7 +615,7 @@ dotraplinkage void __kprobes do_debug(st
14624 * We already checked v86 mode above, so we can check for kernel mode
14625 * by just checking the CPL of CS.
14627 - if ((dr6 & DR_STEP) && !user_mode(regs)) {
14628 + if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
14629 tsk->thread.debugreg6 &= ~DR_STEP;
14630 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
14631 regs->flags &= ~X86_EFLAGS_TF;
14632 @@ -615,7 +644,7 @@ void math_error(struct pt_regs *regs, in
14634 conditional_sti(regs);
14636 - if (!user_mode_vm(regs))
14637 + if (!user_mode(regs))
14639 if (!fixup_exception(regs)) {
14640 task->thread.error_code = error_code;
14641 diff -urNp linux-2.6.37/arch/x86/kernel/tsc.c linux-2.6.37/arch/x86/kernel/tsc.c
14642 --- linux-2.6.37/arch/x86/kernel/tsc.c 2011-01-04 19:50:19.000000000 -0500
14643 +++ linux-2.6.37/arch/x86/kernel/tsc.c 2011-01-17 02:41:01.000000000 -0500
14644 @@ -837,7 +837,7 @@ static struct dmi_system_id __initdata b
14645 DMI_MATCH(DMI_BOARD_NAME, "2635FA0"),
14649 + { NULL, NULL, {{0, {0}}}, NULL}
14652 static void __init check_system_tsc_reliable(void)
14653 diff -urNp linux-2.6.37/arch/x86/kernel/vm86_32.c linux-2.6.37/arch/x86/kernel/vm86_32.c
14654 --- linux-2.6.37/arch/x86/kernel/vm86_32.c 2011-01-04 19:50:19.000000000 -0500
14655 +++ linux-2.6.37/arch/x86/kernel/vm86_32.c 2011-01-17 02:41:01.000000000 -0500
14657 #include <linux/ptrace.h>
14658 #include <linux/audit.h>
14659 #include <linux/stddef.h>
14660 +#include <linux/grsecurity.h>
14662 #include <asm/uaccess.h>
14663 #include <asm/io.h>
14664 @@ -148,7 +149,7 @@ struct pt_regs *save_v86_state(struct ke
14668 - tss = &per_cpu(init_tss, get_cpu());
14669 + tss = init_tss + get_cpu();
14670 current->thread.sp0 = current->thread.saved_sp0;
14671 current->thread.sysenter_cs = __KERNEL_CS;
14672 load_sp0(tss, ¤t->thread);
14673 @@ -207,6 +208,13 @@ int sys_vm86old(struct vm86_struct __use
14674 struct task_struct *tsk;
14675 int tmp, ret = -EPERM;
14677 +#ifdef CONFIG_GRKERNSEC_VM86
14678 + if (!capable(CAP_SYS_RAWIO)) {
14679 + gr_handle_vm86();
14685 if (tsk->thread.saved_sp0)
14687 @@ -237,6 +245,14 @@ int sys_vm86(unsigned long cmd, unsigned
14689 struct vm86plus_struct __user *v86;
14691 +#ifdef CONFIG_GRKERNSEC_VM86
14692 + if (!capable(CAP_SYS_RAWIO)) {
14693 + gr_handle_vm86();
14701 case VM86_REQUEST_IRQ:
14702 @@ -323,7 +339,7 @@ static void do_sys_vm86(struct kernel_vm
14703 tsk->thread.saved_fs = info->regs32->fs;
14704 tsk->thread.saved_gs = get_user_gs(info->regs32);
14706 - tss = &per_cpu(init_tss, get_cpu());
14707 + tss = init_tss + get_cpu();
14708 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
14710 tsk->thread.sysenter_cs = 0;
14711 @@ -528,7 +544,7 @@ static void do_int(struct kernel_vm86_re
14712 goto cannot_handle;
14713 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
14714 goto cannot_handle;
14715 - intr_ptr = (unsigned long __user *) (i << 2);
14716 + intr_ptr = (__force unsigned long __user *) (i << 2);
14717 if (get_user(segoffs, intr_ptr))
14718 goto cannot_handle;
14719 if ((segoffs >> 16) == BIOSSEG)
14720 diff -urNp linux-2.6.37/arch/x86/kernel/vmlinux.lds.S linux-2.6.37/arch/x86/kernel/vmlinux.lds.S
14721 --- linux-2.6.37/arch/x86/kernel/vmlinux.lds.S 2011-01-04 19:50:19.000000000 -0500
14722 +++ linux-2.6.37/arch/x86/kernel/vmlinux.lds.S 2011-01-17 02:41:01.000000000 -0500
14724 #include <asm/page_types.h>
14725 #include <asm/cache.h>
14726 #include <asm/boot.h>
14727 +#include <asm/segment.h>
14729 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
14730 +#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
14732 +#define __KERNEL_TEXT_OFFSET 0
14735 #undef i386 /* in case the preprocessor is a 32bit one */
14737 @@ -34,11 +41,9 @@ OUTPUT_FORMAT(CONFIG_OUTPUT_FORMAT, CONF
14738 #ifdef CONFIG_X86_32
14740 ENTRY(phys_startup_32)
14741 -jiffies = jiffies_64;
14743 OUTPUT_ARCH(i386:x86-64)
14744 ENTRY(phys_startup_64)
14745 -jiffies_64 = jiffies;
14748 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
14749 @@ -69,31 +74,46 @@ jiffies_64 = jiffies;
14752 text PT_LOAD FLAGS(5); /* R_E */
14753 - data PT_LOAD FLAGS(7); /* RWE */
14754 +#ifdef CONFIG_X86_32
14755 + module PT_LOAD FLAGS(5); /* R_E */
14758 + rodata PT_LOAD FLAGS(5); /* R_E */
14760 + rodata PT_LOAD FLAGS(4); /* R__ */
14762 + data PT_LOAD FLAGS(6); /* RW_ */
14763 #ifdef CONFIG_X86_64
14764 user PT_LOAD FLAGS(5); /* R_E */
14766 + init.begin PT_LOAD FLAGS(6); /* RW_ */
14768 percpu PT_LOAD FLAGS(6); /* RW_ */
14770 + text.init PT_LOAD FLAGS(5); /* R_E */
14771 + text.exit PT_LOAD FLAGS(5); /* R_E */
14772 init PT_LOAD FLAGS(7); /* RWE */
14774 note PT_NOTE FLAGS(0); /* ___ */
14779 #ifdef CONFIG_X86_32
14780 - . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
14781 - phys_startup_32 = startup_32 - LOAD_OFFSET;
14782 + . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
14784 - . = __START_KERNEL;
14785 - phys_startup_64 = startup_64 - LOAD_OFFSET;
14786 + . = __START_KERNEL;
14789 /* Text and read-only data */
14790 - .text : AT(ADDR(.text) - LOAD_OFFSET) {
14792 + .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
14793 /* bootstrapping code */
14794 +#ifdef CONFIG_X86_32
14795 + phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
14797 + phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
14799 + __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
14802 #ifdef CONFIG_X86_32
14803 . = ALIGN(PAGE_SIZE);
14804 @@ -108,13 +128,47 @@ SECTIONS
14808 - /* End of text section */
14812 - NOTES :text :note
14813 + . += __KERNEL_TEXT_OFFSET;
14815 +#ifdef CONFIG_X86_32
14816 + . = ALIGN(PAGE_SIZE);
14817 + .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
14819 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_MODULES)
14820 + MODULES_EXEC_VADDR = .;
14822 + . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
14823 + . = ALIGN(HPAGE_SIZE);
14824 + MODULES_EXEC_END = . - 1;
14830 + .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
14831 + /* End of text section */
14832 + _etext = . - __KERNEL_TEXT_OFFSET;
14835 - EXCEPTION_TABLE(16) :text = 0x9090
14836 +#ifdef CONFIG_X86_32
14837 + . = ALIGN(PAGE_SIZE);
14838 + .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
14840 + . = ALIGN(PAGE_SIZE);
14841 + *(.empty_zero_page)
14842 + *(.initial_pg_fixmap)
14843 + *(.initial_pg_pmd)
14844 + *(.initial_page_table)
14845 + *(.swapper_pg_dir)
14849 + . = ALIGN(PAGE_SIZE);
14850 + NOTES :rodata :note
14852 + EXCEPTION_TABLE(16) :rodata
14854 X64_ALIGN_DEBUG_RODATA_BEGIN
14856 @@ -122,16 +176,20 @@ SECTIONS
14859 .data : AT(ADDR(.data) - LOAD_OFFSET) {
14861 +#ifdef CONFIG_PAX_KERNEXEC
14862 + . = ALIGN(HPAGE_SIZE);
14864 + . = ALIGN(PAGE_SIZE);
14867 /* Start of data section */
14871 INIT_TASK_DATA(THREAD_SIZE)
14873 -#ifdef CONFIG_X86_32
14874 - /* 32 bit has nosave before _edata */
14878 PAGE_ALIGNED_DATA(PAGE_SIZE)
14880 @@ -140,6 +198,8 @@ SECTIONS
14884 + jiffies = jiffies_64;
14886 /* rarely changed data like cpu maps */
14887 READ_MOSTLY_DATA(INTERNODE_CACHE_BYTES)
14889 @@ -194,12 +254,6 @@ SECTIONS
14891 vgetcpu_mode = VVIRT(.vgetcpu_mode);
14893 - . = ALIGN(L1_CACHE_BYTES);
14894 - .jiffies : AT(VLOAD(.jiffies)) {
14897 - jiffies = VVIRT(.jiffies);
14899 .vsyscall_3 ADDR(.vsyscall_0) + 3072: AT(VLOAD(.vsyscall_3)) {
14902 @@ -215,12 +269,19 @@ SECTIONS
14903 #endif /* CONFIG_X86_64 */
14905 /* Init code and data - will be freed after init */
14906 - . = ALIGN(PAGE_SIZE);
14907 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
14910 +#ifdef CONFIG_PAX_KERNEXEC
14911 + . = ALIGN(HPAGE_SIZE);
14913 + . = ALIGN(PAGE_SIZE);
14916 __init_begin = .; /* paired with __init_end */
14920 -#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
14923 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
14924 * output PHDR, so the next output section - .init.text - should
14925 @@ -229,12 +290,27 @@ SECTIONS
14926 PERCPU_VADDR(0, :percpu)
14929 - INIT_TEXT_SECTION(PAGE_SIZE)
14930 -#ifdef CONFIG_X86_64
14933 + . = ALIGN(PAGE_SIZE);
14935 + .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
14936 + VMLINUX_SYMBOL(_sinittext) = .;
14938 + VMLINUX_SYMBOL(_einittext) = .;
14939 + . = ALIGN(PAGE_SIZE);
14942 - INIT_DATA_SECTION(16)
14944 + * .exit.text is discard at runtime, not link time, to deal with
14945 + * references from .altinstructions and .eh_frame
14947 + .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
14951 + . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
14953 + . = ALIGN(PAGE_SIZE);
14954 + INIT_DATA_SECTION(16) :init
14956 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
14957 __x86_cpu_dev_start = .;
14958 @@ -288,19 +364,12 @@ SECTIONS
14959 __iommu_table_end = .;
14963 - * .exit.text is discard at runtime, not link time, to deal with
14964 - * references from .altinstructions and .eh_frame
14966 - .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
14970 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
14974 -#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
14975 +#ifndef CONFIG_SMP
14976 PERCPU(THREAD_SIZE)
14979 @@ -319,16 +388,10 @@ SECTIONS
14980 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
14983 - . = ALIGN(PAGE_SIZE);
14984 __smp_locks_end = .;
14985 + . = ALIGN(PAGE_SIZE);
14988 -#ifdef CONFIG_X86_64
14989 - .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
14995 . = ALIGN(PAGE_SIZE);
14996 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
14997 @@ -344,6 +407,7 @@ SECTIONS
14999 . += 64 * 1024; /* 64k alignment slop space */
15000 *(.brk_reservation) /* areas brk users have reserved */
15001 + . = ALIGN(HPAGE_SIZE);
15005 @@ -370,13 +434,12 @@ SECTIONS
15006 * for the boot processor.
15008 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
15009 -INIT_PER_CPU(gdt_page);
15010 INIT_PER_CPU(irq_stack_union);
15013 * Build-time check on the image size:
15015 -. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
15016 +. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
15017 "kernel image bigger than KERNEL_IMAGE_SIZE");
15020 diff -urNp linux-2.6.37/arch/x86/kernel/vsyscall_64.c linux-2.6.37/arch/x86/kernel/vsyscall_64.c
15021 --- linux-2.6.37/arch/x86/kernel/vsyscall_64.c 2011-01-04 19:50:19.000000000 -0500
15022 +++ linux-2.6.37/arch/x86/kernel/vsyscall_64.c 2011-01-17 02:41:01.000000000 -0500
15023 @@ -80,6 +80,7 @@ void update_vsyscall(struct timespec *wa
15025 write_seqlock_irqsave(&vsyscall_gtod_data.lock, flags);
15026 /* copy vsyscall data */
15027 + strlcpy(vsyscall_gtod_data.clock.name, clock->name, sizeof vsyscall_gtod_data.clock.name);
15028 vsyscall_gtod_data.clock.vread = clock->vread;
15029 vsyscall_gtod_data.clock.cycle_last = clock->cycle_last;
15030 vsyscall_gtod_data.clock.mask = clock->mask;
15031 @@ -208,7 +209,7 @@ vgetcpu(unsigned *cpu, unsigned *node, s
15032 We do this here because otherwise user space would do it on
15033 its own in a likely inferior way (no access to jiffies).
15034 If you don't like it pass NULL. */
15035 - if (tcache && tcache->blob[0] == (j = __jiffies)) {
15036 + if (tcache && tcache->blob[0] == (j = jiffies)) {
15037 p = tcache->blob[1];
15038 } else if (__vgetcpu_mode == VGETCPU_RDTSCP) {
15039 /* Load per CPU data from RDTSCP */
15040 diff -urNp linux-2.6.37/arch/x86/kernel/x8664_ksyms_64.c linux-2.6.37/arch/x86/kernel/x8664_ksyms_64.c
15041 --- linux-2.6.37/arch/x86/kernel/x8664_ksyms_64.c 2011-01-04 19:50:19.000000000 -0500
15042 +++ linux-2.6.37/arch/x86/kernel/x8664_ksyms_64.c 2011-01-17 02:41:01.000000000 -0500
15043 @@ -29,8 +29,6 @@ EXPORT_SYMBOL(__put_user_8);
15044 EXPORT_SYMBOL(copy_user_generic_string);
15045 EXPORT_SYMBOL(copy_user_generic_unrolled);
15046 EXPORT_SYMBOL(__copy_user_nocache);
15047 -EXPORT_SYMBOL(_copy_from_user);
15048 -EXPORT_SYMBOL(_copy_to_user);
15050 EXPORT_SYMBOL(copy_page);
15051 EXPORT_SYMBOL(clear_page);
15052 diff -urNp linux-2.6.37/arch/x86/kernel/xsave.c linux-2.6.37/arch/x86/kernel/xsave.c
15053 --- linux-2.6.37/arch/x86/kernel/xsave.c 2011-01-04 19:50:19.000000000 -0500
15054 +++ linux-2.6.37/arch/x86/kernel/xsave.c 2011-01-17 02:41:01.000000000 -0500
15055 @@ -130,7 +130,7 @@ int check_for_xstate(struct i387_fxsave_
15056 fx_sw_user->xstate_size > fx_sw_user->extended_size)
15059 - err = __get_user(magic2, (__u32 *) (((void *)fpstate) +
15060 + err = __get_user(magic2, (__u32 __user *) (((void __user *)fpstate) +
15061 fx_sw_user->extended_size -
15062 FP_XSTATE_MAGIC2_SIZE));
15064 @@ -267,7 +267,7 @@ fx_only:
15065 * the other extended state.
15067 xrstor_state(init_xstate_buf, pcntxt_mask & ~XSTATE_FPSSE);
15068 - return fxrstor_checking((__force struct i387_fxsave_struct *)buf);
15069 + return fxrstor_checking((struct i387_fxsave_struct __user *)buf);
15073 @@ -299,7 +299,7 @@ int restore_i387_xstate(void __user *buf
15075 err = restore_user_xstate(buf);
15077 - err = fxrstor_checking((__force struct i387_fxsave_struct *)
15078 + err = fxrstor_checking((struct i387_fxsave_struct __user *)
15080 if (unlikely(err)) {
15082 diff -urNp linux-2.6.37/arch/x86/kvm/emulate.c linux-2.6.37/arch/x86/kvm/emulate.c
15083 --- linux-2.6.37/arch/x86/kvm/emulate.c 2011-01-04 19:50:19.000000000 -0500
15084 +++ linux-2.6.37/arch/x86/kvm/emulate.c 2011-01-17 02:41:01.000000000 -0500
15086 #define Src2ImmByte (2<<29)
15087 #define Src2One (3<<29)
15088 #define Src2Imm (4<<29)
15089 -#define Src2Mask (7<<29)
15090 +#define Src2Mask (7U<<29)
15092 #define X2(x...) x, x
15093 #define X3(x...) X2(x), x
15094 @@ -197,6 +197,7 @@ struct group_dual {
15096 #define ____emulate_2op(_op, _src, _dst, _eflags, _x, _y, _suffix, _dsttype) \
15098 + unsigned long _tmp; \
15099 __asm__ __volatile__ ( \
15100 _PRE_EFLAGS("0", "4", "2") \
15101 _op _suffix " %"_x"3,%1; " \
15102 @@ -210,8 +211,6 @@ struct group_dual {
15103 /* Raw emulation: instruction has two explicit operands. */
15104 #define __emulate_2op_nobyte(_op,_src,_dst,_eflags,_wx,_wy,_lx,_ly,_qx,_qy) \
15106 - unsigned long _tmp; \
15108 switch ((_dst).bytes) { \
15110 ____emulate_2op(_op,_src,_dst,_eflags,_wx,_wy,"w",u16);\
15111 @@ -227,7 +226,6 @@ struct group_dual {
15113 #define __emulate_2op(_op,_src,_dst,_eflags,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy) \
15115 - unsigned long _tmp; \
15116 switch ((_dst).bytes) { \
15118 ____emulate_2op(_op,_src,_dst,_eflags,_bx,_by,"b",u8); \
15119 diff -urNp linux-2.6.37/arch/x86/kvm/lapic.c linux-2.6.37/arch/x86/kvm/lapic.c
15120 --- linux-2.6.37/arch/x86/kvm/lapic.c 2011-01-04 19:50:19.000000000 -0500
15121 +++ linux-2.6.37/arch/x86/kvm/lapic.c 2011-01-17 02:41:01.000000000 -0500
15123 #define APIC_BUS_CYCLE_NS 1
15125 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
15126 -#define apic_debug(fmt, arg...)
15127 +#define apic_debug(fmt, arg...) do {} while (0)
15129 #define APIC_LVT_NUM 6
15130 /* 14 is the version for Xeon and Pentium 8.4.8*/
15131 diff -urNp linux-2.6.37/arch/x86/kvm/svm.c linux-2.6.37/arch/x86/kvm/svm.c
15132 --- linux-2.6.37/arch/x86/kvm/svm.c 2011-01-04 19:50:19.000000000 -0500
15133 +++ linux-2.6.37/arch/x86/kvm/svm.c 2011-01-17 02:41:01.000000000 -0500
15134 @@ -3023,7 +3023,11 @@ static void reload_tss(struct kvm_vcpu *
15135 int cpu = raw_smp_processor_id();
15137 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
15139 + pax_open_kernel();
15140 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
15141 + pax_close_kernel();
15146 @@ -3600,7 +3604,7 @@ static void svm_fpu_deactivate(struct kv
15147 update_cr0_intercept(svm);
15150 -static struct kvm_x86_ops svm_x86_ops = {
15151 +static const struct kvm_x86_ops svm_x86_ops = {
15152 .cpu_has_kvm_support = has_svm,
15153 .disabled_by_bios = is_disabled,
15154 .hardware_setup = svm_hardware_setup,
15155 diff -urNp linux-2.6.37/arch/x86/kvm/vmx.c linux-2.6.37/arch/x86/kvm/vmx.c
15156 --- linux-2.6.37/arch/x86/kvm/vmx.c 2011-01-04 19:50:19.000000000 -0500
15157 +++ linux-2.6.37/arch/x86/kvm/vmx.c 2011-01-17 02:41:01.000000000 -0500
15158 @@ -705,7 +705,11 @@ static void reload_tss(void)
15159 struct desc_struct *descs;
15161 descs = (void *)gdt->address;
15163 + pax_open_kernel();
15164 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
15165 + pax_close_kernel();
15170 @@ -1589,8 +1593,11 @@ static __init int hardware_setup(void)
15171 if (!cpu_has_vmx_flexpriority())
15172 flexpriority_enabled = 0;
15174 - if (!cpu_has_vmx_tpr_shadow())
15175 - kvm_x86_ops->update_cr8_intercept = NULL;
15176 + if (!cpu_has_vmx_tpr_shadow()) {
15177 + pax_open_kernel();
15178 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
15179 + pax_close_kernel();
15182 if (enable_ept && !cpu_has_vmx_ept_2m_page())
15183 kvm_disable_largepages();
15184 @@ -2575,7 +2582,7 @@ static int vmx_vcpu_setup(struct vcpu_vm
15185 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
15187 asm("mov $.Lkvm_vmx_return, %0" : "=r"(kvm_vmx_return));
15188 - vmcs_writel(HOST_RIP, kvm_vmx_return); /* 22.2.5 */
15189 + vmcs_writel(HOST_RIP, ktla_ktva(kvm_vmx_return)); /* 22.2.5 */
15190 vmcs_write32(VM_EXIT_MSR_STORE_COUNT, 0);
15191 vmcs_write32(VM_EXIT_MSR_LOAD_COUNT, 0);
15192 vmcs_write64(VM_EXIT_MSR_LOAD_ADDR, __pa(vmx->msr_autoload.host));
15193 @@ -3959,6 +3966,12 @@ static void vmx_vcpu_run(struct kvm_vcpu
15194 "jmp .Lkvm_vmx_return \n\t"
15195 ".Llaunched: " __ex(ASM_VMX_VMRESUME) "\n\t"
15196 ".Lkvm_vmx_return: "
15198 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
15199 + "ljmp %[cs],$.Lkvm_vmx_return2\n\t"
15200 + ".Lkvm_vmx_return2: "
15203 /* Save guest registers, load host registers, keep flags */
15204 "xchg %0, (%%"R"sp) \n\t"
15205 "mov %%"R"ax, %c[rax](%0) \n\t"
15206 @@ -4005,6 +4018,11 @@ static void vmx_vcpu_run(struct kvm_vcpu
15207 [r15]"i"(offsetof(struct vcpu_vmx, vcpu.arch.regs[VCPU_REGS_R15])),
15209 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2))
15211 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
15212 + ,[cs]"i"(__KERNEL_CS)
15216 , R"ax", R"bx", R"di", R"si"
15217 #ifdef CONFIG_X86_64
15218 @@ -4018,7 +4036,7 @@ static void vmx_vcpu_run(struct kvm_vcpu
15220 vmx->idt_vectoring_info = vmcs_read32(IDT_VECTORING_INFO_FIELD);
15222 - asm("mov %0, %%ds; mov %0, %%es" : : "r"(__USER_DS));
15223 + asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r"(__KERNEL_DS));
15226 vmx->exit_reason = vmcs_read32(VM_EXIT_REASON);
15227 @@ -4253,7 +4271,7 @@ static void vmx_set_supported_cpuid(u32
15231 -static struct kvm_x86_ops vmx_x86_ops = {
15232 +static const struct kvm_x86_ops vmx_x86_ops = {
15233 .cpu_has_kvm_support = cpu_has_kvm_support,
15234 .disabled_by_bios = vmx_disabled_by_bios,
15235 .hardware_setup = hardware_setup,
15236 diff -urNp linux-2.6.37/arch/x86/kvm/x86.c linux-2.6.37/arch/x86/kvm/x86.c
15237 --- linux-2.6.37/arch/x86/kvm/x86.c 2011-01-04 19:50:19.000000000 -0500
15238 +++ linux-2.6.37/arch/x86/kvm/x86.c 2011-01-17 02:41:01.000000000 -0500
15239 @@ -92,7 +92,7 @@ static void update_cr8_intercept(struct
15240 static int kvm_dev_ioctl_get_supported_cpuid(struct kvm_cpuid2 *cpuid,
15241 struct kvm_cpuid_entry2 __user *entries);
15243 -struct kvm_x86_ops *kvm_x86_ops;
15244 +const struct kvm_x86_ops *kvm_x86_ops;
15245 EXPORT_SYMBOL_GPL(kvm_x86_ops);
15247 int ignore_msrs = 0;
15248 @@ -118,38 +118,38 @@ static struct kvm_shared_msrs_global __r
15249 static DEFINE_PER_CPU(struct kvm_shared_msrs, shared_msrs);
15251 struct kvm_stats_debugfs_item debugfs_entries[] = {
15252 - { "pf_fixed", VCPU_STAT(pf_fixed) },
15253 - { "pf_guest", VCPU_STAT(pf_guest) },
15254 - { "tlb_flush", VCPU_STAT(tlb_flush) },
15255 - { "invlpg", VCPU_STAT(invlpg) },
15256 - { "exits", VCPU_STAT(exits) },
15257 - { "io_exits", VCPU_STAT(io_exits) },
15258 - { "mmio_exits", VCPU_STAT(mmio_exits) },
15259 - { "signal_exits", VCPU_STAT(signal_exits) },
15260 - { "irq_window", VCPU_STAT(irq_window_exits) },
15261 - { "nmi_window", VCPU_STAT(nmi_window_exits) },
15262 - { "halt_exits", VCPU_STAT(halt_exits) },
15263 - { "halt_wakeup", VCPU_STAT(halt_wakeup) },
15264 - { "hypercalls", VCPU_STAT(hypercalls) },
15265 - { "request_irq", VCPU_STAT(request_irq_exits) },
15266 - { "irq_exits", VCPU_STAT(irq_exits) },
15267 - { "host_state_reload", VCPU_STAT(host_state_reload) },
15268 - { "efer_reload", VCPU_STAT(efer_reload) },
15269 - { "fpu_reload", VCPU_STAT(fpu_reload) },
15270 - { "insn_emulation", VCPU_STAT(insn_emulation) },
15271 - { "insn_emulation_fail", VCPU_STAT(insn_emulation_fail) },
15272 - { "irq_injections", VCPU_STAT(irq_injections) },
15273 - { "nmi_injections", VCPU_STAT(nmi_injections) },
15274 - { "mmu_shadow_zapped", VM_STAT(mmu_shadow_zapped) },
15275 - { "mmu_pte_write", VM_STAT(mmu_pte_write) },
15276 - { "mmu_pte_updated", VM_STAT(mmu_pte_updated) },
15277 - { "mmu_pde_zapped", VM_STAT(mmu_pde_zapped) },
15278 - { "mmu_flooded", VM_STAT(mmu_flooded) },
15279 - { "mmu_recycled", VM_STAT(mmu_recycled) },
15280 - { "mmu_cache_miss", VM_STAT(mmu_cache_miss) },
15281 - { "mmu_unsync", VM_STAT(mmu_unsync) },
15282 - { "remote_tlb_flush", VM_STAT(remote_tlb_flush) },
15283 - { "largepages", VM_STAT(lpages) },
15284 + { "pf_fixed", VCPU_STAT(pf_fixed), NULL },
15285 + { "pf_guest", VCPU_STAT(pf_guest), NULL },
15286 + { "tlb_flush", VCPU_STAT(tlb_flush), NULL },
15287 + { "invlpg", VCPU_STAT(invlpg), NULL },
15288 + { "exits", VCPU_STAT(exits), NULL },
15289 + { "io_exits", VCPU_STAT(io_exits), NULL },
15290 + { "mmio_exits", VCPU_STAT(mmio_exits), NULL },
15291 + { "signal_exits", VCPU_STAT(signal_exits), NULL },
15292 + { "irq_window", VCPU_STAT(irq_window_exits), NULL },
15293 + { "nmi_window", VCPU_STAT(nmi_window_exits), NULL },
15294 + { "halt_exits", VCPU_STAT(halt_exits), NULL },
15295 + { "halt_wakeup", VCPU_STAT(halt_wakeup), NULL },
15296 + { "hypercalls", VCPU_STAT(hypercalls), NULL },
15297 + { "request_irq", VCPU_STAT(request_irq_exits), NULL },
15298 + { "irq_exits", VCPU_STAT(irq_exits), NULL },
15299 + { "host_state_reload", VCPU_STAT(host_state_reload), NULL },
15300 + { "efer_reload", VCPU_STAT(efer_reload), NULL },
15301 + { "fpu_reload", VCPU_STAT(fpu_reload), NULL },
15302 + { "insn_emulation", VCPU_STAT(insn_emulation), NULL },
15303 + { "insn_emulation_fail", VCPU_STAT(insn_emulation_fail), NULL },
15304 + { "irq_injections", VCPU_STAT(irq_injections), NULL },
15305 + { "nmi_injections", VCPU_STAT(nmi_injections), NULL },
15306 + { "mmu_shadow_zapped", VM_STAT(mmu_shadow_zapped), NULL },
15307 + { "mmu_pte_write", VM_STAT(mmu_pte_write), NULL },
15308 + { "mmu_pte_updated", VM_STAT(mmu_pte_updated), NULL },
15309 + { "mmu_pde_zapped", VM_STAT(mmu_pde_zapped), NULL },
15310 + { "mmu_flooded", VM_STAT(mmu_flooded), NULL },
15311 + { "mmu_recycled", VM_STAT(mmu_recycled), NULL },
15312 + { "mmu_cache_miss", VM_STAT(mmu_cache_miss), NULL },
15313 + { "mmu_unsync", VM_STAT(mmu_unsync), NULL },
15314 + { "remote_tlb_flush", VM_STAT(remote_tlb_flush), NULL },
15315 + { "largepages", VM_STAT(lpages), NULL },
15319 @@ -1979,6 +1979,8 @@ long kvm_arch_dev_ioctl(struct file *fil
15320 if (n < msr_list.nmsrs)
15323 + if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
15325 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
15326 num_msrs_to_save * sizeof(u32)))
15328 @@ -2446,7 +2448,7 @@ static int kvm_vcpu_ioctl_set_lapic(stru
15329 static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
15330 struct kvm_interrupt *irq)
15332 - if (irq->irq < 0 || irq->irq >= 256)
15333 + if (irq->irq >= 256)
15335 if (irqchip_in_kernel(vcpu->kvm))
15337 @@ -4623,10 +4625,10 @@ void kvm_after_handle_nmi(struct kvm_vcp
15339 EXPORT_SYMBOL_GPL(kvm_after_handle_nmi);
15341 -int kvm_arch_init(void *opaque)
15342 +int kvm_arch_init(const void *opaque)
15345 - struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
15346 + const struct kvm_x86_ops *ops = (const struct kvm_x86_ops *)opaque;
15349 printk(KERN_ERR "kvm: already loaded the other module\n");
15350 diff -urNp linux-2.6.37/arch/x86/lib/atomic64_cx8_32.S linux-2.6.37/arch/x86/lib/atomic64_cx8_32.S
15351 --- linux-2.6.37/arch/x86/lib/atomic64_cx8_32.S 2011-01-04 19:50:19.000000000 -0500
15352 +++ linux-2.6.37/arch/x86/lib/atomic64_cx8_32.S 2011-01-17 02:41:01.000000000 -0500
15353 @@ -86,13 +86,23 @@ ENTRY(atomic64_\func\()_return_cx8)
15355 \ins\()l %esi, %ebx
15356 \insc\()l %edi, %ecx
15358 +#ifdef CONFIG_PAX_REFCOUNT
15361 + _ASM_EXTABLE(2b, 3f)
15372 +#ifdef CONFIG_PAX_REFCOUNT
15379 @@ -116,13 +126,24 @@ ENTRY(atomic64_\func\()_return_cx8)
15384 +#ifdef CONFIG_PAX_REFCOUNT
15387 + _ASM_EXTABLE(2b, 3f)
15398 +#ifdef CONFIG_PAX_REFCOUNT
15405 @@ -176,6 +197,13 @@ ENTRY(atomic64_add_unless_cx8)
15410 +#ifdef CONFIG_PAX_REFCOUNT
15413 + _ASM_EXTABLE(1234b, 1234b)
15419 @@ -208,6 +236,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
15424 +#ifdef CONFIG_PAX_REFCOUNT
15427 + _ASM_EXTABLE(1234b, 1234b)
15433 diff -urNp linux-2.6.37/arch/x86/lib/checksum_32.S linux-2.6.37/arch/x86/lib/checksum_32.S
15434 --- linux-2.6.37/arch/x86/lib/checksum_32.S 2011-01-04 19:50:19.000000000 -0500
15435 +++ linux-2.6.37/arch/x86/lib/checksum_32.S 2011-01-17 02:41:01.000000000 -0500
15437 #include <linux/linkage.h>
15438 #include <asm/dwarf2.h>
15439 #include <asm/errno.h>
15441 +#include <asm/segment.h>
15444 * computes a partial checksum, e.g. for TCP/UDP fragments
15446 @@ -304,9 +305,28 @@ unsigned int csum_partial_copy_generic (
15451 -ENTRY(csum_partial_copy_generic)
15453 +ENTRY(csum_partial_copy_generic_to_user)
15456 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15458 + CFI_ADJUST_CFA_OFFSET 4
15460 + CFI_ADJUST_CFA_OFFSET -4
15461 + jmp csum_partial_copy_generic
15464 +ENTRY(csum_partial_copy_generic_from_user)
15466 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15468 + CFI_ADJUST_CFA_OFFSET 4
15470 + CFI_ADJUST_CFA_OFFSET -4
15473 +ENTRY(csum_partial_copy_generic)
15475 CFI_ADJUST_CFA_OFFSET 4
15477 @@ -331,7 +351,7 @@ ENTRY(csum_partial_copy_generic)
15479 SRC(1: movw (%esi), %bx )
15481 -DST( movw %bx, (%edi) )
15482 +DST( movw %bx, %es:(%edi) )
15486 @@ -343,30 +363,30 @@ DST( movw %bx, (%edi) )
15487 SRC(1: movl (%esi), %ebx )
15488 SRC( movl 4(%esi), %edx )
15490 -DST( movl %ebx, (%edi) )
15491 +DST( movl %ebx, %es:(%edi) )
15493 -DST( movl %edx, 4(%edi) )
15494 +DST( movl %edx, %es:4(%edi) )
15496 SRC( movl 8(%esi), %ebx )
15497 SRC( movl 12(%esi), %edx )
15499 -DST( movl %ebx, 8(%edi) )
15500 +DST( movl %ebx, %es:8(%edi) )
15502 -DST( movl %edx, 12(%edi) )
15503 +DST( movl %edx, %es:12(%edi) )
15505 SRC( movl 16(%esi), %ebx )
15506 SRC( movl 20(%esi), %edx )
15508 -DST( movl %ebx, 16(%edi) )
15509 +DST( movl %ebx, %es:16(%edi) )
15511 -DST( movl %edx, 20(%edi) )
15512 +DST( movl %edx, %es:20(%edi) )
15514 SRC( movl 24(%esi), %ebx )
15515 SRC( movl 28(%esi), %edx )
15517 -DST( movl %ebx, 24(%edi) )
15518 +DST( movl %ebx, %es:24(%edi) )
15520 -DST( movl %edx, 28(%edi) )
15521 +DST( movl %edx, %es:28(%edi) )
15525 @@ -380,7 +400,7 @@ DST( movl %edx, 28(%edi) )
15526 shrl $2, %edx # This clears CF
15527 SRC(3: movl (%esi), %ebx )
15529 -DST( movl %ebx, (%edi) )
15530 +DST( movl %ebx, %es:(%edi) )
15534 @@ -392,12 +412,12 @@ DST( movl %ebx, (%edi) )
15536 SRC( movw (%esi), %cx )
15538 -DST( movw %cx, (%edi) )
15539 +DST( movw %cx, %es:(%edi) )
15543 SRC(5: movb (%esi), %cl )
15544 -DST( movb %cl, (%edi) )
15545 +DST( movb %cl, %es:(%edi) )
15549 @@ -408,7 +428,7 @@ DST( movb %cl, (%edi) )
15552 movl ARGBASE+20(%esp), %ebx # src_err_ptr
15553 - movl $-EFAULT, (%ebx)
15554 + movl $-EFAULT, %ss:(%ebx)
15556 # zero the complete destination - computing the rest
15558 @@ -421,11 +441,19 @@ DST( movb %cl, (%edi) )
15561 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
15562 - movl $-EFAULT,(%ebx)
15563 + movl $-EFAULT,%ss:(%ebx)
15569 + CFI_ADJUST_CFA_OFFSET 4
15571 + CFI_ADJUST_CFA_OFFSET -4
15573 + CFI_ADJUST_CFA_OFFSET 4
15575 + CFI_ADJUST_CFA_OFFSET -4
15577 CFI_ADJUST_CFA_OFFSET -4
15579 @@ -439,26 +467,47 @@ DST( movb %cl, (%edi) )
15580 CFI_ADJUST_CFA_OFFSET -4
15583 -ENDPROC(csum_partial_copy_generic)
15584 +ENDPROC(csum_partial_copy_generic_to_user)
15588 /* Version for PentiumII/PPro */
15590 #define ROUND1(x) \
15592 SRC(movl x(%esi), %ebx ) ; \
15593 addl %ebx, %eax ; \
15594 - DST(movl %ebx, x(%edi) ) ;
15595 + DST(movl %ebx, %es:x(%edi)) ;
15599 SRC(movl x(%esi), %ebx ) ; \
15600 adcl %ebx, %eax ; \
15601 - DST(movl %ebx, x(%edi) ) ;
15602 + DST(movl %ebx, %es:x(%edi)) ;
15606 -ENTRY(csum_partial_copy_generic)
15608 +ENTRY(csum_partial_copy_generic_to_user)
15611 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15613 + CFI_ADJUST_CFA_OFFSET 4
15615 + CFI_ADJUST_CFA_OFFSET -4
15616 + jmp csum_partial_copy_generic
15619 +ENTRY(csum_partial_copy_generic_from_user)
15621 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15623 + CFI_ADJUST_CFA_OFFSET 4
15625 + CFI_ADJUST_CFA_OFFSET -4
15628 +ENTRY(csum_partial_copy_generic)
15630 CFI_ADJUST_CFA_OFFSET 4
15631 CFI_REL_OFFSET ebx, 0
15632 @@ -482,7 +531,7 @@ ENTRY(csum_partial_copy_generic)
15636 - lea 3f(%ebx,%ebx), %ebx
15637 + lea 3f(%ebx,%ebx,2), %ebx
15641 @@ -503,19 +552,19 @@ ENTRY(csum_partial_copy_generic)
15643 SRC( movw (%esi), %dx )
15645 -DST( movw %dx, (%edi) )
15646 +DST( movw %dx, %es:(%edi) )
15651 SRC( movb (%esi), %dl )
15652 -DST( movb %dl, (%edi) )
15653 +DST( movb %dl, %es:(%edi) )
15657 .section .fixup, "ax"
15658 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
15659 - movl $-EFAULT, (%ebx)
15660 + movl $-EFAULT, %ss:(%ebx)
15661 # zero the complete destination (computing the rest is too much work)
15662 movl ARGBASE+8(%esp),%edi # dst
15663 movl ARGBASE+12(%esp),%ecx # len
15664 @@ -523,10 +572,21 @@ DST( movb %dl, (%edi) )
15667 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
15668 - movl $-EFAULT, (%ebx)
15669 + movl $-EFAULT, %ss:(%ebx)
15673 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15675 + CFI_ADJUST_CFA_OFFSET 4
15677 + CFI_ADJUST_CFA_OFFSET -4
15679 + CFI_ADJUST_CFA_OFFSET 4
15681 + CFI_ADJUST_CFA_OFFSET -4
15685 CFI_ADJUST_CFA_OFFSET -4
15687 @@ -538,7 +598,7 @@ DST( movb %dl, (%edi) )
15691 -ENDPROC(csum_partial_copy_generic)
15692 +ENDPROC(csum_partial_copy_generic_to_user)
15696 diff -urNp linux-2.6.37/arch/x86/lib/clear_page_64.S linux-2.6.37/arch/x86/lib/clear_page_64.S
15697 --- linux-2.6.37/arch/x86/lib/clear_page_64.S 2011-01-04 19:50:19.000000000 -0500
15698 +++ linux-2.6.37/arch/x86/lib/clear_page_64.S 2011-01-17 02:41:01.000000000 -0500
15699 @@ -43,7 +43,7 @@ ENDPROC(clear_page)
15701 #include <asm/cpufeature.h>
15703 - .section .altinstr_replacement,"ax"
15704 + .section .altinstr_replacement,"a"
15705 1: .byte 0xeb /* jmp <disp8> */
15706 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
15708 diff -urNp linux-2.6.37/arch/x86/lib/copy_page_64.S linux-2.6.37/arch/x86/lib/copy_page_64.S
15709 --- linux-2.6.37/arch/x86/lib/copy_page_64.S 2011-01-04 19:50:19.000000000 -0500
15710 +++ linux-2.6.37/arch/x86/lib/copy_page_64.S 2011-01-17 02:41:01.000000000 -0500
15711 @@ -104,7 +104,7 @@ ENDPROC(copy_page)
15713 #include <asm/cpufeature.h>
15715 - .section .altinstr_replacement,"ax"
15716 + .section .altinstr_replacement,"a"
15717 1: .byte 0xeb /* jmp <disp8> */
15718 .byte (copy_page_c - copy_page) - (2f - 1b) /* offset */
15720 diff -urNp linux-2.6.37/arch/x86/lib/copy_user_64.S linux-2.6.37/arch/x86/lib/copy_user_64.S
15721 --- linux-2.6.37/arch/x86/lib/copy_user_64.S 2011-01-04 19:50:19.000000000 -0500
15722 +++ linux-2.6.37/arch/x86/lib/copy_user_64.S 2011-01-17 02:41:01.000000000 -0500
15723 @@ -15,13 +15,14 @@
15724 #include <asm/asm-offsets.h>
15725 #include <asm/thread_info.h>
15726 #include <asm/cpufeature.h>
15727 +#include <asm/pgtable.h>
15729 .macro ALTERNATIVE_JUMP feature,orig,alt
15731 .byte 0xe9 /* 32bit jump */
15732 .long \orig-1f /* by default jump to orig */
15734 - .section .altinstr_replacement,"ax"
15735 + .section .altinstr_replacement,"a"
15736 2: .byte 0xe9 /* near jump with 32bit immediate */
15737 .long \alt-1b /* offset */ /* or alternatively to alt */
15739 @@ -64,37 +65,13 @@
15743 -/* Standard copy_to_user with segment limit checking */
15744 -ENTRY(_copy_to_user)
15746 - GET_THREAD_INFO(%rax)
15750 - cmpq TI_addr_limit(%rax),%rcx
15752 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,copy_user_generic_unrolled,copy_user_generic_string
15754 -ENDPROC(_copy_to_user)
15756 -/* Standard copy_from_user with segment limit checking */
15757 -ENTRY(_copy_from_user)
15759 - GET_THREAD_INFO(%rax)
15763 - cmpq TI_addr_limit(%rax),%rcx
15764 - jae bad_from_user
15765 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,copy_user_generic_unrolled,copy_user_generic_string
15767 -ENDPROC(_copy_from_user)
15769 .section .fixup,"ax"
15770 /* must zero dest */
15771 ENTRY(bad_from_user)
15779 diff -urNp linux-2.6.37/arch/x86/lib/copy_user_nocache_64.S linux-2.6.37/arch/x86/lib/copy_user_nocache_64.S
15780 --- linux-2.6.37/arch/x86/lib/copy_user_nocache_64.S 2011-01-04 19:50:19.000000000 -0500
15781 +++ linux-2.6.37/arch/x86/lib/copy_user_nocache_64.S 2011-01-17 02:41:01.000000000 -0500
15783 #include <asm/current.h>
15784 #include <asm/asm-offsets.h>
15785 #include <asm/thread_info.h>
15786 +#include <asm/pgtable.h>
15788 .macro ALIGN_DESTINATION
15789 #ifdef FIX_ALIGNMENT
15792 ENTRY(__copy_user_nocache)
15795 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15796 + mov $PAX_USER_SHADOW_BASE,%rcx
15804 jb 20f /* less then 8 bytes, go to byte copy loop */
15806 diff -urNp linux-2.6.37/arch/x86/lib/csum-wrappers_64.c linux-2.6.37/arch/x86/lib/csum-wrappers_64.c
15807 --- linux-2.6.37/arch/x86/lib/csum-wrappers_64.c 2011-01-04 19:50:19.000000000 -0500
15808 +++ linux-2.6.37/arch/x86/lib/csum-wrappers_64.c 2011-01-17 02:41:01.000000000 -0500
15809 @@ -52,6 +52,8 @@ csum_partial_copy_from_user(const void _
15813 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
15814 + src += PAX_USER_SHADOW_BASE;
15815 isum = csum_partial_copy_generic((__force const void *)src,
15816 dst, len, isum, errp, NULL);
15817 if (unlikely(*errp))
15818 @@ -105,6 +107,8 @@ csum_partial_copy_to_user(const void *sr
15822 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
15823 + dst += PAX_USER_SHADOW_BASE;
15824 return csum_partial_copy_generic(src, (void __force *)dst,
15825 len, isum, NULL, errp);
15827 diff -urNp linux-2.6.37/arch/x86/lib/getuser.S linux-2.6.37/arch/x86/lib/getuser.S
15828 --- linux-2.6.37/arch/x86/lib/getuser.S 2011-01-04 19:50:19.000000000 -0500
15829 +++ linux-2.6.37/arch/x86/lib/getuser.S 2011-01-17 02:41:01.000000000 -0500
15830 @@ -33,14 +33,35 @@
15831 #include <asm/asm-offsets.h>
15832 #include <asm/thread_info.h>
15833 #include <asm/asm.h>
15834 +#include <asm/segment.h>
15835 +#include <asm/pgtable.h>
15837 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
15838 +#define __copyuser_seg %gs:
15840 +#define __copyuser_seg
15844 ENTRY(__get_user_1)
15847 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
15848 GET_THREAD_INFO(%_ASM_DX)
15849 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
15851 -1: movzb (%_ASM_AX),%edx
15853 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15854 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
15855 + cmp %_ASM_DX,%_ASM_AX
15857 + add %_ASM_DX,%_ASM_AX
15863 +1: movzb __copyuser_seg (%_ASM_AX),%edx
15867 @@ -49,11 +70,24 @@ ENDPROC(__get_user_1)
15868 ENTRY(__get_user_2)
15872 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
15874 GET_THREAD_INFO(%_ASM_DX)
15875 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
15877 -2: movzwl -1(%_ASM_AX),%edx
15879 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15880 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
15881 + cmp %_ASM_DX,%_ASM_AX
15883 + add %_ASM_DX,%_ASM_AX
15889 +2: movzwl __copyuser_seg -1(%_ASM_AX),%edx
15893 @@ -62,11 +96,24 @@ ENDPROC(__get_user_2)
15894 ENTRY(__get_user_4)
15898 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
15900 GET_THREAD_INFO(%_ASM_DX)
15901 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
15903 -3: mov -3(%_ASM_AX),%edx
15905 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15906 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
15907 + cmp %_ASM_DX,%_ASM_AX
15909 + add %_ASM_DX,%_ASM_AX
15915 +3: mov __copyuser_seg -3(%_ASM_AX),%edx
15919 @@ -80,6 +127,15 @@ ENTRY(__get_user_8)
15920 GET_THREAD_INFO(%_ASM_DX)
15921 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
15924 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15925 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
15926 + cmp %_ASM_DX,%_ASM_AX
15928 + add %_ASM_DX,%_ASM_AX
15932 4: movq -7(%_ASM_AX),%_ASM_DX
15935 diff -urNp linux-2.6.37/arch/x86/lib/insn.c linux-2.6.37/arch/x86/lib/insn.c
15936 --- linux-2.6.37/arch/x86/lib/insn.c 2011-01-04 19:50:19.000000000 -0500
15937 +++ linux-2.6.37/arch/x86/lib/insn.c 2011-01-17 02:41:01.000000000 -0500
15939 #include <linux/string.h>
15940 #include <asm/inat.h>
15941 #include <asm/insn.h>
15942 +#include <asm/pgtable_types.h>
15944 #define get_next(t, insn) \
15945 ({t r; r = *(t*)insn->next_byte; insn->next_byte += sizeof(t); r; })
15947 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
15949 memset(insn, 0, sizeof(*insn));
15950 - insn->kaddr = kaddr;
15951 - insn->next_byte = kaddr;
15952 + insn->kaddr = ktla_ktva(kaddr);
15953 + insn->next_byte = ktla_ktva(kaddr);
15954 insn->x86_64 = x86_64 ? 1 : 0;
15955 insn->opnd_bytes = 4;
15957 diff -urNp linux-2.6.37/arch/x86/lib/mmx_32.c linux-2.6.37/arch/x86/lib/mmx_32.c
15958 --- linux-2.6.37/arch/x86/lib/mmx_32.c 2011-01-04 19:50:19.000000000 -0500
15959 +++ linux-2.6.37/arch/x86/lib/mmx_32.c 2011-01-17 02:41:01.000000000 -0500
15960 @@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *
15964 + unsigned long cr0;
15966 if (unlikely(in_interrupt()))
15967 return __memcpy(to, from, len);
15968 @@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *
15969 kernel_fpu_begin();
15971 __asm__ __volatile__ (
15972 - "1: prefetch (%0)\n" /* This set is 28 bytes */
15973 - " prefetch 64(%0)\n"
15974 - " prefetch 128(%0)\n"
15975 - " prefetch 192(%0)\n"
15976 - " prefetch 256(%0)\n"
15977 + "1: prefetch (%1)\n" /* This set is 28 bytes */
15978 + " prefetch 64(%1)\n"
15979 + " prefetch 128(%1)\n"
15980 + " prefetch 192(%1)\n"
15981 + " prefetch 256(%1)\n"
15983 ".section .fixup, \"ax\"\n"
15984 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
15987 +#ifdef CONFIG_PAX_KERNEXEC
15988 + " movl %%cr0, %0\n"
15989 + " movl %0, %%eax\n"
15990 + " andl $0xFFFEFFFF, %%eax\n"
15991 + " movl %%eax, %%cr0\n"
15994 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
15996 +#ifdef CONFIG_PAX_KERNEXEC
15997 + " movl %0, %%cr0\n"
16002 _ASM_EXTABLE(1b, 3b)
16004 + : "=&r" (cr0) : "r" (from) : "ax");
16006 for ( ; i > 5; i--) {
16007 __asm__ __volatile__ (
16008 - "1: prefetch 320(%0)\n"
16009 - "2: movq (%0), %%mm0\n"
16010 - " movq 8(%0), %%mm1\n"
16011 - " movq 16(%0), %%mm2\n"
16012 - " movq 24(%0), %%mm3\n"
16013 - " movq %%mm0, (%1)\n"
16014 - " movq %%mm1, 8(%1)\n"
16015 - " movq %%mm2, 16(%1)\n"
16016 - " movq %%mm3, 24(%1)\n"
16017 - " movq 32(%0), %%mm0\n"
16018 - " movq 40(%0), %%mm1\n"
16019 - " movq 48(%0), %%mm2\n"
16020 - " movq 56(%0), %%mm3\n"
16021 - " movq %%mm0, 32(%1)\n"
16022 - " movq %%mm1, 40(%1)\n"
16023 - " movq %%mm2, 48(%1)\n"
16024 - " movq %%mm3, 56(%1)\n"
16025 + "1: prefetch 320(%1)\n"
16026 + "2: movq (%1), %%mm0\n"
16027 + " movq 8(%1), %%mm1\n"
16028 + " movq 16(%1), %%mm2\n"
16029 + " movq 24(%1), %%mm3\n"
16030 + " movq %%mm0, (%2)\n"
16031 + " movq %%mm1, 8(%2)\n"
16032 + " movq %%mm2, 16(%2)\n"
16033 + " movq %%mm3, 24(%2)\n"
16034 + " movq 32(%1), %%mm0\n"
16035 + " movq 40(%1), %%mm1\n"
16036 + " movq 48(%1), %%mm2\n"
16037 + " movq 56(%1), %%mm3\n"
16038 + " movq %%mm0, 32(%2)\n"
16039 + " movq %%mm1, 40(%2)\n"
16040 + " movq %%mm2, 48(%2)\n"
16041 + " movq %%mm3, 56(%2)\n"
16042 ".section .fixup, \"ax\"\n"
16043 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
16046 +#ifdef CONFIG_PAX_KERNEXEC
16047 + " movl %%cr0, %0\n"
16048 + " movl %0, %%eax\n"
16049 + " andl $0xFFFEFFFF, %%eax\n"
16050 + " movl %%eax, %%cr0\n"
16053 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
16055 +#ifdef CONFIG_PAX_KERNEXEC
16056 + " movl %0, %%cr0\n"
16061 _ASM_EXTABLE(1b, 3b)
16062 - : : "r" (from), "r" (to) : "memory");
16063 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
16067 @@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
16068 static void fast_copy_page(void *to, void *from)
16071 + unsigned long cr0;
16073 kernel_fpu_begin();
16075 @@ -166,42 +196,70 @@ static void fast_copy_page(void *to, voi
16076 * but that is for later. -AV
16078 __asm__ __volatile__(
16079 - "1: prefetch (%0)\n"
16080 - " prefetch 64(%0)\n"
16081 - " prefetch 128(%0)\n"
16082 - " prefetch 192(%0)\n"
16083 - " prefetch 256(%0)\n"
16084 + "1: prefetch (%1)\n"
16085 + " prefetch 64(%1)\n"
16086 + " prefetch 128(%1)\n"
16087 + " prefetch 192(%1)\n"
16088 + " prefetch 256(%1)\n"
16090 ".section .fixup, \"ax\"\n"
16091 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
16094 +#ifdef CONFIG_PAX_KERNEXEC
16095 + " movl %%cr0, %0\n"
16096 + " movl %0, %%eax\n"
16097 + " andl $0xFFFEFFFF, %%eax\n"
16098 + " movl %%eax, %%cr0\n"
16101 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
16103 +#ifdef CONFIG_PAX_KERNEXEC
16104 + " movl %0, %%cr0\n"
16109 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
16110 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
16112 for (i = 0; i < (4096-320)/64; i++) {
16113 __asm__ __volatile__ (
16114 - "1: prefetch 320(%0)\n"
16115 - "2: movq (%0), %%mm0\n"
16116 - " movntq %%mm0, (%1)\n"
16117 - " movq 8(%0), %%mm1\n"
16118 - " movntq %%mm1, 8(%1)\n"
16119 - " movq 16(%0), %%mm2\n"
16120 - " movntq %%mm2, 16(%1)\n"
16121 - " movq 24(%0), %%mm3\n"
16122 - " movntq %%mm3, 24(%1)\n"
16123 - " movq 32(%0), %%mm4\n"
16124 - " movntq %%mm4, 32(%1)\n"
16125 - " movq 40(%0), %%mm5\n"
16126 - " movntq %%mm5, 40(%1)\n"
16127 - " movq 48(%0), %%mm6\n"
16128 - " movntq %%mm6, 48(%1)\n"
16129 - " movq 56(%0), %%mm7\n"
16130 - " movntq %%mm7, 56(%1)\n"
16131 + "1: prefetch 320(%1)\n"
16132 + "2: movq (%1), %%mm0\n"
16133 + " movntq %%mm0, (%2)\n"
16134 + " movq 8(%1), %%mm1\n"
16135 + " movntq %%mm1, 8(%2)\n"
16136 + " movq 16(%1), %%mm2\n"
16137 + " movntq %%mm2, 16(%2)\n"
16138 + " movq 24(%1), %%mm3\n"
16139 + " movntq %%mm3, 24(%2)\n"
16140 + " movq 32(%1), %%mm4\n"
16141 + " movntq %%mm4, 32(%2)\n"
16142 + " movq 40(%1), %%mm5\n"
16143 + " movntq %%mm5, 40(%2)\n"
16144 + " movq 48(%1), %%mm6\n"
16145 + " movntq %%mm6, 48(%2)\n"
16146 + " movq 56(%1), %%mm7\n"
16147 + " movntq %%mm7, 56(%2)\n"
16148 ".section .fixup, \"ax\"\n"
16149 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
16152 +#ifdef CONFIG_PAX_KERNEXEC
16153 + " movl %%cr0, %0\n"
16154 + " movl %0, %%eax\n"
16155 + " andl $0xFFFEFFFF, %%eax\n"
16156 + " movl %%eax, %%cr0\n"
16159 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
16161 +#ifdef CONFIG_PAX_KERNEXEC
16162 + " movl %0, %%cr0\n"
16167 - _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
16168 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
16172 @@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
16173 static void fast_copy_page(void *to, void *from)
16176 + unsigned long cr0;
16178 kernel_fpu_begin();
16180 __asm__ __volatile__ (
16181 - "1: prefetch (%0)\n"
16182 - " prefetch 64(%0)\n"
16183 - " prefetch 128(%0)\n"
16184 - " prefetch 192(%0)\n"
16185 - " prefetch 256(%0)\n"
16186 + "1: prefetch (%1)\n"
16187 + " prefetch 64(%1)\n"
16188 + " prefetch 128(%1)\n"
16189 + " prefetch 192(%1)\n"
16190 + " prefetch 256(%1)\n"
16192 ".section .fixup, \"ax\"\n"
16193 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
16196 +#ifdef CONFIG_PAX_KERNEXEC
16197 + " movl %%cr0, %0\n"
16198 + " movl %0, %%eax\n"
16199 + " andl $0xFFFEFFFF, %%eax\n"
16200 + " movl %%eax, %%cr0\n"
16203 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
16205 +#ifdef CONFIG_PAX_KERNEXEC
16206 + " movl %0, %%cr0\n"
16211 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
16212 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
16214 for (i = 0; i < 4096/64; i++) {
16215 __asm__ __volatile__ (
16216 - "1: prefetch 320(%0)\n"
16217 - "2: movq (%0), %%mm0\n"
16218 - " movq 8(%0), %%mm1\n"
16219 - " movq 16(%0), %%mm2\n"
16220 - " movq 24(%0), %%mm3\n"
16221 - " movq %%mm0, (%1)\n"
16222 - " movq %%mm1, 8(%1)\n"
16223 - " movq %%mm2, 16(%1)\n"
16224 - " movq %%mm3, 24(%1)\n"
16225 - " movq 32(%0), %%mm0\n"
16226 - " movq 40(%0), %%mm1\n"
16227 - " movq 48(%0), %%mm2\n"
16228 - " movq 56(%0), %%mm3\n"
16229 - " movq %%mm0, 32(%1)\n"
16230 - " movq %%mm1, 40(%1)\n"
16231 - " movq %%mm2, 48(%1)\n"
16232 - " movq %%mm3, 56(%1)\n"
16233 + "1: prefetch 320(%1)\n"
16234 + "2: movq (%1), %%mm0\n"
16235 + " movq 8(%1), %%mm1\n"
16236 + " movq 16(%1), %%mm2\n"
16237 + " movq 24(%1), %%mm3\n"
16238 + " movq %%mm0, (%2)\n"
16239 + " movq %%mm1, 8(%2)\n"
16240 + " movq %%mm2, 16(%2)\n"
16241 + " movq %%mm3, 24(%2)\n"
16242 + " movq 32(%1), %%mm0\n"
16243 + " movq 40(%1), %%mm1\n"
16244 + " movq 48(%1), %%mm2\n"
16245 + " movq 56(%1), %%mm3\n"
16246 + " movq %%mm0, 32(%2)\n"
16247 + " movq %%mm1, 40(%2)\n"
16248 + " movq %%mm2, 48(%2)\n"
16249 + " movq %%mm3, 56(%2)\n"
16250 ".section .fixup, \"ax\"\n"
16251 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
16254 +#ifdef CONFIG_PAX_KERNEXEC
16255 + " movl %%cr0, %0\n"
16256 + " movl %0, %%eax\n"
16257 + " andl $0xFFFEFFFF, %%eax\n"
16258 + " movl %%eax, %%cr0\n"
16261 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
16263 +#ifdef CONFIG_PAX_KERNEXEC
16264 + " movl %0, %%cr0\n"
16269 _ASM_EXTABLE(1b, 3b)
16270 - : : "r" (from), "r" (to) : "memory");
16271 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
16275 diff -urNp linux-2.6.37/arch/x86/lib/putuser.S linux-2.6.37/arch/x86/lib/putuser.S
16276 --- linux-2.6.37/arch/x86/lib/putuser.S 2011-01-04 19:50:19.000000000 -0500
16277 +++ linux-2.6.37/arch/x86/lib/putuser.S 2011-01-17 02:41:01.000000000 -0500
16279 #include <asm/thread_info.h>
16280 #include <asm/errno.h>
16281 #include <asm/asm.h>
16283 +#include <asm/segment.h>
16284 +#include <asm/pgtable.h>
16288 @@ -29,52 +30,119 @@
16289 * as they get called from within inline assembly.
16292 -#define ENTER CFI_STARTPROC ; \
16293 - GET_THREAD_INFO(%_ASM_BX)
16294 +#define ENTER CFI_STARTPROC
16295 #define EXIT ret ; \
16298 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
16299 +#define _DEST %_ASM_CX,%_ASM_BX
16301 +#define _DEST %_ASM_CX
16304 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
16305 +#define __copyuser_seg %gs:
16307 +#define __copyuser_seg
16311 ENTRY(__put_user_1)
16314 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
16315 + GET_THREAD_INFO(%_ASM_BX)
16316 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
16318 -1: movb %al,(%_ASM_CX)
16320 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
16321 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
16322 + cmp %_ASM_BX,%_ASM_CX
16330 +1: movb %al,__copyuser_seg (_DEST)
16333 ENDPROC(__put_user_1)
16335 ENTRY(__put_user_2)
16338 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
16339 + GET_THREAD_INFO(%_ASM_BX)
16340 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
16342 cmp %_ASM_BX,%_ASM_CX
16344 -2: movw %ax,(%_ASM_CX)
16346 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
16347 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
16348 + cmp %_ASM_BX,%_ASM_CX
16356 +2: movw %ax,__copyuser_seg (_DEST)
16359 ENDPROC(__put_user_2)
16361 ENTRY(__put_user_4)
16364 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
16365 + GET_THREAD_INFO(%_ASM_BX)
16366 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
16368 cmp %_ASM_BX,%_ASM_CX
16370 -3: movl %eax,(%_ASM_CX)
16372 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
16373 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
16374 + cmp %_ASM_BX,%_ASM_CX
16382 +3: movl %eax,__copyuser_seg (_DEST)
16385 ENDPROC(__put_user_4)
16387 ENTRY(__put_user_8)
16390 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
16391 + GET_THREAD_INFO(%_ASM_BX)
16392 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
16394 cmp %_ASM_BX,%_ASM_CX
16396 -4: mov %_ASM_AX,(%_ASM_CX)
16398 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
16399 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
16400 + cmp %_ASM_BX,%_ASM_CX
16408 +4: mov %_ASM_AX,__copyuser_seg (_DEST)
16409 #ifdef CONFIG_X86_32
16410 -5: movl %edx,4(%_ASM_CX)
16411 +5: movl %edx,__copyuser_seg 4(_DEST)
16415 diff -urNp linux-2.6.37/arch/x86/lib/usercopy_32.c linux-2.6.37/arch/x86/lib/usercopy_32.c
16416 --- linux-2.6.37/arch/x86/lib/usercopy_32.c 2011-01-04 19:50:19.000000000 -0500
16417 +++ linux-2.6.37/arch/x86/lib/usercopy_32.c 2011-01-17 02:41:01.000000000 -0500
16418 @@ -43,7 +43,7 @@ do { \
16419 __asm__ __volatile__( \
16423 + "0: lodsb " __copyuser_seg" (%%esi)\n" \
16425 " testb %%al,%%al\n" \
16427 @@ -128,10 +128,12 @@ do { \
16430 __asm__ __volatile__( \
16431 + __COPYUSER_SET_ES \
16432 "0: rep; stosl\n" \
16434 "1: rep; stosb\n" \
16436 + __COPYUSER_RESTORE_ES \
16437 ".section .fixup,\"ax\"\n" \
16438 "3: lea 0(%2,%0,4),%0\n" \
16440 @@ -200,6 +202,7 @@ long strnlen_user(const char __user *s,
16443 __asm__ __volatile__(
16444 + __COPYUSER_SET_ES
16448 @@ -208,6 +211,7 @@ long strnlen_user(const char __user *s,
16452 + __COPYUSER_RESTORE_ES
16453 ".section .fixup,\"ax\"\n"
16454 "2: xorl %%eax,%%eax\n"
16456 @@ -227,7 +231,7 @@ EXPORT_SYMBOL(strnlen_user);
16458 #ifdef CONFIG_X86_INTEL_USERCOPY
16459 static unsigned long
16460 -__copy_user_intel(void __user *to, const void *from, unsigned long size)
16461 +__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
16464 __asm__ __volatile__(
16465 @@ -239,36 +243,36 @@ __copy_user_intel(void __user *to, const
16467 "3: movl 0(%4), %%eax\n"
16468 "4: movl 4(%4), %%edx\n"
16469 - "5: movl %%eax, 0(%3)\n"
16470 - "6: movl %%edx, 4(%3)\n"
16471 + "5: movl %%eax, "__copyuser_seg" 0(%3)\n"
16472 + "6: movl %%edx, "__copyuser_seg" 4(%3)\n"
16473 "7: movl 8(%4), %%eax\n"
16474 "8: movl 12(%4),%%edx\n"
16475 - "9: movl %%eax, 8(%3)\n"
16476 - "10: movl %%edx, 12(%3)\n"
16477 + "9: movl %%eax, "__copyuser_seg" 8(%3)\n"
16478 + "10: movl %%edx, "__copyuser_seg" 12(%3)\n"
16479 "11: movl 16(%4), %%eax\n"
16480 "12: movl 20(%4), %%edx\n"
16481 - "13: movl %%eax, 16(%3)\n"
16482 - "14: movl %%edx, 20(%3)\n"
16483 + "13: movl %%eax, "__copyuser_seg" 16(%3)\n"
16484 + "14: movl %%edx, "__copyuser_seg" 20(%3)\n"
16485 "15: movl 24(%4), %%eax\n"
16486 "16: movl 28(%4), %%edx\n"
16487 - "17: movl %%eax, 24(%3)\n"
16488 - "18: movl %%edx, 28(%3)\n"
16489 + "17: movl %%eax, "__copyuser_seg" 24(%3)\n"
16490 + "18: movl %%edx, "__copyuser_seg" 28(%3)\n"
16491 "19: movl 32(%4), %%eax\n"
16492 "20: movl 36(%4), %%edx\n"
16493 - "21: movl %%eax, 32(%3)\n"
16494 - "22: movl %%edx, 36(%3)\n"
16495 + "21: movl %%eax, "__copyuser_seg" 32(%3)\n"
16496 + "22: movl %%edx, "__copyuser_seg" 36(%3)\n"
16497 "23: movl 40(%4), %%eax\n"
16498 "24: movl 44(%4), %%edx\n"
16499 - "25: movl %%eax, 40(%3)\n"
16500 - "26: movl %%edx, 44(%3)\n"
16501 + "25: movl %%eax, "__copyuser_seg" 40(%3)\n"
16502 + "26: movl %%edx, "__copyuser_seg" 44(%3)\n"
16503 "27: movl 48(%4), %%eax\n"
16504 "28: movl 52(%4), %%edx\n"
16505 - "29: movl %%eax, 48(%3)\n"
16506 - "30: movl %%edx, 52(%3)\n"
16507 + "29: movl %%eax, "__copyuser_seg" 48(%3)\n"
16508 + "30: movl %%edx, "__copyuser_seg" 52(%3)\n"
16509 "31: movl 56(%4), %%eax\n"
16510 "32: movl 60(%4), %%edx\n"
16511 - "33: movl %%eax, 56(%3)\n"
16512 - "34: movl %%edx, 60(%3)\n"
16513 + "33: movl %%eax, "__copyuser_seg" 56(%3)\n"
16514 + "34: movl %%edx, "__copyuser_seg" 60(%3)\n"
16518 @@ -278,10 +282,119 @@ __copy_user_intel(void __user *to, const
16520 " andl $3, %%eax\n"
16522 + __COPYUSER_SET_ES
16524 "36: movl %%eax, %0\n"
16527 + __COPYUSER_RESTORE_ES
16528 + ".section .fixup,\"ax\"\n"
16529 + "101: lea 0(%%eax,%0,4),%0\n"
16532 + ".section __ex_table,\"a\"\n"
16534 + " .long 1b,100b\n"
16535 + " .long 2b,100b\n"
16536 + " .long 3b,100b\n"
16537 + " .long 4b,100b\n"
16538 + " .long 5b,100b\n"
16539 + " .long 6b,100b\n"
16540 + " .long 7b,100b\n"
16541 + " .long 8b,100b\n"
16542 + " .long 9b,100b\n"
16543 + " .long 10b,100b\n"
16544 + " .long 11b,100b\n"
16545 + " .long 12b,100b\n"
16546 + " .long 13b,100b\n"
16547 + " .long 14b,100b\n"
16548 + " .long 15b,100b\n"
16549 + " .long 16b,100b\n"
16550 + " .long 17b,100b\n"
16551 + " .long 18b,100b\n"
16552 + " .long 19b,100b\n"
16553 + " .long 20b,100b\n"
16554 + " .long 21b,100b\n"
16555 + " .long 22b,100b\n"
16556 + " .long 23b,100b\n"
16557 + " .long 24b,100b\n"
16558 + " .long 25b,100b\n"
16559 + " .long 26b,100b\n"
16560 + " .long 27b,100b\n"
16561 + " .long 28b,100b\n"
16562 + " .long 29b,100b\n"
16563 + " .long 30b,100b\n"
16564 + " .long 31b,100b\n"
16565 + " .long 32b,100b\n"
16566 + " .long 33b,100b\n"
16567 + " .long 34b,100b\n"
16568 + " .long 35b,100b\n"
16569 + " .long 36b,100b\n"
16570 + " .long 37b,100b\n"
16571 + " .long 99b,101b\n"
16573 + : "=&c"(size), "=&D" (d0), "=&S" (d1)
16574 + : "1"(to), "2"(from), "0"(size)
16575 + : "eax", "edx", "memory");
16579 +static unsigned long
16580 +__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
16583 + __asm__ __volatile__(
16584 + " .align 2,0x90\n"
16585 + "1: movl "__copyuser_seg" 32(%4), %%eax\n"
16586 + " cmpl $67, %0\n"
16588 + "2: movl "__copyuser_seg" 64(%4), %%eax\n"
16589 + " .align 2,0x90\n"
16590 + "3: movl "__copyuser_seg" 0(%4), %%eax\n"
16591 + "4: movl "__copyuser_seg" 4(%4), %%edx\n"
16592 + "5: movl %%eax, 0(%3)\n"
16593 + "6: movl %%edx, 4(%3)\n"
16594 + "7: movl "__copyuser_seg" 8(%4), %%eax\n"
16595 + "8: movl "__copyuser_seg" 12(%4),%%edx\n"
16596 + "9: movl %%eax, 8(%3)\n"
16597 + "10: movl %%edx, 12(%3)\n"
16598 + "11: movl "__copyuser_seg" 16(%4), %%eax\n"
16599 + "12: movl "__copyuser_seg" 20(%4), %%edx\n"
16600 + "13: movl %%eax, 16(%3)\n"
16601 + "14: movl %%edx, 20(%3)\n"
16602 + "15: movl "__copyuser_seg" 24(%4), %%eax\n"
16603 + "16: movl "__copyuser_seg" 28(%4), %%edx\n"
16604 + "17: movl %%eax, 24(%3)\n"
16605 + "18: movl %%edx, 28(%3)\n"
16606 + "19: movl "__copyuser_seg" 32(%4), %%eax\n"
16607 + "20: movl "__copyuser_seg" 36(%4), %%edx\n"
16608 + "21: movl %%eax, 32(%3)\n"
16609 + "22: movl %%edx, 36(%3)\n"
16610 + "23: movl "__copyuser_seg" 40(%4), %%eax\n"
16611 + "24: movl "__copyuser_seg" 44(%4), %%edx\n"
16612 + "25: movl %%eax, 40(%3)\n"
16613 + "26: movl %%edx, 44(%3)\n"
16614 + "27: movl "__copyuser_seg" 48(%4), %%eax\n"
16615 + "28: movl "__copyuser_seg" 52(%4), %%edx\n"
16616 + "29: movl %%eax, 48(%3)\n"
16617 + "30: movl %%edx, 52(%3)\n"
16618 + "31: movl "__copyuser_seg" 56(%4), %%eax\n"
16619 + "32: movl "__copyuser_seg" 60(%4), %%edx\n"
16620 + "33: movl %%eax, 56(%3)\n"
16621 + "34: movl %%edx, 60(%3)\n"
16622 + " addl $-64, %0\n"
16623 + " addl $64, %4\n"
16624 + " addl $64, %3\n"
16625 + " cmpl $63, %0\n"
16627 + "35: movl %0, %%eax\n"
16629 + " andl $3, %%eax\n"
16631 + "99: rep; movsl "__copyuser_seg" (%%esi), (%%edi)\n"
16632 + "36: movl %%eax, %0\n"
16633 + "37: rep; movsb "__copyuser_seg" (%%esi), (%%edi)\n"
16635 ".section .fixup,\"ax\"\n"
16636 "101: lea 0(%%eax,%0,4),%0\n"
16638 @@ -339,41 +452,41 @@ __copy_user_zeroing_intel(void *to, cons
16640 __asm__ __volatile__(
16642 - "0: movl 32(%4), %%eax\n"
16643 + "0: movl "__copyuser_seg" 32(%4), %%eax\n"
16646 - "1: movl 64(%4), %%eax\n"
16647 + "1: movl "__copyuser_seg" 64(%4), %%eax\n"
16649 - "2: movl 0(%4), %%eax\n"
16650 - "21: movl 4(%4), %%edx\n"
16651 + "2: movl "__copyuser_seg" 0(%4), %%eax\n"
16652 + "21: movl "__copyuser_seg" 4(%4), %%edx\n"
16653 " movl %%eax, 0(%3)\n"
16654 " movl %%edx, 4(%3)\n"
16655 - "3: movl 8(%4), %%eax\n"
16656 - "31: movl 12(%4),%%edx\n"
16657 + "3: movl "__copyuser_seg" 8(%4), %%eax\n"
16658 + "31: movl "__copyuser_seg" 12(%4),%%edx\n"
16659 " movl %%eax, 8(%3)\n"
16660 " movl %%edx, 12(%3)\n"
16661 - "4: movl 16(%4), %%eax\n"
16662 - "41: movl 20(%4), %%edx\n"
16663 + "4: movl "__copyuser_seg" 16(%4), %%eax\n"
16664 + "41: movl "__copyuser_seg" 20(%4), %%edx\n"
16665 " movl %%eax, 16(%3)\n"
16666 " movl %%edx, 20(%3)\n"
16667 - "10: movl 24(%4), %%eax\n"
16668 - "51: movl 28(%4), %%edx\n"
16669 + "10: movl "__copyuser_seg" 24(%4), %%eax\n"
16670 + "51: movl "__copyuser_seg" 28(%4), %%edx\n"
16671 " movl %%eax, 24(%3)\n"
16672 " movl %%edx, 28(%3)\n"
16673 - "11: movl 32(%4), %%eax\n"
16674 - "61: movl 36(%4), %%edx\n"
16675 + "11: movl "__copyuser_seg" 32(%4), %%eax\n"
16676 + "61: movl "__copyuser_seg" 36(%4), %%edx\n"
16677 " movl %%eax, 32(%3)\n"
16678 " movl %%edx, 36(%3)\n"
16679 - "12: movl 40(%4), %%eax\n"
16680 - "71: movl 44(%4), %%edx\n"
16681 + "12: movl "__copyuser_seg" 40(%4), %%eax\n"
16682 + "71: movl "__copyuser_seg" 44(%4), %%edx\n"
16683 " movl %%eax, 40(%3)\n"
16684 " movl %%edx, 44(%3)\n"
16685 - "13: movl 48(%4), %%eax\n"
16686 - "81: movl 52(%4), %%edx\n"
16687 + "13: movl "__copyuser_seg" 48(%4), %%eax\n"
16688 + "81: movl "__copyuser_seg" 52(%4), %%edx\n"
16689 " movl %%eax, 48(%3)\n"
16690 " movl %%edx, 52(%3)\n"
16691 - "14: movl 56(%4), %%eax\n"
16692 - "91: movl 60(%4), %%edx\n"
16693 + "14: movl "__copyuser_seg" 56(%4), %%eax\n"
16694 + "91: movl "__copyuser_seg" 60(%4), %%edx\n"
16695 " movl %%eax, 56(%3)\n"
16696 " movl %%edx, 60(%3)\n"
16698 @@ -385,9 +498,9 @@ __copy_user_zeroing_intel(void *to, cons
16700 " andl $3, %%eax\n"
16702 - "6: rep; movsl\n"
16703 + "6: rep; movsl "__copyuser_seg" (%%esi), (%%edi)\n"
16705 - "7: rep; movsb\n"
16706 + "7: rep; movsb "__copyuser_seg" (%%esi), (%%edi)\n"
16708 ".section .fixup,\"ax\"\n"
16709 "9: lea 0(%%eax,%0,4),%0\n"
16710 @@ -440,41 +553,41 @@ static unsigned long __copy_user_zeroing
16712 __asm__ __volatile__(
16714 - "0: movl 32(%4), %%eax\n"
16715 + "0: movl "__copyuser_seg" 32(%4), %%eax\n"
16718 - "1: movl 64(%4), %%eax\n"
16719 + "1: movl "__copyuser_seg" 64(%4), %%eax\n"
16721 - "2: movl 0(%4), %%eax\n"
16722 - "21: movl 4(%4), %%edx\n"
16723 + "2: movl "__copyuser_seg" 0(%4), %%eax\n"
16724 + "21: movl "__copyuser_seg" 4(%4), %%edx\n"
16725 " movnti %%eax, 0(%3)\n"
16726 " movnti %%edx, 4(%3)\n"
16727 - "3: movl 8(%4), %%eax\n"
16728 - "31: movl 12(%4),%%edx\n"
16729 + "3: movl "__copyuser_seg" 8(%4), %%eax\n"
16730 + "31: movl "__copyuser_seg" 12(%4),%%edx\n"
16731 " movnti %%eax, 8(%3)\n"
16732 " movnti %%edx, 12(%3)\n"
16733 - "4: movl 16(%4), %%eax\n"
16734 - "41: movl 20(%4), %%edx\n"
16735 + "4: movl "__copyuser_seg" 16(%4), %%eax\n"
16736 + "41: movl "__copyuser_seg" 20(%4), %%edx\n"
16737 " movnti %%eax, 16(%3)\n"
16738 " movnti %%edx, 20(%3)\n"
16739 - "10: movl 24(%4), %%eax\n"
16740 - "51: movl 28(%4), %%edx\n"
16741 + "10: movl "__copyuser_seg" 24(%4), %%eax\n"
16742 + "51: movl "__copyuser_seg" 28(%4), %%edx\n"
16743 " movnti %%eax, 24(%3)\n"
16744 " movnti %%edx, 28(%3)\n"
16745 - "11: movl 32(%4), %%eax\n"
16746 - "61: movl 36(%4), %%edx\n"
16747 + "11: movl "__copyuser_seg" 32(%4), %%eax\n"
16748 + "61: movl "__copyuser_seg" 36(%4), %%edx\n"
16749 " movnti %%eax, 32(%3)\n"
16750 " movnti %%edx, 36(%3)\n"
16751 - "12: movl 40(%4), %%eax\n"
16752 - "71: movl 44(%4), %%edx\n"
16753 + "12: movl "__copyuser_seg" 40(%4), %%eax\n"
16754 + "71: movl "__copyuser_seg" 44(%4), %%edx\n"
16755 " movnti %%eax, 40(%3)\n"
16756 " movnti %%edx, 44(%3)\n"
16757 - "13: movl 48(%4), %%eax\n"
16758 - "81: movl 52(%4), %%edx\n"
16759 + "13: movl "__copyuser_seg" 48(%4), %%eax\n"
16760 + "81: movl "__copyuser_seg" 52(%4), %%edx\n"
16761 " movnti %%eax, 48(%3)\n"
16762 " movnti %%edx, 52(%3)\n"
16763 - "14: movl 56(%4), %%eax\n"
16764 - "91: movl 60(%4), %%edx\n"
16765 + "14: movl "__copyuser_seg" 56(%4), %%eax\n"
16766 + "91: movl "__copyuser_seg" 60(%4), %%edx\n"
16767 " movnti %%eax, 56(%3)\n"
16768 " movnti %%edx, 60(%3)\n"
16770 @@ -487,9 +600,9 @@ static unsigned long __copy_user_zeroing
16772 " andl $3, %%eax\n"
16774 - "6: rep; movsl\n"
16775 + "6: rep; movsl "__copyuser_seg" (%%esi), (%%edi)\n"
16777 - "7: rep; movsb\n"
16778 + "7: rep; movsb "__copyuser_seg" (%%esi), (%%edi)\n"
16780 ".section .fixup,\"ax\"\n"
16781 "9: lea 0(%%eax,%0,4),%0\n"
16782 @@ -537,41 +650,41 @@ static unsigned long __copy_user_intel_n
16784 __asm__ __volatile__(
16786 - "0: movl 32(%4), %%eax\n"
16787 + "0: movl "__copyuser_seg" 32(%4), %%eax\n"
16790 - "1: movl 64(%4), %%eax\n"
16791 + "1: movl "__copyuser_seg" 64(%4), %%eax\n"
16793 - "2: movl 0(%4), %%eax\n"
16794 - "21: movl 4(%4), %%edx\n"
16795 + "2: movl "__copyuser_seg" 0(%4), %%eax\n"
16796 + "21: movl "__copyuser_seg" 4(%4), %%edx\n"
16797 " movnti %%eax, 0(%3)\n"
16798 " movnti %%edx, 4(%3)\n"
16799 - "3: movl 8(%4), %%eax\n"
16800 - "31: movl 12(%4),%%edx\n"
16801 + "3: movl "__copyuser_seg" 8(%4), %%eax\n"
16802 + "31: movl "__copyuser_seg" 12(%4),%%edx\n"
16803 " movnti %%eax, 8(%3)\n"
16804 " movnti %%edx, 12(%3)\n"
16805 - "4: movl 16(%4), %%eax\n"
16806 - "41: movl 20(%4), %%edx\n"
16807 + "4: movl "__copyuser_seg" 16(%4), %%eax\n"
16808 + "41: movl "__copyuser_seg" 20(%4), %%edx\n"
16809 " movnti %%eax, 16(%3)\n"
16810 " movnti %%edx, 20(%3)\n"
16811 - "10: movl 24(%4), %%eax\n"
16812 - "51: movl 28(%4), %%edx\n"
16813 + "10: movl "__copyuser_seg" 24(%4), %%eax\n"
16814 + "51: movl "__copyuser_seg" 28(%4), %%edx\n"
16815 " movnti %%eax, 24(%3)\n"
16816 " movnti %%edx, 28(%3)\n"
16817 - "11: movl 32(%4), %%eax\n"
16818 - "61: movl 36(%4), %%edx\n"
16819 + "11: movl "__copyuser_seg" 32(%4), %%eax\n"
16820 + "61: movl "__copyuser_seg" 36(%4), %%edx\n"
16821 " movnti %%eax, 32(%3)\n"
16822 " movnti %%edx, 36(%3)\n"
16823 - "12: movl 40(%4), %%eax\n"
16824 - "71: movl 44(%4), %%edx\n"
16825 + "12: movl "__copyuser_seg" 40(%4), %%eax\n"
16826 + "71: movl "__copyuser_seg" 44(%4), %%edx\n"
16827 " movnti %%eax, 40(%3)\n"
16828 " movnti %%edx, 44(%3)\n"
16829 - "13: movl 48(%4), %%eax\n"
16830 - "81: movl 52(%4), %%edx\n"
16831 + "13: movl "__copyuser_seg" 48(%4), %%eax\n"
16832 + "81: movl "__copyuser_seg" 52(%4), %%edx\n"
16833 " movnti %%eax, 48(%3)\n"
16834 " movnti %%edx, 52(%3)\n"
16835 - "14: movl 56(%4), %%eax\n"
16836 - "91: movl 60(%4), %%edx\n"
16837 + "14: movl "__copyuser_seg" 56(%4), %%eax\n"
16838 + "91: movl "__copyuser_seg" 60(%4), %%edx\n"
16839 " movnti %%eax, 56(%3)\n"
16840 " movnti %%edx, 60(%3)\n"
16842 @@ -584,9 +697,9 @@ static unsigned long __copy_user_intel_n
16844 " andl $3, %%eax\n"
16846 - "6: rep; movsl\n"
16847 + "6: rep; movsl "__copyuser_seg" (%%esi), (%%edi)\n"
16849 - "7: rep; movsb\n"
16850 + "7: rep; movsb "__copyuser_seg" (%%esi), (%%edi)\n"
16852 ".section .fixup,\"ax\"\n"
16853 "9: lea 0(%%eax,%0,4),%0\n"
16854 @@ -629,32 +742,36 @@ static unsigned long __copy_user_intel_n
16856 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
16857 unsigned long size);
16858 -unsigned long __copy_user_intel(void __user *to, const void *from,
16859 +unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
16860 + unsigned long size);
16861 +unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
16862 unsigned long size);
16863 unsigned long __copy_user_zeroing_intel_nocache(void *to,
16864 const void __user *from, unsigned long size);
16865 #endif /* CONFIG_X86_INTEL_USERCOPY */
16867 /* Generic arbitrary sized copy. */
16868 -#define __copy_user(to, from, size) \
16869 +#define __copy_user(to, from, size, prefix, set, restore) \
16871 int __d0, __d1, __d2; \
16872 __asm__ __volatile__( \
16880 - "4: rep; movsb\n" \
16881 + "4: rep; movsb "prefix" (%%esi), (%%edi)\n" \
16885 " .align 2,0x90\n" \
16886 - "0: rep; movsl\n" \
16887 + "0: rep; movsl "prefix" (%%esi), (%%edi)\n" \
16889 - "1: rep; movsb\n" \
16890 + "1: rep; movsb "prefix" (%%esi), (%%edi)\n" \
16893 ".section .fixup,\"ax\"\n" \
16894 "5: addl %3,%0\n" \
16896 @@ -682,14 +799,14 @@ do { \
16900 - "4: rep; movsb\n" \
16901 + "4: rep; movsb "__copyuser_seg" (%%esi), (%%edi)\n" \
16905 " .align 2,0x90\n" \
16906 - "0: rep; movsl\n" \
16907 + "0: rep; movsl "__copyuser_seg" (%%esi), (%%edi)\n" \
16909 - "1: rep; movsb\n" \
16910 + "1: rep; movsb "__copyuser_seg" (%%esi), (%%edi)\n" \
16912 ".section .fixup,\"ax\"\n" \
16913 "5: addl %3,%0\n" \
16914 @@ -775,9 +892,9 @@ survive:
16917 if (movsl_is_ok(to, from, n))
16918 - __copy_user(to, from, n);
16919 + __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
16921 - n = __copy_user_intel(to, from, n);
16922 + n = __generic_copy_to_user_intel(to, from, n);
16925 EXPORT_SYMBOL(__copy_to_user_ll);
16926 @@ -797,10 +914,9 @@ unsigned long __copy_from_user_ll_nozero
16929 if (movsl_is_ok(to, from, n))
16930 - __copy_user(to, from, n);
16931 + __copy_user(to, from, n, __copyuser_seg, "", "");
16933 - n = __copy_user_intel((void __user *)to,
16934 - (const void *)from, n);
16935 + n = __generic_copy_from_user_intel(to, from, n);
16938 EXPORT_SYMBOL(__copy_from_user_ll_nozero);
16939 @@ -827,65 +943,49 @@ unsigned long __copy_from_user_ll_nocach
16940 if (n > 64 && cpu_has_xmm2)
16941 n = __copy_user_intel_nocache(to, from, n);
16943 - __copy_user(to, from, n);
16944 + __copy_user(to, from, n, __copyuser_seg, "", "");
16946 - __copy_user(to, from, n);
16947 + __copy_user(to, from, n, __copyuser_seg, "", "");
16951 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
16954 - * copy_to_user: - Copy a block of data into user space.
16955 - * @to: Destination address, in user space.
16956 - * @from: Source address, in kernel space.
16957 - * @n: Number of bytes to copy.
16959 - * Context: User context only. This function may sleep.
16961 - * Copy data from kernel space to user space.
16963 - * Returns number of bytes that could not be copied.
16964 - * On success, this will be zero.
16967 -copy_to_user(void __user *to, const void *from, unsigned long n)
16968 +void copy_from_user_overflow(void)
16970 - if (access_ok(VERIFY_WRITE, to, n))
16971 - n = __copy_to_user(to, from, n);
16973 + WARN(1, "Buffer overflow detected!\n");
16975 -EXPORT_SYMBOL(copy_to_user);
16976 +EXPORT_SYMBOL(copy_from_user_overflow);
16979 - * copy_from_user: - Copy a block of data from user space.
16980 - * @to: Destination address, in kernel space.
16981 - * @from: Source address, in user space.
16982 - * @n: Number of bytes to copy.
16984 - * Context: User context only. This function may sleep.
16986 - * Copy data from user space to kernel space.
16988 - * Returns number of bytes that could not be copied.
16989 - * On success, this will be zero.
16991 - * If some data could not be copied, this function will pad the copied
16992 - * data to the requested size using zero bytes.
16995 -_copy_from_user(void *to, const void __user *from, unsigned long n)
16996 +void copy_to_user_overflow(void)
16998 - if (access_ok(VERIFY_READ, from, n))
16999 - n = __copy_from_user(to, from, n);
17001 - memset(to, 0, n);
17003 + WARN(1, "Buffer overflow detected!\n");
17005 -EXPORT_SYMBOL(_copy_from_user);
17006 +EXPORT_SYMBOL(copy_to_user_overflow);
17008 -void copy_from_user_overflow(void)
17009 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17010 +void __set_fs(mm_segment_t x)
17012 - WARN(1, "Buffer overflow detected!\n");
17015 + loadsegment(gs, 0);
17017 + case TASK_SIZE_MAX:
17018 + loadsegment(gs, __USER_DS);
17021 + loadsegment(gs, __KERNEL_DS);
17028 -EXPORT_SYMBOL(copy_from_user_overflow);
17030 +void set_fs(mm_segment_t x)
17032 + current_thread_info()->addr_limit = x;
17035 +EXPORT_SYMBOL(set_fs);
17037 diff -urNp linux-2.6.37/arch/x86/lib/usercopy_64.c linux-2.6.37/arch/x86/lib/usercopy_64.c
17038 --- linux-2.6.37/arch/x86/lib/usercopy_64.c 2011-01-04 19:50:19.000000000 -0500
17039 +++ linux-2.6.37/arch/x86/lib/usercopy_64.c 2011-01-17 02:41:01.000000000 -0500
17040 @@ -42,6 +42,8 @@ long
17041 __strncpy_from_user(char *dst, const char __user *src, long count)
17044 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
17045 + src += PAX_USER_SHADOW_BASE;
17046 __do_strncpy_from_user(dst, src, count, res);
17049 @@ -65,6 +67,8 @@ unsigned long __clear_user(void __user *
17053 + if ((unsigned long)addr < PAX_USER_SHADOW_BASE)
17054 + addr += PAX_USER_SHADOW_BASE;
17055 /* no memory constraint because it doesn't change any memory gcc knows
17058 @@ -151,10 +155,14 @@ EXPORT_SYMBOL(strlen_user);
17060 unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
17062 - if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
17063 + if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
17064 + if ((unsigned long)to < PAX_USER_SHADOW_BASE)
17065 + to += PAX_USER_SHADOW_BASE;
17066 + if ((unsigned long)from < PAX_USER_SHADOW_BASE)
17067 + from += PAX_USER_SHADOW_BASE;
17068 return copy_user_generic((__force void *)to, (__force void *)from, len);
17074 EXPORT_SYMBOL(copy_in_user);
17076 diff -urNp linux-2.6.37/arch/x86/Makefile linux-2.6.37/arch/x86/Makefile
17077 --- linux-2.6.37/arch/x86/Makefile 2011-01-04 19:50:19.000000000 -0500
17078 +++ linux-2.6.37/arch/x86/Makefile 2011-01-17 02:41:01.000000000 -0500
17079 @@ -195,3 +195,12 @@ define archhelp
17080 echo ' FDARGS="..." arguments for the booted kernel'
17081 echo ' FDINITRD=file initrd for the booted kernel'
17086 +*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
17087 +*** Please upgrade your binutils to 2.18 or newer
17091 + $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
17092 diff -urNp linux-2.6.37/arch/x86/mm/extable.c linux-2.6.37/arch/x86/mm/extable.c
17093 --- linux-2.6.37/arch/x86/mm/extable.c 2011-01-04 19:50:19.000000000 -0500
17094 +++ linux-2.6.37/arch/x86/mm/extable.c 2011-01-17 02:41:01.000000000 -0500
17096 #include <linux/module.h>
17097 #include <linux/spinlock.h>
17098 +#include <linux/sort.h>
17099 #include <asm/uaccess.h>
17100 +#include <asm/pgtable.h>
17103 + * The exception table needs to be sorted so that the binary
17104 + * search that we use to find entries in it works properly.
17105 + * This is used both for the kernel exception table and for
17106 + * the exception tables of modules that get loaded.
17108 +static int cmp_ex(const void *a, const void *b)
17110 + const struct exception_table_entry *x = a, *y = b;
17112 + /* avoid overflow */
17113 + if (x->insn > y->insn)
17115 + if (x->insn < y->insn)
17120 +static void swap_ex(void *a, void *b, int size)
17122 + struct exception_table_entry t, *x = a, *y = b;
17126 + pax_open_kernel();
17129 + pax_close_kernel();
17132 +void sort_extable(struct exception_table_entry *start,
17133 + struct exception_table_entry *finish)
17135 + sort(start, finish - start, sizeof(struct exception_table_entry),
17136 + cmp_ex, swap_ex);
17139 +#ifdef CONFIG_MODULES
17141 + * If the exception table is sorted, any referring to the module init
17142 + * will be at the beginning or the end.
17144 +void trim_init_extable(struct module *m)
17146 + /*trim the beginning*/
17147 + while (m->num_exentries && within_module_init(m->extable[0].insn, m)) {
17149 + m->num_exentries--;
17152 + while (m->num_exentries &&
17153 + within_module_init(m->extable[m->num_exentries-1].insn, m))
17154 + m->num_exentries--;
17156 +#endif /* CONFIG_MODULES */
17158 int fixup_exception(struct pt_regs *regs)
17160 const struct exception_table_entry *fixup;
17162 #ifdef CONFIG_PNPBIOS
17163 - if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
17164 + if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
17165 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
17166 extern u32 pnp_bios_is_utter_crap;
17167 pnp_bios_is_utter_crap = 1;
17168 diff -urNp linux-2.6.37/arch/x86/mm/fault.c linux-2.6.37/arch/x86/mm/fault.c
17169 --- linux-2.6.37/arch/x86/mm/fault.c 2011-01-04 19:50:19.000000000 -0500
17170 +++ linux-2.6.37/arch/x86/mm/fault.c 2011-01-17 02:41:01.000000000 -0500
17171 @@ -12,10 +12,18 @@
17172 #include <linux/mmiotrace.h> /* kmmio_handler, ... */
17173 #include <linux/perf_event.h> /* perf_sw_event */
17174 #include <linux/hugetlb.h> /* hstate_index_to_shift */
17175 +#include <linux/unistd.h>
17176 +#include <linux/compiler.h>
17178 #include <asm/traps.h> /* dotraplinkage, ... */
17179 #include <asm/pgalloc.h> /* pgd_*(), ... */
17180 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
17181 +#include <asm/vsyscall.h>
17182 +#include <asm/tlbflush.h>
17184 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17185 +#include <asm/stacktrace.h>
17189 * Page fault error code bits:
17190 @@ -53,7 +61,7 @@ static inline int __kprobes notify_page_
17193 /* kprobe_running() needs smp_processor_id() */
17194 - if (kprobes_built_in() && !user_mode_vm(regs)) {
17195 + if (kprobes_built_in() && !user_mode(regs)) {
17197 if (kprobe_running() && kprobe_fault_handler(regs, 14))
17199 @@ -114,7 +122,10 @@ check_prefetch_opcode(struct pt_regs *re
17200 return !instr_lo || (instr_lo>>1) == 1;
17202 /* Prefetch instruction is 0x0F0D or 0x0F18 */
17203 - if (probe_kernel_address(instr, opcode))
17204 + if (user_mode(regs)) {
17205 + if (__copy_from_user_inatomic(&opcode, (__force unsigned char __user *)(instr), 1))
17207 + } else if (probe_kernel_address(instr, opcode))
17210 *prefetch = (instr_lo == 0xF) &&
17211 @@ -148,7 +159,10 @@ is_prefetch(struct pt_regs *regs, unsign
17212 while (instr < max_instr) {
17213 unsigned char opcode;
17215 - if (probe_kernel_address(instr, opcode))
17216 + if (user_mode(regs)) {
17217 + if (__copy_from_user_inatomic(&opcode, (__force unsigned char __user *)(instr), 1))
17219 + } else if (probe_kernel_address(instr, opcode))
17223 @@ -179,6 +193,30 @@ force_sig_info_fault(int si_signo, int s
17224 force_sig_info(si_signo, &info, tsk);
17227 +#ifdef CONFIG_PAX_EMUTRAMP
17228 +static int pax_handle_fetch_fault(struct pt_regs *regs);
17231 +#ifdef CONFIG_PAX_PAGEEXEC
17232 +static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
17238 + pgd = pgd_offset(mm, address);
17239 + if (!pgd_present(*pgd))
17241 + pud = pud_offset(pgd, address);
17242 + if (!pud_present(*pud))
17244 + pmd = pmd_offset(pud, address);
17245 + if (!pmd_present(*pmd))
17251 DEFINE_SPINLOCK(pgd_lock);
17252 LIST_HEAD(pgd_list);
17254 @@ -231,18 +269,35 @@ void vmalloc_sync_all(void)
17255 address += PMD_SIZE) {
17257 unsigned long flags;
17259 +#ifdef CONFIG_PAX_PER_CPU_PGD
17260 + unsigned long cpu;
17265 spin_lock_irqsave(&pgd_lock, flags);
17267 +#ifdef CONFIG_PAX_PER_CPU_PGD
17268 + for (cpu = 0; cpu < NR_CPUS; ++cpu) {
17269 + pgd_t *pgd = get_cpu_pgd(cpu);
17272 list_for_each_entry(page, &pgd_list, lru) {
17273 + pgd_t *pgd = page_address(page);
17274 spinlock_t *pgt_lock;
17277 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
17279 spin_lock(pgt_lock);
17280 - ret = vmalloc_sync_one(page_address(page), address);
17283 + ret = vmalloc_sync_one(pgd, address);
17285 +#ifndef CONFIG_PAX_PER_CPU_PGD
17286 spin_unlock(pgt_lock);
17291 @@ -276,6 +331,11 @@ static noinline __kprobes int vmalloc_fa
17292 * an interrupt in the middle of a task switch..
17294 pgd_paddr = read_cr3();
17296 +#ifdef CONFIG_PAX_PER_CPU_PGD
17297 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (pgd_paddr & PHYSICAL_PAGE_MASK));
17300 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
17303 @@ -371,7 +431,14 @@ static noinline __kprobes int vmalloc_fa
17304 * happen within a race in page table update. In the later
17308 +#ifdef CONFIG_PAX_PER_CPU_PGD
17309 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (read_cr3() & PHYSICAL_PAGE_MASK));
17310 + pgd = pgd_offset_cpu(smp_processor_id(), address);
17312 pgd = pgd_offset(current->active_mm, address);
17315 pgd_ref = pgd_offset_k(address);
17316 if (pgd_none(*pgd_ref))
17318 @@ -533,7 +600,7 @@ static int is_errata93(struct pt_regs *r
17319 static int is_errata100(struct pt_regs *regs, unsigned long address)
17321 #ifdef CONFIG_X86_64
17322 - if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
17323 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
17327 @@ -560,7 +627,7 @@ static int is_f00f_bug(struct pt_regs *r
17330 static const char nx_warning[] = KERN_CRIT
17331 -"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
17332 +"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
17335 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
17336 @@ -569,15 +636,26 @@ show_fault_oops(struct pt_regs *regs, un
17337 if (!oops_may_print())
17340 - if (error_code & PF_INSTR) {
17341 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
17342 unsigned int level;
17344 pte_t *pte = lookup_address(address, &level);
17346 if (pte && pte_present(*pte) && !pte_exec(*pte))
17347 - printk(nx_warning, current_uid());
17348 + printk(nx_warning, current_uid(), current->comm, task_pid_nr(current));
17351 +#ifdef CONFIG_PAX_KERNEXEC
17352 + if (init_mm.start_code <= address && address < init_mm.end_code) {
17353 + if (current->signal->curr_ip)
17354 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
17355 + ¤t->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
17357 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
17358 + current->comm, task_pid_nr(current), current_uid(), current_euid());
17362 printk(KERN_ALERT "BUG: unable to handle kernel ");
17363 if (address < PAGE_SIZE)
17364 printk(KERN_CONT "NULL pointer dereference");
17365 @@ -702,6 +780,68 @@ __bad_area_nosemaphore(struct pt_regs *r
17366 unsigned long address, int si_code)
17368 struct task_struct *tsk = current;
17369 + struct mm_struct *mm = tsk->mm;
17371 +#ifdef CONFIG_X86_64
17372 + if (mm && (error_code & PF_INSTR) && mm->context.vdso) {
17373 + if (regs->ip == (unsigned long)vgettimeofday) {
17374 + regs->ip = (unsigned long)VDSO64_SYMBOL(mm->context.vdso, fallback_gettimeofday);
17376 + } else if (regs->ip == (unsigned long)vtime) {
17377 + regs->ip = (unsigned long)VDSO64_SYMBOL(mm->context.vdso, fallback_time);
17379 + } else if (regs->ip == (unsigned long)vgetcpu) {
17380 + regs->ip = (unsigned long)VDSO64_SYMBOL(mm->context.vdso, getcpu);
17386 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
17387 + if (mm && (error_code & PF_USER)) {
17388 + unsigned long ip = regs->ip;
17390 + if (v8086_mode(regs))
17391 + ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
17394 + * It's possible to have interrupts off here:
17396 + local_irq_enable();
17398 +#ifdef CONFIG_PAX_PAGEEXEC
17399 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) &&
17400 + (((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) || (!(error_code & (PF_PROT | PF_WRITE)) && ip == address))) {
17402 +#ifdef CONFIG_PAX_EMUTRAMP
17403 + switch (pax_handle_fetch_fault(regs)) {
17409 + pax_report_fault(regs, (void *)ip, (void *)regs->sp);
17410 + do_group_exit(SIGKILL);
17414 +#ifdef CONFIG_PAX_SEGMEXEC
17415 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && !(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address)) {
17417 +#ifdef CONFIG_PAX_EMUTRAMP
17418 + switch (pax_handle_fetch_fault(regs)) {
17424 + pax_report_fault(regs, (void *)ip, (void *)regs->sp);
17425 + do_group_exit(SIGKILL);
17432 /* User mode accesses just cause a SIGSEGV */
17433 if (error_code & PF_USER) {
17434 @@ -849,6 +989,99 @@ static int spurious_fault_check(unsigned
17438 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
17439 +static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
17444 + unsigned char pte_mask;
17446 + if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
17447 + !(mm->pax_flags & MF_PAX_PAGEEXEC))
17450 + /* PaX: it's our fault, let's handle it if we can */
17452 + /* PaX: take a look at read faults before acquiring any locks */
17453 + if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
17454 + /* instruction fetch attempt from a protected page in user mode */
17455 + up_read(&mm->mmap_sem);
17457 +#ifdef CONFIG_PAX_EMUTRAMP
17458 + switch (pax_handle_fetch_fault(regs)) {
17464 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
17465 + do_group_exit(SIGKILL);
17468 + pmd = pax_get_pmd(mm, address);
17469 + if (unlikely(!pmd))
17472 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
17473 + if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
17474 + pte_unmap_unlock(pte, ptl);
17478 + if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
17479 + /* write attempt to a protected page in user mode */
17480 + pte_unmap_unlock(pte, ptl);
17485 + if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
17487 + if (likely(address > get_limit(regs->cs)))
17490 + set_pte(pte, pte_mkread(*pte));
17491 + __flush_tlb_one(address);
17492 + pte_unmap_unlock(pte, ptl);
17493 + up_read(&mm->mmap_sem);
17497 + pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
17500 + * PaX: fill DTLB with user rights and retry
17502 + __asm__ __volatile__ (
17504 +#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
17506 + * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
17507 + * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
17508 + * page fault when examined during a TLB load attempt. this is true not only
17509 + * for PTEs holding a non-present entry but also present entries that will
17510 + * raise a page fault (such as those set up by PaX, or the copy-on-write
17511 + * mechanism). in effect it means that we do *not* need to flush the TLBs
17512 + * for our target pages since their PTEs are simply not in the TLBs at all.
17514 + * the best thing in omitting it is that we gain around 15-20% speed in the
17515 + * fast path of the page fault handler and can get rid of tracing since we
17516 + * can no longer flush unintended entries.
17520 + "testb $0,"__copyuser_seg"(%0)\n"
17523 + : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
17524 + : "memory", "cc");
17525 + pte_unmap_unlock(pte, ptl);
17526 + up_read(&mm->mmap_sem);
17532 * Handle a spurious fault caused by a stale TLB entry.
17534 @@ -921,6 +1154,9 @@ int show_unhandled_signals = 1;
17536 access_error(unsigned long error_code, struct vm_area_struct *vma)
17538 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
17541 if (error_code & PF_WRITE) {
17542 /* write, present and write, not present: */
17543 if (unlikely(!(vma->vm_flags & VM_WRITE)))
17544 @@ -954,19 +1190,33 @@ do_page_fault(struct pt_regs *regs, unsi
17546 struct vm_area_struct *vma;
17547 struct task_struct *tsk;
17548 - unsigned long address;
17549 struct mm_struct *mm;
17551 int write = error_code & PF_WRITE;
17552 unsigned int flags = FAULT_FLAG_ALLOW_RETRY |
17553 (write ? FAULT_FLAG_WRITE : 0);
17555 + /* Get the faulting address: */
17556 + unsigned long address = read_cr2();
17558 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17559 + if (!user_mode(regs) && address < 2 * PAX_USER_SHADOW_BASE) {
17560 + if (!search_exception_tables(regs->ip)) {
17561 + bad_area_nosemaphore(regs, error_code, address);
17564 + if (address < PAX_USER_SHADOW_BASE) {
17565 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
17566 + printk(KERN_ERR "PAX: faulting IP: %pA\n", (void *)regs->ip);
17567 + show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
17569 + address -= PAX_USER_SHADOW_BASE;
17576 - /* Get the faulting address: */
17577 - address = read_cr2();
17580 * Detect and handle instructions that would cause a page fault for
17581 * both a tracked kernel page and a userspace page.
17582 @@ -1026,7 +1276,7 @@ do_page_fault(struct pt_regs *regs, unsi
17583 * User-mode registers count as a user access even for any
17584 * potential system fault or CPU buglet:
17586 - if (user_mode_vm(regs)) {
17587 + if (user_mode(regs)) {
17588 local_irq_enable();
17589 error_code |= PF_USER;
17591 @@ -1081,6 +1331,11 @@ retry:
17595 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
17596 + if (pax_handle_pageexec_fault(regs, mm, address, error_code))
17600 vma = find_vma(mm, address);
17601 if (unlikely(!vma)) {
17602 bad_area(regs, error_code, address);
17603 @@ -1092,18 +1347,24 @@ retry:
17604 bad_area(regs, error_code, address);
17607 - if (error_code & PF_USER) {
17609 - * Accessing the stack below %sp is always a bug.
17610 - * The large cushion allows instructions like enter
17611 - * and pusha to work. ("enter $65535, $31" pushes
17612 - * 32 pointers and then decrements %sp by 65535.)
17614 - if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
17615 - bad_area(regs, error_code, address);
17619 + * Accessing the stack below %sp is always a bug.
17620 + * The large cushion allows instructions like enter
17621 + * and pusha to work. ("enter $65535, $31" pushes
17622 + * 32 pointers and then decrements %sp by 65535.)
17624 + if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
17625 + bad_area(regs, error_code, address);
17629 +#ifdef CONFIG_PAX_SEGMEXEC
17630 + if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
17631 + bad_area(regs, error_code, address);
17636 if (unlikely(expand_stack(vma, address))) {
17637 bad_area(regs, error_code, address);
17639 @@ -1158,3 +1419,199 @@ good_area:
17641 up_read(&mm->mmap_sem);
17644 +#ifdef CONFIG_PAX_EMUTRAMP
17645 +static int pax_handle_fetch_fault_32(struct pt_regs *regs)
17649 + do { /* PaX: gcc trampoline emulation #1 */
17650 + unsigned char mov1, mov2;
17651 + unsigned short jmp;
17652 + unsigned int addr1, addr2;
17654 +#ifdef CONFIG_X86_64
17655 + if ((regs->ip + 11) >> 32)
17659 + err = get_user(mov1, (unsigned char __user *)regs->ip);
17660 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
17661 + err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
17662 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
17663 + err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
17668 + if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
17669 + regs->cx = addr1;
17670 + regs->ax = addr2;
17671 + regs->ip = addr2;
17676 + do { /* PaX: gcc trampoline emulation #2 */
17677 + unsigned char mov, jmp;
17678 + unsigned int addr1, addr2;
17680 +#ifdef CONFIG_X86_64
17681 + if ((regs->ip + 9) >> 32)
17685 + err = get_user(mov, (unsigned char __user *)regs->ip);
17686 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
17687 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
17688 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
17693 + if (mov == 0xB9 && jmp == 0xE9) {
17694 + regs->cx = addr1;
17695 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
17700 + return 1; /* PaX in action */
17703 +#ifdef CONFIG_X86_64
17704 +static int pax_handle_fetch_fault_64(struct pt_regs *regs)
17708 + do { /* PaX: gcc trampoline emulation #1 */
17709 + unsigned short mov1, mov2, jmp1;
17710 + unsigned char jmp2;
17711 + unsigned int addr1;
17712 + unsigned long addr2;
17714 + err = get_user(mov1, (unsigned short __user *)regs->ip);
17715 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
17716 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
17717 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
17718 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
17719 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
17724 + if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
17725 + regs->r11 = addr1;
17726 + regs->r10 = addr2;
17727 + regs->ip = addr1;
17732 + do { /* PaX: gcc trampoline emulation #2 */
17733 + unsigned short mov1, mov2, jmp1;
17734 + unsigned char jmp2;
17735 + unsigned long addr1, addr2;
17737 + err = get_user(mov1, (unsigned short __user *)regs->ip);
17738 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
17739 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
17740 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
17741 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
17742 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
17747 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
17748 + regs->r11 = addr1;
17749 + regs->r10 = addr2;
17750 + regs->ip = addr1;
17755 + return 1; /* PaX in action */
17760 + * PaX: decide what to do with offenders (regs->ip = fault address)
17762 + * returns 1 when task should be killed
17763 + * 2 when gcc trampoline was detected
17765 +static int pax_handle_fetch_fault(struct pt_regs *regs)
17767 + if (v8086_mode(regs))
17770 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
17773 +#ifdef CONFIG_X86_32
17774 + return pax_handle_fetch_fault_32(regs);
17776 + if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
17777 + return pax_handle_fetch_fault_32(regs);
17779 + return pax_handle_fetch_fault_64(regs);
17784 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
17785 +void pax_report_insns(void *pc, void *sp)
17789 + printk(KERN_ERR "PAX: bytes at PC: ");
17790 + for (i = 0; i < 20; i++) {
17792 + if (get_user(c, (__force unsigned char __user *)pc+i))
17793 + printk(KERN_CONT "?? ");
17795 + printk(KERN_CONT "%02x ", c);
17799 + printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
17800 + for (i = -1; i < 80 / (long)sizeof(long); i++) {
17802 + if (get_user(c, (__force unsigned long __user *)sp+i))
17803 +#ifdef CONFIG_X86_32
17804 + printk(KERN_CONT "???????? ");
17806 + printk(KERN_CONT "???????????????? ");
17809 + printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
17816 + * probe_kernel_write(): safely attempt to write to a location
17817 + * @dst: address to write to
17818 + * @src: pointer to the data that shall be written
17819 + * @size: size of the data chunk
17821 + * Safely write to address @dst from the buffer at @src. If a kernel fault
17822 + * happens, handle that and return -EFAULT.
17824 +long notrace probe_kernel_write(void *dst, const void *src, size_t size)
17827 + mm_segment_t old_fs = get_fs();
17829 + set_fs(KERNEL_DS);
17830 + pagefault_disable();
17831 + pax_open_kernel();
17832 + ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
17833 + pax_close_kernel();
17834 + pagefault_enable();
17837 + return ret ? -EFAULT : 0;
17839 diff -urNp linux-2.6.37/arch/x86/mm/gup.c linux-2.6.37/arch/x86/mm/gup.c
17840 --- linux-2.6.37/arch/x86/mm/gup.c 2011-01-04 19:50:19.000000000 -0500
17841 +++ linux-2.6.37/arch/x86/mm/gup.c 2011-01-17 02:41:01.000000000 -0500
17842 @@ -237,7 +237,7 @@ int __get_user_pages_fast(unsigned long
17844 len = (unsigned long) nr_pages << PAGE_SHIFT;
17846 - if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
17847 + if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
17848 (void __user *)start, len)))
17851 diff -urNp linux-2.6.37/arch/x86/mm/highmem_32.c linux-2.6.37/arch/x86/mm/highmem_32.c
17852 --- linux-2.6.37/arch/x86/mm/highmem_32.c 2011-01-04 19:50:19.000000000 -0500
17853 +++ linux-2.6.37/arch/x86/mm/highmem_32.c 2011-01-17 02:41:01.000000000 -0500
17854 @@ -44,7 +44,10 @@ void *kmap_atomic_prot(struct page *page
17855 idx = type + KM_TYPE_NR*smp_processor_id();
17856 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
17857 BUG_ON(!pte_none(*(kmap_pte-idx)));
17859 + pax_open_kernel();
17860 set_pte(kmap_pte-idx, mk_pte(page, prot));
17861 + pax_close_kernel();
17863 return (void *)vaddr;
17865 diff -urNp linux-2.6.37/arch/x86/mm/hugetlbpage.c linux-2.6.37/arch/x86/mm/hugetlbpage.c
17866 --- linux-2.6.37/arch/x86/mm/hugetlbpage.c 2011-01-04 19:50:19.000000000 -0500
17867 +++ linux-2.6.37/arch/x86/mm/hugetlbpage.c 2011-01-17 02:41:01.000000000 -0500
17868 @@ -266,13 +266,20 @@ static unsigned long hugetlb_get_unmappe
17869 struct hstate *h = hstate_file(file);
17870 struct mm_struct *mm = current->mm;
17871 struct vm_area_struct *vma;
17872 - unsigned long start_addr;
17873 + unsigned long start_addr, pax_task_size = TASK_SIZE;
17875 +#ifdef CONFIG_PAX_SEGMEXEC
17876 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
17877 + pax_task_size = SEGMEXEC_TASK_SIZE;
17880 + pax_task_size -= PAGE_SIZE;
17882 if (len > mm->cached_hole_size) {
17883 - start_addr = mm->free_area_cache;
17884 + start_addr = mm->free_area_cache;
17886 - start_addr = TASK_UNMAPPED_BASE;
17887 - mm->cached_hole_size = 0;
17888 + start_addr = mm->mmap_base;
17889 + mm->cached_hole_size = 0;
17893 @@ -280,26 +287,27 @@ full_search:
17895 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
17896 /* At this point: (!vma || addr < vma->vm_end). */
17897 - if (TASK_SIZE - len < addr) {
17898 + if (pax_task_size - len < addr) {
17900 * Start a new search - just in case we missed
17903 - if (start_addr != TASK_UNMAPPED_BASE) {
17904 - start_addr = TASK_UNMAPPED_BASE;
17905 + if (start_addr != mm->mmap_base) {
17906 + start_addr = mm->mmap_base;
17907 mm->cached_hole_size = 0;
17912 - if (!vma || addr + len <= vma->vm_start) {
17913 - mm->free_area_cache = addr + len;
17916 + if (check_heap_stack_gap(vma, addr, len))
17918 if (addr + mm->cached_hole_size < vma->vm_start)
17919 mm->cached_hole_size = vma->vm_start - addr;
17920 addr = ALIGN(vma->vm_end, huge_page_size(h));
17923 + mm->free_area_cache = addr + len;
17927 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
17928 @@ -308,10 +316,9 @@ static unsigned long hugetlb_get_unmappe
17930 struct hstate *h = hstate_file(file);
17931 struct mm_struct *mm = current->mm;
17932 - struct vm_area_struct *vma, *prev_vma;
17933 - unsigned long base = mm->mmap_base, addr = addr0;
17934 + struct vm_area_struct *vma;
17935 + unsigned long base = mm->mmap_base, addr;
17936 unsigned long largest_hole = mm->cached_hole_size;
17937 - int first_time = 1;
17939 /* don't allow allocations above current base */
17940 if (mm->free_area_cache > base)
17941 @@ -321,7 +328,7 @@ static unsigned long hugetlb_get_unmappe
17943 mm->free_area_cache = base;
17947 /* make sure it can fit in the remaining address space */
17948 if (mm->free_area_cache < len)
17950 @@ -329,33 +336,27 @@ try_again:
17951 /* either no address requested or cant fit in requested address hole */
17952 addr = (mm->free_area_cache - len) & huge_page_mask(h);
17954 + vma = find_vma(mm, addr);
17956 * Lookup failure means no vma is above this address,
17957 * i.e. return with success:
17959 - if (!(vma = find_vma_prev(mm, addr, &prev_vma)))
17963 * new region fits between prev_vma->vm_end and
17964 * vma->vm_start, use it:
17966 - if (addr + len <= vma->vm_start &&
17967 - (!prev_vma || (addr >= prev_vma->vm_end))) {
17968 + if (check_heap_stack_gap(vma, addr, len)) {
17969 /* remember the address as a hint for next time */
17970 - mm->cached_hole_size = largest_hole;
17971 - return (mm->free_area_cache = addr);
17973 - /* pull free_area_cache down to the first hole */
17974 - if (mm->free_area_cache == vma->vm_end) {
17975 - mm->free_area_cache = vma->vm_start;
17976 - mm->cached_hole_size = largest_hole;
17978 + mm->cached_hole_size = largest_hole;
17979 + return (mm->free_area_cache = addr);
17981 + /* pull free_area_cache down to the first hole */
17982 + if (mm->free_area_cache == vma->vm_end) {
17983 + mm->free_area_cache = vma->vm_start;
17984 + mm->cached_hole_size = largest_hole;
17987 /* remember the largest hole we saw so far */
17988 if (addr + largest_hole < vma->vm_start)
17989 - largest_hole = vma->vm_start - addr;
17990 + largest_hole = vma->vm_start - addr;
17992 /* try just below the current vma->vm_start */
17993 addr = (vma->vm_start - len) & huge_page_mask(h);
17994 @@ -363,22 +364,26 @@ try_again:
17998 - * if hint left us with no space for the requested
17999 - * mapping then try again:
18001 - if (first_time) {
18002 - mm->free_area_cache = base;
18003 - largest_hole = 0;
18008 * A failed mmap() very likely causes application failure,
18009 * so fall back to the bottom-up function here. This scenario
18010 * can happen with large stack limits and large mmap()
18013 - mm->free_area_cache = TASK_UNMAPPED_BASE;
18015 +#ifdef CONFIG_PAX_SEGMEXEC
18016 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
18017 + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
18021 + mm->mmap_base = TASK_UNMAPPED_BASE;
18023 +#ifdef CONFIG_PAX_RANDMMAP
18024 + if (mm->pax_flags & MF_PAX_RANDMMAP)
18025 + mm->mmap_base += mm->delta_mmap;
18028 + mm->free_area_cache = mm->mmap_base;
18029 mm->cached_hole_size = ~0UL;
18030 addr = hugetlb_get_unmapped_area_bottomup(file, addr0,
18031 len, pgoff, flags);
18032 @@ -386,6 +391,7 @@ fail:
18034 * Restore the topdown base:
18036 + mm->mmap_base = base;
18037 mm->free_area_cache = base;
18038 mm->cached_hole_size = ~0UL;
18040 @@ -399,10 +405,19 @@ hugetlb_get_unmapped_area(struct file *f
18041 struct hstate *h = hstate_file(file);
18042 struct mm_struct *mm = current->mm;
18043 struct vm_area_struct *vma;
18044 + unsigned long pax_task_size = TASK_SIZE;
18046 if (len & ~huge_page_mask(h))
18048 - if (len > TASK_SIZE)
18050 +#ifdef CONFIG_PAX_SEGMEXEC
18051 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
18052 + pax_task_size = SEGMEXEC_TASK_SIZE;
18055 + pax_task_size -= PAGE_SIZE;
18057 + if (len > pax_task_size)
18060 if (flags & MAP_FIXED) {
18061 @@ -414,8 +429,7 @@ hugetlb_get_unmapped_area(struct file *f
18063 addr = ALIGN(addr, huge_page_size(h));
18064 vma = find_vma(mm, addr);
18065 - if (TASK_SIZE - len >= addr &&
18066 - (!vma || addr + len <= vma->vm_start))
18067 + if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
18070 if (mm->get_unmapped_area == arch_get_unmapped_area)
18071 diff -urNp linux-2.6.37/arch/x86/mm/init_32.c linux-2.6.37/arch/x86/mm/init_32.c
18072 --- linux-2.6.37/arch/x86/mm/init_32.c 2011-01-04 19:50:19.000000000 -0500
18073 +++ linux-2.6.37/arch/x86/mm/init_32.c 2011-01-17 02:41:01.000000000 -0500
18074 @@ -73,36 +73,6 @@ static __init void *alloc_low_page(void)
18078 - * Creates a middle page table and puts a pointer to it in the
18079 - * given global directory entry. This only returns the gd entry
18080 - * in non-PAE compilation mode, since the middle layer is folded.
18082 -static pmd_t * __init one_md_table_init(pgd_t *pgd)
18085 - pmd_t *pmd_table;
18087 -#ifdef CONFIG_X86_PAE
18088 - if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
18089 - if (after_bootmem)
18090 - pmd_table = (pmd_t *)alloc_bootmem_pages(PAGE_SIZE);
18092 - pmd_table = (pmd_t *)alloc_low_page();
18093 - paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
18094 - set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
18095 - pud = pud_offset(pgd, 0);
18096 - BUG_ON(pmd_table != pmd_offset(pud, 0));
18098 - return pmd_table;
18101 - pud = pud_offset(pgd, 0);
18102 - pmd_table = pmd_offset(pud, 0);
18104 - return pmd_table;
18108 * Create a page table and place a pointer to it in a middle page
18111 @@ -122,13 +92,28 @@ static pte_t * __init one_page_table_ini
18112 page_table = (pte_t *)alloc_low_page();
18114 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
18115 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
18116 + set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
18118 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
18120 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
18123 return pte_offset_kernel(pmd, 0);
18126 +static pmd_t * __init one_md_table_init(pgd_t *pgd)
18129 + pmd_t *pmd_table;
18131 + pud = pud_offset(pgd, 0);
18132 + pmd_table = pmd_offset(pud, 0);
18134 + return pmd_table;
18137 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
18139 int pgd_idx = pgd_index(vaddr);
18140 @@ -202,6 +187,7 @@ page_table_range_init(unsigned long star
18141 int pgd_idx, pmd_idx;
18142 unsigned long vaddr;
18148 @@ -211,8 +197,13 @@ page_table_range_init(unsigned long star
18149 pgd = pgd_base + pgd_idx;
18151 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
18152 - pmd = one_md_table_init(pgd);
18153 - pmd = pmd + pmd_index(vaddr);
18154 + pud = pud_offset(pgd, vaddr);
18155 + pmd = pmd_offset(pud, vaddr);
18157 +#ifdef CONFIG_X86_PAE
18158 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
18161 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
18162 pmd++, pmd_idx++) {
18163 pte = page_table_kmap_check(one_page_table_init(pmd),
18164 @@ -224,11 +215,20 @@ page_table_range_init(unsigned long star
18168 -static inline int is_kernel_text(unsigned long addr)
18169 +static inline int is_kernel_text(unsigned long start, unsigned long end)
18171 - if (addr >= PAGE_OFFSET && addr <= (unsigned long)__init_end)
18174 + if ((start > ktla_ktva((unsigned long)_etext) ||
18175 + end <= ktla_ktva((unsigned long)_stext)) &&
18176 + (start > ktla_ktva((unsigned long)_einittext) ||
18177 + end <= ktla_ktva((unsigned long)_sinittext)) &&
18179 +#ifdef CONFIG_ACPI_SLEEP
18180 + (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
18183 + (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
18189 @@ -245,9 +245,10 @@ kernel_physical_mapping_init(unsigned lo
18190 unsigned long last_map_addr = end;
18191 unsigned long start_pfn, end_pfn;
18192 pgd_t *pgd_base = swapper_pg_dir;
18193 - int pgd_idx, pmd_idx, pte_ofs;
18194 + unsigned int pgd_idx, pmd_idx, pte_ofs;
18200 unsigned pages_2m, pages_4k;
18201 @@ -280,8 +281,13 @@ repeat:
18203 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
18204 pgd = pgd_base + pgd_idx;
18205 - for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
18206 - pmd = one_md_table_init(pgd);
18207 + for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
18208 + pud = pud_offset(pgd, 0);
18209 + pmd = pmd_offset(pud, 0);
18211 +#ifdef CONFIG_X86_PAE
18212 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
18215 if (pfn >= end_pfn)
18217 @@ -293,14 +299,13 @@ repeat:
18219 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
18220 pmd++, pmd_idx++) {
18221 - unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
18222 + unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
18225 * Map with big pages if possible, otherwise
18226 * create normal page tables:
18229 - unsigned int addr2;
18230 pgprot_t prot = PAGE_KERNEL_LARGE;
18232 * first pass will use the same initial
18233 @@ -310,11 +315,7 @@ repeat:
18234 __pgprot(PTE_IDENT_ATTR |
18237 - addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
18238 - PAGE_OFFSET + PAGE_SIZE-1;
18240 - if (is_kernel_text(addr) ||
18241 - is_kernel_text(addr2))
18242 + if (is_kernel_text(address, address + PMD_SIZE))
18243 prot = PAGE_KERNEL_LARGE_EXEC;
18246 @@ -331,7 +332,7 @@ repeat:
18247 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
18249 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
18250 - pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
18251 + pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
18252 pgprot_t prot = PAGE_KERNEL;
18254 * first pass will use the same initial
18255 @@ -339,7 +340,7 @@ repeat:
18257 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
18259 - if (is_kernel_text(addr))
18260 + if (is_kernel_text(address, address + PAGE_SIZE))
18261 prot = PAGE_KERNEL_EXEC;
18264 @@ -471,7 +472,7 @@ void __init native_pagetable_setup_start
18266 pud = pud_offset(pgd, va);
18267 pmd = pmd_offset(pud, va);
18268 - if (!pmd_present(*pmd))
18269 + if (!pmd_present(*pmd) || pmd_huge(*pmd))
18272 pte = pte_offset_kernel(pmd, va);
18273 @@ -523,12 +524,10 @@ void __init early_ioremap_page_table_ran
18275 static void __init pagetable_init(void)
18277 - pgd_t *pgd_base = swapper_pg_dir;
18279 - permanent_kmaps_init(pgd_base);
18280 + permanent_kmaps_init(swapper_pg_dir);
18283 -pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
18284 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
18285 EXPORT_SYMBOL_GPL(__supported_pte_mask);
18287 /* user-defined highmem size */
18288 @@ -753,6 +752,12 @@ void __init mem_init(void)
18292 +#ifdef CONFIG_PAX_PER_CPU_PGD
18293 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
18294 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
18295 + KERNEL_PGD_PTRS);
18298 #ifdef CONFIG_FLATMEM
18301 @@ -770,7 +775,7 @@ void __init mem_init(void)
18302 set_highmem_pages_init();
18304 codesize = (unsigned long) &_etext - (unsigned long) &_text;
18305 - datasize = (unsigned long) &_edata - (unsigned long) &_etext;
18306 + datasize = (unsigned long) &_edata - (unsigned long) &_sdata;
18307 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
18309 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
18310 @@ -811,10 +816,10 @@ void __init mem_init(void)
18311 ((unsigned long)&__init_end -
18312 (unsigned long)&__init_begin) >> 10,
18314 - (unsigned long)&_etext, (unsigned long)&_edata,
18315 - ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
18316 + (unsigned long)&_sdata, (unsigned long)&_edata,
18317 + ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
18319 - (unsigned long)&_text, (unsigned long)&_etext,
18320 + ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
18321 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
18324 @@ -892,6 +897,7 @@ void set_kernel_text_rw(void)
18325 if (!kernel_set_to_readonly)
18328 + start = ktla_ktva(start);
18329 pr_debug("Set kernel text: %lx - %lx for read write\n",
18330 start, start+size);
18332 @@ -906,6 +912,7 @@ void set_kernel_text_ro(void)
18333 if (!kernel_set_to_readonly)
18336 + start = ktla_ktva(start);
18337 pr_debug("Set kernel text: %lx - %lx for read only\n",
18338 start, start+size);
18340 @@ -917,6 +924,7 @@ void mark_rodata_ro(void)
18341 unsigned long start = PFN_ALIGN(_text);
18342 unsigned long size = PFN_ALIGN(_etext) - start;
18344 + start = ktla_ktva(start);
18345 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
18346 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
18348 diff -urNp linux-2.6.37/arch/x86/mm/init_64.c linux-2.6.37/arch/x86/mm/init_64.c
18349 --- linux-2.6.37/arch/x86/mm/init_64.c 2011-01-04 19:50:19.000000000 -0500
18350 +++ linux-2.6.37/arch/x86/mm/init_64.c 2011-01-17 02:41:01.000000000 -0500
18351 @@ -72,7 +72,7 @@ early_param("gbpages", parse_direct_gbpa
18352 * around without checking the pgd every time.
18355 -pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
18356 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
18357 EXPORT_SYMBOL_GPL(__supported_pte_mask);
18359 int force_personality32;
18360 @@ -106,12 +106,22 @@ void sync_global_pgds(unsigned long star
18361 for (address = start; address <= end; address += PGDIR_SIZE) {
18362 const pgd_t *pgd_ref = pgd_offset_k(address);
18363 unsigned long flags;
18365 +#ifdef CONFIG_PAX_PER_CPU_PGD
18366 + unsigned long cpu;
18371 if (pgd_none(*pgd_ref))
18374 spin_lock_irqsave(&pgd_lock, flags);
18376 +#ifdef CONFIG_PAX_PER_CPU_PGD
18377 + for (cpu = 0; cpu < NR_CPUS; ++cpu) {
18378 + pgd_t *pgd = pgd_offset_cpu(cpu, address);
18380 list_for_each_entry(page, &pgd_list, lru) {
18382 spinlock_t *pgt_lock;
18383 @@ -119,6 +129,7 @@ void sync_global_pgds(unsigned long star
18384 pgd = (pgd_t *)page_address(page) + pgd_index(address);
18385 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
18386 spin_lock(pgt_lock);
18389 if (pgd_none(*pgd))
18390 set_pgd(pgd, *pgd_ref);
18391 @@ -126,7 +137,10 @@ void sync_global_pgds(unsigned long star
18392 BUG_ON(pgd_page_vaddr(*pgd)
18393 != pgd_page_vaddr(*pgd_ref));
18395 +#ifndef CONFIG_PAX_PER_CPU_PGD
18396 spin_unlock(pgt_lock);
18400 spin_unlock_irqrestore(&pgd_lock, flags);
18402 @@ -200,7 +214,9 @@ void set_pte_vaddr_pud(pud_t *pud_page,
18403 pmd = fill_pmd(pud, vaddr);
18404 pte = fill_pte(pmd, vaddr);
18406 + pax_open_kernel();
18407 set_pte(pte, new_pte);
18408 + pax_close_kernel();
18411 * It's enough to flush this one mapping.
18412 @@ -259,14 +275,12 @@ static void __init __init_extra_mapping(
18413 pgd = pgd_offset_k((unsigned long)__va(phys));
18414 if (pgd_none(*pgd)) {
18415 pud = (pud_t *) spp_getpage();
18416 - set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
18418 + set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
18420 pud = pud_offset(pgd, (unsigned long)__va(phys));
18421 if (pud_none(*pud)) {
18422 pmd = (pmd_t *) spp_getpage();
18423 - set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
18425 + set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
18427 pmd = pmd_offset(pud, phys);
18428 BUG_ON(!pmd_none(*pmd));
18429 @@ -706,6 +720,12 @@ void __init mem_init(void)
18433 +#ifdef CONFIG_PAX_PER_CPU_PGD
18434 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
18435 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
18436 + KERNEL_PGD_PTRS);
18439 /* clear_bss() already clear the empty_zero_page */
18442 @@ -866,8 +886,8 @@ int kern_addr_valid(unsigned long addr)
18443 static struct vm_area_struct gate_vma = {
18444 .vm_start = VSYSCALL_START,
18445 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
18446 - .vm_page_prot = PAGE_READONLY_EXEC,
18447 - .vm_flags = VM_READ | VM_EXEC
18448 + .vm_page_prot = PAGE_READONLY,
18449 + .vm_flags = VM_READ
18452 struct vm_area_struct *get_gate_vma(struct task_struct *tsk)
18453 @@ -901,7 +921,7 @@ int in_gate_area_no_task(unsigned long a
18455 const char *arch_vma_name(struct vm_area_struct *vma)
18457 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
18458 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
18460 if (vma == &gate_vma)
18461 return "[vsyscall]";
18462 diff -urNp linux-2.6.37/arch/x86/mm/init.c linux-2.6.37/arch/x86/mm/init.c
18463 --- linux-2.6.37/arch/x86/mm/init.c 2011-01-04 19:50:19.000000000 -0500
18464 +++ linux-2.6.37/arch/x86/mm/init.c 2011-01-17 02:41:01.000000000 -0500
18465 @@ -72,11 +72,7 @@ static void __init find_early_table_spac
18466 * cause a hotspot and fill up ZONE_DMA. The page tables
18467 * need roughly 0.5KB per GB.
18469 -#ifdef CONFIG_X86_32
18474 + start = 0x100000;
18475 base = memblock_find_in_range(start, max_pfn_mapped<<PAGE_SHIFT,
18476 tables, PAGE_SIZE);
18477 if (base == MEMBLOCK_ERROR)
18478 @@ -323,7 +319,13 @@ unsigned long __init_refok init_memory_m
18480 int devmem_is_allowed(unsigned long pagenr)
18482 - if (pagenr <= 256)
18485 +#ifdef CONFIG_VM86
18486 + if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
18489 + if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
18491 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
18493 @@ -382,6 +384,86 @@ void free_init_pages(char *what, unsigne
18495 void free_initmem(void)
18498 +#ifdef CONFIG_PAX_KERNEXEC
18499 +#ifdef CONFIG_X86_32
18500 + /* PaX: limit KERNEL_CS to actual size */
18501 + unsigned long addr, limit;
18502 + struct desc_struct d;
18505 + limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
18506 + limit = (limit - 1UL) >> PAGE_SHIFT;
18508 + memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
18509 + for (cpu = 0; cpu < NR_CPUS; cpu++) {
18510 + pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
18511 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
18514 + /* PaX: make KERNEL_CS read-only */
18515 + addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
18516 + if (!paravirt_enabled())
18517 + set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
18519 + for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
18520 + pgd = pgd_offset_k(addr);
18521 + pud = pud_offset(pgd, addr);
18522 + pmd = pmd_offset(pud, addr);
18523 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
18526 +#ifdef CONFIG_X86_PAE
18527 + set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
18529 + for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
18530 + pgd = pgd_offset_k(addr);
18531 + pud = pud_offset(pgd, addr);
18532 + pmd = pmd_offset(pud, addr);
18533 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
18538 +#ifdef CONFIG_MODULES
18539 + set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
18546 + unsigned long addr, end;
18548 + /* PaX: make kernel code/rodata read-only, rest non-executable */
18549 + for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
18550 + pgd = pgd_offset_k(addr);
18551 + pud = pud_offset(pgd, addr);
18552 + pmd = pmd_offset(pud, addr);
18553 + if (!pmd_present(*pmd))
18555 + if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
18556 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
18558 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
18561 + addr = (unsigned long)__va(__pa(__START_KERNEL_map));
18562 + end = addr + KERNEL_IMAGE_SIZE;
18563 + for (; addr < end; addr += PMD_SIZE) {
18564 + pgd = pgd_offset_k(addr);
18565 + pud = pud_offset(pgd, addr);
18566 + pmd = pmd_offset(pud, addr);
18567 + if (!pmd_present(*pmd))
18569 + if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
18570 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
18577 free_init_pages("unused kernel memory",
18578 (unsigned long)(&__init_begin),
18579 (unsigned long)(&__init_end));
18580 diff -urNp linux-2.6.37/arch/x86/mm/iomap_32.c linux-2.6.37/arch/x86/mm/iomap_32.c
18581 --- linux-2.6.37/arch/x86/mm/iomap_32.c 2011-01-04 19:50:19.000000000 -0500
18582 +++ linux-2.6.37/arch/x86/mm/iomap_32.c 2011-01-17 02:41:01.000000000 -0500
18583 @@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long
18584 type = kmap_atomic_idx_push();
18585 idx = type + KM_TYPE_NR * smp_processor_id();
18586 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
18588 + pax_open_kernel();
18589 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
18590 + pax_close_kernel();
18592 arch_flush_lazy_mmu_mode();
18594 return (void *)vaddr;
18595 diff -urNp linux-2.6.37/arch/x86/mm/ioremap.c linux-2.6.37/arch/x86/mm/ioremap.c
18596 --- linux-2.6.37/arch/x86/mm/ioremap.c 2011-01-04 19:50:19.000000000 -0500
18597 +++ linux-2.6.37/arch/x86/mm/ioremap.c 2011-01-17 02:41:01.000000000 -0500
18598 @@ -104,7 +104,7 @@ static void __iomem *__ioremap_caller(re
18599 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
18600 int is_ram = page_is_ram(pfn);
18602 - if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
18603 + if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
18605 WARN_ON_ONCE(is_ram);
18607 @@ -344,7 +344,7 @@ static int __init early_ioremap_debug_se
18608 early_param("early_ioremap_debug", early_ioremap_debug_setup);
18610 static __initdata int after_paging_init;
18611 -static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
18612 +static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
18614 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
18616 @@ -381,8 +381,7 @@ void __init early_ioremap_init(void)
18617 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
18619 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
18620 - memset(bm_pte, 0, sizeof(bm_pte));
18621 - pmd_populate_kernel(&init_mm, pmd, bm_pte);
18622 + pmd_populate_user(&init_mm, pmd, bm_pte);
18625 * The boot-ioremap range spans multiple pmds, for which
18626 diff -urNp linux-2.6.37/arch/x86/mm/kmemcheck/kmemcheck.c linux-2.6.37/arch/x86/mm/kmemcheck/kmemcheck.c
18627 --- linux-2.6.37/arch/x86/mm/kmemcheck/kmemcheck.c 2011-01-04 19:50:19.000000000 -0500
18628 +++ linux-2.6.37/arch/x86/mm/kmemcheck/kmemcheck.c 2011-01-17 02:41:01.000000000 -0500
18629 @@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *reg
18630 * memory (e.g. tracked pages)? For now, we need this to avoid
18631 * invoking kmemcheck for PnP BIOS calls.
18633 - if (regs->flags & X86_VM_MASK)
18634 + if (v8086_mode(regs))
18636 - if (regs->cs != __KERNEL_CS)
18637 + if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
18640 pte = kmemcheck_pte_lookup(address);
18641 diff -urNp linux-2.6.37/arch/x86/mm/mmap.c linux-2.6.37/arch/x86/mm/mmap.c
18642 --- linux-2.6.37/arch/x86/mm/mmap.c 2011-01-04 19:50:19.000000000 -0500
18643 +++ linux-2.6.37/arch/x86/mm/mmap.c 2011-01-17 02:41:01.000000000 -0500
18644 @@ -49,7 +49,7 @@ static unsigned int stack_maxrandom_size
18645 * Leave an at least ~128 MB hole with possible stack randomization.
18647 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
18648 -#define MAX_GAP (TASK_SIZE/6*5)
18649 +#define MAX_GAP (pax_task_size/6*5)
18652 * True on X86_32 or when emulating IA32 on X86_64
18653 @@ -94,27 +94,40 @@ static unsigned long mmap_rnd(void)
18654 return rnd << PAGE_SHIFT;
18657 -static unsigned long mmap_base(void)
18658 +static unsigned long mmap_base(struct mm_struct *mm)
18660 unsigned long gap = rlimit(RLIMIT_STACK);
18661 + unsigned long pax_task_size = TASK_SIZE;
18663 +#ifdef CONFIG_PAX_SEGMEXEC
18664 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
18665 + pax_task_size = SEGMEXEC_TASK_SIZE;
18670 else if (gap > MAX_GAP)
18673 - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
18674 + return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
18678 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
18679 * does, but not when emulating X86_32
18681 -static unsigned long mmap_legacy_base(void)
18682 +static unsigned long mmap_legacy_base(struct mm_struct *mm)
18684 - if (mmap_is_ia32())
18685 + if (mmap_is_ia32()) {
18687 +#ifdef CONFIG_PAX_SEGMEXEC
18688 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
18689 + return SEGMEXEC_TASK_UNMAPPED_BASE;
18693 return TASK_UNMAPPED_BASE;
18696 return TASK_UNMAPPED_BASE + mmap_rnd();
18699 @@ -125,11 +138,23 @@ static unsigned long mmap_legacy_base(vo
18700 void arch_pick_mmap_layout(struct mm_struct *mm)
18702 if (mmap_is_legacy()) {
18703 - mm->mmap_base = mmap_legacy_base();
18704 + mm->mmap_base = mmap_legacy_base(mm);
18706 +#ifdef CONFIG_PAX_RANDMMAP
18707 + if (mm->pax_flags & MF_PAX_RANDMMAP)
18708 + mm->mmap_base += mm->delta_mmap;
18711 mm->get_unmapped_area = arch_get_unmapped_area;
18712 mm->unmap_area = arch_unmap_area;
18714 - mm->mmap_base = mmap_base();
18715 + mm->mmap_base = mmap_base(mm);
18717 +#ifdef CONFIG_PAX_RANDMMAP
18718 + if (mm->pax_flags & MF_PAX_RANDMMAP)
18719 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
18722 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
18723 mm->unmap_area = arch_unmap_area_topdown;
18725 diff -urNp linux-2.6.37/arch/x86/mm/numa_32.c linux-2.6.37/arch/x86/mm/numa_32.c
18726 --- linux-2.6.37/arch/x86/mm/numa_32.c 2011-01-04 19:50:19.000000000 -0500
18727 +++ linux-2.6.37/arch/x86/mm/numa_32.c 2011-01-17 02:41:01.000000000 -0500
18728 @@ -99,7 +99,6 @@ unsigned long node_memmap_size_bytes(int
18732 -extern unsigned long find_max_low_pfn(void);
18733 extern unsigned long highend_pfn, highstart_pfn;
18735 #define LARGE_PAGE_BYTES (PTRS_PER_PTE * PAGE_SIZE)
18736 diff -urNp linux-2.6.37/arch/x86/mm/pageattr.c linux-2.6.37/arch/x86/mm/pageattr.c
18737 --- linux-2.6.37/arch/x86/mm/pageattr.c 2011-01-04 19:50:19.000000000 -0500
18738 +++ linux-2.6.37/arch/x86/mm/pageattr.c 2011-01-17 02:41:01.000000000 -0500
18739 @@ -261,16 +261,17 @@ static inline pgprot_t static_protection
18740 * PCI BIOS based config access (CONFIG_PCI_GOBIOS) support.
18742 if (within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
18743 - pgprot_val(forbidden) |= _PAGE_NX;
18744 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
18747 * The kernel text needs to be executable for obvious reasons
18748 * Does not cover __inittext since that is gone later on. On
18749 * 64bit we do not enforce !NX on the low mapping
18751 - if (within(address, (unsigned long)_text, (unsigned long)_etext))
18752 - pgprot_val(forbidden) |= _PAGE_NX;
18753 + if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
18754 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
18756 +#ifdef CONFIG_DEBUG_RODATA
18758 * The .rodata section needs to be read-only. Using the pfn
18759 * catches all aliases.
18760 @@ -278,6 +279,7 @@ static inline pgprot_t static_protection
18761 if (within(pfn, __pa((unsigned long)__start_rodata) >> PAGE_SHIFT,
18762 __pa((unsigned long)__end_rodata) >> PAGE_SHIFT))
18763 pgprot_val(forbidden) |= _PAGE_RW;
18766 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
18768 @@ -316,6 +318,13 @@ static inline pgprot_t static_protection
18772 +#ifdef CONFIG_PAX_KERNEXEC
18773 + if (within(pfn, __pa((unsigned long)&_text), __pa((unsigned long)&_sdata))) {
18774 + pgprot_val(forbidden) |= _PAGE_RW;
18775 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
18779 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
18782 @@ -368,23 +377,37 @@ EXPORT_SYMBOL_GPL(lookup_address);
18783 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
18785 /* change init_mm */
18786 + pax_open_kernel();
18787 set_pte_atomic(kpte, pte);
18789 #ifdef CONFIG_X86_32
18790 if (!SHARED_KERNEL_PMD) {
18792 +#ifdef CONFIG_PAX_PER_CPU_PGD
18793 + unsigned long cpu;
18798 +#ifdef CONFIG_PAX_PER_CPU_PGD
18799 + for (cpu = 0; cpu < NR_CPUS; ++cpu) {
18800 + pgd_t *pgd = get_cpu_pgd(cpu);
18802 list_for_each_entry(page, &pgd_list, lru) {
18804 + pgd_t *pgd = (pgd_t *)page_address(page);
18810 - pgd = (pgd_t *)page_address(page) + pgd_index(address);
18811 + pgd += pgd_index(address);
18812 pud = pud_offset(pgd, address);
18813 pmd = pmd_offset(pud, address);
18814 set_pte_atomic((pte_t *)pmd, pte);
18818 + pax_close_kernel();
18822 diff -urNp linux-2.6.37/arch/x86/mm/pageattr-test.c linux-2.6.37/arch/x86/mm/pageattr-test.c
18823 --- linux-2.6.37/arch/x86/mm/pageattr-test.c 2011-01-04 19:50:19.000000000 -0500
18824 +++ linux-2.6.37/arch/x86/mm/pageattr-test.c 2011-01-17 02:41:01.000000000 -0500
18825 @@ -36,7 +36,7 @@ enum {
18827 static int pte_testbit(pte_t pte)
18829 - return pte_flags(pte) & _PAGE_UNUSED1;
18830 + return pte_flags(pte) & _PAGE_CPA_TEST;
18833 struct split_state {
18834 diff -urNp linux-2.6.37/arch/x86/mm/pat.c linux-2.6.37/arch/x86/mm/pat.c
18835 --- linux-2.6.37/arch/x86/mm/pat.c 2011-01-04 19:50:19.000000000 -0500
18836 +++ linux-2.6.37/arch/x86/mm/pat.c 2011-01-17 02:41:01.000000000 -0500
18837 @@ -361,7 +361,7 @@ int free_memtype(u64 start, u64 end)
18840 printk(KERN_INFO "%s:%d freeing invalid memtype %Lx-%Lx\n",
18841 - current->comm, current->pid, start, end);
18842 + current->comm, task_pid_nr(current), start, end);
18846 @@ -492,8 +492,8 @@ static inline int range_is_allowed(unsig
18847 while (cursor < to) {
18848 if (!devmem_is_allowed(pfn)) {
18850 - "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
18851 - current->comm, from, to);
18852 + "Program %s tried to access /dev/mem between %Lx->%Lx (%Lx).\n",
18853 + current->comm, from, to, cursor);
18856 cursor += PAGE_SIZE;
18857 @@ -557,7 +557,7 @@ int kernel_map_sync_memtype(u64 base, un
18859 "%s:%d ioremap_change_attr failed %s "
18861 - current->comm, current->pid,
18862 + current->comm, task_pid_nr(current),
18864 base, (unsigned long long)(base + size));
18866 @@ -593,7 +593,7 @@ static int reserve_pfn_range(u64 paddr,
18867 if (want_flags != flags) {
18868 printk(KERN_WARNING
18869 "%s:%d map pfn RAM range req %s for %Lx-%Lx, got %s\n",
18870 - current->comm, current->pid,
18871 + current->comm, task_pid_nr(current),
18872 cattr_name(want_flags),
18873 (unsigned long long)paddr,
18874 (unsigned long long)(paddr + size),
18875 @@ -615,7 +615,7 @@ static int reserve_pfn_range(u64 paddr,
18876 free_memtype(paddr, paddr + size);
18877 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
18878 " for %Lx-%Lx, got %s\n",
18879 - current->comm, current->pid,
18880 + current->comm, task_pid_nr(current),
18881 cattr_name(want_flags),
18882 (unsigned long long)paddr,
18883 (unsigned long long)(paddr + size),
18884 diff -urNp linux-2.6.37/arch/x86/mm/pgtable_32.c linux-2.6.37/arch/x86/mm/pgtable_32.c
18885 --- linux-2.6.37/arch/x86/mm/pgtable_32.c 2011-01-04 19:50:19.000000000 -0500
18886 +++ linux-2.6.37/arch/x86/mm/pgtable_32.c 2011-01-17 02:41:01.000000000 -0500
18887 @@ -48,10 +48,13 @@ void set_pte_vaddr(unsigned long vaddr,
18890 pte = pte_offset_kernel(pmd, vaddr);
18892 + pax_open_kernel();
18893 if (pte_val(pteval))
18894 set_pte_at(&init_mm, vaddr, pte, pteval);
18896 pte_clear(&init_mm, vaddr, pte);
18897 + pax_close_kernel();
18900 * It's enough to flush this one mapping.
18901 diff -urNp linux-2.6.37/arch/x86/mm/pgtable.c linux-2.6.37/arch/x86/mm/pgtable.c
18902 --- linux-2.6.37/arch/x86/mm/pgtable.c 2011-01-04 19:50:19.000000000 -0500
18903 +++ linux-2.6.37/arch/x86/mm/pgtable.c 2011-01-17 02:41:01.000000000 -0500
18904 @@ -84,9 +84,58 @@ static inline void pgd_list_del(pgd_t *p
18905 list_del(&page->lru);
18908 -#define UNSHARED_PTRS_PER_PGD \
18909 - (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
18910 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18911 +pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
18913 +void __shadow_user_pgds(pgd_t *dst, const pgd_t *src, int count)
18916 + *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
18920 +#ifdef CONFIG_PAX_PER_CPU_PGD
18921 +void __clone_user_pgds(pgd_t *dst, const pgd_t *src, int count)
18925 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18926 + *dst++ = __pgd(pgd_val(*src++) & clone_pgd_mask);
18934 +#ifdef CONFIG_PAX_PER_CPU_PGD
18935 +static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
18936 +static inline void pgd_dtor(pgd_t *pgd) {}
18937 +#ifdef CONFIG_X86_64
18938 +#define pxd_t pud_t
18939 +#define pyd_t pgd_t
18940 +#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
18941 +#define pxd_free(mm, pud) pud_free((mm), (pud))
18942 +#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
18943 +#define pyd_offset(mm ,address) pgd_offset((mm), (address))
18944 +#define PYD_SIZE PGDIR_SIZE
18946 +#define pxd_t pmd_t
18947 +#define pyd_t pud_t
18948 +#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
18949 +#define pxd_free(mm, pud) pmd_free((mm), (pud))
18950 +#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
18951 +#define pyd_offset(mm ,address) pud_offset((mm), (address))
18952 +#define PYD_SIZE PUD_SIZE
18955 +#define pxd_t pmd_t
18956 +#define pyd_t pud_t
18957 +#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
18958 +#define pxd_free(mm, pmd) pmd_free((mm), (pmd))
18959 +#define pyd_populate(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
18960 +#define pyd_offset(mm ,address) pud_offset((mm), (address))
18961 +#define PYD_SIZE PUD_SIZE
18963 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
18965 @@ -130,6 +179,7 @@ static void pgd_dtor(pgd_t *pgd)
18967 spin_unlock_irqrestore(&pgd_lock, flags);
18972 * List of all pgd's needed for non-PAE so it can invalidate entries
18973 @@ -142,7 +192,7 @@ static void pgd_dtor(pgd_t *pgd)
18977 -#ifdef CONFIG_X86_PAE
18978 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
18980 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
18981 * updating the top-level pagetable entries to guarantee the
18982 @@ -154,7 +204,7 @@ static void pgd_dtor(pgd_t *pgd)
18983 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
18984 * and initialize the kernel pmds here.
18986 -#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
18987 +#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
18989 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
18991 @@ -173,36 +223,38 @@ void pud_populate(struct mm_struct *mm,
18992 if (mm == current->active_mm)
18993 write_cr3(read_cr3());
18995 +#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
18996 +#define PREALLOCATED_PXDS USER_PGD_PTRS
18997 #else /* !CONFIG_X86_PAE */
18999 /* No need to prepopulate any pagetable entries in non-PAE modes. */
19000 -#define PREALLOCATED_PMDS 0
19001 +#define PREALLOCATED_PXDS 0
19003 #endif /* CONFIG_X86_PAE */
19005 -static void free_pmds(pmd_t *pmds[])
19006 +static void free_pxds(pxd_t *pxds[])
19010 - for(i = 0; i < PREALLOCATED_PMDS; i++)
19012 - free_page((unsigned long)pmds[i]);
19013 + for(i = 0; i < PREALLOCATED_PXDS; i++)
19015 + free_page((unsigned long)pxds[i]);
19018 -static int preallocate_pmds(pmd_t *pmds[])
19019 +static int preallocate_pxds(pxd_t *pxds[])
19022 bool failed = false;
19024 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
19025 - pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
19027 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
19028 + pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
19041 @@ -215,51 +267,56 @@ static int preallocate_pmds(pmd_t *pmds[
19042 * preallocate which never got a corresponding vma will need to be
19045 -static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
19046 +static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
19050 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
19051 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
19052 pgd_t pgd = pgdp[i];
19054 if (pgd_val(pgd) != 0) {
19055 - pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
19056 + pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
19058 - pgdp[i] = native_make_pgd(0);
19059 + set_pgd(pgdp + i, native_make_pgd(0));
19061 - paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
19062 - pmd_free(mm, pmd);
19063 + paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
19064 + pxd_free(mm, pxd);
19069 -static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
19070 +static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
19074 unsigned long addr;
19077 - if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
19078 + if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
19081 - pud = pud_offset(pgd, 0);
19082 +#ifdef CONFIG_X86_64
19083 + pyd = pyd_offset(mm, 0L);
19085 + pyd = pyd_offset(pgd, 0L);
19088 - for (addr = i = 0; i < PREALLOCATED_PMDS;
19089 - i++, pud++, addr += PUD_SIZE) {
19090 - pmd_t *pmd = pmds[i];
19091 + for (addr = i = 0; i < PREALLOCATED_PXDS;
19092 + i++, pyd++, addr += PYD_SIZE) {
19093 + pxd_t *pxd = pxds[i];
19095 if (i >= KERNEL_PGD_BOUNDARY)
19096 - memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
19097 - sizeof(pmd_t) * PTRS_PER_PMD);
19098 + memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
19099 + sizeof(pxd_t) * PTRS_PER_PMD);
19101 - pud_populate(mm, pud, pmd);
19102 + pyd_populate(mm, pyd, pxd);
19106 pgd_t *pgd_alloc(struct mm_struct *mm)
19109 - pmd_t *pmds[PREALLOCATED_PMDS];
19110 + pxd_t *pxds[PREALLOCATED_PXDS];
19112 unsigned long flags;
19114 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
19115 @@ -269,11 +326,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
19119 - if (preallocate_pmds(pmds) != 0)
19120 + if (preallocate_pxds(pxds) != 0)
19123 if (paravirt_pgd_alloc(mm) != 0)
19124 - goto out_free_pmds;
19125 + goto out_free_pxds;
19128 * Make sure that pre-populating the pmds is atomic with
19129 @@ -283,14 +340,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
19130 spin_lock_irqsave(&pgd_lock, flags);
19133 - pgd_prepopulate_pmd(mm, pgd, pmds);
19134 + pgd_prepopulate_pxd(mm, pgd, pxds);
19136 spin_unlock_irqrestore(&pgd_lock, flags);
19145 free_page((unsigned long)pgd);
19147 @@ -299,7 +356,7 @@ out:
19149 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
19151 - pgd_mop_up_pmds(mm, pgd);
19152 + pgd_mop_up_pxds(mm, pgd);
19154 paravirt_pgd_free(mm, pgd);
19155 free_page((unsigned long)pgd);
19156 diff -urNp linux-2.6.37/arch/x86/mm/setup_nx.c linux-2.6.37/arch/x86/mm/setup_nx.c
19157 --- linux-2.6.37/arch/x86/mm/setup_nx.c 2011-01-04 19:50:19.000000000 -0500
19158 +++ linux-2.6.37/arch/x86/mm/setup_nx.c 2011-01-17 02:41:01.000000000 -0500
19160 #include <asm/pgtable.h>
19161 #include <asm/proto.h>
19163 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
19164 static int disable_nx __cpuinitdata;
19166 +#ifndef CONFIG_PAX_PAGEEXEC
19170 @@ -28,12 +30,17 @@ static int __init noexec_setup(char *str
19173 early_param("noexec", noexec_setup);
19178 void __cpuinit x86_configure_nx(void)
19180 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
19181 if (cpu_has_nx && !disable_nx)
19182 __supported_pte_mask |= _PAGE_NX;
19185 __supported_pte_mask &= ~_PAGE_NX;
19188 diff -urNp linux-2.6.37/arch/x86/mm/tlb.c linux-2.6.37/arch/x86/mm/tlb.c
19189 --- linux-2.6.37/arch/x86/mm/tlb.c 2011-01-04 19:50:19.000000000 -0500
19190 +++ linux-2.6.37/arch/x86/mm/tlb.c 2011-01-17 02:41:01.000000000 -0500
19192 #include <asm/uv/uv.h>
19194 DEFINE_PER_CPU_SHARED_ALIGNED(struct tlb_state, cpu_tlbstate)
19195 - = { &init_mm, 0, };
19196 + = { &init_mm, 0 };
19199 * Smarter SMP flushing macros.
19200 @@ -65,7 +65,11 @@ void leave_mm(int cpu)
19202 cpumask_clear_cpu(cpu,
19203 mm_cpumask(percpu_read(cpu_tlbstate.active_mm)));
19205 +#ifndef CONFIG_PAX_PER_CPU_PGD
19206 load_cr3(swapper_pg_dir);
19210 EXPORT_SYMBOL_GPL(leave_mm);
19212 diff -urNp linux-2.6.37/arch/x86/oprofile/backtrace.c linux-2.6.37/arch/x86/oprofile/backtrace.c
19213 --- linux-2.6.37/arch/x86/oprofile/backtrace.c 2011-01-04 19:50:19.000000000 -0500
19214 +++ linux-2.6.37/arch/x86/oprofile/backtrace.c 2011-01-17 02:41:01.000000000 -0500
19215 @@ -57,7 +57,7 @@ dump_user_backtrace_32(struct stack_fram
19216 struct stack_frame_ia32 *fp;
19218 /* Also check accessibility of one struct frame_head beyond */
19219 - if (!access_ok(VERIFY_READ, head, sizeof(bufhead)))
19220 + if (!__access_ok(VERIFY_READ, head, sizeof(bufhead)))
19222 if (__copy_from_user_inatomic(bufhead, head, sizeof(bufhead)))
19224 @@ -123,7 +123,7 @@ x86_backtrace(struct pt_regs * const reg
19226 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
19228 - if (!user_mode_vm(regs)) {
19229 + if (!user_mode(regs)) {
19230 unsigned long stack = kernel_stack_pointer(regs);
19232 dump_trace(NULL, regs, (unsigned long *)stack, 0,
19233 diff -urNp linux-2.6.37/arch/x86/oprofile/op_model_p4.c linux-2.6.37/arch/x86/oprofile/op_model_p4.c
19234 --- linux-2.6.37/arch/x86/oprofile/op_model_p4.c 2011-01-04 19:50:19.000000000 -0500
19235 +++ linux-2.6.37/arch/x86/oprofile/op_model_p4.c 2011-01-17 02:41:01.000000000 -0500
19236 @@ -50,7 +50,7 @@ static inline void setup_num_counters(vo
19240 -static int inline addr_increment(void)
19241 +static inline int addr_increment(void)
19244 return smp_num_siblings == 2 ? 2 : 1;
19245 diff -urNp linux-2.6.37/arch/x86/pci/common.c linux-2.6.37/arch/x86/pci/common.c
19246 --- linux-2.6.37/arch/x86/pci/common.c 2011-01-04 19:50:19.000000000 -0500
19247 +++ linux-2.6.37/arch/x86/pci/common.c 2011-01-17 02:41:01.000000000 -0500
19248 @@ -32,8 +32,8 @@ int noioapicreroute = 1;
19249 int pcibios_last_bus = -1;
19250 unsigned long pirq_table_addr;
19251 struct pci_bus *pci_root_bus;
19252 -struct pci_raw_ops *raw_pci_ops;
19253 -struct pci_raw_ops *raw_pci_ext_ops;
19254 +const struct pci_raw_ops *raw_pci_ops;
19255 +const struct pci_raw_ops *raw_pci_ext_ops;
19257 int raw_pci_read(unsigned int domain, unsigned int bus, unsigned int devfn,
19258 int reg, int len, u32 *val)
19259 @@ -382,7 +382,7 @@ static const struct dmi_system_id __devi
19260 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant DL585 G2"),
19264 + { NULL, NULL, {DMI_MATCH(DMI_NONE, {0})}, NULL}
19267 void __init dmi_check_pciprobe(void)
19268 diff -urNp linux-2.6.37/arch/x86/pci/direct.c linux-2.6.37/arch/x86/pci/direct.c
19269 --- linux-2.6.37/arch/x86/pci/direct.c 2011-01-04 19:50:19.000000000 -0500
19270 +++ linux-2.6.37/arch/x86/pci/direct.c 2011-01-17 02:41:01.000000000 -0500
19271 @@ -79,7 +79,7 @@ static int pci_conf1_write(unsigned int
19273 #undef PCI_CONF1_ADDRESS
19275 -struct pci_raw_ops pci_direct_conf1 = {
19276 +const struct pci_raw_ops pci_direct_conf1 = {
19277 .read = pci_conf1_read,
19278 .write = pci_conf1_write,
19280 @@ -173,7 +173,7 @@ static int pci_conf2_write(unsigned int
19282 #undef PCI_CONF2_ADDRESS
19284 -struct pci_raw_ops pci_direct_conf2 = {
19285 +const struct pci_raw_ops pci_direct_conf2 = {
19286 .read = pci_conf2_read,
19287 .write = pci_conf2_write,
19289 @@ -189,7 +189,7 @@ struct pci_raw_ops pci_direct_conf2 = {
19290 * This should be close to trivial, but it isn't, because there are buggy
19291 * chipsets (yes, you guessed it, by Intel and Compaq) that have no class ID.
19293 -static int __init pci_sanity_check(struct pci_raw_ops *o)
19294 +static int __init pci_sanity_check(const struct pci_raw_ops *o)
19298 diff -urNp linux-2.6.37/arch/x86/pci/fixup.c linux-2.6.37/arch/x86/pci/fixup.c
19299 --- linux-2.6.37/arch/x86/pci/fixup.c 2011-01-04 19:50:19.000000000 -0500
19300 +++ linux-2.6.37/arch/x86/pci/fixup.c 2011-01-17 02:41:01.000000000 -0500
19301 @@ -364,7 +364,7 @@ static const struct dmi_system_id __devi
19302 DMI_MATCH(DMI_PRODUCT_NAME, "MS-6702E"),
19306 + { NULL, NULL, {DMI_MATCH(DMI_NONE, {0})}, NULL }
19310 @@ -435,7 +435,7 @@ static const struct dmi_system_id __devi
19311 DMI_MATCH(DMI_PRODUCT_VERSION, "PSA40U"),
19315 + { NULL, NULL, {DMI_MATCH(DMI_NONE, {0})}, NULL }
19318 static void __devinit pci_pre_fixup_toshiba_ohci1394(struct pci_dev *dev)
19319 diff -urNp linux-2.6.37/arch/x86/pci/irq.c linux-2.6.37/arch/x86/pci/irq.c
19320 --- linux-2.6.37/arch/x86/pci/irq.c 2011-01-04 19:50:19.000000000 -0500
19321 +++ linux-2.6.37/arch/x86/pci/irq.c 2011-01-17 02:41:01.000000000 -0500
19322 @@ -542,7 +542,7 @@ static __init int intel_router_probe(str
19323 static struct pci_device_id __initdata pirq_440gx[] = {
19324 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443GX_0) },
19325 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443GX_2) },
19327 + { PCI_DEVICE(0, 0) }
19330 /* 440GX has a proprietary PIRQ router -- don't use it */
19331 @@ -1114,7 +1114,7 @@ static struct dmi_system_id __initdata p
19332 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 360"),
19336 + { NULL, NULL, {DMI_MATCH(DMI_NONE, {0})}, NULL }
19339 void __init pcibios_irq_init(void)
19340 diff -urNp linux-2.6.37/arch/x86/pci/mmconfig_32.c linux-2.6.37/arch/x86/pci/mmconfig_32.c
19341 --- linux-2.6.37/arch/x86/pci/mmconfig_32.c 2011-01-04 19:50:19.000000000 -0500
19342 +++ linux-2.6.37/arch/x86/pci/mmconfig_32.c 2011-01-17 02:41:01.000000000 -0500
19343 @@ -117,7 +117,7 @@ static int pci_mmcfg_write(unsigned int
19347 -static struct pci_raw_ops pci_mmcfg = {
19348 +static const struct pci_raw_ops pci_mmcfg = {
19349 .read = pci_mmcfg_read,
19350 .write = pci_mmcfg_write,
19352 diff -urNp linux-2.6.37/arch/x86/pci/mmconfig_64.c linux-2.6.37/arch/x86/pci/mmconfig_64.c
19353 --- linux-2.6.37/arch/x86/pci/mmconfig_64.c 2011-01-04 19:50:19.000000000 -0500
19354 +++ linux-2.6.37/arch/x86/pci/mmconfig_64.c 2011-01-17 02:41:01.000000000 -0500
19355 @@ -81,7 +81,7 @@ static int pci_mmcfg_write(unsigned int
19359 -static struct pci_raw_ops pci_mmcfg = {
19360 +static const struct pci_raw_ops pci_mmcfg = {
19361 .read = pci_mmcfg_read,
19362 .write = pci_mmcfg_write,
19364 diff -urNp linux-2.6.37/arch/x86/pci/numaq_32.c linux-2.6.37/arch/x86/pci/numaq_32.c
19365 --- linux-2.6.37/arch/x86/pci/numaq_32.c 2011-01-04 19:50:19.000000000 -0500
19366 +++ linux-2.6.37/arch/x86/pci/numaq_32.c 2011-01-17 02:41:01.000000000 -0500
19367 @@ -108,7 +108,7 @@ static int pci_conf1_mq_write(unsigned i
19369 #undef PCI_CONF1_MQ_ADDRESS
19371 -static struct pci_raw_ops pci_direct_conf1_mq = {
19372 +static const struct pci_raw_ops pci_direct_conf1_mq = {
19373 .read = pci_conf1_mq_read,
19374 .write = pci_conf1_mq_write
19376 diff -urNp linux-2.6.37/arch/x86/pci/olpc.c linux-2.6.37/arch/x86/pci/olpc.c
19377 --- linux-2.6.37/arch/x86/pci/olpc.c 2011-01-04 19:50:19.000000000 -0500
19378 +++ linux-2.6.37/arch/x86/pci/olpc.c 2011-01-17 02:41:01.000000000 -0500
19379 @@ -297,7 +297,7 @@ static int pci_olpc_write(unsigned int s
19383 -static struct pci_raw_ops pci_olpc_conf = {
19384 +static const struct pci_raw_ops pci_olpc_conf = {
19385 .read = pci_olpc_read,
19386 .write = pci_olpc_write,
19388 diff -urNp linux-2.6.37/arch/x86/pci/pcbios.c linux-2.6.37/arch/x86/pci/pcbios.c
19389 --- linux-2.6.37/arch/x86/pci/pcbios.c 2011-01-04 19:50:19.000000000 -0500
19390 +++ linux-2.6.37/arch/x86/pci/pcbios.c 2011-01-17 02:41:01.000000000 -0500
19391 @@ -57,50 +57,93 @@ union bios32 {
19393 unsigned long address;
19394 unsigned short segment;
19395 -} bios32_indirect = { 0, __KERNEL_CS };
19396 +} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
19399 * Returns the entry point for the given service, NULL on error
19402 -static unsigned long bios32_service(unsigned long service)
19403 +static unsigned long __devinit bios32_service(unsigned long service)
19405 unsigned char return_code; /* %al */
19406 unsigned long address; /* %ebx */
19407 unsigned long length; /* %ecx */
19408 unsigned long entry; /* %edx */
19409 unsigned long flags;
19410 + struct desc_struct d, *gdt;
19412 local_irq_save(flags);
19413 - __asm__("lcall *(%%edi); cld"
19415 + gdt = get_cpu_gdt_table(smp_processor_id());
19417 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
19418 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
19419 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
19420 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
19422 + __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
19423 : "=a" (return_code),
19429 - "D" (&bios32_indirect));
19430 + "D" (&bios32_indirect),
19431 + "r"(__PCIBIOS_DS)
19434 + pax_open_kernel();
19435 + gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
19436 + gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
19437 + gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
19438 + gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
19439 + pax_close_kernel();
19441 local_irq_restore(flags);
19443 switch (return_code) {
19445 - return address + entry;
19446 - case 0x80: /* Not present */
19447 - printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
19449 - default: /* Shouldn't happen */
19450 - printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
19451 - service, return_code);
19454 + unsigned char flags;
19456 + printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
19457 + if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
19458 + printk(KERN_WARNING "bios32_service: not valid\n");
19461 + address = address + PAGE_OFFSET;
19462 + length += 16UL; /* some BIOSs underreport this... */
19464 + if (length >= 64*1024*1024) {
19465 + length >>= PAGE_SHIFT;
19469 + for (cpu = 0; cpu < NR_CPUS; cpu++) {
19470 + gdt = get_cpu_gdt_table(cpu);
19471 + pack_descriptor(&d, address, length, 0x9b, flags);
19472 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
19473 + pack_descriptor(&d, address, length, 0x93, flags);
19474 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
19478 + case 0x80: /* Not present */
19479 + printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
19481 + default: /* Shouldn't happen */
19482 + printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
19483 + service, return_code);
19489 unsigned long address;
19490 unsigned short segment;
19491 -} pci_indirect = { 0, __KERNEL_CS };
19492 +} pci_indirect __read_only = { 0, __PCIBIOS_CS };
19494 -static int pci_bios_present;
19495 +static int pci_bios_present __read_only;
19497 static int __devinit check_pcibios(void)
19499 @@ -109,11 +152,13 @@ static int __devinit check_pcibios(void)
19500 unsigned long flags, pcibios_entry;
19502 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
19503 - pci_indirect.address = pcibios_entry + PAGE_OFFSET;
19504 + pci_indirect.address = pcibios_entry;
19506 local_irq_save(flags);
19508 - "lcall *(%%edi); cld\n\t"
19509 + __asm__("movw %w6, %%ds\n\t"
19510 + "lcall *%%ss:(%%edi); cld\n\t"
19516 @@ -122,7 +167,8 @@ static int __devinit check_pcibios(void)
19519 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
19520 - "D" (&pci_indirect)
19521 + "D" (&pci_indirect),
19522 + "r" (__PCIBIOS_DS)
19524 local_irq_restore(flags);
19526 @@ -166,7 +212,10 @@ static int pci_bios_read(unsigned int se
19530 - __asm__("lcall *(%%esi); cld\n\t"
19531 + __asm__("movw %w6, %%ds\n\t"
19532 + "lcall *%%ss:(%%esi); cld\n\t"
19538 @@ -175,7 +224,8 @@ static int pci_bios_read(unsigned int se
19539 : "1" (PCIBIOS_READ_CONFIG_BYTE),
19542 - "S" (&pci_indirect));
19543 + "S" (&pci_indirect),
19544 + "r" (__PCIBIOS_DS));
19546 * Zero-extend the result beyond 8 bits, do not trust the
19547 * BIOS having done it:
19548 @@ -183,7 +233,10 @@ static int pci_bios_read(unsigned int se
19552 - __asm__("lcall *(%%esi); cld\n\t"
19553 + __asm__("movw %w6, %%ds\n\t"
19554 + "lcall *%%ss:(%%esi); cld\n\t"
19560 @@ -192,7 +245,8 @@ static int pci_bios_read(unsigned int se
19561 : "1" (PCIBIOS_READ_CONFIG_WORD),
19564 - "S" (&pci_indirect));
19565 + "S" (&pci_indirect),
19566 + "r" (__PCIBIOS_DS));
19568 * Zero-extend the result beyond 16 bits, do not trust the
19569 * BIOS having done it:
19570 @@ -200,7 +254,10 @@ static int pci_bios_read(unsigned int se
19574 - __asm__("lcall *(%%esi); cld\n\t"
19575 + __asm__("movw %w6, %%ds\n\t"
19576 + "lcall *%%ss:(%%esi); cld\n\t"
19582 @@ -209,7 +266,8 @@ static int pci_bios_read(unsigned int se
19583 : "1" (PCIBIOS_READ_CONFIG_DWORD),
19586 - "S" (&pci_indirect));
19587 + "S" (&pci_indirect),
19588 + "r" (__PCIBIOS_DS));
19592 @@ -232,7 +290,10 @@ static int pci_bios_write(unsigned int s
19596 - __asm__("lcall *(%%esi); cld\n\t"
19597 + __asm__("movw %w6, %%ds\n\t"
19598 + "lcall *%%ss:(%%esi); cld\n\t"
19604 @@ -241,10 +302,14 @@ static int pci_bios_write(unsigned int s
19608 - "S" (&pci_indirect));
19609 + "S" (&pci_indirect),
19610 + "r" (__PCIBIOS_DS));
19613 - __asm__("lcall *(%%esi); cld\n\t"
19614 + __asm__("movw %w6, %%ds\n\t"
19615 + "lcall *%%ss:(%%esi); cld\n\t"
19621 @@ -253,10 +318,14 @@ static int pci_bios_write(unsigned int s
19625 - "S" (&pci_indirect));
19626 + "S" (&pci_indirect),
19627 + "r" (__PCIBIOS_DS));
19630 - __asm__("lcall *(%%esi); cld\n\t"
19631 + __asm__("movw %w6, %%ds\n\t"
19632 + "lcall *%%ss:(%%esi); cld\n\t"
19638 @@ -265,7 +334,8 @@ static int pci_bios_write(unsigned int s
19642 - "S" (&pci_indirect));
19643 + "S" (&pci_indirect),
19644 + "r" (__PCIBIOS_DS));
19648 @@ -279,7 +349,7 @@ static int pci_bios_write(unsigned int s
19649 * Function table for BIOS32 access
19652 -static struct pci_raw_ops pci_bios_access = {
19653 +static const struct pci_raw_ops pci_bios_access = {
19654 .read = pci_bios_read,
19655 .write = pci_bios_write
19657 @@ -288,7 +358,7 @@ static struct pci_raw_ops pci_bios_acces
19658 * Try to find PCI BIOS.
19661 -static struct pci_raw_ops * __devinit pci_find_bios(void)
19662 +static const struct pci_raw_ops * __devinit pci_find_bios(void)
19664 union bios32 *check;
19666 @@ -369,10 +439,13 @@ struct irq_routing_table * pcibios_get_i
19668 DBG("PCI: Fetching IRQ routing table... ");
19669 __asm__("push %%es\n\t"
19670 + "movw %w8, %%ds\n\t"
19673 - "lcall *(%%esi); cld\n\t"
19674 + "lcall *%%ss:(%%esi); cld\n\t"
19681 @@ -383,7 +456,8 @@ struct irq_routing_table * pcibios_get_i
19684 "S" (&pci_indirect),
19687 + "r" (__PCIBIOS_DS)
19689 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
19691 @@ -407,7 +481,10 @@ int pcibios_set_irq_routing(struct pci_d
19695 - __asm__("lcall *(%%esi); cld\n\t"
19696 + __asm__("movw %w5, %%ds\n\t"
19697 + "lcall *%%ss:(%%esi); cld\n\t"
19703 @@ -415,7 +492,8 @@ int pcibios_set_irq_routing(struct pci_d
19704 : "0" (PCIBIOS_SET_PCI_HW_INT),
19705 "b" ((dev->bus->number << 8) | dev->devfn),
19706 "c" ((irq << 8) | (pin + 10)),
19707 - "S" (&pci_indirect));
19708 + "S" (&pci_indirect),
19709 + "r" (__PCIBIOS_DS));
19710 return !(ret & 0xff00);
19712 EXPORT_SYMBOL(pcibios_set_irq_routing);
19713 diff -urNp linux-2.6.37/arch/x86/platform/efi/efi_32.c linux-2.6.37/arch/x86/platform/efi/efi_32.c
19714 --- linux-2.6.37/arch/x86/platform/efi/efi_32.c 2011-01-04 19:50:19.000000000 -0500
19715 +++ linux-2.6.37/arch/x86/platform/efi/efi_32.c 2011-01-17 02:41:01.000000000 -0500
19716 @@ -38,70 +38,37 @@
19719 static unsigned long efi_rt_eflags;
19720 -static pgd_t efi_bak_pg_dir_pointer[2];
19721 +static pgd_t __initdata efi_bak_pg_dir_pointer[KERNEL_PGD_PTRS];
19723 -void efi_call_phys_prelog(void)
19724 +void __init efi_call_phys_prelog(void)
19726 - unsigned long cr4;
19727 - unsigned long temp;
19728 struct desc_ptr gdt_descr;
19730 local_irq_save(efi_rt_eflags);
19733 - * If I don't have PAE, I should just duplicate two entries in page
19734 - * directory. If I have PAE, I just need to duplicate one entry in
19735 - * page directory.
19737 - cr4 = read_cr4_safe();
19739 - if (cr4 & X86_CR4_PAE) {
19740 - efi_bak_pg_dir_pointer[0].pgd =
19741 - swapper_pg_dir[pgd_index(0)].pgd;
19742 - swapper_pg_dir[0].pgd =
19743 - swapper_pg_dir[pgd_index(PAGE_OFFSET)].pgd;
19745 - efi_bak_pg_dir_pointer[0].pgd =
19746 - swapper_pg_dir[pgd_index(0)].pgd;
19747 - efi_bak_pg_dir_pointer[1].pgd =
19748 - swapper_pg_dir[pgd_index(0x400000)].pgd;
19749 - swapper_pg_dir[pgd_index(0)].pgd =
19750 - swapper_pg_dir[pgd_index(PAGE_OFFSET)].pgd;
19751 - temp = PAGE_OFFSET + 0x400000;
19752 - swapper_pg_dir[pgd_index(0x400000)].pgd =
19753 - swapper_pg_dir[pgd_index(temp)].pgd;
19755 + clone_pgd_range(efi_bak_pg_dir_pointer, swapper_pg_dir, KERNEL_PGD_PTRS);
19756 + clone_pgd_range(swapper_pg_dir, swapper_pg_dir + KERNEL_PGD_BOUNDARY,
19757 + min_t(unsigned long, KERNEL_PGD_PTRS, KERNEL_PGD_BOUNDARY));
19760 * After the lock is released, the original page table is restored.
19764 - gdt_descr.address = __pa(get_cpu_gdt_table(0));
19765 + gdt_descr.address = (struct desc_struct *)__pa(get_cpu_gdt_table(0));
19766 gdt_descr.size = GDT_SIZE - 1;
19767 load_gdt(&gdt_descr);
19770 -void efi_call_phys_epilog(void)
19771 +void __init efi_call_phys_epilog(void)
19773 - unsigned long cr4;
19774 struct desc_ptr gdt_descr;
19776 - gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
19777 + gdt_descr.address = get_cpu_gdt_table(0);
19778 gdt_descr.size = GDT_SIZE - 1;
19779 load_gdt(&gdt_descr);
19781 - cr4 = read_cr4_safe();
19783 - if (cr4 & X86_CR4_PAE) {
19784 - swapper_pg_dir[pgd_index(0)].pgd =
19785 - efi_bak_pg_dir_pointer[0].pgd;
19787 - swapper_pg_dir[pgd_index(0)].pgd =
19788 - efi_bak_pg_dir_pointer[0].pgd;
19789 - swapper_pg_dir[pgd_index(0x400000)].pgd =
19790 - efi_bak_pg_dir_pointer[1].pgd;
19792 + clone_pgd_range(swapper_pg_dir, efi_bak_pg_dir_pointer, KERNEL_PGD_PTRS);
19795 * After the lock is released, the original page table is restored.
19796 diff -urNp linux-2.6.37/arch/x86/platform/efi/efi_stub_32.S linux-2.6.37/arch/x86/platform/efi/efi_stub_32.S
19797 --- linux-2.6.37/arch/x86/platform/efi/efi_stub_32.S 2011-01-04 19:50:19.000000000 -0500
19798 +++ linux-2.6.37/arch/x86/platform/efi/efi_stub_32.S 2011-01-17 02:41:01.000000000 -0500
19802 #include <linux/linkage.h>
19803 +#include <linux/init.h>
19804 #include <asm/page_types.h>
19808 * service functions will comply with gcc calling convention, too.
19813 ENTRY(efi_call_phys)
19815 * 0. The function can only be called in Linux kernel. So CS has been
19816 @@ -36,9 +37,7 @@ ENTRY(efi_call_phys)
19817 * The mapping of lower virtual memory has been created in prelog and
19821 - subl $__PAGE_OFFSET, %edx
19823 + jmp 1f-__PAGE_OFFSET
19827 @@ -47,14 +46,8 @@ ENTRY(efi_call_phys)
19828 * parameter 2, ..., param n. To make things easy, we save the return
19829 * address of efi_call_phys in a global variable.
19832 - movl %edx, saved_return_addr
19833 - /* get the function pointer into ECX*/
19835 - movl %ecx, efi_rt_function_ptr
19837 - subl $__PAGE_OFFSET, %edx
19839 + popl (saved_return_addr)
19840 + popl (efi_rt_function_ptr)
19843 * 3. Clear PG bit in %CR0.
19844 @@ -73,9 +66,8 @@ ENTRY(efi_call_phys)
19846 * 5. Call the physical function.
19849 + call *(efi_rt_function_ptr-__PAGE_OFFSET)
19853 * 6. After EFI runtime service returns, control will return to
19854 * following instruction. We'd better readjust stack pointer first.
19855 @@ -88,35 +80,28 @@ ENTRY(efi_call_phys)
19857 orl $0x80000000, %edx
19863 * 8. Now restore the virtual mode from flat mode by
19864 * adding EIP with PAGE_OFFSET.
19868 + jmp 1f+__PAGE_OFFSET
19872 * 9. Balance the stack. And because EAX contain the return value,
19873 * we'd better not clobber it.
19875 - leal efi_rt_function_ptr, %edx
19876 - movl (%edx), %ecx
19878 + pushl (efi_rt_function_ptr)
19881 - * 10. Push the saved return address onto the stack and return.
19882 + * 10. Return to the saved return address.
19884 - leal saved_return_addr, %edx
19885 - movl (%edx), %ecx
19888 + jmpl *(saved_return_addr)
19889 ENDPROC(efi_call_phys)
19896 efi_rt_function_ptr:
19897 diff -urNp linux-2.6.37/arch/x86/power/cpu.c linux-2.6.37/arch/x86/power/cpu.c
19898 --- linux-2.6.37/arch/x86/power/cpu.c 2011-01-04 19:50:19.000000000 -0500
19899 +++ linux-2.6.37/arch/x86/power/cpu.c 2011-01-17 02:41:01.000000000 -0500
19900 @@ -130,7 +130,7 @@ static void do_fpu_end(void)
19901 static void fix_processor_context(void)
19903 int cpu = smp_processor_id();
19904 - struct tss_struct *t = &per_cpu(init_tss, cpu);
19905 + struct tss_struct *t = init_tss + cpu;
19907 set_tss_desc(cpu, t); /*
19908 * This just modifies memory; should not be
19909 @@ -140,7 +140,9 @@ static void fix_processor_context(void)
19912 #ifdef CONFIG_X86_64
19913 + pax_open_kernel();
19914 get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
19915 + pax_close_kernel();
19917 syscall_init(); /* This sets MSR_*STAR and related */
19919 diff -urNp linux-2.6.37/arch/x86/vdso/Makefile linux-2.6.37/arch/x86/vdso/Makefile
19920 --- linux-2.6.37/arch/x86/vdso/Makefile 2011-01-04 19:50:19.000000000 -0500
19921 +++ linux-2.6.37/arch/x86/vdso/Makefile 2011-01-17 02:41:01.000000000 -0500
19922 @@ -123,7 +123,7 @@ quiet_cmd_vdso = VDSO $@
19923 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
19924 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
19926 -VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
19927 +VDSO_LDFLAGS = -fPIC -shared --no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
19931 diff -urNp linux-2.6.37/arch/x86/vdso/vclock_gettime.c linux-2.6.37/arch/x86/vdso/vclock_gettime.c
19932 --- linux-2.6.37/arch/x86/vdso/vclock_gettime.c 2011-01-04 19:50:19.000000000 -0500
19933 +++ linux-2.6.37/arch/x86/vdso/vclock_gettime.c 2011-01-17 02:41:01.000000000 -0500
19934 @@ -22,24 +22,48 @@
19935 #include <asm/hpet.h>
19936 #include <asm/unistd.h>
19937 #include <asm/io.h>
19938 +#include <asm/fixmap.h>
19939 #include "vextern.h"
19941 #define gtod vdso_vsyscall_gtod_data
19943 +notrace noinline long __vdso_fallback_time(long *t)
19946 + asm volatile("syscall"
19948 + : "0" (__NR_time),"D" (t) : "r11", "cx", "memory");
19952 notrace static long vdso_fallback_gettime(long clock, struct timespec *ts)
19955 asm("syscall" : "=a" (ret) :
19956 - "0" (__NR_clock_gettime),"D" (clock), "S" (ts) : "memory");
19957 + "0" (__NR_clock_gettime),"D" (clock), "S" (ts) : "r11", "cx", "memory");
19961 +notrace static inline cycle_t __vdso_vread_hpet(void)
19963 + return readl((const void __iomem *)fix_to_virt(VSYSCALL_HPET) + 0xf0);
19966 +notrace static inline cycle_t __vdso_vread_tsc(void)
19968 + cycle_t ret = (cycle_t)vget_cycles();
19970 + return ret >= gtod->clock.cycle_last ? ret : gtod->clock.cycle_last;
19973 notrace static inline long vgetns(void)
19976 - cycles_t (*vread)(void);
19977 - vread = gtod->clock.vread;
19978 - v = (vread() - gtod->clock.cycle_last) & gtod->clock.mask;
19979 + if (gtod->clock.name[0] == 't' && gtod->clock.name[1] == 's' && gtod->clock.name[2] == 'c' && !gtod->clock.name[3])
19980 + v = __vdso_vread_tsc();
19982 + v = __vdso_vread_hpet();
19983 + v = (v - gtod->clock.cycle_last) & gtod->clock.mask;
19984 return (v * gtod->clock.mult) >> gtod->clock.shift;
19987 @@ -113,7 +137,9 @@ notrace static noinline int do_monotonic
19989 notrace int __vdso_clock_gettime(clockid_t clock, struct timespec *ts)
19991 - if (likely(gtod->sysctl_enabled))
19992 + if (likely(gtod->sysctl_enabled &&
19993 + ((gtod->clock.name[0] == 'h' && gtod->clock.name[1] == 'p' && gtod->clock.name[2] == 'e' && gtod->clock.name[3] == 't' && !gtod->clock.name[4]) ||
19994 + (gtod->clock.name[0] == 't' && gtod->clock.name[1] == 's' && gtod->clock.name[2] == 'c' && !gtod->clock.name[3]))))
19996 case CLOCK_REALTIME:
19997 if (likely(gtod->clock.vread))
19998 @@ -133,10 +159,20 @@ notrace int __vdso_clock_gettime(clockid
19999 int clock_gettime(clockid_t, struct timespec *)
20000 __attribute__((weak, alias("__vdso_clock_gettime")));
20002 -notrace int __vdso_gettimeofday(struct timeval *tv, struct timezone *tz)
20003 +notrace noinline int __vdso_fallback_gettimeofday(struct timeval *tv, struct timezone *tz)
20006 - if (likely(gtod->sysctl_enabled && gtod->clock.vread)) {
20007 + asm("syscall" : "=a" (ret) :
20008 + "0" (__NR_gettimeofday), "D" (tv), "S" (tz) : "r11", "cx", "memory");
20012 +notrace int __vdso_gettimeofday(struct timeval *tv, struct timezone *tz)
20014 + if (likely(gtod->sysctl_enabled &&
20015 + ((gtod->clock.name[0] == 'h' && gtod->clock.name[1] == 'p' && gtod->clock.name[2] == 'e' && gtod->clock.name[3] == 't' && !gtod->clock.name[4]) ||
20016 + (gtod->clock.name[0] == 't' && gtod->clock.name[1] == 's' && gtod->clock.name[2] == 'c' && !gtod->clock.name[3]))))
20018 if (likely(tv != NULL)) {
20019 BUILD_BUG_ON(offsetof(struct timeval, tv_usec) !=
20020 offsetof(struct timespec, tv_nsec) ||
20021 @@ -151,9 +187,7 @@ notrace int __vdso_gettimeofday(struct t
20025 - asm("syscall" : "=a" (ret) :
20026 - "0" (__NR_gettimeofday), "D" (tv), "S" (tz) : "memory");
20028 + return __vdso_fallback_gettimeofday(tv, tz);
20030 int gettimeofday(struct timeval *, struct timezone *)
20031 __attribute__((weak, alias("__vdso_gettimeofday")));
20032 diff -urNp linux-2.6.37/arch/x86/vdso/vdso32-setup.c linux-2.6.37/arch/x86/vdso/vdso32-setup.c
20033 --- linux-2.6.37/arch/x86/vdso/vdso32-setup.c 2011-01-04 19:50:19.000000000 -0500
20034 +++ linux-2.6.37/arch/x86/vdso/vdso32-setup.c 2011-01-17 02:41:01.000000000 -0500
20036 #include <asm/tlbflush.h>
20037 #include <asm/vdso.h>
20038 #include <asm/proto.h>
20039 +#include <asm/mman.h>
20043 @@ -226,7 +227,7 @@ static inline void map_compat_vdso(int m
20044 void enable_sep_cpu(void)
20046 int cpu = get_cpu();
20047 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
20048 + struct tss_struct *tss = init_tss + cpu;
20050 if (!boot_cpu_has(X86_FEATURE_SEP)) {
20052 @@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
20053 gate_vma.vm_start = FIXADDR_USER_START;
20054 gate_vma.vm_end = FIXADDR_USER_END;
20055 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
20056 - gate_vma.vm_page_prot = __P101;
20057 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
20059 * Make sure the vDSO gets into every core dump.
20060 * Dumping its contents makes post-mortem fully interpretable later
20061 @@ -331,14 +332,14 @@ int arch_setup_additional_pages(struct l
20063 addr = VDSO_HIGH_BASE;
20065 - addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
20066 + addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
20067 if (IS_ERR_VALUE(addr)) {
20073 - current->mm->context.vdso = (void *)addr;
20074 + current->mm->context.vdso = addr;
20076 if (compat_uses_vma || !compat) {
20078 @@ -361,11 +362,11 @@ int arch_setup_additional_pages(struct l
20081 current_thread_info()->sysenter_return =
20082 - VDSO32_SYMBOL(addr, SYSENTER_RETURN);
20083 + (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
20087 - current->mm->context.vdso = NULL;
20088 + current->mm->context.vdso = 0;
20090 up_write(&mm->mmap_sem);
20092 @@ -412,8 +413,14 @@ __initcall(ia32_binfmt_init);
20094 const char *arch_vma_name(struct vm_area_struct *vma)
20096 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
20097 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
20100 +#ifdef CONFIG_PAX_SEGMEXEC
20101 + if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
20108 @@ -422,7 +429,7 @@ struct vm_area_struct *get_gate_vma(stru
20109 struct mm_struct *mm = tsk->mm;
20111 /* Check to see if this task was created in compat vdso mode */
20112 - if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
20113 + if (mm && mm->context.vdso == VDSO_HIGH_BASE)
20117 diff -urNp linux-2.6.37/arch/x86/vdso/vdso.lds.S linux-2.6.37/arch/x86/vdso/vdso.lds.S
20118 --- linux-2.6.37/arch/x86/vdso/vdso.lds.S 2011-01-04 19:50:19.000000000 -0500
20119 +++ linux-2.6.37/arch/x86/vdso/vdso.lds.S 2011-01-17 02:41:01.000000000 -0500
20120 @@ -35,3 +35,9 @@ VDSO64_PRELINK = VDSO_PRELINK;
20121 #define VEXTERN(x) VDSO64_ ## x = vdso_ ## x;
20122 #include "vextern.h"
20125 +#define VEXTERN(x) VDSO64_ ## x = __vdso_ ## x;
20126 +VEXTERN(fallback_gettimeofday)
20127 +VEXTERN(fallback_time)
20130 diff -urNp linux-2.6.37/arch/x86/vdso/vextern.h linux-2.6.37/arch/x86/vdso/vextern.h
20131 --- linux-2.6.37/arch/x86/vdso/vextern.h 2011-01-04 19:50:19.000000000 -0500
20132 +++ linux-2.6.37/arch/x86/vdso/vextern.h 2011-01-17 02:41:01.000000000 -0500
20134 put into vextern.h and be referenced as a pointer with vdso prefix.
20135 The main kernel later fills in the values. */
20138 VEXTERN(vgetcpu_mode)
20139 VEXTERN(vsyscall_gtod_data)
20140 diff -urNp linux-2.6.37/arch/x86/vdso/vma.c linux-2.6.37/arch/x86/vdso/vma.c
20141 --- linux-2.6.37/arch/x86/vdso/vma.c 2011-01-04 19:50:19.000000000 -0500
20142 +++ linux-2.6.37/arch/x86/vdso/vma.c 2011-01-17 02:41:01.000000000 -0500
20143 @@ -58,7 +58,7 @@ static int __init init_vdso_vars(void)
20147 - if (memcmp(vbase, "\177ELF", 4)) {
20148 + if (memcmp(vbase, ELFMAG, SELFMAG)) {
20149 printk("VDSO: I'm broken; not ELF\n");
20152 @@ -118,7 +118,7 @@ int arch_setup_additional_pages(struct l
20156 - current->mm->context.vdso = (void *)addr;
20157 + current->mm->context.vdso = addr;
20159 ret = install_special_mapping(mm, addr, vdso_size,
20161 @@ -126,7 +126,7 @@ int arch_setup_additional_pages(struct l
20165 - current->mm->context.vdso = NULL;
20166 + current->mm->context.vdso = 0;
20170 @@ -134,10 +134,3 @@ up_fail:
20171 up_write(&mm->mmap_sem);
20175 -static __init int vdso_setup(char *s)
20177 - vdso_enabled = simple_strtoul(s, NULL, 0);
20180 -__setup("vdso=", vdso_setup);
20181 diff -urNp linux-2.6.37/arch/x86/xen/enlighten.c linux-2.6.37/arch/x86/xen/enlighten.c
20182 --- linux-2.6.37/arch/x86/xen/enlighten.c 2011-01-04 19:50:19.000000000 -0500
20183 +++ linux-2.6.37/arch/x86/xen/enlighten.c 2011-01-17 02:41:01.000000000 -0500
20184 @@ -85,8 +85,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
20186 struct shared_info xen_dummy_shared_info;
20188 -void *xen_initial_gdt;
20190 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
20191 __read_mostly int xen_have_vector_callback;
20192 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
20193 @@ -574,7 +572,7 @@ static void xen_write_idt_entry(gate_des
20197 - start = __get_cpu_var(idt_desc).address;
20198 + start = (unsigned long)__get_cpu_var(idt_desc).address;
20199 end = start + __get_cpu_var(idt_desc).size + 1;
20202 @@ -1134,7 +1132,17 @@ asmlinkage void __init xen_start_kernel(
20203 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
20205 /* Work out if we support NX */
20206 - x86_configure_nx();
20207 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
20208 + if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
20209 + (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
20212 + __supported_pte_mask |= _PAGE_NX;
20213 + rdmsr(MSR_EFER, l, h);
20215 + wrmsr(MSR_EFER, l, h);
20219 xen_setup_features();
20221 @@ -1165,13 +1173,6 @@ asmlinkage void __init xen_start_kernel(
20223 machine_ops = xen_machine_ops;
20226 - * The only reliable way to retain the initial address of the
20227 - * percpu gdt_page is to remember it here, so we can go and
20228 - * mark it RW later, when the initial percpu area is freed.
20230 - xen_initial_gdt = &per_cpu(gdt_page, 0);
20234 pgd = (pgd_t *)xen_start_info->pt_base;
20235 diff -urNp linux-2.6.37/arch/x86/xen/mmu.c linux-2.6.37/arch/x86/xen/mmu.c
20236 --- linux-2.6.37/arch/x86/xen/mmu.c 2011-01-04 19:50:19.000000000 -0500
20237 +++ linux-2.6.37/arch/x86/xen/mmu.c 2011-01-17 02:41:01.000000000 -0500
20238 @@ -2084,6 +2084,8 @@ __init pgd_t *xen_setup_kernel_pagetable
20239 convert_pfn_mfn(init_level4_pgt);
20240 convert_pfn_mfn(level3_ident_pgt);
20241 convert_pfn_mfn(level3_kernel_pgt);
20242 + convert_pfn_mfn(level3_vmalloc_pgt);
20243 + convert_pfn_mfn(level3_vmemmap_pgt);
20245 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
20246 l2 = m2v(l3[pud_index(__START_KERNEL_map)].pud);
20247 @@ -2102,7 +2104,10 @@ __init pgd_t *xen_setup_kernel_pagetable
20248 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
20249 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
20250 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
20251 + set_page_prot(level3_vmalloc_pgt, PAGE_KERNEL_RO);
20252 + set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
20253 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
20254 + set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
20255 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
20256 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
20258 diff -urNp linux-2.6.37/arch/x86/xen/pci-swiotlb-xen.c linux-2.6.37/arch/x86/xen/pci-swiotlb-xen.c
20259 --- linux-2.6.37/arch/x86/xen/pci-swiotlb-xen.c 2011-01-04 19:50:19.000000000 -0500
20260 +++ linux-2.6.37/arch/x86/xen/pci-swiotlb-xen.c 2011-01-17 02:41:01.000000000 -0500
20263 int xen_swiotlb __read_mostly;
20265 -static struct dma_map_ops xen_swiotlb_dma_ops = {
20266 +static const struct dma_map_ops xen_swiotlb_dma_ops = {
20267 .mapping_error = xen_swiotlb_dma_mapping_error,
20268 .alloc_coherent = xen_swiotlb_alloc_coherent,
20269 .free_coherent = xen_swiotlb_free_coherent,
20270 diff -urNp linux-2.6.37/arch/x86/xen/smp.c linux-2.6.37/arch/x86/xen/smp.c
20271 --- linux-2.6.37/arch/x86/xen/smp.c 2011-01-04 19:50:19.000000000 -0500
20272 +++ linux-2.6.37/arch/x86/xen/smp.c 2011-01-17 02:41:01.000000000 -0500
20273 @@ -194,11 +194,6 @@ static void __init xen_smp_prepare_boot_
20275 BUG_ON(smp_processor_id() != 0);
20276 native_smp_prepare_boot_cpu();
20278 - /* We've switched to the "real" per-cpu gdt, so make sure the
20279 - old memory can be recycled */
20280 - make_lowmem_page_readwrite(xen_initial_gdt);
20282 xen_filter_cpu_maps();
20283 xen_setup_vcpu_info_placement();
20285 @@ -259,12 +254,12 @@ cpu_initialize_context(unsigned int cpu,
20286 gdt = get_cpu_gdt_table(cpu);
20288 ctxt->flags = VGCF_IN_KERNEL;
20289 - ctxt->user_regs.ds = __USER_DS;
20290 - ctxt->user_regs.es = __USER_DS;
20291 + ctxt->user_regs.ds = __KERNEL_DS;
20292 + ctxt->user_regs.es = __KERNEL_DS;
20293 ctxt->user_regs.ss = __KERNEL_DS;
20294 #ifdef CONFIG_X86_32
20295 ctxt->user_regs.fs = __KERNEL_PERCPU;
20296 - ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
20297 + savesegment(gs, ctxt->user_regs.gs);
20299 ctxt->gs_base_kernel = per_cpu_offset(cpu);
20301 diff -urNp linux-2.6.37/arch/x86/xen/xen-head.S linux-2.6.37/arch/x86/xen/xen-head.S
20302 --- linux-2.6.37/arch/x86/xen/xen-head.S 2011-01-04 19:50:19.000000000 -0500
20303 +++ linux-2.6.37/arch/x86/xen/xen-head.S 2011-01-17 02:41:01.000000000 -0500
20304 @@ -19,6 +19,17 @@ ENTRY(startup_xen)
20305 #ifdef CONFIG_X86_32
20306 mov %esi,xen_start_info
20307 mov $init_thread_union+THREAD_SIZE,%esp
20309 + movl $cpu_gdt_table,%edi
20310 + movl $__per_cpu_load,%eax
20311 + movw %ax,__KERNEL_PERCPU + 2(%edi)
20313 + movb %al,__KERNEL_PERCPU + 4(%edi)
20314 + movb %ah,__KERNEL_PERCPU + 7(%edi)
20315 + movl $__per_cpu_end - 1,%eax
20316 + subl $__per_cpu_start,%eax
20317 + movw %ax,__KERNEL_PERCPU + 0(%edi)
20320 mov %rsi,xen_start_info
20321 mov $init_thread_union+THREAD_SIZE,%rsp
20322 diff -urNp linux-2.6.37/arch/x86/xen/xen-ops.h linux-2.6.37/arch/x86/xen/xen-ops.h
20323 --- linux-2.6.37/arch/x86/xen/xen-ops.h 2011-01-04 19:50:19.000000000 -0500
20324 +++ linux-2.6.37/arch/x86/xen/xen-ops.h 2011-01-17 02:41:01.000000000 -0500
20326 extern const char xen_hypervisor_callback[];
20327 extern const char xen_failsafe_callback[];
20329 -extern void *xen_initial_gdt;
20332 void xen_copy_trap_info(struct trap_info *traps);
20334 diff -urNp linux-2.6.37/block/blk-iopoll.c linux-2.6.37/block/blk-iopoll.c
20335 --- linux-2.6.37/block/blk-iopoll.c 2011-01-04 19:50:19.000000000 -0500
20336 +++ linux-2.6.37/block/blk-iopoll.c 2011-01-17 02:41:01.000000000 -0500
20337 @@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopo
20339 EXPORT_SYMBOL(blk_iopoll_complete);
20341 -static void blk_iopoll_softirq(struct softirq_action *h)
20342 +static void blk_iopoll_softirq(void)
20344 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
20345 int rearm = 0, budget = blk_iopoll_budget;
20346 diff -urNp linux-2.6.37/block/blk-map.c linux-2.6.37/block/blk-map.c
20347 --- linux-2.6.37/block/blk-map.c 2011-01-04 19:50:19.000000000 -0500
20348 +++ linux-2.6.37/block/blk-map.c 2011-01-17 02:41:01.000000000 -0500
20349 @@ -301,7 +301,7 @@ int blk_rq_map_kern(struct request_queue
20353 - do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
20354 + do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
20356 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
20358 diff -urNp linux-2.6.37/block/blk-softirq.c linux-2.6.37/block/blk-softirq.c
20359 --- linux-2.6.37/block/blk-softirq.c 2011-01-04 19:50:19.000000000 -0500
20360 +++ linux-2.6.37/block/blk-softirq.c 2011-01-17 02:41:01.000000000 -0500
20361 @@ -17,7 +17,7 @@ static DEFINE_PER_CPU(struct list_head,
20362 * Softirq action handler - move entries to local list and loop over them
20363 * while passing them to the queue registered handler.
20365 -static void blk_done_softirq(struct softirq_action *h)
20366 +static void blk_done_softirq(void)
20368 struct list_head *cpu_list, local_list;
20370 diff -urNp linux-2.6.37/crypto/lrw.c linux-2.6.37/crypto/lrw.c
20371 --- linux-2.6.37/crypto/lrw.c 2011-01-04 19:50:19.000000000 -0500
20372 +++ linux-2.6.37/crypto/lrw.c 2011-01-17 02:41:01.000000000 -0500
20373 @@ -60,7 +60,7 @@ static int setkey(struct crypto_tfm *par
20374 struct priv *ctx = crypto_tfm_ctx(parent);
20375 struct crypto_cipher *child = ctx->child;
20377 - be128 tmp = { 0 };
20378 + be128 tmp = { 0, 0 };
20379 int bsize = crypto_cipher_blocksize(child);
20381 crypto_cipher_clear_flags(child, CRYPTO_TFM_REQ_MASK);
20382 diff -urNp linux-2.6.37/Documentation/dontdiff linux-2.6.37/Documentation/dontdiff
20383 --- linux-2.6.37/Documentation/dontdiff 2011-01-04 19:50:19.000000000 -0500
20384 +++ linux-2.6.37/Documentation/dontdiff 2011-01-17 02:41:01.000000000 -0500
20404 @@ -49,11 +52,16 @@
20421 @@ -62,6 +70,7 @@ aic7*reg_print.c*
20429 @@ -76,7 +85,10 @@ btfixupprep
20440 @@ -100,19 +112,23 @@ fore200e_mkfirm
20455 initramfs_data.cpio
20456 +initramfs_data.cpio.bz2
20457 initramfs_data.cpio.gz
20465 @@ -136,10 +152,13 @@ mkboot
20479 @@ -151,7 +170,9 @@ parse.h
20489 @@ -160,15 +181,18 @@ qconf
20508 @@ -189,14 +213,20 @@ version.h*
20529 diff -urNp linux-2.6.37/Documentation/filesystems/sysfs.txt linux-2.6.37/Documentation/filesystems/sysfs.txt
20530 --- linux-2.6.37/Documentation/filesystems/sysfs.txt 2011-01-04 19:50:19.000000000 -0500
20531 +++ linux-2.6.37/Documentation/filesystems/sysfs.txt 2011-01-17 02:41:01.000000000 -0500
20532 @@ -123,8 +123,8 @@ set of sysfs operations for forwarding r
20533 show and store methods of the attribute owners.
20536 - ssize_t (*show)(struct kobject *, struct attribute *, char *);
20537 - ssize_t (*store)(struct kobject *, struct attribute *, const char *, size_t);
20538 + ssize_t (* const show)(struct kobject *, struct attribute *, char *);
20539 + ssize_t (* const store)(struct kobject *, struct attribute *, const char *, size_t);
20542 [ Subsystems should have already defined a struct kobj_type as a
20543 diff -urNp linux-2.6.37/Documentation/kernel-parameters.txt linux-2.6.37/Documentation/kernel-parameters.txt
20544 --- linux-2.6.37/Documentation/kernel-parameters.txt 2011-01-04 19:50:19.000000000 -0500
20545 +++ linux-2.6.37/Documentation/kernel-parameters.txt 2011-01-17 02:41:01.000000000 -0500
20546 @@ -1849,6 +1849,13 @@ and is between 256 and 4096 characters.
20547 the specified number of seconds. This is to be used if
20548 your oopses keep scrolling off the screen.
20550 + pax_nouderef [X86] disables UDEREF. Most likely needed under certain
20551 + virtualization environments that don't cope well with the
20552 + expand down segment used by UDEREF on X86-32 or the frequent
20553 + page table updates on X86-64.
20555 + pax_softmode= [X86-32] 0/1 to disable/enable PaX softmode on boot already.
20560 diff -urNp linux-2.6.37/drivers/acpi/battery.c linux-2.6.37/drivers/acpi/battery.c
20561 --- linux-2.6.37/drivers/acpi/battery.c 2011-01-04 19:50:19.000000000 -0500
20562 +++ linux-2.6.37/drivers/acpi/battery.c 2011-01-17 02:41:01.000000000 -0500
20563 @@ -851,7 +851,7 @@ DECLARE_FILE_FUNCTIONS(alarm);
20566 static struct battery_file {
20567 - struct file_operations ops;
20568 + const struct file_operations ops;
20571 } acpi_battery_file[] = {
20572 diff -urNp linux-2.6.37/drivers/acpi/blacklist.c linux-2.6.37/drivers/acpi/blacklist.c
20573 --- linux-2.6.37/drivers/acpi/blacklist.c 2011-01-04 19:50:19.000000000 -0500
20574 +++ linux-2.6.37/drivers/acpi/blacklist.c 2011-01-17 02:41:01.000000000 -0500
20575 @@ -73,7 +73,7 @@ static struct acpi_blacklist_item acpi_b
20576 {"IBM ", "TP600E ", 0x00000105, ACPI_SIG_DSDT, less_than_or_equal,
20577 "Incorrect _ADR", 1},
20580 + {"", "", 0, NULL, all_versions, NULL, 0}
20583 #if CONFIG_ACPI_BLACKLIST_YEAR
20584 diff -urNp linux-2.6.37/drivers/acpi/dock.c linux-2.6.37/drivers/acpi/dock.c
20585 --- linux-2.6.37/drivers/acpi/dock.c 2011-01-04 19:50:19.000000000 -0500
20586 +++ linux-2.6.37/drivers/acpi/dock.c 2011-01-17 02:41:01.000000000 -0500
20587 @@ -77,7 +77,7 @@ struct dock_dependent_device {
20588 struct list_head list;
20589 struct list_head hotplug_list;
20590 acpi_handle handle;
20591 - struct acpi_dock_ops *ops;
20592 + const struct acpi_dock_ops *ops;
20596 @@ -589,7 +589,7 @@ EXPORT_SYMBOL_GPL(unregister_dock_notifi
20597 * the dock driver after _DCK is executed.
20600 -register_hotplug_dock_device(acpi_handle handle, struct acpi_dock_ops *ops,
20601 +register_hotplug_dock_device(acpi_handle handle, const struct acpi_dock_ops *ops,
20604 struct dock_dependent_device *dd;
20605 diff -urNp linux-2.6.37/drivers/acpi/ec_sys.c linux-2.6.37/drivers/acpi/ec_sys.c
20606 --- linux-2.6.37/drivers/acpi/ec_sys.c 2011-01-04 19:50:19.000000000 -0500
20607 +++ linux-2.6.37/drivers/acpi/ec_sys.c 2011-01-17 02:41:01.000000000 -0500
20608 @@ -96,7 +96,7 @@ static ssize_t acpi_ec_write_io(struct f
20612 -static struct file_operations acpi_ec_io_ops = {
20613 +static const struct file_operations acpi_ec_io_ops = {
20614 .owner = THIS_MODULE,
20615 .open = acpi_ec_open_io,
20616 .read = acpi_ec_read_io,
20617 diff -urNp linux-2.6.37/drivers/acpi/osl.c linux-2.6.37/drivers/acpi/osl.c
20618 --- linux-2.6.37/drivers/acpi/osl.c 2011-01-04 19:50:19.000000000 -0500
20619 +++ linux-2.6.37/drivers/acpi/osl.c 2011-01-17 02:41:01.000000000 -0500
20620 @@ -643,6 +643,8 @@ acpi_os_read_memory(acpi_physical_addres
20623 virt_addr = ioremap(phys_addr, size);
20625 + return AE_NO_MEMORY;
20629 @@ -679,6 +681,8 @@ acpi_os_write_memory(acpi_physical_addre
20632 virt_addr = ioremap(phys_addr, size);
20634 + return AE_NO_MEMORY;
20638 diff -urNp linux-2.6.37/drivers/acpi/power_meter.c linux-2.6.37/drivers/acpi/power_meter.c
20639 --- linux-2.6.37/drivers/acpi/power_meter.c 2011-01-04 19:50:19.000000000 -0500
20640 +++ linux-2.6.37/drivers/acpi/power_meter.c 2011-01-17 02:41:01.000000000 -0500
20641 @@ -316,8 +316,6 @@ static ssize_t set_trip(struct device *d
20648 mutex_lock(&resource->lock);
20649 resource->trip[attr->index - 7] = temp;
20650 diff -urNp linux-2.6.37/drivers/acpi/proc.c linux-2.6.37/drivers/acpi/proc.c
20651 --- linux-2.6.37/drivers/acpi/proc.c 2011-01-04 19:50:19.000000000 -0500
20652 +++ linux-2.6.37/drivers/acpi/proc.c 2011-01-17 02:41:01.000000000 -0500
20653 @@ -338,20 +338,15 @@ acpi_system_write_wakeup_device(struct f
20654 size_t count, loff_t * ppos)
20656 struct list_head *node, *next;
20658 - char str[5] = "";
20659 - unsigned int len = count;
20660 + char strbuf[5] = {0};
20661 struct acpi_device *found_dev = NULL;
20670 - if (copy_from_user(strbuf, buffer, len))
20671 + if (copy_from_user(strbuf, buffer, count))
20673 - strbuf[len] = '\0';
20674 - sscanf(strbuf, "%s", str);
20675 + strbuf[count] = '\0';
20677 mutex_lock(&acpi_device_lock);
20678 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
20679 @@ -360,7 +355,7 @@ acpi_system_write_wakeup_device(struct f
20680 if (!dev->wakeup.flags.valid)
20683 - if (!strncmp(dev->pnp.bus_id, str, 4)) {
20684 + if (!strncmp(dev->pnp.bus_id, strbuf, 4)) {
20685 dev->wakeup.state.enabled =
20686 dev->wakeup.state.enabled ? 0 : 1;
20688 diff -urNp linux-2.6.37/drivers/acpi/processor_driver.c linux-2.6.37/drivers/acpi/processor_driver.c
20689 --- linux-2.6.37/drivers/acpi/processor_driver.c 2011-01-04 19:50:19.000000000 -0500
20690 +++ linux-2.6.37/drivers/acpi/processor_driver.c 2011-01-17 02:41:01.000000000 -0500
20691 @@ -519,7 +519,7 @@ static int __cpuinit acpi_processor_add(
20695 - BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
20696 + BUG_ON(pr->id >= nr_cpu_ids);
20700 diff -urNp linux-2.6.37/drivers/acpi/processor_idle.c linux-2.6.37/drivers/acpi/processor_idle.c
20701 --- linux-2.6.37/drivers/acpi/processor_idle.c 2011-01-04 19:50:19.000000000 -0500
20702 +++ linux-2.6.37/drivers/acpi/processor_idle.c 2011-01-17 02:41:01.000000000 -0500
20703 @@ -114,7 +114,7 @@ static struct dmi_system_id __cpuinitdat
20704 DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer Inc."),
20705 DMI_MATCH(DMI_PRODUCT_NAME,"L8400B series Notebook PC")},
20708 + { NULL, NULL, {DMI_MATCH(DMI_NONE, {0})}, NULL},
20712 diff -urNp linux-2.6.37/drivers/acpi/sleep.c linux-2.6.37/drivers/acpi/sleep.c
20713 --- linux-2.6.37/drivers/acpi/sleep.c 2011-01-04 19:50:19.000000000 -0500
20714 +++ linux-2.6.37/drivers/acpi/sleep.c 2011-01-17 02:41:01.000000000 -0500
20715 @@ -319,7 +319,7 @@ static int acpi_suspend_state_valid(susp
20719 -static struct platform_suspend_ops acpi_suspend_ops = {
20720 +static const struct platform_suspend_ops acpi_suspend_ops = {
20721 .valid = acpi_suspend_state_valid,
20722 .begin = acpi_suspend_begin,
20723 .prepare_late = acpi_pm_prepare,
20724 @@ -347,7 +347,7 @@ static int acpi_suspend_begin_old(suspen
20725 * The following callbacks are used if the pre-ACPI 2.0 suspend ordering has
20728 -static struct platform_suspend_ops acpi_suspend_ops_old = {
20729 +static const struct platform_suspend_ops acpi_suspend_ops_old = {
20730 .valid = acpi_suspend_state_valid,
20731 .begin = acpi_suspend_begin_old,
20732 .prepare_late = acpi_pm_pre_suspend,
20733 @@ -506,7 +506,7 @@ static void acpi_pm_thaw(void)
20734 acpi_enable_all_runtime_gpes();
20737 -static struct platform_hibernation_ops acpi_hibernation_ops = {
20738 +static const struct platform_hibernation_ops acpi_hibernation_ops = {
20739 .begin = acpi_hibernation_begin,
20740 .end = acpi_pm_end,
20741 .pre_snapshot = acpi_pm_prepare,
20742 @@ -549,7 +549,7 @@ static int acpi_hibernation_begin_old(vo
20743 * The following callbacks are used if the pre-ACPI 2.0 suspend ordering has
20746 -static struct platform_hibernation_ops acpi_hibernation_ops_old = {
20747 +static const struct platform_hibernation_ops acpi_hibernation_ops_old = {
20748 .begin = acpi_hibernation_begin_old,
20749 .end = acpi_pm_end,
20750 .pre_snapshot = acpi_pm_pre_suspend,
20751 diff -urNp linux-2.6.37/drivers/acpi/video.c linux-2.6.37/drivers/acpi/video.c
20752 --- linux-2.6.37/drivers/acpi/video.c 2011-01-04 19:50:19.000000000 -0500
20753 +++ linux-2.6.37/drivers/acpi/video.c 2011-01-17 02:41:01.000000000 -0500
20754 @@ -260,7 +260,7 @@ static int acpi_video_set_brightness(str
20755 vd->brightness->levels[request_level]);
20758 -static struct backlight_ops acpi_backlight_ops = {
20759 +static const struct backlight_ops acpi_backlight_ops = {
20760 .get_brightness = acpi_video_get_brightness,
20761 .update_status = acpi_video_set_brightness,
20763 diff -urNp linux-2.6.37/drivers/ata/ahci.c linux-2.6.37/drivers/ata/ahci.c
20764 --- linux-2.6.37/drivers/ata/ahci.c 2011-01-04 19:50:19.000000000 -0500
20765 +++ linux-2.6.37/drivers/ata/ahci.c 2011-01-17 02:41:01.000000000 -0500
20766 @@ -94,17 +94,17 @@ static struct scsi_host_template ahci_sh
20770 -static struct ata_port_operations ahci_vt8251_ops = {
20771 +static const struct ata_port_operations ahci_vt8251_ops = {
20772 .inherits = &ahci_ops,
20773 .hardreset = ahci_vt8251_hardreset,
20776 -static struct ata_port_operations ahci_p5wdh_ops = {
20777 +static const struct ata_port_operations ahci_p5wdh_ops = {
20778 .inherits = &ahci_ops,
20779 .hardreset = ahci_p5wdh_hardreset,
20782 -static struct ata_port_operations ahci_sb600_ops = {
20783 +static const struct ata_port_operations ahci_sb600_ops = {
20784 .inherits = &ahci_ops,
20785 .softreset = ahci_sb600_softreset,
20786 .pmp_softreset = ahci_sb600_softreset,
20787 @@ -388,7 +388,7 @@ static const struct pci_device_id ahci_p
20788 { PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
20789 PCI_CLASS_STORAGE_SATA_AHCI, 0xffffff, board_ahci },
20791 - { } /* terminate list */
20792 + { 0, 0, 0, 0, 0, 0, 0 } /* terminate list */
20796 diff -urNp linux-2.6.37/drivers/ata/ahci.h linux-2.6.37/drivers/ata/ahci.h
20797 --- linux-2.6.37/drivers/ata/ahci.h 2011-01-04 19:50:19.000000000 -0500
20798 +++ linux-2.6.37/drivers/ata/ahci.h 2011-01-17 02:41:01.000000000 -0500
20799 @@ -309,7 +309,7 @@ extern struct device_attribute *ahci_sde
20800 .shost_attrs = ahci_shost_attrs, \
20801 .sdev_attrs = ahci_sdev_attrs
20803 -extern struct ata_port_operations ahci_ops;
20804 +extern const struct ata_port_operations ahci_ops;
20806 void ahci_save_initial_config(struct device *dev,
20807 struct ahci_host_priv *hpriv,
20808 diff -urNp linux-2.6.37/drivers/ata/ata_generic.c linux-2.6.37/drivers/ata/ata_generic.c
20809 --- linux-2.6.37/drivers/ata/ata_generic.c 2011-01-04 19:50:19.000000000 -0500
20810 +++ linux-2.6.37/drivers/ata/ata_generic.c 2011-01-17 02:41:01.000000000 -0500
20811 @@ -101,7 +101,7 @@ static struct scsi_host_template generic
20812 ATA_BMDMA_SHT(DRV_NAME),
20815 -static struct ata_port_operations generic_port_ops = {
20816 +static const struct ata_port_operations generic_port_ops = {
20817 .inherits = &ata_bmdma_port_ops,
20818 .cable_detect = ata_cable_unknown,
20819 .set_mode = generic_set_mode,
20820 diff -urNp linux-2.6.37/drivers/ata/ata_piix.c linux-2.6.37/drivers/ata/ata_piix.c
20821 --- linux-2.6.37/drivers/ata/ata_piix.c 2011-01-04 19:50:19.000000000 -0500
20822 +++ linux-2.6.37/drivers/ata/ata_piix.c 2011-01-17 02:41:01.000000000 -0500
20823 @@ -309,7 +309,7 @@ static const struct pci_device_id piix_p
20824 { 0x8086, 0x1d00, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_sata },
20825 /* SATA Controller IDE (PBG) */
20826 { 0x8086, 0x1d08, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_2port_sata },
20827 - { } /* terminate list */
20828 + { 0, 0, 0, 0, 0, 0, 0 } /* terminate list */
20831 static struct pci_driver piix_pci_driver = {
20832 @@ -327,12 +327,12 @@ static struct scsi_host_template piix_sh
20833 ATA_BMDMA_SHT(DRV_NAME),
20836 -static struct ata_port_operations piix_sata_ops = {
20837 +static const struct ata_port_operations piix_sata_ops = {
20838 .inherits = &ata_bmdma32_port_ops,
20839 .sff_irq_check = piix_irq_check,
20842 -static struct ata_port_operations piix_pata_ops = {
20843 +static const struct ata_port_operations piix_pata_ops = {
20844 .inherits = &piix_sata_ops,
20845 .cable_detect = ata_cable_40wire,
20846 .set_piomode = piix_set_piomode,
20847 @@ -340,12 +340,12 @@ static struct ata_port_operations piix_p
20848 .prereset = piix_pata_prereset,
20851 -static struct ata_port_operations piix_vmw_ops = {
20852 +static const struct ata_port_operations piix_vmw_ops = {
20853 .inherits = &piix_pata_ops,
20854 .bmdma_status = piix_vmw_bmdma_status,
20857 -static struct ata_port_operations ich_pata_ops = {
20858 +static const struct ata_port_operations ich_pata_ops = {
20859 .inherits = &piix_pata_ops,
20860 .cable_detect = ich_pata_cable_detect,
20861 .set_dmamode = ich_set_dmamode,
20862 @@ -361,7 +361,7 @@ static struct scsi_host_template piix_si
20863 .shost_attrs = piix_sidpr_shost_attrs,
20866 -static struct ata_port_operations piix_sidpr_sata_ops = {
20867 +static const struct ata_port_operations piix_sidpr_sata_ops = {
20868 .inherits = &piix_sata_ops,
20869 .hardreset = sata_std_hardreset,
20870 .scr_read = piix_sidpr_scr_read,
20871 @@ -638,7 +638,7 @@ static const struct ich_laptop ich_lapto
20872 { 0x2653, 0x1043, 0x82D8 }, /* ICH6M on Asus Eee 701 */
20873 { 0x27df, 0x104d, 0x900e }, /* ICH7 on Sony TZ-90 */
20880 @@ -1130,7 +1130,7 @@ static int piix_broken_suspend(void)
20884 - { } /* terminate list */
20885 + { NULL, NULL, {DMI_MATCH(DMI_NONE, {0})}, NULL } /* terminate list */
20887 static const char *oemstrs[] = {
20889 diff -urNp linux-2.6.37/drivers/ata/libahci.c linux-2.6.37/drivers/ata/libahci.c
20890 --- linux-2.6.37/drivers/ata/libahci.c 2011-01-04 19:50:19.000000000 -0500
20891 +++ linux-2.6.37/drivers/ata/libahci.c 2011-01-17 02:41:01.000000000 -0500
20892 @@ -140,7 +140,7 @@ struct device_attribute *ahci_sdev_attrs
20894 EXPORT_SYMBOL_GPL(ahci_sdev_attrs);
20896 -struct ata_port_operations ahci_ops = {
20897 +const struct ata_port_operations ahci_ops = {
20898 .inherits = &sata_pmp_port_ops,
20900 .qc_defer = ahci_pmp_qc_defer,
20901 diff -urNp linux-2.6.37/drivers/ata/libata-acpi.c linux-2.6.37/drivers/ata/libata-acpi.c
20902 --- linux-2.6.37/drivers/ata/libata-acpi.c 2011-01-04 19:50:19.000000000 -0500
20903 +++ linux-2.6.37/drivers/ata/libata-acpi.c 2011-01-17 02:41:01.000000000 -0500
20904 @@ -218,12 +218,12 @@ static void ata_acpi_dev_uevent(acpi_han
20905 ata_acpi_uevent(dev->link->ap, dev, event);
20908 -static struct acpi_dock_ops ata_acpi_dev_dock_ops = {
20909 +static const struct acpi_dock_ops ata_acpi_dev_dock_ops = {
20910 .handler = ata_acpi_dev_notify_dock,
20911 .uevent = ata_acpi_dev_uevent,
20914 -static struct acpi_dock_ops ata_acpi_ap_dock_ops = {
20915 +static const struct acpi_dock_ops ata_acpi_ap_dock_ops = {
20916 .handler = ata_acpi_ap_notify_dock,
20917 .uevent = ata_acpi_ap_uevent,
20919 diff -urNp linux-2.6.37/drivers/ata/libata-core.c linux-2.6.37/drivers/ata/libata-core.c
20920 --- linux-2.6.37/drivers/ata/libata-core.c 2011-01-04 19:50:19.000000000 -0500
20921 +++ linux-2.6.37/drivers/ata/libata-core.c 2011-01-17 02:41:01.000000000 -0500
20922 @@ -897,7 +897,7 @@ static const struct ata_xfer_ent {
20923 { ATA_SHIFT_PIO, ATA_NR_PIO_MODES, XFER_PIO_0 },
20924 { ATA_SHIFT_MWDMA, ATA_NR_MWDMA_MODES, XFER_MW_DMA_0 },
20925 { ATA_SHIFT_UDMA, ATA_NR_UDMA_MODES, XFER_UDMA_0 },
20931 @@ -2885,7 +2885,7 @@ static const struct ata_timing ata_timin
20932 { XFER_UDMA_5, 0, 0, 0, 0, 0, 0, 0, 0, 20 },
20933 { XFER_UDMA_6, 0, 0, 0, 0, 0, 0, 0, 0, 15 },
20936 + { 0xFF, 0, 0, 0, 0, 0, 0, 0, 0 }
20939 #define ENOUGH(v, unit) (((v)-1)/(unit)+1)
20940 @@ -4140,7 +4140,7 @@ static const struct ata_blacklist_entry
20941 { "PIONEER DVD-RW DVRTD08", "1.00", ATA_HORKAGE_NOSETXFER },
20945 + { NULL, NULL, 0 }
20949 @@ -4745,7 +4745,7 @@ void ata_qc_free(struct ata_queued_cmd *
20950 struct ata_port *ap;
20953 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
20954 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
20958 @@ -4761,7 +4761,7 @@ void __ata_qc_complete(struct ata_queued
20959 struct ata_port *ap;
20960 struct ata_link *link;
20962 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
20963 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
20964 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
20966 link = qc->dev->link;
20967 @@ -5754,7 +5754,7 @@ static void ata_host_stop(struct device
20971 -static void ata_finalize_port_ops(struct ata_port_operations *ops)
20972 +static void ata_finalize_port_ops(const struct ata_port_operations *ops)
20974 static DEFINE_SPINLOCK(lock);
20975 const struct ata_port_operations *cur;
20976 @@ -5766,6 +5766,7 @@ static void ata_finalize_port_ops(struct
20980 + pax_open_kernel();
20982 for (cur = ops->inherits; cur; cur = cur->inherits) {
20983 void **inherit = (void **)cur;
20984 @@ -5779,8 +5780,9 @@ static void ata_finalize_port_ops(struct
20988 - ops->inherits = NULL;
20989 + ((struct ata_port_operations *)ops)->inherits = NULL;
20991 + pax_close_kernel();
20992 spin_unlock(&lock);
20995 @@ -5877,7 +5879,7 @@ int ata_host_start(struct ata_host *host
20997 /* KILLME - the only user left is ipr */
20998 void ata_host_init(struct ata_host *host, struct device *dev,
20999 - unsigned long flags, struct ata_port_operations *ops)
21000 + unsigned long flags, const struct ata_port_operations *ops)
21002 spin_lock_init(&host->lock);
21003 mutex_init(&host->eh_mutex);
21004 @@ -6583,7 +6585,7 @@ static void ata_dummy_error_handler(stru
21008 -struct ata_port_operations ata_dummy_port_ops = {
21009 +const struct ata_port_operations ata_dummy_port_ops = {
21010 .qc_prep = ata_noop_qc_prep,
21011 .qc_issue = ata_dummy_qc_issue,
21012 .error_handler = ata_dummy_error_handler,
21013 diff -urNp linux-2.6.37/drivers/ata/libata-eh.c linux-2.6.37/drivers/ata/libata-eh.c
21014 --- linux-2.6.37/drivers/ata/libata-eh.c 2011-01-04 19:50:19.000000000 -0500
21015 +++ linux-2.6.37/drivers/ata/libata-eh.c 2011-01-17 02:41:01.000000000 -0500
21016 @@ -3880,7 +3880,7 @@ void ata_do_eh(struct ata_port *ap, ata_
21018 void ata_std_error_handler(struct ata_port *ap)
21020 - struct ata_port_operations *ops = ap->ops;
21021 + const struct ata_port_operations *ops = ap->ops;
21022 ata_reset_fn_t hardreset = ops->hardreset;
21024 /* ignore built-in hardreset if SCR access is not available */
21025 diff -urNp linux-2.6.37/drivers/ata/libata-pmp.c linux-2.6.37/drivers/ata/libata-pmp.c
21026 --- linux-2.6.37/drivers/ata/libata-pmp.c 2011-01-04 19:50:19.000000000 -0500
21027 +++ linux-2.6.37/drivers/ata/libata-pmp.c 2011-01-17 02:41:01.000000000 -0500
21028 @@ -912,7 +912,7 @@ static int sata_pmp_handle_link_fail(str
21030 static int sata_pmp_eh_recover(struct ata_port *ap)
21032 - struct ata_port_operations *ops = ap->ops;
21033 + const struct ata_port_operations *ops = ap->ops;
21034 int pmp_tries, link_tries[SATA_PMP_MAX_PORTS];
21035 struct ata_link *pmp_link = &ap->link;
21036 struct ata_device *pmp_dev = pmp_link->device;
21037 diff -urNp linux-2.6.37/drivers/ata/pata_acpi.c linux-2.6.37/drivers/ata/pata_acpi.c
21038 --- linux-2.6.37/drivers/ata/pata_acpi.c 2011-01-04 19:50:19.000000000 -0500
21039 +++ linux-2.6.37/drivers/ata/pata_acpi.c 2011-01-17 02:41:01.000000000 -0500
21040 @@ -216,7 +216,7 @@ static struct scsi_host_template pacpi_s
21041 ATA_BMDMA_SHT(DRV_NAME),
21044 -static struct ata_port_operations pacpi_ops = {
21045 +static const struct ata_port_operations pacpi_ops = {
21046 .inherits = &ata_bmdma_port_ops,
21047 .qc_issue = pacpi_qc_issue,
21048 .cable_detect = pacpi_cable_detect,
21049 diff -urNp linux-2.6.37/drivers/ata/pata_ali.c linux-2.6.37/drivers/ata/pata_ali.c
21050 --- linux-2.6.37/drivers/ata/pata_ali.c 2011-01-04 19:50:19.000000000 -0500
21051 +++ linux-2.6.37/drivers/ata/pata_ali.c 2011-01-17 02:41:01.000000000 -0500
21052 @@ -363,7 +363,7 @@ static struct scsi_host_template ali_sht
21053 * Port operations for PIO only ALi
21056 -static struct ata_port_operations ali_early_port_ops = {
21057 +static const struct ata_port_operations ali_early_port_ops = {
21058 .inherits = &ata_sff_port_ops,
21059 .cable_detect = ata_cable_40wire,
21060 .set_piomode = ali_set_piomode,
21061 @@ -380,7 +380,7 @@ static const struct ata_port_operations
21062 * Port operations for DMA capable ALi without cable
21065 -static struct ata_port_operations ali_20_port_ops = {
21066 +static const struct ata_port_operations ali_20_port_ops = {
21067 .inherits = &ali_dma_base_ops,
21068 .cable_detect = ata_cable_40wire,
21069 .mode_filter = ali_20_filter,
21070 @@ -391,7 +391,7 @@ static struct ata_port_operations ali_20
21072 * Port operations for DMA capable ALi with cable detect
21074 -static struct ata_port_operations ali_c2_port_ops = {
21075 +static const struct ata_port_operations ali_c2_port_ops = {
21076 .inherits = &ali_dma_base_ops,
21077 .check_atapi_dma = ali_check_atapi_dma,
21078 .cable_detect = ali_c2_cable_detect,
21079 @@ -402,7 +402,7 @@ static struct ata_port_operations ali_c2
21081 * Port operations for DMA capable ALi with cable detect
21083 -static struct ata_port_operations ali_c4_port_ops = {
21084 +static const struct ata_port_operations ali_c4_port_ops = {
21085 .inherits = &ali_dma_base_ops,
21086 .check_atapi_dma = ali_check_atapi_dma,
21087 .cable_detect = ali_c2_cable_detect,
21088 @@ -412,7 +412,7 @@ static struct ata_port_operations ali_c4
21090 * Port operations for DMA capable ALi with cable detect and LBA48
21092 -static struct ata_port_operations ali_c5_port_ops = {
21093 +static const struct ata_port_operations ali_c5_port_ops = {
21094 .inherits = &ali_dma_base_ops,
21095 .check_atapi_dma = ali_check_atapi_dma,
21096 .dev_config = ali_warn_atapi_dma,
21097 diff -urNp linux-2.6.37/drivers/ata/pata_amd.c linux-2.6.37/drivers/ata/pata_amd.c
21098 --- linux-2.6.37/drivers/ata/pata_amd.c 2011-01-04 19:50:19.000000000 -0500
21099 +++ linux-2.6.37/drivers/ata/pata_amd.c 2011-01-17 02:41:01.000000000 -0500
21100 @@ -397,28 +397,28 @@ static const struct ata_port_operations
21101 .prereset = amd_pre_reset,
21104 -static struct ata_port_operations amd33_port_ops = {
21105 +static const struct ata_port_operations amd33_port_ops = {
21106 .inherits = &amd_base_port_ops,
21107 .cable_detect = ata_cable_40wire,
21108 .set_piomode = amd33_set_piomode,
21109 .set_dmamode = amd33_set_dmamode,
21112 -static struct ata_port_operations amd66_port_ops = {
21113 +static const struct ata_port_operations amd66_port_ops = {
21114 .inherits = &amd_base_port_ops,
21115 .cable_detect = ata_cable_unknown,
21116 .set_piomode = amd66_set_piomode,
21117 .set_dmamode = amd66_set_dmamode,
21120 -static struct ata_port_operations amd100_port_ops = {
21121 +static const struct ata_port_operations amd100_port_ops = {
21122 .inherits = &amd_base_port_ops,
21123 .cable_detect = ata_cable_unknown,
21124 .set_piomode = amd100_set_piomode,
21125 .set_dmamode = amd100_set_dmamode,
21128 -static struct ata_port_operations amd133_port_ops = {
21129 +static const struct ata_port_operations amd133_port_ops = {
21130 .inherits = &amd_base_port_ops,
21131 .cable_detect = amd_cable_detect,
21132 .set_piomode = amd133_set_piomode,
21133 @@ -433,13 +433,13 @@ static const struct ata_port_operations
21134 .host_stop = nv_host_stop,
21137 -static struct ata_port_operations nv100_port_ops = {
21138 +static const struct ata_port_operations nv100_port_ops = {
21139 .inherits = &nv_base_port_ops,
21140 .set_piomode = nv100_set_piomode,
21141 .set_dmamode = nv100_set_dmamode,
21144 -static struct ata_port_operations nv133_port_ops = {
21145 +static const struct ata_port_operations nv133_port_ops = {
21146 .inherits = &nv_base_port_ops,
21147 .set_piomode = nv133_set_piomode,
21148 .set_dmamode = nv133_set_dmamode,
21149 diff -urNp linux-2.6.37/drivers/ata/pata_artop.c linux-2.6.37/drivers/ata/pata_artop.c
21150 --- linux-2.6.37/drivers/ata/pata_artop.c 2011-01-04 19:50:19.000000000 -0500
21151 +++ linux-2.6.37/drivers/ata/pata_artop.c 2011-01-17 02:41:01.000000000 -0500
21152 @@ -312,7 +312,7 @@ static struct scsi_host_template artop_s
21153 ATA_BMDMA_SHT(DRV_NAME),
21156 -static struct ata_port_operations artop6210_ops = {
21157 +static const struct ata_port_operations artop6210_ops = {
21158 .inherits = &ata_bmdma_port_ops,
21159 .cable_detect = ata_cable_40wire,
21160 .set_piomode = artop6210_set_piomode,
21161 @@ -321,7 +321,7 @@ static struct ata_port_operations artop6
21162 .qc_defer = artop6210_qc_defer,
21165 -static struct ata_port_operations artop6260_ops = {
21166 +static const struct ata_port_operations artop6260_ops = {
21167 .inherits = &ata_bmdma_port_ops,
21168 .cable_detect = artop6260_cable_detect,
21169 .set_piomode = artop6260_set_piomode,
21170 diff -urNp linux-2.6.37/drivers/ata/pata_at32.c linux-2.6.37/drivers/ata/pata_at32.c
21171 --- linux-2.6.37/drivers/ata/pata_at32.c 2011-01-04 19:50:19.000000000 -0500
21172 +++ linux-2.6.37/drivers/ata/pata_at32.c 2011-01-17 02:41:01.000000000 -0500
21173 @@ -173,7 +173,7 @@ static struct scsi_host_template at32_sh
21174 ATA_PIO_SHT(DRV_NAME),
21177 -static struct ata_port_operations at32_port_ops = {
21178 +static const struct ata_port_operations at32_port_ops = {
21179 .inherits = &ata_sff_port_ops,
21180 .cable_detect = ata_cable_40wire,
21181 .set_piomode = pata_at32_set_piomode,
21182 diff -urNp linux-2.6.37/drivers/ata/pata_at91.c linux-2.6.37/drivers/ata/pata_at91.c
21183 --- linux-2.6.37/drivers/ata/pata_at91.c 2011-01-04 19:50:19.000000000 -0500
21184 +++ linux-2.6.37/drivers/ata/pata_at91.c 2011-01-17 02:41:01.000000000 -0500
21185 @@ -196,7 +196,7 @@ static struct scsi_host_template pata_at
21186 ATA_PIO_SHT(DRV_NAME),
21189 -static struct ata_port_operations pata_at91_port_ops = {
21190 +static const struct ata_port_operations pata_at91_port_ops = {
21191 .inherits = &ata_sff_port_ops,
21193 .sff_data_xfer = pata_at91_data_xfer_noirq,
21194 diff -urNp linux-2.6.37/drivers/ata/pata_atiixp.c linux-2.6.37/drivers/ata/pata_atiixp.c
21195 --- linux-2.6.37/drivers/ata/pata_atiixp.c 2011-01-04 19:50:19.000000000 -0500
21196 +++ linux-2.6.37/drivers/ata/pata_atiixp.c 2011-01-17 02:41:01.000000000 -0500
21197 @@ -214,7 +214,7 @@ static struct scsi_host_template atiixp_
21198 .sg_tablesize = LIBATA_DUMB_MAX_PRD,
21201 -static struct ata_port_operations atiixp_port_ops = {
21202 +static const struct ata_port_operations atiixp_port_ops = {
21203 .inherits = &ata_bmdma_port_ops,
21205 .qc_prep = ata_bmdma_dumb_qc_prep,
21206 diff -urNp linux-2.6.37/drivers/ata/pata_atp867x.c linux-2.6.37/drivers/ata/pata_atp867x.c
21207 --- linux-2.6.37/drivers/ata/pata_atp867x.c 2011-01-04 19:50:19.000000000 -0500
21208 +++ linux-2.6.37/drivers/ata/pata_atp867x.c 2011-01-17 02:41:01.000000000 -0500
21209 @@ -275,7 +275,7 @@ static struct scsi_host_template atp867x
21210 ATA_BMDMA_SHT(DRV_NAME),
21213 -static struct ata_port_operations atp867x_ops = {
21214 +static const struct ata_port_operations atp867x_ops = {
21215 .inherits = &ata_bmdma_port_ops,
21216 .cable_detect = atp867x_cable_detect,
21217 .set_piomode = atp867x_set_piomode,
21218 diff -urNp linux-2.6.37/drivers/ata/pata_bf54x.c linux-2.6.37/drivers/ata/pata_bf54x.c
21219 --- linux-2.6.37/drivers/ata/pata_bf54x.c 2011-01-04 19:50:19.000000000 -0500
21220 +++ linux-2.6.37/drivers/ata/pata_bf54x.c 2011-01-17 02:41:01.000000000 -0500
21221 @@ -1420,7 +1420,7 @@ static struct scsi_host_template bfin_sh
21222 .dma_boundary = ATA_DMA_BOUNDARY,
21225 -static struct ata_port_operations bfin_pata_ops = {
21226 +static const struct ata_port_operations bfin_pata_ops = {
21227 .inherits = &ata_bmdma_port_ops,
21229 .set_piomode = bfin_set_piomode,
21230 diff -urNp linux-2.6.37/drivers/ata/pata_cmd640.c linux-2.6.37/drivers/ata/pata_cmd640.c
21231 --- linux-2.6.37/drivers/ata/pata_cmd640.c 2011-01-04 19:50:19.000000000 -0500
21232 +++ linux-2.6.37/drivers/ata/pata_cmd640.c 2011-01-17 02:41:01.000000000 -0500
21233 @@ -176,7 +176,7 @@ static struct scsi_host_template cmd640_
21234 ATA_PIO_SHT(DRV_NAME),
21237 -static struct ata_port_operations cmd640_port_ops = {
21238 +static const struct ata_port_operations cmd640_port_ops = {
21239 .inherits = &ata_sff_port_ops,
21240 /* In theory xfer_noirq is not needed once we kill the prefetcher */
21241 .sff_data_xfer = ata_sff_data_xfer_noirq,
21242 diff -urNp linux-2.6.37/drivers/ata/pata_cmd64x.c linux-2.6.37/drivers/ata/pata_cmd64x.c
21243 --- linux-2.6.37/drivers/ata/pata_cmd64x.c 2011-01-04 19:50:19.000000000 -0500
21244 +++ linux-2.6.37/drivers/ata/pata_cmd64x.c 2011-01-17 02:41:01.000000000 -0500
21245 @@ -268,18 +268,18 @@ static const struct ata_port_operations
21246 .set_dmamode = cmd64x_set_dmamode,
21249 -static struct ata_port_operations cmd64x_port_ops = {
21250 +static const struct ata_port_operations cmd64x_port_ops = {
21251 .inherits = &cmd64x_base_ops,
21252 .cable_detect = ata_cable_40wire,
21255 -static struct ata_port_operations cmd646r1_port_ops = {
21256 +static const struct ata_port_operations cmd646r1_port_ops = {
21257 .inherits = &cmd64x_base_ops,
21258 .bmdma_stop = cmd646r1_bmdma_stop,
21259 .cable_detect = ata_cable_40wire,
21262 -static struct ata_port_operations cmd648_port_ops = {
21263 +static const struct ata_port_operations cmd648_port_ops = {
21264 .inherits = &cmd64x_base_ops,
21265 .bmdma_stop = cmd648_bmdma_stop,
21266 .cable_detect = cmd648_cable_detect,
21267 diff -urNp linux-2.6.37/drivers/ata/pata_cs5520.c linux-2.6.37/drivers/ata/pata_cs5520.c
21268 --- linux-2.6.37/drivers/ata/pata_cs5520.c 2011-01-04 19:50:19.000000000 -0500
21269 +++ linux-2.6.37/drivers/ata/pata_cs5520.c 2011-01-17 02:41:01.000000000 -0500
21270 @@ -108,7 +108,7 @@ static struct scsi_host_template cs5520_
21271 .sg_tablesize = LIBATA_DUMB_MAX_PRD,
21274 -static struct ata_port_operations cs5520_port_ops = {
21275 +static const struct ata_port_operations cs5520_port_ops = {
21276 .inherits = &ata_bmdma_port_ops,
21277 .qc_prep = ata_bmdma_dumb_qc_prep,
21278 .cable_detect = ata_cable_40wire,
21279 diff -urNp linux-2.6.37/drivers/ata/pata_cs5530.c linux-2.6.37/drivers/ata/pata_cs5530.c
21280 --- linux-2.6.37/drivers/ata/pata_cs5530.c 2011-01-04 19:50:19.000000000 -0500
21281 +++ linux-2.6.37/drivers/ata/pata_cs5530.c 2011-01-17 02:41:01.000000000 -0500
21282 @@ -164,7 +164,7 @@ static struct scsi_host_template cs5530_
21283 .sg_tablesize = LIBATA_DUMB_MAX_PRD,
21286 -static struct ata_port_operations cs5530_port_ops = {
21287 +static const struct ata_port_operations cs5530_port_ops = {
21288 .inherits = &ata_bmdma_port_ops,
21290 .qc_prep = ata_bmdma_dumb_qc_prep,
21291 diff -urNp linux-2.6.37/drivers/ata/pata_cs5535.c linux-2.6.37/drivers/ata/pata_cs5535.c
21292 --- linux-2.6.37/drivers/ata/pata_cs5535.c 2011-01-04 19:50:19.000000000 -0500
21293 +++ linux-2.6.37/drivers/ata/pata_cs5535.c 2011-01-17 02:41:01.000000000 -0500
21294 @@ -160,7 +160,7 @@ static struct scsi_host_template cs5535_
21295 ATA_BMDMA_SHT(DRV_NAME),
21298 -static struct ata_port_operations cs5535_port_ops = {
21299 +static const struct ata_port_operations cs5535_port_ops = {
21300 .inherits = &ata_bmdma_port_ops,
21301 .cable_detect = cs5535_cable_detect,
21302 .set_piomode = cs5535_set_piomode,
21303 diff -urNp linux-2.6.37/drivers/ata/pata_cs5536.c linux-2.6.37/drivers/ata/pata_cs5536.c
21304 --- linux-2.6.37/drivers/ata/pata_cs5536.c 2011-01-04 19:50:19.000000000 -0500
21305 +++ linux-2.6.37/drivers/ata/pata_cs5536.c 2011-01-17 02:41:01.000000000 -0500
21306 @@ -233,7 +233,7 @@ static struct scsi_host_template cs5536_
21307 ATA_BMDMA_SHT(DRV_NAME),
21310 -static struct ata_port_operations cs5536_port_ops = {
21311 +static const struct ata_port_operations cs5536_port_ops = {
21312 .inherits = &ata_bmdma32_port_ops,
21313 .cable_detect = cs5536_cable_detect,
21314 .set_piomode = cs5536_set_piomode,
21315 diff -urNp linux-2.6.37/drivers/ata/pata_cypress.c linux-2.6.37/drivers/ata/pata_cypress.c
21316 --- linux-2.6.37/drivers/ata/pata_cypress.c 2011-01-04 19:50:19.000000000 -0500
21317 +++ linux-2.6.37/drivers/ata/pata_cypress.c 2011-01-17 02:41:01.000000000 -0500
21318 @@ -115,7 +115,7 @@ static struct scsi_host_template cy82c69
21319 ATA_BMDMA_SHT(DRV_NAME),
21322 -static struct ata_port_operations cy82c693_port_ops = {
21323 +static const struct ata_port_operations cy82c693_port_ops = {
21324 .inherits = &ata_bmdma_port_ops,
21325 .cable_detect = ata_cable_40wire,
21326 .set_piomode = cy82c693_set_piomode,
21327 diff -urNp linux-2.6.37/drivers/ata/pata_efar.c linux-2.6.37/drivers/ata/pata_efar.c
21328 --- linux-2.6.37/drivers/ata/pata_efar.c 2011-01-04 19:50:19.000000000 -0500
21329 +++ linux-2.6.37/drivers/ata/pata_efar.c 2011-01-17 02:41:01.000000000 -0500
21330 @@ -238,7 +238,7 @@ static struct scsi_host_template efar_sh
21331 ATA_BMDMA_SHT(DRV_NAME),
21334 -static struct ata_port_operations efar_ops = {
21335 +static const struct ata_port_operations efar_ops = {
21336 .inherits = &ata_bmdma_port_ops,
21337 .cable_detect = efar_cable_detect,
21338 .set_piomode = efar_set_piomode,
21339 diff -urNp linux-2.6.37/drivers/ata/pata_hpt366.c linux-2.6.37/drivers/ata/pata_hpt366.c
21340 --- linux-2.6.37/drivers/ata/pata_hpt366.c 2011-01-04 19:50:19.000000000 -0500
21341 +++ linux-2.6.37/drivers/ata/pata_hpt366.c 2011-01-17 02:41:01.000000000 -0500
21342 @@ -269,7 +269,7 @@ static struct scsi_host_template hpt36x_
21343 * Configuration for HPT366/68
21346 -static struct ata_port_operations hpt366_port_ops = {
21347 +static const struct ata_port_operations hpt366_port_ops = {
21348 .inherits = &ata_bmdma_port_ops,
21349 .cable_detect = hpt36x_cable_detect,
21350 .mode_filter = hpt366_filter,
21351 diff -urNp linux-2.6.37/drivers/ata/pata_hpt37x.c linux-2.6.37/drivers/ata/pata_hpt37x.c
21352 --- linux-2.6.37/drivers/ata/pata_hpt37x.c 2011-01-04 19:50:19.000000000 -0500
21353 +++ linux-2.6.37/drivers/ata/pata_hpt37x.c 2011-01-17 02:41:01.000000000 -0500
21354 @@ -564,7 +564,7 @@ static struct scsi_host_template hpt37x_
21355 * Configuration for HPT370
21358 -static struct ata_port_operations hpt370_port_ops = {
21359 +static const struct ata_port_operations hpt370_port_ops = {
21360 .inherits = &ata_bmdma_port_ops,
21362 .bmdma_stop = hpt370_bmdma_stop,
21363 @@ -580,7 +580,7 @@ static struct ata_port_operations hpt370
21364 * Configuration for HPT370A. Close to 370 but less filters
21367 -static struct ata_port_operations hpt370a_port_ops = {
21368 +static const struct ata_port_operations hpt370a_port_ops = {
21369 .inherits = &hpt370_port_ops,
21370 .mode_filter = hpt370a_filter,
21372 @@ -590,7 +590,7 @@ static struct ata_port_operations hpt370
21373 * and DMA mode setting functionality.
21376 -static struct ata_port_operations hpt372_port_ops = {
21377 +static const struct ata_port_operations hpt372_port_ops = {
21378 .inherits = &ata_bmdma_port_ops,
21380 .bmdma_stop = hpt37x_bmdma_stop,
21381 @@ -606,7 +606,7 @@ static struct ata_port_operations hpt372
21382 * but we have a different cable detection procedure for function 1.
21385 -static struct ata_port_operations hpt374_fn1_port_ops = {
21386 +static const struct ata_port_operations hpt374_fn1_port_ops = {
21387 .inherits = &hpt372_port_ops,
21388 .cable_detect = hpt374_fn1_cable_detect,
21389 .prereset = hpt37x_pre_reset,
21390 diff -urNp linux-2.6.37/drivers/ata/pata_hpt3x2n.c linux-2.6.37/drivers/ata/pata_hpt3x2n.c
21391 --- linux-2.6.37/drivers/ata/pata_hpt3x2n.c 2011-01-04 19:50:19.000000000 -0500
21392 +++ linux-2.6.37/drivers/ata/pata_hpt3x2n.c 2011-01-17 02:41:01.000000000 -0500
21393 @@ -331,7 +331,7 @@ static struct scsi_host_template hpt3x2n
21394 * Configuration for HPT3x2n.
21397 -static struct ata_port_operations hpt3x2n_port_ops = {
21398 +static const struct ata_port_operations hpt3x2n_port_ops = {
21399 .inherits = &ata_bmdma_port_ops,
21401 .bmdma_stop = hpt3x2n_bmdma_stop,
21402 diff -urNp linux-2.6.37/drivers/ata/pata_hpt3x3.c linux-2.6.37/drivers/ata/pata_hpt3x3.c
21403 --- linux-2.6.37/drivers/ata/pata_hpt3x3.c 2011-01-04 19:50:19.000000000 -0500
21404 +++ linux-2.6.37/drivers/ata/pata_hpt3x3.c 2011-01-17 02:41:01.000000000 -0500
21405 @@ -141,7 +141,7 @@ static struct scsi_host_template hpt3x3_
21406 ATA_BMDMA_SHT(DRV_NAME),
21409 -static struct ata_port_operations hpt3x3_port_ops = {
21410 +static const struct ata_port_operations hpt3x3_port_ops = {
21411 .inherits = &ata_bmdma_port_ops,
21412 .cable_detect = ata_cable_40wire,
21413 .set_piomode = hpt3x3_set_piomode,
21414 diff -urNp linux-2.6.37/drivers/ata/pata_icside.c linux-2.6.37/drivers/ata/pata_icside.c
21415 --- linux-2.6.37/drivers/ata/pata_icside.c 2011-01-04 19:50:19.000000000 -0500
21416 +++ linux-2.6.37/drivers/ata/pata_icside.c 2011-01-17 02:41:01.000000000 -0500
21417 @@ -320,7 +320,7 @@ static void pata_icside_postreset(struct
21421 -static struct ata_port_operations pata_icside_port_ops = {
21422 +static const struct ata_port_operations pata_icside_port_ops = {
21423 .inherits = &ata_bmdma_port_ops,
21424 /* no need to build any PRD tables for DMA */
21425 .qc_prep = ata_noop_qc_prep,
21426 diff -urNp linux-2.6.37/drivers/ata/pata_isapnp.c linux-2.6.37/drivers/ata/pata_isapnp.c
21427 --- linux-2.6.37/drivers/ata/pata_isapnp.c 2011-01-04 19:50:19.000000000 -0500
21428 +++ linux-2.6.37/drivers/ata/pata_isapnp.c 2011-01-17 02:41:01.000000000 -0500
21429 @@ -23,12 +23,12 @@ static struct scsi_host_template isapnp_
21430 ATA_PIO_SHT(DRV_NAME),
21433 -static struct ata_port_operations isapnp_port_ops = {
21434 +static const struct ata_port_operations isapnp_port_ops = {
21435 .inherits = &ata_sff_port_ops,
21436 .cable_detect = ata_cable_40wire,
21439 -static struct ata_port_operations isapnp_noalt_port_ops = {
21440 +static const struct ata_port_operations isapnp_noalt_port_ops = {
21441 .inherits = &ata_sff_port_ops,
21442 .cable_detect = ata_cable_40wire,
21443 /* No altstatus so we don't want to use the lost interrupt poll */
21444 diff -urNp linux-2.6.37/drivers/ata/pata_it8213.c linux-2.6.37/drivers/ata/pata_it8213.c
21445 --- linux-2.6.37/drivers/ata/pata_it8213.c 2011-01-04 19:50:19.000000000 -0500
21446 +++ linux-2.6.37/drivers/ata/pata_it8213.c 2011-01-17 02:41:01.000000000 -0500
21447 @@ -233,7 +233,7 @@ static struct scsi_host_template it8213_
21451 -static struct ata_port_operations it8213_ops = {
21452 +static const struct ata_port_operations it8213_ops = {
21453 .inherits = &ata_bmdma_port_ops,
21454 .cable_detect = it8213_cable_detect,
21455 .set_piomode = it8213_set_piomode,
21456 diff -urNp linux-2.6.37/drivers/ata/pata_it821x.c linux-2.6.37/drivers/ata/pata_it821x.c
21457 --- linux-2.6.37/drivers/ata/pata_it821x.c 2011-01-04 19:50:19.000000000 -0500
21458 +++ linux-2.6.37/drivers/ata/pata_it821x.c 2011-01-17 02:41:01.000000000 -0500
21459 @@ -801,7 +801,7 @@ static struct scsi_host_template it821x_
21460 ATA_BMDMA_SHT(DRV_NAME),
21463 -static struct ata_port_operations it821x_smart_port_ops = {
21464 +static const struct ata_port_operations it821x_smart_port_ops = {
21465 .inherits = &ata_bmdma_port_ops,
21467 .check_atapi_dma= it821x_check_atapi_dma,
21468 @@ -815,7 +815,7 @@ static struct ata_port_operations it821x
21469 .port_start = it821x_port_start,
21472 -static struct ata_port_operations it821x_passthru_port_ops = {
21473 +static const struct ata_port_operations it821x_passthru_port_ops = {
21474 .inherits = &ata_bmdma_port_ops,
21476 .check_atapi_dma= it821x_check_atapi_dma,
21477 @@ -831,7 +831,7 @@ static struct ata_port_operations it821x
21478 .port_start = it821x_port_start,
21481 -static struct ata_port_operations it821x_rdc_port_ops = {
21482 +static const struct ata_port_operations it821x_rdc_port_ops = {
21483 .inherits = &ata_bmdma_port_ops,
21485 .check_atapi_dma= it821x_check_atapi_dma,
21486 diff -urNp linux-2.6.37/drivers/ata/pata_ixp4xx_cf.c linux-2.6.37/drivers/ata/pata_ixp4xx_cf.c
21487 --- linux-2.6.37/drivers/ata/pata_ixp4xx_cf.c 2011-01-04 19:50:19.000000000 -0500
21488 +++ linux-2.6.37/drivers/ata/pata_ixp4xx_cf.c 2011-01-17 02:41:01.000000000 -0500
21489 @@ -89,7 +89,7 @@ static struct scsi_host_template ixp4xx_
21490 ATA_PIO_SHT(DRV_NAME),
21493 -static struct ata_port_operations ixp4xx_port_ops = {
21494 +static const struct ata_port_operations ixp4xx_port_ops = {
21495 .inherits = &ata_sff_port_ops,
21496 .sff_data_xfer = ixp4xx_mmio_data_xfer,
21497 .cable_detect = ata_cable_40wire,
21498 diff -urNp linux-2.6.37/drivers/ata/pata_jmicron.c linux-2.6.37/drivers/ata/pata_jmicron.c
21499 --- linux-2.6.37/drivers/ata/pata_jmicron.c 2011-01-04 19:50:19.000000000 -0500
21500 +++ linux-2.6.37/drivers/ata/pata_jmicron.c 2011-01-17 02:41:01.000000000 -0500
21501 @@ -111,7 +111,7 @@ static struct scsi_host_template jmicron
21502 ATA_BMDMA_SHT(DRV_NAME),
21505 -static struct ata_port_operations jmicron_ops = {
21506 +static const struct ata_port_operations jmicron_ops = {
21507 .inherits = &ata_bmdma_port_ops,
21508 .prereset = jmicron_pre_reset,
21510 diff -urNp linux-2.6.37/drivers/ata/pata_legacy.c linux-2.6.37/drivers/ata/pata_legacy.c
21511 --- linux-2.6.37/drivers/ata/pata_legacy.c 2011-01-04 19:50:19.000000000 -0500
21512 +++ linux-2.6.37/drivers/ata/pata_legacy.c 2011-01-17 02:41:01.000000000 -0500
21513 @@ -116,7 +116,7 @@ struct legacy_probe {
21515 struct legacy_controller {
21517 - struct ata_port_operations *ops;
21518 + const struct ata_port_operations *ops;
21519 unsigned int pio_mask;
21520 unsigned int flags;
21521 unsigned int pflags;
21522 @@ -239,12 +239,12 @@ static const struct ata_port_operations
21523 * pio_mask as well.
21526 -static struct ata_port_operations simple_port_ops = {
21527 +static const struct ata_port_operations simple_port_ops = {
21528 .inherits = &legacy_base_port_ops,
21529 .sff_data_xfer = ata_sff_data_xfer_noirq,
21532 -static struct ata_port_operations legacy_port_ops = {
21533 +static const struct ata_port_operations legacy_port_ops = {
21534 .inherits = &legacy_base_port_ops,
21535 .sff_data_xfer = ata_sff_data_xfer_noirq,
21536 .set_mode = legacy_set_mode,
21537 @@ -340,7 +340,7 @@ static unsigned int pdc_data_xfer_vlb(st
21541 -static struct ata_port_operations pdc20230_port_ops = {
21542 +static const struct ata_port_operations pdc20230_port_ops = {
21543 .inherits = &legacy_base_port_ops,
21544 .set_piomode = pdc20230_set_piomode,
21545 .sff_data_xfer = pdc_data_xfer_vlb,
21546 @@ -373,7 +373,7 @@ static void ht6560a_set_piomode(struct a
21547 ioread8(ap->ioaddr.status_addr);
21550 -static struct ata_port_operations ht6560a_port_ops = {
21551 +static const struct ata_port_operations ht6560a_port_ops = {
21552 .inherits = &legacy_base_port_ops,
21553 .set_piomode = ht6560a_set_piomode,
21555 @@ -416,7 +416,7 @@ static void ht6560b_set_piomode(struct a
21556 ioread8(ap->ioaddr.status_addr);
21559 -static struct ata_port_operations ht6560b_port_ops = {
21560 +static const struct ata_port_operations ht6560b_port_ops = {
21561 .inherits = &legacy_base_port_ops,
21562 .set_piomode = ht6560b_set_piomode,
21564 @@ -515,7 +515,7 @@ static void opti82c611a_set_piomode(stru
21568 -static struct ata_port_operations opti82c611a_port_ops = {
21569 +static const struct ata_port_operations opti82c611a_port_ops = {
21570 .inherits = &legacy_base_port_ops,
21571 .set_piomode = opti82c611a_set_piomode,
21573 @@ -625,7 +625,7 @@ static unsigned int opti82c46x_qc_issue(
21574 return ata_sff_qc_issue(qc);
21577 -static struct ata_port_operations opti82c46x_port_ops = {
21578 +static const struct ata_port_operations opti82c46x_port_ops = {
21579 .inherits = &legacy_base_port_ops,
21580 .set_piomode = opti82c46x_set_piomode,
21581 .qc_issue = opti82c46x_qc_issue,
21582 @@ -787,20 +787,20 @@ static int qdi_port(struct platform_devi
21586 -static struct ata_port_operations qdi6500_port_ops = {
21587 +static const struct ata_port_operations qdi6500_port_ops = {
21588 .inherits = &legacy_base_port_ops,
21589 .set_piomode = qdi6500_set_piomode,
21590 .qc_issue = qdi_qc_issue,
21591 .sff_data_xfer = vlb32_data_xfer,
21594 -static struct ata_port_operations qdi6580_port_ops = {
21595 +static const struct ata_port_operations qdi6580_port_ops = {
21596 .inherits = &legacy_base_port_ops,
21597 .set_piomode = qdi6580_set_piomode,
21598 .sff_data_xfer = vlb32_data_xfer,
21601 -static struct ata_port_operations qdi6580dp_port_ops = {
21602 +static const struct ata_port_operations qdi6580dp_port_ops = {
21603 .inherits = &legacy_base_port_ops,
21604 .set_piomode = qdi6580dp_set_piomode,
21605 .qc_issue = qdi_qc_issue,
21606 @@ -872,7 +872,7 @@ static int winbond_port(struct platform_
21610 -static struct ata_port_operations winbond_port_ops = {
21611 +static const struct ata_port_operations winbond_port_ops = {
21612 .inherits = &legacy_base_port_ops,
21613 .set_piomode = winbond_set_piomode,
21614 .sff_data_xfer = vlb32_data_xfer,
21615 @@ -995,7 +995,7 @@ static __init int legacy_init_one(struct
21616 int pio_modes = controller->pio_mask;
21617 unsigned long io = probe->port;
21618 u32 mask = (1 << probe->slot);
21619 - struct ata_port_operations *ops = controller->ops;
21620 + const struct ata_port_operations *ops = controller->ops;
21621 struct legacy_data *ld = &legacy_data[probe->slot];
21622 struct ata_host *host = NULL;
21623 struct ata_port *ap;
21624 diff -urNp linux-2.6.37/drivers/ata/pata_macio.c linux-2.6.37/drivers/ata/pata_macio.c
21625 --- linux-2.6.37/drivers/ata/pata_macio.c 2011-01-04 19:50:19.000000000 -0500
21626 +++ linux-2.6.37/drivers/ata/pata_macio.c 2011-01-17 02:41:01.000000000 -0500
21627 @@ -918,9 +918,8 @@ static struct scsi_host_template pata_ma
21628 .slave_configure = pata_macio_slave_config,
21631 -static struct ata_port_operations pata_macio_ops = {
21632 +static const struct ata_port_operations pata_macio_ops = {
21633 .inherits = &ata_bmdma_port_ops,
21635 .freeze = pata_macio_freeze,
21636 .set_piomode = pata_macio_set_timings,
21637 .set_dmamode = pata_macio_set_timings,
21638 diff -urNp linux-2.6.37/drivers/ata/pata_marvell.c linux-2.6.37/drivers/ata/pata_marvell.c
21639 --- linux-2.6.37/drivers/ata/pata_marvell.c 2011-01-04 19:50:19.000000000 -0500
21640 +++ linux-2.6.37/drivers/ata/pata_marvell.c 2011-01-17 02:41:01.000000000 -0500
21641 @@ -100,7 +100,7 @@ static struct scsi_host_template marvell
21642 ATA_BMDMA_SHT(DRV_NAME),
21645 -static struct ata_port_operations marvell_ops = {
21646 +static const struct ata_port_operations marvell_ops = {
21647 .inherits = &ata_bmdma_port_ops,
21648 .cable_detect = marvell_cable_detect,
21649 .prereset = marvell_pre_reset,
21650 diff -urNp linux-2.6.37/drivers/ata/pata_mpc52xx.c linux-2.6.37/drivers/ata/pata_mpc52xx.c
21651 --- linux-2.6.37/drivers/ata/pata_mpc52xx.c 2011-01-04 19:50:19.000000000 -0500
21652 +++ linux-2.6.37/drivers/ata/pata_mpc52xx.c 2011-01-17 02:41:01.000000000 -0500
21653 @@ -609,7 +609,7 @@ static struct scsi_host_template mpc52xx
21654 ATA_PIO_SHT(DRV_NAME),
21657 -static struct ata_port_operations mpc52xx_ata_port_ops = {
21658 +static const struct ata_port_operations mpc52xx_ata_port_ops = {
21659 .inherits = &ata_sff_port_ops,
21660 .sff_dev_select = mpc52xx_ata_dev_select,
21661 .set_piomode = mpc52xx_ata_set_piomode,
21662 diff -urNp linux-2.6.37/drivers/ata/pata_mpiix.c linux-2.6.37/drivers/ata/pata_mpiix.c
21663 --- linux-2.6.37/drivers/ata/pata_mpiix.c 2011-01-04 19:50:19.000000000 -0500
21664 +++ linux-2.6.37/drivers/ata/pata_mpiix.c 2011-01-17 02:41:01.000000000 -0500
21665 @@ -140,7 +140,7 @@ static struct scsi_host_template mpiix_s
21666 ATA_PIO_SHT(DRV_NAME),
21669 -static struct ata_port_operations mpiix_port_ops = {
21670 +static const struct ata_port_operations mpiix_port_ops = {
21671 .inherits = &ata_sff_port_ops,
21672 .qc_issue = mpiix_qc_issue,
21673 .cable_detect = ata_cable_40wire,
21674 diff -urNp linux-2.6.37/drivers/ata/pata_netcell.c linux-2.6.37/drivers/ata/pata_netcell.c
21675 --- linux-2.6.37/drivers/ata/pata_netcell.c 2011-01-04 19:50:19.000000000 -0500
21676 +++ linux-2.6.37/drivers/ata/pata_netcell.c 2011-01-17 02:41:01.000000000 -0500
21677 @@ -34,7 +34,7 @@ static struct scsi_host_template netcell
21678 ATA_BMDMA_SHT(DRV_NAME),
21681 -static struct ata_port_operations netcell_ops = {
21682 +static const struct ata_port_operations netcell_ops = {
21683 .inherits = &ata_bmdma_port_ops,
21684 .cable_detect = ata_cable_80wire,
21685 .read_id = netcell_read_id,
21686 diff -urNp linux-2.6.37/drivers/ata/pata_ninja32.c linux-2.6.37/drivers/ata/pata_ninja32.c
21687 --- linux-2.6.37/drivers/ata/pata_ninja32.c 2011-01-04 19:50:19.000000000 -0500
21688 +++ linux-2.6.37/drivers/ata/pata_ninja32.c 2011-01-17 02:41:01.000000000 -0500
21689 @@ -81,7 +81,7 @@ static struct scsi_host_template ninja32
21690 ATA_BMDMA_SHT(DRV_NAME),
21693 -static struct ata_port_operations ninja32_port_ops = {
21694 +static const struct ata_port_operations ninja32_port_ops = {
21695 .inherits = &ata_bmdma_port_ops,
21696 .sff_dev_select = ninja32_dev_select,
21697 .cable_detect = ata_cable_40wire,
21698 diff -urNp linux-2.6.37/drivers/ata/pata_ns87410.c linux-2.6.37/drivers/ata/pata_ns87410.c
21699 --- linux-2.6.37/drivers/ata/pata_ns87410.c 2011-01-04 19:50:19.000000000 -0500
21700 +++ linux-2.6.37/drivers/ata/pata_ns87410.c 2011-01-17 02:41:01.000000000 -0500
21701 @@ -132,7 +132,7 @@ static struct scsi_host_template ns87410
21702 ATA_PIO_SHT(DRV_NAME),
21705 -static struct ata_port_operations ns87410_port_ops = {
21706 +static const struct ata_port_operations ns87410_port_ops = {
21707 .inherits = &ata_sff_port_ops,
21708 .qc_issue = ns87410_qc_issue,
21709 .cable_detect = ata_cable_40wire,
21710 diff -urNp linux-2.6.37/drivers/ata/pata_ns87415.c linux-2.6.37/drivers/ata/pata_ns87415.c
21711 --- linux-2.6.37/drivers/ata/pata_ns87415.c 2011-01-04 19:50:19.000000000 -0500
21712 +++ linux-2.6.37/drivers/ata/pata_ns87415.c 2011-01-17 02:41:01.000000000 -0500
21713 @@ -299,7 +299,7 @@ static u8 ns87560_bmdma_status(struct at
21715 #endif /* 87560 SuperIO Support */
21717 -static struct ata_port_operations ns87415_pata_ops = {
21718 +static const struct ata_port_operations ns87415_pata_ops = {
21719 .inherits = &ata_bmdma_port_ops,
21721 .check_atapi_dma = ns87415_check_atapi_dma,
21722 @@ -313,7 +313,7 @@ static struct ata_port_operations ns8741
21725 #if defined(CONFIG_SUPERIO)
21726 -static struct ata_port_operations ns87560_pata_ops = {
21727 +static const struct ata_port_operations ns87560_pata_ops = {
21728 .inherits = &ns87415_pata_ops,
21729 .sff_tf_read = ns87560_tf_read,
21730 .sff_check_status = ns87560_check_status,
21731 diff -urNp linux-2.6.37/drivers/ata/pata_octeon_cf.c linux-2.6.37/drivers/ata/pata_octeon_cf.c
21732 --- linux-2.6.37/drivers/ata/pata_octeon_cf.c 2011-01-04 19:50:19.000000000 -0500
21733 +++ linux-2.6.37/drivers/ata/pata_octeon_cf.c 2011-01-17 02:41:01.000000000 -0500
21734 @@ -780,6 +780,7 @@ static unsigned int octeon_cf_qc_issue(s
21738 +/* cannot be const */
21739 static struct ata_port_operations octeon_cf_ops = {
21740 .inherits = &ata_sff_port_ops,
21741 .check_atapi_dma = octeon_cf_check_atapi_dma,
21742 diff -urNp linux-2.6.37/drivers/ata/pata_oldpiix.c linux-2.6.37/drivers/ata/pata_oldpiix.c
21743 --- linux-2.6.37/drivers/ata/pata_oldpiix.c 2011-01-04 19:50:19.000000000 -0500
21744 +++ linux-2.6.37/drivers/ata/pata_oldpiix.c 2011-01-17 02:41:01.000000000 -0500
21745 @@ -208,7 +208,7 @@ static struct scsi_host_template oldpiix
21746 ATA_BMDMA_SHT(DRV_NAME),
21749 -static struct ata_port_operations oldpiix_pata_ops = {
21750 +static const struct ata_port_operations oldpiix_pata_ops = {
21751 .inherits = &ata_bmdma_port_ops,
21752 .qc_issue = oldpiix_qc_issue,
21753 .cable_detect = ata_cable_40wire,
21754 diff -urNp linux-2.6.37/drivers/ata/pata_opti.c linux-2.6.37/drivers/ata/pata_opti.c
21755 --- linux-2.6.37/drivers/ata/pata_opti.c 2011-01-04 19:50:19.000000000 -0500
21756 +++ linux-2.6.37/drivers/ata/pata_opti.c 2011-01-17 02:41:01.000000000 -0500
21757 @@ -152,7 +152,7 @@ static struct scsi_host_template opti_sh
21758 ATA_PIO_SHT(DRV_NAME),
21761 -static struct ata_port_operations opti_port_ops = {
21762 +static const struct ata_port_operations opti_port_ops = {
21763 .inherits = &ata_sff_port_ops,
21764 .cable_detect = ata_cable_40wire,
21765 .set_piomode = opti_set_piomode,
21766 diff -urNp linux-2.6.37/drivers/ata/pata_optidma.c linux-2.6.37/drivers/ata/pata_optidma.c
21767 --- linux-2.6.37/drivers/ata/pata_optidma.c 2011-01-04 19:50:19.000000000 -0500
21768 +++ linux-2.6.37/drivers/ata/pata_optidma.c 2011-01-17 02:41:01.000000000 -0500
21769 @@ -337,7 +337,7 @@ static struct scsi_host_template optidma
21770 ATA_BMDMA_SHT(DRV_NAME),
21773 -static struct ata_port_operations optidma_port_ops = {
21774 +static const struct ata_port_operations optidma_port_ops = {
21775 .inherits = &ata_bmdma_port_ops,
21776 .cable_detect = ata_cable_40wire,
21777 .set_piomode = optidma_set_pio_mode,
21778 @@ -346,7 +346,7 @@ static struct ata_port_operations optidm
21779 .prereset = optidma_pre_reset,
21782 -static struct ata_port_operations optiplus_port_ops = {
21783 +static const struct ata_port_operations optiplus_port_ops = {
21784 .inherits = &optidma_port_ops,
21785 .set_piomode = optiplus_set_pio_mode,
21786 .set_dmamode = optiplus_set_dma_mode,
21787 diff -urNp linux-2.6.37/drivers/ata/pata_palmld.c linux-2.6.37/drivers/ata/pata_palmld.c
21788 --- linux-2.6.37/drivers/ata/pata_palmld.c 2011-01-04 19:50:19.000000000 -0500
21789 +++ linux-2.6.37/drivers/ata/pata_palmld.c 2011-01-17 02:41:01.000000000 -0500
21790 @@ -37,7 +37,7 @@ static struct scsi_host_template palmld_
21791 ATA_PIO_SHT(DRV_NAME),
21794 -static struct ata_port_operations palmld_port_ops = {
21795 +static const struct ata_port_operations palmld_port_ops = {
21796 .inherits = &ata_sff_port_ops,
21797 .sff_data_xfer = ata_sff_data_xfer_noirq,
21798 .cable_detect = ata_cable_40wire,
21799 diff -urNp linux-2.6.37/drivers/ata/pata_pcmcia.c linux-2.6.37/drivers/ata/pata_pcmcia.c
21800 --- linux-2.6.37/drivers/ata/pata_pcmcia.c 2011-01-04 19:50:19.000000000 -0500
21801 +++ linux-2.6.37/drivers/ata/pata_pcmcia.c 2011-01-17 02:41:01.000000000 -0500
21802 @@ -151,14 +151,14 @@ static struct scsi_host_template pcmcia_
21803 ATA_PIO_SHT(DRV_NAME),
21806 -static struct ata_port_operations pcmcia_port_ops = {
21807 +static const struct ata_port_operations pcmcia_port_ops = {
21808 .inherits = &ata_sff_port_ops,
21809 .sff_data_xfer = ata_sff_data_xfer_noirq,
21810 .cable_detect = ata_cable_40wire,
21811 .set_mode = pcmcia_set_mode,
21814 -static struct ata_port_operations pcmcia_8bit_port_ops = {
21815 +static const struct ata_port_operations pcmcia_8bit_port_ops = {
21816 .inherits = &ata_sff_port_ops,
21817 .sff_data_xfer = ata_data_xfer_8bit,
21818 .cable_detect = ata_cable_40wire,
21819 @@ -205,7 +205,7 @@ static int pcmcia_init_one(struct pcmcia
21820 unsigned long io_base, ctl_base;
21821 void __iomem *io_addr, *ctl_addr;
21823 - struct ata_port_operations *ops = &pcmcia_port_ops;
21824 + const struct ata_port_operations *ops = &pcmcia_port_ops;
21826 /* Set up attributes in order to probe card and get resources */
21827 pdev->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IO |
21828 diff -urNp linux-2.6.37/drivers/ata/pata_pdc2027x.c linux-2.6.37/drivers/ata/pata_pdc2027x.c
21829 --- linux-2.6.37/drivers/ata/pata_pdc2027x.c 2011-01-04 19:50:19.000000000 -0500
21830 +++ linux-2.6.37/drivers/ata/pata_pdc2027x.c 2011-01-17 02:41:01.000000000 -0500
21831 @@ -132,14 +132,14 @@ static struct scsi_host_template pdc2027
21832 ATA_BMDMA_SHT(DRV_NAME),
21835 -static struct ata_port_operations pdc2027x_pata100_ops = {
21836 +static const struct ata_port_operations pdc2027x_pata100_ops = {
21837 .inherits = &ata_bmdma_port_ops,
21838 .check_atapi_dma = pdc2027x_check_atapi_dma,
21839 .cable_detect = pdc2027x_cable_detect,
21840 .prereset = pdc2027x_prereset,
21843 -static struct ata_port_operations pdc2027x_pata133_ops = {
21844 +static const struct ata_port_operations pdc2027x_pata133_ops = {
21845 .inherits = &pdc2027x_pata100_ops,
21846 .mode_filter = pdc2027x_mode_filter,
21847 .set_piomode = pdc2027x_set_piomode,
21848 diff -urNp linux-2.6.37/drivers/ata/pata_pdc202xx_old.c linux-2.6.37/drivers/ata/pata_pdc202xx_old.c
21849 --- linux-2.6.37/drivers/ata/pata_pdc202xx_old.c 2011-01-04 19:50:19.000000000 -0500
21850 +++ linux-2.6.37/drivers/ata/pata_pdc202xx_old.c 2011-01-17 02:41:01.000000000 -0500
21851 @@ -295,7 +295,7 @@ static struct scsi_host_template pdc202x
21852 ATA_BMDMA_SHT(DRV_NAME),
21855 -static struct ata_port_operations pdc2024x_port_ops = {
21856 +static const struct ata_port_operations pdc2024x_port_ops = {
21857 .inherits = &ata_bmdma_port_ops,
21859 .cable_detect = ata_cable_40wire,
21860 @@ -306,7 +306,7 @@ static struct ata_port_operations pdc202
21861 .sff_irq_check = pdc202xx_irq_check,
21864 -static struct ata_port_operations pdc2026x_port_ops = {
21865 +static const struct ata_port_operations pdc2026x_port_ops = {
21866 .inherits = &pdc2024x_port_ops,
21868 .check_atapi_dma = pdc2026x_check_atapi_dma,
21869 diff -urNp linux-2.6.37/drivers/ata/pata_piccolo.c linux-2.6.37/drivers/ata/pata_piccolo.c
21870 --- linux-2.6.37/drivers/ata/pata_piccolo.c 2011-01-04 19:50:19.000000000 -0500
21871 +++ linux-2.6.37/drivers/ata/pata_piccolo.c 2011-01-17 02:41:01.000000000 -0500
21872 @@ -67,7 +67,7 @@ static struct scsi_host_template tosh_sh
21873 ATA_BMDMA_SHT(DRV_NAME),
21876 -static struct ata_port_operations tosh_port_ops = {
21877 +static const struct ata_port_operations tosh_port_ops = {
21878 .inherits = &ata_bmdma_port_ops,
21879 .cable_detect = ata_cable_unknown,
21880 .set_piomode = tosh_set_piomode,
21881 diff -urNp linux-2.6.37/drivers/ata/pata_platform.c linux-2.6.37/drivers/ata/pata_platform.c
21882 --- linux-2.6.37/drivers/ata/pata_platform.c 2011-01-04 19:50:19.000000000 -0500
21883 +++ linux-2.6.37/drivers/ata/pata_platform.c 2011-01-17 02:41:01.000000000 -0500
21884 @@ -48,7 +48,7 @@ static struct scsi_host_template pata_pl
21885 ATA_PIO_SHT(DRV_NAME),
21888 -static struct ata_port_operations pata_platform_port_ops = {
21889 +static const struct ata_port_operations pata_platform_port_ops = {
21890 .inherits = &ata_sff_port_ops,
21891 .sff_data_xfer = ata_sff_data_xfer_noirq,
21892 .cable_detect = ata_cable_unknown,
21893 diff -urNp linux-2.6.37/drivers/ata/pata_pxa.c linux-2.6.37/drivers/ata/pata_pxa.c
21894 --- linux-2.6.37/drivers/ata/pata_pxa.c 2011-01-04 19:50:19.000000000 -0500
21895 +++ linux-2.6.37/drivers/ata/pata_pxa.c 2011-01-17 02:41:01.000000000 -0500
21896 @@ -198,7 +198,7 @@ static struct scsi_host_template pxa_ata
21897 ATA_BMDMA_SHT(DRV_NAME),
21900 -static struct ata_port_operations pxa_ata_port_ops = {
21901 +static const struct ata_port_operations pxa_ata_port_ops = {
21902 .inherits = &ata_bmdma_port_ops,
21903 .cable_detect = ata_cable_40wire,
21905 diff -urNp linux-2.6.37/drivers/ata/pata_qdi.c linux-2.6.37/drivers/ata/pata_qdi.c
21906 --- linux-2.6.37/drivers/ata/pata_qdi.c 2011-01-04 19:50:19.000000000 -0500
21907 +++ linux-2.6.37/drivers/ata/pata_qdi.c 2011-01-17 02:41:01.000000000 -0500
21908 @@ -157,7 +157,7 @@ static struct scsi_host_template qdi_sht
21909 ATA_PIO_SHT(DRV_NAME),
21912 -static struct ata_port_operations qdi6500_port_ops = {
21913 +static const struct ata_port_operations qdi6500_port_ops = {
21914 .inherits = &ata_sff_port_ops,
21915 .qc_issue = qdi_qc_issue,
21916 .sff_data_xfer = qdi_data_xfer,
21917 @@ -165,7 +165,7 @@ static struct ata_port_operations qdi650
21918 .set_piomode = qdi6500_set_piomode,
21921 -static struct ata_port_operations qdi6580_port_ops = {
21922 +static const struct ata_port_operations qdi6580_port_ops = {
21923 .inherits = &qdi6500_port_ops,
21924 .set_piomode = qdi6580_set_piomode,
21926 diff -urNp linux-2.6.37/drivers/ata/pata_radisys.c linux-2.6.37/drivers/ata/pata_radisys.c
21927 --- linux-2.6.37/drivers/ata/pata_radisys.c 2011-01-04 19:50:19.000000000 -0500
21928 +++ linux-2.6.37/drivers/ata/pata_radisys.c 2011-01-17 02:41:01.000000000 -0500
21929 @@ -187,7 +187,7 @@ static struct scsi_host_template radisys
21930 ATA_BMDMA_SHT(DRV_NAME),
21933 -static struct ata_port_operations radisys_pata_ops = {
21934 +static const struct ata_port_operations radisys_pata_ops = {
21935 .inherits = &ata_bmdma_port_ops,
21936 .qc_issue = radisys_qc_issue,
21937 .cable_detect = ata_cable_unknown,
21938 diff -urNp linux-2.6.37/drivers/ata/pata_rb532_cf.c linux-2.6.37/drivers/ata/pata_rb532_cf.c
21939 --- linux-2.6.37/drivers/ata/pata_rb532_cf.c 2011-01-04 19:50:19.000000000 -0500
21940 +++ linux-2.6.37/drivers/ata/pata_rb532_cf.c 2011-01-17 02:41:01.000000000 -0500
21941 @@ -69,7 +69,7 @@ static irqreturn_t rb532_pata_irq_handle
21942 return IRQ_HANDLED;
21945 -static struct ata_port_operations rb532_pata_port_ops = {
21946 +static const struct ata_port_operations rb532_pata_port_ops = {
21947 .inherits = &ata_sff_port_ops,
21948 .sff_data_xfer = ata_sff_data_xfer32,
21950 diff -urNp linux-2.6.37/drivers/ata/pata_rdc.c linux-2.6.37/drivers/ata/pata_rdc.c
21951 --- linux-2.6.37/drivers/ata/pata_rdc.c 2011-01-04 19:50:19.000000000 -0500
21952 +++ linux-2.6.37/drivers/ata/pata_rdc.c 2011-01-17 02:41:01.000000000 -0500
21953 @@ -273,7 +273,7 @@ static void rdc_set_dmamode(struct ata_p
21954 pci_write_config_byte(dev, 0x48, udma_enable);
21957 -static struct ata_port_operations rdc_pata_ops = {
21958 +static const struct ata_port_operations rdc_pata_ops = {
21959 .inherits = &ata_bmdma32_port_ops,
21960 .cable_detect = rdc_pata_cable_detect,
21961 .set_piomode = rdc_set_piomode,
21962 diff -urNp linux-2.6.37/drivers/ata/pata_rz1000.c linux-2.6.37/drivers/ata/pata_rz1000.c
21963 --- linux-2.6.37/drivers/ata/pata_rz1000.c 2011-01-04 19:50:19.000000000 -0500
21964 +++ linux-2.6.37/drivers/ata/pata_rz1000.c 2011-01-17 02:41:01.000000000 -0500
21965 @@ -54,7 +54,7 @@ static struct scsi_host_template rz1000_
21966 ATA_PIO_SHT(DRV_NAME),
21969 -static struct ata_port_operations rz1000_port_ops = {
21970 +static const struct ata_port_operations rz1000_port_ops = {
21971 .inherits = &ata_sff_port_ops,
21972 .cable_detect = ata_cable_40wire,
21973 .set_mode = rz1000_set_mode,
21974 diff -urNp linux-2.6.37/drivers/ata/pata_samsung_cf.c linux-2.6.37/drivers/ata/pata_samsung_cf.c
21975 --- linux-2.6.37/drivers/ata/pata_samsung_cf.c 2011-01-04 19:50:19.000000000 -0500
21976 +++ linux-2.6.37/drivers/ata/pata_samsung_cf.c 2011-01-17 02:41:01.000000000 -0500
21977 @@ -399,7 +399,7 @@ static struct scsi_host_template pata_s3
21978 ATA_PIO_SHT(DRV_NAME),
21981 -static struct ata_port_operations pata_s3c_port_ops = {
21982 +static const struct ata_port_operations pata_s3c_port_ops = {
21983 .inherits = &ata_sff_port_ops,
21984 .sff_check_status = pata_s3c_check_status,
21985 .sff_check_altstatus = pata_s3c_check_altstatus,
21986 @@ -413,7 +413,7 @@ static struct ata_port_operations pata_s
21987 .set_piomode = pata_s3c_set_piomode,
21990 -static struct ata_port_operations pata_s5p_port_ops = {
21991 +static const struct ata_port_operations pata_s5p_port_ops = {
21992 .inherits = &ata_sff_port_ops,
21993 .set_piomode = pata_s3c_set_piomode,
21995 diff -urNp linux-2.6.37/drivers/ata/pata_sc1200.c linux-2.6.37/drivers/ata/pata_sc1200.c
21996 --- linux-2.6.37/drivers/ata/pata_sc1200.c 2011-01-04 19:50:19.000000000 -0500
21997 +++ linux-2.6.37/drivers/ata/pata_sc1200.c 2011-01-17 02:41:01.000000000 -0500
21998 @@ -207,7 +207,7 @@ static struct scsi_host_template sc1200_
21999 .sg_tablesize = LIBATA_DUMB_MAX_PRD,
22002 -static struct ata_port_operations sc1200_port_ops = {
22003 +static const struct ata_port_operations sc1200_port_ops = {
22004 .inherits = &ata_bmdma_port_ops,
22005 .qc_prep = ata_bmdma_dumb_qc_prep,
22006 .qc_issue = sc1200_qc_issue,
22007 diff -urNp linux-2.6.37/drivers/ata/pata_scc.c linux-2.6.37/drivers/ata/pata_scc.c
22008 --- linux-2.6.37/drivers/ata/pata_scc.c 2011-01-04 19:50:19.000000000 -0500
22009 +++ linux-2.6.37/drivers/ata/pata_scc.c 2011-01-17 02:41:01.000000000 -0500
22010 @@ -926,7 +926,7 @@ static struct scsi_host_template scc_sht
22011 ATA_BMDMA_SHT(DRV_NAME),
22014 -static struct ata_port_operations scc_pata_ops = {
22015 +static const struct ata_port_operations scc_pata_ops = {
22016 .inherits = &ata_bmdma_port_ops,
22018 .set_piomode = scc_set_piomode,
22019 diff -urNp linux-2.6.37/drivers/ata/pata_sch.c linux-2.6.37/drivers/ata/pata_sch.c
22020 --- linux-2.6.37/drivers/ata/pata_sch.c 2011-01-04 19:50:19.000000000 -0500
22021 +++ linux-2.6.37/drivers/ata/pata_sch.c 2011-01-17 02:41:01.000000000 -0500
22022 @@ -75,7 +75,7 @@ static struct scsi_host_template sch_sht
22023 ATA_BMDMA_SHT(DRV_NAME),
22026 -static struct ata_port_operations sch_pata_ops = {
22027 +static const struct ata_port_operations sch_pata_ops = {
22028 .inherits = &ata_bmdma_port_ops,
22029 .cable_detect = ata_cable_unknown,
22030 .set_piomode = sch_set_piomode,
22031 diff -urNp linux-2.6.37/drivers/ata/pata_serverworks.c linux-2.6.37/drivers/ata/pata_serverworks.c
22032 --- linux-2.6.37/drivers/ata/pata_serverworks.c 2011-01-04 19:50:19.000000000 -0500
22033 +++ linux-2.6.37/drivers/ata/pata_serverworks.c 2011-01-17 02:41:01.000000000 -0500
22034 @@ -300,7 +300,7 @@ static struct scsi_host_template serverw
22035 ATA_BMDMA_SHT(DRV_NAME),
22038 -static struct ata_port_operations serverworks_osb4_port_ops = {
22039 +static const struct ata_port_operations serverworks_osb4_port_ops = {
22040 .inherits = &ata_bmdma_port_ops,
22041 .cable_detect = serverworks_cable_detect,
22042 .mode_filter = serverworks_osb4_filter,
22043 @@ -308,7 +308,7 @@ static struct ata_port_operations server
22044 .set_dmamode = serverworks_set_dmamode,
22047 -static struct ata_port_operations serverworks_csb_port_ops = {
22048 +static const struct ata_port_operations serverworks_csb_port_ops = {
22049 .inherits = &serverworks_osb4_port_ops,
22050 .mode_filter = serverworks_csb_filter,
22052 diff -urNp linux-2.6.37/drivers/ata/pata_sil680.c linux-2.6.37/drivers/ata/pata_sil680.c
22053 --- linux-2.6.37/drivers/ata/pata_sil680.c 2011-01-04 19:50:19.000000000 -0500
22054 +++ linux-2.6.37/drivers/ata/pata_sil680.c 2011-01-17 02:41:01.000000000 -0500
22055 @@ -225,8 +225,7 @@ static struct scsi_host_template sil680_
22056 ATA_BMDMA_SHT(DRV_NAME),
22060 -static struct ata_port_operations sil680_port_ops = {
22061 +static const struct ata_port_operations sil680_port_ops = {
22062 .inherits = &ata_bmdma32_port_ops,
22063 .sff_exec_command = sil680_sff_exec_command,
22064 .sff_irq_check = sil680_sff_irq_check,
22065 diff -urNp linux-2.6.37/drivers/ata/pata_sis.c linux-2.6.37/drivers/ata/pata_sis.c
22066 --- linux-2.6.37/drivers/ata/pata_sis.c 2011-01-04 19:50:19.000000000 -0500
22067 +++ linux-2.6.37/drivers/ata/pata_sis.c 2011-01-17 02:41:01.000000000 -0500
22068 @@ -503,47 +503,47 @@ static struct scsi_host_template sis_sht
22069 ATA_BMDMA_SHT(DRV_NAME),
22072 -static struct ata_port_operations sis_133_for_sata_ops = {
22073 +static const struct ata_port_operations sis_133_for_sata_ops = {
22074 .inherits = &ata_bmdma_port_ops,
22075 .set_piomode = sis_133_set_piomode,
22076 .set_dmamode = sis_133_set_dmamode,
22077 .cable_detect = sis_133_cable_detect,
22080 -static struct ata_port_operations sis_base_ops = {
22081 +static const struct ata_port_operations sis_base_ops = {
22082 .inherits = &ata_bmdma_port_ops,
22083 .prereset = sis_pre_reset,
22086 -static struct ata_port_operations sis_133_ops = {
22087 +static const struct ata_port_operations sis_133_ops = {
22088 .inherits = &sis_base_ops,
22089 .set_piomode = sis_133_set_piomode,
22090 .set_dmamode = sis_133_set_dmamode,
22091 .cable_detect = sis_133_cable_detect,
22094 -static struct ata_port_operations sis_133_early_ops = {
22095 +static const struct ata_port_operations sis_133_early_ops = {
22096 .inherits = &sis_base_ops,
22097 .set_piomode = sis_100_set_piomode,
22098 .set_dmamode = sis_133_early_set_dmamode,
22099 .cable_detect = sis_66_cable_detect,
22102 -static struct ata_port_operations sis_100_ops = {
22103 +static const struct ata_port_operations sis_100_ops = {
22104 .inherits = &sis_base_ops,
22105 .set_piomode = sis_100_set_piomode,
22106 .set_dmamode = sis_100_set_dmamode,
22107 .cable_detect = sis_66_cable_detect,
22110 -static struct ata_port_operations sis_66_ops = {
22111 +static const struct ata_port_operations sis_66_ops = {
22112 .inherits = &sis_base_ops,
22113 .set_piomode = sis_old_set_piomode,
22114 .set_dmamode = sis_66_set_dmamode,
22115 .cable_detect = sis_66_cable_detect,
22118 -static struct ata_port_operations sis_old_ops = {
22119 +static const struct ata_port_operations sis_old_ops = {
22120 .inherits = &sis_base_ops,
22121 .set_piomode = sis_old_set_piomode,
22122 .set_dmamode = sis_old_set_dmamode,
22123 diff -urNp linux-2.6.37/drivers/ata/pata_sl82c105.c linux-2.6.37/drivers/ata/pata_sl82c105.c
22124 --- linux-2.6.37/drivers/ata/pata_sl82c105.c 2011-01-04 19:50:19.000000000 -0500
22125 +++ linux-2.6.37/drivers/ata/pata_sl82c105.c 2011-01-17 02:41:01.000000000 -0500
22126 @@ -241,7 +241,7 @@ static struct scsi_host_template sl82c10
22127 ATA_BMDMA_SHT(DRV_NAME),
22130 -static struct ata_port_operations sl82c105_port_ops = {
22131 +static const struct ata_port_operations sl82c105_port_ops = {
22132 .inherits = &ata_bmdma_port_ops,
22133 .qc_defer = sl82c105_qc_defer,
22134 .bmdma_start = sl82c105_bmdma_start,
22135 diff -urNp linux-2.6.37/drivers/ata/pata_triflex.c linux-2.6.37/drivers/ata/pata_triflex.c
22136 --- linux-2.6.37/drivers/ata/pata_triflex.c 2011-01-04 19:50:19.000000000 -0500
22137 +++ linux-2.6.37/drivers/ata/pata_triflex.c 2011-01-17 02:41:01.000000000 -0500
22138 @@ -178,7 +178,7 @@ static struct scsi_host_template triflex
22139 ATA_BMDMA_SHT(DRV_NAME),
22142 -static struct ata_port_operations triflex_port_ops = {
22143 +static const struct ata_port_operations triflex_port_ops = {
22144 .inherits = &ata_bmdma_port_ops,
22145 .bmdma_start = triflex_bmdma_start,
22146 .bmdma_stop = triflex_bmdma_stop,
22147 diff -urNp linux-2.6.37/drivers/ata/pata_via.c linux-2.6.37/drivers/ata/pata_via.c
22148 --- linux-2.6.37/drivers/ata/pata_via.c 2011-01-04 19:50:19.000000000 -0500
22149 +++ linux-2.6.37/drivers/ata/pata_via.c 2011-01-17 02:41:01.000000000 -0500
22150 @@ -441,7 +441,7 @@ static struct scsi_host_template via_sht
22151 ATA_BMDMA_SHT(DRV_NAME),
22154 -static struct ata_port_operations via_port_ops = {
22155 +static const struct ata_port_operations via_port_ops = {
22156 .inherits = &ata_bmdma_port_ops,
22157 .cable_detect = via_cable_detect,
22158 .set_piomode = via_set_piomode,
22159 @@ -452,7 +452,7 @@ static struct ata_port_operations via_po
22160 .mode_filter = via_mode_filter,
22163 -static struct ata_port_operations via_port_ops_noirq = {
22164 +static const struct ata_port_operations via_port_ops_noirq = {
22165 .inherits = &via_port_ops,
22166 .sff_data_xfer = ata_sff_data_xfer_noirq,
22168 diff -urNp linux-2.6.37/drivers/ata/pdc_adma.c linux-2.6.37/drivers/ata/pdc_adma.c
22169 --- linux-2.6.37/drivers/ata/pdc_adma.c 2011-01-04 19:50:19.000000000 -0500
22170 +++ linux-2.6.37/drivers/ata/pdc_adma.c 2011-01-17 02:41:01.000000000 -0500
22171 @@ -146,7 +146,7 @@ static struct scsi_host_template adma_at
22172 .dma_boundary = ADMA_DMA_BOUNDARY,
22175 -static struct ata_port_operations adma_ata_ops = {
22176 +static const struct ata_port_operations adma_ata_ops = {
22177 .inherits = &ata_sff_port_ops,
22179 .lost_interrupt = ATA_OP_NULL,
22180 diff -urNp linux-2.6.37/drivers/ata/sata_dwc_460ex.c linux-2.6.37/drivers/ata/sata_dwc_460ex.c
22181 --- linux-2.6.37/drivers/ata/sata_dwc_460ex.c 2011-01-04 19:50:19.000000000 -0500
22182 +++ linux-2.6.37/drivers/ata/sata_dwc_460ex.c 2011-01-17 02:41:01.000000000 -0500
22183 @@ -1560,7 +1560,7 @@ static struct scsi_host_template sata_dw
22184 .dma_boundary = ATA_DMA_BOUNDARY,
22187 -static struct ata_port_operations sata_dwc_ops = {
22188 +static const struct ata_port_operations sata_dwc_ops = {
22189 .inherits = &ata_sff_port_ops,
22191 .error_handler = sata_dwc_error_handler,
22192 diff -urNp linux-2.6.37/drivers/ata/sata_fsl.c linux-2.6.37/drivers/ata/sata_fsl.c
22193 --- linux-2.6.37/drivers/ata/sata_fsl.c 2011-01-04 19:50:19.000000000 -0500
22194 +++ linux-2.6.37/drivers/ata/sata_fsl.c 2011-01-17 02:41:01.000000000 -0500
22195 @@ -1258,7 +1258,7 @@ static struct scsi_host_template sata_fs
22196 .dma_boundary = ATA_DMA_BOUNDARY,
22199 -static struct ata_port_operations sata_fsl_ops = {
22200 +static const struct ata_port_operations sata_fsl_ops = {
22201 .inherits = &sata_pmp_port_ops,
22203 .qc_defer = ata_std_qc_defer,
22204 diff -urNp linux-2.6.37/drivers/ata/sata_inic162x.c linux-2.6.37/drivers/ata/sata_inic162x.c
22205 --- linux-2.6.37/drivers/ata/sata_inic162x.c 2011-01-04 19:50:19.000000000 -0500
22206 +++ linux-2.6.37/drivers/ata/sata_inic162x.c 2011-01-17 02:41:01.000000000 -0500
22207 @@ -705,7 +705,7 @@ static int inic_port_start(struct ata_po
22211 -static struct ata_port_operations inic_port_ops = {
22212 +static const struct ata_port_operations inic_port_ops = {
22213 .inherits = &sata_port_ops,
22215 .check_atapi_dma = inic_check_atapi_dma,
22216 diff -urNp linux-2.6.37/drivers/ata/sata_mv.c linux-2.6.37/drivers/ata/sata_mv.c
22217 --- linux-2.6.37/drivers/ata/sata_mv.c 2011-01-04 19:50:19.000000000 -0500
22218 +++ linux-2.6.37/drivers/ata/sata_mv.c 2011-01-17 02:41:01.000000000 -0500
22219 @@ -663,7 +663,7 @@ static struct scsi_host_template mv6_sht
22220 .dma_boundary = MV_DMA_BOUNDARY,
22223 -static struct ata_port_operations mv5_ops = {
22224 +static const struct ata_port_operations mv5_ops = {
22225 .inherits = &ata_sff_port_ops,
22227 .lost_interrupt = ATA_OP_NULL,
22228 @@ -683,7 +683,7 @@ static struct ata_port_operations mv5_op
22229 .port_stop = mv_port_stop,
22232 -static struct ata_port_operations mv6_ops = {
22233 +static const struct ata_port_operations mv6_ops = {
22234 .inherits = &ata_bmdma_port_ops,
22236 .lost_interrupt = ATA_OP_NULL,
22237 @@ -717,7 +717,7 @@ static struct ata_port_operations mv6_op
22238 .port_stop = mv_port_stop,
22241 -static struct ata_port_operations mv_iie_ops = {
22242 +static const struct ata_port_operations mv_iie_ops = {
22243 .inherits = &mv6_ops,
22244 .dev_config = ATA_OP_NULL,
22245 .qc_prep = mv_qc_prep_iie,
22246 diff -urNp linux-2.6.37/drivers/ata/sata_nv.c linux-2.6.37/drivers/ata/sata_nv.c
22247 --- linux-2.6.37/drivers/ata/sata_nv.c 2011-01-04 19:50:19.000000000 -0500
22248 +++ linux-2.6.37/drivers/ata/sata_nv.c 2011-01-17 02:41:01.000000000 -0500
22249 @@ -465,7 +465,7 @@ static struct scsi_host_template nv_swnc
22250 * cases. Define nv_hardreset() which only kicks in for post-boot
22251 * probing and use it for all variants.
22253 -static struct ata_port_operations nv_generic_ops = {
22254 +static const struct ata_port_operations nv_generic_ops = {
22255 .inherits = &ata_bmdma_port_ops,
22256 .lost_interrupt = ATA_OP_NULL,
22257 .scr_read = nv_scr_read,
22258 @@ -473,20 +473,20 @@ static struct ata_port_operations nv_gen
22259 .hardreset = nv_hardreset,
22262 -static struct ata_port_operations nv_nf2_ops = {
22263 +static const struct ata_port_operations nv_nf2_ops = {
22264 .inherits = &nv_generic_ops,
22265 .freeze = nv_nf2_freeze,
22266 .thaw = nv_nf2_thaw,
22269 -static struct ata_port_operations nv_ck804_ops = {
22270 +static const struct ata_port_operations nv_ck804_ops = {
22271 .inherits = &nv_generic_ops,
22272 .freeze = nv_ck804_freeze,
22273 .thaw = nv_ck804_thaw,
22274 .host_stop = nv_ck804_host_stop,
22277 -static struct ata_port_operations nv_adma_ops = {
22278 +static const struct ata_port_operations nv_adma_ops = {
22279 .inherits = &nv_ck804_ops,
22281 .check_atapi_dma = nv_adma_check_atapi_dma,
22282 @@ -510,7 +510,7 @@ static struct ata_port_operations nv_adm
22283 .host_stop = nv_adma_host_stop,
22286 -static struct ata_port_operations nv_swncq_ops = {
22287 +static const struct ata_port_operations nv_swncq_ops = {
22288 .inherits = &nv_generic_ops,
22290 .qc_defer = ata_std_qc_defer,
22291 diff -urNp linux-2.6.37/drivers/ata/sata_promise.c linux-2.6.37/drivers/ata/sata_promise.c
22292 --- linux-2.6.37/drivers/ata/sata_promise.c 2011-01-04 19:50:19.000000000 -0500
22293 +++ linux-2.6.37/drivers/ata/sata_promise.c 2011-01-17 02:41:01.000000000 -0500
22294 @@ -196,7 +196,7 @@ static const struct ata_port_operations
22295 .error_handler = pdc_error_handler,
22298 -static struct ata_port_operations pdc_sata_ops = {
22299 +static const struct ata_port_operations pdc_sata_ops = {
22300 .inherits = &pdc_common_ops,
22301 .cable_detect = pdc_sata_cable_detect,
22302 .freeze = pdc_sata_freeze,
22303 @@ -209,14 +209,14 @@ static struct ata_port_operations pdc_sa
22305 /* First-generation chips need a more restrictive ->check_atapi_dma op,
22306 and ->freeze/thaw that ignore the hotplug controls. */
22307 -static struct ata_port_operations pdc_old_sata_ops = {
22308 +static const struct ata_port_operations pdc_old_sata_ops = {
22309 .inherits = &pdc_sata_ops,
22310 .freeze = pdc_freeze,
22312 .check_atapi_dma = pdc_old_sata_check_atapi_dma,
22315 -static struct ata_port_operations pdc_pata_ops = {
22316 +static const struct ata_port_operations pdc_pata_ops = {
22317 .inherits = &pdc_common_ops,
22318 .cable_detect = pdc_pata_cable_detect,
22319 .freeze = pdc_freeze,
22320 diff -urNp linux-2.6.37/drivers/ata/sata_qstor.c linux-2.6.37/drivers/ata/sata_qstor.c
22321 --- linux-2.6.37/drivers/ata/sata_qstor.c 2011-01-04 19:50:19.000000000 -0500
22322 +++ linux-2.6.37/drivers/ata/sata_qstor.c 2011-01-17 02:41:01.000000000 -0500
22323 @@ -131,7 +131,7 @@ static struct scsi_host_template qs_ata_
22324 .dma_boundary = QS_DMA_BOUNDARY,
22327 -static struct ata_port_operations qs_ata_ops = {
22328 +static const struct ata_port_operations qs_ata_ops = {
22329 .inherits = &ata_sff_port_ops,
22331 .check_atapi_dma = qs_check_atapi_dma,
22332 diff -urNp linux-2.6.37/drivers/ata/sata_sil24.c linux-2.6.37/drivers/ata/sata_sil24.c
22333 --- linux-2.6.37/drivers/ata/sata_sil24.c 2011-01-04 19:50:19.000000000 -0500
22334 +++ linux-2.6.37/drivers/ata/sata_sil24.c 2011-01-17 02:41:01.000000000 -0500
22335 @@ -389,7 +389,7 @@ static struct scsi_host_template sil24_s
22336 .dma_boundary = ATA_DMA_BOUNDARY,
22339 -static struct ata_port_operations sil24_ops = {
22340 +static const struct ata_port_operations sil24_ops = {
22341 .inherits = &sata_pmp_port_ops,
22343 .qc_defer = sil24_qc_defer,
22344 diff -urNp linux-2.6.37/drivers/ata/sata_sil.c linux-2.6.37/drivers/ata/sata_sil.c
22345 --- linux-2.6.37/drivers/ata/sata_sil.c 2011-01-04 19:50:19.000000000 -0500
22346 +++ linux-2.6.37/drivers/ata/sata_sil.c 2011-01-17 02:41:01.000000000 -0500
22347 @@ -182,7 +182,7 @@ static struct scsi_host_template sil_sht
22348 .sg_tablesize = ATA_MAX_PRD
22351 -static struct ata_port_operations sil_ops = {
22352 +static const struct ata_port_operations sil_ops = {
22353 .inherits = &ata_bmdma32_port_ops,
22354 .dev_config = sil_dev_config,
22355 .set_mode = sil_set_mode,
22356 diff -urNp linux-2.6.37/drivers/ata/sata_sis.c linux-2.6.37/drivers/ata/sata_sis.c
22357 --- linux-2.6.37/drivers/ata/sata_sis.c 2011-01-04 19:50:19.000000000 -0500
22358 +++ linux-2.6.37/drivers/ata/sata_sis.c 2011-01-17 02:41:01.000000000 -0500
22359 @@ -89,7 +89,7 @@ static struct scsi_host_template sis_sht
22360 ATA_BMDMA_SHT(DRV_NAME),
22363 -static struct ata_port_operations sis_ops = {
22364 +static const struct ata_port_operations sis_ops = {
22365 .inherits = &ata_bmdma_port_ops,
22366 .scr_read = sis_scr_read,
22367 .scr_write = sis_scr_write,
22368 diff -urNp linux-2.6.37/drivers/ata/sata_svw.c linux-2.6.37/drivers/ata/sata_svw.c
22369 --- linux-2.6.37/drivers/ata/sata_svw.c 2011-01-04 19:50:19.000000000 -0500
22370 +++ linux-2.6.37/drivers/ata/sata_svw.c 2011-01-17 02:41:01.000000000 -0500
22371 @@ -344,7 +344,7 @@ static struct scsi_host_template k2_sata
22375 -static struct ata_port_operations k2_sata_ops = {
22376 +static const struct ata_port_operations k2_sata_ops = {
22377 .inherits = &ata_bmdma_port_ops,
22378 .sff_tf_load = k2_sata_tf_load,
22379 .sff_tf_read = k2_sata_tf_read,
22380 diff -urNp linux-2.6.37/drivers/ata/sata_sx4.c linux-2.6.37/drivers/ata/sata_sx4.c
22381 --- linux-2.6.37/drivers/ata/sata_sx4.c 2011-01-04 19:50:19.000000000 -0500
22382 +++ linux-2.6.37/drivers/ata/sata_sx4.c 2011-01-17 02:41:01.000000000 -0500
22383 @@ -249,7 +249,7 @@ static struct scsi_host_template pdc_sat
22386 /* TODO: inherit from base port_ops after converting to new EH */
22387 -static struct ata_port_operations pdc_20621_ops = {
22388 +static const struct ata_port_operations pdc_20621_ops = {
22389 .inherits = &ata_sff_port_ops,
22391 .check_atapi_dma = pdc_check_atapi_dma,
22392 diff -urNp linux-2.6.37/drivers/ata/sata_uli.c linux-2.6.37/drivers/ata/sata_uli.c
22393 --- linux-2.6.37/drivers/ata/sata_uli.c 2011-01-04 19:50:19.000000000 -0500
22394 +++ linux-2.6.37/drivers/ata/sata_uli.c 2011-01-17 02:41:01.000000000 -0500
22395 @@ -80,7 +80,7 @@ static struct scsi_host_template uli_sht
22396 ATA_BMDMA_SHT(DRV_NAME),
22399 -static struct ata_port_operations uli_ops = {
22400 +static const struct ata_port_operations uli_ops = {
22401 .inherits = &ata_bmdma_port_ops,
22402 .scr_read = uli_scr_read,
22403 .scr_write = uli_scr_write,
22404 diff -urNp linux-2.6.37/drivers/ata/sata_via.c linux-2.6.37/drivers/ata/sata_via.c
22405 --- linux-2.6.37/drivers/ata/sata_via.c 2011-01-04 19:50:19.000000000 -0500
22406 +++ linux-2.6.37/drivers/ata/sata_via.c 2011-01-17 02:41:01.000000000 -0500
22407 @@ -115,32 +115,32 @@ static struct scsi_host_template svia_sh
22408 ATA_BMDMA_SHT(DRV_NAME),
22411 -static struct ata_port_operations svia_base_ops = {
22412 +static const struct ata_port_operations svia_base_ops = {
22413 .inherits = &ata_bmdma_port_ops,
22414 .sff_tf_load = svia_tf_load,
22417 -static struct ata_port_operations vt6420_sata_ops = {
22418 +static const struct ata_port_operations vt6420_sata_ops = {
22419 .inherits = &svia_base_ops,
22420 .freeze = svia_noop_freeze,
22421 .prereset = vt6420_prereset,
22422 .bmdma_start = vt6420_bmdma_start,
22425 -static struct ata_port_operations vt6421_pata_ops = {
22426 +static const struct ata_port_operations vt6421_pata_ops = {
22427 .inherits = &svia_base_ops,
22428 .cable_detect = vt6421_pata_cable_detect,
22429 .set_piomode = vt6421_set_pio_mode,
22430 .set_dmamode = vt6421_set_dma_mode,
22433 -static struct ata_port_operations vt6421_sata_ops = {
22434 +static const struct ata_port_operations vt6421_sata_ops = {
22435 .inherits = &svia_base_ops,
22436 .scr_read = svia_scr_read,
22437 .scr_write = svia_scr_write,
22440 -static struct ata_port_operations vt8251_ops = {
22441 +static const struct ata_port_operations vt8251_ops = {
22442 .inherits = &svia_base_ops,
22443 .hardreset = sata_std_hardreset,
22444 .scr_read = vt8251_scr_read,
22445 diff -urNp linux-2.6.37/drivers/ata/sata_vsc.c linux-2.6.37/drivers/ata/sata_vsc.c
22446 --- linux-2.6.37/drivers/ata/sata_vsc.c 2011-01-04 19:50:19.000000000 -0500
22447 +++ linux-2.6.37/drivers/ata/sata_vsc.c 2011-01-17 02:41:01.000000000 -0500
22448 @@ -300,7 +300,7 @@ static struct scsi_host_template vsc_sat
22452 -static struct ata_port_operations vsc_sata_ops = {
22453 +static const struct ata_port_operations vsc_sata_ops = {
22454 .inherits = &ata_bmdma_port_ops,
22455 /* The IRQ handling is not quite standard SFF behaviour so we
22456 cannot use the default lost interrupt handler */
22457 diff -urNp linux-2.6.37/drivers/atm/adummy.c linux-2.6.37/drivers/atm/adummy.c
22458 --- linux-2.6.37/drivers/atm/adummy.c 2011-01-04 19:50:19.000000000 -0500
22459 +++ linux-2.6.37/drivers/atm/adummy.c 2011-01-17 02:41:01.000000000 -0500
22460 @@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct
22461 vcc->pop(vcc, skb);
22463 dev_kfree_skb_any(skb);
22464 - atomic_inc(&vcc->stats->tx);
22465 + atomic_inc_unchecked(&vcc->stats->tx);
22469 diff -urNp linux-2.6.37/drivers/atm/ambassador.c linux-2.6.37/drivers/atm/ambassador.c
22470 --- linux-2.6.37/drivers/atm/ambassador.c 2011-01-04 19:50:19.000000000 -0500
22471 +++ linux-2.6.37/drivers/atm/ambassador.c 2011-01-17 02:41:01.000000000 -0500
22472 @@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev,
22473 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
22476 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
22477 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
22479 // free the descriptor
22481 @@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev,
22482 dump_skb ("<<<", vc, skb);
22485 - atomic_inc(&atm_vcc->stats->rx);
22486 + atomic_inc_unchecked(&atm_vcc->stats->rx);
22487 __net_timestamp(skb);
22488 // end of our responsability
22489 atm_vcc->push (atm_vcc, skb);
22490 @@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev,
22492 PRINTK (KERN_INFO, "dropped over-size frame");
22493 // should we count this?
22494 - atomic_inc(&atm_vcc->stats->rx_drop);
22495 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
22499 @@ -1342,7 +1342,7 @@ static int amb_send (struct atm_vcc * at
22502 if (check_area (skb->data, skb->len)) {
22503 - atomic_inc(&atm_vcc->stats->tx_err);
22504 + atomic_inc_unchecked(&atm_vcc->stats->tx_err);
22505 return -ENOMEM; // ?
22508 diff -urNp linux-2.6.37/drivers/atm/atmtcp.c linux-2.6.37/drivers/atm/atmtcp.c
22509 --- linux-2.6.37/drivers/atm/atmtcp.c 2011-01-04 19:50:19.000000000 -0500
22510 +++ linux-2.6.37/drivers/atm/atmtcp.c 2011-01-17 02:41:01.000000000 -0500
22511 @@ -207,7 +207,7 @@ static int atmtcp_v_send(struct atm_vcc
22512 if (vcc->pop) vcc->pop(vcc,skb);
22513 else dev_kfree_skb(skb);
22514 if (dev_data) return 0;
22515 - atomic_inc(&vcc->stats->tx_err);
22516 + atomic_inc_unchecked(&vcc->stats->tx_err);
22519 size = skb->len+sizeof(struct atmtcp_hdr);
22520 @@ -215,7 +215,7 @@ static int atmtcp_v_send(struct atm_vcc
22522 if (vcc->pop) vcc->pop(vcc,skb);
22523 else dev_kfree_skb(skb);
22524 - atomic_inc(&vcc->stats->tx_err);
22525 + atomic_inc_unchecked(&vcc->stats->tx_err);
22528 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
22529 @@ -226,8 +226,8 @@ static int atmtcp_v_send(struct atm_vcc
22530 if (vcc->pop) vcc->pop(vcc,skb);
22531 else dev_kfree_skb(skb);
22532 out_vcc->push(out_vcc,new_skb);
22533 - atomic_inc(&vcc->stats->tx);
22534 - atomic_inc(&out_vcc->stats->rx);
22535 + atomic_inc_unchecked(&vcc->stats->tx);
22536 + atomic_inc_unchecked(&out_vcc->stats->rx);
22540 @@ -301,7 +301,7 @@ static int atmtcp_c_send(struct atm_vcc
22541 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
22542 read_unlock(&vcc_sklist_lock);
22544 - atomic_inc(&vcc->stats->tx_err);
22545 + atomic_inc_unchecked(&vcc->stats->tx_err);
22548 skb_pull(skb,sizeof(struct atmtcp_hdr));
22549 @@ -313,8 +313,8 @@ static int atmtcp_c_send(struct atm_vcc
22550 __net_timestamp(new_skb);
22551 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
22552 out_vcc->push(out_vcc,new_skb);
22553 - atomic_inc(&vcc->stats->tx);
22554 - atomic_inc(&out_vcc->stats->rx);
22555 + atomic_inc_unchecked(&vcc->stats->tx);
22556 + atomic_inc_unchecked(&out_vcc->stats->rx);
22558 if (vcc->pop) vcc->pop(vcc,skb);
22559 else dev_kfree_skb(skb);
22560 diff -urNp linux-2.6.37/drivers/atm/eni.c linux-2.6.37/drivers/atm/eni.c
22561 --- linux-2.6.37/drivers/atm/eni.c 2011-01-04 19:50:19.000000000 -0500
22562 +++ linux-2.6.37/drivers/atm/eni.c 2011-01-17 02:41:01.000000000 -0500
22563 @@ -526,7 +526,7 @@ static int rx_aal0(struct atm_vcc *vcc)
22564 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
22567 - atomic_inc(&vcc->stats->rx_err);
22568 + atomic_inc_unchecked(&vcc->stats->rx_err);
22571 length = ATM_CELL_SIZE-1; /* no HEC */
22572 @@ -581,7 +581,7 @@ static int rx_aal5(struct atm_vcc *vcc)
22576 - atomic_inc(&vcc->stats->rx_err);
22577 + atomic_inc_unchecked(&vcc->stats->rx_err);
22580 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
22581 @@ -598,7 +598,7 @@ static int rx_aal5(struct atm_vcc *vcc)
22582 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
22583 vcc->dev->number,vcc->vci,length,size << 2,descr);
22585 - atomic_inc(&vcc->stats->rx_err);
22586 + atomic_inc_unchecked(&vcc->stats->rx_err);
22589 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
22590 @@ -771,7 +771,7 @@ rx_dequeued++;
22591 vcc->push(vcc,skb);
22594 - atomic_inc(&vcc->stats->rx);
22595 + atomic_inc_unchecked(&vcc->stats->rx);
22597 wake_up(&eni_dev->rx_wait);
22599 @@ -1228,7 +1228,7 @@ static void dequeue_tx(struct atm_dev *d
22601 if (vcc->pop) vcc->pop(vcc,skb);
22602 else dev_kfree_skb_irq(skb);
22603 - atomic_inc(&vcc->stats->tx);
22604 + atomic_inc_unchecked(&vcc->stats->tx);
22605 wake_up(&eni_dev->tx_wait);
22608 diff -urNp linux-2.6.37/drivers/atm/firestream.c linux-2.6.37/drivers/atm/firestream.c
22609 --- linux-2.6.37/drivers/atm/firestream.c 2011-01-04 19:50:19.000000000 -0500
22610 +++ linux-2.6.37/drivers/atm/firestream.c 2011-01-17 02:41:01.000000000 -0500
22611 @@ -749,7 +749,7 @@ static void process_txdone_queue (struct
22615 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
22616 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
22618 fs_dprintk (FS_DEBUG_TXMEM, "i");
22619 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
22620 @@ -816,7 +816,7 @@ static void process_incoming (struct fs_
22622 skb_put (skb, qe->p1 & 0xffff);
22623 ATM_SKB(skb)->vcc = atm_vcc;
22624 - atomic_inc(&atm_vcc->stats->rx);
22625 + atomic_inc_unchecked(&atm_vcc->stats->rx);
22626 __net_timestamp(skb);
22627 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
22628 atm_vcc->push (atm_vcc, skb);
22629 @@ -837,12 +837,12 @@ static void process_incoming (struct fs_
22633 - atomic_inc(&atm_vcc->stats->rx_drop);
22634 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
22636 case 0x1f: /* Reassembly abort: no buffers. */
22637 /* Silently increment error counter. */
22639 - atomic_inc(&atm_vcc->stats->rx_drop);
22640 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
22642 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
22643 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
22644 diff -urNp linux-2.6.37/drivers/atm/fore200e.c linux-2.6.37/drivers/atm/fore200e.c
22645 --- linux-2.6.37/drivers/atm/fore200e.c 2011-01-04 19:50:19.000000000 -0500
22646 +++ linux-2.6.37/drivers/atm/fore200e.c 2011-01-17 02:41:01.000000000 -0500
22647 @@ -933,9 +933,9 @@ fore200e_tx_irq(struct fore200e* fore200
22649 /* check error condition */
22650 if (*entry->status & STATUS_ERROR)
22651 - atomic_inc(&vcc->stats->tx_err);
22652 + atomic_inc_unchecked(&vcc->stats->tx_err);
22654 - atomic_inc(&vcc->stats->tx);
22655 + atomic_inc_unchecked(&vcc->stats->tx);
22659 @@ -1084,7 +1084,7 @@ fore200e_push_rpd(struct fore200e* fore2
22661 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
22663 - atomic_inc(&vcc->stats->rx_drop);
22664 + atomic_inc_unchecked(&vcc->stats->rx_drop);
22668 @@ -1127,14 +1127,14 @@ fore200e_push_rpd(struct fore200e* fore2
22670 dev_kfree_skb_any(skb);
22672 - atomic_inc(&vcc->stats->rx_drop);
22673 + atomic_inc_unchecked(&vcc->stats->rx_drop);
22677 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
22679 vcc->push(vcc, skb);
22680 - atomic_inc(&vcc->stats->rx);
22681 + atomic_inc_unchecked(&vcc->stats->rx);
22683 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
22685 @@ -1212,7 +1212,7 @@ fore200e_rx_irq(struct fore200e* fore200
22686 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
22687 fore200e->atm_dev->number,
22688 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
22689 - atomic_inc(&vcc->stats->rx_err);
22690 + atomic_inc_unchecked(&vcc->stats->rx_err);
22694 @@ -1657,7 +1657,7 @@ fore200e_send(struct atm_vcc *vcc, struc
22698 - atomic_inc(&vcc->stats->tx_err);
22699 + atomic_inc_unchecked(&vcc->stats->tx_err);
22701 fore200e->tx_sat++;
22702 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
22703 diff -urNp linux-2.6.37/drivers/atm/he.c linux-2.6.37/drivers/atm/he.c
22704 --- linux-2.6.37/drivers/atm/he.c 2011-01-04 19:50:19.000000000 -0500
22705 +++ linux-2.6.37/drivers/atm/he.c 2011-01-17 02:41:01.000000000 -0500
22706 @@ -1709,7 +1709,7 @@ he_service_rbrq(struct he_dev *he_dev, i
22708 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
22709 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
22710 - atomic_inc(&vcc->stats->rx_drop);
22711 + atomic_inc_unchecked(&vcc->stats->rx_drop);
22712 goto return_host_buffers;
22715 @@ -1736,7 +1736,7 @@ he_service_rbrq(struct he_dev *he_dev, i
22716 RBRQ_LEN_ERR(he_dev->rbrq_head)
22718 vcc->vpi, vcc->vci);
22719 - atomic_inc(&vcc->stats->rx_err);
22720 + atomic_inc_unchecked(&vcc->stats->rx_err);
22721 goto return_host_buffers;
22724 @@ -1788,7 +1788,7 @@ he_service_rbrq(struct he_dev *he_dev, i
22725 vcc->push(vcc, skb);
22726 spin_lock(&he_dev->global_lock);
22728 - atomic_inc(&vcc->stats->rx);
22729 + atomic_inc_unchecked(&vcc->stats->rx);
22731 return_host_buffers:
22733 @@ -2114,7 +2114,7 @@ __enqueue_tpd(struct he_dev *he_dev, str
22734 tpd->vcc->pop(tpd->vcc, tpd->skb);
22736 dev_kfree_skb_any(tpd->skb);
22737 - atomic_inc(&tpd->vcc->stats->tx_err);
22738 + atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
22740 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
22742 @@ -2526,7 +2526,7 @@ he_send(struct atm_vcc *vcc, struct sk_b
22743 vcc->pop(vcc, skb);
22745 dev_kfree_skb_any(skb);
22746 - atomic_inc(&vcc->stats->tx_err);
22747 + atomic_inc_unchecked(&vcc->stats->tx_err);
22751 @@ -2537,7 +2537,7 @@ he_send(struct atm_vcc *vcc, struct sk_b
22752 vcc->pop(vcc, skb);
22754 dev_kfree_skb_any(skb);
22755 - atomic_inc(&vcc->stats->tx_err);
22756 + atomic_inc_unchecked(&vcc->stats->tx_err);
22760 @@ -2549,7 +2549,7 @@ he_send(struct atm_vcc *vcc, struct sk_b
22761 vcc->pop(vcc, skb);
22763 dev_kfree_skb_any(skb);
22764 - atomic_inc(&vcc->stats->tx_err);
22765 + atomic_inc_unchecked(&vcc->stats->tx_err);
22766 spin_unlock_irqrestore(&he_dev->global_lock, flags);
22769 @@ -2591,7 +2591,7 @@ he_send(struct atm_vcc *vcc, struct sk_b
22770 vcc->pop(vcc, skb);
22772 dev_kfree_skb_any(skb);
22773 - atomic_inc(&vcc->stats->tx_err);
22774 + atomic_inc_unchecked(&vcc->stats->tx_err);
22775 spin_unlock_irqrestore(&he_dev->global_lock, flags);
22778 @@ -2622,7 +2622,7 @@ he_send(struct atm_vcc *vcc, struct sk_b
22779 __enqueue_tpd(he_dev, tpd, cid);
22780 spin_unlock_irqrestore(&he_dev->global_lock, flags);
22782 - atomic_inc(&vcc->stats->tx);
22783 + atomic_inc_unchecked(&vcc->stats->tx);
22787 diff -urNp linux-2.6.37/drivers/atm/horizon.c linux-2.6.37/drivers/atm/horizon.c
22788 --- linux-2.6.37/drivers/atm/horizon.c 2011-01-04 19:50:19.000000000 -0500
22789 +++ linux-2.6.37/drivers/atm/horizon.c 2011-01-17 02:41:01.000000000 -0500
22790 @@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev,
22792 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
22794 - atomic_inc(&vcc->stats->rx);
22795 + atomic_inc_unchecked(&vcc->stats->rx);
22796 __net_timestamp(skb);
22797 // end of our responsability
22798 vcc->push (vcc, skb);
22799 @@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const
22800 dev->tx_iovec = NULL;
22803 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
22804 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
22807 hrz_kfree_skb (skb);
22808 diff -urNp linux-2.6.37/drivers/atm/idt77252.c linux-2.6.37/drivers/atm/idt77252.c
22809 --- linux-2.6.37/drivers/atm/idt77252.c 2011-01-04 19:50:19.000000000 -0500
22810 +++ linux-2.6.37/drivers/atm/idt77252.c 2011-01-17 02:41:01.000000000 -0500
22811 @@ -811,7 +811,7 @@ drain_scq(struct idt77252_dev *card, str
22813 dev_kfree_skb(skb);
22815 - atomic_inc(&vcc->stats->tx);
22816 + atomic_inc_unchecked(&vcc->stats->tx);
22819 atomic_dec(&scq->used);
22820 @@ -1074,13 +1074,13 @@ dequeue_rx(struct idt77252_dev *card, st
22821 if ((sb = dev_alloc_skb(64)) == NULL) {
22822 printk("%s: Can't allocate buffers for aal0.\n",
22824 - atomic_add(i, &vcc->stats->rx_drop);
22825 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
22828 if (!atm_charge(vcc, sb->truesize)) {
22829 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
22831 - atomic_add(i - 1, &vcc->stats->rx_drop);
22832 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
22836 @@ -1097,7 +1097,7 @@ dequeue_rx(struct idt77252_dev *card, st
22837 ATM_SKB(sb)->vcc = vcc;
22838 __net_timestamp(sb);
22839 vcc->push(vcc, sb);
22840 - atomic_inc(&vcc->stats->rx);
22841 + atomic_inc_unchecked(&vcc->stats->rx);
22843 cell += ATM_CELL_PAYLOAD;
22845 @@ -1134,13 +1134,13 @@ dequeue_rx(struct idt77252_dev *card, st
22847 card->name, len, rpp->len, readl(SAR_REG_CDC));
22848 recycle_rx_pool_skb(card, rpp);
22849 - atomic_inc(&vcc->stats->rx_err);
22850 + atomic_inc_unchecked(&vcc->stats->rx_err);
22853 if (stat & SAR_RSQE_CRC) {
22854 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
22855 recycle_rx_pool_skb(card, rpp);
22856 - atomic_inc(&vcc->stats->rx_err);
22857 + atomic_inc_unchecked(&vcc->stats->rx_err);
22860 if (skb_queue_len(&rpp->queue) > 1) {
22861 @@ -1151,7 +1151,7 @@ dequeue_rx(struct idt77252_dev *card, st
22862 RXPRINTK("%s: Can't alloc RX skb.\n",
22864 recycle_rx_pool_skb(card, rpp);
22865 - atomic_inc(&vcc->stats->rx_err);
22866 + atomic_inc_unchecked(&vcc->stats->rx_err);
22869 if (!atm_charge(vcc, skb->truesize)) {
22870 @@ -1170,7 +1170,7 @@ dequeue_rx(struct idt77252_dev *card, st
22871 __net_timestamp(skb);
22873 vcc->push(vcc, skb);
22874 - atomic_inc(&vcc->stats->rx);
22875 + atomic_inc_unchecked(&vcc->stats->rx);
22879 @@ -1192,7 +1192,7 @@ dequeue_rx(struct idt77252_dev *card, st
22880 __net_timestamp(skb);
22882 vcc->push(vcc, skb);
22883 - atomic_inc(&vcc->stats->rx);
22884 + atomic_inc_unchecked(&vcc->stats->rx);
22886 if (skb->truesize > SAR_FB_SIZE_3)
22887 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
22888 @@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *car
22889 if (vcc->qos.aal != ATM_AAL0) {
22890 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
22891 card->name, vpi, vci);
22892 - atomic_inc(&vcc->stats->rx_drop);
22893 + atomic_inc_unchecked(&vcc->stats->rx_drop);
22897 if ((sb = dev_alloc_skb(64)) == NULL) {
22898 printk("%s: Can't allocate buffers for AAL0.\n",
22900 - atomic_inc(&vcc->stats->rx_err);
22901 + atomic_inc_unchecked(&vcc->stats->rx_err);
22905 @@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *car
22906 ATM_SKB(sb)->vcc = vcc;
22907 __net_timestamp(sb);
22908 vcc->push(vcc, sb);
22909 - atomic_inc(&vcc->stats->rx);
22910 + atomic_inc_unchecked(&vcc->stats->rx);
22913 skb_pull(queue, 64);
22914 @@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, s
22917 printk("%s: NULL connection in send().\n", card->name);
22918 - atomic_inc(&vcc->stats->tx_err);
22919 + atomic_inc_unchecked(&vcc->stats->tx_err);
22920 dev_kfree_skb(skb);
22923 if (!test_bit(VCF_TX, &vc->flags)) {
22924 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
22925 - atomic_inc(&vcc->stats->tx_err);
22926 + atomic_inc_unchecked(&vcc->stats->tx_err);
22927 dev_kfree_skb(skb);
22930 @@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, s
22933 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
22934 - atomic_inc(&vcc->stats->tx_err);
22935 + atomic_inc_unchecked(&vcc->stats->tx_err);
22936 dev_kfree_skb(skb);
22940 if (skb_shinfo(skb)->nr_frags != 0) {
22941 printk("%s: No scatter-gather yet.\n", card->name);
22942 - atomic_inc(&vcc->stats->tx_err);
22943 + atomic_inc_unchecked(&vcc->stats->tx_err);
22944 dev_kfree_skb(skb);
22947 @@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, s
22949 err = queue_skb(card, vc, skb, oam);
22951 - atomic_inc(&vcc->stats->tx_err);
22952 + atomic_inc_unchecked(&vcc->stats->tx_err);
22953 dev_kfree_skb(skb);
22956 @@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, v
22957 skb = dev_alloc_skb(64);
22959 printk("%s: Out of memory in send_oam().\n", card->name);
22960 - atomic_inc(&vcc->stats->tx_err);
22961 + atomic_inc_unchecked(&vcc->stats->tx_err);
22964 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
22965 diff -urNp linux-2.6.37/drivers/atm/iphase.c linux-2.6.37/drivers/atm/iphase.c
22966 --- linux-2.6.37/drivers/atm/iphase.c 2011-01-04 19:50:19.000000000 -0500
22967 +++ linux-2.6.37/drivers/atm/iphase.c 2011-01-17 02:41:01.000000000 -0500
22968 @@ -1124,7 +1124,7 @@ static int rx_pkt(struct atm_dev *dev)
22969 status = (u_short) (buf_desc_ptr->desc_mode);
22970 if (status & (RX_CER | RX_PTE | RX_OFL))
22972 - atomic_inc(&vcc->stats->rx_err);
22973 + atomic_inc_unchecked(&vcc->stats->rx_err);
22974 IF_ERR(printk("IA: bad packet, dropping it");)
22975 if (status & RX_CER) {
22976 IF_ERR(printk(" cause: packet CRC error\n");)
22977 @@ -1147,7 +1147,7 @@ static int rx_pkt(struct atm_dev *dev)
22978 len = dma_addr - buf_addr;
22979 if (len > iadev->rx_buf_sz) {
22980 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
22981 - atomic_inc(&vcc->stats->rx_err);
22982 + atomic_inc_unchecked(&vcc->stats->rx_err);
22983 goto out_free_desc;
22986 @@ -1297,7 +1297,7 @@ static void rx_dle_intr(struct atm_dev *
22987 ia_vcc = INPH_IA_VCC(vcc);
22988 if (ia_vcc == NULL)
22990 - atomic_inc(&vcc->stats->rx_err);
22991 + atomic_inc_unchecked(&vcc->stats->rx_err);
22992 dev_kfree_skb_any(skb);
22993 atm_return(vcc, atm_guess_pdu2truesize(len));
22995 @@ -1309,7 +1309,7 @@ static void rx_dle_intr(struct atm_dev *
22996 if ((length > iadev->rx_buf_sz) || (length >
22997 (skb->len - sizeof(struct cpcs_trailer))))
22999 - atomic_inc(&vcc->stats->rx_err);
23000 + atomic_inc_unchecked(&vcc->stats->rx_err);
23001 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
23002 length, skb->len);)
23003 dev_kfree_skb_any(skb);
23004 @@ -1325,7 +1325,7 @@ static void rx_dle_intr(struct atm_dev *
23006 IF_RX(printk("rx_dle_intr: skb push");)
23007 vcc->push(vcc,skb);
23008 - atomic_inc(&vcc->stats->rx);
23009 + atomic_inc_unchecked(&vcc->stats->rx);
23010 iadev->rx_pkt_cnt++;
23013 @@ -2807,15 +2807,15 @@ static int ia_ioctl(struct atm_dev *dev,
23015 struct k_sonet_stats *stats;
23016 stats = &PRIV(_ia_dev[board])->sonet_stats;
23017 - printk("section_bip: %d\n", atomic_read(&stats->section_bip));
23018 - printk("line_bip : %d\n", atomic_read(&stats->line_bip));
23019 - printk("path_bip : %d\n", atomic_read(&stats->path_bip));
23020 - printk("line_febe : %d\n", atomic_read(&stats->line_febe));
23021 - printk("path_febe : %d\n", atomic_read(&stats->path_febe));
23022 - printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
23023 - printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
23024 - printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
23025 - printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
23026 + printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
23027 + printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
23028 + printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
23029 + printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
23030 + printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
23031 + printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
23032 + printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
23033 + printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
23034 + printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
23036 ia_cmds.status = 0;
23038 @@ -2920,7 +2920,7 @@ static int ia_pkt_tx (struct atm_vcc *vc
23039 if ((desc == 0) || (desc > iadev->num_tx_desc))
23041 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
23042 - atomic_inc(&vcc->stats->tx);
23043 + atomic_inc_unchecked(&vcc->stats->tx);
23045 vcc->pop(vcc, skb);
23047 @@ -3025,14 +3025,14 @@ static int ia_pkt_tx (struct atm_vcc *vc
23048 ATM_DESC(skb) = vcc->vci;
23049 skb_queue_tail(&iadev->tx_dma_q, skb);
23051 - atomic_inc(&vcc->stats->tx);
23052 + atomic_inc_unchecked(&vcc->stats->tx);
23053 iadev->tx_pkt_cnt++;
23054 /* Increment transaction counter */
23055 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
23058 /* add flow control logic */
23059 - if (atomic_read(&vcc->stats->tx) % 20 == 0) {
23060 + if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
23061 if (iavcc->vc_desc_cnt > 10) {
23062 vcc->tx_quota = vcc->tx_quota * 3 / 4;
23063 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
23064 diff -urNp linux-2.6.37/drivers/atm/lanai.c linux-2.6.37/drivers/atm/lanai.c
23065 --- linux-2.6.37/drivers/atm/lanai.c 2011-01-04 19:50:19.000000000 -0500
23066 +++ linux-2.6.37/drivers/atm/lanai.c 2011-01-17 02:41:01.000000000 -0500
23067 @@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct l
23068 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
23069 lanai_endtx(lanai, lvcc);
23070 lanai_free_skb(lvcc->tx.atmvcc, skb);
23071 - atomic_inc(&lvcc->tx.atmvcc->stats->tx);
23072 + atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
23075 /* Try to fill the buffer - don't call unless there is backlog */
23076 @@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc
23077 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
23078 __net_timestamp(skb);
23079 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
23080 - atomic_inc(&lvcc->rx.atmvcc->stats->rx);
23081 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
23083 lvcc->rx.buf.ptr = end;
23084 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
23085 @@ -1668,7 +1668,7 @@ static int handle_service(struct lanai_d
23086 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
23087 "vcc %d\n", lanai->number, (unsigned int) s, vci);
23088 lanai->stats.service_rxnotaal5++;
23089 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
23090 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
23093 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
23094 @@ -1680,7 +1680,7 @@ static int handle_service(struct lanai_d
23096 read_unlock(&vcc_sklist_lock);
23097 DPRINTK("got trashed rx pdu on vci %d\n", vci);
23098 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
23099 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
23100 lvcc->stats.x.aal5.service_trash++;
23101 bytes = (SERVICE_GET_END(s) * 16) -
23102 (((unsigned long) lvcc->rx.buf.ptr) -
23103 @@ -1692,7 +1692,7 @@ static int handle_service(struct lanai_d
23105 if (s & SERVICE_STREAM) {
23106 read_unlock(&vcc_sklist_lock);
23107 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
23108 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
23109 lvcc->stats.x.aal5.service_stream++;
23110 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
23111 "PDU on VCI %d!\n", lanai->number, vci);
23112 @@ -1700,7 +1700,7 @@ static int handle_service(struct lanai_d
23115 DPRINTK("got rx crc error on vci %d\n", vci);
23116 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
23117 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
23118 lvcc->stats.x.aal5.service_rxcrc++;
23119 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
23120 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
23121 diff -urNp linux-2.6.37/drivers/atm/nicstar.c linux-2.6.37/drivers/atm/nicstar.c
23122 --- linux-2.6.37/drivers/atm/nicstar.c 2011-01-04 19:50:19.000000000 -0500
23123 +++ linux-2.6.37/drivers/atm/nicstar.c 2011-01-17 02:41:01.000000000 -0500
23124 @@ -1654,7 +1654,7 @@ static int ns_send(struct atm_vcc *vcc,
23125 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
23126 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
23128 - atomic_inc(&vcc->stats->tx_err);
23129 + atomic_inc_unchecked(&vcc->stats->tx_err);
23130 dev_kfree_skb_any(skb);
23133 @@ -1662,7 +1662,7 @@ static int ns_send(struct atm_vcc *vcc,
23135 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
23137 - atomic_inc(&vcc->stats->tx_err);
23138 + atomic_inc_unchecked(&vcc->stats->tx_err);
23139 dev_kfree_skb_any(skb);
23142 @@ -1670,14 +1670,14 @@ static int ns_send(struct atm_vcc *vcc,
23143 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
23144 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
23146 - atomic_inc(&vcc->stats->tx_err);
23147 + atomic_inc_unchecked(&vcc->stats->tx_err);
23148 dev_kfree_skb_any(skb);
23152 if (skb_shinfo(skb)->nr_frags != 0) {
23153 printk("nicstar%d: No scatter-gather yet.\n", card->index);
23154 - atomic_inc(&vcc->stats->tx_err);
23155 + atomic_inc_unchecked(&vcc->stats->tx_err);
23156 dev_kfree_skb_any(skb);
23159 @@ -1725,11 +1725,11 @@ static int ns_send(struct atm_vcc *vcc,
23162 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
23163 - atomic_inc(&vcc->stats->tx_err);
23164 + atomic_inc_unchecked(&vcc->stats->tx_err);
23165 dev_kfree_skb_any(skb);
23168 - atomic_inc(&vcc->stats->tx);
23169 + atomic_inc_unchecked(&vcc->stats->tx);
23173 @@ -2046,14 +2046,14 @@ static void dequeue_rx(ns_dev * card, ns
23175 ("nicstar%d: Can't allocate buffers for aal0.\n",
23177 - atomic_add(i, &vcc->stats->rx_drop);
23178 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
23181 if (!atm_charge(vcc, sb->truesize)) {
23183 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
23185 - atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
23186 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
23187 dev_kfree_skb_any(sb);
23190 @@ -2068,7 +2068,7 @@ static void dequeue_rx(ns_dev * card, ns
23191 ATM_SKB(sb)->vcc = vcc;
23192 __net_timestamp(sb);
23193 vcc->push(vcc, sb);
23194 - atomic_inc(&vcc->stats->rx);
23195 + atomic_inc_unchecked(&vcc->stats->rx);
23196 cell += ATM_CELL_PAYLOAD;
23199 @@ -2085,7 +2085,7 @@ static void dequeue_rx(ns_dev * card, ns
23200 if (iovb == NULL) {
23201 printk("nicstar%d: Out of iovec buffers.\n",
23203 - atomic_inc(&vcc->stats->rx_drop);
23204 + atomic_inc_unchecked(&vcc->stats->rx_drop);
23205 recycle_rx_buf(card, skb);
23208 @@ -2109,7 +2109,7 @@ static void dequeue_rx(ns_dev * card, ns
23209 small or large buffer itself. */
23210 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
23211 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
23212 - atomic_inc(&vcc->stats->rx_err);
23213 + atomic_inc_unchecked(&vcc->stats->rx_err);
23214 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
23216 NS_PRV_IOVCNT(iovb) = 0;
23217 @@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns
23218 ("nicstar%d: Expected a small buffer, and this is not one.\n",
23220 which_list(card, skb);
23221 - atomic_inc(&vcc->stats->rx_err);
23222 + atomic_inc_unchecked(&vcc->stats->rx_err);
23223 recycle_rx_buf(card, skb);
23225 recycle_iov_buf(card, iovb);
23226 @@ -2142,7 +2142,7 @@ static void dequeue_rx(ns_dev * card, ns
23227 ("nicstar%d: Expected a large buffer, and this is not one.\n",
23229 which_list(card, skb);
23230 - atomic_inc(&vcc->stats->rx_err);
23231 + atomic_inc_unchecked(&vcc->stats->rx_err);
23232 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
23233 NS_PRV_IOVCNT(iovb));
23235 @@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns
23236 printk(" - PDU size mismatch.\n");
23239 - atomic_inc(&vcc->stats->rx_err);
23240 + atomic_inc_unchecked(&vcc->stats->rx_err);
23241 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
23242 NS_PRV_IOVCNT(iovb));
23244 @@ -2179,7 +2179,7 @@ static void dequeue_rx(ns_dev * card, ns
23245 /* skb points to a small buffer */
23246 if (!atm_charge(vcc, skb->truesize)) {
23247 push_rxbufs(card, skb);
23248 - atomic_inc(&vcc->stats->rx_drop);
23249 + atomic_inc_unchecked(&vcc->stats->rx_drop);
23252 dequeue_sm_buf(card, skb);
23253 @@ -2189,7 +2189,7 @@ static void dequeue_rx(ns_dev * card, ns
23254 ATM_SKB(skb)->vcc = vcc;
23255 __net_timestamp(skb);
23256 vcc->push(vcc, skb);
23257 - atomic_inc(&vcc->stats->rx);
23258 + atomic_inc_unchecked(&vcc->stats->rx);
23260 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
23261 struct sk_buff *sb;
23262 @@ -2200,7 +2200,7 @@ static void dequeue_rx(ns_dev * card, ns
23263 if (len <= NS_SMBUFSIZE) {
23264 if (!atm_charge(vcc, sb->truesize)) {
23265 push_rxbufs(card, sb);
23266 - atomic_inc(&vcc->stats->rx_drop);
23267 + atomic_inc_unchecked(&vcc->stats->rx_drop);
23270 dequeue_sm_buf(card, sb);
23271 @@ -2210,7 +2210,7 @@ static void dequeue_rx(ns_dev * card, ns
23272 ATM_SKB(sb)->vcc = vcc;
23273 __net_timestamp(sb);
23274 vcc->push(vcc, sb);
23275 - atomic_inc(&vcc->stats->rx);
23276 + atomic_inc_unchecked(&vcc->stats->rx);
23279 push_rxbufs(card, skb);
23280 @@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns
23282 if (!atm_charge(vcc, skb->truesize)) {
23283 push_rxbufs(card, skb);
23284 - atomic_inc(&vcc->stats->rx_drop);
23285 + atomic_inc_unchecked(&vcc->stats->rx_drop);
23287 dequeue_lg_buf(card, skb);
23288 #ifdef NS_USE_DESTRUCTORS
23289 @@ -2232,7 +2232,7 @@ static void dequeue_rx(ns_dev * card, ns
23290 ATM_SKB(skb)->vcc = vcc;
23291 __net_timestamp(skb);
23292 vcc->push(vcc, skb);
23293 - atomic_inc(&vcc->stats->rx);
23294 + atomic_inc_unchecked(&vcc->stats->rx);
23297 push_rxbufs(card, sb);
23298 @@ -2253,7 +2253,7 @@ static void dequeue_rx(ns_dev * card, ns
23300 ("nicstar%d: Out of huge buffers.\n",
23302 - atomic_inc(&vcc->stats->rx_drop);
23303 + atomic_inc_unchecked(&vcc->stats->rx_drop);
23304 recycle_iovec_rx_bufs(card,
23307 @@ -2304,7 +2304,7 @@ static void dequeue_rx(ns_dev * card, ns
23308 card->hbpool.count++;
23310 dev_kfree_skb_any(hb);
23311 - atomic_inc(&vcc->stats->rx_drop);
23312 + atomic_inc_unchecked(&vcc->stats->rx_drop);
23314 /* Copy the small buffer to the huge buffer */
23315 sb = (struct sk_buff *)iov->iov_base;
23316 @@ -2341,7 +2341,7 @@ static void dequeue_rx(ns_dev * card, ns
23317 #endif /* NS_USE_DESTRUCTORS */
23318 __net_timestamp(hb);
23319 vcc->push(vcc, hb);
23320 - atomic_inc(&vcc->stats->rx);
23321 + atomic_inc_unchecked(&vcc->stats->rx);
23325 diff -urNp linux-2.6.37/drivers/atm/solos-pci.c linux-2.6.37/drivers/atm/solos-pci.c
23326 --- linux-2.6.37/drivers/atm/solos-pci.c 2011-01-04 19:50:19.000000000 -0500
23327 +++ linux-2.6.37/drivers/atm/solos-pci.c 2011-01-17 02:41:01.000000000 -0500
23328 @@ -717,7 +717,7 @@ void solos_bh(unsigned long card_arg)
23330 atm_charge(vcc, skb->truesize);
23331 vcc->push(vcc, skb);
23332 - atomic_inc(&vcc->stats->rx);
23333 + atomic_inc_unchecked(&vcc->stats->rx);
23337 @@ -1025,7 +1025,7 @@ static uint32_t fpga_tx(struct solos_car
23338 vcc = SKB_CB(oldskb)->vcc;
23341 - atomic_inc(&vcc->stats->tx);
23342 + atomic_inc_unchecked(&vcc->stats->tx);
23343 solos_pop(vcc, oldskb);
23345 dev_kfree_skb_irq(oldskb);
23346 diff -urNp linux-2.6.37/drivers/atm/suni.c linux-2.6.37/drivers/atm/suni.c
23347 --- linux-2.6.37/drivers/atm/suni.c 2011-01-04 19:50:19.000000000 -0500
23348 +++ linux-2.6.37/drivers/atm/suni.c 2011-01-17 02:41:01.000000000 -0500
23349 @@ -50,8 +50,8 @@ static DEFINE_SPINLOCK(sunis_lock);
23352 #define ADD_LIMITED(s,v) \
23353 - atomic_add((v),&stats->s); \
23354 - if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
23355 + atomic_add_unchecked((v),&stats->s); \
23356 + if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
23359 static void suni_hz(unsigned long from_timer)
23360 diff -urNp linux-2.6.37/drivers/atm/uPD98402.c linux-2.6.37/drivers/atm/uPD98402.c
23361 --- linux-2.6.37/drivers/atm/uPD98402.c 2011-01-04 19:50:19.000000000 -0500
23362 +++ linux-2.6.37/drivers/atm/uPD98402.c 2011-01-17 02:41:01.000000000 -0500
23363 @@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *d
23364 struct sonet_stats tmp;
23367 - atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
23368 + atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
23369 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
23370 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
23371 if (zero && !error) {
23372 @@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev
23375 #define ADD_LIMITED(s,v) \
23376 - { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
23377 - if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
23378 - atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
23379 + { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
23380 + if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
23381 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
23384 static void stat_event(struct atm_dev *dev)
23385 @@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev
23386 if (reason & uPD98402_INT_PFM) stat_event(dev);
23387 if (reason & uPD98402_INT_PCO) {
23388 (void) GET(PCOCR); /* clear interrupt cause */
23389 - atomic_add(GET(HECCT),
23390 + atomic_add_unchecked(GET(HECCT),
23391 &PRIV(dev)->sonet_stats.uncorr_hcs);
23393 if ((reason & uPD98402_INT_RFO) &&
23394 @@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev
23395 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
23396 uPD98402_INT_LOS),PIMR); /* enable them */
23397 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
23398 - atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
23399 - atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
23400 - atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
23401 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
23402 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
23403 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
23407 diff -urNp linux-2.6.37/drivers/atm/zatm.c linux-2.6.37/drivers/atm/zatm.c
23408 --- linux-2.6.37/drivers/atm/zatm.c 2011-01-04 19:50:19.000000000 -0500
23409 +++ linux-2.6.37/drivers/atm/zatm.c 2011-01-17 02:41:01.000000000 -0500
23410 @@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy
23413 dev_kfree_skb_irq(skb);
23414 - if (vcc) atomic_inc(&vcc->stats->rx_err);
23415 + if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
23418 if (!atm_charge(vcc,skb->truesize)) {
23419 @@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy
23421 ATM_SKB(skb)->vcc = vcc;
23422 vcc->push(vcc,skb);
23423 - atomic_inc(&vcc->stats->rx);
23424 + atomic_inc_unchecked(&vcc->stats->rx);
23426 zout(pos & 0xffff,MTA(mbx));
23427 #if 0 /* probably a stupid idea */
23428 @@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD
23429 skb_queue_head(&zatm_vcc->backlog,skb);
23432 - atomic_inc(&vcc->stats->tx);
23433 + atomic_inc_unchecked(&vcc->stats->tx);
23434 wake_up(&zatm_vcc->tx_wait);
23437 diff -urNp linux-2.6.37/drivers/block/cciss.c linux-2.6.37/drivers/block/cciss.c
23438 --- linux-2.6.37/drivers/block/cciss.c 2011-01-04 19:50:19.000000000 -0500
23439 +++ linux-2.6.37/drivers/block/cciss.c 2011-01-17 02:41:01.000000000 -0500
23440 @@ -1112,6 +1112,8 @@ static int cciss_ioctl32_passthru(struct
23444 + memset(&arg64, 0, sizeof(arg64));
23448 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
23449 diff -urNp linux-2.6.37/drivers/char/agp/frontend.c linux-2.6.37/drivers/char/agp/frontend.c
23450 --- linux-2.6.37/drivers/char/agp/frontend.c 2011-01-04 19:50:19.000000000 -0500
23451 +++ linux-2.6.37/drivers/char/agp/frontend.c 2011-01-17 02:41:01.000000000 -0500
23452 @@ -817,7 +817,7 @@ static int agpioc_reserve_wrap(struct ag
23453 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
23456 - if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
23457 + if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
23460 client = agp_find_client_by_pid(reserve.pid);
23461 diff -urNp linux-2.6.37/drivers/char/agp/intel-agp.c linux-2.6.37/drivers/char/agp/intel-agp.c
23462 --- linux-2.6.37/drivers/char/agp/intel-agp.c 2011-01-04 19:50:19.000000000 -0500
23463 +++ linux-2.6.37/drivers/char/agp/intel-agp.c 2011-01-17 02:41:01.000000000 -0500
23464 @@ -903,7 +903,7 @@ static struct pci_device_id agp_intel_pc
23465 ID(PCI_DEVICE_ID_INTEL_SANDYBRIDGE_HB),
23466 ID(PCI_DEVICE_ID_INTEL_SANDYBRIDGE_M_HB),
23467 ID(PCI_DEVICE_ID_INTEL_SANDYBRIDGE_S_HB),
23469 + { 0, 0, 0, 0, 0, 0, 0 }
23472 MODULE_DEVICE_TABLE(pci, agp_intel_pci_table);
23473 diff -urNp linux-2.6.37/drivers/char/hpet.c linux-2.6.37/drivers/char/hpet.c
23474 --- linux-2.6.37/drivers/char/hpet.c 2011-01-04 19:50:19.000000000 -0500
23475 +++ linux-2.6.37/drivers/char/hpet.c 2011-01-17 02:41:01.000000000 -0500
23476 @@ -553,7 +553,7 @@ static inline unsigned long hpet_time_di
23480 -hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
23481 +hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
23482 struct hpet_info *info)
23484 struct hpet_timer __iomem *timer;
23485 @@ -1043,7 +1043,7 @@ static struct acpi_driver hpet_acpi_driv
23489 -static struct miscdevice hpet_misc = { HPET_MINOR, "hpet", &hpet_fops };
23490 +static struct miscdevice hpet_misc = { HPET_MINOR, "hpet", &hpet_fops, {NULL, NULL}, NULL, NULL };
23492 static int __init hpet_init(void)
23494 diff -urNp linux-2.6.37/drivers/char/hvc_console.h linux-2.6.37/drivers/char/hvc_console.h
23495 --- linux-2.6.37/drivers/char/hvc_console.h 2011-01-04 19:50:19.000000000 -0500
23496 +++ linux-2.6.37/drivers/char/hvc_console.h 2011-01-17 02:41:01.000000000 -0500
23497 @@ -82,6 +82,7 @@ extern int hvc_instantiate(uint32_t vter
23498 /* register a vterm for hvc tty operation (module_init or hotplug add) */
23499 extern struct hvc_struct * hvc_alloc(uint32_t vtermno, int data,
23500 const struct hv_ops *ops, int outbuf_size);
23502 /* remove a vterm from hvc tty operation (module_exit or hotplug remove) */
23503 extern int hvc_remove(struct hvc_struct *hp);
23505 diff -urNp linux-2.6.37/drivers/char/hvcs.c linux-2.6.37/drivers/char/hvcs.c
23506 --- linux-2.6.37/drivers/char/hvcs.c 2011-01-04 19:50:19.000000000 -0500
23507 +++ linux-2.6.37/drivers/char/hvcs.c 2011-01-17 02:41:01.000000000 -0500
23508 @@ -270,7 +270,7 @@ struct hvcs_struct {
23509 unsigned int index;
23511 struct tty_struct *tty;
23513 + atomic_t open_count;
23516 * Used to tell the driver kernel_thread what operations need to take
23517 @@ -420,7 +420,7 @@ static ssize_t hvcs_vterm_state_store(st
23519 spin_lock_irqsave(&hvcsd->lock, flags);
23521 - if (hvcsd->open_count > 0) {
23522 + if (atomic_read(&hvcsd->open_count) > 0) {
23523 spin_unlock_irqrestore(&hvcsd->lock, flags);
23524 printk(KERN_INFO "HVCS: vterm state unchanged. "
23525 "The hvcs device node is still in use.\n");
23526 @@ -1136,7 +1136,7 @@ static int hvcs_open(struct tty_struct *
23527 if ((retval = hvcs_partner_connect(hvcsd)))
23528 goto error_release;
23530 - hvcsd->open_count = 1;
23531 + atomic_set(&hvcsd->open_count, 1);
23533 tty->driver_data = hvcsd;
23535 @@ -1170,7 +1170,7 @@ fast_open:
23537 spin_lock_irqsave(&hvcsd->lock, flags);
23538 kref_get(&hvcsd->kref);
23539 - hvcsd->open_count++;
23540 + atomic_inc(&hvcsd->open_count);
23541 hvcsd->todo_mask |= HVCS_SCHED_READ;
23542 spin_unlock_irqrestore(&hvcsd->lock, flags);
23544 @@ -1214,7 +1214,7 @@ static void hvcs_close(struct tty_struct
23545 hvcsd = tty->driver_data;
23547 spin_lock_irqsave(&hvcsd->lock, flags);
23548 - if (--hvcsd->open_count == 0) {
23549 + if (atomic_dec_and_test(&hvcsd->open_count)) {
23551 vio_disable_interrupts(hvcsd->vdev);
23553 @@ -1240,10 +1240,10 @@ static void hvcs_close(struct tty_struct
23554 free_irq(irq, hvcsd);
23555 kref_put(&hvcsd->kref, destroy_hvcs_struct);
23557 - } else if (hvcsd->open_count < 0) {
23558 + } else if (atomic_read(&hvcsd->open_count) < 0) {
23559 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
23560 " is missmanaged.\n",
23561 - hvcsd->vdev->unit_address, hvcsd->open_count);
23562 + hvcsd->vdev->unit_address, atomic_read(&hvcsd->open_count));
23565 spin_unlock_irqrestore(&hvcsd->lock, flags);
23566 @@ -1259,7 +1259,7 @@ static void hvcs_hangup(struct tty_struc
23568 spin_lock_irqsave(&hvcsd->lock, flags);
23569 /* Preserve this so that we know how many kref refs to put */
23570 - temp_open_count = hvcsd->open_count;
23571 + temp_open_count = atomic_read(&hvcsd->open_count);
23574 * Don't kref put inside the spinlock because the destruction
23575 @@ -1274,7 +1274,7 @@ static void hvcs_hangup(struct tty_struc
23576 hvcsd->tty->driver_data = NULL;
23579 - hvcsd->open_count = 0;
23580 + atomic_set(&hvcsd->open_count, 0);
23582 /* This will drop any buffered data on the floor which is OK in a hangup
23584 @@ -1345,7 +1345,7 @@ static int hvcs_write(struct tty_struct
23585 * the middle of a write operation? This is a crummy place to do this
23586 * but we want to keep it all in the spinlock.
23588 - if (hvcsd->open_count <= 0) {
23589 + if (atomic_read(&hvcsd->open_count) <= 0) {
23590 spin_unlock_irqrestore(&hvcsd->lock, flags);
23593 @@ -1419,7 +1419,7 @@ static int hvcs_write_room(struct tty_st
23595 struct hvcs_struct *hvcsd = tty->driver_data;
23597 - if (!hvcsd || hvcsd->open_count <= 0)
23598 + if (!hvcsd || atomic_read(&hvcsd->open_count) <= 0)
23601 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
23602 diff -urNp linux-2.6.37/drivers/char/hvc_xen.c linux-2.6.37/drivers/char/hvc_xen.c
23603 --- linux-2.6.37/drivers/char/hvc_xen.c 2011-01-04 19:50:19.000000000 -0500
23604 +++ linux-2.6.37/drivers/char/hvc_xen.c 2011-01-17 02:41:01.000000000 -0500
23605 @@ -123,7 +123,7 @@ static int domU_read_console(uint32_t vt
23609 -static struct hv_ops domU_hvc_ops = {
23610 +static const struct hv_ops domU_hvc_ops = {
23611 .get_chars = domU_read_console,
23612 .put_chars = domU_write_console,
23613 .notifier_add = notifier_add_irq,
23614 @@ -149,7 +149,7 @@ static int dom0_write_console(uint32_t v
23618 -static struct hv_ops dom0_hvc_ops = {
23619 +static const struct hv_ops dom0_hvc_ops = {
23620 .get_chars = dom0_read_console,
23621 .put_chars = dom0_write_console,
23622 .notifier_add = notifier_add_irq,
23623 @@ -160,7 +160,7 @@ static struct hv_ops dom0_hvc_ops = {
23624 static int __init xen_hvc_init(void)
23626 struct hvc_struct *hp;
23627 - struct hv_ops *ops;
23628 + const struct hv_ops *ops;
23630 if (!xen_pv_domain())
23632 @@ -203,7 +203,7 @@ static void __exit xen_hvc_fini(void)
23634 static int xen_cons_init(void)
23636 - struct hv_ops *ops;
23637 + const struct hv_ops *ops;
23639 if (!xen_pv_domain())
23641 diff -urNp linux-2.6.37/drivers/char/ipmi/ipmi_msghandler.c linux-2.6.37/drivers/char/ipmi/ipmi_msghandler.c
23642 --- linux-2.6.37/drivers/char/ipmi/ipmi_msghandler.c 2011-01-04 19:50:19.000000000 -0500
23643 +++ linux-2.6.37/drivers/char/ipmi/ipmi_msghandler.c 2011-01-17 02:41:01.000000000 -0500
23644 @@ -414,7 +414,7 @@ struct ipmi_smi {
23645 struct proc_dir_entry *proc_dir;
23646 char proc_dir_name[10];
23648 - atomic_t stats[IPMI_NUM_STATS];
23649 + atomic_unchecked_t stats[IPMI_NUM_STATS];
23652 * run_to_completion duplicate of smb_info, smi_info
23653 @@ -447,9 +447,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
23656 #define ipmi_inc_stat(intf, stat) \
23657 - atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
23658 + atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
23659 #define ipmi_get_stat(intf, stat) \
23660 - ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
23661 + ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
23663 static int is_lan_addr(struct ipmi_addr *addr)
23665 @@ -2817,7 +2817,7 @@ int ipmi_register_smi(struct ipmi_smi_ha
23666 INIT_LIST_HEAD(&intf->cmd_rcvrs);
23667 init_waitqueue_head(&intf->waitq);
23668 for (i = 0; i < IPMI_NUM_STATS; i++)
23669 - atomic_set(&intf->stats[i], 0);
23670 + atomic_set_unchecked(&intf->stats[i], 0);
23672 intf->proc_dir = NULL;
23674 diff -urNp linux-2.6.37/drivers/char/ipmi/ipmi_si_intf.c linux-2.6.37/drivers/char/ipmi/ipmi_si_intf.c
23675 --- linux-2.6.37/drivers/char/ipmi/ipmi_si_intf.c 2011-01-04 19:50:19.000000000 -0500
23676 +++ linux-2.6.37/drivers/char/ipmi/ipmi_si_intf.c 2011-01-17 02:41:01.000000000 -0500
23677 @@ -286,7 +286,7 @@ struct smi_info {
23678 unsigned char slave_addr;
23680 /* Counters and things for the proc filesystem. */
23681 - atomic_t stats[SI_NUM_STATS];
23682 + atomic_unchecked_t stats[SI_NUM_STATS];
23684 struct task_struct *thread;
23686 @@ -294,9 +294,9 @@ struct smi_info {
23689 #define smi_inc_stat(smi, stat) \
23690 - atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
23691 + atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
23692 #define smi_get_stat(smi, stat) \
23693 - ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
23694 + ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
23696 #define SI_MAX_PARMS 4
23698 @@ -3178,7 +3178,7 @@ static int try_smi_init(struct smi_info
23699 atomic_set(&new_smi->req_events, 0);
23700 new_smi->run_to_completion = 0;
23701 for (i = 0; i < SI_NUM_STATS; i++)
23702 - atomic_set(&new_smi->stats[i], 0);
23703 + atomic_set_unchecked(&new_smi->stats[i], 0);
23705 new_smi->interrupt_disabled = 1;
23706 atomic_set(&new_smi->stop_operation, 0);
23707 diff -urNp linux-2.6.37/drivers/char/mem.c linux-2.6.37/drivers/char/mem.c
23708 --- linux-2.6.37/drivers/char/mem.c 2011-01-04 19:50:19.000000000 -0500
23709 +++ linux-2.6.37/drivers/char/mem.c 2011-01-17 02:41:01.000000000 -0500
23711 #include <linux/raw.h>
23712 #include <linux/tty.h>
23713 #include <linux/capability.h>
23714 +#include <linux/security.h>
23715 #include <linux/ptrace.h>
23716 #include <linux/device.h>
23717 #include <linux/highmem.h>
23719 # include <linux/efi.h>
23722 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
23723 +extern struct file_operations grsec_fops;
23726 static inline unsigned long size_inside_page(unsigned long start,
23727 unsigned long size)
23729 @@ -120,6 +125,7 @@ static ssize_t read_mem(struct file *fil
23731 while (count > 0) {
23732 unsigned long remaining;
23735 sz = size_inside_page(p, count);
23737 @@ -135,7 +141,23 @@ static ssize_t read_mem(struct file *fil
23741 - remaining = copy_to_user(buf, ptr, sz);
23742 +#ifdef CONFIG_PAX_USERCOPY
23743 + temp = kmalloc(sz, GFP_KERNEL);
23745 + unxlate_dev_mem_ptr(p, ptr);
23748 + memcpy(temp, ptr, sz);
23753 + remaining = copy_to_user(buf, temp, sz);
23755 +#ifdef CONFIG_PAX_USERCOPY
23759 unxlate_dev_mem_ptr(p, ptr);
23762 @@ -161,6 +183,11 @@ static ssize_t write_mem(struct file *fi
23763 if (!valid_phys_addr_range(p, count))
23766 +#ifdef CONFIG_GRKERNSEC_KMEM
23767 + gr_handle_mem_write();
23773 #ifdef __ARCH_HAS_NO_PAGE_ZERO_MAPPED
23774 @@ -316,6 +343,11 @@ static int mmap_mem(struct file *file, s
23775 &vma->vm_page_prot))
23778 +#ifdef CONFIG_GRKERNSEC_KMEM
23779 + if (gr_handle_mem_mmap(vma->vm_pgoff << PAGE_SHIFT, vma))
23783 vma->vm_page_prot = phys_mem_access_prot(file, vma->vm_pgoff,
23785 vma->vm_page_prot);
23786 @@ -398,9 +430,8 @@ static ssize_t read_kmem(struct file *fi
23787 size_t count, loff_t *ppos)
23789 unsigned long p = *ppos;
23790 - ssize_t low_count, read, sz;
23791 + ssize_t low_count, read, sz, err = 0;
23792 char * kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
23796 if (p < (unsigned long) high_memory) {
23797 @@ -422,6 +453,8 @@ static ssize_t read_kmem(struct file *fi
23800 while (low_count > 0) {
23803 sz = size_inside_page(p, low_count);
23806 @@ -431,7 +464,22 @@ static ssize_t read_kmem(struct file *fi
23808 kbuf = xlate_dev_kmem_ptr((char *)p);
23810 - if (copy_to_user(buf, kbuf, sz))
23811 +#ifdef CONFIG_PAX_USERCOPY
23812 + temp = kmalloc(sz, GFP_KERNEL);
23815 + memcpy(temp, kbuf, sz);
23820 + err = copy_to_user(buf, temp, sz);
23822 +#ifdef CONFIG_PAX_USERCOPY
23830 @@ -530,6 +578,11 @@ static ssize_t write_kmem(struct file *f
23831 char * kbuf; /* k-addr because vwrite() takes vmlist_lock rwlock */
23834 +#ifdef CONFIG_GRKERNSEC_KMEM
23835 + gr_handle_kmem_write();
23839 if (p < (unsigned long) high_memory) {
23840 unsigned long to_write = min_t(unsigned long, count,
23841 (unsigned long)high_memory - p);
23842 @@ -731,6 +784,16 @@ static loff_t memory_lseek(struct file *
23844 static int open_port(struct inode * inode, struct file * filp)
23846 +#ifdef CONFIG_GRKERNSEC_KMEM
23847 + gr_handle_open_port();
23851 + return capable(CAP_SYS_RAWIO) ? 0 : -EPERM;
23854 +static int open_mem(struct inode * inode, struct file * filp)
23856 return capable(CAP_SYS_RAWIO) ? 0 : -EPERM;
23859 @@ -738,7 +801,6 @@ static int open_port(struct inode * inod
23860 #define full_lseek null_lseek
23861 #define write_zero write_null
23862 #define read_full read_zero
23863 -#define open_mem open_port
23864 #define open_kmem open_mem
23865 #define open_oldmem open_mem
23867 @@ -857,6 +919,9 @@ static const struct memdev {
23868 #ifdef CONFIG_CRASH_DUMP
23869 [12] = { "oldmem", 0, &oldmem_fops, NULL },
23871 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
23872 + [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
23876 static int memory_open(struct inode *inode, struct file *filp)
23877 diff -urNp linux-2.6.37/drivers/char/nvram.c linux-2.6.37/drivers/char/nvram.c
23878 --- linux-2.6.37/drivers/char/nvram.c 2011-01-04 19:50:19.000000000 -0500
23879 +++ linux-2.6.37/drivers/char/nvram.c 2011-01-17 02:41:01.000000000 -0500
23880 @@ -246,7 +246,7 @@ static ssize_t nvram_read(struct file *f
23882 spin_unlock_irq(&rtc_lock);
23884 - if (copy_to_user(buf, contents, tmp - contents))
23885 + if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
23889 @@ -435,7 +435,10 @@ static const struct file_operations nvra
23890 static struct miscdevice nvram_dev = {
23900 static int __init nvram_init(void)
23901 diff -urNp linux-2.6.37/drivers/char/pcmcia/ipwireless/tty.c linux-2.6.37/drivers/char/pcmcia/ipwireless/tty.c
23902 --- linux-2.6.37/drivers/char/pcmcia/ipwireless/tty.c 2011-01-04 19:50:19.000000000 -0500
23903 +++ linux-2.6.37/drivers/char/pcmcia/ipwireless/tty.c 2011-01-17 02:41:01.000000000 -0500
23904 @@ -51,7 +51,7 @@ struct ipw_tty {
23906 struct ipw_network *network;
23907 struct tty_struct *linux_tty;
23909 + atomic_t open_count;
23910 unsigned int control_lines;
23911 struct mutex ipw_tty_mutex;
23912 int tx_bytes_queued;
23913 @@ -127,10 +127,10 @@ static int ipw_open(struct tty_struct *l
23914 mutex_unlock(&tty->ipw_tty_mutex);
23917 - if (tty->open_count == 0)
23918 + if (atomic_read(&tty->open_count) == 0)
23919 tty->tx_bytes_queued = 0;
23921 - tty->open_count++;
23922 + atomic_inc(&tty->open_count);
23924 tty->linux_tty = linux_tty;
23925 linux_tty->driver_data = tty;
23926 @@ -146,9 +146,7 @@ static int ipw_open(struct tty_struct *l
23928 static void do_ipw_close(struct ipw_tty *tty)
23930 - tty->open_count--;
23932 - if (tty->open_count == 0) {
23933 + if (atomic_dec_return(&tty->open_count) == 0) {
23934 struct tty_struct *linux_tty = tty->linux_tty;
23936 if (linux_tty != NULL) {
23937 @@ -169,7 +167,7 @@ static void ipw_hangup(struct tty_struct
23940 mutex_lock(&tty->ipw_tty_mutex);
23941 - if (tty->open_count == 0) {
23942 + if (atomic_read(&tty->open_count) == 0) {
23943 mutex_unlock(&tty->ipw_tty_mutex);
23946 @@ -198,7 +196,7 @@ void ipwireless_tty_received(struct ipw_
23950 - if (!tty->open_count) {
23951 + if (!atomic_read(&tty->open_count)) {
23952 mutex_unlock(&tty->ipw_tty_mutex);
23955 @@ -240,7 +238,7 @@ static int ipw_write(struct tty_struct *
23958 mutex_lock(&tty->ipw_tty_mutex);
23959 - if (!tty->open_count) {
23960 + if (!atomic_read(&tty->open_count)) {
23961 mutex_unlock(&tty->ipw_tty_mutex);
23964 @@ -280,7 +278,7 @@ static int ipw_write_room(struct tty_str
23968 - if (!tty->open_count)
23969 + if (!atomic_read(&tty->open_count))
23972 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
23973 @@ -322,7 +320,7 @@ static int ipw_chars_in_buffer(struct tt
23977 - if (!tty->open_count)
23978 + if (!atomic_read(&tty->open_count))
23981 return tty->tx_bytes_queued;
23982 @@ -403,7 +401,7 @@ static int ipw_tiocmget(struct tty_struc
23986 - if (!tty->open_count)
23987 + if (!atomic_read(&tty->open_count))
23990 return get_control_lines(tty);
23991 @@ -419,7 +417,7 @@ ipw_tiocmset(struct tty_struct *linux_tt
23995 - if (!tty->open_count)
23996 + if (!atomic_read(&tty->open_count))
23999 return set_control_lines(tty, set, clear);
24000 @@ -433,7 +431,7 @@ static int ipw_ioctl(struct tty_struct *
24004 - if (!tty->open_count)
24005 + if (!atomic_read(&tty->open_count))
24008 /* FIXME: Exactly how is the tty object locked here .. */
24009 @@ -582,7 +580,7 @@ void ipwireless_tty_free(struct ipw_tty
24010 against a parallel ioctl etc */
24011 mutex_lock(&ttyj->ipw_tty_mutex);
24013 - while (ttyj->open_count)
24014 + while (atomic_read(&ttyj->open_count))
24015 do_ipw_close(ttyj);
24016 ipwireless_disassociate_network_ttys(network,
24017 ttyj->channel_idx);
24018 diff -urNp linux-2.6.37/drivers/char/random.c linux-2.6.37/drivers/char/random.c
24019 --- linux-2.6.37/drivers/char/random.c 2011-01-04 19:50:19.000000000 -0500
24020 +++ linux-2.6.37/drivers/char/random.c 2011-01-17 02:41:01.000000000 -0500
24021 @@ -254,8 +254,13 @@
24023 * Configuration information
24025 +#ifdef CONFIG_GRKERNSEC_RANDNET
24026 +#define INPUT_POOL_WORDS 512
24027 +#define OUTPUT_POOL_WORDS 128
24029 #define INPUT_POOL_WORDS 128
24030 #define OUTPUT_POOL_WORDS 32
24032 #define SEC_XFER_SIZE 512
24033 #define EXTRACT_SIZE 10
24035 @@ -293,10 +298,17 @@ static struct poolinfo {
24037 int tap1, tap2, tap3, tap4, tap5;
24038 } poolinfo_table[] = {
24039 +#ifdef CONFIG_GRKERNSEC_RANDNET
24040 + /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
24041 + { 512, 411, 308, 208, 104, 1 },
24042 + /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
24043 + { 128, 103, 76, 51, 25, 1 },
24045 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
24046 { 128, 103, 76, 51, 25, 1 },
24047 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
24048 { 32, 26, 20, 14, 7, 1 },
24051 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
24052 { 2048, 1638, 1231, 819, 411, 1 },
24053 @@ -902,7 +914,7 @@ static ssize_t extract_entropy_user(stru
24055 extract_buf(r, tmp);
24056 i = min_t(int, nbytes, EXTRACT_SIZE);
24057 - if (copy_to_user(buf, tmp, i)) {
24058 + if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
24062 @@ -1207,7 +1219,7 @@ EXPORT_SYMBOL(generate_random_uuid);
24063 #include <linux/sysctl.h>
24065 static int min_read_thresh = 8, min_write_thresh;
24066 -static int max_read_thresh = INPUT_POOL_WORDS * 32;
24067 +static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
24068 static int max_write_thresh = INPUT_POOL_WORDS * 32;
24069 static char sysctl_bootid[16];
24071 diff -urNp linux-2.6.37/drivers/char/sonypi.c linux-2.6.37/drivers/char/sonypi.c
24072 --- linux-2.6.37/drivers/char/sonypi.c 2011-01-04 19:50:19.000000000 -0500
24073 +++ linux-2.6.37/drivers/char/sonypi.c 2011-01-17 02:41:01.000000000 -0500
24074 @@ -491,7 +491,7 @@ static struct sonypi_device {
24075 spinlock_t fifo_lock;
24076 wait_queue_head_t fifo_proc_list;
24077 struct fasync_struct *fifo_async;
24079 + atomic_t open_count;
24081 struct input_dev *input_jog_dev;
24082 struct input_dev *input_key_dev;
24083 @@ -898,7 +898,7 @@ static int sonypi_misc_fasync(int fd, st
24084 static int sonypi_misc_release(struct inode *inode, struct file *file)
24086 mutex_lock(&sonypi_device.lock);
24087 - sonypi_device.open_count--;
24088 + atomic_dec(&sonypi_device.open_count);
24089 mutex_unlock(&sonypi_device.lock);
24092 @@ -907,9 +907,9 @@ static int sonypi_misc_open(struct inode
24094 mutex_lock(&sonypi_device.lock);
24095 /* Flush input queue on first open */
24096 - if (!sonypi_device.open_count)
24097 + if (!atomic_read(&sonypi_device.open_count))
24098 kfifo_reset(&sonypi_device.fifo);
24099 - sonypi_device.open_count++;
24100 + atomic_inc(&sonypi_device.open_count);
24101 mutex_unlock(&sonypi_device.lock);
24104 diff -urNp linux-2.6.37/drivers/char/tpm/tpm_bios.c linux-2.6.37/drivers/char/tpm/tpm_bios.c
24105 --- linux-2.6.37/drivers/char/tpm/tpm_bios.c 2011-01-04 19:50:19.000000000 -0500
24106 +++ linux-2.6.37/drivers/char/tpm/tpm_bios.c 2011-01-17 02:41:01.000000000 -0500
24107 @@ -173,7 +173,7 @@ static void *tpm_bios_measurements_start
24110 if ((event->event_type == 0 && event->event_size == 0) ||
24111 - ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
24112 + (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
24116 @@ -198,7 +198,7 @@ static void *tpm_bios_measurements_next(
24119 if ((event->event_type == 0 && event->event_size == 0) ||
24120 - ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
24121 + (event->event_size >= limit - v - sizeof(struct tcpa_event)))
24125 @@ -291,7 +291,8 @@ static int tpm_binary_bios_measurements_
24128 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
24129 - seq_putc(m, data[i]);
24130 + if (!seq_putc(m, data[i]))
24135 @@ -410,6 +411,11 @@ static int read_log(struct tpm_bios_log
24136 log->bios_event_log_end = log->bios_event_log + len;
24138 virt = acpi_os_map_memory(start, len);
24140 + kfree(log->bios_event_log);
24141 + log->bios_event_log = NULL;
24145 memcpy(log->bios_event_log, virt, len);
24147 diff -urNp linux-2.6.37/drivers/cpuidle/sysfs.c linux-2.6.37/drivers/cpuidle/sysfs.c
24148 --- linux-2.6.37/drivers/cpuidle/sysfs.c 2011-01-04 19:50:19.000000000 -0500
24149 +++ linux-2.6.37/drivers/cpuidle/sysfs.c 2011-01-17 02:41:01.000000000 -0500
24150 @@ -300,7 +300,7 @@ static struct kobj_type ktype_state_cpui
24151 .release = cpuidle_state_sysfs_release,
24154 -static void inline cpuidle_free_state_kobj(struct cpuidle_device *device, int i)
24155 +static inline void cpuidle_free_state_kobj(struct cpuidle_device *device, int i)
24157 kobject_put(&device->kobjs[i]->kobj);
24158 wait_for_completion(&device->kobjs[i]->kobj_unregister);
24159 diff -urNp linux-2.6.37/drivers/edac/edac_core.h linux-2.6.37/drivers/edac/edac_core.h
24160 --- linux-2.6.37/drivers/edac/edac_core.h 2011-01-04 19:50:19.000000000 -0500
24161 +++ linux-2.6.37/drivers/edac/edac_core.h 2011-01-17 02:41:01.000000000 -0500
24162 @@ -87,11 +87,11 @@ extern const char *edac_mem_types[];
24164 #else /* !CONFIG_EDAC_DEBUG */
24166 -#define debugf0( ... )
24167 -#define debugf1( ... )
24168 -#define debugf2( ... )
24169 -#define debugf3( ... )
24170 -#define debugf4( ... )
24171 +#define debugf0( ... ) do {} while (0)
24172 +#define debugf1( ... ) do {} while (0)
24173 +#define debugf2( ... ) do {} while (0)
24174 +#define debugf3( ... ) do {} while (0)
24175 +#define debugf4( ... ) do {} while (0)
24177 #endif /* !CONFIG_EDAC_DEBUG */
24179 diff -urNp linux-2.6.37/drivers/edac/edac_mc_sysfs.c linux-2.6.37/drivers/edac/edac_mc_sysfs.c
24180 --- linux-2.6.37/drivers/edac/edac_mc_sysfs.c 2011-01-04 19:50:19.000000000 -0500
24181 +++ linux-2.6.37/drivers/edac/edac_mc_sysfs.c 2011-01-17 02:41:01.000000000 -0500
24182 @@ -762,7 +762,7 @@ static void edac_inst_grp_release(struct
24185 /* Intermediate show/store table */
24186 -static struct sysfs_ops inst_grp_ops = {
24187 +static const struct sysfs_ops inst_grp_ops = {
24188 .show = inst_grp_show,
24189 .store = inst_grp_store
24191 diff -urNp linux-2.6.37/drivers/firewire/core-cdev.c linux-2.6.37/drivers/firewire/core-cdev.c
24192 --- linux-2.6.37/drivers/firewire/core-cdev.c 2011-01-04 19:50:19.000000000 -0500
24193 +++ linux-2.6.37/drivers/firewire/core-cdev.c 2011-01-17 02:41:01.000000000 -0500
24194 @@ -1329,8 +1329,7 @@ static int init_iso_resource(struct clie
24197 if ((request->channels == 0 && request->bandwidth == 0) ||
24198 - request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL ||
24199 - request->bandwidth < 0)
24200 + request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL)
24203 r = kmalloc(sizeof(*r), GFP_KERNEL);
24204 diff -urNp linux-2.6.37/drivers/firmware/dmi_scan.c linux-2.6.37/drivers/firmware/dmi_scan.c
24205 --- linux-2.6.37/drivers/firmware/dmi_scan.c 2011-01-04 19:50:19.000000000 -0500
24206 +++ linux-2.6.37/drivers/firmware/dmi_scan.c 2011-01-17 02:41:01.000000000 -0500
24207 @@ -442,11 +442,6 @@ void __init dmi_scan_machine(void)
24212 - * no iounmap() for that ioremap(); it would be a no-op, but
24213 - * it's so early in setup that sucker gets confused into doing
24214 - * what it shouldn't if we actually call it.
24216 p = dmi_ioremap(0xF0000, 0x10000);
24219 diff -urNp linux-2.6.37/drivers/gpu/drm/drm_crtc_helper.c linux-2.6.37/drivers/gpu/drm/drm_crtc_helper.c
24220 --- linux-2.6.37/drivers/gpu/drm/drm_crtc_helper.c 2011-01-04 19:50:19.000000000 -0500
24221 +++ linux-2.6.37/drivers/gpu/drm/drm_crtc_helper.c 2011-01-17 02:41:01.000000000 -0500
24222 @@ -276,7 +276,7 @@ static bool drm_encoder_crtc_ok(struct d
24223 struct drm_crtc *tmp;
24226 - WARN(!crtc, "checking null crtc?\n");
24231 diff -urNp linux-2.6.37/drivers/gpu/drm/drm_drv.c linux-2.6.37/drivers/gpu/drm/drm_drv.c
24232 --- linux-2.6.37/drivers/gpu/drm/drm_drv.c 2011-01-04 19:50:19.000000000 -0500
24233 +++ linux-2.6.37/drivers/gpu/drm/drm_drv.c 2011-01-17 02:41:01.000000000 -0500
24234 @@ -425,7 +425,7 @@ long drm_ioctl(struct file *filp,
24236 dev = file_priv->minor->dev;
24237 atomic_inc(&dev->ioctl_count);
24238 - atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
24239 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
24240 ++file_priv->ioctl_count;
24242 DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
24243 diff -urNp linux-2.6.37/drivers/gpu/drm/drm_fops.c linux-2.6.37/drivers/gpu/drm/drm_fops.c
24244 --- linux-2.6.37/drivers/gpu/drm/drm_fops.c 2011-01-04 19:50:19.000000000 -0500
24245 +++ linux-2.6.37/drivers/gpu/drm/drm_fops.c 2011-01-17 02:41:01.000000000 -0500
24246 @@ -70,7 +70,7 @@ static int drm_setup(struct drm_device *
24249 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
24250 - atomic_set(&dev->counts[i], 0);
24251 + atomic_set_unchecked(&dev->counts[i], 0);
24253 dev->sigdata.lock = NULL;
24255 @@ -134,8 +134,8 @@ int drm_open(struct inode *inode, struct
24257 retcode = drm_open_helper(inode, filp, dev);
24259 - atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
24260 - if (!dev->open_count++)
24261 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
24262 + if (atomic_inc_return(&dev->open_count) == 1)
24263 retcode = drm_setup(dev);
24266 @@ -470,7 +470,7 @@ int drm_release(struct inode *inode, str
24268 mutex_lock(&drm_global_mutex);
24270 - DRM_DEBUG("open_count = %d\n", dev->open_count);
24271 + DRM_DEBUG("open_count = %d\n", atomic_read(&dev->open_count));
24273 if (dev->driver->preclose)
24274 dev->driver->preclose(dev, file_priv);
24275 @@ -482,7 +482,7 @@ int drm_release(struct inode *inode, str
24276 DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
24277 task_pid_nr(current),
24278 (long)old_encode_dev(file_priv->minor->device),
24279 - dev->open_count);
24280 + atomic_read(&dev->open_count));
24282 /* if the master has gone away we can't do anything with the lock */
24283 if (file_priv->minor->master)
24284 @@ -563,8 +563,8 @@ int drm_release(struct inode *inode, str
24285 * End inline drm_release
24288 - atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
24289 - if (!--dev->open_count) {
24290 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
24291 + if (atomic_dec_and_test(&dev->open_count)) {
24292 if (atomic_read(&dev->ioctl_count)) {
24293 DRM_ERROR("Device busy: %d\n",
24294 atomic_read(&dev->ioctl_count));
24295 diff -urNp linux-2.6.37/drivers/gpu/drm/drm_global.c linux-2.6.37/drivers/gpu/drm/drm_global.c
24296 --- linux-2.6.37/drivers/gpu/drm/drm_global.c 2011-01-04 19:50:19.000000000 -0500
24297 +++ linux-2.6.37/drivers/gpu/drm/drm_global.c 2011-01-17 02:41:01.000000000 -0500
24299 struct drm_global_item {
24300 struct mutex mutex;
24303 + atomic_t refcount;
24306 static struct drm_global_item glob[DRM_GLOBAL_NUM];
24307 @@ -49,7 +49,7 @@ void drm_global_init(void)
24308 struct drm_global_item *item = &glob[i];
24309 mutex_init(&item->mutex);
24310 item->object = NULL;
24311 - item->refcount = 0;
24312 + atomic_set(&item->refcount, 0);
24316 @@ -59,7 +59,7 @@ void drm_global_release(void)
24317 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
24318 struct drm_global_item *item = &glob[i];
24319 BUG_ON(item->object != NULL);
24320 - BUG_ON(item->refcount != 0);
24321 + BUG_ON(atomic_read(&item->refcount) != 0);
24325 @@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_globa
24328 mutex_lock(&item->mutex);
24329 - if (item->refcount == 0) {
24330 + if (atomic_read(&item->refcount) == 0) {
24331 item->object = kzalloc(ref->size, GFP_KERNEL);
24332 if (unlikely(item->object == NULL)) {
24334 @@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_globa
24338 - ++item->refcount;
24339 + atomic_inc(&item->refcount);
24340 ref->object = item->object;
24341 object = item->object;
24342 mutex_unlock(&item->mutex);
24343 @@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_gl
24344 struct drm_global_item *item = &glob[ref->global_type];
24346 mutex_lock(&item->mutex);
24347 - BUG_ON(item->refcount == 0);
24348 + BUG_ON(atomic_read(&item->refcount) == 0);
24349 BUG_ON(ref->object != item->object);
24350 - if (--item->refcount == 0) {
24351 + if (atomic_dec_and_test(&item->refcount)) {
24353 item->object = NULL;
24355 diff -urNp linux-2.6.37/drivers/gpu/drm/drm_info.c linux-2.6.37/drivers/gpu/drm/drm_info.c
24356 --- linux-2.6.37/drivers/gpu/drm/drm_info.c 2011-01-04 19:50:19.000000000 -0500
24357 +++ linux-2.6.37/drivers/gpu/drm/drm_info.c 2011-01-17 02:41:01.000000000 -0500
24358 @@ -86,10 +86,14 @@ int drm_vm_info(struct seq_file *m, void
24359 struct drm_local_map *map;
24360 struct drm_map_list *r_list;
24362 - /* Hardcoded from _DRM_FRAME_BUFFER,
24363 - _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
24364 - _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
24365 - const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
24366 + static const char * const types[] = {
24367 + [_DRM_FRAME_BUFFER] = "FB",
24368 + [_DRM_REGISTERS] = "REG",
24369 + [_DRM_SHM] = "SHM",
24370 + [_DRM_AGP] = "AGP",
24371 + [_DRM_SCATTER_GATHER] = "SG",
24372 + [_DRM_CONSISTENT] = "PCI",
24373 + [_DRM_GEM] = "GEM" };
24377 @@ -100,7 +104,7 @@ int drm_vm_info(struct seq_file *m, void
24381 - if (map->type < 0 || map->type > 5)
24382 + if (map->type >= ARRAY_SIZE(types))
24385 type = types[map->type];
24386 diff -urNp linux-2.6.37/drivers/gpu/drm/drm_ioctl.c linux-2.6.37/drivers/gpu/drm/drm_ioctl.c
24387 --- linux-2.6.37/drivers/gpu/drm/drm_ioctl.c 2011-01-04 19:50:19.000000000 -0500
24388 +++ linux-2.6.37/drivers/gpu/drm/drm_ioctl.c 2011-01-17 02:41:01.000000000 -0500
24389 @@ -353,7 +353,7 @@ int drm_getstats(struct drm_device *dev,
24390 stats->data[i].value =
24391 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
24393 - stats->data[i].value = atomic_read(&dev->counts[i]);
24394 + stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
24395 stats->data[i].type = dev->types[i];
24398 diff -urNp linux-2.6.37/drivers/gpu/drm/drm_lock.c linux-2.6.37/drivers/gpu/drm/drm_lock.c
24399 --- linux-2.6.37/drivers/gpu/drm/drm_lock.c 2011-01-04 19:50:19.000000000 -0500
24400 +++ linux-2.6.37/drivers/gpu/drm/drm_lock.c 2011-01-17 02:41:01.000000000 -0500
24401 @@ -89,7 +89,7 @@ int drm_lock(struct drm_device *dev, voi
24402 if (drm_lock_take(&master->lock, lock->context)) {
24403 master->lock.file_priv = file_priv;
24404 master->lock.lock_time = jiffies;
24405 - atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
24406 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
24407 break; /* Got lock */
24410 @@ -160,7 +160,7 @@ int drm_unlock(struct drm_device *dev, v
24414 - atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
24415 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
24417 if (drm_lock_free(&master->lock, lock->context)) {
24418 /* FIXME: Should really bail out here. */
24419 diff -urNp linux-2.6.37/drivers/gpu/drm/i810/i810_dma.c linux-2.6.37/drivers/gpu/drm/i810/i810_dma.c
24420 --- linux-2.6.37/drivers/gpu/drm/i810/i810_dma.c 2011-01-04 19:50:19.000000000 -0500
24421 +++ linux-2.6.37/drivers/gpu/drm/i810/i810_dma.c 2011-01-17 02:41:01.000000000 -0500
24422 @@ -953,8 +953,8 @@ static int i810_dma_vertex(struct drm_de
24423 dma->buflist[vertex->idx],
24424 vertex->discard, vertex->used);
24426 - atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
24427 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
24428 + atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
24429 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
24430 sarea_priv->last_enqueue = dev_priv->counter - 1;
24431 sarea_priv->last_dispatch = (int)hw_status[5];
24433 @@ -1114,8 +1114,8 @@ static int i810_dma_mc(struct drm_device
24434 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
24437 - atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
24438 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
24439 + atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
24440 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
24441 sarea_priv->last_enqueue = dev_priv->counter - 1;
24442 sarea_priv->last_dispatch = (int)hw_status[5];
24444 diff -urNp linux-2.6.37/drivers/gpu/drm/i915/dvo_ch7017.c linux-2.6.37/drivers/gpu/drm/i915/dvo_ch7017.c
24445 --- linux-2.6.37/drivers/gpu/drm/i915/dvo_ch7017.c 2011-01-04 19:50:19.000000000 -0500
24446 +++ linux-2.6.37/drivers/gpu/drm/i915/dvo_ch7017.c 2011-01-17 02:41:01.000000000 -0500
24447 @@ -390,7 +390,7 @@ static void ch7017_destroy(struct intel_
24451 -struct intel_dvo_dev_ops ch7017_ops = {
24452 +const struct intel_dvo_dev_ops ch7017_ops = {
24453 .init = ch7017_init,
24454 .detect = ch7017_detect,
24455 .mode_valid = ch7017_mode_valid,
24456 diff -urNp linux-2.6.37/drivers/gpu/drm/i915/dvo_ch7xxx.c linux-2.6.37/drivers/gpu/drm/i915/dvo_ch7xxx.c
24457 --- linux-2.6.37/drivers/gpu/drm/i915/dvo_ch7xxx.c 2011-01-04 19:50:19.000000000 -0500
24458 +++ linux-2.6.37/drivers/gpu/drm/i915/dvo_ch7xxx.c 2011-01-17 02:41:01.000000000 -0500
24459 @@ -320,7 +320,7 @@ static void ch7xxx_destroy(struct intel_
24463 -struct intel_dvo_dev_ops ch7xxx_ops = {
24464 +const struct intel_dvo_dev_ops ch7xxx_ops = {
24465 .init = ch7xxx_init,
24466 .detect = ch7xxx_detect,
24467 .mode_valid = ch7xxx_mode_valid,
24468 diff -urNp linux-2.6.37/drivers/gpu/drm/i915/dvo.h linux-2.6.37/drivers/gpu/drm/i915/dvo.h
24469 --- linux-2.6.37/drivers/gpu/drm/i915/dvo.h 2011-01-04 19:50:19.000000000 -0500
24470 +++ linux-2.6.37/drivers/gpu/drm/i915/dvo.h 2011-01-17 02:41:01.000000000 -0500
24471 @@ -122,23 +122,23 @@ struct intel_dvo_dev_ops {
24473 * \return singly-linked list of modes or NULL if no modes found.
24475 - struct drm_display_mode *(*get_modes)(struct intel_dvo_device *dvo);
24476 + struct drm_display_mode *(* const get_modes)(struct intel_dvo_device *dvo);
24479 * Clean up driver-specific bits of the output
24481 - void (*destroy) (struct intel_dvo_device *dvo);
24482 + void (* const destroy) (struct intel_dvo_device *dvo);
24485 * Debugging hook to dump device registers to log file
24487 - void (*dump_regs)(struct intel_dvo_device *dvo);
24488 + void (* const dump_regs)(struct intel_dvo_device *dvo);
24491 -extern struct intel_dvo_dev_ops sil164_ops;
24492 -extern struct intel_dvo_dev_ops ch7xxx_ops;
24493 -extern struct intel_dvo_dev_ops ivch_ops;
24494 -extern struct intel_dvo_dev_ops tfp410_ops;
24495 -extern struct intel_dvo_dev_ops ch7017_ops;
24496 +extern const struct intel_dvo_dev_ops sil164_ops;
24497 +extern const struct intel_dvo_dev_ops ch7xxx_ops;
24498 +extern const struct intel_dvo_dev_ops ivch_ops;
24499 +extern const struct intel_dvo_dev_ops tfp410_ops;
24500 +extern const struct intel_dvo_dev_ops ch7017_ops;
24502 #endif /* _INTEL_DVO_H */
24503 diff -urNp linux-2.6.37/drivers/gpu/drm/i915/dvo_ivch.c linux-2.6.37/drivers/gpu/drm/i915/dvo_ivch.c
24504 --- linux-2.6.37/drivers/gpu/drm/i915/dvo_ivch.c 2011-01-04 19:50:19.000000000 -0500
24505 +++ linux-2.6.37/drivers/gpu/drm/i915/dvo_ivch.c 2011-01-17 02:41:01.000000000 -0500
24506 @@ -410,7 +410,7 @@ static void ivch_destroy(struct intel_dv
24510 -struct intel_dvo_dev_ops ivch_ops= {
24511 +const struct intel_dvo_dev_ops ivch_ops= {
24514 .mode_valid = ivch_mode_valid,
24515 diff -urNp linux-2.6.37/drivers/gpu/drm/i915/dvo_sil164.c linux-2.6.37/drivers/gpu/drm/i915/dvo_sil164.c
24516 --- linux-2.6.37/drivers/gpu/drm/i915/dvo_sil164.c 2011-01-04 19:50:19.000000000 -0500
24517 +++ linux-2.6.37/drivers/gpu/drm/i915/dvo_sil164.c 2011-01-17 02:41:01.000000000 -0500
24518 @@ -252,7 +252,7 @@ static void sil164_destroy(struct intel_
24522 -struct intel_dvo_dev_ops sil164_ops = {
24523 +const struct intel_dvo_dev_ops sil164_ops = {
24524 .init = sil164_init,
24525 .detect = sil164_detect,
24526 .mode_valid = sil164_mode_valid,
24527 diff -urNp linux-2.6.37/drivers/gpu/drm/i915/dvo_tfp410.c linux-2.6.37/drivers/gpu/drm/i915/dvo_tfp410.c
24528 --- linux-2.6.37/drivers/gpu/drm/i915/dvo_tfp410.c 2011-01-04 19:50:19.000000000 -0500
24529 +++ linux-2.6.37/drivers/gpu/drm/i915/dvo_tfp410.c 2011-01-17 02:41:01.000000000 -0500
24530 @@ -293,7 +293,7 @@ static void tfp410_destroy(struct intel_
24534 -struct intel_dvo_dev_ops tfp410_ops = {
24535 +const struct intel_dvo_dev_ops tfp410_ops = {
24536 .init = tfp410_init,
24537 .detect = tfp410_detect,
24538 .mode_valid = tfp410_mode_valid,
24539 diff -urNp linux-2.6.37/drivers/gpu/drm/i915/i915_dma.c linux-2.6.37/drivers/gpu/drm/i915/i915_dma.c
24540 --- linux-2.6.37/drivers/gpu/drm/i915/i915_dma.c 2011-01-04 19:50:19.000000000 -0500
24541 +++ linux-2.6.37/drivers/gpu/drm/i915/i915_dma.c 2011-01-17 02:41:01.000000000 -0500
24542 @@ -1191,7 +1191,7 @@ static bool i915_switcheroo_can_switch(s
24545 spin_lock(&dev->count_lock);
24546 - can_switch = (dev->open_count == 0);
24547 + can_switch = (atomic_read(&dev->open_count) == 0);
24548 spin_unlock(&dev->count_lock);
24551 diff -urNp linux-2.6.37/drivers/gpu/drm/i915/i915_drv.c linux-2.6.37/drivers/gpu/drm/i915/i915_drv.c
24552 --- linux-2.6.37/drivers/gpu/drm/i915/i915_drv.c 2011-01-04 19:50:19.000000000 -0500
24553 +++ linux-2.6.37/drivers/gpu/drm/i915/i915_drv.c 2011-01-17 02:41:01.000000000 -0500
24554 @@ -579,7 +579,7 @@ static const struct dev_pm_ops i915_pm_o
24555 .restore = i915_pm_resume,
24558 -static struct vm_operations_struct i915_gem_vm_ops = {
24559 +static const struct vm_operations_struct i915_gem_vm_ops = {
24560 .fault = i915_gem_fault,
24561 .open = drm_gem_vm_open,
24562 .close = drm_gem_vm_close,
24563 diff -urNp linux-2.6.37/drivers/gpu/drm/i915/i915_gem.c linux-2.6.37/drivers/gpu/drm/i915/i915_gem.c
24564 --- linux-2.6.37/drivers/gpu/drm/i915/i915_gem.c 2011-01-04 19:50:19.000000000 -0500
24565 +++ linux-2.6.37/drivers/gpu/drm/i915/i915_gem.c 2011-01-17 02:41:01.000000000 -0500
24566 @@ -587,6 +587,7 @@ i915_gem_pread_ioctl(struct drm_device *
24571 if (!i915_gem_object_needs_bit17_swizzle(obj))
24572 ret = i915_gem_shmem_pread_fast(dev, obj, args, file_priv);
24573 if (ret == -EFAULT)
24574 diff -urNp linux-2.6.37/drivers/gpu/drm/nouveau/nouveau_backlight.c linux-2.6.37/drivers/gpu/drm/nouveau/nouveau_backlight.c
24575 --- linux-2.6.37/drivers/gpu/drm/nouveau/nouveau_backlight.c 2011-01-04 19:50:19.000000000 -0500
24576 +++ linux-2.6.37/drivers/gpu/drm/nouveau/nouveau_backlight.c 2011-01-17 02:41:01.000000000 -0500
24577 @@ -59,7 +59,7 @@ static int nv40_set_intensity(struct bac
24581 -static struct backlight_ops nv40_bl_ops = {
24582 +static const struct backlight_ops nv40_bl_ops = {
24583 .options = BL_CORE_SUSPENDRESUME,
24584 .get_brightness = nv40_get_intensity,
24585 .update_status = nv40_set_intensity,
24586 @@ -82,7 +82,7 @@ static int nv50_set_intensity(struct bac
24590 -static struct backlight_ops nv50_bl_ops = {
24591 +static const struct backlight_ops nv50_bl_ops = {
24592 .options = BL_CORE_SUSPENDRESUME,
24593 .get_brightness = nv50_get_intensity,
24594 .update_status = nv50_set_intensity,
24595 diff -urNp linux-2.6.37/drivers/gpu/drm/nouveau/nouveau_state.c linux-2.6.37/drivers/gpu/drm/nouveau/nouveau_state.c
24596 --- linux-2.6.37/drivers/gpu/drm/nouveau/nouveau_state.c 2011-01-04 19:50:19.000000000 -0500
24597 +++ linux-2.6.37/drivers/gpu/drm/nouveau/nouveau_state.c 2011-01-17 02:41:01.000000000 -0500
24598 @@ -546,7 +546,7 @@ static bool nouveau_switcheroo_can_switc
24601 spin_lock(&dev->count_lock);
24602 - can_switch = (dev->open_count == 0);
24603 + can_switch = (atomic_read(&dev->open_count) == 0);
24604 spin_unlock(&dev->count_lock);
24607 diff -urNp linux-2.6.37/drivers/gpu/drm/radeon/mkregtable.c linux-2.6.37/drivers/gpu/drm/radeon/mkregtable.c
24608 --- linux-2.6.37/drivers/gpu/drm/radeon/mkregtable.c 2011-01-04 19:50:19.000000000 -0500
24609 +++ linux-2.6.37/drivers/gpu/drm/radeon/mkregtable.c 2011-01-17 02:41:01.000000000 -0500
24610 @@ -637,14 +637,14 @@ static int parser_auth(struct table *t,
24612 regmatch_t match[4];
24620 struct offset *offset;
24621 char last_reg_s[10];
24623 + unsigned long last_reg;
24626 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
24627 diff -urNp linux-2.6.37/drivers/gpu/drm/radeon/radeon_device.c linux-2.6.37/drivers/gpu/drm/radeon/radeon_device.c
24628 --- linux-2.6.37/drivers/gpu/drm/radeon/radeon_device.c 2011-01-04 19:50:19.000000000 -0500
24629 +++ linux-2.6.37/drivers/gpu/drm/radeon/radeon_device.c 2011-01-17 02:41:01.000000000 -0500
24630 @@ -659,7 +659,7 @@ static bool radeon_switcheroo_can_switch
24633 spin_lock(&dev->count_lock);
24634 - can_switch = (dev->open_count == 0);
24635 + can_switch = (atomic_read(&dev->open_count) == 0);
24636 spin_unlock(&dev->count_lock);
24639 diff -urNp linux-2.6.37/drivers/gpu/drm/radeon/radeon_state.c linux-2.6.37/drivers/gpu/drm/radeon/radeon_state.c
24640 --- linux-2.6.37/drivers/gpu/drm/radeon/radeon_state.c 2011-01-04 19:50:19.000000000 -0500
24641 +++ linux-2.6.37/drivers/gpu/drm/radeon/radeon_state.c 2011-01-17 02:41:01.000000000 -0500
24642 @@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_de
24643 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
24644 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
24646 - if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
24647 + if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
24648 sarea_priv->nbox * sizeof(depth_boxes[0])))
24651 @@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm
24653 drm_radeon_private_t *dev_priv = dev->dev_private;
24654 drm_radeon_getparam_t *param = data;
24658 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
24660 diff -urNp linux-2.6.37/drivers/gpu/drm/radeon/radeon_ttm.c linux-2.6.37/drivers/gpu/drm/radeon/radeon_ttm.c
24661 --- linux-2.6.37/drivers/gpu/drm/radeon/radeon_ttm.c 2011-01-04 19:50:19.000000000 -0500
24662 +++ linux-2.6.37/drivers/gpu/drm/radeon/radeon_ttm.c 2011-01-17 02:41:01.000000000 -0500
24663 @@ -589,8 +589,9 @@ void radeon_ttm_fini(struct radeon_devic
24664 DRM_INFO("radeon: ttm finalized\n");
24667 -static struct vm_operations_struct radeon_ttm_vm_ops;
24668 -static const struct vm_operations_struct *ttm_vm_ops = NULL;
24669 +extern int ttm_bo_vm_fault(struct vm_area_struct *vma, struct vm_fault *vmf);
24670 +extern void ttm_bo_vm_open(struct vm_area_struct *vma);
24671 +extern void ttm_bo_vm_close(struct vm_area_struct *vma);
24673 static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
24675 @@ -598,17 +599,22 @@ static int radeon_ttm_fault(struct vm_ar
24676 struct radeon_device *rdev;
24679 - bo = (struct ttm_buffer_object *)vma->vm_private_data;
24680 - if (bo == NULL) {
24681 + bo = (struct ttm_buffer_object *)vma->vm_private_data;
24683 return VM_FAULT_NOPAGE;
24685 rdev = radeon_get_rdev(bo->bdev);
24686 mutex_lock(&rdev->vram_mutex);
24687 - r = ttm_vm_ops->fault(vma, vmf);
24688 + r = ttm_bo_vm_fault(vma, vmf);
24689 mutex_unlock(&rdev->vram_mutex);
24693 +static const struct vm_operations_struct radeon_ttm_vm_ops = {
24694 + .fault = radeon_ttm_fault,
24695 + .open = ttm_bo_vm_open,
24696 + .close = ttm_bo_vm_close
24699 int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
24701 struct drm_file *file_priv;
24702 @@ -621,18 +627,11 @@ int radeon_mmap(struct file *filp, struc
24704 file_priv = filp->private_data;
24705 rdev = file_priv->minor->dev->dev_private;
24706 - if (rdev == NULL) {
24710 r = ttm_bo_mmap(filp, vma, &rdev->mman.bdev);
24711 - if (unlikely(r != 0)) {
24715 - if (unlikely(ttm_vm_ops == NULL)) {
24716 - ttm_vm_ops = vma->vm_ops;
24717 - radeon_ttm_vm_ops = *ttm_vm_ops;
24718 - radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
24720 vma->vm_ops = &radeon_ttm_vm_ops;
24723 diff -urNp linux-2.6.37/drivers/gpu/drm/ttm/ttm_bo.c linux-2.6.37/drivers/gpu/drm/ttm/ttm_bo.c
24724 --- linux-2.6.37/drivers/gpu/drm/ttm/ttm_bo.c 2011-01-04 19:50:19.000000000 -0500
24725 +++ linux-2.6.37/drivers/gpu/drm/ttm/ttm_bo.c 2011-01-17 02:41:01.000000000 -0500
24727 #include <asm/atomic.h>
24729 #define TTM_ASSERT_LOCKED(param)
24730 -#define TTM_DEBUG(fmt, arg...)
24731 +#define TTM_DEBUG(fmt, arg...) do {} while (0)
24732 #define TTM_BO_HASH_ORDER 13
24734 static int ttm_bo_setup_vm(struct ttm_buffer_object *bo);
24735 diff -urNp linux-2.6.37/drivers/gpu/drm/ttm/ttm_bo_vm.c linux-2.6.37/drivers/gpu/drm/ttm/ttm_bo_vm.c
24736 --- linux-2.6.37/drivers/gpu/drm/ttm/ttm_bo_vm.c 2011-01-04 19:50:19.000000000 -0500
24737 +++ linux-2.6.37/drivers/gpu/drm/ttm/ttm_bo_vm.c 2011-01-17 02:41:01.000000000 -0500
24738 @@ -69,11 +69,11 @@ static struct ttm_buffer_object *ttm_bo_
24742 -static int ttm_bo_vm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
24743 +int ttm_bo_vm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
24745 struct ttm_buffer_object *bo = (struct ttm_buffer_object *)
24746 vma->vm_private_data;
24747 - struct ttm_bo_device *bdev = bo->bdev;
24748 + struct ttm_bo_device *bdev;
24749 unsigned long page_offset;
24750 unsigned long page_last;
24752 @@ -84,6 +84,10 @@ static int ttm_bo_vm_fault(struct vm_are
24753 unsigned long address = (unsigned long)vmf->virtual_address;
24754 int retval = VM_FAULT_NOPAGE;
24757 + return VM_FAULT_NOPAGE;
24761 * Work around locking order reversal in fault / nopfn
24762 * between mmap_sem and bo_reserve: Perform a trylock operation
24763 @@ -212,22 +216,25 @@ out_unlock:
24764 ttm_bo_unreserve(bo);
24767 +EXPORT_SYMBOL(ttm_bo_vm_fault);
24769 -static void ttm_bo_vm_open(struct vm_area_struct *vma)
24770 +void ttm_bo_vm_open(struct vm_area_struct *vma)
24772 struct ttm_buffer_object *bo =
24773 (struct ttm_buffer_object *)vma->vm_private_data;
24775 (void)ttm_bo_reference(bo);
24777 +EXPORT_SYMBOL(ttm_bo_vm_open);
24779 -static void ttm_bo_vm_close(struct vm_area_struct *vma)
24780 +void ttm_bo_vm_close(struct vm_area_struct *vma)
24782 struct ttm_buffer_object *bo = (struct ttm_buffer_object *)vma->vm_private_data;
24785 vma->vm_private_data = NULL;
24787 +EXPORT_SYMBOL(ttm_bo_vm_close);
24789 static const struct vm_operations_struct ttm_bo_vm_ops = {
24790 .fault = ttm_bo_vm_fault,
24791 diff -urNp linux-2.6.37/drivers/hid/usbhid/hiddev.c linux-2.6.37/drivers/hid/usbhid/hiddev.c
24792 --- linux-2.6.37/drivers/hid/usbhid/hiddev.c 2011-01-04 19:50:19.000000000 -0500
24793 +++ linux-2.6.37/drivers/hid/usbhid/hiddev.c 2011-01-17 02:41:01.000000000 -0500
24794 @@ -611,7 +611,7 @@ static long hiddev_ioctl(struct file *fi
24795 return put_user(HID_VERSION, (int __user *)arg);
24797 case HIDIOCAPPLICATION:
24798 - if (arg < 0 || arg >= hid->maxapplication)
24799 + if (arg >= hid->maxapplication)
24802 for (i = 0; i < hid->maxcollection; i++)
24803 diff -urNp linux-2.6.37/drivers/hwmon/k8temp.c linux-2.6.37/drivers/hwmon/k8temp.c
24804 --- linux-2.6.37/drivers/hwmon/k8temp.c 2011-01-04 19:50:19.000000000 -0500
24805 +++ linux-2.6.37/drivers/hwmon/k8temp.c 2011-01-17 02:41:01.000000000 -0500
24806 @@ -138,7 +138,7 @@ static DEVICE_ATTR(name, S_IRUGO, show_n
24808 static const struct pci_device_id k8temp_ids[] = {
24809 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_K8_NB_MISC) },
24811 + { 0, 0, 0, 0, 0, 0, 0 },
24814 MODULE_DEVICE_TABLE(pci, k8temp_ids);
24815 diff -urNp linux-2.6.37/drivers/hwmon/sis5595.c linux-2.6.37/drivers/hwmon/sis5595.c
24816 --- linux-2.6.37/drivers/hwmon/sis5595.c 2011-01-04 19:50:19.000000000 -0500
24817 +++ linux-2.6.37/drivers/hwmon/sis5595.c 2011-01-17 02:41:01.000000000 -0500
24818 @@ -699,7 +699,7 @@ static struct sis5595_data *sis5595_upda
24820 static const struct pci_device_id sis5595_pci_ids[] = {
24821 { PCI_DEVICE(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_503) },
24823 + { 0, 0, 0, 0, 0, 0, 0 }
24826 MODULE_DEVICE_TABLE(pci, sis5595_pci_ids);
24827 diff -urNp linux-2.6.37/drivers/hwmon/via686a.c linux-2.6.37/drivers/hwmon/via686a.c
24828 --- linux-2.6.37/drivers/hwmon/via686a.c 2011-01-04 19:50:19.000000000 -0500
24829 +++ linux-2.6.37/drivers/hwmon/via686a.c 2011-01-17 02:41:01.000000000 -0500
24830 @@ -769,7 +769,7 @@ static struct via686a_data *via686a_upda
24832 static const struct pci_device_id via686a_pci_ids[] = {
24833 { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C686_4) },
24835 + { 0, 0, 0, 0, 0, 0, 0 }
24838 MODULE_DEVICE_TABLE(pci, via686a_pci_ids);
24839 diff -urNp linux-2.6.37/drivers/hwmon/vt8231.c linux-2.6.37/drivers/hwmon/vt8231.c
24840 --- linux-2.6.37/drivers/hwmon/vt8231.c 2011-01-04 19:50:19.000000000 -0500
24841 +++ linux-2.6.37/drivers/hwmon/vt8231.c 2011-01-17 02:41:01.000000000 -0500
24842 @@ -699,7 +699,7 @@ static struct platform_driver vt8231_dri
24844 static const struct pci_device_id vt8231_pci_ids[] = {
24845 { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8231_4) },
24847 + { 0, 0, 0, 0, 0, 0, 0 }
24850 MODULE_DEVICE_TABLE(pci, vt8231_pci_ids);
24851 diff -urNp linux-2.6.37/drivers/hwmon/w83791d.c linux-2.6.37/drivers/hwmon/w83791d.c
24852 --- linux-2.6.37/drivers/hwmon/w83791d.c 2011-01-04 19:50:19.000000000 -0500
24853 +++ linux-2.6.37/drivers/hwmon/w83791d.c 2011-01-17 02:41:01.000000000 -0500
24854 @@ -329,8 +329,8 @@ static int w83791d_detect(struct i2c_cli
24855 struct i2c_board_info *info);
24856 static int w83791d_remove(struct i2c_client *client);
24858 -static int w83791d_read(struct i2c_client *client, u8 register);
24859 -static int w83791d_write(struct i2c_client *client, u8 register, u8 value);
24860 +static int w83791d_read(struct i2c_client *client, u8 reg);
24861 +static int w83791d_write(struct i2c_client *client, u8 reg, u8 value);
24862 static struct w83791d_data *w83791d_update_device(struct device *dev);
24865 diff -urNp linux-2.6.37/drivers/i2c/busses/i2c-i801.c linux-2.6.37/drivers/i2c/busses/i2c-i801.c
24866 --- linux-2.6.37/drivers/i2c/busses/i2c-i801.c 2011-01-04 19:50:19.000000000 -0500
24867 +++ linux-2.6.37/drivers/i2c/busses/i2c-i801.c 2011-01-17 02:41:01.000000000 -0500
24868 @@ -620,7 +620,7 @@ static const struct pci_device_id i801_i
24869 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS_IDF0) },
24870 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS_IDF1) },
24871 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS_IDF2) },
24873 + { 0, 0, 0, 0, 0, 0, 0 }
24876 MODULE_DEVICE_TABLE(pci, i801_ids);
24877 diff -urNp linux-2.6.37/drivers/i2c/busses/i2c-piix4.c linux-2.6.37/drivers/i2c/busses/i2c-piix4.c
24878 --- linux-2.6.37/drivers/i2c/busses/i2c-piix4.c 2011-01-04 19:50:19.000000000 -0500
24879 +++ linux-2.6.37/drivers/i2c/busses/i2c-piix4.c 2011-01-17 02:41:01.000000000 -0500
24880 @@ -124,7 +124,7 @@ static struct dmi_system_id __devinitdat
24882 .matches = { DMI_MATCH(DMI_SYS_VENDOR, "IBM"), },
24885 + { NULL, NULL, {DMI_MATCH(DMI_NONE, {0})}, NULL }
24888 static int __devinit piix4_setup(struct pci_dev *PIIX4_dev,
24889 @@ -491,7 +491,7 @@ static const struct pci_device_id piix4_
24890 PCI_DEVICE_ID_SERVERWORKS_HT1000SB) },
24891 { PCI_DEVICE(PCI_VENDOR_ID_SERVERWORKS,
24892 PCI_DEVICE_ID_SERVERWORKS_HT1100LD) },
24894 + { 0, 0, 0, 0, 0, 0, 0 }
24897 MODULE_DEVICE_TABLE (pci, piix4_ids);
24898 diff -urNp linux-2.6.37/drivers/i2c/busses/i2c-sis630.c linux-2.6.37/drivers/i2c/busses/i2c-sis630.c
24899 --- linux-2.6.37/drivers/i2c/busses/i2c-sis630.c 2011-01-04 19:50:19.000000000 -0500
24900 +++ linux-2.6.37/drivers/i2c/busses/i2c-sis630.c 2011-01-17 02:41:01.000000000 -0500
24901 @@ -471,7 +471,7 @@ static struct i2c_adapter sis630_adapter
24902 static const struct pci_device_id sis630_ids[] __devinitconst = {
24903 { PCI_DEVICE(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_503) },
24904 { PCI_DEVICE(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_LPC) },
24906 + { 0, 0, 0, 0, 0, 0, 0 }
24909 MODULE_DEVICE_TABLE (pci, sis630_ids);
24910 diff -urNp linux-2.6.37/drivers/i2c/busses/i2c-sis96x.c linux-2.6.37/drivers/i2c/busses/i2c-sis96x.c
24911 --- linux-2.6.37/drivers/i2c/busses/i2c-sis96x.c 2011-01-04 19:50:19.000000000 -0500
24912 +++ linux-2.6.37/drivers/i2c/busses/i2c-sis96x.c 2011-01-17 02:41:01.000000000 -0500
24913 @@ -247,7 +247,7 @@ static struct i2c_adapter sis96x_adapter
24915 static const struct pci_device_id sis96x_ids[] = {
24916 { PCI_DEVICE(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_SMBUS) },
24918 + { 0, 0, 0, 0, 0, 0, 0 }
24921 MODULE_DEVICE_TABLE (pci, sis96x_ids);
24922 diff -urNp linux-2.6.37/drivers/ide/ide-cd.c linux-2.6.37/drivers/ide/ide-cd.c
24923 --- linux-2.6.37/drivers/ide/ide-cd.c 2011-01-04 19:50:19.000000000 -0500
24924 +++ linux-2.6.37/drivers/ide/ide-cd.c 2011-01-17 02:41:01.000000000 -0500
24925 @@ -776,7 +776,7 @@ static void cdrom_do_block_pc(ide_drive_
24926 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
24927 if ((unsigned long)buf & alignment
24928 || blk_rq_bytes(rq) & q->dma_pad_mask
24929 - || object_is_on_stack(buf))
24930 + || object_starts_on_stack(buf))
24934 diff -urNp linux-2.6.37/drivers/infiniband/core/cm.c linux-2.6.37/drivers/infiniband/core/cm.c
24935 --- linux-2.6.37/drivers/infiniband/core/cm.c 2011-01-04 19:50:19.000000000 -0500
24936 +++ linux-2.6.37/drivers/infiniband/core/cm.c 2011-01-17 02:41:01.000000000 -0500
24937 @@ -113,7 +113,7 @@ static char const counter_group_names[CM
24939 struct cm_counter_group {
24940 struct kobject obj;
24941 - atomic_long_t counter[CM_ATTR_COUNT];
24942 + atomic_long_unchecked_t counter[CM_ATTR_COUNT];
24945 struct cm_counter_attribute {
24946 @@ -1387,7 +1387,7 @@ static void cm_dup_req_handler(struct cm
24947 struct ib_mad_send_buf *msg = NULL;
24950 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
24951 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
24952 counter[CM_REQ_COUNTER]);
24954 /* Quick state check to discard duplicate REQs. */
24955 @@ -1765,7 +1765,7 @@ static void cm_dup_rep_handler(struct cm
24959 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
24960 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
24961 counter[CM_REP_COUNTER]);
24962 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
24964 @@ -1932,7 +1932,7 @@ static int cm_rtu_handler(struct cm_work
24965 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
24966 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
24967 spin_unlock_irq(&cm_id_priv->lock);
24968 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
24969 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
24970 counter[CM_RTU_COUNTER]);
24973 @@ -2111,7 +2111,7 @@ static int cm_dreq_handler(struct cm_wor
24974 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
24975 dreq_msg->local_comm_id);
24977 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
24978 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
24979 counter[CM_DREQ_COUNTER]);
24980 cm_issue_drep(work->port, work->mad_recv_wc);
24982 @@ -2132,7 +2132,7 @@ static int cm_dreq_handler(struct cm_wor
24983 case IB_CM_MRA_REP_RCVD:
24985 case IB_CM_TIMEWAIT:
24986 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
24987 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
24988 counter[CM_DREQ_COUNTER]);
24989 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
24991 @@ -2146,7 +2146,7 @@ static int cm_dreq_handler(struct cm_wor
24994 case IB_CM_DREQ_RCVD:
24995 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
24996 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
24997 counter[CM_DREQ_COUNTER]);
25000 @@ -2504,7 +2504,7 @@ static int cm_mra_handler(struct cm_work
25001 ib_modify_mad(cm_id_priv->av.port->mad_agent,
25002 cm_id_priv->msg, timeout)) {
25003 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
25004 - atomic_long_inc(&work->port->
25005 + atomic_long_inc_unchecked(&work->port->
25006 counter_group[CM_RECV_DUPLICATES].
25007 counter[CM_MRA_COUNTER]);
25009 @@ -2513,7 +2513,7 @@ static int cm_mra_handler(struct cm_work
25011 case IB_CM_MRA_REQ_RCVD:
25012 case IB_CM_MRA_REP_RCVD:
25013 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
25014 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
25015 counter[CM_MRA_COUNTER]);
25018 @@ -2675,7 +2675,7 @@ static int cm_lap_handler(struct cm_work
25019 case IB_CM_LAP_IDLE:
25021 case IB_CM_MRA_LAP_SENT:
25022 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
25023 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
25024 counter[CM_LAP_COUNTER]);
25025 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
25027 @@ -2691,7 +2691,7 @@ static int cm_lap_handler(struct cm_work
25030 case IB_CM_LAP_RCVD:
25031 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
25032 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
25033 counter[CM_LAP_COUNTER]);
25036 @@ -2975,7 +2975,7 @@ static int cm_sidr_req_handler(struct cm
25037 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
25038 if (cur_cm_id_priv) {
25039 spin_unlock_irq(&cm.lock);
25040 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
25041 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
25042 counter[CM_SIDR_REQ_COUNTER]);
25043 goto out; /* Duplicate message. */
25045 @@ -3186,10 +3186,10 @@ static void cm_send_handler(struct ib_ma
25046 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
25049 - atomic_long_add(1 + msg->retries,
25050 + atomic_long_add_unchecked(1 + msg->retries,
25051 &port->counter_group[CM_XMIT].counter[attr_index]);
25053 - atomic_long_add(msg->retries,
25054 + atomic_long_add_unchecked(msg->retries,
25055 &port->counter_group[CM_XMIT_RETRIES].
25056 counter[attr_index]);
25058 @@ -3399,7 +3399,7 @@ static void cm_recv_handler(struct ib_ma
25061 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
25062 - atomic_long_inc(&port->counter_group[CM_RECV].
25063 + atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
25064 counter[attr_id - CM_ATTR_ID_OFFSET]);
25066 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
25067 @@ -3597,7 +3597,7 @@ static ssize_t cm_show_counter(struct ko
25068 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
25070 return sprintf(buf, "%ld\n",
25071 - atomic_long_read(&group->counter[cm_attr->index]));
25072 + atomic_long_read_unchecked(&group->counter[cm_attr->index]));
25075 static const struct sysfs_ops cm_counter_ops = {
25076 diff -urNp linux-2.6.37/drivers/infiniband/hw/qib/qib.h linux-2.6.37/drivers/infiniband/hw/qib/qib.h
25077 --- linux-2.6.37/drivers/infiniband/hw/qib/qib.h 2011-01-04 19:50:19.000000000 -0500
25078 +++ linux-2.6.37/drivers/infiniband/hw/qib/qib.h 2011-01-17 02:41:01.000000000 -0500
25080 #include <linux/completion.h>
25081 #include <linux/kref.h>
25082 #include <linux/sched.h>
25083 +#include <linux/slab.h>
25085 #include "qib_common.h"
25086 #include "qib_verbs.h"
25087 diff -urNp linux-2.6.37/drivers/input/keyboard/atkbd.c linux-2.6.37/drivers/input/keyboard/atkbd.c
25088 --- linux-2.6.37/drivers/input/keyboard/atkbd.c 2011-01-04 19:50:19.000000000 -0500
25089 +++ linux-2.6.37/drivers/input/keyboard/atkbd.c 2011-01-17 02:41:01.000000000 -0500
25090 @@ -1250,7 +1250,7 @@ static struct serio_device_id atkbd_seri
25092 .extra = SERIO_ANY,
25098 MODULE_DEVICE_TABLE(serio, atkbd_serio_ids);
25099 diff -urNp linux-2.6.37/drivers/input/mouse/lifebook.c linux-2.6.37/drivers/input/mouse/lifebook.c
25100 --- linux-2.6.37/drivers/input/mouse/lifebook.c 2011-01-04 19:50:19.000000000 -0500
25101 +++ linux-2.6.37/drivers/input/mouse/lifebook.c 2011-01-17 02:41:01.000000000 -0500
25102 @@ -123,7 +123,7 @@ static const struct dmi_system_id __init
25103 DMI_MATCH(DMI_PRODUCT_NAME, "LifeBook B142"),
25107 + { NULL, NULL, {DMI_MATCH(DMI_NONE, {0})}, NULL}
25110 void __init lifebook_module_init(void)
25111 diff -urNp linux-2.6.37/drivers/input/mouse/psmouse-base.c linux-2.6.37/drivers/input/mouse/psmouse-base.c
25112 --- linux-2.6.37/drivers/input/mouse/psmouse-base.c 2011-01-04 19:50:19.000000000 -0500
25113 +++ linux-2.6.37/drivers/input/mouse/psmouse-base.c 2011-01-17 02:41:01.000000000 -0500
25114 @@ -1462,7 +1462,7 @@ static struct serio_device_id psmouse_se
25116 .extra = SERIO_ANY,
25122 MODULE_DEVICE_TABLE(serio, psmouse_serio_ids);
25123 diff -urNp linux-2.6.37/drivers/input/mouse/synaptics.c linux-2.6.37/drivers/input/mouse/synaptics.c
25124 --- linux-2.6.37/drivers/input/mouse/synaptics.c 2011-01-04 19:50:19.000000000 -0500
25125 +++ linux-2.6.37/drivers/input/mouse/synaptics.c 2011-01-17 02:41:01.000000000 -0500
25126 @@ -499,7 +499,7 @@ static void synaptics_process_packet(str
25129 if (SYN_MODEL_PEN(priv->model_id))
25130 - ; /* Nothing, treat a pen as a single finger */
25131 + break; /* Nothing, treat a pen as a single finger */
25134 if (SYN_CAP_PALMDETECT(priv->capabilities))
25135 @@ -729,7 +729,6 @@ static const struct dmi_system_id __init
25136 DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
25137 DMI_MATCH(DMI_PRODUCT_NAME, "PORTEGE M300"),
25142 /* Toshiba Portege M300 */
25143 @@ -738,9 +737,8 @@ static const struct dmi_system_id __init
25144 DMI_MATCH(DMI_PRODUCT_NAME, "Portable PC"),
25145 DMI_MATCH(DMI_PRODUCT_VERSION, "Version 1.0"),
25150 + { NULL, NULL, {DMI_MATCH(DMI_NONE, {0})}, NULL }
25154 diff -urNp linux-2.6.37/drivers/input/mousedev.c linux-2.6.37/drivers/input/mousedev.c
25155 --- linux-2.6.37/drivers/input/mousedev.c 2011-01-04 19:50:19.000000000 -0500
25156 +++ linux-2.6.37/drivers/input/mousedev.c 2011-01-17 02:41:01.000000000 -0500
25157 @@ -762,7 +762,7 @@ static ssize_t mousedev_read(struct file
25159 spin_unlock_irq(&client->packet_lock);
25161 - if (copy_to_user(buffer, data, count))
25162 + if (count > sizeof(data) || copy_to_user(buffer, data, count))
25166 @@ -1065,7 +1065,7 @@ static struct input_handler mousedev_han
25168 #ifdef CONFIG_INPUT_MOUSEDEV_PSAUX
25169 static struct miscdevice psaux_mouse = {
25170 - PSMOUSE_MINOR, "psaux", &mousedev_fops
25171 + PSMOUSE_MINOR, "psaux", &mousedev_fops, {NULL, NULL}, NULL, NULL
25173 static int psaux_registered;
25175 diff -urNp linux-2.6.37/drivers/input/serio/i8042-x86ia64io.h linux-2.6.37/drivers/input/serio/i8042-x86ia64io.h
25176 --- linux-2.6.37/drivers/input/serio/i8042-x86ia64io.h 2011-01-04 19:50:19.000000000 -0500
25177 +++ linux-2.6.37/drivers/input/serio/i8042-x86ia64io.h 2011-01-17 02:41:01.000000000 -0500
25178 @@ -183,7 +183,7 @@ static const struct dmi_system_id __init
25179 DMI_MATCH(DMI_PRODUCT_VERSION, "Rev 1"),
25183 + { NULL, NULL, {DMI_MATCH(DMI_NONE, {0})}, NULL }
25187 @@ -424,7 +424,7 @@ static const struct dmi_system_id __init
25188 DMI_MATCH(DMI_PRODUCT_VERSION, "0100"),
25192 + { NULL, NULL, {DMI_MATCH(DMI_NONE, {0})}, NULL }
25195 static const struct dmi_system_id __initconst i8042_dmi_reset_table[] = {
25196 @@ -498,7 +498,7 @@ static const struct dmi_system_id __init
25197 DMI_MATCH(DMI_PRODUCT_NAME, "Vostro 1720"),
25201 + { NULL, NULL, {DMI_MATCH(DMI_NONE, {0})}, NULL }
25205 @@ -517,7 +517,7 @@ static const struct dmi_system_id __init
25206 DMI_MATCH(DMI_BOARD_VENDOR, "MICRO-STAR INTERNATIONAL CO., LTD"),
25210 + { NULL, NULL, {DMI_MATCH(DMI_NONE, {0})}, NULL }
25213 static const struct dmi_system_id __initconst i8042_dmi_laptop_table[] = {
25214 @@ -541,7 +541,7 @@ static const struct dmi_system_id __init
25215 DMI_MATCH(DMI_CHASSIS_TYPE, "14"), /* Sub-Notebook */
25219 + { NULL, NULL, {DMI_MATCH(DMI_NONE, {0})}, NULL }
25223 @@ -615,7 +615,7 @@ static const struct dmi_system_id __init
25224 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 4280"),
25228 + { NULL, NULL, {DMI_MATCH(DMI_NONE, {0})}, NULL }
25231 #endif /* CONFIG_X86 */
25232 diff -urNp linux-2.6.37/drivers/input/serio/serio_raw.c linux-2.6.37/drivers/input/serio/serio_raw.c
25233 --- linux-2.6.37/drivers/input/serio/serio_raw.c 2011-01-04 19:50:19.000000000 -0500
25234 +++ linux-2.6.37/drivers/input/serio/serio_raw.c 2011-01-17 02:41:01.000000000 -0500
25235 @@ -376,7 +376,7 @@ static struct serio_device_id serio_raw_
25237 .extra = SERIO_ANY,
25243 MODULE_DEVICE_TABLE(serio, serio_raw_serio_ids);
25244 diff -urNp linux-2.6.37/drivers/isdn/gigaset/common.c linux-2.6.37/drivers/isdn/gigaset/common.c
25245 --- linux-2.6.37/drivers/isdn/gigaset/common.c 2011-01-04 19:50:19.000000000 -0500
25246 +++ linux-2.6.37/drivers/isdn/gigaset/common.c 2011-01-17 02:41:01.000000000 -0500
25247 @@ -723,7 +723,7 @@ struct cardstate *gigaset_initcs(struct
25248 cs->commands_pending = 0;
25249 cs->cur_at_seq = 0;
25251 - cs->open_count = 0;
25252 + atomic_set(&cs->open_count, 0);
25255 cs->tty_dev = NULL;
25256 diff -urNp linux-2.6.37/drivers/isdn/gigaset/gigaset.h linux-2.6.37/drivers/isdn/gigaset/gigaset.h
25257 --- linux-2.6.37/drivers/isdn/gigaset/gigaset.h 2011-01-04 19:50:19.000000000 -0500
25258 +++ linux-2.6.37/drivers/isdn/gigaset/gigaset.h 2011-01-17 02:41:01.000000000 -0500
25259 @@ -433,7 +433,7 @@ struct cardstate {
25260 spinlock_t cmdlock;
25261 unsigned curlen, cmdbytes;
25263 - unsigned open_count;
25264 + atomic_t open_count;
25265 struct tty_struct *tty;
25266 struct tasklet_struct if_wake_tasklet;
25267 unsigned control_state;
25268 diff -urNp linux-2.6.37/drivers/isdn/gigaset/interface.c linux-2.6.37/drivers/isdn/gigaset/interface.c
25269 --- linux-2.6.37/drivers/isdn/gigaset/interface.c 2011-01-04 19:50:19.000000000 -0500
25270 +++ linux-2.6.37/drivers/isdn/gigaset/interface.c 2011-01-17 02:41:01.000000000 -0500
25271 @@ -160,9 +160,7 @@ static int if_open(struct tty_struct *tt
25272 return -ERESTARTSYS;
25273 tty->driver_data = cs;
25275 - ++cs->open_count;
25277 - if (cs->open_count == 1) {
25278 + if (atomic_inc_return(&cs->open_count) == 1) {
25279 spin_lock_irqsave(&cs->lock, flags);
25281 spin_unlock_irqrestore(&cs->lock, flags);
25282 @@ -190,10 +188,10 @@ static void if_close(struct tty_struct *
25284 if (!cs->connected)
25285 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
25286 - else if (!cs->open_count)
25287 + else if (!atomic_read(&cs->open_count))
25288 dev_warn(cs->dev, "%s: device not opened\n", __func__);
25290 - if (!--cs->open_count) {
25291 + if (!atomic_dec_return(&cs->open_count)) {
25292 spin_lock_irqsave(&cs->lock, flags);
25294 spin_unlock_irqrestore(&cs->lock, flags);
25295 @@ -228,7 +226,7 @@ static int if_ioctl(struct tty_struct *t
25296 if (!cs->connected) {
25297 gig_dbg(DEBUG_IF, "not connected");
25299 - } else if (!cs->open_count)
25300 + } else if (!atomic_read(&cs->open_count))
25301 dev_warn(cs->dev, "%s: device not opened\n", __func__);
25304 @@ -358,7 +356,7 @@ static int if_write(struct tty_struct *t
25308 - if (!cs->open_count) {
25309 + if (!atomic_read(&cs->open_count)) {
25310 dev_warn(cs->dev, "%s: device not opened\n", __func__);
25313 @@ -411,7 +409,7 @@ static int if_write_room(struct tty_stru
25314 if (!cs->connected) {
25315 gig_dbg(DEBUG_IF, "not connected");
25317 - } else if (!cs->open_count)
25318 + } else if (!atomic_read(&cs->open_count))
25319 dev_warn(cs->dev, "%s: device not opened\n", __func__);
25320 else if (cs->mstate != MS_LOCKED) {
25321 dev_warn(cs->dev, "can't write to unlocked device\n");
25322 @@ -441,7 +439,7 @@ static int if_chars_in_buffer(struct tty
25324 if (!cs->connected)
25325 gig_dbg(DEBUG_IF, "not connected");
25326 - else if (!cs->open_count)
25327 + else if (!atomic_read(&cs->open_count))
25328 dev_warn(cs->dev, "%s: device not opened\n", __func__);
25329 else if (cs->mstate != MS_LOCKED)
25330 dev_warn(cs->dev, "can't write to unlocked device\n");
25331 @@ -469,7 +467,7 @@ static void if_throttle(struct tty_struc
25333 if (!cs->connected)
25334 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
25335 - else if (!cs->open_count)
25336 + else if (!atomic_read(&cs->open_count))
25337 dev_warn(cs->dev, "%s: device not opened\n", __func__);
25339 gig_dbg(DEBUG_IF, "%s: not implemented\n", __func__);
25340 @@ -493,7 +491,7 @@ static void if_unthrottle(struct tty_str
25342 if (!cs->connected)
25343 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
25344 - else if (!cs->open_count)
25345 + else if (!atomic_read(&cs->open_count))
25346 dev_warn(cs->dev, "%s: device not opened\n", __func__);
25348 gig_dbg(DEBUG_IF, "%s: not implemented\n", __func__);
25349 @@ -524,7 +522,7 @@ static void if_set_termios(struct tty_st
25353 - if (!cs->open_count) {
25354 + if (!atomic_read(&cs->open_count)) {
25355 dev_warn(cs->dev, "%s: device not opened\n", __func__);
25358 diff -urNp linux-2.6.37/drivers/isdn/hardware/avm/b1.c linux-2.6.37/drivers/isdn/hardware/avm/b1.c
25359 --- linux-2.6.37/drivers/isdn/hardware/avm/b1.c 2011-01-04 19:50:19.000000000 -0500
25360 +++ linux-2.6.37/drivers/isdn/hardware/avm/b1.c 2011-01-17 02:41:01.000000000 -0500
25361 @@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capilo
25364 if (t4file->user) {
25365 - if (copy_from_user(buf, dp, left))
25366 + if (left > sizeof buf || copy_from_user(buf, dp, left))
25369 memcpy(buf, dp, left);
25370 @@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capilo
25373 if (config->user) {
25374 - if (copy_from_user(buf, dp, left))
25375 + if (left > sizeof buf || copy_from_user(buf, dp, left))
25378 memcpy(buf, dp, left);
25379 diff -urNp linux-2.6.37/drivers/isdn/icn/icn.c linux-2.6.37/drivers/isdn/icn/icn.c
25380 --- linux-2.6.37/drivers/isdn/icn/icn.c 2011-01-04 19:50:19.000000000 -0500
25381 +++ linux-2.6.37/drivers/isdn/icn/icn.c 2011-01-17 02:41:01.000000000 -0500
25382 @@ -1045,7 +1045,7 @@ icn_writecmd(const u_char * buf, int len
25386 - if (copy_from_user(msg, buf, count))
25387 + if (count > sizeof msg || copy_from_user(msg, buf, count))
25390 memcpy(msg, buf, count);
25391 diff -urNp linux-2.6.37/drivers/lguest/core.c linux-2.6.37/drivers/lguest/core.c
25392 --- linux-2.6.37/drivers/lguest/core.c 2011-01-04 19:50:19.000000000 -0500
25393 +++ linux-2.6.37/drivers/lguest/core.c 2011-01-17 02:41:01.000000000 -0500
25394 @@ -92,9 +92,17 @@ static __init int map_switcher(void)
25395 * it's worked so far. The end address needs +1 because __get_vm_area
25396 * allocates an extra guard page, so we need space for that.
25399 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
25400 + switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
25401 + VM_ALLOC | VM_KERNEXEC, SWITCHER_ADDR, SWITCHER_ADDR
25402 + + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
25404 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
25405 VM_ALLOC, SWITCHER_ADDR, SWITCHER_ADDR
25406 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
25409 if (!switcher_vma) {
25411 printk("lguest: could not map switcher pages high\n");
25412 @@ -119,7 +127,7 @@ static __init int map_switcher(void)
25413 * Now the Switcher is mapped at the right address, we can't fail!
25414 * Copy in the compiled-in Switcher code (from <arch>_switcher.S).
25416 - memcpy(switcher_vma->addr, start_switcher_text,
25417 + memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
25418 end_switcher_text - start_switcher_text);
25420 printk(KERN_INFO "lguest: mapped switcher at %p\n",
25421 diff -urNp linux-2.6.37/drivers/lguest/x86/core.c linux-2.6.37/drivers/lguest/x86/core.c
25422 --- linux-2.6.37/drivers/lguest/x86/core.c 2011-01-04 19:50:19.000000000 -0500
25423 +++ linux-2.6.37/drivers/lguest/x86/core.c 2011-01-17 02:41:01.000000000 -0500
25424 @@ -59,7 +59,7 @@ static struct {
25425 /* Offset from where switcher.S was compiled to where we've copied it */
25426 static unsigned long switcher_offset(void)
25428 - return SWITCHER_ADDR - (unsigned long)start_switcher_text;
25429 + return SWITCHER_ADDR - (unsigned long)ktla_ktva(start_switcher_text);
25432 /* This cpu's struct lguest_pages. */
25433 @@ -100,7 +100,13 @@ static void copy_in_guest_info(struct lg
25434 * These copies are pretty cheap, so we do them unconditionally: */
25435 /* Save the current Host top-level page directory.
25438 +#ifdef CONFIG_PAX_PER_CPU_PGD
25439 + pages->state.host_cr3 = read_cr3();
25441 pages->state.host_cr3 = __pa(current->mm->pgd);
25445 * Set up the Guest's page tables to see this CPU's pages (and no
25446 * other CPU's pages).
25447 @@ -547,7 +553,7 @@ void __init lguest_arch_host_init(void)
25448 * compiled-in switcher code and the high-mapped copy we just made.
25450 for (i = 0; i < IDT_ENTRIES; i++)
25451 - default_idt_entries[i] += switcher_offset();
25452 + default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
25455 * Set up the Switcher's per-cpu areas.
25456 @@ -630,7 +636,7 @@ void __init lguest_arch_host_init(void)
25457 * it will be undisturbed when we switch. To change %cs and jump we
25458 * need this structure to feed to Intel's "lcall" instruction.
25460 - lguest_entry.offset = (long)switch_to_guest + switcher_offset();
25461 + lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
25462 lguest_entry.segment = LGUEST_CS;
25465 diff -urNp linux-2.6.37/drivers/lguest/x86/switcher_32.S linux-2.6.37/drivers/lguest/x86/switcher_32.S
25466 --- linux-2.6.37/drivers/lguest/x86/switcher_32.S 2011-01-04 19:50:19.000000000 -0500
25467 +++ linux-2.6.37/drivers/lguest/x86/switcher_32.S 2011-01-17 02:41:01.000000000 -0500
25469 #include <asm/page.h>
25470 #include <asm/segment.h>
25471 #include <asm/lguest.h>
25472 +#include <asm/processor-flags.h>
25474 // We mark the start of the code to copy
25475 // It's placed in .text tho it's never run here
25476 @@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
25477 // Changes type when we load it: damn Intel!
25478 // For after we switch over our page tables
25479 // That entry will be read-only: we'd crash.
25481 +#ifdef CONFIG_PAX_KERNEXEC
25483 + xor $X86_CR0_WP, %edx
25487 movl $(GDT_ENTRY_TSS*8), %edx
25490 @@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
25491 // Let's clear it again for our return.
25492 // The GDT descriptor of the Host
25493 // Points to the table after two "size" bytes
25494 - movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
25495 + movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
25496 // Clear "used" from type field (byte 5, bit 2)
25497 - andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
25498 + andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
25500 +#ifdef CONFIG_PAX_KERNEXEC
25502 + xor $X86_CR0_WP, %eax
25506 // Once our page table's switched, the Guest is live!
25507 // The Host fades as we run this final step.
25508 @@ -295,13 +309,12 @@ deliver_to_host:
25509 // I consulted gcc, and it gave
25510 // These instructions, which I gladly credit:
25511 leal (%edx,%ebx,8), %eax
25512 - movzwl (%eax),%edx
25513 - movl 4(%eax), %eax
25516 + movl 4(%eax), %edx
25518 // Now the address of the handler's in %edx
25519 // We call it now: its "iret" drops us home.
25521 + ljmp $__KERNEL_CS, $1f
25524 // Every interrupt can come to us here
25525 // But we must truly tell each apart.
25526 diff -urNp linux-2.6.37/drivers/macintosh/via-pmu-backlight.c linux-2.6.37/drivers/macintosh/via-pmu-backlight.c
25527 --- linux-2.6.37/drivers/macintosh/via-pmu-backlight.c 2011-01-04 19:50:19.000000000 -0500
25528 +++ linux-2.6.37/drivers/macintosh/via-pmu-backlight.c 2011-01-17 02:41:01.000000000 -0500
25531 #define MAX_PMU_LEVEL 0xFF
25533 -static struct backlight_ops pmu_backlight_data;
25534 +static const struct backlight_ops pmu_backlight_data;
25535 static DEFINE_SPINLOCK(pmu_backlight_lock);
25536 static int sleeping, uses_pmu_bl;
25537 static u8 bl_curve[FB_BACKLIGHT_LEVELS];
25538 @@ -115,7 +115,7 @@ static int pmu_backlight_get_brightness(
25539 return bd->props.brightness;
25542 -static struct backlight_ops pmu_backlight_data = {
25543 +static const struct backlight_ops pmu_backlight_data = {
25544 .get_brightness = pmu_backlight_get_brightness,
25545 .update_status = pmu_backlight_update_status,
25547 diff -urNp linux-2.6.37/drivers/macintosh/via-pmu.c linux-2.6.37/drivers/macintosh/via-pmu.c
25548 --- linux-2.6.37/drivers/macintosh/via-pmu.c 2011-01-04 19:50:19.000000000 -0500
25549 +++ linux-2.6.37/drivers/macintosh/via-pmu.c 2011-01-17 02:41:01.000000000 -0500
25550 @@ -2257,7 +2257,7 @@ static int pmu_sleep_valid(suspend_state
25551 && (pmac_call_feature(PMAC_FTR_SLEEP_STATE, NULL, 0, -1) >= 0);
25554 -static struct platform_suspend_ops pmu_pm_ops = {
25555 +static const struct platform_suspend_ops pmu_pm_ops = {
25556 .enter = powerbook_sleep,
25557 .valid = pmu_sleep_valid,
25559 diff -urNp linux-2.6.37/drivers/md/bitmap.c linux-2.6.37/drivers/md/bitmap.c
25560 --- linux-2.6.37/drivers/md/bitmap.c 2011-01-04 19:50:19.000000000 -0500
25561 +++ linux-2.6.37/drivers/md/bitmap.c 2011-01-17 02:41:01.000000000 -0500
25564 # define PRINTK(x...) printk(KERN_DEBUG x)
25566 -# define PRINTK(x...)
25567 +# define PRINTK(x...) do {} while (0)
25571 diff -urNp linux-2.6.37/drivers/md/dm-table.c linux-2.6.37/drivers/md/dm-table.c
25572 --- linux-2.6.37/drivers/md/dm-table.c 2011-01-04 19:50:19.000000000 -0500
25573 +++ linux-2.6.37/drivers/md/dm-table.c 2011-01-17 02:41:01.000000000 -0500
25574 @@ -366,7 +366,7 @@ static int device_area_is_invalid(struct
25578 - if ((start >= dev_size) || (start + len > dev_size)) {
25579 + if ((start >= dev_size) || (len > dev_size - start)) {
25580 DMWARN("%s: %s too small for target: "
25581 "start=%llu, len=%llu, dev_size=%llu",
25582 dm_device_name(ti->table->md), bdevname(bdev, b),
25583 diff -urNp linux-2.6.37/drivers/md/md.c linux-2.6.37/drivers/md/md.c
25584 --- linux-2.6.37/drivers/md/md.c 2011-01-04 19:50:19.000000000 -0500
25585 +++ linux-2.6.37/drivers/md/md.c 2011-01-17 02:41:01.000000000 -0500
25586 @@ -1875,7 +1875,7 @@ static int bind_rdev_to_array(mdk_rdev_t
25588 ko = &part_to_dev(rdev->bdev->bd_part)->kobj;
25589 if (sysfs_create_link(&rdev->kobj, ko, "block"))
25590 - /* failure here is OK */;
25591 + /* failure here is OK */{}
25592 rdev->sysfs_state = sysfs_get_dirent_safe(rdev->kobj.sd, "state");
25594 list_add_rcu(&rdev->same_set, &mddev->disks);
25595 @@ -2487,7 +2487,7 @@ slot_store(mdk_rdev_t *rdev, const char
25596 sysfs_notify_dirent_safe(rdev->sysfs_state);
25597 sprintf(nm, "rd%d", rdev->raid_disk);
25598 if (sysfs_create_link(&rdev->mddev->kobj, &rdev->kobj, nm))
25599 - /* failure here is OK */;
25600 + /* failure here is OK */{}
25601 /* don't wakeup anyone, leave that to userspace. */
25603 if (slot >= rdev->mddev->raid_disks)
25604 @@ -4570,7 +4570,7 @@ int md_run(mddev_t *mddev)
25606 sprintf(nm, "rd%d", rdev->raid_disk);
25607 if (sysfs_create_link(&mddev->kobj, &rdev->kobj, nm))
25608 - /* failure here is OK */;
25609 + /* failure here is OK */{}
25612 set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
25613 @@ -6408,7 +6408,7 @@ static int md_seq_show(struct seq_file *
25614 chunk_kb ? "KB" : "B");
25615 if (bitmap->file) {
25616 seq_printf(seq, ", file: ");
25617 - seq_path(seq, &bitmap->file->f_path, " \t\n");
25618 + seq_path(seq, &bitmap->file->f_path, " \t\n\\");
25621 seq_printf(seq, "\n");
25622 @@ -6502,7 +6502,7 @@ static int is_mddev_idle(mddev_t *mddev,
25623 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
25624 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
25625 (int)part_stat_read(&disk->part0, sectors[1]) -
25626 - atomic_read(&disk->sync_io);
25627 + atomic_read_unchecked(&disk->sync_io);
25628 /* sync IO will cause sync_io to increase before the disk_stats
25629 * as sync_io is counted when a request starts, and
25630 * disk_stats is counted when it completes.
25631 @@ -7020,7 +7020,7 @@ static int remove_and_add_spares(mddev_t
25632 sprintf(nm, "rd%d", rdev->raid_disk);
25633 if (sysfs_create_link(&mddev->kobj,
25635 - /* failure here is OK */;
25636 + /* failure here is OK */{}
25638 md_new_event(mddev);
25639 set_bit(MD_CHANGE_DEVS, &mddev->flags);
25640 diff -urNp linux-2.6.37/drivers/md/md.h linux-2.6.37/drivers/md/md.h
25641 --- linux-2.6.37/drivers/md/md.h 2011-01-04 19:50:19.000000000 -0500
25642 +++ linux-2.6.37/drivers/md/md.h 2011-01-17 02:41:01.000000000 -0500
25643 @@ -353,7 +353,7 @@ static inline void rdev_dec_pending(mdk_
25645 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
25647 - atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
25648 + atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
25651 struct mdk_personality
25652 diff -urNp linux-2.6.37/drivers/media/dvb/dvb-core/dvbdev.c linux-2.6.37/drivers/media/dvb/dvb-core/dvbdev.c
25653 --- linux-2.6.37/drivers/media/dvb/dvb-core/dvbdev.c 2011-01-04 19:50:19.000000000 -0500
25654 +++ linux-2.6.37/drivers/media/dvb/dvb-core/dvbdev.c 2011-01-17 02:41:01.000000000 -0500
25655 @@ -192,6 +192,7 @@ int dvb_register_device(struct dvb_adapt
25656 const struct dvb_device *template, void *priv, int type)
25658 struct dvb_device *dvbdev;
25659 + /* cannot be const, see this function */
25660 struct file_operations *dvbdevfops;
25661 struct device *clsdev;
25663 diff -urNp linux-2.6.37/drivers/media/IR/ir-lirc-codec.c linux-2.6.37/drivers/media/IR/ir-lirc-codec.c
25664 --- linux-2.6.37/drivers/media/IR/ir-lirc-codec.c 2011-01-04 19:50:19.000000000 -0500
25665 +++ linux-2.6.37/drivers/media/IR/ir-lirc-codec.c 2011-01-17 02:41:01.000000000 -0500
25666 @@ -275,7 +275,7 @@ static void ir_lirc_close(void *data)
25670 -static struct file_operations lirc_fops = {
25671 +static const struct file_operations lirc_fops = {
25672 .owner = THIS_MODULE,
25673 .write = ir_lirc_transmit_ir,
25674 .unlocked_ioctl = ir_lirc_ioctl,
25675 diff -urNp linux-2.6.37/drivers/media/IR/lirc_dev.c linux-2.6.37/drivers/media/IR/lirc_dev.c
25676 --- linux-2.6.37/drivers/media/IR/lirc_dev.c 2011-01-04 19:50:19.000000000 -0500
25677 +++ linux-2.6.37/drivers/media/IR/lirc_dev.c 2011-01-17 02:41:01.000000000 -0500
25678 @@ -151,7 +151,7 @@ static int lirc_thread(void *irctl)
25682 -static struct file_operations lirc_dev_fops = {
25683 +static const struct file_operations lirc_dev_fops = {
25684 .owner = THIS_MODULE,
25685 .read = lirc_dev_fop_read,
25686 .write = lirc_dev_fop_write,
25687 diff -urNp linux-2.6.37/drivers/media/radio/radio-cadet.c linux-2.6.37/drivers/media/radio/radio-cadet.c
25688 --- linux-2.6.37/drivers/media/radio/radio-cadet.c 2011-01-04 19:50:19.000000000 -0500
25689 +++ linux-2.6.37/drivers/media/radio/radio-cadet.c 2011-01-17 02:41:01.000000000 -0500
25690 @@ -349,7 +349,7 @@ static ssize_t cadet_read(struct file *f
25691 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
25692 mutex_unlock(&dev->lock);
25694 - if (copy_to_user(data, readbuf, i))
25695 + if (i > sizeof readbuf || copy_to_user(data, readbuf, i))
25699 diff -urNp linux-2.6.37/drivers/media/video/saa7164/saa7164-core.c linux-2.6.37/drivers/media/video/saa7164/saa7164-core.c
25700 --- linux-2.6.37/drivers/media/video/saa7164/saa7164-core.c 2011-01-04 19:50:19.000000000 -0500
25701 +++ linux-2.6.37/drivers/media/video/saa7164/saa7164-core.c 2011-01-17 02:41:01.000000000 -0500
25702 @@ -1169,7 +1169,7 @@ static int saa7164_proc_open(struct inod
25703 return single_open(filp, saa7164_proc_show, NULL);
25706 -static struct file_operations saa7164_proc_fops = {
25707 +static const struct file_operations saa7164_proc_fops = {
25708 .open = saa7164_proc_open,
25710 .llseek = seq_lseek,
25711 diff -urNp linux-2.6.37/drivers/message/fusion/mptbase.c linux-2.6.37/drivers/message/fusion/mptbase.c
25712 --- linux-2.6.37/drivers/message/fusion/mptbase.c 2011-01-04 19:50:19.000000000 -0500
25713 +++ linux-2.6.37/drivers/message/fusion/mptbase.c 2011-01-17 02:41:01.000000000 -0500
25714 @@ -6683,8 +6683,13 @@ static int mpt_iocinfo_proc_show(struct
25715 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
25716 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
25718 +#ifdef CONFIG_GRKERNSEC_HIDESYM
25719 + seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
25721 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
25722 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
25726 * Rounding UP to nearest 4-kB boundary here...
25728 diff -urNp linux-2.6.37/drivers/message/fusion/mptdebug.h linux-2.6.37/drivers/message/fusion/mptdebug.h
25729 --- linux-2.6.37/drivers/message/fusion/mptdebug.h 2011-01-04 19:50:19.000000000 -0500
25730 +++ linux-2.6.37/drivers/message/fusion/mptdebug.h 2011-01-17 02:41:01.000000000 -0500
25735 -#define MPT_CHECK_LOGGING(IOC, CMD, BITS)
25736 +#define MPT_CHECK_LOGGING(IOC, CMD, BITS) do {} while (0)
25740 diff -urNp linux-2.6.37/drivers/message/fusion/mptsas.c linux-2.6.37/drivers/message/fusion/mptsas.c
25741 --- linux-2.6.37/drivers/message/fusion/mptsas.c 2011-01-04 19:50:19.000000000 -0500
25742 +++ linux-2.6.37/drivers/message/fusion/mptsas.c 2011-01-17 02:41:01.000000000 -0500
25743 @@ -439,6 +439,23 @@ mptsas_is_end_device(struct mptsas_devin
25747 +static inline void
25748 +mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
25750 + if (phy_info->port_details) {
25751 + phy_info->port_details->rphy = rphy;
25752 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
25753 + ioc->name, rphy));
25757 + dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
25758 + &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
25759 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
25760 + ioc->name, rphy, rphy->dev.release));
25766 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
25767 @@ -477,23 +494,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *p
25771 -static inline void
25772 -mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
25774 - if (phy_info->port_details) {
25775 - phy_info->port_details->rphy = rphy;
25776 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
25777 - ioc->name, rphy));
25781 - dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
25782 - &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
25783 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
25784 - ioc->name, rphy, rphy->dev.release));
25788 static inline struct sas_port *
25789 mptsas_get_port(struct mptsas_phyinfo *phy_info)
25791 diff -urNp linux-2.6.37/drivers/message/fusion/mptscsih.c linux-2.6.37/drivers/message/fusion/mptscsih.c
25792 --- linux-2.6.37/drivers/message/fusion/mptscsih.c 2011-01-04 19:50:19.000000000 -0500
25793 +++ linux-2.6.37/drivers/message/fusion/mptscsih.c 2011-01-17 02:41:01.000000000 -0500
25794 @@ -1268,15 +1268,16 @@ mptscsih_info(struct Scsi_Host *SChost)
25796 h = shost_priv(SChost);
25799 - if (h->info_kbuf == NULL)
25800 - if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
25801 - return h->info_kbuf;
25802 - h->info_kbuf[0] = '\0';
25806 - mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
25807 - h->info_kbuf[size-1] = '\0';
25809 + if (h->info_kbuf == NULL)
25810 + if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
25811 + return h->info_kbuf;
25812 + h->info_kbuf[0] = '\0';
25814 + mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
25815 + h->info_kbuf[size-1] = '\0';
25817 return h->info_kbuf;
25819 diff -urNp linux-2.6.37/drivers/message/i2o/i2o_proc.c linux-2.6.37/drivers/message/i2o/i2o_proc.c
25820 --- linux-2.6.37/drivers/message/i2o/i2o_proc.c 2011-01-04 19:50:19.000000000 -0500
25821 +++ linux-2.6.37/drivers/message/i2o/i2o_proc.c 2011-01-17 02:41:01.000000000 -0500
25822 @@ -255,13 +255,6 @@ static char *scsi_devices[] = {
25823 "Array Controller Device"
25826 -static char *chtostr(u8 * chars, int n)
25830 - return strncat(tmp, (char *)chars, n);
25833 static int i2o_report_query_status(struct seq_file *seq, int block_status,
25836 @@ -838,8 +831,7 @@ static int i2o_seq_show_ddm_table(struct
25838 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
25839 seq_printf(seq, "%-#8x", ddm_table.module_id);
25840 - seq_printf(seq, "%-29s",
25841 - chtostr(ddm_table.module_name_version, 28));
25842 + seq_printf(seq, "%-.28s", ddm_table.module_name_version);
25843 seq_printf(seq, "%9d ", ddm_table.data_size);
25844 seq_printf(seq, "%8d", ddm_table.code_size);
25846 @@ -940,8 +932,8 @@ static int i2o_seq_show_drivers_stored(s
25848 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
25849 seq_printf(seq, "%-#8x", dst->module_id);
25850 - seq_printf(seq, "%-29s", chtostr(dst->module_name_version, 28));
25851 - seq_printf(seq, "%-9s", chtostr(dst->date, 8));
25852 + seq_printf(seq, "%-.28s", dst->module_name_version);
25853 + seq_printf(seq, "%-.8s", dst->date);
25854 seq_printf(seq, "%8d ", dst->module_size);
25855 seq_printf(seq, "%8d ", dst->mpb_size);
25856 seq_printf(seq, "0x%04x", dst->module_flags);
25857 @@ -1272,14 +1264,10 @@ static int i2o_seq_show_dev_identity(str
25858 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
25859 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
25860 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
25861 - seq_printf(seq, "Vendor info : %s\n",
25862 - chtostr((u8 *) (work32 + 2), 16));
25863 - seq_printf(seq, "Product info : %s\n",
25864 - chtostr((u8 *) (work32 + 6), 16));
25865 - seq_printf(seq, "Description : %s\n",
25866 - chtostr((u8 *) (work32 + 10), 16));
25867 - seq_printf(seq, "Product rev. : %s\n",
25868 - chtostr((u8 *) (work32 + 14), 8));
25869 + seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
25870 + seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
25871 + seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
25872 + seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
25874 seq_printf(seq, "Serial number : ");
25875 print_serial_number(seq, (u8 *) (work32 + 16),
25876 @@ -1324,10 +1312,8 @@ static int i2o_seq_show_ddm_identity(str
25879 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
25880 - seq_printf(seq, "Module name : %s\n",
25881 - chtostr(result.module_name, 24));
25882 - seq_printf(seq, "Module revision : %s\n",
25883 - chtostr(result.module_rev, 8));
25884 + seq_printf(seq, "Module name : %.24s\n", result.module_name);
25885 + seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
25887 seq_printf(seq, "Serial number : ");
25888 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
25889 @@ -1358,14 +1344,10 @@ static int i2o_seq_show_uinfo(struct seq
25893 - seq_printf(seq, "Device name : %s\n",
25894 - chtostr(result.device_name, 64));
25895 - seq_printf(seq, "Service name : %s\n",
25896 - chtostr(result.service_name, 64));
25897 - seq_printf(seq, "Physical name : %s\n",
25898 - chtostr(result.physical_location, 64));
25899 - seq_printf(seq, "Instance number : %s\n",
25900 - chtostr(result.instance_number, 4));
25901 + seq_printf(seq, "Device name : %.64s\n", result.device_name);
25902 + seq_printf(seq, "Service name : %.64s\n", result.service_name);
25903 + seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
25904 + seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
25908 diff -urNp linux-2.6.37/drivers/mfd/janz-cmodio.c linux-2.6.37/drivers/mfd/janz-cmodio.c
25909 --- linux-2.6.37/drivers/mfd/janz-cmodio.c 2011-01-04 19:50:19.000000000 -0500
25910 +++ linux-2.6.37/drivers/mfd/janz-cmodio.c 2011-01-17 02:41:01.000000000 -0500
25913 #include <linux/kernel.h>
25914 #include <linux/module.h>
25915 +#include <linux/slab.h>
25916 #include <linux/init.h>
25917 #include <linux/pci.h>
25918 #include <linux/interrupt.h>
25919 diff -urNp linux-2.6.37/drivers/misc/kgdbts.c linux-2.6.37/drivers/misc/kgdbts.c
25920 --- linux-2.6.37/drivers/misc/kgdbts.c 2011-01-04 19:50:19.000000000 -0500
25921 +++ linux-2.6.37/drivers/misc/kgdbts.c 2011-01-17 02:41:01.000000000 -0500
25922 @@ -118,7 +118,7 @@
25924 #define MAX_CONFIG_LEN 40
25926 -static struct kgdb_io kgdbts_io_ops;
25927 +static const struct kgdb_io kgdbts_io_ops;
25928 static char get_buf[BUFMAX];
25929 static int get_buf_cnt;
25930 static char put_buf[BUFMAX];
25931 @@ -1103,7 +1103,7 @@ static void kgdbts_post_exp_handler(void
25932 module_put(THIS_MODULE);
25935 -static struct kgdb_io kgdbts_io_ops = {
25936 +static const struct kgdb_io kgdbts_io_ops = {
25938 .read_char = kgdbts_get_char,
25939 .write_char = kgdbts_put_char,
25940 diff -urNp linux-2.6.37/drivers/misc/sgi-gru/gruhandles.c linux-2.6.37/drivers/misc/sgi-gru/gruhandles.c
25941 --- linux-2.6.37/drivers/misc/sgi-gru/gruhandles.c 2011-01-04 19:50:19.000000000 -0500
25942 +++ linux-2.6.37/drivers/misc/sgi-gru/gruhandles.c 2011-01-17 02:41:01.000000000 -0500
25943 @@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op
25944 unsigned long nsec;
25946 nsec = CLKS2NSEC(clks);
25947 - atomic_long_inc(&mcs_op_statistics[op].count);
25948 - atomic_long_add(nsec, &mcs_op_statistics[op].total);
25949 + atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
25950 + atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
25951 if (mcs_op_statistics[op].max < nsec)
25952 mcs_op_statistics[op].max = nsec;
25954 diff -urNp linux-2.6.37/drivers/misc/sgi-gru/gruprocfs.c linux-2.6.37/drivers/misc/sgi-gru/gruprocfs.c
25955 --- linux-2.6.37/drivers/misc/sgi-gru/gruprocfs.c 2011-01-04 19:50:19.000000000 -0500
25956 +++ linux-2.6.37/drivers/misc/sgi-gru/gruprocfs.c 2011-01-17 02:41:01.000000000 -0500
25959 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
25961 -static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
25962 +static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
25964 - unsigned long val = atomic_long_read(v);
25965 + unsigned long val = atomic_long_read_unchecked(v);
25967 seq_printf(s, "%16lu %s\n", val, id);
25969 @@ -134,8 +134,8 @@ static int mcs_statistics_show(struct se
25971 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
25972 for (op = 0; op < mcsop_last; op++) {
25973 - count = atomic_long_read(&mcs_op_statistics[op].count);
25974 - total = atomic_long_read(&mcs_op_statistics[op].total);
25975 + count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
25976 + total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
25977 max = mcs_op_statistics[op].max;
25978 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
25979 count ? total / count : 0, max);
25980 diff -urNp linux-2.6.37/drivers/misc/sgi-gru/grutables.h linux-2.6.37/drivers/misc/sgi-gru/grutables.h
25981 --- linux-2.6.37/drivers/misc/sgi-gru/grutables.h 2011-01-04 19:50:19.000000000 -0500
25982 +++ linux-2.6.37/drivers/misc/sgi-gru/grutables.h 2011-01-17 02:41:01.000000000 -0500
25983 @@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
25986 struct gru_stats_s {
25987 - atomic_long_t vdata_alloc;
25988 - atomic_long_t vdata_free;
25989 - atomic_long_t gts_alloc;
25990 - atomic_long_t gts_free;
25991 - atomic_long_t gms_alloc;
25992 - atomic_long_t gms_free;
25993 - atomic_long_t gts_double_allocate;
25994 - atomic_long_t assign_context;
25995 - atomic_long_t assign_context_failed;
25996 - atomic_long_t free_context;
25997 - atomic_long_t load_user_context;
25998 - atomic_long_t load_kernel_context;
25999 - atomic_long_t lock_kernel_context;
26000 - atomic_long_t unlock_kernel_context;
26001 - atomic_long_t steal_user_context;
26002 - atomic_long_t steal_kernel_context;
26003 - atomic_long_t steal_context_failed;
26004 - atomic_long_t nopfn;
26005 - atomic_long_t asid_new;
26006 - atomic_long_t asid_next;
26007 - atomic_long_t asid_wrap;
26008 - atomic_long_t asid_reuse;
26009 - atomic_long_t intr;
26010 - atomic_long_t intr_cbr;
26011 - atomic_long_t intr_tfh;
26012 - atomic_long_t intr_spurious;
26013 - atomic_long_t intr_mm_lock_failed;
26014 - atomic_long_t call_os;
26015 - atomic_long_t call_os_wait_queue;
26016 - atomic_long_t user_flush_tlb;
26017 - atomic_long_t user_unload_context;
26018 - atomic_long_t user_exception;
26019 - atomic_long_t set_context_option;
26020 - atomic_long_t check_context_retarget_intr;
26021 - atomic_long_t check_context_unload;
26022 - atomic_long_t tlb_dropin;
26023 - atomic_long_t tlb_preload_page;
26024 - atomic_long_t tlb_dropin_fail_no_asid;
26025 - atomic_long_t tlb_dropin_fail_upm;
26026 - atomic_long_t tlb_dropin_fail_invalid;
26027 - atomic_long_t tlb_dropin_fail_range_active;
26028 - atomic_long_t tlb_dropin_fail_idle;
26029 - atomic_long_t tlb_dropin_fail_fmm;
26030 - atomic_long_t tlb_dropin_fail_no_exception;
26031 - atomic_long_t tfh_stale_on_fault;
26032 - atomic_long_t mmu_invalidate_range;
26033 - atomic_long_t mmu_invalidate_page;
26034 - atomic_long_t flush_tlb;
26035 - atomic_long_t flush_tlb_gru;
26036 - atomic_long_t flush_tlb_gru_tgh;
26037 - atomic_long_t flush_tlb_gru_zero_asid;
26039 - atomic_long_t copy_gpa;
26040 - atomic_long_t read_gpa;
26042 - atomic_long_t mesq_receive;
26043 - atomic_long_t mesq_receive_none;
26044 - atomic_long_t mesq_send;
26045 - atomic_long_t mesq_send_failed;
26046 - atomic_long_t mesq_noop;
26047 - atomic_long_t mesq_send_unexpected_error;
26048 - atomic_long_t mesq_send_lb_overflow;
26049 - atomic_long_t mesq_send_qlimit_reached;
26050 - atomic_long_t mesq_send_amo_nacked;
26051 - atomic_long_t mesq_send_put_nacked;
26052 - atomic_long_t mesq_page_overflow;
26053 - atomic_long_t mesq_qf_locked;
26054 - atomic_long_t mesq_qf_noop_not_full;
26055 - atomic_long_t mesq_qf_switch_head_failed;
26056 - atomic_long_t mesq_qf_unexpected_error;
26057 - atomic_long_t mesq_noop_unexpected_error;
26058 - atomic_long_t mesq_noop_lb_overflow;
26059 - atomic_long_t mesq_noop_qlimit_reached;
26060 - atomic_long_t mesq_noop_amo_nacked;
26061 - atomic_long_t mesq_noop_put_nacked;
26062 - atomic_long_t mesq_noop_page_overflow;
26063 + atomic_long_unchecked_t vdata_alloc;
26064 + atomic_long_unchecked_t vdata_free;
26065 + atomic_long_unchecked_t gts_alloc;
26066 + atomic_long_unchecked_t gts_free;
26067 + atomic_long_unchecked_t gms_alloc;
26068 + atomic_long_unchecked_t gms_free;
26069 + atomic_long_unchecked_t gts_double_allocate;
26070 + atomic_long_unchecked_t assign_context;
26071 + atomic_long_unchecked_t assign_context_failed;
26072 + atomic_long_unchecked_t free_context;
26073 + atomic_long_unchecked_t load_user_context;
26074 + atomic_long_unchecked_t load_kernel_context;
26075 + atomic_long_unchecked_t lock_kernel_context;
26076 + atomic_long_unchecked_t unlock_kernel_context;
26077 + atomic_long_unchecked_t steal_user_context;
26078 + atomic_long_unchecked_t steal_kernel_context;
26079 + atomic_long_unchecked_t steal_context_failed;
26080 + atomic_long_unchecked_t nopfn;
26081 + atomic_long_unchecked_t asid_new;
26082 + atomic_long_unchecked_t asid_next;
26083 + atomic_long_unchecked_t asid_wrap;
26084 + atomic_long_unchecked_t asid_reuse;
26085 + atomic_long_unchecked_t intr;
26086 + atomic_long_unchecked_t intr_cbr;
26087 + atomic_long_unchecked_t intr_tfh;
26088 + atomic_long_unchecked_t intr_spurious;
26089 + atomic_long_unchecked_t intr_mm_lock_failed;
26090 + atomic_long_unchecked_t call_os;
26091 + atomic_long_unchecked_t call_os_wait_queue;
26092 + atomic_long_unchecked_t user_flush_tlb;
26093 + atomic_long_unchecked_t user_unload_context;
26094 + atomic_long_unchecked_t user_exception;
26095 + atomic_long_unchecked_t set_context_option;
26096 + atomic_long_unchecked_t check_context_retarget_intr;
26097 + atomic_long_unchecked_t check_context_unload;
26098 + atomic_long_unchecked_t tlb_dropin;
26099 + atomic_long_unchecked_t tlb_preload_page;
26100 + atomic_long_unchecked_t tlb_dropin_fail_no_asid;
26101 + atomic_long_unchecked_t tlb_dropin_fail_upm;
26102 + atomic_long_unchecked_t tlb_dropin_fail_invalid;
26103 + atomic_long_unchecked_t tlb_dropin_fail_range_active;
26104 + atomic_long_unchecked_t tlb_dropin_fail_idle;
26105 + atomic_long_unchecked_t tlb_dropin_fail_fmm;
26106 + atomic_long_unchecked_t tlb_dropin_fail_no_exception;
26107 + atomic_long_unchecked_t tfh_stale_on_fault;
26108 + atomic_long_unchecked_t mmu_invalidate_range;
26109 + atomic_long_unchecked_t mmu_invalidate_page;
26110 + atomic_long_unchecked_t flush_tlb;
26111 + atomic_long_unchecked_t flush_tlb_gru;
26112 + atomic_long_unchecked_t flush_tlb_gru_tgh;
26113 + atomic_long_unchecked_t flush_tlb_gru_zero_asid;
26115 + atomic_long_unchecked_t copy_gpa;
26116 + atomic_long_unchecked_t read_gpa;
26118 + atomic_long_unchecked_t mesq_receive;
26119 + atomic_long_unchecked_t mesq_receive_none;
26120 + atomic_long_unchecked_t mesq_send;
26121 + atomic_long_unchecked_t mesq_send_failed;
26122 + atomic_long_unchecked_t mesq_noop;
26123 + atomic_long_unchecked_t mesq_send_unexpected_error;
26124 + atomic_long_unchecked_t mesq_send_lb_overflow;
26125 + atomic_long_unchecked_t mesq_send_qlimit_reached;
26126 + atomic_long_unchecked_t mesq_send_amo_nacked;
26127 + atomic_long_unchecked_t mesq_send_put_nacked;
26128 + atomic_long_unchecked_t mesq_page_overflow;
26129 + atomic_long_unchecked_t mesq_qf_locked;
26130 + atomic_long_unchecked_t mesq_qf_noop_not_full;
26131 + atomic_long_unchecked_t mesq_qf_switch_head_failed;
26132 + atomic_long_unchecked_t mesq_qf_unexpected_error;
26133 + atomic_long_unchecked_t mesq_noop_unexpected_error;
26134 + atomic_long_unchecked_t mesq_noop_lb_overflow;
26135 + atomic_long_unchecked_t mesq_noop_qlimit_reached;
26136 + atomic_long_unchecked_t mesq_noop_amo_nacked;
26137 + atomic_long_unchecked_t mesq_noop_put_nacked;
26138 + atomic_long_unchecked_t mesq_noop_page_overflow;
26142 @@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start
26143 tghop_invalidate, mcsop_last};
26145 struct mcs_op_statistic {
26146 - atomic_long_t count;
26147 - atomic_long_t total;
26148 + atomic_long_unchecked_t count;
26149 + atomic_long_unchecked_t total;
26153 @@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_st
26155 #define STAT(id) do { \
26156 if (gru_options & OPT_STATS) \
26157 - atomic_long_inc(&gru_stats.id); \
26158 + atomic_long_inc_unchecked(&gru_stats.id); \
26161 #ifdef CONFIG_SGI_GRU_DEBUG
26162 diff -urNp linux-2.6.37/drivers/mtd/devices/doc2000.c linux-2.6.37/drivers/mtd/devices/doc2000.c
26163 --- linux-2.6.37/drivers/mtd/devices/doc2000.c 2011-01-04 19:50:19.000000000 -0500
26164 +++ linux-2.6.37/drivers/mtd/devices/doc2000.c 2011-01-17 02:41:01.000000000 -0500
26165 @@ -776,7 +776,7 @@ static int doc_write(struct mtd_info *mt
26167 /* The ECC will not be calculated correctly if less than 512 is written */
26169 - if (len != 0x200 && eccbuf)
26170 + if (len != 0x200)
26171 printk(KERN_WARNING
26172 "ECC needs a full sector write (adr: %lx size %lx)\n",
26173 (long) to, (long) len);
26174 diff -urNp linux-2.6.37/drivers/mtd/devices/doc2001.c linux-2.6.37/drivers/mtd/devices/doc2001.c
26175 --- linux-2.6.37/drivers/mtd/devices/doc2001.c 2011-01-04 19:50:19.000000000 -0500
26176 +++ linux-2.6.37/drivers/mtd/devices/doc2001.c 2011-01-17 02:41:01.000000000 -0500
26177 @@ -393,7 +393,7 @@ static int doc_read (struct mtd_info *mt
26178 struct Nand *mychip = &this->chips[from >> (this->chipshift)];
26180 /* Don't allow read past end of device */
26181 - if (from >= this->totlen)
26182 + if (from >= this->totlen || !len)
26185 /* Don't allow a single read to cross a 512-byte block boundary */
26186 diff -urNp linux-2.6.37/drivers/mtd/nand/denali.c linux-2.6.37/drivers/mtd/nand/denali.c
26187 --- linux-2.6.37/drivers/mtd/nand/denali.c 2011-01-04 19:50:19.000000000 -0500
26188 +++ linux-2.6.37/drivers/mtd/nand/denali.c 2011-01-17 02:41:01.000000000 -0500
26190 #include <linux/pci.h>
26191 #include <linux/mtd/mtd.h>
26192 #include <linux/module.h>
26193 +#include <linux/slab.h>
26195 #include "denali.h"
26197 diff -urNp linux-2.6.37/drivers/mtd/ubi/build.c linux-2.6.37/drivers/mtd/ubi/build.c
26198 --- linux-2.6.37/drivers/mtd/ubi/build.c 2011-01-04 19:50:19.000000000 -0500
26199 +++ linux-2.6.37/drivers/mtd/ubi/build.c 2011-01-17 02:41:01.000000000 -0500
26200 @@ -1285,7 +1285,7 @@ module_exit(ubi_exit);
26201 static int __init bytes_str_to_int(const char *str)
26204 - unsigned long result;
26205 + unsigned long result, scale = 1;
26207 result = simple_strtoul(str, &endp, 0);
26208 if (str == endp || result >= INT_MAX) {
26209 @@ -1296,11 +1296,11 @@ static int __init bytes_str_to_int(const
26221 if (endp[1] == 'i' && endp[2] == 'B')
26224 @@ -1311,7 +1311,13 @@ static int __init bytes_str_to_int(const
26229 + if ((intoverflow_t)result*scale >= INT_MAX) {
26230 + printk(KERN_ERR "UBI error: incorrect bytes count: \"%s\"\n",
26235 + return result*scale;
26239 diff -urNp linux-2.6.37/drivers/net/e1000e/82571.c linux-2.6.37/drivers/net/e1000e/82571.c
26240 --- linux-2.6.37/drivers/net/e1000e/82571.c 2011-01-04 19:50:19.000000000 -0500
26241 +++ linux-2.6.37/drivers/net/e1000e/82571.c 2011-01-17 02:41:01.000000000 -0500
26242 @@ -211,6 +211,7 @@ static s32 e1000_init_mac_params_82571(s
26244 struct e1000_hw *hw = &adapter->hw;
26245 struct e1000_mac_info *mac = &hw->mac;
26246 + /* cannot be const */
26247 struct e1000_mac_operations *func = &mac->ops;
26250 @@ -1740,7 +1741,7 @@ static void e1000_clear_hw_cntrs_82571(s
26254 -static struct e1000_mac_operations e82571_mac_ops = {
26255 +static const struct e1000_mac_operations e82571_mac_ops = {
26256 /* .check_mng_mode: mac type dependent */
26257 /* .check_for_link: media type dependent */
26258 .id_led_init = e1000e_id_led_init,
26259 @@ -1762,7 +1763,7 @@ static struct e1000_mac_operations e8257
26260 .read_mac_addr = e1000_read_mac_addr_82571,
26263 -static struct e1000_phy_operations e82_phy_ops_igp = {
26264 +static const struct e1000_phy_operations e82_phy_ops_igp = {
26265 .acquire = e1000_get_hw_semaphore_82571,
26266 .check_polarity = e1000_check_polarity_igp,
26267 .check_reset_block = e1000e_check_reset_block_generic,
26268 @@ -1780,7 +1781,7 @@ static struct e1000_phy_operations e82_p
26269 .cfg_on_link_up = NULL,
26272 -static struct e1000_phy_operations e82_phy_ops_m88 = {
26273 +static const struct e1000_phy_operations e82_phy_ops_m88 = {
26274 .acquire = e1000_get_hw_semaphore_82571,
26275 .check_polarity = e1000_check_polarity_m88,
26276 .check_reset_block = e1000e_check_reset_block_generic,
26277 @@ -1798,7 +1799,7 @@ static struct e1000_phy_operations e82_p
26278 .cfg_on_link_up = NULL,
26281 -static struct e1000_phy_operations e82_phy_ops_bm = {
26282 +static const struct e1000_phy_operations e82_phy_ops_bm = {
26283 .acquire = e1000_get_hw_semaphore_82571,
26284 .check_polarity = e1000_check_polarity_m88,
26285 .check_reset_block = e1000e_check_reset_block_generic,
26286 @@ -1816,7 +1817,7 @@ static struct e1000_phy_operations e82_p
26287 .cfg_on_link_up = NULL,
26290 -static struct e1000_nvm_operations e82571_nvm_ops = {
26291 +static const struct e1000_nvm_operations e82571_nvm_ops = {
26292 .acquire = e1000_acquire_nvm_82571,
26293 .read = e1000e_read_nvm_eerd,
26294 .release = e1000_release_nvm_82571,
26295 diff -urNp linux-2.6.37/drivers/net/e1000e/e1000.h linux-2.6.37/drivers/net/e1000e/e1000.h
26296 --- linux-2.6.37/drivers/net/e1000e/e1000.h 2011-01-04 19:50:19.000000000 -0500
26297 +++ linux-2.6.37/drivers/net/e1000e/e1000.h 2011-01-17 02:41:01.000000000 -0500
26298 @@ -407,9 +407,9 @@ struct e1000_info {
26300 u32 max_hw_frame_size;
26301 s32 (*get_variants)(struct e1000_adapter *);
26302 - struct e1000_mac_operations *mac_ops;
26303 - struct e1000_phy_operations *phy_ops;
26304 - struct e1000_nvm_operations *nvm_ops;
26305 + const struct e1000_mac_operations *mac_ops;
26306 + const struct e1000_phy_operations *phy_ops;
26307 + const struct e1000_nvm_operations *nvm_ops;
26310 /* hardware capability, feature, and workaround flags */
26311 diff -urNp linux-2.6.37/drivers/net/e1000e/es2lan.c linux-2.6.37/drivers/net/e1000e/es2lan.c
26312 --- linux-2.6.37/drivers/net/e1000e/es2lan.c 2011-01-04 19:50:19.000000000 -0500
26313 +++ linux-2.6.37/drivers/net/e1000e/es2lan.c 2011-01-17 02:41:01.000000000 -0500
26314 @@ -205,6 +205,7 @@ static s32 e1000_init_mac_params_80003es
26316 struct e1000_hw *hw = &adapter->hw;
26317 struct e1000_mac_info *mac = &hw->mac;
26318 + /* cannot be const */
26319 struct e1000_mac_operations *func = &mac->ops;
26321 /* Set media type */
26322 @@ -1431,7 +1432,7 @@ static void e1000_clear_hw_cntrs_80003es
26326 -static struct e1000_mac_operations es2_mac_ops = {
26327 +static const struct e1000_mac_operations es2_mac_ops = {
26328 .read_mac_addr = e1000_read_mac_addr_80003es2lan,
26329 .id_led_init = e1000e_id_led_init,
26330 .check_mng_mode = e1000e_check_mng_mode_generic,
26331 @@ -1453,7 +1454,7 @@ static struct e1000_mac_operations es2_m
26332 .setup_led = e1000e_setup_led_generic,
26335 -static struct e1000_phy_operations es2_phy_ops = {
26336 +static const struct e1000_phy_operations es2_phy_ops = {
26337 .acquire = e1000_acquire_phy_80003es2lan,
26338 .check_polarity = e1000_check_polarity_m88,
26339 .check_reset_block = e1000e_check_reset_block_generic,
26340 @@ -1471,7 +1472,7 @@ static struct e1000_phy_operations es2_p
26341 .cfg_on_link_up = e1000_cfg_on_link_up_80003es2lan,
26344 -static struct e1000_nvm_operations es2_nvm_ops = {
26345 +static const struct e1000_nvm_operations es2_nvm_ops = {
26346 .acquire = e1000_acquire_nvm_80003es2lan,
26347 .read = e1000e_read_nvm_eerd,
26348 .release = e1000_release_nvm_80003es2lan,
26349 diff -urNp linux-2.6.37/drivers/net/e1000e/hw.h linux-2.6.37/drivers/net/e1000e/hw.h
26350 --- linux-2.6.37/drivers/net/e1000e/hw.h 2011-01-04 19:50:19.000000000 -0500
26351 +++ linux-2.6.37/drivers/net/e1000e/hw.h 2011-01-17 02:41:01.000000000 -0500
26352 @@ -800,16 +800,17 @@ struct e1000_phy_operations {
26354 /* Function pointers for the NVM. */
26355 struct e1000_nvm_operations {
26356 - s32 (*acquire)(struct e1000_hw *);
26357 - s32 (*read)(struct e1000_hw *, u16, u16, u16 *);
26358 - void (*release)(struct e1000_hw *);
26359 - s32 (*update)(struct e1000_hw *);
26360 - s32 (*valid_led_default)(struct e1000_hw *, u16 *);
26361 - s32 (*validate)(struct e1000_hw *);
26362 - s32 (*write)(struct e1000_hw *, u16, u16, u16 *);
26363 + s32 (* const acquire)(struct e1000_hw *);
26364 + s32 (* const read)(struct e1000_hw *, u16, u16, u16 *);
26365 + void (* const release)(struct e1000_hw *);
26366 + s32 (* const update)(struct e1000_hw *);
26367 + s32 (* const valid_led_default)(struct e1000_hw *, u16 *);
26368 + s32 (* const validate)(struct e1000_hw *);
26369 + s32 (* const write)(struct e1000_hw *, u16, u16, u16 *);
26372 struct e1000_mac_info {
26373 + /* cannot be const see e1000_init_mac_params_ich8lan */
26374 struct e1000_mac_operations ops;
26377 @@ -852,6 +853,7 @@ struct e1000_mac_info {
26380 struct e1000_phy_info {
26381 + /* Cannot be const see e1000_init_phy_params_82571() */
26382 struct e1000_phy_operations ops;
26384 enum e1000_phy_type type;
26385 @@ -886,6 +888,7 @@ struct e1000_phy_info {
26388 struct e1000_nvm_info {
26389 + /* cannot be const */
26390 struct e1000_nvm_operations ops;
26392 enum e1000_nvm_type type;
26393 diff -urNp linux-2.6.37/drivers/net/e1000e/ich8lan.c linux-2.6.37/drivers/net/e1000e/ich8lan.c
26394 --- linux-2.6.37/drivers/net/e1000e/ich8lan.c 2011-01-04 19:50:19.000000000 -0500
26395 +++ linux-2.6.37/drivers/net/e1000e/ich8lan.c 2011-01-17 02:41:01.000000000 -0500
26396 @@ -3856,7 +3856,7 @@ static void e1000_clear_hw_cntrs_ich8lan
26400 -static struct e1000_mac_operations ich8_mac_ops = {
26401 +static const struct e1000_mac_operations ich8_mac_ops = {
26402 .id_led_init = e1000e_id_led_init,
26403 /* check_mng_mode dependent on mac type */
26404 .check_for_link = e1000_check_for_copper_link_ich8lan,
26405 @@ -3875,7 +3875,7 @@ static struct e1000_mac_operations ich8_
26406 /* id_led_init dependent on mac type */
26409 -static struct e1000_phy_operations ich8_phy_ops = {
26410 +static const struct e1000_phy_operations ich8_phy_ops = {
26411 .acquire = e1000_acquire_swflag_ich8lan,
26412 .check_reset_block = e1000_check_reset_block_ich8lan,
26414 @@ -3889,7 +3889,7 @@ static struct e1000_phy_operations ich8_
26415 .write_reg = e1000e_write_phy_reg_igp,
26418 -static struct e1000_nvm_operations ich8_nvm_ops = {
26419 +static const struct e1000_nvm_operations ich8_nvm_ops = {
26420 .acquire = e1000_acquire_nvm_ich8lan,
26421 .read = e1000_read_nvm_ich8lan,
26422 .release = e1000_release_nvm_ich8lan,
26423 diff -urNp linux-2.6.37/drivers/net/igb/e1000_82575.c linux-2.6.37/drivers/net/igb/e1000_82575.c
26424 --- linux-2.6.37/drivers/net/igb/e1000_82575.c 2011-01-04 19:50:19.000000000 -0500
26425 +++ linux-2.6.37/drivers/net/igb/e1000_82575.c 2011-01-17 02:41:01.000000000 -0500
26426 @@ -1712,7 +1712,7 @@ u16 igb_rxpbs_adjust_82580(u32 data)
26430 -static struct e1000_mac_operations e1000_mac_ops_82575 = {
26431 +static const struct e1000_mac_operations e1000_mac_ops_82575 = {
26432 .init_hw = igb_init_hw_82575,
26433 .check_for_link = igb_check_for_link_82575,
26434 .rar_set = igb_rar_set,
26435 @@ -1720,13 +1720,13 @@ static struct e1000_mac_operations e1000
26436 .get_speed_and_duplex = igb_get_speed_and_duplex_copper,
26439 -static struct e1000_phy_operations e1000_phy_ops_82575 = {
26440 +static const struct e1000_phy_operations e1000_phy_ops_82575 = {
26441 .acquire = igb_acquire_phy_82575,
26442 .get_cfg_done = igb_get_cfg_done_82575,
26443 .release = igb_release_phy_82575,
26446 -static struct e1000_nvm_operations e1000_nvm_ops_82575 = {
26447 +static const struct e1000_nvm_operations e1000_nvm_ops_82575 = {
26448 .acquire = igb_acquire_nvm_82575,
26449 .read = igb_read_nvm_eerd,
26450 .release = igb_release_nvm_82575,
26451 diff -urNp linux-2.6.37/drivers/net/igb/e1000_hw.h linux-2.6.37/drivers/net/igb/e1000_hw.h
26452 --- linux-2.6.37/drivers/net/igb/e1000_hw.h 2011-01-04 19:50:19.000000000 -0500
26453 +++ linux-2.6.37/drivers/net/igb/e1000_hw.h 2011-01-17 02:41:01.000000000 -0500
26454 @@ -325,22 +325,23 @@ struct e1000_phy_operations {
26457 struct e1000_nvm_operations {
26458 - s32 (*acquire)(struct e1000_hw *);
26459 - s32 (*read)(struct e1000_hw *, u16, u16, u16 *);
26460 - void (*release)(struct e1000_hw *);
26461 - s32 (*write)(struct e1000_hw *, u16, u16, u16 *);
26462 + s32 (* const acquire)(struct e1000_hw *);
26463 + s32 (* const read)(struct e1000_hw *, u16, u16, u16 *);
26464 + void (* const release)(struct e1000_hw *);
26465 + s32 (* const write)(struct e1000_hw *, u16, u16, u16 *);
26468 struct e1000_info {
26469 s32 (*get_invariants)(struct e1000_hw *);
26470 - struct e1000_mac_operations *mac_ops;
26471 - struct e1000_phy_operations *phy_ops;
26472 - struct e1000_nvm_operations *nvm_ops;
26473 + const struct e1000_mac_operations *mac_ops;
26474 + const struct e1000_phy_operations *phy_ops;
26475 + const struct e1000_nvm_operations *nvm_ops;
26478 extern const struct e1000_info e1000_82575_info;
26480 struct e1000_mac_info {
26481 + /* cannot be const see igb_get_invariants_82575() */
26482 struct e1000_mac_operations ops;
26485 @@ -379,6 +380,7 @@ struct e1000_mac_info {
26488 struct e1000_phy_info {
26489 + /* cannot be const see igb_get_invariants_82575() */
26490 struct e1000_phy_operations ops;
26492 enum e1000_phy_type type;
26493 @@ -414,6 +416,7 @@ struct e1000_phy_info {
26496 struct e1000_nvm_info {
26497 + /* cannot be const */
26498 struct e1000_nvm_operations ops;
26500 enum e1000_nvm_type type;
26501 diff -urNp linux-2.6.37/drivers/net/igbvf/vf.h linux-2.6.37/drivers/net/igbvf/vf.h
26502 --- linux-2.6.37/drivers/net/igbvf/vf.h 2011-01-04 19:50:19.000000000 -0500
26503 +++ linux-2.6.37/drivers/net/igbvf/vf.h 2011-01-17 02:41:01.000000000 -0500
26504 @@ -189,6 +189,7 @@ struct e1000_mac_operations {
26507 struct e1000_mac_info {
26508 + /* cannot be const see e1000_init_mac_params_vf() */
26509 struct e1000_mac_operations ops;
26512 diff -urNp linux-2.6.37/drivers/net/irda/vlsi_ir.c linux-2.6.37/drivers/net/irda/vlsi_ir.c
26513 --- linux-2.6.37/drivers/net/irda/vlsi_ir.c 2011-01-04 19:50:19.000000000 -0500
26514 +++ linux-2.6.37/drivers/net/irda/vlsi_ir.c 2011-01-17 02:41:01.000000000 -0500
26515 @@ -907,13 +907,12 @@ static netdev_tx_t vlsi_hard_start_xmit(
26516 /* no race - tx-ring already empty */
26517 vlsi_set_baud(idev, iobase);
26518 netif_wake_queue(ndev);
26523 /* keep the speed change pending like it would
26524 * for any len>0 packet. tx completion interrupt
26525 * will apply it when the tx ring becomes empty.
26528 spin_unlock_irqrestore(&idev->lock, flags);
26529 dev_kfree_skb_any(skb);
26530 return NETDEV_TX_OK;
26531 diff -urNp linux-2.6.37/drivers/net/macvtap.c linux-2.6.37/drivers/net/macvtap.c
26532 --- linux-2.6.37/drivers/net/macvtap.c 2011-01-04 19:50:19.000000000 -0500
26533 +++ linux-2.6.37/drivers/net/macvtap.c 2011-01-17 02:41:01.000000000 -0500
26534 @@ -529,8 +529,9 @@ static ssize_t macvtap_get_user(struct m
26535 vnet_hdr_len = q->vnet_hdr_sz;
26538 - if ((len -= vnet_hdr_len) < 0)
26539 + if (len < vnet_hdr_len)
26541 + len -= vnet_hdr_len;
26543 err = memcpy_fromiovecend((void *)&vnet_hdr, iv, 0,
26545 diff -urNp linux-2.6.37/drivers/net/pcnet32.c linux-2.6.37/drivers/net/pcnet32.c
26546 --- linux-2.6.37/drivers/net/pcnet32.c 2011-01-04 19:50:19.000000000 -0500
26547 +++ linux-2.6.37/drivers/net/pcnet32.c 2011-01-17 02:41:01.000000000 -0500
26548 @@ -82,7 +82,7 @@ static int cards_found;
26550 * VLB I/O addresses
26552 -static unsigned int pcnet32_portlist[] __initdata =
26553 +static unsigned int pcnet32_portlist[] __devinitdata =
26554 { 0x300, 0x320, 0x340, 0x360, 0 };
26556 static int pcnet32_debug;
26557 diff -urNp linux-2.6.37/drivers/net/ppp_generic.c linux-2.6.37/drivers/net/ppp_generic.c
26558 --- linux-2.6.37/drivers/net/ppp_generic.c 2011-01-04 19:50:19.000000000 -0500
26559 +++ linux-2.6.37/drivers/net/ppp_generic.c 2011-01-17 02:41:01.000000000 -0500
26560 @@ -986,7 +986,6 @@ ppp_net_ioctl(struct net_device *dev, st
26561 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
26562 struct ppp_stats stats;
26563 struct ppp_comp_stats cstats;
26567 case SIOCGPPPSTATS:
26568 @@ -1008,8 +1007,7 @@ ppp_net_ioctl(struct net_device *dev, st
26572 - vers = PPP_VERSION;
26573 - if (copy_to_user(addr, vers, strlen(vers) + 1))
26574 + if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
26578 diff -urNp linux-2.6.37/drivers/net/tg3.h linux-2.6.37/drivers/net/tg3.h
26579 --- linux-2.6.37/drivers/net/tg3.h 2011-01-04 19:50:19.000000000 -0500
26580 +++ linux-2.6.37/drivers/net/tg3.h 2011-01-17 02:41:01.000000000 -0500
26581 @@ -131,6 +131,7 @@
26582 #define CHIPREV_ID_5750_A0 0x4000
26583 #define CHIPREV_ID_5750_A1 0x4001
26584 #define CHIPREV_ID_5750_A3 0x4003
26585 +#define CHIPREV_ID_5750_C1 0x4201
26586 #define CHIPREV_ID_5750_C2 0x4202
26587 #define CHIPREV_ID_5752_A0_HW 0x5000
26588 #define CHIPREV_ID_5752_A0 0x6000
26589 diff -urNp linux-2.6.37/drivers/net/tulip/de4x5.c linux-2.6.37/drivers/net/tulip/de4x5.c
26590 --- linux-2.6.37/drivers/net/tulip/de4x5.c 2011-01-04 19:50:19.000000000 -0500
26591 +++ linux-2.6.37/drivers/net/tulip/de4x5.c 2011-01-17 02:41:01.000000000 -0500
26592 @@ -5401,7 +5401,7 @@ de4x5_ioctl(struct net_device *dev, stru
26593 for (i=0; i<ETH_ALEN; i++) {
26594 tmp.addr[i] = dev->dev_addr[i];
26596 - if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
26597 + if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
26600 case DE4X5_SET_HWADDR: /* Set the hardware address */
26601 @@ -5441,7 +5441,7 @@ de4x5_ioctl(struct net_device *dev, stru
26602 spin_lock_irqsave(&lp->lock, flags);
26603 memcpy(&statbuf, &lp->pktStats, ioc->len);
26604 spin_unlock_irqrestore(&lp->lock, flags);
26605 - if (copy_to_user(ioc->data, &statbuf, ioc->len))
26606 + if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
26610 diff -urNp linux-2.6.37/drivers/net/usb/hso.c linux-2.6.37/drivers/net/usb/hso.c
26611 --- linux-2.6.37/drivers/net/usb/hso.c 2011-01-04 19:50:19.000000000 -0500
26612 +++ linux-2.6.37/drivers/net/usb/hso.c 2011-01-17 02:41:01.000000000 -0500
26613 @@ -257,7 +257,7 @@ struct hso_serial {
26615 /* from usb_serial_port */
26616 struct tty_struct *tty;
26618 + atomic_t open_count;
26619 spinlock_t serial_lock;
26621 int (*write_data) (struct hso_serial *serial);
26622 @@ -1187,7 +1187,7 @@ static void put_rxbuf_data_and_resubmit_
26625 urb = serial->rx_urb[0];
26626 - if (serial->open_count > 0) {
26627 + if (atomic_read(&serial->open_count) > 0) {
26628 count = put_rxbuf_data(urb, serial);
26631 @@ -1223,7 +1223,7 @@ static void hso_std_serial_read_bulk_cal
26632 DUMP1(urb->transfer_buffer, urb->actual_length);
26634 /* Anyone listening? */
26635 - if (serial->open_count == 0)
26636 + if (atomic_read(&serial->open_count) == 0)
26640 @@ -1318,8 +1318,7 @@ static int hso_serial_open(struct tty_st
26641 spin_unlock_irq(&serial->serial_lock);
26643 /* check for port already opened, if not set the termios */
26644 - serial->open_count++;
26645 - if (serial->open_count == 1) {
26646 + if (atomic_inc_return(&serial->open_count) == 1) {
26647 serial->rx_state = RX_IDLE;
26648 /* Force default termio settings */
26649 _hso_serial_set_termios(tty, NULL);
26650 @@ -1331,7 +1330,7 @@ static int hso_serial_open(struct tty_st
26651 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
26653 hso_stop_serial_device(serial->parent);
26654 - serial->open_count--;
26655 + atomic_dec(&serial->open_count);
26656 kref_put(&serial->parent->ref, hso_serial_ref_free);
26659 @@ -1368,10 +1367,10 @@ static void hso_serial_close(struct tty_
26661 /* reset the rts and dtr */
26662 /* do the actual close */
26663 - serial->open_count--;
26664 + atomic_dec(&serial->open_count);
26666 - if (serial->open_count <= 0) {
26667 - serial->open_count = 0;
26668 + if (atomic_read(&serial->open_count) <= 0) {
26669 + atomic_set(&serial->open_count, 0);
26670 spin_lock_irq(&serial->serial_lock);
26671 if (serial->tty == tty) {
26672 serial->tty->driver_data = NULL;
26673 @@ -1453,7 +1452,7 @@ static void hso_serial_set_termios(struc
26675 /* the actual setup */
26676 spin_lock_irqsave(&serial->serial_lock, flags);
26677 - if (serial->open_count)
26678 + if (atomic_read(&serial->open_count))
26679 _hso_serial_set_termios(tty, old);
26681 tty->termios = old;
26682 @@ -1913,7 +1912,7 @@ static void intr_callback(struct urb *ur
26683 D1("Pending read interrupt on port %d\n", i);
26684 spin_lock(&serial->serial_lock);
26685 if (serial->rx_state == RX_IDLE &&
26686 - serial->open_count > 0) {
26687 + atomic_read(&serial->open_count) > 0) {
26688 /* Setup and send a ctrl req read on
26690 if (!serial->rx_urb_filled[0]) {
26691 @@ -3105,7 +3104,7 @@ static int hso_resume(struct usb_interfa
26692 /* Start all serial ports */
26693 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
26694 if (serial_table[i] && (serial_table[i]->interface == iface)) {
26695 - if (dev2ser(serial_table[i])->open_count) {
26696 + if (atomic_read(&dev2ser(serial_table[i])->open_count)) {
26698 hso_start_serial_device(serial_table[i], GFP_NOIO);
26699 hso_kick_transmit(dev2ser(serial_table[i]));
26700 diff -urNp linux-2.6.37/drivers/net/wireless/b43/debugfs.c linux-2.6.37/drivers/net/wireless/b43/debugfs.c
26701 --- linux-2.6.37/drivers/net/wireless/b43/debugfs.c 2011-01-04 19:50:19.000000000 -0500
26702 +++ linux-2.6.37/drivers/net/wireless/b43/debugfs.c 2011-01-17 02:41:01.000000000 -0500
26703 @@ -43,7 +43,7 @@ static struct dentry *rootdir;
26704 struct b43_debugfs_fops {
26705 ssize_t (*read)(struct b43_wldev *dev, char *buf, size_t bufsize);
26706 int (*write)(struct b43_wldev *dev, const char *buf, size_t count);
26707 - struct file_operations fops;
26708 + const struct file_operations fops;
26709 /* Offset of struct b43_dfs_file in struct b43_dfsentry */
26710 size_t file_struct_offset;
26712 diff -urNp linux-2.6.37/drivers/net/wireless/b43legacy/debugfs.c linux-2.6.37/drivers/net/wireless/b43legacy/debugfs.c
26713 --- linux-2.6.37/drivers/net/wireless/b43legacy/debugfs.c 2011-01-04 19:50:19.000000000 -0500
26714 +++ linux-2.6.37/drivers/net/wireless/b43legacy/debugfs.c 2011-01-17 02:41:01.000000000 -0500
26715 @@ -44,7 +44,7 @@ static struct dentry *rootdir;
26716 struct b43legacy_debugfs_fops {
26717 ssize_t (*read)(struct b43legacy_wldev *dev, char *buf, size_t bufsize);
26718 int (*write)(struct b43legacy_wldev *dev, const char *buf, size_t count);
26719 - struct file_operations fops;
26720 + const struct file_operations fops;
26721 /* Offset of struct b43legacy_dfs_file in struct b43legacy_dfsentry */
26722 size_t file_struct_offset;
26723 /* Take wl->irq_lock before calling read/write? */
26724 diff -urNp linux-2.6.37/drivers/net/wireless/iwlwifi/iwl-debug.h linux-2.6.37/drivers/net/wireless/iwlwifi/iwl-debug.h
26725 --- linux-2.6.37/drivers/net/wireless/iwlwifi/iwl-debug.h 2011-01-04 19:50:19.000000000 -0500
26726 +++ linux-2.6.37/drivers/net/wireless/iwlwifi/iwl-debug.h 2011-01-17 02:41:01.000000000 -0500
26727 @@ -68,8 +68,8 @@ do {
26731 -#define IWL_DEBUG(__priv, level, fmt, args...)
26732 -#define IWL_DEBUG_LIMIT(__priv, level, fmt, args...)
26733 +#define IWL_DEBUG(__priv, level, fmt, args...) do {} while (0)
26734 +#define IWL_DEBUG_LIMIT(__priv, level, fmt, args...) do {} while (0)
26735 static inline void iwl_print_hex_dump(struct iwl_priv *priv, int level,
26736 const void *p, u32 len)
26738 diff -urNp linux-2.6.37/drivers/net/wireless/libertas/debugfs.c linux-2.6.37/drivers/net/wireless/libertas/debugfs.c
26739 --- linux-2.6.37/drivers/net/wireless/libertas/debugfs.c 2011-01-04 19:50:19.000000000 -0500
26740 +++ linux-2.6.37/drivers/net/wireless/libertas/debugfs.c 2011-01-17 02:41:01.000000000 -0500
26741 @@ -702,7 +702,7 @@ out_unlock:
26742 struct lbs_debugfs_files {
26745 - struct file_operations fops;
26746 + const struct file_operations fops;
26749 static const struct lbs_debugfs_files debugfs_files[] = {
26750 diff -urNp linux-2.6.37/drivers/net/wireless/rndis_wlan.c linux-2.6.37/drivers/net/wireless/rndis_wlan.c
26751 --- linux-2.6.37/drivers/net/wireless/rndis_wlan.c 2011-01-04 19:50:19.000000000 -0500
26752 +++ linux-2.6.37/drivers/net/wireless/rndis_wlan.c 2011-01-17 02:41:01.000000000 -0500
26753 @@ -1236,7 +1236,7 @@ static int set_rts_threshold(struct usbn
26755 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
26757 - if (rts_threshold < 0 || rts_threshold > 2347)
26758 + if (rts_threshold > 2347)
26759 rts_threshold = 2347;
26761 tmp = cpu_to_le32(rts_threshold);
26762 diff -urNp linux-2.6.37/drivers/oprofile/buffer_sync.c linux-2.6.37/drivers/oprofile/buffer_sync.c
26763 --- linux-2.6.37/drivers/oprofile/buffer_sync.c 2011-01-04 19:50:19.000000000 -0500
26764 +++ linux-2.6.37/drivers/oprofile/buffer_sync.c 2011-01-17 02:41:01.000000000 -0500
26765 @@ -342,7 +342,7 @@ static void add_data(struct op_entry *en
26766 if (cookie == NO_COOKIE)
26768 if (cookie == INVALID_COOKIE) {
26769 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
26770 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
26773 if (cookie != last_cookie) {
26774 @@ -386,14 +386,14 @@ add_sample(struct mm_struct *mm, struct
26775 /* add userspace sample */
26778 - atomic_inc(&oprofile_stats.sample_lost_no_mm);
26779 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
26783 cookie = lookup_dcookie(mm, s->eip, &offset);
26785 if (cookie == INVALID_COOKIE) {
26786 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
26787 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
26791 @@ -562,7 +562,7 @@ void sync_buffer(int cpu)
26792 /* ignore backtraces if failed to add a sample */
26793 if (state == sb_bt_start) {
26794 state = sb_bt_ignore;
26795 - atomic_inc(&oprofile_stats.bt_lost_no_mapping);
26796 + atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
26800 diff -urNp linux-2.6.37/drivers/oprofile/event_buffer.c linux-2.6.37/drivers/oprofile/event_buffer.c
26801 --- linux-2.6.37/drivers/oprofile/event_buffer.c 2011-01-04 19:50:19.000000000 -0500
26802 +++ linux-2.6.37/drivers/oprofile/event_buffer.c 2011-01-17 02:41:01.000000000 -0500
26803 @@ -53,7 +53,7 @@ void add_event_entry(unsigned long value
26806 if (buffer_pos == buffer_size) {
26807 - atomic_inc(&oprofile_stats.event_lost_overflow);
26808 + atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
26812 diff -urNp linux-2.6.37/drivers/oprofile/oprof.c linux-2.6.37/drivers/oprofile/oprof.c
26813 --- linux-2.6.37/drivers/oprofile/oprof.c 2011-01-04 19:50:19.000000000 -0500
26814 +++ linux-2.6.37/drivers/oprofile/oprof.c 2011-01-17 02:41:01.000000000 -0500
26815 @@ -110,7 +110,7 @@ static void switch_worker(struct work_st
26816 if (oprofile_ops.switch_events())
26819 - atomic_inc(&oprofile_stats.multiplex_counter);
26820 + atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
26821 start_switch_worker();
26824 diff -urNp linux-2.6.37/drivers/oprofile/oprofilefs.c linux-2.6.37/drivers/oprofile/oprofilefs.c
26825 --- linux-2.6.37/drivers/oprofile/oprofilefs.c 2011-01-04 19:50:19.000000000 -0500
26826 +++ linux-2.6.37/drivers/oprofile/oprofilefs.c 2011-01-17 02:41:01.000000000 -0500
26827 @@ -186,7 +186,7 @@ static const struct file_operations atom
26830 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
26831 - char const *name, atomic_t *val)
26832 + char const *name, atomic_unchecked_t *val)
26834 return __oprofilefs_create_file(sb, root, name,
26835 &atomic_ro_fops, 0444, val);
26836 diff -urNp linux-2.6.37/drivers/oprofile/oprofile_stats.c linux-2.6.37/drivers/oprofile/oprofile_stats.c
26837 --- linux-2.6.37/drivers/oprofile/oprofile_stats.c 2011-01-04 19:50:19.000000000 -0500
26838 +++ linux-2.6.37/drivers/oprofile/oprofile_stats.c 2011-01-17 02:41:01.000000000 -0500
26839 @@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
26840 cpu_buf->sample_invalid_eip = 0;
26843 - atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
26844 - atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
26845 - atomic_set(&oprofile_stats.event_lost_overflow, 0);
26846 - atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
26847 - atomic_set(&oprofile_stats.multiplex_counter, 0);
26848 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
26849 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
26850 + atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
26851 + atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
26852 + atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
26856 diff -urNp linux-2.6.37/drivers/oprofile/oprofile_stats.h linux-2.6.37/drivers/oprofile/oprofile_stats.h
26857 --- linux-2.6.37/drivers/oprofile/oprofile_stats.h 2011-01-04 19:50:19.000000000 -0500
26858 +++ linux-2.6.37/drivers/oprofile/oprofile_stats.h 2011-01-17 02:41:01.000000000 -0500
26859 @@ -13,11 +13,11 @@
26860 #include <asm/atomic.h>
26862 struct oprofile_stat_struct {
26863 - atomic_t sample_lost_no_mm;
26864 - atomic_t sample_lost_no_mapping;
26865 - atomic_t bt_lost_no_mapping;
26866 - atomic_t event_lost_overflow;
26867 - atomic_t multiplex_counter;
26868 + atomic_unchecked_t sample_lost_no_mm;
26869 + atomic_unchecked_t sample_lost_no_mapping;
26870 + atomic_unchecked_t bt_lost_no_mapping;
26871 + atomic_unchecked_t event_lost_overflow;
26872 + atomic_unchecked_t multiplex_counter;
26875 extern struct oprofile_stat_struct oprofile_stats;
26876 diff -urNp linux-2.6.37/drivers/parport/procfs.c linux-2.6.37/drivers/parport/procfs.c
26877 --- linux-2.6.37/drivers/parport/procfs.c 2011-01-04 19:50:19.000000000 -0500
26878 +++ linux-2.6.37/drivers/parport/procfs.c 2011-01-17 02:41:01.000000000 -0500
26879 @@ -64,7 +64,7 @@ static int do_active_device(ctl_table *t
26883 - return copy_to_user(result, buffer, len) ? -EFAULT : 0;
26884 + return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
26887 #ifdef CONFIG_PARPORT_1284
26888 @@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table
26892 - return copy_to_user (result, buffer, len) ? -EFAULT : 0;
26893 + return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
26895 #endif /* IEEE1284.3 support. */
26897 diff -urNp linux-2.6.37/drivers/pci/hotplug/acpiphp_glue.c linux-2.6.37/drivers/pci/hotplug/acpiphp_glue.c
26898 --- linux-2.6.37/drivers/pci/hotplug/acpiphp_glue.c 2011-01-04 19:50:19.000000000 -0500
26899 +++ linux-2.6.37/drivers/pci/hotplug/acpiphp_glue.c 2011-01-17 02:41:01.000000000 -0500
26900 @@ -110,7 +110,7 @@ static int post_dock_fixups(struct notif
26904 -static struct acpi_dock_ops acpiphp_dock_ops = {
26905 +static const struct acpi_dock_ops acpiphp_dock_ops = {
26906 .handler = handle_hotplug_event_func,
26909 diff -urNp linux-2.6.37/drivers/pci/hotplug/cpqphp_nvram.c linux-2.6.37/drivers/pci/hotplug/cpqphp_nvram.c
26910 --- linux-2.6.37/drivers/pci/hotplug/cpqphp_nvram.c 2011-01-04 19:50:19.000000000 -0500
26911 +++ linux-2.6.37/drivers/pci/hotplug/cpqphp_nvram.c 2011-01-17 02:41:01.000000000 -0500
26912 @@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_
26914 void compaq_nvram_init (void __iomem *rom_start)
26917 +#ifndef CONFIG_PAX_KERNEXEC
26919 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
26923 dbg("int15 entry = %p\n", compaq_int15_entry_point);
26925 /* initialize our int15 lock */
26926 diff -urNp linux-2.6.37/drivers/pci/intel-iommu.c linux-2.6.37/drivers/pci/intel-iommu.c
26927 --- linux-2.6.37/drivers/pci/intel-iommu.c 2011-01-04 19:50:19.000000000 -0500
26928 +++ linux-2.6.37/drivers/pci/intel-iommu.c 2011-01-17 02:41:01.000000000 -0500
26929 @@ -2934,7 +2934,7 @@ static int intel_mapping_error(struct de
26933 -struct dma_map_ops intel_dma_ops = {
26934 +const struct dma_map_ops intel_dma_ops = {
26935 .alloc_coherent = intel_alloc_coherent,
26936 .free_coherent = intel_free_coherent,
26937 .map_sg = intel_map_sg,
26938 diff -urNp linux-2.6.37/drivers/pci/pcie/portdrv_pci.c linux-2.6.37/drivers/pci/pcie/portdrv_pci.c
26939 --- linux-2.6.37/drivers/pci/pcie/portdrv_pci.c 2011-01-04 19:50:19.000000000 -0500
26940 +++ linux-2.6.37/drivers/pci/pcie/portdrv_pci.c 2011-01-17 02:41:01.000000000 -0500
26941 @@ -276,7 +276,7 @@ static void pcie_portdrv_err_resume(stru
26942 static const struct pci_device_id port_pci_ids[] = { {
26943 /* handle any PCI-Express port */
26944 PCI_DEVICE_CLASS(((PCI_CLASS_BRIDGE_PCI << 8) | 0x00), ~0),
26945 - }, { /* end: all zeroes */ }
26946 + }, { 0, 0, 0, 0, 0, 0, 0 }
26948 MODULE_DEVICE_TABLE(pci, port_pci_ids);
26950 diff -urNp linux-2.6.37/drivers/pci/probe.c linux-2.6.37/drivers/pci/probe.c
26951 --- linux-2.6.37/drivers/pci/probe.c 2011-01-04 19:50:19.000000000 -0500
26952 +++ linux-2.6.37/drivers/pci/probe.c 2011-01-17 02:41:01.000000000 -0500
26953 @@ -62,14 +62,14 @@ static ssize_t pci_bus_show_cpuaffinity(
26957 -static ssize_t inline pci_bus_show_cpumaskaffinity(struct device *dev,
26958 +static inline ssize_t pci_bus_show_cpumaskaffinity(struct device *dev,
26959 struct device_attribute *attr,
26962 return pci_bus_show_cpuaffinity(dev, 0, attr, buf);
26965 -static ssize_t inline pci_bus_show_cpulistaffinity(struct device *dev,
26966 +static inline ssize_t pci_bus_show_cpulistaffinity(struct device *dev,
26967 struct device_attribute *attr,
26970 @@ -165,7 +165,7 @@ int __pci_read_base(struct pci_dev *dev,
26974 - mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
26975 + mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
26977 if (!dev->mmio_always_on) {
26978 pci_read_config_word(dev, PCI_COMMAND, &orig_cmd);
26979 diff -urNp linux-2.6.37/drivers/pci/proc.c linux-2.6.37/drivers/pci/proc.c
26980 --- linux-2.6.37/drivers/pci/proc.c 2011-01-04 19:50:19.000000000 -0500
26981 +++ linux-2.6.37/drivers/pci/proc.c 2011-01-17 02:41:01.000000000 -0500
26982 @@ -476,7 +476,16 @@ static const struct file_operations proc
26983 static int __init pci_proc_init(void)
26985 struct pci_dev *dev = NULL;
26987 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
26988 +#ifdef CONFIG_GRKERNSEC_PROC_USER
26989 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
26990 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
26991 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
26994 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
26996 proc_create("devices", 0, proc_bus_pci_dir,
26997 &proc_bus_pci_dev_operations);
26998 proc_initialized = 1;
26999 diff -urNp linux-2.6.37/drivers/pcmcia/ti113x.h linux-2.6.37/drivers/pcmcia/ti113x.h
27000 --- linux-2.6.37/drivers/pcmcia/ti113x.h 2011-01-04 19:50:19.000000000 -0500
27001 +++ linux-2.6.37/drivers/pcmcia/ti113x.h 2011-01-17 02:41:01.000000000 -0500
27002 @@ -936,7 +936,7 @@ static struct pci_device_id ene_tune_tbl
27003 DEVID(PCI_VENDOR_ID_MOTOROLA, 0x3410, 0xECC0, PCI_ANY_ID,
27004 ENE_TEST_C9_TLTENABLE | ENE_TEST_C9_PFENABLE, ENE_TEST_C9_TLTENABLE),
27007 + { 0, 0, 0, 0, 0, 0, 0 }
27010 static void ene_tune_bridge(struct pcmcia_socket *sock, struct pci_bus *bus)
27011 diff -urNp linux-2.6.37/drivers/pcmcia/yenta_socket.c linux-2.6.37/drivers/pcmcia/yenta_socket.c
27012 --- linux-2.6.37/drivers/pcmcia/yenta_socket.c 2011-01-04 19:50:19.000000000 -0500
27013 +++ linux-2.6.37/drivers/pcmcia/yenta_socket.c 2011-01-17 02:41:01.000000000 -0500
27014 @@ -1426,7 +1426,7 @@ static struct pci_device_id yenta_table[
27016 /* match any cardbus bridge */
27017 CB_ID(PCI_ANY_ID, PCI_ANY_ID, DEFAULT),
27018 - { /* all zeroes */ }
27019 + { 0, 0, 0, 0, 0, 0, 0 }
27021 MODULE_DEVICE_TABLE(pci, yenta_table);
27023 diff -urNp linux-2.6.37/drivers/platform/x86/acer-wmi.c linux-2.6.37/drivers/platform/x86/acer-wmi.c
27024 --- linux-2.6.37/drivers/platform/x86/acer-wmi.c 2011-01-04 19:50:19.000000000 -0500
27025 +++ linux-2.6.37/drivers/platform/x86/acer-wmi.c 2011-01-17 02:41:01.000000000 -0500
27026 @@ -915,7 +915,7 @@ static int update_bl_status(struct backl
27030 -static struct backlight_ops acer_bl_ops = {
27031 +static const struct backlight_ops acer_bl_ops = {
27032 .get_brightness = read_brightness,
27033 .update_status = update_bl_status,
27035 diff -urNp linux-2.6.37/drivers/platform/x86/asus_acpi.c linux-2.6.37/drivers/platform/x86/asus_acpi.c
27036 --- linux-2.6.37/drivers/platform/x86/asus_acpi.c 2011-01-04 19:50:19.000000000 -0500
27037 +++ linux-2.6.37/drivers/platform/x86/asus_acpi.c 2011-01-17 02:41:01.000000000 -0500
27038 @@ -1467,7 +1467,7 @@ static int asus_hotk_remove(struct acpi_
27042 -static struct backlight_ops asus_backlight_data = {
27043 +static const struct backlight_ops asus_backlight_data = {
27044 .get_brightness = read_brightness,
27045 .update_status = set_brightness_status,
27047 diff -urNp linux-2.6.37/drivers/platform/x86/asus-laptop.c linux-2.6.37/drivers/platform/x86/asus-laptop.c
27048 --- linux-2.6.37/drivers/platform/x86/asus-laptop.c 2011-01-04 19:50:19.000000000 -0500
27049 +++ linux-2.6.37/drivers/platform/x86/asus-laptop.c 2011-01-17 02:41:01.000000000 -0500
27050 @@ -243,7 +243,6 @@ struct asus_laptop {
27051 struct asus_led gled;
27052 struct asus_led kled;
27053 struct workqueue_struct *led_workqueue;
27055 int wireless_status;
27058 @@ -640,7 +639,7 @@ static int update_bl_status(struct backl
27059 return asus_lcd_set(asus, value);
27062 -static struct backlight_ops asusbl_ops = {
27063 +static const struct backlight_ops asusbl_ops = {
27064 .get_brightness = asus_read_brightness,
27065 .update_status = update_bl_status,
27067 diff -urNp linux-2.6.37/drivers/platform/x86/dell-laptop.c linux-2.6.37/drivers/platform/x86/dell-laptop.c
27068 --- linux-2.6.37/drivers/platform/x86/dell-laptop.c 2011-01-04 19:50:19.000000000 -0500
27069 +++ linux-2.6.37/drivers/platform/x86/dell-laptop.c 2011-01-17 02:41:01.000000000 -0500
27070 @@ -546,7 +546,7 @@ out:
27071 return buffer->output[1];
27074 -static struct backlight_ops dell_ops = {
27075 +static const struct backlight_ops dell_ops = {
27076 .get_brightness = dell_get_intensity,
27077 .update_status = dell_send_intensity,
27079 diff -urNp linux-2.6.37/drivers/platform/x86/eeepc-laptop.c linux-2.6.37/drivers/platform/x86/eeepc-laptop.c
27080 --- linux-2.6.37/drivers/platform/x86/eeepc-laptop.c 2011-01-04 19:50:19.000000000 -0500
27081 +++ linux-2.6.37/drivers/platform/x86/eeepc-laptop.c 2011-01-17 02:41:01.000000000 -0500
27082 @@ -1115,7 +1115,7 @@ static int update_bl_status(struct backl
27083 return set_brightness(bd, bd->props.brightness);
27086 -static struct backlight_ops eeepcbl_ops = {
27087 +static const struct backlight_ops eeepcbl_ops = {
27088 .get_brightness = read_brightness,
27089 .update_status = update_bl_status,
27091 diff -urNp linux-2.6.37/drivers/platform/x86/fujitsu-laptop.c linux-2.6.37/drivers/platform/x86/fujitsu-laptop.c
27092 --- linux-2.6.37/drivers/platform/x86/fujitsu-laptop.c 2011-01-04 19:50:19.000000000 -0500
27093 +++ linux-2.6.37/drivers/platform/x86/fujitsu-laptop.c 2011-01-17 02:41:01.000000000 -0500
27094 @@ -437,7 +437,7 @@ static int bl_update_status(struct backl
27098 -static struct backlight_ops fujitsubl_ops = {
27099 +static const struct backlight_ops fujitsubl_ops = {
27100 .get_brightness = bl_get_brightness,
27101 .update_status = bl_update_status,
27103 diff -urNp linux-2.6.37/drivers/platform/x86/sony-laptop.c linux-2.6.37/drivers/platform/x86/sony-laptop.c
27104 --- linux-2.6.37/drivers/platform/x86/sony-laptop.c 2011-01-04 19:50:19.000000000 -0500
27105 +++ linux-2.6.37/drivers/platform/x86/sony-laptop.c 2011-01-17 02:41:01.000000000 -0500
27106 @@ -856,7 +856,7 @@ static int sony_backlight_get_brightness
27109 static struct backlight_device *sony_backlight_device;
27110 -static struct backlight_ops sony_backlight_ops = {
27111 +static const struct backlight_ops sony_backlight_ops = {
27112 .update_status = sony_backlight_update_status,
27113 .get_brightness = sony_backlight_get_brightness,
27115 diff -urNp linux-2.6.37/drivers/platform/x86/thinkpad_acpi.c linux-2.6.37/drivers/platform/x86/thinkpad_acpi.c
27116 --- linux-2.6.37/drivers/platform/x86/thinkpad_acpi.c 2011-01-04 19:50:19.000000000 -0500
27117 +++ linux-2.6.37/drivers/platform/x86/thinkpad_acpi.c 2011-01-17 02:41:01.000000000 -0500
27118 @@ -6109,7 +6109,7 @@ static void tpacpi_brightness_notify_cha
27119 BACKLIGHT_UPDATE_HOTKEY);
27122 -static struct backlight_ops ibm_backlight_data = {
27123 +static const struct backlight_ops ibm_backlight_data = {
27124 .get_brightness = brightness_get,
27125 .update_status = brightness_update_status,
27127 diff -urNp linux-2.6.37/drivers/platform/x86/toshiba_acpi.c linux-2.6.37/drivers/platform/x86/toshiba_acpi.c
27128 --- linux-2.6.37/drivers/platform/x86/toshiba_acpi.c 2011-01-04 19:50:19.000000000 -0500
27129 +++ linux-2.6.37/drivers/platform/x86/toshiba_acpi.c 2011-01-17 02:41:01.000000000 -0500
27130 @@ -841,7 +841,7 @@ static void remove_toshiba_proc_entries(
27131 remove_proc_entry("version", toshiba_proc_dir);
27134 -static struct backlight_ops toshiba_backlight_data = {
27135 +static const struct backlight_ops toshiba_backlight_data = {
27136 .get_brightness = get_lcd,
27137 .update_status = set_lcd_status,
27139 diff -urNp linux-2.6.37/drivers/pnp/pnpbios/bioscalls.c linux-2.6.37/drivers/pnp/pnpbios/bioscalls.c
27140 --- linux-2.6.37/drivers/pnp/pnpbios/bioscalls.c 2011-01-04 19:50:19.000000000 -0500
27141 +++ linux-2.6.37/drivers/pnp/pnpbios/bioscalls.c 2011-01-17 02:41:01.000000000 -0500
27142 @@ -59,7 +59,7 @@ do { \
27143 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
27146 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
27147 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
27148 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
27151 @@ -96,7 +96,10 @@ static inline u16 call_pnp_bios(u16 func
27154 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
27156 + pax_open_kernel();
27157 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
27158 + pax_close_kernel();
27160 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
27161 spin_lock_irqsave(&pnp_bios_lock, flags);
27162 @@ -134,7 +137,10 @@ static inline u16 call_pnp_bios(u16 func
27164 spin_unlock_irqrestore(&pnp_bios_lock, flags);
27166 + pax_open_kernel();
27167 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
27168 + pax_close_kernel();
27172 /* If we get here and this is set then the PnP BIOS faulted on us. */
27173 @@ -468,7 +474,7 @@ int pnp_bios_read_escd(char *data, u32 n
27177 -void pnpbios_calls_init(union pnp_bios_install_struct *header)
27178 +void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
27182 @@ -476,6 +482,8 @@ void pnpbios_calls_init(union pnp_bios_i
27183 pnp_bios_callpoint.offset = header->fields.pm16offset;
27184 pnp_bios_callpoint.segment = PNP_CS16;
27186 + pax_open_kernel();
27188 for_each_possible_cpu(i) {
27189 struct desc_struct *gdt = get_cpu_gdt_table(i);
27191 @@ -487,4 +495,6 @@ void pnpbios_calls_init(union pnp_bios_i
27192 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
27193 (unsigned long)__va(header->fields.pm16dseg));
27196 + pax_close_kernel();
27198 diff -urNp linux-2.6.37/drivers/pnp/quirks.c linux-2.6.37/drivers/pnp/quirks.c
27199 --- linux-2.6.37/drivers/pnp/quirks.c 2011-01-04 19:50:19.000000000 -0500
27200 +++ linux-2.6.37/drivers/pnp/quirks.c 2011-01-17 02:41:01.000000000 -0500
27201 @@ -322,7 +322,7 @@ static struct pnp_fixup pnp_fixups[] = {
27202 /* PnP resources that might overlap PCI BARs */
27203 {"PNP0c01", quirk_system_pci_resources},
27204 {"PNP0c02", quirk_system_pci_resources},
27209 void pnp_fixup_device(struct pnp_dev *dev)
27210 diff -urNp linux-2.6.37/drivers/pnp/resource.c linux-2.6.37/drivers/pnp/resource.c
27211 --- linux-2.6.37/drivers/pnp/resource.c 2011-01-04 19:50:19.000000000 -0500
27212 +++ linux-2.6.37/drivers/pnp/resource.c 2011-01-17 02:41:01.000000000 -0500
27213 @@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, s
27216 /* check if the resource is valid */
27217 - if (*irq < 0 || *irq > 15)
27221 /* check if the resource is reserved */
27222 @@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, s
27225 /* check if the resource is valid */
27226 - if (*dma < 0 || *dma == 4 || *dma > 7)
27227 + if (*dma == 4 || *dma > 7)
27230 /* check if the resource is reserved */
27231 diff -urNp linux-2.6.37/drivers/rtc/rtc-dev.c linux-2.6.37/drivers/rtc/rtc-dev.c
27232 --- linux-2.6.37/drivers/rtc/rtc-dev.c 2011-01-04 19:50:19.000000000 -0500
27233 +++ linux-2.6.37/drivers/rtc/rtc-dev.c 2011-01-17 02:41:01.000000000 -0500
27235 #include <linux/module.h>
27236 #include <linux/rtc.h>
27237 #include <linux/sched.h>
27238 +#include <linux/grsecurity.h>
27239 #include "rtc-core.h"
27241 static dev_t rtc_devt;
27242 @@ -357,6 +358,8 @@ static long rtc_dev_ioctl(struct file *f
27243 if (copy_from_user(&tm, uarg, sizeof(tm)))
27246 + gr_log_timechange();
27248 return rtc_set_time(rtc, &tm);
27251 diff -urNp linux-2.6.37/drivers/s390/cio/qdio_debug.c linux-2.6.37/drivers/s390/cio/qdio_debug.c
27252 --- linux-2.6.37/drivers/s390/cio/qdio_debug.c 2011-01-04 19:50:19.000000000 -0500
27253 +++ linux-2.6.37/drivers/s390/cio/qdio_debug.c 2011-01-17 02:41:01.000000000 -0500
27254 @@ -224,7 +224,7 @@ static int qperf_seq_open(struct inode *
27255 filp->f_path.dentry->d_inode->i_private);
27258 -static struct file_operations debugfs_perf_fops = {
27259 +static const struct file_operations debugfs_perf_fops = {
27260 .owner = THIS_MODULE,
27261 .open = qperf_seq_open,
27263 diff -urNp linux-2.6.37/drivers/scsi/hpsa.c linux-2.6.37/drivers/scsi/hpsa.c
27264 --- linux-2.6.37/drivers/scsi/hpsa.c 2011-01-04 19:50:19.000000000 -0500
27265 +++ linux-2.6.37/drivers/scsi/hpsa.c 2011-01-17 02:41:01.000000000 -0500
27266 @@ -2292,6 +2292,8 @@ static int hpsa_ioctl32_passthru(struct
27270 + memset(&arg64, 0, sizeof(arg64));
27273 err |= copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
27274 sizeof(arg64.LUN_info));
27275 diff -urNp linux-2.6.37/drivers/scsi/ipr.c linux-2.6.37/drivers/scsi/ipr.c
27276 --- linux-2.6.37/drivers/scsi/ipr.c 2011-01-04 19:50:19.000000000 -0500
27277 +++ linux-2.6.37/drivers/scsi/ipr.c 2011-01-17 02:41:01.000000000 -0500
27278 @@ -6202,7 +6202,7 @@ static bool ipr_qc_fill_rtf(struct ata_q
27282 -static struct ata_port_operations ipr_sata_ops = {
27283 +static const struct ata_port_operations ipr_sata_ops = {
27284 .phy_reset = ipr_ata_phy_reset,
27285 .hardreset = ipr_sata_reset,
27286 .post_internal_cmd = ipr_ata_post_internal,
27287 diff -urNp linux-2.6.37/drivers/scsi/libfc/fc_exch.c linux-2.6.37/drivers/scsi/libfc/fc_exch.c
27288 --- linux-2.6.37/drivers/scsi/libfc/fc_exch.c 2011-01-04 19:50:19.000000000 -0500
27289 +++ linux-2.6.37/drivers/scsi/libfc/fc_exch.c 2011-01-17 02:41:01.000000000 -0500
27290 @@ -100,12 +100,12 @@ struct fc_exch_mgr {
27291 * all together if not used XXX
27294 - atomic_t no_free_exch;
27295 - atomic_t no_free_exch_xid;
27296 - atomic_t xid_not_found;
27297 - atomic_t xid_busy;
27298 - atomic_t seq_not_found;
27299 - atomic_t non_bls_resp;
27300 + atomic_unchecked_t no_free_exch;
27301 + atomic_unchecked_t no_free_exch_xid;
27302 + atomic_unchecked_t xid_not_found;
27303 + atomic_unchecked_t xid_busy;
27304 + atomic_unchecked_t seq_not_found;
27305 + atomic_unchecked_t non_bls_resp;
27308 #define fc_seq_exch(sp) container_of(sp, struct fc_exch, seq)
27309 @@ -670,7 +670,7 @@ static struct fc_exch *fc_exch_em_alloc(
27310 /* allocate memory for exchange */
27311 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
27313 - atomic_inc(&mp->stats.no_free_exch);
27314 + atomic_inc_unchecked(&mp->stats.no_free_exch);
27317 memset(ep, 0, sizeof(*ep));
27318 @@ -718,7 +718,7 @@ out:
27321 spin_unlock_bh(&pool->lock);
27322 - atomic_inc(&mp->stats.no_free_exch_xid);
27323 + atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
27324 mempool_free(ep, mp->ep_pool);
27327 @@ -863,7 +863,7 @@ static enum fc_pf_rjt_reason fc_seq_look
27328 xid = ntohs(fh->fh_ox_id); /* we originated exch */
27329 ep = fc_exch_find(mp, xid);
27331 - atomic_inc(&mp->stats.xid_not_found);
27332 + atomic_inc_unchecked(&mp->stats.xid_not_found);
27333 reject = FC_RJT_OX_ID;
27336 @@ -893,7 +893,7 @@ static enum fc_pf_rjt_reason fc_seq_look
27337 ep = fc_exch_find(mp, xid);
27338 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
27340 - atomic_inc(&mp->stats.xid_busy);
27341 + atomic_inc_unchecked(&mp->stats.xid_busy);
27342 reject = FC_RJT_RX_ID;
27345 @@ -904,7 +904,7 @@ static enum fc_pf_rjt_reason fc_seq_look
27347 xid = ep->xid; /* get our XID */
27349 - atomic_inc(&mp->stats.xid_not_found);
27350 + atomic_inc_unchecked(&mp->stats.xid_not_found);
27351 reject = FC_RJT_RX_ID; /* XID not found */
27354 @@ -921,7 +921,7 @@ static enum fc_pf_rjt_reason fc_seq_look
27357 if (sp->id != fh->fh_seq_id) {
27358 - atomic_inc(&mp->stats.seq_not_found);
27359 + atomic_inc_unchecked(&mp->stats.seq_not_found);
27360 reject = FC_RJT_SEQ_ID; /* sequence/exch should exist */
27363 @@ -1338,22 +1338,22 @@ static void fc_exch_recv_seq_resp(struct
27365 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
27367 - atomic_inc(&mp->stats.xid_not_found);
27368 + atomic_inc_unchecked(&mp->stats.xid_not_found);
27371 if (ep->esb_stat & ESB_ST_COMPLETE) {
27372 - atomic_inc(&mp->stats.xid_not_found);
27373 + atomic_inc_unchecked(&mp->stats.xid_not_found);
27376 if (ep->rxid == FC_XID_UNKNOWN)
27377 ep->rxid = ntohs(fh->fh_rx_id);
27378 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
27379 - atomic_inc(&mp->stats.xid_not_found);
27380 + atomic_inc_unchecked(&mp->stats.xid_not_found);
27383 if (ep->did != ntoh24(fh->fh_s_id) &&
27384 ep->did != FC_FID_FLOGI) {
27385 - atomic_inc(&mp->stats.xid_not_found);
27386 + atomic_inc_unchecked(&mp->stats.xid_not_found);
27390 @@ -1362,7 +1362,7 @@ static void fc_exch_recv_seq_resp(struct
27391 sp->ssb_stat |= SSB_ST_RESP;
27392 sp->id = fh->fh_seq_id;
27393 } else if (sp->id != fh->fh_seq_id) {
27394 - atomic_inc(&mp->stats.seq_not_found);
27395 + atomic_inc_unchecked(&mp->stats.seq_not_found);
27399 @@ -1425,9 +1425,9 @@ static void fc_exch_recv_resp(struct fc_
27400 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
27403 - atomic_inc(&mp->stats.xid_not_found);
27404 + atomic_inc_unchecked(&mp->stats.xid_not_found);
27406 - atomic_inc(&mp->stats.non_bls_resp);
27407 + atomic_inc_unchecked(&mp->stats.non_bls_resp);
27411 diff -urNp linux-2.6.37/drivers/scsi/libsas/sas_ata.c linux-2.6.37/drivers/scsi/libsas/sas_ata.c
27412 --- linux-2.6.37/drivers/scsi/libsas/sas_ata.c 2011-01-04 19:50:19.000000000 -0500
27413 +++ linux-2.6.37/drivers/scsi/libsas/sas_ata.c 2011-01-17 02:41:01.000000000 -0500
27414 @@ -348,10 +348,10 @@ static int sas_ata_scr_read(struct ata_l
27418 -static struct ata_port_operations sas_sata_ops = {
27419 +static const struct ata_port_operations sas_sata_ops = {
27420 .phy_reset = sas_ata_phy_reset,
27421 .post_internal_cmd = sas_ata_post_internal,
27422 - .qc_defer = ata_std_qc_defer,
27423 + .qc_defer = ata_std_qc_defer,
27424 .qc_prep = ata_noop_qc_prep,
27425 .qc_issue = sas_ata_qc_issue,
27426 .qc_fill_rtf = sas_ata_qc_fill_rtf,
27427 diff -urNp linux-2.6.37/drivers/scsi/mpt2sas/mpt2sas_debug.h linux-2.6.37/drivers/scsi/mpt2sas/mpt2sas_debug.h
27428 --- linux-2.6.37/drivers/scsi/mpt2sas/mpt2sas_debug.h 2011-01-04 19:50:19.000000000 -0500
27429 +++ linux-2.6.37/drivers/scsi/mpt2sas/mpt2sas_debug.h 2011-01-17 02:41:01.000000000 -0500
27434 -#define MPT_CHECK_LOGGING(IOC, CMD, BITS)
27435 +#define MPT_CHECK_LOGGING(IOC, CMD, BITS) do {} while (0)
27436 #endif /* CONFIG_SCSI_MPT2SAS_LOGGING */
27439 diff -urNp linux-2.6.37/drivers/scsi/qla2xxx/qla_os.c linux-2.6.37/drivers/scsi/qla2xxx/qla_os.c
27440 --- linux-2.6.37/drivers/scsi/qla2xxx/qla_os.c 2011-01-04 19:50:19.000000000 -0500
27441 +++ linux-2.6.37/drivers/scsi/qla2xxx/qla_os.c 2011-01-17 02:41:01.000000000 -0500
27442 @@ -4083,7 +4083,7 @@ static struct pci_driver qla2xxx_pci_dri
27443 .err_handler = &qla2xxx_err_handler,
27446 -static struct file_operations apidev_fops = {
27447 +static const struct file_operations apidev_fops = {
27448 .owner = THIS_MODULE,
27449 .llseek = noop_llseek,
27451 diff -urNp linux-2.6.37/drivers/scsi/scsi_logging.h linux-2.6.37/drivers/scsi/scsi_logging.h
27452 --- linux-2.6.37/drivers/scsi/scsi_logging.h 2011-01-04 19:50:19.000000000 -0500
27453 +++ linux-2.6.37/drivers/scsi/scsi_logging.h 2011-01-17 02:41:01.000000000 -0500
27454 @@ -51,7 +51,7 @@ do { \
27458 -#define SCSI_CHECK_LOGGING(SHIFT, BITS, LEVEL, CMD)
27459 +#define SCSI_CHECK_LOGGING(SHIFT, BITS, LEVEL, CMD) do {} while (0)
27460 #endif /* CONFIG_SCSI_LOGGING */
27463 diff -urNp linux-2.6.37/drivers/scsi/sg.c linux-2.6.37/drivers/scsi/sg.c
27464 --- linux-2.6.37/drivers/scsi/sg.c 2011-01-04 19:50:19.000000000 -0500
27465 +++ linux-2.6.37/drivers/scsi/sg.c 2011-01-17 02:41:01.000000000 -0500
27466 @@ -2310,7 +2310,7 @@ struct sg_proc_leaf {
27467 const struct file_operations * fops;
27470 -static struct sg_proc_leaf sg_proc_leaf_arr[] = {
27471 +static const struct sg_proc_leaf sg_proc_leaf_arr[] = {
27472 {"allow_dio", &adio_fops},
27473 {"debug", &debug_fops},
27474 {"def_reserved_size", &dressz_fops},
27475 @@ -2325,7 +2325,7 @@ sg_proc_init(void)
27478 int num_leaves = ARRAY_SIZE(sg_proc_leaf_arr);
27479 - struct sg_proc_leaf * leaf;
27480 + const struct sg_proc_leaf * leaf;
27482 sg_proc_sgp = proc_mkdir(sg_proc_sg_dirname, NULL);
27484 diff -urNp linux-2.6.37/drivers/serial/8250_pci.c linux-2.6.37/drivers/serial/8250_pci.c
27485 --- linux-2.6.37/drivers/serial/8250_pci.c 2011-01-04 19:50:19.000000000 -0500
27486 +++ linux-2.6.37/drivers/serial/8250_pci.c 2011-01-17 02:41:01.000000000 -0500
27487 @@ -3782,7 +3782,7 @@ static struct pci_device_id serial_pci_t
27488 PCI_ANY_ID, PCI_ANY_ID,
27489 PCI_CLASS_COMMUNICATION_MULTISERIAL << 8,
27490 0xffff00, pbn_default },
27492 + { 0, 0, 0, 0, 0, 0, 0 }
27495 static struct pci_driver serial_pci_driver = {
27496 diff -urNp linux-2.6.37/drivers/serial/kgdboc.c linux-2.6.37/drivers/serial/kgdboc.c
27497 --- linux-2.6.37/drivers/serial/kgdboc.c 2011-01-04 19:50:19.000000000 -0500
27498 +++ linux-2.6.37/drivers/serial/kgdboc.c 2011-01-17 02:41:01.000000000 -0500
27501 #define MAX_CONFIG_LEN 40
27503 -static struct kgdb_io kgdboc_io_ops;
27504 +/* cannot be const, see configure_kgdboc() */
27505 +static struct kgdb_io kgdboc_io_ops;
27507 /* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
27508 static int configured = -1;
27509 @@ -293,6 +294,7 @@ static void kgdboc_post_exp_handler(void
27510 kgdboc_restore_input();
27513 +/* cannot be const, see configure_kgdboc() */
27514 static struct kgdb_io kgdboc_io_ops = {
27516 .read_char = kgdboc_get_char,
27517 diff -urNp linux-2.6.37/drivers/staging/autofs/root.c linux-2.6.37/drivers/staging/autofs/root.c
27518 --- linux-2.6.37/drivers/staging/autofs/root.c 2011-01-04 19:50:19.000000000 -0500
27519 +++ linux-2.6.37/drivers/staging/autofs/root.c 2011-01-17 21:04:34.000000000 -0500
27520 @@ -308,7 +308,8 @@ static int autofs_root_symlink(struct in
27521 set_bit(n,sbi->symlink_bitmap);
27522 sl = &sbi->symlink[n];
27523 sl->len = strlen(symname);
27524 - sl->data = kmalloc(slsize = sl->len+1, GFP_KERNEL);
27525 + slsize = sl->len + 1;
27526 + sl->data = kmalloc(slsize, GFP_KERNEL);
27528 clear_bit(n,sbi->symlink_bitmap);
27530 diff -urNp linux-2.6.37/drivers/staging/bcm/Bcmchar.c linux-2.6.37/drivers/staging/bcm/Bcmchar.c
27531 --- linux-2.6.37/drivers/staging/bcm/Bcmchar.c 2011-01-04 19:50:19.000000000 -0500
27532 +++ linux-2.6.37/drivers/staging/bcm/Bcmchar.c 2011-01-17 02:41:01.000000000 -0500
27533 @@ -2386,7 +2386,7 @@ static long bcm_char_ioctl(struct file *
27537 -static struct file_operations bcm_fops = {
27538 +static const struct file_operations bcm_fops = {
27539 .owner = THIS_MODULE,
27540 .open = bcm_char_open,
27541 .release = bcm_char_release,
27542 diff -urNp linux-2.6.37/drivers/staging/bcm/InterfaceInit.c linux-2.6.37/drivers/staging/bcm/InterfaceInit.c
27543 --- linux-2.6.37/drivers/staging/bcm/InterfaceInit.c 2011-01-04 19:50:19.000000000 -0500
27544 +++ linux-2.6.37/drivers/staging/bcm/InterfaceInit.c 2011-01-17 02:41:01.000000000 -0500
27545 @@ -157,7 +157,7 @@ VOID ConfigureEndPointTypesThroughEEPROM
27549 -static struct file_operations usbbcm_fops = {
27550 +static const struct file_operations usbbcm_fops = {
27551 .open = usbbcm_open,
27552 .release = usbbcm_release,
27553 .read = usbbcm_read,
27554 diff -urNp linux-2.6.37/drivers/staging/comedi/comedi_fops.c linux-2.6.37/drivers/staging/comedi/comedi_fops.c
27555 --- linux-2.6.37/drivers/staging/comedi/comedi_fops.c 2011-01-04 19:50:19.000000000 -0500
27556 +++ linux-2.6.37/drivers/staging/comedi/comedi_fops.c 2011-01-17 02:41:01.000000000 -0500
27557 @@ -1426,7 +1426,7 @@ static void comedi_unmap(struct vm_area_
27558 mutex_unlock(&dev->mutex);
27561 -static struct vm_operations_struct comedi_vm_ops = {
27562 +static const struct vm_operations_struct comedi_vm_ops = {
27563 .close = comedi_unmap,
27566 diff -urNp linux-2.6.37/drivers/staging/ft1000/ft1000-usb/ft1000_chdev.c linux-2.6.37/drivers/staging/ft1000/ft1000-usb/ft1000_chdev.c
27567 --- linux-2.6.37/drivers/staging/ft1000/ft1000-usb/ft1000_chdev.c 2011-01-04 19:50:19.000000000 -0500
27568 +++ linux-2.6.37/drivers/staging/ft1000/ft1000-usb/ft1000_chdev.c 2011-01-17 02:41:01.000000000 -0500
27569 @@ -69,7 +69,7 @@ int numofmsgbuf = 0;
27571 // Table of entry-point routines for char device
27573 -static struct file_operations ft1000fops =
27574 +static const struct file_operations ft1000fops =
27576 .unlocked_ioctl = ft1000_ChIoctl,
27577 .poll = ft1000_ChPoll,
27578 diff -urNp linux-2.6.37/drivers/staging/go7007/go7007-v4l2.c linux-2.6.37/drivers/staging/go7007/go7007-v4l2.c
27579 --- linux-2.6.37/drivers/staging/go7007/go7007-v4l2.c 2011-01-04 19:50:19.000000000 -0500
27580 +++ linux-2.6.37/drivers/staging/go7007/go7007-v4l2.c 2011-01-17 02:41:01.000000000 -0500
27581 @@ -1672,7 +1672,7 @@ static int go7007_vm_fault(struct vm_are
27585 -static struct vm_operations_struct go7007_vm_ops = {
27586 +static const struct vm_operations_struct go7007_vm_ops = {
27587 .open = go7007_vm_open,
27588 .close = go7007_vm_close,
27589 .fault = go7007_vm_fault,
27590 diff -urNp linux-2.6.37/drivers/staging/hv/hv.c linux-2.6.37/drivers/staging/hv/hv.c
27591 --- linux-2.6.37/drivers/staging/hv/hv.c 2011-01-04 19:50:19.000000000 -0500
27592 +++ linux-2.6.37/drivers/staging/hv/hv.c 2011-01-17 02:41:01.000000000 -0500
27593 @@ -162,7 +162,7 @@ static u64 HvDoHypercall(u64 Control, vo
27594 u64 outputAddress = (Output) ? virt_to_phys(Output) : 0;
27595 u32 outputAddressHi = outputAddress >> 32;
27596 u32 outputAddressLo = outputAddress & 0xFFFFFFFF;
27597 - volatile void *hypercallPage = gHvContext.HypercallPage;
27598 + volatile void *hypercallPage = ktva_ktla(gHvContext.HypercallPage);
27600 DPRINT_DBG(VMBUS, "Hypercall <control %llx input %p output %p>",
27601 Control, Input, Output);
27602 diff -urNp linux-2.6.37/drivers/staging/msm/msm_fb_bl.c linux-2.6.37/drivers/staging/msm/msm_fb_bl.c
27603 --- linux-2.6.37/drivers/staging/msm/msm_fb_bl.c 2011-01-04 19:50:19.000000000 -0500
27604 +++ linux-2.6.37/drivers/staging/msm/msm_fb_bl.c 2011-01-17 02:41:01.000000000 -0500
27605 @@ -42,7 +42,7 @@ static int msm_fb_bl_update_status(struc
27609 -static struct backlight_ops msm_fb_bl_ops = {
27610 +static const struct backlight_ops msm_fb_bl_ops = {
27611 .get_brightness = msm_fb_bl_get_brightness,
27612 .update_status = msm_fb_bl_update_status,
27614 diff -urNp linux-2.6.37/drivers/staging/olpc_dcon/olpc_dcon.c linux-2.6.37/drivers/staging/olpc_dcon/olpc_dcon.c
27615 --- linux-2.6.37/drivers/staging/olpc_dcon/olpc_dcon.c 2011-01-04 19:50:19.000000000 -0500
27616 +++ linux-2.6.37/drivers/staging/olpc_dcon/olpc_dcon.c 2011-01-17 02:41:01.000000000 -0500
27617 @@ -615,7 +615,7 @@ static struct device_attribute dcon_devi
27618 __ATTR(resumeline, 0644, dcon_resumeline_show, dcon_resumeline_store),
27621 -static struct backlight_ops dcon_bl_ops = {
27622 +static const struct backlight_ops dcon_bl_ops = {
27623 .get_brightness = dconbl_get,
27624 .update_status = dconbl_set
27626 diff -urNp linux-2.6.37/drivers/staging/phison/phison.c linux-2.6.37/drivers/staging/phison/phison.c
27627 --- linux-2.6.37/drivers/staging/phison/phison.c 2011-01-04 19:50:19.000000000 -0500
27628 +++ linux-2.6.37/drivers/staging/phison/phison.c 2011-01-17 02:41:01.000000000 -0500
27629 @@ -43,7 +43,7 @@ static struct scsi_host_template phison_
27630 ATA_BMDMA_SHT(DRV_NAME),
27633 -static struct ata_port_operations phison_ops = {
27634 +static const struct ata_port_operations phison_ops = {
27635 .inherits = &ata_bmdma_port_ops,
27636 .prereset = phison_pre_reset,
27638 diff -urNp linux-2.6.37/drivers/staging/pohmelfs/inode.c linux-2.6.37/drivers/staging/pohmelfs/inode.c
27639 --- linux-2.6.37/drivers/staging/pohmelfs/inode.c 2011-01-04 19:50:19.000000000 -0500
27640 +++ linux-2.6.37/drivers/staging/pohmelfs/inode.c 2011-01-17 02:41:01.000000000 -0500
27641 @@ -1848,7 +1848,7 @@ static int pohmelfs_fill_super(struct su
27642 mutex_init(&psb->mcache_lock);
27643 psb->mcache_root = RB_ROOT;
27644 psb->mcache_timeout = msecs_to_jiffies(5000);
27645 - atomic_long_set(&psb->mcache_gen, 0);
27646 + atomic_long_set_unchecked(&psb->mcache_gen, 0);
27648 psb->trans_max_pages = 100;
27650 diff -urNp linux-2.6.37/drivers/staging/pohmelfs/mcache.c linux-2.6.37/drivers/staging/pohmelfs/mcache.c
27651 --- linux-2.6.37/drivers/staging/pohmelfs/mcache.c 2011-01-04 19:50:19.000000000 -0500
27652 +++ linux-2.6.37/drivers/staging/pohmelfs/mcache.c 2011-01-17 02:41:01.000000000 -0500
27653 @@ -121,7 +121,7 @@ struct pohmelfs_mcache *pohmelfs_mcache_
27657 - m->gen = atomic_long_inc_return(&psb->mcache_gen);
27658 + m->gen = atomic_long_inc_return_unchecked(&psb->mcache_gen);
27660 mutex_lock(&psb->mcache_lock);
27661 err = pohmelfs_mcache_insert(psb, m);
27662 diff -urNp linux-2.6.37/drivers/staging/pohmelfs/netfs.h linux-2.6.37/drivers/staging/pohmelfs/netfs.h
27663 --- linux-2.6.37/drivers/staging/pohmelfs/netfs.h 2011-01-04 19:50:19.000000000 -0500
27664 +++ linux-2.6.37/drivers/staging/pohmelfs/netfs.h 2011-01-17 02:41:01.000000000 -0500
27665 @@ -571,7 +571,7 @@ struct pohmelfs_config;
27666 struct pohmelfs_sb {
27667 struct rb_root mcache_root;
27668 struct mutex mcache_lock;
27669 - atomic_long_t mcache_gen;
27670 + atomic_long_unchecked_t mcache_gen;
27671 unsigned long mcache_timeout;
27674 diff -urNp linux-2.6.37/drivers/staging/rtl8192u/ieee80211/proc.c linux-2.6.37/drivers/staging/rtl8192u/ieee80211/proc.c
27675 --- linux-2.6.37/drivers/staging/rtl8192u/ieee80211/proc.c 2011-01-04 19:50:19.000000000 -0500
27676 +++ linux-2.6.37/drivers/staging/rtl8192u/ieee80211/proc.c 2011-01-17 02:41:01.000000000 -0500
27677 @@ -99,7 +99,7 @@ static int crypto_info_open(struct inode
27678 return seq_open(file, &crypto_seq_ops);
27681 -static struct file_operations proc_crypto_ops = {
27682 +static const struct file_operations proc_crypto_ops = {
27683 .open = crypto_info_open,
27685 .llseek = seq_lseek,
27686 diff -urNp linux-2.6.37/drivers/staging/samsung-laptop/samsung-laptop.c linux-2.6.37/drivers/staging/samsung-laptop/samsung-laptop.c
27687 --- linux-2.6.37/drivers/staging/samsung-laptop/samsung-laptop.c 2011-01-04 19:50:19.000000000 -0500
27688 +++ linux-2.6.37/drivers/staging/samsung-laptop/samsung-laptop.c 2011-01-17 02:41:01.000000000 -0500
27689 @@ -269,7 +269,7 @@ static int update_status(struct backligh
27693 -static struct backlight_ops backlight_ops = {
27694 +static const struct backlight_ops backlight_ops = {
27695 .get_brightness = get_brightness,
27696 .update_status = update_status,
27698 diff -urNp linux-2.6.37/drivers/staging/spectra/ffsport.c linux-2.6.37/drivers/staging/spectra/ffsport.c
27699 --- linux-2.6.37/drivers/staging/spectra/ffsport.c 2011-01-04 19:50:19.000000000 -0500
27700 +++ linux-2.6.37/drivers/staging/spectra/ffsport.c 2011-01-17 02:41:01.000000000 -0500
27701 @@ -603,7 +603,7 @@ int GLOB_SBD_unlocked_ioctl(struct block
27705 -static struct block_device_operations GLOB_SBD_ops = {
27706 +static const struct block_device_operations GLOB_SBD_ops = {
27707 .owner = THIS_MODULE,
27708 .open = GLOB_SBD_open,
27709 .release = GLOB_SBD_release,
27710 diff -urNp linux-2.6.37/drivers/staging/vme/devices/vme_user.c linux-2.6.37/drivers/staging/vme/devices/vme_user.c
27711 --- linux-2.6.37/drivers/staging/vme/devices/vme_user.c 2011-01-04 19:50:19.000000000 -0500
27712 +++ linux-2.6.37/drivers/staging/vme/devices/vme_user.c 2011-01-17 02:41:01.000000000 -0500
27713 @@ -137,7 +137,7 @@ static long vme_user_unlocked_ioctl(stru
27714 static int __init vme_user_probe(struct device *, int, int);
27715 static int __exit vme_user_remove(struct device *, int, int);
27717 -static struct file_operations vme_user_fops = {
27718 +static const struct file_operations vme_user_fops = {
27719 .open = vme_user_open,
27720 .release = vme_user_release,
27721 .read = vme_user_read,
27722 diff -urNp linux-2.6.37/drivers/staging/westbridge/astoria/block/cyasblkdev_block.c linux-2.6.37/drivers/staging/westbridge/astoria/block/cyasblkdev_block.c
27723 --- linux-2.6.37/drivers/staging/westbridge/astoria/block/cyasblkdev_block.c 2011-01-04 19:50:19.000000000 -0500
27724 +++ linux-2.6.37/drivers/staging/westbridge/astoria/block/cyasblkdev_block.c 2011-01-17 02:41:01.000000000 -0500
27725 @@ -426,7 +426,7 @@ int cyasblkdev_revalidate_disk(struct ge
27728 /*standard block device driver interface */
27729 -static struct block_device_operations cyasblkdev_bdops = {
27730 +static const struct block_device_operations cyasblkdev_bdops = {
27731 .open = cyasblkdev_blk_open,
27732 .release = cyasblkdev_blk_release,
27733 .ioctl = cyasblkdev_blk_ioctl,
27734 diff -urNp linux-2.6.37/drivers/tty/n_gsm.c linux-2.6.37/drivers/tty/n_gsm.c
27735 --- linux-2.6.37/drivers/tty/n_gsm.c 2011-01-04 19:50:19.000000000 -0500
27736 +++ linux-2.6.37/drivers/tty/n_gsm.c 2011-01-17 02:41:01.000000000 -0500
27737 @@ -1579,7 +1579,7 @@ static struct gsm_dlci *gsm_dlci_alloc(s
27739 spin_lock_init(&dlci->lock);
27740 dlci->fifo = &dlci->_fifo;
27741 - if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
27742 + if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
27746 diff -urNp linux-2.6.37/drivers/tty/n_tty.c linux-2.6.37/drivers/tty/n_tty.c
27747 --- linux-2.6.37/drivers/tty/n_tty.c 2011-01-04 19:50:19.000000000 -0500
27748 +++ linux-2.6.37/drivers/tty/n_tty.c 2011-01-17 02:41:01.000000000 -0500
27749 @@ -2116,6 +2116,7 @@ void n_tty_inherit_ops(struct tty_ldisc_
27751 *ops = tty_ldisc_N_TTY;
27753 - ops->refcount = ops->flags = 0;
27754 + atomic_set(&ops->refcount, 0);
27757 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
27758 diff -urNp linux-2.6.37/drivers/tty/pty.c linux-2.6.37/drivers/tty/pty.c
27759 --- linux-2.6.37/drivers/tty/pty.c 2011-01-04 19:50:19.000000000 -0500
27760 +++ linux-2.6.37/drivers/tty/pty.c 2011-01-17 02:41:01.000000000 -0500
27761 @@ -700,7 +700,18 @@ out:
27765 -static struct file_operations ptmx_fops;
27766 +static const struct file_operations ptmx_fops = {
27767 + .llseek = no_llseek,
27768 + .read = tty_read,
27769 + .write = tty_write,
27770 + .poll = tty_poll,
27771 + .unlocked_ioctl = tty_ioctl,
27772 + .compat_ioctl = tty_compat_ioctl,
27773 + .open = ptmx_open,
27774 + .release = tty_release,
27775 + .fasync = tty_fasync,
27779 static void __init unix98_pty_init(void)
27781 @@ -753,10 +764,6 @@ static void __init unix98_pty_init(void)
27783 register_sysctl_table(pty_root_table);
27785 - /* Now create the /dev/ptmx special device */
27786 - tty_default_fops(&ptmx_fops);
27787 - ptmx_fops.open = ptmx_open;
27789 cdev_init(&ptmx_cdev, &ptmx_fops);
27790 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
27791 register_chrdev_region(MKDEV(TTYAUX_MAJOR, 2), 1, "/dev/ptmx") < 0)
27792 diff -urNp linux-2.6.37/drivers/tty/tty_io.c linux-2.6.37/drivers/tty/tty_io.c
27793 --- linux-2.6.37/drivers/tty/tty_io.c 2011-01-04 19:50:19.000000000 -0500
27794 +++ linux-2.6.37/drivers/tty/tty_io.c 2011-01-17 02:41:01.000000000 -0500
27795 @@ -140,21 +140,11 @@ EXPORT_SYMBOL(tty_mutex);
27796 /* Spinlock to protect the tty->tty_files list */
27797 DEFINE_SPINLOCK(tty_files_lock);
27799 -static ssize_t tty_read(struct file *, char __user *, size_t, loff_t *);
27800 -static ssize_t tty_write(struct file *, const char __user *, size_t, loff_t *);
27801 ssize_t redirected_tty_write(struct file *, const char __user *,
27803 -static unsigned int tty_poll(struct file *, poll_table *);
27804 static int tty_open(struct inode *, struct file *);
27805 long tty_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
27806 -#ifdef CONFIG_COMPAT
27807 -static long tty_compat_ioctl(struct file *file, unsigned int cmd,
27808 - unsigned long arg);
27810 -#define tty_compat_ioctl NULL
27812 static int __tty_fasync(int fd, struct file *filp, int on);
27813 -static int tty_fasync(int fd, struct file *filp, int on);
27814 static void release_tty(struct tty_struct *tty, int idx);
27815 static void __proc_set_tty(struct task_struct *tsk, struct tty_struct *tty);
27816 static void proc_set_tty(struct task_struct *tsk, struct tty_struct *tty);
27817 @@ -938,7 +928,7 @@ EXPORT_SYMBOL(start_tty);
27818 * read calls may be outstanding in parallel.
27821 -static ssize_t tty_read(struct file *file, char __user *buf, size_t count,
27822 +ssize_t tty_read(struct file *file, char __user *buf, size_t count,
27826 @@ -964,6 +954,8 @@ static ssize_t tty_read(struct file *fil
27830 +EXPORT_SYMBOL(tty_read);
27832 void tty_write_unlock(struct tty_struct *tty)
27834 mutex_unlock(&tty->atomic_write_lock);
27835 @@ -1113,7 +1105,7 @@ void tty_write_message(struct tty_struct
27836 * write method will not be invoked in parallel for each device.
27839 -static ssize_t tty_write(struct file *file, const char __user *buf,
27840 +ssize_t tty_write(struct file *file, const char __user *buf,
27841 size_t count, loff_t *ppos)
27843 struct inode *inode = file->f_path.dentry->d_inode;
27844 @@ -1139,6 +1131,8 @@ static ssize_t tty_write(struct file *fi
27848 +EXPORT_SYMBOL(tty_write);
27850 ssize_t redirected_tty_write(struct file *file, const char __user *buf,
27851 size_t count, loff_t *ppos)
27853 @@ -1778,6 +1772,8 @@ int tty_release(struct inode *inode, str
27857 +EXPORT_SYMBOL(tty_release);
27860 * tty_open - open a tty device
27861 * @inode: inode of device file
27862 @@ -1969,7 +1965,7 @@ got_driver:
27863 * may be re-entered freely by other callers.
27866 -static unsigned int tty_poll(struct file *filp, poll_table *wait)
27867 +unsigned int tty_poll(struct file *filp, poll_table *wait)
27869 struct tty_struct *tty = file_tty(filp);
27870 struct tty_ldisc *ld;
27871 @@ -1985,6 +1981,8 @@ static unsigned int tty_poll(struct file
27875 +EXPORT_SYMBOL(tty_poll);
27877 static int __tty_fasync(int fd, struct file *filp, int on)
27879 struct tty_struct *tty = file_tty(filp);
27880 @@ -2026,7 +2024,7 @@ out:
27884 -static int tty_fasync(int fd, struct file *filp, int on)
27885 +int tty_fasync(int fd, struct file *filp, int on)
27889 @@ -2035,6 +2033,8 @@ static int tty_fasync(int fd, struct fil
27893 +EXPORT_SYMBOL(tty_fasync);
27896 * tiocsti - fake input character
27897 * @tty: tty to fake input into
27898 @@ -2687,8 +2687,10 @@ long tty_ioctl(struct file *file, unsign
27902 +EXPORT_SYMBOL(tty_ioctl);
27904 #ifdef CONFIG_COMPAT
27905 -static long tty_compat_ioctl(struct file *file, unsigned int cmd,
27906 +long tty_compat_ioctl(struct file *file, unsigned int cmd,
27909 struct inode *inode = file->f_dentry->d_inode;
27910 @@ -2712,6 +2714,9 @@ static long tty_compat_ioctl(struct file
27915 +EXPORT_SYMBOL(tty_compat_ioctl);
27920 @@ -3190,11 +3195,6 @@ struct tty_struct *get_current_tty(void)
27922 EXPORT_SYMBOL_GPL(get_current_tty);
27924 -void tty_default_fops(struct file_operations *fops)
27926 - *fops = tty_fops;
27930 * Initialize the console device. This is called *early*, so
27931 * we can't necessarily depend on lots of kernel help here.
27932 diff -urNp linux-2.6.37/drivers/tty/tty_ldisc.c linux-2.6.37/drivers/tty/tty_ldisc.c
27933 --- linux-2.6.37/drivers/tty/tty_ldisc.c 2011-01-04 19:50:19.000000000 -0500
27934 +++ linux-2.6.37/drivers/tty/tty_ldisc.c 2011-01-17 02:41:01.000000000 -0500
27935 @@ -76,7 +76,7 @@ static void put_ldisc(struct tty_ldisc *
27936 if (atomic_dec_and_lock(&ld->users, &tty_ldisc_lock)) {
27937 struct tty_ldisc_ops *ldo = ld->ops;
27940 + atomic_dec(&ldo->refcount);
27941 module_put(ldo->owner);
27942 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
27944 @@ -111,7 +111,7 @@ int tty_register_ldisc(int disc, struct
27945 spin_lock_irqsave(&tty_ldisc_lock, flags);
27946 tty_ldiscs[disc] = new_ldisc;
27947 new_ldisc->num = disc;
27948 - new_ldisc->refcount = 0;
27949 + atomic_set(&new_ldisc->refcount, 0);
27950 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
27953 @@ -139,7 +139,7 @@ int tty_unregister_ldisc(int disc)
27956 spin_lock_irqsave(&tty_ldisc_lock, flags);
27957 - if (tty_ldiscs[disc]->refcount)
27958 + if (atomic_read(&tty_ldiscs[disc]->refcount))
27961 tty_ldiscs[disc] = NULL;
27962 @@ -160,7 +160,7 @@ static struct tty_ldisc_ops *get_ldops(i
27964 ret = ERR_PTR(-EAGAIN);
27965 if (try_module_get(ldops->owner)) {
27966 - ldops->refcount++;
27967 + atomic_inc(&ldops->refcount);
27971 @@ -173,7 +173,7 @@ static void put_ldops(struct tty_ldisc_o
27972 unsigned long flags;
27974 spin_lock_irqsave(&tty_ldisc_lock, flags);
27975 - ldops->refcount--;
27976 + atomic_dec(&ldops->refcount);
27977 module_put(ldops->owner);
27978 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
27980 diff -urNp linux-2.6.37/drivers/tty/vt/keyboard.c linux-2.6.37/drivers/tty/vt/keyboard.c
27981 --- linux-2.6.37/drivers/tty/vt/keyboard.c 2011-01-04 19:50:19.000000000 -0500
27982 +++ linux-2.6.37/drivers/tty/vt/keyboard.c 2011-01-17 02:41:01.000000000 -0500
27983 @@ -657,6 +657,16 @@ static void k_spec(struct vc_data *vc, u
27984 kbd->kbdmode == VC_MEDIUMRAW) &&
27985 value != KVAL(K_SAK))
27986 return; /* SAK is allowed even in raw mode */
27988 +#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
27990 + void *func = fn_handler[value];
27991 + if (func == fn_show_state || func == fn_show_ptregs ||
27992 + func == fn_show_mem)
27997 fn_handler[value](vc);
28000 @@ -1413,7 +1423,7 @@ static const struct input_device_id kbd_
28001 .evbit = { BIT_MASK(EV_SND) },
28004 - { }, /* Terminating entry */
28005 + { 0 }, /* Terminating entry */
28008 MODULE_DEVICE_TABLE(input, kbd_ids);
28009 diff -urNp linux-2.6.37/drivers/tty/vt/vt_ioctl.c linux-2.6.37/drivers/tty/vt/vt_ioctl.c
28010 --- linux-2.6.37/drivers/tty/vt/vt_ioctl.c 2011-01-04 19:50:19.000000000 -0500
28011 +++ linux-2.6.37/drivers/tty/vt/vt_ioctl.c 2011-01-17 02:41:01.000000000 -0500
28012 @@ -210,9 +210,6 @@ do_kdsk_ioctl(int cmd, struct kbentry __
28013 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
28016 - if (!capable(CAP_SYS_TTY_CONFIG))
28021 key_map = key_maps[s];
28022 @@ -224,6 +221,9 @@ do_kdsk_ioctl(int cmd, struct kbentry __
28023 val = (i ? K_HOLE : K_NOSUCHMAP);
28024 return put_user(val, &user_kbe->kb_value);
28026 + if (!capable(CAP_SYS_TTY_CONFIG))
28031 if (!i && v == K_NOSUCHMAP) {
28032 @@ -325,9 +325,6 @@ do_kdgkb_ioctl(int cmd, struct kbsentry
28036 - if (!capable(CAP_SYS_TTY_CONFIG))
28039 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
28042 @@ -361,6 +358,9 @@ do_kdgkb_ioctl(int cmd, struct kbsentry
28044 return ((p && *p) ? -EOVERFLOW : 0);
28046 + if (!capable(CAP_SYS_TTY_CONFIG))
28052 diff -urNp linux-2.6.37/drivers/usb/atm/cxacru.c linux-2.6.37/drivers/usb/atm/cxacru.c
28053 --- linux-2.6.37/drivers/usb/atm/cxacru.c 2011-01-04 19:50:19.000000000 -0500
28054 +++ linux-2.6.37/drivers/usb/atm/cxacru.c 2011-01-17 02:41:01.000000000 -0500
28055 @@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_c
28056 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
28059 - if (index < 0 || index > 0x7f)
28060 + if (index > 0x7f)
28064 diff -urNp linux-2.6.37/drivers/usb/atm/usbatm.c linux-2.6.37/drivers/usb/atm/usbatm.c
28065 --- linux-2.6.37/drivers/usb/atm/usbatm.c 2011-01-04 19:50:19.000000000 -0500
28066 +++ linux-2.6.37/drivers/usb/atm/usbatm.c 2011-01-17 02:41:01.000000000 -0500
28067 @@ -332,7 +332,7 @@ static void usbatm_extract_one_cell(stru
28068 if (printk_ratelimit())
28069 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
28070 __func__, vpi, vci);
28071 - atomic_inc(&vcc->stats->rx_err);
28072 + atomic_inc_unchecked(&vcc->stats->rx_err);
28076 @@ -360,7 +360,7 @@ static void usbatm_extract_one_cell(stru
28077 if (length > ATM_MAX_AAL5_PDU) {
28078 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
28079 __func__, length, vcc);
28080 - atomic_inc(&vcc->stats->rx_err);
28081 + atomic_inc_unchecked(&vcc->stats->rx_err);
28085 @@ -369,14 +369,14 @@ static void usbatm_extract_one_cell(stru
28086 if (sarb->len < pdu_length) {
28087 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
28088 __func__, pdu_length, sarb->len, vcc);
28089 - atomic_inc(&vcc->stats->rx_err);
28090 + atomic_inc_unchecked(&vcc->stats->rx_err);
28094 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
28095 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
28097 - atomic_inc(&vcc->stats->rx_err);
28098 + atomic_inc_unchecked(&vcc->stats->rx_err);
28102 @@ -386,7 +386,7 @@ static void usbatm_extract_one_cell(stru
28103 if (printk_ratelimit())
28104 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
28106 - atomic_inc(&vcc->stats->rx_drop);
28107 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28111 @@ -411,7 +411,7 @@ static void usbatm_extract_one_cell(stru
28113 vcc->push(vcc, skb);
28115 - atomic_inc(&vcc->stats->rx);
28116 + atomic_inc_unchecked(&vcc->stats->rx);
28120 @@ -614,7 +614,7 @@ static void usbatm_tx_process(unsigned l
28121 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
28123 usbatm_pop(vcc, skb);
28124 - atomic_inc(&vcc->stats->tx);
28125 + atomic_inc_unchecked(&vcc->stats->tx);
28127 skb = skb_dequeue(&instance->sndqueue);
28129 @@ -773,11 +773,11 @@ static int usbatm_atm_proc_read(struct a
28131 return sprintf(page,
28132 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
28133 - atomic_read(&atm_dev->stats.aal5.tx),
28134 - atomic_read(&atm_dev->stats.aal5.tx_err),
28135 - atomic_read(&atm_dev->stats.aal5.rx),
28136 - atomic_read(&atm_dev->stats.aal5.rx_err),
28137 - atomic_read(&atm_dev->stats.aal5.rx_drop));
28138 + atomic_read_unchecked(&atm_dev->stats.aal5.tx),
28139 + atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
28140 + atomic_read_unchecked(&atm_dev->stats.aal5.rx),
28141 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
28142 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
28145 if (instance->disconnected)
28146 diff -urNp linux-2.6.37/drivers/usb/class/cdc-acm.c linux-2.6.37/drivers/usb/class/cdc-acm.c
28147 --- linux-2.6.37/drivers/usb/class/cdc-acm.c 2011-01-04 19:50:19.000000000 -0500
28148 +++ linux-2.6.37/drivers/usb/class/cdc-acm.c 2011-01-17 02:41:01.000000000 -0500
28149 @@ -1634,7 +1634,7 @@ static const struct usb_device_id acm_id
28150 { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM,
28151 USB_CDC_ACM_PROTO_AT_CDMA) },
28154 + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
28157 MODULE_DEVICE_TABLE(usb, acm_ids);
28158 diff -urNp linux-2.6.37/drivers/usb/class/cdc-wdm.c linux-2.6.37/drivers/usb/class/cdc-wdm.c
28159 --- linux-2.6.37/drivers/usb/class/cdc-wdm.c 2011-01-04 19:50:19.000000000 -0500
28160 +++ linux-2.6.37/drivers/usb/class/cdc-wdm.c 2011-01-17 02:41:01.000000000 -0500
28161 @@ -342,7 +342,7 @@ static ssize_t wdm_write
28165 - if (!file->f_flags && O_NONBLOCK)
28166 + if (!(file->f_flags & O_NONBLOCK))
28167 r = wait_event_interruptible(desc->wait, !test_bit(WDM_IN_USE,
28170 diff -urNp linux-2.6.37/drivers/usb/class/usblp.c linux-2.6.37/drivers/usb/class/usblp.c
28171 --- linux-2.6.37/drivers/usb/class/usblp.c 2011-01-04 19:50:19.000000000 -0500
28172 +++ linux-2.6.37/drivers/usb/class/usblp.c 2011-01-17 02:41:01.000000000 -0500
28173 @@ -227,7 +227,7 @@ static const struct quirk_printer_struct
28174 { 0x0482, 0x0010, USBLP_QUIRK_BIDIR }, /* Kyocera Mita FS 820, by zut <kernel@zut.de> */
28175 { 0x04f9, 0x000d, USBLP_QUIRK_BIDIR }, /* Brother Industries, Ltd HL-1440 Laser Printer */
28176 { 0x04b8, 0x0202, USBLP_QUIRK_BAD_CLASS }, /* Seiko Epson Receipt Printer M129C */
28181 static int usblp_wwait(struct usblp *usblp, int nonblock);
28182 @@ -1398,7 +1398,7 @@ static const struct usb_device_id usblp_
28183 { USB_INTERFACE_INFO(7, 1, 2) },
28184 { USB_INTERFACE_INFO(7, 1, 3) },
28185 { USB_DEVICE(0x04b8, 0x0202) }, /* Seiko Epson Receipt Printer M129C */
28186 - { } /* Terminating entry */
28187 + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } /* Terminating entry */
28190 MODULE_DEVICE_TABLE(usb, usblp_ids);
28191 diff -urNp linux-2.6.37/drivers/usb/core/hcd.c linux-2.6.37/drivers/usb/core/hcd.c
28192 --- linux-2.6.37/drivers/usb/core/hcd.c 2011-01-04 19:50:19.000000000 -0500
28193 +++ linux-2.6.37/drivers/usb/core/hcd.c 2011-01-17 02:41:01.000000000 -0500
28194 @@ -2431,7 +2431,7 @@ EXPORT_SYMBOL_GPL(usb_hcd_platform_shutd
28196 #if defined(CONFIG_USB_MON) || defined(CONFIG_USB_MON_MODULE)
28198 -struct usb_mon_operations *mon_ops;
28199 +const struct usb_mon_operations *mon_ops;
28202 * The registration is unlocked.
28203 @@ -2441,7 +2441,7 @@ struct usb_mon_operations *mon_ops;
28204 * symbols from usbcore, usbcore gets referenced and cannot be unloaded first.
28207 -int usb_mon_register (struct usb_mon_operations *ops)
28208 +int usb_mon_register (const struct usb_mon_operations *ops)
28212 diff -urNp linux-2.6.37/drivers/usb/core/hub.c linux-2.6.37/drivers/usb/core/hub.c
28213 --- linux-2.6.37/drivers/usb/core/hub.c 2011-01-04 19:50:19.000000000 -0500
28214 +++ linux-2.6.37/drivers/usb/core/hub.c 2011-01-17 02:41:01.000000000 -0500
28215 @@ -3461,7 +3461,7 @@ static const struct usb_device_id hub_id
28216 .bDeviceClass = USB_CLASS_HUB},
28217 { .match_flags = USB_DEVICE_ID_MATCH_INT_CLASS,
28218 .bInterfaceClass = USB_CLASS_HUB},
28219 - { } /* Terminating entry */
28220 + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } /* Terminating entry */
28223 MODULE_DEVICE_TABLE (usb, hub_id_table);
28224 diff -urNp linux-2.6.37/drivers/usb/core/message.c linux-2.6.37/drivers/usb/core/message.c
28225 --- linux-2.6.37/drivers/usb/core/message.c 2011-01-04 19:50:19.000000000 -0500
28226 +++ linux-2.6.37/drivers/usb/core/message.c 2011-01-17 02:41:01.000000000 -0500
28227 @@ -869,8 +869,8 @@ char *usb_cache_string(struct usb_device
28228 buf = kmalloc(MAX_USB_STRING_SIZE, GFP_NOIO);
28230 len = usb_string(udev, index, buf, MAX_USB_STRING_SIZE);
28232 - smallbuf = kmalloc(++len, GFP_NOIO);
28234 + smallbuf = kmalloc(len, GFP_NOIO);
28237 memcpy(smallbuf, buf, len);
28238 diff -urNp linux-2.6.37/drivers/usb/early/ehci-dbgp.c linux-2.6.37/drivers/usb/early/ehci-dbgp.c
28239 --- linux-2.6.37/drivers/usb/early/ehci-dbgp.c 2011-01-04 19:50:19.000000000 -0500
28240 +++ linux-2.6.37/drivers/usb/early/ehci-dbgp.c 2011-01-17 02:41:01.000000000 -0500
28241 @@ -96,6 +96,7 @@ static inline u32 dbgp_len_update(u32 x,
28245 +/* cannot be const, see kgdbdbgp_parse_config */
28246 static struct kgdb_io kgdbdbgp_io_ops;
28247 #define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
28249 @@ -1026,6 +1027,7 @@ static void kgdbdbgp_write_char(u8 chr)
28250 early_dbgp_write(NULL, &chr, 1);
28253 +/* cannot be const, see kgdbdbgp_parse_config() */
28254 static struct kgdb_io kgdbdbgp_io_ops = {
28255 .name = "kgdbdbgp",
28256 .read_char = kgdbdbgp_read_char,
28257 diff -urNp linux-2.6.37/drivers/usb/host/ehci-pci.c linux-2.6.37/drivers/usb/host/ehci-pci.c
28258 --- linux-2.6.37/drivers/usb/host/ehci-pci.c 2011-01-04 19:50:19.000000000 -0500
28259 +++ linux-2.6.37/drivers/usb/host/ehci-pci.c 2011-01-17 02:41:01.000000000 -0500
28260 @@ -470,7 +470,7 @@ static const struct pci_device_id pci_id
28261 PCI_DEVICE_CLASS(PCI_CLASS_SERIAL_USB_EHCI, ~0),
28262 .driver_data = (unsigned long) &ehci_pci_hc_driver,
28264 - { /* end: all zeroes */ }
28265 + { 0, 0, 0, 0, 0, 0, 0 }
28267 MODULE_DEVICE_TABLE(pci, pci_ids);
28269 diff -urNp linux-2.6.37/drivers/usb/host/uhci-hcd.c linux-2.6.37/drivers/usb/host/uhci-hcd.c
28270 --- linux-2.6.37/drivers/usb/host/uhci-hcd.c 2011-01-04 19:50:19.000000000 -0500
28271 +++ linux-2.6.37/drivers/usb/host/uhci-hcd.c 2011-01-17 02:41:01.000000000 -0500
28272 @@ -948,7 +948,7 @@ static const struct pci_device_id uhci_p
28273 /* handle any USB UHCI controller */
28274 PCI_DEVICE_CLASS(PCI_CLASS_SERIAL_USB_UHCI, ~0),
28275 .driver_data = (unsigned long) &uhci_driver,
28276 - }, { /* end: all zeroes */ }
28277 + }, { 0, 0, 0, 0, 0, 0, 0 }
28280 MODULE_DEVICE_TABLE(pci, uhci_pci_ids);
28281 diff -urNp linux-2.6.37/drivers/usb/mon/mon_main.c linux-2.6.37/drivers/usb/mon/mon_main.c
28282 --- linux-2.6.37/drivers/usb/mon/mon_main.c 2011-01-04 19:50:19.000000000 -0500
28283 +++ linux-2.6.37/drivers/usb/mon/mon_main.c 2011-01-17 02:41:01.000000000 -0500
28284 @@ -238,7 +238,7 @@ static struct notifier_block mon_nb = {
28288 -static struct usb_mon_operations mon_ops_0 = {
28289 +static const struct usb_mon_operations mon_ops_0 = {
28290 .urb_submit = mon_submit,
28291 .urb_submit_error = mon_submit_error,
28292 .urb_complete = mon_complete,
28293 diff -urNp linux-2.6.37/drivers/usb/storage/debug.h linux-2.6.37/drivers/usb/storage/debug.h
28294 --- linux-2.6.37/drivers/usb/storage/debug.h 2011-01-04 19:50:19.000000000 -0500
28295 +++ linux-2.6.37/drivers/usb/storage/debug.h 2011-01-17 02:41:01.000000000 -0500
28296 @@ -54,9 +54,9 @@ void usb_stor_show_sense( unsigned char
28297 #define US_DEBUGPX(x...) printk( x )
28298 #define US_DEBUG(x) x
28300 -#define US_DEBUGP(x...)
28301 -#define US_DEBUGPX(x...)
28302 -#define US_DEBUG(x)
28303 +#define US_DEBUGP(x...) do {} while (0)
28304 +#define US_DEBUGPX(x...) do {} while (0)
28305 +#define US_DEBUG(x) do {} while (0)
28309 diff -urNp linux-2.6.37/drivers/usb/storage/usb.c linux-2.6.37/drivers/usb/storage/usb.c
28310 --- linux-2.6.37/drivers/usb/storage/usb.c 2011-01-04 19:50:19.000000000 -0500
28311 +++ linux-2.6.37/drivers/usb/storage/usb.c 2011-01-17 02:41:01.000000000 -0500
28312 @@ -122,7 +122,7 @@ MODULE_PARM_DESC(quirks, "supplemental l
28314 static struct us_unusual_dev us_unusual_dev_list[] = {
28315 # include "unusual_devs.h"
28316 - { } /* Terminating entry */
28317 + { NULL, NULL, 0, 0, NULL } /* Terminating entry */
28321 diff -urNp linux-2.6.37/drivers/usb/storage/usual-tables.c linux-2.6.37/drivers/usb/storage/usual-tables.c
28322 --- linux-2.6.37/drivers/usb/storage/usual-tables.c 2011-01-04 19:50:19.000000000 -0500
28323 +++ linux-2.6.37/drivers/usb/storage/usual-tables.c 2011-01-17 02:41:01.000000000 -0500
28326 struct usb_device_id usb_storage_usb_ids[] = {
28327 # include "unusual_devs.h"
28328 - { } /* Terminating entry */
28329 + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } /* Terminating entry */
28331 EXPORT_SYMBOL_GPL(usb_storage_usb_ids);
28333 diff -urNp linux-2.6.37/drivers/vhost/vhost.c linux-2.6.37/drivers/vhost/vhost.c
28334 --- linux-2.6.37/drivers/vhost/vhost.c 2011-01-04 19:50:19.000000000 -0500
28335 +++ linux-2.6.37/drivers/vhost/vhost.c 2011-01-17 02:41:01.000000000 -0500
28336 @@ -560,7 +560,7 @@ static int init_used(struct vhost_virtqu
28337 return get_user(vq->last_used_idx, &used->idx);
28340 -static long vhost_set_vring(struct vhost_dev *d, int ioctl, void __user *argp)
28341 +static long vhost_set_vring(struct vhost_dev *d, unsigned int ioctl, void __user *argp)
28343 struct file *eventfp, *filep = NULL,
28344 *pollstart = NULL, *pollstop = NULL;
28345 diff -urNp linux-2.6.37/drivers/video/atmel_lcdfb.c linux-2.6.37/drivers/video/atmel_lcdfb.c
28346 --- linux-2.6.37/drivers/video/atmel_lcdfb.c 2011-01-04 19:50:19.000000000 -0500
28347 +++ linux-2.6.37/drivers/video/atmel_lcdfb.c 2011-01-17 02:41:01.000000000 -0500
28348 @@ -111,7 +111,7 @@ static int atmel_bl_get_brightness(struc
28349 return lcdc_readl(sinfo, ATMEL_LCDC_CONTRAST_VAL);
28352 -static struct backlight_ops atmel_lcdc_bl_ops = {
28353 +static const struct backlight_ops atmel_lcdc_bl_ops = {
28354 .update_status = atmel_bl_update_status,
28355 .get_brightness = atmel_bl_get_brightness,
28357 diff -urNp linux-2.6.37/drivers/video/aty/aty128fb.c linux-2.6.37/drivers/video/aty/aty128fb.c
28358 --- linux-2.6.37/drivers/video/aty/aty128fb.c 2011-01-04 19:50:19.000000000 -0500
28359 +++ linux-2.6.37/drivers/video/aty/aty128fb.c 2011-01-17 02:41:01.000000000 -0500
28360 @@ -1786,7 +1786,7 @@ static int aty128_bl_get_brightness(stru
28361 return bd->props.brightness;
28364 -static struct backlight_ops aty128_bl_data = {
28365 +static const struct backlight_ops aty128_bl_data = {
28366 .get_brightness = aty128_bl_get_brightness,
28367 .update_status = aty128_bl_update_status,
28369 diff -urNp linux-2.6.37/drivers/video/aty/atyfb_base.c linux-2.6.37/drivers/video/aty/atyfb_base.c
28370 --- linux-2.6.37/drivers/video/aty/atyfb_base.c 2011-01-04 19:50:19.000000000 -0500
28371 +++ linux-2.6.37/drivers/video/aty/atyfb_base.c 2011-01-17 02:41:01.000000000 -0500
28372 @@ -2221,7 +2221,7 @@ static int aty_bl_get_brightness(struct
28373 return bd->props.brightness;
28376 -static struct backlight_ops aty_bl_data = {
28377 +static const struct backlight_ops aty_bl_data = {
28378 .get_brightness = aty_bl_get_brightness,
28379 .update_status = aty_bl_update_status,
28381 diff -urNp linux-2.6.37/drivers/video/aty/radeon_backlight.c linux-2.6.37/drivers/video/aty/radeon_backlight.c
28382 --- linux-2.6.37/drivers/video/aty/radeon_backlight.c 2011-01-04 19:50:19.000000000 -0500
28383 +++ linux-2.6.37/drivers/video/aty/radeon_backlight.c 2011-01-17 02:41:01.000000000 -0500
28384 @@ -128,7 +128,7 @@ static int radeon_bl_get_brightness(stru
28385 return bd->props.brightness;
28388 -static struct backlight_ops radeon_bl_data = {
28389 +static const struct backlight_ops radeon_bl_data = {
28390 .get_brightness = radeon_bl_get_brightness,
28391 .update_status = radeon_bl_update_status,
28393 diff -urNp linux-2.6.37/drivers/video/backlight/88pm860x_bl.c linux-2.6.37/drivers/video/backlight/88pm860x_bl.c
28394 --- linux-2.6.37/drivers/video/backlight/88pm860x_bl.c 2011-01-04 19:50:19.000000000 -0500
28395 +++ linux-2.6.37/drivers/video/backlight/88pm860x_bl.c 2011-01-17 02:41:01.000000000 -0500
28396 @@ -155,7 +155,7 @@ out:
28400 -static struct backlight_ops pm860x_backlight_ops = {
28401 +static const struct backlight_ops pm860x_backlight_ops = {
28402 .options = BL_CORE_SUSPENDRESUME,
28403 .update_status = pm860x_backlight_update_status,
28404 .get_brightness = pm860x_backlight_get_brightness,
28405 diff -urNp linux-2.6.37/drivers/video/backlight/max8925_bl.c linux-2.6.37/drivers/video/backlight/max8925_bl.c
28406 --- linux-2.6.37/drivers/video/backlight/max8925_bl.c 2011-01-04 19:50:19.000000000 -0500
28407 +++ linux-2.6.37/drivers/video/backlight/max8925_bl.c 2011-01-17 02:41:01.000000000 -0500
28408 @@ -92,7 +92,7 @@ static int max8925_backlight_get_brightn
28412 -static struct backlight_ops max8925_backlight_ops = {
28413 +static const struct backlight_ops max8925_backlight_ops = {
28414 .options = BL_CORE_SUSPENDRESUME,
28415 .update_status = max8925_backlight_update_status,
28416 .get_brightness = max8925_backlight_get_brightness,
28417 diff -urNp linux-2.6.37/drivers/video/fbcmap.c linux-2.6.37/drivers/video/fbcmap.c
28418 --- linux-2.6.37/drivers/video/fbcmap.c 2011-01-04 19:50:19.000000000 -0500
28419 +++ linux-2.6.37/drivers/video/fbcmap.c 2011-01-17 02:41:01.000000000 -0500
28420 @@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user
28424 - if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
28425 - !info->fbops->fb_setcmap)) {
28426 + if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
28430 diff -urNp linux-2.6.37/drivers/video/fbmem.c linux-2.6.37/drivers/video/fbmem.c
28431 --- linux-2.6.37/drivers/video/fbmem.c 2011-01-04 19:50:19.000000000 -0500
28432 +++ linux-2.6.37/drivers/video/fbmem.c 2011-01-17 02:41:01.000000000 -0500
28433 @@ -403,7 +403,7 @@ static void fb_do_show_logo(struct fb_in
28434 image->dx += image->width + 8;
28436 } else if (rotate == FB_ROTATE_UD) {
28437 - for (x = 0; x < num && image->dx >= 0; x++) {
28438 + for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
28439 info->fbops->fb_imageblit(info, image);
28440 image->dx -= image->width + 8;
28442 @@ -415,7 +415,7 @@ static void fb_do_show_logo(struct fb_in
28443 image->dy += image->height + 8;
28445 } else if (rotate == FB_ROTATE_CCW) {
28446 - for (x = 0; x < num && image->dy >= 0; x++) {
28447 + for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
28448 info->fbops->fb_imageblit(info, image);
28449 image->dy -= image->height + 8;
28451 @@ -1101,7 +1101,7 @@ static long do_fb_ioctl(struct fb_info *
28453 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
28455 - if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
28456 + if (con2fb.framebuffer >= FB_MAX)
28458 if (!registered_fb[con2fb.framebuffer])
28459 request_module("fb%d", con2fb.framebuffer);
28460 diff -urNp linux-2.6.37/drivers/video/fbmon.c linux-2.6.37/drivers/video/fbmon.c
28461 --- linux-2.6.37/drivers/video/fbmon.c 2011-01-04 19:50:19.000000000 -0500
28462 +++ linux-2.6.37/drivers/video/fbmon.c 2011-01-17 02:41:01.000000000 -0500
28465 #define DPRINTK(fmt, args...) printk(fmt,## args)
28467 -#define DPRINTK(fmt, args...)
28468 +#define DPRINTK(fmt, args...) do {} while (0)
28471 #define FBMON_FIX_HEADER 1
28472 diff -urNp linux-2.6.37/drivers/video/i810/i810_accel.c linux-2.6.37/drivers/video/i810/i810_accel.c
28473 --- linux-2.6.37/drivers/video/i810/i810_accel.c 2011-01-04 19:50:19.000000000 -0500
28474 +++ linux-2.6.37/drivers/video/i810/i810_accel.c 2011-01-17 02:41:01.000000000 -0500
28475 @@ -73,6 +73,7 @@ static inline int wait_for_space(struct
28478 printk("ringbuffer lockup!!!\n");
28479 + printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
28480 i810_report_error(mmio);
28481 par->dev_flags |= LOCKUP;
28482 info->pixmap.scan_align = 1;
28483 diff -urNp linux-2.6.37/drivers/video/i810/i810_main.c linux-2.6.37/drivers/video/i810/i810_main.c
28484 --- linux-2.6.37/drivers/video/i810/i810_main.c 2011-01-04 19:50:19.000000000 -0500
28485 +++ linux-2.6.37/drivers/video/i810/i810_main.c 2011-01-17 02:41:01.000000000 -0500
28486 @@ -120,7 +120,7 @@ static struct pci_device_id i810fb_pci_t
28487 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 4 },
28488 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82815_CGC,
28489 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 5 },
28491 + { 0, 0, 0, 0, 0, 0, 0 },
28494 static struct pci_driver i810fb_driver = {
28495 diff -urNp linux-2.6.37/drivers/video/modedb.c linux-2.6.37/drivers/video/modedb.c
28496 --- linux-2.6.37/drivers/video/modedb.c 2011-01-04 19:50:19.000000000 -0500
28497 +++ linux-2.6.37/drivers/video/modedb.c 2011-01-17 02:41:01.000000000 -0500
28498 @@ -40,240 +40,240 @@ static const struct fb_videomode modedb[
28500 /* 640x400 @ 70 Hz, 31.5 kHz hsync */
28501 NULL, 70, 640, 400, 39721, 40, 24, 39, 9, 96, 2,
28502 - 0, FB_VMODE_NONINTERLACED
28503 + 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
28505 /* 640x480 @ 60 Hz, 31.5 kHz hsync */
28506 NULL, 60, 640, 480, 39721, 40, 24, 32, 11, 96, 2,
28507 - 0, FB_VMODE_NONINTERLACED
28508 + 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
28510 /* 800x600 @ 56 Hz, 35.15 kHz hsync */
28511 NULL, 56, 800, 600, 27777, 128, 24, 22, 1, 72, 2,
28512 - 0, FB_VMODE_NONINTERLACED
28513 + 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
28515 /* 1024x768 @ 87 Hz interlaced, 35.5 kHz hsync */
28516 NULL, 87, 1024, 768, 22271, 56, 24, 33, 8, 160, 8,
28517 - 0, FB_VMODE_INTERLACED
28518 + 0, FB_VMODE_INTERLACED, FB_MODE_IS_UNKNOWN
28520 /* 640x400 @ 85 Hz, 37.86 kHz hsync */
28521 NULL, 85, 640, 400, 31746, 96, 32, 41, 1, 64, 3,
28522 - FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
28523 + FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
28525 /* 640x480 @ 72 Hz, 36.5 kHz hsync */
28526 NULL, 72, 640, 480, 31746, 144, 40, 30, 8, 40, 3,
28527 - 0, FB_VMODE_NONINTERLACED
28528 + 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
28530 /* 640x480 @ 75 Hz, 37.50 kHz hsync */
28531 NULL, 75, 640, 480, 31746, 120, 16, 16, 1, 64, 3,
28532 - 0, FB_VMODE_NONINTERLACED
28533 + 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
28535 /* 800x600 @ 60 Hz, 37.8 kHz hsync */
28536 NULL, 60, 800, 600, 25000, 88, 40, 23, 1, 128, 4,
28537 - FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
28538 + FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
28540 /* 640x480 @ 85 Hz, 43.27 kHz hsync */
28541 NULL, 85, 640, 480, 27777, 80, 56, 25, 1, 56, 3,
28542 - 0, FB_VMODE_NONINTERLACED
28543 + 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
28545 /* 1152x864 @ 89 Hz interlaced, 44 kHz hsync */
28546 NULL, 89, 1152, 864, 15384, 96, 16, 110, 1, 216, 10,
28547 - 0, FB_VMODE_INTERLACED
28548 + 0, FB_VMODE_INTERLACED, FB_MODE_IS_UNKNOWN
28550 /* 800x600 @ 72 Hz, 48.0 kHz hsync */
28551 NULL, 72, 800, 600, 20000, 64, 56, 23, 37, 120, 6,
28552 - FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
28553 + FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
28555 /* 1024x768 @ 60 Hz, 48.4 kHz hsync */
28556 NULL, 60, 1024, 768, 15384, 168, 8, 29, 3, 144, 6,
28557 - 0, FB_VMODE_NONINTERLACED
28558 + 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
28560 /* 640x480 @ 100 Hz, 53.01 kHz hsync */
28561 NULL, 100, 640, 480, 21834, 96, 32, 36, 8, 96, 6,
28562 - 0, FB_VMODE_NONINTERLACED
28563 + 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
28565 /* 1152x864 @ 60 Hz, 53.5 kHz hsync */
28566 NULL, 60, 1152, 864, 11123, 208, 64, 16, 4, 256, 8,
28567 - 0, FB_VMODE_NONINTERLACED
28568 + 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
28570 /* 800x600 @ 85 Hz, 55.84 kHz hsync */
28571 NULL, 85, 800, 600, 16460, 160, 64, 36, 16, 64, 5,
28572 - 0, FB_VMODE_NONINTERLACED
28573 + 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
28575 /* 1024x768 @ 70 Hz, 56.5 kHz hsync */
28576 NULL, 70, 1024, 768, 13333, 144, 24, 29, 3, 136, 6,
28577 - 0, FB_VMODE_NONINTERLACED
28578 + 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
28580 /* 1280x1024 @ 87 Hz interlaced, 51 kHz hsync */
28581 NULL, 87, 1280, 1024, 12500, 56, 16, 128, 1, 216, 12,
28582 - 0, FB_VMODE_INTERLACED
28583 + 0, FB_VMODE_INTERLACED, FB_MODE_IS_UNKNOWN
28585 /* 800x600 @ 100 Hz, 64.02 kHz hsync */
28586 NULL, 100, 800, 600, 14357, 160, 64, 30, 4, 64, 6,
28587 - 0, FB_VMODE_NONINTERLACED
28588 + 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
28590 /* 1024x768 @ 76 Hz, 62.5 kHz hsync */
28591 NULL, 76, 1024, 768, 11764, 208, 8, 36, 16, 120, 3,
28592 - 0, FB_VMODE_NONINTERLACED
28593 + 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
28595 /* 1152x864 @ 70 Hz, 62.4 kHz hsync */
28596 NULL, 70, 1152, 864, 10869, 106, 56, 20, 1, 160, 10,
28597 - 0, FB_VMODE_NONINTERLACED
28598 + 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
28600 /* 1280x1024 @ 61 Hz, 64.2 kHz hsync */
28601 NULL, 61, 1280, 1024, 9090, 200, 48, 26, 1, 184, 3,
28602 - 0, FB_VMODE_NONINTERLACED
28603 + 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
28605 /* 1400x1050 @ 60Hz, 63.9 kHz hsync */
28606 NULL, 60, 1400, 1050, 9259, 136, 40, 13, 1, 112, 3,
28607 - 0, FB_VMODE_NONINTERLACED
28608 + 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
28610 /* 1400x1050 @ 75,107 Hz, 82,392 kHz +hsync +vsync*/
28611 NULL, 75, 1400, 1050, 7190, 120, 56, 23, 10, 112, 13,
28612 - FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
28613 + FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
28615 /* 1400x1050 @ 60 Hz, ? kHz +hsync +vsync*/
28616 NULL, 60, 1400, 1050, 9259, 128, 40, 12, 0, 112, 3,
28617 - FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
28618 + FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
28620 /* 1024x768 @ 85 Hz, 70.24 kHz hsync */
28621 NULL, 85, 1024, 768, 10111, 192, 32, 34, 14, 160, 6,
28622 - 0, FB_VMODE_NONINTERLACED
28623 + 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
28625 /* 1152x864 @ 78 Hz, 70.8 kHz hsync */
28626 NULL, 78, 1152, 864, 9090, 228, 88, 32, 0, 84, 12,
28627 - 0, FB_VMODE_NONINTERLACED
28628 + 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
28630 /* 1280x1024 @ 70 Hz, 74.59 kHz hsync */
28631 NULL, 70, 1280, 1024, 7905, 224, 32, 28, 8, 160, 8,
28632 - 0, FB_VMODE_NONINTERLACED
28633 + 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
28635 /* 1600x1200 @ 60Hz, 75.00 kHz hsync */
28636 NULL, 60, 1600, 1200, 6172, 304, 64, 46, 1, 192, 3,
28637 - FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
28638 + FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
28640 /* 1152x864 @ 84 Hz, 76.0 kHz hsync */
28641 NULL, 84, 1152, 864, 7407, 184, 312, 32, 0, 128, 12,
28642 - 0, FB_VMODE_NONINTERLACED
28643 + 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
28645 /* 1280x1024 @ 74 Hz, 78.85 kHz hsync */
28646 NULL, 74, 1280, 1024, 7407, 256, 32, 34, 3, 144, 3,
28647 - 0, FB_VMODE_NONINTERLACED
28648 + 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
28650 /* 1024x768 @ 100Hz, 80.21 kHz hsync */
28651 NULL, 100, 1024, 768, 8658, 192, 32, 21, 3, 192, 10,
28652 - 0, FB_VMODE_NONINTERLACED
28653 + 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
28655 /* 1280x1024 @ 76 Hz, 81.13 kHz hsync */
28656 NULL, 76, 1280, 1024, 7407, 248, 32, 34, 3, 104, 3,
28657 - 0, FB_VMODE_NONINTERLACED
28658 + 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
28660 /* 1600x1200 @ 70 Hz, 87.50 kHz hsync */
28661 NULL, 70, 1600, 1200, 5291, 304, 64, 46, 1, 192, 3,
28662 - 0, FB_VMODE_NONINTERLACED
28663 + 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
28665 /* 1152x864 @ 100 Hz, 89.62 kHz hsync */
28666 NULL, 100, 1152, 864, 7264, 224, 32, 17, 2, 128, 19,
28667 - 0, FB_VMODE_NONINTERLACED
28668 + 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
28670 /* 1280x1024 @ 85 Hz, 91.15 kHz hsync */
28671 NULL, 85, 1280, 1024, 6349, 224, 64, 44, 1, 160, 3,
28672 - FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
28673 + FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
28675 /* 1600x1200 @ 75 Hz, 93.75 kHz hsync */
28676 NULL, 75, 1600, 1200, 4938, 304, 64, 46, 1, 192, 3,
28677 - FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
28678 + FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
28680 /* 1680x1050 @ 60 Hz, 65.191 kHz hsync */
28681 NULL, 60, 1680, 1050, 6848, 280, 104, 30, 3, 176, 6,
28682 - FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
28683 + FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
28685 /* 1600x1200 @ 85 Hz, 105.77 kHz hsync */
28686 NULL, 85, 1600, 1200, 4545, 272, 16, 37, 4, 192, 3,
28687 - FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
28688 + FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
28690 /* 1280x1024 @ 100 Hz, 107.16 kHz hsync */
28691 NULL, 100, 1280, 1024, 5502, 256, 32, 26, 7, 128, 15,
28692 - 0, FB_VMODE_NONINTERLACED
28693 + 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
28695 /* 1800x1440 @ 64Hz, 96.15 kHz hsync */
28696 NULL, 64, 1800, 1440, 4347, 304, 96, 46, 1, 192, 3,
28697 - FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
28698 + FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
28700 /* 1800x1440 @ 70Hz, 104.52 kHz hsync */
28701 NULL, 70, 1800, 1440, 4000, 304, 96, 46, 1, 192, 3,
28702 - FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
28703 + FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
28705 /* 512x384 @ 78 Hz, 31.50 kHz hsync */
28706 NULL, 78, 512, 384, 49603, 48, 16, 16, 1, 64, 3,
28707 - 0, FB_VMODE_NONINTERLACED
28708 + 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
28710 /* 512x384 @ 85 Hz, 34.38 kHz hsync */
28711 NULL, 85, 512, 384, 45454, 48, 16, 16, 1, 64, 3,
28712 - 0, FB_VMODE_NONINTERLACED
28713 + 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
28715 /* 320x200 @ 70 Hz, 31.5 kHz hsync, 8:5 aspect ratio */
28716 NULL, 70, 320, 200, 79440, 16, 16, 20, 4, 48, 1,
28717 - 0, FB_VMODE_DOUBLE
28718 + 0, FB_VMODE_DOUBLE, FB_MODE_IS_UNKNOWN
28720 /* 320x240 @ 60 Hz, 31.5 kHz hsync, 4:3 aspect ratio */
28721 NULL, 60, 320, 240, 79440, 16, 16, 16, 5, 48, 1,
28722 - 0, FB_VMODE_DOUBLE
28723 + 0, FB_VMODE_DOUBLE, FB_MODE_IS_UNKNOWN
28725 /* 320x240 @ 72 Hz, 36.5 kHz hsync */
28726 NULL, 72, 320, 240, 63492, 16, 16, 16, 4, 48, 2,
28727 - 0, FB_VMODE_DOUBLE
28728 + 0, FB_VMODE_DOUBLE, FB_MODE_IS_UNKNOWN
28730 /* 400x300 @ 56 Hz, 35.2 kHz hsync, 4:3 aspect ratio */
28731 NULL, 56, 400, 300, 55555, 64, 16, 10, 1, 32, 1,
28732 - 0, FB_VMODE_DOUBLE
28733 + 0, FB_VMODE_DOUBLE, FB_MODE_IS_UNKNOWN
28735 /* 400x300 @ 60 Hz, 37.8 kHz hsync */
28736 NULL, 60, 400, 300, 50000, 48, 16, 11, 1, 64, 2,
28737 - 0, FB_VMODE_DOUBLE
28738 + 0, FB_VMODE_DOUBLE, FB_MODE_IS_UNKNOWN
28740 /* 400x300 @ 72 Hz, 48.0 kHz hsync */
28741 NULL, 72, 400, 300, 40000, 32, 24, 11, 19, 64, 3,
28742 - 0, FB_VMODE_DOUBLE
28743 + 0, FB_VMODE_DOUBLE, FB_MODE_IS_UNKNOWN
28745 /* 480x300 @ 56 Hz, 35.2 kHz hsync, 8:5 aspect ratio */
28746 NULL, 56, 480, 300, 46176, 80, 16, 10, 1, 40, 1,
28747 - 0, FB_VMODE_DOUBLE
28748 + 0, FB_VMODE_DOUBLE, FB_MODE_IS_UNKNOWN
28750 /* 480x300 @ 60 Hz, 37.8 kHz hsync */
28751 NULL, 60, 480, 300, 41858, 56, 16, 11, 1, 80, 2,
28752 - 0, FB_VMODE_DOUBLE
28753 + 0, FB_VMODE_DOUBLE, FB_MODE_IS_UNKNOWN
28755 /* 480x300 @ 63 Hz, 39.6 kHz hsync */
28756 NULL, 63, 480, 300, 40000, 56, 16, 11, 1, 80, 2,
28757 - 0, FB_VMODE_DOUBLE
28758 + 0, FB_VMODE_DOUBLE, FB_MODE_IS_UNKNOWN
28760 /* 480x300 @ 72 Hz, 48.0 kHz hsync */
28761 NULL, 72, 480, 300, 33386, 40, 24, 11, 19, 80, 3,
28762 - 0, FB_VMODE_DOUBLE
28763 + 0, FB_VMODE_DOUBLE, FB_MODE_IS_UNKNOWN
28765 /* 1920x1200 @ 60 Hz, 74.5 Khz hsync */
28766 NULL, 60, 1920, 1200, 5177, 128, 336, 1, 38, 208, 3,
28767 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
28768 - FB_VMODE_NONINTERLACED
28769 + FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
28771 /* 1152x768, 60 Hz, PowerBook G4 Titanium I and II */
28772 NULL, 60, 1152, 768, 14047, 158, 26, 29, 3, 136, 6,
28773 - FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
28774 + FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
28776 /* 1366x768, 60 Hz, 47.403 kHz hsync, WXGA 16:9 aspect ratio */
28777 NULL, 60, 1366, 768, 13806, 120, 10, 14, 3, 32, 5,
28778 - 0, FB_VMODE_NONINTERLACED
28779 + 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
28781 /* 1280x800, 60 Hz, 47.403 kHz hsync, WXGA 16:10 aspect ratio */
28782 NULL, 60, 1280, 800, 12048, 200, 64, 24, 1, 136, 3,
28783 - 0, FB_VMODE_NONINTERLACED
28784 + 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
28786 /* 720x576i @ 50 Hz, 15.625 kHz hsync (PAL RGB) */
28787 NULL, 50, 720, 576, 74074, 64, 16, 39, 5, 64, 5,
28788 - 0, FB_VMODE_INTERLACED
28789 + 0, FB_VMODE_INTERLACED, FB_MODE_IS_UNKNOWN
28791 /* 800x520i @ 50 Hz, 15.625 kHz hsync (PAL RGB) */
28792 NULL, 50, 800, 520, 58823, 144, 64, 72, 28, 80, 5,
28793 - 0, FB_VMODE_INTERLACED
28794 + 0, FB_VMODE_INTERLACED, FB_MODE_IS_UNKNOWN
28798 diff -urNp linux-2.6.37/drivers/video/nvidia/nv_backlight.c linux-2.6.37/drivers/video/nvidia/nv_backlight.c
28799 --- linux-2.6.37/drivers/video/nvidia/nv_backlight.c 2011-01-04 19:50:19.000000000 -0500
28800 +++ linux-2.6.37/drivers/video/nvidia/nv_backlight.c 2011-01-17 02:41:01.000000000 -0500
28801 @@ -87,7 +87,7 @@ static int nvidia_bl_get_brightness(stru
28802 return bd->props.brightness;
28805 -static struct backlight_ops nvidia_bl_ops = {
28806 +static const struct backlight_ops nvidia_bl_ops = {
28807 .get_brightness = nvidia_bl_get_brightness,
28808 .update_status = nvidia_bl_update_status,
28810 diff -urNp linux-2.6.37/drivers/video/omap2/displays/panel-taal.c linux-2.6.37/drivers/video/omap2/displays/panel-taal.c
28811 --- linux-2.6.37/drivers/video/omap2/displays/panel-taal.c 2011-01-04 19:50:19.000000000 -0500
28812 +++ linux-2.6.37/drivers/video/omap2/displays/panel-taal.c 2011-01-17 02:41:01.000000000 -0500
28813 @@ -465,7 +465,7 @@ static int taal_bl_get_intensity(struct
28817 -static struct backlight_ops taal_bl_ops = {
28818 +static const struct backlight_ops taal_bl_ops = {
28819 .get_brightness = taal_bl_get_intensity,
28820 .update_status = taal_bl_update_status,
28822 diff -urNp linux-2.6.37/drivers/video/riva/fbdev.c linux-2.6.37/drivers/video/riva/fbdev.c
28823 --- linux-2.6.37/drivers/video/riva/fbdev.c 2011-01-04 19:50:19.000000000 -0500
28824 +++ linux-2.6.37/drivers/video/riva/fbdev.c 2011-01-17 02:41:01.000000000 -0500
28825 @@ -331,7 +331,7 @@ static int riva_bl_get_brightness(struct
28826 return bd->props.brightness;
28829 -static struct backlight_ops riva_bl_ops = {
28830 +static const struct backlight_ops riva_bl_ops = {
28831 .get_brightness = riva_bl_get_brightness,
28832 .update_status = riva_bl_update_status,
28834 diff -urNp linux-2.6.37/drivers/video/uvesafb.c linux-2.6.37/drivers/video/uvesafb.c
28835 --- linux-2.6.37/drivers/video/uvesafb.c 2011-01-04 19:50:19.000000000 -0500
28836 +++ linux-2.6.37/drivers/video/uvesafb.c 2011-01-17 02:41:01.000000000 -0500
28838 #include <linux/io.h>
28839 #include <linux/mutex.h>
28840 #include <linux/slab.h>
28841 +#include <linux/moduleloader.h>
28842 #include <video/edid.h>
28843 #include <video/uvesafb.h>
28845 @@ -121,7 +122,7 @@ static int uvesafb_helper_start(void)
28849 - return call_usermodehelper(v86d_path, argv, envp, 1);
28850 + return call_usermodehelper(v86d_path, argv, envp, UMH_WAIT_PROC);
28854 @@ -569,10 +570,32 @@ static int __devinit uvesafb_vbe_getpmi(
28855 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
28856 par->pmi_setpal = par->ypan = 0;
28859 +#ifdef CONFIG_PAX_KERNEXEC
28860 +#ifdef CONFIG_MODULES
28861 + par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
28863 + if (!par->pmi_code) {
28864 + par->pmi_setpal = par->ypan = 0;
28869 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
28870 + task->t.regs.edi);
28872 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
28873 + pax_open_kernel();
28874 + memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
28875 + pax_close_kernel();
28877 + par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
28878 + par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
28880 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
28881 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
28884 printk(KERN_INFO "uvesafb: protected mode interface info at "
28886 (u16)task->t.regs.es, (u16)task->t.regs.edi);
28887 @@ -1800,6 +1823,11 @@ out:
28888 if (par->vbe_modes)
28889 kfree(par->vbe_modes);
28891 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
28892 + if (par->pmi_code)
28893 + module_free_exec(NULL, par->pmi_code);
28896 framebuffer_release(info);
28899 @@ -1826,6 +1854,12 @@ static int uvesafb_remove(struct platfor
28900 kfree(par->vbe_state_orig);
28901 if (par->vbe_state_saved)
28902 kfree(par->vbe_state_saved);
28904 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
28905 + if (par->pmi_code)
28906 + module_free_exec(NULL, par->pmi_code);
28911 framebuffer_release(info);
28912 diff -urNp linux-2.6.37/drivers/video/vesafb.c linux-2.6.37/drivers/video/vesafb.c
28913 --- linux-2.6.37/drivers/video/vesafb.c 2011-01-04 19:50:19.000000000 -0500
28914 +++ linux-2.6.37/drivers/video/vesafb.c 2011-01-17 02:41:01.000000000 -0500
28918 #include <linux/module.h>
28919 +#include <linux/moduleloader.h>
28920 #include <linux/kernel.h>
28921 #include <linux/errno.h>
28922 #include <linux/string.h>
28923 @@ -52,8 +53,8 @@ static int vram_remap __initdata; /*
28924 static int vram_total __initdata; /* Set total amount of memory */
28925 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
28926 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
28927 -static void (*pmi_start)(void) __read_mostly;
28928 -static void (*pmi_pal) (void) __read_mostly;
28929 +static void (*pmi_start)(void) __read_only;
28930 +static void (*pmi_pal) (void) __read_only;
28931 static int depth __read_mostly;
28932 static int vga_compat __read_mostly;
28933 /* --------------------------------------------------------------------- */
28934 @@ -232,6 +233,7 @@ static int __init vesafb_probe(struct pl
28935 unsigned int size_vmode;
28936 unsigned int size_remap;
28937 unsigned int size_total;
28938 + void *pmi_code = NULL;
28940 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
28942 @@ -274,10 +276,6 @@ static int __init vesafb_probe(struct pl
28943 size_remap = size_total;
28944 vesafb_fix.smem_len = size_remap;
28947 - screen_info.vesapm_seg = 0;
28950 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
28951 printk(KERN_WARNING
28952 "vesafb: cannot reserve video memory at 0x%lx\n",
28953 @@ -319,9 +317,21 @@ static int __init vesafb_probe(struct pl
28954 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
28955 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
28959 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
28960 + pmi_code = module_alloc_exec(screen_info.vesapm_size);
28962 +#elif !defined(CONFIG_PAX_KERNEXEC)
28967 + screen_info.vesapm_seg = 0;
28969 if (screen_info.vesapm_seg) {
28970 - printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
28971 - screen_info.vesapm_seg,screen_info.vesapm_off);
28972 + printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
28973 + screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
28976 if (screen_info.vesapm_seg < 0xc000)
28977 @@ -329,9 +339,25 @@ static int __init vesafb_probe(struct pl
28979 if (ypan || pmi_setpal) {
28980 unsigned short *pmi_base;
28981 - pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
28982 - pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
28983 - pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
28985 + pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
28987 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
28988 + pax_open_kernel();
28989 + memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
28991 + pmi_code = pmi_base;
28994 + pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
28995 + pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
28997 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
28998 + pmi_start = ktva_ktla(pmi_start);
28999 + pmi_pal = ktva_ktla(pmi_pal);
29000 + pax_close_kernel();
29003 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
29005 printk(KERN_INFO "vesafb: pmi: ports = ");
29006 @@ -473,6 +499,11 @@ static int __init vesafb_probe(struct pl
29007 info->node, info->fix.id);
29011 +#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
29012 + module_free_exec(NULL, pmi_code);
29015 if (info->screen_base)
29016 iounmap(info->screen_base);
29017 framebuffer_release(info);
29018 diff -urNp linux-2.6.37/fs/9p/vfs_inode.c linux-2.6.37/fs/9p/vfs_inode.c
29019 --- linux-2.6.37/fs/9p/vfs_inode.c 2011-01-04 19:50:19.000000000 -0500
29020 +++ linux-2.6.37/fs/9p/vfs_inode.c 2011-01-17 02:41:01.000000000 -0500
29021 @@ -1598,7 +1598,7 @@ static void *v9fs_vfs_follow_link(struct
29023 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
29025 - char *s = nd_get_link(nd);
29026 + const char *s = nd_get_link(nd);
29028 P9_DPRINTK(P9_DEBUG_VFS, " %s %s\n", dentry->d_name.name,
29029 IS_ERR(s) ? "<error>" : s);
29030 diff -urNp linux-2.6.37/fs/aio.c linux-2.6.37/fs/aio.c
29031 --- linux-2.6.37/fs/aio.c 2011-01-04 19:50:19.000000000 -0500
29032 +++ linux-2.6.37/fs/aio.c 2011-01-17 02:41:01.000000000 -0500
29033 @@ -130,7 +130,7 @@ static int aio_setup_ring(struct kioctx
29034 size += sizeof(struct io_event) * nr_events;
29035 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
29037 - if (nr_pages < 0)
29038 + if (nr_pages <= 0)
29041 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
29042 diff -urNp linux-2.6.37/fs/attr.c linux-2.6.37/fs/attr.c
29043 --- linux-2.6.37/fs/attr.c 2011-01-04 19:50:19.000000000 -0500
29044 +++ linux-2.6.37/fs/attr.c 2011-01-17 02:41:01.000000000 -0500
29045 @@ -98,6 +98,7 @@ int inode_newsize_ok(const struct inode
29046 unsigned long limit;
29048 limit = rlimit(RLIMIT_FSIZE);
29049 + gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
29050 if (limit != RLIM_INFINITY && offset > limit)
29052 if (offset > inode->i_sb->s_maxbytes)
29053 diff -urNp linux-2.6.37/fs/autofs4/symlink.c linux-2.6.37/fs/autofs4/symlink.c
29054 --- linux-2.6.37/fs/autofs4/symlink.c 2011-01-04 19:50:19.000000000 -0500
29055 +++ linux-2.6.37/fs/autofs4/symlink.c 2011-01-17 02:41:01.000000000 -0500
29057 static void *autofs4_follow_link(struct dentry *dentry, struct nameidata *nd)
29059 struct autofs_info *ino = autofs4_dentry_ino(dentry);
29060 - nd_set_link(nd, (char *)ino->u.symlink);
29061 + nd_set_link(nd, ino->u.symlink);
29065 diff -urNp linux-2.6.37/fs/befs/linuxvfs.c linux-2.6.37/fs/befs/linuxvfs.c
29066 --- linux-2.6.37/fs/befs/linuxvfs.c 2011-01-04 19:50:19.000000000 -0500
29067 +++ linux-2.6.37/fs/befs/linuxvfs.c 2011-01-17 02:41:01.000000000 -0500
29068 @@ -493,7 +493,7 @@ static void befs_put_link(struct dentry
29070 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
29071 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
29072 - char *link = nd_get_link(nd);
29073 + const char *link = nd_get_link(nd);
29077 diff -urNp linux-2.6.37/fs/binfmt_aout.c linux-2.6.37/fs/binfmt_aout.c
29078 --- linux-2.6.37/fs/binfmt_aout.c 2011-01-04 19:50:19.000000000 -0500
29079 +++ linux-2.6.37/fs/binfmt_aout.c 2011-01-17 02:41:01.000000000 -0500
29081 #include <linux/string.h>
29082 #include <linux/fs.h>
29083 #include <linux/file.h>
29084 +#include <linux/security.h>
29085 #include <linux/stat.h>
29086 #include <linux/fcntl.h>
29087 #include <linux/ptrace.h>
29088 @@ -86,6 +87,8 @@ static int aout_core_dump(struct coredum
29090 # define START_STACK(u) ((void __user *)u.start_stack)
29092 + memset(&dump, 0, sizeof(dump));
29097 @@ -97,10 +100,12 @@ static int aout_core_dump(struct coredum
29099 /* If the size of the dump file exceeds the rlimit, then see what would happen
29100 if we wrote the stack, but not the data area. */
29101 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
29102 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
29105 /* Make sure we have enough room to write the stack and data areas. */
29106 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
29107 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
29110 @@ -234,6 +239,8 @@ static int load_aout_binary(struct linux
29111 rlim = rlimit(RLIMIT_DATA);
29112 if (rlim >= RLIM_INFINITY)
29115 + gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
29116 if (ex.a_data + ex.a_bss > rlim)
29119 @@ -262,6 +269,27 @@ static int load_aout_binary(struct linux
29120 install_exec_creds(bprm);
29121 current->flags &= ~PF_FORKNOEXEC;
29123 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
29124 + current->mm->pax_flags = 0UL;
29127 +#ifdef CONFIG_PAX_PAGEEXEC
29128 + if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
29129 + current->mm->pax_flags |= MF_PAX_PAGEEXEC;
29131 +#ifdef CONFIG_PAX_EMUTRAMP
29132 + if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
29133 + current->mm->pax_flags |= MF_PAX_EMUTRAMP;
29136 +#ifdef CONFIG_PAX_MPROTECT
29137 + if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
29138 + current->mm->pax_flags |= MF_PAX_MPROTECT;
29144 if (N_MAGIC(ex) == OMAGIC) {
29145 unsigned long text_addr, map_size;
29147 @@ -334,7 +362,7 @@ static int load_aout_binary(struct linux
29149 down_write(¤t->mm->mmap_sem);
29150 error = do_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
29151 - PROT_READ | PROT_WRITE | PROT_EXEC,
29152 + PROT_READ | PROT_WRITE,
29153 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
29154 fd_offset + ex.a_text);
29155 up_write(¤t->mm->mmap_sem);
29156 diff -urNp linux-2.6.37/fs/binfmt_elf.c linux-2.6.37/fs/binfmt_elf.c
29157 --- linux-2.6.37/fs/binfmt_elf.c 2011-01-04 19:50:19.000000000 -0500
29158 +++ linux-2.6.37/fs/binfmt_elf.c 2011-01-17 02:41:01.000000000 -0500
29159 @@ -51,6 +51,10 @@ static int elf_core_dump(struct coredump
29160 #define elf_core_dump NULL
29163 +#ifdef CONFIG_PAX_MPROTECT
29164 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
29167 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
29168 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
29170 @@ -70,6 +74,11 @@ static struct linux_binfmt elf_format =
29171 .load_binary = load_elf_binary,
29172 .load_shlib = load_elf_library,
29173 .core_dump = elf_core_dump,
29175 +#ifdef CONFIG_PAX_MPROTECT
29176 + .handle_mprotect= elf_handle_mprotect,
29179 .min_coredump = ELF_EXEC_PAGESIZE,
29182 @@ -78,6 +87,8 @@ static struct linux_binfmt elf_format =
29184 static int set_brk(unsigned long start, unsigned long end)
29186 + unsigned long e = end;
29188 start = ELF_PAGEALIGN(start);
29189 end = ELF_PAGEALIGN(end);
29191 @@ -88,7 +99,7 @@ static int set_brk(unsigned long start,
29192 if (BAD_ADDR(addr))
29195 - current->mm->start_brk = current->mm->brk = end;
29196 + current->mm->start_brk = current->mm->brk = e;
29200 @@ -149,7 +160,7 @@ create_elf_tables(struct linux_binprm *b
29201 elf_addr_t __user *u_rand_bytes;
29202 const char *k_platform = ELF_PLATFORM;
29203 const char *k_base_platform = ELF_BASE_PLATFORM;
29204 - unsigned char k_rand_bytes[16];
29205 + u32 k_rand_bytes[4];
29207 elf_addr_t *elf_info;
29209 @@ -196,8 +207,12 @@ create_elf_tables(struct linux_binprm *b
29210 * Generate 16 random bytes for userspace PRNG seeding.
29212 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
29213 - u_rand_bytes = (elf_addr_t __user *)
29214 - STACK_ALLOC(p, sizeof(k_rand_bytes));
29215 + srandom32(k_rand_bytes[0] ^ random32());
29216 + srandom32(k_rand_bytes[1] ^ random32());
29217 + srandom32(k_rand_bytes[2] ^ random32());
29218 + srandom32(k_rand_bytes[3] ^ random32());
29219 + p = STACK_ROUND(p, sizeof(k_rand_bytes));
29220 + u_rand_bytes = (elf_addr_t __user *) p;
29221 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
29224 @@ -386,10 +401,10 @@ static unsigned long load_elf_interp(str
29226 struct elf_phdr *elf_phdata;
29227 struct elf_phdr *eppnt;
29228 - unsigned long load_addr = 0;
29229 + unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
29230 int load_addr_set = 0;
29231 unsigned long last_bss = 0, elf_bss = 0;
29232 - unsigned long error = ~0UL;
29233 + unsigned long error = -EINVAL;
29234 unsigned long total_size;
29235 int retval, i, size;
29237 @@ -435,6 +450,11 @@ static unsigned long load_elf_interp(str
29241 +#ifdef CONFIG_PAX_SEGMEXEC
29242 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
29243 + pax_task_size = SEGMEXEC_TASK_SIZE;
29246 eppnt = elf_phdata;
29247 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
29248 if (eppnt->p_type == PT_LOAD) {
29249 @@ -478,8 +498,8 @@ static unsigned long load_elf_interp(str
29250 k = load_addr + eppnt->p_vaddr;
29252 eppnt->p_filesz > eppnt->p_memsz ||
29253 - eppnt->p_memsz > TASK_SIZE ||
29254 - TASK_SIZE - eppnt->p_memsz < k) {
29255 + eppnt->p_memsz > pax_task_size ||
29256 + pax_task_size - eppnt->p_memsz < k) {
29260 @@ -533,6 +553,177 @@ out:
29264 +#if (defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS)) && defined(CONFIG_PAX_SOFTMODE)
29265 +static unsigned long pax_parse_softmode(const struct elf_phdr * const elf_phdata)
29267 + unsigned long pax_flags = 0UL;
29269 +#ifdef CONFIG_PAX_PAGEEXEC
29270 + if (elf_phdata->p_flags & PF_PAGEEXEC)
29271 + pax_flags |= MF_PAX_PAGEEXEC;
29274 +#ifdef CONFIG_PAX_SEGMEXEC
29275 + if (elf_phdata->p_flags & PF_SEGMEXEC)
29276 + pax_flags |= MF_PAX_SEGMEXEC;
29279 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
29280 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
29281 + if ((__supported_pte_mask & _PAGE_NX))
29282 + pax_flags &= ~MF_PAX_SEGMEXEC;
29284 + pax_flags &= ~MF_PAX_PAGEEXEC;
29288 +#ifdef CONFIG_PAX_EMUTRAMP
29289 + if (elf_phdata->p_flags & PF_EMUTRAMP)
29290 + pax_flags |= MF_PAX_EMUTRAMP;
29293 +#ifdef CONFIG_PAX_MPROTECT
29294 + if (elf_phdata->p_flags & PF_MPROTECT)
29295 + pax_flags |= MF_PAX_MPROTECT;
29298 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
29299 + if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
29300 + pax_flags |= MF_PAX_RANDMMAP;
29303 + return pax_flags;
29307 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
29308 +static unsigned long pax_parse_hardmode(const struct elf_phdr * const elf_phdata)
29310 + unsigned long pax_flags = 0UL;
29312 +#ifdef CONFIG_PAX_PAGEEXEC
29313 + if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
29314 + pax_flags |= MF_PAX_PAGEEXEC;
29317 +#ifdef CONFIG_PAX_SEGMEXEC
29318 + if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
29319 + pax_flags |= MF_PAX_SEGMEXEC;
29322 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
29323 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
29324 + if ((__supported_pte_mask & _PAGE_NX))
29325 + pax_flags &= ~MF_PAX_SEGMEXEC;
29327 + pax_flags &= ~MF_PAX_PAGEEXEC;
29331 +#ifdef CONFIG_PAX_EMUTRAMP
29332 + if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
29333 + pax_flags |= MF_PAX_EMUTRAMP;
29336 +#ifdef CONFIG_PAX_MPROTECT
29337 + if (!(elf_phdata->p_flags & PF_NOMPROTECT))
29338 + pax_flags |= MF_PAX_MPROTECT;
29341 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
29342 + if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
29343 + pax_flags |= MF_PAX_RANDMMAP;
29346 + return pax_flags;
29350 +#ifdef CONFIG_PAX_EI_PAX
29351 +static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
29353 + unsigned long pax_flags = 0UL;
29355 +#ifdef CONFIG_PAX_PAGEEXEC
29356 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
29357 + pax_flags |= MF_PAX_PAGEEXEC;
29360 +#ifdef CONFIG_PAX_SEGMEXEC
29361 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
29362 + pax_flags |= MF_PAX_SEGMEXEC;
29365 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
29366 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
29367 + if ((__supported_pte_mask & _PAGE_NX))
29368 + pax_flags &= ~MF_PAX_SEGMEXEC;
29370 + pax_flags &= ~MF_PAX_PAGEEXEC;
29374 +#ifdef CONFIG_PAX_EMUTRAMP
29375 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
29376 + pax_flags |= MF_PAX_EMUTRAMP;
29379 +#ifdef CONFIG_PAX_MPROTECT
29380 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
29381 + pax_flags |= MF_PAX_MPROTECT;
29384 +#ifdef CONFIG_PAX_ASLR
29385 + if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
29386 + pax_flags |= MF_PAX_RANDMMAP;
29389 + return pax_flags;
29393 +#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS)
29394 +static long pax_parse_elf_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
29396 + unsigned long pax_flags = 0UL;
29398 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
29402 +#ifdef CONFIG_PAX_EI_PAX
29403 + pax_flags = pax_parse_ei_pax(elf_ex);
29406 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
29407 + for (i = 0UL; i < elf_ex->e_phnum; i++)
29408 + if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
29409 + if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
29410 + ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
29411 + ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
29412 + ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
29413 + ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
29416 +#ifdef CONFIG_PAX_SOFTMODE
29417 + if (pax_softmode)
29418 + pax_flags = pax_parse_softmode(&elf_phdata[i]);
29422 + pax_flags = pax_parse_hardmode(&elf_phdata[i]);
29427 + if (0 > pax_check_flags(&pax_flags))
29430 + current->mm->pax_flags = pax_flags;
29436 * These are the functions used to load ELF style executables and shared
29437 * libraries. There is no binary dependent code anywhere else.
29438 @@ -549,6 +740,11 @@ static unsigned long randomize_stack_top
29440 unsigned int random_variable = 0;
29442 +#ifdef CONFIG_PAX_RANDUSTACK
29443 + if (randomize_va_space)
29444 + return stack_top - current->mm->delta_stack;
29447 if ((current->flags & PF_RANDOMIZE) &&
29448 !(current->personality & ADDR_NO_RANDOMIZE)) {
29449 random_variable = get_random_int() & STACK_RND_MASK;
29450 @@ -567,7 +763,7 @@ static int load_elf_binary(struct linux_
29451 unsigned long load_addr = 0, load_bias = 0;
29452 int load_addr_set = 0;
29453 char * elf_interpreter = NULL;
29454 - unsigned long error;
29455 + unsigned long error = 0;
29456 struct elf_phdr *elf_ppnt, *elf_phdata;
29457 unsigned long elf_bss, elf_brk;
29459 @@ -577,11 +773,11 @@ static int load_elf_binary(struct linux_
29460 unsigned long start_code, end_code, start_data, end_data;
29461 unsigned long reloc_func_desc = 0;
29462 int executable_stack = EXSTACK_DEFAULT;
29463 - unsigned long def_flags = 0;
29465 struct elfhdr elf_ex;
29466 struct elfhdr interp_elf_ex;
29468 + unsigned long pax_task_size = TASK_SIZE;
29470 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
29472 @@ -719,11 +915,80 @@ static int load_elf_binary(struct linux_
29474 /* OK, This is the point of no return */
29475 current->flags &= ~PF_FORKNOEXEC;
29476 - current->mm->def_flags = def_flags;
29478 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
29479 + current->mm->pax_flags = 0UL;
29482 +#ifdef CONFIG_PAX_DLRESOLVE
29483 + current->mm->call_dl_resolve = 0UL;
29486 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
29487 + current->mm->call_syscall = 0UL;
29490 +#ifdef CONFIG_PAX_ASLR
29491 + current->mm->delta_mmap = 0UL;
29492 + current->mm->delta_stack = 0UL;
29495 + current->mm->def_flags = 0;
29497 +#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS)
29498 + if (0 > pax_parse_elf_flags(&loc->elf_ex, elf_phdata)) {
29499 + send_sig(SIGKILL, current, 0);
29500 + goto out_free_dentry;
29504 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
29505 + pax_set_initial_flags(bprm);
29506 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
29507 + if (pax_set_initial_flags_func)
29508 + (pax_set_initial_flags_func)(bprm);
29511 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
29512 + if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
29513 + current->mm->context.user_cs_limit = PAGE_SIZE;
29514 + current->mm->def_flags |= VM_PAGEEXEC;
29518 +#ifdef CONFIG_PAX_SEGMEXEC
29519 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
29520 + current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
29521 + current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
29522 + pax_task_size = SEGMEXEC_TASK_SIZE;
29526 +#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
29527 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
29528 + set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
29533 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
29534 may depend on the personality. */
29535 SET_PERSONALITY(loc->elf_ex);
29537 +#ifdef CONFIG_PAX_ASLR
29538 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
29539 + current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
29540 + current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
29544 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
29545 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
29546 + executable_stack = EXSTACK_DISABLE_X;
29547 + current->personality &= ~READ_IMPLIES_EXEC;
29551 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
29552 current->personality |= READ_IMPLIES_EXEC;
29554 @@ -805,6 +1070,20 @@ static int load_elf_binary(struct linux_
29556 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
29559 +#ifdef CONFIG_PAX_RANDMMAP
29560 + /* PaX: randomize base address at the default exe base if requested */
29561 + if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
29562 +#ifdef CONFIG_SPARC64
29563 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
29565 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
29567 + load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
29568 + elf_flags |= MAP_FIXED;
29574 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
29575 @@ -837,9 +1116,9 @@ static int load_elf_binary(struct linux_
29576 * allowed task size. Note that p_filesz must always be
29577 * <= p_memsz so it is only necessary to check p_memsz.
29579 - if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
29580 - elf_ppnt->p_memsz > TASK_SIZE ||
29581 - TASK_SIZE - elf_ppnt->p_memsz < k) {
29582 + if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
29583 + elf_ppnt->p_memsz > pax_task_size ||
29584 + pax_task_size - elf_ppnt->p_memsz < k) {
29585 /* set_brk can never work. Avoid overflows. */
29586 send_sig(SIGKILL, current, 0);
29588 @@ -867,6 +1146,11 @@ static int load_elf_binary(struct linux_
29589 start_data += load_bias;
29590 end_data += load_bias;
29592 +#ifdef CONFIG_PAX_RANDMMAP
29593 + if (current->mm->pax_flags & MF_PAX_RANDMMAP)
29594 + elf_brk += PAGE_SIZE + ((pax_get_random_long() & ~PAGE_MASK) << 4);
29597 /* Calling set_brk effectively mmaps the pages that we need
29598 * for the bss and break sections. We must do this before
29599 * mapping in the interpreter, to make sure it doesn't wind
29600 @@ -878,9 +1162,11 @@ static int load_elf_binary(struct linux_
29601 goto out_free_dentry;
29603 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
29604 - send_sig(SIGSEGV, current, 0);
29605 - retval = -EFAULT; /* Nobody gets to see this, but.. */
29606 - goto out_free_dentry;
29608 + * This bss-zeroing can fail if the ELF
29609 + * file specifies odd protections. So
29610 + * we don't check the return value
29614 if (elf_interpreter) {
29615 @@ -1091,7 +1377,7 @@ out:
29616 * Decide what to dump of a segment, part, all or none.
29618 static unsigned long vma_dump_size(struct vm_area_struct *vma,
29619 - unsigned long mm_flags)
29620 + unsigned long mm_flags, long signr)
29622 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
29624 @@ -1125,7 +1411,7 @@ static unsigned long vma_dump_size(struc
29625 if (vma->vm_file == NULL)
29628 - if (FILTER(MAPPED_PRIVATE))
29629 + if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
29633 @@ -1347,9 +1633,9 @@ static void fill_auxv_note(struct memelf
29635 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
29640 - while (auxv[i - 2] != AT_NULL);
29641 + } while (auxv[i - 2] != AT_NULL);
29642 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
29645 @@ -1855,14 +2141,14 @@ static void fill_extnum_info(struct elfh
29648 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
29649 - unsigned long mm_flags)
29650 + struct coredump_params *cprm)
29652 struct vm_area_struct *vma;
29655 for (vma = first_vma(current, gate_vma); vma != NULL;
29656 vma = next_vma(vma, gate_vma))
29657 - size += vma_dump_size(vma, mm_flags);
29658 + size += vma_dump_size(vma, cprm->mm_flags, cprm->signr);
29662 @@ -1956,7 +2242,7 @@ static int elf_core_dump(struct coredump
29664 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
29666 - offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
29667 + offset += elf_core_vma_data_size(gate_vma, cprm);
29668 offset += elf_core_extra_data_size();
29671 @@ -1970,10 +2256,12 @@ static int elf_core_dump(struct coredump
29674 size += sizeof(*elf);
29675 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
29676 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
29679 size += sizeof(*phdr4note);
29680 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
29681 if (size > cprm->limit
29682 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
29684 @@ -1987,7 +2275,7 @@ static int elf_core_dump(struct coredump
29685 phdr.p_offset = offset;
29686 phdr.p_vaddr = vma->vm_start;
29688 - phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
29689 + phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->signr);
29690 phdr.p_memsz = vma->vm_end - vma->vm_start;
29691 offset += phdr.p_filesz;
29692 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
29693 @@ -1998,6 +2286,7 @@ static int elf_core_dump(struct coredump
29694 phdr.p_align = ELF_EXEC_PAGESIZE;
29696 size += sizeof(phdr);
29697 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
29698 if (size > cprm->limit
29699 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
29701 @@ -2022,7 +2311,7 @@ static int elf_core_dump(struct coredump
29702 unsigned long addr;
29705 - end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
29706 + end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->signr);
29708 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
29710 @@ -2031,6 +2320,7 @@ static int elf_core_dump(struct coredump
29711 page = get_dump_page(addr);
29713 void *kaddr = kmap(page);
29714 + gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
29715 stop = ((size += PAGE_SIZE) > cprm->limit) ||
29716 !dump_write(cprm->file, kaddr,
29718 @@ -2048,6 +2338,7 @@ static int elf_core_dump(struct coredump
29720 if (e_phnum == PN_XNUM) {
29721 size += sizeof(*shdr4extnum);
29722 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
29723 if (size > cprm->limit
29724 || !dump_write(cprm->file, shdr4extnum,
29725 sizeof(*shdr4extnum)))
29726 @@ -2068,6 +2359,97 @@ out:
29728 #endif /* CONFIG_ELF_CORE */
29730 +#ifdef CONFIG_PAX_MPROTECT
29731 +/* PaX: non-PIC ELF libraries need relocations on their executable segments
29732 + * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
29733 + * we'll remove VM_MAYWRITE for good on RELRO segments.
29735 + * The checks favour ld-linux.so behaviour which operates on a per ELF segment
29736 + * basis because we want to allow the common case and not the special ones.
29738 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
29740 + struct elfhdr elf_h;
29741 + struct elf_phdr elf_p;
29743 + unsigned long oldflags;
29744 + bool is_textrel_rw, is_textrel_rx, is_relro;
29746 + if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
29749 + oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
29750 + newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
29752 +#ifdef CONFIG_PAX_ELFRELOCS
29753 + /* possible TEXTREL */
29754 + is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
29755 + 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);
29757 + is_textrel_rw = false;
29758 + is_textrel_rx = false;
29761 + /* possible RELRO */
29762 + is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
29764 + if (!is_textrel_rw && !is_textrel_rx && !is_relro)
29767 + if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
29768 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
29770 +#ifdef CONFIG_PAX_ETEXECRELOCS
29771 + ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
29773 + ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
29776 + (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
29777 + !elf_check_arch(&elf_h) ||
29778 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
29779 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
29782 + for (i = 0UL; i < elf_h.e_phnum; i++) {
29783 + if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
29785 + switch (elf_p.p_type) {
29787 + if (!is_textrel_rw && !is_textrel_rx)
29790 + while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
29793 + if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
29795 + if (dyn.d_tag == DT_NULL)
29797 + if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
29798 + gr_log_textrel(vma);
29799 + if (is_textrel_rw)
29800 + vma->vm_flags |= VM_MAYWRITE;
29802 + /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
29803 + vma->vm_flags &= ~VM_MAYWRITE;
29810 + case PT_GNU_RELRO:
29813 + if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
29814 + vma->vm_flags &= ~VM_MAYWRITE;
29821 static int __init init_elf_binfmt(void)
29823 return register_binfmt(&elf_format);
29824 diff -urNp linux-2.6.37/fs/binfmt_flat.c linux-2.6.37/fs/binfmt_flat.c
29825 --- linux-2.6.37/fs/binfmt_flat.c 2011-01-04 19:50:19.000000000 -0500
29826 +++ linux-2.6.37/fs/binfmt_flat.c 2011-01-17 02:41:01.000000000 -0500
29827 @@ -567,7 +567,9 @@ static int load_flat_file(struct linux_b
29828 realdatastart = (unsigned long) -ENOMEM;
29829 printk("Unable to allocate RAM for process data, errno %d\n",
29830 (int)-realdatastart);
29831 + down_write(¤t->mm->mmap_sem);
29832 do_munmap(current->mm, textpos, text_len);
29833 + up_write(¤t->mm->mmap_sem);
29834 ret = realdatastart;
29837 @@ -591,8 +593,10 @@ static int load_flat_file(struct linux_b
29839 if (IS_ERR_VALUE(result)) {
29840 printk("Unable to read data+bss, errno %d\n", (int)-result);
29841 + down_write(¤t->mm->mmap_sem);
29842 do_munmap(current->mm, textpos, text_len);
29843 do_munmap(current->mm, realdatastart, len);
29844 + up_write(¤t->mm->mmap_sem);
29848 @@ -661,8 +665,10 @@ static int load_flat_file(struct linux_b
29850 if (IS_ERR_VALUE(result)) {
29851 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
29852 + down_write(¤t->mm->mmap_sem);
29853 do_munmap(current->mm, textpos, text_len + data_len + extra +
29854 MAX_SHARED_LIBS * sizeof(unsigned long));
29855 + up_write(¤t->mm->mmap_sem);
29859 diff -urNp linux-2.6.37/fs/binfmt_misc.c linux-2.6.37/fs/binfmt_misc.c
29860 --- linux-2.6.37/fs/binfmt_misc.c 2011-01-04 19:50:19.000000000 -0500
29861 +++ linux-2.6.37/fs/binfmt_misc.c 2011-01-17 02:41:01.000000000 -0500
29862 @@ -698,7 +698,7 @@ static int bm_fill_super(struct super_bl
29863 static struct tree_descr bm_files[] = {
29864 [2] = {"status", &bm_status_operations, S_IWUSR|S_IRUGO},
29865 [3] = {"register", &bm_register_operations, S_IWUSR},
29866 - /* last one */ {""}
29867 + /* last one */ {"", NULL, 0}
29869 int err = simple_fill_super(sb, 0x42494e4d, bm_files);
29871 diff -urNp linux-2.6.37/fs/bio.c linux-2.6.37/fs/bio.c
29872 --- linux-2.6.37/fs/bio.c 2011-01-04 19:50:19.000000000 -0500
29873 +++ linux-2.6.37/fs/bio.c 2011-01-17 02:41:01.000000000 -0500
29874 @@ -1233,7 +1233,7 @@ static void bio_copy_kern_endio(struct b
29875 const int read = bio_data_dir(bio) == READ;
29876 struct bio_map_data *bmd = bio->bi_private;
29878 - char *p = bmd->sgvecs[0].iov_base;
29879 + char *p = (__force char *)bmd->sgvecs[0].iov_base;
29881 __bio_for_each_segment(bvec, bio, i, 0) {
29882 char *addr = page_address(bvec->bv_page);
29883 diff -urNp linux-2.6.37/fs/block_dev.c linux-2.6.37/fs/block_dev.c
29884 --- linux-2.6.37/fs/block_dev.c 2011-01-04 19:50:19.000000000 -0500
29885 +++ linux-2.6.37/fs/block_dev.c 2011-01-17 02:41:01.000000000 -0500
29886 @@ -662,7 +662,7 @@ static bool bd_may_claim(struct block_de
29887 else if (bdev->bd_contains == bdev)
29888 return true; /* is a whole device which isn't held */
29890 - else if (whole->bd_holder == bd_claim)
29891 + else if (whole->bd_holder == (void *)bd_claim)
29892 return true; /* is a partition of a device that is being partitioned */
29893 else if (whole->bd_holder != NULL)
29894 return false; /* is a partition of a held device */
29895 diff -urNp linux-2.6.37/fs/btrfs/ctree.c linux-2.6.37/fs/btrfs/ctree.c
29896 --- linux-2.6.37/fs/btrfs/ctree.c 2011-01-04 19:50:19.000000000 -0500
29897 +++ linux-2.6.37/fs/btrfs/ctree.c 2011-01-17 02:41:01.000000000 -0500
29898 @@ -466,9 +466,12 @@ static noinline int __btrfs_cow_block(st
29899 free_extent_buffer(buf);
29900 add_root_to_dirty_list(root);
29902 - if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
29903 - parent_start = parent->start;
29905 + if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
29907 + parent_start = parent->start;
29909 + parent_start = 0;
29913 WARN_ON(trans->transid != btrfs_header_generation(parent));
29914 @@ -3768,7 +3771,6 @@ setup_items_for_insert(struct btrfs_tran
29918 - struct btrfs_disk_key disk_key;
29919 btrfs_cpu_key_to_disk(&disk_key, cpu_key);
29920 ret = fixup_low_keys(trans, root, path, &disk_key, 1);
29922 diff -urNp linux-2.6.37/fs/btrfs/disk-io.c linux-2.6.37/fs/btrfs/disk-io.c
29923 --- linux-2.6.37/fs/btrfs/disk-io.c 2011-01-04 19:50:19.000000000 -0500
29924 +++ linux-2.6.37/fs/btrfs/disk-io.c 2011-01-17 02:41:01.000000000 -0500
29926 #include "tree-log.h"
29927 #include "free-space-cache.h"
29929 -static struct extent_io_ops btree_extent_io_ops;
29930 +static const struct extent_io_ops btree_extent_io_ops;
29931 static void end_workqueue_fn(struct btrfs_work *work);
29932 static void free_fs_root(struct btrfs_root *root);
29934 @@ -2619,7 +2619,7 @@ out:
29938 -static struct extent_io_ops btree_extent_io_ops = {
29939 +static const struct extent_io_ops btree_extent_io_ops = {
29940 .write_cache_pages_lock_hook = btree_lock_page_hook,
29941 .readpage_end_io_hook = btree_readpage_end_io_hook,
29942 .submit_bio_hook = btree_submit_bio_hook,
29943 diff -urNp linux-2.6.37/fs/btrfs/extent_io.h linux-2.6.37/fs/btrfs/extent_io.h
29944 --- linux-2.6.37/fs/btrfs/extent_io.h 2011-01-04 19:50:19.000000000 -0500
29945 +++ linux-2.6.37/fs/btrfs/extent_io.h 2011-01-17 02:41:01.000000000 -0500
29946 @@ -51,36 +51,36 @@ typedef int (extent_submit_bio_hook_t)(s
29947 struct bio *bio, int mirror_num,
29948 unsigned long bio_flags, u64 bio_offset);
29949 struct extent_io_ops {
29950 - int (*fill_delalloc)(struct inode *inode, struct page *locked_page,
29951 + int (* const fill_delalloc)(struct inode *inode, struct page *locked_page,
29952 u64 start, u64 end, int *page_started,
29953 unsigned long *nr_written);
29954 - int (*writepage_start_hook)(struct page *page, u64 start, u64 end);
29955 - int (*writepage_io_hook)(struct page *page, u64 start, u64 end);
29956 + int (* const writepage_start_hook)(struct page *page, u64 start, u64 end);
29957 + int (* const writepage_io_hook)(struct page *page, u64 start, u64 end);
29958 extent_submit_bio_hook_t *submit_bio_hook;
29959 - int (*merge_bio_hook)(struct page *page, unsigned long offset,
29960 + int (* const merge_bio_hook)(struct page *page, unsigned long offset,
29961 size_t size, struct bio *bio,
29962 unsigned long bio_flags);
29963 - int (*readpage_io_hook)(struct page *page, u64 start, u64 end);
29964 - int (*readpage_io_failed_hook)(struct bio *bio, struct page *page,
29965 + int (* const readpage_io_hook)(struct page *page, u64 start, u64 end);
29966 + int (* const readpage_io_failed_hook)(struct bio *bio, struct page *page,
29967 u64 start, u64 end,
29968 struct extent_state *state);
29969 - int (*writepage_io_failed_hook)(struct bio *bio, struct page *page,
29970 + int (* const writepage_io_failed_hook)(struct bio *bio, struct page *page,
29971 u64 start, u64 end,
29972 struct extent_state *state);
29973 - int (*readpage_end_io_hook)(struct page *page, u64 start, u64 end,
29974 + int (* const readpage_end_io_hook)(struct page *page, u64 start, u64 end,
29975 struct extent_state *state);
29976 - int (*writepage_end_io_hook)(struct page *page, u64 start, u64 end,
29977 + int (* const writepage_end_io_hook)(struct page *page, u64 start, u64 end,
29978 struct extent_state *state, int uptodate);
29979 - int (*set_bit_hook)(struct inode *inode, struct extent_state *state,
29980 + int (* const set_bit_hook)(struct inode *inode, struct extent_state *state,
29982 - int (*clear_bit_hook)(struct inode *inode, struct extent_state *state,
29983 + int (* const clear_bit_hook)(struct inode *inode, struct extent_state *state,
29985 - int (*merge_extent_hook)(struct inode *inode,
29986 + int (* const merge_extent_hook)(struct inode *inode,
29987 struct extent_state *new,
29988 struct extent_state *other);
29989 - int (*split_extent_hook)(struct inode *inode,
29990 + int (* const split_extent_hook)(struct inode *inode,
29991 struct extent_state *orig, u64 split);
29992 - int (*write_cache_pages_lock_hook)(struct page *page);
29993 + int (* const write_cache_pages_lock_hook)(struct page *page);
29996 struct extent_io_tree {
29997 @@ -90,7 +90,7 @@ struct extent_io_tree {
30000 spinlock_t buffer_lock;
30001 - struct extent_io_ops *ops;
30002 + const struct extent_io_ops *ops;
30005 struct extent_state {
30006 diff -urNp linux-2.6.37/fs/btrfs/free-space-cache.c linux-2.6.37/fs/btrfs/free-space-cache.c
30007 --- linux-2.6.37/fs/btrfs/free-space-cache.c 2011-01-04 19:50:19.000000000 -0500
30008 +++ linux-2.6.37/fs/btrfs/free-space-cache.c 2011-01-17 02:41:01.000000000 -0500
30009 @@ -1828,8 +1828,6 @@ u64 btrfs_alloc_from_cluster(struct btrf
30012 if (entry->bytes < bytes || entry->offset < min_start) {
30013 - struct rb_node *node;
30015 node = rb_next(&entry->offset_index);
30018 @@ -1980,7 +1978,7 @@ again:
30020 while (entry->bitmap || found_bitmap ||
30021 (!entry->bitmap && entry->bytes < min_bytes)) {
30022 - struct rb_node *node = rb_next(&entry->offset_index);
30023 + node = rb_next(&entry->offset_index);
30025 if (entry->bitmap && entry->bytes > bytes + empty_size) {
30026 ret = btrfs_bitmap_cluster(block_group, entry, cluster,
30027 diff -urNp linux-2.6.37/fs/btrfs/inode.c linux-2.6.37/fs/btrfs/inode.c
30028 --- linux-2.6.37/fs/btrfs/inode.c 2011-01-04 19:50:19.000000000 -0500
30029 +++ linux-2.6.37/fs/btrfs/inode.c 2011-01-17 02:41:01.000000000 -0500
30030 @@ -64,7 +64,7 @@ static const struct inode_operations btr
30031 static const struct address_space_operations btrfs_aops;
30032 static const struct address_space_operations btrfs_symlink_aops;
30033 static const struct file_operations btrfs_dir_file_operations;
30034 -static struct extent_io_ops btrfs_extent_io_ops;
30035 +static const struct extent_io_ops btrfs_extent_io_ops;
30037 static struct kmem_cache *btrfs_inode_cachep;
30038 struct kmem_cache *btrfs_trans_handle_cachep;
30039 @@ -7246,7 +7246,7 @@ static const struct file_operations btrf
30040 .fsync = btrfs_sync_file,
30043 -static struct extent_io_ops btrfs_extent_io_ops = {
30044 +static const struct extent_io_ops btrfs_extent_io_ops = {
30045 .fill_delalloc = run_delalloc_range,
30046 .submit_bio_hook = btrfs_submit_bio_hook,
30047 .merge_bio_hook = btrfs_merge_bio_hook,
30048 diff -urNp linux-2.6.37/fs/btrfs/relocation.c linux-2.6.37/fs/btrfs/relocation.c
30049 --- linux-2.6.37/fs/btrfs/relocation.c 2011-01-04 19:50:19.000000000 -0500
30050 +++ linux-2.6.37/fs/btrfs/relocation.c 2011-01-17 02:41:01.000000000 -0500
30051 @@ -1238,7 +1238,7 @@ static int __update_reloc_root(struct bt
30053 spin_unlock(&rc->reloc_root_tree.lock);
30055 - BUG_ON((struct btrfs_root *)node->data != root);
30056 + BUG_ON(!node || (struct btrfs_root *)node->data != root);
30059 spin_lock(&rc->reloc_root_tree.lock);
30060 diff -urNp linux-2.6.37/fs/cachefiles/bind.c linux-2.6.37/fs/cachefiles/bind.c
30061 --- linux-2.6.37/fs/cachefiles/bind.c 2011-01-04 19:50:19.000000000 -0500
30062 +++ linux-2.6.37/fs/cachefiles/bind.c 2011-01-17 02:41:01.000000000 -0500
30063 @@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachef
30066 /* start by checking things over */
30067 - ASSERT(cache->fstop_percent >= 0 &&
30068 - cache->fstop_percent < cache->fcull_percent &&
30069 + ASSERT(cache->fstop_percent < cache->fcull_percent &&
30070 cache->fcull_percent < cache->frun_percent &&
30071 cache->frun_percent < 100);
30073 - ASSERT(cache->bstop_percent >= 0 &&
30074 - cache->bstop_percent < cache->bcull_percent &&
30075 + ASSERT(cache->bstop_percent < cache->bcull_percent &&
30076 cache->bcull_percent < cache->brun_percent &&
30077 cache->brun_percent < 100);
30079 diff -urNp linux-2.6.37/fs/cachefiles/daemon.c linux-2.6.37/fs/cachefiles/daemon.c
30080 --- linux-2.6.37/fs/cachefiles/daemon.c 2011-01-04 19:50:19.000000000 -0500
30081 +++ linux-2.6.37/fs/cachefiles/daemon.c 2011-01-17 02:41:01.000000000 -0500
30082 @@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(st
30086 - if (copy_to_user(_buffer, buffer, n) != 0)
30087 + if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
30091 @@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(s
30092 if (test_bit(CACHEFILES_DEAD, &cache->flags))
30095 - if (datalen < 0 || datalen > PAGE_SIZE - 1)
30096 + if (datalen > PAGE_SIZE - 1)
30097 return -EOPNOTSUPP;
30099 /* drag the command string into the kernel so we can parse it */
30100 @@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struc
30101 if (args[0] != '%' || args[1] != '\0')
30104 - if (fstop < 0 || fstop >= cache->fcull_percent)
30105 + if (fstop >= cache->fcull_percent)
30106 return cachefiles_daemon_range_error(cache, args);
30108 cache->fstop_percent = fstop;
30109 @@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struc
30110 if (args[0] != '%' || args[1] != '\0')
30113 - if (bstop < 0 || bstop >= cache->bcull_percent)
30114 + if (bstop >= cache->bcull_percent)
30115 return cachefiles_daemon_range_error(cache, args);
30117 cache->bstop_percent = bstop;
30118 diff -urNp linux-2.6.37/fs/cachefiles/rdwr.c linux-2.6.37/fs/cachefiles/rdwr.c
30119 --- linux-2.6.37/fs/cachefiles/rdwr.c 2011-01-04 19:50:19.000000000 -0500
30120 +++ linux-2.6.37/fs/cachefiles/rdwr.c 2011-01-17 02:41:01.000000000 -0500
30121 @@ -945,7 +945,7 @@ int cachefiles_write_page(struct fscache
30124 ret = file->f_op->write(
30125 - file, (const void __user *) data, len, &pos);
30126 + file, (__force const void __user *) data, len, &pos);
30130 diff -urNp linux-2.6.37/fs/ceph/dir.c linux-2.6.37/fs/ceph/dir.c
30131 --- linux-2.6.37/fs/ceph/dir.c 2011-01-04 19:50:19.000000000 -0500
30132 +++ linux-2.6.37/fs/ceph/dir.c 2011-01-17 02:41:01.000000000 -0500
30133 @@ -223,7 +223,7 @@ static int ceph_readdir(struct file *fil
30134 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
30135 struct ceph_mds_client *mdsc = fsc->mdsc;
30136 unsigned frag = fpos_frag(filp->f_pos);
30137 - int off = fpos_off(filp->f_pos);
30138 + unsigned int off = fpos_off(filp->f_pos);
30141 struct ceph_mds_reply_info_parsed *rinfo;
30142 @@ -355,7 +355,7 @@ more:
30143 rinfo = &fi->last_readdir->r_reply_info;
30144 dout("readdir frag %x num %d off %d chunkoff %d\n", frag,
30145 rinfo->dir_nr, off, fi->offset);
30146 - while (off - fi->offset >= 0 && off - fi->offset < rinfo->dir_nr) {
30147 + while (off >= fi->offset && off - fi->offset < rinfo->dir_nr) {
30148 u64 pos = ceph_make_fpos(frag, off);
30149 struct ceph_mds_reply_inode *in =
30150 rinfo->dir_in[off - fi->offset].in;
30151 diff -urNp linux-2.6.37/fs/cifs/cifs_uniupr.h linux-2.6.37/fs/cifs/cifs_uniupr.h
30152 --- linux-2.6.37/fs/cifs/cifs_uniupr.h 2011-01-04 19:50:19.000000000 -0500
30153 +++ linux-2.6.37/fs/cifs/cifs_uniupr.h 2011-01-17 02:41:01.000000000 -0500
30154 @@ -132,7 +132,7 @@ const struct UniCaseRange CifsUniUpperRa
30155 {0x0490, 0x04cc, UniCaseRangeU0490},
30156 {0x1e00, 0x1ffc, UniCaseRangeU1e00},
30157 {0xff40, 0xff5a, UniCaseRangeUff40},
30163 diff -urNp linux-2.6.37/fs/cifs/link.c linux-2.6.37/fs/cifs/link.c
30164 --- linux-2.6.37/fs/cifs/link.c 2011-01-04 19:50:19.000000000 -0500
30165 +++ linux-2.6.37/fs/cifs/link.c 2011-01-17 02:41:01.000000000 -0500
30166 @@ -540,7 +540,7 @@ symlink_exit:
30168 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
30170 - char *p = nd_get_link(nd);
30171 + const char *p = nd_get_link(nd);
30175 diff -urNp linux-2.6.37/fs/compat_binfmt_elf.c linux-2.6.37/fs/compat_binfmt_elf.c
30176 --- linux-2.6.37/fs/compat_binfmt_elf.c 2011-01-04 19:50:19.000000000 -0500
30177 +++ linux-2.6.37/fs/compat_binfmt_elf.c 2011-01-17 02:41:01.000000000 -0500
30178 @@ -30,11 +30,13 @@
30184 #define elfhdr elf32_hdr
30185 #define elf_phdr elf32_phdr
30186 #define elf_shdr elf32_shdr
30187 #define elf_note elf32_note
30188 +#define elf_dyn Elf32_Dyn
30189 #define elf_addr_t Elf32_Addr
30192 diff -urNp linux-2.6.37/fs/compat.c linux-2.6.37/fs/compat.c
30193 --- linux-2.6.37/fs/compat.c 2011-01-04 19:50:19.000000000 -0500
30194 +++ linux-2.6.37/fs/compat.c 2011-01-17 02:41:01.000000000 -0500
30195 @@ -592,7 +592,7 @@ ssize_t compat_rw_copy_check_uvector(int
30199 - if (nr_segs > UIO_MAXIOV || nr_segs < 0)
30200 + if (nr_segs > UIO_MAXIOV)
30202 if (nr_segs > fast_segs) {
30204 @@ -876,6 +876,7 @@ struct compat_old_linux_dirent {
30206 struct compat_readdir_callback {
30207 struct compat_old_linux_dirent __user *dirent;
30208 + struct file * file;
30212 @@ -893,6 +894,10 @@ static int compat_fillonedir(void *__buf
30213 buf->result = -EOVERFLOW;
30217 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
30221 dirent = buf->dirent;
30222 if (!access_ok(VERIFY_WRITE, dirent,
30223 @@ -925,6 +930,7 @@ asmlinkage long compat_sys_old_readdir(u
30226 buf.dirent = dirent;
30229 error = vfs_readdir(file, compat_fillonedir, &buf);
30231 @@ -945,6 +951,7 @@ struct compat_linux_dirent {
30232 struct compat_getdents_callback {
30233 struct compat_linux_dirent __user *current_dir;
30234 struct compat_linux_dirent __user *previous;
30235 + struct file * file;
30239 @@ -966,6 +973,10 @@ static int compat_filldir(void *__buf, c
30240 buf->error = -EOVERFLOW;
30244 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
30247 dirent = buf->previous;
30249 if (__put_user(offset, &dirent->d_off))
30250 @@ -1013,6 +1024,7 @@ asmlinkage long compat_sys_getdents(unsi
30251 buf.previous = NULL;
30256 error = vfs_readdir(file, compat_filldir, &buf);
30258 @@ -1034,6 +1046,7 @@ out:
30259 struct compat_getdents_callback64 {
30260 struct linux_dirent64 __user *current_dir;
30261 struct linux_dirent64 __user *previous;
30262 + struct file * file;
30266 @@ -1050,6 +1063,10 @@ static int compat_filldir64(void * __buf
30267 buf->error = -EINVAL; /* only used if we fail.. */
30268 if (reclen > buf->count)
30271 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
30274 dirent = buf->previous;
30277 @@ -1101,6 +1118,7 @@ asmlinkage long compat_sys_getdents64(un
30278 buf.previous = NULL;
30283 error = vfs_readdir(file, compat_filldir64, &buf);
30285 @@ -1419,6 +1437,7 @@ static int compat_copy_strings(int argc,
30287 page = get_arg_page(bprm, pos, 1);
30289 + /* We've exceed the stack rlimit. */
30293 @@ -1460,6 +1479,11 @@ int compat_do_execve(char * filename,
30294 compat_uptr_t __user *envp,
30295 struct pt_regs * regs)
30297 +#ifdef CONFIG_GRKERNSEC
30298 + struct file *old_exec_file;
30299 + struct acl_subject_label *old_acl;
30300 + struct rlimit old_rlim[RLIM_NLIMITS];
30302 struct linux_binprm *bprm;
30304 struct files_struct *displaced;
30305 @@ -1496,6 +1520,14 @@ int compat_do_execve(char * filename,
30306 bprm->filename = filename;
30307 bprm->interp = filename;
30309 + gr_learn_resource(current, RLIMIT_NPROC, atomic_read(¤t->cred->user->processes), 1);
30310 + retval = -EAGAIN;
30311 + if (gr_handle_nproc())
30313 + retval = -EACCES;
30314 + if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt))
30317 retval = bprm_mm_init(bprm);
30320 @@ -1525,9 +1557,40 @@ int compat_do_execve(char * filename,
30324 + if (!gr_tpe_allow(file)) {
30325 + retval = -EACCES;
30329 + if (gr_check_crash_exec(file)) {
30330 + retval = -EACCES;
30334 + gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
30336 + gr_handle_exec_args_compat(bprm, argv);
30338 +#ifdef CONFIG_GRKERNSEC
30339 + old_acl = current->acl;
30340 + memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
30341 + old_exec_file = current->exec_file;
30343 + current->exec_file = file;
30346 + retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
30347 + bprm->unsafe & LSM_UNSAFE_SHARE);
30351 retval = search_binary_handler(bprm, regs);
30355 +#ifdef CONFIG_GRKERNSEC
30356 + if (old_exec_file)
30357 + fput(old_exec_file);
30360 /* execve succeeded */
30361 current->fs->in_exec = 0;
30362 @@ -1538,6 +1601,14 @@ int compat_do_execve(char * filename,
30363 put_files_struct(displaced);
30367 +#ifdef CONFIG_GRKERNSEC
30368 + current->acl = old_acl;
30369 + memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
30370 + fput(current->exec_file);
30371 + current->exec_file = old_exec_file;
30376 acct_arg_size(bprm, 0);
30377 diff -urNp linux-2.6.37/fs/compat_ioctl.c linux-2.6.37/fs/compat_ioctl.c
30378 --- linux-2.6.37/fs/compat_ioctl.c 2011-01-04 19:50:19.000000000 -0500
30379 +++ linux-2.6.37/fs/compat_ioctl.c 2011-01-17 02:41:01.000000000 -0500
30380 @@ -208,6 +208,8 @@ static int do_video_set_spu_palette(unsi
30382 err = get_user(palp, &up->palette);
30383 err |= get_user(length, &up->length);
30387 up_native = compat_alloc_user_space(sizeof(struct video_spu_palette));
30388 err = put_user(compat_ptr(palp), &up_native->palette);
30389 @@ -1637,8 +1639,8 @@ asmlinkage long compat_sys_ioctl(unsigne
30390 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
30393 - a = *(unsigned int *)p;
30394 - b = *(unsigned int *)q;
30395 + a = *(const unsigned int *)p;
30396 + b = *(const unsigned int *)q;
30400 diff -urNp linux-2.6.37/fs/debugfs/inode.c linux-2.6.37/fs/debugfs/inode.c
30401 --- linux-2.6.37/fs/debugfs/inode.c 2011-01-04 19:50:19.000000000 -0500
30402 +++ linux-2.6.37/fs/debugfs/inode.c 2011-01-17 02:41:01.000000000 -0500
30403 @@ -130,7 +130,7 @@ static inline int debugfs_positive(struc
30405 static int debug_fill_super(struct super_block *sb, void *data, int silent)
30407 - static struct tree_descr debug_files[] = {{""}};
30408 + static struct tree_descr debug_files[] = {{"", NULL, 0}};
30410 return simple_fill_super(sb, DEBUGFS_MAGIC, debug_files);
30412 diff -urNp linux-2.6.37/fs/dlm/lockspace.c linux-2.6.37/fs/dlm/lockspace.c
30413 --- linux-2.6.37/fs/dlm/lockspace.c 2011-01-04 19:50:19.000000000 -0500
30414 +++ linux-2.6.37/fs/dlm/lockspace.c 2011-01-17 02:41:01.000000000 -0500
30415 @@ -200,7 +200,7 @@ static int dlm_uevent(struct kset *kset,
30419 -static struct kset_uevent_ops dlm_uevent_ops = {
30420 +static const struct kset_uevent_ops dlm_uevent_ops = {
30421 .uevent = dlm_uevent,
30424 diff -urNp linux-2.6.37/fs/ecryptfs/inode.c linux-2.6.37/fs/ecryptfs/inode.c
30425 --- linux-2.6.37/fs/ecryptfs/inode.c 2011-01-04 19:50:19.000000000 -0500
30426 +++ linux-2.6.37/fs/ecryptfs/inode.c 2011-01-17 02:41:01.000000000 -0500
30427 @@ -745,7 +745,7 @@ static int ecryptfs_readlink_lower(struc
30430 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
30431 - (char __user *)lower_buf,
30432 + (__force char __user *)lower_buf,
30436 @@ -791,7 +791,7 @@ static void *ecryptfs_follow_link(struct
30440 - rc = dentry->d_inode->i_op->readlink(dentry, (char __user *)buf, len);
30441 + rc = dentry->d_inode->i_op->readlink(dentry, (__force char __user *)buf, len);
30445 @@ -806,7 +806,7 @@ out:
30447 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
30449 - char *buf = nd_get_link(nd);
30450 + const char *buf = nd_get_link(nd);
30451 if (!IS_ERR(buf)) {
30452 /* Free the char* */
30454 diff -urNp linux-2.6.37/fs/ecryptfs/miscdev.c linux-2.6.37/fs/ecryptfs/miscdev.c
30455 --- linux-2.6.37/fs/ecryptfs/miscdev.c 2011-01-04 19:50:19.000000000 -0500
30456 +++ linux-2.6.37/fs/ecryptfs/miscdev.c 2011-01-17 02:41:01.000000000 -0500
30457 @@ -328,7 +328,7 @@ check_list:
30458 goto out_unlock_msg_ctx;
30460 if (msg_ctx->msg) {
30461 - if (copy_to_user(&buf[i], packet_length, packet_length_size))
30462 + if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
30463 goto out_unlock_msg_ctx;
30464 i += packet_length_size;
30465 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
30466 diff -urNp linux-2.6.37/fs/exec.c linux-2.6.37/fs/exec.c
30467 --- linux-2.6.37/fs/exec.c 2011-01-04 19:50:19.000000000 -0500
30468 +++ linux-2.6.37/fs/exec.c 2011-01-17 02:41:01.000000000 -0500
30469 @@ -55,12 +55,24 @@
30470 #include <linux/fs_struct.h>
30471 #include <linux/pipe_fs_i.h>
30472 #include <linux/oom.h>
30473 +#include <linux/random.h>
30474 +#include <linux/seq_file.h>
30476 +#ifdef CONFIG_PAX_REFCOUNT
30477 +#include <linux/kallsyms.h>
30478 +#include <linux/kdebug.h>
30481 #include <asm/uaccess.h>
30482 #include <asm/mmu_context.h>
30483 #include <asm/tlb.h>
30484 #include "internal.h"
30486 +#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
30487 +void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
30488 +EXPORT_SYMBOL(pax_set_initial_flags_func);
30492 char core_pattern[CORENAME_MAX_SIZE] = "core";
30493 unsigned int core_pipe_limit;
30494 @@ -120,7 +132,7 @@ SYSCALL_DEFINE1(uselib, const char __use
30497 file = do_filp_open(AT_FDCWD, tmp,
30498 - O_LARGEFILE | O_RDONLY | FMODE_EXEC, 0,
30499 + O_LARGEFILE | O_RDONLY | FMODE_EXEC | FMODE_GREXEC, 0,
30500 MAY_READ | MAY_EXEC | MAY_OPEN);
30502 error = PTR_ERR(file);
30503 @@ -187,18 +199,10 @@ struct page *get_arg_page(struct linux_b
30509 -#ifdef CONFIG_STACK_GROWSUP
30511 - ret = expand_stack_downwards(bprm->vma, pos);
30516 - ret = get_user_pages(current, bprm->mm, pos,
30517 - 1, write, 1, &page, NULL);
30519 + if (0 > expand_stack_downwards(bprm->vma, pos))
30521 + if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
30525 @@ -273,6 +277,11 @@ static int __bprm_mm_init(struct linux_b
30526 vma->vm_end = STACK_TOP_MAX;
30527 vma->vm_start = vma->vm_end - PAGE_SIZE;
30528 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
30530 +#ifdef CONFIG_PAX_SEGMEXEC
30531 + vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
30534 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
30535 INIT_LIST_HEAD(&vma->anon_vma_chain);
30537 @@ -287,6 +296,12 @@ static int __bprm_mm_init(struct linux_b
30538 mm->stack_vm = mm->total_vm = 1;
30539 up_write(&mm->mmap_sem);
30540 bprm->p = vma->vm_end - sizeof(void *);
30542 +#ifdef CONFIG_PAX_RANDUSTACK
30543 + if (randomize_va_space)
30544 + bprm->p ^= (pax_get_random_long() & ~15) & ~PAGE_MASK;
30549 up_write(&mm->mmap_sem);
30550 @@ -522,7 +537,7 @@ int copy_strings_kernel(int argc, const
30552 mm_segment_t oldfs = get_fs();
30554 - r = copy_strings(argc, (const char __user *const __user *)argv, bprm);
30555 + r = copy_strings(argc, (__force const char __user *const __user *)argv, bprm);
30559 @@ -552,7 +567,8 @@ static int shift_arg_pages(struct vm_are
30560 unsigned long new_end = old_end - shift;
30561 struct mmu_gather *tlb;
30563 - BUG_ON(new_start > new_end);
30564 + if (new_start >= new_end || new_start < mmap_min_addr)
30568 * ensure there are no vmas between where we want to go
30569 @@ -561,6 +577,10 @@ static int shift_arg_pages(struct vm_are
30570 if (vma != find_vma(mm, new_start))
30573 +#ifdef CONFIG_PAX_SEGMEXEC
30574 + BUG_ON(pax_find_mirror_vma(vma));
30578 * cover the whole range: [new_start, old_end)
30580 @@ -641,10 +661,6 @@ int setup_arg_pages(struct linux_binprm
30581 stack_top = arch_align_stack(stack_top);
30582 stack_top = PAGE_ALIGN(stack_top);
30584 - if (unlikely(stack_top < mmap_min_addr) ||
30585 - unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
30588 stack_shift = vma->vm_end - stack_top;
30590 bprm->p -= stack_shift;
30591 @@ -656,8 +672,28 @@ int setup_arg_pages(struct linux_binprm
30592 bprm->exec -= stack_shift;
30594 down_write(&mm->mmap_sem);
30596 + /* Move stack pages down in memory. */
30597 + if (stack_shift) {
30598 + ret = shift_arg_pages(vma, stack_shift);
30603 vm_flags = VM_STACK_FLAGS;
30605 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
30606 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
30607 + vm_flags &= ~VM_EXEC;
30609 +#ifdef CONFIG_PAX_MPROTECT
30610 + if (mm->pax_flags & MF_PAX_MPROTECT)
30611 + vm_flags &= ~VM_MAYEXEC;
30618 * Adjust stack execute permissions; explicitly enable for
30619 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
30620 @@ -676,13 +712,6 @@ int setup_arg_pages(struct linux_binprm
30622 BUG_ON(prev != vma);
30624 - /* Move stack pages down in memory. */
30625 - if (stack_shift) {
30626 - ret = shift_arg_pages(vma, stack_shift);
30631 /* mprotect_fixup is overkill to remove the temporary stack flags */
30632 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
30634 @@ -723,7 +752,7 @@ struct file *open_exec(const char *name)
30637 file = do_filp_open(AT_FDCWD, name,
30638 - O_LARGEFILE | O_RDONLY | FMODE_EXEC, 0,
30639 + O_LARGEFILE | O_RDONLY | FMODE_EXEC | FMODE_GREXEC, 0,
30640 MAY_EXEC | MAY_OPEN);
30643 @@ -760,7 +789,7 @@ int kernel_read(struct file *file, loff_
30646 /* The cast to a user pointer is valid due to the set_fs() */
30647 - result = vfs_read(file, (void __user *)addr, count, &pos);
30648 + result = vfs_read(file, (__force void __user *)addr, count, &pos);
30652 @@ -1182,7 +1211,7 @@ int check_unsafe_exec(struct linux_binpr
30656 - if (p->fs->users > n_fs) {
30657 + if (atomic_read(&p->fs->users) > n_fs) {
30658 bprm->unsafe |= LSM_UNSAFE_SHARE;
30661 @@ -1378,6 +1407,11 @@ int do_execve(const char * filename,
30662 const char __user *const __user *envp,
30663 struct pt_regs * regs)
30665 +#ifdef CONFIG_GRKERNSEC
30666 + struct file *old_exec_file;
30667 + struct acl_subject_label *old_acl;
30668 + struct rlimit old_rlim[RLIM_NLIMITS];
30670 struct linux_binprm *bprm;
30672 struct files_struct *displaced;
30673 @@ -1414,6 +1448,18 @@ int do_execve(const char * filename,
30674 bprm->filename = filename;
30675 bprm->interp = filename;
30677 + gr_learn_resource(current, RLIMIT_NPROC, atomic_read(¤t->cred->user->processes), 1);
30679 + if (gr_handle_nproc()) {
30680 + retval = -EAGAIN;
30684 + if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
30685 + retval = -EACCES;
30689 retval = bprm_mm_init(bprm);
30692 @@ -1443,9 +1489,40 @@ int do_execve(const char * filename,
30696 + if (!gr_tpe_allow(file)) {
30697 + retval = -EACCES;
30701 + if (gr_check_crash_exec(file)) {
30702 + retval = -EACCES;
30706 + gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
30708 + gr_handle_exec_args(bprm, argv);
30710 +#ifdef CONFIG_GRKERNSEC
30711 + old_acl = current->acl;
30712 + memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
30713 + old_exec_file = current->exec_file;
30715 + current->exec_file = file;
30718 + retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
30719 + bprm->unsafe & LSM_UNSAFE_SHARE);
30723 retval = search_binary_handler(bprm,regs);
30727 +#ifdef CONFIG_GRKERNSEC
30728 + if (old_exec_file)
30729 + fput(old_exec_file);
30732 /* execve succeeded */
30733 current->fs->in_exec = 0;
30734 @@ -1456,6 +1533,14 @@ int do_execve(const char * filename,
30735 put_files_struct(displaced);
30739 +#ifdef CONFIG_GRKERNSEC
30740 + current->acl = old_acl;
30741 + memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
30742 + fput(current->exec_file);
30743 + current->exec_file = old_exec_file;
30748 acct_arg_size(bprm, 0);
30749 @@ -1642,6 +1727,217 @@ out:
30753 +int pax_check_flags(unsigned long *flags)
30757 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
30758 + if (*flags & MF_PAX_SEGMEXEC)
30760 + *flags &= ~MF_PAX_SEGMEXEC;
30761 + retval = -EINVAL;
30765 + if ((*flags & MF_PAX_PAGEEXEC)
30767 +#ifdef CONFIG_PAX_PAGEEXEC
30768 + && (*flags & MF_PAX_SEGMEXEC)
30773 + *flags &= ~MF_PAX_PAGEEXEC;
30774 + retval = -EINVAL;
30777 + if ((*flags & MF_PAX_MPROTECT)
30779 +#ifdef CONFIG_PAX_MPROTECT
30780 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
30785 + *flags &= ~MF_PAX_MPROTECT;
30786 + retval = -EINVAL;
30789 + if ((*flags & MF_PAX_EMUTRAMP)
30791 +#ifdef CONFIG_PAX_EMUTRAMP
30792 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
30797 + *flags &= ~MF_PAX_EMUTRAMP;
30798 + retval = -EINVAL;
30804 +EXPORT_SYMBOL(pax_check_flags);
30806 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
30807 +void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
30809 + struct task_struct *tsk = current;
30810 + struct mm_struct *mm = current->mm;
30811 + char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
30812 + char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
30813 + char *path_exec = NULL;
30814 + char *path_fault = NULL;
30815 + unsigned long start = 0UL, end = 0UL, offset = 0UL;
30817 + if (buffer_exec && buffer_fault) {
30818 + struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
30820 + down_read(&mm->mmap_sem);
30822 + while (vma && (!vma_exec || !vma_fault)) {
30823 + if ((vma->vm_flags & VM_EXECUTABLE) && vma->vm_file)
30825 + if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
30827 + vma = vma->vm_next;
30830 + path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
30831 + if (IS_ERR(path_exec))
30832 + path_exec = "<path too long>";
30834 + path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
30837 + path_exec = buffer_exec;
30839 + path_exec = "<path too long>";
30843 + start = vma_fault->vm_start;
30844 + end = vma_fault->vm_end;
30845 + offset = vma_fault->vm_pgoff << PAGE_SHIFT;
30846 + if (vma_fault->vm_file) {
30847 + path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
30848 + if (IS_ERR(path_fault))
30849 + path_fault = "<path too long>";
30851 + path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
30852 + if (path_fault) {
30854 + path_fault = buffer_fault;
30856 + path_fault = "<path too long>";
30859 + path_fault = "<anonymous mapping>";
30861 + up_read(&mm->mmap_sem);
30863 + if (tsk->signal->curr_ip)
30864 + printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
30866 + printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
30867 + printk(KERN_ERR "PAX: terminating task: %s(%s):%d, uid/euid: %u/%u, "
30868 + "PC: %p, SP: %p\n", path_exec, tsk->comm, task_pid_nr(tsk),
30869 + task_uid(tsk), task_euid(tsk), pc, sp);
30870 + free_page((unsigned long)buffer_exec);
30871 + free_page((unsigned long)buffer_fault);
30872 + pax_report_insns(pc, sp);
30873 + do_coredump(SIGKILL, SIGKILL, regs);
30877 +#ifdef CONFIG_PAX_REFCOUNT
30878 +void pax_report_refcount_overflow(struct pt_regs *regs)
30880 + if (current->signal->curr_ip)
30881 + printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
30882 + ¤t->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
30884 + printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
30885 + current->comm, task_pid_nr(current), current_uid(), current_euid());
30886 + print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
30888 + force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
30892 +#ifdef CONFIG_PAX_USERCOPY
30893 +/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
30894 +int object_is_on_stack(const void *obj, unsigned long len)
30896 + const void * const stack = task_stack_page(current);
30897 + const void * const stackend = stack + THREAD_SIZE;
30899 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
30900 + const void *frame = NULL;
30901 + const void *oldframe;
30904 + if (obj + len < obj)
30907 + if (obj + len <= stack || stackend <= obj)
30910 + if (obj < stack || stackend < obj + len)
30913 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
30914 + oldframe = __builtin_frame_address(1);
30916 + frame = __builtin_frame_address(2);
30918 + low ----------------------------------------------> high
30919 + [saved bp][saved ip][args][local vars][saved bp][saved ip]
30920 + ^----------------^
30921 + allow copies only within here
30923 + while (stack <= frame && frame < stackend) {
30924 + /* if obj + len extends past the last frame, this
30925 + check won't pass and the next frame will be 0,
30926 + causing us to bail out and correctly report
30927 + the copy as invalid
30929 + if (obj + len <= frame)
30930 + return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
30931 + oldframe = frame;
30932 + frame = *(const void * const *)frame;
30941 +void pax_report_leak_to_user(const void *ptr, unsigned long len)
30943 + if (current->signal->curr_ip)
30944 + printk(KERN_ERR "PAX: From %pI4: kernel memory leak attempt detected from %p (%lu bytes)\n",
30945 + ¤t->signal->curr_ip, ptr, len);
30947 + printk(KERN_ERR "PAX: kernel memory leak attempt detected from %p (%lu bytes)\n", ptr, len);
30949 + do_group_exit(SIGKILL);
30952 +void pax_report_overflow_from_user(const void *ptr, unsigned long len)
30954 + if (current->signal->curr_ip)
30955 + printk(KERN_ERR "PAX: From %pI4: kernel memory overflow attempt detected to %p (%lu bytes)\n",
30956 + ¤t->signal->curr_ip, ptr, len);
30958 + printk(KERN_ERR "PAX: kernel memory overflow attempt detected to %p (%lu bytes)\n", ptr, len);
30960 + do_group_exit(SIGKILL);
30964 static int zap_process(struct task_struct *start, int exit_code)
30966 struct task_struct *t;
30967 @@ -1852,17 +2148,17 @@ static void wait_for_dump_helpers(struct
30968 pipe = file->f_path.dentry->d_inode->i_pipe;
30973 + atomic_inc(&pipe->readers);
30974 + atomic_dec(&pipe->writers);
30976 - while ((pipe->readers > 1) && (!signal_pending(current))) {
30977 + while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
30978 wake_up_interruptible_sync(&pipe->wait);
30979 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
30985 + atomic_dec(&pipe->readers);
30986 + atomic_inc(&pipe->writers);
30990 @@ -1978,6 +2274,10 @@ void do_coredump(long signr, int exit_co
30991 goto fail_corename;
30994 + if (signr == SIGKILL || signr == SIGILL)
30995 + gr_handle_brute_attach(current);
30996 + gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
31000 char **helper_argv;
31001 diff -urNp linux-2.6.37/fs/ext2/balloc.c linux-2.6.37/fs/ext2/balloc.c
31002 --- linux-2.6.37/fs/ext2/balloc.c 2011-01-04 19:50:19.000000000 -0500
31003 +++ linux-2.6.37/fs/ext2/balloc.c 2011-01-17 02:41:01.000000000 -0500
31004 @@ -1192,7 +1192,7 @@ static int ext2_has_free_blocks(struct e
31006 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
31007 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
31008 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
31009 + if (free_blocks < root_blocks + 1 && !capable_nolog(CAP_SYS_RESOURCE) &&
31010 sbi->s_resuid != current_fsuid() &&
31011 (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
31013 diff -urNp linux-2.6.37/fs/ext2/xattr.c linux-2.6.37/fs/ext2/xattr.c
31014 --- linux-2.6.37/fs/ext2/xattr.c 2011-01-04 19:50:19.000000000 -0500
31015 +++ linux-2.6.37/fs/ext2/xattr.c 2011-01-17 02:41:01.000000000 -0500
31020 -# define ea_idebug(f...)
31021 -# define ea_bdebug(f...)
31022 +# define ea_idebug(inode, f...) do {} while (0)
31023 +# define ea_bdebug(bh, f...) do {} while (0)
31026 static int ext2_xattr_set2(struct inode *, struct buffer_head *,
31027 diff -urNp linux-2.6.37/fs/ext3/balloc.c linux-2.6.37/fs/ext3/balloc.c
31028 --- linux-2.6.37/fs/ext3/balloc.c 2011-01-04 19:50:19.000000000 -0500
31029 +++ linux-2.6.37/fs/ext3/balloc.c 2011-01-17 02:41:01.000000000 -0500
31030 @@ -1425,7 +1425,7 @@ static int ext3_has_free_blocks(struct e
31032 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
31033 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
31034 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
31035 + if (free_blocks < root_blocks + 1 && !capable_nolog(CAP_SYS_RESOURCE) &&
31036 sbi->s_resuid != current_fsuid() &&
31037 (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
31039 diff -urNp linux-2.6.37/fs/ext3/namei.c linux-2.6.37/fs/ext3/namei.c
31040 --- linux-2.6.37/fs/ext3/namei.c 2011-01-04 19:50:19.000000000 -0500
31041 +++ linux-2.6.37/fs/ext3/namei.c 2011-01-17 02:41:01.000000000 -0500
31042 @@ -1168,7 +1168,7 @@ static struct ext3_dir_entry_2 *do_split
31043 char *data1 = (*bh)->b_data, *data2;
31044 unsigned split, move, size;
31045 struct ext3_dir_entry_2 *de = NULL, *de2;
31049 bh2 = ext3_append (handle, dir, &newblock, &err);
31051 diff -urNp linux-2.6.37/fs/ext3/xattr.c linux-2.6.37/fs/ext3/xattr.c
31052 --- linux-2.6.37/fs/ext3/xattr.c 2011-01-04 19:50:19.000000000 -0500
31053 +++ linux-2.6.37/fs/ext3/xattr.c 2011-01-17 02:41:01.000000000 -0500
31058 -# define ea_idebug(f...)
31059 -# define ea_bdebug(f...)
31060 +# define ea_idebug(f...) do {} while (0)
31061 +# define ea_bdebug(f...) do {} while (0)
31064 static void ext3_xattr_cache_insert(struct buffer_head *);
31065 diff -urNp linux-2.6.37/fs/ext4/balloc.c linux-2.6.37/fs/ext4/balloc.c
31066 --- linux-2.6.37/fs/ext4/balloc.c 2011-01-04 19:50:19.000000000 -0500
31067 +++ linux-2.6.37/fs/ext4/balloc.c 2011-01-17 02:41:01.000000000 -0500
31068 @@ -519,7 +519,7 @@ static int ext4_has_free_blocks(struct e
31069 /* Hm, nope. Are (enough) root reserved blocks available? */
31070 if (sbi->s_resuid == current_fsuid() ||
31071 ((sbi->s_resgid != 0) && in_group_p(sbi->s_resgid)) ||
31072 - capable(CAP_SYS_RESOURCE)) {
31073 + capable_nolog(CAP_SYS_RESOURCE)) {
31074 if (free_blocks >= (nblocks + dirty_blocks))
31077 diff -urNp linux-2.6.37/fs/ext4/ext4.h linux-2.6.37/fs/ext4/ext4.h
31078 --- linux-2.6.37/fs/ext4/ext4.h 2011-01-04 19:50:19.000000000 -0500
31079 +++ linux-2.6.37/fs/ext4/ext4.h 2011-01-17 02:41:01.000000000 -0500
31080 @@ -1164,19 +1164,19 @@ struct ext4_sb_info {
31081 unsigned long s_mb_last_start;
31083 /* stats for buddy allocator */
31084 - atomic_t s_bal_reqs; /* number of reqs with len > 1 */
31085 - atomic_t s_bal_success; /* we found long enough chunks */
31086 - atomic_t s_bal_allocated; /* in blocks */
31087 - atomic_t s_bal_ex_scanned; /* total extents scanned */
31088 - atomic_t s_bal_goals; /* goal hits */
31089 - atomic_t s_bal_breaks; /* too long searches */
31090 - atomic_t s_bal_2orders; /* 2^order hits */
31091 + atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
31092 + atomic_unchecked_t s_bal_success; /* we found long enough chunks */
31093 + atomic_unchecked_t s_bal_allocated; /* in blocks */
31094 + atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
31095 + atomic_unchecked_t s_bal_goals; /* goal hits */
31096 + atomic_unchecked_t s_bal_breaks; /* too long searches */
31097 + atomic_unchecked_t s_bal_2orders; /* 2^order hits */
31098 spinlock_t s_bal_lock;
31099 unsigned long s_mb_buddies_generated;
31100 unsigned long long s_mb_generation_time;
31101 - atomic_t s_mb_lost_chunks;
31102 - atomic_t s_mb_preallocated;
31103 - atomic_t s_mb_discarded;
31104 + atomic_unchecked_t s_mb_lost_chunks;
31105 + atomic_unchecked_t s_mb_preallocated;
31106 + atomic_unchecked_t s_mb_discarded;
31107 atomic_t s_lock_busy;
31109 /* locality groups */
31110 diff -urNp linux-2.6.37/fs/ext4/mballoc.c linux-2.6.37/fs/ext4/mballoc.c
31111 --- linux-2.6.37/fs/ext4/mballoc.c 2011-01-04 19:50:19.000000000 -0500
31112 +++ linux-2.6.37/fs/ext4/mballoc.c 2011-01-17 02:41:01.000000000 -0500
31113 @@ -1841,7 +1841,7 @@ void ext4_mb_simple_scan_group(struct ex
31114 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
31116 if (EXT4_SB(sb)->s_mb_stats)
31117 - atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
31118 + atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
31122 @@ -2135,7 +2135,7 @@ repeat:
31123 ac->ac_status = AC_STATUS_CONTINUE;
31124 ac->ac_flags |= EXT4_MB_HINT_FIRST;
31126 - atomic_inc(&sbi->s_mb_lost_chunks);
31127 + atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
31131 @@ -2577,25 +2577,25 @@ int ext4_mb_release(struct super_block *
31132 if (sbi->s_mb_stats) {
31134 "EXT4-fs: mballoc: %u blocks %u reqs (%u success)\n",
31135 - atomic_read(&sbi->s_bal_allocated),
31136 - atomic_read(&sbi->s_bal_reqs),
31137 - atomic_read(&sbi->s_bal_success));
31138 + atomic_read_unchecked(&sbi->s_bal_allocated),
31139 + atomic_read_unchecked(&sbi->s_bal_reqs),
31140 + atomic_read_unchecked(&sbi->s_bal_success));
31142 "EXT4-fs: mballoc: %u extents scanned, %u goal hits, "
31143 "%u 2^N hits, %u breaks, %u lost\n",
31144 - atomic_read(&sbi->s_bal_ex_scanned),
31145 - atomic_read(&sbi->s_bal_goals),
31146 - atomic_read(&sbi->s_bal_2orders),
31147 - atomic_read(&sbi->s_bal_breaks),
31148 - atomic_read(&sbi->s_mb_lost_chunks));
31149 + atomic_read_unchecked(&sbi->s_bal_ex_scanned),
31150 + atomic_read_unchecked(&sbi->s_bal_goals),
31151 + atomic_read_unchecked(&sbi->s_bal_2orders),
31152 + atomic_read_unchecked(&sbi->s_bal_breaks),
31153 + atomic_read_unchecked(&sbi->s_mb_lost_chunks));
31155 "EXT4-fs: mballoc: %lu generated and it took %Lu\n",
31156 sbi->s_mb_buddies_generated++,
31157 sbi->s_mb_generation_time);
31159 "EXT4-fs: mballoc: %u preallocated, %u discarded\n",
31160 - atomic_read(&sbi->s_mb_preallocated),
31161 - atomic_read(&sbi->s_mb_discarded));
31162 + atomic_read_unchecked(&sbi->s_mb_preallocated),
31163 + atomic_read_unchecked(&sbi->s_mb_discarded));
31166 free_percpu(sbi->s_locality_groups);
31167 @@ -3080,16 +3080,16 @@ static void ext4_mb_collect_stats(struct
31168 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
31170 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
31171 - atomic_inc(&sbi->s_bal_reqs);
31172 - atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
31173 + atomic_inc_unchecked(&sbi->s_bal_reqs);
31174 + atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
31175 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
31176 - atomic_inc(&sbi->s_bal_success);
31177 - atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
31178 + atomic_inc_unchecked(&sbi->s_bal_success);
31179 + atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
31180 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
31181 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
31182 - atomic_inc(&sbi->s_bal_goals);
31183 + atomic_inc_unchecked(&sbi->s_bal_goals);
31184 if (ac->ac_found > sbi->s_mb_max_to_scan)
31185 - atomic_inc(&sbi->s_bal_breaks);
31186 + atomic_inc_unchecked(&sbi->s_bal_breaks);
31189 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
31190 @@ -3487,7 +3487,7 @@ ext4_mb_new_inode_pa(struct ext4_allocat
31191 trace_ext4_mb_new_inode_pa(ac, pa);
31193 ext4_mb_use_inode_pa(ac, pa);
31194 - atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
31195 + atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
31197 ei = EXT4_I(ac->ac_inode);
31198 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
31199 @@ -3547,7 +3547,7 @@ ext4_mb_new_group_pa(struct ext4_allocat
31200 trace_ext4_mb_new_group_pa(ac, pa);
31202 ext4_mb_use_group_pa(ac, pa);
31203 - atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
31204 + atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
31206 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
31208 @@ -3634,7 +3634,7 @@ ext4_mb_release_inode_pa(struct ext4_bud
31209 * from the bitmap and continue.
31212 - atomic_add(free, &sbi->s_mb_discarded);
31213 + atomic_add_unchecked(free, &sbi->s_mb_discarded);
31217 @@ -3652,7 +3652,7 @@ ext4_mb_release_group_pa(struct ext4_bud
31218 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
31219 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
31220 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
31221 - atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
31222 + atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
31223 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
31226 diff -urNp linux-2.6.37/fs/ext4/namei.c linux-2.6.37/fs/ext4/namei.c
31227 --- linux-2.6.37/fs/ext4/namei.c 2011-01-04 19:50:19.000000000 -0500
31228 +++ linux-2.6.37/fs/ext4/namei.c 2011-01-17 02:41:01.000000000 -0500
31229 @@ -1161,7 +1161,7 @@ static struct ext4_dir_entry_2 *do_split
31230 char *data1 = (*bh)->b_data, *data2;
31231 unsigned split, move, size;
31232 struct ext4_dir_entry_2 *de = NULL, *de2;
31236 bh2 = ext4_append (handle, dir, &newblock, &err);
31238 diff -urNp linux-2.6.37/fs/ext4/xattr.c linux-2.6.37/fs/ext4/xattr.c
31239 --- linux-2.6.37/fs/ext4/xattr.c 2011-01-04 19:50:19.000000000 -0500
31240 +++ linux-2.6.37/fs/ext4/xattr.c 2011-01-17 02:41:01.000000000 -0500
31245 -# define ea_idebug(f...)
31246 -# define ea_bdebug(f...)
31247 +# define ea_idebug(inode, f...) do {} while (0)
31248 +# define ea_bdebug(bh, f...) do {} while (0)
31251 static void ext4_xattr_cache_insert(struct buffer_head *);
31252 diff -urNp linux-2.6.37/fs/fcntl.c linux-2.6.37/fs/fcntl.c
31253 --- linux-2.6.37/fs/fcntl.c 2011-01-04 19:50:19.000000000 -0500
31254 +++ linux-2.6.37/fs/fcntl.c 2011-01-17 02:53:49.000000000 -0500
31255 @@ -224,6 +224,11 @@ int __f_setown(struct file *filp, struct
31259 + if (gr_handle_chroot_fowner(pid, type))
31261 + if (gr_check_protected_task_fowner(pid, type))
31264 f_modown(filp, pid, type, force);
31267 @@ -348,6 +353,7 @@ static long do_fcntl(int fd, unsigned in
31270 case F_DUPFD_CLOEXEC:
31271 + gr_learn_resource(current, RLIMIT_NOFILE, arg, 0);
31272 if (arg >= rlimit(RLIMIT_NOFILE))
31274 err = alloc_fd(arg, cmd == F_DUPFD_CLOEXEC ? O_CLOEXEC : 0);
31275 @@ -808,14 +814,14 @@ static int __init fcntl_init(void)
31276 * Exceptions: O_NONBLOCK is a two bit define on parisc; O_NDELAY
31277 * is defined as O_NONBLOCK on some platforms and not on others.
31279 - BUILD_BUG_ON(18 - 1 /* for O_RDONLY being 0 */ != HWEIGHT32(
31280 + BUILD_BUG_ON(19 - 1 /* for O_RDONLY being 0 */ != HWEIGHT32(
31281 O_RDONLY | O_WRONLY | O_RDWR |
31282 O_CREAT | O_EXCL | O_NOCTTY |
31283 O_TRUNC | O_APPEND | /* O_NONBLOCK | */
31284 __O_SYNC | O_DSYNC | FASYNC |
31285 O_DIRECT | O_LARGEFILE | O_DIRECTORY |
31286 O_NOFOLLOW | O_NOATIME | O_CLOEXEC |
31288 + FMODE_EXEC | FMODE_GREXEC
31291 fasync_cache = kmem_cache_create("fasync_cache",
31292 diff -urNp linux-2.6.37/fs/fifo.c linux-2.6.37/fs/fifo.c
31293 --- linux-2.6.37/fs/fifo.c 2011-01-04 19:50:19.000000000 -0500
31294 +++ linux-2.6.37/fs/fifo.c 2011-01-17 02:41:01.000000000 -0500
31295 @@ -58,10 +58,10 @@ static int fifo_open(struct inode *inode
31297 filp->f_op = &read_pipefifo_fops;
31299 - if (pipe->readers++ == 0)
31300 + if (atomic_inc_return(&pipe->readers) == 1)
31301 wake_up_partner(inode);
31303 - if (!pipe->writers) {
31304 + if (!atomic_read(&pipe->writers)) {
31305 if ((filp->f_flags & O_NONBLOCK)) {
31306 /* suppress POLLHUP until we have
31308 @@ -82,15 +82,15 @@ static int fifo_open(struct inode *inode
31309 * errno=ENXIO when there is no process reading the FIFO.
31312 - if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
31313 + if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
31316 filp->f_op = &write_pipefifo_fops;
31318 - if (!pipe->writers++)
31319 + if (atomic_inc_return(&pipe->writers) == 1)
31320 wake_up_partner(inode);
31322 - if (!pipe->readers) {
31323 + if (!atomic_read(&pipe->readers)) {
31324 wait_for_partner(inode, &pipe->r_counter);
31325 if (signal_pending(current))
31327 @@ -106,11 +106,11 @@ static int fifo_open(struct inode *inode
31329 filp->f_op = &rdwr_pipefifo_fops;
31333 + atomic_inc(&pipe->readers);
31334 + atomic_inc(&pipe->writers);
31337 - if (pipe->readers == 1 || pipe->writers == 1)
31338 + if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
31339 wake_up_partner(inode);
31342 @@ -124,19 +124,19 @@ static int fifo_open(struct inode *inode
31346 - if (!--pipe->readers)
31347 + if (atomic_dec_and_test(&pipe->readers))
31348 wake_up_interruptible(&pipe->wait);
31349 ret = -ERESTARTSYS;
31353 - if (!--pipe->writers)
31354 + if (atomic_dec_and_test(&pipe->writers))
31355 wake_up_interruptible(&pipe->wait);
31356 ret = -ERESTARTSYS;
31360 - if (!pipe->readers && !pipe->writers)
31361 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
31362 free_pipe_info(inode);
31365 diff -urNp linux-2.6.37/fs/file.c linux-2.6.37/fs/file.c
31366 --- linux-2.6.37/fs/file.c 2011-01-04 19:50:19.000000000 -0500
31367 +++ linux-2.6.37/fs/file.c 2011-01-17 02:41:01.000000000 -0500
31369 #include <linux/slab.h>
31370 #include <linux/vmalloc.h>
31371 #include <linux/file.h>
31372 +#include <linux/security.h>
31373 #include <linux/fdtable.h>
31374 #include <linux/bitops.h>
31375 #include <linux/interrupt.h>
31376 @@ -250,6 +251,7 @@ int expand_files(struct files_struct *fi
31377 * N.B. For clone tasks sharing a files structure, this test
31378 * will limit the total number of files that can be opened.
31380 + gr_learn_resource(current, RLIMIT_NOFILE, nr, 0);
31381 if (nr >= rlimit(RLIMIT_NOFILE))
31384 diff -urNp linux-2.6.37/fs/fs_struct.c linux-2.6.37/fs/fs_struct.c
31385 --- linux-2.6.37/fs/fs_struct.c 2011-01-04 19:50:19.000000000 -0500
31386 +++ linux-2.6.37/fs/fs_struct.c 2011-01-17 02:41:01.000000000 -0500
31388 #include <linux/slab.h>
31389 #include <linux/fs_struct.h>
31390 #include <linux/vserver/global.h>
31391 +#include <linux/grsecurity.h>
31394 * Replace the fs->{rootmnt,root} with {mnt,dentry}. Put the old values.
31395 @@ -17,6 +18,7 @@ void set_fs_root(struct fs_struct *fs, s
31396 old_root = fs->root;
31399 + gr_set_chroot_entries(current, path);
31400 spin_unlock(&fs->lock);
31401 if (old_root.dentry)
31402 path_put(&old_root);
31403 @@ -56,6 +58,7 @@ void chroot_fs_refs(struct path *old_roo
31404 && fs->root.mnt == old_root->mnt) {
31405 path_get(new_root);
31406 fs->root = *new_root;
31407 + gr_set_chroot_entries(p, new_root);
31410 if (fs->pwd.dentry == old_root->dentry
31411 @@ -89,7 +92,8 @@ void exit_fs(struct task_struct *tsk)
31413 spin_lock(&fs->lock);
31415 - kill = !--fs->users;
31416 + gr_clear_chroot_entries(tsk);
31417 + kill = !atomic_dec_return(&fs->users);
31418 spin_unlock(&fs->lock);
31421 @@ -102,7 +106,7 @@ struct fs_struct *copy_fs_struct(struct
31422 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
31423 /* We don't need to lock fs - think why ;-) */
31426 + atomic_set(&fs->users, 1);
31428 spin_lock_init(&fs->lock);
31429 fs->umask = old->umask;
31430 @@ -122,8 +126,9 @@ int unshare_fs_struct(void)
31432 task_lock(current);
31433 spin_lock(&fs->lock);
31434 - kill = !--fs->users;
31435 + kill = !atomic_dec_return(&fs->users);
31436 current->fs = new_fs;
31437 + gr_set_chroot_entries(current, &new_fs->root);
31438 spin_unlock(&fs->lock);
31439 task_unlock(current);
31441 @@ -142,7 +147,7 @@ EXPORT_SYMBOL(current_umask);
31443 /* to be mentioned only in INIT_TASK */
31444 struct fs_struct init_fs = {
31446 + .users = ATOMIC_INIT(1),
31447 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
31450 @@ -157,12 +162,13 @@ void daemonize_fs_struct(void)
31451 task_lock(current);
31453 spin_lock(&init_fs.lock);
31455 + atomic_inc(&init_fs.users);
31456 spin_unlock(&init_fs.lock);
31458 spin_lock(&fs->lock);
31459 current->fs = &init_fs;
31460 - kill = !--fs->users;
31461 + gr_set_chroot_entries(current, ¤t->fs->root);
31462 + kill = !atomic_dec_return(&fs->users);
31463 spin_unlock(&fs->lock);
31465 task_unlock(current);
31466 diff -urNp linux-2.6.37/fs/fuse/control.c linux-2.6.37/fs/fuse/control.c
31467 --- linux-2.6.37/fs/fuse/control.c 2011-01-04 19:50:19.000000000 -0500
31468 +++ linux-2.6.37/fs/fuse/control.c 2011-01-17 02:41:01.000000000 -0500
31469 @@ -298,7 +298,7 @@ void fuse_ctl_remove_conn(struct fuse_co
31471 static int fuse_ctl_fill_super(struct super_block *sb, void *data, int silent)
31473 - struct tree_descr empty_descr = {""};
31474 + struct tree_descr empty_descr = {"", NULL, 0};
31475 struct fuse_conn *fc;
31478 diff -urNp linux-2.6.37/fs/fuse/cuse.c linux-2.6.37/fs/fuse/cuse.c
31479 --- linux-2.6.37/fs/fuse/cuse.c 2011-01-04 19:50:19.000000000 -0500
31480 +++ linux-2.6.37/fs/fuse/cuse.c 2011-01-17 02:41:01.000000000 -0500
31481 @@ -530,8 +530,18 @@ static int cuse_channel_release(struct i
31485 -static struct file_operations cuse_channel_fops; /* initialized during init */
31487 +static const struct file_operations cuse_channel_fops = { /* initialized during init */
31488 + .owner = THIS_MODULE,
31489 + .llseek = no_llseek,
31490 + .read = do_sync_read,
31491 + .aio_read = fuse_dev_read,
31492 + .write = do_sync_write,
31493 + .aio_write = fuse_dev_write,
31494 + .poll = fuse_dev_poll,
31495 + .open = cuse_channel_open,
31496 + .release = cuse_channel_release,
31497 + .fasync = fuse_dev_fasync,
31500 /**************************************************************************
31501 * Misc stuff and module initializatiion
31502 @@ -577,12 +587,6 @@ static int __init cuse_init(void)
31503 for (i = 0; i < CUSE_CONNTBL_LEN; i++)
31504 INIT_LIST_HEAD(&cuse_conntbl[i]);
31506 - /* inherit and extend fuse_dev_operations */
31507 - cuse_channel_fops = fuse_dev_operations;
31508 - cuse_channel_fops.owner = THIS_MODULE;
31509 - cuse_channel_fops.open = cuse_channel_open;
31510 - cuse_channel_fops.release = cuse_channel_release;
31512 cuse_class = class_create(THIS_MODULE, "cuse");
31513 if (IS_ERR(cuse_class))
31514 return PTR_ERR(cuse_class);
31515 diff -urNp linux-2.6.37/fs/fuse/dev.c linux-2.6.37/fs/fuse/dev.c
31516 --- linux-2.6.37/fs/fuse/dev.c 2011-01-04 19:50:19.000000000 -0500
31517 +++ linux-2.6.37/fs/fuse/dev.c 2011-01-17 02:41:01.000000000 -0500
31518 @@ -1047,7 +1047,7 @@ static ssize_t fuse_dev_do_read(struct f
31522 -static ssize_t fuse_dev_read(struct kiocb *iocb, const struct iovec *iov,
31523 +ssize_t fuse_dev_read(struct kiocb *iocb, const struct iovec *iov,
31524 unsigned long nr_segs, loff_t pos)
31526 struct fuse_copy_state cs;
31527 @@ -1061,6 +1061,8 @@ static ssize_t fuse_dev_read(struct kioc
31528 return fuse_dev_do_read(fc, file, &cs, iov_length(iov, nr_segs));
31531 +EXPORT_SYMBOL_GPL(fuse_dev_read);
31533 static int fuse_dev_pipe_buf_steal(struct pipe_inode_info *pipe,
31534 struct pipe_buffer *buf)
31536 @@ -1104,7 +1106,7 @@ static ssize_t fuse_dev_splice_read(stru
31540 - if (!pipe->readers) {
31541 + if (!atomic_read(&pipe->readers)) {
31542 send_sig(SIGPIPE, current, 0);
31545 @@ -1597,7 +1599,7 @@ static ssize_t fuse_dev_do_write(struct
31549 -static ssize_t fuse_dev_write(struct kiocb *iocb, const struct iovec *iov,
31550 +ssize_t fuse_dev_write(struct kiocb *iocb, const struct iovec *iov,
31551 unsigned long nr_segs, loff_t pos)
31553 struct fuse_copy_state cs;
31554 @@ -1610,6 +1612,8 @@ static ssize_t fuse_dev_write(struct kio
31555 return fuse_dev_do_write(fc, &cs, iov_length(iov, nr_segs));
31558 +EXPORT_SYMBOL_GPL(fuse_dev_write);
31560 static ssize_t fuse_dev_splice_write(struct pipe_inode_info *pipe,
31561 struct file *out, loff_t *ppos,
31562 size_t len, unsigned int flags)
31563 @@ -1688,7 +1692,7 @@ out:
31567 -static unsigned fuse_dev_poll(struct file *file, poll_table *wait)
31568 +unsigned fuse_dev_poll(struct file *file, poll_table *wait)
31570 unsigned mask = POLLOUT | POLLWRNORM;
31571 struct fuse_conn *fc = fuse_get_conn(file);
31572 @@ -1707,6 +1711,8 @@ static unsigned fuse_dev_poll(struct fil
31576 +EXPORT_SYMBOL_GPL(fuse_dev_poll);
31579 * Abort all requests on the given list (pending or processing)
31581 @@ -1824,7 +1830,7 @@ int fuse_dev_release(struct inode *inode
31583 EXPORT_SYMBOL_GPL(fuse_dev_release);
31585 -static int fuse_dev_fasync(int fd, struct file *file, int on)
31586 +int fuse_dev_fasync(int fd, struct file *file, int on)
31588 struct fuse_conn *fc = fuse_get_conn(file);
31590 @@ -1834,6 +1840,8 @@ static int fuse_dev_fasync(int fd, struc
31591 return fasync_helper(fd, file, on, &fc->fasync);
31594 +EXPORT_SYMBOL_GPL(fuse_dev_fasync);
31596 const struct file_operations fuse_dev_operations = {
31597 .owner = THIS_MODULE,
31598 .llseek = no_llseek,
31599 diff -urNp linux-2.6.37/fs/fuse/dir.c linux-2.6.37/fs/fuse/dir.c
31600 --- linux-2.6.37/fs/fuse/dir.c 2011-01-04 19:50:19.000000000 -0500
31601 +++ linux-2.6.37/fs/fuse/dir.c 2011-01-17 02:41:01.000000000 -0500
31602 @@ -1127,7 +1127,7 @@ static char *read_link(struct dentry *de
31606 -static void free_link(char *link)
31607 +static void free_link(const char *link)
31610 free_page((unsigned long) link);
31611 diff -urNp linux-2.6.37/fs/fuse/fuse_i.h linux-2.6.37/fs/fuse/fuse_i.h
31612 --- linux-2.6.37/fs/fuse/fuse_i.h 2011-01-04 19:50:19.000000000 -0500
31613 +++ linux-2.6.37/fs/fuse/fuse_i.h 2011-01-17 02:41:01.000000000 -0500
31614 @@ -525,6 +525,16 @@ extern const struct file_operations fuse
31616 extern const struct dentry_operations fuse_dentry_operations;
31618 +extern ssize_t fuse_dev_read(struct kiocb *iocb, const struct iovec *iov,
31619 + unsigned long nr_segs, loff_t pos);
31621 +extern ssize_t fuse_dev_write(struct kiocb *iocb, const struct iovec *iov,
31622 + unsigned long nr_segs, loff_t pos);
31624 +extern unsigned fuse_dev_poll(struct file *file, poll_table *wait);
31626 +extern int fuse_dev_fasync(int fd, struct file *file, int on);
31629 * Inode to nodeid comparison.
31631 diff -urNp linux-2.6.37/fs/hfs/inode.c linux-2.6.37/fs/hfs/inode.c
31632 --- linux-2.6.37/fs/hfs/inode.c 2011-01-04 19:50:19.000000000 -0500
31633 +++ linux-2.6.37/fs/hfs/inode.c 2011-01-17 02:41:01.000000000 -0500
31634 @@ -447,7 +447,7 @@ int hfs_write_inode(struct inode *inode,
31636 if (S_ISDIR(main_inode->i_mode)) {
31637 if (fd.entrylength < sizeof(struct hfs_cat_dir))
31640 hfs_bnode_read(fd.bnode, &rec, fd.entryoffset,
31641 sizeof(struct hfs_cat_dir));
31642 if (rec.type != HFS_CDR_DIR ||
31643 @@ -468,7 +468,7 @@ int hfs_write_inode(struct inode *inode,
31644 sizeof(struct hfs_cat_file));
31646 if (fd.entrylength < sizeof(struct hfs_cat_file))
31649 hfs_bnode_read(fd.bnode, &rec, fd.entryoffset,
31650 sizeof(struct hfs_cat_file));
31651 if (rec.type != HFS_CDR_FIL ||
31652 diff -urNp linux-2.6.37/fs/hfsplus/inode.c linux-2.6.37/fs/hfsplus/inode.c
31653 --- linux-2.6.37/fs/hfsplus/inode.c 2011-01-04 19:50:19.000000000 -0500
31654 +++ linux-2.6.37/fs/hfsplus/inode.c 2011-01-17 02:41:01.000000000 -0500
31655 @@ -478,7 +478,7 @@ int hfsplus_cat_read_inode(struct inode
31656 struct hfsplus_cat_folder *folder = &entry.folder;
31658 if (fd->entrylength < sizeof(struct hfsplus_cat_folder))
31661 hfs_bnode_read(fd->bnode, &entry, fd->entryoffset,
31662 sizeof(struct hfsplus_cat_folder));
31663 hfsplus_get_perms(inode, &folder->permissions, 1);
31664 @@ -495,7 +495,7 @@ int hfsplus_cat_read_inode(struct inode
31665 struct hfsplus_cat_file *file = &entry.file;
31667 if (fd->entrylength < sizeof(struct hfsplus_cat_file))
31670 hfs_bnode_read(fd->bnode, &entry, fd->entryoffset,
31671 sizeof(struct hfsplus_cat_file));
31673 @@ -551,7 +551,7 @@ int hfsplus_cat_write_inode(struct inode
31674 struct hfsplus_cat_folder *folder = &entry.folder;
31676 if (fd.entrylength < sizeof(struct hfsplus_cat_folder))
31679 hfs_bnode_read(fd.bnode, &entry, fd.entryoffset,
31680 sizeof(struct hfsplus_cat_folder));
31681 /* simple node checks? */
31682 @@ -573,7 +573,7 @@ int hfsplus_cat_write_inode(struct inode
31683 struct hfsplus_cat_file *file = &entry.file;
31685 if (fd.entrylength < sizeof(struct hfsplus_cat_file))
31688 hfs_bnode_read(fd.bnode, &entry, fd.entryoffset,
31689 sizeof(struct hfsplus_cat_file));
31690 hfsplus_inode_write_fork(inode, &file->data_fork);
31691 diff -urNp linux-2.6.37/fs/hugetlbfs/inode.c linux-2.6.37/fs/hugetlbfs/inode.c
31692 --- linux-2.6.37/fs/hugetlbfs/inode.c 2011-01-04 19:50:19.000000000 -0500
31693 +++ linux-2.6.37/fs/hugetlbfs/inode.c 2011-01-17 02:41:01.000000000 -0500
31694 @@ -908,7 +908,7 @@ static struct file_system_type hugetlbfs
31695 .kill_sb = kill_litter_super,
31698 -static struct vfsmount *hugetlbfs_vfsmount;
31699 +struct vfsmount *hugetlbfs_vfsmount;
31701 static int can_do_hugetlb_shm(void)
31703 diff -urNp linux-2.6.37/fs/ioctl.c linux-2.6.37/fs/ioctl.c
31704 --- linux-2.6.37/fs/ioctl.c 2011-01-04 19:50:19.000000000 -0500
31705 +++ linux-2.6.37/fs/ioctl.c 2011-01-17 02:41:01.000000000 -0500
31706 @@ -86,7 +86,7 @@ int fiemap_fill_next_extent(struct fiema
31707 u64 phys, u64 len, u32 flags)
31709 struct fiemap_extent extent;
31710 - struct fiemap_extent *dest = fieinfo->fi_extents_start;
31711 + struct fiemap_extent __user *dest = fieinfo->fi_extents_start;
31713 /* only count the extents */
31714 if (fieinfo->fi_extents_max == 0) {
31715 @@ -196,7 +196,7 @@ static int ioctl_fiemap(struct file *fil
31717 fieinfo.fi_flags = fiemap.fm_flags;
31718 fieinfo.fi_extents_max = fiemap.fm_extent_count;
31719 - fieinfo.fi_extents_start = (struct fiemap_extent *)(arg + sizeof(fiemap));
31720 + fieinfo.fi_extents_start = (struct fiemap_extent __user *)(arg + sizeof(fiemap));
31722 if (fiemap.fm_extent_count != 0 &&
31723 !access_ok(VERIFY_WRITE, fieinfo.fi_extents_start,
31724 @@ -209,7 +209,7 @@ static int ioctl_fiemap(struct file *fil
31725 error = inode->i_op->fiemap(inode, &fieinfo, fiemap.fm_start, len);
31726 fiemap.fm_flags = fieinfo.fi_flags;
31727 fiemap.fm_mapped_extents = fieinfo.fi_extents_mapped;
31728 - if (copy_to_user((char *)arg, &fiemap, sizeof(fiemap)))
31729 + if (copy_to_user((__force char __user *)arg, &fiemap, sizeof(fiemap)))
31733 diff -urNp linux-2.6.37/fs/jffs2/debug.h linux-2.6.37/fs/jffs2/debug.h
31734 --- linux-2.6.37/fs/jffs2/debug.h 2011-01-04 19:50:19.000000000 -0500
31735 +++ linux-2.6.37/fs/jffs2/debug.h 2011-01-17 02:41:01.000000000 -0500
31736 @@ -53,13 +53,13 @@
31737 #if CONFIG_JFFS2_FS_DEBUG > 0
31741 +#define D1(x) do {} while (0);
31744 #if CONFIG_JFFS2_FS_DEBUG > 1
31748 +#define D2(x) do {} while (0);
31751 /* The prefixes of JFFS2 messages */
31752 @@ -115,73 +115,73 @@
31753 #ifdef JFFS2_DBG_READINODE_MESSAGES
31754 #define dbg_readinode(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
31756 -#define dbg_readinode(fmt, ...)
31757 +#define dbg_readinode(fmt, ...) do {} while (0)
31759 #ifdef JFFS2_DBG_READINODE2_MESSAGES
31760 #define dbg_readinode2(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
31762 -#define dbg_readinode2(fmt, ...)
31763 +#define dbg_readinode2(fmt, ...) do {} while (0)
31766 /* Fragtree build debugging messages */
31767 #ifdef JFFS2_DBG_FRAGTREE_MESSAGES
31768 #define dbg_fragtree(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
31770 -#define dbg_fragtree(fmt, ...)
31771 +#define dbg_fragtree(fmt, ...) do {} while (0)
31773 #ifdef JFFS2_DBG_FRAGTREE2_MESSAGES
31774 #define dbg_fragtree2(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
31776 -#define dbg_fragtree2(fmt, ...)
31777 +#define dbg_fragtree2(fmt, ...) do {} while (0)
31780 /* Directory entry list manilulation debugging messages */
31781 #ifdef JFFS2_DBG_DENTLIST_MESSAGES
31782 #define dbg_dentlist(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
31784 -#define dbg_dentlist(fmt, ...)
31785 +#define dbg_dentlist(fmt, ...) do {} while (0)
31788 /* Print the messages about manipulating node_refs */
31789 #ifdef JFFS2_DBG_NODEREF_MESSAGES
31790 #define dbg_noderef(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
31792 -#define dbg_noderef(fmt, ...)
31793 +#define dbg_noderef(fmt, ...) do {} while (0)
31796 /* Manipulations with the list of inodes (JFFS2 inocache) */
31797 #ifdef JFFS2_DBG_INOCACHE_MESSAGES
31798 #define dbg_inocache(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
31800 -#define dbg_inocache(fmt, ...)
31801 +#define dbg_inocache(fmt, ...) do {} while (0)
31804 /* Summary debugging messages */
31805 #ifdef JFFS2_DBG_SUMMARY_MESSAGES
31806 #define dbg_summary(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
31808 -#define dbg_summary(fmt, ...)
31809 +#define dbg_summary(fmt, ...) do {} while (0)
31812 /* File system build messages */
31813 #ifdef JFFS2_DBG_FSBUILD_MESSAGES
31814 #define dbg_fsbuild(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
31816 -#define dbg_fsbuild(fmt, ...)
31817 +#define dbg_fsbuild(fmt, ...) do {} while (0)
31820 /* Watch the object allocations */
31821 #ifdef JFFS2_DBG_MEMALLOC_MESSAGES
31822 #define dbg_memalloc(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
31824 -#define dbg_memalloc(fmt, ...)
31825 +#define dbg_memalloc(fmt, ...) do {} while (0)
31828 /* Watch the XATTR subsystem */
31829 #ifdef JFFS2_DBG_XATTR_MESSAGES
31830 #define dbg_xattr(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
31832 -#define dbg_xattr(fmt, ...)
31833 +#define dbg_xattr(fmt, ...) do {} while (0)
31836 /* "Sanity" checks */
31837 diff -urNp linux-2.6.37/fs/jffs2/erase.c linux-2.6.37/fs/jffs2/erase.c
31838 --- linux-2.6.37/fs/jffs2/erase.c 2011-01-04 19:50:19.000000000 -0500
31839 +++ linux-2.6.37/fs/jffs2/erase.c 2011-01-17 02:41:01.000000000 -0500
31840 @@ -439,7 +439,8 @@ static void jffs2_mark_erased_block(stru
31841 struct jffs2_unknown_node marker = {
31842 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
31843 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
31844 - .totlen = cpu_to_je32(c->cleanmarker_size)
31845 + .totlen = cpu_to_je32(c->cleanmarker_size),
31846 + .hdr_crc = cpu_to_je32(0)
31849 jffs2_prealloc_raw_node_refs(c, jeb, 1);
31850 diff -urNp linux-2.6.37/fs/jffs2/summary.h linux-2.6.37/fs/jffs2/summary.h
31851 --- linux-2.6.37/fs/jffs2/summary.h 2011-01-04 19:50:19.000000000 -0500
31852 +++ linux-2.6.37/fs/jffs2/summary.h 2011-01-17 02:41:01.000000000 -0500
31853 @@ -194,18 +194,18 @@ int jffs2_sum_scan_sumnode(struct jffs2_
31855 #define jffs2_sum_active() (0)
31856 #define jffs2_sum_init(a) (0)
31857 -#define jffs2_sum_exit(a)
31858 -#define jffs2_sum_disable_collecting(a)
31859 +#define jffs2_sum_exit(a) do {} while (0)
31860 +#define jffs2_sum_disable_collecting(a) do {} while (0)
31861 #define jffs2_sum_is_disabled(a) (0)
31862 -#define jffs2_sum_reset_collected(a)
31863 +#define jffs2_sum_reset_collected(a) do {} while (0)
31864 #define jffs2_sum_add_kvec(a,b,c,d) (0)
31865 -#define jffs2_sum_move_collected(a,b)
31866 +#define jffs2_sum_move_collected(a,b) do {} while (0)
31867 #define jffs2_sum_write_sumnode(a) (0)
31868 -#define jffs2_sum_add_padding_mem(a,b)
31869 -#define jffs2_sum_add_inode_mem(a,b,c)
31870 -#define jffs2_sum_add_dirent_mem(a,b,c)
31871 -#define jffs2_sum_add_xattr_mem(a,b,c)
31872 -#define jffs2_sum_add_xref_mem(a,b,c)
31873 +#define jffs2_sum_add_padding_mem(a,b) do {} while (0)
31874 +#define jffs2_sum_add_inode_mem(a,b,c) do {} while (0)
31875 +#define jffs2_sum_add_dirent_mem(a,b,c) do {} while (0)
31876 +#define jffs2_sum_add_xattr_mem(a,b,c) do {} while (0)
31877 +#define jffs2_sum_add_xref_mem(a,b,c) do {} while (0)
31878 #define jffs2_sum_scan_sumnode(a,b,c,d,e) (0)
31880 #endif /* CONFIG_JFFS2_SUMMARY */
31881 diff -urNp linux-2.6.37/fs/jffs2/wbuf.c linux-2.6.37/fs/jffs2/wbuf.c
31882 --- linux-2.6.37/fs/jffs2/wbuf.c 2011-01-04 19:50:19.000000000 -0500
31883 +++ linux-2.6.37/fs/jffs2/wbuf.c 2011-01-17 02:41:01.000000000 -0500
31884 @@ -1012,7 +1012,8 @@ static const struct jffs2_unknown_node o
31886 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
31887 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
31888 - .totlen = constant_cpu_to_je32(8)
31889 + .totlen = constant_cpu_to_je32(8),
31890 + .hdr_crc = constant_cpu_to_je32(0)
31894 diff -urNp linux-2.6.37/fs/Kconfig.binfmt linux-2.6.37/fs/Kconfig.binfmt
31895 --- linux-2.6.37/fs/Kconfig.binfmt 2011-01-04 19:50:19.000000000 -0500
31896 +++ linux-2.6.37/fs/Kconfig.binfmt 2011-01-17 02:41:01.000000000 -0500
31897 @@ -86,7 +86,7 @@ config HAVE_AOUT
31900 tristate "Kernel support for a.out and ECOFF binaries"
31901 - depends on HAVE_AOUT
31902 + depends on HAVE_AOUT && BROKEN
31904 A.out (Assembler.OUTput) is a set of formats for libraries and
31905 executables used in the earliest versions of UNIX. Linux used
31906 diff -urNp linux-2.6.37/fs/lockd/svc.c linux-2.6.37/fs/lockd/svc.c
31907 --- linux-2.6.37/fs/lockd/svc.c 2011-01-04 19:50:19.000000000 -0500
31908 +++ linux-2.6.37/fs/lockd/svc.c 2011-01-17 02:41:01.000000000 -0500
31911 static struct svc_program nlmsvc_program;
31913 -struct nlmsvc_binding * nlmsvc_ops;
31914 +const struct nlmsvc_binding * nlmsvc_ops;
31915 EXPORT_SYMBOL_GPL(nlmsvc_ops);
31917 static DEFINE_MUTEX(nlmsvc_mutex);
31918 diff -urNp linux-2.6.37/fs/locks.c linux-2.6.37/fs/locks.c
31919 --- linux-2.6.37/fs/locks.c 2011-01-04 19:50:19.000000000 -0500
31920 +++ linux-2.6.37/fs/locks.c 2011-01-17 02:41:01.000000000 -0500
31921 @@ -2050,16 +2050,16 @@ void locks_remove_flock(struct file *fil
31924 if (filp->f_op && filp->f_op->flock) {
31925 - struct file_lock fl = {
31926 + struct file_lock flock = {
31927 .fl_pid = current->tgid,
31929 .fl_flags = FL_FLOCK,
31930 .fl_type = F_UNLCK,
31931 .fl_end = OFFSET_MAX,
31933 - filp->f_op->flock(filp, F_SETLKW, &fl);
31934 - if (fl.fl_ops && fl.fl_ops->fl_release_private)
31935 - fl.fl_ops->fl_release_private(&fl);
31936 + filp->f_op->flock(filp, F_SETLKW, &flock);
31937 + if (flock.fl_ops && flock.fl_ops->fl_release_private)
31938 + flock.fl_ops->fl_release_private(&flock);
31942 diff -urNp linux-2.6.37/fs/namei.c linux-2.6.37/fs/namei.c
31943 --- linux-2.6.37/fs/namei.c 2011-01-04 19:50:19.000000000 -0500
31944 +++ linux-2.6.37/fs/namei.c 2011-01-17 11:57:48.000000000 -0500
31945 @@ -221,14 +221,6 @@ int generic_permission(struct inode *ino
31949 - * Read/write DACs are always overridable.
31950 - * Executable DACs are overridable if at least one exec bit is set.
31952 - if (!(mask & MAY_EXEC) || execute_ok(inode))
31953 - if (capable(CAP_DAC_OVERRIDE))
31957 * Searching includes executable on directories, else just read.
31959 mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
31960 @@ -236,6 +228,14 @@ int generic_permission(struct inode *ino
31961 if (capable(CAP_DAC_READ_SEARCH))
31965 + * Read/write DACs are always overridable.
31966 + * Executable DACs are overridable if at least one exec bit is set.
31968 + if (!(mask & MAY_EXEC) || execute_ok(inode))
31969 + if (capable(CAP_DAC_OVERRIDE))
31975 @@ -473,7 +473,8 @@ static int exec_permission(struct inode
31979 - if (capable(CAP_DAC_OVERRIDE) || capable(CAP_DAC_READ_SEARCH))
31980 + if (capable_nolog(CAP_DAC_OVERRIDE) || capable(CAP_DAC_READ_SEARCH) ||
31981 + capable(CAP_DAC_OVERRIDE))
31985 @@ -542,7 +543,7 @@ __do_follow_link(struct path *path, stru
31986 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
31987 error = PTR_ERR(*p);
31989 - char *s = nd_get_link(nd);
31990 + const char *s = nd_get_link(nd);
31993 error = __vfs_follow_link(nd, s);
31994 @@ -575,6 +576,13 @@ static inline int do_follow_link(struct
31995 err = security_inode_follow_link(path->dentry, nd);
31999 + if (gr_handle_follow_link(path->dentry->d_parent->d_inode,
32000 + path->dentry->d_inode, path->dentry, nd->path.mnt)) {
32005 current->link_count++;
32006 current->total_link_count++;
32008 @@ -967,11 +975,18 @@ return_reval:
32012 + if (!(nd->flags & LOOKUP_PARENT) && !gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
32013 + path_put(&nd->path);
32018 path_put_conditional(&next, nd);
32021 + if (!(nd->flags & LOOKUP_PARENT) && !gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt))
32024 path_put(&nd->path);
32027 @@ -1397,6 +1412,30 @@ int vfs_create(struct inode *dir, struct
32032 + * Note that while the flag value (low two bits) for sys_open means:
32034 + * 01 - write-only
32035 + * 10 - read-write
32037 + * it is changed into
32038 + * 00 - no permissions needed
32039 + * 01 - read-permission
32040 + * 10 - write-permission
32041 + * 11 - read-write
32042 + * for the internal routines (ie open_namei()/follow_link() etc)
32043 + * This is more logical, and also allows the 00 "no perm needed"
32044 + * to be used for symlinks (where the permissions are checked
32048 +static inline int open_to_namei_flags(int flag)
32050 + if ((flag+1) & O_ACCMODE)
32055 int may_open(struct path *path, int acc_mode, int flag)
32057 struct dentry *dentry = path->dentry;
32058 @@ -1445,7 +1484,26 @@ int may_open(struct path *path, int acc_
32060 * Ensure there are no outstanding leases on the file.
32062 - return break_lease(inode, flag);
32063 + error = break_lease(inode, flag);
32067 + if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode)) {
32072 + if (gr_handle_rawio(inode)) {
32077 + if (!gr_acl_handle_open(dentry, path->mnt, open_to_namei_flags(flag))) {
32085 static int handle_truncate(struct path *path)
32086 @@ -1479,6 +1537,12 @@ static int __open_namei_create(struct na
32089 struct dentry *dir = nd->path.dentry;
32090 + int flag = open_to_namei_flags(open_flag);
32092 + if (!gr_acl_handle_creat(path->dentry, nd->path.dentry, nd->path.mnt, flag, mode)) {
32097 if (!IS_POSIXACL(dir->d_inode))
32098 mode &= ~current_umask();
32099 @@ -1486,6 +1550,8 @@ static int __open_namei_create(struct na
32102 error = vfs_create(dir->d_inode, path->dentry, mode, nd);
32104 + gr_handle_create(path->dentry, nd->path.mnt);
32106 mutex_unlock(&dir->d_inode->i_mutex);
32107 dput(nd->path.dentry);
32108 @@ -1496,30 +1562,6 @@ out_unlock:
32109 return may_open(&nd->path, 0, open_flag & ~O_TRUNC);
32113 - * Note that while the flag value (low two bits) for sys_open means:
32115 - * 01 - write-only
32116 - * 10 - read-write
32118 - * it is changed into
32119 - * 00 - no permissions needed
32120 - * 01 - read-permission
32121 - * 10 - write-permission
32122 - * 11 - read-write
32123 - * for the internal routines (ie open_namei()/follow_link() etc)
32124 - * This is more logical, and also allows the 00 "no perm needed"
32125 - * to be used for symlinks (where the permissions are checked
32129 -static inline int open_to_namei_flags(int flag)
32131 - if ((flag+1) & O_ACCMODE)
32136 static int open_will_truncate(int flag, struct inode *inode)
32139 @@ -1589,6 +1631,7 @@ static struct file *do_last(struct namei
32140 int mode, const char *pathname)
32142 struct dentry *dir = nd->path.dentry;
32143 + int flag = open_to_namei_flags(open_flag);
32145 int error = -EISDIR;
32147 @@ -1690,6 +1733,14 @@ static struct file *do_last(struct namei
32149 * It already exists.
32152 + /* only check if O_CREAT is specified, all other checks need to go
32154 + if (gr_handle_fifo(path->dentry, path->mnt, dir, flag, acc_mode)) {
32156 + goto exit_mutex_unlock;
32159 mutex_unlock(&dir->d_inode->i_mutex);
32160 audit_inode(pathname, path->dentry);
32162 @@ -1838,6 +1889,11 @@ reval:
32163 error = security_inode_follow_link(path.dentry, &nd);
32166 + if (gr_handle_follow_link(path.dentry->d_parent->d_inode,
32167 + path.dentry->d_inode, path.dentry, nd.path.mnt)) {
32171 error = __do_follow_link(&path, &nd, &cookie);
32172 if (unlikely(error)) {
32173 /* nd.path had been dropped */
32174 @@ -2013,6 +2069,17 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const
32175 error = may_mknod(mode);
32179 + if (gr_handle_chroot_mknod(dentry, nd.path.mnt, mode)) {
32184 + if (!gr_acl_handle_mknod(dentry, nd.path.dentry, nd.path.mnt, mode)) {
32189 error = mnt_want_write(nd.path.mnt);
32192 @@ -2033,6 +2100,9 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const
32195 mnt_drop_write(nd.path.mnt);
32198 + gr_handle_create(dentry, nd.path.mnt);
32202 @@ -2085,6 +2155,11 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const
32203 if (IS_ERR(dentry))
32206 + if (!gr_acl_handle_mkdir(dentry, nd.path.dentry, nd.path.mnt)) {
32211 if (!IS_POSIXACL(nd.path.dentry->d_inode))
32212 mode &= ~current_umask();
32213 error = mnt_want_write(nd.path.mnt);
32214 @@ -2096,6 +2171,10 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const
32215 error = vfs_mkdir(nd.path.dentry->d_inode, dentry, mode);
32217 mnt_drop_write(nd.path.mnt);
32220 + gr_handle_create(dentry, nd.path.mnt);
32225 @@ -2177,6 +2256,8 @@ static long do_rmdir(int dfd, const char
32227 struct dentry *dentry;
32228 struct nameidata nd;
32229 + ino_t saved_ino = 0;
32230 + dev_t saved_dev = 0;
32232 error = user_path_parent(dfd, pathname, &nd, &name);
32234 @@ -2201,6 +2282,19 @@ static long do_rmdir(int dfd, const char
32235 error = PTR_ERR(dentry);
32236 if (IS_ERR(dentry))
32239 + if (dentry->d_inode != NULL) {
32240 + if (dentry->d_inode->i_nlink <= 1) {
32241 + saved_ino = dentry->d_inode->i_ino;
32242 + saved_dev = dentry->d_inode->i_sb->s_dev;
32245 + if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
32251 error = mnt_want_write(nd.path.mnt);
32254 @@ -2208,6 +2302,8 @@ static long do_rmdir(int dfd, const char
32257 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
32258 + if (!error && (saved_dev || saved_ino))
32259 + gr_handle_delete(saved_ino, saved_dev);
32261 mnt_drop_write(nd.path.mnt);
32263 @@ -2270,6 +2366,8 @@ static long do_unlinkat(int dfd, const c
32264 struct dentry *dentry;
32265 struct nameidata nd;
32266 struct inode *inode = NULL;
32267 + ino_t saved_ino = 0;
32268 + dev_t saved_dev = 0;
32270 error = user_path_parent(dfd, pathname, &nd, &name);
32272 @@ -2289,8 +2387,17 @@ static long do_unlinkat(int dfd, const c
32273 if (nd.last.name[nd.last.len])
32275 inode = dentry->d_inode;
32279 + if (inode->i_nlink <= 1) {
32280 + saved_ino = inode->i_ino;
32281 + saved_dev = inode->i_sb->s_dev;
32283 + if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
32288 error = mnt_want_write(nd.path.mnt);
32291 @@ -2298,6 +2405,8 @@ static long do_unlinkat(int dfd, const c
32294 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
32295 + if (!error && (saved_ino || saved_dev))
32296 + gr_handle_delete(saved_ino, saved_dev);
32298 mnt_drop_write(nd.path.mnt);
32300 @@ -2375,6 +2484,11 @@ SYSCALL_DEFINE3(symlinkat, const char __
32301 if (IS_ERR(dentry))
32304 + if (!gr_acl_handle_symlink(dentry, nd.path.dentry, nd.path.mnt, from)) {
32309 error = mnt_want_write(nd.path.mnt);
32312 @@ -2382,6 +2496,8 @@ SYSCALL_DEFINE3(symlinkat, const char __
32314 goto out_drop_write;
32315 error = vfs_symlink(nd.path.dentry->d_inode, dentry, from);
32317 + gr_handle_create(dentry, nd.path.mnt);
32319 mnt_drop_write(nd.path.mnt);
32321 @@ -2474,6 +2590,20 @@ SYSCALL_DEFINE5(linkat, int, olddfd, con
32322 error = PTR_ERR(new_dentry);
32323 if (IS_ERR(new_dentry))
32326 + if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
32327 + old_path.dentry->d_inode,
32328 + old_path.dentry->d_inode->i_mode, to)) {
32333 + if (!gr_acl_handle_link(new_dentry, nd.path.dentry, nd.path.mnt,
32334 + old_path.dentry, old_path.mnt, to)) {
32339 error = mnt_want_write(nd.path.mnt);
32342 @@ -2481,6 +2611,8 @@ SYSCALL_DEFINE5(linkat, int, olddfd, con
32344 goto out_drop_write;
32345 error = vfs_link(old_path.dentry, nd.path.dentry->d_inode, new_dentry);
32347 + gr_handle_create(new_dentry, nd.path.mnt);
32349 mnt_drop_write(nd.path.mnt);
32351 @@ -2714,6 +2846,12 @@ SYSCALL_DEFINE4(renameat, int, olddfd, c
32352 if (new_dentry == trap)
32355 + error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
32356 + old_dentry, old_dir->d_inode, oldnd.path.mnt,
32361 error = mnt_want_write(oldnd.path.mnt);
32364 @@ -2723,6 +2861,9 @@ SYSCALL_DEFINE4(renameat, int, olddfd, c
32366 error = vfs_rename(old_dir->d_inode, old_dentry,
32367 new_dir->d_inode, new_dentry);
32369 + gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
32370 + new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
32372 mnt_drop_write(oldnd.path.mnt);
32374 diff -urNp linux-2.6.37/fs/namespace.c linux-2.6.37/fs/namespace.c
32375 --- linux-2.6.37/fs/namespace.c 2011-01-04 19:50:19.000000000 -0500
32376 +++ linux-2.6.37/fs/namespace.c 2011-01-17 02:41:01.000000000 -0500
32377 @@ -1141,6 +1141,9 @@ static int do_umount(struct vfsmount *mn
32378 if (!(sb->s_flags & MS_RDONLY))
32379 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
32380 up_write(&sb->s_umount);
32382 + gr_log_remount(mnt->mnt_devname, retval);
32387 @@ -1160,6 +1163,9 @@ static int do_umount(struct vfsmount *mn
32388 br_write_unlock(vfsmount_lock);
32389 up_write(&namespace_sem);
32390 release_mounts(&umount_list);
32392 + gr_log_unmount(mnt->mnt_devname, retval);
32397 @@ -2053,6 +2059,16 @@ long do_mount(char *dev_name, char *dir_
32398 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
32401 + if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
32406 + if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
32411 if (flags & MS_REMOUNT)
32412 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
32414 @@ -2067,6 +2083,9 @@ long do_mount(char *dev_name, char *dir_
32415 dev_name, data_page);
32419 + gr_log_mount(dev_name, dir_name, retval);
32424 @@ -2273,6 +2292,12 @@ SYSCALL_DEFINE2(pivot_root, const char _
32428 + if (gr_handle_chroot_pivot()) {
32434 get_fs_root(current->fs, &root);
32435 down_write(&namespace_sem);
32436 mutex_lock(&old.dentry->d_inode->i_mutex);
32437 diff -urNp linux-2.6.37/fs/nfs/inode.c linux-2.6.37/fs/nfs/inode.c
32438 --- linux-2.6.37/fs/nfs/inode.c 2011-01-04 19:50:19.000000000 -0500
32439 +++ linux-2.6.37/fs/nfs/inode.c 2011-01-17 02:41:01.000000000 -0500
32440 @@ -985,16 +985,16 @@ static int nfs_size_need_update(const st
32441 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
32444 -static atomic_long_t nfs_attr_generation_counter;
32445 +static atomic_long_unchecked_t nfs_attr_generation_counter;
32447 static unsigned long nfs_read_attr_generation_counter(void)
32449 - return atomic_long_read(&nfs_attr_generation_counter);
32450 + return atomic_long_read_unchecked(&nfs_attr_generation_counter);
32453 unsigned long nfs_inc_attr_generation_counter(void)
32455 - return atomic_long_inc_return(&nfs_attr_generation_counter);
32456 + return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
32459 void nfs_fattr_init(struct nfs_fattr *fattr)
32460 diff -urNp linux-2.6.37/fs/nfs/nfs4proc.c linux-2.6.37/fs/nfs/nfs4proc.c
32461 --- linux-2.6.37/fs/nfs/nfs4proc.c 2011-01-04 19:50:19.000000000 -0500
32462 +++ linux-2.6.37/fs/nfs/nfs4proc.c 2011-01-17 02:41:01.000000000 -0500
32463 @@ -1184,7 +1184,7 @@ static int _nfs4_do_open_reclaim(struct
32464 static int nfs4_do_open_reclaim(struct nfs_open_context *ctx, struct nfs4_state *state)
32466 struct nfs_server *server = NFS_SERVER(state->inode);
32467 - struct nfs4_exception exception = { };
32468 + struct nfs4_exception exception = {0, 0};
32471 err = _nfs4_do_open_reclaim(ctx, state);
32472 @@ -1226,7 +1226,7 @@ static int _nfs4_open_delegation_recall(
32474 int nfs4_open_delegation_recall(struct nfs_open_context *ctx, struct nfs4_state *state, const nfs4_stateid *stateid)
32476 - struct nfs4_exception exception = { };
32477 + struct nfs4_exception exception = {0, 0};
32478 struct nfs_server *server = NFS_SERVER(state->inode);
32481 @@ -1602,7 +1602,7 @@ static int _nfs4_open_expired(struct nfs
32482 static int nfs4_do_open_expired(struct nfs_open_context *ctx, struct nfs4_state *state)
32484 struct nfs_server *server = NFS_SERVER(state->inode);
32485 - struct nfs4_exception exception = { };
32486 + struct nfs4_exception exception = {0, 0};
32490 @@ -1717,7 +1717,7 @@ out_err:
32492 static struct nfs4_state *nfs4_do_open(struct inode *dir, struct path *path, fmode_t fmode, int flags, struct iattr *sattr, struct rpc_cred *cred)
32494 - struct nfs4_exception exception = { };
32495 + struct nfs4_exception exception = {0, 0};
32496 struct nfs4_state *res;
32499 @@ -1808,7 +1808,7 @@ static int nfs4_do_setattr(struct inode
32500 struct nfs4_state *state)
32502 struct nfs_server *server = NFS_SERVER(inode);
32503 - struct nfs4_exception exception = { };
32504 + struct nfs4_exception exception = {0, 0};
32507 err = nfs4_handle_exception(server,
32508 @@ -2081,7 +2081,7 @@ static int _nfs4_server_capabilities(str
32510 int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle)
32512 - struct nfs4_exception exception = { };
32513 + struct nfs4_exception exception = {0, 0};
32516 err = nfs4_handle_exception(server,
32517 @@ -2115,7 +2115,7 @@ static int _nfs4_lookup_root(struct nfs_
32518 static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle,
32519 struct nfs_fsinfo *info)
32521 - struct nfs4_exception exception = { };
32522 + struct nfs4_exception exception = {0, 0};
32525 err = nfs4_handle_exception(server,
32526 @@ -2203,7 +2203,7 @@ static int _nfs4_proc_getattr(struct nfs
32528 static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr)
32530 - struct nfs4_exception exception = { };
32531 + struct nfs4_exception exception = {0, 0};
32534 err = nfs4_handle_exception(server,
32535 @@ -2291,7 +2291,7 @@ static int nfs4_proc_lookupfh(struct nfs
32536 struct qstr *name, struct nfs_fh *fhandle,
32537 struct nfs_fattr *fattr)
32539 - struct nfs4_exception exception = { };
32540 + struct nfs4_exception exception = {0, 0};
32543 err = _nfs4_proc_lookupfh(server, dirfh, name, fhandle, fattr);
32544 @@ -2320,7 +2320,7 @@ static int _nfs4_proc_lookup(struct inod
32546 static int nfs4_proc_lookup(struct inode *dir, struct qstr *name, struct nfs_fh *fhandle, struct nfs_fattr *fattr)
32548 - struct nfs4_exception exception = { };
32549 + struct nfs4_exception exception = {0, 0};
32552 err = nfs4_handle_exception(NFS_SERVER(dir),
32553 @@ -2387,7 +2387,7 @@ static int _nfs4_proc_access(struct inod
32555 static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry)
32557 - struct nfs4_exception exception = { };
32558 + struct nfs4_exception exception = {0, 0};
32561 err = nfs4_handle_exception(NFS_SERVER(inode),
32562 @@ -2443,7 +2443,7 @@ static int _nfs4_proc_readlink(struct in
32563 static int nfs4_proc_readlink(struct inode *inode, struct page *page,
32564 unsigned int pgbase, unsigned int pglen)
32566 - struct nfs4_exception exception = { };
32567 + struct nfs4_exception exception = {0, 0};
32570 err = nfs4_handle_exception(NFS_SERVER(inode),
32571 @@ -2537,7 +2537,7 @@ out:
32573 static int nfs4_proc_remove(struct inode *dir, struct qstr *name)
32575 - struct nfs4_exception exception = { };
32576 + struct nfs4_exception exception = {0, 0};
32579 err = nfs4_handle_exception(NFS_SERVER(dir),
32580 @@ -2642,7 +2642,7 @@ out:
32581 static int nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name,
32582 struct inode *new_dir, struct qstr *new_name)
32584 - struct nfs4_exception exception = { };
32585 + struct nfs4_exception exception = {0, 0};
32588 err = nfs4_handle_exception(NFS_SERVER(old_dir),
32589 @@ -2691,7 +2691,7 @@ out:
32591 static int nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name)
32593 - struct nfs4_exception exception = { };
32594 + struct nfs4_exception exception = {0, 0};
32597 err = nfs4_handle_exception(NFS_SERVER(inode),
32598 @@ -2783,7 +2783,7 @@ out:
32599 static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry,
32600 struct page *page, unsigned int len, struct iattr *sattr)
32602 - struct nfs4_exception exception = { };
32603 + struct nfs4_exception exception = {0, 0};
32606 err = nfs4_handle_exception(NFS_SERVER(dir),
32607 @@ -2814,7 +2814,7 @@ out:
32608 static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry,
32609 struct iattr *sattr)
32611 - struct nfs4_exception exception = { };
32612 + struct nfs4_exception exception = {0, 0};
32615 err = nfs4_handle_exception(NFS_SERVER(dir),
32616 @@ -2866,7 +2866,7 @@ static int _nfs4_proc_readdir(struct den
32617 static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred,
32618 u64 cookie, struct page **pages, unsigned int count, int plus)
32620 - struct nfs4_exception exception = { };
32621 + struct nfs4_exception exception = {0, 0};
32624 err = nfs4_handle_exception(NFS_SERVER(dentry->d_inode),
32625 @@ -2914,7 +2914,7 @@ out:
32626 static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry,
32627 struct iattr *sattr, dev_t rdev)
32629 - struct nfs4_exception exception = { };
32630 + struct nfs4_exception exception = {0, 0};
32633 err = nfs4_handle_exception(NFS_SERVER(dir),
32634 @@ -2946,7 +2946,7 @@ static int _nfs4_proc_statfs(struct nfs_
32636 static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat)
32638 - struct nfs4_exception exception = { };
32639 + struct nfs4_exception exception = {0, 0};
32642 err = nfs4_handle_exception(server,
32643 @@ -2977,7 +2977,7 @@ static int _nfs4_do_fsinfo(struct nfs_se
32645 static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo)
32647 - struct nfs4_exception exception = { };
32648 + struct nfs4_exception exception = {0, 0};
32652 @@ -3023,7 +3023,7 @@ static int _nfs4_proc_pathconf(struct nf
32653 static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle,
32654 struct nfs_pathconf *pathconf)
32656 - struct nfs4_exception exception = { };
32657 + struct nfs4_exception exception = {0, 0};
32661 @@ -3340,7 +3340,7 @@ out_free:
32663 static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen)
32665 - struct nfs4_exception exception = { };
32666 + struct nfs4_exception exception = {0, 0};
32669 ret = __nfs4_get_acl_uncached(inode, buf, buflen);
32670 @@ -3405,7 +3405,7 @@ static int __nfs4_proc_set_acl(struct in
32672 static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen)
32674 - struct nfs4_exception exception = { };
32675 + struct nfs4_exception exception = {0, 0};
32678 err = nfs4_handle_exception(NFS_SERVER(inode),
32679 @@ -3685,7 +3685,7 @@ out:
32680 int nfs4_proc_delegreturn(struct inode *inode, struct rpc_cred *cred, const nfs4_stateid *stateid, int issync)
32682 struct nfs_server *server = NFS_SERVER(inode);
32683 - struct nfs4_exception exception = { };
32684 + struct nfs4_exception exception = {0, 0};
32687 err = _nfs4_proc_delegreturn(inode, cred, stateid, issync);
32688 @@ -3758,7 +3758,7 @@ out:
32690 static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request)
32692 - struct nfs4_exception exception = { };
32693 + struct nfs4_exception exception = {0, 0};
32697 @@ -4167,7 +4167,7 @@ static int _nfs4_do_setlk(struct nfs4_st
32698 static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request)
32700 struct nfs_server *server = NFS_SERVER(state->inode);
32701 - struct nfs4_exception exception = { };
32702 + struct nfs4_exception exception = {0, 0};
32706 @@ -4185,7 +4185,7 @@ static int nfs4_lock_reclaim(struct nfs4
32707 static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request)
32709 struct nfs_server *server = NFS_SERVER(state->inode);
32710 - struct nfs4_exception exception = { };
32711 + struct nfs4_exception exception = {0, 0};
32714 err = nfs4_set_lock_state(state, request);
32715 @@ -4249,7 +4249,7 @@ out:
32717 static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request)
32719 - struct nfs4_exception exception = { };
32720 + struct nfs4_exception exception = {0, 0};
32724 @@ -4309,7 +4309,7 @@ nfs4_proc_lock(struct file *filp, int cm
32725 int nfs4_lock_delegation_recall(struct nfs4_state *state, struct file_lock *fl)
32727 struct nfs_server *server = NFS_SERVER(state->inode);
32728 - struct nfs4_exception exception = { };
32729 + struct nfs4_exception exception = {0, 0};
32732 err = nfs4_set_lock_state(state, fl);
32733 diff -urNp linux-2.6.37/fs/nfsd/lockd.c linux-2.6.37/fs/nfsd/lockd.c
32734 --- linux-2.6.37/fs/nfsd/lockd.c 2011-01-04 19:50:19.000000000 -0500
32735 +++ linux-2.6.37/fs/nfsd/lockd.c 2011-01-17 02:41:01.000000000 -0500
32736 @@ -61,7 +61,7 @@ nlm_fclose(struct file *filp)
32740 -static struct nlmsvc_binding nfsd_nlm_ops = {
32741 +static const struct nlmsvc_binding nfsd_nlm_ops = {
32742 .fopen = nlm_fopen, /* open file for locking */
32743 .fclose = nlm_fclose, /* close file */
32745 diff -urNp linux-2.6.37/fs/nfsd/nfsctl.c linux-2.6.37/fs/nfsd/nfsctl.c
32746 --- linux-2.6.37/fs/nfsd/nfsctl.c 2011-01-04 19:50:19.000000000 -0500
32747 +++ linux-2.6.37/fs/nfsd/nfsctl.c 2011-01-17 02:41:01.000000000 -0500
32748 @@ -178,7 +178,7 @@ static int export_features_open(struct i
32749 return single_open(file, export_features_show, NULL);
32752 -static struct file_operations export_features_operations = {
32753 +static const struct file_operations export_features_operations = {
32754 .open = export_features_open,
32756 .llseek = seq_lseek,
32757 diff -urNp linux-2.6.37/fs/nfsd/vfs.c linux-2.6.37/fs/nfsd/vfs.c
32758 --- linux-2.6.37/fs/nfsd/vfs.c 2011-01-04 19:50:19.000000000 -0500
32759 +++ linux-2.6.37/fs/nfsd/vfs.c 2011-01-17 02:41:01.000000000 -0500
32760 @@ -916,7 +916,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, st
32764 - host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
32765 + host_err = vfs_readv(file, (__force struct iovec __user *)vec, vlen, &offset);
32769 @@ -1029,7 +1029,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, s
32771 /* Write the data. */
32772 oldfs = get_fs(); set_fs(KERNEL_DS);
32773 - host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &offset);
32774 + host_err = vfs_writev(file, (__force struct iovec __user *)vec, vlen, &offset);
32778 @@ -1546,7 +1546,7 @@ nfsd_readlink(struct svc_rqst *rqstp, st
32781 oldfs = get_fs(); set_fs(KERNEL_DS);
32782 - host_err = inode->i_op->readlink(dentry, buf, *lenp);
32783 + host_err = inode->i_op->readlink(dentry, (__force char __user *)buf, *lenp);
32787 diff -urNp linux-2.6.37/fs/nls/nls_base.c linux-2.6.37/fs/nls/nls_base.c
32788 --- linux-2.6.37/fs/nls/nls_base.c 2011-01-04 19:50:19.000000000 -0500
32789 +++ linux-2.6.37/fs/nls/nls_base.c 2011-01-17 02:41:01.000000000 -0500
32790 @@ -41,7 +41,7 @@ static const struct utf8_table utf8_tabl
32791 {0xF8, 0xF0, 3*6, 0x1FFFFF, 0x10000, /* 4 byte sequence */},
32792 {0xFC, 0xF8, 4*6, 0x3FFFFFF, 0x200000, /* 5 byte sequence */},
32793 {0xFE, 0xFC, 5*6, 0x7FFFFFFF, 0x4000000, /* 6 byte sequence */},
32794 - {0, /* end of table */}
32795 + {0, 0, 0, 0, 0, /* end of table */}
32798 #define UNICODE_MAX 0x0010ffff
32799 diff -urNp linux-2.6.37/fs/ntfs/dir.c linux-2.6.37/fs/ntfs/dir.c
32800 --- linux-2.6.37/fs/ntfs/dir.c 2011-01-04 19:50:19.000000000 -0500
32801 +++ linux-2.6.37/fs/ntfs/dir.c 2011-01-17 02:41:01.000000000 -0500
32802 @@ -1329,7 +1329,7 @@ find_next_index_buffer:
32803 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
32804 ~(s64)(ndir->itype.index.block_size - 1)));
32805 /* Bounds checks. */
32806 - if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
32807 + if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
32808 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
32809 "inode 0x%lx or driver bug.", vdir->i_ino);
32811 diff -urNp linux-2.6.37/fs/ntfs/file.c linux-2.6.37/fs/ntfs/file.c
32812 --- linux-2.6.37/fs/ntfs/file.c 2011-01-04 19:50:19.000000000 -0500
32813 +++ linux-2.6.37/fs/ntfs/file.c 2011-01-17 02:41:01.000000000 -0500
32814 @@ -2223,6 +2223,6 @@ const struct inode_operations ntfs_file_
32815 #endif /* NTFS_RW */
32818 -const struct file_operations ntfs_empty_file_ops = {};
32819 +const struct file_operations ntfs_empty_file_ops __read_only;
32821 -const struct inode_operations ntfs_empty_inode_ops = {};
32822 +const struct inode_operations ntfs_empty_inode_ops __read_only;
32823 diff -urNp linux-2.6.37/fs/ocfs2/localalloc.c linux-2.6.37/fs/ocfs2/localalloc.c
32824 --- linux-2.6.37/fs/ocfs2/localalloc.c 2011-01-04 19:50:19.000000000 -0500
32825 +++ linux-2.6.37/fs/ocfs2/localalloc.c 2011-01-17 02:41:01.000000000 -0500
32826 @@ -1307,7 +1307,7 @@ static int ocfs2_local_alloc_slide_windo
32830 - atomic_inc(&osb->alloc_stats.moves);
32831 + atomic_inc_unchecked(&osb->alloc_stats.moves);
32835 diff -urNp linux-2.6.37/fs/ocfs2/ocfs2.h linux-2.6.37/fs/ocfs2/ocfs2.h
32836 --- linux-2.6.37/fs/ocfs2/ocfs2.h 2011-01-04 19:50:19.000000000 -0500
32837 +++ linux-2.6.37/fs/ocfs2/ocfs2.h 2011-01-17 02:41:01.000000000 -0500
32838 @@ -230,11 +230,11 @@ enum ocfs2_vol_state
32840 struct ocfs2_alloc_stats
32843 - atomic_t local_data;
32844 - atomic_t bitmap_data;
32845 - atomic_t bg_allocs;
32846 - atomic_t bg_extends;
32847 + atomic_unchecked_t moves;
32848 + atomic_unchecked_t local_data;
32849 + atomic_unchecked_t bitmap_data;
32850 + atomic_unchecked_t bg_allocs;
32851 + atomic_unchecked_t bg_extends;
32854 enum ocfs2_local_alloc_state
32855 diff -urNp linux-2.6.37/fs/ocfs2/suballoc.c linux-2.6.37/fs/ocfs2/suballoc.c
32856 --- linux-2.6.37/fs/ocfs2/suballoc.c 2011-01-04 19:50:19.000000000 -0500
32857 +++ linux-2.6.37/fs/ocfs2/suballoc.c 2011-01-17 02:41:01.000000000 -0500
32858 @@ -877,7 +877,7 @@ static int ocfs2_reserve_suballoc_bits(s
32859 mlog_errno(status);
32862 - atomic_inc(&osb->alloc_stats.bg_extends);
32863 + atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
32865 /* You should never ask for this much metadata */
32866 BUG_ON(bits_wanted >
32867 @@ -2012,7 +2012,7 @@ int ocfs2_claim_metadata(handle_t *handl
32868 mlog_errno(status);
32871 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
32872 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
32874 *suballoc_loc = res.sr_bg_blkno;
32875 *suballoc_bit_start = res.sr_bit_offset;
32876 @@ -2219,7 +2219,7 @@ int ocfs2_claim_new_inode(handle_t *hand
32877 mlog_errno(status);
32880 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
32881 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
32883 BUG_ON(res.sr_bits != 1);
32885 @@ -2324,7 +2324,7 @@ int __ocfs2_claim_clusters(handle_t *han
32889 - atomic_inc(&osb->alloc_stats.local_data);
32890 + atomic_inc_unchecked(&osb->alloc_stats.local_data);
32892 if (min_clusters > (osb->bitmap_cpg - 1)) {
32893 /* The only paths asking for contiguousness
32894 @@ -2350,7 +2350,7 @@ int __ocfs2_claim_clusters(handle_t *han
32895 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
32897 res.sr_bit_offset);
32898 - atomic_inc(&osb->alloc_stats.bitmap_data);
32899 + atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
32900 *num_clusters = res.sr_bits;
32903 diff -urNp linux-2.6.37/fs/ocfs2/super.c linux-2.6.37/fs/ocfs2/super.c
32904 --- linux-2.6.37/fs/ocfs2/super.c 2011-01-04 19:50:19.000000000 -0500
32905 +++ linux-2.6.37/fs/ocfs2/super.c 2011-01-17 02:41:01.000000000 -0500
32906 @@ -297,11 +297,11 @@ static int ocfs2_osb_dump(struct ocfs2_s
32907 "%10s => GlobalAllocs: %d LocalAllocs: %d "
32908 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
32910 - atomic_read(&osb->alloc_stats.bitmap_data),
32911 - atomic_read(&osb->alloc_stats.local_data),
32912 - atomic_read(&osb->alloc_stats.bg_allocs),
32913 - atomic_read(&osb->alloc_stats.moves),
32914 - atomic_read(&osb->alloc_stats.bg_extends));
32915 + atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
32916 + atomic_read_unchecked(&osb->alloc_stats.local_data),
32917 + atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
32918 + atomic_read_unchecked(&osb->alloc_stats.moves),
32919 + atomic_read_unchecked(&osb->alloc_stats.bg_extends));
32921 out += snprintf(buf + out, len - out,
32922 "%10s => State: %u Descriptor: %llu Size: %u bits "
32923 @@ -2122,11 +2122,11 @@ static int ocfs2_initialize_super(struct
32924 spin_lock_init(&osb->osb_xattr_lock);
32925 ocfs2_init_steal_slots(osb);
32927 - atomic_set(&osb->alloc_stats.moves, 0);
32928 - atomic_set(&osb->alloc_stats.local_data, 0);
32929 - atomic_set(&osb->alloc_stats.bitmap_data, 0);
32930 - atomic_set(&osb->alloc_stats.bg_allocs, 0);
32931 - atomic_set(&osb->alloc_stats.bg_extends, 0);
32932 + atomic_set_unchecked(&osb->alloc_stats.moves, 0);
32933 + atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
32934 + atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
32935 + atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
32936 + atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
32938 /* Copy the blockcheck stats from the superblock probe */
32939 osb->osb_ecc_stats = *stats;
32940 diff -urNp linux-2.6.37/fs/ocfs2/symlink.c linux-2.6.37/fs/ocfs2/symlink.c
32941 --- linux-2.6.37/fs/ocfs2/symlink.c 2011-01-04 19:50:19.000000000 -0500
32942 +++ linux-2.6.37/fs/ocfs2/symlink.c 2011-01-17 02:41:01.000000000 -0500
32943 @@ -148,7 +148,7 @@ bail:
32945 static void ocfs2_fast_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
32947 - char *link = nd_get_link(nd);
32948 + const char *link = nd_get_link(nd);
32952 diff -urNp linux-2.6.37/fs/open.c linux-2.6.37/fs/open.c
32953 --- linux-2.6.37/fs/open.c 2011-01-04 19:50:19.000000000 -0500
32954 +++ linux-2.6.37/fs/open.c 2011-01-17 02:49:14.000000000 -0500
32955 @@ -112,6 +112,10 @@ static long do_sys_truncate(const char _
32956 error = locks_verify_truncate(inode, NULL, length);
32958 error = security_path_truncate(&path);
32960 + if (!error && !gr_acl_handle_truncate(path.dentry, path.mnt))
32964 error = do_truncate(path.dentry, length, 0, NULL);
32966 @@ -345,6 +349,9 @@ SYSCALL_DEFINE3(faccessat, int, dfd, con
32967 if (__mnt_is_readonly(path.mnt))
32970 + if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
32976 @@ -371,6 +378,8 @@ SYSCALL_DEFINE1(chdir, const char __user
32980 + gr_log_chdir(path.dentry, path.mnt);
32982 set_fs_pwd(current->fs, &path);
32985 @@ -397,6 +406,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd
32988 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
32990 + if (!error && !gr_chroot_fchdir(file->f_path.dentry, file->f_path.mnt))
32994 + gr_log_chdir(file->f_path.dentry, file->f_path.mnt);
32997 set_fs_pwd(current->fs, &file->f_path);
32999 @@ -425,7 +441,18 @@ SYSCALL_DEFINE1(chroot, const char __use
33003 + if (gr_handle_chroot_chroot(path.dentry, path.mnt))
33004 + goto dput_and_out;
33006 + if (gr_handle_chroot_caps(&path)) {
33008 + goto dput_and_out;
33011 set_fs_root(current->fs, &path);
33013 + gr_handle_chroot_chdir(&path);
33018 @@ -453,12 +480,25 @@ SYSCALL_DEFINE2(fchmod, unsigned int, fd
33019 err = mnt_want_write_file(file);
33023 mutex_lock(&inode->i_mutex);
33025 + if (!gr_acl_handle_fchmod(dentry, file->f_vfsmnt, mode)) {
33030 err = security_path_chmod(dentry, file->f_vfsmnt, mode);
33033 if (mode == (mode_t) -1)
33034 mode = inode->i_mode;
33036 + if (gr_handle_chroot_chmod(dentry, file->f_vfsmnt, mode)) {
33041 newattrs.ia_mode = (mode & S_IALLUGO) | (inode->i_mode & ~S_IALLUGO);
33042 newattrs.ia_valid = ATTR_MODE | ATTR_CTIME;
33043 err = notify_change(dentry, &newattrs);
33044 @@ -486,12 +526,25 @@ SYSCALL_DEFINE3(fchmodat, int, dfd, cons
33045 error = mnt_want_write(path.mnt);
33049 mutex_lock(&inode->i_mutex);
33051 + if (!gr_acl_handle_chmod(path.dentry, path.mnt, mode)) {
33056 error = security_path_chmod(path.dentry, path.mnt, mode);
33059 if (mode == (mode_t) -1)
33060 mode = inode->i_mode;
33062 + if (gr_handle_chroot_chmod(path.dentry, path.mnt, mode)) {
33067 newattrs.ia_mode = (mode & S_IALLUGO) | (inode->i_mode & ~S_IALLUGO);
33068 newattrs.ia_valid = ATTR_MODE | ATTR_CTIME;
33069 error = notify_change(path.dentry, &newattrs);
33070 @@ -515,6 +568,9 @@ static int chown_common(struct path *pat
33072 struct iattr newattrs;
33074 + if (!gr_acl_handle_chown(path->dentry, path->mnt))
33077 newattrs.ia_valid = ATTR_CTIME;
33078 if (user != (uid_t) -1) {
33079 newattrs.ia_valid |= ATTR_UID;
33080 @@ -883,7 +939,10 @@ long do_sys_open(int dfd, const char __u
33081 if (!IS_ERR(tmp)) {
33082 fd = get_unused_fd_flags(flags);
33084 - struct file *f = do_filp_open(dfd, tmp, flags, mode, 0);
33086 + /* don't allow to be set by userland */
33087 + flags &= ~FMODE_GREXEC;
33088 + f = do_filp_open(dfd, tmp, flags, mode, 0);
33092 diff -urNp linux-2.6.37/fs/pipe.c linux-2.6.37/fs/pipe.c
33093 --- linux-2.6.37/fs/pipe.c 2011-01-04 19:50:19.000000000 -0500
33094 +++ linux-2.6.37/fs/pipe.c 2011-01-17 02:41:01.000000000 -0500
33095 @@ -420,9 +420,9 @@ redo:
33097 if (bufs) /* More to do? */
33099 - if (!pipe->writers)
33100 + if (!atomic_read(&pipe->writers))
33102 - if (!pipe->waiting_writers) {
33103 + if (!atomic_read(&pipe->waiting_writers)) {
33104 /* syscall merging: Usually we must not sleep
33105 * if O_NONBLOCK is set, or if we got some data.
33106 * But if a writer sleeps in kernel space, then
33107 @@ -481,7 +481,7 @@ pipe_write(struct kiocb *iocb, const str
33108 mutex_lock(&inode->i_mutex);
33109 pipe = inode->i_pipe;
33111 - if (!pipe->readers) {
33112 + if (!atomic_read(&pipe->readers)) {
33113 send_sig(SIGPIPE, current, 0);
33116 @@ -530,7 +530,7 @@ redo1:
33120 - if (!pipe->readers) {
33121 + if (!atomic_read(&pipe->readers)) {
33122 send_sig(SIGPIPE, current, 0);
33125 @@ -616,9 +616,9 @@ redo2:
33126 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
33129 - pipe->waiting_writers++;
33130 + atomic_inc(&pipe->waiting_writers);
33132 - pipe->waiting_writers--;
33133 + atomic_dec(&pipe->waiting_writers);
33136 mutex_unlock(&inode->i_mutex);
33137 @@ -685,7 +685,7 @@ pipe_poll(struct file *filp, poll_table
33139 if (filp->f_mode & FMODE_READ) {
33140 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
33141 - if (!pipe->writers && filp->f_version != pipe->w_counter)
33142 + if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
33146 @@ -695,7 +695,7 @@ pipe_poll(struct file *filp, poll_table
33147 * Most Unices do not set POLLERR for FIFOs but on Linux they
33148 * behave exactly like pipes for poll().
33150 - if (!pipe->readers)
33151 + if (!atomic_read(&pipe->readers))
33155 @@ -709,10 +709,10 @@ pipe_release(struct inode *inode, int de
33157 mutex_lock(&inode->i_mutex);
33158 pipe = inode->i_pipe;
33159 - pipe->readers -= decr;
33160 - pipe->writers -= decw;
33161 + atomic_sub(decr, &pipe->readers);
33162 + atomic_sub(decw, &pipe->writers);
33164 - if (!pipe->readers && !pipe->writers) {
33165 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
33166 free_pipe_info(inode);
33168 wake_up_interruptible_sync(&pipe->wait);
33169 @@ -802,7 +802,7 @@ pipe_read_open(struct inode *inode, stru
33171 if (inode->i_pipe) {
33173 - inode->i_pipe->readers++;
33174 + atomic_inc(&inode->i_pipe->readers);
33177 mutex_unlock(&inode->i_mutex);
33178 @@ -819,7 +819,7 @@ pipe_write_open(struct inode *inode, str
33180 if (inode->i_pipe) {
33182 - inode->i_pipe->writers++;
33183 + atomic_inc(&inode->i_pipe->writers);
33186 mutex_unlock(&inode->i_mutex);
33187 @@ -837,9 +837,9 @@ pipe_rdwr_open(struct inode *inode, stru
33188 if (inode->i_pipe) {
33190 if (filp->f_mode & FMODE_READ)
33191 - inode->i_pipe->readers++;
33192 + atomic_inc(&inode->i_pipe->readers);
33193 if (filp->f_mode & FMODE_WRITE)
33194 - inode->i_pipe->writers++;
33195 + atomic_inc(&inode->i_pipe->writers);
33198 mutex_unlock(&inode->i_mutex);
33199 @@ -931,7 +931,7 @@ void free_pipe_info(struct inode *inode)
33200 inode->i_pipe = NULL;
33203 -static struct vfsmount *pipe_mnt __read_mostly;
33204 +struct vfsmount *pipe_mnt __read_mostly;
33207 * pipefs_dname() is called from d_path().
33208 @@ -961,7 +961,8 @@ static struct inode * get_pipe_inode(voi
33210 inode->i_pipe = pipe;
33212 - pipe->readers = pipe->writers = 1;
33213 + atomic_set(&pipe->readers, 1);
33214 + atomic_set(&pipe->writers, 1);
33215 inode->i_fop = &rdwr_pipefifo_fops;
33218 diff -urNp linux-2.6.37/fs/proc/array.c linux-2.6.37/fs/proc/array.c
33219 --- linux-2.6.37/fs/proc/array.c 2011-01-04 19:50:19.000000000 -0500
33220 +++ linux-2.6.37/fs/proc/array.c 2011-01-17 02:41:01.000000000 -0500
33222 #include <linux/tty.h>
33223 #include <linux/string.h>
33224 #include <linux/mman.h>
33225 +#include <linux/grsecurity.h>
33226 #include <linux/proc_fs.h>
33227 #include <linux/ioport.h>
33228 #include <linux/uaccess.h>
33229 @@ -337,6 +338,21 @@ static void task_cpus_allowed(struct seq
33230 seq_printf(m, "\n");
33233 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
33234 +static inline void task_pax(struct seq_file *m, struct task_struct *p)
33237 + seq_printf(m, "PaX:\t%c%c%c%c%c\n",
33238 + p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
33239 + p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
33240 + p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
33241 + p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
33242 + p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
33244 + seq_printf(m, "PaX:\t-----\n");
33248 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
33249 struct pid *pid, struct task_struct *task)
33251 @@ -357,9 +373,24 @@ int proc_pid_status(struct seq_file *m,
33252 task_show_regs(m, task);
33254 task_context_switch_counts(m, task);
33256 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
33257 + task_pax(m, task);
33260 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
33261 + task_grsec_rbac(m, task);
33267 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
33268 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
33269 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
33270 + _mm->pax_flags & MF_PAX_SEGMEXEC))
33273 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
33274 struct pid *pid, struct task_struct *task, int whole)
33276 @@ -452,6 +483,19 @@ static int do_task_stat(struct seq_file
33277 gtime = task->gtime;
33280 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
33281 + if (PAX_RAND_FLAGS(mm)) {
33287 +#ifdef CONFIG_GRKERNSEC_HIDESYM
33293 /* scale priority and nice values from timeslices to -20..20 */
33294 /* to make it look like a "normal" Unix priority/nice value */
33295 priority = task_prio(task);
33296 @@ -492,9 +536,15 @@ static int do_task_stat(struct seq_file
33298 mm ? get_mm_rss(mm) : 0,
33300 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
33301 + PAX_RAND_FLAGS(mm) ? 1 : (mm ? mm->start_code : 0),
33302 + PAX_RAND_FLAGS(mm) ? 1 : (mm ? mm->end_code : 0),
33303 + PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0),
33305 mm ? mm->start_code : 0,
33306 mm ? mm->end_code : 0,
33307 (permitted && mm) ? mm->start_stack : 0,
33311 /* The signal information here is obsolete.
33312 @@ -547,3 +597,10 @@ int proc_pid_statm(struct seq_file *m, s
33317 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
33318 +int proc_pid_ipaddr(struct task_struct *task, char *buffer)
33320 + return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
33323 diff -urNp linux-2.6.37/fs/proc/base.c linux-2.6.37/fs/proc/base.c
33324 --- linux-2.6.37/fs/proc/base.c 2011-01-04 19:50:19.000000000 -0500
33325 +++ linux-2.6.37/fs/proc/base.c 2011-01-17 02:41:01.000000000 -0500
33326 @@ -104,6 +104,22 @@ struct pid_entry {
33330 +struct getdents_callback {
33331 + struct linux_dirent __user * current_dir;
33332 + struct linux_dirent __user * previous;
33333 + struct file * file;
33338 +static int gr_fake_filldir(void * __buf, const char *name, int namlen,
33339 + loff_t offset, u64 ino, unsigned int d_type)
33341 + struct getdents_callback * buf = (struct getdents_callback *) __buf;
33342 + buf->error = -EINVAL;
33346 #define NOD(NAME, MODE, IOP, FOP, OP) { \
33348 .len = sizeof(NAME) - 1, \
33349 @@ -203,6 +219,9 @@ static int check_mem_permission(struct t
33350 if (task == current)
33353 + if (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))
33357 * If current is actively ptrace'ing, and would also be
33358 * permitted to freshly attach with ptrace now, permit it.
33359 @@ -250,6 +269,9 @@ static int proc_pid_cmdline(struct task_
33361 goto out_mm; /* Shh! No looking before we're done */
33363 + if (gr_acl_handle_procpidmem(task))
33366 len = mm->arg_end - mm->arg_start;
33368 if (len > PAGE_SIZE)
33369 @@ -277,12 +299,28 @@ out:
33373 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
33374 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
33375 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
33376 + _mm->pax_flags & MF_PAX_SEGMEXEC))
33379 static int proc_pid_auxv(struct task_struct *task, char *buffer)
33382 struct mm_struct *mm = get_task_mm(task);
33384 unsigned int nwords = 0;
33386 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
33387 + /* allow if we're currently ptracing this task */
33388 + if (PAX_RAND_FLAGS(mm) &&
33389 + (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
33397 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
33398 @@ -296,7 +334,7 @@ static int proc_pid_auxv(struct task_str
33402 -#ifdef CONFIG_KALLSYMS
33403 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
33405 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
33406 * Returns the resolved symbol. If that fails, simply return the address.
33407 @@ -318,7 +356,7 @@ static int proc_pid_wchan(struct task_st
33409 #endif /* CONFIG_KALLSYMS */
33411 -#ifdef CONFIG_STACKTRACE
33412 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
33414 #define MAX_STACK_TRACE_DEPTH 64
33416 @@ -509,7 +547,7 @@ static int proc_pid_limits(struct task_s
33420 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
33421 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
33422 static int proc_pid_syscall(struct task_struct *task, char *buffer)
33425 @@ -930,6 +968,9 @@ static ssize_t environ_read(struct file
33429 + if (gr_acl_handle_procpidmem(task))
33432 if (!ptrace_may_access(task, PTRACE_MODE_READ))
33435 @@ -1663,7 +1704,11 @@ static struct inode *proc_pid_make_inode
33437 cred = __task_cred(task);
33438 inode->i_uid = cred->euid;
33439 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
33440 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
33442 inode->i_gid = cred->egid;
33446 security_task_to_inode(task, inode);
33447 @@ -1681,6 +1726,9 @@ static int pid_getattr(struct vfsmount *
33448 struct inode *inode = dentry->d_inode;
33449 struct task_struct *task;
33450 const struct cred *cred;
33451 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
33452 + const struct cred *tmpcred = current_cred();
33455 generic_fillattr(inode, stat);
33457 @@ -1688,12 +1736,34 @@ static int pid_getattr(struct vfsmount *
33460 task = pid_task(proc_pid(inode), PIDTYPE_PID);
33462 + if (task && (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))) {
33463 + rcu_read_unlock();
33468 + cred = __task_cred(task);
33469 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
33470 + if (!tmpcred->uid || (tmpcred->uid == cred->uid)
33471 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
33472 + || in_group_p(CONFIG_GRKERNSEC_PROC_GID)
33476 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
33477 +#ifdef CONFIG_GRKERNSEC_PROC_USER
33478 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
33479 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
33480 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
33482 task_dumpable(task)) {
33483 - cred = __task_cred(task);
33484 stat->uid = cred->euid;
33485 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
33486 + stat->gid = CONFIG_GRKERNSEC_PROC_GID;
33488 stat->gid = cred->egid;
33493 @@ -1725,11 +1795,20 @@ static int pid_revalidate(struct dentry
33496 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
33497 +#ifdef CONFIG_GRKERNSEC_PROC_USER
33498 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
33499 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
33500 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
33502 task_dumpable(task)) {
33504 cred = __task_cred(task);
33505 inode->i_uid = cred->euid;
33506 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
33507 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
33509 inode->i_gid = cred->egid;
33514 @@ -1850,7 +1929,8 @@ static int proc_fd_info(struct inode *in
33515 int fd = proc_fd(inode);
33518 - files = get_files_struct(task);
33519 + if (!gr_acl_handle_procpidmem(task))
33520 + files = get_files_struct(task);
33521 put_task_struct(task);
33524 @@ -2104,12 +2184,22 @@ static const struct file_operations proc
33525 static int proc_fd_permission(struct inode *inode, int mask)
33528 + struct task_struct *task;
33530 rv = generic_permission(inode, mask, NULL);
33534 if (task_pid(current) == proc_pid(inode))
33537 + task = get_proc_task(inode);
33538 + if (task == NULL)
33541 + if (gr_acl_handle_procpidmem(task))
33544 + put_task_struct(task);
33549 @@ -2219,6 +2309,9 @@ static struct dentry *proc_pident_lookup
33553 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
33557 * Yes, it does not scale. And it should not. Don't add
33558 * new entries into /proc/<tgid>/ without very good reasons.
33559 @@ -2263,6 +2356,9 @@ static int proc_pident_readdir(struct fi
33563 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
33569 @@ -2533,7 +2629,7 @@ static void *proc_self_follow_link(struc
33570 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
33573 - char *s = nd_get_link(nd);
33574 + const char *s = nd_get_link(nd);
33578 @@ -2734,7 +2830,7 @@ static const struct pid_entry tgid_base_
33579 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
33581 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
33582 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
33583 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
33584 INF("syscall", S_IRUSR, proc_pid_syscall),
33586 INF("cmdline", S_IRUGO, proc_pid_cmdline),
33587 @@ -2759,10 +2855,10 @@ static const struct pid_entry tgid_base_
33588 #ifdef CONFIG_SECURITY
33589 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
33591 -#ifdef CONFIG_KALLSYMS
33592 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
33593 INF("wchan", S_IRUGO, proc_pid_wchan),
33595 -#ifdef CONFIG_STACKTRACE
33596 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
33597 ONE("stack", S_IRUSR, proc_pid_stack),
33599 #ifdef CONFIG_SCHEDSTATS
33600 @@ -2793,6 +2889,9 @@ static const struct pid_entry tgid_base_
33601 INF("io", S_IRUGO, proc_tgid_io_accounting),
33603 ONE("nsproxy", S_IRUGO, proc_pid_nsproxy),
33604 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
33605 + INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
33609 static int proc_tgid_base_readdir(struct file * filp,
33610 @@ -2918,7 +3017,14 @@ static struct dentry *proc_pid_instantia
33614 +#ifdef CONFIG_GRKERNSEC_PROC_USER
33615 + inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
33616 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
33617 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
33618 + inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
33620 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
33622 inode->i_op = &proc_tgid_base_inode_operations;
33623 inode->i_fop = &proc_tgid_base_operations;
33624 inode->i_flags|=S_IMMUTABLE;
33625 @@ -2960,7 +3066,11 @@ struct dentry *proc_pid_lookup(struct in
33629 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
33630 + goto out_put_task;
33632 result = proc_pid_instantiate(dir, dentry, task, NULL);
33634 put_task_struct(task);
33637 @@ -3025,6 +3135,11 @@ int proc_pid_readdir(struct file * filp,
33639 unsigned int nr = filp->f_pos - FIRST_PROCESS_ENTRY;
33640 struct task_struct *reaper = get_proc_task_real(filp->f_path.dentry->d_inode);
33641 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
33642 + const struct cred *tmpcred = current_cred();
33643 + const struct cred *itercred;
33645 + filldir_t __filldir = filldir;
33646 struct tgid_iter iter;
33647 struct pid_namespace *ns;
33649 @@ -3043,8 +3158,27 @@ int proc_pid_readdir(struct file * filp,
33650 for (iter = next_tgid(ns, iter);
33652 iter.tgid += 1, iter = next_tgid(ns, iter)) {
33653 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
33655 + itercred = __task_cred(iter.task);
33657 + if (gr_pid_is_chrooted(iter.task) || gr_check_hidden_task(iter.task)
33658 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
33659 + || (tmpcred->uid && (itercred->uid != tmpcred->uid)
33660 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
33661 + && !in_group_p(CONFIG_GRKERNSEC_PROC_GID)
33666 + __filldir = &gr_fake_filldir;
33668 + __filldir = filldir;
33669 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
33670 + rcu_read_unlock();
33672 filp->f_pos = iter.tgid + TGID_OFFSET;
33673 if (!vx_proc_task_visible(iter.task))
33675 - if (proc_pid_fill_cache(filp, dirent, filldir, iter) < 0) {
33676 + if (proc_pid_fill_cache(filp, dirent, __filldir, iter) < 0) {
33677 put_task_struct(iter.task);
33678 @@ -3071,7 +3205,7 @@ static const struct pid_entry tid_base_s
33679 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
33681 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
33682 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
33683 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
33684 INF("syscall", S_IRUSR, proc_pid_syscall),
33686 INF("cmdline", S_IRUGO, proc_pid_cmdline),
33687 @@ -3095,10 +3229,10 @@ static const struct pid_entry tid_base_s
33688 #ifdef CONFIG_SECURITY
33689 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
33691 -#ifdef CONFIG_KALLSYMS
33692 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
33693 INF("wchan", S_IRUGO, proc_pid_wchan),
33695 -#ifdef CONFIG_STACKTRACE
33696 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
33697 ONE("stack", S_IRUSR, proc_pid_stack),
33699 #ifdef CONFIG_SCHEDSTATS
33700 diff -urNp linux-2.6.37/fs/proc/cmdline.c linux-2.6.37/fs/proc/cmdline.c
33701 --- linux-2.6.37/fs/proc/cmdline.c 2011-01-04 19:50:19.000000000 -0500
33702 +++ linux-2.6.37/fs/proc/cmdline.c 2011-01-17 02:41:01.000000000 -0500
33703 @@ -23,7 +23,11 @@ static const struct file_operations cmdl
33705 static int __init proc_cmdline_init(void)
33707 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
33708 + proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
33710 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
33714 module_init(proc_cmdline_init);
33715 diff -urNp linux-2.6.37/fs/proc/devices.c linux-2.6.37/fs/proc/devices.c
33716 --- linux-2.6.37/fs/proc/devices.c 2011-01-04 19:50:19.000000000 -0500
33717 +++ linux-2.6.37/fs/proc/devices.c 2011-01-17 02:41:01.000000000 -0500
33718 @@ -64,7 +64,11 @@ static const struct file_operations proc
33720 static int __init proc_devices_init(void)
33722 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
33723 + proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
33725 proc_create("devices", 0, NULL, &proc_devinfo_operations);
33729 module_init(proc_devices_init);
33730 diff -urNp linux-2.6.37/fs/proc/inode.c linux-2.6.37/fs/proc/inode.c
33731 --- linux-2.6.37/fs/proc/inode.c 2011-01-04 19:50:19.000000000 -0500
33732 +++ linux-2.6.37/fs/proc/inode.c 2011-01-17 02:41:01.000000000 -0500
33733 @@ -425,7 +425,11 @@ struct inode *proc_get_inode(struct supe
33735 inode->i_mode = de->mode;
33736 inode->i_uid = de->uid;
33737 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
33738 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
33740 inode->i_gid = de->gid;
33744 inode->i_size = de->size;
33745 diff -urNp linux-2.6.37/fs/proc/internal.h linux-2.6.37/fs/proc/internal.h
33746 --- linux-2.6.37/fs/proc/internal.h 2011-01-04 19:50:19.000000000 -0500
33747 +++ linux-2.6.37/fs/proc/internal.h 2011-01-17 02:41:01.000000000 -0500
33748 @@ -51,6 +51,9 @@ extern int proc_pid_status(struct seq_fi
33749 extern int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
33750 struct pid *pid, struct task_struct *task);
33752 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
33753 +extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
33755 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
33757 extern const struct file_operations proc_maps_operations;
33758 diff -urNp linux-2.6.37/fs/proc/Kconfig linux-2.6.37/fs/proc/Kconfig
33759 --- linux-2.6.37/fs/proc/Kconfig 2011-01-04 19:50:19.000000000 -0500
33760 +++ linux-2.6.37/fs/proc/Kconfig 2011-01-17 02:41:01.000000000 -0500
33761 @@ -30,12 +30,12 @@ config PROC_FS
33764 bool "/proc/kcore support" if !ARM
33765 - depends on PROC_FS && MMU
33766 + depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
33769 bool "/proc/vmcore support"
33770 - depends on PROC_FS && CRASH_DUMP
33772 + depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
33775 Exports the dump image of crashed kernel in ELF format.
33777 @@ -59,8 +59,8 @@ config PROC_SYSCTL
33780 config PROC_PAGE_MONITOR
33782 - depends on PROC_FS && MMU
33784 + depends on PROC_FS && MMU && !GRKERNSEC
33785 bool "Enable /proc page monitoring" if EMBEDDED
33787 Various /proc files exist to monitor process memory utilization:
33788 diff -urNp linux-2.6.37/fs/proc/kcore.c linux-2.6.37/fs/proc/kcore.c
33789 --- linux-2.6.37/fs/proc/kcore.c 2011-01-04 19:50:19.000000000 -0500
33790 +++ linux-2.6.37/fs/proc/kcore.c 2011-01-17 02:41:01.000000000 -0500
33791 @@ -478,9 +478,10 @@ read_kcore(struct file *file, char __use
33792 * the addresses in the elf_phdr on our list.
33794 start = kc_offset_to_vaddr(*fpos - elf_buflen);
33795 - if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
33796 + tsz = PAGE_SIZE - (start & ~PAGE_MASK);
33797 + if (tsz > buflen)
33802 struct kcore_list *m;
33804 @@ -509,20 +510,23 @@ read_kcore(struct file *file, char __use
33807 if (kern_addr_valid(start)) {
33810 + mm_segment_t oldfs;
33812 - n = copy_to_user(buffer, (char *)start, tsz);
33814 - * We cannot distingush between fault on source
33815 - * and fault on destination. When this happens
33816 - * we clear too and hope it will trigger the
33820 - if (clear_user(buffer + tsz - n,
33822 + elf_buf = kmalloc(tsz, GFP_KERNEL);
33825 + oldfs = get_fs();
33826 + set_fs(KERNEL_DS);
33827 + if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
33829 + if (copy_to_user(buffer, elf_buf, tsz)) {
33837 if (clear_user(buffer, tsz))
33839 @@ -542,6 +546,9 @@ read_kcore(struct file *file, char __use
33841 static int open_kcore(struct inode *inode, struct file *filp)
33843 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
33846 if (!capable(CAP_SYS_RAWIO))
33848 if (kcore_need_update)
33849 diff -urNp linux-2.6.37/fs/proc/meminfo.c linux-2.6.37/fs/proc/meminfo.c
33850 --- linux-2.6.37/fs/proc/meminfo.c 2011-01-04 19:50:19.000000000 -0500
33851 +++ linux-2.6.37/fs/proc/meminfo.c 2011-01-17 02:41:01.000000000 -0500
33852 @@ -149,7 +149,7 @@ static int meminfo_proc_show(struct seq_
33854 vmi.largest_chunk >> 10
33855 #ifdef CONFIG_MEMORY_FAILURE
33856 - ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10)
33857 + ,atomic_long_read_unchecked(&mce_bad_pages) << (PAGE_SHIFT - 10)
33861 diff -urNp linux-2.6.37/fs/proc/nommu.c linux-2.6.37/fs/proc/nommu.c
33862 --- linux-2.6.37/fs/proc/nommu.c 2011-01-04 19:50:19.000000000 -0500
33863 +++ linux-2.6.37/fs/proc/nommu.c 2011-01-17 02:41:01.000000000 -0500
33864 @@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_
33867 seq_printf(m, "%*c", len, ' ');
33868 - seq_path(m, &file->f_path, "");
33869 + seq_path(m, &file->f_path, "\n\\");
33873 diff -urNp linux-2.6.37/fs/proc/proc_net.c linux-2.6.37/fs/proc/proc_net.c
33874 --- linux-2.6.37/fs/proc/proc_net.c 2011-01-04 19:50:19.000000000 -0500
33875 +++ linux-2.6.37/fs/proc/proc_net.c 2011-01-17 02:41:01.000000000 -0500
33876 @@ -105,6 +105,17 @@ static struct net *get_proc_task_net(str
33877 struct task_struct *task;
33878 struct nsproxy *ns;
33879 struct net *net = NULL;
33880 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
33881 + const struct cred *cred = current_cred();
33884 +#ifdef CONFIG_GRKERNSEC_PROC_USER
33887 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
33888 + if (cred->fsuid && !in_group_p(CONFIG_GRKERNSEC_PROC_GID))
33893 task = pid_task(proc_pid(dir), PIDTYPE_PID);
33894 diff -urNp linux-2.6.37/fs/proc/proc_sysctl.c linux-2.6.37/fs/proc/proc_sysctl.c
33895 --- linux-2.6.37/fs/proc/proc_sysctl.c 2011-01-04 19:50:19.000000000 -0500
33896 +++ linux-2.6.37/fs/proc/proc_sysctl.c 2011-01-17 02:41:01.000000000 -0500
33898 #include <linux/security.h>
33899 #include "internal.h"
33901 +extern __u32 gr_handle_sysctl(const struct ctl_table *table, const int op);
33903 static const struct dentry_operations proc_sys_dentry_operations;
33904 static const struct file_operations proc_sys_file_operations;
33905 static const struct inode_operations proc_sys_inode_operations;
33906 @@ -111,6 +113,9 @@ static struct dentry *proc_sys_lookup(st
33910 + if (gr_handle_sysctl(p, MAY_EXEC))
33913 err = ERR_PTR(-ENOMEM);
33914 inode = proc_sys_make_inode(dir->i_sb, h ? h : head, p);
33916 @@ -230,6 +235,9 @@ static int scan(struct ctl_table_header
33917 if (*pos < file->f_pos)
33920 + if (gr_handle_sysctl(table, 0))
33923 res = proc_sys_fill_cache(file, dirent, filldir, head, table);
33926 @@ -355,6 +363,9 @@ static int proc_sys_getattr(struct vfsmo
33928 return PTR_ERR(head);
33930 + if (table && gr_handle_sysctl(table, MAY_EXEC))
33933 generic_fillattr(inode, stat);
33935 stat->mode = (stat->mode & S_IFMT) | table->mode;
33936 diff -urNp linux-2.6.37/fs/proc/root.c linux-2.6.37/fs/proc/root.c
33937 --- linux-2.6.37/fs/proc/root.c 2011-01-04 19:50:19.000000000 -0500
33938 +++ linux-2.6.37/fs/proc/root.c 2011-01-17 02:41:01.000000000 -0500
33939 @@ -132,7 +132,15 @@ void __init proc_root_init(void)
33940 #ifdef CONFIG_PROC_DEVICETREE
33941 proc_device_tree_init();
33943 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
33944 +#ifdef CONFIG_GRKERNSEC_PROC_USER
33945 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
33946 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
33947 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
33950 proc_mkdir("bus", NULL);
33955 diff -urNp linux-2.6.37/fs/proc/task_mmu.c linux-2.6.37/fs/proc/task_mmu.c
33956 --- linux-2.6.37/fs/proc/task_mmu.c 2011-01-04 19:50:19.000000000 -0500
33957 +++ linux-2.6.37/fs/proc/task_mmu.c 2011-01-17 02:41:01.000000000 -0500
33958 @@ -49,8 +49,13 @@ void task_mem(struct seq_file *m, struct
33959 "VmExe:\t%8lu kB\n"
33960 "VmLib:\t%8lu kB\n"
33961 "VmPTE:\t%8lu kB\n"
33962 - "VmSwap:\t%8lu kB\n",
33963 - hiwater_vm << (PAGE_SHIFT-10),
33964 + "VmSwap:\t%8lu kB\n"
33966 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
33967 + "CsBase:\t%8lx\nCsLim:\t%8lx\n"
33970 + ,hiwater_vm << (PAGE_SHIFT-10),
33971 (total_vm - mm->reserved_vm) << (PAGE_SHIFT-10),
33972 mm->locked_vm << (PAGE_SHIFT-10),
33973 hiwater_rss << (PAGE_SHIFT-10),
33974 @@ -58,7 +63,13 @@ void task_mem(struct seq_file *m, struct
33975 data << (PAGE_SHIFT-10),
33976 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
33977 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
33978 - swap << (PAGE_SHIFT-10));
33979 + swap << (PAGE_SHIFT-10)
33981 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
33982 + , mm->context.user_cs_base, mm->context.user_cs_limit
33988 unsigned long task_vsize(struct mm_struct *mm)
33989 @@ -203,6 +214,12 @@ static int do_maps_open(struct inode *in
33993 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
33994 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
33995 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
33996 + _mm->pax_flags & MF_PAX_SEGMEXEC))
33999 static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
34001 struct mm_struct *mm = vma->vm_mm;
34002 @@ -210,7 +227,6 @@ static void show_map_vma(struct seq_file
34003 int flags = vma->vm_flags;
34004 unsigned long ino = 0;
34005 unsigned long long pgoff = 0;
34006 - unsigned long start;
34010 @@ -221,20 +237,24 @@ static void show_map_vma(struct seq_file
34011 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
34014 - /* We don't show the stack guard page in /proc/maps */
34015 - start = vma->vm_start;
34016 - if (vma->vm_flags & VM_GROWSDOWN)
34017 - if (!vma_stack_continue(vma->vm_prev, vma->vm_start))
34018 - start += PAGE_SIZE;
34020 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
34022 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
34023 + PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start,
34024 + PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end,
34029 flags & VM_READ ? 'r' : '-',
34030 flags & VM_WRITE ? 'w' : '-',
34031 flags & VM_EXEC ? 'x' : '-',
34032 flags & VM_MAYSHARE ? 's' : 'p',
34033 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
34034 + PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
34038 MAJOR(dev), MINOR(dev), ino, &len);
34041 @@ -243,16 +263,16 @@ static void show_map_vma(struct seq_file
34044 pad_len_spaces(m, len);
34045 - seq_path(m, &file->f_path, "\n");
34046 + seq_path(m, &file->f_path, "\n\\");
34048 const char *name = arch_vma_name(vma);
34051 - if (vma->vm_start <= mm->start_brk &&
34052 - vma->vm_end >= mm->brk) {
34053 + if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
34055 - } else if (vma->vm_start <= mm->start_stack &&
34056 - vma->vm_end >= mm->start_stack) {
34057 + } else if ((vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
34058 + (vma->vm_start <= mm->start_stack &&
34059 + vma->vm_end >= mm->start_stack)) {
34063 @@ -398,11 +418,16 @@ static int show_smap(struct seq_file *m,
34066 memset(&mss, 0, sizeof mss);
34068 - /* mmap_sem is held in m_start */
34069 - if (vma->vm_mm && !is_vm_hugetlb_page(vma))
34070 - walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
34072 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
34073 + if (!PAX_RAND_FLAGS(vma->vm_mm)) {
34076 + /* mmap_sem is held in m_start */
34077 + if (vma->vm_mm && !is_vm_hugetlb_page(vma))
34078 + walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
34079 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
34082 show_map_vma(m, vma);
34085 @@ -418,7 +443,11 @@ static int show_smap(struct seq_file *m,
34087 "KernelPageSize: %8lu kB\n"
34088 "MMUPageSize: %8lu kB\n",
34089 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
34090 + PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
34092 (vma->vm_end - vma->vm_start) >> 10,
34094 mss.resident >> 10,
34095 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
34096 mss.shared_clean >> 10,
34097 diff -urNp linux-2.6.37/fs/proc/task_nommu.c linux-2.6.37/fs/proc/task_nommu.c
34098 --- linux-2.6.37/fs/proc/task_nommu.c 2011-01-04 19:50:19.000000000 -0500
34099 +++ linux-2.6.37/fs/proc/task_nommu.c 2011-01-17 02:41:01.000000000 -0500
34100 @@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct
34102 bytes += kobjsize(mm);
34104 - if (current->fs && current->fs->users > 1)
34105 + if (current->fs && atomic_read(¤t->fs->users) > 1)
34106 sbytes += kobjsize(current->fs);
34108 bytes += kobjsize(current->fs);
34109 @@ -165,7 +165,7 @@ static int nommu_vma_show(struct seq_fil
34112 pad_len_spaces(m, len);
34113 - seq_path(m, &file->f_path, "");
34114 + seq_path(m, &file->f_path, "\n\\");
34116 if (vma->vm_start <= mm->start_stack &&
34117 vma->vm_end >= mm->start_stack) {
34118 diff -urNp linux-2.6.37/fs/readdir.c linux-2.6.37/fs/readdir.c
34119 --- linux-2.6.37/fs/readdir.c 2011-01-04 19:50:19.000000000 -0500
34120 +++ linux-2.6.37/fs/readdir.c 2011-01-17 02:41:01.000000000 -0500
34122 #include <linux/security.h>
34123 #include <linux/syscalls.h>
34124 #include <linux/unistd.h>
34125 +#include <linux/namei.h>
34127 #include <asm/uaccess.h>
34129 @@ -67,6 +68,7 @@ struct old_linux_dirent {
34131 struct readdir_callback {
34132 struct old_linux_dirent __user * dirent;
34133 + struct file * file;
34137 @@ -84,6 +86,10 @@ static int fillonedir(void * __buf, cons
34138 buf->result = -EOVERFLOW;
34142 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
34146 dirent = buf->dirent;
34147 if (!access_ok(VERIFY_WRITE, dirent,
34148 @@ -116,6 +122,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned in
34151 buf.dirent = dirent;
34154 error = vfs_readdir(file, fillonedir, &buf);
34156 @@ -142,6 +149,7 @@ struct linux_dirent {
34157 struct getdents_callback {
34158 struct linux_dirent __user * current_dir;
34159 struct linux_dirent __user * previous;
34160 + struct file * file;
34164 @@ -163,6 +171,10 @@ static int filldir(void * __buf, const c
34165 buf->error = -EOVERFLOW;
34169 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
34172 dirent = buf->previous;
34174 if (__put_user(offset, &dirent->d_off))
34175 @@ -210,6 +222,7 @@ SYSCALL_DEFINE3(getdents, unsigned int,
34176 buf.previous = NULL;
34181 error = vfs_readdir(file, filldir, &buf);
34183 @@ -229,6 +242,7 @@ out:
34184 struct getdents_callback64 {
34185 struct linux_dirent64 __user * current_dir;
34186 struct linux_dirent64 __user * previous;
34187 + struct file *file;
34191 @@ -244,6 +258,10 @@ static int filldir64(void * __buf, const
34192 buf->error = -EINVAL; /* only used if we fail.. */
34193 if (reclen > buf->count)
34196 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
34199 dirent = buf->previous;
34201 if (__put_user(offset, &dirent->d_off))
34202 @@ -291,6 +309,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int
34204 buf.current_dir = dirent;
34205 buf.previous = NULL;
34210 diff -urNp linux-2.6.37/fs/reiserfs/do_balan.c linux-2.6.37/fs/reiserfs/do_balan.c
34211 --- linux-2.6.37/fs/reiserfs/do_balan.c 2011-01-04 19:50:19.000000000 -0500
34212 +++ linux-2.6.37/fs/reiserfs/do_balan.c 2011-01-17 02:41:02.000000000 -0500
34213 @@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb,
34217 - atomic_inc(&(fs_generation(tb->tb_sb)));
34218 + atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
34219 do_balance_starts(tb);
34221 /* balance leaf returns 0 except if combining L R and S into
34222 diff -urNp linux-2.6.37/fs/reiserfs/item_ops.c linux-2.6.37/fs/reiserfs/item_ops.c
34223 --- linux-2.6.37/fs/reiserfs/item_ops.c 2011-01-04 19:50:19.000000000 -0500
34224 +++ linux-2.6.37/fs/reiserfs/item_ops.c 2011-01-17 02:41:02.000000000 -0500
34225 @@ -102,7 +102,7 @@ static void sd_print_vi(struct virtual_i
34226 vi->vi_index, vi->vi_type, vi->vi_ih);
34229 -static struct item_operations stat_data_ops = {
34230 +static const struct item_operations stat_data_ops = {
34231 .bytes_number = sd_bytes_number,
34232 .decrement_key = sd_decrement_key,
34233 .is_left_mergeable = sd_is_left_mergeable,
34234 @@ -196,7 +196,7 @@ static void direct_print_vi(struct virtu
34235 vi->vi_index, vi->vi_type, vi->vi_ih);
34238 -static struct item_operations direct_ops = {
34239 +static const struct item_operations direct_ops = {
34240 .bytes_number = direct_bytes_number,
34241 .decrement_key = direct_decrement_key,
34242 .is_left_mergeable = direct_is_left_mergeable,
34243 @@ -341,7 +341,7 @@ static void indirect_print_vi(struct vir
34244 vi->vi_index, vi->vi_type, vi->vi_ih);
34247 -static struct item_operations indirect_ops = {
34248 +static const struct item_operations indirect_ops = {
34249 .bytes_number = indirect_bytes_number,
34250 .decrement_key = indirect_decrement_key,
34251 .is_left_mergeable = indirect_is_left_mergeable,
34252 @@ -628,7 +628,7 @@ static void direntry_print_vi(struct vir
34256 -static struct item_operations direntry_ops = {
34257 +static const struct item_operations direntry_ops = {
34258 .bytes_number = direntry_bytes_number,
34259 .decrement_key = direntry_decrement_key,
34260 .is_left_mergeable = direntry_is_left_mergeable,
34261 @@ -724,7 +724,7 @@ static void errcatch_print_vi(struct vir
34262 "Invalid item type observed, run fsck ASAP");
34265 -static struct item_operations errcatch_ops = {
34266 +static const struct item_operations errcatch_ops = {
34267 errcatch_bytes_number,
34268 errcatch_decrement_key,
34269 errcatch_is_left_mergeable,
34270 @@ -746,7 +746,7 @@ static struct item_operations errcatch_o
34271 #error Item types must use disk-format assigned values.
34274 -struct item_operations *item_ops[TYPE_ANY + 1] = {
34275 +const struct item_operations * const item_ops[TYPE_ANY + 1] = {
34279 diff -urNp linux-2.6.37/fs/reiserfs/procfs.c linux-2.6.37/fs/reiserfs/procfs.c
34280 --- linux-2.6.37/fs/reiserfs/procfs.c 2011-01-04 19:50:19.000000000 -0500
34281 +++ linux-2.6.37/fs/reiserfs/procfs.c 2011-01-17 02:41:02.000000000 -0500
34282 @@ -113,7 +113,7 @@ static int show_super(struct seq_file *m
34283 "SMALL_TAILS " : "NO_TAILS ",
34284 replay_only(sb) ? "REPLAY_ONLY " : "",
34285 convert_reiserfs(sb) ? "CONV " : "",
34286 - atomic_read(&r->s_generation_counter),
34287 + atomic_read_unchecked(&r->s_generation_counter),
34288 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
34289 SF(s_do_balance), SF(s_unneeded_left_neighbor),
34290 SF(s_good_search_by_key_reada), SF(s_bmaps),
34291 diff -urNp linux-2.6.37/fs/select.c linux-2.6.37/fs/select.c
34292 --- linux-2.6.37/fs/select.c 2011-01-04 19:50:19.000000000 -0500
34293 +++ linux-2.6.37/fs/select.c 2011-01-17 02:41:02.000000000 -0500
34295 #include <linux/module.h>
34296 #include <linux/slab.h>
34297 #include <linux/poll.h>
34298 +#include <linux/security.h>
34299 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
34300 #include <linux/file.h>
34301 #include <linux/fdtable.h>
34302 @@ -838,6 +839,7 @@ int do_sys_poll(struct pollfd __user *uf
34303 struct poll_list *walk = head;
34304 unsigned long todo = nfds;
34306 + gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
34307 if (nfds > rlimit(RLIMIT_NOFILE))
34310 diff -urNp linux-2.6.37/fs/seq_file.c linux-2.6.37/fs/seq_file.c
34311 --- linux-2.6.37/fs/seq_file.c 2011-01-04 19:50:19.000000000 -0500
34312 +++ linux-2.6.37/fs/seq_file.c 2011-01-17 02:41:02.000000000 -0500
34313 @@ -76,7 +76,8 @@ static int traverse(struct seq_file *m,
34317 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
34318 + m->size = PAGE_SIZE;
34319 + m->buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
34323 @@ -116,7 +117,8 @@ static int traverse(struct seq_file *m,
34327 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
34329 + m->buf = kmalloc(m->size, GFP_KERNEL);
34330 return !m->buf ? -ENOMEM : -EAGAIN;
34333 @@ -169,7 +171,8 @@ ssize_t seq_read(struct file *file, char
34334 m->version = file->f_version;
34335 /* grab buffer if we didn't have one */
34337 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
34338 + m->size = PAGE_SIZE;
34339 + m->buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
34343 @@ -210,7 +213,8 @@ ssize_t seq_read(struct file *file, char
34347 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
34349 + m->buf = kmalloc(m->size, GFP_KERNEL);
34353 diff -urNp linux-2.6.37/fs/splice.c linux-2.6.37/fs/splice.c
34354 --- linux-2.6.37/fs/splice.c 2011-01-04 19:50:19.000000000 -0500
34355 +++ linux-2.6.37/fs/splice.c 2011-01-17 02:41:02.000000000 -0500
34356 @@ -186,7 +186,7 @@ ssize_t splice_to_pipe(struct pipe_inode
34360 - if (!pipe->readers) {
34361 + if (!atomic_read(&pipe->readers)) {
34362 send_sig(SIGPIPE, current, 0);
34365 @@ -240,9 +240,9 @@ ssize_t splice_to_pipe(struct pipe_inode
34369 - pipe->waiting_writers++;
34370 + atomic_inc(&pipe->waiting_writers);
34372 - pipe->waiting_writers--;
34373 + atomic_dec(&pipe->waiting_writers);
34377 @@ -556,7 +556,7 @@ static ssize_t kernel_readv(struct file
34380 /* The cast to a user pointer is valid due to the set_fs() */
34381 - res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
34382 + res = vfs_readv(file, (__force const struct iovec __user *)vec, vlen, &pos);
34386 @@ -571,7 +571,7 @@ static ssize_t kernel_write(struct file
34389 /* The cast to a user pointer is valid due to the set_fs() */
34390 - res = vfs_write(file, (const char __user *)buf, count, &pos);
34391 + res = vfs_write(file, (__force const char __user *)buf, count, &pos);
34395 @@ -622,7 +622,7 @@ ssize_t default_file_splice_read(struct
34398 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
34399 - vec[i].iov_base = (void __user *) page_address(page);
34400 + vec[i].iov_base = (__force void __user *) page_address(page);
34401 vec[i].iov_len = this_len;
34402 spd.pages[i] = page;
34404 @@ -849,10 +849,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
34405 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
34407 while (!pipe->nrbufs) {
34408 - if (!pipe->writers)
34409 + if (!atomic_read(&pipe->writers))
34412 - if (!pipe->waiting_writers && sd->num_spliced)
34413 + if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
34416 if (sd->flags & SPLICE_F_NONBLOCK)
34417 @@ -1189,7 +1189,7 @@ ssize_t splice_direct_to_actor(struct fi
34418 * out of the pipe right after the splice_to_pipe(). So set
34419 * PIPE_READERS appropriately.
34421 - pipe->readers = 1;
34422 + atomic_set(&pipe->readers, 1);
34424 current->splice_pipe = pipe;
34426 @@ -1745,9 +1745,9 @@ static int ipipe_prep(struct pipe_inode_
34427 ret = -ERESTARTSYS;
34430 - if (!pipe->writers)
34431 + if (!atomic_read(&pipe->writers))
34433 - if (!pipe->waiting_writers) {
34434 + if (!atomic_read(&pipe->waiting_writers)) {
34435 if (flags & SPLICE_F_NONBLOCK) {
34438 @@ -1779,7 +1779,7 @@ static int opipe_prep(struct pipe_inode_
34441 while (pipe->nrbufs >= pipe->buffers) {
34442 - if (!pipe->readers) {
34443 + if (!atomic_read(&pipe->readers)) {
34444 send_sig(SIGPIPE, current, 0);
34447 @@ -1792,9 +1792,9 @@ static int opipe_prep(struct pipe_inode_
34448 ret = -ERESTARTSYS;
34451 - pipe->waiting_writers++;
34452 + atomic_inc(&pipe->waiting_writers);
34454 - pipe->waiting_writers--;
34455 + atomic_dec(&pipe->waiting_writers);
34459 @@ -1830,14 +1830,14 @@ retry:
34460 pipe_double_lock(ipipe, opipe);
34463 - if (!opipe->readers) {
34464 + if (!atomic_read(&opipe->readers)) {
34465 send_sig(SIGPIPE, current, 0);
34471 - if (!ipipe->nrbufs && !ipipe->writers)
34472 + if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
34476 @@ -1937,7 +1937,7 @@ static int link_pipe(struct pipe_inode_i
34477 pipe_double_lock(ipipe, opipe);
34480 - if (!opipe->readers) {
34481 + if (!atomic_read(&opipe->readers)) {
34482 send_sig(SIGPIPE, current, 0);
34485 @@ -1982,7 +1982,7 @@ static int link_pipe(struct pipe_inode_i
34486 * return EAGAIN if we have the potential of some data in the
34487 * future, otherwise just return 0
34489 - if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
34490 + if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
34493 pipe_unlock(ipipe);
34494 diff -urNp linux-2.6.37/fs/sysfs/symlink.c linux-2.6.37/fs/sysfs/symlink.c
34495 --- linux-2.6.37/fs/sysfs/symlink.c 2011-01-04 19:50:19.000000000 -0500
34496 +++ linux-2.6.37/fs/sysfs/symlink.c 2011-01-17 02:41:02.000000000 -0500
34497 @@ -286,7 +286,7 @@ static void *sysfs_follow_link(struct de
34499 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
34501 - char *page = nd_get_link(nd);
34502 + const char *page = nd_get_link(nd);
34504 free_page((unsigned long)page);
34506 diff -urNp linux-2.6.37/fs/udf/misc.c linux-2.6.37/fs/udf/misc.c
34507 --- linux-2.6.37/fs/udf/misc.c 2011-01-04 19:50:19.000000000 -0500
34508 +++ linux-2.6.37/fs/udf/misc.c 2011-01-17 02:41:02.000000000 -0500
34509 @@ -142,8 +142,8 @@ struct genericFormat *udf_add_extendedat
34510 iinfo->i_lenEAttr += size;
34511 return (struct genericFormat *)&ea[offset];
34515 + if (loc & 0x02) {
34520 @@ -286,7 +286,7 @@ void udf_new_tag(char *data, uint16_t id
34522 u8 udf_tag_checksum(const struct tag *t)
34524 - u8 *data = (u8 *)t;
34525 + const u8 *data = (const u8 *)t;
34528 for (i = 0; i < sizeof(struct tag); ++i)
34529 diff -urNp linux-2.6.37/fs/udf/udfdecl.h linux-2.6.37/fs/udf/udfdecl.h
34530 --- linux-2.6.37/fs/udf/udfdecl.h 2011-01-04 19:50:19.000000000 -0500
34531 +++ linux-2.6.37/fs/udf/udfdecl.h 2011-01-17 02:41:02.000000000 -0500
34532 @@ -26,7 +26,7 @@ do { \
34536 -#define udf_debug(f, a...) /**/
34537 +#define udf_debug(f, a...) do {} while (0)
34540 #define udf_info(f, a...) \
34541 diff -urNp linux-2.6.37/fs/utimes.c linux-2.6.37/fs/utimes.c
34542 --- linux-2.6.37/fs/utimes.c 2011-01-04 19:50:19.000000000 -0500
34543 +++ linux-2.6.37/fs/utimes.c 2011-01-17 02:41:02.000000000 -0500
34545 #include <linux/compiler.h>
34546 #include <linux/file.h>
34547 #include <linux/fs.h>
34548 +#include <linux/security.h>
34549 #include <linux/linkage.h>
34550 #include <linux/mount.h>
34551 #include <linux/namei.h>
34552 @@ -101,6 +102,12 @@ static int utimes_common(struct path *pa
34553 goto mnt_drop_write_and_out;
34557 + if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
34559 + goto mnt_drop_write_and_out;
34562 mutex_lock(&inode->i_mutex);
34563 error = notify_change(path->dentry, &newattrs);
34564 mutex_unlock(&inode->i_mutex);
34565 diff -urNp linux-2.6.37/fs/xattr_acl.c linux-2.6.37/fs/xattr_acl.c
34566 --- linux-2.6.37/fs/xattr_acl.c 2011-01-04 19:50:19.000000000 -0500
34567 +++ linux-2.6.37/fs/xattr_acl.c 2011-01-17 02:41:02.000000000 -0500
34570 posix_acl_from_xattr(const void *value, size_t size)
34572 - posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
34573 - posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
34574 + const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
34575 + const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
34577 struct posix_acl *acl;
34578 struct posix_acl_entry *acl_e;
34579 diff -urNp linux-2.6.37/fs/xattr.c linux-2.6.37/fs/xattr.c
34580 --- linux-2.6.37/fs/xattr.c 2011-01-04 19:50:19.000000000 -0500
34581 +++ linux-2.6.37/fs/xattr.c 2011-01-17 02:41:02.000000000 -0500
34582 @@ -247,7 +247,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
34583 * Extended attribute SET operations
34586 -setxattr(struct dentry *d, const char __user *name, const void __user *value,
34587 +setxattr(struct path *path, const char __user *name, const void __user *value,
34588 size_t size, int flags)
34591 @@ -271,7 +271,13 @@ setxattr(struct dentry *d, const char __
34592 return PTR_ERR(kvalue);
34595 - error = vfs_setxattr(d, kname, kvalue, size, flags);
34596 + if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
34601 + error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
34606 @@ -288,7 +294,7 @@ SYSCALL_DEFINE5(setxattr, const char __u
34608 error = mnt_want_write(path.mnt);
34610 - error = setxattr(path.dentry, name, value, size, flags);
34611 + error = setxattr(&path, name, value, size, flags);
34612 mnt_drop_write(path.mnt);
34615 @@ -307,7 +313,7 @@ SYSCALL_DEFINE5(lsetxattr, const char __
34617 error = mnt_want_write(path.mnt);
34619 - error = setxattr(path.dentry, name, value, size, flags);
34620 + error = setxattr(&path, name, value, size, flags);
34621 mnt_drop_write(path.mnt);
34624 @@ -318,17 +324,15 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, cons
34625 const void __user *,value, size_t, size, int, flags)
34628 - struct dentry *dentry;
34629 int error = -EBADF;
34634 - dentry = f->f_path.dentry;
34635 - audit_inode(NULL, dentry);
34636 + audit_inode(NULL, f->f_path.dentry);
34637 error = mnt_want_write_file(f);
34639 - error = setxattr(dentry, name, value, size, flags);
34640 + error = setxattr(&f->f_path, name, value, size, flags);
34641 mnt_drop_write(f->f_path.mnt);
34644 diff -urNp linux-2.6.37/fs/xfs/linux-2.6/xfs_ioctl.c linux-2.6.37/fs/xfs/linux-2.6/xfs_ioctl.c
34645 --- linux-2.6.37/fs/xfs/linux-2.6/xfs_ioctl.c 2011-01-04 19:50:19.000000000 -0500
34646 +++ linux-2.6.37/fs/xfs/linux-2.6/xfs_ioctl.c 2011-01-17 02:41:02.000000000 -0500
34647 @@ -127,7 +127,7 @@ xfs_find_handle(
34651 - if (copy_to_user(hreq->ohandle, &handle, hsize) ||
34652 + if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
34653 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
34656 diff -urNp linux-2.6.37/fs/xfs/linux-2.6/xfs_iops.c linux-2.6.37/fs/xfs/linux-2.6/xfs_iops.c
34657 --- linux-2.6.37/fs/xfs/linux-2.6/xfs_iops.c 2011-01-04 19:50:19.000000000 -0500
34658 +++ linux-2.6.37/fs/xfs/linux-2.6/xfs_iops.c 2011-01-17 02:41:02.000000000 -0500
34659 @@ -437,7 +437,7 @@ xfs_vn_put_link(
34660 struct nameidata *nd,
34663 - char *s = nd_get_link(nd);
34664 + const char *s = nd_get_link(nd);
34668 diff -urNp linux-2.6.37/fs/xfs/xfs_bmap.c linux-2.6.37/fs/xfs/xfs_bmap.c
34669 --- linux-2.6.37/fs/xfs/xfs_bmap.c 2011-01-04 19:50:19.000000000 -0500
34670 +++ linux-2.6.37/fs/xfs/xfs_bmap.c 2011-01-17 02:41:02.000000000 -0500
34671 @@ -287,7 +287,7 @@ xfs_bmap_validate_ret(
34675 -#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
34676 +#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
34680 diff -urNp linux-2.6.37/grsecurity/gracl_alloc.c linux-2.6.37/grsecurity/gracl_alloc.c
34681 --- linux-2.6.37/grsecurity/gracl_alloc.c 1969-12-31 19:00:00.000000000 -0500
34682 +++ linux-2.6.37/grsecurity/gracl_alloc.c 2011-01-17 02:41:02.000000000 -0500
34684 +#include <linux/kernel.h>
34685 +#include <linux/mm.h>
34686 +#include <linux/slab.h>
34687 +#include <linux/vmalloc.h>
34688 +#include <linux/gracl.h>
34689 +#include <linux/grsecurity.h>
34691 +static unsigned long alloc_stack_next = 1;
34692 +static unsigned long alloc_stack_size = 1;
34693 +static void **alloc_stack;
34695 +static __inline__ int
34698 + if (alloc_stack_next == 1)
34701 + kfree(alloc_stack[alloc_stack_next - 2]);
34703 + alloc_stack_next--;
34708 +static __inline__ int
34709 +alloc_push(void *buf)
34711 + if (alloc_stack_next >= alloc_stack_size)
34714 + alloc_stack[alloc_stack_next - 1] = buf;
34716 + alloc_stack_next++;
34722 +acl_alloc(unsigned long len)
34724 + void *ret = NULL;
34726 + if (!len || len > PAGE_SIZE)
34729 + ret = kmalloc(len, GFP_KERNEL);
34732 + if (alloc_push(ret)) {
34743 +acl_alloc_num(unsigned long num, unsigned long len)
34745 + if (!len || (num > (PAGE_SIZE / len)))
34748 + return acl_alloc(num * len);
34752 +acl_free_all(void)
34754 + if (gr_acl_is_enabled() || !alloc_stack)
34757 + while (alloc_pop()) ;
34759 + if (alloc_stack) {
34760 + if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
34761 + kfree(alloc_stack);
34763 + vfree(alloc_stack);
34766 + alloc_stack = NULL;
34767 + alloc_stack_size = 1;
34768 + alloc_stack_next = 1;
34774 +acl_alloc_stack_init(unsigned long size)
34776 + if ((size * sizeof (void *)) <= PAGE_SIZE)
34778 + (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
34780 + alloc_stack = (void **) vmalloc(size * sizeof (void *));
34782 + alloc_stack_size = size;
34784 + if (!alloc_stack)
34789 diff -urNp linux-2.6.37/grsecurity/gracl.c linux-2.6.37/grsecurity/gracl.c
34790 --- linux-2.6.37/grsecurity/gracl.c 1969-12-31 19:00:00.000000000 -0500
34791 +++ linux-2.6.37/grsecurity/gracl.c 2011-01-17 20:20:28.000000000 -0500
34793 +#include <linux/kernel.h>
34794 +#include <linux/module.h>
34795 +#include <linux/sched.h>
34796 +#include <linux/mm.h>
34797 +#include <linux/file.h>
34798 +#include <linux/fs.h>
34799 +#include <linux/namei.h>
34800 +#include <linux/mount.h>
34801 +#include <linux/tty.h>
34802 +#include <linux/proc_fs.h>
34803 +#include <linux/smp_lock.h>
34804 +#include <linux/lglock.h>
34805 +#include <linux/slab.h>
34806 +#include <linux/vmalloc.h>
34807 +#include <linux/types.h>
34808 +#include <linux/sysctl.h>
34809 +#include <linux/netdevice.h>
34810 +#include <linux/ptrace.h>
34811 +#include <linux/gracl.h>
34812 +#include <linux/gralloc.h>
34813 +#include <linux/grsecurity.h>
34814 +#include <linux/grinternal.h>
34815 +#include <linux/pid_namespace.h>
34816 +#include <linux/fdtable.h>
34817 +#include <linux/percpu.h>
34819 +#include <asm/uaccess.h>
34820 +#include <asm/errno.h>
34821 +#include <asm/mman.h>
34823 +static struct acl_role_db acl_role_set;
34824 +static struct name_db name_set;
34825 +static struct inodev_db inodev_set;
34827 +/* for keeping track of userspace pointers used for subjects, so we
34828 + can share references in the kernel as well
34831 +static struct path real_root;
34833 +static struct acl_subj_map_db subj_map_set;
34835 +static struct acl_role_label *default_role;
34837 +static struct acl_role_label *role_list;
34839 +static u16 acl_sp_role_value;
34841 +extern char *gr_shared_page[4];
34842 +static DEFINE_MUTEX(gr_dev_mutex);
34843 +DEFINE_RWLOCK(gr_inode_lock);
34845 +struct gr_arg *gr_usermode;
34847 +static unsigned int gr_status __read_only = GR_STATUS_INIT;
34849 +extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
34850 +extern void gr_clear_learn_entries(void);
34852 +#ifdef CONFIG_GRKERNSEC_RESLOG
34853 +extern void gr_log_resource(const struct task_struct *task,
34854 + const int res, const unsigned long wanted, const int gt);
34857 +unsigned char *gr_system_salt;
34858 +unsigned char *gr_system_sum;
34860 +static struct sprole_pw **acl_special_roles = NULL;
34861 +static __u16 num_sprole_pws = 0;
34863 +static struct acl_role_label *kernel_role = NULL;
34865 +static unsigned int gr_auth_attempts = 0;
34866 +static unsigned long gr_auth_expires = 0UL;
34868 +extern struct vfsmount *sock_mnt;
34869 +extern struct vfsmount *pipe_mnt;
34870 +extern struct vfsmount *shm_mnt;
34871 +#ifdef CONFIG_HUGETLBFS
34872 +extern struct vfsmount *hugetlbfs_vfsmount;
34875 +static struct acl_object_label *fakefs_obj;
34877 +extern int gr_init_uidset(void);
34878 +extern void gr_free_uidset(void);
34879 +extern void gr_remove_uid(uid_t uid);
34880 +extern int gr_find_uid(uid_t uid);
34882 +DECLARE_BRLOCK(vfsmount_lock);
34885 +gr_acl_is_enabled(void)
34887 + return (gr_status & GR_READY);
34890 +static char gr_task_roletype_to_char(struct task_struct *task)
34892 + switch (task->role->roletype &
34893 + (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
34894 + GR_ROLE_SPECIAL)) {
34895 + case GR_ROLE_DEFAULT:
34897 + case GR_ROLE_USER:
34899 + case GR_ROLE_GROUP:
34901 + case GR_ROLE_SPECIAL:
34908 +char gr_roletype_to_char(void)
34910 + return gr_task_roletype_to_char(current);
34914 +gr_acl_tpe_check(void)
34916 + if (unlikely(!(gr_status & GR_READY)))
34918 + if (current->role->roletype & GR_ROLE_TPE)
34925 +gr_handle_rawio(const struct inode *inode)
34927 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
34928 + if (inode && S_ISBLK(inode->i_mode) &&
34929 + grsec_enable_chroot_caps && proc_is_chrooted(current) &&
34930 + !capable(CAP_SYS_RAWIO))
34937 +gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
34939 + if (likely(lena != lenb))
34942 + return !memcmp(a, b, lena);
34945 +static int prepend(char **buffer, int *buflen, const char *str, int namelen)
34947 + *buflen -= namelen;
34949 + return -ENAMETOOLONG;
34950 + *buffer -= namelen;
34951 + memcpy(*buffer, str, namelen);
34955 +static int prepend_name(char **buffer, int *buflen, struct qstr *name)
34957 + return prepend(buffer, buflen, name->name, name->len);
34960 +static int prepend_path(const struct path *path, struct path *root,
34961 + char **buffer, int *buflen)
34963 + struct dentry *dentry = path->dentry;
34964 + struct vfsmount *vfsmnt = path->mnt;
34965 + bool slash = false;
34968 + while (dentry != root->dentry || vfsmnt != root->mnt) {
34969 + struct dentry * parent;
34971 + if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
34972 + /* Global root? */
34973 + if (vfsmnt->mnt_parent == vfsmnt) {
34976 + dentry = vfsmnt->mnt_mountpoint;
34977 + vfsmnt = vfsmnt->mnt_parent;
34980 + parent = dentry->d_parent;
34981 + prefetch(parent);
34982 + error = prepend_name(buffer, buflen, &dentry->d_name);
34984 + error = prepend(buffer, buflen, "/", 1);
34993 + if (!error && !slash)
34994 + error = prepend(buffer, buflen, "/", 1);
34999 +/* this must be called with vfsmount_lock and dcache_lock held */
35001 +static char *__our_d_path(const struct path *path, struct path *root,
35002 + char *buf, int buflen)
35004 + char *res = buf + buflen;
35007 + prepend(&res, &buflen, "\0", 1);
35008 + error = prepend_path(path, root, &res, &buflen);
35010 + return ERR_PTR(error);
35016 +gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
35020 + retval = __our_d_path(path, root, buf, buflen);
35021 + if (unlikely(IS_ERR(retval)))
35022 + retval = strcpy(buf, "<path too long>");
35023 + else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
35024 + retval[1] = '\0';
35030 +__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
35031 + char *buf, int buflen)
35033 + struct path path;
35036 + path.dentry = (struct dentry *)dentry;
35037 + path.mnt = (struct vfsmount *)vfsmnt;
35039 + /* we can use real_root.dentry, real_root.mnt, because this is only called
35040 + by the RBAC system */
35041 + res = gen_full_path(&path, &real_root, buf, buflen);
35047 +d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
35048 + char *buf, int buflen)
35051 + struct path path;
35052 + struct path root;
35053 + struct task_struct *reaper = &init_task;
35055 + path.dentry = (struct dentry *)dentry;
35056 + path.mnt = (struct vfsmount *)vfsmnt;
35058 + /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
35059 + get_fs_root(reaper->fs, &root);
35061 + spin_lock(&dcache_lock);
35062 + br_read_lock(vfsmount_lock);
35063 + res = gen_full_path(&path, &root, buf, buflen);
35064 + br_read_unlock(vfsmount_lock);
35065 + spin_unlock(&dcache_lock);
35072 +gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
35075 + spin_lock(&dcache_lock);
35076 + br_read_lock(vfsmount_lock);
35077 + ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
35079 + br_read_unlock(vfsmount_lock);
35080 + spin_unlock(&dcache_lock);
35085 +gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
35087 + return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
35092 +gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
35094 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
35099 +gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
35101 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
35106 +gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
35108 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
35113 +gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
35115 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
35120 +to_gr_audit(const __u32 reqmode)
35122 + /* masks off auditable permission flags, then shifts them to create
35123 + auditing flags, and adds the special case of append auditing if
35124 + we're requesting write */
35125 + return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
35128 +struct acl_subject_label *
35129 +lookup_subject_map(const struct acl_subject_label *userp)
35131 + unsigned int index = shash(userp, subj_map_set.s_size);
35132 + struct subject_map *match;
35134 + match = subj_map_set.s_hash[index];
35136 + while (match && match->user != userp)
35137 + match = match->next;
35139 + if (match != NULL)
35140 + return match->kernel;
35146 +insert_subj_map_entry(struct subject_map *subjmap)
35148 + unsigned int index = shash(subjmap->user, subj_map_set.s_size);
35149 + struct subject_map **curr;
35151 + subjmap->prev = NULL;
35153 + curr = &subj_map_set.s_hash[index];
35154 + if (*curr != NULL)
35155 + (*curr)->prev = subjmap;
35157 + subjmap->next = *curr;
35163 +static struct acl_role_label *
35164 +lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
35167 + unsigned int index = rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
35168 + struct acl_role_label *match;
35169 + struct role_allowed_ip *ipp;
35171 + u32 curr_ip = task->signal->curr_ip;
35173 + task->signal->saved_ip = curr_ip;
35175 + match = acl_role_set.r_hash[index];
35178 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
35179 + for (x = 0; x < match->domain_child_num; x++) {
35180 + if (match->domain_children[x] == uid)
35183 + } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
35185 + match = match->next;
35188 + if (match == NULL) {
35190 + index = rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
35191 + match = acl_role_set.r_hash[index];
35194 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
35195 + for (x = 0; x < match->domain_child_num; x++) {
35196 + if (match->domain_children[x] == gid)
35199 + } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
35201 + match = match->next;
35204 + if (match == NULL)
35205 + match = default_role;
35206 + if (match->allowed_ips == NULL)
35209 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
35211 + ((ntohl(curr_ip) & ipp->netmask) ==
35212 + (ntohl(ipp->addr) & ipp->netmask)))
35215 + match = default_role;
35217 + } else if (match->allowed_ips == NULL) {
35220 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
35222 + ((ntohl(curr_ip) & ipp->netmask) ==
35223 + (ntohl(ipp->addr) & ipp->netmask)))
35232 +struct acl_subject_label *
35233 +lookup_acl_subj_label(const ino_t ino, const dev_t dev,
35234 + const struct acl_role_label *role)
35236 + unsigned int index = fhash(ino, dev, role->subj_hash_size);
35237 + struct acl_subject_label *match;
35239 + match = role->subj_hash[index];
35241 + while (match && (match->inode != ino || match->device != dev ||
35242 + (match->mode & GR_DELETED))) {
35243 + match = match->next;
35246 + if (match && !(match->mode & GR_DELETED))
35252 +struct acl_subject_label *
35253 +lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
35254 + const struct acl_role_label *role)
35256 + unsigned int index = fhash(ino, dev, role->subj_hash_size);
35257 + struct acl_subject_label *match;
35259 + match = role->subj_hash[index];
35261 + while (match && (match->inode != ino || match->device != dev ||
35262 + !(match->mode & GR_DELETED))) {
35263 + match = match->next;
35266 + if (match && (match->mode & GR_DELETED))
35272 +static struct acl_object_label *
35273 +lookup_acl_obj_label(const ino_t ino, const dev_t dev,
35274 + const struct acl_subject_label *subj)
35276 + unsigned int index = fhash(ino, dev, subj->obj_hash_size);
35277 + struct acl_object_label *match;
35279 + match = subj->obj_hash[index];
35281 + while (match && (match->inode != ino || match->device != dev ||
35282 + (match->mode & GR_DELETED))) {
35283 + match = match->next;
35286 + if (match && !(match->mode & GR_DELETED))
35292 +static struct acl_object_label *
35293 +lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
35294 + const struct acl_subject_label *subj)
35296 + unsigned int index = fhash(ino, dev, subj->obj_hash_size);
35297 + struct acl_object_label *match;
35299 + match = subj->obj_hash[index];
35301 + while (match && (match->inode != ino || match->device != dev ||
35302 + !(match->mode & GR_DELETED))) {
35303 + match = match->next;
35306 + if (match && (match->mode & GR_DELETED))
35309 + match = subj->obj_hash[index];
35311 + while (match && (match->inode != ino || match->device != dev ||
35312 + (match->mode & GR_DELETED))) {
35313 + match = match->next;
35316 + if (match && !(match->mode & GR_DELETED))
35322 +static struct name_entry *
35323 +lookup_name_entry(const char *name)
35325 + unsigned int len = strlen(name);
35326 + unsigned int key = full_name_hash(name, len);
35327 + unsigned int index = key % name_set.n_size;
35328 + struct name_entry *match;
35330 + match = name_set.n_hash[index];
35332 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
35333 + match = match->next;
35338 +static struct name_entry *
35339 +lookup_name_entry_create(const char *name)
35341 + unsigned int len = strlen(name);
35342 + unsigned int key = full_name_hash(name, len);
35343 + unsigned int index = key % name_set.n_size;
35344 + struct name_entry *match;
35346 + match = name_set.n_hash[index];
35348 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
35349 + !match->deleted))
35350 + match = match->next;
35352 + if (match && match->deleted)
35355 + match = name_set.n_hash[index];
35357 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
35359 + match = match->next;
35361 + if (match && !match->deleted)
35367 +static struct inodev_entry *
35368 +lookup_inodev_entry(const ino_t ino, const dev_t dev)
35370 + unsigned int index = fhash(ino, dev, inodev_set.i_size);
35371 + struct inodev_entry *match;
35373 + match = inodev_set.i_hash[index];
35375 + while (match && (match->nentry->inode != ino || match->nentry->device != dev))
35376 + match = match->next;
35382 +insert_inodev_entry(struct inodev_entry *entry)
35384 + unsigned int index = fhash(entry->nentry->inode, entry->nentry->device,
35385 + inodev_set.i_size);
35386 + struct inodev_entry **curr;
35388 + entry->prev = NULL;
35390 + curr = &inodev_set.i_hash[index];
35391 + if (*curr != NULL)
35392 + (*curr)->prev = entry;
35394 + entry->next = *curr;
35401 +__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
35403 + unsigned int index =
35404 + rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
35405 + struct acl_role_label **curr;
35406 + struct acl_role_label *tmp;
35408 + curr = &acl_role_set.r_hash[index];
35410 + /* if role was already inserted due to domains and already has
35411 + a role in the same bucket as it attached, then we need to
35412 + combine these two buckets
35414 + if (role->next) {
35415 + tmp = role->next;
35416 + while (tmp->next)
35418 + tmp->next = *curr;
35420 + role->next = *curr;
35427 +insert_acl_role_label(struct acl_role_label *role)
35431 + if (role_list == NULL) {
35432 + role_list = role;
35433 + role->prev = NULL;
35435 + role->prev = role_list;
35436 + role_list = role;
35439 + /* used for hash chains */
35440 + role->next = NULL;
35442 + if (role->roletype & GR_ROLE_DOMAIN) {
35443 + for (i = 0; i < role->domain_child_num; i++)
35444 + __insert_acl_role_label(role, role->domain_children[i]);
35446 + __insert_acl_role_label(role, role->uidgid);
35450 +insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
35452 + struct name_entry **curr, *nentry;
35453 + struct inodev_entry *ientry;
35454 + unsigned int len = strlen(name);
35455 + unsigned int key = full_name_hash(name, len);
35456 + unsigned int index = key % name_set.n_size;
35458 + curr = &name_set.n_hash[index];
35460 + while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
35461 + curr = &((*curr)->next);
35463 + if (*curr != NULL)
35466 + nentry = acl_alloc(sizeof (struct name_entry));
35467 + if (nentry == NULL)
35469 + ientry = acl_alloc(sizeof (struct inodev_entry));
35470 + if (ientry == NULL)
35472 + ientry->nentry = nentry;
35474 + nentry->key = key;
35475 + nentry->name = name;
35476 + nentry->inode = inode;
35477 + nentry->device = device;
35478 + nentry->len = len;
35479 + nentry->deleted = deleted;
35481 + nentry->prev = NULL;
35482 + curr = &name_set.n_hash[index];
35483 + if (*curr != NULL)
35484 + (*curr)->prev = nentry;
35485 + nentry->next = *curr;
35488 + /* insert us into the table searchable by inode/dev */
35489 + insert_inodev_entry(ientry);
35495 +insert_acl_obj_label(struct acl_object_label *obj,
35496 + struct acl_subject_label *subj)
35498 + unsigned int index =
35499 + fhash(obj->inode, obj->device, subj->obj_hash_size);
35500 + struct acl_object_label **curr;
35503 + obj->prev = NULL;
35505 + curr = &subj->obj_hash[index];
35506 + if (*curr != NULL)
35507 + (*curr)->prev = obj;
35509 + obj->next = *curr;
35516 +insert_acl_subj_label(struct acl_subject_label *obj,
35517 + struct acl_role_label *role)
35519 + unsigned int index = fhash(obj->inode, obj->device, role->subj_hash_size);
35520 + struct acl_subject_label **curr;
35522 + obj->prev = NULL;
35524 + curr = &role->subj_hash[index];
35525 + if (*curr != NULL)
35526 + (*curr)->prev = obj;
35528 + obj->next = *curr;
35534 +/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
35537 +create_table(__u32 * len, int elementsize)
35539 + unsigned int table_sizes[] = {
35540 + 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
35541 + 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
35542 + 4194301, 8388593, 16777213, 33554393, 67108859
35544 + void *newtable = NULL;
35545 + unsigned int pwr = 0;
35547 + while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
35548 + table_sizes[pwr] <= *len)
35551 + if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
35554 + if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
35556 + kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
35558 + newtable = vmalloc(table_sizes[pwr] * elementsize);
35560 + *len = table_sizes[pwr];
35566 +init_variables(const struct gr_arg *arg)
35568 + struct task_struct *reaper = &init_task;
35569 + unsigned int stacksize;
35571 + subj_map_set.s_size = arg->role_db.num_subjects;
35572 + acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
35573 + name_set.n_size = arg->role_db.num_objects;
35574 + inodev_set.i_size = arg->role_db.num_objects;
35576 + if (!subj_map_set.s_size || !acl_role_set.r_size ||
35577 + !name_set.n_size || !inodev_set.i_size)
35580 + if (!gr_init_uidset())
35583 + /* set up the stack that holds allocation info */
35585 + stacksize = arg->role_db.num_pointers + 5;
35587 + if (!acl_alloc_stack_init(stacksize))
35590 + /* grab reference for the real root dentry and vfsmount */
35591 + get_fs_root(reaper->fs, &real_root);
35593 + fakefs_obj = acl_alloc(sizeof(struct acl_object_label));
35594 + if (fakefs_obj == NULL)
35596 + fakefs_obj->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
35598 + subj_map_set.s_hash =
35599 + (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
35600 + acl_role_set.r_hash =
35601 + (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
35602 + name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
35603 + inodev_set.i_hash =
35604 + (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
35606 + if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
35607 + !name_set.n_hash || !inodev_set.i_hash)
35610 + memset(subj_map_set.s_hash, 0,
35611 + sizeof(struct subject_map *) * subj_map_set.s_size);
35612 + memset(acl_role_set.r_hash, 0,
35613 + sizeof (struct acl_role_label *) * acl_role_set.r_size);
35614 + memset(name_set.n_hash, 0,
35615 + sizeof (struct name_entry *) * name_set.n_size);
35616 + memset(inodev_set.i_hash, 0,
35617 + sizeof (struct inodev_entry *) * inodev_set.i_size);
35622 +/* free information not needed after startup
35623 + currently contains user->kernel pointer mappings for subjects
35627 +free_init_variables(void)
35631 + if (subj_map_set.s_hash) {
35632 + for (i = 0; i < subj_map_set.s_size; i++) {
35633 + if (subj_map_set.s_hash[i]) {
35634 + kfree(subj_map_set.s_hash[i]);
35635 + subj_map_set.s_hash[i] = NULL;
35639 + if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
35641 + kfree(subj_map_set.s_hash);
35643 + vfree(subj_map_set.s_hash);
35650 +free_variables(void)
35652 + struct acl_subject_label *s;
35653 + struct acl_role_label *r;
35654 + struct task_struct *task, *task2;
35657 + gr_clear_learn_entries();
35659 + read_lock(&tasklist_lock);
35660 + do_each_thread(task2, task) {
35661 + task->acl_sp_role = 0;
35662 + task->acl_role_id = 0;
35663 + task->acl = NULL;
35664 + task->role = NULL;
35665 + } while_each_thread(task2, task);
35666 + read_unlock(&tasklist_lock);
35668 + /* release the reference to the real root dentry and vfsmount */
35669 + path_put(&real_root);
35671 + /* free all object hash tables */
35673 + FOR_EACH_ROLE_START(r)
35674 + if (r->subj_hash == NULL)
35676 + FOR_EACH_SUBJECT_START(r, s, x)
35677 + if (s->obj_hash == NULL)
35679 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
35680 + kfree(s->obj_hash);
35682 + vfree(s->obj_hash);
35683 + FOR_EACH_SUBJECT_END(s, x)
35684 + FOR_EACH_NESTED_SUBJECT_START(r, s)
35685 + if (s->obj_hash == NULL)
35687 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
35688 + kfree(s->obj_hash);
35690 + vfree(s->obj_hash);
35691 + FOR_EACH_NESTED_SUBJECT_END(s)
35692 + if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
35693 + kfree(r->subj_hash);
35695 + vfree(r->subj_hash);
35696 + r->subj_hash = NULL;
35698 + FOR_EACH_ROLE_END(r)
35702 + if (acl_role_set.r_hash) {
35703 + if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
35705 + kfree(acl_role_set.r_hash);
35707 + vfree(acl_role_set.r_hash);
35709 + if (name_set.n_hash) {
35710 + if ((name_set.n_size * sizeof (struct name_entry *)) <=
35712 + kfree(name_set.n_hash);
35714 + vfree(name_set.n_hash);
35717 + if (inodev_set.i_hash) {
35718 + if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
35720 + kfree(inodev_set.i_hash);
35722 + vfree(inodev_set.i_hash);
35725 + gr_free_uidset();
35727 + memset(&name_set, 0, sizeof (struct name_db));
35728 + memset(&inodev_set, 0, sizeof (struct inodev_db));
35729 + memset(&acl_role_set, 0, sizeof (struct acl_role_db));
35730 + memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
35732 + default_role = NULL;
35733 + role_list = NULL;
35739 +count_user_objs(struct acl_object_label *userp)
35741 + struct acl_object_label o_tmp;
35745 + if (copy_from_user(&o_tmp, userp,
35746 + sizeof (struct acl_object_label)))
35749 + userp = o_tmp.prev;
35756 +static struct acl_subject_label *
35757 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role);
35760 +copy_user_glob(struct acl_object_label *obj)
35762 + struct acl_object_label *g_tmp, **guser;
35763 + unsigned int len;
35766 + if (obj->globbed == NULL)
35769 + guser = &obj->globbed;
35771 + g_tmp = (struct acl_object_label *)
35772 + acl_alloc(sizeof (struct acl_object_label));
35773 + if (g_tmp == NULL)
35776 + if (copy_from_user(g_tmp, *guser,
35777 + sizeof (struct acl_object_label)))
35780 + len = strnlen_user(g_tmp->filename, PATH_MAX);
35782 + if (!len || len >= PATH_MAX)
35785 + if ((tmp = (char *) acl_alloc(len)) == NULL)
35788 + if (copy_from_user(tmp, g_tmp->filename, len))
35790 + tmp[len-1] = '\0';
35791 + g_tmp->filename = tmp;
35794 + guser = &(g_tmp->next);
35801 +copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
35802 + struct acl_role_label *role)
35804 + struct acl_object_label *o_tmp;
35805 + unsigned int len;
35810 + if ((o_tmp = (struct acl_object_label *)
35811 + acl_alloc(sizeof (struct acl_object_label))) == NULL)
35814 + if (copy_from_user(o_tmp, userp,
35815 + sizeof (struct acl_object_label)))
35818 + userp = o_tmp->prev;
35820 + len = strnlen_user(o_tmp->filename, PATH_MAX);
35822 + if (!len || len >= PATH_MAX)
35825 + if ((tmp = (char *) acl_alloc(len)) == NULL)
35828 + if (copy_from_user(tmp, o_tmp->filename, len))
35830 + tmp[len-1] = '\0';
35831 + o_tmp->filename = tmp;
35833 + insert_acl_obj_label(o_tmp, subj);
35834 + if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
35835 + o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
35838 + ret = copy_user_glob(o_tmp);
35842 + if (o_tmp->nested) {
35843 + o_tmp->nested = do_copy_user_subj(o_tmp->nested, role);
35844 + if (IS_ERR(o_tmp->nested))
35845 + return PTR_ERR(o_tmp->nested);
35847 + /* insert into nested subject list */
35848 + o_tmp->nested->next = role->hash->first;
35849 + role->hash->first = o_tmp->nested;
35857 +count_user_subjs(struct acl_subject_label *userp)
35859 + struct acl_subject_label s_tmp;
35863 + if (copy_from_user(&s_tmp, userp,
35864 + sizeof (struct acl_subject_label)))
35867 + userp = s_tmp.prev;
35868 + /* do not count nested subjects against this count, since
35869 + they are not included in the hash table, but are
35870 + attached to objects. We have already counted
35871 + the subjects in userspace for the allocation
35874 + if (!(s_tmp.mode & GR_NESTED))
35882 +copy_user_allowedips(struct acl_role_label *rolep)
35884 + struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
35886 + ruserip = rolep->allowed_ips;
35888 + while (ruserip) {
35891 + if ((rtmp = (struct role_allowed_ip *)
35892 + acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
35895 + if (copy_from_user(rtmp, ruserip,
35896 + sizeof (struct role_allowed_ip)))
35899 + ruserip = rtmp->prev;
35902 + rtmp->prev = NULL;
35903 + rolep->allowed_ips = rtmp;
35905 + rlast->next = rtmp;
35906 + rtmp->prev = rlast;
35910 + rtmp->next = NULL;
35917 +copy_user_transitions(struct acl_role_label *rolep)
35919 + struct role_transition *rusertp, *rtmp = NULL, *rlast;
35921 + unsigned int len;
35924 + rusertp = rolep->transitions;
35926 + while (rusertp) {
35929 + if ((rtmp = (struct role_transition *)
35930 + acl_alloc(sizeof (struct role_transition))) == NULL)
35933 + if (copy_from_user(rtmp, rusertp,
35934 + sizeof (struct role_transition)))
35937 + rusertp = rtmp->prev;
35939 + len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
35941 + if (!len || len >= GR_SPROLE_LEN)
35944 + if ((tmp = (char *) acl_alloc(len)) == NULL)
35947 + if (copy_from_user(tmp, rtmp->rolename, len))
35949 + tmp[len-1] = '\0';
35950 + rtmp->rolename = tmp;
35953 + rtmp->prev = NULL;
35954 + rolep->transitions = rtmp;
35956 + rlast->next = rtmp;
35957 + rtmp->prev = rlast;
35961 + rtmp->next = NULL;
35967 +static struct acl_subject_label *
35968 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role)
35970 + struct acl_subject_label *s_tmp = NULL, *s_tmp2;
35971 + unsigned int len;
35974 + struct acl_ip_label **i_tmp, *i_utmp2;
35975 + struct gr_hash_struct ghash;
35976 + struct subject_map *subjmap;
35977 + unsigned int i_num;
35980 + s_tmp = lookup_subject_map(userp);
35982 + /* we've already copied this subject into the kernel, just return
35983 + the reference to it, and don't copy it over again
35988 + if ((s_tmp = (struct acl_subject_label *)
35989 + acl_alloc(sizeof (struct acl_subject_label))) == NULL)
35990 + return ERR_PTR(-ENOMEM);
35992 + subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
35993 + if (subjmap == NULL)
35994 + return ERR_PTR(-ENOMEM);
35996 + subjmap->user = userp;
35997 + subjmap->kernel = s_tmp;
35998 + insert_subj_map_entry(subjmap);
36000 + if (copy_from_user(s_tmp, userp,
36001 + sizeof (struct acl_subject_label)))
36002 + return ERR_PTR(-EFAULT);
36004 + len = strnlen_user(s_tmp->filename, PATH_MAX);
36006 + if (!len || len >= PATH_MAX)
36007 + return ERR_PTR(-EINVAL);
36009 + if ((tmp = (char *) acl_alloc(len)) == NULL)
36010 + return ERR_PTR(-ENOMEM);
36012 + if (copy_from_user(tmp, s_tmp->filename, len))
36013 + return ERR_PTR(-EFAULT);
36014 + tmp[len-1] = '\0';
36015 + s_tmp->filename = tmp;
36017 + if (!strcmp(s_tmp->filename, "/"))
36018 + role->root_label = s_tmp;
36020 + if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
36021 + return ERR_PTR(-EFAULT);
36023 + /* copy user and group transition tables */
36025 + if (s_tmp->user_trans_num) {
36028 + uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
36029 + if (uidlist == NULL)
36030 + return ERR_PTR(-ENOMEM);
36031 + if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
36032 + return ERR_PTR(-EFAULT);
36034 + s_tmp->user_transitions = uidlist;
36037 + if (s_tmp->group_trans_num) {
36040 + gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
36041 + if (gidlist == NULL)
36042 + return ERR_PTR(-ENOMEM);
36043 + if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
36044 + return ERR_PTR(-EFAULT);
36046 + s_tmp->group_transitions = gidlist;
36049 + /* set up object hash table */
36050 + num_objs = count_user_objs(ghash.first);
36052 + s_tmp->obj_hash_size = num_objs;
36053 + s_tmp->obj_hash =
36054 + (struct acl_object_label **)
36055 + create_table(&(s_tmp->obj_hash_size), sizeof(void *));
36057 + if (!s_tmp->obj_hash)
36058 + return ERR_PTR(-ENOMEM);
36060 + memset(s_tmp->obj_hash, 0,
36061 + s_tmp->obj_hash_size *
36062 + sizeof (struct acl_object_label *));
36064 + /* add in objects */
36065 + err = copy_user_objs(ghash.first, s_tmp, role);
36068 + return ERR_PTR(err);
36070 + /* set pointer for parent subject */
36071 + if (s_tmp->parent_subject) {
36072 + s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role);
36074 + if (IS_ERR(s_tmp2))
36077 + s_tmp->parent_subject = s_tmp2;
36080 + /* add in ip acls */
36082 + if (!s_tmp->ip_num) {
36083 + s_tmp->ips = NULL;
36088 + (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
36089 + sizeof (struct acl_ip_label *));
36092 + return ERR_PTR(-ENOMEM);
36094 + for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
36095 + *(i_tmp + i_num) =
36096 + (struct acl_ip_label *)
36097 + acl_alloc(sizeof (struct acl_ip_label));
36098 + if (!*(i_tmp + i_num))
36099 + return ERR_PTR(-ENOMEM);
36101 + if (copy_from_user
36102 + (&i_utmp2, s_tmp->ips + i_num,
36103 + sizeof (struct acl_ip_label *)))
36104 + return ERR_PTR(-EFAULT);
36106 + if (copy_from_user
36107 + (*(i_tmp + i_num), i_utmp2,
36108 + sizeof (struct acl_ip_label)))
36109 + return ERR_PTR(-EFAULT);
36111 + if ((*(i_tmp + i_num))->iface == NULL)
36114 + len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
36115 + if (!len || len >= IFNAMSIZ)
36116 + return ERR_PTR(-EINVAL);
36117 + tmp = acl_alloc(len);
36119 + return ERR_PTR(-ENOMEM);
36120 + if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
36121 + return ERR_PTR(-EFAULT);
36122 + (*(i_tmp + i_num))->iface = tmp;
36125 + s_tmp->ips = i_tmp;
36128 + if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
36129 + s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
36130 + return ERR_PTR(-ENOMEM);
36136 +copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
36138 + struct acl_subject_label s_pre;
36139 + struct acl_subject_label * ret;
36143 + if (copy_from_user(&s_pre, userp,
36144 + sizeof (struct acl_subject_label)))
36147 + /* do not add nested subjects here, add
36148 + while parsing objects
36151 + if (s_pre.mode & GR_NESTED) {
36152 + userp = s_pre.prev;
36156 + ret = do_copy_user_subj(userp, role);
36158 + err = PTR_ERR(ret);
36162 + insert_acl_subj_label(ret, role);
36164 + userp = s_pre.prev;
36171 +copy_user_acl(struct gr_arg *arg)
36173 + struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
36174 + struct sprole_pw *sptmp;
36175 + struct gr_hash_struct *ghash;
36176 + uid_t *domainlist;
36177 + unsigned int r_num;
36178 + unsigned int len;
36184 + /* we need a default and kernel role */
36185 + if (arg->role_db.num_roles < 2)
36188 + /* copy special role authentication info from userspace */
36190 + num_sprole_pws = arg->num_sprole_pws;
36191 + acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
36193 + if (!acl_special_roles) {
36198 + for (i = 0; i < num_sprole_pws; i++) {
36199 + sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
36204 + if (copy_from_user(sptmp, arg->sprole_pws + i,
36205 + sizeof (struct sprole_pw))) {
36211 + strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
36213 + if (!len || len >= GR_SPROLE_LEN) {
36218 + if ((tmp = (char *) acl_alloc(len)) == NULL) {
36223 + if (copy_from_user(tmp, sptmp->rolename, len)) {
36227 + tmp[len-1] = '\0';
36228 +#ifdef CONFIG_GRKERNSEC_ACL_DEBUG
36229 + printk(KERN_ALERT "Copying special role %s\n", tmp);
36231 + sptmp->rolename = tmp;
36232 + acl_special_roles[i] = sptmp;
36235 + r_utmp = (struct acl_role_label **) arg->role_db.r_table;
36237 + for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
36238 + r_tmp = acl_alloc(sizeof (struct acl_role_label));
36245 + if (copy_from_user(&r_utmp2, r_utmp + r_num,
36246 + sizeof (struct acl_role_label *))) {
36251 + if (copy_from_user(r_tmp, r_utmp2,
36252 + sizeof (struct acl_role_label))) {
36257 + len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
36259 + if (!len || len >= PATH_MAX) {
36264 + if ((tmp = (char *) acl_alloc(len)) == NULL) {
36268 + if (copy_from_user(tmp, r_tmp->rolename, len)) {
36272 + tmp[len-1] = '\0';
36273 + r_tmp->rolename = tmp;
36275 + if (!strcmp(r_tmp->rolename, "default")
36276 + && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
36277 + default_role = r_tmp;
36278 + } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
36279 + kernel_role = r_tmp;
36282 + if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL) {
36286 + if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct))) {
36291 + r_tmp->hash = ghash;
36293 + num_subjs = count_user_subjs(r_tmp->hash->first);
36295 + r_tmp->subj_hash_size = num_subjs;
36296 + r_tmp->subj_hash =
36297 + (struct acl_subject_label **)
36298 + create_table(&(r_tmp->subj_hash_size), sizeof(void *));
36300 + if (!r_tmp->subj_hash) {
36305 + err = copy_user_allowedips(r_tmp);
36309 + /* copy domain info */
36310 + if (r_tmp->domain_children != NULL) {
36311 + domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
36312 + if (domainlist == NULL) {
36316 + if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t))) {
36320 + r_tmp->domain_children = domainlist;
36323 + err = copy_user_transitions(r_tmp);
36327 + memset(r_tmp->subj_hash, 0,
36328 + r_tmp->subj_hash_size *
36329 + sizeof (struct acl_subject_label *));
36331 + err = copy_user_subjs(r_tmp->hash->first, r_tmp);
36336 + /* set nested subject list to null */
36337 + r_tmp->hash->first = NULL;
36339 + insert_acl_role_label(r_tmp);
36344 + free_variables();
36351 +gracl_init(struct gr_arg *args)
36355 + memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
36356 + memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
36358 + if (init_variables(args)) {
36359 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
36361 + free_variables();
36365 + error = copy_user_acl(args);
36366 + free_init_variables();
36368 + free_variables();
36372 + if ((error = gr_set_acls(0))) {
36373 + free_variables();
36377 + pax_open_kernel();
36378 + gr_status |= GR_READY;
36379 + pax_close_kernel();
36385 +/* derived from glibc fnmatch() 0: match, 1: no match*/
36388 +glob_match(const char *p, const char *n)
36392 + while ((c = *p++) != '\0') {
36397 + else if (*n == '/')
36405 + for (c = *p++; c == '?' || c == '*'; c = *p++) {
36408 + else if (c == '?') {
36418 + const char *endp;
36420 + if ((endp = strchr(n, '/')) == NULL)
36421 + endp = n + strlen(n);
36424 + for (--p; n < endp; ++n)
36425 + if (!glob_match(p, n))
36427 + } else if (c == '/') {
36428 + while (*n != '\0' && *n != '/')
36430 + if (*n == '/' && !glob_match(p, n + 1))
36433 + for (--p; n < endp; ++n)
36434 + if (*n == c && !glob_match(p, n))
36445 + if (*n == '\0' || *n == '/')
36448 + not = (*p == '!' || *p == '^');
36454 + unsigned char fn = (unsigned char)*n;
36464 + if (c == '-' && *p != ']') {
36465 + unsigned char cend = *p++;
36467 + if (cend == '\0')
36470 + if (cold <= fn && fn <= cend)
36484 + while (c != ']') {
36511 +static struct acl_object_label *
36512 +chk_glob_label(struct acl_object_label *globbed,
36513 + struct dentry *dentry, struct vfsmount *mnt, char **path)
36515 + struct acl_object_label *tmp;
36517 + if (*path == NULL)
36518 + *path = gr_to_filename_nolock(dentry, mnt);
36523 + if (!glob_match(tmp->filename, *path))
36531 +static struct acl_object_label *
36532 +__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
36533 + const ino_t curr_ino, const dev_t curr_dev,
36534 + const struct acl_subject_label *subj, char **path, const int checkglob)
36536 + struct acl_subject_label *tmpsubj;
36537 + struct acl_object_label *retval;
36538 + struct acl_object_label *retval2;
36540 + tmpsubj = (struct acl_subject_label *) subj;
36541 + read_lock(&gr_inode_lock);
36543 + retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
36545 + if (checkglob && retval->globbed) {
36546 + retval2 = chk_glob_label(retval->globbed, (struct dentry *)orig_dentry,
36547 + (struct vfsmount *)orig_mnt, path);
36549 + retval = retval2;
36553 + } while ((tmpsubj = tmpsubj->parent_subject));
36554 + read_unlock(&gr_inode_lock);
36559 +static __inline__ struct acl_object_label *
36560 +full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
36561 + const struct dentry *curr_dentry,
36562 + const struct acl_subject_label *subj, char **path, const int checkglob)
36564 + int newglob = checkglob;
36566 + /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
36567 + as we don't want a / * rule to match instead of the / object
36568 + don't do this for create lookups that call this function though, since they're looking up
36569 + on the parent and thus need globbing checks on all paths
36571 + if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
36572 + newglob = GR_NO_GLOB;
36574 + return __full_lookup(orig_dentry, orig_mnt,
36575 + curr_dentry->d_inode->i_ino,
36576 + curr_dentry->d_inode->i_sb->s_dev, subj, path, newglob);
36579 +static struct acl_object_label *
36580 +__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
36581 + const struct acl_subject_label *subj, char *path, const int checkglob)
36583 + struct dentry *dentry = (struct dentry *) l_dentry;
36584 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
36585 + struct acl_object_label *retval;
36587 + spin_lock(&dcache_lock);
36588 + br_read_lock(vfsmount_lock);
36590 + if (unlikely(mnt == shm_mnt || mnt == pipe_mnt || mnt == sock_mnt ||
36591 +#ifdef CONFIG_HUGETLBFS
36592 + mnt == hugetlbfs_vfsmount ||
36594 + /* ignore Eric Biederman */
36595 + IS_PRIVATE(l_dentry->d_inode))) {
36596 + retval = fakefs_obj;
36601 + if (dentry == real_root.dentry && mnt == real_root.mnt)
36604 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
36605 + if (mnt->mnt_parent == mnt)
36608 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
36609 + if (retval != NULL)
36612 + dentry = mnt->mnt_mountpoint;
36613 + mnt = mnt->mnt_parent;
36617 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
36618 + if (retval != NULL)
36621 + dentry = dentry->d_parent;
36624 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
36626 + if (retval == NULL)
36627 + retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
36629 + br_read_unlock(vfsmount_lock);
36630 + spin_unlock(&dcache_lock);
36632 + BUG_ON(retval == NULL);
36637 +static __inline__ struct acl_object_label *
36638 +chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
36639 + const struct acl_subject_label *subj)
36641 + char *path = NULL;
36642 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
36645 +static __inline__ struct acl_object_label *
36646 +chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
36647 + const struct acl_subject_label *subj)
36649 + char *path = NULL;
36650 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
36653 +static __inline__ struct acl_object_label *
36654 +chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
36655 + const struct acl_subject_label *subj, char *path)
36657 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
36660 +static struct acl_subject_label *
36661 +chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
36662 + const struct acl_role_label *role)
36664 + struct dentry *dentry = (struct dentry *) l_dentry;
36665 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
36666 + struct acl_subject_label *retval;
36668 + spin_lock(&dcache_lock);
36669 + br_read_lock(vfsmount_lock);
36672 + if (dentry == real_root.dentry && mnt == real_root.mnt)
36674 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
36675 + if (mnt->mnt_parent == mnt)
36678 + read_lock(&gr_inode_lock);
36680 + lookup_acl_subj_label(dentry->d_inode->i_ino,
36681 + dentry->d_inode->i_sb->s_dev, role);
36682 + read_unlock(&gr_inode_lock);
36683 + if (retval != NULL)
36686 + dentry = mnt->mnt_mountpoint;
36687 + mnt = mnt->mnt_parent;
36691 + read_lock(&gr_inode_lock);
36692 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
36693 + dentry->d_inode->i_sb->s_dev, role);
36694 + read_unlock(&gr_inode_lock);
36695 + if (retval != NULL)
36698 + dentry = dentry->d_parent;
36701 + read_lock(&gr_inode_lock);
36702 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
36703 + dentry->d_inode->i_sb->s_dev, role);
36704 + read_unlock(&gr_inode_lock);
36706 + if (unlikely(retval == NULL)) {
36707 + read_lock(&gr_inode_lock);
36708 + retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
36709 + real_root.dentry->d_inode->i_sb->s_dev, role);
36710 + read_unlock(&gr_inode_lock);
36713 + br_read_unlock(vfsmount_lock);
36714 + spin_unlock(&dcache_lock);
36716 + BUG_ON(retval == NULL);
36722 +gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
36724 + struct task_struct *task = current;
36725 + const struct cred *cred = current_cred();
36727 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
36728 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
36729 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
36730 + 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
36736 +gr_log_learn_sysctl(const char *path, const __u32 mode)
36738 + struct task_struct *task = current;
36739 + const struct cred *cred = current_cred();
36741 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
36742 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
36743 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
36744 + 1UL, 1UL, path, (unsigned long) mode, &task->signal->saved_ip);
36750 +gr_log_learn_id_change(const char type, const unsigned int real,
36751 + const unsigned int effective, const unsigned int fs)
36753 + struct task_struct *task = current;
36754 + const struct cred *cred = current_cred();
36756 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
36757 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
36758 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
36759 + type, real, effective, fs, &task->signal->saved_ip);
36765 +gr_check_link(const struct dentry * new_dentry,
36766 + const struct dentry * parent_dentry,
36767 + const struct vfsmount * parent_mnt,
36768 + const struct dentry * old_dentry, const struct vfsmount * old_mnt)
36770 + struct acl_object_label *obj;
36771 + __u32 oldmode, newmode;
36774 + if (unlikely(!(gr_status & GR_READY)))
36775 + return (GR_CREATE | GR_LINK);
36777 + obj = chk_obj_label(old_dentry, old_mnt, current->acl);
36778 + oldmode = obj->mode;
36780 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
36781 + oldmode |= (GR_CREATE | GR_LINK);
36783 + needmode = GR_CREATE | GR_AUDIT_CREATE | GR_SUPPRESS;
36784 + if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID))
36785 + needmode |= GR_SETID | GR_AUDIT_SETID;
36788 + gr_check_create(new_dentry, parent_dentry, parent_mnt,
36789 + oldmode | needmode);
36791 + needmode = newmode & (GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC |
36792 + GR_SETID | GR_READ | GR_FIND | GR_DELETE |
36793 + GR_INHERIT | GR_AUDIT_INHERIT);
36795 + if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID) && !(newmode & GR_SETID))
36798 + if ((oldmode & needmode) != needmode)
36801 + needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
36802 + if ((newmode & needmode) != needmode)
36805 + if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
36808 + needmode = oldmode;
36809 + if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID))
36810 + needmode |= GR_SETID;
36812 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
36813 + gr_log_learn(old_dentry, old_mnt, needmode);
36814 + return (GR_CREATE | GR_LINK);
36815 + } else if (newmode & GR_SUPPRESS)
36816 + return GR_SUPPRESS;
36822 +gr_search_file(const struct dentry * dentry, const __u32 mode,
36823 + const struct vfsmount * mnt)
36825 + __u32 retval = mode;
36826 + struct acl_subject_label *curracl;
36827 + struct acl_object_label *currobj;
36829 + if (unlikely(!(gr_status & GR_READY)))
36830 + return (mode & ~GR_AUDITS);
36832 + curracl = current->acl;
36834 + currobj = chk_obj_label(dentry, mnt, curracl);
36835 + retval = currobj->mode & mode;
36838 + ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
36839 + && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
36840 + __u32 new_mode = mode;
36842 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
36844 + retval = new_mode;
36846 + if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
36847 + new_mode |= GR_INHERIT;
36849 + if (!(mode & GR_NOLEARN))
36850 + gr_log_learn(dentry, mnt, new_mode);
36857 +gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
36858 + const struct vfsmount * mnt, const __u32 mode)
36860 + struct name_entry *match;
36861 + struct acl_object_label *matchpo;
36862 + struct acl_subject_label *curracl;
36866 + if (unlikely(!(gr_status & GR_READY)))
36867 + return (mode & ~GR_AUDITS);
36869 + preempt_disable();
36870 + path = gr_to_filename_rbac(new_dentry, mnt);
36871 + match = lookup_name_entry_create(path);
36874 + goto check_parent;
36876 + curracl = current->acl;
36878 + read_lock(&gr_inode_lock);
36879 + matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
36880 + read_unlock(&gr_inode_lock);
36883 + if ((matchpo->mode & mode) !=
36884 + (mode & ~(GR_AUDITS | GR_SUPPRESS))
36885 + && curracl->mode & (GR_LEARN | GR_INHERITLEARN)) {
36886 + __u32 new_mode = mode;
36888 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
36890 + gr_log_learn(new_dentry, mnt, new_mode);
36892 + preempt_enable();
36895 + preempt_enable();
36896 + return (matchpo->mode & mode);
36900 + curracl = current->acl;
36902 + matchpo = chk_obj_create_label(parent, mnt, curracl, path);
36903 + retval = matchpo->mode & mode;
36905 + if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
36906 + && (curracl->mode & (GR_LEARN | GR_INHERITLEARN))) {
36907 + __u32 new_mode = mode;
36909 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
36911 + gr_log_learn(new_dentry, mnt, new_mode);
36912 + preempt_enable();
36916 + preempt_enable();
36921 +gr_check_hidden_task(const struct task_struct *task)
36923 + if (unlikely(!(gr_status & GR_READY)))
36926 + if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
36933 +gr_check_protected_task(const struct task_struct *task)
36935 + if (unlikely(!(gr_status & GR_READY) || !task))
36938 + if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
36939 + task->acl != current->acl)
36946 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
36948 + struct task_struct *p;
36951 + if (unlikely(!(gr_status & GR_READY) || !pid))
36954 + read_lock(&tasklist_lock);
36955 + do_each_pid_task(pid, type, p) {
36956 + if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
36957 + p->acl != current->acl) {
36961 + } while_each_pid_task(pid, type, p);
36963 + read_unlock(&tasklist_lock);
36969 +gr_copy_label(struct task_struct *tsk)
36971 + tsk->signal->used_accept = 0;
36972 + tsk->acl_sp_role = 0;
36973 + tsk->acl_role_id = current->acl_role_id;
36974 + tsk->acl = current->acl;
36975 + tsk->role = current->role;
36976 + tsk->signal->curr_ip = current->signal->curr_ip;
36977 + tsk->signal->saved_ip = current->signal->saved_ip;
36978 + if (current->exec_file)
36979 + get_file(current->exec_file);
36980 + tsk->exec_file = current->exec_file;
36981 + tsk->is_writable = current->is_writable;
36982 + if (unlikely(current->signal->used_accept)) {
36983 + current->signal->curr_ip = 0;
36984 + current->signal->saved_ip = 0;
36991 +gr_set_proc_res(struct task_struct *task)
36993 + struct acl_subject_label *proc;
36994 + unsigned short i;
36996 + proc = task->acl;
36998 + if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
37001 + for (i = 0; i < RLIM_NLIMITS; i++) {
37002 + if (!(proc->resmask & (1 << i)))
37005 + task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
37006 + task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
37013 +gr_check_user_change(int real, int effective, int fs)
37020 + int effectiveok = 0;
37023 + if (unlikely(!(gr_status & GR_READY)))
37026 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
37027 + gr_log_learn_id_change('u', real, effective, fs);
37029 + num = current->acl->user_trans_num;
37030 + uidlist = current->acl->user_transitions;
37032 + if (uidlist == NULL)
37037 + if (effective == -1)
37042 + if (current->acl->user_trans_type & GR_ID_ALLOW) {
37043 + for (i = 0; i < num; i++) {
37044 + curuid = (int)uidlist[i];
37045 + if (real == curuid)
37047 + if (effective == curuid)
37049 + if (fs == curuid)
37052 + } else if (current->acl->user_trans_type & GR_ID_DENY) {
37053 + for (i = 0; i < num; i++) {
37054 + curuid = (int)uidlist[i];
37055 + if (real == curuid)
37057 + if (effective == curuid)
37059 + if (fs == curuid)
37062 + /* not in deny list */
37070 + if (realok && effectiveok && fsok)
37073 + gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
37079 +gr_check_group_change(int real, int effective, int fs)
37086 + int effectiveok = 0;
37089 + if (unlikely(!(gr_status & GR_READY)))
37092 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
37093 + gr_log_learn_id_change('g', real, effective, fs);
37095 + num = current->acl->group_trans_num;
37096 + gidlist = current->acl->group_transitions;
37098 + if (gidlist == NULL)
37103 + if (effective == -1)
37108 + if (current->acl->group_trans_type & GR_ID_ALLOW) {
37109 + for (i = 0; i < num; i++) {
37110 + curgid = (int)gidlist[i];
37111 + if (real == curgid)
37113 + if (effective == curgid)
37115 + if (fs == curgid)
37118 + } else if (current->acl->group_trans_type & GR_ID_DENY) {
37119 + for (i = 0; i < num; i++) {
37120 + curgid = (int)gidlist[i];
37121 + if (real == curgid)
37123 + if (effective == curgid)
37125 + if (fs == curgid)
37128 + /* not in deny list */
37136 + if (realok && effectiveok && fsok)
37139 + gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
37145 +gr_set_role_label(struct task_struct *task, const uid_t uid, const uid_t gid)
37147 + struct acl_role_label *role = task->role;
37148 + struct acl_subject_label *subj = NULL;
37149 + struct acl_object_label *obj;
37150 + struct file *filp;
37152 + if (unlikely(!(gr_status & GR_READY)))
37155 + filp = task->exec_file;
37157 + /* kernel process, we'll give them the kernel role */
37158 + if (unlikely(!filp)) {
37159 + task->role = kernel_role;
37160 + task->acl = kernel_role->root_label;
37162 + } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
37163 + role = lookup_acl_role_label(task, uid, gid);
37165 + /* perform subject lookup in possibly new role
37166 + we can use this result below in the case where role == task->role
37168 + subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
37170 + /* if we changed uid/gid, but result in the same role
37171 + and are using inheritance, don't lose the inherited subject
37172 + if current subject is other than what normal lookup
37173 + would result in, we arrived via inheritance, don't
37176 + if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
37177 + (subj == task->acl)))
37178 + task->acl = subj;
37180 + task->role = role;
37182 + task->is_writable = 0;
37184 + /* ignore additional mmap checks for processes that are writable
37185 + by the default ACL */
37186 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
37187 + if (unlikely(obj->mode & GR_WRITE))
37188 + task->is_writable = 1;
37189 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
37190 + if (unlikely(obj->mode & GR_WRITE))
37191 + task->is_writable = 1;
37193 +#ifdef CONFIG_GRKERNSEC_ACL_DEBUG
37194 + printk(KERN_ALERT "Set role label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
37197 + gr_set_proc_res(task);
37203 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
37204 + const int unsafe_share)
37206 + struct task_struct *task = current;
37207 + struct acl_subject_label *newacl;
37208 + struct acl_object_label *obj;
37211 + if (unlikely(!(gr_status & GR_READY)))
37214 + newacl = chk_subj_label(dentry, mnt, task->role);
37217 + if ((((task->ptrace & PT_PTRACED) || unsafe_share) &&
37218 + !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
37219 + !(task->role->roletype & GR_ROLE_GOD) &&
37220 + !gr_search_file(dentry, GR_PTRACERD, mnt) &&
37221 + !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN)))) {
37222 + task_unlock(task);
37223 + if (unsafe_share)
37224 + gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
37226 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
37229 + task_unlock(task);
37231 + obj = chk_obj_label(dentry, mnt, task->acl);
37232 + retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
37234 + if (!(task->acl->mode & GR_INHERITLEARN) &&
37235 + ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
37237 + task->acl = obj->nested;
37239 + task->acl = newacl;
37240 + } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
37241 + gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
37243 + task->is_writable = 0;
37245 + /* ignore additional mmap checks for processes that are writable
37246 + by the default ACL */
37247 + obj = chk_obj_label(dentry, mnt, default_role->root_label);
37248 + if (unlikely(obj->mode & GR_WRITE))
37249 + task->is_writable = 1;
37250 + obj = chk_obj_label(dentry, mnt, task->role->root_label);
37251 + if (unlikely(obj->mode & GR_WRITE))
37252 + task->is_writable = 1;
37254 + gr_set_proc_res(task);
37256 +#ifdef CONFIG_GRKERNSEC_ACL_DEBUG
37257 + printk(KERN_ALERT "Set subject label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
37262 +/* always called with valid inodev ptr */
37264 +do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
37266 + struct acl_object_label *matchpo;
37267 + struct acl_subject_label *matchps;
37268 + struct acl_subject_label *subj;
37269 + struct acl_role_label *role;
37272 + FOR_EACH_ROLE_START(role)
37273 + FOR_EACH_SUBJECT_START(role, subj, x)
37274 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
37275 + matchpo->mode |= GR_DELETED;
37276 + FOR_EACH_SUBJECT_END(subj,x)
37277 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
37278 + if (subj->inode == ino && subj->device == dev)
37279 + subj->mode |= GR_DELETED;
37280 + FOR_EACH_NESTED_SUBJECT_END(subj)
37281 + if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
37282 + matchps->mode |= GR_DELETED;
37283 + FOR_EACH_ROLE_END(role)
37285 + inodev->nentry->deleted = 1;
37291 +gr_handle_delete(const ino_t ino, const dev_t dev)
37293 + struct inodev_entry *inodev;
37295 + if (unlikely(!(gr_status & GR_READY)))
37298 + write_lock(&gr_inode_lock);
37299 + inodev = lookup_inodev_entry(ino, dev);
37300 + if (inodev != NULL)
37301 + do_handle_delete(inodev, ino, dev);
37302 + write_unlock(&gr_inode_lock);
37308 +update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
37309 + const ino_t newinode, const dev_t newdevice,
37310 + struct acl_subject_label *subj)
37312 + unsigned int index = fhash(oldinode, olddevice, subj->obj_hash_size);
37313 + struct acl_object_label *match;
37315 + match = subj->obj_hash[index];
37317 + while (match && (match->inode != oldinode ||
37318 + match->device != olddevice ||
37319 + !(match->mode & GR_DELETED)))
37320 + match = match->next;
37322 + if (match && (match->inode == oldinode)
37323 + && (match->device == olddevice)
37324 + && (match->mode & GR_DELETED)) {
37325 + if (match->prev == NULL) {
37326 + subj->obj_hash[index] = match->next;
37327 + if (match->next != NULL)
37328 + match->next->prev = NULL;
37330 + match->prev->next = match->next;
37331 + if (match->next != NULL)
37332 + match->next->prev = match->prev;
37334 + match->prev = NULL;
37335 + match->next = NULL;
37336 + match->inode = newinode;
37337 + match->device = newdevice;
37338 + match->mode &= ~GR_DELETED;
37340 + insert_acl_obj_label(match, subj);
37347 +update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
37348 + const ino_t newinode, const dev_t newdevice,
37349 + struct acl_role_label *role)
37351 + unsigned int index = fhash(oldinode, olddevice, role->subj_hash_size);
37352 + struct acl_subject_label *match;
37354 + match = role->subj_hash[index];
37356 + while (match && (match->inode != oldinode ||
37357 + match->device != olddevice ||
37358 + !(match->mode & GR_DELETED)))
37359 + match = match->next;
37361 + if (match && (match->inode == oldinode)
37362 + && (match->device == olddevice)
37363 + && (match->mode & GR_DELETED)) {
37364 + if (match->prev == NULL) {
37365 + role->subj_hash[index] = match->next;
37366 + if (match->next != NULL)
37367 + match->next->prev = NULL;
37369 + match->prev->next = match->next;
37370 + if (match->next != NULL)
37371 + match->next->prev = match->prev;
37373 + match->prev = NULL;
37374 + match->next = NULL;
37375 + match->inode = newinode;
37376 + match->device = newdevice;
37377 + match->mode &= ~GR_DELETED;
37379 + insert_acl_subj_label(match, role);
37386 +update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
37387 + const ino_t newinode, const dev_t newdevice)
37389 + unsigned int index = fhash(oldinode, olddevice, inodev_set.i_size);
37390 + struct inodev_entry *match;
37392 + match = inodev_set.i_hash[index];
37394 + while (match && (match->nentry->inode != oldinode ||
37395 + match->nentry->device != olddevice || !match->nentry->deleted))
37396 + match = match->next;
37398 + if (match && (match->nentry->inode == oldinode)
37399 + && (match->nentry->device == olddevice) &&
37400 + match->nentry->deleted) {
37401 + if (match->prev == NULL) {
37402 + inodev_set.i_hash[index] = match->next;
37403 + if (match->next != NULL)
37404 + match->next->prev = NULL;
37406 + match->prev->next = match->next;
37407 + if (match->next != NULL)
37408 + match->next->prev = match->prev;
37410 + match->prev = NULL;
37411 + match->next = NULL;
37412 + match->nentry->inode = newinode;
37413 + match->nentry->device = newdevice;
37414 + match->nentry->deleted = 0;
37416 + insert_inodev_entry(match);
37423 +do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
37424 + const struct vfsmount *mnt)
37426 + struct acl_subject_label *subj;
37427 + struct acl_role_label *role;
37430 + FOR_EACH_ROLE_START(role)
37431 + update_acl_subj_label(matchn->inode, matchn->device,
37432 + dentry->d_inode->i_ino,
37433 + dentry->d_inode->i_sb->s_dev, role);
37435 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
37436 + if ((subj->inode == dentry->d_inode->i_ino) &&
37437 + (subj->device == dentry->d_inode->i_sb->s_dev)) {
37438 + subj->inode = dentry->d_inode->i_ino;
37439 + subj->device = dentry->d_inode->i_sb->s_dev;
37441 + FOR_EACH_NESTED_SUBJECT_END(subj)
37442 + FOR_EACH_SUBJECT_START(role, subj, x)
37443 + update_acl_obj_label(matchn->inode, matchn->device,
37444 + dentry->d_inode->i_ino,
37445 + dentry->d_inode->i_sb->s_dev, subj);
37446 + FOR_EACH_SUBJECT_END(subj,x)
37447 + FOR_EACH_ROLE_END(role)
37449 + update_inodev_entry(matchn->inode, matchn->device,
37450 + dentry->d_inode->i_ino, dentry->d_inode->i_sb->s_dev);
37456 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
37458 + struct name_entry *matchn;
37460 + if (unlikely(!(gr_status & GR_READY)))
37463 + preempt_disable();
37464 + matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
37466 + if (unlikely((unsigned long)matchn)) {
37467 + write_lock(&gr_inode_lock);
37468 + do_handle_create(matchn, dentry, mnt);
37469 + write_unlock(&gr_inode_lock);
37471 + preempt_enable();
37477 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
37478 + struct dentry *old_dentry,
37479 + struct dentry *new_dentry,
37480 + struct vfsmount *mnt, const __u8 replace)
37482 + struct name_entry *matchn;
37483 + struct inodev_entry *inodev;
37485 + /* vfs_rename swaps the name and parent link for old_dentry and
37487 + at this point, old_dentry has the new name, parent link, and inode
37488 + for the renamed file
37489 + if a file is being replaced by a rename, new_dentry has the inode
37490 + and name for the replaced file
37493 + if (unlikely(!(gr_status & GR_READY)))
37496 + preempt_disable();
37497 + matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
37499 + /* we wouldn't have to check d_inode if it weren't for
37500 + NFS silly-renaming
37503 + write_lock(&gr_inode_lock);
37504 + if (unlikely(replace && new_dentry->d_inode)) {
37505 + inodev = lookup_inodev_entry(new_dentry->d_inode->i_ino,
37506 + new_dentry->d_inode->i_sb->s_dev);
37507 + if (inodev != NULL && (new_dentry->d_inode->i_nlink <= 1))
37508 + do_handle_delete(inodev, new_dentry->d_inode->i_ino,
37509 + new_dentry->d_inode->i_sb->s_dev);
37512 + inodev = lookup_inodev_entry(old_dentry->d_inode->i_ino,
37513 + old_dentry->d_inode->i_sb->s_dev);
37514 + if (inodev != NULL && (old_dentry->d_inode->i_nlink <= 1))
37515 + do_handle_delete(inodev, old_dentry->d_inode->i_ino,
37516 + old_dentry->d_inode->i_sb->s_dev);
37518 + if (unlikely((unsigned long)matchn))
37519 + do_handle_create(matchn, old_dentry, mnt);
37521 + write_unlock(&gr_inode_lock);
37522 + preempt_enable();
37528 +lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
37529 + unsigned char **sum)
37531 + struct acl_role_label *r;
37532 + struct role_allowed_ip *ipp;
37533 + struct role_transition *trans;
37536 + u32 curr_ip = current->signal->curr_ip;
37538 + current->signal->saved_ip = curr_ip;
37540 + /* check transition table */
37542 + for (trans = current->role->transitions; trans; trans = trans->next) {
37543 + if (!strcmp(rolename, trans->rolename)) {
37552 + /* handle special roles that do not require authentication
37555 + FOR_EACH_ROLE_START(r)
37556 + if (!strcmp(rolename, r->rolename) &&
37557 + (r->roletype & GR_ROLE_SPECIAL)) {
37559 + if (r->allowed_ips != NULL) {
37560 + for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
37561 + if ((ntohl(curr_ip) & ipp->netmask) ==
37562 + (ntohl(ipp->addr) & ipp->netmask))
37570 + if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
37571 + ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
37577 + FOR_EACH_ROLE_END(r)
37579 + for (i = 0; i < num_sprole_pws; i++) {
37580 + if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
37581 + *salt = acl_special_roles[i]->salt;
37582 + *sum = acl_special_roles[i]->sum;
37591 +assign_special_role(char *rolename)
37593 + struct acl_object_label *obj;
37594 + struct acl_role_label *r;
37595 + struct acl_role_label *assigned = NULL;
37596 + struct task_struct *tsk;
37597 + struct file *filp;
37599 + FOR_EACH_ROLE_START(r)
37600 + if (!strcmp(rolename, r->rolename) &&
37601 + (r->roletype & GR_ROLE_SPECIAL)) {
37605 + FOR_EACH_ROLE_END(r)
37610 + read_lock(&tasklist_lock);
37611 + read_lock(&grsec_exec_file_lock);
37613 + tsk = current->real_parent;
37617 + filp = tsk->exec_file;
37618 + if (filp == NULL)
37621 + tsk->is_writable = 0;
37623 + tsk->acl_sp_role = 1;
37624 + tsk->acl_role_id = ++acl_sp_role_value;
37625 + tsk->role = assigned;
37626 + tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
37628 + /* ignore additional mmap checks for processes that are writable
37629 + by the default ACL */
37630 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
37631 + if (unlikely(obj->mode & GR_WRITE))
37632 + tsk->is_writable = 1;
37633 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
37634 + if (unlikely(obj->mode & GR_WRITE))
37635 + tsk->is_writable = 1;
37637 +#ifdef CONFIG_GRKERNSEC_ACL_DEBUG
37638 + printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename, tsk->acl->filename, tsk->comm, tsk->pid);
37642 + read_unlock(&grsec_exec_file_lock);
37643 + read_unlock(&tasklist_lock);
37647 +int gr_check_secure_terminal(struct task_struct *task)
37649 + struct task_struct *p, *p2, *p3;
37650 + struct files_struct *files;
37651 + struct fdtable *fdt;
37652 + struct file *our_file = NULL, *file;
37655 + if (task->signal->tty == NULL)
37658 + files = get_files_struct(task);
37659 + if (files != NULL) {
37661 + fdt = files_fdtable(files);
37662 + for (i=0; i < fdt->max_fds; i++) {
37663 + file = fcheck_files(files, i);
37664 + if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
37669 + rcu_read_unlock();
37670 + put_files_struct(files);
37673 + if (our_file == NULL)
37676 + read_lock(&tasklist_lock);
37677 + do_each_thread(p2, p) {
37678 + files = get_files_struct(p);
37679 + if (files == NULL ||
37680 + (p->signal && p->signal->tty == task->signal->tty)) {
37681 + if (files != NULL)
37682 + put_files_struct(files);
37686 + fdt = files_fdtable(files);
37687 + for (i=0; i < fdt->max_fds; i++) {
37688 + file = fcheck_files(files, i);
37689 + if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
37690 + file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
37692 + while (p3->pid > 0) {
37695 + p3 = p3->real_parent;
37699 + gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
37700 + gr_handle_alertkill(p);
37701 + rcu_read_unlock();
37702 + put_files_struct(files);
37703 + read_unlock(&tasklist_lock);
37708 + rcu_read_unlock();
37709 + put_files_struct(files);
37710 + } while_each_thread(p2, p);
37711 + read_unlock(&tasklist_lock);
37718 +write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
37720 + struct gr_arg_wrapper uwrap;
37721 + unsigned char *sprole_salt = NULL;
37722 + unsigned char *sprole_sum = NULL;
37723 + int error = sizeof (struct gr_arg_wrapper);
37726 + mutex_lock(&gr_dev_mutex);
37728 + if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
37733 + if (count != sizeof (struct gr_arg_wrapper)) {
37734 + gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
37740 + if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
37741 + gr_auth_expires = 0;
37742 + gr_auth_attempts = 0;
37745 + if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
37750 + if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
37755 + if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
37760 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
37761 + gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
37762 + time_after(gr_auth_expires, get_seconds())) {
37767 + /* if non-root trying to do anything other than use a special role,
37768 + do not attempt authentication, do not count towards authentication
37772 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
37773 + gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
37779 + /* ensure pw and special role name are null terminated */
37781 + gr_usermode->pw[GR_PW_LEN - 1] = '\0';
37782 + gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
37785 + * We have our enough of the argument structure..(we have yet
37786 + * to copy_from_user the tables themselves) . Copy the tables
37787 + * only if we need them, i.e. for loading operations. */
37789 + switch (gr_usermode->mode) {
37791 + if (gr_status & GR_READY) {
37793 + if (!gr_check_secure_terminal(current))
37798 + case GR_SHUTDOWN:
37799 + if ((gr_status & GR_READY)
37800 + && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
37801 + pax_open_kernel();
37802 + gr_status &= ~GR_READY;
37803 + pax_close_kernel();
37805 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
37806 + free_variables();
37807 + memset(gr_usermode, 0, sizeof (struct gr_arg));
37808 + memset(gr_system_salt, 0, GR_SALT_LEN);
37809 + memset(gr_system_sum, 0, GR_SHA_LEN);
37810 + } else if (gr_status & GR_READY) {
37811 + gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
37814 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
37819 + if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
37820 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
37822 + if (gr_status & GR_READY)
37826 + gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
37830 + if (!(gr_status & GR_READY)) {
37831 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
37833 + } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
37834 + preempt_disable();
37836 + pax_open_kernel();
37837 + gr_status &= ~GR_READY;
37838 + pax_close_kernel();
37840 + free_variables();
37841 + if (!(error2 = gracl_init(gr_usermode))) {
37842 + preempt_enable();
37843 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
37845 + preempt_enable();
37847 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
37850 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
37855 + if (unlikely(!(gr_status & GR_READY))) {
37856 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
37861 + if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
37862 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
37863 + if (gr_usermode->segv_device && gr_usermode->segv_inode) {
37864 + struct acl_subject_label *segvacl;
37866 + lookup_acl_subj_label(gr_usermode->segv_inode,
37867 + gr_usermode->segv_device,
37870 + segvacl->crashes = 0;
37871 + segvacl->expires = 0;
37873 + } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
37874 + gr_remove_uid(gr_usermode->segv_uid);
37877 + gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
37882 + case GR_SPROLEPAM:
37883 + if (unlikely(!(gr_status & GR_READY))) {
37884 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
37889 + if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
37890 + current->role->expires = 0;
37891 + current->role->auth_attempts = 0;
37894 + if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
37895 + time_after(current->role->expires, get_seconds())) {
37900 + if (lookup_special_role_auth
37901 + (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
37902 + && ((!sprole_salt && !sprole_sum)
37903 + || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
37905 + assign_special_role(gr_usermode->sp_role);
37906 + read_lock(&tasklist_lock);
37907 + if (current->real_parent)
37908 + p = current->real_parent->role->rolename;
37909 + read_unlock(&tasklist_lock);
37910 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
37911 + p, acl_sp_role_value);
37913 + gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
37915 + if(!(current->role->auth_attempts++))
37916 + current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
37921 + case GR_UNSPROLE:
37922 + if (unlikely(!(gr_status & GR_READY))) {
37923 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
37928 + if (current->role->roletype & GR_ROLE_SPECIAL) {
37932 + read_lock(&tasklist_lock);
37933 + if (current->real_parent) {
37934 + p = current->real_parent->role->rolename;
37935 + i = current->real_parent->acl_role_id;
37937 + read_unlock(&tasklist_lock);
37939 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
37947 + gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
37952 + if (error != -EPERM)
37955 + if(!(gr_auth_attempts++))
37956 + gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
37959 + mutex_unlock(&gr_dev_mutex);
37964 +gr_set_acls(const int type)
37966 + struct acl_object_label *obj;
37967 + struct task_struct *task, *task2;
37968 + struct file *filp;
37969 + struct acl_role_label *role = current->role;
37970 + __u16 acl_role_id = current->acl_role_id;
37971 + const struct cred *cred;
37973 + struct name_entry *nmatch;
37974 + struct acl_subject_label *tmpsubj;
37977 + read_lock(&tasklist_lock);
37978 + read_lock(&grsec_exec_file_lock);
37979 + do_each_thread(task2, task) {
37980 + /* check to see if we're called from the exit handler,
37981 + if so, only replace ACLs that have inherited the admin
37984 + if (type && (task->role != role ||
37985 + task->acl_role_id != acl_role_id))
37988 + task->acl_role_id = 0;
37989 + task->acl_sp_role = 0;
37991 + if ((filp = task->exec_file)) {
37992 + cred = __task_cred(task);
37993 + task->role = lookup_acl_role_label(task, cred->uid, cred->gid);
37995 + /* the following is to apply the correct subject
37996 + on binaries running when the RBAC system
37997 + is enabled, when the binaries have been
37998 + replaced or deleted since their execution
38000 + when the RBAC system starts, the inode/dev
38001 + from exec_file will be one the RBAC system
38002 + is unaware of. It only knows the inode/dev
38003 + of the present file on disk, or the absence
38006 + preempt_disable();
38007 + tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
38009 + nmatch = lookup_name_entry(tmpname);
38010 + preempt_enable();
38013 + if (nmatch->deleted)
38014 + tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
38016 + tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
38017 + if (tmpsubj != NULL)
38018 + task->acl = tmpsubj;
38020 + if (tmpsubj == NULL)
38021 + task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
38024 + struct acl_subject_label *curr;
38025 + curr = task->acl;
38027 + task->is_writable = 0;
38028 + /* ignore additional mmap checks for processes that are writable
38029 + by the default ACL */
38030 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
38031 + if (unlikely(obj->mode & GR_WRITE))
38032 + task->is_writable = 1;
38033 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
38034 + if (unlikely(obj->mode & GR_WRITE))
38035 + task->is_writable = 1;
38037 + gr_set_proc_res(task);
38039 +#ifdef CONFIG_GRKERNSEC_ACL_DEBUG
38040 + printk(KERN_ALERT "gr_set_acls for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
38043 + read_unlock(&grsec_exec_file_lock);
38044 + read_unlock(&tasklist_lock);
38045 + rcu_read_unlock();
38046 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task->pid);
38050 + // it's a kernel process
38051 + task->role = kernel_role;
38052 + task->acl = kernel_role->root_label;
38053 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
38054 + task->acl->mode &= ~GR_PROCFIND;
38057 + } while_each_thread(task2, task);
38058 + read_unlock(&grsec_exec_file_lock);
38059 + read_unlock(&tasklist_lock);
38060 + rcu_read_unlock();
38066 +gr_learn_resource(const struct task_struct *task,
38067 + const int res, const unsigned long wanted, const int gt)
38069 + struct acl_subject_label *acl;
38070 + const struct cred *cred;
38072 + if (unlikely((gr_status & GR_READY) &&
38073 + task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
38074 + goto skip_reslog;
38076 +#ifdef CONFIG_GRKERNSEC_RESLOG
38077 + gr_log_resource(task, res, wanted, gt);
38081 + if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
38086 + if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
38087 + !(acl->resmask & (1 << (unsigned short) res))))
38090 + if (wanted >= acl->res[res].rlim_cur) {
38091 + unsigned long res_add;
38093 + res_add = wanted;
38096 + res_add += GR_RLIM_CPU_BUMP;
38098 + case RLIMIT_FSIZE:
38099 + res_add += GR_RLIM_FSIZE_BUMP;
38101 + case RLIMIT_DATA:
38102 + res_add += GR_RLIM_DATA_BUMP;
38104 + case RLIMIT_STACK:
38105 + res_add += GR_RLIM_STACK_BUMP;
38107 + case RLIMIT_CORE:
38108 + res_add += GR_RLIM_CORE_BUMP;
38111 + res_add += GR_RLIM_RSS_BUMP;
38113 + case RLIMIT_NPROC:
38114 + res_add += GR_RLIM_NPROC_BUMP;
38116 + case RLIMIT_NOFILE:
38117 + res_add += GR_RLIM_NOFILE_BUMP;
38119 + case RLIMIT_MEMLOCK:
38120 + res_add += GR_RLIM_MEMLOCK_BUMP;
38123 + res_add += GR_RLIM_AS_BUMP;
38125 + case RLIMIT_LOCKS:
38126 + res_add += GR_RLIM_LOCKS_BUMP;
38128 + case RLIMIT_SIGPENDING:
38129 + res_add += GR_RLIM_SIGPENDING_BUMP;
38131 + case RLIMIT_MSGQUEUE:
38132 + res_add += GR_RLIM_MSGQUEUE_BUMP;
38134 + case RLIMIT_NICE:
38135 + res_add += GR_RLIM_NICE_BUMP;
38137 + case RLIMIT_RTPRIO:
38138 + res_add += GR_RLIM_RTPRIO_BUMP;
38140 + case RLIMIT_RTTIME:
38141 + res_add += GR_RLIM_RTTIME_BUMP;
38145 + acl->res[res].rlim_cur = res_add;
38147 + if (wanted > acl->res[res].rlim_max)
38148 + acl->res[res].rlim_max = res_add;
38150 + /* only log the subject filename, since resource logging is supported for
38151 + single-subject learning only */
38153 + cred = __task_cred(task);
38154 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
38155 + task->role->roletype, cred->uid, cred->gid, acl->filename,
38156 + acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
38157 + "", (unsigned long) res, &task->signal->saved_ip);
38158 + rcu_read_unlock();
38164 +#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
38166 +pax_set_initial_flags(struct linux_binprm *bprm)
38168 + struct task_struct *task = current;
38169 + struct acl_subject_label *proc;
38170 + unsigned long flags;
38172 + if (unlikely(!(gr_status & GR_READY)))
38175 + flags = pax_get_flags(task);
38177 + proc = task->acl;
38179 + if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
38180 + flags &= ~MF_PAX_PAGEEXEC;
38181 + if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
38182 + flags &= ~MF_PAX_SEGMEXEC;
38183 + if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
38184 + flags &= ~MF_PAX_RANDMMAP;
38185 + if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
38186 + flags &= ~MF_PAX_EMUTRAMP;
38187 + if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
38188 + flags &= ~MF_PAX_MPROTECT;
38190 + if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
38191 + flags |= MF_PAX_PAGEEXEC;
38192 + if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
38193 + flags |= MF_PAX_SEGMEXEC;
38194 + if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
38195 + flags |= MF_PAX_RANDMMAP;
38196 + if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
38197 + flags |= MF_PAX_EMUTRAMP;
38198 + if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
38199 + flags |= MF_PAX_MPROTECT;
38201 + pax_set_flags(task, flags);
38207 +#ifdef CONFIG_SYSCTL
38208 +/* Eric Biederman likes breaking userland ABI and every inode-based security
38209 + system to save 35kb of memory */
38211 +/* we modify the passed in filename, but adjust it back before returning */
38212 +static struct acl_object_label *gr_lookup_by_name(char *name, unsigned int len)
38214 + struct name_entry *nmatch;
38215 + char *p, *lastp = NULL;
38216 + struct acl_object_label *obj = NULL, *tmp;
38217 + struct acl_subject_label *tmpsubj;
38220 + read_lock(&gr_inode_lock);
38222 + p = name + len - 1;
38224 + nmatch = lookup_name_entry(name);
38225 + if (lastp != NULL)
38228 + if (nmatch == NULL)
38229 + goto next_component;
38230 + tmpsubj = current->acl;
38232 + obj = lookup_acl_obj_label(nmatch->inode, nmatch->device, tmpsubj);
38233 + if (obj != NULL) {
38234 + tmp = obj->globbed;
38236 + if (!glob_match(tmp->filename, name)) {
38244 + } while ((tmpsubj = tmpsubj->parent_subject));
38250 + while (*p != '/')
38262 + read_unlock(&gr_inode_lock);
38263 + /* obj returned will always be non-null */
38267 +/* returns 0 when allowing, non-zero on error
38268 + op of 0 is used for readdir, so we don't log the names of hidden files
38271 +gr_handle_sysctl(const struct ctl_table *table, const int op)
38273 + struct ctl_table *tmp;
38274 + const char *proc_sys = "/proc/sys";
38276 + struct acl_object_label *obj;
38277 + unsigned short len = 0, pos = 0, depth = 0, i;
38281 + if (unlikely(!(gr_status & GR_READY)))
38284 + /* for now, ignore operations on non-sysctl entries if it's not a
38286 + if (table->child != NULL && op != 0)
38290 + /* it's only a read if it's an entry, read on dirs is for readdir */
38291 + if (op & MAY_READ)
38293 + if (op & MAY_WRITE)
38294 + mode |= GR_WRITE;
38296 + preempt_disable();
38298 + path = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
38300 + /* it's only a read/write if it's an actual entry, not a dir
38301 + (which are opened for readdir)
38304 + /* convert the requested sysctl entry into a pathname */
38306 + for (tmp = (struct ctl_table *)table; tmp != NULL; tmp = tmp->parent) {
38307 + len += strlen(tmp->procname);
38312 + if ((len + depth + strlen(proc_sys) + 1) > PAGE_SIZE) {
38317 + memset(path, 0, PAGE_SIZE);
38319 + memcpy(path, proc_sys, strlen(proc_sys));
38321 + pos += strlen(proc_sys);
38323 + for (; depth > 0; depth--) {
38326 + for (i = 1, tmp = (struct ctl_table *)table; tmp != NULL; tmp = tmp->parent) {
38327 + if (depth == i) {
38328 + memcpy(path + pos, tmp->procname,
38329 + strlen(tmp->procname));
38330 + pos += strlen(tmp->procname);
38336 + obj = gr_lookup_by_name(path, pos);
38337 + err = obj->mode & (mode | to_gr_audit(mode) | GR_SUPPRESS);
38339 + if (unlikely((current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) &&
38340 + ((err & mode) != mode))) {
38341 + __u32 new_mode = mode;
38343 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
38346 + gr_log_learn_sysctl(path, new_mode);
38347 + } else if (!(err & GR_FIND) && !(err & GR_SUPPRESS) && op != 0) {
38348 + gr_log_hidden_sysctl(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, path);
38350 + } else if (!(err & GR_FIND)) {
38352 + } else if (((err & mode) & ~GR_FIND) != (mode & ~GR_FIND) && !(err & GR_SUPPRESS)) {
38353 + gr_log_str4(GR_DONT_AUDIT, GR_SYSCTL_ACL_MSG, "denied",
38354 + path, (mode & GR_READ) ? " reading" : "",
38355 + (mode & GR_WRITE) ? " writing" : "");
38357 + } else if ((err & mode) != mode) {
38359 + } else if ((((err & mode) & ~GR_FIND) == (mode & ~GR_FIND)) && (err & GR_AUDITS)) {
38360 + gr_log_str4(GR_DO_AUDIT, GR_SYSCTL_ACL_MSG, "successful",
38361 + path, (mode & GR_READ) ? " reading" : "",
38362 + (mode & GR_WRITE) ? " writing" : "");
38368 + preempt_enable();
38375 +gr_handle_proc_ptrace(struct task_struct *task)
38377 + struct file *filp;
38378 + struct task_struct *tmp = task;
38379 + struct task_struct *curtemp = current;
38382 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
38383 + if (unlikely(!(gr_status & GR_READY)))
38387 + read_lock(&tasklist_lock);
38388 + read_lock(&grsec_exec_file_lock);
38389 + filp = task->exec_file;
38391 + while (tmp->pid > 0) {
38392 + if (tmp == curtemp)
38394 + tmp = tmp->real_parent;
38397 + if (!filp || (tmp->pid == 0 && ((grsec_enable_harden_ptrace && current_uid() && !(gr_status & GR_READY)) ||
38398 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
38399 + read_unlock(&grsec_exec_file_lock);
38400 + read_unlock(&tasklist_lock);
38404 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
38405 + if (!(gr_status & GR_READY)) {
38406 + read_unlock(&grsec_exec_file_lock);
38407 + read_unlock(&tasklist_lock);
38412 + retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
38413 + read_unlock(&grsec_exec_file_lock);
38414 + read_unlock(&tasklist_lock);
38416 + if (retmode & GR_NOPTRACE)
38419 + if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
38420 + && (current->acl != task->acl || (current->acl != current->role->root_label
38421 + && current->pid != task->pid)))
38427 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
38429 + if (unlikely(!(gr_status & GR_READY)))
38432 + if (!(current->role->roletype & GR_ROLE_GOD))
38435 + seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
38436 + p->role->rolename, gr_task_roletype_to_char(p),
38437 + p->acl->filename);
38441 +gr_handle_ptrace(struct task_struct *task, const long request)
38443 + struct task_struct *tmp = task;
38444 + struct task_struct *curtemp = current;
38447 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
38448 + if (unlikely(!(gr_status & GR_READY)))
38452 + read_lock(&tasklist_lock);
38453 + while (tmp->pid > 0) {
38454 + if (tmp == curtemp)
38456 + tmp = tmp->real_parent;
38459 + if (tmp->pid == 0 && ((grsec_enable_harden_ptrace && current_uid() && !(gr_status & GR_READY)) ||
38460 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
38461 + read_unlock(&tasklist_lock);
38462 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
38465 + read_unlock(&tasklist_lock);
38467 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
38468 + if (!(gr_status & GR_READY))
38472 + read_lock(&grsec_exec_file_lock);
38473 + if (unlikely(!task->exec_file)) {
38474 + read_unlock(&grsec_exec_file_lock);
38478 + retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
38479 + read_unlock(&grsec_exec_file_lock);
38481 + if (retmode & GR_NOPTRACE) {
38482 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
38486 + if (retmode & GR_PTRACERD) {
38487 + switch (request) {
38488 + case PTRACE_POKETEXT:
38489 + case PTRACE_POKEDATA:
38490 + case PTRACE_POKEUSR:
38491 +#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
38492 + case PTRACE_SETREGS:
38493 + case PTRACE_SETFPREGS:
38496 + case PTRACE_SETFPXREGS:
38498 +#ifdef CONFIG_ALTIVEC
38499 + case PTRACE_SETVRREGS:
38505 + } else if (!(current->acl->mode & GR_POVERRIDE) &&
38506 + !(current->role->roletype & GR_ROLE_GOD) &&
38507 + (current->acl != task->acl)) {
38508 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
38515 +static int is_writable_mmap(const struct file *filp)
38517 + struct task_struct *task = current;
38518 + struct acl_object_label *obj, *obj2;
38520 + if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
38521 + !task->is_writable && S_ISREG(filp->f_path.dentry->d_inode->i_mode) && filp->f_path.mnt != shm_mnt) {
38522 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
38523 + obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
38524 + task->role->root_label);
38525 + if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
38526 + gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
38534 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
38538 + if (unlikely(!file || !(prot & PROT_EXEC)))
38541 + if (is_writable_mmap(file))
38545 + gr_search_file(file->f_path.dentry,
38546 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
38547 + file->f_path.mnt);
38549 + if (!gr_tpe_allow(file))
38552 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
38553 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
38555 + } else if (unlikely(!(mode & GR_EXEC))) {
38557 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
38558 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
38566 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
38570 + if (unlikely(!file || !(prot & PROT_EXEC)))
38573 + if (is_writable_mmap(file))
38577 + gr_search_file(file->f_path.dentry,
38578 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
38579 + file->f_path.mnt);
38581 + if (!gr_tpe_allow(file))
38584 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
38585 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
38587 + } else if (unlikely(!(mode & GR_EXEC))) {
38589 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
38590 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
38598 +gr_acl_handle_psacct(struct task_struct *task, const long code)
38600 + unsigned long runtime;
38601 + unsigned long cputime;
38602 + unsigned int wday, cday;
38606 + struct timespec timeval;
38608 + if (unlikely(!(gr_status & GR_READY) || !task->acl ||
38609 + !(task->acl->mode & GR_PROCACCT)))
38612 + do_posix_clock_monotonic_gettime(&timeval);
38613 + runtime = timeval.tv_sec - task->start_time.tv_sec;
38614 + wday = runtime / (3600 * 24);
38615 + runtime -= wday * (3600 * 24);
38616 + whr = runtime / 3600;
38617 + runtime -= whr * 3600;
38618 + wmin = runtime / 60;
38619 + runtime -= wmin * 60;
38622 + cputime = (task->utime + task->stime) / HZ;
38623 + cday = cputime / (3600 * 24);
38624 + cputime -= cday * (3600 * 24);
38625 + chr = cputime / 3600;
38626 + cputime -= chr * 3600;
38627 + cmin = cputime / 60;
38628 + cputime -= cmin * 60;
38631 + gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
38636 +void gr_set_kernel_label(struct task_struct *task)
38638 + if (gr_status & GR_READY) {
38639 + task->role = kernel_role;
38640 + task->acl = kernel_role->root_label;
38645 +#ifdef CONFIG_TASKSTATS
38646 +int gr_is_taskstats_denied(int pid)
38648 + struct task_struct *task;
38649 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
38650 + const struct cred *cred;
38654 + /* restrict taskstats viewing to un-chrooted root users
38655 + who have the 'view' subject flag if the RBAC system is enabled
38659 + read_lock(&tasklist_lock);
38660 + task = find_task_by_vpid(pid);
38662 +#ifdef CONFIG_GRKERNSEC_CHROOT
38663 + if (proc_is_chrooted(task))
38666 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
38667 + cred = __task_cred(task);
38668 +#ifdef CONFIG_GRKERNSEC_PROC_USER
38669 + if (cred->uid != 0)
38671 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
38672 + if (cred->uid != 0 && !groups_search(cred->group_info, CONFIG_GRKERNSEC_PROC_GID))
38676 + if (gr_status & GR_READY) {
38677 + if (!(task->acl->mode & GR_VIEW))
38683 + read_unlock(&tasklist_lock);
38684 + rcu_read_unlock();
38690 +/* AUXV entries are filled via a descendant of search_binary_handler
38691 + after we've already applied the subject for the target
38693 +int gr_acl_enable_at_secure(void)
38695 + if (unlikely(!(gr_status & GR_READY)))
38698 + if (current->acl->mode & GR_ATSECURE)
38704 +int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
38706 + struct task_struct *task = current;
38707 + struct dentry *dentry = file->f_path.dentry;
38708 + struct vfsmount *mnt = file->f_path.mnt;
38709 + struct acl_object_label *obj, *tmp;
38710 + struct acl_subject_label *subj;
38711 + unsigned int bufsize;
38715 + if (unlikely(!(gr_status & GR_READY)))
38718 + if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
38721 + /* ignore Eric Biederman */
38722 + if (IS_PRIVATE(dentry->d_inode))
38725 + subj = task->acl;
38727 + obj = lookup_acl_obj_label(ino, dentry->d_inode->i_sb->s_dev, subj);
38729 + return (obj->mode & GR_FIND) ? 1 : 0;
38730 + } while ((subj = subj->parent_subject));
38732 + /* this is purely an optimization since we're looking for an object
38733 + for the directory we're doing a readdir on
38734 + if it's possible for any globbed object to match the entry we're
38735 + filling into the directory, then the object we find here will be
38736 + an anchor point with attached globbed objects
38738 + obj = chk_obj_label_noglob(dentry, mnt, task->acl);
38739 + if (obj->globbed == NULL)
38740 + return (obj->mode & GR_FIND) ? 1 : 0;
38742 + is_not_root = ((obj->filename[0] == '/') &&
38743 + (obj->filename[1] == '\0')) ? 0 : 1;
38744 + bufsize = PAGE_SIZE - namelen - is_not_root;
38746 + /* check bufsize > PAGE_SIZE || bufsize == 0 */
38747 + if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
38750 + preempt_disable();
38751 + path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
38754 + bufsize = strlen(path);
38756 + /* if base is "/", don't append an additional slash */
38758 + *(path + bufsize) = '/';
38759 + memcpy(path + bufsize + is_not_root, name, namelen);
38760 + *(path + bufsize + namelen + is_not_root) = '\0';
38762 + tmp = obj->globbed;
38764 + if (!glob_match(tmp->filename, path)) {
38765 + preempt_enable();
38766 + return (tmp->mode & GR_FIND) ? 1 : 0;
38770 + preempt_enable();
38771 + return (obj->mode & GR_FIND) ? 1 : 0;
38774 +#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
38775 +EXPORT_SYMBOL(gr_acl_is_enabled);
38777 +EXPORT_SYMBOL(gr_learn_resource);
38778 +EXPORT_SYMBOL(gr_set_kernel_label);
38779 +#ifdef CONFIG_SECURITY
38780 +EXPORT_SYMBOL(gr_check_user_change);
38781 +EXPORT_SYMBOL(gr_check_group_change);
38784 diff -urNp linux-2.6.37/grsecurity/gracl_cap.c linux-2.6.37/grsecurity/gracl_cap.c
38785 --- linux-2.6.37/grsecurity/gracl_cap.c 1969-12-31 19:00:00.000000000 -0500
38786 +++ linux-2.6.37/grsecurity/gracl_cap.c 2011-01-17 02:41:02.000000000 -0500
38788 +#include <linux/kernel.h>
38789 +#include <linux/module.h>
38790 +#include <linux/sched.h>
38791 +#include <linux/gracl.h>
38792 +#include <linux/grsecurity.h>
38793 +#include <linux/grinternal.h>
38795 +static const char *captab_log[] = {
38797 + "CAP_DAC_OVERRIDE",
38798 + "CAP_DAC_READ_SEARCH",
38805 + "CAP_LINUX_IMMUTABLE",
38806 + "CAP_NET_BIND_SERVICE",
38807 + "CAP_NET_BROADCAST",
38812 + "CAP_SYS_MODULE",
38814 + "CAP_SYS_CHROOT",
38815 + "CAP_SYS_PTRACE",
38820 + "CAP_SYS_RESOURCE",
38822 + "CAP_SYS_TTY_CONFIG",
38825 + "CAP_AUDIT_WRITE",
38826 + "CAP_AUDIT_CONTROL",
38828 + "CAP_MAC_OVERRIDE",
38832 +EXPORT_SYMBOL(gr_is_capable);
38833 +EXPORT_SYMBOL(gr_is_capable_nolog);
38836 +gr_is_capable(const int cap)
38838 + struct task_struct *task = current;
38839 + const struct cred *cred = current_cred();
38840 + struct acl_subject_label *curracl;
38841 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
38842 + kernel_cap_t cap_audit = __cap_empty_set;
38844 + if (!gr_acl_is_enabled())
38847 + curracl = task->acl;
38849 + cap_drop = curracl->cap_lower;
38850 + cap_mask = curracl->cap_mask;
38851 + cap_audit = curracl->cap_invert_audit;
38853 + while ((curracl = curracl->parent_subject)) {
38854 + /* if the cap isn't specified in the current computed mask but is specified in the
38855 + current level subject, and is lowered in the current level subject, then add
38856 + it to the set of dropped capabilities
38857 + otherwise, add the current level subject's mask to the current computed mask
38859 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
38860 + cap_raise(cap_mask, cap);
38861 + if (cap_raised(curracl->cap_lower, cap))
38862 + cap_raise(cap_drop, cap);
38863 + if (cap_raised(curracl->cap_invert_audit, cap))
38864 + cap_raise(cap_audit, cap);
38868 + if (!cap_raised(cap_drop, cap)) {
38869 + if (cap_raised(cap_audit, cap))
38870 + gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
38874 + curracl = task->acl;
38876 + if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
38877 + && cap_raised(cred->cap_effective, cap)) {
38878 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
38879 + task->role->roletype, cred->uid,
38880 + cred->gid, task->exec_file ?
38881 + gr_to_filename(task->exec_file->f_path.dentry,
38882 + task->exec_file->f_path.mnt) : curracl->filename,
38883 + curracl->filename, 0UL,
38884 + 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
38888 + if ((cap >= 0) && (cap < (sizeof(captab_log)/sizeof(captab_log[0]))) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
38889 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
38894 +gr_is_capable_nolog(const int cap)
38896 + struct acl_subject_label *curracl;
38897 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
38899 + if (!gr_acl_is_enabled())
38902 + curracl = current->acl;
38904 + cap_drop = curracl->cap_lower;
38905 + cap_mask = curracl->cap_mask;
38907 + while ((curracl = curracl->parent_subject)) {
38908 + /* if the cap isn't specified in the current computed mask but is specified in the
38909 + current level subject, and is lowered in the current level subject, then add
38910 + it to the set of dropped capabilities
38911 + otherwise, add the current level subject's mask to the current computed mask
38913 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
38914 + cap_raise(cap_mask, cap);
38915 + if (cap_raised(curracl->cap_lower, cap))
38916 + cap_raise(cap_drop, cap);
38920 + if (!cap_raised(cap_drop, cap))
38926 diff -urNp linux-2.6.37/grsecurity/gracl_fs.c linux-2.6.37/grsecurity/gracl_fs.c
38927 --- linux-2.6.37/grsecurity/gracl_fs.c 1969-12-31 19:00:00.000000000 -0500
38928 +++ linux-2.6.37/grsecurity/gracl_fs.c 2011-01-17 02:41:02.000000000 -0500
38930 +#include <linux/kernel.h>
38931 +#include <linux/sched.h>
38932 +#include <linux/types.h>
38933 +#include <linux/fs.h>
38934 +#include <linux/file.h>
38935 +#include <linux/stat.h>
38936 +#include <linux/grsecurity.h>
38937 +#include <linux/grinternal.h>
38938 +#include <linux/gracl.h>
38941 +gr_acl_handle_hidden_file(const struct dentry * dentry,
38942 + const struct vfsmount * mnt)
38946 + if (unlikely(!dentry->d_inode))
38950 + gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
38952 + if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
38953 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
38955 + } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
38956 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
38958 + } else if (unlikely(!(mode & GR_FIND)))
38965 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
38968 + __u32 reqmode = GR_FIND;
38971 + if (unlikely(!dentry->d_inode))
38974 + if (unlikely(fmode & O_APPEND))
38975 + reqmode |= GR_APPEND;
38976 + else if (unlikely(fmode & FMODE_WRITE))
38977 + reqmode |= GR_WRITE;
38978 + if (likely((fmode & FMODE_READ) && !(fmode & O_DIRECTORY)))
38979 + reqmode |= GR_READ;
38980 + if ((fmode & FMODE_GREXEC) && (fmode & FMODE_EXEC))
38981 + reqmode &= ~GR_READ;
38983 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
38986 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
38987 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
38988 + reqmode & GR_READ ? " reading" : "",
38989 + reqmode & GR_WRITE ? " writing" : reqmode &
38990 + GR_APPEND ? " appending" : "");
38993 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
38995 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
38996 + reqmode & GR_READ ? " reading" : "",
38997 + reqmode & GR_WRITE ? " writing" : reqmode &
38998 + GR_APPEND ? " appending" : "");
39000 + } else if (unlikely((mode & reqmode) != reqmode))
39007 +gr_acl_handle_creat(const struct dentry * dentry,
39008 + const struct dentry * p_dentry,
39009 + const struct vfsmount * p_mnt, const int fmode,
39012 + __u32 reqmode = GR_WRITE | GR_CREATE;
39015 + if (unlikely(fmode & O_APPEND))
39016 + reqmode |= GR_APPEND;
39017 + if (unlikely((fmode & FMODE_READ) && !(fmode & O_DIRECTORY)))
39018 + reqmode |= GR_READ;
39019 + if (unlikely((fmode & O_CREAT) && (imode & (S_ISUID | S_ISGID))))
39020 + reqmode |= GR_SETID;
39023 + gr_check_create(dentry, p_dentry, p_mnt,
39024 + reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
39026 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
39027 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
39028 + reqmode & GR_READ ? " reading" : "",
39029 + reqmode & GR_WRITE ? " writing" : reqmode &
39030 + GR_APPEND ? " appending" : "");
39033 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
39035 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
39036 + reqmode & GR_READ ? " reading" : "",
39037 + reqmode & GR_WRITE ? " writing" : reqmode &
39038 + GR_APPEND ? " appending" : "");
39040 + } else if (unlikely((mode & reqmode) != reqmode))
39047 +gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
39050 + __u32 mode, reqmode = GR_FIND;
39052 + if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
39053 + reqmode |= GR_EXEC;
39054 + if (fmode & S_IWOTH)
39055 + reqmode |= GR_WRITE;
39056 + if (fmode & S_IROTH)
39057 + reqmode |= GR_READ;
39060 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
39063 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
39064 + gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
39065 + reqmode & GR_READ ? " reading" : "",
39066 + reqmode & GR_WRITE ? " writing" : "",
39067 + reqmode & GR_EXEC ? " executing" : "");
39070 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
39072 + gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
39073 + reqmode & GR_READ ? " reading" : "",
39074 + reqmode & GR_WRITE ? " writing" : "",
39075 + reqmode & GR_EXEC ? " executing" : "");
39077 + } else if (unlikely((mode & reqmode) != reqmode))
39083 +static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
39087 + mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
39089 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
39090 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
39092 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
39093 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
39095 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
39098 + return (reqmode);
39102 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
39104 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
39108 +gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
39110 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
39114 +gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
39116 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
39120 +gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
39122 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
39126 +gr_acl_handle_fchmod(const struct dentry *dentry, const struct vfsmount *mnt,
39129 + if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
39132 + if (unlikely((mode != (mode_t)-1) && (mode & (S_ISUID | S_ISGID)))) {
39133 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
39134 + GR_FCHMOD_ACL_MSG);
39136 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_FCHMOD_ACL_MSG);
39141 +gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
39144 + if (unlikely((mode != (mode_t)-1) && (mode & (S_ISUID | S_ISGID)))) {
39145 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
39146 + GR_CHMOD_ACL_MSG);
39148 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
39153 +gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
39155 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
39159 +gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
39161 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
39165 +gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
39167 + return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
39171 +gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
39173 + return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
39174 + GR_UNIXCONNECT_ACL_MSG);
39177 +/* hardlinks require at minimum create permission,
39178 + any additional privilege required is based on the
39179 + privilege of the file being linked to
39182 +gr_acl_handle_link(const struct dentry * new_dentry,
39183 + const struct dentry * parent_dentry,
39184 + const struct vfsmount * parent_mnt,
39185 + const struct dentry * old_dentry,
39186 + const struct vfsmount * old_mnt, const char *to)
39189 + __u32 needmode = GR_CREATE | GR_LINK;
39190 + __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
39193 + gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
39196 + if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
39197 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
39199 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
39200 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
39202 + } else if (unlikely((mode & needmode) != needmode))
39209 +gr_acl_handle_symlink(const struct dentry * new_dentry,
39210 + const struct dentry * parent_dentry,
39211 + const struct vfsmount * parent_mnt, const char *from)
39213 + __u32 needmode = GR_WRITE | GR_CREATE;
39217 + gr_check_create(new_dentry, parent_dentry, parent_mnt,
39218 + GR_CREATE | GR_AUDIT_CREATE |
39219 + GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
39221 + if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
39222 + gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
39224 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
39225 + gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
39227 + } else if (unlikely((mode & needmode) != needmode))
39230 + return (GR_WRITE | GR_CREATE);
39233 +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)
39237 + mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
39239 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
39240 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
39242 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
39243 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
39245 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
39248 + return (reqmode);
39252 +gr_acl_handle_mknod(const struct dentry * new_dentry,
39253 + const struct dentry * parent_dentry,
39254 + const struct vfsmount * parent_mnt,
39257 + __u32 reqmode = GR_WRITE | GR_CREATE;
39258 + if (unlikely(mode & (S_ISUID | S_ISGID)))
39259 + reqmode |= GR_SETID;
39261 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
39262 + reqmode, GR_MKNOD_ACL_MSG);
39266 +gr_acl_handle_mkdir(const struct dentry *new_dentry,
39267 + const struct dentry *parent_dentry,
39268 + const struct vfsmount *parent_mnt)
39270 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
39271 + GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
39274 +#define RENAME_CHECK_SUCCESS(old, new) \
39275 + (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
39276 + ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
39279 +gr_acl_handle_rename(struct dentry *new_dentry,
39280 + struct dentry *parent_dentry,
39281 + const struct vfsmount *parent_mnt,
39282 + struct dentry *old_dentry,
39283 + struct inode *old_parent_inode,
39284 + struct vfsmount *old_mnt, const char *newname)
39286 + __u32 comp1, comp2;
39289 + if (unlikely(!gr_acl_is_enabled()))
39292 + if (!new_dentry->d_inode) {
39293 + comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
39294 + GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
39295 + GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
39296 + comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
39297 + GR_DELETE | GR_AUDIT_DELETE |
39298 + GR_AUDIT_READ | GR_AUDIT_WRITE |
39299 + GR_SUPPRESS, old_mnt);
39301 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
39302 + GR_CREATE | GR_DELETE |
39303 + GR_AUDIT_CREATE | GR_AUDIT_DELETE |
39304 + GR_AUDIT_READ | GR_AUDIT_WRITE |
39305 + GR_SUPPRESS, parent_mnt);
39307 + gr_search_file(old_dentry,
39308 + GR_READ | GR_WRITE | GR_AUDIT_READ |
39309 + GR_DELETE | GR_AUDIT_DELETE |
39310 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
39313 + if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
39314 + ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
39315 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
39316 + else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
39317 + && !(comp2 & GR_SUPPRESS)) {
39318 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
39320 + } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
39327 +gr_acl_handle_exit(void)
39331 + struct file *exec_file;
39333 + if (unlikely(current->acl_sp_role && gr_acl_is_enabled())) {
39334 + id = current->acl_role_id;
39335 + rolename = current->role->rolename;
39337 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
39340 + write_lock(&grsec_exec_file_lock);
39341 + exec_file = current->exec_file;
39342 + current->exec_file = NULL;
39343 + write_unlock(&grsec_exec_file_lock);
39350 +gr_acl_handle_procpidmem(const struct task_struct *task)
39352 + if (unlikely(!gr_acl_is_enabled()))
39355 + if (task != current && task->acl->mode & GR_PROTPROCFD)
39360 diff -urNp linux-2.6.37/grsecurity/gracl_ip.c linux-2.6.37/grsecurity/gracl_ip.c
39361 --- linux-2.6.37/grsecurity/gracl_ip.c 1969-12-31 19:00:00.000000000 -0500
39362 +++ linux-2.6.37/grsecurity/gracl_ip.c 2011-01-17 02:41:02.000000000 -0500
39364 +#include <linux/kernel.h>
39365 +#include <asm/uaccess.h>
39366 +#include <asm/errno.h>
39367 +#include <net/sock.h>
39368 +#include <linux/file.h>
39369 +#include <linux/fs.h>
39370 +#include <linux/net.h>
39371 +#include <linux/in.h>
39372 +#include <linux/skbuff.h>
39373 +#include <linux/ip.h>
39374 +#include <linux/udp.h>
39375 +#include <linux/smp_lock.h>
39376 +#include <linux/types.h>
39377 +#include <linux/sched.h>
39378 +#include <linux/netdevice.h>
39379 +#include <linux/inetdevice.h>
39380 +#include <linux/gracl.h>
39381 +#include <linux/grsecurity.h>
39382 +#include <linux/grinternal.h>
39384 +#define GR_BIND 0x01
39385 +#define GR_CONNECT 0x02
39386 +#define GR_INVERT 0x04
39387 +#define GR_BINDOVERRIDE 0x08
39388 +#define GR_CONNECTOVERRIDE 0x10
39389 +#define GR_SOCK_FAMILY 0x20
39391 +static const char * gr_protocols[IPPROTO_MAX] = {
39392 + "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
39393 + "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
39394 + "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
39395 + "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
39396 + "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
39397 + "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
39398 + "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
39399 + "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
39400 + "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
39401 + "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
39402 + "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
39403 + "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
39404 + "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
39405 + "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
39406 + "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
39407 + "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
39408 + "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
39409 + "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
39410 + "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
39411 + "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
39412 + "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
39413 + "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
39414 + "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
39415 + "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
39416 + "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
39417 + "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
39418 + "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
39419 + "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
39420 + "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
39421 + "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
39422 + "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
39423 + "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
39426 +static const char * gr_socktypes[SOCK_MAX] = {
39427 + "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
39428 + "unknown:7", "unknown:8", "unknown:9", "packet"
39431 +static const char * gr_sockfamilies[AF_MAX+1] = {
39432 + "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
39433 + "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
39434 + "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "tipc", "bluetooth",
39435 + "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
39439 +gr_proto_to_name(unsigned char proto)
39441 + return gr_protocols[proto];
39445 +gr_socktype_to_name(unsigned char type)
39447 + return gr_socktypes[type];
39451 +gr_sockfamily_to_name(unsigned char family)
39453 + return gr_sockfamilies[family];
39457 +gr_search_socket(const int domain, const int type, const int protocol)
39459 + struct acl_subject_label *curr;
39460 + const struct cred *cred = current_cred();
39462 + if (unlikely(!gr_acl_is_enabled()))
39465 + if ((domain < 0) || (type < 0) || (protocol < 0) ||
39466 + (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
39467 + goto exit; // let the kernel handle it
39469 + curr = current->acl;
39471 + if (curr->sock_families[domain / 32] & (1 << (domain % 32))) {
39472 + /* the family is allowed, if this is PF_INET allow it only if
39473 + the extra sock type/protocol checks pass */
39474 + if (domain == PF_INET)
39478 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
39479 + __u32 fakeip = 0;
39480 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
39481 + current->role->roletype, cred->uid,
39482 + cred->gid, current->exec_file ?
39483 + gr_to_filename(current->exec_file->f_path.dentry,
39484 + current->exec_file->f_path.mnt) :
39485 + curr->filename, curr->filename,
39486 + &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
39487 + ¤t->signal->saved_ip);
39494 + /* the rest of this checking is for IPv4 only */
39498 + if ((curr->ip_type & (1 << type)) &&
39499 + (curr->ip_proto[protocol / 32] & (1 << (protocol % 32))))
39502 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
39503 + /* we don't place acls on raw sockets , and sometimes
39504 + dgram/ip sockets are opened for ioctl and not
39505 + bind/connect, so we'll fake a bind learn log */
39506 + if (type == SOCK_RAW || type == SOCK_PACKET) {
39507 + __u32 fakeip = 0;
39508 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
39509 + current->role->roletype, cred->uid,
39510 + cred->gid, current->exec_file ?
39511 + gr_to_filename(current->exec_file->f_path.dentry,
39512 + current->exec_file->f_path.mnt) :
39513 + curr->filename, curr->filename,
39514 + &fakeip, 0, type,
39515 + protocol, GR_CONNECT, ¤t->signal->saved_ip);
39516 + } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
39517 + __u32 fakeip = 0;
39518 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
39519 + current->role->roletype, cred->uid,
39520 + cred->gid, current->exec_file ?
39521 + gr_to_filename(current->exec_file->f_path.dentry,
39522 + current->exec_file->f_path.mnt) :
39523 + curr->filename, curr->filename,
39524 + &fakeip, 0, type,
39525 + protocol, GR_BIND, ¤t->signal->saved_ip);
39527 + /* we'll log when they use connect or bind */
39532 + if (domain == PF_INET)
39533 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
39534 + gr_socktype_to_name(type), gr_proto_to_name(protocol));
39536 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
39537 + gr_socktype_to_name(type), protocol);
39544 +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)
39546 + if ((ip->mode & mode) &&
39547 + (ip_port >= ip->low) &&
39548 + (ip_port <= ip->high) &&
39549 + ((ntohl(ip_addr) & our_netmask) ==
39550 + (ntohl(our_addr) & our_netmask))
39551 + && (ip->proto[protocol / 32] & (1 << (protocol % 32)))
39552 + && (ip->type & (1 << type))) {
39553 + if (ip->mode & GR_INVERT)
39554 + return 2; // specifically denied
39556 + return 1; // allowed
39559 + return 0; // not specifically allowed, may continue parsing
39563 +gr_search_connectbind(const int full_mode, struct sock *sk,
39564 + struct sockaddr_in *addr, const int type)
39566 + char iface[IFNAMSIZ] = {0};
39567 + struct acl_subject_label *curr;
39568 + struct acl_ip_label *ip;
39569 + struct inet_sock *isk;
39570 + struct net_device *dev;
39571 + struct in_device *idev;
39574 + int mode = full_mode & (GR_BIND | GR_CONNECT);
39575 + __u32 ip_addr = 0;
39577 + __u32 our_netmask;
39579 + __u16 ip_port = 0;
39580 + const struct cred *cred = current_cred();
39582 + if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
39585 + curr = current->acl;
39586 + isk = inet_sk(sk);
39588 + /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
39589 + if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
39590 + addr->sin_addr.s_addr = curr->inaddr_any_override;
39591 + if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
39592 + struct sockaddr_in saddr;
39595 + saddr.sin_family = AF_INET;
39596 + saddr.sin_addr.s_addr = curr->inaddr_any_override;
39597 + saddr.sin_port = isk->inet_sport;
39599 + err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
39603 + err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
39611 + ip_addr = addr->sin_addr.s_addr;
39612 + ip_port = ntohs(addr->sin_port);
39614 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
39615 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
39616 + current->role->roletype, cred->uid,
39617 + cred->gid, current->exec_file ?
39618 + gr_to_filename(current->exec_file->f_path.dentry,
39619 + current->exec_file->f_path.mnt) :
39620 + curr->filename, curr->filename,
39621 + &ip_addr, ip_port, type,
39622 + sk->sk_protocol, mode, ¤t->signal->saved_ip);
39626 + for (i = 0; i < curr->ip_num; i++) {
39627 + ip = *(curr->ips + i);
39628 + if (ip->iface != NULL) {
39629 + strncpy(iface, ip->iface, IFNAMSIZ - 1);
39630 + p = strchr(iface, ':');
39633 + dev = dev_get_by_name(sock_net(sk), iface);
39636 + idev = in_dev_get(dev);
39637 + if (idev == NULL) {
39643 + if (!strcmp(ip->iface, ifa->ifa_label)) {
39644 + our_addr = ifa->ifa_address;
39645 + our_netmask = 0xffffffff;
39646 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
39648 + rcu_read_unlock();
39649 + in_dev_put(idev);
39652 + } else if (ret == 2) {
39653 + rcu_read_unlock();
39654 + in_dev_put(idev);
39659 + } endfor_ifa(idev);
39660 + rcu_read_unlock();
39661 + in_dev_put(idev);
39664 + our_addr = ip->addr;
39665 + our_netmask = ip->netmask;
39666 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
39669 + else if (ret == 2)
39675 + if (mode == GR_BIND)
39676 + 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));
39677 + else if (mode == GR_CONNECT)
39678 + 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));
39684 +gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
39686 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
39690 +gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
39692 + return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
39695 +int gr_search_listen(struct socket *sock)
39697 + struct sock *sk = sock->sk;
39698 + struct sockaddr_in addr;
39700 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
39701 + addr.sin_port = inet_sk(sk)->inet_sport;
39703 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
39706 +int gr_search_accept(struct socket *sock)
39708 + struct sock *sk = sock->sk;
39709 + struct sockaddr_in addr;
39711 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
39712 + addr.sin_port = inet_sk(sk)->inet_sport;
39714 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
39718 +gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
39721 + return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
39723 + struct sockaddr_in sin;
39724 + const struct inet_sock *inet = inet_sk(sk);
39726 + sin.sin_addr.s_addr = inet->inet_daddr;
39727 + sin.sin_port = inet->inet_dport;
39729 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
39734 +gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
39736 + struct sockaddr_in sin;
39738 + if (unlikely(skb->len < sizeof (struct udphdr)))
39739 + return 0; // skip this packet
39741 + sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
39742 + sin.sin_port = udp_hdr(skb)->source;
39744 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
39746 diff -urNp linux-2.6.37/grsecurity/gracl_learn.c linux-2.6.37/grsecurity/gracl_learn.c
39747 --- linux-2.6.37/grsecurity/gracl_learn.c 1969-12-31 19:00:00.000000000 -0500
39748 +++ linux-2.6.37/grsecurity/gracl_learn.c 2011-01-17 02:41:02.000000000 -0500
39750 +#include <linux/kernel.h>
39751 +#include <linux/mm.h>
39752 +#include <linux/sched.h>
39753 +#include <linux/poll.h>
39754 +#include <linux/smp_lock.h>
39755 +#include <linux/string.h>
39756 +#include <linux/file.h>
39757 +#include <linux/types.h>
39758 +#include <linux/vmalloc.h>
39759 +#include <linux/grinternal.h>
39761 +extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
39762 + size_t count, loff_t *ppos);
39763 +extern int gr_acl_is_enabled(void);
39765 +static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
39766 +static int gr_learn_attached;
39768 +/* use a 512k buffer */
39769 +#define LEARN_BUFFER_SIZE (512 * 1024)
39771 +static DEFINE_SPINLOCK(gr_learn_lock);
39772 +static DEFINE_MUTEX(gr_learn_user_mutex);
39774 +/* we need to maintain two buffers, so that the kernel context of grlearn
39775 + uses a semaphore around the userspace copying, and the other kernel contexts
39776 + use a spinlock when copying into the buffer, since they cannot sleep
39778 +static char *learn_buffer;
39779 +static char *learn_buffer_user;
39780 +static int learn_buffer_len;
39781 +static int learn_buffer_user_len;
39784 +read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
39786 + DECLARE_WAITQUEUE(wait, current);
39787 + ssize_t retval = 0;
39789 + add_wait_queue(&learn_wait, &wait);
39790 + set_current_state(TASK_INTERRUPTIBLE);
39792 + mutex_lock(&gr_learn_user_mutex);
39793 + spin_lock(&gr_learn_lock);
39794 + if (learn_buffer_len)
39796 + spin_unlock(&gr_learn_lock);
39797 + mutex_unlock(&gr_learn_user_mutex);
39798 + if (file->f_flags & O_NONBLOCK) {
39799 + retval = -EAGAIN;
39802 + if (signal_pending(current)) {
39803 + retval = -ERESTARTSYS;
39810 + memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
39811 + learn_buffer_user_len = learn_buffer_len;
39812 + retval = learn_buffer_len;
39813 + learn_buffer_len = 0;
39815 + spin_unlock(&gr_learn_lock);
39817 + if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
39818 + retval = -EFAULT;
39820 + mutex_unlock(&gr_learn_user_mutex);
39822 + set_current_state(TASK_RUNNING);
39823 + remove_wait_queue(&learn_wait, &wait);
39827 +static unsigned int
39828 +poll_learn(struct file * file, poll_table * wait)
39830 + poll_wait(file, &learn_wait, wait);
39832 + if (learn_buffer_len)
39833 + return (POLLIN | POLLRDNORM);
39839 +gr_clear_learn_entries(void)
39843 + mutex_lock(&gr_learn_user_mutex);
39844 + if (learn_buffer != NULL) {
39845 + spin_lock(&gr_learn_lock);
39846 + tmp = learn_buffer;
39847 + learn_buffer = NULL;
39848 + spin_unlock(&gr_learn_lock);
39849 + vfree(learn_buffer);
39851 + if (learn_buffer_user != NULL) {
39852 + vfree(learn_buffer_user);
39853 + learn_buffer_user = NULL;
39855 + learn_buffer_len = 0;
39856 + mutex_unlock(&gr_learn_user_mutex);
39862 +gr_add_learn_entry(const char *fmt, ...)
39865 + unsigned int len;
39867 + if (!gr_learn_attached)
39870 + spin_lock(&gr_learn_lock);
39872 + /* leave a gap at the end so we know when it's "full" but don't have to
39873 + compute the exact length of the string we're trying to append
39875 + if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
39876 + spin_unlock(&gr_learn_lock);
39877 + wake_up_interruptible(&learn_wait);
39880 + if (learn_buffer == NULL) {
39881 + spin_unlock(&gr_learn_lock);
39885 + va_start(args, fmt);
39886 + len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
39889 + learn_buffer_len += len + 1;
39891 + spin_unlock(&gr_learn_lock);
39892 + wake_up_interruptible(&learn_wait);
39898 +open_learn(struct inode *inode, struct file *file)
39900 + if (file->f_mode & FMODE_READ && gr_learn_attached)
39902 + if (file->f_mode & FMODE_READ) {
39904 + mutex_lock(&gr_learn_user_mutex);
39905 + if (learn_buffer == NULL)
39906 + learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
39907 + if (learn_buffer_user == NULL)
39908 + learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
39909 + if (learn_buffer == NULL) {
39910 + retval = -ENOMEM;
39913 + if (learn_buffer_user == NULL) {
39914 + retval = -ENOMEM;
39917 + learn_buffer_len = 0;
39918 + learn_buffer_user_len = 0;
39919 + gr_learn_attached = 1;
39921 + mutex_unlock(&gr_learn_user_mutex);
39928 +close_learn(struct inode *inode, struct file *file)
39932 + if (file->f_mode & FMODE_READ) {
39933 + mutex_lock(&gr_learn_user_mutex);
39934 + if (learn_buffer != NULL) {
39935 + spin_lock(&gr_learn_lock);
39936 + tmp = learn_buffer;
39937 + learn_buffer = NULL;
39938 + spin_unlock(&gr_learn_lock);
39941 + if (learn_buffer_user != NULL) {
39942 + vfree(learn_buffer_user);
39943 + learn_buffer_user = NULL;
39945 + learn_buffer_len = 0;
39946 + learn_buffer_user_len = 0;
39947 + gr_learn_attached = 0;
39948 + mutex_unlock(&gr_learn_user_mutex);
39954 +const struct file_operations grsec_fops = {
39955 + .read = read_learn,
39956 + .write = write_grsec_handler,
39957 + .open = open_learn,
39958 + .release = close_learn,
39959 + .poll = poll_learn,
39961 diff -urNp linux-2.6.37/grsecurity/gracl_res.c linux-2.6.37/grsecurity/gracl_res.c
39962 --- linux-2.6.37/grsecurity/gracl_res.c 1969-12-31 19:00:00.000000000 -0500
39963 +++ linux-2.6.37/grsecurity/gracl_res.c 2011-01-17 02:41:02.000000000 -0500
39965 +#include <linux/kernel.h>
39966 +#include <linux/sched.h>
39967 +#include <linux/gracl.h>
39968 +#include <linux/grinternal.h>
39970 +static const char *restab_log[] = {
39971 + [RLIMIT_CPU] = "RLIMIT_CPU",
39972 + [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
39973 + [RLIMIT_DATA] = "RLIMIT_DATA",
39974 + [RLIMIT_STACK] = "RLIMIT_STACK",
39975 + [RLIMIT_CORE] = "RLIMIT_CORE",
39976 + [RLIMIT_RSS] = "RLIMIT_RSS",
39977 + [RLIMIT_NPROC] = "RLIMIT_NPROC",
39978 + [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
39979 + [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
39980 + [RLIMIT_AS] = "RLIMIT_AS",
39981 + [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
39982 + [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
39983 + [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
39984 + [RLIMIT_NICE] = "RLIMIT_NICE",
39985 + [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
39986 + [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
39987 + [GR_CRASH_RES] = "RLIMIT_CRASH"
39991 +gr_log_resource(const struct task_struct *task,
39992 + const int res, const unsigned long wanted, const int gt)
39994 + const struct cred *cred;
39995 + unsigned long rlim;
39997 + if (!gr_acl_is_enabled() && !grsec_resource_logging)
40000 + // not yet supported resource
40001 + if (unlikely(!restab_log[res]))
40004 + if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
40005 + rlim = task_rlimit_max(task, res);
40007 + rlim = task_rlimit(task, res);
40009 + if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
40013 + cred = __task_cred(task);
40015 + if (res == RLIMIT_NPROC &&
40016 + (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
40017 + cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
40018 + goto out_rcu_unlock;
40019 + else if (res == RLIMIT_MEMLOCK &&
40020 + cap_raised(cred->cap_effective, CAP_IPC_LOCK))
40021 + goto out_rcu_unlock;
40022 + else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
40023 + goto out_rcu_unlock;
40024 + rcu_read_unlock();
40026 + gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
40030 + rcu_read_unlock();
40033 diff -urNp linux-2.6.37/grsecurity/gracl_segv.c linux-2.6.37/grsecurity/gracl_segv.c
40034 --- linux-2.6.37/grsecurity/gracl_segv.c 1969-12-31 19:00:00.000000000 -0500
40035 +++ linux-2.6.37/grsecurity/gracl_segv.c 2011-01-17 02:41:02.000000000 -0500
40037 +#include <linux/kernel.h>
40038 +#include <linux/mm.h>
40039 +#include <asm/uaccess.h>
40040 +#include <asm/errno.h>
40041 +#include <asm/mman.h>
40042 +#include <net/sock.h>
40043 +#include <linux/file.h>
40044 +#include <linux/fs.h>
40045 +#include <linux/net.h>
40046 +#include <linux/in.h>
40047 +#include <linux/smp_lock.h>
40048 +#include <linux/slab.h>
40049 +#include <linux/types.h>
40050 +#include <linux/sched.h>
40051 +#include <linux/timer.h>
40052 +#include <linux/gracl.h>
40053 +#include <linux/grsecurity.h>
40054 +#include <linux/grinternal.h>
40056 +static struct crash_uid *uid_set;
40057 +static unsigned short uid_used;
40058 +static DEFINE_SPINLOCK(gr_uid_lock);
40059 +extern rwlock_t gr_inode_lock;
40060 +extern struct acl_subject_label *
40061 + lookup_acl_subj_label(const ino_t inode, const dev_t dev,
40062 + struct acl_role_label *role);
40063 +extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
40066 +gr_init_uidset(void)
40069 + kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
40072 + return uid_set ? 1 : 0;
40076 +gr_free_uidset(void)
40085 +gr_find_uid(const uid_t uid)
40087 + struct crash_uid *tmp = uid_set;
40089 + int low = 0, high = uid_used - 1, mid;
40091 + while (high >= low) {
40092 + mid = (low + high) >> 1;
40093 + buid = tmp[mid].uid;
40105 +static __inline__ void
40106 +gr_insertsort(void)
40108 + unsigned short i, j;
40109 + struct crash_uid index;
40111 + for (i = 1; i < uid_used; i++) {
40112 + index = uid_set[i];
40114 + while ((j > 0) && uid_set[j - 1].uid > index.uid) {
40115 + uid_set[j] = uid_set[j - 1];
40118 + uid_set[j] = index;
40124 +static __inline__ void
40125 +gr_insert_uid(const uid_t uid, const unsigned long expires)
40129 + if (uid_used == GR_UIDTABLE_MAX)
40132 + loc = gr_find_uid(uid);
40135 + uid_set[loc].expires = expires;
40139 + uid_set[uid_used].uid = uid;
40140 + uid_set[uid_used].expires = expires;
40149 +gr_remove_uid(const unsigned short loc)
40151 + unsigned short i;
40153 + for (i = loc + 1; i < uid_used; i++)
40154 + uid_set[i - 1] = uid_set[i];
40162 +gr_check_crash_uid(const uid_t uid)
40167 + if (unlikely(!gr_acl_is_enabled()))
40170 + spin_lock(&gr_uid_lock);
40171 + loc = gr_find_uid(uid);
40176 + if (time_before_eq(uid_set[loc].expires, get_seconds()))
40177 + gr_remove_uid(loc);
40182 + spin_unlock(&gr_uid_lock);
40186 +static __inline__ int
40187 +proc_is_setxid(const struct cred *cred)
40189 + if (cred->uid != cred->euid || cred->uid != cred->suid ||
40190 + cred->uid != cred->fsuid)
40192 + if (cred->gid != cred->egid || cred->gid != cred->sgid ||
40193 + cred->gid != cred->fsgid)
40198 +static __inline__ int
40199 +gr_fake_force_sig(int sig, struct task_struct *t)
40201 + unsigned long int flags;
40202 + int ret, blocked, ignored;
40203 + struct k_sigaction *action;
40205 + spin_lock_irqsave(&t->sighand->siglock, flags);
40206 + action = &t->sighand->action[sig-1];
40207 + ignored = action->sa.sa_handler == SIG_IGN;
40208 + blocked = sigismember(&t->blocked, sig);
40209 + if (blocked || ignored) {
40210 + action->sa.sa_handler = SIG_DFL;
40212 + sigdelset(&t->blocked, sig);
40213 + recalc_sigpending_and_wake(t);
40216 + if (action->sa.sa_handler == SIG_DFL)
40217 + t->signal->flags &= ~SIGNAL_UNKILLABLE;
40218 + ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
40220 + spin_unlock_irqrestore(&t->sighand->siglock, flags);
40226 +gr_handle_crash(struct task_struct *task, const int sig)
40228 + struct acl_subject_label *curr;
40229 + struct acl_subject_label *curr2;
40230 + struct task_struct *tsk, *tsk2;
40231 + const struct cred *cred;
40232 + const struct cred *cred2;
40234 + if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
40237 + if (unlikely(!gr_acl_is_enabled()))
40240 + curr = task->acl;
40242 + if (!(curr->resmask & (1 << GR_CRASH_RES)))
40245 + if (time_before_eq(curr->expires, get_seconds())) {
40246 + curr->expires = 0;
40247 + curr->crashes = 0;
40252 + if (!curr->expires)
40253 + curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
40255 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
40256 + time_after(curr->expires, get_seconds())) {
40258 + cred = __task_cred(task);
40259 + if (cred->uid && proc_is_setxid(cred)) {
40260 + gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
40261 + spin_lock(&gr_uid_lock);
40262 + gr_insert_uid(cred->uid, curr->expires);
40263 + spin_unlock(&gr_uid_lock);
40264 + curr->expires = 0;
40265 + curr->crashes = 0;
40266 + read_lock(&tasklist_lock);
40267 + do_each_thread(tsk2, tsk) {
40268 + cred2 = __task_cred(tsk);
40269 + if (tsk != task && cred2->uid == cred->uid)
40270 + gr_fake_force_sig(SIGKILL, tsk);
40271 + } while_each_thread(tsk2, tsk);
40272 + read_unlock(&tasklist_lock);
40274 + gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
40275 + read_lock(&tasklist_lock);
40276 + do_each_thread(tsk2, tsk) {
40277 + if (likely(tsk != task)) {
40278 + curr2 = tsk->acl;
40280 + if (curr2->device == curr->device &&
40281 + curr2->inode == curr->inode)
40282 + gr_fake_force_sig(SIGKILL, tsk);
40284 + } while_each_thread(tsk2, tsk);
40285 + read_unlock(&tasklist_lock);
40287 + rcu_read_unlock();
40294 +gr_check_crash_exec(const struct file *filp)
40296 + struct acl_subject_label *curr;
40298 + if (unlikely(!gr_acl_is_enabled()))
40301 + read_lock(&gr_inode_lock);
40302 + curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
40303 + filp->f_path.dentry->d_inode->i_sb->s_dev,
40305 + read_unlock(&gr_inode_lock);
40307 + if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) ||
40308 + (!curr->crashes && !curr->expires))
40311 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
40312 + time_after(curr->expires, get_seconds()))
40314 + else if (time_before_eq(curr->expires, get_seconds())) {
40315 + curr->crashes = 0;
40316 + curr->expires = 0;
40323 +gr_handle_alertkill(struct task_struct *task)
40325 + struct acl_subject_label *curracl;
40327 + struct task_struct *p, *p2;
40329 + if (unlikely(!gr_acl_is_enabled()))
40332 + curracl = task->acl;
40333 + curr_ip = task->signal->curr_ip;
40335 + if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
40336 + read_lock(&tasklist_lock);
40337 + do_each_thread(p2, p) {
40338 + if (p->signal->curr_ip == curr_ip)
40339 + gr_fake_force_sig(SIGKILL, p);
40340 + } while_each_thread(p2, p);
40341 + read_unlock(&tasklist_lock);
40342 + } else if (curracl->mode & GR_KILLPROC)
40343 + gr_fake_force_sig(SIGKILL, task);
40347 diff -urNp linux-2.6.37/grsecurity/gracl_shm.c linux-2.6.37/grsecurity/gracl_shm.c
40348 --- linux-2.6.37/grsecurity/gracl_shm.c 1969-12-31 19:00:00.000000000 -0500
40349 +++ linux-2.6.37/grsecurity/gracl_shm.c 2011-01-17 02:41:02.000000000 -0500
40351 +#include <linux/kernel.h>
40352 +#include <linux/mm.h>
40353 +#include <linux/sched.h>
40354 +#include <linux/file.h>
40355 +#include <linux/ipc.h>
40356 +#include <linux/gracl.h>
40357 +#include <linux/grsecurity.h>
40358 +#include <linux/grinternal.h>
40361 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
40362 + const time_t shm_createtime, const uid_t cuid, const int shmid)
40364 + struct task_struct *task;
40366 + if (!gr_acl_is_enabled())
40370 + read_lock(&tasklist_lock);
40372 + task = find_task_by_vpid(shm_cprid);
40374 + if (unlikely(!task))
40375 + task = find_task_by_vpid(shm_lapid);
40377 + if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
40378 + (task->pid == shm_lapid)) &&
40379 + (task->acl->mode & GR_PROTSHM) &&
40380 + (task->acl != current->acl))) {
40381 + read_unlock(&tasklist_lock);
40382 + rcu_read_unlock();
40383 + gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, cuid, shm_cprid, shmid);
40386 + read_unlock(&tasklist_lock);
40387 + rcu_read_unlock();
40391 diff -urNp linux-2.6.37/grsecurity/grsec_chdir.c linux-2.6.37/grsecurity/grsec_chdir.c
40392 --- linux-2.6.37/grsecurity/grsec_chdir.c 1969-12-31 19:00:00.000000000 -0500
40393 +++ linux-2.6.37/grsecurity/grsec_chdir.c 2011-01-17 02:41:02.000000000 -0500
40395 +#include <linux/kernel.h>
40396 +#include <linux/sched.h>
40397 +#include <linux/fs.h>
40398 +#include <linux/file.h>
40399 +#include <linux/grsecurity.h>
40400 +#include <linux/grinternal.h>
40403 +gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
40405 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
40406 + if ((grsec_enable_chdir && grsec_enable_group &&
40407 + in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
40408 + !grsec_enable_group)) {
40409 + gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
40414 diff -urNp linux-2.6.37/grsecurity/grsec_chroot.c linux-2.6.37/grsecurity/grsec_chroot.c
40415 --- linux-2.6.37/grsecurity/grsec_chroot.c 1969-12-31 19:00:00.000000000 -0500
40416 +++ linux-2.6.37/grsecurity/grsec_chroot.c 2011-01-17 02:41:02.000000000 -0500
40418 +#include <linux/kernel.h>
40419 +#include <linux/module.h>
40420 +#include <linux/sched.h>
40421 +#include <linux/file.h>
40422 +#include <linux/fs.h>
40423 +#include <linux/mount.h>
40424 +#include <linux/types.h>
40425 +#include <linux/pid_namespace.h>
40426 +#include <linux/grsecurity.h>
40427 +#include <linux/grinternal.h>
40429 +void gr_set_chroot_entries(struct task_struct *task, struct path *path)
40431 +#ifdef CONFIG_GRKERNSEC
40432 + if (task->pid > 1 && path->dentry != init_task.fs->root.dentry &&
40433 + path->dentry != task->nsproxy->mnt_ns->root->mnt_root)
40434 + task->gr_is_chrooted = 1;
40436 + task->gr_is_chrooted = 0;
40438 + task->gr_chroot_dentry = path->dentry;
40443 +void gr_clear_chroot_entries(struct task_struct *task)
40445 +#ifdef CONFIG_GRKERNSEC
40446 + task->gr_is_chrooted = 0;
40447 + task->gr_chroot_dentry = NULL;
40453 +gr_handle_chroot_unix(struct pid *pid)
40455 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
40456 + struct task_struct *p;
40458 + if (unlikely(!grsec_enable_chroot_unix))
40461 + if (likely(!proc_is_chrooted(current)))
40465 + read_lock(&tasklist_lock);
40466 + p = pid_task(pid, PIDTYPE_PID);
40467 + if (unlikely(!have_same_root(current, p))) {
40468 + read_unlock(&tasklist_lock);
40469 + rcu_read_unlock();
40470 + gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
40473 + read_unlock(&tasklist_lock);
40474 + rcu_read_unlock();
40480 +gr_handle_chroot_nice(void)
40482 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
40483 + if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
40484 + gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
40492 +gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
40494 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
40495 + if (grsec_enable_chroot_nice && (niceval < task_nice(p))
40496 + && proc_is_chrooted(current)) {
40497 + gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, p->pid);
40505 +gr_handle_chroot_rawio(const struct inode *inode)
40507 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
40508 + if (grsec_enable_chroot_caps && proc_is_chrooted(current) &&
40509 + inode && S_ISBLK(inode->i_mode) && !capable(CAP_SYS_RAWIO))
40516 +gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
40518 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
40519 + struct task_struct *p;
40521 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
40524 + read_lock(&tasklist_lock);
40525 + do_each_pid_task(pid, type, p) {
40526 + if (!have_same_root(current, p)) {
40530 + } while_each_pid_task(pid, type, p);
40532 + read_unlock(&tasklist_lock);
40539 +gr_pid_is_chrooted(struct task_struct *p)
40541 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
40542 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
40545 + if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
40546 + !have_same_root(current, p)) {
40553 +EXPORT_SYMBOL(gr_pid_is_chrooted);
40555 +#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
40556 +int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
40558 + struct dentry *dentry = (struct dentry *)u_dentry;
40559 + struct vfsmount *mnt = (struct vfsmount *)u_mnt;
40560 + struct path realroot, currentroot;
40561 + struct task_struct *reaper = &init_task;
40564 + get_fs_root(reaper->fs, &realroot);
40565 + get_fs_root(current->fs, ¤troot);
40567 + spin_lock(&dcache_lock);
40569 + if (unlikely((dentry == realroot.dentry && mnt == realroot.mnt)
40570 + || (dentry == currentroot.dentry && mnt == currentroot.mnt)))
40572 + if (unlikely(dentry == mnt->mnt_root || IS_ROOT(dentry))) {
40573 + if (mnt->mnt_parent == mnt)
40575 + dentry = mnt->mnt_mountpoint;
40576 + mnt = mnt->mnt_parent;
40579 + dentry = dentry->d_parent;
40581 + spin_unlock(&dcache_lock);
40583 + path_put(¤troot);
40585 + /* access is outside of chroot */
40586 + if (dentry == realroot.dentry && mnt == realroot.mnt)
40589 + path_put(&realroot);
40595 +gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
40597 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
40598 + if (!grsec_enable_chroot_fchdir)
40601 + if (!proc_is_chrooted(current))
40603 + else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
40604 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
40612 +gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
40613 + const time_t shm_createtime)
40615 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
40616 + struct pid *pid = NULL;
40617 + time_t starttime;
40619 + if (unlikely(!grsec_enable_chroot_shmat))
40622 + if (likely(!proc_is_chrooted(current)))
40626 + read_lock(&tasklist_lock);
40628 + pid = find_vpid(shm_cprid);
40630 + struct task_struct *p;
40631 + p = pid_task(pid, PIDTYPE_PID);
40632 + starttime = p->start_time.tv_sec;
40633 + if (unlikely(!have_same_root(current, p) &&
40634 + time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime))) {
40635 + read_unlock(&tasklist_lock);
40636 + rcu_read_unlock();
40637 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
40641 + pid = find_vpid(shm_lapid);
40643 + struct task_struct *p;
40644 + p = pid_task(pid, PIDTYPE_PID);
40645 + if (unlikely(!have_same_root(current, p))) {
40646 + read_unlock(&tasklist_lock);
40647 + rcu_read_unlock();
40648 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
40654 + read_unlock(&tasklist_lock);
40655 + rcu_read_unlock();
40661 +gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
40663 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
40664 + if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
40665 + gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
40671 +gr_handle_chroot_mknod(const struct dentry *dentry,
40672 + const struct vfsmount *mnt, const int mode)
40674 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
40675 + if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
40676 + proc_is_chrooted(current)) {
40677 + gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
40685 +gr_handle_chroot_mount(const struct dentry *dentry,
40686 + const struct vfsmount *mnt, const char *dev_name)
40688 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
40689 + if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
40690 + gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name, dentry, mnt);
40698 +gr_handle_chroot_pivot(void)
40700 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
40701 + if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
40702 + gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
40710 +gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
40712 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
40713 + if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
40714 + !gr_is_outside_chroot(dentry, mnt)) {
40715 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
40723 +gr_handle_chroot_caps(struct path *path)
40725 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
40726 + if (grsec_enable_chroot_caps && current->pid > 1 && current->fs != NULL &&
40727 + (init_task.fs->root.dentry != path->dentry) &&
40728 + (current->nsproxy->mnt_ns->root->mnt_root != path->dentry)) {
40730 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
40731 + const struct cred *old = current_cred();
40732 + struct cred *new = prepare_creds();
40736 + new->cap_permitted = cap_drop(old->cap_permitted,
40738 + new->cap_inheritable = cap_drop(old->cap_inheritable,
40740 + new->cap_effective = cap_drop(old->cap_effective,
40743 + commit_creds(new);
40752 +gr_handle_chroot_sysctl(const int op)
40754 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
40755 + if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
40756 + proc_is_chrooted(current))
40763 +gr_handle_chroot_chdir(struct path *path)
40765 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
40766 + if (grsec_enable_chroot_chdir)
40767 + set_fs_pwd(current->fs, path);
40773 +gr_handle_chroot_chmod(const struct dentry *dentry,
40774 + const struct vfsmount *mnt, const int mode)
40776 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
40777 + /* allow chmod +s on directories, but not files */
40778 + if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
40779 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
40780 + proc_is_chrooted(current)) {
40781 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
40788 +#ifdef CONFIG_SECURITY
40789 +EXPORT_SYMBOL(gr_handle_chroot_caps);
40791 diff -urNp linux-2.6.37/grsecurity/grsec_disabled.c linux-2.6.37/grsecurity/grsec_disabled.c
40792 --- linux-2.6.37/grsecurity/grsec_disabled.c 1969-12-31 19:00:00.000000000 -0500
40793 +++ linux-2.6.37/grsecurity/grsec_disabled.c 2011-01-17 02:41:02.000000000 -0500
40795 +#include <linux/kernel.h>
40796 +#include <linux/module.h>
40797 +#include <linux/sched.h>
40798 +#include <linux/file.h>
40799 +#include <linux/fs.h>
40800 +#include <linux/kdev_t.h>
40801 +#include <linux/net.h>
40802 +#include <linux/in.h>
40803 +#include <linux/ip.h>
40804 +#include <linux/skbuff.h>
40805 +#include <linux/sysctl.h>
40807 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
40809 +pax_set_initial_flags(struct linux_binprm *bprm)
40815 +#ifdef CONFIG_SYSCTL
40817 +gr_handle_sysctl(const struct ctl_table * table, const int op)
40823 +#ifdef CONFIG_TASKSTATS
40824 +int gr_is_taskstats_denied(int pid)
40831 +gr_acl_is_enabled(void)
40837 +gr_handle_rawio(const struct inode *inode)
40843 +gr_acl_handle_psacct(struct task_struct *task, const long code)
40849 +gr_handle_ptrace(struct task_struct *task, const long request)
40855 +gr_handle_proc_ptrace(struct task_struct *task)
40861 +gr_learn_resource(const struct task_struct *task,
40862 + const int res, const unsigned long wanted, const int gt)
40868 +gr_set_acls(const int type)
40874 +gr_check_hidden_task(const struct task_struct *tsk)
40880 +gr_check_protected_task(const struct task_struct *task)
40886 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
40892 +gr_copy_label(struct task_struct *tsk)
40898 +gr_set_pax_flags(struct task_struct *task)
40904 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
40905 + const int unsafe_share)
40911 +gr_handle_delete(const ino_t ino, const dev_t dev)
40917 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
40923 +gr_handle_crash(struct task_struct *task, const int sig)
40929 +gr_check_crash_exec(const struct file *filp)
40935 +gr_check_crash_uid(const uid_t uid)
40941 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
40942 + struct dentry *old_dentry,
40943 + struct dentry *new_dentry,
40944 + struct vfsmount *mnt, const __u8 replace)
40950 +gr_search_socket(const int family, const int type, const int protocol)
40956 +gr_search_connectbind(const int mode, const struct socket *sock,
40957 + const struct sockaddr_in *addr)
40963 +gr_is_capable(const int cap)
40969 +gr_is_capable_nolog(const int cap)
40975 +gr_handle_alertkill(struct task_struct *task)
40981 +gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
40987 +gr_acl_handle_hidden_file(const struct dentry * dentry,
40988 + const struct vfsmount * mnt)
40994 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
41001 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
41007 +gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
41013 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
41014 + unsigned int *vm_flags)
41020 +gr_acl_handle_truncate(const struct dentry * dentry,
41021 + const struct vfsmount * mnt)
41027 +gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
41033 +gr_acl_handle_access(const struct dentry * dentry,
41034 + const struct vfsmount * mnt, const int fmode)
41040 +gr_acl_handle_fchmod(const struct dentry * dentry, const struct vfsmount * mnt,
41047 +gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
41054 +gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
41060 +gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
41066 +grsecurity_init(void)
41072 +gr_acl_handle_mknod(const struct dentry * new_dentry,
41073 + const struct dentry * parent_dentry,
41074 + const struct vfsmount * parent_mnt,
41081 +gr_acl_handle_mkdir(const struct dentry * new_dentry,
41082 + const struct dentry * parent_dentry,
41083 + const struct vfsmount * parent_mnt)
41089 +gr_acl_handle_symlink(const struct dentry * new_dentry,
41090 + const struct dentry * parent_dentry,
41091 + const struct vfsmount * parent_mnt, const char *from)
41097 +gr_acl_handle_link(const struct dentry * new_dentry,
41098 + const struct dentry * parent_dentry,
41099 + const struct vfsmount * parent_mnt,
41100 + const struct dentry * old_dentry,
41101 + const struct vfsmount * old_mnt, const char *to)
41107 +gr_acl_handle_rename(const struct dentry *new_dentry,
41108 + const struct dentry *parent_dentry,
41109 + const struct vfsmount *parent_mnt,
41110 + const struct dentry *old_dentry,
41111 + const struct inode *old_parent_inode,
41112 + const struct vfsmount *old_mnt, const char *newname)
41118 +gr_acl_handle_filldir(const struct file *file, const char *name,
41119 + const int namelen, const ino_t ino)
41125 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
41126 + const time_t shm_createtime, const uid_t cuid, const int shmid)
41132 +gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
41138 +gr_search_accept(const struct socket *sock)
41144 +gr_search_listen(const struct socket *sock)
41150 +gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
41156 +gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
41162 +gr_acl_handle_creat(const struct dentry * dentry,
41163 + const struct dentry * p_dentry,
41164 + const struct vfsmount * p_mnt, const int fmode,
41171 +gr_acl_handle_exit(void)
41177 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
41183 +gr_set_role_label(const uid_t uid, const gid_t gid)
41189 +gr_acl_handle_procpidmem(const struct task_struct *task)
41195 +gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
41201 +gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
41207 +gr_set_kernel_label(struct task_struct *task)
41213 +gr_check_user_change(int real, int effective, int fs)
41219 +gr_check_group_change(int real, int effective, int fs)
41224 +int gr_acl_enable_at_secure(void)
41229 +EXPORT_SYMBOL(gr_is_capable);
41230 +EXPORT_SYMBOL(gr_is_capable_nolog);
41231 +EXPORT_SYMBOL(gr_learn_resource);
41232 +EXPORT_SYMBOL(gr_set_kernel_label);
41233 +#ifdef CONFIG_SECURITY
41234 +EXPORT_SYMBOL(gr_check_user_change);
41235 +EXPORT_SYMBOL(gr_check_group_change);
41237 diff -urNp linux-2.6.37/grsecurity/grsec_exec.c linux-2.6.37/grsecurity/grsec_exec.c
41238 --- linux-2.6.37/grsecurity/grsec_exec.c 1969-12-31 19:00:00.000000000 -0500
41239 +++ linux-2.6.37/grsecurity/grsec_exec.c 2011-01-17 02:41:02.000000000 -0500
41241 +#include <linux/kernel.h>
41242 +#include <linux/sched.h>
41243 +#include <linux/file.h>
41244 +#include <linux/binfmts.h>
41245 +#include <linux/smp_lock.h>
41246 +#include <linux/fs.h>
41247 +#include <linux/types.h>
41248 +#include <linux/grdefs.h>
41249 +#include <linux/grinternal.h>
41250 +#include <linux/capability.h>
41251 +#include <linux/compat.h>
41253 +#include <asm/uaccess.h>
41255 +#ifdef CONFIG_GRKERNSEC_EXECLOG
41256 +static char gr_exec_arg_buf[132];
41257 +static DEFINE_MUTEX(gr_exec_arg_mutex);
41261 +gr_handle_nproc(void)
41263 +#ifdef CONFIG_GRKERNSEC_EXECVE
41264 + const struct cred *cred = current_cred();
41265 + if (grsec_enable_execve && cred->user &&
41266 + (atomic_read(&cred->user->processes) > rlimit(RLIMIT_NPROC)) &&
41267 + !capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE)) {
41268 + gr_log_noargs(GR_DONT_AUDIT, GR_NPROC_MSG);
41276 +gr_handle_exec_args(struct linux_binprm *bprm, const char __user *const __user *argv)
41278 +#ifdef CONFIG_GRKERNSEC_EXECLOG
41279 + char *grarg = gr_exec_arg_buf;
41280 + unsigned int i, x, execlen = 0;
41283 + if (!((grsec_enable_execlog && grsec_enable_group &&
41284 + in_group_p(grsec_audit_gid))
41285 + || (grsec_enable_execlog && !grsec_enable_group)))
41288 + mutex_lock(&gr_exec_arg_mutex);
41289 + memset(grarg, 0, sizeof(gr_exec_arg_buf));
41291 + if (unlikely(argv == NULL))
41294 + for (i = 0; i < bprm->argc && execlen < 128; i++) {
41295 + const char __user *p;
41296 + unsigned int len;
41298 + if (copy_from_user(&p, argv + i, sizeof(p)))
41302 + len = strnlen_user(p, 128 - execlen);
41303 + if (len > 128 - execlen)
41304 + len = 128 - execlen;
41305 + else if (len > 0)
41307 + if (copy_from_user(grarg + execlen, p, len))
41310 + /* rewrite unprintable characters */
41311 + for (x = 0; x < len; x++) {
41312 + c = *(grarg + execlen + x);
41313 + if (c < 32 || c > 126)
41314 + *(grarg + execlen + x) = ' ';
41318 + *(grarg + execlen) = ' ';
41319 + *(grarg + execlen + 1) = '\0';
41324 + gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
41325 + bprm->file->f_path.mnt, grarg);
41326 + mutex_unlock(&gr_exec_arg_mutex);
41331 +#ifdef CONFIG_COMPAT
41333 +gr_handle_exec_args_compat(struct linux_binprm *bprm, compat_uptr_t __user *argv)
41335 +#ifdef CONFIG_GRKERNSEC_EXECLOG
41336 + char *grarg = gr_exec_arg_buf;
41337 + unsigned int i, x, execlen = 0;
41340 + if (!((grsec_enable_execlog && grsec_enable_group &&
41341 + in_group_p(grsec_audit_gid))
41342 + || (grsec_enable_execlog && !grsec_enable_group)))
41345 + mutex_lock(&gr_exec_arg_mutex);
41346 + memset(grarg, 0, sizeof(gr_exec_arg_buf));
41348 + if (unlikely(argv == NULL))
41351 + for (i = 0; i < bprm->argc && execlen < 128; i++) {
41353 + unsigned int len;
41355 + if (get_user(p, argv + i))
41357 + len = strnlen_user(compat_ptr(p), 128 - execlen);
41358 + if (len > 128 - execlen)
41359 + len = 128 - execlen;
41360 + else if (len > 0)
41364 + if (copy_from_user(grarg + execlen, compat_ptr(p), len))
41367 + /* rewrite unprintable characters */
41368 + for (x = 0; x < len; x++) {
41369 + c = *(grarg + execlen + x);
41370 + if (c < 32 || c > 126)
41371 + *(grarg + execlen + x) = ' ';
41375 + *(grarg + execlen) = ' ';
41376 + *(grarg + execlen + 1) = '\0';
41381 + gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
41382 + bprm->file->f_path.mnt, grarg);
41383 + mutex_unlock(&gr_exec_arg_mutex);
41388 diff -urNp linux-2.6.37/grsecurity/grsec_fifo.c linux-2.6.37/grsecurity/grsec_fifo.c
41389 --- linux-2.6.37/grsecurity/grsec_fifo.c 1969-12-31 19:00:00.000000000 -0500
41390 +++ linux-2.6.37/grsecurity/grsec_fifo.c 2011-01-17 02:41:02.000000000 -0500
41392 +#include <linux/kernel.h>
41393 +#include <linux/sched.h>
41394 +#include <linux/fs.h>
41395 +#include <linux/file.h>
41396 +#include <linux/grinternal.h>
41399 +gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
41400 + const struct dentry *dir, const int flag, const int acc_mode)
41402 +#ifdef CONFIG_GRKERNSEC_FIFO
41403 + const struct cred *cred = current_cred();
41405 + if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
41406 + !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
41407 + (dentry->d_inode->i_uid != dir->d_inode->i_uid) &&
41408 + (cred->fsuid != dentry->d_inode->i_uid)) {
41409 + if (!generic_permission(dentry->d_inode, acc_mode, NULL))
41410 + gr_log_fs_int2(GR_DONT_AUDIT, GR_FIFO_MSG, dentry, mnt, dentry->d_inode->i_uid, dentry->d_inode->i_gid);
41416 diff -urNp linux-2.6.37/grsecurity/grsec_fork.c linux-2.6.37/grsecurity/grsec_fork.c
41417 --- linux-2.6.37/grsecurity/grsec_fork.c 1969-12-31 19:00:00.000000000 -0500
41418 +++ linux-2.6.37/grsecurity/grsec_fork.c 2011-01-17 02:41:02.000000000 -0500
41420 +#include <linux/kernel.h>
41421 +#include <linux/sched.h>
41422 +#include <linux/grsecurity.h>
41423 +#include <linux/grinternal.h>
41424 +#include <linux/errno.h>
41427 +gr_log_forkfail(const int retval)
41429 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
41430 + if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
41431 + switch (retval) {
41433 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
41436 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
41443 diff -urNp linux-2.6.37/grsecurity/grsec_init.c linux-2.6.37/grsecurity/grsec_init.c
41444 --- linux-2.6.37/grsecurity/grsec_init.c 1969-12-31 19:00:00.000000000 -0500
41445 +++ linux-2.6.37/grsecurity/grsec_init.c 2011-01-17 02:41:02.000000000 -0500
41447 +#include <linux/kernel.h>
41448 +#include <linux/sched.h>
41449 +#include <linux/mm.h>
41450 +#include <linux/smp_lock.h>
41451 +#include <linux/gracl.h>
41452 +#include <linux/slab.h>
41453 +#include <linux/vmalloc.h>
41454 +#include <linux/percpu.h>
41455 +#include <linux/module.h>
41457 +int grsec_enable_link;
41458 +int grsec_enable_dmesg;
41459 +int grsec_enable_harden_ptrace;
41460 +int grsec_enable_fifo;
41461 +int grsec_enable_execve;
41462 +int grsec_enable_execlog;
41463 +int grsec_enable_signal;
41464 +int grsec_enable_forkfail;
41465 +int grsec_enable_audit_ptrace;
41466 +int grsec_enable_time;
41467 +int grsec_enable_audit_textrel;
41468 +int grsec_enable_group;
41469 +int grsec_audit_gid;
41470 +int grsec_enable_chdir;
41471 +int grsec_enable_mount;
41472 +int grsec_enable_rofs;
41473 +int grsec_enable_chroot_findtask;
41474 +int grsec_enable_chroot_mount;
41475 +int grsec_enable_chroot_shmat;
41476 +int grsec_enable_chroot_fchdir;
41477 +int grsec_enable_chroot_double;
41478 +int grsec_enable_chroot_pivot;
41479 +int grsec_enable_chroot_chdir;
41480 +int grsec_enable_chroot_chmod;
41481 +int grsec_enable_chroot_mknod;
41482 +int grsec_enable_chroot_nice;
41483 +int grsec_enable_chroot_execlog;
41484 +int grsec_enable_chroot_caps;
41485 +int grsec_enable_chroot_sysctl;
41486 +int grsec_enable_chroot_unix;
41487 +int grsec_enable_tpe;
41488 +int grsec_tpe_gid;
41489 +int grsec_enable_blackhole;
41490 +#ifdef CONFIG_IPV6_MODULE
41491 +EXPORT_SYMBOL(grsec_enable_blackhole);
41493 +int grsec_lastack_retries;
41494 +int grsec_enable_tpe_all;
41495 +int grsec_enable_tpe_invert;
41496 +int grsec_enable_socket_all;
41497 +int grsec_socket_all_gid;
41498 +int grsec_enable_socket_client;
41499 +int grsec_socket_client_gid;
41500 +int grsec_enable_socket_server;
41501 +int grsec_socket_server_gid;
41502 +int grsec_resource_logging;
41503 +int grsec_disable_privio;
41504 +int grsec_enable_log_rwxmaps;
41507 +DEFINE_SPINLOCK(grsec_alert_lock);
41508 +unsigned long grsec_alert_wtime = 0;
41509 +unsigned long grsec_alert_fyet = 0;
41511 +DEFINE_SPINLOCK(grsec_audit_lock);
41513 +DEFINE_RWLOCK(grsec_exec_file_lock);
41515 +char *gr_shared_page[4];
41517 +char *gr_alert_log_fmt;
41518 +char *gr_audit_log_fmt;
41519 +char *gr_alert_log_buf;
41520 +char *gr_audit_log_buf;
41522 +extern struct gr_arg *gr_usermode;
41523 +extern unsigned char *gr_system_salt;
41524 +extern unsigned char *gr_system_sum;
41527 +grsecurity_init(void)
41530 + /* create the per-cpu shared pages */
41533 + memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
41536 + for (j = 0; j < 4; j++) {
41537 + gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
41538 + if (gr_shared_page[j] == NULL) {
41539 + panic("Unable to allocate grsecurity shared page");
41544 + /* allocate log buffers */
41545 + gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
41546 + if (!gr_alert_log_fmt) {
41547 + panic("Unable to allocate grsecurity alert log format buffer");
41550 + gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
41551 + if (!gr_audit_log_fmt) {
41552 + panic("Unable to allocate grsecurity audit log format buffer");
41555 + gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
41556 + if (!gr_alert_log_buf) {
41557 + panic("Unable to allocate grsecurity alert log buffer");
41560 + gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
41561 + if (!gr_audit_log_buf) {
41562 + panic("Unable to allocate grsecurity audit log buffer");
41566 + /* allocate memory for authentication structure */
41567 + gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
41568 + gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
41569 + gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
41571 + if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
41572 + panic("Unable to allocate grsecurity authentication structure");
41577 +#ifdef CONFIG_GRKERNSEC_IO
41578 +#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
41579 + grsec_disable_privio = 1;
41580 +#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
41581 + grsec_disable_privio = 1;
41583 + grsec_disable_privio = 0;
41587 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
41588 + /* for backward compatibility, tpe_invert always defaults to on if
41589 + enabled in the kernel
41591 + grsec_enable_tpe_invert = 1;
41594 +#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
41595 +#ifndef CONFIG_GRKERNSEC_SYSCTL
41599 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
41600 + grsec_enable_audit_textrel = 1;
41602 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
41603 + grsec_enable_log_rwxmaps = 1;
41605 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
41606 + grsec_enable_group = 1;
41607 + grsec_audit_gid = CONFIG_GRKERNSEC_AUDIT_GID;
41609 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
41610 + grsec_enable_chdir = 1;
41612 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
41613 + grsec_enable_harden_ptrace = 1;
41615 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
41616 + grsec_enable_mount = 1;
41618 +#ifdef CONFIG_GRKERNSEC_LINK
41619 + grsec_enable_link = 1;
41621 +#ifdef CONFIG_GRKERNSEC_DMESG
41622 + grsec_enable_dmesg = 1;
41624 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
41625 + grsec_enable_blackhole = 1;
41626 + grsec_lastack_retries = 4;
41628 +#ifdef CONFIG_GRKERNSEC_FIFO
41629 + grsec_enable_fifo = 1;
41631 +#ifdef CONFIG_GRKERNSEC_EXECVE
41632 + grsec_enable_execve = 1;
41634 +#ifdef CONFIG_GRKERNSEC_EXECLOG
41635 + grsec_enable_execlog = 1;
41637 +#ifdef CONFIG_GRKERNSEC_SIGNAL
41638 + grsec_enable_signal = 1;
41640 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
41641 + grsec_enable_forkfail = 1;
41643 +#ifdef CONFIG_GRKERNSEC_TIME
41644 + grsec_enable_time = 1;
41646 +#ifdef CONFIG_GRKERNSEC_RESLOG
41647 + grsec_resource_logging = 1;
41649 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
41650 + grsec_enable_chroot_findtask = 1;
41652 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
41653 + grsec_enable_chroot_unix = 1;
41655 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
41656 + grsec_enable_chroot_mount = 1;
41658 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
41659 + grsec_enable_chroot_fchdir = 1;
41661 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
41662 + grsec_enable_chroot_shmat = 1;
41664 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
41665 + grsec_enable_audit_ptrace = 1;
41667 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
41668 + grsec_enable_chroot_double = 1;
41670 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
41671 + grsec_enable_chroot_pivot = 1;
41673 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
41674 + grsec_enable_chroot_chdir = 1;
41676 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
41677 + grsec_enable_chroot_chmod = 1;
41679 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
41680 + grsec_enable_chroot_mknod = 1;
41682 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
41683 + grsec_enable_chroot_nice = 1;
41685 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
41686 + grsec_enable_chroot_execlog = 1;
41688 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
41689 + grsec_enable_chroot_caps = 1;
41691 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
41692 + grsec_enable_chroot_sysctl = 1;
41694 +#ifdef CONFIG_GRKERNSEC_TPE
41695 + grsec_enable_tpe = 1;
41696 + grsec_tpe_gid = CONFIG_GRKERNSEC_TPE_GID;
41697 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
41698 + grsec_enable_tpe_all = 1;
41701 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
41702 + grsec_enable_socket_all = 1;
41703 + grsec_socket_all_gid = CONFIG_GRKERNSEC_SOCKET_ALL_GID;
41705 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
41706 + grsec_enable_socket_client = 1;
41707 + grsec_socket_client_gid = CONFIG_GRKERNSEC_SOCKET_CLIENT_GID;
41709 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
41710 + grsec_enable_socket_server = 1;
41711 + grsec_socket_server_gid = CONFIG_GRKERNSEC_SOCKET_SERVER_GID;
41717 diff -urNp linux-2.6.37/grsecurity/grsec_link.c linux-2.6.37/grsecurity/grsec_link.c
41718 --- linux-2.6.37/grsecurity/grsec_link.c 1969-12-31 19:00:00.000000000 -0500
41719 +++ linux-2.6.37/grsecurity/grsec_link.c 2011-01-17 02:41:02.000000000 -0500
41721 +#include <linux/kernel.h>
41722 +#include <linux/sched.h>
41723 +#include <linux/fs.h>
41724 +#include <linux/file.h>
41725 +#include <linux/grinternal.h>
41728 +gr_handle_follow_link(const struct inode *parent,
41729 + const struct inode *inode,
41730 + const struct dentry *dentry, const struct vfsmount *mnt)
41732 +#ifdef CONFIG_GRKERNSEC_LINK
41733 + const struct cred *cred = current_cred();
41735 + if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
41736 + (parent->i_mode & S_ISVTX) && (parent->i_uid != inode->i_uid) &&
41737 + (parent->i_mode & S_IWOTH) && (cred->fsuid != inode->i_uid)) {
41738 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
41746 +gr_handle_hardlink(const struct dentry *dentry,
41747 + const struct vfsmount *mnt,
41748 + struct inode *inode, const int mode, const char *to)
41750 +#ifdef CONFIG_GRKERNSEC_LINK
41751 + const struct cred *cred = current_cred();
41753 + if (grsec_enable_link && cred->fsuid != inode->i_uid &&
41754 + (!S_ISREG(mode) || (mode & S_ISUID) ||
41755 + ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP)) ||
41756 + (generic_permission(inode, MAY_READ | MAY_WRITE, NULL))) &&
41757 + !capable(CAP_FOWNER) && cred->uid) {
41758 + gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to);
41764 diff -urNp linux-2.6.37/grsecurity/grsec_log.c linux-2.6.37/grsecurity/grsec_log.c
41765 --- linux-2.6.37/grsecurity/grsec_log.c 1969-12-31 19:00:00.000000000 -0500
41766 +++ linux-2.6.37/grsecurity/grsec_log.c 2011-01-17 02:41:02.000000000 -0500
41768 +#include <linux/kernel.h>
41769 +#include <linux/sched.h>
41770 +#include <linux/file.h>
41771 +#include <linux/tty.h>
41772 +#include <linux/fs.h>
41773 +#include <linux/grinternal.h>
41775 +#ifdef CONFIG_TREE_PREEMPT_RCU
41776 +#define DISABLE_PREEMPT() preempt_disable()
41777 +#define ENABLE_PREEMPT() preempt_enable()
41779 +#define DISABLE_PREEMPT()
41780 +#define ENABLE_PREEMPT()
41783 +#define BEGIN_LOCKS(x) \
41784 + DISABLE_PREEMPT(); \
41785 + rcu_read_lock(); \
41786 + read_lock(&tasklist_lock); \
41787 + read_lock(&grsec_exec_file_lock); \
41788 + if (x != GR_DO_AUDIT) \
41789 + spin_lock(&grsec_alert_lock); \
41791 + spin_lock(&grsec_audit_lock)
41793 +#define END_LOCKS(x) \
41794 + if (x != GR_DO_AUDIT) \
41795 + spin_unlock(&grsec_alert_lock); \
41797 + spin_unlock(&grsec_audit_lock); \
41798 + read_unlock(&grsec_exec_file_lock); \
41799 + read_unlock(&tasklist_lock); \
41800 + rcu_read_unlock(); \
41801 + ENABLE_PREEMPT(); \
41802 + if (x == GR_DONT_AUDIT) \
41803 + gr_handle_alertkill(current)
41810 +extern char *gr_alert_log_fmt;
41811 +extern char *gr_audit_log_fmt;
41812 +extern char *gr_alert_log_buf;
41813 +extern char *gr_audit_log_buf;
41815 +static int gr_log_start(int audit)
41817 + char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
41818 + char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
41819 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
41821 + if (audit == GR_DO_AUDIT)
41824 + if (!grsec_alert_wtime || jiffies - grsec_alert_wtime > CONFIG_GRKERNSEC_FLOODTIME * HZ) {
41825 + grsec_alert_wtime = jiffies;
41826 + grsec_alert_fyet = 0;
41827 + } else if ((jiffies - grsec_alert_wtime < CONFIG_GRKERNSEC_FLOODTIME * HZ) && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
41828 + grsec_alert_fyet++;
41829 + } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
41830 + grsec_alert_wtime = jiffies;
41831 + grsec_alert_fyet++;
41832 + printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
41834 + } else return FLOODING;
41837 + memset(buf, 0, PAGE_SIZE);
41838 + if (current->signal->curr_ip && gr_acl_is_enabled()) {
41839 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
41840 + snprintf(buf, PAGE_SIZE - 1, fmt, ¤t->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
41841 + } else if (current->signal->curr_ip) {
41842 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
41843 + snprintf(buf, PAGE_SIZE - 1, fmt, ¤t->signal->curr_ip);
41844 + } else if (gr_acl_is_enabled()) {
41845 + sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
41846 + snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
41848 + sprintf(fmt, "%s%s", loglevel, "grsec: ");
41849 + strcpy(buf, fmt);
41852 + return NO_FLOODING;
41855 +static void gr_log_middle(int audit, const char *msg, va_list ap)
41856 + __attribute__ ((format (printf, 2, 0)));
41858 +static void gr_log_middle(int audit, const char *msg, va_list ap)
41860 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
41861 + unsigned int len = strlen(buf);
41863 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
41868 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
41869 + __attribute__ ((format (printf, 2, 3)));
41871 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
41873 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
41874 + unsigned int len = strlen(buf);
41877 + va_start(ap, msg);
41878 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
41884 +static void gr_log_end(int audit)
41886 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
41887 + unsigned int len = strlen(buf);
41889 + snprintf(buf + len, PAGE_SIZE - len - 1, DEFAULTSECMSG, DEFAULTSECARGS(current, current_cred(), __task_cred(current->real_parent)));
41890 + printk("%s\n", buf);
41895 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
41898 + char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
41899 + char *str1, *str2, *str3;
41902 + unsigned long ulong1, ulong2;
41903 + struct dentry *dentry;
41904 + struct vfsmount *mnt;
41905 + struct file *file;
41906 + struct task_struct *task;
41907 + const struct cred *cred, *pcred;
41910 + BEGIN_LOCKS(audit);
41911 + logtype = gr_log_start(audit);
41912 + if (logtype == FLOODING) {
41913 + END_LOCKS(audit);
41916 + va_start(ap, argtypes);
41917 + switch (argtypes) {
41918 + case GR_TTYSNIFF:
41919 + task = va_arg(ap, struct task_struct *);
41920 + 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);
41922 + case GR_SYSCTL_HIDDEN:
41923 + str1 = va_arg(ap, char *);
41924 + gr_log_middle_varargs(audit, msg, result, str1);
41927 + dentry = va_arg(ap, struct dentry *);
41928 + mnt = va_arg(ap, struct vfsmount *);
41929 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
41931 + case GR_RBAC_STR:
41932 + dentry = va_arg(ap, struct dentry *);
41933 + mnt = va_arg(ap, struct vfsmount *);
41934 + str1 = va_arg(ap, char *);
41935 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
41937 + case GR_STR_RBAC:
41938 + str1 = va_arg(ap, char *);
41939 + dentry = va_arg(ap, struct dentry *);
41940 + mnt = va_arg(ap, struct vfsmount *);
41941 + gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
41943 + case GR_RBAC_MODE2:
41944 + dentry = va_arg(ap, struct dentry *);
41945 + mnt = va_arg(ap, struct vfsmount *);
41946 + str1 = va_arg(ap, char *);
41947 + str2 = va_arg(ap, char *);
41948 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
41950 + case GR_RBAC_MODE3:
41951 + dentry = va_arg(ap, struct dentry *);
41952 + mnt = va_arg(ap, struct vfsmount *);
41953 + str1 = va_arg(ap, char *);
41954 + str2 = va_arg(ap, char *);
41955 + str3 = va_arg(ap, char *);
41956 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
41958 + case GR_FILENAME:
41959 + dentry = va_arg(ap, struct dentry *);
41960 + mnt = va_arg(ap, struct vfsmount *);
41961 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
41963 + case GR_STR_FILENAME:
41964 + str1 = va_arg(ap, char *);
41965 + dentry = va_arg(ap, struct dentry *);
41966 + mnt = va_arg(ap, struct vfsmount *);
41967 + gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
41969 + case GR_FILENAME_STR:
41970 + dentry = va_arg(ap, struct dentry *);
41971 + mnt = va_arg(ap, struct vfsmount *);
41972 + str1 = va_arg(ap, char *);
41973 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
41975 + case GR_FILENAME_TWO_INT:
41976 + dentry = va_arg(ap, struct dentry *);
41977 + mnt = va_arg(ap, struct vfsmount *);
41978 + num1 = va_arg(ap, int);
41979 + num2 = va_arg(ap, int);
41980 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
41982 + case GR_FILENAME_TWO_INT_STR:
41983 + dentry = va_arg(ap, struct dentry *);
41984 + mnt = va_arg(ap, struct vfsmount *);
41985 + num1 = va_arg(ap, int);
41986 + num2 = va_arg(ap, int);
41987 + str1 = va_arg(ap, char *);
41988 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
41991 + file = va_arg(ap, struct file *);
41992 + ulong1 = va_arg(ap, unsigned long);
41993 + ulong2 = va_arg(ap, unsigned long);
41994 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
41997 + task = va_arg(ap, struct task_struct *);
41998 + 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);
42000 + case GR_RESOURCE:
42001 + task = va_arg(ap, struct task_struct *);
42002 + cred = __task_cred(task);
42003 + pcred = __task_cred(task->real_parent);
42004 + ulong1 = va_arg(ap, unsigned long);
42005 + str1 = va_arg(ap, char *);
42006 + ulong2 = va_arg(ap, unsigned long);
42007 + 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);
42010 + task = va_arg(ap, struct task_struct *);
42011 + cred = __task_cred(task);
42012 + pcred = __task_cred(task->real_parent);
42013 + str1 = va_arg(ap, char *);
42014 + 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);
42017 + str1 = va_arg(ap, char *);
42018 + voidptr = va_arg(ap, void *);
42019 + gr_log_middle_varargs(audit, msg, str1, voidptr);
42022 + task = va_arg(ap, struct task_struct *);
42023 + cred = __task_cred(task);
42024 + pcred = __task_cred(task->real_parent);
42025 + num1 = va_arg(ap, int);
42026 + 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);
42029 + task = va_arg(ap, struct task_struct *);
42030 + cred = __task_cred(task);
42031 + pcred = __task_cred(task->real_parent);
42032 + ulong1 = va_arg(ap, unsigned long);
42033 + 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);
42036 + task = va_arg(ap, struct task_struct *);
42037 + cred = __task_cred(task);
42038 + pcred = __task_cred(task->real_parent);
42039 + ulong1 = va_arg(ap, unsigned long);
42040 + 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);
42043 + file = va_arg(ap, struct file *);
42044 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
42048 + unsigned int wday, cday;
42052 + char cur_tty[64] = { 0 };
42053 + char parent_tty[64] = { 0 };
42055 + task = va_arg(ap, struct task_struct *);
42056 + wday = va_arg(ap, unsigned int);
42057 + cday = va_arg(ap, unsigned int);
42058 + whr = va_arg(ap, int);
42059 + chr = va_arg(ap, int);
42060 + wmin = va_arg(ap, int);
42061 + cmin = va_arg(ap, int);
42062 + wsec = va_arg(ap, int);
42063 + csec = va_arg(ap, int);
42064 + ulong1 = va_arg(ap, unsigned long);
42065 + cred = __task_cred(task);
42066 + pcred = __task_cred(task->real_parent);
42068 + 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);
42072 + gr_log_middle(audit, msg, ap);
42075 + gr_log_end(audit);
42076 + END_LOCKS(audit);
42078 diff -urNp linux-2.6.37/grsecurity/grsec_mem.c linux-2.6.37/grsecurity/grsec_mem.c
42079 --- linux-2.6.37/grsecurity/grsec_mem.c 1969-12-31 19:00:00.000000000 -0500
42080 +++ linux-2.6.37/grsecurity/grsec_mem.c 2011-01-17 02:41:02.000000000 -0500
42082 +#include <linux/kernel.h>
42083 +#include <linux/sched.h>
42084 +#include <linux/mm.h>
42085 +#include <linux/mman.h>
42086 +#include <linux/grinternal.h>
42089 +gr_handle_ioperm(void)
42091 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
42096 +gr_handle_iopl(void)
42098 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
42103 +gr_handle_mem_write(void)
42105 + gr_log_noargs(GR_DONT_AUDIT, GR_MEM_WRITE_MSG);
42110 +gr_handle_kmem_write(void)
42112 + gr_log_noargs(GR_DONT_AUDIT, GR_KMEM_MSG);
42117 +gr_handle_open_port(void)
42119 + gr_log_noargs(GR_DONT_AUDIT, GR_PORT_OPEN_MSG);
42124 +gr_handle_mem_mmap(const unsigned long offset, struct vm_area_struct *vma)
42126 + unsigned long start, end;
42129 + end = start + vma->vm_end - vma->vm_start;
42131 + if (start > end) {
42132 + gr_log_noargs(GR_DONT_AUDIT, GR_MEM_MMAP_MSG);
42136 + /* allowed ranges : ISA I/O BIOS */
42137 + if ((start >= __pa(high_memory))
42138 +#if defined(CONFIG_X86) || defined(CONFIG_PPC)
42139 + || (start >= 0x000a0000 && end <= 0x00100000)
42140 + || (start >= 0x00000000 && end <= 0x00001000)
42145 + if (vma->vm_flags & VM_WRITE) {
42146 + gr_log_noargs(GR_DONT_AUDIT, GR_MEM_MMAP_MSG);
42149 + vma->vm_flags &= ~VM_MAYWRITE;
42155 +gr_log_nonroot_mod_load(const char *modname)
42157 + gr_log_str(GR_DONT_AUDIT, GR_NONROOT_MODLOAD_MSG, modname);
42162 +gr_handle_vm86(void)
42164 + gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
42167 diff -urNp linux-2.6.37/grsecurity/grsec_mount.c linux-2.6.37/grsecurity/grsec_mount.c
42168 --- linux-2.6.37/grsecurity/grsec_mount.c 1969-12-31 19:00:00.000000000 -0500
42169 +++ linux-2.6.37/grsecurity/grsec_mount.c 2011-01-17 02:41:02.000000000 -0500
42171 +#include <linux/kernel.h>
42172 +#include <linux/sched.h>
42173 +#include <linux/mount.h>
42174 +#include <linux/grsecurity.h>
42175 +#include <linux/grinternal.h>
42178 +gr_log_remount(const char *devname, const int retval)
42180 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
42181 + if (grsec_enable_mount && (retval >= 0))
42182 + gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
42188 +gr_log_unmount(const char *devname, const int retval)
42190 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
42191 + if (grsec_enable_mount && (retval >= 0))
42192 + gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
42198 +gr_log_mount(const char *from, const char *to, const int retval)
42200 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
42201 + if (grsec_enable_mount && (retval >= 0))
42202 + gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from, to);
42208 +gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
42210 +#ifdef CONFIG_GRKERNSEC_ROFS
42211 + if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
42212 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
42221 +gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
42223 +#ifdef CONFIG_GRKERNSEC_ROFS
42224 + if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
42225 + dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
42226 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
42233 diff -urNp linux-2.6.37/grsecurity/grsec_pax.c linux-2.6.37/grsecurity/grsec_pax.c
42234 --- linux-2.6.37/grsecurity/grsec_pax.c 1969-12-31 19:00:00.000000000 -0500
42235 +++ linux-2.6.37/grsecurity/grsec_pax.c 2011-01-17 02:41:02.000000000 -0500
42237 +#include <linux/kernel.h>
42238 +#include <linux/sched.h>
42239 +#include <linux/mm.h>
42240 +#include <linux/file.h>
42241 +#include <linux/grinternal.h>
42242 +#include <linux/grsecurity.h>
42245 +gr_log_textrel(struct vm_area_struct * vma)
42247 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
42248 + if (grsec_enable_audit_textrel)
42249 + gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
42255 +gr_log_rwxmmap(struct file *file)
42257 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
42258 + if (grsec_enable_log_rwxmaps)
42259 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
42265 +gr_log_rwxmprotect(struct file *file)
42267 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
42268 + if (grsec_enable_log_rwxmaps)
42269 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
42273 diff -urNp linux-2.6.37/grsecurity/grsec_ptrace.c linux-2.6.37/grsecurity/grsec_ptrace.c
42274 --- linux-2.6.37/grsecurity/grsec_ptrace.c 1969-12-31 19:00:00.000000000 -0500
42275 +++ linux-2.6.37/grsecurity/grsec_ptrace.c 2011-01-17 02:41:02.000000000 -0500
42277 +#include <linux/kernel.h>
42278 +#include <linux/sched.h>
42279 +#include <linux/grinternal.h>
42280 +#include <linux/grsecurity.h>
42283 +gr_audit_ptrace(struct task_struct *task)
42285 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
42286 + if (grsec_enable_audit_ptrace)
42287 + gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
42291 diff -urNp linux-2.6.37/grsecurity/grsec_sig.c linux-2.6.37/grsecurity/grsec_sig.c
42292 --- linux-2.6.37/grsecurity/grsec_sig.c 1969-12-31 19:00:00.000000000 -0500
42293 +++ linux-2.6.37/grsecurity/grsec_sig.c 2011-01-17 02:41:02.000000000 -0500
42295 +#include <linux/kernel.h>
42296 +#include <linux/sched.h>
42297 +#include <linux/delay.h>
42298 +#include <linux/grsecurity.h>
42299 +#include <linux/grinternal.h>
42301 +char *signames[] = {
42302 + [SIGSEGV] = "Segmentation fault",
42303 + [SIGILL] = "Illegal instruction",
42304 + [SIGABRT] = "Abort",
42305 + [SIGBUS] = "Invalid alignment/Bus error"
42309 +gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
42311 +#ifdef CONFIG_GRKERNSEC_SIGNAL
42312 + if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
42313 + (sig == SIGABRT) || (sig == SIGBUS))) {
42314 + if (t->pid == current->pid) {
42315 + gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
42317 + gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
42325 +gr_handle_signal(const struct task_struct *p, const int sig)
42327 +#ifdef CONFIG_GRKERNSEC
42328 + if (current->pid > 1 && gr_check_protected_task(p)) {
42329 + gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
42331 + } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
42338 +void gr_handle_brute_attach(struct task_struct *p)
42340 +#ifdef CONFIG_GRKERNSEC_BRUTE
42341 + read_lock(&tasklist_lock);
42342 + read_lock(&grsec_exec_file_lock);
42343 + if (p->real_parent && p->real_parent->exec_file == p->exec_file)
42344 + p->real_parent->brute = 1;
42345 + read_unlock(&grsec_exec_file_lock);
42346 + read_unlock(&tasklist_lock);
42351 +void gr_handle_brute_check(void)
42353 +#ifdef CONFIG_GRKERNSEC_BRUTE
42354 + if (current->brute)
42355 + msleep(30 * 1000);
42360 diff -urNp linux-2.6.37/grsecurity/grsec_sock.c linux-2.6.37/grsecurity/grsec_sock.c
42361 --- linux-2.6.37/grsecurity/grsec_sock.c 1969-12-31 19:00:00.000000000 -0500
42362 +++ linux-2.6.37/grsecurity/grsec_sock.c 2011-01-17 02:41:02.000000000 -0500
42364 +#include <linux/kernel.h>
42365 +#include <linux/module.h>
42366 +#include <linux/sched.h>
42367 +#include <linux/file.h>
42368 +#include <linux/net.h>
42369 +#include <linux/in.h>
42370 +#include <linux/ip.h>
42371 +#include <net/sock.h>
42372 +#include <net/inet_sock.h>
42373 +#include <linux/grsecurity.h>
42374 +#include <linux/grinternal.h>
42375 +#include <linux/gracl.h>
42377 +kernel_cap_t gr_cap_rtnetlink(struct sock *sock);
42378 +EXPORT_SYMBOL(gr_cap_rtnetlink);
42380 +extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
42381 +extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
42383 +EXPORT_SYMBOL(gr_search_udp_recvmsg);
42384 +EXPORT_SYMBOL(gr_search_udp_sendmsg);
42386 +#ifdef CONFIG_UNIX_MODULE
42387 +EXPORT_SYMBOL(gr_acl_handle_unix);
42388 +EXPORT_SYMBOL(gr_acl_handle_mknod);
42389 +EXPORT_SYMBOL(gr_handle_chroot_unix);
42390 +EXPORT_SYMBOL(gr_handle_create);
42393 +#ifdef CONFIG_GRKERNSEC
42394 +#define gr_conn_table_size 32749
42395 +struct conn_table_entry {
42396 + struct conn_table_entry *next;
42397 + struct signal_struct *sig;
42400 +struct conn_table_entry *gr_conn_table[gr_conn_table_size];
42401 +DEFINE_SPINLOCK(gr_conn_table_lock);
42403 +extern const char * gr_socktype_to_name(unsigned char type);
42404 +extern const char * gr_proto_to_name(unsigned char proto);
42405 +extern const char * gr_sockfamily_to_name(unsigned char family);
42407 +static __inline__ int
42408 +conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
42410 + return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
42413 +static __inline__ int
42414 +conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
42415 + __u16 sport, __u16 dport)
42417 + if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
42418 + sig->gr_sport == sport && sig->gr_dport == dport))
42424 +static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
42426 + struct conn_table_entry **match;
42427 + unsigned int index;
42429 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
42430 + sig->gr_sport, sig->gr_dport,
42431 + gr_conn_table_size);
42433 + newent->sig = sig;
42435 + match = &gr_conn_table[index];
42436 + newent->next = *match;
42442 +static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
42444 + struct conn_table_entry *match, *last = NULL;
42445 + unsigned int index;
42447 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
42448 + sig->gr_sport, sig->gr_dport,
42449 + gr_conn_table_size);
42451 + match = gr_conn_table[index];
42452 + while (match && !conn_match(match->sig,
42453 + sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
42454 + sig->gr_dport)) {
42456 + match = match->next;
42461 + last->next = match->next;
42463 + gr_conn_table[index] = NULL;
42470 +static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
42471 + __u16 sport, __u16 dport)
42473 + struct conn_table_entry *match;
42474 + unsigned int index;
42476 + index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
42478 + match = gr_conn_table[index];
42479 + while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
42480 + match = match->next;
42483 + return match->sig;
42490 +void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
42492 +#ifdef CONFIG_GRKERNSEC
42493 + struct signal_struct *sig = task->signal;
42494 + struct conn_table_entry *newent;
42496 + newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
42497 + if (newent == NULL)
42499 + /* no bh lock needed since we are called with bh disabled */
42500 + spin_lock(&gr_conn_table_lock);
42501 + gr_del_task_from_ip_table_nolock(sig);
42502 + sig->gr_saddr = inet->inet_rcv_saddr;
42503 + sig->gr_daddr = inet->inet_daddr;
42504 + sig->gr_sport = inet->inet_sport;
42505 + sig->gr_dport = inet->inet_dport;
42506 + gr_add_to_task_ip_table_nolock(sig, newent);
42507 + spin_unlock(&gr_conn_table_lock);
42512 +void gr_del_task_from_ip_table(struct task_struct *task)
42514 +#ifdef CONFIG_GRKERNSEC
42515 + spin_lock_bh(&gr_conn_table_lock);
42516 + gr_del_task_from_ip_table_nolock(task->signal);
42517 + spin_unlock_bh(&gr_conn_table_lock);
42523 +gr_attach_curr_ip(const struct sock *sk)
42525 +#ifdef CONFIG_GRKERNSEC
42526 + struct signal_struct *p, *set;
42527 + const struct inet_sock *inet = inet_sk(sk);
42529 + if (unlikely(sk->sk_protocol != IPPROTO_TCP))
42532 + set = current->signal;
42534 + spin_lock_bh(&gr_conn_table_lock);
42535 + p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
42536 + inet->inet_dport, inet->inet_sport);
42537 + if (unlikely(p != NULL)) {
42538 + set->curr_ip = p->curr_ip;
42539 + set->used_accept = 1;
42540 + gr_del_task_from_ip_table_nolock(p);
42541 + spin_unlock_bh(&gr_conn_table_lock);
42544 + spin_unlock_bh(&gr_conn_table_lock);
42546 + set->curr_ip = inet->inet_daddr;
42547 + set->used_accept = 1;
42553 +gr_handle_sock_all(const int family, const int type, const int protocol)
42555 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
42556 + if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
42557 + (family != AF_UNIX)) {
42558 + if (family == AF_INET)
42559 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
42561 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
42569 +gr_handle_sock_server(const struct sockaddr *sck)
42571 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
42572 + if (grsec_enable_socket_server &&
42573 + in_group_p(grsec_socket_server_gid) &&
42574 + sck && (sck->sa_family != AF_UNIX) &&
42575 + (sck->sa_family != AF_LOCAL)) {
42576 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
42584 +gr_handle_sock_server_other(const struct sock *sck)
42586 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
42587 + if (grsec_enable_socket_server &&
42588 + in_group_p(grsec_socket_server_gid) &&
42589 + sck && (sck->sk_family != AF_UNIX) &&
42590 + (sck->sk_family != AF_LOCAL)) {
42591 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
42599 +gr_handle_sock_client(const struct sockaddr *sck)
42601 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
42602 + if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
42603 + sck && (sck->sa_family != AF_UNIX) &&
42604 + (sck->sa_family != AF_LOCAL)) {
42605 + gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
42613 +gr_cap_rtnetlink(struct sock *sock)
42615 +#ifdef CONFIG_GRKERNSEC
42616 + if (!gr_acl_is_enabled())
42617 + return current_cap();
42618 + else if (sock->sk_protocol == NETLINK_ISCSI &&
42619 + cap_raised(current_cap(), CAP_SYS_ADMIN) &&
42620 + gr_is_capable(CAP_SYS_ADMIN))
42621 + return current_cap();
42622 + else if (sock->sk_protocol == NETLINK_AUDIT &&
42623 + cap_raised(current_cap(), CAP_AUDIT_WRITE) &&
42624 + gr_is_capable(CAP_AUDIT_WRITE) &&
42625 + cap_raised(current_cap(), CAP_AUDIT_CONTROL) &&
42626 + gr_is_capable(CAP_AUDIT_CONTROL))
42627 + return current_cap();
42628 + else if (cap_raised(current_cap(), CAP_NET_ADMIN) &&
42629 + ((sock->sk_protocol == NETLINK_ROUTE) ?
42630 + gr_is_capable_nolog(CAP_NET_ADMIN) :
42631 + gr_is_capable(CAP_NET_ADMIN)))
42632 + return current_cap();
42634 + return __cap_empty_set;
42636 + return current_cap();
42639 diff -urNp linux-2.6.37/grsecurity/grsec_sysctl.c linux-2.6.37/grsecurity/grsec_sysctl.c
42640 --- linux-2.6.37/grsecurity/grsec_sysctl.c 1969-12-31 19:00:00.000000000 -0500
42641 +++ linux-2.6.37/grsecurity/grsec_sysctl.c 2011-01-17 02:41:02.000000000 -0500
42643 +#include <linux/kernel.h>
42644 +#include <linux/sched.h>
42645 +#include <linux/sysctl.h>
42646 +#include <linux/grsecurity.h>
42647 +#include <linux/grinternal.h>
42650 +gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
42652 +#ifdef CONFIG_GRKERNSEC_SYSCTL
42653 + if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
42654 + gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
42661 +#ifdef CONFIG_GRKERNSEC_ROFS
42662 +static int __maybe_unused one = 1;
42665 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
42666 +struct ctl_table grsecurity_table[] = {
42667 +#ifdef CONFIG_GRKERNSEC_SYSCTL
42668 +#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
42669 +#ifdef CONFIG_GRKERNSEC_IO
42671 + .procname = "disable_priv_io",
42672 + .data = &grsec_disable_privio,
42673 + .maxlen = sizeof(int),
42675 + .proc_handler = &proc_dointvec,
42679 +#ifdef CONFIG_GRKERNSEC_LINK
42681 + .procname = "linking_restrictions",
42682 + .data = &grsec_enable_link,
42683 + .maxlen = sizeof(int),
42685 + .proc_handler = &proc_dointvec,
42688 +#ifdef CONFIG_GRKERNSEC_FIFO
42690 + .procname = "fifo_restrictions",
42691 + .data = &grsec_enable_fifo,
42692 + .maxlen = sizeof(int),
42694 + .proc_handler = &proc_dointvec,
42697 +#ifdef CONFIG_GRKERNSEC_EXECVE
42699 + .procname = "execve_limiting",
42700 + .data = &grsec_enable_execve,
42701 + .maxlen = sizeof(int),
42703 + .proc_handler = &proc_dointvec,
42706 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
42708 + .procname = "ip_blackhole",
42709 + .data = &grsec_enable_blackhole,
42710 + .maxlen = sizeof(int),
42712 + .proc_handler = &proc_dointvec,
42715 + .procname = "lastack_retries",
42716 + .data = &grsec_lastack_retries,
42717 + .maxlen = sizeof(int),
42719 + .proc_handler = &proc_dointvec,
42722 +#ifdef CONFIG_GRKERNSEC_EXECLOG
42724 + .procname = "exec_logging",
42725 + .data = &grsec_enable_execlog,
42726 + .maxlen = sizeof(int),
42728 + .proc_handler = &proc_dointvec,
42731 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
42733 + .procname = "rwxmap_logging",
42734 + .data = &grsec_enable_log_rwxmaps,
42735 + .maxlen = sizeof(int),
42737 + .proc_handler = &proc_dointvec,
42740 +#ifdef CONFIG_GRKERNSEC_SIGNAL
42742 + .procname = "signal_logging",
42743 + .data = &grsec_enable_signal,
42744 + .maxlen = sizeof(int),
42746 + .proc_handler = &proc_dointvec,
42749 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
42751 + .procname = "forkfail_logging",
42752 + .data = &grsec_enable_forkfail,
42753 + .maxlen = sizeof(int),
42755 + .proc_handler = &proc_dointvec,
42758 +#ifdef CONFIG_GRKERNSEC_TIME
42760 + .procname = "timechange_logging",
42761 + .data = &grsec_enable_time,
42762 + .maxlen = sizeof(int),
42764 + .proc_handler = &proc_dointvec,
42767 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
42769 + .procname = "chroot_deny_shmat",
42770 + .data = &grsec_enable_chroot_shmat,
42771 + .maxlen = sizeof(int),
42773 + .proc_handler = &proc_dointvec,
42776 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
42778 + .procname = "chroot_deny_unix",
42779 + .data = &grsec_enable_chroot_unix,
42780 + .maxlen = sizeof(int),
42782 + .proc_handler = &proc_dointvec,
42785 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
42787 + .procname = "chroot_deny_mount",
42788 + .data = &grsec_enable_chroot_mount,
42789 + .maxlen = sizeof(int),
42791 + .proc_handler = &proc_dointvec,
42794 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
42796 + .procname = "chroot_deny_fchdir",
42797 + .data = &grsec_enable_chroot_fchdir,
42798 + .maxlen = sizeof(int),
42800 + .proc_handler = &proc_dointvec,
42803 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
42805 + .procname = "chroot_deny_chroot",
42806 + .data = &grsec_enable_chroot_double,
42807 + .maxlen = sizeof(int),
42809 + .proc_handler = &proc_dointvec,
42812 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
42814 + .procname = "chroot_deny_pivot",
42815 + .data = &grsec_enable_chroot_pivot,
42816 + .maxlen = sizeof(int),
42818 + .proc_handler = &proc_dointvec,
42821 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
42823 + .procname = "chroot_enforce_chdir",
42824 + .data = &grsec_enable_chroot_chdir,
42825 + .maxlen = sizeof(int),
42827 + .proc_handler = &proc_dointvec,
42830 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
42832 + .procname = "chroot_deny_chmod",
42833 + .data = &grsec_enable_chroot_chmod,
42834 + .maxlen = sizeof(int),
42836 + .proc_handler = &proc_dointvec,
42839 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
42841 + .procname = "chroot_deny_mknod",
42842 + .data = &grsec_enable_chroot_mknod,
42843 + .maxlen = sizeof(int),
42845 + .proc_handler = &proc_dointvec,
42848 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
42850 + .procname = "chroot_restrict_nice",
42851 + .data = &grsec_enable_chroot_nice,
42852 + .maxlen = sizeof(int),
42854 + .proc_handler = &proc_dointvec,
42857 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
42859 + .procname = "chroot_execlog",
42860 + .data = &grsec_enable_chroot_execlog,
42861 + .maxlen = sizeof(int),
42863 + .proc_handler = &proc_dointvec,
42866 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
42868 + .procname = "chroot_caps",
42869 + .data = &grsec_enable_chroot_caps,
42870 + .maxlen = sizeof(int),
42872 + .proc_handler = &proc_dointvec,
42875 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
42877 + .procname = "chroot_deny_sysctl",
42878 + .data = &grsec_enable_chroot_sysctl,
42879 + .maxlen = sizeof(int),
42881 + .proc_handler = &proc_dointvec,
42884 +#ifdef CONFIG_GRKERNSEC_TPE
42886 + .procname = "tpe",
42887 + .data = &grsec_enable_tpe,
42888 + .maxlen = sizeof(int),
42890 + .proc_handler = &proc_dointvec,
42893 + .procname = "tpe_gid",
42894 + .data = &grsec_tpe_gid,
42895 + .maxlen = sizeof(int),
42897 + .proc_handler = &proc_dointvec,
42900 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
42902 + .procname = "tpe_invert",
42903 + .data = &grsec_enable_tpe_invert,
42904 + .maxlen = sizeof(int),
42906 + .proc_handler = &proc_dointvec,
42909 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
42911 + .procname = "tpe_restrict_all",
42912 + .data = &grsec_enable_tpe_all,
42913 + .maxlen = sizeof(int),
42915 + .proc_handler = &proc_dointvec,
42918 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
42920 + .procname = "socket_all",
42921 + .data = &grsec_enable_socket_all,
42922 + .maxlen = sizeof(int),
42924 + .proc_handler = &proc_dointvec,
42927 + .procname = "socket_all_gid",
42928 + .data = &grsec_socket_all_gid,
42929 + .maxlen = sizeof(int),
42931 + .proc_handler = &proc_dointvec,
42934 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
42936 + .procname = "socket_client",
42937 + .data = &grsec_enable_socket_client,
42938 + .maxlen = sizeof(int),
42940 + .proc_handler = &proc_dointvec,
42943 + .procname = "socket_client_gid",
42944 + .data = &grsec_socket_client_gid,
42945 + .maxlen = sizeof(int),
42947 + .proc_handler = &proc_dointvec,
42950 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
42952 + .procname = "socket_server",
42953 + .data = &grsec_enable_socket_server,
42954 + .maxlen = sizeof(int),
42956 + .proc_handler = &proc_dointvec,
42959 + .procname = "socket_server_gid",
42960 + .data = &grsec_socket_server_gid,
42961 + .maxlen = sizeof(int),
42963 + .proc_handler = &proc_dointvec,
42966 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
42968 + .procname = "audit_group",
42969 + .data = &grsec_enable_group,
42970 + .maxlen = sizeof(int),
42972 + .proc_handler = &proc_dointvec,
42975 + .procname = "audit_gid",
42976 + .data = &grsec_audit_gid,
42977 + .maxlen = sizeof(int),
42979 + .proc_handler = &proc_dointvec,
42982 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
42984 + .procname = "audit_chdir",
42985 + .data = &grsec_enable_chdir,
42986 + .maxlen = sizeof(int),
42988 + .proc_handler = &proc_dointvec,
42991 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
42993 + .procname = "audit_mount",
42994 + .data = &grsec_enable_mount,
42995 + .maxlen = sizeof(int),
42997 + .proc_handler = &proc_dointvec,
43000 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
43002 + .procname = "audit_textrel",
43003 + .data = &grsec_enable_audit_textrel,
43004 + .maxlen = sizeof(int),
43006 + .proc_handler = &proc_dointvec,
43009 +#ifdef CONFIG_GRKERNSEC_DMESG
43011 + .procname = "dmesg",
43012 + .data = &grsec_enable_dmesg,
43013 + .maxlen = sizeof(int),
43015 + .proc_handler = &proc_dointvec,
43018 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
43020 + .procname = "chroot_findtask",
43021 + .data = &grsec_enable_chroot_findtask,
43022 + .maxlen = sizeof(int),
43024 + .proc_handler = &proc_dointvec,
43027 +#ifdef CONFIG_GRKERNSEC_RESLOG
43029 + .procname = "resource_logging",
43030 + .data = &grsec_resource_logging,
43031 + .maxlen = sizeof(int),
43033 + .proc_handler = &proc_dointvec,
43036 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
43038 + .procname = "audit_ptrace",
43039 + .data = &grsec_enable_audit_ptrace,
43040 + .maxlen = sizeof(int),
43042 + .proc_handler = &proc_dointvec,
43045 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
43047 + .procname = "harden_ptrace",
43048 + .data = &grsec_enable_harden_ptrace,
43049 + .maxlen = sizeof(int),
43051 + .proc_handler = &proc_dointvec,
43055 + .procname = "grsec_lock",
43056 + .data = &grsec_lock,
43057 + .maxlen = sizeof(int),
43059 + .proc_handler = &proc_dointvec,
43062 +#ifdef CONFIG_GRKERNSEC_ROFS
43064 + .procname = "romount_protect",
43065 + .data = &grsec_enable_rofs,
43066 + .maxlen = sizeof(int),
43068 + .proc_handler = &proc_dointvec_minmax,
43076 diff -urNp linux-2.6.37/grsecurity/grsec_time.c linux-2.6.37/grsecurity/grsec_time.c
43077 --- linux-2.6.37/grsecurity/grsec_time.c 1969-12-31 19:00:00.000000000 -0500
43078 +++ linux-2.6.37/grsecurity/grsec_time.c 2011-01-17 02:41:02.000000000 -0500
43080 +#include <linux/kernel.h>
43081 +#include <linux/sched.h>
43082 +#include <linux/grinternal.h>
43083 +#include <linux/module.h>
43086 +gr_log_timechange(void)
43088 +#ifdef CONFIG_GRKERNSEC_TIME
43089 + if (grsec_enable_time)
43090 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
43095 +EXPORT_SYMBOL(gr_log_timechange);
43096 diff -urNp linux-2.6.37/grsecurity/grsec_tpe.c linux-2.6.37/grsecurity/grsec_tpe.c
43097 --- linux-2.6.37/grsecurity/grsec_tpe.c 1969-12-31 19:00:00.000000000 -0500
43098 +++ linux-2.6.37/grsecurity/grsec_tpe.c 2011-01-17 02:41:02.000000000 -0500
43100 +#include <linux/kernel.h>
43101 +#include <linux/sched.h>
43102 +#include <linux/file.h>
43103 +#include <linux/fs.h>
43104 +#include <linux/grinternal.h>
43106 +extern int gr_acl_tpe_check(void);
43109 +gr_tpe_allow(const struct file *file)
43111 +#ifdef CONFIG_GRKERNSEC
43112 + struct inode *inode = file->f_path.dentry->d_parent->d_inode;
43113 + const struct cred *cred = current_cred();
43115 + if (cred->uid && ((grsec_enable_tpe &&
43116 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
43117 + ((grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid)) ||
43118 + (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid)))
43120 + in_group_p(grsec_tpe_gid)
43122 + ) || gr_acl_tpe_check()) &&
43123 + (inode->i_uid || (!inode->i_uid && ((inode->i_mode & S_IWGRP) ||
43124 + (inode->i_mode & S_IWOTH))))) {
43125 + gr_log_fs_generic(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, file->f_path.dentry, file->f_path.mnt);
43128 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
43129 + if (cred->uid && grsec_enable_tpe && grsec_enable_tpe_all &&
43130 + ((inode->i_uid && (inode->i_uid != cred->uid)) ||
43131 + (inode->i_mode & S_IWGRP) || (inode->i_mode & S_IWOTH))) {
43132 + gr_log_fs_generic(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, file->f_path.dentry, file->f_path.mnt);
43139 diff -urNp linux-2.6.37/grsecurity/grsum.c linux-2.6.37/grsecurity/grsum.c
43140 --- linux-2.6.37/grsecurity/grsum.c 1969-12-31 19:00:00.000000000 -0500
43141 +++ linux-2.6.37/grsecurity/grsum.c 2011-01-17 02:41:02.000000000 -0500
43143 +#include <linux/err.h>
43144 +#include <linux/kernel.h>
43145 +#include <linux/sched.h>
43146 +#include <linux/mm.h>
43147 +#include <linux/scatterlist.h>
43148 +#include <linux/crypto.h>
43149 +#include <linux/gracl.h>
43152 +#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
43153 +#error "crypto and sha256 must be built into the kernel"
43157 +chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
43160 + struct crypto_hash *tfm;
43161 + struct hash_desc desc;
43162 + struct scatterlist sg;
43163 + unsigned char temp_sum[GR_SHA_LEN];
43164 + volatile int retval = 0;
43165 + volatile int dummy = 0;
43168 + sg_init_table(&sg, 1);
43170 + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
43171 + if (IS_ERR(tfm)) {
43172 + /* should never happen, since sha256 should be built in */
43179 + crypto_hash_init(&desc);
43182 + sg_set_buf(&sg, p, GR_SALT_LEN);
43183 + crypto_hash_update(&desc, &sg, sg.length);
43186 + sg_set_buf(&sg, p, strlen(p));
43188 + crypto_hash_update(&desc, &sg, sg.length);
43190 + crypto_hash_final(&desc, temp_sum);
43192 + memset(entry->pw, 0, GR_PW_LEN);
43194 + for (i = 0; i < GR_SHA_LEN; i++)
43195 + if (sum[i] != temp_sum[i])
43198 + dummy = 1; // waste a cycle
43200 + crypto_free_hash(tfm);
43204 diff -urNp linux-2.6.37/grsecurity/Kconfig linux-2.6.37/grsecurity/Kconfig
43205 --- linux-2.6.37/grsecurity/Kconfig 1969-12-31 19:00:00.000000000 -0500
43206 +++ linux-2.6.37/grsecurity/Kconfig 2011-01-17 02:41:02.000000000 -0500
43209 +# grecurity configuration
43215 + bool "Grsecurity"
43217 + select CRYPTO_SHA256
43219 + If you say Y here, you will be able to configure many features
43220 + that will enhance the security of your system. It is highly
43221 + recommended that you say Y here and read through the help
43222 + for each option so that you fully understand the features and
43223 + can evaluate their usefulness for your machine.
43226 + prompt "Security Level"
43227 + depends on GRKERNSEC
43228 + default GRKERNSEC_CUSTOM
43230 +config GRKERNSEC_LOW
43232 + select GRKERNSEC_LINK
43233 + select GRKERNSEC_FIFO
43234 + select GRKERNSEC_EXECVE
43235 + select GRKERNSEC_RANDNET
43236 + select GRKERNSEC_DMESG
43237 + select GRKERNSEC_CHROOT
43238 + select GRKERNSEC_CHROOT_CHDIR
43241 + If you choose this option, several of the grsecurity options will
43242 + be enabled that will give you greater protection against a number
43243 + of attacks, while assuring that none of your software will have any
43244 + conflicts with the additional security measures. If you run a lot
43245 + of unusual software, or you are having problems with the higher
43246 + security levels, you should say Y here. With this option, the
43247 + following features are enabled:
43249 + - Linking restrictions
43250 + - FIFO restrictions
43251 + - Enforcing RLIMIT_NPROC on execve
43252 + - Restricted dmesg
43253 + - Enforced chdir("/") on chroot
43254 + - Runtime module disabling
43256 +config GRKERNSEC_MEDIUM
43259 + select PAX_EI_PAX
43260 + select PAX_PT_PAX_FLAGS
43261 + select PAX_HAVE_ACL_FLAGS
43262 + select GRKERNSEC_PROC_MEMMAP if (PAX_NOEXEC || PAX_ASLR)
43263 + select GRKERNSEC_CHROOT
43264 + select GRKERNSEC_CHROOT_SYSCTL
43265 + select GRKERNSEC_LINK
43266 + select GRKERNSEC_FIFO
43267 + select GRKERNSEC_EXECVE
43268 + select GRKERNSEC_DMESG
43269 + select GRKERNSEC_RANDNET
43270 + select GRKERNSEC_FORKFAIL
43271 + select GRKERNSEC_TIME
43272 + select GRKERNSEC_SIGNAL
43273 + select GRKERNSEC_CHROOT
43274 + select GRKERNSEC_CHROOT_UNIX
43275 + select GRKERNSEC_CHROOT_MOUNT
43276 + select GRKERNSEC_CHROOT_PIVOT
43277 + select GRKERNSEC_CHROOT_DOUBLE
43278 + select GRKERNSEC_CHROOT_CHDIR
43279 + select GRKERNSEC_CHROOT_MKNOD
43280 + select GRKERNSEC_PROC
43281 + select GRKERNSEC_PROC_USERGROUP
43282 + select PAX_RANDUSTACK
43284 + select PAX_RANDMMAP
43285 + select PAX_REFCOUNT if (X86 || SPARC64)
43286 + select PAX_USERCOPY if ((X86 || SPARC32 || SPARC64 || PPC) && (SLAB || SLUB || SLOB))
43289 + If you say Y here, several features in addition to those included
43290 + in the low additional security level will be enabled. These
43291 + features provide even more security to your system, though in rare
43292 + cases they may be incompatible with very old or poorly written
43293 + software. If you enable this option, make sure that your auth
43294 + service (identd) is running as gid 1001. With this option,
43295 + the following features (in addition to those provided in the
43296 + low additional security level) will be enabled:
43298 + - Failed fork logging
43299 + - Time change logging
43301 + - Deny mounts in chroot
43302 + - Deny double chrooting
43303 + - Deny sysctl writes in chroot
43304 + - Deny mknod in chroot
43305 + - Deny access to abstract AF_UNIX sockets out of chroot
43306 + - Deny pivot_root in chroot
43307 + - Denied writes of /dev/kmem, /dev/mem, and /dev/port
43308 + - /proc restrictions with special GID set to 10 (usually wheel)
43309 + - Address Space Layout Randomization (ASLR)
43310 + - Prevent exploitation of most refcount overflows
43311 + - Bounds checking of copying between the kernel and userland
43313 +config GRKERNSEC_HIGH
43315 + select GRKERNSEC_LINK
43316 + select GRKERNSEC_FIFO
43317 + select GRKERNSEC_EXECVE
43318 + select GRKERNSEC_DMESG
43319 + select GRKERNSEC_FORKFAIL
43320 + select GRKERNSEC_TIME
43321 + select GRKERNSEC_SIGNAL
43322 + select GRKERNSEC_CHROOT
43323 + select GRKERNSEC_CHROOT_SHMAT
43324 + select GRKERNSEC_CHROOT_UNIX
43325 + select GRKERNSEC_CHROOT_MOUNT
43326 + select GRKERNSEC_CHROOT_FCHDIR
43327 + select GRKERNSEC_CHROOT_PIVOT
43328 + select GRKERNSEC_CHROOT_DOUBLE
43329 + select GRKERNSEC_CHROOT_CHDIR
43330 + select GRKERNSEC_CHROOT_MKNOD
43331 + select GRKERNSEC_CHROOT_CAPS
43332 + select GRKERNSEC_CHROOT_SYSCTL
43333 + select GRKERNSEC_CHROOT_FINDTASK
43334 + select GRKERNSEC_PROC
43335 + select GRKERNSEC_PROC_MEMMAP if (PAX_NOEXEC || PAX_ASLR)
43336 + select GRKERNSEC_HIDESYM
43337 + select GRKERNSEC_BRUTE
43338 + select GRKERNSEC_PROC_USERGROUP
43339 + select GRKERNSEC_KMEM
43340 + select GRKERNSEC_RESLOG
43341 + select GRKERNSEC_RANDNET
43342 + select GRKERNSEC_PROC_ADD
43343 + select GRKERNSEC_CHROOT_CHMOD
43344 + select GRKERNSEC_CHROOT_NICE
43345 + select GRKERNSEC_AUDIT_MOUNT
43346 + select GRKERNSEC_MODHARDEN if (MODULES)
43347 + select GRKERNSEC_HARDEN_PTRACE
43348 + select GRKERNSEC_VM86 if (X86_32)
43350 + select PAX_RANDUSTACK
43352 + select PAX_RANDMMAP
43353 + select PAX_NOEXEC
43354 + select PAX_MPROTECT
43355 + select PAX_EI_PAX
43356 + select PAX_PT_PAX_FLAGS
43357 + select PAX_HAVE_ACL_FLAGS
43358 + select PAX_KERNEXEC if ((PPC || X86) && (!X86_32 || X86_WP_WORKS_OK) && !XEN)
43359 + select PAX_MEMORY_UDEREF if (X86 && !XEN)
43360 + select PAX_RANDKSTACK if (X86_TSC && !X86_64)
43361 + select PAX_SEGMEXEC if (X86_32)
43362 + select PAX_PAGEEXEC
43363 + select PAX_EMUPLT if (ALPHA || PARISC || SPARC32 || SPARC64)
43364 + select PAX_EMUTRAMP if (PARISC)
43365 + select PAX_EMUSIGRT if (PARISC)
43366 + select PAX_ETEXECRELOCS if (ALPHA || IA64 || PARISC)
43367 + select PAX_ELFRELOCS if (PAX_ETEXECRELOCS || (IA64 || PPC || X86))
43368 + select PAX_REFCOUNT if (X86 || SPARC64)
43369 + select PAX_USERCOPY if ((X86 || PPC || SPARC32 || SPARC64) && (SLAB || SLUB || SLOB))
43371 + If you say Y here, many of the features of grsecurity will be
43372 + enabled, which will protect you against many kinds of attacks
43373 + against your system. The heightened security comes at a cost
43374 + of an increased chance of incompatibilities with rare software
43375 + on your machine. Since this security level enables PaX, you should
43376 + view <http://pax.grsecurity.net> and read about the PaX
43377 + project. While you are there, download chpax and run it on
43378 + binaries that cause problems with PaX. Also remember that
43379 + since the /proc restrictions are enabled, you must run your
43380 + identd as gid 1001. This security level enables the following
43381 + features in addition to those listed in the low and medium
43384 + - Additional /proc restrictions
43385 + - Chmod restrictions in chroot
43386 + - No signals, ptrace, or viewing of processes outside of chroot
43387 + - Capability restrictions in chroot
43388 + - Deny fchdir out of chroot
43389 + - Priority restrictions in chroot
43390 + - Segmentation-based implementation of PaX
43391 + - Mprotect restrictions
43392 + - Removal of addresses from /proc/<pid>/[smaps|maps|stat]
43393 + - Kernel stack randomization
43394 + - Mount/unmount/remount logging
43395 + - Kernel symbol hiding
43396 + - Prevention of memory exhaustion-based exploits
43397 + - Hardening of module auto-loading
43398 + - Ptrace restrictions
43399 + - Restricted vm86 mode
43401 +config GRKERNSEC_CUSTOM
43404 + If you say Y here, you will be able to configure every grsecurity
43405 + option, which allows you to enable many more features that aren't
43406 + covered in the basic security levels. These additional features
43407 + include TPE, socket restrictions, and the sysctl system for
43408 + grsecurity. It is advised that you read through the help for
43409 + each option to determine its usefulness in your situation.
43413 +menu "Address Space Protection"
43414 +depends on GRKERNSEC
43416 +config GRKERNSEC_KMEM
43417 + bool "Deny writing to /dev/kmem, /dev/mem, and /dev/port"
43419 + If you say Y here, /dev/kmem and /dev/mem won't be allowed to
43420 + be written to via mmap or otherwise to modify the running kernel.
43421 + /dev/port will also not be allowed to be opened. If you have module
43422 + support disabled, enabling this will close up four ways that are
43423 + currently used to insert malicious code into the running kernel.
43424 + Even with all these features enabled, we still highly recommend that
43425 + you use the RBAC system, as it is still possible for an attacker to
43426 + modify the running kernel through privileged I/O granted by ioperm/iopl.
43427 + If you are not using XFree86, you may be able to stop this additional
43428 + case by enabling the 'Disable privileged I/O' option. Though nothing
43429 + legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
43430 + but only to video memory, which is the only writing we allow in this
43431 + case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
43432 + not be allowed to mprotect it with PROT_WRITE later.
43433 + It is highly recommended that you say Y here if you meet all the
43434 + conditions above.
43436 +config GRKERNSEC_VM86
43437 + bool "Restrict VM86 mode"
43438 + depends on X86_32
43441 + If you say Y here, only processes with CAP_SYS_RAWIO will be able to
43442 + make use of a special execution mode on 32bit x86 processors called
43443 + Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
43444 + video cards and will still work with this option enabled. The purpose
43445 + of the option is to prevent exploitation of emulation errors in
43446 + virtualization of vm86 mode like the one discovered in VMWare in 2009.
43447 + Nearly all users should be able to enable this option.
43449 +config GRKERNSEC_IO
43450 + bool "Disable privileged I/O"
43453 + select RTC_INTF_DEV
43454 + select RTC_DRV_CMOS
43457 + If you say Y here, all ioperm and iopl calls will return an error.
43458 + Ioperm and iopl can be used to modify the running kernel.
43459 + Unfortunately, some programs need this access to operate properly,
43460 + the most notable of which are XFree86 and hwclock. hwclock can be
43461 + remedied by having RTC support in the kernel, so real-time
43462 + clock support is enabled if this option is enabled, to ensure
43463 + that hwclock operates correctly. XFree86 still will not
43464 + operate correctly with this option enabled, so DO NOT CHOOSE Y
43465 + IF YOU USE XFree86. If you use XFree86 and you still want to
43466 + protect your kernel against modification, use the RBAC system.
43468 +config GRKERNSEC_PROC_MEMMAP
43469 + bool "Remove addresses from /proc/<pid>/[smaps|maps|stat]"
43470 + default y if (PAX_NOEXEC || PAX_ASLR)
43471 + depends on PAX_NOEXEC || PAX_ASLR
43473 + If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
43474 + give no information about the addresses of its mappings if
43475 + PaX features that rely on random addresses are enabled on the task.
43476 + If you use PaX it is greatly recommended that you say Y here as it
43477 + closes up a hole that makes the full ASLR useless for suid
43480 +config GRKERNSEC_BRUTE
43481 + bool "Deter exploit bruteforcing"
43483 + If you say Y here, attempts to bruteforce exploits against forking
43484 + daemons such as apache or sshd will be deterred. When a child of a
43485 + forking daemon is killed by PaX or crashes due to an illegal
43486 + instruction, the parent process will be delayed 30 seconds upon every
43487 + subsequent fork until the administrator is able to assess the
43488 + situation and restart the daemon. It is recommended that you also
43489 + enable signal logging in the auditing section so that logs are
43490 + generated when a process performs an illegal instruction.
43492 +config GRKERNSEC_MODHARDEN
43493 + bool "Harden module auto-loading"
43494 + depends on MODULES
43496 + If you say Y here, module auto-loading in response to use of some
43497 + feature implemented by an unloaded module will be restricted to
43498 + root users. Enabling this option helps defend against attacks
43499 + by unprivileged users who abuse the auto-loading behavior to
43500 + cause a vulnerable module to load that is then exploited.
43502 + If this option prevents a legitimate use of auto-loading for a
43503 + non-root user, the administrator can execute modprobe manually
43504 + with the exact name of the module mentioned in the alert log.
43505 + Alternatively, the administrator can add the module to the list
43506 + of modules loaded at boot by modifying init scripts.
43508 + Modification of init scripts will most likely be needed on
43509 + Ubuntu servers with encrypted home directory support enabled,
43510 + as the first non-root user logging in will cause the ecb(aes),
43511 + ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
43513 +config GRKERNSEC_HIDESYM
43514 + bool "Hide kernel symbols"
43516 + If you say Y here, getting information on loaded modules, and
43517 + displaying all kernel symbols through a syscall will be restricted
43518 + to users with CAP_SYS_MODULE. For software compatibility reasons,
43519 + /proc/kallsyms will be restricted to the root user. The RBAC
43520 + system can hide that entry even from root.
43522 + This option also prevents leaking of kernel addresses through
43523 + several /proc entries.
43525 + Note that this option is only effective provided the following
43526 + conditions are met:
43527 + 1) The kernel using grsecurity is not precompiled by some distribution
43528 + 2) You have also enabled GRKERNSEC_DMESG
43529 + 3) You are using the RBAC system and hiding other files such as your
43530 + kernel image and System.map. Alternatively, enabling this option
43531 + causes the permissions on /boot, /lib/modules, and the kernel
43532 + source directory to change at compile time to prevent
43533 + reading by non-root users.
43534 + If the above conditions are met, this option will aid in providing a
43535 + useful protection against local kernel exploitation of overflows
43536 + and arbitrary read/write vulnerabilities.
43539 +menu "Role Based Access Control Options"
43540 +depends on GRKERNSEC
43542 +config GRKERNSEC_NO_RBAC
43543 + bool "Disable RBAC system"
43545 + If you say Y here, the /dev/grsec device will be removed from the kernel,
43546 + preventing the RBAC system from being enabled. You should only say Y
43547 + here if you have no intention of using the RBAC system, so as to prevent
43548 + an attacker with root access from misusing the RBAC system to hide files
43549 + and processes when loadable module support and /dev/[k]mem have been
43552 +config GRKERNSEC_ACL_HIDEKERN
43553 + bool "Hide kernel processes"
43555 + If you say Y here, all kernel threads will be hidden to all
43556 + processes but those whose subject has the "view hidden processes"
43559 +config GRKERNSEC_ACL_MAXTRIES
43560 + int "Maximum tries before password lockout"
43563 + This option enforces the maximum number of times a user can attempt
43564 + to authorize themselves with the grsecurity RBAC system before being
43565 + denied the ability to attempt authorization again for a specified time.
43566 + The lower the number, the harder it will be to brute-force a password.
43568 +config GRKERNSEC_ACL_TIMEOUT
43569 + int "Time to wait after max password tries, in seconds"
43572 + This option specifies the time the user must wait after attempting to
43573 + authorize to the RBAC system with the maximum number of invalid
43574 + passwords. The higher the number, the harder it will be to brute-force
43578 +menu "Filesystem Protections"
43579 +depends on GRKERNSEC
43581 +config GRKERNSEC_PROC
43582 + bool "Proc restrictions"
43584 + If you say Y here, the permissions of the /proc filesystem
43585 + will be altered to enhance system security and privacy. You MUST
43586 + choose either a user only restriction or a user and group restriction.
43587 + Depending upon the option you choose, you can either restrict users to
43588 + see only the processes they themselves run, or choose a group that can
43589 + view all processes and files normally restricted to root if you choose
43590 + the "restrict to user only" option. NOTE: If you're running identd as
43591 + a non-root user, you will have to run it as the group you specify here.
43593 +config GRKERNSEC_PROC_USER
43594 + bool "Restrict /proc to user only"
43595 + depends on GRKERNSEC_PROC
43597 + If you say Y here, non-root users will only be able to view their own
43598 + processes, and restricts them from viewing network-related information,
43599 + and viewing kernel symbol and module information.
43601 +config GRKERNSEC_PROC_USERGROUP
43602 + bool "Allow special group"
43603 + depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
43605 + If you say Y here, you will be able to select a group that will be
43606 + able to view all processes and network-related information. If you've
43607 + enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
43608 + remain hidden. This option is useful if you want to run identd as
43611 +config GRKERNSEC_PROC_GID
43612 + int "GID for special group"
43613 + depends on GRKERNSEC_PROC_USERGROUP
43616 +config GRKERNSEC_PROC_ADD
43617 + bool "Additional restrictions"
43618 + depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
43620 + If you say Y here, additional restrictions will be placed on
43621 + /proc that keep normal users from viewing device information and
43622 + slabinfo information that could be useful for exploits.
43624 +config GRKERNSEC_LINK
43625 + bool "Linking restrictions"
43627 + If you say Y here, /tmp race exploits will be prevented, since users
43628 + will no longer be able to follow symlinks owned by other users in
43629 + world-writable +t directories (i.e. /tmp), unless the owner of the
43630 + symlink is the owner of the directory. users will also not be
43631 + able to hardlink to files they do not own. If the sysctl option is
43632 + enabled, a sysctl option with name "linking_restrictions" is created.
43634 +config GRKERNSEC_FIFO
43635 + bool "FIFO restrictions"
43637 + If you say Y here, users will not be able to write to FIFOs they don't
43638 + own in world-writable +t directories (i.e. /tmp), unless the owner of
43639 + the FIFO is the same owner of the directory it's held in. If the sysctl
43640 + option is enabled, a sysctl option with name "fifo_restrictions" is
43643 +config GRKERNSEC_ROFS
43644 + bool "Runtime read-only mount protection"
43646 + If you say Y here, a sysctl option with name "romount_protect" will
43647 + be created. By setting this option to 1 at runtime, filesystems
43648 + will be protected in the following ways:
43649 + * No new writable mounts will be allowed
43650 + * Existing read-only mounts won't be able to be remounted read/write
43651 + * Write operations will be denied on all block devices
43652 + This option acts independently of grsec_lock: once it is set to 1,
43653 + it cannot be turned off. Therefore, please be mindful of the resulting
43654 + behavior if this option is enabled in an init script on a read-only
43655 + filesystem. This feature is mainly intended for secure embedded systems.
43657 +config GRKERNSEC_CHROOT
43658 + bool "Chroot jail restrictions"
43660 + If you say Y here, you will be able to choose several options that will
43661 + make breaking out of a chrooted jail much more difficult. If you
43662 + encounter no software incompatibilities with the following options, it
43663 + is recommended that you enable each one.
43665 +config GRKERNSEC_CHROOT_MOUNT
43666 + bool "Deny mounts"
43667 + depends on GRKERNSEC_CHROOT
43669 + If you say Y here, processes inside a chroot will not be able to
43670 + mount or remount filesystems. If the sysctl option is enabled, a
43671 + sysctl option with name "chroot_deny_mount" is created.
43673 +config GRKERNSEC_CHROOT_DOUBLE
43674 + bool "Deny double-chroots"
43675 + depends on GRKERNSEC_CHROOT
43677 + If you say Y here, processes inside a chroot will not be able to chroot
43678 + again outside the chroot. This is a widely used method of breaking
43679 + out of a chroot jail and should not be allowed. If the sysctl
43680 + option is enabled, a sysctl option with name
43681 + "chroot_deny_chroot" is created.
43683 +config GRKERNSEC_CHROOT_PIVOT
43684 + bool "Deny pivot_root in chroot"
43685 + depends on GRKERNSEC_CHROOT
43687 + If you say Y here, processes inside a chroot will not be able to use
43688 + a function called pivot_root() that was introduced in Linux 2.3.41. It
43689 + works similar to chroot in that it changes the root filesystem. This
43690 + function could be misused in a chrooted process to attempt to break out
43691 + of the chroot, and therefore should not be allowed. If the sysctl
43692 + option is enabled, a sysctl option with name "chroot_deny_pivot" is
43695 +config GRKERNSEC_CHROOT_CHDIR
43696 + bool "Enforce chdir(\"/\") on all chroots"
43697 + depends on GRKERNSEC_CHROOT
43699 + If you say Y here, the current working directory of all newly-chrooted
43700 + applications will be set to the the root directory of the chroot.
43701 + The man page on chroot(2) states:
43702 + Note that this call does not change the current working
43703 + directory, so that `.' can be outside the tree rooted at
43704 + `/'. In particular, the super-user can escape from a
43705 + `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
43707 + It is recommended that you say Y here, since it's not known to break
43708 + any software. If the sysctl option is enabled, a sysctl option with
43709 + name "chroot_enforce_chdir" is created.
43711 +config GRKERNSEC_CHROOT_CHMOD
43712 + bool "Deny (f)chmod +s"
43713 + depends on GRKERNSEC_CHROOT
43715 + If you say Y here, processes inside a chroot will not be able to chmod
43716 + or fchmod files to make them have suid or sgid bits. This protects
43717 + against another published method of breaking a chroot. If the sysctl
43718 + option is enabled, a sysctl option with name "chroot_deny_chmod" is
43721 +config GRKERNSEC_CHROOT_FCHDIR
43722 + bool "Deny fchdir out of chroot"
43723 + depends on GRKERNSEC_CHROOT
43725 + If you say Y here, a well-known method of breaking chroots by fchdir'ing
43726 + to a file descriptor of the chrooting process that points to a directory
43727 + outside the filesystem will be stopped. If the sysctl option
43728 + is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
43730 +config GRKERNSEC_CHROOT_MKNOD
43731 + bool "Deny mknod"
43732 + depends on GRKERNSEC_CHROOT
43734 + If you say Y here, processes inside a chroot will not be allowed to
43735 + mknod. The problem with using mknod inside a chroot is that it
43736 + would allow an attacker to create a device entry that is the same
43737 + as one on the physical root of your system, which could range from
43738 + anything from the console device to a device for your harddrive (which
43739 + they could then use to wipe the drive or steal data). It is recommended
43740 + that you say Y here, unless you run into software incompatibilities.
43741 + If the sysctl option is enabled, a sysctl option with name
43742 + "chroot_deny_mknod" is created.
43744 +config GRKERNSEC_CHROOT_SHMAT
43745 + bool "Deny shmat() out of chroot"
43746 + depends on GRKERNSEC_CHROOT
43748 + If you say Y here, processes inside a chroot will not be able to attach
43749 + to shared memory segments that were created outside of the chroot jail.
43750 + It is recommended that you say Y here. If the sysctl option is enabled,
43751 + a sysctl option with name "chroot_deny_shmat" is created.
43753 +config GRKERNSEC_CHROOT_UNIX
43754 + bool "Deny access to abstract AF_UNIX sockets out of chroot"
43755 + depends on GRKERNSEC_CHROOT
43757 + If you say Y here, processes inside a chroot will not be able to
43758 + connect to abstract (meaning not belonging to a filesystem) Unix
43759 + domain sockets that were bound outside of a chroot. It is recommended
43760 + that you say Y here. If the sysctl option is enabled, a sysctl option
43761 + with name "chroot_deny_unix" is created.
43763 +config GRKERNSEC_CHROOT_FINDTASK
43764 + bool "Protect outside processes"
43765 + depends on GRKERNSEC_CHROOT
43767 + If you say Y here, processes inside a chroot will not be able to
43768 + kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
43769 + getsid, or view any process outside of the chroot. If the sysctl
43770 + option is enabled, a sysctl option with name "chroot_findtask" is
43773 +config GRKERNSEC_CHROOT_NICE
43774 + bool "Restrict priority changes"
43775 + depends on GRKERNSEC_CHROOT
43777 + If you say Y here, processes inside a chroot will not be able to raise
43778 + the priority of processes in the chroot, or alter the priority of
43779 + processes outside the chroot. This provides more security than simply
43780 + removing CAP_SYS_NICE from the process' capability set. If the
43781 + sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
43784 +config GRKERNSEC_CHROOT_SYSCTL
43785 + bool "Deny sysctl writes"
43786 + depends on GRKERNSEC_CHROOT
43788 + If you say Y here, an attacker in a chroot will not be able to
43789 + write to sysctl entries, either by sysctl(2) or through a /proc
43790 + interface. It is strongly recommended that you say Y here. If the
43791 + sysctl option is enabled, a sysctl option with name
43792 + "chroot_deny_sysctl" is created.
43794 +config GRKERNSEC_CHROOT_CAPS
43795 + bool "Capability restrictions"
43796 + depends on GRKERNSEC_CHROOT
43798 + If you say Y here, the capabilities on all root processes within a
43799 + chroot jail will be lowered to stop module insertion, raw i/o,
43800 + system and net admin tasks, rebooting the system, modifying immutable
43801 + files, modifying IPC owned by another, and changing the system time.
43802 + This is left an option because it can break some apps. Disable this
43803 + if your chrooted apps are having problems performing those kinds of
43804 + tasks. If the sysctl option is enabled, a sysctl option with
43805 + name "chroot_caps" is created.
43808 +menu "Kernel Auditing"
43809 +depends on GRKERNSEC
43811 +config GRKERNSEC_AUDIT_GROUP
43812 + bool "Single group for auditing"
43814 + If you say Y here, the exec, chdir, and (un)mount logging features
43815 + will only operate on a group you specify. This option is recommended
43816 + if you only want to watch certain users instead of having a large
43817 + amount of logs from the entire system. If the sysctl option is enabled,
43818 + a sysctl option with name "audit_group" is created.
43820 +config GRKERNSEC_AUDIT_GID
43821 + int "GID for auditing"
43822 + depends on GRKERNSEC_AUDIT_GROUP
43825 +config GRKERNSEC_EXECLOG
43826 + bool "Exec logging"
43828 + If you say Y here, all execve() calls will be logged (since the
43829 + other exec*() calls are frontends to execve(), all execution
43830 + will be logged). Useful for shell-servers that like to keep track
43831 + of their users. If the sysctl option is enabled, a sysctl option with
43832 + name "exec_logging" is created.
43833 + WARNING: This option when enabled will produce a LOT of logs, especially
43834 + on an active system.
43836 +config GRKERNSEC_RESLOG
43837 + bool "Resource logging"
43839 + If you say Y here, all attempts to overstep resource limits will
43840 + be logged with the resource name, the requested size, and the current
43841 + limit. It is highly recommended that you say Y here. If the sysctl
43842 + option is enabled, a sysctl option with name "resource_logging" is
43843 + created. If the RBAC system is enabled, the sysctl value is ignored.
43845 +config GRKERNSEC_CHROOT_EXECLOG
43846 + bool "Log execs within chroot"
43848 + If you say Y here, all executions inside a chroot jail will be logged
43849 + to syslog. This can cause a large amount of logs if certain
43850 + applications (eg. djb's daemontools) are installed on the system, and
43851 + is therefore left as an option. If the sysctl option is enabled, a
43852 + sysctl option with name "chroot_execlog" is created.
43854 +config GRKERNSEC_AUDIT_PTRACE
43855 + bool "Ptrace logging"
43857 + If you say Y here, all attempts to attach to a process via ptrace
43858 + will be logged. If the sysctl option is enabled, a sysctl option
43859 + with name "audit_ptrace" is created.
43861 +config GRKERNSEC_AUDIT_CHDIR
43862 + bool "Chdir logging"
43864 + If you say Y here, all chdir() calls will be logged. If the sysctl
43865 + option is enabled, a sysctl option with name "audit_chdir" is created.
43867 +config GRKERNSEC_AUDIT_MOUNT
43868 + bool "(Un)Mount logging"
43870 + If you say Y here, all mounts and unmounts will be logged. If the
43871 + sysctl option is enabled, a sysctl option with name "audit_mount" is
43874 +config GRKERNSEC_SIGNAL
43875 + bool "Signal logging"
43877 + If you say Y here, certain important signals will be logged, such as
43878 + SIGSEGV, which will as a result inform you of when a error in a program
43879 + occurred, which in some cases could mean a possible exploit attempt.
43880 + If the sysctl option is enabled, a sysctl option with name
43881 + "signal_logging" is created.
43883 +config GRKERNSEC_FORKFAIL
43884 + bool "Fork failure logging"
43886 + If you say Y here, all failed fork() attempts will be logged.
43887 + This could suggest a fork bomb, or someone attempting to overstep
43888 + their process limit. If the sysctl option is enabled, a sysctl option
43889 + with name "forkfail_logging" is created.
43891 +config GRKERNSEC_TIME
43892 + bool "Time change logging"
43894 + If you say Y here, any changes of the system clock will be logged.
43895 + If the sysctl option is enabled, a sysctl option with name
43896 + "timechange_logging" is created.
43898 +config GRKERNSEC_PROC_IPADDR
43899 + bool "/proc/<pid>/ipaddr support"
43901 + If you say Y here, a new entry will be added to each /proc/<pid>
43902 + directory that contains the IP address of the person using the task.
43903 + The IP is carried across local TCP and AF_UNIX stream sockets.
43904 + This information can be useful for IDS/IPSes to perform remote response
43905 + to a local attack. The entry is readable by only the owner of the
43906 + process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
43907 + the RBAC system), and thus does not create privacy concerns.
43909 +config GRKERNSEC_RWXMAP_LOG
43910 + bool 'Denied RWX mmap/mprotect logging'
43911 + depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
43913 + If you say Y here, calls to mmap() and mprotect() with explicit
43914 + usage of PROT_WRITE and PROT_EXEC together will be logged when
43915 + denied by the PAX_MPROTECT feature. If the sysctl option is
43916 + enabled, a sysctl option with name "rwxmap_logging" is created.
43918 +config GRKERNSEC_AUDIT_TEXTREL
43919 + bool 'ELF text relocations logging (READ HELP)'
43920 + depends on PAX_MPROTECT
43922 + If you say Y here, text relocations will be logged with the filename
43923 + of the offending library or binary. The purpose of the feature is
43924 + to help Linux distribution developers get rid of libraries and
43925 + binaries that need text relocations which hinder the future progress
43926 + of PaX. Only Linux distribution developers should say Y here, and
43927 + never on a production machine, as this option creates an information
43928 + leak that could aid an attacker in defeating the randomization of
43929 + a single memory region. If the sysctl option is enabled, a sysctl
43930 + option with name "audit_textrel" is created.
43934 +menu "Executable Protections"
43935 +depends on GRKERNSEC
43937 +config GRKERNSEC_EXECVE
43938 + bool "Enforce RLIMIT_NPROC on execs"
43940 + If you say Y here, users with a resource limit on processes will
43941 + have the value checked during execve() calls. The current system
43942 + only checks the system limit during fork() calls. If the sysctl option
43943 + is enabled, a sysctl option with name "execve_limiting" is created.
43945 +config GRKERNSEC_DMESG
43946 + bool "Dmesg(8) restriction"
43948 + If you say Y here, non-root users will not be able to use dmesg(8)
43949 + to view up to the last 4kb of messages in the kernel's log buffer.
43950 + The kernel's log buffer often contains kernel addresses and other
43951 + identifying information useful to an attacker in fingerprinting a
43952 + system for a targeted exploit.
43953 + If the sysctl option is enabled, a sysctl option with name "dmesg" is
43956 +config GRKERNSEC_HARDEN_PTRACE
43957 + bool "Deter ptrace-based process snooping"
43959 + If you say Y here, TTY sniffers and other malicious monitoring
43960 + programs implemented through ptrace will be defeated. If you
43961 + have been using the RBAC system, this option has already been
43962 + enabled for several years for all users, with the ability to make
43963 + fine-grained exceptions.
43965 + This option only affects the ability of non-root users to ptrace
43966 + processes that are not a descendent of the ptracing process.
43967 + This means that strace ./binary and gdb ./binary will still work,
43968 + but attaching to arbitrary processes will not. If the sysctl
43969 + option is enabled, a sysctl option with name "harden_ptrace" is
43972 +config GRKERNSEC_TPE
43973 + bool "Trusted Path Execution (TPE)"
43975 + If you say Y here, you will be able to choose a gid to add to the
43976 + supplementary groups of users you want to mark as "untrusted."
43977 + These users will not be able to execute any files that are not in
43978 + root-owned directories writable only by root. If the sysctl option
43979 + is enabled, a sysctl option with name "tpe" is created.
43981 +config GRKERNSEC_TPE_ALL
43982 + bool "Partially restrict all non-root users"
43983 + depends on GRKERNSEC_TPE
43985 + If you say Y here, all non-root users will be covered under
43986 + a weaker TPE restriction. This is separate from, and in addition to,
43987 + the main TPE options that you have selected elsewhere. Thus, if a
43988 + "trusted" GID is chosen, this restriction applies to even that GID.
43989 + Under this restriction, all non-root users will only be allowed to
43990 + execute files in directories they own that are not group or
43991 + world-writable, or in directories owned by root and writable only by
43992 + root. If the sysctl option is enabled, a sysctl option with name
43993 + "tpe_restrict_all" is created.
43995 +config GRKERNSEC_TPE_INVERT
43996 + bool "Invert GID option"
43997 + depends on GRKERNSEC_TPE
43999 + If you say Y here, the group you specify in the TPE configuration will
44000 + decide what group TPE restrictions will be *disabled* for. This
44001 + option is useful if you want TPE restrictions to be applied to most
44002 + users on the system. If the sysctl option is enabled, a sysctl option
44003 + with name "tpe_invert" is created. Unlike other sysctl options, this
44004 + entry will default to on for backward-compatibility.
44006 +config GRKERNSEC_TPE_GID
44007 + int "GID for untrusted users"
44008 + depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
44011 + Setting this GID determines what group TPE restrictions will be
44012 + *enabled* for. If the sysctl option is enabled, a sysctl option
44013 + with name "tpe_gid" is created.
44015 +config GRKERNSEC_TPE_GID
44016 + int "GID for trusted users"
44017 + depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
44020 + Setting this GID determines what group TPE restrictions will be
44021 + *disabled* for. If the sysctl option is enabled, a sysctl option
44022 + with name "tpe_gid" is created.
44025 +menu "Network Protections"
44026 +depends on GRKERNSEC
44028 +config GRKERNSEC_RANDNET
44029 + bool "Larger entropy pools"
44031 + If you say Y here, the entropy pools used for many features of Linux
44032 + and grsecurity will be doubled in size. Since several grsecurity
44033 + features use additional randomness, it is recommended that you say Y
44034 + here. Saying Y here has a similar effect as modifying
44035 + /proc/sys/kernel/random/poolsize.
44037 +config GRKERNSEC_BLACKHOLE
44038 + bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
44040 + If you say Y here, neither TCP resets nor ICMP
44041 + destination-unreachable packets will be sent in response to packets
44042 + sent to ports for which no associated listening process exists.
44043 + This feature supports both IPV4 and IPV6 and exempts the
44044 + loopback interface from blackholing. Enabling this feature
44045 + makes a host more resilient to DoS attacks and reduces network
44046 + visibility against scanners.
44048 + The blackhole feature as-implemented is equivalent to the FreeBSD
44049 + blackhole feature, as it prevents RST responses to all packets, not
44050 + just SYNs. Under most application behavior this causes no
44051 + problems, but applications (like haproxy) may not close certain
44052 + connections in a way that cleanly terminates them on the remote
44053 + end, leaving the remote host in LAST_ACK state. Because of this
44054 + side-effect and to prevent intentional LAST_ACK DoSes, this
44055 + feature also adds automatic mitigation against such attacks.
44056 + The mitigation drastically reduces the amount of time a socket
44057 + can spend in LAST_ACK state. If you're using haproxy and not
44058 + all servers it connects to have this option enabled, consider
44059 + disabling this feature on the haproxy host.
44061 + If the sysctl option is enabled, two sysctl options with names
44062 + "ip_blackhole" and "lastack_retries" will be created.
44063 + While "ip_blackhole" takes the standard zero/non-zero on/off
44064 + toggle, "lastack_retries" uses the same kinds of values as
44065 + "tcp_retries1" and "tcp_retries2". The default value of 4
44066 + prevents a socket from lasting more than 45 seconds in LAST_ACK
44069 +config GRKERNSEC_SOCKET
44070 + bool "Socket restrictions"
44072 + If you say Y here, you will be able to choose from several options.
44073 + If you assign a GID on your system and add it to the supplementary
44074 + groups of users you want to restrict socket access to, this patch
44075 + will perform up to three things, based on the option(s) you choose.
44077 +config GRKERNSEC_SOCKET_ALL
44078 + bool "Deny any sockets to group"
44079 + depends on GRKERNSEC_SOCKET
44081 + If you say Y here, you will be able to choose a GID of whose users will
44082 + be unable to connect to other hosts from your machine or run server
44083 + applications from your machine. If the sysctl option is enabled, a
44084 + sysctl option with name "socket_all" is created.
44086 +config GRKERNSEC_SOCKET_ALL_GID
44087 + int "GID to deny all sockets for"
44088 + depends on GRKERNSEC_SOCKET_ALL
44091 + Here you can choose the GID to disable socket access for. Remember to
44092 + add the users you want socket access disabled for to the GID
44093 + specified here. If the sysctl option is enabled, a sysctl option
44094 + with name "socket_all_gid" is created.
44096 +config GRKERNSEC_SOCKET_CLIENT
44097 + bool "Deny client sockets to group"
44098 + depends on GRKERNSEC_SOCKET
44100 + If you say Y here, you will be able to choose a GID of whose users will
44101 + be unable to connect to other hosts from your machine, but will be
44102 + able to run servers. If this option is enabled, all users in the group
44103 + you specify will have to use passive mode when initiating ftp transfers
44104 + from the shell on your machine. If the sysctl option is enabled, a
44105 + sysctl option with name "socket_client" is created.
44107 +config GRKERNSEC_SOCKET_CLIENT_GID
44108 + int "GID to deny client sockets for"
44109 + depends on GRKERNSEC_SOCKET_CLIENT
44112 + Here you can choose the GID to disable client socket access for.
44113 + Remember to add the users you want client socket access disabled for to
44114 + the GID specified here. If the sysctl option is enabled, a sysctl
44115 + option with name "socket_client_gid" is created.
44117 +config GRKERNSEC_SOCKET_SERVER
44118 + bool "Deny server sockets to group"
44119 + depends on GRKERNSEC_SOCKET
44121 + If you say Y here, you will be able to choose a GID of whose users will
44122 + be unable to run server applications from your machine. If the sysctl
44123 + option is enabled, a sysctl option with name "socket_server" is created.
44125 +config GRKERNSEC_SOCKET_SERVER_GID
44126 + int "GID to deny server sockets for"
44127 + depends on GRKERNSEC_SOCKET_SERVER
44130 + Here you can choose the GID to disable server socket access for.
44131 + Remember to add the users you want server socket access disabled for to
44132 + the GID specified here. If the sysctl option is enabled, a sysctl
44133 + option with name "socket_server_gid" is created.
44136 +menu "Sysctl support"
44137 +depends on GRKERNSEC && SYSCTL
44139 +config GRKERNSEC_SYSCTL
44140 + bool "Sysctl support"
44142 + If you say Y here, you will be able to change the options that
44143 + grsecurity runs with at bootup, without having to recompile your
44144 + kernel. You can echo values to files in /proc/sys/kernel/grsecurity
44145 + to enable (1) or disable (0) various features. All the sysctl entries
44146 + are mutable until the "grsec_lock" entry is set to a non-zero value.
44147 + All features enabled in the kernel configuration are disabled at boot
44148 + if you do not say Y to the "Turn on features by default" option.
44149 + All options should be set at startup, and the grsec_lock entry should
44150 + be set to a non-zero value after all the options are set.
44151 + *THIS IS EXTREMELY IMPORTANT*
44153 +config GRKERNSEC_SYSCTL_DISTRO
44154 + bool "Extra sysctl support for distro makers (READ HELP)"
44155 + depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
44157 + If you say Y here, additional sysctl options will be created
44158 + for features that affect processes running as root. Therefore,
44159 + it is critical when using this option that the grsec_lock entry be
44160 + enabled after boot. Only distros with prebuilt kernel packages
44161 + with this option enabled that can ensure grsec_lock is enabled
44162 + after boot should use this option.
44163 + *Failure to set grsec_lock after boot makes all grsec features
44164 + this option covers useless*
44166 + Currently this option creates the following sysctl entries:
44167 + "Disable Privileged I/O": "disable_priv_io"
44169 +config GRKERNSEC_SYSCTL_ON
44170 + bool "Turn on features by default"
44171 + depends on GRKERNSEC_SYSCTL
44173 + If you say Y here, instead of having all features enabled in the
44174 + kernel configuration disabled at boot time, the features will be
44175 + enabled at boot time. It is recommended you say Y here unless
44176 + there is some reason you would want all sysctl-tunable features to
44177 + be disabled by default. As mentioned elsewhere, it is important
44178 + to enable the grsec_lock entry once you have finished modifying
44179 + the sysctl entries.
44182 +menu "Logging Options"
44183 +depends on GRKERNSEC
44185 +config GRKERNSEC_FLOODTIME
44186 + int "Seconds in between log messages (minimum)"
44189 + This option allows you to enforce the number of seconds between
44190 + grsecurity log messages. The default should be suitable for most
44191 + people, however, if you choose to change it, choose a value small enough
44192 + to allow informative logs to be produced, but large enough to
44193 + prevent flooding.
44195 +config GRKERNSEC_FLOODBURST
44196 + int "Number of messages in a burst (maximum)"
44199 + This option allows you to choose the maximum number of messages allowed
44200 + within the flood time interval you chose in a separate option. The
44201 + default should be suitable for most people, however if you find that
44202 + many of your logs are being interpreted as flooding, you may want to
44203 + raise this value.
44208 diff -urNp linux-2.6.37/grsecurity/Makefile linux-2.6.37/grsecurity/Makefile
44209 --- linux-2.6.37/grsecurity/Makefile 1969-12-31 19:00:00.000000000 -0500
44210 +++ linux-2.6.37/grsecurity/Makefile 2011-01-17 02:41:02.000000000 -0500
44212 +# grsecurity's ACL system was originally written in 2001 by Michael Dalton
44213 +# during 2001-2009 it has been completely redesigned by Brad Spengler
44214 +# into an RBAC system
44216 +# All code in this directory and various hooks inserted throughout the kernel
44217 +# are copyright Brad Spengler - Open Source Security, Inc., and released
44218 +# under the GPL v2 or higher
44220 +obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
44221 + grsec_mount.o grsec_sig.o grsec_sock.o grsec_sysctl.o \
44222 + grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
44224 +obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_ip.o gracl_segv.o \
44225 + gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
44226 + gracl_learn.o grsec_log.o
44227 +obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
44229 +ifndef CONFIG_GRKERNSEC
44230 +obj-y += grsec_disabled.o
44233 +ifdef CONFIG_GRKERNSEC_HIDESYM
44234 +extra-y := grsec_hidesym.o
44235 +$(obj)/grsec_hidesym.o:
44236 + @-chmod -f 500 /boot
44237 + @-chmod -f 500 /lib/modules
44239 + @echo ' grsec: protected kernel image paths'
44241 diff -urNp linux-2.6.37/include/acpi/acoutput.h linux-2.6.37/include/acpi/acoutput.h
44242 --- linux-2.6.37/include/acpi/acoutput.h 2011-01-04 19:50:19.000000000 -0500
44243 +++ linux-2.6.37/include/acpi/acoutput.h 2011-01-17 02:41:02.000000000 -0500
44244 @@ -269,8 +269,8 @@
44245 * leaving no executable debug code!
44247 #define ACPI_FUNCTION_NAME(a)
44248 -#define ACPI_DEBUG_PRINT(pl)
44249 -#define ACPI_DEBUG_PRINT_RAW(pl)
44250 +#define ACPI_DEBUG_PRINT(pl) do {} while (0)
44251 +#define ACPI_DEBUG_PRINT_RAW(pl) do {} while (0)
44253 #endif /* ACPI_DEBUG_OUTPUT */
44255 diff -urNp linux-2.6.37/include/acpi/acpi_drivers.h linux-2.6.37/include/acpi/acpi_drivers.h
44256 --- linux-2.6.37/include/acpi/acpi_drivers.h 2011-01-04 19:50:19.000000000 -0500
44257 +++ linux-2.6.37/include/acpi/acpi_drivers.h 2011-01-17 02:41:02.000000000 -0500
44258 @@ -119,8 +119,8 @@ void pci_acpi_crs_quirks(void);
44260 -------------------------------------------------------------------------- */
44261 struct acpi_dock_ops {
44262 - acpi_notify_handler handler;
44263 - acpi_notify_handler uevent;
44264 + const acpi_notify_handler handler;
44265 + const acpi_notify_handler uevent;
44268 #if defined(CONFIG_ACPI_DOCK) || defined(CONFIG_ACPI_DOCK_MODULE)
44269 @@ -128,7 +128,7 @@ extern int is_dock_device(acpi_handle ha
44270 extern int register_dock_notifier(struct notifier_block *nb);
44271 extern void unregister_dock_notifier(struct notifier_block *nb);
44272 extern int register_hotplug_dock_device(acpi_handle handle,
44273 - struct acpi_dock_ops *ops,
44274 + const struct acpi_dock_ops *ops,
44276 extern void unregister_hotplug_dock_device(acpi_handle handle);
44278 @@ -144,7 +144,7 @@ static inline void unregister_dock_notif
44281 static inline int register_hotplug_dock_device(acpi_handle handle,
44282 - struct acpi_dock_ops *ops,
44283 + const struct acpi_dock_ops *ops,
44287 diff -urNp linux-2.6.37/include/asm-generic/atomic-long.h linux-2.6.37/include/asm-generic/atomic-long.h
44288 --- linux-2.6.37/include/asm-generic/atomic-long.h 2011-01-04 19:50:19.000000000 -0500
44289 +++ linux-2.6.37/include/asm-generic/atomic-long.h 2011-01-17 02:41:02.000000000 -0500
44292 typedef atomic64_t atomic_long_t;
44294 +#ifdef CONFIG_PAX_REFCOUNT
44295 +typedef atomic64_unchecked_t atomic_long_unchecked_t;
44297 +typedef atomic64_t atomic_long_unchecked_t;
44300 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
44302 static inline long atomic_long_read(atomic_long_t *l)
44303 @@ -31,6 +37,15 @@ static inline long atomic_long_read(atom
44304 return (long)atomic64_read(v);
44307 +#ifdef CONFIG_PAX_REFCOUNT
44308 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
44310 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
44312 + return (long)atomic64_read_unchecked(v);
44316 static inline void atomic_long_set(atomic_long_t *l, long i)
44318 atomic64_t *v = (atomic64_t *)l;
44319 @@ -38,6 +53,15 @@ static inline void atomic_long_set(atomi
44320 atomic64_set(v, i);
44323 +#ifdef CONFIG_PAX_REFCOUNT
44324 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
44326 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
44328 + atomic64_set_unchecked(v, i);
44332 static inline void atomic_long_inc(atomic_long_t *l)
44334 atomic64_t *v = (atomic64_t *)l;
44335 @@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomi
44339 +#ifdef CONFIG_PAX_REFCOUNT
44340 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
44342 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
44344 + atomic64_inc_unchecked(v);
44348 static inline void atomic_long_dec(atomic_long_t *l)
44350 atomic64_t *v = (atomic64_t *)l;
44351 @@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomi
44355 +#ifdef CONFIG_PAX_REFCOUNT
44356 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
44358 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
44360 + atomic64_dec_unchecked(v);
44364 static inline void atomic_long_add(long i, atomic_long_t *l)
44366 atomic64_t *v = (atomic64_t *)l;
44367 @@ -59,6 +101,15 @@ static inline void atomic_long_add(long
44368 atomic64_add(i, v);
44371 +#ifdef CONFIG_PAX_REFCOUNT
44372 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
44374 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
44376 + atomic64_add_unchecked(i, v);
44380 static inline void atomic_long_sub(long i, atomic_long_t *l)
44382 atomic64_t *v = (atomic64_t *)l;
44383 @@ -66,6 +117,15 @@ static inline void atomic_long_sub(long
44384 atomic64_sub(i, v);
44387 +#ifdef CONFIG_PAX_REFCOUNT
44388 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
44390 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
44392 + atomic64_sub_unchecked(i, v);
44396 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
44398 atomic64_t *v = (atomic64_t *)l;
44399 @@ -115,6 +175,15 @@ static inline long atomic_long_inc_retur
44400 return (long)atomic64_inc_return(v);
44403 +#ifdef CONFIG_PAX_REFCOUNT
44404 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
44406 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
44408 + return (long)atomic64_inc_return_unchecked(v);
44412 static inline long atomic_long_dec_return(atomic_long_t *l)
44414 atomic64_t *v = (atomic64_t *)l;
44415 @@ -140,6 +209,12 @@ static inline long atomic_long_add_unles
44417 typedef atomic_t atomic_long_t;
44419 +#ifdef CONFIG_PAX_REFCOUNT
44420 +typedef atomic_unchecked_t atomic_long_unchecked_t;
44422 +typedef atomic_t atomic_long_unchecked_t;
44425 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
44426 static inline long atomic_long_read(atomic_long_t *l)
44428 @@ -148,6 +223,15 @@ static inline long atomic_long_read(atom
44429 return (long)atomic_read(v);
44432 +#ifdef CONFIG_PAX_REFCOUNT
44433 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
44435 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
44437 + return (long)atomic_read_unchecked(v);
44441 static inline void atomic_long_set(atomic_long_t *l, long i)
44443 atomic_t *v = (atomic_t *)l;
44444 @@ -155,6 +239,15 @@ static inline void atomic_long_set(atomi
44448 +#ifdef CONFIG_PAX_REFCOUNT
44449 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
44451 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
44453 + atomic_set_unchecked(v, i);
44457 static inline void atomic_long_inc(atomic_long_t *l)
44459 atomic_t *v = (atomic_t *)l;
44460 @@ -162,6 +255,15 @@ static inline void atomic_long_inc(atomi
44464 +#ifdef CONFIG_PAX_REFCOUNT
44465 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
44467 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
44469 + atomic_inc_unchecked(v);
44473 static inline void atomic_long_dec(atomic_long_t *l)
44475 atomic_t *v = (atomic_t *)l;
44476 @@ -169,6 +271,15 @@ static inline void atomic_long_dec(atomi
44480 +#ifdef CONFIG_PAX_REFCOUNT
44481 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
44483 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
44485 + atomic_dec_unchecked(v);
44489 static inline void atomic_long_add(long i, atomic_long_t *l)
44491 atomic_t *v = (atomic_t *)l;
44492 @@ -176,6 +287,15 @@ static inline void atomic_long_add(long
44496 +#ifdef CONFIG_PAX_REFCOUNT
44497 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
44499 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
44501 + atomic_add_unchecked(i, v);
44505 static inline void atomic_long_sub(long i, atomic_long_t *l)
44507 atomic_t *v = (atomic_t *)l;
44508 @@ -183,6 +303,15 @@ static inline void atomic_long_sub(long
44512 +#ifdef CONFIG_PAX_REFCOUNT
44513 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
44515 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
44517 + atomic_sub_unchecked(i, v);
44521 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
44523 atomic_t *v = (atomic_t *)l;
44524 @@ -232,6 +361,15 @@ static inline long atomic_long_inc_retur
44525 return (long)atomic_inc_return(v);
44528 +#ifdef CONFIG_PAX_REFCOUNT
44529 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
44531 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
44533 + return (long)atomic_inc_return_unchecked(v);
44537 static inline long atomic_long_dec_return(atomic_long_t *l)
44539 atomic_t *v = (atomic_t *)l;
44540 @@ -255,4 +393,41 @@ static inline long atomic_long_add_unles
44542 #endif /* BITS_PER_LONG == 64 */
44544 +#ifdef CONFIG_PAX_REFCOUNT
44545 +static inline void pax_refcount_needs_these_functions(void)
44547 + atomic_read_unchecked((atomic_unchecked_t *)NULL);
44548 + atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
44549 + atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
44550 + atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
44551 + atomic_inc_unchecked((atomic_unchecked_t *)NULL);
44552 + atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
44553 + atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
44555 + atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
44556 + atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
44557 + atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
44558 + atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
44559 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
44560 + atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
44561 + atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
44564 +#define atomic_read_unchecked(v) atomic_read(v)
44565 +#define atomic_set_unchecked(v, i) atomic_set((v), (i))
44566 +#define atomic_add_unchecked(i, v) atomic_add((i), (v))
44567 +#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
44568 +#define atomic_inc_unchecked(v) atomic_inc(v)
44569 +#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
44570 +#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
44572 +#define atomic_long_read_unchecked(v) atomic_long_read(v)
44573 +#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
44574 +#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
44575 +#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
44576 +#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
44577 +#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
44578 +#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
44581 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
44582 diff -urNp linux-2.6.37/include/asm-generic/dma-mapping-common.h linux-2.6.37/include/asm-generic/dma-mapping-common.h
44583 --- linux-2.6.37/include/asm-generic/dma-mapping-common.h 2011-01-04 19:50:19.000000000 -0500
44584 +++ linux-2.6.37/include/asm-generic/dma-mapping-common.h 2011-01-17 02:41:02.000000000 -0500
44585 @@ -11,7 +11,7 @@ static inline dma_addr_t dma_map_single_
44586 enum dma_data_direction dir,
44587 struct dma_attrs *attrs)
44589 - struct dma_map_ops *ops = get_dma_ops(dev);
44590 + const struct dma_map_ops *ops = get_dma_ops(dev);
44593 kmemcheck_mark_initialized(ptr, size);
44594 @@ -30,7 +30,7 @@ static inline void dma_unmap_single_attr
44595 enum dma_data_direction dir,
44596 struct dma_attrs *attrs)
44598 - struct dma_map_ops *ops = get_dma_ops(dev);
44599 + const struct dma_map_ops *ops = get_dma_ops(dev);
44601 BUG_ON(!valid_dma_direction(dir));
44602 if (ops->unmap_page)
44603 @@ -42,7 +42,7 @@ static inline int dma_map_sg_attrs(struc
44604 int nents, enum dma_data_direction dir,
44605 struct dma_attrs *attrs)
44607 - struct dma_map_ops *ops = get_dma_ops(dev);
44608 + const struct dma_map_ops *ops = get_dma_ops(dev);
44610 struct scatterlist *s;
44612 @@ -59,7 +59,7 @@ static inline void dma_unmap_sg_attrs(st
44613 int nents, enum dma_data_direction dir,
44614 struct dma_attrs *attrs)
44616 - struct dma_map_ops *ops = get_dma_ops(dev);
44617 + const struct dma_map_ops *ops = get_dma_ops(dev);
44619 BUG_ON(!valid_dma_direction(dir));
44620 debug_dma_unmap_sg(dev, sg, nents, dir);
44621 @@ -71,7 +71,7 @@ static inline dma_addr_t dma_map_page(st
44622 size_t offset, size_t size,
44623 enum dma_data_direction dir)
44625 - struct dma_map_ops *ops = get_dma_ops(dev);
44626 + const struct dma_map_ops *ops = get_dma_ops(dev);
44629 kmemcheck_mark_initialized(page_address(page) + offset, size);
44630 @@ -85,7 +85,7 @@ static inline dma_addr_t dma_map_page(st
44631 static inline void dma_unmap_page(struct device *dev, dma_addr_t addr,
44632 size_t size, enum dma_data_direction dir)
44634 - struct dma_map_ops *ops = get_dma_ops(dev);
44635 + const struct dma_map_ops *ops = get_dma_ops(dev);
44637 BUG_ON(!valid_dma_direction(dir));
44638 if (ops->unmap_page)
44639 @@ -97,7 +97,7 @@ static inline void dma_sync_single_for_c
44641 enum dma_data_direction dir)
44643 - struct dma_map_ops *ops = get_dma_ops(dev);
44644 + const struct dma_map_ops *ops = get_dma_ops(dev);
44646 BUG_ON(!valid_dma_direction(dir));
44647 if (ops->sync_single_for_cpu)
44648 @@ -109,7 +109,7 @@ static inline void dma_sync_single_for_d
44649 dma_addr_t addr, size_t size,
44650 enum dma_data_direction dir)
44652 - struct dma_map_ops *ops = get_dma_ops(dev);
44653 + const struct dma_map_ops *ops = get_dma_ops(dev);
44655 BUG_ON(!valid_dma_direction(dir));
44656 if (ops->sync_single_for_device)
44657 @@ -139,7 +139,7 @@ static inline void
44658 dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg,
44659 int nelems, enum dma_data_direction dir)
44661 - struct dma_map_ops *ops = get_dma_ops(dev);
44662 + const struct dma_map_ops *ops = get_dma_ops(dev);
44664 BUG_ON(!valid_dma_direction(dir));
44665 if (ops->sync_sg_for_cpu)
44666 @@ -151,7 +151,7 @@ static inline void
44667 dma_sync_sg_for_device(struct device *dev, struct scatterlist *sg,
44668 int nelems, enum dma_data_direction dir)
44670 - struct dma_map_ops *ops = get_dma_ops(dev);
44671 + const struct dma_map_ops *ops = get_dma_ops(dev);
44673 BUG_ON(!valid_dma_direction(dir));
44674 if (ops->sync_sg_for_device)
44675 diff -urNp linux-2.6.37/include/asm-generic/futex.h linux-2.6.37/include/asm-generic/futex.h
44676 --- linux-2.6.37/include/asm-generic/futex.h 2011-01-04 19:50:19.000000000 -0500
44677 +++ linux-2.6.37/include/asm-generic/futex.h 2011-01-17 02:41:02.000000000 -0500
44679 #include <asm/errno.h>
44682 -futex_atomic_op_inuser (int encoded_op, int __user *uaddr)
44683 +futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
44685 int op = (encoded_op >> 28) & 7;
44686 int cmp = (encoded_op >> 24) & 15;
44687 @@ -48,7 +48,7 @@ futex_atomic_op_inuser (int encoded_op,
44691 -futex_atomic_cmpxchg_inatomic(int __user *uaddr, int oldval, int newval)
44692 +futex_atomic_cmpxchg_inatomic(u32 __user *uaddr, int oldval, int newval)
44696 diff -urNp linux-2.6.37/include/asm-generic/int-l64.h linux-2.6.37/include/asm-generic/int-l64.h
44697 --- linux-2.6.37/include/asm-generic/int-l64.h 2011-01-04 19:50:19.000000000 -0500
44698 +++ linux-2.6.37/include/asm-generic/int-l64.h 2011-01-17 02:41:02.000000000 -0500
44699 @@ -46,6 +46,8 @@ typedef unsigned int u32;
44700 typedef signed long s64;
44701 typedef unsigned long u64;
44703 +typedef unsigned int intoverflow_t __attribute__ ((mode(TI)));
44706 #define U8_C(x) x ## U
44708 diff -urNp linux-2.6.37/include/asm-generic/int-ll64.h linux-2.6.37/include/asm-generic/int-ll64.h
44709 --- linux-2.6.37/include/asm-generic/int-ll64.h 2011-01-04 19:50:19.000000000 -0500
44710 +++ linux-2.6.37/include/asm-generic/int-ll64.h 2011-01-17 02:41:02.000000000 -0500
44711 @@ -51,6 +51,8 @@ typedef unsigned int u32;
44712 typedef signed long long s64;
44713 typedef unsigned long long u64;
44715 +typedef unsigned long long intoverflow_t;
44718 #define U8_C(x) x ## U
44720 diff -urNp linux-2.6.37/include/asm-generic/kmap_types.h linux-2.6.37/include/asm-generic/kmap_types.h
44721 --- linux-2.6.37/include/asm-generic/kmap_types.h 2011-01-04 19:50:19.000000000 -0500
44722 +++ linux-2.6.37/include/asm-generic/kmap_types.h 2011-01-17 02:41:02.000000000 -0500
44723 @@ -29,10 +29,11 @@ KMAP_D(16) KM_IRQ_PTE,
44725 KMAP_D(18) KM_NMI_PTE,
44727 +KMAP_D(20) KM_CLEARPAGE,
44729 * Remember to update debug_kmap_atomic() when adding new kmap types!
44731 -KMAP_D(20) KM_TYPE_NR
44732 +KMAP_D(21) KM_TYPE_NR
44736 diff -urNp linux-2.6.37/include/asm-generic/pgtable.h linux-2.6.37/include/asm-generic/pgtable.h
44737 --- linux-2.6.37/include/asm-generic/pgtable.h 2011-01-04 19:50:19.000000000 -0500
44738 +++ linux-2.6.37/include/asm-generic/pgtable.h 2011-01-17 02:41:02.000000000 -0500
44739 @@ -348,6 +348,14 @@ extern void untrack_pfn_vma(struct vm_ar
44740 unsigned long size);
44743 +#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
44744 +static inline unsigned long pax_open_kernel(void) { return 0; }
44747 +#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
44748 +static inline unsigned long pax_close_kernel(void) { return 0; }
44751 #endif /* !__ASSEMBLY__ */
44753 #endif /* _ASM_GENERIC_PGTABLE_H */
44754 diff -urNp linux-2.6.37/include/asm-generic/pgtable-nopmd.h linux-2.6.37/include/asm-generic/pgtable-nopmd.h
44755 --- linux-2.6.37/include/asm-generic/pgtable-nopmd.h 2011-01-04 19:50:19.000000000 -0500
44756 +++ linux-2.6.37/include/asm-generic/pgtable-nopmd.h 2011-01-17 02:41:02.000000000 -0500
44758 #ifndef _PGTABLE_NOPMD_H
44759 #define _PGTABLE_NOPMD_H
44761 -#ifndef __ASSEMBLY__
44763 #include <asm-generic/pgtable-nopud.h>
44767 #define __PAGETABLE_PMD_FOLDED
44769 +#define PMD_SHIFT PUD_SHIFT
44770 +#define PTRS_PER_PMD 1
44771 +#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
44772 +#define PMD_MASK (~(PMD_SIZE-1))
44774 +#ifndef __ASSEMBLY__
44779 * Having the pmd type consist of a pud gets the size right, and allows
44780 * us to conceptually access the pud entry that this pmd is folded into
44781 @@ -16,11 +21,6 @@ struct mm_struct;
44783 typedef struct { pud_t pud; } pmd_t;
44785 -#define PMD_SHIFT PUD_SHIFT
44786 -#define PTRS_PER_PMD 1
44787 -#define PMD_SIZE (1UL << PMD_SHIFT)
44788 -#define PMD_MASK (~(PMD_SIZE-1))
44791 * The "pud_xxx()" functions here are trivial for a folded two-level
44792 * setup: the pmd is never bad, and a pmd always exists (as it's folded
44793 diff -urNp linux-2.6.37/include/asm-generic/pgtable-nopud.h linux-2.6.37/include/asm-generic/pgtable-nopud.h
44794 --- linux-2.6.37/include/asm-generic/pgtable-nopud.h 2011-01-04 19:50:19.000000000 -0500
44795 +++ linux-2.6.37/include/asm-generic/pgtable-nopud.h 2011-01-17 02:41:02.000000000 -0500
44797 #ifndef _PGTABLE_NOPUD_H
44798 #define _PGTABLE_NOPUD_H
44800 -#ifndef __ASSEMBLY__
44802 #define __PAGETABLE_PUD_FOLDED
44804 +#define PUD_SHIFT PGDIR_SHIFT
44805 +#define PTRS_PER_PUD 1
44806 +#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
44807 +#define PUD_MASK (~(PUD_SIZE-1))
44809 +#ifndef __ASSEMBLY__
44812 * Having the pud type consist of a pgd gets the size right, and allows
44813 * us to conceptually access the pgd entry that this pud is folded into
44816 typedef struct { pgd_t pgd; } pud_t;
44818 -#define PUD_SHIFT PGDIR_SHIFT
44819 -#define PTRS_PER_PUD 1
44820 -#define PUD_SIZE (1UL << PUD_SHIFT)
44821 -#define PUD_MASK (~(PUD_SIZE-1))
44824 * The "pgd_xxx()" functions here are trivial for a folded two-level
44825 * setup: the pud is never bad, and a pud always exists (as it's folded
44826 diff -urNp linux-2.6.37/include/asm-generic/vmlinux.lds.h linux-2.6.37/include/asm-generic/vmlinux.lds.h
44827 --- linux-2.6.37/include/asm-generic/vmlinux.lds.h 2011-01-04 19:50:19.000000000 -0500
44828 +++ linux-2.6.37/include/asm-generic/vmlinux.lds.h 2011-01-17 02:41:02.000000000 -0500
44829 @@ -210,6 +210,7 @@
44830 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
44831 VMLINUX_SYMBOL(__start_rodata) = .; \
44832 *(.rodata) *(.rodata.*) \
44833 + *(.data..read_only) \
44834 *(__vermagic) /* Kernel version magic */ \
44835 *(__markers_strings) /* Markers: strings */ \
44836 *(__tracepoints_strings)/* Tracepoints: strings */ \
44837 @@ -679,14 +680,15 @@
44838 * section in the linker script will go there too. @phdr should have
44841 - * Note that this macros defines __per_cpu_load as an absolute symbol.
44842 + * Note that this macros defines per_cpu_load as an absolute symbol.
44843 * If there is no need to put the percpu section at a predetermined
44844 * address, use PERCPU().
44846 #define PERCPU_VADDR(vaddr, phdr) \
44847 - VMLINUX_SYMBOL(__per_cpu_load) = .; \
44848 - .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
44849 + per_cpu_load = .; \
44850 + .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
44852 + VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
44853 VMLINUX_SYMBOL(__per_cpu_start) = .; \
44854 *(.data..percpu..first) \
44855 . = ALIGN(PAGE_SIZE); \
44856 @@ -696,7 +698,7 @@
44857 *(.data..percpu..shared_aligned) \
44858 VMLINUX_SYMBOL(__per_cpu_end) = .; \
44860 - . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
44861 + . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
44864 * PERCPU - define output section for percpu area, simple version
44865 diff -urNp linux-2.6.37/include/drm/drm_pciids.h linux-2.6.37/include/drm/drm_pciids.h
44866 --- linux-2.6.37/include/drm/drm_pciids.h 2011-01-04 19:50:19.000000000 -0500
44867 +++ linux-2.6.37/include/drm/drm_pciids.h 2011-01-17 02:41:02.000000000 -0500
44868 @@ -419,7 +419,7 @@
44869 {0x1002, 0x9713, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS880|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP|RADEON_IS_IGP}, \
44870 {0x1002, 0x9714, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS880|RADEON_NEW_MEMMAP|RADEON_IS_IGP}, \
44871 {0x1002, 0x9715, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS880|RADEON_NEW_MEMMAP|RADEON_IS_IGP}, \
44873 + {0, 0, 0, 0, 0, 0}
44875 #define r128_PCI_IDS \
44876 {0x1002, 0x4c45, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
44877 @@ -459,14 +459,14 @@
44878 {0x1002, 0x5446, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
44879 {0x1002, 0x544C, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
44880 {0x1002, 0x5452, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
44882 + {0, 0, 0, 0, 0, 0}
44884 #define mga_PCI_IDS \
44885 {0x102b, 0x0520, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MGA_CARD_TYPE_G200}, \
44886 {0x102b, 0x0521, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MGA_CARD_TYPE_G200}, \
44887 {0x102b, 0x0525, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MGA_CARD_TYPE_G400}, \
44888 {0x102b, 0x2527, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MGA_CARD_TYPE_G550}, \
44890 + {0, 0, 0, 0, 0, 0}
44892 #define mach64_PCI_IDS \
44893 {0x1002, 0x4749, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
44894 @@ -489,7 +489,7 @@
44895 {0x1002, 0x4c53, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
44896 {0x1002, 0x4c4d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
44897 {0x1002, 0x4c4e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
44899 + {0, 0, 0, 0, 0, 0}
44901 #define sisdrv_PCI_IDS \
44902 {0x1039, 0x0300, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
44903 @@ -500,7 +500,7 @@
44904 {0x1039, 0x7300, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
44905 {0x18CA, 0x0040, PCI_ANY_ID, PCI_ANY_ID, 0, 0, SIS_CHIP_315}, \
44906 {0x18CA, 0x0042, PCI_ANY_ID, PCI_ANY_ID, 0, 0, SIS_CHIP_315}, \
44908 + {0, 0, 0, 0, 0, 0}
44910 #define tdfx_PCI_IDS \
44911 {0x121a, 0x0003, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
44912 @@ -509,7 +509,7 @@
44913 {0x121a, 0x0007, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
44914 {0x121a, 0x0009, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
44915 {0x121a, 0x000b, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
44917 + {0, 0, 0, 0, 0, 0}
44919 #define viadrv_PCI_IDS \
44920 {0x1106, 0x3022, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
44921 @@ -521,14 +521,14 @@
44922 {0x1106, 0x3343, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
44923 {0x1106, 0x3230, PCI_ANY_ID, PCI_ANY_ID, 0, 0, VIA_DX9_0}, \
44924 {0x1106, 0x3157, PCI_ANY_ID, PCI_ANY_ID, 0, 0, VIA_PRO_GROUP_A}, \
44926 + {0, 0, 0, 0, 0, 0}
44928 #define i810_PCI_IDS \
44929 {0x8086, 0x7121, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
44930 {0x8086, 0x7123, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
44931 {0x8086, 0x7125, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
44932 {0x8086, 0x1132, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
44934 + {0, 0, 0, 0, 0, 0}
44936 #define i830_PCI_IDS \
44937 {0x8086, 0x3577, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
44938 @@ -536,11 +536,11 @@
44939 {0x8086, 0x3582, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
44940 {0x8086, 0x2572, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
44941 {0x8086, 0x358e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
44943 + {0, 0, 0, 0, 0, 0}
44945 #define gamma_PCI_IDS \
44946 {0x3d3d, 0x0008, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
44948 + {0, 0, 0, 0, 0, 0}
44950 #define savage_PCI_IDS \
44951 {0x5333, 0x8a20, PCI_ANY_ID, PCI_ANY_ID, 0, 0, S3_SAVAGE3D}, \
44952 @@ -566,10 +566,10 @@
44953 {0x5333, 0x8d02, PCI_ANY_ID, PCI_ANY_ID, 0, 0, S3_TWISTER}, \
44954 {0x5333, 0x8d03, PCI_ANY_ID, PCI_ANY_ID, 0, 0, S3_PROSAVAGEDDR}, \
44955 {0x5333, 0x8d04, PCI_ANY_ID, PCI_ANY_ID, 0, 0, S3_PROSAVAGEDDR}, \
44957 + {0, 0, 0, 0, 0, 0}
44959 #define ffb_PCI_IDS \
44961 + {0, 0, 0, 0, 0, 0}
44963 #define i915_PCI_IDS \
44964 {0x8086, 0x3577, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_DISPLAY_VGA << 8, 0xffff00, 0}, \
44965 @@ -603,4 +603,4 @@
44966 {0x8086, 0x0042, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_DISPLAY_VGA << 8, 0xffff00, 0}, \
44967 {0x8086, 0x0046, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_DISPLAY_VGA << 8, 0xffff00, 0}, \
44968 {0x8086, 0x0102, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_DISPLAY_VGA << 8, 0xffff00, 0}, \
44970 + {0, 0, 0, 0, 0, 0}
44971 diff -urNp linux-2.6.37/include/drm/drmP.h linux-2.6.37/include/drm/drmP.h
44972 --- linux-2.6.37/include/drm/drmP.h 2011-01-04 19:50:19.000000000 -0500
44973 +++ linux-2.6.37/include/drm/drmP.h 2011-01-17 02:41:02.000000000 -0500
44974 @@ -804,7 +804,7 @@ struct drm_driver {
44975 void (*vgaarb_irq)(struct drm_device *dev, bool state);
44977 /* Driver private ops for this object */
44978 - struct vm_operations_struct *gem_vm_ops;
44979 + const struct vm_operations_struct *gem_vm_ops;
44983 @@ -817,7 +817,7 @@ struct drm_driver {
44985 struct drm_ioctl_desc *ioctls;
44987 - struct file_operations fops;
44988 + const struct file_operations fops;
44989 struct pci_driver pci_driver;
44990 struct platform_device *platform_device;
44991 /* List of devices hanging off this driver */
44992 @@ -914,7 +914,7 @@ struct drm_device {
44994 /** \name Usage Counters */
44996 - int open_count; /**< Outstanding files open */
44997 + atomic_t open_count; /**< Outstanding files open */
44998 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
44999 atomic_t vma_count; /**< Outstanding vma areas open */
45000 int buf_use; /**< Buffers in use -- cannot alloc */
45001 @@ -925,7 +925,7 @@ struct drm_device {
45003 unsigned long counters;
45004 enum drm_stat_type types[15];
45005 - atomic_t counts[15];
45006 + atomic_unchecked_t counts[15];
45009 struct list_head filelist;
45010 diff -urNp linux-2.6.37/include/linux/a.out.h linux-2.6.37/include/linux/a.out.h
45011 --- linux-2.6.37/include/linux/a.out.h 2011-01-04 19:50:19.000000000 -0500
45012 +++ linux-2.6.37/include/linux/a.out.h 2011-01-17 02:41:02.000000000 -0500
45013 @@ -39,6 +39,14 @@ enum machine_type {
45014 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
45017 +/* Constants for the N_FLAGS field */
45018 +#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
45019 +#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
45020 +#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
45021 +#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
45022 +/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
45023 +#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
45025 #if !defined (N_MAGIC)
45026 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
45028 diff -urNp linux-2.6.37/include/linux/atmdev.h linux-2.6.37/include/linux/atmdev.h
45029 --- linux-2.6.37/include/linux/atmdev.h 2011-01-04 19:50:19.000000000 -0500
45030 +++ linux-2.6.37/include/linux/atmdev.h 2011-01-17 02:41:02.000000000 -0500
45031 @@ -237,7 +237,7 @@ struct compat_atm_iobuf {
45034 struct k_atm_aal_stats {
45035 -#define __HANDLE_ITEM(i) atomic_t i
45036 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
45038 #undef __HANDLE_ITEM
45040 diff -urNp linux-2.6.37/include/linux/binfmts.h linux-2.6.37/include/linux/binfmts.h
45041 --- linux-2.6.37/include/linux/binfmts.h 2011-01-04 19:50:19.000000000 -0500
45042 +++ linux-2.6.37/include/linux/binfmts.h 2011-01-17 02:41:02.000000000 -0500
45043 @@ -92,6 +92,7 @@ struct linux_binfmt {
45044 int (*load_binary)(struct linux_binprm *, struct pt_regs * regs);
45045 int (*load_shlib)(struct file *);
45046 int (*core_dump)(struct coredump_params *cprm);
45047 + void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
45048 unsigned long min_coredump; /* minimal dump size */
45051 diff -urNp linux-2.6.37/include/linux/blkdev.h linux-2.6.37/include/linux/blkdev.h
45052 --- linux-2.6.37/include/linux/blkdev.h 2011-01-04 19:50:19.000000000 -0500
45053 +++ linux-2.6.37/include/linux/blkdev.h 2011-01-17 02:41:02.000000000 -0500
45054 @@ -1250,19 +1250,19 @@ queue_max_integrity_segments(struct requ
45055 #endif /* CONFIG_BLK_DEV_INTEGRITY */
45057 struct block_device_operations {
45058 - int (*open) (struct block_device *, fmode_t);
45059 - int (*release) (struct gendisk *, fmode_t);
45060 - int (*ioctl) (struct block_device *, fmode_t, unsigned, unsigned long);
45061 - int (*compat_ioctl) (struct block_device *, fmode_t, unsigned, unsigned long);
45062 - int (*direct_access) (struct block_device *, sector_t,
45063 + int (* const open) (struct block_device *, fmode_t);
45064 + int (* const release) (struct gendisk *, fmode_t);
45065 + int (* const ioctl) (struct block_device *, fmode_t, unsigned, unsigned long);
45066 + int (* const compat_ioctl) (struct block_device *, fmode_t, unsigned, unsigned long);
45067 + int (* const direct_access) (struct block_device *, sector_t,
45068 void **, unsigned long *);
45069 - int (*media_changed) (struct gendisk *);
45070 - void (*unlock_native_capacity) (struct gendisk *);
45071 - int (*revalidate_disk) (struct gendisk *);
45072 - int (*getgeo)(struct block_device *, struct hd_geometry *);
45073 + int (* const media_changed) (struct gendisk *);
45074 + void (* const unlock_native_capacity) (struct gendisk *);
45075 + int (* const revalidate_disk) (struct gendisk *);
45076 + int (* const getgeo)(struct block_device *, struct hd_geometry *);
45077 /* this callback is with swap_lock and sometimes page table lock held */
45078 - void (*swap_slot_free_notify) (struct block_device *, unsigned long);
45079 - struct module *owner;
45080 + void (* const swap_slot_free_notify) (struct block_device *, unsigned long);
45081 + struct module * const owner;
45084 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
45085 diff -urNp linux-2.6.37/include/linux/byteorder/little_endian.h linux-2.6.37/include/linux/byteorder/little_endian.h
45086 --- linux-2.6.37/include/linux/byteorder/little_endian.h 2011-01-04 19:50:19.000000000 -0500
45087 +++ linux-2.6.37/include/linux/byteorder/little_endian.h 2011-01-17 02:41:02.000000000 -0500
45088 @@ -42,51 +42,51 @@
45090 static inline __le64 __cpu_to_le64p(const __u64 *p)
45092 - return (__force __le64)*p;
45093 + return (__force const __le64)*p;
45095 static inline __u64 __le64_to_cpup(const __le64 *p)
45097 - return (__force __u64)*p;
45098 + return (__force const __u64)*p;
45100 static inline __le32 __cpu_to_le32p(const __u32 *p)
45102 - return (__force __le32)*p;
45103 + return (__force const __le32)*p;
45105 static inline __u32 __le32_to_cpup(const __le32 *p)
45107 - return (__force __u32)*p;
45108 + return (__force const __u32)*p;
45110 static inline __le16 __cpu_to_le16p(const __u16 *p)
45112 - return (__force __le16)*p;
45113 + return (__force const __le16)*p;
45115 static inline __u16 __le16_to_cpup(const __le16 *p)
45117 - return (__force __u16)*p;
45118 + return (__force const __u16)*p;
45120 static inline __be64 __cpu_to_be64p(const __u64 *p)
45122 - return (__force __be64)__swab64p(p);
45123 + return (__force const __be64)__swab64p(p);
45125 static inline __u64 __be64_to_cpup(const __be64 *p)
45127 - return __swab64p((__u64 *)p);
45128 + return __swab64p((const __u64 *)p);
45130 static inline __be32 __cpu_to_be32p(const __u32 *p)
45132 - return (__force __be32)__swab32p(p);
45133 + return (__force const __be32)__swab32p(p);
45135 static inline __u32 __be32_to_cpup(const __be32 *p)
45137 - return __swab32p((__u32 *)p);
45138 + return __swab32p((const __u32 *)p);
45140 static inline __be16 __cpu_to_be16p(const __u16 *p)
45142 - return (__force __be16)__swab16p(p);
45143 + return (__force const __be16)__swab16p(p);
45145 static inline __u16 __be16_to_cpup(const __be16 *p)
45147 - return __swab16p((__u16 *)p);
45148 + return __swab16p((const __u16 *)p);
45150 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
45151 #define __le64_to_cpus(x) do { (void)(x); } while (0)
45152 diff -urNp linux-2.6.37/include/linux/cache.h linux-2.6.37/include/linux/cache.h
45153 --- linux-2.6.37/include/linux/cache.h 2011-01-04 19:50:19.000000000 -0500
45154 +++ linux-2.6.37/include/linux/cache.h 2011-01-17 02:41:02.000000000 -0500
45156 #define __read_mostly
45159 +#ifndef __read_only
45160 +#define __read_only __read_mostly
45163 #ifndef ____cacheline_aligned
45164 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
45166 diff -urNp linux-2.6.37/include/linux/capability.h linux-2.6.37/include/linux/capability.h
45167 --- linux-2.6.37/include/linux/capability.h 2011-01-04 19:50:19.000000000 -0500
45168 +++ linux-2.6.37/include/linux/capability.h 2011-01-17 02:41:02.000000000 -0500
45169 @@ -558,6 +558,7 @@ extern const kernel_cap_t __cap_init_eff
45170 (security_real_capable_noaudit((t), (cap)) == 0)
45172 extern int capable(int cap);
45173 +int capable_nolog(int cap);
45175 /* audit system wants to get cap info from files as well */
45177 diff -urNp linux-2.6.37/include/linux/compiler-gcc4.h linux-2.6.37/include/linux/compiler-gcc4.h
45178 --- linux-2.6.37/include/linux/compiler-gcc4.h 2011-01-04 19:50:19.000000000 -0500
45179 +++ linux-2.6.37/include/linux/compiler-gcc4.h 2011-01-17 02:41:02.000000000 -0500
45184 +#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
45185 +#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
45186 +#define __bos0(ptr) __bos((ptr), 0)
45187 +#define __bos1(ptr) __bos((ptr), 1)
45190 #if __GNUC_MINOR__ > 0
45191 diff -urNp linux-2.6.37/include/linux/compiler.h linux-2.6.37/include/linux/compiler.h
45192 --- linux-2.6.37/include/linux/compiler.h 2011-01-04 19:50:19.000000000 -0500
45193 +++ linux-2.6.37/include/linux/compiler.h 2011-01-17 02:41:02.000000000 -0500
45194 @@ -273,6 +273,22 @@ void ftrace_likely_update(struct ftrace_
45198 +#ifndef __alloc_size
45199 +#define __alloc_size
45214 /* Simple shorthand for a section definition */
45216 # define __section(S) __attribute__ ((__section__(#S)))
45217 @@ -306,6 +322,7 @@ void ftrace_likely_update(struct ftrace_
45218 * use is to mediate communication between process-level code and irq/NMI
45219 * handlers, all running on the same CPU.
45221 -#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
45222 +#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
45223 +#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
45225 #endif /* __LINUX_COMPILER_H */
45226 diff -urNp linux-2.6.37/include/linux/cpuset.h linux-2.6.37/include/linux/cpuset.h
45227 --- linux-2.6.37/include/linux/cpuset.h 2011-01-04 19:50:19.000000000 -0500
45228 +++ linux-2.6.37/include/linux/cpuset.h 2011-01-17 02:41:02.000000000 -0500
45229 @@ -118,7 +118,7 @@ static inline void put_mems_allowed(void
45233 - --ACCESS_ONCE(current->mems_allowed_change_disable);
45234 + --ACCESS_ONCE_RW(current->mems_allowed_change_disable);
45237 static inline void set_mems_allowed(nodemask_t nodemask)
45238 diff -urNp linux-2.6.37/include/linux/decompress/mm.h linux-2.6.37/include/linux/decompress/mm.h
45239 --- linux-2.6.37/include/linux/decompress/mm.h 2011-01-04 19:50:19.000000000 -0500
45240 +++ linux-2.6.37/include/linux/decompress/mm.h 2011-01-17 02:41:02.000000000 -0500
45241 @@ -78,7 +78,7 @@ static void free(void *where)
45242 * warnings when not needed (indeed large_malloc / large_free are not
45243 * needed by inflate */
45245 -#define malloc(a) kmalloc(a, GFP_KERNEL)
45246 +#define malloc(a) kmalloc((a), GFP_KERNEL)
45247 #define free(a) kfree(a)
45249 #define large_malloc(a) vmalloc(a)
45250 diff -urNp linux-2.6.37/include/linux/dma-mapping.h linux-2.6.37/include/linux/dma-mapping.h
45251 --- linux-2.6.37/include/linux/dma-mapping.h 2011-01-04 19:50:19.000000000 -0500
45252 +++ linux-2.6.37/include/linux/dma-mapping.h 2011-01-17 02:41:02.000000000 -0500
45253 @@ -16,40 +16,40 @@ enum dma_data_direction {
45256 struct dma_map_ops {
45257 - void* (*alloc_coherent)(struct device *dev, size_t size,
45258 + void* (* const alloc_coherent)(struct device *dev, size_t size,
45259 dma_addr_t *dma_handle, gfp_t gfp);
45260 - void (*free_coherent)(struct device *dev, size_t size,
45261 + void (* const free_coherent)(struct device *dev, size_t size,
45262 void *vaddr, dma_addr_t dma_handle);
45263 - dma_addr_t (*map_page)(struct device *dev, struct page *page,
45264 + dma_addr_t (* const map_page)(struct device *dev, struct page *page,
45265 unsigned long offset, size_t size,
45266 enum dma_data_direction dir,
45267 struct dma_attrs *attrs);
45268 - void (*unmap_page)(struct device *dev, dma_addr_t dma_handle,
45269 + void (* const unmap_page)(struct device *dev, dma_addr_t dma_handle,
45270 size_t size, enum dma_data_direction dir,
45271 struct dma_attrs *attrs);
45272 - int (*map_sg)(struct device *dev, struct scatterlist *sg,
45273 + int (* const map_sg)(struct device *dev, struct scatterlist *sg,
45274 int nents, enum dma_data_direction dir,
45275 struct dma_attrs *attrs);
45276 - void (*unmap_sg)(struct device *dev,
45277 + void (* const unmap_sg)(struct device *dev,
45278 struct scatterlist *sg, int nents,
45279 enum dma_data_direction dir,
45280 struct dma_attrs *attrs);
45281 - void (*sync_single_for_cpu)(struct device *dev,
45282 + void (* const sync_single_for_cpu)(struct device *dev,
45283 dma_addr_t dma_handle, size_t size,
45284 enum dma_data_direction dir);
45285 - void (*sync_single_for_device)(struct device *dev,
45286 + void (* const sync_single_for_device)(struct device *dev,
45287 dma_addr_t dma_handle, size_t size,
45288 enum dma_data_direction dir);
45289 - void (*sync_sg_for_cpu)(struct device *dev,
45290 + void (* const sync_sg_for_cpu)(struct device *dev,
45291 struct scatterlist *sg, int nents,
45292 enum dma_data_direction dir);
45293 - void (*sync_sg_for_device)(struct device *dev,
45294 + void (* const sync_sg_for_device)(struct device *dev,
45295 struct scatterlist *sg, int nents,
45296 enum dma_data_direction dir);
45297 - int (*mapping_error)(struct device *dev, dma_addr_t dma_addr);
45298 - int (*dma_supported)(struct device *dev, u64 mask);
45299 - int (*set_dma_mask)(struct device *dev, u64 mask);
45301 + int (* const mapping_error)(struct device *dev, dma_addr_t dma_addr);
45302 + int (* const dma_supported)(struct device *dev, u64 mask);
45303 + int (* set_dma_mask)(struct device *dev, u64 mask);
45304 + const int is_phys;
45307 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
45308 diff -urNp linux-2.6.37/include/linux/elf.h linux-2.6.37/include/linux/elf.h
45309 --- linux-2.6.37/include/linux/elf.h 2011-01-04 19:50:19.000000000 -0500
45310 +++ linux-2.6.37/include/linux/elf.h 2011-01-17 02:41:02.000000000 -0500
45311 @@ -49,6 +49,17 @@ typedef __s64 Elf64_Sxword;
45312 #define PT_GNU_EH_FRAME 0x6474e550
45314 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
45315 +#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
45317 +#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
45319 +/* Constants for the e_flags field */
45320 +#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
45321 +#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
45322 +#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
45323 +#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
45324 +/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
45325 +#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
45328 * Extended Numbering
45329 @@ -106,6 +117,8 @@ typedef __s64 Elf64_Sxword;
45330 #define DT_DEBUG 21
45331 #define DT_TEXTREL 22
45332 #define DT_JMPREL 23
45333 +#define DT_FLAGS 30
45334 + #define DF_TEXTREL 0x00000004
45335 #define DT_ENCODING 32
45336 #define OLD_DT_LOOS 0x60000000
45337 #define DT_LOOS 0x6000000d
45338 @@ -252,6 +265,19 @@ typedef struct elf64_hdr {
45342 +#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
45343 +#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
45344 +#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
45345 +#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
45346 +#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
45347 +#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
45348 +/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
45349 +/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
45350 +#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
45351 +#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
45352 +#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
45353 +#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
45355 typedef struct elf32_phdr{
45357 Elf32_Off p_offset;
45358 @@ -344,6 +370,8 @@ typedef struct elf64_shdr {
45364 #define ELFMAG0 0x7f /* EI_MAG */
45365 #define ELFMAG1 'E'
45366 #define ELFMAG2 'L'
45367 @@ -421,6 +449,7 @@ extern Elf32_Dyn _DYNAMIC [];
45368 #define elf_note elf32_note
45369 #define elf_addr_t Elf32_Off
45370 #define Elf_Half Elf32_Half
45371 +#define elf_dyn Elf32_Dyn
45375 @@ -431,6 +460,7 @@ extern Elf64_Dyn _DYNAMIC [];
45376 #define elf_note elf64_note
45377 #define elf_addr_t Elf64_Off
45378 #define Elf_Half Elf64_Half
45379 +#define elf_dyn Elf64_Dyn
45383 diff -urNp linux-2.6.37/include/linux/fs.h linux-2.6.37/include/linux/fs.h
45384 --- linux-2.6.37/include/linux/fs.h 2011-01-04 19:50:19.000000000 -0500
45385 +++ linux-2.6.37/include/linux/fs.h 2011-01-17 02:43:32.000000000 -0500
45386 @@ -105,6 +105,11 @@ struct inodes_stat_t {
45387 /* File was opened by fanotify and shouldn't generate fanotify events */
45388 #define FMODE_NONOTIFY ((__force fmode_t)0x1000000)
45390 +/* Hack for grsec so as not to require read permission simply to execute
45393 +#define FMODE_GREXEC ((__force fmode_t)0x2000000)
45396 * The below are the various read and write types that we support. Some of
45397 * them include behavioral modifiers that send information down to the
45398 @@ -578,42 +583,42 @@ typedef int (*read_actor_t)(read_descrip
45399 unsigned long, unsigned long);
45401 struct address_space_operations {
45402 - int (*writepage)(struct page *page, struct writeback_control *wbc);
45403 - int (*readpage)(struct file *, struct page *);
45404 - void (*sync_page)(struct page *);
45405 + int (* const writepage)(struct page *page, struct writeback_control *wbc);
45406 + int (* const readpage)(struct file *, struct page *);
45407 + void (* const sync_page)(struct page *);
45409 /* Write back some dirty pages from this mapping. */
45410 - int (*writepages)(struct address_space *, struct writeback_control *);
45411 + int (* const writepages)(struct address_space *, struct writeback_control *);
45413 /* Set a page dirty. Return true if this dirtied it */
45414 - int (*set_page_dirty)(struct page *page);
45415 + int (* const set_page_dirty)(struct page *page);
45417 - int (*readpages)(struct file *filp, struct address_space *mapping,
45418 + int (* const readpages)(struct file *filp, struct address_space *mapping,
45419 struct list_head *pages, unsigned nr_pages);
45421 - int (*write_begin)(struct file *, struct address_space *mapping,
45422 + int (* const write_begin)(struct file *, struct address_space *mapping,
45423 loff_t pos, unsigned len, unsigned flags,
45424 struct page **pagep, void **fsdata);
45425 - int (*write_end)(struct file *, struct address_space *mapping,
45426 + int (* const write_end)(struct file *, struct address_space *mapping,
45427 loff_t pos, unsigned len, unsigned copied,
45428 struct page *page, void *fsdata);
45430 /* Unfortunately this kludge is needed for FIBMAP. Don't use it */
45431 - sector_t (*bmap)(struct address_space *, sector_t);
45432 - void (*invalidatepage) (struct page *, unsigned long);
45433 - int (*releasepage) (struct page *, gfp_t);
45434 - void (*freepage)(struct page *);
45435 - ssize_t (*direct_IO)(int, struct kiocb *, const struct iovec *iov,
45436 + sector_t (* const bmap)(struct address_space *, sector_t);
45437 + void (* const invalidatepage) (struct page *, unsigned long);
45438 + int (* const releasepage) (struct page *, gfp_t);
45439 + void (* const freepage)(struct page *);
45440 + ssize_t (* const direct_IO)(int, struct kiocb *, const struct iovec *iov,
45441 loff_t offset, unsigned long nr_segs);
45442 - int (*get_xip_mem)(struct address_space *, pgoff_t, int,
45443 + int (* const get_xip_mem)(struct address_space *, pgoff_t, int,
45444 void **, unsigned long *);
45445 /* migrate the contents of a page to the specified target */
45446 - int (*migratepage) (struct address_space *,
45447 + int (* const migratepage) (struct address_space *,
45448 struct page *, struct page *);
45449 - int (*launder_page) (struct page *);
45450 - int (*is_partially_uptodate) (struct page *, read_descriptor_t *,
45451 + int (* const launder_page) (struct page *);
45452 + int (* const is_partially_uptodate) (struct page *, read_descriptor_t *,
45454 - int (*error_remove_page)(struct address_space *, struct page *);
45455 + int (* const error_remove_page)(struct address_space *, struct page *);
45459 @@ -1049,18 +1054,18 @@ static inline int file_check_writeable(s
45460 typedef struct files_struct *fl_owner_t;
45462 struct file_lock_operations {
45463 - void (*fl_copy_lock)(struct file_lock *, struct file_lock *);
45464 - void (*fl_release_private)(struct file_lock *);
45465 + void (* const fl_copy_lock)(struct file_lock *, struct file_lock *);
45466 + void (* const fl_release_private)(struct file_lock *);
45469 struct lock_manager_operations {
45470 - int (*fl_compare_owner)(struct file_lock *, struct file_lock *);
45471 - void (*fl_notify)(struct file_lock *); /* unblock callback */
45472 - int (*fl_grant)(struct file_lock *, struct file_lock *, int);
45473 - void (*fl_release_private)(struct file_lock *);
45474 - void (*fl_break)(struct file_lock *);
45475 - int (*fl_mylease)(struct file_lock *, struct file_lock *);
45476 - int (*fl_change)(struct file_lock **, int);
45477 + int (* const fl_compare_owner)(struct file_lock *, struct file_lock *);
45478 + void (* const fl_notify)(struct file_lock *); /* unblock callback */
45479 + int (* const fl_grant)(struct file_lock *, struct file_lock *, int);
45480 + void (* const fl_release_private)(struct file_lock *);
45481 + void (* const fl_break)(struct file_lock *);
45482 + int (* const fl_mylease)(struct file_lock *, struct file_lock *);
45483 + int (* const fl_change)(struct file_lock **, int);
45486 struct lock_manager {
45487 @@ -1474,7 +1479,7 @@ struct fiemap_extent_info {
45488 unsigned int fi_flags; /* Flags as passed from user */
45489 unsigned int fi_extents_mapped; /* Number of mapped extents */
45490 unsigned int fi_extents_max; /* Size of fiemap_extent array */
45491 - struct fiemap_extent *fi_extents_start; /* Start of fiemap_extent
45492 + struct fiemap_extent __user *fi_extents_start; /* Start of fiemap_extent
45495 int fiemap_fill_next_extent(struct fiemap_extent_info *info, u64 logical,
45496 diff -urNp linux-2.6.37/include/linux/fs_struct.h linux-2.6.37/include/linux/fs_struct.h
45497 --- linux-2.6.37/include/linux/fs_struct.h 2011-01-04 19:50:19.000000000 -0500
45498 +++ linux-2.6.37/include/linux/fs_struct.h 2011-01-17 02:41:02.000000000 -0500
45500 #include <linux/path.h>
45508 diff -urNp linux-2.6.37/include/linux/genhd.h linux-2.6.37/include/linux/genhd.h
45509 --- linux-2.6.37/include/linux/genhd.h 2011-01-04 19:50:19.000000000 -0500
45510 +++ linux-2.6.37/include/linux/genhd.h 2011-01-17 02:41:02.000000000 -0500
45511 @@ -172,7 +172,7 @@ struct gendisk {
45513 struct timer_rand_state *random;
45515 - atomic_t sync_io; /* RAID */
45516 + atomic_unchecked_t sync_io; /* RAID */
45517 struct work_struct async_notify;
45518 #ifdef CONFIG_BLK_DEV_INTEGRITY
45519 struct blk_integrity *integrity;
45520 diff -urNp linux-2.6.37/include/linux/gracl.h linux-2.6.37/include/linux/gracl.h
45521 --- linux-2.6.37/include/linux/gracl.h 1969-12-31 19:00:00.000000000 -0500
45522 +++ linux-2.6.37/include/linux/gracl.h 2011-01-17 02:41:02.000000000 -0500
45527 +#include <linux/grdefs.h>
45528 +#include <linux/resource.h>
45529 +#include <linux/capability.h>
45530 +#include <linux/dcache.h>
45531 +#include <asm/resource.h>
45533 +/* Major status information */
45535 +#define GR_VERSION "grsecurity 2.2.1"
45536 +#define GRSECURITY_VERSION 0x2201
45547 + GR_SPROLEPAM = 8,
45550 +/* Password setup definitions
45551 + * kernel/grhash.c */
45554 + GR_SALT_LEN = 16,
45559 + GR_SPROLE_LEN = 64,
45568 +#define GR_NLIMITS 32
45570 +/* Begin Data Structures */
45572 +struct sprole_pw {
45573 + unsigned char *rolename;
45574 + unsigned char salt[GR_SALT_LEN];
45575 + unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
45578 +struct name_entry {
45585 + struct name_entry *prev;
45586 + struct name_entry *next;
45589 +struct inodev_entry {
45590 + struct name_entry *nentry;
45591 + struct inodev_entry *prev;
45592 + struct inodev_entry *next;
45595 +struct acl_role_db {
45596 + struct acl_role_label **r_hash;
45600 +struct inodev_db {
45601 + struct inodev_entry **i_hash;
45606 + struct name_entry **n_hash;
45610 +struct crash_uid {
45612 + unsigned long expires;
45615 +struct gr_hash_struct {
45617 + void **nametable;
45619 + __u32 table_size;
45624 +/* Userspace Grsecurity ACL data structures */
45626 +struct acl_subject_label {
45631 + kernel_cap_t cap_mask;
45632 + kernel_cap_t cap_lower;
45633 + kernel_cap_t cap_invert_audit;
45635 + struct rlimit res[GR_NLIMITS];
45638 + __u8 user_trans_type;
45639 + __u8 group_trans_type;
45640 + uid_t *user_transitions;
45641 + gid_t *group_transitions;
45642 + __u16 user_trans_num;
45643 + __u16 group_trans_num;
45645 + __u32 sock_families[2];
45646 + __u32 ip_proto[8];
45648 + struct acl_ip_label **ips;
45650 + __u32 inaddr_any_override;
45653 + unsigned long expires;
45655 + struct acl_subject_label *parent_subject;
45656 + struct gr_hash_struct *hash;
45657 + struct acl_subject_label *prev;
45658 + struct acl_subject_label *next;
45660 + struct acl_object_label **obj_hash;
45661 + __u32 obj_hash_size;
45665 +struct role_allowed_ip {
45669 + struct role_allowed_ip *prev;
45670 + struct role_allowed_ip *next;
45673 +struct role_transition {
45676 + struct role_transition *prev;
45677 + struct role_transition *next;
45680 +struct acl_role_label {
45685 + __u16 auth_attempts;
45686 + unsigned long expires;
45688 + struct acl_subject_label *root_label;
45689 + struct gr_hash_struct *hash;
45691 + struct acl_role_label *prev;
45692 + struct acl_role_label *next;
45694 + struct role_transition *transitions;
45695 + struct role_allowed_ip *allowed_ips;
45696 + uid_t *domain_children;
45697 + __u16 domain_child_num;
45699 + struct acl_subject_label **subj_hash;
45700 + __u32 subj_hash_size;
45703 +struct user_acl_role_db {
45704 + struct acl_role_label **r_table;
45705 + __u32 num_pointers; /* Number of allocations to track */
45706 + __u32 num_roles; /* Number of roles */
45707 + __u32 num_domain_children; /* Number of domain children */
45708 + __u32 num_subjects; /* Number of subjects */
45709 + __u32 num_objects; /* Number of objects */
45712 +struct acl_object_label {
45718 + struct acl_subject_label *nested;
45719 + struct acl_object_label *globbed;
45721 + /* next two structures not used */
45723 + struct acl_object_label *prev;
45724 + struct acl_object_label *next;
45727 +struct acl_ip_label {
45736 + /* next two structures not used */
45738 + struct acl_ip_label *prev;
45739 + struct acl_ip_label *next;
45743 + struct user_acl_role_db role_db;
45744 + unsigned char pw[GR_PW_LEN];
45745 + unsigned char salt[GR_SALT_LEN];
45746 + unsigned char sum[GR_SHA_LEN];
45747 + unsigned char sp_role[GR_SPROLE_LEN];
45748 + struct sprole_pw *sprole_pws;
45749 + dev_t segv_device;
45750 + ino_t segv_inode;
45752 + __u16 num_sprole_pws;
45756 +struct gr_arg_wrapper {
45757 + struct gr_arg *arg;
45762 +struct subject_map {
45763 + struct acl_subject_label *user;
45764 + struct acl_subject_label *kernel;
45765 + struct subject_map *prev;
45766 + struct subject_map *next;
45769 +struct acl_subj_map_db {
45770 + struct subject_map **s_hash;
45774 +/* End Data Structures Section */
45776 +/* Hash functions generated by empirical testing by Brad Spengler
45777 + Makes good use of the low bits of the inode. Generally 0-1 times
45778 + in loop for successful match. 0-3 for unsuccessful match.
45779 + Shift/add algorithm with modulus of table size and an XOR*/
45781 +static __inline__ unsigned int
45782 +rhash(const uid_t uid, const __u16 type, const unsigned int sz)
45784 + return ((((uid + type) << (16 + type)) ^ uid) % sz);
45787 + static __inline__ unsigned int
45788 +shash(const struct acl_subject_label *userp, const unsigned int sz)
45790 + return ((const unsigned long)userp % sz);
45793 +static __inline__ unsigned int
45794 +fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
45796 + return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
45799 +static __inline__ unsigned int
45800 +nhash(const char *name, const __u16 len, const unsigned int sz)
45802 + return full_name_hash((const unsigned char *)name, len) % sz;
45805 +#define FOR_EACH_ROLE_START(role) \
45806 + role = role_list; \
45809 +#define FOR_EACH_ROLE_END(role) \
45810 + role = role->prev; \
45813 +#define FOR_EACH_SUBJECT_START(role,subj,iter) \
45816 + while (iter < role->subj_hash_size) { \
45817 + if (subj == NULL) \
45818 + subj = role->subj_hash[iter]; \
45819 + if (subj == NULL) { \
45824 +#define FOR_EACH_SUBJECT_END(subj,iter) \
45825 + subj = subj->next; \
45826 + if (subj == NULL) \
45831 +#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
45832 + subj = role->hash->first; \
45833 + while (subj != NULL) {
45835 +#define FOR_EACH_NESTED_SUBJECT_END(subj) \
45836 + subj = subj->next; \
45841 diff -urNp linux-2.6.37/include/linux/gralloc.h linux-2.6.37/include/linux/gralloc.h
45842 --- linux-2.6.37/include/linux/gralloc.h 1969-12-31 19:00:00.000000000 -0500
45843 +++ linux-2.6.37/include/linux/gralloc.h 2011-01-17 02:41:02.000000000 -0500
45845 +#ifndef __GRALLOC_H
45846 +#define __GRALLOC_H
45848 +void acl_free_all(void);
45849 +int acl_alloc_stack_init(unsigned long size);
45850 +void *acl_alloc(unsigned long len);
45851 +void *acl_alloc_num(unsigned long num, unsigned long len);
45854 diff -urNp linux-2.6.37/include/linux/grdefs.h linux-2.6.37/include/linux/grdefs.h
45855 --- linux-2.6.37/include/linux/grdefs.h 1969-12-31 19:00:00.000000000 -0500
45856 +++ linux-2.6.37/include/linux/grdefs.h 2011-01-17 02:41:02.000000000 -0500
45861 +/* Begin grsecurity status declarations */
45865 + GR_STATUS_INIT = 0x00 // disabled state
45868 +/* Begin ACL declarations */
45873 + GR_ROLE_USER = 0x0001,
45874 + GR_ROLE_GROUP = 0x0002,
45875 + GR_ROLE_DEFAULT = 0x0004,
45876 + GR_ROLE_SPECIAL = 0x0008,
45877 + GR_ROLE_AUTH = 0x0010,
45878 + GR_ROLE_NOPW = 0x0020,
45879 + GR_ROLE_GOD = 0x0040,
45880 + GR_ROLE_LEARN = 0x0080,
45881 + GR_ROLE_TPE = 0x0100,
45882 + GR_ROLE_DOMAIN = 0x0200,
45883 + GR_ROLE_PAM = 0x0400
45886 +/* ACL Subject and Object mode flags */
45888 + GR_DELETED = 0x80000000
45891 +/* ACL Object-only mode flags */
45893 + GR_READ = 0x00000001,
45894 + GR_APPEND = 0x00000002,
45895 + GR_WRITE = 0x00000004,
45896 + GR_EXEC = 0x00000008,
45897 + GR_FIND = 0x00000010,
45898 + GR_INHERIT = 0x00000020,
45899 + GR_SETID = 0x00000040,
45900 + GR_CREATE = 0x00000080,
45901 + GR_DELETE = 0x00000100,
45902 + GR_LINK = 0x00000200,
45903 + GR_AUDIT_READ = 0x00000400,
45904 + GR_AUDIT_APPEND = 0x00000800,
45905 + GR_AUDIT_WRITE = 0x00001000,
45906 + GR_AUDIT_EXEC = 0x00002000,
45907 + GR_AUDIT_FIND = 0x00004000,
45908 + GR_AUDIT_INHERIT= 0x00008000,
45909 + GR_AUDIT_SETID = 0x00010000,
45910 + GR_AUDIT_CREATE = 0x00020000,
45911 + GR_AUDIT_DELETE = 0x00040000,
45912 + GR_AUDIT_LINK = 0x00080000,
45913 + GR_PTRACERD = 0x00100000,
45914 + GR_NOPTRACE = 0x00200000,
45915 + GR_SUPPRESS = 0x00400000,
45916 + GR_NOLEARN = 0x00800000
45919 +#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
45920 + GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
45921 + GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
45923 +/* ACL subject-only mode flags */
45925 + GR_KILL = 0x00000001,
45926 + GR_VIEW = 0x00000002,
45927 + GR_PROTECTED = 0x00000004,
45928 + GR_LEARN = 0x00000008,
45929 + GR_OVERRIDE = 0x00000010,
45930 + /* just a placeholder, this mode is only used in userspace */
45931 + GR_DUMMY = 0x00000020,
45932 + GR_PROTSHM = 0x00000040,
45933 + GR_KILLPROC = 0x00000080,
45934 + GR_KILLIPPROC = 0x00000100,
45935 + /* just a placeholder, this mode is only used in userspace */
45936 + GR_NOTROJAN = 0x00000200,
45937 + GR_PROTPROCFD = 0x00000400,
45938 + GR_PROCACCT = 0x00000800,
45939 + GR_RELAXPTRACE = 0x00001000,
45940 + GR_NESTED = 0x00002000,
45941 + GR_INHERITLEARN = 0x00004000,
45942 + GR_PROCFIND = 0x00008000,
45943 + GR_POVERRIDE = 0x00010000,
45944 + GR_KERNELAUTH = 0x00020000,
45945 + GR_ATSECURE = 0x00040000
45949 + GR_PAX_ENABLE_SEGMEXEC = 0x0001,
45950 + GR_PAX_ENABLE_PAGEEXEC = 0x0002,
45951 + GR_PAX_ENABLE_MPROTECT = 0x0004,
45952 + GR_PAX_ENABLE_RANDMMAP = 0x0008,
45953 + GR_PAX_ENABLE_EMUTRAMP = 0x0010,
45954 + GR_PAX_DISABLE_SEGMEXEC = 0x0100,
45955 + GR_PAX_DISABLE_PAGEEXEC = 0x0200,
45956 + GR_PAX_DISABLE_MPROTECT = 0x0400,
45957 + GR_PAX_DISABLE_RANDMMAP = 0x0800,
45958 + GR_PAX_DISABLE_EMUTRAMP = 0x1000,
45962 + GR_ID_USER = 0x01,
45963 + GR_ID_GROUP = 0x02,
45967 + GR_ID_ALLOW = 0x01,
45968 + GR_ID_DENY = 0x02,
45971 +#define GR_CRASH_RES 31
45972 +#define GR_UIDTABLE_MAX 500
45974 +/* begin resource learning section */
45976 + GR_RLIM_CPU_BUMP = 60,
45977 + GR_RLIM_FSIZE_BUMP = 50000,
45978 + GR_RLIM_DATA_BUMP = 10000,
45979 + GR_RLIM_STACK_BUMP = 1000,
45980 + GR_RLIM_CORE_BUMP = 10000,
45981 + GR_RLIM_RSS_BUMP = 500000,
45982 + GR_RLIM_NPROC_BUMP = 1,
45983 + GR_RLIM_NOFILE_BUMP = 5,
45984 + GR_RLIM_MEMLOCK_BUMP = 50000,
45985 + GR_RLIM_AS_BUMP = 500000,
45986 + GR_RLIM_LOCKS_BUMP = 2,
45987 + GR_RLIM_SIGPENDING_BUMP = 5,
45988 + GR_RLIM_MSGQUEUE_BUMP = 10000,
45989 + GR_RLIM_NICE_BUMP = 1,
45990 + GR_RLIM_RTPRIO_BUMP = 1,
45991 + GR_RLIM_RTTIME_BUMP = 1000000
45995 diff -urNp linux-2.6.37/include/linux/grinternal.h linux-2.6.37/include/linux/grinternal.h
45996 --- linux-2.6.37/include/linux/grinternal.h 1969-12-31 19:00:00.000000000 -0500
45997 +++ linux-2.6.37/include/linux/grinternal.h 2011-01-17 02:41:02.000000000 -0500
45999 +#ifndef __GRINTERNAL_H
46000 +#define __GRINTERNAL_H
46002 +#ifdef CONFIG_GRKERNSEC
46004 +#include <linux/fs.h>
46005 +#include <linux/mnt_namespace.h>
46006 +#include <linux/nsproxy.h>
46007 +#include <linux/gracl.h>
46008 +#include <linux/grdefs.h>
46009 +#include <linux/grmsg.h>
46011 +void gr_add_learn_entry(const char *fmt, ...)
46012 + __attribute__ ((format (printf, 1, 2)));
46013 +__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
46014 + const struct vfsmount *mnt);
46015 +__u32 gr_check_create(const struct dentry *new_dentry,
46016 + const struct dentry *parent,
46017 + const struct vfsmount *mnt, const __u32 mode);
46018 +int gr_check_protected_task(const struct task_struct *task);
46019 +__u32 to_gr_audit(const __u32 reqmode);
46020 +int gr_set_acls(const int type);
46022 +int gr_acl_is_enabled(void);
46023 +char gr_roletype_to_char(void);
46025 +void gr_handle_alertkill(struct task_struct *task);
46026 +char *gr_to_filename(const struct dentry *dentry,
46027 + const struct vfsmount *mnt);
46028 +char *gr_to_filename1(const struct dentry *dentry,
46029 + const struct vfsmount *mnt);
46030 +char *gr_to_filename2(const struct dentry *dentry,
46031 + const struct vfsmount *mnt);
46032 +char *gr_to_filename3(const struct dentry *dentry,
46033 + const struct vfsmount *mnt);
46035 +extern int grsec_enable_harden_ptrace;
46036 +extern int grsec_enable_link;
46037 +extern int grsec_enable_fifo;
46038 +extern int grsec_enable_execve;
46039 +extern int grsec_enable_shm;
46040 +extern int grsec_enable_execlog;
46041 +extern int grsec_enable_signal;
46042 +extern int grsec_enable_audit_ptrace;
46043 +extern int grsec_enable_forkfail;
46044 +extern int grsec_enable_time;
46045 +extern int grsec_enable_rofs;
46046 +extern int grsec_enable_chroot_shmat;
46047 +extern int grsec_enable_chroot_findtask;
46048 +extern int grsec_enable_chroot_mount;
46049 +extern int grsec_enable_chroot_double;
46050 +extern int grsec_enable_chroot_pivot;
46051 +extern int grsec_enable_chroot_chdir;
46052 +extern int grsec_enable_chroot_chmod;
46053 +extern int grsec_enable_chroot_mknod;
46054 +extern int grsec_enable_chroot_fchdir;
46055 +extern int grsec_enable_chroot_nice;
46056 +extern int grsec_enable_chroot_execlog;
46057 +extern int grsec_enable_chroot_caps;
46058 +extern int grsec_enable_chroot_sysctl;
46059 +extern int grsec_enable_chroot_unix;
46060 +extern int grsec_enable_tpe;
46061 +extern int grsec_tpe_gid;
46062 +extern int grsec_enable_tpe_all;
46063 +extern int grsec_enable_tpe_invert;
46064 +extern int grsec_enable_socket_all;
46065 +extern int grsec_socket_all_gid;
46066 +extern int grsec_enable_socket_client;
46067 +extern int grsec_socket_client_gid;
46068 +extern int grsec_enable_socket_server;
46069 +extern int grsec_socket_server_gid;
46070 +extern int grsec_audit_gid;
46071 +extern int grsec_enable_group;
46072 +extern int grsec_enable_audit_textrel;
46073 +extern int grsec_enable_log_rwxmaps;
46074 +extern int grsec_enable_mount;
46075 +extern int grsec_enable_chdir;
46076 +extern int grsec_resource_logging;
46077 +extern int grsec_enable_blackhole;
46078 +extern int grsec_lastack_retries;
46079 +extern int grsec_lock;
46081 +extern spinlock_t grsec_alert_lock;
46082 +extern unsigned long grsec_alert_wtime;
46083 +extern unsigned long grsec_alert_fyet;
46085 +extern spinlock_t grsec_audit_lock;
46087 +extern rwlock_t grsec_exec_file_lock;
46089 +#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
46090 + gr_to_filename2((tsk)->exec_file->f_path.dentry, \
46091 + (tsk)->exec_file->f_vfsmnt) : "/")
46093 +#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
46094 + gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
46095 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
46097 +#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
46098 + gr_to_filename((tsk)->exec_file->f_path.dentry, \
46099 + (tsk)->exec_file->f_vfsmnt) : "/")
46101 +#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
46102 + gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
46103 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
46105 +#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
46107 +#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
46109 +#define DEFAULTSECARGS(task, cred, pcred) gr_task_fullpath(task), (task)->comm, \
46110 + (task)->pid, (cred)->uid, \
46111 + (cred)->euid, (cred)->gid, (cred)->egid, \
46112 + gr_parent_task_fullpath(task), \
46113 + (task)->real_parent->comm, (task)->real_parent->pid, \
46114 + (pcred)->uid, (pcred)->euid, \
46115 + (pcred)->gid, (pcred)->egid
46117 +#define GR_CHROOT_CAPS {{ \
46118 + CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
46119 + CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
46120 + CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
46121 + CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
46122 + CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
46123 + CAP_TO_MASK(CAP_IPC_OWNER) , 0 }}
46125 +#define security_learn(normal_msg,args...) \
46127 + read_lock(&grsec_exec_file_lock); \
46128 + gr_add_learn_entry(normal_msg "\n", ## args); \
46129 + read_unlock(&grsec_exec_file_lock); \
46135 + GR_DONT_AUDIT_GOOD
46146 + GR_SYSCTL_HIDDEN,
46149 + GR_ONE_INT_TWO_STR,
46155 + GR_FIVE_INT_TWO_STR,
46161 + GR_FILENAME_TWO_INT,
46162 + GR_FILENAME_TWO_INT_STR,
46175 +#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
46176 +#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
46177 +#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
46178 +#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
46179 +#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
46180 +#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
46181 +#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)
46182 +#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
46183 +#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
46184 +#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
46185 +#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
46186 +#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
46187 +#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
46188 +#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
46189 +#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
46190 +#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)
46191 +#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
46192 +#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
46193 +#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
46194 +#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
46195 +#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
46196 +#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
46197 +#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
46198 +#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)
46199 +#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
46200 +#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
46201 +#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
46202 +#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
46203 +#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
46204 +#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
46205 +#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
46206 +#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
46207 +#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)
46208 +#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
46210 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
46215 diff -urNp linux-2.6.37/include/linux/grmsg.h linux-2.6.37/include/linux/grmsg.h
46216 --- linux-2.6.37/include/linux/grmsg.h 1969-12-31 19:00:00.000000000 -0500
46217 +++ linux-2.6.37/include/linux/grmsg.h 2011-01-17 02:41:02.000000000 -0500
46219 +#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"
46220 +#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"
46221 +#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
46222 +#define GR_STOPMOD_MSG "denied modification of module state by "
46223 +#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
46224 +#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
46225 +#define GR_IOPERM_MSG "denied use of ioperm() by "
46226 +#define GR_IOPL_MSG "denied use of iopl() by "
46227 +#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
46228 +#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
46229 +#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
46230 +#define GR_KMEM_MSG "denied write of /dev/kmem by "
46231 +#define GR_PORT_OPEN_MSG "denied open of /dev/port by "
46232 +#define GR_MEM_WRITE_MSG "denied write of /dev/mem by "
46233 +#define GR_MEM_MMAP_MSG "denied mmap write of /dev/[k]mem by "
46234 +#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
46235 +#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"
46236 +#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"
46237 +#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
46238 +#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
46239 +#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
46240 +#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
46241 +#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
46242 +#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
46243 +#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
46244 +#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
46245 +#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
46246 +#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
46247 +#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
46248 +#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
46249 +#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
46250 +#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
46251 +#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
46252 +#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
46253 +#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
46254 +#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
46255 +#define GR_NPROC_MSG "denied overstep of process limit by "
46256 +#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
46257 +#define GR_EXEC_TPE_MSG "denied untrusted exec of %.950s by "
46258 +#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
46259 +#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
46260 +#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
46261 +#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
46262 +#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
46263 +#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
46264 +#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
46265 +#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
46266 +#define GR_FCHMOD_ACL_MSG "%s fchmod of %.950s by "
46267 +#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
46268 +#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
46269 +#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
46270 +#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
46271 +#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
46272 +#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
46273 +#define GR_INITF_ACL_MSG "init_variables() failed %s by "
46274 +#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"
46275 +#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbaged by "
46276 +#define GR_SHUTS_ACL_MSG "shutdown auth success for "
46277 +#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
46278 +#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
46279 +#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
46280 +#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
46281 +#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
46282 +#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
46283 +#define GR_ENABLEF_ACL_MSG "unable to load %s for "
46284 +#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
46285 +#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
46286 +#define GR_RELOADF_ACL_MSG "failed reload of %s for "
46287 +#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
46288 +#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
46289 +#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
46290 +#define GR_SPROLEF_ACL_MSG "special role %s failure for "
46291 +#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
46292 +#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
46293 +#define GR_INVMODE_ACL_MSG "invalid mode %d by "
46294 +#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
46295 +#define GR_FAILFORK_MSG "failed fork with errno %s by "
46296 +#define GR_NICE_CHROOT_MSG "denied priority change by "
46297 +#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
46298 +#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
46299 +#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
46300 +#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
46301 +#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
46302 +#define GR_TIME_MSG "time set by "
46303 +#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
46304 +#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
46305 +#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
46306 +#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
46307 +#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
46308 +#define GR_BIND_MSG "denied bind() by "
46309 +#define GR_CONNECT_MSG "denied connect() by "
46310 +#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
46311 +#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
46312 +#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"
46313 +#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
46314 +#define GR_CAP_ACL_MSG "use of %s denied for "
46315 +#define GR_CAP_ACL_MSG2 "use of %s permitted for "
46316 +#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
46317 +#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
46318 +#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
46319 +#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
46320 +#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
46321 +#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
46322 +#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
46323 +#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
46324 +#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
46325 +#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
46326 +#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
46327 +#define GR_NONROOT_MODLOAD_MSG "denied kernel module auto-load of %.64s by "
46328 +#define GR_VM86_MSG "denied use of vm86 by "
46329 +#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
46330 diff -urNp linux-2.6.37/include/linux/grsecurity.h linux-2.6.37/include/linux/grsecurity.h
46331 --- linux-2.6.37/include/linux/grsecurity.h 1969-12-31 19:00:00.000000000 -0500
46332 +++ linux-2.6.37/include/linux/grsecurity.h 2011-01-17 02:41:02.000000000 -0500
46334 +#ifndef GR_SECURITY_H
46335 +#define GR_SECURITY_H
46336 +#include <linux/fs.h>
46337 +#include <linux/fs_struct.h>
46338 +#include <linux/binfmts.h>
46339 +#include <linux/gracl.h>
46340 +#include <linux/compat.h>
46342 +/* notify of brain-dead configs */
46343 +#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
46344 +#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
46346 +#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_EI_PAX) && !defined(CONFIG_PAX_PT_PAX_FLAGS)
46347 +#error "CONFIG_PAX_NOEXEC enabled, but neither CONFIG_PAX_EI_PAX nor CONFIG_PAX_PT_PAX_FLAGS are enabled."
46349 +#if defined(CONFIG_PAX_ASLR) && (defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)) && !defined(CONFIG_PAX_EI_PAX) && !defined(CONFIG_PAX_PT_PAX_FLAGS)
46350 +#error "CONFIG_PAX_ASLR enabled, but neither CONFIG_PAX_EI_PAX nor CONFIG_PAX_PT_PAX_FLAGS are enabled."
46352 +#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
46353 +#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
46355 +#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
46356 +#error "CONFIG_PAX enabled, but no PaX options are enabled."
46359 +void gr_handle_brute_attach(struct task_struct *p);
46360 +void gr_handle_brute_check(void);
46362 +char gr_roletype_to_char(void);
46364 +int gr_acl_enable_at_secure(void);
46366 +int gr_check_user_change(int real, int effective, int fs);
46367 +int gr_check_group_change(int real, int effective, int fs);
46369 +void gr_del_task_from_ip_table(struct task_struct *p);
46371 +int gr_pid_is_chrooted(struct task_struct *p);
46372 +int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
46373 +int gr_handle_chroot_nice(void);
46374 +int gr_handle_chroot_sysctl(const int op);
46375 +int gr_handle_chroot_setpriority(struct task_struct *p,
46376 + const int niceval);
46377 +int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
46378 +int gr_handle_chroot_chroot(const struct dentry *dentry,
46379 + const struct vfsmount *mnt);
46380 +int gr_handle_chroot_caps(struct path *path);
46381 +void gr_handle_chroot_chdir(struct path *path);
46382 +int gr_handle_chroot_chmod(const struct dentry *dentry,
46383 + const struct vfsmount *mnt, const int mode);
46384 +int gr_handle_chroot_mknod(const struct dentry *dentry,
46385 + const struct vfsmount *mnt, const int mode);
46386 +int gr_handle_chroot_mount(const struct dentry *dentry,
46387 + const struct vfsmount *mnt,
46388 + const char *dev_name);
46389 +int gr_handle_chroot_pivot(void);
46390 +int gr_handle_chroot_unix(struct pid *pid);
46392 +int gr_handle_rawio(const struct inode *inode);
46393 +int gr_handle_nproc(void);
46395 +void gr_handle_ioperm(void);
46396 +void gr_handle_iopl(void);
46398 +int gr_tpe_allow(const struct file *file);
46400 +void gr_set_chroot_entries(struct task_struct *task, struct path *path);
46401 +void gr_clear_chroot_entries(struct task_struct *task);
46403 +void gr_log_forkfail(const int retval);
46404 +void gr_log_timechange(void);
46405 +void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
46406 +void gr_log_chdir(const struct dentry *dentry,
46407 + const struct vfsmount *mnt);
46408 +void gr_log_chroot_exec(const struct dentry *dentry,
46409 + const struct vfsmount *mnt);
46410 +void gr_handle_exec_args(struct linux_binprm *bprm, const char __user *const __user *argv);
46411 +#ifdef CONFIG_COMPAT
46412 +void gr_handle_exec_args_compat(struct linux_binprm *bprm, compat_uptr_t __user *argv);
46414 +void gr_log_remount(const char *devname, const int retval);
46415 +void gr_log_unmount(const char *devname, const int retval);
46416 +void gr_log_mount(const char *from, const char *to, const int retval);
46417 +void gr_log_textrel(struct vm_area_struct *vma);
46418 +void gr_log_rwxmmap(struct file *file);
46419 +void gr_log_rwxmprotect(struct file *file);
46421 +int gr_handle_follow_link(const struct inode *parent,
46422 + const struct inode *inode,
46423 + const struct dentry *dentry,
46424 + const struct vfsmount *mnt);
46425 +int gr_handle_fifo(const struct dentry *dentry,
46426 + const struct vfsmount *mnt,
46427 + const struct dentry *dir, const int flag,
46428 + const int acc_mode);
46429 +int gr_handle_hardlink(const struct dentry *dentry,
46430 + const struct vfsmount *mnt,
46431 + struct inode *inode,
46432 + const int mode, const char *to);
46434 +int gr_is_capable(const int cap);
46435 +int gr_is_capable_nolog(const int cap);
46436 +void gr_learn_resource(const struct task_struct *task, const int limit,
46437 + const unsigned long wanted, const int gt);
46438 +void gr_copy_label(struct task_struct *tsk);
46439 +void gr_handle_crash(struct task_struct *task, const int sig);
46440 +int gr_handle_signal(const struct task_struct *p, const int sig);
46441 +int gr_check_crash_uid(const uid_t uid);
46442 +int gr_check_protected_task(const struct task_struct *task);
46443 +int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
46444 +int gr_acl_handle_mmap(const struct file *file,
46445 + const unsigned long prot);
46446 +int gr_acl_handle_mprotect(const struct file *file,
46447 + const unsigned long prot);
46448 +int gr_check_hidden_task(const struct task_struct *tsk);
46449 +__u32 gr_acl_handle_truncate(const struct dentry *dentry,
46450 + const struct vfsmount *mnt);
46451 +__u32 gr_acl_handle_utime(const struct dentry *dentry,
46452 + const struct vfsmount *mnt);
46453 +__u32 gr_acl_handle_access(const struct dentry *dentry,
46454 + const struct vfsmount *mnt, const int fmode);
46455 +__u32 gr_acl_handle_fchmod(const struct dentry *dentry,
46456 + const struct vfsmount *mnt, mode_t mode);
46457 +__u32 gr_acl_handle_chmod(const struct dentry *dentry,
46458 + const struct vfsmount *mnt, mode_t mode);
46459 +__u32 gr_acl_handle_chown(const struct dentry *dentry,
46460 + const struct vfsmount *mnt);
46461 +__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
46462 + const struct vfsmount *mnt);
46463 +int gr_handle_ptrace(struct task_struct *task, const long request);
46464 +int gr_handle_proc_ptrace(struct task_struct *task);
46465 +__u32 gr_acl_handle_execve(const struct dentry *dentry,
46466 + const struct vfsmount *mnt);
46467 +int gr_check_crash_exec(const struct file *filp);
46468 +int gr_acl_is_enabled(void);
46469 +void gr_set_kernel_label(struct task_struct *task);
46470 +void gr_set_role_label(struct task_struct *task, const uid_t uid,
46471 + const gid_t gid);
46472 +int gr_set_proc_label(const struct dentry *dentry,
46473 + const struct vfsmount *mnt,
46474 + const int unsafe_share);
46475 +__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
46476 + const struct vfsmount *mnt);
46477 +__u32 gr_acl_handle_open(const struct dentry *dentry,
46478 + const struct vfsmount *mnt, const int fmode);
46479 +__u32 gr_acl_handle_creat(const struct dentry *dentry,
46480 + const struct dentry *p_dentry,
46481 + const struct vfsmount *p_mnt, const int fmode,
46482 + const int imode);
46483 +void gr_handle_create(const struct dentry *dentry,
46484 + const struct vfsmount *mnt);
46485 +__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
46486 + const struct dentry *parent_dentry,
46487 + const struct vfsmount *parent_mnt,
46489 +__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
46490 + const struct dentry *parent_dentry,
46491 + const struct vfsmount *parent_mnt);
46492 +__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
46493 + const struct vfsmount *mnt);
46494 +void gr_handle_delete(const ino_t ino, const dev_t dev);
46495 +__u32 gr_acl_handle_unlink(const struct dentry *dentry,
46496 + const struct vfsmount *mnt);
46497 +__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
46498 + const struct dentry *parent_dentry,
46499 + const struct vfsmount *parent_mnt,
46500 + const char *from);
46501 +__u32 gr_acl_handle_link(const struct dentry *new_dentry,
46502 + const struct dentry *parent_dentry,
46503 + const struct vfsmount *parent_mnt,
46504 + const struct dentry *old_dentry,
46505 + const struct vfsmount *old_mnt, const char *to);
46506 +int gr_acl_handle_rename(struct dentry *new_dentry,
46507 + struct dentry *parent_dentry,
46508 + const struct vfsmount *parent_mnt,
46509 + struct dentry *old_dentry,
46510 + struct inode *old_parent_inode,
46511 + struct vfsmount *old_mnt, const char *newname);
46512 +void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
46513 + struct dentry *old_dentry,
46514 + struct dentry *new_dentry,
46515 + struct vfsmount *mnt, const __u8 replace);
46516 +__u32 gr_check_link(const struct dentry *new_dentry,
46517 + const struct dentry *parent_dentry,
46518 + const struct vfsmount *parent_mnt,
46519 + const struct dentry *old_dentry,
46520 + const struct vfsmount *old_mnt);
46521 +int gr_acl_handle_filldir(const struct file *file, const char *name,
46522 + const unsigned int namelen, const ino_t ino);
46524 +__u32 gr_acl_handle_unix(const struct dentry *dentry,
46525 + const struct vfsmount *mnt);
46526 +void gr_acl_handle_exit(void);
46527 +void gr_acl_handle_psacct(struct task_struct *task, const long code);
46528 +int gr_acl_handle_procpidmem(const struct task_struct *task);
46529 +int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
46530 +int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
46531 +void gr_audit_ptrace(struct task_struct *task);
46533 +#ifdef CONFIG_GRKERNSEC
46534 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
46535 +void gr_log_nonroot_mod_load(const char *modname);
46536 +void gr_handle_vm86(void);
46537 +void gr_handle_mem_write(void);
46538 +void gr_handle_kmem_write(void);
46539 +void gr_handle_open_port(void);
46540 +int gr_handle_mem_mmap(const unsigned long offset,
46541 + struct vm_area_struct *vma);
46543 +extern int grsec_enable_dmesg;
46544 +extern int grsec_disable_privio;
46548 diff -urNp linux-2.6.37/include/linux/grsock.h linux-2.6.37/include/linux/grsock.h
46549 --- linux-2.6.37/include/linux/grsock.h 1969-12-31 19:00:00.000000000 -0500
46550 +++ linux-2.6.37/include/linux/grsock.h 2011-01-17 02:41:02.000000000 -0500
46552 +#ifndef __GRSOCK_H
46553 +#define __GRSOCK_H
46555 +extern void gr_attach_curr_ip(const struct sock *sk);
46556 +extern int gr_handle_sock_all(const int family, const int type,
46557 + const int protocol);
46558 +extern int gr_handle_sock_server(const struct sockaddr *sck);
46559 +extern int gr_handle_sock_server_other(const struct sock *sck);
46560 +extern int gr_handle_sock_client(const struct sockaddr *sck);
46561 +extern int gr_search_connect(struct socket * sock,
46562 + struct sockaddr_in * addr);
46563 +extern int gr_search_bind(struct socket * sock,
46564 + struct sockaddr_in * addr);
46565 +extern int gr_search_listen(struct socket * sock);
46566 +extern int gr_search_accept(struct socket * sock);
46567 +extern int gr_search_socket(const int domain, const int type,
46568 + const int protocol);
46571 diff -urNp linux-2.6.37/include/linux/highmem.h linux-2.6.37/include/linux/highmem.h
46572 --- linux-2.6.37/include/linux/highmem.h 2011-01-04 19:50:19.000000000 -0500
46573 +++ linux-2.6.37/include/linux/highmem.h 2011-01-17 02:41:02.000000000 -0500
46574 @@ -182,6 +182,18 @@ static inline void clear_highpage(struct
46575 kunmap_atomic(kaddr, KM_USER0);
46578 +static inline void sanitize_highpage(struct page *page)
46581 + unsigned long flags;
46583 + local_irq_save(flags);
46584 + kaddr = kmap_atomic(page, KM_CLEARPAGE);
46585 + clear_page(kaddr);
46586 + kunmap_atomic(kaddr, KM_CLEARPAGE);
46587 + local_irq_restore(flags);
46590 static inline void zero_user_segments(struct page *page,
46591 unsigned start1, unsigned end1,
46592 unsigned start2, unsigned end2)
46593 diff -urNp linux-2.6.37/include/linux/init.h linux-2.6.37/include/linux/init.h
46594 --- linux-2.6.37/include/linux/init.h 2011-01-04 19:50:19.000000000 -0500
46595 +++ linux-2.6.37/include/linux/init.h 2011-01-17 02:41:02.000000000 -0500
46596 @@ -293,13 +293,13 @@ void __init parse_early_options(char *cm
46598 /* Each module must use one module_init(). */
46599 #define module_init(initfn) \
46600 - static inline initcall_t __inittest(void) \
46601 + static inline __used initcall_t __inittest(void) \
46602 { return initfn; } \
46603 int init_module(void) __attribute__((alias(#initfn)));
46605 /* This is only required if you want to be unloadable. */
46606 #define module_exit(exitfn) \
46607 - static inline exitcall_t __exittest(void) \
46608 + static inline __used exitcall_t __exittest(void) \
46609 { return exitfn; } \
46610 void cleanup_module(void) __attribute__((alias(#exitfn)));
46612 diff -urNp linux-2.6.37/include/linux/interrupt.h linux-2.6.37/include/linux/interrupt.h
46613 --- linux-2.6.37/include/linux/interrupt.h 2011-01-04 19:50:19.000000000 -0500
46614 +++ linux-2.6.37/include/linux/interrupt.h 2011-01-17 02:41:02.000000000 -0500
46615 @@ -393,7 +393,7 @@ enum
46616 /* map softirq index to softirq name. update 'softirq_to_name' in
46617 * kernel/softirq.c when adding a new softirq.
46619 -extern char *softirq_to_name[NR_SOFTIRQS];
46620 +extern const char * const softirq_to_name[NR_SOFTIRQS];
46622 /* softirq mask and active fields moved to irq_cpustat_t in
46623 * asm/hardirq.h to get better cache usage. KAO
46624 @@ -401,12 +401,12 @@ extern char *softirq_to_name[NR_SOFTIRQS
46626 struct softirq_action
46628 - void (*action)(struct softirq_action *);
46629 + void (*action)(void);
46632 asmlinkage void do_softirq(void);
46633 asmlinkage void __do_softirq(void);
46634 -extern void open_softirq(int nr, void (*action)(struct softirq_action *));
46635 +extern void open_softirq(int nr, void (*action)(void));
46636 extern void softirq_init(void);
46637 static inline void __raise_softirq_irqoff(unsigned int nr)
46639 diff -urNp linux-2.6.37/include/linux/jbd2.h linux-2.6.37/include/linux/jbd2.h
46640 --- linux-2.6.37/include/linux/jbd2.h 2011-01-04 19:50:19.000000000 -0500
46641 +++ linux-2.6.37/include/linux/jbd2.h 2011-01-17 02:41:02.000000000 -0500
46642 @@ -67,7 +67,7 @@ extern u8 jbd2_journal_enable_debug;
46646 -#define jbd_debug(f, a...) /**/
46647 +#define jbd_debug(f, a...) do {} while (0)
46650 extern void *jbd2_alloc(size_t size, gfp_t flags);
46651 diff -urNp linux-2.6.37/include/linux/jbd.h linux-2.6.37/include/linux/jbd.h
46652 --- linux-2.6.37/include/linux/jbd.h 2011-01-04 19:50:19.000000000 -0500
46653 +++ linux-2.6.37/include/linux/jbd.h 2011-01-17 02:41:02.000000000 -0500
46654 @@ -67,7 +67,7 @@ extern u8 journal_enable_debug;
46658 -#define jbd_debug(f, a...) /**/
46659 +#define jbd_debug(f, a...) do {} while (0)
46662 static inline void *jbd_alloc(size_t size, gfp_t flags)
46663 diff -urNp linux-2.6.37/include/linux/kallsyms.h linux-2.6.37/include/linux/kallsyms.h
46664 --- linux-2.6.37/include/linux/kallsyms.h 2011-01-04 19:50:19.000000000 -0500
46665 +++ linux-2.6.37/include/linux/kallsyms.h 2011-01-17 02:41:02.000000000 -0500
46670 -#ifdef CONFIG_KALLSYMS
46671 +#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
46672 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
46673 /* Lookup the address for a symbol. Returns 0 if not found. */
46674 unsigned long kallsyms_lookup_name(const char *name);
46676 @@ -92,6 +93,15 @@ static inline int lookup_symbol_attrs(un
46677 /* Stupid that this does nothing, but I didn't create this mess. */
46678 #define __print_symbol(fmt, addr)
46679 #endif /*CONFIG_KALLSYMS*/
46680 +#else /* when included by kallsyms.c, vsnprintf.c, or
46681 + arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
46682 +extern void __print_symbol(const char *fmt, unsigned long address);
46683 +extern int sprint_symbol(char *buffer, unsigned long address);
46684 +const char *kallsyms_lookup(unsigned long addr,
46685 + unsigned long *symbolsize,
46686 + unsigned long *offset,
46687 + char **modname, char *namebuf);
46690 /* This macro allows us to keep printk typechecking */
46691 static void __check_printsym_format(const char *fmt, ...)
46692 diff -urNp linux-2.6.37/include/linux/kgdb.h linux-2.6.37/include/linux/kgdb.h
46693 --- linux-2.6.37/include/linux/kgdb.h 2011-01-04 19:50:19.000000000 -0500
46694 +++ linux-2.6.37/include/linux/kgdb.h 2011-01-17 02:41:02.000000000 -0500
46695 @@ -269,22 +269,22 @@ struct kgdb_arch {
46699 - int (*read_char) (void);
46700 - void (*write_char) (u8);
46701 - void (*flush) (void);
46702 - int (*init) (void);
46703 - void (*pre_exception) (void);
46704 - void (*post_exception) (void);
46705 + int (* const read_char) (void);
46706 + void (* const write_char) (u8);
46707 + void (* const flush) (void);
46708 + int (* const init) (void);
46709 + void (* const pre_exception) (void);
46710 + void (* const post_exception) (void);
46714 -extern struct kgdb_arch arch_kgdb_ops;
46715 +extern const struct kgdb_arch arch_kgdb_ops;
46717 extern unsigned long __weak kgdb_arch_pc(int exception, struct pt_regs *regs);
46719 -extern int kgdb_register_io_module(struct kgdb_io *local_kgdb_io_ops);
46720 -extern void kgdb_unregister_io_module(struct kgdb_io *local_kgdb_io_ops);
46721 -extern struct kgdb_io *dbg_io_ops;
46722 +extern int kgdb_register_io_module(const struct kgdb_io *local_kgdb_io_ops);
46723 +extern void kgdb_unregister_io_module(const struct kgdb_io *local_kgdb_io_ops);
46724 +extern const struct kgdb_io *dbg_io_ops;
46726 extern int kgdb_hex2long(char **ptr, unsigned long *long_val);
46727 extern char *kgdb_mem2hex(char *mem, char *buf, int count);
46728 diff -urNp linux-2.6.37/include/linux/kvm_host.h linux-2.6.37/include/linux/kvm_host.h
46729 --- linux-2.6.37/include/linux/kvm_host.h 2011-01-04 19:50:19.000000000 -0500
46730 +++ linux-2.6.37/include/linux/kvm_host.h 2011-01-17 02:41:02.000000000 -0500
46731 @@ -246,7 +246,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vc
46732 void vcpu_load(struct kvm_vcpu *vcpu);
46733 void vcpu_put(struct kvm_vcpu *vcpu);
46735 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
46736 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
46737 struct module *module);
46738 void kvm_exit(void);
46740 @@ -375,7 +375,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(
46741 struct kvm_guest_debug *dbg);
46742 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
46744 -int kvm_arch_init(void *opaque);
46745 +int kvm_arch_init(const void *opaque);
46746 void kvm_arch_exit(void);
46748 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
46749 diff -urNp linux-2.6.37/include/linux/libata.h linux-2.6.37/include/linux/libata.h
46750 --- linux-2.6.37/include/linux/libata.h 2011-01-04 19:50:19.000000000 -0500
46751 +++ linux-2.6.37/include/linux/libata.h 2011-01-17 02:41:02.000000000 -0500
46752 @@ -65,11 +65,11 @@
46753 #ifdef ATA_VERBOSE_DEBUG
46754 #define VPRINTK(fmt, args...) printk(KERN_ERR "%s: " fmt, __func__, ## args)
46756 -#define VPRINTK(fmt, args...)
46757 +#define VPRINTK(fmt, args...) do {} while (0)
46758 #endif /* ATA_VERBOSE_DEBUG */
46760 -#define DPRINTK(fmt, args...)
46761 -#define VPRINTK(fmt, args...)
46762 +#define DPRINTK(fmt, args...) do {} while (0)
46763 +#define VPRINTK(fmt, args...) do {} while (0)
46764 #endif /* ATA_DEBUG */
46766 #define BPRINTK(fmt, args...) if (ap->flags & ATA_FLAG_DEBUGMSG) printk(KERN_ERR "%s: " fmt, __func__, ## args)
46767 @@ -530,11 +530,11 @@ struct ata_ioports {
46771 - struct device *dev;
46772 + struct device *dev;
46773 void __iomem * const *iomap;
46774 unsigned int n_ports;
46775 void *private_data;
46776 - struct ata_port_operations *ops;
46777 + const struct ata_port_operations *ops;
46778 unsigned long flags;
46780 struct mutex eh_mutex;
46781 @@ -725,7 +725,7 @@ struct ata_link {
46784 struct Scsi_Host *scsi_host; /* our co-allocated scsi host */
46785 - struct ata_port_operations *ops;
46786 + const struct ata_port_operations *ops;
46788 /* Flags owned by the EH context. Only EH should touch these once the
46790 @@ -913,7 +913,7 @@ struct ata_port_info {
46791 unsigned long pio_mask;
46792 unsigned long mwdma_mask;
46793 unsigned long udma_mask;
46794 - struct ata_port_operations *port_ops;
46795 + const struct ata_port_operations *port_ops;
46796 void *private_data;
46799 @@ -937,7 +937,7 @@ extern const unsigned long sata_deb_timi
46800 extern const unsigned long sata_deb_timing_hotplug[];
46801 extern const unsigned long sata_deb_timing_long[];
46803 -extern struct ata_port_operations ata_dummy_port_ops;
46804 +extern const struct ata_port_operations ata_dummy_port_ops;
46805 extern const struct ata_port_info ata_dummy_port_info;
46807 static inline const unsigned long *
46808 @@ -983,7 +983,7 @@ extern int ata_host_activate(struct ata_
46809 struct scsi_host_template *sht);
46810 extern void ata_host_detach(struct ata_host *host);
46811 extern void ata_host_init(struct ata_host *, struct device *,
46812 - unsigned long, struct ata_port_operations *);
46813 + unsigned long, const struct ata_port_operations *);
46814 extern int ata_scsi_detect(struct scsi_host_template *sht);
46815 extern int ata_scsi_ioctl(struct scsi_device *dev, int cmd, void __user *arg);
46816 extern int ata_scsi_queuecmd(struct Scsi_Host *h, struct scsi_cmnd *cmd);
46817 diff -urNp linux-2.6.37/include/linux/lockd/bind.h linux-2.6.37/include/linux/lockd/bind.h
46818 --- linux-2.6.37/include/linux/lockd/bind.h 2011-01-04 19:50:19.000000000 -0500
46819 +++ linux-2.6.37/include/linux/lockd/bind.h 2011-01-17 02:41:02.000000000 -0500
46820 @@ -23,13 +23,13 @@ struct svc_rqst;
46821 * This is the set of functions for lockd->nfsd communication
46823 struct nlmsvc_binding {
46824 - __be32 (*fopen)(struct svc_rqst *,
46825 + __be32 (* const fopen)(struct svc_rqst *,
46828 - void (*fclose)(struct file *);
46829 + void (* const fclose)(struct file *);
46832 -extern struct nlmsvc_binding * nlmsvc_ops;
46833 +extern const struct nlmsvc_binding * nlmsvc_ops;
46836 * Similar to nfs_client_initdata, but without the NFS-specific
46837 diff -urNp linux-2.6.37/include/linux/mm.h linux-2.6.37/include/linux/mm.h
46838 --- linux-2.6.37/include/linux/mm.h 2011-01-04 19:50:19.000000000 -0500
46839 +++ linux-2.6.37/include/linux/mm.h 2011-01-17 02:41:02.000000000 -0500
46840 @@ -107,7 +107,14 @@ extern unsigned int kobjsize(const void
46842 #define VM_CAN_NONLINEAR 0x08000000 /* Has ->fault & does nonlinear pages */
46843 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
46845 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
46846 +#define VM_SAO 0x00000000 /* Strong Access Ordering (powerpc) */
46847 +#define VM_PAGEEXEC 0x20000000 /* vma->vm_page_prot needs special handling */
46849 #define VM_SAO 0x20000000 /* Strong Access Ordering (powerpc) */
46852 #define VM_PFN_AT_MMAP 0x40000000 /* PFNMAP vma that is fully mapped at mmap time */
46853 #define VM_MERGEABLE 0x80000000 /* KSM may merge identical pages */
46855 @@ -875,12 +882,6 @@ int set_page_dirty(struct page *page);
46856 int set_page_dirty_lock(struct page *page);
46857 int clear_page_dirty_for_io(struct page *page);
46859 -/* Is the vma a continuation of the stack vma above it? */
46860 -static inline int vma_stack_continue(struct vm_area_struct *vma, unsigned long addr)
46862 - return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
46865 extern unsigned long move_page_tables(struct vm_area_struct *vma,
46866 unsigned long old_addr, struct vm_area_struct *new_vma,
46867 unsigned long new_addr, unsigned long len);
46868 @@ -1032,6 +1033,15 @@ struct shrinker {
46869 extern void register_shrinker(struct shrinker *);
46870 extern void unregister_shrinker(struct shrinker *);
46873 +pgprot_t vm_get_page_prot(unsigned long vm_flags);
46875 +static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
46877 + return __pgprot(0);
46881 int vma_wants_writenotify(struct vm_area_struct *vma);
46883 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
46884 @@ -1318,6 +1328,7 @@ out:
46887 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
46888 +extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
46890 extern unsigned long do_brk(unsigned long, unsigned long);
46892 @@ -1374,6 +1385,10 @@ extern struct vm_area_struct * find_vma(
46893 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
46894 struct vm_area_struct **pprev);
46896 +extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
46897 +extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
46898 +extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
46900 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
46901 NULL if none. Assume start_addr < end_addr. */
46902 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
46903 @@ -1390,15 +1405,6 @@ static inline unsigned long vma_pages(st
46904 return (vma->vm_end - vma->vm_start) >> PAGE_SHIFT;
46908 -pgprot_t vm_get_page_prot(unsigned long vm_flags);
46910 -static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
46912 - return __pgprot(0);
46916 struct vm_area_struct *find_extend_vma(struct mm_struct *, unsigned long addr);
46917 int remap_pfn_range(struct vm_area_struct *, unsigned long addr,
46918 unsigned long pfn, unsigned long size, pgprot_t);
46919 @@ -1505,7 +1511,7 @@ extern int unpoison_memory(unsigned long
46920 extern int sysctl_memory_failure_early_kill;
46921 extern int sysctl_memory_failure_recovery;
46922 extern void shake_page(struct page *p, int access);
46923 -extern atomic_long_t mce_bad_pages;
46924 +extern atomic_long_unchecked_t mce_bad_pages;
46925 extern int soft_offline_page(struct page *page, int flags);
46926 #ifdef CONFIG_MEMORY_FAILURE
46927 int is_hwpoison_address(unsigned long addr);
46928 @@ -1518,5 +1524,11 @@ static inline int is_hwpoison_address(un
46930 extern void dump_page(struct page *page);
46932 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
46933 +extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
46935 +static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
46938 #endif /* __KERNEL__ */
46939 #endif /* _LINUX_MM_H */
46940 diff -urNp linux-2.6.37/include/linux/mm_types.h linux-2.6.37/include/linux/mm_types.h
46941 --- linux-2.6.37/include/linux/mm_types.h 2011-01-04 19:50:19.000000000 -0500
46942 +++ linux-2.6.37/include/linux/mm_types.h 2011-01-17 02:41:02.000000000 -0500
46943 @@ -183,6 +183,8 @@ struct vm_area_struct {
46945 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
46948 + struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
46951 struct core_thread {
46952 @@ -312,6 +314,24 @@ struct mm_struct {
46954 /* How many tasks sharing this mm are OOM_DISABLE */
46955 atomic_t oom_disable_count;
46957 +#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS) || defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
46958 + unsigned long pax_flags;
46961 +#ifdef CONFIG_PAX_DLRESOLVE
46962 + unsigned long call_dl_resolve;
46965 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
46966 + unsigned long call_syscall;
46969 +#ifdef CONFIG_PAX_ASLR
46970 + unsigned long delta_mmap; /* randomized offset */
46971 + unsigned long delta_stack; /* randomized offset */
46976 /* Future-safe accessor for struct mm_struct's cpu_vm_mask. */
46977 diff -urNp linux-2.6.37/include/linux/mmu_notifier.h linux-2.6.37/include/linux/mmu_notifier.h
46978 --- linux-2.6.37/include/linux/mmu_notifier.h 2011-01-04 19:50:19.000000000 -0500
46979 +++ linux-2.6.37/include/linux/mmu_notifier.h 2011-01-17 02:41:02.000000000 -0500
46980 @@ -235,12 +235,12 @@ static inline void mmu_notifier_mm_destr
46982 #define ptep_clear_flush_notify(__vma, __address, __ptep) \
46986 struct vm_area_struct *___vma = __vma; \
46987 unsigned long ___address = __address; \
46988 - __pte = ptep_clear_flush(___vma, ___address, __ptep); \
46989 + ___pte = ptep_clear_flush(___vma, ___address, __ptep); \
46990 mmu_notifier_invalidate_page(___vma->vm_mm, ___address); \
46995 #define ptep_clear_flush_young_notify(__vma, __address, __ptep) \
46996 diff -urNp linux-2.6.37/include/linux/mmzone.h linux-2.6.37/include/linux/mmzone.h
46997 --- linux-2.6.37/include/linux/mmzone.h 2011-01-04 19:50:19.000000000 -0500
46998 +++ linux-2.6.37/include/linux/mmzone.h 2011-01-17 02:41:02.000000000 -0500
46999 @@ -354,7 +354,7 @@ struct zone {
47000 unsigned long flags; /* zone flags, see below */
47002 /* Zone statistics */
47003 - atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
47004 + atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
47007 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
47008 diff -urNp linux-2.6.37/include/linux/mod_devicetable.h linux-2.6.37/include/linux/mod_devicetable.h
47009 --- linux-2.6.37/include/linux/mod_devicetable.h 2011-01-04 19:50:19.000000000 -0500
47010 +++ linux-2.6.37/include/linux/mod_devicetable.h 2011-01-17 02:41:02.000000000 -0500
47012 typedef unsigned long kernel_ulong_t;
47015 -#define PCI_ANY_ID (~0)
47016 +#define PCI_ANY_ID ((__u16)~0)
47018 struct pci_device_id {
47019 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
47020 @@ -131,7 +131,7 @@ struct usb_device_id {
47021 #define USB_DEVICE_ID_MATCH_INT_SUBCLASS 0x0100
47022 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
47024 -#define HID_ANY_ID (~0)
47025 +#define HID_ANY_ID (~0U)
47027 struct hid_device_id {
47029 diff -urNp linux-2.6.37/include/linux/module.h linux-2.6.37/include/linux/module.h
47030 --- linux-2.6.37/include/linux/module.h 2011-01-04 19:50:19.000000000 -0500
47031 +++ linux-2.6.37/include/linux/module.h 2011-01-17 02:41:02.000000000 -0500
47032 @@ -297,16 +297,16 @@ struct module
47035 /* If this is non-NULL, vfree after init() returns */
47036 - void *module_init;
47037 + void *module_init_rx, *module_init_rw;
47039 /* Here is the actual code + data, vfree'd on unload. */
47040 - void *module_core;
47041 + void *module_core_rx, *module_core_rw;
47043 /* Here are the sizes of the init and core sections */
47044 - unsigned int init_size, core_size;
47045 + unsigned int init_size_rw, core_size_rw;
47047 /* The size of the executable code in each section. */
47048 - unsigned int init_text_size, core_text_size;
47049 + unsigned int init_size_rx, core_size_rx;
47051 /* Arch-specific module values */
47052 struct mod_arch_specific arch;
47053 @@ -411,16 +411,46 @@ bool is_module_address(unsigned long add
47054 bool is_module_percpu_address(unsigned long addr);
47055 bool is_module_text_address(unsigned long addr);
47057 +static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
47060 +#ifdef CONFIG_PAX_KERNEXEC
47061 + if (ktla_ktva(addr) >= (unsigned long)start &&
47062 + ktla_ktva(addr) < (unsigned long)start + size)
47066 + return ((void *)addr >= start && (void *)addr < start + size);
47069 +static inline int within_module_core_rx(unsigned long addr, struct module *mod)
47071 + return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
47074 +static inline int within_module_core_rw(unsigned long addr, struct module *mod)
47076 + return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
47079 +static inline int within_module_init_rx(unsigned long addr, struct module *mod)
47081 + return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
47084 +static inline int within_module_init_rw(unsigned long addr, struct module *mod)
47086 + return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
47089 static inline int within_module_core(unsigned long addr, struct module *mod)
47091 - return (unsigned long)mod->module_core <= addr &&
47092 - addr < (unsigned long)mod->module_core + mod->core_size;
47093 + return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
47096 static inline int within_module_init(unsigned long addr, struct module *mod)
47098 - return (unsigned long)mod->module_init <= addr &&
47099 - addr < (unsigned long)mod->module_init + mod->init_size;
47100 + return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
47103 /* Search for module by name: must hold module_mutex. */
47104 diff -urNp linux-2.6.37/include/linux/moduleloader.h linux-2.6.37/include/linux/moduleloader.h
47105 --- linux-2.6.37/include/linux/moduleloader.h 2011-01-04 19:50:19.000000000 -0500
47106 +++ linux-2.6.37/include/linux/moduleloader.h 2011-01-17 02:41:02.000000000 -0500
47107 @@ -20,9 +20,21 @@ unsigned int arch_mod_section_prepend(st
47108 sections. Returns NULL on failure. */
47109 void *module_alloc(unsigned long size);
47111 +#ifdef CONFIG_PAX_KERNEXEC
47112 +void *module_alloc_exec(unsigned long size);
47114 +#define module_alloc_exec(x) module_alloc(x)
47117 /* Free memory returned from module_alloc. */
47118 void module_free(struct module *mod, void *module_region);
47120 +#ifdef CONFIG_PAX_KERNEXEC
47121 +void module_free_exec(struct module *mod, void *module_region);
47123 +#define module_free_exec(x, y) module_free((x), (y))
47126 /* Apply the given relocation to the (simplified) ELF. Return -error
47128 int apply_relocate(Elf_Shdr *sechdrs,
47129 diff -urNp linux-2.6.37/include/linux/moduleparam.h linux-2.6.37/include/linux/moduleparam.h
47130 --- linux-2.6.37/include/linux/moduleparam.h 2011-01-04 19:50:19.000000000 -0500
47131 +++ linux-2.6.37/include/linux/moduleparam.h 2011-01-17 02:41:02.000000000 -0500
47132 @@ -253,7 +253,7 @@ static inline void __kernel_param_unlock
47133 * @len is usually just sizeof(string).
47135 #define module_param_string(name, string, len, perm) \
47136 - static const struct kparam_string __param_string_##name \
47137 + static const struct kparam_string __param_string_##name __used \
47138 = { len, string }; \
47139 __module_param_call(MODULE_PARAM_PREFIX, name, \
47140 ¶m_ops_string, \
47141 @@ -368,7 +368,7 @@ extern int param_get_invbool(char *buffe
47142 * module_param_named() for why this might be necessary.
47144 #define module_param_array_named(name, array, type, nump, perm) \
47145 - static const struct kparam_array __param_arr_##name \
47146 + static const struct kparam_array __param_arr_##name __used \
47147 = { ARRAY_SIZE(array), nump, ¶m_ops_##type, \
47148 sizeof(array[0]), array }; \
47149 __module_param_call(MODULE_PARAM_PREFIX, name, \
47150 diff -urNp linux-2.6.37/include/linux/namei.h linux-2.6.37/include/linux/namei.h
47151 --- linux-2.6.37/include/linux/namei.h 2011-01-04 19:50:19.000000000 -0500
47152 +++ linux-2.6.37/include/linux/namei.h 2011-01-17 02:41:02.000000000 -0500
47153 @@ -22,7 +22,7 @@ struct nameidata {
47154 unsigned int flags;
47157 - char *saved_names[MAX_NESTED_LINKS + 1];
47158 + const char *saved_names[MAX_NESTED_LINKS + 1];
47162 @@ -81,12 +81,12 @@ extern int follow_up(struct path *);
47163 extern struct dentry *lock_rename(struct dentry *, struct dentry *);
47164 extern void unlock_rename(struct dentry *, struct dentry *);
47166 -static inline void nd_set_link(struct nameidata *nd, char *path)
47167 +static inline void nd_set_link(struct nameidata *nd, const char *path)
47169 nd->saved_names[nd->depth] = path;
47172 -static inline char *nd_get_link(struct nameidata *nd)
47173 +static inline const char *nd_get_link(const struct nameidata *nd)
47175 return nd->saved_names[nd->depth];
47177 diff -urNp linux-2.6.37/include/linux/netfilter/xt_gradm.h linux-2.6.37/include/linux/netfilter/xt_gradm.h
47178 --- linux-2.6.37/include/linux/netfilter/xt_gradm.h 1969-12-31 19:00:00.000000000 -0500
47179 +++ linux-2.6.37/include/linux/netfilter/xt_gradm.h 2011-01-17 02:41:02.000000000 -0500
47181 +#ifndef _LINUX_NETFILTER_XT_GRADM_H
47182 +#define _LINUX_NETFILTER_XT_GRADM_H 1
47184 +struct xt_gradm_mtinfo {
47190 diff -urNp linux-2.6.37/include/linux/oprofile.h linux-2.6.37/include/linux/oprofile.h
47191 --- linux-2.6.37/include/linux/oprofile.h 2011-01-04 19:50:19.000000000 -0500
47192 +++ linux-2.6.37/include/linux/oprofile.h 2011-01-17 02:41:02.000000000 -0500
47193 @@ -130,9 +130,9 @@ int oprofilefs_create_ulong(struct super
47194 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
47195 char const * name, ulong * val);
47197 -/** Create a file for read-only access to an atomic_t. */
47198 +/** Create a file for read-only access to an atomic_unchecked_t. */
47199 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
47200 - char const * name, atomic_t * val);
47201 + char const * name, atomic_unchecked_t * val);
47203 /** create a directory */
47204 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
47205 diff -urNp linux-2.6.37/include/linux/pipe_fs_i.h linux-2.6.37/include/linux/pipe_fs_i.h
47206 --- linux-2.6.37/include/linux/pipe_fs_i.h 2011-01-04 19:50:19.000000000 -0500
47207 +++ linux-2.6.37/include/linux/pipe_fs_i.h 2011-01-17 02:41:02.000000000 -0500
47208 @@ -45,9 +45,9 @@ struct pipe_buffer {
47209 struct pipe_inode_info {
47210 wait_queue_head_t wait;
47211 unsigned int nrbufs, curbuf, buffers;
47212 - unsigned int readers;
47213 - unsigned int writers;
47214 - unsigned int waiting_writers;
47215 + atomic_t readers;
47216 + atomic_t writers;
47217 + atomic_t waiting_writers;
47218 unsigned int r_counter;
47219 unsigned int w_counter;
47220 struct page *tmp_page;
47221 diff -urNp linux-2.6.37/include/linux/pm_runtime.h linux-2.6.37/include/linux/pm_runtime.h
47222 --- linux-2.6.37/include/linux/pm_runtime.h 2011-01-04 19:50:19.000000000 -0500
47223 +++ linux-2.6.37/include/linux/pm_runtime.h 2011-01-17 02:41:02.000000000 -0500
47224 @@ -83,7 +83,7 @@ static inline bool pm_runtime_suspended(
47226 static inline void pm_runtime_mark_last_busy(struct device *dev)
47228 - ACCESS_ONCE(dev->power.last_busy) = jiffies;
47229 + ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
47232 #else /* !CONFIG_PM_RUNTIME */
47233 diff -urNp linux-2.6.37/include/linux/poison.h linux-2.6.37/include/linux/poison.h
47234 --- linux-2.6.37/include/linux/poison.h 2011-01-04 19:50:19.000000000 -0500
47235 +++ linux-2.6.37/include/linux/poison.h 2011-01-17 02:41:02.000000000 -0500
47237 * under normal circumstances, used to verify that nobody uses
47238 * non-initialized list entries.
47240 -#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
47241 -#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
47242 +#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
47243 +#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
47245 /********** include/linux/timer.h **********/
47247 diff -urNp linux-2.6.37/include/linux/proc_fs.h linux-2.6.37/include/linux/proc_fs.h
47248 --- linux-2.6.37/include/linux/proc_fs.h 2011-01-04 19:50:19.000000000 -0500
47249 +++ linux-2.6.37/include/linux/proc_fs.h 2011-01-17 02:41:02.000000000 -0500
47250 @@ -155,6 +155,19 @@ static inline struct proc_dir_entry *pro
47251 return proc_create_data(name, mode, parent, proc_fops, NULL);
47254 +static inline struct proc_dir_entry *proc_create_grsec(const char *name, mode_t mode,
47255 + struct proc_dir_entry *parent, const struct file_operations *proc_fops)
47257 +#ifdef CONFIG_GRKERNSEC_PROC_USER
47258 + return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
47259 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
47260 + return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
47262 + return proc_create_data(name, mode, parent, proc_fops, NULL);
47267 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
47268 mode_t mode, struct proc_dir_entry *base,
47269 read_proc_t *read_proc, void * data)
47270 diff -urNp linux-2.6.37/include/linux/random.h linux-2.6.37/include/linux/random.h
47271 --- linux-2.6.37/include/linux/random.h 2011-01-04 19:50:19.000000000 -0500
47272 +++ linux-2.6.37/include/linux/random.h 2011-01-17 02:41:02.000000000 -0500
47273 @@ -80,12 +80,17 @@ void srandom32(u32 seed);
47275 u32 prandom32(struct rnd_state *);
47277 +static inline unsigned long pax_get_random_long(void)
47279 + return random32() + (sizeof(long) > 4 ? (unsigned long)random32() << 32 : 0);
47283 * Handle minimum values for seeds
47285 static inline u32 __seed(u32 x, u32 m)
47287 - return (x < m) ? x + m : x;
47288 + return (x <= m) ? x + m + 1 : x;
47292 diff -urNp linux-2.6.37/include/linux/reiserfs_fs.h linux-2.6.37/include/linux/reiserfs_fs.h
47293 --- linux-2.6.37/include/linux/reiserfs_fs.h 2011-01-04 19:50:19.000000000 -0500
47294 +++ linux-2.6.37/include/linux/reiserfs_fs.h 2011-01-17 02:41:02.000000000 -0500
47295 @@ -1403,7 +1403,7 @@ static inline loff_t max_reiserfs_offset
47296 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
47298 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
47299 -#define get_generation(s) atomic_read (&fs_generation(s))
47300 +#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
47301 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
47302 #define __fs_changed(gen,s) (gen != get_generation (s))
47303 #define fs_changed(gen,s) \
47304 @@ -1615,24 +1615,24 @@ static inline struct super_block *sb_fro
47307 struct item_operations {
47308 - int (*bytes_number) (struct item_head * ih, int block_size);
47309 - void (*decrement_key) (struct cpu_key *);
47310 - int (*is_left_mergeable) (struct reiserfs_key * ih,
47311 + int (* const bytes_number) (struct item_head * ih, int block_size);
47312 + void (* const decrement_key) (struct cpu_key *);
47313 + int (* const is_left_mergeable) (struct reiserfs_key * ih,
47314 unsigned long bsize);
47315 - void (*print_item) (struct item_head *, char *item);
47316 - void (*check_item) (struct item_head *, char *item);
47317 + void (* const print_item) (struct item_head *, char *item);
47318 + void (* const check_item) (struct item_head *, char *item);
47320 - int (*create_vi) (struct virtual_node * vn, struct virtual_item * vi,
47321 + int (* const create_vi) (struct virtual_node * vn, struct virtual_item * vi,
47322 int is_affected, int insert_size);
47323 - int (*check_left) (struct virtual_item * vi, int free,
47324 + int (* const check_left) (struct virtual_item * vi, int free,
47325 int start_skip, int end_skip);
47326 - int (*check_right) (struct virtual_item * vi, int free);
47327 - int (*part_size) (struct virtual_item * vi, int from, int to);
47328 - int (*unit_num) (struct virtual_item * vi);
47329 - void (*print_vi) (struct virtual_item * vi);
47330 + int (* const check_right) (struct virtual_item * vi, int free);
47331 + int (* const part_size) (struct virtual_item * vi, int from, int to);
47332 + int (* const unit_num) (struct virtual_item * vi);
47333 + void (* const print_vi) (struct virtual_item * vi);
47336 -extern struct item_operations *item_ops[TYPE_ANY + 1];
47337 +extern const struct item_operations * const item_ops[TYPE_ANY + 1];
47339 #define op_bytes_number(ih,bsize) item_ops[le_ih_k_type (ih)]->bytes_number (ih, bsize)
47340 #define op_is_left_mergeable(key,bsize) item_ops[le_key_k_type (le_key_version (key), key)]->is_left_mergeable (key, bsize)
47341 diff -urNp linux-2.6.37/include/linux/reiserfs_fs_sb.h linux-2.6.37/include/linux/reiserfs_fs_sb.h
47342 --- linux-2.6.37/include/linux/reiserfs_fs_sb.h 2011-01-04 19:50:19.000000000 -0500
47343 +++ linux-2.6.37/include/linux/reiserfs_fs_sb.h 2011-01-17 02:41:02.000000000 -0500
47344 @@ -386,7 +386,7 @@ struct reiserfs_sb_info {
47345 /* Comment? -Hans */
47346 wait_queue_head_t s_wait;
47347 /* To be obsoleted soon by per buffer seals.. -Hans */
47348 - atomic_t s_generation_counter; // increased by one every time the
47349 + atomic_unchecked_t s_generation_counter; // increased by one every time the
47350 // tree gets re-balanced
47351 unsigned long s_properties; /* File system properties. Currently holds
47352 on-disk FS format */
47353 diff -urNp linux-2.6.37/include/linux/rmap.h linux-2.6.37/include/linux/rmap.h
47354 --- linux-2.6.37/include/linux/rmap.h 2011-01-04 19:50:19.000000000 -0500
47355 +++ linux-2.6.37/include/linux/rmap.h 2011-01-17 02:41:02.000000000 -0500
47356 @@ -145,8 +145,8 @@ static inline void anon_vma_unlock(struc
47357 void anon_vma_init(void); /* create anon_vma_cachep */
47358 int anon_vma_prepare(struct vm_area_struct *);
47359 void unlink_anon_vmas(struct vm_area_struct *);
47360 -int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
47361 -int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
47362 +int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
47363 +int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
47364 void __anon_vma_link(struct vm_area_struct *);
47365 void anon_vma_free(struct anon_vma *);
47367 diff -urNp linux-2.6.37/include/linux/sched.h linux-2.6.37/include/linux/sched.h
47368 --- linux-2.6.37/include/linux/sched.h 2011-01-04 19:50:19.000000000 -0500
47369 +++ linux-2.6.37/include/linux/sched.h 2011-01-17 02:41:02.000000000 -0500
47370 @@ -100,6 +100,7 @@ struct robust_list_head;
47373 struct perf_event_context;
47374 +struct linux_binprm;
47377 * List of flags we want to share for kernel threads,
47378 @@ -377,10 +378,12 @@ struct user_namespace;
47379 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
47381 extern int sysctl_max_map_count;
47382 +extern unsigned long sysctl_heap_stack_gap;
47384 #include <linux/aio.h>
47387 +extern bool check_heap_stack_gap(struct vm_area_struct *vma, unsigned long addr, unsigned long len);
47388 extern void arch_pick_mmap_layout(struct mm_struct *mm);
47389 extern unsigned long
47390 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
47391 @@ -624,6 +627,16 @@ struct signal_struct {
47392 struct tty_audit_buf *tty_audit_buf;
47395 +#ifdef CONFIG_GRKERNSEC
47402 + u8 used_accept:1;
47405 int oom_adj; /* OOM kill score adjustment (bit shift) */
47406 int oom_score_adj; /* OOM kill score adjustment */
47408 @@ -1181,7 +1194,7 @@ enum perf_event_task_context {
47410 struct task_struct {
47411 volatile long state; /* -1 unrunnable, 0 runnable, >0 stopped */
47413 + struct thread_info *stack;
47415 unsigned int flags; /* per process flags, defined below */
47416 unsigned int ptrace;
47417 @@ -1291,8 +1304,8 @@ struct task_struct {
47418 struct list_head thread_group;
47420 struct completion *vfork_done; /* for vfork() */
47421 - int __user *set_child_tid; /* CLONE_CHILD_SETTID */
47422 - int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
47423 + pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
47424 + pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
47426 cputime_t utime, stime, utimescaled, stimescaled;
47428 @@ -1308,13 +1321,6 @@ struct task_struct {
47429 struct task_cputime cputime_expires;
47430 struct list_head cpu_timers[3];
47432 -/* process credentials */
47433 - const struct cred __rcu *real_cred; /* objective and real subjective task
47434 - * credentials (COW) */
47435 - const struct cred __rcu *cred; /* effective (overridable) subjective task
47436 - * credentials (COW) */
47437 - struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */
47439 char comm[TASK_COMM_LEN]; /* executable name excluding path
47440 - access with [gs]et_task_comm (which lock
47441 it with task_lock())
47442 @@ -1333,6 +1339,10 @@ struct task_struct {
47443 struct thread_struct thread;
47444 /* filesystem information */
47445 struct fs_struct *fs;
47447 + const struct cred __rcu *cred; /* effective (overridable) subjective task
47448 + * credentials (COW) */
47450 /* open file information */
47451 struct files_struct *files;
47453 @@ -1379,6 +1389,11 @@ struct task_struct {
47454 struct rt_mutex_waiter *pi_blocked_on;
47457 +/* process credentials */
47458 + const struct cred __rcu *real_cred; /* objective and real subjective task
47459 + * credentials (COW) */
47460 + struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */
47462 #ifdef CONFIG_DEBUG_MUTEXES
47463 /* mutex deadlock detection */
47464 struct mutex_waiter *blocked_on;
47465 @@ -1483,6 +1498,20 @@ struct task_struct {
47466 unsigned long default_timer_slack_ns;
47468 struct list_head *scm_work_list;
47470 +#ifdef CONFIG_GRKERNSEC
47472 + struct dentry *gr_chroot_dentry;
47473 + struct acl_subject_label *acl;
47474 + struct acl_role_label *role;
47475 + struct file *exec_file;
47480 + u8 gr_is_chrooted;
47483 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
47484 /* Index of current stored address in ret_stack */
47485 int curr_ret_stack;
47486 @@ -1514,6 +1543,52 @@ struct task_struct {
47490 +#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
47491 +#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
47492 +#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
47493 +#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
47494 +/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
47495 +#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
47497 +#ifdef CONFIG_PAX_SOFTMODE
47498 +extern unsigned int pax_softmode;
47501 +extern int pax_check_flags(unsigned long *);
47503 +/* if tsk != current then task_lock must be held on it */
47504 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
47505 +static inline unsigned long pax_get_flags(struct task_struct *tsk)
47507 + if (likely(tsk->mm))
47508 + return tsk->mm->pax_flags;
47513 +/* if tsk != current then task_lock must be held on it */
47514 +static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
47516 + if (likely(tsk->mm)) {
47517 + tsk->mm->pax_flags = flags;
47524 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
47525 +extern void pax_set_initial_flags(struct linux_binprm *bprm);
47526 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
47527 +extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
47530 +void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
47531 +void pax_report_insns(void *pc, void *sp);
47532 +void pax_report_refcount_overflow(struct pt_regs *regs);
47533 +void pax_report_leak_to_user(const void *ptr, unsigned long len);
47534 +void pax_report_overflow_from_user(const void *ptr, unsigned long len);
47536 /* Future-safe accessor for struct task_struct's cpus_allowed. */
47537 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
47539 @@ -2134,7 +2209,7 @@ extern void __cleanup_sighand(struct sig
47540 extern void exit_itimers(struct signal_struct *);
47541 extern void flush_itimer_signals(void);
47543 -extern NORET_TYPE void do_group_exit(int);
47544 +extern NORET_TYPE void do_group_exit(int) ATTRIB_NORET;
47546 extern void daemonize(const char *, ...);
47547 extern int allow_signal(int);
47548 @@ -2259,8 +2334,8 @@ static inline void unlock_task_sighand(s
47550 #ifndef __HAVE_THREAD_FUNCTIONS
47552 -#define task_thread_info(task) ((struct thread_info *)(task)->stack)
47553 -#define task_stack_page(task) ((task)->stack)
47554 +#define task_thread_info(task) ((task)->stack)
47555 +#define task_stack_page(task) ((void *)(task)->stack)
47557 static inline void setup_thread_stack(struct task_struct *p, struct task_struct *org)
47559 @@ -2275,13 +2350,17 @@ static inline unsigned long *end_of_stac
47563 -static inline int object_is_on_stack(void *obj)
47564 +static inline int object_starts_on_stack(void *obj)
47566 - void *stack = task_stack_page(current);
47567 + const void *stack = task_stack_page(current);
47569 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
47572 +#ifdef CONFIG_PAX_USERCOPY
47573 +extern int object_is_on_stack(const void *obj, unsigned long len);
47576 extern void thread_info_cache_init(void);
47578 #ifdef CONFIG_DEBUG_STACK_USAGE
47579 diff -urNp linux-2.6.37/include/linux/screen_info.h linux-2.6.37/include/linux/screen_info.h
47580 --- linux-2.6.37/include/linux/screen_info.h 2011-01-04 19:50:19.000000000 -0500
47581 +++ linux-2.6.37/include/linux/screen_info.h 2011-01-17 02:41:02.000000000 -0500
47582 @@ -43,7 +43,8 @@ struct screen_info {
47583 __u16 pages; /* 0x32 */
47584 __u16 vesa_attributes; /* 0x34 */
47585 __u32 capabilities; /* 0x36 */
47586 - __u8 _reserved[6]; /* 0x3a */
47587 + __u16 vesapm_size; /* 0x3a */
47588 + __u8 _reserved[4]; /* 0x3c */
47589 } __attribute__((packed));
47591 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
47592 diff -urNp linux-2.6.37/include/linux/security.h linux-2.6.37/include/linux/security.h
47593 --- linux-2.6.37/include/linux/security.h 2011-01-04 19:50:19.000000000 -0500
47594 +++ linux-2.6.37/include/linux/security.h 2011-01-17 02:41:02.000000000 -0500
47596 #include <linux/key.h>
47597 #include <linux/xfrm.h>
47598 #include <linux/slab.h>
47599 +#include <linux/grsecurity.h>
47600 #include <net/flow.h>
47602 /* Maximum number of letters for an LSM name string */
47603 diff -urNp linux-2.6.37/include/linux/shm.h linux-2.6.37/include/linux/shm.h
47604 --- linux-2.6.37/include/linux/shm.h 2011-01-04 19:50:19.000000000 -0500
47605 +++ linux-2.6.37/include/linux/shm.h 2011-01-17 02:41:02.000000000 -0500
47606 @@ -95,6 +95,10 @@ struct shmid_kernel /* private to the ke
47609 struct user_struct *mlock_user;
47610 +#ifdef CONFIG_GRKERNSEC
47611 + time_t shm_createtime;
47616 /* shm_mode upper byte flags */
47617 diff -urNp linux-2.6.37/include/linux/skbuff.h linux-2.6.37/include/linux/skbuff.h
47618 --- linux-2.6.37/include/linux/skbuff.h 2011-01-04 19:50:19.000000000 -0500
47619 +++ linux-2.6.37/include/linux/skbuff.h 2011-01-17 02:41:02.000000000 -0500
47620 @@ -581,7 +581,7 @@ static inline struct skb_shared_hwtstamp
47622 static inline int skb_queue_empty(const struct sk_buff_head *list)
47624 - return list->next == (struct sk_buff *)list;
47625 + return list->next == (const struct sk_buff *)list;
47629 @@ -594,7 +594,7 @@ static inline int skb_queue_empty(const
47630 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
47631 const struct sk_buff *skb)
47633 - return skb->next == (struct sk_buff *)list;
47634 + return skb->next == (const struct sk_buff *)list;
47638 @@ -607,7 +607,7 @@ static inline bool skb_queue_is_last(con
47639 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
47640 const struct sk_buff *skb)
47642 - return skb->prev == (struct sk_buff *)list;
47643 + return skb->prev == (const struct sk_buff *)list;
47647 diff -urNp linux-2.6.37/include/linux/slab.h linux-2.6.37/include/linux/slab.h
47648 --- linux-2.6.37/include/linux/slab.h 2011-01-04 19:50:19.000000000 -0500
47649 +++ linux-2.6.37/include/linux/slab.h 2011-01-17 02:41:02.000000000 -0500
47652 #include <linux/gfp.h>
47653 #include <linux/types.h>
47654 +#include <linux/err.h>
47657 * Flags to pass to kmem_cache_create().
47658 @@ -87,10 +88,13 @@
47659 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
47660 * Both make kfree a no-op.
47662 -#define ZERO_SIZE_PTR ((void *)16)
47663 +#define ZERO_SIZE_PTR \
47665 + BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
47666 + (void *)(-MAX_ERRNO-1L); \
47669 -#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
47670 - (unsigned long)ZERO_SIZE_PTR)
47671 +#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
47674 * struct kmem_cache related prototypes
47675 @@ -144,6 +148,7 @@ void * __must_check krealloc(const void
47676 void kfree(const void *);
47677 void kzfree(const void *);
47678 size_t ksize(const void *);
47679 +void check_object_size(const void *ptr, unsigned long n, bool to);
47682 * Allocator specific definitions. These are mainly used to establish optimized
47683 @@ -336,4 +341,37 @@ static inline void *kzalloc_node(size_t
47685 void __init kmem_cache_init_late(void);
47687 +#define kmalloc(x, y) \
47689 + void *___retval; \
47690 + intoverflow_t ___x = (intoverflow_t)x; \
47691 + if (WARN(___x > ULONG_MAX, "kmalloc size overflow\n"))\
47692 + ___retval = NULL; \
47694 + ___retval = kmalloc((size_t)___x, (y)); \
47698 +#define kmalloc_node(x, y, z) \
47700 + void *___retval; \
47701 + intoverflow_t ___x = (intoverflow_t)x; \
47702 + if (WARN(___x > ULONG_MAX, "kmalloc_node size overflow\n"))\
47703 + ___retval = NULL; \
47705 + ___retval = kmalloc_node((size_t)___x, (y), (z));\
47709 +#define kzalloc(x, y) \
47711 + void *___retval; \
47712 + intoverflow_t ___x = (intoverflow_t)x; \
47713 + if (WARN(___x > ULONG_MAX, "kzalloc size overflow\n"))\
47714 + ___retval = NULL; \
47716 + ___retval = kzalloc((size_t)___x, (y)); \
47720 #endif /* _LINUX_SLAB_H */
47721 diff -urNp linux-2.6.37/include/linux/slub_def.h linux-2.6.37/include/linux/slub_def.h
47722 --- linux-2.6.37/include/linux/slub_def.h 2011-01-04 19:50:19.000000000 -0500
47723 +++ linux-2.6.37/include/linux/slub_def.h 2011-01-17 02:41:02.000000000 -0500
47724 @@ -80,7 +80,7 @@ struct kmem_cache {
47725 struct kmem_cache_order_objects max;
47726 struct kmem_cache_order_objects min;
47727 gfp_t allocflags; /* gfp flags to use on each alloc */
47728 - int refcount; /* Refcount for slab cache destroy */
47729 + atomic_t refcount; /* Refcount for slab cache destroy */
47730 void (*ctor)(void *);
47731 int inuse; /* Offset to metadata */
47732 int align; /* Alignment */
47733 diff -urNp linux-2.6.37/include/linux/sonet.h linux-2.6.37/include/linux/sonet.h
47734 --- linux-2.6.37/include/linux/sonet.h 2011-01-04 19:50:19.000000000 -0500
47735 +++ linux-2.6.37/include/linux/sonet.h 2011-01-17 02:41:02.000000000 -0500
47736 @@ -61,7 +61,7 @@ struct sonet_stats {
47737 #include <asm/atomic.h>
47739 struct k_sonet_stats {
47740 -#define __HANDLE_ITEM(i) atomic_t i
47741 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
47743 #undef __HANDLE_ITEM
47745 diff -urNp linux-2.6.37/include/linux/sunrpc/clnt.h linux-2.6.37/include/linux/sunrpc/clnt.h
47746 --- linux-2.6.37/include/linux/sunrpc/clnt.h 2011-01-04 19:50:19.000000000 -0500
47747 +++ linux-2.6.37/include/linux/sunrpc/clnt.h 2011-01-17 02:41:02.000000000 -0500
47748 @@ -168,9 +168,9 @@ static inline unsigned short rpc_get_por
47750 switch (sap->sa_family) {
47752 - return ntohs(((struct sockaddr_in *)sap)->sin_port);
47753 + return ntohs(((const struct sockaddr_in *)sap)->sin_port);
47755 - return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
47756 + return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
47760 @@ -203,7 +203,7 @@ static inline bool __rpc_cmp_addr4(const
47761 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
47762 const struct sockaddr *src)
47764 - const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
47765 + const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
47766 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
47768 dsin->sin_family = ssin->sin_family;
47769 @@ -300,7 +300,7 @@ static inline u32 rpc_get_scope_id(const
47770 if (sa->sa_family != AF_INET6)
47773 - return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
47774 + return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
47777 #endif /* __KERNEL__ */
47778 diff -urNp linux-2.6.37/include/linux/suspend.h linux-2.6.37/include/linux/suspend.h
47779 --- linux-2.6.37/include/linux/suspend.h 2011-01-04 19:50:19.000000000 -0500
47780 +++ linux-2.6.37/include/linux/suspend.h 2011-01-17 02:41:02.000000000 -0500
47781 @@ -106,15 +106,15 @@ typedef int __bitwise suspend_state_t;
47782 * which require special recovery actions in that situation.
47784 struct platform_suspend_ops {
47785 - int (*valid)(suspend_state_t state);
47786 - int (*begin)(suspend_state_t state);
47787 - int (*prepare)(void);
47788 - int (*prepare_late)(void);
47789 - int (*enter)(suspend_state_t state);
47790 - void (*wake)(void);
47791 - void (*finish)(void);
47792 - void (*end)(void);
47793 - void (*recover)(void);
47794 + int (* const valid)(suspend_state_t state);
47795 + int (* const begin)(suspend_state_t state);
47796 + int (* const prepare)(void);
47797 + int (* const prepare_late)(void);
47798 + int (* const enter)(suspend_state_t state);
47799 + void (* const wake)(void);
47800 + void (* const finish)(void);
47801 + void (* const end)(void);
47802 + void (* const recover)(void);
47805 #ifdef CONFIG_SUSPEND
47806 @@ -122,7 +122,7 @@ struct platform_suspend_ops {
47807 * suspend_set_ops - set platform dependent suspend operations
47808 * @ops: The new suspend operations to set.
47810 -extern void suspend_set_ops(struct platform_suspend_ops *ops);
47811 +extern void suspend_set_ops(const struct platform_suspend_ops *ops);
47812 extern int suspend_valid_only_mem(suspend_state_t state);
47815 @@ -147,7 +147,7 @@ extern int pm_suspend(suspend_state_t st
47816 #else /* !CONFIG_SUSPEND */
47817 #define suspend_valid_only_mem NULL
47819 -static inline void suspend_set_ops(struct platform_suspend_ops *ops) {}
47820 +static inline void suspend_set_ops(const struct platform_suspend_ops *ops) {}
47821 static inline int pm_suspend(suspend_state_t state) { return -ENOSYS; }
47822 #endif /* !CONFIG_SUSPEND */
47824 @@ -217,16 +217,16 @@ extern void mark_free_pages(struct zone
47825 * platforms which require special recovery actions in that situation.
47827 struct platform_hibernation_ops {
47828 - int (*begin)(void);
47829 - void (*end)(void);
47830 - int (*pre_snapshot)(void);
47831 - void (*finish)(void);
47832 - int (*prepare)(void);
47833 - int (*enter)(void);
47834 - void (*leave)(void);
47835 - int (*pre_restore)(void);
47836 - void (*restore_cleanup)(void);
47837 - void (*recover)(void);
47838 + int (* const begin)(void);
47839 + void (* const end)(void);
47840 + int (* const pre_snapshot)(void);
47841 + void (* const finish)(void);
47842 + int (* const prepare)(void);
47843 + int (* const enter)(void);
47844 + void (* const leave)(void);
47845 + int (* const pre_restore)(void);
47846 + void (* const restore_cleanup)(void);
47847 + void (* const recover)(void);
47850 #ifdef CONFIG_HIBERNATION
47851 @@ -245,7 +245,7 @@ extern void swsusp_set_page_free(struct
47852 extern void swsusp_unset_page_free(struct page *);
47853 extern unsigned long get_safe_page(gfp_t gfp_mask);
47855 -extern void hibernation_set_ops(struct platform_hibernation_ops *ops);
47856 +extern void hibernation_set_ops(const struct platform_hibernation_ops *ops);
47857 extern int hibernate(void);
47858 extern bool system_entering_hibernation(void);
47859 #else /* CONFIG_HIBERNATION */
47860 @@ -253,7 +253,7 @@ static inline int swsusp_page_is_forbidd
47861 static inline void swsusp_set_page_free(struct page *p) {}
47862 static inline void swsusp_unset_page_free(struct page *p) {}
47864 -static inline void hibernation_set_ops(struct platform_hibernation_ops *ops) {}
47865 +static inline void hibernation_set_ops(const struct platform_hibernation_ops *ops) {}
47866 static inline int hibernate(void) { return -ENOSYS; }
47867 static inline bool system_entering_hibernation(void) { return false; }
47868 #endif /* CONFIG_HIBERNATION */
47869 diff -urNp linux-2.6.37/include/linux/sysctl.h linux-2.6.37/include/linux/sysctl.h
47870 --- linux-2.6.37/include/linux/sysctl.h 2011-01-04 19:50:19.000000000 -0500
47871 +++ linux-2.6.37/include/linux/sysctl.h 2011-01-17 02:41:02.000000000 -0500
47872 @@ -155,7 +155,11 @@ enum
47873 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
47877 +#ifdef CONFIG_PAX_SOFTMODE
47879 + PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
47883 /* CTL_VM names: */
47885 @@ -966,6 +970,8 @@ typedef int proc_handler (struct ctl_tab
47887 extern int proc_dostring(struct ctl_table *, int,
47888 void __user *, size_t *, loff_t *);
47889 +extern int proc_dostring_modpriv(struct ctl_table *, int,
47890 + void __user *, size_t *, loff_t *);
47891 extern int proc_dointvec(struct ctl_table *, int,
47892 void __user *, size_t *, loff_t *);
47893 extern int proc_dointvec_minmax(struct ctl_table *, int,
47894 diff -urNp linux-2.6.37/include/linux/sysfs.h linux-2.6.37/include/linux/sysfs.h
47895 --- linux-2.6.37/include/linux/sysfs.h 2011-01-04 19:50:19.000000000 -0500
47896 +++ linux-2.6.37/include/linux/sysfs.h 2011-01-17 02:41:02.000000000 -0500
47897 @@ -110,8 +110,8 @@ struct bin_attribute {
47898 #define sysfs_bin_attr_init(bin_attr) sysfs_attr_init(&(bin_attr)->attr)
47901 - ssize_t (*show)(struct kobject *, struct attribute *,char *);
47902 - ssize_t (*store)(struct kobject *,struct attribute *,const char *, size_t);
47903 + ssize_t (* const show)(struct kobject *, struct attribute *,char *);
47904 + ssize_t (* const store)(struct kobject *,struct attribute *,const char *, size_t);
47907 struct sysfs_dirent;
47908 diff -urNp linux-2.6.37/include/linux/tty.h linux-2.6.37/include/linux/tty.h
47909 --- linux-2.6.37/include/linux/tty.h 2011-01-04 19:50:19.000000000 -0500
47910 +++ linux-2.6.37/include/linux/tty.h 2011-01-17 02:41:02.000000000 -0500
47912 #include <linux/tty_driver.h>
47913 #include <linux/tty_ldisc.h>
47914 #include <linux/mutex.h>
47915 +#include <linux/poll.h>
47916 +#include <linux/smp_lock.h>
47918 #include <asm/system.h>
47920 @@ -465,7 +467,6 @@ extern int tty_perform_flush(struct tty_
47921 extern dev_t tty_devnum(struct tty_struct *tty);
47922 extern void proc_clear_tty(struct task_struct *p);
47923 extern struct tty_struct *get_current_tty(void);
47924 -extern void tty_default_fops(struct file_operations *fops);
47925 extern struct tty_struct *alloc_tty_struct(void);
47926 extern int tty_add_file(struct tty_struct *tty, struct file *file);
47927 extern void free_tty_struct(struct tty_struct *tty);
47928 @@ -528,6 +529,18 @@ extern void tty_ldisc_begin(void);
47929 /* This last one is just for the tty layer internals and shouldn't be used elsewhere */
47930 extern void tty_ldisc_enable(struct tty_struct *tty);
47933 +extern ssize_t tty_read(struct file *, char __user *, size_t, loff_t *);
47934 +extern ssize_t tty_write(struct file *, const char __user *, size_t, loff_t *);
47935 +extern unsigned int tty_poll(struct file *, poll_table *);
47936 +#ifdef CONFIG_COMPAT
47937 +extern long tty_compat_ioctl(struct file *file, unsigned int cmd,
47938 + unsigned long arg);
47940 +#define tty_compat_ioctl NULL
47942 +extern int tty_release(struct inode *, struct file *);
47943 +extern int tty_fasync(int fd, struct file *filp, int on);
47946 extern struct tty_ldisc_ops tty_ldisc_N_TTY;
47947 diff -urNp linux-2.6.37/include/linux/tty_ldisc.h linux-2.6.37/include/linux/tty_ldisc.h
47948 --- linux-2.6.37/include/linux/tty_ldisc.h 2011-01-04 19:50:19.000000000 -0500
47949 +++ linux-2.6.37/include/linux/tty_ldisc.h 2011-01-17 02:41:02.000000000 -0500
47950 @@ -147,7 +147,7 @@ struct tty_ldisc_ops {
47952 struct module *owner;
47955 + atomic_t refcount;
47959 diff -urNp linux-2.6.37/include/linux/types.h linux-2.6.37/include/linux/types.h
47960 --- linux-2.6.37/include/linux/types.h 2011-01-04 19:50:19.000000000 -0500
47961 +++ linux-2.6.37/include/linux/types.h 2011-01-17 02:41:02.000000000 -0500
47962 @@ -207,10 +207,26 @@ typedef struct {
47966 +#ifdef CONFIG_PAX_REFCOUNT
47969 +} atomic_unchecked_t;
47971 +typedef atomic_t atomic_unchecked_t;
47974 #ifdef CONFIG_64BIT
47979 +#ifdef CONFIG_PAX_REFCOUNT
47982 +} atomic64_unchecked_t;
47984 +typedef atomic64_t atomic64_unchecked_t;
47989 diff -urNp linux-2.6.37/include/linux/u64_stats_sync.h linux-2.6.37/include/linux/u64_stats_sync.h
47990 --- linux-2.6.37/include/linux/u64_stats_sync.h 2011-01-04 19:50:19.000000000 -0500
47991 +++ linux-2.6.37/include/linux/u64_stats_sync.h 2011-01-17 02:41:02.000000000 -0500
47992 @@ -67,21 +67,21 @@ struct u64_stats_sync {
47996 -static void inline u64_stats_update_begin(struct u64_stats_sync *syncp)
47997 +static inline void u64_stats_update_begin(struct u64_stats_sync *syncp)
47999 #if BITS_PER_LONG==32 && defined(CONFIG_SMP)
48000 write_seqcount_begin(&syncp->seq);
48004 -static void inline u64_stats_update_end(struct u64_stats_sync *syncp)
48005 +static inline void u64_stats_update_end(struct u64_stats_sync *syncp)
48007 #if BITS_PER_LONG==32 && defined(CONFIG_SMP)
48008 write_seqcount_end(&syncp->seq);
48012 -static unsigned int inline u64_stats_fetch_begin(const struct u64_stats_sync *syncp)
48013 +static inline unsigned int u64_stats_fetch_begin(const struct u64_stats_sync *syncp)
48015 #if BITS_PER_LONG==32 && defined(CONFIG_SMP)
48016 return read_seqcount_begin(&syncp->seq);
48017 @@ -93,7 +93,7 @@ static unsigned int inline u64_stats_fet
48021 -static bool inline u64_stats_fetch_retry(const struct u64_stats_sync *syncp,
48022 +static inline bool u64_stats_fetch_retry(const struct u64_stats_sync *syncp,
48023 unsigned int start)
48025 #if BITS_PER_LONG==32 && defined(CONFIG_SMP)
48026 @@ -112,7 +112,7 @@ static bool inline u64_stats_fetch_retry
48027 * - UP 32bit must disable BH.
48028 * - 64bit have no problem atomically reading u64 values, irq safe.
48030 -static unsigned int inline u64_stats_fetch_begin_bh(const struct u64_stats_sync *syncp)
48031 +static inline unsigned int u64_stats_fetch_begin_bh(const struct u64_stats_sync *syncp)
48033 #if BITS_PER_LONG==32 && defined(CONFIG_SMP)
48034 return read_seqcount_begin(&syncp->seq);
48035 @@ -124,7 +124,7 @@ static unsigned int inline u64_stats_fet
48039 -static bool inline u64_stats_fetch_retry_bh(const struct u64_stats_sync *syncp,
48040 +static inline bool u64_stats_fetch_retry_bh(const struct u64_stats_sync *syncp,
48041 unsigned int start)
48043 #if BITS_PER_LONG==32 && defined(CONFIG_SMP)
48044 diff -urNp linux-2.6.37/include/linux/uaccess.h linux-2.6.37/include/linux/uaccess.h
48045 --- linux-2.6.37/include/linux/uaccess.h 2011-01-04 19:50:19.000000000 -0500
48046 +++ linux-2.6.37/include/linux/uaccess.h 2011-01-17 02:41:02.000000000 -0500
48047 @@ -76,11 +76,11 @@ static inline unsigned long __copy_from_
48049 mm_segment_t old_fs = get_fs(); \
48051 - set_fs(KERNEL_DS); \
48052 pagefault_disable(); \
48053 + set_fs(KERNEL_DS); \
48054 ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
48055 - pagefault_enable(); \
48057 + pagefault_enable(); \
48061 @@ -93,8 +93,8 @@ static inline unsigned long __copy_from_
48062 * Safely read from address @src to the buffer at @dst. If a kernel fault
48063 * happens, handle that and return -EFAULT.
48065 -extern long probe_kernel_read(void *dst, void *src, size_t size);
48066 -extern long __probe_kernel_read(void *dst, void *src, size_t size);
48067 +extern long probe_kernel_read(void *dst, const void *src, size_t size);
48068 +extern long __probe_kernel_read(void *dst, const void *src, size_t size);
48071 * probe_kernel_write(): safely attempt to write to a location
48072 @@ -105,7 +105,7 @@ extern long __probe_kernel_read(void *ds
48073 * Safely write to address @dst from the buffer at @src. If a kernel fault
48074 * happens, handle that and return -EFAULT.
48076 -extern long notrace probe_kernel_write(void *dst, void *src, size_t size);
48077 -extern long notrace __probe_kernel_write(void *dst, void *src, size_t size);
48078 +extern long notrace probe_kernel_write(void *dst, const void *src, size_t size);
48079 +extern long notrace __probe_kernel_write(void *dst, const void *src, size_t size);
48081 #endif /* __LINUX_UACCESS_H__ */
48082 diff -urNp linux-2.6.37/include/linux/unaligned/access_ok.h linux-2.6.37/include/linux/unaligned/access_ok.h
48083 --- linux-2.6.37/include/linux/unaligned/access_ok.h 2011-01-04 19:50:19.000000000 -0500
48084 +++ linux-2.6.37/include/linux/unaligned/access_ok.h 2011-01-17 02:41:02.000000000 -0500
48087 static inline u16 get_unaligned_le16(const void *p)
48089 - return le16_to_cpup((__le16 *)p);
48090 + return le16_to_cpup((const __le16 *)p);
48093 static inline u32 get_unaligned_le32(const void *p)
48095 - return le32_to_cpup((__le32 *)p);
48096 + return le32_to_cpup((const __le32 *)p);
48099 static inline u64 get_unaligned_le64(const void *p)
48101 - return le64_to_cpup((__le64 *)p);
48102 + return le64_to_cpup((const __le64 *)p);
48105 static inline u16 get_unaligned_be16(const void *p)
48107 - return be16_to_cpup((__be16 *)p);
48108 + return be16_to_cpup((const __be16 *)p);
48111 static inline u32 get_unaligned_be32(const void *p)
48113 - return be32_to_cpup((__be32 *)p);
48114 + return be32_to_cpup((const __be32 *)p);
48117 static inline u64 get_unaligned_be64(const void *p)
48119 - return be64_to_cpup((__be64 *)p);
48120 + return be64_to_cpup((const __be64 *)p);
48123 static inline void put_unaligned_le16(u16 val, void *p)
48124 diff -urNp linux-2.6.37/include/linux/usb/hcd.h linux-2.6.37/include/linux/usb/hcd.h
48125 --- linux-2.6.37/include/linux/usb/hcd.h 2011-01-04 19:50:19.000000000 -0500
48126 +++ linux-2.6.37/include/linux/usb/hcd.h 2011-01-17 02:41:02.000000000 -0500
48127 @@ -580,7 +580,7 @@ struct usb_mon_operations {
48128 /* void (*urb_unlink)(struct usb_bus *bus, struct urb *urb); */
48131 -extern struct usb_mon_operations *mon_ops;
48132 +extern const struct usb_mon_operations *mon_ops;
48134 static inline void usbmon_urb_submit(struct usb_bus *bus, struct urb *urb)
48136 @@ -602,7 +602,7 @@ static inline void usbmon_urb_complete(s
48137 (*mon_ops->urb_complete)(bus, urb, status);
48140 -int usb_mon_register(struct usb_mon_operations *ops);
48141 +int usb_mon_register(const struct usb_mon_operations *ops);
48142 void usb_mon_deregister(void);
48145 diff -urNp linux-2.6.37/include/linux/vmalloc.h linux-2.6.37/include/linux/vmalloc.h
48146 --- linux-2.6.37/include/linux/vmalloc.h 2011-01-04 19:50:19.000000000 -0500
48147 +++ linux-2.6.37/include/linux/vmalloc.h 2011-01-17 02:41:02.000000000 -0500
48148 @@ -13,6 +13,11 @@ struct vm_area_struct; /* vma defining
48149 #define VM_MAP 0x00000004 /* vmap()ed pages */
48150 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
48151 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
48153 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
48154 +#define VM_KERNEXEC 0x00000020 /* allocate from executable kernel memory range */
48157 /* bits [20..32] reserved for arch specific ioremap internals */
48160 @@ -125,4 +130,103 @@ struct vm_struct **pcpu_get_vm_areas(con
48161 void pcpu_free_vm_areas(struct vm_struct **vms, int nr_vms);
48164 +#define vmalloc(x) \
48166 + void *___retval; \
48167 + intoverflow_t ___x = (intoverflow_t)x; \
48168 + if (WARN(___x > ULONG_MAX, "vmalloc size overflow\n")) \
48169 + ___retval = NULL; \
48171 + ___retval = vmalloc((unsigned long)___x); \
48175 +#define vzalloc(x) \
48177 + void *___retval; \
48178 + intoverflow_t ___x = (intoverflow_t)x; \
48179 + if (WARN(___x > ULONG_MAX, "vzalloc size overflow\n")) \
48180 + ___retval = NULL; \
48182 + ___retval = vzalloc((unsigned long)___x); \
48186 +#define __vmalloc(x, y, z) \
48188 + void *___retval; \
48189 + intoverflow_t ___x = (intoverflow_t)x; \
48190 + if (WARN(___x > ULONG_MAX, "__vmalloc size overflow\n"))\
48191 + ___retval = NULL; \
48193 + ___retval = __vmalloc((unsigned long)___x, (y), (z));\
48197 +#define vmalloc_user(x) \
48199 + void *___retval; \
48200 + intoverflow_t ___x = (intoverflow_t)x; \
48201 + if (WARN(___x > ULONG_MAX, "vmalloc_user size overflow\n"))\
48202 + ___retval = NULL; \
48204 + ___retval = vmalloc_user((unsigned long)___x); \
48208 +#define vmalloc_exec(x) \
48210 + void *___retval; \
48211 + intoverflow_t ___x = (intoverflow_t)x; \
48212 + if (WARN(___x > ULONG_MAX, "vmalloc_exec size overflow\n"))\
48213 + ___retval = NULL; \
48215 + ___retval = vmalloc_exec((unsigned long)___x); \
48219 +#define vmalloc_node(x, y) \
48221 + void *___retval; \
48222 + intoverflow_t ___x = (intoverflow_t)x; \
48223 + if (WARN(___x > ULONG_MAX, "vmalloc_node size overflow\n"))\
48224 + ___retval = NULL; \
48226 + ___retval = vmalloc_node((unsigned long)___x, (y));\
48230 +#define vzalloc_node(x, y) \
48232 + void *___retval; \
48233 + intoverflow_t ___x = (intoverflow_t)x; \
48234 + if (WARN(___x > ULONG_MAX, "vzalloc_node size overflow\n"))\
48235 + ___retval = NULL; \
48237 + ___retval = vzalloc_node((unsigned long)___x, (y));\
48241 +#define vmalloc_32(x) \
48243 + void *___retval; \
48244 + intoverflow_t ___x = (intoverflow_t)x; \
48245 + if (WARN(___x > ULONG_MAX, "vmalloc_32 size overflow\n"))\
48246 + ___retval = NULL; \
48248 + ___retval = vmalloc_32((unsigned long)___x); \
48252 +#define vmalloc_32_user(x) \
48254 +void *___retval; \
48255 + intoverflow_t ___x = (intoverflow_t)x; \
48256 + if (WARN(___x > ULONG_MAX, "vmalloc_32_user size overflow\n"))\
48257 + ___retval = NULL; \
48259 + ___retval = vmalloc_32_user((unsigned long)___x);\
48263 #endif /* _LINUX_VMALLOC_H */
48264 diff -urNp linux-2.6.37/include/linux/vmstat.h linux-2.6.37/include/linux/vmstat.h
48265 --- linux-2.6.37/include/linux/vmstat.h 2011-01-04 19:50:19.000000000 -0500
48266 +++ linux-2.6.37/include/linux/vmstat.h 2011-01-17 02:41:02.000000000 -0500
48267 @@ -140,18 +140,18 @@ static inline void vm_events_fold_cpu(in
48269 * Zone based page accounting with per cpu differentials.
48271 -extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
48272 +extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
48274 static inline void zone_page_state_add(long x, struct zone *zone,
48275 enum zone_stat_item item)
48277 - atomic_long_add(x, &zone->vm_stat[item]);
48278 - atomic_long_add(x, &vm_stat[item]);
48279 + atomic_long_add_unchecked(x, &zone->vm_stat[item]);
48280 + atomic_long_add_unchecked(x, &vm_stat[item]);
48283 static inline unsigned long global_page_state(enum zone_stat_item item)
48285 - long x = atomic_long_read(&vm_stat[item]);
48286 + long x = atomic_long_read_unchecked(&vm_stat[item]);
48290 @@ -162,7 +162,7 @@ static inline unsigned long global_page_
48291 static inline unsigned long zone_page_state(struct zone *zone,
48292 enum zone_stat_item item)
48294 - long x = atomic_long_read(&zone->vm_stat[item]);
48295 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
48299 @@ -179,7 +179,7 @@ static inline unsigned long zone_page_st
48300 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
48301 enum zone_stat_item item)
48303 - long x = atomic_long_read(&zone->vm_stat[item]);
48304 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
48308 @@ -268,8 +268,8 @@ static inline void __mod_zone_page_state
48310 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
48312 - atomic_long_inc(&zone->vm_stat[item]);
48313 - atomic_long_inc(&vm_stat[item]);
48314 + atomic_long_inc_unchecked(&zone->vm_stat[item]);
48315 + atomic_long_inc_unchecked(&vm_stat[item]);
48318 static inline void __inc_zone_page_state(struct page *page,
48319 @@ -280,8 +280,8 @@ static inline void __inc_zone_page_state
48321 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
48323 - atomic_long_dec(&zone->vm_stat[item]);
48324 - atomic_long_dec(&vm_stat[item]);
48325 + atomic_long_dec_unchecked(&zone->vm_stat[item]);
48326 + atomic_long_dec_unchecked(&vm_stat[item]);
48329 static inline void __dec_zone_page_state(struct page *page,
48330 diff -urNp linux-2.6.37/include/net/inetpeer.h linux-2.6.37/include/net/inetpeer.h
48331 --- linux-2.6.37/include/net/inetpeer.h 2011-01-04 19:50:19.000000000 -0500
48332 +++ linux-2.6.37/include/net/inetpeer.h 2011-01-17 02:41:02.000000000 -0500
48333 @@ -30,8 +30,8 @@ struct inet_peer {
48337 - atomic_t rid; /* Frag reception counter */
48338 - atomic_t ip_id_count; /* IP ID for the next packet */
48339 + atomic_unchecked_t rid; /* Frag reception counter */
48340 + atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
48342 __u32 tcp_ts_stamp;
48344 @@ -62,7 +62,7 @@ static inline __u16 inet_getid(struct in
48347 inet_peer_refcheck(p);
48348 - return atomic_add_return(more, &p->ip_id_count) - more;
48349 + return atomic_add_return_unchecked(more, &p->ip_id_count) - more;
48352 #endif /* _NET_INETPEER_H */
48353 diff -urNp linux-2.6.37/include/net/irda/ircomm_tty.h linux-2.6.37/include/net/irda/ircomm_tty.h
48354 --- linux-2.6.37/include/net/irda/ircomm_tty.h 2011-01-04 19:50:19.000000000 -0500
48355 +++ linux-2.6.37/include/net/irda/ircomm_tty.h 2011-01-17 02:41:02.000000000 -0500
48356 @@ -105,8 +105,8 @@ struct ircomm_tty_cb {
48357 unsigned short close_delay;
48358 unsigned short closing_wait; /* time to wait before closing */
48361 - int blocked_open; /* # of blocked opens */
48362 + atomic_t open_count;
48363 + atomic_t blocked_open; /* # of blocked opens */
48365 /* Protect concurent access to :
48366 * o self->open_count
48367 diff -urNp linux-2.6.37/include/net/neighbour.h linux-2.6.37/include/net/neighbour.h
48368 --- linux-2.6.37/include/net/neighbour.h 2011-01-04 19:50:19.000000000 -0500
48369 +++ linux-2.6.37/include/net/neighbour.h 2011-01-17 02:41:02.000000000 -0500
48370 @@ -118,12 +118,12 @@ struct neighbour {
48374 - void (*solicit)(struct neighbour *, struct sk_buff*);
48375 - void (*error_report)(struct neighbour *, struct sk_buff*);
48376 - int (*output)(struct sk_buff*);
48377 - int (*connected_output)(struct sk_buff*);
48378 - int (*hh_output)(struct sk_buff*);
48379 - int (*queue_xmit)(struct sk_buff*);
48380 + void (* const solicit)(struct neighbour *, struct sk_buff*);
48381 + void (* const error_report)(struct neighbour *, struct sk_buff*);
48382 + int (* const output)(struct sk_buff*);
48383 + int (* const connected_output)(struct sk_buff*);
48384 + int (* const hh_output)(struct sk_buff*);
48385 + int (* const queue_xmit)(struct sk_buff*);
48388 struct pneigh_entry {
48389 diff -urNp linux-2.6.37/include/net/netlink.h linux-2.6.37/include/net/netlink.h
48390 --- linux-2.6.37/include/net/netlink.h 2011-01-04 19:50:19.000000000 -0500
48391 +++ linux-2.6.37/include/net/netlink.h 2011-01-17 02:41:02.000000000 -0500
48392 @@ -558,7 +558,7 @@ static inline void *nlmsg_get_pos(struct
48393 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
48396 - skb_trim(skb, (unsigned char *) mark - skb->data);
48397 + skb_trim(skb, (const unsigned char *) mark - skb->data);
48401 diff -urNp linux-2.6.37/include/net/sctp/sctp.h linux-2.6.37/include/net/sctp/sctp.h
48402 --- linux-2.6.37/include/net/sctp/sctp.h 2011-01-04 19:50:19.000000000 -0500
48403 +++ linux-2.6.37/include/net/sctp/sctp.h 2011-01-17 02:41:02.000000000 -0500
48404 @@ -316,9 +316,9 @@ do { \
48406 #else /* SCTP_DEBUG */
48408 -#define SCTP_DEBUG_PRINTK(whatever...)
48409 -#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
48410 -#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
48411 +#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
48412 +#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
48413 +#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
48414 #define SCTP_ENABLE_DEBUG
48415 #define SCTP_DISABLE_DEBUG
48416 #define SCTP_ASSERT(expr, str, func)
48417 diff -urNp linux-2.6.37/include/net/tcp.h linux-2.6.37/include/net/tcp.h
48418 --- linux-2.6.37/include/net/tcp.h 2011-01-04 19:50:19.000000000 -0500
48419 +++ linux-2.6.37/include/net/tcp.h 2011-01-17 02:41:02.000000000 -0500
48420 @@ -1380,6 +1380,7 @@ enum tcp_seq_states {
48421 struct tcp_seq_afinfo {
48423 sa_family_t family;
48424 + /* cannot be const */
48425 struct file_operations seq_fops;
48426 struct seq_operations seq_ops;
48428 diff -urNp linux-2.6.37/include/net/udp.h linux-2.6.37/include/net/udp.h
48429 --- linux-2.6.37/include/net/udp.h 2011-01-04 19:50:19.000000000 -0500
48430 +++ linux-2.6.37/include/net/udp.h 2011-01-17 02:41:02.000000000 -0500
48431 @@ -223,6 +223,7 @@ struct udp_seq_afinfo {
48433 sa_family_t family;
48434 struct udp_table *udp_table;
48435 + /* cannot be const */
48436 struct file_operations seq_fops;
48437 struct seq_operations seq_ops;
48439 diff -urNp linux-2.6.37/include/sound/ac97_codec.h linux-2.6.37/include/sound/ac97_codec.h
48440 --- linux-2.6.37/include/sound/ac97_codec.h 2011-01-04 19:50:19.000000000 -0500
48441 +++ linux-2.6.37/include/sound/ac97_codec.h 2011-01-17 02:41:02.000000000 -0500
48442 @@ -419,15 +419,15 @@
48445 struct snd_ac97_build_ops {
48446 - int (*build_3d) (struct snd_ac97 *ac97);
48447 - int (*build_specific) (struct snd_ac97 *ac97);
48448 - int (*build_spdif) (struct snd_ac97 *ac97);
48449 - int (*build_post_spdif) (struct snd_ac97 *ac97);
48450 + int (* const build_3d) (struct snd_ac97 *ac97);
48451 + int (* const build_specific) (struct snd_ac97 *ac97);
48452 + int (* const build_spdif) (struct snd_ac97 *ac97);
48453 + int (* const build_post_spdif) (struct snd_ac97 *ac97);
48455 - void (*suspend) (struct snd_ac97 *ac97);
48456 - void (*resume) (struct snd_ac97 *ac97);
48457 + void (* const suspend) (struct snd_ac97 *ac97);
48458 + void (* const resume) (struct snd_ac97 *ac97);
48460 - void (*update_jacks) (struct snd_ac97 *ac97); /* for jack-sharing */
48461 + void (* const update_jacks) (struct snd_ac97 *ac97); /* for jack-sharing */
48464 struct snd_ac97_bus_ops {
48465 @@ -477,7 +477,7 @@ struct snd_ac97_template {
48468 /* -- lowlevel (hardware) driver specific -- */
48469 - struct snd_ac97_build_ops * build_ops;
48470 + const struct snd_ac97_build_ops * build_ops;
48471 void *private_data;
48472 void (*private_free) (struct snd_ac97 *ac97);
48474 diff -urNp linux-2.6.37/include/trace/events/irq.h linux-2.6.37/include/trace/events/irq.h
48475 --- linux-2.6.37/include/trace/events/irq.h 2011-01-04 19:50:19.000000000 -0500
48476 +++ linux-2.6.37/include/trace/events/irq.h 2011-01-17 02:41:02.000000000 -0500
48477 @@ -36,7 +36,7 @@ struct softirq_action;
48479 TRACE_EVENT(irq_handler_entry,
48481 - TP_PROTO(int irq, struct irqaction *action),
48482 + TP_PROTO(int irq, const struct irqaction *action),
48484 TP_ARGS(irq, action),
48486 @@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
48488 TRACE_EVENT(irq_handler_exit,
48490 - TP_PROTO(int irq, struct irqaction *action, int ret),
48491 + TP_PROTO(int irq, const struct irqaction *action, int ret),
48493 TP_ARGS(irq, action, ret),
48495 diff -urNp linux-2.6.37/include/video/uvesafb.h linux-2.6.37/include/video/uvesafb.h
48496 --- linux-2.6.37/include/video/uvesafb.h 2011-01-04 19:50:19.000000000 -0500
48497 +++ linux-2.6.37/include/video/uvesafb.h 2011-01-17 02:41:02.000000000 -0500
48498 @@ -177,6 +177,7 @@ struct uvesafb_par {
48499 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
48500 u8 pmi_setpal; /* PMI for palette changes */
48501 u16 *pmi_base; /* protected mode interface location */
48502 + u8 *pmi_code; /* protected mode code location */
48505 u8 *vbe_state_orig; /*
48506 diff -urNp linux-2.6.37/init/do_mounts.c linux-2.6.37/init/do_mounts.c
48507 --- linux-2.6.37/init/do_mounts.c 2011-01-04 19:50:19.000000000 -0500
48508 +++ linux-2.6.37/init/do_mounts.c 2011-01-17 02:41:02.000000000 -0500
48509 @@ -287,7 +287,7 @@ static void __init get_fs_names(char *pa
48511 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
48513 - int err = sys_mount(name, "/root", fs, flags, data);
48514 + int err = sys_mount((__force char __user *)name, (__force char __user *)"/root", (__force char __user *)fs, flags, (__force void __user *)data);
48518 @@ -382,18 +382,18 @@ void __init change_floppy(char *fmt, ...
48519 va_start(args, fmt);
48520 vsprintf(buf, fmt, args);
48522 - fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
48523 + fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
48525 sys_ioctl(fd, FDEJECT, 0);
48528 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
48529 - fd = sys_open("/dev/console", O_RDWR, 0);
48530 + fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
48532 sys_ioctl(fd, TCGETS, (long)&termios);
48533 termios.c_lflag &= ~ICANON;
48534 sys_ioctl(fd, TCSETSF, (long)&termios);
48535 - sys_read(fd, &c, 1);
48536 + sys_read(fd, (char __user *)&c, 1);
48537 termios.c_lflag |= ICANON;
48538 sys_ioctl(fd, TCSETSF, (long)&termios);
48540 @@ -487,6 +487,6 @@ void __init prepare_namespace(void)
48543 devtmpfs_mount("dev");
48544 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
48545 + sys_mount((__force char __user *)".", (__force char __user *)"/", NULL, MS_MOVE, NULL);
48546 sys_chroot((const char __user __force *)".");
48548 diff -urNp linux-2.6.37/init/do_mounts.h linux-2.6.37/init/do_mounts.h
48549 --- linux-2.6.37/init/do_mounts.h 2011-01-04 19:50:19.000000000 -0500
48550 +++ linux-2.6.37/init/do_mounts.h 2011-01-17 02:41:02.000000000 -0500
48551 @@ -15,15 +15,15 @@ extern int root_mountflags;
48553 static inline int create_dev(char *name, dev_t dev)
48555 - sys_unlink(name);
48556 - return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
48557 + sys_unlink((__force char __user *)name);
48558 + return sys_mknod((__force char __user *)name, S_IFBLK|0600, new_encode_dev(dev));
48561 #if BITS_PER_LONG == 32
48562 static inline u32 bstat(char *name)
48564 struct stat64 stat;
48565 - if (sys_stat64(name, &stat) != 0)
48566 + if (sys_stat64((__force char __user *)name, (__force struct stat64 __user *)&stat) != 0)
48568 if (!S_ISBLK(stat.st_mode))
48570 diff -urNp linux-2.6.37/init/do_mounts_initrd.c linux-2.6.37/init/do_mounts_initrd.c
48571 --- linux-2.6.37/init/do_mounts_initrd.c 2011-01-04 19:50:19.000000000 -0500
48572 +++ linux-2.6.37/init/do_mounts_initrd.c 2011-01-17 02:41:02.000000000 -0500
48573 @@ -44,13 +44,13 @@ static void __init handle_initrd(void)
48574 create_dev("/dev/root.old", Root_RAM0);
48575 /* mount initrd on rootfs' /root */
48576 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
48577 - sys_mkdir("/old", 0700);
48578 - root_fd = sys_open("/", 0, 0);
48579 - old_fd = sys_open("/old", 0, 0);
48580 + sys_mkdir((__force const char __user *)"/old", 0700);
48581 + root_fd = sys_open((__force const char __user *)"/", 0, 0);
48582 + old_fd = sys_open((__force const char __user *)"/old", 0, 0);
48583 /* move initrd over / and chdir/chroot in initrd root */
48584 - sys_chdir("/root");
48585 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
48587 + sys_chdir((__force const char __user *)"/root");
48588 + sys_mount((__force char __user *)".", (__force char __user *)"/", NULL, MS_MOVE, NULL);
48589 + sys_chroot((__force const char __user *)".");
48592 * In case that a resume from disk is carried out by linuxrc or one of
48593 @@ -67,15 +67,15 @@ static void __init handle_initrd(void)
48595 /* move initrd to rootfs' /old */
48596 sys_fchdir(old_fd);
48597 - sys_mount("/", ".", NULL, MS_MOVE, NULL);
48598 + sys_mount((__force char __user *)"/", (__force char __user *)".", NULL, MS_MOVE, NULL);
48599 /* switch root and cwd back to / of rootfs */
48600 sys_fchdir(root_fd);
48602 + sys_chroot((__force const char __user *)".");
48604 sys_close(root_fd);
48606 if (new_decode_dev(real_root_dev) == Root_RAM0) {
48607 - sys_chdir("/old");
48608 + sys_chdir((__force const char __user *)"/old");
48612 @@ -83,17 +83,17 @@ static void __init handle_initrd(void)
48615 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
48616 - error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
48617 + error = sys_mount((__force char __user *)"/old", (__force char __user *)"/root/initrd", NULL, MS_MOVE, NULL);
48621 - int fd = sys_open("/dev/root.old", O_RDWR, 0);
48622 + int fd = sys_open((__force const char __user *)"/dev/root.old", O_RDWR, 0);
48623 if (error == -ENOENT)
48624 printk("/initrd does not exist. Ignored.\n");
48626 printk("failed\n");
48627 printk(KERN_NOTICE "Unmounting old root\n");
48628 - sys_umount("/old", MNT_DETACH);
48629 + sys_umount((__force char __user *)"/old", MNT_DETACH);
48630 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
48633 @@ -116,11 +116,11 @@ int __init initrd_load(void)
48634 * mounted in the normal path.
48636 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
48637 - sys_unlink("/initrd.image");
48638 + sys_unlink((__force const char __user *)"/initrd.image");
48643 - sys_unlink("/initrd.image");
48644 + sys_unlink((__force const char __user *)"/initrd.image");
48647 diff -urNp linux-2.6.37/init/do_mounts_md.c linux-2.6.37/init/do_mounts_md.c
48648 --- linux-2.6.37/init/do_mounts_md.c 2011-01-04 19:50:19.000000000 -0500
48649 +++ linux-2.6.37/init/do_mounts_md.c 2011-01-17 02:41:02.000000000 -0500
48650 @@ -170,7 +170,7 @@ static void __init md_setup_drive(void)
48651 partitioned ? "_d" : "", minor,
48652 md_setup_args[ent].device_names);
48654 - fd = sys_open(name, 0, 0);
48655 + fd = sys_open((__force char __user *)name, 0, 0);
48657 printk(KERN_ERR "md: open failed - cannot start "
48658 "array %s\n", name);
48659 @@ -233,7 +233,7 @@ static void __init md_setup_drive(void)
48663 - fd = sys_open(name, 0, 0);
48664 + fd = sys_open((__force char __user *)name, 0, 0);
48665 sys_ioctl(fd, BLKRRPART, 0);
48668 diff -urNp linux-2.6.37/init/initramfs.c linux-2.6.37/init/initramfs.c
48669 --- linux-2.6.37/init/initramfs.c 2011-01-04 19:50:19.000000000 -0500
48670 +++ linux-2.6.37/init/initramfs.c 2011-01-17 02:41:02.000000000 -0500
48671 @@ -74,7 +74,7 @@ static void __init free_hash(void)
48675 -static long __init do_utime(char __user *filename, time_t mtime)
48676 +static long __init do_utime(__force char __user *filename, time_t mtime)
48678 struct timespec t[2];
48680 @@ -109,7 +109,7 @@ static void __init dir_utime(void)
48681 struct dir_entry *de, *tmp;
48682 list_for_each_entry_safe(de, tmp, &dir_list, list) {
48683 list_del(&de->list);
48684 - do_utime(de->name, de->mtime);
48685 + do_utime((__force char __user *)de->name, de->mtime);
48689 @@ -271,7 +271,7 @@ static int __init maybe_link(void)
48691 char *old = find_link(major, minor, ino, mode, collected);
48693 - return (sys_link(old, collected) < 0) ? -1 : 1;
48694 + return (sys_link((__force char __user *)old, (__force char __user *)collected) < 0) ? -1 : 1;
48698 @@ -280,11 +280,11 @@ static void __init clean_path(char *path
48702 - if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
48703 + if (!sys_newlstat((__force char __user *)path, (__force struct stat __user *)&st) && (st.st_mode^mode) & S_IFMT) {
48704 if (S_ISDIR(st.st_mode))
48706 + sys_rmdir((__force char __user *)path);
48708 - sys_unlink(path);
48709 + sys_unlink((__force char __user *)path);
48713 @@ -305,7 +305,7 @@ static int __init do_name(void)
48714 int openflags = O_WRONLY|O_CREAT;
48716 openflags |= O_TRUNC;
48717 - wfd = sys_open(collected, openflags, mode);
48718 + wfd = sys_open((__force char __user *)collected, openflags, mode);
48721 sys_fchown(wfd, uid, gid);
48722 @@ -317,17 +317,17 @@ static int __init do_name(void)
48725 } else if (S_ISDIR(mode)) {
48726 - sys_mkdir(collected, mode);
48727 - sys_chown(collected, uid, gid);
48728 - sys_chmod(collected, mode);
48729 + sys_mkdir((__force char __user *)collected, mode);
48730 + sys_chown((__force char __user *)collected, uid, gid);
48731 + sys_chmod((__force char __user *)collected, mode);
48732 dir_add(collected, mtime);
48733 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
48734 S_ISFIFO(mode) || S_ISSOCK(mode)) {
48735 if (maybe_link() == 0) {
48736 - sys_mknod(collected, mode, rdev);
48737 - sys_chown(collected, uid, gid);
48738 - sys_chmod(collected, mode);
48739 - do_utime(collected, mtime);
48740 + sys_mknod((__force char __user *)collected, mode, rdev);
48741 + sys_chown((__force char __user *)collected, uid, gid);
48742 + sys_chmod((__force char __user *)collected, mode);
48743 + do_utime((__force char __user *)collected, mtime);
48747 @@ -336,15 +336,15 @@ static int __init do_name(void)
48748 static int __init do_copy(void)
48750 if (count >= body_len) {
48751 - sys_write(wfd, victim, body_len);
48752 + sys_write(wfd, (__force char __user *)victim, body_len);
48754 - do_utime(vcollected, mtime);
48755 + do_utime((__force char __user *)vcollected, mtime);
48761 - sys_write(wfd, victim, count);
48762 + sys_write(wfd, (__force char __user *)victim, count);
48766 @@ -355,9 +355,9 @@ static int __init do_symlink(void)
48768 collected[N_ALIGN(name_len) + body_len] = '\0';
48769 clean_path(collected, 0);
48770 - sys_symlink(collected + N_ALIGN(name_len), collected);
48771 - sys_lchown(collected, uid, gid);
48772 - do_utime(collected, mtime);
48773 + sys_symlink((__force char __user *)collected + N_ALIGN(name_len), (__force char __user *)collected);
48774 + sys_lchown((__force char __user *)collected, uid, gid);
48775 + do_utime((__force char __user *)collected, mtime);
48777 next_state = Reset;
48779 diff -urNp linux-2.6.37/init/Kconfig linux-2.6.37/init/Kconfig
48780 --- linux-2.6.37/init/Kconfig 2011-01-04 19:50:19.000000000 -0500
48781 +++ linux-2.6.37/init/Kconfig 2011-01-17 02:41:02.000000000 -0500
48782 @@ -1108,7 +1108,7 @@ config SLUB_DEBUG
48785 bool "Disable heap randomization"
48789 Randomizing heap placement makes heap exploits harder, but it
48790 also breaks ancient binaries (including anything libc5 based).
48791 diff -urNp linux-2.6.37/init/main.c linux-2.6.37/init/main.c
48792 --- linux-2.6.37/init/main.c 2011-01-04 19:50:19.000000000 -0500
48793 +++ linux-2.6.37/init/main.c 2011-01-17 02:41:02.000000000 -0500
48794 @@ -94,6 +94,7 @@ static inline void mark_rodata_ro(void)
48796 extern void tc_init(void);
48798 +extern void grsecurity_init(void);
48800 enum system_states system_state __read_mostly;
48801 EXPORT_SYMBOL(system_state);
48802 @@ -196,6 +197,47 @@ static int __init set_reset_devices(char
48804 __setup("reset_devices", set_reset_devices);
48806 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
48807 +extern char pax_enter_kernel_user[];
48808 +extern char pax_exit_kernel_user[];
48809 +extern pgdval_t clone_pgd_mask;
48812 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
48813 +static int __init setup_pax_nouderef(char *str)
48815 +#ifdef CONFIG_X86_32
48816 + unsigned int cpu;
48818 + for (cpu = 0; cpu < NR_CPUS; cpu++) {
48819 + get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_DS].type = 3;
48820 + get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_DS].limit = 0xf;
48821 + get_cpu_gdt_table(cpu)[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
48822 + get_cpu_gdt_table(cpu)[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
48824 + asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r" (__KERNEL_DS) : "memory");
48826 + memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
48827 + memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
48828 + clone_pgd_mask = ~(pgdval_t)0UL;
48833 +early_param("pax_nouderef", setup_pax_nouderef);
48836 +#ifdef CONFIG_PAX_SOFTMODE
48837 +unsigned int pax_softmode;
48839 +static int __init setup_pax_softmode(char *str)
48841 + get_option(&str, &pax_softmode);
48844 +__setup("pax_softmode=", setup_pax_softmode);
48847 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
48848 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
48849 static const char *panic_later, *panic_param;
48850 @@ -740,6 +782,7 @@ int __init_or_module do_one_initcall(ini
48852 int count = preempt_count();
48854 + const char *msg1 = "", *msg2 = "";
48856 if (initcall_debug)
48857 ret = do_one_initcall_debug(fn);
48858 @@ -752,15 +795,15 @@ int __init_or_module do_one_initcall(ini
48859 sprintf(msgbuf, "error code %d ", ret);
48861 if (preempt_count() != count) {
48862 - strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
48863 + msg1 = " preemption imbalance";
48864 preempt_count() = count;
48866 if (irqs_disabled()) {
48867 - strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
48868 + msg2 = " disabled interrupts";
48869 local_irq_enable();
48872 - printk("initcall %pF returned with %s\n", fn, msgbuf);
48873 + if (msgbuf[0] || *msg1 || *msg2) {
48874 + printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
48878 @@ -889,7 +932,7 @@ static int __init kernel_init(void * unu
48881 /* Open the /dev/console on the rootfs, this should never fail */
48882 - if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
48883 + if (sys_open((__force const char __user *) "/dev/console", O_RDWR, 0) < 0)
48884 printk(KERN_WARNING "Warning: unable to open an initial console.\n");
48887 @@ -902,11 +945,13 @@ static int __init kernel_init(void * unu
48888 if (!ramdisk_execute_command)
48889 ramdisk_execute_command = "/init";
48891 - if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
48892 + if (sys_access((__force const char __user *) ramdisk_execute_command, 0) != 0) {
48893 ramdisk_execute_command = NULL;
48894 prepare_namespace();
48897 + grsecurity_init();
48900 * Ok, we have completed the initial bootup, and
48901 * we're essentially up and running. Get rid of the
48902 diff -urNp linux-2.6.37/ipc/mqueue.c linux-2.6.37/ipc/mqueue.c
48903 --- linux-2.6.37/ipc/mqueue.c 2011-01-04 19:50:19.000000000 -0500
48904 +++ linux-2.6.37/ipc/mqueue.c 2011-01-17 02:41:02.000000000 -0500
48905 @@ -154,6 +154,7 @@ static struct inode *mqueue_get_inode(st
48906 mq_bytes = (mq_msg_tblsz +
48907 (info->attr.mq_maxmsg * info->attr.mq_msgsize));
48909 + gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
48910 spin_lock(&mq_lock);
48911 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
48912 u->mq_bytes + mq_bytes >
48913 diff -urNp linux-2.6.37/ipc/shm.c linux-2.6.37/ipc/shm.c
48914 --- linux-2.6.37/ipc/shm.c 2011-01-04 19:50:19.000000000 -0500
48915 +++ linux-2.6.37/ipc/shm.c 2011-01-17 02:41:02.000000000 -0500
48916 @@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_name
48917 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
48920 +#ifdef CONFIG_GRKERNSEC
48921 +extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
48922 + const time_t shm_createtime, const uid_t cuid,
48923 + const int shmid);
48924 +extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
48925 + const time_t shm_createtime);
48928 void shm_init_ns(struct ipc_namespace *ns)
48930 ns->shm_ctlmax = SHMMAX;
48931 @@ -401,6 +409,14 @@ static int newseg(struct ipc_namespace *
48932 shp->shm_lprid = 0;
48933 shp->shm_atim = shp->shm_dtim = 0;
48934 shp->shm_ctim = get_seconds();
48935 +#ifdef CONFIG_GRKERNSEC
48937 + struct timespec timeval;
48938 + do_posix_clock_monotonic_gettime(&timeval);
48940 + shp->shm_createtime = timeval.tv_sec;
48943 shp->shm_segsz = size;
48944 shp->shm_nattch = 0;
48945 shp->shm_file = file;
48946 @@ -895,9 +911,21 @@ long do_shmat(int shmid, char __user *sh
48950 +#ifdef CONFIG_GRKERNSEC
48951 + if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
48952 + shp->shm_perm.cuid, shmid) ||
48953 + !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
48959 path = shp->shm_file->f_path;
48962 +#ifdef CONFIG_GRKERNSEC
48963 + shp->shm_lapid = current->pid;
48965 size = i_size_read(path.dentry->d_inode);
48968 diff -urNp linux-2.6.37/kernel/acct.c linux-2.6.37/kernel/acct.c
48969 --- linux-2.6.37/kernel/acct.c 2011-01-04 19:50:19.000000000 -0500
48970 +++ linux-2.6.37/kernel/acct.c 2011-01-17 02:41:02.000000000 -0500
48971 @@ -570,7 +570,7 @@ static void do_acct_process(struct bsd_a
48973 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
48974 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
48975 - file->f_op->write(file, (char *)&ac,
48976 + file->f_op->write(file, (__force char __user *)&ac,
48977 sizeof(acct_t), &file->f_pos);
48978 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
48980 diff -urNp linux-2.6.37/kernel/capability.c linux-2.6.37/kernel/capability.c
48981 --- linux-2.6.37/kernel/capability.c 2011-01-04 19:50:19.000000000 -0500
48982 +++ linux-2.6.37/kernel/capability.c 2011-01-17 02:41:02.000000000 -0500
48983 @@ -205,6 +205,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_
48984 * before modification is attempted and the application
48987 + if (tocopy > ARRAY_SIZE(kdata))
48990 if (copy_to_user(dataptr, kdata, tocopy
48991 * sizeof(struct __user_cap_data_struct))) {
48993 @@ -306,10 +309,26 @@ int capable(int cap)
48997 - if (security_capable(cap) == 0) {
48998 + if (security_capable(cap) == 0 && gr_is_capable(cap)) {
48999 current->flags |= PF_SUPERPRIV;
49005 +int capable_nolog(int cap)
49007 + if (unlikely(!cap_valid(cap))) {
49008 + printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
49012 + if (security_capable(cap) == 0 && gr_is_capable_nolog(cap)) {
49013 + current->flags |= PF_SUPERPRIV;
49019 EXPORT_SYMBOL(capable);
49020 +EXPORT_SYMBOL(capable_nolog);
49021 diff -urNp linux-2.6.37/kernel/compat.c linux-2.6.37/kernel/compat.c
49022 --- linux-2.6.37/kernel/compat.c 2011-01-04 19:50:19.000000000 -0500
49023 +++ linux-2.6.37/kernel/compat.c 2011-01-17 02:41:02.000000000 -0500
49026 #include <linux/linkage.h>
49027 #include <linux/compat.h>
49028 +#include <linux/module.h>
49029 #include <linux/errno.h>
49030 #include <linux/time.h>
49031 #include <linux/signal.h>
49032 diff -urNp linux-2.6.37/kernel/configs.c linux-2.6.37/kernel/configs.c
49033 --- linux-2.6.37/kernel/configs.c 2011-01-04 19:50:19.000000000 -0500
49034 +++ linux-2.6.37/kernel/configs.c 2011-01-17 02:41:02.000000000 -0500
49035 @@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
49036 struct proc_dir_entry *entry;
49038 /* create the current config file */
49039 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
49040 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
49041 + entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
49042 + &ikconfig_file_ops);
49043 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49044 + entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
49045 + &ikconfig_file_ops);
49048 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
49049 &ikconfig_file_ops);
49055 diff -urNp linux-2.6.37/kernel/cred.c linux-2.6.37/kernel/cred.c
49056 --- linux-2.6.37/kernel/cred.c 2011-01-04 19:50:19.000000000 -0500
49057 +++ linux-2.6.37/kernel/cred.c 2011-01-17 02:41:02.000000000 -0500
49058 @@ -483,6 +483,8 @@ int commit_creds(struct cred *new)
49060 get_cred(new); /* we will require a ref for the subj creds too */
49062 + gr_set_role_label(task, new->uid, new->gid);
49064 /* dumpability changes */
49065 if (old->euid != new->euid ||
49066 old->egid != new->egid ||
49067 diff -urNp linux-2.6.37/kernel/debug/debug_core.c linux-2.6.37/kernel/debug/debug_core.c
49068 --- linux-2.6.37/kernel/debug/debug_core.c 2011-01-04 19:50:19.000000000 -0500
49069 +++ linux-2.6.37/kernel/debug/debug_core.c 2011-01-17 02:41:02.000000000 -0500
49070 @@ -72,7 +72,7 @@ int kgdb_io_module_registered;
49071 /* Guard for recursive entry */
49072 static int exception_level;
49074 -struct kgdb_io *dbg_io_ops;
49075 +const struct kgdb_io *dbg_io_ops;
49076 static DEFINE_SPINLOCK(kgdb_registration_lock);
49078 /* kgdb console driver is loaded */
49079 @@ -864,7 +864,7 @@ static void kgdb_initial_breakpoint(void
49081 * Register it with the KGDB core.
49083 -int kgdb_register_io_module(struct kgdb_io *new_dbg_io_ops)
49084 +int kgdb_register_io_module(const struct kgdb_io *new_dbg_io_ops)
49088 @@ -909,7 +909,7 @@ EXPORT_SYMBOL_GPL(kgdb_register_io_modul
49090 * Unregister it with the KGDB core.
49092 -void kgdb_unregister_io_module(struct kgdb_io *old_dbg_io_ops)
49093 +void kgdb_unregister_io_module(const struct kgdb_io *old_dbg_io_ops)
49095 BUG_ON(kgdb_connected);
49097 diff -urNp linux-2.6.37/kernel/debug/kdb/kdb_main.c linux-2.6.37/kernel/debug/kdb/kdb_main.c
49098 --- linux-2.6.37/kernel/debug/kdb/kdb_main.c 2011-01-04 19:50:19.000000000 -0500
49099 +++ linux-2.6.37/kernel/debug/kdb/kdb_main.c 2011-01-17 02:41:02.000000000 -0500
49100 @@ -1980,7 +1980,7 @@ static int kdb_lsmod(int argc, const cha
49101 list_for_each_entry(mod, kdb_modules, list) {
49103 kdb_printf("%-20s%8u 0x%p ", mod->name,
49104 - mod->core_size, (void *)mod);
49105 + mod->core_size_rx + mod->core_size_rw, (void *)mod);
49106 #ifdef CONFIG_MODULE_UNLOAD
49107 kdb_printf("%4d ", module_refcount(mod));
49109 @@ -1990,7 +1990,7 @@ static int kdb_lsmod(int argc, const cha
49110 kdb_printf(" (Loading)");
49112 kdb_printf(" (Live)");
49113 - kdb_printf(" 0x%p", mod->module_core);
49114 + kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
49116 #ifdef CONFIG_MODULE_UNLOAD
49118 diff -urNp linux-2.6.37/kernel/exit.c linux-2.6.37/kernel/exit.c
49119 --- linux-2.6.37/kernel/exit.c 2011-01-04 19:50:19.000000000 -0500
49120 +++ linux-2.6.37/kernel/exit.c 2011-01-17 02:41:02.000000000 -0500
49122 #include <asm/pgtable.h>
49123 #include <asm/mmu_context.h>
49125 +#ifdef CONFIG_GRKERNSEC
49126 +extern rwlock_t grsec_exec_file_lock;
49129 static void exit_mm(struct task_struct * tsk);
49131 static void __unhash_process(struct task_struct *p, bool group_dead)
49132 @@ -169,6 +173,8 @@ void release_task(struct task_struct * p
49133 struct task_struct *leader;
49136 + gr_del_task_from_ip_table(p);
49138 tracehook_prepare_release_task(p);
49139 /* don't need to get the RCU readlock here - the process is dead and
49140 * can't be modifying its own credentials. But shut RCU-lockdep up */
49141 @@ -338,11 +344,22 @@ static void reparent_to_kthreadd(void)
49143 write_lock_irq(&tasklist_lock);
49145 +#ifdef CONFIG_GRKERNSEC
49146 + write_lock(&grsec_exec_file_lock);
49147 + if (current->exec_file) {
49148 + fput(current->exec_file);
49149 + current->exec_file = NULL;
49151 + write_unlock(&grsec_exec_file_lock);
49154 ptrace_unlink(current);
49155 /* Reparent to init */
49156 current->real_parent = current->parent = kthreadd_task;
49157 list_move_tail(¤t->sibling, ¤t->real_parent->children);
49159 + gr_set_kernel_label(current);
49161 /* Set the exit signal to SIGCHLD so we signal init on exit */
49162 current->exit_signal = SIGCHLD;
49164 @@ -394,7 +411,7 @@ int allow_signal(int sig)
49165 * know it'll be handled, so that they don't get converted to
49166 * SIGKILL or just silently dropped.
49168 - current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
49169 + current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
49170 recalc_sigpending();
49171 spin_unlock_irq(¤t->sighand->siglock);
49173 @@ -430,6 +447,17 @@ void daemonize(const char *name, ...)
49174 vsnprintf(current->comm, sizeof(current->comm), name, args);
49177 +#ifdef CONFIG_GRKERNSEC
49178 + write_lock(&grsec_exec_file_lock);
49179 + if (current->exec_file) {
49180 + fput(current->exec_file);
49181 + current->exec_file = NULL;
49183 + write_unlock(&grsec_exec_file_lock);
49186 + gr_set_kernel_label(current);
49189 * If we were started as result of loading a module, close all of the
49190 * user space pages. We don't need them, and if we didn't close them
49191 @@ -905,17 +933,17 @@ NORET_TYPE void do_exit(long code)
49192 struct task_struct *tsk = current;
49195 - profile_task_exit(tsk);
49197 - WARN_ON(atomic_read(&tsk->fs_excl));
49200 + * Check this first since set_fs() below depends on
49201 + * current_thread_info(), which we better not access when we're in
49202 + * interrupt context. Other than that, we want to do the set_fs()
49203 + * as early as possible.
49205 if (unlikely(in_interrupt()))
49206 panic("Aiee, killing interrupt handler!");
49207 - if (unlikely(!tsk->pid))
49208 - panic("Attempted to kill the idle task!");
49211 - * If do_exit is called because this processes oopsed, it's possible
49212 + * If do_exit is called because this processes Oops'ed, it's possible
49213 * that get_fs() was left as KERNEL_DS, so reset it to USER_DS before
49214 * continuing. Amongst other possible reasons, this is to prevent
49215 * mm_release()->clear_child_tid() from writing to a user-controlled
49216 @@ -923,6 +951,13 @@ NORET_TYPE void do_exit(long code)
49220 + profile_task_exit(tsk);
49222 + WARN_ON(atomic_read(&tsk->fs_excl));
49224 + if (unlikely(!tsk->pid))
49225 + panic("Attempted to kill the idle task!");
49227 tracehook_report_exit(&code);
49229 validate_creds_for_do_exit(tsk);
49230 @@ -983,6 +1018,9 @@ NORET_TYPE void do_exit(long code)
49231 tsk->exit_code = code;
49232 taskstats_exit(tsk, group_dead);
49234 + gr_acl_handle_psacct(tsk, code);
49235 + gr_acl_handle_exit();
49240 diff -urNp linux-2.6.37/kernel/fork.c linux-2.6.37/kernel/fork.c
49241 --- linux-2.6.37/kernel/fork.c 2011-01-04 19:50:19.000000000 -0500
49242 +++ linux-2.6.37/kernel/fork.c 2011-01-17 02:41:02.000000000 -0500
49243 @@ -278,7 +278,7 @@ static struct task_struct *dup_task_stru
49244 *stackend = STACK_END_MAGIC; /* for overflow detection */
49246 #ifdef CONFIG_CC_STACKPROTECTOR
49247 - tsk->stack_canary = get_random_int();
49248 + tsk->stack_canary = pax_get_random_long();
49251 /* One for us, one for whoever does the "release_task()" (usually parent) */
49252 @@ -300,13 +300,78 @@ out:
49256 +static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct vm_area_struct *mpnt)
49258 + struct vm_area_struct *tmp;
49259 + unsigned long charge;
49260 + struct mempolicy *pol;
49261 + struct file *file;
49264 + if (mpnt->vm_flags & VM_ACCOUNT) {
49265 + unsigned int len = (mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT;
49266 + if (security_vm_enough_memory(len))
49270 + tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
49275 + INIT_LIST_HEAD(&tmp->anon_vma_chain);
49276 + pol = mpol_dup(vma_policy(mpnt));
49278 + goto fail_nomem_policy;
49279 + vma_set_policy(tmp, pol);
49280 + if (anon_vma_fork(tmp, mpnt))
49281 + goto fail_nomem_anon_vma_fork;
49282 + tmp->vm_flags &= ~VM_LOCKED;
49283 + tmp->vm_next = tmp->vm_prev = NULL;
49284 + tmp->vm_mirror = NULL;
49285 + file = tmp->vm_file;
49287 + struct inode *inode = file->f_path.dentry->d_inode;
49288 + struct address_space *mapping = file->f_mapping;
49291 + if (tmp->vm_flags & VM_DENYWRITE)
49292 + atomic_dec(&inode->i_writecount);
49293 + spin_lock(&mapping->i_mmap_lock);
49294 + if (tmp->vm_flags & VM_SHARED)
49295 + mapping->i_mmap_writable++;
49296 + tmp->vm_truncate_count = mpnt->vm_truncate_count;
49297 + flush_dcache_mmap_lock(mapping);
49298 + /* insert tmp into the share list, just after mpnt */
49299 + vma_prio_tree_add(tmp, mpnt);
49300 + flush_dcache_mmap_unlock(mapping);
49301 + spin_unlock(&mapping->i_mmap_lock);
49305 + * Clear hugetlb-related page reserves for children. This only
49306 + * affects MAP_PRIVATE mappings. Faults generated by the child
49307 + * are not guaranteed to succeed, even if read-only
49309 + if (is_vm_hugetlb_page(tmp))
49310 + reset_vma_resv_huge_pages(tmp);
49314 +fail_nomem_anon_vma_fork:
49316 +fail_nomem_policy:
49317 + kmem_cache_free(vm_area_cachep, tmp);
49319 + vm_unacct_memory(charge);
49323 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
49325 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
49326 struct rb_node **rb_link, *rb_parent;
49328 - unsigned long charge;
49329 - struct mempolicy *pol;
49331 down_write(&oldmm->mmap_sem);
49332 flush_cache_dup_mm(oldmm);
49333 @@ -318,8 +383,8 @@ static int dup_mmap(struct mm_struct *mm
49336 mm->mmap_cache = NULL;
49337 - mm->free_area_cache = oldmm->mmap_base;
49338 - mm->cached_hole_size = ~0UL;
49339 + mm->free_area_cache = oldmm->free_area_cache;
49340 + mm->cached_hole_size = oldmm->cached_hole_size;
49342 cpumask_clear(mm_cpumask(mm));
49343 mm->mm_rb = RB_ROOT;
49344 @@ -332,8 +397,6 @@ static int dup_mmap(struct mm_struct *mm
49347 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
49348 - struct file *file;
49350 if (mpnt->vm_flags & VM_DONTCOPY) {
49351 long pages = vma_pages(mpnt);
49352 mm->total_vm -= pages;
49353 @@ -341,56 +404,13 @@ static int dup_mmap(struct mm_struct *mm
49358 - if (mpnt->vm_flags & VM_ACCOUNT) {
49359 - unsigned int len = (mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT;
49360 - if (security_vm_enough_memory(len))
49364 - tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
49368 - INIT_LIST_HEAD(&tmp->anon_vma_chain);
49369 - pol = mpol_dup(vma_policy(mpnt));
49370 - retval = PTR_ERR(pol);
49372 - goto fail_nomem_policy;
49373 - vma_set_policy(tmp, pol);
49375 - if (anon_vma_fork(tmp, mpnt))
49376 - goto fail_nomem_anon_vma_fork;
49377 - tmp->vm_flags &= ~VM_LOCKED;
49378 - tmp->vm_next = tmp->vm_prev = NULL;
49379 - file = tmp->vm_file;
49381 - struct inode *inode = file->f_path.dentry->d_inode;
49382 - struct address_space *mapping = file->f_mapping;
49385 - if (tmp->vm_flags & VM_DENYWRITE)
49386 - atomic_dec(&inode->i_writecount);
49387 - spin_lock(&mapping->i_mmap_lock);
49388 - if (tmp->vm_flags & VM_SHARED)
49389 - mapping->i_mmap_writable++;
49390 - tmp->vm_truncate_count = mpnt->vm_truncate_count;
49391 - flush_dcache_mmap_lock(mapping);
49392 - /* insert tmp into the share list, just after mpnt */
49393 - vma_prio_tree_add(tmp, mpnt);
49394 - flush_dcache_mmap_unlock(mapping);
49395 - spin_unlock(&mapping->i_mmap_lock);
49396 + tmp = dup_vma(mm, mpnt);
49398 + retval = -ENOMEM;
49403 - * Clear hugetlb-related page reserves for children. This only
49404 - * affects MAP_PRIVATE mappings. Faults generated by the child
49405 - * are not guaranteed to succeed, even if read-only
49407 - if (is_vm_hugetlb_page(tmp))
49408 - reset_vma_resv_huge_pages(tmp);
49411 * Link in the new vma and copy the page table entries.
49414 @@ -411,6 +431,31 @@ static int dup_mmap(struct mm_struct *mm
49419 +#ifdef CONFIG_PAX_SEGMEXEC
49420 + if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
49421 + struct vm_area_struct *mpnt_m;
49423 + for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
49424 + BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
49426 + if (!mpnt->vm_mirror)
49429 + if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
49430 + BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
49431 + mpnt->vm_mirror = mpnt_m;
49433 + BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
49434 + mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
49435 + mpnt_m->vm_mirror->vm_mirror = mpnt_m;
49436 + mpnt->vm_mirror->vm_mirror = mpnt;
49443 /* a new mm has just been created */
49444 arch_dup_mmap(oldmm, mm);
49446 @@ -419,14 +464,6 @@ out:
49447 flush_tlb_mm(oldmm);
49448 up_write(&oldmm->mmap_sem);
49450 -fail_nomem_anon_vma_fork:
49452 -fail_nomem_policy:
49453 - kmem_cache_free(vm_area_cachep, tmp);
49455 - retval = -ENOMEM;
49456 - vm_unacct_memory(charge);
49460 static inline int mm_alloc_pgd(struct mm_struct * mm)
49461 @@ -765,13 +802,14 @@ static int copy_fs(unsigned long clone_f
49462 spin_unlock(&fs->lock);
49466 + atomic_inc(&fs->users);
49467 spin_unlock(&fs->lock);
49470 tsk->fs = copy_fs_struct(fs);
49473 + gr_set_chroot_entries(tsk, &tsk->fs->root);
49477 @@ -1027,10 +1065,13 @@ static struct task_struct *copy_process(
49479 if (!vx_nproc_avail(1))
49480 goto bad_fork_free;
49482 + gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
49484 if (atomic_read(&p->real_cred->user->processes) >=
49485 task_rlimit(p, RLIMIT_NPROC)) {
49486 - if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
49487 - p->real_cred->user != INIT_USER)
49488 + if (p->real_cred->user != INIT_USER &&
49489 + !capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE))
49490 goto bad_fork_free;
49493 @@ -1184,6 +1225,8 @@ static struct task_struct *copy_process(
49494 goto bad_fork_free_pid;
49497 + gr_copy_label(p);
49499 p->set_child_tid = (clone_flags & CLONE_CHILD_SETTID) ? child_tidptr : NULL;
49501 * Clear TID on mm_release()?
49502 @@ -1341,6 +1384,8 @@ bad_fork_cleanup_count:
49506 + gr_log_forkfail(retval);
49508 return ERR_PTR(retval);
49511 @@ -1446,6 +1491,8 @@ long do_fork(unsigned long clone_flags,
49512 if (clone_flags & CLONE_PARENT_SETTID)
49513 put_user(nr, parent_tidptr);
49515 + gr_handle_brute_check();
49517 if (clone_flags & CLONE_VFORK) {
49518 p->vfork_done = &vfork;
49519 init_completion(&vfork);
49520 @@ -1570,7 +1617,7 @@ static int unshare_fs(unsigned long unsh
49523 /* don't need lock here; in the worst case we'll do useless copy */
49524 - if (fs->users == 1)
49525 + if (atomic_read(&fs->users) == 1)
49528 *new_fsp = copy_fs_struct(fs);
49529 @@ -1693,7 +1740,8 @@ SYSCALL_DEFINE1(unshare, unsigned long,
49531 spin_lock(&fs->lock);
49532 current->fs = new_fs;
49534 + gr_set_chroot_entries(current, ¤t->fs->root);
49535 + if (atomic_dec_return(&fs->users))
49539 diff -urNp linux-2.6.37/kernel/futex.c linux-2.6.37/kernel/futex.c
49540 --- linux-2.6.37/kernel/futex.c 2011-01-04 19:50:19.000000000 -0500
49541 +++ linux-2.6.37/kernel/futex.c 2011-01-17 02:41:02.000000000 -0500
49543 #include <linux/mount.h>
49544 #include <linux/pagemap.h>
49545 #include <linux/syscalls.h>
49546 +#include <linux/ptrace.h>
49547 #include <linux/signal.h>
49548 #include <linux/module.h>
49549 #include <linux/magic.h>
49550 @@ -222,6 +223,11 @@ get_futex_key(u32 __user *uaddr, int fsh
49554 +#ifdef CONFIG_PAX_SEGMEXEC
49555 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
49560 * The futex address must be "naturally" aligned.
49562 @@ -2384,7 +2390,9 @@ SYSCALL_DEFINE3(get_robust_list, int, pi
49564 struct robust_list_head __user *head;
49566 +#ifndef CONFIG_GRKERNSEC_PROC_MEMMAP
49567 const struct cred *cred = current_cred(), *pcred;
49570 if (!futex_cmpxchg_enabled)
49572 @@ -2400,11 +2408,16 @@ SYSCALL_DEFINE3(get_robust_list, int, pi
49576 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49577 + if (!ptrace_may_access(p, PTRACE_MODE_READ))
49580 pcred = __task_cred(p);
49581 if (cred->euid != pcred->euid &&
49582 cred->euid != pcred->uid &&
49583 !capable(CAP_SYS_PTRACE))
49586 head = p->robust_list;
49589 @@ -2648,6 +2661,7 @@ static int __init futex_init(void)
49593 + mm_segment_t oldfs;
49596 * This will fail and we want it. Some arch implementations do
49597 @@ -2659,7 +2673,10 @@ static int __init futex_init(void)
49598 * implementation, the non-functional ones will return
49601 + oldfs = get_fs();
49603 curval = cmpxchg_futex_value_locked(NULL, 0, 0);
49605 if (curval == -EFAULT)
49606 futex_cmpxchg_enabled = 1;
49608 diff -urNp linux-2.6.37/kernel/futex_compat.c linux-2.6.37/kernel/futex_compat.c
49609 --- linux-2.6.37/kernel/futex_compat.c 2011-01-04 19:50:19.000000000 -0500
49610 +++ linux-2.6.37/kernel/futex_compat.c 2011-01-17 02:41:02.000000000 -0500
49612 #include <linux/compat.h>
49613 #include <linux/nsproxy.h>
49614 #include <linux/futex.h>
49615 +#include <linux/ptrace.h>
49617 #include <asm/uaccess.h>
49619 @@ -136,7 +137,10 @@ compat_sys_get_robust_list(int pid, comp
49621 struct compat_robust_list_head __user *head;
49623 - const struct cred *cred = current_cred(), *pcred;
49624 +#ifndef CONFIG_GRKERNSEC_PROC_MEMMAP
49625 + const struct cred *cred = current_cred();
49626 + const struct cred *pcred;
49629 if (!futex_cmpxchg_enabled)
49631 @@ -152,11 +156,16 @@ compat_sys_get_robust_list(int pid, comp
49635 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49636 + if (!ptrace_may_access(p, PTRACE_MODE_READ))
49639 pcred = __task_cred(p);
49640 if (cred->euid != pcred->euid &&
49641 cred->euid != pcred->uid &&
49642 !capable(CAP_SYS_PTRACE))
49645 head = p->compat_robust_list;
49648 diff -urNp linux-2.6.37/kernel/gcov/base.c linux-2.6.37/kernel/gcov/base.c
49649 --- linux-2.6.37/kernel/gcov/base.c 2011-01-04 19:50:19.000000000 -0500
49650 +++ linux-2.6.37/kernel/gcov/base.c 2011-01-17 02:41:02.000000000 -0500
49651 @@ -102,11 +102,6 @@ void gcov_enable_events(void)
49654 #ifdef CONFIG_MODULES
49655 -static inline int within(void *addr, void *start, unsigned long size)
49657 - return ((addr >= start) && (addr < start + size));
49660 /* Update list and generate events when modules are unloaded. */
49661 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
49663 @@ -121,7 +116,7 @@ static int gcov_module_notifier(struct n
49665 /* Remove entries located in module from linked list. */
49666 for (info = gcov_info_head; info; info = info->next) {
49667 - if (within(info, mod->module_core, mod->core_size)) {
49668 + if (within_module_core_rw((unsigned long)info, mod)) {
49670 prev->next = info->next;
49672 diff -urNp linux-2.6.37/kernel/hrtimer.c linux-2.6.37/kernel/hrtimer.c
49673 --- linux-2.6.37/kernel/hrtimer.c 2011-01-04 19:50:19.000000000 -0500
49674 +++ linux-2.6.37/kernel/hrtimer.c 2011-01-17 02:41:02.000000000 -0500
49675 @@ -1401,7 +1401,7 @@ void hrtimer_peek_ahead_timers(void)
49676 local_irq_restore(flags);
49679 -static void run_hrtimer_softirq(struct softirq_action *h)
49680 +static void run_hrtimer_softirq(void)
49682 hrtimer_peek_ahead_timers();
49684 diff -urNp linux-2.6.37/kernel/jump_label.c linux-2.6.37/kernel/jump_label.c
49685 --- linux-2.6.37/kernel/jump_label.c 2011-01-04 19:50:19.000000000 -0500
49686 +++ linux-2.6.37/kernel/jump_label.c 2011-01-17 02:41:02.000000000 -0500
49687 @@ -49,6 +49,17 @@ void jump_label_unlock(void)
49688 mutex_unlock(&jump_label_mutex);
49691 +static void jump_label_swap(void *a, void *b, int size)
49693 + struct jump_entry t;
49695 + t = *(struct jump_entry *)a;
49696 + pax_open_kernel();
49697 + *(struct jump_entry *)a = *(struct jump_entry *)b;
49698 + *(struct jump_entry *)b = t;
49699 + pax_close_kernel();
49702 static int jump_label_cmp(const void *a, const void *b)
49704 const struct jump_entry *jea = a;
49705 @@ -70,7 +81,7 @@ sort_jump_label_entries(struct jump_entr
49707 size = (((unsigned long)stop - (unsigned long)start)
49708 / sizeof(struct jump_entry));
49709 - sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
49710 + sort(start, size, sizeof(struct jump_entry), jump_label_cmp, jump_label_swap);
49713 static struct jump_label_entry *get_jump_label_entry(jump_label_t key)
49714 @@ -407,8 +418,11 @@ static void remove_jump_label_module_ini
49715 count = e_module->nr_entries;
49716 iter = e_module->table;
49718 - if (within_module_init(iter->code, mod))
49719 + if (within_module_init(iter->code, mod)) {
49720 + pax_open_kernel();
49722 + pax_close_kernel();
49727 diff -urNp linux-2.6.37/kernel/kallsyms.c linux-2.6.37/kernel/kallsyms.c
49728 --- linux-2.6.37/kernel/kallsyms.c 2011-01-04 19:50:19.000000000 -0500
49729 +++ linux-2.6.37/kernel/kallsyms.c 2011-01-17 02:41:02.000000000 -0500
49731 * Changed the compression method from stem compression to "table lookup"
49732 * compression (see scripts/kallsyms.c for a more complete description)
49734 +#ifdef CONFIG_GRKERNSEC_HIDESYM
49735 +#define __INCLUDED_BY_HIDESYM 1
49737 #include <linux/kallsyms.h>
49738 #include <linux/module.h>
49739 #include <linux/init.h>
49740 @@ -53,12 +56,33 @@ extern const unsigned long kallsyms_mark
49742 static inline int is_kernel_inittext(unsigned long addr)
49744 + if (system_state != SYSTEM_BOOTING)
49747 if (addr >= (unsigned long)_sinittext
49748 && addr <= (unsigned long)_einittext)
49753 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
49754 +#ifdef CONFIG_MODULES
49755 +static inline int is_module_text(unsigned long addr)
49757 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
49760 + addr = ktla_ktva(addr);
49761 + return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
49764 +static inline int is_module_text(unsigned long addr)
49771 static inline int is_kernel_text(unsigned long addr)
49773 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
49774 @@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigne
49776 static inline int is_kernel(unsigned long addr)
49779 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
49780 + if (is_kernel_text(addr) || is_kernel_inittext(addr))
49783 + if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
49785 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
49789 return in_gate_area_no_task(addr);
49792 static int is_ksym_addr(unsigned long addr)
49795 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
49796 + if (is_module_text(addr))
49801 return is_kernel(addr);
49803 @@ -416,7 +455,6 @@ static unsigned long get_ksymbol_core(st
49805 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
49807 - iter->name[0] = '\0';
49808 iter->nameoff = get_symbol_offset(new_pos);
49809 iter->pos = new_pos;
49811 @@ -464,6 +502,11 @@ static int s_show(struct seq_file *m, vo
49813 struct kallsym_iter *iter = m->private;
49815 +#ifdef CONFIG_GRKERNSEC_HIDESYM
49816 + if (current_uid())
49820 /* Some debugging symbols have no name. Ignore them. */
49821 if (!iter->name[0])
49823 @@ -504,7 +547,7 @@ static int kallsyms_open(struct inode *i
49824 struct kallsym_iter *iter;
49827 - iter = kmalloc(sizeof(*iter), GFP_KERNEL);
49828 + iter = kzalloc(sizeof(*iter), GFP_KERNEL);
49831 reset_iter(iter, 0);
49832 diff -urNp linux-2.6.37/kernel/kmod.c linux-2.6.37/kernel/kmod.c
49833 --- linux-2.6.37/kernel/kmod.c 2011-01-04 19:50:19.000000000 -0500
49834 +++ linux-2.6.37/kernel/kmod.c 2011-01-17 02:41:02.000000000 -0500
49835 @@ -90,6 +90,18 @@ int __request_module(bool wait, const ch
49839 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
49840 + /* we could do a tighter check here, but some distros
49841 + are taking it upon themselves to remove CAP_SYS_MODULE
49842 + from even root-running apps which cause modules to be
49845 + if (current_uid()) {
49846 + gr_log_nonroot_mod_load(module_name);
49851 /* If modprobe needs a service that is in a module, we get a recursive
49852 * loop. Limit the number of running kmod threads to max_threads/2 or
49853 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
49854 diff -urNp linux-2.6.37/kernel/kprobes.c linux-2.6.37/kernel/kprobes.c
49855 --- linux-2.6.37/kernel/kprobes.c 2011-01-04 19:50:19.000000000 -0500
49856 +++ linux-2.6.37/kernel/kprobes.c 2011-01-17 02:41:02.000000000 -0500
49857 @@ -185,7 +185,7 @@ static kprobe_opcode_t __kprobes *__get_
49858 * kernel image and loaded module images reside. This is required
49859 * so x86_64 can correctly handle the %rip-relative fixups.
49861 - kip->insns = module_alloc(PAGE_SIZE);
49862 + kip->insns = module_alloc_exec(PAGE_SIZE);
49866 @@ -225,7 +225,7 @@ static int __kprobes collect_one_slot(st
49868 if (!list_is_singular(&kip->list)) {
49869 list_del(&kip->list);
49870 - module_free(NULL, kip->insns);
49871 + module_free_exec(NULL, kip->insns);
49875 @@ -1724,7 +1724,7 @@ static int __init init_kprobes(void)
49878 unsigned long offset = 0, size = 0;
49879 - char *modname, namebuf[128];
49880 + char *modname, namebuf[KSYM_NAME_LEN];
49881 const char *symbol_name;
49883 struct kprobe_blackpoint *kb;
49884 @@ -1850,7 +1850,7 @@ static int __kprobes show_kprobe_addr(st
49885 const char *sym = NULL;
49886 unsigned int i = *(loff_t *) v;
49887 unsigned long offset = 0;
49888 - char *modname, namebuf[128];
49889 + char *modname, namebuf[KSYM_NAME_LEN];
49891 head = &kprobe_table[i];
49893 diff -urNp linux-2.6.37/kernel/lockdep.c linux-2.6.37/kernel/lockdep.c
49894 --- linux-2.6.37/kernel/lockdep.c 2011-01-04 19:50:19.000000000 -0500
49895 +++ linux-2.6.37/kernel/lockdep.c 2011-01-17 02:41:02.000000000 -0500
49896 @@ -571,6 +571,10 @@ static int static_obj(void *obj)
49897 end = (unsigned long) &_end,
49898 addr = (unsigned long) obj;
49900 +#ifdef CONFIG_PAX_KERNEXEC
49901 + start = ktla_ktva(start);
49907 @@ -706,6 +710,7 @@ register_lock_class(struct lockdep_map *
49908 if (!static_obj(lock->key)) {
49910 printk("INFO: trying to register non-static key.\n");
49911 + printk("lock:%pS key:%pS.\n", lock, lock->key);
49912 printk("the code is fine but needs lockdep annotation.\n");
49913 printk("turning off the locking correctness validator.\n");
49915 @@ -2768,7 +2773,7 @@ static int __lock_acquire(struct lockdep
49919 - atomic_inc((atomic_t *)&class->ops);
49920 + atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
49921 if (very_verbose(class)) {
49922 printk("\nacquire class [%p] %s", class->key, class->name);
49923 if (class->name_version > 1)
49924 diff -urNp linux-2.6.37/kernel/lockdep_proc.c linux-2.6.37/kernel/lockdep_proc.c
49925 --- linux-2.6.37/kernel/lockdep_proc.c 2011-01-04 19:50:19.000000000 -0500
49926 +++ linux-2.6.37/kernel/lockdep_proc.c 2011-01-17 02:41:02.000000000 -0500
49927 @@ -39,7 +39,7 @@ static void l_stop(struct seq_file *m, v
49929 static void print_name(struct seq_file *m, struct lock_class *class)
49932 + char str[KSYM_NAME_LEN];
49933 const char *name = class->name;
49936 diff -urNp linux-2.6.37/kernel/module.c linux-2.6.37/kernel/module.c
49937 --- linux-2.6.37/kernel/module.c 2011-01-04 19:50:19.000000000 -0500
49938 +++ linux-2.6.37/kernel/module.c 2011-01-17 02:41:02.000000000 -0500
49939 @@ -97,7 +97,8 @@ static BLOCKING_NOTIFIER_HEAD(module_not
49941 /* Bounds of module allocation, for speeding __module_address.
49942 * Protected by module_mutex. */
49943 -static unsigned long module_addr_min = -1UL, module_addr_max = 0;
49944 +static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
49945 +static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
49947 int register_module_notifier(struct notifier_block * nb)
49949 @@ -261,7 +262,7 @@ bool each_symbol(bool (*fn)(const struct
49952 list_for_each_entry_rcu(mod, &modules, list) {
49953 - struct symsearch arr[] = {
49954 + struct symsearch modarr[] = {
49955 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
49956 NOT_GPL_ONLY, false },
49957 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
49958 @@ -283,7 +284,7 @@ bool each_symbol(bool (*fn)(const struct
49962 - if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
49963 + if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
49967 @@ -394,7 +395,7 @@ static inline void __percpu *mod_percpu(
49968 static int percpu_modalloc(struct module *mod,
49969 unsigned long size, unsigned long align)
49971 - if (align > PAGE_SIZE) {
49972 + if (align-1 >= PAGE_SIZE) {
49973 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
49974 mod->name, align, PAGE_SIZE);
49976 @@ -1566,15 +1567,18 @@ static void free_module(struct module *m
49977 destroy_params(mod->kp, mod->num_kp);
49979 /* This may be NULL, but that's OK */
49980 - module_free(mod, mod->module_init);
49981 + module_free(mod, mod->module_init_rw);
49982 + module_free_exec(mod, mod->module_init_rx);
49984 percpu_modfree(mod);
49986 /* Free lock-classes: */
49987 - lockdep_free_key_range(mod->module_core, mod->core_size);
49988 + lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
49989 + lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
49991 /* Finally, free the core (containing the module structure) */
49992 - module_free(mod, mod->module_core);
49993 + module_free_exec(mod, mod->module_core_rx);
49994 + module_free(mod, mod->module_core_rw);
49997 update_protections(current->mm);
49998 @@ -1667,7 +1671,9 @@ static int simplify_symbols(struct modul
49999 ksym = resolve_symbol_wait(mod, info, name);
50000 /* Ok if resolved. */
50001 if (ksym && !IS_ERR(ksym)) {
50002 + pax_open_kernel();
50003 sym[i].st_value = ksym->value;
50004 + pax_close_kernel();
50008 @@ -1686,7 +1692,9 @@ static int simplify_symbols(struct modul
50009 secbase = (unsigned long)mod_percpu(mod);
50011 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
50012 + pax_open_kernel();
50013 sym[i].st_value += secbase;
50014 + pax_close_kernel();
50018 @@ -1774,11 +1782,12 @@ static void layout_sections(struct modul
50019 || s->sh_entsize != ~0UL
50020 || strstarts(sname, ".init"))
50022 - s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
50023 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
50024 + s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
50026 + s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
50027 DEBUGP("\t%s\n", name);
50030 - mod->core_text_size = mod->core_size;
50033 DEBUGP("Init section allocation order:\n");
50034 @@ -1792,12 +1801,13 @@ static void layout_sections(struct modul
50035 || s->sh_entsize != ~0UL
50036 || !strstarts(sname, ".init"))
50038 - s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
50039 - | INIT_OFFSET_MASK);
50040 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
50041 + s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
50043 + s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
50044 + s->sh_entsize |= INIT_OFFSET_MASK;
50045 DEBUGP("\t%s\n", sname);
50048 - mod->init_text_size = mod->init_size;
50052 @@ -1965,7 +1975,7 @@ static void layout_symtab(struct module
50054 /* Put symbol section at end of init part of module. */
50055 symsect->sh_flags |= SHF_ALLOC;
50056 - symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
50057 + symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
50058 info->index.sym) | INIT_OFFSET_MASK;
50059 DEBUGP("\t%s\n", info->secstrings + symsect->sh_name);
50061 @@ -1982,19 +1992,19 @@ static void layout_symtab(struct module
50064 /* Append room for core symbols at end of core part. */
50065 - info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
50066 - mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
50067 + info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
50068 + mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
50070 /* Put string table section at end of init part of module. */
50071 strsect->sh_flags |= SHF_ALLOC;
50072 - strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
50073 + strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
50074 info->index.str) | INIT_OFFSET_MASK;
50075 DEBUGP("\t%s\n", info->secstrings + strsect->sh_name);
50077 /* Append room for core symbols' strings at end of core part. */
50078 - info->stroffs = mod->core_size;
50079 + info->stroffs = mod->core_size_rx;
50080 __set_bit(0, info->strmap);
50081 - mod->core_size += bitmap_weight(info->strmap, strsect->sh_size);
50082 + mod->core_size_rx += bitmap_weight(info->strmap, strsect->sh_size);
50085 static void add_kallsyms(struct module *mod, const struct load_info *info)
50086 @@ -2010,11 +2020,13 @@ static void add_kallsyms(struct module *
50087 /* Make sure we get permanent strtab: don't use info->strtab. */
50088 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
50090 + pax_open_kernel();
50092 /* Set types up while we still have access to sections. */
50093 for (i = 0; i < mod->num_symtab; i++)
50094 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
50096 - mod->core_symtab = dst = mod->module_core + info->symoffs;
50097 + mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
50100 for (ndst = i = 1; i < mod->num_symtab; ++i, ++src) {
50101 @@ -2027,10 +2039,12 @@ static void add_kallsyms(struct module *
50103 mod->core_num_syms = ndst;
50105 - mod->core_strtab = s = mod->module_core + info->stroffs;
50106 + mod->core_strtab = s = mod->module_core_rx + info->stroffs;
50107 for (*s = 0, i = 1; i < info->sechdrs[info->index.str].sh_size; ++i)
50108 if (test_bit(i, info->strmap))
50109 *++s = mod->strtab[i];
50111 + pax_close_kernel();
50114 static inline void layout_symtab(struct module *mod, struct load_info *info)
50115 @@ -2059,17 +2073,33 @@ static void dynamic_debug_remove(struct
50116 ddebug_remove_module(debug->modname);
50119 -static void *module_alloc_update_bounds(unsigned long size)
50120 +static void *module_alloc_update_bounds_rw(unsigned long size)
50122 void *ret = module_alloc(size);
50125 mutex_lock(&module_mutex);
50126 /* Update module bounds. */
50127 - if ((unsigned long)ret < module_addr_min)
50128 - module_addr_min = (unsigned long)ret;
50129 - if ((unsigned long)ret + size > module_addr_max)
50130 - module_addr_max = (unsigned long)ret + size;
50131 + if ((unsigned long)ret < module_addr_min_rw)
50132 + module_addr_min_rw = (unsigned long)ret;
50133 + if ((unsigned long)ret + size > module_addr_max_rw)
50134 + module_addr_max_rw = (unsigned long)ret + size;
50135 + mutex_unlock(&module_mutex);
50140 +static void *module_alloc_update_bounds_rx(unsigned long size)
50142 + void *ret = module_alloc_exec(size);
50145 + mutex_lock(&module_mutex);
50146 + /* Update module bounds. */
50147 + if ((unsigned long)ret < module_addr_min_rx)
50148 + module_addr_min_rx = (unsigned long)ret;
50149 + if ((unsigned long)ret + size > module_addr_max_rx)
50150 + module_addr_max_rx = (unsigned long)ret + size;
50151 mutex_unlock(&module_mutex);
50154 @@ -2362,7 +2392,7 @@ static int move_module(struct module *mo
50157 /* Do the allocs. */
50158 - ptr = module_alloc_update_bounds(mod->core_size);
50159 + ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
50161 * The pointer to this block is stored in the module structure
50162 * which is inside the block. Just mark it as not being a
50163 @@ -2372,23 +2402,50 @@ static int move_module(struct module *mo
50167 - memset(ptr, 0, mod->core_size);
50168 - mod->module_core = ptr;
50169 + memset(ptr, 0, mod->core_size_rw);
50170 + mod->module_core_rw = ptr;
50172 - ptr = module_alloc_update_bounds(mod->init_size);
50173 + ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
50175 * The pointer to this block is stored in the module structure
50176 * which is inside the block. This block doesn't need to be
50177 * scanned as it contains data and code that will be freed
50178 * after the module is initialized.
50180 - kmemleak_ignore(ptr);
50181 - if (!ptr && mod->init_size) {
50182 - module_free(mod, mod->module_core);
50183 + kmemleak_not_leak(ptr);
50184 + if (!ptr && mod->init_size_rw) {
50185 + module_free(mod, mod->module_core_rw);
50188 + memset(ptr, 0, mod->init_size_rw);
50189 + mod->module_init_rw = ptr;
50191 + ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
50192 + kmemleak_not_leak(ptr);
50194 + module_free(mod, mod->module_init_rw);
50195 + module_free(mod, mod->module_core_rw);
50198 - memset(ptr, 0, mod->init_size);
50199 - mod->module_init = ptr;
50201 + pax_open_kernel();
50202 + memset(ptr, 0, mod->core_size_rx);
50203 + pax_close_kernel();
50204 + mod->module_core_rx = ptr;
50206 + ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
50207 + kmemleak_not_leak(ptr);
50208 + if (!ptr && mod->init_size_rx) {
50209 + module_free_exec(mod, mod->module_core_rx);
50210 + module_free(mod, mod->module_init_rw);
50211 + module_free(mod, mod->module_core_rw);
50215 + pax_open_kernel();
50216 + memset(ptr, 0, mod->init_size_rx);
50217 + pax_close_kernel();
50218 + mod->module_init_rx = ptr;
50220 /* Transfer each section which specifies SHF_ALLOC */
50221 DEBUGP("final section addresses:\n");
50222 @@ -2399,16 +2456,45 @@ static int move_module(struct module *mo
50223 if (!(shdr->sh_flags & SHF_ALLOC))
50226 - if (shdr->sh_entsize & INIT_OFFSET_MASK)
50227 - dest = mod->module_init
50228 - + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
50230 - dest = mod->module_core + shdr->sh_entsize;
50231 + if (shdr->sh_entsize & INIT_OFFSET_MASK) {
50232 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
50233 + dest = mod->module_init_rw
50234 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
50236 + dest = mod->module_init_rx
50237 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
50239 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
50240 + dest = mod->module_core_rw + shdr->sh_entsize;
50242 + dest = mod->module_core_rx + shdr->sh_entsize;
50245 + if (shdr->sh_type != SHT_NOBITS) {
50247 +#ifdef CONFIG_PAX_KERNEXEC
50248 +#ifdef CONFIG_X86_64
50249 + if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
50250 + set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
50252 + if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
50253 + pax_open_kernel();
50254 + memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
50255 + pax_close_kernel();
50259 - if (shdr->sh_type != SHT_NOBITS)
50260 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
50262 /* Update sh_addr to point to copy in image. */
50263 - shdr->sh_addr = (unsigned long)dest;
50265 +#ifdef CONFIG_PAX_KERNEXEC
50266 + if (shdr->sh_flags & SHF_EXECINSTR)
50267 + shdr->sh_addr = ktva_ktla((unsigned long)dest);
50271 + shdr->sh_addr = (unsigned long)dest;
50272 DEBUGP("\t0x%lx %s\n",
50273 shdr->sh_addr, info->secstrings + shdr->sh_name);
50275 @@ -2459,12 +2545,12 @@ static void flush_module_icache(const st
50276 * Do it before processing of module parameters, so the module
50277 * can provide parameter accessor functions of its own.
50279 - if (mod->module_init)
50280 - flush_icache_range((unsigned long)mod->module_init,
50281 - (unsigned long)mod->module_init
50282 - + mod->init_size);
50283 - flush_icache_range((unsigned long)mod->module_core,
50284 - (unsigned long)mod->module_core + mod->core_size);
50285 + if (mod->module_init_rx)
50286 + flush_icache_range((unsigned long)mod->module_init_rx,
50287 + (unsigned long)mod->module_init_rx
50288 + + mod->init_size_rx);
50289 + flush_icache_range((unsigned long)mod->module_core_rx,
50290 + (unsigned long)mod->module_core_rx + mod->core_size_rx);
50294 @@ -2536,8 +2622,10 @@ static void module_deallocate(struct mod
50296 kfree(info->strmap);
50297 percpu_modfree(mod);
50298 - module_free(mod, mod->module_init);
50299 - module_free(mod, mod->module_core);
50300 + module_free_exec(mod, mod->module_init_rx);
50301 + module_free_exec(mod, mod->module_core_rx);
50302 + module_free(mod, mod->module_init_rw);
50303 + module_free(mod, mod->module_core_rw);
50306 static int post_relocation(struct module *mod, const struct load_info *info)
50307 @@ -2765,10 +2853,12 @@ SYSCALL_DEFINE3(init_module, void __user
50308 mod->symtab = mod->core_symtab;
50309 mod->strtab = mod->core_strtab;
50311 - module_free(mod, mod->module_init);
50312 - mod->module_init = NULL;
50313 - mod->init_size = 0;
50314 - mod->init_text_size = 0;
50315 + module_free(mod, mod->module_init_rw);
50316 + module_free_exec(mod, mod->module_init_rx);
50317 + mod->module_init_rw = NULL;
50318 + mod->module_init_rx = NULL;
50319 + mod->init_size_rw = 0;
50320 + mod->init_size_rx = 0;
50321 mutex_unlock(&module_mutex);
50324 @@ -2799,10 +2889,16 @@ static const char *get_ksymbol(struct mo
50325 unsigned long nextval;
50327 /* At worse, next value is at end of module */
50328 - if (within_module_init(addr, mod))
50329 - nextval = (unsigned long)mod->module_init+mod->init_text_size;
50330 + if (within_module_init_rx(addr, mod))
50331 + nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
50332 + else if (within_module_init_rw(addr, mod))
50333 + nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
50334 + else if (within_module_core_rx(addr, mod))
50335 + nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
50336 + else if (within_module_core_rw(addr, mod))
50337 + nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
50339 - nextval = (unsigned long)mod->module_core+mod->core_text_size;
50342 /* Scan for closest preceeding symbol, and next symbol. (ELF
50343 starts real symbols at 1). */
50344 @@ -3048,7 +3144,7 @@ static int m_show(struct seq_file *m, vo
50347 seq_printf(m, "%s %u",
50348 - mod->name, mod->init_size + mod->core_size);
50349 + mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
50350 print_unload_info(m, mod);
50352 /* Informative for users. */
50353 @@ -3057,7 +3153,7 @@ static int m_show(struct seq_file *m, vo
50354 mod->state == MODULE_STATE_COMING ? "Loading":
50356 /* Used by oprofile and other similar tools. */
50357 - seq_printf(m, " 0x%p", mod->module_core);
50358 + seq_printf(m, " 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
50362 @@ -3093,7 +3189,17 @@ static const struct file_operations proc
50364 static int __init proc_modules_init(void)
50366 +#ifndef CONFIG_GRKERNSEC_HIDESYM
50367 +#ifdef CONFIG_GRKERNSEC_PROC_USER
50368 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
50369 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
50370 + proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
50372 proc_create("modules", 0, NULL, &proc_modules_operations);
50375 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
50379 module_init(proc_modules_init);
50380 @@ -3152,12 +3258,12 @@ struct module *__module_address(unsigned
50382 struct module *mod;
50384 - if (addr < module_addr_min || addr > module_addr_max)
50385 + if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
50386 + (addr < module_addr_min_rw || addr > module_addr_max_rw))
50389 list_for_each_entry_rcu(mod, &modules, list)
50390 - if (within_module_core(addr, mod)
50391 - || within_module_init(addr, mod))
50392 + if (within_module_init(addr, mod) || within_module_core(addr, mod))
50396 @@ -3191,11 +3297,20 @@ bool is_module_text_address(unsigned lon
50398 struct module *__module_text_address(unsigned long addr)
50400 - struct module *mod = __module_address(addr);
50401 + struct module *mod;
50403 +#ifdef CONFIG_X86_32
50404 + addr = ktla_ktva(addr);
50407 + if (addr < module_addr_min_rx || addr > module_addr_max_rx)
50410 + mod = __module_address(addr);
50413 /* Make sure it's within the text section. */
50414 - if (!within(addr, mod->module_init, mod->init_text_size)
50415 - && !within(addr, mod->module_core, mod->core_text_size))
50416 + if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
50420 diff -urNp linux-2.6.37/kernel/panic.c linux-2.6.37/kernel/panic.c
50421 --- linux-2.6.37/kernel/panic.c 2011-01-04 19:50:19.000000000 -0500
50422 +++ linux-2.6.37/kernel/panic.c 2011-01-17 02:41:02.000000000 -0500
50423 @@ -368,7 +368,7 @@ static void warn_slowpath_common(const c
50426 printk(KERN_WARNING "------------[ cut here ]------------\n");
50427 - printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
50428 + printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
50429 board = dmi_get_system_info(DMI_PRODUCT_NAME);
50431 printk(KERN_WARNING "Hardware name: %s\n", board);
50432 @@ -423,7 +423,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
50434 void __stack_chk_fail(void)
50436 - panic("stack-protector: Kernel stack is corrupted in: %p\n",
50438 + panic("stack-protector: Kernel stack is corrupted in: %pA\n",
50439 __builtin_return_address(0));
50441 EXPORT_SYMBOL(__stack_chk_fail);
50442 diff -urNp linux-2.6.37/kernel/pid.c linux-2.6.37/kernel/pid.c
50443 --- linux-2.6.37/kernel/pid.c 2011-01-04 19:50:19.000000000 -0500
50444 +++ linux-2.6.37/kernel/pid.c 2011-01-17 02:41:02.000000000 -0500
50446 #include <linux/rculist.h>
50447 #include <linux/bootmem.h>
50448 #include <linux/hash.h>
50449 +#include <linux/security.h>
50450 #include <linux/pid_namespace.h>
50451 #include <linux/init_task.h>
50452 #include <linux/syscalls.h>
50453 @@ -45,7 +46,7 @@ struct pid init_struct_pid = INIT_STRUCT
50455 int pid_max = PID_MAX_DEFAULT;
50457 -#define RESERVED_PIDS 300
50458 +#define RESERVED_PIDS 500
50460 int pid_max_min = RESERVED_PIDS + 1;
50461 int pid_max_max = PID_MAX_LIMIT;
50462 @@ -416,8 +417,15 @@ EXPORT_SYMBOL(pid_task);
50464 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
50466 + struct task_struct *task;
50468 rcu_lockdep_assert(rcu_read_lock_held());
50469 - return pid_task(find_pid_ns(vx_rmap_pid(nr), ns), PIDTYPE_PID);
50470 + task = pid_task(find_pid_ns(vx_rmap_pid(nr), ns), PIDTYPE_PID);
50472 + if (gr_pid_is_chrooted(task))
50478 struct task_struct *find_task_by_vpid(pid_t vnr)
50479 diff -urNp linux-2.6.37/kernel/posix-cpu-timers.c linux-2.6.37/kernel/posix-cpu-timers.c
50480 --- linux-2.6.37/kernel/posix-cpu-timers.c 2011-01-04 19:50:19.000000000 -0500
50481 +++ linux-2.6.37/kernel/posix-cpu-timers.c 2011-01-17 02:41:02.000000000 -0500
50483 #include <linux/posix-timers.h>
50484 #include <linux/errno.h>
50485 #include <linux/math64.h>
50486 +#include <linux/security.h>
50487 #include <asm/uaccess.h>
50488 #include <linux/kernel_stat.h>
50489 #include <trace/events/timer.h>
50490 diff -urNp linux-2.6.37/kernel/posix-timers.c linux-2.6.37/kernel/posix-timers.c
50491 --- linux-2.6.37/kernel/posix-timers.c 2011-01-04 19:50:19.000000000 -0500
50492 +++ linux-2.6.37/kernel/posix-timers.c 2011-01-17 02:41:02.000000000 -0500
50494 #include <linux/compiler.h>
50495 #include <linux/idr.h>
50496 #include <linux/posix-timers.h>
50497 +#include <linux/grsecurity.h>
50498 #include <linux/syscalls.h>
50499 #include <linux/wait.h>
50500 #include <linux/workqueue.h>
50501 @@ -949,6 +950,13 @@ SYSCALL_DEFINE2(clock_settime, const clo
50502 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
50505 + /* only the CLOCK_REALTIME clock can be set, all other clocks
50506 + have their clock_set fptr set to a nosettime dummy function
50507 + CLOCK_REALTIME has a NULL clock_set fptr which causes it to
50508 + call common_clock_set, which calls do_sys_settimeofday, which
50512 return CLOCK_DISPATCH(which_clock, clock_set, (which_clock, &new_tp));
50515 diff -urNp linux-2.6.37/kernel/power/hibernate.c linux-2.6.37/kernel/power/hibernate.c
50516 --- linux-2.6.37/kernel/power/hibernate.c 2011-01-04 19:50:19.000000000 -0500
50517 +++ linux-2.6.37/kernel/power/hibernate.c 2011-01-17 02:41:02.000000000 -0500
50518 @@ -51,14 +51,14 @@ enum {
50520 static int hibernation_mode = HIBERNATION_SHUTDOWN;
50522 -static struct platform_hibernation_ops *hibernation_ops;
50523 +static const struct platform_hibernation_ops *hibernation_ops;
50526 * hibernation_set_ops - set the global hibernate operations
50527 * @ops: the hibernation operations to use in subsequent hibernation transitions
50530 -void hibernation_set_ops(struct platform_hibernation_ops *ops)
50531 +void hibernation_set_ops(const struct platform_hibernation_ops *ops)
50533 if (ops && !(ops->begin && ops->end && ops->pre_snapshot
50534 && ops->prepare && ops->finish && ops->enter && ops->pre_restore
50535 diff -urNp linux-2.6.37/kernel/power/poweroff.c linux-2.6.37/kernel/power/poweroff.c
50536 --- linux-2.6.37/kernel/power/poweroff.c 2011-01-04 19:50:19.000000000 -0500
50537 +++ linux-2.6.37/kernel/power/poweroff.c 2011-01-17 02:41:02.000000000 -0500
50538 @@ -37,7 +37,7 @@ static struct sysrq_key_op sysrq_powerof
50539 .enable_mask = SYSRQ_ENABLE_BOOT,
50542 -static int pm_sysrq_init(void)
50543 +static int __init pm_sysrq_init(void)
50545 register_sysrq_key('o', &sysrq_poweroff_op);
50547 diff -urNp linux-2.6.37/kernel/power/process.c linux-2.6.37/kernel/power/process.c
50548 --- linux-2.6.37/kernel/power/process.c 2011-01-04 19:50:19.000000000 -0500
50549 +++ linux-2.6.37/kernel/power/process.c 2011-01-17 02:41:02.000000000 -0500
50550 @@ -41,6 +41,7 @@ static int try_to_freeze_tasks(bool sig_
50551 u64 elapsed_csecs64;
50552 unsigned int elapsed_csecs;
50553 bool wakeup = false;
50554 + bool timedout = false;
50556 do_gettimeofday(&start);
50558 @@ -51,6 +52,8 @@ static int try_to_freeze_tasks(bool sig_
50562 + if (time_after(jiffies, end_time))
50564 read_lock(&tasklist_lock);
50565 do_each_thread(g, p) {
50566 if (frozen(p) || !freezeable(p))
50567 @@ -65,9 +68,13 @@ static int try_to_freeze_tasks(bool sig_
50568 * It is "frozen enough". If the task does wake
50569 * up, it will immediately call try_to_freeze.
50571 - if (!task_is_stopped_or_traced(p) &&
50572 - !freezer_should_skip(p))
50573 + if (!task_is_stopped_or_traced(p) && !freezer_should_skip(p)) {
50576 + printk(KERN_ERR "Task refusing to freeze:\n");
50577 + sched_show_task(p);
50580 } while_each_thread(g, p);
50581 read_unlock(&tasklist_lock);
50583 @@ -76,7 +83,7 @@ static int try_to_freeze_tasks(bool sig_
50587 - if (!todo || time_after(jiffies, end_time))
50588 + if (!todo || timedout)
50591 if (!pm_check_wakeup_events()) {
50592 diff -urNp linux-2.6.37/kernel/power/suspend.c linux-2.6.37/kernel/power/suspend.c
50593 --- linux-2.6.37/kernel/power/suspend.c 2011-01-04 19:50:19.000000000 -0500
50594 +++ linux-2.6.37/kernel/power/suspend.c 2011-01-17 02:41:02.000000000 -0500
50595 @@ -30,13 +30,13 @@ const char *const pm_states[PM_SUSPEND_M
50596 [PM_SUSPEND_MEM] = "mem",
50599 -static struct platform_suspend_ops *suspend_ops;
50600 +static const struct platform_suspend_ops *suspend_ops;
50603 * suspend_set_ops - Set the global suspend method table.
50604 * @ops: Pointer to ops structure.
50606 -void suspend_set_ops(struct platform_suspend_ops *ops)
50607 +void suspend_set_ops(const struct platform_suspend_ops *ops)
50609 mutex_lock(&pm_mutex);
50611 diff -urNp linux-2.6.37/kernel/printk.c linux-2.6.37/kernel/printk.c
50612 --- linux-2.6.37/kernel/printk.c 2011-01-04 19:50:19.000000000 -0500
50613 +++ linux-2.6.37/kernel/printk.c 2011-01-17 02:41:02.000000000 -0500
50614 @@ -274,6 +274,11 @@ int do_syslog(int type, char __user *buf
50618 +#ifdef CONFIG_GRKERNSEC_DMESG
50619 + if (grsec_enable_dmesg && !capable(CAP_SYS_ADMIN))
50624 * If this is from /proc/kmsg we only do the capabilities checks
50626 diff -urNp linux-2.6.37/kernel/ptrace.c linux-2.6.37/kernel/ptrace.c
50627 --- linux-2.6.37/kernel/ptrace.c 2011-01-04 19:50:19.000000000 -0500
50628 +++ linux-2.6.37/kernel/ptrace.c 2011-01-17 02:41:02.000000000 -0500
50629 @@ -140,7 +140,7 @@ int __ptrace_may_access(struct task_stru
50630 cred->gid != tcred->egid ||
50631 cred->gid != tcred->sgid ||
50632 cred->gid != tcred->gid) &&
50633 - !capable(CAP_SYS_PTRACE)) {
50634 + !capable_nolog(CAP_SYS_PTRACE)) {
50638 @@ -148,7 +148,7 @@ int __ptrace_may_access(struct task_stru
50641 dumpable = get_dumpable(task->mm);
50642 - if (!dumpable && !capable(CAP_SYS_PTRACE))
50643 + if (!dumpable && !capable_nolog(CAP_SYS_PTRACE))
50646 return security_ptrace_access_check(task, mode);
50647 @@ -198,7 +198,7 @@ int ptrace_attach(struct task_struct *ta
50648 goto unlock_tasklist;
50650 task->ptrace = PT_PTRACED;
50651 - if (capable(CAP_SYS_PTRACE))
50652 + if (capable_nolog(CAP_SYS_PTRACE))
50653 task->ptrace |= PT_PTRACE_CAP;
50655 __ptrace_link(task, current);
50656 @@ -369,7 +369,7 @@ int ptrace_readdata(struct task_struct *
50660 - if (copy_to_user(dst, buf, retval))
50661 + if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
50665 @@ -565,7 +565,7 @@ int ptrace_request(struct task_struct *c
50669 - void __user *datavp = (void __user *) data;
50670 + void __user *datavp = (__force void __user *) data;
50671 unsigned long __user *datalp = datavp;
50674 @@ -713,14 +713,21 @@ SYSCALL_DEFINE4(ptrace, long, request, l
50675 if (!vx_check(vx_task_xid(child), VS_WATCH_P | VS_IDENT))
50676 goto out_put_task_struct;
50678 + if (gr_handle_ptrace(child, request)) {
50680 + goto out_put_task_struct;
50683 if (request == PTRACE_ATTACH) {
50684 ret = ptrace_attach(child);
50686 * Some architectures need to do book-keeping after
50691 arch_ptrace_attach(child);
50692 + gr_audit_ptrace(child);
50694 goto out_put_task_struct;
50697 @@ -855,14 +862,21 @@ asmlinkage long compat_sys_ptrace(compat
50701 + if (gr_handle_ptrace(child, request)) {
50703 + goto out_put_task_struct;
50706 if (request == PTRACE_ATTACH) {
50707 ret = ptrace_attach(child);
50709 * Some architectures need to do book-keeping after
50714 arch_ptrace_attach(child);
50715 + gr_audit_ptrace(child);
50717 goto out_put_task_struct;
50720 diff -urNp linux-2.6.37/kernel/rcutree.c linux-2.6.37/kernel/rcutree.c
50721 --- linux-2.6.37/kernel/rcutree.c 2011-01-04 19:50:19.000000000 -0500
50722 +++ linux-2.6.37/kernel/rcutree.c 2011-01-17 02:41:02.000000000 -0500
50723 @@ -1394,7 +1394,7 @@ __rcu_process_callbacks(struct rcu_state
50725 * Do softirq processing for the current CPU.
50727 -static void rcu_process_callbacks(struct softirq_action *unused)
50728 +static void rcu_process_callbacks(void)
50731 * Memory references from any prior RCU read-side critical sections
50732 diff -urNp linux-2.6.37/kernel/rcutree_plugin.h linux-2.6.37/kernel/rcutree_plugin.h
50733 --- linux-2.6.37/kernel/rcutree_plugin.h 2011-01-04 19:50:19.000000000 -0500
50734 +++ linux-2.6.37/kernel/rcutree_plugin.h 2011-01-17 02:41:02.000000000 -0500
50735 @@ -729,7 +729,7 @@ void synchronize_rcu_expedited(void)
50737 /* Clean up and exit. */
50738 smp_mb(); /* ensure expedited GP seen before counter increment. */
50739 - ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
50740 + ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
50742 mutex_unlock(&sync_rcu_preempt_exp_mutex);
50744 diff -urNp linux-2.6.37/kernel/resource.c linux-2.6.37/kernel/resource.c
50745 --- linux-2.6.37/kernel/resource.c 2011-01-04 19:50:19.000000000 -0500
50746 +++ linux-2.6.37/kernel/resource.c 2011-01-17 02:41:02.000000000 -0500
50747 @@ -133,8 +133,18 @@ static const struct file_operations proc
50749 static int __init ioresources_init(void)
50751 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
50752 +#ifdef CONFIG_GRKERNSEC_PROC_USER
50753 + proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
50754 + proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
50755 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
50756 + proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
50757 + proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
50760 proc_create("ioports", 0, NULL, &proc_ioports_operations);
50761 proc_create("iomem", 0, NULL, &proc_iomem_operations);
50765 __initcall(ioresources_init);
50766 diff -urNp linux-2.6.37/kernel/rtmutex.c linux-2.6.37/kernel/rtmutex.c
50767 --- linux-2.6.37/kernel/rtmutex.c 2011-01-04 19:50:19.000000000 -0500
50768 +++ linux-2.6.37/kernel/rtmutex.c 2011-01-17 02:41:02.000000000 -0500
50769 @@ -511,7 +511,7 @@ static void wakeup_next_waiter(struct rt
50771 raw_spin_lock_irqsave(&pendowner->pi_lock, flags);
50773 - WARN_ON(!pendowner->pi_blocked_on);
50774 + BUG_ON(!pendowner->pi_blocked_on);
50775 WARN_ON(pendowner->pi_blocked_on != waiter);
50776 WARN_ON(pendowner->pi_blocked_on->lock != lock);
50778 diff -urNp linux-2.6.37/kernel/sched.c linux-2.6.37/kernel/sched.c
50779 --- linux-2.6.37/kernel/sched.c 2011-01-04 19:50:19.000000000 -0500
50780 +++ linux-2.6.37/kernel/sched.c 2011-01-17 02:41:02.000000000 -0500
50781 @@ -4770,6 +4770,8 @@ int can_nice(const struct task_struct *p
50782 /* convert nice value [19,-20] to rlimit style value [1,40] */
50783 int nice_rlim = 20 - nice;
50785 + gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
50787 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
50788 capable(CAP_SYS_NICE));
50790 @@ -4803,7 +4805,8 @@ SYSCALL_DEFINE1(nice, int, increment)
50794 - if (increment < 0 && !can_nice(current, nice))
50795 + if (increment < 0 && (!can_nice(current, nice) ||
50796 + gr_handle_chroot_nice()))
50797 return vx_flags(VXF_IGNEG_NICE, 0) ? 0 : -EPERM;
50799 retval = security_task_setnice(current, nice);
50800 @@ -4946,6 +4949,7 @@ recheck:
50801 unsigned long rlim_rtprio =
50802 task_rlimit(p, RLIMIT_RTPRIO);
50804 + gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
50805 /* can't set/change the rt policy */
50806 if (policy != p->policy && !rlim_rtprio)
50808 @@ -7155,7 +7159,7 @@ static void init_sched_groups_power(int
50812 - WARN_ON(!sd || !sd->groups);
50813 + BUG_ON(!sd || !sd->groups);
50815 if (cpu != group_first_cpu(sd->groups))
50817 diff -urNp linux-2.6.37/kernel/sched_fair.c linux-2.6.37/kernel/sched_fair.c
50818 --- linux-2.6.37/kernel/sched_fair.c 2011-01-04 19:50:19.000000000 -0500
50819 +++ linux-2.6.37/kernel/sched_fair.c 2011-01-17 02:41:02.000000000 -0500
50820 @@ -3724,7 +3724,7 @@ static void nohz_idle_balance(int this_c
50821 * run_rebalance_domains is triggered when needed from the scheduler tick.
50822 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
50824 -static void run_rebalance_domains(struct softirq_action *h)
50825 +static void run_rebalance_domains(void)
50827 int this_cpu = smp_processor_id();
50828 struct rq *this_rq = cpu_rq(this_cpu);
50829 diff -urNp linux-2.6.37/kernel/signal.c linux-2.6.37/kernel/signal.c
50830 --- linux-2.6.37/kernel/signal.c 2011-01-04 19:50:19.000000000 -0500
50831 +++ linux-2.6.37/kernel/signal.c 2011-01-17 02:41:02.000000000 -0500
50832 @@ -45,12 +45,12 @@ static struct kmem_cache *sigqueue_cache
50834 int print_fatal_signals __read_mostly;
50836 -static void __user *sig_handler(struct task_struct *t, int sig)
50837 +static __sighandler_t sig_handler(struct task_struct *t, int sig)
50839 return t->sighand->action[sig - 1].sa.sa_handler;
50842 -static int sig_handler_ignored(void __user *handler, int sig)
50843 +static int sig_handler_ignored(__sighandler_t handler, int sig)
50845 /* Is it explicitly or implicitly ignored? */
50846 return handler == SIG_IGN ||
50847 @@ -60,7 +60,7 @@ static int sig_handler_ignored(void __us
50848 static int sig_task_ignored(struct task_struct *t, int sig,
50849 int from_ancestor_ns)
50851 - void __user *handler;
50852 + __sighandler_t handler;
50854 handler = sig_handler(t, sig);
50856 @@ -243,6 +243,9 @@ __sigqueue_alloc(int sig, struct task_st
50857 atomic_inc(&user->sigpending);
50860 + if (!override_rlimit)
50861 + gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
50863 if (override_rlimit ||
50864 atomic_read(&user->sigpending) <=
50865 task_rlimit(t, RLIMIT_SIGPENDING)) {
50866 @@ -367,7 +370,7 @@ flush_signal_handlers(struct task_struct
50868 int unhandled_signal(struct task_struct *tsk, int sig)
50870 - void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
50871 + __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
50872 if (is_global_init(tsk))
50874 if (handler != SIG_IGN && handler != SIG_DFL)
50875 @@ -705,6 +708,10 @@ static int check_kill_permission(int sig
50876 sig, info, t, vx_task_xid(t), t->pid, current->xid);
50880 + if (gr_handle_signal(t, sig))
50884 return security_task_kill(t, info, sig, 0);
50886 @@ -1025,7 +1032,7 @@ __group_send_sig_info(int sig, struct si
50887 return send_signal(sig, info, p, 1);
50892 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
50894 return send_signal(sig, info, t, 0);
50895 @@ -1079,6 +1086,9 @@ force_sig_info(int sig, struct siginfo *
50896 ret = specific_send_sig_info(sig, info, t);
50897 spin_unlock_irqrestore(&t->sighand->siglock, flags);
50899 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
50900 + gr_handle_crash(t, sig);
50905 @@ -1137,8 +1146,11 @@ int group_send_sig_info(int sig, struct
50906 ret = check_kill_permission(sig, info, p);
50910 + if (!ret && sig) {
50911 ret = do_send_sig_info(sig, info, p, true);
50913 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
50918 diff -urNp linux-2.6.37/kernel/smp.c linux-2.6.37/kernel/smp.c
50919 --- linux-2.6.37/kernel/smp.c 2011-01-04 19:50:19.000000000 -0500
50920 +++ linux-2.6.37/kernel/smp.c 2011-01-17 02:41:02.000000000 -0500
50921 @@ -510,22 +510,22 @@ int smp_call_function(smp_call_func_t fu
50923 EXPORT_SYMBOL(smp_call_function);
50925 -void ipi_call_lock(void)
50926 +void ipi_call_lock(void) __acquires(call_function.lock)
50928 raw_spin_lock(&call_function.lock);
50931 -void ipi_call_unlock(void)
50932 +void ipi_call_unlock(void) __releases(call_function.lock)
50934 raw_spin_unlock(&call_function.lock);
50937 -void ipi_call_lock_irq(void)
50938 +void ipi_call_lock_irq(void) __acquires(call_function.lock)
50940 raw_spin_lock_irq(&call_function.lock);
50943 -void ipi_call_unlock_irq(void)
50944 +void ipi_call_unlock_irq(void) __releases(call_function.lock)
50946 raw_spin_unlock_irq(&call_function.lock);
50948 diff -urNp linux-2.6.37/kernel/softirq.c linux-2.6.37/kernel/softirq.c
50949 --- linux-2.6.37/kernel/softirq.c 2011-01-04 19:50:19.000000000 -0500
50950 +++ linux-2.6.37/kernel/softirq.c 2011-01-17 02:41:02.000000000 -0500
50951 @@ -56,7 +56,7 @@ static struct softirq_action softirq_vec
50953 static DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
50955 -char *softirq_to_name[NR_SOFTIRQS] = {
50956 +const char * const softirq_to_name[NR_SOFTIRQS] = {
50957 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
50958 "TASKLET", "SCHED", "HRTIMER", "RCU"
50960 @@ -206,7 +206,7 @@ EXPORT_SYMBOL(local_bh_enable_ip);
50962 asmlinkage void __do_softirq(void)
50964 - struct softirq_action *h;
50965 + const struct softirq_action *h;
50967 int max_restart = MAX_SOFTIRQ_RESTART;
50969 @@ -235,7 +235,7 @@ restart:
50970 kstat_incr_softirqs_this_cpu(vec_nr);
50972 trace_softirq_entry(vec_nr);
50975 trace_softirq_exit(vec_nr);
50976 if (unlikely(prev_count != preempt_count())) {
50977 printk(KERN_ERR "huh, entered softirq %u %s %p"
50978 @@ -365,7 +365,7 @@ void raise_softirq(unsigned int nr)
50979 local_irq_restore(flags);
50982 -void open_softirq(int nr, void (*action)(struct softirq_action *))
50983 +void open_softirq(int nr, void (*action)(void))
50985 softirq_vec[nr].action = action;
50987 @@ -421,7 +421,7 @@ void __tasklet_hi_schedule_first(struct
50989 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
50991 -static void tasklet_action(struct softirq_action *a)
50992 +static void tasklet_action(void)
50994 struct tasklet_struct *list;
50996 @@ -456,7 +456,7 @@ static void tasklet_action(struct softir
51000 -static void tasklet_hi_action(struct softirq_action *a)
51001 +static void tasklet_hi_action(void)
51003 struct tasklet_struct *list;
51005 diff -urNp linux-2.6.37/kernel/sys.c linux-2.6.37/kernel/sys.c
51006 --- linux-2.6.37/kernel/sys.c 2011-01-04 19:50:19.000000000 -0500
51007 +++ linux-2.6.37/kernel/sys.c 2011-01-17 02:41:02.000000000 -0500
51008 @@ -134,6 +134,12 @@ static int set_one_prio(struct task_stru
51013 + if (gr_handle_chroot_setpriority(p, niceval)) {
51018 no_nice = security_task_setnice(p, niceval);
51021 @@ -511,6 +517,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, g
51025 + if (gr_check_group_change(new->gid, new->egid, -1))
51028 if (rgid != (gid_t) -1 ||
51029 (egid != (gid_t) -1 && egid != old->gid))
51030 new->sgid = new->egid;
51031 @@ -540,6 +549,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
51032 old = current_cred();
51036 + if (gr_check_group_change(gid, gid, gid))
51039 if (capable(CAP_SETGID))
51040 new->gid = new->egid = new->sgid = new->fsgid = gid;
51041 else if (gid == old->gid || gid == old->sgid)
51042 @@ -620,6 +633,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, u
51046 + if (gr_check_user_change(new->uid, new->euid, -1))
51049 if (new->uid != old->uid) {
51050 retval = set_user(new);
51052 @@ -664,6 +680,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
51053 old = current_cred();
51057 + if (gr_check_crash_uid(uid))
51059 + if (gr_check_user_change(uid, uid, uid))
51062 if (capable(CAP_SETUID)) {
51063 new->suid = new->uid = uid;
51064 if (uid != old->uid) {
51065 @@ -718,6 +740,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid,
51069 + if (gr_check_user_change(ruid, euid, -1))
51072 if (ruid != (uid_t) -1) {
51074 if (ruid != old->uid) {
51075 @@ -782,6 +807,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid,
51079 + if (gr_check_group_change(rgid, egid, -1))
51082 if (rgid != (gid_t) -1)
51084 if (egid != (gid_t) -1)
51085 @@ -828,6 +856,9 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
51086 old = current_cred();
51087 old_fsuid = old->fsuid;
51089 + if (gr_check_user_change(-1, -1, uid))
51092 if (uid == old->uid || uid == old->euid ||
51093 uid == old->suid || uid == old->fsuid ||
51094 capable(CAP_SETUID)) {
51095 @@ -838,6 +869,7 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
51103 @@ -864,12 +896,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
51104 if (gid == old->gid || gid == old->egid ||
51105 gid == old->sgid || gid == old->fsgid ||
51106 capable(CAP_SETGID)) {
51107 + if (gr_check_group_change(-1, -1, gid))
51110 if (gid != old_fsgid) {
51120 @@ -1607,7 +1643,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsi
51121 error = get_dumpable(me->mm);
51123 case PR_SET_DUMPABLE:
51124 - if (arg2 < 0 || arg2 > 1) {
51129 diff -urNp linux-2.6.37/kernel/sysctl.c linux-2.6.37/kernel/sysctl.c
51130 --- linux-2.6.37/kernel/sysctl.c 2011-01-04 19:50:19.000000000 -0500
51131 +++ linux-2.6.37/kernel/sysctl.c 2011-01-17 02:41:02.000000000 -0500
51135 #if defined(CONFIG_SYSCTL)
51136 +#include <linux/grsecurity.h>
51137 +#include <linux/grinternal.h>
51139 +extern __u32 gr_handle_sysctl(const ctl_table *table, const int op);
51140 +extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
51142 +extern int gr_handle_chroot_sysctl(const int op);
51144 /* External variables not in a header file. */
51145 extern int sysctl_overcommit_memory;
51146 @@ -188,6 +195,7 @@ static int sysrq_sysctl_handler(ctl_tabl
51150 +extern struct ctl_table grsecurity_table[];
51152 static struct ctl_table root_table[];
51153 static struct ctl_table_root sysctl_table_root;
51154 @@ -217,6 +225,20 @@ extern struct ctl_table epoll_table[];
51155 int sysctl_legacy_va_layout;
51158 +#ifdef CONFIG_PAX_SOFTMODE
51159 +static ctl_table pax_table[] = {
51161 + .procname = "softmode",
51162 + .data = &pax_softmode,
51163 + .maxlen = sizeof(unsigned int),
51165 + .proc_handler = &proc_dointvec,
51172 /* The default sysctl tables: */
51174 static struct ctl_table root_table[] = {
51175 @@ -269,6 +291,22 @@ static int max_extfrag_threshold = 1000;
51178 static struct ctl_table kern_table[] = {
51179 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
51181 + .procname = "grsecurity",
51183 + .child = grsecurity_table,
51187 +#ifdef CONFIG_PAX_SOFTMODE
51189 + .procname = "pax",
51191 + .child = pax_table,
51196 .procname = "sched_child_runs_first",
51197 .data = &sysctl_sched_child_runs_first,
51198 @@ -549,7 +587,7 @@ static struct ctl_table kern_table[] = {
51199 .data = &modprobe_path,
51200 .maxlen = KMOD_PATH_LEN,
51202 - .proc_handler = proc_dostring,
51203 + .proc_handler = proc_dostring_modpriv,
51206 .procname = "modules_disabled",
51207 @@ -1180,6 +1218,13 @@ static struct ctl_table vm_table[] = {
51208 .proc_handler = proc_dointvec_minmax,
51212 + .procname = "heap_stack_gap",
51213 + .data = &sysctl_heap_stack_gap,
51214 + .maxlen = sizeof(sysctl_heap_stack_gap),
51216 + .proc_handler = proc_doulongvec_minmax,
51220 .procname = "nr_trim_pages",
51221 @@ -1695,6 +1740,16 @@ int sysctl_perm(struct ctl_table_root *r
51225 + if (table->parent != NULL && table->parent->procname != NULL &&
51226 + table->procname != NULL &&
51227 + gr_handle_sysctl_mod(table->parent->procname, table->procname, op))
51229 + if (gr_handle_chroot_sysctl(op))
51231 + error = gr_handle_sysctl(table, op);
51235 error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
51238 @@ -2102,6 +2157,16 @@ int proc_dostring(struct ctl_table *tabl
51239 buffer, lenp, ppos);
51242 +int proc_dostring_modpriv(struct ctl_table *table, int write,
51243 + void __user *buffer, size_t *lenp, loff_t *ppos)
51245 + if (write && !capable(CAP_SYS_MODULE))
51248 + return _proc_do_string(table->data, table->maxlen, write,
51249 + buffer, lenp, ppos);
51252 static size_t proc_skip_spaces(char **buf)
51255 @@ -2207,6 +2272,8 @@ static int proc_put_long(void __user **b
51259 + if (len > sizeof(tmp))
51260 + len = sizeof(tmp);
51261 if (copy_to_user(*buf, tmp, len))
51264 @@ -2512,8 +2579,11 @@ static int __do_proc_doulongvec_minmax(v
51267 val = convdiv * (*i) / convmul;
51270 err = proc_put_char(&buffer, &left, '\t');
51274 err = proc_put_long(&buffer, &left, val, false);
51277 @@ -2908,6 +2978,12 @@ int proc_dostring(struct ctl_table *tabl
51281 +int proc_dostring_modpriv(struct ctl_table *table, int write,
51282 + void __user *buffer, size_t *lenp, loff_t *ppos)
51287 int proc_dointvec(struct ctl_table *table, int write,
51288 void __user *buffer, size_t *lenp, loff_t *ppos)
51290 @@ -2964,6 +3040,7 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
51291 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
51292 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
51293 EXPORT_SYMBOL(proc_dostring);
51294 +EXPORT_SYMBOL(proc_dostring_modpriv);
51295 EXPORT_SYMBOL(proc_doulongvec_minmax);
51296 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
51297 EXPORT_SYMBOL(register_sysctl_table);
51298 diff -urNp linux-2.6.37/kernel/sysctl_check.c linux-2.6.37/kernel/sysctl_check.c
51299 --- linux-2.6.37/kernel/sysctl_check.c 2011-01-04 19:50:19.000000000 -0500
51300 +++ linux-2.6.37/kernel/sysctl_check.c 2011-01-17 02:41:02.000000000 -0500
51301 @@ -131,6 +131,7 @@ int sysctl_check_table(struct nsproxy *n
51302 set_fail(&fail, table, "Directory with extra2");
51304 if ((table->proc_handler == proc_dostring) ||
51305 + (table->proc_handler == proc_dostring_modpriv) ||
51306 (table->proc_handler == proc_dointvec) ||
51307 (table->proc_handler == proc_dointvec_minmax) ||
51308 (table->proc_handler == proc_dointvec_jiffies) ||
51309 diff -urNp linux-2.6.37/kernel/taskstats.c linux-2.6.37/kernel/taskstats.c
51310 --- linux-2.6.37/kernel/taskstats.c 2011-01-04 19:50:19.000000000 -0500
51311 +++ linux-2.6.37/kernel/taskstats.c 2011-01-17 02:41:02.000000000 -0500
51313 #include <linux/cgroup.h>
51314 #include <linux/fs.h>
51315 #include <linux/file.h>
51316 +#include <linux/grsecurity.h>
51317 #include <net/genetlink.h>
51318 #include <asm/atomic.h>
51320 +extern int gr_is_taskstats_denied(int pid);
51323 * Maximum length of a cpumask that can be specified in
51324 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
51325 @@ -550,6 +553,9 @@ err:
51327 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
51329 + if (gr_is_taskstats_denied(current->pid))
51332 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
51333 return cmd_attr_register_cpumask(info);
51334 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
51335 diff -urNp linux-2.6.37/kernel/time/tick-broadcast.c linux-2.6.37/kernel/time/tick-broadcast.c
51336 --- linux-2.6.37/kernel/time/tick-broadcast.c 2011-01-04 19:50:19.000000000 -0500
51337 +++ linux-2.6.37/kernel/time/tick-broadcast.c 2011-01-17 02:41:02.000000000 -0500
51338 @@ -116,7 +116,7 @@ int tick_device_uses_broadcast(struct cl
51339 * then clear the broadcast bit.
51341 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
51342 - int cpu = smp_processor_id();
51343 + cpu = smp_processor_id();
51345 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
51346 tick_broadcast_clear_oneshot(cpu);
51347 diff -urNp linux-2.6.37/kernel/time/timekeeping.c linux-2.6.37/kernel/time/timekeeping.c
51348 --- linux-2.6.37/kernel/time/timekeeping.c 2011-01-04 19:50:19.000000000 -0500
51349 +++ linux-2.6.37/kernel/time/timekeeping.c 2011-01-17 02:41:02.000000000 -0500
51351 #include <linux/init.h>
51352 #include <linux/mm.h>
51353 #include <linux/sched.h>
51354 +#include <linux/grsecurity.h>
51355 #include <linux/sysdev.h>
51356 #include <linux/clocksource.h>
51357 #include <linux/jiffies.h>
51358 @@ -314,6 +315,8 @@ int do_settimeofday(struct timespec *tv)
51359 if ((unsigned long)tv->tv_nsec >= NSEC_PER_SEC)
51362 + gr_log_timechange();
51364 write_seqlock_irqsave(&xtime_lock, flags);
51366 timekeeping_forward_now();
51367 diff -urNp linux-2.6.37/kernel/time/timer_list.c linux-2.6.37/kernel/time/timer_list.c
51368 --- linux-2.6.37/kernel/time/timer_list.c 2011-01-04 19:50:19.000000000 -0500
51369 +++ linux-2.6.37/kernel/time/timer_list.c 2011-01-17 02:41:02.000000000 -0500
51370 @@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base,
51372 static void print_name_offset(struct seq_file *m, void *sym)
51374 +#ifdef CONFIG_GRKERNSEC_HIDESYM
51375 + SEQ_printf(m, "<%p>", NULL);
51377 char symname[KSYM_NAME_LEN];
51379 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
51380 SEQ_printf(m, "<%p>", sym);
51382 SEQ_printf(m, "%s", symname);
51387 @@ -112,7 +116,11 @@ next_one:
51389 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
51391 +#ifdef CONFIG_GRKERNSEC_HIDESYM
51392 + SEQ_printf(m, " .base: %p\n", NULL);
51394 SEQ_printf(m, " .base: %p\n", base);
51396 SEQ_printf(m, " .index: %d\n",
51398 SEQ_printf(m, " .resolution: %Lu nsecs\n",
51399 @@ -293,7 +301,11 @@ static int __init init_timer_list_procfs
51401 struct proc_dir_entry *pe;
51403 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
51404 + pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
51406 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
51411 diff -urNp linux-2.6.37/kernel/time/timer_stats.c linux-2.6.37/kernel/time/timer_stats.c
51412 --- linux-2.6.37/kernel/time/timer_stats.c 2011-01-04 19:50:19.000000000 -0500
51413 +++ linux-2.6.37/kernel/time/timer_stats.c 2011-01-17 02:41:02.000000000 -0500
51414 @@ -269,12 +269,16 @@ void timer_stats_update_stats(void *time
51416 static void print_name_offset(struct seq_file *m, unsigned long addr)
51418 +#ifdef CONFIG_GRKERNSEC_HIDESYM
51419 + seq_printf(m, "<%p>", NULL);
51421 char symname[KSYM_NAME_LEN];
51423 if (lookup_symbol_name(addr, symname) < 0)
51424 seq_printf(m, "<%p>", (void *)addr);
51426 seq_printf(m, "%s", symname);
51430 static int tstats_show(struct seq_file *m, void *v)
51431 @@ -417,7 +421,11 @@ static int __init init_tstats_procfs(voi
51433 struct proc_dir_entry *pe;
51435 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
51436 + pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
51438 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
51443 diff -urNp linux-2.6.37/kernel/time.c linux-2.6.37/kernel/time.c
51444 --- linux-2.6.37/kernel/time.c 2011-01-04 19:50:19.000000000 -0500
51445 +++ linux-2.6.37/kernel/time.c 2011-01-17 02:41:02.000000000 -0500
51446 @@ -163,6 +163,11 @@ int do_sys_settimeofday(struct timespec
51450 + /* we log in do_settimeofday called below, so don't log twice
51453 + gr_log_timechange();
51455 /* SMP safe, global irq locking makes it work. */
51457 update_vsyscall_tz();
51458 @@ -238,7 +243,7 @@ EXPORT_SYMBOL(current_fs_time);
51459 * Avoid unnecessary multiplications/divisions in the
51460 * two most common HZ cases:
51462 -unsigned int inline jiffies_to_msecs(const unsigned long j)
51463 +inline unsigned int jiffies_to_msecs(const unsigned long j)
51465 #if HZ <= MSEC_PER_SEC && !(MSEC_PER_SEC % HZ)
51466 return (MSEC_PER_SEC / HZ) * j;
51467 @@ -254,7 +259,7 @@ unsigned int inline jiffies_to_msecs(con
51469 EXPORT_SYMBOL(jiffies_to_msecs);
51471 -unsigned int inline jiffies_to_usecs(const unsigned long j)
51472 +inline unsigned int jiffies_to_usecs(const unsigned long j)
51474 #if HZ <= USEC_PER_SEC && !(USEC_PER_SEC % HZ)
51475 return (USEC_PER_SEC / HZ) * j;
51476 diff -urNp linux-2.6.37/kernel/timer.c linux-2.6.37/kernel/timer.c
51477 --- linux-2.6.37/kernel/timer.c 2011-01-04 19:50:19.000000000 -0500
51478 +++ linux-2.6.37/kernel/timer.c 2011-01-17 02:41:02.000000000 -0500
51479 @@ -1296,7 +1296,7 @@ void update_process_times(int user_tick)
51481 * This function runs timers and the timer-tq in bottom half context.
51483 -static void run_timer_softirq(struct softirq_action *h)
51484 +static void run_timer_softirq(void)
51486 struct tvec_base *base = __get_cpu_var(tvec_bases);
51488 diff -urNp linux-2.6.37/kernel/trace/ftrace.c linux-2.6.37/kernel/trace/ftrace.c
51489 --- linux-2.6.37/kernel/trace/ftrace.c 2011-01-04 19:50:19.000000000 -0500
51490 +++ linux-2.6.37/kernel/trace/ftrace.c 2011-01-17 02:41:02.000000000 -0500
51491 @@ -1107,13 +1107,18 @@ ftrace_code_disable(struct module *mod,
51495 + ret = ftrace_arch_code_modify_prepare();
51496 + FTRACE_WARN_ON(ret);
51500 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
51501 + FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
51503 ftrace_bug(ret, ip);
51504 rec->flags |= FTRACE_FL_FAILED;
51508 + return ret ? 0 : 1;
51512 diff -urNp linux-2.6.37/kernel/trace/ring_buffer.c linux-2.6.37/kernel/trace/ring_buffer.c
51513 --- linux-2.6.37/kernel/trace/ring_buffer.c 2011-01-04 19:50:19.000000000 -0500
51514 +++ linux-2.6.37/kernel/trace/ring_buffer.c 2011-01-17 02:41:02.000000000 -0500
51515 @@ -669,7 +669,7 @@ static struct list_head *rb_list_head(st
51516 * the reader page). But if the next page is a header page,
51517 * its flags will be non zero.
51521 rb_is_head_page(struct ring_buffer_per_cpu *cpu_buffer,
51522 struct buffer_page *page, struct list_head *list)
51524 diff -urNp linux-2.6.37/kernel/trace/trace.c linux-2.6.37/kernel/trace/trace.c
51525 --- linux-2.6.37/kernel/trace/trace.c 2011-01-04 19:50:19.000000000 -0500
51526 +++ linux-2.6.37/kernel/trace/trace.c 2011-01-17 02:41:02.000000000 -0500
51527 @@ -3969,10 +3969,9 @@ static const struct file_operations trac
51531 -static struct dentry *d_tracer;
51533 struct dentry *tracing_init_dentry(void)
51535 + static struct dentry *d_tracer;
51539 @@ -3992,10 +3991,9 @@ struct dentry *tracing_init_dentry(void)
51543 -static struct dentry *d_percpu;
51545 struct dentry *tracing_dentry_percpu(void)
51547 + static struct dentry *d_percpu;
51549 struct dentry *d_tracer;
51551 diff -urNp linux-2.6.37/kernel/trace/trace_events.c linux-2.6.37/kernel/trace/trace_events.c
51552 --- linux-2.6.37/kernel/trace/trace_events.c 2011-01-04 19:50:19.000000000 -0500
51553 +++ linux-2.6.37/kernel/trace/trace_events.c 2011-01-17 02:41:02.000000000 -0500
51554 @@ -1231,6 +1231,7 @@ static LIST_HEAD(ftrace_module_file_list
51555 * Modules must own their file_operations to keep up with
51556 * reference counting.
51558 +/* cannot be const, see trace_create_file_ops() */
51559 struct ftrace_module_file_ops {
51560 struct list_head list;
51561 struct module *mod;
51562 diff -urNp linux-2.6.37/kernel/trace/trace_output.c linux-2.6.37/kernel/trace/trace_output.c
51563 --- linux-2.6.37/kernel/trace/trace_output.c 2011-01-04 19:50:19.000000000 -0500
51564 +++ linux-2.6.37/kernel/trace/trace_output.c 2011-01-17 02:41:02.000000000 -0500
51565 @@ -278,7 +278,7 @@ int trace_seq_path(struct trace_seq *s,
51567 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
51569 - p = mangle_path(s->buffer + s->len, p, "\n");
51570 + p = mangle_path(s->buffer + s->len, p, "\n\\");
51572 s->len = p - s->buffer;
51574 diff -urNp linux-2.6.37/kernel/trace/trace_stack.c linux-2.6.37/kernel/trace/trace_stack.c
51575 --- linux-2.6.37/kernel/trace/trace_stack.c 2011-01-04 19:50:19.000000000 -0500
51576 +++ linux-2.6.37/kernel/trace/trace_stack.c 2011-01-17 02:41:02.000000000 -0500
51577 @@ -50,7 +50,7 @@ static inline void check_stack(void)
51580 /* we do not handle interrupt stacks yet */
51581 - if (!object_is_on_stack(&this_size))
51582 + if (!object_starts_on_stack(&this_size))
51585 local_irq_save(flags);
51586 diff -urNp linux-2.6.37/lib/bug.c linux-2.6.37/lib/bug.c
51587 --- linux-2.6.37/lib/bug.c 2011-01-04 19:50:19.000000000 -0500
51588 +++ linux-2.6.37/lib/bug.c 2011-01-17 02:41:02.000000000 -0500
51589 @@ -133,6 +133,8 @@ enum bug_trap_type report_bug(unsigned l
51590 return BUG_TRAP_TYPE_NONE;
51592 bug = find_bug(bugaddr);
51594 + return BUG_TRAP_TYPE_NONE;
51598 diff -urNp linux-2.6.37/lib/debugobjects.c linux-2.6.37/lib/debugobjects.c
51599 --- linux-2.6.37/lib/debugobjects.c 2011-01-04 19:50:19.000000000 -0500
51600 +++ linux-2.6.37/lib/debugobjects.c 2011-01-17 02:41:02.000000000 -0500
51601 @@ -281,7 +281,7 @@ static void debug_object_is_on_stack(voi
51605 - is_on_stack = object_is_on_stack(addr);
51606 + is_on_stack = object_starts_on_stack(addr);
51607 if (is_on_stack == onstack)
51610 diff -urNp linux-2.6.37/lib/dma-debug.c linux-2.6.37/lib/dma-debug.c
51611 --- linux-2.6.37/lib/dma-debug.c 2011-01-04 19:50:19.000000000 -0500
51612 +++ linux-2.6.37/lib/dma-debug.c 2011-01-17 02:41:02.000000000 -0500
51613 @@ -862,7 +862,7 @@ out:
51615 static void check_for_stack(struct device *dev, void *addr)
51617 - if (object_is_on_stack(addr))
51618 + if (object_starts_on_stack(addr))
51619 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
51620 "stack [addr=%p]\n", addr);
51622 diff -urNp linux-2.6.37/lib/inflate.c linux-2.6.37/lib/inflate.c
51623 --- linux-2.6.37/lib/inflate.c 2011-01-04 19:50:19.000000000 -0500
51624 +++ linux-2.6.37/lib/inflate.c 2011-01-17 02:41:02.000000000 -0500
51625 @@ -269,7 +269,7 @@ static void free(void *where)
51626 malloc_ptr = free_mem_ptr;
51629 -#define malloc(a) kmalloc(a, GFP_KERNEL)
51630 +#define malloc(a) kmalloc((a), GFP_KERNEL)
51631 #define free(a) kfree(a)
51634 diff -urNp linux-2.6.37/lib/Kconfig.debug linux-2.6.37/lib/Kconfig.debug
51635 --- linux-2.6.37/lib/Kconfig.debug 2011-01-04 19:50:19.000000000 -0500
51636 +++ linux-2.6.37/lib/Kconfig.debug 2011-01-17 02:41:02.000000000 -0500
51637 @@ -1065,6 +1065,7 @@ config LATENCYTOP
51638 depends on DEBUG_KERNEL
51639 depends on STACKTRACE_SUPPORT
51641 + depends on !GRKERNSEC_HIDESYM
51642 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE
51644 select KALLSYMS_ALL
51645 diff -urNp linux-2.6.37/lib/kref.c linux-2.6.37/lib/kref.c
51646 --- linux-2.6.37/lib/kref.c 2011-01-04 19:50:19.000000000 -0500
51647 +++ linux-2.6.37/lib/kref.c 2011-01-17 02:41:02.000000000 -0500
51648 @@ -52,7 +52,7 @@ void kref_get(struct kref *kref)
51650 int kref_put(struct kref *kref, void (*release)(struct kref *kref))
51652 - WARN_ON(release == NULL);
51653 + BUG_ON(release == NULL);
51654 WARN_ON(release == (void (*)(struct kref *))kfree);
51656 if (atomic_dec_and_test(&kref->refcount)) {
51657 diff -urNp linux-2.6.37/lib/radix-tree.c linux-2.6.37/lib/radix-tree.c
51658 --- linux-2.6.37/lib/radix-tree.c 2011-01-04 19:50:19.000000000 -0500
51659 +++ linux-2.6.37/lib/radix-tree.c 2011-01-17 02:41:02.000000000 -0500
51660 @@ -80,7 +80,7 @@ struct radix_tree_preload {
51662 struct radix_tree_node *nodes[RADIX_TREE_MAX_PATH];
51664 -static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
51665 +static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
51667 static inline void *ptr_to_indirect(void *ptr)
51669 diff -urNp linux-2.6.37/lib/vsprintf.c linux-2.6.37/lib/vsprintf.c
51670 --- linux-2.6.37/lib/vsprintf.c 2011-01-04 19:50:19.000000000 -0500
51671 +++ linux-2.6.37/lib/vsprintf.c 2011-01-17 02:41:02.000000000 -0500
51673 * - scnprintf and vscnprintf
51676 +#ifdef CONFIG_GRKERNSEC_HIDESYM
51677 +#define __INCLUDED_BY_HIDESYM 1
51679 #include <stdarg.h>
51680 #include <linux/module.h>
51681 #include <linux/types.h>
51682 @@ -574,7 +577,7 @@ char *symbol_string(char *buf, char *end
51683 unsigned long value = (unsigned long) ptr;
51684 #ifdef CONFIG_KALLSYMS
51685 char sym[KSYM_SYMBOL_LEN];
51686 - if (ext != 'f' && ext != 's')
51687 + if (ext != 'f' && ext != 's' && ext != 'a')
51688 sprint_symbol(sym, value);
51690 kallsyms_lookup(value, NULL, NULL, NULL, sym);
51691 @@ -947,6 +950,8 @@ char *uuid_string(char *buf, char *end,
51692 * - 'f' For simple symbolic function names without offset
51693 * - 'S' For symbolic direct pointers with offset
51694 * - 's' For symbolic direct pointers without offset
51695 + * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
51696 + * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
51697 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
51698 * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
51699 * - 'M' For a 6-byte MAC address, it prints the address in the
51700 @@ -990,12 +995,12 @@ char *pointer(const char *fmt, char *buf
51704 - * Print (null) with the same width as a pointer so it makes
51705 + * Print (nil) with the same width as a pointer so it makes
51706 * tabular output look nice.
51708 if (spec.field_width == -1)
51709 spec.field_width = 2 * sizeof(void *);
51710 - return string(buf, end, "(null)", spec);
51711 + return string(buf, end, "(nil)", spec);
51715 @@ -1005,6 +1010,13 @@ char *pointer(const char *fmt, char *buf
51719 +#ifdef CONFIG_GRKERNSEC_HIDESYM
51722 + return symbol_string(buf, end, ptr, spec, *fmt);
51726 return symbol_string(buf, end, ptr, spec, *fmt);
51729 @@ -1750,11 +1762,11 @@ int bstr_printf(char *buf, size_t size,
51730 typeof(type) value; \
51731 if (sizeof(type) == 8) { \
51732 args = PTR_ALIGN(args, sizeof(u32)); \
51733 - *(u32 *)&value = *(u32 *)args; \
51734 - *((u32 *)&value + 1) = *(u32 *)(args + 4); \
51735 + *(u32 *)&value = *(const u32 *)args; \
51736 + *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
51738 args = PTR_ALIGN(args, sizeof(type)); \
51739 - value = *(typeof(type) *)args; \
51740 + value = *(const typeof(type) *)args; \
51742 args += sizeof(type); \
51744 @@ -1817,7 +1829,7 @@ int bstr_printf(char *buf, size_t size,
51745 case FORMAT_TYPE_STR: {
51746 const char *str_arg = args;
51747 args += strlen(str_arg) + 1;
51748 - str = string(str, end, (char *)str_arg, spec);
51749 + str = string(str, end, str_arg, spec);
51753 diff -urNp linux-2.6.37/localversion-grsec linux-2.6.37/localversion-grsec
51754 --- linux-2.6.37/localversion-grsec 1969-12-31 19:00:00.000000000 -0500
51755 +++ linux-2.6.37/localversion-grsec 2011-01-17 02:41:02.000000000 -0500
51758 diff -urNp linux-2.6.37/Makefile linux-2.6.37/Makefile
51759 --- linux-2.6.37/Makefile 2011-01-04 19:50:19.000000000 -0500
51760 +++ linux-2.6.37/Makefile 2011-01-17 02:41:02.000000000 -0500
51761 @@ -232,8 +232,8 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH"
51765 -HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
51766 -HOSTCXXFLAGS = -O2
51767 +HOSTCFLAGS = -Wall -W -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer -fno-delete-null-pointer-checks
51768 +HOSTCXXFLAGS = -O2 -fno-delete-null-pointer-checks
51770 # Decide whether to build built-in, modular, or both.
51771 # Normally, just do built-in.
51772 @@ -680,7 +680,7 @@ export mod_strip_cmd
51775 ifeq ($(KBUILD_EXTMOD),)
51776 -core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
51777 +core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
51779 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
51780 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
51781 diff -urNp linux-2.6.37/mm/bootmem.c linux-2.6.37/mm/bootmem.c
51782 --- linux-2.6.37/mm/bootmem.c 2011-01-04 19:50:19.000000000 -0500
51783 +++ linux-2.6.37/mm/bootmem.c 2011-01-17 02:41:02.000000000 -0500
51784 @@ -201,19 +201,30 @@ static void __init __free_pages_memory(u
51785 unsigned long __init free_all_memory_core_early(int nodeid)
51789 + u64 start, end, startrange, endrange;
51790 unsigned long count = 0;
51791 - struct range *range = NULL;
51792 + struct range *range = NULL, rangerange = { 0, 0 };
51795 nr_range = get_free_all_memory_range(&range, nodeid);
51796 + startrange = __pa(range) >> PAGE_SHIFT;
51797 + endrange = (__pa(range + nr_range) - 1) >> PAGE_SHIFT;
51799 for (i = 0; i < nr_range; i++) {
51800 start = range[i].start;
51801 end = range[i].end;
51802 + if (start <= endrange && startrange < end) {
51803 + BUG_ON(rangerange.start | rangerange.end);
51804 + rangerange = range[i];
51807 count += end - start;
51808 __free_pages_memory(start, end);
51810 + start = rangerange.start;
51811 + end = rangerange.end;
51812 + count += end - start;
51813 + __free_pages_memory(start, end);
51817 diff -urNp linux-2.6.37/mm/filemap.c linux-2.6.37/mm/filemap.c
51818 --- linux-2.6.37/mm/filemap.c 2011-01-04 19:50:19.000000000 -0500
51819 +++ linux-2.6.37/mm/filemap.c 2011-01-17 02:41:02.000000000 -0500
51820 @@ -1660,7 +1660,7 @@ int generic_file_mmap(struct file * file
51821 struct address_space *mapping = file->f_mapping;
51823 if (!mapping->a_ops->readpage)
51826 file_accessed(file);
51827 vma->vm_ops = &generic_file_vm_ops;
51828 vma->vm_flags |= VM_CAN_NONLINEAR;
51829 @@ -2056,6 +2056,7 @@ inline int generic_write_checks(struct f
51830 *pos = i_size_read(inode);
51832 if (limit != RLIM_INFINITY) {
51833 + gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
51834 if (*pos >= limit) {
51835 send_sig(SIGXFSZ, current, 0);
51837 diff -urNp linux-2.6.37/mm/fremap.c linux-2.6.37/mm/fremap.c
51838 --- linux-2.6.37/mm/fremap.c 2011-01-04 19:50:19.000000000 -0500
51839 +++ linux-2.6.37/mm/fremap.c 2011-01-17 02:41:02.000000000 -0500
51840 @@ -156,6 +156,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsign
51842 vma = find_vma(mm, start);
51844 +#ifdef CONFIG_PAX_SEGMEXEC
51845 + if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
51850 * Make sure the vma is shared, that it supports prefaulting,
51851 * and that the remapped range is valid and fully within
51852 @@ -224,7 +229,7 @@ SYSCALL_DEFINE5(remap_file_pages, unsign
51854 * drop PG_Mlocked flag for over-mapped range
51856 - unsigned int saved_flags = vma->vm_flags;
51857 + unsigned long saved_flags = vma->vm_flags;
51858 munlock_vma_pages_range(vma, start, start + size);
51859 vma->vm_flags = saved_flags;
51861 diff -urNp linux-2.6.37/mm/highmem.c linux-2.6.37/mm/highmem.c
51862 --- linux-2.6.37/mm/highmem.c 2011-01-04 19:50:19.000000000 -0500
51863 +++ linux-2.6.37/mm/highmem.c 2011-01-17 02:41:02.000000000 -0500
51864 @@ -125,9 +125,10 @@ static void flush_all_zero_pkmaps(void)
51865 * So no dangers, even with speculative execution.
51867 page = pte_page(pkmap_page_table[i]);
51868 + pax_open_kernel();
51869 pte_clear(&init_mm, (unsigned long)page_address(page),
51870 &pkmap_page_table[i]);
51872 + pax_close_kernel();
51873 set_page_address(page, NULL);
51876 @@ -186,9 +187,11 @@ start:
51879 vaddr = PKMAP_ADDR(last_pkmap_nr);
51881 + pax_open_kernel();
51882 set_pte_at(&init_mm, vaddr,
51883 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
51885 + pax_close_kernel();
51886 pkmap_count[last_pkmap_nr] = 1;
51887 set_page_address(page, (void *)vaddr);
51889 diff -urNp linux-2.6.37/mm/hugetlb.c linux-2.6.37/mm/hugetlb.c
51890 --- linux-2.6.37/mm/hugetlb.c 2011-01-04 19:50:19.000000000 -0500
51891 +++ linux-2.6.37/mm/hugetlb.c 2011-01-17 02:41:02.000000000 -0500
51892 @@ -2373,6 +2373,27 @@ static int unmap_ref_private(struct mm_s
51896 +#ifdef CONFIG_PAX_SEGMEXEC
51897 +static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
51899 + struct mm_struct *mm = vma->vm_mm;
51900 + struct vm_area_struct *vma_m;
51901 + unsigned long address_m;
51904 + vma_m = pax_find_mirror_vma(vma);
51908 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
51909 + address_m = address + SEGMEXEC_TASK_SIZE;
51910 + ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
51911 + get_page(page_m);
51912 + hugepage_add_anon_rmap(page_m, vma_m, address_m);
51913 + set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
51918 * Hugetlb_cow() should be called with page lock of the original hugepage held.
51920 @@ -2473,6 +2494,11 @@ retry_avoidcopy:
51921 make_huge_pte(vma, new_page, 1));
51922 page_remove_rmap(old_page);
51923 hugepage_add_new_anon_rmap(new_page, vma, address);
51925 +#ifdef CONFIG_PAX_SEGMEXEC
51926 + pax_mirror_huge_pte(vma, address, new_page);
51929 /* Make the old page be freed below */
51930 new_page = old_page;
51931 mmu_notifier_invalidate_range_end(mm,
51932 @@ -2624,6 +2650,10 @@ retry:
51933 && (vma->vm_flags & VM_SHARED)));
51934 set_huge_pte_at(mm, address, ptep, new_pte);
51936 +#ifdef CONFIG_PAX_SEGMEXEC
51937 + pax_mirror_huge_pte(vma, address, page);
51940 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
51941 /* Optimization, do the COW without a second fault */
51942 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
51943 @@ -2653,6 +2683,10 @@ int hugetlb_fault(struct mm_struct *mm,
51944 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
51945 struct hstate *h = hstate_vma(vma);
51947 +#ifdef CONFIG_PAX_SEGMEXEC
51948 + struct vm_area_struct *vma_m;
51951 ptep = huge_pte_offset(mm, address);
51953 entry = huge_ptep_get(ptep);
51954 @@ -2664,6 +2698,26 @@ int hugetlb_fault(struct mm_struct *mm,
51955 VM_FAULT_SET_HINDEX(h - hstates);
51958 +#ifdef CONFIG_PAX_SEGMEXEC
51959 + vma_m = pax_find_mirror_vma(vma);
51961 + unsigned long address_m;
51963 + if (vma->vm_start > vma_m->vm_start) {
51964 + address_m = address;
51965 + address -= SEGMEXEC_TASK_SIZE;
51967 + h = hstate_vma(vma);
51969 + address_m = address + SEGMEXEC_TASK_SIZE;
51971 + if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
51972 + return VM_FAULT_OOM;
51973 + address_m &= HPAGE_MASK;
51974 + unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
51978 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
51980 return VM_FAULT_OOM;
51981 diff -urNp linux-2.6.37/mm/Kconfig linux-2.6.37/mm/Kconfig
51982 --- linux-2.6.37/mm/Kconfig 2011-01-04 19:50:19.000000000 -0500
51983 +++ linux-2.6.37/mm/Kconfig 2011-01-17 02:41:02.000000000 -0500
51984 @@ -240,7 +240,7 @@ config KSM
51985 config DEFAULT_MMAP_MIN_ADDR
51986 int "Low address space to protect from user allocation"
51991 This is the portion of low virtual memory which should be protected
51992 from userspace allocation. Keeping a user from writing to low pages
51993 diff -urNp linux-2.6.37/mm/kmemleak.c linux-2.6.37/mm/kmemleak.c
51994 --- linux-2.6.37/mm/kmemleak.c 2011-01-04 19:50:19.000000000 -0500
51995 +++ linux-2.6.37/mm/kmemleak.c 2011-01-17 02:41:02.000000000 -0500
51996 @@ -355,7 +355,7 @@ static void print_unreferenced(struct se
51998 for (i = 0; i < object->trace_len; i++) {
51999 void *ptr = (void *)object->trace[i];
52000 - seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
52001 + seq_printf(seq, " [<%p>] %pA\n", ptr, ptr);
52005 diff -urNp linux-2.6.37/mm/maccess.c linux-2.6.37/mm/maccess.c
52006 --- linux-2.6.37/mm/maccess.c 2011-01-04 19:50:19.000000000 -0500
52007 +++ linux-2.6.37/mm/maccess.c 2011-01-17 02:41:02.000000000 -0500
52008 @@ -15,10 +15,10 @@
52009 * happens, handle that and return -EFAULT.
52012 -long __weak probe_kernel_read(void *dst, void *src, size_t size)
52013 +long __weak probe_kernel_read(void *dst, const void *src, size_t size)
52014 __attribute__((alias("__probe_kernel_read")));
52016 -long __probe_kernel_read(void *dst, void *src, size_t size)
52017 +long __probe_kernel_read(void *dst, const void *src, size_t size)
52020 mm_segment_t old_fs = get_fs();
52021 @@ -43,10 +43,10 @@ EXPORT_SYMBOL_GPL(probe_kernel_read);
52022 * Safely write to address @dst from the buffer at @src. If a kernel fault
52023 * happens, handle that and return -EFAULT.
52025 -long __weak probe_kernel_write(void *dst, void *src, size_t size)
52026 +long __weak probe_kernel_write(void *dst, const void *src, size_t size)
52027 __attribute__((alias("__probe_kernel_write")));
52029 -long __probe_kernel_write(void *dst, void *src, size_t size)
52030 +long __probe_kernel_write(void *dst, const void *src, size_t size)
52033 mm_segment_t old_fs = get_fs();
52034 diff -urNp linux-2.6.37/mm/madvise.c linux-2.6.37/mm/madvise.c
52035 --- linux-2.6.37/mm/madvise.c 2011-01-04 19:50:19.000000000 -0500
52036 +++ linux-2.6.37/mm/madvise.c 2011-01-17 02:41:02.000000000 -0500
52037 @@ -45,6 +45,10 @@ static long madvise_behavior(struct vm_a
52039 unsigned long new_flags = vma->vm_flags;
52041 +#ifdef CONFIG_PAX_SEGMEXEC
52042 + struct vm_area_struct *vma_m;
52045 switch (behavior) {
52047 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
52048 @@ -104,6 +108,13 @@ success:
52050 * vm_flags is protected by the mmap_sem held in write mode.
52053 +#ifdef CONFIG_PAX_SEGMEXEC
52054 + vma_m = pax_find_mirror_vma(vma);
52056 + vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
52059 vma->vm_flags = new_flags;
52062 @@ -162,6 +173,11 @@ static long madvise_dontneed(struct vm_a
52063 struct vm_area_struct ** prev,
52064 unsigned long start, unsigned long end)
52067 +#ifdef CONFIG_PAX_SEGMEXEC
52068 + struct vm_area_struct *vma_m;
52072 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
52074 @@ -174,6 +190,21 @@ static long madvise_dontneed(struct vm_a
52075 zap_page_range(vma, start, end - start, &details);
52077 zap_page_range(vma, start, end - start, NULL);
52079 +#ifdef CONFIG_PAX_SEGMEXEC
52080 + vma_m = pax_find_mirror_vma(vma);
52082 + if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
52083 + struct zap_details details = {
52084 + .nonlinear_vma = vma_m,
52085 + .last_index = ULONG_MAX,
52087 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
52089 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
52096 @@ -366,6 +397,16 @@ SYSCALL_DEFINE3(madvise, unsigned long,
52100 +#ifdef CONFIG_PAX_SEGMEXEC
52101 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
52102 + if (end > SEGMEXEC_TASK_SIZE)
52107 + if (end > TASK_SIZE)
52113 diff -urNp linux-2.6.37/mm/memory.c linux-2.6.37/mm/memory.c
52114 --- linux-2.6.37/mm/memory.c 2011-01-04 19:50:19.000000000 -0500
52115 +++ linux-2.6.37/mm/memory.c 2011-01-17 02:41:02.000000000 -0500
52116 @@ -259,8 +259,12 @@ static inline void free_pmd_range(struct
52119 pmd = pmd_offset(pud, start);
52121 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
52123 pmd_free_tlb(tlb, pmd, start);
52128 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
52129 @@ -291,9 +295,12 @@ static inline void free_pud_range(struct
52130 if (end - 1 > ceiling - 1)
52133 +#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
52134 pud = pud_offset(pgd, start);
52136 pud_free_tlb(tlb, pud, start);
52142 @@ -1361,10 +1368,10 @@ int __get_user_pages(struct task_struct
52143 (VM_MAYREAD | VM_MAYWRITE) : (VM_READ | VM_WRITE);
52147 + while (nr_pages) {
52148 struct vm_area_struct *vma;
52150 - vma = find_extend_vma(mm, start);
52151 + vma = find_vma(mm, start);
52152 if (!vma && in_gate_area(tsk, start)) {
52153 unsigned long pg = start & PAGE_MASK;
52154 struct vm_area_struct *gate_vma = get_gate_vma(tsk);
52155 @@ -1416,7 +1423,7 @@ int __get_user_pages(struct task_struct
52160 + if (!vma || start < vma->vm_start ||
52161 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
52162 !(vm_flags & vma->vm_flags))
52163 return i ? : -EFAULT;
52164 @@ -1492,7 +1499,7 @@ int __get_user_pages(struct task_struct
52165 start += PAGE_SIZE;
52167 } while (nr_pages && start < vma->vm_end);
52168 - } while (nr_pages);
52173 @@ -1637,6 +1644,10 @@ static int insert_page(struct vm_area_st
52174 page_add_file_rmap(page);
52175 set_pte_at(mm, addr, pte, mk_pte(page, prot));
52177 +#ifdef CONFIG_PAX_SEGMEXEC
52178 + pax_mirror_file_pte(vma, addr, page, ptl);
52182 pte_unmap_unlock(pte, ptl);
52184 @@ -1671,10 +1682,22 @@ out:
52185 int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
52189 +#ifdef CONFIG_PAX_SEGMEXEC
52190 + struct vm_area_struct *vma_m;
52193 if (addr < vma->vm_start || addr >= vma->vm_end)
52195 if (!page_count(page))
52198 +#ifdef CONFIG_PAX_SEGMEXEC
52199 + vma_m = pax_find_mirror_vma(vma);
52201 + vma_m->vm_flags |= VM_INSERTPAGE;
52204 vma->vm_flags |= VM_INSERTPAGE;
52205 return insert_page(vma, addr, page, vma->vm_page_prot);
52207 @@ -1760,6 +1783,7 @@ int vm_insert_mixed(struct vm_area_struc
52210 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
52211 + BUG_ON(vma->vm_mirror);
52213 if (addr < vma->vm_start || addr >= vma->vm_end)
52215 @@ -2087,6 +2111,186 @@ static inline void cow_user_page(struct
52216 copy_user_highpage(dst, src, va, vma);
52219 +#ifdef CONFIG_PAX_SEGMEXEC
52220 +static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
52222 + struct mm_struct *mm = vma->vm_mm;
52224 + pte_t *pte, entry;
52226 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
52228 + if (!pte_present(entry)) {
52229 + if (!pte_none(entry)) {
52230 + BUG_ON(pte_file(entry));
52231 + free_swap_and_cache(pte_to_swp_entry(entry));
52232 + pte_clear_not_present_full(mm, address, pte, 0);
52235 + struct page *page;
52237 + flush_cache_page(vma, address, pte_pfn(entry));
52238 + entry = ptep_clear_flush(vma, address, pte);
52239 + BUG_ON(pte_dirty(entry));
52240 + page = vm_normal_page(vma, address, entry);
52242 + update_hiwater_rss(mm);
52243 + if (PageAnon(page))
52244 + dec_mm_counter_fast(mm, MM_ANONPAGES);
52246 + dec_mm_counter_fast(mm, MM_FILEPAGES);
52247 + page_remove_rmap(page);
52248 + page_cache_release(page);
52251 + pte_unmap_unlock(pte, ptl);
52254 +/* PaX: if vma is mirrored, synchronize the mirror's PTE
52256 + * the ptl of the lower mapped page is held on entry and is not released on exit
52257 + * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
52259 +static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
52261 + struct mm_struct *mm = vma->vm_mm;
52262 + unsigned long address_m;
52263 + spinlock_t *ptl_m;
52264 + struct vm_area_struct *vma_m;
52266 + pte_t *pte_m, entry_m;
52268 + BUG_ON(!page_m || !PageAnon(page_m));
52270 + vma_m = pax_find_mirror_vma(vma);
52274 + BUG_ON(!PageLocked(page_m));
52275 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
52276 + address_m = address + SEGMEXEC_TASK_SIZE;
52277 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
52278 + pte_m = pte_offset_map(pmd_m, address_m);
52279 + ptl_m = pte_lockptr(mm, pmd_m);
52280 + if (ptl != ptl_m) {
52281 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
52282 + if (!pte_none(*pte_m))
52286 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
52287 + page_cache_get(page_m);
52288 + page_add_anon_rmap(page_m, vma_m, address_m);
52289 + inc_mm_counter_fast(mm, MM_ANONPAGES);
52290 + set_pte_at(mm, address_m, pte_m, entry_m);
52291 + update_mmu_cache(vma_m, address_m, entry_m);
52293 + if (ptl != ptl_m)
52294 + spin_unlock(ptl_m);
52295 + pte_unmap(pte_m);
52296 + unlock_page(page_m);
52299 +void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
52301 + struct mm_struct *mm = vma->vm_mm;
52302 + unsigned long address_m;
52303 + spinlock_t *ptl_m;
52304 + struct vm_area_struct *vma_m;
52306 + pte_t *pte_m, entry_m;
52308 + BUG_ON(!page_m || PageAnon(page_m));
52310 + vma_m = pax_find_mirror_vma(vma);
52314 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
52315 + address_m = address + SEGMEXEC_TASK_SIZE;
52316 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
52317 + pte_m = pte_offset_map(pmd_m, address_m);
52318 + ptl_m = pte_lockptr(mm, pmd_m);
52319 + if (ptl != ptl_m) {
52320 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
52321 + if (!pte_none(*pte_m))
52325 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
52326 + page_cache_get(page_m);
52327 + page_add_file_rmap(page_m);
52328 + inc_mm_counter_fast(mm, MM_FILEPAGES);
52329 + set_pte_at(mm, address_m, pte_m, entry_m);
52330 + update_mmu_cache(vma_m, address_m, entry_m);
52332 + if (ptl != ptl_m)
52333 + spin_unlock(ptl_m);
52334 + pte_unmap(pte_m);
52337 +static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
52339 + struct mm_struct *mm = vma->vm_mm;
52340 + unsigned long address_m;
52341 + spinlock_t *ptl_m;
52342 + struct vm_area_struct *vma_m;
52344 + pte_t *pte_m, entry_m;
52346 + vma_m = pax_find_mirror_vma(vma);
52350 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
52351 + address_m = address + SEGMEXEC_TASK_SIZE;
52352 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
52353 + pte_m = pte_offset_map(pmd_m, address_m);
52354 + ptl_m = pte_lockptr(mm, pmd_m);
52355 + if (ptl != ptl_m) {
52356 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
52357 + if (!pte_none(*pte_m))
52361 + entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
52362 + set_pte_at(mm, address_m, pte_m, entry_m);
52364 + if (ptl != ptl_m)
52365 + spin_unlock(ptl_m);
52366 + pte_unmap(pte_m);
52369 +static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
52371 + struct page *page_m;
52374 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
52378 + page_m = vm_normal_page(vma, address, entry);
52380 + pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
52381 + else if (PageAnon(page_m)) {
52382 + if (pax_find_mirror_vma(vma)) {
52383 + pte_unmap_unlock(pte, ptl);
52384 + lock_page(page_m);
52385 + pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
52386 + if (pte_same(entry, *pte))
52387 + pax_mirror_anon_pte(vma, address, page_m, ptl);
52389 + unlock_page(page_m);
52392 + pax_mirror_file_pte(vma, address, page_m, ptl);
52395 + pte_unmap_unlock(pte, ptl);
52400 * This routine handles present pages, when users try to write
52401 * to a shared page. It is done by copying the page to a new address
52402 @@ -2274,6 +2478,12 @@ gotten:
52404 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
52405 if (likely(pte_same(*page_table, orig_pte))) {
52407 +#ifdef CONFIG_PAX_SEGMEXEC
52408 + if (pax_find_mirror_vma(vma))
52409 + BUG_ON(!trylock_page(new_page));
52413 if (!PageAnon(old_page)) {
52414 dec_mm_counter_fast(mm, MM_FILEPAGES);
52415 @@ -2325,6 +2535,10 @@ gotten:
52416 page_remove_rmap(old_page);
52419 +#ifdef CONFIG_PAX_SEGMEXEC
52420 + pax_mirror_anon_pte(vma, address, new_page, ptl);
52423 /* Free the old page.. */
52424 new_page = old_page;
52425 ret |= VM_FAULT_WRITE;
52426 @@ -2756,6 +2970,11 @@ static int do_swap_page(struct mm_struct
52428 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
52429 try_to_free_swap(page);
52431 +#ifdef CONFIG_PAX_SEGMEXEC
52432 + if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
52438 @@ -2779,6 +2998,11 @@ static int do_swap_page(struct mm_struct
52440 /* No need to invalidate - it was non-present before */
52441 update_mmu_cache(vma, address, page_table);
52443 +#ifdef CONFIG_PAX_SEGMEXEC
52444 + pax_mirror_anon_pte(vma, address, page, ptl);
52448 pte_unmap_unlock(page_table, ptl);
52450 @@ -2798,40 +3022,6 @@ out_release:
52454 - * This is like a special single-page "expand_{down|up}wards()",
52455 - * except we must first make sure that 'address{-|+}PAGE_SIZE'
52456 - * doesn't hit another vma.
52458 -static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
52460 - address &= PAGE_MASK;
52461 - if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
52462 - struct vm_area_struct *prev = vma->vm_prev;
52465 - * Is there a mapping abutting this one below?
52467 - * That's only ok if it's the same stack mapping
52468 - * that has gotten split..
52470 - if (prev && prev->vm_end == address)
52471 - return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
52473 - expand_stack(vma, address - PAGE_SIZE);
52475 - if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
52476 - struct vm_area_struct *next = vma->vm_next;
52478 - /* As VM_GROWSDOWN but s/below/above/ */
52479 - if (next && next->vm_start == address + PAGE_SIZE)
52480 - return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
52482 - expand_upwards(vma, address + PAGE_SIZE);
52488 * We enter with non-exclusive mmap_sem (to exclude vma changes,
52489 * but allow concurrent faults), and pte mapped but not yet locked.
52490 * We return with mmap_sem still held, but pte unmapped and unlocked.
52491 @@ -2840,27 +3030,23 @@ static int do_anonymous_page(struct mm_s
52492 unsigned long address, pte_t *page_table, pmd_t *pmd,
52493 unsigned int flags)
52495 - struct page *page;
52496 + struct page *page = NULL;
52500 - pte_unmap(page_table);
52502 - /* Check if we need to add a guard page to the stack */
52503 - if (check_stack_guard_page(vma, address) < 0)
52504 - return VM_FAULT_SIGBUS;
52506 - /* Use the zero-page for reads */
52507 if (!(flags & FAULT_FLAG_WRITE)) {
52508 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
52509 vma->vm_page_prot));
52510 - page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
52511 + ptl = pte_lockptr(mm, pmd);
52513 if (!pte_none(*page_table))
52518 /* Allocate our own private page. */
52519 + pte_unmap(page_table);
52521 if (unlikely(anon_vma_prepare(vma)))
52523 page = alloc_zeroed_user_highpage_movable(vma, address);
52524 @@ -2879,6 +3065,11 @@ static int do_anonymous_page(struct mm_s
52525 if (!pte_none(*page_table))
52528 +#ifdef CONFIG_PAX_SEGMEXEC
52529 + if (pax_find_mirror_vma(vma))
52530 + BUG_ON(!trylock_page(page));
52533 inc_mm_counter_fast(mm, MM_ANONPAGES);
52534 page_add_new_anon_rmap(page, vma, address);
52536 @@ -2886,6 +3077,12 @@ setpte:
52538 /* No need to invalidate - it was non-present before */
52539 update_mmu_cache(vma, address, page_table);
52541 +#ifdef CONFIG_PAX_SEGMEXEC
52543 + pax_mirror_anon_pte(vma, address, page, ptl);
52547 pte_unmap_unlock(page_table, ptl);
52549 @@ -3029,6 +3226,12 @@ static int __do_fault(struct mm_struct *
52551 /* Only go through if we didn't race with anybody else... */
52552 if (likely(pte_same(*page_table, orig_pte))) {
52554 +#ifdef CONFIG_PAX_SEGMEXEC
52555 + if (anon && pax_find_mirror_vma(vma))
52556 + BUG_ON(!trylock_page(page));
52559 flush_icache_page(vma, page);
52560 entry = mk_pte(page, vma->vm_page_prot);
52561 if (flags & FAULT_FLAG_WRITE)
52562 @@ -3048,6 +3251,14 @@ static int __do_fault(struct mm_struct *
52564 /* no need to invalidate: a not-present page won't be cached */
52565 update_mmu_cache(vma, address, page_table);
52567 +#ifdef CONFIG_PAX_SEGMEXEC
52569 + pax_mirror_anon_pte(vma, address, page, ptl);
52571 + pax_mirror_file_pte(vma, address, page, ptl);
52576 mem_cgroup_uncharge_page(page);
52577 @@ -3195,6 +3406,12 @@ static inline int handle_pte_fault(struc
52578 if (flags & FAULT_FLAG_WRITE)
52579 flush_tlb_fix_spurious_fault(vma, address);
52582 +#ifdef CONFIG_PAX_SEGMEXEC
52583 + pax_mirror_pte(vma, address, pte, pmd, ptl);
52588 pte_unmap_unlock(pte, ptl);
52590 @@ -3211,6 +3428,10 @@ int handle_mm_fault(struct mm_struct *mm
52594 +#ifdef CONFIG_PAX_SEGMEXEC
52595 + struct vm_area_struct *vma_m;
52598 __set_current_state(TASK_RUNNING);
52600 count_vm_event(PGFAULT);
52601 @@ -3221,6 +3442,34 @@ int handle_mm_fault(struct mm_struct *mm
52602 if (unlikely(is_vm_hugetlb_page(vma)))
52603 return hugetlb_fault(mm, vma, address, flags);
52605 +#ifdef CONFIG_PAX_SEGMEXEC
52606 + vma_m = pax_find_mirror_vma(vma);
52608 + unsigned long address_m;
52613 + if (vma->vm_start > vma_m->vm_start) {
52614 + address_m = address;
52615 + address -= SEGMEXEC_TASK_SIZE;
52618 + address_m = address + SEGMEXEC_TASK_SIZE;
52620 + pgd_m = pgd_offset(mm, address_m);
52621 + pud_m = pud_alloc(mm, pgd_m, address_m);
52623 + return VM_FAULT_OOM;
52624 + pmd_m = pmd_alloc(mm, pud_m, address_m);
52626 + return VM_FAULT_OOM;
52627 + if (!pmd_present(*pmd_m) && __pte_alloc(mm, pmd_m, address_m))
52628 + return VM_FAULT_OOM;
52629 + pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
52633 pgd = pgd_offset(mm, address);
52634 pud = pud_alloc(mm, pgd, address);
52636 @@ -3318,7 +3567,7 @@ static int __init gate_vma_init(void)
52637 gate_vma.vm_start = FIXADDR_USER_START;
52638 gate_vma.vm_end = FIXADDR_USER_END;
52639 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
52640 - gate_vma.vm_page_prot = __P101;
52641 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
52643 * Make sure the vDSO gets into every core dump.
52644 * Dumping its contents makes post-mortem fully interpretable later
52645 diff -urNp linux-2.6.37/mm/memory-failure.c linux-2.6.37/mm/memory-failure.c
52646 --- linux-2.6.37/mm/memory-failure.c 2011-01-04 19:50:19.000000000 -0500
52647 +++ linux-2.6.37/mm/memory-failure.c 2011-01-17 02:41:02.000000000 -0500
52648 @@ -58,7 +58,7 @@ int sysctl_memory_failure_early_kill __r
52650 int sysctl_memory_failure_recovery __read_mostly = 1;
52652 -atomic_long_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
52653 +atomic_long_unchecked_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
52655 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
52657 @@ -967,7 +967,7 @@ int __memory_failure(unsigned long pfn,
52660 nr_pages = 1 << compound_order(hpage);
52661 - atomic_long_add(nr_pages, &mce_bad_pages);
52662 + atomic_long_add_unchecked(nr_pages, &mce_bad_pages);
52665 * We need/can do nothing about count=0 pages.
52666 @@ -997,7 +997,7 @@ int __memory_failure(unsigned long pfn,
52667 if (!PageHWPoison(hpage)
52668 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
52669 || (p != hpage && TestSetPageHWPoison(hpage))) {
52670 - atomic_long_sub(nr_pages, &mce_bad_pages);
52671 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
52674 set_page_hwpoison_huge_page(hpage);
52675 @@ -1052,7 +1052,7 @@ int __memory_failure(unsigned long pfn,
52677 if (hwpoison_filter(p)) {
52678 if (TestClearPageHWPoison(p))
52679 - atomic_long_sub(nr_pages, &mce_bad_pages);
52680 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
52681 unlock_page(hpage);
52684 @@ -1178,7 +1178,7 @@ int unpoison_memory(unsigned long pfn)
52687 if (TestClearPageHWPoison(p))
52688 - atomic_long_sub(nr_pages, &mce_bad_pages);
52689 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
52690 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
52693 @@ -1192,7 +1192,7 @@ int unpoison_memory(unsigned long pfn)
52695 if (TestClearPageHWPoison(page)) {
52696 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
52697 - atomic_long_sub(nr_pages, &mce_bad_pages);
52698 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
52700 if (PageHuge(page))
52701 clear_page_hwpoison_huge_page(page);
52702 @@ -1301,7 +1301,7 @@ static int soft_offline_huge_page(struct
52705 if (!PageHWPoison(hpage))
52706 - atomic_long_add(1 << compound_order(hpage), &mce_bad_pages);
52707 + atomic_long_add_unchecked(1 << compound_order(hpage), &mce_bad_pages);
52708 set_page_hwpoison_huge_page(hpage);
52709 dequeue_hwpoisoned_huge_page(hpage);
52710 /* keep elevated page count for bad page */
52711 @@ -1428,7 +1428,7 @@ int soft_offline_page(struct page *page,
52715 - atomic_long_add(1, &mce_bad_pages);
52716 + atomic_long_add_unchecked(1, &mce_bad_pages);
52717 SetPageHWPoison(page);
52718 /* keep elevated page count for bad page */
52720 diff -urNp linux-2.6.37/mm/mempolicy.c linux-2.6.37/mm/mempolicy.c
52721 --- linux-2.6.37/mm/mempolicy.c 2011-01-04 19:50:19.000000000 -0500
52722 +++ linux-2.6.37/mm/mempolicy.c 2011-01-17 02:41:02.000000000 -0500
52723 @@ -642,6 +642,10 @@ static int mbind_range(struct mm_struct
52724 unsigned long vmstart;
52725 unsigned long vmend;
52727 +#ifdef CONFIG_PAX_SEGMEXEC
52728 + struct vm_area_struct *vma_m;
52731 vma = find_vma_prev(mm, start, &prev);
52732 if (!vma || vma->vm_start > start)
52734 @@ -672,6 +676,16 @@ static int mbind_range(struct mm_struct
52735 err = policy_vma(vma, new_pol);
52739 +#ifdef CONFIG_PAX_SEGMEXEC
52740 + vma_m = pax_find_mirror_vma(vma);
52742 + err = policy_vma(vma_m, new_pol);
52751 @@ -1104,6 +1118,17 @@ static long do_mbind(unsigned long start
52756 +#ifdef CONFIG_PAX_SEGMEXEC
52757 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
52758 + if (end > SEGMEXEC_TASK_SIZE)
52763 + if (end > TASK_SIZE)
52769 @@ -1324,6 +1349,14 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pi
52773 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52774 + if (mm != current->mm &&
52775 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
52782 * Check if this process has the right to modify the specified
52783 * process. The right exists if the process has administrative
52784 @@ -1333,8 +1366,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pi
52786 tcred = __task_cred(task);
52787 if (cred->euid != tcred->suid && cred->euid != tcred->uid &&
52788 - cred->uid != tcred->suid && cred->uid != tcred->uid &&
52789 - !capable(CAP_SYS_NICE)) {
52790 + cred->uid != tcred->suid && !capable(CAP_SYS_NICE)) {
52794 @@ -2632,7 +2664,7 @@ int show_numa_map(struct seq_file *m, vo
52797 seq_printf(m, " file=");
52798 - seq_path(m, &file->f_path, "\n\t= ");
52799 + seq_path(m, &file->f_path, "\n\t\\= ");
52800 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
52801 seq_printf(m, " heap");
52802 } else if (vma->vm_start <= mm->start_stack &&
52803 diff -urNp linux-2.6.37/mm/migrate.c linux-2.6.37/mm/migrate.c
52804 --- linux-2.6.37/mm/migrate.c 2011-01-04 19:50:19.000000000 -0500
52805 +++ linux-2.6.37/mm/migrate.c 2011-01-17 02:41:02.000000000 -0500
52806 @@ -1299,6 +1299,14 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid,
52810 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52811 + if (mm != current->mm &&
52812 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
52819 * Check if this process has the right to modify the specified
52820 * process. The right exists if the process has administrative
52821 @@ -1308,8 +1316,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid,
52823 tcred = __task_cred(task);
52824 if (cred->euid != tcred->suid && cred->euid != tcred->uid &&
52825 - cred->uid != tcred->suid && cred->uid != tcred->uid &&
52826 - !capable(CAP_SYS_NICE)) {
52827 + cred->uid != tcred->suid && !capable(CAP_SYS_NICE)) {
52831 diff -urNp linux-2.6.37/mm/mlock.c linux-2.6.37/mm/mlock.c
52832 --- linux-2.6.37/mm/mlock.c 2011-01-04 19:50:19.000000000 -0500
52833 +++ linux-2.6.37/mm/mlock.c 2011-01-17 02:41:02.000000000 -0500
52835 #include <linux/pagemap.h>
52836 #include <linux/mempolicy.h>
52837 #include <linux/syscalls.h>
52838 +#include <linux/security.h>
52839 #include <linux/sched.h>
52840 #include <linux/module.h>
52841 #include <linux/rmap.h>
52842 @@ -135,13 +136,6 @@ void munlock_vma_page(struct page *page)
52846 -static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
52848 - return (vma->vm_flags & VM_GROWSDOWN) &&
52849 - (vma->vm_start == addr) &&
52850 - !vma_stack_continue(vma->vm_prev, addr);
52854 * __mlock_vma_pages_range() - mlock a range of pages in the vma.
52856 @@ -174,12 +168,6 @@ static long __mlock_vma_pages_range(stru
52857 if (vma->vm_flags & VM_WRITE)
52858 gup_flags |= FOLL_WRITE;
52860 - /* We don't try to access the guard page of a stack vma */
52861 - if (stack_guard_page(vma, start)) {
52862 - addr += PAGE_SIZE;
52866 while (nr_pages > 0) {
52869 @@ -445,6 +433,9 @@ static int do_mlock(unsigned long start,
52873 + if (end > TASK_SIZE)
52876 vma = find_vma_prev(current->mm, start, &prev);
52877 if (!vma || vma->vm_start > start)
52879 @@ -455,6 +446,11 @@ static int do_mlock(unsigned long start,
52880 for (nstart = start ; ; ) {
52881 unsigned int newflags;
52883 +#ifdef CONFIG_PAX_SEGMEXEC
52884 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
52888 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
52890 newflags = vma->vm_flags | VM_LOCKED;
52891 @@ -504,6 +500,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, st
52892 lock_limit >>= PAGE_SHIFT;
52894 /* check against resource limits */
52895 + gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
52896 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
52897 error = do_mlock(start, len, 1);
52898 up_write(¤t->mm->mmap_sem);
52899 @@ -525,17 +522,23 @@ SYSCALL_DEFINE2(munlock, unsigned long,
52900 static int do_mlockall(int flags)
52902 struct vm_area_struct * vma, * prev = NULL;
52903 - unsigned int def_flags = 0;
52905 if (flags & MCL_FUTURE)
52906 - def_flags = VM_LOCKED;
52907 - current->mm->def_flags = def_flags;
52908 + current->mm->def_flags |= VM_LOCKED;
52910 + current->mm->def_flags &= ~VM_LOCKED;
52911 if (flags == MCL_FUTURE)
52914 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
52915 - unsigned int newflags;
52916 + unsigned long newflags;
52918 +#ifdef CONFIG_PAX_SEGMEXEC
52919 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
52923 + BUG_ON(vma->vm_end > TASK_SIZE);
52924 newflags = vma->vm_flags | VM_LOCKED;
52925 if (!(flags & MCL_CURRENT))
52926 newflags &= ~VM_LOCKED;
52927 @@ -567,6 +570,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
52928 lock_limit >>= PAGE_SHIFT;
52931 + gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
52932 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
52933 capable(CAP_IPC_LOCK))
52934 ret = do_mlockall(flags);
52935 diff -urNp linux-2.6.37/mm/mmap.c linux-2.6.37/mm/mmap.c
52936 --- linux-2.6.37/mm/mmap.c 2011-01-04 19:50:19.000000000 -0500
52937 +++ linux-2.6.37/mm/mmap.c 2011-01-17 02:41:02.000000000 -0500
52939 #define arch_rebalance_pgtables(addr, len) (addr)
52942 +static inline void verify_mm_writelocked(struct mm_struct *mm)
52944 +#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
52945 + if (unlikely(down_read_trylock(&mm->mmap_sem))) {
52946 + up_read(&mm->mmap_sem);
52952 static void unmap_region(struct mm_struct *mm,
52953 struct vm_area_struct *vma, struct vm_area_struct *prev,
52954 unsigned long start, unsigned long end);
52955 @@ -70,22 +80,32 @@ static void unmap_region(struct mm_struc
52956 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
52959 -pgprot_t protection_map[16] = {
52960 +pgprot_t protection_map[16] __read_only = {
52961 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
52962 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
52965 pgprot_t vm_get_page_prot(unsigned long vm_flags)
52967 - return __pgprot(pgprot_val(protection_map[vm_flags &
52968 + pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
52969 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
52970 pgprot_val(arch_vm_get_page_prot(vm_flags)));
52972 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
52973 + if (!(__supported_pte_mask & _PAGE_NX) &&
52974 + (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
52975 + (vm_flags & (VM_READ | VM_WRITE)))
52976 + prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
52981 EXPORT_SYMBOL(vm_get_page_prot);
52983 int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
52984 int sysctl_overcommit_ratio = 50; /* default is 50% */
52985 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
52986 +unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
52987 struct percpu_counter vm_committed_as;
52990 @@ -231,6 +251,7 @@ static struct vm_area_struct *remove_vma
52991 struct vm_area_struct *next = vma->vm_next;
52994 + BUG_ON(vma->vm_mirror);
52995 if (vma->vm_ops && vma->vm_ops->close)
52996 vma->vm_ops->close(vma);
52997 if (vma->vm_file) {
52998 @@ -267,6 +288,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
52999 * not page aligned -Ram Gupta
53001 rlim = rlimit(RLIMIT_DATA);
53002 + gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
53003 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
53004 (mm->end_data - mm->start_data) > rlim)
53006 @@ -708,6 +730,12 @@ static int
53007 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
53008 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
53011 +#ifdef CONFIG_PAX_SEGMEXEC
53012 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
53016 if (is_mergeable_vma(vma, file, vm_flags) &&
53017 is_mergeable_anon_vma(anon_vma, vma->anon_vma)) {
53018 if (vma->vm_pgoff == vm_pgoff)
53019 @@ -727,6 +755,12 @@ static int
53020 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
53021 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
53024 +#ifdef CONFIG_PAX_SEGMEXEC
53025 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
53029 if (is_mergeable_vma(vma, file, vm_flags) &&
53030 is_mergeable_anon_vma(anon_vma, vma->anon_vma)) {
53032 @@ -769,13 +803,20 @@ can_vma_merge_after(struct vm_area_struc
53033 struct vm_area_struct *vma_merge(struct mm_struct *mm,
53034 struct vm_area_struct *prev, unsigned long addr,
53035 unsigned long end, unsigned long vm_flags,
53036 - struct anon_vma *anon_vma, struct file *file,
53037 + struct anon_vma *anon_vma, struct file *file,
53038 pgoff_t pgoff, struct mempolicy *policy)
53040 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
53041 struct vm_area_struct *area, *next;
53044 +#ifdef CONFIG_PAX_SEGMEXEC
53045 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
53046 + struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
53048 + BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
53052 * We later require that vma->vm_flags == vm_flags,
53053 * so this tests vma->vm_flags & VM_SPECIAL, too.
53054 @@ -791,6 +832,15 @@ struct vm_area_struct *vma_merge(struct
53055 if (next && next->vm_end == end) /* cases 6, 7, 8 */
53056 next = next->vm_next;
53058 +#ifdef CONFIG_PAX_SEGMEXEC
53060 + prev_m = pax_find_mirror_vma(prev);
53062 + area_m = pax_find_mirror_vma(area);
53064 + next_m = pax_find_mirror_vma(next);
53068 * Can it merge with the predecessor?
53070 @@ -810,9 +860,24 @@ struct vm_area_struct *vma_merge(struct
53072 err = vma_adjust(prev, prev->vm_start,
53073 next->vm_end, prev->vm_pgoff, NULL);
53074 - } else /* cases 2, 5, 7 */
53076 +#ifdef CONFIG_PAX_SEGMEXEC
53077 + if (!err && prev_m)
53078 + err = vma_adjust(prev_m, prev_m->vm_start,
53079 + next_m->vm_end, prev_m->vm_pgoff, NULL);
53082 + } else { /* cases 2, 5, 7 */
53083 err = vma_adjust(prev, prev->vm_start,
53084 end, prev->vm_pgoff, NULL);
53086 +#ifdef CONFIG_PAX_SEGMEXEC
53087 + if (!err && prev_m)
53088 + err = vma_adjust(prev_m, prev_m->vm_start,
53089 + end_m, prev_m->vm_pgoff, NULL);
53096 @@ -825,12 +890,27 @@ struct vm_area_struct *vma_merge(struct
53097 mpol_equal(policy, vma_policy(next)) &&
53098 can_vma_merge_before(next, vm_flags,
53099 anon_vma, file, pgoff+pglen)) {
53100 - if (prev && addr < prev->vm_end) /* case 4 */
53101 + if (prev && addr < prev->vm_end) { /* case 4 */
53102 err = vma_adjust(prev, prev->vm_start,
53103 addr, prev->vm_pgoff, NULL);
53104 - else /* cases 3, 8 */
53106 +#ifdef CONFIG_PAX_SEGMEXEC
53107 + if (!err && prev_m)
53108 + err = vma_adjust(prev_m, prev_m->vm_start,
53109 + addr_m, prev_m->vm_pgoff, NULL);
53112 + } else { /* cases 3, 8 */
53113 err = vma_adjust(area, addr, next->vm_end,
53114 next->vm_pgoff - pglen, NULL);
53116 +#ifdef CONFIG_PAX_SEGMEXEC
53117 + if (!err && area_m)
53118 + err = vma_adjust(area_m, addr_m, next_m->vm_end,
53119 + next_m->vm_pgoff - pglen, NULL);
53126 @@ -945,14 +1025,11 @@ none:
53127 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
53128 struct file *file, long pages)
53130 - const unsigned long stack_flags
53131 - = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
53134 mm->shared_vm += pages;
53135 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
53136 mm->exec_vm += pages;
53137 - } else if (flags & stack_flags)
53138 + } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
53139 mm->stack_vm += pages;
53140 if (flags & (VM_RESERVED|VM_IO))
53141 mm->reserved_vm += pages;
53142 @@ -979,7 +1056,7 @@ unsigned long do_mmap_pgoff(struct file
53143 * (the exception is when the underlying filesystem is noexec
53144 * mounted, in which case we dont add PROT_EXEC.)
53146 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
53147 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
53148 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
53151 @@ -1005,7 +1082,7 @@ unsigned long do_mmap_pgoff(struct file
53152 /* Obtain the address to map to. we verify (or select) it and ensure
53153 * that it represents a valid section of the address space.
53155 - addr = get_unmapped_area(file, addr, len, pgoff, flags);
53156 + addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
53157 if (addr & ~PAGE_MASK)
53160 @@ -1016,6 +1093,31 @@ unsigned long do_mmap_pgoff(struct file
53161 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
53162 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
53164 +#ifdef CONFIG_PAX_MPROTECT
53165 + if (mm->pax_flags & MF_PAX_MPROTECT) {
53166 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
53167 + gr_log_rwxmmap(file);
53169 +#ifdef CONFIG_PAX_EMUPLT
53170 + vm_flags &= ~VM_EXEC;
53177 + if (!(vm_flags & VM_EXEC))
53178 + vm_flags &= ~VM_MAYEXEC;
53180 + vm_flags &= ~VM_MAYWRITE;
53184 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
53185 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
53186 + vm_flags &= ~VM_PAGEEXEC;
53189 if (flags & MAP_LOCKED)
53190 if (!can_do_mlock())
53192 @@ -1027,6 +1129,7 @@ unsigned long do_mmap_pgoff(struct file
53193 locked += mm->locked_vm;
53194 lock_limit = rlimit(RLIMIT_MEMLOCK);
53195 lock_limit >>= PAGE_SHIFT;
53196 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
53197 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
53200 @@ -1097,6 +1200,9 @@ unsigned long do_mmap_pgoff(struct file
53204 + if (!gr_acl_handle_mmap(file, prot))
53207 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
53209 EXPORT_SYMBOL(do_mmap_pgoff);
53210 @@ -1174,10 +1280,10 @@ SYSCALL_DEFINE1(old_mmap, struct mmap_ar
53212 int vma_wants_writenotify(struct vm_area_struct *vma)
53214 - unsigned int vm_flags = vma->vm_flags;
53215 + unsigned long vm_flags = vma->vm_flags;
53217 /* If it was private or non-writable, the write bit is already clear */
53218 - if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
53219 + if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
53222 /* The backer wishes to know when pages are first written to? */
53223 @@ -1226,14 +1332,24 @@ unsigned long mmap_region(struct file *f
53224 unsigned long charged = 0;
53225 struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
53227 +#ifdef CONFIG_PAX_SEGMEXEC
53228 + struct vm_area_struct *vma_m = NULL;
53232 + * mm->mmap_sem is required to protect against another thread
53233 + * changing the mappings in case we sleep.
53235 + verify_mm_writelocked(mm);
53237 /* Clear old maps */
53240 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
53241 if (vma && vma->vm_start < addr + len) {
53242 if (do_munmap(mm, addr, len))
53244 - goto munmap_back;
53245 + vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
53246 + BUG_ON(vma && vma->vm_start < addr + len);
53249 /* Check against address space limit. */
53250 @@ -1282,6 +1398,16 @@ munmap_back:
53254 +#ifdef CONFIG_PAX_SEGMEXEC
53255 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
53256 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
53265 vma->vm_start = addr;
53266 vma->vm_end = addr + len;
53267 @@ -1305,6 +1431,19 @@ munmap_back:
53268 error = file->f_op->mmap(file, vma);
53270 goto unmap_and_free_vma;
53272 +#ifdef CONFIG_PAX_SEGMEXEC
53273 + if (vma_m && (vm_flags & VM_EXECUTABLE))
53274 + added_exe_file_vma(mm);
53277 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
53278 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
53279 + vma->vm_flags |= VM_PAGEEXEC;
53280 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
53284 if (vm_flags & VM_EXECUTABLE)
53285 added_exe_file_vma(mm);
53287 @@ -1340,6 +1479,11 @@ munmap_back:
53288 vma_link(mm, vma, prev, rb_link, rb_parent);
53289 file = vma->vm_file;
53291 +#ifdef CONFIG_PAX_SEGMEXEC
53293 + BUG_ON(pax_mirror_vma(vma_m, vma));
53296 /* Once vma denies write, undo our temporary denial count */
53297 if (correct_wcount)
53298 atomic_inc(&inode->i_writecount);
53299 @@ -1348,6 +1492,7 @@ out:
53301 mm->total_vm += len >> PAGE_SHIFT;
53302 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
53303 + track_exec_limit(mm, addr, addr + len, vm_flags);
53304 if (vm_flags & VM_LOCKED) {
53305 if (!mlock_vma_pages_range(vma, addr, addr + len))
53306 mm->locked_vm += (len >> PAGE_SHIFT);
53307 @@ -1365,6 +1510,12 @@ unmap_and_free_vma:
53308 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
53312 +#ifdef CONFIG_PAX_SEGMEXEC
53314 + kmem_cache_free(vm_area_cachep, vma_m);
53317 kmem_cache_free(vm_area_cachep, vma);
53320 @@ -1372,6 +1523,33 @@ unacct_error:
53324 +bool check_heap_stack_gap(struct vm_area_struct *vma, unsigned long addr, unsigned long len)
53327 +#ifdef CONFIG_STACK_GROWSUP
53328 + if (addr > sysctl_heap_stack_gap)
53329 + vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
53331 + vma = find_vma(current->mm, 0);
53332 + if (vma && (vma->vm_flags & VM_GROWSUP))
53338 + if (addr + len > vma->vm_start)
53341 + if (vma->vm_flags & VM_GROWSDOWN)
53342 + return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
53343 +#ifdef CONFIG_STACK_GROWSUP
53344 + else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
53345 + return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
53351 /* Get an address range which is currently unmapped.
53352 * For shmat() with addr=0.
53354 @@ -1398,18 +1576,23 @@ arch_get_unmapped_area(struct file *filp
53355 if (flags & MAP_FIXED)
53358 +#ifdef CONFIG_PAX_RANDMMAP
53359 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
53363 addr = PAGE_ALIGN(addr);
53364 - vma = find_vma(mm, addr);
53365 - if (TASK_SIZE - len >= addr &&
53366 - (!vma || addr + len <= vma->vm_start))
53368 + if (TASK_SIZE - len >= addr) {
53369 + vma = find_vma(mm, addr);
53370 + if (check_heap_stack_gap(vma, addr, len))
53374 if (len > mm->cached_hole_size) {
53375 - start_addr = addr = mm->free_area_cache;
53376 + start_addr = addr = mm->free_area_cache;
53378 - start_addr = addr = TASK_UNMAPPED_BASE;
53379 - mm->cached_hole_size = 0;
53380 + start_addr = addr = mm->mmap_base;
53381 + mm->cached_hole_size = 0;
53385 @@ -1420,34 +1603,40 @@ full_search:
53386 * Start a new search - just in case we missed
53389 - if (start_addr != TASK_UNMAPPED_BASE) {
53390 - addr = TASK_UNMAPPED_BASE;
53391 - start_addr = addr;
53392 + if (start_addr != mm->mmap_base) {
53393 + start_addr = addr = mm->mmap_base;
53394 mm->cached_hole_size = 0;
53399 - if (!vma || addr + len <= vma->vm_start) {
53401 - * Remember the place where we stopped the search:
53403 - mm->free_area_cache = addr + len;
53406 + if (check_heap_stack_gap(vma, addr, len))
53408 if (addr + mm->cached_hole_size < vma->vm_start)
53409 mm->cached_hole_size = vma->vm_start - addr;
53410 addr = vma->vm_end;
53414 + * Remember the place where we stopped the search:
53416 + mm->free_area_cache = addr + len;
53421 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
53424 +#ifdef CONFIG_PAX_SEGMEXEC
53425 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
53430 * Is this a new hole at the lowest possible address?
53432 - if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache) {
53433 + if (addr >= mm->mmap_base && addr < mm->free_area_cache) {
53434 mm->free_area_cache = addr;
53435 mm->cached_hole_size = ~0UL;
53437 @@ -1465,7 +1654,7 @@ arch_get_unmapped_area_topdown(struct fi
53439 struct vm_area_struct *vma;
53440 struct mm_struct *mm = current->mm;
53441 - unsigned long addr = addr0;
53442 + unsigned long base = mm->mmap_base, addr = addr0;
53444 /* requested length too big for entire address space */
53445 if (len > TASK_SIZE)
53446 @@ -1474,13 +1663,18 @@ arch_get_unmapped_area_topdown(struct fi
53447 if (flags & MAP_FIXED)
53450 +#ifdef CONFIG_PAX_RANDMMAP
53451 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
53454 /* requesting a specific address */
53456 addr = PAGE_ALIGN(addr);
53457 - vma = find_vma(mm, addr);
53458 - if (TASK_SIZE - len >= addr &&
53459 - (!vma || addr + len <= vma->vm_start))
53461 + if (TASK_SIZE - len >= addr) {
53462 + vma = find_vma(mm, addr);
53463 + if (check_heap_stack_gap(vma, addr, len))
53468 /* check if free_area_cache is useful for us */
53469 @@ -1495,7 +1689,7 @@ arch_get_unmapped_area_topdown(struct fi
53470 /* make sure it can fit in the remaining address space */
53472 vma = find_vma(mm, addr-len);
53473 - if (!vma || addr <= vma->vm_start)
53474 + if (check_heap_stack_gap(vma, addr - len, len))
53475 /* remember the address as a hint for next time */
53476 return (mm->free_area_cache = addr-len);
53478 @@ -1512,7 +1706,7 @@ arch_get_unmapped_area_topdown(struct fi
53479 * return with success:
53481 vma = find_vma(mm, addr);
53482 - if (!vma || addr+len <= vma->vm_start)
53483 + if (check_heap_stack_gap(vma, addr, len))
53484 /* remember the address as a hint for next time */
53485 return (mm->free_area_cache = addr);
53487 @@ -1531,13 +1725,21 @@ bottomup:
53488 * can happen with large stack limits and large mmap()
53491 + mm->mmap_base = TASK_UNMAPPED_BASE;
53493 +#ifdef CONFIG_PAX_RANDMMAP
53494 + if (mm->pax_flags & MF_PAX_RANDMMAP)
53495 + mm->mmap_base += mm->delta_mmap;
53498 + mm->free_area_cache = mm->mmap_base;
53499 mm->cached_hole_size = ~0UL;
53500 - mm->free_area_cache = TASK_UNMAPPED_BASE;
53501 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
53503 * Restore the topdown base:
53505 - mm->free_area_cache = mm->mmap_base;
53506 + mm->mmap_base = base;
53507 + mm->free_area_cache = base;
53508 mm->cached_hole_size = ~0UL;
53511 @@ -1546,6 +1748,12 @@ bottomup:
53513 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
53516 +#ifdef CONFIG_PAX_SEGMEXEC
53517 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
53522 * Is this a new hole at the highest possible address?
53524 @@ -1553,8 +1761,10 @@ void arch_unmap_area_topdown(struct mm_s
53525 mm->free_area_cache = addr;
53527 /* dont allow allocations above current base */
53528 - if (mm->free_area_cache > mm->mmap_base)
53529 + if (mm->free_area_cache > mm->mmap_base) {
53530 mm->free_area_cache = mm->mmap_base;
53531 + mm->cached_hole_size = ~0UL;
53536 @@ -1662,6 +1872,28 @@ out:
53537 return prev ? prev->vm_next : vma;
53540 +#ifdef CONFIG_PAX_SEGMEXEC
53541 +struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
53543 + struct vm_area_struct *vma_m;
53545 + BUG_ON(!vma || vma->vm_start >= vma->vm_end);
53546 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
53547 + BUG_ON(vma->vm_mirror);
53550 + BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
53551 + vma_m = vma->vm_mirror;
53552 + BUG_ON(!vma_m || vma_m->vm_mirror != vma);
53553 + BUG_ON(vma->vm_file != vma_m->vm_file);
53554 + BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
53555 + BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
53556 + BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
53557 + BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED | VM_RESERVED));
53563 * Verify that the stack growth is acceptable and
53564 * update accounting. This is shared with both the
53565 @@ -1678,6 +1910,7 @@ static int acct_stack_growth(struct vm_a
53568 /* Stack limit test */
53569 + gr_learn_resource(current, RLIMIT_STACK, size, 1);
53570 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
53573 @@ -1688,6 +1921,7 @@ static int acct_stack_growth(struct vm_a
53574 locked = mm->locked_vm + grow;
53575 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
53576 limit >>= PAGE_SHIFT;
53577 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
53578 if (locked > limit && !capable(CAP_IPC_LOCK))
53581 @@ -1718,37 +1952,48 @@ static int acct_stack_growth(struct vm_a
53582 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
53583 * vma is the last one with address > vma->vm_end. Have to extend vma.
53585 +#ifndef CONFIG_IA64
53588 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
53593 if (!(vma->vm_flags & VM_GROWSUP))
53596 + /* Also guard against wrapping around to address 0. */
53597 + if (address < PAGE_ALIGN(address+1))
53598 + address = PAGE_ALIGN(address+1);
53603 * We must make sure the anon_vma is allocated
53604 * so that the anon_vma locking is not a noop.
53606 if (unlikely(anon_vma_prepare(vma)))
53608 + locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
53609 + if (locknext && anon_vma_prepare(vma->vm_next))
53611 vma_lock_anon_vma(vma);
53613 + vma_lock_anon_vma(vma->vm_next);
53616 * vma->vm_start/vm_end cannot change under us because the caller
53617 * is required to hold the mmap_sem in read mode. We need the
53618 - * anon_vma lock to serialize against concurrent expand_stacks.
53619 - * Also guard against wrapping around to address 0.
53620 + * anon_vma locks to serialize against concurrent expand_stacks
53621 + * and expand_upwards.
53623 - if (address < PAGE_ALIGN(address+4))
53624 - address = PAGE_ALIGN(address+4);
53626 - vma_unlock_anon_vma(vma);
53631 /* Somebody else might have raced and expanded it already */
53632 - if (address > vma->vm_end) {
53633 + 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)
53635 + else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
53636 unsigned long size, grow;
53638 size = address - vma->vm_start;
53639 @@ -1760,6 +2005,8 @@ int expand_upwards(struct vm_area_struct
53640 perf_event_mmap(vma);
53644 + vma_unlock_anon_vma(vma->vm_next);
53645 vma_unlock_anon_vma(vma);
53648 @@ -1772,6 +2019,8 @@ static int expand_downwards(struct vm_ar
53649 unsigned long address)
53652 + bool lockprev = false;
53653 + struct vm_area_struct *prev;
53656 * We must make sure the anon_vma is allocated
53657 @@ -1785,6 +2034,15 @@ static int expand_downwards(struct vm_ar
53661 + prev = vma->vm_prev;
53662 +#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
53663 + lockprev = prev && (prev->vm_flags & VM_GROWSUP);
53665 + if (lockprev && anon_vma_prepare(prev))
53668 + vma_lock_anon_vma(prev);
53670 vma_lock_anon_vma(vma);
53673 @@ -1794,9 +2052,17 @@ static int expand_downwards(struct vm_ar
53676 /* Somebody else might have raced and expanded it already */
53677 - if (address < vma->vm_start) {
53678 + if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
53680 + else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
53681 unsigned long size, grow;
53683 +#ifdef CONFIG_PAX_SEGMEXEC
53684 + struct vm_area_struct *vma_m;
53686 + vma_m = pax_find_mirror_vma(vma);
53689 size = vma->vm_end - address;
53690 grow = (vma->vm_start - address) >> PAGE_SHIFT;
53692 @@ -1804,10 +2070,21 @@ static int expand_downwards(struct vm_ar
53694 vma->vm_start = address;
53695 vma->vm_pgoff -= grow;
53696 + track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
53698 +#ifdef CONFIG_PAX_SEGMEXEC
53700 + vma_m->vm_start -= grow << PAGE_SHIFT;
53701 + vma_m->vm_pgoff -= grow;
53705 perf_event_mmap(vma);
53708 vma_unlock_anon_vma(vma);
53710 + vma_unlock_anon_vma(prev);
53714 @@ -1881,6 +2158,13 @@ static void remove_vma_list(struct mm_st
53716 long nrpages = vma_pages(vma);
53718 +#ifdef CONFIG_PAX_SEGMEXEC
53719 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
53720 + vma = remove_vma(vma);
53725 mm->total_vm -= nrpages;
53726 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
53727 vma = remove_vma(vma);
53728 @@ -1926,6 +2210,16 @@ detach_vmas_to_be_unmapped(struct mm_str
53729 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
53730 vma->vm_prev = NULL;
53733 +#ifdef CONFIG_PAX_SEGMEXEC
53734 + if (vma->vm_mirror) {
53735 + BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
53736 + vma->vm_mirror->vm_mirror = NULL;
53737 + vma->vm_mirror->vm_flags &= ~VM_EXEC;
53738 + vma->vm_mirror = NULL;
53742 rb_erase(&vma->vm_rb, &mm->mm_rb);
53745 @@ -1954,14 +2248,33 @@ static int __split_vma(struct mm_struct
53746 struct vm_area_struct *new;
53749 +#ifdef CONFIG_PAX_SEGMEXEC
53750 + struct vm_area_struct *vma_m, *new_m = NULL;
53751 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
53754 if (is_vm_hugetlb_page(vma) && (addr &
53755 ~(huge_page_mask(hstate_vma(vma)))))
53758 +#ifdef CONFIG_PAX_SEGMEXEC
53759 + vma_m = pax_find_mirror_vma(vma);
53762 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
53766 +#ifdef CONFIG_PAX_SEGMEXEC
53768 + new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
53770 + kmem_cache_free(vm_area_cachep, new);
53776 /* most fields are the same, copy all, and then fixup */
53779 @@ -1974,6 +2287,22 @@ static int __split_vma(struct mm_struct
53780 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
53783 +#ifdef CONFIG_PAX_SEGMEXEC
53786 + INIT_LIST_HEAD(&new_m->anon_vma_chain);
53787 + new_m->vm_mirror = new;
53788 + new->vm_mirror = new_m;
53791 + new_m->vm_end = addr_m;
53793 + new_m->vm_start = addr_m;
53794 + new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
53799 pol = mpol_dup(vma_policy(vma));
53801 err = PTR_ERR(pol);
53802 @@ -1999,6 +2328,42 @@ static int __split_vma(struct mm_struct
53804 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
53806 +#ifdef CONFIG_PAX_SEGMEXEC
53807 + if (!err && vma_m) {
53808 + if (anon_vma_clone(new_m, vma_m))
53809 + goto out_free_mpol;
53812 + vma_set_policy(new_m, pol);
53814 + if (new_m->vm_file) {
53815 + get_file(new_m->vm_file);
53816 + if (vma_m->vm_flags & VM_EXECUTABLE)
53817 + added_exe_file_vma(mm);
53820 + if (new_m->vm_ops && new_m->vm_ops->open)
53821 + new_m->vm_ops->open(new_m);
53824 + err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
53825 + ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
53827 + err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
53830 + if (new_m->vm_ops && new_m->vm_ops->close)
53831 + new_m->vm_ops->close(new_m);
53832 + if (new_m->vm_file) {
53833 + if (vma_m->vm_flags & VM_EXECUTABLE)
53834 + removed_exe_file_vma(mm);
53835 + fput(new_m->vm_file);
53845 @@ -2011,10 +2376,18 @@ static int __split_vma(struct mm_struct
53846 removed_exe_file_vma(mm);
53847 fput(new->vm_file);
53849 - unlink_anon_vmas(new);
53854 +#ifdef CONFIG_PAX_SEGMEXEC
53856 + unlink_anon_vmas(new_m);
53857 + kmem_cache_free(vm_area_cachep, new_m);
53861 + unlink_anon_vmas(new);
53862 kmem_cache_free(vm_area_cachep, new);
53865 @@ -2027,6 +2400,15 @@ static int __split_vma(struct mm_struct
53866 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
53867 unsigned long addr, int new_below)
53870 +#ifdef CONFIG_PAX_SEGMEXEC
53871 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
53872 + BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
53873 + if (mm->map_count >= sysctl_max_map_count-1)
53878 if (mm->map_count >= sysctl_max_map_count)
53881 @@ -2038,11 +2420,30 @@ int split_vma(struct mm_struct *mm, stru
53882 * work. This now handles partial unmappings.
53883 * Jeremy Fitzhardinge <jeremy@goop.org>
53885 +#ifdef CONFIG_PAX_SEGMEXEC
53886 +int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
53888 + int ret = __do_munmap(mm, start, len);
53889 + if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
53892 + return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
53895 +int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
53897 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
53901 struct vm_area_struct *vma, *prev, *last;
53904 + * mm->mmap_sem is required to protect against another thread
53905 + * changing the mappings in case we sleep.
53907 + verify_mm_writelocked(mm);
53909 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
53912 @@ -2116,6 +2517,8 @@ int do_munmap(struct mm_struct *mm, unsi
53913 /* Fix up all other VM information */
53914 remove_vma_list(mm, vma);
53916 + track_exec_limit(mm, start, end, 0UL);
53921 @@ -2128,22 +2531,18 @@ SYSCALL_DEFINE2(munmap, unsigned long, a
53923 profile_munmap(addr);
53925 +#ifdef CONFIG_PAX_SEGMEXEC
53926 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
53927 + (len > SEGMEXEC_TASK_SIZE || addr > SEGMEXEC_TASK_SIZE-len))
53931 down_write(&mm->mmap_sem);
53932 ret = do_munmap(mm, addr, len);
53933 up_write(&mm->mmap_sem);
53937 -static inline void verify_mm_writelocked(struct mm_struct *mm)
53939 -#ifdef CONFIG_DEBUG_VM
53940 - if (unlikely(down_read_trylock(&mm->mmap_sem))) {
53942 - up_read(&mm->mmap_sem);
53948 * this is really a simplified "do_mmap". it only handles
53949 * anonymous maps. eventually we may be able to do some
53950 @@ -2157,6 +2556,7 @@ unsigned long do_brk(unsigned long addr,
53951 struct rb_node ** rb_link, * rb_parent;
53952 pgoff_t pgoff = addr >> PAGE_SHIFT;
53954 + unsigned long charged;
53956 len = PAGE_ALIGN(len);
53958 @@ -2168,16 +2568,30 @@ unsigned long do_brk(unsigned long addr,
53960 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
53962 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
53963 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
53964 + flags &= ~VM_EXEC;
53966 +#ifdef CONFIG_PAX_MPROTECT
53967 + if (mm->pax_flags & MF_PAX_MPROTECT)
53968 + flags &= ~VM_MAYEXEC;
53974 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
53975 if (error & ~PAGE_MASK)
53978 + charged = len >> PAGE_SHIFT;
53981 * mlock MCL_FUTURE?
53983 if (mm->def_flags & VM_LOCKED) {
53984 unsigned long locked, lock_limit;
53985 - locked = len >> PAGE_SHIFT;
53986 + locked = charged;
53987 locked += mm->locked_vm;
53988 lock_limit = rlimit(RLIMIT_MEMLOCK);
53989 lock_limit >>= PAGE_SHIFT;
53990 @@ -2194,22 +2608,22 @@ unsigned long do_brk(unsigned long addr,
53992 * Clear old maps. this also does some error checking for us
53995 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
53996 if (vma && vma->vm_start < addr + len) {
53997 if (do_munmap(mm, addr, len))
53999 - goto munmap_back;
54000 + vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
54001 + BUG_ON(vma && vma->vm_start < addr + len);
54004 /* Check against address space limits *after* clearing old maps... */
54005 - if (!may_expand_vm(mm, len >> PAGE_SHIFT))
54006 + if (!may_expand_vm(mm, charged))
54009 if (mm->map_count > sysctl_max_map_count)
54012 - if (security_vm_enough_memory(len >> PAGE_SHIFT))
54013 + if (security_vm_enough_memory(charged))
54016 /* Can we just expand an old private anonymous mapping? */
54017 @@ -2223,7 +2637,7 @@ unsigned long do_brk(unsigned long addr,
54019 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
54021 - vm_unacct_memory(len >> PAGE_SHIFT);
54022 + vm_unacct_memory(charged);
54026 @@ -2237,11 +2651,12 @@ unsigned long do_brk(unsigned long addr,
54027 vma_link(mm, vma, prev, rb_link, rb_parent);
54029 perf_event_mmap(vma);
54030 - mm->total_vm += len >> PAGE_SHIFT;
54031 + mm->total_vm += charged;
54032 if (flags & VM_LOCKED) {
54033 if (!mlock_vma_pages_range(vma, addr, addr + len))
54034 - mm->locked_vm += (len >> PAGE_SHIFT);
54035 + mm->locked_vm += charged;
54037 + track_exec_limit(mm, addr, addr + len, flags);
54041 @@ -2288,8 +2703,10 @@ void exit_mmap(struct mm_struct *mm)
54042 * Walk the list again, actually closing and freeing it,
54043 * with preemption enabled, without holding any MM locks.
54047 + vma->vm_mirror = NULL;
54048 vma = remove_vma(vma);
54051 BUG_ON(mm->nr_ptes > (FIRST_USER_ADDRESS+PMD_SIZE-1)>>PMD_SHIFT);
54053 @@ -2303,6 +2720,13 @@ int insert_vm_struct(struct mm_struct *
54054 struct vm_area_struct * __vma, * prev;
54055 struct rb_node ** rb_link, * rb_parent;
54057 +#ifdef CONFIG_PAX_SEGMEXEC
54058 + struct vm_area_struct *vma_m = NULL;
54061 + if (security_file_mmap(NULL, 0, 0, 0, vma->vm_start, 1))
54065 * The vm_pgoff of a purely anonymous vma should be irrelevant
54066 * until its first write fault, when page's anon_vma and index
54067 @@ -2325,7 +2749,22 @@ int insert_vm_struct(struct mm_struct *
54068 if ((vma->vm_flags & VM_ACCOUNT) &&
54069 security_vm_enough_memory_mm(mm, vma_pages(vma)))
54072 +#ifdef CONFIG_PAX_SEGMEXEC
54073 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
54074 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
54080 vma_link(mm, vma, prev, rb_link, rb_parent);
54082 +#ifdef CONFIG_PAX_SEGMEXEC
54084 + BUG_ON(pax_mirror_vma(vma_m, vma));
54090 @@ -2343,6 +2782,8 @@ struct vm_area_struct *copy_vma(struct v
54091 struct rb_node **rb_link, *rb_parent;
54092 struct mempolicy *pol;
54094 + BUG_ON(vma->vm_mirror);
54097 * If anonymous vma has not yet been faulted, update new pgoff
54098 * to match new location, to increase its chance of merging.
54099 @@ -2392,6 +2833,39 @@ struct vm_area_struct *copy_vma(struct v
54100 kmem_cache_free(vm_area_cachep, new_vma);
54104 +#ifdef CONFIG_PAX_SEGMEXEC
54105 +long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
54107 + struct vm_area_struct *prev_m;
54108 + struct rb_node **rb_link_m, *rb_parent_m;
54109 + struct mempolicy *pol_m;
54111 + BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
54112 + BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
54113 + BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
54115 + INIT_LIST_HEAD(&vma_m->anon_vma_chain);
54116 + if (anon_vma_clone(vma_m, vma))
54118 + pol_m = vma_policy(vma_m);
54120 + vma_set_policy(vma_m, pol_m);
54121 + vma_m->vm_start += SEGMEXEC_TASK_SIZE;
54122 + vma_m->vm_end += SEGMEXEC_TASK_SIZE;
54123 + vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
54124 + vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
54125 + if (vma_m->vm_file)
54126 + get_file(vma_m->vm_file);
54127 + if (vma_m->vm_ops && vma_m->vm_ops->open)
54128 + vma_m->vm_ops->open(vma_m);
54129 + find_vma_prepare(vma->vm_mm, vma_m->vm_start, &prev_m, &rb_link_m, &rb_parent_m);
54130 + vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
54131 + vma_m->vm_mirror = vma;
54132 + vma->vm_mirror = vma_m;
54138 * Return true if the calling process may expand its vm space by the passed
54139 @@ -2403,7 +2877,7 @@ int may_expand_vm(struct mm_struct *mm,
54142 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
54144 + gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
54145 if (cur + npages > lim)
54148 @@ -2474,6 +2948,17 @@ int install_special_mapping(struct mm_st
54149 vma->vm_start = addr;
54150 vma->vm_end = addr + len;
54152 +#ifdef CONFIG_PAX_MPROTECT
54153 + if (mm->pax_flags & MF_PAX_MPROTECT) {
54154 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
54156 + if (!(vm_flags & VM_EXEC))
54157 + vm_flags &= ~VM_MAYEXEC;
54159 + vm_flags &= ~VM_MAYWRITE;
54163 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
54164 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
54166 diff -urNp linux-2.6.37/mm/mprotect.c linux-2.6.37/mm/mprotect.c
54167 --- linux-2.6.37/mm/mprotect.c 2011-01-04 19:50:19.000000000 -0500
54168 +++ linux-2.6.37/mm/mprotect.c 2011-01-17 02:41:02.000000000 -0500
54169 @@ -23,10 +23,16 @@
54170 #include <linux/mmu_notifier.h>
54171 #include <linux/migrate.h>
54172 #include <linux/perf_event.h>
54174 +#ifdef CONFIG_PAX_MPROTECT
54175 +#include <linux/elf.h>
54178 #include <asm/uaccess.h>
54179 #include <asm/pgtable.h>
54180 #include <asm/cacheflush.h>
54181 #include <asm/tlbflush.h>
54182 +#include <asm/mmu_context.h>
54184 #ifndef pgprot_modify
54185 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
54186 @@ -131,6 +137,48 @@ static void change_protection(struct vm_
54187 flush_tlb_range(vma, start, end);
54190 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
54191 +/* called while holding the mmap semaphor for writing except stack expansion */
54192 +void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
54194 + unsigned long oldlimit, newlimit = 0UL;
54196 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
54199 + spin_lock(&mm->page_table_lock);
54200 + oldlimit = mm->context.user_cs_limit;
54201 + if ((prot & VM_EXEC) && oldlimit < end)
54202 + /* USER_CS limit moved up */
54204 + else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
54205 + /* USER_CS limit moved down */
54206 + newlimit = start;
54209 + mm->context.user_cs_limit = newlimit;
54213 + cpus_clear(mm->context.cpu_user_cs_mask);
54214 + cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
54217 + set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
54219 + spin_unlock(&mm->page_table_lock);
54220 + if (newlimit == end) {
54221 + struct vm_area_struct *vma = find_vma(mm, oldlimit);
54223 + for (; vma && vma->vm_start < end; vma = vma->vm_next)
54224 + if (is_vm_hugetlb_page(vma))
54225 + hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
54227 + change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma));
54233 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
54234 unsigned long start, unsigned long end, unsigned long newflags)
54235 @@ -143,11 +191,29 @@ mprotect_fixup(struct vm_area_struct *vm
54237 int dirty_accountable = 0;
54239 +#ifdef CONFIG_PAX_SEGMEXEC
54240 + struct vm_area_struct *vma_m = NULL;
54241 + unsigned long start_m, end_m;
54243 + start_m = start + SEGMEXEC_TASK_SIZE;
54244 + end_m = end + SEGMEXEC_TASK_SIZE;
54247 if (newflags == oldflags) {
54252 + if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
54253 + struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
54255 + if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
54258 + if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
54263 * If we make a private mapping writable we increase our commit;
54264 * but (without finer accounting) cannot reduce our commit if we
54265 @@ -164,6 +230,42 @@ mprotect_fixup(struct vm_area_struct *vm
54269 +#ifdef CONFIG_PAX_SEGMEXEC
54270 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
54271 + if (start != vma->vm_start) {
54272 + error = split_vma(mm, vma, start, 1);
54275 + BUG_ON(!*pprev || (*pprev)->vm_next == vma);
54276 + *pprev = (*pprev)->vm_next;
54279 + if (end != vma->vm_end) {
54280 + error = split_vma(mm, vma, end, 0);
54285 + if (pax_find_mirror_vma(vma)) {
54286 + error = __do_munmap(mm, start_m, end_m - start_m);
54290 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
54295 + vma->vm_flags = newflags;
54296 + error = pax_mirror_vma(vma_m, vma);
54298 + vma->vm_flags = oldflags;
54306 * First try to merge with previous and/or next vma.
54308 @@ -194,9 +296,21 @@ success:
54309 * vm_flags and vm_page_prot are protected by the mmap_sem
54310 * held in write mode.
54313 +#ifdef CONFIG_PAX_SEGMEXEC
54314 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
54315 + pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
54318 vma->vm_flags = newflags;
54320 +#ifdef CONFIG_PAX_MPROTECT
54321 + if (mm->binfmt && mm->binfmt->handle_mprotect)
54322 + mm->binfmt->handle_mprotect(vma, newflags);
54325 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
54326 - vm_get_page_prot(newflags));
54327 + vm_get_page_prot(vma->vm_flags));
54329 if (vma_wants_writenotify(vma)) {
54330 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
54331 @@ -238,6 +352,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long,
54336 +#ifdef CONFIG_PAX_SEGMEXEC
54337 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
54338 + if (end > SEGMEXEC_TASK_SIZE)
54343 + if (end > TASK_SIZE)
54346 if (!arch_validate_prot(prot))
54349 @@ -245,7 +370,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long,
54351 * Does the application expect PROT_READ to imply PROT_EXEC:
54353 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
54354 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
54357 vm_flags = calc_vm_prot_bits(prot);
54358 @@ -277,6 +402,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long,
54359 if (start > vma->vm_start)
54362 +#ifdef CONFIG_PAX_MPROTECT
54363 + if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
54364 + current->mm->binfmt->handle_mprotect(vma, vm_flags);
54367 for (nstart = start ; ; ) {
54368 unsigned long newflags;
54370 @@ -286,6 +416,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long,
54372 /* newflags >> 4 shift VM_MAY% in place of VM_% */
54373 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
54374 + if (prot & (PROT_WRITE | PROT_EXEC))
54375 + gr_log_rwxmprotect(vma->vm_file);
54381 + if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
54385 @@ -300,6 +438,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long,
54386 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
54390 + track_exec_limit(current->mm, nstart, tmp, vm_flags);
54394 if (nstart < prev->vm_end)
54395 diff -urNp linux-2.6.37/mm/mremap.c linux-2.6.37/mm/mremap.c
54396 --- linux-2.6.37/mm/mremap.c 2011-01-04 19:50:19.000000000 -0500
54397 +++ linux-2.6.37/mm/mremap.c 2011-01-17 02:41:02.000000000 -0500
54398 @@ -113,6 +113,12 @@ static void move_ptes(struct vm_area_str
54400 pte = ptep_clear_flush(vma, old_addr, old_pte);
54401 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
54403 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
54404 + if (!(__supported_pte_mask & _PAGE_NX) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
54405 + pte = pte_exprotect(pte);
54408 set_pte_at(mm, new_addr, new_pte, pte);
54411 @@ -272,6 +278,11 @@ static struct vm_area_struct *vma_to_res
54412 if (is_vm_hugetlb_page(vma))
54415 +#ifdef CONFIG_PAX_SEGMEXEC
54416 + if (pax_find_mirror_vma(vma))
54420 /* We can't remap across vm area boundaries */
54421 if (old_len > vma->vm_end - addr)
54423 @@ -321,20 +332,25 @@ static unsigned long mremap_to(unsigned
54424 unsigned long ret = -EINVAL;
54425 unsigned long charged = 0;
54426 unsigned long map_flags;
54427 + unsigned long pax_task_size = TASK_SIZE;
54429 if (new_addr & ~PAGE_MASK)
54432 - if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
54433 +#ifdef CONFIG_PAX_SEGMEXEC
54434 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
54435 + pax_task_size = SEGMEXEC_TASK_SIZE;
54438 + pax_task_size -= PAGE_SIZE;
54440 + if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
54443 /* Check if the location we're moving into overlaps the
54444 * old location at all, and fail if it does.
54446 - if ((new_addr <= addr) && (new_addr+new_len) > addr)
54449 - if ((addr <= new_addr) && (addr+old_len) > new_addr)
54450 + if (addr + old_len > new_addr && new_addr + new_len > addr)
54453 ret = security_file_mmap(NULL, 0, 0, 0, new_addr, 1);
54454 @@ -406,6 +422,7 @@ unsigned long do_mremap(unsigned long ad
54455 struct vm_area_struct *vma;
54456 unsigned long ret = -EINVAL;
54457 unsigned long charged = 0;
54458 + unsigned long pax_task_size = TASK_SIZE;
54460 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
54462 @@ -424,6 +441,17 @@ unsigned long do_mremap(unsigned long ad
54466 +#ifdef CONFIG_PAX_SEGMEXEC
54467 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
54468 + pax_task_size = SEGMEXEC_TASK_SIZE;
54471 + pax_task_size -= PAGE_SIZE;
54473 + if (new_len > pax_task_size || addr > pax_task_size-new_len ||
54474 + old_len > pax_task_size || addr > pax_task_size-old_len)
54477 if (flags & MREMAP_FIXED) {
54478 if (flags & MREMAP_MAYMOVE)
54479 ret = mremap_to(addr, old_len, new_addr, new_len);
54480 @@ -473,6 +501,7 @@ unsigned long do_mremap(unsigned long ad
54484 + track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
54488 @@ -499,7 +528,13 @@ unsigned long do_mremap(unsigned long ad
54489 ret = security_file_mmap(NULL, 0, 0, 0, new_addr, 1);
54493 + map_flags = vma->vm_flags;
54494 ret = move_vma(vma, addr, old_len, new_len, new_addr);
54495 + if (!(ret & ~PAGE_MASK)) {
54496 + track_exec_limit(current->mm, addr, addr + old_len, 0UL);
54497 + track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
54501 if (ret & ~PAGE_MASK)
54502 diff -urNp linux-2.6.37/mm/nommu.c linux-2.6.37/mm/nommu.c
54503 --- linux-2.6.37/mm/nommu.c 2011-01-04 19:50:19.000000000 -0500
54504 +++ linux-2.6.37/mm/nommu.c 2011-01-17 02:41:02.000000000 -0500
54505 @@ -63,7 +63,6 @@ int sysctl_overcommit_memory = OVERCOMMI
54506 int sysctl_overcommit_ratio = 50; /* default is 50% */
54507 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
54508 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
54509 -int heap_stack_gap = 0;
54511 atomic_long_t mmap_pages_allocated;
54513 @@ -831,15 +830,6 @@ struct vm_area_struct *find_vma(struct m
54514 EXPORT_SYMBOL(find_vma);
54518 - * - we don't extend stack VMAs under NOMMU conditions
54520 -struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
54522 - return find_vma(mm, addr);
54526 * expand a stack to a given address
54527 * - not supported under NOMMU conditions
54529 @@ -1561,6 +1551,7 @@ int split_vma(struct mm_struct *mm, stru
54531 /* most fields are the same, copy all, and then fixup */
54533 + INIT_LIST_HEAD(&new->anon_vma_chain);
54534 *region = *vma->vm_region;
54535 new->vm_region = region;
54537 diff -urNp linux-2.6.37/mm/page_alloc.c linux-2.6.37/mm/page_alloc.c
54538 --- linux-2.6.37/mm/page_alloc.c 2011-01-04 19:50:19.000000000 -0500
54539 +++ linux-2.6.37/mm/page_alloc.c 2011-01-17 02:41:02.000000000 -0500
54540 @@ -648,6 +648,10 @@ static bool free_pages_prepare(struct pa
54544 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
54545 + unsigned long index = 1UL << order;
54548 trace_mm_page_free_direct(page, order);
54549 kmemcheck_free_shadow(page, order);
54551 @@ -666,6 +670,12 @@ static bool free_pages_prepare(struct pa
54552 debug_check_no_obj_freed(page_address(page),
54553 PAGE_SIZE << order);
54556 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
54557 + for (; index; --index)
54558 + sanitize_highpage(page + index - 1);
54561 arch_free_page(page, order);
54562 kernel_map_pages(page, 1 << order, 0);
54564 @@ -780,8 +790,10 @@ static int prep_new_page(struct page *pa
54565 arch_alloc_page(page, order);
54566 kernel_map_pages(page, 1 << order, 1);
54568 +#ifndef CONFIG_PAX_MEMORY_SANITIZE
54569 if (gfp_flags & __GFP_ZERO)
54570 prep_zero_page(page, order, gfp_flags);
54573 if (order && (gfp_flags & __GFP_COMP))
54574 prep_compound_page(page, order);
54575 @@ -4014,7 +4026,7 @@ static void __init setup_usemap(struct p
54576 zone->pageblock_flags = alloc_bootmem_node(pgdat, usemapsize);
54579 -static void inline setup_usemap(struct pglist_data *pgdat,
54580 +static inline void setup_usemap(struct pglist_data *pgdat,
54581 struct zone *zone, unsigned long zonesize) {}
54582 #endif /* CONFIG_SPARSEMEM */
54584 diff -urNp linux-2.6.37/mm/percpu.c linux-2.6.37/mm/percpu.c
54585 --- linux-2.6.37/mm/percpu.c 2011-01-04 19:50:19.000000000 -0500
54586 +++ linux-2.6.37/mm/percpu.c 2011-01-17 02:41:02.000000000 -0500
54587 @@ -121,7 +121,7 @@ static unsigned int pcpu_first_unit_cpu
54588 static unsigned int pcpu_last_unit_cpu __read_mostly;
54590 /* the address of the first chunk which starts with the kernel static area */
54591 -void *pcpu_base_addr __read_mostly;
54592 +void *pcpu_base_addr __read_only;
54593 EXPORT_SYMBOL_GPL(pcpu_base_addr);
54595 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
54596 diff -urNp linux-2.6.37/mm/rmap.c linux-2.6.37/mm/rmap.c
54597 --- linux-2.6.37/mm/rmap.c 2011-01-04 19:50:19.000000000 -0500
54598 +++ linux-2.6.37/mm/rmap.c 2011-01-17 02:41:02.000000000 -0500
54599 @@ -117,6 +117,10 @@ int anon_vma_prepare(struct vm_area_stru
54600 struct anon_vma *anon_vma = vma->anon_vma;
54601 struct anon_vma_chain *avc;
54603 +#ifdef CONFIG_PAX_SEGMEXEC
54604 + struct anon_vma_chain *avc_m = NULL;
54608 if (unlikely(!anon_vma)) {
54609 struct mm_struct *mm = vma->vm_mm;
54610 @@ -126,6 +130,12 @@ int anon_vma_prepare(struct vm_area_stru
54614 +#ifdef CONFIG_PAX_SEGMEXEC
54615 + avc_m = anon_vma_chain_alloc();
54617 + goto out_enomem_free_avc;
54620 anon_vma = find_mergeable_anon_vma(vma);
54623 @@ -144,6 +154,21 @@ int anon_vma_prepare(struct vm_area_stru
54624 /* page_table_lock to protect against threads */
54625 spin_lock(&mm->page_table_lock);
54626 if (likely(!vma->anon_vma)) {
54628 +#ifdef CONFIG_PAX_SEGMEXEC
54629 + struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
54632 + BUG_ON(vma_m->anon_vma);
54633 + vma_m->anon_vma = anon_vma;
54634 + avc_m->anon_vma = anon_vma;
54635 + avc_m->vma = vma;
54636 + list_add(&avc_m->same_vma, &vma_m->anon_vma_chain);
54637 + list_add(&avc_m->same_anon_vma, &anon_vma->head);
54642 vma->anon_vma = anon_vma;
54643 avc->anon_vma = anon_vma;
54645 @@ -157,12 +182,24 @@ int anon_vma_prepare(struct vm_area_stru
54647 if (unlikely(allocated))
54648 anon_vma_free(allocated);
54650 +#ifdef CONFIG_PAX_SEGMEXEC
54651 + if (unlikely(avc_m))
54652 + anon_vma_chain_free(avc_m);
54656 anon_vma_chain_free(avc);
54660 out_enomem_free_avc:
54662 +#ifdef CONFIG_PAX_SEGMEXEC
54664 + anon_vma_chain_free(avc_m);
54667 anon_vma_chain_free(avc);
54670 @@ -185,7 +222,7 @@ static void anon_vma_chain_link(struct v
54671 * Attach the anon_vmas from src to dst.
54672 * Returns 0 on success, -ENOMEM on failure.
54674 -int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
54675 +int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
54677 struct anon_vma_chain *avc, *pavc;
54679 @@ -207,7 +244,7 @@ int anon_vma_clone(struct vm_area_struct
54680 * the corresponding VMA in the parent process is attached to.
54681 * Returns 0 on success, non-zero on failure.
54683 -int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
54684 +int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
54686 struct anon_vma_chain *avc;
54687 struct anon_vma *anon_vma;
54688 diff -urNp linux-2.6.37/mm/shmem.c linux-2.6.37/mm/shmem.c
54689 --- linux-2.6.37/mm/shmem.c 2011-01-04 19:50:19.000000000 -0500
54690 +++ linux-2.6.37/mm/shmem.c 2011-01-17 02:41:02.000000000 -0500
54692 #include <linux/percpu_counter.h>
54693 #include <linux/swap.h>
54695 -static struct vfsmount *shm_mnt;
54696 +struct vfsmount *shm_mnt;
54698 #ifdef CONFIG_SHMEM
54700 diff -urNp linux-2.6.37/mm/slab.c linux-2.6.37/mm/slab.c
54701 --- linux-2.6.37/mm/slab.c 2011-01-04 19:50:19.000000000 -0500
54702 +++ linux-2.6.37/mm/slab.c 2011-01-17 02:41:02.000000000 -0500
54703 @@ -284,7 +284,7 @@ struct kmem_list3 {
54704 * Need this for bootstrapping a per node allocator.
54706 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
54707 -struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
54708 +struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
54709 #define CACHE_CACHE 0
54710 #define SIZE_AC MAX_NUMNODES
54711 #define SIZE_L3 (2 * MAX_NUMNODES)
54712 @@ -534,7 +534,7 @@ static inline void *index_to_obj(struct
54713 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
54715 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
54716 - const struct slab *slab, void *obj)
54717 + const struct slab *slab, const void *obj)
54719 u32 offset = (obj - slab->s_mem);
54720 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
54721 @@ -560,14 +560,14 @@ struct cache_names {
54722 static struct cache_names __initdata cache_names[] = {
54723 #define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
54724 #include <linux/kmalloc_sizes.h>
54730 static struct arraycache_init initarray_cache __initdata =
54731 - { {0, BOOT_CPUCACHE_ENTRIES, 1, 0} };
54732 + { {0, BOOT_CPUCACHE_ENTRIES, 1, 0}, {NULL} };
54733 static struct arraycache_init initarray_generic =
54734 - { {0, BOOT_CPUCACHE_ENTRIES, 1, 0} };
54735 + { {0, BOOT_CPUCACHE_ENTRIES, 1, 0}, {NULL} };
54737 /* internal cache of cache description objs */
54738 static struct kmem_cache cache_cache = {
54739 @@ -4557,15 +4557,66 @@ static const struct file_operations proc
54741 static int __init slab_proc_init(void)
54743 - proc_create("slabinfo",S_IWUSR|S_IRUGO,NULL,&proc_slabinfo_operations);
54744 + mode_t gr_mode = S_IRUGO;
54746 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
54747 + gr_mode = S_IRUSR;
54750 + proc_create("slabinfo",S_IWUSR|gr_mode,NULL,&proc_slabinfo_operations);
54751 #ifdef CONFIG_DEBUG_SLAB_LEAK
54752 - proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
54753 + proc_create("slab_allocators", gr_mode, NULL, &proc_slabstats_operations);
54757 module_init(slab_proc_init);
54760 +void check_object_size(const void *ptr, unsigned long n, bool to)
54763 +#ifdef CONFIG_PAX_USERCOPY
54764 + struct kmem_cache *cachep;
54765 + struct slab *slabp;
54766 + struct page *page;
54767 + unsigned int objnr;
54768 + unsigned long offset;
54773 + if (ZERO_OR_NULL_PTR(ptr))
54776 + if (!virt_addr_valid(ptr))
54779 + page = virt_to_head_page(ptr);
54781 + if (!PageSlab(page)) {
54782 + if (object_is_on_stack(ptr, n) == -1)
54787 + cachep = page_get_cache(page);
54788 + slabp = page_get_slab(page);
54789 + objnr = obj_to_index(cachep, slabp, ptr);
54790 + BUG_ON(objnr >= cachep->num);
54791 + offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
54792 + if (offset <= obj_size(cachep) && n <= obj_size(cachep) - offset)
54797 + pax_report_leak_to_user(ptr, n);
54799 + pax_report_overflow_from_user(ptr, n);
54803 +EXPORT_SYMBOL(check_object_size);
54806 * ksize - get the actual amount of memory allocated for a given object
54807 * @objp: Pointer to the object
54808 diff -urNp linux-2.6.37/mm/slob.c linux-2.6.37/mm/slob.c
54809 --- linux-2.6.37/mm/slob.c 2011-01-04 19:50:19.000000000 -0500
54810 +++ linux-2.6.37/mm/slob.c 2011-01-17 02:41:02.000000000 -0500
54812 * If kmalloc is asked for objects of PAGE_SIZE or larger, it calls
54813 * alloc_pages() directly, allocating compound pages so the page order
54814 * does not have to be separately tracked, and also stores the exact
54815 - * allocation size in page->private so that it can be used to accurately
54816 + * allocation size in slob_page->size so that it can be used to accurately
54817 * provide ksize(). These objects are detected in kfree() because slob_page()
54818 * is false for them.
54823 #include <linux/kernel.h>
54824 +#include <linux/sched.h>
54825 #include <linux/slab.h>
54826 #include <linux/mm.h>
54827 #include <linux/swap.h> /* struct reclaim_state */
54828 @@ -102,7 +103,8 @@ struct slob_page {
54829 unsigned long flags; /* mandatory */
54830 atomic_t _count; /* mandatory */
54831 slobidx_t units; /* free units left in page */
54832 - unsigned long pad[2];
54833 + unsigned long pad[1];
54834 + unsigned long size; /* size when >=PAGE_SIZE */
54835 slob_t *free; /* first free slob_t in page */
54836 struct list_head list; /* linked list of free pages */
54838 @@ -135,7 +137,7 @@ static LIST_HEAD(free_slob_large);
54840 static inline int is_slob_page(struct slob_page *sp)
54842 - return PageSlab((struct page *)sp);
54843 + return PageSlab((struct page *)sp) && !sp->size;
54846 static inline void set_slob_page(struct slob_page *sp)
54847 @@ -150,7 +152,7 @@ static inline void clear_slob_page(struc
54849 static inline struct slob_page *slob_page(const void *addr)
54851 - return (struct slob_page *)virt_to_page(addr);
54852 + return (struct slob_page *)virt_to_head_page(addr);
54856 @@ -210,7 +212,7 @@ static void set_slob(slob_t *s, slobidx_
54858 * Return the size of a slob block.
54860 -static slobidx_t slob_units(slob_t *s)
54861 +static slobidx_t slob_units(const slob_t *s)
54865 @@ -220,7 +222,7 @@ static slobidx_t slob_units(slob_t *s)
54867 * Return the next free slob block pointer after this one.
54869 -static slob_t *slob_next(slob_t *s)
54870 +static slob_t *slob_next(const slob_t *s)
54872 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
54874 @@ -235,7 +237,7 @@ static slob_t *slob_next(slob_t *s)
54876 * Returns true if s is the last free block in its page.
54878 -static int slob_last(slob_t *s)
54879 +static int slob_last(const slob_t *s)
54881 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
54883 @@ -254,6 +256,7 @@ static void *slob_new_pages(gfp_t gfp, i
54887 + set_slob_page(page);
54888 return page_address(page);
54891 @@ -370,11 +373,11 @@ static void *slob_alloc(size_t size, gfp
54895 - set_slob_page(sp);
54897 spin_lock_irqsave(&slob_lock, flags);
54898 sp->units = SLOB_UNITS(PAGE_SIZE);
54901 INIT_LIST_HEAD(&sp->list);
54902 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
54903 set_slob_page_free(sp, slob_list);
54904 @@ -476,10 +479,9 @@ out:
54905 * End of slob allocator proper. Begin kmem_cache_alloc and kmalloc frontend.
54908 -void *__kmalloc_node(size_t size, gfp_t gfp, int node)
54909 +static void *__kmalloc_node_align(size_t size, gfp_t gfp, int node, int align)
54912 - int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
54916 lockdep_trace_alloc(gfp);
54917 @@ -492,7 +494,10 @@ void *__kmalloc_node(size_t size, gfp_t
54922 + BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
54923 + BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
54924 + m[0].units = size;
54925 + m[1].units = align;
54926 ret = (void *)m + align;
54928 trace_kmalloc_node(_RET_IP_, ret,
54929 @@ -504,9 +509,9 @@ void *__kmalloc_node(size_t size, gfp_t
54931 ret = slob_new_pages(gfp, order, node);
54933 - struct page *page;
54934 - page = virt_to_page(ret);
54935 - page->private = size;
54936 + struct slob_page *sp;
54937 + sp = slob_page(ret);
54941 trace_kmalloc_node(_RET_IP_, ret,
54942 @@ -516,6 +521,13 @@ void *__kmalloc_node(size_t size, gfp_t
54943 kmemleak_alloc(ret, size, 1, gfp);
54947 +void *__kmalloc_node(size_t size, gfp_t gfp, int node)
54949 + int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
54951 + return __kmalloc_node_align(size, gfp, node, align);
54953 EXPORT_SYMBOL(__kmalloc_node);
54955 void kfree(const void *block)
54956 @@ -531,13 +543,84 @@ void kfree(const void *block)
54957 sp = slob_page(block);
54958 if (is_slob_page(sp)) {
54959 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
54960 - unsigned int *m = (unsigned int *)(block - align);
54961 - slob_free(m, *m + align);
54963 + slob_t *m = (slob_t *)(block - align);
54964 + slob_free(m, m[0].units + align);
54966 + clear_slob_page(sp);
54967 + free_slob_page(sp);
54969 put_page(&sp->page);
54972 EXPORT_SYMBOL(kfree);
54974 +void check_object_size(const void *ptr, unsigned long n, bool to)
54977 +#ifdef CONFIG_PAX_USERCOPY
54978 + struct slob_page *sp;
54979 + const slob_t *free;
54980 + const void *base;
54985 + if (ZERO_OR_NULL_PTR(ptr))
54988 + if (!virt_addr_valid(ptr))
54991 + sp = slob_page(ptr);
54992 + if (!PageSlab((struct page*)sp)) {
54993 + if (object_is_on_stack(ptr, n) == -1)
54999 + base = page_address(&sp->page);
55000 + if (base <= ptr && n <= sp->size - (ptr - base))
55005 + /* some tricky double walking to find the chunk */
55006 + base = (void *)((unsigned long)ptr & PAGE_MASK);
55009 + while (!slob_last(free) && (void *)free <= ptr) {
55010 + base = free + slob_units(free);
55011 + free = slob_next(free);
55014 + while (base < (void *)free) {
55015 + slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
55016 + int size = SLOB_UNIT * SLOB_UNITS(m + align);
55019 + if (ptr < base + align)
55022 + offset = ptr - base - align;
55023 + if (offset < m) {
55024 + if (n <= m - offset)
55033 + pax_report_leak_to_user(ptr, n);
55035 + pax_report_overflow_from_user(ptr, n);
55039 +EXPORT_SYMBOL(check_object_size);
55041 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
55042 size_t ksize(const void *block)
55044 @@ -550,10 +633,10 @@ size_t ksize(const void *block)
55045 sp = slob_page(block);
55046 if (is_slob_page(sp)) {
55047 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
55048 - unsigned int *m = (unsigned int *)(block - align);
55049 - return SLOB_UNITS(*m) * SLOB_UNIT;
55050 + slob_t *m = (slob_t *)(block - align);
55051 + return SLOB_UNITS(m[0].units) * SLOB_UNIT;
55053 - return sp->page.private;
55056 EXPORT_SYMBOL(ksize);
55058 @@ -608,17 +691,25 @@ void *kmem_cache_alloc_node(struct kmem_
55062 +#ifdef CONFIG_PAX_USERCOPY
55063 + b = __kmalloc_node_align(c->size, flags, node, c->align);
55065 if (c->size < PAGE_SIZE) {
55066 b = slob_alloc(c->size, flags, c->align, node);
55067 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
55068 SLOB_UNITS(c->size) * SLOB_UNIT,
55071 + struct slob_page *sp;
55073 b = slob_new_pages(flags, get_order(c->size), node);
55074 + sp = slob_page(b);
55075 + sp->size = c->size;
55076 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
55077 PAGE_SIZE << get_order(c->size),
55084 @@ -630,10 +721,16 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
55086 static void __kmem_cache_free(void *b, int size)
55088 - if (size < PAGE_SIZE)
55089 + struct slob_page *sp = slob_page(b);
55091 + if (is_slob_page(sp))
55092 slob_free(b, size);
55095 + clear_slob_page(sp);
55096 + free_slob_page(sp);
55098 slob_free_pages(b, get_order(size));
55102 static void kmem_rcu_free(struct rcu_head *head)
55103 @@ -646,14 +743,23 @@ static void kmem_rcu_free(struct rcu_hea
55105 void kmem_cache_free(struct kmem_cache *c, void *b)
55107 + int size = c->size;
55109 +#ifdef CONFIG_PAX_USERCOPY
55110 + if (size + c->align < PAGE_SIZE) {
55111 + size += c->align;
55116 kmemleak_free_recursive(b, c->flags);
55117 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
55118 struct slob_rcu *slob_rcu;
55119 - slob_rcu = b + (c->size - sizeof(struct slob_rcu));
55120 - slob_rcu->size = c->size;
55121 + slob_rcu = b + (size - sizeof(struct slob_rcu));
55122 + slob_rcu->size = size;
55123 call_rcu(&slob_rcu->head, kmem_rcu_free);
55125 - __kmem_cache_free(b, c->size);
55126 + __kmem_cache_free(b, size);
55129 trace_kmem_cache_free(_RET_IP_, b);
55130 diff -urNp linux-2.6.37/mm/slub.c linux-2.6.37/mm/slub.c
55131 --- linux-2.6.37/mm/slub.c 2011-01-04 19:50:19.000000000 -0500
55132 +++ linux-2.6.37/mm/slub.c 2011-01-17 02:41:02.000000000 -0500
55133 @@ -388,7 +388,7 @@ static void print_track(const char *s, s
55137 - printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
55138 + printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
55139 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
55142 @@ -1911,6 +1911,8 @@ void kmem_cache_free(struct kmem_cache *
55144 page = virt_to_head_page(x);
55146 + BUG_ON(!PageSlab(page));
55148 slab_free(s, page, x, _RET_IP_);
55150 trace_kmem_cache_free(_RET_IP_, x);
55151 @@ -1955,7 +1957,7 @@ static int slub_min_objects;
55152 * Merge control. If this is set then no merging of slab caches will occur.
55153 * (Could be removed. This was introduced to pacify the merge skeptics.)
55155 -static int slub_nomerge;
55156 +static int slub_nomerge = 1;
55159 * Calculate the order of allocation given an slab object size.
55160 @@ -2365,7 +2367,7 @@ static int kmem_cache_open(struct kmem_c
55161 * list to avoid pounding the page allocator excessively.
55163 set_min_partial(s, ilog2(s->size));
55165 + atomic_set(&s->refcount, 1);
55167 s->remote_node_defrag_ratio = 1000;
55169 @@ -2506,8 +2508,7 @@ static inline int kmem_cache_close(struc
55170 void kmem_cache_destroy(struct kmem_cache *s)
55172 down_write(&slub_lock);
55174 - if (!s->refcount) {
55175 + if (atomic_dec_and_test(&s->refcount)) {
55176 list_del(&s->list);
55177 if (kmem_cache_close(s)) {
55178 printk(KERN_ERR "SLUB %s: %s called for cache that "
55179 @@ -2717,6 +2718,46 @@ void *__kmalloc_node(size_t size, gfp_t
55180 EXPORT_SYMBOL(__kmalloc_node);
55183 +void check_object_size(const void *ptr, unsigned long n, bool to)
55186 +#ifdef CONFIG_PAX_USERCOPY
55187 + struct page *page;
55188 + struct kmem_cache *s;
55189 + unsigned long offset;
55194 + if (ZERO_OR_NULL_PTR(ptr))
55197 + if (!virt_addr_valid(ptr))
55200 + page = get_object_page(ptr);
55203 + if (object_is_on_stack(ptr, n) == -1)
55209 + offset = (ptr - page_address(page)) % s->size;
55210 + if (offset <= s->objsize && n <= s->objsize - offset)
55215 + pax_report_leak_to_user(ptr, n);
55217 + pax_report_overflow_from_user(ptr, n);
55221 +EXPORT_SYMBOL(check_object_size);
55223 size_t ksize(const void *object)
55226 @@ -2982,7 +3023,7 @@ static void __init kmem_cache_bootstrap_
55229 list_add(&s->list, &slab_caches);
55230 - s->refcount = -1;
55231 + atomic_set(&s->refcount, -1);
55233 for_each_node_state(node, N_NORMAL_MEMORY) {
55234 struct kmem_cache_node *n = get_node(s, node);
55235 @@ -3177,7 +3218,7 @@ static int slab_unmergeable(struct kmem_
55237 * We may have set a slab to be unmergeable during bootstrap.
55239 - if (s->refcount < 0)
55240 + if (atomic_read(&s->refcount) < 0)
55244 @@ -3236,7 +3277,7 @@ struct kmem_cache *kmem_cache_create(con
55245 down_write(&slub_lock);
55246 s = find_mergeable(size, align, flags, name, ctor);
55249 + atomic_inc(&s->refcount);
55251 * Adjust the object sizes so that we clear
55252 * the complete object on kzalloc.
55253 @@ -3245,7 +3286,7 @@ struct kmem_cache *kmem_cache_create(con
55254 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
55256 if (sysfs_slab_alias(s, name)) {
55258 + atomic_dec(&s->refcount);
55261 up_write(&slub_lock);
55262 @@ -3981,7 +4022,7 @@ SLAB_ATTR_RO(ctor);
55264 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
55266 - return sprintf(buf, "%d\n", s->refcount - 1);
55267 + return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
55269 SLAB_ATTR_RO(aliases);
55271 @@ -4718,7 +4759,13 @@ static const struct file_operations proc
55273 static int __init slab_proc_init(void)
55275 - proc_create("slabinfo", S_IRUGO, NULL, &proc_slabinfo_operations);
55276 + mode_t gr_mode = S_IRUGO;
55278 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
55279 + gr_mode = S_IRUSR;
55282 + proc_create("slabinfo", gr_mode, NULL, &proc_slabinfo_operations);
55285 module_init(slab_proc_init);
55286 diff -urNp linux-2.6.37/mm/util.c linux-2.6.37/mm/util.c
55287 --- linux-2.6.37/mm/util.c 2011-01-04 19:50:19.000000000 -0500
55288 +++ linux-2.6.37/mm/util.c 2011-01-17 02:41:02.000000000 -0500
55289 @@ -240,6 +240,12 @@ EXPORT_SYMBOL(strndup_user);
55290 void arch_pick_mmap_layout(struct mm_struct *mm)
55292 mm->mmap_base = TASK_UNMAPPED_BASE;
55294 +#ifdef CONFIG_PAX_RANDMMAP
55295 + if (mm->pax_flags & MF_PAX_RANDMMAP)
55296 + mm->mmap_base += mm->delta_mmap;
55299 mm->get_unmapped_area = arch_get_unmapped_area;
55300 mm->unmap_area = arch_unmap_area;
55302 diff -urNp linux-2.6.37/mm/vmalloc.c linux-2.6.37/mm/vmalloc.c
55303 --- linux-2.6.37/mm/vmalloc.c 2011-01-04 19:50:19.000000000 -0500
55304 +++ linux-2.6.37/mm/vmalloc.c 2011-01-17 02:41:02.000000000 -0500
55305 @@ -39,8 +39,19 @@ static void vunmap_pte_range(pmd_t *pmd,
55307 pte = pte_offset_kernel(pmd, addr);
55309 - pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
55310 - WARN_ON(!pte_none(ptent) && !pte_present(ptent));
55312 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
55313 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
55314 + BUG_ON(!pte_exec(*pte));
55315 + set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
55321 + pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
55322 + WARN_ON(!pte_none(ptent) && !pte_present(ptent));
55324 } while (pte++, addr += PAGE_SIZE, addr != end);
55327 @@ -91,6 +102,7 @@ static int vmap_pte_range(pmd_t *pmd, un
55328 unsigned long end, pgprot_t prot, struct page **pages, int *nr)
55331 + int ret = -ENOMEM;
55334 * nr is a running index into the array which helps higher level
55335 @@ -100,17 +112,30 @@ static int vmap_pte_range(pmd_t *pmd, un
55336 pte = pte_alloc_kernel(pmd, addr);
55340 + pax_open_kernel();
55342 struct page *page = pages[*nr];
55344 - if (WARN_ON(!pte_none(*pte)))
55346 - if (WARN_ON(!page))
55348 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
55349 + if (pgprot_val(prot) & _PAGE_NX)
55352 + if (WARN_ON(!pte_none(*pte))) {
55356 + if (WARN_ON(!page)) {
55360 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
55362 } while (pte++, addr += PAGE_SIZE, addr != end);
55366 + pax_close_kernel();
55370 static int vmap_pmd_range(pud_t *pud, unsigned long addr,
55371 @@ -191,11 +216,20 @@ int is_vmalloc_or_module_addr(const void
55372 * and fall back on vmalloc() if that fails. Others
55373 * just put it in the vmalloc space.
55375 -#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
55376 +#ifdef CONFIG_MODULES
55377 +#ifdef MODULES_VADDR
55378 unsigned long addr = (unsigned long)x;
55379 if (addr >= MODULES_VADDR && addr < MODULES_END)
55383 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
55384 + if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
55390 return is_vmalloc_addr(x);
55393 @@ -216,8 +250,14 @@ struct page *vmalloc_to_page(const void
55395 if (!pgd_none(*pgd)) {
55396 pud_t *pud = pud_offset(pgd, addr);
55398 + if (!pud_large(*pud))
55400 if (!pud_none(*pud)) {
55401 pmd_t *pmd = pmd_offset(pud, addr);
55403 + if (!pmd_large(*pmd))
55405 if (!pmd_none(*pmd)) {
55408 @@ -1243,6 +1283,16 @@ static struct vm_struct *__get_vm_area_n
55409 struct vm_struct *area;
55411 BUG_ON(in_interrupt());
55413 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
55414 + if (flags & VM_KERNEXEC) {
55415 + if (start != VMALLOC_START || end != VMALLOC_END)
55417 + start = (unsigned long)MODULES_EXEC_VADDR;
55418 + end = (unsigned long)MODULES_EXEC_END;
55422 if (flags & VM_IOREMAP) {
55423 int bit = fls(size);
55425 @@ -1468,6 +1518,11 @@ void *vmap(struct page **pages, unsigned
55426 if (count > totalram_pages)
55429 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
55430 + if (!(pgprot_val(prot) & _PAGE_NX))
55431 + flags |= VM_KERNEXEC;
55434 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
55435 __builtin_return_address(0));
55437 @@ -1577,6 +1632,13 @@ static void *__vmalloc_node(unsigned lon
55438 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
55441 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
55442 + if (!(pgprot_val(prot) & _PAGE_NX))
55443 + area = __get_vm_area_node(size, align, VM_ALLOC | VM_KERNEXEC, VMALLOC_START, VMALLOC_END,
55444 + node, gfp_mask, caller);
55448 area = __get_vm_area_node(size, align, VM_ALLOC, VMALLOC_START,
55449 VMALLOC_END, node, gfp_mask, caller);
55451 @@ -1595,6 +1657,7 @@ static void *__vmalloc_node(unsigned lon
55456 void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot)
55458 return __vmalloc_node(size, 1, gfp_mask, prot, -1,
55459 @@ -1618,6 +1681,7 @@ static inline void *__vmalloc_node_flags
55460 * For tight control over page level allocator and protection flags
55461 * use __vmalloc() instead.
55464 void *vmalloc(unsigned long size)
55466 return __vmalloc_node_flags(size, -1, GFP_KERNEL | __GFP_HIGHMEM);
55467 @@ -1634,6 +1698,7 @@ EXPORT_SYMBOL(vmalloc);
55468 * For tight control over page level allocator and protection flags
55469 * use __vmalloc() instead.
55472 void *vzalloc(unsigned long size)
55474 return __vmalloc_node_flags(size, -1,
55475 @@ -1648,6 +1713,7 @@ EXPORT_SYMBOL(vzalloc);
55476 * The resulting memory area is zeroed so it can be mapped to userspace
55477 * without leaking data.
55479 +#undef vmalloc_user
55480 void *vmalloc_user(unsigned long size)
55482 struct vm_struct *area;
55483 @@ -1675,6 +1741,7 @@ EXPORT_SYMBOL(vmalloc_user);
55484 * For tight control over page level allocator and protection flags
55485 * use __vmalloc() instead.
55487 +#undef vmalloc_node
55488 void *vmalloc_node(unsigned long size, int node)
55490 return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL,
55491 @@ -1694,6 +1761,7 @@ EXPORT_SYMBOL(vmalloc_node);
55492 * For tight control over page level allocator and protection flags
55493 * use __vmalloc_node() instead.
55495 +#undef vzalloc_node
55496 void *vzalloc_node(unsigned long size, int node)
55498 return __vmalloc_node_flags(size, node,
55499 @@ -1716,10 +1784,10 @@ EXPORT_SYMBOL(vzalloc_node);
55500 * For tight control over page level allocator and protection flags
55501 * use __vmalloc() instead.
55504 +#undef vmalloc_exec
55505 void *vmalloc_exec(unsigned long size)
55507 - return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
55508 + return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
55509 -1, __builtin_return_address(0));
55512 @@ -1738,6 +1806,7 @@ void *vmalloc_exec(unsigned long size)
55513 * Allocate enough 32bit PA addressable pages to cover @size from the
55514 * page level allocator and map them into contiguous kernel virtual space.
55517 void *vmalloc_32(unsigned long size)
55519 return __vmalloc_node(size, 1, GFP_VMALLOC32, PAGE_KERNEL,
55520 @@ -1752,6 +1821,7 @@ EXPORT_SYMBOL(vmalloc_32);
55521 * The resulting memory area is 32bit addressable and zeroed so it can be
55522 * mapped to userspace without leaking data.
55524 +#undef vmalloc_32_user
55525 void *vmalloc_32_user(unsigned long size)
55527 struct vm_struct *area;
55528 @@ -2016,6 +2086,8 @@ int remap_vmalloc_range(struct vm_area_s
55529 unsigned long uaddr = vma->vm_start;
55530 unsigned long usize = vma->vm_end - vma->vm_start;
55532 + BUG_ON(vma->vm_mirror);
55534 if ((PAGE_SIZE-1) & (unsigned long)addr)
55537 diff -urNp linux-2.6.37/mm/vmstat.c linux-2.6.37/mm/vmstat.c
55538 --- linux-2.6.37/mm/vmstat.c 2011-01-04 19:50:19.000000000 -0500
55539 +++ linux-2.6.37/mm/vmstat.c 2011-01-17 02:41:02.000000000 -0500
55540 @@ -78,7 +78,7 @@ void vm_events_fold_cpu(int cpu)
55542 * vm_stat contains the global counters
55544 -atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
55545 +atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
55546 EXPORT_SYMBOL(vm_stat);
55549 @@ -330,7 +330,7 @@ void refresh_cpu_vm_stats(int cpu)
55550 v = p->vm_stat_diff[i];
55551 p->vm_stat_diff[i] = 0;
55552 local_irq_restore(flags);
55553 - atomic_long_add(v, &zone->vm_stat[i]);
55554 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
55555 global_diff[i] += v;
55557 /* 3 seconds idle till flush */
55558 @@ -368,7 +368,7 @@ void refresh_cpu_vm_stats(int cpu)
55560 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
55561 if (global_diff[i])
55562 - atomic_long_add(global_diff[i], &vm_stat[i]);
55563 + atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
55567 @@ -1066,10 +1066,20 @@ static int __init setup_vmstat(void)
55568 start_cpu_timer(cpu);
55570 #ifdef CONFIG_PROC_FS
55571 - proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
55572 - proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
55573 - proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
55574 - proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
55576 + mode_t gr_mode = S_IRUGO;
55577 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
55578 + gr_mode = S_IRUSR;
55580 + proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
55581 + proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
55582 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
55583 + proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
55585 + proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
55587 + proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
55592 diff -urNp linux-2.6.37/net/8021q/vlan.c linux-2.6.37/net/8021q/vlan.c
55593 --- linux-2.6.37/net/8021q/vlan.c 2011-01-04 19:50:19.000000000 -0500
55594 +++ linux-2.6.37/net/8021q/vlan.c 2011-01-17 02:41:02.000000000 -0500
55595 @@ -588,8 +588,7 @@ static int vlan_ioctl_handler(struct net
55597 if (!capable(CAP_NET_ADMIN))
55599 - if ((args.u.name_type >= 0) &&
55600 - (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
55601 + if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
55602 struct vlan_net *vn;
55604 vn = net_generic(net, vlan_net_id);
55605 diff -urNp linux-2.6.37/net/atm/atm_misc.c linux-2.6.37/net/atm/atm_misc.c
55606 --- linux-2.6.37/net/atm/atm_misc.c 2011-01-04 19:50:19.000000000 -0500
55607 +++ linux-2.6.37/net/atm/atm_misc.c 2011-01-17 02:41:02.000000000 -0500
55608 @@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int
55609 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
55611 atm_return(vcc, truesize);
55612 - atomic_inc(&vcc->stats->rx_drop);
55613 + atomic_inc_unchecked(&vcc->stats->rx_drop);
55616 EXPORT_SYMBOL(atm_charge);
55617 @@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct
55620 atm_return(vcc, guess);
55621 - atomic_inc(&vcc->stats->rx_drop);
55622 + atomic_inc_unchecked(&vcc->stats->rx_drop);
55625 EXPORT_SYMBOL(atm_alloc_charge);
55626 @@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
55628 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
55630 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
55631 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
55633 #undef __HANDLE_ITEM
55635 @@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
55637 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
55639 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
55640 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
55642 #undef __HANDLE_ITEM
55644 diff -urNp linux-2.6.37/net/atm/proc.c linux-2.6.37/net/atm/proc.c
55645 --- linux-2.6.37/net/atm/proc.c 2011-01-04 19:50:19.000000000 -0500
55646 +++ linux-2.6.37/net/atm/proc.c 2011-01-17 02:41:02.000000000 -0500
55647 @@ -45,9 +45,9 @@ static void add_stats(struct seq_file *s
55648 const struct k_atm_aal_stats *stats)
55650 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
55651 - atomic_read(&stats->tx), atomic_read(&stats->tx_err),
55652 - atomic_read(&stats->rx), atomic_read(&stats->rx_err),
55653 - atomic_read(&stats->rx_drop));
55654 + atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
55655 + atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
55656 + atomic_read_unchecked(&stats->rx_drop));
55659 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
55660 @@ -191,7 +191,12 @@ static void vcc_info(struct seq_file *se
55662 struct sock *sk = sk_atm(vcc);
55664 +#ifdef CONFIG_GRKERNSEC_HIDESYM
55665 + seq_printf(seq, "%p ", NULL);
55667 seq_printf(seq, "%p ", vcc);
55671 seq_printf(seq, "Unassigned ");
55673 diff -urNp linux-2.6.37/net/atm/resources.c linux-2.6.37/net/atm/resources.c
55674 --- linux-2.6.37/net/atm/resources.c 2011-01-04 19:50:19.000000000 -0500
55675 +++ linux-2.6.37/net/atm/resources.c 2011-01-17 02:41:02.000000000 -0500
55676 @@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
55677 static void copy_aal_stats(struct k_atm_aal_stats *from,
55678 struct atm_aal_stats *to)
55680 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
55681 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
55683 #undef __HANDLE_ITEM
55685 @@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_
55686 static void subtract_aal_stats(struct k_atm_aal_stats *from,
55687 struct atm_aal_stats *to)
55689 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
55690 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
55692 #undef __HANDLE_ITEM
55694 diff -urNp linux-2.6.37/net/ax25/af_ax25.c linux-2.6.37/net/ax25/af_ax25.c
55695 --- linux-2.6.37/net/ax25/af_ax25.c 2011-01-04 19:50:19.000000000 -0500
55696 +++ linux-2.6.37/net/ax25/af_ax25.c 2011-01-17 02:41:02.000000000 -0500
55697 @@ -1392,7 +1392,7 @@ static int ax25_getname(struct socket *s
55701 - memset(fsa, 0, sizeof(fsa));
55702 + memset(fsa, 0, sizeof(*fsa));
55704 ax25 = ax25_sk(sk);
55706 diff -urNp linux-2.6.37/net/bridge/br_multicast.c linux-2.6.37/net/bridge/br_multicast.c
55707 --- linux-2.6.37/net/bridge/br_multicast.c 2011-01-04 19:50:19.000000000 -0500
55708 +++ linux-2.6.37/net/bridge/br_multicast.c 2011-01-17 02:41:02.000000000 -0500
55709 @@ -1461,7 +1461,7 @@ static int br_multicast_ipv6_rcv(struct
55710 nexthdr = ip6h->nexthdr;
55711 offset = ipv6_skip_exthdr(skb, sizeof(*ip6h), &nexthdr);
55713 - if (offset < 0 || nexthdr != IPPROTO_ICMPV6)
55714 + if (nexthdr != IPPROTO_ICMPV6)
55717 /* Okay, we found ICMPv6 header */
55718 diff -urNp linux-2.6.37/net/bridge/br_stp_if.c linux-2.6.37/net/bridge/br_stp_if.c
55719 --- linux-2.6.37/net/bridge/br_stp_if.c 2011-01-04 19:50:19.000000000 -0500
55720 +++ linux-2.6.37/net/bridge/br_stp_if.c 2011-01-17 02:41:02.000000000 -0500
55721 @@ -145,7 +145,7 @@ static void br_stp_stop(struct net_bridg
55722 char *envp[] = { NULL };
55724 if (br->stp_enabled == BR_USER_STP) {
55725 - r = call_usermodehelper(BR_STP_PROG, argv, envp, 1);
55726 + r = call_usermodehelper(BR_STP_PROG, argv, envp, UMH_WAIT_PROC);
55727 br_info(br, "userspace STP stopped, return code %d\n", r);
55729 /* To start timers on any ports left in blocking */
55730 diff -urNp linux-2.6.37/net/bridge/netfilter/ebtables.c linux-2.6.37/net/bridge/netfilter/ebtables.c
55731 --- linux-2.6.37/net/bridge/netfilter/ebtables.c 2011-01-04 19:50:19.000000000 -0500
55732 +++ linux-2.6.37/net/bridge/netfilter/ebtables.c 2011-01-17 02:41:02.000000000 -0500
55733 @@ -1511,7 +1511,7 @@ static int do_ebt_get_ctl(struct sock *s
55734 tmp.valid_hooks = t->table->valid_hooks;
55736 mutex_unlock(&ebt_mutex);
55737 - if (copy_to_user(user, &tmp, *len) != 0){
55738 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
55739 BUGPRINT("c2u Didn't work\n");
55742 diff -urNp linux-2.6.37/net/core/dev.c linux-2.6.37/net/core/dev.c
55743 --- linux-2.6.37/net/core/dev.c 2011-01-04 19:50:19.000000000 -0500
55744 +++ linux-2.6.37/net/core/dev.c 2011-01-17 02:41:02.000000000 -0500
55745 @@ -2654,7 +2654,7 @@ int netif_rx_ni(struct sk_buff *skb)
55747 EXPORT_SYMBOL(netif_rx_ni);
55749 -static void net_tx_action(struct softirq_action *h)
55750 +static void net_tx_action(void)
55752 struct softnet_data *sd = &__get_cpu_var(softnet_data);
55754 @@ -3570,7 +3570,7 @@ void netif_napi_del(struct napi_struct *
55756 EXPORT_SYMBOL(netif_napi_del);
55758 -static void net_rx_action(struct softirq_action *h)
55759 +static void net_rx_action(void)
55761 struct softnet_data *sd = &__get_cpu_var(softnet_data);
55762 unsigned long time_limit = jiffies + 2;
55763 diff -urNp linux-2.6.37/net/core/sock.c linux-2.6.37/net/core/sock.c
55764 --- linux-2.6.37/net/core/sock.c 2011-01-04 19:50:19.000000000 -0500
55765 +++ linux-2.6.37/net/core/sock.c 2011-01-17 02:41:02.000000000 -0500
55766 @@ -934,7 +934,7 @@ int sock_getsockopt(struct socket *sock,
55770 - if (copy_to_user(optval, address, len))
55771 + if (len > sizeof(address) || copy_to_user(optval, address, len))
55775 @@ -967,7 +967,7 @@ int sock_getsockopt(struct socket *sock,
55779 - if (copy_to_user(optval, &v, len))
55780 + if (len > sizeof(v) || copy_to_user(optval, &v, len))
55783 if (put_user(len, optlen))
55784 diff -urNp linux-2.6.37/net/dccp/ccids/ccid3.c linux-2.6.37/net/dccp/ccids/ccid3.c
55785 --- linux-2.6.37/net/dccp/ccids/ccid3.c 2011-01-04 19:50:19.000000000 -0500
55786 +++ linux-2.6.37/net/dccp/ccids/ccid3.c 2011-01-17 02:41:02.000000000 -0500
55788 static int ccid3_debug;
55789 #define ccid3_pr_debug(format, a...) DCCP_PR_DEBUG(ccid3_debug, format, ##a)
55791 -#define ccid3_pr_debug(format, a...)
55792 +#define ccid3_pr_debug(format, a...) do {} while (0)
55796 diff -urNp linux-2.6.37/net/dccp/dccp.h linux-2.6.37/net/dccp/dccp.h
55797 --- linux-2.6.37/net/dccp/dccp.h 2011-01-04 19:50:19.000000000 -0500
55798 +++ linux-2.6.37/net/dccp/dccp.h 2011-01-17 02:41:02.000000000 -0500
55799 @@ -44,9 +44,9 @@ extern int dccp_debug;
55800 #define dccp_pr_debug_cat(format, a...) DCCP_PRINTK(dccp_debug, format, ##a)
55801 #define dccp_debug(fmt, a...) dccp_pr_debug_cat(KERN_DEBUG fmt, ##a)
55803 -#define dccp_pr_debug(format, a...)
55804 -#define dccp_pr_debug_cat(format, a...)
55805 -#define dccp_debug(format, a...)
55806 +#define dccp_pr_debug(format, a...) do {} while (0)
55807 +#define dccp_pr_debug_cat(format, a...) do {} while (0)
55808 +#define dccp_debug(format, a...) do {} while (0)
55811 extern struct inet_hashinfo dccp_hashinfo;
55812 diff -urNp linux-2.6.37/net/decnet/sysctl_net_decnet.c linux-2.6.37/net/decnet/sysctl_net_decnet.c
55813 --- linux-2.6.37/net/decnet/sysctl_net_decnet.c 2011-01-04 19:50:19.000000000 -0500
55814 +++ linux-2.6.37/net/decnet/sysctl_net_decnet.c 2011-01-17 02:41:02.000000000 -0500
55815 @@ -173,7 +173,7 @@ static int dn_node_address_handler(ctl_t
55817 if (len > *lenp) len = *lenp;
55819 - if (copy_to_user(buffer, addr, len))
55820 + if (len > sizeof addr || copy_to_user(buffer, addr, len))
55824 @@ -236,7 +236,7 @@ static int dn_def_dev_handler(ctl_table
55826 if (len > *lenp) len = *lenp;
55828 - if (copy_to_user(buffer, devname, len))
55829 + if (len > sizeof devname || copy_to_user(buffer, devname, len))
55833 diff -urNp linux-2.6.37/net/econet/Kconfig linux-2.6.37/net/econet/Kconfig
55834 --- linux-2.6.37/net/econet/Kconfig 2011-01-04 19:50:19.000000000 -0500
55835 +++ linux-2.6.37/net/econet/Kconfig 2011-01-17 02:41:02.000000000 -0500
55839 tristate "Acorn Econet/AUN protocols (EXPERIMENTAL)"
55840 - depends on EXPERIMENTAL && INET
55841 + depends on EXPERIMENTAL && INET && BROKEN
55843 Econet is a fairly old and slow networking protocol mainly used by
55844 Acorn computers to access file and print servers. It uses native
55845 diff -urNp linux-2.6.37/net/ipv4/inet_diag.c linux-2.6.37/net/ipv4/inet_diag.c
55846 --- linux-2.6.37/net/ipv4/inet_diag.c 2011-01-04 19:50:19.000000000 -0500
55847 +++ linux-2.6.37/net/ipv4/inet_diag.c 2011-01-17 02:41:02.000000000 -0500
55848 @@ -114,8 +114,14 @@ static int inet_csk_diag_fill(struct soc
55849 r->idiag_retrans = 0;
55851 r->id.idiag_if = sk->sk_bound_dev_if;
55853 +#ifdef CONFIG_GRKERNSEC_HIDESYM
55854 + r->id.idiag_cookie[0] = 0;
55855 + r->id.idiag_cookie[1] = 0;
55857 r->id.idiag_cookie[0] = (u32)(unsigned long)sk;
55858 r->id.idiag_cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
55861 r->id.idiag_sport = inet->inet_sport;
55862 r->id.idiag_dport = inet->inet_dport;
55863 @@ -201,8 +207,15 @@ static int inet_twsk_diag_fill(struct in
55864 r->idiag_family = tw->tw_family;
55865 r->idiag_retrans = 0;
55866 r->id.idiag_if = tw->tw_bound_dev_if;
55868 +#ifdef CONFIG_GRKERNSEC_HIDESYM
55869 + r->id.idiag_cookie[0] = 0;
55870 + r->id.idiag_cookie[1] = 0;
55872 r->id.idiag_cookie[0] = (u32)(unsigned long)tw;
55873 r->id.idiag_cookie[1] = (u32)(((unsigned long)tw >> 31) >> 1);
55876 r->id.idiag_sport = tw->tw_sport;
55877 r->id.idiag_dport = tw->tw_dport;
55878 r->id.idiag_src[0] = tw->tw_rcv_saddr;
55879 @@ -285,12 +298,14 @@ static int inet_diag_get_exact(struct sk
55883 +#ifndef CONFIG_GRKERNSEC_HIDESYM
55885 if ((req->id.idiag_cookie[0] != INET_DIAG_NOCOOKIE ||
55886 req->id.idiag_cookie[1] != INET_DIAG_NOCOOKIE) &&
55887 ((u32)(unsigned long)sk != req->id.idiag_cookie[0] ||
55888 (u32)((((unsigned long)sk) >> 31) >> 1) != req->id.idiag_cookie[1]))
55893 rep = alloc_skb(NLMSG_SPACE((sizeof(struct inet_diag_msg) +
55894 @@ -582,8 +597,14 @@ static int inet_diag_fill_req(struct sk_
55895 r->idiag_retrans = req->retrans;
55897 r->id.idiag_if = sk->sk_bound_dev_if;
55899 +#ifdef CONFIG_GRKERNSEC_HIDESYM
55900 + r->id.idiag_cookie[0] = 0;
55901 + r->id.idiag_cookie[1] = 0;
55903 r->id.idiag_cookie[0] = (u32)(unsigned long)req;
55904 r->id.idiag_cookie[1] = (u32)(((unsigned long)req >> 31) >> 1);
55907 tmo = req->expires - jiffies;
55909 diff -urNp linux-2.6.37/net/ipv4/inet_hashtables.c linux-2.6.37/net/ipv4/inet_hashtables.c
55910 --- linux-2.6.37/net/ipv4/inet_hashtables.c 2011-01-04 19:50:19.000000000 -0500
55911 +++ linux-2.6.37/net/ipv4/inet_hashtables.c 2011-01-17 02:41:02.000000000 -0500
55912 @@ -18,11 +18,14 @@
55913 #include <linux/sched.h>
55914 #include <linux/slab.h>
55915 #include <linux/wait.h>
55916 +#include <linux/security.h>
55918 #include <net/inet_connection_sock.h>
55919 #include <net/inet_hashtables.h>
55920 #include <net/route.h>
55921 #include <net/ip.h>
55923 +extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
55926 * Allocate and initialize a new local port bind bucket.
55927 * The bindhash mutex for snum's hash chain must be held here.
55928 @@ -529,6 +532,8 @@ ok:
55929 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
55930 spin_unlock(&head->lock);
55932 + gr_update_task_in_ip_table(current, inet_sk(sk));
55935 inet_twsk_deschedule(tw, death_row);
55937 diff -urNp linux-2.6.37/net/ipv4/inetpeer.c linux-2.6.37/net/ipv4/inetpeer.c
55938 --- linux-2.6.37/net/ipv4/inetpeer.c 2011-01-04 19:50:19.000000000 -0500
55939 +++ linux-2.6.37/net/ipv4/inetpeer.c 2011-01-17 02:41:02.000000000 -0500
55940 @@ -469,8 +469,8 @@ struct inet_peer *inet_getpeer(__be32 da
55942 p->v4daddr = daddr;
55943 atomic_set(&p->refcnt, 1);
55944 - atomic_set(&p->rid, 0);
55945 - atomic_set(&p->ip_id_count, secure_ip_id(daddr));
55946 + atomic_set_unchecked(&p->rid, 0);
55947 + atomic_set_unchecked(&p->ip_id_count, secure_ip_id(daddr));
55948 p->tcp_ts_stamp = 0;
55949 INIT_LIST_HEAD(&p->unused);
55951 diff -urNp linux-2.6.37/net/ipv4/ip_fragment.c linux-2.6.37/net/ipv4/ip_fragment.c
55952 --- linux-2.6.37/net/ipv4/ip_fragment.c 2011-01-04 19:50:19.000000000 -0500
55953 +++ linux-2.6.37/net/ipv4/ip_fragment.c 2011-01-17 02:41:02.000000000 -0500
55954 @@ -279,7 +279,7 @@ static inline int ip_frag_too_far(struct
55958 - end = atomic_inc_return(&peer->rid);
55959 + end = atomic_inc_return_unchecked(&peer->rid);
55962 rc = qp->q.fragments && (end - start) > max;
55963 diff -urNp linux-2.6.37/net/ipv4/netfilter/nf_nat_snmp_basic.c linux-2.6.37/net/ipv4/netfilter/nf_nat_snmp_basic.c
55964 --- linux-2.6.37/net/ipv4/netfilter/nf_nat_snmp_basic.c 2011-01-04 19:50:19.000000000 -0500
55965 +++ linux-2.6.37/net/ipv4/netfilter/nf_nat_snmp_basic.c 2011-01-17 02:41:02.000000000 -0500
55966 @@ -398,7 +398,7 @@ static unsigned char asn1_octets_decode(
55970 - *octets = kmalloc(eoc - ctx->pointer, GFP_ATOMIC);
55971 + *octets = kmalloc((eoc - ctx->pointer), GFP_ATOMIC);
55972 if (*octets == NULL) {
55973 if (net_ratelimit())
55974 pr_notice("OOM in bsalg (%d)\n", __LINE__);
55975 diff -urNp linux-2.6.37/net/ipv4/route.c linux-2.6.37/net/ipv4/route.c
55976 --- linux-2.6.37/net/ipv4/route.c 2011-01-04 19:50:19.000000000 -0500
55977 +++ linux-2.6.37/net/ipv4/route.c 2011-01-17 02:41:02.000000000 -0500
55978 @@ -2876,7 +2876,7 @@ static int rt_fill_info(struct net *net,
55979 expires = rt->dst.expires ? rt->dst.expires - jiffies : 0;
55981 inet_peer_refcheck(rt->peer);
55982 - id = atomic_read(&rt->peer->ip_id_count) & 0xffff;
55983 + id = atomic_read_unchecked(&rt->peer->ip_id_count) & 0xffff;
55984 if (rt->peer->tcp_ts_stamp) {
55985 ts = rt->peer->tcp_ts;
55986 tsage = get_seconds() - rt->peer->tcp_ts_stamp;
55987 diff -urNp linux-2.6.37/net/ipv4/tcp_ipv4.c linux-2.6.37/net/ipv4/tcp_ipv4.c
55988 --- linux-2.6.37/net/ipv4/tcp_ipv4.c 2011-01-04 19:50:19.000000000 -0500
55989 +++ linux-2.6.37/net/ipv4/tcp_ipv4.c 2011-01-17 02:41:02.000000000 -0500
55990 @@ -86,6 +86,9 @@ int sysctl_tcp_tw_reuse __read_mostly;
55991 int sysctl_tcp_low_latency __read_mostly;
55992 EXPORT_SYMBOL(sysctl_tcp_low_latency);
55994 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
55995 +extern int grsec_enable_blackhole;
55998 #ifdef CONFIG_TCP_MD5SIG
55999 static struct tcp_md5sig_key *tcp_v4_md5_do_lookup(struct sock *sk,
56000 @@ -1599,6 +1602,9 @@ int tcp_v4_do_rcv(struct sock *sk, struc
56004 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
56005 + if (!grsec_enable_blackhole)
56007 tcp_v4_send_reset(rsk, skb);
56010 @@ -1661,12 +1667,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
56011 TCP_SKB_CB(skb)->sacked = 0;
56013 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
56016 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
56019 goto no_tcp_socket;
56023 - if (sk->sk_state == TCP_TIME_WAIT)
56024 + if (sk->sk_state == TCP_TIME_WAIT) {
56025 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
56031 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
56032 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
56033 @@ -1716,6 +1729,10 @@ no_tcp_socket:
56035 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
56037 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
56038 + if (!grsec_enable_blackhole || (ret == 1 &&
56039 + (skb->dev->flags & IFF_LOOPBACK)))
56041 tcp_v4_send_reset(NULL, skb);
56044 @@ -2404,7 +2421,11 @@ static void get_openreq4(struct sock *sk
56045 0, /* non standard timer */
56046 0, /* open_requests have no inode */
56047 atomic_read(&sk->sk_refcnt),
56048 +#ifdef CONFIG_GRKERNSEC_HIDESYM
56056 @@ -2454,7 +2475,12 @@ static void get_tcp4_sock(struct sock *s
56058 icsk->icsk_probes_out,
56060 - atomic_read(&sk->sk_refcnt), sk,
56061 + atomic_read(&sk->sk_refcnt),
56062 +#ifdef CONFIG_GRKERNSEC_HIDESYM
56067 jiffies_to_clock_t(icsk->icsk_rto),
56068 jiffies_to_clock_t(icsk->icsk_ack.ato),
56069 (icsk->icsk_ack.quick << 1) | icsk->icsk_ack.pingpong,
56070 @@ -2482,7 +2508,13 @@ static void get_timewait4_sock(struct in
56071 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %p%n",
56072 i, src, srcp, dest, destp, tw->tw_substate, 0, 0,
56073 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
56074 - atomic_read(&tw->tw_refcnt), tw, len);
56075 + atomic_read(&tw->tw_refcnt),
56076 +#ifdef CONFIG_GRKERNSEC_HIDESYM
56085 diff -urNp linux-2.6.37/net/ipv4/tcp_minisocks.c linux-2.6.37/net/ipv4/tcp_minisocks.c
56086 --- linux-2.6.37/net/ipv4/tcp_minisocks.c 2011-01-04 19:50:19.000000000 -0500
56087 +++ linux-2.6.37/net/ipv4/tcp_minisocks.c 2011-01-17 02:41:02.000000000 -0500
56089 #include <net/inet_common.h>
56090 #include <net/xfrm.h>
56092 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
56093 +extern int grsec_enable_blackhole;
56096 int sysctl_tcp_syncookies __read_mostly = 1;
56097 EXPORT_SYMBOL(sysctl_tcp_syncookies);
56099 @@ -700,6 +704,10 @@ listen_overflow:
56102 NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_EMBRYONICRSTS);
56104 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
56105 + if (!grsec_enable_blackhole)
56107 if (!(flg & TCP_FLAG_RST))
56108 req->rsk_ops->send_reset(sk, skb);
56110 diff -urNp linux-2.6.37/net/ipv4/tcp_probe.c linux-2.6.37/net/ipv4/tcp_probe.c
56111 --- linux-2.6.37/net/ipv4/tcp_probe.c 2011-01-04 19:50:19.000000000 -0500
56112 +++ linux-2.6.37/net/ipv4/tcp_probe.c 2011-01-17 02:41:02.000000000 -0500
56113 @@ -202,7 +202,7 @@ static ssize_t tcpprobe_read(struct file
56114 if (cnt + width >= len)
56117 - if (copy_to_user(buf + cnt, tbuf, width))
56118 + if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
56122 diff -urNp linux-2.6.37/net/ipv4/tcp_timer.c linux-2.6.37/net/ipv4/tcp_timer.c
56123 --- linux-2.6.37/net/ipv4/tcp_timer.c 2011-01-04 19:50:19.000000000 -0500
56124 +++ linux-2.6.37/net/ipv4/tcp_timer.c 2011-01-17 02:41:02.000000000 -0500
56126 #include <linux/gfp.h>
56127 #include <net/tcp.h>
56129 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
56130 +extern int grsec_lastack_retries;
56133 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
56134 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
56135 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
56136 @@ -199,6 +203,13 @@ static int tcp_write_timeout(struct sock
56140 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
56141 + if ((sk->sk_state == TCP_LAST_ACK) &&
56142 + (grsec_lastack_retries > 0) &&
56143 + (grsec_lastack_retries < retry_until))
56144 + retry_until = grsec_lastack_retries;
56147 if (retransmits_timed_out(sk, retry_until,
56148 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
56149 /* Has it gone just too far? */
56150 diff -urNp linux-2.6.37/net/ipv4/udp.c linux-2.6.37/net/ipv4/udp.c
56151 --- linux-2.6.37/net/ipv4/udp.c 2011-01-04 19:50:19.000000000 -0500
56152 +++ linux-2.6.37/net/ipv4/udp.c 2011-01-17 02:41:02.000000000 -0500
56154 #include <linux/types.h>
56155 #include <linux/fcntl.h>
56156 #include <linux/module.h>
56157 +#include <linux/security.h>
56158 #include <linux/socket.h>
56159 #include <linux/sockios.h>
56160 #include <linux/igmp.h>
56161 @@ -107,6 +108,10 @@
56162 #include <net/xfrm.h>
56163 #include "udp_impl.h"
56165 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
56166 +extern int grsec_enable_blackhole;
56169 struct udp_table udp_table __read_mostly;
56170 EXPORT_SYMBOL(udp_table);
56172 @@ -564,6 +569,9 @@ found:
56176 +extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
56177 +extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
56180 * This routine is called by the ICMP module when it gets some
56181 * sort of error condition. If err < 0 then the socket should
56182 @@ -832,9 +840,18 @@ int udp_sendmsg(struct kiocb *iocb, stru
56183 dport = usin->sin_port;
56187 + err = gr_search_udp_sendmsg(sk, usin);
56191 if (sk->sk_state != TCP_ESTABLISHED)
56192 return -EDESTADDRREQ;
56194 + err = gr_search_udp_sendmsg(sk, NULL);
56198 daddr = inet->inet_daddr;
56199 dport = inet->inet_dport;
56200 /* Open fast path for connected socket.
56201 @@ -1141,6 +1158,10 @@ try_again:
56205 + err = gr_search_udp_recvmsg(sk, skb);
56209 ulen = skb->len - sizeof(struct udphdr);
56212 @@ -1625,6 +1646,9 @@ int __udp4_lib_rcv(struct sk_buff *skb,
56215 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
56216 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
56217 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
56219 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
56222 @@ -2052,7 +2076,12 @@ static void udp4_format_sock(struct sock
56223 sk_wmem_alloc_get(sp),
56224 sk_rmem_alloc_get(sp),
56225 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
56226 - atomic_read(&sp->sk_refcnt), sp,
56227 + atomic_read(&sp->sk_refcnt),
56228 +#ifdef CONFIG_GRKERNSEC_HIDESYM
56233 atomic_read(&sp->sk_drops), len);
56236 diff -urNp linux-2.6.37/net/ipv6/exthdrs.c linux-2.6.37/net/ipv6/exthdrs.c
56237 --- linux-2.6.37/net/ipv6/exthdrs.c 2011-01-04 19:50:19.000000000 -0500
56238 +++ linux-2.6.37/net/ipv6/exthdrs.c 2011-01-17 02:41:02.000000000 -0500
56239 @@ -634,7 +634,7 @@ static struct tlvtype_proc tlvprochopopt
56240 .type = IPV6_TLV_JUMBO,
56241 .func = ipv6_hop_jumbo,
56247 int ipv6_parse_hopopts(struct sk_buff *skb)
56248 diff -urNp linux-2.6.37/net/ipv6/raw.c linux-2.6.37/net/ipv6/raw.c
56249 --- linux-2.6.37/net/ipv6/raw.c 2011-01-04 19:50:19.000000000 -0500
56250 +++ linux-2.6.37/net/ipv6/raw.c 2011-01-17 02:41:02.000000000 -0500
56251 @@ -601,7 +601,7 @@ out:
56255 -static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
56256 +static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
56257 struct flowi *fl, struct dst_entry **dstp,
56258 unsigned int flags)
56260 @@ -1243,7 +1243,13 @@ static void raw6_sock_seq_show(struct se
56264 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
56265 + atomic_read(&sp->sk_refcnt),
56266 +#ifdef CONFIG_GRKERNSEC_HIDESYM
56271 + atomic_read(&sp->sk_drops));
56274 static int raw6_seq_show(struct seq_file *seq, void *v)
56275 diff -urNp linux-2.6.37/net/ipv6/tcp_ipv6.c linux-2.6.37/net/ipv6/tcp_ipv6.c
56276 --- linux-2.6.37/net/ipv6/tcp_ipv6.c 2011-01-04 19:50:19.000000000 -0500
56277 +++ linux-2.6.37/net/ipv6/tcp_ipv6.c 2011-01-17 02:41:02.000000000 -0500
56278 @@ -92,6 +92,10 @@ static struct tcp_md5sig_key *tcp_v6_md5
56282 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
56283 +extern int grsec_enable_blackhole;
56286 static void tcp_v6_hash(struct sock *sk)
56288 if (sk->sk_state != TCP_CLOSE) {
56289 @@ -1631,6 +1635,9 @@ static int tcp_v6_do_rcv(struct sock *sk
56293 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
56294 + if (!grsec_enable_blackhole)
56296 tcp_v6_send_reset(sk, skb);
56299 @@ -1710,12 +1717,20 @@ static int tcp_v6_rcv(struct sk_buff *sk
56300 TCP_SKB_CB(skb)->sacked = 0;
56302 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
56305 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
56308 goto no_tcp_socket;
56312 - if (sk->sk_state == TCP_TIME_WAIT)
56313 + if (sk->sk_state == TCP_TIME_WAIT) {
56314 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
56320 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
56321 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
56322 @@ -1763,6 +1778,10 @@ no_tcp_socket:
56324 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
56326 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
56327 + if (!grsec_enable_blackhole || (ret == 1 &&
56328 + (skb->dev->flags & IFF_LOOPBACK)))
56330 tcp_v6_send_reset(NULL, skb);
56333 @@ -1991,7 +2010,13 @@ static void get_openreq6(struct seq_file
56335 0, /* non standard timer */
56336 0, /* open_requests have no inode */
56339 +#ifdef CONFIG_GRKERNSEC_HIDESYM
56347 static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
56348 @@ -2041,7 +2066,12 @@ static void get_tcp6_sock(struct seq_fil
56350 icsk->icsk_probes_out,
56352 - atomic_read(&sp->sk_refcnt), sp,
56353 + atomic_read(&sp->sk_refcnt),
56354 +#ifdef CONFIG_GRKERNSEC_HIDESYM
56359 jiffies_to_clock_t(icsk->icsk_rto),
56360 jiffies_to_clock_t(icsk->icsk_ack.ato),
56361 (icsk->icsk_ack.quick << 1 ) | icsk->icsk_ack.pingpong,
56362 @@ -2076,7 +2106,13 @@ static void get_timewait6_sock(struct se
56363 dest->s6_addr32[2], dest->s6_addr32[3], destp,
56364 tw->tw_substate, 0, 0,
56365 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
56366 - atomic_read(&tw->tw_refcnt), tw);
56367 + atomic_read(&tw->tw_refcnt),
56368 +#ifdef CONFIG_GRKERNSEC_HIDESYM
56376 static int tcp6_seq_show(struct seq_file *seq, void *v)
56377 diff -urNp linux-2.6.37/net/ipv6/udp.c linux-2.6.37/net/ipv6/udp.c
56378 --- linux-2.6.37/net/ipv6/udp.c 2011-01-04 19:50:19.000000000 -0500
56379 +++ linux-2.6.37/net/ipv6/udp.c 2011-01-17 02:41:02.000000000 -0500
56381 #include <linux/seq_file.h>
56382 #include "udp_impl.h"
56384 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
56385 +extern int grsec_enable_blackhole;
56388 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
56390 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
56391 @@ -773,6 +777,9 @@ int __udp6_lib_rcv(struct sk_buff *skb,
56392 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS,
56393 proto == IPPROTO_UDPLITE);
56395 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
56396 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
56398 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
56401 @@ -1407,7 +1414,12 @@ static void udp6_sock_seq_show(struct se
56405 - atomic_read(&sp->sk_refcnt), sp,
56406 + atomic_read(&sp->sk_refcnt),
56407 +#ifdef CONFIG_GRKERNSEC_HIDESYM
56412 atomic_read(&sp->sk_drops));
56415 diff -urNp linux-2.6.37/net/irda/ircomm/ircomm_tty.c linux-2.6.37/net/irda/ircomm/ircomm_tty.c
56416 --- linux-2.6.37/net/irda/ircomm/ircomm_tty.c 2011-01-04 19:50:19.000000000 -0500
56417 +++ linux-2.6.37/net/irda/ircomm/ircomm_tty.c 2011-01-17 02:41:02.000000000 -0500
56418 @@ -281,16 +281,16 @@ static int ircomm_tty_block_til_ready(st
56419 add_wait_queue(&self->open_wait, &wait);
56421 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
56422 - __FILE__,__LINE__, tty->driver->name, self->open_count );
56423 + __FILE__,__LINE__, tty->driver->name, atomic_read(&self->open_count) );
56425 /* As far as I can see, we protect open_count - Jean II */
56426 spin_lock_irqsave(&self->spinlock, flags);
56427 if (!tty_hung_up_p(filp)) {
56429 - self->open_count--;
56430 + atomic_dec(&self->open_count);
56432 spin_unlock_irqrestore(&self->spinlock, flags);
56433 - self->blocked_open++;
56434 + atomic_inc(&self->blocked_open);
56437 if (tty->termios->c_cflag & CBAUD) {
56438 @@ -330,7 +330,7 @@ static int ircomm_tty_block_til_ready(st
56441 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
56442 - __FILE__,__LINE__, tty->driver->name, self->open_count );
56443 + __FILE__,__LINE__, tty->driver->name, atomic_read(&self->open_count) );
56447 @@ -341,13 +341,13 @@ static int ircomm_tty_block_til_ready(st
56449 /* ++ is not atomic, so this should be protected - Jean II */
56450 spin_lock_irqsave(&self->spinlock, flags);
56451 - self->open_count++;
56452 + atomic_inc(&self->open_count);
56453 spin_unlock_irqrestore(&self->spinlock, flags);
56455 - self->blocked_open--;
56456 + atomic_dec(&self->blocked_open);
56458 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
56459 - __FILE__,__LINE__, tty->driver->name, self->open_count);
56460 + __FILE__,__LINE__, tty->driver->name, atomic_read(&self->open_count));
56463 self->flags |= ASYNC_NORMAL_ACTIVE;
56464 @@ -416,14 +416,14 @@ static int ircomm_tty_open(struct tty_st
56466 /* ++ is not atomic, so this should be protected - Jean II */
56467 spin_lock_irqsave(&self->spinlock, flags);
56468 - self->open_count++;
56469 + atomic_inc(&self->open_count);
56471 tty->driver_data = self;
56473 spin_unlock_irqrestore(&self->spinlock, flags);
56475 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
56476 - self->line, self->open_count);
56477 + self->line, atomic_read(&self->open_count));
56479 /* Not really used by us, but lets do it anyway */
56480 self->tty->low_latency = (self->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
56481 @@ -509,7 +509,7 @@ static void ircomm_tty_close(struct tty_
56485 - if ((tty->count == 1) && (self->open_count != 1)) {
56486 + if ((tty->count == 1) && (atomic_read(&self->open_count) != 1)) {
56488 * Uh, oh. tty->count is 1, which means that the tty
56489 * structure will be freed. state->count should always
56490 @@ -519,16 +519,16 @@ static void ircomm_tty_close(struct tty_
56492 IRDA_DEBUG(0, "%s(), bad serial port count; "
56493 "tty->count is 1, state->count is %d\n", __func__ ,
56494 - self->open_count);
56495 - self->open_count = 1;
56496 + atomic_read(&self->open_count));
56497 + atomic_set(&self->open_count, 1);
56500 - if (--self->open_count < 0) {
56501 + if (atomic_dec_return(&self->open_count) < 0) {
56502 IRDA_ERROR("%s(), bad serial port count for ttys%d: %d\n",
56503 - __func__, self->line, self->open_count);
56504 - self->open_count = 0;
56505 + __func__, self->line, atomic_read(&self->open_count));
56506 + atomic_set(&self->open_count, 0);
56508 - if (self->open_count) {
56509 + if (atomic_read(&self->open_count)) {
56510 spin_unlock_irqrestore(&self->spinlock, flags);
56512 IRDA_DEBUG(0, "%s(), open count > 0\n", __func__ );
56513 @@ -560,7 +560,7 @@ static void ircomm_tty_close(struct tty_
56517 - if (self->blocked_open) {
56518 + if (atomic_read(&self->blocked_open)) {
56519 if (self->close_delay)
56520 schedule_timeout_interruptible(self->close_delay);
56521 wake_up_interruptible(&self->open_wait);
56522 @@ -1012,7 +1012,7 @@ static void ircomm_tty_hangup(struct tty
56523 spin_lock_irqsave(&self->spinlock, flags);
56524 self->flags &= ~ASYNC_NORMAL_ACTIVE;
56526 - self->open_count = 0;
56527 + atomic_set(&self->open_count, 0);
56528 spin_unlock_irqrestore(&self->spinlock, flags);
56530 wake_up_interruptible(&self->open_wait);
56531 @@ -1364,7 +1364,7 @@ static void ircomm_tty_line_info(struct
56534 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
56535 - seq_printf(m, "Open count: %d\n", self->open_count);
56536 + seq_printf(m, "Open count: %d\n", atomic_read(&self->open_count));
56537 seq_printf(m, "Max data size: %d\n", self->max_data_size);
56538 seq_printf(m, "Max header size: %d\n", self->max_header_size);
56540 diff -urNp linux-2.6.37/net/key/af_key.c linux-2.6.37/net/key/af_key.c
56541 --- linux-2.6.37/net/key/af_key.c 2011-01-04 19:50:19.000000000 -0500
56542 +++ linux-2.6.37/net/key/af_key.c 2011-01-17 02:41:02.000000000 -0500
56543 @@ -3644,7 +3644,11 @@ static int pfkey_seq_show(struct seq_fil
56544 seq_printf(f ,"sk RefCnt Rmem Wmem User Inode\n");
56546 seq_printf(f ,"%p %-6d %-6u %-6u %-6u %-6lu\n",
56547 +#ifdef CONFIG_GRKERNSEC_HIDESYM
56552 atomic_read(&s->sk_refcnt),
56553 sk_rmem_alloc_get(s),
56554 sk_wmem_alloc_get(s),
56555 diff -urNp linux-2.6.37/net/mac80211/ieee80211_i.h linux-2.6.37/net/mac80211/ieee80211_i.h
56556 --- linux-2.6.37/net/mac80211/ieee80211_i.h 2011-01-04 19:50:19.000000000 -0500
56557 +++ linux-2.6.37/net/mac80211/ieee80211_i.h 2011-01-17 02:41:02.000000000 -0500
56558 @@ -704,7 +704,7 @@ struct ieee80211_local {
56559 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
56560 spinlock_t queue_stop_reason_lock;
56563 + atomic_t open_count;
56564 int monitors, cooked_mntrs;
56565 /* number of interfaces with corresponding FIF_ flags */
56566 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
56567 diff -urNp linux-2.6.37/net/mac80211/iface.c linux-2.6.37/net/mac80211/iface.c
56568 --- linux-2.6.37/net/mac80211/iface.c 2011-01-04 19:50:19.000000000 -0500
56569 +++ linux-2.6.37/net/mac80211/iface.c 2011-01-17 02:41:02.000000000 -0500
56570 @@ -216,7 +216,7 @@ static int ieee80211_do_open(struct net_
56574 - if (local->open_count == 0) {
56575 + if (atomic_read(&local->open_count) == 0) {
56576 res = drv_start(local);
56579 @@ -238,7 +238,7 @@ static int ieee80211_do_open(struct net_
56580 memcpy(dev->perm_addr, dev->dev_addr, ETH_ALEN);
56582 if (!is_valid_ether_addr(dev->dev_addr)) {
56583 - if (!local->open_count)
56584 + if (!atomic_read(&local->open_count))
56586 return -EADDRNOTAVAIL;
56588 @@ -335,7 +335,7 @@ static int ieee80211_do_open(struct net_
56589 mutex_unlock(&local->mtx);
56592 - local->open_count++;
56593 + atomic_inc(&local->open_count);
56595 if (hw_reconf_flags) {
56596 ieee80211_hw_config(local, hw_reconf_flags);
56597 @@ -355,7 +355,7 @@ static int ieee80211_do_open(struct net_
56599 drv_remove_interface(local, &sdata->vif);
56601 - if (!local->open_count)
56602 + if (!atomic_read(&local->open_count))
56606 @@ -481,7 +481,7 @@ static void ieee80211_do_stop(struct iee
56610 - local->open_count--;
56611 + atomic_dec(&local->open_count);
56613 switch (sdata->vif.type) {
56614 case NL80211_IFTYPE_AP_VLAN:
56615 @@ -552,7 +552,7 @@ static void ieee80211_do_stop(struct iee
56617 ieee80211_recalc_ps(local, -1);
56619 - if (local->open_count == 0) {
56620 + if (atomic_read(&local->open_count) == 0) {
56621 if (local->ops->napi_poll)
56622 napi_disable(&local->napi);
56623 ieee80211_clear_tx_pending(local);
56624 diff -urNp linux-2.6.37/net/mac80211/main.c linux-2.6.37/net/mac80211/main.c
56625 --- linux-2.6.37/net/mac80211/main.c 2011-01-04 19:50:19.000000000 -0500
56626 +++ linux-2.6.37/net/mac80211/main.c 2011-01-17 02:41:02.000000000 -0500
56627 @@ -159,7 +159,7 @@ int ieee80211_hw_config(struct ieee80211
56628 local->hw.conf.power_level = power;
56631 - if (changed && local->open_count) {
56632 + if (changed && atomic_read(&local->open_count)) {
56633 ret = drv_config(local, changed);
56636 diff -urNp linux-2.6.37/net/mac80211/pm.c linux-2.6.37/net/mac80211/pm.c
56637 --- linux-2.6.37/net/mac80211/pm.c 2011-01-04 19:50:19.000000000 -0500
56638 +++ linux-2.6.37/net/mac80211/pm.c 2011-01-17 02:41:02.000000000 -0500
56639 @@ -95,7 +95,7 @@ int __ieee80211_suspend(struct ieee80211
56642 /* stop hardware - this must stop RX */
56643 - if (local->open_count)
56644 + if (atomic_read(&local->open_count))
56645 ieee80211_stop_device(local);
56647 local->suspended = true;
56648 diff -urNp linux-2.6.37/net/mac80211/rate.c linux-2.6.37/net/mac80211/rate.c
56649 --- linux-2.6.37/net/mac80211/rate.c 2011-01-04 19:50:19.000000000 -0500
56650 +++ linux-2.6.37/net/mac80211/rate.c 2011-01-17 02:41:02.000000000 -0500
56651 @@ -361,7 +361,7 @@ int ieee80211_init_rate_ctrl_alg(struct
56655 - if (local->open_count)
56656 + if (atomic_read(&local->open_count))
56659 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
56660 diff -urNp linux-2.6.37/net/mac80211/rc80211_pid_debugfs.c linux-2.6.37/net/mac80211/rc80211_pid_debugfs.c
56661 --- linux-2.6.37/net/mac80211/rc80211_pid_debugfs.c 2011-01-04 19:50:19.000000000 -0500
56662 +++ linux-2.6.37/net/mac80211/rc80211_pid_debugfs.c 2011-01-17 02:41:02.000000000 -0500
56663 @@ -192,7 +192,7 @@ static ssize_t rate_control_pid_events_r
56665 spin_unlock_irqrestore(&events->lock, status);
56667 - if (copy_to_user(buf, pb, p))
56668 + if (p > sizeof(pb) || copy_to_user(buf, pb, p))
56672 diff -urNp linux-2.6.37/net/mac80211/tx.c linux-2.6.37/net/mac80211/tx.c
56673 --- linux-2.6.37/net/mac80211/tx.c 2011-01-04 19:50:19.000000000 -0500
56674 +++ linux-2.6.37/net/mac80211/tx.c 2011-01-17 02:41:02.000000000 -0500
56675 @@ -173,7 +173,7 @@ static __le16 ieee80211_duration(struct
56676 return cpu_to_le16(dur);
56679 -static int inline is_ieee80211_device(struct ieee80211_local *local,
56680 +static inline int is_ieee80211_device(struct ieee80211_local *local,
56681 struct net_device *dev)
56683 return local == wdev_priv(dev->ieee80211_ptr);
56684 diff -urNp linux-2.6.37/net/mac80211/util.c linux-2.6.37/net/mac80211/util.c
56685 --- linux-2.6.37/net/mac80211/util.c 2011-01-04 19:50:19.000000000 -0500
56686 +++ linux-2.6.37/net/mac80211/util.c 2011-01-17 02:41:02.000000000 -0500
56687 @@ -1111,7 +1111,7 @@ int ieee80211_reconfig(struct ieee80211_
56688 local->resuming = true;
56690 /* restart hardware */
56691 - if (local->open_count) {
56692 + if (atomic_read(&local->open_count)) {
56694 * Upon resume hardware can sometimes be goofy due to
56695 * various platform / driver / bus issues, so restarting
56696 diff -urNp linux-2.6.37/net/netfilter/Kconfig linux-2.6.37/net/netfilter/Kconfig
56697 --- linux-2.6.37/net/netfilter/Kconfig 2011-01-04 19:50:19.000000000 -0500
56698 +++ linux-2.6.37/net/netfilter/Kconfig 2011-01-17 02:41:02.000000000 -0500
56699 @@ -709,6 +709,16 @@ config NETFILTER_XT_MATCH_ESP
56701 To compile it as a module, choose M here. If unsure, say N.
56703 +config NETFILTER_XT_MATCH_GRADM
56704 + tristate '"gradm" match support'
56705 + depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
56706 + depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
56708 + The gradm match allows to match on grsecurity RBAC being enabled.
56709 + It is useful when iptables rules are applied early on bootup to
56710 + prevent connections to the machine (except from a trusted host)
56711 + while the RBAC system is disabled.
56713 config NETFILTER_XT_MATCH_HASHLIMIT
56714 tristate '"hashlimit" match support'
56715 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
56716 diff -urNp linux-2.6.37/net/netfilter/Makefile linux-2.6.37/net/netfilter/Makefile
56717 --- linux-2.6.37/net/netfilter/Makefile 2011-01-04 19:50:19.000000000 -0500
56718 +++ linux-2.6.37/net/netfilter/Makefile 2011-01-17 02:41:02.000000000 -0500
56719 @@ -74,6 +74,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_CPU) +=
56720 obj-$(CONFIG_NETFILTER_XT_MATCH_DCCP) += xt_dccp.o
56721 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
56722 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
56723 +obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
56724 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
56725 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
56726 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
56727 diff -urNp linux-2.6.37/net/netfilter/nf_conntrack_netlink.c linux-2.6.37/net/netfilter/nf_conntrack_netlink.c
56728 --- linux-2.6.37/net/netfilter/nf_conntrack_netlink.c 2011-01-04 19:50:19.000000000 -0500
56729 +++ linux-2.6.37/net/netfilter/nf_conntrack_netlink.c 2011-01-17 02:41:02.000000000 -0500
56730 @@ -761,7 +761,7 @@ static const struct nla_policy tuple_nla
56732 ctnetlink_parse_tuple(const struct nlattr * const cda[],
56733 struct nf_conntrack_tuple *tuple,
56734 - enum ctattr_tuple type, u_int8_t l3num)
56735 + enum ctattr_type type, u_int8_t l3num)
56737 struct nlattr *tb[CTA_TUPLE_MAX+1];
56739 diff -urNp linux-2.6.37/net/netfilter/xt_gradm.c linux-2.6.37/net/netfilter/xt_gradm.c
56740 --- linux-2.6.37/net/netfilter/xt_gradm.c 1969-12-31 19:00:00.000000000 -0500
56741 +++ linux-2.6.37/net/netfilter/xt_gradm.c 2011-01-17 02:41:02.000000000 -0500
56744 + * gradm match for netfilter
56745 + * Copyright © Zbigniew Krzystolik, 2010
56747 + * This program is free software; you can redistribute it and/or modify
56748 + * it under the terms of the GNU General Public License; either version
56749 + * 2 or 3 as published by the Free Software Foundation.
56751 +#include <linux/module.h>
56752 +#include <linux/moduleparam.h>
56753 +#include <linux/skbuff.h>
56754 +#include <linux/netfilter/x_tables.h>
56755 +#include <linux/grsecurity.h>
56756 +#include <linux/netfilter/xt_gradm.h>
56759 +gradm_mt(const struct sk_buff *skb, struct xt_action_param *par)
56761 + const struct xt_gradm_mtinfo *info = par->matchinfo;
56762 + bool retval = false;
56763 + if (gr_acl_is_enabled())
56765 + return retval ^ info->invflags;
56768 +static struct xt_match gradm_mt_reg __read_mostly = {
56771 + .family = NFPROTO_UNSPEC,
56772 + .match = gradm_mt,
56773 + .matchsize = XT_ALIGN(sizeof(struct xt_gradm_mtinfo)),
56774 + .me = THIS_MODULE,
56777 +static int __init gradm_mt_init(void)
56779 + return xt_register_match(&gradm_mt_reg);
56782 +static void __exit gradm_mt_exit(void)
56784 + xt_unregister_match(&gradm_mt_reg);
56787 +module_init(gradm_mt_init);
56788 +module_exit(gradm_mt_exit);
56789 +MODULE_AUTHOR("Zbigniew Krzystolik <zbyniu@destrukcja.pl>");
56790 +MODULE_DESCRIPTION("Xtables: Grsecurity RBAC match");
56791 +MODULE_LICENSE("GPL");
56792 +MODULE_ALIAS("ipt_gradm");
56793 +MODULE_ALIAS("ip6t_gradm");
56794 diff -urNp linux-2.6.37/net/netlink/af_netlink.c linux-2.6.37/net/netlink/af_netlink.c
56795 --- linux-2.6.37/net/netlink/af_netlink.c 2011-01-04 19:50:19.000000000 -0500
56796 +++ linux-2.6.37/net/netlink/af_netlink.c 2011-01-17 02:41:02.000000000 -0500
56797 @@ -1991,13 +1991,21 @@ static int netlink_seq_show(struct seq_f
56798 struct netlink_sock *nlk = nlk_sk(s);
56800 seq_printf(seq, "%p %-3d %-6d %08x %-8d %-8d %p %-8d %-8d %-8lu\n",
56801 +#ifdef CONFIG_GRKERNSEC_HIDESYM
56808 nlk->groups ? (u32)nlk->groups[0] : 0,
56809 sk_rmem_alloc_get(s),
56810 sk_wmem_alloc_get(s),
56811 +#ifdef CONFIG_GRKERNSEC_HIDESYM
56816 atomic_read(&s->sk_refcnt),
56817 atomic_read(&s->sk_drops),
56819 diff -urNp linux-2.6.37/net/netrom/af_netrom.c linux-2.6.37/net/netrom/af_netrom.c
56820 --- linux-2.6.37/net/netrom/af_netrom.c 2011-01-04 19:50:19.000000000 -0500
56821 +++ linux-2.6.37/net/netrom/af_netrom.c 2011-01-17 02:41:02.000000000 -0500
56822 @@ -840,6 +840,7 @@ static int nr_getname(struct socket *soc
56823 struct sock *sk = sock->sk;
56824 struct nr_sock *nr = nr_sk(sk);
56826 + memset(sax, 0, sizeof(*sax));
56829 if (sk->sk_state != TCP_ESTABLISHED) {
56830 @@ -854,7 +855,6 @@ static int nr_getname(struct socket *soc
56831 *uaddr_len = sizeof(struct full_sockaddr_ax25);
56833 sax->fsa_ax25.sax25_family = AF_NETROM;
56834 - sax->fsa_ax25.sax25_ndigis = 0;
56835 sax->fsa_ax25.sax25_call = nr->source_addr;
56836 *uaddr_len = sizeof(struct sockaddr_ax25);
56838 diff -urNp linux-2.6.37/net/packet/af_packet.c linux-2.6.37/net/packet/af_packet.c
56839 --- linux-2.6.37/net/packet/af_packet.c 2011-01-04 19:50:19.000000000 -0500
56840 +++ linux-2.6.37/net/packet/af_packet.c 2011-01-17 02:41:02.000000000 -0500
56841 @@ -2123,7 +2123,7 @@ static int packet_getsockopt(struct sock
56842 case PACKET_HDRLEN:
56843 if (len > sizeof(int))
56845 - if (copy_from_user(&val, optval, len))
56846 + if (len > sizeof(val) || copy_from_user(&val, optval, len))
56850 @@ -2161,7 +2161,7 @@ static int packet_getsockopt(struct sock
56852 if (put_user(len, optlen))
56854 - if (copy_to_user(optval, data, len))
56855 + if (len > sizeof(st) || copy_to_user(optval, data, len))
56859 @@ -2640,7 +2640,11 @@ static int packet_seq_show(struct seq_fi
56862 "%p %-6d %-4d %04x %-5d %1d %-6u %-6u %-6lu\n",
56863 +#ifdef CONFIG_GRKERNSEC_HIDESYM
56868 atomic_read(&s->sk_refcnt),
56871 diff -urNp linux-2.6.37/net/phonet/af_phonet.c linux-2.6.37/net/phonet/af_phonet.c
56872 --- linux-2.6.37/net/phonet/af_phonet.c 2011-01-04 19:50:19.000000000 -0500
56873 +++ linux-2.6.37/net/phonet/af_phonet.c 2011-01-17 02:41:02.000000000 -0500
56874 @@ -41,7 +41,7 @@ static struct phonet_protocol *phonet_pr
56876 struct phonet_protocol *pp;
56878 - if (protocol >= PHONET_NPROTO)
56879 + if (protocol < 0 || protocol >= PHONET_NPROTO)
56883 @@ -463,7 +463,7 @@ int __init_or_module phonet_proto_regist
56887 - if (protocol >= PHONET_NPROTO)
56888 + if (protocol < 0 || protocol >= PHONET_NPROTO)
56891 err = proto_register(pp->prot, 1);
56892 diff -urNp linux-2.6.37/net/phonet/socket.c linux-2.6.37/net/phonet/socket.c
56893 --- linux-2.6.37/net/phonet/socket.c 2011-01-04 19:50:19.000000000 -0500
56894 +++ linux-2.6.37/net/phonet/socket.c 2011-01-17 02:41:02.000000000 -0500
56895 @@ -637,7 +637,12 @@ static int pn_sock_seq_show(struct seq_f
56897 sk_wmem_alloc_get(sk), sk_rmem_alloc_get(sk),
56898 sock_i_uid(sk), sock_i_ino(sk),
56899 - atomic_read(&sk->sk_refcnt), sk,
56900 + atomic_read(&sk->sk_refcnt),
56901 +#ifdef CONFIG_GRKERNSEC_HIDESYM
56906 atomic_read(&sk->sk_drops), &len);
56908 seq_printf(seq, "%*s\n", 127 - len, "");
56909 diff -urNp linux-2.6.37/net/sctp/proc.c linux-2.6.37/net/sctp/proc.c
56910 --- linux-2.6.37/net/sctp/proc.c 2011-01-04 19:50:19.000000000 -0500
56911 +++ linux-2.6.37/net/sctp/proc.c 2011-01-17 02:41:02.000000000 -0500
56912 @@ -212,7 +212,12 @@ static int sctp_eps_seq_show(struct seq_
56913 sctp_for_each_hentry(epb, node, &head->chain) {
56916 - seq_printf(seq, "%8p %8p %-3d %-3d %-4d %-5d %5d %5lu ", ep, sk,
56917 + seq_printf(seq, "%8p %8p %-3d %-3d %-4d %-5d %5d %5lu ",
56918 +#ifdef CONFIG_GRKERNSEC_HIDESYM
56923 sctp_sk(sk)->type, sk->sk_state, hash,
56924 epb->bind_addr.port,
56925 sock_i_uid(sk), sock_i_ino(sk));
56926 @@ -318,7 +323,12 @@ static int sctp_assocs_seq_show(struct s
56928 "%8p %8p %-3d %-3d %-2d %-4d "
56929 "%4d %8d %8d %7d %5lu %-5d %5d ",
56930 - assoc, sk, sctp_sk(sk)->type, sk->sk_state,
56931 +#ifdef CONFIG_GRKERNSEC_HIDESYM
56936 + sctp_sk(sk)->type, sk->sk_state,
56937 assoc->state, hash,
56939 assoc->sndbuf_used,
56940 diff -urNp linux-2.6.37/net/sctp/socket.c linux-2.6.37/net/sctp/socket.c
56941 --- linux-2.6.37/net/sctp/socket.c 2011-01-04 19:50:19.000000000 -0500
56942 +++ linux-2.6.37/net/sctp/socket.c 2011-01-17 02:41:02.000000000 -0500
56943 @@ -1496,7 +1496,7 @@ SCTP_STATIC int sctp_sendmsg(struct kioc
56944 struct sctp_sndrcvinfo *sinfo;
56945 struct sctp_initmsg *sinit;
56946 sctp_assoc_t associd = 0;
56947 - sctp_cmsgs_t cmsgs = { NULL };
56948 + sctp_cmsgs_t cmsgs = { NULL, NULL };
56950 sctp_scope_t scope;
56952 @@ -4435,7 +4435,7 @@ static int sctp_getsockopt_peer_addrs(st
56953 addrlen = sctp_get_af_specific(temp.sa.sa_family)->sockaddr_len;
56954 if (space_left < addrlen)
56956 - if (copy_to_user(to, &temp, addrlen))
56957 + if (addrlen > sizeof(temp) || copy_to_user(to, &temp, addrlen))
56961 diff -urNp linux-2.6.37/net/socket.c linux-2.6.37/net/socket.c
56962 --- linux-2.6.37/net/socket.c 2011-01-04 19:50:19.000000000 -0500
56963 +++ linux-2.6.37/net/socket.c 2011-01-17 02:41:02.000000000 -0500
56965 #include <linux/nsproxy.h>
56966 #include <linux/magic.h>
56967 #include <linux/slab.h>
56968 +#include <linux/in.h>
56970 #include <asm/uaccess.h>
56971 #include <asm/unistd.h>
56972 @@ -105,6 +106,8 @@
56973 #include <linux/sockios.h>
56974 #include <linux/atalk.h>
56976 +#include <linux/grsock.h>
56978 static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
56979 static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
56980 unsigned long nr_segs, loff_t pos);
56981 @@ -311,7 +314,7 @@ static struct dentry *sockfs_mount(struc
56982 return mount_pseudo(fs_type, "socket:", &sockfs_ops, SOCKFS_MAGIC);
56985 -static struct vfsmount *sock_mnt __read_mostly;
56986 +struct vfsmount *sock_mnt __read_mostly;
56988 static struct file_system_type sock_fs_type = {
56990 @@ -1173,6 +1176,8 @@ int __sock_create(struct net *net, int f
56991 return -EAFNOSUPPORT;
56992 if (type < 0 || type >= SOCK_MAX)
56994 + if (protocol < 0)
56999 @@ -1305,6 +1310,16 @@ SYSCALL_DEFINE3(socket, int, family, int
57000 if (SOCK_NONBLOCK != O_NONBLOCK && (flags & SOCK_NONBLOCK))
57001 flags = (flags & ~SOCK_NONBLOCK) | O_NONBLOCK;
57003 + if(!gr_search_socket(family, type, protocol)) {
57004 + retval = -EACCES;
57008 + if (gr_handle_sock_all(family, type, protocol)) {
57009 + retval = -EACCES;
57013 retval = sock_create(family, type, protocol, &sock);
57016 @@ -1417,6 +1432,14 @@ SYSCALL_DEFINE3(bind, int, fd, struct so
57018 err = move_addr_to_kernel(umyaddr, addrlen, (struct sockaddr *)&address);
57020 + if (gr_handle_sock_server((struct sockaddr *)&address)) {
57024 + err = gr_search_bind(sock, (struct sockaddr_in *)&address);
57028 err = security_socket_bind(sock,
57029 (struct sockaddr *)&address,
57031 @@ -1425,6 +1448,7 @@ SYSCALL_DEFINE3(bind, int, fd, struct so
57032 (struct sockaddr *)
57033 &address, addrlen);
57036 fput_light(sock->file, fput_needed);
57039 @@ -1448,10 +1472,20 @@ SYSCALL_DEFINE2(listen, int, fd, int, ba
57040 if ((unsigned)backlog > somaxconn)
57041 backlog = somaxconn;
57043 + if (gr_handle_sock_server_other(sock->sk)) {
57048 + err = gr_search_listen(sock);
57052 err = security_socket_listen(sock, backlog);
57054 err = sock->ops->listen(sock, backlog);
57057 fput_light(sock->file, fput_needed);
57060 @@ -1495,6 +1529,18 @@ SYSCALL_DEFINE4(accept4, int, fd, struct
57061 newsock->type = sock->type;
57062 newsock->ops = sock->ops;
57064 + if (gr_handle_sock_server_other(sock->sk)) {
57066 + sock_release(newsock);
57070 + err = gr_search_accept(sock);
57072 + sock_release(newsock);
57077 * We don't need try_module_get here, as the listening socket (sock)
57078 * has the protocol module (sock->ops->owner) held.
57079 @@ -1533,6 +1579,8 @@ SYSCALL_DEFINE4(accept4, int, fd, struct
57080 fd_install(newfd, newfile);
57083 + gr_attach_curr_ip(newsock->sk);
57086 fput_light(sock->file, fput_needed);
57088 @@ -1565,6 +1613,7 @@ SYSCALL_DEFINE3(connect, int, fd, struct
57091 struct socket *sock;
57092 + struct sockaddr *sck;
57093 struct sockaddr_storage address;
57094 int err, fput_needed;
57096 @@ -1575,6 +1624,17 @@ SYSCALL_DEFINE3(connect, int, fd, struct
57100 + sck = (struct sockaddr *)&address;
57102 + if (gr_handle_sock_client(sck)) {
57107 + err = gr_search_connect(sock, (struct sockaddr_in *)sck);
57112 security_socket_connect(sock, (struct sockaddr *)&address, addrlen);
57114 diff -urNp linux-2.6.37/net/sunrpc/sched.c linux-2.6.37/net/sunrpc/sched.c
57115 --- linux-2.6.37/net/sunrpc/sched.c 2011-01-04 19:50:19.000000000 -0500
57116 +++ linux-2.6.37/net/sunrpc/sched.c 2011-01-17 02:41:02.000000000 -0500
57117 @@ -234,9 +234,9 @@ static int rpc_wait_bit_killable(void *w
57119 static void rpc_task_set_debuginfo(struct rpc_task *task)
57121 - static atomic_t rpc_pid;
57122 + static atomic_unchecked_t rpc_pid;
57124 - task->tk_pid = atomic_inc_return(&rpc_pid);
57125 + task->tk_pid = atomic_inc_return_unchecked(&rpc_pid);
57128 static inline void rpc_task_set_debuginfo(struct rpc_task *task)
57129 diff -urNp linux-2.6.37/net/sunrpc/xprtrdma/svc_rdma.c linux-2.6.37/net/sunrpc/xprtrdma/svc_rdma.c
57130 --- linux-2.6.37/net/sunrpc/xprtrdma/svc_rdma.c 2011-01-04 19:50:19.000000000 -0500
57131 +++ linux-2.6.37/net/sunrpc/xprtrdma/svc_rdma.c 2011-01-17 02:41:02.000000000 -0500
57132 @@ -109,7 +109,7 @@ static int read_reset_stat(ctl_table *ta
57136 - if (len && copy_to_user(buffer, str_buf, len))
57137 + if (len > sizeof str_buf || (len && copy_to_user(buffer, str_buf, len)))
57141 diff -urNp linux-2.6.37/net/sysctl_net.c linux-2.6.37/net/sysctl_net.c
57142 --- linux-2.6.37/net/sysctl_net.c 2011-01-04 19:50:19.000000000 -0500
57143 +++ linux-2.6.37/net/sysctl_net.c 2011-01-17 02:41:02.000000000 -0500
57144 @@ -46,7 +46,7 @@ static int net_ctl_permissions(struct ct
57145 struct ctl_table *table)
57147 /* Allow network administrator to have same access as root. */
57148 - if (capable(CAP_NET_ADMIN)) {
57149 + if (capable_nolog(CAP_NET_ADMIN)) {
57150 int mode = (table->mode >> 6) & 7;
57151 return (mode << 6) | (mode << 3) | mode;
57153 diff -urNp linux-2.6.37/net/tipc/socket.c linux-2.6.37/net/tipc/socket.c
57154 --- linux-2.6.37/net/tipc/socket.c 2011-01-04 19:50:19.000000000 -0500
57155 +++ linux-2.6.37/net/tipc/socket.c 2011-01-17 02:41:02.000000000 -0500
57156 @@ -1475,8 +1475,9 @@ static int connect(struct socket *sock,
57161 - ; /* leave "res" unchanged */
57163 + /* leave "res" unchanged */
57165 sock->state = SS_DISCONNECTING;
57168 diff -urNp linux-2.6.37/net/unix/af_unix.c linux-2.6.37/net/unix/af_unix.c
57169 --- linux-2.6.37/net/unix/af_unix.c 2011-01-04 19:50:19.000000000 -0500
57170 +++ linux-2.6.37/net/unix/af_unix.c 2011-01-17 02:41:02.000000000 -0500
57171 @@ -764,6 +764,12 @@ static struct sock *unix_find_other(stru
57172 err = -ECONNREFUSED;
57173 if (!S_ISSOCK(inode->i_mode))
57176 + if (!gr_acl_handle_unix(path.dentry, path.mnt)) {
57181 u = unix_find_socket_byinode(inode);
57184 @@ -784,6 +790,13 @@ static struct sock *unix_find_other(stru
57186 struct dentry *dentry;
57187 dentry = unix_sk(u)->dentry;
57189 + if (!gr_handle_chroot_unix(u->sk_peer_pid)) {
57196 touch_atime(unix_sk(u)->mnt, dentry);
57198 @@ -869,11 +882,18 @@ static int unix_bind(struct socket *sock
57199 err = security_path_mknod(&nd.path, dentry, mode, 0);
57201 goto out_mknod_drop_write;
57202 + if (!gr_acl_handle_mknod(dentry, nd.path.dentry, nd.path.mnt, mode)) {
57204 + goto out_mknod_drop_write;
57206 err = vfs_mknod(nd.path.dentry->d_inode, dentry, mode, 0);
57207 out_mknod_drop_write:
57208 mnt_drop_write(nd.path.mnt);
57210 goto out_mknod_dput;
57212 + gr_handle_create(dentry, nd.path.mnt);
57214 mutex_unlock(&nd.path.dentry->d_inode->i_mutex);
57215 dput(nd.path.dentry);
57216 nd.path.dentry = dentry;
57217 @@ -891,6 +911,11 @@ out_mknod_drop_write:
57221 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
57222 + put_pid(sk->sk_peer_pid);
57223 + sk->sk_peer_pid = get_pid(task_tgid(current));
57226 list = &unix_socket_table[addr->hash];
57228 list = &unix_socket_table[dentry->d_inode->i_ino & (UNIX_HASH_SIZE-1)];
57229 @@ -2226,7 +2251,11 @@ static int unix_seq_show(struct seq_file
57230 unix_state_lock(s);
57232 seq_printf(seq, "%p: %08X %08X %08X %04X %02X %5lu",
57233 +#ifdef CONFIG_GRKERNSEC_HIDESYM
57238 atomic_read(&s->sk_refcnt),
57240 s->sk_state == TCP_LISTEN ? __SO_ACCEPTCON : 0,
57241 diff -urNp linux-2.6.37/net/wireless/reg.c linux-2.6.37/net/wireless/reg.c
57242 --- linux-2.6.37/net/wireless/reg.c 2011-01-04 19:50:19.000000000 -0500
57243 +++ linux-2.6.37/net/wireless/reg.c 2011-01-17 02:41:02.000000000 -0500
57245 printk(KERN_DEBUG format , ## args); \
57248 -#define REG_DBG_PRINT(args...)
57249 +#define REG_DBG_PRINT(args...) do {} while (0)
57252 /* Receipt of information from last regulatory request */
57253 diff -urNp linux-2.6.37/net/wireless/wext-core.c linux-2.6.37/net/wireless/wext-core.c
57254 --- linux-2.6.37/net/wireless/wext-core.c 2011-01-04 19:50:19.000000000 -0500
57255 +++ linux-2.6.37/net/wireless/wext-core.c 2011-01-17 02:41:02.000000000 -0500
57256 @@ -744,8 +744,7 @@ static int ioctl_standard_iw_point(struc
57259 /* Support for very large requests */
57260 - if ((descr->flags & IW_DESCR_FLAG_NOMAX) &&
57261 - (user_length > descr->max_tokens)) {
57262 + if (user_length > descr->max_tokens) {
57263 /* Allow userspace to GET more than max so
57264 * we can support any size GET requests.
57265 * There is still a limit : -ENOMEM.
57266 @@ -782,22 +781,6 @@ static int ioctl_standard_iw_point(struc
57270 - if (IW_IS_GET(cmd) && !(descr->flags & IW_DESCR_FLAG_NOMAX)) {
57272 - * If this is a GET, but not NOMAX, it means that the extra
57273 - * data is not bounded by userspace, but by max_tokens. Thus
57274 - * set the length to max_tokens. This matches the extra data
57276 - * The driver should fill it with the number of tokens it
57277 - * provided, and it may check iwp->length rather than having
57278 - * knowledge of max_tokens. If the driver doesn't change the
57279 - * iwp->length, this ioctl just copies back max_token tokens
57280 - * filled with zeroes. Hopefully the driver isn't claiming
57281 - * them to be valid data.
57283 - iwp->length = descr->max_tokens;
57286 err = handler(dev, info, (union iwreq_data *) iwp, extra);
57288 iwp->length += essid_compat;
57289 diff -urNp linux-2.6.37/net/x25/x25_facilities.c linux-2.6.37/net/x25/x25_facilities.c
57290 --- linux-2.6.37/net/x25/x25_facilities.c 2011-01-04 19:50:19.000000000 -0500
57291 +++ linux-2.6.37/net/x25/x25_facilities.c 2011-01-17 02:41:02.000000000 -0500
57292 @@ -157,7 +157,8 @@ int x25_parse_facilities(struct sk_buff
57295 printk(KERN_DEBUG "X.25: unknown facility %02X,"
57296 - "length %d\n", p[0], p[1]);
57297 + "length %d, values %02X, %02X\n",
57298 + p[0], p[1], p[2], p[3]);
57302 diff -urNp linux-2.6.37/net/xfrm/xfrm_policy.c linux-2.6.37/net/xfrm/xfrm_policy.c
57303 --- linux-2.6.37/net/xfrm/xfrm_policy.c 2011-01-04 19:50:19.000000000 -0500
57304 +++ linux-2.6.37/net/xfrm/xfrm_policy.c 2011-01-17 02:41:02.000000000 -0500
57305 @@ -1504,7 +1504,7 @@ free_dst:
57311 xfrm_dst_alloc_copy(void **target, void *src, int size)
57314 @@ -1516,7 +1516,7 @@ xfrm_dst_alloc_copy(void **target, void
57320 xfrm_dst_update_parent(struct dst_entry *dst, struct xfrm_selector *sel)
57322 #ifdef CONFIG_XFRM_SUB_POLICY
57323 @@ -1528,7 +1528,7 @@ xfrm_dst_update_parent(struct dst_entry
57329 xfrm_dst_update_origin(struct dst_entry *dst, struct flowi *fl)
57331 #ifdef CONFIG_XFRM_SUB_POLICY
57332 diff -urNp linux-2.6.37/scripts/basic/fixdep.c linux-2.6.37/scripts/basic/fixdep.c
57333 --- linux-2.6.37/scripts/basic/fixdep.c 2011-01-04 19:50:19.000000000 -0500
57334 +++ linux-2.6.37/scripts/basic/fixdep.c 2011-01-17 02:41:02.000000000 -0500
57335 @@ -222,9 +222,9 @@ static void use_config(char *m, int slen
57337 static void parse_config_file(char *map, size_t len)
57339 - int *end = (int *) (map + len);
57340 + unsigned int *end = (unsigned int *) (map + len);
57341 /* start at +1, so that p can never be < map */
57342 - int *m = (int *) map + 1;
57343 + unsigned int *m = (unsigned int *) map + 1;
57346 for (; m < end; m++) {
57347 @@ -371,7 +371,7 @@ static void print_deps(void)
57348 static void traps(void)
57350 static char test[] __attribute__((aligned(sizeof(int)))) = "CONF";
57351 - int *p = (int *)test;
57352 + unsigned int *p = (unsigned int *)test;
57354 if (*p != INT_CONF) {
57355 fprintf(stderr, "fixdep: sizeof(int) != 4 or wrong endianess? %#x\n",
57356 diff -urNp linux-2.6.37/scripts/kallsyms.c linux-2.6.37/scripts/kallsyms.c
57357 --- linux-2.6.37/scripts/kallsyms.c 2011-01-04 19:50:19.000000000 -0500
57358 +++ linux-2.6.37/scripts/kallsyms.c 2011-01-17 02:41:02.000000000 -0500
57359 @@ -43,10 +43,10 @@ struct text_range {
57361 static unsigned long long _text;
57362 static struct text_range text_ranges[] = {
57363 - { "_stext", "_etext" },
57364 - { "_sinittext", "_einittext" },
57365 - { "_stext_l1", "_etext_l1" }, /* Blackfin on-chip L1 inst SRAM */
57366 - { "_stext_l2", "_etext_l2" }, /* Blackfin on-chip L2 SRAM */
57367 + { "_stext", "_etext", 0, 0 },
57368 + { "_sinittext", "_einittext", 0, 0 },
57369 + { "_stext_l1", "_etext_l1", 0, 0 }, /* Blackfin on-chip L1 inst SRAM */
57370 + { "_stext_l2", "_etext_l2", 0, 0 }, /* Blackfin on-chip L2 SRAM */
57372 #define text_range_text (&text_ranges[0])
57373 #define text_range_inittext (&text_ranges[1])
57374 diff -urNp linux-2.6.37/scripts/mod/file2alias.c linux-2.6.37/scripts/mod/file2alias.c
57375 --- linux-2.6.37/scripts/mod/file2alias.c 2011-01-04 19:50:19.000000000 -0500
57376 +++ linux-2.6.37/scripts/mod/file2alias.c 2011-01-17 02:41:02.000000000 -0500
57377 @@ -72,7 +72,7 @@ static void device_id_check(const char *
57378 unsigned long size, unsigned long id_size,
57384 if (size % id_size || size < id_size) {
57385 if (cross_build != 0)
57386 @@ -102,7 +102,7 @@ static void device_id_check(const char *
57387 /* USB is special because the bcdDevice can be matched against a numeric range */
57388 /* Looks like "usb:vNpNdNdcNdscNdpNicNiscNipN" */
57389 static void do_usb_entry(struct usb_device_id *id,
57390 - unsigned int bcdDevice_initial, int bcdDevice_initial_digits,
57391 + unsigned int bcdDevice_initial, unsigned int bcdDevice_initial_digits,
57392 unsigned char range_lo, unsigned char range_hi,
57393 unsigned char max, struct module *mod)
57395 @@ -437,7 +437,7 @@ static void do_pnp_device_entry(void *sy
57396 for (i = 0; i < count; i++) {
57397 const char *id = (char *)devs[i].id;
57398 char acpi_id[sizeof(devs[0].id)];
57402 buf_printf(&mod->dev_table_buf,
57403 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
57404 @@ -467,7 +467,7 @@ static void do_pnp_card_entries(void *sy
57406 for (j = 0; j < PNP_MAX_DEVICES; j++) {
57407 const char *id = (char *)card->devs[j].id;
57409 + unsigned int i2, j2;
57413 @@ -493,7 +493,7 @@ static void do_pnp_card_entries(void *sy
57414 /* add an individual alias for every device entry */
57416 char acpi_id[sizeof(card->devs[0].id)];
57420 buf_printf(&mod->dev_table_buf,
57421 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
57422 @@ -768,7 +768,7 @@ static void dmi_ascii_filter(char *d, co
57423 static int do_dmi_entry(const char *filename, struct dmi_system_id *id,
57427 + unsigned int i, j;
57429 sprintf(alias, "dmi*");
57431 diff -urNp linux-2.6.37/scripts/mod/modpost.c linux-2.6.37/scripts/mod/modpost.c
57432 --- linux-2.6.37/scripts/mod/modpost.c 2011-01-04 19:50:19.000000000 -0500
57433 +++ linux-2.6.37/scripts/mod/modpost.c 2011-01-17 02:41:02.000000000 -0500
57434 @@ -895,6 +895,7 @@ enum mismatch {
57435 ANY_INIT_TO_ANY_EXIT,
57436 ANY_EXIT_TO_ANY_INIT,
57437 EXPORT_TO_INIT_EXIT,
57441 struct sectioncheck {
57442 @@ -1003,6 +1004,12 @@ const struct sectioncheck sectioncheck[]
57443 .tosec = { INIT_SECTIONS, EXIT_SECTIONS, NULL },
57444 .mismatch = EXPORT_TO_INIT_EXIT,
57445 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
57447 +/* Do not reference code from writable data */
57449 + .fromsec = { DATA_SECTIONS, NULL },
57450 + .tosec = { TEXT_SECTIONS, NULL },
57451 + .mismatch = DATA_TO_TEXT
57455 @@ -1125,10 +1132,10 @@ static Elf_Sym *find_elf_symbol(struct e
57457 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
57459 - if (sym->st_value == addr)
57461 /* Find a symbol nearby - addr are maybe negative */
57462 d = sym->st_value - addr;
57466 d = addr - sym->st_value;
57467 if (d < distance) {
57468 @@ -1400,6 +1407,14 @@ static void report_sec_mismatch(const ch
57469 tosym, prl_to, prl_to, tosym);
57472 + case DATA_TO_TEXT:
57475 + "The variable %s references\n"
57476 + "the %s %s%s%s\n",
57477 + fromsym, to, sec2annotation(tosec), tosym, to_p);
57481 fprintf(stderr, "\n");
57483 @@ -1723,7 +1738,7 @@ void __attribute__((format(printf, 2, 3)
57487 -void buf_write(struct buffer *buf, const char *s, int len)
57488 +void buf_write(struct buffer *buf, const char *s, unsigned int len)
57490 if (buf->size - buf->pos < len) {
57491 buf->size += len + SZ;
57492 @@ -1935,7 +1950,7 @@ static void write_if_changed(struct buff
57493 if (fstat(fileno(file), &st) < 0)
57496 - if (st.st_size != b->pos)
57497 + if (st.st_size != (off_t)b->pos)
57500 tmp = NOFAIL(malloc(b->pos));
57501 diff -urNp linux-2.6.37/scripts/mod/modpost.h linux-2.6.37/scripts/mod/modpost.h
57502 --- linux-2.6.37/scripts/mod/modpost.h 2011-01-04 19:50:19.000000000 -0500
57503 +++ linux-2.6.37/scripts/mod/modpost.h 2011-01-17 02:41:02.000000000 -0500
57504 @@ -92,15 +92,15 @@ void *do_nofail(void *ptr, const char *e
57510 + unsigned int pos;
57511 + unsigned int size;
57514 void __attribute__((format(printf, 2, 3)))
57515 buf_printf(struct buffer *buf, const char *fmt, ...);
57518 -buf_write(struct buffer *buf, const char *s, int len);
57519 +buf_write(struct buffer *buf, const char *s, unsigned int len);
57522 struct module *next;
57523 diff -urNp linux-2.6.37/scripts/mod/sumversion.c linux-2.6.37/scripts/mod/sumversion.c
57524 --- linux-2.6.37/scripts/mod/sumversion.c 2011-01-04 19:50:19.000000000 -0500
57525 +++ linux-2.6.37/scripts/mod/sumversion.c 2011-01-17 02:41:02.000000000 -0500
57526 @@ -455,7 +455,7 @@ static void write_version(const char *fi
57530 - if (write(fd, sum, strlen(sum)+1) != strlen(sum)+1) {
57531 + if (write(fd, sum, strlen(sum)+1) != (ssize_t)strlen(sum)+1) {
57532 warn("writing sum in %s failed: %s\n",
57533 filename, strerror(errno));
57535 diff -urNp linux-2.6.37/scripts/pnmtologo.c linux-2.6.37/scripts/pnmtologo.c
57536 --- linux-2.6.37/scripts/pnmtologo.c 2011-01-04 19:50:19.000000000 -0500
57537 +++ linux-2.6.37/scripts/pnmtologo.c 2011-01-17 02:41:02.000000000 -0500
57538 @@ -237,14 +237,14 @@ static void write_header(void)
57539 fprintf(out, " * Linux logo %s\n", logoname);
57540 fputs(" */\n\n", out);
57541 fputs("#include <linux/linux_logo.h>\n\n", out);
57542 - fprintf(out, "static unsigned char %s_data[] __initdata = {\n",
57543 + fprintf(out, "static unsigned char %s_data[] = {\n",
57547 static void write_footer(void)
57549 fputs("\n};\n\n", out);
57550 - fprintf(out, "const struct linux_logo %s __initconst = {\n", logoname);
57551 + fprintf(out, "const struct linux_logo %s = {\n", logoname);
57552 fprintf(out, "\t.type\t\t= %s,\n", logo_types[logo_type]);
57553 fprintf(out, "\t.width\t\t= %d,\n", logo_width);
57554 fprintf(out, "\t.height\t\t= %d,\n", logo_height);
57555 @@ -374,7 +374,7 @@ static void write_logo_clut224(void)
57556 fputs("\n};\n\n", out);
57558 /* write logo clut */
57559 - fprintf(out, "static unsigned char %s_clut[] __initdata = {\n",
57560 + fprintf(out, "static unsigned char %s_clut[] = {\n",
57563 for (i = 0; i < logo_clutsize; i++) {
57564 diff -urNp linux-2.6.37/security/apparmor/lsm.c linux-2.6.37/security/apparmor/lsm.c
57565 --- linux-2.6.37/security/apparmor/lsm.c 2011-01-04 19:50:19.000000000 -0500
57566 +++ linux-2.6.37/security/apparmor/lsm.c 2011-01-17 02:41:02.000000000 -0500
57567 @@ -619,7 +619,7 @@ static int apparmor_task_setrlimit(struc
57571 -static struct security_operations apparmor_ops = {
57572 +static struct security_operations apparmor_ops __read_only = {
57573 .name = "apparmor",
57575 .ptrace_access_check = apparmor_ptrace_access_check,
57576 diff -urNp linux-2.6.37/security/commoncap.c linux-2.6.37/security/commoncap.c
57577 --- linux-2.6.37/security/commoncap.c 2011-01-04 19:50:19.000000000 -0500
57578 +++ linux-2.6.37/security/commoncap.c 2011-01-17 02:41:02.000000000 -0500
57580 #include <linux/prctl.h>
57581 #include <linux/securebits.h>
57582 // #include <linux/vs_context.h>
57583 +#include <net/sock.h>
57586 * If a non-root user executes a setuid-root binary in
57587 @@ -50,9 +51,11 @@ static void warn_setuid_and_fcaps_mixed(
57591 +extern kernel_cap_t gr_cap_rtnetlink(struct sock *sk);
57593 int cap_netlink_send(struct sock *sk, struct sk_buff *skb)
57595 - NETLINK_CB(skb).eff_cap = vx_mbcaps(current_cap());
57596 + NETLINK_CB(skb).eff_cap = vx_mbcaps(gr_cap_rtnetlink(sk));
57600 @@ -534,6 +537,9 @@ int cap_bprm_secureexec(struct linux_bin
57602 const struct cred *cred = current_cred();
57604 + if (gr_acl_enable_at_secure())
57607 if (cred->uid != 0) {
57608 if (bprm->cap_effective)
57610 diff -urNp linux-2.6.37/security/integrity/ima/ima_api.c linux-2.6.37/security/integrity/ima/ima_api.c
57611 --- linux-2.6.37/security/integrity/ima/ima_api.c 2011-01-04 19:50:19.000000000 -0500
57612 +++ linux-2.6.37/security/integrity/ima/ima_api.c 2011-01-17 02:41:02.000000000 -0500
57613 @@ -75,7 +75,7 @@ void ima_add_violation(struct inode *ino
57616 /* can overflow, only indicator */
57617 - atomic_long_inc(&ima_htable.violations);
57618 + atomic_long_inc_unchecked(&ima_htable.violations);
57620 entry = kmalloc(sizeof(*entry), GFP_KERNEL);
57622 diff -urNp linux-2.6.37/security/integrity/ima/ima_fs.c linux-2.6.37/security/integrity/ima/ima_fs.c
57623 --- linux-2.6.37/security/integrity/ima/ima_fs.c 2011-01-04 19:50:19.000000000 -0500
57624 +++ linux-2.6.37/security/integrity/ima/ima_fs.c 2011-01-17 02:41:02.000000000 -0500
57625 @@ -28,12 +28,12 @@
57626 static int valid_policy = 1;
57627 #define TMPBUFLEN 12
57628 static ssize_t ima_show_htable_value(char __user *buf, size_t count,
57629 - loff_t *ppos, atomic_long_t *val)
57630 + loff_t *ppos, atomic_long_unchecked_t *val)
57632 char tmpbuf[TMPBUFLEN];
57635 - len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read(val));
57636 + len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read_unchecked(val));
57637 return simple_read_from_buffer(buf, count, ppos, tmpbuf, len);
57640 diff -urNp linux-2.6.37/security/integrity/ima/ima.h linux-2.6.37/security/integrity/ima/ima.h
57641 --- linux-2.6.37/security/integrity/ima/ima.h 2011-01-04 19:50:19.000000000 -0500
57642 +++ linux-2.6.37/security/integrity/ima/ima.h 2011-01-17 02:41:02.000000000 -0500
57643 @@ -85,8 +85,8 @@ void ima_add_violation(struct inode *ino
57644 extern spinlock_t ima_queue_lock;
57646 struct ima_h_table {
57647 - atomic_long_t len; /* number of stored measurements in the list */
57648 - atomic_long_t violations;
57649 + atomic_long_unchecked_t len; /* number of stored measurements in the list */
57650 + atomic_long_unchecked_t violations;
57651 struct hlist_head queue[IMA_MEASURE_HTABLE_SIZE];
57653 extern struct ima_h_table ima_htable;
57654 diff -urNp linux-2.6.37/security/integrity/ima/ima_queue.c linux-2.6.37/security/integrity/ima/ima_queue.c
57655 --- linux-2.6.37/security/integrity/ima/ima_queue.c 2011-01-04 19:50:19.000000000 -0500
57656 +++ linux-2.6.37/security/integrity/ima/ima_queue.c 2011-01-17 02:41:02.000000000 -0500
57657 @@ -79,7 +79,7 @@ static int ima_add_digest_entry(struct i
57658 INIT_LIST_HEAD(&qe->later);
57659 list_add_tail_rcu(&qe->later, &ima_measurements);
57661 - atomic_long_inc(&ima_htable.len);
57662 + atomic_long_inc_unchecked(&ima_htable.len);
57663 key = ima_hash_key(entry->digest);
57664 hlist_add_head_rcu(&qe->hnext, &ima_htable.queue[key]);
57666 diff -urNp linux-2.6.37/security/Kconfig linux-2.6.37/security/Kconfig
57667 --- linux-2.6.37/security/Kconfig 2011-01-04 19:50:19.000000000 -0500
57668 +++ linux-2.6.37/security/Kconfig 2011-01-17 02:41:02.000000000 -0500
57671 menu "Security options"
57673 +source grsecurity/Kconfig
57677 + config ARCH_TRACK_EXEC_LIMIT
57680 + config PAX_PER_CPU_PGD
57683 + config TASK_SIZE_MAX_SHIFT
57685 + depends on X86_64
57686 + default 47 if !PAX_PER_CPU_PGD
57687 + default 42 if PAX_PER_CPU_PGD
57689 + config PAX_ENABLE_PAE
57691 + default y if (X86_32 && (MPENTIUM4 || MK8 || MPSC || MCORE2 || MATOM))
57694 + bool "Enable various PaX features"
57695 + depends on GRKERNSEC && (ALPHA || ARM || AVR32 || IA64 || MIPS || PARISC || PPC || SPARC || X86)
57697 + This allows you to enable various PaX features. PaX adds
57698 + intrusion prevention mechanisms to the kernel that reduce
57699 + the risks posed by exploitable memory corruption bugs.
57701 +menu "PaX Control"
57704 +config PAX_SOFTMODE
57705 + bool 'Support soft mode'
57706 + select PAX_PT_PAX_FLAGS
57708 + Enabling this option will allow you to run PaX in soft mode, that
57709 + is, PaX features will not be enforced by default, only on executables
57710 + marked explicitly. You must also enable PT_PAX_FLAGS support as it
57711 + is the only way to mark executables for soft mode use.
57713 + Soft mode can be activated by using the "pax_softmode=1" kernel command
57714 + line option on boot. Furthermore you can control various PaX features
57715 + at runtime via the entries in /proc/sys/kernel/pax.
57718 + bool 'Use legacy ELF header marking'
57720 + Enabling this option will allow you to control PaX features on
57721 + a per executable basis via the 'chpax' utility available at
57722 + http://pax.grsecurity.net/. The control flags will be read from
57723 + an otherwise reserved part of the ELF header. This marking has
57724 + numerous drawbacks (no support for soft-mode, toolchain does not
57725 + know about the non-standard use of the ELF header) therefore it
57726 + has been deprecated in favour of PT_PAX_FLAGS support.
57728 + If you have applications not marked by the PT_PAX_FLAGS ELF
57729 + program header then you MUST enable this option otherwise they
57730 + will not get any protection.
57732 + Note that if you enable PT_PAX_FLAGS marking support as well,
57733 + the PT_PAX_FLAG marks will override the legacy EI_PAX marks.
57735 +config PAX_PT_PAX_FLAGS
57736 + bool 'Use ELF program header marking'
57738 + Enabling this option will allow you to control PaX features on
57739 + a per executable basis via the 'paxctl' utility available at
57740 + http://pax.grsecurity.net/. The control flags will be read from
57741 + a PaX specific ELF program header (PT_PAX_FLAGS). This marking
57742 + has the benefits of supporting both soft mode and being fully
57743 + integrated into the toolchain (the binutils patch is available
57744 + from http://pax.grsecurity.net).
57746 + If you have applications not marked by the PT_PAX_FLAGS ELF
57747 + program header then you MUST enable the EI_PAX marking support
57748 + otherwise they will not get any protection.
57750 + Note that if you enable the legacy EI_PAX marking support as well,
57751 + the EI_PAX marks will be overridden by the PT_PAX_FLAGS marks.
57754 + prompt 'MAC system integration'
57755 + default PAX_HAVE_ACL_FLAGS
57757 + Mandatory Access Control systems have the option of controlling
57758 + PaX flags on a per executable basis, choose the method supported
57759 + by your particular system.
57761 + - "none": if your MAC system does not interact with PaX,
57762 + - "direct": if your MAC system defines pax_set_initial_flags() itself,
57763 + - "hook": if your MAC system uses the pax_set_initial_flags_func callback.
57765 + NOTE: this option is for developers/integrators only.
57767 + config PAX_NO_ACL_FLAGS
57770 + config PAX_HAVE_ACL_FLAGS
57773 + config PAX_HOOK_ACL_FLAGS
57779 +menu "Non-executable pages"
57783 + bool "Enforce non-executable pages"
57784 + depends on (PAX_EI_PAX || PAX_PT_PAX_FLAGS || PAX_HAVE_ACL_FLAGS || PAX_HOOK_ACL_FLAGS) && (ALPHA || (ARM && (CPU_V6 || CPU_V7)) || IA64 || MIPS || PARISC || PPC || S390 || SPARC || X86)
57786 + By design some architectures do not allow for protecting memory
57787 + pages against execution or even if they do, Linux does not make
57788 + use of this feature. In practice this means that if a page is
57789 + readable (such as the stack or heap) it is also executable.
57791 + There is a well known exploit technique that makes use of this
57792 + fact and a common programming mistake where an attacker can
57793 + introduce code of his choice somewhere in the attacked program's
57794 + memory (typically the stack or the heap) and then execute it.
57796 + If the attacked program was running with different (typically
57797 + higher) privileges than that of the attacker, then he can elevate
57798 + his own privilege level (e.g. get a root shell, write to files for
57799 + which he does not have write access to, etc).
57801 + Enabling this option will let you choose from various features
57802 + that prevent the injection and execution of 'foreign' code in
57805 + This will also break programs that rely on the old behaviour and
57806 + expect that dynamically allocated memory via the malloc() family
57807 + of functions is executable (which it is not). Notable examples
57808 + are the XFree86 4.x server, the java runtime and wine.
57810 +config PAX_PAGEEXEC
57811 + bool "Paging based non-executable pages"
57812 + depends on PAX_NOEXEC && (!X86_32 || M586 || M586TSC || M586MMX || M686 || MPENTIUMII || MPENTIUMIII || MPENTIUMM || MCORE2 || MATOM || MPENTIUM4 || MPSC || MK7 || MK8 || MWINCHIPC6 || MWINCHIP2 || MWINCHIP3D || MVIAC3_2 || MVIAC7)
57813 + select S390_SWITCH_AMODE if S390
57814 + select S390_EXEC_PROTECT if S390
57815 + select ARCH_TRACK_EXEC_LIMIT if X86_32
57817 + This implementation is based on the paging feature of the CPU.
57818 + On i386 without hardware non-executable bit support there is a
57819 + variable but usually low performance impact, however on Intel's
57820 + P4 core based CPUs it is very high so you should not enable this
57821 + for kernels meant to be used on such CPUs.
57823 + On alpha, avr32, ia64, parisc, sparc, sparc64, x86_64 and i386
57824 + with hardware non-executable bit support there is no performance
57825 + impact, on ppc the impact is negligible.
57827 + Note that several architectures require various emulations due to
57828 + badly designed userland ABIs, this will cause a performance impact
57829 + but will disappear as soon as userland is fixed. For example, ppc
57830 + userland MUST have been built with secure-plt by a recent toolchain.
57832 +config PAX_SEGMEXEC
57833 + bool "Segmentation based non-executable pages"
57834 + depends on PAX_NOEXEC && X86_32
57836 + This implementation is based on the segmentation feature of the
57837 + CPU and has a very small performance impact, however applications
57838 + will be limited to a 1.5 GB address space instead of the normal
57841 +config PAX_EMUTRAMP
57842 + bool "Emulate trampolines" if (PAX_PAGEEXEC || PAX_SEGMEXEC) && (PARISC || X86)
57843 + default y if PARISC
57845 + There are some programs and libraries that for one reason or
57846 + another attempt to execute special small code snippets from
57847 + non-executable memory pages. Most notable examples are the
57848 + signal handler return code generated by the kernel itself and
57849 + the GCC trampolines.
57851 + If you enabled CONFIG_PAX_PAGEEXEC or CONFIG_PAX_SEGMEXEC then
57852 + such programs will no longer work under your kernel.
57854 + As a remedy you can say Y here and use the 'chpax' or 'paxctl'
57855 + utilities to enable trampoline emulation for the affected programs
57856 + yet still have the protection provided by the non-executable pages.
57858 + On parisc you MUST enable this option and EMUSIGRT as well, otherwise
57859 + your system will not even boot.
57861 + Alternatively you can say N here and use the 'chpax' or 'paxctl'
57862 + utilities to disable CONFIG_PAX_PAGEEXEC and CONFIG_PAX_SEGMEXEC
57863 + for the affected files.
57865 + NOTE: enabling this feature *may* open up a loophole in the
57866 + protection provided by non-executable pages that an attacker
57867 + could abuse. Therefore the best solution is to not have any
57868 + files on your system that would require this option. This can
57869 + be achieved by not using libc5 (which relies on the kernel
57870 + signal handler return code) and not using or rewriting programs
57871 + that make use of the nested function implementation of GCC.
57872 + Skilled users can just fix GCC itself so that it implements
57873 + nested function calls in a way that does not interfere with PaX.
57875 +config PAX_EMUSIGRT
57876 + bool "Automatically emulate sigreturn trampolines"
57877 + depends on PAX_EMUTRAMP && PARISC
57880 + Enabling this option will have the kernel automatically detect
57881 + and emulate signal return trampolines executing on the stack
57882 + that would otherwise lead to task termination.
57884 + This solution is intended as a temporary one for users with
57885 + legacy versions of libc (libc5, glibc 2.0, uClibc before 0.9.17,
57886 + Modula-3 runtime, etc) or executables linked to such, basically
57887 + everything that does not specify its own SA_RESTORER function in
57888 + normal executable memory like glibc 2.1+ does.
57890 + On parisc you MUST enable this option, otherwise your system will
57893 + NOTE: this feature cannot be disabled on a per executable basis
57894 + and since it *does* open up a loophole in the protection provided
57895 + by non-executable pages, the best solution is to not have any
57896 + files on your system that would require this option.
57898 +config PAX_MPROTECT
57899 + bool "Restrict mprotect()"
57900 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC)
57902 + Enabling this option will prevent programs from
57903 + - changing the executable status of memory pages that were
57904 + not originally created as executable,
57905 + - making read-only executable pages writable again,
57906 + - creating executable pages from anonymous memory,
57907 + - making read-only-after-relocations (RELRO) data pages writable again.
57909 + You should say Y here to complete the protection provided by
57910 + the enforcement of non-executable pages.
57912 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
57913 + this feature on a per file basis.
57915 +config PAX_ELFRELOCS
57916 + bool "Allow ELF text relocations (read help)"
57917 + depends on PAX_MPROTECT
57920 + Non-executable pages and mprotect() restrictions are effective
57921 + in preventing the introduction of new executable code into an
57922 + attacked task's address space. There remain only two venues
57923 + for this kind of attack: if the attacker can execute already
57924 + existing code in the attacked task then he can either have it
57925 + create and mmap() a file containing his code or have it mmap()
57926 + an already existing ELF library that does not have position
57927 + independent code in it and use mprotect() on it to make it
57928 + writable and copy his code there. While protecting against
57929 + the former approach is beyond PaX, the latter can be prevented
57930 + by having only PIC ELF libraries on one's system (which do not
57931 + need to relocate their code). If you are sure this is your case,
57932 + as is the case with all modern Linux distributions, then leave
57933 + this option disabled. You should say 'n' here.
57935 +config PAX_ETEXECRELOCS
57936 + bool "Allow ELF ET_EXEC text relocations"
57937 + depends on PAX_MPROTECT && (ALPHA || IA64 || PARISC)
57938 + select PAX_ELFRELOCS
57941 + On some architectures there are incorrectly created applications
57942 + that require text relocations and would not work without enabling
57943 + this option. If you are an alpha, ia64 or parisc user, you should
57944 + enable this option and disable it once you have made sure that
57945 + none of your applications need it.
57948 + bool "Automatically emulate ELF PLT"
57949 + depends on PAX_MPROTECT && (ALPHA || PARISC || SPARC)
57952 + Enabling this option will have the kernel automatically detect
57953 + and emulate the Procedure Linkage Table entries in ELF files.
57954 + On some architectures such entries are in writable memory, and
57955 + become non-executable leading to task termination. Therefore
57956 + it is mandatory that you enable this option on alpha, parisc,
57957 + sparc and sparc64, otherwise your system would not even boot.
57959 + NOTE: this feature *does* open up a loophole in the protection
57960 + provided by the non-executable pages, therefore the proper
57961 + solution is to modify the toolchain to produce a PLT that does
57962 + not need to be writable.
57964 +config PAX_DLRESOLVE
57965 + bool 'Emulate old glibc resolver stub'
57966 + depends on PAX_EMUPLT && SPARC
57969 + This option is needed if userland has an old glibc (before 2.4)
57970 + that puts a 'save' instruction into the runtime generated resolver
57971 + stub that needs special emulation.
57973 +config PAX_KERNEXEC
57974 + bool "Enforce non-executable kernel pages"
57975 + depends on PAX_NOEXEC && (PPC || X86) && (!X86_32 || X86_WP_WORKS_OK) && !XEN
57976 + select PAX_PER_CPU_PGD if X86_64 || (X86_32 && X86_PAE)
57978 + This is the kernel land equivalent of PAGEEXEC and MPROTECT,
57979 + that is, enabling this option will make it harder to inject
57980 + and execute 'foreign' code in kernel memory itself.
57982 +config PAX_KERNEXEC_MODULE_TEXT
57983 + int "Minimum amount of memory reserved for module code"
57985 + depends on PAX_KERNEXEC && X86_32 && MODULES
57987 + Due to implementation details the kernel must reserve a fixed
57988 + amount of memory for module code at compile time that cannot be
57989 + changed at runtime. Here you can specify the minimum amount
57990 + in MB that will be reserved. Due to the same implementation
57991 + details this size will always be rounded up to the next 2/4 MB
57992 + boundary (depends on PAE) so the actually available memory for
57993 + module code will usually be more than this minimum.
57995 + The default 4 MB should be enough for most users but if you have
57996 + an excessive number of modules (e.g., most distribution configs
57997 + compile many drivers as modules) or use huge modules such as
57998 + nvidia's kernel driver, you will need to adjust this amount.
57999 + A good rule of thumb is to look at your currently loaded kernel
58000 + modules and add up their sizes.
58004 +menu "Address Space Layout Randomization"
58008 + bool "Address Space Layout Randomization"
58009 + depends on PAX_EI_PAX || PAX_PT_PAX_FLAGS || PAX_HAVE_ACL_FLAGS || PAX_HOOK_ACL_FLAGS
58011 + Many if not most exploit techniques rely on the knowledge of
58012 + certain addresses in the attacked program. The following options
58013 + will allow the kernel to apply a certain amount of randomization
58014 + to specific parts of the program thereby forcing an attacker to
58015 + guess them in most cases. Any failed guess will most likely crash
58016 + the attacked program which allows the kernel to detect such attempts
58017 + and react on them. PaX itself provides no reaction mechanisms,
58018 + instead it is strongly encouraged that you make use of Nergal's
58019 + segvguard (ftp://ftp.pl.openwall.com/misc/segvguard/) or grsecurity's
58020 + (http://www.grsecurity.net/) built-in crash detection features or
58021 + develop one yourself.
58023 + By saying Y here you can choose to randomize the following areas:
58024 + - top of the task's kernel stack
58025 + - top of the task's userland stack
58026 + - base address for mmap() requests that do not specify one
58027 + (this includes all libraries)
58028 + - base address of the main executable
58030 + It is strongly recommended to say Y here as address space layout
58031 + randomization has negligible impact on performance yet it provides
58032 + a very effective protection.
58034 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
58035 + this feature on a per file basis.
58037 +config PAX_RANDKSTACK
58038 + bool "Randomize kernel stack base"
58039 + depends on PAX_ASLR && X86_TSC && X86_32
58041 + By saying Y here the kernel will randomize every task's kernel
58042 + stack on every system call. This will not only force an attacker
58043 + to guess it but also prevent him from making use of possible
58044 + leaked information about it.
58046 + Since the kernel stack is a rather scarce resource, randomization
58047 + may cause unexpected stack overflows, therefore you should very
58048 + carefully test your system. Note that once enabled in the kernel
58049 + configuration, this feature cannot be disabled on a per file basis.
58051 +config PAX_RANDUSTACK
58052 + bool "Randomize user stack base"
58053 + depends on PAX_ASLR
58055 + By saying Y here the kernel will randomize every task's userland
58056 + stack. The randomization is done in two steps where the second
58057 + one may apply a big amount of shift to the top of the stack and
58058 + cause problems for programs that want to use lots of memory (more
58059 + than 2.5 GB if SEGMEXEC is not active, or 1.25 GB when it is).
58060 + For this reason the second step can be controlled by 'chpax' or
58061 + 'paxctl' on a per file basis.
58063 +config PAX_RANDMMAP
58064 + bool "Randomize mmap() base"
58065 + depends on PAX_ASLR
58067 + By saying Y here the kernel will use a randomized base address for
58068 + mmap() requests that do not specify one themselves. As a result
58069 + all dynamically loaded libraries will appear at random addresses
58070 + and therefore be harder to exploit by a technique where an attacker
58071 + attempts to execute library code for his purposes (e.g. spawn a
58072 + shell from an exploited program that is running at an elevated
58073 + privilege level).
58075 + Furthermore, if a program is relinked as a dynamic ELF file, its
58076 + base address will be randomized as well, completing the full
58077 + randomization of the address space layout. Attacking such programs
58078 + becomes a guess game. You can find an example of doing this at
58079 + http://pax.grsecurity.net/et_dyn.tar.gz and practical samples at
58080 + http://www.grsecurity.net/grsec-gcc-specs.tar.gz .
58082 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control this
58083 + feature on a per file basis.
58087 +menu "Miscellaneous hardening features"
58089 +config PAX_MEMORY_SANITIZE
58090 + bool "Sanitize all freed memory"
58092 + By saying Y here the kernel will erase memory pages as soon as they
58093 + are freed. This in turn reduces the lifetime of data stored in the
58094 + pages, making it less likely that sensitive information such as
58095 + passwords, cryptographic secrets, etc stay in memory for too long.
58097 + This is especially useful for programs whose runtime is short, long
58098 + lived processes and the kernel itself benefit from this as long as
58099 + they operate on whole memory pages and ensure timely freeing of pages
58100 + that may hold sensitive information.
58102 + The tradeoff is performance impact, on a single CPU system kernel
58103 + compilation sees a 3% slowdown, other systems and workloads may vary
58104 + and you are advised to test this feature on your expected workload
58105 + before deploying it.
58107 + Note that this feature does not protect data stored in live pages,
58108 + e.g., process memory swapped to disk may stay there for a long time.
58110 +config PAX_MEMORY_UDEREF
58111 + bool "Prevent invalid userland pointer dereference"
58112 + depends on X86 && !UML_X86 && !XEN
58113 + select PAX_PER_CPU_PGD if X86_64
58115 + By saying Y here the kernel will be prevented from dereferencing
58116 + userland pointers in contexts where the kernel expects only kernel
58117 + pointers. This is both a useful runtime debugging feature and a
58118 + security measure that prevents exploiting a class of kernel bugs.
58120 + The tradeoff is that some virtualization solutions may experience
58121 + a huge slowdown and therefore you should not enable this feature
58122 + for kernels meant to run in such environments. Whether a given VM
58123 + solution is affected or not is best determined by simply trying it
58124 + out, the performance impact will be obvious right on boot as this
58125 + mechanism engages from very early on. A good rule of thumb is that
58126 + VMs running on CPUs without hardware virtualization support (i.e.,
58127 + the majority of IA-32 CPUs) will likely experience the slowdown.
58129 +config PAX_REFCOUNT
58130 + bool "Prevent various kernel object reference counter overflows"
58131 + depends on GRKERNSEC && (X86 || SPARC64)
58133 + By saying Y here the kernel will detect and prevent overflowing
58134 + various (but not all) kinds of object reference counters. Such
58135 + overflows can normally occur due to bugs only and are often, if
58136 + not always, exploitable.
58138 + The tradeoff is that data structures protected by an overflowed
58139 + refcount will never be freed and therefore will leak memory. Note
58140 + that this leak also happens even without this protection but in
58141 + that case the overflow can eventually trigger the freeing of the
58142 + data structure while it is still being used elsewhere, resulting
58143 + in the exploitable situation that this feature prevents.
58145 + Since this has a negligible performance impact, you should enable
58148 +config PAX_USERCOPY
58149 + bool "Bounds check heap object copies between kernel and userland"
58150 + depends on X86 || PPC || SPARC
58151 + depends on GRKERNSEC && (SLAB || SLUB || SLOB)
58153 + By saying Y here the kernel will enforce the size of heap objects
58154 + when they are copied in either direction between the kernel and
58155 + userland, even if only a part of the heap object is copied.
58157 + Specifically, this checking prevents information leaking from the
58158 + kernel heap during kernel to userland copies (if the kernel heap
58159 + object is otherwise fully initialized) and prevents kernel heap
58160 + overflows during userland to kernel copies.
58162 + Note that the current implementation provides the strictest checks
58163 + for the SLUB allocator.
58165 + If frame pointers are enabled on x86, this option will also restrict
58166 + copies into and out of the kernel stack to local variables within a
58169 + Since this has a negligible performance impact, you should enable
58177 bool "Enable access key retention support"
58179 @@ -136,7 +639,7 @@ config INTEL_TXT
58180 config LSM_MMAP_MIN_ADDR
58181 int "Low address space for LSM to protect from user allocation"
58182 depends on SECURITY && SECURITY_SELINUX
58186 This is the portion of low virtual memory which should be protected
58187 from userspace allocation. Keeping a user from writing to low pages
58188 diff -urNp linux-2.6.37/security/min_addr.c linux-2.6.37/security/min_addr.c
58189 --- linux-2.6.37/security/min_addr.c 2011-01-04 19:50:19.000000000 -0500
58190 +++ linux-2.6.37/security/min_addr.c 2011-01-17 02:41:02.000000000 -0500
58191 @@ -14,6 +14,7 @@ unsigned long dac_mmap_min_addr = CONFIG
58193 static void update_mmap_min_addr(void)
58196 #ifdef CONFIG_LSM_MMAP_MIN_ADDR
58197 if (dac_mmap_min_addr > CONFIG_LSM_MMAP_MIN_ADDR)
58198 mmap_min_addr = dac_mmap_min_addr;
58199 @@ -22,6 +23,7 @@ static void update_mmap_min_addr(void)
58201 mmap_min_addr = dac_mmap_min_addr;
58207 diff -urNp linux-2.6.37/security/security.c linux-2.6.37/security/security.c
58208 --- linux-2.6.37/security/security.c 2011-01-04 19:50:19.000000000 -0500
58209 +++ linux-2.6.37/security/security.c 2011-01-17 02:41:02.000000000 -0500
58210 @@ -25,8 +25,8 @@ static __initdata char chosen_lsm[SECURI
58211 /* things that live in capability.c */
58212 extern void __init security_fixup_ops(struct security_operations *ops);
58214 -static struct security_operations *security_ops;
58215 -static struct security_operations default_security_ops = {
58216 +static struct security_operations *security_ops __read_only;
58217 +static struct security_operations default_security_ops __read_only = {
58221 @@ -67,7 +67,9 @@ int __init security_init(void)
58223 void reset_security_ops(void)
58225 + pax_open_kernel();
58226 security_ops = &default_security_ops;
58227 + pax_close_kernel();
58230 /* Save user chosen LSM */
58231 diff -urNp linux-2.6.37/security/selinux/hooks.c linux-2.6.37/security/selinux/hooks.c
58232 --- linux-2.6.37/security/selinux/hooks.c 2011-01-04 19:50:19.000000000 -0500
58233 +++ linux-2.6.37/security/selinux/hooks.c 2011-01-17 02:41:02.000000000 -0500
58235 #define NUM_SEL_MNT_OPTS 5
58237 extern int selinux_nlmsg_lookup(u16 sclass, u16 nlmsg_type, u32 *perm);
58238 -extern struct security_operations *security_ops;
58240 /* SECMARK reference count */
58241 atomic_t selinux_secmark_refcount = ATOMIC_INIT(0);
58242 @@ -5388,7 +5387,7 @@ static int selinux_key_getsecurity(struc
58246 -static struct security_operations selinux_ops = {
58247 +static struct security_operations selinux_ops __read_only = {
58250 .ptrace_access_check = selinux_ptrace_access_check,
58251 diff -urNp linux-2.6.37/security/smack/smack_lsm.c linux-2.6.37/security/smack/smack_lsm.c
58252 --- linux-2.6.37/security/smack/smack_lsm.c 2011-01-04 19:50:19.000000000 -0500
58253 +++ linux-2.6.37/security/smack/smack_lsm.c 2011-01-17 02:41:02.000000000 -0500
58254 @@ -3052,7 +3052,7 @@ static int smack_inode_getsecctx(struct
58258 -struct security_operations smack_ops = {
58259 +struct security_operations smack_ops __read_only = {
58262 .ptrace_access_check = smack_ptrace_access_check,
58263 diff -urNp linux-2.6.37/security/tomoyo/tomoyo.c linux-2.6.37/security/tomoyo/tomoyo.c
58264 --- linux-2.6.37/security/tomoyo/tomoyo.c 2011-01-04 19:50:19.000000000 -0500
58265 +++ linux-2.6.37/security/tomoyo/tomoyo.c 2011-01-17 02:41:02.000000000 -0500
58266 @@ -240,7 +240,7 @@ static int tomoyo_sb_pivotroot(struct pa
58267 * tomoyo_security_ops is a "struct security_operations" which is used for
58268 * registering TOMOYO.
58270 -static struct security_operations tomoyo_security_ops = {
58271 +static struct security_operations tomoyo_security_ops __read_only = {
58273 .cred_alloc_blank = tomoyo_cred_alloc_blank,
58274 .cred_prepare = tomoyo_cred_prepare,
58275 diff -urNp linux-2.6.37/sound/aoa/codecs/onyx.c linux-2.6.37/sound/aoa/codecs/onyx.c
58276 --- linux-2.6.37/sound/aoa/codecs/onyx.c 2011-01-04 19:50:19.000000000 -0500
58277 +++ linux-2.6.37/sound/aoa/codecs/onyx.c 2011-01-17 02:41:02.000000000 -0500
58278 @@ -54,7 +54,7 @@ struct onyx {
58283 + atomic_t open_count;
58284 struct codec_info *codec_info;
58286 /* mutex serializes concurrent access to the device
58287 @@ -753,7 +753,7 @@ static int onyx_open(struct codec_info_i
58288 struct onyx *onyx = cii->codec_data;
58290 mutex_lock(&onyx->mutex);
58291 - onyx->open_count++;
58292 + atomic_inc(&onyx->open_count);
58293 mutex_unlock(&onyx->mutex);
58296 @@ -765,8 +765,7 @@ static int onyx_close(struct codec_info_
58297 struct onyx *onyx = cii->codec_data;
58299 mutex_lock(&onyx->mutex);
58300 - onyx->open_count--;
58301 - if (!onyx->open_count)
58302 + if (atomic_dec_and_test(&onyx->open_count))
58303 onyx->spdif_locked = onyx->analog_locked = 0;
58304 mutex_unlock(&onyx->mutex);
58306 diff -urNp linux-2.6.37/sound/core/oss/pcm_oss.c linux-2.6.37/sound/core/oss/pcm_oss.c
58307 --- linux-2.6.37/sound/core/oss/pcm_oss.c 2011-01-04 19:50:19.000000000 -0500
58308 +++ linux-2.6.37/sound/core/oss/pcm_oss.c 2011-01-17 02:41:02.000000000 -0500
58309 @@ -2969,8 +2969,8 @@ static void snd_pcm_oss_proc_done(struct
58312 #else /* !CONFIG_SND_VERBOSE_PROCFS */
58313 -#define snd_pcm_oss_proc_init(pcm)
58314 -#define snd_pcm_oss_proc_done(pcm)
58315 +#define snd_pcm_oss_proc_init(pcm) do {} while (0)
58316 +#define snd_pcm_oss_proc_done(pcm) do {} while (0)
58317 #endif /* CONFIG_SND_VERBOSE_PROCFS */
58320 diff -urNp linux-2.6.37/sound/core/seq/seq_lock.h linux-2.6.37/sound/core/seq/seq_lock.h
58321 --- linux-2.6.37/sound/core/seq/seq_lock.h 2011-01-04 19:50:19.000000000 -0500
58322 +++ linux-2.6.37/sound/core/seq/seq_lock.h 2011-01-17 02:41:02.000000000 -0500
58323 @@ -23,10 +23,10 @@ void snd_use_lock_sync_helper(snd_use_lo
58324 #else /* SMP || CONFIG_SND_DEBUG */
58326 typedef spinlock_t snd_use_lock_t; /* dummy */
58327 -#define snd_use_lock_init(lockp) /**/
58328 -#define snd_use_lock_use(lockp) /**/
58329 -#define snd_use_lock_free(lockp) /**/
58330 -#define snd_use_lock_sync(lockp) /**/
58331 +#define snd_use_lock_init(lockp) do {} while (0)
58332 +#define snd_use_lock_use(lockp) do {} while (0)
58333 +#define snd_use_lock_free(lockp) do {} while (0)
58334 +#define snd_use_lock_sync(lockp) do {} while (0)
58336 #endif /* SMP || CONFIG_SND_DEBUG */
58338 diff -urNp linux-2.6.37/sound/drivers/mts64.c linux-2.6.37/sound/drivers/mts64.c
58339 --- linux-2.6.37/sound/drivers/mts64.c 2011-01-04 19:50:19.000000000 -0500
58340 +++ linux-2.6.37/sound/drivers/mts64.c 2011-01-17 02:41:02.000000000 -0500
58341 @@ -66,7 +66,7 @@ struct mts64 {
58342 struct pardevice *pardev;
58343 int pardev_claimed;
58346 + atomic_t open_count;
58347 int current_midi_output_port;
58348 int current_midi_input_port;
58349 u8 mode[MTS64_NUM_INPUT_PORTS];
58350 @@ -696,7 +696,7 @@ static int snd_mts64_rawmidi_open(struct
58352 struct mts64 *mts = substream->rmidi->private_data;
58354 - if (mts->open_count == 0) {
58355 + if (atomic_read(&mts->open_count) == 0) {
58356 /* We don't need a spinlock here, because this is just called
58357 if the device has not been opened before.
58358 So there aren't any IRQs from the device */
58359 @@ -704,7 +704,7 @@ static int snd_mts64_rawmidi_open(struct
58363 - ++(mts->open_count);
58364 + atomic_inc(&mts->open_count);
58368 @@ -714,8 +714,7 @@ static int snd_mts64_rawmidi_close(struc
58369 struct mts64 *mts = substream->rmidi->private_data;
58370 unsigned long flags;
58372 - --(mts->open_count);
58373 - if (mts->open_count == 0) {
58374 + if (atomic_dec_return(&mts->open_count) == 0) {
58375 /* We need the spinlock_irqsave here because we can still
58376 have IRQs at this point */
58377 spin_lock_irqsave(&mts->lock, flags);
58378 @@ -724,8 +723,8 @@ static int snd_mts64_rawmidi_close(struc
58382 - } else if (mts->open_count < 0)
58383 - mts->open_count = 0;
58384 + } else if (atomic_read(&mts->open_count) < 0)
58385 + atomic_set(&mts->open_count, 0);
58389 diff -urNp linux-2.6.37/sound/drivers/portman2x4.c linux-2.6.37/sound/drivers/portman2x4.c
58390 --- linux-2.6.37/sound/drivers/portman2x4.c 2011-01-04 19:50:19.000000000 -0500
58391 +++ linux-2.6.37/sound/drivers/portman2x4.c 2011-01-17 02:41:02.000000000 -0500
58392 @@ -84,7 +84,7 @@ struct portman {
58393 struct pardevice *pardev;
58394 int pardev_claimed;
58397 + atomic_t open_count;
58398 int mode[PORTMAN_NUM_INPUT_PORTS];
58399 struct snd_rawmidi_substream *midi_input[PORTMAN_NUM_INPUT_PORTS];
58401 diff -urNp linux-2.6.37/sound/oss/sb_audio.c linux-2.6.37/sound/oss/sb_audio.c
58402 --- linux-2.6.37/sound/oss/sb_audio.c 2011-01-04 19:50:19.000000000 -0500
58403 +++ linux-2.6.37/sound/oss/sb_audio.c 2011-01-17 02:41:02.000000000 -0500
58404 @@ -901,7 +901,7 @@ sb16_copy_from_user(int dev,
58405 buf16 = (signed short *)(localbuf + localoffs);
58408 - locallen = (c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
58409 + locallen = ((unsigned)c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
58410 if (copy_from_user(lbuf8,
58411 userbuf+useroffs + p,
58413 diff -urNp linux-2.6.37/sound/oss/swarm_cs4297a.c linux-2.6.37/sound/oss/swarm_cs4297a.c
58414 --- linux-2.6.37/sound/oss/swarm_cs4297a.c 2011-01-04 19:50:19.000000000 -0500
58415 +++ linux-2.6.37/sound/oss/swarm_cs4297a.c 2011-01-17 02:41:02.000000000 -0500
58416 @@ -2606,7 +2606,6 @@ static int __init cs4297a_init(void)
58418 struct cs4297a_state *s;
58422 #ifndef CONFIG_BCM_CS4297A_CSWARM
58424 @@ -2696,22 +2695,23 @@ static int __init cs4297a_init(void)
58426 char *sb1250_duart_present;
58433 val = SOUND_MASK_LINE;
58434 mixer_ioctl(s, SOUND_MIXER_WRITE_RECSRC, (unsigned long) &val);
58435 for (i = 0; i < ARRAY_SIZE(initvol); i++) {
58436 val = initvol[i].vol;
58437 mixer_ioctl(s, initvol[i].mixch, (unsigned long) &val);
58440 // cs4297a_write_ac97(s, 0x18, 0x0808);
58442 // cs4297a_write_ac97(s, 0x5e, 0x180);
58443 cs4297a_write_ac97(s, 0x02, 0x0808);
58444 cs4297a_write_ac97(s, 0x18, 0x0808);
58448 list_add(&s->list, &cs4297a_devs);
58450 diff -urNp linux-2.6.37/sound/pci/ac97/ac97_codec.c linux-2.6.37/sound/pci/ac97/ac97_codec.c
58451 --- linux-2.6.37/sound/pci/ac97/ac97_codec.c 2011-01-04 19:50:19.000000000 -0500
58452 +++ linux-2.6.37/sound/pci/ac97/ac97_codec.c 2011-01-17 02:41:02.000000000 -0500
58453 @@ -1962,7 +1962,7 @@ static int snd_ac97_dev_disconnect(struc
58456 /* build_ops to do nothing */
58457 -static struct snd_ac97_build_ops null_build_ops;
58458 +static const struct snd_ac97_build_ops null_build_ops;
58460 #ifdef CONFIG_SND_AC97_POWER_SAVE
58461 static void do_update_power(struct work_struct *work)
58462 diff -urNp linux-2.6.37/sound/pci/ac97/ac97_patch.c linux-2.6.37/sound/pci/ac97/ac97_patch.c
58463 --- linux-2.6.37/sound/pci/ac97/ac97_patch.c 2011-01-04 19:50:19.000000000 -0500
58464 +++ linux-2.6.37/sound/pci/ac97/ac97_patch.c 2011-01-17 02:41:02.000000000 -0500
58465 @@ -371,7 +371,7 @@ static int patch_yamaha_ymf743_build_spd
58469 -static struct snd_ac97_build_ops patch_yamaha_ymf743_ops = {
58470 +static const struct snd_ac97_build_ops patch_yamaha_ymf743_ops = {
58471 .build_spdif = patch_yamaha_ymf743_build_spdif,
58472 .build_3d = patch_yamaha_ymf7x3_3d,
58474 @@ -455,7 +455,7 @@ static int patch_yamaha_ymf753_post_spdi
58478 -static struct snd_ac97_build_ops patch_yamaha_ymf753_ops = {
58479 +static const struct snd_ac97_build_ops patch_yamaha_ymf753_ops = {
58480 .build_3d = patch_yamaha_ymf7x3_3d,
58481 .build_post_spdif = patch_yamaha_ymf753_post_spdif
58483 @@ -502,7 +502,7 @@ static int patch_wolfson_wm9703_specific
58487 -static struct snd_ac97_build_ops patch_wolfson_wm9703_ops = {
58488 +static const struct snd_ac97_build_ops patch_wolfson_wm9703_ops = {
58489 .build_specific = patch_wolfson_wm9703_specific,
58492 @@ -533,7 +533,7 @@ static int patch_wolfson_wm9704_specific
58496 -static struct snd_ac97_build_ops patch_wolfson_wm9704_ops = {
58497 +static const struct snd_ac97_build_ops patch_wolfson_wm9704_ops = {
58498 .build_specific = patch_wolfson_wm9704_specific,
58501 @@ -677,7 +677,7 @@ static int patch_wolfson_wm9711_specific
58505 -static struct snd_ac97_build_ops patch_wolfson_wm9711_ops = {
58506 +static const struct snd_ac97_build_ops patch_wolfson_wm9711_ops = {
58507 .build_specific = patch_wolfson_wm9711_specific,
58510 @@ -871,7 +871,7 @@ static void patch_wolfson_wm9713_resume
58514 -static struct snd_ac97_build_ops patch_wolfson_wm9713_ops = {
58515 +static const struct snd_ac97_build_ops patch_wolfson_wm9713_ops = {
58516 .build_specific = patch_wolfson_wm9713_specific,
58517 .build_3d = patch_wolfson_wm9713_3d,
58519 @@ -976,7 +976,7 @@ static int patch_sigmatel_stac97xx_speci
58523 -static struct snd_ac97_build_ops patch_sigmatel_stac9700_ops = {
58524 +static const struct snd_ac97_build_ops patch_sigmatel_stac9700_ops = {
58525 .build_3d = patch_sigmatel_stac9700_3d,
58526 .build_specific = patch_sigmatel_stac97xx_specific
58528 @@ -1023,7 +1023,7 @@ static int patch_sigmatel_stac9708_speci
58529 return patch_sigmatel_stac97xx_specific(ac97);
58532 -static struct snd_ac97_build_ops patch_sigmatel_stac9708_ops = {
58533 +static const struct snd_ac97_build_ops patch_sigmatel_stac9708_ops = {
58534 .build_3d = patch_sigmatel_stac9708_3d,
58535 .build_specific = patch_sigmatel_stac9708_specific
58537 @@ -1252,7 +1252,7 @@ static int patch_sigmatel_stac9758_speci
58541 -static struct snd_ac97_build_ops patch_sigmatel_stac9758_ops = {
58542 +static const struct snd_ac97_build_ops patch_sigmatel_stac9758_ops = {
58543 .build_3d = patch_sigmatel_stac9700_3d,
58544 .build_specific = patch_sigmatel_stac9758_specific
58546 @@ -1327,7 +1327,7 @@ static int patch_cirrus_build_spdif(stru
58550 -static struct snd_ac97_build_ops patch_cirrus_ops = {
58551 +static const struct snd_ac97_build_ops patch_cirrus_ops = {
58552 .build_spdif = patch_cirrus_build_spdif
58555 @@ -1384,7 +1384,7 @@ static int patch_conexant_build_spdif(st
58559 -static struct snd_ac97_build_ops patch_conexant_ops = {
58560 +static const struct snd_ac97_build_ops patch_conexant_ops = {
58561 .build_spdif = patch_conexant_build_spdif
58564 @@ -1486,7 +1486,7 @@ static const struct snd_ac97_res_table a
58565 { AC97_VIDEO, 0x9f1f },
58566 { AC97_AUX, 0x9f1f },
58567 { AC97_PCM, 0x9f1f },
58568 - { } /* terminator */
58569 + { 0, 0 } /* terminator */
58572 static int patch_ad1819(struct snd_ac97 * ac97)
58573 @@ -1560,7 +1560,7 @@ static void patch_ad1881_chained(struct
58577 -static struct snd_ac97_build_ops patch_ad1881_build_ops = {
58578 +static const struct snd_ac97_build_ops patch_ad1881_build_ops = {
58580 .resume = ad18xx_resume
58582 @@ -1647,7 +1647,7 @@ static int patch_ad1885_specific(struct
58586 -static struct snd_ac97_build_ops patch_ad1885_build_ops = {
58587 +static const struct snd_ac97_build_ops patch_ad1885_build_ops = {
58588 .build_specific = &patch_ad1885_specific,
58590 .resume = ad18xx_resume
58591 @@ -1674,7 +1674,7 @@ static int patch_ad1886_specific(struct
58595 -static struct snd_ac97_build_ops patch_ad1886_build_ops = {
58596 +static const struct snd_ac97_build_ops patch_ad1886_build_ops = {
58597 .build_specific = &patch_ad1886_specific,
58599 .resume = ad18xx_resume
58600 @@ -1881,7 +1881,7 @@ static int patch_ad1981a_specific(struct
58601 ARRAY_SIZE(snd_ac97_ad1981x_jack_sense));
58604 -static struct snd_ac97_build_ops patch_ad1981a_build_ops = {
58605 +static const struct snd_ac97_build_ops patch_ad1981a_build_ops = {
58606 .build_post_spdif = patch_ad198x_post_spdif,
58607 .build_specific = patch_ad1981a_specific,
58609 @@ -1936,7 +1936,7 @@ static int patch_ad1981b_specific(struct
58610 ARRAY_SIZE(snd_ac97_ad1981x_jack_sense));
58613 -static struct snd_ac97_build_ops patch_ad1981b_build_ops = {
58614 +static const struct snd_ac97_build_ops patch_ad1981b_build_ops = {
58615 .build_post_spdif = patch_ad198x_post_spdif,
58616 .build_specific = patch_ad1981b_specific,
58618 @@ -2075,7 +2075,7 @@ static int patch_ad1888_specific(struct
58619 return patch_build_controls(ac97, snd_ac97_ad1888_controls, ARRAY_SIZE(snd_ac97_ad1888_controls));
58622 -static struct snd_ac97_build_ops patch_ad1888_build_ops = {
58623 +static const struct snd_ac97_build_ops patch_ad1888_build_ops = {
58624 .build_post_spdif = patch_ad198x_post_spdif,
58625 .build_specific = patch_ad1888_specific,
58627 @@ -2124,7 +2124,7 @@ static int patch_ad1980_specific(struct
58628 return patch_build_controls(ac97, &snd_ac97_ad198x_2cmic, 1);
58631 -static struct snd_ac97_build_ops patch_ad1980_build_ops = {
58632 +static const struct snd_ac97_build_ops patch_ad1980_build_ops = {
58633 .build_post_spdif = patch_ad198x_post_spdif,
58634 .build_specific = patch_ad1980_specific,
58636 @@ -2239,7 +2239,7 @@ static int patch_ad1985_specific(struct
58637 ARRAY_SIZE(snd_ac97_ad1985_controls));
58640 -static struct snd_ac97_build_ops patch_ad1985_build_ops = {
58641 +static const struct snd_ac97_build_ops patch_ad1985_build_ops = {
58642 .build_post_spdif = patch_ad198x_post_spdif,
58643 .build_specific = patch_ad1985_specific,
58645 @@ -2531,7 +2531,7 @@ static int patch_ad1986_specific(struct
58646 ARRAY_SIZE(snd_ac97_ad1985_controls));
58649 -static struct snd_ac97_build_ops patch_ad1986_build_ops = {
58650 +static const struct snd_ac97_build_ops patch_ad1986_build_ops = {
58651 .build_post_spdif = patch_ad198x_post_spdif,
58652 .build_specific = patch_ad1986_specific,
58654 @@ -2636,7 +2636,7 @@ static int patch_alc650_specific(struct
58658 -static struct snd_ac97_build_ops patch_alc650_ops = {
58659 +static const struct snd_ac97_build_ops patch_alc650_ops = {
58660 .build_specific = patch_alc650_specific,
58661 .update_jacks = alc650_update_jacks
58663 @@ -2788,7 +2788,7 @@ static int patch_alc655_specific(struct
58667 -static struct snd_ac97_build_ops patch_alc655_ops = {
58668 +static const struct snd_ac97_build_ops patch_alc655_ops = {
58669 .build_specific = patch_alc655_specific,
58670 .update_jacks = alc655_update_jacks
58672 @@ -2900,7 +2900,7 @@ static int patch_alc850_specific(struct
58676 -static struct snd_ac97_build_ops patch_alc850_ops = {
58677 +static const struct snd_ac97_build_ops patch_alc850_ops = {
58678 .build_specific = patch_alc850_specific,
58679 .update_jacks = alc850_update_jacks
58681 @@ -2962,7 +2962,7 @@ static int patch_cm9738_specific(struct
58682 return patch_build_controls(ac97, snd_ac97_cm9738_controls, ARRAY_SIZE(snd_ac97_cm9738_controls));
58685 -static struct snd_ac97_build_ops patch_cm9738_ops = {
58686 +static const struct snd_ac97_build_ops patch_cm9738_ops = {
58687 .build_specific = patch_cm9738_specific,
58688 .update_jacks = cm9738_update_jacks
58690 @@ -3053,7 +3053,7 @@ static int patch_cm9739_post_spdif(struc
58691 return patch_build_controls(ac97, snd_ac97_cm9739_controls_spdif, ARRAY_SIZE(snd_ac97_cm9739_controls_spdif));
58694 -static struct snd_ac97_build_ops patch_cm9739_ops = {
58695 +static const struct snd_ac97_build_ops patch_cm9739_ops = {
58696 .build_specific = patch_cm9739_specific,
58697 .build_post_spdif = patch_cm9739_post_spdif,
58698 .update_jacks = cm9739_update_jacks
58699 @@ -3227,7 +3227,7 @@ static int patch_cm9761_specific(struct
58700 return patch_build_controls(ac97, snd_ac97_cm9761_controls, ARRAY_SIZE(snd_ac97_cm9761_controls));
58703 -static struct snd_ac97_build_ops patch_cm9761_ops = {
58704 +static const struct snd_ac97_build_ops patch_cm9761_ops = {
58705 .build_specific = patch_cm9761_specific,
58706 .build_post_spdif = patch_cm9761_post_spdif,
58707 .update_jacks = cm9761_update_jacks
58708 @@ -3323,7 +3323,7 @@ static int patch_cm9780_specific(struct
58709 return patch_build_controls(ac97, cm9780_controls, ARRAY_SIZE(cm9780_controls));
58712 -static struct snd_ac97_build_ops patch_cm9780_ops = {
58713 +static const struct snd_ac97_build_ops patch_cm9780_ops = {
58714 .build_specific = patch_cm9780_specific,
58715 .build_post_spdif = patch_cm9761_post_spdif /* identical with CM9761 */
58717 @@ -3443,7 +3443,7 @@ static int patch_vt1616_specific(struct
58721 -static struct snd_ac97_build_ops patch_vt1616_ops = {
58722 +static const struct snd_ac97_build_ops patch_vt1616_ops = {
58723 .build_specific = patch_vt1616_specific
58726 @@ -3797,7 +3797,7 @@ static int patch_it2646_specific(struct
58730 -static struct snd_ac97_build_ops patch_it2646_ops = {
58731 +static const struct snd_ac97_build_ops patch_it2646_ops = {
58732 .build_specific = patch_it2646_specific,
58733 .update_jacks = it2646_update_jacks
58735 @@ -3831,7 +3831,7 @@ static int patch_si3036_specific(struct
58739 -static struct snd_ac97_build_ops patch_si3036_ops = {
58740 +static const struct snd_ac97_build_ops patch_si3036_ops = {
58741 .build_specific = patch_si3036_specific,
58744 @@ -3864,7 +3864,7 @@ static struct snd_ac97_res_table lm4550_
58745 { AC97_AUX, 0x1f1f },
58746 { AC97_PCM, 0x1f1f },
58747 { AC97_REC_GAIN, 0x0f0f },
58748 - { } /* terminator */
58749 + { 0, 0 } /* terminator */
58752 static int patch_lm4550(struct snd_ac97 *ac97)
58753 @@ -3898,7 +3898,7 @@ static int patch_ucb1400_specific(struct
58757 -static struct snd_ac97_build_ops patch_ucb1400_ops = {
58758 +static const struct snd_ac97_build_ops patch_ucb1400_ops = {
58759 .build_specific = patch_ucb1400_specific,
58762 diff -urNp linux-2.6.37/sound/pci/ens1370.c linux-2.6.37/sound/pci/ens1370.c
58763 --- linux-2.6.37/sound/pci/ens1370.c 2011-01-04 19:50:19.000000000 -0500
58764 +++ linux-2.6.37/sound/pci/ens1370.c 2011-01-17 02:41:02.000000000 -0500
58765 @@ -452,7 +452,7 @@ static DEFINE_PCI_DEVICE_TABLE(snd_audio
58766 { PCI_VDEVICE(ENSONIQ, 0x5880), 0, }, /* ES1373 - CT5880 */
58767 { PCI_VDEVICE(ECTIVA, 0x8938), 0, }, /* Ectiva EV1938 */
58770 + { 0, 0, 0, 0, 0, 0, 0 }
58773 MODULE_DEVICE_TABLE(pci, snd_audiopci_ids);
58774 diff -urNp linux-2.6.37/sound/pci/hda/patch_hdmi.c linux-2.6.37/sound/pci/hda/patch_hdmi.c
58775 --- linux-2.6.37/sound/pci/hda/patch_hdmi.c 2011-01-04 19:50:19.000000000 -0500
58776 +++ linux-2.6.37/sound/pci/hda/patch_hdmi.c 2011-01-17 02:41:02.000000000 -0500
58777 @@ -726,10 +726,10 @@ static void hdmi_non_intrinsic_event(str
58792 diff -urNp linux-2.6.37/sound/pci/intel8x0.c linux-2.6.37/sound/pci/intel8x0.c
58793 --- linux-2.6.37/sound/pci/intel8x0.c 2011-01-04 19:50:19.000000000 -0500
58794 +++ linux-2.6.37/sound/pci/intel8x0.c 2011-01-17 02:41:02.000000000 -0500
58795 @@ -444,7 +444,7 @@ static DEFINE_PCI_DEVICE_TABLE(snd_intel
58796 { PCI_VDEVICE(AMD, 0x746d), DEVICE_INTEL }, /* AMD8111 */
58797 { PCI_VDEVICE(AMD, 0x7445), DEVICE_INTEL }, /* AMD768 */
58798 { PCI_VDEVICE(AL, 0x5455), DEVICE_ALI }, /* Ali5455 */
58800 + { 0, 0, 0, 0, 0, 0, 0 }
58803 MODULE_DEVICE_TABLE(pci, snd_intel8x0_ids);
58804 @@ -2141,7 +2141,7 @@ static struct ac97_quirk ac97_quirks[] _
58805 .type = AC97_TUNE_HP_ONLY
58808 - { } /* terminator */
58809 + { 0, 0, 0, 0, NULL, 0 } /* terminator */
58812 static int __devinit snd_intel8x0_mixer(struct intel8x0 *chip, int ac97_clock,
58813 diff -urNp linux-2.6.37/sound/pci/intel8x0m.c linux-2.6.37/sound/pci/intel8x0m.c
58814 --- linux-2.6.37/sound/pci/intel8x0m.c 2011-01-04 19:50:19.000000000 -0500
58815 +++ linux-2.6.37/sound/pci/intel8x0m.c 2011-01-17 02:41:02.000000000 -0500
58816 @@ -239,7 +239,7 @@ static DEFINE_PCI_DEVICE_TABLE(snd_intel
58817 { PCI_VDEVICE(AMD, 0x746d), DEVICE_INTEL }, /* AMD8111 */
58818 { PCI_VDEVICE(AL, 0x5455), DEVICE_ALI }, /* Ali5455 */
58821 + { 0, 0, 0, 0, 0, 0, 0 }
58824 MODULE_DEVICE_TABLE(pci, snd_intel8x0m_ids);
58825 @@ -1264,7 +1264,7 @@ static struct shortname_table {
58826 { 0x5455, "ALi M5455" },
58827 { 0x746d, "AMD AMD8111" },
58833 static int __devinit snd_intel8x0m_probe(struct pci_dev *pci,
58834 diff -urNp linux-2.6.37/usr/gen_init_cpio.c linux-2.6.37/usr/gen_init_cpio.c
58835 --- linux-2.6.37/usr/gen_init_cpio.c 2011-01-04 19:50:19.000000000 -0500
58836 +++ linux-2.6.37/usr/gen_init_cpio.c 2011-01-17 02:41:02.000000000 -0500
58837 @@ -299,7 +299,7 @@ static int cpio_mkfile(const char *name,
58846 @@ -386,9 +386,10 @@ static char *cpio_replace_env(char *new_
58847 *env_var = *expanded = '\0';
58848 strncat(env_var, start + 2, end - start - 2);
58849 strncat(expanded, new_location, start - new_location);
58850 - strncat(expanded, getenv(env_var), PATH_MAX);
58851 - strncat(expanded, end + 1, PATH_MAX);
58852 + strncat(expanded, getenv(env_var), PATH_MAX - strlen(expanded));
58853 + strncat(expanded, end + 1, PATH_MAX - strlen(expanded));
58854 strncpy(new_location, expanded, PATH_MAX);
58855 + new_location[PATH_MAX] = 0;
58859 diff -urNp linux-2.6.37/virt/kvm/kvm_main.c linux-2.6.37/virt/kvm/kvm_main.c
58860 --- linux-2.6.37/virt/kvm/kvm_main.c 2011-01-04 19:50:19.000000000 -0500
58861 +++ linux-2.6.37/virt/kvm/kvm_main.c 2011-01-17 02:41:02.000000000 -0500
58862 @@ -1344,6 +1344,7 @@ static int kvm_vcpu_release(struct inode
58866 +/* cannot be const */
58867 static struct file_operations kvm_vcpu_fops = {
58868 .release = kvm_vcpu_release,
58869 .unlocked_ioctl = kvm_vcpu_ioctl,
58870 @@ -1812,6 +1813,7 @@ static int kvm_vm_mmap(struct file *file
58874 +/* cannot be const */
58875 static struct file_operations kvm_vm_fops = {
58876 .release = kvm_vm_release,
58877 .unlocked_ioctl = kvm_vm_ioctl,
58878 @@ -1910,6 +1912,7 @@ out:
58882 +/* cannot be const */
58883 static struct file_operations kvm_chardev_ops = {
58884 .unlocked_ioctl = kvm_dev_ioctl,
58885 .compat_ioctl = kvm_dev_ioctl,
58886 @@ -1920,6 +1923,9 @@ static struct miscdevice kvm_dev = {
58895 static void hardware_enable(void *junk)
58896 @@ -2259,7 +2265,7 @@ static void kvm_sched_out(struct preempt
58897 kvm_arch_vcpu_put(vcpu);
58900 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
58901 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
58902 struct module *module)