]> git.ipfire.org Git - ipfire-3.x.git/blob - pkgs/core/kernel/patches/grsecurity-2.2.1-2.6.37-201101170305.patch
naoki: Allow diff as a filename ending for patches.
[ipfire-3.x.git] / pkgs / core / kernel / patches / grsecurity-2.2.1-2.6.37-201101170305.patch
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
4 @@ -3,9 +3,9 @@
5
6 #include <linux/dma-attrs.h>
7
8 -extern struct dma_map_ops *dma_ops;
9 +extern const struct dma_map_ops *dma_ops;
10
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)
13 {
14 return dma_ops;
15 }
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
20
21 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
22
23 +#ifdef CONFIG_PAX_ASLR
24 +#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
25 +
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)
28 +#endif
29 +
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)
40 +
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)
45 +#else
46 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
47 +# define PAGE_COPY_NOEXEC PAGE_COPY
48 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
49 +#endif
50 +
51 #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
52
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,
58
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;
64
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)
72 return -ENOMEM;
73 - if (!vma || addr + len <= vma->vm_start)
74 + if (check_heap_stack_gap(vma, addr, len))
75 return addr;
76 addr = vma->vm_end;
77 vma = vma->vm_next;
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? */
81
82 +#ifdef CONFIG_PAX_RANDMMAP
83 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
84 +#endif
85 +
86 if (addr) {
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
90 }
91
92 /* Next, try allocating at TASK_UNMAPPED_BASE. */
93 - addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
94 - len, limit);
95 + addr = arch_get_unmapped_area_1 (PAGE_ALIGN(current->mm->mmap_base), len, limit);
96 +
97 if (addr != (unsigned long) -ENOMEM)
98 return addr;
99
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
104 return 0;
105 }
106
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,
114 };
115
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
123 return 0;
124 }
125
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,
133 };
134
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);
138
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);
145 }
146
147 +#ifdef CONFIG_PAX_PAGEEXEC
148 +/*
149 + * PaX: decide what to do with offenders (regs->pc = fault address)
150 + *
151 + * returns 1 when task should be killed
152 + * 2 when patched PLT trampoline was detected
153 + * 3 when unpatched PLT trampoline was detected
154 + */
155 +static int pax_handle_fetch_fault(struct pt_regs *regs)
156 +{
157 +
158 +#ifdef CONFIG_PAX_EMUPLT
159 + int err;
160 +
161 + do { /* PaX: patched PLT emulation #1 */
162 + unsigned int ldah, ldq, jmp;
163 +
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));
167 +
168 + if (err)
169 + break;
170 +
171 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
172 + (ldq & 0xFFFF0000U) == 0xA77B0000U &&
173 + jmp == 0x6BFB0000U)
174 + {
175 + unsigned long r27, addr;
176 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
177 + unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
178 +
179 + addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
180 + err = get_user(r27, (unsigned long *)addr);
181 + if (err)
182 + break;
183 +
184 + regs->r27 = r27;
185 + regs->pc = r27;
186 + return 2;
187 + }
188 + } while (0);
189 +
190 + do { /* PaX: patched PLT emulation #2 */
191 + unsigned int ldah, lda, br;
192 +
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));
196 +
197 + if (err)
198 + break;
199 +
200 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
201 + (lda & 0xFFFF0000U) == 0xA77B0000U &&
202 + (br & 0xFFE00000U) == 0xC3E00000U)
203 + {
204 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
205 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
206 + unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
207 +
208 + regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
209 + regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
210 + return 2;
211 + }
212 + } while (0);
213 +
214 + do { /* PaX: unpatched PLT emulation */
215 + unsigned int br;
216 +
217 + err = get_user(br, (unsigned int *)regs->pc);
218 +
219 + if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
220 + unsigned int br2, ldq, nop, jmp;
221 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
222 +
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));
229 +
230 + if (err)
231 + break;
232 +
233 + if (br2 == 0xC3600000U &&
234 + ldq == 0xA77B000CU &&
235 + nop == 0x47FF041FU &&
236 + jmp == 0x6B7B0000U)
237 + {
238 + regs->r28 = regs->pc+4;
239 + regs->r27 = addr+16;
240 + regs->pc = resolver;
241 + return 3;
242 + }
243 + }
244 + } while (0);
245 +#endif
246 +
247 + return 1;
248 +}
249 +
250 +void pax_report_insns(void *pc, void *sp)
251 +{
252 + unsigned long i;
253 +
254 + printk(KERN_ERR "PAX: bytes at PC: ");
255 + for (i = 0; i < 5; i++) {
256 + unsigned int c;
257 + if (get_user(c, (unsigned int *)pc+i))
258 + printk(KERN_CONT "???????? ");
259 + else
260 + printk(KERN_CONT "%08x ", c);
261 + }
262 + printk("\n");
263 +}
264 +#endif
265
266 /*
267 * This routine handles page faults. It determines the address,
268 @@ -131,8 +249,29 @@ do_page_fault(unsigned long address, uns
269 good_area:
270 si_code = SEGV_ACCERR;
271 if (cause < 0) {
272 - if (!(vma->vm_flags & VM_EXEC))
273 + if (!(vma->vm_flags & VM_EXEC)) {
274 +
275 +#ifdef CONFIG_PAX_PAGEEXEC
276 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
277 + goto bad_area;
278 +
279 + up_read(&mm->mmap_sem);
280 + switch (pax_handle_fetch_fault(regs)) {
281 +
282 +#ifdef CONFIG_PAX_EMUPLT
283 + case 2:
284 + case 3:
285 + return;
286 +#endif
287 +
288 + }
289 + pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
290 + do_group_exit(SIGKILL);
291 +#else
292 goto bad_area;
293 +#endif
294 +
295 + }
296 } else if (!cause) {
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. */
305
306 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
307 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
308 +
309 +#ifdef CONFIG_PAX_ASLR
310 +#define PAX_ELF_ET_DYN_BASE 0x00008000UL
311 +
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)
314 +#endif
315
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))
321
322 -struct mm_struct;
323 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
324 -#define arch_randomize_brk arch_randomize_brk
325 -
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 {
333 KM_L1_CACHE,
334 KM_L2_CACHE,
335 KM_KDB,
336 + KM_CLEARPAGE,
337 KM_TYPE_NR
338 };
339
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
344
345 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
346 {
347 + if ((long)n < 0)
348 + return n;
349 +
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
354
355 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
356 {
357 + if ((long)n < 0)
358 + return n;
359 +
360 if (access_ok(VERIFY_WRITE, to, n))
361 n = __copy_to_user(to, from, n);
362 return 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
368 * handler.
369 */
370 -struct kgdb_arch arch_kgdb_ops = {
371 +const struct kgdb_arch arch_kgdb_ops = {
372 #ifndef __ARMEB__
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
378 @@ -28,7 +28,6 @@
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>
384
385 #include <asm/cacheflush.h>
386 @@ -477,12 +476,6 @@ unsigned long get_wchan(struct task_stru
387 return 0;
388 }
389
390 -unsigned long arch_randomize_brk(struct mm_struct *mm)
391 -{
392 - unsigned long range_end = mm->brk + 0x02000000;
393 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
394 -}
395 -
396 /*
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)
403 }
404
405
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
415 return ret;
416 }
417
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,
422 };
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
427 return 0;
428 }
429
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,
434 };
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
439 return 0;
440 }
441
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,
446 };
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
451 return count;
452 }
453
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
462
463
464
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;
475 }
476
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)
486 return;
487 }
488
489 -static struct platform_suspend_ops omap_pm_ops = {
490 +static const struct platform_suspend_ops omap_pm_ops = {
491 .begin = omap3_pm_begin,
492 .end = omap3_pm_end,
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)
498 return;
499 }
500
501 -static struct platform_suspend_ops omap_pm_ops = {
502 +static const struct platform_suspend_ops omap_pm_ops = {
503 .begin = omap4_pm_begin,
504 .end = omap4_pm_end,
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);
511 }
512
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,
517 };
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();
523 }
524
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
534 }
535
536 #ifdef CONFIG_PM
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);
547 }
548
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,
553 };
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,
558 }
559 #endif
560
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);
565 + }
566 +#endif
567 +
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
572 }
573 #endif /* CONFIG_MMU */
574
575 +#ifdef CONFIG_PAX_PAGEEXEC
576 +void pax_report_insns(void *pc, void *sp)
577 +{
578 + long i;
579 +
580 + printk(KERN_ERR "PAX: bytes at PC: ");
581 + for (i = 0; i < 20; i++) {
582 + unsigned char c;
583 + if (get_user(c, (__force unsigned char __user *)pc+i))
584 + printk(KERN_CONT "?? ");
585 + else
586 + printk(KERN_CONT "%02x ", c);
587 + }
588 + printk("\n");
589 +
590 + printk(KERN_ERR "PAX: bytes at SP-4: ");
591 + for (i = -1; i < 20; i++) {
592 + unsigned long c;
593 + if (get_user(c, (__force unsigned long __user *)sp+i))
594 + printk(KERN_CONT "???????? ");
595 + else
596 + printk(KERN_CONT "%08lx ", c);
597 + }
598 + printk("\n");
599 +}
600 +#endif
601 +
602 /*
603 * First Level Translation Fault Handler
604 *
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
609 if (len > TASK_SIZE)
610 return -ENOMEM;
611
612 +#ifdef CONFIG_PAX_RANDMMAP
613 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
614 +#endif
615 +
616 if (addr) {
617 if (do_align)
618 addr = COLOUR_ALIGN(addr, pgoff);
619 @@ -71,15 +75,14 @@ arch_get_unmapped_area(struct file *filp
620 addr = PAGE_ALIGN(addr);
621
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))
626 return addr;
627 }
628 if (len > mm->cached_hole_size) {
629 - start_addr = addr = mm->free_area_cache;
630 + start_addr = addr = mm->free_area_cache;
631 } else {
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;
636 }
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
641 * some holes.
642 */
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;
648 goto full_search;
649 }
650 return -ENOMEM;
651 }
652 - if (!vma || addr + len <= vma->vm_start) {
653 + if (check_heap_stack_gap(vma, addr, len)) {
654 /*
655 * Remember the place where we stopped the search:
656 */
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();
662 }
663
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. */
675
676 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
677 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
678
679 +#ifdef CONFIG_PAX_ASLR
680 +#define PAX_ELF_ET_DYN_BASE 0x00001000UL
681 +
682 +#define PAX_DELTA_MMAP_LEN 15
683 +#define PAX_DELTA_STACK_LEN 15
684 +#endif
685
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,
692 D(11) KM_IRQ1,
693 D(12) KM_SOFTIRQ0,
694 D(13) KM_SOFTIRQ1,
695 -D(14) KM_TYPE_NR
696 +D(14) KM_CLEARPAGE,
697 +D(15) KM_TYPE_NR
698 };
699
700 #undef D
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:
705 return 0;
706 }
707
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,
712 };
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
717
718 int exception_trace = 1;
719
720 +#ifdef CONFIG_PAX_PAGEEXEC
721 +void pax_report_insns(void *pc, void *sp)
722 +{
723 + unsigned long i;
724 +
725 + printk(KERN_ERR "PAX: bytes at PC: ");
726 + for (i = 0; i < 20; i++) {
727 + unsigned char c;
728 + if (get_user(c, (unsigned char *)pc+i))
729 + printk(KERN_CONT "???????? ");
730 + else
731 + printk(KERN_CONT "%02x ", c);
732 + }
733 + printk("\n");
734 +}
735 +#endif
736 +
737 /*
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);
742
743 if (user_mode(regs)) {
744 +
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);
750 + }
751 + }
752 +#endif
753 +
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 */
762 }
763
764 -struct kgdb_arch arch_kgdb_ops = {
765 +const struct kgdb_arch arch_kgdb_ops = {
766 .gdb_bpt_instr = {0xa1},
767 #ifdef CONFIG_SMP
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
773 return 0;
774 }
775
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,
780 };
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);
786 }
787
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)
790 {
791 unsigned long lsrc = (unsigned long)src;
792 int mem_type;
793 @@ -55,7 +55,7 @@ long probe_kernel_read(void *dst, void *
794 return -EFAULT;
795 }
796
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)
799 {
800 unsigned long ldst = (unsigned long)dst;
801 int mem_type;
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 {
806 KM_IRQ1,
807 KM_SOFTIRQ0,
808 KM_SOFTIRQ1,
809 + KM_CLEARPAGE,
810 KM_TYPE_NR
811 };
812
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
817 if (addr) {
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))
823 goto success;
824 }
825
826 @@ -89,7 +88,7 @@ unsigned long arch_get_unmapped_area(str
827 for (; vma; vma = vma->vm_next) {
828 if (addr > limit)
829 break;
830 - if (addr + len <= vma->vm_start)
831 + if (check_heap_stack_gap(vma, addr, len))
832 goto success;
833 addr = vma->vm_end;
834 }
835 @@ -104,7 +103,7 @@ unsigned long arch_get_unmapped_area(str
836 for (; vma; vma = vma->vm_next) {
837 if (addr > limit)
838 break;
839 - if (addr + len <= vma->vm_start)
840 + if (check_heap_stack_gap(vma, addr, len))
841 goto success;
842 addr = vma->vm_end;
843 }
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
847 @@ -17,7 +17,7 @@
848 #include <linux/swiotlb.h>
849 #include <asm/machvec.h>
850
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;
853
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);
858 }
859
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)
862 {
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
869 },
870 };
871
872 -extern struct dma_map_ops swiotlb_dma_ops;
873 +extern const struct dma_map_ops swiotlb_dma_ops;
874
875 static int __init
876 sba_init(void)
877 @@ -2211,7 +2211,7 @@ sba_page_override(char *str)
878
879 __setup("sbapagesize=",sba_page_override);
880
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
889 @@ -12,7 +12,7 @@
890
891 #define ARCH_HAS_DMA_GET_REQUIRED_MASK
892
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);
897
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)
901 {
902 - struct dma_map_ops *ops = platform_dma_get_ops(dev);
903 + const struct dma_map_ops *ops = platform_dma_get_ops(dev);
904 void *caddr;
905
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)
910 {
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);
915 }
916 @@ -49,13 +49,13 @@ static inline void dma_free_coherent(str
917
918 static inline int dma_mapping_error(struct device *dev, dma_addr_t daddr)
919 {
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);
923 }
924
925 static inline int dma_supported(struct device *dev, u64 mask)
926 {
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);
930 }
931
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
935 @@ -42,6 +42,13 @@
936 */
937 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
938
939 +#ifdef CONFIG_PAX_ASLR
940 +#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
941 +
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)
944 +#endif
945 +
946 #define PT_IA_64_UNWIND 0x70000001
947
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 *);
958
959 /*
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 */
963
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 *);
967
968 /*
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
973 @@ -12,7 +12,7 @@
974 * David Mosberger-Tang <davidm@hpl.hp.com>
975 */
976
977 -
978 +#include <linux/const.h>
979 #include <asm/mman.h>
980 #include <asm/page.h>
981 #include <asm/processor.h>
982 @@ -143,6 +143,17 @@
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)
986 +
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)
991 +#else
992 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
993 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
994 +# define PAGE_COPY_NOEXEC PAGE_COPY
995 +#endif
996 +
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); \
1006 \
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); \
1010 __cu_len; \
1011 })
1012 @@ -269,7 +269,7 @@ __copy_from_user (void *to, const void _
1013 long __cu_len = (n); \
1014 \
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); \
1019 __cu_len; \
1020 })
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
1024 @@ -3,7 +3,7 @@
1025 /* Set this to 1 if there is a HW IOMMU in the system */
1026 int iommu_detected __read_mostly;
1027
1028 -struct dma_map_ops *dma_ops;
1029 +const struct dma_map_ops *dma_ops;
1030 EXPORT_SYMBOL(dma_ops);
1031
1032 #define PREALLOC_DMA_DEBUG_ENTRIES (1 << 16)
1033 @@ -16,7 +16,7 @@ static int __init dma_init(void)
1034 }
1035 fs_initcall(dma_init);
1036
1037 -struct dma_map_ops *dma_get_ops(struct device *dev)
1038 +const struct dma_map_ops *dma_get_ops(struct device *dev)
1039 {
1040 return dma_ops;
1041 }
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)
1046 void
1047 module_free (struct module *mod, void *module_region)
1048 {
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;
1054 }
1055 @@ -502,15 +501,39 @@ module_frob_arch_sections (Elf_Ehdr *ehd
1056 }
1057
1058 static inline int
1059 +in_init_rx (const struct module *mod, uint64_t addr)
1060 +{
1061 + return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
1062 +}
1063 +
1064 +static inline int
1065 +in_init_rw (const struct module *mod, uint64_t addr)
1066 +{
1067 + return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
1068 +}
1069 +
1070 +static inline int
1071 in_init (const struct module *mod, uint64_t addr)
1072 {
1073 - return addr - (uint64_t) mod->module_init < mod->init_size;
1074 + return in_init_rx(mod, addr) || in_init_rw(mod, addr);
1075 +}
1076 +
1077 +static inline int
1078 +in_core_rx (const struct module *mod, uint64_t addr)
1079 +{
1080 + return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
1081 +}
1082 +
1083 +static inline int
1084 +in_core_rw (const struct module *mod, uint64_t addr)
1085 +{
1086 + return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
1087 }
1088
1089 static inline int
1090 in_core (const struct module *mod, uint64_t addr)
1091 {
1092 - return addr - (uint64_t) mod->module_core < mod->core_size;
1093 + return in_core_rx(mod, addr) || in_core_rw(mod, addr);
1094 }
1095
1096 static inline int
1097 @@ -693,7 +716,14 @@ do_reloc (struct module *mod, uint8_t r_
1098 break;
1099
1100 case RV_BDREL:
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;
1110 break;
1111
1112 case RV_LTV:
1113 @@ -828,15 +858,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs,
1114 * addresses have been selected...
1115 */
1116 uint64_t gp;
1117 - if (mod->core_size > MAX_LTOFF)
1118 + if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
1119 /*
1120 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
1121 * at the end of the module.
1122 */
1123 - gp = mod->core_size - MAX_LTOFF / 2;
1124 + gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
1125 else
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);
1130 mod->arch.gp = gp;
1131 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
1132 }
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,
1138 };
1139
1140 -extern struct dma_map_ops intel_dma_ops;
1141 +extern const struct dma_map_ops intel_dma_ops;
1142
1143 static int __init pci_iommu_init(void)
1144 {
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);
1150 }
1151
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)
1162 addr = 0;
1163 #endif
1164 +
1165 +#ifdef CONFIG_PAX_RANDMMAP
1166 + if (mm->pax_flags & MF_PAX_RANDMMAP)
1167 + addr = mm->free_area_cache;
1168 + else
1169 +#endif
1170 +
1171 if (!addr)
1172 addr = mm->free_area_cache;
1173
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;
1183 goto full_search;
1184 }
1185 return -ENOMEM;
1186 }
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;
1191 return addr;
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 {
1196 /* Per-cpu data: */
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;
1201 /*
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);
1209 }
1210
1211 +#ifdef CONFIG_PAX_PAGEEXEC
1212 +void pax_report_insns(void *pc, void *sp)
1213 +{
1214 + unsigned long i;
1215 +
1216 + printk(KERN_ERR "PAX: bytes at PC: ");
1217 + for (i = 0; i < 8; i++) {
1218 + unsigned int c;
1219 + if (get_user(c, (unsigned int *)pc+i))
1220 + printk(KERN_CONT "???????? ");
1221 + else
1222 + printk(KERN_CONT "%08x ", c);
1223 + }
1224 + printk("\n");
1225 +}
1226 +#endif
1227 +
1228 void __kprobes
1229 ia64_do_page_fault (unsigned long address, unsigned long isr, struct pt_regs *regs)
1230 {
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));
1234
1235 - if ((vma->vm_flags & mask) != mask)
1236 + if ((vma->vm_flags & mask) != mask) {
1237 +
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)
1241 + goto bad_area;
1242 +
1243 + up_read(&mm->mmap_sem);
1244 + pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
1245 + do_group_exit(SIGKILL);
1246 + }
1247 +#endif
1248 +
1249 goto bad_area;
1250
1251 + }
1252 +
1253 /*
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)
1262 return -ENOMEM;
1263 - if (!vmm || (addr + len) <= vmm->vm_start)
1264 + if (check_heap_stack_gap(vmm, addr, len))
1265 return addr;
1266 addr = ALIGN(vmm->vm_end, HPAGE_SIZE);
1267 }
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;
1275 +
1276 +#ifdef CONFIG_PAX_PAGEEXEC
1277 + if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
1278 + vma->vm_flags &= ~VM_EXEC;
1279 +
1280 +#ifdef CONFIG_PAX_MPROTECT
1281 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
1282 + vma->vm_flags &= ~VM_MAYEXEC;
1283 +#endif
1284 +
1285 + }
1286 +#endif
1287 +
1288 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
1289 down_write(&current->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 *
1295 return ret;
1296 }
1297
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
1306 @@ -14,6 +14,9 @@
1307 unsigned long
1308 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
1309 {
1310 + if ((long)n < 0)
1311 + return n;
1312 +
1313 prefetch(from);
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,
1317 unsigned long
1318 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
1319 {
1320 + if ((long)n < 0)
1321 + return n;
1322 +
1323 prefetchw(to);
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;
1330
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;
1335 void *dma_data;
1336 };
1337
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;
1343 }
1344
1345 -extern struct dma_map_ops *dma_ops;
1346 +extern const struct dma_map_ops *dma_ops;
1347
1348 /*
1349 * Available generic sets of operations
1350 */
1351 -extern struct dma_map_ops dma_direct_ops;
1352 +extern const struct dma_map_ops dma_direct_ops;
1353
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)
1356 {
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;
1361 }
1362
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)
1365 {
1366 dev->archdata.dma_ops = ops;
1367 }
1368
1369 static inline int dma_supported(struct device *dev, u64 mask)
1370 {
1371 - struct dma_map_ops *ops = get_dma_ops(dev);
1372 + const struct dma_map_ops *ops = get_dma_ops(dev);
1373
1374 if (unlikely(!ops))
1375 return 0;
1376 @@ -81,7 +81,7 @@ static inline int dma_supported(struct d
1377
1378 static inline int dma_set_mask(struct device *dev, u64 dma_mask)
1379 {
1380 - struct dma_map_ops *ops = get_dma_ops(dev);
1381 + const struct dma_map_ops *ops = get_dma_ops(dev);
1382
1383 if (unlikely(ops == NULL))
1384 return -EIO;
1385 @@ -97,7 +97,7 @@ static inline int dma_set_mask(struct de
1386
1387 static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
1388 {
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);
1393
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)
1397 {
1398 - struct dma_map_ops *ops = get_dma_ops(dev);
1399 + const struct dma_map_ops *ops = get_dma_ops(dev);
1400 void *memory;
1401
1402 BUG_ON(!ops);
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)
1406 {
1407 - struct dma_map_ops *ops = get_dma_ops(dev);
1408 + const struct dma_map_ops *ops = get_dma_ops(dev);
1409
1410 BUG_ON(!ops);
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_
1416 }
1417
1418 #ifdef CONFIG_PCI
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);
1431 }
1432
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)
1442 /*
1443 * Global data
1444 */
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 */
1449 #else
1450 +>>>>>>> master
1451 .gdb_bpt_instr = {0xba, 0x0c, 0x00, 0x18}, /* brki r16, 0x18 */
1452 #endif
1453 };
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;
1460
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;
1463
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)
1466 {
1467 pci_dma_ops = dma_ops;
1468 }
1469
1470 -struct dma_map_ops *get_pci_dma_ops(void)
1471 +const struct dma_map_ops *get_pci_dma_ops(void)
1472 {
1473 return pci_dma_ops;
1474 }
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)
1479
1480 }
1481
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
1491 }
1492
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);
1498 };
1499 @@ -324,7 +324,7 @@ static struct octeon_dma_map_ops _octeon
1500 },
1501 };
1502
1503 -struct dma_map_ops *octeon_pci_dma_map_ops;
1504 +const struct dma_map_ops *octeon_pci_dma_map_ops;
1505
1506 void __init octeon_pci_dma_init(void)
1507 {
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;
1512
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;
1517 };
1518
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
1523 @@ -7,9 +7,9 @@
1524
1525 #include <dma-coherence.h>
1526
1527 -extern struct dma_map_ops *mips_dma_map_ops;
1528 +extern const struct dma_map_ops *mips_dma_map_ops;
1529
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)
1532 {
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 *
1536
1537 static inline int dma_supported(struct device *dev, u64 mask)
1538 {
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);
1542 }
1543
1544 static inline int dma_mapping_error(struct device *dev, u64 mask)
1545 {
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);
1549 }
1550
1551 @@ -59,7 +59,7 @@ static inline void *dma_alloc_coherent(s
1552 dma_addr_t *dma_handle, gfp_t gfp)
1553 {
1554 void *ret;
1555 - struct dma_map_ops *ops = get_dma_ops(dev);
1556 + const struct dma_map_ops *ops = get_dma_ops(dev);
1557
1558 ret = ops->alloc_coherent(dev, size, dma_handle, gfp);
1559
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)
1563 {
1564 - struct dma_map_ops *ops = get_dma_ops(dev);
1565 + const struct dma_map_ops *ops = get_dma_ops(dev);
1566
1567 ops->free_coherent(dev, size, vaddr, dma_handle);
1568
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)
1574 #endif
1575
1576 +#ifdef CONFIG_PAX_ASLR
1577 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT_ADDR) ? 0x00400000UL : 0x00400000UL)
1578 +
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)
1581 +#endif
1582 +
1583 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
1584 struct linux_binprm;
1585 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
1586 int uses_interp);
1587
1588 -struct mm_struct;
1589 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1590 -#define arch_randomize_brk arch_randomize_brk
1591 -
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);
1598
1599 struct dma_map_ops;
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;
1603
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; })
1614 #else
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
1620 @@ -23,6 +23,7 @@
1621 #include <asm/dsp.h>
1622 #include <asm/watch.h>
1623 #include <asm/war.h>
1624 +#include <asm/asm.h>
1625
1626
1627 /*
1628 @@ -230,6 +231,6 @@ extern void per_cpu_trap_init(void);
1629 */
1630 #define __ARCH_WANT_UNLOCKED_CTXSW
1631
1632 -extern unsigned long arch_align_stack(unsigned long sp);
1633 +#define arch_align_stack(x) ((x) & ALMASK)
1634
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
1640 return 0;
1641 }
1642
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,
1647 };
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)
1654
1655 +#ifdef CONFIG_PAX_ASLR
1656 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT_ADDR) ? 0x00400000UL : 0x00400000UL)
1657 +
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)
1660 +#endif
1661 +
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)
1671
1672 +#ifdef CONFIG_PAX_ASLR
1673 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT_ADDR) ? 0x00400000UL : 0x00400000UL)
1674 +
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)
1677 +#endif
1678 +
1679 #include <asm/processor.h>
1680
1681 /*
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
1686 return -1;
1687 }
1688
1689 +/* cannot be const, see kgdb_arch_init */
1690 struct kgdb_arch arch_kgdb_ops;
1691
1692 /*
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
1697 out:
1698 return pc;
1699 }
1700 -
1701 -/*
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.
1704 - */
1705 -unsigned long arch_align_stack(unsigned long sp)
1706 -{
1707 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
1708 - sp -= get_random_int() & ~PAGE_MASK;
1709 -
1710 - return sp & ALMASK;
1711 -}
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
1716 do_color_align = 0;
1717 if (filp || (flags & MAP_SHARED))
1718 do_color_align = 1;
1719 +
1720 +#ifdef CONFIG_PAX_RANDMMAP
1721 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
1722 +#endif
1723 +
1724 if (addr) {
1725 if (do_color_align)
1726 addr = COLOUR_ALIGN(addr, pgoff);
1727 else
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))
1733 return addr;
1734 }
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)
1739 return -ENOMEM;
1740 - if (!vmm || addr + len <= vmm->vm_start)
1741 + if (check_heap_stack_gap(vmm, addr, len))
1742 return addr;
1743 addr = vmm->vm_end;
1744 if (do_color_align)
1745 @@ -168,19 +172,6 @@ static inline unsigned long brk_rnd(void
1746 return rnd;
1747 }
1748
1749 -unsigned long arch_randomize_brk(struct mm_struct *mm)
1750 -{
1751 - unsigned long base = mm->brk;
1752 - unsigned long ret;
1753 -
1754 - ret = PAGE_ALIGN(base + brk_rnd());
1755 -
1756 - if (ret < mm->brk)
1757 - return mm->brk;
1758 -
1759 - return ret;
1760 -}
1761 -
1762 SYSCALL_DEFINE6(mips_mmap, unsigned long, addr, unsigned long, len,
1763 unsigned long, prot, unsigned long, flags, unsigned long,
1764 fd, off_t, offset)
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
1769 }
1770 }
1771
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,
1776 };
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,
1781
1782 EXPORT_SYMBOL(dma_cache_sync);
1783
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
1791 };
1792
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);
1796
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
1801 @@ -28,6 +28,23 @@
1802 #include <asm/highmem.h> /* For VMALLOC_END */
1803 #include <linux/kdebug.h>
1804
1805 +#ifdef CONFIG_PAX_PAGEEXEC
1806 +void pax_report_insns(void *pc, void *sp)
1807 +{
1808 + unsigned long i;
1809 +
1810 + printk(KERN_ERR "PAX: bytes at PC: ");
1811 + for (i = 0; i < 5; i++) {
1812 + unsigned int c;
1813 + if (get_user(c, (unsigned int *)pc+i))
1814 + printk(KERN_CONT "???????? ");
1815 + else
1816 + printk(KERN_CONT "%08x ", c);
1817 + }
1818 + printk("\n");
1819 +}
1820 +#endif
1821 +
1822 /*
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..
1829
1830 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
1831
1832 +#ifdef CONFIG_PAX_ASLR
1833 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
1834 +
1835 +#define PAX_DELTA_MMAP_LEN 16
1836 +#define PAX_DELTA_STACK_LEN 16
1837 +#endif
1838 +
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)
1849 +
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)
1854 +#else
1855 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
1856 +# define PAGE_COPY_NOEXEC PAGE_COPY
1857 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
1858 +#endif
1859 +
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
1866 @@ -96,16 +96,38 @@
1867
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)
1871 +{
1872 + return (loc >= me->module_init_rx &&
1873 + loc < (me->module_init_rx + me->init_size_rx));
1874 +}
1875 +
1876 +static inline int in_init_rw(struct module *me, void *loc)
1877 +{
1878 + return (loc >= me->module_init_rw &&
1879 + loc < (me->module_init_rw + me->init_size_rw));
1880 +}
1881 +
1882 static inline int in_init(struct module *me, void *loc)
1883 {
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);
1887 +}
1888 +
1889 +static inline int in_core_rx(struct module *me, void *loc)
1890 +{
1891 + return (loc >= me->module_core_rx &&
1892 + loc < (me->module_core_rx + me->core_size_rx));
1893 +}
1894 +
1895 +static inline int in_core_rw(struct module *me, void *loc)
1896 +{
1897 + return (loc >= me->module_core_rw &&
1898 + loc < (me->module_core_rw + me->core_size_rw));
1899 }
1900
1901 static inline int in_core(struct module *me, void *loc)
1902 {
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);
1906 }
1907
1908 static inline int in_local(struct module *me, void *loc)
1909 @@ -365,13 +387,13 @@ int module_frob_arch_sections(CONST Elf_
1910 }
1911
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);
1916 -
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);
1923 +
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);
1927
1928 me->arch.got_max = gots;
1929 me->arch.fdesc_max = fdescs;
1930 @@ -389,7 +411,7 @@ static Elf64_Word get_got(struct module
1931
1932 BUG_ON(value == 0);
1933
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)
1938 goto out;
1939 @@ -407,7 +429,7 @@ static Elf64_Word get_got(struct module
1940 #ifdef CONFIG_64BIT
1941 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
1942 {
1943 - Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
1944 + Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
1945
1946 if (!value) {
1947 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
1948 @@ -425,7 +447,7 @@ static Elf_Addr get_fdesc(struct module
1949
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;
1955 }
1956 #endif /* CONFIG_64BIT */
1957 @@ -849,7 +871,7 @@ register_unwind_table(struct module *me,
1958
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;
1963
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)
1972 return -ENOMEM;
1973 - if (!vma || addr + len <= vma->vm_start)
1974 + if (check_heap_stack_gap(vma, addr, len))
1975 return addr;
1976 addr = vma->vm_end;
1977 }
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)
1981 return -ENOMEM;
1982 - if (!vma || addr + len <= vma->vm_start)
1983 + if (check_heap_stack_gap(vma, addr, len))
1984 return addr;
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)
1989 return addr;
1990 if (!addr)
1991 - addr = TASK_UNMAPPED_BASE;
1992 + addr = current->mm->mmap_base;
1993
1994 if (filp) {
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
2000
2001 down_read(&current->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)) {
2005 -
2006 + if (vma && (regs->iaoq[0] >= vma->vm_start)) {
2007 fault_address = regs->iaoq[0];
2008 fault_space = regs->iasq[0];
2009
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
2013 @@ -15,6 +15,7 @@
2014 #include <linux/sched.h>
2015 #include <linux/interrupt.h>
2016 #include <linux/module.h>
2017 +#include <linux/unistd.h>
2018
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)
2024 {
2025 - if (code == 6 || code == 16)
2026 + if (code == 6 || code == 7 || code == 16)
2027 return VM_EXEC;
2028
2029 switch (inst & 0xf0000000) {
2030 @@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsign
2031 }
2032 #endif
2033
2034 +#ifdef CONFIG_PAX_PAGEEXEC
2035 +/*
2036 + * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
2037 + *
2038 + * returns 1 when task should be killed
2039 + * 2 when rt_sigreturn trampoline was detected
2040 + * 3 when unpatched PLT trampoline was detected
2041 + */
2042 +static int pax_handle_fetch_fault(struct pt_regs *regs)
2043 +{
2044 +
2045 +#ifdef CONFIG_PAX_EMUPLT
2046 + int err;
2047 +
2048 + do { /* PaX: unpatched PLT emulation */
2049 + unsigned int bl, depwi;
2050 +
2051 + err = get_user(bl, (unsigned int *)instruction_pointer(regs));
2052 + err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
2053 +
2054 + if (err)
2055 + break;
2056 +
2057 + if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
2058 + unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
2059 +
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));
2063 +
2064 + if (err)
2065 + break;
2066 +
2067 + if (ldw == 0x0E801096U &&
2068 + bv == 0xEAC0C000U &&
2069 + ldw2 == 0x0E881095U)
2070 + {
2071 + unsigned int resolver, map;
2072 +
2073 + err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
2074 + err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
2075 + if (err)
2076 + break;
2077 +
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;
2083 + return 3;
2084 + }
2085 + }
2086 + } while (0);
2087 +#endif
2088 +
2089 +#ifdef CONFIG_PAX_EMUTRAMP
2090 +
2091 +#ifndef CONFIG_PAX_EMUSIGRT
2092 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
2093 + return 1;
2094 +#endif
2095 +
2096 + do { /* PaX: rt_sigreturn emulation */
2097 + unsigned int ldi1, ldi2, bel, nop;
2098 +
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));
2103 +
2104 + if (err)
2105 + break;
2106 +
2107 + if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
2108 + ldi2 == 0x3414015AU &&
2109 + bel == 0xE4008200U &&
2110 + nop == 0x08000240U)
2111 + {
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];
2120 + return 2;
2121 + }
2122 + } while (0);
2123 +#endif
2124 +
2125 + return 1;
2126 +}
2127 +
2128 +void pax_report_insns(void *pc, void *sp)
2129 +{
2130 + unsigned long i;
2131 +
2132 + printk(KERN_ERR "PAX: bytes at PC: ");
2133 + for (i = 0; i < 5; i++) {
2134 + unsigned int c;
2135 + if (get_user(c, (unsigned int *)pc+i))
2136 + printk(KERN_CONT "???????? ");
2137 + else
2138 + printk(KERN_CONT "%08x ", c);
2139 + }
2140 + printk("\n");
2141 +}
2142 +#endif
2143 +
2144 int fixup_exception(struct pt_regs *regs)
2145 {
2146 const struct exception_table_entry *fix;
2147 @@ -192,8 +303,33 @@ good_area:
2148
2149 acc_type = parisc_acctyp(code,regs->iir);
2150
2151 - if ((vma->vm_flags & acc_type) != acc_type)
2152 + if ((vma->vm_flags & acc_type) != acc_type) {
2153 +
2154 +#ifdef CONFIG_PAX_PAGEEXEC
2155 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
2156 + (address & ~3UL) == instruction_pointer(regs))
2157 + {
2158 + up_read(&mm->mmap_sem);
2159 + switch (pax_handle_fetch_fault(regs)) {
2160 +
2161 +#ifdef CONFIG_PAX_EMUPLT
2162 + case 3:
2163 + return;
2164 +#endif
2165 +
2166 +#ifdef CONFIG_PAX_EMUTRAMP
2167 + case 2:
2168 + return;
2169 +#endif
2170 +
2171 + }
2172 + pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
2173 + do_group_exit(SIGKILL);
2174 + }
2175 +#endif
2176 +
2177 goto bad_area;
2178 + }
2179
2180 /*
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;
2186
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;
2191
2192 /*
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
2198 /*
2199 * Available generic sets of operations
2200 */
2201 +/* cannot be const */
2202 #ifdef CONFIG_PPC64
2203 -extern struct dma_map_ops dma_iommu_ops;
2204 +extern const struct dma_map_ops dma_iommu_ops;
2205 #endif
2206 -extern struct dma_map_ops dma_direct_ops;
2207 +extern const struct dma_map_ops dma_direct_ops;
2208
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)
2211 {
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;
2216 }
2217
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)
2220 {
2221 dev->archdata.dma_ops = ops;
2222 }
2223 @@ -118,7 +119,7 @@ static inline void set_dma_offset(struct
2224
2225 static inline int dma_supported(struct device *dev, u64 mask)
2226 {
2227 - struct dma_map_ops *dma_ops = get_dma_ops(dev);
2228 + const struct dma_map_ops *dma_ops = get_dma_ops(dev);
2229
2230 if (unlikely(dma_ops == NULL))
2231 return 0;
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)
2235 {
2236 - struct dma_map_ops *dma_ops = get_dma_ops(dev);
2237 + const struct dma_map_ops *dma_ops = get_dma_ops(dev);
2238 void *cpu_addr;
2239
2240 BUG_ON(!dma_ops);
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)
2244 {
2245 - struct dma_map_ops *dma_ops = get_dma_ops(dev);
2246 + const struct dma_map_ops *dma_ops = get_dma_ops(dev);
2247
2248 BUG_ON(!dma_ops);
2249
2250 @@ -158,7 +159,7 @@ static inline void dma_free_coherent(str
2251
2252 static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
2253 {
2254 - struct dma_map_ops *dma_ops = get_dma_ops(dev);
2255 + const struct dma_map_ops *dma_ops = get_dma_ops(dev);
2256
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. */
2265
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)
2269 +
2270 +#ifdef CONFIG_PAX_ASLR
2271 +#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
2272 +
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)
2276 +#else
2277 +#define PAX_DELTA_MMAP_LEN 15
2278 +#define PAX_DELTA_STACK_LEN 15
2279 +#endif
2280 +#endif
2281
2282 /*
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)))
2287
2288 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
2289 -#define arch_randomize_brk arch_randomize_brk
2290 -
2291 #endif /* __KERNEL__ */
2292
2293 /*
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);
2300
2301 +/* dma-iommu.c */
2302 +extern int dma_iommu_dma_supported(struct device *dev, u64 mask);
2303 +
2304 #ifdef CONFIG_PCI
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 {
2311 KM_PPC_SYNC_PAGE,
2312 KM_PPC_SYNC_ICACHE,
2313 KM_KDB,
2314 + KM_CLEARPAGE,
2315 KM_TYPE_NR
2316 };
2317
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.
2324 */
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)
2330
2331 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
2332 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
2333
2334 +#ifndef CONFIG_PAX_PAGEEXEC
2335 #define VM_STACK_DEFAULT_FLAGS \
2336 (is_32bit_task() ? \
2337 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
2338 +#endif
2339
2340 #include <asm-generic/getorder.h>
2341
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.
2348 */
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)
2354
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)
2359 #endif
2360
2361 +#define ktla_ktva(addr) (addr)
2362 +#define ktva_ktla(addr) (addr)
2363 +
2364 #ifndef __ASSEMBLY__
2365
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
2371 }
2372
2373 #ifdef CONFIG_PCI
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
2384 @@ -21,6 +21,7 @@
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
2395 @@ -191,6 +191,7 @@
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
2406 @@ -13,7 +13,7 @@
2407
2408 #include <linux/swiotlb.h>
2409
2410 -extern struct dma_map_ops swiotlb_dma_ops;
2411 +extern const struct dma_map_ops swiotlb_dma_ops;
2412
2413 static inline void dma_mark_clean(void *addr, size_t size) {}
2414
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))
2420 #endif
2421
2422 -extern unsigned long arch_align_stack(unsigned long sp);
2423 +#define arch_align_stack(x) ((x) & ~0xfUL)
2424
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
2430 @@ -13,6 +13,8 @@
2431 #define VERIFY_READ 0
2432 #define VERIFY_WRITE 1
2433
2434 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
2435 +
2436 /*
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);
2442
2443 -#ifndef __powerpc64__
2444 -
2445 -static inline unsigned long copy_from_user(void *to,
2446 - const void __user *from, unsigned long n)
2447 -{
2448 - unsigned long over;
2449 -
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,
2455 - n - over) + over;
2456 - }
2457 - return n;
2458 -}
2459 -
2460 -static inline unsigned long copy_to_user(void __user *to,
2461 - const void *from, unsigned long n)
2462 -{
2463 - unsigned long over;
2464 -
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,
2470 - n - over) + over;
2471 - }
2472 - return n;
2473 -}
2474 -
2475 -#else /* __powerpc64__ */
2476 -
2477 -#define __copy_in_user(to, from, size) \
2478 - __copy_tofrom_user((to), (from), (size))
2479 -
2480 -extern unsigned long copy_from_user(void *to, const void __user *from,
2481 - unsigned long n);
2482 -extern unsigned long copy_to_user(void __user *to, const void *from,
2483 - unsigned long n);
2484 -extern unsigned long copy_in_user(void __user *to, const void __user *from,
2485 - unsigned long n);
2486 -
2487 -#endif /* __powerpc64__ */
2488 -
2489 static inline unsigned long __copy_from_user_inatomic(void *to,
2490 const void __user *from, unsigned long n)
2491 {
2492 @@ -396,6 +352,10 @@ static inline unsigned long __copy_from_
2493 if (ret == 0)
2494 return 0;
2495 }
2496 +
2497 + if (!__builtin_constant_p(n))
2498 + check_object_size(to, n, false);
2499 +
2500 return __copy_tofrom_user((__force void __user *)to, from, n);
2501 }
2502
2503 @@ -422,6 +382,10 @@ static inline unsigned long __copy_to_us
2504 if (ret == 0)
2505 return 0;
2506 }
2507 +
2508 + if (!__builtin_constant_p(n))
2509 + check_object_size(from, n, true);
2510 +
2511 return __copy_tofrom_user(to, (__force const void __user *)from, n);
2512 }
2513
2514 @@ -439,6 +403,92 @@ static inline unsigned long __copy_to_us
2515 return __copy_to_user_inatomic(to, from, size);
2516 }
2517
2518 +#ifndef __powerpc64__
2519 +
2520 +static inline unsigned long __must_check copy_from_user(void *to,
2521 + const void __user *from, unsigned long n)
2522 +{
2523 + unsigned long over;
2524 +
2525 + if ((long)n < 0)
2526 + return n;
2527 +
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);
2532 + }
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,
2538 + n - over) + over;
2539 + }
2540 + return n;
2541 +}
2542 +
2543 +static inline unsigned long __must_check copy_to_user(void __user *to,
2544 + const void *from, unsigned long n)
2545 +{
2546 + unsigned long over;
2547 +
2548 + if ((long)n < 0)
2549 + return n;
2550 +
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);
2555 + }
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,
2561 + n - over) + over;
2562 + }
2563 + return n;
2564 +}
2565 +
2566 +#else /* __powerpc64__ */
2567 +
2568 +#define __copy_in_user(to, from, size) \
2569 + __copy_tofrom_user((to), (from), (size))
2570 +
2571 +static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
2572 +{
2573 + if ((long)n < 0 || n > INT_MAX)
2574 + return n;
2575 +
2576 + if (!__builtin_constant_p(n))
2577 + check_object_size(to, n, false);
2578 +
2579 + if (likely(access_ok(VERIFY_READ, from, n)))
2580 + n = __copy_from_user(to, from, n);
2581 + else
2582 + memset(to, 0, n);
2583 + return n;
2584 +}
2585 +
2586 +static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
2587 +{
2588 + if ((long)n < 0 || n > INT_MAX)
2589 + return n;
2590 +
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);
2595 + }
2596 + return n;
2597 +}
2598 +
2599 +extern unsigned long copy_in_user(void __user *to, const void __user *from,
2600 + unsigned long n);
2601 +
2602 +#endif /* __powerpc64__ */
2603 +
2604 extern unsigned long __clear_user(void __user *addr, unsigned long size);
2605
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
2611 }
2612 #endif
2613
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);
2620
2621 int dma_set_mask(struct device *dev, u64 dma_mask)
2622 {
2623 - struct dma_map_ops *dma_ops = get_dma_ops(dev);
2624 + const struct dma_map_ops *dma_ops = get_dma_ops(dev);
2625
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
2632 }
2633
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)
2637 {
2638 struct iommu_table *tbl = get_iommu_table_base(dev);
2639
2640 @@ -90,6 +90,7 @@ static int dma_iommu_dma_supported(struc
2641 return 1;
2642 }
2643
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.
2654 */
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:
2664 std r14,_DAR(r1)
2665 std r15,_DSISR(r1)
2666 addi r3,r1,STACK_FRAME_OVERHEAD
2667 + bl .save_nvgprs
2668 mr r4,r14
2669 mr r5,r15
2670 ld r14,PACA_EXGEN+EX_R14(r13)
2671 @@ -504,8 +505,7 @@ storage_fault_common:
2672 cmpdi r3,0
2673 bne- 1f
2674 b .ret_from_except_lite
2675 -1: bl .save_nvgprs
2676 - mr r5,r3
2677 +1: mr r5,r3
2678 addi r3,r1,STACK_FRAME_OVERHEAD
2679 ld r4,_DAR(r1)
2680 bl .bad_page_fault
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:
2685 11: ld r4,_DAR(r1)
2686 ld r5,_DSISR(r1)
2687 addi r3,r1,STACK_FRAME_OVERHEAD
2688 + bl .save_nvgprs
2689 bl .do_page_fault
2690 cmpdi r3,0
2691 beq+ 13f
2692 - bl .save_nvgprs
2693 mr r5,r3
2694 addi r3,r1,STACK_FRAME_OVERHEAD
2695 lwz r4,_DAR(r1)
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
2700 return 1;
2701 }
2702
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
2712 /*
2713 * Global data
2714 */
2715 -struct kgdb_arch arch_kgdb_ops = {
2716 +const struct kgdb_arch arch_kgdb_ops = {
2717 .gdb_bpt_instr = {0x7d, 0x82, 0x10, 0x08},
2718 };
2719
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;
2725 }
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);
2729 return -ENOEXEC;
2730 }
2731
2732 @@ -203,11 +203,16 @@ static uint32_t do_plt_call(void *locati
2733
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;
2741 - else
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;
2745 + else {
2746 + printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
2747 + return ~0UL;
2748 + }
2749
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
2755 @@ -31,11 +31,24 @@
2756
2757 LIST_HEAD(module_bug_list);
2758
2759 +#ifdef CONFIG_PAX_KERNEXEC
2760 void *module_alloc(unsigned long size)
2761 {
2762 if (size == 0)
2763 return NULL;
2764
2765 + return vmalloc(size);
2766 +}
2767 +
2768 +void *module_alloc_exec(unsigned long size)
2769 +#else
2770 +void *module_alloc(unsigned long size)
2771 +#endif
2772 +
2773 +{
2774 + if (size == 0)
2775 + return NULL;
2776 +
2777 return vmalloc_exec(size);
2778 }
2779
2780 @@ -45,6 +58,13 @@ void module_free(struct module *mod, voi
2781 vfree(module_region);
2782 }
2783
2784 +#ifdef CONFIG_PAX_KERNEXEC
2785 +void module_free_exec(struct module *mod, void *module_region)
2786 +{
2787 + module_free(mod, module_region);
2788 +}
2789 +#endif
2790 +
2791 static const Elf_Shdr *find_section(const Elf_Ehdr *hdr,
2792 const Elf_Shdr *sechdrs,
2793 const char *name)
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;
2799
2800
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;
2803
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)
2806 {
2807 pci_dma_ops = dma_ops;
2808 }
2809
2810 -struct dma_map_ops *get_pci_dma_ops(void)
2811 +const struct dma_map_ops *get_pci_dma_ops(void)
2812 {
2813 return pci_dma_ops;
2814 }
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
2821 */
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);
2826 #endif
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,
2830 newsp = stack[0];
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) {
2837 - printk(" (%pS)",
2838 + printk(" (%pA)",
2839 (void *)current->ret_stack[curr_frame].ret);
2840 curr_frame--;
2841 }
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);
2845 lr = regs->link;
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);
2849 firstframe = 1;
2850 }
2851 @@ -1242,58 +1242,3 @@ void thread_info_cache_init(void)
2852 }
2853
2854 #endif /* THREAD_SHIFT < PAGE_SHIFT */
2855 -
2856 -unsigned long arch_align_stack(unsigned long sp)
2857 -{
2858 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
2859 - sp -= get_random_int() & ~PAGE_MASK;
2860 - return sp & ~0xf;
2861 -}
2862 -
2863 -static inline unsigned long brk_rnd(void)
2864 -{
2865 - unsigned long rnd = 0;
2866 -
2867 - /* 8MB for 32bit, 1GB for 64bit */
2868 - if (is_32bit_task())
2869 - rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
2870 - else
2871 - rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
2872 -
2873 - return rnd << PAGE_SHIFT;
2874 -}
2875 -
2876 -unsigned long arch_randomize_brk(struct mm_struct *mm)
2877 -{
2878 - unsigned long base = mm->brk;
2879 - unsigned long ret;
2880 -
2881 -#ifdef CONFIG_PPC_STD_MMU_64
2882 - /*
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.
2888 - */
2889 - if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
2890 - base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
2891 -#endif
2892 -
2893 - ret = PAGE_ALIGN(base + brk_rnd());
2894 -
2895 - if (ret < mm->brk)
2896 - return mm->brk;
2897 -
2898 - return ret;
2899 -}
2900 -
2901 -unsigned long randomize_et_dyn(unsigned long base)
2902 -{
2903 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
2904 -
2905 - if (ret < base)
2906 - return base;
2907 -
2908 - return ret;
2909 -}
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;
2916 addr = frame;
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))
2920 goto badframe;
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;
2927
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;
2932 } else {
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
2937 @@ -36,6 +36,7 @@
2938 #include <asm/firmware.h>
2939 #include <asm/vdso.h>
2940 #include <asm/vdso_datapage.h>
2941 +#include <asm/mman.h>
2942
2943 #include "setup.h"
2944
2945 @@ -220,7 +221,7 @@ int arch_setup_additional_pages(struct l
2946 vdso_base = VDSO32_MBASE;
2947 #endif
2948
2949 - current->mm->context.vdso_base = 0;
2950 + current->mm->context.vdso_base = ~0UL;
2951
2952 /* vDSO has a problem and was disabled, just don't "enable" it for the
2953 * process
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),
2958 - 0, 0);
2959 + 0, MAP_PRIVATE | MAP_EXECUTABLE);
2960 if (IS_ERR_VALUE(vdso_base)) {
2961 rc = vdso_base;
2962 goto fail_mmapsem;
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);
2968 }
2969
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,
2979
2980 @@ -858,7 +859,6 @@ static void vio_cmo_bus_remove(struct vi
2981
2982 static void vio_cmo_set_dma_ops(struct vio_dev *viodev)
2983 {
2984 - vio_dma_mapping_ops.dma_supported = dma_iommu_ops.dma_supported;
2985 viodev->dev.archdata.dma_ops = &vio_dma_mapping_ops;
2986 }
2987
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
2991 @@ -9,22 +9,6 @@
2992 #include <linux/module.h>
2993 #include <asm/uaccess.h>
2994
2995 -unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
2996 -{
2997 - if (likely(access_ok(VERIFY_READ, from, n)))
2998 - n = __copy_from_user(to, from, n);
2999 - else
3000 - memset(to, 0, n);
3001 - return n;
3002 -}
3003 -
3004 -unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
3005 -{
3006 - if (likely(access_ok(VERIFY_WRITE, to, n)))
3007 - n = __copy_to_user(to, from, n);
3008 - return n;
3009 -}
3010 -
3011 unsigned long copy_in_user(void __user *to, const void __user *from,
3012 unsigned long n)
3013 {
3014 @@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *
3015 return n;
3016 }
3017
3018 -EXPORT_SYMBOL(copy_from_user);
3019 -EXPORT_SYMBOL(copy_to_user);
3020 EXPORT_SYMBOL(copy_in_user);
3021
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
3025 @@ -31,6 +31,10 @@
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>
3033
3034 #include <asm/firmware.h>
3035 #include <asm/page.h>
3036 @@ -42,6 +46,7 @@
3037 #include <asm/tlbflush.h>
3038 #include <asm/siginfo.h>
3039 #include <mm/mmu_decl.h>
3040 +#include <asm/ptrace.h>
3041
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
3045 }
3046 #endif
3047
3048 +#ifdef CONFIG_PAX_PAGEEXEC
3049 +/*
3050 + * PaX: decide what to do with offenders (regs->nip = fault address)
3051 + *
3052 + * returns 1 when task should be killed
3053 + */
3054 +static int pax_handle_fetch_fault(struct pt_regs *regs)
3055 +{
3056 + return 1;
3057 +}
3058 +
3059 +void pax_report_insns(void *pc, void *sp)
3060 +{
3061 + unsigned long i;
3062 +
3063 + printk(KERN_ERR "PAX: bytes at PC: ");
3064 + for (i = 0; i < 5; i++) {
3065 + unsigned int c;
3066 + if (get_user(c, (unsigned int __user *)pc+i))
3067 + printk(KERN_CONT "???????? ");
3068 + else
3069 + printk(KERN_CONT "%08x ", c);
3070 + }
3071 + printk("\n");
3072 +}
3073 +#endif
3074 +
3075 /*
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.
3080 */
3081 if (trap == 0x400)
3082 - error_code &= 0x48200000;
3083 + error_code &= 0x58200000;
3084 else
3085 is_write = error_code & DSISR_ISSTORE;
3086 #else
3087 @@ -258,7 +290,7 @@ good_area:
3088 * "undefined". Of those that can be set, this is the only
3089 * one which seems bad.
3090 */
3091 - if (error_code & 0x10000000)
3092 + if (error_code & DSISR_GUARDED)
3093 /* Guarded storage error. */
3094 goto bad_area;
3095 #endif /* CONFIG_8xx */
3096 @@ -273,7 +305,7 @@ good_area:
3097 * processors use the same I/D cache coherency mechanism
3098 * as embedded.
3099 */
3100 - if (error_code & DSISR_PROTFAULT)
3101 + if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
3102 goto bad_area;
3103 #endif /* CONFIG_PPC_STD_MMU */
3104
3105 @@ -342,6 +374,23 @@ bad_area:
3106 bad_area_nosemaphore:
3107 /* User mode accesses cause a SIGSEGV */
3108 if (user_mode(regs)) {
3109 +
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))) {
3114 +#else
3115 + if (is_exec && regs->nip == address) {
3116 +#endif
3117 + switch (pax_handle_fetch_fault(regs)) {
3118 + }
3119 +
3120 + pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
3121 + do_group_exit(SIGKILL);
3122 + }
3123 + }
3124 +#endif
3125 +
3126 _exception(SIGSEGV, regs, code, address);
3127 return 0;
3128 }
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
3133 */
3134 if (mmap_is_legacy()) {
3135 mm->mmap_base = TASK_UNMAPPED_BASE;
3136 +
3137 +#ifdef CONFIG_PAX_RANDMMAP
3138 + if (mm->pax_flags & MF_PAX_RANDMMAP)
3139 + mm->mmap_base += mm->delta_mmap;
3140 +#endif
3141 +
3142 mm->get_unmapped_area = arch_get_unmapped_area;
3143 mm->unmap_area = arch_unmap_area;
3144 } else {
3145 mm->mmap_base = mmap_base();
3146 +
3147 +#ifdef CONFIG_PAX_RANDMMAP
3148 + if (mm->pax_flags & MF_PAX_RANDMMAP)
3149 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
3150 +#endif
3151 +
3152 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
3153 mm->unmap_area = arch_unmap_area_topdown;
3154 }
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)
3160 return 0;
3161 vma = find_vma(mm, addr);
3162 - return (!vma || (addr + len) <= vma->vm_start);
3163 + return check_heap_stack_gap(vma, addr, len);
3164 }
3165
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);
3169 continue;
3170 }
3171 - if (!vma || addr + len <= vma->vm_start) {
3172 + if (check_heap_stack_gap(vma, addr, len)) {
3173 /*
3174 * Remember the place where we stopped the search:
3175 */
3176 @@ -336,7 +336,7 @@ static unsigned long slice_find_area_top
3177 * return with success:
3178 */
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 */
3183 if (use_cache)
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))
3187 return -EINVAL;
3188
3189 +#ifdef CONFIG_PAX_RANDMMAP
3190 + if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
3191 + addr = 0;
3192 +#endif
3193 +
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;
3202 }
3203
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)
3213 iounmap(mbar);
3214 }
3215
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)
3225 return ret;
3226 }
3227
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
3237
3238 static int dma_set_mask_and_switch(struct device *dev, u64 dma_mask);
3239
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);
3250 }
3251
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,
3259 };
3260
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
3270 .name = "power",
3271 };
3272
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
3282 return 1;
3283 }
3284
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,
3289 };
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)
3296
3297 +#ifdef CONFIG_PAX_ASLR
3298 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
3299 +
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 )
3302 +#endif
3303 +
3304 /* This yields a mask that user programs can use to figure out what
3305 instruction set this CPU supports. */
3306
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)
3312 {
3313 might_fault();
3314 +
3315 + if ((long)n < 0)
3316 + return n;
3317 +
3318 if (access_ok(VERIFY_WRITE, to, n))
3319 n = __copy_to_user(to, from, n);
3320 return 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)
3324 {
3325 + if ((long)n < 0)
3326 + return n;
3327 +
3328 if (__builtin_constant_p(n) && (n <= 256))
3329 return uaccess.copy_from_user_small(n, from, to);
3330 else
3331 @@ -293,6 +300,10 @@ copy_from_user(void *to, const void __us
3332 unsigned int sz = __compiletime_object_size(to);
3333
3334 might_fault();
3335 +
3336 + if ((long)n < 0)
3337 + return n;
3338 +
3339 if (unlikely(sz != -1 && sz < n)) {
3340 copy_from_user_overflow();
3341 return n;
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
3346
3347 config S390_EXEC_PROTECT
3348 bool "Data execute protection"
3349 + default y
3350 help
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.
3357 + space programs.
3358 + Enabling this (via kernel parameter) on machines earlier than IBM
3359 + System z9 will reduce system performance.
3360
3361 comment "Code generation options"
3362
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,
3367
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;
3380 return 0;
3381 }
3382
3383 @@ -258,7 +258,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base
3384 if (info->got_initialized == 0) {
3385 Elf_Addr *gotent;
3386
3387 - gotent = me->module_core + me->arch.got_offset +
3388 + gotent = me->module_core_rw + me->arch.got_offset +
3389 info->got_offset;
3390 *gotent = val;
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) {
3404 unsigned int *ip;
3405 - ip = me->module_core + me->arch.plt_offset +
3406 + ip = me->module_core_rx + me->arch.plt_offset +
3407 info->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 +
3417 info->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
3429 break;
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 *
3441 }
3442 early_param("mem", early_parse_mem);
3443
3444 -unsigned int user_mode = HOME_SPACE_MODE;
3445 +unsigned int user_mode = SECONDARY_SPACE_MODE;
3446 EXPORT_SYMBOL_GPL(user_mode);
3447
3448 static int set_amode_and_uaccess(unsigned long user_amode,
3449 @@ -310,17 +310,6 @@ static int set_amode_and_uaccess(unsigne
3450 }
3451 }
3452
3453 -/*
3454 - * Switch kernel/user addressing modes?
3455 - */
3456 -static int __init early_parse_switch_amode(char *p)
3457 -{
3458 - if (user_mode != SECONDARY_SPACE_MODE)
3459 - user_mode = PRIMARY_SPACE_MODE;
3460 - return 0;
3461 -}
3462 -early_param("switch_amode", early_parse_switch_amode);
3463 -
3464 static int __init early_parse_user_mode(char *p)
3465 {
3466 if (p && strcmp(p, "primary") == 0)
3467 @@ -337,20 +326,6 @@ static int __init early_parse_user_mode(
3468 }
3469 early_param("user_mode", early_parse_user_mode);
3470
3471 -#ifdef CONFIG_S390_EXEC_PROTECT
3472 -/*
3473 - * Enable execute protection?
3474 - */
3475 -static int __init early_parse_noexec(char *p)
3476 -{
3477 - if (!strncmp(p, "off", 3))
3478 - return 0;
3479 - user_mode = SECONDARY_SPACE_MODE;
3480 - return 0;
3481 -}
3482 -early_param("noexec", early_parse_noexec);
3483 -#endif /* CONFIG_S390_EXEC_PROTECT */
3484 -
3485 static void setup_addressing_mode(void)
3486 {
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;
3493 }
3494
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)
3497 {
3498 long copied = 0;
3499
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
3504 */
3505 if (mmap_is_legacy()) {
3506 mm->mmap_base = TASK_UNMAPPED_BASE;
3507 +
3508 +#ifdef CONFIG_PAX_RANDMMAP
3509 + if (mm->pax_flags & MF_PAX_RANDMMAP)
3510 + mm->mmap_base += mm->delta_mmap;
3511 +#endif
3512 +
3513 mm->get_unmapped_area = arch_get_unmapped_area;
3514 mm->unmap_area = arch_unmap_area;
3515 } else {
3516 mm->mmap_base = mmap_base();
3517 +
3518 +#ifdef CONFIG_PAX_RANDMMAP
3519 + if (mm->pax_flags & MF_PAX_RANDMMAP)
3520 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
3521 +#endif
3522 +
3523 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
3524 mm->unmap_area = arch_unmap_area_topdown;
3525 }
3526 @@ -153,10 +165,22 @@ void arch_pick_mmap_layout(struct mm_str
3527 */
3528 if (mmap_is_legacy()) {
3529 mm->mmap_base = TASK_UNMAPPED_BASE;
3530 +
3531 +#ifdef CONFIG_PAX_RANDMMAP
3532 + if (mm->pax_flags & MF_PAX_RANDMMAP)
3533 + mm->mmap_base += mm->delta_mmap;
3534 +#endif
3535 +
3536 mm->get_unmapped_area = s390_get_unmapped_area;
3537 mm->unmap_area = arch_unmap_area;
3538 } else {
3539 mm->mmap_base = mmap_base();
3540 +
3541 +#ifdef CONFIG_PAX_RANDMMAP
3542 + if (mm->pax_flags & MF_PAX_RANDMMAP)
3543 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
3544 +#endif
3545 +
3546 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
3547 mm->unmap_area = arch_unmap_area_topdown;
3548 }
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)
3554
3555 typedef void (*vi_handler_t)(void);
3556 -extern unsigned long arch_align_stack(unsigned long sp);
3557 +#define arch_align_stack(x) (x)
3558
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
3565
3566 return task_pt_regs(task)->cp0_epc;
3567 }
3568 -
3569 -unsigned long arch_align_stack(unsigned long sp)
3570 -{
3571 - return sp;
3572 -}
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_
3577 return 0;
3578 }
3579
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,
3584 };
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
3588 @@ -1,10 +1,10 @@
3589 #ifndef __ASM_SH_DMA_MAPPING_H
3590 #define __ASM_SH_DMA_MAPPING_H
3591
3592 -extern struct dma_map_ops *dma_ops;
3593 +extern const struct dma_map_ops *dma_ops;
3594 extern void no_iommu_init(void);
3595
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)
3598 {
3599 return dma_ops;
3600 }
3601 @@ -14,7 +14,7 @@ static inline struct dma_map_ops *get_dm
3602
3603 static inline int dma_supported(struct device *dev, u64 mask)
3604 {
3605 - struct dma_map_ops *ops = get_dma_ops(dev);
3606 + const struct dma_map_ops *ops = get_dma_ops(dev);
3607
3608 if (ops->dma_supported)
3609 return ops->dma_supported(dev, mask);
3610 @@ -24,7 +24,7 @@ static inline int dma_supported(struct d
3611
3612 static inline int dma_set_mask(struct device *dev, u64 mask)
3613 {
3614 - struct dma_map_ops *ops = get_dma_ops(dev);
3615 + const struct dma_map_ops *ops = get_dma_ops(dev);
3616
3617 if (!dev->dma_mask || !dma_supported(dev, mask))
3618 return -EIO;
3619 @@ -44,7 +44,7 @@ void dma_cache_sync(struct device *dev,
3620
3621 static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
3622 {
3623 - struct dma_map_ops *ops = get_dma_ops(dev);
3624 + const struct dma_map_ops *ops = get_dma_ops(dev);
3625
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)
3631 {
3632 - struct dma_map_ops *ops = get_dma_ops(dev);
3633 + const struct dma_map_ops *ops = get_dma_ops(dev);
3634 void *memory;
3635
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)
3640 {
3641 - struct dma_map_ops *ops = get_dma_ops(dev);
3642 + const struct dma_map_ops *ops = get_dma_ops(dev);
3643
3644 if (dma_release_from_coherent(dev, get_order(size), vaddr))
3645 return;
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
3650 return 0;
3651 }
3652
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,
3657 };
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
3662 }
3663 #endif
3664
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);
3675 }
3676
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
3685 @@ -22,7 +22,7 @@
3686
3687 #define PREALLOC_DMA_DEBUG_ENTRIES 4096
3688
3689 -struct dma_map_ops *dma_ops;
3690 +const struct dma_map_ops *dma_ops;
3691 EXPORT_SYMBOL(dma_ops);
3692
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);
3699
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))
3704 return addr;
3705 }
3706
3707 @@ -106,7 +105,7 @@ full_search:
3708 }
3709 return -ENOMEM;
3710 }
3711 - if (likely(!vma || addr + len <= vma->vm_start)) {
3712 + if (likely(check_heap_stack_gap(vma, addr, len))) {
3713 /*
3714 * Remember the place where we stopped the search:
3715 */
3716 @@ -157,8 +156,7 @@ arch_get_unmapped_area_topdown(struct fi
3717 addr = PAGE_ALIGN(addr);
3718
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))
3723 return addr;
3724 }
3725
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);
3734 }
3735 @@ -199,7 +197,7 @@ arch_get_unmapped_area_topdown(struct fi
3736 * return with success:
3737 */
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);
3743 }
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
3747 @@ -14,18 +14,40 @@
3748 #define ATOMIC64_INIT(i) { (i) }
3749
3750 #define atomic_read(v) (*(volatile int *)&(v)->counter)
3751 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
3752 +{
3753 + return v->counter;
3754 +}
3755 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
3756 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
3757 +{
3758 + return v->counter;
3759 +}
3760
3761 #define atomic_set(v, i) (((v)->counter) = i)
3762 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
3763 +{
3764 + v->counter = i;
3765 +}
3766 #define atomic64_set(v, i) (((v)->counter) = i)
3767 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
3768 +{
3769 + v->counter = i;
3770 +}
3771
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 *);
3780
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 *);
3787
3788 @@ -33,12 +55,24 @@ extern long atomic64_sub_ret(long, atomi
3789 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
3790
3791 #define atomic_inc_return(v) atomic_add_ret(1, v)
3792 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
3793 +{
3794 + return atomic_add_ret_unchecked(1, v);
3795 +}
3796 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
3797 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
3798 +{
3799 + return atomic64_add_ret_unchecked(1, v);
3800 +}
3801
3802 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
3803 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
3804
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)
3807 +{
3808 + return atomic_add_ret_unchecked(i, v);
3809 +}
3810 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
3811
3812 /*
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)
3815
3816 #define atomic_inc(v) atomic_add(1, v)
3817 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
3818 +{
3819 + atomic_add_unchecked(1, v);
3820 +}
3821 #define atomic64_inc(v) atomic64_add(1, v)
3822 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
3823 +{
3824 + atomic64_add_unchecked(1, v);
3825 +}
3826
3827 #define atomic_dec(v) atomic_sub(1, v)
3828 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
3829 +{
3830 + atomic_sub_unchecked(1, v);
3831 +}
3832 #define atomic64_dec(v) atomic64_sub(1, v)
3833 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
3834 +{
3835 + atomic64_sub_unchecked(1, v);
3836 +}
3837
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
3841
3842 static inline int atomic_add_unless(atomic_t *v, int a, int u)
3843 {
3844 - int c, old;
3845 + int c, old, new;
3846 c = atomic_read(v);
3847 for (;;) {
3848 - if (unlikely(c == (u)))
3849 + if (unlikely(c == u))
3850 break;
3851 - old = atomic_cmpxchg((v), c, c + (a));
3852 +
3853 + asm volatile("addcc %2, %0, %0\n"
3854 +
3855 +#ifdef CONFIG_PAX_REFCOUNT
3856 + "tvs %%icc, 6\n"
3857 +#endif
3858 +
3859 + : "=r" (new)
3860 + : "0" (c), "ir" (a)
3861 + : "cc");
3862 +
3863 + old = atomic_cmpxchg(v, c, new);
3864 if (likely(old == c))
3865 break;
3866 c = old;
3867 }
3868 - return c != (u);
3869 + return c != u;
3870 }
3871
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
3874
3875 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
3876 {
3877 - long c, old;
3878 + long c, old, new;
3879 c = atomic64_read(v);
3880 for (;;) {
3881 - if (unlikely(c == (u)))
3882 + if (unlikely(c == u))
3883 break;
3884 - old = atomic64_cmpxchg((v), c, c + (a));
3885 +
3886 + asm volatile("addcc %2, %0, %0\n"
3887 +
3888 +#ifdef CONFIG_PAX_REFCOUNT
3889 + "tvs %%xcc, 6\n"
3890 +#endif
3891 +
3892 + : "=r" (new)
3893 + : "0" (c), "ir" (a)
3894 + : "cc");
3895 +
3896 + old = atomic64_cmpxchg(v, c, new);
3897 if (likely(old == c))
3898 break;
3899 c = old;
3900 }
3901 - return c != (u);
3902 + return c != u;
3903 }
3904
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)
3912
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;
3916
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)
3919 {
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)
3925 {
3926 - struct dma_map_ops *ops = get_dma_ops(dev);
3927 + const struct dma_map_ops *ops = get_dma_ops(dev);
3928 void *cpu_addr;
3929
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)
3934 {
3935 - struct dma_map_ops *ops = get_dma_ops(dev);
3936 + const struct dma_map_ops *ops = get_dma_ops(dev);
3937
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 {
3944
3945 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
3946
3947 +#ifdef CONFIG_PAX_ASLR
3948 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
3949 +
3950 +#define PAX_DELTA_MMAP_LEN 16
3951 +#define PAX_DELTA_STACK_LEN 16
3952 +#endif
3953 +
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
3956 on Sparc. */
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
3963
3964 +#ifdef CONFIG_PAX_ASLR
3965 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
3966 +
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)
3969 +#endif
3970
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)
3980 +
3981 +#ifdef CONFIG_PAX_PAGEEXEC
3982 +BTFIXUPDEF_INT(page_shared_noexec)
3983 +BTFIXUPDEF_INT(page_copy_noexec)
3984 +BTFIXUPDEF_INT(page_readonly_noexec)
3985 +#endif
3986 +
3987 BTFIXUPDEF_INT(page_kernel)
3988
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))
3993
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))
3998 +#else
3999 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
4000 +# define PAGE_COPY_NOEXEC PAGE_COPY
4001 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
4002 +#endif
4003 +
4004 extern unsigned long page_kernel;
4005
4006 #ifdef MODULE
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)
4014 +
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)
4019 +#endif
4020 +
4021 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
4022 SRMMU_DIRTY | SRMMU_REF)
4023
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"
4030 " brlz,pn %0, 2f\n"
4031 -"4: add %0, 1, %1\n"
4032 +"4: addcc %0, 1, %1\n"
4033 +
4034 +#ifdef CONFIG_PAX_REFCOUNT
4035 +" tvs %%icc, 6\n"
4036 +#endif
4037 +
4038 " cas [%2], %0, %1\n"
4039 " cmp %0, %1\n"
4040 " bne,pn %%icc, 1b\n"
4041 @@ -112,7 +117,7 @@ static void inline arch_read_lock(arch_r
4042 " .previous"
4043 : "=&r" (tmp1), "=&r" (tmp2)
4044 : "r" (lock)
4045 - : "memory");
4046 + : "memory", "cc");
4047 }
4048
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"
4053 " mov 0, %0\n"
4054 -" add %0, 1, %1\n"
4055 +" addcc %0, 1, %1\n"
4056 +
4057 +#ifdef CONFIG_PAX_REFCOUNT
4058 +" tvs %%icc, 6\n"
4059 +#endif
4060 +
4061 " cas [%2], %0, %1\n"
4062 " cmp %0, %1\n"
4063 " bne,pn %%icc, 1b\n"
4064 @@ -142,7 +152,12 @@ static void inline arch_read_unlock(arch
4065
4066 __asm__ __volatile__(
4067 "1: lduw [%2], %0\n"
4068 -" sub %0, 1, %1\n"
4069 +" subcc %0, 1, %1\n"
4070 +
4071 +#ifdef CONFIG_PAX_REFCOUNT
4072 +" tvs %%icc, 6\n"
4073 +#endif
4074 +
4075 " cas [%2], %0, %1\n"
4076 " cmp %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 __
4082
4083 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
4084 {
4085 - if (n && __access_ok((unsigned long) to, n))
4086 + if ((long)n < 0)
4087 + return n;
4088 +
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);
4093 - else
4094 + } else
4095 return n;
4096 }
4097
4098 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
4099 {
4100 + if ((long)n < 0)
4101 + return n;
4102 +
4103 + if (!__builtin_constant_p(n))
4104 + check_object_size(from, n, true);
4105 +
4106 return __copy_user(to, (__force void __user *) from, n);
4107 }
4108
4109 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
4110 {
4111 - if (n && __access_ok((unsigned long) from, n))
4112 + if ((long)n < 0)
4113 + return n;
4114 +
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);
4119 - else
4120 + } else
4121 return n;
4122 }
4123
4124 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
4125 {
4126 + if ((long)n < 0)
4127 + return n;
4128 +
4129 return __copy_user((__force void __user *) to, from, n);
4130 }
4131
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
4135 @@ -10,6 +10,7 @@
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)
4146 {
4147 - unsigned long ret = ___copy_from_user(to, from, size);
4148 + unsigned long ret;
4149
4150 + if ((long)size < 0 || size > INT_MAX)
4151 + return size;
4152 +
4153 + if (!__builtin_constant_p(size))
4154 + check_object_size(to, size, false);
4155 +
4156 + ret = ___copy_from_user(to, from, size);
4157 if (unlikely(ret))
4158 ret = copy_from_user_fixup(to, from, size);
4159
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)
4163 {
4164 - unsigned long ret = ___copy_to_user(to, from, size);
4165 + unsigned long ret;
4166 +
4167 + if ((long)size < 0 || size > INT_MAX)
4168 + return size;
4169 +
4170 + if (!__builtin_constant_p(size))
4171 + check_object_size(from, size, true);
4172
4173 + ret = ___copy_to_user(to, from, size);
4174 if (unlikely(ret))
4175 ret = copy_to_user_fixup(to, from, size);
4176 return ret;
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
4180 @@ -1,5 +1,13 @@
4181 #ifndef ___ASM_SPARC_UACCESS_H
4182 #define ___ASM_SPARC_UACCESS_H
4183 +
4184 +#ifdef __KERNEL__
4185 +#ifndef __ASSEMBLY__
4186 +#include <linux/types.h>
4187 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
4188 +#endif
4189 +#endif
4190 +
4191 #if defined(__sparc__) && defined(__arch64__)
4192 #include <asm/uaccess_64.h>
4193 #else
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);
4199 }
4200
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,
4208 };
4209
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);
4213
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
4219 BUG();
4220 }
4221
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,
4229 };
4230
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);
4234
4235 static int __init sparc_register_ioport(void)
4236 @@ -645,7 +645,7 @@ static void pci32_sync_sg_for_device(str
4237 }
4238 }
4239
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;
4250 }
4251
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 },
4256 };
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;
4262 }
4263
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 },
4268 };
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
4272 @@ -3,7 +3,7 @@
4273 #
4274
4275 asflags-y := -ansi
4276 -ccflags-y := -Werror
4277 +#ccflags-y := -Werror
4278
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);
4286 }
4287
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],
4298 rw->ins[6],
4299 rw->ins[7]);
4300 - printk("%pS\n", (void *) rw->ins[7]);
4301 + printk("%pA\n", (void *) rw->ins[7]);
4302 rw = (struct reg_window32 *) rw->ins[6];
4303 }
4304 spin_unlock_irqrestore(&sparc_backtrace_lock, flags);
4305 @@ -263,14 +263,14 @@ void show_regs(struct pt_regs *r)
4306
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]);
4319
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;
4324 pc = rw->ins[7];
4325 printk("[%08lx : ", pc);
4326 - printk("%pS ] ", (void *) pc);
4327 + printk("%pA ] ", (void *) pc);
4328 fp = rw->ins[6];
4329 } while (++count < 16);
4330 printk("\n");
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]);
4340 }
4341
4342 void show_regs(struct pt_regs *regs)
4343 {
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],
4350 regs->u_regs[3]);
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],
4354 regs->u_regs[15]);
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]);
4359 }
4360 @@ -285,7 +285,7 @@ void arch_trigger_all_cpu_backtrace(void
4361 ((tp && tp->task) ? tp->task->pid : -1));
4362
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",
4366 (void *) gp->tpc,
4367 (void *) gp->o7,
4368 (void *) gp->i7,
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)
4374 return -ENOMEM;
4375 if (!addr)
4376 - addr = TASK_UNMAPPED_BASE;
4377 + addr = current->mm->mmap_base;
4378
4379 if (flags & MAP_SHARED)
4380 addr = COLOUR_ALIGN(addr);
4381 @@ -71,7 +71,7 @@ unsigned long arch_get_unmapped_area(str
4382 }
4383 if (TASK_SIZE - PAGE_SIZE - len < addr)
4384 return -ENOMEM;
4385 - if (!vmm || addr + len <= vmm->vm_start)
4386 + if (check_heap_stack_gap(vmm, addr, len))
4387 return addr;
4388 addr = vmm->vm_end;
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.
4396 */
4397 - if ((flags & MAP_SHARED) &&
4398 + if ((filp || (flags & MAP_SHARED)) &&
4399 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
4400 return -EINVAL;
4401 return addr;
4402 @@ -139,6 +139,10 @@ unsigned long arch_get_unmapped_area(str
4403 if (filp || (flags & MAP_SHARED))
4404 do_color_align = 1;
4405
4406 +#ifdef CONFIG_PAX_RANDMMAP
4407 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4408 +#endif
4409 +
4410 if (addr) {
4411 if (do_color_align)
4412 addr = COLOUR_ALIGN(addr, pgoff);
4413 @@ -146,15 +150,14 @@ unsigned long arch_get_unmapped_area(str
4414 addr = PAGE_ALIGN(addr);
4415
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))
4420 return addr;
4421 }
4422
4423 if (len > mm->cached_hole_size) {
4424 - start_addr = addr = mm->free_area_cache;
4425 + start_addr = addr = mm->free_area_cache;
4426 } else {
4427 - start_addr = addr = TASK_UNMAPPED_BASE;
4428 + start_addr = addr = mm->mmap_base;
4429 mm->cached_hole_size = 0;
4430 }
4431
4432 @@ -174,14 +177,14 @@ full_search:
4433 vma = find_vma(mm, VA_EXCLUDE_END);
4434 }
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;
4441 goto full_search;
4442 }
4443 return -ENOMEM;
4444 }
4445 - if (likely(!vma || addr + len <= vma->vm_start)) {
4446 + if (likely(check_heap_stack_gap(vma, addr, len))) {
4447 /*
4448 * Remember the place where we stopped the search:
4449 */
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.
4453 */
4454 - if ((flags & MAP_SHARED) &&
4455 + if ((filp || (flags & MAP_SHARED)) &&
4456 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
4457 return -EINVAL;
4458 return addr;
4459 @@ -236,8 +239,7 @@ arch_get_unmapped_area_topdown(struct fi
4460 addr = PAGE_ALIGN(addr);
4461
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))
4466 return addr;
4467 }
4468
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);
4477 }
4478 @@ -278,7 +280,7 @@ arch_get_unmapped_area_topdown(struct fi
4479 * return with success:
4480 */
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);
4486 }
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;
4491 +
4492 +#ifdef CONFIG_PAX_RANDMMAP
4493 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4494 + mm->mmap_base += mm->delta_mmap;
4495 +#endif
4496 +
4497 mm->get_unmapped_area = arch_get_unmapped_area;
4498 mm->unmap_area = arch_unmap_area;
4499 } else {
4500 @@ -397,6 +405,12 @@ void arch_pick_mmap_layout(struct mm_str
4501 gap = (task_size / 6 * 5);
4502
4503 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
4504 +
4505 +#ifdef CONFIG_PAX_RANDMMAP
4506 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4507 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4508 +#endif
4509 +
4510 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4511 mm->unmap_area = arch_unmap_area_topdown;
4512 }
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_
4517 count++ < 30 &&
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];
4524 }
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_
4529 i + 1,
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);
4534 }
4535 }
4536
4537 @@ -95,6 +95,12 @@ void bad_trap(struct pt_regs *regs, long
4538
4539 lvl -= 0x100;
4540 if (regs->tstate & TSTATE_PRIV) {
4541 +
4542 +#ifdef CONFIG_PAX_REFCOUNT
4543 + if (lvl == 6)
4544 + pax_report_refcount_overflow(regs);
4545 +#endif
4546 +
4547 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
4548 die_if_kernel(buffer, regs);
4549 }
4550 @@ -113,11 +119,16 @@ void bad_trap(struct pt_regs *regs, long
4551 void bad_trap_tl1(struct pt_regs *regs, long lvl)
4552 {
4553 char buffer[32];
4554 -
4555 +
4556 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
4557 0, lvl, SIGTRAP) == NOTIFY_STOP)
4558 return;
4559
4560 +#ifdef CONFIG_PAX_REFCOUNT
4561 + if (lvl == 6)
4562 + pax_report_refcount_overflow(regs);
4563 +#endif
4564 +
4565 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
4566
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,
4578 smp_processor_id(),
4579 (type & 0x1) ? 'I' : 'D',
4580 regs->tpc);
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.");
4584 }
4585
4586 @@ -1756,7 +1767,7 @@ void cheetah_plus_parity_error(int type,
4587 smp_processor_id(),
4588 (type & 0x1) ? 'I' : 'D',
4589 regs->tpc);
4590 - printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
4591 + printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
4592 }
4593
4594 struct sun4v_error_entry {
4595 @@ -1963,9 +1974,9 @@ void sun4v_itlb_error_report(struct pt_r
4596
4597 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
4598 regs->tpc, tl);
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
4608
4609 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
4610 regs->tpc, tl);
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;
4621 }
4622
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);
4632 graph++;
4633 }
4634 }
4635 @@ -2255,7 +2266,7 @@ void die_if_kernel(char *str, struct pt_
4636 while (rw &&
4637 count++ < 30 &&
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]);
4642
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);
4649
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);
4654 }
4655 }
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
4659 @@ -18,7 +18,12 @@
4660 atomic_add: /* %o0 = increment, %o1 = atomic_ptr */
4661 BACKOFF_SETUP(%o2)
4662 1: lduw [%o1], %g1
4663 - add %g1, %o0, %g7
4664 + addcc %g1, %o0, %g7
4665 +
4666 +#ifdef CONFIG_PAX_REFCOUNT
4667 + tvs %icc, 6
4668 +#endif
4669 +
4670 cas [%o1], %g1, %g7
4671 cmp %g1, %g7
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
4676
4677 + .globl atomic_add_unchecked
4678 + .type atomic_add_unchecked,#function
4679 +atomic_add_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
4680 + BACKOFF_SETUP(%o2)
4681 +1: lduw [%o1], %g1
4682 + add %g1, %o0, %g7
4683 + cas [%o1], %g1, %g7
4684 + cmp %g1, %g7
4685 + bne,pn %icc, 2f
4686 + nop
4687 + retl
4688 + nop
4689 +2: BACKOFF_SPIN(%o2, %o3, 1b)
4690 + .size atomic_add_unchecked, .-atomic_add_unchecked
4691 +
4692 .globl atomic_sub
4693 .type atomic_sub,#function
4694 atomic_sub: /* %o0 = decrement, %o1 = atomic_ptr */
4695 BACKOFF_SETUP(%o2)
4696 1: lduw [%o1], %g1
4697 - sub %g1, %o0, %g7
4698 + subcc %g1, %o0, %g7
4699 +
4700 +#ifdef CONFIG_PAX_REFCOUNT
4701 + tvs %icc, 6
4702 +#endif
4703 +
4704 cas [%o1], %g1, %g7
4705 cmp %g1, %g7
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
4710
4711 + .globl atomic_sub_unchecked
4712 + .type atomic_sub_unchecked,#function
4713 +atomic_sub_unchecked: /* %o0 = decrement, %o1 = atomic_ptr */
4714 + BACKOFF_SETUP(%o2)
4715 +1: lduw [%o1], %g1
4716 + sub %g1, %o0, %g7
4717 + cas [%o1], %g1, %g7
4718 + cmp %g1, %g7
4719 + bne,pn %icc, 2f
4720 + nop
4721 + retl
4722 + nop
4723 +2: BACKOFF_SPIN(%o2, %o3, 1b)
4724 + .size atomic_sub_unchecked, .-atomic_sub_unchecked
4725 +
4726 .globl atomic_add_ret
4727 .type atomic_add_ret,#function
4728 atomic_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
4729 BACKOFF_SETUP(%o2)
4730 1: lduw [%o1], %g1
4731 - add %g1, %o0, %g7
4732 + addcc %g1, %o0, %g7
4733 +
4734 +#ifdef CONFIG_PAX_REFCOUNT
4735 + tvs %icc, 6
4736 +#endif
4737 +
4738 cas [%o1], %g1, %g7
4739 cmp %g1, %g7
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
4744
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)
4749 +1: lduw [%o1], %g1
4750 + addcc %g1, %o0, %g7
4751 + cas [%o1], %g1, %g7
4752 + cmp %g1, %g7
4753 + bne,pn %icc, 2f
4754 + add %g7, %o0, %g7
4755 + sra %g7, 0, %o0
4756 + retl
4757 + nop
4758 +2: BACKOFF_SPIN(%o2, %o3, 1b)
4759 + .size atomic_add_ret_unchecked, .-atomic_add_ret_unchecked
4760 +
4761 .globl atomic_sub_ret
4762 .type atomic_sub_ret,#function
4763 atomic_sub_ret: /* %o0 = decrement, %o1 = atomic_ptr */
4764 BACKOFF_SETUP(%o2)
4765 1: lduw [%o1], %g1
4766 - sub %g1, %o0, %g7
4767 + subcc %g1, %o0, %g7
4768 +
4769 +#ifdef CONFIG_PAX_REFCOUNT
4770 + tvs %icc, 6
4771 +#endif
4772 +
4773 cas [%o1], %g1, %g7
4774 cmp %g1, %g7
4775 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
4776 @@ -78,7 +144,12 @@ atomic_sub_ret: /* %o0 = decrement, %o1
4777 atomic64_add: /* %o0 = increment, %o1 = atomic_ptr */
4778 BACKOFF_SETUP(%o2)
4779 1: ldx [%o1], %g1
4780 - add %g1, %o0, %g7
4781 + addcc %g1, %o0, %g7
4782 +
4783 +#ifdef CONFIG_PAX_REFCOUNT
4784 + tvs %xcc, 6
4785 +#endif
4786 +
4787 casx [%o1], %g1, %g7
4788 cmp %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
4793
4794 + .globl atomic64_add_unchecked
4795 + .type atomic64_add_unchecked,#function
4796 +atomic64_add_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
4797 + BACKOFF_SETUP(%o2)
4798 +1: ldx [%o1], %g1
4799 + addcc %g1, %o0, %g7
4800 + casx [%o1], %g1, %g7
4801 + cmp %g1, %g7
4802 + bne,pn %xcc, 2f
4803 + nop
4804 + retl
4805 + nop
4806 +2: BACKOFF_SPIN(%o2, %o3, 1b)
4807 + .size atomic64_add_unchecked, .-atomic64_add_unchecked
4808 +
4809 .globl atomic64_sub
4810 .type atomic64_sub,#function
4811 atomic64_sub: /* %o0 = decrement, %o1 = atomic_ptr */
4812 BACKOFF_SETUP(%o2)
4813 1: ldx [%o1], %g1
4814 - sub %g1, %o0, %g7
4815 + subcc %g1, %o0, %g7
4816 +
4817 +#ifdef CONFIG_PAX_REFCOUNT
4818 + tvs %xcc, 6
4819 +#endif
4820 +
4821 casx [%o1], %g1, %g7
4822 cmp %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
4827
4828 + .globl atomic64_sub_unchecked
4829 + .type atomic64_sub_unchecked,#function
4830 +atomic64_sub_unchecked: /* %o0 = decrement, %o1 = atomic_ptr */
4831 + BACKOFF_SETUP(%o2)
4832 +1: ldx [%o1], %g1
4833 + subcc %g1, %o0, %g7
4834 + casx [%o1], %g1, %g7
4835 + cmp %g1, %g7
4836 + bne,pn %xcc, 2f
4837 + nop
4838 + retl
4839 + nop
4840 +2: BACKOFF_SPIN(%o2, %o3, 1b)
4841 + .size atomic64_sub_unchecked, .-atomic64_sub_unchecked
4842 +
4843 .globl atomic64_add_ret
4844 .type atomic64_add_ret,#function
4845 atomic64_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
4846 BACKOFF_SETUP(%o2)
4847 1: ldx [%o1], %g1
4848 - add %g1, %o0, %g7
4849 + addcc %g1, %o0, %g7
4850 +
4851 +#ifdef CONFIG_PAX_REFCOUNT
4852 + tvs %xcc, 6
4853 +#endif
4854 +
4855 casx [%o1], %g1, %g7
4856 cmp %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
4861
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)
4866 +1: ldx [%o1], %g1
4867 + addcc %g1, %o0, %g7
4868 + casx [%o1], %g1, %g7
4869 + cmp %g1, %g7
4870 + bne,pn %xcc, 2f
4871 + add %g7, %o0, %g7
4872 + mov %g7, %o0
4873 + retl
4874 + nop
4875 +2: BACKOFF_SPIN(%o2, %o3, 1b)
4876 + .size atomic64_add_ret_unchecked, .-atomic64_add_ret_unchecked
4877 +
4878 .globl atomic64_sub_ret
4879 .type atomic64_sub_ret,#function
4880 atomic64_sub_ret: /* %o0 = decrement, %o1 = atomic_ptr */
4881 BACKOFF_SETUP(%o2)
4882 1: ldx [%o1], %g1
4883 - sub %g1, %o0, %g7
4884 + subcc %g1, %o0, %g7
4885 +
4886 +#ifdef CONFIG_PAX_REFCOUNT
4887 + tvs %xcc, 6
4888 +#endif
4889 +
4890 casx [%o1], %g1, %g7
4891 cmp %g1, %g7
4892 bne,pn %xcc, 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);
4897
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);
4912
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)
4925
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
4929 @@ -22,6 +22,9 @@
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>
4936
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);
4941 }
4942
4943 +#ifdef CONFIG_PAX_PAGEEXEC
4944 +#ifdef CONFIG_PAX_DLRESOLVE
4945 +static void pax_emuplt_close(struct vm_area_struct *vma)
4946 +{
4947 + vma->vm_mm->call_dl_resolve = 0UL;
4948 +}
4949 +
4950 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
4951 +{
4952 + unsigned int *kaddr;
4953 +
4954 + vmf->page = alloc_page(GFP_HIGHUSER);
4955 + if (!vmf->page)
4956 + return VM_FAULT_OOM;
4957 +
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;
4964 +}
4965 +
4966 +static const struct vm_operations_struct pax_vm_ops = {
4967 + .close = pax_emuplt_close,
4968 + .fault = pax_emuplt_fault
4969 +};
4970 +
4971 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
4972 +{
4973 + int ret;
4974 +
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;
4982 +
4983 + ret = insert_vm_struct(current->mm, vma);
4984 + if (ret)
4985 + return ret;
4986 +
4987 + ++current->mm->total_vm;
4988 + return 0;
4989 +}
4990 +#endif
4991 +
4992 +/*
4993 + * PaX: decide what to do with offenders (regs->pc = fault address)
4994 + *
4995 + * returns 1 when task should be killed
4996 + * 2 when patched PLT trampoline was detected
4997 + * 3 when unpatched PLT trampoline was detected
4998 + */
4999 +static int pax_handle_fetch_fault(struct pt_regs *regs)
5000 +{
5001 +
5002 +#ifdef CONFIG_PAX_EMUPLT
5003 + int err;
5004 +
5005 + do { /* PaX: patched PLT emulation #1 */
5006 + unsigned int sethi1, sethi2, jmpl;
5007 +
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));
5011 +
5012 + if (err)
5013 + break;
5014 +
5015 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
5016 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
5017 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
5018 + {
5019 + unsigned int addr;
5020 +
5021 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
5022 + addr = regs->u_regs[UREG_G1];
5023 + addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
5024 + regs->pc = addr;
5025 + regs->npc = addr+4;
5026 + return 2;
5027 + }
5028 + } while (0);
5029 +
5030 + { /* PaX: patched PLT emulation #2 */
5031 + unsigned int ba;
5032 +
5033 + err = get_user(ba, (unsigned int *)regs->pc);
5034 +
5035 + if (!err && (ba & 0xFFC00000U) == 0x30800000U) {
5036 + unsigned int addr;
5037 +
5038 + addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
5039 + regs->pc = addr;
5040 + regs->npc = addr+4;
5041 + return 2;
5042 + }
5043 + }
5044 +
5045 + do { /* PaX: patched PLT emulation #3 */
5046 + unsigned int sethi, jmpl, nop;
5047 +
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));
5051 +
5052 + if (err)
5053 + break;
5054 +
5055 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
5056 + (jmpl & 0xFFFFE000U) == 0x81C06000U &&
5057 + nop == 0x01000000U)
5058 + {
5059 + unsigned int addr;
5060 +
5061 + addr = (sethi & 0x003FFFFFU) << 10;
5062 + regs->u_regs[UREG_G1] = addr;
5063 + addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
5064 + regs->pc = addr;
5065 + regs->npc = addr+4;
5066 + return 2;
5067 + }
5068 + } while (0);
5069 +
5070 + do { /* PaX: unpatched PLT emulation step 1 */
5071 + unsigned int sethi, ba, nop;
5072 +
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));
5076 +
5077 + if (err)
5078 + break;
5079 +
5080 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
5081 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
5082 + nop == 0x01000000U)
5083 + {
5084 + unsigned int addr, save, call;
5085 +
5086 + if ((ba & 0xFFC00000U) == 0x30800000U)
5087 + addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
5088 + else
5089 + addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
5090 +
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));
5094 + if (err)
5095 + break;
5096 +
5097 +#ifdef CONFIG_PAX_DLRESOLVE
5098 + if (save == 0x9DE3BFA8U &&
5099 + (call & 0xC0000000U) == 0x40000000U &&
5100 + nop == 0x01000000U)
5101 + {
5102 + struct vm_area_struct *vma;
5103 + unsigned long call_dl_resolve;
5104 +
5105 + down_read(&current->mm->mmap_sem);
5106 + call_dl_resolve = current->mm->call_dl_resolve;
5107 + up_read(&current->mm->mmap_sem);
5108 + if (likely(call_dl_resolve))
5109 + goto emulate;
5110 +
5111 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
5112 +
5113 + down_write(&current->mm->mmap_sem);
5114 + if (current->mm->call_dl_resolve) {
5115 + call_dl_resolve = current->mm->call_dl_resolve;
5116 + up_write(&current->mm->mmap_sem);
5117 + if (vma)
5118 + kmem_cache_free(vm_area_cachep, vma);
5119 + goto emulate;
5120 + }
5121 +
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(&current->mm->mmap_sem);
5125 + if (vma)
5126 + kmem_cache_free(vm_area_cachep, vma);
5127 + return 1;
5128 + }
5129 +
5130 + if (pax_insert_vma(vma, call_dl_resolve)) {
5131 + up_write(&current->mm->mmap_sem);
5132 + kmem_cache_free(vm_area_cachep, vma);
5133 + return 1;
5134 + }
5135 +
5136 + current->mm->call_dl_resolve = call_dl_resolve;
5137 + up_write(&current->mm->mmap_sem);
5138 +
5139 +emulate:
5140 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
5141 + regs->pc = call_dl_resolve;
5142 + regs->npc = addr+4;
5143 + return 3;
5144 + }
5145 +#endif
5146 +
5147 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
5148 + if ((save & 0xFFC00000U) == 0x05000000U &&
5149 + (call & 0xFFFFE000U) == 0x85C0A000U &&
5150 + nop == 0x01000000U)
5151 + {
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);
5156 + regs->pc = addr;
5157 + regs->npc = addr+4;
5158 + return 3;
5159 + }
5160 + }
5161 + } while (0);
5162 +
5163 + do { /* PaX: unpatched PLT emulation step 2 */
5164 + unsigned int save, call, nop;
5165 +
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));
5169 + if (err)
5170 + break;
5171 +
5172 + if (save == 0x9DE3BFA8U &&
5173 + (call & 0xC0000000U) == 0x40000000U &&
5174 + nop == 0x01000000U)
5175 + {
5176 + unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
5177 +
5178 + regs->u_regs[UREG_RETPC] = regs->pc;
5179 + regs->pc = dl_resolve;
5180 + regs->npc = dl_resolve+4;
5181 + return 3;
5182 + }
5183 + } while (0);
5184 +#endif
5185 +
5186 + return 1;
5187 +}
5188 +
5189 +void pax_report_insns(void *pc, void *sp)
5190 +{
5191 + unsigned long i;
5192 +
5193 + printk(KERN_ERR "PAX: bytes at PC: ");
5194 + for (i = 0; i < 8; i++) {
5195 + unsigned int c;
5196 + if (get_user(c, (unsigned int *)pc+i))
5197 + printk(KERN_CONT "???????? ");
5198 + else
5199 + printk(KERN_CONT "%08x ", c);
5200 + }
5201 + printk("\n");
5202 +}
5203 +#endif
5204 +
5205 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
5206 int text_fault)
5207 {
5208 @@ -282,6 +547,24 @@ good_area:
5209 if(!(vma->vm_flags & VM_WRITE))
5210 goto bad_area;
5211 } else {
5212 +
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)) {
5217 +
5218 +#ifdef CONFIG_PAX_EMUPLT
5219 + case 2:
5220 + case 3:
5221 + return;
5222 +#endif
5223 +
5224 + }
5225 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
5226 + do_group_exit(SIGKILL);
5227 + }
5228 +#endif
5229 +
5230 /* Allow reads even for write-only mappings */
5231 if(!(vma->vm_flags & (VM_READ | VM_EXEC)))
5232 goto bad_area;
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
5236 @@ -21,6 +21,9 @@
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>
5243
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",
5248 regs->tpc);
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);
5253 dump_stack();
5254 unhandled_fault(regs->tpc, current, regs);
5255 @@ -272,6 +275,457 @@ static void noinline __kprobes bogus_32b
5256 show_regs(regs);
5257 }
5258
5259 +#ifdef CONFIG_PAX_PAGEEXEC
5260 +#ifdef CONFIG_PAX_DLRESOLVE
5261 +static void pax_emuplt_close(struct vm_area_struct *vma)
5262 +{
5263 + vma->vm_mm->call_dl_resolve = 0UL;
5264 +}
5265 +
5266 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
5267 +{
5268 + unsigned int *kaddr;
5269 +
5270 + vmf->page = alloc_page(GFP_HIGHUSER);
5271 + if (!vmf->page)
5272 + return VM_FAULT_OOM;
5273 +
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;
5280 +}
5281 +
5282 +static const struct vm_operations_struct pax_vm_ops = {
5283 + .close = pax_emuplt_close,
5284 + .fault = pax_emuplt_fault
5285 +};
5286 +
5287 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
5288 +{
5289 + int ret;
5290 +
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;
5298 +
5299 + ret = insert_vm_struct(current->mm, vma);
5300 + if (ret)
5301 + return ret;
5302 +
5303 + ++current->mm->total_vm;
5304 + return 0;
5305 +}
5306 +#endif
5307 +
5308 +/*
5309 + * PaX: decide what to do with offenders (regs->tpc = fault address)
5310 + *
5311 + * returns 1 when task should be killed
5312 + * 2 when patched PLT trampoline was detected
5313 + * 3 when unpatched PLT trampoline was detected
5314 + */
5315 +static int pax_handle_fetch_fault(struct pt_regs *regs)
5316 +{
5317 +
5318 +#ifdef CONFIG_PAX_EMUPLT
5319 + int err;
5320 +
5321 + do { /* PaX: patched PLT emulation #1 */
5322 + unsigned int sethi1, sethi2, jmpl;
5323 +
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));
5327 +
5328 + if (err)
5329 + break;
5330 +
5331 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
5332 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
5333 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
5334 + {
5335 + unsigned long addr;
5336 +
5337 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
5338 + addr = regs->u_regs[UREG_G1];
5339 + addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
5340 +
5341 + if (test_thread_flag(TIF_32BIT))
5342 + addr &= 0xFFFFFFFFUL;
5343 +
5344 + regs->tpc = addr;
5345 + regs->tnpc = addr+4;
5346 + return 2;
5347 + }
5348 + } while (0);
5349 +
5350 + { /* PaX: patched PLT emulation #2 */
5351 + unsigned int ba;
5352 +
5353 + err = get_user(ba, (unsigned int *)regs->tpc);
5354 +
5355 + if (!err && (ba & 0xFFC00000U) == 0x30800000U) {
5356 + unsigned long addr;
5357 +
5358 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
5359 +
5360 + if (test_thread_flag(TIF_32BIT))
5361 + addr &= 0xFFFFFFFFUL;
5362 +
5363 + regs->tpc = addr;
5364 + regs->tnpc = addr+4;
5365 + return 2;
5366 + }
5367 + }
5368 +
5369 + do { /* PaX: patched PLT emulation #3 */
5370 + unsigned int sethi, jmpl, nop;
5371 +
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));
5375 +
5376 + if (err)
5377 + break;
5378 +
5379 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
5380 + (jmpl & 0xFFFFE000U) == 0x81C06000U &&
5381 + nop == 0x01000000U)
5382 + {
5383 + unsigned long addr;
5384 +
5385 + addr = (sethi & 0x003FFFFFU) << 10;
5386 + regs->u_regs[UREG_G1] = addr;
5387 + addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
5388 +
5389 + if (test_thread_flag(TIF_32BIT))
5390 + addr &= 0xFFFFFFFFUL;
5391 +
5392 + regs->tpc = addr;
5393 + regs->tnpc = addr+4;
5394 + return 2;
5395 + }
5396 + } while (0);
5397 +
5398 + do { /* PaX: patched PLT emulation #4 */
5399 + unsigned int sethi, mov1, call, mov2;
5400 +
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));
5405 +
5406 + if (err)
5407 + break;
5408 +
5409 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
5410 + mov1 == 0x8210000FU &&
5411 + (call & 0xC0000000U) == 0x40000000U &&
5412 + mov2 == 0x9E100001U)
5413 + {
5414 + unsigned long addr;
5415 +
5416 + regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
5417 + addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
5418 +
5419 + if (test_thread_flag(TIF_32BIT))
5420 + addr &= 0xFFFFFFFFUL;
5421 +
5422 + regs->tpc = addr;
5423 + regs->tnpc = addr+4;
5424 + return 2;
5425 + }
5426 + } while (0);
5427 +
5428 + do { /* PaX: patched PLT emulation #5 */
5429 + unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
5430 +
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));
5439 +
5440 + if (err)
5441 + break;
5442 +
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)
5451 + {
5452 + unsigned long addr;
5453 +
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];
5458 + regs->tpc = addr;
5459 + regs->tnpc = addr+4;
5460 + return 2;
5461 + }
5462 + } while (0);
5463 +
5464 + do { /* PaX: patched PLT emulation #6 */
5465 + unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
5466 +
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));
5474 +
5475 + if (err)
5476 + break;
5477 +
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)
5485 + {
5486 + unsigned long addr;
5487 +
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];
5492 + regs->tpc = addr;
5493 + regs->tnpc = addr+4;
5494 + return 2;
5495 + }
5496 + } while (0);
5497 +
5498 + do { /* PaX: unpatched PLT emulation step 1 */
5499 + unsigned int sethi, ba, nop;
5500 +
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));
5504 +
5505 + if (err)
5506 + break;
5507 +
5508 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
5509 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
5510 + nop == 0x01000000U)
5511 + {
5512 + unsigned long addr;
5513 + unsigned int save, call;
5514 + unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
5515 +
5516 + if ((ba & 0xFFC00000U) == 0x30800000U)
5517 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
5518 + else
5519 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
5520 +
5521 + if (test_thread_flag(TIF_32BIT))
5522 + addr &= 0xFFFFFFFFUL;
5523 +
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));
5527 + if (err)
5528 + break;
5529 +
5530 +#ifdef CONFIG_PAX_DLRESOLVE
5531 + if (save == 0x9DE3BFA8U &&
5532 + (call & 0xC0000000U) == 0x40000000U &&
5533 + nop == 0x01000000U)
5534 + {
5535 + struct vm_area_struct *vma;
5536 + unsigned long call_dl_resolve;
5537 +
5538 + down_read(&current->mm->mmap_sem);
5539 + call_dl_resolve = current->mm->call_dl_resolve;
5540 + up_read(&current->mm->mmap_sem);
5541 + if (likely(call_dl_resolve))
5542 + goto emulate;
5543 +
5544 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
5545 +
5546 + down_write(&current->mm->mmap_sem);
5547 + if (current->mm->call_dl_resolve) {
5548 + call_dl_resolve = current->mm->call_dl_resolve;
5549 + up_write(&current->mm->mmap_sem);
5550 + if (vma)
5551 + kmem_cache_free(vm_area_cachep, vma);
5552 + goto emulate;
5553 + }
5554 +
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(&current->mm->mmap_sem);
5558 + if (vma)
5559 + kmem_cache_free(vm_area_cachep, vma);
5560 + return 1;
5561 + }
5562 +
5563 + if (pax_insert_vma(vma, call_dl_resolve)) {
5564 + up_write(&current->mm->mmap_sem);
5565 + kmem_cache_free(vm_area_cachep, vma);
5566 + return 1;
5567 + }
5568 +
5569 + current->mm->call_dl_resolve = call_dl_resolve;
5570 + up_write(&current->mm->mmap_sem);
5571 +
5572 +emulate:
5573 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
5574 + regs->tpc = call_dl_resolve;
5575 + regs->tnpc = addr+4;
5576 + return 3;
5577 + }
5578 +#endif
5579 +
5580 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
5581 + if ((save & 0xFFC00000U) == 0x05000000U &&
5582 + (call & 0xFFFFE000U) == 0x85C0A000U &&
5583 + nop == 0x01000000U)
5584 + {
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);
5589 +
5590 + if (test_thread_flag(TIF_32BIT))
5591 + addr &= 0xFFFFFFFFUL;
5592 +
5593 + regs->tpc = addr;
5594 + regs->tnpc = addr+4;
5595 + return 3;
5596 + }
5597 +
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));
5607 + if (err)
5608 + break;
5609 +
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)
5618 + {
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];
5626 + regs->tpc = addr;
5627 + regs->tnpc = addr+4;
5628 + return 3;
5629 + }
5630 + }
5631 + } while (0);
5632 +
5633 +#ifdef CONFIG_PAX_DLRESOLVE
5634 + do { /* PaX: unpatched PLT emulation step 2 */
5635 + unsigned int save, call, nop;
5636 +
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));
5640 + if (err)
5641 + break;
5642 +
5643 + if (save == 0x9DE3BFA8U &&
5644 + (call & 0xC0000000U) == 0x40000000U &&
5645 + nop == 0x01000000U)
5646 + {
5647 + unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
5648 +
5649 + if (test_thread_flag(TIF_32BIT))
5650 + dl_resolve &= 0xFFFFFFFFUL;
5651 +
5652 + regs->u_regs[UREG_RETPC] = regs->tpc;
5653 + regs->tpc = dl_resolve;
5654 + regs->tnpc = dl_resolve+4;
5655 + return 3;
5656 + }
5657 + } while (0);
5658 +#endif
5659 +
5660 + do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
5661 + unsigned int sethi, ba, nop;
5662 +
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));
5666 +
5667 + if (err)
5668 + break;
5669 +
5670 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
5671 + (ba & 0xFFF00000U) == 0x30600000U &&
5672 + nop == 0x01000000U)
5673 + {
5674 + unsigned long addr;
5675 +
5676 + addr = (sethi & 0x003FFFFFU) << 10;
5677 + regs->u_regs[UREG_G1] = addr;
5678 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
5679 +
5680 + if (test_thread_flag(TIF_32BIT))
5681 + addr &= 0xFFFFFFFFUL;
5682 +
5683 + regs->tpc = addr;
5684 + regs->tnpc = addr+4;
5685 + return 2;
5686 + }
5687 + } while (0);
5688 +
5689 +#endif
5690 +
5691 + return 1;
5692 +}
5693 +
5694 +void pax_report_insns(void *pc, void *sp)
5695 +{
5696 + unsigned long i;
5697 +
5698 + printk(KERN_ERR "PAX: bytes at PC: ");
5699 + for (i = 0; i < 8; i++) {
5700 + unsigned int c;
5701 + if (get_user(c, (unsigned int *)pc+i))
5702 + printk(KERN_CONT "???????? ");
5703 + else
5704 + printk(KERN_CONT "%08x ", c);
5705 + }
5706 + printk("\n");
5707 +}
5708 +#endif
5709 +
5710 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
5711 {
5712 struct mm_struct *mm = current->mm;
5713 @@ -340,6 +794,29 @@ asmlinkage void __kprobes do_sparc64_fau
5714 if (!vma)
5715 goto bad_area;
5716
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))
5721 + {
5722 + if (address != regs->tpc)
5723 + goto good_area;
5724 +
5725 + up_read(&mm->mmap_sem);
5726 + switch (pax_handle_fetch_fault(regs)) {
5727 +
5728 +#ifdef CONFIG_PAX_EMUPLT
5729 + case 2:
5730 + case 3:
5731 + return;
5732 +#endif
5733 +
5734 + }
5735 + pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
5736 + do_group_exit(SIGKILL);
5737 + }
5738 +#endif
5739 +
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:
5747 }
5748 return -ENOMEM;
5749 }
5750 - if (likely(!vma || addr + len <= vma->vm_start)) {
5751 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5752 /*
5753 * Remember the place where we stopped the search:
5754 */
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);
5763 }
5764 @@ -125,7 +125,7 @@ hugetlb_get_unmapped_area_topdown(struct
5765 * return with success:
5766 */
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);
5772 }
5773 @@ -182,8 +182,7 @@ hugetlb_get_unmapped_area(struct file *f
5774 if (addr) {
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))
5780 return addr;
5781 }
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);
5789
5790 +pgprot_t PAGE_SHARED_NOEXEC __read_mostly;
5791 +EXPORT_SYMBOL(PAGE_SHARED_NOEXEC);
5792 +
5793 void __init paging_init(void)
5794 {
5795 switch(sparc_cpu_model) {
5796 @@ -346,17 +349,17 @@ void __init paging_init(void)
5797
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
5823 @@ -2,7 +2,7 @@
5824 #
5825
5826 asflags-y := -ansi
5827 -ccflags-y := -Werror
5828 +#ccflags-y := -Werror
5829
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));
5839 +
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));
5844 +#endif
5845 +
5846 BTFIXUPSET_INT(page_kernel, pgprot_val(SRMMU_PAGE_KERNEL));
5847 page_kernel = pgprot_val(SRMMU_PAGE_KERNEL);
5848
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 {
5853 KM_IRQ1,
5854 KM_SOFTIRQ0,
5855 KM_SOFTIRQ1,
5856 + KM_CLEARPAGE,
5857 KM_TYPE_NR
5858 };
5859
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
5863 @@ -14,6 +14,9 @@
5864 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
5865 #define PAGE_MASK (~(PAGE_SIZE-1))
5866
5867 +#define ktla_ktva(addr) (addr)
5868 +#define ktva_ktla(addr) (addr)
5869 +
5870 #ifndef __ASSEMBLY__
5871
5872 struct page;
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)
5877 return 2;
5878 }
5879
5880 -/*
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.
5886 - */
5887 -#ifndef arch_align_stack
5888 -unsigned long arch_align_stack(unsigned long sp)
5889 -{
5890 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
5891 - sp -= get_random_int() % 8192;
5892 - return sp & ~0xf;
5893 -}
5894 -#endif
5895 -
5896 unsigned long get_wchan(struct task_struct *p)
5897 {
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
5902 @@ -11,6 +11,21 @@
5903 #include "asm/uaccess.h"
5904 #include "asm/unistd.h"
5905
5906 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
5907 +{
5908 + unsigned long pax_task_size = TASK_SIZE;
5909 +
5910 +#ifdef CONFIG_PAX_SEGMEXEC
5911 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
5912 + pax_task_size = SEGMEXEC_TASK_SIZE;
5913 +#endif
5914 +
5915 + if (len > pax_task_size || addr > pax_task_size - len)
5916 + return -EINVAL;
5917 +
5918 + return 0;
5919 +}
5920 +
5921 /*
5922 * The prototype on i386 is:
5923 *
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
5928 u8 v;
5929 const u32 *p = (const u32 *)addr;
5930
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));
5933 return v;
5934 }
5935
5936 @@ -37,7 +37,7 @@ static inline int variable_test_bit(int
5937
5938 static inline void set_bit(int nr, void *addr)
5939 {
5940 - asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
5941 + asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
5942 }
5943
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)
5950 {
5951 u16 seg;
5952 - asm("movw %%ds,%0" : "=rm" (seg));
5953 + asm volatile("movw %%ds,%0" : "=rm" (seg));
5954 return seg;
5955 }
5956
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)
5959 {
5960 u8 diff;
5961 - asm("repe; cmpsb; setnz %0"
5962 + asm volatile("repe; cmpsb; setnz %0"
5963 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
5964 return diff;
5965 }
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)
5970 notl %eax
5971 andl %eax, %ebx
5972 #else
5973 - movl $LOAD_PHYSICAL_ADDR, %ebx
5974 + movl $____LOAD_PHYSICAL_ADDR, %ebx
5975 #endif
5976
5977 /* Target address to relocate to for decompression */
5978 @@ -162,7 +162,7 @@ relocated:
5979 * and where it was actually loaded.
5980 */
5981 movl %ebp, %ebx
5982 - subl $LOAD_PHYSICAL_ADDR, %ebx
5983 + subl $____LOAD_PHYSICAL_ADDR, %ebx
5984 jz 2f /* Nothing to be done if loaded at compiled addr. */
5985 /*
5986 * Process relocations.
5987 @@ -170,8 +170,7 @@ relocated:
5988
5989 1: subl $4, %edi
5990 movl (%edi), %ecx
5991 - testl %ecx, %ecx
5992 - jz 2f
5993 + jecxz 2f
5994 addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
5995 jmp 1b
5996 2:
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)
6001 notl %eax
6002 andl %eax, %ebx
6003 #else
6004 - movl $LOAD_PHYSICAL_ADDR, %ebx
6005 + movl $____LOAD_PHYSICAL_ADDR, %ebx
6006 #endif
6007
6008 /* Target address to relocate to for decompression */
6009 @@ -233,7 +233,7 @@ ENTRY(startup_64)
6010 notq %rax
6011 andq %rax, %rbp
6012 #else
6013 - movq $LOAD_PHYSICAL_ADDR, %rbp
6014 + movq $____LOAD_PHYSICAL_ADDR, %rbp
6015 #endif
6016
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)
6022 case PT_LOAD:
6023 #ifdef CONFIG_RELOCATABLE
6024 dest = output;
6025 - dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
6026 + dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
6027 #else
6028 dest = (void *)(phdr->p_paddr);
6029 #endif
6030 @@ -359,7 +359,7 @@ asmlinkage void decompress_kernel(void *
6031 error("Destination address too large");
6032 #endif
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");
6037 #endif
6038
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[])
6043
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 */
6049
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
6054 @@ -13,8 +13,11 @@
6055
6056 static void die(char *fmt, ...);
6057
6058 +#include "../../../../include/generated/autoconf.h"
6059 +
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;
6065
6066 @@ -270,9 +273,39 @@ static void read_ehdr(FILE *fp)
6067 }
6068 }
6069
6070 +static void read_phdrs(FILE *fp)
6071 +{
6072 + unsigned int i;
6073 +
6074 + phdr = calloc(ehdr.e_phnum, sizeof(Elf32_Phdr));
6075 + if (!phdr) {
6076 + die("Unable to allocate %d program headers\n",
6077 + ehdr.e_phnum);
6078 + }
6079 + if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
6080 + die("Seek to %d failed: %s\n",
6081 + ehdr.e_phoff, strerror(errno));
6082 + }
6083 + if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
6084 + die("Cannot read ELF program headers: %s\n",
6085 + strerror(errno));
6086 + }
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);
6096 + }
6097 +
6098 +}
6099 +
6100 static void read_shdrs(FILE *fp)
6101 {
6102 - int i;
6103 + unsigned int i;
6104 Elf32_Shdr shdr;
6105
6106 secs = calloc(ehdr.e_shnum, sizeof(struct section));
6107 @@ -307,7 +340,7 @@ static void read_shdrs(FILE *fp)
6108
6109 static void read_strtabs(FILE *fp)
6110 {
6111 - int i;
6112 + unsigned int i;
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)
6117
6118 static void read_symtabs(FILE *fp)
6119 {
6120 - int i,j;
6121 + unsigned int i,j;
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)
6126
6127 static void read_relocs(FILE *fp)
6128 {
6129 - int i,j;
6130 + unsigned int i,j;
6131 + uint32_t base;
6132 +
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",
6138 strerror(errno));
6139 }
6140 + base = 0;
6141 + for (j = 0; j < ehdr.e_phnum; j++) {
6142 + if (phdr[j].p_type != PT_LOAD )
6143 + continue;
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)
6145 + continue;
6146 + base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
6147 + break;
6148 + }
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);
6154 }
6155 }
6156 @@ -396,14 +440,14 @@ static void read_relocs(FILE *fp)
6157
6158 static void print_absolute_symbols(void)
6159 {
6160 - int i;
6161 + unsigned int i;
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];
6166 char *sym_strtab;
6167 Elf32_Sym *sh_symtab;
6168 - int j;
6169 + unsigned int j;
6170
6171 if (sec->shdr.sh_type != SHT_SYMTAB) {
6172 continue;
6173 @@ -431,14 +475,14 @@ static void print_absolute_symbols(void)
6174
6175 static void print_absolute_relocs(void)
6176 {
6177 - int i, printed = 0;
6178 + unsigned int i, printed = 0;
6179
6180 for (i = 0; i < ehdr.e_shnum; i++) {
6181 struct section *sec = &secs[i];
6182 struct section *sec_applies, *sec_symtab;
6183 char *sym_strtab;
6184 Elf32_Sym *sh_symtab;
6185 - int j;
6186 + unsigned int j;
6187 if (sec->shdr.sh_type != SHT_REL) {
6188 continue;
6189 }
6190 @@ -499,13 +543,13 @@ static void print_absolute_relocs(void)
6191
6192 static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym))
6193 {
6194 - int i;
6195 + unsigned int i;
6196 /* Walk through the relocations */
6197 for (i = 0; i < ehdr.e_shnum; i++) {
6198 char *sym_strtab;
6199 Elf32_Sym *sh_symtab;
6200 struct section *sec_applies, *sec_symtab;
6201 - int j;
6202 + unsigned int j;
6203 struct section *sec = &secs[i];
6204
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))) {
6208 continue;
6209 }
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"))
6212 + continue;
6213 +
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"))
6217 + continue;
6218 + if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
6219 + continue;
6220 + if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
6221 + continue;
6222 + if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
6223 + continue;
6224 +#endif
6225 +
6226 switch (r_type) {
6227 case R_386_NONE:
6228 case R_386_PC32:
6229 @@ -571,7 +631,7 @@ static int cmp_relocs(const void *va, co
6230
6231 static void emit_relocs(int as_text)
6232 {
6233 - int i;
6234 + unsigned int i;
6235 /* Count how many relocations I have and allocate space for them. */
6236 reloc_count = 0;
6237 walk_relocs(count_reloc);
6238 @@ -665,6 +725,7 @@ int main(int argc, char **argv)
6239 fname, strerror(errno));
6240 }
6241 read_ehdr(fp);
6242 + read_phdrs(fp);
6243 read_shdrs(fp);
6244 read_strtabs(fp);
6245 read_symtabs(fp);
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;
6251 u32 cr0;
6252
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)
6259 {
6260 u32 f0, f1;
6261
6262 - asm("pushfl ; "
6263 + asm volatile("pushfl ; "
6264 "pushfl ; "
6265 "popl %0 ; "
6266 "movl %0,%1 ; "
6267 @@ -115,7 +115,7 @@ static void get_flags(void)
6268 set_bit(X86_FEATURE_FPU, cpu.flags);
6269
6270 if (has_eflag(X86_EFLAGS_ID)) {
6271 - asm("cpuid"
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)
6277
6278 if (max_intel_level >= 0x00000001 &&
6279 max_intel_level <= 0x0000ffff) {
6280 - asm("cpuid"
6281 + asm volatile("cpuid"
6282 : "=a" (tfms),
6283 "=c" (cpu.flags[4]),
6284 "=d" (cpu.flags[0])
6285 @@ -136,7 +136,7 @@ static void get_flags(void)
6286 cpu.model += ((tfms >> 16) & 0xf) << 4;
6287 }
6288
6289 - asm("cpuid"
6290 + asm volatile("cpuid"
6291 : "=a" (max_amd_level)
6292 : "a" (0x80000000)
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;
6298 - asm("cpuid"
6299 + asm volatile("cpuid"
6300 : "+a" (eax),
6301 "=c" (cpu.flags[6]),
6302 "=d" (cpu.flags[1])
6303 @@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *r
6304 u32 ecx = MSR_K7_HWCR;
6305 u32 eax, edx;
6306
6307 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
6308 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
6309 eax &= ~(1 << 15);
6310 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
6311 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
6312
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;
6317 u32 eax, edx;
6318
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));
6324
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
6328 u32 eax, edx;
6329 u32 level = 1;
6330
6331 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
6332 - asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
6333 - asm("cpuid"
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])
6338 : : "ecx", "ebx");
6339 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
6340 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
6341
6342 err = check_flags();
6343 }
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
6349 # struct setup_data
6350
6351 -pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
6352 +pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
6353
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
6359 @@ -19,7 +19,7 @@
6360
6361 static int detect_memory_e820(void)
6362 {
6363 - int count = 0;
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)
6373 {
6374 char entry_buf[4];
6375 - int i, len = 0;
6376 + unsigned int i, len = 0;
6377 int key;
6378 unsigned int v;
6379
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)
6384
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;
6388 }
6389
6390 /*
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;
6396 struct user32 dump;
6397
6398 + memset(&dump, 0, sizeof(dump));
6399 +
6400 fs = get_fs();
6401 set_fs(KERNEL_DS);
6402 has_dumped = 1;
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
6406 @@ -13,6 +13,7 @@
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>
6412
6413 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
6414 @@ -120,6 +121,11 @@ ENTRY(ia32_sysenter_target)
6415 SWAPGS_UNSAFE_STACK
6416 movq PER_CPU_VAR(kernel_stack), %rsp
6417 addq $(KERNEL_STACK_OFFSET),%rsp
6418 +
6419 +#ifdef CONFIG_PAX_MEMORY_UDEREF
6420 + call pax_enter_kernel_user
6421 +#endif
6422 +
6423 /*
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)
6427 SAVE_ARGS 0,0,1
6428 /* no need to do an access_ok check here because rbp has been
6429 32bit zero extended */
6430 +
6431 +#ifdef CONFIG_PAX_MEMORY_UDEREF
6432 + mov $PAX_USER_SHADOW_BASE,%r10
6433 + add %r10,%rbp
6434 +#endif
6435 +
6436 1: movl (%rbp),%ebp
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)
6441 jnz sysexit_audit
6442 sysexit_from_sys_call:
6443 +
6444 +#ifdef CONFIG_PAX_MEMORY_UDEREF
6445 + call pax_exit_kernel_user
6446 +#endif
6447 +
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)
6452 movl %esp,%r8d
6453 CFI_REGISTER rsp,r8
6454 movq PER_CPU_VAR(kernel_stack),%rsp
6455 +
6456 +#ifdef CONFIG_PAX_MEMORY_UDEREF
6457 + call pax_enter_kernel_user
6458 +#endif
6459 +
6460 /*
6461 * No need to follow this irqs on/off section: the syscall
6462 * disabled irqs and here we enable it straight after entry:
6463 @@ -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 */
6467 +
6468 +#ifdef CONFIG_PAX_MEMORY_UDEREF
6469 + mov $PAX_USER_SHADOW_BASE,%r10
6470 + add %r10,%r8
6471 +#endif
6472 +
6473 1: movl (%r8),%r9d
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)
6478 jnz sysretl_audit
6479 sysretl_from_sys_call:
6480 +
6481 +#ifdef CONFIG_PAX_MEMORY_UDEREF
6482 + call pax_exit_kernel_user
6483 +#endif
6484 +
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
6491 SWAPGS
6492 +
6493 +#ifdef CONFIG_PAX_MEMORY_UDEREF
6494 + call pax_enter_kernel_user
6495 +#endif
6496 +
6497 /*
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
6504 sp -= frame_size;
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;
6510 }
6511
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.
6515 */
6516 - put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
6517 + put_user_ex(*((const u64 *)&code), (u64 *)frame->retcode);
6518 } put_user_catch(err);
6519
6520 if (err)
6521 @@ -503,7 +503,7 @@ int ia32_setup_rt_frame(int sig, struct
6522 0xb8,
6523 __NR_ia32_rt_sigreturn,
6524 0x80cd,
6525 - 0,
6526 + 0
6527 };
6528
6529 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
6530 @@ -533,16 +533,18 @@ int ia32_setup_rt_frame(int sig, struct
6531
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);
6537 else
6538 - restorer = VDSO32_SYMBOL(current->mm->context.vdso,
6539 - rt_sigreturn);
6540 + restorer = &frame->retcode;
6541 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
6542
6543 /*
6544 * Not actually used anymore, but left because some gdb
6545 * versions need it.
6546 */
6547 - put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
6548 + put_user_ex(*((const u64 *)&code), (u64 *)frame->retcode);
6549 } put_user_catch(err);
6550
6551 if (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 */ \
6558 ".previous\n" \
6559 - ".section .altinstr_replacement, \"ax\"\n" \
6560 + ".section .altinstr_replacement, \"a\"\n" \
6561 "663:\n\t" newinstr "\n664:\n" /* replacement */ \
6562 ".previous"
6563
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
6569 "pushl %%edi\n\t"
6570 "pushl %%ebp\n\t"
6571 - "lcall *%%cs:apm_bios_entry\n\t"
6572 + "lcall *%%ss:apm_bios_entry\n\t"
6573 "setc %%al\n\t"
6574 "popl %%ebp\n\t"
6575 "popl %%edi\n\t"
6576 @@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_as
6577 __asm__ __volatile__(APM_DO_ZERO_SEGS
6578 "pushl %%edi\n\t"
6579 "pushl %%ebp\n\t"
6580 - "lcall *%%cs:apm_bios_entry\n\t"
6581 + "lcall *%%ss:apm_bios_entry\n\t"
6582 "setc %%bl\n\t"
6583 "popl %%ebp\n\t"
6584 "popl %%edi\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;
6590 } atomic64_t;
6591
6592 +#ifdef CONFIG_PAX_REFCOUNT
6593 +typedef struct {
6594 + u64 __aligned(8) counter;
6595 +} atomic64_unchecked_t;
6596 +#else
6597 +typedef atomic64_t atomic64_unchecked_t;
6598 +#endif
6599 +
6600 #define ATOMIC64_INIT(val) { (val) }
6601
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
6606 @@ -18,7 +18,19 @@
6607 */
6608 static inline long atomic64_read(const atomic64_t *v)
6609 {
6610 - return (*(volatile long *)&(v)->counter);
6611 + return (*(volatile const long *)&(v)->counter);
6612 +}
6613 +
6614 +/**
6615 + * atomic64_read_unchecked - read atomic64 variable
6616 + * @v: pointer of type atomic64_unchecked_t
6617 + *
6618 + * Atomically reads the value of @v.
6619 + * Doesn't imply a read memory barrier.
6620 + */
6621 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
6622 +{
6623 + return (*(volatile const long *)&(v)->counter);
6624 }
6625
6626 /**
6627 @@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64
6628 }
6629
6630 /**
6631 + * atomic64_set_unchecked - set atomic64 variable
6632 + * @v: pointer to type atomic64_unchecked_t
6633 + * @i: required value
6634 + *
6635 + * Atomically sets the value of @v to @i.
6636 + */
6637 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
6638 +{
6639 + v->counter = i;
6640 +}
6641 +
6642 +/**
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
6647 */
6648 static inline void atomic64_add(long i, atomic64_t *v)
6649 {
6650 + asm volatile(LOCK_PREFIX "addq %1,%0\n"
6651 +
6652 +#ifdef CONFIG_PAX_REFCOUNT
6653 + "jno 0f\n"
6654 + LOCK_PREFIX "subq %1,%0\n"
6655 + "int $4\n0:\n"
6656 + _ASM_EXTABLE(0b, 0b)
6657 +#endif
6658 +
6659 + : "=m" (v->counter)
6660 + : "er" (i), "m" (v->counter));
6661 +}
6662 +
6663 +/**
6664 + * atomic64_add_unchecked - add integer to atomic64 variable
6665 + * @i: integer value to add
6666 + * @v: pointer to type atomic64_unchecked_t
6667 + *
6668 + * Atomically adds @i to @v.
6669 + */
6670 +static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
6671 +{
6672 asm volatile(LOCK_PREFIX "addq %1,%0"
6673 : "=m" (v->counter)
6674 : "er" (i), "m" (v->counter));
6675 @@ -56,7 +102,29 @@ static inline void atomic64_add(long i,
6676 */
6677 static inline void atomic64_sub(long i, atomic64_t *v)
6678 {
6679 - asm volatile(LOCK_PREFIX "subq %1,%0"
6680 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
6681 +
6682 +#ifdef CONFIG_PAX_REFCOUNT
6683 + "jno 0f\n"
6684 + LOCK_PREFIX "addq %1,%0\n"
6685 + "int $4\n0:\n"
6686 + _ASM_EXTABLE(0b, 0b)
6687 +#endif
6688 +
6689 + : "=m" (v->counter)
6690 + : "er" (i), "m" (v->counter));
6691 +}
6692 +
6693 +/**
6694 + * atomic64_sub_unchecked - subtract the atomic64 variable
6695 + * @i: integer value to subtract
6696 + * @v: pointer to type atomic64_unchecked_t
6697 + *
6698 + * Atomically subtracts @i from @v.
6699 + */
6700 +static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
6701 +{
6702 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
6703 : "=m" (v->counter)
6704 : "er" (i), "m" (v->counter));
6705 }
6706 @@ -74,7 +142,16 @@ static inline int atomic64_sub_and_test(
6707 {
6708 unsigned char c;
6709
6710 - asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
6711 + asm volatile(LOCK_PREFIX "subq %2,%0\n"
6712 +
6713 +#ifdef CONFIG_PAX_REFCOUNT
6714 + "jno 0f\n"
6715 + LOCK_PREFIX "addq %2,%0\n"
6716 + "int $4\n0:\n"
6717 + _ASM_EXTABLE(0b, 0b)
6718 +#endif
6719 +
6720 + "sete %1\n"
6721 : "=m" (v->counter), "=qm" (c)
6722 : "er" (i), "m" (v->counter) : "memory");
6723 return c;
6724 @@ -88,6 +165,27 @@ static inline int atomic64_sub_and_test(
6725 */
6726 static inline void atomic64_inc(atomic64_t *v)
6727 {
6728 + asm volatile(LOCK_PREFIX "incq %0\n"
6729 +
6730 +#ifdef CONFIG_PAX_REFCOUNT
6731 + "jno 0f\n"
6732 + LOCK_PREFIX "decq %0\n"
6733 + "int $4\n0:\n"
6734 + _ASM_EXTABLE(0b, 0b)
6735 +#endif
6736 +
6737 + : "=m" (v->counter)
6738 + : "m" (v->counter));
6739 +}
6740 +
6741 +/**
6742 + * atomic64_inc_unchecked - increment atomic64 variable
6743 + * @v: pointer to type atomic64_unchecked_t
6744 + *
6745 + * Atomically increments @v by 1.
6746 + */
6747 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
6748 +{
6749 asm volatile(LOCK_PREFIX "incq %0"
6750 : "=m" (v->counter)
6751 : "m" (v->counter));
6752 @@ -101,7 +199,28 @@ static inline void atomic64_inc(atomic64
6753 */
6754 static inline void atomic64_dec(atomic64_t *v)
6755 {
6756 - asm volatile(LOCK_PREFIX "decq %0"
6757 + asm volatile(LOCK_PREFIX "decq %0\n"
6758 +
6759 +#ifdef CONFIG_PAX_REFCOUNT
6760 + "jno 0f\n"
6761 + LOCK_PREFIX "incq %0\n"
6762 + "int $4\n0:\n"
6763 + _ASM_EXTABLE(0b, 0b)
6764 +#endif
6765 +
6766 + : "=m" (v->counter)
6767 + : "m" (v->counter));
6768 +}
6769 +
6770 +/**
6771 + * atomic64_dec_unchecked - decrement atomic64 variable
6772 + * @v: pointer to type atomic64_t
6773 + *
6774 + * Atomically decrements @v by 1.
6775 + */
6776 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
6777 +{
6778 + asm volatile(LOCK_PREFIX "decq %0\n"
6779 : "=m" (v->counter)
6780 : "m" (v->counter));
6781 }
6782 @@ -118,7 +237,16 @@ static inline int atomic64_dec_and_test(
6783 {
6784 unsigned char c;
6785
6786 - asm volatile(LOCK_PREFIX "decq %0; sete %1"
6787 + asm volatile(LOCK_PREFIX "decq %0\n"
6788 +
6789 +#ifdef CONFIG_PAX_REFCOUNT
6790 + "jno 0f\n"
6791 + LOCK_PREFIX "incq %0\n"
6792 + "int $4\n0:\n"
6793 + _ASM_EXTABLE(0b, 0b)
6794 +#endif
6795 +
6796 + "sete %1\n"
6797 : "=m" (v->counter), "=qm" (c)
6798 : "m" (v->counter) : "memory");
6799 return c != 0;
6800 @@ -136,7 +264,16 @@ static inline int atomic64_inc_and_test(
6801 {
6802 unsigned char c;
6803
6804 - asm volatile(LOCK_PREFIX "incq %0; sete %1"
6805 + asm volatile(LOCK_PREFIX "incq %0\n"
6806 +
6807 +#ifdef CONFIG_PAX_REFCOUNT
6808 + "jno 0f\n"
6809 + LOCK_PREFIX "decq %0\n"
6810 + "int $4\n0:\n"
6811 + _ASM_EXTABLE(0b, 0b)
6812 +#endif
6813 +
6814 + "sete %1\n"
6815 : "=m" (v->counter), "=qm" (c)
6816 : "m" (v->counter) : "memory");
6817 return c != 0;
6818 @@ -155,7 +292,16 @@ static inline int atomic64_add_negative(
6819 {
6820 unsigned char c;
6821
6822 - asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
6823 + asm volatile(LOCK_PREFIX "addq %2,%0\n"
6824 +
6825 +#ifdef CONFIG_PAX_REFCOUNT
6826 + "jno 0f\n"
6827 + LOCK_PREFIX "subq %2,%0\n"
6828 + "int $4\n0:\n"
6829 + _ASM_EXTABLE(0b, 0b)
6830 +#endif
6831 +
6832 + "sets %1\n"
6833 : "=m" (v->counter), "=qm" (c)
6834 : "er" (i), "m" (v->counter) : "memory");
6835 return c;
6836 @@ -171,7 +317,31 @@ static inline int atomic64_add_negative(
6837 static inline long atomic64_add_return(long i, atomic64_t *v)
6838 {
6839 long __i = i;
6840 - asm volatile(LOCK_PREFIX "xaddq %0, %1;"
6841 + asm volatile(LOCK_PREFIX "xaddq %0, %1\n"
6842 +
6843 +#ifdef CONFIG_PAX_REFCOUNT
6844 + "jno 0f\n"
6845 + "movq %0, %1\n"
6846 + "int $4\n0:\n"
6847 + _ASM_EXTABLE(0b, 0b)
6848 +#endif
6849 +
6850 + : "+r" (i), "+m" (v->counter)
6851 + : : "memory");
6852 + return i + __i;
6853 +}
6854 +
6855 +/**
6856 + * atomic64_add_return_unchecked - add and return
6857 + * @i: integer value to add
6858 + * @v: pointer to type atomic64_unchecked_t
6859 + *
6860 + * Atomically adds @i to @v and returns @i + @v
6861 + */
6862 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
6863 +{
6864 + long __i = i;
6865 + asm volatile(LOCK_PREFIX "xaddq %0, %1"
6866 : "+r" (i), "+m" (v->counter)
6867 : : "memory");
6868 return i + __i;
6869 @@ -183,6 +353,10 @@ static inline long atomic64_sub_return(l
6870 }
6871
6872 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
6873 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
6874 +{
6875 + return atomic64_add_return_unchecked(1, v);
6876 +}
6877 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
6878
6879 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
6880 @@ -206,17 +380,30 @@ static inline long atomic64_xchg(atomic6
6881 */
6882 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
6883 {
6884 - long c, old;
6885 + long c, old, new;
6886 c = atomic64_read(v);
6887 for (;;) {
6888 - if (unlikely(c == (u)))
6889 + if (unlikely(c == u))
6890 break;
6891 - old = atomic64_cmpxchg((v), c, c + (a));
6892 +
6893 + asm volatile("add %2,%0\n"
6894 +
6895 +#ifdef CONFIG_PAX_REFCOUNT
6896 + "jno 0f\n"
6897 + "sub %2,%0\n"
6898 + "int $4\n0:\n"
6899 + _ASM_EXTABLE(0b, 0b)
6900 +#endif
6901 +
6902 + : "=r" (new)
6903 + : "0" (c), "ir" (a));
6904 +
6905 + old = atomic64_cmpxchg(v, c, new);
6906 if (likely(old == c))
6907 break;
6908 c = old;
6909 }
6910 - return c != (u);
6911 + return c != u;
6912 }
6913
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
6918 @@ -22,7 +22,18 @@
6919 */
6920 static inline int atomic_read(const atomic_t *v)
6921 {
6922 - return (*(volatile int *)&(v)->counter);
6923 + return (*(volatile const int *)&(v)->counter);
6924 +}
6925 +
6926 +/**
6927 + * atomic_read_unchecked - read atomic variable
6928 + * @v: pointer of type atomic_unchecked_t
6929 + *
6930 + * Atomically reads the value of @v.
6931 + */
6932 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
6933 +{
6934 + return (*(volatile const int *)&(v)->counter);
6935 }
6936
6937 /**
6938 @@ -38,6 +49,18 @@ static inline void atomic_set(atomic_t *
6939 }
6940
6941 /**
6942 + * atomic_set_unchecked - set atomic variable
6943 + * @v: pointer of type atomic_unchecked_t
6944 + * @i: required value
6945 + *
6946 + * Atomically sets the value of @v to @i.
6947 + */
6948 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
6949 +{
6950 + v->counter = i;
6951 +}
6952 +
6953 +/**
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 *
6958 */
6959 static inline void atomic_add(int i, atomic_t *v)
6960 {
6961 - asm volatile(LOCK_PREFIX "addl %1,%0"
6962 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
6963 +
6964 +#ifdef CONFIG_PAX_REFCOUNT
6965 + "jno 0f\n"
6966 + LOCK_PREFIX "subl %1,%0\n"
6967 + "int $4\n0:\n"
6968 + _ASM_EXTABLE(0b, 0b)
6969 +#endif
6970 +
6971 + : "+m" (v->counter)
6972 + : "ir" (i));
6973 +}
6974 +
6975 +/**
6976 + * atomic_add_unchecked - add integer to atomic variable
6977 + * @i: integer value to add
6978 + * @v: pointer of type atomic_unchecked_t
6979 + *
6980 + * Atomically adds @i to @v.
6981 + */
6982 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
6983 +{
6984 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
6985 : "+m" (v->counter)
6986 : "ir" (i));
6987 }
6988 @@ -60,7 +105,29 @@ static inline void atomic_add(int i, ato
6989 */
6990 static inline void atomic_sub(int i, atomic_t *v)
6991 {
6992 - asm volatile(LOCK_PREFIX "subl %1,%0"
6993 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
6994 +
6995 +#ifdef CONFIG_PAX_REFCOUNT
6996 + "jno 0f\n"
6997 + LOCK_PREFIX "addl %1,%0\n"
6998 + "int $4\n0:\n"
6999 + _ASM_EXTABLE(0b, 0b)
7000 +#endif
7001 +
7002 + : "+m" (v->counter)
7003 + : "ir" (i));
7004 +}
7005 +
7006 +/**
7007 + * atomic_sub_unchecked - subtract integer from atomic variable
7008 + * @i: integer value to subtract
7009 + * @v: pointer of type atomic_t
7010 + *
7011 + * Atomically subtracts @i from @v.
7012 + */
7013 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
7014 +{
7015 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
7016 : "+m" (v->counter)
7017 : "ir" (i));
7018 }
7019 @@ -78,7 +145,16 @@ static inline int atomic_sub_and_test(in
7020 {
7021 unsigned char c;
7022
7023 - asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
7024 + asm volatile(LOCK_PREFIX "subl %2,%0\n"
7025 +
7026 +#ifdef CONFIG_PAX_REFCOUNT
7027 + "jno 0f\n"
7028 + LOCK_PREFIX "addl %2,%0\n"
7029 + "int $4\n0:\n"
7030 + _ASM_EXTABLE(0b, 0b)
7031 +#endif
7032 +
7033 + "sete %1\n"
7034 : "+m" (v->counter), "=qm" (c)
7035 : "ir" (i) : "memory");
7036 return c;
7037 @@ -92,7 +168,27 @@ static inline int atomic_sub_and_test(in
7038 */
7039 static inline void atomic_inc(atomic_t *v)
7040 {
7041 - asm volatile(LOCK_PREFIX "incl %0"
7042 + asm volatile(LOCK_PREFIX "incl %0\n"
7043 +
7044 +#ifdef CONFIG_PAX_REFCOUNT
7045 + "jno 0f\n"
7046 + LOCK_PREFIX "decl %0\n"
7047 + "int $4\n0:\n"
7048 + _ASM_EXTABLE(0b, 0b)
7049 +#endif
7050 +
7051 + : "+m" (v->counter));
7052 +}
7053 +
7054 +/**
7055 + * atomic_inc_unchecked - increment atomic variable
7056 + * @v: pointer of type atomic_unchecked_t
7057 + *
7058 + * Atomically increments @v by 1.
7059 + */
7060 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
7061 +{
7062 + asm volatile(LOCK_PREFIX "incl %0\n"
7063 : "+m" (v->counter));
7064 }
7065
7066 @@ -104,7 +200,27 @@ static inline void atomic_inc(atomic_t *
7067 */
7068 static inline void atomic_dec(atomic_t *v)
7069 {
7070 - asm volatile(LOCK_PREFIX "decl %0"
7071 + asm volatile(LOCK_PREFIX "decl %0\n"
7072 +
7073 +#ifdef CONFIG_PAX_REFCOUNT
7074 + "jno 0f\n"
7075 + LOCK_PREFIX "incl %0\n"
7076 + "int $4\n0:\n"
7077 + _ASM_EXTABLE(0b, 0b)
7078 +#endif
7079 +
7080 + : "+m" (v->counter));
7081 +}
7082 +
7083 +/**
7084 + * atomic_dec_unchecked - decrement atomic variable
7085 + * @v: pointer of type atomic_t
7086 + *
7087 + * Atomically decrements @v by 1.
7088 + */
7089 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
7090 +{
7091 + asm volatile(LOCK_PREFIX "decl %0\n"
7092 : "+m" (v->counter));
7093 }
7094
7095 @@ -120,7 +236,16 @@ static inline int atomic_dec_and_test(at
7096 {
7097 unsigned char c;
7098
7099 - asm volatile(LOCK_PREFIX "decl %0; sete %1"
7100 + asm volatile(LOCK_PREFIX "decl %0\n"
7101 +
7102 +#ifdef CONFIG_PAX_REFCOUNT
7103 + "jno 0f\n"
7104 + LOCK_PREFIX "incl %0\n"
7105 + "int $4\n0:\n"
7106 + _ASM_EXTABLE(0b, 0b)
7107 +#endif
7108 +
7109 + "sete %1\n"
7110 : "+m" (v->counter), "=qm" (c)
7111 : : "memory");
7112 return c != 0;
7113 @@ -138,7 +263,16 @@ static inline int atomic_inc_and_test(at
7114 {
7115 unsigned char c;
7116
7117 - asm volatile(LOCK_PREFIX "incl %0; sete %1"
7118 + asm volatile(LOCK_PREFIX "incl %0\n"
7119 +
7120 +#ifdef CONFIG_PAX_REFCOUNT
7121 + "jno 0f\n"
7122 + LOCK_PREFIX "decl %0\n"
7123 + "int $4\n0:\n"
7124 + _ASM_EXTABLE(0b, 0b)
7125 +#endif
7126 +
7127 + "sete %1\n"
7128 : "+m" (v->counter), "=qm" (c)
7129 : : "memory");
7130 return c != 0;
7131 @@ -157,7 +291,16 @@ static inline int atomic_add_negative(in
7132 {
7133 unsigned char c;
7134
7135 - asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
7136 + asm volatile(LOCK_PREFIX "addl %2,%0\n"
7137 +
7138 +#ifdef CONFIG_PAX_REFCOUNT
7139 + "jno 0f\n"
7140 + LOCK_PREFIX "subl %2,%0\n"
7141 + "int $4\n0:\n"
7142 + _ASM_EXTABLE(0b, 0b)
7143 +#endif
7144 +
7145 + "sets %1\n"
7146 : "+m" (v->counter), "=qm" (c)
7147 : "ir" (i) : "memory");
7148 return c;
7149 @@ -180,6 +323,46 @@ static inline int atomic_add_return(int
7150 #endif
7151 /* Modern 486+ processor */
7152 __i = i;
7153 + asm volatile(LOCK_PREFIX "xaddl %0, %1\n"
7154 +
7155 +#ifdef CONFIG_PAX_REFCOUNT
7156 + "jno 0f\n"
7157 + "movl %0, %1\n"
7158 + "int $4\n0:\n"
7159 + _ASM_EXTABLE(0b, 0b)
7160 +#endif
7161 +
7162 + : "+r" (i), "+m" (v->counter)
7163 + : : "memory");
7164 + return i + __i;
7165 +
7166 +#ifdef CONFIG_M386
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);
7172 + return i + __i;
7173 +#endif
7174 +}
7175 +
7176 +/**
7177 + * atomic_add_return_unchecked - add integer and return
7178 + * @v: pointer of type atomic_unchecked_t
7179 + * @i: integer value to add
7180 + *
7181 + * Atomically adds @i to @v and returns @i + @v
7182 + */
7183 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
7184 +{
7185 + int __i;
7186 +#ifdef CONFIG_M386
7187 + unsigned long flags;
7188 + if (unlikely(boot_cpu_data.x86 <= 3))
7189 + goto no_xadd;
7190 +#endif
7191 + /* Modern 486+ processor */
7192 + __i = i;
7193 asm volatile(LOCK_PREFIX "xaddl %0, %1"
7194 : "+r" (i), "+m" (v->counter)
7195 : : "memory");
7196 @@ -208,6 +391,10 @@ static inline int atomic_sub_return(int
7197 }
7198
7199 #define atomic_inc_return(v) (atomic_add_return(1, v))
7200 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
7201 +{
7202 + return atomic_add_return_unchecked(1, v);
7203 +}
7204 #define atomic_dec_return(v) (atomic_sub_return(1, v))
7205
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 *
7208 */
7209 static inline int atomic_add_unless(atomic_t *v, int a, int u)
7210 {
7211 - int c, old;
7212 + int c, old, new;
7213 c = atomic_read(v);
7214 for (;;) {
7215 - if (unlikely(c == (u)))
7216 + if (unlikely(c == u))
7217 break;
7218 - old = atomic_cmpxchg((v), c, c + (a));
7219 +
7220 + asm volatile("addl %2,%0\n"
7221 +
7222 +#ifdef CONFIG_PAX_REFCOUNT
7223 + "jno 0f\n"
7224 + "subl %2,%0\n"
7225 + "int $4\n0:\n"
7226 + _ASM_EXTABLE(0b, 0b)
7227 +#endif
7228 +
7229 + : "=r" (new)
7230 + : "0" (c), "ir" (a));
7231 +
7232 + old = atomic_cmpxchg(v, c, new);
7233 if (likely(old == c))
7234 break;
7235 c = old;
7236 }
7237 - return c != (u);
7238 + return c != u;
7239 }
7240
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
7245 @@ -38,7 +38,7 @@
7246 * a mask operation on a byte.
7247 */
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))
7252
7253 /**
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
7257 @@ -11,10 +11,15 @@
7258 #include <asm/pgtable_types.h>
7259
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))
7265
7266 +#ifndef __ASSEMBLY__
7267 +extern unsigned char __LOAD_PHYSICAL_ADDR[];
7268 +#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
7269 +#endif
7270 +
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;
7279
7280 if (pg_flags == _PGMT_DEFAULT)
7281 - return -1;
7282 + return ~0UL;
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
7289 @@ -8,6 +8,7 @@
7290 #define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7291
7292 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
7293 +#define __read_only __attribute__((__section__(".data..read_only")))
7294
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);
7303
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);
7307 +
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);
7311 +
7312 /*
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
7316 int *err_ptr)
7317 {
7318 might_sleep();
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);
7322 }
7323
7324 @@ -178,7 +186,7 @@ static inline __wsum csum_and_copy_to_us
7325 {
7326 might_sleep();
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);
7331
7332 if (len)
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 */
7339 ".previous\n"
7340 - ".section .altinstr_replacement,\"ax\"\n"
7341 + ".section .altinstr_replacement,\"a\"\n"
7342 "3: movb $1,%0\n"
7343 "4:\n"
7344 ".previous\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
7348 @@ -4,6 +4,7 @@
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>
7354
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;
7361 desc->s = 1;
7362 desc->dpl = 0x3;
7363 desc->p = info->seg_not_present ^ 1;
7364 @@ -31,16 +33,12 @@ static inline void fill_ldt(struct desc_
7365 }
7366
7367 extern struct desc_ptr idt_descr;
7368 -extern gate_desc idt_table[];
7369 -
7370 -struct gdt_page {
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];
7375
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)
7378 {
7379 - return per_cpu(gdt_page, cpu).gdt;
7380 + return cpu_gdt_table[cpu];
7381 }
7382
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)
7387 {
7388 + pax_open_kernel();
7389 memcpy(&idt[entry], gate, sizeof(*gate));
7390 + pax_close_kernel();
7391 }
7392
7393 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry,
7394 const void *desc)
7395 {
7396 + pax_open_kernel();
7397 memcpy(&ldt[entry], desc, 8);
7398 + pax_close_kernel();
7399 }
7400
7401 static inline void native_write_gdt_entry(struct desc_struct *gdt, int entry,
7402 const void *desc, int type)
7403 {
7404 unsigned int size;
7405 +
7406 switch (type) {
7407 case DESC_TSS:
7408 size = sizeof(tss_desc);
7409 @@ -139,7 +142,10 @@ static inline void native_write_gdt_entr
7410 size = sizeof(struct desc_struct);
7411 break;
7412 }
7413 +
7414 + pax_open_kernel();
7415 memcpy(&gdt[entry], desc, size);
7416 + pax_close_kernel();
7417 }
7418
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
7421
7422 static inline void native_load_tr_desc(void)
7423 {
7424 + pax_open_kernel();
7425 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
7426 + pax_close_kernel();
7427 }
7428
7429 static inline void native_load_gdt(const struct desc_ptr *dtr)
7430 @@ -246,8 +254,10 @@ static inline void native_load_tls(struc
7431 unsigned int i;
7432 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
7433
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();
7438 }
7439
7440 #define _LDT_empty(info) \
7441 @@ -309,7 +319,7 @@ static inline void set_desc_limit(struct
7442 desc->limit = (limit >> 16) & 0xf;
7443 }
7444
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)
7448 {
7449 gate_desc s;
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.
7453 */
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)
7456 {
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
7460 /*
7461 * This routine sets up an interrupt gate at directory privilege level 3.
7462 */
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)
7465 {
7466 BUG_ON((unsigned)n > 0xFF);
7467 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
7468 }
7469
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)
7472 {
7473 BUG_ON((unsigned)n > 0xFF);
7474 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
7475 }
7476
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)
7479 {
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)
7484 {
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));
7488 }
7489
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)
7492 {
7493 BUG_ON((unsigned)n > 0xFF);
7494 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
7495 }
7496
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)
7499 {
7500 BUG_ON((unsigned)n > 0xFF);
7501 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
7502 }
7503
7504 +#ifdef CONFIG_X86_32
7505 +static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
7506 +{
7507 + struct desc_struct d;
7508 +
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);
7513 +}
7514 +#endif
7515 +
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 {
7521 void *acpi_handle;
7522 #endif
7523 #ifdef CONFIG_X86_64
7524 -struct dma_map_ops *dma_ops;
7525 + const struct dma_map_ops *dma_ops;
7526 #endif
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;
7535
7536 -extern struct dma_map_ops *dma_ops;
7537 +extern const struct dma_map_ops *dma_ops;
7538
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)
7541 {
7542 #ifdef CONFIG_X86_32
7543 return dma_ops;
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)
7547 {
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);
7552
7553 @@ -115,7 +115,7 @@ static inline void *
7554 dma_alloc_coherent(struct device *dev, size_t size, dma_addr_t *dma_handle,
7555 gfp_t gfp)
7556 {
7557 - struct dma_map_ops *ops = get_dma_ops(dev);
7558 + const struct dma_map_ops *ops = get_dma_ops(dev);
7559 void *memory;
7560
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)
7565 {
7566 - struct dma_map_ops *ops = get_dma_ops(dev);
7567 + const struct dma_map_ops *ops = get_dma_ops(dev);
7568
7569 WARN_ON(irqs_disabled()); /* for portability */
7570
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
7577
7578 -#define BIOS_BEGIN 0x000a0000
7579 +#define BIOS_BEGIN 0x000c0000
7580 #define BIOS_END 0x00100000
7581
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. */
7589
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)
7592 +#else
7593 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
7594 +#endif
7595 +
7596 +#ifdef CONFIG_PAX_ASLR
7597 +#ifdef CONFIG_X86_32
7598 +#define PAX_ELF_ET_DYN_BASE 0x10000000UL
7599 +
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)
7602 +#else
7603 +#define PAX_ELF_ET_DYN_BASE 0x400000UL
7604 +
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)
7607 +#endif
7608 +#endif
7609
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 \
7614 do { \
7615 if (vdso_enabled) \
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);\
7619 } while (0)
7620
7621 #define AT_SYSINFO 32
7622 @@ -303,7 +320,7 @@ do { \
7623
7624 #endif /* !CONFIG_X86_32 */
7625
7626 -#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
7627 +#define VDSO_CURRENT_BASE (current->mm->context.vdso)
7628
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
7634
7635 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
7636 -#define arch_randomize_brk arch_randomize_brk
7637 -
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
7642 @@ -12,16 +12,18 @@
7643 #include <asm/system.h>
7644
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" \
7650 "\tjmp\t2b\n" \
7651 "\t.previous\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))
7656
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" \
7661 "\t" insn "\n" \
7662 @@ -34,10 +36,10 @@
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))
7669
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)
7672 {
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
7676
7677 switch (op) {
7678 case FUTEX_OP_SET:
7679 - __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
7680 + __futex_atomic_op1("xchgl %0, "__copyuser_seg"%2", ret, oldval, uaddr, oparg);
7681 break;
7682 case FUTEX_OP_ADD:
7683 - __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
7684 + __futex_atomic_op1(LOCK_PREFIX "xaddl %0, "__copyuser_seg"%2", ret, oldval,
7685 uaddr, oparg);
7686 break;
7687 case FUTEX_OP_OR:
7688 @@ -109,7 +111,7 @@ static inline int futex_atomic_op_inuser
7689 return ret;
7690 }
7691
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,
7694 int newval)
7695 {
7696
7697 @@ -119,16 +121,16 @@ static inline int futex_atomic_cmpxchg_i
7698 return -ENOSYS;
7699 #endif
7700
7701 - if (!access_ok(VERIFY_WRITE, uaddr, sizeof(int)))
7702 + if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
7703 return -EFAULT;
7704
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"
7708 "3:\tmov %2, %0\n"
7709 "\tjmp 2b\n"
7710 "\t.previous\n"
7711 _ASM_EXTABLE(1b, 3b)
7712 - : "=a" (oldval), "+m" (*uaddr)
7713 + : "=a" (oldval), "+m" (*____m(uaddr))
7714 : "i" (-EFAULT), "r" (newval), "0" (oldval)
7715 : "memory"
7716 );
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
7721 {
7722 int err;
7723
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);
7727 +#endif
7728 +
7729 /* See comment in fxsave() below. */
7730 asm volatile("1: rex64/fxrstor (%[fx])\n\t"
7731 "2:\n"
7732 @@ -109,6 +114,11 @@ static inline int fxsave_user(struct i38
7733 {
7734 int err;
7735
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);
7739 +#endif
7740 +
7741 /*
7742 * Clear the bytes not touched by the fxsave and reserved
7743 * for the SW usage.
7744 @@ -189,13 +199,8 @@ static inline void fpu_fxsave(struct fpu
7745 #endif /* CONFIG_X86_64 */
7746
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 */
7750 -#ifdef CONFIG_SMP
7751 -#define safe_address (__per_cpu_offset[0])
7752 -#else
7753 -#define safe_address (kstat_cpu(0).cpustat.user)
7754 -#endif
7755 + in L1 during context switch. */
7756 +#define safe_address (init_tss[smp_processor_id()].x86_tss.sp0)
7757
7758 /*
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);
7764
7765 #include <linux/vmalloc.h>
7766
7767 +#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
7768 +static inline int valid_phys_addr_range(unsigned long addr, size_t count)
7769 +{
7770 + return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1 << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
7771 +}
7772 +
7773 +static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
7774 +{
7775 + return (pfn + (count >> PAGE_SHIFT)) < (1 << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
7776 +}
7777 +
7778 /*
7779 * Convert a virtual cached pointer to an uncached pointer
7780 */
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
7784 @@ -1,7 +1,7 @@
7785 #ifndef _ASM_X86_IOMMU_H
7786 #define _ASM_X86_IOMMU_H
7787
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
7797 sti; \
7798 sysexit
7799
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
7804 +
7805 #else
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;
7813 };
7814
7815 -extern struct kvm_x86_ops *kvm_x86_ops;
7816 +extern const struct kvm_x86_ops *kvm_x86_ops;
7817
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 {
7824
7825 static inline void local_inc(local_t *l)
7826 {
7827 - asm volatile(_ASM_INC "%0"
7828 + asm volatile(_ASM_INC "%0\n"
7829 +
7830 +#ifdef CONFIG_PAX_REFCOUNT
7831 + "jno 0f\n"
7832 + _ASM_DEC "%0\n"
7833 + "int $4\n0:\n"
7834 + _ASM_EXTABLE(0b, 0b)
7835 +#endif
7836 +
7837 : "+m" (l->a.counter));
7838 }
7839
7840 static inline void local_dec(local_t *l)
7841 {
7842 - asm volatile(_ASM_DEC "%0"
7843 + asm volatile(_ASM_DEC "%0\n"
7844 +
7845 +#ifdef CONFIG_PAX_REFCOUNT
7846 + "jno 0f\n"
7847 + _ASM_INC "%0\n"
7848 + "int $4\n0:\n"
7849 + _ASM_EXTABLE(0b, 0b)
7850 +#endif
7851 +
7852 : "+m" (l->a.counter));
7853 }
7854
7855 static inline void local_add(long i, local_t *l)
7856 {
7857 - asm volatile(_ASM_ADD "%1,%0"
7858 + asm volatile(_ASM_ADD "%1,%0\n"
7859 +
7860 +#ifdef CONFIG_PAX_REFCOUNT
7861 + "jno 0f\n"
7862 + _ASM_SUB "%1,%0\n"
7863 + "int $4\n0:\n"
7864 + _ASM_EXTABLE(0b, 0b)
7865 +#endif
7866 +
7867 : "+m" (l->a.counter)
7868 : "ir" (i));
7869 }
7870
7871 static inline void local_sub(long i, local_t *l)
7872 {
7873 - asm volatile(_ASM_SUB "%1,%0"
7874 + asm volatile(_ASM_SUB "%1,%0\n"
7875 +
7876 +#ifdef CONFIG_PAX_REFCOUNT
7877 + "jno 0f\n"
7878 + _ASM_ADD "%1,%0\n"
7879 + "int $4\n0:\n"
7880 + _ASM_EXTABLE(0b, 0b)
7881 +#endif
7882 +
7883 : "+m" (l->a.counter)
7884 : "ir" (i));
7885 }
7886 @@ -55,7 +87,16 @@ static inline int local_sub_and_test(lon
7887 {
7888 unsigned char c;
7889
7890 - asm volatile(_ASM_SUB "%2,%0; sete %1"
7891 + asm volatile(_ASM_SUB "%2,%0\n"
7892 +
7893 +#ifdef CONFIG_PAX_REFCOUNT
7894 + "jno 0f\n"
7895 + _ASM_ADD "%2,%0\n"
7896 + "int $4\n0:\n"
7897 + _ASM_EXTABLE(0b, 0b)
7898 +#endif
7899 +
7900 + "sete %1\n"
7901 : "+m" (l->a.counter), "=qm" (c)
7902 : "ir" (i) : "memory");
7903 return c;
7904 @@ -73,7 +114,16 @@ static inline int local_dec_and_test(loc
7905 {
7906 unsigned char c;
7907
7908 - asm volatile(_ASM_DEC "%0; sete %1"
7909 + asm volatile(_ASM_DEC "%0\n"
7910 +
7911 +#ifdef CONFIG_PAX_REFCOUNT
7912 + "jno 0f\n"
7913 + _ASM_INC "%0\n"
7914 + "int $4\n0:\n"
7915 + _ASM_EXTABLE(0b, 0b)
7916 +#endif
7917 +
7918 + "sete %1\n"
7919 : "+m" (l->a.counter), "=qm" (c)
7920 : : "memory");
7921 return c != 0;
7922 @@ -91,7 +141,16 @@ static inline int local_inc_and_test(loc
7923 {
7924 unsigned char c;
7925
7926 - asm volatile(_ASM_INC "%0; sete %1"
7927 + asm volatile(_ASM_INC "%0\n"
7928 +
7929 +#ifdef CONFIG_PAX_REFCOUNT
7930 + "jno 0f\n"
7931 + _ASM_DEC "%0\n"
7932 + "int $4\n0:\n"
7933 + _ASM_EXTABLE(0b, 0b)
7934 +#endif
7935 +
7936 + "sete %1\n"
7937 : "+m" (l->a.counter), "=qm" (c)
7938 : : "memory");
7939 return c != 0;
7940 @@ -110,7 +169,16 @@ static inline int local_add_negative(lon
7941 {
7942 unsigned char c;
7943
7944 - asm volatile(_ASM_ADD "%2,%0; sets %1"
7945 + asm volatile(_ASM_ADD "%2,%0\n"
7946 +
7947 +#ifdef CONFIG_PAX_REFCOUNT
7948 + "jno 0f\n"
7949 + _ASM_SUB "%2,%0\n"
7950 + "int $4\n0:\n"
7951 + _ASM_EXTABLE(0b, 0b)
7952 +#endif
7953 +
7954 + "sets %1\n"
7955 : "+m" (l->a.counter), "=qm" (c)
7956 : "ir" (i) : "memory");
7957 return c;
7958 @@ -133,7 +201,15 @@ static inline long local_add_return(long
7959 #endif
7960 /* Modern 486+ processor */
7961 __i = i;
7962 - asm volatile(_ASM_XADD "%0, %1;"
7963 + asm volatile(_ASM_XADD "%0, %1\n"
7964 +
7965 +#ifdef CONFIG_PAX_REFCOUNT
7966 + "jno 0f\n"
7967 + _ASM_MOV "%0,%1\n"
7968 + "int $4\n0:\n"
7969 + _ASM_EXTABLE(0b, 0b)
7970 +#endif
7971 +
7972 : "+r" (i), "+m" (l->a.counter)
7973 : : "memory");
7974 return i + __i;
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
7979 #else
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
7988 #endif
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 };
7994
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);
7999
8000 - enum ucode_state (*request_microcode_fw) (int cpu,
8001 + enum ucode_state (* const request_microcode_fw) (int cpu,
8002 struct device *device);
8003
8004 - void (*microcode_fini_cpu) (int cpu);
8005 + void (* const microcode_fini_cpu) (int cpu);
8006
8007 /*
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[];
8011
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);
8015 #else
8016 -static inline struct microcode_ops * __init init_intel_microcode(void)
8017 +static inline const struct microcode_ops * __init init_intel_microcode(void)
8018 {
8019 return NULL;
8020 }
8021 #endif /* CONFIG_MICROCODE_INTEL */
8022
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);
8026 #else
8027 -static inline struct microcode_ops * __init init_amd_microcode(void)
8028 +static inline const struct microcode_ops * __init init_amd_microcode(void)
8029 {
8030 return NULL;
8031 }
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
8035 @@ -5,4 +5,14 @@
8036
8037 #include <asm-generic/mman.h>
8038
8039 +#ifdef __KERNEL__
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);
8045 +#endif
8046 +#endif
8047 +#endif
8048 +
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
8054
8055 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
8056 {
8057 +
8058 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
8059 + unsigned int i;
8060 + pgd_t *pgd;
8061 +
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));
8067 + else
8068 + pgd[i] = native_make_pgd(0);
8069 + pax_close_kernel();
8070 +#endif
8071 +
8072 #ifdef CONFIG_SMP
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)
8077 {
8078 unsigned cpu = smp_processor_id();
8079 +#if defined(CONFIG_X86_32) && defined(CONFIG_SMP)
8080 + int tlbstate = TLBSTATE_OK;
8081 +#endif
8082
8083 if (likely(prev != next)) {
8084 /* stop flush ipis for the previous mm */
8085 cpumask_clear_cpu(cpu, mm_cpumask(prev));
8086 #ifdef CONFIG_SMP
8087 +#ifdef CONFIG_X86_32
8088 + tlbstate = percpu_read(cpu_tlbstate.state);
8089 +#endif
8090 percpu_write(cpu_tlbstate.state, TLBSTATE_OK);
8091 percpu_write(cpu_tlbstate.active_mm, next);
8092 #endif
8093 cpumask_set_cpu(cpu, mm_cpumask(next));
8094
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));
8102 +#else
8103 load_cr3(next->pgd);
8104 +#endif
8105
8106 /*
8107 * load the LDT, if the LDT is different:
8108 */
8109 if (unlikely(prev->context.ldt != next->context.ldt))
8110 load_LDT_nolock(&next->context);
8111 - }
8112 +
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);
8119 + }
8120 +#endif
8121 +
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);
8126 #ifdef CONFIG_SMP
8127 + else if (unlikely(tlbstate != TLBSTATE_OK))
8128 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
8129 +#endif
8130 +#endif
8131 +
8132 + }
8133 else {
8134 +
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));
8141 +#endif
8142 +
8143 +#ifdef CONFIG_SMP
8144 percpu_write(cpu_tlbstate.state, TLBSTATE_OK);
8145 BUG_ON(percpu_read(cpu_tlbstate.active_mm) != next);
8146
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.
8150 */
8151 +
8152 +#ifndef CONFIG_PAX_PER_CPU_PGD
8153 load_cr3(next->pgd);
8154 +#endif
8155 +
8156 load_LDT_nolock(&next->context);
8157 +
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);
8161 +#endif
8162 +
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)))
8166 +#endif
8167 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
8168 +#endif
8169 +
8170 }
8171 - }
8172 #endif
8173 + }
8174 }
8175
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
8180 @@ -9,10 +9,23 @@
8181 * we put the segment information here.
8182 */
8183 typedef struct {
8184 - void *ldt;
8185 + struct desc_struct *ldt;
8186 int size;
8187 struct mutex lock;
8188 - void *vdso;
8189 + unsigned long vdso;
8190 +
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;
8195 +
8196 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
8197 + cpumask_t cpu_user_cs_mask;
8198 +#endif
8199 +
8200 +#endif
8201 +#endif
8202 +
8203 } mm_context_t;
8204
8205 #ifdef CONFIG_SMP
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
8209 @@ -59,8 +59,26 @@
8210 #error unknown processor family
8211 #endif
8212
8213 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8214 +#define MODULE_PAX_UDEREF "UDEREF "
8215 +#else
8216 +#define MODULE_PAX_UDEREF ""
8217 +#endif
8218 +
8219 #ifdef CONFIG_X86_32
8220 -# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
8221 +# ifdef CONFIG_PAX_KERNEXEC
8222 +# define MODULE_PAX_KERNEXEC "KERNEXEC "
8223 +# else
8224 +# define MODULE_PAX_KERNEXEC ""
8225 +# endif
8226 +# ifdef CONFIG_GRKERNSEC
8227 +# define MODULE_GRSEC "GRSECURITY "
8228 +# else
8229 +# define MODULE_GRSEC ""
8230 +# endif
8231 +# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_GRSEC MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
8232 +#else
8233 +# define MODULE_ARCH_VERMAGIC MODULE_PAX_UDEREF
8234 #endif
8235
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);
8241
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;
8246
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);
8254 }
8255
8256 +#ifdef CONFIG_PAX_KERNEXEC
8257 +static inline unsigned long pax_open_kernel(void)
8258 +{
8259 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
8260 +}
8261 +
8262 +static inline unsigned long pax_close_kernel(void)
8263 +{
8264 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
8265 +}
8266 +#else
8267 +static inline unsigned long pax_open_kernel(void) { return 0; }
8268 +static inline unsigned long pax_close_kernel(void) { return 0; }
8269 +#endif
8270 +
8271 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
8272
8273 static inline int arch_spin_is_locked(struct arch_spinlock *lock)
8274 @@ -931,7 +946,7 @@ extern void default_banner(void);
8275
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
8280 #endif
8281
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), \
8285 CLBR_NONE, \
8286 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
8287 +
8288 +#define GET_CR0_INTO_RDI \
8289 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
8290 + mov %rax,%rdi
8291 +
8292 +#define SET_RDI_INTO_CR0 \
8293 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
8294 +
8295 +#define GET_CR3_INTO_RDI \
8296 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
8297 + mov %rax,%rdi
8298 +
8299 +#define SET_RDI_INTO_CR3 \
8300 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
8301 +
8302 #endif /* CONFIG_X86_32 */
8303
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);
8312 +
8313 +#ifdef CONFIG_PAX_KERNEXEC
8314 + unsigned long (*pax_open_kernel)(void);
8315 + unsigned long (*pax_close_kernel)(void);
8316 +#endif
8317 +
8318 };
8319
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);
8326
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);
8334 };
8335
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;
8340
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;
8344
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)
8351 {
8352 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
8353 + set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
8354 +}
8355 +
8356 +static inline void pmd_populate_user(struct mm_struct *mm,
8357 + pmd_t *pmd, pte_t *pte)
8358 +{
8359 + paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
8360 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
8361 }
8362
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
8367
8368 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
8369 {
8370 + pax_open_kernel();
8371 *pmdp = pmd;
8372 + pax_close_kernel();
8373 }
8374
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
8379 @@ -25,9 +25,6 @@
8380 struct mm_struct;
8381 struct vm_area_struct;
8382
8383 -extern pgd_t swapper_pg_dir[1024];
8384 -extern pgd_t initial_page_table[1024];
8385 -
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>
8391 #endif
8392
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];
8397 +#endif
8398 +
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) \
8405 do { \
8406 + pax_open_kernel(); \
8407 pte_clear(&init_mm, (vaddr), (ptep)); \
8408 + pax_close_kernel(); \
8409 __flush_tlb_one((vaddr)); \
8410 } while (0)
8411
8412 @@ -74,6 +79,9 @@ do { \
8413
8414 #endif /* !__ASSEMBLY__ */
8415
8416 +#define HAVE_ARCH_UNMAPPED_AREA
8417 +#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
8418 +
8419 /*
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
8425 @@ -8,7 +8,7 @@
8426 */
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))
8432 #else
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)
8436 #endif
8437
8438 +#ifdef CONFIG_PAX_KERNEXEC
8439 +#ifndef __ASSEMBLY__
8440 +extern unsigned char MODULES_EXEC_VADDR[];
8441 +extern unsigned char MODULES_EXEC_END[];
8442 +#endif
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)
8446 +#else
8447 +#define ktla_ktva(addr) (addr)
8448 +#define ktva_ktla(addr) (addr)
8449 +#endif
8450 +
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
8458
8459 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
8460 {
8461 + pax_open_kernel();
8462 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
8463 + pax_close_kernel();
8464 }
8465
8466 static inline void native_set_pud(pud_t *pudp, pud_t pud)
8467 {
8468 + pax_open_kernel();
8469 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
8470 + pax_close_kernel();
8471 }
8472
8473 /*
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
8477 @@ -16,10 +16,13 @@
8478
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];
8490
8491 #define swapper_pg_dir init_level4_pgt
8492
8493 @@ -74,7 +77,9 @@ static inline pte_t native_ptep_get_and_
8494
8495 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
8496 {
8497 + pax_open_kernel();
8498 *pmdp = pmd;
8499 + pax_close_kernel();
8500 }
8501
8502 static inline void native_pmd_clear(pmd_t *pmd)
8503 @@ -94,7 +99,9 @@ static inline void native_pud_clear(pud_
8504
8505 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
8506 {
8507 + pax_open_kernel();
8508 *pgdp = pgd;
8509 + pax_close_kernel();
8510 }
8511
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
8522 +
8523 +#define ktla_ktva(addr) (addr)
8524 +#define ktva_ktla(addr) (addr)
8525
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
8531
8532 #define arch_end_context_switch(prev) do {} while(0)
8533
8534 +#define pax_open_kernel() native_pax_open_kernel()
8535 +#define pax_close_kernel() native_pax_close_kernel()
8536 #endif /* CONFIG_PARAVIRT */
8537
8538 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
8539 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
8540 +
8541 +#ifdef CONFIG_PAX_KERNEXEC
8542 +static inline unsigned long native_pax_open_kernel(void)
8543 +{
8544 + unsigned long cr0;
8545 +
8546 + preempt_disable();
8547 + barrier();
8548 + cr0 = read_cr0() ^ X86_CR0_WP;
8549 + BUG_ON(unlikely(cr0 & X86_CR0_WP));
8550 + write_cr0(cr0);
8551 + return cr0 ^ X86_CR0_WP;
8552 +}
8553 +
8554 +static inline unsigned long native_pax_close_kernel(void)
8555 +{
8556 + unsigned long cr0;
8557 +
8558 + cr0 = read_cr0() ^ X86_CR0_WP;
8559 + BUG_ON(unlikely(!(cr0 & X86_CR0_WP)));
8560 + write_cr0(cr0);
8561 + barrier();
8562 + preempt_enable_no_resched();
8563 + return cr0 ^ X86_CR0_WP;
8564 +}
8565 +#else
8566 +static inline unsigned long native_pax_open_kernel(void) { return 0; }
8567 +static inline unsigned long native_pax_close_kernel(void) { return 0; }
8568 +#endif
8569 +
8570 /*
8571 * The following only work if pte_present() is true.
8572 * Undefined behaviour if not..
8573 */
8574 +static inline int pte_user(pte_t pte)
8575 +{
8576 + return pte_val(pte) & _PAGE_USER;
8577 +}
8578 +
8579 static inline int pte_dirty(pte_t pte)
8580 {
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);
8584 }
8585
8586 +static inline pte_t pte_mkread(pte_t pte)
8587 +{
8588 + return __pte(pte_val(pte) | _PAGE_USER);
8589 +}
8590 +
8591 static inline pte_t pte_mkexec(pte_t pte)
8592 {
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);
8597 + else
8598 +#endif
8599 + return pte_set_flags(pte, _PAGE_USER);
8600 +}
8601 +
8602 +static inline pte_t pte_exprotect(pte_t pte)
8603 +{
8604 +#ifdef CONFIG_X86_PAE
8605 + if (__supported_pte_mask & _PAGE_NX)
8606 + return pte_set_flags(pte, _PAGE_NX);
8607 + else
8608 +#endif
8609 + return pte_clear_flags(pte, _PAGE_USER);
8610 }
8611
8612 static inline pte_t pte_mkdirty(pte_t pte)
8613 @@ -306,6 +365,15 @@ pte_t *populate_extra_pte(unsigned long
8614 #endif
8615
8616 #ifndef __ASSEMBLY__
8617 +
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)
8621 +{
8622 + return cpu_pgd[cpu];
8623 +}
8624 +#endif
8625 +
8626 #include <linux/mm_types.h>
8627
8628 static inline int pte_none(pte_t pte)
8629 @@ -476,7 +544,7 @@ static inline pud_t *pud_offset(pgd_t *p
8630
8631 static inline int pgd_bad(pgd_t pgd)
8632 {
8633 - return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
8634 + return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
8635 }
8636
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;
8641 */
8642 -#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
8643 +#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
8644 +
8645 +#ifdef CONFIG_PAX_PER_CPU_PGD
8646 +#define pgd_offset_cpu(cpu, address) (get_cpu_pgd(cpu) + pgd_index(address))
8647 +#endif
8648 +
8649 /*
8650 * a shortcut which implies the use of the kernel's pgd, instead
8651 * of a process's
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)
8655
8656 +#ifdef CONFIG_X86_32
8657 +#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
8658 +#else
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))
8661 +
8662 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8663 +#define PAX_USER_SHADOW_BASE (_AC(1,UL) << TASK_SIZE_MAX_SHIFT)
8664 +#else
8665 +#define PAX_USER_SHADOW_BASE (_AC(0,UL))
8666 +#endif
8667 +
8668 +#endif
8669 +
8670 #ifndef __ASSEMBLY__
8671
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.
8676 */
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)
8679 {
8680 - memcpy(dst, src, count * sizeof(pgd_t));
8681 + pax_open_kernel();
8682 + while (count--)
8683 + *dst++ = *src++;
8684 + pax_close_kernel();
8685 }
8686
8687 +#ifdef CONFIG_PAX_PER_CPU_PGD
8688 +extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src, int count);
8689 +#endif
8690 +
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);
8693 +#else
8694 +static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src, int count) {}
8695 +#endif
8696
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
8702 @@ -16,12 +16,11 @@
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 */
8715
8716 /* If _PAGE_BIT_PRESENT is clear, we use these: */
8717 @@ -39,7 +38,6 @@
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)
8725 @@ -55,8 +53,10 @@
8726
8727 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
8728 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
8729 -#else
8730 +#elif defined(CONFIG_KMEMCHECK)
8731 #define _PAGE_NX (_AT(pteval_t, 0))
8732 +#else
8733 +#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
8734 #endif
8735
8736 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
8737 @@ -93,6 +93,9 @@
8738 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
8739 _PAGE_ACCESSED)
8740
8741 +#define PAGE_READONLY_NOEXEC PAGE_READONLY
8742 +#define PAGE_SHARED_NOEXEC PAGE_SHARED
8743 +
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)
8747 @@ -103,8 +106,8 @@
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)
8758 @@ -163,8 +166,8 @@
8759 * bits are combined, this will alow user to access the high address mapped
8760 * VDSO in the presence of CONFIG_COMPAT_VDSO
8761 */
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) */
8767 #endif
8768
8769 @@ -202,7 +205,17 @@ static inline pgdval_t pgd_flags(pgd_t p
8770 {
8771 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
8772 }
8773 +#endif
8774
8775 +#if PAGETABLE_LEVELS == 3
8776 +#include <asm-generic/pgtable-nopud.h>
8777 +#endif
8778 +
8779 +#if PAGETABLE_LEVELS == 2
8780 +#include <asm-generic/pgtable-nopmd.h>
8781 +#endif
8782 +
8783 +#ifndef __ASSEMBLY__
8784 #if PAGETABLE_LEVELS > 3
8785 typedef struct { pudval_t pud; } pud_t;
8786
8787 @@ -216,8 +229,6 @@ static inline pudval_t native_pud_val(pu
8788 return pud.pud;
8789 }
8790 #else
8791 -#include <asm-generic/pgtable-nopud.h>
8792 -
8793 static inline pudval_t native_pud_val(pud_t pud)
8794 {
8795 return native_pgd_val(pud.pgd);
8796 @@ -237,8 +248,6 @@ static inline pmdval_t native_pmd_val(pm
8797 return pmd.pmd;
8798 }
8799 #else
8800 -#include <asm-generic/pgtable-nopmd.h>
8801 -
8802 static inline pmdval_t native_pmd_val(pmd_t pmd)
8803 {
8804 return native_pgd_val(pmd.pud.pgd);
8805 @@ -278,7 +287,6 @@ typedef struct page *pgtable_t;
8806
8807 extern pteval_t __supported_pte_mask;
8808 extern void set_nx(void);
8809 -extern int nx_enabled;
8810
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 {
8817
8818 } ____cacheline_aligned;
8819
8820 -DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
8821 +extern struct tss_struct init_tss[NR_CPUS];
8822
8823 /*
8824 * Save the original ist values for checking stack pointers during debugging
8825 @@ -864,8 +864,15 @@ static inline void spin_lock_prefetch(co
8826 */
8827 #define TASK_SIZE PAGE_OFFSET
8828 #define TASK_SIZE_MAX TASK_SIZE
8829 +
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)
8833 +#else
8834 #define STACK_TOP TASK_SIZE
8835 -#define STACK_TOP_MAX STACK_TOP
8836 +#endif
8837 +
8838 +#define STACK_TOP_MAX TASK_SIZE
8839
8840 #define INIT_THREAD { \
8841 .sp0 = sizeof(init_stack) + (long)&init_stack, \
8842 @@ -882,7 +889,7 @@ static inline void spin_lock_prefetch(co
8843 */
8844 #define INIT_TSS { \
8845 .x86_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);
8853
8854 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
8855 -#define KSTK_TOP(info) \
8856 -({ \
8857 - unsigned long *__ptr = (unsigned long *)(info); \
8858 - (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
8859 -})
8860 +#define KSTK_TOP(info) ((info)->task.thread.sp0)
8861
8862 /*
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) \
8866 ({ \
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); \
8870 __regs__ - 1; \
8871 })
8872
8873 @@ -922,13 +925,13 @@ extern unsigned long thread_saved_pc(str
8874 /*
8875 * User space process size. 47bits minus one guard page.
8876 */
8877 -#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
8878 +#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
8879
8880 /* This decides where the kernel will search for a free chunk of vm
8881 * space during mmap's.
8882 */
8883 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
8884 - 0xc0000000 : 0xFFFFe000)
8885 + 0xc0000000 : 0xFFFFf000)
8886
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
8890 */
8891 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
8892
8893 +#ifdef CONFIG_PAX_SEGMEXEC
8894 +#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
8895 +#endif
8896 +
8897 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
8898
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_
8904 }
8905
8906 /*
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
8914 + * be used.
8915 */
8916 -static inline int user_mode(struct pt_regs *regs)
8917 +static inline int user_mode_novm(struct pt_regs *regs)
8918 {
8919 #ifdef CONFIG_X86_32
8920 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
8921 #else
8922 - return !!(regs->cs & 3);
8923 + return !!(regs->cs & SEGMENT_RPL_MASK);
8924 #endif
8925 }
8926
8927 -static inline int user_mode_vm(struct pt_regs *regs)
8928 +static inline int user_mode(struct pt_regs *regs)
8929 {
8930 #ifdef CONFIG_X86_32
8931 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
8932 USER_RPL;
8933 #else
8934 - return user_mode(regs);
8935 + return user_mode_novm(regs);
8936 #endif
8937 }
8938
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;
8943
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);
8948
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
8955 {
8956 asm volatile("# beginning down_read\n\t"
8957 LOCK_PREFIX _ASM_INC "(%1)\n\t"
8958 +
8959 +#ifdef CONFIG_PAX_REFCOUNT
8960 + "jno 0f\n"
8961 + LOCK_PREFIX _ASM_DEC "(%1)\n"
8962 + "int $4\n0:\n"
8963 + _ASM_EXTABLE(0b, 0b)
8964 +#endif
8965 +
8966 /* adds 0x00000001 */
8967 " jns 1f\n"
8968 " call call_rwsem_down_read_failed\n"
8969 @@ -139,6 +147,14 @@ static inline int __down_read_trylock(st
8970 "1:\n\t"
8971 " mov %1,%2\n\t"
8972 " add %3,%2\n\t"
8973 +
8974 +#ifdef CONFIG_PAX_REFCOUNT
8975 + "jno 0f\n"
8976 + "sub %3,%2\n"
8977 + "int $4\n0:\n"
8978 + _ASM_EXTABLE(0b, 0b)
8979 +#endif
8980 +
8981 " jle 2f\n\t"
8982 LOCK_PREFIX " cmpxchg %2,%0\n\t"
8983 " jnz 1b\n\t"
8984 @@ -158,6 +174,14 @@ static inline void __down_write_nested(s
8985 rwsem_count_t tmp;
8986 asm volatile("# beginning down_write\n\t"
8987 LOCK_PREFIX " xadd %1,(%2)\n\t"
8988 +
8989 +#ifdef CONFIG_PAX_REFCOUNT
8990 + "jno 0f\n"
8991 + "mov %1,(%2)\n"
8992 + "int $4\n0:\n"
8993 + _ASM_EXTABLE(0b, 0b)
8994 +#endif
8995 +
8996 /* adds 0xffff0001, returns the old value */
8997 " test %1,%1\n\t"
8998 /* was the count 0 before? */
8999 @@ -196,6 +220,14 @@ static inline void __up_read(struct rw_s
9000 rwsem_count_t tmp;
9001 asm volatile("# beginning __up_read\n\t"
9002 LOCK_PREFIX " xadd %1,(%2)\n\t"
9003 +
9004 +#ifdef CONFIG_PAX_REFCOUNT
9005 + "jno 0f\n"
9006 + "mov %1,(%2)\n"
9007 + "int $4\n0:\n"
9008 + _ASM_EXTABLE(0b, 0b)
9009 +#endif
9010 +
9011 /* subtracts 1, returns the old value */
9012 " jns 1f\n\t"
9013 " call call_rwsem_wake\n" /* expects old value in %edx */
9014 @@ -214,6 +246,14 @@ static inline void __up_write(struct rw_
9015 rwsem_count_t tmp;
9016 asm volatile("# beginning __up_write\n\t"
9017 LOCK_PREFIX " xadd %1,(%2)\n\t"
9018 +
9019 +#ifdef CONFIG_PAX_REFCOUNT
9020 + "jno 0f\n"
9021 + "mov %1,(%2)\n"
9022 + "int $4\n0:\n"
9023 + _ASM_EXTABLE(0b, 0b)
9024 +#endif
9025 +
9026 /* subtracts 0xffff0001, returns the old value */
9027 " jns 1f\n\t"
9028 " call call_rwsem_wake\n" /* expects old value in %edx */
9029 @@ -231,6 +271,14 @@ static inline void __downgrade_write(str
9030 {
9031 asm volatile("# beginning __downgrade_write\n\t"
9032 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
9033 +
9034 +#ifdef CONFIG_PAX_REFCOUNT
9035 + "jno 0f\n"
9036 + LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
9037 + "int $4\n0:\n"
9038 + _ASM_EXTABLE(0b, 0b)
9039 +#endif
9040 +
9041 /*
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)
9047 {
9048 - asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
9049 + asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
9050 +
9051 +#ifdef CONFIG_PAX_REFCOUNT
9052 + "jno 0f\n"
9053 + LOCK_PREFIX _ASM_SUB "%1,%0\n"
9054 + "int $4\n0:\n"
9055 + _ASM_EXTABLE(0b, 0b)
9056 +#endif
9057 +
9058 : "+m" (sem->count)
9059 : "er" (delta));
9060 }
9061 @@ -263,7 +319,15 @@ static inline rwsem_count_t rwsem_atomic
9062 {
9063 rwsem_count_t tmp = delta;
9064
9065 - asm volatile(LOCK_PREFIX "xadd %0,%1"
9066 + asm volatile(LOCK_PREFIX "xadd %0,%1\n"
9067 +
9068 +#ifdef CONFIG_PAX_REFCOUNT
9069 + "jno 0f\n"
9070 + "mov %0,%1\n"
9071 + "int $4\n0:\n"
9072 + _ASM_EXTABLE(0b, 0b)
9073 +#endif
9074 +
9075 : "+r" (tmp), "+m" (sem->count)
9076 : : "memory");
9077
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
9081 @@ -62,8 +62,8 @@
9082 * 26 - ESPFIX small SS
9083 * 27 - per-cpu [ offset to per-cpu data area ]
9084 * 28 - stack_canary-20 [ for stack protector ]
9085 - * 29 - unused
9086 - * 30 - unused
9087 + * 29 - PCI BIOS CS
9088 + * 30 - PCI BIOS DS
9089 * 31 - TSS for double fault handler
9090 */
9091 #define GDT_ENTRY_TLS_MIN 6
9092 @@ -77,6 +77,8 @@
9093
9094 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
9095
9096 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
9097 +
9098 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
9099
9100 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
9101 @@ -102,6 +104,12 @@
9102 #define __KERNEL_STACK_CANARY 0
9103 #endif
9104
9105 +#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
9106 +#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
9107 +
9108 +#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
9109 +#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
9110 +
9111 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
9112
9113 /*
9114 @@ -139,7 +147,7 @@
9115 */
9116
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)
9120
9121
9122 #else
9123 @@ -163,6 +171,8 @@
9124 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS * 8 + 3)
9125 #define __USER32_DS __USER_DS
9126
9127 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
9128 +
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
9132 @@ -183,6 +193,7 @@
9133 #endif
9134
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);
9149
9150 static inline struct cpumask *cpu_sibling_mask(int cpu)
9151 {
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)
9157 {
9158 asm volatile(LOCK_PREFIX " subl $1,(%0)\n\t"
9159 +
9160 +#ifdef CONFIG_PAX_REFCOUNT
9161 + "jno 0f\n"
9162 + LOCK_PREFIX " addl $1,(%0)\n"
9163 + "int $4\n0:\n"
9164 + _ASM_EXTABLE(0b, 0b)
9165 +#endif
9166 +
9167 "jns 1f\n"
9168 "call __read_lock_failed\n\t"
9169 "1:\n"
9170 @@ -258,6 +266,14 @@ static inline void arch_read_lock(arch_r
9171 static inline void arch_write_lock(arch_rwlock_t *rw)
9172 {
9173 asm volatile(LOCK_PREFIX " subl %1,(%0)\n\t"
9174 +
9175 +#ifdef CONFIG_PAX_REFCOUNT
9176 + "jno 0f\n"
9177 + LOCK_PREFIX " addl %1,(%0)\n"
9178 + "int $4\n0:\n"
9179 + _ASM_EXTABLE(0b, 0b)
9180 +#endif
9181 +
9182 "jz 1f\n"
9183 "call __write_lock_failed\n\t"
9184 "1:\n"
9185 @@ -286,12 +302,29 @@ static inline int arch_write_trylock(arc
9186
9187 static inline void arch_read_unlock(arch_rwlock_t *rw)
9188 {
9189 - asm volatile(LOCK_PREFIX "incl %0" :"+m" (rw->lock) : : "memory");
9190 + asm volatile(LOCK_PREFIX "incl %0\n"
9191 +
9192 +#ifdef CONFIG_PAX_REFCOUNT
9193 + "jno 0f\n"
9194 + LOCK_PREFIX "decl %0\n"
9195 + "int $4\n0:\n"
9196 + _ASM_EXTABLE(0b, 0b)
9197 +#endif
9198 +
9199 + :"+m" (rw->lock) : : "memory");
9200 }
9201
9202 static inline void arch_write_unlock(arch_rwlock_t *rw)
9203 {
9204 - asm volatile(LOCK_PREFIX "addl %1, %0"
9205 + asm volatile(LOCK_PREFIX "addl %1, %0\n"
9206 +
9207 +#ifdef CONFIG_PAX_REFCOUNT
9208 + "jno 0f\n"
9209 + LOCK_PREFIX "subl %1, %0\n"
9210 + "int $4\n0:\n"
9211 + _ASM_EXTABLE(0b, 0b)
9212 +#endif
9213 +
9214 : "+m" (rw->lock) : "i" (RW_LOCK_BIAS) : "memory");
9215 }
9216
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
9221
9222 static inline void load_stack_canary_segment(void)
9223 {
9224 -#ifdef CONFIG_X86_32
9225 +#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
9226 asm volatile ("mov %0, %%gs" : : "r" (0));
9227 #endif
9228 }
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
9233 {
9234 unsigned long __limit;
9235 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
9236 - return __limit + 1;
9237 + return __limit;
9238 }
9239
9240 static inline void native_clts(void)
9241 @@ -342,7 +342,7 @@ void enable_hlt(void);
9242
9243 void cpu_idle_wait(void);
9244
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);
9248
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)
9256 {
9257 + if ((long)n < 0)
9258 + return n;
9259 +
9260 if (__builtin_constant_p(n)) {
9261 unsigned long ret;
9262
9263 @@ -62,6 +65,8 @@ __copy_to_user_inatomic(void __user *to,
9264 return ret;
9265 }
9266 }
9267 + if (!__builtin_constant_p(n))
9268 + check_object_size(from, n, true);
9269 return __copy_to_user_ll(to, from, n);
9270 }
9271
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)
9275 {
9276 + if ((long)n < 0)
9277 + return n;
9278 +
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)
9284 {
9285 might_fault();
9286 +
9287 + if ((long)n < 0)
9288 + return n;
9289 +
9290 if (__builtin_constant_p(n)) {
9291 unsigned long ret;
9292
9293 @@ -153,6 +165,8 @@ __copy_from_user(void *to, const void __
9294 return ret;
9295 }
9296 }
9297 + if (!__builtin_constant_p(n))
9298 + check_object_size(to, n, false);
9299 return __copy_from_user_ll(to, from, n);
9300 }
9301
9302 @@ -160,6 +174,10 @@ static __always_inline unsigned long __c
9303 const void __user *from, unsigned long n)
9304 {
9305 might_fault();
9306 +
9307 + if ((long)n < 0)
9308 + return n;
9309 +
9310 if (__builtin_constant_p(n)) {
9311 unsigned long ret;
9312
9313 @@ -182,15 +200,19 @@ static __always_inline unsigned long
9314 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
9315 unsigned long n)
9316 {
9317 - return __copy_from_user_ll_nocache_nozero(to, from, n);
9318 -}
9319 + if ((long)n < 0)
9320 + return n;
9321
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,
9326 - unsigned long n);
9327 + return __copy_from_user_ll_nocache_nozero(to, from, n);
9328 +}
9329
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")
9333 +#else
9334 + __compiletime_warning("copy_to_user() buffer size is not provably correct")
9335 +#endif
9336 +;
9337
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
9341 #endif
9342 ;
9343
9344 -static inline unsigned long __must_check copy_from_user(void *to,
9345 - const void __user *from,
9346 - unsigned long n)
9347 +/**
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.
9352 + *
9353 + * Context: User context only. This function may sleep.
9354 + *
9355 + * Copy data from kernel space to user space.
9356 + *
9357 + * Returns number of bytes that could not be copied.
9358 + * On success, this will be zero.
9359 + */
9360 +static inline unsigned long __must_check
9361 +copy_to_user(void __user *to, const void *from, unsigned long n)
9362 +{
9363 + int sz = __compiletime_object_size(from);
9364 +
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);
9369 + return n;
9370 +}
9371 +
9372 +/**
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.
9377 + *
9378 + * Context: User context only. This function may sleep.
9379 + *
9380 + * Copy data from user space to kernel space.
9381 + *
9382 + * Returns number of bytes that could not be copied.
9383 + * On success, this will be zero.
9384 + *
9385 + * If some data could not be copied, this function will pad the copied
9386 + * data to the requested size using zero bytes.
9387 + */
9388 +static inline unsigned long __must_check
9389 +copy_from_user(void *to, const void __user *from, unsigned long n)
9390 {
9391 int sz = __compiletime_object_size(to);
9392
9393 - if (likely(sz == -1 || sz >= n))
9394 - n = _copy_from_user(to, from, n);
9395 - else
9396 + if (unlikely(sz != -1 && sz < n))
9397 copy_from_user_overflow();
9398 -
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);
9404 + memset(to, 0, n);
9405 + }
9406 return n;
9407 }
9408
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
9412 @@ -11,6 +11,9 @@
9413 #include <asm/alternative.h>
9414 #include <asm/cpufeature.h>
9415 #include <asm/page.h>
9416 +#include <asm/pgtable.h>
9417 +
9418 +#define set_fs(x) (current_thread_info()->addr_limit = (x))
9419
9420 /*
9421 * Copy To/From Userspace
9422 @@ -37,26 +40,26 @@ copy_user_generic(void *to, const void *
9423 return ret;
9424 }
9425
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);
9436
9437 static inline unsigned long __must_check copy_from_user(void *to,
9438 const void __user *from,
9439 - unsigned long n)
9440 + unsigned n)
9441 {
9442 - int sz = __compiletime_object_size(to);
9443 -
9444 might_fault();
9445 - if (likely(sz == -1 || sz >= n))
9446 - n = _copy_from_user(to, from, n);
9447 -#ifdef CONFIG_DEBUG_VM
9448 - else
9449 - WARN(1, "Buffer overflow detected!\n");
9450 -#endif
9451 +
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);
9457 + memset(to, 0, n);
9458 + }
9459 return n;
9460 }
9461
9462 @@ -65,110 +68,174 @@ int copy_to_user(void __user *dst, const
9463 {
9464 might_fault();
9465
9466 - return _copy_to_user(dst, src, size);
9467 + if (access_ok(VERIFY_WRITE, dst, size))
9468 + size = __copy_to_user(dst, src, size);
9469 + return size;
9470 }
9471
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)
9475 {
9476 - int ret = 0;
9477 + int sz = __compiletime_object_size(dst);
9478 + unsigned ret = 0;
9479
9480 might_fault();
9481 - if (!__builtin_constant_p(size))
9482 - return copy_user_generic(dst, (__force void *)src, size);
9483 +
9484 + if ((int)size < 0)
9485 + return size;
9486 +
9487 +#ifdef CONFIG_PAX_MEMORY_UDEREF
9488 + if (!__access_ok(VERIFY_READ, src, size))
9489 + return size;
9490 +#endif
9491 +
9492 + if (unlikely(sz != -1 && sz < size)) {
9493 +#ifdef CONFIG_DEBUG_VM
9494 + WARN(1, "Buffer overflow detected!\n");
9495 +#endif
9496 + return size;
9497 + }
9498 +
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);
9504 + }
9505 switch (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);
9509 return ret;
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);
9513 return ret;
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);
9517 return ret;
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);
9521 return ret;
9522 case 10:
9523 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
9524 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
9525 ret, "q", "", "=r", 10);
9526 if (unlikely(ret))
9527 return ret;
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);
9532 return ret;
9533 case 16:
9534 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
9535 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
9536 ret, "q", "", "=r", 16);
9537 if (unlikely(ret))
9538 return ret;
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);
9543 return ret;
9544 default:
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);
9549 }
9550 }
9551
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)
9555 {
9556 - int ret = 0;
9557 + int sz = __compiletime_object_size(src);
9558 + unsigned ret = 0;
9559
9560 might_fault();
9561 - if (!__builtin_constant_p(size))
9562 +
9563 + if ((int)size < 0)
9564 + return size;
9565 +
9566 +#ifdef CONFIG_PAX_MEMORY_UDEREF
9567 + if (!__access_ok(VERIFY_WRITE, dst, size))
9568 + return size;
9569 +#endif
9570 +
9571 + if (unlikely(sz != -1 && sz < size)) {
9572 +#ifdef CONFIG_DEBUG_VM
9573 + WARN(1, "Buffer overflow detected!\n");
9574 +#endif
9575 + return size;
9576 + }
9577 +
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);
9583 + }
9584 switch (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);
9588 return ret;
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);
9592 return ret;
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);
9596 return ret;
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);
9600 return ret;
9601 case 10:
9602 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
9603 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
9604 ret, "q", "", "er", 10);
9605 if (unlikely(ret))
9606 return ret;
9607 asm("":::"memory");
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);
9611 return ret;
9612 case 16:
9613 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
9614 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
9615 ret, "q", "", "er", 16);
9616 if (unlikely(ret))
9617 return ret;
9618 asm("":::"memory");
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);
9622 return ret;
9623 default:
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);
9627 }
9628 }
9629
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)
9633 {
9634 - int ret = 0;
9635 + unsigned ret = 0;
9636
9637 might_fault();
9638 - if (!__builtin_constant_p(size))
9639 +
9640 + if ((int)size < 0)
9641 + return size;
9642 +
9643 +#ifdef CONFIG_PAX_MEMORY_UDEREF
9644 + if (!__access_ok(VERIFY_READ, src, size))
9645 + return size;
9646 + if (!__access_ok(VERIFY_WRITE, dst, size))
9647 + return size;
9648 +#endif
9649 +
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);
9658 + }
9659 switch (size) {
9660 case 1: {
9661 u8 tmp;
9662 - __get_user_asm(tmp, (u8 __user *)src,
9663 + __get_user_asm(tmp, (const u8 __user *)src,
9664 ret, "b", "b", "=q", 1);
9665 if (likely(!ret))
9666 __put_user_asm(tmp, (u8 __user *)dst,
9667 @@ -177,7 +244,7 @@ int __copy_in_user(void __user *dst, con
9668 }
9669 case 2: {
9670 u16 tmp;
9671 - __get_user_asm(tmp, (u16 __user *)src,
9672 + __get_user_asm(tmp, (const u16 __user *)src,
9673 ret, "w", "w", "=r", 2);
9674 if (likely(!ret))
9675 __put_user_asm(tmp, (u16 __user *)dst,
9676 @@ -187,7 +254,7 @@ int __copy_in_user(void __user *dst, con
9677
9678 case 4: {
9679 u32 tmp;
9680 - __get_user_asm(tmp, (u32 __user *)src,
9681 + __get_user_asm(tmp, (const u32 __user *)src,
9682 ret, "l", "k", "=r", 4);
9683 if (likely(!ret))
9684 __put_user_asm(tmp, (u32 __user *)dst,
9685 @@ -196,7 +263,7 @@ int __copy_in_user(void __user *dst, con
9686 }
9687 case 8: {
9688 u64 tmp;
9689 - __get_user_asm(tmp, (u64 __user *)src,
9690 + __get_user_asm(tmp, (const u64 __user *)src,
9691 ret, "q", "", "=r", 8);
9692 if (likely(!ret))
9693 __put_user_asm(tmp, (u64 __user *)dst,
9694 @@ -204,8 +271,12 @@ int __copy_in_user(void __user *dst, con
9695 return ret;
9696 }
9697 default:
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);
9705 }
9706 }
9707
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)
9711 {
9712 + if ((int)size < 0)
9713 + return size;
9714 +
9715 +#ifdef CONFIG_PAX_MEMORY_UDEREF
9716 + if (!__access_ok(VERIFY_READ, src, size))
9717 + return size;
9718 +#endif
9719 +
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);
9723 }
9724
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)
9728 {
9729 + if ((int)size < 0)
9730 + return size;
9731 +
9732 +#ifdef CONFIG_PAX_MEMORY_UDEREF
9733 + if (!__access_ok(VERIFY_WRITE, dst, size))
9734 + return size;
9735 +#endif
9736 +
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);
9740 }
9741
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);
9745
9746 -static inline int
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)
9749 {
9750 might_sleep();
9751 +
9752 + if ((int)size < 0)
9753 + return size;
9754 +
9755 +#ifdef CONFIG_PAX_MEMORY_UDEREF
9756 + if (!__access_ok(VERIFY_READ, src, size))
9757 + return size;
9758 +#endif
9759 +
9760 return __copy_user_nocache(dst, src, size, 1);
9761 }
9762
9763 -static inline int
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,
9766 unsigned size)
9767 {
9768 + if ((int)size < 0)
9769 + return size;
9770 +
9771 +#ifdef CONFIG_PAX_MEMORY_UDEREF
9772 + if (!__access_ok(VERIFY_READ, src, size))
9773 + return size;
9774 +#endif
9775 +
9776 return __copy_user_nocache(dst, src, size, 0);
9777 }
9778
9779 -unsigned long
9780 +extern unsigned long
9781 copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
9782
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
9787 @@ -8,12 +8,15 @@
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>
9794
9795 #define VERIFY_READ 0
9796 #define VERIFY_WRITE 1
9797
9798 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
9799 +
9800 /*
9801 * The fs value determines whether argument validity checking should be
9802 * performed or not. If get_fs() == USER_DS, checking is performed, with
9803 @@ -29,7 +32,12 @@
9804
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);
9810 +#else
9811 #define set_fs(x) (current_thread_info()->addr_limit = (x))
9812 +#endif
9813
9814 #define segment_eq(a, b) ((a).seg == (b).seg)
9815
9816 @@ -77,7 +85,33 @@
9817 * checks that the pointer is in the user space range - after calling
9818 * this function, memory access functions may still return -EFAULT.
9819 */
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) \
9823 +({ \
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) { \
9831 + char __c_ao; \
9832 + __addr_ao += PAGE_SIZE; \
9833 + if (__size > PAGE_SIZE) \
9834 + cond_resched(); \
9835 + if (__get_user(__c_ao, (char __user *)__addr)) \
9836 + break; \
9837 + if (type != VERIFY_WRITE) { \
9838 + __addr = __addr_ao; \
9839 + continue; \
9840 + } \
9841 + if (__put_user(__c_ao, (char __user *)__addr)) \
9842 + break; \
9843 + __addr = __addr_ao; \
9844 + } \
9845 + } \
9846 + __ret_ao; \
9847 +})
9848
9849 /*
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")
9854
9855 -
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"
9860 +#else
9861 +#define __copyuser_seg
9862 +#define __COPYUSER_SET_ES
9863 +#define __COPYUSER_RESTORE_ES
9864 +#endif
9865
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" \
9872 "3:\n" \
9873 ".section .fixup,\"ax\"\n" \
9874 "4: movl %3,%0\n" \
9875 @@ -200,8 +242,8 @@ extern int __get_user_bad(void);
9876 : "A" (x), "r" (addr), "i" (errret), "0" (err))
9877
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" \
9883 "3:\n" \
9884 _ASM_EXTABLE(1b, 2b - 1b) \
9885 _ASM_EXTABLE(2b, 3b - 2b) \
9886 @@ -374,7 +416,7 @@ do { \
9887 } while (0)
9888
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"\
9892 "2:\n" \
9893 ".section .fixup,\"ax\"\n" \
9894 "3: mov %3,%0\n" \
9895 @@ -382,7 +424,7 @@ do { \
9896 " jmp 2b\n" \
9897 ".previous\n" \
9898 _ASM_EXTABLE(1b, 3b) \
9899 - : "=r" (err), ltype(x) \
9900 + : "=r" (err), ltype (x) \
9901 : "m" (__m(addr)), "i" (errret), "0" (err))
9902
9903 #define __get_user_size_ex(x, ptr, size) \
9904 @@ -407,7 +449,7 @@ do { \
9905 } while (0)
9906
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"\
9910 "2:\n" \
9911 _ASM_EXTABLE(1b, 2b - 1b) \
9912 : ltype(x) : "m" (__m(addr)))
9913 @@ -424,13 +466,24 @@ do { \
9914 int __gu_err; \
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; \
9919 __gu_err; \
9920 })
9921
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)
9926 +#define ____m(x) \
9927 +({ \
9928 + unsigned long ____x = (unsigned long)(x); \
9929 + if (____x < PAX_USER_SHADOW_BASE) \
9930 + ____x += PAX_USER_SHADOW_BASE; \
9931 + (void __user *)____x; \
9932 +})
9933 +#else
9934 +#define ____m(x) (x)
9935 +#endif
9936 +#define __m(x) (*(struct __large_struct __user *)____m(x))
9937
9938 /*
9939 * Tell gcc we read from memory instead of writing: this is because
9940 @@ -438,7 +491,7 @@ struct __large_struct { unsigned long bu
9941 * aliasing issues.
9942 */
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"\
9946 "2:\n" \
9947 ".section .fixup,\"ax\"\n" \
9948 "3: mov %3,%0\n" \
9949 @@ -446,10 +499,10 @@ struct __large_struct { unsigned long bu
9950 ".previous\n" \
9951 _ASM_EXTABLE(1b, 3b) \
9952 : "=r"(err) \
9953 - : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
9954 + : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err))
9955
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"\
9959 "2:\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.
9964 */
9965
9966 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
9967 +#define __get_user(x, ptr) get_user((x), (ptr))
9968 +#else
9969 #define __get_user(x, ptr) \
9970 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
9971 +#endif
9972
9973 /**
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.
9977 */
9978
9979 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
9980 +#define __put_user(x, ptr) put_user((x), (ptr))
9981 +#else
9982 #define __put_user(x, ptr) \
9983 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
9984 +#endif
9985
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; \
9994 } while (0)
9995
9996 #ifdef CONFIG_X86_WP_WORKS_OK
9997 @@ -567,6 +628,7 @@ extern struct movsl_mask {
9998
9999 #define ARCH_HAS_NOCACHE_UACCESS 1
10000
10001 +#define ARCH_HAS_SORT_EXTABLE
10002 #ifdef CONFIG_X86_32
10003 # include "uaccess_32.h"
10004 #else
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 */
10012 + char name[8];
10013 cycle_t (*vread)(void);
10014 cycle_t cycle_last;
10015 cycle_t mask;
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 {
10020
10021 #ifdef __KERNEL__
10022 #include <linux/seqlock.h>
10023 +#include <linux/getcpu.h>
10024 +#include <linux/time.h>
10025
10026 #define __section_vgetcpu_mode __attribute__ ((unused, __section__ (".vgetcpu_mode"), aligned(16)))
10027 -#define __section_jiffies __attribute__ ((unused, __section__ (".jiffies"), aligned(16)))
10028
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
10033
10034 extern int __vgetcpu_mode;
10035 -extern volatile unsigned long __jiffies;
10036
10037 /* kernel space (writeable) */
10038 extern int vgetcpu_mode;
10039 @@ -39,6 +39,9 @@ extern struct timezone sys_tz;
10040
10041 extern void map_vsyscall(void);
10042
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__ */
10047
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
10053 {
10054 int err;
10055
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);
10059 +#endif
10060 +
10061 /*
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
10065 u32 lmask = mask;
10066 u32 hmask = mask >> 32;
10067
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);
10071 +#endif
10072 +
10073 __asm__ __volatile__("1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
10074 "2:\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
10080
10081 config X86_32_LAZY_GS
10082 def_bool y
10083 - depends on X86_32 && !CC_STACKPROTECTOR
10084 + depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
10085
10086 config ARCH_HWEIGHT_CFLAGS
10087 string
10088 @@ -992,7 +992,7 @@ choice
10089
10090 config NOHIGHMEM
10091 bool "off"
10092 - depends on !X86_NUMAQ
10093 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
10094 ---help---
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
10098
10099 config HIGHMEM4G
10100 bool "4GB"
10101 - depends on !X86_NUMAQ
10102 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
10103 ---help---
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
10107 hex
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
10113 default 0xC0000000
10114 depends on X86_32
10115 @@ -1427,7 +1427,7 @@ config ARCH_USES_PG_UNCACHED
10116
10117 config EFI
10118 bool "EFI runtime service support"
10119 - depends on ACPI
10120 + depends on ACPI && !PAX_KERNEXEC
10121 ---help---
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
10125
10126 config CC_STACKPROTECTOR
10127 bool "Enable -fstack-protector buffer overflow detection (EXPERIMENTAL)"
10128 + depends on X86_64 || !PAX_MEMORY_UDEREF
10129 ---help---
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
10137 ---help---
10138 This gives the physical address where the kernel is loaded.
10139
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
10146 ---help---
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.
10150
10151 config COMPAT_VDSO
10152 - def_bool y
10153 + def_bool n
10154 prompt "Compat VDSO support"
10155 depends on X86_32 || IA32_EMULATION
10156 + depends on !PAX_NOEXEC && !PAX_MEMORY_UDEREF
10157 ---help---
10158 Map the 32-bit VDSO to the predictable old-style address too.
10159
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
10164
10165 config X86_F00F_BUG
10166 def_bool y
10167 - depends on M586MMX || M586TSC || M586 || M486 || M386
10168 + depends on (M586MMX || M586TSC || M586 || M486 || M386) && !PAX_KERNEXEC
10169
10170 config X86_INVD_BUG
10171 def_bool y
10172 @@ -360,7 +360,7 @@ config X86_POPAD_OK
10173
10174 config X86_ALIGNMENT_16
10175 def_bool y
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
10178
10179 config X86_INTEL_USERCOPY
10180 def_bool y
10181 @@ -406,7 +406,7 @@ config X86_CMPXCHG64
10182 # generates cmov.
10183 config X86_CMOV
10184 def_bool y
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)
10187
10188 config X86_MINIMUM_CPU_FAMILY
10189 int
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"
10196 default y
10197 - depends on DEBUG_KERNEL
10198 + depends on DEBUG_KERNEL && BROKEN
10199 ---help---
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"),
10207 },
10208 },
10209 - {}
10210 + { NULL, NULL, {{0, {0}}}, NULL}
10211 };
10212
10213 /*
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
10217 @@ -12,6 +12,7 @@
10218 #include <linux/cpumask.h>
10219 #include <asm/segment.h>
10220 #include <asm/desc.h>
10221 +#include <asm/e820.h>
10222
10223 #ifdef CONFIG_X86_32
10224 #include <asm/pgtable.h>
10225 @@ -20,7 +21,7 @@
10226 #include "realmode/wakeup.h"
10227 #include "sleep.h"
10228
10229 -unsigned long acpi_wakeup_address;
10230 +unsigned long acpi_wakeup_address = 0x2000;
10231 unsigned long acpi_realmode_flags;
10232
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;
10236 #ifdef CONFIG_SMP
10237 stack_start.sp = temp_stack + sizeof(temp_stack);
10238 +
10239 + pax_open_kernel();
10240 early_gdt_descr.address =
10241 (unsigned long)get_cpu_gdt_table(smp_processor_id());
10242 + pax_close_kernel();
10243 +
10244 initial_gs = per_cpu_offset(smp_processor_id());
10245 #endif
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
10253
10254 - movl %cs:saved_magic, %eax
10255 - cmpl $0x12345678, %eax
10256 + cmpl $0x12345678, saved_magic
10257 jne bogus_magic
10258
10259 # jump to place where we left off
10260 - movl saved_eip, %eax
10261 - jmp *%eax
10262 + jmp *(saved_eip)
10263
10264 bogus_magic:
10265 jmp bogus_magic
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)
10271 continue;
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);
10276 };
10277 mutex_unlock(&text_mutex);
10278 @@ -269,7 +269,7 @@ static void alternatives_smp_unlock(cons
10279 if (!*poff || ptr < text || ptr >= text_end)
10280 continue;
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);
10285 };
10286 mutex_unlock(&text_mutex);
10287 @@ -437,7 +437,7 @@ void __init_or_module apply_paravirt(str
10288
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);
10295
10296 @@ -505,7 +505,7 @@ void __init alternative_instructions(voi
10297 if (smp_alt_once)
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));
10302
10303 restart_nmi();
10304 }
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.
10308 */
10309 -void *__init_or_module text_poke_early(void *addr, const void *opcode,
10310 +void *__kprobes text_poke_early(void *addr, const void *opcode,
10311 size_t len)
10312 {
10313 unsigned long flags;
10314 local_irq_save(flags);
10315 - memcpy(addr, opcode, len);
10316 +
10317 + pax_open_kernel();
10318 + memcpy(ktla_ktva(addr), opcode, len);
10319 sync_core();
10320 + pax_close_kernel();
10321 +
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
10326 */
10327 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
10328 {
10329 - unsigned long flags;
10330 - char *vaddr;
10331 + unsigned char *vaddr = ktla_ktva(addr);
10332 struct page *pages[2];
10333 - int i;
10334 + size_t i;
10335
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);
10341 } else {
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);
10347 }
10348 BUG_ON(!pages[0]);
10349 - local_irq_save(flags);
10350 - set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
10351 - if (pages[1])
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);
10356 - if (pages[1])
10357 - clear_fixmap(FIX_TEXT_POKE1);
10358 - local_flush_tlb();
10359 - sync_core();
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]);
10367 return addr;
10368 }
10369
10370 @@ -645,9 +635,9 @@ void *__kprobes text_poke_smp(void *addr
10371 #if defined(CONFIG_DYNAMIC_FTRACE) || defined(HAVE_JUMP_LABEL)
10372
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 };
10376 #else
10377 -unsigned char ideal_nop5[5] = { 0x3e, 0x8d, 0x74, 0x26, 0x00 };
10378 +unsigned char ideal_nop5[5] __read_only = { 0x3e, 0x8d, 0x74, 0x26, 0x00 };
10379 #endif
10380
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(
10386 }
10387 }
10388
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,
10399 GFP_KERNEL);
10400 if (!ioapic_entries)
10401 - return 0;
10402 + return NULL;
10403
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);
10409
10410 - return 0;
10411 + return NULL;
10412 }
10413
10414 /*
10415 @@ -1024,7 +1024,7 @@ int IO_APIC_get_PCI_irq_vector(int bus,
10416 }
10417 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
10418
10419 -void lock_vector_lock(void)
10420 +void lock_vector_lock(void) __acquires(vector_lock)
10421 {
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);
10426 }
10427
10428 -void unlock_vector_lock(void)
10429 +void unlock_vector_lock(void) __releases(vector_lock)
10430 {
10431 raw_spin_unlock(&vector_lock);
10432 }
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.
10439 */
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);
10443
10444 static const char driver_version[] = "1.16ac"; /* no spaces */
10445 @@ -588,7 +588,10 @@ static long __apm_bios_call(void *_call)
10446 BUG_ON(cpu != 0);
10447 gdt = get_cpu_gdt_table(cpu);
10448 save_desc_40 = gdt[0x40 / 8];
10449 +
10450 + pax_open_kernel();
10451 gdt[0x40 / 8] = bad_bios_desc;
10452 + pax_close_kernel();
10453
10454 apm_irq_save(flags);
10455 APM_DO_SAVE_SEGS;
10456 @@ -597,7 +600,11 @@ static long __apm_bios_call(void *_call)
10457 &call->esi);
10458 APM_DO_RESTORE_SEGS;
10459 apm_irq_restore(flags);
10460 +
10461 + pax_open_kernel();
10462 gdt[0x40 / 8] = save_desc_40;
10463 + pax_close_kernel();
10464 +
10465 put_cpu();
10466
10467 return call->eax & 0xff;
10468 @@ -664,7 +671,10 @@ static long __apm_bios_call_simple(void
10469 BUG_ON(cpu != 0);
10470 gdt = get_cpu_gdt_table(cpu);
10471 save_desc_40 = gdt[0x40 / 8];
10472 +
10473 + pax_open_kernel();
10474 gdt[0x40 / 8] = bad_bios_desc;
10475 + pax_close_kernel();
10476
10477 apm_irq_save(flags);
10478 APM_DO_SAVE_SEGS;
10479 @@ -672,7 +682,11 @@ static long __apm_bios_call_simple(void
10480 &call->eax);
10481 APM_DO_RESTORE_SEGS;
10482 apm_irq_restore(flags);
10483 +
10484 + pax_open_kernel();
10485 gdt[0x40 / 8] = save_desc_40;
10486 + pax_close_kernel();
10487 +
10488 put_cpu();
10489 return error;
10490 }
10491 @@ -975,7 +989,7 @@ recalc:
10492
10493 static void apm_power_off(void)
10494 {
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 = {
10502 APM_MINOR_DEV,
10503 "apm_bios",
10504 - &apm_bios_fops
10505 + &apm_bios_fops,
10506 + {NULL, NULL},
10507 + NULL,
10508 + NULL
10509 };
10510
10511
10512 @@ -2253,7 +2270,7 @@ static struct dmi_system_id __initdata a
10513 { DMI_MATCH(DMI_SYS_VENDOR, "IBM"), },
10514 },
10515
10516 - { }
10517 + { NULL, NULL, {DMI_MATCH(DMI_NONE, {0})}, NULL}
10518 };
10519
10520 /*
10521 @@ -2356,12 +2373,15 @@ static int __init apm_init(void)
10522 * code to that CPU.
10523 */
10524 gdt = get_cpu_gdt_table(0);
10525 +
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();
10534
10535 proc_create("apm", 0, NULL, &apm_file_ops);
10536
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);
10544 +
10545 +#ifdef CONFIG_PAX_KERNEXEC
10546 + OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
10547 +#endif
10548 +
10549 #endif
10550
10551 #ifdef CONFIG_XEN
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);
10559 +
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);
10563 +#endif
10564 +
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);
10569 +#endif
10570 +
10571 #endif
10572
10573
10574 @@ -115,6 +127,7 @@ int main(void)
10575 ENTRY(cr8);
10576 BLANK();
10577 #undef ENTRY
10578 + DEFINE(TSS_size, sizeof(struct tss_struct));
10579 DEFINE(TSS_ist, offsetof(struct tss_struct, x86_tss.ist));
10580 BLANK();
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
10586
10587 static const struct cpu_dev *this_cpu __cpuinitdata = &default_cpu;
10588
10589 -DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
10590 -#ifdef CONFIG_X86_64
10591 - /*
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
10595 - *
10596 - * TLS descriptors are currently at a different place compared to i386.
10597 - * Hopefully nobody expects them at a fixed place (Wine?)
10598 - */
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),
10605 -#else
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),
10610 - /*
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.
10614 - */
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),
10625 - /*
10626 - * The APM segments have byte granularity and their bases
10627 - * are set at run time. All have 64k limits.
10628 - */
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),
10633 - /* data */
10634 - [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
10635 -
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
10639 -#endif
10640 -} };
10641 -EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
10642 -
10643 static int __init x86_xsave_setup(char *s)
10644 {
10645 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
10646 @@ -352,7 +298,7 @@ void switch_to_new_gdt(int cpu)
10647 {
10648 struct desc_ptr gdt_descr;
10649
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);
10658
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);
10661 +#endif
10662 +
10663 /* If the model name is still unset, do table lookup. */
10664 if (!c->x86_model_id[0]) {
10665 const char *p;
10666 @@ -1085,7 +1035,7 @@ struct pt_regs * __cpuinit idle_regs(str
10667 {
10668 memset(regs, 0, sizeof(struct pt_regs));
10669 regs->fs = __KERNEL_PERCPU;
10670 - regs->gs = __KERNEL_STACK_CANARY;
10671 + savesegment(gs, regs->gs);
10672
10673 return regs;
10674 }
10675 @@ -1140,7 +1090,7 @@ void __cpuinit cpu_init(void)
10676 int i;
10677
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);
10682
10683 #ifdef CONFIG_NUMA
10684 @@ -1166,7 +1116,7 @@ void __cpuinit cpu_init(void)
10685 switch_to_new_gdt(cpu);
10686 loadsegment(fs, 0);
10687
10688 - load_idt((const struct desc_ptr *)&idt_descr);
10689 + load_idt(&idt_descr);
10690
10691 memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
10692 syscall_init();
10693 @@ -1175,7 +1125,6 @@ void __cpuinit cpu_init(void)
10694 wrmsrl(MSR_KERNEL_GS_BASE, 0);
10695 barrier();
10696
10697 - x86_configure_nx();
10698 if (cpu != 0)
10699 enable_x2apic();
10700
10701 @@ -1229,7 +1178,7 @@ void __cpuinit cpu_init(void)
10702 {
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;
10708
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"),
10715 },
10716 },
10717 - { }
10718 + { NULL, NULL, {DMI_MATCH(DMI_NONE, {0})}, NULL }
10719 };
10720
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 },
10728
10729 - { NULL, }
10730 + { NULL, NULL, 0, NULL}
10731 };
10732 #undef _BANIAS
10733 #undef BANIAS
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.
10740 */
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);
10744 }
10745 #endif
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
10751 endif
10752
10753 -# Make sure load_percpu_segment has no stackprotector
10754 -nostackp := $(call cc-option, -fno-stack-protector)
10755 -CFLAGS_common.o := $(nostackp)
10756 -
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!" : "",
10765 m->cs, m->ip);
10766
10767 - if (m->cs == __KERNEL_CS)
10768 + if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
10769 print_symbol("{%s}", m->ip);
10770 pr_cont("\n");
10771 }
10772 @@ -1460,14 +1460,14 @@ void __cpuinit mcheck_cpu_init(struct cp
10773 */
10774
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? */
10779
10780 static int mce_open(struct inode *inode, struct file *file)
10781 {
10782 spin_lock(&mce_state_lock);
10783
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);
10787
10788 return -EBUSY;
10789 @@ -1475,7 +1475,7 @@ static int mce_open(struct inode *inode,
10790
10791 if (file->f_flags & O_EXCL)
10792 open_exclu = 1;
10793 - open_count++;
10794 + atomic_inc(&open_count);
10795
10796 spin_unlock(&mce_state_lock);
10797
10798 @@ -1486,7 +1486,7 @@ static int mce_release(struct inode *ino
10799 {
10800 spin_lock(&mce_state_lock);
10801
10802 - open_count--;
10803 + atomic_dec(&open_count);
10804 open_exclu = 0;
10805
10806 spin_unlock(&mce_state_lock);
10807 @@ -1673,6 +1673,7 @@ static struct miscdevice mce_log_device
10808 MISC_MCELOG_MINOR,
10809 "mcelog",
10810 &mce_chrdev_ops,
10811 + {NULL, NULL}, NULL, NULL
10812 };
10813
10814 /*
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 */
10822 - {}
10823 + { 0, 0 }
10824 };
10825
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;
10833
10834 -static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
10835 +static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
10836
10837 const struct mtrr_ops *mtrr_if;
10838
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];
10844
10845 struct mtrr_ops {
10846 - u32 vendor;
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);
10855
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,
10861 int replace_reg);
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);
10867 };
10868
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 {
10874
10875 /* Interface defining a CPU specific perfctr watchdog */
10876 struct wd_ops {
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);
10887 unsigned perfctr;
10888 unsigned evntsel;
10889 u64 checkbit;
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
10893
10894 +/* cannot be const, see probe_nmi_watchdog */
10895 static struct wd_ops intel_arch_wd_ops;
10896
10897 static int setup_intel_arch_watchdog(unsigned nmi_hz)
10898 @@ -686,6 +687,7 @@ static int setup_intel_arch_watchdog(uns
10899 return 1;
10900 }
10901
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
10910 break;
10911
10912 perf_callchain_store(entry, frame.return_address);
10913 - fp = frame.next_frame;
10914 + fp = (__force const void __user *)frame.next_frame;
10915 }
10916 }
10917
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,
10922 regs = args->regs;
10923
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;
10929 }
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
10933 @@ -11,7 +11,7 @@
10934
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)
10939
10940 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
10941
10942 @@ -21,7 +21,7 @@ static void doublefault_fn(void)
10943 unsigned long gdt, tss;
10944
10945 store_gdt(&gdt_desc);
10946 - gdt = gdt_desc.address;
10947 + gdt = (unsigned long)gdt_desc.address;
10948
10949 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
10950
10951 @@ -58,10 +58,10 @@ struct tss_struct doublefault_tss __cach
10952 /* 0x2 bit is always set */
10953 .flags = X86_EFLAGS_SF | 0x2,
10954 .sp = STACK_START,
10955 - .es = __USER_DS,
10956 + .es = __KERNEL_DS,
10957 .cs = __KERNEL_CS,
10958 .ss = __KERNEL_DS,
10959 - .ds = __USER_DS,
10960 + .ds = __KERNEL_DS,
10961 .fs = __KERNEL_PERCPU,
10962
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..
10970 */
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;
10975 unsigned char c;
10976 u8 *ip;
10977 + unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(smp_processor_id())[(0xffff & regs->cs) >> 3]);
10978
10979 printk(KERN_EMERG "Stack:\n");
10980 show_stack_log_lvl(NULL, regs, &regs->sp,
10981 @@ -117,10 +118,10 @@ void show_registers(struct pt_regs *regs
10982
10983 printk(KERN_EMERG "Code: ");
10984
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;
10992 }
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.");
10996 break;
10997 }
10998 - if (ip == (u8 *)regs->ip)
10999 + if (ip == (u8 *)regs->ip + cs_base)
11000 printk("<%02x> ", c);
11001 else
11002 printk("%02x ", c);
11003 @@ -142,6 +143,7 @@ int is_valid_bugaddr(unsigned long ip)
11004 {
11005 unsigned short ud2;
11006
11007 + ip = ktla_ktva(ip);
11008 if (ip < PAGE_OFFSET)
11009 return 0;
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
11014 @@ -2,6 +2,9 @@
11015 * Copyright (C) 1991, 1992 Linus Torvalds
11016 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
11017 */
11018 +#ifdef CONFIG_GRKERNSEC_HIDESYM
11019 +#define __INCLUDED_BY_HIDESYM 1
11020 +#endif
11021 #include <linux/kallsyms.h>
11022 #include <linux/kprobes.h>
11023 #include <linux/uaccess.h>
11024 @@ -27,7 +30,7 @@ static int die_counter;
11025
11026 void printk_address(unsigned long address, int reliable)
11027 {
11028 - printk(" [<%p>] %s%pS\n", (void *) address,
11029 + printk(" [<%p>] %s%pA\n", (void *) address,
11030 reliable ? "" : "? ", (void *) address);
11031 }
11032
11033 @@ -206,7 +209,7 @@ void dump_stack(void)
11034 #endif
11035
11036 printk("Pid: %d, comm: %.20s %s %s %.*s\n",
11037 - current->pid, current->comm, print_tainted(),
11038 + task_pid_nr(current), current->comm, 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");
11044 if (panic_on_oops)
11045 panic("Fatal exception");
11046 - do_exit(signr);
11047 + do_group_exit(signr);
11048 }
11049
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
11052
11053 show_registers(regs);
11054 #ifdef CONFIG_X86_32
11055 - if (user_mode_vm(regs)) {
11056 + if (user_mode(regs)) {
11057 sp = regs->sp;
11058 ss = regs->ss & 0xffff;
11059 } else {
11060 @@ -317,7 +320,7 @@ void die(const char *str, struct pt_regs
11061 unsigned long flags = oops_begin();
11062 int sig = SIGSEGV;
11063
11064 - if (!user_mode_vm(regs))
11065 + if (!user_mode(regs))
11066 report_bug(regs->ip, regs);
11067
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*/
11074 .endm
11075 .macro SET_KERNEL_GS reg
11076 +
11077 +#ifdef CONFIG_CC_STACKPROTECTOR
11078 movl $(__KERNEL_STACK_CANARY), \reg
11079 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
11080 + movl $(__USER_DS), \reg
11081 +#else
11082 + xorl \reg, \reg
11083 +#endif
11084 +
11085 movl \reg, %gs
11086 .endm
11087
11088 #endif /* CONFIG_X86_32_LAZY_GS */
11089
11090 -.macro SAVE_ALL
11091 +.macro PAX_EXIT_KERNEL
11092 +#ifdef CONFIG_PAX_KERNEXEC
11093 +#ifdef CONFIG_PARAVIRT
11094 + push %eax; push %ecx
11095 +#endif
11096 + mov %cs, %esi
11097 + cmp $__KERNEXEC_KERNEL_CS, %esi
11098 + jnz 2f
11099 +#ifdef CONFIG_PARAVIRT
11100 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
11101 + mov %eax, %esi
11102 +#else
11103 + mov %cr0, %esi
11104 +#endif
11105 + btr $16, %esi
11106 + ljmp $__KERNEL_CS, $1f
11107 +1:
11108 +#ifdef CONFIG_PARAVIRT
11109 + mov %esi, %eax
11110 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
11111 +#else
11112 + mov %esi, %cr0
11113 +#endif
11114 +2:
11115 +#ifdef CONFIG_PARAVIRT
11116 + pop %ecx; pop %eax
11117 +#endif
11118 +#endif
11119 +.endm
11120 +
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)
11126 + mov %eax, %esi
11127 +#else
11128 + mov %cr0, %esi
11129 +#endif
11130 + bts $16, %esi
11131 + jnc 1f
11132 + mov %cs, %esi
11133 + cmp $__KERNEL_CS, %esi
11134 + jz 3f
11135 + ljmp $__KERNEL_CS, $3f
11136 +1: ljmp $__KERNEXEC_KERNEL_CS, $2f
11137 +2:
11138 +#ifdef CONFIG_PARAVIRT
11139 + mov %esi, %eax
11140 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
11141 +#else
11142 + mov %esi, %cr0
11143 +#endif
11144 +3:
11145 +#ifdef CONFIG_PARAVIRT
11146 + pop %ecx; pop %eax
11147 +#endif
11148 +#endif
11149 +.endm
11150 +
11151 +.macro __SAVE_ALL _DS
11152 cld
11153 PUSH_GS
11154 pushl_cfi %fs
11155 @@ -212,7 +280,7 @@
11156 CFI_REL_OFFSET ecx, 0
11157 pushl_cfi %ebx
11158 CFI_REL_OFFSET ebx, 0
11159 - movl $(__USER_DS), %edx
11160 + movl $\_DS, %edx
11161 movl %edx, %ds
11162 movl %edx, %es
11163 movl $(__KERNEL_PERCPU), %edx
11164 @@ -220,6 +288,15 @@
11165 SET_KERNEL_GS %edx
11166 .endm
11167
11168 +.macro SAVE_ALL
11169 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
11170 + __SAVE_ALL __KERNEL_DS
11171 + PAX_ENTER_KERNEL
11172 +#else
11173 + __SAVE_ALL __USER_DS
11174 +#endif
11175 +.endm
11176 +
11177 .macro RESTORE_INT_REGS
11178 popl_cfi %ebx
11179 CFI_RESTORE ebx
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
11184 +
11185 +#ifdef CONFIG_PAX_KERNEXEC
11186 + jae resume_userspace
11187 +
11188 + PAX_EXIT_KERNEL
11189 + jmp resume_kernel
11190 +#else
11191 jb resume_kernel # not returning to v8086 or userspace
11192 +#endif
11193
11194 ENTRY(resume_userspace)
11195 LOCKDEP_SYS_EXIT
11196 @@ -392,10 +477,9 @@ sysenter_past_esp:
11197 /*CFI_REL_OFFSET cs, 0*/
11198 /*
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.
11202 */
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
11207
11208 pushl_cfi %eax
11209 @@ -406,9 +490,19 @@ sysenter_past_esp:
11210 * Load the potential sixth argument from user stack.
11211 * Careful about security.
11212 */
11213 + movl PT_OLDESP(%esp),%ebp
11214 +
11215 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11216 + mov PT_OLDSS(%esp),%ds
11217 +1: movl %ds:(%ebp),%ebp
11218 + push %ss
11219 + pop %ds
11220 +#else
11221 cmpl $__PAGE_OFFSET-3,%ebp
11222 jae syscall_fault
11223 1: movl (%ebp),%ebp
11224 +#endif
11225 +
11226 movl %ebp,PT_EBP(%esp)
11227 .section __ex_table,"a"
11228 .align 4
11229 @@ -431,12 +525,23 @@ sysenter_do_call:
11230 testl $_TIF_ALLWORK_MASK, %ecx
11231 jne sysexit_audit
11232 sysenter_exit:
11233 +
11234 +#ifdef CONFIG_PAX_RANDKSTACK
11235 + pushl %eax
11236 + CFI_ADJUST_CFA_OFFSET 4
11237 + call pax_randomize_kstack
11238 + popl %eax
11239 + CFI_ADJUST_CFA_OFFSET -4
11240 +#endif
11241 +
11242 /* if something modifies registers it must also disable sysexit */
11243 movl PT_EIP(%esp), %edx
11244 movl PT_OLDESP(%esp), %ecx
11245 xorl %ebp,%ebp
11246 TRACE_IRQS_ON
11247 1: mov PT_FS(%esp), %fs
11248 +2: mov PT_DS(%esp), %ds
11249 +3: mov PT_ES(%esp), %es
11250 PTGS_TO_GS
11251 ENABLE_INTERRUPTS_SYSEXIT
11252
11253 @@ -479,11 +584,17 @@ sysexit_audit:
11254
11255 CFI_ENDPROC
11256 .pushsection .fixup,"ax"
11257 -2: movl $0,PT_FS(%esp)
11258 +4: movl $0,PT_FS(%esp)
11259 + jmp 1b
11260 +5: movl $0,PT_DS(%esp)
11261 + jmp 1b
11262 +6: movl $0,PT_ES(%esp)
11263 jmp 1b
11264 .section __ex_table,"a"
11265 .align 4
11266 - .long 1b,2b
11267 + .long 1b,4b
11268 + .long 2b,5b
11269 + .long 3b,6b
11270 .popsection
11271 PTGS_TO_GS_EX
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
11276
11277 +#ifdef CONFIG_PAX_RANDKSTACK
11278 + call pax_randomize_kstack
11279 +#endif
11280 +
11281 restore_all:
11282 TRACE_IRQS_IRET
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.
11287 */
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) */
11294 +#ifdef CONFIG_SMP
11295 + movl PER_CPU_VAR(cpu_number), %ebx
11296 + shll $PAGE_SHIFT_asm, %ebx
11297 + addl $cpu_gdt_table, %ebx
11298 +#else
11299 + movl $cpu_gdt_table, %ebx
11300 +#endif
11301 shr $16, %edx
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:
11310
11311 work_notifysig: # deal with pending signals and
11312 # notify-resume requests
11313 + movl %esp, %eax
11314 #ifdef CONFIG_VM86
11315 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
11316 - movl %esp, %eax
11317 - jne work_notifysig_v86 # returning to kernel-space or
11318 + jz 1f # returning to kernel-space or
11319 # vm86-space
11320 - xorl %edx, %edx
11321 - call do_notify_resume
11322 - jmp resume_userspace_sig
11323
11324 - ALIGN
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
11328 popl_cfi %ecx
11329 movl %eax, %esp
11330 -#else
11331 - movl %esp, %eax
11332 +1:
11333 #endif
11334 xorl %edx, %edx
11335 call do_notify_resume
11336 @@ -668,6 +784,10 @@ END(syscall_exit_work)
11337
11338 RING0_INT_FRAME # can't unwind into user space anyway
11339 syscall_fault:
11340 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11341 + push %ss
11342 + pop %ds
11343 +#endif
11344 GET_THREAD_INFO(%ebp)
11345 movl $-EFAULT,PT_EAX(%esp)
11346 jmp resume_userspace
11347 @@ -750,6 +870,36 @@ ptregs_clone:
11348 CFI_ENDPROC
11349 ENDPROC(ptregs_clone)
11350
11351 + ALIGN;
11352 +ENTRY(kernel_execve)
11353 + CFI_STARTPROC
11354 + pushl_cfi %ebp
11355 + sub $PT_OLDSS+4,%esp
11356 + pushl_cfi %edi
11357 + pushl_cfi %ecx
11358 + pushl_cfi %eax
11359 + lea 3*4(%esp),%edi
11360 + mov $PT_OLDSS/4+1,%ecx
11361 + xorl %eax,%eax
11362 + rep stosl
11363 + popl_cfi %eax
11364 + popl_cfi %ecx
11365 + popl_cfi %edi
11366 + movl $X86_EFLAGS_IF,PT_EFLAGS(%esp)
11367 + pushl_cfi %esp
11368 + call sys_execve
11369 + add $4,%esp
11370 + CFI_ADJUST_CFA_OFFSET -4
11371 + GET_THREAD_INFO(%ebp)
11372 + test %eax,%eax
11373 + jz syscall_exit
11374 + add $PT_OLDSS+4,%esp
11375 + CFI_ADJUST_CFA_OFFSET -PT_OLDSS-4
11376 + popl_cfi %ebp
11377 + ret
11378 + CFI_ENDPROC
11379 +ENDPROC(kernel_execve)
11380 +
11381 .macro FIXUP_ESPFIX_STACK
11382 /*
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.
11386 */
11387 /* fixup the stack */
11388 - mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
11389 - mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
11390 +#ifdef CONFIG_SMP
11391 + movl PER_CPU_VAR(cpu_number), %ebx
11392 + shll $PAGE_SHIFT_asm, %ebx
11393 + addl $cpu_gdt_table, %ebx
11394 +#else
11395 + movl $cpu_gdt_table, %ebx
11396 +#endif
11397 + mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
11398 + mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
11399 shl $16, %eax
11400 addl %esp, %eax /* the adjusted stack pointer */
11401 pushl_cfi $__KERNEL_DS
11402 @@ -1211,7 +1368,6 @@ return_to_handler:
11403 jmp *%ecx
11404 #endif
11405
11406 -.section .rodata,"a"
11407 #include "syscall_table_32.S"
11408
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
11412 REG_TO_PTGS %ecx
11413 SET_KERNEL_GS %ecx
11414 - movl $(__USER_DS), %ecx
11415 + movl $(__KERNEL_DS), %ecx
11416 movl %ecx, %ds
11417 movl %ecx, %es
11418 +
11419 + PAX_ENTER_KERNEL
11420 +
11421 TRACE_IRQS_OFF
11422 movl %esp,%eax # pt_regs pointer
11423 call *%edi
11424 @@ -1344,6 +1503,9 @@ nmi_stack_correct:
11425 xorl %edx,%edx # zero error code
11426 movl %esp,%eax # pt_regs pointer
11427 call do_nmi
11428 +
11429 + PAX_EXIT_KERNEL
11430 +
11431 jmp restore_all_notrace
11432 CFI_ENDPROC
11433
11434 @@ -1380,6 +1542,9 @@ nmi_espfix_stack:
11435 FIXUP_ESPFIX_STACK # %eax == %esp
11436 xorl %edx,%edx # zero error code
11437 call do_nmi
11438 +
11439 + PAX_EXIT_KERNEL
11440 +
11441 RESTORE_REGS
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
11447 @@ -53,6 +53,7 @@
11448 #include <asm/paravirt.h>
11449 #include <asm/ftrace.h>
11450 #include <asm/percpu.h>
11451 +#include <asm/pgtable.h>
11452
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 */
11458
11459 + .macro ljmpq sel, off
11460 +#if defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
11461 + .byte 0x48; ljmp *1234f(%rip)
11462 + .pushsection .rodata
11463 + .align 16
11464 + 1234: .quad \off; .word \sel
11465 + .popsection
11466 +#else
11467 + push $\sel
11468 + push $\off
11469 + lretq
11470 +#endif
11471 + .endm
11472 +
11473 +ENTRY(pax_enter_kernel)
11474 +
11475 +#ifdef CONFIG_PAX_KERNEXEC
11476 + push %rdi
11477 +
11478 +#ifdef CONFIG_PARAVIRT
11479 + PV_SAVE_REGS(CLBR_RDI)
11480 +#endif
11481 +
11482 + GET_CR0_INTO_RDI
11483 + bts $16,%rdi
11484 + jnc 1f
11485 + mov %cs,%edi
11486 + cmp $__KERNEL_CS,%edi
11487 + jz 3f
11488 + ljmpq __KERNEL_CS,3f
11489 +1: ljmpq __KERNEXEC_KERNEL_CS,2f
11490 +2: SET_RDI_INTO_CR0
11491 +3:
11492 +
11493 +#ifdef CONFIG_PARAVIRT
11494 + PV_RESTORE_REGS(CLBR_RDI)
11495 +#endif
11496 +
11497 + pop %rdi
11498 +#endif
11499 +
11500 + retq
11501 +ENDPROC(pax_enter_kernel)
11502 +
11503 +ENTRY(pax_exit_kernel)
11504 +
11505 +#ifdef CONFIG_PAX_KERNEXEC
11506 + push %rdi
11507 +
11508 +#ifdef CONFIG_PARAVIRT
11509 + PV_SAVE_REGS(CLBR_RDI)
11510 +#endif
11511 +
11512 + mov %cs,%rdi
11513 + cmp $__KERNEXEC_KERNEL_CS,%edi
11514 + jnz 2f
11515 + GET_CR0_INTO_RDI
11516 + btr $16,%rdi
11517 + ljmpq __KERNEL_CS,1f
11518 +1: SET_RDI_INTO_CR0
11519 +2:
11520 +
11521 +#ifdef CONFIG_PARAVIRT
11522 + PV_RESTORE_REGS(CLBR_RDI);
11523 +#endif
11524 +
11525 + pop %rdi
11526 +#endif
11527 +
11528 + retq
11529 +ENDPROC(pax_exit_kernel)
11530 +
11531 +ENTRY(pax_enter_kernel_user)
11532 +
11533 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11534 + push %rdi
11535 + push %rbx
11536 +
11537 +#ifdef CONFIG_PARAVIRT
11538 + PV_SAVE_REGS(CLBR_RDI)
11539 +#endif
11540 +
11541 + GET_CR3_INTO_RDI
11542 + mov %rdi,%rbx
11543 + add $__START_KERNEL_map,%rbx
11544 + sub phys_base(%rip),%rbx
11545 +
11546 +#ifdef CONFIG_PARAVIRT
11547 + push %rdi
11548 + cmpl $0, pv_info+PARAVIRT_enabled
11549 + jz 1f
11550 + i = 0
11551 + .rept USER_PGD_PTRS
11552 + mov i*8(%rbx),%rsi
11553 + mov $0,%sil
11554 + lea i*8(%rbx),%rdi
11555 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd)
11556 + i = i + 1
11557 + .endr
11558 + jmp 2f
11559 +1:
11560 +#endif
11561 +
11562 + i = 0
11563 + .rept USER_PGD_PTRS
11564 + movb $0,i*8(%rbx)
11565 + i = i + 1
11566 + .endr
11567 +
11568 +#ifdef CONFIG_PARAVIRT
11569 +2: pop %rdi
11570 +#endif
11571 + SET_RDI_INTO_CR3
11572 +
11573 +#ifdef CONFIG_PAX_KERNEXEC
11574 + GET_CR0_INTO_RDI
11575 + bts $16,%rdi
11576 + SET_RDI_INTO_CR0
11577 +#endif
11578 +
11579 +#ifdef CONFIG_PARAVIRT
11580 + PV_RESTORE_REGS(CLBR_RDI)
11581 +#endif
11582 +
11583 + pop %rbx
11584 + pop %rdi
11585 +#endif
11586 +
11587 + retq
11588 +ENDPROC(pax_enter_kernel_user)
11589 +
11590 +ENTRY(pax_exit_kernel_user)
11591 +
11592 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11593 + push %rdi
11594 +
11595 +#ifdef CONFIG_PARAVIRT
11596 + push %rbx
11597 + PV_SAVE_REGS(CLBR_RDI)
11598 +#endif
11599 +
11600 +#ifdef CONFIG_PAX_KERNEXEC
11601 + GET_CR0_INTO_RDI
11602 + btr $16,%rdi
11603 + SET_RDI_INTO_CR0
11604 +#endif
11605 +
11606 + GET_CR3_INTO_RDI
11607 + add $__START_KERNEL_map,%rdi
11608 + sub phys_base(%rip),%rdi
11609 +
11610 +#ifdef CONFIG_PARAVIRT
11611 + cmpl $0, pv_info+PARAVIRT_enabled
11612 + jz 1f
11613 + mov %rdi,%rbx
11614 + i = 0
11615 + .rept USER_PGD_PTRS
11616 + mov i*8(%rbx),%rsi
11617 + mov $0x67,%sil
11618 + lea i*8(%rbx),%rdi
11619 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd)
11620 + i = i + 1
11621 + .endr
11622 + jmp 2f
11623 +1:
11624 +#endif
11625 +
11626 + i = 0
11627 + .rept USER_PGD_PTRS
11628 + movb $0x67,i*8(%rdi)
11629 + i = i + 1
11630 + .endr
11631 +
11632 +#ifdef CONFIG_PARAVIRT
11633 +2: PV_RESTORE_REGS(CLBR_RDI)
11634 + pop %rbx
11635 +#endif
11636 +
11637 + pop %rdi
11638 +#endif
11639 +
11640 + retq
11641 +ENDPROC(pax_exit_kernel_user)
11642
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)
11651 je 1f
11652 SWAPGS
11653 /*
11654 @@ -403,7 +587,7 @@ ENTRY(ret_from_fork)
11655
11656 RESTORE_REST
11657
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
11661
11662 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
11663 @@ -462,6 +646,11 @@ ENTRY(system_call_after_swapgs)
11664
11665 movq %rsp,PER_CPU_VAR(old_rsp)
11666 movq PER_CPU_VAR(kernel_stack),%rsp
11667 +
11668 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11669 + call pax_enter_kernel_user
11670 +#endif
11671 +
11672 /*
11673 * No need to follow this irqs off/on section - it's straight
11674 * and short:
11675 @@ -496,6 +685,11 @@ sysret_check:
11676 andl %edi,%edx
11677 jnz sysret_careful
11678 CFI_REMEMBER_STATE
11679 +
11680 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11681 + call pax_exit_kernel_user
11682 +#endif
11683 +
11684 /*
11685 * sysretq will re-enable interrupts:
11686 */
11687 @@ -605,7 +799,7 @@ tracesys:
11688 GLOBAL(int_ret_from_sys_call)
11689 DISABLE_INTERRUPTS(CLBR_NONE)
11690 TRACE_IRQS_OFF
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
11698 call save_args
11699 PARTIAL_FRAME 0
11700 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11701 + testb $3, CS(%rdi)
11702 + jnz 1f
11703 + call pax_enter_kernel
11704 + jmp 2f
11705 +1: call pax_enter_kernel_user
11706 +2:
11707 +#else
11708 + call pax_enter_kernel
11709 +#endif
11710 call \func
11711 .endm
11712
11713 @@ -813,7 +1017,7 @@ ret_from_intr:
11714 CFI_ADJUST_CFA_OFFSET -8
11715 exit_intr:
11716 GET_THREAD_INFO(%rcx)
11717 - testl $3,CS-ARGOFFSET(%rsp)
11718 + testb $3,CS-ARGOFFSET(%rsp)
11719 je retint_kernel
11720
11721 /* Interrupt came from user space */
11722 @@ -835,12 +1039,18 @@ retint_swapgs: /* return to user-space
11723 * The iretq could re-enable interrupts:
11724 */
11725 DISABLE_INTERRUPTS(CLBR_ANY)
11726 +
11727 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11728 + call pax_exit_kernel_user
11729 +#endif
11730 +
11731 TRACE_IRQS_IRETQ
11732 SWAPGS
11733 jmp restore_args
11734
11735 retint_restore_args: /* return to kernel space */
11736 DISABLE_INTERRUPTS(CLBR_ANY)
11737 + call pax_exit_kernel
11738 /*
11739 * The iretq could re-enable interrupts:
11740 */
11741 @@ -1012,6 +1222,16 @@ ENTRY(\sym)
11742 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
11743 call error_entry
11744 DEFAULT_FRAME 0
11745 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11746 + testb $3, CS(%rsp)
11747 + jnz 1f
11748 + call pax_enter_kernel
11749 + jmp 2f
11750 +1: call pax_enter_kernel_user
11751 +2:
11752 +#else
11753 + call pax_enter_kernel
11754 +#endif
11755 movq %rsp,%rdi /* pt_regs pointer */
11756 xorl %esi,%esi /* no error code */
11757 call \do_sym
11758 @@ -1029,6 +1249,16 @@ ENTRY(\sym)
11759 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
11760 call save_paranoid
11761 TRACE_IRQS_OFF
11762 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11763 + testb $3, CS(%rsp)
11764 + jnz 1f
11765 + call pax_enter_kernel
11766 + jmp 2f
11767 +1: call pax_enter_kernel_user
11768 +2:
11769 +#else
11770 + call pax_enter_kernel
11771 +#endif
11772 movq %rsp,%rdi /* pt_regs pointer */
11773 xorl %esi,%esi /* no error code */
11774 call \do_sym
11775 @@ -1037,7 +1267,7 @@ ENTRY(\sym)
11776 END(\sym)
11777 .endm
11778
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
11782 ENTRY(\sym)
11783 INTR_FRAME
11784 @@ -1047,8 +1277,24 @@ ENTRY(\sym)
11785 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
11786 call save_paranoid
11787 TRACE_IRQS_OFF
11788 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11789 + testb $3, CS(%rsp)
11790 + jnz 1f
11791 + call pax_enter_kernel
11792 + jmp 2f
11793 +1: call pax_enter_kernel_user
11794 +2:
11795 +#else
11796 + call pax_enter_kernel
11797 +#endif
11798 movq %rsp,%rdi /* pt_regs pointer */
11799 xorl %esi,%esi /* no error code */
11800 +#ifdef CONFIG_SMP
11801 + imul $TSS_size, PER_CPU_VAR(cpu_number), %r12d
11802 + lea init_tss(%r12), %r12
11803 +#else
11804 + lea init_tss(%rip), %r12
11805 +#endif
11806 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
11807 call \do_sym
11808 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
11809 @@ -1065,6 +1311,16 @@ ENTRY(\sym)
11810 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
11811 call error_entry
11812 DEFAULT_FRAME 0
11813 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11814 + testb $3, CS(%rsp)
11815 + jnz 1f
11816 + call pax_enter_kernel
11817 + jmp 2f
11818 +1: call pax_enter_kernel_user
11819 +2:
11820 +#else
11821 + call pax_enter_kernel
11822 +#endif
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)
11827 call save_paranoid
11828 DEFAULT_FRAME 0
11829 TRACE_IRQS_OFF
11830 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11831 + testb $3, CS(%rsp)
11832 + jnz 1f
11833 + call pax_enter_kernel
11834 + jmp 2f
11835 +1: call pax_enter_kernel_user
11836 +2:
11837 +#else
11838 + call pax_enter_kernel
11839 +#endif
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)
11844 TRACE_IRQS_OFF
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
11854 + RESTORE_ALL 8
11855 + jmp irq_return
11856 +#endif
11857 paranoid_swapgs:
11858 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11859 + call pax_exit_kernel_user
11860 +#else
11861 + call pax_exit_kernel
11862 +#endif
11863 TRACE_IRQS_IRETQ 0
11864 SWAPGS_UNSAFE_STACK
11865 RESTORE_ALL 8
11866 jmp irq_return
11867 paranoid_restore:
11868 + call pax_exit_kernel
11869 TRACE_IRQS_IRETQ 0
11870 RESTORE_ALL 8
11871 jmp irq_return
11872 @@ -1408,7 +1687,7 @@ ENTRY(error_entry)
11873 movq_cfi r14, R14+8
11874 movq_cfi r15, R15+8
11875 xorl %ebx,%ebx
11876 - testl $3,CS+8(%rsp)
11877 + testb $3,CS+8(%rsp)
11878 je error_kernelspace
11879 error_swapgs:
11880 SWAPGS
11881 @@ -1472,6 +1751,16 @@ ENTRY(nmi)
11882 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
11883 call save_paranoid
11884 DEFAULT_FRAME 0
11885 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11886 + testb $3, CS(%rsp)
11887 + jnz 1f
11888 + call pax_enter_kernel
11889 + jmp 2f
11890 +1: call pax_enter_kernel_user
11891 +2:
11892 +#else
11893 + call pax_enter_kernel
11894 +#endif
11895 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
11896 movq %rsp,%rdi
11897 movq $-1,%rsi
11898 @@ -1482,11 +1771,12 @@ ENTRY(nmi)
11899 DISABLE_INTERRUPTS(CLBR_NONE)
11900 testl %ebx,%ebx /* swapgs needed? */
11901 jnz nmi_restore
11902 - testl $3,CS(%rsp)
11903 + testb $3,CS(%rsp)
11904 jnz nmi_userspace
11905 nmi_swapgs:
11906 SWAPGS_UNSAFE_STACK
11907 nmi_restore:
11908 + call pax_exit_kernel
11909 RESTORE_ALL 8
11910 jmp irq_return
11911 nmi_userspace:
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)
11916
11917 if (atomic_inc_return(&nmi_running) & MOD_CODE_WRITE_FLAG) {
11918 smp_rmb();
11919 + pax_open_kernel();
11920 ftrace_mod_code();
11921 + pax_close_kernel();
11922 atomic_inc(&nmi_update_count);
11923 }
11924 /* Must have previous changes seen before executions */
11925 @@ -268,6 +270,8 @@ ftrace_modify_code(unsigned long ip, uns
11926 {
11927 unsigned char replaced[MCOUNT_INSN_SIZE];
11928
11929 + ip = ktla_ktva(ip);
11930 +
11931 /*
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;
11936 int ret;
11937
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);
11942
11943 @@ -350,6 +354,8 @@ static int ftrace_mod_jmp(unsigned long
11944 {
11945 unsigned char code[MCOUNT_INSN_SIZE];
11946
11947 + ip = ktla_ktva(ip);
11948 +
11949 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
11950 return -EFAULT;
11951
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
11955 @@ -19,6 +19,7 @@
11956 #include <asm/io_apic.h>
11957 #include <asm/bios_ebda.h>
11958 #include <asm/tlbflush.h>
11959 +#include <asm/boot.h>
11960
11961 static void __init i386_default_early_setup(void)
11962 {
11963 @@ -43,7 +44,7 @@ void __init i386_start_kernel(void)
11964 memblock_x86_reserve_range(PAGE_SIZE, PAGE_SIZE + PAGE_SIZE, "EX TRAMPOLINE");
11965 #endif
11966
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");
11969
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
11975 @@ -25,6 +25,12 @@
11976 /* Physical address */
11977 #define pa(X) ((X) - __PAGE_OFFSET)
11978
11979 +#ifdef CONFIG_PAX_KERNEXEC
11980 +#define ta(X) (X)
11981 +#else
11982 +#define ta(X) ((X) - __PAGE_OFFSET)
11983 +#endif
11984 +
11985 /*
11986 * References to members of the new_cpu_data structure.
11987 */
11988 @@ -54,11 +60,7 @@
11989 * and small than max_low_pfn, otherwise will waste some page table entries
11990 */
11991
11992 -#if PTRS_PER_PMD > 1
11993 -#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
11994 -#else
11995 -#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
11996 -#endif
11997 +#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
11998
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)
12003
12004 /*
12005 + * Real beginning of normal "text" segment
12006 + */
12007 +ENTRY(stext)
12008 +ENTRY(_stext)
12009 +
12010 +/*
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)
12015 * can.
12016 */
12017 __HEAD
12018 +
12019 +#ifdef CONFIG_PAX_KERNEXEC
12020 + jmp startup_32
12021 +/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
12022 +.fill PAGE_SIZE-5,1,0xcc
12023 +#endif
12024 +
12025 ENTRY(startup_32)
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)
12029 movl %eax,%gs
12030 2:
12031
12032 +#ifdef CONFIG_SMP
12033 + movl $pa(cpu_gdt_table),%edi
12034 + movl $__per_cpu_load,%eax
12035 + movw %ax,__KERNEL_PERCPU + 2(%edi)
12036 + rorl $16,%eax
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)
12042 +#endif
12043 +
12044 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12045 + movl $NR_CPUS,%ecx
12046 + movl $pa(cpu_gdt_table),%edi
12047 +1:
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
12052 + loop 1b
12053 +#endif
12054 +
12055 +#ifdef CONFIG_PAX_KERNEXEC
12056 + movl $pa(boot_gdt),%edi
12057 + movl $__LOAD_PHYSICAL_ADDR,%eax
12058 + movw %ax,__BOOT_CS + 2(%edi)
12059 + rorl $16,%eax
12060 + movb %al,__BOOT_CS + 4(%edi)
12061 + movb %ah,__BOOT_CS + 7(%edi)
12062 + rorl $16,%eax
12063 +
12064 + ljmp $(__BOOT_CS),$1f
12065 +1:
12066 +
12067 + movl $NR_CPUS,%ecx
12068 + movl $pa(cpu_gdt_table),%edi
12069 + addl $__PAGE_OFFSET,%eax
12070 +1:
12071 + movw %ax,__KERNEL_CS + 2(%edi)
12072 + movw %ax,__KERNEXEC_KERNEL_CS + 2(%edi)
12073 + rorl $16,%eax
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)
12078 + rorl $16,%eax
12079 + addl $PAGE_SIZE_asm,%edi
12080 + loop 1b
12081 +#endif
12082 +
12083 /*
12084 * Clear BSS first so that there are no surprises...
12085 */
12086 @@ -150,9 +216,7 @@ ENTRY(startup_32)
12087 cmpl $num_subarch_entries, %eax
12088 jae bad_subarch
12089
12090 - movl pa(subarch_entries)(,%eax,4), %eax
12091 - subl $__PAGE_OFFSET, %eax
12092 - jmp *%eax
12093 + jmp *pa(subarch_entries)(,%eax,4)
12094
12095 bad_subarch:
12096 WEAK(lguest_entry)
12097 @@ -164,10 +228,10 @@ WEAK(xen_entry)
12098 __INITDATA
12099
12100 subarch_entries:
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
12110 .previous
12111 #endif /* CONFIG_PARAVIRT */
12112 @@ -227,8 +291,11 @@ default_entry:
12113 movl %eax, pa(max_pfn_mapped)
12114
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)
12120 +#else
12121 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
12122 +#endif
12123 #else /* Not PAE */
12124
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)
12128
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)
12134 +#else
12135 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
12136 +#endif
12137 #endif
12138 jmp 3f
12139 /*
12140 @@ -306,6 +376,7 @@ ENTRY(startup_32_smp)
12141 orl %edx,%eax
12142 movl %eax,%cr4
12143
12144 +#ifdef CONFIG_X86_PAE
12145 testb $X86_CR4_PAE, %al # check if PAE is enabled
12146 jz 6f
12147
12148 @@ -330,6 +401,9 @@ ENTRY(startup_32_smp)
12149 /* Make changes effective */
12150 wrmsr
12151
12152 + btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
12153 +#endif
12154 +
12155 6:
12156
12157 /*
12158 @@ -355,9 +429,7 @@ ENTRY(startup_32_smp)
12159
12160 #ifdef CONFIG_SMP
12161 cmpb $0, ready
12162 - jz 1f /* Initial CPU cleans BSS */
12163 - jmp checkCPUtype
12164 -1:
12165 + jnz checkCPUtype /* Initial CPU cleans BSS */
12166 #endif /* CONFIG_SMP */
12167
12168 /*
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.
12172
12173 - movl $(__USER_DS),%eax # DS/ES contains default USER segment
12174 +# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
12175 movl %eax,%ds
12176 movl %eax,%es
12177
12178 @@ -449,15 +521,22 @@ is386: movl $2,%ecx # set MP
12179 */
12180 cmpb $0,ready
12181 jne 1f
12182 - movl $gdt_page,%eax
12183 + movl $cpu_gdt_table,%eax
12184 movl $stack_canary,%ecx
12185 +#ifdef CONFIG_SMP
12186 + addl $__per_cpu_load,%ecx
12187 +#endif
12188 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
12189 shrl $16, %ecx
12190 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
12191 movb %ch, 8 * GDT_ENTRY_STACK_CANARY + 7(%eax)
12192 1:
12193 -#endif
12194 movl $(__KERNEL_STACK_CANARY),%eax
12195 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
12196 + movl $(__USER_DS),%eax
12197 +#else
12198 + xorl %eax,%eax
12199 +#endif
12200 movl %eax,%gs
12201
12202 xorl %eax,%eax # Clear LDT
12203 @@ -468,10 +547,6 @@ is386: movl $2,%ecx # set MP
12204 #ifdef CONFIG_SMP
12205 movb ready, %cl
12206 movb $1, ready
12207 - cmpb $0,%cl # the first CPU calls start_kernel
12208 - je 1f
12209 - movl (stack_start), %esp
12210 -1:
12211 #endif /* CONFIG_SMP */
12212 jmp *(initial_code)
12213
12214 @@ -557,22 +632,22 @@ early_page_fault:
12215 jmp early_fault
12216
12217 early_fault:
12218 - cld
12219 #ifdef CONFIG_PRINTK
12220 + cmpl $1,%ss:early_recursion_flag
12221 + je hlt_loop
12222 + incl %ss:early_recursion_flag
12223 + cld
12224 pusha
12225 movl $(__KERNEL_DS),%eax
12226 movl %eax,%ds
12227 movl %eax,%es
12228 - cmpl $2,early_recursion_flag
12229 - je hlt_loop
12230 - incl early_recursion_flag
12231 movl %cr2,%eax
12232 pushl %eax
12233 pushl %edx /* trapno */
12234 pushl $fault_msg
12235 call printk
12236 +; call dump_stack
12237 #endif
12238 - call dump_stack
12239 hlt_loop:
12240 hlt
12241 jmp hlt_loop
12242 @@ -580,8 +655,11 @@ hlt_loop:
12243 /* This is the default interrupt "handler" :-) */
12244 ALIGN
12245 ignore_int:
12246 - cld
12247 #ifdef CONFIG_PRINTK
12248 + cmpl $2,%ss:early_recursion_flag
12249 + je hlt_loop
12250 + incl %ss:early_recursion_flag
12251 + cld
12252 pushl %eax
12253 pushl %ecx
12254 pushl %edx
12255 @@ -590,9 +668,6 @@ ignore_int:
12256 movl $(__KERNEL_DS),%eax
12257 movl %eax,%ds
12258 movl %eax,%es
12259 - cmpl $2,early_recursion_flag
12260 - je hlt_loop
12261 - incl early_recursion_flag
12262 pushl 16(%esp)
12263 pushl 24(%esp)
12264 pushl 32(%esp)
12265 @@ -619,29 +694,42 @@ ENTRY(initial_code)
12266 /*
12267 * BSS section
12268 */
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
12275 #else
12276 ENTRY(initial_page_table)
12277 .fill 1024,4,0
12278 #endif
12279 +.section .initial_pg_fixmap,"a",@progbits
12280 ENTRY(initial_pg_fixmap)
12281 .fill 1024,4,0
12282 +.section .empty_zero_page,"a",@progbits
12283 ENTRY(empty_zero_page)
12284 .fill 4096,1,0
12285 +.section .swapper_pg_dir,"a",@progbits
12286 ENTRY(swapper_pg_dir)
12287 +#ifdef CONFIG_X86_PAE
12288 + .fill 4,8,0
12289 +#else
12290 .fill 1024,4,0
12291 +#endif
12292 +
12293 +/*
12294 + * The IDT has to be page-aligned to simplify the Pentium
12295 + * F0 0F bug workaround.. We have a special link segment
12296 + * for this.
12297 + */
12298 +.section .idt,"a",@progbits
12299 +ENTRY(idt_table)
12300 + .fill 256,8,0
12301
12302 /*
12303 * This starts the data section.
12304 */
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 */
12312 # if KPMDS == 3
12313 @@ -660,15 +748,24 @@ ENTRY(initial_page_table)
12314 # error "Kernel PMDs should be 1, 2 or 3"
12315 # endif
12316 .align PAGE_SIZE_asm /* needs to be page-sized too */
12317 +
12318 +#ifdef CONFIG_PAX_PER_CPU_PGD
12319 +ENTRY(cpu_pgd)
12320 + .rept NR_CPUS
12321 + .fill 4,8,0
12322 + .endr
12323 +#endif
12324 +
12325 #endif
12326
12327 .data
12328 ENTRY(stack_start)
12329 - .long init_thread_union+THREAD_SIZE
12330 + .long init_thread_union+THREAD_SIZE-8
12331 .long __BOOT_DS
12332
12333 ready: .byte 0
12334
12335 +.section .rodata,"a",@progbits
12336 early_recursion_flag:
12337 .long 0
12338
12339 @@ -704,7 +801,7 @@ fault_msg:
12340 .word 0 # 32 bit align gdt_desc.address
12341 boot_gdt_descr:
12342 .word __BOOT_DS+7
12343 - .long boot_gdt - __PAGE_OFFSET
12344 + .long pa(boot_gdt)
12345
12346 .word 0 # 32-bit align idt_desc.address
12347 idt_descr:
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 */
12354
12355 /*
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
12359 ENTRY(boot_gdt)
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 */
12365 +
12366 + .align PAGE_SIZE_asm
12367 +ENTRY(cpu_gdt_table)
12368 + .rept NR_CPUS
12369 + .quad 0x0000000000000000 /* NULL descriptor */
12370 + .quad 0x0000000000000000 /* 0x0b reserved */
12371 + .quad 0x0000000000000000 /* 0x13 reserved */
12372 + .quad 0x0000000000000000 /* 0x1b reserved */
12373 +
12374 +#ifdef CONFIG_PAX_KERNEXEC
12375 + .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
12376 +#else
12377 + .quad 0x0000000000000000 /* 0x20 unused */
12378 +#endif
12379 +
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 */
12387 +
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 */
12392 +
12393 + .quad 0x0000000000000000 /* 0x80 TSS descriptor */
12394 + .quad 0x0000000000000000 /* 0x88 LDT descriptor */
12395 +
12396 + /*
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.
12400 + */
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 */
12406 +
12407 + /*
12408 + * The APM segments have byte granularity and their bases
12409 + * are set at run time. All have 64k limits.
12410 + */
12411 + .quad 0x00409b000000ffff /* 0xb8 APM CS code */
12412 + .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
12413 + .quad 0x004093000000ffff /* 0xc8 APM DS data */
12414 +
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 */
12421 +
12422 + /* Be sure this is zeroed to avoid false validations in Xen */
12423 + .fill PAGE_SIZE_asm - GDT_SIZE,1,0
12424 + .endr
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
12428 @@ -19,6 +19,7 @@
12429 #include <asm/cache.h>
12430 #include <asm/processor-flags.h>
12431 #include <asm/percpu.h>
12432 +#include <asm/cpufeature.h>
12433
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)
12444
12445 .text
12446 __HEAD
12447 @@ -85,35 +90,22 @@ startup_64:
12448 */
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)
12454
12455 addq %rbp, level3_ident_pgt + 0(%rip)
12456 +#ifndef CONFIG_XEN
12457 + addq %rbp, level3_ident_pgt + 8(%rip)
12458 +#endif
12459
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)
12463
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)
12467
12468 - /* Add an Identity mapping if I am above 1G */
12469 - leaq _text(%rip), %rdi
12470 - andq $PMD_PAGE_MASK, %rdi
12471 -
12472 - movq %rdi, %rax
12473 - shrq $PUD_SHIFT, %rax
12474 - andq $(PTRS_PER_PUD - 1), %rax
12475 - jz ident_complete
12476 -
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)
12480 -
12481 - movq %rdi, %rax
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)
12487 -ident_complete:
12488 + addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
12489 + addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
12490
12491 /*
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.
12495 */
12496
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
12501 movq %rax, %cr4
12502
12503 /* Setup early boot stage 4 level pagetables. */
12504 @@ -184,9 +176,14 @@ ENTRY(secondary_startup_64)
12505 movl $MSR_EFER, %ecx
12506 rdmsr
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? */
12510 jnc 1f
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 */
12518
12519 /* Setup cr0 */
12520 @@ -270,7 +267,7 @@ ENTRY(secondary_startup_64)
12521 bad_address:
12522 jmp bad_address
12523
12524 - .section ".init.text","ax"
12525 + __INIT
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 */
12531 1: hlt
12532 jmp 1b
12533 + .previous
12534
12535 #ifdef CONFIG_EARLY_PRINTK
12536 + __INITDATA
12537 early_recursion_flag:
12538 .long 0
12539 + .previous
12540
12541 + .section .rodata,"a",@progbits
12542 early_idt_msg:
12543 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
12544 early_idt_ripmsg:
12545 .asciz "RIP %s\n"
12546 -#endif /* CONFIG_EARLY_PRINTK */
12547 .previous
12548 +#endif /* CONFIG_EARLY_PRINTK */
12549
12550 + .section .rodata,"a",@progbits
12551 #define NEXT_PAGE(name) \
12552 .balign PAGE_SIZE; \
12553 ENTRY(name)
12554 @@ -339,7 +341,6 @@ ENTRY(name)
12555 i = i + 1 ; \
12556 .endr
12557
12558 - .data
12559 /*
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
12573
12574 +#ifdef CONFIG_PAX_PER_CPU_PGD
12575 +NEXT_PAGE(cpu_pgd)
12576 + .rept NR_CPUS
12577 + .fill 512,8,0
12578 + .endr
12579 +#endif
12580 +
12581 NEXT_PAGE(level3_ident_pgt)
12582 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
12583 +#ifdef CONFIG_XEN
12584 .fill 511,8,0
12585 +#else
12586 + .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
12587 + .fill 510,8,0
12588 +#endif
12589 +
12590 +NEXT_PAGE(level3_vmalloc_pgt)
12591 + .fill 512,8,0
12592 +
12593 +NEXT_PAGE(level3_vmemmap_pgt)
12594 + .fill L3_VMEMMAP_START,8,0
12595 + .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
12596
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
12602
12603 +NEXT_PAGE(level2_vmemmap_pgt)
12604 + .fill 512,8,0
12605 +
12606 NEXT_PAGE(level2_fixmap_pgt)
12607 - .fill 506,8,0
12608 - .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
12609 - /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
12610 - .fill 5,8,0
12611 + .fill 507,8,0
12612 + .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
12613 + /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
12614 + .fill 4,8,0
12615
12616 -NEXT_PAGE(level1_fixmap_pgt)
12617 +NEXT_PAGE(level1_vsyscall_pgt)
12618 .fill 512,8,0
12619
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.
12624 */
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)
12628
12629 NEXT_PAGE(level2_kernel_pgt)
12630 /*
12631 @@ -390,33 +417,55 @@ NEXT_PAGE(level2_kernel_pgt)
12632 * If you want to increase this then increase MODULES_VADDR
12633 * too.)
12634 */
12635 - PMDS(0, __PAGE_KERNEL_LARGE_EXEC,
12636 - KERNEL_IMAGE_SIZE/PMD_SIZE)
12637 -
12638 -NEXT_PAGE(level2_spare_pgt)
12639 - .fill 512, 8, 0
12640 + PMDS(0, __PAGE_KERNEL_LARGE_EXEC, KERNEL_IMAGE_SIZE/PMD_SIZE)
12641
12642 #undef PMDS
12643 #undef NEXT_PAGE
12644
12645 - .data
12646 + .align PAGE_SIZE
12647 +ENTRY(cpu_gdt_table)
12648 + .rept NR_CPUS
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 */
12656 +
12657 +#ifdef CONFIG_PAX_KERNEXEC
12658 + .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
12659 +#else
12660 + .quad 0x0 /* unused */
12661 +#endif
12662 +
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 */
12668 +
12669 + /* zero the remaining page */
12670 + .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
12671 + .endr
12672 +
12673 .align 16
12674 .globl early_gdt_descr
12675 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
12680
12681 ENTRY(phys_base)
12682 /* This must match the first entry in level2_kernel_pgt */
12683 .quad 0x0000000000000000
12684
12685 #include "../../x86/xen/xen-head.S"
12686 -
12687 - .section .bss, "aw", @nobits
12688 +
12689 + .section .rodata,"a",@progbits
12690 .align L1_CACHE_BYTES
12691 ENTRY(idt_table)
12692 - .skip IDT_ENTRIES * 16
12693 + .fill 512,8,0
12694
12695 __PAGE_ALIGNED_BSS
12696 .align PAGE_SIZE
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);
12702 #endif
12703
12704 +EXPORT_SYMBOL_GPL(cpu_gdt_table);
12705 +
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);
12710
12711 EXPORT_SYMBOL(__get_user_1);
12712 EXPORT_SYMBOL(__get_user_2);
12713 @@ -36,3 +40,7 @@ EXPORT_SYMBOL(strstr);
12714
12715 EXPORT_SYMBOL(csum_partial);
12716 EXPORT_SYMBOL(empty_zero_page);
12717 +
12718 +#ifdef CONFIG_PAX_KERNEXEC
12719 +EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
12720 +#endif
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.
12727 */
12728 -DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
12729 -
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
12735 @@ -6,6 +6,7 @@
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
12744
12745 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
12746 return -EINVAL;
12747 +#ifdef CONFIG_GRKERNSEC_IO
12748 + if (turn_on && grsec_disable_privio) {
12749 + gr_handle_ioperm();
12750 + return -EPERM;
12751 + }
12752 +#endif
12753 if (turn_on && !capable(CAP_SYS_RAWIO))
12754 return -EPERM;
12755
12756 @@ -67,7 +74,7 @@ asmlinkage long sys_ioperm(unsigned long
12757 * because the ->io_bitmap_max value must match the bitmap
12758 * contents:
12759 */
12760 - tss = &per_cpu(init_tss, get_cpu());
12761 + tss = init_tss + get_cpu();
12762
12763 set_bitmap(t->io_bitmap_ptr, from, num, !turn_on);
12764
12765 @@ -112,6 +119,12 @@ long sys_iopl(unsigned int level, struct
12766 return -EINVAL;
12767 /* Trying to gain more privileges? */
12768 if (level > old) {
12769 +#ifdef CONFIG_GRKERNSEC_IO
12770 + if (grsec_disable_privio) {
12771 + gr_handle_iopl();
12772 + return -EPERM;
12773 + }
12774 +#endif
12775 if (!capable(CAP_SYS_RAWIO))
12776 return -EPERM;
12777 }
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
12782 return 0;
12783
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;
12789
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);
12793
12794 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12795 + __set_fs(irqctx->tinfo.addr_limit);
12796 +#endif
12797 +
12798 if (unlikely(overflow))
12799 call_on_stack(print_stack_overflow, isp);
12800
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");
12805 +
12806 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12807 + __set_fs(curctx->tinfo.addr_limit);
12808 +#endif
12809 +
12810 return 1;
12811 }
12812
12813 @@ -171,9 +180,18 @@ asmlinkage void do_softirq(void)
12814 irqctx->tinfo.previous_esp = current_stack_pointer;
12815
12816 /* build the stack frame on the softirq stack */
12817 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
12818 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
12819 +
12820 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12821 + __set_fs(irqctx->tinfo.addr_limit);
12822 +#endif
12823
12824 call_on_stack(__do_softirq, isp);
12825 +
12826 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12827 + __set_fs(curctx->addr_limit);
12828 +#endif
12829 +
12830 /*
12831 * Shouldnt happen, we returned above if in_interrupt():
12832 */
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,
12837 switch (regno) {
12838 #ifdef CONFIG_X86_32
12839 case GDB_SS:
12840 - if (!user_mode_vm(regs))
12841 + if (!user_mode(regs))
12842 *(unsigned long *)mem = __KERNEL_DS;
12843 break;
12844 case GDB_SP:
12845 - if (!user_mode_vm(regs))
12846 + if (!user_mode(regs))
12847 *(unsigned long *)mem = kernel_stack_pointer(regs);
12848 break;
12849 case GDB_GS:
12850 @@ -722,7 +722,7 @@ void kgdb_arch_set_pc(struct pt_regs *re
12851 regs->ip = ip;
12852 }
12853
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;
12864
12865 insn = (struct __arch_relative_insn *)from;
12866 +
12867 + pax_open_kernel();
12868 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
12869 insn->op = op;
12870 + pax_close_kernel();
12871 }
12872
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;
12877
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. */
12881
12882 retry:
12883 @@ -314,7 +317,9 @@ static int __kprobes __copy_instruction(
12884 }
12885 }
12886 insn_get_length(&insn);
12887 + pax_open_kernel();
12888 memcpy(dest, insn.kaddr, insn.length);
12889 + pax_close_kernel();
12890
12891 #ifdef CONFIG_X86_64
12892 if (insn_rip_relative(&insn)) {
12893 @@ -338,7 +343,9 @@ static int __kprobes __copy_instruction(
12894 (u8 *) dest;
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();
12900 }
12901 #endif
12902 return insn.length;
12903 @@ -352,12 +359,12 @@ static void __kprobes arch_copy_kprobe(s
12904 */
12905 __copy_instruction(p->ainsn.insn, p->addr, 0);
12906
12907 - if (can_boost(p->addr))
12908 + if (can_boost(ktla_ktva(p->addr)))
12909 p->ainsn.boostable = 0;
12910 else
12911 p->ainsn.boostable = -1;
12912
12913 - p->opcode = *p->addr;
12914 + p->opcode = *(ktla_ktva(p->addr));
12915 }
12916
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
12920 * stepping.
12921 */
12922 - regs->ip = (unsigned long)p->ainsn.insn;
12923 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
12924 preempt_enable_no_resched();
12925 return;
12926 }
12927 @@ -493,7 +500,7 @@ static void __kprobes setup_singlestep(s
12928 if (p->opcode == BREAKPOINT_INSTRUCTION)
12929 regs->ip = (unsigned long)p->addr;
12930 else
12931 - regs->ip = (unsigned long)p->ainsn.insn;
12932 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
12933 }
12934
12935 /*
12936 @@ -572,7 +579,7 @@ static int __kprobes kprobe_handler(stru
12937 setup_singlestep(p, regs, kcb, 0);
12938 return 1;
12939 }
12940 - } else if (*addr != BREAKPOINT_INSTRUCTION) {
12941 + } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
12942 /*
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)
12947 {
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;
12953
12954 @@ -999,7 +1006,7 @@ int __kprobes kprobe_exceptions_notify(s
12955 struct die_args *args = data;
12956 int ret = NOTIFY_DONE;
12957
12958 - if (args->regs && user_mode_vm(args->regs))
12959 + if (args->regs && user_mode(args->regs))
12960 return ret;
12961
12962 switch (val) {
12963 @@ -1368,7 +1375,7 @@ int __kprobes arch_prepare_optimized_kpr
12964 * Verify if the address gap is in 2GB range, because this uses
12965 * a relative jump.
12966 */
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)
12970 return -ERANGE;
12971
12972 @@ -1389,11 +1396,11 @@ int __kprobes arch_prepare_optimized_kpr
12973 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
12974
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));
12978
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);
12983
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));
12988
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);
12993
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
12999 if (reload) {
13000 #ifdef CONFIG_SMP
13001 preempt_disable();
13002 - load_LDT(pc);
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);
13007 preempt_enable();
13008 #else
13009 - load_LDT(pc);
13010 + load_LDT_nolock(pc);
13011 #endif
13012 }
13013 if (oldsize) {
13014 @@ -95,7 +95,7 @@ static inline int copy_ldt(mm_context_t
13015 return err;
13016
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);
13020 return 0;
13021 }
13022
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);
13026 }
13027 +
13028 + if (tsk == current) {
13029 + mm->context.vdso = 0;
13030 +
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;
13035 +
13036 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
13037 + cpus_clear(mm->context.cpu_user_cs_mask);
13038 +#endif
13039 +
13040 +#endif
13041 +#endif
13042 +
13043 + }
13044 +
13045 return retval;
13046 }
13047
13048 @@ -230,6 +248,13 @@ static int write_ldt(void __user *ptr, u
13049 }
13050 }
13051
13052 +#ifdef CONFIG_PAX_SEGMEXEC
13053 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
13054 + error = -EINVAL;
13055 + goto out_unlock;
13056 + }
13057 +#endif
13058 +
13059 fill_ldt(&ldt, &ldt_info);
13060 if (oldmode)
13061 ldt.avl = 0;
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
13065 @@ -27,7 +27,7 @@
13066 #include <asm/cacheflush.h>
13067 #include <asm/debugreg.h>
13068
13069 -static void set_idt(void *newidt, __u16 limit)
13070 +static void set_idt(struct desc_struct *newidt, __u16 limit)
13071 {
13072 struct desc_ptr curidt;
13073
13074 @@ -39,7 +39,7 @@ static void set_idt(void *newidt, __u16
13075 }
13076
13077
13078 -static void set_gdt(void *newgdt, __u16 limit)
13079 +static void set_gdt(struct desc_struct *newgdt, __u16 limit)
13080 {
13081 struct desc_ptr curgdt;
13082
13083 @@ -217,7 +217,7 @@ void machine_kexec(struct kimage *image)
13084 }
13085
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);
13089
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
13096 uci->mc = NULL;
13097 }
13098
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,
13106 };
13107
13108 -struct microcode_ops * __init init_amd_microcode(void)
13109 +const struct microcode_ops * __init init_amd_microcode(void)
13110 {
13111 return &microcode_amd_ops;
13112 }
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");
13117
13118 #define MICROCODE_VERSION "2.00"
13119
13120 -static struct microcode_ops *microcode_ops;
13121 +static const struct microcode_ops *microcode_ops;
13122
13123 /*
13124 * Synchronization.
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
13129
13130 static int get_ucode_user(void *to, const void *from, size_t n)
13131 {
13132 - return copy_from_user(to, from, n);
13133 + return copy_from_user(to, (__force const void __user *)from, n);
13134 }
13135
13136 static enum ucode_state
13137 request_microcode_user(int cpu, const void __user *buf, size_t size)
13138 {
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);
13141 }
13142
13143 static void microcode_fini_cpu(int cpu)
13144 @@ -457,7 +457,7 @@ static void microcode_fini_cpu(int cpu)
13145 uci->mc = NULL;
13146 }
13147
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,
13155 };
13156
13157 -struct microcode_ops * __init init_intel_microcode(void)
13158 +const struct microcode_ops * __init init_intel_microcode(void)
13159 {
13160 return &microcode_intel_ops;
13161 }
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
13165 @@ -35,7 +35,7 @@
13166 #define DEBUGP(fmt...)
13167 #endif
13168
13169 -void *module_alloc(unsigned long size)
13170 +static void *__module_alloc(unsigned long size, pgprot_t prot)
13171 {
13172 struct vm_struct *area;
13173
13174 @@ -49,8 +49,18 @@ void *module_alloc(unsigned long size)
13175 if (!area)
13176 return NULL;
13177
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);
13181 +}
13182 +
13183 +void *module_alloc(unsigned long size)
13184 +{
13185 +
13186 +#ifdef CONFIG_PAX_KERNEXEC
13187 + return __module_alloc(size, PAGE_KERNEL);
13188 +#else
13189 + return __module_alloc(size, PAGE_KERNEL_EXEC);
13190 +#endif
13191 +
13192 }
13193
13194 /* Free memory returned from module_alloc */
13195 @@ -59,6 +69,40 @@ void module_free(struct module *mod, voi
13196 vfree(module_region);
13197 }
13198
13199 +#ifdef CONFIG_PAX_KERNEXEC
13200 +#ifdef CONFIG_X86_32
13201 +void *module_alloc_exec(unsigned long size)
13202 +{
13203 + struct vm_struct *area;
13204 +
13205 + if (size == 0)
13206 + return NULL;
13207 +
13208 + area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
13209 + return area ? area->addr : NULL;
13210 +}
13211 +EXPORT_SYMBOL(module_alloc_exec);
13212 +
13213 +void module_free_exec(struct module *mod, void *module_region)
13214 +{
13215 + vunmap(module_region);
13216 +}
13217 +EXPORT_SYMBOL(module_free_exec);
13218 +#else
13219 +void module_free_exec(struct module *mod, void *module_region)
13220 +{
13221 + module_free(mod, module_region);
13222 +}
13223 +EXPORT_SYMBOL(module_free_exec);
13224 +
13225 +void *module_alloc_exec(unsigned long size)
13226 +{
13227 + return __module_alloc(size, PAGE_KERNEL_RX);
13228 +}
13229 +EXPORT_SYMBOL(module_alloc_exec);
13230 +#endif
13231 +#endif
13232 +
13233 /* We don't need anything special. */
13234 int module_frob_arch_sections(Elf_Ehdr *hdr,
13235 Elf_Shdr *sechdrs,
13236 @@ -78,14 +122,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
13237 unsigned int i;
13238 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
13239 Elf32_Sym *sym;
13240 - uint32_t *location;
13241 + uint32_t *plocation, location;
13242
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)) {
13258 case R_386_32:
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();
13264 break;
13265 case R_386_PC32:
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();
13271 break;
13272 default:
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:
13276 break;
13277 case R_X86_64_64:
13278 + pax_open_kernel();
13279 *(u64 *)loc = val;
13280 + pax_close_kernel();
13281 break;
13282 case R_X86_64_32:
13283 + pax_open_kernel();
13284 *(u32 *)loc = val;
13285 + pax_close_kernel();
13286 if (val != *(u32 *)loc)
13287 goto overflow;
13288 break;
13289 case R_X86_64_32S:
13290 + pax_open_kernel();
13291 *(s32 *)loc = val;
13292 + pax_close_kernel();
13293 if ((s64)val != *(s32 *)loc)
13294 goto overflow;
13295 break;
13296 case R_X86_64_PC32:
13297 val -= (u64)loc;
13298 + pax_open_kernel();
13299 *(u32 *)loc = val;
13300 + pax_close_kernel();
13301 +
13302 #if 0
13303 if ((s64)val != *(s32 *)loc)
13304 goto overflow;
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)
13311 {
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();
13325
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);
13333
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)
13337 insn_len = len;
13338 else
13339 - memcpy(insnbuf, start, insn_len);
13340 + memcpy(insnbuf, ktla_ktva(start), insn_len);
13341
13342 return insn_len;
13343 }
13344 @@ -294,22 +294,22 @@ void arch_flush_lazy_mmu_mode(void)
13345 preempt_enable();
13346 }
13347
13348 -struct pv_info pv_info = {
13349 +struct pv_info pv_info __read_only = {
13350 .name = "bare hardware",
13351 .paravirt_enabled = 0,
13352 .kernel_rpl = 0,
13353 .shared_kernel_pmd = 1, /* Only used when CONFIG_X86_PAE is set */
13354 };
13355
13356 -struct pv_init_ops pv_init_ops = {
13357 +struct pv_init_ops pv_init_ops __read_only = {
13358 .patch = native_patch,
13359 };
13360
13361 -struct pv_time_ops pv_time_ops = {
13362 +struct pv_time_ops pv_time_ops __read_only = {
13363 .sched_clock = native_sched_clock,
13364 };
13365
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 = {
13372 #endif
13373 };
13374
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,
13382 };
13383
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,
13388 #endif
13389 @@ -396,7 +396,7 @@ struct pv_apic_ops pv_apic_ops = {
13390 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
13391 #endif
13392
13393 -struct pv_mmu_ops pv_mmu_ops = {
13394 +struct pv_mmu_ops pv_mmu_ops __read_only = {
13395
13396 .read_cr2 = native_read_cr2,
13397 .write_cr2 = native_write_cr2,
13398 @@ -462,6 +462,12 @@ struct pv_mmu_ops pv_mmu_ops = {
13399 },
13400
13401 .set_fixmap = native_set_fixmap,
13402 +
13403 +#ifdef CONFIG_PAX_KERNEXEC
13404 + .pax_open_kernel = native_pax_open_kernel,
13405 + .pax_close_kernel = native_pax_close_kernel,
13406 +#endif
13407 +
13408 };
13409
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);
13416 }
13417
13418 -struct pv_lock_ops pv_lock_ops = {
13419 +struct pv_lock_ops pv_lock_ops __read_only = {
13420 #ifdef CONFIG_SMP
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));
13428 }
13429
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
13438 @@ -16,7 +16,7 @@
13439
13440 static int forbid_dac __read_mostly;
13441
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);
13445
13446 static int iommu_sac_force __read_mostly;
13447 @@ -250,7 +250,7 @@ early_param("iommu", iommu_setup);
13448
13449 int dma_supported(struct device *dev, u64 mask)
13450 {
13451 - struct dma_map_ops *ops = get_dma_ops(dev);
13452 + const struct dma_map_ops *ops = get_dma_ops(dev);
13453
13454 #ifdef CONFIG_PCI
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
13460 return -1;
13461 }
13462
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();
13473 }
13474
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);
13485 }
13486
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)
13497 {
13498 return ((unsigned long *)tsk->thread.sp)[3];
13499 +//XXX return tsk->thread.eip;
13500 }
13501
13502 #ifndef CONFIG_SMP
13503 @@ -130,15 +131,14 @@ void __show_regs(struct pt_regs *regs, i
13504 unsigned long sp;
13505 unsigned short ss, gs;
13506
13507 - if (user_mode_vm(regs)) {
13508 + if (user_mode(regs)) {
13509 sp = regs->sp;
13510 ss = regs->ss & 0xffff;
13511 - gs = get_user_gs(regs);
13512 } else {
13513 sp = kernel_stack_pointer(regs);
13514 savesegment(ss, ss);
13515 - savesegment(gs, gs);
13516 }
13517 + gs = get_user_gs(regs);
13518
13519 show_regs_common();
13520
13521 @@ -200,7 +200,7 @@ int copy_thread(unsigned long clone_flag
13522 struct task_struct *tsk;
13523 int err;
13524
13525 - childregs = task_pt_regs(p);
13526 + childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
13527 *childregs = *regs;
13528 childregs->ax = 0;
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;
13536 bool preload_fpu;
13537
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,
13540 */
13541 lazy_save_gs(prev->gs);
13542
13543 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13544 + __set_fs(task_thread_info(next_p)->addr_limit);
13545 +#endif
13546 +
13547 /*
13548 * Load the per-thread Thread-Local Storage descriptor.
13549 */
13550 @@ -408,3 +412,27 @@ unsigned long get_wchan(struct task_stru
13551 return 0;
13552 }
13553
13554 +#ifdef CONFIG_PAX_RANDKSTACK
13555 +asmlinkage void pax_randomize_kstack(void)
13556 +{
13557 + struct thread_struct *thread = &current->thread;
13558 + unsigned long time;
13559 +
13560 + if (!randomize_va_space)
13561 + return;
13562 +
13563 + rdtscl(time);
13564 +
13565 + /* P4 seems to return a 0 LSB, ignore it */
13566 +#ifdef CONFIG_MPENTIUM4
13567 + time &= 0x1EUL;
13568 + time <<= 2;
13569 +#else
13570 + time &= 0xFUL;
13571 + time <<= 3;
13572 +#endif
13573 +
13574 + thread->sp0 ^= time;
13575 + load_sp0(init_tss + smp_processor_id(), thread);
13576 +}
13577 +#endif
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)
13583 {
13584 /* idle loop has pid 0 */
13585 - if (current->pid)
13586 + if (task_pid_nr(current))
13587 return;
13588 __exit_idle();
13589 }
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;
13597 bool preload_fpu;
13598
13599 @@ -533,12 +533,11 @@ unsigned long get_wchan(struct task_stru
13600 if (!p || p == current || p->state == TASK_RUNNING)
13601 return 0;
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))
13605 return 0;
13606 fp = *(u64 *)(p->thread.sp);
13607 do {
13608 - if (fp < (unsigned long)stack ||
13609 - fp >= (unsigned long)stack+THREAD_SIZE)
13610 + if (fp < stack || fp > stack+THREAD_SIZE-8-sizeof(u64))
13611 return 0;
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;
13619
13620 if (bp) {
13621 - struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
13622 + struct tss_struct *tss = init_tss + get_cpu();
13623
13624 t->io_bitmap_ptr = NULL;
13625 clear_thread_flag(TIF_IO_BITMAP);
13626 @@ -108,7 +108,7 @@ void show_regs_common(void)
13627
13628 printk(KERN_CONT "\n");
13629 printk(KERN_DEFAULT "Pid: %d, comm: %.20s %s %s %.*s %s/%s\n",
13630 - current->pid, current->comm, print_tainted(),
13631 + task_pid_nr(current), current->comm, print_tainted(),
13632 init_utsname()->release,
13633 (int)strcspn(init_utsname()->version, " "),
13634 init_utsname()->version, board, product);
13635 @@ -118,6 +118,9 @@ void flush_thread(void)
13636 {
13637 struct task_struct *tsk = current;
13638
13639 +#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
13640 + loadsegment(gs, 0);
13641 +#endif
13642 flush_ptrace_hw_breakpoint(tsk);
13643 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
13644 /*
13645 @@ -280,10 +283,10 @@ int kernel_thread(int (*fn)(void *), voi
13646 regs.di = (unsigned long) arg;
13647
13648 #ifdef CONFIG_X86_32
13649 - regs.ds = __USER_DS;
13650 - regs.es = __USER_DS;
13651 + regs.ds = __KERNEL_DS;
13652 + regs.es = __KERNEL_DS;
13653 regs.fs = __KERNEL_PERCPU;
13654 - regs.gs = __KERNEL_STACK_CANARY;
13655 + savesegment(gs, regs.gs);
13656 #else
13657 regs.ss = __KERNEL_DS;
13658 #endif
13659 @@ -658,17 +661,3 @@ static int __init idle_setup(char *str)
13660 return 0;
13661 }
13662 early_param("idle", idle_setup);
13663 -
13664 -unsigned long arch_align_stack(unsigned long sp)
13665 -{
13666 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
13667 - sp -= get_random_int() % 8192;
13668 - return sp & ~0xf;
13669 -}
13670 -
13671 -unsigned long arch_randomize_brk(struct mm_struct *mm)
13672 -{
13673 - unsigned long range_end = mm->brk + 0x02000000;
13674 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
13675 -}
13676 -
13677 diff -urNp linux-2.6.37/arch/x86/kernel/ptrace.c linux-2.6.37/arch/x86/kernel/ptrace.c
13678 --- linux-2.6.37/arch/x86/kernel/ptrace.c 2011-01-04 19:50:19.000000000 -0500
13679 +++ linux-2.6.37/arch/x86/kernel/ptrace.c 2011-01-17 02:41:01.000000000 -0500
13680 @@ -805,7 +805,7 @@ long arch_ptrace(struct task_struct *chi
13681 unsigned long addr, unsigned long data)
13682 {
13683 int ret;
13684 - unsigned long __user *datap = (unsigned long __user *)data;
13685 + unsigned long __user *datap = (__force unsigned long __user *)data;
13686
13687 switch (request) {
13688 /* read the word at location addr in the USER area. */
13689 @@ -890,14 +890,14 @@ long arch_ptrace(struct task_struct *chi
13690 if ((int) addr < 0)
13691 return -EIO;
13692 ret = do_get_thread_area(child, addr,
13693 - (struct user_desc __user *)data);
13694 + (__force struct user_desc __user *) data);
13695 break;
13696
13697 case PTRACE_SET_THREAD_AREA:
13698 if ((int) addr < 0)
13699 return -EIO;
13700 ret = do_set_thread_area(child, addr,
13701 - (struct user_desc __user *)data, 0);
13702 + (__force struct user_desc __user *) data, 0);
13703 break;
13704 #endif
13705
13706 @@ -1314,7 +1314,7 @@ static void fill_sigtrap_info(struct tas
13707 memset(info, 0, sizeof(*info));
13708 info->si_signo = SIGTRAP;
13709 info->si_code = si_code;
13710 - info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
13711 + info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
13712 }
13713
13714 void user_single_step_siginfo(struct task_struct *tsk,
13715 diff -urNp linux-2.6.37/arch/x86/kernel/reboot.c linux-2.6.37/arch/x86/kernel/reboot.c
13716 --- linux-2.6.37/arch/x86/kernel/reboot.c 2011-01-04 19:50:19.000000000 -0500
13717 +++ linux-2.6.37/arch/x86/kernel/reboot.c 2011-01-17 02:41:01.000000000 -0500
13718 @@ -33,7 +33,7 @@ void (*pm_power_off)(void);
13719 EXPORT_SYMBOL(pm_power_off);
13720
13721 static const struct desc_ptr no_idt = {};
13722 -static int reboot_mode;
13723 +static unsigned short reboot_mode;
13724 enum reboot_type reboot_type = BOOT_KBD;
13725 int reboot_force;
13726
13727 @@ -284,7 +284,7 @@ static struct dmi_system_id __initdata r
13728 DMI_MATCH(DMI_BOARD_NAME, "P4S800"),
13729 },
13730 },
13731 - { }
13732 + { NULL, NULL, {{0, {0}}}, NULL}
13733 };
13734
13735 static int __init reboot_init(void)
13736 @@ -300,12 +300,12 @@ core_initcall(reboot_init);
13737 controller to pulse the CPU reset line, which is more thorough, but
13738 doesn't work with at least one type of 486 motherboard. It is easy
13739 to stop this code working; hence the copious comments. */
13740 -static const unsigned long long
13741 -real_mode_gdt_entries [3] =
13742 +static struct desc_struct
13743 +real_mode_gdt_entries [3] __read_only =
13744 {
13745 - 0x0000000000000000ULL, /* Null descriptor */
13746 - 0x00009b000000ffffULL, /* 16-bit real-mode 64k code at 0x00000000 */
13747 - 0x000093000100ffffULL /* 16-bit real-mode 64k data at 0x00000100 */
13748 + GDT_ENTRY_INIT(0, 0, 0), /* Null descriptor */
13749 + GDT_ENTRY_INIT(0x9b, 0, 0xffff), /* 16-bit real-mode 64k code at 0x00000000 */
13750 + GDT_ENTRY_INIT(0x93, 0x100, 0xffff) /* 16-bit real-mode 64k data at 0x00000100 */
13751 };
13752
13753 static const struct desc_ptr
13754 @@ -354,7 +354,7 @@ static const unsigned char jump_to_bios
13755 * specified by the code and length parameters.
13756 * We assume that length will aways be less that 100!
13757 */
13758 -void machine_real_restart(const unsigned char *code, int length)
13759 +void machine_real_restart(const unsigned char *code, unsigned int length)
13760 {
13761 local_irq_disable();
13762
13763 @@ -381,16 +381,15 @@ void machine_real_restart(const unsigned
13764 boot)". This seems like a fairly standard thing that gets set by
13765 REBOOT.COM programs, and the previous reset routine did this
13766 too. */
13767 - *((unsigned short *)0x472) = reboot_mode;
13768 + *(unsigned short *)(__va(0x472)) = reboot_mode;
13769
13770 /* For the switch to real mode, copy some code to low memory. It has
13771 to be in the first 64k because it is running in 16-bit mode, and it
13772 has to have the same physical and virtual address, because it turns
13773 off paging. Copy it near the end of the first page, out of the way
13774 of BIOS variables. */
13775 - memcpy((void *)(0x1000 - sizeof(real_mode_switch) - 100),
13776 - real_mode_switch, sizeof (real_mode_switch));
13777 - memcpy((void *)(0x1000 - 100), code, length);
13778 + memcpy(__va(0x1000 - sizeof (real_mode_switch) - 100), real_mode_switch, sizeof (real_mode_switch));
13779 + memcpy(__va(0x1000 - 100), code, length);
13780
13781 /* Set up the IDT for real mode. */
13782 load_idt(&real_mode_idt);
13783 diff -urNp linux-2.6.37/arch/x86/kernel/setup.c linux-2.6.37/arch/x86/kernel/setup.c
13784 --- linux-2.6.37/arch/x86/kernel/setup.c 2011-01-04 19:50:19.000000000 -0500
13785 +++ linux-2.6.37/arch/x86/kernel/setup.c 2011-01-17 02:41:01.000000000 -0500
13786 @@ -654,7 +654,7 @@ static void __init trim_bios_range(void)
13787 * area (640->1Mb) as ram even though it is not.
13788 * take them out.
13789 */
13790 - e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
13791 + e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
13792 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
13793 }
13794
13795 @@ -790,14 +790,14 @@ void __init setup_arch(char **cmdline_p)
13796
13797 if (!boot_params.hdr.root_flags)
13798 root_mountflags &= ~MS_RDONLY;
13799 - init_mm.start_code = (unsigned long) _text;
13800 - init_mm.end_code = (unsigned long) _etext;
13801 + init_mm.start_code = ktla_ktva((unsigned long) _text);
13802 + init_mm.end_code = ktla_ktva((unsigned long) _etext);
13803 init_mm.end_data = (unsigned long) _edata;
13804 init_mm.brk = _brk_end;
13805
13806 - code_resource.start = virt_to_phys(_text);
13807 - code_resource.end = virt_to_phys(_etext)-1;
13808 - data_resource.start = virt_to_phys(_etext);
13809 + code_resource.start = virt_to_phys(ktla_ktva(_text));
13810 + code_resource.end = virt_to_phys(ktla_ktva(_etext))-1;
13811 + data_resource.start = virt_to_phys(_sdata);
13812 data_resource.end = virt_to_phys(_edata)-1;
13813 bss_resource.start = virt_to_phys(&__bss_start);
13814 bss_resource.end = virt_to_phys(&__bss_stop)-1;
13815 diff -urNp linux-2.6.37/arch/x86/kernel/setup_percpu.c linux-2.6.37/arch/x86/kernel/setup_percpu.c
13816 --- linux-2.6.37/arch/x86/kernel/setup_percpu.c 2011-01-04 19:50:19.000000000 -0500
13817 +++ linux-2.6.37/arch/x86/kernel/setup_percpu.c 2011-01-17 02:41:01.000000000 -0500
13818 @@ -21,19 +21,17 @@
13819 #include <asm/cpu.h>
13820 #include <asm/stackprotector.h>
13821
13822 -DEFINE_PER_CPU(int, cpu_number);
13823 +#ifdef CONFIG_SMP
13824 +DEFINE_PER_CPU(unsigned int, cpu_number);
13825 EXPORT_PER_CPU_SYMBOL(cpu_number);
13826 +#endif
13827
13828 -#ifdef CONFIG_X86_64
13829 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
13830 -#else
13831 -#define BOOT_PERCPU_OFFSET 0
13832 -#endif
13833
13834 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
13835 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
13836
13837 -unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
13838 +unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
13839 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
13840 };
13841 EXPORT_SYMBOL(__per_cpu_offset);
13842 @@ -155,10 +153,10 @@ static inline void setup_percpu_segment(
13843 {
13844 #ifdef CONFIG_X86_32
13845 struct desc_struct gdt;
13846 + unsigned long base = per_cpu_offset(cpu);
13847
13848 - pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
13849 - 0x2 | DESCTYPE_S, 0x8);
13850 - gdt.s = 1;
13851 + pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
13852 + 0x83 | DESCTYPE_S, 0xC);
13853 write_gdt_entry(get_cpu_gdt_table(cpu),
13854 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
13855 #endif
13856 @@ -207,6 +205,11 @@ void __init setup_per_cpu_areas(void)
13857 /* alrighty, percpu areas up and running */
13858 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
13859 for_each_possible_cpu(cpu) {
13860 +#ifdef CONFIG_CC_STACKPROTECTOR
13861 +#ifdef CONFIG_x86_32
13862 + unsigned long canary = per_cpu(stack_canary, cpu);
13863 +#endif
13864 +#endif
13865 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
13866 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
13867 per_cpu(cpu_number, cpu) = cpu;
13868 @@ -243,6 +246,12 @@ void __init setup_per_cpu_areas(void)
13869 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
13870 #endif
13871 #endif
13872 +#ifdef CONFIG_CC_STACKPROTECTOR
13873 +#ifdef CONFIG_x86_32
13874 + if (cpu == boot_cpu_id)
13875 + per_cpu(stack_canary, cpu) = canary;
13876 +#endif
13877 +#endif
13878 /*
13879 * Up to this point, the boot CPU has been using .init.data
13880 * area. Reload any changed state for the boot CPU.
13881 diff -urNp linux-2.6.37/arch/x86/kernel/signal.c linux-2.6.37/arch/x86/kernel/signal.c
13882 --- linux-2.6.37/arch/x86/kernel/signal.c 2011-01-04 19:50:19.000000000 -0500
13883 +++ linux-2.6.37/arch/x86/kernel/signal.c 2011-01-17 02:41:01.000000000 -0500
13884 @@ -198,7 +198,7 @@ static unsigned long align_sigframe(unsi
13885 * Align the stack pointer according to the i386 ABI,
13886 * i.e. so that on function entry ((sp + 4) & 15) == 0.
13887 */
13888 - sp = ((sp + 4) & -16ul) - 4;
13889 + sp = ((sp - 12) & -16ul) - 4;
13890 #else /* !CONFIG_X86_32 */
13891 sp = round_down(sp, 16) - 8;
13892 #endif
13893 @@ -249,11 +249,11 @@ get_sigframe(struct k_sigaction *ka, str
13894 * Return an always-bogus address instead so we will die with SIGSEGV.
13895 */
13896 if (onsigstack && !likely(on_sig_stack(sp)))
13897 - return (void __user *)-1L;
13898 + return (__force void __user *)-1L;
13899
13900 /* save i387 state */
13901 if (used_math() && save_i387_xstate(*fpstate) < 0)
13902 - return (void __user *)-1L;
13903 + return (__force void __user *)-1L;
13904
13905 return (void __user *)sp;
13906 }
13907 @@ -308,9 +308,9 @@ __setup_frame(int sig, struct k_sigactio
13908 }
13909
13910 if (current->mm->context.vdso)
13911 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
13912 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
13913 else
13914 - restorer = &frame->retcode;
13915 + restorer = (void __user *)&frame->retcode;
13916 if (ka->sa.sa_flags & SA_RESTORER)
13917 restorer = ka->sa.sa_restorer;
13918
13919 @@ -324,7 +324,7 @@ __setup_frame(int sig, struct k_sigactio
13920 * reasons and because gdb uses it as a signature to notice
13921 * signal handler stack frames.
13922 */
13923 - err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
13924 + err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
13925
13926 if (err)
13927 return -EFAULT;
13928 @@ -378,7 +378,10 @@ static int __setup_rt_frame(int sig, str
13929 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
13930
13931 /* Set up to return from userspace. */
13932 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
13933 + if (current->mm->context.vdso)
13934 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
13935 + else
13936 + restorer = (void __user *)&frame->retcode;
13937 if (ka->sa.sa_flags & SA_RESTORER)
13938 restorer = ka->sa.sa_restorer;
13939 put_user_ex(restorer, &frame->pretcode);
13940 @@ -390,7 +393,7 @@ static int __setup_rt_frame(int sig, str
13941 * reasons and because gdb uses it as a signature to notice
13942 * signal handler stack frames.
13943 */
13944 - put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
13945 + put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
13946 } put_user_catch(err);
13947
13948 if (err)
13949 @@ -780,7 +783,7 @@ static void do_signal(struct pt_regs *re
13950 * X86_32: vm86 regs switched out by assembly code before reaching
13951 * here, so testing against kernel CS suffices.
13952 */
13953 - if (!user_mode(regs))
13954 + if (!user_mode_novm(regs))
13955 return;
13956
13957 if (current_thread_info()->status & TS_RESTORE_SIGMASK)
13958 diff -urNp linux-2.6.37/arch/x86/kernel/smpboot.c linux-2.6.37/arch/x86/kernel/smpboot.c
13959 --- linux-2.6.37/arch/x86/kernel/smpboot.c 2011-01-04 19:50:19.000000000 -0500
13960 +++ linux-2.6.37/arch/x86/kernel/smpboot.c 2011-01-17 02:41:01.000000000 -0500
13961 @@ -786,7 +786,11 @@ do_rest:
13962 (unsigned long)task_stack_page(c_idle.idle) -
13963 KERNEL_STACK_OFFSET + THREAD_SIZE;
13964 #endif
13965 +
13966 + pax_open_kernel();
13967 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
13968 + pax_close_kernel();
13969 +
13970 initial_code = (unsigned long)start_secondary;
13971 stack_start.sp = (void *) c_idle.idle->thread.sp;
13972
13973 @@ -926,6 +930,12 @@ int __cpuinit native_cpu_up(unsigned int
13974
13975 per_cpu(cpu_state, cpu) = CPU_UP_PREPARE;
13976
13977 +#ifdef CONFIG_PAX_PER_CPU_PGD
13978 + clone_pgd_range(get_cpu_pgd(cpu) + KERNEL_PGD_BOUNDARY,
13979 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
13980 + KERNEL_PGD_PTRS);
13981 +#endif
13982 +
13983 err = do_boot_cpu(apicid, cpu);
13984 if (err) {
13985 pr_debug("do_boot_cpu failed %d\n", err);
13986 diff -urNp linux-2.6.37/arch/x86/kernel/step.c linux-2.6.37/arch/x86/kernel/step.c
13987 --- linux-2.6.37/arch/x86/kernel/step.c 2011-01-04 19:50:19.000000000 -0500
13988 +++ linux-2.6.37/arch/x86/kernel/step.c 2011-01-17 02:41:01.000000000 -0500
13989 @@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struc
13990 struct desc_struct *desc;
13991 unsigned long base;
13992
13993 - seg &= ~7UL;
13994 + seg >>= 3;
13995
13996 mutex_lock(&child->mm->context.lock);
13997 - if (unlikely((seg >> 3) >= child->mm->context.size))
13998 + if (unlikely(seg >= child->mm->context.size))
13999 addr = -1L; /* bogus selector, access would fault */
14000 else {
14001 desc = child->mm->context.ldt + seg;
14002 @@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struc
14003 addr += base;
14004 }
14005 mutex_unlock(&child->mm->context.lock);
14006 - }
14007 + } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
14008 + addr = ktla_ktva(addr);
14009
14010 return addr;
14011 }
14012 @@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct t
14013 unsigned char opcode[15];
14014 unsigned long addr = convert_ip_to_linear(child, regs);
14015
14016 + if (addr == -EINVAL)
14017 + return 0;
14018 +
14019 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
14020 for (i = 0; i < copied; i++) {
14021 switch (opcode[i]) {
14022 @@ -74,7 +78,7 @@ static int is_setting_trap_flag(struct t
14023
14024 #ifdef CONFIG_X86_64
14025 case 0x40 ... 0x4f:
14026 - if (regs->cs != __USER_CS)
14027 + if ((regs->cs & 0xffff) != __USER_CS)
14028 /* 32-bit mode: register increment */
14029 return 0;
14030 /* 64-bit mode: REX prefix */
14031 diff -urNp linux-2.6.37/arch/x86/kernel/syscall_table_32.S linux-2.6.37/arch/x86/kernel/syscall_table_32.S
14032 --- linux-2.6.37/arch/x86/kernel/syscall_table_32.S 2011-01-04 19:50:19.000000000 -0500
14033 +++ linux-2.6.37/arch/x86/kernel/syscall_table_32.S 2011-01-17 02:41:01.000000000 -0500
14034 @@ -1,3 +1,4 @@
14035 +.section .rodata,"a",@progbits
14036 ENTRY(sys_call_table)
14037 .long sys_restart_syscall /* 0 - old "setup()" system call, used for restarting */
14038 .long sys_exit
14039 diff -urNp linux-2.6.37/arch/x86/kernel/sys_i386_32.c linux-2.6.37/arch/x86/kernel/sys_i386_32.c
14040 --- linux-2.6.37/arch/x86/kernel/sys_i386_32.c 2011-01-04 19:50:19.000000000 -0500
14041 +++ linux-2.6.37/arch/x86/kernel/sys_i386_32.c 2011-01-17 02:41:01.000000000 -0500
14042 @@ -24,17 +24,224 @@
14043
14044 #include <asm/syscalls.h>
14045
14046 -/*
14047 - * Do a system call from kernel instead of calling sys_execve so we
14048 - * end up with proper pt_regs.
14049 - */
14050 -int kernel_execve(const char *filename,
14051 - const char *const argv[],
14052 - const char *const envp[])
14053 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
14054 {
14055 - long __res;
14056 - asm volatile ("int $0x80"
14057 - : "=a" (__res)
14058 - : "0" (__NR_execve), "b" (filename), "c" (argv), "d" (envp) : "memory");
14059 - return __res;
14060 + unsigned long pax_task_size = TASK_SIZE;
14061 +
14062 +#ifdef CONFIG_PAX_SEGMEXEC
14063 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
14064 + pax_task_size = SEGMEXEC_TASK_SIZE;
14065 +#endif
14066 +
14067 + if (len > pax_task_size || addr > pax_task_size - len)
14068 + return -EINVAL;
14069 +
14070 + return 0;
14071 +}
14072 +
14073 +unsigned long
14074 +arch_get_unmapped_area(struct file *filp, unsigned long addr,
14075 + unsigned long len, unsigned long pgoff, unsigned long flags)
14076 +{
14077 + struct mm_struct *mm = current->mm;
14078 + struct vm_area_struct *vma;
14079 + unsigned long start_addr, pax_task_size = TASK_SIZE;
14080 +
14081 +#ifdef CONFIG_PAX_SEGMEXEC
14082 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
14083 + pax_task_size = SEGMEXEC_TASK_SIZE;
14084 +#endif
14085 +
14086 + pax_task_size -= PAGE_SIZE;
14087 +
14088 + if (len > pax_task_size)
14089 + return -ENOMEM;
14090 +
14091 + if (flags & MAP_FIXED)
14092 + return addr;
14093 +
14094 +#ifdef CONFIG_PAX_RANDMMAP
14095 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
14096 +#endif
14097 +
14098 + if (addr) {
14099 + addr = PAGE_ALIGN(addr);
14100 + if (pax_task_size - len >= addr) {
14101 + vma = find_vma(mm, addr);
14102 + if (check_heap_stack_gap(vma, addr, len))
14103 + return addr;
14104 + }
14105 + }
14106 + if (len > mm->cached_hole_size) {
14107 + start_addr = addr = mm->free_area_cache;
14108 + } else {
14109 + start_addr = addr = mm->mmap_base;
14110 + mm->cached_hole_size = 0;
14111 + }
14112 +
14113 +#ifdef CONFIG_PAX_PAGEEXEC
14114 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE) && start_addr >= mm->mmap_base) {
14115 + start_addr = 0x00110000UL;
14116 +
14117 +#ifdef CONFIG_PAX_RANDMMAP
14118 + if (mm->pax_flags & MF_PAX_RANDMMAP)
14119 + start_addr += mm->delta_mmap & 0x03FFF000UL;
14120 +#endif
14121 +
14122 + if (mm->start_brk <= start_addr && start_addr < mm->mmap_base)
14123 + start_addr = addr = mm->mmap_base;
14124 + else
14125 + addr = start_addr;
14126 + }
14127 +#endif
14128 +
14129 +full_search:
14130 + for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
14131 + /* At this point: (!vma || addr < vma->vm_end). */
14132 + if (pax_task_size - len < addr) {
14133 + /*
14134 + * Start a new search - just in case we missed
14135 + * some holes.
14136 + */
14137 + if (start_addr != mm->mmap_base) {
14138 + start_addr = addr = mm->mmap_base;
14139 + mm->cached_hole_size = 0;
14140 + goto full_search;
14141 + }
14142 + return -ENOMEM;
14143 + }
14144 + if (check_heap_stack_gap(vma, addr, len))
14145 + break;
14146 + if (addr + mm->cached_hole_size < vma->vm_start)
14147 + mm->cached_hole_size = vma->vm_start - addr;
14148 + addr = vma->vm_end;
14149 + if (mm->start_brk <= addr && addr < mm->mmap_base) {
14150 + start_addr = addr = mm->mmap_base;
14151 + mm->cached_hole_size = 0;
14152 + goto full_search;
14153 + }
14154 + }
14155 +
14156 + /*
14157 + * Remember the place where we stopped the search:
14158 + */
14159 + mm->free_area_cache = addr + len;
14160 + return addr;
14161 +}
14162 +
14163 +unsigned long
14164 +arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
14165 + const unsigned long len, const unsigned long pgoff,
14166 + const unsigned long flags)
14167 +{
14168 + struct vm_area_struct *vma;
14169 + struct mm_struct *mm = current->mm;
14170 + unsigned long base = mm->mmap_base, addr = addr0, pax_task_size = TASK_SIZE;
14171 +
14172 +#ifdef CONFIG_PAX_SEGMEXEC
14173 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
14174 + pax_task_size = SEGMEXEC_TASK_SIZE;
14175 +#endif
14176 +
14177 + pax_task_size -= PAGE_SIZE;
14178 +
14179 + /* requested length too big for entire address space */
14180 + if (len > pax_task_size)
14181 + return -ENOMEM;
14182 +
14183 + if (flags & MAP_FIXED)
14184 + return addr;
14185 +
14186 +#ifdef CONFIG_PAX_PAGEEXEC
14187 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
14188 + goto bottomup;
14189 +#endif
14190 +
14191 +#ifdef CONFIG_PAX_RANDMMAP
14192 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
14193 +#endif
14194 +
14195 + /* requesting a specific address */
14196 + if (addr) {
14197 + addr = PAGE_ALIGN(addr);
14198 + if (pax_task_size - len >= addr) {
14199 + vma = find_vma(mm, addr);
14200 + if (check_heap_stack_gap(vma, addr, len))
14201 + return addr;
14202 + }
14203 + }
14204 +
14205 + /* check if free_area_cache is useful for us */
14206 + if (len <= mm->cached_hole_size) {
14207 + mm->cached_hole_size = 0;
14208 + mm->free_area_cache = mm->mmap_base;
14209 + }
14210 +
14211 + /* either no address requested or can't fit in requested address hole */
14212 + addr = mm->free_area_cache;
14213 +
14214 + /* make sure it can fit in the remaining address space */
14215 + if (addr > len) {
14216 + vma = find_vma(mm, addr-len);
14217 + if (check_heap_stack_gap(vma, addr - len, len))
14218 + /* remember the address as a hint for next time */
14219 + return (mm->free_area_cache = addr-len);
14220 + }
14221 +
14222 + if (mm->mmap_base < len)
14223 + goto bottomup;
14224 +
14225 + addr = mm->mmap_base-len;
14226 +
14227 + do {
14228 + /*
14229 + * Lookup failure means no vma is above this address,
14230 + * else if new region fits below vma->vm_start,
14231 + * return with success:
14232 + */
14233 + vma = find_vma(mm, addr);
14234 + if (check_heap_stack_gap(vma, addr, len))
14235 + /* remember the address as a hint for next time */
14236 + return (mm->free_area_cache = addr);
14237 +
14238 + /* remember the largest hole we saw so far */
14239 + if (addr + mm->cached_hole_size < vma->vm_start)
14240 + mm->cached_hole_size = vma->vm_start - addr;
14241 +
14242 + /* try just below the current vma->vm_start */
14243 + addr = vma->vm_start-len;
14244 + } while (len < vma->vm_start);
14245 +
14246 +bottomup:
14247 + /*
14248 + * A failed mmap() very likely causes application failure,
14249 + * so fall back to the bottom-up function here. This scenario
14250 + * can happen with large stack limits and large mmap()
14251 + * allocations.
14252 + */
14253 +
14254 +#ifdef CONFIG_PAX_SEGMEXEC
14255 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
14256 + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
14257 + else
14258 +#endif
14259 +
14260 + mm->mmap_base = TASK_UNMAPPED_BASE;
14261 +
14262 +#ifdef CONFIG_PAX_RANDMMAP
14263 + if (mm->pax_flags & MF_PAX_RANDMMAP)
14264 + mm->mmap_base += mm->delta_mmap;
14265 +#endif
14266 +
14267 + mm->free_area_cache = mm->mmap_base;
14268 + mm->cached_hole_size = ~0UL;
14269 + addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
14270 + /*
14271 + * Restore the topdown base:
14272 + */
14273 + mm->mmap_base = base;
14274 + mm->free_area_cache = base;
14275 + mm->cached_hole_size = ~0UL;
14276 +
14277 + return addr;
14278 }
14279 diff -urNp linux-2.6.37/arch/x86/kernel/sys_x86_64.c linux-2.6.37/arch/x86/kernel/sys_x86_64.c
14280 --- linux-2.6.37/arch/x86/kernel/sys_x86_64.c 2011-01-04 19:50:19.000000000 -0500
14281 +++ linux-2.6.37/arch/x86/kernel/sys_x86_64.c 2011-01-17 02:41:01.000000000 -0500
14282 @@ -32,8 +32,8 @@ out:
14283 return error;
14284 }
14285
14286 -static void find_start_end(unsigned long flags, unsigned long *begin,
14287 - unsigned long *end)
14288 +static void find_start_end(struct mm_struct *mm, unsigned long flags,
14289 + unsigned long *begin, unsigned long *end)
14290 {
14291 if (!test_thread_flag(TIF_IA32) && (flags & MAP_32BIT)) {
14292 unsigned long new_begin;
14293 @@ -52,7 +52,7 @@ static void find_start_end(unsigned long
14294 *begin = new_begin;
14295 }
14296 } else {
14297 - *begin = TASK_UNMAPPED_BASE;
14298 + *begin = mm->mmap_base;
14299 *end = TASK_SIZE;
14300 }
14301 }
14302 @@ -69,16 +69,19 @@ arch_get_unmapped_area(struct file *filp
14303 if (flags & MAP_FIXED)
14304 return addr;
14305
14306 - find_start_end(flags, &begin, &end);
14307 + find_start_end(mm, flags, &begin, &end);
14308
14309 if (len > end)
14310 return -ENOMEM;
14311
14312 +#ifdef CONFIG_PAX_RANDMMAP
14313 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
14314 +#endif
14315 +
14316 if (addr) {
14317 addr = PAGE_ALIGN(addr);
14318 vma = find_vma(mm, addr);
14319 - if (end - len >= addr &&
14320 - (!vma || addr + len <= vma->vm_start))
14321 + if (end - len >= addr && check_heap_stack_gap(vma, addr, len))
14322 return addr;
14323 }
14324 if (((flags & MAP_32BIT) || test_thread_flag(TIF_IA32))
14325 @@ -106,7 +109,7 @@ full_search:
14326 }
14327 return -ENOMEM;
14328 }
14329 - if (!vma || addr + len <= vma->vm_start) {
14330 + if (check_heap_stack_gap(vma, addr, len)) {
14331 /*
14332 * Remember the place where we stopped the search:
14333 */
14334 @@ -128,7 +131,7 @@ arch_get_unmapped_area_topdown(struct fi
14335 {
14336 struct vm_area_struct *vma;
14337 struct mm_struct *mm = current->mm;
14338 - unsigned long addr = addr0;
14339 + unsigned long base = mm->mmap_base, addr = addr0;
14340
14341 /* requested length too big for entire address space */
14342 if (len > TASK_SIZE)
14343 @@ -141,12 +144,15 @@ arch_get_unmapped_area_topdown(struct fi
14344 if (!test_thread_flag(TIF_IA32) && (flags & MAP_32BIT))
14345 goto bottomup;
14346
14347 +#ifdef CONFIG_PAX_RANDMMAP
14348 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
14349 +#endif
14350 +
14351 /* requesting a specific address */
14352 if (addr) {
14353 addr = PAGE_ALIGN(addr);
14354 vma = find_vma(mm, addr);
14355 - if (TASK_SIZE - len >= addr &&
14356 - (!vma || addr + len <= vma->vm_start))
14357 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
14358 return addr;
14359 }
14360
14361 @@ -162,7 +168,7 @@ arch_get_unmapped_area_topdown(struct fi
14362 /* make sure it can fit in the remaining address space */
14363 if (addr > len) {
14364 vma = find_vma(mm, addr-len);
14365 - if (!vma || addr <= vma->vm_start)
14366 + if (check_heap_stack_gap(vma, addr - len, len))
14367 /* remember the address as a hint for next time */
14368 return mm->free_area_cache = addr-len;
14369 }
14370 @@ -179,7 +185,7 @@ arch_get_unmapped_area_topdown(struct fi
14371 * return with success:
14372 */
14373 vma = find_vma(mm, addr);
14374 - if (!vma || addr+len <= vma->vm_start)
14375 + if (check_heap_stack_gap(vma, addr, len))
14376 /* remember the address as a hint for next time */
14377 return mm->free_area_cache = addr;
14378
14379 @@ -198,13 +204,21 @@ bottomup:
14380 * can happen with large stack limits and large mmap()
14381 * allocations.
14382 */
14383 + mm->mmap_base = TASK_UNMAPPED_BASE;
14384 +
14385 +#ifdef CONFIG_PAX_RANDMMAP
14386 + if (mm->pax_flags & MF_PAX_RANDMMAP)
14387 + mm->mmap_base += mm->delta_mmap;
14388 +#endif
14389 +
14390 + mm->free_area_cache = mm->mmap_base;
14391 mm->cached_hole_size = ~0UL;
14392 - mm->free_area_cache = TASK_UNMAPPED_BASE;
14393 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
14394 /*
14395 * Restore the topdown base:
14396 */
14397 - mm->free_area_cache = mm->mmap_base;
14398 + mm->mmap_base = base;
14399 + mm->free_area_cache = base;
14400 mm->cached_hole_size = ~0UL;
14401
14402 return addr;
14403 diff -urNp linux-2.6.37/arch/x86/kernel/time.c linux-2.6.37/arch/x86/kernel/time.c
14404 --- linux-2.6.37/arch/x86/kernel/time.c 2011-01-04 19:50:19.000000000 -0500
14405 +++ linux-2.6.37/arch/x86/kernel/time.c 2011-01-17 02:41:01.000000000 -0500
14406 @@ -26,17 +26,13 @@
14407 int timer_ack;
14408 #endif
14409
14410 -#ifdef CONFIG_X86_64
14411 -volatile unsigned long __jiffies __section_jiffies = INITIAL_JIFFIES;
14412 -#endif
14413 -
14414 unsigned long profile_pc(struct pt_regs *regs)
14415 {
14416 unsigned long pc = instruction_pointer(regs);
14417
14418 - if (!user_mode_vm(regs) && in_lock_functions(pc)) {
14419 + if (!user_mode(regs) && in_lock_functions(pc)) {
14420 #ifdef CONFIG_FRAME_POINTER
14421 - return *(unsigned long *)(regs->bp + sizeof(long));
14422 + return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
14423 #else
14424 unsigned long *sp =
14425 (unsigned long *)kernel_stack_pointer(regs);
14426 @@ -45,11 +41,17 @@ unsigned long profile_pc(struct pt_regs
14427 * or above a saved flags. Eflags has bits 22-31 zero,
14428 * kernel addresses don't.
14429 */
14430 +
14431 +#ifdef CONFIG_PAX_KERNEXEC
14432 + return ktla_ktva(sp[0]);
14433 +#else
14434 if (sp[0] >> 22)
14435 return sp[0];
14436 if (sp[1] >> 22)
14437 return sp[1];
14438 #endif
14439 +
14440 +#endif
14441 }
14442 return pc;
14443 }
14444 diff -urNp linux-2.6.37/arch/x86/kernel/tls.c linux-2.6.37/arch/x86/kernel/tls.c
14445 --- linux-2.6.37/arch/x86/kernel/tls.c 2011-01-04 19:50:19.000000000 -0500
14446 +++ linux-2.6.37/arch/x86/kernel/tls.c 2011-01-17 02:41:01.000000000 -0500
14447 @@ -85,6 +85,11 @@ int do_set_thread_area(struct task_struc
14448 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
14449 return -EINVAL;
14450
14451 +#ifdef CONFIG_PAX_SEGMEXEC
14452 + if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
14453 + return -EINVAL;
14454 +#endif
14455 +
14456 set_tls_desc(p, idx, &info, 1);
14457
14458 return 0;
14459 diff -urNp linux-2.6.37/arch/x86/kernel/trampoline_32.S linux-2.6.37/arch/x86/kernel/trampoline_32.S
14460 --- linux-2.6.37/arch/x86/kernel/trampoline_32.S 2011-01-04 19:50:19.000000000 -0500
14461 +++ linux-2.6.37/arch/x86/kernel/trampoline_32.S 2011-01-17 02:41:01.000000000 -0500
14462 @@ -32,6 +32,12 @@
14463 #include <asm/segment.h>
14464 #include <asm/page_types.h>
14465
14466 +#ifdef CONFIG_PAX_KERNEXEC
14467 +#define ta(X) (X)
14468 +#else
14469 +#define ta(X) ((X) - __PAGE_OFFSET)
14470 +#endif
14471 +
14472 /* We can free up trampoline after bootup if cpu hotplug is not supported. */
14473 __CPUINITRODATA
14474 .code16
14475 @@ -60,7 +66,7 @@ r_base = .
14476 inc %ax # protected mode (PE) bit
14477 lmsw %ax # into protected mode
14478 # flush prefetch and jump to startup_32_smp in arch/i386/kernel/head.S
14479 - ljmpl $__BOOT_CS, $(startup_32_smp-__PAGE_OFFSET)
14480 + ljmpl $__BOOT_CS, $ta(startup_32_smp)
14481
14482 # These need to be in the same 64K segment as the above;
14483 # hence we don't use the boot_gdt_descr defined in head.S
14484 diff -urNp linux-2.6.37/arch/x86/kernel/trampoline_64.S linux-2.6.37/arch/x86/kernel/trampoline_64.S
14485 --- linux-2.6.37/arch/x86/kernel/trampoline_64.S 2011-01-04 19:50:19.000000000 -0500
14486 +++ linux-2.6.37/arch/x86/kernel/trampoline_64.S 2011-01-17 02:41:01.000000000 -0500
14487 @@ -91,7 +91,7 @@ startup_32:
14488 movl $__KERNEL_DS, %eax # Initialize the %ds segment register
14489 movl %eax, %ds
14490
14491 - movl $X86_CR4_PAE, %eax
14492 + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
14493 movl %eax, %cr4 # Enable PAE mode
14494
14495 # Setup trampoline 4 level pagetables
14496 @@ -138,7 +138,7 @@ tidt:
14497 # so the kernel can live anywhere
14498 .balign 4
14499 tgdt:
14500 - .short tgdt_end - tgdt # gdt limit
14501 + .short tgdt_end - tgdt - 1 # gdt limit
14502 .long tgdt - r_base
14503 .short 0
14504 .quad 0x00cf9b000000ffff # __KERNEL32_CS
14505 diff -urNp linux-2.6.37/arch/x86/kernel/traps.c linux-2.6.37/arch/x86/kernel/traps.c
14506 --- linux-2.6.37/arch/x86/kernel/traps.c 2011-01-04 19:50:19.000000000 -0500
14507 +++ linux-2.6.37/arch/x86/kernel/traps.c 2011-01-17 02:41:01.000000000 -0500
14508 @@ -70,12 +70,6 @@ asmlinkage int system_call(void);
14509
14510 /* Do we ignore FPU interrupts ? */
14511 char ignore_fpu_irq;
14512 -
14513 -/*
14514 - * The IDT has to be page-aligned to simplify the Pentium
14515 - * F0 0F bug workaround.
14516 - */
14517 -gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
14518 #endif
14519
14520 DECLARE_BITMAP(used_vectors, NR_VECTORS);
14521 @@ -110,13 +104,13 @@ static inline void preempt_conditional_c
14522 }
14523
14524 static void __kprobes
14525 -do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
14526 +do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
14527 long error_code, siginfo_t *info)
14528 {
14529 struct task_struct *tsk = current;
14530
14531 #ifdef CONFIG_X86_32
14532 - if (regs->flags & X86_VM_MASK) {
14533 + if (v8086_mode(regs)) {
14534 /*
14535 * traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
14536 * On nmi (interrupt 2), do_trap should not be called.
14537 @@ -127,7 +121,7 @@ do_trap(int trapnr, int signr, char *str
14538 }
14539 #endif
14540
14541 - if (!user_mode(regs))
14542 + if (!user_mode_novm(regs))
14543 goto kernel_trap;
14544
14545 #ifdef CONFIG_X86_32
14546 @@ -150,7 +144,7 @@ trap_signal:
14547 printk_ratelimit()) {
14548 printk(KERN_INFO
14549 "%s[%d] trap %s ip:%lx sp:%lx error:%lx",
14550 - tsk->comm, tsk->pid, str,
14551 + tsk->comm, task_pid_nr(tsk), str,
14552 regs->ip, regs->sp, error_code);
14553 print_vma_addr(" in ", regs->ip);
14554 printk("\n");
14555 @@ -167,8 +161,20 @@ kernel_trap:
14556 if (!fixup_exception(regs)) {
14557 tsk->thread.error_code = error_code;
14558 tsk->thread.trap_no = trapnr;
14559 +
14560 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
14561 + if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
14562 + str = "PAX: suspicious stack segment fault";
14563 +#endif
14564 +
14565 die(str, regs, error_code);
14566 }
14567 +
14568 +#ifdef CONFIG_PAX_REFCOUNT
14569 + if (trapnr == 4)
14570 + pax_report_refcount_overflow(regs);
14571 +#endif
14572 +
14573 return;
14574
14575 #ifdef CONFIG_X86_32
14576 @@ -257,14 +263,30 @@ do_general_protection(struct pt_regs *re
14577 conditional_sti(regs);
14578
14579 #ifdef CONFIG_X86_32
14580 - if (regs->flags & X86_VM_MASK)
14581 + if (v8086_mode(regs))
14582 goto gp_in_vm86;
14583 #endif
14584
14585 tsk = current;
14586 - if (!user_mode(regs))
14587 + if (!user_mode_novm(regs))
14588 goto gp_in_kernel;
14589
14590 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
14591 + if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
14592 + struct mm_struct *mm = tsk->mm;
14593 + unsigned long limit;
14594 +
14595 + down_write(&mm->mmap_sem);
14596 + limit = mm->context.user_cs_limit;
14597 + if (limit < TASK_SIZE) {
14598 + track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
14599 + up_write(&mm->mmap_sem);
14600 + return;
14601 + }
14602 + up_write(&mm->mmap_sem);
14603 + }
14604 +#endif
14605 +
14606 tsk->thread.error_code = error_code;
14607 tsk->thread.trap_no = 13;
14608
14609 @@ -297,6 +319,13 @@ gp_in_kernel:
14610 if (notify_die(DIE_GPF, "general protection fault", regs,
14611 error_code, 13, SIGSEGV) == NOTIFY_STOP)
14612 return;
14613 +
14614 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
14615 + if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
14616 + die("PAX: suspicious general protection fault", regs, error_code);
14617 + else
14618 +#endif
14619 +
14620 die("general protection fault", regs, error_code);
14621 }
14622
14623 @@ -572,7 +601,7 @@ dotraplinkage void __kprobes do_debug(st
14624 /* It's safe to allow irq's after DR6 has been saved */
14625 preempt_conditional_sti(regs);
14626
14627 - if (regs->flags & X86_VM_MASK) {
14628 + if (v8086_mode(regs)) {
14629 handle_vm86_trap((struct kernel_vm86_regs *) regs,
14630 error_code, 1);
14631 preempt_conditional_cli(regs);
14632 @@ -586,7 +615,7 @@ dotraplinkage void __kprobes do_debug(st
14633 * We already checked v86 mode above, so we can check for kernel mode
14634 * by just checking the CPL of CS.
14635 */
14636 - if ((dr6 & DR_STEP) && !user_mode(regs)) {
14637 + if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
14638 tsk->thread.debugreg6 &= ~DR_STEP;
14639 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
14640 regs->flags &= ~X86_EFLAGS_TF;
14641 @@ -615,7 +644,7 @@ void math_error(struct pt_regs *regs, in
14642 return;
14643 conditional_sti(regs);
14644
14645 - if (!user_mode_vm(regs))
14646 + if (!user_mode(regs))
14647 {
14648 if (!fixup_exception(regs)) {
14649 task->thread.error_code = error_code;
14650 diff -urNp linux-2.6.37/arch/x86/kernel/tsc.c linux-2.6.37/arch/x86/kernel/tsc.c
14651 --- linux-2.6.37/arch/x86/kernel/tsc.c 2011-01-04 19:50:19.000000000 -0500
14652 +++ linux-2.6.37/arch/x86/kernel/tsc.c 2011-01-17 02:41:01.000000000 -0500
14653 @@ -837,7 +837,7 @@ static struct dmi_system_id __initdata b
14654 DMI_MATCH(DMI_BOARD_NAME, "2635FA0"),
14655 },
14656 },
14657 - {}
14658 + { NULL, NULL, {{0, {0}}}, NULL}
14659 };
14660
14661 static void __init check_system_tsc_reliable(void)
14662 diff -urNp linux-2.6.37/arch/x86/kernel/vm86_32.c linux-2.6.37/arch/x86/kernel/vm86_32.c
14663 --- linux-2.6.37/arch/x86/kernel/vm86_32.c 2011-01-04 19:50:19.000000000 -0500
14664 +++ linux-2.6.37/arch/x86/kernel/vm86_32.c 2011-01-17 02:41:01.000000000 -0500
14665 @@ -41,6 +41,7 @@
14666 #include <linux/ptrace.h>
14667 #include <linux/audit.h>
14668 #include <linux/stddef.h>
14669 +#include <linux/grsecurity.h>
14670
14671 #include <asm/uaccess.h>
14672 #include <asm/io.h>
14673 @@ -148,7 +149,7 @@ struct pt_regs *save_v86_state(struct ke
14674 do_exit(SIGSEGV);
14675 }
14676
14677 - tss = &per_cpu(init_tss, get_cpu());
14678 + tss = init_tss + get_cpu();
14679 current->thread.sp0 = current->thread.saved_sp0;
14680 current->thread.sysenter_cs = __KERNEL_CS;
14681 load_sp0(tss, &current->thread);
14682 @@ -207,6 +208,13 @@ int sys_vm86old(struct vm86_struct __use
14683 struct task_struct *tsk;
14684 int tmp, ret = -EPERM;
14685
14686 +#ifdef CONFIG_GRKERNSEC_VM86
14687 + if (!capable(CAP_SYS_RAWIO)) {
14688 + gr_handle_vm86();
14689 + goto out;
14690 + }
14691 +#endif
14692 +
14693 tsk = current;
14694 if (tsk->thread.saved_sp0)
14695 goto out;
14696 @@ -237,6 +245,14 @@ int sys_vm86(unsigned long cmd, unsigned
14697 int tmp, ret;
14698 struct vm86plus_struct __user *v86;
14699
14700 +#ifdef CONFIG_GRKERNSEC_VM86
14701 + if (!capable(CAP_SYS_RAWIO)) {
14702 + gr_handle_vm86();
14703 + ret = -EPERM;
14704 + goto out;
14705 + }
14706 +#endif
14707 +
14708 tsk = current;
14709 switch (cmd) {
14710 case VM86_REQUEST_IRQ:
14711 @@ -323,7 +339,7 @@ static void do_sys_vm86(struct kernel_vm
14712 tsk->thread.saved_fs = info->regs32->fs;
14713 tsk->thread.saved_gs = get_user_gs(info->regs32);
14714
14715 - tss = &per_cpu(init_tss, get_cpu());
14716 + tss = init_tss + get_cpu();
14717 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
14718 if (cpu_has_sep)
14719 tsk->thread.sysenter_cs = 0;
14720 @@ -528,7 +544,7 @@ static void do_int(struct kernel_vm86_re
14721 goto cannot_handle;
14722 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
14723 goto cannot_handle;
14724 - intr_ptr = (unsigned long __user *) (i << 2);
14725 + intr_ptr = (__force unsigned long __user *) (i << 2);
14726 if (get_user(segoffs, intr_ptr))
14727 goto cannot_handle;
14728 if ((segoffs >> 16) == BIOSSEG)
14729 diff -urNp linux-2.6.37/arch/x86/kernel/vmlinux.lds.S linux-2.6.37/arch/x86/kernel/vmlinux.lds.S
14730 --- linux-2.6.37/arch/x86/kernel/vmlinux.lds.S 2011-01-04 19:50:19.000000000 -0500
14731 +++ linux-2.6.37/arch/x86/kernel/vmlinux.lds.S 2011-01-17 02:41:01.000000000 -0500
14732 @@ -26,6 +26,13 @@
14733 #include <asm/page_types.h>
14734 #include <asm/cache.h>
14735 #include <asm/boot.h>
14736 +#include <asm/segment.h>
14737 +
14738 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
14739 +#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
14740 +#else
14741 +#define __KERNEL_TEXT_OFFSET 0
14742 +#endif
14743
14744 #undef i386 /* in case the preprocessor is a 32bit one */
14745
14746 @@ -34,11 +41,9 @@ OUTPUT_FORMAT(CONFIG_OUTPUT_FORMAT, CONF
14747 #ifdef CONFIG_X86_32
14748 OUTPUT_ARCH(i386)
14749 ENTRY(phys_startup_32)
14750 -jiffies = jiffies_64;
14751 #else
14752 OUTPUT_ARCH(i386:x86-64)
14753 ENTRY(phys_startup_64)
14754 -jiffies_64 = jiffies;
14755 #endif
14756
14757 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
14758 @@ -69,31 +74,46 @@ jiffies_64 = jiffies;
14759
14760 PHDRS {
14761 text PT_LOAD FLAGS(5); /* R_E */
14762 - data PT_LOAD FLAGS(7); /* RWE */
14763 +#ifdef CONFIG_X86_32
14764 + module PT_LOAD FLAGS(5); /* R_E */
14765 +#endif
14766 +#ifdef CONFIG_XEN
14767 + rodata PT_LOAD FLAGS(5); /* R_E */
14768 +#else
14769 + rodata PT_LOAD FLAGS(4); /* R__ */
14770 +#endif
14771 + data PT_LOAD FLAGS(6); /* RW_ */
14772 #ifdef CONFIG_X86_64
14773 user PT_LOAD FLAGS(5); /* R_E */
14774 +#endif
14775 + init.begin PT_LOAD FLAGS(6); /* RW_ */
14776 #ifdef CONFIG_SMP
14777 percpu PT_LOAD FLAGS(6); /* RW_ */
14778 #endif
14779 + text.init PT_LOAD FLAGS(5); /* R_E */
14780 + text.exit PT_LOAD FLAGS(5); /* R_E */
14781 init PT_LOAD FLAGS(7); /* RWE */
14782 -#endif
14783 note PT_NOTE FLAGS(0); /* ___ */
14784 }
14785
14786 SECTIONS
14787 {
14788 #ifdef CONFIG_X86_32
14789 - . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
14790 - phys_startup_32 = startup_32 - LOAD_OFFSET;
14791 + . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
14792 #else
14793 - . = __START_KERNEL;
14794 - phys_startup_64 = startup_64 - LOAD_OFFSET;
14795 + . = __START_KERNEL;
14796 #endif
14797
14798 /* Text and read-only data */
14799 - .text : AT(ADDR(.text) - LOAD_OFFSET) {
14800 - _text = .;
14801 + .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
14802 /* bootstrapping code */
14803 +#ifdef CONFIG_X86_32
14804 + phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
14805 +#else
14806 + phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
14807 +#endif
14808 + __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
14809 + _text = .;
14810 HEAD_TEXT
14811 #ifdef CONFIG_X86_32
14812 . = ALIGN(PAGE_SIZE);
14813 @@ -108,13 +128,47 @@ SECTIONS
14814 IRQENTRY_TEXT
14815 *(.fixup)
14816 *(.gnu.warning)
14817 - /* End of text section */
14818 - _etext = .;
14819 } :text = 0x9090
14820
14821 - NOTES :text :note
14822 + . += __KERNEL_TEXT_OFFSET;
14823 +
14824 +#ifdef CONFIG_X86_32
14825 + . = ALIGN(PAGE_SIZE);
14826 + .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
14827 +
14828 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_MODULES)
14829 + MODULES_EXEC_VADDR = .;
14830 + BYTE(0)
14831 + . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
14832 + . = ALIGN(HPAGE_SIZE);
14833 + MODULES_EXEC_END = . - 1;
14834 +#endif
14835 +
14836 + } :module
14837 +#endif
14838 +
14839 + .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
14840 + /* End of text section */
14841 + _etext = . - __KERNEL_TEXT_OFFSET;
14842 + }
14843
14844 - EXCEPTION_TABLE(16) :text = 0x9090
14845 +#ifdef CONFIG_X86_32
14846 + . = ALIGN(PAGE_SIZE);
14847 + .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
14848 + *(.idt)
14849 + . = ALIGN(PAGE_SIZE);
14850 + *(.empty_zero_page)
14851 + *(.initial_pg_fixmap)
14852 + *(.initial_pg_pmd)
14853 + *(.initial_page_table)
14854 + *(.swapper_pg_dir)
14855 + } :rodata
14856 +#endif
14857 +
14858 + . = ALIGN(PAGE_SIZE);
14859 + NOTES :rodata :note
14860 +
14861 + EXCEPTION_TABLE(16) :rodata
14862
14863 X64_ALIGN_DEBUG_RODATA_BEGIN
14864 RO_DATA(PAGE_SIZE)
14865 @@ -122,16 +176,20 @@ SECTIONS
14866
14867 /* Data */
14868 .data : AT(ADDR(.data) - LOAD_OFFSET) {
14869 +
14870 +#ifdef CONFIG_PAX_KERNEXEC
14871 + . = ALIGN(HPAGE_SIZE);
14872 +#else
14873 + . = ALIGN(PAGE_SIZE);
14874 +#endif
14875 +
14876 /* Start of data section */
14877 _sdata = .;
14878
14879 /* init_task */
14880 INIT_TASK_DATA(THREAD_SIZE)
14881
14882 -#ifdef CONFIG_X86_32
14883 - /* 32 bit has nosave before _edata */
14884 NOSAVE_DATA
14885 -#endif
14886
14887 PAGE_ALIGNED_DATA(PAGE_SIZE)
14888
14889 @@ -140,6 +198,8 @@ SECTIONS
14890 DATA_DATA
14891 CONSTRUCTORS
14892
14893 + jiffies = jiffies_64;
14894 +
14895 /* rarely changed data like cpu maps */
14896 READ_MOSTLY_DATA(INTERNODE_CACHE_BYTES)
14897
14898 @@ -194,12 +254,6 @@ SECTIONS
14899 }
14900 vgetcpu_mode = VVIRT(.vgetcpu_mode);
14901
14902 - . = ALIGN(L1_CACHE_BYTES);
14903 - .jiffies : AT(VLOAD(.jiffies)) {
14904 - *(.jiffies)
14905 - }
14906 - jiffies = VVIRT(.jiffies);
14907 -
14908 .vsyscall_3 ADDR(.vsyscall_0) + 3072: AT(VLOAD(.vsyscall_3)) {
14909 *(.vsyscall_3)
14910 }
14911 @@ -215,12 +269,19 @@ SECTIONS
14912 #endif /* CONFIG_X86_64 */
14913
14914 /* Init code and data - will be freed after init */
14915 - . = ALIGN(PAGE_SIZE);
14916 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
14917 + BYTE(0)
14918 +
14919 +#ifdef CONFIG_PAX_KERNEXEC
14920 + . = ALIGN(HPAGE_SIZE);
14921 +#else
14922 + . = ALIGN(PAGE_SIZE);
14923 +#endif
14924 +
14925 __init_begin = .; /* paired with __init_end */
14926 - }
14927 + } :init.begin
14928
14929 -#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
14930 +#ifdef CONFIG_SMP
14931 /*
14932 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
14933 * output PHDR, so the next output section - .init.text - should
14934 @@ -229,12 +290,27 @@ SECTIONS
14935 PERCPU_VADDR(0, :percpu)
14936 #endif
14937
14938 - INIT_TEXT_SECTION(PAGE_SIZE)
14939 -#ifdef CONFIG_X86_64
14940 - :init
14941 -#endif
14942 + . = ALIGN(PAGE_SIZE);
14943 + init_begin = .;
14944 + .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
14945 + VMLINUX_SYMBOL(_sinittext) = .;
14946 + INIT_TEXT
14947 + VMLINUX_SYMBOL(_einittext) = .;
14948 + . = ALIGN(PAGE_SIZE);
14949 + } :text.init
14950
14951 - INIT_DATA_SECTION(16)
14952 + /*
14953 + * .exit.text is discard at runtime, not link time, to deal with
14954 + * references from .altinstructions and .eh_frame
14955 + */
14956 + .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
14957 + EXIT_TEXT
14958 + . = ALIGN(16);
14959 + } :text.exit
14960 + . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
14961 +
14962 + . = ALIGN(PAGE_SIZE);
14963 + INIT_DATA_SECTION(16) :init
14964
14965 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
14966 __x86_cpu_dev_start = .;
14967 @@ -288,19 +364,12 @@ SECTIONS
14968 __iommu_table_end = .;
14969 }
14970 . = ALIGN(8);
14971 - /*
14972 - * .exit.text is discard at runtime, not link time, to deal with
14973 - * references from .altinstructions and .eh_frame
14974 - */
14975 - .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
14976 - EXIT_TEXT
14977 - }
14978
14979 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
14980 EXIT_DATA
14981 }
14982
14983 -#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
14984 +#ifndef CONFIG_SMP
14985 PERCPU(THREAD_SIZE)
14986 #endif
14987
14988 @@ -319,16 +388,10 @@ SECTIONS
14989 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
14990 __smp_locks = .;
14991 *(.smp_locks)
14992 - . = ALIGN(PAGE_SIZE);
14993 __smp_locks_end = .;
14994 + . = ALIGN(PAGE_SIZE);
14995 }
14996
14997 -#ifdef CONFIG_X86_64
14998 - .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
14999 - NOSAVE_DATA
15000 - }
15001 -#endif
15002 -
15003 /* BSS */
15004 . = ALIGN(PAGE_SIZE);
15005 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
15006 @@ -344,6 +407,7 @@ SECTIONS
15007 __brk_base = .;
15008 . += 64 * 1024; /* 64k alignment slop space */
15009 *(.brk_reservation) /* areas brk users have reserved */
15010 + . = ALIGN(HPAGE_SIZE);
15011 __brk_limit = .;
15012 }
15013
15014 @@ -370,13 +434,12 @@ SECTIONS
15015 * for the boot processor.
15016 */
15017 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
15018 -INIT_PER_CPU(gdt_page);
15019 INIT_PER_CPU(irq_stack_union);
15020
15021 /*
15022 * Build-time check on the image size:
15023 */
15024 -. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
15025 +. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
15026 "kernel image bigger than KERNEL_IMAGE_SIZE");
15027
15028 #ifdef CONFIG_SMP
15029 diff -urNp linux-2.6.37/arch/x86/kernel/vsyscall_64.c linux-2.6.37/arch/x86/kernel/vsyscall_64.c
15030 --- linux-2.6.37/arch/x86/kernel/vsyscall_64.c 2011-01-04 19:50:19.000000000 -0500
15031 +++ linux-2.6.37/arch/x86/kernel/vsyscall_64.c 2011-01-17 02:41:01.000000000 -0500
15032 @@ -80,6 +80,7 @@ void update_vsyscall(struct timespec *wa
15033
15034 write_seqlock_irqsave(&vsyscall_gtod_data.lock, flags);
15035 /* copy vsyscall data */
15036 + strlcpy(vsyscall_gtod_data.clock.name, clock->name, sizeof vsyscall_gtod_data.clock.name);
15037 vsyscall_gtod_data.clock.vread = clock->vread;
15038 vsyscall_gtod_data.clock.cycle_last = clock->cycle_last;
15039 vsyscall_gtod_data.clock.mask = clock->mask;
15040 @@ -208,7 +209,7 @@ vgetcpu(unsigned *cpu, unsigned *node, s
15041 We do this here because otherwise user space would do it on
15042 its own in a likely inferior way (no access to jiffies).
15043 If you don't like it pass NULL. */
15044 - if (tcache && tcache->blob[0] == (j = __jiffies)) {
15045 + if (tcache && tcache->blob[0] == (j = jiffies)) {
15046 p = tcache->blob[1];
15047 } else if (__vgetcpu_mode == VGETCPU_RDTSCP) {
15048 /* Load per CPU data from RDTSCP */
15049 diff -urNp linux-2.6.37/arch/x86/kernel/x8664_ksyms_64.c linux-2.6.37/arch/x86/kernel/x8664_ksyms_64.c
15050 --- linux-2.6.37/arch/x86/kernel/x8664_ksyms_64.c 2011-01-04 19:50:19.000000000 -0500
15051 +++ linux-2.6.37/arch/x86/kernel/x8664_ksyms_64.c 2011-01-17 02:41:01.000000000 -0500
15052 @@ -29,8 +29,6 @@ EXPORT_SYMBOL(__put_user_8);
15053 EXPORT_SYMBOL(copy_user_generic_string);
15054 EXPORT_SYMBOL(copy_user_generic_unrolled);
15055 EXPORT_SYMBOL(__copy_user_nocache);
15056 -EXPORT_SYMBOL(_copy_from_user);
15057 -EXPORT_SYMBOL(_copy_to_user);
15058
15059 EXPORT_SYMBOL(copy_page);
15060 EXPORT_SYMBOL(clear_page);
15061 diff -urNp linux-2.6.37/arch/x86/kernel/xsave.c linux-2.6.37/arch/x86/kernel/xsave.c
15062 --- linux-2.6.37/arch/x86/kernel/xsave.c 2011-01-04 19:50:19.000000000 -0500
15063 +++ linux-2.6.37/arch/x86/kernel/xsave.c 2011-01-17 02:41:01.000000000 -0500
15064 @@ -130,7 +130,7 @@ int check_for_xstate(struct i387_fxsave_
15065 fx_sw_user->xstate_size > fx_sw_user->extended_size)
15066 return -EINVAL;
15067
15068 - err = __get_user(magic2, (__u32 *) (((void *)fpstate) +
15069 + err = __get_user(magic2, (__u32 __user *) (((void __user *)fpstate) +
15070 fx_sw_user->extended_size -
15071 FP_XSTATE_MAGIC2_SIZE));
15072 if (err)
15073 @@ -267,7 +267,7 @@ fx_only:
15074 * the other extended state.
15075 */
15076 xrstor_state(init_xstate_buf, pcntxt_mask & ~XSTATE_FPSSE);
15077 - return fxrstor_checking((__force struct i387_fxsave_struct *)buf);
15078 + return fxrstor_checking((struct i387_fxsave_struct __user *)buf);
15079 }
15080
15081 /*
15082 @@ -299,7 +299,7 @@ int restore_i387_xstate(void __user *buf
15083 if (use_xsave())
15084 err = restore_user_xstate(buf);
15085 else
15086 - err = fxrstor_checking((__force struct i387_fxsave_struct *)
15087 + err = fxrstor_checking((struct i387_fxsave_struct __user *)
15088 buf);
15089 if (unlikely(err)) {
15090 /*
15091 diff -urNp linux-2.6.37/arch/x86/kvm/emulate.c linux-2.6.37/arch/x86/kvm/emulate.c
15092 --- linux-2.6.37/arch/x86/kvm/emulate.c 2011-01-04 19:50:19.000000000 -0500
15093 +++ linux-2.6.37/arch/x86/kvm/emulate.c 2011-01-17 02:41:01.000000000 -0500
15094 @@ -96,7 +96,7 @@
15095 #define Src2ImmByte (2<<29)
15096 #define Src2One (3<<29)
15097 #define Src2Imm (4<<29)
15098 -#define Src2Mask (7<<29)
15099 +#define Src2Mask (7U<<29)
15100
15101 #define X2(x...) x, x
15102 #define X3(x...) X2(x), x
15103 @@ -197,6 +197,7 @@ struct group_dual {
15104
15105 #define ____emulate_2op(_op, _src, _dst, _eflags, _x, _y, _suffix, _dsttype) \
15106 do { \
15107 + unsigned long _tmp; \
15108 __asm__ __volatile__ ( \
15109 _PRE_EFLAGS("0", "4", "2") \
15110 _op _suffix " %"_x"3,%1; " \
15111 @@ -210,8 +211,6 @@ struct group_dual {
15112 /* Raw emulation: instruction has two explicit operands. */
15113 #define __emulate_2op_nobyte(_op,_src,_dst,_eflags,_wx,_wy,_lx,_ly,_qx,_qy) \
15114 do { \
15115 - unsigned long _tmp; \
15116 - \
15117 switch ((_dst).bytes) { \
15118 case 2: \
15119 ____emulate_2op(_op,_src,_dst,_eflags,_wx,_wy,"w",u16);\
15120 @@ -227,7 +226,6 @@ struct group_dual {
15121
15122 #define __emulate_2op(_op,_src,_dst,_eflags,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy) \
15123 do { \
15124 - unsigned long _tmp; \
15125 switch ((_dst).bytes) { \
15126 case 1: \
15127 ____emulate_2op(_op,_src,_dst,_eflags,_bx,_by,"b",u8); \
15128 diff -urNp linux-2.6.37/arch/x86/kvm/lapic.c linux-2.6.37/arch/x86/kvm/lapic.c
15129 --- linux-2.6.37/arch/x86/kvm/lapic.c 2011-01-04 19:50:19.000000000 -0500
15130 +++ linux-2.6.37/arch/x86/kvm/lapic.c 2011-01-17 02:41:01.000000000 -0500
15131 @@ -53,7 +53,7 @@
15132 #define APIC_BUS_CYCLE_NS 1
15133
15134 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
15135 -#define apic_debug(fmt, arg...)
15136 +#define apic_debug(fmt, arg...) do {} while (0)
15137
15138 #define APIC_LVT_NUM 6
15139 /* 14 is the version for Xeon and Pentium 8.4.8*/
15140 diff -urNp linux-2.6.37/arch/x86/kvm/svm.c linux-2.6.37/arch/x86/kvm/svm.c
15141 --- linux-2.6.37/arch/x86/kvm/svm.c 2011-01-04 19:50:19.000000000 -0500
15142 +++ linux-2.6.37/arch/x86/kvm/svm.c 2011-01-17 02:41:01.000000000 -0500
15143 @@ -3023,7 +3023,11 @@ static void reload_tss(struct kvm_vcpu *
15144 int cpu = raw_smp_processor_id();
15145
15146 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
15147 +
15148 + pax_open_kernel();
15149 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
15150 + pax_close_kernel();
15151 +
15152 load_TR_desc();
15153 }
15154
15155 @@ -3600,7 +3604,7 @@ static void svm_fpu_deactivate(struct kv
15156 update_cr0_intercept(svm);
15157 }
15158
15159 -static struct kvm_x86_ops svm_x86_ops = {
15160 +static const struct kvm_x86_ops svm_x86_ops = {
15161 .cpu_has_kvm_support = has_svm,
15162 .disabled_by_bios = is_disabled,
15163 .hardware_setup = svm_hardware_setup,
15164 diff -urNp linux-2.6.37/arch/x86/kvm/vmx.c linux-2.6.37/arch/x86/kvm/vmx.c
15165 --- linux-2.6.37/arch/x86/kvm/vmx.c 2011-01-04 19:50:19.000000000 -0500
15166 +++ linux-2.6.37/arch/x86/kvm/vmx.c 2011-01-17 02:41:01.000000000 -0500
15167 @@ -705,7 +705,11 @@ static void reload_tss(void)
15168 struct desc_struct *descs;
15169
15170 descs = (void *)gdt->address;
15171 +
15172 + pax_open_kernel();
15173 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
15174 + pax_close_kernel();
15175 +
15176 load_TR_desc();
15177 }
15178
15179 @@ -1589,8 +1593,11 @@ static __init int hardware_setup(void)
15180 if (!cpu_has_vmx_flexpriority())
15181 flexpriority_enabled = 0;
15182
15183 - if (!cpu_has_vmx_tpr_shadow())
15184 - kvm_x86_ops->update_cr8_intercept = NULL;
15185 + if (!cpu_has_vmx_tpr_shadow()) {
15186 + pax_open_kernel();
15187 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
15188 + pax_close_kernel();
15189 + }
15190
15191 if (enable_ept && !cpu_has_vmx_ept_2m_page())
15192 kvm_disable_largepages();
15193 @@ -2575,7 +2582,7 @@ static int vmx_vcpu_setup(struct vcpu_vm
15194 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
15195
15196 asm("mov $.Lkvm_vmx_return, %0" : "=r"(kvm_vmx_return));
15197 - vmcs_writel(HOST_RIP, kvm_vmx_return); /* 22.2.5 */
15198 + vmcs_writel(HOST_RIP, ktla_ktva(kvm_vmx_return)); /* 22.2.5 */
15199 vmcs_write32(VM_EXIT_MSR_STORE_COUNT, 0);
15200 vmcs_write32(VM_EXIT_MSR_LOAD_COUNT, 0);
15201 vmcs_write64(VM_EXIT_MSR_LOAD_ADDR, __pa(vmx->msr_autoload.host));
15202 @@ -3959,6 +3966,12 @@ static void vmx_vcpu_run(struct kvm_vcpu
15203 "jmp .Lkvm_vmx_return \n\t"
15204 ".Llaunched: " __ex(ASM_VMX_VMRESUME) "\n\t"
15205 ".Lkvm_vmx_return: "
15206 +
15207 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
15208 + "ljmp %[cs],$.Lkvm_vmx_return2\n\t"
15209 + ".Lkvm_vmx_return2: "
15210 +#endif
15211 +
15212 /* Save guest registers, load host registers, keep flags */
15213 "xchg %0, (%%"R"sp) \n\t"
15214 "mov %%"R"ax, %c[rax](%0) \n\t"
15215 @@ -4005,6 +4018,11 @@ static void vmx_vcpu_run(struct kvm_vcpu
15216 [r15]"i"(offsetof(struct vcpu_vmx, vcpu.arch.regs[VCPU_REGS_R15])),
15217 #endif
15218 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2))
15219 +
15220 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
15221 + ,[cs]"i"(__KERNEL_CS)
15222 +#endif
15223 +
15224 : "cc", "memory"
15225 , R"ax", R"bx", R"di", R"si"
15226 #ifdef CONFIG_X86_64
15227 @@ -4018,7 +4036,7 @@ static void vmx_vcpu_run(struct kvm_vcpu
15228
15229 vmx->idt_vectoring_info = vmcs_read32(IDT_VECTORING_INFO_FIELD);
15230
15231 - asm("mov %0, %%ds; mov %0, %%es" : : "r"(__USER_DS));
15232 + asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r"(__KERNEL_DS));
15233 vmx->launched = 1;
15234
15235 vmx->exit_reason = vmcs_read32(VM_EXIT_REASON);
15236 @@ -4253,7 +4271,7 @@ static void vmx_set_supported_cpuid(u32
15237 {
15238 }
15239
15240 -static struct kvm_x86_ops vmx_x86_ops = {
15241 +static const struct kvm_x86_ops vmx_x86_ops = {
15242 .cpu_has_kvm_support = cpu_has_kvm_support,
15243 .disabled_by_bios = vmx_disabled_by_bios,
15244 .hardware_setup = hardware_setup,
15245 diff -urNp linux-2.6.37/arch/x86/kvm/x86.c linux-2.6.37/arch/x86/kvm/x86.c
15246 --- linux-2.6.37/arch/x86/kvm/x86.c 2011-01-04 19:50:19.000000000 -0500
15247 +++ linux-2.6.37/arch/x86/kvm/x86.c 2011-01-17 02:41:01.000000000 -0500
15248 @@ -92,7 +92,7 @@ static void update_cr8_intercept(struct
15249 static int kvm_dev_ioctl_get_supported_cpuid(struct kvm_cpuid2 *cpuid,
15250 struct kvm_cpuid_entry2 __user *entries);
15251
15252 -struct kvm_x86_ops *kvm_x86_ops;
15253 +const struct kvm_x86_ops *kvm_x86_ops;
15254 EXPORT_SYMBOL_GPL(kvm_x86_ops);
15255
15256 int ignore_msrs = 0;
15257 @@ -118,38 +118,38 @@ static struct kvm_shared_msrs_global __r
15258 static DEFINE_PER_CPU(struct kvm_shared_msrs, shared_msrs);
15259
15260 struct kvm_stats_debugfs_item debugfs_entries[] = {
15261 - { "pf_fixed", VCPU_STAT(pf_fixed) },
15262 - { "pf_guest", VCPU_STAT(pf_guest) },
15263 - { "tlb_flush", VCPU_STAT(tlb_flush) },
15264 - { "invlpg", VCPU_STAT(invlpg) },
15265 - { "exits", VCPU_STAT(exits) },
15266 - { "io_exits", VCPU_STAT(io_exits) },
15267 - { "mmio_exits", VCPU_STAT(mmio_exits) },
15268 - { "signal_exits", VCPU_STAT(signal_exits) },
15269 - { "irq_window", VCPU_STAT(irq_window_exits) },
15270 - { "nmi_window", VCPU_STAT(nmi_window_exits) },
15271 - { "halt_exits", VCPU_STAT(halt_exits) },
15272 - { "halt_wakeup", VCPU_STAT(halt_wakeup) },
15273 - { "hypercalls", VCPU_STAT(hypercalls) },
15274 - { "request_irq", VCPU_STAT(request_irq_exits) },
15275 - { "irq_exits", VCPU_STAT(irq_exits) },
15276 - { "host_state_reload", VCPU_STAT(host_state_reload) },
15277 - { "efer_reload", VCPU_STAT(efer_reload) },
15278 - { "fpu_reload", VCPU_STAT(fpu_reload) },
15279 - { "insn_emulation", VCPU_STAT(insn_emulation) },
15280 - { "insn_emulation_fail", VCPU_STAT(insn_emulation_fail) },
15281 - { "irq_injections", VCPU_STAT(irq_injections) },
15282 - { "nmi_injections", VCPU_STAT(nmi_injections) },
15283 - { "mmu_shadow_zapped", VM_STAT(mmu_shadow_zapped) },
15284 - { "mmu_pte_write", VM_STAT(mmu_pte_write) },
15285 - { "mmu_pte_updated", VM_STAT(mmu_pte_updated) },
15286 - { "mmu_pde_zapped", VM_STAT(mmu_pde_zapped) },
15287 - { "mmu_flooded", VM_STAT(mmu_flooded) },
15288 - { "mmu_recycled", VM_STAT(mmu_recycled) },
15289 - { "mmu_cache_miss", VM_STAT(mmu_cache_miss) },
15290 - { "mmu_unsync", VM_STAT(mmu_unsync) },
15291 - { "remote_tlb_flush", VM_STAT(remote_tlb_flush) },
15292 - { "largepages", VM_STAT(lpages) },
15293 + { "pf_fixed", VCPU_STAT(pf_fixed), NULL },
15294 + { "pf_guest", VCPU_STAT(pf_guest), NULL },
15295 + { "tlb_flush", VCPU_STAT(tlb_flush), NULL },
15296 + { "invlpg", VCPU_STAT(invlpg), NULL },
15297 + { "exits", VCPU_STAT(exits), NULL },
15298 + { "io_exits", VCPU_STAT(io_exits), NULL },
15299 + { "mmio_exits", VCPU_STAT(mmio_exits), NULL },
15300 + { "signal_exits", VCPU_STAT(signal_exits), NULL },
15301 + { "irq_window", VCPU_STAT(irq_window_exits), NULL },
15302 + { "nmi_window", VCPU_STAT(nmi_window_exits), NULL },
15303 + { "halt_exits", VCPU_STAT(halt_exits), NULL },
15304 + { "halt_wakeup", VCPU_STAT(halt_wakeup), NULL },
15305 + { "hypercalls", VCPU_STAT(hypercalls), NULL },
15306 + { "request_irq", VCPU_STAT(request_irq_exits), NULL },
15307 + { "irq_exits", VCPU_STAT(irq_exits), NULL },
15308 + { "host_state_reload", VCPU_STAT(host_state_reload), NULL },
15309 + { "efer_reload", VCPU_STAT(efer_reload), NULL },
15310 + { "fpu_reload", VCPU_STAT(fpu_reload), NULL },
15311 + { "insn_emulation", VCPU_STAT(insn_emulation), NULL },
15312 + { "insn_emulation_fail", VCPU_STAT(insn_emulation_fail), NULL },
15313 + { "irq_injections", VCPU_STAT(irq_injections), NULL },
15314 + { "nmi_injections", VCPU_STAT(nmi_injections), NULL },
15315 + { "mmu_shadow_zapped", VM_STAT(mmu_shadow_zapped), NULL },
15316 + { "mmu_pte_write", VM_STAT(mmu_pte_write), NULL },
15317 + { "mmu_pte_updated", VM_STAT(mmu_pte_updated), NULL },
15318 + { "mmu_pde_zapped", VM_STAT(mmu_pde_zapped), NULL },
15319 + { "mmu_flooded", VM_STAT(mmu_flooded), NULL },
15320 + { "mmu_recycled", VM_STAT(mmu_recycled), NULL },
15321 + { "mmu_cache_miss", VM_STAT(mmu_cache_miss), NULL },
15322 + { "mmu_unsync", VM_STAT(mmu_unsync), NULL },
15323 + { "remote_tlb_flush", VM_STAT(remote_tlb_flush), NULL },
15324 + { "largepages", VM_STAT(lpages), NULL },
15325 { NULL }
15326 };
15327
15328 @@ -1979,6 +1979,8 @@ long kvm_arch_dev_ioctl(struct file *fil
15329 if (n < msr_list.nmsrs)
15330 goto out;
15331 r = -EFAULT;
15332 + if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
15333 + goto out;
15334 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
15335 num_msrs_to_save * sizeof(u32)))
15336 goto out;
15337 @@ -2446,7 +2448,7 @@ static int kvm_vcpu_ioctl_set_lapic(stru
15338 static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
15339 struct kvm_interrupt *irq)
15340 {
15341 - if (irq->irq < 0 || irq->irq >= 256)
15342 + if (irq->irq >= 256)
15343 return -EINVAL;
15344 if (irqchip_in_kernel(vcpu->kvm))
15345 return -ENXIO;
15346 @@ -4623,10 +4625,10 @@ void kvm_after_handle_nmi(struct kvm_vcp
15347 }
15348 EXPORT_SYMBOL_GPL(kvm_after_handle_nmi);
15349
15350 -int kvm_arch_init(void *opaque)
15351 +int kvm_arch_init(const void *opaque)
15352 {
15353 int r;
15354 - struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
15355 + const struct kvm_x86_ops *ops = (const struct kvm_x86_ops *)opaque;
15356
15357 if (kvm_x86_ops) {
15358 printk(KERN_ERR "kvm: already loaded the other module\n");
15359 diff -urNp linux-2.6.37/arch/x86/lib/atomic64_cx8_32.S linux-2.6.37/arch/x86/lib/atomic64_cx8_32.S
15360 --- linux-2.6.37/arch/x86/lib/atomic64_cx8_32.S 2011-01-04 19:50:19.000000000 -0500
15361 +++ linux-2.6.37/arch/x86/lib/atomic64_cx8_32.S 2011-01-17 02:41:01.000000000 -0500
15362 @@ -86,13 +86,23 @@ ENTRY(atomic64_\func\()_return_cx8)
15363 movl %edx, %ecx
15364 \ins\()l %esi, %ebx
15365 \insc\()l %edi, %ecx
15366 +
15367 +#ifdef CONFIG_PAX_REFCOUNT
15368 + into
15369 +2:
15370 + _ASM_EXTABLE(2b, 3f)
15371 +#endif
15372 +
15373 LOCK_PREFIX
15374 cmpxchg8b (%ebp)
15375 jne 1b
15376 -
15377 -10:
15378 movl %ebx, %eax
15379 movl %ecx, %edx
15380 +
15381 +#ifdef CONFIG_PAX_REFCOUNT
15382 +3:
15383 +#endif
15384 +
15385 RESTORE edi
15386 RESTORE esi
15387 RESTORE ebx
15388 @@ -116,13 +126,24 @@ ENTRY(atomic64_\func\()_return_cx8)
15389 movl %edx, %ecx
15390 \ins\()l $1, %ebx
15391 \insc\()l $0, %ecx
15392 +
15393 +#ifdef CONFIG_PAX_REFCOUNT
15394 + into
15395 +2:
15396 + _ASM_EXTABLE(2b, 3f)
15397 +#endif
15398 +
15399 LOCK_PREFIX
15400 cmpxchg8b (%esi)
15401 jne 1b
15402
15403 -10:
15404 movl %ebx, %eax
15405 movl %ecx, %edx
15406 +
15407 +#ifdef CONFIG_PAX_REFCOUNT
15408 +3:
15409 +#endif
15410 +
15411 RESTORE ebx
15412 ret
15413 CFI_ENDPROC
15414 @@ -176,6 +197,13 @@ ENTRY(atomic64_add_unless_cx8)
15415 movl %edx, %ecx
15416 addl %esi, %ebx
15417 adcl %edi, %ecx
15418 +
15419 +#ifdef CONFIG_PAX_REFCOUNT
15420 + into
15421 +1234:
15422 + _ASM_EXTABLE(1234b, 1234b)
15423 +#endif
15424 +
15425 LOCK_PREFIX
15426 cmpxchg8b (%ebp)
15427 jne 1b
15428 @@ -208,6 +236,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
15429 movl %edx, %ecx
15430 addl $1, %ebx
15431 adcl $0, %ecx
15432 +
15433 +#ifdef CONFIG_PAX_REFCOUNT
15434 + into
15435 +1234:
15436 + _ASM_EXTABLE(1234b, 1234b)
15437 +#endif
15438 +
15439 LOCK_PREFIX
15440 cmpxchg8b (%esi)
15441 jne 1b
15442 diff -urNp linux-2.6.37/arch/x86/lib/checksum_32.S linux-2.6.37/arch/x86/lib/checksum_32.S
15443 --- linux-2.6.37/arch/x86/lib/checksum_32.S 2011-01-04 19:50:19.000000000 -0500
15444 +++ linux-2.6.37/arch/x86/lib/checksum_32.S 2011-01-17 02:41:01.000000000 -0500
15445 @@ -28,7 +28,8 @@
15446 #include <linux/linkage.h>
15447 #include <asm/dwarf2.h>
15448 #include <asm/errno.h>
15449 -
15450 +#include <asm/segment.h>
15451 +
15452 /*
15453 * computes a partial checksum, e.g. for TCP/UDP fragments
15454 */
15455 @@ -304,9 +305,28 @@ unsigned int csum_partial_copy_generic (
15456
15457 #define ARGBASE 16
15458 #define FP 12
15459 -
15460 -ENTRY(csum_partial_copy_generic)
15461 +
15462 +ENTRY(csum_partial_copy_generic_to_user)
15463 CFI_STARTPROC
15464 +
15465 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15466 + pushl %gs
15467 + CFI_ADJUST_CFA_OFFSET 4
15468 + popl %es
15469 + CFI_ADJUST_CFA_OFFSET -4
15470 + jmp csum_partial_copy_generic
15471 +#endif
15472 +
15473 +ENTRY(csum_partial_copy_generic_from_user)
15474 +
15475 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15476 + pushl %gs
15477 + CFI_ADJUST_CFA_OFFSET 4
15478 + popl %ds
15479 + CFI_ADJUST_CFA_OFFSET -4
15480 +#endif
15481 +
15482 +ENTRY(csum_partial_copy_generic)
15483 subl $4,%esp
15484 CFI_ADJUST_CFA_OFFSET 4
15485 pushl %edi
15486 @@ -331,7 +351,7 @@ ENTRY(csum_partial_copy_generic)
15487 jmp 4f
15488 SRC(1: movw (%esi), %bx )
15489 addl $2, %esi
15490 -DST( movw %bx, (%edi) )
15491 +DST( movw %bx, %es:(%edi) )
15492 addl $2, %edi
15493 addw %bx, %ax
15494 adcl $0, %eax
15495 @@ -343,30 +363,30 @@ DST( movw %bx, (%edi) )
15496 SRC(1: movl (%esi), %ebx )
15497 SRC( movl 4(%esi), %edx )
15498 adcl %ebx, %eax
15499 -DST( movl %ebx, (%edi) )
15500 +DST( movl %ebx, %es:(%edi) )
15501 adcl %edx, %eax
15502 -DST( movl %edx, 4(%edi) )
15503 +DST( movl %edx, %es:4(%edi) )
15504
15505 SRC( movl 8(%esi), %ebx )
15506 SRC( movl 12(%esi), %edx )
15507 adcl %ebx, %eax
15508 -DST( movl %ebx, 8(%edi) )
15509 +DST( movl %ebx, %es:8(%edi) )
15510 adcl %edx, %eax
15511 -DST( movl %edx, 12(%edi) )
15512 +DST( movl %edx, %es:12(%edi) )
15513
15514 SRC( movl 16(%esi), %ebx )
15515 SRC( movl 20(%esi), %edx )
15516 adcl %ebx, %eax
15517 -DST( movl %ebx, 16(%edi) )
15518 +DST( movl %ebx, %es:16(%edi) )
15519 adcl %edx, %eax
15520 -DST( movl %edx, 20(%edi) )
15521 +DST( movl %edx, %es:20(%edi) )
15522
15523 SRC( movl 24(%esi), %ebx )
15524 SRC( movl 28(%esi), %edx )
15525 adcl %ebx, %eax
15526 -DST( movl %ebx, 24(%edi) )
15527 +DST( movl %ebx, %es:24(%edi) )
15528 adcl %edx, %eax
15529 -DST( movl %edx, 28(%edi) )
15530 +DST( movl %edx, %es:28(%edi) )
15531
15532 lea 32(%esi), %esi
15533 lea 32(%edi), %edi
15534 @@ -380,7 +400,7 @@ DST( movl %edx, 28(%edi) )
15535 shrl $2, %edx # This clears CF
15536 SRC(3: movl (%esi), %ebx )
15537 adcl %ebx, %eax
15538 -DST( movl %ebx, (%edi) )
15539 +DST( movl %ebx, %es:(%edi) )
15540 lea 4(%esi), %esi
15541 lea 4(%edi), %edi
15542 dec %edx
15543 @@ -392,12 +412,12 @@ DST( movl %ebx, (%edi) )
15544 jb 5f
15545 SRC( movw (%esi), %cx )
15546 leal 2(%esi), %esi
15547 -DST( movw %cx, (%edi) )
15548 +DST( movw %cx, %es:(%edi) )
15549 leal 2(%edi), %edi
15550 je 6f
15551 shll $16,%ecx
15552 SRC(5: movb (%esi), %cl )
15553 -DST( movb %cl, (%edi) )
15554 +DST( movb %cl, %es:(%edi) )
15555 6: addl %ecx, %eax
15556 adcl $0, %eax
15557 7:
15558 @@ -408,7 +428,7 @@ DST( movb %cl, (%edi) )
15559
15560 6001:
15561 movl ARGBASE+20(%esp), %ebx # src_err_ptr
15562 - movl $-EFAULT, (%ebx)
15563 + movl $-EFAULT, %ss:(%ebx)
15564
15565 # zero the complete destination - computing the rest
15566 # is too much work
15567 @@ -421,11 +441,19 @@ DST( movb %cl, (%edi) )
15568
15569 6002:
15570 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
15571 - movl $-EFAULT,(%ebx)
15572 + movl $-EFAULT,%ss:(%ebx)
15573 jmp 5000b
15574
15575 .previous
15576
15577 + pushl %ss
15578 + CFI_ADJUST_CFA_OFFSET 4
15579 + popl %ds
15580 + CFI_ADJUST_CFA_OFFSET -4
15581 + pushl %ss
15582 + CFI_ADJUST_CFA_OFFSET 4
15583 + popl %es
15584 + CFI_ADJUST_CFA_OFFSET -4
15585 popl %ebx
15586 CFI_ADJUST_CFA_OFFSET -4
15587 CFI_RESTORE ebx
15588 @@ -439,26 +467,47 @@ DST( movb %cl, (%edi) )
15589 CFI_ADJUST_CFA_OFFSET -4
15590 ret
15591 CFI_ENDPROC
15592 -ENDPROC(csum_partial_copy_generic)
15593 +ENDPROC(csum_partial_copy_generic_to_user)
15594
15595 #else
15596
15597 /* Version for PentiumII/PPro */
15598
15599 #define ROUND1(x) \
15600 + nop; nop; nop; \
15601 SRC(movl x(%esi), %ebx ) ; \
15602 addl %ebx, %eax ; \
15603 - DST(movl %ebx, x(%edi) ) ;
15604 + DST(movl %ebx, %es:x(%edi)) ;
15605
15606 #define ROUND(x) \
15607 + nop; nop; nop; \
15608 SRC(movl x(%esi), %ebx ) ; \
15609 adcl %ebx, %eax ; \
15610 - DST(movl %ebx, x(%edi) ) ;
15611 + DST(movl %ebx, %es:x(%edi)) ;
15612
15613 #define ARGBASE 12
15614 -
15615 -ENTRY(csum_partial_copy_generic)
15616 +
15617 +ENTRY(csum_partial_copy_generic_to_user)
15618 CFI_STARTPROC
15619 +
15620 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15621 + pushl %gs
15622 + CFI_ADJUST_CFA_OFFSET 4
15623 + popl %es
15624 + CFI_ADJUST_CFA_OFFSET -4
15625 + jmp csum_partial_copy_generic
15626 +#endif
15627 +
15628 +ENTRY(csum_partial_copy_generic_from_user)
15629 +
15630 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15631 + pushl %gs
15632 + CFI_ADJUST_CFA_OFFSET 4
15633 + popl %ds
15634 + CFI_ADJUST_CFA_OFFSET -4
15635 +#endif
15636 +
15637 +ENTRY(csum_partial_copy_generic)
15638 pushl %ebx
15639 CFI_ADJUST_CFA_OFFSET 4
15640 CFI_REL_OFFSET ebx, 0
15641 @@ -482,7 +531,7 @@ ENTRY(csum_partial_copy_generic)
15642 subl %ebx, %edi
15643 lea -1(%esi),%edx
15644 andl $-32,%edx
15645 - lea 3f(%ebx,%ebx), %ebx
15646 + lea 3f(%ebx,%ebx,2), %ebx
15647 testl %esi, %esi
15648 jmp *%ebx
15649 1: addl $64,%esi
15650 @@ -503,19 +552,19 @@ ENTRY(csum_partial_copy_generic)
15651 jb 5f
15652 SRC( movw (%esi), %dx )
15653 leal 2(%esi), %esi
15654 -DST( movw %dx, (%edi) )
15655 +DST( movw %dx, %es:(%edi) )
15656 leal 2(%edi), %edi
15657 je 6f
15658 shll $16,%edx
15659 5:
15660 SRC( movb (%esi), %dl )
15661 -DST( movb %dl, (%edi) )
15662 +DST( movb %dl, %es:(%edi) )
15663 6: addl %edx, %eax
15664 adcl $0, %eax
15665 7:
15666 .section .fixup, "ax"
15667 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
15668 - movl $-EFAULT, (%ebx)
15669 + movl $-EFAULT, %ss:(%ebx)
15670 # zero the complete destination (computing the rest is too much work)
15671 movl ARGBASE+8(%esp),%edi # dst
15672 movl ARGBASE+12(%esp),%ecx # len
15673 @@ -523,10 +572,21 @@ DST( movb %dl, (%edi) )
15674 rep; stosb
15675 jmp 7b
15676 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
15677 - movl $-EFAULT, (%ebx)
15678 + movl $-EFAULT, %ss:(%ebx)
15679 jmp 7b
15680 .previous
15681
15682 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15683 + pushl %ss
15684 + CFI_ADJUST_CFA_OFFSET 4
15685 + popl %ds
15686 + CFI_ADJUST_CFA_OFFSET -4
15687 + pushl %ss
15688 + CFI_ADJUST_CFA_OFFSET 4
15689 + popl %es
15690 + CFI_ADJUST_CFA_OFFSET -4
15691 +#endif
15692 +
15693 popl %esi
15694 CFI_ADJUST_CFA_OFFSET -4
15695 CFI_RESTORE esi
15696 @@ -538,7 +598,7 @@ DST( movb %dl, (%edi) )
15697 CFI_RESTORE ebx
15698 ret
15699 CFI_ENDPROC
15700 -ENDPROC(csum_partial_copy_generic)
15701 +ENDPROC(csum_partial_copy_generic_to_user)
15702
15703 #undef ROUND
15704 #undef ROUND1
15705 diff -urNp linux-2.6.37/arch/x86/lib/clear_page_64.S linux-2.6.37/arch/x86/lib/clear_page_64.S
15706 --- linux-2.6.37/arch/x86/lib/clear_page_64.S 2011-01-04 19:50:19.000000000 -0500
15707 +++ linux-2.6.37/arch/x86/lib/clear_page_64.S 2011-01-17 02:41:01.000000000 -0500
15708 @@ -43,7 +43,7 @@ ENDPROC(clear_page)
15709
15710 #include <asm/cpufeature.h>
15711
15712 - .section .altinstr_replacement,"ax"
15713 + .section .altinstr_replacement,"a"
15714 1: .byte 0xeb /* jmp <disp8> */
15715 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
15716 2:
15717 diff -urNp linux-2.6.37/arch/x86/lib/copy_page_64.S linux-2.6.37/arch/x86/lib/copy_page_64.S
15718 --- linux-2.6.37/arch/x86/lib/copy_page_64.S 2011-01-04 19:50:19.000000000 -0500
15719 +++ linux-2.6.37/arch/x86/lib/copy_page_64.S 2011-01-17 02:41:01.000000000 -0500
15720 @@ -104,7 +104,7 @@ ENDPROC(copy_page)
15721
15722 #include <asm/cpufeature.h>
15723
15724 - .section .altinstr_replacement,"ax"
15725 + .section .altinstr_replacement,"a"
15726 1: .byte 0xeb /* jmp <disp8> */
15727 .byte (copy_page_c - copy_page) - (2f - 1b) /* offset */
15728 2:
15729 diff -urNp linux-2.6.37/arch/x86/lib/copy_user_64.S linux-2.6.37/arch/x86/lib/copy_user_64.S
15730 --- linux-2.6.37/arch/x86/lib/copy_user_64.S 2011-01-04 19:50:19.000000000 -0500
15731 +++ linux-2.6.37/arch/x86/lib/copy_user_64.S 2011-01-17 02:41:01.000000000 -0500
15732 @@ -15,13 +15,14 @@
15733 #include <asm/asm-offsets.h>
15734 #include <asm/thread_info.h>
15735 #include <asm/cpufeature.h>
15736 +#include <asm/pgtable.h>
15737
15738 .macro ALTERNATIVE_JUMP feature,orig,alt
15739 0:
15740 .byte 0xe9 /* 32bit jump */
15741 .long \orig-1f /* by default jump to orig */
15742 1:
15743 - .section .altinstr_replacement,"ax"
15744 + .section .altinstr_replacement,"a"
15745 2: .byte 0xe9 /* near jump with 32bit immediate */
15746 .long \alt-1b /* offset */ /* or alternatively to alt */
15747 .previous
15748 @@ -64,37 +65,13 @@
15749 #endif
15750 .endm
15751
15752 -/* Standard copy_to_user with segment limit checking */
15753 -ENTRY(_copy_to_user)
15754 - CFI_STARTPROC
15755 - GET_THREAD_INFO(%rax)
15756 - movq %rdi,%rcx
15757 - addq %rdx,%rcx
15758 - jc bad_to_user
15759 - cmpq TI_addr_limit(%rax),%rcx
15760 - jae bad_to_user
15761 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,copy_user_generic_unrolled,copy_user_generic_string
15762 - CFI_ENDPROC
15763 -ENDPROC(_copy_to_user)
15764 -
15765 -/* Standard copy_from_user with segment limit checking */
15766 -ENTRY(_copy_from_user)
15767 - CFI_STARTPROC
15768 - GET_THREAD_INFO(%rax)
15769 - movq %rsi,%rcx
15770 - addq %rdx,%rcx
15771 - jc bad_from_user
15772 - cmpq TI_addr_limit(%rax),%rcx
15773 - jae bad_from_user
15774 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,copy_user_generic_unrolled,copy_user_generic_string
15775 - CFI_ENDPROC
15776 -ENDPROC(_copy_from_user)
15777 -
15778 .section .fixup,"ax"
15779 /* must zero dest */
15780 ENTRY(bad_from_user)
15781 bad_from_user:
15782 CFI_STARTPROC
15783 + testl %edx,%edx
15784 + js bad_to_user
15785 movl %edx,%ecx
15786 xorl %eax,%eax
15787 rep
15788 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
15789 --- linux-2.6.37/arch/x86/lib/copy_user_nocache_64.S 2011-01-04 19:50:19.000000000 -0500
15790 +++ linux-2.6.37/arch/x86/lib/copy_user_nocache_64.S 2011-01-17 02:41:01.000000000 -0500
15791 @@ -14,6 +14,7 @@
15792 #include <asm/current.h>
15793 #include <asm/asm-offsets.h>
15794 #include <asm/thread_info.h>
15795 +#include <asm/pgtable.h>
15796
15797 .macro ALIGN_DESTINATION
15798 #ifdef FIX_ALIGNMENT
15799 @@ -50,6 +51,15 @@
15800 */
15801 ENTRY(__copy_user_nocache)
15802 CFI_STARTPROC
15803 +
15804 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15805 + mov $PAX_USER_SHADOW_BASE,%rcx
15806 + cmp %rcx,%rsi
15807 + jae 1f
15808 + add %rcx,%rsi
15809 +1:
15810 +#endif
15811 +
15812 cmpl $8,%edx
15813 jb 20f /* less then 8 bytes, go to byte copy loop */
15814 ALIGN_DESTINATION
15815 diff -urNp linux-2.6.37/arch/x86/lib/csum-wrappers_64.c linux-2.6.37/arch/x86/lib/csum-wrappers_64.c
15816 --- linux-2.6.37/arch/x86/lib/csum-wrappers_64.c 2011-01-04 19:50:19.000000000 -0500
15817 +++ linux-2.6.37/arch/x86/lib/csum-wrappers_64.c 2011-01-17 02:41:01.000000000 -0500
15818 @@ -52,6 +52,8 @@ csum_partial_copy_from_user(const void _
15819 len -= 2;
15820 }
15821 }
15822 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
15823 + src += PAX_USER_SHADOW_BASE;
15824 isum = csum_partial_copy_generic((__force const void *)src,
15825 dst, len, isum, errp, NULL);
15826 if (unlikely(*errp))
15827 @@ -105,6 +107,8 @@ csum_partial_copy_to_user(const void *sr
15828 }
15829
15830 *errp = 0;
15831 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
15832 + dst += PAX_USER_SHADOW_BASE;
15833 return csum_partial_copy_generic(src, (void __force *)dst,
15834 len, isum, NULL, errp);
15835 }
15836 diff -urNp linux-2.6.37/arch/x86/lib/getuser.S linux-2.6.37/arch/x86/lib/getuser.S
15837 --- linux-2.6.37/arch/x86/lib/getuser.S 2011-01-04 19:50:19.000000000 -0500
15838 +++ linux-2.6.37/arch/x86/lib/getuser.S 2011-01-17 02:41:01.000000000 -0500
15839 @@ -33,14 +33,35 @@
15840 #include <asm/asm-offsets.h>
15841 #include <asm/thread_info.h>
15842 #include <asm/asm.h>
15843 +#include <asm/segment.h>
15844 +#include <asm/pgtable.h>
15845 +
15846 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
15847 +#define __copyuser_seg %gs:
15848 +#else
15849 +#define __copyuser_seg
15850 +#endif
15851
15852 .text
15853 ENTRY(__get_user_1)
15854 CFI_STARTPROC
15855 +
15856 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
15857 GET_THREAD_INFO(%_ASM_DX)
15858 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
15859 jae bad_get_user
15860 -1: movzb (%_ASM_AX),%edx
15861 +
15862 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15863 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
15864 + cmp %_ASM_DX,%_ASM_AX
15865 + jae 1234f
15866 + add %_ASM_DX,%_ASM_AX
15867 +1234:
15868 +#endif
15869 +
15870 +#endif
15871 +
15872 +1: movzb __copyuser_seg (%_ASM_AX),%edx
15873 xor %eax,%eax
15874 ret
15875 CFI_ENDPROC
15876 @@ -49,11 +70,24 @@ ENDPROC(__get_user_1)
15877 ENTRY(__get_user_2)
15878 CFI_STARTPROC
15879 add $1,%_ASM_AX
15880 +
15881 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
15882 jc bad_get_user
15883 GET_THREAD_INFO(%_ASM_DX)
15884 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
15885 jae bad_get_user
15886 -2: movzwl -1(%_ASM_AX),%edx
15887 +
15888 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15889 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
15890 + cmp %_ASM_DX,%_ASM_AX
15891 + jae 1234f
15892 + add %_ASM_DX,%_ASM_AX
15893 +1234:
15894 +#endif
15895 +
15896 +#endif
15897 +
15898 +2: movzwl __copyuser_seg -1(%_ASM_AX),%edx
15899 xor %eax,%eax
15900 ret
15901 CFI_ENDPROC
15902 @@ -62,11 +96,24 @@ ENDPROC(__get_user_2)
15903 ENTRY(__get_user_4)
15904 CFI_STARTPROC
15905 add $3,%_ASM_AX
15906 +
15907 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
15908 jc bad_get_user
15909 GET_THREAD_INFO(%_ASM_DX)
15910 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
15911 jae bad_get_user
15912 -3: mov -3(%_ASM_AX),%edx
15913 +
15914 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15915 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
15916 + cmp %_ASM_DX,%_ASM_AX
15917 + jae 1234f
15918 + add %_ASM_DX,%_ASM_AX
15919 +1234:
15920 +#endif
15921 +
15922 +#endif
15923 +
15924 +3: mov __copyuser_seg -3(%_ASM_AX),%edx
15925 xor %eax,%eax
15926 ret
15927 CFI_ENDPROC
15928 @@ -80,6 +127,15 @@ ENTRY(__get_user_8)
15929 GET_THREAD_INFO(%_ASM_DX)
15930 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
15931 jae bad_get_user
15932 +
15933 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15934 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
15935 + cmp %_ASM_DX,%_ASM_AX
15936 + jae 1234f
15937 + add %_ASM_DX,%_ASM_AX
15938 +1234:
15939 +#endif
15940 +
15941 4: movq -7(%_ASM_AX),%_ASM_DX
15942 xor %eax,%eax
15943 ret
15944 diff -urNp linux-2.6.37/arch/x86/lib/insn.c linux-2.6.37/arch/x86/lib/insn.c
15945 --- linux-2.6.37/arch/x86/lib/insn.c 2011-01-04 19:50:19.000000000 -0500
15946 +++ linux-2.6.37/arch/x86/lib/insn.c 2011-01-17 02:41:01.000000000 -0500
15947 @@ -21,6 +21,7 @@
15948 #include <linux/string.h>
15949 #include <asm/inat.h>
15950 #include <asm/insn.h>
15951 +#include <asm/pgtable_types.h>
15952
15953 #define get_next(t, insn) \
15954 ({t r; r = *(t*)insn->next_byte; insn->next_byte += sizeof(t); r; })
15955 @@ -40,8 +41,8 @@
15956 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
15957 {
15958 memset(insn, 0, sizeof(*insn));
15959 - insn->kaddr = kaddr;
15960 - insn->next_byte = kaddr;
15961 + insn->kaddr = ktla_ktva(kaddr);
15962 + insn->next_byte = ktla_ktva(kaddr);
15963 insn->x86_64 = x86_64 ? 1 : 0;
15964 insn->opnd_bytes = 4;
15965 if (x86_64)
15966 diff -urNp linux-2.6.37/arch/x86/lib/mmx_32.c linux-2.6.37/arch/x86/lib/mmx_32.c
15967 --- linux-2.6.37/arch/x86/lib/mmx_32.c 2011-01-04 19:50:19.000000000 -0500
15968 +++ linux-2.6.37/arch/x86/lib/mmx_32.c 2011-01-17 02:41:01.000000000 -0500
15969 @@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *
15970 {
15971 void *p;
15972 int i;
15973 + unsigned long cr0;
15974
15975 if (unlikely(in_interrupt()))
15976 return __memcpy(to, from, len);
15977 @@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *
15978 kernel_fpu_begin();
15979
15980 __asm__ __volatile__ (
15981 - "1: prefetch (%0)\n" /* This set is 28 bytes */
15982 - " prefetch 64(%0)\n"
15983 - " prefetch 128(%0)\n"
15984 - " prefetch 192(%0)\n"
15985 - " prefetch 256(%0)\n"
15986 + "1: prefetch (%1)\n" /* This set is 28 bytes */
15987 + " prefetch 64(%1)\n"
15988 + " prefetch 128(%1)\n"
15989 + " prefetch 192(%1)\n"
15990 + " prefetch 256(%1)\n"
15991 "2: \n"
15992 ".section .fixup, \"ax\"\n"
15993 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
15994 + "3: \n"
15995 +
15996 +#ifdef CONFIG_PAX_KERNEXEC
15997 + " movl %%cr0, %0\n"
15998 + " movl %0, %%eax\n"
15999 + " andl $0xFFFEFFFF, %%eax\n"
16000 + " movl %%eax, %%cr0\n"
16001 +#endif
16002 +
16003 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
16004 +
16005 +#ifdef CONFIG_PAX_KERNEXEC
16006 + " movl %0, %%cr0\n"
16007 +#endif
16008 +
16009 " jmp 2b\n"
16010 ".previous\n"
16011 _ASM_EXTABLE(1b, 3b)
16012 - : : "r" (from));
16013 + : "=&r" (cr0) : "r" (from) : "ax");
16014
16015 for ( ; i > 5; i--) {
16016 __asm__ __volatile__ (
16017 - "1: prefetch 320(%0)\n"
16018 - "2: movq (%0), %%mm0\n"
16019 - " movq 8(%0), %%mm1\n"
16020 - " movq 16(%0), %%mm2\n"
16021 - " movq 24(%0), %%mm3\n"
16022 - " movq %%mm0, (%1)\n"
16023 - " movq %%mm1, 8(%1)\n"
16024 - " movq %%mm2, 16(%1)\n"
16025 - " movq %%mm3, 24(%1)\n"
16026 - " movq 32(%0), %%mm0\n"
16027 - " movq 40(%0), %%mm1\n"
16028 - " movq 48(%0), %%mm2\n"
16029 - " movq 56(%0), %%mm3\n"
16030 - " movq %%mm0, 32(%1)\n"
16031 - " movq %%mm1, 40(%1)\n"
16032 - " movq %%mm2, 48(%1)\n"
16033 - " movq %%mm3, 56(%1)\n"
16034 + "1: prefetch 320(%1)\n"
16035 + "2: movq (%1), %%mm0\n"
16036 + " movq 8(%1), %%mm1\n"
16037 + " movq 16(%1), %%mm2\n"
16038 + " movq 24(%1), %%mm3\n"
16039 + " movq %%mm0, (%2)\n"
16040 + " movq %%mm1, 8(%2)\n"
16041 + " movq %%mm2, 16(%2)\n"
16042 + " movq %%mm3, 24(%2)\n"
16043 + " movq 32(%1), %%mm0\n"
16044 + " movq 40(%1), %%mm1\n"
16045 + " movq 48(%1), %%mm2\n"
16046 + " movq 56(%1), %%mm3\n"
16047 + " movq %%mm0, 32(%2)\n"
16048 + " movq %%mm1, 40(%2)\n"
16049 + " movq %%mm2, 48(%2)\n"
16050 + " movq %%mm3, 56(%2)\n"
16051 ".section .fixup, \"ax\"\n"
16052 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
16053 + "3:\n"
16054 +
16055 +#ifdef CONFIG_PAX_KERNEXEC
16056 + " movl %%cr0, %0\n"
16057 + " movl %0, %%eax\n"
16058 + " andl $0xFFFEFFFF, %%eax\n"
16059 + " movl %%eax, %%cr0\n"
16060 +#endif
16061 +
16062 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
16063 +
16064 +#ifdef CONFIG_PAX_KERNEXEC
16065 + " movl %0, %%cr0\n"
16066 +#endif
16067 +
16068 " jmp 2b\n"
16069 ".previous\n"
16070 _ASM_EXTABLE(1b, 3b)
16071 - : : "r" (from), "r" (to) : "memory");
16072 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
16073
16074 from += 64;
16075 to += 64;
16076 @@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
16077 static void fast_copy_page(void *to, void *from)
16078 {
16079 int i;
16080 + unsigned long cr0;
16081
16082 kernel_fpu_begin();
16083
16084 @@ -166,42 +196,70 @@ static void fast_copy_page(void *to, voi
16085 * but that is for later. -AV
16086 */
16087 __asm__ __volatile__(
16088 - "1: prefetch (%0)\n"
16089 - " prefetch 64(%0)\n"
16090 - " prefetch 128(%0)\n"
16091 - " prefetch 192(%0)\n"
16092 - " prefetch 256(%0)\n"
16093 + "1: prefetch (%1)\n"
16094 + " prefetch 64(%1)\n"
16095 + " prefetch 128(%1)\n"
16096 + " prefetch 192(%1)\n"
16097 + " prefetch 256(%1)\n"
16098 "2: \n"
16099 ".section .fixup, \"ax\"\n"
16100 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
16101 + "3: \n"
16102 +
16103 +#ifdef CONFIG_PAX_KERNEXEC
16104 + " movl %%cr0, %0\n"
16105 + " movl %0, %%eax\n"
16106 + " andl $0xFFFEFFFF, %%eax\n"
16107 + " movl %%eax, %%cr0\n"
16108 +#endif
16109 +
16110 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
16111 +
16112 +#ifdef CONFIG_PAX_KERNEXEC
16113 + " movl %0, %%cr0\n"
16114 +#endif
16115 +
16116 " jmp 2b\n"
16117 ".previous\n"
16118 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
16119 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
16120
16121 for (i = 0; i < (4096-320)/64; i++) {
16122 __asm__ __volatile__ (
16123 - "1: prefetch 320(%0)\n"
16124 - "2: movq (%0), %%mm0\n"
16125 - " movntq %%mm0, (%1)\n"
16126 - " movq 8(%0), %%mm1\n"
16127 - " movntq %%mm1, 8(%1)\n"
16128 - " movq 16(%0), %%mm2\n"
16129 - " movntq %%mm2, 16(%1)\n"
16130 - " movq 24(%0), %%mm3\n"
16131 - " movntq %%mm3, 24(%1)\n"
16132 - " movq 32(%0), %%mm4\n"
16133 - " movntq %%mm4, 32(%1)\n"
16134 - " movq 40(%0), %%mm5\n"
16135 - " movntq %%mm5, 40(%1)\n"
16136 - " movq 48(%0), %%mm6\n"
16137 - " movntq %%mm6, 48(%1)\n"
16138 - " movq 56(%0), %%mm7\n"
16139 - " movntq %%mm7, 56(%1)\n"
16140 + "1: prefetch 320(%1)\n"
16141 + "2: movq (%1), %%mm0\n"
16142 + " movntq %%mm0, (%2)\n"
16143 + " movq 8(%1), %%mm1\n"
16144 + " movntq %%mm1, 8(%2)\n"
16145 + " movq 16(%1), %%mm2\n"
16146 + " movntq %%mm2, 16(%2)\n"
16147 + " movq 24(%1), %%mm3\n"
16148 + " movntq %%mm3, 24(%2)\n"
16149 + " movq 32(%1), %%mm4\n"
16150 + " movntq %%mm4, 32(%2)\n"
16151 + " movq 40(%1), %%mm5\n"
16152 + " movntq %%mm5, 40(%2)\n"
16153 + " movq 48(%1), %%mm6\n"
16154 + " movntq %%mm6, 48(%2)\n"
16155 + " movq 56(%1), %%mm7\n"
16156 + " movntq %%mm7, 56(%2)\n"
16157 ".section .fixup, \"ax\"\n"
16158 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
16159 + "3:\n"
16160 +
16161 +#ifdef CONFIG_PAX_KERNEXEC
16162 + " movl %%cr0, %0\n"
16163 + " movl %0, %%eax\n"
16164 + " andl $0xFFFEFFFF, %%eax\n"
16165 + " movl %%eax, %%cr0\n"
16166 +#endif
16167 +
16168 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
16169 +
16170 +#ifdef CONFIG_PAX_KERNEXEC
16171 + " movl %0, %%cr0\n"
16172 +#endif
16173 +
16174 " jmp 2b\n"
16175 ".previous\n"
16176 - _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
16177 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
16178
16179 from += 64;
16180 to += 64;
16181 @@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
16182 static void fast_copy_page(void *to, void *from)
16183 {
16184 int i;
16185 + unsigned long cr0;
16186
16187 kernel_fpu_begin();
16188
16189 __asm__ __volatile__ (
16190 - "1: prefetch (%0)\n"
16191 - " prefetch 64(%0)\n"
16192 - " prefetch 128(%0)\n"
16193 - " prefetch 192(%0)\n"
16194 - " prefetch 256(%0)\n"
16195 + "1: prefetch (%1)\n"
16196 + " prefetch 64(%1)\n"
16197 + " prefetch 128(%1)\n"
16198 + " prefetch 192(%1)\n"
16199 + " prefetch 256(%1)\n"
16200 "2: \n"
16201 ".section .fixup, \"ax\"\n"
16202 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
16203 + "3: \n"
16204 +
16205 +#ifdef CONFIG_PAX_KERNEXEC
16206 + " movl %%cr0, %0\n"
16207 + " movl %0, %%eax\n"
16208 + " andl $0xFFFEFFFF, %%eax\n"
16209 + " movl %%eax, %%cr0\n"
16210 +#endif
16211 +
16212 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
16213 +
16214 +#ifdef CONFIG_PAX_KERNEXEC
16215 + " movl %0, %%cr0\n"
16216 +#endif
16217 +
16218 " jmp 2b\n"
16219 ".previous\n"
16220 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
16221 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
16222
16223 for (i = 0; i < 4096/64; i++) {
16224 __asm__ __volatile__ (
16225 - "1: prefetch 320(%0)\n"
16226 - "2: movq (%0), %%mm0\n"
16227 - " movq 8(%0), %%mm1\n"
16228 - " movq 16(%0), %%mm2\n"
16229 - " movq 24(%0), %%mm3\n"
16230 - " movq %%mm0, (%1)\n"
16231 - " movq %%mm1, 8(%1)\n"
16232 - " movq %%mm2, 16(%1)\n"
16233 - " movq %%mm3, 24(%1)\n"
16234 - " movq 32(%0), %%mm0\n"
16235 - " movq 40(%0), %%mm1\n"
16236 - " movq 48(%0), %%mm2\n"
16237 - " movq 56(%0), %%mm3\n"
16238 - " movq %%mm0, 32(%1)\n"
16239 - " movq %%mm1, 40(%1)\n"
16240 - " movq %%mm2, 48(%1)\n"
16241 - " movq %%mm3, 56(%1)\n"
16242 + "1: prefetch 320(%1)\n"
16243 + "2: movq (%1), %%mm0\n"
16244 + " movq 8(%1), %%mm1\n"
16245 + " movq 16(%1), %%mm2\n"
16246 + " movq 24(%1), %%mm3\n"
16247 + " movq %%mm0, (%2)\n"
16248 + " movq %%mm1, 8(%2)\n"
16249 + " movq %%mm2, 16(%2)\n"
16250 + " movq %%mm3, 24(%2)\n"
16251 + " movq 32(%1), %%mm0\n"
16252 + " movq 40(%1), %%mm1\n"
16253 + " movq 48(%1), %%mm2\n"
16254 + " movq 56(%1), %%mm3\n"
16255 + " movq %%mm0, 32(%2)\n"
16256 + " movq %%mm1, 40(%2)\n"
16257 + " movq %%mm2, 48(%2)\n"
16258 + " movq %%mm3, 56(%2)\n"
16259 ".section .fixup, \"ax\"\n"
16260 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
16261 + "3:\n"
16262 +
16263 +#ifdef CONFIG_PAX_KERNEXEC
16264 + " movl %%cr0, %0\n"
16265 + " movl %0, %%eax\n"
16266 + " andl $0xFFFEFFFF, %%eax\n"
16267 + " movl %%eax, %%cr0\n"
16268 +#endif
16269 +
16270 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
16271 +
16272 +#ifdef CONFIG_PAX_KERNEXEC
16273 + " movl %0, %%cr0\n"
16274 +#endif
16275 +
16276 " jmp 2b\n"
16277 ".previous\n"
16278 _ASM_EXTABLE(1b, 3b)
16279 - : : "r" (from), "r" (to) : "memory");
16280 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
16281
16282 from += 64;
16283 to += 64;
16284 diff -urNp linux-2.6.37/arch/x86/lib/putuser.S linux-2.6.37/arch/x86/lib/putuser.S
16285 --- linux-2.6.37/arch/x86/lib/putuser.S 2011-01-04 19:50:19.000000000 -0500
16286 +++ linux-2.6.37/arch/x86/lib/putuser.S 2011-01-17 02:41:01.000000000 -0500
16287 @@ -15,7 +15,8 @@
16288 #include <asm/thread_info.h>
16289 #include <asm/errno.h>
16290 #include <asm/asm.h>
16291 -
16292 +#include <asm/segment.h>
16293 +#include <asm/pgtable.h>
16294
16295 /*
16296 * __put_user_X
16297 @@ -29,52 +30,119 @@
16298 * as they get called from within inline assembly.
16299 */
16300
16301 -#define ENTER CFI_STARTPROC ; \
16302 - GET_THREAD_INFO(%_ASM_BX)
16303 +#define ENTER CFI_STARTPROC
16304 #define EXIT ret ; \
16305 CFI_ENDPROC
16306
16307 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
16308 +#define _DEST %_ASM_CX,%_ASM_BX
16309 +#else
16310 +#define _DEST %_ASM_CX
16311 +#endif
16312 +
16313 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
16314 +#define __copyuser_seg %gs:
16315 +#else
16316 +#define __copyuser_seg
16317 +#endif
16318 +
16319 .text
16320 ENTRY(__put_user_1)
16321 ENTER
16322 +
16323 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
16324 + GET_THREAD_INFO(%_ASM_BX)
16325 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
16326 jae bad_put_user
16327 -1: movb %al,(%_ASM_CX)
16328 +
16329 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
16330 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
16331 + cmp %_ASM_BX,%_ASM_CX
16332 + jb 1234f
16333 + xor %ebx,%ebx
16334 +1234:
16335 +#endif
16336 +
16337 +#endif
16338 +
16339 +1: movb %al,__copyuser_seg (_DEST)
16340 xor %eax,%eax
16341 EXIT
16342 ENDPROC(__put_user_1)
16343
16344 ENTRY(__put_user_2)
16345 ENTER
16346 +
16347 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
16348 + GET_THREAD_INFO(%_ASM_BX)
16349 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
16350 sub $1,%_ASM_BX
16351 cmp %_ASM_BX,%_ASM_CX
16352 jae bad_put_user
16353 -2: movw %ax,(%_ASM_CX)
16354 +
16355 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
16356 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
16357 + cmp %_ASM_BX,%_ASM_CX
16358 + jb 1234f
16359 + xor %ebx,%ebx
16360 +1234:
16361 +#endif
16362 +
16363 +#endif
16364 +
16365 +2: movw %ax,__copyuser_seg (_DEST)
16366 xor %eax,%eax
16367 EXIT
16368 ENDPROC(__put_user_2)
16369
16370 ENTRY(__put_user_4)
16371 ENTER
16372 +
16373 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
16374 + GET_THREAD_INFO(%_ASM_BX)
16375 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
16376 sub $3,%_ASM_BX
16377 cmp %_ASM_BX,%_ASM_CX
16378 jae bad_put_user
16379 -3: movl %eax,(%_ASM_CX)
16380 +
16381 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
16382 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
16383 + cmp %_ASM_BX,%_ASM_CX
16384 + jb 1234f
16385 + xor %ebx,%ebx
16386 +1234:
16387 +#endif
16388 +
16389 +#endif
16390 +
16391 +3: movl %eax,__copyuser_seg (_DEST)
16392 xor %eax,%eax
16393 EXIT
16394 ENDPROC(__put_user_4)
16395
16396 ENTRY(__put_user_8)
16397 ENTER
16398 +
16399 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
16400 + GET_THREAD_INFO(%_ASM_BX)
16401 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
16402 sub $7,%_ASM_BX
16403 cmp %_ASM_BX,%_ASM_CX
16404 jae bad_put_user
16405 -4: mov %_ASM_AX,(%_ASM_CX)
16406 +
16407 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
16408 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
16409 + cmp %_ASM_BX,%_ASM_CX
16410 + jb 1234f
16411 + xor %ebx,%ebx
16412 +1234:
16413 +#endif
16414 +
16415 +#endif
16416 +
16417 +4: mov %_ASM_AX,__copyuser_seg (_DEST)
16418 #ifdef CONFIG_X86_32
16419 -5: movl %edx,4(%_ASM_CX)
16420 +5: movl %edx,__copyuser_seg 4(_DEST)
16421 #endif
16422 xor %eax,%eax
16423 EXIT
16424 diff -urNp linux-2.6.37/arch/x86/lib/usercopy_32.c linux-2.6.37/arch/x86/lib/usercopy_32.c
16425 --- linux-2.6.37/arch/x86/lib/usercopy_32.c 2011-01-04 19:50:19.000000000 -0500
16426 +++ linux-2.6.37/arch/x86/lib/usercopy_32.c 2011-01-17 02:41:01.000000000 -0500
16427 @@ -43,7 +43,7 @@ do { \
16428 __asm__ __volatile__( \
16429 " testl %1,%1\n" \
16430 " jz 2f\n" \
16431 - "0: lodsb\n" \
16432 + "0: lodsb " __copyuser_seg" (%%esi)\n" \
16433 " stosb\n" \
16434 " testb %%al,%%al\n" \
16435 " jz 1f\n" \
16436 @@ -128,10 +128,12 @@ do { \
16437 int __d0; \
16438 might_fault(); \
16439 __asm__ __volatile__( \
16440 + __COPYUSER_SET_ES \
16441 "0: rep; stosl\n" \
16442 " movl %2,%0\n" \
16443 "1: rep; stosb\n" \
16444 "2:\n" \
16445 + __COPYUSER_RESTORE_ES \
16446 ".section .fixup,\"ax\"\n" \
16447 "3: lea 0(%2,%0,4),%0\n" \
16448 " jmp 2b\n" \
16449 @@ -200,6 +202,7 @@ long strnlen_user(const char __user *s,
16450 might_fault();
16451
16452 __asm__ __volatile__(
16453 + __COPYUSER_SET_ES
16454 " testl %0, %0\n"
16455 " jz 3f\n"
16456 " andl %0,%%ecx\n"
16457 @@ -208,6 +211,7 @@ long strnlen_user(const char __user *s,
16458 " subl %%ecx,%0\n"
16459 " addl %0,%%eax\n"
16460 "1:\n"
16461 + __COPYUSER_RESTORE_ES
16462 ".section .fixup,\"ax\"\n"
16463 "2: xorl %%eax,%%eax\n"
16464 " jmp 1b\n"
16465 @@ -227,7 +231,7 @@ EXPORT_SYMBOL(strnlen_user);
16466
16467 #ifdef CONFIG_X86_INTEL_USERCOPY
16468 static unsigned long
16469 -__copy_user_intel(void __user *to, const void *from, unsigned long size)
16470 +__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
16471 {
16472 int d0, d1;
16473 __asm__ __volatile__(
16474 @@ -239,36 +243,36 @@ __copy_user_intel(void __user *to, const
16475 " .align 2,0x90\n"
16476 "3: movl 0(%4), %%eax\n"
16477 "4: movl 4(%4), %%edx\n"
16478 - "5: movl %%eax, 0(%3)\n"
16479 - "6: movl %%edx, 4(%3)\n"
16480 + "5: movl %%eax, "__copyuser_seg" 0(%3)\n"
16481 + "6: movl %%edx, "__copyuser_seg" 4(%3)\n"
16482 "7: movl 8(%4), %%eax\n"
16483 "8: movl 12(%4),%%edx\n"
16484 - "9: movl %%eax, 8(%3)\n"
16485 - "10: movl %%edx, 12(%3)\n"
16486 + "9: movl %%eax, "__copyuser_seg" 8(%3)\n"
16487 + "10: movl %%edx, "__copyuser_seg" 12(%3)\n"
16488 "11: movl 16(%4), %%eax\n"
16489 "12: movl 20(%4), %%edx\n"
16490 - "13: movl %%eax, 16(%3)\n"
16491 - "14: movl %%edx, 20(%3)\n"
16492 + "13: movl %%eax, "__copyuser_seg" 16(%3)\n"
16493 + "14: movl %%edx, "__copyuser_seg" 20(%3)\n"
16494 "15: movl 24(%4), %%eax\n"
16495 "16: movl 28(%4), %%edx\n"
16496 - "17: movl %%eax, 24(%3)\n"
16497 - "18: movl %%edx, 28(%3)\n"
16498 + "17: movl %%eax, "__copyuser_seg" 24(%3)\n"
16499 + "18: movl %%edx, "__copyuser_seg" 28(%3)\n"
16500 "19: movl 32(%4), %%eax\n"
16501 "20: movl 36(%4), %%edx\n"
16502 - "21: movl %%eax, 32(%3)\n"
16503 - "22: movl %%edx, 36(%3)\n"
16504 + "21: movl %%eax, "__copyuser_seg" 32(%3)\n"
16505 + "22: movl %%edx, "__copyuser_seg" 36(%3)\n"
16506 "23: movl 40(%4), %%eax\n"
16507 "24: movl 44(%4), %%edx\n"
16508 - "25: movl %%eax, 40(%3)\n"
16509 - "26: movl %%edx, 44(%3)\n"
16510 + "25: movl %%eax, "__copyuser_seg" 40(%3)\n"
16511 + "26: movl %%edx, "__copyuser_seg" 44(%3)\n"
16512 "27: movl 48(%4), %%eax\n"
16513 "28: movl 52(%4), %%edx\n"
16514 - "29: movl %%eax, 48(%3)\n"
16515 - "30: movl %%edx, 52(%3)\n"
16516 + "29: movl %%eax, "__copyuser_seg" 48(%3)\n"
16517 + "30: movl %%edx, "__copyuser_seg" 52(%3)\n"
16518 "31: movl 56(%4), %%eax\n"
16519 "32: movl 60(%4), %%edx\n"
16520 - "33: movl %%eax, 56(%3)\n"
16521 - "34: movl %%edx, 60(%3)\n"
16522 + "33: movl %%eax, "__copyuser_seg" 56(%3)\n"
16523 + "34: movl %%edx, "__copyuser_seg" 60(%3)\n"
16524 " addl $-64, %0\n"
16525 " addl $64, %4\n"
16526 " addl $64, %3\n"
16527 @@ -278,10 +282,119 @@ __copy_user_intel(void __user *to, const
16528 " shrl $2, %0\n"
16529 " andl $3, %%eax\n"
16530 " cld\n"
16531 + __COPYUSER_SET_ES
16532 "99: rep; movsl\n"
16533 "36: movl %%eax, %0\n"
16534 "37: rep; movsb\n"
16535 "100:\n"
16536 + __COPYUSER_RESTORE_ES
16537 + ".section .fixup,\"ax\"\n"
16538 + "101: lea 0(%%eax,%0,4),%0\n"
16539 + " jmp 100b\n"
16540 + ".previous\n"
16541 + ".section __ex_table,\"a\"\n"
16542 + " .align 4\n"
16543 + " .long 1b,100b\n"
16544 + " .long 2b,100b\n"
16545 + " .long 3b,100b\n"
16546 + " .long 4b,100b\n"
16547 + " .long 5b,100b\n"
16548 + " .long 6b,100b\n"
16549 + " .long 7b,100b\n"
16550 + " .long 8b,100b\n"
16551 + " .long 9b,100b\n"
16552 + " .long 10b,100b\n"
16553 + " .long 11b,100b\n"
16554 + " .long 12b,100b\n"
16555 + " .long 13b,100b\n"
16556 + " .long 14b,100b\n"
16557 + " .long 15b,100b\n"
16558 + " .long 16b,100b\n"
16559 + " .long 17b,100b\n"
16560 + " .long 18b,100b\n"
16561 + " .long 19b,100b\n"
16562 + " .long 20b,100b\n"
16563 + " .long 21b,100b\n"
16564 + " .long 22b,100b\n"
16565 + " .long 23b,100b\n"
16566 + " .long 24b,100b\n"
16567 + " .long 25b,100b\n"
16568 + " .long 26b,100b\n"
16569 + " .long 27b,100b\n"
16570 + " .long 28b,100b\n"
16571 + " .long 29b,100b\n"
16572 + " .long 30b,100b\n"
16573 + " .long 31b,100b\n"
16574 + " .long 32b,100b\n"
16575 + " .long 33b,100b\n"
16576 + " .long 34b,100b\n"
16577 + " .long 35b,100b\n"
16578 + " .long 36b,100b\n"
16579 + " .long 37b,100b\n"
16580 + " .long 99b,101b\n"
16581 + ".previous"
16582 + : "=&c"(size), "=&D" (d0), "=&S" (d1)
16583 + : "1"(to), "2"(from), "0"(size)
16584 + : "eax", "edx", "memory");
16585 + return size;
16586 +}
16587 +
16588 +static unsigned long
16589 +__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
16590 +{
16591 + int d0, d1;
16592 + __asm__ __volatile__(
16593 + " .align 2,0x90\n"
16594 + "1: movl "__copyuser_seg" 32(%4), %%eax\n"
16595 + " cmpl $67, %0\n"
16596 + " jbe 3f\n"
16597 + "2: movl "__copyuser_seg" 64(%4), %%eax\n"
16598 + " .align 2,0x90\n"
16599 + "3: movl "__copyuser_seg" 0(%4), %%eax\n"
16600 + "4: movl "__copyuser_seg" 4(%4), %%edx\n"
16601 + "5: movl %%eax, 0(%3)\n"
16602 + "6: movl %%edx, 4(%3)\n"
16603 + "7: movl "__copyuser_seg" 8(%4), %%eax\n"
16604 + "8: movl "__copyuser_seg" 12(%4),%%edx\n"
16605 + "9: movl %%eax, 8(%3)\n"
16606 + "10: movl %%edx, 12(%3)\n"
16607 + "11: movl "__copyuser_seg" 16(%4), %%eax\n"
16608 + "12: movl "__copyuser_seg" 20(%4), %%edx\n"
16609 + "13: movl %%eax, 16(%3)\n"
16610 + "14: movl %%edx, 20(%3)\n"
16611 + "15: movl "__copyuser_seg" 24(%4), %%eax\n"
16612 + "16: movl "__copyuser_seg" 28(%4), %%edx\n"
16613 + "17: movl %%eax, 24(%3)\n"
16614 + "18: movl %%edx, 28(%3)\n"
16615 + "19: movl "__copyuser_seg" 32(%4), %%eax\n"
16616 + "20: movl "__copyuser_seg" 36(%4), %%edx\n"
16617 + "21: movl %%eax, 32(%3)\n"
16618 + "22: movl %%edx, 36(%3)\n"
16619 + "23: movl "__copyuser_seg" 40(%4), %%eax\n"
16620 + "24: movl "__copyuser_seg" 44(%4), %%edx\n"
16621 + "25: movl %%eax, 40(%3)\n"
16622 + "26: movl %%edx, 44(%3)\n"
16623 + "27: movl "__copyuser_seg" 48(%4), %%eax\n"
16624 + "28: movl "__copyuser_seg" 52(%4), %%edx\n"
16625 + "29: movl %%eax, 48(%3)\n"
16626 + "30: movl %%edx, 52(%3)\n"
16627 + "31: movl "__copyuser_seg" 56(%4), %%eax\n"
16628 + "32: movl "__copyuser_seg" 60(%4), %%edx\n"
16629 + "33: movl %%eax, 56(%3)\n"
16630 + "34: movl %%edx, 60(%3)\n"
16631 + " addl $-64, %0\n"
16632 + " addl $64, %4\n"
16633 + " addl $64, %3\n"
16634 + " cmpl $63, %0\n"
16635 + " ja 1b\n"
16636 + "35: movl %0, %%eax\n"
16637 + " shrl $2, %0\n"
16638 + " andl $3, %%eax\n"
16639 + " cld\n"
16640 + "99: rep; movsl "__copyuser_seg" (%%esi), (%%edi)\n"
16641 + "36: movl %%eax, %0\n"
16642 + "37: rep; movsb "__copyuser_seg" (%%esi), (%%edi)\n"
16643 + "100:\n"
16644 ".section .fixup,\"ax\"\n"
16645 "101: lea 0(%%eax,%0,4),%0\n"
16646 " jmp 100b\n"
16647 @@ -339,41 +452,41 @@ __copy_user_zeroing_intel(void *to, cons
16648 int d0, d1;
16649 __asm__ __volatile__(
16650 " .align 2,0x90\n"
16651 - "0: movl 32(%4), %%eax\n"
16652 + "0: movl "__copyuser_seg" 32(%4), %%eax\n"
16653 " cmpl $67, %0\n"
16654 " jbe 2f\n"
16655 - "1: movl 64(%4), %%eax\n"
16656 + "1: movl "__copyuser_seg" 64(%4), %%eax\n"
16657 " .align 2,0x90\n"
16658 - "2: movl 0(%4), %%eax\n"
16659 - "21: movl 4(%4), %%edx\n"
16660 + "2: movl "__copyuser_seg" 0(%4), %%eax\n"
16661 + "21: movl "__copyuser_seg" 4(%4), %%edx\n"
16662 " movl %%eax, 0(%3)\n"
16663 " movl %%edx, 4(%3)\n"
16664 - "3: movl 8(%4), %%eax\n"
16665 - "31: movl 12(%4),%%edx\n"
16666 + "3: movl "__copyuser_seg" 8(%4), %%eax\n"
16667 + "31: movl "__copyuser_seg" 12(%4),%%edx\n"
16668 " movl %%eax, 8(%3)\n"
16669 " movl %%edx, 12(%3)\n"
16670 - "4: movl 16(%4), %%eax\n"
16671 - "41: movl 20(%4), %%edx\n"
16672 + "4: movl "__copyuser_seg" 16(%4), %%eax\n"
16673 + "41: movl "__copyuser_seg" 20(%4), %%edx\n"
16674 " movl %%eax, 16(%3)\n"
16675 " movl %%edx, 20(%3)\n"
16676 - "10: movl 24(%4), %%eax\n"
16677 - "51: movl 28(%4), %%edx\n"
16678 + "10: movl "__copyuser_seg" 24(%4), %%eax\n"
16679 + "51: movl "__copyuser_seg" 28(%4), %%edx\n"
16680 " movl %%eax, 24(%3)\n"
16681 " movl %%edx, 28(%3)\n"
16682 - "11: movl 32(%4), %%eax\n"
16683 - "61: movl 36(%4), %%edx\n"
16684 + "11: movl "__copyuser_seg" 32(%4), %%eax\n"
16685 + "61: movl "__copyuser_seg" 36(%4), %%edx\n"
16686 " movl %%eax, 32(%3)\n"
16687 " movl %%edx, 36(%3)\n"
16688 - "12: movl 40(%4), %%eax\n"
16689 - "71: movl 44(%4), %%edx\n"
16690 + "12: movl "__copyuser_seg" 40(%4), %%eax\n"
16691 + "71: movl "__copyuser_seg" 44(%4), %%edx\n"
16692 " movl %%eax, 40(%3)\n"
16693 " movl %%edx, 44(%3)\n"
16694 - "13: movl 48(%4), %%eax\n"
16695 - "81: movl 52(%4), %%edx\n"
16696 + "13: movl "__copyuser_seg" 48(%4), %%eax\n"
16697 + "81: movl "__copyuser_seg" 52(%4), %%edx\n"
16698 " movl %%eax, 48(%3)\n"
16699 " movl %%edx, 52(%3)\n"
16700 - "14: movl 56(%4), %%eax\n"
16701 - "91: movl 60(%4), %%edx\n"
16702 + "14: movl "__copyuser_seg" 56(%4), %%eax\n"
16703 + "91: movl "__copyuser_seg" 60(%4), %%edx\n"
16704 " movl %%eax, 56(%3)\n"
16705 " movl %%edx, 60(%3)\n"
16706 " addl $-64, %0\n"
16707 @@ -385,9 +498,9 @@ __copy_user_zeroing_intel(void *to, cons
16708 " shrl $2, %0\n"
16709 " andl $3, %%eax\n"
16710 " cld\n"
16711 - "6: rep; movsl\n"
16712 + "6: rep; movsl "__copyuser_seg" (%%esi), (%%edi)\n"
16713 " movl %%eax,%0\n"
16714 - "7: rep; movsb\n"
16715 + "7: rep; movsb "__copyuser_seg" (%%esi), (%%edi)\n"
16716 "8:\n"
16717 ".section .fixup,\"ax\"\n"
16718 "9: lea 0(%%eax,%0,4),%0\n"
16719 @@ -440,41 +553,41 @@ static unsigned long __copy_user_zeroing
16720
16721 __asm__ __volatile__(
16722 " .align 2,0x90\n"
16723 - "0: movl 32(%4), %%eax\n"
16724 + "0: movl "__copyuser_seg" 32(%4), %%eax\n"
16725 " cmpl $67, %0\n"
16726 " jbe 2f\n"
16727 - "1: movl 64(%4), %%eax\n"
16728 + "1: movl "__copyuser_seg" 64(%4), %%eax\n"
16729 " .align 2,0x90\n"
16730 - "2: movl 0(%4), %%eax\n"
16731 - "21: movl 4(%4), %%edx\n"
16732 + "2: movl "__copyuser_seg" 0(%4), %%eax\n"
16733 + "21: movl "__copyuser_seg" 4(%4), %%edx\n"
16734 " movnti %%eax, 0(%3)\n"
16735 " movnti %%edx, 4(%3)\n"
16736 - "3: movl 8(%4), %%eax\n"
16737 - "31: movl 12(%4),%%edx\n"
16738 + "3: movl "__copyuser_seg" 8(%4), %%eax\n"
16739 + "31: movl "__copyuser_seg" 12(%4),%%edx\n"
16740 " movnti %%eax, 8(%3)\n"
16741 " movnti %%edx, 12(%3)\n"
16742 - "4: movl 16(%4), %%eax\n"
16743 - "41: movl 20(%4), %%edx\n"
16744 + "4: movl "__copyuser_seg" 16(%4), %%eax\n"
16745 + "41: movl "__copyuser_seg" 20(%4), %%edx\n"
16746 " movnti %%eax, 16(%3)\n"
16747 " movnti %%edx, 20(%3)\n"
16748 - "10: movl 24(%4), %%eax\n"
16749 - "51: movl 28(%4), %%edx\n"
16750 + "10: movl "__copyuser_seg" 24(%4), %%eax\n"
16751 + "51: movl "__copyuser_seg" 28(%4), %%edx\n"
16752 " movnti %%eax, 24(%3)\n"
16753 " movnti %%edx, 28(%3)\n"
16754 - "11: movl 32(%4), %%eax\n"
16755 - "61: movl 36(%4), %%edx\n"
16756 + "11: movl "__copyuser_seg" 32(%4), %%eax\n"
16757 + "61: movl "__copyuser_seg" 36(%4), %%edx\n"
16758 " movnti %%eax, 32(%3)\n"
16759 " movnti %%edx, 36(%3)\n"
16760 - "12: movl 40(%4), %%eax\n"
16761 - "71: movl 44(%4), %%edx\n"
16762 + "12: movl "__copyuser_seg" 40(%4), %%eax\n"
16763 + "71: movl "__copyuser_seg" 44(%4), %%edx\n"
16764 " movnti %%eax, 40(%3)\n"
16765 " movnti %%edx, 44(%3)\n"
16766 - "13: movl 48(%4), %%eax\n"
16767 - "81: movl 52(%4), %%edx\n"
16768 + "13: movl "__copyuser_seg" 48(%4), %%eax\n"
16769 + "81: movl "__copyuser_seg" 52(%4), %%edx\n"
16770 " movnti %%eax, 48(%3)\n"
16771 " movnti %%edx, 52(%3)\n"
16772 - "14: movl 56(%4), %%eax\n"
16773 - "91: movl 60(%4), %%edx\n"
16774 + "14: movl "__copyuser_seg" 56(%4), %%eax\n"
16775 + "91: movl "__copyuser_seg" 60(%4), %%edx\n"
16776 " movnti %%eax, 56(%3)\n"
16777 " movnti %%edx, 60(%3)\n"
16778 " addl $-64, %0\n"
16779 @@ -487,9 +600,9 @@ static unsigned long __copy_user_zeroing
16780 " shrl $2, %0\n"
16781 " andl $3, %%eax\n"
16782 " cld\n"
16783 - "6: rep; movsl\n"
16784 + "6: rep; movsl "__copyuser_seg" (%%esi), (%%edi)\n"
16785 " movl %%eax,%0\n"
16786 - "7: rep; movsb\n"
16787 + "7: rep; movsb "__copyuser_seg" (%%esi), (%%edi)\n"
16788 "8:\n"
16789 ".section .fixup,\"ax\"\n"
16790 "9: lea 0(%%eax,%0,4),%0\n"
16791 @@ -537,41 +650,41 @@ static unsigned long __copy_user_intel_n
16792
16793 __asm__ __volatile__(
16794 " .align 2,0x90\n"
16795 - "0: movl 32(%4), %%eax\n"
16796 + "0: movl "__copyuser_seg" 32(%4), %%eax\n"
16797 " cmpl $67, %0\n"
16798 " jbe 2f\n"
16799 - "1: movl 64(%4), %%eax\n"
16800 + "1: movl "__copyuser_seg" 64(%4), %%eax\n"
16801 " .align 2,0x90\n"
16802 - "2: movl 0(%4), %%eax\n"
16803 - "21: movl 4(%4), %%edx\n"
16804 + "2: movl "__copyuser_seg" 0(%4), %%eax\n"
16805 + "21: movl "__copyuser_seg" 4(%4), %%edx\n"
16806 " movnti %%eax, 0(%3)\n"
16807 " movnti %%edx, 4(%3)\n"
16808 - "3: movl 8(%4), %%eax\n"
16809 - "31: movl 12(%4),%%edx\n"
16810 + "3: movl "__copyuser_seg" 8(%4), %%eax\n"
16811 + "31: movl "__copyuser_seg" 12(%4),%%edx\n"
16812 " movnti %%eax, 8(%3)\n"
16813 " movnti %%edx, 12(%3)\n"
16814 - "4: movl 16(%4), %%eax\n"
16815 - "41: movl 20(%4), %%edx\n"
16816 + "4: movl "__copyuser_seg" 16(%4), %%eax\n"
16817 + "41: movl "__copyuser_seg" 20(%4), %%edx\n"
16818 " movnti %%eax, 16(%3)\n"
16819 " movnti %%edx, 20(%3)\n"
16820 - "10: movl 24(%4), %%eax\n"
16821 - "51: movl 28(%4), %%edx\n"
16822 + "10: movl "__copyuser_seg" 24(%4), %%eax\n"
16823 + "51: movl "__copyuser_seg" 28(%4), %%edx\n"
16824 " movnti %%eax, 24(%3)\n"
16825 " movnti %%edx, 28(%3)\n"
16826 - "11: movl 32(%4), %%eax\n"
16827 - "61: movl 36(%4), %%edx\n"
16828 + "11: movl "__copyuser_seg" 32(%4), %%eax\n"
16829 + "61: movl "__copyuser_seg" 36(%4), %%edx\n"
16830 " movnti %%eax, 32(%3)\n"
16831 " movnti %%edx, 36(%3)\n"
16832 - "12: movl 40(%4), %%eax\n"
16833 - "71: movl 44(%4), %%edx\n"
16834 + "12: movl "__copyuser_seg" 40(%4), %%eax\n"
16835 + "71: movl "__copyuser_seg" 44(%4), %%edx\n"
16836 " movnti %%eax, 40(%3)\n"
16837 " movnti %%edx, 44(%3)\n"
16838 - "13: movl 48(%4), %%eax\n"
16839 - "81: movl 52(%4), %%edx\n"
16840 + "13: movl "__copyuser_seg" 48(%4), %%eax\n"
16841 + "81: movl "__copyuser_seg" 52(%4), %%edx\n"
16842 " movnti %%eax, 48(%3)\n"
16843 " movnti %%edx, 52(%3)\n"
16844 - "14: movl 56(%4), %%eax\n"
16845 - "91: movl 60(%4), %%edx\n"
16846 + "14: movl "__copyuser_seg" 56(%4), %%eax\n"
16847 + "91: movl "__copyuser_seg" 60(%4), %%edx\n"
16848 " movnti %%eax, 56(%3)\n"
16849 " movnti %%edx, 60(%3)\n"
16850 " addl $-64, %0\n"
16851 @@ -584,9 +697,9 @@ static unsigned long __copy_user_intel_n
16852 " shrl $2, %0\n"
16853 " andl $3, %%eax\n"
16854 " cld\n"
16855 - "6: rep; movsl\n"
16856 + "6: rep; movsl "__copyuser_seg" (%%esi), (%%edi)\n"
16857 " movl %%eax,%0\n"
16858 - "7: rep; movsb\n"
16859 + "7: rep; movsb "__copyuser_seg" (%%esi), (%%edi)\n"
16860 "8:\n"
16861 ".section .fixup,\"ax\"\n"
16862 "9: lea 0(%%eax,%0,4),%0\n"
16863 @@ -629,32 +742,36 @@ static unsigned long __copy_user_intel_n
16864 */
16865 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
16866 unsigned long size);
16867 -unsigned long __copy_user_intel(void __user *to, const void *from,
16868 +unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
16869 + unsigned long size);
16870 +unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
16871 unsigned long size);
16872 unsigned long __copy_user_zeroing_intel_nocache(void *to,
16873 const void __user *from, unsigned long size);
16874 #endif /* CONFIG_X86_INTEL_USERCOPY */
16875
16876 /* Generic arbitrary sized copy. */
16877 -#define __copy_user(to, from, size) \
16878 +#define __copy_user(to, from, size, prefix, set, restore) \
16879 do { \
16880 int __d0, __d1, __d2; \
16881 __asm__ __volatile__( \
16882 + set \
16883 " cmp $7,%0\n" \
16884 " jbe 1f\n" \
16885 " movl %1,%0\n" \
16886 " negl %0\n" \
16887 " andl $7,%0\n" \
16888 " subl %0,%3\n" \
16889 - "4: rep; movsb\n" \
16890 + "4: rep; movsb "prefix" (%%esi), (%%edi)\n" \
16891 " movl %3,%0\n" \
16892 " shrl $2,%0\n" \
16893 " andl $3,%3\n" \
16894 " .align 2,0x90\n" \
16895 - "0: rep; movsl\n" \
16896 + "0: rep; movsl "prefix" (%%esi), (%%edi)\n" \
16897 " movl %3,%0\n" \
16898 - "1: rep; movsb\n" \
16899 + "1: rep; movsb "prefix" (%%esi), (%%edi)\n" \
16900 "2:\n" \
16901 + restore \
16902 ".section .fixup,\"ax\"\n" \
16903 "5: addl %3,%0\n" \
16904 " jmp 2b\n" \
16905 @@ -682,14 +799,14 @@ do { \
16906 " negl %0\n" \
16907 " andl $7,%0\n" \
16908 " subl %0,%3\n" \
16909 - "4: rep; movsb\n" \
16910 + "4: rep; movsb "__copyuser_seg" (%%esi), (%%edi)\n" \
16911 " movl %3,%0\n" \
16912 " shrl $2,%0\n" \
16913 " andl $3,%3\n" \
16914 " .align 2,0x90\n" \
16915 - "0: rep; movsl\n" \
16916 + "0: rep; movsl "__copyuser_seg" (%%esi), (%%edi)\n" \
16917 " movl %3,%0\n" \
16918 - "1: rep; movsb\n" \
16919 + "1: rep; movsb "__copyuser_seg" (%%esi), (%%edi)\n" \
16920 "2:\n" \
16921 ".section .fixup,\"ax\"\n" \
16922 "5: addl %3,%0\n" \
16923 @@ -775,9 +892,9 @@ survive:
16924 }
16925 #endif
16926 if (movsl_is_ok(to, from, n))
16927 - __copy_user(to, from, n);
16928 + __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
16929 else
16930 - n = __copy_user_intel(to, from, n);
16931 + n = __generic_copy_to_user_intel(to, from, n);
16932 return n;
16933 }
16934 EXPORT_SYMBOL(__copy_to_user_ll);
16935 @@ -797,10 +914,9 @@ unsigned long __copy_from_user_ll_nozero
16936 unsigned long n)
16937 {
16938 if (movsl_is_ok(to, from, n))
16939 - __copy_user(to, from, n);
16940 + __copy_user(to, from, n, __copyuser_seg, "", "");
16941 else
16942 - n = __copy_user_intel((void __user *)to,
16943 - (const void *)from, n);
16944 + n = __generic_copy_from_user_intel(to, from, n);
16945 return n;
16946 }
16947 EXPORT_SYMBOL(__copy_from_user_ll_nozero);
16948 @@ -827,65 +943,49 @@ unsigned long __copy_from_user_ll_nocach
16949 if (n > 64 && cpu_has_xmm2)
16950 n = __copy_user_intel_nocache(to, from, n);
16951 else
16952 - __copy_user(to, from, n);
16953 + __copy_user(to, from, n, __copyuser_seg, "", "");
16954 #else
16955 - __copy_user(to, from, n);
16956 + __copy_user(to, from, n, __copyuser_seg, "", "");
16957 #endif
16958 return n;
16959 }
16960 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
16961
16962 -/**
16963 - * copy_to_user: - Copy a block of data into user space.
16964 - * @to: Destination address, in user space.
16965 - * @from: Source address, in kernel space.
16966 - * @n: Number of bytes to copy.
16967 - *
16968 - * Context: User context only. This function may sleep.
16969 - *
16970 - * Copy data from kernel space to user space.
16971 - *
16972 - * Returns number of bytes that could not be copied.
16973 - * On success, this will be zero.
16974 - */
16975 -unsigned long
16976 -copy_to_user(void __user *to, const void *from, unsigned long n)
16977 +void copy_from_user_overflow(void)
16978 {
16979 - if (access_ok(VERIFY_WRITE, to, n))
16980 - n = __copy_to_user(to, from, n);
16981 - return n;
16982 + WARN(1, "Buffer overflow detected!\n");
16983 }
16984 -EXPORT_SYMBOL(copy_to_user);
16985 +EXPORT_SYMBOL(copy_from_user_overflow);
16986
16987 -/**
16988 - * copy_from_user: - Copy a block of data from user space.
16989 - * @to: Destination address, in kernel space.
16990 - * @from: Source address, in user space.
16991 - * @n: Number of bytes to copy.
16992 - *
16993 - * Context: User context only. This function may sleep.
16994 - *
16995 - * Copy data from user space to kernel space.
16996 - *
16997 - * Returns number of bytes that could not be copied.
16998 - * On success, this will be zero.
16999 - *
17000 - * If some data could not be copied, this function will pad the copied
17001 - * data to the requested size using zero bytes.
17002 - */
17003 -unsigned long
17004 -_copy_from_user(void *to, const void __user *from, unsigned long n)
17005 +void copy_to_user_overflow(void)
17006 {
17007 - if (access_ok(VERIFY_READ, from, n))
17008 - n = __copy_from_user(to, from, n);
17009 - else
17010 - memset(to, 0, n);
17011 - return n;
17012 + WARN(1, "Buffer overflow detected!\n");
17013 }
17014 -EXPORT_SYMBOL(_copy_from_user);
17015 +EXPORT_SYMBOL(copy_to_user_overflow);
17016
17017 -void copy_from_user_overflow(void)
17018 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17019 +void __set_fs(mm_segment_t x)
17020 {
17021 - WARN(1, "Buffer overflow detected!\n");
17022 + switch (x.seg) {
17023 + case 0:
17024 + loadsegment(gs, 0);
17025 + break;
17026 + case TASK_SIZE_MAX:
17027 + loadsegment(gs, __USER_DS);
17028 + break;
17029 + case -1UL:
17030 + loadsegment(gs, __KERNEL_DS);
17031 + break;
17032 + default:
17033 + BUG();
17034 + }
17035 + return;
17036 }
17037 -EXPORT_SYMBOL(copy_from_user_overflow);
17038 +
17039 +void set_fs(mm_segment_t x)
17040 +{
17041 + current_thread_info()->addr_limit = x;
17042 + __set_fs(x);
17043 +}
17044 +EXPORT_SYMBOL(set_fs);
17045 +#endif
17046 diff -urNp linux-2.6.37/arch/x86/lib/usercopy_64.c linux-2.6.37/arch/x86/lib/usercopy_64.c
17047 --- linux-2.6.37/arch/x86/lib/usercopy_64.c 2011-01-04 19:50:19.000000000 -0500
17048 +++ linux-2.6.37/arch/x86/lib/usercopy_64.c 2011-01-17 02:41:01.000000000 -0500
17049 @@ -42,6 +42,8 @@ long
17050 __strncpy_from_user(char *dst, const char __user *src, long count)
17051 {
17052 long res;
17053 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
17054 + src += PAX_USER_SHADOW_BASE;
17055 __do_strncpy_from_user(dst, src, count, res);
17056 return res;
17057 }
17058 @@ -65,6 +67,8 @@ unsigned long __clear_user(void __user *
17059 {
17060 long __d0;
17061 might_fault();
17062 + if ((unsigned long)addr < PAX_USER_SHADOW_BASE)
17063 + addr += PAX_USER_SHADOW_BASE;
17064 /* no memory constraint because it doesn't change any memory gcc knows
17065 about */
17066 asm volatile(
17067 @@ -151,10 +155,14 @@ EXPORT_SYMBOL(strlen_user);
17068
17069 unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
17070 {
17071 - if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
17072 + if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
17073 + if ((unsigned long)to < PAX_USER_SHADOW_BASE)
17074 + to += PAX_USER_SHADOW_BASE;
17075 + if ((unsigned long)from < PAX_USER_SHADOW_BASE)
17076 + from += PAX_USER_SHADOW_BASE;
17077 return copy_user_generic((__force void *)to, (__force void *)from, len);
17078 - }
17079 - return len;
17080 + }
17081 + return len;
17082 }
17083 EXPORT_SYMBOL(copy_in_user);
17084
17085 diff -urNp linux-2.6.37/arch/x86/Makefile linux-2.6.37/arch/x86/Makefile
17086 --- linux-2.6.37/arch/x86/Makefile 2011-01-04 19:50:19.000000000 -0500
17087 +++ linux-2.6.37/arch/x86/Makefile 2011-01-17 02:41:01.000000000 -0500
17088 @@ -195,3 +195,12 @@ define archhelp
17089 echo ' FDARGS="..." arguments for the booted kernel'
17090 echo ' FDINITRD=file initrd for the booted kernel'
17091 endef
17092 +
17093 +define OLD_LD
17094 +
17095 +*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
17096 +*** Please upgrade your binutils to 2.18 or newer
17097 +endef
17098 +
17099 +archprepare:
17100 + $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
17101 diff -urNp linux-2.6.37/arch/x86/mm/extable.c linux-2.6.37/arch/x86/mm/extable.c
17102 --- linux-2.6.37/arch/x86/mm/extable.c 2011-01-04 19:50:19.000000000 -0500
17103 +++ linux-2.6.37/arch/x86/mm/extable.c 2011-01-17 02:41:01.000000000 -0500
17104 @@ -1,14 +1,71 @@
17105 #include <linux/module.h>
17106 #include <linux/spinlock.h>
17107 +#include <linux/sort.h>
17108 #include <asm/uaccess.h>
17109 +#include <asm/pgtable.h>
17110
17111 +/*
17112 + * The exception table needs to be sorted so that the binary
17113 + * search that we use to find entries in it works properly.
17114 + * This is used both for the kernel exception table and for
17115 + * the exception tables of modules that get loaded.
17116 + */
17117 +static int cmp_ex(const void *a, const void *b)
17118 +{
17119 + const struct exception_table_entry *x = a, *y = b;
17120 +
17121 + /* avoid overflow */
17122 + if (x->insn > y->insn)
17123 + return 1;
17124 + if (x->insn < y->insn)
17125 + return -1;
17126 + return 0;
17127 +}
17128 +
17129 +static void swap_ex(void *a, void *b, int size)
17130 +{
17131 + struct exception_table_entry t, *x = a, *y = b;
17132 +
17133 + t = *x;
17134 +
17135 + pax_open_kernel();
17136 + *x = *y;
17137 + *y = t;
17138 + pax_close_kernel();
17139 +}
17140 +
17141 +void sort_extable(struct exception_table_entry *start,
17142 + struct exception_table_entry *finish)
17143 +{
17144 + sort(start, finish - start, sizeof(struct exception_table_entry),
17145 + cmp_ex, swap_ex);
17146 +}
17147 +
17148 +#ifdef CONFIG_MODULES
17149 +/*
17150 + * If the exception table is sorted, any referring to the module init
17151 + * will be at the beginning or the end.
17152 + */
17153 +void trim_init_extable(struct module *m)
17154 +{
17155 + /*trim the beginning*/
17156 + while (m->num_exentries && within_module_init(m->extable[0].insn, m)) {
17157 + m->extable++;
17158 + m->num_exentries--;
17159 + }
17160 + /*trim the end*/
17161 + while (m->num_exentries &&
17162 + within_module_init(m->extable[m->num_exentries-1].insn, m))
17163 + m->num_exentries--;
17164 +}
17165 +#endif /* CONFIG_MODULES */
17166
17167 int fixup_exception(struct pt_regs *regs)
17168 {
17169 const struct exception_table_entry *fixup;
17170
17171 #ifdef CONFIG_PNPBIOS
17172 - if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
17173 + if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
17174 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
17175 extern u32 pnp_bios_is_utter_crap;
17176 pnp_bios_is_utter_crap = 1;
17177 diff -urNp linux-2.6.37/arch/x86/mm/fault.c linux-2.6.37/arch/x86/mm/fault.c
17178 --- linux-2.6.37/arch/x86/mm/fault.c 2011-01-04 19:50:19.000000000 -0500
17179 +++ linux-2.6.37/arch/x86/mm/fault.c 2011-01-17 02:41:01.000000000 -0500
17180 @@ -12,10 +12,18 @@
17181 #include <linux/mmiotrace.h> /* kmmio_handler, ... */
17182 #include <linux/perf_event.h> /* perf_sw_event */
17183 #include <linux/hugetlb.h> /* hstate_index_to_shift */
17184 +#include <linux/unistd.h>
17185 +#include <linux/compiler.h>
17186
17187 #include <asm/traps.h> /* dotraplinkage, ... */
17188 #include <asm/pgalloc.h> /* pgd_*(), ... */
17189 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
17190 +#include <asm/vsyscall.h>
17191 +#include <asm/tlbflush.h>
17192 +
17193 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17194 +#include <asm/stacktrace.h>
17195 +#endif
17196
17197 /*
17198 * Page fault error code bits:
17199 @@ -53,7 +61,7 @@ static inline int __kprobes notify_page_
17200 int ret = 0;
17201
17202 /* kprobe_running() needs smp_processor_id() */
17203 - if (kprobes_built_in() && !user_mode_vm(regs)) {
17204 + if (kprobes_built_in() && !user_mode(regs)) {
17205 preempt_disable();
17206 if (kprobe_running() && kprobe_fault_handler(regs, 14))
17207 ret = 1;
17208 @@ -114,7 +122,10 @@ check_prefetch_opcode(struct pt_regs *re
17209 return !instr_lo || (instr_lo>>1) == 1;
17210 case 0x00:
17211 /* Prefetch instruction is 0x0F0D or 0x0F18 */
17212 - if (probe_kernel_address(instr, opcode))
17213 + if (user_mode(regs)) {
17214 + if (__copy_from_user_inatomic(&opcode, (__force unsigned char __user *)(instr), 1))
17215 + return 0;
17216 + } else if (probe_kernel_address(instr, opcode))
17217 return 0;
17218
17219 *prefetch = (instr_lo == 0xF) &&
17220 @@ -148,7 +159,10 @@ is_prefetch(struct pt_regs *regs, unsign
17221 while (instr < max_instr) {
17222 unsigned char opcode;
17223
17224 - if (probe_kernel_address(instr, opcode))
17225 + if (user_mode(regs)) {
17226 + if (__copy_from_user_inatomic(&opcode, (__force unsigned char __user *)(instr), 1))
17227 + break;
17228 + } else if (probe_kernel_address(instr, opcode))
17229 break;
17230
17231 instr++;
17232 @@ -179,6 +193,30 @@ force_sig_info_fault(int si_signo, int s
17233 force_sig_info(si_signo, &info, tsk);
17234 }
17235
17236 +#ifdef CONFIG_PAX_EMUTRAMP
17237 +static int pax_handle_fetch_fault(struct pt_regs *regs);
17238 +#endif
17239 +
17240 +#ifdef CONFIG_PAX_PAGEEXEC
17241 +static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
17242 +{
17243 + pgd_t *pgd;
17244 + pud_t *pud;
17245 + pmd_t *pmd;
17246 +
17247 + pgd = pgd_offset(mm, address);
17248 + if (!pgd_present(*pgd))
17249 + return NULL;
17250 + pud = pud_offset(pgd, address);
17251 + if (!pud_present(*pud))
17252 + return NULL;
17253 + pmd = pmd_offset(pud, address);
17254 + if (!pmd_present(*pmd))
17255 + return NULL;
17256 + return pmd;
17257 +}
17258 +#endif
17259 +
17260 DEFINE_SPINLOCK(pgd_lock);
17261 LIST_HEAD(pgd_list);
17262
17263 @@ -231,18 +269,35 @@ void vmalloc_sync_all(void)
17264 address += PMD_SIZE) {
17265
17266 unsigned long flags;
17267 +
17268 +#ifdef CONFIG_PAX_PER_CPU_PGD
17269 + unsigned long cpu;
17270 +#else
17271 struct page *page;
17272 +#endif
17273
17274 spin_lock_irqsave(&pgd_lock, flags);
17275 +
17276 +#ifdef CONFIG_PAX_PER_CPU_PGD
17277 + for (cpu = 0; cpu < NR_CPUS; ++cpu) {
17278 + pgd_t *pgd = get_cpu_pgd(cpu);
17279 + pmd_t *ret;
17280 +#else
17281 list_for_each_entry(page, &pgd_list, lru) {
17282 + pgd_t *pgd = page_address(page);
17283 spinlock_t *pgt_lock;
17284 pmd_t *ret;
17285
17286 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
17287
17288 spin_lock(pgt_lock);
17289 - ret = vmalloc_sync_one(page_address(page), address);
17290 +#endif
17291 +
17292 + ret = vmalloc_sync_one(pgd, address);
17293 +
17294 +#ifndef CONFIG_PAX_PER_CPU_PGD
17295 spin_unlock(pgt_lock);
17296 +#endif
17297
17298 if (!ret)
17299 break;
17300 @@ -276,6 +331,11 @@ static noinline __kprobes int vmalloc_fa
17301 * an interrupt in the middle of a task switch..
17302 */
17303 pgd_paddr = read_cr3();
17304 +
17305 +#ifdef CONFIG_PAX_PER_CPU_PGD
17306 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (pgd_paddr & PHYSICAL_PAGE_MASK));
17307 +#endif
17308 +
17309 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
17310 if (!pmd_k)
17311 return -1;
17312 @@ -371,7 +431,14 @@ static noinline __kprobes int vmalloc_fa
17313 * happen within a race in page table update. In the later
17314 * case just flush:
17315 */
17316 +
17317 +#ifdef CONFIG_PAX_PER_CPU_PGD
17318 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (read_cr3() & PHYSICAL_PAGE_MASK));
17319 + pgd = pgd_offset_cpu(smp_processor_id(), address);
17320 +#else
17321 pgd = pgd_offset(current->active_mm, address);
17322 +#endif
17323 +
17324 pgd_ref = pgd_offset_k(address);
17325 if (pgd_none(*pgd_ref))
17326 return -1;
17327 @@ -533,7 +600,7 @@ static int is_errata93(struct pt_regs *r
17328 static int is_errata100(struct pt_regs *regs, unsigned long address)
17329 {
17330 #ifdef CONFIG_X86_64
17331 - if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
17332 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
17333 return 1;
17334 #endif
17335 return 0;
17336 @@ -560,7 +627,7 @@ static int is_f00f_bug(struct pt_regs *r
17337 }
17338
17339 static const char nx_warning[] = KERN_CRIT
17340 -"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
17341 +"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
17342
17343 static void
17344 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
17345 @@ -569,15 +636,26 @@ show_fault_oops(struct pt_regs *regs, un
17346 if (!oops_may_print())
17347 return;
17348
17349 - if (error_code & PF_INSTR) {
17350 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
17351 unsigned int level;
17352
17353 pte_t *pte = lookup_address(address, &level);
17354
17355 if (pte && pte_present(*pte) && !pte_exec(*pte))
17356 - printk(nx_warning, current_uid());
17357 + printk(nx_warning, current_uid(), current->comm, task_pid_nr(current));
17358 }
17359
17360 +#ifdef CONFIG_PAX_KERNEXEC
17361 + if (init_mm.start_code <= address && address < init_mm.end_code) {
17362 + if (current->signal->curr_ip)
17363 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
17364 + &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
17365 + else
17366 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
17367 + current->comm, task_pid_nr(current), current_uid(), current_euid());
17368 + }
17369 +#endif
17370 +
17371 printk(KERN_ALERT "BUG: unable to handle kernel ");
17372 if (address < PAGE_SIZE)
17373 printk(KERN_CONT "NULL pointer dereference");
17374 @@ -702,6 +780,68 @@ __bad_area_nosemaphore(struct pt_regs *r
17375 unsigned long address, int si_code)
17376 {
17377 struct task_struct *tsk = current;
17378 + struct mm_struct *mm = tsk->mm;
17379 +
17380 +#ifdef CONFIG_X86_64
17381 + if (mm && (error_code & PF_INSTR) && mm->context.vdso) {
17382 + if (regs->ip == (unsigned long)vgettimeofday) {
17383 + regs->ip = (unsigned long)VDSO64_SYMBOL(mm->context.vdso, fallback_gettimeofday);
17384 + return;
17385 + } else if (regs->ip == (unsigned long)vtime) {
17386 + regs->ip = (unsigned long)VDSO64_SYMBOL(mm->context.vdso, fallback_time);
17387 + return;
17388 + } else if (regs->ip == (unsigned long)vgetcpu) {
17389 + regs->ip = (unsigned long)VDSO64_SYMBOL(mm->context.vdso, getcpu);
17390 + return;
17391 + }
17392 + }
17393 +#endif
17394 +
17395 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
17396 + if (mm && (error_code & PF_USER)) {
17397 + unsigned long ip = regs->ip;
17398 +
17399 + if (v8086_mode(regs))
17400 + ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
17401 +
17402 + /*
17403 + * It's possible to have interrupts off here:
17404 + */
17405 + local_irq_enable();
17406 +
17407 +#ifdef CONFIG_PAX_PAGEEXEC
17408 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) &&
17409 + (((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) || (!(error_code & (PF_PROT | PF_WRITE)) && ip == address))) {
17410 +
17411 +#ifdef CONFIG_PAX_EMUTRAMP
17412 + switch (pax_handle_fetch_fault(regs)) {
17413 + case 2:
17414 + return;
17415 + }
17416 +#endif
17417 +
17418 + pax_report_fault(regs, (void *)ip, (void *)regs->sp);
17419 + do_group_exit(SIGKILL);
17420 + }
17421 +#endif
17422 +
17423 +#ifdef CONFIG_PAX_SEGMEXEC
17424 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && !(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address)) {
17425 +
17426 +#ifdef CONFIG_PAX_EMUTRAMP
17427 + switch (pax_handle_fetch_fault(regs)) {
17428 + case 2:
17429 + return;
17430 + }
17431 +#endif
17432 +
17433 + pax_report_fault(regs, (void *)ip, (void *)regs->sp);
17434 + do_group_exit(SIGKILL);
17435 + }
17436 +#endif
17437 +
17438 + }
17439 +#endif
17440
17441 /* User mode accesses just cause a SIGSEGV */
17442 if (error_code & PF_USER) {
17443 @@ -849,6 +989,99 @@ static int spurious_fault_check(unsigned
17444 return 1;
17445 }
17446
17447 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
17448 +static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
17449 +{
17450 + pte_t *pte;
17451 + pmd_t *pmd;
17452 + spinlock_t *ptl;
17453 + unsigned char pte_mask;
17454 +
17455 + if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
17456 + !(mm->pax_flags & MF_PAX_PAGEEXEC))
17457 + return 0;
17458 +
17459 + /* PaX: it's our fault, let's handle it if we can */
17460 +
17461 + /* PaX: take a look at read faults before acquiring any locks */
17462 + if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
17463 + /* instruction fetch attempt from a protected page in user mode */
17464 + up_read(&mm->mmap_sem);
17465 +
17466 +#ifdef CONFIG_PAX_EMUTRAMP
17467 + switch (pax_handle_fetch_fault(regs)) {
17468 + case 2:
17469 + return 1;
17470 + }
17471 +#endif
17472 +
17473 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
17474 + do_group_exit(SIGKILL);
17475 + }
17476 +
17477 + pmd = pax_get_pmd(mm, address);
17478 + if (unlikely(!pmd))
17479 + return 0;
17480 +
17481 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
17482 + if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
17483 + pte_unmap_unlock(pte, ptl);
17484 + return 0;
17485 + }
17486 +
17487 + if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
17488 + /* write attempt to a protected page in user mode */
17489 + pte_unmap_unlock(pte, ptl);
17490 + return 0;
17491 + }
17492 +
17493 +#ifdef CONFIG_SMP
17494 + if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
17495 +#else
17496 + if (likely(address > get_limit(regs->cs)))
17497 +#endif
17498 + {
17499 + set_pte(pte, pte_mkread(*pte));
17500 + __flush_tlb_one(address);
17501 + pte_unmap_unlock(pte, ptl);
17502 + up_read(&mm->mmap_sem);
17503 + return 1;
17504 + }
17505 +
17506 + pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
17507 +
17508 + /*
17509 + * PaX: fill DTLB with user rights and retry
17510 + */
17511 + __asm__ __volatile__ (
17512 + "orb %2,(%1)\n"
17513 +#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
17514 +/*
17515 + * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
17516 + * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
17517 + * page fault when examined during a TLB load attempt. this is true not only
17518 + * for PTEs holding a non-present entry but also present entries that will
17519 + * raise a page fault (such as those set up by PaX, or the copy-on-write
17520 + * mechanism). in effect it means that we do *not* need to flush the TLBs
17521 + * for our target pages since their PTEs are simply not in the TLBs at all.
17522 +
17523 + * the best thing in omitting it is that we gain around 15-20% speed in the
17524 + * fast path of the page fault handler and can get rid of tracing since we
17525 + * can no longer flush unintended entries.
17526 + */
17527 + "invlpg (%0)\n"
17528 +#endif
17529 + "testb $0,"__copyuser_seg"(%0)\n"
17530 + "xorb %3,(%1)\n"
17531 + :
17532 + : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
17533 + : "memory", "cc");
17534 + pte_unmap_unlock(pte, ptl);
17535 + up_read(&mm->mmap_sem);
17536 + return 1;
17537 +}
17538 +#endif
17539 +
17540 /*
17541 * Handle a spurious fault caused by a stale TLB entry.
17542 *
17543 @@ -921,6 +1154,9 @@ int show_unhandled_signals = 1;
17544 static inline int
17545 access_error(unsigned long error_code, struct vm_area_struct *vma)
17546 {
17547 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
17548 + return 1;
17549 +
17550 if (error_code & PF_WRITE) {
17551 /* write, present and write, not present: */
17552 if (unlikely(!(vma->vm_flags & VM_WRITE)))
17553 @@ -954,19 +1190,33 @@ do_page_fault(struct pt_regs *regs, unsi
17554 {
17555 struct vm_area_struct *vma;
17556 struct task_struct *tsk;
17557 - unsigned long address;
17558 struct mm_struct *mm;
17559 int fault;
17560 int write = error_code & PF_WRITE;
17561 unsigned int flags = FAULT_FLAG_ALLOW_RETRY |
17562 (write ? FAULT_FLAG_WRITE : 0);
17563
17564 + /* Get the faulting address: */
17565 + unsigned long address = read_cr2();
17566 +
17567 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17568 + if (!user_mode(regs) && address < 2 * PAX_USER_SHADOW_BASE) {
17569 + if (!search_exception_tables(regs->ip)) {
17570 + bad_area_nosemaphore(regs, error_code, address);
17571 + return;
17572 + }
17573 + if (address < PAX_USER_SHADOW_BASE) {
17574 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
17575 + printk(KERN_ERR "PAX: faulting IP: %pA\n", (void *)regs->ip);
17576 + show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
17577 + } else
17578 + address -= PAX_USER_SHADOW_BASE;
17579 + }
17580 +#endif
17581 +
17582 tsk = current;
17583 mm = tsk->mm;
17584
17585 - /* Get the faulting address: */
17586 - address = read_cr2();
17587 -
17588 /*
17589 * Detect and handle instructions that would cause a page fault for
17590 * both a tracked kernel page and a userspace page.
17591 @@ -1026,7 +1276,7 @@ do_page_fault(struct pt_regs *regs, unsi
17592 * User-mode registers count as a user access even for any
17593 * potential system fault or CPU buglet:
17594 */
17595 - if (user_mode_vm(regs)) {
17596 + if (user_mode(regs)) {
17597 local_irq_enable();
17598 error_code |= PF_USER;
17599 } else {
17600 @@ -1081,6 +1331,11 @@ retry:
17601 might_sleep();
17602 }
17603
17604 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
17605 + if (pax_handle_pageexec_fault(regs, mm, address, error_code))
17606 + return;
17607 +#endif
17608 +
17609 vma = find_vma(mm, address);
17610 if (unlikely(!vma)) {
17611 bad_area(regs, error_code, address);
17612 @@ -1092,18 +1347,24 @@ retry:
17613 bad_area(regs, error_code, address);
17614 return;
17615 }
17616 - if (error_code & PF_USER) {
17617 - /*
17618 - * Accessing the stack below %sp is always a bug.
17619 - * The large cushion allows instructions like enter
17620 - * and pusha to work. ("enter $65535, $31" pushes
17621 - * 32 pointers and then decrements %sp by 65535.)
17622 - */
17623 - if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
17624 - bad_area(regs, error_code, address);
17625 - return;
17626 - }
17627 + /*
17628 + * Accessing the stack below %sp is always a bug.
17629 + * The large cushion allows instructions like enter
17630 + * and pusha to work. ("enter $65535, $31" pushes
17631 + * 32 pointers and then decrements %sp by 65535.)
17632 + */
17633 + if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
17634 + bad_area(regs, error_code, address);
17635 + return;
17636 }
17637 +
17638 +#ifdef CONFIG_PAX_SEGMEXEC
17639 + if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
17640 + bad_area(regs, error_code, address);
17641 + return;
17642 + }
17643 +#endif
17644 +
17645 if (unlikely(expand_stack(vma, address))) {
17646 bad_area(regs, error_code, address);
17647 return;
17648 @@ -1158,3 +1419,199 @@ good_area:
17649
17650 up_read(&mm->mmap_sem);
17651 }
17652 +
17653 +#ifdef CONFIG_PAX_EMUTRAMP
17654 +static int pax_handle_fetch_fault_32(struct pt_regs *regs)
17655 +{
17656 + int err;
17657 +
17658 + do { /* PaX: gcc trampoline emulation #1 */
17659 + unsigned char mov1, mov2;
17660 + unsigned short jmp;
17661 + unsigned int addr1, addr2;
17662 +
17663 +#ifdef CONFIG_X86_64
17664 + if ((regs->ip + 11) >> 32)
17665 + break;
17666 +#endif
17667 +
17668 + err = get_user(mov1, (unsigned char __user *)regs->ip);
17669 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
17670 + err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
17671 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
17672 + err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
17673 +
17674 + if (err)
17675 + break;
17676 +
17677 + if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
17678 + regs->cx = addr1;
17679 + regs->ax = addr2;
17680 + regs->ip = addr2;
17681 + return 2;
17682 + }
17683 + } while (0);
17684 +
17685 + do { /* PaX: gcc trampoline emulation #2 */
17686 + unsigned char mov, jmp;
17687 + unsigned int addr1, addr2;
17688 +
17689 +#ifdef CONFIG_X86_64
17690 + if ((regs->ip + 9) >> 32)
17691 + break;
17692 +#endif
17693 +
17694 + err = get_user(mov, (unsigned char __user *)regs->ip);
17695 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
17696 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
17697 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
17698 +
17699 + if (err)
17700 + break;
17701 +
17702 + if (mov == 0xB9 && jmp == 0xE9) {
17703 + regs->cx = addr1;
17704 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
17705 + return 2;
17706 + }
17707 + } while (0);
17708 +
17709 + return 1; /* PaX in action */
17710 +}
17711 +
17712 +#ifdef CONFIG_X86_64
17713 +static int pax_handle_fetch_fault_64(struct pt_regs *regs)
17714 +{
17715 + int err;
17716 +
17717 + do { /* PaX: gcc trampoline emulation #1 */
17718 + unsigned short mov1, mov2, jmp1;
17719 + unsigned char jmp2;
17720 + unsigned int addr1;
17721 + unsigned long addr2;
17722 +
17723 + err = get_user(mov1, (unsigned short __user *)regs->ip);
17724 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
17725 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
17726 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
17727 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
17728 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
17729 +
17730 + if (err)
17731 + break;
17732 +
17733 + if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
17734 + regs->r11 = addr1;
17735 + regs->r10 = addr2;
17736 + regs->ip = addr1;
17737 + return 2;
17738 + }
17739 + } while (0);
17740 +
17741 + do { /* PaX: gcc trampoline emulation #2 */
17742 + unsigned short mov1, mov2, jmp1;
17743 + unsigned char jmp2;
17744 + unsigned long addr1, addr2;
17745 +
17746 + err = get_user(mov1, (unsigned short __user *)regs->ip);
17747 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
17748 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
17749 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
17750 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
17751 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
17752 +
17753 + if (err)
17754 + break;
17755 +
17756 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
17757 + regs->r11 = addr1;
17758 + regs->r10 = addr2;
17759 + regs->ip = addr1;
17760 + return 2;
17761 + }
17762 + } while (0);
17763 +
17764 + return 1; /* PaX in action */
17765 +}
17766 +#endif
17767 +
17768 +/*
17769 + * PaX: decide what to do with offenders (regs->ip = fault address)
17770 + *
17771 + * returns 1 when task should be killed
17772 + * 2 when gcc trampoline was detected
17773 + */
17774 +static int pax_handle_fetch_fault(struct pt_regs *regs)
17775 +{
17776 + if (v8086_mode(regs))
17777 + return 1;
17778 +
17779 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
17780 + return 1;
17781 +
17782 +#ifdef CONFIG_X86_32
17783 + return pax_handle_fetch_fault_32(regs);
17784 +#else
17785 + if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
17786 + return pax_handle_fetch_fault_32(regs);
17787 + else
17788 + return pax_handle_fetch_fault_64(regs);
17789 +#endif
17790 +}
17791 +#endif
17792 +
17793 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
17794 +void pax_report_insns(void *pc, void *sp)
17795 +{
17796 + long i;
17797 +
17798 + printk(KERN_ERR "PAX: bytes at PC: ");
17799 + for (i = 0; i < 20; i++) {
17800 + unsigned char c;
17801 + if (get_user(c, (__force unsigned char __user *)pc+i))
17802 + printk(KERN_CONT "?? ");
17803 + else
17804 + printk(KERN_CONT "%02x ", c);
17805 + }
17806 + printk("\n");
17807 +
17808 + printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
17809 + for (i = -1; i < 80 / (long)sizeof(long); i++) {
17810 + unsigned long c;
17811 + if (get_user(c, (__force unsigned long __user *)sp+i))
17812 +#ifdef CONFIG_X86_32
17813 + printk(KERN_CONT "???????? ");
17814 +#else
17815 + printk(KERN_CONT "???????????????? ");
17816 +#endif
17817 + else
17818 + printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
17819 + }
17820 + printk("\n");
17821 +}
17822 +#endif
17823 +
17824 +/**
17825 + * probe_kernel_write(): safely attempt to write to a location
17826 + * @dst: address to write to
17827 + * @src: pointer to the data that shall be written
17828 + * @size: size of the data chunk
17829 + *
17830 + * Safely write to address @dst from the buffer at @src. If a kernel fault
17831 + * happens, handle that and return -EFAULT.
17832 + */
17833 +long notrace probe_kernel_write(void *dst, const void *src, size_t size)
17834 +{
17835 + long ret;
17836 + mm_segment_t old_fs = get_fs();
17837 +
17838 + set_fs(KERNEL_DS);
17839 + pagefault_disable();
17840 + pax_open_kernel();
17841 + ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
17842 + pax_close_kernel();
17843 + pagefault_enable();
17844 + set_fs(old_fs);
17845 +
17846 + return ret ? -EFAULT : 0;
17847 +}
17848 diff -urNp linux-2.6.37/arch/x86/mm/gup.c linux-2.6.37/arch/x86/mm/gup.c
17849 --- linux-2.6.37/arch/x86/mm/gup.c 2011-01-04 19:50:19.000000000 -0500
17850 +++ linux-2.6.37/arch/x86/mm/gup.c 2011-01-17 02:41:01.000000000 -0500
17851 @@ -237,7 +237,7 @@ int __get_user_pages_fast(unsigned long
17852 addr = start;
17853 len = (unsigned long) nr_pages << PAGE_SHIFT;
17854 end = start + len;
17855 - if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
17856 + if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
17857 (void __user *)start, len)))
17858 return 0;
17859
17860 diff -urNp linux-2.6.37/arch/x86/mm/highmem_32.c linux-2.6.37/arch/x86/mm/highmem_32.c
17861 --- linux-2.6.37/arch/x86/mm/highmem_32.c 2011-01-04 19:50:19.000000000 -0500
17862 +++ linux-2.6.37/arch/x86/mm/highmem_32.c 2011-01-17 02:41:01.000000000 -0500
17863 @@ -44,7 +44,10 @@ void *kmap_atomic_prot(struct page *page
17864 idx = type + KM_TYPE_NR*smp_processor_id();
17865 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
17866 BUG_ON(!pte_none(*(kmap_pte-idx)));
17867 +
17868 + pax_open_kernel();
17869 set_pte(kmap_pte-idx, mk_pte(page, prot));
17870 + pax_close_kernel();
17871
17872 return (void *)vaddr;
17873 }
17874 diff -urNp linux-2.6.37/arch/x86/mm/hugetlbpage.c linux-2.6.37/arch/x86/mm/hugetlbpage.c
17875 --- linux-2.6.37/arch/x86/mm/hugetlbpage.c 2011-01-04 19:50:19.000000000 -0500
17876 +++ linux-2.6.37/arch/x86/mm/hugetlbpage.c 2011-01-17 02:41:01.000000000 -0500
17877 @@ -266,13 +266,20 @@ static unsigned long hugetlb_get_unmappe
17878 struct hstate *h = hstate_file(file);
17879 struct mm_struct *mm = current->mm;
17880 struct vm_area_struct *vma;
17881 - unsigned long start_addr;
17882 + unsigned long start_addr, pax_task_size = TASK_SIZE;
17883 +
17884 +#ifdef CONFIG_PAX_SEGMEXEC
17885 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
17886 + pax_task_size = SEGMEXEC_TASK_SIZE;
17887 +#endif
17888 +
17889 + pax_task_size -= PAGE_SIZE;
17890
17891 if (len > mm->cached_hole_size) {
17892 - start_addr = mm->free_area_cache;
17893 + start_addr = mm->free_area_cache;
17894 } else {
17895 - start_addr = TASK_UNMAPPED_BASE;
17896 - mm->cached_hole_size = 0;
17897 + start_addr = mm->mmap_base;
17898 + mm->cached_hole_size = 0;
17899 }
17900
17901 full_search:
17902 @@ -280,26 +287,27 @@ full_search:
17903
17904 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
17905 /* At this point: (!vma || addr < vma->vm_end). */
17906 - if (TASK_SIZE - len < addr) {
17907 + if (pax_task_size - len < addr) {
17908 /*
17909 * Start a new search - just in case we missed
17910 * some holes.
17911 */
17912 - if (start_addr != TASK_UNMAPPED_BASE) {
17913 - start_addr = TASK_UNMAPPED_BASE;
17914 + if (start_addr != mm->mmap_base) {
17915 + start_addr = mm->mmap_base;
17916 mm->cached_hole_size = 0;
17917 goto full_search;
17918 }
17919 return -ENOMEM;
17920 }
17921 - if (!vma || addr + len <= vma->vm_start) {
17922 - mm->free_area_cache = addr + len;
17923 - return addr;
17924 - }
17925 + if (check_heap_stack_gap(vma, addr, len))
17926 + break;
17927 if (addr + mm->cached_hole_size < vma->vm_start)
17928 mm->cached_hole_size = vma->vm_start - addr;
17929 addr = ALIGN(vma->vm_end, huge_page_size(h));
17930 }
17931 +
17932 + mm->free_area_cache = addr + len;
17933 + return addr;
17934 }
17935
17936 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
17937 @@ -308,10 +316,9 @@ static unsigned long hugetlb_get_unmappe
17938 {
17939 struct hstate *h = hstate_file(file);
17940 struct mm_struct *mm = current->mm;
17941 - struct vm_area_struct *vma, *prev_vma;
17942 - unsigned long base = mm->mmap_base, addr = addr0;
17943 + struct vm_area_struct *vma;
17944 + unsigned long base = mm->mmap_base, addr;
17945 unsigned long largest_hole = mm->cached_hole_size;
17946 - int first_time = 1;
17947
17948 /* don't allow allocations above current base */
17949 if (mm->free_area_cache > base)
17950 @@ -321,7 +328,7 @@ static unsigned long hugetlb_get_unmappe
17951 largest_hole = 0;
17952 mm->free_area_cache = base;
17953 }
17954 -try_again:
17955 +
17956 /* make sure it can fit in the remaining address space */
17957 if (mm->free_area_cache < len)
17958 goto fail;
17959 @@ -329,33 +336,27 @@ try_again:
17960 /* either no address requested or cant fit in requested address hole */
17961 addr = (mm->free_area_cache - len) & huge_page_mask(h);
17962 do {
17963 + vma = find_vma(mm, addr);
17964 /*
17965 * Lookup failure means no vma is above this address,
17966 * i.e. return with success:
17967 - */
17968 - if (!(vma = find_vma_prev(mm, addr, &prev_vma)))
17969 - return addr;
17970 -
17971 - /*
17972 * new region fits between prev_vma->vm_end and
17973 * vma->vm_start, use it:
17974 */
17975 - if (addr + len <= vma->vm_start &&
17976 - (!prev_vma || (addr >= prev_vma->vm_end))) {
17977 + if (check_heap_stack_gap(vma, addr, len)) {
17978 /* remember the address as a hint for next time */
17979 - mm->cached_hole_size = largest_hole;
17980 - return (mm->free_area_cache = addr);
17981 - } else {
17982 - /* pull free_area_cache down to the first hole */
17983 - if (mm->free_area_cache == vma->vm_end) {
17984 - mm->free_area_cache = vma->vm_start;
17985 - mm->cached_hole_size = largest_hole;
17986 - }
17987 + mm->cached_hole_size = largest_hole;
17988 + return (mm->free_area_cache = addr);
17989 + }
17990 + /* pull free_area_cache down to the first hole */
17991 + if (mm->free_area_cache == vma->vm_end) {
17992 + mm->free_area_cache = vma->vm_start;
17993 + mm->cached_hole_size = largest_hole;
17994 }
17995
17996 /* remember the largest hole we saw so far */
17997 if (addr + largest_hole < vma->vm_start)
17998 - largest_hole = vma->vm_start - addr;
17999 + largest_hole = vma->vm_start - addr;
18000
18001 /* try just below the current vma->vm_start */
18002 addr = (vma->vm_start - len) & huge_page_mask(h);
18003 @@ -363,22 +364,26 @@ try_again:
18004
18005 fail:
18006 /*
18007 - * if hint left us with no space for the requested
18008 - * mapping then try again:
18009 - */
18010 - if (first_time) {
18011 - mm->free_area_cache = base;
18012 - largest_hole = 0;
18013 - first_time = 0;
18014 - goto try_again;
18015 - }
18016 - /*
18017 * A failed mmap() very likely causes application failure,
18018 * so fall back to the bottom-up function here. This scenario
18019 * can happen with large stack limits and large mmap()
18020 * allocations.
18021 */
18022 - mm->free_area_cache = TASK_UNMAPPED_BASE;
18023 +
18024 +#ifdef CONFIG_PAX_SEGMEXEC
18025 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
18026 + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
18027 + else
18028 +#endif
18029 +
18030 + mm->mmap_base = TASK_UNMAPPED_BASE;
18031 +
18032 +#ifdef CONFIG_PAX_RANDMMAP
18033 + if (mm->pax_flags & MF_PAX_RANDMMAP)
18034 + mm->mmap_base += mm->delta_mmap;
18035 +#endif
18036 +
18037 + mm->free_area_cache = mm->mmap_base;
18038 mm->cached_hole_size = ~0UL;
18039 addr = hugetlb_get_unmapped_area_bottomup(file, addr0,
18040 len, pgoff, flags);
18041 @@ -386,6 +391,7 @@ fail:
18042 /*
18043 * Restore the topdown base:
18044 */
18045 + mm->mmap_base = base;
18046 mm->free_area_cache = base;
18047 mm->cached_hole_size = ~0UL;
18048
18049 @@ -399,10 +405,19 @@ hugetlb_get_unmapped_area(struct file *f
18050 struct hstate *h = hstate_file(file);
18051 struct mm_struct *mm = current->mm;
18052 struct vm_area_struct *vma;
18053 + unsigned long pax_task_size = TASK_SIZE;
18054
18055 if (len & ~huge_page_mask(h))
18056 return -EINVAL;
18057 - if (len > TASK_SIZE)
18058 +
18059 +#ifdef CONFIG_PAX_SEGMEXEC
18060 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
18061 + pax_task_size = SEGMEXEC_TASK_SIZE;
18062 +#endif
18063 +
18064 + pax_task_size -= PAGE_SIZE;
18065 +
18066 + if (len > pax_task_size)
18067 return -ENOMEM;
18068
18069 if (flags & MAP_FIXED) {
18070 @@ -414,8 +429,7 @@ hugetlb_get_unmapped_area(struct file *f
18071 if (addr) {
18072 addr = ALIGN(addr, huge_page_size(h));
18073 vma = find_vma(mm, addr);
18074 - if (TASK_SIZE - len >= addr &&
18075 - (!vma || addr + len <= vma->vm_start))
18076 + if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
18077 return addr;
18078 }
18079 if (mm->get_unmapped_area == arch_get_unmapped_area)
18080 diff -urNp linux-2.6.37/arch/x86/mm/init_32.c linux-2.6.37/arch/x86/mm/init_32.c
18081 --- linux-2.6.37/arch/x86/mm/init_32.c 2011-01-04 19:50:19.000000000 -0500
18082 +++ linux-2.6.37/arch/x86/mm/init_32.c 2011-01-17 02:41:01.000000000 -0500
18083 @@ -73,36 +73,6 @@ static __init void *alloc_low_page(void)
18084 }
18085
18086 /*
18087 - * Creates a middle page table and puts a pointer to it in the
18088 - * given global directory entry. This only returns the gd entry
18089 - * in non-PAE compilation mode, since the middle layer is folded.
18090 - */
18091 -static pmd_t * __init one_md_table_init(pgd_t *pgd)
18092 -{
18093 - pud_t *pud;
18094 - pmd_t *pmd_table;
18095 -
18096 -#ifdef CONFIG_X86_PAE
18097 - if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
18098 - if (after_bootmem)
18099 - pmd_table = (pmd_t *)alloc_bootmem_pages(PAGE_SIZE);
18100 - else
18101 - pmd_table = (pmd_t *)alloc_low_page();
18102 - paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
18103 - set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
18104 - pud = pud_offset(pgd, 0);
18105 - BUG_ON(pmd_table != pmd_offset(pud, 0));
18106 -
18107 - return pmd_table;
18108 - }
18109 -#endif
18110 - pud = pud_offset(pgd, 0);
18111 - pmd_table = pmd_offset(pud, 0);
18112 -
18113 - return pmd_table;
18114 -}
18115 -
18116 -/*
18117 * Create a page table and place a pointer to it in a middle page
18118 * directory entry:
18119 */
18120 @@ -122,13 +92,28 @@ static pte_t * __init one_page_table_ini
18121 page_table = (pte_t *)alloc_low_page();
18122
18123 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
18124 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
18125 + set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
18126 +#else
18127 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
18128 +#endif
18129 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
18130 }
18131
18132 return pte_offset_kernel(pmd, 0);
18133 }
18134
18135 +static pmd_t * __init one_md_table_init(pgd_t *pgd)
18136 +{
18137 + pud_t *pud;
18138 + pmd_t *pmd_table;
18139 +
18140 + pud = pud_offset(pgd, 0);
18141 + pmd_table = pmd_offset(pud, 0);
18142 +
18143 + return pmd_table;
18144 +}
18145 +
18146 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
18147 {
18148 int pgd_idx = pgd_index(vaddr);
18149 @@ -202,6 +187,7 @@ page_table_range_init(unsigned long star
18150 int pgd_idx, pmd_idx;
18151 unsigned long vaddr;
18152 pgd_t *pgd;
18153 + pud_t *pud;
18154 pmd_t *pmd;
18155 pte_t *pte = NULL;
18156
18157 @@ -211,8 +197,13 @@ page_table_range_init(unsigned long star
18158 pgd = pgd_base + pgd_idx;
18159
18160 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
18161 - pmd = one_md_table_init(pgd);
18162 - pmd = pmd + pmd_index(vaddr);
18163 + pud = pud_offset(pgd, vaddr);
18164 + pmd = pmd_offset(pud, vaddr);
18165 +
18166 +#ifdef CONFIG_X86_PAE
18167 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
18168 +#endif
18169 +
18170 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
18171 pmd++, pmd_idx++) {
18172 pte = page_table_kmap_check(one_page_table_init(pmd),
18173 @@ -224,11 +215,20 @@ page_table_range_init(unsigned long star
18174 }
18175 }
18176
18177 -static inline int is_kernel_text(unsigned long addr)
18178 +static inline int is_kernel_text(unsigned long start, unsigned long end)
18179 {
18180 - if (addr >= PAGE_OFFSET && addr <= (unsigned long)__init_end)
18181 - return 1;
18182 - return 0;
18183 + if ((start > ktla_ktva((unsigned long)_etext) ||
18184 + end <= ktla_ktva((unsigned long)_stext)) &&
18185 + (start > ktla_ktva((unsigned long)_einittext) ||
18186 + end <= ktla_ktva((unsigned long)_sinittext)) &&
18187 +
18188 +#ifdef CONFIG_ACPI_SLEEP
18189 + (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
18190 +#endif
18191 +
18192 + (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
18193 + return 0;
18194 + return 1;
18195 }
18196
18197 /*
18198 @@ -245,9 +245,10 @@ kernel_physical_mapping_init(unsigned lo
18199 unsigned long last_map_addr = end;
18200 unsigned long start_pfn, end_pfn;
18201 pgd_t *pgd_base = swapper_pg_dir;
18202 - int pgd_idx, pmd_idx, pte_ofs;
18203 + unsigned int pgd_idx, pmd_idx, pte_ofs;
18204 unsigned long pfn;
18205 pgd_t *pgd;
18206 + pud_t *pud;
18207 pmd_t *pmd;
18208 pte_t *pte;
18209 unsigned pages_2m, pages_4k;
18210 @@ -280,8 +281,13 @@ repeat:
18211 pfn = start_pfn;
18212 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
18213 pgd = pgd_base + pgd_idx;
18214 - for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
18215 - pmd = one_md_table_init(pgd);
18216 + for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
18217 + pud = pud_offset(pgd, 0);
18218 + pmd = pmd_offset(pud, 0);
18219 +
18220 +#ifdef CONFIG_X86_PAE
18221 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
18222 +#endif
18223
18224 if (pfn >= end_pfn)
18225 continue;
18226 @@ -293,14 +299,13 @@ repeat:
18227 #endif
18228 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
18229 pmd++, pmd_idx++) {
18230 - unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
18231 + unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
18232
18233 /*
18234 * Map with big pages if possible, otherwise
18235 * create normal page tables:
18236 */
18237 if (use_pse) {
18238 - unsigned int addr2;
18239 pgprot_t prot = PAGE_KERNEL_LARGE;
18240 /*
18241 * first pass will use the same initial
18242 @@ -310,11 +315,7 @@ repeat:
18243 __pgprot(PTE_IDENT_ATTR |
18244 _PAGE_PSE);
18245
18246 - addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
18247 - PAGE_OFFSET + PAGE_SIZE-1;
18248 -
18249 - if (is_kernel_text(addr) ||
18250 - is_kernel_text(addr2))
18251 + if (is_kernel_text(address, address + PMD_SIZE))
18252 prot = PAGE_KERNEL_LARGE_EXEC;
18253
18254 pages_2m++;
18255 @@ -331,7 +332,7 @@ repeat:
18256 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
18257 pte += pte_ofs;
18258 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
18259 - pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
18260 + pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
18261 pgprot_t prot = PAGE_KERNEL;
18262 /*
18263 * first pass will use the same initial
18264 @@ -339,7 +340,7 @@ repeat:
18265 */
18266 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
18267
18268 - if (is_kernel_text(addr))
18269 + if (is_kernel_text(address, address + PAGE_SIZE))
18270 prot = PAGE_KERNEL_EXEC;
18271
18272 pages_4k++;
18273 @@ -471,7 +472,7 @@ void __init native_pagetable_setup_start
18274
18275 pud = pud_offset(pgd, va);
18276 pmd = pmd_offset(pud, va);
18277 - if (!pmd_present(*pmd))
18278 + if (!pmd_present(*pmd) || pmd_huge(*pmd))
18279 break;
18280
18281 pte = pte_offset_kernel(pmd, va);
18282 @@ -523,12 +524,10 @@ void __init early_ioremap_page_table_ran
18283
18284 static void __init pagetable_init(void)
18285 {
18286 - pgd_t *pgd_base = swapper_pg_dir;
18287 -
18288 - permanent_kmaps_init(pgd_base);
18289 + permanent_kmaps_init(swapper_pg_dir);
18290 }
18291
18292 -pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
18293 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
18294 EXPORT_SYMBOL_GPL(__supported_pte_mask);
18295
18296 /* user-defined highmem size */
18297 @@ -753,6 +752,12 @@ void __init mem_init(void)
18298
18299 pci_iommu_alloc();
18300
18301 +#ifdef CONFIG_PAX_PER_CPU_PGD
18302 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
18303 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
18304 + KERNEL_PGD_PTRS);
18305 +#endif
18306 +
18307 #ifdef CONFIG_FLATMEM
18308 BUG_ON(!mem_map);
18309 #endif
18310 @@ -770,7 +775,7 @@ void __init mem_init(void)
18311 set_highmem_pages_init();
18312
18313 codesize = (unsigned long) &_etext - (unsigned long) &_text;
18314 - datasize = (unsigned long) &_edata - (unsigned long) &_etext;
18315 + datasize = (unsigned long) &_edata - (unsigned long) &_sdata;
18316 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
18317
18318 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
18319 @@ -811,10 +816,10 @@ void __init mem_init(void)
18320 ((unsigned long)&__init_end -
18321 (unsigned long)&__init_begin) >> 10,
18322
18323 - (unsigned long)&_etext, (unsigned long)&_edata,
18324 - ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
18325 + (unsigned long)&_sdata, (unsigned long)&_edata,
18326 + ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
18327
18328 - (unsigned long)&_text, (unsigned long)&_etext,
18329 + ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
18330 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
18331
18332 /*
18333 @@ -892,6 +897,7 @@ void set_kernel_text_rw(void)
18334 if (!kernel_set_to_readonly)
18335 return;
18336
18337 + start = ktla_ktva(start);
18338 pr_debug("Set kernel text: %lx - %lx for read write\n",
18339 start, start+size);
18340
18341 @@ -906,6 +912,7 @@ void set_kernel_text_ro(void)
18342 if (!kernel_set_to_readonly)
18343 return;
18344
18345 + start = ktla_ktva(start);
18346 pr_debug("Set kernel text: %lx - %lx for read only\n",
18347 start, start+size);
18348
18349 @@ -917,6 +924,7 @@ void mark_rodata_ro(void)
18350 unsigned long start = PFN_ALIGN(_text);
18351 unsigned long size = PFN_ALIGN(_etext) - start;
18352
18353 + start = ktla_ktva(start);
18354 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
18355 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
18356 size >> 10);
18357 diff -urNp linux-2.6.37/arch/x86/mm/init_64.c linux-2.6.37/arch/x86/mm/init_64.c
18358 --- linux-2.6.37/arch/x86/mm/init_64.c 2011-01-04 19:50:19.000000000 -0500
18359 +++ linux-2.6.37/arch/x86/mm/init_64.c 2011-01-17 02:41:01.000000000 -0500
18360 @@ -72,7 +72,7 @@ early_param("gbpages", parse_direct_gbpa
18361 * around without checking the pgd every time.
18362 */
18363
18364 -pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
18365 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
18366 EXPORT_SYMBOL_GPL(__supported_pte_mask);
18367
18368 int force_personality32;
18369 @@ -106,12 +106,22 @@ void sync_global_pgds(unsigned long star
18370 for (address = start; address <= end; address += PGDIR_SIZE) {
18371 const pgd_t *pgd_ref = pgd_offset_k(address);
18372 unsigned long flags;
18373 +
18374 +#ifdef CONFIG_PAX_PER_CPU_PGD
18375 + unsigned long cpu;
18376 +#else
18377 struct page *page;
18378 +#endif
18379
18380 if (pgd_none(*pgd_ref))
18381 continue;
18382
18383 spin_lock_irqsave(&pgd_lock, flags);
18384 +
18385 +#ifdef CONFIG_PAX_PER_CPU_PGD
18386 + for (cpu = 0; cpu < NR_CPUS; ++cpu) {
18387 + pgd_t *pgd = pgd_offset_cpu(cpu, address);
18388 +#else
18389 list_for_each_entry(page, &pgd_list, lru) {
18390 pgd_t *pgd;
18391 spinlock_t *pgt_lock;
18392 @@ -119,6 +129,7 @@ void sync_global_pgds(unsigned long star
18393 pgd = (pgd_t *)page_address(page) + pgd_index(address);
18394 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
18395 spin_lock(pgt_lock);
18396 +#endif
18397
18398 if (pgd_none(*pgd))
18399 set_pgd(pgd, *pgd_ref);
18400 @@ -126,7 +137,10 @@ void sync_global_pgds(unsigned long star
18401 BUG_ON(pgd_page_vaddr(*pgd)
18402 != pgd_page_vaddr(*pgd_ref));
18403
18404 +#ifndef CONFIG_PAX_PER_CPU_PGD
18405 spin_unlock(pgt_lock);
18406 +#endif
18407 +
18408 }
18409 spin_unlock_irqrestore(&pgd_lock, flags);
18410 }
18411 @@ -200,7 +214,9 @@ void set_pte_vaddr_pud(pud_t *pud_page,
18412 pmd = fill_pmd(pud, vaddr);
18413 pte = fill_pte(pmd, vaddr);
18414
18415 + pax_open_kernel();
18416 set_pte(pte, new_pte);
18417 + pax_close_kernel();
18418
18419 /*
18420 * It's enough to flush this one mapping.
18421 @@ -259,14 +275,12 @@ static void __init __init_extra_mapping(
18422 pgd = pgd_offset_k((unsigned long)__va(phys));
18423 if (pgd_none(*pgd)) {
18424 pud = (pud_t *) spp_getpage();
18425 - set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
18426 - _PAGE_USER));
18427 + set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
18428 }
18429 pud = pud_offset(pgd, (unsigned long)__va(phys));
18430 if (pud_none(*pud)) {
18431 pmd = (pmd_t *) spp_getpage();
18432 - set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
18433 - _PAGE_USER));
18434 + set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
18435 }
18436 pmd = pmd_offset(pud, phys);
18437 BUG_ON(!pmd_none(*pmd));
18438 @@ -706,6 +720,12 @@ void __init mem_init(void)
18439
18440 pci_iommu_alloc();
18441
18442 +#ifdef CONFIG_PAX_PER_CPU_PGD
18443 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
18444 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
18445 + KERNEL_PGD_PTRS);
18446 +#endif
18447 +
18448 /* clear_bss() already clear the empty_zero_page */
18449
18450 reservedpages = 0;
18451 @@ -866,8 +886,8 @@ int kern_addr_valid(unsigned long addr)
18452 static struct vm_area_struct gate_vma = {
18453 .vm_start = VSYSCALL_START,
18454 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
18455 - .vm_page_prot = PAGE_READONLY_EXEC,
18456 - .vm_flags = VM_READ | VM_EXEC
18457 + .vm_page_prot = PAGE_READONLY,
18458 + .vm_flags = VM_READ
18459 };
18460
18461 struct vm_area_struct *get_gate_vma(struct task_struct *tsk)
18462 @@ -901,7 +921,7 @@ int in_gate_area_no_task(unsigned long a
18463
18464 const char *arch_vma_name(struct vm_area_struct *vma)
18465 {
18466 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
18467 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
18468 return "[vdso]";
18469 if (vma == &gate_vma)
18470 return "[vsyscall]";
18471 diff -urNp linux-2.6.37/arch/x86/mm/init.c linux-2.6.37/arch/x86/mm/init.c
18472 --- linux-2.6.37/arch/x86/mm/init.c 2011-01-04 19:50:19.000000000 -0500
18473 +++ linux-2.6.37/arch/x86/mm/init.c 2011-01-17 02:41:01.000000000 -0500
18474 @@ -72,11 +72,7 @@ static void __init find_early_table_spac
18475 * cause a hotspot and fill up ZONE_DMA. The page tables
18476 * need roughly 0.5KB per GB.
18477 */
18478 -#ifdef CONFIG_X86_32
18479 - start = 0x7000;
18480 -#else
18481 - start = 0x8000;
18482 -#endif
18483 + start = 0x100000;
18484 base = memblock_find_in_range(start, max_pfn_mapped<<PAGE_SHIFT,
18485 tables, PAGE_SIZE);
18486 if (base == MEMBLOCK_ERROR)
18487 @@ -323,7 +319,13 @@ unsigned long __init_refok init_memory_m
18488 */
18489 int devmem_is_allowed(unsigned long pagenr)
18490 {
18491 - if (pagenr <= 256)
18492 + if (!pagenr)
18493 + return 1;
18494 +#ifdef CONFIG_VM86
18495 + if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
18496 + return 1;
18497 +#endif
18498 + if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
18499 return 1;
18500 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
18501 return 0;
18502 @@ -382,6 +384,86 @@ void free_init_pages(char *what, unsigne
18503
18504 void free_initmem(void)
18505 {
18506 +
18507 +#ifdef CONFIG_PAX_KERNEXEC
18508 +#ifdef CONFIG_X86_32
18509 + /* PaX: limit KERNEL_CS to actual size */
18510 + unsigned long addr, limit;
18511 + struct desc_struct d;
18512 + int cpu;
18513 +
18514 + limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
18515 + limit = (limit - 1UL) >> PAGE_SHIFT;
18516 +
18517 + memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
18518 + for (cpu = 0; cpu < NR_CPUS; cpu++) {
18519 + pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
18520 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
18521 + }
18522 +
18523 + /* PaX: make KERNEL_CS read-only */
18524 + addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
18525 + if (!paravirt_enabled())
18526 + set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
18527 +/*
18528 + for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
18529 + pgd = pgd_offset_k(addr);
18530 + pud = pud_offset(pgd, addr);
18531 + pmd = pmd_offset(pud, addr);
18532 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
18533 + }
18534 +*/
18535 +#ifdef CONFIG_X86_PAE
18536 + set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
18537 +/*
18538 + for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
18539 + pgd = pgd_offset_k(addr);
18540 + pud = pud_offset(pgd, addr);
18541 + pmd = pmd_offset(pud, addr);
18542 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
18543 + }
18544 +*/
18545 +#endif
18546 +
18547 +#ifdef CONFIG_MODULES
18548 + set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
18549 +#endif
18550 +
18551 +#else
18552 + pgd_t *pgd;
18553 + pud_t *pud;
18554 + pmd_t *pmd;
18555 + unsigned long addr, end;
18556 +
18557 + /* PaX: make kernel code/rodata read-only, rest non-executable */
18558 + for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
18559 + pgd = pgd_offset_k(addr);
18560 + pud = pud_offset(pgd, addr);
18561 + pmd = pmd_offset(pud, addr);
18562 + if (!pmd_present(*pmd))
18563 + continue;
18564 + if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
18565 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
18566 + else
18567 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
18568 + }
18569 +
18570 + addr = (unsigned long)__va(__pa(__START_KERNEL_map));
18571 + end = addr + KERNEL_IMAGE_SIZE;
18572 + for (; addr < end; addr += PMD_SIZE) {
18573 + pgd = pgd_offset_k(addr);
18574 + pud = pud_offset(pgd, addr);
18575 + pmd = pmd_offset(pud, addr);
18576 + if (!pmd_present(*pmd))
18577 + continue;
18578 + if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
18579 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
18580 + }
18581 +#endif
18582 +
18583 + flush_tlb_all();
18584 +#endif
18585 +
18586 free_init_pages("unused kernel memory",
18587 (unsigned long)(&__init_begin),
18588 (unsigned long)(&__init_end));
18589 diff -urNp linux-2.6.37/arch/x86/mm/iomap_32.c linux-2.6.37/arch/x86/mm/iomap_32.c
18590 --- linux-2.6.37/arch/x86/mm/iomap_32.c 2011-01-04 19:50:19.000000000 -0500
18591 +++ linux-2.6.37/arch/x86/mm/iomap_32.c 2011-01-17 02:41:01.000000000 -0500
18592 @@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long
18593 type = kmap_atomic_idx_push();
18594 idx = type + KM_TYPE_NR * smp_processor_id();
18595 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
18596 +
18597 + pax_open_kernel();
18598 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
18599 + pax_close_kernel();
18600 +
18601 arch_flush_lazy_mmu_mode();
18602
18603 return (void *)vaddr;
18604 diff -urNp linux-2.6.37/arch/x86/mm/ioremap.c linux-2.6.37/arch/x86/mm/ioremap.c
18605 --- linux-2.6.37/arch/x86/mm/ioremap.c 2011-01-04 19:50:19.000000000 -0500
18606 +++ linux-2.6.37/arch/x86/mm/ioremap.c 2011-01-17 02:41:01.000000000 -0500
18607 @@ -104,7 +104,7 @@ static void __iomem *__ioremap_caller(re
18608 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
18609 int is_ram = page_is_ram(pfn);
18610
18611 - if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
18612 + if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
18613 return NULL;
18614 WARN_ON_ONCE(is_ram);
18615 }
18616 @@ -344,7 +344,7 @@ static int __init early_ioremap_debug_se
18617 early_param("early_ioremap_debug", early_ioremap_debug_setup);
18618
18619 static __initdata int after_paging_init;
18620 -static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
18621 +static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
18622
18623 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
18624 {
18625 @@ -381,8 +381,7 @@ void __init early_ioremap_init(void)
18626 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
18627
18628 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
18629 - memset(bm_pte, 0, sizeof(bm_pte));
18630 - pmd_populate_kernel(&init_mm, pmd, bm_pte);
18631 + pmd_populate_user(&init_mm, pmd, bm_pte);
18632
18633 /*
18634 * The boot-ioremap range spans multiple pmds, for which
18635 diff -urNp linux-2.6.37/arch/x86/mm/kmemcheck/kmemcheck.c linux-2.6.37/arch/x86/mm/kmemcheck/kmemcheck.c
18636 --- linux-2.6.37/arch/x86/mm/kmemcheck/kmemcheck.c 2011-01-04 19:50:19.000000000 -0500
18637 +++ linux-2.6.37/arch/x86/mm/kmemcheck/kmemcheck.c 2011-01-17 02:41:01.000000000 -0500
18638 @@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *reg
18639 * memory (e.g. tracked pages)? For now, we need this to avoid
18640 * invoking kmemcheck for PnP BIOS calls.
18641 */
18642 - if (regs->flags & X86_VM_MASK)
18643 + if (v8086_mode(regs))
18644 return false;
18645 - if (regs->cs != __KERNEL_CS)
18646 + if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
18647 return false;
18648
18649 pte = kmemcheck_pte_lookup(address);
18650 diff -urNp linux-2.6.37/arch/x86/mm/mmap.c linux-2.6.37/arch/x86/mm/mmap.c
18651 --- linux-2.6.37/arch/x86/mm/mmap.c 2011-01-04 19:50:19.000000000 -0500
18652 +++ linux-2.6.37/arch/x86/mm/mmap.c 2011-01-17 02:41:01.000000000 -0500
18653 @@ -49,7 +49,7 @@ static unsigned int stack_maxrandom_size
18654 * Leave an at least ~128 MB hole with possible stack randomization.
18655 */
18656 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
18657 -#define MAX_GAP (TASK_SIZE/6*5)
18658 +#define MAX_GAP (pax_task_size/6*5)
18659
18660 /*
18661 * True on X86_32 or when emulating IA32 on X86_64
18662 @@ -94,27 +94,40 @@ static unsigned long mmap_rnd(void)
18663 return rnd << PAGE_SHIFT;
18664 }
18665
18666 -static unsigned long mmap_base(void)
18667 +static unsigned long mmap_base(struct mm_struct *mm)
18668 {
18669 unsigned long gap = rlimit(RLIMIT_STACK);
18670 + unsigned long pax_task_size = TASK_SIZE;
18671 +
18672 +#ifdef CONFIG_PAX_SEGMEXEC
18673 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
18674 + pax_task_size = SEGMEXEC_TASK_SIZE;
18675 +#endif
18676
18677 if (gap < MIN_GAP)
18678 gap = MIN_GAP;
18679 else if (gap > MAX_GAP)
18680 gap = MAX_GAP;
18681
18682 - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
18683 + return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
18684 }
18685
18686 /*
18687 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
18688 * does, but not when emulating X86_32
18689 */
18690 -static unsigned long mmap_legacy_base(void)
18691 +static unsigned long mmap_legacy_base(struct mm_struct *mm)
18692 {
18693 - if (mmap_is_ia32())
18694 + if (mmap_is_ia32()) {
18695 +
18696 +#ifdef CONFIG_PAX_SEGMEXEC
18697 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
18698 + return SEGMEXEC_TASK_UNMAPPED_BASE;
18699 + else
18700 +#endif
18701 +
18702 return TASK_UNMAPPED_BASE;
18703 - else
18704 + } else
18705 return TASK_UNMAPPED_BASE + mmap_rnd();
18706 }
18707
18708 @@ -125,11 +138,23 @@ static unsigned long mmap_legacy_base(vo
18709 void arch_pick_mmap_layout(struct mm_struct *mm)
18710 {
18711 if (mmap_is_legacy()) {
18712 - mm->mmap_base = mmap_legacy_base();
18713 + mm->mmap_base = mmap_legacy_base(mm);
18714 +
18715 +#ifdef CONFIG_PAX_RANDMMAP
18716 + if (mm->pax_flags & MF_PAX_RANDMMAP)
18717 + mm->mmap_base += mm->delta_mmap;
18718 +#endif
18719 +
18720 mm->get_unmapped_area = arch_get_unmapped_area;
18721 mm->unmap_area = arch_unmap_area;
18722 } else {
18723 - mm->mmap_base = mmap_base();
18724 + mm->mmap_base = mmap_base(mm);
18725 +
18726 +#ifdef CONFIG_PAX_RANDMMAP
18727 + if (mm->pax_flags & MF_PAX_RANDMMAP)
18728 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
18729 +#endif
18730 +
18731 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
18732 mm->unmap_area = arch_unmap_area_topdown;
18733 }
18734 diff -urNp linux-2.6.37/arch/x86/mm/numa_32.c linux-2.6.37/arch/x86/mm/numa_32.c
18735 --- linux-2.6.37/arch/x86/mm/numa_32.c 2011-01-04 19:50:19.000000000 -0500
18736 +++ linux-2.6.37/arch/x86/mm/numa_32.c 2011-01-17 02:41:01.000000000 -0500
18737 @@ -99,7 +99,6 @@ unsigned long node_memmap_size_bytes(int
18738 }
18739 #endif
18740
18741 -extern unsigned long find_max_low_pfn(void);
18742 extern unsigned long highend_pfn, highstart_pfn;
18743
18744 #define LARGE_PAGE_BYTES (PTRS_PER_PTE * PAGE_SIZE)
18745 diff -urNp linux-2.6.37/arch/x86/mm/pageattr.c linux-2.6.37/arch/x86/mm/pageattr.c
18746 --- linux-2.6.37/arch/x86/mm/pageattr.c 2011-01-04 19:50:19.000000000 -0500
18747 +++ linux-2.6.37/arch/x86/mm/pageattr.c 2011-01-17 02:41:01.000000000 -0500
18748 @@ -261,16 +261,17 @@ static inline pgprot_t static_protection
18749 * PCI BIOS based config access (CONFIG_PCI_GOBIOS) support.
18750 */
18751 if (within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
18752 - pgprot_val(forbidden) |= _PAGE_NX;
18753 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
18754
18755 /*
18756 * The kernel text needs to be executable for obvious reasons
18757 * Does not cover __inittext since that is gone later on. On
18758 * 64bit we do not enforce !NX on the low mapping
18759 */
18760 - if (within(address, (unsigned long)_text, (unsigned long)_etext))
18761 - pgprot_val(forbidden) |= _PAGE_NX;
18762 + if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
18763 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
18764
18765 +#ifdef CONFIG_DEBUG_RODATA
18766 /*
18767 * The .rodata section needs to be read-only. Using the pfn
18768 * catches all aliases.
18769 @@ -278,6 +279,7 @@ static inline pgprot_t static_protection
18770 if (within(pfn, __pa((unsigned long)__start_rodata) >> PAGE_SHIFT,
18771 __pa((unsigned long)__end_rodata) >> PAGE_SHIFT))
18772 pgprot_val(forbidden) |= _PAGE_RW;
18773 +#endif
18774
18775 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
18776 /*
18777 @@ -316,6 +318,13 @@ static inline pgprot_t static_protection
18778 }
18779 #endif
18780
18781 +#ifdef CONFIG_PAX_KERNEXEC
18782 + if (within(pfn, __pa((unsigned long)&_text), __pa((unsigned long)&_sdata))) {
18783 + pgprot_val(forbidden) |= _PAGE_RW;
18784 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
18785 + }
18786 +#endif
18787 +
18788 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
18789
18790 return prot;
18791 @@ -368,23 +377,37 @@ EXPORT_SYMBOL_GPL(lookup_address);
18792 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
18793 {
18794 /* change init_mm */
18795 + pax_open_kernel();
18796 set_pte_atomic(kpte, pte);
18797 +
18798 #ifdef CONFIG_X86_32
18799 if (!SHARED_KERNEL_PMD) {
18800 +
18801 +#ifdef CONFIG_PAX_PER_CPU_PGD
18802 + unsigned long cpu;
18803 +#else
18804 struct page *page;
18805 +#endif
18806
18807 +#ifdef CONFIG_PAX_PER_CPU_PGD
18808 + for (cpu = 0; cpu < NR_CPUS; ++cpu) {
18809 + pgd_t *pgd = get_cpu_pgd(cpu);
18810 +#else
18811 list_for_each_entry(page, &pgd_list, lru) {
18812 - pgd_t *pgd;
18813 + pgd_t *pgd = (pgd_t *)page_address(page);
18814 +#endif
18815 +
18816 pud_t *pud;
18817 pmd_t *pmd;
18818
18819 - pgd = (pgd_t *)page_address(page) + pgd_index(address);
18820 + pgd += pgd_index(address);
18821 pud = pud_offset(pgd, address);
18822 pmd = pmd_offset(pud, address);
18823 set_pte_atomic((pte_t *)pmd, pte);
18824 }
18825 }
18826 #endif
18827 + pax_close_kernel();
18828 }
18829
18830 static int
18831 diff -urNp linux-2.6.37/arch/x86/mm/pageattr-test.c linux-2.6.37/arch/x86/mm/pageattr-test.c
18832 --- linux-2.6.37/arch/x86/mm/pageattr-test.c 2011-01-04 19:50:19.000000000 -0500
18833 +++ linux-2.6.37/arch/x86/mm/pageattr-test.c 2011-01-17 02:41:01.000000000 -0500
18834 @@ -36,7 +36,7 @@ enum {
18835
18836 static int pte_testbit(pte_t pte)
18837 {
18838 - return pte_flags(pte) & _PAGE_UNUSED1;
18839 + return pte_flags(pte) & _PAGE_CPA_TEST;
18840 }
18841
18842 struct split_state {
18843 diff -urNp linux-2.6.37/arch/x86/mm/pat.c linux-2.6.37/arch/x86/mm/pat.c
18844 --- linux-2.6.37/arch/x86/mm/pat.c 2011-01-04 19:50:19.000000000 -0500
18845 +++ linux-2.6.37/arch/x86/mm/pat.c 2011-01-17 02:41:01.000000000 -0500
18846 @@ -361,7 +361,7 @@ int free_memtype(u64 start, u64 end)
18847
18848 if (!entry) {
18849 printk(KERN_INFO "%s:%d freeing invalid memtype %Lx-%Lx\n",
18850 - current->comm, current->pid, start, end);
18851 + current->comm, task_pid_nr(current), start, end);
18852 return -EINVAL;
18853 }
18854
18855 @@ -492,8 +492,8 @@ static inline int range_is_allowed(unsig
18856 while (cursor < to) {
18857 if (!devmem_is_allowed(pfn)) {
18858 printk(KERN_INFO
18859 - "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
18860 - current->comm, from, to);
18861 + "Program %s tried to access /dev/mem between %Lx->%Lx (%Lx).\n",
18862 + current->comm, from, to, cursor);
18863 return 0;
18864 }
18865 cursor += PAGE_SIZE;
18866 @@ -557,7 +557,7 @@ int kernel_map_sync_memtype(u64 base, un
18867 printk(KERN_INFO
18868 "%s:%d ioremap_change_attr failed %s "
18869 "for %Lx-%Lx\n",
18870 - current->comm, current->pid,
18871 + current->comm, task_pid_nr(current),
18872 cattr_name(flags),
18873 base, (unsigned long long)(base + size));
18874 return -EINVAL;
18875 @@ -593,7 +593,7 @@ static int reserve_pfn_range(u64 paddr,
18876 if (want_flags != flags) {
18877 printk(KERN_WARNING
18878 "%s:%d map pfn RAM range req %s 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 @@ -615,7 +615,7 @@ static int reserve_pfn_range(u64 paddr,
18885 free_memtype(paddr, paddr + size);
18886 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
18887 " for %Lx-%Lx, got %s\n",
18888 - current->comm, current->pid,
18889 + current->comm, task_pid_nr(current),
18890 cattr_name(want_flags),
18891 (unsigned long long)paddr,
18892 (unsigned long long)(paddr + size),
18893 diff -urNp linux-2.6.37/arch/x86/mm/pgtable_32.c linux-2.6.37/arch/x86/mm/pgtable_32.c
18894 --- linux-2.6.37/arch/x86/mm/pgtable_32.c 2011-01-04 19:50:19.000000000 -0500
18895 +++ linux-2.6.37/arch/x86/mm/pgtable_32.c 2011-01-17 02:41:01.000000000 -0500
18896 @@ -48,10 +48,13 @@ void set_pte_vaddr(unsigned long vaddr,
18897 return;
18898 }
18899 pte = pte_offset_kernel(pmd, vaddr);
18900 +
18901 + pax_open_kernel();
18902 if (pte_val(pteval))
18903 set_pte_at(&init_mm, vaddr, pte, pteval);
18904 else
18905 pte_clear(&init_mm, vaddr, pte);
18906 + pax_close_kernel();
18907
18908 /*
18909 * It's enough to flush this one mapping.
18910 diff -urNp linux-2.6.37/arch/x86/mm/pgtable.c linux-2.6.37/arch/x86/mm/pgtable.c
18911 --- linux-2.6.37/arch/x86/mm/pgtable.c 2011-01-04 19:50:19.000000000 -0500
18912 +++ linux-2.6.37/arch/x86/mm/pgtable.c 2011-01-17 02:41:01.000000000 -0500
18913 @@ -84,9 +84,58 @@ static inline void pgd_list_del(pgd_t *p
18914 list_del(&page->lru);
18915 }
18916
18917 -#define UNSHARED_PTRS_PER_PGD \
18918 - (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
18919 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18920 +pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
18921
18922 +void __shadow_user_pgds(pgd_t *dst, const pgd_t *src, int count)
18923 +{
18924 + while (count--)
18925 + *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
18926 +}
18927 +#endif
18928 +
18929 +#ifdef CONFIG_PAX_PER_CPU_PGD
18930 +void __clone_user_pgds(pgd_t *dst, const pgd_t *src, int count)
18931 +{
18932 + while (count--)
18933 +
18934 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18935 + *dst++ = __pgd(pgd_val(*src++) & clone_pgd_mask);
18936 +#else
18937 + *dst++ = *src++;
18938 +#endif
18939 +
18940 +}
18941 +#endif
18942 +
18943 +#ifdef CONFIG_PAX_PER_CPU_PGD
18944 +static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
18945 +static inline void pgd_dtor(pgd_t *pgd) {}
18946 +#ifdef CONFIG_X86_64
18947 +#define pxd_t pud_t
18948 +#define pyd_t pgd_t
18949 +#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
18950 +#define pxd_free(mm, pud) pud_free((mm), (pud))
18951 +#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
18952 +#define pyd_offset(mm ,address) pgd_offset((mm), (address))
18953 +#define PYD_SIZE PGDIR_SIZE
18954 +#else
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, pud) pmd_free((mm), (pud))
18959 +#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
18960 +#define pyd_offset(mm ,address) pud_offset((mm), (address))
18961 +#define PYD_SIZE PUD_SIZE
18962 +#endif
18963 +#else
18964 +#define pxd_t pmd_t
18965 +#define pyd_t pud_t
18966 +#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
18967 +#define pxd_free(mm, pmd) pmd_free((mm), (pmd))
18968 +#define pyd_populate(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
18969 +#define pyd_offset(mm ,address) pud_offset((mm), (address))
18970 +#define PYD_SIZE PUD_SIZE
18971
18972 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
18973 {
18974 @@ -130,6 +179,7 @@ static void pgd_dtor(pgd_t *pgd)
18975 pgd_list_del(pgd);
18976 spin_unlock_irqrestore(&pgd_lock, flags);
18977 }
18978 +#endif
18979
18980 /*
18981 * List of all pgd's needed for non-PAE so it can invalidate entries
18982 @@ -142,7 +192,7 @@ static void pgd_dtor(pgd_t *pgd)
18983 * -- wli
18984 */
18985
18986 -#ifdef CONFIG_X86_PAE
18987 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
18988 /*
18989 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
18990 * updating the top-level pagetable entries to guarantee the
18991 @@ -154,7 +204,7 @@ static void pgd_dtor(pgd_t *pgd)
18992 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
18993 * and initialize the kernel pmds here.
18994 */
18995 -#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
18996 +#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
18997
18998 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
18999 {
19000 @@ -173,36 +223,38 @@ void pud_populate(struct mm_struct *mm,
19001 if (mm == current->active_mm)
19002 write_cr3(read_cr3());
19003 }
19004 +#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
19005 +#define PREALLOCATED_PXDS USER_PGD_PTRS
19006 #else /* !CONFIG_X86_PAE */
19007
19008 /* No need to prepopulate any pagetable entries in non-PAE modes. */
19009 -#define PREALLOCATED_PMDS 0
19010 +#define PREALLOCATED_PXDS 0
19011
19012 #endif /* CONFIG_X86_PAE */
19013
19014 -static void free_pmds(pmd_t *pmds[])
19015 +static void free_pxds(pxd_t *pxds[])
19016 {
19017 int i;
19018
19019 - for(i = 0; i < PREALLOCATED_PMDS; i++)
19020 - if (pmds[i])
19021 - free_page((unsigned long)pmds[i]);
19022 + for(i = 0; i < PREALLOCATED_PXDS; i++)
19023 + if (pxds[i])
19024 + free_page((unsigned long)pxds[i]);
19025 }
19026
19027 -static int preallocate_pmds(pmd_t *pmds[])
19028 +static int preallocate_pxds(pxd_t *pxds[])
19029 {
19030 int i;
19031 bool failed = false;
19032
19033 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
19034 - pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
19035 - if (pmd == NULL)
19036 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
19037 + pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
19038 + if (pxd == NULL)
19039 failed = true;
19040 - pmds[i] = pmd;
19041 + pxds[i] = pxd;
19042 }
19043
19044 if (failed) {
19045 - free_pmds(pmds);
19046 + free_pxds(pxds);
19047 return -ENOMEM;
19048 }
19049
19050 @@ -215,51 +267,56 @@ static int preallocate_pmds(pmd_t *pmds[
19051 * preallocate which never got a corresponding vma will need to be
19052 * freed manually.
19053 */
19054 -static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
19055 +static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
19056 {
19057 int i;
19058
19059 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
19060 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
19061 pgd_t pgd = pgdp[i];
19062
19063 if (pgd_val(pgd) != 0) {
19064 - pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
19065 + pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
19066
19067 - pgdp[i] = native_make_pgd(0);
19068 + set_pgd(pgdp + i, native_make_pgd(0));
19069
19070 - paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
19071 - pmd_free(mm, pmd);
19072 + paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
19073 + pxd_free(mm, pxd);
19074 }
19075 }
19076 }
19077
19078 -static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
19079 +static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
19080 {
19081 - pud_t *pud;
19082 + pyd_t *pyd;
19083 unsigned long addr;
19084 int i;
19085
19086 - if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
19087 + if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
19088 return;
19089
19090 - pud = pud_offset(pgd, 0);
19091 +#ifdef CONFIG_X86_64
19092 + pyd = pyd_offset(mm, 0L);
19093 +#else
19094 + pyd = pyd_offset(pgd, 0L);
19095 +#endif
19096
19097 - for (addr = i = 0; i < PREALLOCATED_PMDS;
19098 - i++, pud++, addr += PUD_SIZE) {
19099 - pmd_t *pmd = pmds[i];
19100 + for (addr = i = 0; i < PREALLOCATED_PXDS;
19101 + i++, pyd++, addr += PYD_SIZE) {
19102 + pxd_t *pxd = pxds[i];
19103
19104 if (i >= KERNEL_PGD_BOUNDARY)
19105 - memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
19106 - sizeof(pmd_t) * PTRS_PER_PMD);
19107 + memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
19108 + sizeof(pxd_t) * PTRS_PER_PMD);
19109
19110 - pud_populate(mm, pud, pmd);
19111 + pyd_populate(mm, pyd, pxd);
19112 }
19113 }
19114
19115 pgd_t *pgd_alloc(struct mm_struct *mm)
19116 {
19117 pgd_t *pgd;
19118 - pmd_t *pmds[PREALLOCATED_PMDS];
19119 + pxd_t *pxds[PREALLOCATED_PXDS];
19120 +
19121 unsigned long flags;
19122
19123 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
19124 @@ -269,11 +326,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
19125
19126 mm->pgd = pgd;
19127
19128 - if (preallocate_pmds(pmds) != 0)
19129 + if (preallocate_pxds(pxds) != 0)
19130 goto out_free_pgd;
19131
19132 if (paravirt_pgd_alloc(mm) != 0)
19133 - goto out_free_pmds;
19134 + goto out_free_pxds;
19135
19136 /*
19137 * Make sure that pre-populating the pmds is atomic with
19138 @@ -283,14 +340,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
19139 spin_lock_irqsave(&pgd_lock, flags);
19140
19141 pgd_ctor(mm, pgd);
19142 - pgd_prepopulate_pmd(mm, pgd, pmds);
19143 + pgd_prepopulate_pxd(mm, pgd, pxds);
19144
19145 spin_unlock_irqrestore(&pgd_lock, flags);
19146
19147 return pgd;
19148
19149 -out_free_pmds:
19150 - free_pmds(pmds);
19151 +out_free_pxds:
19152 + free_pxds(pxds);
19153 out_free_pgd:
19154 free_page((unsigned long)pgd);
19155 out:
19156 @@ -299,7 +356,7 @@ out:
19157
19158 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
19159 {
19160 - pgd_mop_up_pmds(mm, pgd);
19161 + pgd_mop_up_pxds(mm, pgd);
19162 pgd_dtor(pgd);
19163 paravirt_pgd_free(mm, pgd);
19164 free_page((unsigned long)pgd);
19165 diff -urNp linux-2.6.37/arch/x86/mm/setup_nx.c linux-2.6.37/arch/x86/mm/setup_nx.c
19166 --- linux-2.6.37/arch/x86/mm/setup_nx.c 2011-01-04 19:50:19.000000000 -0500
19167 +++ linux-2.6.37/arch/x86/mm/setup_nx.c 2011-01-17 02:41:01.000000000 -0500
19168 @@ -5,8 +5,10 @@
19169 #include <asm/pgtable.h>
19170 #include <asm/proto.h>
19171
19172 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
19173 static int disable_nx __cpuinitdata;
19174
19175 +#ifndef CONFIG_PAX_PAGEEXEC
19176 /*
19177 * noexec = on|off
19178 *
19179 @@ -28,12 +30,17 @@ static int __init noexec_setup(char *str
19180 return 0;
19181 }
19182 early_param("noexec", noexec_setup);
19183 +#endif
19184 +
19185 +#endif
19186
19187 void __cpuinit x86_configure_nx(void)
19188 {
19189 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
19190 if (cpu_has_nx && !disable_nx)
19191 __supported_pte_mask |= _PAGE_NX;
19192 else
19193 +#endif
19194 __supported_pte_mask &= ~_PAGE_NX;
19195 }
19196
19197 diff -urNp linux-2.6.37/arch/x86/mm/tlb.c linux-2.6.37/arch/x86/mm/tlb.c
19198 --- linux-2.6.37/arch/x86/mm/tlb.c 2011-01-04 19:50:19.000000000 -0500
19199 +++ linux-2.6.37/arch/x86/mm/tlb.c 2011-01-17 02:41:01.000000000 -0500
19200 @@ -14,7 +14,7 @@
19201 #include <asm/uv/uv.h>
19202
19203 DEFINE_PER_CPU_SHARED_ALIGNED(struct tlb_state, cpu_tlbstate)
19204 - = { &init_mm, 0, };
19205 + = { &init_mm, 0 };
19206
19207 /*
19208 * Smarter SMP flushing macros.
19209 @@ -65,7 +65,11 @@ void leave_mm(int cpu)
19210 BUG();
19211 cpumask_clear_cpu(cpu,
19212 mm_cpumask(percpu_read(cpu_tlbstate.active_mm)));
19213 +
19214 +#ifndef CONFIG_PAX_PER_CPU_PGD
19215 load_cr3(swapper_pg_dir);
19216 +#endif
19217 +
19218 }
19219 EXPORT_SYMBOL_GPL(leave_mm);
19220
19221 diff -urNp linux-2.6.37/arch/x86/oprofile/backtrace.c linux-2.6.37/arch/x86/oprofile/backtrace.c
19222 --- linux-2.6.37/arch/x86/oprofile/backtrace.c 2011-01-04 19:50:19.000000000 -0500
19223 +++ linux-2.6.37/arch/x86/oprofile/backtrace.c 2011-01-17 02:41:01.000000000 -0500
19224 @@ -57,7 +57,7 @@ dump_user_backtrace_32(struct stack_fram
19225 struct stack_frame_ia32 *fp;
19226
19227 /* Also check accessibility of one struct frame_head beyond */
19228 - if (!access_ok(VERIFY_READ, head, sizeof(bufhead)))
19229 + if (!__access_ok(VERIFY_READ, head, sizeof(bufhead)))
19230 return NULL;
19231 if (__copy_from_user_inatomic(bufhead, head, sizeof(bufhead)))
19232 return NULL;
19233 @@ -123,7 +123,7 @@ x86_backtrace(struct pt_regs * const reg
19234 {
19235 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
19236
19237 - if (!user_mode_vm(regs)) {
19238 + if (!user_mode(regs)) {
19239 unsigned long stack = kernel_stack_pointer(regs);
19240 if (depth)
19241 dump_trace(NULL, regs, (unsigned long *)stack, 0,
19242 diff -urNp linux-2.6.37/arch/x86/oprofile/op_model_p4.c linux-2.6.37/arch/x86/oprofile/op_model_p4.c
19243 --- linux-2.6.37/arch/x86/oprofile/op_model_p4.c 2011-01-04 19:50:19.000000000 -0500
19244 +++ linux-2.6.37/arch/x86/oprofile/op_model_p4.c 2011-01-17 02:41:01.000000000 -0500
19245 @@ -50,7 +50,7 @@ static inline void setup_num_counters(vo
19246 #endif
19247 }
19248
19249 -static int inline addr_increment(void)
19250 +static inline int addr_increment(void)
19251 {
19252 #ifdef CONFIG_SMP
19253 return smp_num_siblings == 2 ? 2 : 1;
19254 diff -urNp linux-2.6.37/arch/x86/pci/common.c linux-2.6.37/arch/x86/pci/common.c
19255 --- linux-2.6.37/arch/x86/pci/common.c 2011-01-04 19:50:19.000000000 -0500
19256 +++ linux-2.6.37/arch/x86/pci/common.c 2011-01-17 02:41:01.000000000 -0500
19257 @@ -32,8 +32,8 @@ int noioapicreroute = 1;
19258 int pcibios_last_bus = -1;
19259 unsigned long pirq_table_addr;
19260 struct pci_bus *pci_root_bus;
19261 -struct pci_raw_ops *raw_pci_ops;
19262 -struct pci_raw_ops *raw_pci_ext_ops;
19263 +const struct pci_raw_ops *raw_pci_ops;
19264 +const struct pci_raw_ops *raw_pci_ext_ops;
19265
19266 int raw_pci_read(unsigned int domain, unsigned int bus, unsigned int devfn,
19267 int reg, int len, u32 *val)
19268 @@ -382,7 +382,7 @@ static const struct dmi_system_id __devi
19269 DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant DL585 G2"),
19270 },
19271 },
19272 - {}
19273 + { NULL, NULL, {DMI_MATCH(DMI_NONE, {0})}, NULL}
19274 };
19275
19276 void __init dmi_check_pciprobe(void)
19277 diff -urNp linux-2.6.37/arch/x86/pci/direct.c linux-2.6.37/arch/x86/pci/direct.c
19278 --- linux-2.6.37/arch/x86/pci/direct.c 2011-01-04 19:50:19.000000000 -0500
19279 +++ linux-2.6.37/arch/x86/pci/direct.c 2011-01-17 02:41:01.000000000 -0500
19280 @@ -79,7 +79,7 @@ static int pci_conf1_write(unsigned int
19281
19282 #undef PCI_CONF1_ADDRESS
19283
19284 -struct pci_raw_ops pci_direct_conf1 = {
19285 +const struct pci_raw_ops pci_direct_conf1 = {
19286 .read = pci_conf1_read,
19287 .write = pci_conf1_write,
19288 };
19289 @@ -173,7 +173,7 @@ static int pci_conf2_write(unsigned int
19290
19291 #undef PCI_CONF2_ADDRESS
19292
19293 -struct pci_raw_ops pci_direct_conf2 = {
19294 +const struct pci_raw_ops pci_direct_conf2 = {
19295 .read = pci_conf2_read,
19296 .write = pci_conf2_write,
19297 };
19298 @@ -189,7 +189,7 @@ struct pci_raw_ops pci_direct_conf2 = {
19299 * This should be close to trivial, but it isn't, because there are buggy
19300 * chipsets (yes, you guessed it, by Intel and Compaq) that have no class ID.
19301 */
19302 -static int __init pci_sanity_check(struct pci_raw_ops *o)
19303 +static int __init pci_sanity_check(const struct pci_raw_ops *o)
19304 {
19305 u32 x = 0;
19306 int year, devfn;
19307 diff -urNp linux-2.6.37/arch/x86/pci/fixup.c linux-2.6.37/arch/x86/pci/fixup.c
19308 --- linux-2.6.37/arch/x86/pci/fixup.c 2011-01-04 19:50:19.000000000 -0500
19309 +++ linux-2.6.37/arch/x86/pci/fixup.c 2011-01-17 02:41:01.000000000 -0500
19310 @@ -364,7 +364,7 @@ static const struct dmi_system_id __devi
19311 DMI_MATCH(DMI_PRODUCT_NAME, "MS-6702E"),
19312 },
19313 },
19314 - {}
19315 + { NULL, NULL, {DMI_MATCH(DMI_NONE, {0})}, NULL }
19316 };
19317
19318 /*
19319 @@ -435,7 +435,7 @@ static const struct dmi_system_id __devi
19320 DMI_MATCH(DMI_PRODUCT_VERSION, "PSA40U"),
19321 },
19322 },
19323 - { }
19324 + { NULL, NULL, {DMI_MATCH(DMI_NONE, {0})}, NULL }
19325 };
19326
19327 static void __devinit pci_pre_fixup_toshiba_ohci1394(struct pci_dev *dev)
19328 diff -urNp linux-2.6.37/arch/x86/pci/irq.c linux-2.6.37/arch/x86/pci/irq.c
19329 --- linux-2.6.37/arch/x86/pci/irq.c 2011-01-04 19:50:19.000000000 -0500
19330 +++ linux-2.6.37/arch/x86/pci/irq.c 2011-01-17 02:41:01.000000000 -0500
19331 @@ -542,7 +542,7 @@ static __init int intel_router_probe(str
19332 static struct pci_device_id __initdata pirq_440gx[] = {
19333 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443GX_0) },
19334 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443GX_2) },
19335 - { },
19336 + { PCI_DEVICE(0, 0) }
19337 };
19338
19339 /* 440GX has a proprietary PIRQ router -- don't use it */
19340 @@ -1114,7 +1114,7 @@ static struct dmi_system_id __initdata p
19341 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 360"),
19342 },
19343 },
19344 - { }
19345 + { NULL, NULL, {DMI_MATCH(DMI_NONE, {0})}, NULL }
19346 };
19347
19348 void __init pcibios_irq_init(void)
19349 diff -urNp linux-2.6.37/arch/x86/pci/mmconfig_32.c linux-2.6.37/arch/x86/pci/mmconfig_32.c
19350 --- linux-2.6.37/arch/x86/pci/mmconfig_32.c 2011-01-04 19:50:19.000000000 -0500
19351 +++ linux-2.6.37/arch/x86/pci/mmconfig_32.c 2011-01-17 02:41:01.000000000 -0500
19352 @@ -117,7 +117,7 @@ static int pci_mmcfg_write(unsigned int
19353 return 0;
19354 }
19355
19356 -static struct pci_raw_ops pci_mmcfg = {
19357 +static const struct pci_raw_ops pci_mmcfg = {
19358 .read = pci_mmcfg_read,
19359 .write = pci_mmcfg_write,
19360 };
19361 diff -urNp linux-2.6.37/arch/x86/pci/mmconfig_64.c linux-2.6.37/arch/x86/pci/mmconfig_64.c
19362 --- linux-2.6.37/arch/x86/pci/mmconfig_64.c 2011-01-04 19:50:19.000000000 -0500
19363 +++ linux-2.6.37/arch/x86/pci/mmconfig_64.c 2011-01-17 02:41:01.000000000 -0500
19364 @@ -81,7 +81,7 @@ static int pci_mmcfg_write(unsigned int
19365 return 0;
19366 }
19367
19368 -static struct pci_raw_ops pci_mmcfg = {
19369 +static const struct pci_raw_ops pci_mmcfg = {
19370 .read = pci_mmcfg_read,
19371 .write = pci_mmcfg_write,
19372 };
19373 diff -urNp linux-2.6.37/arch/x86/pci/numaq_32.c linux-2.6.37/arch/x86/pci/numaq_32.c
19374 --- linux-2.6.37/arch/x86/pci/numaq_32.c 2011-01-04 19:50:19.000000000 -0500
19375 +++ linux-2.6.37/arch/x86/pci/numaq_32.c 2011-01-17 02:41:01.000000000 -0500
19376 @@ -108,7 +108,7 @@ static int pci_conf1_mq_write(unsigned i
19377
19378 #undef PCI_CONF1_MQ_ADDRESS
19379
19380 -static struct pci_raw_ops pci_direct_conf1_mq = {
19381 +static const struct pci_raw_ops pci_direct_conf1_mq = {
19382 .read = pci_conf1_mq_read,
19383 .write = pci_conf1_mq_write
19384 };
19385 diff -urNp linux-2.6.37/arch/x86/pci/olpc.c linux-2.6.37/arch/x86/pci/olpc.c
19386 --- linux-2.6.37/arch/x86/pci/olpc.c 2011-01-04 19:50:19.000000000 -0500
19387 +++ linux-2.6.37/arch/x86/pci/olpc.c 2011-01-17 02:41:01.000000000 -0500
19388 @@ -297,7 +297,7 @@ static int pci_olpc_write(unsigned int s
19389 return 0;
19390 }
19391
19392 -static struct pci_raw_ops pci_olpc_conf = {
19393 +static const struct pci_raw_ops pci_olpc_conf = {
19394 .read = pci_olpc_read,
19395 .write = pci_olpc_write,
19396 };
19397 diff -urNp linux-2.6.37/arch/x86/pci/pcbios.c linux-2.6.37/arch/x86/pci/pcbios.c
19398 --- linux-2.6.37/arch/x86/pci/pcbios.c 2011-01-04 19:50:19.000000000 -0500
19399 +++ linux-2.6.37/arch/x86/pci/pcbios.c 2011-01-17 02:41:01.000000000 -0500
19400 @@ -57,50 +57,93 @@ union bios32 {
19401 static struct {
19402 unsigned long address;
19403 unsigned short segment;
19404 -} bios32_indirect = { 0, __KERNEL_CS };
19405 +} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
19406
19407 /*
19408 * Returns the entry point for the given service, NULL on error
19409 */
19410
19411 -static unsigned long bios32_service(unsigned long service)
19412 +static unsigned long __devinit bios32_service(unsigned long service)
19413 {
19414 unsigned char return_code; /* %al */
19415 unsigned long address; /* %ebx */
19416 unsigned long length; /* %ecx */
19417 unsigned long entry; /* %edx */
19418 unsigned long flags;
19419 + struct desc_struct d, *gdt;
19420
19421 local_irq_save(flags);
19422 - __asm__("lcall *(%%edi); cld"
19423 +
19424 + gdt = get_cpu_gdt_table(smp_processor_id());
19425 +
19426 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
19427 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
19428 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
19429 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
19430 +
19431 + __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
19432 : "=a" (return_code),
19433 "=b" (address),
19434 "=c" (length),
19435 "=d" (entry)
19436 : "0" (service),
19437 "1" (0),
19438 - "D" (&bios32_indirect));
19439 + "D" (&bios32_indirect),
19440 + "r"(__PCIBIOS_DS)
19441 + : "memory");
19442 +
19443 + pax_open_kernel();
19444 + gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
19445 + gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
19446 + gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
19447 + gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
19448 + pax_close_kernel();
19449 +
19450 local_irq_restore(flags);
19451
19452 switch (return_code) {
19453 - case 0:
19454 - return address + entry;
19455 - case 0x80: /* Not present */
19456 - printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
19457 - return 0;
19458 - default: /* Shouldn't happen */
19459 - printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
19460 - service, return_code);
19461 + case 0: {
19462 + int cpu;
19463 + unsigned char flags;
19464 +
19465 + printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
19466 + if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
19467 + printk(KERN_WARNING "bios32_service: not valid\n");
19468 return 0;
19469 + }
19470 + address = address + PAGE_OFFSET;
19471 + length += 16UL; /* some BIOSs underreport this... */
19472 + flags = 4;
19473 + if (length >= 64*1024*1024) {
19474 + length >>= PAGE_SHIFT;
19475 + flags |= 8;
19476 + }
19477 +
19478 + for (cpu = 0; cpu < NR_CPUS; cpu++) {
19479 + gdt = get_cpu_gdt_table(cpu);
19480 + pack_descriptor(&d, address, length, 0x9b, flags);
19481 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
19482 + pack_descriptor(&d, address, length, 0x93, flags);
19483 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
19484 + }
19485 + return entry;
19486 + }
19487 + case 0x80: /* Not present */
19488 + printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
19489 + return 0;
19490 + default: /* Shouldn't happen */
19491 + printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
19492 + service, return_code);
19493 + return 0;
19494 }
19495 }
19496
19497 static struct {
19498 unsigned long address;
19499 unsigned short segment;
19500 -} pci_indirect = { 0, __KERNEL_CS };
19501 +} pci_indirect __read_only = { 0, __PCIBIOS_CS };
19502
19503 -static int pci_bios_present;
19504 +static int pci_bios_present __read_only;
19505
19506 static int __devinit check_pcibios(void)
19507 {
19508 @@ -109,11 +152,13 @@ static int __devinit check_pcibios(void)
19509 unsigned long flags, pcibios_entry;
19510
19511 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
19512 - pci_indirect.address = pcibios_entry + PAGE_OFFSET;
19513 + pci_indirect.address = pcibios_entry;
19514
19515 local_irq_save(flags);
19516 - __asm__(
19517 - "lcall *(%%edi); cld\n\t"
19518 + __asm__("movw %w6, %%ds\n\t"
19519 + "lcall *%%ss:(%%edi); cld\n\t"
19520 + "push %%ss\n\t"
19521 + "pop %%ds\n\t"
19522 "jc 1f\n\t"
19523 "xor %%ah, %%ah\n"
19524 "1:"
19525 @@ -122,7 +167,8 @@ static int __devinit check_pcibios(void)
19526 "=b" (ebx),
19527 "=c" (ecx)
19528 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
19529 - "D" (&pci_indirect)
19530 + "D" (&pci_indirect),
19531 + "r" (__PCIBIOS_DS)
19532 : "memory");
19533 local_irq_restore(flags);
19534
19535 @@ -166,7 +212,10 @@ static int pci_bios_read(unsigned int se
19536
19537 switch (len) {
19538 case 1:
19539 - __asm__("lcall *(%%esi); cld\n\t"
19540 + __asm__("movw %w6, %%ds\n\t"
19541 + "lcall *%%ss:(%%esi); cld\n\t"
19542 + "push %%ss\n\t"
19543 + "pop %%ds\n\t"
19544 "jc 1f\n\t"
19545 "xor %%ah, %%ah\n"
19546 "1:"
19547 @@ -175,7 +224,8 @@ static int pci_bios_read(unsigned int se
19548 : "1" (PCIBIOS_READ_CONFIG_BYTE),
19549 "b" (bx),
19550 "D" ((long)reg),
19551 - "S" (&pci_indirect));
19552 + "S" (&pci_indirect),
19553 + "r" (__PCIBIOS_DS));
19554 /*
19555 * Zero-extend the result beyond 8 bits, do not trust the
19556 * BIOS having done it:
19557 @@ -183,7 +233,10 @@ static int pci_bios_read(unsigned int se
19558 *value &= 0xff;
19559 break;
19560 case 2:
19561 - __asm__("lcall *(%%esi); cld\n\t"
19562 + __asm__("movw %w6, %%ds\n\t"
19563 + "lcall *%%ss:(%%esi); cld\n\t"
19564 + "push %%ss\n\t"
19565 + "pop %%ds\n\t"
19566 "jc 1f\n\t"
19567 "xor %%ah, %%ah\n"
19568 "1:"
19569 @@ -192,7 +245,8 @@ static int pci_bios_read(unsigned int se
19570 : "1" (PCIBIOS_READ_CONFIG_WORD),
19571 "b" (bx),
19572 "D" ((long)reg),
19573 - "S" (&pci_indirect));
19574 + "S" (&pci_indirect),
19575 + "r" (__PCIBIOS_DS));
19576 /*
19577 * Zero-extend the result beyond 16 bits, do not trust the
19578 * BIOS having done it:
19579 @@ -200,7 +254,10 @@ static int pci_bios_read(unsigned int se
19580 *value &= 0xffff;
19581 break;
19582 case 4:
19583 - __asm__("lcall *(%%esi); cld\n\t"
19584 + __asm__("movw %w6, %%ds\n\t"
19585 + "lcall *%%ss:(%%esi); cld\n\t"
19586 + "push %%ss\n\t"
19587 + "pop %%ds\n\t"
19588 "jc 1f\n\t"
19589 "xor %%ah, %%ah\n"
19590 "1:"
19591 @@ -209,7 +266,8 @@ static int pci_bios_read(unsigned int se
19592 : "1" (PCIBIOS_READ_CONFIG_DWORD),
19593 "b" (bx),
19594 "D" ((long)reg),
19595 - "S" (&pci_indirect));
19596 + "S" (&pci_indirect),
19597 + "r" (__PCIBIOS_DS));
19598 break;
19599 }
19600
19601 @@ -232,7 +290,10 @@ static int pci_bios_write(unsigned int s
19602
19603 switch (len) {
19604 case 1:
19605 - __asm__("lcall *(%%esi); cld\n\t"
19606 + __asm__("movw %w6, %%ds\n\t"
19607 + "lcall *%%ss:(%%esi); cld\n\t"
19608 + "push %%ss\n\t"
19609 + "pop %%ds\n\t"
19610 "jc 1f\n\t"
19611 "xor %%ah, %%ah\n"
19612 "1:"
19613 @@ -241,10 +302,14 @@ static int pci_bios_write(unsigned int s
19614 "c" (value),
19615 "b" (bx),
19616 "D" ((long)reg),
19617 - "S" (&pci_indirect));
19618 + "S" (&pci_indirect),
19619 + "r" (__PCIBIOS_DS));
19620 break;
19621 case 2:
19622 - __asm__("lcall *(%%esi); cld\n\t"
19623 + __asm__("movw %w6, %%ds\n\t"
19624 + "lcall *%%ss:(%%esi); cld\n\t"
19625 + "push %%ss\n\t"
19626 + "pop %%ds\n\t"
19627 "jc 1f\n\t"
19628 "xor %%ah, %%ah\n"
19629 "1:"
19630 @@ -253,10 +318,14 @@ static int pci_bios_write(unsigned int s
19631 "c" (value),
19632 "b" (bx),
19633 "D" ((long)reg),
19634 - "S" (&pci_indirect));
19635 + "S" (&pci_indirect),
19636 + "r" (__PCIBIOS_DS));
19637 break;
19638 case 4:
19639 - __asm__("lcall *(%%esi); cld\n\t"
19640 + __asm__("movw %w6, %%ds\n\t"
19641 + "lcall *%%ss:(%%esi); cld\n\t"
19642 + "push %%ss\n\t"
19643 + "pop %%ds\n\t"
19644 "jc 1f\n\t"
19645 "xor %%ah, %%ah\n"
19646 "1:"
19647 @@ -265,7 +334,8 @@ static int pci_bios_write(unsigned int s
19648 "c" (value),
19649 "b" (bx),
19650 "D" ((long)reg),
19651 - "S" (&pci_indirect));
19652 + "S" (&pci_indirect),
19653 + "r" (__PCIBIOS_DS));
19654 break;
19655 }
19656
19657 @@ -279,7 +349,7 @@ static int pci_bios_write(unsigned int s
19658 * Function table for BIOS32 access
19659 */
19660
19661 -static struct pci_raw_ops pci_bios_access = {
19662 +static const struct pci_raw_ops pci_bios_access = {
19663 .read = pci_bios_read,
19664 .write = pci_bios_write
19665 };
19666 @@ -288,7 +358,7 @@ static struct pci_raw_ops pci_bios_acces
19667 * Try to find PCI BIOS.
19668 */
19669
19670 -static struct pci_raw_ops * __devinit pci_find_bios(void)
19671 +static const struct pci_raw_ops * __devinit pci_find_bios(void)
19672 {
19673 union bios32 *check;
19674 unsigned char sum;
19675 @@ -369,10 +439,13 @@ struct irq_routing_table * pcibios_get_i
19676
19677 DBG("PCI: Fetching IRQ routing table... ");
19678 __asm__("push %%es\n\t"
19679 + "movw %w8, %%ds\n\t"
19680 "push %%ds\n\t"
19681 "pop %%es\n\t"
19682 - "lcall *(%%esi); cld\n\t"
19683 + "lcall *%%ss:(%%esi); cld\n\t"
19684 "pop %%es\n\t"
19685 + "push %%ss\n\t"
19686 + "pop %%ds\n"
19687 "jc 1f\n\t"
19688 "xor %%ah, %%ah\n"
19689 "1:"
19690 @@ -383,7 +456,8 @@ struct irq_routing_table * pcibios_get_i
19691 "1" (0),
19692 "D" ((long) &opt),
19693 "S" (&pci_indirect),
19694 - "m" (opt)
19695 + "m" (opt),
19696 + "r" (__PCIBIOS_DS)
19697 : "memory");
19698 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
19699 if (ret & 0xff00)
19700 @@ -407,7 +481,10 @@ int pcibios_set_irq_routing(struct pci_d
19701 {
19702 int ret;
19703
19704 - __asm__("lcall *(%%esi); cld\n\t"
19705 + __asm__("movw %w5, %%ds\n\t"
19706 + "lcall *%%ss:(%%esi); cld\n\t"
19707 + "push %%ss\n\t"
19708 + "pop %%ds\n"
19709 "jc 1f\n\t"
19710 "xor %%ah, %%ah\n"
19711 "1:"
19712 @@ -415,7 +492,8 @@ int pcibios_set_irq_routing(struct pci_d
19713 : "0" (PCIBIOS_SET_PCI_HW_INT),
19714 "b" ((dev->bus->number << 8) | dev->devfn),
19715 "c" ((irq << 8) | (pin + 10)),
19716 - "S" (&pci_indirect));
19717 + "S" (&pci_indirect),
19718 + "r" (__PCIBIOS_DS));
19719 return !(ret & 0xff00);
19720 }
19721 EXPORT_SYMBOL(pcibios_set_irq_routing);
19722 diff -urNp linux-2.6.37/arch/x86/platform/efi/efi_32.c linux-2.6.37/arch/x86/platform/efi/efi_32.c
19723 --- linux-2.6.37/arch/x86/platform/efi/efi_32.c 2011-01-04 19:50:19.000000000 -0500
19724 +++ linux-2.6.37/arch/x86/platform/efi/efi_32.c 2011-01-17 02:41:01.000000000 -0500
19725 @@ -38,70 +38,37 @@
19726 */
19727
19728 static unsigned long efi_rt_eflags;
19729 -static pgd_t efi_bak_pg_dir_pointer[2];
19730 +static pgd_t __initdata efi_bak_pg_dir_pointer[KERNEL_PGD_PTRS];
19731
19732 -void efi_call_phys_prelog(void)
19733 +void __init efi_call_phys_prelog(void)
19734 {
19735 - unsigned long cr4;
19736 - unsigned long temp;
19737 struct desc_ptr gdt_descr;
19738
19739 local_irq_save(efi_rt_eflags);
19740
19741 - /*
19742 - * If I don't have PAE, I should just duplicate two entries in page
19743 - * directory. If I have PAE, I just need to duplicate one entry in
19744 - * page directory.
19745 - */
19746 - cr4 = read_cr4_safe();
19747 -
19748 - if (cr4 & X86_CR4_PAE) {
19749 - efi_bak_pg_dir_pointer[0].pgd =
19750 - swapper_pg_dir[pgd_index(0)].pgd;
19751 - swapper_pg_dir[0].pgd =
19752 - swapper_pg_dir[pgd_index(PAGE_OFFSET)].pgd;
19753 - } else {
19754 - efi_bak_pg_dir_pointer[0].pgd =
19755 - swapper_pg_dir[pgd_index(0)].pgd;
19756 - efi_bak_pg_dir_pointer[1].pgd =
19757 - swapper_pg_dir[pgd_index(0x400000)].pgd;
19758 - swapper_pg_dir[pgd_index(0)].pgd =
19759 - swapper_pg_dir[pgd_index(PAGE_OFFSET)].pgd;
19760 - temp = PAGE_OFFSET + 0x400000;
19761 - swapper_pg_dir[pgd_index(0x400000)].pgd =
19762 - swapper_pg_dir[pgd_index(temp)].pgd;
19763 - }
19764 + clone_pgd_range(efi_bak_pg_dir_pointer, swapper_pg_dir, KERNEL_PGD_PTRS);
19765 + clone_pgd_range(swapper_pg_dir, swapper_pg_dir + KERNEL_PGD_BOUNDARY,
19766 + min_t(unsigned long, KERNEL_PGD_PTRS, KERNEL_PGD_BOUNDARY));
19767
19768 /*
19769 * After the lock is released, the original page table is restored.
19770 */
19771 __flush_tlb_all();
19772
19773 - gdt_descr.address = __pa(get_cpu_gdt_table(0));
19774 + gdt_descr.address = (struct desc_struct *)__pa(get_cpu_gdt_table(0));
19775 gdt_descr.size = GDT_SIZE - 1;
19776 load_gdt(&gdt_descr);
19777 }
19778
19779 -void efi_call_phys_epilog(void)
19780 +void __init efi_call_phys_epilog(void)
19781 {
19782 - unsigned long cr4;
19783 struct desc_ptr gdt_descr;
19784
19785 - gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
19786 + gdt_descr.address = get_cpu_gdt_table(0);
19787 gdt_descr.size = GDT_SIZE - 1;
19788 load_gdt(&gdt_descr);
19789
19790 - cr4 = read_cr4_safe();
19791 -
19792 - if (cr4 & X86_CR4_PAE) {
19793 - swapper_pg_dir[pgd_index(0)].pgd =
19794 - efi_bak_pg_dir_pointer[0].pgd;
19795 - } else {
19796 - swapper_pg_dir[pgd_index(0)].pgd =
19797 - efi_bak_pg_dir_pointer[0].pgd;
19798 - swapper_pg_dir[pgd_index(0x400000)].pgd =
19799 - efi_bak_pg_dir_pointer[1].pgd;
19800 - }
19801 + clone_pgd_range(swapper_pg_dir, efi_bak_pg_dir_pointer, KERNEL_PGD_PTRS);
19802
19803 /*
19804 * After the lock is released, the original page table is restored.
19805 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
19806 --- linux-2.6.37/arch/x86/platform/efi/efi_stub_32.S 2011-01-04 19:50:19.000000000 -0500
19807 +++ linux-2.6.37/arch/x86/platform/efi/efi_stub_32.S 2011-01-17 02:41:01.000000000 -0500
19808 @@ -6,6 +6,7 @@
19809 */
19810
19811 #include <linux/linkage.h>
19812 +#include <linux/init.h>
19813 #include <asm/page_types.h>
19814
19815 /*
19816 @@ -20,7 +21,7 @@
19817 * service functions will comply with gcc calling convention, too.
19818 */
19819
19820 -.text
19821 +__INIT
19822 ENTRY(efi_call_phys)
19823 /*
19824 * 0. The function can only be called in Linux kernel. So CS has been
19825 @@ -36,9 +37,7 @@ ENTRY(efi_call_phys)
19826 * The mapping of lower virtual memory has been created in prelog and
19827 * epilog.
19828 */
19829 - movl $1f, %edx
19830 - subl $__PAGE_OFFSET, %edx
19831 - jmp *%edx
19832 + jmp 1f-__PAGE_OFFSET
19833 1:
19834
19835 /*
19836 @@ -47,14 +46,8 @@ ENTRY(efi_call_phys)
19837 * parameter 2, ..., param n. To make things easy, we save the return
19838 * address of efi_call_phys in a global variable.
19839 */
19840 - popl %edx
19841 - movl %edx, saved_return_addr
19842 - /* get the function pointer into ECX*/
19843 - popl %ecx
19844 - movl %ecx, efi_rt_function_ptr
19845 - movl $2f, %edx
19846 - subl $__PAGE_OFFSET, %edx
19847 - pushl %edx
19848 + popl (saved_return_addr)
19849 + popl (efi_rt_function_ptr)
19850
19851 /*
19852 * 3. Clear PG bit in %CR0.
19853 @@ -73,9 +66,8 @@ ENTRY(efi_call_phys)
19854 /*
19855 * 5. Call the physical function.
19856 */
19857 - jmp *%ecx
19858 + call *(efi_rt_function_ptr-__PAGE_OFFSET)
19859
19860 -2:
19861 /*
19862 * 6. After EFI runtime service returns, control will return to
19863 * following instruction. We'd better readjust stack pointer first.
19864 @@ -88,35 +80,28 @@ ENTRY(efi_call_phys)
19865 movl %cr0, %edx
19866 orl $0x80000000, %edx
19867 movl %edx, %cr0
19868 - jmp 1f
19869 -1:
19870 +
19871 /*
19872 * 8. Now restore the virtual mode from flat mode by
19873 * adding EIP with PAGE_OFFSET.
19874 */
19875 - movl $1f, %edx
19876 - jmp *%edx
19877 + jmp 1f+__PAGE_OFFSET
19878 1:
19879
19880 /*
19881 * 9. Balance the stack. And because EAX contain the return value,
19882 * we'd better not clobber it.
19883 */
19884 - leal efi_rt_function_ptr, %edx
19885 - movl (%edx), %ecx
19886 - pushl %ecx
19887 + pushl (efi_rt_function_ptr)
19888
19889 /*
19890 - * 10. Push the saved return address onto the stack and return.
19891 + * 10. Return to the saved return address.
19892 */
19893 - leal saved_return_addr, %edx
19894 - movl (%edx), %ecx
19895 - pushl %ecx
19896 - ret
19897 + jmpl *(saved_return_addr)
19898 ENDPROC(efi_call_phys)
19899 .previous
19900
19901 -.data
19902 +__INITDATA
19903 saved_return_addr:
19904 .long 0
19905 efi_rt_function_ptr:
19906 diff -urNp linux-2.6.37/arch/x86/power/cpu.c linux-2.6.37/arch/x86/power/cpu.c
19907 --- linux-2.6.37/arch/x86/power/cpu.c 2011-01-04 19:50:19.000000000 -0500
19908 +++ linux-2.6.37/arch/x86/power/cpu.c 2011-01-17 02:41:01.000000000 -0500
19909 @@ -130,7 +130,7 @@ static void do_fpu_end(void)
19910 static void fix_processor_context(void)
19911 {
19912 int cpu = smp_processor_id();
19913 - struct tss_struct *t = &per_cpu(init_tss, cpu);
19914 + struct tss_struct *t = init_tss + cpu;
19915
19916 set_tss_desc(cpu, t); /*
19917 * This just modifies memory; should not be
19918 @@ -140,7 +140,9 @@ static void fix_processor_context(void)
19919 */
19920
19921 #ifdef CONFIG_X86_64
19922 + pax_open_kernel();
19923 get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
19924 + pax_close_kernel();
19925
19926 syscall_init(); /* This sets MSR_*STAR and related */
19927 #endif
19928 diff -urNp linux-2.6.37/arch/x86/vdso/Makefile linux-2.6.37/arch/x86/vdso/Makefile
19929 --- linux-2.6.37/arch/x86/vdso/Makefile 2011-01-04 19:50:19.000000000 -0500
19930 +++ linux-2.6.37/arch/x86/vdso/Makefile 2011-01-17 02:41:01.000000000 -0500
19931 @@ -123,7 +123,7 @@ quiet_cmd_vdso = VDSO $@
19932 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
19933 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
19934
19935 -VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
19936 +VDSO_LDFLAGS = -fPIC -shared --no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
19937 GCOV_PROFILE := n
19938
19939 #
19940 diff -urNp linux-2.6.37/arch/x86/vdso/vclock_gettime.c linux-2.6.37/arch/x86/vdso/vclock_gettime.c
19941 --- linux-2.6.37/arch/x86/vdso/vclock_gettime.c 2011-01-04 19:50:19.000000000 -0500
19942 +++ linux-2.6.37/arch/x86/vdso/vclock_gettime.c 2011-01-17 02:41:01.000000000 -0500
19943 @@ -22,24 +22,48 @@
19944 #include <asm/hpet.h>
19945 #include <asm/unistd.h>
19946 #include <asm/io.h>
19947 +#include <asm/fixmap.h>
19948 #include "vextern.h"
19949
19950 #define gtod vdso_vsyscall_gtod_data
19951
19952 +notrace noinline long __vdso_fallback_time(long *t)
19953 +{
19954 + long secs;
19955 + asm volatile("syscall"
19956 + : "=a" (secs)
19957 + : "0" (__NR_time),"D" (t) : "r11", "cx", "memory");
19958 + return secs;
19959 +}
19960 +
19961 notrace static long vdso_fallback_gettime(long clock, struct timespec *ts)
19962 {
19963 long ret;
19964 asm("syscall" : "=a" (ret) :
19965 - "0" (__NR_clock_gettime),"D" (clock), "S" (ts) : "memory");
19966 + "0" (__NR_clock_gettime),"D" (clock), "S" (ts) : "r11", "cx", "memory");
19967 return ret;
19968 }
19969
19970 +notrace static inline cycle_t __vdso_vread_hpet(void)
19971 +{
19972 + return readl((const void __iomem *)fix_to_virt(VSYSCALL_HPET) + 0xf0);
19973 +}
19974 +
19975 +notrace static inline cycle_t __vdso_vread_tsc(void)
19976 +{
19977 + cycle_t ret = (cycle_t)vget_cycles();
19978 +
19979 + return ret >= gtod->clock.cycle_last ? ret : gtod->clock.cycle_last;
19980 +}
19981 +
19982 notrace static inline long vgetns(void)
19983 {
19984 long v;
19985 - cycles_t (*vread)(void);
19986 - vread = gtod->clock.vread;
19987 - v = (vread() - gtod->clock.cycle_last) & gtod->clock.mask;
19988 + if (gtod->clock.name[0] == 't' && gtod->clock.name[1] == 's' && gtod->clock.name[2] == 'c' && !gtod->clock.name[3])
19989 + v = __vdso_vread_tsc();
19990 + else
19991 + v = __vdso_vread_hpet();
19992 + v = (v - gtod->clock.cycle_last) & gtod->clock.mask;
19993 return (v * gtod->clock.mult) >> gtod->clock.shift;
19994 }
19995
19996 @@ -113,7 +137,9 @@ notrace static noinline int do_monotonic
19997
19998 notrace int __vdso_clock_gettime(clockid_t clock, struct timespec *ts)
19999 {
20000 - if (likely(gtod->sysctl_enabled))
20001 + if (likely(gtod->sysctl_enabled &&
20002 + ((gtod->clock.name[0] == 'h' && gtod->clock.name[1] == 'p' && gtod->clock.name[2] == 'e' && gtod->clock.name[3] == 't' && !gtod->clock.name[4]) ||
20003 + (gtod->clock.name[0] == 't' && gtod->clock.name[1] == 's' && gtod->clock.name[2] == 'c' && !gtod->clock.name[3]))))
20004 switch (clock) {
20005 case CLOCK_REALTIME:
20006 if (likely(gtod->clock.vread))
20007 @@ -133,10 +159,20 @@ notrace int __vdso_clock_gettime(clockid
20008 int clock_gettime(clockid_t, struct timespec *)
20009 __attribute__((weak, alias("__vdso_clock_gettime")));
20010
20011 -notrace int __vdso_gettimeofday(struct timeval *tv, struct timezone *tz)
20012 +notrace noinline int __vdso_fallback_gettimeofday(struct timeval *tv, struct timezone *tz)
20013 {
20014 long ret;
20015 - if (likely(gtod->sysctl_enabled && gtod->clock.vread)) {
20016 + asm("syscall" : "=a" (ret) :
20017 + "0" (__NR_gettimeofday), "D" (tv), "S" (tz) : "r11", "cx", "memory");
20018 + return ret;
20019 +}
20020 +
20021 +notrace int __vdso_gettimeofday(struct timeval *tv, struct timezone *tz)
20022 +{
20023 + if (likely(gtod->sysctl_enabled &&
20024 + ((gtod->clock.name[0] == 'h' && gtod->clock.name[1] == 'p' && gtod->clock.name[2] == 'e' && gtod->clock.name[3] == 't' && !gtod->clock.name[4]) ||
20025 + (gtod->clock.name[0] == 't' && gtod->clock.name[1] == 's' && gtod->clock.name[2] == 'c' && !gtod->clock.name[3]))))
20026 + {
20027 if (likely(tv != NULL)) {
20028 BUILD_BUG_ON(offsetof(struct timeval, tv_usec) !=
20029 offsetof(struct timespec, tv_nsec) ||
20030 @@ -151,9 +187,7 @@ notrace int __vdso_gettimeofday(struct t
20031 }
20032 return 0;
20033 }
20034 - asm("syscall" : "=a" (ret) :
20035 - "0" (__NR_gettimeofday), "D" (tv), "S" (tz) : "memory");
20036 - return ret;
20037 + return __vdso_fallback_gettimeofday(tv, tz);
20038 }
20039 int gettimeofday(struct timeval *, struct timezone *)
20040 __attribute__((weak, alias("__vdso_gettimeofday")));
20041 diff -urNp linux-2.6.37/arch/x86/vdso/vdso32-setup.c linux-2.6.37/arch/x86/vdso/vdso32-setup.c
20042 --- linux-2.6.37/arch/x86/vdso/vdso32-setup.c 2011-01-04 19:50:19.000000000 -0500
20043 +++ linux-2.6.37/arch/x86/vdso/vdso32-setup.c 2011-01-17 02:41:01.000000000 -0500
20044 @@ -25,6 +25,7 @@
20045 #include <asm/tlbflush.h>
20046 #include <asm/vdso.h>
20047 #include <asm/proto.h>
20048 +#include <asm/mman.h>
20049
20050 enum {
20051 VDSO_DISABLED = 0,
20052 @@ -226,7 +227,7 @@ static inline void map_compat_vdso(int m
20053 void enable_sep_cpu(void)
20054 {
20055 int cpu = get_cpu();
20056 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
20057 + struct tss_struct *tss = init_tss + cpu;
20058
20059 if (!boot_cpu_has(X86_FEATURE_SEP)) {
20060 put_cpu();
20061 @@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
20062 gate_vma.vm_start = FIXADDR_USER_START;
20063 gate_vma.vm_end = FIXADDR_USER_END;
20064 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
20065 - gate_vma.vm_page_prot = __P101;
20066 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
20067 /*
20068 * Make sure the vDSO gets into every core dump.
20069 * Dumping its contents makes post-mortem fully interpretable later
20070 @@ -331,14 +332,14 @@ int arch_setup_additional_pages(struct l
20071 if (compat)
20072 addr = VDSO_HIGH_BASE;
20073 else {
20074 - addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
20075 + addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
20076 if (IS_ERR_VALUE(addr)) {
20077 ret = addr;
20078 goto up_fail;
20079 }
20080 }
20081
20082 - current->mm->context.vdso = (void *)addr;
20083 + current->mm->context.vdso = addr;
20084
20085 if (compat_uses_vma || !compat) {
20086 /*
20087 @@ -361,11 +362,11 @@ int arch_setup_additional_pages(struct l
20088 }
20089
20090 current_thread_info()->sysenter_return =
20091 - VDSO32_SYMBOL(addr, SYSENTER_RETURN);
20092 + (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
20093
20094 up_fail:
20095 if (ret)
20096 - current->mm->context.vdso = NULL;
20097 + current->mm->context.vdso = 0;
20098
20099 up_write(&mm->mmap_sem);
20100
20101 @@ -412,8 +413,14 @@ __initcall(ia32_binfmt_init);
20102
20103 const char *arch_vma_name(struct vm_area_struct *vma)
20104 {
20105 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
20106 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
20107 return "[vdso]";
20108 +
20109 +#ifdef CONFIG_PAX_SEGMEXEC
20110 + if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
20111 + return "[vdso]";
20112 +#endif
20113 +
20114 return NULL;
20115 }
20116
20117 @@ -422,7 +429,7 @@ struct vm_area_struct *get_gate_vma(stru
20118 struct mm_struct *mm = tsk->mm;
20119
20120 /* Check to see if this task was created in compat vdso mode */
20121 - if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
20122 + if (mm && mm->context.vdso == VDSO_HIGH_BASE)
20123 return &gate_vma;
20124 return NULL;
20125 }
20126 diff -urNp linux-2.6.37/arch/x86/vdso/vdso.lds.S linux-2.6.37/arch/x86/vdso/vdso.lds.S
20127 --- linux-2.6.37/arch/x86/vdso/vdso.lds.S 2011-01-04 19:50:19.000000000 -0500
20128 +++ linux-2.6.37/arch/x86/vdso/vdso.lds.S 2011-01-17 02:41:01.000000000 -0500
20129 @@ -35,3 +35,9 @@ VDSO64_PRELINK = VDSO_PRELINK;
20130 #define VEXTERN(x) VDSO64_ ## x = vdso_ ## x;
20131 #include "vextern.h"
20132 #undef VEXTERN
20133 +
20134 +#define VEXTERN(x) VDSO64_ ## x = __vdso_ ## x;
20135 +VEXTERN(fallback_gettimeofday)
20136 +VEXTERN(fallback_time)
20137 +VEXTERN(getcpu)
20138 +#undef VEXTERN
20139 diff -urNp linux-2.6.37/arch/x86/vdso/vextern.h linux-2.6.37/arch/x86/vdso/vextern.h
20140 --- linux-2.6.37/arch/x86/vdso/vextern.h 2011-01-04 19:50:19.000000000 -0500
20141 +++ linux-2.6.37/arch/x86/vdso/vextern.h 2011-01-17 02:41:01.000000000 -0500
20142 @@ -11,6 +11,5 @@
20143 put into vextern.h and be referenced as a pointer with vdso prefix.
20144 The main kernel later fills in the values. */
20145
20146 -VEXTERN(jiffies)
20147 VEXTERN(vgetcpu_mode)
20148 VEXTERN(vsyscall_gtod_data)
20149 diff -urNp linux-2.6.37/arch/x86/vdso/vma.c linux-2.6.37/arch/x86/vdso/vma.c
20150 --- linux-2.6.37/arch/x86/vdso/vma.c 2011-01-04 19:50:19.000000000 -0500
20151 +++ linux-2.6.37/arch/x86/vdso/vma.c 2011-01-17 02:41:01.000000000 -0500
20152 @@ -58,7 +58,7 @@ static int __init init_vdso_vars(void)
20153 if (!vbase)
20154 goto oom;
20155
20156 - if (memcmp(vbase, "\177ELF", 4)) {
20157 + if (memcmp(vbase, ELFMAG, SELFMAG)) {
20158 printk("VDSO: I'm broken; not ELF\n");
20159 vdso_enabled = 0;
20160 }
20161 @@ -118,7 +118,7 @@ int arch_setup_additional_pages(struct l
20162 goto up_fail;
20163 }
20164
20165 - current->mm->context.vdso = (void *)addr;
20166 + current->mm->context.vdso = addr;
20167
20168 ret = install_special_mapping(mm, addr, vdso_size,
20169 VM_READ|VM_EXEC|
20170 @@ -126,7 +126,7 @@ int arch_setup_additional_pages(struct l
20171 VM_ALWAYSDUMP,
20172 vdso_pages);
20173 if (ret) {
20174 - current->mm->context.vdso = NULL;
20175 + current->mm->context.vdso = 0;
20176 goto up_fail;
20177 }
20178
20179 @@ -134,10 +134,3 @@ up_fail:
20180 up_write(&mm->mmap_sem);
20181 return ret;
20182 }
20183 -
20184 -static __init int vdso_setup(char *s)
20185 -{
20186 - vdso_enabled = simple_strtoul(s, NULL, 0);
20187 - return 0;
20188 -}
20189 -__setup("vdso=", vdso_setup);
20190 diff -urNp linux-2.6.37/arch/x86/xen/enlighten.c linux-2.6.37/arch/x86/xen/enlighten.c
20191 --- linux-2.6.37/arch/x86/xen/enlighten.c 2011-01-04 19:50:19.000000000 -0500
20192 +++ linux-2.6.37/arch/x86/xen/enlighten.c 2011-01-17 02:41:01.000000000 -0500
20193 @@ -85,8 +85,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
20194
20195 struct shared_info xen_dummy_shared_info;
20196
20197 -void *xen_initial_gdt;
20198 -
20199 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
20200 __read_mostly int xen_have_vector_callback;
20201 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
20202 @@ -574,7 +572,7 @@ static void xen_write_idt_entry(gate_des
20203
20204 preempt_disable();
20205
20206 - start = __get_cpu_var(idt_desc).address;
20207 + start = (unsigned long)__get_cpu_var(idt_desc).address;
20208 end = start + __get_cpu_var(idt_desc).size + 1;
20209
20210 xen_mc_flush();
20211 @@ -1134,7 +1132,17 @@ asmlinkage void __init xen_start_kernel(
20212 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
20213
20214 /* Work out if we support NX */
20215 - x86_configure_nx();
20216 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
20217 + if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
20218 + (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
20219 + unsigned l, h;
20220 +
20221 + __supported_pte_mask |= _PAGE_NX;
20222 + rdmsr(MSR_EFER, l, h);
20223 + l |= EFER_NX;
20224 + wrmsr(MSR_EFER, l, h);
20225 + }
20226 +#endif
20227
20228 xen_setup_features();
20229
20230 @@ -1165,13 +1173,6 @@ asmlinkage void __init xen_start_kernel(
20231
20232 machine_ops = xen_machine_ops;
20233
20234 - /*
20235 - * The only reliable way to retain the initial address of the
20236 - * percpu gdt_page is to remember it here, so we can go and
20237 - * mark it RW later, when the initial percpu area is freed.
20238 - */
20239 - xen_initial_gdt = &per_cpu(gdt_page, 0);
20240 -
20241 xen_smp_init();
20242
20243 pgd = (pgd_t *)xen_start_info->pt_base;
20244 diff -urNp linux-2.6.37/arch/x86/xen/mmu.c linux-2.6.37/arch/x86/xen/mmu.c
20245 --- linux-2.6.37/arch/x86/xen/mmu.c 2011-01-04 19:50:19.000000000 -0500
20246 +++ linux-2.6.37/arch/x86/xen/mmu.c 2011-01-17 02:41:01.000000000 -0500
20247 @@ -2084,6 +2084,8 @@ __init pgd_t *xen_setup_kernel_pagetable
20248 convert_pfn_mfn(init_level4_pgt);
20249 convert_pfn_mfn(level3_ident_pgt);
20250 convert_pfn_mfn(level3_kernel_pgt);
20251 + convert_pfn_mfn(level3_vmalloc_pgt);
20252 + convert_pfn_mfn(level3_vmemmap_pgt);
20253
20254 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
20255 l2 = m2v(l3[pud_index(__START_KERNEL_map)].pud);
20256 @@ -2102,7 +2104,10 @@ __init pgd_t *xen_setup_kernel_pagetable
20257 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
20258 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
20259 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
20260 + set_page_prot(level3_vmalloc_pgt, PAGE_KERNEL_RO);
20261 + set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
20262 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
20263 + set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
20264 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
20265 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
20266
20267 diff -urNp linux-2.6.37/arch/x86/xen/pci-swiotlb-xen.c linux-2.6.37/arch/x86/xen/pci-swiotlb-xen.c
20268 --- linux-2.6.37/arch/x86/xen/pci-swiotlb-xen.c 2011-01-04 19:50:19.000000000 -0500
20269 +++ linux-2.6.37/arch/x86/xen/pci-swiotlb-xen.c 2011-01-17 02:41:01.000000000 -0500
20270 @@ -10,7 +10,7 @@
20271
20272 int xen_swiotlb __read_mostly;
20273
20274 -static struct dma_map_ops xen_swiotlb_dma_ops = {
20275 +static const struct dma_map_ops xen_swiotlb_dma_ops = {
20276 .mapping_error = xen_swiotlb_dma_mapping_error,
20277 .alloc_coherent = xen_swiotlb_alloc_coherent,
20278 .free_coherent = xen_swiotlb_free_coherent,
20279 diff -urNp linux-2.6.37/arch/x86/xen/smp.c linux-2.6.37/arch/x86/xen/smp.c
20280 --- linux-2.6.37/arch/x86/xen/smp.c 2011-01-04 19:50:19.000000000 -0500
20281 +++ linux-2.6.37/arch/x86/xen/smp.c 2011-01-17 02:41:01.000000000 -0500
20282 @@ -194,11 +194,6 @@ static void __init xen_smp_prepare_boot_
20283 {
20284 BUG_ON(smp_processor_id() != 0);
20285 native_smp_prepare_boot_cpu();
20286 -
20287 - /* We've switched to the "real" per-cpu gdt, so make sure the
20288 - old memory can be recycled */
20289 - make_lowmem_page_readwrite(xen_initial_gdt);
20290 -
20291 xen_filter_cpu_maps();
20292 xen_setup_vcpu_info_placement();
20293 }
20294 @@ -259,12 +254,12 @@ cpu_initialize_context(unsigned int cpu,
20295 gdt = get_cpu_gdt_table(cpu);
20296
20297 ctxt->flags = VGCF_IN_KERNEL;
20298 - ctxt->user_regs.ds = __USER_DS;
20299 - ctxt->user_regs.es = __USER_DS;
20300 + ctxt->user_regs.ds = __KERNEL_DS;
20301 + ctxt->user_regs.es = __KERNEL_DS;
20302 ctxt->user_regs.ss = __KERNEL_DS;
20303 #ifdef CONFIG_X86_32
20304 ctxt->user_regs.fs = __KERNEL_PERCPU;
20305 - ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
20306 + savesegment(gs, ctxt->user_regs.gs);
20307 #else
20308 ctxt->gs_base_kernel = per_cpu_offset(cpu);
20309 #endif
20310 diff -urNp linux-2.6.37/arch/x86/xen/xen-head.S linux-2.6.37/arch/x86/xen/xen-head.S
20311 --- linux-2.6.37/arch/x86/xen/xen-head.S 2011-01-04 19:50:19.000000000 -0500
20312 +++ linux-2.6.37/arch/x86/xen/xen-head.S 2011-01-17 02:41:01.000000000 -0500
20313 @@ -19,6 +19,17 @@ ENTRY(startup_xen)
20314 #ifdef CONFIG_X86_32
20315 mov %esi,xen_start_info
20316 mov $init_thread_union+THREAD_SIZE,%esp
20317 +#ifdef CONFIG_SMP
20318 + movl $cpu_gdt_table,%edi
20319 + movl $__per_cpu_load,%eax
20320 + movw %ax,__KERNEL_PERCPU + 2(%edi)
20321 + rorl $16,%eax
20322 + movb %al,__KERNEL_PERCPU + 4(%edi)
20323 + movb %ah,__KERNEL_PERCPU + 7(%edi)
20324 + movl $__per_cpu_end - 1,%eax
20325 + subl $__per_cpu_start,%eax
20326 + movw %ax,__KERNEL_PERCPU + 0(%edi)
20327 +#endif
20328 #else
20329 mov %rsi,xen_start_info
20330 mov $init_thread_union+THREAD_SIZE,%rsp
20331 diff -urNp linux-2.6.37/arch/x86/xen/xen-ops.h linux-2.6.37/arch/x86/xen/xen-ops.h
20332 --- linux-2.6.37/arch/x86/xen/xen-ops.h 2011-01-04 19:50:19.000000000 -0500
20333 +++ linux-2.6.37/arch/x86/xen/xen-ops.h 2011-01-17 02:41:01.000000000 -0500
20334 @@ -10,8 +10,6 @@
20335 extern const char xen_hypervisor_callback[];
20336 extern const char xen_failsafe_callback[];
20337
20338 -extern void *xen_initial_gdt;
20339 -
20340 struct trap_info;
20341 void xen_copy_trap_info(struct trap_info *traps);
20342
20343 diff -urNp linux-2.6.37/block/blk-iopoll.c linux-2.6.37/block/blk-iopoll.c
20344 --- linux-2.6.37/block/blk-iopoll.c 2011-01-04 19:50:19.000000000 -0500
20345 +++ linux-2.6.37/block/blk-iopoll.c 2011-01-17 02:41:01.000000000 -0500
20346 @@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopo
20347 }
20348 EXPORT_SYMBOL(blk_iopoll_complete);
20349
20350 -static void blk_iopoll_softirq(struct softirq_action *h)
20351 +static void blk_iopoll_softirq(void)
20352 {
20353 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
20354 int rearm = 0, budget = blk_iopoll_budget;
20355 diff -urNp linux-2.6.37/block/blk-map.c linux-2.6.37/block/blk-map.c
20356 --- linux-2.6.37/block/blk-map.c 2011-01-04 19:50:19.000000000 -0500
20357 +++ linux-2.6.37/block/blk-map.c 2011-01-17 02:41:01.000000000 -0500
20358 @@ -301,7 +301,7 @@ int blk_rq_map_kern(struct request_queue
20359 if (!len || !kbuf)
20360 return -EINVAL;
20361
20362 - do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
20363 + do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
20364 if (do_copy)
20365 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
20366 else
20367 diff -urNp linux-2.6.37/block/blk-softirq.c linux-2.6.37/block/blk-softirq.c
20368 --- linux-2.6.37/block/blk-softirq.c 2011-01-04 19:50:19.000000000 -0500
20369 +++ linux-2.6.37/block/blk-softirq.c 2011-01-17 02:41:01.000000000 -0500
20370 @@ -17,7 +17,7 @@ static DEFINE_PER_CPU(struct list_head,
20371 * Softirq action handler - move entries to local list and loop over them
20372 * while passing them to the queue registered handler.
20373 */
20374 -static void blk_done_softirq(struct softirq_action *h)
20375 +static void blk_done_softirq(void)
20376 {
20377 struct list_head *cpu_list, local_list;
20378
20379 diff -urNp linux-2.6.37/crypto/lrw.c linux-2.6.37/crypto/lrw.c
20380 --- linux-2.6.37/crypto/lrw.c 2011-01-04 19:50:19.000000000 -0500
20381 +++ linux-2.6.37/crypto/lrw.c 2011-01-17 02:41:01.000000000 -0500
20382 @@ -60,7 +60,7 @@ static int setkey(struct crypto_tfm *par
20383 struct priv *ctx = crypto_tfm_ctx(parent);
20384 struct crypto_cipher *child = ctx->child;
20385 int err, i;
20386 - be128 tmp = { 0 };
20387 + be128 tmp = { 0, 0 };
20388 int bsize = crypto_cipher_blocksize(child);
20389
20390 crypto_cipher_clear_flags(child, CRYPTO_TFM_REQ_MASK);
20391 diff -urNp linux-2.6.37/Documentation/dontdiff linux-2.6.37/Documentation/dontdiff
20392 --- linux-2.6.37/Documentation/dontdiff 2011-01-04 19:50:19.000000000 -0500
20393 +++ linux-2.6.37/Documentation/dontdiff 2011-01-17 02:41:01.000000000 -0500
20394 @@ -3,6 +3,7 @@
20395 *.bin
20396 *.cpio
20397 *.csp
20398 +*.dbg
20399 *.dsp
20400 *.dvi
20401 *.elf
20402 @@ -38,8 +39,10 @@
20403 *.tab.h
20404 *.tex
20405 *.ver
20406 +*.vim
20407 *.xml
20408 *_MODULES
20409 +*_reg_safe.h
20410 *_vga16.c
20411 *~
20412 *.9
20413 @@ -49,11 +52,16 @@
20414 53c700_d.h
20415 CVS
20416 ChangeSet
20417 +GPATH
20418 +GRTAGS
20419 +GSYMS
20420 +GTAGS
20421 Image
20422 Kerntypes
20423 Module.markers
20424 Module.symvers
20425 PENDING
20426 +PERF*
20427 SCCS
20428 System.map*
20429 TAGS
20430 @@ -62,6 +70,7 @@ aic7*reg_print.c*
20431 aic7*seq.h*
20432 aicasm
20433 aicdb.h*
20434 +altivec[0-9].c
20435 asm-offsets.h
20436 asm_offsets.h
20437 autoconf.h*
20438 @@ -76,7 +85,10 @@ btfixupprep
20439 build
20440 bvmlinux
20441 bzImage*
20442 +capflags.c
20443 classlist.h*
20444 +clut_vga16.c
20445 +common-cmds.h
20446 comp*.log
20447 compile.h*
20448 conf
20449 @@ -100,19 +112,23 @@ fore200e_mkfirm
20450 fore200e_pca_fw.c*
20451 gconf
20452 gen-devlist
20453 +gen-kdb_cmds.c
20454 gen_crc32table
20455 gen_init_cpio
20456 generated
20457 genheaders
20458 genksyms
20459 *_gray256.c
20460 +hash
20461 ihex2fw
20462 ikconfig.h*
20463 +inat-tables.c
20464 initramfs_data.cpio
20465 +initramfs_data.cpio.bz2
20466 initramfs_data.cpio.gz
20467 initramfs_list
20468 +int[0-9]*.c
20469 kallsyms
20470 -kconfig
20471 keywords.c
20472 ksym.c*
20473 ksym.h*
20474 @@ -136,10 +152,13 @@ mkboot
20475 mkbugboot
20476 mkcpustr
20477 mkdep
20478 +mkpiggy
20479 mkprep
20480 +mkregtable
20481 mktables
20482 mktree
20483 modpost
20484 +modules.builtin
20485 modules.order
20486 modversions.h*
20487 ncscope.*
20488 @@ -151,7 +170,9 @@ parse.h
20489 patches*
20490 pca200e.bin
20491 pca200e_ecd.bin2
20492 +perf-archive
20493 piggy.gz
20494 +piggy.S
20495 piggyback
20496 pnmtologo
20497 ppc_defs.h*
20498 @@ -160,15 +181,18 @@ qconf
20499 raid6altivec*.c
20500 raid6int*.c
20501 raid6tables.c
20502 +regdb.c
20503 relocs
20504 series
20505 setup
20506 setup.bin
20507 setup.elf
20508 sImage
20509 +slabinfo
20510 sm_tbl*
20511 split-include
20512 syscalltab.h
20513 +tables.c
20514 tags
20515 tftpboot.img
20516 timeconst.h
20517 @@ -189,14 +213,20 @@ version.h*
20518 vmlinux
20519 vmlinux-*
20520 vmlinux.aout
20521 +vmlinux.bin.all
20522 +vmlinux.bin.bz2
20523 vmlinux.lds
20524 +vmlinux.relocs
20525 +voffset.h
20526 vsyscall.lds
20527 vsyscall_32.lds
20528 wanxlfw.inc
20529 uImage
20530 unifdef
20531 +utsrelease.h
20532 wakeup.bin
20533 wakeup.elf
20534 wakeup.lds
20535 zImage*
20536 zconf.hash.c
20537 +zoffset.h
20538 diff -urNp linux-2.6.37/Documentation/filesystems/sysfs.txt linux-2.6.37/Documentation/filesystems/sysfs.txt
20539 --- linux-2.6.37/Documentation/filesystems/sysfs.txt 2011-01-04 19:50:19.000000000 -0500
20540 +++ linux-2.6.37/Documentation/filesystems/sysfs.txt 2011-01-17 02:41:01.000000000 -0500
20541 @@ -123,8 +123,8 @@ set of sysfs operations for forwarding r
20542 show and store methods of the attribute owners.
20543
20544 struct sysfs_ops {
20545 - ssize_t (*show)(struct kobject *, struct attribute *, char *);
20546 - ssize_t (*store)(struct kobject *, struct attribute *, const char *, size_t);
20547 + ssize_t (* const show)(struct kobject *, struct attribute *, char *);
20548 + ssize_t (* const store)(struct kobject *, struct attribute *, const char *, size_t);
20549 };
20550
20551 [ Subsystems should have already defined a struct kobj_type as a
20552 diff -urNp linux-2.6.37/Documentation/kernel-parameters.txt linux-2.6.37/Documentation/kernel-parameters.txt
20553 --- linux-2.6.37/Documentation/kernel-parameters.txt 2011-01-04 19:50:19.000000000 -0500
20554 +++ linux-2.6.37/Documentation/kernel-parameters.txt 2011-01-17 02:41:01.000000000 -0500
20555 @@ -1849,6 +1849,13 @@ and is between 256 and 4096 characters.
20556 the specified number of seconds. This is to be used if
20557 your oopses keep scrolling off the screen.
20558
20559 + pax_nouderef [X86] disables UDEREF. Most likely needed under certain
20560 + virtualization environments that don't cope well with the
20561 + expand down segment used by UDEREF on X86-32 or the frequent
20562 + page table updates on X86-64.
20563 +
20564 + pax_softmode= [X86-32] 0/1 to disable/enable PaX softmode on boot already.
20565 +
20566 pcbit= [HW,ISDN]
20567
20568 pcd. [PARIDE]
20569 diff -urNp linux-2.6.37/drivers/acpi/battery.c linux-2.6.37/drivers/acpi/battery.c
20570 --- linux-2.6.37/drivers/acpi/battery.c 2011-01-04 19:50:19.000000000 -0500
20571 +++ linux-2.6.37/drivers/acpi/battery.c 2011-01-17 02:41:01.000000000 -0500
20572 @@ -851,7 +851,7 @@ DECLARE_FILE_FUNCTIONS(alarm);
20573 }
20574
20575 static struct battery_file {
20576 - struct file_operations ops;
20577 + const struct file_operations ops;
20578 mode_t mode;
20579 const char *name;
20580 } acpi_battery_file[] = {
20581 diff -urNp linux-2.6.37/drivers/acpi/blacklist.c linux-2.6.37/drivers/acpi/blacklist.c
20582 --- linux-2.6.37/drivers/acpi/blacklist.c 2011-01-04 19:50:19.000000000 -0500
20583 +++ linux-2.6.37/drivers/acpi/blacklist.c 2011-01-17 02:41:01.000000000 -0500
20584 @@ -73,7 +73,7 @@ static struct acpi_blacklist_item acpi_b
20585 {"IBM ", "TP600E ", 0x00000105, ACPI_SIG_DSDT, less_than_or_equal,
20586 "Incorrect _ADR", 1},
20587
20588 - {""}
20589 + {"", "", 0, NULL, all_versions, NULL, 0}
20590 };
20591
20592 #if CONFIG_ACPI_BLACKLIST_YEAR
20593 diff -urNp linux-2.6.37/drivers/acpi/dock.c linux-2.6.37/drivers/acpi/dock.c
20594 --- linux-2.6.37/drivers/acpi/dock.c 2011-01-04 19:50:19.000000000 -0500
20595 +++ linux-2.6.37/drivers/acpi/dock.c 2011-01-17 02:41:01.000000000 -0500
20596 @@ -77,7 +77,7 @@ struct dock_dependent_device {
20597 struct list_head list;
20598 struct list_head hotplug_list;
20599 acpi_handle handle;
20600 - struct acpi_dock_ops *ops;
20601 + const struct acpi_dock_ops *ops;
20602 void *context;
20603 };
20604
20605 @@ -589,7 +589,7 @@ EXPORT_SYMBOL_GPL(unregister_dock_notifi
20606 * the dock driver after _DCK is executed.
20607 */
20608 int
20609 -register_hotplug_dock_device(acpi_handle handle, struct acpi_dock_ops *ops,
20610 +register_hotplug_dock_device(acpi_handle handle, const struct acpi_dock_ops *ops,
20611 void *context)
20612 {
20613 struct dock_dependent_device *dd;
20614 diff -urNp linux-2.6.37/drivers/acpi/ec_sys.c linux-2.6.37/drivers/acpi/ec_sys.c
20615 --- linux-2.6.37/drivers/acpi/ec_sys.c 2011-01-04 19:50:19.000000000 -0500
20616 +++ linux-2.6.37/drivers/acpi/ec_sys.c 2011-01-17 02:41:01.000000000 -0500
20617 @@ -96,7 +96,7 @@ static ssize_t acpi_ec_write_io(struct f
20618 return count;
20619 }
20620
20621 -static struct file_operations acpi_ec_io_ops = {
20622 +static const struct file_operations acpi_ec_io_ops = {
20623 .owner = THIS_MODULE,
20624 .open = acpi_ec_open_io,
20625 .read = acpi_ec_read_io,
20626 diff -urNp linux-2.6.37/drivers/acpi/osl.c linux-2.6.37/drivers/acpi/osl.c
20627 --- linux-2.6.37/drivers/acpi/osl.c 2011-01-04 19:50:19.000000000 -0500
20628 +++ linux-2.6.37/drivers/acpi/osl.c 2011-01-17 02:41:01.000000000 -0500
20629 @@ -643,6 +643,8 @@ acpi_os_read_memory(acpi_physical_addres
20630 rcu_read_unlock();
20631 if (!virt_addr) {
20632 virt_addr = ioremap(phys_addr, size);
20633 + if (!virt_addr)
20634 + return AE_NO_MEMORY;
20635 unmap = 1;
20636 }
20637 if (!value)
20638 @@ -679,6 +681,8 @@ acpi_os_write_memory(acpi_physical_addre
20639 rcu_read_unlock();
20640 if (!virt_addr) {
20641 virt_addr = ioremap(phys_addr, size);
20642 + if (!virt_addr)
20643 + return AE_NO_MEMORY;
20644 unmap = 1;
20645 }
20646
20647 diff -urNp linux-2.6.37/drivers/acpi/power_meter.c linux-2.6.37/drivers/acpi/power_meter.c
20648 --- linux-2.6.37/drivers/acpi/power_meter.c 2011-01-04 19:50:19.000000000 -0500
20649 +++ linux-2.6.37/drivers/acpi/power_meter.c 2011-01-17 02:41:01.000000000 -0500
20650 @@ -316,8 +316,6 @@ static ssize_t set_trip(struct device *d
20651 return res;
20652
20653 temp /= 1000;
20654 - if (temp < 0)
20655 - return -EINVAL;
20656
20657 mutex_lock(&resource->lock);
20658 resource->trip[attr->index - 7] = temp;
20659 diff -urNp linux-2.6.37/drivers/acpi/proc.c linux-2.6.37/drivers/acpi/proc.c
20660 --- linux-2.6.37/drivers/acpi/proc.c 2011-01-04 19:50:19.000000000 -0500
20661 +++ linux-2.6.37/drivers/acpi/proc.c 2011-01-17 02:41:01.000000000 -0500
20662 @@ -338,20 +338,15 @@ acpi_system_write_wakeup_device(struct f
20663 size_t count, loff_t * ppos)
20664 {
20665 struct list_head *node, *next;
20666 - char strbuf[5];
20667 - char str[5] = "";
20668 - unsigned int len = count;
20669 + char strbuf[5] = {0};
20670 struct acpi_device *found_dev = NULL;
20671
20672 - if (len > 4)
20673 - len = 4;
20674 - if (len < 0)
20675 - return -EFAULT;
20676 + if (count > 4)
20677 + count = 4;
20678
20679 - if (copy_from_user(strbuf, buffer, len))
20680 + if (copy_from_user(strbuf, buffer, count))
20681 return -EFAULT;
20682 - strbuf[len] = '\0';
20683 - sscanf(strbuf, "%s", str);
20684 + strbuf[count] = '\0';
20685
20686 mutex_lock(&acpi_device_lock);
20687 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
20688 @@ -360,7 +355,7 @@ acpi_system_write_wakeup_device(struct f
20689 if (!dev->wakeup.flags.valid)
20690 continue;
20691
20692 - if (!strncmp(dev->pnp.bus_id, str, 4)) {
20693 + if (!strncmp(dev->pnp.bus_id, strbuf, 4)) {
20694 dev->wakeup.state.enabled =
20695 dev->wakeup.state.enabled ? 0 : 1;
20696 found_dev = dev;
20697 diff -urNp linux-2.6.37/drivers/acpi/processor_driver.c linux-2.6.37/drivers/acpi/processor_driver.c
20698 --- linux-2.6.37/drivers/acpi/processor_driver.c 2011-01-04 19:50:19.000000000 -0500
20699 +++ linux-2.6.37/drivers/acpi/processor_driver.c 2011-01-17 02:41:01.000000000 -0500
20700 @@ -519,7 +519,7 @@ static int __cpuinit acpi_processor_add(
20701 return 0;
20702 #endif
20703
20704 - BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
20705 + BUG_ON(pr->id >= nr_cpu_ids);
20706
20707 /*
20708 * Buggy BIOS check
20709 diff -urNp linux-2.6.37/drivers/acpi/processor_idle.c linux-2.6.37/drivers/acpi/processor_idle.c
20710 --- linux-2.6.37/drivers/acpi/processor_idle.c 2011-01-04 19:50:19.000000000 -0500
20711 +++ linux-2.6.37/drivers/acpi/processor_idle.c 2011-01-17 02:41:01.000000000 -0500
20712 @@ -114,7 +114,7 @@ static struct dmi_system_id __cpuinitdat
20713 DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer Inc."),
20714 DMI_MATCH(DMI_PRODUCT_NAME,"L8400B series Notebook PC")},
20715 (void *)1},
20716 - {},
20717 + { NULL, NULL, {DMI_MATCH(DMI_NONE, {0})}, NULL},
20718 };
20719
20720
20721 diff -urNp linux-2.6.37/drivers/acpi/sleep.c linux-2.6.37/drivers/acpi/sleep.c
20722 --- linux-2.6.37/drivers/acpi/sleep.c 2011-01-04 19:50:19.000000000 -0500
20723 +++ linux-2.6.37/drivers/acpi/sleep.c 2011-01-17 02:41:01.000000000 -0500
20724 @@ -319,7 +319,7 @@ static int acpi_suspend_state_valid(susp
20725 }
20726 }
20727
20728 -static struct platform_suspend_ops acpi_suspend_ops = {
20729 +static const struct platform_suspend_ops acpi_suspend_ops = {
20730 .valid = acpi_suspend_state_valid,
20731 .begin = acpi_suspend_begin,
20732 .prepare_late = acpi_pm_prepare,
20733 @@ -347,7 +347,7 @@ static int acpi_suspend_begin_old(suspen
20734 * The following callbacks are used if the pre-ACPI 2.0 suspend ordering has
20735 * been requested.
20736 */
20737 -static struct platform_suspend_ops acpi_suspend_ops_old = {
20738 +static const struct platform_suspend_ops acpi_suspend_ops_old = {
20739 .valid = acpi_suspend_state_valid,
20740 .begin = acpi_suspend_begin_old,
20741 .prepare_late = acpi_pm_pre_suspend,
20742 @@ -506,7 +506,7 @@ static void acpi_pm_thaw(void)
20743 acpi_enable_all_runtime_gpes();
20744 }
20745
20746 -static struct platform_hibernation_ops acpi_hibernation_ops = {
20747 +static const struct platform_hibernation_ops acpi_hibernation_ops = {
20748 .begin = acpi_hibernation_begin,
20749 .end = acpi_pm_end,
20750 .pre_snapshot = acpi_pm_prepare,
20751 @@ -549,7 +549,7 @@ static int acpi_hibernation_begin_old(vo
20752 * The following callbacks are used if the pre-ACPI 2.0 suspend ordering has
20753 * been requested.
20754 */
20755 -static struct platform_hibernation_ops acpi_hibernation_ops_old = {
20756 +static const struct platform_hibernation_ops acpi_hibernation_ops_old = {
20757 .begin = acpi_hibernation_begin_old,
20758 .end = acpi_pm_end,
20759 .pre_snapshot = acpi_pm_pre_suspend,
20760 diff -urNp linux-2.6.37/drivers/acpi/video.c linux-2.6.37/drivers/acpi/video.c
20761 --- linux-2.6.37/drivers/acpi/video.c 2011-01-04 19:50:19.000000000 -0500
20762 +++ linux-2.6.37/drivers/acpi/video.c 2011-01-17 02:41:01.000000000 -0500
20763 @@ -260,7 +260,7 @@ static int acpi_video_set_brightness(str
20764 vd->brightness->levels[request_level]);
20765 }
20766
20767 -static struct backlight_ops acpi_backlight_ops = {
20768 +static const struct backlight_ops acpi_backlight_ops = {
20769 .get_brightness = acpi_video_get_brightness,
20770 .update_status = acpi_video_set_brightness,
20771 };
20772 diff -urNp linux-2.6.37/drivers/ata/ahci.c linux-2.6.37/drivers/ata/ahci.c
20773 --- linux-2.6.37/drivers/ata/ahci.c 2011-01-04 19:50:19.000000000 -0500
20774 +++ linux-2.6.37/drivers/ata/ahci.c 2011-01-17 02:41:01.000000000 -0500
20775 @@ -94,17 +94,17 @@ static struct scsi_host_template ahci_sh
20776 AHCI_SHT("ahci"),
20777 };
20778
20779 -static struct ata_port_operations ahci_vt8251_ops = {
20780 +static const struct ata_port_operations ahci_vt8251_ops = {
20781 .inherits = &ahci_ops,
20782 .hardreset = ahci_vt8251_hardreset,
20783 };
20784
20785 -static struct ata_port_operations ahci_p5wdh_ops = {
20786 +static const struct ata_port_operations ahci_p5wdh_ops = {
20787 .inherits = &ahci_ops,
20788 .hardreset = ahci_p5wdh_hardreset,
20789 };
20790
20791 -static struct ata_port_operations ahci_sb600_ops = {
20792 +static const struct ata_port_operations ahci_sb600_ops = {
20793 .inherits = &ahci_ops,
20794 .softreset = ahci_sb600_softreset,
20795 .pmp_softreset = ahci_sb600_softreset,
20796 @@ -388,7 +388,7 @@ static const struct pci_device_id ahci_p
20797 { PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
20798 PCI_CLASS_STORAGE_SATA_AHCI, 0xffffff, board_ahci },
20799
20800 - { } /* terminate list */
20801 + { 0, 0, 0, 0, 0, 0, 0 } /* terminate list */
20802 };
20803
20804
20805 diff -urNp linux-2.6.37/drivers/ata/ahci.h linux-2.6.37/drivers/ata/ahci.h
20806 --- linux-2.6.37/drivers/ata/ahci.h 2011-01-04 19:50:19.000000000 -0500
20807 +++ linux-2.6.37/drivers/ata/ahci.h 2011-01-17 02:41:01.000000000 -0500
20808 @@ -309,7 +309,7 @@ extern struct device_attribute *ahci_sde
20809 .shost_attrs = ahci_shost_attrs, \
20810 .sdev_attrs = ahci_sdev_attrs
20811
20812 -extern struct ata_port_operations ahci_ops;
20813 +extern const struct ata_port_operations ahci_ops;
20814
20815 void ahci_save_initial_config(struct device *dev,
20816 struct ahci_host_priv *hpriv,
20817 diff -urNp linux-2.6.37/drivers/ata/ata_generic.c linux-2.6.37/drivers/ata/ata_generic.c
20818 --- linux-2.6.37/drivers/ata/ata_generic.c 2011-01-04 19:50:19.000000000 -0500
20819 +++ linux-2.6.37/drivers/ata/ata_generic.c 2011-01-17 02:41:01.000000000 -0500
20820 @@ -101,7 +101,7 @@ static struct scsi_host_template generic
20821 ATA_BMDMA_SHT(DRV_NAME),
20822 };
20823
20824 -static struct ata_port_operations generic_port_ops = {
20825 +static const struct ata_port_operations generic_port_ops = {
20826 .inherits = &ata_bmdma_port_ops,
20827 .cable_detect = ata_cable_unknown,
20828 .set_mode = generic_set_mode,
20829 diff -urNp linux-2.6.37/drivers/ata/ata_piix.c linux-2.6.37/drivers/ata/ata_piix.c
20830 --- linux-2.6.37/drivers/ata/ata_piix.c 2011-01-04 19:50:19.000000000 -0500
20831 +++ linux-2.6.37/drivers/ata/ata_piix.c 2011-01-17 02:41:01.000000000 -0500
20832 @@ -309,7 +309,7 @@ static const struct pci_device_id piix_p
20833 { 0x8086, 0x1d00, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_sata },
20834 /* SATA Controller IDE (PBG) */
20835 { 0x8086, 0x1d08, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_2port_sata },
20836 - { } /* terminate list */
20837 + { 0, 0, 0, 0, 0, 0, 0 } /* terminate list */
20838 };
20839
20840 static struct pci_driver piix_pci_driver = {
20841 @@ -327,12 +327,12 @@ static struct scsi_host_template piix_sh
20842 ATA_BMDMA_SHT(DRV_NAME),
20843 };
20844
20845 -static struct ata_port_operations piix_sata_ops = {
20846 +static const struct ata_port_operations piix_sata_ops = {
20847 .inherits = &ata_bmdma32_port_ops,
20848 .sff_irq_check = piix_irq_check,
20849 };
20850
20851 -static struct ata_port_operations piix_pata_ops = {
20852 +static const struct ata_port_operations piix_pata_ops = {
20853 .inherits = &piix_sata_ops,
20854 .cable_detect = ata_cable_40wire,
20855 .set_piomode = piix_set_piomode,
20856 @@ -340,12 +340,12 @@ static struct ata_port_operations piix_p
20857 .prereset = piix_pata_prereset,
20858 };
20859
20860 -static struct ata_port_operations piix_vmw_ops = {
20861 +static const struct ata_port_operations piix_vmw_ops = {
20862 .inherits = &piix_pata_ops,
20863 .bmdma_status = piix_vmw_bmdma_status,
20864 };
20865
20866 -static struct ata_port_operations ich_pata_ops = {
20867 +static const struct ata_port_operations ich_pata_ops = {
20868 .inherits = &piix_pata_ops,
20869 .cable_detect = ich_pata_cable_detect,
20870 .set_dmamode = ich_set_dmamode,
20871 @@ -361,7 +361,7 @@ static struct scsi_host_template piix_si
20872 .shost_attrs = piix_sidpr_shost_attrs,
20873 };
20874
20875 -static struct ata_port_operations piix_sidpr_sata_ops = {
20876 +static const struct ata_port_operations piix_sidpr_sata_ops = {
20877 .inherits = &piix_sata_ops,
20878 .hardreset = sata_std_hardreset,
20879 .scr_read = piix_sidpr_scr_read,
20880 @@ -638,7 +638,7 @@ static const struct ich_laptop ich_lapto
20881 { 0x2653, 0x1043, 0x82D8 }, /* ICH6M on Asus Eee 701 */
20882 { 0x27df, 0x104d, 0x900e }, /* ICH7 on Sony TZ-90 */
20883 /* end marker */
20884 - { 0, }
20885 + { 0, 0, 0 }
20886 };
20887
20888 /**
20889 @@ -1130,7 +1130,7 @@ static int piix_broken_suspend(void)
20890 },
20891 },
20892
20893 - { } /* terminate list */
20894 + { NULL, NULL, {DMI_MATCH(DMI_NONE, {0})}, NULL } /* terminate list */
20895 };
20896 static const char *oemstrs[] = {
20897 "Tecra M3,",
20898 diff -urNp linux-2.6.37/drivers/ata/libahci.c linux-2.6.37/drivers/ata/libahci.c
20899 --- linux-2.6.37/drivers/ata/libahci.c 2011-01-04 19:50:19.000000000 -0500
20900 +++ linux-2.6.37/drivers/ata/libahci.c 2011-01-17 02:41:01.000000000 -0500
20901 @@ -140,7 +140,7 @@ struct device_attribute *ahci_sdev_attrs
20902 };
20903 EXPORT_SYMBOL_GPL(ahci_sdev_attrs);
20904
20905 -struct ata_port_operations ahci_ops = {
20906 +const struct ata_port_operations ahci_ops = {
20907 .inherits = &sata_pmp_port_ops,
20908
20909 .qc_defer = ahci_pmp_qc_defer,
20910 diff -urNp linux-2.6.37/drivers/ata/libata-acpi.c linux-2.6.37/drivers/ata/libata-acpi.c
20911 --- linux-2.6.37/drivers/ata/libata-acpi.c 2011-01-04 19:50:19.000000000 -0500
20912 +++ linux-2.6.37/drivers/ata/libata-acpi.c 2011-01-17 02:41:01.000000000 -0500
20913 @@ -218,12 +218,12 @@ static void ata_acpi_dev_uevent(acpi_han
20914 ata_acpi_uevent(dev->link->ap, dev, event);
20915 }
20916
20917 -static struct acpi_dock_ops ata_acpi_dev_dock_ops = {
20918 +static const struct acpi_dock_ops ata_acpi_dev_dock_ops = {
20919 .handler = ata_acpi_dev_notify_dock,
20920 .uevent = ata_acpi_dev_uevent,
20921 };
20922
20923 -static struct acpi_dock_ops ata_acpi_ap_dock_ops = {
20924 +static const struct acpi_dock_ops ata_acpi_ap_dock_ops = {
20925 .handler = ata_acpi_ap_notify_dock,
20926 .uevent = ata_acpi_ap_uevent,
20927 };
20928 diff -urNp linux-2.6.37/drivers/ata/libata-core.c linux-2.6.37/drivers/ata/libata-core.c
20929 --- linux-2.6.37/drivers/ata/libata-core.c 2011-01-04 19:50:19.000000000 -0500
20930 +++ linux-2.6.37/drivers/ata/libata-core.c 2011-01-17 02:41:01.000000000 -0500
20931 @@ -897,7 +897,7 @@ static const struct ata_xfer_ent {
20932 { ATA_SHIFT_PIO, ATA_NR_PIO_MODES, XFER_PIO_0 },
20933 { ATA_SHIFT_MWDMA, ATA_NR_MWDMA_MODES, XFER_MW_DMA_0 },
20934 { ATA_SHIFT_UDMA, ATA_NR_UDMA_MODES, XFER_UDMA_0 },
20935 - { -1, },
20936 + { -1, 0, 0 }
20937 };
20938
20939 /**
20940 @@ -2885,7 +2885,7 @@ static const struct ata_timing ata_timin
20941 { XFER_UDMA_5, 0, 0, 0, 0, 0, 0, 0, 0, 20 },
20942 { XFER_UDMA_6, 0, 0, 0, 0, 0, 0, 0, 0, 15 },
20943
20944 - { 0xFF }
20945 + { 0xFF, 0, 0, 0, 0, 0, 0, 0, 0 }
20946 };
20947
20948 #define ENOUGH(v, unit) (((v)-1)/(unit)+1)
20949 @@ -4140,7 +4140,7 @@ static const struct ata_blacklist_entry
20950 { "PIONEER DVD-RW DVRTD08", "1.00", ATA_HORKAGE_NOSETXFER },
20951
20952 /* End Marker */
20953 - { }
20954 + { NULL, NULL, 0 }
20955 };
20956
20957 /**
20958 @@ -4745,7 +4745,7 @@ void ata_qc_free(struct ata_queued_cmd *
20959 struct ata_port *ap;
20960 unsigned int tag;
20961
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 ap = qc->ap;
20965
20966 qc->flags = 0;
20967 @@ -4761,7 +4761,7 @@ void __ata_qc_complete(struct ata_queued
20968 struct ata_port *ap;
20969 struct ata_link *link;
20970
20971 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
20972 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
20973 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
20974 ap = qc->ap;
20975 link = qc->dev->link;
20976 @@ -5754,7 +5754,7 @@ static void ata_host_stop(struct device
20977 * LOCKING:
20978 * None.
20979 */
20980 -static void ata_finalize_port_ops(struct ata_port_operations *ops)
20981 +static void ata_finalize_port_ops(const struct ata_port_operations *ops)
20982 {
20983 static DEFINE_SPINLOCK(lock);
20984 const struct ata_port_operations *cur;
20985 @@ -5766,6 +5766,7 @@ static void ata_finalize_port_ops(struct
20986 return;
20987
20988 spin_lock(&lock);
20989 + pax_open_kernel();
20990
20991 for (cur = ops->inherits; cur; cur = cur->inherits) {
20992 void **inherit = (void **)cur;
20993 @@ -5779,8 +5780,9 @@ static void ata_finalize_port_ops(struct
20994 if (IS_ERR(*pp))
20995 *pp = NULL;
20996
20997 - ops->inherits = NULL;
20998 + ((struct ata_port_operations *)ops)->inherits = NULL;
20999
21000 + pax_close_kernel();
21001 spin_unlock(&lock);
21002 }
21003
21004 @@ -5877,7 +5879,7 @@ int ata_host_start(struct ata_host *host
21005 */
21006 /* KILLME - the only user left is ipr */
21007 void ata_host_init(struct ata_host *host, struct device *dev,
21008 - unsigned long flags, struct ata_port_operations *ops)
21009 + unsigned long flags, const struct ata_port_operations *ops)
21010 {
21011 spin_lock_init(&host->lock);
21012 mutex_init(&host->eh_mutex);
21013 @@ -6583,7 +6585,7 @@ static void ata_dummy_error_handler(stru
21014 /* truly dummy */
21015 }
21016
21017 -struct ata_port_operations ata_dummy_port_ops = {
21018 +const struct ata_port_operations ata_dummy_port_ops = {
21019 .qc_prep = ata_noop_qc_prep,
21020 .qc_issue = ata_dummy_qc_issue,
21021 .error_handler = ata_dummy_error_handler,
21022 diff -urNp linux-2.6.37/drivers/ata/libata-eh.c linux-2.6.37/drivers/ata/libata-eh.c
21023 --- linux-2.6.37/drivers/ata/libata-eh.c 2011-01-04 19:50:19.000000000 -0500
21024 +++ linux-2.6.37/drivers/ata/libata-eh.c 2011-01-17 02:41:01.000000000 -0500
21025 @@ -3880,7 +3880,7 @@ void ata_do_eh(struct ata_port *ap, ata_
21026 */
21027 void ata_std_error_handler(struct ata_port *ap)
21028 {
21029 - struct ata_port_operations *ops = ap->ops;
21030 + const struct ata_port_operations *ops = ap->ops;
21031 ata_reset_fn_t hardreset = ops->hardreset;
21032
21033 /* ignore built-in hardreset if SCR access is not available */
21034 diff -urNp linux-2.6.37/drivers/ata/libata-pmp.c linux-2.6.37/drivers/ata/libata-pmp.c
21035 --- linux-2.6.37/drivers/ata/libata-pmp.c 2011-01-04 19:50:19.000000000 -0500
21036 +++ linux-2.6.37/drivers/ata/libata-pmp.c 2011-01-17 02:41:01.000000000 -0500
21037 @@ -912,7 +912,7 @@ static int sata_pmp_handle_link_fail(str
21038 */
21039 static int sata_pmp_eh_recover(struct ata_port *ap)
21040 {
21041 - struct ata_port_operations *ops = ap->ops;
21042 + const struct ata_port_operations *ops = ap->ops;
21043 int pmp_tries, link_tries[SATA_PMP_MAX_PORTS];
21044 struct ata_link *pmp_link = &ap->link;
21045 struct ata_device *pmp_dev = pmp_link->device;
21046 diff -urNp linux-2.6.37/drivers/ata/pata_acpi.c linux-2.6.37/drivers/ata/pata_acpi.c
21047 --- linux-2.6.37/drivers/ata/pata_acpi.c 2011-01-04 19:50:19.000000000 -0500
21048 +++ linux-2.6.37/drivers/ata/pata_acpi.c 2011-01-17 02:41:01.000000000 -0500
21049 @@ -216,7 +216,7 @@ static struct scsi_host_template pacpi_s
21050 ATA_BMDMA_SHT(DRV_NAME),
21051 };
21052
21053 -static struct ata_port_operations pacpi_ops = {
21054 +static const struct ata_port_operations pacpi_ops = {
21055 .inherits = &ata_bmdma_port_ops,
21056 .qc_issue = pacpi_qc_issue,
21057 .cable_detect = pacpi_cable_detect,
21058 diff -urNp linux-2.6.37/drivers/ata/pata_ali.c linux-2.6.37/drivers/ata/pata_ali.c
21059 --- linux-2.6.37/drivers/ata/pata_ali.c 2011-01-04 19:50:19.000000000 -0500
21060 +++ linux-2.6.37/drivers/ata/pata_ali.c 2011-01-17 02:41:01.000000000 -0500
21061 @@ -363,7 +363,7 @@ static struct scsi_host_template ali_sht
21062 * Port operations for PIO only ALi
21063 */
21064
21065 -static struct ata_port_operations ali_early_port_ops = {
21066 +static const struct ata_port_operations ali_early_port_ops = {
21067 .inherits = &ata_sff_port_ops,
21068 .cable_detect = ata_cable_40wire,
21069 .set_piomode = ali_set_piomode,
21070 @@ -380,7 +380,7 @@ static const struct ata_port_operations
21071 * Port operations for DMA capable ALi without cable
21072 * detect
21073 */
21074 -static struct ata_port_operations ali_20_port_ops = {
21075 +static const struct ata_port_operations ali_20_port_ops = {
21076 .inherits = &ali_dma_base_ops,
21077 .cable_detect = ata_cable_40wire,
21078 .mode_filter = ali_20_filter,
21079 @@ -391,7 +391,7 @@ static struct ata_port_operations ali_20
21080 /*
21081 * Port operations for DMA capable ALi with cable detect
21082 */
21083 -static struct ata_port_operations ali_c2_port_ops = {
21084 +static const struct ata_port_operations ali_c2_port_ops = {
21085 .inherits = &ali_dma_base_ops,
21086 .check_atapi_dma = ali_check_atapi_dma,
21087 .cable_detect = ali_c2_cable_detect,
21088 @@ -402,7 +402,7 @@ static struct ata_port_operations ali_c2
21089 /*
21090 * Port operations for DMA capable ALi with cable detect
21091 */
21092 -static struct ata_port_operations ali_c4_port_ops = {
21093 +static const struct ata_port_operations ali_c4_port_ops = {
21094 .inherits = &ali_dma_base_ops,
21095 .check_atapi_dma = ali_check_atapi_dma,
21096 .cable_detect = ali_c2_cable_detect,
21097 @@ -412,7 +412,7 @@ static struct ata_port_operations ali_c4
21098 /*
21099 * Port operations for DMA capable ALi with cable detect and LBA48
21100 */
21101 -static struct ata_port_operations ali_c5_port_ops = {
21102 +static const struct ata_port_operations ali_c5_port_ops = {
21103 .inherits = &ali_dma_base_ops,
21104 .check_atapi_dma = ali_check_atapi_dma,
21105 .dev_config = ali_warn_atapi_dma,
21106 diff -urNp linux-2.6.37/drivers/ata/pata_amd.c linux-2.6.37/drivers/ata/pata_amd.c
21107 --- linux-2.6.37/drivers/ata/pata_amd.c 2011-01-04 19:50:19.000000000 -0500
21108 +++ linux-2.6.37/drivers/ata/pata_amd.c 2011-01-17 02:41:01.000000000 -0500
21109 @@ -397,28 +397,28 @@ static const struct ata_port_operations
21110 .prereset = amd_pre_reset,
21111 };
21112
21113 -static struct ata_port_operations amd33_port_ops = {
21114 +static const struct ata_port_operations amd33_port_ops = {
21115 .inherits = &amd_base_port_ops,
21116 .cable_detect = ata_cable_40wire,
21117 .set_piomode = amd33_set_piomode,
21118 .set_dmamode = amd33_set_dmamode,
21119 };
21120
21121 -static struct ata_port_operations amd66_port_ops = {
21122 +static const struct ata_port_operations amd66_port_ops = {
21123 .inherits = &amd_base_port_ops,
21124 .cable_detect = ata_cable_unknown,
21125 .set_piomode = amd66_set_piomode,
21126 .set_dmamode = amd66_set_dmamode,
21127 };
21128
21129 -static struct ata_port_operations amd100_port_ops = {
21130 +static const struct ata_port_operations amd100_port_ops = {
21131 .inherits = &amd_base_port_ops,
21132 .cable_detect = ata_cable_unknown,
21133 .set_piomode = amd100_set_piomode,
21134 .set_dmamode = amd100_set_dmamode,
21135 };
21136
21137 -static struct ata_port_operations amd133_port_ops = {
21138 +static const struct ata_port_operations amd133_port_ops = {
21139 .inherits = &amd_base_port_ops,
21140 .cable_detect = amd_cable_detect,
21141 .set_piomode = amd133_set_piomode,
21142 @@ -433,13 +433,13 @@ static const struct ata_port_operations
21143 .host_stop = nv_host_stop,
21144 };
21145
21146 -static struct ata_port_operations nv100_port_ops = {
21147 +static const struct ata_port_operations nv100_port_ops = {
21148 .inherits = &nv_base_port_ops,
21149 .set_piomode = nv100_set_piomode,
21150 .set_dmamode = nv100_set_dmamode,
21151 };
21152
21153 -static struct ata_port_operations nv133_port_ops = {
21154 +static const struct ata_port_operations nv133_port_ops = {
21155 .inherits = &nv_base_port_ops,
21156 .set_piomode = nv133_set_piomode,
21157 .set_dmamode = nv133_set_dmamode,
21158 diff -urNp linux-2.6.37/drivers/ata/pata_artop.c linux-2.6.37/drivers/ata/pata_artop.c
21159 --- linux-2.6.37/drivers/ata/pata_artop.c 2011-01-04 19:50:19.000000000 -0500
21160 +++ linux-2.6.37/drivers/ata/pata_artop.c 2011-01-17 02:41:01.000000000 -0500
21161 @@ -312,7 +312,7 @@ static struct scsi_host_template artop_s
21162 ATA_BMDMA_SHT(DRV_NAME),
21163 };
21164
21165 -static struct ata_port_operations artop6210_ops = {
21166 +static const struct ata_port_operations artop6210_ops = {
21167 .inherits = &ata_bmdma_port_ops,
21168 .cable_detect = ata_cable_40wire,
21169 .set_piomode = artop6210_set_piomode,
21170 @@ -321,7 +321,7 @@ static struct ata_port_operations artop6
21171 .qc_defer = artop6210_qc_defer,
21172 };
21173
21174 -static struct ata_port_operations artop6260_ops = {
21175 +static const struct ata_port_operations artop6260_ops = {
21176 .inherits = &ata_bmdma_port_ops,
21177 .cable_detect = artop6260_cable_detect,
21178 .set_piomode = artop6260_set_piomode,
21179 diff -urNp linux-2.6.37/drivers/ata/pata_at32.c linux-2.6.37/drivers/ata/pata_at32.c
21180 --- linux-2.6.37/drivers/ata/pata_at32.c 2011-01-04 19:50:19.000000000 -0500
21181 +++ linux-2.6.37/drivers/ata/pata_at32.c 2011-01-17 02:41:01.000000000 -0500
21182 @@ -173,7 +173,7 @@ static struct scsi_host_template at32_sh
21183 ATA_PIO_SHT(DRV_NAME),
21184 };
21185
21186 -static struct ata_port_operations at32_port_ops = {
21187 +static const struct ata_port_operations at32_port_ops = {
21188 .inherits = &ata_sff_port_ops,
21189 .cable_detect = ata_cable_40wire,
21190 .set_piomode = pata_at32_set_piomode,
21191 diff -urNp linux-2.6.37/drivers/ata/pata_at91.c linux-2.6.37/drivers/ata/pata_at91.c
21192 --- linux-2.6.37/drivers/ata/pata_at91.c 2011-01-04 19:50:19.000000000 -0500
21193 +++ linux-2.6.37/drivers/ata/pata_at91.c 2011-01-17 02:41:01.000000000 -0500
21194 @@ -196,7 +196,7 @@ static struct scsi_host_template pata_at
21195 ATA_PIO_SHT(DRV_NAME),
21196 };
21197
21198 -static struct ata_port_operations pata_at91_port_ops = {
21199 +static const struct ata_port_operations pata_at91_port_ops = {
21200 .inherits = &ata_sff_port_ops,
21201
21202 .sff_data_xfer = pata_at91_data_xfer_noirq,
21203 diff -urNp linux-2.6.37/drivers/ata/pata_atiixp.c linux-2.6.37/drivers/ata/pata_atiixp.c
21204 --- linux-2.6.37/drivers/ata/pata_atiixp.c 2011-01-04 19:50:19.000000000 -0500
21205 +++ linux-2.6.37/drivers/ata/pata_atiixp.c 2011-01-17 02:41:01.000000000 -0500
21206 @@ -214,7 +214,7 @@ static struct scsi_host_template atiixp_
21207 .sg_tablesize = LIBATA_DUMB_MAX_PRD,
21208 };
21209
21210 -static struct ata_port_operations atiixp_port_ops = {
21211 +static const struct ata_port_operations atiixp_port_ops = {
21212 .inherits = &ata_bmdma_port_ops,
21213
21214 .qc_prep = ata_bmdma_dumb_qc_prep,
21215 diff -urNp linux-2.6.37/drivers/ata/pata_atp867x.c linux-2.6.37/drivers/ata/pata_atp867x.c
21216 --- linux-2.6.37/drivers/ata/pata_atp867x.c 2011-01-04 19:50:19.000000000 -0500
21217 +++ linux-2.6.37/drivers/ata/pata_atp867x.c 2011-01-17 02:41:01.000000000 -0500
21218 @@ -275,7 +275,7 @@ static struct scsi_host_template atp867x
21219 ATA_BMDMA_SHT(DRV_NAME),
21220 };
21221
21222 -static struct ata_port_operations atp867x_ops = {
21223 +static const struct ata_port_operations atp867x_ops = {
21224 .inherits = &ata_bmdma_port_ops,
21225 .cable_detect = atp867x_cable_detect,
21226 .set_piomode = atp867x_set_piomode,
21227 diff -urNp linux-2.6.37/drivers/ata/pata_bf54x.c linux-2.6.37/drivers/ata/pata_bf54x.c
21228 --- linux-2.6.37/drivers/ata/pata_bf54x.c 2011-01-04 19:50:19.000000000 -0500
21229 +++ linux-2.6.37/drivers/ata/pata_bf54x.c 2011-01-17 02:41:01.000000000 -0500
21230 @@ -1420,7 +1420,7 @@ static struct scsi_host_template bfin_sh
21231 .dma_boundary = ATA_DMA_BOUNDARY,
21232 };
21233
21234 -static struct ata_port_operations bfin_pata_ops = {
21235 +static const struct ata_port_operations bfin_pata_ops = {
21236 .inherits = &ata_bmdma_port_ops,
21237
21238 .set_piomode = bfin_set_piomode,
21239 diff -urNp linux-2.6.37/drivers/ata/pata_cmd640.c linux-2.6.37/drivers/ata/pata_cmd640.c
21240 --- linux-2.6.37/drivers/ata/pata_cmd640.c 2011-01-04 19:50:19.000000000 -0500
21241 +++ linux-2.6.37/drivers/ata/pata_cmd640.c 2011-01-17 02:41:01.000000000 -0500
21242 @@ -176,7 +176,7 @@ static struct scsi_host_template cmd640_
21243 ATA_PIO_SHT(DRV_NAME),
21244 };
21245
21246 -static struct ata_port_operations cmd640_port_ops = {
21247 +static const struct ata_port_operations cmd640_port_ops = {
21248 .inherits = &ata_sff_port_ops,
21249 /* In theory xfer_noirq is not needed once we kill the prefetcher */
21250 .sff_data_xfer = ata_sff_data_xfer_noirq,
21251 diff -urNp linux-2.6.37/drivers/ata/pata_cmd64x.c linux-2.6.37/drivers/ata/pata_cmd64x.c
21252 --- linux-2.6.37/drivers/ata/pata_cmd64x.c 2011-01-04 19:50:19.000000000 -0500
21253 +++ linux-2.6.37/drivers/ata/pata_cmd64x.c 2011-01-17 02:41:01.000000000 -0500
21254 @@ -268,18 +268,18 @@ static const struct ata_port_operations
21255 .set_dmamode = cmd64x_set_dmamode,
21256 };
21257
21258 -static struct ata_port_operations cmd64x_port_ops = {
21259 +static const struct ata_port_operations cmd64x_port_ops = {
21260 .inherits = &cmd64x_base_ops,
21261 .cable_detect = ata_cable_40wire,
21262 };
21263
21264 -static struct ata_port_operations cmd646r1_port_ops = {
21265 +static const struct ata_port_operations cmd646r1_port_ops = {
21266 .inherits = &cmd64x_base_ops,
21267 .bmdma_stop = cmd646r1_bmdma_stop,
21268 .cable_detect = ata_cable_40wire,
21269 };
21270
21271 -static struct ata_port_operations cmd648_port_ops = {
21272 +static const struct ata_port_operations cmd648_port_ops = {
21273 .inherits = &cmd64x_base_ops,
21274 .bmdma_stop = cmd648_bmdma_stop,
21275 .cable_detect = cmd648_cable_detect,
21276 diff -urNp linux-2.6.37/drivers/ata/pata_cs5520.c linux-2.6.37/drivers/ata/pata_cs5520.c
21277 --- linux-2.6.37/drivers/ata/pata_cs5520.c 2011-01-04 19:50:19.000000000 -0500
21278 +++ linux-2.6.37/drivers/ata/pata_cs5520.c 2011-01-17 02:41:01.000000000 -0500
21279 @@ -108,7 +108,7 @@ static struct scsi_host_template cs5520_
21280 .sg_tablesize = LIBATA_DUMB_MAX_PRD,
21281 };
21282
21283 -static struct ata_port_operations cs5520_port_ops = {
21284 +static const struct ata_port_operations cs5520_port_ops = {
21285 .inherits = &ata_bmdma_port_ops,
21286 .qc_prep = ata_bmdma_dumb_qc_prep,
21287 .cable_detect = ata_cable_40wire,
21288 diff -urNp linux-2.6.37/drivers/ata/pata_cs5530.c linux-2.6.37/drivers/ata/pata_cs5530.c
21289 --- linux-2.6.37/drivers/ata/pata_cs5530.c 2011-01-04 19:50:19.000000000 -0500
21290 +++ linux-2.6.37/drivers/ata/pata_cs5530.c 2011-01-17 02:41:01.000000000 -0500
21291 @@ -164,7 +164,7 @@ static struct scsi_host_template cs5530_
21292 .sg_tablesize = LIBATA_DUMB_MAX_PRD,
21293 };
21294
21295 -static struct ata_port_operations cs5530_port_ops = {
21296 +static const struct ata_port_operations cs5530_port_ops = {
21297 .inherits = &ata_bmdma_port_ops,
21298
21299 .qc_prep = ata_bmdma_dumb_qc_prep,
21300 diff -urNp linux-2.6.37/drivers/ata/pata_cs5535.c linux-2.6.37/drivers/ata/pata_cs5535.c
21301 --- linux-2.6.37/drivers/ata/pata_cs5535.c 2011-01-04 19:50:19.000000000 -0500
21302 +++ linux-2.6.37/drivers/ata/pata_cs5535.c 2011-01-17 02:41:01.000000000 -0500
21303 @@ -160,7 +160,7 @@ static struct scsi_host_template cs5535_
21304 ATA_BMDMA_SHT(DRV_NAME),
21305 };
21306
21307 -static struct ata_port_operations cs5535_port_ops = {
21308 +static const struct ata_port_operations cs5535_port_ops = {
21309 .inherits = &ata_bmdma_port_ops,
21310 .cable_detect = cs5535_cable_detect,
21311 .set_piomode = cs5535_set_piomode,
21312 diff -urNp linux-2.6.37/drivers/ata/pata_cs5536.c linux-2.6.37/drivers/ata/pata_cs5536.c
21313 --- linux-2.6.37/drivers/ata/pata_cs5536.c 2011-01-04 19:50:19.000000000 -0500
21314 +++ linux-2.6.37/drivers/ata/pata_cs5536.c 2011-01-17 02:41:01.000000000 -0500
21315 @@ -233,7 +233,7 @@ static struct scsi_host_template cs5536_
21316 ATA_BMDMA_SHT(DRV_NAME),
21317 };
21318
21319 -static struct ata_port_operations cs5536_port_ops = {
21320 +static const struct ata_port_operations cs5536_port_ops = {
21321 .inherits = &ata_bmdma32_port_ops,
21322 .cable_detect = cs5536_cable_detect,
21323 .set_piomode = cs5536_set_piomode,
21324 diff -urNp linux-2.6.37/drivers/ata/pata_cypress.c linux-2.6.37/drivers/ata/pata_cypress.c
21325 --- linux-2.6.37/drivers/ata/pata_cypress.c 2011-01-04 19:50:19.000000000 -0500
21326 +++ linux-2.6.37/drivers/ata/pata_cypress.c 2011-01-17 02:41:01.000000000 -0500
21327 @@ -115,7 +115,7 @@ static struct scsi_host_template cy82c69
21328 ATA_BMDMA_SHT(DRV_NAME),
21329 };
21330
21331 -static struct ata_port_operations cy82c693_port_ops = {
21332 +static const struct ata_port_operations cy82c693_port_ops = {
21333 .inherits = &ata_bmdma_port_ops,
21334 .cable_detect = ata_cable_40wire,
21335 .set_piomode = cy82c693_set_piomode,
21336 diff -urNp linux-2.6.37/drivers/ata/pata_efar.c linux-2.6.37/drivers/ata/pata_efar.c
21337 --- linux-2.6.37/drivers/ata/pata_efar.c 2011-01-04 19:50:19.000000000 -0500
21338 +++ linux-2.6.37/drivers/ata/pata_efar.c 2011-01-17 02:41:01.000000000 -0500
21339 @@ -238,7 +238,7 @@ static struct scsi_host_template efar_sh
21340 ATA_BMDMA_SHT(DRV_NAME),
21341 };
21342
21343 -static struct ata_port_operations efar_ops = {
21344 +static const struct ata_port_operations efar_ops = {
21345 .inherits = &ata_bmdma_port_ops,
21346 .cable_detect = efar_cable_detect,
21347 .set_piomode = efar_set_piomode,
21348 diff -urNp linux-2.6.37/drivers/ata/pata_hpt366.c linux-2.6.37/drivers/ata/pata_hpt366.c
21349 --- linux-2.6.37/drivers/ata/pata_hpt366.c 2011-01-04 19:50:19.000000000 -0500
21350 +++ linux-2.6.37/drivers/ata/pata_hpt366.c 2011-01-17 02:41:01.000000000 -0500
21351 @@ -269,7 +269,7 @@ static struct scsi_host_template hpt36x_
21352 * Configuration for HPT366/68
21353 */
21354
21355 -static struct ata_port_operations hpt366_port_ops = {
21356 +static const struct ata_port_operations hpt366_port_ops = {
21357 .inherits = &ata_bmdma_port_ops,
21358 .cable_detect = hpt36x_cable_detect,
21359 .mode_filter = hpt366_filter,
21360 diff -urNp linux-2.6.37/drivers/ata/pata_hpt37x.c linux-2.6.37/drivers/ata/pata_hpt37x.c
21361 --- linux-2.6.37/drivers/ata/pata_hpt37x.c 2011-01-04 19:50:19.000000000 -0500
21362 +++ linux-2.6.37/drivers/ata/pata_hpt37x.c 2011-01-17 02:41:01.000000000 -0500
21363 @@ -564,7 +564,7 @@ static struct scsi_host_template hpt37x_
21364 * Configuration for HPT370
21365 */
21366
21367 -static struct ata_port_operations hpt370_port_ops = {
21368 +static const struct ata_port_operations hpt370_port_ops = {
21369 .inherits = &ata_bmdma_port_ops,
21370
21371 .bmdma_stop = hpt370_bmdma_stop,
21372 @@ -580,7 +580,7 @@ static struct ata_port_operations hpt370
21373 * Configuration for HPT370A. Close to 370 but less filters
21374 */
21375
21376 -static struct ata_port_operations hpt370a_port_ops = {
21377 +static const struct ata_port_operations hpt370a_port_ops = {
21378 .inherits = &hpt370_port_ops,
21379 .mode_filter = hpt370a_filter,
21380 };
21381 @@ -590,7 +590,7 @@ static struct ata_port_operations hpt370
21382 * and DMA mode setting functionality.
21383 */
21384
21385 -static struct ata_port_operations hpt372_port_ops = {
21386 +static const struct ata_port_operations hpt372_port_ops = {
21387 .inherits = &ata_bmdma_port_ops,
21388
21389 .bmdma_stop = hpt37x_bmdma_stop,
21390 @@ -606,7 +606,7 @@ static struct ata_port_operations hpt372
21391 * but we have a different cable detection procedure for function 1.
21392 */
21393
21394 -static struct ata_port_operations hpt374_fn1_port_ops = {
21395 +static const struct ata_port_operations hpt374_fn1_port_ops = {
21396 .inherits = &hpt372_port_ops,
21397 .cable_detect = hpt374_fn1_cable_detect,
21398 .prereset = hpt37x_pre_reset,
21399 diff -urNp linux-2.6.37/drivers/ata/pata_hpt3x2n.c linux-2.6.37/drivers/ata/pata_hpt3x2n.c
21400 --- linux-2.6.37/drivers/ata/pata_hpt3x2n.c 2011-01-04 19:50:19.000000000 -0500
21401 +++ linux-2.6.37/drivers/ata/pata_hpt3x2n.c 2011-01-17 02:41:01.000000000 -0500
21402 @@ -331,7 +331,7 @@ static struct scsi_host_template hpt3x2n
21403 * Configuration for HPT3x2n.
21404 */
21405
21406 -static struct ata_port_operations hpt3x2n_port_ops = {
21407 +static const struct ata_port_operations hpt3x2n_port_ops = {
21408 .inherits = &ata_bmdma_port_ops,
21409
21410 .bmdma_stop = hpt3x2n_bmdma_stop,
21411 diff -urNp linux-2.6.37/drivers/ata/pata_hpt3x3.c linux-2.6.37/drivers/ata/pata_hpt3x3.c
21412 --- linux-2.6.37/drivers/ata/pata_hpt3x3.c 2011-01-04 19:50:19.000000000 -0500
21413 +++ linux-2.6.37/drivers/ata/pata_hpt3x3.c 2011-01-17 02:41:01.000000000 -0500
21414 @@ -141,7 +141,7 @@ static struct scsi_host_template hpt3x3_
21415 ATA_BMDMA_SHT(DRV_NAME),
21416 };
21417
21418 -static struct ata_port_operations hpt3x3_port_ops = {
21419 +static const struct ata_port_operations hpt3x3_port_ops = {
21420 .inherits = &ata_bmdma_port_ops,
21421 .cable_detect = ata_cable_40wire,
21422 .set_piomode = hpt3x3_set_piomode,
21423 diff -urNp linux-2.6.37/drivers/ata/pata_icside.c linux-2.6.37/drivers/ata/pata_icside.c
21424 --- linux-2.6.37/drivers/ata/pata_icside.c 2011-01-04 19:50:19.000000000 -0500
21425 +++ linux-2.6.37/drivers/ata/pata_icside.c 2011-01-17 02:41:01.000000000 -0500
21426 @@ -320,7 +320,7 @@ static void pata_icside_postreset(struct
21427 }
21428 }
21429
21430 -static struct ata_port_operations pata_icside_port_ops = {
21431 +static const struct ata_port_operations pata_icside_port_ops = {
21432 .inherits = &ata_bmdma_port_ops,
21433 /* no need to build any PRD tables for DMA */
21434 .qc_prep = ata_noop_qc_prep,
21435 diff -urNp linux-2.6.37/drivers/ata/pata_isapnp.c linux-2.6.37/drivers/ata/pata_isapnp.c
21436 --- linux-2.6.37/drivers/ata/pata_isapnp.c 2011-01-04 19:50:19.000000000 -0500
21437 +++ linux-2.6.37/drivers/ata/pata_isapnp.c 2011-01-17 02:41:01.000000000 -0500
21438 @@ -23,12 +23,12 @@ static struct scsi_host_template isapnp_
21439 ATA_PIO_SHT(DRV_NAME),
21440 };
21441
21442 -static struct ata_port_operations isapnp_port_ops = {
21443 +static const struct ata_port_operations isapnp_port_ops = {
21444 .inherits = &ata_sff_port_ops,
21445 .cable_detect = ata_cable_40wire,
21446 };
21447
21448 -static struct ata_port_operations isapnp_noalt_port_ops = {
21449 +static const struct ata_port_operations isapnp_noalt_port_ops = {
21450 .inherits = &ata_sff_port_ops,
21451 .cable_detect = ata_cable_40wire,
21452 /* No altstatus so we don't want to use the lost interrupt poll */
21453 diff -urNp linux-2.6.37/drivers/ata/pata_it8213.c linux-2.6.37/drivers/ata/pata_it8213.c
21454 --- linux-2.6.37/drivers/ata/pata_it8213.c 2011-01-04 19:50:19.000000000 -0500
21455 +++ linux-2.6.37/drivers/ata/pata_it8213.c 2011-01-17 02:41:01.000000000 -0500
21456 @@ -233,7 +233,7 @@ static struct scsi_host_template it8213_
21457 };
21458
21459
21460 -static struct ata_port_operations it8213_ops = {
21461 +static const struct ata_port_operations it8213_ops = {
21462 .inherits = &ata_bmdma_port_ops,
21463 .cable_detect = it8213_cable_detect,
21464 .set_piomode = it8213_set_piomode,
21465 diff -urNp linux-2.6.37/drivers/ata/pata_it821x.c linux-2.6.37/drivers/ata/pata_it821x.c
21466 --- linux-2.6.37/drivers/ata/pata_it821x.c 2011-01-04 19:50:19.000000000 -0500
21467 +++ linux-2.6.37/drivers/ata/pata_it821x.c 2011-01-17 02:41:01.000000000 -0500
21468 @@ -801,7 +801,7 @@ static struct scsi_host_template it821x_
21469 ATA_BMDMA_SHT(DRV_NAME),
21470 };
21471
21472 -static struct ata_port_operations it821x_smart_port_ops = {
21473 +static const struct ata_port_operations it821x_smart_port_ops = {
21474 .inherits = &ata_bmdma_port_ops,
21475
21476 .check_atapi_dma= it821x_check_atapi_dma,
21477 @@ -815,7 +815,7 @@ static struct ata_port_operations it821x
21478 .port_start = it821x_port_start,
21479 };
21480
21481 -static struct ata_port_operations it821x_passthru_port_ops = {
21482 +static const struct ata_port_operations it821x_passthru_port_ops = {
21483 .inherits = &ata_bmdma_port_ops,
21484
21485 .check_atapi_dma= it821x_check_atapi_dma,
21486 @@ -831,7 +831,7 @@ static struct ata_port_operations it821x
21487 .port_start = it821x_port_start,
21488 };
21489
21490 -static struct ata_port_operations it821x_rdc_port_ops = {
21491 +static const struct ata_port_operations it821x_rdc_port_ops = {
21492 .inherits = &ata_bmdma_port_ops,
21493
21494 .check_atapi_dma= it821x_check_atapi_dma,
21495 diff -urNp linux-2.6.37/drivers/ata/pata_ixp4xx_cf.c linux-2.6.37/drivers/ata/pata_ixp4xx_cf.c
21496 --- linux-2.6.37/drivers/ata/pata_ixp4xx_cf.c 2011-01-04 19:50:19.000000000 -0500
21497 +++ linux-2.6.37/drivers/ata/pata_ixp4xx_cf.c 2011-01-17 02:41:01.000000000 -0500
21498 @@ -89,7 +89,7 @@ static struct scsi_host_template ixp4xx_
21499 ATA_PIO_SHT(DRV_NAME),
21500 };
21501
21502 -static struct ata_port_operations ixp4xx_port_ops = {
21503 +static const struct ata_port_operations ixp4xx_port_ops = {
21504 .inherits = &ata_sff_port_ops,
21505 .sff_data_xfer = ixp4xx_mmio_data_xfer,
21506 .cable_detect = ata_cable_40wire,
21507 diff -urNp linux-2.6.37/drivers/ata/pata_jmicron.c linux-2.6.37/drivers/ata/pata_jmicron.c
21508 --- linux-2.6.37/drivers/ata/pata_jmicron.c 2011-01-04 19:50:19.000000000 -0500
21509 +++ linux-2.6.37/drivers/ata/pata_jmicron.c 2011-01-17 02:41:01.000000000 -0500
21510 @@ -111,7 +111,7 @@ static struct scsi_host_template jmicron
21511 ATA_BMDMA_SHT(DRV_NAME),
21512 };
21513
21514 -static struct ata_port_operations jmicron_ops = {
21515 +static const struct ata_port_operations jmicron_ops = {
21516 .inherits = &ata_bmdma_port_ops,
21517 .prereset = jmicron_pre_reset,
21518 };
21519 diff -urNp linux-2.6.37/drivers/ata/pata_legacy.c linux-2.6.37/drivers/ata/pata_legacy.c
21520 --- linux-2.6.37/drivers/ata/pata_legacy.c 2011-01-04 19:50:19.000000000 -0500
21521 +++ linux-2.6.37/drivers/ata/pata_legacy.c 2011-01-17 02:41:01.000000000 -0500
21522 @@ -116,7 +116,7 @@ struct legacy_probe {
21523
21524 struct legacy_controller {
21525 const char *name;
21526 - struct ata_port_operations *ops;
21527 + const struct ata_port_operations *ops;
21528 unsigned int pio_mask;
21529 unsigned int flags;
21530 unsigned int pflags;
21531 @@ -239,12 +239,12 @@ static const struct ata_port_operations
21532 * pio_mask as well.
21533 */
21534
21535 -static struct ata_port_operations simple_port_ops = {
21536 +static const struct ata_port_operations simple_port_ops = {
21537 .inherits = &legacy_base_port_ops,
21538 .sff_data_xfer = ata_sff_data_xfer_noirq,
21539 };
21540
21541 -static struct ata_port_operations legacy_port_ops = {
21542 +static const struct ata_port_operations legacy_port_ops = {
21543 .inherits = &legacy_base_port_ops,
21544 .sff_data_xfer = ata_sff_data_xfer_noirq,
21545 .set_mode = legacy_set_mode,
21546 @@ -340,7 +340,7 @@ static unsigned int pdc_data_xfer_vlb(st
21547 return buflen;
21548 }
21549
21550 -static struct ata_port_operations pdc20230_port_ops = {
21551 +static const struct ata_port_operations pdc20230_port_ops = {
21552 .inherits = &legacy_base_port_ops,
21553 .set_piomode = pdc20230_set_piomode,
21554 .sff_data_xfer = pdc_data_xfer_vlb,
21555 @@ -373,7 +373,7 @@ static void ht6560a_set_piomode(struct a
21556 ioread8(ap->ioaddr.status_addr);
21557 }
21558
21559 -static struct ata_port_operations ht6560a_port_ops = {
21560 +static const struct ata_port_operations ht6560a_port_ops = {
21561 .inherits = &legacy_base_port_ops,
21562 .set_piomode = ht6560a_set_piomode,
21563 };
21564 @@ -416,7 +416,7 @@ static void ht6560b_set_piomode(struct a
21565 ioread8(ap->ioaddr.status_addr);
21566 }
21567
21568 -static struct ata_port_operations ht6560b_port_ops = {
21569 +static const struct ata_port_operations ht6560b_port_ops = {
21570 .inherits = &legacy_base_port_ops,
21571 .set_piomode = ht6560b_set_piomode,
21572 };
21573 @@ -515,7 +515,7 @@ static void opti82c611a_set_piomode(stru
21574 }
21575
21576
21577 -static struct ata_port_operations opti82c611a_port_ops = {
21578 +static const struct ata_port_operations opti82c611a_port_ops = {
21579 .inherits = &legacy_base_port_ops,
21580 .set_piomode = opti82c611a_set_piomode,
21581 };
21582 @@ -625,7 +625,7 @@ static unsigned int opti82c46x_qc_issue(
21583 return ata_sff_qc_issue(qc);
21584 }
21585
21586 -static struct ata_port_operations opti82c46x_port_ops = {
21587 +static const struct ata_port_operations opti82c46x_port_ops = {
21588 .inherits = &legacy_base_port_ops,
21589 .set_piomode = opti82c46x_set_piomode,
21590 .qc_issue = opti82c46x_qc_issue,
21591 @@ -787,20 +787,20 @@ static int qdi_port(struct platform_devi
21592 return 0;
21593 }
21594
21595 -static struct ata_port_operations qdi6500_port_ops = {
21596 +static const struct ata_port_operations qdi6500_port_ops = {
21597 .inherits = &legacy_base_port_ops,
21598 .set_piomode = qdi6500_set_piomode,
21599 .qc_issue = qdi_qc_issue,
21600 .sff_data_xfer = vlb32_data_xfer,
21601 };
21602
21603 -static struct ata_port_operations qdi6580_port_ops = {
21604 +static const struct ata_port_operations qdi6580_port_ops = {
21605 .inherits = &legacy_base_port_ops,
21606 .set_piomode = qdi6580_set_piomode,
21607 .sff_data_xfer = vlb32_data_xfer,
21608 };
21609
21610 -static struct ata_port_operations qdi6580dp_port_ops = {
21611 +static const struct ata_port_operations qdi6580dp_port_ops = {
21612 .inherits = &legacy_base_port_ops,
21613 .set_piomode = qdi6580dp_set_piomode,
21614 .qc_issue = qdi_qc_issue,
21615 @@ -872,7 +872,7 @@ static int winbond_port(struct platform_
21616 return 0;
21617 }
21618
21619 -static struct ata_port_operations winbond_port_ops = {
21620 +static const struct ata_port_operations winbond_port_ops = {
21621 .inherits = &legacy_base_port_ops,
21622 .set_piomode = winbond_set_piomode,
21623 .sff_data_xfer = vlb32_data_xfer,
21624 @@ -995,7 +995,7 @@ static __init int legacy_init_one(struct
21625 int pio_modes = controller->pio_mask;
21626 unsigned long io = probe->port;
21627 u32 mask = (1 << probe->slot);
21628 - struct ata_port_operations *ops = controller->ops;
21629 + const struct ata_port_operations *ops = controller->ops;
21630 struct legacy_data *ld = &legacy_data[probe->slot];
21631 struct ata_host *host = NULL;
21632 struct ata_port *ap;
21633 diff -urNp linux-2.6.37/drivers/ata/pata_macio.c linux-2.6.37/drivers/ata/pata_macio.c
21634 --- linux-2.6.37/drivers/ata/pata_macio.c 2011-01-04 19:50:19.000000000 -0500
21635 +++ linux-2.6.37/drivers/ata/pata_macio.c 2011-01-17 02:41:01.000000000 -0500
21636 @@ -918,9 +918,8 @@ static struct scsi_host_template pata_ma
21637 .slave_configure = pata_macio_slave_config,
21638 };
21639
21640 -static struct ata_port_operations pata_macio_ops = {
21641 +static const struct ata_port_operations pata_macio_ops = {
21642 .inherits = &ata_bmdma_port_ops,
21643 -
21644 .freeze = pata_macio_freeze,
21645 .set_piomode = pata_macio_set_timings,
21646 .set_dmamode = pata_macio_set_timings,
21647 diff -urNp linux-2.6.37/drivers/ata/pata_marvell.c linux-2.6.37/drivers/ata/pata_marvell.c
21648 --- linux-2.6.37/drivers/ata/pata_marvell.c 2011-01-04 19:50:19.000000000 -0500
21649 +++ linux-2.6.37/drivers/ata/pata_marvell.c 2011-01-17 02:41:01.000000000 -0500
21650 @@ -100,7 +100,7 @@ static struct scsi_host_template marvell
21651 ATA_BMDMA_SHT(DRV_NAME),
21652 };
21653
21654 -static struct ata_port_operations marvell_ops = {
21655 +static const struct ata_port_operations marvell_ops = {
21656 .inherits = &ata_bmdma_port_ops,
21657 .cable_detect = marvell_cable_detect,
21658 .prereset = marvell_pre_reset,
21659 diff -urNp linux-2.6.37/drivers/ata/pata_mpc52xx.c linux-2.6.37/drivers/ata/pata_mpc52xx.c
21660 --- linux-2.6.37/drivers/ata/pata_mpc52xx.c 2011-01-04 19:50:19.000000000 -0500
21661 +++ linux-2.6.37/drivers/ata/pata_mpc52xx.c 2011-01-17 02:41:01.000000000 -0500
21662 @@ -609,7 +609,7 @@ static struct scsi_host_template mpc52xx
21663 ATA_PIO_SHT(DRV_NAME),
21664 };
21665
21666 -static struct ata_port_operations mpc52xx_ata_port_ops = {
21667 +static const struct ata_port_operations mpc52xx_ata_port_ops = {
21668 .inherits = &ata_sff_port_ops,
21669 .sff_dev_select = mpc52xx_ata_dev_select,
21670 .set_piomode = mpc52xx_ata_set_piomode,
21671 diff -urNp linux-2.6.37/drivers/ata/pata_mpiix.c linux-2.6.37/drivers/ata/pata_mpiix.c
21672 --- linux-2.6.37/drivers/ata/pata_mpiix.c 2011-01-04 19:50:19.000000000 -0500
21673 +++ linux-2.6.37/drivers/ata/pata_mpiix.c 2011-01-17 02:41:01.000000000 -0500
21674 @@ -140,7 +140,7 @@ static struct scsi_host_template mpiix_s
21675 ATA_PIO_SHT(DRV_NAME),
21676 };
21677
21678 -static struct ata_port_operations mpiix_port_ops = {
21679 +static const struct ata_port_operations mpiix_port_ops = {
21680 .inherits = &ata_sff_port_ops,
21681 .qc_issue = mpiix_qc_issue,
21682 .cable_detect = ata_cable_40wire,
21683 diff -urNp linux-2.6.37/drivers/ata/pata_netcell.c linux-2.6.37/drivers/ata/pata_netcell.c
21684 --- linux-2.6.37/drivers/ata/pata_netcell.c 2011-01-04 19:50:19.000000000 -0500
21685 +++ linux-2.6.37/drivers/ata/pata_netcell.c 2011-01-17 02:41:01.000000000 -0500
21686 @@ -34,7 +34,7 @@ static struct scsi_host_template netcell
21687 ATA_BMDMA_SHT(DRV_NAME),
21688 };
21689
21690 -static struct ata_port_operations netcell_ops = {
21691 +static const struct ata_port_operations netcell_ops = {
21692 .inherits = &ata_bmdma_port_ops,
21693 .cable_detect = ata_cable_80wire,
21694 .read_id = netcell_read_id,
21695 diff -urNp linux-2.6.37/drivers/ata/pata_ninja32.c linux-2.6.37/drivers/ata/pata_ninja32.c
21696 --- linux-2.6.37/drivers/ata/pata_ninja32.c 2011-01-04 19:50:19.000000000 -0500
21697 +++ linux-2.6.37/drivers/ata/pata_ninja32.c 2011-01-17 02:41:01.000000000 -0500
21698 @@ -81,7 +81,7 @@ static struct scsi_host_template ninja32
21699 ATA_BMDMA_SHT(DRV_NAME),
21700 };
21701
21702 -static struct ata_port_operations ninja32_port_ops = {
21703 +static const struct ata_port_operations ninja32_port_ops = {
21704 .inherits = &ata_bmdma_port_ops,
21705 .sff_dev_select = ninja32_dev_select,
21706 .cable_detect = ata_cable_40wire,
21707 diff -urNp linux-2.6.37/drivers/ata/pata_ns87410.c linux-2.6.37/drivers/ata/pata_ns87410.c
21708 --- linux-2.6.37/drivers/ata/pata_ns87410.c 2011-01-04 19:50:19.000000000 -0500
21709 +++ linux-2.6.37/drivers/ata/pata_ns87410.c 2011-01-17 02:41:01.000000000 -0500
21710 @@ -132,7 +132,7 @@ static struct scsi_host_template ns87410
21711 ATA_PIO_SHT(DRV_NAME),
21712 };
21713
21714 -static struct ata_port_operations ns87410_port_ops = {
21715 +static const struct ata_port_operations ns87410_port_ops = {
21716 .inherits = &ata_sff_port_ops,
21717 .qc_issue = ns87410_qc_issue,
21718 .cable_detect = ata_cable_40wire,
21719 diff -urNp linux-2.6.37/drivers/ata/pata_ns87415.c linux-2.6.37/drivers/ata/pata_ns87415.c
21720 --- linux-2.6.37/drivers/ata/pata_ns87415.c 2011-01-04 19:50:19.000000000 -0500
21721 +++ linux-2.6.37/drivers/ata/pata_ns87415.c 2011-01-17 02:41:01.000000000 -0500
21722 @@ -299,7 +299,7 @@ static u8 ns87560_bmdma_status(struct at
21723 }
21724 #endif /* 87560 SuperIO Support */
21725
21726 -static struct ata_port_operations ns87415_pata_ops = {
21727 +static const struct ata_port_operations ns87415_pata_ops = {
21728 .inherits = &ata_bmdma_port_ops,
21729
21730 .check_atapi_dma = ns87415_check_atapi_dma,
21731 @@ -313,7 +313,7 @@ static struct ata_port_operations ns8741
21732 };
21733
21734 #if defined(CONFIG_SUPERIO)
21735 -static struct ata_port_operations ns87560_pata_ops = {
21736 +static const struct ata_port_operations ns87560_pata_ops = {
21737 .inherits = &ns87415_pata_ops,
21738 .sff_tf_read = ns87560_tf_read,
21739 .sff_check_status = ns87560_check_status,
21740 diff -urNp linux-2.6.37/drivers/ata/pata_octeon_cf.c linux-2.6.37/drivers/ata/pata_octeon_cf.c
21741 --- linux-2.6.37/drivers/ata/pata_octeon_cf.c 2011-01-04 19:50:19.000000000 -0500
21742 +++ linux-2.6.37/drivers/ata/pata_octeon_cf.c 2011-01-17 02:41:01.000000000 -0500
21743 @@ -780,6 +780,7 @@ static unsigned int octeon_cf_qc_issue(s
21744 return 0;
21745 }
21746
21747 +/* cannot be const */
21748 static struct ata_port_operations octeon_cf_ops = {
21749 .inherits = &ata_sff_port_ops,
21750 .check_atapi_dma = octeon_cf_check_atapi_dma,
21751 diff -urNp linux-2.6.37/drivers/ata/pata_oldpiix.c linux-2.6.37/drivers/ata/pata_oldpiix.c
21752 --- linux-2.6.37/drivers/ata/pata_oldpiix.c 2011-01-04 19:50:19.000000000 -0500
21753 +++ linux-2.6.37/drivers/ata/pata_oldpiix.c 2011-01-17 02:41:01.000000000 -0500
21754 @@ -208,7 +208,7 @@ static struct scsi_host_template oldpiix
21755 ATA_BMDMA_SHT(DRV_NAME),
21756 };
21757
21758 -static struct ata_port_operations oldpiix_pata_ops = {
21759 +static const struct ata_port_operations oldpiix_pata_ops = {
21760 .inherits = &ata_bmdma_port_ops,
21761 .qc_issue = oldpiix_qc_issue,
21762 .cable_detect = ata_cable_40wire,
21763 diff -urNp linux-2.6.37/drivers/ata/pata_opti.c linux-2.6.37/drivers/ata/pata_opti.c
21764 --- linux-2.6.37/drivers/ata/pata_opti.c 2011-01-04 19:50:19.000000000 -0500
21765 +++ linux-2.6.37/drivers/ata/pata_opti.c 2011-01-17 02:41:01.000000000 -0500
21766 @@ -152,7 +152,7 @@ static struct scsi_host_template opti_sh
21767 ATA_PIO_SHT(DRV_NAME),
21768 };
21769
21770 -static struct ata_port_operations opti_port_ops = {
21771 +static const struct ata_port_operations opti_port_ops = {
21772 .inherits = &ata_sff_port_ops,
21773 .cable_detect = ata_cable_40wire,
21774 .set_piomode = opti_set_piomode,
21775 diff -urNp linux-2.6.37/drivers/ata/pata_optidma.c linux-2.6.37/drivers/ata/pata_optidma.c
21776 --- linux-2.6.37/drivers/ata/pata_optidma.c 2011-01-04 19:50:19.000000000 -0500
21777 +++ linux-2.6.37/drivers/ata/pata_optidma.c 2011-01-17 02:41:01.000000000 -0500
21778 @@ -337,7 +337,7 @@ static struct scsi_host_template optidma
21779 ATA_BMDMA_SHT(DRV_NAME),
21780 };
21781
21782 -static struct ata_port_operations optidma_port_ops = {
21783 +static const struct ata_port_operations optidma_port_ops = {
21784 .inherits = &ata_bmdma_port_ops,
21785 .cable_detect = ata_cable_40wire,
21786 .set_piomode = optidma_set_pio_mode,
21787 @@ -346,7 +346,7 @@ static struct ata_port_operations optidm
21788 .prereset = optidma_pre_reset,
21789 };
21790
21791 -static struct ata_port_operations optiplus_port_ops = {
21792 +static const struct ata_port_operations optiplus_port_ops = {
21793 .inherits = &optidma_port_ops,
21794 .set_piomode = optiplus_set_pio_mode,
21795 .set_dmamode = optiplus_set_dma_mode,
21796 diff -urNp linux-2.6.37/drivers/ata/pata_palmld.c linux-2.6.37/drivers/ata/pata_palmld.c
21797 --- linux-2.6.37/drivers/ata/pata_palmld.c 2011-01-04 19:50:19.000000000 -0500
21798 +++ linux-2.6.37/drivers/ata/pata_palmld.c 2011-01-17 02:41:01.000000000 -0500
21799 @@ -37,7 +37,7 @@ static struct scsi_host_template palmld_
21800 ATA_PIO_SHT(DRV_NAME),
21801 };
21802
21803 -static struct ata_port_operations palmld_port_ops = {
21804 +static const struct ata_port_operations palmld_port_ops = {
21805 .inherits = &ata_sff_port_ops,
21806 .sff_data_xfer = ata_sff_data_xfer_noirq,
21807 .cable_detect = ata_cable_40wire,
21808 diff -urNp linux-2.6.37/drivers/ata/pata_pcmcia.c linux-2.6.37/drivers/ata/pata_pcmcia.c
21809 --- linux-2.6.37/drivers/ata/pata_pcmcia.c 2011-01-04 19:50:19.000000000 -0500
21810 +++ linux-2.6.37/drivers/ata/pata_pcmcia.c 2011-01-17 02:41:01.000000000 -0500
21811 @@ -151,14 +151,14 @@ static struct scsi_host_template pcmcia_
21812 ATA_PIO_SHT(DRV_NAME),
21813 };
21814
21815 -static struct ata_port_operations pcmcia_port_ops = {
21816 +static const struct ata_port_operations pcmcia_port_ops = {
21817 .inherits = &ata_sff_port_ops,
21818 .sff_data_xfer = ata_sff_data_xfer_noirq,
21819 .cable_detect = ata_cable_40wire,
21820 .set_mode = pcmcia_set_mode,
21821 };
21822
21823 -static struct ata_port_operations pcmcia_8bit_port_ops = {
21824 +static const struct ata_port_operations pcmcia_8bit_port_ops = {
21825 .inherits = &ata_sff_port_ops,
21826 .sff_data_xfer = ata_data_xfer_8bit,
21827 .cable_detect = ata_cable_40wire,
21828 @@ -205,7 +205,7 @@ static int pcmcia_init_one(struct pcmcia
21829 unsigned long io_base, ctl_base;
21830 void __iomem *io_addr, *ctl_addr;
21831 int n_ports = 1;
21832 - struct ata_port_operations *ops = &pcmcia_port_ops;
21833 + const struct ata_port_operations *ops = &pcmcia_port_ops;
21834
21835 /* Set up attributes in order to probe card and get resources */
21836 pdev->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IO |
21837 diff -urNp linux-2.6.37/drivers/ata/pata_pdc2027x.c linux-2.6.37/drivers/ata/pata_pdc2027x.c
21838 --- linux-2.6.37/drivers/ata/pata_pdc2027x.c 2011-01-04 19:50:19.000000000 -0500
21839 +++ linux-2.6.37/drivers/ata/pata_pdc2027x.c 2011-01-17 02:41:01.000000000 -0500
21840 @@ -132,14 +132,14 @@ static struct scsi_host_template pdc2027
21841 ATA_BMDMA_SHT(DRV_NAME),
21842 };
21843
21844 -static struct ata_port_operations pdc2027x_pata100_ops = {
21845 +static const struct ata_port_operations pdc2027x_pata100_ops = {
21846 .inherits = &ata_bmdma_port_ops,
21847 .check_atapi_dma = pdc2027x_check_atapi_dma,
21848 .cable_detect = pdc2027x_cable_detect,
21849 .prereset = pdc2027x_prereset,
21850 };
21851
21852 -static struct ata_port_operations pdc2027x_pata133_ops = {
21853 +static const struct ata_port_operations pdc2027x_pata133_ops = {
21854 .inherits = &pdc2027x_pata100_ops,
21855 .mode_filter = pdc2027x_mode_filter,
21856 .set_piomode = pdc2027x_set_piomode,
21857 diff -urNp linux-2.6.37/drivers/ata/pata_pdc202xx_old.c linux-2.6.37/drivers/ata/pata_pdc202xx_old.c
21858 --- linux-2.6.37/drivers/ata/pata_pdc202xx_old.c 2011-01-04 19:50:19.000000000 -0500
21859 +++ linux-2.6.37/drivers/ata/pata_pdc202xx_old.c 2011-01-17 02:41:01.000000000 -0500
21860 @@ -295,7 +295,7 @@ static struct scsi_host_template pdc202x
21861 ATA_BMDMA_SHT(DRV_NAME),
21862 };
21863
21864 -static struct ata_port_operations pdc2024x_port_ops = {
21865 +static const struct ata_port_operations pdc2024x_port_ops = {
21866 .inherits = &ata_bmdma_port_ops,
21867
21868 .cable_detect = ata_cable_40wire,
21869 @@ -306,7 +306,7 @@ static struct ata_port_operations pdc202
21870 .sff_irq_check = pdc202xx_irq_check,
21871 };
21872
21873 -static struct ata_port_operations pdc2026x_port_ops = {
21874 +static const struct ata_port_operations pdc2026x_port_ops = {
21875 .inherits = &pdc2024x_port_ops,
21876
21877 .check_atapi_dma = pdc2026x_check_atapi_dma,
21878 diff -urNp linux-2.6.37/drivers/ata/pata_piccolo.c linux-2.6.37/drivers/ata/pata_piccolo.c
21879 --- linux-2.6.37/drivers/ata/pata_piccolo.c 2011-01-04 19:50:19.000000000 -0500
21880 +++ linux-2.6.37/drivers/ata/pata_piccolo.c 2011-01-17 02:41:01.000000000 -0500
21881 @@ -67,7 +67,7 @@ static struct scsi_host_template tosh_sh
21882 ATA_BMDMA_SHT(DRV_NAME),
21883 };
21884
21885 -static struct ata_port_operations tosh_port_ops = {
21886 +static const struct ata_port_operations tosh_port_ops = {
21887 .inherits = &ata_bmdma_port_ops,
21888 .cable_detect = ata_cable_unknown,
21889 .set_piomode = tosh_set_piomode,
21890 diff -urNp linux-2.6.37/drivers/ata/pata_platform.c linux-2.6.37/drivers/ata/pata_platform.c
21891 --- linux-2.6.37/drivers/ata/pata_platform.c 2011-01-04 19:50:19.000000000 -0500
21892 +++ linux-2.6.37/drivers/ata/pata_platform.c 2011-01-17 02:41:01.000000000 -0500
21893 @@ -48,7 +48,7 @@ static struct scsi_host_template pata_pl
21894 ATA_PIO_SHT(DRV_NAME),
21895 };
21896
21897 -static struct ata_port_operations pata_platform_port_ops = {
21898 +static const struct ata_port_operations pata_platform_port_ops = {
21899 .inherits = &ata_sff_port_ops,
21900 .sff_data_xfer = ata_sff_data_xfer_noirq,
21901 .cable_detect = ata_cable_unknown,
21902 diff -urNp linux-2.6.37/drivers/ata/pata_pxa.c linux-2.6.37/drivers/ata/pata_pxa.c
21903 --- linux-2.6.37/drivers/ata/pata_pxa.c 2011-01-04 19:50:19.000000000 -0500
21904 +++ linux-2.6.37/drivers/ata/pata_pxa.c 2011-01-17 02:41:01.000000000 -0500
21905 @@ -198,7 +198,7 @@ static struct scsi_host_template pxa_ata
21906 ATA_BMDMA_SHT(DRV_NAME),
21907 };
21908
21909 -static struct ata_port_operations pxa_ata_port_ops = {
21910 +static const struct ata_port_operations pxa_ata_port_ops = {
21911 .inherits = &ata_bmdma_port_ops,
21912 .cable_detect = ata_cable_40wire,
21913
21914 diff -urNp linux-2.6.37/drivers/ata/pata_qdi.c linux-2.6.37/drivers/ata/pata_qdi.c
21915 --- linux-2.6.37/drivers/ata/pata_qdi.c 2011-01-04 19:50:19.000000000 -0500
21916 +++ linux-2.6.37/drivers/ata/pata_qdi.c 2011-01-17 02:41:01.000000000 -0500
21917 @@ -157,7 +157,7 @@ static struct scsi_host_template qdi_sht
21918 ATA_PIO_SHT(DRV_NAME),
21919 };
21920
21921 -static struct ata_port_operations qdi6500_port_ops = {
21922 +static const struct ata_port_operations qdi6500_port_ops = {
21923 .inherits = &ata_sff_port_ops,
21924 .qc_issue = qdi_qc_issue,
21925 .sff_data_xfer = qdi_data_xfer,
21926 @@ -165,7 +165,7 @@ static struct ata_port_operations qdi650
21927 .set_piomode = qdi6500_set_piomode,
21928 };
21929
21930 -static struct ata_port_operations qdi6580_port_ops = {
21931 +static const struct ata_port_operations qdi6580_port_ops = {
21932 .inherits = &qdi6500_port_ops,
21933 .set_piomode = qdi6580_set_piomode,
21934 };
21935 diff -urNp linux-2.6.37/drivers/ata/pata_radisys.c linux-2.6.37/drivers/ata/pata_radisys.c
21936 --- linux-2.6.37/drivers/ata/pata_radisys.c 2011-01-04 19:50:19.000000000 -0500
21937 +++ linux-2.6.37/drivers/ata/pata_radisys.c 2011-01-17 02:41:01.000000000 -0500
21938 @@ -187,7 +187,7 @@ static struct scsi_host_template radisys
21939 ATA_BMDMA_SHT(DRV_NAME),
21940 };
21941
21942 -static struct ata_port_operations radisys_pata_ops = {
21943 +static const struct ata_port_operations radisys_pata_ops = {
21944 .inherits = &ata_bmdma_port_ops,
21945 .qc_issue = radisys_qc_issue,
21946 .cable_detect = ata_cable_unknown,
21947 diff -urNp linux-2.6.37/drivers/ata/pata_rb532_cf.c linux-2.6.37/drivers/ata/pata_rb532_cf.c
21948 --- linux-2.6.37/drivers/ata/pata_rb532_cf.c 2011-01-04 19:50:19.000000000 -0500
21949 +++ linux-2.6.37/drivers/ata/pata_rb532_cf.c 2011-01-17 02:41:01.000000000 -0500
21950 @@ -69,7 +69,7 @@ static irqreturn_t rb532_pata_irq_handle
21951 return IRQ_HANDLED;
21952 }
21953
21954 -static struct ata_port_operations rb532_pata_port_ops = {
21955 +static const struct ata_port_operations rb532_pata_port_ops = {
21956 .inherits = &ata_sff_port_ops,
21957 .sff_data_xfer = ata_sff_data_xfer32,
21958 };
21959 diff -urNp linux-2.6.37/drivers/ata/pata_rdc.c linux-2.6.37/drivers/ata/pata_rdc.c
21960 --- linux-2.6.37/drivers/ata/pata_rdc.c 2011-01-04 19:50:19.000000000 -0500
21961 +++ linux-2.6.37/drivers/ata/pata_rdc.c 2011-01-17 02:41:01.000000000 -0500
21962 @@ -273,7 +273,7 @@ static void rdc_set_dmamode(struct ata_p
21963 pci_write_config_byte(dev, 0x48, udma_enable);
21964 }
21965
21966 -static struct ata_port_operations rdc_pata_ops = {
21967 +static const struct ata_port_operations rdc_pata_ops = {
21968 .inherits = &ata_bmdma32_port_ops,
21969 .cable_detect = rdc_pata_cable_detect,
21970 .set_piomode = rdc_set_piomode,
21971 diff -urNp linux-2.6.37/drivers/ata/pata_rz1000.c linux-2.6.37/drivers/ata/pata_rz1000.c
21972 --- linux-2.6.37/drivers/ata/pata_rz1000.c 2011-01-04 19:50:19.000000000 -0500
21973 +++ linux-2.6.37/drivers/ata/pata_rz1000.c 2011-01-17 02:41:01.000000000 -0500
21974 @@ -54,7 +54,7 @@ static struct scsi_host_template rz1000_
21975 ATA_PIO_SHT(DRV_NAME),
21976 };
21977
21978 -static struct ata_port_operations rz1000_port_ops = {
21979 +static const struct ata_port_operations rz1000_port_ops = {
21980 .inherits = &ata_sff_port_ops,
21981 .cable_detect = ata_cable_40wire,
21982 .set_mode = rz1000_set_mode,
21983 diff -urNp linux-2.6.37/drivers/ata/pata_samsung_cf.c linux-2.6.37/drivers/ata/pata_samsung_cf.c
21984 --- linux-2.6.37/drivers/ata/pata_samsung_cf.c 2011-01-04 19:50:19.000000000 -0500
21985 +++ linux-2.6.37/drivers/ata/pata_samsung_cf.c 2011-01-17 02:41:01.000000000 -0500
21986 @@ -399,7 +399,7 @@ static struct scsi_host_template pata_s3
21987 ATA_PIO_SHT(DRV_NAME),
21988 };
21989
21990 -static struct ata_port_operations pata_s3c_port_ops = {
21991 +static const struct ata_port_operations pata_s3c_port_ops = {
21992 .inherits = &ata_sff_port_ops,
21993 .sff_check_status = pata_s3c_check_status,
21994 .sff_check_altstatus = pata_s3c_check_altstatus,
21995 @@ -413,7 +413,7 @@ static struct ata_port_operations pata_s
21996 .set_piomode = pata_s3c_set_piomode,
21997 };
21998
21999 -static struct ata_port_operations pata_s5p_port_ops = {
22000 +static const struct ata_port_operations pata_s5p_port_ops = {
22001 .inherits = &ata_sff_port_ops,
22002 .set_piomode = pata_s3c_set_piomode,
22003 };
22004 diff -urNp linux-2.6.37/drivers/ata/pata_sc1200.c linux-2.6.37/drivers/ata/pata_sc1200.c
22005 --- linux-2.6.37/drivers/ata/pata_sc1200.c 2011-01-04 19:50:19.000000000 -0500
22006 +++ linux-2.6.37/drivers/ata/pata_sc1200.c 2011-01-17 02:41:01.000000000 -0500
22007 @@ -207,7 +207,7 @@ static struct scsi_host_template sc1200_
22008 .sg_tablesize = LIBATA_DUMB_MAX_PRD,
22009 };
22010
22011 -static struct ata_port_operations sc1200_port_ops = {
22012 +static const struct ata_port_operations sc1200_port_ops = {
22013 .inherits = &ata_bmdma_port_ops,
22014 .qc_prep = ata_bmdma_dumb_qc_prep,
22015 .qc_issue = sc1200_qc_issue,
22016 diff -urNp linux-2.6.37/drivers/ata/pata_scc.c linux-2.6.37/drivers/ata/pata_scc.c
22017 --- linux-2.6.37/drivers/ata/pata_scc.c 2011-01-04 19:50:19.000000000 -0500
22018 +++ linux-2.6.37/drivers/ata/pata_scc.c 2011-01-17 02:41:01.000000000 -0500
22019 @@ -926,7 +926,7 @@ static struct scsi_host_template scc_sht
22020 ATA_BMDMA_SHT(DRV_NAME),
22021 };
22022
22023 -static struct ata_port_operations scc_pata_ops = {
22024 +static const struct ata_port_operations scc_pata_ops = {
22025 .inherits = &ata_bmdma_port_ops,
22026
22027 .set_piomode = scc_set_piomode,
22028 diff -urNp linux-2.6.37/drivers/ata/pata_sch.c linux-2.6.37/drivers/ata/pata_sch.c
22029 --- linux-2.6.37/drivers/ata/pata_sch.c 2011-01-04 19:50:19.000000000 -0500
22030 +++ linux-2.6.37/drivers/ata/pata_sch.c 2011-01-17 02:41:01.000000000 -0500
22031 @@ -75,7 +75,7 @@ static struct scsi_host_template sch_sht
22032 ATA_BMDMA_SHT(DRV_NAME),
22033 };
22034
22035 -static struct ata_port_operations sch_pata_ops = {
22036 +static const struct ata_port_operations sch_pata_ops = {
22037 .inherits = &ata_bmdma_port_ops,
22038 .cable_detect = ata_cable_unknown,
22039 .set_piomode = sch_set_piomode,
22040 diff -urNp linux-2.6.37/drivers/ata/pata_serverworks.c linux-2.6.37/drivers/ata/pata_serverworks.c
22041 --- linux-2.6.37/drivers/ata/pata_serverworks.c 2011-01-04 19:50:19.000000000 -0500
22042 +++ linux-2.6.37/drivers/ata/pata_serverworks.c 2011-01-17 02:41:01.000000000 -0500
22043 @@ -300,7 +300,7 @@ static struct scsi_host_template serverw
22044 ATA_BMDMA_SHT(DRV_NAME),
22045 };
22046
22047 -static struct ata_port_operations serverworks_osb4_port_ops = {
22048 +static const struct ata_port_operations serverworks_osb4_port_ops = {
22049 .inherits = &ata_bmdma_port_ops,
22050 .cable_detect = serverworks_cable_detect,
22051 .mode_filter = serverworks_osb4_filter,
22052 @@ -308,7 +308,7 @@ static struct ata_port_operations server
22053 .set_dmamode = serverworks_set_dmamode,
22054 };
22055
22056 -static struct ata_port_operations serverworks_csb_port_ops = {
22057 +static const struct ata_port_operations serverworks_csb_port_ops = {
22058 .inherits = &serverworks_osb4_port_ops,
22059 .mode_filter = serverworks_csb_filter,
22060 };
22061 diff -urNp linux-2.6.37/drivers/ata/pata_sil680.c linux-2.6.37/drivers/ata/pata_sil680.c
22062 --- linux-2.6.37/drivers/ata/pata_sil680.c 2011-01-04 19:50:19.000000000 -0500
22063 +++ linux-2.6.37/drivers/ata/pata_sil680.c 2011-01-17 02:41:01.000000000 -0500
22064 @@ -225,8 +225,7 @@ static struct scsi_host_template sil680_
22065 ATA_BMDMA_SHT(DRV_NAME),
22066 };
22067
22068 -
22069 -static struct ata_port_operations sil680_port_ops = {
22070 +static const struct ata_port_operations sil680_port_ops = {
22071 .inherits = &ata_bmdma32_port_ops,
22072 .sff_exec_command = sil680_sff_exec_command,
22073 .sff_irq_check = sil680_sff_irq_check,
22074 diff -urNp linux-2.6.37/drivers/ata/pata_sis.c linux-2.6.37/drivers/ata/pata_sis.c
22075 --- linux-2.6.37/drivers/ata/pata_sis.c 2011-01-04 19:50:19.000000000 -0500
22076 +++ linux-2.6.37/drivers/ata/pata_sis.c 2011-01-17 02:41:01.000000000 -0500
22077 @@ -503,47 +503,47 @@ static struct scsi_host_template sis_sht
22078 ATA_BMDMA_SHT(DRV_NAME),
22079 };
22080
22081 -static struct ata_port_operations sis_133_for_sata_ops = {
22082 +static const struct ata_port_operations sis_133_for_sata_ops = {
22083 .inherits = &ata_bmdma_port_ops,
22084 .set_piomode = sis_133_set_piomode,
22085 .set_dmamode = sis_133_set_dmamode,
22086 .cable_detect = sis_133_cable_detect,
22087 };
22088
22089 -static struct ata_port_operations sis_base_ops = {
22090 +static const struct ata_port_operations sis_base_ops = {
22091 .inherits = &ata_bmdma_port_ops,
22092 .prereset = sis_pre_reset,
22093 };
22094
22095 -static struct ata_port_operations sis_133_ops = {
22096 +static const struct ata_port_operations sis_133_ops = {
22097 .inherits = &sis_base_ops,
22098 .set_piomode = sis_133_set_piomode,
22099 .set_dmamode = sis_133_set_dmamode,
22100 .cable_detect = sis_133_cable_detect,
22101 };
22102
22103 -static struct ata_port_operations sis_133_early_ops = {
22104 +static const struct ata_port_operations sis_133_early_ops = {
22105 .inherits = &sis_base_ops,
22106 .set_piomode = sis_100_set_piomode,
22107 .set_dmamode = sis_133_early_set_dmamode,
22108 .cable_detect = sis_66_cable_detect,
22109 };
22110
22111 -static struct ata_port_operations sis_100_ops = {
22112 +static const struct ata_port_operations sis_100_ops = {
22113 .inherits = &sis_base_ops,
22114 .set_piomode = sis_100_set_piomode,
22115 .set_dmamode = sis_100_set_dmamode,
22116 .cable_detect = sis_66_cable_detect,
22117 };
22118
22119 -static struct ata_port_operations sis_66_ops = {
22120 +static const struct ata_port_operations sis_66_ops = {
22121 .inherits = &sis_base_ops,
22122 .set_piomode = sis_old_set_piomode,
22123 .set_dmamode = sis_66_set_dmamode,
22124 .cable_detect = sis_66_cable_detect,
22125 };
22126
22127 -static struct ata_port_operations sis_old_ops = {
22128 +static const struct ata_port_operations sis_old_ops = {
22129 .inherits = &sis_base_ops,
22130 .set_piomode = sis_old_set_piomode,
22131 .set_dmamode = sis_old_set_dmamode,
22132 diff -urNp linux-2.6.37/drivers/ata/pata_sl82c105.c linux-2.6.37/drivers/ata/pata_sl82c105.c
22133 --- linux-2.6.37/drivers/ata/pata_sl82c105.c 2011-01-04 19:50:19.000000000 -0500
22134 +++ linux-2.6.37/drivers/ata/pata_sl82c105.c 2011-01-17 02:41:01.000000000 -0500
22135 @@ -241,7 +241,7 @@ static struct scsi_host_template sl82c10
22136 ATA_BMDMA_SHT(DRV_NAME),
22137 };
22138
22139 -static struct ata_port_operations sl82c105_port_ops = {
22140 +static const struct ata_port_operations sl82c105_port_ops = {
22141 .inherits = &ata_bmdma_port_ops,
22142 .qc_defer = sl82c105_qc_defer,
22143 .bmdma_start = sl82c105_bmdma_start,
22144 diff -urNp linux-2.6.37/drivers/ata/pata_triflex.c linux-2.6.37/drivers/ata/pata_triflex.c
22145 --- linux-2.6.37/drivers/ata/pata_triflex.c 2011-01-04 19:50:19.000000000 -0500
22146 +++ linux-2.6.37/drivers/ata/pata_triflex.c 2011-01-17 02:41:01.000000000 -0500
22147 @@ -178,7 +178,7 @@ static struct scsi_host_template triflex
22148 ATA_BMDMA_SHT(DRV_NAME),
22149 };
22150
22151 -static struct ata_port_operations triflex_port_ops = {
22152 +static const struct ata_port_operations triflex_port_ops = {
22153 .inherits = &ata_bmdma_port_ops,
22154 .bmdma_start = triflex_bmdma_start,
22155 .bmdma_stop = triflex_bmdma_stop,
22156 diff -urNp linux-2.6.37/drivers/ata/pata_via.c linux-2.6.37/drivers/ata/pata_via.c
22157 --- linux-2.6.37/drivers/ata/pata_via.c 2011-01-04 19:50:19.000000000 -0500
22158 +++ linux-2.6.37/drivers/ata/pata_via.c 2011-01-17 02:41:01.000000000 -0500
22159 @@ -441,7 +441,7 @@ static struct scsi_host_template via_sht
22160 ATA_BMDMA_SHT(DRV_NAME),
22161 };
22162
22163 -static struct ata_port_operations via_port_ops = {
22164 +static const struct ata_port_operations via_port_ops = {
22165 .inherits = &ata_bmdma_port_ops,
22166 .cable_detect = via_cable_detect,
22167 .set_piomode = via_set_piomode,
22168 @@ -452,7 +452,7 @@ static struct ata_port_operations via_po
22169 .mode_filter = via_mode_filter,
22170 };
22171
22172 -static struct ata_port_operations via_port_ops_noirq = {
22173 +static const struct ata_port_operations via_port_ops_noirq = {
22174 .inherits = &via_port_ops,
22175 .sff_data_xfer = ata_sff_data_xfer_noirq,
22176 };
22177 diff -urNp linux-2.6.37/drivers/ata/pdc_adma.c linux-2.6.37/drivers/ata/pdc_adma.c
22178 --- linux-2.6.37/drivers/ata/pdc_adma.c 2011-01-04 19:50:19.000000000 -0500
22179 +++ linux-2.6.37/drivers/ata/pdc_adma.c 2011-01-17 02:41:01.000000000 -0500
22180 @@ -146,7 +146,7 @@ static struct scsi_host_template adma_at
22181 .dma_boundary = ADMA_DMA_BOUNDARY,
22182 };
22183
22184 -static struct ata_port_operations adma_ata_ops = {
22185 +static const struct ata_port_operations adma_ata_ops = {
22186 .inherits = &ata_sff_port_ops,
22187
22188 .lost_interrupt = ATA_OP_NULL,
22189 diff -urNp linux-2.6.37/drivers/ata/sata_dwc_460ex.c linux-2.6.37/drivers/ata/sata_dwc_460ex.c
22190 --- linux-2.6.37/drivers/ata/sata_dwc_460ex.c 2011-01-04 19:50:19.000000000 -0500
22191 +++ linux-2.6.37/drivers/ata/sata_dwc_460ex.c 2011-01-17 02:41:01.000000000 -0500
22192 @@ -1560,7 +1560,7 @@ static struct scsi_host_template sata_dw
22193 .dma_boundary = ATA_DMA_BOUNDARY,
22194 };
22195
22196 -static struct ata_port_operations sata_dwc_ops = {
22197 +static const struct ata_port_operations sata_dwc_ops = {
22198 .inherits = &ata_sff_port_ops,
22199
22200 .error_handler = sata_dwc_error_handler,
22201 diff -urNp linux-2.6.37/drivers/ata/sata_fsl.c linux-2.6.37/drivers/ata/sata_fsl.c
22202 --- linux-2.6.37/drivers/ata/sata_fsl.c 2011-01-04 19:50:19.000000000 -0500
22203 +++ linux-2.6.37/drivers/ata/sata_fsl.c 2011-01-17 02:41:01.000000000 -0500
22204 @@ -1258,7 +1258,7 @@ static struct scsi_host_template sata_fs
22205 .dma_boundary = ATA_DMA_BOUNDARY,
22206 };
22207
22208 -static struct ata_port_operations sata_fsl_ops = {
22209 +static const struct ata_port_operations sata_fsl_ops = {
22210 .inherits = &sata_pmp_port_ops,
22211
22212 .qc_defer = ata_std_qc_defer,
22213 diff -urNp linux-2.6.37/drivers/ata/sata_inic162x.c linux-2.6.37/drivers/ata/sata_inic162x.c
22214 --- linux-2.6.37/drivers/ata/sata_inic162x.c 2011-01-04 19:50:19.000000000 -0500
22215 +++ linux-2.6.37/drivers/ata/sata_inic162x.c 2011-01-17 02:41:01.000000000 -0500
22216 @@ -705,7 +705,7 @@ static int inic_port_start(struct ata_po
22217 return 0;
22218 }
22219
22220 -static struct ata_port_operations inic_port_ops = {
22221 +static const struct ata_port_operations inic_port_ops = {
22222 .inherits = &sata_port_ops,
22223
22224 .check_atapi_dma = inic_check_atapi_dma,
22225 diff -urNp linux-2.6.37/drivers/ata/sata_mv.c linux-2.6.37/drivers/ata/sata_mv.c
22226 --- linux-2.6.37/drivers/ata/sata_mv.c 2011-01-04 19:50:19.000000000 -0500
22227 +++ linux-2.6.37/drivers/ata/sata_mv.c 2011-01-17 02:41:01.000000000 -0500
22228 @@ -663,7 +663,7 @@ static struct scsi_host_template mv6_sht
22229 .dma_boundary = MV_DMA_BOUNDARY,
22230 };
22231
22232 -static struct ata_port_operations mv5_ops = {
22233 +static const struct ata_port_operations mv5_ops = {
22234 .inherits = &ata_sff_port_ops,
22235
22236 .lost_interrupt = ATA_OP_NULL,
22237 @@ -683,7 +683,7 @@ static struct ata_port_operations mv5_op
22238 .port_stop = mv_port_stop,
22239 };
22240
22241 -static struct ata_port_operations mv6_ops = {
22242 +static const struct ata_port_operations mv6_ops = {
22243 .inherits = &ata_bmdma_port_ops,
22244
22245 .lost_interrupt = ATA_OP_NULL,
22246 @@ -717,7 +717,7 @@ static struct ata_port_operations mv6_op
22247 .port_stop = mv_port_stop,
22248 };
22249
22250 -static struct ata_port_operations mv_iie_ops = {
22251 +static const struct ata_port_operations mv_iie_ops = {
22252 .inherits = &mv6_ops,
22253 .dev_config = ATA_OP_NULL,
22254 .qc_prep = mv_qc_prep_iie,
22255 diff -urNp linux-2.6.37/drivers/ata/sata_nv.c linux-2.6.37/drivers/ata/sata_nv.c
22256 --- linux-2.6.37/drivers/ata/sata_nv.c 2011-01-04 19:50:19.000000000 -0500
22257 +++ linux-2.6.37/drivers/ata/sata_nv.c 2011-01-17 02:41:01.000000000 -0500
22258 @@ -465,7 +465,7 @@ static struct scsi_host_template nv_swnc
22259 * cases. Define nv_hardreset() which only kicks in for post-boot
22260 * probing and use it for all variants.
22261 */
22262 -static struct ata_port_operations nv_generic_ops = {
22263 +static const struct ata_port_operations nv_generic_ops = {
22264 .inherits = &ata_bmdma_port_ops,
22265 .lost_interrupt = ATA_OP_NULL,
22266 .scr_read = nv_scr_read,
22267 @@ -473,20 +473,20 @@ static struct ata_port_operations nv_gen
22268 .hardreset = nv_hardreset,
22269 };
22270
22271 -static struct ata_port_operations nv_nf2_ops = {
22272 +static const struct ata_port_operations nv_nf2_ops = {
22273 .inherits = &nv_generic_ops,
22274 .freeze = nv_nf2_freeze,
22275 .thaw = nv_nf2_thaw,
22276 };
22277
22278 -static struct ata_port_operations nv_ck804_ops = {
22279 +static const struct ata_port_operations nv_ck804_ops = {
22280 .inherits = &nv_generic_ops,
22281 .freeze = nv_ck804_freeze,
22282 .thaw = nv_ck804_thaw,
22283 .host_stop = nv_ck804_host_stop,
22284 };
22285
22286 -static struct ata_port_operations nv_adma_ops = {
22287 +static const struct ata_port_operations nv_adma_ops = {
22288 .inherits = &nv_ck804_ops,
22289
22290 .check_atapi_dma = nv_adma_check_atapi_dma,
22291 @@ -510,7 +510,7 @@ static struct ata_port_operations nv_adm
22292 .host_stop = nv_adma_host_stop,
22293 };
22294
22295 -static struct ata_port_operations nv_swncq_ops = {
22296 +static const struct ata_port_operations nv_swncq_ops = {
22297 .inherits = &nv_generic_ops,
22298
22299 .qc_defer = ata_std_qc_defer,
22300 diff -urNp linux-2.6.37/drivers/ata/sata_promise.c linux-2.6.37/drivers/ata/sata_promise.c
22301 --- linux-2.6.37/drivers/ata/sata_promise.c 2011-01-04 19:50:19.000000000 -0500
22302 +++ linux-2.6.37/drivers/ata/sata_promise.c 2011-01-17 02:41:01.000000000 -0500
22303 @@ -196,7 +196,7 @@ static const struct ata_port_operations
22304 .error_handler = pdc_error_handler,
22305 };
22306
22307 -static struct ata_port_operations pdc_sata_ops = {
22308 +static const struct ata_port_operations pdc_sata_ops = {
22309 .inherits = &pdc_common_ops,
22310 .cable_detect = pdc_sata_cable_detect,
22311 .freeze = pdc_sata_freeze,
22312 @@ -209,14 +209,14 @@ static struct ata_port_operations pdc_sa
22313
22314 /* First-generation chips need a more restrictive ->check_atapi_dma op,
22315 and ->freeze/thaw that ignore the hotplug controls. */
22316 -static struct ata_port_operations pdc_old_sata_ops = {
22317 +static const struct ata_port_operations pdc_old_sata_ops = {
22318 .inherits = &pdc_sata_ops,
22319 .freeze = pdc_freeze,
22320 .thaw = pdc_thaw,
22321 .check_atapi_dma = pdc_old_sata_check_atapi_dma,
22322 };
22323
22324 -static struct ata_port_operations pdc_pata_ops = {
22325 +static const struct ata_port_operations pdc_pata_ops = {
22326 .inherits = &pdc_common_ops,
22327 .cable_detect = pdc_pata_cable_detect,
22328 .freeze = pdc_freeze,
22329 diff -urNp linux-2.6.37/drivers/ata/sata_qstor.c linux-2.6.37/drivers/ata/sata_qstor.c
22330 --- linux-2.6.37/drivers/ata/sata_qstor.c 2011-01-04 19:50:19.000000000 -0500
22331 +++ linux-2.6.37/drivers/ata/sata_qstor.c 2011-01-17 02:41:01.000000000 -0500
22332 @@ -131,7 +131,7 @@ static struct scsi_host_template qs_ata_
22333 .dma_boundary = QS_DMA_BOUNDARY,
22334 };
22335
22336 -static struct ata_port_operations qs_ata_ops = {
22337 +static const struct ata_port_operations qs_ata_ops = {
22338 .inherits = &ata_sff_port_ops,
22339
22340 .check_atapi_dma = qs_check_atapi_dma,
22341 diff -urNp linux-2.6.37/drivers/ata/sata_sil24.c linux-2.6.37/drivers/ata/sata_sil24.c
22342 --- linux-2.6.37/drivers/ata/sata_sil24.c 2011-01-04 19:50:19.000000000 -0500
22343 +++ linux-2.6.37/drivers/ata/sata_sil24.c 2011-01-17 02:41:01.000000000 -0500
22344 @@ -389,7 +389,7 @@ static struct scsi_host_template sil24_s
22345 .dma_boundary = ATA_DMA_BOUNDARY,
22346 };
22347
22348 -static struct ata_port_operations sil24_ops = {
22349 +static const struct ata_port_operations sil24_ops = {
22350 .inherits = &sata_pmp_port_ops,
22351
22352 .qc_defer = sil24_qc_defer,
22353 diff -urNp linux-2.6.37/drivers/ata/sata_sil.c linux-2.6.37/drivers/ata/sata_sil.c
22354 --- linux-2.6.37/drivers/ata/sata_sil.c 2011-01-04 19:50:19.000000000 -0500
22355 +++ linux-2.6.37/drivers/ata/sata_sil.c 2011-01-17 02:41:01.000000000 -0500
22356 @@ -182,7 +182,7 @@ static struct scsi_host_template sil_sht
22357 .sg_tablesize = ATA_MAX_PRD
22358 };
22359
22360 -static struct ata_port_operations sil_ops = {
22361 +static const struct ata_port_operations sil_ops = {
22362 .inherits = &ata_bmdma32_port_ops,
22363 .dev_config = sil_dev_config,
22364 .set_mode = sil_set_mode,
22365 diff -urNp linux-2.6.37/drivers/ata/sata_sis.c linux-2.6.37/drivers/ata/sata_sis.c
22366 --- linux-2.6.37/drivers/ata/sata_sis.c 2011-01-04 19:50:19.000000000 -0500
22367 +++ linux-2.6.37/drivers/ata/sata_sis.c 2011-01-17 02:41:01.000000000 -0500
22368 @@ -89,7 +89,7 @@ static struct scsi_host_template sis_sht
22369 ATA_BMDMA_SHT(DRV_NAME),
22370 };
22371
22372 -static struct ata_port_operations sis_ops = {
22373 +static const struct ata_port_operations sis_ops = {
22374 .inherits = &ata_bmdma_port_ops,
22375 .scr_read = sis_scr_read,
22376 .scr_write = sis_scr_write,
22377 diff -urNp linux-2.6.37/drivers/ata/sata_svw.c linux-2.6.37/drivers/ata/sata_svw.c
22378 --- linux-2.6.37/drivers/ata/sata_svw.c 2011-01-04 19:50:19.000000000 -0500
22379 +++ linux-2.6.37/drivers/ata/sata_svw.c 2011-01-17 02:41:01.000000000 -0500
22380 @@ -344,7 +344,7 @@ static struct scsi_host_template k2_sata
22381 };
22382
22383
22384 -static struct ata_port_operations k2_sata_ops = {
22385 +static const struct ata_port_operations k2_sata_ops = {
22386 .inherits = &ata_bmdma_port_ops,
22387 .sff_tf_load = k2_sata_tf_load,
22388 .sff_tf_read = k2_sata_tf_read,
22389 diff -urNp linux-2.6.37/drivers/ata/sata_sx4.c linux-2.6.37/drivers/ata/sata_sx4.c
22390 --- linux-2.6.37/drivers/ata/sata_sx4.c 2011-01-04 19:50:19.000000000 -0500
22391 +++ linux-2.6.37/drivers/ata/sata_sx4.c 2011-01-17 02:41:01.000000000 -0500
22392 @@ -249,7 +249,7 @@ static struct scsi_host_template pdc_sat
22393 };
22394
22395 /* TODO: inherit from base port_ops after converting to new EH */
22396 -static struct ata_port_operations pdc_20621_ops = {
22397 +static const struct ata_port_operations pdc_20621_ops = {
22398 .inherits = &ata_sff_port_ops,
22399
22400 .check_atapi_dma = pdc_check_atapi_dma,
22401 diff -urNp linux-2.6.37/drivers/ata/sata_uli.c linux-2.6.37/drivers/ata/sata_uli.c
22402 --- linux-2.6.37/drivers/ata/sata_uli.c 2011-01-04 19:50:19.000000000 -0500
22403 +++ linux-2.6.37/drivers/ata/sata_uli.c 2011-01-17 02:41:01.000000000 -0500
22404 @@ -80,7 +80,7 @@ static struct scsi_host_template uli_sht
22405 ATA_BMDMA_SHT(DRV_NAME),
22406 };
22407
22408 -static struct ata_port_operations uli_ops = {
22409 +static const struct ata_port_operations uli_ops = {
22410 .inherits = &ata_bmdma_port_ops,
22411 .scr_read = uli_scr_read,
22412 .scr_write = uli_scr_write,
22413 diff -urNp linux-2.6.37/drivers/ata/sata_via.c linux-2.6.37/drivers/ata/sata_via.c
22414 --- linux-2.6.37/drivers/ata/sata_via.c 2011-01-04 19:50:19.000000000 -0500
22415 +++ linux-2.6.37/drivers/ata/sata_via.c 2011-01-17 02:41:01.000000000 -0500
22416 @@ -115,32 +115,32 @@ static struct scsi_host_template svia_sh
22417 ATA_BMDMA_SHT(DRV_NAME),
22418 };
22419
22420 -static struct ata_port_operations svia_base_ops = {
22421 +static const struct ata_port_operations svia_base_ops = {
22422 .inherits = &ata_bmdma_port_ops,
22423 .sff_tf_load = svia_tf_load,
22424 };
22425
22426 -static struct ata_port_operations vt6420_sata_ops = {
22427 +static const struct ata_port_operations vt6420_sata_ops = {
22428 .inherits = &svia_base_ops,
22429 .freeze = svia_noop_freeze,
22430 .prereset = vt6420_prereset,
22431 .bmdma_start = vt6420_bmdma_start,
22432 };
22433
22434 -static struct ata_port_operations vt6421_pata_ops = {
22435 +static const struct ata_port_operations vt6421_pata_ops = {
22436 .inherits = &svia_base_ops,
22437 .cable_detect = vt6421_pata_cable_detect,
22438 .set_piomode = vt6421_set_pio_mode,
22439 .set_dmamode = vt6421_set_dma_mode,
22440 };
22441
22442 -static struct ata_port_operations vt6421_sata_ops = {
22443 +static const struct ata_port_operations vt6421_sata_ops = {
22444 .inherits = &svia_base_ops,
22445 .scr_read = svia_scr_read,
22446 .scr_write = svia_scr_write,
22447 };
22448
22449 -static struct ata_port_operations vt8251_ops = {
22450 +static const struct ata_port_operations vt8251_ops = {
22451 .inherits = &svia_base_ops,
22452 .hardreset = sata_std_hardreset,
22453 .scr_read = vt8251_scr_read,
22454 diff -urNp linux-2.6.37/drivers/ata/sata_vsc.c linux-2.6.37/drivers/ata/sata_vsc.c
22455 --- linux-2.6.37/drivers/ata/sata_vsc.c 2011-01-04 19:50:19.000000000 -0500
22456 +++ linux-2.6.37/drivers/ata/sata_vsc.c 2011-01-17 02:41:01.000000000 -0500
22457 @@ -300,7 +300,7 @@ static struct scsi_host_template vsc_sat
22458 };
22459
22460
22461 -static struct ata_port_operations vsc_sata_ops = {
22462 +static const struct ata_port_operations vsc_sata_ops = {
22463 .inherits = &ata_bmdma_port_ops,
22464 /* The IRQ handling is not quite standard SFF behaviour so we
22465 cannot use the default lost interrupt handler */
22466 diff -urNp linux-2.6.37/drivers/atm/adummy.c linux-2.6.37/drivers/atm/adummy.c
22467 --- linux-2.6.37/drivers/atm/adummy.c 2011-01-04 19:50:19.000000000 -0500
22468 +++ linux-2.6.37/drivers/atm/adummy.c 2011-01-17 02:41:01.000000000 -0500
22469 @@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct
22470 vcc->pop(vcc, skb);
22471 else
22472 dev_kfree_skb_any(skb);
22473 - atomic_inc(&vcc->stats->tx);
22474 + atomic_inc_unchecked(&vcc->stats->tx);
22475
22476 return 0;
22477 }
22478 diff -urNp linux-2.6.37/drivers/atm/ambassador.c linux-2.6.37/drivers/atm/ambassador.c
22479 --- linux-2.6.37/drivers/atm/ambassador.c 2011-01-04 19:50:19.000000000 -0500
22480 +++ linux-2.6.37/drivers/atm/ambassador.c 2011-01-17 02:41:01.000000000 -0500
22481 @@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev,
22482 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
22483
22484 // VC layer stats
22485 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
22486 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
22487
22488 // free the descriptor
22489 kfree (tx_descr);
22490 @@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev,
22491 dump_skb ("<<<", vc, skb);
22492
22493 // VC layer stats
22494 - atomic_inc(&atm_vcc->stats->rx);
22495 + atomic_inc_unchecked(&atm_vcc->stats->rx);
22496 __net_timestamp(skb);
22497 // end of our responsability
22498 atm_vcc->push (atm_vcc, skb);
22499 @@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev,
22500 } else {
22501 PRINTK (KERN_INFO, "dropped over-size frame");
22502 // should we count this?
22503 - atomic_inc(&atm_vcc->stats->rx_drop);
22504 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
22505 }
22506
22507 } else {
22508 @@ -1342,7 +1342,7 @@ static int amb_send (struct atm_vcc * at
22509 }
22510
22511 if (check_area (skb->data, skb->len)) {
22512 - atomic_inc(&atm_vcc->stats->tx_err);
22513 + atomic_inc_unchecked(&atm_vcc->stats->tx_err);
22514 return -ENOMEM; // ?
22515 }
22516
22517 diff -urNp linux-2.6.37/drivers/atm/atmtcp.c linux-2.6.37/drivers/atm/atmtcp.c
22518 --- linux-2.6.37/drivers/atm/atmtcp.c 2011-01-04 19:50:19.000000000 -0500
22519 +++ linux-2.6.37/drivers/atm/atmtcp.c 2011-01-17 02:41:01.000000000 -0500
22520 @@ -207,7 +207,7 @@ static int atmtcp_v_send(struct atm_vcc
22521 if (vcc->pop) vcc->pop(vcc,skb);
22522 else dev_kfree_skb(skb);
22523 if (dev_data) return 0;
22524 - atomic_inc(&vcc->stats->tx_err);
22525 + atomic_inc_unchecked(&vcc->stats->tx_err);
22526 return -ENOLINK;
22527 }
22528 size = skb->len+sizeof(struct atmtcp_hdr);
22529 @@ -215,7 +215,7 @@ static int atmtcp_v_send(struct atm_vcc
22530 if (!new_skb) {
22531 if (vcc->pop) vcc->pop(vcc,skb);
22532 else dev_kfree_skb(skb);
22533 - atomic_inc(&vcc->stats->tx_err);
22534 + atomic_inc_unchecked(&vcc->stats->tx_err);
22535 return -ENOBUFS;
22536 }
22537 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
22538 @@ -226,8 +226,8 @@ static int atmtcp_v_send(struct atm_vcc
22539 if (vcc->pop) vcc->pop(vcc,skb);
22540 else dev_kfree_skb(skb);
22541 out_vcc->push(out_vcc,new_skb);
22542 - atomic_inc(&vcc->stats->tx);
22543 - atomic_inc(&out_vcc->stats->rx);
22544 + atomic_inc_unchecked(&vcc->stats->tx);
22545 + atomic_inc_unchecked(&out_vcc->stats->rx);
22546 return 0;
22547 }
22548
22549 @@ -301,7 +301,7 @@ static int atmtcp_c_send(struct atm_vcc
22550 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
22551 read_unlock(&vcc_sklist_lock);
22552 if (!out_vcc) {
22553 - atomic_inc(&vcc->stats->tx_err);
22554 + atomic_inc_unchecked(&vcc->stats->tx_err);
22555 goto done;
22556 }
22557 skb_pull(skb,sizeof(struct atmtcp_hdr));
22558 @@ -313,8 +313,8 @@ static int atmtcp_c_send(struct atm_vcc
22559 __net_timestamp(new_skb);
22560 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
22561 out_vcc->push(out_vcc,new_skb);
22562 - atomic_inc(&vcc->stats->tx);
22563 - atomic_inc(&out_vcc->stats->rx);
22564 + atomic_inc_unchecked(&vcc->stats->tx);
22565 + atomic_inc_unchecked(&out_vcc->stats->rx);
22566 done:
22567 if (vcc->pop) vcc->pop(vcc,skb);
22568 else dev_kfree_skb(skb);
22569 diff -urNp linux-2.6.37/drivers/atm/eni.c linux-2.6.37/drivers/atm/eni.c
22570 --- linux-2.6.37/drivers/atm/eni.c 2011-01-04 19:50:19.000000000 -0500
22571 +++ linux-2.6.37/drivers/atm/eni.c 2011-01-17 02:41:01.000000000 -0500
22572 @@ -526,7 +526,7 @@ static int rx_aal0(struct atm_vcc *vcc)
22573 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
22574 vcc->dev->number);
22575 length = 0;
22576 - atomic_inc(&vcc->stats->rx_err);
22577 + atomic_inc_unchecked(&vcc->stats->rx_err);
22578 }
22579 else {
22580 length = ATM_CELL_SIZE-1; /* no HEC */
22581 @@ -581,7 +581,7 @@ static int rx_aal5(struct atm_vcc *vcc)
22582 size);
22583 }
22584 eff = length = 0;
22585 - atomic_inc(&vcc->stats->rx_err);
22586 + atomic_inc_unchecked(&vcc->stats->rx_err);
22587 }
22588 else {
22589 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
22590 @@ -598,7 +598,7 @@ static int rx_aal5(struct atm_vcc *vcc)
22591 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
22592 vcc->dev->number,vcc->vci,length,size << 2,descr);
22593 length = eff = 0;
22594 - atomic_inc(&vcc->stats->rx_err);
22595 + atomic_inc_unchecked(&vcc->stats->rx_err);
22596 }
22597 }
22598 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
22599 @@ -771,7 +771,7 @@ rx_dequeued++;
22600 vcc->push(vcc,skb);
22601 pushed++;
22602 }
22603 - atomic_inc(&vcc->stats->rx);
22604 + atomic_inc_unchecked(&vcc->stats->rx);
22605 }
22606 wake_up(&eni_dev->rx_wait);
22607 }
22608 @@ -1228,7 +1228,7 @@ static void dequeue_tx(struct atm_dev *d
22609 PCI_DMA_TODEVICE);
22610 if (vcc->pop) vcc->pop(vcc,skb);
22611 else dev_kfree_skb_irq(skb);
22612 - atomic_inc(&vcc->stats->tx);
22613 + atomic_inc_unchecked(&vcc->stats->tx);
22614 wake_up(&eni_dev->tx_wait);
22615 dma_complete++;
22616 }
22617 diff -urNp linux-2.6.37/drivers/atm/firestream.c linux-2.6.37/drivers/atm/firestream.c
22618 --- linux-2.6.37/drivers/atm/firestream.c 2011-01-04 19:50:19.000000000 -0500
22619 +++ linux-2.6.37/drivers/atm/firestream.c 2011-01-17 02:41:01.000000000 -0500
22620 @@ -749,7 +749,7 @@ static void process_txdone_queue (struct
22621 }
22622 }
22623
22624 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
22625 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
22626
22627 fs_dprintk (FS_DEBUG_TXMEM, "i");
22628 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
22629 @@ -816,7 +816,7 @@ static void process_incoming (struct fs_
22630 #endif
22631 skb_put (skb, qe->p1 & 0xffff);
22632 ATM_SKB(skb)->vcc = atm_vcc;
22633 - atomic_inc(&atm_vcc->stats->rx);
22634 + atomic_inc_unchecked(&atm_vcc->stats->rx);
22635 __net_timestamp(skb);
22636 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
22637 atm_vcc->push (atm_vcc, skb);
22638 @@ -837,12 +837,12 @@ static void process_incoming (struct fs_
22639 kfree (pe);
22640 }
22641 if (atm_vcc)
22642 - atomic_inc(&atm_vcc->stats->rx_drop);
22643 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
22644 break;
22645 case 0x1f: /* Reassembly abort: no buffers. */
22646 /* Silently increment error counter. */
22647 if (atm_vcc)
22648 - atomic_inc(&atm_vcc->stats->rx_drop);
22649 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
22650 break;
22651 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
22652 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
22653 diff -urNp linux-2.6.37/drivers/atm/fore200e.c linux-2.6.37/drivers/atm/fore200e.c
22654 --- linux-2.6.37/drivers/atm/fore200e.c 2011-01-04 19:50:19.000000000 -0500
22655 +++ linux-2.6.37/drivers/atm/fore200e.c 2011-01-17 02:41:01.000000000 -0500
22656 @@ -933,9 +933,9 @@ fore200e_tx_irq(struct fore200e* fore200
22657 #endif
22658 /* check error condition */
22659 if (*entry->status & STATUS_ERROR)
22660 - atomic_inc(&vcc->stats->tx_err);
22661 + atomic_inc_unchecked(&vcc->stats->tx_err);
22662 else
22663 - atomic_inc(&vcc->stats->tx);
22664 + atomic_inc_unchecked(&vcc->stats->tx);
22665 }
22666 }
22667
22668 @@ -1084,7 +1084,7 @@ fore200e_push_rpd(struct fore200e* fore2
22669 if (skb == NULL) {
22670 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
22671
22672 - atomic_inc(&vcc->stats->rx_drop);
22673 + atomic_inc_unchecked(&vcc->stats->rx_drop);
22674 return -ENOMEM;
22675 }
22676
22677 @@ -1127,14 +1127,14 @@ fore200e_push_rpd(struct fore200e* fore2
22678
22679 dev_kfree_skb_any(skb);
22680
22681 - atomic_inc(&vcc->stats->rx_drop);
22682 + atomic_inc_unchecked(&vcc->stats->rx_drop);
22683 return -ENOMEM;
22684 }
22685
22686 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
22687
22688 vcc->push(vcc, skb);
22689 - atomic_inc(&vcc->stats->rx);
22690 + atomic_inc_unchecked(&vcc->stats->rx);
22691
22692 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
22693
22694 @@ -1212,7 +1212,7 @@ fore200e_rx_irq(struct fore200e* fore200
22695 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
22696 fore200e->atm_dev->number,
22697 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
22698 - atomic_inc(&vcc->stats->rx_err);
22699 + atomic_inc_unchecked(&vcc->stats->rx_err);
22700 }
22701 }
22702
22703 @@ -1657,7 +1657,7 @@ fore200e_send(struct atm_vcc *vcc, struc
22704 goto retry_here;
22705 }
22706
22707 - atomic_inc(&vcc->stats->tx_err);
22708 + atomic_inc_unchecked(&vcc->stats->tx_err);
22709
22710 fore200e->tx_sat++;
22711 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
22712 diff -urNp linux-2.6.37/drivers/atm/he.c linux-2.6.37/drivers/atm/he.c
22713 --- linux-2.6.37/drivers/atm/he.c 2011-01-04 19:50:19.000000000 -0500
22714 +++ linux-2.6.37/drivers/atm/he.c 2011-01-17 02:41:01.000000000 -0500
22715 @@ -1709,7 +1709,7 @@ he_service_rbrq(struct he_dev *he_dev, i
22716
22717 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
22718 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
22719 - atomic_inc(&vcc->stats->rx_drop);
22720 + atomic_inc_unchecked(&vcc->stats->rx_drop);
22721 goto return_host_buffers;
22722 }
22723
22724 @@ -1736,7 +1736,7 @@ he_service_rbrq(struct he_dev *he_dev, i
22725 RBRQ_LEN_ERR(he_dev->rbrq_head)
22726 ? "LEN_ERR" : "",
22727 vcc->vpi, vcc->vci);
22728 - atomic_inc(&vcc->stats->rx_err);
22729 + atomic_inc_unchecked(&vcc->stats->rx_err);
22730 goto return_host_buffers;
22731 }
22732
22733 @@ -1788,7 +1788,7 @@ he_service_rbrq(struct he_dev *he_dev, i
22734 vcc->push(vcc, skb);
22735 spin_lock(&he_dev->global_lock);
22736
22737 - atomic_inc(&vcc->stats->rx);
22738 + atomic_inc_unchecked(&vcc->stats->rx);
22739
22740 return_host_buffers:
22741 ++pdus_assembled;
22742 @@ -2114,7 +2114,7 @@ __enqueue_tpd(struct he_dev *he_dev, str
22743 tpd->vcc->pop(tpd->vcc, tpd->skb);
22744 else
22745 dev_kfree_skb_any(tpd->skb);
22746 - atomic_inc(&tpd->vcc->stats->tx_err);
22747 + atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
22748 }
22749 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
22750 return;
22751 @@ -2526,7 +2526,7 @@ he_send(struct atm_vcc *vcc, struct sk_b
22752 vcc->pop(vcc, skb);
22753 else
22754 dev_kfree_skb_any(skb);
22755 - atomic_inc(&vcc->stats->tx_err);
22756 + atomic_inc_unchecked(&vcc->stats->tx_err);
22757 return -EINVAL;
22758 }
22759
22760 @@ -2537,7 +2537,7 @@ he_send(struct atm_vcc *vcc, struct sk_b
22761 vcc->pop(vcc, skb);
22762 else
22763 dev_kfree_skb_any(skb);
22764 - atomic_inc(&vcc->stats->tx_err);
22765 + atomic_inc_unchecked(&vcc->stats->tx_err);
22766 return -EINVAL;
22767 }
22768 #endif
22769 @@ -2549,7 +2549,7 @@ he_send(struct atm_vcc *vcc, struct sk_b
22770 vcc->pop(vcc, skb);
22771 else
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);
22776 return -ENOMEM;
22777 }
22778 @@ -2591,7 +2591,7 @@ he_send(struct atm_vcc *vcc, struct sk_b
22779 vcc->pop(vcc, skb);
22780 else
22781 dev_kfree_skb_any(skb);
22782 - atomic_inc(&vcc->stats->tx_err);
22783 + atomic_inc_unchecked(&vcc->stats->tx_err);
22784 spin_unlock_irqrestore(&he_dev->global_lock, flags);
22785 return -ENOMEM;
22786 }
22787 @@ -2622,7 +2622,7 @@ he_send(struct atm_vcc *vcc, struct sk_b
22788 __enqueue_tpd(he_dev, tpd, cid);
22789 spin_unlock_irqrestore(&he_dev->global_lock, flags);
22790
22791 - atomic_inc(&vcc->stats->tx);
22792 + atomic_inc_unchecked(&vcc->stats->tx);
22793
22794 return 0;
22795 }
22796 diff -urNp linux-2.6.37/drivers/atm/horizon.c linux-2.6.37/drivers/atm/horizon.c
22797 --- linux-2.6.37/drivers/atm/horizon.c 2011-01-04 19:50:19.000000000 -0500
22798 +++ linux-2.6.37/drivers/atm/horizon.c 2011-01-17 02:41:01.000000000 -0500
22799 @@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev,
22800 {
22801 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
22802 // VC layer stats
22803 - atomic_inc(&vcc->stats->rx);
22804 + atomic_inc_unchecked(&vcc->stats->rx);
22805 __net_timestamp(skb);
22806 // end of our responsability
22807 vcc->push (vcc, skb);
22808 @@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const
22809 dev->tx_iovec = NULL;
22810
22811 // VC layer stats
22812 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
22813 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
22814
22815 // free the skb
22816 hrz_kfree_skb (skb);
22817 diff -urNp linux-2.6.37/drivers/atm/idt77252.c linux-2.6.37/drivers/atm/idt77252.c
22818 --- linux-2.6.37/drivers/atm/idt77252.c 2011-01-04 19:50:19.000000000 -0500
22819 +++ linux-2.6.37/drivers/atm/idt77252.c 2011-01-17 02:41:01.000000000 -0500
22820 @@ -811,7 +811,7 @@ drain_scq(struct idt77252_dev *card, str
22821 else
22822 dev_kfree_skb(skb);
22823
22824 - atomic_inc(&vcc->stats->tx);
22825 + atomic_inc_unchecked(&vcc->stats->tx);
22826 }
22827
22828 atomic_dec(&scq->used);
22829 @@ -1074,13 +1074,13 @@ dequeue_rx(struct idt77252_dev *card, st
22830 if ((sb = dev_alloc_skb(64)) == NULL) {
22831 printk("%s: Can't allocate buffers for aal0.\n",
22832 card->name);
22833 - atomic_add(i, &vcc->stats->rx_drop);
22834 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
22835 break;
22836 }
22837 if (!atm_charge(vcc, sb->truesize)) {
22838 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
22839 card->name);
22840 - atomic_add(i - 1, &vcc->stats->rx_drop);
22841 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
22842 dev_kfree_skb(sb);
22843 break;
22844 }
22845 @@ -1097,7 +1097,7 @@ dequeue_rx(struct idt77252_dev *card, st
22846 ATM_SKB(sb)->vcc = vcc;
22847 __net_timestamp(sb);
22848 vcc->push(vcc, sb);
22849 - atomic_inc(&vcc->stats->rx);
22850 + atomic_inc_unchecked(&vcc->stats->rx);
22851
22852 cell += ATM_CELL_PAYLOAD;
22853 }
22854 @@ -1134,13 +1134,13 @@ dequeue_rx(struct idt77252_dev *card, st
22855 "(CDC: %08x)\n",
22856 card->name, len, rpp->len, readl(SAR_REG_CDC));
22857 recycle_rx_pool_skb(card, rpp);
22858 - atomic_inc(&vcc->stats->rx_err);
22859 + atomic_inc_unchecked(&vcc->stats->rx_err);
22860 return;
22861 }
22862 if (stat & SAR_RSQE_CRC) {
22863 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
22864 recycle_rx_pool_skb(card, rpp);
22865 - atomic_inc(&vcc->stats->rx_err);
22866 + atomic_inc_unchecked(&vcc->stats->rx_err);
22867 return;
22868 }
22869 if (skb_queue_len(&rpp->queue) > 1) {
22870 @@ -1151,7 +1151,7 @@ dequeue_rx(struct idt77252_dev *card, st
22871 RXPRINTK("%s: Can't alloc RX skb.\n",
22872 card->name);
22873 recycle_rx_pool_skb(card, rpp);
22874 - atomic_inc(&vcc->stats->rx_err);
22875 + atomic_inc_unchecked(&vcc->stats->rx_err);
22876 return;
22877 }
22878 if (!atm_charge(vcc, skb->truesize)) {
22879 @@ -1170,7 +1170,7 @@ dequeue_rx(struct idt77252_dev *card, st
22880 __net_timestamp(skb);
22881
22882 vcc->push(vcc, skb);
22883 - atomic_inc(&vcc->stats->rx);
22884 + atomic_inc_unchecked(&vcc->stats->rx);
22885
22886 return;
22887 }
22888 @@ -1192,7 +1192,7 @@ dequeue_rx(struct idt77252_dev *card, st
22889 __net_timestamp(skb);
22890
22891 vcc->push(vcc, skb);
22892 - atomic_inc(&vcc->stats->rx);
22893 + atomic_inc_unchecked(&vcc->stats->rx);
22894
22895 if (skb->truesize > SAR_FB_SIZE_3)
22896 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
22897 @@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *car
22898 if (vcc->qos.aal != ATM_AAL0) {
22899 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
22900 card->name, vpi, vci);
22901 - atomic_inc(&vcc->stats->rx_drop);
22902 + atomic_inc_unchecked(&vcc->stats->rx_drop);
22903 goto drop;
22904 }
22905
22906 if ((sb = dev_alloc_skb(64)) == NULL) {
22907 printk("%s: Can't allocate buffers for AAL0.\n",
22908 card->name);
22909 - atomic_inc(&vcc->stats->rx_err);
22910 + atomic_inc_unchecked(&vcc->stats->rx_err);
22911 goto drop;
22912 }
22913
22914 @@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *car
22915 ATM_SKB(sb)->vcc = vcc;
22916 __net_timestamp(sb);
22917 vcc->push(vcc, sb);
22918 - atomic_inc(&vcc->stats->rx);
22919 + atomic_inc_unchecked(&vcc->stats->rx);
22920
22921 drop:
22922 skb_pull(queue, 64);
22923 @@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, s
22924
22925 if (vc == NULL) {
22926 printk("%s: NULL connection in send().\n", card->name);
22927 - atomic_inc(&vcc->stats->tx_err);
22928 + atomic_inc_unchecked(&vcc->stats->tx_err);
22929 dev_kfree_skb(skb);
22930 return -EINVAL;
22931 }
22932 if (!test_bit(VCF_TX, &vc->flags)) {
22933 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
22934 - atomic_inc(&vcc->stats->tx_err);
22935 + atomic_inc_unchecked(&vcc->stats->tx_err);
22936 dev_kfree_skb(skb);
22937 return -EINVAL;
22938 }
22939 @@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, s
22940 break;
22941 default:
22942 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
22943 - atomic_inc(&vcc->stats->tx_err);
22944 + atomic_inc_unchecked(&vcc->stats->tx_err);
22945 dev_kfree_skb(skb);
22946 return -EINVAL;
22947 }
22948
22949 if (skb_shinfo(skb)->nr_frags != 0) {
22950 printk("%s: No scatter-gather yet.\n", card->name);
22951 - atomic_inc(&vcc->stats->tx_err);
22952 + atomic_inc_unchecked(&vcc->stats->tx_err);
22953 dev_kfree_skb(skb);
22954 return -EINVAL;
22955 }
22956 @@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, s
22957
22958 err = queue_skb(card, vc, skb, oam);
22959 if (err) {
22960 - atomic_inc(&vcc->stats->tx_err);
22961 + atomic_inc_unchecked(&vcc->stats->tx_err);
22962 dev_kfree_skb(skb);
22963 return err;
22964 }
22965 @@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, v
22966 skb = dev_alloc_skb(64);
22967 if (!skb) {
22968 printk("%s: Out of memory in send_oam().\n", card->name);
22969 - atomic_inc(&vcc->stats->tx_err);
22970 + atomic_inc_unchecked(&vcc->stats->tx_err);
22971 return -ENOMEM;
22972 }
22973 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
22974 diff -urNp linux-2.6.37/drivers/atm/iphase.c linux-2.6.37/drivers/atm/iphase.c
22975 --- linux-2.6.37/drivers/atm/iphase.c 2011-01-04 19:50:19.000000000 -0500
22976 +++ linux-2.6.37/drivers/atm/iphase.c 2011-01-17 02:41:01.000000000 -0500
22977 @@ -1124,7 +1124,7 @@ static int rx_pkt(struct atm_dev *dev)
22978 status = (u_short) (buf_desc_ptr->desc_mode);
22979 if (status & (RX_CER | RX_PTE | RX_OFL))
22980 {
22981 - atomic_inc(&vcc->stats->rx_err);
22982 + atomic_inc_unchecked(&vcc->stats->rx_err);
22983 IF_ERR(printk("IA: bad packet, dropping it");)
22984 if (status & RX_CER) {
22985 IF_ERR(printk(" cause: packet CRC error\n");)
22986 @@ -1147,7 +1147,7 @@ static int rx_pkt(struct atm_dev *dev)
22987 len = dma_addr - buf_addr;
22988 if (len > iadev->rx_buf_sz) {
22989 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
22990 - atomic_inc(&vcc->stats->rx_err);
22991 + atomic_inc_unchecked(&vcc->stats->rx_err);
22992 goto out_free_desc;
22993 }
22994
22995 @@ -1297,7 +1297,7 @@ static void rx_dle_intr(struct atm_dev *
22996 ia_vcc = INPH_IA_VCC(vcc);
22997 if (ia_vcc == NULL)
22998 {
22999 - atomic_inc(&vcc->stats->rx_err);
23000 + atomic_inc_unchecked(&vcc->stats->rx_err);
23001 dev_kfree_skb_any(skb);
23002 atm_return(vcc, atm_guess_pdu2truesize(len));
23003 goto INCR_DLE;
23004 @@ -1309,7 +1309,7 @@ static void rx_dle_intr(struct atm_dev *
23005 if ((length > iadev->rx_buf_sz) || (length >
23006 (skb->len - sizeof(struct cpcs_trailer))))
23007 {
23008 - atomic_inc(&vcc->stats->rx_err);
23009 + atomic_inc_unchecked(&vcc->stats->rx_err);
23010 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
23011 length, skb->len);)
23012 dev_kfree_skb_any(skb);
23013 @@ -1325,7 +1325,7 @@ static void rx_dle_intr(struct atm_dev *
23014
23015 IF_RX(printk("rx_dle_intr: skb push");)
23016 vcc->push(vcc,skb);
23017 - atomic_inc(&vcc->stats->rx);
23018 + atomic_inc_unchecked(&vcc->stats->rx);
23019 iadev->rx_pkt_cnt++;
23020 }
23021 INCR_DLE:
23022 @@ -2807,15 +2807,15 @@ static int ia_ioctl(struct atm_dev *dev,
23023 {
23024 struct k_sonet_stats *stats;
23025 stats = &PRIV(_ia_dev[board])->sonet_stats;
23026 - printk("section_bip: %d\n", atomic_read(&stats->section_bip));
23027 - printk("line_bip : %d\n", atomic_read(&stats->line_bip));
23028 - printk("path_bip : %d\n", atomic_read(&stats->path_bip));
23029 - printk("line_febe : %d\n", atomic_read(&stats->line_febe));
23030 - printk("path_febe : %d\n", atomic_read(&stats->path_febe));
23031 - printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
23032 - printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
23033 - printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
23034 - printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
23035 + printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
23036 + printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
23037 + printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
23038 + printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
23039 + printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
23040 + printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
23041 + printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
23042 + printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
23043 + printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
23044 }
23045 ia_cmds.status = 0;
23046 break;
23047 @@ -2920,7 +2920,7 @@ static int ia_pkt_tx (struct atm_vcc *vc
23048 if ((desc == 0) || (desc > iadev->num_tx_desc))
23049 {
23050 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
23051 - atomic_inc(&vcc->stats->tx);
23052 + atomic_inc_unchecked(&vcc->stats->tx);
23053 if (vcc->pop)
23054 vcc->pop(vcc, skb);
23055 else
23056 @@ -3025,14 +3025,14 @@ static int ia_pkt_tx (struct atm_vcc *vc
23057 ATM_DESC(skb) = vcc->vci;
23058 skb_queue_tail(&iadev->tx_dma_q, skb);
23059
23060 - atomic_inc(&vcc->stats->tx);
23061 + atomic_inc_unchecked(&vcc->stats->tx);
23062 iadev->tx_pkt_cnt++;
23063 /* Increment transaction counter */
23064 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
23065
23066 #if 0
23067 /* add flow control logic */
23068 - if (atomic_read(&vcc->stats->tx) % 20 == 0) {
23069 + if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
23070 if (iavcc->vc_desc_cnt > 10) {
23071 vcc->tx_quota = vcc->tx_quota * 3 / 4;
23072 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
23073 diff -urNp linux-2.6.37/drivers/atm/lanai.c linux-2.6.37/drivers/atm/lanai.c
23074 --- linux-2.6.37/drivers/atm/lanai.c 2011-01-04 19:50:19.000000000 -0500
23075 +++ linux-2.6.37/drivers/atm/lanai.c 2011-01-17 02:41:01.000000000 -0500
23076 @@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct l
23077 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
23078 lanai_endtx(lanai, lvcc);
23079 lanai_free_skb(lvcc->tx.atmvcc, skb);
23080 - atomic_inc(&lvcc->tx.atmvcc->stats->tx);
23081 + atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
23082 }
23083
23084 /* Try to fill the buffer - don't call unless there is backlog */
23085 @@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc
23086 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
23087 __net_timestamp(skb);
23088 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
23089 - atomic_inc(&lvcc->rx.atmvcc->stats->rx);
23090 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
23091 out:
23092 lvcc->rx.buf.ptr = end;
23093 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
23094 @@ -1668,7 +1668,7 @@ static int handle_service(struct lanai_d
23095 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
23096 "vcc %d\n", lanai->number, (unsigned int) s, vci);
23097 lanai->stats.service_rxnotaal5++;
23098 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
23099 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
23100 return 0;
23101 }
23102 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
23103 @@ -1680,7 +1680,7 @@ static int handle_service(struct lanai_d
23104 int bytes;
23105 read_unlock(&vcc_sklist_lock);
23106 DPRINTK("got trashed rx pdu on vci %d\n", vci);
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_trash++;
23110 bytes = (SERVICE_GET_END(s) * 16) -
23111 (((unsigned long) lvcc->rx.buf.ptr) -
23112 @@ -1692,7 +1692,7 @@ static int handle_service(struct lanai_d
23113 }
23114 if (s & SERVICE_STREAM) {
23115 read_unlock(&vcc_sklist_lock);
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_stream++;
23119 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
23120 "PDU on VCI %d!\n", lanai->number, vci);
23121 @@ -1700,7 +1700,7 @@ static int handle_service(struct lanai_d
23122 return 0;
23123 }
23124 DPRINTK("got rx crc error on vci %d\n", vci);
23125 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
23126 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
23127 lvcc->stats.x.aal5.service_rxcrc++;
23128 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
23129 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
23130 diff -urNp linux-2.6.37/drivers/atm/nicstar.c linux-2.6.37/drivers/atm/nicstar.c
23131 --- linux-2.6.37/drivers/atm/nicstar.c 2011-01-04 19:50:19.000000000 -0500
23132 +++ linux-2.6.37/drivers/atm/nicstar.c 2011-01-17 02:41:01.000000000 -0500
23133 @@ -1654,7 +1654,7 @@ static int ns_send(struct atm_vcc *vcc,
23134 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
23135 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
23136 card->index);
23137 - atomic_inc(&vcc->stats->tx_err);
23138 + atomic_inc_unchecked(&vcc->stats->tx_err);
23139 dev_kfree_skb_any(skb);
23140 return -EINVAL;
23141 }
23142 @@ -1662,7 +1662,7 @@ static int ns_send(struct atm_vcc *vcc,
23143 if (!vc->tx) {
23144 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
23145 card->index);
23146 - atomic_inc(&vcc->stats->tx_err);
23147 + atomic_inc_unchecked(&vcc->stats->tx_err);
23148 dev_kfree_skb_any(skb);
23149 return -EINVAL;
23150 }
23151 @@ -1670,14 +1670,14 @@ static int ns_send(struct atm_vcc *vcc,
23152 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
23153 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
23154 card->index);
23155 - atomic_inc(&vcc->stats->tx_err);
23156 + atomic_inc_unchecked(&vcc->stats->tx_err);
23157 dev_kfree_skb_any(skb);
23158 return -EINVAL;
23159 }
23160
23161 if (skb_shinfo(skb)->nr_frags != 0) {
23162 printk("nicstar%d: No scatter-gather yet.\n", card->index);
23163 - atomic_inc(&vcc->stats->tx_err);
23164 + atomic_inc_unchecked(&vcc->stats->tx_err);
23165 dev_kfree_skb_any(skb);
23166 return -EINVAL;
23167 }
23168 @@ -1725,11 +1725,11 @@ static int ns_send(struct atm_vcc *vcc,
23169 }
23170
23171 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
23172 - atomic_inc(&vcc->stats->tx_err);
23173 + atomic_inc_unchecked(&vcc->stats->tx_err);
23174 dev_kfree_skb_any(skb);
23175 return -EIO;
23176 }
23177 - atomic_inc(&vcc->stats->tx);
23178 + atomic_inc_unchecked(&vcc->stats->tx);
23179
23180 return 0;
23181 }
23182 @@ -2046,14 +2046,14 @@ static void dequeue_rx(ns_dev * card, ns
23183 printk
23184 ("nicstar%d: Can't allocate buffers for aal0.\n",
23185 card->index);
23186 - atomic_add(i, &vcc->stats->rx_drop);
23187 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
23188 break;
23189 }
23190 if (!atm_charge(vcc, sb->truesize)) {
23191 RXPRINTK
23192 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
23193 card->index);
23194 - atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
23195 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
23196 dev_kfree_skb_any(sb);
23197 break;
23198 }
23199 @@ -2068,7 +2068,7 @@ static void dequeue_rx(ns_dev * card, ns
23200 ATM_SKB(sb)->vcc = vcc;
23201 __net_timestamp(sb);
23202 vcc->push(vcc, sb);
23203 - atomic_inc(&vcc->stats->rx);
23204 + atomic_inc_unchecked(&vcc->stats->rx);
23205 cell += ATM_CELL_PAYLOAD;
23206 }
23207
23208 @@ -2085,7 +2085,7 @@ static void dequeue_rx(ns_dev * card, ns
23209 if (iovb == NULL) {
23210 printk("nicstar%d: Out of iovec buffers.\n",
23211 card->index);
23212 - atomic_inc(&vcc->stats->rx_drop);
23213 + atomic_inc_unchecked(&vcc->stats->rx_drop);
23214 recycle_rx_buf(card, skb);
23215 return;
23216 }
23217 @@ -2109,7 +2109,7 @@ static void dequeue_rx(ns_dev * card, ns
23218 small or large buffer itself. */
23219 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
23220 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
23221 - atomic_inc(&vcc->stats->rx_err);
23222 + atomic_inc_unchecked(&vcc->stats->rx_err);
23223 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
23224 NS_MAX_IOVECS);
23225 NS_PRV_IOVCNT(iovb) = 0;
23226 @@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns
23227 ("nicstar%d: Expected a small buffer, and this is not one.\n",
23228 card->index);
23229 which_list(card, skb);
23230 - atomic_inc(&vcc->stats->rx_err);
23231 + atomic_inc_unchecked(&vcc->stats->rx_err);
23232 recycle_rx_buf(card, skb);
23233 vc->rx_iov = NULL;
23234 recycle_iov_buf(card, iovb);
23235 @@ -2142,7 +2142,7 @@ static void dequeue_rx(ns_dev * card, ns
23236 ("nicstar%d: Expected a large buffer, and this is not one.\n",
23237 card->index);
23238 which_list(card, skb);
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));
23243 vc->rx_iov = NULL;
23244 @@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns
23245 printk(" - PDU size mismatch.\n");
23246 else
23247 printk(".\n");
23248 - atomic_inc(&vcc->stats->rx_err);
23249 + atomic_inc_unchecked(&vcc->stats->rx_err);
23250 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
23251 NS_PRV_IOVCNT(iovb));
23252 vc->rx_iov = NULL;
23253 @@ -2179,7 +2179,7 @@ static void dequeue_rx(ns_dev * card, ns
23254 /* skb points to a small buffer */
23255 if (!atm_charge(vcc, skb->truesize)) {
23256 push_rxbufs(card, skb);
23257 - atomic_inc(&vcc->stats->rx_drop);
23258 + atomic_inc_unchecked(&vcc->stats->rx_drop);
23259 } else {
23260 skb_put(skb, len);
23261 dequeue_sm_buf(card, skb);
23262 @@ -2189,7 +2189,7 @@ static void dequeue_rx(ns_dev * card, ns
23263 ATM_SKB(skb)->vcc = vcc;
23264 __net_timestamp(skb);
23265 vcc->push(vcc, skb);
23266 - atomic_inc(&vcc->stats->rx);
23267 + atomic_inc_unchecked(&vcc->stats->rx);
23268 }
23269 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
23270 struct sk_buff *sb;
23271 @@ -2200,7 +2200,7 @@ static void dequeue_rx(ns_dev * card, ns
23272 if (len <= NS_SMBUFSIZE) {
23273 if (!atm_charge(vcc, sb->truesize)) {
23274 push_rxbufs(card, sb);
23275 - atomic_inc(&vcc->stats->rx_drop);
23276 + atomic_inc_unchecked(&vcc->stats->rx_drop);
23277 } else {
23278 skb_put(sb, len);
23279 dequeue_sm_buf(card, sb);
23280 @@ -2210,7 +2210,7 @@ static void dequeue_rx(ns_dev * card, ns
23281 ATM_SKB(sb)->vcc = vcc;
23282 __net_timestamp(sb);
23283 vcc->push(vcc, sb);
23284 - atomic_inc(&vcc->stats->rx);
23285 + atomic_inc_unchecked(&vcc->stats->rx);
23286 }
23287
23288 push_rxbufs(card, skb);
23289 @@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns
23290
23291 if (!atm_charge(vcc, skb->truesize)) {
23292 push_rxbufs(card, skb);
23293 - atomic_inc(&vcc->stats->rx_drop);
23294 + atomic_inc_unchecked(&vcc->stats->rx_drop);
23295 } else {
23296 dequeue_lg_buf(card, skb);
23297 #ifdef NS_USE_DESTRUCTORS
23298 @@ -2232,7 +2232,7 @@ static void dequeue_rx(ns_dev * card, ns
23299 ATM_SKB(skb)->vcc = vcc;
23300 __net_timestamp(skb);
23301 vcc->push(vcc, skb);
23302 - atomic_inc(&vcc->stats->rx);
23303 + atomic_inc_unchecked(&vcc->stats->rx);
23304 }
23305
23306 push_rxbufs(card, sb);
23307 @@ -2253,7 +2253,7 @@ static void dequeue_rx(ns_dev * card, ns
23308 printk
23309 ("nicstar%d: Out of huge buffers.\n",
23310 card->index);
23311 - atomic_inc(&vcc->stats->rx_drop);
23312 + atomic_inc_unchecked(&vcc->stats->rx_drop);
23313 recycle_iovec_rx_bufs(card,
23314 (struct iovec *)
23315 iovb->data,
23316 @@ -2304,7 +2304,7 @@ static void dequeue_rx(ns_dev * card, ns
23317 card->hbpool.count++;
23318 } else
23319 dev_kfree_skb_any(hb);
23320 - atomic_inc(&vcc->stats->rx_drop);
23321 + atomic_inc_unchecked(&vcc->stats->rx_drop);
23322 } else {
23323 /* Copy the small buffer to the huge buffer */
23324 sb = (struct sk_buff *)iov->iov_base;
23325 @@ -2341,7 +2341,7 @@ static void dequeue_rx(ns_dev * card, ns
23326 #endif /* NS_USE_DESTRUCTORS */
23327 __net_timestamp(hb);
23328 vcc->push(vcc, hb);
23329 - atomic_inc(&vcc->stats->rx);
23330 + atomic_inc_unchecked(&vcc->stats->rx);
23331 }
23332 }
23333
23334 diff -urNp linux-2.6.37/drivers/atm/solos-pci.c linux-2.6.37/drivers/atm/solos-pci.c
23335 --- linux-2.6.37/drivers/atm/solos-pci.c 2011-01-04 19:50:19.000000000 -0500
23336 +++ linux-2.6.37/drivers/atm/solos-pci.c 2011-01-17 02:41:01.000000000 -0500
23337 @@ -717,7 +717,7 @@ void solos_bh(unsigned long card_arg)
23338 }
23339 atm_charge(vcc, skb->truesize);
23340 vcc->push(vcc, skb);
23341 - atomic_inc(&vcc->stats->rx);
23342 + atomic_inc_unchecked(&vcc->stats->rx);
23343 break;
23344
23345 case PKT_STATUS:
23346 @@ -1025,7 +1025,7 @@ static uint32_t fpga_tx(struct solos_car
23347 vcc = SKB_CB(oldskb)->vcc;
23348
23349 if (vcc) {
23350 - atomic_inc(&vcc->stats->tx);
23351 + atomic_inc_unchecked(&vcc->stats->tx);
23352 solos_pop(vcc, oldskb);
23353 } else
23354 dev_kfree_skb_irq(oldskb);
23355 diff -urNp linux-2.6.37/drivers/atm/suni.c linux-2.6.37/drivers/atm/suni.c
23356 --- linux-2.6.37/drivers/atm/suni.c 2011-01-04 19:50:19.000000000 -0500
23357 +++ linux-2.6.37/drivers/atm/suni.c 2011-01-17 02:41:01.000000000 -0500
23358 @@ -50,8 +50,8 @@ static DEFINE_SPINLOCK(sunis_lock);
23359
23360
23361 #define ADD_LIMITED(s,v) \
23362 - atomic_add((v),&stats->s); \
23363 - if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
23364 + atomic_add_unchecked((v),&stats->s); \
23365 + if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
23366
23367
23368 static void suni_hz(unsigned long from_timer)
23369 diff -urNp linux-2.6.37/drivers/atm/uPD98402.c linux-2.6.37/drivers/atm/uPD98402.c
23370 --- linux-2.6.37/drivers/atm/uPD98402.c 2011-01-04 19:50:19.000000000 -0500
23371 +++ linux-2.6.37/drivers/atm/uPD98402.c 2011-01-17 02:41:01.000000000 -0500
23372 @@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *d
23373 struct sonet_stats tmp;
23374 int error = 0;
23375
23376 - atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
23377 + atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
23378 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
23379 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
23380 if (zero && !error) {
23381 @@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev
23382
23383
23384 #define ADD_LIMITED(s,v) \
23385 - { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
23386 - if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
23387 - atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
23388 + { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
23389 + if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
23390 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
23391
23392
23393 static void stat_event(struct atm_dev *dev)
23394 @@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev
23395 if (reason & uPD98402_INT_PFM) stat_event(dev);
23396 if (reason & uPD98402_INT_PCO) {
23397 (void) GET(PCOCR); /* clear interrupt cause */
23398 - atomic_add(GET(HECCT),
23399 + atomic_add_unchecked(GET(HECCT),
23400 &PRIV(dev)->sonet_stats.uncorr_hcs);
23401 }
23402 if ((reason & uPD98402_INT_RFO) &&
23403 @@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev
23404 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
23405 uPD98402_INT_LOS),PIMR); /* enable them */
23406 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
23407 - atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
23408 - atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
23409 - atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
23410 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
23411 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
23412 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
23413 return 0;
23414 }
23415
23416 diff -urNp linux-2.6.37/drivers/atm/zatm.c linux-2.6.37/drivers/atm/zatm.c
23417 --- linux-2.6.37/drivers/atm/zatm.c 2011-01-04 19:50:19.000000000 -0500
23418 +++ linux-2.6.37/drivers/atm/zatm.c 2011-01-17 02:41:01.000000000 -0500
23419 @@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy
23420 }
23421 if (!size) {
23422 dev_kfree_skb_irq(skb);
23423 - if (vcc) atomic_inc(&vcc->stats->rx_err);
23424 + if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
23425 continue;
23426 }
23427 if (!atm_charge(vcc,skb->truesize)) {
23428 @@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy
23429 skb->len = size;
23430 ATM_SKB(skb)->vcc = vcc;
23431 vcc->push(vcc,skb);
23432 - atomic_inc(&vcc->stats->rx);
23433 + atomic_inc_unchecked(&vcc->stats->rx);
23434 }
23435 zout(pos & 0xffff,MTA(mbx));
23436 #if 0 /* probably a stupid idea */
23437 @@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD
23438 skb_queue_head(&zatm_vcc->backlog,skb);
23439 break;
23440 }
23441 - atomic_inc(&vcc->stats->tx);
23442 + atomic_inc_unchecked(&vcc->stats->tx);
23443 wake_up(&zatm_vcc->tx_wait);
23444 }
23445
23446 diff -urNp linux-2.6.37/drivers/block/cciss.c linux-2.6.37/drivers/block/cciss.c
23447 --- linux-2.6.37/drivers/block/cciss.c 2011-01-04 19:50:19.000000000 -0500
23448 +++ linux-2.6.37/drivers/block/cciss.c 2011-01-17 02:41:01.000000000 -0500
23449 @@ -1112,6 +1112,8 @@ static int cciss_ioctl32_passthru(struct
23450 int err;
23451 u32 cp;
23452
23453 + memset(&arg64, 0, sizeof(arg64));
23454 +
23455 err = 0;
23456 err |=
23457 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
23458 diff -urNp linux-2.6.37/drivers/char/agp/frontend.c linux-2.6.37/drivers/char/agp/frontend.c
23459 --- linux-2.6.37/drivers/char/agp/frontend.c 2011-01-04 19:50:19.000000000 -0500
23460 +++ linux-2.6.37/drivers/char/agp/frontend.c 2011-01-17 02:41:01.000000000 -0500
23461 @@ -817,7 +817,7 @@ static int agpioc_reserve_wrap(struct ag
23462 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
23463 return -EFAULT;
23464
23465 - if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
23466 + if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
23467 return -EFAULT;
23468
23469 client = agp_find_client_by_pid(reserve.pid);
23470 diff -urNp linux-2.6.37/drivers/char/agp/intel-agp.c linux-2.6.37/drivers/char/agp/intel-agp.c
23471 --- linux-2.6.37/drivers/char/agp/intel-agp.c 2011-01-04 19:50:19.000000000 -0500
23472 +++ linux-2.6.37/drivers/char/agp/intel-agp.c 2011-01-17 02:41:01.000000000 -0500
23473 @@ -903,7 +903,7 @@ static struct pci_device_id agp_intel_pc
23474 ID(PCI_DEVICE_ID_INTEL_SANDYBRIDGE_HB),
23475 ID(PCI_DEVICE_ID_INTEL_SANDYBRIDGE_M_HB),
23476 ID(PCI_DEVICE_ID_INTEL_SANDYBRIDGE_S_HB),
23477 - { }
23478 + { 0, 0, 0, 0, 0, 0, 0 }
23479 };
23480
23481 MODULE_DEVICE_TABLE(pci, agp_intel_pci_table);
23482 diff -urNp linux-2.6.37/drivers/char/hpet.c linux-2.6.37/drivers/char/hpet.c
23483 --- linux-2.6.37/drivers/char/hpet.c 2011-01-04 19:50:19.000000000 -0500
23484 +++ linux-2.6.37/drivers/char/hpet.c 2011-01-17 02:41:01.000000000 -0500
23485 @@ -553,7 +553,7 @@ static inline unsigned long hpet_time_di
23486 }
23487
23488 static int
23489 -hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
23490 +hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
23491 struct hpet_info *info)
23492 {
23493 struct hpet_timer __iomem *timer;
23494 @@ -1043,7 +1043,7 @@ static struct acpi_driver hpet_acpi_driv
23495 },
23496 };
23497
23498 -static struct miscdevice hpet_misc = { HPET_MINOR, "hpet", &hpet_fops };
23499 +static struct miscdevice hpet_misc = { HPET_MINOR, "hpet", &hpet_fops, {NULL, NULL}, NULL, NULL };
23500
23501 static int __init hpet_init(void)
23502 {
23503 diff -urNp linux-2.6.37/drivers/char/hvc_console.h linux-2.6.37/drivers/char/hvc_console.h
23504 --- linux-2.6.37/drivers/char/hvc_console.h 2011-01-04 19:50:19.000000000 -0500
23505 +++ linux-2.6.37/drivers/char/hvc_console.h 2011-01-17 02:41:01.000000000 -0500
23506 @@ -82,6 +82,7 @@ extern int hvc_instantiate(uint32_t vter
23507 /* register a vterm for hvc tty operation (module_init or hotplug add) */
23508 extern struct hvc_struct * hvc_alloc(uint32_t vtermno, int data,
23509 const struct hv_ops *ops, int outbuf_size);
23510 +
23511 /* remove a vterm from hvc tty operation (module_exit or hotplug remove) */
23512 extern int hvc_remove(struct hvc_struct *hp);
23513
23514 diff -urNp linux-2.6.37/drivers/char/hvcs.c linux-2.6.37/drivers/char/hvcs.c
23515 --- linux-2.6.37/drivers/char/hvcs.c 2011-01-04 19:50:19.000000000 -0500
23516 +++ linux-2.6.37/drivers/char/hvcs.c 2011-01-17 02:41:01.000000000 -0500
23517 @@ -270,7 +270,7 @@ struct hvcs_struct {
23518 unsigned int index;
23519
23520 struct tty_struct *tty;
23521 - int open_count;
23522 + atomic_t open_count;
23523
23524 /*
23525 * Used to tell the driver kernel_thread what operations need to take
23526 @@ -420,7 +420,7 @@ static ssize_t hvcs_vterm_state_store(st
23527
23528 spin_lock_irqsave(&hvcsd->lock, flags);
23529
23530 - if (hvcsd->open_count > 0) {
23531 + if (atomic_read(&hvcsd->open_count) > 0) {
23532 spin_unlock_irqrestore(&hvcsd->lock, flags);
23533 printk(KERN_INFO "HVCS: vterm state unchanged. "
23534 "The hvcs device node is still in use.\n");
23535 @@ -1136,7 +1136,7 @@ static int hvcs_open(struct tty_struct *
23536 if ((retval = hvcs_partner_connect(hvcsd)))
23537 goto error_release;
23538
23539 - hvcsd->open_count = 1;
23540 + atomic_set(&hvcsd->open_count, 1);
23541 hvcsd->tty = tty;
23542 tty->driver_data = hvcsd;
23543
23544 @@ -1170,7 +1170,7 @@ fast_open:
23545
23546 spin_lock_irqsave(&hvcsd->lock, flags);
23547 kref_get(&hvcsd->kref);
23548 - hvcsd->open_count++;
23549 + atomic_inc(&hvcsd->open_count);
23550 hvcsd->todo_mask |= HVCS_SCHED_READ;
23551 spin_unlock_irqrestore(&hvcsd->lock, flags);
23552
23553 @@ -1214,7 +1214,7 @@ static void hvcs_close(struct tty_struct
23554 hvcsd = tty->driver_data;
23555
23556 spin_lock_irqsave(&hvcsd->lock, flags);
23557 - if (--hvcsd->open_count == 0) {
23558 + if (atomic_dec_and_test(&hvcsd->open_count)) {
23559
23560 vio_disable_interrupts(hvcsd->vdev);
23561
23562 @@ -1240,10 +1240,10 @@ static void hvcs_close(struct tty_struct
23563 free_irq(irq, hvcsd);
23564 kref_put(&hvcsd->kref, destroy_hvcs_struct);
23565 return;
23566 - } else if (hvcsd->open_count < 0) {
23567 + } else if (atomic_read(&hvcsd->open_count) < 0) {
23568 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
23569 " is missmanaged.\n",
23570 - hvcsd->vdev->unit_address, hvcsd->open_count);
23571 + hvcsd->vdev->unit_address, atomic_read(&hvcsd->open_count));
23572 }
23573
23574 spin_unlock_irqrestore(&hvcsd->lock, flags);
23575 @@ -1259,7 +1259,7 @@ static void hvcs_hangup(struct tty_struc
23576
23577 spin_lock_irqsave(&hvcsd->lock, flags);
23578 /* Preserve this so that we know how many kref refs to put */
23579 - temp_open_count = hvcsd->open_count;
23580 + temp_open_count = atomic_read(&hvcsd->open_count);
23581
23582 /*
23583 * Don't kref put inside the spinlock because the destruction
23584 @@ -1274,7 +1274,7 @@ static void hvcs_hangup(struct tty_struc
23585 hvcsd->tty->driver_data = NULL;
23586 hvcsd->tty = NULL;
23587
23588 - hvcsd->open_count = 0;
23589 + atomic_set(&hvcsd->open_count, 0);
23590
23591 /* This will drop any buffered data on the floor which is OK in a hangup
23592 * scenario. */
23593 @@ -1345,7 +1345,7 @@ static int hvcs_write(struct tty_struct
23594 * the middle of a write operation? This is a crummy place to do this
23595 * but we want to keep it all in the spinlock.
23596 */
23597 - if (hvcsd->open_count <= 0) {
23598 + if (atomic_read(&hvcsd->open_count) <= 0) {
23599 spin_unlock_irqrestore(&hvcsd->lock, flags);
23600 return -ENODEV;
23601 }
23602 @@ -1419,7 +1419,7 @@ static int hvcs_write_room(struct tty_st
23603 {
23604 struct hvcs_struct *hvcsd = tty->driver_data;
23605
23606 - if (!hvcsd || hvcsd->open_count <= 0)
23607 + if (!hvcsd || atomic_read(&hvcsd->open_count) <= 0)
23608 return 0;
23609
23610 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
23611 diff -urNp linux-2.6.37/drivers/char/hvc_xen.c linux-2.6.37/drivers/char/hvc_xen.c
23612 --- linux-2.6.37/drivers/char/hvc_xen.c 2011-01-04 19:50:19.000000000 -0500
23613 +++ linux-2.6.37/drivers/char/hvc_xen.c 2011-01-17 02:41:01.000000000 -0500
23614 @@ -123,7 +123,7 @@ static int domU_read_console(uint32_t vt
23615 return recv;
23616 }
23617
23618 -static struct hv_ops domU_hvc_ops = {
23619 +static const struct hv_ops domU_hvc_ops = {
23620 .get_chars = domU_read_console,
23621 .put_chars = domU_write_console,
23622 .notifier_add = notifier_add_irq,
23623 @@ -149,7 +149,7 @@ static int dom0_write_console(uint32_t v
23624 return len;
23625 }
23626
23627 -static struct hv_ops dom0_hvc_ops = {
23628 +static const struct hv_ops dom0_hvc_ops = {
23629 .get_chars = dom0_read_console,
23630 .put_chars = dom0_write_console,
23631 .notifier_add = notifier_add_irq,
23632 @@ -160,7 +160,7 @@ static struct hv_ops dom0_hvc_ops = {
23633 static int __init xen_hvc_init(void)
23634 {
23635 struct hvc_struct *hp;
23636 - struct hv_ops *ops;
23637 + const struct hv_ops *ops;
23638
23639 if (!xen_pv_domain())
23640 return -ENODEV;
23641 @@ -203,7 +203,7 @@ static void __exit xen_hvc_fini(void)
23642
23643 static int xen_cons_init(void)
23644 {
23645 - struct hv_ops *ops;
23646 + const struct hv_ops *ops;
23647
23648 if (!xen_pv_domain())
23649 return 0;
23650 diff -urNp linux-2.6.37/drivers/char/ipmi/ipmi_msghandler.c linux-2.6.37/drivers/char/ipmi/ipmi_msghandler.c
23651 --- linux-2.6.37/drivers/char/ipmi/ipmi_msghandler.c 2011-01-04 19:50:19.000000000 -0500
23652 +++ linux-2.6.37/drivers/char/ipmi/ipmi_msghandler.c 2011-01-17 02:41:01.000000000 -0500
23653 @@ -414,7 +414,7 @@ struct ipmi_smi {
23654 struct proc_dir_entry *proc_dir;
23655 char proc_dir_name[10];
23656
23657 - atomic_t stats[IPMI_NUM_STATS];
23658 + atomic_unchecked_t stats[IPMI_NUM_STATS];
23659
23660 /*
23661 * run_to_completion duplicate of smb_info, smi_info
23662 @@ -447,9 +447,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
23663
23664
23665 #define ipmi_inc_stat(intf, stat) \
23666 - atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
23667 + atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
23668 #define ipmi_get_stat(intf, stat) \
23669 - ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
23670 + ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
23671
23672 static int is_lan_addr(struct ipmi_addr *addr)
23673 {
23674 @@ -2817,7 +2817,7 @@ int ipmi_register_smi(struct ipmi_smi_ha
23675 INIT_LIST_HEAD(&intf->cmd_rcvrs);
23676 init_waitqueue_head(&intf->waitq);
23677 for (i = 0; i < IPMI_NUM_STATS; i++)
23678 - atomic_set(&intf->stats[i], 0);
23679 + atomic_set_unchecked(&intf->stats[i], 0);
23680
23681 intf->proc_dir = NULL;
23682
23683 diff -urNp linux-2.6.37/drivers/char/ipmi/ipmi_si_intf.c linux-2.6.37/drivers/char/ipmi/ipmi_si_intf.c
23684 --- linux-2.6.37/drivers/char/ipmi/ipmi_si_intf.c 2011-01-04 19:50:19.000000000 -0500
23685 +++ linux-2.6.37/drivers/char/ipmi/ipmi_si_intf.c 2011-01-17 02:41:01.000000000 -0500
23686 @@ -286,7 +286,7 @@ struct smi_info {
23687 unsigned char slave_addr;
23688
23689 /* Counters and things for the proc filesystem. */
23690 - atomic_t stats[SI_NUM_STATS];
23691 + atomic_unchecked_t stats[SI_NUM_STATS];
23692
23693 struct task_struct *thread;
23694
23695 @@ -294,9 +294,9 @@ struct smi_info {
23696 };
23697
23698 #define smi_inc_stat(smi, stat) \
23699 - atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
23700 + atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
23701 #define smi_get_stat(smi, stat) \
23702 - ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
23703 + ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
23704
23705 #define SI_MAX_PARMS 4
23706
23707 @@ -3178,7 +3178,7 @@ static int try_smi_init(struct smi_info
23708 atomic_set(&new_smi->req_events, 0);
23709 new_smi->run_to_completion = 0;
23710 for (i = 0; i < SI_NUM_STATS; i++)
23711 - atomic_set(&new_smi->stats[i], 0);
23712 + atomic_set_unchecked(&new_smi->stats[i], 0);
23713
23714 new_smi->interrupt_disabled = 1;
23715 atomic_set(&new_smi->stop_operation, 0);
23716 diff -urNp linux-2.6.37/drivers/char/mem.c linux-2.6.37/drivers/char/mem.c
23717 --- linux-2.6.37/drivers/char/mem.c 2011-01-04 19:50:19.000000000 -0500
23718 +++ linux-2.6.37/drivers/char/mem.c 2011-01-17 02:41:01.000000000 -0500
23719 @@ -18,6 +18,7 @@
23720 #include <linux/raw.h>
23721 #include <linux/tty.h>
23722 #include <linux/capability.h>
23723 +#include <linux/security.h>
23724 #include <linux/ptrace.h>
23725 #include <linux/device.h>
23726 #include <linux/highmem.h>
23727 @@ -34,6 +35,10 @@
23728 # include <linux/efi.h>
23729 #endif
23730
23731 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
23732 +extern struct file_operations grsec_fops;
23733 +#endif
23734 +
23735 static inline unsigned long size_inside_page(unsigned long start,
23736 unsigned long size)
23737 {
23738 @@ -120,6 +125,7 @@ static ssize_t read_mem(struct file *fil
23739
23740 while (count > 0) {
23741 unsigned long remaining;
23742 + char *temp;
23743
23744 sz = size_inside_page(p, count);
23745
23746 @@ -135,7 +141,23 @@ static ssize_t read_mem(struct file *fil
23747 if (!ptr)
23748 return -EFAULT;
23749
23750 - remaining = copy_to_user(buf, ptr, sz);
23751 +#ifdef CONFIG_PAX_USERCOPY
23752 + temp = kmalloc(sz, GFP_KERNEL);
23753 + if (!temp) {
23754 + unxlate_dev_mem_ptr(p, ptr);
23755 + return -ENOMEM;
23756 + }
23757 + memcpy(temp, ptr, sz);
23758 +#else
23759 + temp = ptr;
23760 +#endif
23761 +
23762 + remaining = copy_to_user(buf, temp, sz);
23763 +
23764 +#ifdef CONFIG_PAX_USERCOPY
23765 + kfree(temp);
23766 +#endif
23767 +
23768 unxlate_dev_mem_ptr(p, ptr);
23769 if (remaining)
23770 return -EFAULT;
23771 @@ -161,6 +183,11 @@ static ssize_t write_mem(struct file *fi
23772 if (!valid_phys_addr_range(p, count))
23773 return -EFAULT;
23774
23775 +#ifdef CONFIG_GRKERNSEC_KMEM
23776 + gr_handle_mem_write();
23777 + return -EPERM;
23778 +#endif
23779 +
23780 written = 0;
23781
23782 #ifdef __ARCH_HAS_NO_PAGE_ZERO_MAPPED
23783 @@ -316,6 +343,11 @@ static int mmap_mem(struct file *file, s
23784 &vma->vm_page_prot))
23785 return -EINVAL;
23786
23787 +#ifdef CONFIG_GRKERNSEC_KMEM
23788 + if (gr_handle_mem_mmap(vma->vm_pgoff << PAGE_SHIFT, vma))
23789 + return -EPERM;
23790 +#endif
23791 +
23792 vma->vm_page_prot = phys_mem_access_prot(file, vma->vm_pgoff,
23793 size,
23794 vma->vm_page_prot);
23795 @@ -398,9 +430,8 @@ static ssize_t read_kmem(struct file *fi
23796 size_t count, loff_t *ppos)
23797 {
23798 unsigned long p = *ppos;
23799 - ssize_t low_count, read, sz;
23800 + ssize_t low_count, read, sz, err = 0;
23801 char * kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
23802 - int err = 0;
23803
23804 read = 0;
23805 if (p < (unsigned long) high_memory) {
23806 @@ -422,6 +453,8 @@ static ssize_t read_kmem(struct file *fi
23807 }
23808 #endif
23809 while (low_count > 0) {
23810 + char *temp;
23811 +
23812 sz = size_inside_page(p, low_count);
23813
23814 /*
23815 @@ -431,7 +464,22 @@ static ssize_t read_kmem(struct file *fi
23816 */
23817 kbuf = xlate_dev_kmem_ptr((char *)p);
23818
23819 - if (copy_to_user(buf, kbuf, sz))
23820 +#ifdef CONFIG_PAX_USERCOPY
23821 + temp = kmalloc(sz, GFP_KERNEL);
23822 + if (!temp)
23823 + return -ENOMEM;
23824 + memcpy(temp, kbuf, sz);
23825 +#else
23826 + temp = kbuf;
23827 +#endif
23828 +
23829 + err = copy_to_user(buf, temp, sz);
23830 +
23831 +#ifdef CONFIG_PAX_USERCOPY
23832 + kfree(temp);
23833 +#endif
23834 +
23835 + if (err)
23836 return -EFAULT;
23837 buf += sz;
23838 p += sz;
23839 @@ -530,6 +578,11 @@ static ssize_t write_kmem(struct file *f
23840 char * kbuf; /* k-addr because vwrite() takes vmlist_lock rwlock */
23841 int err = 0;
23842
23843 +#ifdef CONFIG_GRKERNSEC_KMEM
23844 + gr_handle_kmem_write();
23845 + return -EPERM;
23846 +#endif
23847 +
23848 if (p < (unsigned long) high_memory) {
23849 unsigned long to_write = min_t(unsigned long, count,
23850 (unsigned long)high_memory - p);
23851 @@ -731,6 +784,16 @@ static loff_t memory_lseek(struct file *
23852
23853 static int open_port(struct inode * inode, struct file * filp)
23854 {
23855 +#ifdef CONFIG_GRKERNSEC_KMEM
23856 + gr_handle_open_port();
23857 + return -EPERM;
23858 +#endif
23859 +
23860 + return capable(CAP_SYS_RAWIO) ? 0 : -EPERM;
23861 +}
23862 +
23863 +static int open_mem(struct inode * inode, struct file * filp)
23864 +{
23865 return capable(CAP_SYS_RAWIO) ? 0 : -EPERM;
23866 }
23867
23868 @@ -738,7 +801,6 @@ static int open_port(struct inode * inod
23869 #define full_lseek null_lseek
23870 #define write_zero write_null
23871 #define read_full read_zero
23872 -#define open_mem open_port
23873 #define open_kmem open_mem
23874 #define open_oldmem open_mem
23875
23876 @@ -857,6 +919,9 @@ static const struct memdev {
23877 #ifdef CONFIG_CRASH_DUMP
23878 [12] = { "oldmem", 0, &oldmem_fops, NULL },
23879 #endif
23880 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
23881 + [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
23882 +#endif
23883 };
23884
23885 static int memory_open(struct inode *inode, struct file *filp)
23886 diff -urNp linux-2.6.37/drivers/char/nvram.c linux-2.6.37/drivers/char/nvram.c
23887 --- linux-2.6.37/drivers/char/nvram.c 2011-01-04 19:50:19.000000000 -0500
23888 +++ linux-2.6.37/drivers/char/nvram.c 2011-01-17 02:41:01.000000000 -0500
23889 @@ -246,7 +246,7 @@ static ssize_t nvram_read(struct file *f
23890
23891 spin_unlock_irq(&rtc_lock);
23892
23893 - if (copy_to_user(buf, contents, tmp - contents))
23894 + if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
23895 return -EFAULT;
23896
23897 *ppos = i;
23898 @@ -435,7 +435,10 @@ static const struct file_operations nvra
23899 static struct miscdevice nvram_dev = {
23900 NVRAM_MINOR,
23901 "nvram",
23902 - &nvram_fops
23903 + &nvram_fops,
23904 + {NULL, NULL},
23905 + NULL,
23906 + NULL
23907 };
23908
23909 static int __init nvram_init(void)
23910 diff -urNp linux-2.6.37/drivers/char/pcmcia/ipwireless/tty.c linux-2.6.37/drivers/char/pcmcia/ipwireless/tty.c
23911 --- linux-2.6.37/drivers/char/pcmcia/ipwireless/tty.c 2011-01-04 19:50:19.000000000 -0500
23912 +++ linux-2.6.37/drivers/char/pcmcia/ipwireless/tty.c 2011-01-17 02:41:01.000000000 -0500
23913 @@ -51,7 +51,7 @@ struct ipw_tty {
23914 int tty_type;
23915 struct ipw_network *network;
23916 struct tty_struct *linux_tty;
23917 - int open_count;
23918 + atomic_t open_count;
23919 unsigned int control_lines;
23920 struct mutex ipw_tty_mutex;
23921 int tx_bytes_queued;
23922 @@ -127,10 +127,10 @@ static int ipw_open(struct tty_struct *l
23923 mutex_unlock(&tty->ipw_tty_mutex);
23924 return -ENODEV;
23925 }
23926 - if (tty->open_count == 0)
23927 + if (atomic_read(&tty->open_count) == 0)
23928 tty->tx_bytes_queued = 0;
23929
23930 - tty->open_count++;
23931 + atomic_inc(&tty->open_count);
23932
23933 tty->linux_tty = linux_tty;
23934 linux_tty->driver_data = tty;
23935 @@ -146,9 +146,7 @@ static int ipw_open(struct tty_struct *l
23936
23937 static void do_ipw_close(struct ipw_tty *tty)
23938 {
23939 - tty->open_count--;
23940 -
23941 - if (tty->open_count == 0) {
23942 + if (atomic_dec_return(&tty->open_count) == 0) {
23943 struct tty_struct *linux_tty = tty->linux_tty;
23944
23945 if (linux_tty != NULL) {
23946 @@ -169,7 +167,7 @@ static void ipw_hangup(struct tty_struct
23947 return;
23948
23949 mutex_lock(&tty->ipw_tty_mutex);
23950 - if (tty->open_count == 0) {
23951 + if (atomic_read(&tty->open_count) == 0) {
23952 mutex_unlock(&tty->ipw_tty_mutex);
23953 return;
23954 }
23955 @@ -198,7 +196,7 @@ void ipwireless_tty_received(struct ipw_
23956 return;
23957 }
23958
23959 - if (!tty->open_count) {
23960 + if (!atomic_read(&tty->open_count)) {
23961 mutex_unlock(&tty->ipw_tty_mutex);
23962 return;
23963 }
23964 @@ -240,7 +238,7 @@ static int ipw_write(struct tty_struct *
23965 return -ENODEV;
23966
23967 mutex_lock(&tty->ipw_tty_mutex);
23968 - if (!tty->open_count) {
23969 + if (!atomic_read(&tty->open_count)) {
23970 mutex_unlock(&tty->ipw_tty_mutex);
23971 return -EINVAL;
23972 }
23973 @@ -280,7 +278,7 @@ static int ipw_write_room(struct tty_str
23974 if (!tty)
23975 return -ENODEV;
23976
23977 - if (!tty->open_count)
23978 + if (!atomic_read(&tty->open_count))
23979 return -EINVAL;
23980
23981 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
23982 @@ -322,7 +320,7 @@ static int ipw_chars_in_buffer(struct tt
23983 if (!tty)
23984 return 0;
23985
23986 - if (!tty->open_count)
23987 + if (!atomic_read(&tty->open_count))
23988 return 0;
23989
23990 return tty->tx_bytes_queued;
23991 @@ -403,7 +401,7 @@ static int ipw_tiocmget(struct tty_struc
23992 if (!tty)
23993 return -ENODEV;
23994
23995 - if (!tty->open_count)
23996 + if (!atomic_read(&tty->open_count))
23997 return -EINVAL;
23998
23999 return get_control_lines(tty);
24000 @@ -419,7 +417,7 @@ ipw_tiocmset(struct tty_struct *linux_tt
24001 if (!tty)
24002 return -ENODEV;
24003
24004 - if (!tty->open_count)
24005 + if (!atomic_read(&tty->open_count))
24006 return -EINVAL;
24007
24008 return set_control_lines(tty, set, clear);
24009 @@ -433,7 +431,7 @@ static int ipw_ioctl(struct tty_struct *
24010 if (!tty)
24011 return -ENODEV;
24012
24013 - if (!tty->open_count)
24014 + if (!atomic_read(&tty->open_count))
24015 return -EINVAL;
24016
24017 /* FIXME: Exactly how is the tty object locked here .. */
24018 @@ -582,7 +580,7 @@ void ipwireless_tty_free(struct ipw_tty
24019 against a parallel ioctl etc */
24020 mutex_lock(&ttyj->ipw_tty_mutex);
24021 }
24022 - while (ttyj->open_count)
24023 + while (atomic_read(&ttyj->open_count))
24024 do_ipw_close(ttyj);
24025 ipwireless_disassociate_network_ttys(network,
24026 ttyj->channel_idx);
24027 diff -urNp linux-2.6.37/drivers/char/random.c linux-2.6.37/drivers/char/random.c
24028 --- linux-2.6.37/drivers/char/random.c 2011-01-04 19:50:19.000000000 -0500
24029 +++ linux-2.6.37/drivers/char/random.c 2011-01-17 02:41:01.000000000 -0500
24030 @@ -254,8 +254,13 @@
24031 /*
24032 * Configuration information
24033 */
24034 +#ifdef CONFIG_GRKERNSEC_RANDNET
24035 +#define INPUT_POOL_WORDS 512
24036 +#define OUTPUT_POOL_WORDS 128
24037 +#else
24038 #define INPUT_POOL_WORDS 128
24039 #define OUTPUT_POOL_WORDS 32
24040 +#endif
24041 #define SEC_XFER_SIZE 512
24042 #define EXTRACT_SIZE 10
24043
24044 @@ -293,10 +298,17 @@ static struct poolinfo {
24045 int poolwords;
24046 int tap1, tap2, tap3, tap4, tap5;
24047 } poolinfo_table[] = {
24048 +#ifdef CONFIG_GRKERNSEC_RANDNET
24049 + /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
24050 + { 512, 411, 308, 208, 104, 1 },
24051 + /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
24052 + { 128, 103, 76, 51, 25, 1 },
24053 +#else
24054 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
24055 { 128, 103, 76, 51, 25, 1 },
24056 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
24057 { 32, 26, 20, 14, 7, 1 },
24058 +#endif
24059 #if 0
24060 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
24061 { 2048, 1638, 1231, 819, 411, 1 },
24062 @@ -902,7 +914,7 @@ static ssize_t extract_entropy_user(stru
24063
24064 extract_buf(r, tmp);
24065 i = min_t(int, nbytes, EXTRACT_SIZE);
24066 - if (copy_to_user(buf, tmp, i)) {
24067 + if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
24068 ret = -EFAULT;
24069 break;
24070 }
24071 @@ -1207,7 +1219,7 @@ EXPORT_SYMBOL(generate_random_uuid);
24072 #include <linux/sysctl.h>
24073
24074 static int min_read_thresh = 8, min_write_thresh;
24075 -static int max_read_thresh = INPUT_POOL_WORDS * 32;
24076 +static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
24077 static int max_write_thresh = INPUT_POOL_WORDS * 32;
24078 static char sysctl_bootid[16];
24079
24080 diff -urNp linux-2.6.37/drivers/char/sonypi.c linux-2.6.37/drivers/char/sonypi.c
24081 --- linux-2.6.37/drivers/char/sonypi.c 2011-01-04 19:50:19.000000000 -0500
24082 +++ linux-2.6.37/drivers/char/sonypi.c 2011-01-17 02:41:01.000000000 -0500
24083 @@ -491,7 +491,7 @@ static struct sonypi_device {
24084 spinlock_t fifo_lock;
24085 wait_queue_head_t fifo_proc_list;
24086 struct fasync_struct *fifo_async;
24087 - int open_count;
24088 + atomic_t open_count;
24089 int model;
24090 struct input_dev *input_jog_dev;
24091 struct input_dev *input_key_dev;
24092 @@ -898,7 +898,7 @@ static int sonypi_misc_fasync(int fd, st
24093 static int sonypi_misc_release(struct inode *inode, struct file *file)
24094 {
24095 mutex_lock(&sonypi_device.lock);
24096 - sonypi_device.open_count--;
24097 + atomic_dec(&sonypi_device.open_count);
24098 mutex_unlock(&sonypi_device.lock);
24099 return 0;
24100 }
24101 @@ -907,9 +907,9 @@ static int sonypi_misc_open(struct inode
24102 {
24103 mutex_lock(&sonypi_device.lock);
24104 /* Flush input queue on first open */
24105 - if (!sonypi_device.open_count)
24106 + if (!atomic_read(&sonypi_device.open_count))
24107 kfifo_reset(&sonypi_device.fifo);
24108 - sonypi_device.open_count++;
24109 + atomic_inc(&sonypi_device.open_count);
24110 mutex_unlock(&sonypi_device.lock);
24111
24112 return 0;
24113 diff -urNp linux-2.6.37/drivers/char/tpm/tpm_bios.c linux-2.6.37/drivers/char/tpm/tpm_bios.c
24114 --- linux-2.6.37/drivers/char/tpm/tpm_bios.c 2011-01-04 19:50:19.000000000 -0500
24115 +++ linux-2.6.37/drivers/char/tpm/tpm_bios.c 2011-01-17 02:41:01.000000000 -0500
24116 @@ -173,7 +173,7 @@ static void *tpm_bios_measurements_start
24117 event = addr;
24118
24119 if ((event->event_type == 0 && event->event_size == 0) ||
24120 - ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
24121 + (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
24122 return NULL;
24123
24124 return addr;
24125 @@ -198,7 +198,7 @@ static void *tpm_bios_measurements_next(
24126 return NULL;
24127
24128 if ((event->event_type == 0 && event->event_size == 0) ||
24129 - ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
24130 + (event->event_size >= limit - v - sizeof(struct tcpa_event)))
24131 return NULL;
24132
24133 (*pos)++;
24134 @@ -291,7 +291,8 @@ static int tpm_binary_bios_measurements_
24135 int i;
24136
24137 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
24138 - seq_putc(m, data[i]);
24139 + if (!seq_putc(m, data[i]))
24140 + return -EFAULT;
24141
24142 return 0;
24143 }
24144 @@ -410,6 +411,11 @@ static int read_log(struct tpm_bios_log
24145 log->bios_event_log_end = log->bios_event_log + len;
24146
24147 virt = acpi_os_map_memory(start, len);
24148 + if (!virt) {
24149 + kfree(log->bios_event_log);
24150 + log->bios_event_log = NULL;
24151 + return -EFAULT;
24152 + }
24153
24154 memcpy(log->bios_event_log, virt, len);
24155
24156 diff -urNp linux-2.6.37/drivers/cpuidle/sysfs.c linux-2.6.37/drivers/cpuidle/sysfs.c
24157 --- linux-2.6.37/drivers/cpuidle/sysfs.c 2011-01-04 19:50:19.000000000 -0500
24158 +++ linux-2.6.37/drivers/cpuidle/sysfs.c 2011-01-17 02:41:01.000000000 -0500
24159 @@ -300,7 +300,7 @@ static struct kobj_type ktype_state_cpui
24160 .release = cpuidle_state_sysfs_release,
24161 };
24162
24163 -static void inline cpuidle_free_state_kobj(struct cpuidle_device *device, int i)
24164 +static inline void cpuidle_free_state_kobj(struct cpuidle_device *device, int i)
24165 {
24166 kobject_put(&device->kobjs[i]->kobj);
24167 wait_for_completion(&device->kobjs[i]->kobj_unregister);
24168 diff -urNp linux-2.6.37/drivers/edac/edac_core.h linux-2.6.37/drivers/edac/edac_core.h
24169 --- linux-2.6.37/drivers/edac/edac_core.h 2011-01-04 19:50:19.000000000 -0500
24170 +++ linux-2.6.37/drivers/edac/edac_core.h 2011-01-17 02:41:01.000000000 -0500
24171 @@ -87,11 +87,11 @@ extern const char *edac_mem_types[];
24172
24173 #else /* !CONFIG_EDAC_DEBUG */
24174
24175 -#define debugf0( ... )
24176 -#define debugf1( ... )
24177 -#define debugf2( ... )
24178 -#define debugf3( ... )
24179 -#define debugf4( ... )
24180 +#define debugf0( ... ) do {} while (0)
24181 +#define debugf1( ... ) do {} while (0)
24182 +#define debugf2( ... ) do {} while (0)
24183 +#define debugf3( ... ) do {} while (0)
24184 +#define debugf4( ... ) do {} while (0)
24185
24186 #endif /* !CONFIG_EDAC_DEBUG */
24187
24188 diff -urNp linux-2.6.37/drivers/edac/edac_mc_sysfs.c linux-2.6.37/drivers/edac/edac_mc_sysfs.c
24189 --- linux-2.6.37/drivers/edac/edac_mc_sysfs.c 2011-01-04 19:50:19.000000000 -0500
24190 +++ linux-2.6.37/drivers/edac/edac_mc_sysfs.c 2011-01-17 02:41:01.000000000 -0500
24191 @@ -762,7 +762,7 @@ static void edac_inst_grp_release(struct
24192 }
24193
24194 /* Intermediate show/store table */
24195 -static struct sysfs_ops inst_grp_ops = {
24196 +static const struct sysfs_ops inst_grp_ops = {
24197 .show = inst_grp_show,
24198 .store = inst_grp_store
24199 };
24200 diff -urNp linux-2.6.37/drivers/firewire/core-cdev.c linux-2.6.37/drivers/firewire/core-cdev.c
24201 --- linux-2.6.37/drivers/firewire/core-cdev.c 2011-01-04 19:50:19.000000000 -0500
24202 +++ linux-2.6.37/drivers/firewire/core-cdev.c 2011-01-17 02:41:01.000000000 -0500
24203 @@ -1329,8 +1329,7 @@ static int init_iso_resource(struct clie
24204 int ret;
24205
24206 if ((request->channels == 0 && request->bandwidth == 0) ||
24207 - request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL ||
24208 - request->bandwidth < 0)
24209 + request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL)
24210 return -EINVAL;
24211
24212 r = kmalloc(sizeof(*r), GFP_KERNEL);
24213 diff -urNp linux-2.6.37/drivers/firmware/dmi_scan.c linux-2.6.37/drivers/firmware/dmi_scan.c
24214 --- linux-2.6.37/drivers/firmware/dmi_scan.c 2011-01-04 19:50:19.000000000 -0500
24215 +++ linux-2.6.37/drivers/firmware/dmi_scan.c 2011-01-17 02:41:01.000000000 -0500
24216 @@ -442,11 +442,6 @@ void __init dmi_scan_machine(void)
24217 }
24218 }
24219 else {
24220 - /*
24221 - * no iounmap() for that ioremap(); it would be a no-op, but
24222 - * it's so early in setup that sucker gets confused into doing
24223 - * what it shouldn't if we actually call it.
24224 - */
24225 p = dmi_ioremap(0xF0000, 0x10000);
24226 if (p == NULL)
24227 goto error;
24228 diff -urNp linux-2.6.37/drivers/gpu/drm/drm_crtc_helper.c linux-2.6.37/drivers/gpu/drm/drm_crtc_helper.c
24229 --- linux-2.6.37/drivers/gpu/drm/drm_crtc_helper.c 2011-01-04 19:50:19.000000000 -0500
24230 +++ linux-2.6.37/drivers/gpu/drm/drm_crtc_helper.c 2011-01-17 02:41:01.000000000 -0500
24231 @@ -276,7 +276,7 @@ static bool drm_encoder_crtc_ok(struct d
24232 struct drm_crtc *tmp;
24233 int crtc_mask = 1;
24234
24235 - WARN(!crtc, "checking null crtc?\n");
24236 + BUG_ON(!crtc);
24237
24238 dev = crtc->dev;
24239
24240 diff -urNp linux-2.6.37/drivers/gpu/drm/drm_drv.c linux-2.6.37/drivers/gpu/drm/drm_drv.c
24241 --- linux-2.6.37/drivers/gpu/drm/drm_drv.c 2011-01-04 19:50:19.000000000 -0500
24242 +++ linux-2.6.37/drivers/gpu/drm/drm_drv.c 2011-01-17 02:41:01.000000000 -0500
24243 @@ -425,7 +425,7 @@ long drm_ioctl(struct file *filp,
24244
24245 dev = file_priv->minor->dev;
24246 atomic_inc(&dev->ioctl_count);
24247 - atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
24248 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
24249 ++file_priv->ioctl_count;
24250
24251 DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
24252 diff -urNp linux-2.6.37/drivers/gpu/drm/drm_fops.c linux-2.6.37/drivers/gpu/drm/drm_fops.c
24253 --- linux-2.6.37/drivers/gpu/drm/drm_fops.c 2011-01-04 19:50:19.000000000 -0500
24254 +++ linux-2.6.37/drivers/gpu/drm/drm_fops.c 2011-01-17 02:41:01.000000000 -0500
24255 @@ -70,7 +70,7 @@ static int drm_setup(struct drm_device *
24256 }
24257
24258 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
24259 - atomic_set(&dev->counts[i], 0);
24260 + atomic_set_unchecked(&dev->counts[i], 0);
24261
24262 dev->sigdata.lock = NULL;
24263
24264 @@ -134,8 +134,8 @@ int drm_open(struct inode *inode, struct
24265
24266 retcode = drm_open_helper(inode, filp, dev);
24267 if (!retcode) {
24268 - atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
24269 - if (!dev->open_count++)
24270 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
24271 + if (atomic_inc_return(&dev->open_count) == 1)
24272 retcode = drm_setup(dev);
24273 }
24274 if (!retcode) {
24275 @@ -470,7 +470,7 @@ int drm_release(struct inode *inode, str
24276
24277 mutex_lock(&drm_global_mutex);
24278
24279 - DRM_DEBUG("open_count = %d\n", dev->open_count);
24280 + DRM_DEBUG("open_count = %d\n", atomic_read(&dev->open_count));
24281
24282 if (dev->driver->preclose)
24283 dev->driver->preclose(dev, file_priv);
24284 @@ -482,7 +482,7 @@ int drm_release(struct inode *inode, str
24285 DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
24286 task_pid_nr(current),
24287 (long)old_encode_dev(file_priv->minor->device),
24288 - dev->open_count);
24289 + atomic_read(&dev->open_count));
24290
24291 /* if the master has gone away we can't do anything with the lock */
24292 if (file_priv->minor->master)
24293 @@ -563,8 +563,8 @@ int drm_release(struct inode *inode, str
24294 * End inline drm_release
24295 */
24296
24297 - atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
24298 - if (!--dev->open_count) {
24299 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
24300 + if (atomic_dec_and_test(&dev->open_count)) {
24301 if (atomic_read(&dev->ioctl_count)) {
24302 DRM_ERROR("Device busy: %d\n",
24303 atomic_read(&dev->ioctl_count));
24304 diff -urNp linux-2.6.37/drivers/gpu/drm/drm_global.c linux-2.6.37/drivers/gpu/drm/drm_global.c
24305 --- linux-2.6.37/drivers/gpu/drm/drm_global.c 2011-01-04 19:50:19.000000000 -0500
24306 +++ linux-2.6.37/drivers/gpu/drm/drm_global.c 2011-01-17 02:41:01.000000000 -0500
24307 @@ -36,7 +36,7 @@
24308 struct drm_global_item {
24309 struct mutex mutex;
24310 void *object;
24311 - int refcount;
24312 + atomic_t refcount;
24313 };
24314
24315 static struct drm_global_item glob[DRM_GLOBAL_NUM];
24316 @@ -49,7 +49,7 @@ void drm_global_init(void)
24317 struct drm_global_item *item = &glob[i];
24318 mutex_init(&item->mutex);
24319 item->object = NULL;
24320 - item->refcount = 0;
24321 + atomic_set(&item->refcount, 0);
24322 }
24323 }
24324
24325 @@ -59,7 +59,7 @@ void drm_global_release(void)
24326 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
24327 struct drm_global_item *item = &glob[i];
24328 BUG_ON(item->object != NULL);
24329 - BUG_ON(item->refcount != 0);
24330 + BUG_ON(atomic_read(&item->refcount) != 0);
24331 }
24332 }
24333
24334 @@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_globa
24335 void *object;
24336
24337 mutex_lock(&item->mutex);
24338 - if (item->refcount == 0) {
24339 + if (atomic_read(&item->refcount) == 0) {
24340 item->object = kzalloc(ref->size, GFP_KERNEL);
24341 if (unlikely(item->object == NULL)) {
24342 ret = -ENOMEM;
24343 @@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_globa
24344 goto out_err;
24345
24346 }
24347 - ++item->refcount;
24348 + atomic_inc(&item->refcount);
24349 ref->object = item->object;
24350 object = item->object;
24351 mutex_unlock(&item->mutex);
24352 @@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_gl
24353 struct drm_global_item *item = &glob[ref->global_type];
24354
24355 mutex_lock(&item->mutex);
24356 - BUG_ON(item->refcount == 0);
24357 + BUG_ON(atomic_read(&item->refcount) == 0);
24358 BUG_ON(ref->object != item->object);
24359 - if (--item->refcount == 0) {
24360 + if (atomic_dec_and_test(&item->refcount)) {
24361 ref->release(ref);
24362 item->object = NULL;
24363 }
24364 diff -urNp linux-2.6.37/drivers/gpu/drm/drm_info.c linux-2.6.37/drivers/gpu/drm/drm_info.c
24365 --- linux-2.6.37/drivers/gpu/drm/drm_info.c 2011-01-04 19:50:19.000000000 -0500
24366 +++ linux-2.6.37/drivers/gpu/drm/drm_info.c 2011-01-17 02:41:01.000000000 -0500
24367 @@ -86,10 +86,14 @@ int drm_vm_info(struct seq_file *m, void
24368 struct drm_local_map *map;
24369 struct drm_map_list *r_list;
24370
24371 - /* Hardcoded from _DRM_FRAME_BUFFER,
24372 - _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
24373 - _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
24374 - const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
24375 + static const char * const types[] = {
24376 + [_DRM_FRAME_BUFFER] = "FB",
24377 + [_DRM_REGISTERS] = "REG",
24378 + [_DRM_SHM] = "SHM",
24379 + [_DRM_AGP] = "AGP",
24380 + [_DRM_SCATTER_GATHER] = "SG",
24381 + [_DRM_CONSISTENT] = "PCI",
24382 + [_DRM_GEM] = "GEM" };
24383 const char *type;
24384 int i;
24385
24386 @@ -100,7 +104,7 @@ int drm_vm_info(struct seq_file *m, void
24387 map = r_list->map;
24388 if (!map)
24389 continue;
24390 - if (map->type < 0 || map->type > 5)
24391 + if (map->type >= ARRAY_SIZE(types))
24392 type = "??";
24393 else
24394 type = types[map->type];
24395 diff -urNp linux-2.6.37/drivers/gpu/drm/drm_ioctl.c linux-2.6.37/drivers/gpu/drm/drm_ioctl.c
24396 --- linux-2.6.37/drivers/gpu/drm/drm_ioctl.c 2011-01-04 19:50:19.000000000 -0500
24397 +++ linux-2.6.37/drivers/gpu/drm/drm_ioctl.c 2011-01-17 02:41:01.000000000 -0500
24398 @@ -353,7 +353,7 @@ int drm_getstats(struct drm_device *dev,
24399 stats->data[i].value =
24400 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
24401 else
24402 - stats->data[i].value = atomic_read(&dev->counts[i]);
24403 + stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
24404 stats->data[i].type = dev->types[i];
24405 }
24406
24407 diff -urNp linux-2.6.37/drivers/gpu/drm/drm_lock.c linux-2.6.37/drivers/gpu/drm/drm_lock.c
24408 --- linux-2.6.37/drivers/gpu/drm/drm_lock.c 2011-01-04 19:50:19.000000000 -0500
24409 +++ linux-2.6.37/drivers/gpu/drm/drm_lock.c 2011-01-17 02:41:01.000000000 -0500
24410 @@ -89,7 +89,7 @@ int drm_lock(struct drm_device *dev, voi
24411 if (drm_lock_take(&master->lock, lock->context)) {
24412 master->lock.file_priv = file_priv;
24413 master->lock.lock_time = jiffies;
24414 - atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
24415 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
24416 break; /* Got lock */
24417 }
24418
24419 @@ -160,7 +160,7 @@ int drm_unlock(struct drm_device *dev, v
24420 return -EINVAL;
24421 }
24422
24423 - atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
24424 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
24425
24426 if (drm_lock_free(&master->lock, lock->context)) {
24427 /* FIXME: Should really bail out here. */
24428 diff -urNp linux-2.6.37/drivers/gpu/drm/i810/i810_dma.c linux-2.6.37/drivers/gpu/drm/i810/i810_dma.c
24429 --- linux-2.6.37/drivers/gpu/drm/i810/i810_dma.c 2011-01-04 19:50:19.000000000 -0500
24430 +++ linux-2.6.37/drivers/gpu/drm/i810/i810_dma.c 2011-01-17 02:41:01.000000000 -0500
24431 @@ -953,8 +953,8 @@ static int i810_dma_vertex(struct drm_de
24432 dma->buflist[vertex->idx],
24433 vertex->discard, vertex->used);
24434
24435 - atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
24436 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
24437 + atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
24438 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
24439 sarea_priv->last_enqueue = dev_priv->counter - 1;
24440 sarea_priv->last_dispatch = (int)hw_status[5];
24441
24442 @@ -1114,8 +1114,8 @@ static int i810_dma_mc(struct drm_device
24443 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
24444 mc->last_render);
24445
24446 - atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
24447 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
24448 + atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
24449 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
24450 sarea_priv->last_enqueue = dev_priv->counter - 1;
24451 sarea_priv->last_dispatch = (int)hw_status[5];
24452
24453 diff -urNp linux-2.6.37/drivers/gpu/drm/i915/dvo_ch7017.c linux-2.6.37/drivers/gpu/drm/i915/dvo_ch7017.c
24454 --- linux-2.6.37/drivers/gpu/drm/i915/dvo_ch7017.c 2011-01-04 19:50:19.000000000 -0500
24455 +++ linux-2.6.37/drivers/gpu/drm/i915/dvo_ch7017.c 2011-01-17 02:41:01.000000000 -0500
24456 @@ -390,7 +390,7 @@ static void ch7017_destroy(struct intel_
24457 }
24458 }
24459
24460 -struct intel_dvo_dev_ops ch7017_ops = {
24461 +const struct intel_dvo_dev_ops ch7017_ops = {
24462 .init = ch7017_init,
24463 .detect = ch7017_detect,
24464 .mode_valid = ch7017_mode_valid,
24465 diff -urNp linux-2.6.37/drivers/gpu/drm/i915/dvo_ch7xxx.c linux-2.6.37/drivers/gpu/drm/i915/dvo_ch7xxx.c
24466 --- linux-2.6.37/drivers/gpu/drm/i915/dvo_ch7xxx.c 2011-01-04 19:50:19.000000000 -0500
24467 +++ linux-2.6.37/drivers/gpu/drm/i915/dvo_ch7xxx.c 2011-01-17 02:41:01.000000000 -0500
24468 @@ -320,7 +320,7 @@ static void ch7xxx_destroy(struct intel_
24469 }
24470 }
24471
24472 -struct intel_dvo_dev_ops ch7xxx_ops = {
24473 +const struct intel_dvo_dev_ops ch7xxx_ops = {
24474 .init = ch7xxx_init,
24475 .detect = ch7xxx_detect,
24476 .mode_valid = ch7xxx_mode_valid,
24477 diff -urNp linux-2.6.37/drivers/gpu/drm/i915/dvo.h linux-2.6.37/drivers/gpu/drm/i915/dvo.h
24478 --- linux-2.6.37/drivers/gpu/drm/i915/dvo.h 2011-01-04 19:50:19.000000000 -0500
24479 +++ linux-2.6.37/drivers/gpu/drm/i915/dvo.h 2011-01-17 02:41:01.000000000 -0500
24480 @@ -122,23 +122,23 @@ struct intel_dvo_dev_ops {
24481 *
24482 * \return singly-linked list of modes or NULL if no modes found.
24483 */
24484 - struct drm_display_mode *(*get_modes)(struct intel_dvo_device *dvo);
24485 + struct drm_display_mode *(* const get_modes)(struct intel_dvo_device *dvo);
24486
24487 /**
24488 * Clean up driver-specific bits of the output
24489 */
24490 - void (*destroy) (struct intel_dvo_device *dvo);
24491 + void (* const destroy) (struct intel_dvo_device *dvo);
24492
24493 /**
24494 * Debugging hook to dump device registers to log file
24495 */
24496 - void (*dump_regs)(struct intel_dvo_device *dvo);
24497 + void (* const dump_regs)(struct intel_dvo_device *dvo);
24498 };
24499
24500 -extern struct intel_dvo_dev_ops sil164_ops;
24501 -extern struct intel_dvo_dev_ops ch7xxx_ops;
24502 -extern struct intel_dvo_dev_ops ivch_ops;
24503 -extern struct intel_dvo_dev_ops tfp410_ops;
24504 -extern struct intel_dvo_dev_ops ch7017_ops;
24505 +extern const struct intel_dvo_dev_ops sil164_ops;
24506 +extern const struct intel_dvo_dev_ops ch7xxx_ops;
24507 +extern const struct intel_dvo_dev_ops ivch_ops;
24508 +extern const struct intel_dvo_dev_ops tfp410_ops;
24509 +extern const struct intel_dvo_dev_ops ch7017_ops;
24510
24511 #endif /* _INTEL_DVO_H */
24512 diff -urNp linux-2.6.37/drivers/gpu/drm/i915/dvo_ivch.c linux-2.6.37/drivers/gpu/drm/i915/dvo_ivch.c
24513 --- linux-2.6.37/drivers/gpu/drm/i915/dvo_ivch.c 2011-01-04 19:50:19.000000000 -0500
24514 +++ linux-2.6.37/drivers/gpu/drm/i915/dvo_ivch.c 2011-01-17 02:41:01.000000000 -0500
24515 @@ -410,7 +410,7 @@ static void ivch_destroy(struct intel_dv
24516 }
24517 }
24518
24519 -struct intel_dvo_dev_ops ivch_ops= {
24520 +const struct intel_dvo_dev_ops ivch_ops= {
24521 .init = ivch_init,
24522 .dpms = ivch_dpms,
24523 .mode_valid = ivch_mode_valid,
24524 diff -urNp linux-2.6.37/drivers/gpu/drm/i915/dvo_sil164.c linux-2.6.37/drivers/gpu/drm/i915/dvo_sil164.c
24525 --- linux-2.6.37/drivers/gpu/drm/i915/dvo_sil164.c 2011-01-04 19:50:19.000000000 -0500
24526 +++ linux-2.6.37/drivers/gpu/drm/i915/dvo_sil164.c 2011-01-17 02:41:01.000000000 -0500
24527 @@ -252,7 +252,7 @@ static void sil164_destroy(struct intel_
24528 }
24529 }
24530
24531 -struct intel_dvo_dev_ops sil164_ops = {
24532 +const struct intel_dvo_dev_ops sil164_ops = {
24533 .init = sil164_init,
24534 .detect = sil164_detect,
24535 .mode_valid = sil164_mode_valid,
24536 diff -urNp linux-2.6.37/drivers/gpu/drm/i915/dvo_tfp410.c linux-2.6.37/drivers/gpu/drm/i915/dvo_tfp410.c
24537 --- linux-2.6.37/drivers/gpu/drm/i915/dvo_tfp410.c 2011-01-04 19:50:19.000000000 -0500
24538 +++ linux-2.6.37/drivers/gpu/drm/i915/dvo_tfp410.c 2011-01-17 02:41:01.000000000 -0500
24539 @@ -293,7 +293,7 @@ static void tfp410_destroy(struct intel_
24540 }
24541 }
24542
24543 -struct intel_dvo_dev_ops tfp410_ops = {
24544 +const struct intel_dvo_dev_ops tfp410_ops = {
24545 .init = tfp410_init,
24546 .detect = tfp410_detect,
24547 .mode_valid = tfp410_mode_valid,
24548 diff -urNp linux-2.6.37/drivers/gpu/drm/i915/i915_dma.c linux-2.6.37/drivers/gpu/drm/i915/i915_dma.c
24549 --- linux-2.6.37/drivers/gpu/drm/i915/i915_dma.c 2011-01-04 19:50:19.000000000 -0500
24550 +++ linux-2.6.37/drivers/gpu/drm/i915/i915_dma.c 2011-01-17 02:41:01.000000000 -0500
24551 @@ -1191,7 +1191,7 @@ static bool i915_switcheroo_can_switch(s
24552 bool can_switch;
24553
24554 spin_lock(&dev->count_lock);
24555 - can_switch = (dev->open_count == 0);
24556 + can_switch = (atomic_read(&dev->open_count) == 0);
24557 spin_unlock(&dev->count_lock);
24558 return can_switch;
24559 }
24560 diff -urNp linux-2.6.37/drivers/gpu/drm/i915/i915_drv.c linux-2.6.37/drivers/gpu/drm/i915/i915_drv.c
24561 --- linux-2.6.37/drivers/gpu/drm/i915/i915_drv.c 2011-01-04 19:50:19.000000000 -0500
24562 +++ linux-2.6.37/drivers/gpu/drm/i915/i915_drv.c 2011-01-17 02:41:01.000000000 -0500
24563 @@ -579,7 +579,7 @@ static const struct dev_pm_ops i915_pm_o
24564 .restore = i915_pm_resume,
24565 };
24566
24567 -static struct vm_operations_struct i915_gem_vm_ops = {
24568 +static const struct vm_operations_struct i915_gem_vm_ops = {
24569 .fault = i915_gem_fault,
24570 .open = drm_gem_vm_open,
24571 .close = drm_gem_vm_close,
24572 diff -urNp linux-2.6.37/drivers/gpu/drm/i915/i915_gem.c linux-2.6.37/drivers/gpu/drm/i915/i915_gem.c
24573 --- linux-2.6.37/drivers/gpu/drm/i915/i915_gem.c 2011-01-04 19:50:19.000000000 -0500
24574 +++ linux-2.6.37/drivers/gpu/drm/i915/i915_gem.c 2011-01-17 02:41:01.000000000 -0500
24575 @@ -587,6 +587,7 @@ i915_gem_pread_ioctl(struct drm_device *
24576 goto out_put;
24577
24578 ret = -EFAULT;
24579 +
24580 if (!i915_gem_object_needs_bit17_swizzle(obj))
24581 ret = i915_gem_shmem_pread_fast(dev, obj, args, file_priv);
24582 if (ret == -EFAULT)
24583 diff -urNp linux-2.6.37/drivers/gpu/drm/nouveau/nouveau_backlight.c linux-2.6.37/drivers/gpu/drm/nouveau/nouveau_backlight.c
24584 --- linux-2.6.37/drivers/gpu/drm/nouveau/nouveau_backlight.c 2011-01-04 19:50:19.000000000 -0500
24585 +++ linux-2.6.37/drivers/gpu/drm/nouveau/nouveau_backlight.c 2011-01-17 02:41:01.000000000 -0500
24586 @@ -59,7 +59,7 @@ static int nv40_set_intensity(struct bac
24587 return 0;
24588 }
24589
24590 -static struct backlight_ops nv40_bl_ops = {
24591 +static const struct backlight_ops nv40_bl_ops = {
24592 .options = BL_CORE_SUSPENDRESUME,
24593 .get_brightness = nv40_get_intensity,
24594 .update_status = nv40_set_intensity,
24595 @@ -82,7 +82,7 @@ static int nv50_set_intensity(struct bac
24596 return 0;
24597 }
24598
24599 -static struct backlight_ops nv50_bl_ops = {
24600 +static const struct backlight_ops nv50_bl_ops = {
24601 .options = BL_CORE_SUSPENDRESUME,
24602 .get_brightness = nv50_get_intensity,
24603 .update_status = nv50_set_intensity,
24604 diff -urNp linux-2.6.37/drivers/gpu/drm/nouveau/nouveau_state.c linux-2.6.37/drivers/gpu/drm/nouveau/nouveau_state.c
24605 --- linux-2.6.37/drivers/gpu/drm/nouveau/nouveau_state.c 2011-01-04 19:50:19.000000000 -0500
24606 +++ linux-2.6.37/drivers/gpu/drm/nouveau/nouveau_state.c 2011-01-17 02:41:01.000000000 -0500
24607 @@ -546,7 +546,7 @@ static bool nouveau_switcheroo_can_switc
24608 bool can_switch;
24609
24610 spin_lock(&dev->count_lock);
24611 - can_switch = (dev->open_count == 0);
24612 + can_switch = (atomic_read(&dev->open_count) == 0);
24613 spin_unlock(&dev->count_lock);
24614 return can_switch;
24615 }
24616 diff -urNp linux-2.6.37/drivers/gpu/drm/radeon/mkregtable.c linux-2.6.37/drivers/gpu/drm/radeon/mkregtable.c
24617 --- linux-2.6.37/drivers/gpu/drm/radeon/mkregtable.c 2011-01-04 19:50:19.000000000 -0500
24618 +++ linux-2.6.37/drivers/gpu/drm/radeon/mkregtable.c 2011-01-17 02:41:01.000000000 -0500
24619 @@ -637,14 +637,14 @@ static int parser_auth(struct table *t,
24620 regex_t mask_rex;
24621 regmatch_t match[4];
24622 char buf[1024];
24623 - size_t end;
24624 + long end;
24625 int len;
24626 int done = 0;
24627 int r;
24628 unsigned o;
24629 struct offset *offset;
24630 char last_reg_s[10];
24631 - int last_reg;
24632 + unsigned long last_reg;
24633
24634 if (regcomp
24635 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
24636 diff -urNp linux-2.6.37/drivers/gpu/drm/radeon/radeon_device.c linux-2.6.37/drivers/gpu/drm/radeon/radeon_device.c
24637 --- linux-2.6.37/drivers/gpu/drm/radeon/radeon_device.c 2011-01-04 19:50:19.000000000 -0500
24638 +++ linux-2.6.37/drivers/gpu/drm/radeon/radeon_device.c 2011-01-17 02:41:01.000000000 -0500
24639 @@ -659,7 +659,7 @@ static bool radeon_switcheroo_can_switch
24640 bool can_switch;
24641
24642 spin_lock(&dev->count_lock);
24643 - can_switch = (dev->open_count == 0);
24644 + can_switch = (atomic_read(&dev->open_count) == 0);
24645 spin_unlock(&dev->count_lock);
24646 return can_switch;
24647 }
24648 diff -urNp linux-2.6.37/drivers/gpu/drm/radeon/radeon_state.c linux-2.6.37/drivers/gpu/drm/radeon/radeon_state.c
24649 --- linux-2.6.37/drivers/gpu/drm/radeon/radeon_state.c 2011-01-04 19:50:19.000000000 -0500
24650 +++ linux-2.6.37/drivers/gpu/drm/radeon/radeon_state.c 2011-01-17 02:41:01.000000000 -0500
24651 @@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_de
24652 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
24653 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
24654
24655 - if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
24656 + if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
24657 sarea_priv->nbox * sizeof(depth_boxes[0])))
24658 return -EFAULT;
24659
24660 @@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm
24661 {
24662 drm_radeon_private_t *dev_priv = dev->dev_private;
24663 drm_radeon_getparam_t *param = data;
24664 - int value;
24665 + int value = 0;
24666
24667 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
24668
24669 diff -urNp linux-2.6.37/drivers/gpu/drm/radeon/radeon_ttm.c linux-2.6.37/drivers/gpu/drm/radeon/radeon_ttm.c
24670 --- linux-2.6.37/drivers/gpu/drm/radeon/radeon_ttm.c 2011-01-04 19:50:19.000000000 -0500
24671 +++ linux-2.6.37/drivers/gpu/drm/radeon/radeon_ttm.c 2011-01-17 02:41:01.000000000 -0500
24672 @@ -589,8 +589,9 @@ void radeon_ttm_fini(struct radeon_devic
24673 DRM_INFO("radeon: ttm finalized\n");
24674 }
24675
24676 -static struct vm_operations_struct radeon_ttm_vm_ops;
24677 -static const struct vm_operations_struct *ttm_vm_ops = NULL;
24678 +extern int ttm_bo_vm_fault(struct vm_area_struct *vma, struct vm_fault *vmf);
24679 +extern void ttm_bo_vm_open(struct vm_area_struct *vma);
24680 +extern void ttm_bo_vm_close(struct vm_area_struct *vma);
24681
24682 static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
24683 {
24684 @@ -598,17 +599,22 @@ static int radeon_ttm_fault(struct vm_ar
24685 struct radeon_device *rdev;
24686 int r;
24687
24688 - bo = (struct ttm_buffer_object *)vma->vm_private_data;
24689 - if (bo == NULL) {
24690 + bo = (struct ttm_buffer_object *)vma->vm_private_data;
24691 + if (!bo)
24692 return VM_FAULT_NOPAGE;
24693 - }
24694 rdev = radeon_get_rdev(bo->bdev);
24695 mutex_lock(&rdev->vram_mutex);
24696 - r = ttm_vm_ops->fault(vma, vmf);
24697 + r = ttm_bo_vm_fault(vma, vmf);
24698 mutex_unlock(&rdev->vram_mutex);
24699 return r;
24700 }
24701
24702 +static const struct vm_operations_struct radeon_ttm_vm_ops = {
24703 + .fault = radeon_ttm_fault,
24704 + .open = ttm_bo_vm_open,
24705 + .close = ttm_bo_vm_close
24706 +};
24707 +
24708 int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
24709 {
24710 struct drm_file *file_priv;
24711 @@ -621,18 +627,11 @@ int radeon_mmap(struct file *filp, struc
24712
24713 file_priv = filp->private_data;
24714 rdev = file_priv->minor->dev->dev_private;
24715 - if (rdev == NULL) {
24716 + if (!rdev)
24717 return -EINVAL;
24718 - }
24719 r = ttm_bo_mmap(filp, vma, &rdev->mman.bdev);
24720 - if (unlikely(r != 0)) {
24721 + if (r)
24722 return r;
24723 - }
24724 - if (unlikely(ttm_vm_ops == NULL)) {
24725 - ttm_vm_ops = vma->vm_ops;
24726 - radeon_ttm_vm_ops = *ttm_vm_ops;
24727 - radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
24728 - }
24729 vma->vm_ops = &radeon_ttm_vm_ops;
24730 return 0;
24731 }
24732 diff -urNp linux-2.6.37/drivers/gpu/drm/ttm/ttm_bo.c linux-2.6.37/drivers/gpu/drm/ttm/ttm_bo.c
24733 --- linux-2.6.37/drivers/gpu/drm/ttm/ttm_bo.c 2011-01-04 19:50:19.000000000 -0500
24734 +++ linux-2.6.37/drivers/gpu/drm/ttm/ttm_bo.c 2011-01-17 02:41:01.000000000 -0500
24735 @@ -40,7 +40,7 @@
24736 #include <asm/atomic.h>
24737
24738 #define TTM_ASSERT_LOCKED(param)
24739 -#define TTM_DEBUG(fmt, arg...)
24740 +#define TTM_DEBUG(fmt, arg...) do {} while (0)
24741 #define TTM_BO_HASH_ORDER 13
24742
24743 static int ttm_bo_setup_vm(struct ttm_buffer_object *bo);
24744 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
24745 --- linux-2.6.37/drivers/gpu/drm/ttm/ttm_bo_vm.c 2011-01-04 19:50:19.000000000 -0500
24746 +++ linux-2.6.37/drivers/gpu/drm/ttm/ttm_bo_vm.c 2011-01-17 02:41:01.000000000 -0500
24747 @@ -69,11 +69,11 @@ static struct ttm_buffer_object *ttm_bo_
24748 return best_bo;
24749 }
24750
24751 -static int ttm_bo_vm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
24752 +int ttm_bo_vm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
24753 {
24754 struct ttm_buffer_object *bo = (struct ttm_buffer_object *)
24755 vma->vm_private_data;
24756 - struct ttm_bo_device *bdev = bo->bdev;
24757 + struct ttm_bo_device *bdev;
24758 unsigned long page_offset;
24759 unsigned long page_last;
24760 unsigned long pfn;
24761 @@ -84,6 +84,10 @@ static int ttm_bo_vm_fault(struct vm_are
24762 unsigned long address = (unsigned long)vmf->virtual_address;
24763 int retval = VM_FAULT_NOPAGE;
24764
24765 + if (!bo)
24766 + return VM_FAULT_NOPAGE;
24767 + bdev = bo->bdev;
24768 +
24769 /*
24770 * Work around locking order reversal in fault / nopfn
24771 * between mmap_sem and bo_reserve: Perform a trylock operation
24772 @@ -212,22 +216,25 @@ out_unlock:
24773 ttm_bo_unreserve(bo);
24774 return retval;
24775 }
24776 +EXPORT_SYMBOL(ttm_bo_vm_fault);
24777
24778 -static void ttm_bo_vm_open(struct vm_area_struct *vma)
24779 +void ttm_bo_vm_open(struct vm_area_struct *vma)
24780 {
24781 struct ttm_buffer_object *bo =
24782 (struct ttm_buffer_object *)vma->vm_private_data;
24783
24784 (void)ttm_bo_reference(bo);
24785 }
24786 +EXPORT_SYMBOL(ttm_bo_vm_open);
24787
24788 -static void ttm_bo_vm_close(struct vm_area_struct *vma)
24789 +void ttm_bo_vm_close(struct vm_area_struct *vma)
24790 {
24791 struct ttm_buffer_object *bo = (struct ttm_buffer_object *)vma->vm_private_data;
24792
24793 ttm_bo_unref(&bo);
24794 vma->vm_private_data = NULL;
24795 }
24796 +EXPORT_SYMBOL(ttm_bo_vm_close);
24797
24798 static const struct vm_operations_struct ttm_bo_vm_ops = {
24799 .fault = ttm_bo_vm_fault,
24800 diff -urNp linux-2.6.37/drivers/hid/usbhid/hiddev.c linux-2.6.37/drivers/hid/usbhid/hiddev.c
24801 --- linux-2.6.37/drivers/hid/usbhid/hiddev.c 2011-01-04 19:50:19.000000000 -0500
24802 +++ linux-2.6.37/drivers/hid/usbhid/hiddev.c 2011-01-17 02:41:01.000000000 -0500
24803 @@ -611,7 +611,7 @@ static long hiddev_ioctl(struct file *fi
24804 return put_user(HID_VERSION, (int __user *)arg);
24805
24806 case HIDIOCAPPLICATION:
24807 - if (arg < 0 || arg >= hid->maxapplication)
24808 + if (arg >= hid->maxapplication)
24809 return -EINVAL;
24810
24811 for (i = 0; i < hid->maxcollection; i++)
24812 diff -urNp linux-2.6.37/drivers/hwmon/k8temp.c linux-2.6.37/drivers/hwmon/k8temp.c
24813 --- linux-2.6.37/drivers/hwmon/k8temp.c 2011-01-04 19:50:19.000000000 -0500
24814 +++ linux-2.6.37/drivers/hwmon/k8temp.c 2011-01-17 02:41:01.000000000 -0500
24815 @@ -138,7 +138,7 @@ static DEVICE_ATTR(name, S_IRUGO, show_n
24816
24817 static const struct pci_device_id k8temp_ids[] = {
24818 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_K8_NB_MISC) },
24819 - { 0 },
24820 + { 0, 0, 0, 0, 0, 0, 0 },
24821 };
24822
24823 MODULE_DEVICE_TABLE(pci, k8temp_ids);
24824 diff -urNp linux-2.6.37/drivers/hwmon/sis5595.c linux-2.6.37/drivers/hwmon/sis5595.c
24825 --- linux-2.6.37/drivers/hwmon/sis5595.c 2011-01-04 19:50:19.000000000 -0500
24826 +++ linux-2.6.37/drivers/hwmon/sis5595.c 2011-01-17 02:41:01.000000000 -0500
24827 @@ -699,7 +699,7 @@ static struct sis5595_data *sis5595_upda
24828
24829 static const struct pci_device_id sis5595_pci_ids[] = {
24830 { PCI_DEVICE(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_503) },
24831 - { 0, }
24832 + { 0, 0, 0, 0, 0, 0, 0 }
24833 };
24834
24835 MODULE_DEVICE_TABLE(pci, sis5595_pci_ids);
24836 diff -urNp linux-2.6.37/drivers/hwmon/via686a.c linux-2.6.37/drivers/hwmon/via686a.c
24837 --- linux-2.6.37/drivers/hwmon/via686a.c 2011-01-04 19:50:19.000000000 -0500
24838 +++ linux-2.6.37/drivers/hwmon/via686a.c 2011-01-17 02:41:01.000000000 -0500
24839 @@ -769,7 +769,7 @@ static struct via686a_data *via686a_upda
24840
24841 static const struct pci_device_id via686a_pci_ids[] = {
24842 { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C686_4) },
24843 - { 0, }
24844 + { 0, 0, 0, 0, 0, 0, 0 }
24845 };
24846
24847 MODULE_DEVICE_TABLE(pci, via686a_pci_ids);
24848 diff -urNp linux-2.6.37/drivers/hwmon/vt8231.c linux-2.6.37/drivers/hwmon/vt8231.c
24849 --- linux-2.6.37/drivers/hwmon/vt8231.c 2011-01-04 19:50:19.000000000 -0500
24850 +++ linux-2.6.37/drivers/hwmon/vt8231.c 2011-01-17 02:41:01.000000000 -0500
24851 @@ -699,7 +699,7 @@ static struct platform_driver vt8231_dri
24852
24853 static const struct pci_device_id vt8231_pci_ids[] = {
24854 { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8231_4) },
24855 - { 0, }
24856 + { 0, 0, 0, 0, 0, 0, 0 }
24857 };
24858
24859 MODULE_DEVICE_TABLE(pci, vt8231_pci_ids);
24860 diff -urNp linux-2.6.37/drivers/hwmon/w83791d.c linux-2.6.37/drivers/hwmon/w83791d.c
24861 --- linux-2.6.37/drivers/hwmon/w83791d.c 2011-01-04 19:50:19.000000000 -0500
24862 +++ linux-2.6.37/drivers/hwmon/w83791d.c 2011-01-17 02:41:01.000000000 -0500
24863 @@ -329,8 +329,8 @@ static int w83791d_detect(struct i2c_cli
24864 struct i2c_board_info *info);
24865 static int w83791d_remove(struct i2c_client *client);
24866
24867 -static int w83791d_read(struct i2c_client *client, u8 register);
24868 -static int w83791d_write(struct i2c_client *client, u8 register, u8 value);
24869 +static int w83791d_read(struct i2c_client *client, u8 reg);
24870 +static int w83791d_write(struct i2c_client *client, u8 reg, u8 value);
24871 static struct w83791d_data *w83791d_update_device(struct device *dev);
24872
24873 #ifdef DEBUG
24874 diff -urNp linux-2.6.37/drivers/i2c/busses/i2c-i801.c linux-2.6.37/drivers/i2c/busses/i2c-i801.c
24875 --- linux-2.6.37/drivers/i2c/busses/i2c-i801.c 2011-01-04 19:50:19.000000000 -0500
24876 +++ linux-2.6.37/drivers/i2c/busses/i2c-i801.c 2011-01-17 02:41:01.000000000 -0500
24877 @@ -620,7 +620,7 @@ static const struct pci_device_id i801_i
24878 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS_IDF0) },
24879 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS_IDF1) },
24880 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS_IDF2) },
24881 - { 0, }
24882 + { 0, 0, 0, 0, 0, 0, 0 }
24883 };
24884
24885 MODULE_DEVICE_TABLE(pci, i801_ids);
24886 diff -urNp linux-2.6.37/drivers/i2c/busses/i2c-piix4.c linux-2.6.37/drivers/i2c/busses/i2c-piix4.c
24887 --- linux-2.6.37/drivers/i2c/busses/i2c-piix4.c 2011-01-04 19:50:19.000000000 -0500
24888 +++ linux-2.6.37/drivers/i2c/busses/i2c-piix4.c 2011-01-17 02:41:01.000000000 -0500
24889 @@ -124,7 +124,7 @@ static struct dmi_system_id __devinitdat
24890 .ident = "IBM",
24891 .matches = { DMI_MATCH(DMI_SYS_VENDOR, "IBM"), },
24892 },
24893 - { },
24894 + { NULL, NULL, {DMI_MATCH(DMI_NONE, {0})}, NULL }
24895 };
24896
24897 static int __devinit piix4_setup(struct pci_dev *PIIX4_dev,
24898 @@ -491,7 +491,7 @@ static const struct pci_device_id piix4_
24899 PCI_DEVICE_ID_SERVERWORKS_HT1000SB) },
24900 { PCI_DEVICE(PCI_VENDOR_ID_SERVERWORKS,
24901 PCI_DEVICE_ID_SERVERWORKS_HT1100LD) },
24902 - { 0, }
24903 + { 0, 0, 0, 0, 0, 0, 0 }
24904 };
24905
24906 MODULE_DEVICE_TABLE (pci, piix4_ids);
24907 diff -urNp linux-2.6.37/drivers/i2c/busses/i2c-sis630.c linux-2.6.37/drivers/i2c/busses/i2c-sis630.c
24908 --- linux-2.6.37/drivers/i2c/busses/i2c-sis630.c 2011-01-04 19:50:19.000000000 -0500
24909 +++ linux-2.6.37/drivers/i2c/busses/i2c-sis630.c 2011-01-17 02:41:01.000000000 -0500
24910 @@ -471,7 +471,7 @@ static struct i2c_adapter sis630_adapter
24911 static const struct pci_device_id sis630_ids[] __devinitconst = {
24912 { PCI_DEVICE(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_503) },
24913 { PCI_DEVICE(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_LPC) },
24914 - { 0, }
24915 + { 0, 0, 0, 0, 0, 0, 0 }
24916 };
24917
24918 MODULE_DEVICE_TABLE (pci, sis630_ids);
24919 diff -urNp linux-2.6.37/drivers/i2c/busses/i2c-sis96x.c linux-2.6.37/drivers/i2c/busses/i2c-sis96x.c
24920 --- linux-2.6.37/drivers/i2c/busses/i2c-sis96x.c 2011-01-04 19:50:19.000000000 -0500
24921 +++ linux-2.6.37/drivers/i2c/busses/i2c-sis96x.c 2011-01-17 02:41:01.000000000 -0500
24922 @@ -247,7 +247,7 @@ static struct i2c_adapter sis96x_adapter
24923
24924 static const struct pci_device_id sis96x_ids[] = {
24925 { PCI_DEVICE(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_SMBUS) },
24926 - { 0, }
24927 + { 0, 0, 0, 0, 0, 0, 0 }
24928 };
24929
24930 MODULE_DEVICE_TABLE (pci, sis96x_ids);
24931 diff -urNp linux-2.6.37/drivers/ide/ide-cd.c linux-2.6.37/drivers/ide/ide-cd.c
24932 --- linux-2.6.37/drivers/ide/ide-cd.c 2011-01-04 19:50:19.000000000 -0500
24933 +++ linux-2.6.37/drivers/ide/ide-cd.c 2011-01-17 02:41:01.000000000 -0500
24934 @@ -776,7 +776,7 @@ static void cdrom_do_block_pc(ide_drive_
24935 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
24936 if ((unsigned long)buf & alignment
24937 || blk_rq_bytes(rq) & q->dma_pad_mask
24938 - || object_is_on_stack(buf))
24939 + || object_starts_on_stack(buf))
24940 drive->dma = 0;
24941 }
24942 }
24943 diff -urNp linux-2.6.37/drivers/infiniband/core/cm.c linux-2.6.37/drivers/infiniband/core/cm.c
24944 --- linux-2.6.37/drivers/infiniband/core/cm.c 2011-01-04 19:50:19.000000000 -0500
24945 +++ linux-2.6.37/drivers/infiniband/core/cm.c 2011-01-17 02:41:01.000000000 -0500
24946 @@ -113,7 +113,7 @@ static char const counter_group_names[CM
24947
24948 struct cm_counter_group {
24949 struct kobject obj;
24950 - atomic_long_t counter[CM_ATTR_COUNT];
24951 + atomic_long_unchecked_t counter[CM_ATTR_COUNT];
24952 };
24953
24954 struct cm_counter_attribute {
24955 @@ -1387,7 +1387,7 @@ static void cm_dup_req_handler(struct cm
24956 struct ib_mad_send_buf *msg = NULL;
24957 int ret;
24958
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_REQ_COUNTER]);
24962
24963 /* Quick state check to discard duplicate REQs. */
24964 @@ -1765,7 +1765,7 @@ static void cm_dup_rep_handler(struct cm
24965 if (!cm_id_priv)
24966 return;
24967
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_REP_COUNTER]);
24971 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
24972 if (ret)
24973 @@ -1932,7 +1932,7 @@ static int cm_rtu_handler(struct cm_work
24974 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
24975 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
24976 spin_unlock_irq(&cm_id_priv->lock);
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_RTU_COUNTER]);
24980 goto out;
24981 }
24982 @@ -2111,7 +2111,7 @@ static int cm_dreq_handler(struct cm_wor
24983 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
24984 dreq_msg->local_comm_id);
24985 if (!cm_id_priv) {
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 cm_issue_drep(work->port, work->mad_recv_wc);
24990 return -EINVAL;
24991 @@ -2132,7 +2132,7 @@ static int cm_dreq_handler(struct cm_wor
24992 case IB_CM_MRA_REP_RCVD:
24993 break;
24994 case IB_CM_TIMEWAIT:
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]);
24998 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
24999 goto unlock;
25000 @@ -2146,7 +2146,7 @@ static int cm_dreq_handler(struct cm_wor
25001 cm_free_msg(msg);
25002 goto deref;
25003 case IB_CM_DREQ_RCVD:
25004 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
25005 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
25006 counter[CM_DREQ_COUNTER]);
25007 goto unlock;
25008 default:
25009 @@ -2504,7 +2504,7 @@ static int cm_mra_handler(struct cm_work
25010 ib_modify_mad(cm_id_priv->av.port->mad_agent,
25011 cm_id_priv->msg, timeout)) {
25012 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
25013 - atomic_long_inc(&work->port->
25014 + atomic_long_inc_unchecked(&work->port->
25015 counter_group[CM_RECV_DUPLICATES].
25016 counter[CM_MRA_COUNTER]);
25017 goto out;
25018 @@ -2513,7 +2513,7 @@ static int cm_mra_handler(struct cm_work
25019 break;
25020 case IB_CM_MRA_REQ_RCVD:
25021 case IB_CM_MRA_REP_RCVD:
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_MRA_COUNTER]);
25025 /* fall through */
25026 default:
25027 @@ -2675,7 +2675,7 @@ static int cm_lap_handler(struct cm_work
25028 case IB_CM_LAP_IDLE:
25029 break;
25030 case IB_CM_MRA_LAP_SENT:
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]);
25034 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
25035 goto unlock;
25036 @@ -2691,7 +2691,7 @@ static int cm_lap_handler(struct cm_work
25037 cm_free_msg(msg);
25038 goto deref;
25039 case IB_CM_LAP_RCVD:
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_LAP_COUNTER]);
25043 goto unlock;
25044 default:
25045 @@ -2975,7 +2975,7 @@ static int cm_sidr_req_handler(struct cm
25046 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
25047 if (cur_cm_id_priv) {
25048 spin_unlock_irq(&cm.lock);
25049 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
25050 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
25051 counter[CM_SIDR_REQ_COUNTER]);
25052 goto out; /* Duplicate message. */
25053 }
25054 @@ -3186,10 +3186,10 @@ static void cm_send_handler(struct ib_ma
25055 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
25056 msg->retries = 1;
25057
25058 - atomic_long_add(1 + msg->retries,
25059 + atomic_long_add_unchecked(1 + msg->retries,
25060 &port->counter_group[CM_XMIT].counter[attr_index]);
25061 if (msg->retries)
25062 - atomic_long_add(msg->retries,
25063 + atomic_long_add_unchecked(msg->retries,
25064 &port->counter_group[CM_XMIT_RETRIES].
25065 counter[attr_index]);
25066
25067 @@ -3399,7 +3399,7 @@ static void cm_recv_handler(struct ib_ma
25068 }
25069
25070 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
25071 - atomic_long_inc(&port->counter_group[CM_RECV].
25072 + atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
25073 counter[attr_id - CM_ATTR_ID_OFFSET]);
25074
25075 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
25076 @@ -3597,7 +3597,7 @@ static ssize_t cm_show_counter(struct ko
25077 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
25078
25079 return sprintf(buf, "%ld\n",
25080 - atomic_long_read(&group->counter[cm_attr->index]));
25081 + atomic_long_read_unchecked(&group->counter[cm_attr->index]));
25082 }
25083
25084 static const struct sysfs_ops cm_counter_ops = {
25085 diff -urNp linux-2.6.37/drivers/infiniband/hw/qib/qib.h linux-2.6.37/drivers/infiniband/hw/qib/qib.h
25086 --- linux-2.6.37/drivers/infiniband/hw/qib/qib.h 2011-01-04 19:50:19.000000000 -0500
25087 +++ linux-2.6.37/drivers/infiniband/hw/qib/qib.h 2011-01-17 02:41:01.000000000 -0500
25088 @@ -51,6 +51,7 @@
25089 #include <linux/completion.h>
25090 #include <linux/kref.h>
25091 #include <linux/sched.h>
25092 +#include <linux/slab.h>
25093
25094 #include "qib_common.h"
25095 #include "qib_verbs.h"
25096 diff -urNp linux-2.6.37/drivers/input/keyboard/atkbd.c linux-2.6.37/drivers/input/keyboard/atkbd.c
25097 --- linux-2.6.37/drivers/input/keyboard/atkbd.c 2011-01-04 19:50:19.000000000 -0500
25098 +++ linux-2.6.37/drivers/input/keyboard/atkbd.c 2011-01-17 02:41:01.000000000 -0500
25099 @@ -1250,7 +1250,7 @@ static struct serio_device_id atkbd_seri
25100 .id = SERIO_ANY,
25101 .extra = SERIO_ANY,
25102 },
25103 - { 0 }
25104 + { 0, 0, 0, 0 }
25105 };
25106
25107 MODULE_DEVICE_TABLE(serio, atkbd_serio_ids);
25108 diff -urNp linux-2.6.37/drivers/input/mouse/lifebook.c linux-2.6.37/drivers/input/mouse/lifebook.c
25109 --- linux-2.6.37/drivers/input/mouse/lifebook.c 2011-01-04 19:50:19.000000000 -0500
25110 +++ linux-2.6.37/drivers/input/mouse/lifebook.c 2011-01-17 02:41:01.000000000 -0500
25111 @@ -123,7 +123,7 @@ static const struct dmi_system_id __init
25112 DMI_MATCH(DMI_PRODUCT_NAME, "LifeBook B142"),
25113 },
25114 },
25115 - { }
25116 + { NULL, NULL, {DMI_MATCH(DMI_NONE, {0})}, NULL}
25117 };
25118
25119 void __init lifebook_module_init(void)
25120 diff -urNp linux-2.6.37/drivers/input/mouse/psmouse-base.c linux-2.6.37/drivers/input/mouse/psmouse-base.c
25121 --- linux-2.6.37/drivers/input/mouse/psmouse-base.c 2011-01-04 19:50:19.000000000 -0500
25122 +++ linux-2.6.37/drivers/input/mouse/psmouse-base.c 2011-01-17 02:41:01.000000000 -0500
25123 @@ -1462,7 +1462,7 @@ static struct serio_device_id psmouse_se
25124 .id = SERIO_ANY,
25125 .extra = SERIO_ANY,
25126 },
25127 - { 0 }
25128 + { 0, 0, 0, 0 }
25129 };
25130
25131 MODULE_DEVICE_TABLE(serio, psmouse_serio_ids);
25132 diff -urNp linux-2.6.37/drivers/input/mouse/synaptics.c linux-2.6.37/drivers/input/mouse/synaptics.c
25133 --- linux-2.6.37/drivers/input/mouse/synaptics.c 2011-01-04 19:50:19.000000000 -0500
25134 +++ linux-2.6.37/drivers/input/mouse/synaptics.c 2011-01-17 02:41:01.000000000 -0500
25135 @@ -499,7 +499,7 @@ static void synaptics_process_packet(str
25136 break;
25137 case 2:
25138 if (SYN_MODEL_PEN(priv->model_id))
25139 - ; /* Nothing, treat a pen as a single finger */
25140 + break; /* Nothing, treat a pen as a single finger */
25141 break;
25142 case 4 ... 15:
25143 if (SYN_CAP_PALMDETECT(priv->capabilities))
25144 @@ -729,7 +729,6 @@ static const struct dmi_system_id __init
25145 DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
25146 DMI_MATCH(DMI_PRODUCT_NAME, "PORTEGE M300"),
25147 },
25148 -
25149 },
25150 {
25151 /* Toshiba Portege M300 */
25152 @@ -738,9 +737,8 @@ static const struct dmi_system_id __init
25153 DMI_MATCH(DMI_PRODUCT_NAME, "Portable PC"),
25154 DMI_MATCH(DMI_PRODUCT_VERSION, "Version 1.0"),
25155 },
25156 -
25157 },
25158 - { }
25159 + { NULL, NULL, {DMI_MATCH(DMI_NONE, {0})}, NULL }
25160 #endif
25161 };
25162
25163 diff -urNp linux-2.6.37/drivers/input/mousedev.c linux-2.6.37/drivers/input/mousedev.c
25164 --- linux-2.6.37/drivers/input/mousedev.c 2011-01-04 19:50:19.000000000 -0500
25165 +++ linux-2.6.37/drivers/input/mousedev.c 2011-01-17 02:41:01.000000000 -0500
25166 @@ -762,7 +762,7 @@ static ssize_t mousedev_read(struct file
25167
25168 spin_unlock_irq(&client->packet_lock);
25169
25170 - if (copy_to_user(buffer, data, count))
25171 + if (count > sizeof(data) || copy_to_user(buffer, data, count))
25172 return -EFAULT;
25173
25174 return count;
25175 @@ -1065,7 +1065,7 @@ static struct input_handler mousedev_han
25176
25177 #ifdef CONFIG_INPUT_MOUSEDEV_PSAUX
25178 static struct miscdevice psaux_mouse = {
25179 - PSMOUSE_MINOR, "psaux", &mousedev_fops
25180 + PSMOUSE_MINOR, "psaux", &mousedev_fops, {NULL, NULL}, NULL, NULL
25181 };
25182 static int psaux_registered;
25183 #endif
25184 diff -urNp linux-2.6.37/drivers/input/serio/i8042-x86ia64io.h linux-2.6.37/drivers/input/serio/i8042-x86ia64io.h
25185 --- linux-2.6.37/drivers/input/serio/i8042-x86ia64io.h 2011-01-04 19:50:19.000000000 -0500
25186 +++ linux-2.6.37/drivers/input/serio/i8042-x86ia64io.h 2011-01-17 02:41:01.000000000 -0500
25187 @@ -183,7 +183,7 @@ static const struct dmi_system_id __init
25188 DMI_MATCH(DMI_PRODUCT_VERSION, "Rev 1"),
25189 },
25190 },
25191 - { }
25192 + { NULL, NULL, {DMI_MATCH(DMI_NONE, {0})}, NULL }
25193 };
25194
25195 /*
25196 @@ -424,7 +424,7 @@ static const struct dmi_system_id __init
25197 DMI_MATCH(DMI_PRODUCT_VERSION, "0100"),
25198 },
25199 },
25200 - { }
25201 + { NULL, NULL, {DMI_MATCH(DMI_NONE, {0})}, NULL }
25202 };
25203
25204 static const struct dmi_system_id __initconst i8042_dmi_reset_table[] = {
25205 @@ -498,7 +498,7 @@ static const struct dmi_system_id __init
25206 DMI_MATCH(DMI_PRODUCT_NAME, "Vostro 1720"),
25207 },
25208 },
25209 - { }
25210 + { NULL, NULL, {DMI_MATCH(DMI_NONE, {0})}, NULL }
25211 };
25212
25213 #ifdef CONFIG_PNP
25214 @@ -517,7 +517,7 @@ static const struct dmi_system_id __init
25215 DMI_MATCH(DMI_BOARD_VENDOR, "MICRO-STAR INTERNATIONAL CO., LTD"),
25216 },
25217 },
25218 - { }
25219 + { NULL, NULL, {DMI_MATCH(DMI_NONE, {0})}, NULL }
25220 };
25221
25222 static const struct dmi_system_id __initconst i8042_dmi_laptop_table[] = {
25223 @@ -541,7 +541,7 @@ static const struct dmi_system_id __init
25224 DMI_MATCH(DMI_CHASSIS_TYPE, "14"), /* Sub-Notebook */
25225 },
25226 },
25227 - { }
25228 + { NULL, NULL, {DMI_MATCH(DMI_NONE, {0})}, NULL }
25229 };
25230 #endif
25231
25232 @@ -615,7 +615,7 @@ static const struct dmi_system_id __init
25233 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 4280"),
25234 },
25235 },
25236 - { }
25237 + { NULL, NULL, {DMI_MATCH(DMI_NONE, {0})}, NULL }
25238 };
25239
25240 #endif /* CONFIG_X86 */
25241 diff -urNp linux-2.6.37/drivers/input/serio/serio_raw.c linux-2.6.37/drivers/input/serio/serio_raw.c
25242 --- linux-2.6.37/drivers/input/serio/serio_raw.c 2011-01-04 19:50:19.000000000 -0500
25243 +++ linux-2.6.37/drivers/input/serio/serio_raw.c 2011-01-17 02:41:01.000000000 -0500
25244 @@ -376,7 +376,7 @@ static struct serio_device_id serio_raw_
25245 .id = SERIO_ANY,
25246 .extra = SERIO_ANY,
25247 },
25248 - { 0 }
25249 + { 0, 0, 0, 0 }
25250 };
25251
25252 MODULE_DEVICE_TABLE(serio, serio_raw_serio_ids);
25253 diff -urNp linux-2.6.37/drivers/isdn/gigaset/common.c linux-2.6.37/drivers/isdn/gigaset/common.c
25254 --- linux-2.6.37/drivers/isdn/gigaset/common.c 2011-01-04 19:50:19.000000000 -0500
25255 +++ linux-2.6.37/drivers/isdn/gigaset/common.c 2011-01-17 02:41:01.000000000 -0500
25256 @@ -723,7 +723,7 @@ struct cardstate *gigaset_initcs(struct
25257 cs->commands_pending = 0;
25258 cs->cur_at_seq = 0;
25259 cs->gotfwver = -1;
25260 - cs->open_count = 0;
25261 + atomic_set(&cs->open_count, 0);
25262 cs->dev = NULL;
25263 cs->tty = NULL;
25264 cs->tty_dev = NULL;
25265 diff -urNp linux-2.6.37/drivers/isdn/gigaset/gigaset.h linux-2.6.37/drivers/isdn/gigaset/gigaset.h
25266 --- linux-2.6.37/drivers/isdn/gigaset/gigaset.h 2011-01-04 19:50:19.000000000 -0500
25267 +++ linux-2.6.37/drivers/isdn/gigaset/gigaset.h 2011-01-17 02:41:01.000000000 -0500
25268 @@ -433,7 +433,7 @@ struct cardstate {
25269 spinlock_t cmdlock;
25270 unsigned curlen, cmdbytes;
25271
25272 - unsigned open_count;
25273 + atomic_t open_count;
25274 struct tty_struct *tty;
25275 struct tasklet_struct if_wake_tasklet;
25276 unsigned control_state;
25277 diff -urNp linux-2.6.37/drivers/isdn/gigaset/interface.c linux-2.6.37/drivers/isdn/gigaset/interface.c
25278 --- linux-2.6.37/drivers/isdn/gigaset/interface.c 2011-01-04 19:50:19.000000000 -0500
25279 +++ linux-2.6.37/drivers/isdn/gigaset/interface.c 2011-01-17 02:41:01.000000000 -0500
25280 @@ -160,9 +160,7 @@ static int if_open(struct tty_struct *tt
25281 return -ERESTARTSYS;
25282 tty->driver_data = cs;
25283
25284 - ++cs->open_count;
25285 -
25286 - if (cs->open_count == 1) {
25287 + if (atomic_inc_return(&cs->open_count) == 1) {
25288 spin_lock_irqsave(&cs->lock, flags);
25289 cs->tty = tty;
25290 spin_unlock_irqrestore(&cs->lock, flags);
25291 @@ -190,10 +188,10 @@ static void if_close(struct tty_struct *
25292
25293 if (!cs->connected)
25294 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
25295 - else if (!cs->open_count)
25296 + else if (!atomic_read(&cs->open_count))
25297 dev_warn(cs->dev, "%s: device not opened\n", __func__);
25298 else {
25299 - if (!--cs->open_count) {
25300 + if (!atomic_dec_return(&cs->open_count)) {
25301 spin_lock_irqsave(&cs->lock, flags);
25302 cs->tty = NULL;
25303 spin_unlock_irqrestore(&cs->lock, flags);
25304 @@ -228,7 +226,7 @@ static int if_ioctl(struct tty_struct *t
25305 if (!cs->connected) {
25306 gig_dbg(DEBUG_IF, "not connected");
25307 retval = -ENODEV;
25308 - } else if (!cs->open_count)
25309 + } else if (!atomic_read(&cs->open_count))
25310 dev_warn(cs->dev, "%s: device not opened\n", __func__);
25311 else {
25312 retval = 0;
25313 @@ -358,7 +356,7 @@ static int if_write(struct tty_struct *t
25314 retval = -ENODEV;
25315 goto done;
25316 }
25317 - if (!cs->open_count) {
25318 + if (!atomic_read(&cs->open_count)) {
25319 dev_warn(cs->dev, "%s: device not opened\n", __func__);
25320 retval = -ENODEV;
25321 goto done;
25322 @@ -411,7 +409,7 @@ static int if_write_room(struct tty_stru
25323 if (!cs->connected) {
25324 gig_dbg(DEBUG_IF, "not connected");
25325 retval = -ENODEV;
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 @@ -441,7 +439,7 @@ static int if_chars_in_buffer(struct tty
25332
25333 if (!cs->connected)
25334 gig_dbg(DEBUG_IF, "not connected");
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__);
25338 else if (cs->mstate != MS_LOCKED)
25339 dev_warn(cs->dev, "can't write to unlocked device\n");
25340 @@ -469,7 +467,7 @@ static void if_throttle(struct tty_struc
25341
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__);
25347 else
25348 gig_dbg(DEBUG_IF, "%s: not implemented\n", __func__);
25349 @@ -493,7 +491,7 @@ static void if_unthrottle(struct tty_str
25350
25351 if (!cs->connected)
25352 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
25353 - else if (!cs->open_count)
25354 + else if (!atomic_read(&cs->open_count))
25355 dev_warn(cs->dev, "%s: device not opened\n", __func__);
25356 else
25357 gig_dbg(DEBUG_IF, "%s: not implemented\n", __func__);
25358 @@ -524,7 +522,7 @@ static void if_set_termios(struct tty_st
25359 goto out;
25360 }
25361
25362 - if (!cs->open_count) {
25363 + if (!atomic_read(&cs->open_count)) {
25364 dev_warn(cs->dev, "%s: device not opened\n", __func__);
25365 goto out;
25366 }
25367 diff -urNp linux-2.6.37/drivers/isdn/hardware/avm/b1.c linux-2.6.37/drivers/isdn/hardware/avm/b1.c
25368 --- linux-2.6.37/drivers/isdn/hardware/avm/b1.c 2011-01-04 19:50:19.000000000 -0500
25369 +++ linux-2.6.37/drivers/isdn/hardware/avm/b1.c 2011-01-17 02:41:01.000000000 -0500
25370 @@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capilo
25371 }
25372 if (left) {
25373 if (t4file->user) {
25374 - if (copy_from_user(buf, dp, left))
25375 + if (left > sizeof buf || copy_from_user(buf, dp, left))
25376 return -EFAULT;
25377 } else {
25378 memcpy(buf, dp, left);
25379 @@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capilo
25380 }
25381 if (left) {
25382 if (config->user) {
25383 - if (copy_from_user(buf, dp, left))
25384 + if (left > sizeof buf || copy_from_user(buf, dp, left))
25385 return -EFAULT;
25386 } else {
25387 memcpy(buf, dp, left);
25388 diff -urNp linux-2.6.37/drivers/isdn/icn/icn.c linux-2.6.37/drivers/isdn/icn/icn.c
25389 --- linux-2.6.37/drivers/isdn/icn/icn.c 2011-01-04 19:50:19.000000000 -0500
25390 +++ linux-2.6.37/drivers/isdn/icn/icn.c 2011-01-17 02:41:01.000000000 -0500
25391 @@ -1045,7 +1045,7 @@ icn_writecmd(const u_char * buf, int len
25392 if (count > len)
25393 count = len;
25394 if (user) {
25395 - if (copy_from_user(msg, buf, count))
25396 + if (count > sizeof msg || copy_from_user(msg, buf, count))
25397 return -EFAULT;
25398 } else
25399 memcpy(msg, buf, count);
25400 diff -urNp linux-2.6.37/drivers/lguest/core.c linux-2.6.37/drivers/lguest/core.c
25401 --- linux-2.6.37/drivers/lguest/core.c 2011-01-04 19:50:19.000000000 -0500
25402 +++ linux-2.6.37/drivers/lguest/core.c 2011-01-17 02:41:01.000000000 -0500
25403 @@ -92,9 +92,17 @@ static __init int map_switcher(void)
25404 * it's worked so far. The end address needs +1 because __get_vm_area
25405 * allocates an extra guard page, so we need space for that.
25406 */
25407 +
25408 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
25409 + switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
25410 + VM_ALLOC | VM_KERNEXEC, SWITCHER_ADDR, SWITCHER_ADDR
25411 + + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
25412 +#else
25413 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
25414 VM_ALLOC, SWITCHER_ADDR, SWITCHER_ADDR
25415 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
25416 +#endif
25417 +
25418 if (!switcher_vma) {
25419 err = -ENOMEM;
25420 printk("lguest: could not map switcher pages high\n");
25421 @@ -119,7 +127,7 @@ static __init int map_switcher(void)
25422 * Now the Switcher is mapped at the right address, we can't fail!
25423 * Copy in the compiled-in Switcher code (from <arch>_switcher.S).
25424 */
25425 - memcpy(switcher_vma->addr, start_switcher_text,
25426 + memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
25427 end_switcher_text - start_switcher_text);
25428
25429 printk(KERN_INFO "lguest: mapped switcher at %p\n",
25430 diff -urNp linux-2.6.37/drivers/lguest/x86/core.c linux-2.6.37/drivers/lguest/x86/core.c
25431 --- linux-2.6.37/drivers/lguest/x86/core.c 2011-01-04 19:50:19.000000000 -0500
25432 +++ linux-2.6.37/drivers/lguest/x86/core.c 2011-01-17 02:41:01.000000000 -0500
25433 @@ -59,7 +59,7 @@ static struct {
25434 /* Offset from where switcher.S was compiled to where we've copied it */
25435 static unsigned long switcher_offset(void)
25436 {
25437 - return SWITCHER_ADDR - (unsigned long)start_switcher_text;
25438 + return SWITCHER_ADDR - (unsigned long)ktla_ktva(start_switcher_text);
25439 }
25440
25441 /* This cpu's struct lguest_pages. */
25442 @@ -100,7 +100,13 @@ static void copy_in_guest_info(struct lg
25443 * These copies are pretty cheap, so we do them unconditionally: */
25444 /* Save the current Host top-level page directory.
25445 */
25446 +
25447 +#ifdef CONFIG_PAX_PER_CPU_PGD
25448 + pages->state.host_cr3 = read_cr3();
25449 +#else
25450 pages->state.host_cr3 = __pa(current->mm->pgd);
25451 +#endif
25452 +
25453 /*
25454 * Set up the Guest's page tables to see this CPU's pages (and no
25455 * other CPU's pages).
25456 @@ -547,7 +553,7 @@ void __init lguest_arch_host_init(void)
25457 * compiled-in switcher code and the high-mapped copy we just made.
25458 */
25459 for (i = 0; i < IDT_ENTRIES; i++)
25460 - default_idt_entries[i] += switcher_offset();
25461 + default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
25462
25463 /*
25464 * Set up the Switcher's per-cpu areas.
25465 @@ -630,7 +636,7 @@ void __init lguest_arch_host_init(void)
25466 * it will be undisturbed when we switch. To change %cs and jump we
25467 * need this structure to feed to Intel's "lcall" instruction.
25468 */
25469 - lguest_entry.offset = (long)switch_to_guest + switcher_offset();
25470 + lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
25471 lguest_entry.segment = LGUEST_CS;
25472
25473 /*
25474 diff -urNp linux-2.6.37/drivers/lguest/x86/switcher_32.S linux-2.6.37/drivers/lguest/x86/switcher_32.S
25475 --- linux-2.6.37/drivers/lguest/x86/switcher_32.S 2011-01-04 19:50:19.000000000 -0500
25476 +++ linux-2.6.37/drivers/lguest/x86/switcher_32.S 2011-01-17 02:41:01.000000000 -0500
25477 @@ -87,6 +87,7 @@
25478 #include <asm/page.h>
25479 #include <asm/segment.h>
25480 #include <asm/lguest.h>
25481 +#include <asm/processor-flags.h>
25482
25483 // We mark the start of the code to copy
25484 // It's placed in .text tho it's never run here
25485 @@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
25486 // Changes type when we load it: damn Intel!
25487 // For after we switch over our page tables
25488 // That entry will be read-only: we'd crash.
25489 +
25490 +#ifdef CONFIG_PAX_KERNEXEC
25491 + mov %cr0, %edx
25492 + xor $X86_CR0_WP, %edx
25493 + mov %edx, %cr0
25494 +#endif
25495 +
25496 movl $(GDT_ENTRY_TSS*8), %edx
25497 ltr %dx
25498
25499 @@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
25500 // Let's clear it again for our return.
25501 // The GDT descriptor of the Host
25502 // Points to the table after two "size" bytes
25503 - movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
25504 + movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
25505 // Clear "used" from type field (byte 5, bit 2)
25506 - andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
25507 + andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
25508 +
25509 +#ifdef CONFIG_PAX_KERNEXEC
25510 + mov %cr0, %eax
25511 + xor $X86_CR0_WP, %eax
25512 + mov %eax, %cr0
25513 +#endif
25514
25515 // Once our page table's switched, the Guest is live!
25516 // The Host fades as we run this final step.
25517 @@ -295,13 +309,12 @@ deliver_to_host:
25518 // I consulted gcc, and it gave
25519 // These instructions, which I gladly credit:
25520 leal (%edx,%ebx,8), %eax
25521 - movzwl (%eax),%edx
25522 - movl 4(%eax), %eax
25523 - xorw %ax, %ax
25524 - orl %eax, %edx
25525 + movl 4(%eax), %edx
25526 + movw (%eax), %dx
25527 // Now the address of the handler's in %edx
25528 // We call it now: its "iret" drops us home.
25529 - jmp *%edx
25530 + ljmp $__KERNEL_CS, $1f
25531 +1: jmp *%edx
25532
25533 // Every interrupt can come to us here
25534 // But we must truly tell each apart.
25535 diff -urNp linux-2.6.37/drivers/macintosh/via-pmu-backlight.c linux-2.6.37/drivers/macintosh/via-pmu-backlight.c
25536 --- linux-2.6.37/drivers/macintosh/via-pmu-backlight.c 2011-01-04 19:50:19.000000000 -0500
25537 +++ linux-2.6.37/drivers/macintosh/via-pmu-backlight.c 2011-01-17 02:41:01.000000000 -0500
25538 @@ -15,7 +15,7 @@
25539
25540 #define MAX_PMU_LEVEL 0xFF
25541
25542 -static struct backlight_ops pmu_backlight_data;
25543 +static const struct backlight_ops pmu_backlight_data;
25544 static DEFINE_SPINLOCK(pmu_backlight_lock);
25545 static int sleeping, uses_pmu_bl;
25546 static u8 bl_curve[FB_BACKLIGHT_LEVELS];
25547 @@ -115,7 +115,7 @@ static int pmu_backlight_get_brightness(
25548 return bd->props.brightness;
25549 }
25550
25551 -static struct backlight_ops pmu_backlight_data = {
25552 +static const struct backlight_ops pmu_backlight_data = {
25553 .get_brightness = pmu_backlight_get_brightness,
25554 .update_status = pmu_backlight_update_status,
25555
25556 diff -urNp linux-2.6.37/drivers/macintosh/via-pmu.c linux-2.6.37/drivers/macintosh/via-pmu.c
25557 --- linux-2.6.37/drivers/macintosh/via-pmu.c 2011-01-04 19:50:19.000000000 -0500
25558 +++ linux-2.6.37/drivers/macintosh/via-pmu.c 2011-01-17 02:41:01.000000000 -0500
25559 @@ -2257,7 +2257,7 @@ static int pmu_sleep_valid(suspend_state
25560 && (pmac_call_feature(PMAC_FTR_SLEEP_STATE, NULL, 0, -1) >= 0);
25561 }
25562
25563 -static struct platform_suspend_ops pmu_pm_ops = {
25564 +static const struct platform_suspend_ops pmu_pm_ops = {
25565 .enter = powerbook_sleep,
25566 .valid = pmu_sleep_valid,
25567 };
25568 diff -urNp linux-2.6.37/drivers/md/bitmap.c linux-2.6.37/drivers/md/bitmap.c
25569 --- linux-2.6.37/drivers/md/bitmap.c 2011-01-04 19:50:19.000000000 -0500
25570 +++ linux-2.6.37/drivers/md/bitmap.c 2011-01-17 02:41:01.000000000 -0500
25571 @@ -55,7 +55,7 @@
25572 # if DEBUG > 0
25573 # define PRINTK(x...) printk(KERN_DEBUG x)
25574 # else
25575 -# define PRINTK(x...)
25576 +# define PRINTK(x...) do {} while (0)
25577 # endif
25578 #endif
25579
25580 diff -urNp linux-2.6.37/drivers/md/dm-table.c linux-2.6.37/drivers/md/dm-table.c
25581 --- linux-2.6.37/drivers/md/dm-table.c 2011-01-04 19:50:19.000000000 -0500
25582 +++ linux-2.6.37/drivers/md/dm-table.c 2011-01-17 02:41:01.000000000 -0500
25583 @@ -366,7 +366,7 @@ static int device_area_is_invalid(struct
25584 if (!dev_size)
25585 return 0;
25586
25587 - if ((start >= dev_size) || (start + len > dev_size)) {
25588 + if ((start >= dev_size) || (len > dev_size - start)) {
25589 DMWARN("%s: %s too small for target: "
25590 "start=%llu, len=%llu, dev_size=%llu",
25591 dm_device_name(ti->table->md), bdevname(bdev, b),
25592 diff -urNp linux-2.6.37/drivers/md/md.c linux-2.6.37/drivers/md/md.c
25593 --- linux-2.6.37/drivers/md/md.c 2011-01-04 19:50:19.000000000 -0500
25594 +++ linux-2.6.37/drivers/md/md.c 2011-01-17 02:41:01.000000000 -0500
25595 @@ -1875,7 +1875,7 @@ static int bind_rdev_to_array(mdk_rdev_t
25596
25597 ko = &part_to_dev(rdev->bdev->bd_part)->kobj;
25598 if (sysfs_create_link(&rdev->kobj, ko, "block"))
25599 - /* failure here is OK */;
25600 + /* failure here is OK */{}
25601 rdev->sysfs_state = sysfs_get_dirent_safe(rdev->kobj.sd, "state");
25602
25603 list_add_rcu(&rdev->same_set, &mddev->disks);
25604 @@ -2487,7 +2487,7 @@ slot_store(mdk_rdev_t *rdev, const char
25605 sysfs_notify_dirent_safe(rdev->sysfs_state);
25606 sprintf(nm, "rd%d", rdev->raid_disk);
25607 if (sysfs_create_link(&rdev->mddev->kobj, &rdev->kobj, nm))
25608 - /* failure here is OK */;
25609 + /* failure here is OK */{}
25610 /* don't wakeup anyone, leave that to userspace. */
25611 } else {
25612 if (slot >= rdev->mddev->raid_disks)
25613 @@ -4570,7 +4570,7 @@ int md_run(mddev_t *mddev)
25614 char nm[20];
25615 sprintf(nm, "rd%d", rdev->raid_disk);
25616 if (sysfs_create_link(&mddev->kobj, &rdev->kobj, nm))
25617 - /* failure here is OK */;
25618 + /* failure here is OK */{}
25619 }
25620
25621 set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
25622 @@ -6408,7 +6408,7 @@ static int md_seq_show(struct seq_file *
25623 chunk_kb ? "KB" : "B");
25624 if (bitmap->file) {
25625 seq_printf(seq, ", file: ");
25626 - seq_path(seq, &bitmap->file->f_path, " \t\n");
25627 + seq_path(seq, &bitmap->file->f_path, " \t\n\\");
25628 }
25629
25630 seq_printf(seq, "\n");
25631 @@ -6502,7 +6502,7 @@ static int is_mddev_idle(mddev_t *mddev,
25632 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
25633 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
25634 (int)part_stat_read(&disk->part0, sectors[1]) -
25635 - atomic_read(&disk->sync_io);
25636 + atomic_read_unchecked(&disk->sync_io);
25637 /* sync IO will cause sync_io to increase before the disk_stats
25638 * as sync_io is counted when a request starts, and
25639 * disk_stats is counted when it completes.
25640 @@ -7020,7 +7020,7 @@ static int remove_and_add_spares(mddev_t
25641 sprintf(nm, "rd%d", rdev->raid_disk);
25642 if (sysfs_create_link(&mddev->kobj,
25643 &rdev->kobj, nm))
25644 - /* failure here is OK */;
25645 + /* failure here is OK */{}
25646 spares++;
25647 md_new_event(mddev);
25648 set_bit(MD_CHANGE_DEVS, &mddev->flags);
25649 diff -urNp linux-2.6.37/drivers/md/md.h linux-2.6.37/drivers/md/md.h
25650 --- linux-2.6.37/drivers/md/md.h 2011-01-04 19:50:19.000000000 -0500
25651 +++ linux-2.6.37/drivers/md/md.h 2011-01-17 02:41:01.000000000 -0500
25652 @@ -353,7 +353,7 @@ static inline void rdev_dec_pending(mdk_
25653
25654 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
25655 {
25656 - atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
25657 + atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
25658 }
25659
25660 struct mdk_personality
25661 diff -urNp linux-2.6.37/drivers/media/dvb/dvb-core/dvbdev.c linux-2.6.37/drivers/media/dvb/dvb-core/dvbdev.c
25662 --- linux-2.6.37/drivers/media/dvb/dvb-core/dvbdev.c 2011-01-04 19:50:19.000000000 -0500
25663 +++ linux-2.6.37/drivers/media/dvb/dvb-core/dvbdev.c 2011-01-17 02:41:01.000000000 -0500
25664 @@ -192,6 +192,7 @@ int dvb_register_device(struct dvb_adapt
25665 const struct dvb_device *template, void *priv, int type)
25666 {
25667 struct dvb_device *dvbdev;
25668 + /* cannot be const, see this function */
25669 struct file_operations *dvbdevfops;
25670 struct device *clsdev;
25671 int minor;
25672 diff -urNp linux-2.6.37/drivers/media/IR/ir-lirc-codec.c linux-2.6.37/drivers/media/IR/ir-lirc-codec.c
25673 --- linux-2.6.37/drivers/media/IR/ir-lirc-codec.c 2011-01-04 19:50:19.000000000 -0500
25674 +++ linux-2.6.37/drivers/media/IR/ir-lirc-codec.c 2011-01-17 02:41:01.000000000 -0500
25675 @@ -275,7 +275,7 @@ static void ir_lirc_close(void *data)
25676 return;
25677 }
25678
25679 -static struct file_operations lirc_fops = {
25680 +static const struct file_operations lirc_fops = {
25681 .owner = THIS_MODULE,
25682 .write = ir_lirc_transmit_ir,
25683 .unlocked_ioctl = ir_lirc_ioctl,
25684 diff -urNp linux-2.6.37/drivers/media/IR/lirc_dev.c linux-2.6.37/drivers/media/IR/lirc_dev.c
25685 --- linux-2.6.37/drivers/media/IR/lirc_dev.c 2011-01-04 19:50:19.000000000 -0500
25686 +++ linux-2.6.37/drivers/media/IR/lirc_dev.c 2011-01-17 02:41:01.000000000 -0500
25687 @@ -151,7 +151,7 @@ static int lirc_thread(void *irctl)
25688 }
25689
25690
25691 -static struct file_operations lirc_dev_fops = {
25692 +static const struct file_operations lirc_dev_fops = {
25693 .owner = THIS_MODULE,
25694 .read = lirc_dev_fop_read,
25695 .write = lirc_dev_fop_write,
25696 diff -urNp linux-2.6.37/drivers/media/radio/radio-cadet.c linux-2.6.37/drivers/media/radio/radio-cadet.c
25697 --- linux-2.6.37/drivers/media/radio/radio-cadet.c 2011-01-04 19:50:19.000000000 -0500
25698 +++ linux-2.6.37/drivers/media/radio/radio-cadet.c 2011-01-17 02:41:01.000000000 -0500
25699 @@ -349,7 +349,7 @@ static ssize_t cadet_read(struct file *f
25700 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
25701 mutex_unlock(&dev->lock);
25702
25703 - if (copy_to_user(data, readbuf, i))
25704 + if (i > sizeof readbuf || copy_to_user(data, readbuf, i))
25705 return -EFAULT;
25706 return i;
25707 }
25708 diff -urNp linux-2.6.37/drivers/media/video/saa7164/saa7164-core.c linux-2.6.37/drivers/media/video/saa7164/saa7164-core.c
25709 --- linux-2.6.37/drivers/media/video/saa7164/saa7164-core.c 2011-01-04 19:50:19.000000000 -0500
25710 +++ linux-2.6.37/drivers/media/video/saa7164/saa7164-core.c 2011-01-17 02:41:01.000000000 -0500
25711 @@ -1169,7 +1169,7 @@ static int saa7164_proc_open(struct inod
25712 return single_open(filp, saa7164_proc_show, NULL);
25713 }
25714
25715 -static struct file_operations saa7164_proc_fops = {
25716 +static const struct file_operations saa7164_proc_fops = {
25717 .open = saa7164_proc_open,
25718 .read = seq_read,
25719 .llseek = seq_lseek,
25720 diff -urNp linux-2.6.37/drivers/message/fusion/mptbase.c linux-2.6.37/drivers/message/fusion/mptbase.c
25721 --- linux-2.6.37/drivers/message/fusion/mptbase.c 2011-01-04 19:50:19.000000000 -0500
25722 +++ linux-2.6.37/drivers/message/fusion/mptbase.c 2011-01-17 02:41:01.000000000 -0500
25723 @@ -6683,8 +6683,13 @@ static int mpt_iocinfo_proc_show(struct
25724 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
25725 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
25726
25727 +#ifdef CONFIG_GRKERNSEC_HIDESYM
25728 + seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
25729 +#else
25730 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
25731 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
25732 +#endif
25733 +
25734 /*
25735 * Rounding UP to nearest 4-kB boundary here...
25736 */
25737 diff -urNp linux-2.6.37/drivers/message/fusion/mptdebug.h linux-2.6.37/drivers/message/fusion/mptdebug.h
25738 --- linux-2.6.37/drivers/message/fusion/mptdebug.h 2011-01-04 19:50:19.000000000 -0500
25739 +++ linux-2.6.37/drivers/message/fusion/mptdebug.h 2011-01-17 02:41:01.000000000 -0500
25740 @@ -71,7 +71,7 @@
25741 CMD; \
25742 }
25743 #else
25744 -#define MPT_CHECK_LOGGING(IOC, CMD, BITS)
25745 +#define MPT_CHECK_LOGGING(IOC, CMD, BITS) do {} while (0)
25746 #endif
25747
25748
25749 diff -urNp linux-2.6.37/drivers/message/fusion/mptsas.c linux-2.6.37/drivers/message/fusion/mptsas.c
25750 --- linux-2.6.37/drivers/message/fusion/mptsas.c 2011-01-04 19:50:19.000000000 -0500
25751 +++ linux-2.6.37/drivers/message/fusion/mptsas.c 2011-01-17 02:41:01.000000000 -0500
25752 @@ -439,6 +439,23 @@ mptsas_is_end_device(struct mptsas_devin
25753 return 0;
25754 }
25755
25756 +static inline void
25757 +mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
25758 +{
25759 + if (phy_info->port_details) {
25760 + phy_info->port_details->rphy = rphy;
25761 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
25762 + ioc->name, rphy));
25763 + }
25764 +
25765 + if (rphy) {
25766 + dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
25767 + &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
25768 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
25769 + ioc->name, rphy, rphy->dev.release));
25770 + }
25771 +}
25772 +
25773 /* no mutex */
25774 static void
25775 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
25776 @@ -477,23 +494,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *p
25777 return NULL;
25778 }
25779
25780 -static inline void
25781 -mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
25782 -{
25783 - if (phy_info->port_details) {
25784 - phy_info->port_details->rphy = rphy;
25785 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
25786 - ioc->name, rphy));
25787 - }
25788 -
25789 - if (rphy) {
25790 - dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
25791 - &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
25792 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
25793 - ioc->name, rphy, rphy->dev.release));
25794 - }
25795 -}
25796 -
25797 static inline struct sas_port *
25798 mptsas_get_port(struct mptsas_phyinfo *phy_info)
25799 {
25800 diff -urNp linux-2.6.37/drivers/message/fusion/mptscsih.c linux-2.6.37/drivers/message/fusion/mptscsih.c
25801 --- linux-2.6.37/drivers/message/fusion/mptscsih.c 2011-01-04 19:50:19.000000000 -0500
25802 +++ linux-2.6.37/drivers/message/fusion/mptscsih.c 2011-01-17 02:41:01.000000000 -0500
25803 @@ -1268,15 +1268,16 @@ mptscsih_info(struct Scsi_Host *SChost)
25804
25805 h = shost_priv(SChost);
25806
25807 - if (h) {
25808 - if (h->info_kbuf == NULL)
25809 - if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
25810 - return h->info_kbuf;
25811 - h->info_kbuf[0] = '\0';
25812 + if (!h)
25813 + return NULL;
25814
25815 - mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
25816 - h->info_kbuf[size-1] = '\0';
25817 - }
25818 + if (h->info_kbuf == NULL)
25819 + if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
25820 + return h->info_kbuf;
25821 + h->info_kbuf[0] = '\0';
25822 +
25823 + mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
25824 + h->info_kbuf[size-1] = '\0';
25825
25826 return h->info_kbuf;
25827 }
25828 diff -urNp linux-2.6.37/drivers/message/i2o/i2o_proc.c linux-2.6.37/drivers/message/i2o/i2o_proc.c
25829 --- linux-2.6.37/drivers/message/i2o/i2o_proc.c 2011-01-04 19:50:19.000000000 -0500
25830 +++ linux-2.6.37/drivers/message/i2o/i2o_proc.c 2011-01-17 02:41:01.000000000 -0500
25831 @@ -255,13 +255,6 @@ static char *scsi_devices[] = {
25832 "Array Controller Device"
25833 };
25834
25835 -static char *chtostr(u8 * chars, int n)
25836 -{
25837 - char tmp[256];
25838 - tmp[0] = 0;
25839 - return strncat(tmp, (char *)chars, n);
25840 -}
25841 -
25842 static int i2o_report_query_status(struct seq_file *seq, int block_status,
25843 char *group)
25844 {
25845 @@ -838,8 +831,7 @@ static int i2o_seq_show_ddm_table(struct
25846
25847 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
25848 seq_printf(seq, "%-#8x", ddm_table.module_id);
25849 - seq_printf(seq, "%-29s",
25850 - chtostr(ddm_table.module_name_version, 28));
25851 + seq_printf(seq, "%-.28s", ddm_table.module_name_version);
25852 seq_printf(seq, "%9d ", ddm_table.data_size);
25853 seq_printf(seq, "%8d", ddm_table.code_size);
25854
25855 @@ -940,8 +932,8 @@ static int i2o_seq_show_drivers_stored(s
25856
25857 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
25858 seq_printf(seq, "%-#8x", dst->module_id);
25859 - seq_printf(seq, "%-29s", chtostr(dst->module_name_version, 28));
25860 - seq_printf(seq, "%-9s", chtostr(dst->date, 8));
25861 + seq_printf(seq, "%-.28s", dst->module_name_version);
25862 + seq_printf(seq, "%-.8s", dst->date);
25863 seq_printf(seq, "%8d ", dst->module_size);
25864 seq_printf(seq, "%8d ", dst->mpb_size);
25865 seq_printf(seq, "0x%04x", dst->module_flags);
25866 @@ -1272,14 +1264,10 @@ static int i2o_seq_show_dev_identity(str
25867 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
25868 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
25869 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
25870 - seq_printf(seq, "Vendor info : %s\n",
25871 - chtostr((u8 *) (work32 + 2), 16));
25872 - seq_printf(seq, "Product info : %s\n",
25873 - chtostr((u8 *) (work32 + 6), 16));
25874 - seq_printf(seq, "Description : %s\n",
25875 - chtostr((u8 *) (work32 + 10), 16));
25876 - seq_printf(seq, "Product rev. : %s\n",
25877 - chtostr((u8 *) (work32 + 14), 8));
25878 + seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
25879 + seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
25880 + seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
25881 + seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
25882
25883 seq_printf(seq, "Serial number : ");
25884 print_serial_number(seq, (u8 *) (work32 + 16),
25885 @@ -1324,10 +1312,8 @@ static int i2o_seq_show_ddm_identity(str
25886 }
25887
25888 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
25889 - seq_printf(seq, "Module name : %s\n",
25890 - chtostr(result.module_name, 24));
25891 - seq_printf(seq, "Module revision : %s\n",
25892 - chtostr(result.module_rev, 8));
25893 + seq_printf(seq, "Module name : %.24s\n", result.module_name);
25894 + seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
25895
25896 seq_printf(seq, "Serial number : ");
25897 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
25898 @@ -1358,14 +1344,10 @@ static int i2o_seq_show_uinfo(struct seq
25899 return 0;
25900 }
25901
25902 - seq_printf(seq, "Device name : %s\n",
25903 - chtostr(result.device_name, 64));
25904 - seq_printf(seq, "Service name : %s\n",
25905 - chtostr(result.service_name, 64));
25906 - seq_printf(seq, "Physical name : %s\n",
25907 - chtostr(result.physical_location, 64));
25908 - seq_printf(seq, "Instance number : %s\n",
25909 - chtostr(result.instance_number, 4));
25910 + seq_printf(seq, "Device name : %.64s\n", result.device_name);
25911 + seq_printf(seq, "Service name : %.64s\n", result.service_name);
25912 + seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
25913 + seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
25914
25915 return 0;
25916 }
25917 diff -urNp linux-2.6.37/drivers/mfd/janz-cmodio.c linux-2.6.37/drivers/mfd/janz-cmodio.c
25918 --- linux-2.6.37/drivers/mfd/janz-cmodio.c 2011-01-04 19:50:19.000000000 -0500
25919 +++ linux-2.6.37/drivers/mfd/janz-cmodio.c 2011-01-17 02:41:01.000000000 -0500
25920 @@ -13,6 +13,7 @@
25921
25922 #include <linux/kernel.h>
25923 #include <linux/module.h>
25924 +#include <linux/slab.h>
25925 #include <linux/init.h>
25926 #include <linux/pci.h>
25927 #include <linux/interrupt.h>
25928 diff -urNp linux-2.6.37/drivers/misc/kgdbts.c linux-2.6.37/drivers/misc/kgdbts.c
25929 --- linux-2.6.37/drivers/misc/kgdbts.c 2011-01-04 19:50:19.000000000 -0500
25930 +++ linux-2.6.37/drivers/misc/kgdbts.c 2011-01-17 02:41:01.000000000 -0500
25931 @@ -118,7 +118,7 @@
25932 } while (0)
25933 #define MAX_CONFIG_LEN 40
25934
25935 -static struct kgdb_io kgdbts_io_ops;
25936 +static const struct kgdb_io kgdbts_io_ops;
25937 static char get_buf[BUFMAX];
25938 static int get_buf_cnt;
25939 static char put_buf[BUFMAX];
25940 @@ -1103,7 +1103,7 @@ static void kgdbts_post_exp_handler(void
25941 module_put(THIS_MODULE);
25942 }
25943
25944 -static struct kgdb_io kgdbts_io_ops = {
25945 +static const struct kgdb_io kgdbts_io_ops = {
25946 .name = "kgdbts",
25947 .read_char = kgdbts_get_char,
25948 .write_char = kgdbts_put_char,
25949 diff -urNp linux-2.6.37/drivers/misc/sgi-gru/gruhandles.c linux-2.6.37/drivers/misc/sgi-gru/gruhandles.c
25950 --- linux-2.6.37/drivers/misc/sgi-gru/gruhandles.c 2011-01-04 19:50:19.000000000 -0500
25951 +++ linux-2.6.37/drivers/misc/sgi-gru/gruhandles.c 2011-01-17 02:41:01.000000000 -0500
25952 @@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op
25953 unsigned long nsec;
25954
25955 nsec = CLKS2NSEC(clks);
25956 - atomic_long_inc(&mcs_op_statistics[op].count);
25957 - atomic_long_add(nsec, &mcs_op_statistics[op].total);
25958 + atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
25959 + atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
25960 if (mcs_op_statistics[op].max < nsec)
25961 mcs_op_statistics[op].max = nsec;
25962 }
25963 diff -urNp linux-2.6.37/drivers/misc/sgi-gru/gruprocfs.c linux-2.6.37/drivers/misc/sgi-gru/gruprocfs.c
25964 --- linux-2.6.37/drivers/misc/sgi-gru/gruprocfs.c 2011-01-04 19:50:19.000000000 -0500
25965 +++ linux-2.6.37/drivers/misc/sgi-gru/gruprocfs.c 2011-01-17 02:41:01.000000000 -0500
25966 @@ -32,9 +32,9 @@
25967
25968 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
25969
25970 -static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
25971 +static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
25972 {
25973 - unsigned long val = atomic_long_read(v);
25974 + unsigned long val = atomic_long_read_unchecked(v);
25975
25976 seq_printf(s, "%16lu %s\n", val, id);
25977 }
25978 @@ -134,8 +134,8 @@ static int mcs_statistics_show(struct se
25979
25980 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
25981 for (op = 0; op < mcsop_last; op++) {
25982 - count = atomic_long_read(&mcs_op_statistics[op].count);
25983 - total = atomic_long_read(&mcs_op_statistics[op].total);
25984 + count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
25985 + total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
25986 max = mcs_op_statistics[op].max;
25987 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
25988 count ? total / count : 0, max);
25989 diff -urNp linux-2.6.37/drivers/misc/sgi-gru/grutables.h linux-2.6.37/drivers/misc/sgi-gru/grutables.h
25990 --- linux-2.6.37/drivers/misc/sgi-gru/grutables.h 2011-01-04 19:50:19.000000000 -0500
25991 +++ linux-2.6.37/drivers/misc/sgi-gru/grutables.h 2011-01-17 02:41:01.000000000 -0500
25992 @@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
25993 * GRU statistics.
25994 */
25995 struct gru_stats_s {
25996 - atomic_long_t vdata_alloc;
25997 - atomic_long_t vdata_free;
25998 - atomic_long_t gts_alloc;
25999 - atomic_long_t gts_free;
26000 - atomic_long_t gms_alloc;
26001 - atomic_long_t gms_free;
26002 - atomic_long_t gts_double_allocate;
26003 - atomic_long_t assign_context;
26004 - atomic_long_t assign_context_failed;
26005 - atomic_long_t free_context;
26006 - atomic_long_t load_user_context;
26007 - atomic_long_t load_kernel_context;
26008 - atomic_long_t lock_kernel_context;
26009 - atomic_long_t unlock_kernel_context;
26010 - atomic_long_t steal_user_context;
26011 - atomic_long_t steal_kernel_context;
26012 - atomic_long_t steal_context_failed;
26013 - atomic_long_t nopfn;
26014 - atomic_long_t asid_new;
26015 - atomic_long_t asid_next;
26016 - atomic_long_t asid_wrap;
26017 - atomic_long_t asid_reuse;
26018 - atomic_long_t intr;
26019 - atomic_long_t intr_cbr;
26020 - atomic_long_t intr_tfh;
26021 - atomic_long_t intr_spurious;
26022 - atomic_long_t intr_mm_lock_failed;
26023 - atomic_long_t call_os;
26024 - atomic_long_t call_os_wait_queue;
26025 - atomic_long_t user_flush_tlb;
26026 - atomic_long_t user_unload_context;
26027 - atomic_long_t user_exception;
26028 - atomic_long_t set_context_option;
26029 - atomic_long_t check_context_retarget_intr;
26030 - atomic_long_t check_context_unload;
26031 - atomic_long_t tlb_dropin;
26032 - atomic_long_t tlb_preload_page;
26033 - atomic_long_t tlb_dropin_fail_no_asid;
26034 - atomic_long_t tlb_dropin_fail_upm;
26035 - atomic_long_t tlb_dropin_fail_invalid;
26036 - atomic_long_t tlb_dropin_fail_range_active;
26037 - atomic_long_t tlb_dropin_fail_idle;
26038 - atomic_long_t tlb_dropin_fail_fmm;
26039 - atomic_long_t tlb_dropin_fail_no_exception;
26040 - atomic_long_t tfh_stale_on_fault;
26041 - atomic_long_t mmu_invalidate_range;
26042 - atomic_long_t mmu_invalidate_page;
26043 - atomic_long_t flush_tlb;
26044 - atomic_long_t flush_tlb_gru;
26045 - atomic_long_t flush_tlb_gru_tgh;
26046 - atomic_long_t flush_tlb_gru_zero_asid;
26047 -
26048 - atomic_long_t copy_gpa;
26049 - atomic_long_t read_gpa;
26050 -
26051 - atomic_long_t mesq_receive;
26052 - atomic_long_t mesq_receive_none;
26053 - atomic_long_t mesq_send;
26054 - atomic_long_t mesq_send_failed;
26055 - atomic_long_t mesq_noop;
26056 - atomic_long_t mesq_send_unexpected_error;
26057 - atomic_long_t mesq_send_lb_overflow;
26058 - atomic_long_t mesq_send_qlimit_reached;
26059 - atomic_long_t mesq_send_amo_nacked;
26060 - atomic_long_t mesq_send_put_nacked;
26061 - atomic_long_t mesq_page_overflow;
26062 - atomic_long_t mesq_qf_locked;
26063 - atomic_long_t mesq_qf_noop_not_full;
26064 - atomic_long_t mesq_qf_switch_head_failed;
26065 - atomic_long_t mesq_qf_unexpected_error;
26066 - atomic_long_t mesq_noop_unexpected_error;
26067 - atomic_long_t mesq_noop_lb_overflow;
26068 - atomic_long_t mesq_noop_qlimit_reached;
26069 - atomic_long_t mesq_noop_amo_nacked;
26070 - atomic_long_t mesq_noop_put_nacked;
26071 - atomic_long_t mesq_noop_page_overflow;
26072 + atomic_long_unchecked_t vdata_alloc;
26073 + atomic_long_unchecked_t vdata_free;
26074 + atomic_long_unchecked_t gts_alloc;
26075 + atomic_long_unchecked_t gts_free;
26076 + atomic_long_unchecked_t gms_alloc;
26077 + atomic_long_unchecked_t gms_free;
26078 + atomic_long_unchecked_t gts_double_allocate;
26079 + atomic_long_unchecked_t assign_context;
26080 + atomic_long_unchecked_t assign_context_failed;
26081 + atomic_long_unchecked_t free_context;
26082 + atomic_long_unchecked_t load_user_context;
26083 + atomic_long_unchecked_t load_kernel_context;
26084 + atomic_long_unchecked_t lock_kernel_context;
26085 + atomic_long_unchecked_t unlock_kernel_context;
26086 + atomic_long_unchecked_t steal_user_context;
26087 + atomic_long_unchecked_t steal_kernel_context;
26088 + atomic_long_unchecked_t steal_context_failed;
26089 + atomic_long_unchecked_t nopfn;
26090 + atomic_long_unchecked_t asid_new;
26091 + atomic_long_unchecked_t asid_next;
26092 + atomic_long_unchecked_t asid_wrap;
26093 + atomic_long_unchecked_t asid_reuse;
26094 + atomic_long_unchecked_t intr;
26095 + atomic_long_unchecked_t intr_cbr;
26096 + atomic_long_unchecked_t intr_tfh;
26097 + atomic_long_unchecked_t intr_spurious;
26098 + atomic_long_unchecked_t intr_mm_lock_failed;
26099 + atomic_long_unchecked_t call_os;
26100 + atomic_long_unchecked_t call_os_wait_queue;
26101 + atomic_long_unchecked_t user_flush_tlb;
26102 + atomic_long_unchecked_t user_unload_context;
26103 + atomic_long_unchecked_t user_exception;
26104 + atomic_long_unchecked_t set_context_option;
26105 + atomic_long_unchecked_t check_context_retarget_intr;
26106 + atomic_long_unchecked_t check_context_unload;
26107 + atomic_long_unchecked_t tlb_dropin;
26108 + atomic_long_unchecked_t tlb_preload_page;
26109 + atomic_long_unchecked_t tlb_dropin_fail_no_asid;
26110 + atomic_long_unchecked_t tlb_dropin_fail_upm;
26111 + atomic_long_unchecked_t tlb_dropin_fail_invalid;
26112 + atomic_long_unchecked_t tlb_dropin_fail_range_active;
26113 + atomic_long_unchecked_t tlb_dropin_fail_idle;
26114 + atomic_long_unchecked_t tlb_dropin_fail_fmm;
26115 + atomic_long_unchecked_t tlb_dropin_fail_no_exception;
26116 + atomic_long_unchecked_t tfh_stale_on_fault;
26117 + atomic_long_unchecked_t mmu_invalidate_range;
26118 + atomic_long_unchecked_t mmu_invalidate_page;
26119 + atomic_long_unchecked_t flush_tlb;
26120 + atomic_long_unchecked_t flush_tlb_gru;
26121 + atomic_long_unchecked_t flush_tlb_gru_tgh;
26122 + atomic_long_unchecked_t flush_tlb_gru_zero_asid;
26123 +
26124 + atomic_long_unchecked_t copy_gpa;
26125 + atomic_long_unchecked_t read_gpa;
26126 +
26127 + atomic_long_unchecked_t mesq_receive;
26128 + atomic_long_unchecked_t mesq_receive_none;
26129 + atomic_long_unchecked_t mesq_send;
26130 + atomic_long_unchecked_t mesq_send_failed;
26131 + atomic_long_unchecked_t mesq_noop;
26132 + atomic_long_unchecked_t mesq_send_unexpected_error;
26133 + atomic_long_unchecked_t mesq_send_lb_overflow;
26134 + atomic_long_unchecked_t mesq_send_qlimit_reached;
26135 + atomic_long_unchecked_t mesq_send_amo_nacked;
26136 + atomic_long_unchecked_t mesq_send_put_nacked;
26137 + atomic_long_unchecked_t mesq_page_overflow;
26138 + atomic_long_unchecked_t mesq_qf_locked;
26139 + atomic_long_unchecked_t mesq_qf_noop_not_full;
26140 + atomic_long_unchecked_t mesq_qf_switch_head_failed;
26141 + atomic_long_unchecked_t mesq_qf_unexpected_error;
26142 + atomic_long_unchecked_t mesq_noop_unexpected_error;
26143 + atomic_long_unchecked_t mesq_noop_lb_overflow;
26144 + atomic_long_unchecked_t mesq_noop_qlimit_reached;
26145 + atomic_long_unchecked_t mesq_noop_amo_nacked;
26146 + atomic_long_unchecked_t mesq_noop_put_nacked;
26147 + atomic_long_unchecked_t mesq_noop_page_overflow;
26148
26149 };
26150
26151 @@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start
26152 tghop_invalidate, mcsop_last};
26153
26154 struct mcs_op_statistic {
26155 - atomic_long_t count;
26156 - atomic_long_t total;
26157 + atomic_long_unchecked_t count;
26158 + atomic_long_unchecked_t total;
26159 unsigned long max;
26160 };
26161
26162 @@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_st
26163
26164 #define STAT(id) do { \
26165 if (gru_options & OPT_STATS) \
26166 - atomic_long_inc(&gru_stats.id); \
26167 + atomic_long_inc_unchecked(&gru_stats.id); \
26168 } while (0)
26169
26170 #ifdef CONFIG_SGI_GRU_DEBUG
26171 diff -urNp linux-2.6.37/drivers/mtd/devices/doc2000.c linux-2.6.37/drivers/mtd/devices/doc2000.c
26172 --- linux-2.6.37/drivers/mtd/devices/doc2000.c 2011-01-04 19:50:19.000000000 -0500
26173 +++ linux-2.6.37/drivers/mtd/devices/doc2000.c 2011-01-17 02:41:01.000000000 -0500
26174 @@ -776,7 +776,7 @@ static int doc_write(struct mtd_info *mt
26175
26176 /* The ECC will not be calculated correctly if less than 512 is written */
26177 /* DBB-
26178 - if (len != 0x200 && eccbuf)
26179 + if (len != 0x200)
26180 printk(KERN_WARNING
26181 "ECC needs a full sector write (adr: %lx size %lx)\n",
26182 (long) to, (long) len);
26183 diff -urNp linux-2.6.37/drivers/mtd/devices/doc2001.c linux-2.6.37/drivers/mtd/devices/doc2001.c
26184 --- linux-2.6.37/drivers/mtd/devices/doc2001.c 2011-01-04 19:50:19.000000000 -0500
26185 +++ linux-2.6.37/drivers/mtd/devices/doc2001.c 2011-01-17 02:41:01.000000000 -0500
26186 @@ -393,7 +393,7 @@ static int doc_read (struct mtd_info *mt
26187 struct Nand *mychip = &this->chips[from >> (this->chipshift)];
26188
26189 /* Don't allow read past end of device */
26190 - if (from >= this->totlen)
26191 + if (from >= this->totlen || !len)
26192 return -EINVAL;
26193
26194 /* Don't allow a single read to cross a 512-byte block boundary */
26195 diff -urNp linux-2.6.37/drivers/mtd/nand/denali.c linux-2.6.37/drivers/mtd/nand/denali.c
26196 --- linux-2.6.37/drivers/mtd/nand/denali.c 2011-01-04 19:50:19.000000000 -0500
26197 +++ linux-2.6.37/drivers/mtd/nand/denali.c 2011-01-17 02:41:01.000000000 -0500
26198 @@ -25,6 +25,7 @@
26199 #include <linux/pci.h>
26200 #include <linux/mtd/mtd.h>
26201 #include <linux/module.h>
26202 +#include <linux/slab.h>
26203
26204 #include "denali.h"
26205
26206 diff -urNp linux-2.6.37/drivers/mtd/ubi/build.c linux-2.6.37/drivers/mtd/ubi/build.c
26207 --- linux-2.6.37/drivers/mtd/ubi/build.c 2011-01-04 19:50:19.000000000 -0500
26208 +++ linux-2.6.37/drivers/mtd/ubi/build.c 2011-01-17 02:41:01.000000000 -0500
26209 @@ -1285,7 +1285,7 @@ module_exit(ubi_exit);
26210 static int __init bytes_str_to_int(const char *str)
26211 {
26212 char *endp;
26213 - unsigned long result;
26214 + unsigned long result, scale = 1;
26215
26216 result = simple_strtoul(str, &endp, 0);
26217 if (str == endp || result >= INT_MAX) {
26218 @@ -1296,11 +1296,11 @@ static int __init bytes_str_to_int(const
26219
26220 switch (*endp) {
26221 case 'G':
26222 - result *= 1024;
26223 + scale *= 1024;
26224 case 'M':
26225 - result *= 1024;
26226 + scale *= 1024;
26227 case 'K':
26228 - result *= 1024;
26229 + scale *= 1024;
26230 if (endp[1] == 'i' && endp[2] == 'B')
26231 endp += 2;
26232 case '\0':
26233 @@ -1311,7 +1311,13 @@ static int __init bytes_str_to_int(const
26234 return -EINVAL;
26235 }
26236
26237 - return result;
26238 + if ((intoverflow_t)result*scale >= INT_MAX) {
26239 + printk(KERN_ERR "UBI error: incorrect bytes count: \"%s\"\n",
26240 + str);
26241 + return -EINVAL;
26242 + }
26243 +
26244 + return result*scale;
26245 }
26246
26247 /**
26248 diff -urNp linux-2.6.37/drivers/net/e1000e/82571.c linux-2.6.37/drivers/net/e1000e/82571.c
26249 --- linux-2.6.37/drivers/net/e1000e/82571.c 2011-01-04 19:50:19.000000000 -0500
26250 +++ linux-2.6.37/drivers/net/e1000e/82571.c 2011-01-17 02:41:01.000000000 -0500
26251 @@ -211,6 +211,7 @@ static s32 e1000_init_mac_params_82571(s
26252 {
26253 struct e1000_hw *hw = &adapter->hw;
26254 struct e1000_mac_info *mac = &hw->mac;
26255 + /* cannot be const */
26256 struct e1000_mac_operations *func = &mac->ops;
26257 u32 swsm = 0;
26258 u32 swsm2 = 0;
26259 @@ -1740,7 +1741,7 @@ static void e1000_clear_hw_cntrs_82571(s
26260 er32(ICRXDMTC);
26261 }
26262
26263 -static struct e1000_mac_operations e82571_mac_ops = {
26264 +static const struct e1000_mac_operations e82571_mac_ops = {
26265 /* .check_mng_mode: mac type dependent */
26266 /* .check_for_link: media type dependent */
26267 .id_led_init = e1000e_id_led_init,
26268 @@ -1762,7 +1763,7 @@ static struct e1000_mac_operations e8257
26269 .read_mac_addr = e1000_read_mac_addr_82571,
26270 };
26271
26272 -static struct e1000_phy_operations e82_phy_ops_igp = {
26273 +static const struct e1000_phy_operations e82_phy_ops_igp = {
26274 .acquire = e1000_get_hw_semaphore_82571,
26275 .check_polarity = e1000_check_polarity_igp,
26276 .check_reset_block = e1000e_check_reset_block_generic,
26277 @@ -1780,7 +1781,7 @@ static struct e1000_phy_operations e82_p
26278 .cfg_on_link_up = NULL,
26279 };
26280
26281 -static struct e1000_phy_operations e82_phy_ops_m88 = {
26282 +static const struct e1000_phy_operations e82_phy_ops_m88 = {
26283 .acquire = e1000_get_hw_semaphore_82571,
26284 .check_polarity = e1000_check_polarity_m88,
26285 .check_reset_block = e1000e_check_reset_block_generic,
26286 @@ -1798,7 +1799,7 @@ static struct e1000_phy_operations e82_p
26287 .cfg_on_link_up = NULL,
26288 };
26289
26290 -static struct e1000_phy_operations e82_phy_ops_bm = {
26291 +static const struct e1000_phy_operations e82_phy_ops_bm = {
26292 .acquire = e1000_get_hw_semaphore_82571,
26293 .check_polarity = e1000_check_polarity_m88,
26294 .check_reset_block = e1000e_check_reset_block_generic,
26295 @@ -1816,7 +1817,7 @@ static struct e1000_phy_operations e82_p
26296 .cfg_on_link_up = NULL,
26297 };
26298
26299 -static struct e1000_nvm_operations e82571_nvm_ops = {
26300 +static const struct e1000_nvm_operations e82571_nvm_ops = {
26301 .acquire = e1000_acquire_nvm_82571,
26302 .read = e1000e_read_nvm_eerd,
26303 .release = e1000_release_nvm_82571,
26304 diff -urNp linux-2.6.37/drivers/net/e1000e/e1000.h linux-2.6.37/drivers/net/e1000e/e1000.h
26305 --- linux-2.6.37/drivers/net/e1000e/e1000.h 2011-01-04 19:50:19.000000000 -0500
26306 +++ linux-2.6.37/drivers/net/e1000e/e1000.h 2011-01-17 02:41:01.000000000 -0500
26307 @@ -407,9 +407,9 @@ struct e1000_info {
26308 u32 pba;
26309 u32 max_hw_frame_size;
26310 s32 (*get_variants)(struct e1000_adapter *);
26311 - struct e1000_mac_operations *mac_ops;
26312 - struct e1000_phy_operations *phy_ops;
26313 - struct e1000_nvm_operations *nvm_ops;
26314 + const struct e1000_mac_operations *mac_ops;
26315 + const struct e1000_phy_operations *phy_ops;
26316 + const struct e1000_nvm_operations *nvm_ops;
26317 };
26318
26319 /* hardware capability, feature, and workaround flags */
26320 diff -urNp linux-2.6.37/drivers/net/e1000e/es2lan.c linux-2.6.37/drivers/net/e1000e/es2lan.c
26321 --- linux-2.6.37/drivers/net/e1000e/es2lan.c 2011-01-04 19:50:19.000000000 -0500
26322 +++ linux-2.6.37/drivers/net/e1000e/es2lan.c 2011-01-17 02:41:01.000000000 -0500
26323 @@ -205,6 +205,7 @@ static s32 e1000_init_mac_params_80003es
26324 {
26325 struct e1000_hw *hw = &adapter->hw;
26326 struct e1000_mac_info *mac = &hw->mac;
26327 + /* cannot be const */
26328 struct e1000_mac_operations *func = &mac->ops;
26329
26330 /* Set media type */
26331 @@ -1431,7 +1432,7 @@ static void e1000_clear_hw_cntrs_80003es
26332 er32(ICRXDMTC);
26333 }
26334
26335 -static struct e1000_mac_operations es2_mac_ops = {
26336 +static const struct e1000_mac_operations es2_mac_ops = {
26337 .read_mac_addr = e1000_read_mac_addr_80003es2lan,
26338 .id_led_init = e1000e_id_led_init,
26339 .check_mng_mode = e1000e_check_mng_mode_generic,
26340 @@ -1453,7 +1454,7 @@ static struct e1000_mac_operations es2_m
26341 .setup_led = e1000e_setup_led_generic,
26342 };
26343
26344 -static struct e1000_phy_operations es2_phy_ops = {
26345 +static const struct e1000_phy_operations es2_phy_ops = {
26346 .acquire = e1000_acquire_phy_80003es2lan,
26347 .check_polarity = e1000_check_polarity_m88,
26348 .check_reset_block = e1000e_check_reset_block_generic,
26349 @@ -1471,7 +1472,7 @@ static struct e1000_phy_operations es2_p
26350 .cfg_on_link_up = e1000_cfg_on_link_up_80003es2lan,
26351 };
26352
26353 -static struct e1000_nvm_operations es2_nvm_ops = {
26354 +static const struct e1000_nvm_operations es2_nvm_ops = {
26355 .acquire = e1000_acquire_nvm_80003es2lan,
26356 .read = e1000e_read_nvm_eerd,
26357 .release = e1000_release_nvm_80003es2lan,
26358 diff -urNp linux-2.6.37/drivers/net/e1000e/hw.h linux-2.6.37/drivers/net/e1000e/hw.h
26359 --- linux-2.6.37/drivers/net/e1000e/hw.h 2011-01-04 19:50:19.000000000 -0500
26360 +++ linux-2.6.37/drivers/net/e1000e/hw.h 2011-01-17 02:41:01.000000000 -0500
26361 @@ -800,16 +800,17 @@ struct e1000_phy_operations {
26362
26363 /* Function pointers for the NVM. */
26364 struct e1000_nvm_operations {
26365 - s32 (*acquire)(struct e1000_hw *);
26366 - s32 (*read)(struct e1000_hw *, u16, u16, u16 *);
26367 - void (*release)(struct e1000_hw *);
26368 - s32 (*update)(struct e1000_hw *);
26369 - s32 (*valid_led_default)(struct e1000_hw *, u16 *);
26370 - s32 (*validate)(struct e1000_hw *);
26371 - s32 (*write)(struct e1000_hw *, u16, u16, u16 *);
26372 + s32 (* const acquire)(struct e1000_hw *);
26373 + s32 (* const read)(struct e1000_hw *, u16, u16, u16 *);
26374 + void (* const release)(struct e1000_hw *);
26375 + s32 (* const update)(struct e1000_hw *);
26376 + s32 (* const valid_led_default)(struct e1000_hw *, u16 *);
26377 + s32 (* const validate)(struct e1000_hw *);
26378 + s32 (* const write)(struct e1000_hw *, u16, u16, u16 *);
26379 };
26380
26381 struct e1000_mac_info {
26382 + /* cannot be const see e1000_init_mac_params_ich8lan */
26383 struct e1000_mac_operations ops;
26384
26385 u8 addr[6];
26386 @@ -852,6 +853,7 @@ struct e1000_mac_info {
26387 };
26388
26389 struct e1000_phy_info {
26390 + /* Cannot be const see e1000_init_phy_params_82571() */
26391 struct e1000_phy_operations ops;
26392
26393 enum e1000_phy_type type;
26394 @@ -886,6 +888,7 @@ struct e1000_phy_info {
26395 };
26396
26397 struct e1000_nvm_info {
26398 + /* cannot be const */
26399 struct e1000_nvm_operations ops;
26400
26401 enum e1000_nvm_type type;
26402 diff -urNp linux-2.6.37/drivers/net/e1000e/ich8lan.c linux-2.6.37/drivers/net/e1000e/ich8lan.c
26403 --- linux-2.6.37/drivers/net/e1000e/ich8lan.c 2011-01-04 19:50:19.000000000 -0500
26404 +++ linux-2.6.37/drivers/net/e1000e/ich8lan.c 2011-01-17 02:41:01.000000000 -0500
26405 @@ -3856,7 +3856,7 @@ static void e1000_clear_hw_cntrs_ich8lan
26406 }
26407 }
26408
26409 -static struct e1000_mac_operations ich8_mac_ops = {
26410 +static const struct e1000_mac_operations ich8_mac_ops = {
26411 .id_led_init = e1000e_id_led_init,
26412 /* check_mng_mode dependent on mac type */
26413 .check_for_link = e1000_check_for_copper_link_ich8lan,
26414 @@ -3875,7 +3875,7 @@ static struct e1000_mac_operations ich8_
26415 /* id_led_init dependent on mac type */
26416 };
26417
26418 -static struct e1000_phy_operations ich8_phy_ops = {
26419 +static const struct e1000_phy_operations ich8_phy_ops = {
26420 .acquire = e1000_acquire_swflag_ich8lan,
26421 .check_reset_block = e1000_check_reset_block_ich8lan,
26422 .commit = NULL,
26423 @@ -3889,7 +3889,7 @@ static struct e1000_phy_operations ich8_
26424 .write_reg = e1000e_write_phy_reg_igp,
26425 };
26426
26427 -static struct e1000_nvm_operations ich8_nvm_ops = {
26428 +static const struct e1000_nvm_operations ich8_nvm_ops = {
26429 .acquire = e1000_acquire_nvm_ich8lan,
26430 .read = e1000_read_nvm_ich8lan,
26431 .release = e1000_release_nvm_ich8lan,
26432 diff -urNp linux-2.6.37/drivers/net/igb/e1000_82575.c linux-2.6.37/drivers/net/igb/e1000_82575.c
26433 --- linux-2.6.37/drivers/net/igb/e1000_82575.c 2011-01-04 19:50:19.000000000 -0500
26434 +++ linux-2.6.37/drivers/net/igb/e1000_82575.c 2011-01-17 02:41:01.000000000 -0500
26435 @@ -1712,7 +1712,7 @@ u16 igb_rxpbs_adjust_82580(u32 data)
26436 return ret_val;
26437 }
26438
26439 -static struct e1000_mac_operations e1000_mac_ops_82575 = {
26440 +static const struct e1000_mac_operations e1000_mac_ops_82575 = {
26441 .init_hw = igb_init_hw_82575,
26442 .check_for_link = igb_check_for_link_82575,
26443 .rar_set = igb_rar_set,
26444 @@ -1720,13 +1720,13 @@ static struct e1000_mac_operations e1000
26445 .get_speed_and_duplex = igb_get_speed_and_duplex_copper,
26446 };
26447
26448 -static struct e1000_phy_operations e1000_phy_ops_82575 = {
26449 +static const struct e1000_phy_operations e1000_phy_ops_82575 = {
26450 .acquire = igb_acquire_phy_82575,
26451 .get_cfg_done = igb_get_cfg_done_82575,
26452 .release = igb_release_phy_82575,
26453 };
26454
26455 -static struct e1000_nvm_operations e1000_nvm_ops_82575 = {
26456 +static const struct e1000_nvm_operations e1000_nvm_ops_82575 = {
26457 .acquire = igb_acquire_nvm_82575,
26458 .read = igb_read_nvm_eerd,
26459 .release = igb_release_nvm_82575,
26460 diff -urNp linux-2.6.37/drivers/net/igb/e1000_hw.h linux-2.6.37/drivers/net/igb/e1000_hw.h
26461 --- linux-2.6.37/drivers/net/igb/e1000_hw.h 2011-01-04 19:50:19.000000000 -0500
26462 +++ linux-2.6.37/drivers/net/igb/e1000_hw.h 2011-01-17 02:41:01.000000000 -0500
26463 @@ -325,22 +325,23 @@ struct e1000_phy_operations {
26464 };
26465
26466 struct e1000_nvm_operations {
26467 - s32 (*acquire)(struct e1000_hw *);
26468 - s32 (*read)(struct e1000_hw *, u16, u16, u16 *);
26469 - void (*release)(struct e1000_hw *);
26470 - s32 (*write)(struct e1000_hw *, u16, u16, u16 *);
26471 + s32 (* const acquire)(struct e1000_hw *);
26472 + s32 (* const read)(struct e1000_hw *, u16, u16, u16 *);
26473 + void (* const release)(struct e1000_hw *);
26474 + s32 (* const write)(struct e1000_hw *, u16, u16, u16 *);
26475 };
26476
26477 struct e1000_info {
26478 s32 (*get_invariants)(struct e1000_hw *);
26479 - struct e1000_mac_operations *mac_ops;
26480 - struct e1000_phy_operations *phy_ops;
26481 - struct e1000_nvm_operations *nvm_ops;
26482 + const struct e1000_mac_operations *mac_ops;
26483 + const struct e1000_phy_operations *phy_ops;
26484 + const struct e1000_nvm_operations *nvm_ops;
26485 };
26486
26487 extern const struct e1000_info e1000_82575_info;
26488
26489 struct e1000_mac_info {
26490 + /* cannot be const see igb_get_invariants_82575() */
26491 struct e1000_mac_operations ops;
26492
26493 u8 addr[6];
26494 @@ -379,6 +380,7 @@ struct e1000_mac_info {
26495 };
26496
26497 struct e1000_phy_info {
26498 + /* cannot be const see igb_get_invariants_82575() */
26499 struct e1000_phy_operations ops;
26500
26501 enum e1000_phy_type type;
26502 @@ -414,6 +416,7 @@ struct e1000_phy_info {
26503 };
26504
26505 struct e1000_nvm_info {
26506 + /* cannot be const */
26507 struct e1000_nvm_operations ops;
26508
26509 enum e1000_nvm_type type;
26510 diff -urNp linux-2.6.37/drivers/net/igbvf/vf.h linux-2.6.37/drivers/net/igbvf/vf.h
26511 --- linux-2.6.37/drivers/net/igbvf/vf.h 2011-01-04 19:50:19.000000000 -0500
26512 +++ linux-2.6.37/drivers/net/igbvf/vf.h 2011-01-17 02:41:01.000000000 -0500
26513 @@ -189,6 +189,7 @@ struct e1000_mac_operations {
26514 };
26515
26516 struct e1000_mac_info {
26517 + /* cannot be const see e1000_init_mac_params_vf() */
26518 struct e1000_mac_operations ops;
26519 u8 addr[6];
26520 u8 perm_addr[6];
26521 diff -urNp linux-2.6.37/drivers/net/irda/vlsi_ir.c linux-2.6.37/drivers/net/irda/vlsi_ir.c
26522 --- linux-2.6.37/drivers/net/irda/vlsi_ir.c 2011-01-04 19:50:19.000000000 -0500
26523 +++ linux-2.6.37/drivers/net/irda/vlsi_ir.c 2011-01-17 02:41:01.000000000 -0500
26524 @@ -907,13 +907,12 @@ static netdev_tx_t vlsi_hard_start_xmit(
26525 /* no race - tx-ring already empty */
26526 vlsi_set_baud(idev, iobase);
26527 netif_wake_queue(ndev);
26528 - }
26529 - else
26530 - ;
26531 + } else {
26532 /* keep the speed change pending like it would
26533 * for any len>0 packet. tx completion interrupt
26534 * will apply it when the tx ring becomes empty.
26535 */
26536 + }
26537 spin_unlock_irqrestore(&idev->lock, flags);
26538 dev_kfree_skb_any(skb);
26539 return NETDEV_TX_OK;
26540 diff -urNp linux-2.6.37/drivers/net/macvtap.c linux-2.6.37/drivers/net/macvtap.c
26541 --- linux-2.6.37/drivers/net/macvtap.c 2011-01-04 19:50:19.000000000 -0500
26542 +++ linux-2.6.37/drivers/net/macvtap.c 2011-01-17 02:41:01.000000000 -0500
26543 @@ -529,8 +529,9 @@ static ssize_t macvtap_get_user(struct m
26544 vnet_hdr_len = q->vnet_hdr_sz;
26545
26546 err = -EINVAL;
26547 - if ((len -= vnet_hdr_len) < 0)
26548 + if (len < vnet_hdr_len)
26549 goto err;
26550 + len -= vnet_hdr_len;
26551
26552 err = memcpy_fromiovecend((void *)&vnet_hdr, iv, 0,
26553 sizeof(vnet_hdr));
26554 diff -urNp linux-2.6.37/drivers/net/pcnet32.c linux-2.6.37/drivers/net/pcnet32.c
26555 --- linux-2.6.37/drivers/net/pcnet32.c 2011-01-04 19:50:19.000000000 -0500
26556 +++ linux-2.6.37/drivers/net/pcnet32.c 2011-01-17 02:41:01.000000000 -0500
26557 @@ -82,7 +82,7 @@ static int cards_found;
26558 /*
26559 * VLB I/O addresses
26560 */
26561 -static unsigned int pcnet32_portlist[] __initdata =
26562 +static unsigned int pcnet32_portlist[] __devinitdata =
26563 { 0x300, 0x320, 0x340, 0x360, 0 };
26564
26565 static int pcnet32_debug;
26566 diff -urNp linux-2.6.37/drivers/net/ppp_generic.c linux-2.6.37/drivers/net/ppp_generic.c
26567 --- linux-2.6.37/drivers/net/ppp_generic.c 2011-01-04 19:50:19.000000000 -0500
26568 +++ linux-2.6.37/drivers/net/ppp_generic.c 2011-01-17 02:41:01.000000000 -0500
26569 @@ -986,7 +986,6 @@ ppp_net_ioctl(struct net_device *dev, st
26570 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
26571 struct ppp_stats stats;
26572 struct ppp_comp_stats cstats;
26573 - char *vers;
26574
26575 switch (cmd) {
26576 case SIOCGPPPSTATS:
26577 @@ -1008,8 +1007,7 @@ ppp_net_ioctl(struct net_device *dev, st
26578 break;
26579
26580 case SIOCGPPPVER:
26581 - vers = PPP_VERSION;
26582 - if (copy_to_user(addr, vers, strlen(vers) + 1))
26583 + if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
26584 break;
26585 err = 0;
26586 break;
26587 diff -urNp linux-2.6.37/drivers/net/tg3.h linux-2.6.37/drivers/net/tg3.h
26588 --- linux-2.6.37/drivers/net/tg3.h 2011-01-04 19:50:19.000000000 -0500
26589 +++ linux-2.6.37/drivers/net/tg3.h 2011-01-17 02:41:01.000000000 -0500
26590 @@ -131,6 +131,7 @@
26591 #define CHIPREV_ID_5750_A0 0x4000
26592 #define CHIPREV_ID_5750_A1 0x4001
26593 #define CHIPREV_ID_5750_A3 0x4003
26594 +#define CHIPREV_ID_5750_C1 0x4201
26595 #define CHIPREV_ID_5750_C2 0x4202
26596 #define CHIPREV_ID_5752_A0_HW 0x5000
26597 #define CHIPREV_ID_5752_A0 0x6000
26598 diff -urNp linux-2.6.37/drivers/net/tulip/de4x5.c linux-2.6.37/drivers/net/tulip/de4x5.c
26599 --- linux-2.6.37/drivers/net/tulip/de4x5.c 2011-01-04 19:50:19.000000000 -0500
26600 +++ linux-2.6.37/drivers/net/tulip/de4x5.c 2011-01-17 02:41:01.000000000 -0500
26601 @@ -5401,7 +5401,7 @@ de4x5_ioctl(struct net_device *dev, stru
26602 for (i=0; i<ETH_ALEN; i++) {
26603 tmp.addr[i] = dev->dev_addr[i];
26604 }
26605 - if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
26606 + if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
26607 break;
26608
26609 case DE4X5_SET_HWADDR: /* Set the hardware address */
26610 @@ -5441,7 +5441,7 @@ de4x5_ioctl(struct net_device *dev, stru
26611 spin_lock_irqsave(&lp->lock, flags);
26612 memcpy(&statbuf, &lp->pktStats, ioc->len);
26613 spin_unlock_irqrestore(&lp->lock, flags);
26614 - if (copy_to_user(ioc->data, &statbuf, ioc->len))
26615 + if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
26616 return -EFAULT;
26617 break;
26618 }
26619 diff -urNp linux-2.6.37/drivers/net/usb/hso.c linux-2.6.37/drivers/net/usb/hso.c
26620 --- linux-2.6.37/drivers/net/usb/hso.c 2011-01-04 19:50:19.000000000 -0500
26621 +++ linux-2.6.37/drivers/net/usb/hso.c 2011-01-17 02:41:01.000000000 -0500
26622 @@ -257,7 +257,7 @@ struct hso_serial {
26623
26624 /* from usb_serial_port */
26625 struct tty_struct *tty;
26626 - int open_count;
26627 + atomic_t open_count;
26628 spinlock_t serial_lock;
26629
26630 int (*write_data) (struct hso_serial *serial);
26631 @@ -1187,7 +1187,7 @@ static void put_rxbuf_data_and_resubmit_
26632 struct urb *urb;
26633
26634 urb = serial->rx_urb[0];
26635 - if (serial->open_count > 0) {
26636 + if (atomic_read(&serial->open_count) > 0) {
26637 count = put_rxbuf_data(urb, serial);
26638 if (count == -1)
26639 return;
26640 @@ -1223,7 +1223,7 @@ static void hso_std_serial_read_bulk_cal
26641 DUMP1(urb->transfer_buffer, urb->actual_length);
26642
26643 /* Anyone listening? */
26644 - if (serial->open_count == 0)
26645 + if (atomic_read(&serial->open_count) == 0)
26646 return;
26647
26648 if (status == 0) {
26649 @@ -1318,8 +1318,7 @@ static int hso_serial_open(struct tty_st
26650 spin_unlock_irq(&serial->serial_lock);
26651
26652 /* check for port already opened, if not set the termios */
26653 - serial->open_count++;
26654 - if (serial->open_count == 1) {
26655 + if (atomic_inc_return(&serial->open_count) == 1) {
26656 serial->rx_state = RX_IDLE;
26657 /* Force default termio settings */
26658 _hso_serial_set_termios(tty, NULL);
26659 @@ -1331,7 +1330,7 @@ static int hso_serial_open(struct tty_st
26660 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
26661 if (result) {
26662 hso_stop_serial_device(serial->parent);
26663 - serial->open_count--;
26664 + atomic_dec(&serial->open_count);
26665 kref_put(&serial->parent->ref, hso_serial_ref_free);
26666 }
26667 } else {
26668 @@ -1368,10 +1367,10 @@ static void hso_serial_close(struct tty_
26669
26670 /* reset the rts and dtr */
26671 /* do the actual close */
26672 - serial->open_count--;
26673 + atomic_dec(&serial->open_count);
26674
26675 - if (serial->open_count <= 0) {
26676 - serial->open_count = 0;
26677 + if (atomic_read(&serial->open_count) <= 0) {
26678 + atomic_set(&serial->open_count, 0);
26679 spin_lock_irq(&serial->serial_lock);
26680 if (serial->tty == tty) {
26681 serial->tty->driver_data = NULL;
26682 @@ -1453,7 +1452,7 @@ static void hso_serial_set_termios(struc
26683
26684 /* the actual setup */
26685 spin_lock_irqsave(&serial->serial_lock, flags);
26686 - if (serial->open_count)
26687 + if (atomic_read(&serial->open_count))
26688 _hso_serial_set_termios(tty, old);
26689 else
26690 tty->termios = old;
26691 @@ -1913,7 +1912,7 @@ static void intr_callback(struct urb *ur
26692 D1("Pending read interrupt on port %d\n", i);
26693 spin_lock(&serial->serial_lock);
26694 if (serial->rx_state == RX_IDLE &&
26695 - serial->open_count > 0) {
26696 + atomic_read(&serial->open_count) > 0) {
26697 /* Setup and send a ctrl req read on
26698 * port i */
26699 if (!serial->rx_urb_filled[0]) {
26700 @@ -3105,7 +3104,7 @@ static int hso_resume(struct usb_interfa
26701 /* Start all serial ports */
26702 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
26703 if (serial_table[i] && (serial_table[i]->interface == iface)) {
26704 - if (dev2ser(serial_table[i])->open_count) {
26705 + if (atomic_read(&dev2ser(serial_table[i])->open_count)) {
26706 result =
26707 hso_start_serial_device(serial_table[i], GFP_NOIO);
26708 hso_kick_transmit(dev2ser(serial_table[i]));
26709 diff -urNp linux-2.6.37/drivers/net/wireless/b43/debugfs.c linux-2.6.37/drivers/net/wireless/b43/debugfs.c
26710 --- linux-2.6.37/drivers/net/wireless/b43/debugfs.c 2011-01-04 19:50:19.000000000 -0500
26711 +++ linux-2.6.37/drivers/net/wireless/b43/debugfs.c 2011-01-17 02:41:01.000000000 -0500
26712 @@ -43,7 +43,7 @@ static struct dentry *rootdir;
26713 struct b43_debugfs_fops {
26714 ssize_t (*read)(struct b43_wldev *dev, char *buf, size_t bufsize);
26715 int (*write)(struct b43_wldev *dev, const char *buf, size_t count);
26716 - struct file_operations fops;
26717 + const struct file_operations fops;
26718 /* Offset of struct b43_dfs_file in struct b43_dfsentry */
26719 size_t file_struct_offset;
26720 };
26721 diff -urNp linux-2.6.37/drivers/net/wireless/b43legacy/debugfs.c linux-2.6.37/drivers/net/wireless/b43legacy/debugfs.c
26722 --- linux-2.6.37/drivers/net/wireless/b43legacy/debugfs.c 2011-01-04 19:50:19.000000000 -0500
26723 +++ linux-2.6.37/drivers/net/wireless/b43legacy/debugfs.c 2011-01-17 02:41:01.000000000 -0500
26724 @@ -44,7 +44,7 @@ static struct dentry *rootdir;
26725 struct b43legacy_debugfs_fops {
26726 ssize_t (*read)(struct b43legacy_wldev *dev, char *buf, size_t bufsize);
26727 int (*write)(struct b43legacy_wldev *dev, const char *buf, size_t count);
26728 - struct file_operations fops;
26729 + const struct file_operations fops;
26730 /* Offset of struct b43legacy_dfs_file in struct b43legacy_dfsentry */
26731 size_t file_struct_offset;
26732 /* Take wl->irq_lock before calling read/write? */
26733 diff -urNp linux-2.6.37/drivers/net/wireless/iwlwifi/iwl-debug.h linux-2.6.37/drivers/net/wireless/iwlwifi/iwl-debug.h
26734 --- linux-2.6.37/drivers/net/wireless/iwlwifi/iwl-debug.h 2011-01-04 19:50:19.000000000 -0500
26735 +++ linux-2.6.37/drivers/net/wireless/iwlwifi/iwl-debug.h 2011-01-17 02:41:01.000000000 -0500
26736 @@ -68,8 +68,8 @@ do {
26737 } while (0)
26738
26739 #else
26740 -#define IWL_DEBUG(__priv, level, fmt, args...)
26741 -#define IWL_DEBUG_LIMIT(__priv, level, fmt, args...)
26742 +#define IWL_DEBUG(__priv, level, fmt, args...) do {} while (0)
26743 +#define IWL_DEBUG_LIMIT(__priv, level, fmt, args...) do {} while (0)
26744 static inline void iwl_print_hex_dump(struct iwl_priv *priv, int level,
26745 const void *p, u32 len)
26746 {}
26747 diff -urNp linux-2.6.37/drivers/net/wireless/libertas/debugfs.c linux-2.6.37/drivers/net/wireless/libertas/debugfs.c
26748 --- linux-2.6.37/drivers/net/wireless/libertas/debugfs.c 2011-01-04 19:50:19.000000000 -0500
26749 +++ linux-2.6.37/drivers/net/wireless/libertas/debugfs.c 2011-01-17 02:41:01.000000000 -0500
26750 @@ -702,7 +702,7 @@ out_unlock:
26751 struct lbs_debugfs_files {
26752 const char *name;
26753 int perm;
26754 - struct file_operations fops;
26755 + const struct file_operations fops;
26756 };
26757
26758 static const struct lbs_debugfs_files debugfs_files[] = {
26759 diff -urNp linux-2.6.37/drivers/net/wireless/rndis_wlan.c linux-2.6.37/drivers/net/wireless/rndis_wlan.c
26760 --- linux-2.6.37/drivers/net/wireless/rndis_wlan.c 2011-01-04 19:50:19.000000000 -0500
26761 +++ linux-2.6.37/drivers/net/wireless/rndis_wlan.c 2011-01-17 02:41:01.000000000 -0500
26762 @@ -1236,7 +1236,7 @@ static int set_rts_threshold(struct usbn
26763
26764 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
26765
26766 - if (rts_threshold < 0 || rts_threshold > 2347)
26767 + if (rts_threshold > 2347)
26768 rts_threshold = 2347;
26769
26770 tmp = cpu_to_le32(rts_threshold);
26771 diff -urNp linux-2.6.37/drivers/oprofile/buffer_sync.c linux-2.6.37/drivers/oprofile/buffer_sync.c
26772 --- linux-2.6.37/drivers/oprofile/buffer_sync.c 2011-01-04 19:50:19.000000000 -0500
26773 +++ linux-2.6.37/drivers/oprofile/buffer_sync.c 2011-01-17 02:41:01.000000000 -0500
26774 @@ -342,7 +342,7 @@ static void add_data(struct op_entry *en
26775 if (cookie == NO_COOKIE)
26776 offset = pc;
26777 if (cookie == INVALID_COOKIE) {
26778 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
26779 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
26780 offset = pc;
26781 }
26782 if (cookie != last_cookie) {
26783 @@ -386,14 +386,14 @@ add_sample(struct mm_struct *mm, struct
26784 /* add userspace sample */
26785
26786 if (!mm) {
26787 - atomic_inc(&oprofile_stats.sample_lost_no_mm);
26788 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
26789 return 0;
26790 }
26791
26792 cookie = lookup_dcookie(mm, s->eip, &offset);
26793
26794 if (cookie == INVALID_COOKIE) {
26795 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
26796 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
26797 return 0;
26798 }
26799
26800 @@ -562,7 +562,7 @@ void sync_buffer(int cpu)
26801 /* ignore backtraces if failed to add a sample */
26802 if (state == sb_bt_start) {
26803 state = sb_bt_ignore;
26804 - atomic_inc(&oprofile_stats.bt_lost_no_mapping);
26805 + atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
26806 }
26807 }
26808 release_mm(mm);
26809 diff -urNp linux-2.6.37/drivers/oprofile/event_buffer.c linux-2.6.37/drivers/oprofile/event_buffer.c
26810 --- linux-2.6.37/drivers/oprofile/event_buffer.c 2011-01-04 19:50:19.000000000 -0500
26811 +++ linux-2.6.37/drivers/oprofile/event_buffer.c 2011-01-17 02:41:01.000000000 -0500
26812 @@ -53,7 +53,7 @@ void add_event_entry(unsigned long value
26813 }
26814
26815 if (buffer_pos == buffer_size) {
26816 - atomic_inc(&oprofile_stats.event_lost_overflow);
26817 + atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
26818 return;
26819 }
26820
26821 diff -urNp linux-2.6.37/drivers/oprofile/oprof.c linux-2.6.37/drivers/oprofile/oprof.c
26822 --- linux-2.6.37/drivers/oprofile/oprof.c 2011-01-04 19:50:19.000000000 -0500
26823 +++ linux-2.6.37/drivers/oprofile/oprof.c 2011-01-17 02:41:01.000000000 -0500
26824 @@ -110,7 +110,7 @@ static void switch_worker(struct work_st
26825 if (oprofile_ops.switch_events())
26826 return;
26827
26828 - atomic_inc(&oprofile_stats.multiplex_counter);
26829 + atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
26830 start_switch_worker();
26831 }
26832
26833 diff -urNp linux-2.6.37/drivers/oprofile/oprofilefs.c linux-2.6.37/drivers/oprofile/oprofilefs.c
26834 --- linux-2.6.37/drivers/oprofile/oprofilefs.c 2011-01-04 19:50:19.000000000 -0500
26835 +++ linux-2.6.37/drivers/oprofile/oprofilefs.c 2011-01-17 02:41:01.000000000 -0500
26836 @@ -186,7 +186,7 @@ static const struct file_operations atom
26837
26838
26839 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
26840 - char const *name, atomic_t *val)
26841 + char const *name, atomic_unchecked_t *val)
26842 {
26843 return __oprofilefs_create_file(sb, root, name,
26844 &atomic_ro_fops, 0444, val);
26845 diff -urNp linux-2.6.37/drivers/oprofile/oprofile_stats.c linux-2.6.37/drivers/oprofile/oprofile_stats.c
26846 --- linux-2.6.37/drivers/oprofile/oprofile_stats.c 2011-01-04 19:50:19.000000000 -0500
26847 +++ linux-2.6.37/drivers/oprofile/oprofile_stats.c 2011-01-17 02:41:01.000000000 -0500
26848 @@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
26849 cpu_buf->sample_invalid_eip = 0;
26850 }
26851
26852 - atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
26853 - atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
26854 - atomic_set(&oprofile_stats.event_lost_overflow, 0);
26855 - atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
26856 - atomic_set(&oprofile_stats.multiplex_counter, 0);
26857 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
26858 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
26859 + atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
26860 + atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
26861 + atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
26862 }
26863
26864
26865 diff -urNp linux-2.6.37/drivers/oprofile/oprofile_stats.h linux-2.6.37/drivers/oprofile/oprofile_stats.h
26866 --- linux-2.6.37/drivers/oprofile/oprofile_stats.h 2011-01-04 19:50:19.000000000 -0500
26867 +++ linux-2.6.37/drivers/oprofile/oprofile_stats.h 2011-01-17 02:41:01.000000000 -0500
26868 @@ -13,11 +13,11 @@
26869 #include <asm/atomic.h>
26870
26871 struct oprofile_stat_struct {
26872 - atomic_t sample_lost_no_mm;
26873 - atomic_t sample_lost_no_mapping;
26874 - atomic_t bt_lost_no_mapping;
26875 - atomic_t event_lost_overflow;
26876 - atomic_t multiplex_counter;
26877 + atomic_unchecked_t sample_lost_no_mm;
26878 + atomic_unchecked_t sample_lost_no_mapping;
26879 + atomic_unchecked_t bt_lost_no_mapping;
26880 + atomic_unchecked_t event_lost_overflow;
26881 + atomic_unchecked_t multiplex_counter;
26882 };
26883
26884 extern struct oprofile_stat_struct oprofile_stats;
26885 diff -urNp linux-2.6.37/drivers/parport/procfs.c linux-2.6.37/drivers/parport/procfs.c
26886 --- linux-2.6.37/drivers/parport/procfs.c 2011-01-04 19:50:19.000000000 -0500
26887 +++ linux-2.6.37/drivers/parport/procfs.c 2011-01-17 02:41:01.000000000 -0500
26888 @@ -64,7 +64,7 @@ static int do_active_device(ctl_table *t
26889
26890 *ppos += len;
26891
26892 - return copy_to_user(result, buffer, len) ? -EFAULT : 0;
26893 + return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
26894 }
26895
26896 #ifdef CONFIG_PARPORT_1284
26897 @@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table
26898
26899 *ppos += len;
26900
26901 - return copy_to_user (result, buffer, len) ? -EFAULT : 0;
26902 + return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
26903 }
26904 #endif /* IEEE1284.3 support. */
26905
26906 diff -urNp linux-2.6.37/drivers/pci/hotplug/acpiphp_glue.c linux-2.6.37/drivers/pci/hotplug/acpiphp_glue.c
26907 --- linux-2.6.37/drivers/pci/hotplug/acpiphp_glue.c 2011-01-04 19:50:19.000000000 -0500
26908 +++ linux-2.6.37/drivers/pci/hotplug/acpiphp_glue.c 2011-01-17 02:41:01.000000000 -0500
26909 @@ -110,7 +110,7 @@ static int post_dock_fixups(struct notif
26910 }
26911
26912
26913 -static struct acpi_dock_ops acpiphp_dock_ops = {
26914 +static const struct acpi_dock_ops acpiphp_dock_ops = {
26915 .handler = handle_hotplug_event_func,
26916 };
26917
26918 diff -urNp linux-2.6.37/drivers/pci/hotplug/cpqphp_nvram.c linux-2.6.37/drivers/pci/hotplug/cpqphp_nvram.c
26919 --- linux-2.6.37/drivers/pci/hotplug/cpqphp_nvram.c 2011-01-04 19:50:19.000000000 -0500
26920 +++ linux-2.6.37/drivers/pci/hotplug/cpqphp_nvram.c 2011-01-17 02:41:01.000000000 -0500
26921 @@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_
26922
26923 void compaq_nvram_init (void __iomem *rom_start)
26924 {
26925 +
26926 +#ifndef CONFIG_PAX_KERNEXEC
26927 if (rom_start) {
26928 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
26929 }
26930 +#endif
26931 +
26932 dbg("int15 entry = %p\n", compaq_int15_entry_point);
26933
26934 /* initialize our int15 lock */
26935 diff -urNp linux-2.6.37/drivers/pci/intel-iommu.c linux-2.6.37/drivers/pci/intel-iommu.c
26936 --- linux-2.6.37/drivers/pci/intel-iommu.c 2011-01-04 19:50:19.000000000 -0500
26937 +++ linux-2.6.37/drivers/pci/intel-iommu.c 2011-01-17 02:41:01.000000000 -0500
26938 @@ -2934,7 +2934,7 @@ static int intel_mapping_error(struct de
26939 return !dma_addr;
26940 }
26941
26942 -struct dma_map_ops intel_dma_ops = {
26943 +const struct dma_map_ops intel_dma_ops = {
26944 .alloc_coherent = intel_alloc_coherent,
26945 .free_coherent = intel_free_coherent,
26946 .map_sg = intel_map_sg,
26947 diff -urNp linux-2.6.37/drivers/pci/pcie/portdrv_pci.c linux-2.6.37/drivers/pci/pcie/portdrv_pci.c
26948 --- linux-2.6.37/drivers/pci/pcie/portdrv_pci.c 2011-01-04 19:50:19.000000000 -0500
26949 +++ linux-2.6.37/drivers/pci/pcie/portdrv_pci.c 2011-01-17 02:41:01.000000000 -0500
26950 @@ -276,7 +276,7 @@ static void pcie_portdrv_err_resume(stru
26951 static const struct pci_device_id port_pci_ids[] = { {
26952 /* handle any PCI-Express port */
26953 PCI_DEVICE_CLASS(((PCI_CLASS_BRIDGE_PCI << 8) | 0x00), ~0),
26954 - }, { /* end: all zeroes */ }
26955 + }, { 0, 0, 0, 0, 0, 0, 0 }
26956 };
26957 MODULE_DEVICE_TABLE(pci, port_pci_ids);
26958
26959 diff -urNp linux-2.6.37/drivers/pci/probe.c linux-2.6.37/drivers/pci/probe.c
26960 --- linux-2.6.37/drivers/pci/probe.c 2011-01-04 19:50:19.000000000 -0500
26961 +++ linux-2.6.37/drivers/pci/probe.c 2011-01-17 02:41:01.000000000 -0500
26962 @@ -62,14 +62,14 @@ static ssize_t pci_bus_show_cpuaffinity(
26963 return ret;
26964 }
26965
26966 -static ssize_t inline pci_bus_show_cpumaskaffinity(struct device *dev,
26967 +static inline ssize_t pci_bus_show_cpumaskaffinity(struct device *dev,
26968 struct device_attribute *attr,
26969 char *buf)
26970 {
26971 return pci_bus_show_cpuaffinity(dev, 0, attr, buf);
26972 }
26973
26974 -static ssize_t inline pci_bus_show_cpulistaffinity(struct device *dev,
26975 +static inline ssize_t pci_bus_show_cpulistaffinity(struct device *dev,
26976 struct device_attribute *attr,
26977 char *buf)
26978 {
26979 @@ -165,7 +165,7 @@ int __pci_read_base(struct pci_dev *dev,
26980 u32 l, sz, mask;
26981 u16 orig_cmd;
26982
26983 - mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
26984 + mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
26985
26986 if (!dev->mmio_always_on) {
26987 pci_read_config_word(dev, PCI_COMMAND, &orig_cmd);
26988 diff -urNp linux-2.6.37/drivers/pci/proc.c linux-2.6.37/drivers/pci/proc.c
26989 --- linux-2.6.37/drivers/pci/proc.c 2011-01-04 19:50:19.000000000 -0500
26990 +++ linux-2.6.37/drivers/pci/proc.c 2011-01-17 02:41:01.000000000 -0500
26991 @@ -476,7 +476,16 @@ static const struct file_operations proc
26992 static int __init pci_proc_init(void)
26993 {
26994 struct pci_dev *dev = NULL;
26995 +
26996 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
26997 +#ifdef CONFIG_GRKERNSEC_PROC_USER
26998 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
26999 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
27000 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
27001 +#endif
27002 +#else
27003 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
27004 +#endif
27005 proc_create("devices", 0, proc_bus_pci_dir,
27006 &proc_bus_pci_dev_operations);
27007 proc_initialized = 1;
27008 diff -urNp linux-2.6.37/drivers/pcmcia/ti113x.h linux-2.6.37/drivers/pcmcia/ti113x.h
27009 --- linux-2.6.37/drivers/pcmcia/ti113x.h 2011-01-04 19:50:19.000000000 -0500
27010 +++ linux-2.6.37/drivers/pcmcia/ti113x.h 2011-01-17 02:41:01.000000000 -0500
27011 @@ -936,7 +936,7 @@ static struct pci_device_id ene_tune_tbl
27012 DEVID(PCI_VENDOR_ID_MOTOROLA, 0x3410, 0xECC0, PCI_ANY_ID,
27013 ENE_TEST_C9_TLTENABLE | ENE_TEST_C9_PFENABLE, ENE_TEST_C9_TLTENABLE),
27014
27015 - {}
27016 + { 0, 0, 0, 0, 0, 0, 0 }
27017 };
27018
27019 static void ene_tune_bridge(struct pcmcia_socket *sock, struct pci_bus *bus)
27020 diff -urNp linux-2.6.37/drivers/pcmcia/yenta_socket.c linux-2.6.37/drivers/pcmcia/yenta_socket.c
27021 --- linux-2.6.37/drivers/pcmcia/yenta_socket.c 2011-01-04 19:50:19.000000000 -0500
27022 +++ linux-2.6.37/drivers/pcmcia/yenta_socket.c 2011-01-17 02:41:01.000000000 -0500
27023 @@ -1426,7 +1426,7 @@ static struct pci_device_id yenta_table[
27024
27025 /* match any cardbus bridge */
27026 CB_ID(PCI_ANY_ID, PCI_ANY_ID, DEFAULT),
27027 - { /* all zeroes */ }
27028 + { 0, 0, 0, 0, 0, 0, 0 }
27029 };
27030 MODULE_DEVICE_TABLE(pci, yenta_table);
27031
27032 diff -urNp linux-2.6.37/drivers/platform/x86/acer-wmi.c linux-2.6.37/drivers/platform/x86/acer-wmi.c
27033 --- linux-2.6.37/drivers/platform/x86/acer-wmi.c 2011-01-04 19:50:19.000000000 -0500
27034 +++ linux-2.6.37/drivers/platform/x86/acer-wmi.c 2011-01-17 02:41:01.000000000 -0500
27035 @@ -915,7 +915,7 @@ static int update_bl_status(struct backl
27036 return 0;
27037 }
27038
27039 -static struct backlight_ops acer_bl_ops = {
27040 +static const struct backlight_ops acer_bl_ops = {
27041 .get_brightness = read_brightness,
27042 .update_status = update_bl_status,
27043 };
27044 diff -urNp linux-2.6.37/drivers/platform/x86/asus_acpi.c linux-2.6.37/drivers/platform/x86/asus_acpi.c
27045 --- linux-2.6.37/drivers/platform/x86/asus_acpi.c 2011-01-04 19:50:19.000000000 -0500
27046 +++ linux-2.6.37/drivers/platform/x86/asus_acpi.c 2011-01-17 02:41:01.000000000 -0500
27047 @@ -1467,7 +1467,7 @@ static int asus_hotk_remove(struct acpi_
27048 return 0;
27049 }
27050
27051 -static struct backlight_ops asus_backlight_data = {
27052 +static const struct backlight_ops asus_backlight_data = {
27053 .get_brightness = read_brightness,
27054 .update_status = set_brightness_status,
27055 };
27056 diff -urNp linux-2.6.37/drivers/platform/x86/asus-laptop.c linux-2.6.37/drivers/platform/x86/asus-laptop.c
27057 --- linux-2.6.37/drivers/platform/x86/asus-laptop.c 2011-01-04 19:50:19.000000000 -0500
27058 +++ linux-2.6.37/drivers/platform/x86/asus-laptop.c 2011-01-17 02:41:01.000000000 -0500
27059 @@ -243,7 +243,6 @@ struct asus_laptop {
27060 struct asus_led gled;
27061 struct asus_led kled;
27062 struct workqueue_struct *led_workqueue;
27063 -
27064 int wireless_status;
27065 bool have_rsts;
27066 int lcd_state;
27067 @@ -640,7 +639,7 @@ static int update_bl_status(struct backl
27068 return asus_lcd_set(asus, value);
27069 }
27070
27071 -static struct backlight_ops asusbl_ops = {
27072 +static const struct backlight_ops asusbl_ops = {
27073 .get_brightness = asus_read_brightness,
27074 .update_status = update_bl_status,
27075 };
27076 diff -urNp linux-2.6.37/drivers/platform/x86/dell-laptop.c linux-2.6.37/drivers/platform/x86/dell-laptop.c
27077 --- linux-2.6.37/drivers/platform/x86/dell-laptop.c 2011-01-04 19:50:19.000000000 -0500
27078 +++ linux-2.6.37/drivers/platform/x86/dell-laptop.c 2011-01-17 02:41:01.000000000 -0500
27079 @@ -546,7 +546,7 @@ out:
27080 return buffer->output[1];
27081 }
27082
27083 -static struct backlight_ops dell_ops = {
27084 +static const struct backlight_ops dell_ops = {
27085 .get_brightness = dell_get_intensity,
27086 .update_status = dell_send_intensity,
27087 };
27088 diff -urNp linux-2.6.37/drivers/platform/x86/eeepc-laptop.c linux-2.6.37/drivers/platform/x86/eeepc-laptop.c
27089 --- linux-2.6.37/drivers/platform/x86/eeepc-laptop.c 2011-01-04 19:50:19.000000000 -0500
27090 +++ linux-2.6.37/drivers/platform/x86/eeepc-laptop.c 2011-01-17 02:41:01.000000000 -0500
27091 @@ -1115,7 +1115,7 @@ static int update_bl_status(struct backl
27092 return set_brightness(bd, bd->props.brightness);
27093 }
27094
27095 -static struct backlight_ops eeepcbl_ops = {
27096 +static const struct backlight_ops eeepcbl_ops = {
27097 .get_brightness = read_brightness,
27098 .update_status = update_bl_status,
27099 };
27100 diff -urNp linux-2.6.37/drivers/platform/x86/fujitsu-laptop.c linux-2.6.37/drivers/platform/x86/fujitsu-laptop.c
27101 --- linux-2.6.37/drivers/platform/x86/fujitsu-laptop.c 2011-01-04 19:50:19.000000000 -0500
27102 +++ linux-2.6.37/drivers/platform/x86/fujitsu-laptop.c 2011-01-17 02:41:01.000000000 -0500
27103 @@ -437,7 +437,7 @@ static int bl_update_status(struct backl
27104 return ret;
27105 }
27106
27107 -static struct backlight_ops fujitsubl_ops = {
27108 +static const struct backlight_ops fujitsubl_ops = {
27109 .get_brightness = bl_get_brightness,
27110 .update_status = bl_update_status,
27111 };
27112 diff -urNp linux-2.6.37/drivers/platform/x86/sony-laptop.c linux-2.6.37/drivers/platform/x86/sony-laptop.c
27113 --- linux-2.6.37/drivers/platform/x86/sony-laptop.c 2011-01-04 19:50:19.000000000 -0500
27114 +++ linux-2.6.37/drivers/platform/x86/sony-laptop.c 2011-01-17 02:41:01.000000000 -0500
27115 @@ -856,7 +856,7 @@ static int sony_backlight_get_brightness
27116 }
27117
27118 static struct backlight_device *sony_backlight_device;
27119 -static struct backlight_ops sony_backlight_ops = {
27120 +static const struct backlight_ops sony_backlight_ops = {
27121 .update_status = sony_backlight_update_status,
27122 .get_brightness = sony_backlight_get_brightness,
27123 };
27124 diff -urNp linux-2.6.37/drivers/platform/x86/thinkpad_acpi.c linux-2.6.37/drivers/platform/x86/thinkpad_acpi.c
27125 --- linux-2.6.37/drivers/platform/x86/thinkpad_acpi.c 2011-01-04 19:50:19.000000000 -0500
27126 +++ linux-2.6.37/drivers/platform/x86/thinkpad_acpi.c 2011-01-17 02:41:01.000000000 -0500
27127 @@ -6109,7 +6109,7 @@ static void tpacpi_brightness_notify_cha
27128 BACKLIGHT_UPDATE_HOTKEY);
27129 }
27130
27131 -static struct backlight_ops ibm_backlight_data = {
27132 +static const struct backlight_ops ibm_backlight_data = {
27133 .get_brightness = brightness_get,
27134 .update_status = brightness_update_status,
27135 };
27136 diff -urNp linux-2.6.37/drivers/platform/x86/toshiba_acpi.c linux-2.6.37/drivers/platform/x86/toshiba_acpi.c
27137 --- linux-2.6.37/drivers/platform/x86/toshiba_acpi.c 2011-01-04 19:50:19.000000000 -0500
27138 +++ linux-2.6.37/drivers/platform/x86/toshiba_acpi.c 2011-01-17 02:41:01.000000000 -0500
27139 @@ -841,7 +841,7 @@ static void remove_toshiba_proc_entries(
27140 remove_proc_entry("version", toshiba_proc_dir);
27141 }
27142
27143 -static struct backlight_ops toshiba_backlight_data = {
27144 +static const struct backlight_ops toshiba_backlight_data = {
27145 .get_brightness = get_lcd,
27146 .update_status = set_lcd_status,
27147 };
27148 diff -urNp linux-2.6.37/drivers/pnp/pnpbios/bioscalls.c linux-2.6.37/drivers/pnp/pnpbios/bioscalls.c
27149 --- linux-2.6.37/drivers/pnp/pnpbios/bioscalls.c 2011-01-04 19:50:19.000000000 -0500
27150 +++ linux-2.6.37/drivers/pnp/pnpbios/bioscalls.c 2011-01-17 02:41:01.000000000 -0500
27151 @@ -59,7 +59,7 @@ do { \
27152 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
27153 } while(0)
27154
27155 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
27156 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
27157 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
27158
27159 /*
27160 @@ -96,7 +96,10 @@ static inline u16 call_pnp_bios(u16 func
27161
27162 cpu = get_cpu();
27163 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
27164 +
27165 + pax_open_kernel();
27166 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
27167 + pax_close_kernel();
27168
27169 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
27170 spin_lock_irqsave(&pnp_bios_lock, flags);
27171 @@ -134,7 +137,10 @@ static inline u16 call_pnp_bios(u16 func
27172 :"memory");
27173 spin_unlock_irqrestore(&pnp_bios_lock, flags);
27174
27175 + pax_open_kernel();
27176 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
27177 + pax_close_kernel();
27178 +
27179 put_cpu();
27180
27181 /* If we get here and this is set then the PnP BIOS faulted on us. */
27182 @@ -468,7 +474,7 @@ int pnp_bios_read_escd(char *data, u32 n
27183 return status;
27184 }
27185
27186 -void pnpbios_calls_init(union pnp_bios_install_struct *header)
27187 +void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
27188 {
27189 int i;
27190
27191 @@ -476,6 +482,8 @@ void pnpbios_calls_init(union pnp_bios_i
27192 pnp_bios_callpoint.offset = header->fields.pm16offset;
27193 pnp_bios_callpoint.segment = PNP_CS16;
27194
27195 + pax_open_kernel();
27196 +
27197 for_each_possible_cpu(i) {
27198 struct desc_struct *gdt = get_cpu_gdt_table(i);
27199 if (!gdt)
27200 @@ -487,4 +495,6 @@ void pnpbios_calls_init(union pnp_bios_i
27201 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
27202 (unsigned long)__va(header->fields.pm16dseg));
27203 }
27204 +
27205 + pax_close_kernel();
27206 }
27207 diff -urNp linux-2.6.37/drivers/pnp/quirks.c linux-2.6.37/drivers/pnp/quirks.c
27208 --- linux-2.6.37/drivers/pnp/quirks.c 2011-01-04 19:50:19.000000000 -0500
27209 +++ linux-2.6.37/drivers/pnp/quirks.c 2011-01-17 02:41:01.000000000 -0500
27210 @@ -322,7 +322,7 @@ static struct pnp_fixup pnp_fixups[] = {
27211 /* PnP resources that might overlap PCI BARs */
27212 {"PNP0c01", quirk_system_pci_resources},
27213 {"PNP0c02", quirk_system_pci_resources},
27214 - {""}
27215 + {"", NULL}
27216 };
27217
27218 void pnp_fixup_device(struct pnp_dev *dev)
27219 diff -urNp linux-2.6.37/drivers/pnp/resource.c linux-2.6.37/drivers/pnp/resource.c
27220 --- linux-2.6.37/drivers/pnp/resource.c 2011-01-04 19:50:19.000000000 -0500
27221 +++ linux-2.6.37/drivers/pnp/resource.c 2011-01-17 02:41:01.000000000 -0500
27222 @@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, s
27223 return 1;
27224
27225 /* check if the resource is valid */
27226 - if (*irq < 0 || *irq > 15)
27227 + if (*irq > 15)
27228 return 0;
27229
27230 /* check if the resource is reserved */
27231 @@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, s
27232 return 1;
27233
27234 /* check if the resource is valid */
27235 - if (*dma < 0 || *dma == 4 || *dma > 7)
27236 + if (*dma == 4 || *dma > 7)
27237 return 0;
27238
27239 /* check if the resource is reserved */
27240 diff -urNp linux-2.6.37/drivers/rtc/rtc-dev.c linux-2.6.37/drivers/rtc/rtc-dev.c
27241 --- linux-2.6.37/drivers/rtc/rtc-dev.c 2011-01-04 19:50:19.000000000 -0500
27242 +++ linux-2.6.37/drivers/rtc/rtc-dev.c 2011-01-17 02:41:01.000000000 -0500
27243 @@ -14,6 +14,7 @@
27244 #include <linux/module.h>
27245 #include <linux/rtc.h>
27246 #include <linux/sched.h>
27247 +#include <linux/grsecurity.h>
27248 #include "rtc-core.h"
27249
27250 static dev_t rtc_devt;
27251 @@ -357,6 +358,8 @@ static long rtc_dev_ioctl(struct file *f
27252 if (copy_from_user(&tm, uarg, sizeof(tm)))
27253 return -EFAULT;
27254
27255 + gr_log_timechange();
27256 +
27257 return rtc_set_time(rtc, &tm);
27258
27259 case RTC_PIE_ON:
27260 diff -urNp linux-2.6.37/drivers/s390/cio/qdio_debug.c linux-2.6.37/drivers/s390/cio/qdio_debug.c
27261 --- linux-2.6.37/drivers/s390/cio/qdio_debug.c 2011-01-04 19:50:19.000000000 -0500
27262 +++ linux-2.6.37/drivers/s390/cio/qdio_debug.c 2011-01-17 02:41:01.000000000 -0500
27263 @@ -224,7 +224,7 @@ static int qperf_seq_open(struct inode *
27264 filp->f_path.dentry->d_inode->i_private);
27265 }
27266
27267 -static struct file_operations debugfs_perf_fops = {
27268 +static const struct file_operations debugfs_perf_fops = {
27269 .owner = THIS_MODULE,
27270 .open = qperf_seq_open,
27271 .read = seq_read,
27272 diff -urNp linux-2.6.37/drivers/scsi/hpsa.c linux-2.6.37/drivers/scsi/hpsa.c
27273 --- linux-2.6.37/drivers/scsi/hpsa.c 2011-01-04 19:50:19.000000000 -0500
27274 +++ linux-2.6.37/drivers/scsi/hpsa.c 2011-01-17 02:41:01.000000000 -0500
27275 @@ -2292,6 +2292,8 @@ static int hpsa_ioctl32_passthru(struct
27276 int err;
27277 u32 cp;
27278
27279 + memset(&arg64, 0, sizeof(arg64));
27280 +
27281 err = 0;
27282 err |= copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
27283 sizeof(arg64.LUN_info));
27284 diff -urNp linux-2.6.37/drivers/scsi/ipr.c linux-2.6.37/drivers/scsi/ipr.c
27285 --- linux-2.6.37/drivers/scsi/ipr.c 2011-01-04 19:50:19.000000000 -0500
27286 +++ linux-2.6.37/drivers/scsi/ipr.c 2011-01-17 02:41:01.000000000 -0500
27287 @@ -6202,7 +6202,7 @@ static bool ipr_qc_fill_rtf(struct ata_q
27288 return true;
27289 }
27290
27291 -static struct ata_port_operations ipr_sata_ops = {
27292 +static const struct ata_port_operations ipr_sata_ops = {
27293 .phy_reset = ipr_ata_phy_reset,
27294 .hardreset = ipr_sata_reset,
27295 .post_internal_cmd = ipr_ata_post_internal,
27296 diff -urNp linux-2.6.37/drivers/scsi/libfc/fc_exch.c linux-2.6.37/drivers/scsi/libfc/fc_exch.c
27297 --- linux-2.6.37/drivers/scsi/libfc/fc_exch.c 2011-01-04 19:50:19.000000000 -0500
27298 +++ linux-2.6.37/drivers/scsi/libfc/fc_exch.c 2011-01-17 02:41:01.000000000 -0500
27299 @@ -100,12 +100,12 @@ struct fc_exch_mgr {
27300 * all together if not used XXX
27301 */
27302 struct {
27303 - atomic_t no_free_exch;
27304 - atomic_t no_free_exch_xid;
27305 - atomic_t xid_not_found;
27306 - atomic_t xid_busy;
27307 - atomic_t seq_not_found;
27308 - atomic_t non_bls_resp;
27309 + atomic_unchecked_t no_free_exch;
27310 + atomic_unchecked_t no_free_exch_xid;
27311 + atomic_unchecked_t xid_not_found;
27312 + atomic_unchecked_t xid_busy;
27313 + atomic_unchecked_t seq_not_found;
27314 + atomic_unchecked_t non_bls_resp;
27315 } stats;
27316 };
27317 #define fc_seq_exch(sp) container_of(sp, struct fc_exch, seq)
27318 @@ -670,7 +670,7 @@ static struct fc_exch *fc_exch_em_alloc(
27319 /* allocate memory for exchange */
27320 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
27321 if (!ep) {
27322 - atomic_inc(&mp->stats.no_free_exch);
27323 + atomic_inc_unchecked(&mp->stats.no_free_exch);
27324 goto out;
27325 }
27326 memset(ep, 0, sizeof(*ep));
27327 @@ -718,7 +718,7 @@ out:
27328 return ep;
27329 err:
27330 spin_unlock_bh(&pool->lock);
27331 - atomic_inc(&mp->stats.no_free_exch_xid);
27332 + atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
27333 mempool_free(ep, mp->ep_pool);
27334 return NULL;
27335 }
27336 @@ -863,7 +863,7 @@ static enum fc_pf_rjt_reason fc_seq_look
27337 xid = ntohs(fh->fh_ox_id); /* we originated exch */
27338 ep = fc_exch_find(mp, xid);
27339 if (!ep) {
27340 - atomic_inc(&mp->stats.xid_not_found);
27341 + atomic_inc_unchecked(&mp->stats.xid_not_found);
27342 reject = FC_RJT_OX_ID;
27343 goto out;
27344 }
27345 @@ -893,7 +893,7 @@ static enum fc_pf_rjt_reason fc_seq_look
27346 ep = fc_exch_find(mp, xid);
27347 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
27348 if (ep) {
27349 - atomic_inc(&mp->stats.xid_busy);
27350 + atomic_inc_unchecked(&mp->stats.xid_busy);
27351 reject = FC_RJT_RX_ID;
27352 goto rel;
27353 }
27354 @@ -904,7 +904,7 @@ static enum fc_pf_rjt_reason fc_seq_look
27355 }
27356 xid = ep->xid; /* get our XID */
27357 } else if (!ep) {
27358 - atomic_inc(&mp->stats.xid_not_found);
27359 + atomic_inc_unchecked(&mp->stats.xid_not_found);
27360 reject = FC_RJT_RX_ID; /* XID not found */
27361 goto out;
27362 }
27363 @@ -921,7 +921,7 @@ static enum fc_pf_rjt_reason fc_seq_look
27364 } else {
27365 sp = &ep->seq;
27366 if (sp->id != fh->fh_seq_id) {
27367 - atomic_inc(&mp->stats.seq_not_found);
27368 + atomic_inc_unchecked(&mp->stats.seq_not_found);
27369 reject = FC_RJT_SEQ_ID; /* sequence/exch should exist */
27370 goto rel;
27371 }
27372 @@ -1338,22 +1338,22 @@ static void fc_exch_recv_seq_resp(struct
27373
27374 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
27375 if (!ep) {
27376 - atomic_inc(&mp->stats.xid_not_found);
27377 + atomic_inc_unchecked(&mp->stats.xid_not_found);
27378 goto out;
27379 }
27380 if (ep->esb_stat & ESB_ST_COMPLETE) {
27381 - atomic_inc(&mp->stats.xid_not_found);
27382 + atomic_inc_unchecked(&mp->stats.xid_not_found);
27383 goto out;
27384 }
27385 if (ep->rxid == FC_XID_UNKNOWN)
27386 ep->rxid = ntohs(fh->fh_rx_id);
27387 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
27388 - atomic_inc(&mp->stats.xid_not_found);
27389 + atomic_inc_unchecked(&mp->stats.xid_not_found);
27390 goto rel;
27391 }
27392 if (ep->did != ntoh24(fh->fh_s_id) &&
27393 ep->did != FC_FID_FLOGI) {
27394 - atomic_inc(&mp->stats.xid_not_found);
27395 + atomic_inc_unchecked(&mp->stats.xid_not_found);
27396 goto rel;
27397 }
27398 sof = fr_sof(fp);
27399 @@ -1362,7 +1362,7 @@ static void fc_exch_recv_seq_resp(struct
27400 sp->ssb_stat |= SSB_ST_RESP;
27401 sp->id = fh->fh_seq_id;
27402 } else if (sp->id != fh->fh_seq_id) {
27403 - atomic_inc(&mp->stats.seq_not_found);
27404 + atomic_inc_unchecked(&mp->stats.seq_not_found);
27405 goto rel;
27406 }
27407
27408 @@ -1425,9 +1425,9 @@ static void fc_exch_recv_resp(struct fc_
27409 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
27410
27411 if (!sp)
27412 - atomic_inc(&mp->stats.xid_not_found);
27413 + atomic_inc_unchecked(&mp->stats.xid_not_found);
27414 else
27415 - atomic_inc(&mp->stats.non_bls_resp);
27416 + atomic_inc_unchecked(&mp->stats.non_bls_resp);
27417
27418 fc_frame_free(fp);
27419 }
27420 diff -urNp linux-2.6.37/drivers/scsi/libsas/sas_ata.c linux-2.6.37/drivers/scsi/libsas/sas_ata.c
27421 --- linux-2.6.37/drivers/scsi/libsas/sas_ata.c 2011-01-04 19:50:19.000000000 -0500
27422 +++ linux-2.6.37/drivers/scsi/libsas/sas_ata.c 2011-01-17 02:41:01.000000000 -0500
27423 @@ -348,10 +348,10 @@ static int sas_ata_scr_read(struct ata_l
27424 }
27425 }
27426
27427 -static struct ata_port_operations sas_sata_ops = {
27428 +static const struct ata_port_operations sas_sata_ops = {
27429 .phy_reset = sas_ata_phy_reset,
27430 .post_internal_cmd = sas_ata_post_internal,
27431 - .qc_defer = ata_std_qc_defer,
27432 + .qc_defer = ata_std_qc_defer,
27433 .qc_prep = ata_noop_qc_prep,
27434 .qc_issue = sas_ata_qc_issue,
27435 .qc_fill_rtf = sas_ata_qc_fill_rtf,
27436 diff -urNp linux-2.6.37/drivers/scsi/mpt2sas/mpt2sas_debug.h linux-2.6.37/drivers/scsi/mpt2sas/mpt2sas_debug.h
27437 --- linux-2.6.37/drivers/scsi/mpt2sas/mpt2sas_debug.h 2011-01-04 19:50:19.000000000 -0500
27438 +++ linux-2.6.37/drivers/scsi/mpt2sas/mpt2sas_debug.h 2011-01-17 02:41:01.000000000 -0500
27439 @@ -79,7 +79,7 @@
27440 CMD; \
27441 }
27442 #else
27443 -#define MPT_CHECK_LOGGING(IOC, CMD, BITS)
27444 +#define MPT_CHECK_LOGGING(IOC, CMD, BITS) do {} while (0)
27445 #endif /* CONFIG_SCSI_MPT2SAS_LOGGING */
27446
27447
27448 diff -urNp linux-2.6.37/drivers/scsi/qla2xxx/qla_os.c linux-2.6.37/drivers/scsi/qla2xxx/qla_os.c
27449 --- linux-2.6.37/drivers/scsi/qla2xxx/qla_os.c 2011-01-04 19:50:19.000000000 -0500
27450 +++ linux-2.6.37/drivers/scsi/qla2xxx/qla_os.c 2011-01-17 02:41:01.000000000 -0500
27451 @@ -4083,7 +4083,7 @@ static struct pci_driver qla2xxx_pci_dri
27452 .err_handler = &qla2xxx_err_handler,
27453 };
27454
27455 -static struct file_operations apidev_fops = {
27456 +static const struct file_operations apidev_fops = {
27457 .owner = THIS_MODULE,
27458 .llseek = noop_llseek,
27459 };
27460 diff -urNp linux-2.6.37/drivers/scsi/scsi_logging.h linux-2.6.37/drivers/scsi/scsi_logging.h
27461 --- linux-2.6.37/drivers/scsi/scsi_logging.h 2011-01-04 19:50:19.000000000 -0500
27462 +++ linux-2.6.37/drivers/scsi/scsi_logging.h 2011-01-17 02:41:01.000000000 -0500
27463 @@ -51,7 +51,7 @@ do { \
27464 } while (0); \
27465 } while (0)
27466 #else
27467 -#define SCSI_CHECK_LOGGING(SHIFT, BITS, LEVEL, CMD)
27468 +#define SCSI_CHECK_LOGGING(SHIFT, BITS, LEVEL, CMD) do {} while (0)
27469 #endif /* CONFIG_SCSI_LOGGING */
27470
27471 /*
27472 diff -urNp linux-2.6.37/drivers/scsi/sg.c linux-2.6.37/drivers/scsi/sg.c
27473 --- linux-2.6.37/drivers/scsi/sg.c 2011-01-04 19:50:19.000000000 -0500
27474 +++ linux-2.6.37/drivers/scsi/sg.c 2011-01-17 02:41:01.000000000 -0500
27475 @@ -2310,7 +2310,7 @@ struct sg_proc_leaf {
27476 const struct file_operations * fops;
27477 };
27478
27479 -static struct sg_proc_leaf sg_proc_leaf_arr[] = {
27480 +static const struct sg_proc_leaf sg_proc_leaf_arr[] = {
27481 {"allow_dio", &adio_fops},
27482 {"debug", &debug_fops},
27483 {"def_reserved_size", &dressz_fops},
27484 @@ -2325,7 +2325,7 @@ sg_proc_init(void)
27485 {
27486 int k, mask;
27487 int num_leaves = ARRAY_SIZE(sg_proc_leaf_arr);
27488 - struct sg_proc_leaf * leaf;
27489 + const struct sg_proc_leaf * leaf;
27490
27491 sg_proc_sgp = proc_mkdir(sg_proc_sg_dirname, NULL);
27492 if (!sg_proc_sgp)
27493 diff -urNp linux-2.6.37/drivers/serial/8250_pci.c linux-2.6.37/drivers/serial/8250_pci.c
27494 --- linux-2.6.37/drivers/serial/8250_pci.c 2011-01-04 19:50:19.000000000 -0500
27495 +++ linux-2.6.37/drivers/serial/8250_pci.c 2011-01-17 02:41:01.000000000 -0500
27496 @@ -3782,7 +3782,7 @@ static struct pci_device_id serial_pci_t
27497 PCI_ANY_ID, PCI_ANY_ID,
27498 PCI_CLASS_COMMUNICATION_MULTISERIAL << 8,
27499 0xffff00, pbn_default },
27500 - { 0, }
27501 + { 0, 0, 0, 0, 0, 0, 0 }
27502 };
27503
27504 static struct pci_driver serial_pci_driver = {
27505 diff -urNp linux-2.6.37/drivers/serial/kgdboc.c linux-2.6.37/drivers/serial/kgdboc.c
27506 --- linux-2.6.37/drivers/serial/kgdboc.c 2011-01-04 19:50:19.000000000 -0500
27507 +++ linux-2.6.37/drivers/serial/kgdboc.c 2011-01-17 02:41:01.000000000 -0500
27508 @@ -22,7 +22,8 @@
27509
27510 #define MAX_CONFIG_LEN 40
27511
27512 -static struct kgdb_io kgdboc_io_ops;
27513 +/* cannot be const, see configure_kgdboc() */
27514 +static struct kgdb_io kgdboc_io_ops;
27515
27516 /* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
27517 static int configured = -1;
27518 @@ -293,6 +294,7 @@ static void kgdboc_post_exp_handler(void
27519 kgdboc_restore_input();
27520 }
27521
27522 +/* cannot be const, see configure_kgdboc() */
27523 static struct kgdb_io kgdboc_io_ops = {
27524 .name = "kgdboc",
27525 .read_char = kgdboc_get_char,
27526 diff -urNp linux-2.6.37/drivers/staging/bcm/Bcmchar.c linux-2.6.37/drivers/staging/bcm/Bcmchar.c
27527 --- linux-2.6.37/drivers/staging/bcm/Bcmchar.c 2011-01-04 19:50:19.000000000 -0500
27528 +++ linux-2.6.37/drivers/staging/bcm/Bcmchar.c 2011-01-17 02:41:01.000000000 -0500
27529 @@ -2386,7 +2386,7 @@ static long bcm_char_ioctl(struct file *
27530 }
27531
27532
27533 -static struct file_operations bcm_fops = {
27534 +static const struct file_operations bcm_fops = {
27535 .owner = THIS_MODULE,
27536 .open = bcm_char_open,
27537 .release = bcm_char_release,
27538 diff -urNp linux-2.6.37/drivers/staging/bcm/InterfaceInit.c linux-2.6.37/drivers/staging/bcm/InterfaceInit.c
27539 --- linux-2.6.37/drivers/staging/bcm/InterfaceInit.c 2011-01-04 19:50:19.000000000 -0500
27540 +++ linux-2.6.37/drivers/staging/bcm/InterfaceInit.c 2011-01-17 02:41:01.000000000 -0500
27541 @@ -157,7 +157,7 @@ VOID ConfigureEndPointTypesThroughEEPROM
27542
27543 }
27544
27545 -static struct file_operations usbbcm_fops = {
27546 +static const struct file_operations usbbcm_fops = {
27547 .open = usbbcm_open,
27548 .release = usbbcm_release,
27549 .read = usbbcm_read,
27550 diff -urNp linux-2.6.37/drivers/staging/comedi/comedi_fops.c linux-2.6.37/drivers/staging/comedi/comedi_fops.c
27551 --- linux-2.6.37/drivers/staging/comedi/comedi_fops.c 2011-01-04 19:50:19.000000000 -0500
27552 +++ linux-2.6.37/drivers/staging/comedi/comedi_fops.c 2011-01-17 02:41:01.000000000 -0500
27553 @@ -1426,7 +1426,7 @@ static void comedi_unmap(struct vm_area_
27554 mutex_unlock(&dev->mutex);
27555 }
27556
27557 -static struct vm_operations_struct comedi_vm_ops = {
27558 +static const struct vm_operations_struct comedi_vm_ops = {
27559 .close = comedi_unmap,
27560 };
27561
27562 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
27563 --- linux-2.6.37/drivers/staging/ft1000/ft1000-usb/ft1000_chdev.c 2011-01-04 19:50:19.000000000 -0500
27564 +++ linux-2.6.37/drivers/staging/ft1000/ft1000-usb/ft1000_chdev.c 2011-01-17 02:41:01.000000000 -0500
27565 @@ -69,7 +69,7 @@ int numofmsgbuf = 0;
27566 //
27567 // Table of entry-point routines for char device
27568 //
27569 -static struct file_operations ft1000fops =
27570 +static const struct file_operations ft1000fops =
27571 {
27572 .unlocked_ioctl = ft1000_ChIoctl,
27573 .poll = ft1000_ChPoll,
27574 diff -urNp linux-2.6.37/drivers/staging/go7007/go7007-v4l2.c linux-2.6.37/drivers/staging/go7007/go7007-v4l2.c
27575 --- linux-2.6.37/drivers/staging/go7007/go7007-v4l2.c 2011-01-04 19:50:19.000000000 -0500
27576 +++ linux-2.6.37/drivers/staging/go7007/go7007-v4l2.c 2011-01-17 02:41:01.000000000 -0500
27577 @@ -1672,7 +1672,7 @@ static int go7007_vm_fault(struct vm_are
27578 return 0;
27579 }
27580
27581 -static struct vm_operations_struct go7007_vm_ops = {
27582 +static const struct vm_operations_struct go7007_vm_ops = {
27583 .open = go7007_vm_open,
27584 .close = go7007_vm_close,
27585 .fault = go7007_vm_fault,
27586 diff -urNp linux-2.6.37/drivers/staging/hv/hv.c linux-2.6.37/drivers/staging/hv/hv.c
27587 --- linux-2.6.37/drivers/staging/hv/hv.c 2011-01-04 19:50:19.000000000 -0500
27588 +++ linux-2.6.37/drivers/staging/hv/hv.c 2011-01-17 02:41:01.000000000 -0500
27589 @@ -162,7 +162,7 @@ static u64 HvDoHypercall(u64 Control, vo
27590 u64 outputAddress = (Output) ? virt_to_phys(Output) : 0;
27591 u32 outputAddressHi = outputAddress >> 32;
27592 u32 outputAddressLo = outputAddress & 0xFFFFFFFF;
27593 - volatile void *hypercallPage = gHvContext.HypercallPage;
27594 + volatile void *hypercallPage = ktva_ktla(gHvContext.HypercallPage);
27595
27596 DPRINT_DBG(VMBUS, "Hypercall <control %llx input %p output %p>",
27597 Control, Input, Output);
27598 diff -urNp linux-2.6.37/drivers/staging/msm/msm_fb_bl.c linux-2.6.37/drivers/staging/msm/msm_fb_bl.c
27599 --- linux-2.6.37/drivers/staging/msm/msm_fb_bl.c 2011-01-04 19:50:19.000000000 -0500
27600 +++ linux-2.6.37/drivers/staging/msm/msm_fb_bl.c 2011-01-17 02:41:01.000000000 -0500
27601 @@ -42,7 +42,7 @@ static int msm_fb_bl_update_status(struc
27602 return 0;
27603 }
27604
27605 -static struct backlight_ops msm_fb_bl_ops = {
27606 +static const struct backlight_ops msm_fb_bl_ops = {
27607 .get_brightness = msm_fb_bl_get_brightness,
27608 .update_status = msm_fb_bl_update_status,
27609 };
27610 diff -urNp linux-2.6.37/drivers/staging/olpc_dcon/olpc_dcon.c linux-2.6.37/drivers/staging/olpc_dcon/olpc_dcon.c
27611 --- linux-2.6.37/drivers/staging/olpc_dcon/olpc_dcon.c 2011-01-04 19:50:19.000000000 -0500
27612 +++ linux-2.6.37/drivers/staging/olpc_dcon/olpc_dcon.c 2011-01-17 02:41:01.000000000 -0500
27613 @@ -615,7 +615,7 @@ static struct device_attribute dcon_devi
27614 __ATTR(resumeline, 0644, dcon_resumeline_show, dcon_resumeline_store),
27615 };
27616
27617 -static struct backlight_ops dcon_bl_ops = {
27618 +static const struct backlight_ops dcon_bl_ops = {
27619 .get_brightness = dconbl_get,
27620 .update_status = dconbl_set
27621 };
27622 diff -urNp linux-2.6.37/drivers/staging/phison/phison.c linux-2.6.37/drivers/staging/phison/phison.c
27623 --- linux-2.6.37/drivers/staging/phison/phison.c 2011-01-04 19:50:19.000000000 -0500
27624 +++ linux-2.6.37/drivers/staging/phison/phison.c 2011-01-17 02:41:01.000000000 -0500
27625 @@ -43,7 +43,7 @@ static struct scsi_host_template phison_
27626 ATA_BMDMA_SHT(DRV_NAME),
27627 };
27628
27629 -static struct ata_port_operations phison_ops = {
27630 +static const struct ata_port_operations phison_ops = {
27631 .inherits = &ata_bmdma_port_ops,
27632 .prereset = phison_pre_reset,
27633 };
27634 diff -urNp linux-2.6.37/drivers/staging/pohmelfs/inode.c linux-2.6.37/drivers/staging/pohmelfs/inode.c
27635 --- linux-2.6.37/drivers/staging/pohmelfs/inode.c 2011-01-04 19:50:19.000000000 -0500
27636 +++ linux-2.6.37/drivers/staging/pohmelfs/inode.c 2011-01-17 02:41:01.000000000 -0500
27637 @@ -1848,7 +1848,7 @@ static int pohmelfs_fill_super(struct su
27638 mutex_init(&psb->mcache_lock);
27639 psb->mcache_root = RB_ROOT;
27640 psb->mcache_timeout = msecs_to_jiffies(5000);
27641 - atomic_long_set(&psb->mcache_gen, 0);
27642 + atomic_long_set_unchecked(&psb->mcache_gen, 0);
27643
27644 psb->trans_max_pages = 100;
27645
27646 diff -urNp linux-2.6.37/drivers/staging/pohmelfs/mcache.c linux-2.6.37/drivers/staging/pohmelfs/mcache.c
27647 --- linux-2.6.37/drivers/staging/pohmelfs/mcache.c 2011-01-04 19:50:19.000000000 -0500
27648 +++ linux-2.6.37/drivers/staging/pohmelfs/mcache.c 2011-01-17 02:41:01.000000000 -0500
27649 @@ -121,7 +121,7 @@ struct pohmelfs_mcache *pohmelfs_mcache_
27650 m->data = data;
27651 m->start = start;
27652 m->size = size;
27653 - m->gen = atomic_long_inc_return(&psb->mcache_gen);
27654 + m->gen = atomic_long_inc_return_unchecked(&psb->mcache_gen);
27655
27656 mutex_lock(&psb->mcache_lock);
27657 err = pohmelfs_mcache_insert(psb, m);
27658 diff -urNp linux-2.6.37/drivers/staging/pohmelfs/netfs.h linux-2.6.37/drivers/staging/pohmelfs/netfs.h
27659 --- linux-2.6.37/drivers/staging/pohmelfs/netfs.h 2011-01-04 19:50:19.000000000 -0500
27660 +++ linux-2.6.37/drivers/staging/pohmelfs/netfs.h 2011-01-17 02:41:01.000000000 -0500
27661 @@ -571,7 +571,7 @@ struct pohmelfs_config;
27662 struct pohmelfs_sb {
27663 struct rb_root mcache_root;
27664 struct mutex mcache_lock;
27665 - atomic_long_t mcache_gen;
27666 + atomic_long_unchecked_t mcache_gen;
27667 unsigned long mcache_timeout;
27668
27669 unsigned int idx;
27670 diff -urNp linux-2.6.37/drivers/staging/rtl8192u/ieee80211/proc.c linux-2.6.37/drivers/staging/rtl8192u/ieee80211/proc.c
27671 --- linux-2.6.37/drivers/staging/rtl8192u/ieee80211/proc.c 2011-01-04 19:50:19.000000000 -0500
27672 +++ linux-2.6.37/drivers/staging/rtl8192u/ieee80211/proc.c 2011-01-17 02:41:01.000000000 -0500
27673 @@ -99,7 +99,7 @@ static int crypto_info_open(struct inode
27674 return seq_open(file, &crypto_seq_ops);
27675 }
27676
27677 -static struct file_operations proc_crypto_ops = {
27678 +static const struct file_operations proc_crypto_ops = {
27679 .open = crypto_info_open,
27680 .read = seq_read,
27681 .llseek = seq_lseek,
27682 diff -urNp linux-2.6.37/drivers/staging/samsung-laptop/samsung-laptop.c linux-2.6.37/drivers/staging/samsung-laptop/samsung-laptop.c
27683 --- linux-2.6.37/drivers/staging/samsung-laptop/samsung-laptop.c 2011-01-04 19:50:19.000000000 -0500
27684 +++ linux-2.6.37/drivers/staging/samsung-laptop/samsung-laptop.c 2011-01-17 02:41:01.000000000 -0500
27685 @@ -269,7 +269,7 @@ static int update_status(struct backligh
27686 return 0;
27687 }
27688
27689 -static struct backlight_ops backlight_ops = {
27690 +static const struct backlight_ops backlight_ops = {
27691 .get_brightness = get_brightness,
27692 .update_status = update_status,
27693 };
27694 diff -urNp linux-2.6.37/drivers/staging/spectra/ffsport.c linux-2.6.37/drivers/staging/spectra/ffsport.c
27695 --- linux-2.6.37/drivers/staging/spectra/ffsport.c 2011-01-04 19:50:19.000000000 -0500
27696 +++ linux-2.6.37/drivers/staging/spectra/ffsport.c 2011-01-17 02:41:01.000000000 -0500
27697 @@ -603,7 +603,7 @@ int GLOB_SBD_unlocked_ioctl(struct block
27698 return ret;
27699 }
27700
27701 -static struct block_device_operations GLOB_SBD_ops = {
27702 +static const struct block_device_operations GLOB_SBD_ops = {
27703 .owner = THIS_MODULE,
27704 .open = GLOB_SBD_open,
27705 .release = GLOB_SBD_release,
27706 diff -urNp linux-2.6.37/drivers/staging/vme/devices/vme_user.c linux-2.6.37/drivers/staging/vme/devices/vme_user.c
27707 --- linux-2.6.37/drivers/staging/vme/devices/vme_user.c 2011-01-04 19:50:19.000000000 -0500
27708 +++ linux-2.6.37/drivers/staging/vme/devices/vme_user.c 2011-01-17 02:41:01.000000000 -0500
27709 @@ -137,7 +137,7 @@ static long vme_user_unlocked_ioctl(stru
27710 static int __init vme_user_probe(struct device *, int, int);
27711 static int __exit vme_user_remove(struct device *, int, int);
27712
27713 -static struct file_operations vme_user_fops = {
27714 +static const struct file_operations vme_user_fops = {
27715 .open = vme_user_open,
27716 .release = vme_user_release,
27717 .read = vme_user_read,
27718 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
27719 --- linux-2.6.37/drivers/staging/westbridge/astoria/block/cyasblkdev_block.c 2011-01-04 19:50:19.000000000 -0500
27720 +++ linux-2.6.37/drivers/staging/westbridge/astoria/block/cyasblkdev_block.c 2011-01-17 02:41:01.000000000 -0500
27721 @@ -426,7 +426,7 @@ int cyasblkdev_revalidate_disk(struct ge
27722
27723
27724 /*standard block device driver interface */
27725 -static struct block_device_operations cyasblkdev_bdops = {
27726 +static const struct block_device_operations cyasblkdev_bdops = {
27727 .open = cyasblkdev_blk_open,
27728 .release = cyasblkdev_blk_release,
27729 .ioctl = cyasblkdev_blk_ioctl,
27730 diff -urNp linux-2.6.37/drivers/tty/n_gsm.c linux-2.6.37/drivers/tty/n_gsm.c
27731 --- linux-2.6.37/drivers/tty/n_gsm.c 2011-01-04 19:50:19.000000000 -0500
27732 +++ linux-2.6.37/drivers/tty/n_gsm.c 2011-01-17 02:41:01.000000000 -0500
27733 @@ -1579,7 +1579,7 @@ static struct gsm_dlci *gsm_dlci_alloc(s
27734 return NULL;
27735 spin_lock_init(&dlci->lock);
27736 dlci->fifo = &dlci->_fifo;
27737 - if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
27738 + if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
27739 kfree(dlci);
27740 return NULL;
27741 }
27742 diff -urNp linux-2.6.37/drivers/tty/n_tty.c linux-2.6.37/drivers/tty/n_tty.c
27743 --- linux-2.6.37/drivers/tty/n_tty.c 2011-01-04 19:50:19.000000000 -0500
27744 +++ linux-2.6.37/drivers/tty/n_tty.c 2011-01-17 02:41:01.000000000 -0500
27745 @@ -2116,6 +2116,7 @@ void n_tty_inherit_ops(struct tty_ldisc_
27746 {
27747 *ops = tty_ldisc_N_TTY;
27748 ops->owner = NULL;
27749 - ops->refcount = ops->flags = 0;
27750 + atomic_set(&ops->refcount, 0);
27751 + ops->flags = 0;
27752 }
27753 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
27754 diff -urNp linux-2.6.37/drivers/tty/pty.c linux-2.6.37/drivers/tty/pty.c
27755 --- linux-2.6.37/drivers/tty/pty.c 2011-01-04 19:50:19.000000000 -0500
27756 +++ linux-2.6.37/drivers/tty/pty.c 2011-01-17 02:41:01.000000000 -0500
27757 @@ -700,7 +700,18 @@ out:
27758 return retval;
27759 }
27760
27761 -static struct file_operations ptmx_fops;
27762 +static const struct file_operations ptmx_fops = {
27763 + .llseek = no_llseek,
27764 + .read = tty_read,
27765 + .write = tty_write,
27766 + .poll = tty_poll,
27767 + .unlocked_ioctl = tty_ioctl,
27768 + .compat_ioctl = tty_compat_ioctl,
27769 + .open = ptmx_open,
27770 + .release = tty_release,
27771 + .fasync = tty_fasync,
27772 +};
27773 +
27774
27775 static void __init unix98_pty_init(void)
27776 {
27777 @@ -753,10 +764,6 @@ static void __init unix98_pty_init(void)
27778
27779 register_sysctl_table(pty_root_table);
27780
27781 - /* Now create the /dev/ptmx special device */
27782 - tty_default_fops(&ptmx_fops);
27783 - ptmx_fops.open = ptmx_open;
27784 -
27785 cdev_init(&ptmx_cdev, &ptmx_fops);
27786 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
27787 register_chrdev_region(MKDEV(TTYAUX_MAJOR, 2), 1, "/dev/ptmx") < 0)
27788 diff -urNp linux-2.6.37/drivers/tty/tty_io.c linux-2.6.37/drivers/tty/tty_io.c
27789 --- linux-2.6.37/drivers/tty/tty_io.c 2011-01-04 19:50:19.000000000 -0500
27790 +++ linux-2.6.37/drivers/tty/tty_io.c 2011-01-17 02:41:01.000000000 -0500
27791 @@ -140,21 +140,11 @@ EXPORT_SYMBOL(tty_mutex);
27792 /* Spinlock to protect the tty->tty_files list */
27793 DEFINE_SPINLOCK(tty_files_lock);
27794
27795 -static ssize_t tty_read(struct file *, char __user *, size_t, loff_t *);
27796 -static ssize_t tty_write(struct file *, const char __user *, size_t, loff_t *);
27797 ssize_t redirected_tty_write(struct file *, const char __user *,
27798 size_t, loff_t *);
27799 -static unsigned int tty_poll(struct file *, poll_table *);
27800 static int tty_open(struct inode *, struct file *);
27801 long tty_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
27802 -#ifdef CONFIG_COMPAT
27803 -static long tty_compat_ioctl(struct file *file, unsigned int cmd,
27804 - unsigned long arg);
27805 -#else
27806 -#define tty_compat_ioctl NULL
27807 -#endif
27808 static int __tty_fasync(int fd, struct file *filp, int on);
27809 -static int tty_fasync(int fd, struct file *filp, int on);
27810 static void release_tty(struct tty_struct *tty, int idx);
27811 static void __proc_set_tty(struct task_struct *tsk, struct tty_struct *tty);
27812 static void proc_set_tty(struct task_struct *tsk, struct tty_struct *tty);
27813 @@ -938,7 +928,7 @@ EXPORT_SYMBOL(start_tty);
27814 * read calls may be outstanding in parallel.
27815 */
27816
27817 -static ssize_t tty_read(struct file *file, char __user *buf, size_t count,
27818 +ssize_t tty_read(struct file *file, char __user *buf, size_t count,
27819 loff_t *ppos)
27820 {
27821 int i;
27822 @@ -964,6 +954,8 @@ static ssize_t tty_read(struct file *fil
27823 return i;
27824 }
27825
27826 +EXPORT_SYMBOL(tty_read);
27827 +
27828 void tty_write_unlock(struct tty_struct *tty)
27829 {
27830 mutex_unlock(&tty->atomic_write_lock);
27831 @@ -1113,7 +1105,7 @@ void tty_write_message(struct tty_struct
27832 * write method will not be invoked in parallel for each device.
27833 */
27834
27835 -static ssize_t tty_write(struct file *file, const char __user *buf,
27836 +ssize_t tty_write(struct file *file, const char __user *buf,
27837 size_t count, loff_t *ppos)
27838 {
27839 struct inode *inode = file->f_path.dentry->d_inode;
27840 @@ -1139,6 +1131,8 @@ static ssize_t tty_write(struct file *fi
27841 return ret;
27842 }
27843
27844 +EXPORT_SYMBOL(tty_write);
27845 +
27846 ssize_t redirected_tty_write(struct file *file, const char __user *buf,
27847 size_t count, loff_t *ppos)
27848 {
27849 @@ -1778,6 +1772,8 @@ int tty_release(struct inode *inode, str
27850 return 0;
27851 }
27852
27853 +EXPORT_SYMBOL(tty_release);
27854 +
27855 /**
27856 * tty_open - open a tty device
27857 * @inode: inode of device file
27858 @@ -1969,7 +1965,7 @@ got_driver:
27859 * may be re-entered freely by other callers.
27860 */
27861
27862 -static unsigned int tty_poll(struct file *filp, poll_table *wait)
27863 +unsigned int tty_poll(struct file *filp, poll_table *wait)
27864 {
27865 struct tty_struct *tty = file_tty(filp);
27866 struct tty_ldisc *ld;
27867 @@ -1985,6 +1981,8 @@ static unsigned int tty_poll(struct file
27868 return ret;
27869 }
27870
27871 +EXPORT_SYMBOL(tty_poll);
27872 +
27873 static int __tty_fasync(int fd, struct file *filp, int on)
27874 {
27875 struct tty_struct *tty = file_tty(filp);
27876 @@ -2026,7 +2024,7 @@ out:
27877 return retval;
27878 }
27879
27880 -static int tty_fasync(int fd, struct file *filp, int on)
27881 +int tty_fasync(int fd, struct file *filp, int on)
27882 {
27883 int retval;
27884 tty_lock();
27885 @@ -2035,6 +2033,8 @@ static int tty_fasync(int fd, struct fil
27886 return retval;
27887 }
27888
27889 +EXPORT_SYMBOL(tty_fasync);
27890 +
27891 /**
27892 * tiocsti - fake input character
27893 * @tty: tty to fake input into
27894 @@ -2687,8 +2687,10 @@ long tty_ioctl(struct file *file, unsign
27895 return retval;
27896 }
27897
27898 +EXPORT_SYMBOL(tty_ioctl);
27899 +
27900 #ifdef CONFIG_COMPAT
27901 -static long tty_compat_ioctl(struct file *file, unsigned int cmd,
27902 +long tty_compat_ioctl(struct file *file, unsigned int cmd,
27903 unsigned long arg)
27904 {
27905 struct inode *inode = file->f_dentry->d_inode;
27906 @@ -2712,6 +2714,9 @@ static long tty_compat_ioctl(struct file
27907
27908 return retval;
27909 }
27910 +
27911 +EXPORT_SYMBOL(tty_compat_ioctl);
27912 +
27913 #endif
27914
27915 /*
27916 @@ -3190,11 +3195,6 @@ struct tty_struct *get_current_tty(void)
27917 }
27918 EXPORT_SYMBOL_GPL(get_current_tty);
27919
27920 -void tty_default_fops(struct file_operations *fops)
27921 -{
27922 - *fops = tty_fops;
27923 -}
27924 -
27925 /*
27926 * Initialize the console device. This is called *early*, so
27927 * we can't necessarily depend on lots of kernel help here.
27928 diff -urNp linux-2.6.37/drivers/tty/tty_ldisc.c linux-2.6.37/drivers/tty/tty_ldisc.c
27929 --- linux-2.6.37/drivers/tty/tty_ldisc.c 2011-01-04 19:50:19.000000000 -0500
27930 +++ linux-2.6.37/drivers/tty/tty_ldisc.c 2011-01-17 02:41:01.000000000 -0500
27931 @@ -76,7 +76,7 @@ static void put_ldisc(struct tty_ldisc *
27932 if (atomic_dec_and_lock(&ld->users, &tty_ldisc_lock)) {
27933 struct tty_ldisc_ops *ldo = ld->ops;
27934
27935 - ldo->refcount--;
27936 + atomic_dec(&ldo->refcount);
27937 module_put(ldo->owner);
27938 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
27939
27940 @@ -111,7 +111,7 @@ int tty_register_ldisc(int disc, struct
27941 spin_lock_irqsave(&tty_ldisc_lock, flags);
27942 tty_ldiscs[disc] = new_ldisc;
27943 new_ldisc->num = disc;
27944 - new_ldisc->refcount = 0;
27945 + atomic_set(&new_ldisc->refcount, 0);
27946 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
27947
27948 return ret;
27949 @@ -139,7 +139,7 @@ int tty_unregister_ldisc(int disc)
27950 return -EINVAL;
27951
27952 spin_lock_irqsave(&tty_ldisc_lock, flags);
27953 - if (tty_ldiscs[disc]->refcount)
27954 + if (atomic_read(&tty_ldiscs[disc]->refcount))
27955 ret = -EBUSY;
27956 else
27957 tty_ldiscs[disc] = NULL;
27958 @@ -160,7 +160,7 @@ static struct tty_ldisc_ops *get_ldops(i
27959 if (ldops) {
27960 ret = ERR_PTR(-EAGAIN);
27961 if (try_module_get(ldops->owner)) {
27962 - ldops->refcount++;
27963 + atomic_inc(&ldops->refcount);
27964 ret = ldops;
27965 }
27966 }
27967 @@ -173,7 +173,7 @@ static void put_ldops(struct tty_ldisc_o
27968 unsigned long flags;
27969
27970 spin_lock_irqsave(&tty_ldisc_lock, flags);
27971 - ldops->refcount--;
27972 + atomic_dec(&ldops->refcount);
27973 module_put(ldops->owner);
27974 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
27975 }
27976 diff -urNp linux-2.6.37/drivers/tty/vt/keyboard.c linux-2.6.37/drivers/tty/vt/keyboard.c
27977 --- linux-2.6.37/drivers/tty/vt/keyboard.c 2011-01-04 19:50:19.000000000 -0500
27978 +++ linux-2.6.37/drivers/tty/vt/keyboard.c 2011-01-17 02:41:01.000000000 -0500
27979 @@ -657,6 +657,16 @@ static void k_spec(struct vc_data *vc, u
27980 kbd->kbdmode == VC_MEDIUMRAW) &&
27981 value != KVAL(K_SAK))
27982 return; /* SAK is allowed even in raw mode */
27983 +
27984 +#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
27985 + {
27986 + void *func = fn_handler[value];
27987 + if (func == fn_show_state || func == fn_show_ptregs ||
27988 + func == fn_show_mem)
27989 + return;
27990 + }
27991 +#endif
27992 +
27993 fn_handler[value](vc);
27994 }
27995
27996 @@ -1413,7 +1423,7 @@ static const struct input_device_id kbd_
27997 .evbit = { BIT_MASK(EV_SND) },
27998 },
27999
28000 - { }, /* Terminating entry */
28001 + { 0 }, /* Terminating entry */
28002 };
28003
28004 MODULE_DEVICE_TABLE(input, kbd_ids);
28005 diff -urNp linux-2.6.37/drivers/tty/vt/vt_ioctl.c linux-2.6.37/drivers/tty/vt/vt_ioctl.c
28006 --- linux-2.6.37/drivers/tty/vt/vt_ioctl.c 2011-01-04 19:50:19.000000000 -0500
28007 +++ linux-2.6.37/drivers/tty/vt/vt_ioctl.c 2011-01-17 02:41:01.000000000 -0500
28008 @@ -210,9 +210,6 @@ do_kdsk_ioctl(int cmd, struct kbentry __
28009 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
28010 return -EFAULT;
28011
28012 - if (!capable(CAP_SYS_TTY_CONFIG))
28013 - perm = 0;
28014 -
28015 switch (cmd) {
28016 case KDGKBENT:
28017 key_map = key_maps[s];
28018 @@ -224,6 +221,9 @@ do_kdsk_ioctl(int cmd, struct kbentry __
28019 val = (i ? K_HOLE : K_NOSUCHMAP);
28020 return put_user(val, &user_kbe->kb_value);
28021 case KDSKBENT:
28022 + if (!capable(CAP_SYS_TTY_CONFIG))
28023 + perm = 0;
28024 +
28025 if (!perm)
28026 return -EPERM;
28027 if (!i && v == K_NOSUCHMAP) {
28028 @@ -325,9 +325,6 @@ do_kdgkb_ioctl(int cmd, struct kbsentry
28029 int i, j, k;
28030 int ret;
28031
28032 - if (!capable(CAP_SYS_TTY_CONFIG))
28033 - perm = 0;
28034 -
28035 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
28036 if (!kbs) {
28037 ret = -ENOMEM;
28038 @@ -361,6 +358,9 @@ do_kdgkb_ioctl(int cmd, struct kbsentry
28039 kfree(kbs);
28040 return ((p && *p) ? -EOVERFLOW : 0);
28041 case KDSKBSENT:
28042 + if (!capable(CAP_SYS_TTY_CONFIG))
28043 + perm = 0;
28044 +
28045 if (!perm) {
28046 ret = -EPERM;
28047 goto reterr;
28048 diff -urNp linux-2.6.37/drivers/usb/atm/cxacru.c linux-2.6.37/drivers/usb/atm/cxacru.c
28049 --- linux-2.6.37/drivers/usb/atm/cxacru.c 2011-01-04 19:50:19.000000000 -0500
28050 +++ linux-2.6.37/drivers/usb/atm/cxacru.c 2011-01-17 02:41:01.000000000 -0500
28051 @@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_c
28052 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
28053 if (ret < 2)
28054 return -EINVAL;
28055 - if (index < 0 || index > 0x7f)
28056 + if (index > 0x7f)
28057 return -EINVAL;
28058 pos += tmp;
28059
28060 diff -urNp linux-2.6.37/drivers/usb/atm/usbatm.c linux-2.6.37/drivers/usb/atm/usbatm.c
28061 --- linux-2.6.37/drivers/usb/atm/usbatm.c 2011-01-04 19:50:19.000000000 -0500
28062 +++ linux-2.6.37/drivers/usb/atm/usbatm.c 2011-01-17 02:41:01.000000000 -0500
28063 @@ -332,7 +332,7 @@ static void usbatm_extract_one_cell(stru
28064 if (printk_ratelimit())
28065 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
28066 __func__, vpi, vci);
28067 - atomic_inc(&vcc->stats->rx_err);
28068 + atomic_inc_unchecked(&vcc->stats->rx_err);
28069 return;
28070 }
28071
28072 @@ -360,7 +360,7 @@ static void usbatm_extract_one_cell(stru
28073 if (length > ATM_MAX_AAL5_PDU) {
28074 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
28075 __func__, length, vcc);
28076 - atomic_inc(&vcc->stats->rx_err);
28077 + atomic_inc_unchecked(&vcc->stats->rx_err);
28078 goto out;
28079 }
28080
28081 @@ -369,14 +369,14 @@ static void usbatm_extract_one_cell(stru
28082 if (sarb->len < pdu_length) {
28083 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
28084 __func__, pdu_length, sarb->len, vcc);
28085 - atomic_inc(&vcc->stats->rx_err);
28086 + atomic_inc_unchecked(&vcc->stats->rx_err);
28087 goto out;
28088 }
28089
28090 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
28091 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
28092 __func__, vcc);
28093 - atomic_inc(&vcc->stats->rx_err);
28094 + atomic_inc_unchecked(&vcc->stats->rx_err);
28095 goto out;
28096 }
28097
28098 @@ -386,7 +386,7 @@ static void usbatm_extract_one_cell(stru
28099 if (printk_ratelimit())
28100 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
28101 __func__, length);
28102 - atomic_inc(&vcc->stats->rx_drop);
28103 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28104 goto out;
28105 }
28106
28107 @@ -411,7 +411,7 @@ static void usbatm_extract_one_cell(stru
28108
28109 vcc->push(vcc, skb);
28110
28111 - atomic_inc(&vcc->stats->rx);
28112 + atomic_inc_unchecked(&vcc->stats->rx);
28113 out:
28114 skb_trim(sarb, 0);
28115 }
28116 @@ -614,7 +614,7 @@ static void usbatm_tx_process(unsigned l
28117 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
28118
28119 usbatm_pop(vcc, skb);
28120 - atomic_inc(&vcc->stats->tx);
28121 + atomic_inc_unchecked(&vcc->stats->tx);
28122
28123 skb = skb_dequeue(&instance->sndqueue);
28124 }
28125 @@ -773,11 +773,11 @@ static int usbatm_atm_proc_read(struct a
28126 if (!left--)
28127 return sprintf(page,
28128 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
28129 - atomic_read(&atm_dev->stats.aal5.tx),
28130 - atomic_read(&atm_dev->stats.aal5.tx_err),
28131 - atomic_read(&atm_dev->stats.aal5.rx),
28132 - atomic_read(&atm_dev->stats.aal5.rx_err),
28133 - atomic_read(&atm_dev->stats.aal5.rx_drop));
28134 + atomic_read_unchecked(&atm_dev->stats.aal5.tx),
28135 + atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
28136 + atomic_read_unchecked(&atm_dev->stats.aal5.rx),
28137 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
28138 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
28139
28140 if (!left--) {
28141 if (instance->disconnected)
28142 diff -urNp linux-2.6.37/drivers/usb/class/cdc-acm.c linux-2.6.37/drivers/usb/class/cdc-acm.c
28143 --- linux-2.6.37/drivers/usb/class/cdc-acm.c 2011-01-04 19:50:19.000000000 -0500
28144 +++ linux-2.6.37/drivers/usb/class/cdc-acm.c 2011-01-17 02:41:01.000000000 -0500
28145 @@ -1634,7 +1634,7 @@ static const struct usb_device_id acm_id
28146 { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM,
28147 USB_CDC_ACM_PROTO_AT_CDMA) },
28148
28149 - { }
28150 + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
28151 };
28152
28153 MODULE_DEVICE_TABLE(usb, acm_ids);
28154 diff -urNp linux-2.6.37/drivers/usb/class/cdc-wdm.c linux-2.6.37/drivers/usb/class/cdc-wdm.c
28155 --- linux-2.6.37/drivers/usb/class/cdc-wdm.c 2011-01-04 19:50:19.000000000 -0500
28156 +++ linux-2.6.37/drivers/usb/class/cdc-wdm.c 2011-01-17 02:41:01.000000000 -0500
28157 @@ -342,7 +342,7 @@ static ssize_t wdm_write
28158 goto outnp;
28159 }
28160
28161 - if (!file->f_flags && O_NONBLOCK)
28162 + if (!(file->f_flags & O_NONBLOCK))
28163 r = wait_event_interruptible(desc->wait, !test_bit(WDM_IN_USE,
28164 &desc->flags));
28165 else
28166 diff -urNp linux-2.6.37/drivers/usb/class/usblp.c linux-2.6.37/drivers/usb/class/usblp.c
28167 --- linux-2.6.37/drivers/usb/class/usblp.c 2011-01-04 19:50:19.000000000 -0500
28168 +++ linux-2.6.37/drivers/usb/class/usblp.c 2011-01-17 02:41:01.000000000 -0500
28169 @@ -227,7 +227,7 @@ static const struct quirk_printer_struct
28170 { 0x0482, 0x0010, USBLP_QUIRK_BIDIR }, /* Kyocera Mita FS 820, by zut <kernel@zut.de> */
28171 { 0x04f9, 0x000d, USBLP_QUIRK_BIDIR }, /* Brother Industries, Ltd HL-1440 Laser Printer */
28172 { 0x04b8, 0x0202, USBLP_QUIRK_BAD_CLASS }, /* Seiko Epson Receipt Printer M129C */
28173 - { 0, 0 }
28174 + { 0, 0, 0 }
28175 };
28176
28177 static int usblp_wwait(struct usblp *usblp, int nonblock);
28178 @@ -1398,7 +1398,7 @@ static const struct usb_device_id usblp_
28179 { USB_INTERFACE_INFO(7, 1, 2) },
28180 { USB_INTERFACE_INFO(7, 1, 3) },
28181 { USB_DEVICE(0x04b8, 0x0202) }, /* Seiko Epson Receipt Printer M129C */
28182 - { } /* Terminating entry */
28183 + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } /* Terminating entry */
28184 };
28185
28186 MODULE_DEVICE_TABLE(usb, usblp_ids);
28187 diff -urNp linux-2.6.37/drivers/usb/core/hcd.c linux-2.6.37/drivers/usb/core/hcd.c
28188 --- linux-2.6.37/drivers/usb/core/hcd.c 2011-01-04 19:50:19.000000000 -0500
28189 +++ linux-2.6.37/drivers/usb/core/hcd.c 2011-01-17 02:41:01.000000000 -0500
28190 @@ -2431,7 +2431,7 @@ EXPORT_SYMBOL_GPL(usb_hcd_platform_shutd
28191
28192 #if defined(CONFIG_USB_MON) || defined(CONFIG_USB_MON_MODULE)
28193
28194 -struct usb_mon_operations *mon_ops;
28195 +const struct usb_mon_operations *mon_ops;
28196
28197 /*
28198 * The registration is unlocked.
28199 @@ -2441,7 +2441,7 @@ struct usb_mon_operations *mon_ops;
28200 * symbols from usbcore, usbcore gets referenced and cannot be unloaded first.
28201 */
28202
28203 -int usb_mon_register (struct usb_mon_operations *ops)
28204 +int usb_mon_register (const struct usb_mon_operations *ops)
28205 {
28206
28207 if (mon_ops)
28208 diff -urNp linux-2.6.37/drivers/usb/core/hub.c linux-2.6.37/drivers/usb/core/hub.c
28209 --- linux-2.6.37/drivers/usb/core/hub.c 2011-01-04 19:50:19.000000000 -0500
28210 +++ linux-2.6.37/drivers/usb/core/hub.c 2011-01-17 02:41:01.000000000 -0500
28211 @@ -3461,7 +3461,7 @@ static const struct usb_device_id hub_id
28212 .bDeviceClass = USB_CLASS_HUB},
28213 { .match_flags = USB_DEVICE_ID_MATCH_INT_CLASS,
28214 .bInterfaceClass = USB_CLASS_HUB},
28215 - { } /* Terminating entry */
28216 + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } /* Terminating entry */
28217 };
28218
28219 MODULE_DEVICE_TABLE (usb, hub_id_table);
28220 diff -urNp linux-2.6.37/drivers/usb/core/message.c linux-2.6.37/drivers/usb/core/message.c
28221 --- linux-2.6.37/drivers/usb/core/message.c 2011-01-04 19:50:19.000000000 -0500
28222 +++ linux-2.6.37/drivers/usb/core/message.c 2011-01-17 02:41:01.000000000 -0500
28223 @@ -869,8 +869,8 @@ char *usb_cache_string(struct usb_device
28224 buf = kmalloc(MAX_USB_STRING_SIZE, GFP_NOIO);
28225 if (buf) {
28226 len = usb_string(udev, index, buf, MAX_USB_STRING_SIZE);
28227 - if (len > 0) {
28228 - smallbuf = kmalloc(++len, GFP_NOIO);
28229 + if (len++ > 0) {
28230 + smallbuf = kmalloc(len, GFP_NOIO);
28231 if (!smallbuf)
28232 return buf;
28233 memcpy(smallbuf, buf, len);
28234 diff -urNp linux-2.6.37/drivers/usb/early/ehci-dbgp.c linux-2.6.37/drivers/usb/early/ehci-dbgp.c
28235 --- linux-2.6.37/drivers/usb/early/ehci-dbgp.c 2011-01-04 19:50:19.000000000 -0500
28236 +++ linux-2.6.37/drivers/usb/early/ehci-dbgp.c 2011-01-17 02:41:01.000000000 -0500
28237 @@ -96,6 +96,7 @@ static inline u32 dbgp_len_update(u32 x,
28238 }
28239
28240 #ifdef CONFIG_KGDB
28241 +/* cannot be const, see kgdbdbgp_parse_config */
28242 static struct kgdb_io kgdbdbgp_io_ops;
28243 #define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
28244 #else
28245 @@ -1026,6 +1027,7 @@ static void kgdbdbgp_write_char(u8 chr)
28246 early_dbgp_write(NULL, &chr, 1);
28247 }
28248
28249 +/* cannot be const, see kgdbdbgp_parse_config() */
28250 static struct kgdb_io kgdbdbgp_io_ops = {
28251 .name = "kgdbdbgp",
28252 .read_char = kgdbdbgp_read_char,
28253 diff -urNp linux-2.6.37/drivers/usb/host/ehci-pci.c linux-2.6.37/drivers/usb/host/ehci-pci.c
28254 --- linux-2.6.37/drivers/usb/host/ehci-pci.c 2011-01-04 19:50:19.000000000 -0500
28255 +++ linux-2.6.37/drivers/usb/host/ehci-pci.c 2011-01-17 02:41:01.000000000 -0500
28256 @@ -470,7 +470,7 @@ static const struct pci_device_id pci_id
28257 PCI_DEVICE_CLASS(PCI_CLASS_SERIAL_USB_EHCI, ~0),
28258 .driver_data = (unsigned long) &ehci_pci_hc_driver,
28259 },
28260 - { /* end: all zeroes */ }
28261 + { 0, 0, 0, 0, 0, 0, 0 }
28262 };
28263 MODULE_DEVICE_TABLE(pci, pci_ids);
28264
28265 diff -urNp linux-2.6.37/drivers/usb/host/uhci-hcd.c linux-2.6.37/drivers/usb/host/uhci-hcd.c
28266 --- linux-2.6.37/drivers/usb/host/uhci-hcd.c 2011-01-04 19:50:19.000000000 -0500
28267 +++ linux-2.6.37/drivers/usb/host/uhci-hcd.c 2011-01-17 02:41:01.000000000 -0500
28268 @@ -948,7 +948,7 @@ static const struct pci_device_id uhci_p
28269 /* handle any USB UHCI controller */
28270 PCI_DEVICE_CLASS(PCI_CLASS_SERIAL_USB_UHCI, ~0),
28271 .driver_data = (unsigned long) &uhci_driver,
28272 - }, { /* end: all zeroes */ }
28273 + }, { 0, 0, 0, 0, 0, 0, 0 }
28274 };
28275
28276 MODULE_DEVICE_TABLE(pci, uhci_pci_ids);
28277 diff -urNp linux-2.6.37/drivers/usb/mon/mon_main.c linux-2.6.37/drivers/usb/mon/mon_main.c
28278 --- linux-2.6.37/drivers/usb/mon/mon_main.c 2011-01-04 19:50:19.000000000 -0500
28279 +++ linux-2.6.37/drivers/usb/mon/mon_main.c 2011-01-17 02:41:01.000000000 -0500
28280 @@ -238,7 +238,7 @@ static struct notifier_block mon_nb = {
28281 /*
28282 * Ops
28283 */
28284 -static struct usb_mon_operations mon_ops_0 = {
28285 +static const struct usb_mon_operations mon_ops_0 = {
28286 .urb_submit = mon_submit,
28287 .urb_submit_error = mon_submit_error,
28288 .urb_complete = mon_complete,
28289 diff -urNp linux-2.6.37/drivers/usb/storage/debug.h linux-2.6.37/drivers/usb/storage/debug.h
28290 --- linux-2.6.37/drivers/usb/storage/debug.h 2011-01-04 19:50:19.000000000 -0500
28291 +++ linux-2.6.37/drivers/usb/storage/debug.h 2011-01-17 02:41:01.000000000 -0500
28292 @@ -54,9 +54,9 @@ void usb_stor_show_sense( unsigned char
28293 #define US_DEBUGPX(x...) printk( x )
28294 #define US_DEBUG(x) x
28295 #else
28296 -#define US_DEBUGP(x...)
28297 -#define US_DEBUGPX(x...)
28298 -#define US_DEBUG(x)
28299 +#define US_DEBUGP(x...) do {} while (0)
28300 +#define US_DEBUGPX(x...) do {} while (0)
28301 +#define US_DEBUG(x) do {} while (0)
28302 #endif
28303
28304 #endif
28305 diff -urNp linux-2.6.37/drivers/usb/storage/usb.c linux-2.6.37/drivers/usb/storage/usb.c
28306 --- linux-2.6.37/drivers/usb/storage/usb.c 2011-01-04 19:50:19.000000000 -0500
28307 +++ linux-2.6.37/drivers/usb/storage/usb.c 2011-01-17 02:41:01.000000000 -0500
28308 @@ -122,7 +122,7 @@ MODULE_PARM_DESC(quirks, "supplemental l
28309
28310 static struct us_unusual_dev us_unusual_dev_list[] = {
28311 # include "unusual_devs.h"
28312 - { } /* Terminating entry */
28313 + { NULL, NULL, 0, 0, NULL } /* Terminating entry */
28314 };
28315
28316 #undef UNUSUAL_DEV
28317 diff -urNp linux-2.6.37/drivers/usb/storage/usual-tables.c linux-2.6.37/drivers/usb/storage/usual-tables.c
28318 --- linux-2.6.37/drivers/usb/storage/usual-tables.c 2011-01-04 19:50:19.000000000 -0500
28319 +++ linux-2.6.37/drivers/usb/storage/usual-tables.c 2011-01-17 02:41:01.000000000 -0500
28320 @@ -48,7 +48,7 @@
28321
28322 struct usb_device_id usb_storage_usb_ids[] = {
28323 # include "unusual_devs.h"
28324 - { } /* Terminating entry */
28325 + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } /* Terminating entry */
28326 };
28327 EXPORT_SYMBOL_GPL(usb_storage_usb_ids);
28328
28329 diff -urNp linux-2.6.37/drivers/vhost/vhost.c linux-2.6.37/drivers/vhost/vhost.c
28330 --- linux-2.6.37/drivers/vhost/vhost.c 2011-01-04 19:50:19.000000000 -0500
28331 +++ linux-2.6.37/drivers/vhost/vhost.c 2011-01-17 02:41:01.000000000 -0500
28332 @@ -560,7 +560,7 @@ static int init_used(struct vhost_virtqu
28333 return get_user(vq->last_used_idx, &used->idx);
28334 }
28335
28336 -static long vhost_set_vring(struct vhost_dev *d, int ioctl, void __user *argp)
28337 +static long vhost_set_vring(struct vhost_dev *d, unsigned int ioctl, void __user *argp)
28338 {
28339 struct file *eventfp, *filep = NULL,
28340 *pollstart = NULL, *pollstop = NULL;
28341 diff -urNp linux-2.6.37/drivers/video/atmel_lcdfb.c linux-2.6.37/drivers/video/atmel_lcdfb.c
28342 --- linux-2.6.37/drivers/video/atmel_lcdfb.c 2011-01-04 19:50:19.000000000 -0500
28343 +++ linux-2.6.37/drivers/video/atmel_lcdfb.c 2011-01-17 02:41:01.000000000 -0500
28344 @@ -111,7 +111,7 @@ static int atmel_bl_get_brightness(struc
28345 return lcdc_readl(sinfo, ATMEL_LCDC_CONTRAST_VAL);
28346 }
28347
28348 -static struct backlight_ops atmel_lcdc_bl_ops = {
28349 +static const struct backlight_ops atmel_lcdc_bl_ops = {
28350 .update_status = atmel_bl_update_status,
28351 .get_brightness = atmel_bl_get_brightness,
28352 };
28353 diff -urNp linux-2.6.37/drivers/video/aty/aty128fb.c linux-2.6.37/drivers/video/aty/aty128fb.c
28354 --- linux-2.6.37/drivers/video/aty/aty128fb.c 2011-01-04 19:50:19.000000000 -0500
28355 +++ linux-2.6.37/drivers/video/aty/aty128fb.c 2011-01-17 02:41:01.000000000 -0500
28356 @@ -1786,7 +1786,7 @@ static int aty128_bl_get_brightness(stru
28357 return bd->props.brightness;
28358 }
28359
28360 -static struct backlight_ops aty128_bl_data = {
28361 +static const struct backlight_ops aty128_bl_data = {
28362 .get_brightness = aty128_bl_get_brightness,
28363 .update_status = aty128_bl_update_status,
28364 };
28365 diff -urNp linux-2.6.37/drivers/video/aty/atyfb_base.c linux-2.6.37/drivers/video/aty/atyfb_base.c
28366 --- linux-2.6.37/drivers/video/aty/atyfb_base.c 2011-01-04 19:50:19.000000000 -0500
28367 +++ linux-2.6.37/drivers/video/aty/atyfb_base.c 2011-01-17 02:41:01.000000000 -0500
28368 @@ -2221,7 +2221,7 @@ static int aty_bl_get_brightness(struct
28369 return bd->props.brightness;
28370 }
28371
28372 -static struct backlight_ops aty_bl_data = {
28373 +static const struct backlight_ops aty_bl_data = {
28374 .get_brightness = aty_bl_get_brightness,
28375 .update_status = aty_bl_update_status,
28376 };
28377 diff -urNp linux-2.6.37/drivers/video/aty/radeon_backlight.c linux-2.6.37/drivers/video/aty/radeon_backlight.c
28378 --- linux-2.6.37/drivers/video/aty/radeon_backlight.c 2011-01-04 19:50:19.000000000 -0500
28379 +++ linux-2.6.37/drivers/video/aty/radeon_backlight.c 2011-01-17 02:41:01.000000000 -0500
28380 @@ -128,7 +128,7 @@ static int radeon_bl_get_brightness(stru
28381 return bd->props.brightness;
28382 }
28383
28384 -static struct backlight_ops radeon_bl_data = {
28385 +static const struct backlight_ops radeon_bl_data = {
28386 .get_brightness = radeon_bl_get_brightness,
28387 .update_status = radeon_bl_update_status,
28388 };
28389 diff -urNp linux-2.6.37/drivers/video/backlight/88pm860x_bl.c linux-2.6.37/drivers/video/backlight/88pm860x_bl.c
28390 --- linux-2.6.37/drivers/video/backlight/88pm860x_bl.c 2011-01-04 19:50:19.000000000 -0500
28391 +++ linux-2.6.37/drivers/video/backlight/88pm860x_bl.c 2011-01-17 02:41:01.000000000 -0500
28392 @@ -155,7 +155,7 @@ out:
28393 return -EINVAL;
28394 }
28395
28396 -static struct backlight_ops pm860x_backlight_ops = {
28397 +static const struct backlight_ops pm860x_backlight_ops = {
28398 .options = BL_CORE_SUSPENDRESUME,
28399 .update_status = pm860x_backlight_update_status,
28400 .get_brightness = pm860x_backlight_get_brightness,
28401 diff -urNp linux-2.6.37/drivers/video/backlight/max8925_bl.c linux-2.6.37/drivers/video/backlight/max8925_bl.c
28402 --- linux-2.6.37/drivers/video/backlight/max8925_bl.c 2011-01-04 19:50:19.000000000 -0500
28403 +++ linux-2.6.37/drivers/video/backlight/max8925_bl.c 2011-01-17 02:41:01.000000000 -0500
28404 @@ -92,7 +92,7 @@ static int max8925_backlight_get_brightn
28405 return ret;
28406 }
28407
28408 -static struct backlight_ops max8925_backlight_ops = {
28409 +static const struct backlight_ops max8925_backlight_ops = {
28410 .options = BL_CORE_SUSPENDRESUME,
28411 .update_status = max8925_backlight_update_status,
28412 .get_brightness = max8925_backlight_get_brightness,
28413 diff -urNp linux-2.6.37/drivers/video/fbcmap.c linux-2.6.37/drivers/video/fbcmap.c
28414 --- linux-2.6.37/drivers/video/fbcmap.c 2011-01-04 19:50:19.000000000 -0500
28415 +++ linux-2.6.37/drivers/video/fbcmap.c 2011-01-17 02:41:01.000000000 -0500
28416 @@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user
28417 rc = -ENODEV;
28418 goto out;
28419 }
28420 - if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
28421 - !info->fbops->fb_setcmap)) {
28422 + if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
28423 rc = -EINVAL;
28424 goto out1;
28425 }
28426 diff -urNp linux-2.6.37/drivers/video/fbmem.c linux-2.6.37/drivers/video/fbmem.c
28427 --- linux-2.6.37/drivers/video/fbmem.c 2011-01-04 19:50:19.000000000 -0500
28428 +++ linux-2.6.37/drivers/video/fbmem.c 2011-01-17 02:41:01.000000000 -0500
28429 @@ -403,7 +403,7 @@ static void fb_do_show_logo(struct fb_in
28430 image->dx += image->width + 8;
28431 }
28432 } else if (rotate == FB_ROTATE_UD) {
28433 - for (x = 0; x < num && image->dx >= 0; x++) {
28434 + for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
28435 info->fbops->fb_imageblit(info, image);
28436 image->dx -= image->width + 8;
28437 }
28438 @@ -415,7 +415,7 @@ static void fb_do_show_logo(struct fb_in
28439 image->dy += image->height + 8;
28440 }
28441 } else if (rotate == FB_ROTATE_CCW) {
28442 - for (x = 0; x < num && image->dy >= 0; x++) {
28443 + for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
28444 info->fbops->fb_imageblit(info, image);
28445 image->dy -= image->height + 8;
28446 }
28447 @@ -1101,7 +1101,7 @@ static long do_fb_ioctl(struct fb_info *
28448 return -EFAULT;
28449 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
28450 return -EINVAL;
28451 - if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
28452 + if (con2fb.framebuffer >= FB_MAX)
28453 return -EINVAL;
28454 if (!registered_fb[con2fb.framebuffer])
28455 request_module("fb%d", con2fb.framebuffer);
28456 diff -urNp linux-2.6.37/drivers/video/fbmon.c linux-2.6.37/drivers/video/fbmon.c
28457 --- linux-2.6.37/drivers/video/fbmon.c 2011-01-04 19:50:19.000000000 -0500
28458 +++ linux-2.6.37/drivers/video/fbmon.c 2011-01-17 02:41:01.000000000 -0500
28459 @@ -46,7 +46,7 @@
28460 #ifdef DEBUG
28461 #define DPRINTK(fmt, args...) printk(fmt,## args)
28462 #else
28463 -#define DPRINTK(fmt, args...)
28464 +#define DPRINTK(fmt, args...) do {} while (0)
28465 #endif
28466
28467 #define FBMON_FIX_HEADER 1
28468 diff -urNp linux-2.6.37/drivers/video/i810/i810_accel.c linux-2.6.37/drivers/video/i810/i810_accel.c
28469 --- linux-2.6.37/drivers/video/i810/i810_accel.c 2011-01-04 19:50:19.000000000 -0500
28470 +++ linux-2.6.37/drivers/video/i810/i810_accel.c 2011-01-17 02:41:01.000000000 -0500
28471 @@ -73,6 +73,7 @@ static inline int wait_for_space(struct
28472 }
28473 }
28474 printk("ringbuffer lockup!!!\n");
28475 + printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
28476 i810_report_error(mmio);
28477 par->dev_flags |= LOCKUP;
28478 info->pixmap.scan_align = 1;
28479 diff -urNp linux-2.6.37/drivers/video/i810/i810_main.c linux-2.6.37/drivers/video/i810/i810_main.c
28480 --- linux-2.6.37/drivers/video/i810/i810_main.c 2011-01-04 19:50:19.000000000 -0500
28481 +++ linux-2.6.37/drivers/video/i810/i810_main.c 2011-01-17 02:41:01.000000000 -0500
28482 @@ -120,7 +120,7 @@ static struct pci_device_id i810fb_pci_t
28483 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 4 },
28484 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82815_CGC,
28485 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 5 },
28486 - { 0 },
28487 + { 0, 0, 0, 0, 0, 0, 0 },
28488 };
28489
28490 static struct pci_driver i810fb_driver = {
28491 diff -urNp linux-2.6.37/drivers/video/modedb.c linux-2.6.37/drivers/video/modedb.c
28492 --- linux-2.6.37/drivers/video/modedb.c 2011-01-04 19:50:19.000000000 -0500
28493 +++ linux-2.6.37/drivers/video/modedb.c 2011-01-17 02:41:01.000000000 -0500
28494 @@ -40,240 +40,240 @@ static const struct fb_videomode modedb[
28495 {
28496 /* 640x400 @ 70 Hz, 31.5 kHz hsync */
28497 NULL, 70, 640, 400, 39721, 40, 24, 39, 9, 96, 2,
28498 - 0, FB_VMODE_NONINTERLACED
28499 + 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
28500 }, {
28501 /* 640x480 @ 60 Hz, 31.5 kHz hsync */
28502 NULL, 60, 640, 480, 39721, 40, 24, 32, 11, 96, 2,
28503 - 0, FB_VMODE_NONINTERLACED
28504 + 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
28505 }, {
28506 /* 800x600 @ 56 Hz, 35.15 kHz hsync */
28507 NULL, 56, 800, 600, 27777, 128, 24, 22, 1, 72, 2,
28508 - 0, FB_VMODE_NONINTERLACED
28509 + 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
28510 }, {
28511 /* 1024x768 @ 87 Hz interlaced, 35.5 kHz hsync */
28512 NULL, 87, 1024, 768, 22271, 56, 24, 33, 8, 160, 8,
28513 - 0, FB_VMODE_INTERLACED
28514 + 0, FB_VMODE_INTERLACED, FB_MODE_IS_UNKNOWN
28515 }, {
28516 /* 640x400 @ 85 Hz, 37.86 kHz hsync */
28517 NULL, 85, 640, 400, 31746, 96, 32, 41, 1, 64, 3,
28518 - FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
28519 + FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
28520 }, {
28521 /* 640x480 @ 72 Hz, 36.5 kHz hsync */
28522 NULL, 72, 640, 480, 31746, 144, 40, 30, 8, 40, 3,
28523 - 0, FB_VMODE_NONINTERLACED
28524 + 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
28525 }, {
28526 /* 640x480 @ 75 Hz, 37.50 kHz hsync */
28527 NULL, 75, 640, 480, 31746, 120, 16, 16, 1, 64, 3,
28528 - 0, FB_VMODE_NONINTERLACED
28529 + 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
28530 }, {
28531 /* 800x600 @ 60 Hz, 37.8 kHz hsync */
28532 NULL, 60, 800, 600, 25000, 88, 40, 23, 1, 128, 4,
28533 - FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
28534 + FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
28535 }, {
28536 /* 640x480 @ 85 Hz, 43.27 kHz hsync */
28537 NULL, 85, 640, 480, 27777, 80, 56, 25, 1, 56, 3,
28538 - 0, FB_VMODE_NONINTERLACED
28539 + 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
28540 }, {
28541 /* 1152x864 @ 89 Hz interlaced, 44 kHz hsync */
28542 NULL, 89, 1152, 864, 15384, 96, 16, 110, 1, 216, 10,
28543 - 0, FB_VMODE_INTERLACED
28544 + 0, FB_VMODE_INTERLACED, FB_MODE_IS_UNKNOWN
28545 }, {
28546 /* 800x600 @ 72 Hz, 48.0 kHz hsync */
28547 NULL, 72, 800, 600, 20000, 64, 56, 23, 37, 120, 6,
28548 - FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
28549 + FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
28550 }, {
28551 /* 1024x768 @ 60 Hz, 48.4 kHz hsync */
28552 NULL, 60, 1024, 768, 15384, 168, 8, 29, 3, 144, 6,
28553 - 0, FB_VMODE_NONINTERLACED
28554 + 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
28555 }, {
28556 /* 640x480 @ 100 Hz, 53.01 kHz hsync */
28557 NULL, 100, 640, 480, 21834, 96, 32, 36, 8, 96, 6,
28558 - 0, FB_VMODE_NONINTERLACED
28559 + 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
28560 }, {
28561 /* 1152x864 @ 60 Hz, 53.5 kHz hsync */
28562 NULL, 60, 1152, 864, 11123, 208, 64, 16, 4, 256, 8,
28563 - 0, FB_VMODE_NONINTERLACED
28564 + 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
28565 }, {
28566 /* 800x600 @ 85 Hz, 55.84 kHz hsync */
28567 NULL, 85, 800, 600, 16460, 160, 64, 36, 16, 64, 5,
28568 - 0, FB_VMODE_NONINTERLACED
28569 + 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
28570 }, {
28571 /* 1024x768 @ 70 Hz, 56.5 kHz hsync */
28572 NULL, 70, 1024, 768, 13333, 144, 24, 29, 3, 136, 6,
28573 - 0, FB_VMODE_NONINTERLACED
28574 + 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
28575 }, {
28576 /* 1280x1024 @ 87 Hz interlaced, 51 kHz hsync */
28577 NULL, 87, 1280, 1024, 12500, 56, 16, 128, 1, 216, 12,
28578 - 0, FB_VMODE_INTERLACED
28579 + 0, FB_VMODE_INTERLACED, FB_MODE_IS_UNKNOWN
28580 }, {
28581 /* 800x600 @ 100 Hz, 64.02 kHz hsync */
28582 NULL, 100, 800, 600, 14357, 160, 64, 30, 4, 64, 6,
28583 - 0, FB_VMODE_NONINTERLACED
28584 + 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
28585 }, {
28586 /* 1024x768 @ 76 Hz, 62.5 kHz hsync */
28587 NULL, 76, 1024, 768, 11764, 208, 8, 36, 16, 120, 3,
28588 - 0, FB_VMODE_NONINTERLACED
28589 + 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
28590 }, {
28591 /* 1152x864 @ 70 Hz, 62.4 kHz hsync */
28592 NULL, 70, 1152, 864, 10869, 106, 56, 20, 1, 160, 10,
28593 - 0, FB_VMODE_NONINTERLACED
28594 + 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
28595 }, {
28596 /* 1280x1024 @ 61 Hz, 64.2 kHz hsync */
28597 NULL, 61, 1280, 1024, 9090, 200, 48, 26, 1, 184, 3,
28598 - 0, FB_VMODE_NONINTERLACED
28599 + 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
28600 }, {
28601 /* 1400x1050 @ 60Hz, 63.9 kHz hsync */
28602 NULL, 60, 1400, 1050, 9259, 136, 40, 13, 1, 112, 3,
28603 - 0, FB_VMODE_NONINTERLACED
28604 + 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
28605 }, {
28606 /* 1400x1050 @ 75,107 Hz, 82,392 kHz +hsync +vsync*/
28607 NULL, 75, 1400, 1050, 7190, 120, 56, 23, 10, 112, 13,
28608 - FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
28609 + FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
28610 }, {
28611 /* 1400x1050 @ 60 Hz, ? kHz +hsync +vsync*/
28612 NULL, 60, 1400, 1050, 9259, 128, 40, 12, 0, 112, 3,
28613 - FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
28614 + FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
28615 }, {
28616 /* 1024x768 @ 85 Hz, 70.24 kHz hsync */
28617 NULL, 85, 1024, 768, 10111, 192, 32, 34, 14, 160, 6,
28618 - 0, FB_VMODE_NONINTERLACED
28619 + 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
28620 }, {
28621 /* 1152x864 @ 78 Hz, 70.8 kHz hsync */
28622 NULL, 78, 1152, 864, 9090, 228, 88, 32, 0, 84, 12,
28623 - 0, FB_VMODE_NONINTERLACED
28624 + 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
28625 }, {
28626 /* 1280x1024 @ 70 Hz, 74.59 kHz hsync */
28627 NULL, 70, 1280, 1024, 7905, 224, 32, 28, 8, 160, 8,
28628 - 0, FB_VMODE_NONINTERLACED
28629 + 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
28630 }, {
28631 /* 1600x1200 @ 60Hz, 75.00 kHz hsync */
28632 NULL, 60, 1600, 1200, 6172, 304, 64, 46, 1, 192, 3,
28633 - FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
28634 + FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
28635 }, {
28636 /* 1152x864 @ 84 Hz, 76.0 kHz hsync */
28637 NULL, 84, 1152, 864, 7407, 184, 312, 32, 0, 128, 12,
28638 - 0, FB_VMODE_NONINTERLACED
28639 + 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
28640 }, {
28641 /* 1280x1024 @ 74 Hz, 78.85 kHz hsync */
28642 NULL, 74, 1280, 1024, 7407, 256, 32, 34, 3, 144, 3,
28643 - 0, FB_VMODE_NONINTERLACED
28644 + 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
28645 }, {
28646 /* 1024x768 @ 100Hz, 80.21 kHz hsync */
28647 NULL, 100, 1024, 768, 8658, 192, 32, 21, 3, 192, 10,
28648 - 0, FB_VMODE_NONINTERLACED
28649 + 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
28650 }, {
28651 /* 1280x1024 @ 76 Hz, 81.13 kHz hsync */
28652 NULL, 76, 1280, 1024, 7407, 248, 32, 34, 3, 104, 3,
28653 - 0, FB_VMODE_NONINTERLACED
28654 + 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
28655 }, {
28656 /* 1600x1200 @ 70 Hz, 87.50 kHz hsync */
28657 NULL, 70, 1600, 1200, 5291, 304, 64, 46, 1, 192, 3,
28658 - 0, FB_VMODE_NONINTERLACED
28659 + 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
28660 }, {
28661 /* 1152x864 @ 100 Hz, 89.62 kHz hsync */
28662 NULL, 100, 1152, 864, 7264, 224, 32, 17, 2, 128, 19,
28663 - 0, FB_VMODE_NONINTERLACED
28664 + 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
28665 }, {
28666 /* 1280x1024 @ 85 Hz, 91.15 kHz hsync */
28667 NULL, 85, 1280, 1024, 6349, 224, 64, 44, 1, 160, 3,
28668 - FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
28669 + FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
28670 }, {
28671 /* 1600x1200 @ 75 Hz, 93.75 kHz hsync */
28672 NULL, 75, 1600, 1200, 4938, 304, 64, 46, 1, 192, 3,
28673 - FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
28674 + FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
28675 }, {
28676 /* 1680x1050 @ 60 Hz, 65.191 kHz hsync */
28677 NULL, 60, 1680, 1050, 6848, 280, 104, 30, 3, 176, 6,
28678 - FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
28679 + FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
28680 }, {
28681 /* 1600x1200 @ 85 Hz, 105.77 kHz hsync */
28682 NULL, 85, 1600, 1200, 4545, 272, 16, 37, 4, 192, 3,
28683 - FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
28684 + FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
28685 }, {
28686 /* 1280x1024 @ 100 Hz, 107.16 kHz hsync */
28687 NULL, 100, 1280, 1024, 5502, 256, 32, 26, 7, 128, 15,
28688 - 0, FB_VMODE_NONINTERLACED
28689 + 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
28690 }, {
28691 /* 1800x1440 @ 64Hz, 96.15 kHz hsync */
28692 NULL, 64, 1800, 1440, 4347, 304, 96, 46, 1, 192, 3,
28693 - FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
28694 + FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
28695 }, {
28696 /* 1800x1440 @ 70Hz, 104.52 kHz hsync */
28697 NULL, 70, 1800, 1440, 4000, 304, 96, 46, 1, 192, 3,
28698 - FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
28699 + FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
28700 }, {
28701 /* 512x384 @ 78 Hz, 31.50 kHz hsync */
28702 NULL, 78, 512, 384, 49603, 48, 16, 16, 1, 64, 3,
28703 - 0, FB_VMODE_NONINTERLACED
28704 + 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
28705 }, {
28706 /* 512x384 @ 85 Hz, 34.38 kHz hsync */
28707 NULL, 85, 512, 384, 45454, 48, 16, 16, 1, 64, 3,
28708 - 0, FB_VMODE_NONINTERLACED
28709 + 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
28710 }, {
28711 /* 320x200 @ 70 Hz, 31.5 kHz hsync, 8:5 aspect ratio */
28712 NULL, 70, 320, 200, 79440, 16, 16, 20, 4, 48, 1,
28713 - 0, FB_VMODE_DOUBLE
28714 + 0, FB_VMODE_DOUBLE, FB_MODE_IS_UNKNOWN
28715 }, {
28716 /* 320x240 @ 60 Hz, 31.5 kHz hsync, 4:3 aspect ratio */
28717 NULL, 60, 320, 240, 79440, 16, 16, 16, 5, 48, 1,
28718 - 0, FB_VMODE_DOUBLE
28719 + 0, FB_VMODE_DOUBLE, FB_MODE_IS_UNKNOWN
28720 }, {
28721 /* 320x240 @ 72 Hz, 36.5 kHz hsync */
28722 NULL, 72, 320, 240, 63492, 16, 16, 16, 4, 48, 2,
28723 - 0, FB_VMODE_DOUBLE
28724 + 0, FB_VMODE_DOUBLE, FB_MODE_IS_UNKNOWN
28725 }, {
28726 /* 400x300 @ 56 Hz, 35.2 kHz hsync, 4:3 aspect ratio */
28727 NULL, 56, 400, 300, 55555, 64, 16, 10, 1, 32, 1,
28728 - 0, FB_VMODE_DOUBLE
28729 + 0, FB_VMODE_DOUBLE, FB_MODE_IS_UNKNOWN
28730 }, {
28731 /* 400x300 @ 60 Hz, 37.8 kHz hsync */
28732 NULL, 60, 400, 300, 50000, 48, 16, 11, 1, 64, 2,
28733 - 0, FB_VMODE_DOUBLE
28734 + 0, FB_VMODE_DOUBLE, FB_MODE_IS_UNKNOWN
28735 }, {
28736 /* 400x300 @ 72 Hz, 48.0 kHz hsync */
28737 NULL, 72, 400, 300, 40000, 32, 24, 11, 19, 64, 3,
28738 - 0, FB_VMODE_DOUBLE
28739 + 0, FB_VMODE_DOUBLE, FB_MODE_IS_UNKNOWN
28740 }, {
28741 /* 480x300 @ 56 Hz, 35.2 kHz hsync, 8:5 aspect ratio */
28742 NULL, 56, 480, 300, 46176, 80, 16, 10, 1, 40, 1,
28743 - 0, FB_VMODE_DOUBLE
28744 + 0, FB_VMODE_DOUBLE, FB_MODE_IS_UNKNOWN
28745 }, {
28746 /* 480x300 @ 60 Hz, 37.8 kHz hsync */
28747 NULL, 60, 480, 300, 41858, 56, 16, 11, 1, 80, 2,
28748 - 0, FB_VMODE_DOUBLE
28749 + 0, FB_VMODE_DOUBLE, FB_MODE_IS_UNKNOWN
28750 }, {
28751 /* 480x300 @ 63 Hz, 39.6 kHz hsync */
28752 NULL, 63, 480, 300, 40000, 56, 16, 11, 1, 80, 2,
28753 - 0, FB_VMODE_DOUBLE
28754 + 0, FB_VMODE_DOUBLE, FB_MODE_IS_UNKNOWN
28755 }, {
28756 /* 480x300 @ 72 Hz, 48.0 kHz hsync */
28757 NULL, 72, 480, 300, 33386, 40, 24, 11, 19, 80, 3,
28758 - 0, FB_VMODE_DOUBLE
28759 + 0, FB_VMODE_DOUBLE, FB_MODE_IS_UNKNOWN
28760 }, {
28761 /* 1920x1200 @ 60 Hz, 74.5 Khz hsync */
28762 NULL, 60, 1920, 1200, 5177, 128, 336, 1, 38, 208, 3,
28763 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
28764 - FB_VMODE_NONINTERLACED
28765 + FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
28766 }, {
28767 /* 1152x768, 60 Hz, PowerBook G4 Titanium I and II */
28768 NULL, 60, 1152, 768, 14047, 158, 26, 29, 3, 136, 6,
28769 - FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
28770 + FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
28771 }, {
28772 /* 1366x768, 60 Hz, 47.403 kHz hsync, WXGA 16:9 aspect ratio */
28773 NULL, 60, 1366, 768, 13806, 120, 10, 14, 3, 32, 5,
28774 - 0, FB_VMODE_NONINTERLACED
28775 + 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
28776 }, {
28777 /* 1280x800, 60 Hz, 47.403 kHz hsync, WXGA 16:10 aspect ratio */
28778 NULL, 60, 1280, 800, 12048, 200, 64, 24, 1, 136, 3,
28779 - 0, FB_VMODE_NONINTERLACED
28780 + 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
28781 }, {
28782 /* 720x576i @ 50 Hz, 15.625 kHz hsync (PAL RGB) */
28783 NULL, 50, 720, 576, 74074, 64, 16, 39, 5, 64, 5,
28784 - 0, FB_VMODE_INTERLACED
28785 + 0, FB_VMODE_INTERLACED, FB_MODE_IS_UNKNOWN
28786 }, {
28787 /* 800x520i @ 50 Hz, 15.625 kHz hsync (PAL RGB) */
28788 NULL, 50, 800, 520, 58823, 144, 64, 72, 28, 80, 5,
28789 - 0, FB_VMODE_INTERLACED
28790 + 0, FB_VMODE_INTERLACED, FB_MODE_IS_UNKNOWN
28791 },
28792 };
28793
28794 diff -urNp linux-2.6.37/drivers/video/nvidia/nv_backlight.c linux-2.6.37/drivers/video/nvidia/nv_backlight.c
28795 --- linux-2.6.37/drivers/video/nvidia/nv_backlight.c 2011-01-04 19:50:19.000000000 -0500
28796 +++ linux-2.6.37/drivers/video/nvidia/nv_backlight.c 2011-01-17 02:41:01.000000000 -0500
28797 @@ -87,7 +87,7 @@ static int nvidia_bl_get_brightness(stru
28798 return bd->props.brightness;
28799 }
28800
28801 -static struct backlight_ops nvidia_bl_ops = {
28802 +static const struct backlight_ops nvidia_bl_ops = {
28803 .get_brightness = nvidia_bl_get_brightness,
28804 .update_status = nvidia_bl_update_status,
28805 };
28806 diff -urNp linux-2.6.37/drivers/video/omap2/displays/panel-taal.c linux-2.6.37/drivers/video/omap2/displays/panel-taal.c
28807 --- linux-2.6.37/drivers/video/omap2/displays/panel-taal.c 2011-01-04 19:50:19.000000000 -0500
28808 +++ linux-2.6.37/drivers/video/omap2/displays/panel-taal.c 2011-01-17 02:41:01.000000000 -0500
28809 @@ -465,7 +465,7 @@ static int taal_bl_get_intensity(struct
28810 return 0;
28811 }
28812
28813 -static struct backlight_ops taal_bl_ops = {
28814 +static const struct backlight_ops taal_bl_ops = {
28815 .get_brightness = taal_bl_get_intensity,
28816 .update_status = taal_bl_update_status,
28817 };
28818 diff -urNp linux-2.6.37/drivers/video/riva/fbdev.c linux-2.6.37/drivers/video/riva/fbdev.c
28819 --- linux-2.6.37/drivers/video/riva/fbdev.c 2011-01-04 19:50:19.000000000 -0500
28820 +++ linux-2.6.37/drivers/video/riva/fbdev.c 2011-01-17 02:41:01.000000000 -0500
28821 @@ -331,7 +331,7 @@ static int riva_bl_get_brightness(struct
28822 return bd->props.brightness;
28823 }
28824
28825 -static struct backlight_ops riva_bl_ops = {
28826 +static const struct backlight_ops riva_bl_ops = {
28827 .get_brightness = riva_bl_get_brightness,
28828 .update_status = riva_bl_update_status,
28829 };
28830 diff -urNp linux-2.6.37/drivers/video/uvesafb.c linux-2.6.37/drivers/video/uvesafb.c
28831 --- linux-2.6.37/drivers/video/uvesafb.c 2011-01-04 19:50:19.000000000 -0500
28832 +++ linux-2.6.37/drivers/video/uvesafb.c 2011-01-17 02:41:01.000000000 -0500
28833 @@ -19,6 +19,7 @@
28834 #include <linux/io.h>
28835 #include <linux/mutex.h>
28836 #include <linux/slab.h>
28837 +#include <linux/moduleloader.h>
28838 #include <video/edid.h>
28839 #include <video/uvesafb.h>
28840 #ifdef CONFIG_X86
28841 @@ -121,7 +122,7 @@ static int uvesafb_helper_start(void)
28842 NULL,
28843 };
28844
28845 - return call_usermodehelper(v86d_path, argv, envp, 1);
28846 + return call_usermodehelper(v86d_path, argv, envp, UMH_WAIT_PROC);
28847 }
28848
28849 /*
28850 @@ -569,10 +570,32 @@ static int __devinit uvesafb_vbe_getpmi(
28851 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
28852 par->pmi_setpal = par->ypan = 0;
28853 } else {
28854 +
28855 +#ifdef CONFIG_PAX_KERNEXEC
28856 +#ifdef CONFIG_MODULES
28857 + par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
28858 +#endif
28859 + if (!par->pmi_code) {
28860 + par->pmi_setpal = par->ypan = 0;
28861 + return 0;
28862 + }
28863 +#endif
28864 +
28865 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
28866 + task->t.regs.edi);
28867 +
28868 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
28869 + pax_open_kernel();
28870 + memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
28871 + pax_close_kernel();
28872 +
28873 + par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
28874 + par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
28875 +#else
28876 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
28877 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
28878 +#endif
28879 +
28880 printk(KERN_INFO "uvesafb: protected mode interface info at "
28881 "%04x:%04x\n",
28882 (u16)task->t.regs.es, (u16)task->t.regs.edi);
28883 @@ -1800,6 +1823,11 @@ out:
28884 if (par->vbe_modes)
28885 kfree(par->vbe_modes);
28886
28887 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
28888 + if (par->pmi_code)
28889 + module_free_exec(NULL, par->pmi_code);
28890 +#endif
28891 +
28892 framebuffer_release(info);
28893 return err;
28894 }
28895 @@ -1826,6 +1854,12 @@ static int uvesafb_remove(struct platfor
28896 kfree(par->vbe_state_orig);
28897 if (par->vbe_state_saved)
28898 kfree(par->vbe_state_saved);
28899 +
28900 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
28901 + if (par->pmi_code)
28902 + module_free_exec(NULL, par->pmi_code);
28903 +#endif
28904 +
28905 }
28906
28907 framebuffer_release(info);
28908 diff -urNp linux-2.6.37/drivers/video/vesafb.c linux-2.6.37/drivers/video/vesafb.c
28909 --- linux-2.6.37/drivers/video/vesafb.c 2011-01-04 19:50:19.000000000 -0500
28910 +++ linux-2.6.37/drivers/video/vesafb.c 2011-01-17 02:41:01.000000000 -0500
28911 @@ -9,6 +9,7 @@
28912 */
28913
28914 #include <linux/module.h>
28915 +#include <linux/moduleloader.h>
28916 #include <linux/kernel.h>
28917 #include <linux/errno.h>
28918 #include <linux/string.h>
28919 @@ -52,8 +53,8 @@ static int vram_remap __initdata; /*
28920 static int vram_total __initdata; /* Set total amount of memory */
28921 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
28922 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
28923 -static void (*pmi_start)(void) __read_mostly;
28924 -static void (*pmi_pal) (void) __read_mostly;
28925 +static void (*pmi_start)(void) __read_only;
28926 +static void (*pmi_pal) (void) __read_only;
28927 static int depth __read_mostly;
28928 static int vga_compat __read_mostly;
28929 /* --------------------------------------------------------------------- */
28930 @@ -232,6 +233,7 @@ static int __init vesafb_probe(struct pl
28931 unsigned int size_vmode;
28932 unsigned int size_remap;
28933 unsigned int size_total;
28934 + void *pmi_code = NULL;
28935
28936 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
28937 return -ENODEV;
28938 @@ -274,10 +276,6 @@ static int __init vesafb_probe(struct pl
28939 size_remap = size_total;
28940 vesafb_fix.smem_len = size_remap;
28941
28942 -#ifndef __i386__
28943 - screen_info.vesapm_seg = 0;
28944 -#endif
28945 -
28946 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
28947 printk(KERN_WARNING
28948 "vesafb: cannot reserve video memory at 0x%lx\n",
28949 @@ -319,9 +317,21 @@ static int __init vesafb_probe(struct pl
28950 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
28951 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
28952
28953 +#ifdef __i386__
28954 +
28955 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
28956 + pmi_code = module_alloc_exec(screen_info.vesapm_size);
28957 + if (!pmi_code)
28958 +#elif !defined(CONFIG_PAX_KERNEXEC)
28959 + if (0)
28960 +#endif
28961 +
28962 +#endif
28963 + screen_info.vesapm_seg = 0;
28964 +
28965 if (screen_info.vesapm_seg) {
28966 - printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
28967 - screen_info.vesapm_seg,screen_info.vesapm_off);
28968 + printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
28969 + screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
28970 }
28971
28972 if (screen_info.vesapm_seg < 0xc000)
28973 @@ -329,9 +339,25 @@ static int __init vesafb_probe(struct pl
28974
28975 if (ypan || pmi_setpal) {
28976 unsigned short *pmi_base;
28977 - pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
28978 - pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
28979 - pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
28980 +
28981 + pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
28982 +
28983 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
28984 + pax_open_kernel();
28985 + memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
28986 +#else
28987 + pmi_code = pmi_base;
28988 +#endif
28989 +
28990 + pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
28991 + pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
28992 +
28993 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
28994 + pmi_start = ktva_ktla(pmi_start);
28995 + pmi_pal = ktva_ktla(pmi_pal);
28996 + pax_close_kernel();
28997 +#endif
28998 +
28999 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
29000 if (pmi_base[3]) {
29001 printk(KERN_INFO "vesafb: pmi: ports = ");
29002 @@ -473,6 +499,11 @@ static int __init vesafb_probe(struct pl
29003 info->node, info->fix.id);
29004 return 0;
29005 err:
29006 +
29007 +#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
29008 + module_free_exec(NULL, pmi_code);
29009 +#endif
29010 +
29011 if (info->screen_base)
29012 iounmap(info->screen_base);
29013 framebuffer_release(info);
29014 diff -urNp linux-2.6.37/fs/9p/vfs_inode.c linux-2.6.37/fs/9p/vfs_inode.c
29015 --- linux-2.6.37/fs/9p/vfs_inode.c 2011-01-04 19:50:19.000000000 -0500
29016 +++ linux-2.6.37/fs/9p/vfs_inode.c 2011-01-17 02:41:01.000000000 -0500
29017 @@ -1598,7 +1598,7 @@ static void *v9fs_vfs_follow_link(struct
29018 static void
29019 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
29020 {
29021 - char *s = nd_get_link(nd);
29022 + const char *s = nd_get_link(nd);
29023
29024 P9_DPRINTK(P9_DEBUG_VFS, " %s %s\n", dentry->d_name.name,
29025 IS_ERR(s) ? "<error>" : s);
29026 diff -urNp linux-2.6.37/fs/aio.c linux-2.6.37/fs/aio.c
29027 --- linux-2.6.37/fs/aio.c 2011-01-04 19:50:19.000000000 -0500
29028 +++ linux-2.6.37/fs/aio.c 2011-01-17 02:41:01.000000000 -0500
29029 @@ -130,7 +130,7 @@ static int aio_setup_ring(struct kioctx
29030 size += sizeof(struct io_event) * nr_events;
29031 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
29032
29033 - if (nr_pages < 0)
29034 + if (nr_pages <= 0)
29035 return -EINVAL;
29036
29037 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
29038 diff -urNp linux-2.6.37/fs/attr.c linux-2.6.37/fs/attr.c
29039 --- linux-2.6.37/fs/attr.c 2011-01-04 19:50:19.000000000 -0500
29040 +++ linux-2.6.37/fs/attr.c 2011-01-17 02:41:01.000000000 -0500
29041 @@ -98,6 +98,7 @@ int inode_newsize_ok(const struct inode
29042 unsigned long limit;
29043
29044 limit = rlimit(RLIMIT_FSIZE);
29045 + gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
29046 if (limit != RLIM_INFINITY && offset > limit)
29047 goto out_sig;
29048 if (offset > inode->i_sb->s_maxbytes)
29049 diff -urNp linux-2.6.37/fs/autofs4/symlink.c linux-2.6.37/fs/autofs4/symlink.c
29050 --- linux-2.6.37/fs/autofs4/symlink.c 2011-01-04 19:50:19.000000000 -0500
29051 +++ linux-2.6.37/fs/autofs4/symlink.c 2011-01-17 02:41:01.000000000 -0500
29052 @@ -15,7 +15,7 @@
29053 static void *autofs4_follow_link(struct dentry *dentry, struct nameidata *nd)
29054 {
29055 struct autofs_info *ino = autofs4_dentry_ino(dentry);
29056 - nd_set_link(nd, (char *)ino->u.symlink);
29057 + nd_set_link(nd, ino->u.symlink);
29058 return NULL;
29059 }
29060
29061 diff -urNp linux-2.6.37/fs/befs/linuxvfs.c linux-2.6.37/fs/befs/linuxvfs.c
29062 --- linux-2.6.37/fs/befs/linuxvfs.c 2011-01-04 19:50:19.000000000 -0500
29063 +++ linux-2.6.37/fs/befs/linuxvfs.c 2011-01-17 02:41:01.000000000 -0500
29064 @@ -493,7 +493,7 @@ static void befs_put_link(struct dentry
29065 {
29066 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
29067 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
29068 - char *link = nd_get_link(nd);
29069 + const char *link = nd_get_link(nd);
29070 if (!IS_ERR(link))
29071 kfree(link);
29072 }
29073 diff -urNp linux-2.6.37/fs/binfmt_aout.c linux-2.6.37/fs/binfmt_aout.c
29074 --- linux-2.6.37/fs/binfmt_aout.c 2011-01-04 19:50:19.000000000 -0500
29075 +++ linux-2.6.37/fs/binfmt_aout.c 2011-01-17 02:41:01.000000000 -0500
29076 @@ -16,6 +16,7 @@
29077 #include <linux/string.h>
29078 #include <linux/fs.h>
29079 #include <linux/file.h>
29080 +#include <linux/security.h>
29081 #include <linux/stat.h>
29082 #include <linux/fcntl.h>
29083 #include <linux/ptrace.h>
29084 @@ -86,6 +87,8 @@ static int aout_core_dump(struct coredum
29085 #endif
29086 # define START_STACK(u) ((void __user *)u.start_stack)
29087
29088 + memset(&dump, 0, sizeof(dump));
29089 +
29090 fs = get_fs();
29091 set_fs(KERNEL_DS);
29092 has_dumped = 1;
29093 @@ -97,10 +100,12 @@ static int aout_core_dump(struct coredum
29094
29095 /* If the size of the dump file exceeds the rlimit, then see what would happen
29096 if we wrote the stack, but not the data area. */
29097 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
29098 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
29099 dump.u_dsize = 0;
29100
29101 /* Make sure we have enough room to write the stack and data areas. */
29102 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
29103 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
29104 dump.u_ssize = 0;
29105
29106 @@ -234,6 +239,8 @@ static int load_aout_binary(struct linux
29107 rlim = rlimit(RLIMIT_DATA);
29108 if (rlim >= RLIM_INFINITY)
29109 rlim = ~0;
29110 +
29111 + gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
29112 if (ex.a_data + ex.a_bss > rlim)
29113 return -ENOMEM;
29114
29115 @@ -262,6 +269,27 @@ static int load_aout_binary(struct linux
29116 install_exec_creds(bprm);
29117 current->flags &= ~PF_FORKNOEXEC;
29118
29119 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
29120 + current->mm->pax_flags = 0UL;
29121 +#endif
29122 +
29123 +#ifdef CONFIG_PAX_PAGEEXEC
29124 + if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
29125 + current->mm->pax_flags |= MF_PAX_PAGEEXEC;
29126 +
29127 +#ifdef CONFIG_PAX_EMUTRAMP
29128 + if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
29129 + current->mm->pax_flags |= MF_PAX_EMUTRAMP;
29130 +#endif
29131 +
29132 +#ifdef CONFIG_PAX_MPROTECT
29133 + if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
29134 + current->mm->pax_flags |= MF_PAX_MPROTECT;
29135 +#endif
29136 +
29137 + }
29138 +#endif
29139 +
29140 if (N_MAGIC(ex) == OMAGIC) {
29141 unsigned long text_addr, map_size;
29142 loff_t pos;
29143 @@ -334,7 +362,7 @@ static int load_aout_binary(struct linux
29144
29145 down_write(&current->mm->mmap_sem);
29146 error = do_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
29147 - PROT_READ | PROT_WRITE | PROT_EXEC,
29148 + PROT_READ | PROT_WRITE,
29149 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
29150 fd_offset + ex.a_text);
29151 up_write(&current->mm->mmap_sem);
29152 diff -urNp linux-2.6.37/fs/binfmt_elf.c linux-2.6.37/fs/binfmt_elf.c
29153 --- linux-2.6.37/fs/binfmt_elf.c 2011-01-04 19:50:19.000000000 -0500
29154 +++ linux-2.6.37/fs/binfmt_elf.c 2011-01-17 02:41:01.000000000 -0500
29155 @@ -51,6 +51,10 @@ static int elf_core_dump(struct coredump
29156 #define elf_core_dump NULL
29157 #endif
29158
29159 +#ifdef CONFIG_PAX_MPROTECT
29160 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
29161 +#endif
29162 +
29163 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
29164 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
29165 #else
29166 @@ -70,6 +74,11 @@ static struct linux_binfmt elf_format =
29167 .load_binary = load_elf_binary,
29168 .load_shlib = load_elf_library,
29169 .core_dump = elf_core_dump,
29170 +
29171 +#ifdef CONFIG_PAX_MPROTECT
29172 + .handle_mprotect= elf_handle_mprotect,
29173 +#endif
29174 +
29175 .min_coredump = ELF_EXEC_PAGESIZE,
29176 .hasvdso = 1
29177 };
29178 @@ -78,6 +87,8 @@ static struct linux_binfmt elf_format =
29179
29180 static int set_brk(unsigned long start, unsigned long end)
29181 {
29182 + unsigned long e = end;
29183 +
29184 start = ELF_PAGEALIGN(start);
29185 end = ELF_PAGEALIGN(end);
29186 if (end > start) {
29187 @@ -88,7 +99,7 @@ static int set_brk(unsigned long start,
29188 if (BAD_ADDR(addr))
29189 return addr;
29190 }
29191 - current->mm->start_brk = current->mm->brk = end;
29192 + current->mm->start_brk = current->mm->brk = e;
29193 return 0;
29194 }
29195
29196 @@ -149,7 +160,7 @@ create_elf_tables(struct linux_binprm *b
29197 elf_addr_t __user *u_rand_bytes;
29198 const char *k_platform = ELF_PLATFORM;
29199 const char *k_base_platform = ELF_BASE_PLATFORM;
29200 - unsigned char k_rand_bytes[16];
29201 + u32 k_rand_bytes[4];
29202 int items;
29203 elf_addr_t *elf_info;
29204 int ei_index = 0;
29205 @@ -196,8 +207,12 @@ create_elf_tables(struct linux_binprm *b
29206 * Generate 16 random bytes for userspace PRNG seeding.
29207 */
29208 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
29209 - u_rand_bytes = (elf_addr_t __user *)
29210 - STACK_ALLOC(p, sizeof(k_rand_bytes));
29211 + srandom32(k_rand_bytes[0] ^ random32());
29212 + srandom32(k_rand_bytes[1] ^ random32());
29213 + srandom32(k_rand_bytes[2] ^ random32());
29214 + srandom32(k_rand_bytes[3] ^ random32());
29215 + p = STACK_ROUND(p, sizeof(k_rand_bytes));
29216 + u_rand_bytes = (elf_addr_t __user *) p;
29217 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
29218 return -EFAULT;
29219
29220 @@ -386,10 +401,10 @@ static unsigned long load_elf_interp(str
29221 {
29222 struct elf_phdr *elf_phdata;
29223 struct elf_phdr *eppnt;
29224 - unsigned long load_addr = 0;
29225 + unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
29226 int load_addr_set = 0;
29227 unsigned long last_bss = 0, elf_bss = 0;
29228 - unsigned long error = ~0UL;
29229 + unsigned long error = -EINVAL;
29230 unsigned long total_size;
29231 int retval, i, size;
29232
29233 @@ -435,6 +450,11 @@ static unsigned long load_elf_interp(str
29234 goto out_close;
29235 }
29236
29237 +#ifdef CONFIG_PAX_SEGMEXEC
29238 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
29239 + pax_task_size = SEGMEXEC_TASK_SIZE;
29240 +#endif
29241 +
29242 eppnt = elf_phdata;
29243 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
29244 if (eppnt->p_type == PT_LOAD) {
29245 @@ -478,8 +498,8 @@ static unsigned long load_elf_interp(str
29246 k = load_addr + eppnt->p_vaddr;
29247 if (BAD_ADDR(k) ||
29248 eppnt->p_filesz > eppnt->p_memsz ||
29249 - eppnt->p_memsz > TASK_SIZE ||
29250 - TASK_SIZE - eppnt->p_memsz < k) {
29251 + eppnt->p_memsz > pax_task_size ||
29252 + pax_task_size - eppnt->p_memsz < k) {
29253 error = -ENOMEM;
29254 goto out_close;
29255 }
29256 @@ -533,6 +553,177 @@ out:
29257 return error;
29258 }
29259
29260 +#if (defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS)) && defined(CONFIG_PAX_SOFTMODE)
29261 +static unsigned long pax_parse_softmode(const struct elf_phdr * const elf_phdata)
29262 +{
29263 + unsigned long pax_flags = 0UL;
29264 +
29265 +#ifdef CONFIG_PAX_PAGEEXEC
29266 + if (elf_phdata->p_flags & PF_PAGEEXEC)
29267 + pax_flags |= MF_PAX_PAGEEXEC;
29268 +#endif
29269 +
29270 +#ifdef CONFIG_PAX_SEGMEXEC
29271 + if (elf_phdata->p_flags & PF_SEGMEXEC)
29272 + pax_flags |= MF_PAX_SEGMEXEC;
29273 +#endif
29274 +
29275 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
29276 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
29277 + if ((__supported_pte_mask & _PAGE_NX))
29278 + pax_flags &= ~MF_PAX_SEGMEXEC;
29279 + else
29280 + pax_flags &= ~MF_PAX_PAGEEXEC;
29281 + }
29282 +#endif
29283 +
29284 +#ifdef CONFIG_PAX_EMUTRAMP
29285 + if (elf_phdata->p_flags & PF_EMUTRAMP)
29286 + pax_flags |= MF_PAX_EMUTRAMP;
29287 +#endif
29288 +
29289 +#ifdef CONFIG_PAX_MPROTECT
29290 + if (elf_phdata->p_flags & PF_MPROTECT)
29291 + pax_flags |= MF_PAX_MPROTECT;
29292 +#endif
29293 +
29294 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
29295 + if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
29296 + pax_flags |= MF_PAX_RANDMMAP;
29297 +#endif
29298 +
29299 + return pax_flags;
29300 +}
29301 +#endif
29302 +
29303 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
29304 +static unsigned long pax_parse_hardmode(const struct elf_phdr * const elf_phdata)
29305 +{
29306 + unsigned long pax_flags = 0UL;
29307 +
29308 +#ifdef CONFIG_PAX_PAGEEXEC
29309 + if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
29310 + pax_flags |= MF_PAX_PAGEEXEC;
29311 +#endif
29312 +
29313 +#ifdef CONFIG_PAX_SEGMEXEC
29314 + if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
29315 + pax_flags |= MF_PAX_SEGMEXEC;
29316 +#endif
29317 +
29318 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
29319 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
29320 + if ((__supported_pte_mask & _PAGE_NX))
29321 + pax_flags &= ~MF_PAX_SEGMEXEC;
29322 + else
29323 + pax_flags &= ~MF_PAX_PAGEEXEC;
29324 + }
29325 +#endif
29326 +
29327 +#ifdef CONFIG_PAX_EMUTRAMP
29328 + if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
29329 + pax_flags |= MF_PAX_EMUTRAMP;
29330 +#endif
29331 +
29332 +#ifdef CONFIG_PAX_MPROTECT
29333 + if (!(elf_phdata->p_flags & PF_NOMPROTECT))
29334 + pax_flags |= MF_PAX_MPROTECT;
29335 +#endif
29336 +
29337 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
29338 + if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
29339 + pax_flags |= MF_PAX_RANDMMAP;
29340 +#endif
29341 +
29342 + return pax_flags;
29343 +}
29344 +#endif
29345 +
29346 +#ifdef CONFIG_PAX_EI_PAX
29347 +static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
29348 +{
29349 + unsigned long pax_flags = 0UL;
29350 +
29351 +#ifdef CONFIG_PAX_PAGEEXEC
29352 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
29353 + pax_flags |= MF_PAX_PAGEEXEC;
29354 +#endif
29355 +
29356 +#ifdef CONFIG_PAX_SEGMEXEC
29357 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
29358 + pax_flags |= MF_PAX_SEGMEXEC;
29359 +#endif
29360 +
29361 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
29362 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
29363 + if ((__supported_pte_mask & _PAGE_NX))
29364 + pax_flags &= ~MF_PAX_SEGMEXEC;
29365 + else
29366 + pax_flags &= ~MF_PAX_PAGEEXEC;
29367 + }
29368 +#endif
29369 +
29370 +#ifdef CONFIG_PAX_EMUTRAMP
29371 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
29372 + pax_flags |= MF_PAX_EMUTRAMP;
29373 +#endif
29374 +
29375 +#ifdef CONFIG_PAX_MPROTECT
29376 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
29377 + pax_flags |= MF_PAX_MPROTECT;
29378 +#endif
29379 +
29380 +#ifdef CONFIG_PAX_ASLR
29381 + if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
29382 + pax_flags |= MF_PAX_RANDMMAP;
29383 +#endif
29384 +
29385 + return pax_flags;
29386 +}
29387 +#endif
29388 +
29389 +#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS)
29390 +static long pax_parse_elf_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
29391 +{
29392 + unsigned long pax_flags = 0UL;
29393 +
29394 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
29395 + unsigned long i;
29396 +#endif
29397 +
29398 +#ifdef CONFIG_PAX_EI_PAX
29399 + pax_flags = pax_parse_ei_pax(elf_ex);
29400 +#endif
29401 +
29402 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
29403 + for (i = 0UL; i < elf_ex->e_phnum; i++)
29404 + if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
29405 + if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
29406 + ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
29407 + ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
29408 + ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
29409 + ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
29410 + return -EINVAL;
29411 +
29412 +#ifdef CONFIG_PAX_SOFTMODE
29413 + if (pax_softmode)
29414 + pax_flags = pax_parse_softmode(&elf_phdata[i]);
29415 + else
29416 +#endif
29417 +
29418 + pax_flags = pax_parse_hardmode(&elf_phdata[i]);
29419 + break;
29420 + }
29421 +#endif
29422 +
29423 + if (0 > pax_check_flags(&pax_flags))
29424 + return -EINVAL;
29425 +
29426 + current->mm->pax_flags = pax_flags;
29427 + return 0;
29428 +}
29429 +#endif
29430 +
29431 /*
29432 * These are the functions used to load ELF style executables and shared
29433 * libraries. There is no binary dependent code anywhere else.
29434 @@ -549,6 +740,11 @@ static unsigned long randomize_stack_top
29435 {
29436 unsigned int random_variable = 0;
29437
29438 +#ifdef CONFIG_PAX_RANDUSTACK
29439 + if (randomize_va_space)
29440 + return stack_top - current->mm->delta_stack;
29441 +#endif
29442 +
29443 if ((current->flags & PF_RANDOMIZE) &&
29444 !(current->personality & ADDR_NO_RANDOMIZE)) {
29445 random_variable = get_random_int() & STACK_RND_MASK;
29446 @@ -567,7 +763,7 @@ static int load_elf_binary(struct linux_
29447 unsigned long load_addr = 0, load_bias = 0;
29448 int load_addr_set = 0;
29449 char * elf_interpreter = NULL;
29450 - unsigned long error;
29451 + unsigned long error = 0;
29452 struct elf_phdr *elf_ppnt, *elf_phdata;
29453 unsigned long elf_bss, elf_brk;
29454 int retval, i;
29455 @@ -577,11 +773,11 @@ static int load_elf_binary(struct linux_
29456 unsigned long start_code, end_code, start_data, end_data;
29457 unsigned long reloc_func_desc = 0;
29458 int executable_stack = EXSTACK_DEFAULT;
29459 - unsigned long def_flags = 0;
29460 struct {
29461 struct elfhdr elf_ex;
29462 struct elfhdr interp_elf_ex;
29463 } *loc;
29464 + unsigned long pax_task_size = TASK_SIZE;
29465
29466 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
29467 if (!loc) {
29468 @@ -719,11 +915,80 @@ static int load_elf_binary(struct linux_
29469
29470 /* OK, This is the point of no return */
29471 current->flags &= ~PF_FORKNOEXEC;
29472 - current->mm->def_flags = def_flags;
29473 +
29474 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
29475 + current->mm->pax_flags = 0UL;
29476 +#endif
29477 +
29478 +#ifdef CONFIG_PAX_DLRESOLVE
29479 + current->mm->call_dl_resolve = 0UL;
29480 +#endif
29481 +
29482 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
29483 + current->mm->call_syscall = 0UL;
29484 +#endif
29485 +
29486 +#ifdef CONFIG_PAX_ASLR
29487 + current->mm->delta_mmap = 0UL;
29488 + current->mm->delta_stack = 0UL;
29489 +#endif
29490 +
29491 + current->mm->def_flags = 0;
29492 +
29493 +#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS)
29494 + if (0 > pax_parse_elf_flags(&loc->elf_ex, elf_phdata)) {
29495 + send_sig(SIGKILL, current, 0);
29496 + goto out_free_dentry;
29497 + }
29498 +#endif
29499 +
29500 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
29501 + pax_set_initial_flags(bprm);
29502 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
29503 + if (pax_set_initial_flags_func)
29504 + (pax_set_initial_flags_func)(bprm);
29505 +#endif
29506 +
29507 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
29508 + if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
29509 + current->mm->context.user_cs_limit = PAGE_SIZE;
29510 + current->mm->def_flags |= VM_PAGEEXEC;
29511 + }
29512 +#endif
29513 +
29514 +#ifdef CONFIG_PAX_SEGMEXEC
29515 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
29516 + current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
29517 + current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
29518 + pax_task_size = SEGMEXEC_TASK_SIZE;
29519 + }
29520 +#endif
29521 +
29522 +#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
29523 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
29524 + set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
29525 + put_cpu();
29526 + }
29527 +#endif
29528
29529 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
29530 may depend on the personality. */
29531 SET_PERSONALITY(loc->elf_ex);
29532 +
29533 +#ifdef CONFIG_PAX_ASLR
29534 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
29535 + current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
29536 + current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
29537 + }
29538 +#endif
29539 +
29540 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
29541 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
29542 + executable_stack = EXSTACK_DISABLE_X;
29543 + current->personality &= ~READ_IMPLIES_EXEC;
29544 + } else
29545 +#endif
29546 +
29547 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
29548 current->personality |= READ_IMPLIES_EXEC;
29549
29550 @@ -805,6 +1070,20 @@ static int load_elf_binary(struct linux_
29551 #else
29552 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
29553 #endif
29554 +
29555 +#ifdef CONFIG_PAX_RANDMMAP
29556 + /* PaX: randomize base address at the default exe base if requested */
29557 + if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
29558 +#ifdef CONFIG_SPARC64
29559 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
29560 +#else
29561 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
29562 +#endif
29563 + load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
29564 + elf_flags |= MAP_FIXED;
29565 + }
29566 +#endif
29567 +
29568 }
29569
29570 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
29571 @@ -837,9 +1116,9 @@ static int load_elf_binary(struct linux_
29572 * allowed task size. Note that p_filesz must always be
29573 * <= p_memsz so it is only necessary to check p_memsz.
29574 */
29575 - if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
29576 - elf_ppnt->p_memsz > TASK_SIZE ||
29577 - TASK_SIZE - elf_ppnt->p_memsz < k) {
29578 + if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
29579 + elf_ppnt->p_memsz > pax_task_size ||
29580 + pax_task_size - elf_ppnt->p_memsz < k) {
29581 /* set_brk can never work. Avoid overflows. */
29582 send_sig(SIGKILL, current, 0);
29583 retval = -EINVAL;
29584 @@ -867,6 +1146,11 @@ static int load_elf_binary(struct linux_
29585 start_data += load_bias;
29586 end_data += load_bias;
29587
29588 +#ifdef CONFIG_PAX_RANDMMAP
29589 + if (current->mm->pax_flags & MF_PAX_RANDMMAP)
29590 + elf_brk += PAGE_SIZE + ((pax_get_random_long() & ~PAGE_MASK) << 4);
29591 +#endif
29592 +
29593 /* Calling set_brk effectively mmaps the pages that we need
29594 * for the bss and break sections. We must do this before
29595 * mapping in the interpreter, to make sure it doesn't wind
29596 @@ -878,9 +1162,11 @@ static int load_elf_binary(struct linux_
29597 goto out_free_dentry;
29598 }
29599 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
29600 - send_sig(SIGSEGV, current, 0);
29601 - retval = -EFAULT; /* Nobody gets to see this, but.. */
29602 - goto out_free_dentry;
29603 + /*
29604 + * This bss-zeroing can fail if the ELF
29605 + * file specifies odd protections. So
29606 + * we don't check the return value
29607 + */
29608 }
29609
29610 if (elf_interpreter) {
29611 @@ -1091,7 +1377,7 @@ out:
29612 * Decide what to dump of a segment, part, all or none.
29613 */
29614 static unsigned long vma_dump_size(struct vm_area_struct *vma,
29615 - unsigned long mm_flags)
29616 + unsigned long mm_flags, long signr)
29617 {
29618 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
29619
29620 @@ -1125,7 +1411,7 @@ static unsigned long vma_dump_size(struc
29621 if (vma->vm_file == NULL)
29622 return 0;
29623
29624 - if (FILTER(MAPPED_PRIVATE))
29625 + if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
29626 goto whole;
29627
29628 /*
29629 @@ -1347,9 +1633,9 @@ static void fill_auxv_note(struct memelf
29630 {
29631 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
29632 int i = 0;
29633 - do
29634 + do {
29635 i += 2;
29636 - while (auxv[i - 2] != AT_NULL);
29637 + } while (auxv[i - 2] != AT_NULL);
29638 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
29639 }
29640
29641 @@ -1855,14 +2141,14 @@ static void fill_extnum_info(struct elfh
29642 }
29643
29644 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
29645 - unsigned long mm_flags)
29646 + struct coredump_params *cprm)
29647 {
29648 struct vm_area_struct *vma;
29649 size_t size = 0;
29650
29651 for (vma = first_vma(current, gate_vma); vma != NULL;
29652 vma = next_vma(vma, gate_vma))
29653 - size += vma_dump_size(vma, mm_flags);
29654 + size += vma_dump_size(vma, cprm->mm_flags, cprm->signr);
29655 return size;
29656 }
29657
29658 @@ -1956,7 +2242,7 @@ static int elf_core_dump(struct coredump
29659
29660 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
29661
29662 - offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
29663 + offset += elf_core_vma_data_size(gate_vma, cprm);
29664 offset += elf_core_extra_data_size();
29665 e_shoff = offset;
29666
29667 @@ -1970,10 +2256,12 @@ static int elf_core_dump(struct coredump
29668 offset = dataoff;
29669
29670 size += sizeof(*elf);
29671 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
29672 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
29673 goto end_coredump;
29674
29675 size += sizeof(*phdr4note);
29676 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
29677 if (size > cprm->limit
29678 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
29679 goto end_coredump;
29680 @@ -1987,7 +2275,7 @@ static int elf_core_dump(struct coredump
29681 phdr.p_offset = offset;
29682 phdr.p_vaddr = vma->vm_start;
29683 phdr.p_paddr = 0;
29684 - phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
29685 + phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->signr);
29686 phdr.p_memsz = vma->vm_end - vma->vm_start;
29687 offset += phdr.p_filesz;
29688 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
29689 @@ -1998,6 +2286,7 @@ static int elf_core_dump(struct coredump
29690 phdr.p_align = ELF_EXEC_PAGESIZE;
29691
29692 size += sizeof(phdr);
29693 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
29694 if (size > cprm->limit
29695 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
29696 goto end_coredump;
29697 @@ -2022,7 +2311,7 @@ static int elf_core_dump(struct coredump
29698 unsigned long addr;
29699 unsigned long end;
29700
29701 - end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
29702 + end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->signr);
29703
29704 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
29705 struct page *page;
29706 @@ -2031,6 +2320,7 @@ static int elf_core_dump(struct coredump
29707 page = get_dump_page(addr);
29708 if (page) {
29709 void *kaddr = kmap(page);
29710 + gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
29711 stop = ((size += PAGE_SIZE) > cprm->limit) ||
29712 !dump_write(cprm->file, kaddr,
29713 PAGE_SIZE);
29714 @@ -2048,6 +2338,7 @@ static int elf_core_dump(struct coredump
29715
29716 if (e_phnum == PN_XNUM) {
29717 size += sizeof(*shdr4extnum);
29718 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
29719 if (size > cprm->limit
29720 || !dump_write(cprm->file, shdr4extnum,
29721 sizeof(*shdr4extnum)))
29722 @@ -2068,6 +2359,97 @@ out:
29723
29724 #endif /* CONFIG_ELF_CORE */
29725
29726 +#ifdef CONFIG_PAX_MPROTECT
29727 +/* PaX: non-PIC ELF libraries need relocations on their executable segments
29728 + * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
29729 + * we'll remove VM_MAYWRITE for good on RELRO segments.
29730 + *
29731 + * The checks favour ld-linux.so behaviour which operates on a per ELF segment
29732 + * basis because we want to allow the common case and not the special ones.
29733 + */
29734 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
29735 +{
29736 + struct elfhdr elf_h;
29737 + struct elf_phdr elf_p;
29738 + unsigned long i;
29739 + unsigned long oldflags;
29740 + bool is_textrel_rw, is_textrel_rx, is_relro;
29741 +
29742 + if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
29743 + return;
29744 +
29745 + oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
29746 + newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
29747 +
29748 +#ifdef CONFIG_PAX_ELFRELOCS
29749 + /* possible TEXTREL */
29750 + is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
29751 + 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);
29752 +#else
29753 + is_textrel_rw = false;
29754 + is_textrel_rx = false;
29755 +#endif
29756 +
29757 + /* possible RELRO */
29758 + is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
29759 +
29760 + if (!is_textrel_rw && !is_textrel_rx && !is_relro)
29761 + return;
29762 +
29763 + if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
29764 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
29765 +
29766 +#ifdef CONFIG_PAX_ETEXECRELOCS
29767 + ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
29768 +#else
29769 + ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
29770 +#endif
29771 +
29772 + (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
29773 + !elf_check_arch(&elf_h) ||
29774 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
29775 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
29776 + return;
29777 +
29778 + for (i = 0UL; i < elf_h.e_phnum; i++) {
29779 + if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
29780 + return;
29781 + switch (elf_p.p_type) {
29782 + case PT_DYNAMIC:
29783 + if (!is_textrel_rw && !is_textrel_rx)
29784 + continue;
29785 + i = 0UL;
29786 + while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
29787 + elf_dyn dyn;
29788 +
29789 + if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
29790 + return;
29791 + if (dyn.d_tag == DT_NULL)
29792 + return;
29793 + if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
29794 + gr_log_textrel(vma);
29795 + if (is_textrel_rw)
29796 + vma->vm_flags |= VM_MAYWRITE;
29797 + else
29798 + /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
29799 + vma->vm_flags &= ~VM_MAYWRITE;
29800 + return;
29801 + }
29802 + i++;
29803 + }
29804 + return;
29805 +
29806 + case PT_GNU_RELRO:
29807 + if (!is_relro)
29808 + continue;
29809 + if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
29810 + vma->vm_flags &= ~VM_MAYWRITE;
29811 + return;
29812 + }
29813 + }
29814 +}
29815 +#endif
29816 +
29817 static int __init init_elf_binfmt(void)
29818 {
29819 return register_binfmt(&elf_format);
29820 diff -urNp linux-2.6.37/fs/binfmt_flat.c linux-2.6.37/fs/binfmt_flat.c
29821 --- linux-2.6.37/fs/binfmt_flat.c 2011-01-04 19:50:19.000000000 -0500
29822 +++ linux-2.6.37/fs/binfmt_flat.c 2011-01-17 02:41:01.000000000 -0500
29823 @@ -567,7 +567,9 @@ static int load_flat_file(struct linux_b
29824 realdatastart = (unsigned long) -ENOMEM;
29825 printk("Unable to allocate RAM for process data, errno %d\n",
29826 (int)-realdatastart);
29827 + down_write(&current->mm->mmap_sem);
29828 do_munmap(current->mm, textpos, text_len);
29829 + up_write(&current->mm->mmap_sem);
29830 ret = realdatastart;
29831 goto err;
29832 }
29833 @@ -591,8 +593,10 @@ static int load_flat_file(struct linux_b
29834 }
29835 if (IS_ERR_VALUE(result)) {
29836 printk("Unable to read data+bss, errno %d\n", (int)-result);
29837 + down_write(&current->mm->mmap_sem);
29838 do_munmap(current->mm, textpos, text_len);
29839 do_munmap(current->mm, realdatastart, len);
29840 + up_write(&current->mm->mmap_sem);
29841 ret = result;
29842 goto err;
29843 }
29844 @@ -661,8 +665,10 @@ static int load_flat_file(struct linux_b
29845 }
29846 if (IS_ERR_VALUE(result)) {
29847 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
29848 + down_write(&current->mm->mmap_sem);
29849 do_munmap(current->mm, textpos, text_len + data_len + extra +
29850 MAX_SHARED_LIBS * sizeof(unsigned long));
29851 + up_write(&current->mm->mmap_sem);
29852 ret = result;
29853 goto err;
29854 }
29855 diff -urNp linux-2.6.37/fs/binfmt_misc.c linux-2.6.37/fs/binfmt_misc.c
29856 --- linux-2.6.37/fs/binfmt_misc.c 2011-01-04 19:50:19.000000000 -0500
29857 +++ linux-2.6.37/fs/binfmt_misc.c 2011-01-17 02:41:01.000000000 -0500
29858 @@ -698,7 +698,7 @@ static int bm_fill_super(struct super_bl
29859 static struct tree_descr bm_files[] = {
29860 [2] = {"status", &bm_status_operations, S_IWUSR|S_IRUGO},
29861 [3] = {"register", &bm_register_operations, S_IWUSR},
29862 - /* last one */ {""}
29863 + /* last one */ {"", NULL, 0}
29864 };
29865 int err = simple_fill_super(sb, 0x42494e4d, bm_files);
29866 if (!err)
29867 diff -urNp linux-2.6.37/fs/bio.c linux-2.6.37/fs/bio.c
29868 --- linux-2.6.37/fs/bio.c 2011-01-04 19:50:19.000000000 -0500
29869 +++ linux-2.6.37/fs/bio.c 2011-01-17 02:41:01.000000000 -0500
29870 @@ -1233,7 +1233,7 @@ static void bio_copy_kern_endio(struct b
29871 const int read = bio_data_dir(bio) == READ;
29872 struct bio_map_data *bmd = bio->bi_private;
29873 int i;
29874 - char *p = bmd->sgvecs[0].iov_base;
29875 + char *p = (__force char *)bmd->sgvecs[0].iov_base;
29876
29877 __bio_for_each_segment(bvec, bio, i, 0) {
29878 char *addr = page_address(bvec->bv_page);
29879 diff -urNp linux-2.6.37/fs/block_dev.c linux-2.6.37/fs/block_dev.c
29880 --- linux-2.6.37/fs/block_dev.c 2011-01-04 19:50:19.000000000 -0500
29881 +++ linux-2.6.37/fs/block_dev.c 2011-01-17 02:41:01.000000000 -0500
29882 @@ -662,7 +662,7 @@ static bool bd_may_claim(struct block_de
29883 else if (bdev->bd_contains == bdev)
29884 return true; /* is a whole device which isn't held */
29885
29886 - else if (whole->bd_holder == bd_claim)
29887 + else if (whole->bd_holder == (void *)bd_claim)
29888 return true; /* is a partition of a device that is being partitioned */
29889 else if (whole->bd_holder != NULL)
29890 return false; /* is a partition of a held device */
29891 diff -urNp linux-2.6.37/fs/btrfs/ctree.c linux-2.6.37/fs/btrfs/ctree.c
29892 --- linux-2.6.37/fs/btrfs/ctree.c 2011-01-04 19:50:19.000000000 -0500
29893 +++ linux-2.6.37/fs/btrfs/ctree.c 2011-01-17 02:41:01.000000000 -0500
29894 @@ -466,9 +466,12 @@ static noinline int __btrfs_cow_block(st
29895 free_extent_buffer(buf);
29896 add_root_to_dirty_list(root);
29897 } else {
29898 - if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
29899 - parent_start = parent->start;
29900 - else
29901 + if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
29902 + if (parent)
29903 + parent_start = parent->start;
29904 + else
29905 + parent_start = 0;
29906 + } else
29907 parent_start = 0;
29908
29909 WARN_ON(trans->transid != btrfs_header_generation(parent));
29910 @@ -3768,7 +3771,6 @@ setup_items_for_insert(struct btrfs_tran
29911
29912 ret = 0;
29913 if (slot == 0) {
29914 - struct btrfs_disk_key disk_key;
29915 btrfs_cpu_key_to_disk(&disk_key, cpu_key);
29916 ret = fixup_low_keys(trans, root, path, &disk_key, 1);
29917 }
29918 diff -urNp linux-2.6.37/fs/btrfs/disk-io.c linux-2.6.37/fs/btrfs/disk-io.c
29919 --- linux-2.6.37/fs/btrfs/disk-io.c 2011-01-04 19:50:19.000000000 -0500
29920 +++ linux-2.6.37/fs/btrfs/disk-io.c 2011-01-17 02:41:01.000000000 -0500
29921 @@ -41,7 +41,7 @@
29922 #include "tree-log.h"
29923 #include "free-space-cache.h"
29924
29925 -static struct extent_io_ops btree_extent_io_ops;
29926 +static const struct extent_io_ops btree_extent_io_ops;
29927 static void end_workqueue_fn(struct btrfs_work *work);
29928 static void free_fs_root(struct btrfs_root *root);
29929
29930 @@ -2619,7 +2619,7 @@ out:
29931 return 0;
29932 }
29933
29934 -static struct extent_io_ops btree_extent_io_ops = {
29935 +static const struct extent_io_ops btree_extent_io_ops = {
29936 .write_cache_pages_lock_hook = btree_lock_page_hook,
29937 .readpage_end_io_hook = btree_readpage_end_io_hook,
29938 .submit_bio_hook = btree_submit_bio_hook,
29939 diff -urNp linux-2.6.37/fs/btrfs/extent_io.h linux-2.6.37/fs/btrfs/extent_io.h
29940 --- linux-2.6.37/fs/btrfs/extent_io.h 2011-01-04 19:50:19.000000000 -0500
29941 +++ linux-2.6.37/fs/btrfs/extent_io.h 2011-01-17 02:41:01.000000000 -0500
29942 @@ -51,36 +51,36 @@ typedef int (extent_submit_bio_hook_t)(s
29943 struct bio *bio, int mirror_num,
29944 unsigned long bio_flags, u64 bio_offset);
29945 struct extent_io_ops {
29946 - int (*fill_delalloc)(struct inode *inode, struct page *locked_page,
29947 + int (* const fill_delalloc)(struct inode *inode, struct page *locked_page,
29948 u64 start, u64 end, int *page_started,
29949 unsigned long *nr_written);
29950 - int (*writepage_start_hook)(struct page *page, u64 start, u64 end);
29951 - int (*writepage_io_hook)(struct page *page, u64 start, u64 end);
29952 + int (* const writepage_start_hook)(struct page *page, u64 start, u64 end);
29953 + int (* const writepage_io_hook)(struct page *page, u64 start, u64 end);
29954 extent_submit_bio_hook_t *submit_bio_hook;
29955 - int (*merge_bio_hook)(struct page *page, unsigned long offset,
29956 + int (* const merge_bio_hook)(struct page *page, unsigned long offset,
29957 size_t size, struct bio *bio,
29958 unsigned long bio_flags);
29959 - int (*readpage_io_hook)(struct page *page, u64 start, u64 end);
29960 - int (*readpage_io_failed_hook)(struct bio *bio, struct page *page,
29961 + int (* const readpage_io_hook)(struct page *page, u64 start, u64 end);
29962 + int (* const readpage_io_failed_hook)(struct bio *bio, struct page *page,
29963 u64 start, u64 end,
29964 struct extent_state *state);
29965 - int (*writepage_io_failed_hook)(struct bio *bio, struct page *page,
29966 + int (* const writepage_io_failed_hook)(struct bio *bio, struct page *page,
29967 u64 start, u64 end,
29968 struct extent_state *state);
29969 - int (*readpage_end_io_hook)(struct page *page, u64 start, u64 end,
29970 + int (* const readpage_end_io_hook)(struct page *page, u64 start, u64 end,
29971 struct extent_state *state);
29972 - int (*writepage_end_io_hook)(struct page *page, u64 start, u64 end,
29973 + int (* const writepage_end_io_hook)(struct page *page, u64 start, u64 end,
29974 struct extent_state *state, int uptodate);
29975 - int (*set_bit_hook)(struct inode *inode, struct extent_state *state,
29976 + int (* const set_bit_hook)(struct inode *inode, struct extent_state *state,
29977 int *bits);
29978 - int (*clear_bit_hook)(struct inode *inode, struct extent_state *state,
29979 + int (* const clear_bit_hook)(struct inode *inode, struct extent_state *state,
29980 int *bits);
29981 - int (*merge_extent_hook)(struct inode *inode,
29982 + int (* const merge_extent_hook)(struct inode *inode,
29983 struct extent_state *new,
29984 struct extent_state *other);
29985 - int (*split_extent_hook)(struct inode *inode,
29986 + int (* const split_extent_hook)(struct inode *inode,
29987 struct extent_state *orig, u64 split);
29988 - int (*write_cache_pages_lock_hook)(struct page *page);
29989 + int (* const write_cache_pages_lock_hook)(struct page *page);
29990 };
29991
29992 struct extent_io_tree {
29993 @@ -90,7 +90,7 @@ struct extent_io_tree {
29994 u64 dirty_bytes;
29995 spinlock_t lock;
29996 spinlock_t buffer_lock;
29997 - struct extent_io_ops *ops;
29998 + const struct extent_io_ops *ops;
29999 };
30000
30001 struct extent_state {
30002 diff -urNp linux-2.6.37/fs/btrfs/free-space-cache.c linux-2.6.37/fs/btrfs/free-space-cache.c
30003 --- linux-2.6.37/fs/btrfs/free-space-cache.c 2011-01-04 19:50:19.000000000 -0500
30004 +++ linux-2.6.37/fs/btrfs/free-space-cache.c 2011-01-17 02:41:01.000000000 -0500
30005 @@ -1828,8 +1828,6 @@ u64 btrfs_alloc_from_cluster(struct btrf
30006
30007 while(1) {
30008 if (entry->bytes < bytes || entry->offset < min_start) {
30009 - struct rb_node *node;
30010 -
30011 node = rb_next(&entry->offset_index);
30012 if (!node)
30013 break;
30014 @@ -1980,7 +1978,7 @@ again:
30015 */
30016 while (entry->bitmap || found_bitmap ||
30017 (!entry->bitmap && entry->bytes < min_bytes)) {
30018 - struct rb_node *node = rb_next(&entry->offset_index);
30019 + node = rb_next(&entry->offset_index);
30020
30021 if (entry->bitmap && entry->bytes > bytes + empty_size) {
30022 ret = btrfs_bitmap_cluster(block_group, entry, cluster,
30023 diff -urNp linux-2.6.37/fs/btrfs/inode.c linux-2.6.37/fs/btrfs/inode.c
30024 --- linux-2.6.37/fs/btrfs/inode.c 2011-01-04 19:50:19.000000000 -0500
30025 +++ linux-2.6.37/fs/btrfs/inode.c 2011-01-17 02:41:01.000000000 -0500
30026 @@ -64,7 +64,7 @@ static const struct inode_operations btr
30027 static const struct address_space_operations btrfs_aops;
30028 static const struct address_space_operations btrfs_symlink_aops;
30029 static const struct file_operations btrfs_dir_file_operations;
30030 -static struct extent_io_ops btrfs_extent_io_ops;
30031 +static const struct extent_io_ops btrfs_extent_io_ops;
30032
30033 static struct kmem_cache *btrfs_inode_cachep;
30034 struct kmem_cache *btrfs_trans_handle_cachep;
30035 @@ -7246,7 +7246,7 @@ static const struct file_operations btrf
30036 .fsync = btrfs_sync_file,
30037 };
30038
30039 -static struct extent_io_ops btrfs_extent_io_ops = {
30040 +static const struct extent_io_ops btrfs_extent_io_ops = {
30041 .fill_delalloc = run_delalloc_range,
30042 .submit_bio_hook = btrfs_submit_bio_hook,
30043 .merge_bio_hook = btrfs_merge_bio_hook,
30044 diff -urNp linux-2.6.37/fs/btrfs/relocation.c linux-2.6.37/fs/btrfs/relocation.c
30045 --- linux-2.6.37/fs/btrfs/relocation.c 2011-01-04 19:50:19.000000000 -0500
30046 +++ linux-2.6.37/fs/btrfs/relocation.c 2011-01-17 02:41:01.000000000 -0500
30047 @@ -1238,7 +1238,7 @@ static int __update_reloc_root(struct bt
30048 }
30049 spin_unlock(&rc->reloc_root_tree.lock);
30050
30051 - BUG_ON((struct btrfs_root *)node->data != root);
30052 + BUG_ON(!node || (struct btrfs_root *)node->data != root);
30053
30054 if (!del) {
30055 spin_lock(&rc->reloc_root_tree.lock);
30056 diff -urNp linux-2.6.37/fs/cachefiles/bind.c linux-2.6.37/fs/cachefiles/bind.c
30057 --- linux-2.6.37/fs/cachefiles/bind.c 2011-01-04 19:50:19.000000000 -0500
30058 +++ linux-2.6.37/fs/cachefiles/bind.c 2011-01-17 02:41:01.000000000 -0500
30059 @@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachef
30060 args);
30061
30062 /* start by checking things over */
30063 - ASSERT(cache->fstop_percent >= 0 &&
30064 - cache->fstop_percent < cache->fcull_percent &&
30065 + ASSERT(cache->fstop_percent < cache->fcull_percent &&
30066 cache->fcull_percent < cache->frun_percent &&
30067 cache->frun_percent < 100);
30068
30069 - ASSERT(cache->bstop_percent >= 0 &&
30070 - cache->bstop_percent < cache->bcull_percent &&
30071 + ASSERT(cache->bstop_percent < cache->bcull_percent &&
30072 cache->bcull_percent < cache->brun_percent &&
30073 cache->brun_percent < 100);
30074
30075 diff -urNp linux-2.6.37/fs/cachefiles/daemon.c linux-2.6.37/fs/cachefiles/daemon.c
30076 --- linux-2.6.37/fs/cachefiles/daemon.c 2011-01-04 19:50:19.000000000 -0500
30077 +++ linux-2.6.37/fs/cachefiles/daemon.c 2011-01-17 02:41:01.000000000 -0500
30078 @@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(st
30079 if (n > buflen)
30080 return -EMSGSIZE;
30081
30082 - if (copy_to_user(_buffer, buffer, n) != 0)
30083 + if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
30084 return -EFAULT;
30085
30086 return n;
30087 @@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(s
30088 if (test_bit(CACHEFILES_DEAD, &cache->flags))
30089 return -EIO;
30090
30091 - if (datalen < 0 || datalen > PAGE_SIZE - 1)
30092 + if (datalen > PAGE_SIZE - 1)
30093 return -EOPNOTSUPP;
30094
30095 /* drag the command string into the kernel so we can parse it */
30096 @@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struc
30097 if (args[0] != '%' || args[1] != '\0')
30098 return -EINVAL;
30099
30100 - if (fstop < 0 || fstop >= cache->fcull_percent)
30101 + if (fstop >= cache->fcull_percent)
30102 return cachefiles_daemon_range_error(cache, args);
30103
30104 cache->fstop_percent = fstop;
30105 @@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struc
30106 if (args[0] != '%' || args[1] != '\0')
30107 return -EINVAL;
30108
30109 - if (bstop < 0 || bstop >= cache->bcull_percent)
30110 + if (bstop >= cache->bcull_percent)
30111 return cachefiles_daemon_range_error(cache, args);
30112
30113 cache->bstop_percent = bstop;
30114 diff -urNp linux-2.6.37/fs/cachefiles/rdwr.c linux-2.6.37/fs/cachefiles/rdwr.c
30115 --- linux-2.6.37/fs/cachefiles/rdwr.c 2011-01-04 19:50:19.000000000 -0500
30116 +++ linux-2.6.37/fs/cachefiles/rdwr.c 2011-01-17 02:41:01.000000000 -0500
30117 @@ -945,7 +945,7 @@ int cachefiles_write_page(struct fscache
30118 old_fs = get_fs();
30119 set_fs(KERNEL_DS);
30120 ret = file->f_op->write(
30121 - file, (const void __user *) data, len, &pos);
30122 + file, (__force const void __user *) data, len, &pos);
30123 set_fs(old_fs);
30124 kunmap(page);
30125 if (ret != len)
30126 diff -urNp linux-2.6.37/fs/ceph/dir.c linux-2.6.37/fs/ceph/dir.c
30127 --- linux-2.6.37/fs/ceph/dir.c 2011-01-04 19:50:19.000000000 -0500
30128 +++ linux-2.6.37/fs/ceph/dir.c 2011-01-17 02:41:01.000000000 -0500
30129 @@ -223,7 +223,7 @@ static int ceph_readdir(struct file *fil
30130 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
30131 struct ceph_mds_client *mdsc = fsc->mdsc;
30132 unsigned frag = fpos_frag(filp->f_pos);
30133 - int off = fpos_off(filp->f_pos);
30134 + unsigned int off = fpos_off(filp->f_pos);
30135 int err;
30136 u32 ftype;
30137 struct ceph_mds_reply_info_parsed *rinfo;
30138 @@ -355,7 +355,7 @@ more:
30139 rinfo = &fi->last_readdir->r_reply_info;
30140 dout("readdir frag %x num %d off %d chunkoff %d\n", frag,
30141 rinfo->dir_nr, off, fi->offset);
30142 - while (off - fi->offset >= 0 && off - fi->offset < rinfo->dir_nr) {
30143 + while (off >= fi->offset && off - fi->offset < rinfo->dir_nr) {
30144 u64 pos = ceph_make_fpos(frag, off);
30145 struct ceph_mds_reply_inode *in =
30146 rinfo->dir_in[off - fi->offset].in;
30147 diff -urNp linux-2.6.37/fs/cifs/cifs_uniupr.h linux-2.6.37/fs/cifs/cifs_uniupr.h
30148 --- linux-2.6.37/fs/cifs/cifs_uniupr.h 2011-01-04 19:50:19.000000000 -0500
30149 +++ linux-2.6.37/fs/cifs/cifs_uniupr.h 2011-01-17 02:41:01.000000000 -0500
30150 @@ -132,7 +132,7 @@ const struct UniCaseRange CifsUniUpperRa
30151 {0x0490, 0x04cc, UniCaseRangeU0490},
30152 {0x1e00, 0x1ffc, UniCaseRangeU1e00},
30153 {0xff40, 0xff5a, UniCaseRangeUff40},
30154 - {0}
30155 + {0, 0, NULL}
30156 };
30157 #endif
30158
30159 diff -urNp linux-2.6.37/fs/cifs/link.c linux-2.6.37/fs/cifs/link.c
30160 --- linux-2.6.37/fs/cifs/link.c 2011-01-04 19:50:19.000000000 -0500
30161 +++ linux-2.6.37/fs/cifs/link.c 2011-01-17 02:41:01.000000000 -0500
30162 @@ -540,7 +540,7 @@ symlink_exit:
30163
30164 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
30165 {
30166 - char *p = nd_get_link(nd);
30167 + const char *p = nd_get_link(nd);
30168 if (!IS_ERR(p))
30169 kfree(p);
30170 }
30171 diff -urNp linux-2.6.37/fs/compat_binfmt_elf.c linux-2.6.37/fs/compat_binfmt_elf.c
30172 --- linux-2.6.37/fs/compat_binfmt_elf.c 2011-01-04 19:50:19.000000000 -0500
30173 +++ linux-2.6.37/fs/compat_binfmt_elf.c 2011-01-17 02:41:01.000000000 -0500
30174 @@ -30,11 +30,13 @@
30175 #undef elf_phdr
30176 #undef elf_shdr
30177 #undef elf_note
30178 +#undef elf_dyn
30179 #undef elf_addr_t
30180 #define elfhdr elf32_hdr
30181 #define elf_phdr elf32_phdr
30182 #define elf_shdr elf32_shdr
30183 #define elf_note elf32_note
30184 +#define elf_dyn Elf32_Dyn
30185 #define elf_addr_t Elf32_Addr
30186
30187 /*
30188 diff -urNp linux-2.6.37/fs/compat.c linux-2.6.37/fs/compat.c
30189 --- linux-2.6.37/fs/compat.c 2011-01-04 19:50:19.000000000 -0500
30190 +++ linux-2.6.37/fs/compat.c 2011-01-17 02:41:01.000000000 -0500
30191 @@ -592,7 +592,7 @@ ssize_t compat_rw_copy_check_uvector(int
30192 goto out;
30193
30194 ret = -EINVAL;
30195 - if (nr_segs > UIO_MAXIOV || nr_segs < 0)
30196 + if (nr_segs > UIO_MAXIOV)
30197 goto out;
30198 if (nr_segs > fast_segs) {
30199 ret = -ENOMEM;
30200 @@ -876,6 +876,7 @@ struct compat_old_linux_dirent {
30201
30202 struct compat_readdir_callback {
30203 struct compat_old_linux_dirent __user *dirent;
30204 + struct file * file;
30205 int result;
30206 };
30207
30208 @@ -893,6 +894,10 @@ static int compat_fillonedir(void *__buf
30209 buf->result = -EOVERFLOW;
30210 return -EOVERFLOW;
30211 }
30212 +
30213 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
30214 + return 0;
30215 +
30216 buf->result++;
30217 dirent = buf->dirent;
30218 if (!access_ok(VERIFY_WRITE, dirent,
30219 @@ -925,6 +930,7 @@ asmlinkage long compat_sys_old_readdir(u
30220
30221 buf.result = 0;
30222 buf.dirent = dirent;
30223 + buf.file = file;
30224
30225 error = vfs_readdir(file, compat_fillonedir, &buf);
30226 if (buf.result)
30227 @@ -945,6 +951,7 @@ struct compat_linux_dirent {
30228 struct compat_getdents_callback {
30229 struct compat_linux_dirent __user *current_dir;
30230 struct compat_linux_dirent __user *previous;
30231 + struct file * file;
30232 int count;
30233 int error;
30234 };
30235 @@ -966,6 +973,10 @@ static int compat_filldir(void *__buf, c
30236 buf->error = -EOVERFLOW;
30237 return -EOVERFLOW;
30238 }
30239 +
30240 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
30241 + return 0;
30242 +
30243 dirent = buf->previous;
30244 if (dirent) {
30245 if (__put_user(offset, &dirent->d_off))
30246 @@ -1013,6 +1024,7 @@ asmlinkage long compat_sys_getdents(unsi
30247 buf.previous = NULL;
30248 buf.count = count;
30249 buf.error = 0;
30250 + buf.file = file;
30251
30252 error = vfs_readdir(file, compat_filldir, &buf);
30253 if (error >= 0)
30254 @@ -1034,6 +1046,7 @@ out:
30255 struct compat_getdents_callback64 {
30256 struct linux_dirent64 __user *current_dir;
30257 struct linux_dirent64 __user *previous;
30258 + struct file * file;
30259 int count;
30260 int error;
30261 };
30262 @@ -1050,6 +1063,10 @@ static int compat_filldir64(void * __buf
30263 buf->error = -EINVAL; /* only used if we fail.. */
30264 if (reclen > buf->count)
30265 return -EINVAL;
30266 +
30267 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
30268 + return 0;
30269 +
30270 dirent = buf->previous;
30271
30272 if (dirent) {
30273 @@ -1101,6 +1118,7 @@ asmlinkage long compat_sys_getdents64(un
30274 buf.previous = NULL;
30275 buf.count = count;
30276 buf.error = 0;
30277 + buf.file = file;
30278
30279 error = vfs_readdir(file, compat_filldir64, &buf);
30280 if (error >= 0)
30281 @@ -1419,6 +1437,7 @@ static int compat_copy_strings(int argc,
30282
30283 page = get_arg_page(bprm, pos, 1);
30284 if (!page) {
30285 + /* We've exceed the stack rlimit. */
30286 ret = -E2BIG;
30287 goto out;
30288 }
30289 @@ -1460,6 +1479,11 @@ int compat_do_execve(char * filename,
30290 compat_uptr_t __user *envp,
30291 struct pt_regs * regs)
30292 {
30293 +#ifdef CONFIG_GRKERNSEC
30294 + struct file *old_exec_file;
30295 + struct acl_subject_label *old_acl;
30296 + struct rlimit old_rlim[RLIM_NLIMITS];
30297 +#endif
30298 struct linux_binprm *bprm;
30299 struct file *file;
30300 struct files_struct *displaced;
30301 @@ -1496,6 +1520,14 @@ int compat_do_execve(char * filename,
30302 bprm->filename = filename;
30303 bprm->interp = filename;
30304
30305 + gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
30306 + retval = -EAGAIN;
30307 + if (gr_handle_nproc())
30308 + goto out_file;
30309 + retval = -EACCES;
30310 + if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt))
30311 + goto out_file;
30312 +
30313 retval = bprm_mm_init(bprm);
30314 if (retval)
30315 goto out_file;
30316 @@ -1525,9 +1557,40 @@ int compat_do_execve(char * filename,
30317 if (retval < 0)
30318 goto out;
30319
30320 + if (!gr_tpe_allow(file)) {
30321 + retval = -EACCES;
30322 + goto out;
30323 + }
30324 +
30325 + if (gr_check_crash_exec(file)) {
30326 + retval = -EACCES;
30327 + goto out;
30328 + }
30329 +
30330 + gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
30331 +
30332 + gr_handle_exec_args_compat(bprm, argv);
30333 +
30334 +#ifdef CONFIG_GRKERNSEC
30335 + old_acl = current->acl;
30336 + memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
30337 + old_exec_file = current->exec_file;
30338 + get_file(file);
30339 + current->exec_file = file;
30340 +#endif
30341 +
30342 + retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
30343 + bprm->unsafe & LSM_UNSAFE_SHARE);
30344 + if (retval < 0)
30345 + goto out_fail;
30346 +
30347 retval = search_binary_handler(bprm, regs);
30348 if (retval < 0)
30349 - goto out;
30350 + goto out_fail;
30351 +#ifdef CONFIG_GRKERNSEC
30352 + if (old_exec_file)
30353 + fput(old_exec_file);
30354 +#endif
30355
30356 /* execve succeeded */
30357 current->fs->in_exec = 0;
30358 @@ -1538,6 +1601,14 @@ int compat_do_execve(char * filename,
30359 put_files_struct(displaced);
30360 return retval;
30361
30362 +out_fail:
30363 +#ifdef CONFIG_GRKERNSEC
30364 + current->acl = old_acl;
30365 + memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
30366 + fput(current->exec_file);
30367 + current->exec_file = old_exec_file;
30368 +#endif
30369 +
30370 out:
30371 if (bprm->mm) {
30372 acct_arg_size(bprm, 0);
30373 diff -urNp linux-2.6.37/fs/compat_ioctl.c linux-2.6.37/fs/compat_ioctl.c
30374 --- linux-2.6.37/fs/compat_ioctl.c 2011-01-04 19:50:19.000000000 -0500
30375 +++ linux-2.6.37/fs/compat_ioctl.c 2011-01-17 02:41:01.000000000 -0500
30376 @@ -208,6 +208,8 @@ static int do_video_set_spu_palette(unsi
30377
30378 err = get_user(palp, &up->palette);
30379 err |= get_user(length, &up->length);
30380 + if (err)
30381 + return -EFAULT;
30382
30383 up_native = compat_alloc_user_space(sizeof(struct video_spu_palette));
30384 err = put_user(compat_ptr(palp), &up_native->palette);
30385 @@ -1637,8 +1639,8 @@ asmlinkage long compat_sys_ioctl(unsigne
30386 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
30387 {
30388 unsigned int a, b;
30389 - a = *(unsigned int *)p;
30390 - b = *(unsigned int *)q;
30391 + a = *(const unsigned int *)p;
30392 + b = *(const unsigned int *)q;
30393 if (a > b)
30394 return 1;
30395 if (a < b)
30396 diff -urNp linux-2.6.37/fs/debugfs/inode.c linux-2.6.37/fs/debugfs/inode.c
30397 --- linux-2.6.37/fs/debugfs/inode.c 2011-01-04 19:50:19.000000000 -0500
30398 +++ linux-2.6.37/fs/debugfs/inode.c 2011-01-17 02:41:01.000000000 -0500
30399 @@ -130,7 +130,7 @@ static inline int debugfs_positive(struc
30400
30401 static int debug_fill_super(struct super_block *sb, void *data, int silent)
30402 {
30403 - static struct tree_descr debug_files[] = {{""}};
30404 + static struct tree_descr debug_files[] = {{"", NULL, 0}};
30405
30406 return simple_fill_super(sb, DEBUGFS_MAGIC, debug_files);
30407 }
30408 diff -urNp linux-2.6.37/fs/dlm/lockspace.c linux-2.6.37/fs/dlm/lockspace.c
30409 --- linux-2.6.37/fs/dlm/lockspace.c 2011-01-04 19:50:19.000000000 -0500
30410 +++ linux-2.6.37/fs/dlm/lockspace.c 2011-01-17 02:41:01.000000000 -0500
30411 @@ -200,7 +200,7 @@ static int dlm_uevent(struct kset *kset,
30412 return 0;
30413 }
30414
30415 -static struct kset_uevent_ops dlm_uevent_ops = {
30416 +static const struct kset_uevent_ops dlm_uevent_ops = {
30417 .uevent = dlm_uevent,
30418 };
30419
30420 diff -urNp linux-2.6.37/fs/ecryptfs/inode.c linux-2.6.37/fs/ecryptfs/inode.c
30421 --- linux-2.6.37/fs/ecryptfs/inode.c 2011-01-04 19:50:19.000000000 -0500
30422 +++ linux-2.6.37/fs/ecryptfs/inode.c 2011-01-17 02:41:01.000000000 -0500
30423 @@ -745,7 +745,7 @@ static int ecryptfs_readlink_lower(struc
30424 old_fs = get_fs();
30425 set_fs(get_ds());
30426 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
30427 - (char __user *)lower_buf,
30428 + (__force char __user *)lower_buf,
30429 lower_bufsiz);
30430 set_fs(old_fs);
30431 if (rc < 0)
30432 @@ -791,7 +791,7 @@ static void *ecryptfs_follow_link(struct
30433 }
30434 old_fs = get_fs();
30435 set_fs(get_ds());
30436 - rc = dentry->d_inode->i_op->readlink(dentry, (char __user *)buf, len);
30437 + rc = dentry->d_inode->i_op->readlink(dentry, (__force char __user *)buf, len);
30438 set_fs(old_fs);
30439 if (rc < 0) {
30440 kfree(buf);
30441 @@ -806,7 +806,7 @@ out:
30442 static void
30443 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
30444 {
30445 - char *buf = nd_get_link(nd);
30446 + const char *buf = nd_get_link(nd);
30447 if (!IS_ERR(buf)) {
30448 /* Free the char* */
30449 kfree(buf);
30450 diff -urNp linux-2.6.37/fs/ecryptfs/miscdev.c linux-2.6.37/fs/ecryptfs/miscdev.c
30451 --- linux-2.6.37/fs/ecryptfs/miscdev.c 2011-01-04 19:50:19.000000000 -0500
30452 +++ linux-2.6.37/fs/ecryptfs/miscdev.c 2011-01-17 02:41:01.000000000 -0500
30453 @@ -328,7 +328,7 @@ check_list:
30454 goto out_unlock_msg_ctx;
30455 i = 5;
30456 if (msg_ctx->msg) {
30457 - if (copy_to_user(&buf[i], packet_length, packet_length_size))
30458 + if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
30459 goto out_unlock_msg_ctx;
30460 i += packet_length_size;
30461 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
30462 diff -urNp linux-2.6.37/fs/exec.c linux-2.6.37/fs/exec.c
30463 --- linux-2.6.37/fs/exec.c 2011-01-04 19:50:19.000000000 -0500
30464 +++ linux-2.6.37/fs/exec.c 2011-01-17 02:41:01.000000000 -0500
30465 @@ -55,12 +55,24 @@
30466 #include <linux/fs_struct.h>
30467 #include <linux/pipe_fs_i.h>
30468 #include <linux/oom.h>
30469 +#include <linux/random.h>
30470 +#include <linux/seq_file.h>
30471 +
30472 +#ifdef CONFIG_PAX_REFCOUNT
30473 +#include <linux/kallsyms.h>
30474 +#include <linux/kdebug.h>
30475 +#endif
30476
30477 #include <asm/uaccess.h>
30478 #include <asm/mmu_context.h>
30479 #include <asm/tlb.h>
30480 #include "internal.h"
30481
30482 +#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
30483 +void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
30484 +EXPORT_SYMBOL(pax_set_initial_flags_func);
30485 +#endif
30486 +
30487 int core_uses_pid;
30488 char core_pattern[CORENAME_MAX_SIZE] = "core";
30489 unsigned int core_pipe_limit;
30490 @@ -120,7 +132,7 @@ SYSCALL_DEFINE1(uselib, const char __use
30491 goto out;
30492
30493 file = do_filp_open(AT_FDCWD, tmp,
30494 - O_LARGEFILE | O_RDONLY | FMODE_EXEC, 0,
30495 + O_LARGEFILE | O_RDONLY | FMODE_EXEC | FMODE_GREXEC, 0,
30496 MAY_READ | MAY_EXEC | MAY_OPEN);
30497 putname(tmp);
30498 error = PTR_ERR(file);
30499 @@ -187,18 +199,10 @@ struct page *get_arg_page(struct linux_b
30500 int write)
30501 {
30502 struct page *page;
30503 - int ret;
30504
30505 -#ifdef CONFIG_STACK_GROWSUP
30506 - if (write) {
30507 - ret = expand_stack_downwards(bprm->vma, pos);
30508 - if (ret < 0)
30509 - return NULL;
30510 - }
30511 -#endif
30512 - ret = get_user_pages(current, bprm->mm, pos,
30513 - 1, write, 1, &page, NULL);
30514 - if (ret <= 0)
30515 + if (0 > expand_stack_downwards(bprm->vma, pos))
30516 + return NULL;
30517 + if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
30518 return NULL;
30519
30520 if (write) {
30521 @@ -273,6 +277,11 @@ static int __bprm_mm_init(struct linux_b
30522 vma->vm_end = STACK_TOP_MAX;
30523 vma->vm_start = vma->vm_end - PAGE_SIZE;
30524 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
30525 +
30526 +#ifdef CONFIG_PAX_SEGMEXEC
30527 + vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
30528 +#endif
30529 +
30530 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
30531 INIT_LIST_HEAD(&vma->anon_vma_chain);
30532
30533 @@ -287,6 +296,12 @@ static int __bprm_mm_init(struct linux_b
30534 mm->stack_vm = mm->total_vm = 1;
30535 up_write(&mm->mmap_sem);
30536 bprm->p = vma->vm_end - sizeof(void *);
30537 +
30538 +#ifdef CONFIG_PAX_RANDUSTACK
30539 + if (randomize_va_space)
30540 + bprm->p ^= (pax_get_random_long() & ~15) & ~PAGE_MASK;
30541 +#endif
30542 +
30543 return 0;
30544 err:
30545 up_write(&mm->mmap_sem);
30546 @@ -522,7 +537,7 @@ int copy_strings_kernel(int argc, const
30547 int r;
30548 mm_segment_t oldfs = get_fs();
30549 set_fs(KERNEL_DS);
30550 - r = copy_strings(argc, (const char __user *const __user *)argv, bprm);
30551 + r = copy_strings(argc, (__force const char __user *const __user *)argv, bprm);
30552 set_fs(oldfs);
30553 return r;
30554 }
30555 @@ -552,7 +567,8 @@ static int shift_arg_pages(struct vm_are
30556 unsigned long new_end = old_end - shift;
30557 struct mmu_gather *tlb;
30558
30559 - BUG_ON(new_start > new_end);
30560 + if (new_start >= new_end || new_start < mmap_min_addr)
30561 + return -ENOMEM;
30562
30563 /*
30564 * ensure there are no vmas between where we want to go
30565 @@ -561,6 +577,10 @@ static int shift_arg_pages(struct vm_are
30566 if (vma != find_vma(mm, new_start))
30567 return -EFAULT;
30568
30569 +#ifdef CONFIG_PAX_SEGMEXEC
30570 + BUG_ON(pax_find_mirror_vma(vma));
30571 +#endif
30572 +
30573 /*
30574 * cover the whole range: [new_start, old_end)
30575 */
30576 @@ -641,10 +661,6 @@ int setup_arg_pages(struct linux_binprm
30577 stack_top = arch_align_stack(stack_top);
30578 stack_top = PAGE_ALIGN(stack_top);
30579
30580 - if (unlikely(stack_top < mmap_min_addr) ||
30581 - unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
30582 - return -ENOMEM;
30583 -
30584 stack_shift = vma->vm_end - stack_top;
30585
30586 bprm->p -= stack_shift;
30587 @@ -656,8 +672,28 @@ int setup_arg_pages(struct linux_binprm
30588 bprm->exec -= stack_shift;
30589
30590 down_write(&mm->mmap_sem);
30591 +
30592 + /* Move stack pages down in memory. */
30593 + if (stack_shift) {
30594 + ret = shift_arg_pages(vma, stack_shift);
30595 + if (ret)
30596 + goto out_unlock;
30597 + }
30598 +
30599 vm_flags = VM_STACK_FLAGS;
30600
30601 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
30602 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
30603 + vm_flags &= ~VM_EXEC;
30604 +
30605 +#ifdef CONFIG_PAX_MPROTECT
30606 + if (mm->pax_flags & MF_PAX_MPROTECT)
30607 + vm_flags &= ~VM_MAYEXEC;
30608 +#endif
30609 +
30610 + }
30611 +#endif
30612 +
30613 /*
30614 * Adjust stack execute permissions; explicitly enable for
30615 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
30616 @@ -676,13 +712,6 @@ int setup_arg_pages(struct linux_binprm
30617 goto out_unlock;
30618 BUG_ON(prev != vma);
30619
30620 - /* Move stack pages down in memory. */
30621 - if (stack_shift) {
30622 - ret = shift_arg_pages(vma, stack_shift);
30623 - if (ret)
30624 - goto out_unlock;
30625 - }
30626 -
30627 /* mprotect_fixup is overkill to remove the temporary stack flags */
30628 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
30629
30630 @@ -723,7 +752,7 @@ struct file *open_exec(const char *name)
30631 int err;
30632
30633 file = do_filp_open(AT_FDCWD, name,
30634 - O_LARGEFILE | O_RDONLY | FMODE_EXEC, 0,
30635 + O_LARGEFILE | O_RDONLY | FMODE_EXEC | FMODE_GREXEC, 0,
30636 MAY_EXEC | MAY_OPEN);
30637 if (IS_ERR(file))
30638 goto out;
30639 @@ -760,7 +789,7 @@ int kernel_read(struct file *file, loff_
30640 old_fs = get_fs();
30641 set_fs(get_ds());
30642 /* The cast to a user pointer is valid due to the set_fs() */
30643 - result = vfs_read(file, (void __user *)addr, count, &pos);
30644 + result = vfs_read(file, (__force void __user *)addr, count, &pos);
30645 set_fs(old_fs);
30646 return result;
30647 }
30648 @@ -1182,7 +1211,7 @@ int check_unsafe_exec(struct linux_binpr
30649 }
30650 rcu_read_unlock();
30651
30652 - if (p->fs->users > n_fs) {
30653 + if (atomic_read(&p->fs->users) > n_fs) {
30654 bprm->unsafe |= LSM_UNSAFE_SHARE;
30655 } else {
30656 res = -EAGAIN;
30657 @@ -1378,6 +1407,11 @@ int do_execve(const char * filename,
30658 const char __user *const __user *envp,
30659 struct pt_regs * regs)
30660 {
30661 +#ifdef CONFIG_GRKERNSEC
30662 + struct file *old_exec_file;
30663 + struct acl_subject_label *old_acl;
30664 + struct rlimit old_rlim[RLIM_NLIMITS];
30665 +#endif
30666 struct linux_binprm *bprm;
30667 struct file *file;
30668 struct files_struct *displaced;
30669 @@ -1414,6 +1448,18 @@ int do_execve(const char * filename,
30670 bprm->filename = filename;
30671 bprm->interp = filename;
30672
30673 + gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
30674 +
30675 + if (gr_handle_nproc()) {
30676 + retval = -EAGAIN;
30677 + goto out_file;
30678 + }
30679 +
30680 + if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
30681 + retval = -EACCES;
30682 + goto out_file;
30683 + }
30684 +
30685 retval = bprm_mm_init(bprm);
30686 if (retval)
30687 goto out_file;
30688 @@ -1443,9 +1489,40 @@ int do_execve(const char * filename,
30689 if (retval < 0)
30690 goto out;
30691
30692 + if (!gr_tpe_allow(file)) {
30693 + retval = -EACCES;
30694 + goto out;
30695 + }
30696 +
30697 + if (gr_check_crash_exec(file)) {
30698 + retval = -EACCES;
30699 + goto out;
30700 + }
30701 +
30702 + gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
30703 +
30704 + gr_handle_exec_args(bprm, argv);
30705 +
30706 +#ifdef CONFIG_GRKERNSEC
30707 + old_acl = current->acl;
30708 + memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
30709 + old_exec_file = current->exec_file;
30710 + get_file(file);
30711 + current->exec_file = file;
30712 +#endif
30713 +
30714 + retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
30715 + bprm->unsafe & LSM_UNSAFE_SHARE);
30716 + if (retval < 0)
30717 + goto out_fail;
30718 +
30719 retval = search_binary_handler(bprm,regs);
30720 if (retval < 0)
30721 - goto out;
30722 + goto out_fail;
30723 +#ifdef CONFIG_GRKERNSEC
30724 + if (old_exec_file)
30725 + fput(old_exec_file);
30726 +#endif
30727
30728 /* execve succeeded */
30729 current->fs->in_exec = 0;
30730 @@ -1456,6 +1533,14 @@ int do_execve(const char * filename,
30731 put_files_struct(displaced);
30732 return retval;
30733
30734 +out_fail:
30735 +#ifdef CONFIG_GRKERNSEC
30736 + current->acl = old_acl;
30737 + memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
30738 + fput(current->exec_file);
30739 + current->exec_file = old_exec_file;
30740 +#endif
30741 +
30742 out:
30743 if (bprm->mm) {
30744 acct_arg_size(bprm, 0);
30745 @@ -1642,6 +1727,217 @@ out:
30746 return ispipe;
30747 }
30748
30749 +int pax_check_flags(unsigned long *flags)
30750 +{
30751 + int retval = 0;
30752 +
30753 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
30754 + if (*flags & MF_PAX_SEGMEXEC)
30755 + {
30756 + *flags &= ~MF_PAX_SEGMEXEC;
30757 + retval = -EINVAL;
30758 + }
30759 +#endif
30760 +
30761 + if ((*flags & MF_PAX_PAGEEXEC)
30762 +
30763 +#ifdef CONFIG_PAX_PAGEEXEC
30764 + && (*flags & MF_PAX_SEGMEXEC)
30765 +#endif
30766 +
30767 + )
30768 + {
30769 + *flags &= ~MF_PAX_PAGEEXEC;
30770 + retval = -EINVAL;
30771 + }
30772 +
30773 + if ((*flags & MF_PAX_MPROTECT)
30774 +
30775 +#ifdef CONFIG_PAX_MPROTECT
30776 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
30777 +#endif
30778 +
30779 + )
30780 + {
30781 + *flags &= ~MF_PAX_MPROTECT;
30782 + retval = -EINVAL;
30783 + }
30784 +
30785 + if ((*flags & MF_PAX_EMUTRAMP)
30786 +
30787 +#ifdef CONFIG_PAX_EMUTRAMP
30788 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
30789 +#endif
30790 +
30791 + )
30792 + {
30793 + *flags &= ~MF_PAX_EMUTRAMP;
30794 + retval = -EINVAL;
30795 + }
30796 +
30797 + return retval;
30798 +}
30799 +
30800 +EXPORT_SYMBOL(pax_check_flags);
30801 +
30802 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
30803 +void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
30804 +{
30805 + struct task_struct *tsk = current;
30806 + struct mm_struct *mm = current->mm;
30807 + char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
30808 + char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
30809 + char *path_exec = NULL;
30810 + char *path_fault = NULL;
30811 + unsigned long start = 0UL, end = 0UL, offset = 0UL;
30812 +
30813 + if (buffer_exec && buffer_fault) {
30814 + struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
30815 +
30816 + down_read(&mm->mmap_sem);
30817 + vma = mm->mmap;
30818 + while (vma && (!vma_exec || !vma_fault)) {
30819 + if ((vma->vm_flags & VM_EXECUTABLE) && vma->vm_file)
30820 + vma_exec = vma;
30821 + if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
30822 + vma_fault = vma;
30823 + vma = vma->vm_next;
30824 + }
30825 + if (vma_exec) {
30826 + path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
30827 + if (IS_ERR(path_exec))
30828 + path_exec = "<path too long>";
30829 + else {
30830 + path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
30831 + if (path_exec) {
30832 + *path_exec = 0;
30833 + path_exec = buffer_exec;
30834 + } else
30835 + path_exec = "<path too long>";
30836 + }
30837 + }
30838 + if (vma_fault) {
30839 + start = vma_fault->vm_start;
30840 + end = vma_fault->vm_end;
30841 + offset = vma_fault->vm_pgoff << PAGE_SHIFT;
30842 + if (vma_fault->vm_file) {
30843 + path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
30844 + if (IS_ERR(path_fault))
30845 + path_fault = "<path too long>";
30846 + else {
30847 + path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
30848 + if (path_fault) {
30849 + *path_fault = 0;
30850 + path_fault = buffer_fault;
30851 + } else
30852 + path_fault = "<path too long>";
30853 + }
30854 + } else
30855 + path_fault = "<anonymous mapping>";
30856 + }
30857 + up_read(&mm->mmap_sem);
30858 + }
30859 + if (tsk->signal->curr_ip)
30860 + printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
30861 + else
30862 + printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
30863 + printk(KERN_ERR "PAX: terminating task: %s(%s):%d, uid/euid: %u/%u, "
30864 + "PC: %p, SP: %p\n", path_exec, tsk->comm, task_pid_nr(tsk),
30865 + task_uid(tsk), task_euid(tsk), pc, sp);
30866 + free_page((unsigned long)buffer_exec);
30867 + free_page((unsigned long)buffer_fault);
30868 + pax_report_insns(pc, sp);
30869 + do_coredump(SIGKILL, SIGKILL, regs);
30870 +}
30871 +#endif
30872 +
30873 +#ifdef CONFIG_PAX_REFCOUNT
30874 +void pax_report_refcount_overflow(struct pt_regs *regs)
30875 +{
30876 + if (current->signal->curr_ip)
30877 + printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
30878 + &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
30879 + else
30880 + printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
30881 + current->comm, task_pid_nr(current), current_uid(), current_euid());
30882 + print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
30883 + show_regs(regs);
30884 + force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
30885 +}
30886 +#endif
30887 +
30888 +#ifdef CONFIG_PAX_USERCOPY
30889 +/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
30890 +int object_is_on_stack(const void *obj, unsigned long len)
30891 +{
30892 + const void * const stack = task_stack_page(current);
30893 + const void * const stackend = stack + THREAD_SIZE;
30894 +
30895 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
30896 + const void *frame = NULL;
30897 + const void *oldframe;
30898 +#endif
30899 +
30900 + if (obj + len < obj)
30901 + return -1;
30902 +
30903 + if (obj + len <= stack || stackend <= obj)
30904 + return 0;
30905 +
30906 + if (obj < stack || stackend < obj + len)
30907 + return -1;
30908 +
30909 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
30910 + oldframe = __builtin_frame_address(1);
30911 + if (oldframe)
30912 + frame = __builtin_frame_address(2);
30913 + /*
30914 + low ----------------------------------------------> high
30915 + [saved bp][saved ip][args][local vars][saved bp][saved ip]
30916 + ^----------------^
30917 + allow copies only within here
30918 + */
30919 + while (stack <= frame && frame < stackend) {
30920 + /* if obj + len extends past the last frame, this
30921 + check won't pass and the next frame will be 0,
30922 + causing us to bail out and correctly report
30923 + the copy as invalid
30924 + */
30925 + if (obj + len <= frame)
30926 + return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
30927 + oldframe = frame;
30928 + frame = *(const void * const *)frame;
30929 + }
30930 + return -1;
30931 +#else
30932 + return 1;
30933 +#endif
30934 +}
30935 +
30936 +
30937 +void pax_report_leak_to_user(const void *ptr, unsigned long len)
30938 +{
30939 + if (current->signal->curr_ip)
30940 + printk(KERN_ERR "PAX: From %pI4: kernel memory leak attempt detected from %p (%lu bytes)\n",
30941 + &current->signal->curr_ip, ptr, len);
30942 + else
30943 + printk(KERN_ERR "PAX: kernel memory leak attempt detected from %p (%lu bytes)\n", ptr, len);
30944 + dump_stack();
30945 + do_group_exit(SIGKILL);
30946 +}
30947 +
30948 +void pax_report_overflow_from_user(const void *ptr, unsigned long len)
30949 +{
30950 + if (current->signal->curr_ip)
30951 + printk(KERN_ERR "PAX: From %pI4: kernel memory overflow attempt detected to %p (%lu bytes)\n",
30952 + &current->signal->curr_ip, ptr, len);
30953 + else
30954 + printk(KERN_ERR "PAX: kernel memory overflow attempt detected to %p (%lu bytes)\n", ptr, len);
30955 + dump_stack();
30956 + do_group_exit(SIGKILL);
30957 +}
30958 +#endif
30959 +
30960 static int zap_process(struct task_struct *start, int exit_code)
30961 {
30962 struct task_struct *t;
30963 @@ -1852,17 +2148,17 @@ static void wait_for_dump_helpers(struct
30964 pipe = file->f_path.dentry->d_inode->i_pipe;
30965
30966 pipe_lock(pipe);
30967 - pipe->readers++;
30968 - pipe->writers--;
30969 + atomic_inc(&pipe->readers);
30970 + atomic_dec(&pipe->writers);
30971
30972 - while ((pipe->readers > 1) && (!signal_pending(current))) {
30973 + while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
30974 wake_up_interruptible_sync(&pipe->wait);
30975 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
30976 pipe_wait(pipe);
30977 }
30978
30979 - pipe->readers--;
30980 - pipe->writers++;
30981 + atomic_dec(&pipe->readers);
30982 + atomic_inc(&pipe->writers);
30983 pipe_unlock(pipe);
30984
30985 }
30986 @@ -1978,6 +2274,10 @@ void do_coredump(long signr, int exit_co
30987 goto fail_corename;
30988 }
30989
30990 + if (signr == SIGKILL || signr == SIGILL)
30991 + gr_handle_brute_attach(current);
30992 + gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
30993 +
30994 if (ispipe) {
30995 int dump_count;
30996 char **helper_argv;
30997 diff -urNp linux-2.6.37/fs/ext2/balloc.c linux-2.6.37/fs/ext2/balloc.c
30998 --- linux-2.6.37/fs/ext2/balloc.c 2011-01-04 19:50:19.000000000 -0500
30999 +++ linux-2.6.37/fs/ext2/balloc.c 2011-01-17 02:41:01.000000000 -0500
31000 @@ -1192,7 +1192,7 @@ static int ext2_has_free_blocks(struct e
31001
31002 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
31003 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
31004 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
31005 + if (free_blocks < root_blocks + 1 && !capable_nolog(CAP_SYS_RESOURCE) &&
31006 sbi->s_resuid != current_fsuid() &&
31007 (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
31008 return 0;
31009 diff -urNp linux-2.6.37/fs/ext2/xattr.c linux-2.6.37/fs/ext2/xattr.c
31010 --- linux-2.6.37/fs/ext2/xattr.c 2011-01-04 19:50:19.000000000 -0500
31011 +++ linux-2.6.37/fs/ext2/xattr.c 2011-01-17 02:41:01.000000000 -0500
31012 @@ -86,8 +86,8 @@
31013 printk("\n"); \
31014 } while (0)
31015 #else
31016 -# define ea_idebug(f...)
31017 -# define ea_bdebug(f...)
31018 +# define ea_idebug(inode, f...) do {} while (0)
31019 +# define ea_bdebug(bh, f...) do {} while (0)
31020 #endif
31021
31022 static int ext2_xattr_set2(struct inode *, struct buffer_head *,
31023 diff -urNp linux-2.6.37/fs/ext3/balloc.c linux-2.6.37/fs/ext3/balloc.c
31024 --- linux-2.6.37/fs/ext3/balloc.c 2011-01-04 19:50:19.000000000 -0500
31025 +++ linux-2.6.37/fs/ext3/balloc.c 2011-01-17 02:41:01.000000000 -0500
31026 @@ -1425,7 +1425,7 @@ static int ext3_has_free_blocks(struct e
31027
31028 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
31029 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
31030 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
31031 + if (free_blocks < root_blocks + 1 && !capable_nolog(CAP_SYS_RESOURCE) &&
31032 sbi->s_resuid != current_fsuid() &&
31033 (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
31034 return 0;
31035 diff -urNp linux-2.6.37/fs/ext3/namei.c linux-2.6.37/fs/ext3/namei.c
31036 --- linux-2.6.37/fs/ext3/namei.c 2011-01-04 19:50:19.000000000 -0500
31037 +++ linux-2.6.37/fs/ext3/namei.c 2011-01-17 02:41:01.000000000 -0500
31038 @@ -1168,7 +1168,7 @@ static struct ext3_dir_entry_2 *do_split
31039 char *data1 = (*bh)->b_data, *data2;
31040 unsigned split, move, size;
31041 struct ext3_dir_entry_2 *de = NULL, *de2;
31042 - int err = 0, i;
31043 + int i, err = 0;
31044
31045 bh2 = ext3_append (handle, dir, &newblock, &err);
31046 if (!(bh2)) {
31047 diff -urNp linux-2.6.37/fs/ext3/xattr.c linux-2.6.37/fs/ext3/xattr.c
31048 --- linux-2.6.37/fs/ext3/xattr.c 2011-01-04 19:50:19.000000000 -0500
31049 +++ linux-2.6.37/fs/ext3/xattr.c 2011-01-17 02:41:01.000000000 -0500
31050 @@ -89,8 +89,8 @@
31051 printk("\n"); \
31052 } while (0)
31053 #else
31054 -# define ea_idebug(f...)
31055 -# define ea_bdebug(f...)
31056 +# define ea_idebug(f...) do {} while (0)
31057 +# define ea_bdebug(f...) do {} while (0)
31058 #endif
31059
31060 static void ext3_xattr_cache_insert(struct buffer_head *);
31061 diff -urNp linux-2.6.37/fs/ext4/balloc.c linux-2.6.37/fs/ext4/balloc.c
31062 --- linux-2.6.37/fs/ext4/balloc.c 2011-01-04 19:50:19.000000000 -0500
31063 +++ linux-2.6.37/fs/ext4/balloc.c 2011-01-17 02:41:01.000000000 -0500
31064 @@ -519,7 +519,7 @@ static int ext4_has_free_blocks(struct e
31065 /* Hm, nope. Are (enough) root reserved blocks available? */
31066 if (sbi->s_resuid == current_fsuid() ||
31067 ((sbi->s_resgid != 0) && in_group_p(sbi->s_resgid)) ||
31068 - capable(CAP_SYS_RESOURCE)) {
31069 + capable_nolog(CAP_SYS_RESOURCE)) {
31070 if (free_blocks >= (nblocks + dirty_blocks))
31071 return 1;
31072 }
31073 diff -urNp linux-2.6.37/fs/ext4/ext4.h linux-2.6.37/fs/ext4/ext4.h
31074 --- linux-2.6.37/fs/ext4/ext4.h 2011-01-04 19:50:19.000000000 -0500
31075 +++ linux-2.6.37/fs/ext4/ext4.h 2011-01-17 02:41:01.000000000 -0500
31076 @@ -1164,19 +1164,19 @@ struct ext4_sb_info {
31077 unsigned long s_mb_last_start;
31078
31079 /* stats for buddy allocator */
31080 - atomic_t s_bal_reqs; /* number of reqs with len > 1 */
31081 - atomic_t s_bal_success; /* we found long enough chunks */
31082 - atomic_t s_bal_allocated; /* in blocks */
31083 - atomic_t s_bal_ex_scanned; /* total extents scanned */
31084 - atomic_t s_bal_goals; /* goal hits */
31085 - atomic_t s_bal_breaks; /* too long searches */
31086 - atomic_t s_bal_2orders; /* 2^order hits */
31087 + atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
31088 + atomic_unchecked_t s_bal_success; /* we found long enough chunks */
31089 + atomic_unchecked_t s_bal_allocated; /* in blocks */
31090 + atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
31091 + atomic_unchecked_t s_bal_goals; /* goal hits */
31092 + atomic_unchecked_t s_bal_breaks; /* too long searches */
31093 + atomic_unchecked_t s_bal_2orders; /* 2^order hits */
31094 spinlock_t s_bal_lock;
31095 unsigned long s_mb_buddies_generated;
31096 unsigned long long s_mb_generation_time;
31097 - atomic_t s_mb_lost_chunks;
31098 - atomic_t s_mb_preallocated;
31099 - atomic_t s_mb_discarded;
31100 + atomic_unchecked_t s_mb_lost_chunks;
31101 + atomic_unchecked_t s_mb_preallocated;
31102 + atomic_unchecked_t s_mb_discarded;
31103 atomic_t s_lock_busy;
31104
31105 /* locality groups */
31106 diff -urNp linux-2.6.37/fs/ext4/mballoc.c linux-2.6.37/fs/ext4/mballoc.c
31107 --- linux-2.6.37/fs/ext4/mballoc.c 2011-01-04 19:50:19.000000000 -0500
31108 +++ linux-2.6.37/fs/ext4/mballoc.c 2011-01-17 02:41:01.000000000 -0500
31109 @@ -1841,7 +1841,7 @@ void ext4_mb_simple_scan_group(struct ex
31110 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
31111
31112 if (EXT4_SB(sb)->s_mb_stats)
31113 - atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
31114 + atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
31115
31116 break;
31117 }
31118 @@ -2135,7 +2135,7 @@ repeat:
31119 ac->ac_status = AC_STATUS_CONTINUE;
31120 ac->ac_flags |= EXT4_MB_HINT_FIRST;
31121 cr = 3;
31122 - atomic_inc(&sbi->s_mb_lost_chunks);
31123 + atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
31124 goto repeat;
31125 }
31126 }
31127 @@ -2577,25 +2577,25 @@ int ext4_mb_release(struct super_block *
31128 if (sbi->s_mb_stats) {
31129 printk(KERN_INFO
31130 "EXT4-fs: mballoc: %u blocks %u reqs (%u success)\n",
31131 - atomic_read(&sbi->s_bal_allocated),
31132 - atomic_read(&sbi->s_bal_reqs),
31133 - atomic_read(&sbi->s_bal_success));
31134 + atomic_read_unchecked(&sbi->s_bal_allocated),
31135 + atomic_read_unchecked(&sbi->s_bal_reqs),
31136 + atomic_read_unchecked(&sbi->s_bal_success));
31137 printk(KERN_INFO
31138 "EXT4-fs: mballoc: %u extents scanned, %u goal hits, "
31139 "%u 2^N hits, %u breaks, %u lost\n",
31140 - atomic_read(&sbi->s_bal_ex_scanned),
31141 - atomic_read(&sbi->s_bal_goals),
31142 - atomic_read(&sbi->s_bal_2orders),
31143 - atomic_read(&sbi->s_bal_breaks),
31144 - atomic_read(&sbi->s_mb_lost_chunks));
31145 + atomic_read_unchecked(&sbi->s_bal_ex_scanned),
31146 + atomic_read_unchecked(&sbi->s_bal_goals),
31147 + atomic_read_unchecked(&sbi->s_bal_2orders),
31148 + atomic_read_unchecked(&sbi->s_bal_breaks),
31149 + atomic_read_unchecked(&sbi->s_mb_lost_chunks));
31150 printk(KERN_INFO
31151 "EXT4-fs: mballoc: %lu generated and it took %Lu\n",
31152 sbi->s_mb_buddies_generated++,
31153 sbi->s_mb_generation_time);
31154 printk(KERN_INFO
31155 "EXT4-fs: mballoc: %u preallocated, %u discarded\n",
31156 - atomic_read(&sbi->s_mb_preallocated),
31157 - atomic_read(&sbi->s_mb_discarded));
31158 + atomic_read_unchecked(&sbi->s_mb_preallocated),
31159 + atomic_read_unchecked(&sbi->s_mb_discarded));
31160 }
31161
31162 free_percpu(sbi->s_locality_groups);
31163 @@ -3080,16 +3080,16 @@ static void ext4_mb_collect_stats(struct
31164 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
31165
31166 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
31167 - atomic_inc(&sbi->s_bal_reqs);
31168 - atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
31169 + atomic_inc_unchecked(&sbi->s_bal_reqs);
31170 + atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
31171 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
31172 - atomic_inc(&sbi->s_bal_success);
31173 - atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
31174 + atomic_inc_unchecked(&sbi->s_bal_success);
31175 + atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
31176 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
31177 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
31178 - atomic_inc(&sbi->s_bal_goals);
31179 + atomic_inc_unchecked(&sbi->s_bal_goals);
31180 if (ac->ac_found > sbi->s_mb_max_to_scan)
31181 - atomic_inc(&sbi->s_bal_breaks);
31182 + atomic_inc_unchecked(&sbi->s_bal_breaks);
31183 }
31184
31185 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
31186 @@ -3487,7 +3487,7 @@ ext4_mb_new_inode_pa(struct ext4_allocat
31187 trace_ext4_mb_new_inode_pa(ac, pa);
31188
31189 ext4_mb_use_inode_pa(ac, pa);
31190 - atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
31191 + atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
31192
31193 ei = EXT4_I(ac->ac_inode);
31194 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
31195 @@ -3547,7 +3547,7 @@ ext4_mb_new_group_pa(struct ext4_allocat
31196 trace_ext4_mb_new_group_pa(ac, pa);
31197
31198 ext4_mb_use_group_pa(ac, pa);
31199 - atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
31200 + atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
31201
31202 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
31203 lg = ac->ac_lg;
31204 @@ -3634,7 +3634,7 @@ ext4_mb_release_inode_pa(struct ext4_bud
31205 * from the bitmap and continue.
31206 */
31207 }
31208 - atomic_add(free, &sbi->s_mb_discarded);
31209 + atomic_add_unchecked(free, &sbi->s_mb_discarded);
31210
31211 return err;
31212 }
31213 @@ -3652,7 +3652,7 @@ ext4_mb_release_group_pa(struct ext4_bud
31214 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
31215 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
31216 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
31217 - atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
31218 + atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
31219 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
31220
31221 return 0;
31222 diff -urNp linux-2.6.37/fs/ext4/namei.c linux-2.6.37/fs/ext4/namei.c
31223 --- linux-2.6.37/fs/ext4/namei.c 2011-01-04 19:50:19.000000000 -0500
31224 +++ linux-2.6.37/fs/ext4/namei.c 2011-01-17 02:41:01.000000000 -0500
31225 @@ -1161,7 +1161,7 @@ static struct ext4_dir_entry_2 *do_split
31226 char *data1 = (*bh)->b_data, *data2;
31227 unsigned split, move, size;
31228 struct ext4_dir_entry_2 *de = NULL, *de2;
31229 - int err = 0, i;
31230 + int i, err = 0;
31231
31232 bh2 = ext4_append (handle, dir, &newblock, &err);
31233 if (!(bh2)) {
31234 diff -urNp linux-2.6.37/fs/ext4/xattr.c linux-2.6.37/fs/ext4/xattr.c
31235 --- linux-2.6.37/fs/ext4/xattr.c 2011-01-04 19:50:19.000000000 -0500
31236 +++ linux-2.6.37/fs/ext4/xattr.c 2011-01-17 02:41:01.000000000 -0500
31237 @@ -82,8 +82,8 @@
31238 printk("\n"); \
31239 } while (0)
31240 #else
31241 -# define ea_idebug(f...)
31242 -# define ea_bdebug(f...)
31243 +# define ea_idebug(inode, f...) do {} while (0)
31244 +# define ea_bdebug(bh, f...) do {} while (0)
31245 #endif
31246
31247 static void ext4_xattr_cache_insert(struct buffer_head *);
31248 diff -urNp linux-2.6.37/fs/fcntl.c linux-2.6.37/fs/fcntl.c
31249 --- linux-2.6.37/fs/fcntl.c 2011-01-04 19:50:19.000000000 -0500
31250 +++ linux-2.6.37/fs/fcntl.c 2011-01-17 02:53:49.000000000 -0500
31251 @@ -224,6 +224,11 @@ int __f_setown(struct file *filp, struct
31252 if (err)
31253 return err;
31254
31255 + if (gr_handle_chroot_fowner(pid, type))
31256 + return -ENOENT;
31257 + if (gr_check_protected_task_fowner(pid, type))
31258 + return -EACCES;
31259 +
31260 f_modown(filp, pid, type, force);
31261 return 0;
31262 }
31263 @@ -348,6 +353,7 @@ static long do_fcntl(int fd, unsigned in
31264 switch (cmd) {
31265 case F_DUPFD:
31266 case F_DUPFD_CLOEXEC:
31267 + gr_learn_resource(current, RLIMIT_NOFILE, arg, 0);
31268 if (arg >= rlimit(RLIMIT_NOFILE))
31269 break;
31270 err = alloc_fd(arg, cmd == F_DUPFD_CLOEXEC ? O_CLOEXEC : 0);
31271 @@ -808,14 +814,14 @@ static int __init fcntl_init(void)
31272 * Exceptions: O_NONBLOCK is a two bit define on parisc; O_NDELAY
31273 * is defined as O_NONBLOCK on some platforms and not on others.
31274 */
31275 - BUILD_BUG_ON(18 - 1 /* for O_RDONLY being 0 */ != HWEIGHT32(
31276 + BUILD_BUG_ON(19 - 1 /* for O_RDONLY being 0 */ != HWEIGHT32(
31277 O_RDONLY | O_WRONLY | O_RDWR |
31278 O_CREAT | O_EXCL | O_NOCTTY |
31279 O_TRUNC | O_APPEND | /* O_NONBLOCK | */
31280 __O_SYNC | O_DSYNC | FASYNC |
31281 O_DIRECT | O_LARGEFILE | O_DIRECTORY |
31282 O_NOFOLLOW | O_NOATIME | O_CLOEXEC |
31283 - FMODE_EXEC
31284 + FMODE_EXEC | FMODE_GREXEC
31285 ));
31286
31287 fasync_cache = kmem_cache_create("fasync_cache",
31288 diff -urNp linux-2.6.37/fs/fifo.c linux-2.6.37/fs/fifo.c
31289 --- linux-2.6.37/fs/fifo.c 2011-01-04 19:50:19.000000000 -0500
31290 +++ linux-2.6.37/fs/fifo.c 2011-01-17 02:41:01.000000000 -0500
31291 @@ -58,10 +58,10 @@ static int fifo_open(struct inode *inode
31292 */
31293 filp->f_op = &read_pipefifo_fops;
31294 pipe->r_counter++;
31295 - if (pipe->readers++ == 0)
31296 + if (atomic_inc_return(&pipe->readers) == 1)
31297 wake_up_partner(inode);
31298
31299 - if (!pipe->writers) {
31300 + if (!atomic_read(&pipe->writers)) {
31301 if ((filp->f_flags & O_NONBLOCK)) {
31302 /* suppress POLLHUP until we have
31303 * seen a writer */
31304 @@ -82,15 +82,15 @@ static int fifo_open(struct inode *inode
31305 * errno=ENXIO when there is no process reading the FIFO.
31306 */
31307 ret = -ENXIO;
31308 - if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
31309 + if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
31310 goto err;
31311
31312 filp->f_op = &write_pipefifo_fops;
31313 pipe->w_counter++;
31314 - if (!pipe->writers++)
31315 + if (atomic_inc_return(&pipe->writers) == 1)
31316 wake_up_partner(inode);
31317
31318 - if (!pipe->readers) {
31319 + if (!atomic_read(&pipe->readers)) {
31320 wait_for_partner(inode, &pipe->r_counter);
31321 if (signal_pending(current))
31322 goto err_wr;
31323 @@ -106,11 +106,11 @@ static int fifo_open(struct inode *inode
31324 */
31325 filp->f_op = &rdwr_pipefifo_fops;
31326
31327 - pipe->readers++;
31328 - pipe->writers++;
31329 + atomic_inc(&pipe->readers);
31330 + atomic_inc(&pipe->writers);
31331 pipe->r_counter++;
31332 pipe->w_counter++;
31333 - if (pipe->readers == 1 || pipe->writers == 1)
31334 + if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
31335 wake_up_partner(inode);
31336 break;
31337
31338 @@ -124,19 +124,19 @@ static int fifo_open(struct inode *inode
31339 return 0;
31340
31341 err_rd:
31342 - if (!--pipe->readers)
31343 + if (atomic_dec_and_test(&pipe->readers))
31344 wake_up_interruptible(&pipe->wait);
31345 ret = -ERESTARTSYS;
31346 goto err;
31347
31348 err_wr:
31349 - if (!--pipe->writers)
31350 + if (atomic_dec_and_test(&pipe->writers))
31351 wake_up_interruptible(&pipe->wait);
31352 ret = -ERESTARTSYS;
31353 goto err;
31354
31355 err:
31356 - if (!pipe->readers && !pipe->writers)
31357 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
31358 free_pipe_info(inode);
31359
31360 err_nocleanup:
31361 diff -urNp linux-2.6.37/fs/file.c linux-2.6.37/fs/file.c
31362 --- linux-2.6.37/fs/file.c 2011-01-04 19:50:19.000000000 -0500
31363 +++ linux-2.6.37/fs/file.c 2011-01-17 02:41:01.000000000 -0500
31364 @@ -14,6 +14,7 @@
31365 #include <linux/slab.h>
31366 #include <linux/vmalloc.h>
31367 #include <linux/file.h>
31368 +#include <linux/security.h>
31369 #include <linux/fdtable.h>
31370 #include <linux/bitops.h>
31371 #include <linux/interrupt.h>
31372 @@ -250,6 +251,7 @@ int expand_files(struct files_struct *fi
31373 * N.B. For clone tasks sharing a files structure, this test
31374 * will limit the total number of files that can be opened.
31375 */
31376 + gr_learn_resource(current, RLIMIT_NOFILE, nr, 0);
31377 if (nr >= rlimit(RLIMIT_NOFILE))
31378 return -EMFILE;
31379
31380 diff -urNp linux-2.6.37/fs/fs_struct.c linux-2.6.37/fs/fs_struct.c
31381 --- linux-2.6.37/fs/fs_struct.c 2011-01-04 19:50:19.000000000 -0500
31382 +++ linux-2.6.37/fs/fs_struct.c 2011-01-17 02:41:01.000000000 -0500
31383 @@ -4,6 +4,7 @@
31384 #include <linux/path.h>
31385 #include <linux/slab.h>
31386 #include <linux/fs_struct.h>
31387 +#include <linux/grsecurity.h>
31388
31389 /*
31390 * Replace the fs->{rootmnt,root} with {mnt,dentry}. Put the old values.
31391 @@ -17,6 +18,7 @@ void set_fs_root(struct fs_struct *fs, s
31392 old_root = fs->root;
31393 fs->root = *path;
31394 path_get(path);
31395 + gr_set_chroot_entries(current, path);
31396 spin_unlock(&fs->lock);
31397 if (old_root.dentry)
31398 path_put(&old_root);
31399 @@ -56,6 +58,7 @@ void chroot_fs_refs(struct path *old_roo
31400 && fs->root.mnt == old_root->mnt) {
31401 path_get(new_root);
31402 fs->root = *new_root;
31403 + gr_set_chroot_entries(p, new_root);
31404 count++;
31405 }
31406 if (fs->pwd.dentry == old_root->dentry
31407 @@ -89,7 +92,8 @@ void exit_fs(struct task_struct *tsk)
31408 task_lock(tsk);
31409 spin_lock(&fs->lock);
31410 tsk->fs = NULL;
31411 - kill = !--fs->users;
31412 + gr_clear_chroot_entries(tsk);
31413 + kill = !atomic_dec_return(&fs->users);
31414 spin_unlock(&fs->lock);
31415 task_unlock(tsk);
31416 if (kill)
31417 @@ -102,7 +106,7 @@ struct fs_struct *copy_fs_struct(struct
31418 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
31419 /* We don't need to lock fs - think why ;-) */
31420 if (fs) {
31421 - fs->users = 1;
31422 + atomic_set(&fs->users, 1);
31423 fs->in_exec = 0;
31424 spin_lock_init(&fs->lock);
31425 fs->umask = old->umask;
31426 @@ -122,8 +126,9 @@ int unshare_fs_struct(void)
31427
31428 task_lock(current);
31429 spin_lock(&fs->lock);
31430 - kill = !--fs->users;
31431 + kill = !atomic_dec_return(&fs->users);
31432 current->fs = new_fs;
31433 + gr_set_chroot_entries(current, &new_fs->root);
31434 spin_unlock(&fs->lock);
31435 task_unlock(current);
31436
31437 @@ -142,7 +147,7 @@ EXPORT_SYMBOL(current_umask);
31438
31439 /* to be mentioned only in INIT_TASK */
31440 struct fs_struct init_fs = {
31441 - .users = 1,
31442 + .users = ATOMIC_INIT(1),
31443 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
31444 .umask = 0022,
31445 };
31446 @@ -157,12 +162,13 @@ void daemonize_fs_struct(void)
31447 task_lock(current);
31448
31449 spin_lock(&init_fs.lock);
31450 - init_fs.users++;
31451 + atomic_inc(&init_fs.users);
31452 spin_unlock(&init_fs.lock);
31453
31454 spin_lock(&fs->lock);
31455 current->fs = &init_fs;
31456 - kill = !--fs->users;
31457 + gr_set_chroot_entries(current, &current->fs->root);
31458 + kill = !atomic_dec_return(&fs->users);
31459 spin_unlock(&fs->lock);
31460
31461 task_unlock(current);
31462 diff -urNp linux-2.6.37/fs/fuse/control.c linux-2.6.37/fs/fuse/control.c
31463 --- linux-2.6.37/fs/fuse/control.c 2011-01-04 19:50:19.000000000 -0500
31464 +++ linux-2.6.37/fs/fuse/control.c 2011-01-17 02:41:01.000000000 -0500
31465 @@ -298,7 +298,7 @@ void fuse_ctl_remove_conn(struct fuse_co
31466
31467 static int fuse_ctl_fill_super(struct super_block *sb, void *data, int silent)
31468 {
31469 - struct tree_descr empty_descr = {""};
31470 + struct tree_descr empty_descr = {"", NULL, 0};
31471 struct fuse_conn *fc;
31472 int err;
31473
31474 diff -urNp linux-2.6.37/fs/fuse/cuse.c linux-2.6.37/fs/fuse/cuse.c
31475 --- linux-2.6.37/fs/fuse/cuse.c 2011-01-04 19:50:19.000000000 -0500
31476 +++ linux-2.6.37/fs/fuse/cuse.c 2011-01-17 02:41:01.000000000 -0500
31477 @@ -530,8 +530,18 @@ static int cuse_channel_release(struct i
31478 return rc;
31479 }
31480
31481 -static struct file_operations cuse_channel_fops; /* initialized during init */
31482 -
31483 +static const struct file_operations cuse_channel_fops = { /* initialized during init */
31484 + .owner = THIS_MODULE,
31485 + .llseek = no_llseek,
31486 + .read = do_sync_read,
31487 + .aio_read = fuse_dev_read,
31488 + .write = do_sync_write,
31489 + .aio_write = fuse_dev_write,
31490 + .poll = fuse_dev_poll,
31491 + .open = cuse_channel_open,
31492 + .release = cuse_channel_release,
31493 + .fasync = fuse_dev_fasync,
31494 +};
31495
31496 /**************************************************************************
31497 * Misc stuff and module initializatiion
31498 @@ -577,12 +587,6 @@ static int __init cuse_init(void)
31499 for (i = 0; i < CUSE_CONNTBL_LEN; i++)
31500 INIT_LIST_HEAD(&cuse_conntbl[i]);
31501
31502 - /* inherit and extend fuse_dev_operations */
31503 - cuse_channel_fops = fuse_dev_operations;
31504 - cuse_channel_fops.owner = THIS_MODULE;
31505 - cuse_channel_fops.open = cuse_channel_open;
31506 - cuse_channel_fops.release = cuse_channel_release;
31507 -
31508 cuse_class = class_create(THIS_MODULE, "cuse");
31509 if (IS_ERR(cuse_class))
31510 return PTR_ERR(cuse_class);
31511 diff -urNp linux-2.6.37/fs/fuse/dev.c linux-2.6.37/fs/fuse/dev.c
31512 --- linux-2.6.37/fs/fuse/dev.c 2011-01-04 19:50:19.000000000 -0500
31513 +++ linux-2.6.37/fs/fuse/dev.c 2011-01-17 02:41:01.000000000 -0500
31514 @@ -1047,7 +1047,7 @@ static ssize_t fuse_dev_do_read(struct f
31515 return err;
31516 }
31517
31518 -static ssize_t fuse_dev_read(struct kiocb *iocb, const struct iovec *iov,
31519 +ssize_t fuse_dev_read(struct kiocb *iocb, const struct iovec *iov,
31520 unsigned long nr_segs, loff_t pos)
31521 {
31522 struct fuse_copy_state cs;
31523 @@ -1061,6 +1061,8 @@ static ssize_t fuse_dev_read(struct kioc
31524 return fuse_dev_do_read(fc, file, &cs, iov_length(iov, nr_segs));
31525 }
31526
31527 +EXPORT_SYMBOL_GPL(fuse_dev_read);
31528 +
31529 static int fuse_dev_pipe_buf_steal(struct pipe_inode_info *pipe,
31530 struct pipe_buffer *buf)
31531 {
31532 @@ -1104,7 +1106,7 @@ static ssize_t fuse_dev_splice_read(stru
31533 ret = 0;
31534 pipe_lock(pipe);
31535
31536 - if (!pipe->readers) {
31537 + if (!atomic_read(&pipe->readers)) {
31538 send_sig(SIGPIPE, current, 0);
31539 if (!ret)
31540 ret = -EPIPE;
31541 @@ -1597,7 +1599,7 @@ static ssize_t fuse_dev_do_write(struct
31542 return err;
31543 }
31544
31545 -static ssize_t fuse_dev_write(struct kiocb *iocb, const struct iovec *iov,
31546 +ssize_t fuse_dev_write(struct kiocb *iocb, const struct iovec *iov,
31547 unsigned long nr_segs, loff_t pos)
31548 {
31549 struct fuse_copy_state cs;
31550 @@ -1610,6 +1612,8 @@ static ssize_t fuse_dev_write(struct kio
31551 return fuse_dev_do_write(fc, &cs, iov_length(iov, nr_segs));
31552 }
31553
31554 +EXPORT_SYMBOL_GPL(fuse_dev_write);
31555 +
31556 static ssize_t fuse_dev_splice_write(struct pipe_inode_info *pipe,
31557 struct file *out, loff_t *ppos,
31558 size_t len, unsigned int flags)
31559 @@ -1688,7 +1692,7 @@ out:
31560 return ret;
31561 }
31562
31563 -static unsigned fuse_dev_poll(struct file *file, poll_table *wait)
31564 +unsigned fuse_dev_poll(struct file *file, poll_table *wait)
31565 {
31566 unsigned mask = POLLOUT | POLLWRNORM;
31567 struct fuse_conn *fc = fuse_get_conn(file);
31568 @@ -1707,6 +1711,8 @@ static unsigned fuse_dev_poll(struct fil
31569 return mask;
31570 }
31571
31572 +EXPORT_SYMBOL_GPL(fuse_dev_poll);
31573 +
31574 /*
31575 * Abort all requests on the given list (pending or processing)
31576 *
31577 @@ -1824,7 +1830,7 @@ int fuse_dev_release(struct inode *inode
31578 }
31579 EXPORT_SYMBOL_GPL(fuse_dev_release);
31580
31581 -static int fuse_dev_fasync(int fd, struct file *file, int on)
31582 +int fuse_dev_fasync(int fd, struct file *file, int on)
31583 {
31584 struct fuse_conn *fc = fuse_get_conn(file);
31585 if (!fc)
31586 @@ -1834,6 +1840,8 @@ static int fuse_dev_fasync(int fd, struc
31587 return fasync_helper(fd, file, on, &fc->fasync);
31588 }
31589
31590 +EXPORT_SYMBOL_GPL(fuse_dev_fasync);
31591 +
31592 const struct file_operations fuse_dev_operations = {
31593 .owner = THIS_MODULE,
31594 .llseek = no_llseek,
31595 diff -urNp linux-2.6.37/fs/fuse/dir.c linux-2.6.37/fs/fuse/dir.c
31596 --- linux-2.6.37/fs/fuse/dir.c 2011-01-04 19:50:19.000000000 -0500
31597 +++ linux-2.6.37/fs/fuse/dir.c 2011-01-17 02:41:01.000000000 -0500
31598 @@ -1127,7 +1127,7 @@ static char *read_link(struct dentry *de
31599 return link;
31600 }
31601
31602 -static void free_link(char *link)
31603 +static void free_link(const char *link)
31604 {
31605 if (!IS_ERR(link))
31606 free_page((unsigned long) link);
31607 diff -urNp linux-2.6.37/fs/fuse/fuse_i.h linux-2.6.37/fs/fuse/fuse_i.h
31608 --- linux-2.6.37/fs/fuse/fuse_i.h 2011-01-04 19:50:19.000000000 -0500
31609 +++ linux-2.6.37/fs/fuse/fuse_i.h 2011-01-17 02:41:01.000000000 -0500
31610 @@ -525,6 +525,16 @@ extern const struct file_operations fuse
31611
31612 extern const struct dentry_operations fuse_dentry_operations;
31613
31614 +extern ssize_t fuse_dev_read(struct kiocb *iocb, const struct iovec *iov,
31615 + unsigned long nr_segs, loff_t pos);
31616 +
31617 +extern ssize_t fuse_dev_write(struct kiocb *iocb, const struct iovec *iov,
31618 + unsigned long nr_segs, loff_t pos);
31619 +
31620 +extern unsigned fuse_dev_poll(struct file *file, poll_table *wait);
31621 +
31622 +extern int fuse_dev_fasync(int fd, struct file *file, int on);
31623 +
31624 /**
31625 * Inode to nodeid comparison.
31626 */
31627 diff -urNp linux-2.6.37/fs/hfs/inode.c linux-2.6.37/fs/hfs/inode.c
31628 --- linux-2.6.37/fs/hfs/inode.c 2011-01-04 19:50:19.000000000 -0500
31629 +++ linux-2.6.37/fs/hfs/inode.c 2011-01-17 02:41:01.000000000 -0500
31630 @@ -447,7 +447,7 @@ int hfs_write_inode(struct inode *inode,
31631
31632 if (S_ISDIR(main_inode->i_mode)) {
31633 if (fd.entrylength < sizeof(struct hfs_cat_dir))
31634 - /* panic? */;
31635 + {/* panic? */}
31636 hfs_bnode_read(fd.bnode, &rec, fd.entryoffset,
31637 sizeof(struct hfs_cat_dir));
31638 if (rec.type != HFS_CDR_DIR ||
31639 @@ -468,7 +468,7 @@ int hfs_write_inode(struct inode *inode,
31640 sizeof(struct hfs_cat_file));
31641 } else {
31642 if (fd.entrylength < sizeof(struct hfs_cat_file))
31643 - /* panic? */;
31644 + {/* panic? */}
31645 hfs_bnode_read(fd.bnode, &rec, fd.entryoffset,
31646 sizeof(struct hfs_cat_file));
31647 if (rec.type != HFS_CDR_FIL ||
31648 diff -urNp linux-2.6.37/fs/hfsplus/inode.c linux-2.6.37/fs/hfsplus/inode.c
31649 --- linux-2.6.37/fs/hfsplus/inode.c 2011-01-04 19:50:19.000000000 -0500
31650 +++ linux-2.6.37/fs/hfsplus/inode.c 2011-01-17 02:41:01.000000000 -0500
31651 @@ -478,7 +478,7 @@ int hfsplus_cat_read_inode(struct inode
31652 struct hfsplus_cat_folder *folder = &entry.folder;
31653
31654 if (fd->entrylength < sizeof(struct hfsplus_cat_folder))
31655 - /* panic? */;
31656 + {/* panic? */}
31657 hfs_bnode_read(fd->bnode, &entry, fd->entryoffset,
31658 sizeof(struct hfsplus_cat_folder));
31659 hfsplus_get_perms(inode, &folder->permissions, 1);
31660 @@ -495,7 +495,7 @@ int hfsplus_cat_read_inode(struct inode
31661 struct hfsplus_cat_file *file = &entry.file;
31662
31663 if (fd->entrylength < sizeof(struct hfsplus_cat_file))
31664 - /* panic? */;
31665 + {/* panic? */}
31666 hfs_bnode_read(fd->bnode, &entry, fd->entryoffset,
31667 sizeof(struct hfsplus_cat_file));
31668
31669 @@ -551,7 +551,7 @@ int hfsplus_cat_write_inode(struct inode
31670 struct hfsplus_cat_folder *folder = &entry.folder;
31671
31672 if (fd.entrylength < sizeof(struct hfsplus_cat_folder))
31673 - /* panic? */;
31674 + {/* panic? */}
31675 hfs_bnode_read(fd.bnode, &entry, fd.entryoffset,
31676 sizeof(struct hfsplus_cat_folder));
31677 /* simple node checks? */
31678 @@ -573,7 +573,7 @@ int hfsplus_cat_write_inode(struct inode
31679 struct hfsplus_cat_file *file = &entry.file;
31680
31681 if (fd.entrylength < sizeof(struct hfsplus_cat_file))
31682 - /* panic? */;
31683 + {/* panic? */}
31684 hfs_bnode_read(fd.bnode, &entry, fd.entryoffset,
31685 sizeof(struct hfsplus_cat_file));
31686 hfsplus_inode_write_fork(inode, &file->data_fork);
31687 diff -urNp linux-2.6.37/fs/hugetlbfs/inode.c linux-2.6.37/fs/hugetlbfs/inode.c
31688 --- linux-2.6.37/fs/hugetlbfs/inode.c 2011-01-04 19:50:19.000000000 -0500
31689 +++ linux-2.6.37/fs/hugetlbfs/inode.c 2011-01-17 02:41:01.000000000 -0500
31690 @@ -908,7 +908,7 @@ static struct file_system_type hugetlbfs
31691 .kill_sb = kill_litter_super,
31692 };
31693
31694 -static struct vfsmount *hugetlbfs_vfsmount;
31695 +struct vfsmount *hugetlbfs_vfsmount;
31696
31697 static int can_do_hugetlb_shm(void)
31698 {
31699 diff -urNp linux-2.6.37/fs/ioctl.c linux-2.6.37/fs/ioctl.c
31700 --- linux-2.6.37/fs/ioctl.c 2011-01-04 19:50:19.000000000 -0500
31701 +++ linux-2.6.37/fs/ioctl.c 2011-01-17 02:41:01.000000000 -0500
31702 @@ -86,7 +86,7 @@ int fiemap_fill_next_extent(struct fiema
31703 u64 phys, u64 len, u32 flags)
31704 {
31705 struct fiemap_extent extent;
31706 - struct fiemap_extent *dest = fieinfo->fi_extents_start;
31707 + struct fiemap_extent __user *dest = fieinfo->fi_extents_start;
31708
31709 /* only count the extents */
31710 if (fieinfo->fi_extents_max == 0) {
31711 @@ -196,7 +196,7 @@ static int ioctl_fiemap(struct file *fil
31712
31713 fieinfo.fi_flags = fiemap.fm_flags;
31714 fieinfo.fi_extents_max = fiemap.fm_extent_count;
31715 - fieinfo.fi_extents_start = (struct fiemap_extent *)(arg + sizeof(fiemap));
31716 + fieinfo.fi_extents_start = (struct fiemap_extent __user *)(arg + sizeof(fiemap));
31717
31718 if (fiemap.fm_extent_count != 0 &&
31719 !access_ok(VERIFY_WRITE, fieinfo.fi_extents_start,
31720 @@ -209,7 +209,7 @@ static int ioctl_fiemap(struct file *fil
31721 error = inode->i_op->fiemap(inode, &fieinfo, fiemap.fm_start, len);
31722 fiemap.fm_flags = fieinfo.fi_flags;
31723 fiemap.fm_mapped_extents = fieinfo.fi_extents_mapped;
31724 - if (copy_to_user((char *)arg, &fiemap, sizeof(fiemap)))
31725 + if (copy_to_user((__force char __user *)arg, &fiemap, sizeof(fiemap)))
31726 error = -EFAULT;
31727
31728 return error;
31729 diff -urNp linux-2.6.37/fs/jffs2/debug.h linux-2.6.37/fs/jffs2/debug.h
31730 --- linux-2.6.37/fs/jffs2/debug.h 2011-01-04 19:50:19.000000000 -0500
31731 +++ linux-2.6.37/fs/jffs2/debug.h 2011-01-17 02:41:01.000000000 -0500
31732 @@ -53,13 +53,13 @@
31733 #if CONFIG_JFFS2_FS_DEBUG > 0
31734 #define D1(x) x
31735 #else
31736 -#define D1(x)
31737 +#define D1(x) do {} while (0);
31738 #endif
31739
31740 #if CONFIG_JFFS2_FS_DEBUG > 1
31741 #define D2(x) x
31742 #else
31743 -#define D2(x)
31744 +#define D2(x) do {} while (0);
31745 #endif
31746
31747 /* The prefixes of JFFS2 messages */
31748 @@ -115,73 +115,73 @@
31749 #ifdef JFFS2_DBG_READINODE_MESSAGES
31750 #define dbg_readinode(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
31751 #else
31752 -#define dbg_readinode(fmt, ...)
31753 +#define dbg_readinode(fmt, ...) do {} while (0)
31754 #endif
31755 #ifdef JFFS2_DBG_READINODE2_MESSAGES
31756 #define dbg_readinode2(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
31757 #else
31758 -#define dbg_readinode2(fmt, ...)
31759 +#define dbg_readinode2(fmt, ...) do {} while (0)
31760 #endif
31761
31762 /* Fragtree build debugging messages */
31763 #ifdef JFFS2_DBG_FRAGTREE_MESSAGES
31764 #define dbg_fragtree(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
31765 #else
31766 -#define dbg_fragtree(fmt, ...)
31767 +#define dbg_fragtree(fmt, ...) do {} while (0)
31768 #endif
31769 #ifdef JFFS2_DBG_FRAGTREE2_MESSAGES
31770 #define dbg_fragtree2(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
31771 #else
31772 -#define dbg_fragtree2(fmt, ...)
31773 +#define dbg_fragtree2(fmt, ...) do {} while (0)
31774 #endif
31775
31776 /* Directory entry list manilulation debugging messages */
31777 #ifdef JFFS2_DBG_DENTLIST_MESSAGES
31778 #define dbg_dentlist(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
31779 #else
31780 -#define dbg_dentlist(fmt, ...)
31781 +#define dbg_dentlist(fmt, ...) do {} while (0)
31782 #endif
31783
31784 /* Print the messages about manipulating node_refs */
31785 #ifdef JFFS2_DBG_NODEREF_MESSAGES
31786 #define dbg_noderef(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
31787 #else
31788 -#define dbg_noderef(fmt, ...)
31789 +#define dbg_noderef(fmt, ...) do {} while (0)
31790 #endif
31791
31792 /* Manipulations with the list of inodes (JFFS2 inocache) */
31793 #ifdef JFFS2_DBG_INOCACHE_MESSAGES
31794 #define dbg_inocache(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
31795 #else
31796 -#define dbg_inocache(fmt, ...)
31797 +#define dbg_inocache(fmt, ...) do {} while (0)
31798 #endif
31799
31800 /* Summary debugging messages */
31801 #ifdef JFFS2_DBG_SUMMARY_MESSAGES
31802 #define dbg_summary(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
31803 #else
31804 -#define dbg_summary(fmt, ...)
31805 +#define dbg_summary(fmt, ...) do {} while (0)
31806 #endif
31807
31808 /* File system build messages */
31809 #ifdef JFFS2_DBG_FSBUILD_MESSAGES
31810 #define dbg_fsbuild(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
31811 #else
31812 -#define dbg_fsbuild(fmt, ...)
31813 +#define dbg_fsbuild(fmt, ...) do {} while (0)
31814 #endif
31815
31816 /* Watch the object allocations */
31817 #ifdef JFFS2_DBG_MEMALLOC_MESSAGES
31818 #define dbg_memalloc(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
31819 #else
31820 -#define dbg_memalloc(fmt, ...)
31821 +#define dbg_memalloc(fmt, ...) do {} while (0)
31822 #endif
31823
31824 /* Watch the XATTR subsystem */
31825 #ifdef JFFS2_DBG_XATTR_MESSAGES
31826 #define dbg_xattr(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
31827 #else
31828 -#define dbg_xattr(fmt, ...)
31829 +#define dbg_xattr(fmt, ...) do {} while (0)
31830 #endif
31831
31832 /* "Sanity" checks */
31833 diff -urNp linux-2.6.37/fs/jffs2/erase.c linux-2.6.37/fs/jffs2/erase.c
31834 --- linux-2.6.37/fs/jffs2/erase.c 2011-01-04 19:50:19.000000000 -0500
31835 +++ linux-2.6.37/fs/jffs2/erase.c 2011-01-17 02:41:01.000000000 -0500
31836 @@ -439,7 +439,8 @@ static void jffs2_mark_erased_block(stru
31837 struct jffs2_unknown_node marker = {
31838 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
31839 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
31840 - .totlen = cpu_to_je32(c->cleanmarker_size)
31841 + .totlen = cpu_to_je32(c->cleanmarker_size),
31842 + .hdr_crc = cpu_to_je32(0)
31843 };
31844
31845 jffs2_prealloc_raw_node_refs(c, jeb, 1);
31846 diff -urNp linux-2.6.37/fs/jffs2/summary.h linux-2.6.37/fs/jffs2/summary.h
31847 --- linux-2.6.37/fs/jffs2/summary.h 2011-01-04 19:50:19.000000000 -0500
31848 +++ linux-2.6.37/fs/jffs2/summary.h 2011-01-17 02:41:01.000000000 -0500
31849 @@ -194,18 +194,18 @@ int jffs2_sum_scan_sumnode(struct jffs2_
31850
31851 #define jffs2_sum_active() (0)
31852 #define jffs2_sum_init(a) (0)
31853 -#define jffs2_sum_exit(a)
31854 -#define jffs2_sum_disable_collecting(a)
31855 +#define jffs2_sum_exit(a) do {} while (0)
31856 +#define jffs2_sum_disable_collecting(a) do {} while (0)
31857 #define jffs2_sum_is_disabled(a) (0)
31858 -#define jffs2_sum_reset_collected(a)
31859 +#define jffs2_sum_reset_collected(a) do {} while (0)
31860 #define jffs2_sum_add_kvec(a,b,c,d) (0)
31861 -#define jffs2_sum_move_collected(a,b)
31862 +#define jffs2_sum_move_collected(a,b) do {} while (0)
31863 #define jffs2_sum_write_sumnode(a) (0)
31864 -#define jffs2_sum_add_padding_mem(a,b)
31865 -#define jffs2_sum_add_inode_mem(a,b,c)
31866 -#define jffs2_sum_add_dirent_mem(a,b,c)
31867 -#define jffs2_sum_add_xattr_mem(a,b,c)
31868 -#define jffs2_sum_add_xref_mem(a,b,c)
31869 +#define jffs2_sum_add_padding_mem(a,b) do {} while (0)
31870 +#define jffs2_sum_add_inode_mem(a,b,c) do {} while (0)
31871 +#define jffs2_sum_add_dirent_mem(a,b,c) do {} while (0)
31872 +#define jffs2_sum_add_xattr_mem(a,b,c) do {} while (0)
31873 +#define jffs2_sum_add_xref_mem(a,b,c) do {} while (0)
31874 #define jffs2_sum_scan_sumnode(a,b,c,d,e) (0)
31875
31876 #endif /* CONFIG_JFFS2_SUMMARY */
31877 diff -urNp linux-2.6.37/fs/jffs2/wbuf.c linux-2.6.37/fs/jffs2/wbuf.c
31878 --- linux-2.6.37/fs/jffs2/wbuf.c 2011-01-04 19:50:19.000000000 -0500
31879 +++ linux-2.6.37/fs/jffs2/wbuf.c 2011-01-17 02:41:01.000000000 -0500
31880 @@ -1012,7 +1012,8 @@ static const struct jffs2_unknown_node o
31881 {
31882 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
31883 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
31884 - .totlen = constant_cpu_to_je32(8)
31885 + .totlen = constant_cpu_to_je32(8),
31886 + .hdr_crc = constant_cpu_to_je32(0)
31887 };
31888
31889 /*
31890 diff -urNp linux-2.6.37/fs/Kconfig.binfmt linux-2.6.37/fs/Kconfig.binfmt
31891 --- linux-2.6.37/fs/Kconfig.binfmt 2011-01-04 19:50:19.000000000 -0500
31892 +++ linux-2.6.37/fs/Kconfig.binfmt 2011-01-17 02:41:01.000000000 -0500
31893 @@ -86,7 +86,7 @@ config HAVE_AOUT
31894
31895 config BINFMT_AOUT
31896 tristate "Kernel support for a.out and ECOFF binaries"
31897 - depends on HAVE_AOUT
31898 + depends on HAVE_AOUT && BROKEN
31899 ---help---
31900 A.out (Assembler.OUTput) is a set of formats for libraries and
31901 executables used in the earliest versions of UNIX. Linux used
31902 diff -urNp linux-2.6.37/fs/lockd/svc.c linux-2.6.37/fs/lockd/svc.c
31903 --- linux-2.6.37/fs/lockd/svc.c 2011-01-04 19:50:19.000000000 -0500
31904 +++ linux-2.6.37/fs/lockd/svc.c 2011-01-17 02:41:01.000000000 -0500
31905 @@ -41,7 +41,7 @@
31906
31907 static struct svc_program nlmsvc_program;
31908
31909 -struct nlmsvc_binding * nlmsvc_ops;
31910 +const struct nlmsvc_binding * nlmsvc_ops;
31911 EXPORT_SYMBOL_GPL(nlmsvc_ops);
31912
31913 static DEFINE_MUTEX(nlmsvc_mutex);
31914 diff -urNp linux-2.6.37/fs/locks.c linux-2.6.37/fs/locks.c
31915 --- linux-2.6.37/fs/locks.c 2011-01-04 19:50:19.000000000 -0500
31916 +++ linux-2.6.37/fs/locks.c 2011-01-17 02:41:01.000000000 -0500
31917 @@ -2050,16 +2050,16 @@ void locks_remove_flock(struct file *fil
31918 return;
31919
31920 if (filp->f_op && filp->f_op->flock) {
31921 - struct file_lock fl = {
31922 + struct file_lock flock = {
31923 .fl_pid = current->tgid,
31924 .fl_file = filp,
31925 .fl_flags = FL_FLOCK,
31926 .fl_type = F_UNLCK,
31927 .fl_end = OFFSET_MAX,
31928 };
31929 - filp->f_op->flock(filp, F_SETLKW, &fl);
31930 - if (fl.fl_ops && fl.fl_ops->fl_release_private)
31931 - fl.fl_ops->fl_release_private(&fl);
31932 + filp->f_op->flock(filp, F_SETLKW, &flock);
31933 + if (flock.fl_ops && flock.fl_ops->fl_release_private)
31934 + flock.fl_ops->fl_release_private(&flock);
31935 }
31936
31937 lock_flocks();
31938 diff -urNp linux-2.6.37/fs/namei.c linux-2.6.37/fs/namei.c
31939 --- linux-2.6.37/fs/namei.c 2011-01-04 19:50:19.000000000 -0500
31940 +++ linux-2.6.37/fs/namei.c 2011-01-17 02:46:52.000000000 -0500
31941 @@ -221,14 +221,6 @@ int generic_permission(struct inode *ino
31942 return ret;
31943
31944 /*
31945 - * Read/write DACs are always overridable.
31946 - * Executable DACs are overridable if at least one exec bit is set.
31947 - */
31948 - if (!(mask & MAY_EXEC) || execute_ok(inode))
31949 - if (capable(CAP_DAC_OVERRIDE))
31950 - return 0;
31951 -
31952 - /*
31953 * Searching includes executable on directories, else just read.
31954 */
31955 mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
31956 @@ -236,6 +228,14 @@ int generic_permission(struct inode *ino
31957 if (capable(CAP_DAC_READ_SEARCH))
31958 return 0;
31959
31960 + /*
31961 + * Read/write DACs are always overridable.
31962 + * Executable DACs are overridable if at least one exec bit is set.
31963 + */
31964 + if (!(mask & MAY_EXEC) || execute_ok(inode))
31965 + if (capable(CAP_DAC_OVERRIDE))
31966 + return 0;
31967 +
31968 return -EACCES;
31969 }
31970
31971 @@ -473,7 +473,8 @@ static int exec_permission(struct inode
31972 if (!ret)
31973 goto ok;
31974
31975 - if (capable(CAP_DAC_OVERRIDE) || capable(CAP_DAC_READ_SEARCH))
31976 + if (capable_nolog(CAP_DAC_OVERRIDE) || capable(CAP_DAC_READ_SEARCH) ||
31977 + capable(CAP_DAC_OVERRIDE))
31978 goto ok;
31979
31980 return ret;
31981 @@ -542,7 +543,7 @@ __do_follow_link(struct path *path, stru
31982 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
31983 error = PTR_ERR(*p);
31984 if (!IS_ERR(*p)) {
31985 - char *s = nd_get_link(nd);
31986 + const char *s = nd_get_link(nd);
31987 error = 0;
31988 if (s)
31989 error = __vfs_follow_link(nd, s);
31990 @@ -575,6 +576,13 @@ static inline int do_follow_link(struct
31991 err = security_inode_follow_link(path->dentry, nd);
31992 if (err)
31993 goto loop;
31994 +
31995 + if (gr_handle_follow_link(path->dentry->d_parent->d_inode,
31996 + path->dentry->d_inode, path->dentry, nd->path.mnt)) {
31997 + err = -EACCES;
31998 + goto loop;
31999 + }
32000 +
32001 current->link_count++;
32002 current->total_link_count++;
32003 nd->depth++;
32004 @@ -967,11 +975,18 @@ return_reval:
32005 break;
32006 }
32007 return_base:
32008 + if (!(nd->flags & LOOKUP_PARENT) && !gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
32009 + path_put(&nd->path);
32010 + return -ENOENT;
32011 + }
32012 return 0;
32013 out_dput:
32014 path_put_conditional(&next, nd);
32015 break;
32016 }
32017 + if (!(nd->flags & LOOKUP_PARENT) && !gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt))
32018 + err = -ENOENT;
32019 +
32020 path_put(&nd->path);
32021 return_err:
32022 return err;
32023 @@ -1397,6 +1412,30 @@ int vfs_create(struct inode *dir, struct
32024 return error;
32025 }
32026
32027 +/*
32028 + * Note that while the flag value (low two bits) for sys_open means:
32029 + * 00 - read-only
32030 + * 01 - write-only
32031 + * 10 - read-write
32032 + * 11 - special
32033 + * it is changed into
32034 + * 00 - no permissions needed
32035 + * 01 - read-permission
32036 + * 10 - write-permission
32037 + * 11 - read-write
32038 + * for the internal routines (ie open_namei()/follow_link() etc)
32039 + * This is more logical, and also allows the 00 "no perm needed"
32040 + * to be used for symlinks (where the permissions are checked
32041 + * later).
32042 + *
32043 +*/
32044 +static inline int open_to_namei_flags(int flag)
32045 +{
32046 + if ((flag+1) & O_ACCMODE)
32047 + flag++;
32048 + return flag;
32049 +}
32050 +
32051 int may_open(struct path *path, int acc_mode, int flag)
32052 {
32053 struct dentry *dentry = path->dentry;
32054 @@ -1445,7 +1484,26 @@ int may_open(struct path *path, int acc_
32055 /*
32056 * Ensure there are no outstanding leases on the file.
32057 */
32058 - return break_lease(inode, flag);
32059 + error = break_lease(inode, flag);
32060 + if (error)
32061 + return error;
32062 +
32063 + if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode)) {
32064 + error = -EPERM;
32065 + goto exit;
32066 + }
32067 +
32068 + if (gr_handle_rawio(inode)) {
32069 + error = -EPERM;
32070 + goto exit;
32071 + }
32072 +
32073 + if (!gr_acl_handle_open(dentry, path->mnt, open_to_namei_flags(flag))) {
32074 + error = -EACCES;
32075 + goto exit;
32076 + }
32077 +exit:
32078 + return error;
32079 }
32080
32081 static int handle_truncate(struct path *path)
32082 @@ -1479,6 +1537,12 @@ static int __open_namei_create(struct na
32083 {
32084 int error;
32085 struct dentry *dir = nd->path.dentry;
32086 + int flag = open_to_namei_flags(open_flag);
32087 +
32088 + if (!gr_acl_handle_creat(path->dentry, nd->path.dentry, nd->path.mnt, flag, mode)) {
32089 + error = -EACCES;
32090 + goto out_unlock;
32091 + }
32092
32093 if (!IS_POSIXACL(dir->d_inode))
32094 mode &= ~current_umask();
32095 @@ -1486,6 +1550,8 @@ static int __open_namei_create(struct na
32096 if (error)
32097 goto out_unlock;
32098 error = vfs_create(dir->d_inode, path->dentry, mode, nd);
32099 + if (!error)
32100 + gr_handle_create(path->dentry, nd->path.mnt);
32101 out_unlock:
32102 mutex_unlock(&dir->d_inode->i_mutex);
32103 dput(nd->path.dentry);
32104 @@ -1496,30 +1562,6 @@ out_unlock:
32105 return may_open(&nd->path, 0, open_flag & ~O_TRUNC);
32106 }
32107
32108 -/*
32109 - * Note that while the flag value (low two bits) for sys_open means:
32110 - * 00 - read-only
32111 - * 01 - write-only
32112 - * 10 - read-write
32113 - * 11 - special
32114 - * it is changed into
32115 - * 00 - no permissions needed
32116 - * 01 - read-permission
32117 - * 10 - write-permission
32118 - * 11 - read-write
32119 - * for the internal routines (ie open_namei()/follow_link() etc)
32120 - * This is more logical, and also allows the 00 "no perm needed"
32121 - * to be used for symlinks (where the permissions are checked
32122 - * later).
32123 - *
32124 -*/
32125 -static inline int open_to_namei_flags(int flag)
32126 -{
32127 - if ((flag+1) & O_ACCMODE)
32128 - flag++;
32129 - return flag;
32130 -}
32131 -
32132 static int open_will_truncate(int flag, struct inode *inode)
32133 {
32134 /*
32135 @@ -1589,6 +1631,7 @@ static struct file *do_last(struct namei
32136 int mode, const char *pathname)
32137 {
32138 struct dentry *dir = nd->path.dentry;
32139 + int flag = open_to_namei_flags(open_flag);
32140 struct file *filp;
32141 int error = -EISDIR;
32142
32143 @@ -1690,6 +1733,14 @@ static struct file *do_last(struct namei
32144 /*
32145 * It already exists.
32146 */
32147 +
32148 + /* only check if O_CREAT is specified, all other checks need to go
32149 + into may_open */
32150 + if (gr_handle_fifo(path->dentry, path->mnt, dir, flag, acc_mode)) {
32151 + error = -EACCES;
32152 + goto exit_mutex_unlock;
32153 + }
32154 +
32155 mutex_unlock(&dir->d_inode->i_mutex);
32156 audit_inode(pathname, path->dentry);
32157
32158 @@ -2013,6 +2064,17 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const
32159 error = may_mknod(mode);
32160 if (error)
32161 goto out_dput;
32162 +
32163 + if (gr_handle_chroot_mknod(dentry, nd.path.mnt, mode)) {
32164 + error = -EPERM;
32165 + goto out_dput;
32166 + }
32167 +
32168 + if (!gr_acl_handle_mknod(dentry, nd.path.dentry, nd.path.mnt, mode)) {
32169 + error = -EACCES;
32170 + goto out_dput;
32171 + }
32172 +
32173 error = mnt_want_write(nd.path.mnt);
32174 if (error)
32175 goto out_dput;
32176 @@ -2033,6 +2095,9 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const
32177 }
32178 out_drop_write:
32179 mnt_drop_write(nd.path.mnt);
32180 +
32181 + if (!error)
32182 + gr_handle_create(dentry, nd.path.mnt);
32183 out_dput:
32184 dput(dentry);
32185 out_unlock:
32186 @@ -2085,6 +2150,11 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const
32187 if (IS_ERR(dentry))
32188 goto out_unlock;
32189
32190 + if (!gr_acl_handle_mkdir(dentry, nd.path.dentry, nd.path.mnt)) {
32191 + error = -EACCES;
32192 + goto out_dput;
32193 + }
32194 +
32195 if (!IS_POSIXACL(nd.path.dentry->d_inode))
32196 mode &= ~current_umask();
32197 error = mnt_want_write(nd.path.mnt);
32198 @@ -2096,6 +2166,10 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const
32199 error = vfs_mkdir(nd.path.dentry->d_inode, dentry, mode);
32200 out_drop_write:
32201 mnt_drop_write(nd.path.mnt);
32202 +
32203 + if (!error)
32204 + gr_handle_create(dentry, nd.path.mnt);
32205 +
32206 out_dput:
32207 dput(dentry);
32208 out_unlock:
32209 @@ -2177,6 +2251,8 @@ static long do_rmdir(int dfd, const char
32210 char * name;
32211 struct dentry *dentry;
32212 struct nameidata nd;
32213 + ino_t saved_ino = 0;
32214 + dev_t saved_dev = 0;
32215
32216 error = user_path_parent(dfd, pathname, &nd, &name);
32217 if (error)
32218 @@ -2201,6 +2277,19 @@ static long do_rmdir(int dfd, const char
32219 error = PTR_ERR(dentry);
32220 if (IS_ERR(dentry))
32221 goto exit2;
32222 +
32223 + if (dentry->d_inode != NULL) {
32224 + if (dentry->d_inode->i_nlink <= 1) {
32225 + saved_ino = dentry->d_inode->i_ino;
32226 + saved_dev = dentry->d_inode->i_sb->s_dev;
32227 + }
32228 +
32229 + if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
32230 + error = -EACCES;
32231 + goto exit3;
32232 + }
32233 + }
32234 +
32235 error = mnt_want_write(nd.path.mnt);
32236 if (error)
32237 goto exit3;
32238 @@ -2208,6 +2297,8 @@ static long do_rmdir(int dfd, const char
32239 if (error)
32240 goto exit4;
32241 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
32242 + if (!error && (saved_dev || saved_ino))
32243 + gr_handle_delete(saved_ino, saved_dev);
32244 exit4:
32245 mnt_drop_write(nd.path.mnt);
32246 exit3:
32247 @@ -2270,6 +2361,8 @@ static long do_unlinkat(int dfd, const c
32248 struct dentry *dentry;
32249 struct nameidata nd;
32250 struct inode *inode = NULL;
32251 + ino_t saved_ino = 0;
32252 + dev_t saved_dev = 0;
32253
32254 error = user_path_parent(dfd, pathname, &nd, &name);
32255 if (error)
32256 @@ -2289,8 +2382,17 @@ static long do_unlinkat(int dfd, const c
32257 if (nd.last.name[nd.last.len])
32258 goto slashes;
32259 inode = dentry->d_inode;
32260 - if (inode)
32261 + if (inode) {
32262 ihold(inode);
32263 + if (inode->i_nlink <= 1) {
32264 + saved_ino = inode->i_ino;
32265 + saved_dev = inode->i_sb->s_dev;
32266 + }
32267 + if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
32268 + error = -EACCES;
32269 + goto exit2;
32270 + }
32271 + }
32272 error = mnt_want_write(nd.path.mnt);
32273 if (error)
32274 goto exit2;
32275 @@ -2298,6 +2400,8 @@ static long do_unlinkat(int dfd, const c
32276 if (error)
32277 goto exit3;
32278 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
32279 + if (!error && (saved_ino || saved_dev))
32280 + gr_handle_delete(saved_ino, saved_dev);
32281 exit3:
32282 mnt_drop_write(nd.path.mnt);
32283 exit2:
32284 @@ -2375,6 +2479,11 @@ SYSCALL_DEFINE3(symlinkat, const char __
32285 if (IS_ERR(dentry))
32286 goto out_unlock;
32287
32288 + if (!gr_acl_handle_symlink(dentry, nd.path.dentry, nd.path.mnt, from)) {
32289 + error = -EACCES;
32290 + goto out_dput;
32291 + }
32292 +
32293 error = mnt_want_write(nd.path.mnt);
32294 if (error)
32295 goto out_dput;
32296 @@ -2382,6 +2491,8 @@ SYSCALL_DEFINE3(symlinkat, const char __
32297 if (error)
32298 goto out_drop_write;
32299 error = vfs_symlink(nd.path.dentry->d_inode, dentry, from);
32300 + if (!error)
32301 + gr_handle_create(dentry, nd.path.mnt);
32302 out_drop_write:
32303 mnt_drop_write(nd.path.mnt);
32304 out_dput:
32305 @@ -2474,6 +2585,20 @@ SYSCALL_DEFINE5(linkat, int, olddfd, con
32306 error = PTR_ERR(new_dentry);
32307 if (IS_ERR(new_dentry))
32308 goto out_unlock;
32309 +
32310 + if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
32311 + old_path.dentry->d_inode,
32312 + old_path.dentry->d_inode->i_mode, to)) {
32313 + error = -EACCES;
32314 + goto out_dput;
32315 + }
32316 +
32317 + if (!gr_acl_handle_link(new_dentry, nd.path.dentry, nd.path.mnt,
32318 + old_path.dentry, old_path.mnt, to)) {
32319 + error = -EACCES;
32320 + goto out_dput;
32321 + }
32322 +
32323 error = mnt_want_write(nd.path.mnt);
32324 if (error)
32325 goto out_dput;
32326 @@ -2481,6 +2606,8 @@ SYSCALL_DEFINE5(linkat, int, olddfd, con
32327 if (error)
32328 goto out_drop_write;
32329 error = vfs_link(old_path.dentry, nd.path.dentry->d_inode, new_dentry);
32330 + if (!error)
32331 + gr_handle_create(new_dentry, nd.path.mnt);
32332 out_drop_write:
32333 mnt_drop_write(nd.path.mnt);
32334 out_dput:
32335 @@ -2714,6 +2841,12 @@ SYSCALL_DEFINE4(renameat, int, olddfd, c
32336 if (new_dentry == trap)
32337 goto exit5;
32338
32339 + error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
32340 + old_dentry, old_dir->d_inode, oldnd.path.mnt,
32341 + to);
32342 + if (error)
32343 + goto exit5;
32344 +
32345 error = mnt_want_write(oldnd.path.mnt);
32346 if (error)
32347 goto exit5;
32348 @@ -2723,6 +2856,9 @@ SYSCALL_DEFINE4(renameat, int, olddfd, c
32349 goto exit6;
32350 error = vfs_rename(old_dir->d_inode, old_dentry,
32351 new_dir->d_inode, new_dentry);
32352 + if (!error)
32353 + gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
32354 + new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
32355 exit6:
32356 mnt_drop_write(oldnd.path.mnt);
32357 exit5:
32358 diff -urNp linux-2.6.37/fs/namespace.c linux-2.6.37/fs/namespace.c
32359 --- linux-2.6.37/fs/namespace.c 2011-01-04 19:50:19.000000000 -0500
32360 +++ linux-2.6.37/fs/namespace.c 2011-01-17 02:41:01.000000000 -0500
32361 @@ -1141,6 +1141,9 @@ static int do_umount(struct vfsmount *mn
32362 if (!(sb->s_flags & MS_RDONLY))
32363 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
32364 up_write(&sb->s_umount);
32365 +
32366 + gr_log_remount(mnt->mnt_devname, retval);
32367 +
32368 return retval;
32369 }
32370
32371 @@ -1160,6 +1163,9 @@ static int do_umount(struct vfsmount *mn
32372 br_write_unlock(vfsmount_lock);
32373 up_write(&namespace_sem);
32374 release_mounts(&umount_list);
32375 +
32376 + gr_log_unmount(mnt->mnt_devname, retval);
32377 +
32378 return retval;
32379 }
32380
32381 @@ -2053,6 +2059,16 @@ long do_mount(char *dev_name, char *dir_
32382 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
32383 MS_STRICTATIME);
32384
32385 + if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
32386 + retval = -EPERM;
32387 + goto dput_out;
32388 + }
32389 +
32390 + if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
32391 + retval = -EPERM;
32392 + goto dput_out;
32393 + }
32394 +
32395 if (flags & MS_REMOUNT)
32396 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
32397 data_page);
32398 @@ -2067,6 +2083,9 @@ long do_mount(char *dev_name, char *dir_
32399 dev_name, data_page);
32400 dput_out:
32401 path_put(&path);
32402 +
32403 + gr_log_mount(dev_name, dir_name, retval);
32404 +
32405 return retval;
32406 }
32407
32408 @@ -2273,6 +2292,12 @@ SYSCALL_DEFINE2(pivot_root, const char _
32409 goto out1;
32410 }
32411
32412 + if (gr_handle_chroot_pivot()) {
32413 + error = -EPERM;
32414 + path_put(&old);
32415 + goto out1;
32416 + }
32417 +
32418 get_fs_root(current->fs, &root);
32419 down_write(&namespace_sem);
32420 mutex_lock(&old.dentry->d_inode->i_mutex);
32421 diff -urNp linux-2.6.37/fs/nfs/inode.c linux-2.6.37/fs/nfs/inode.c
32422 --- linux-2.6.37/fs/nfs/inode.c 2011-01-04 19:50:19.000000000 -0500
32423 +++ linux-2.6.37/fs/nfs/inode.c 2011-01-17 02:41:01.000000000 -0500
32424 @@ -985,16 +985,16 @@ static int nfs_size_need_update(const st
32425 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
32426 }
32427
32428 -static atomic_long_t nfs_attr_generation_counter;
32429 +static atomic_long_unchecked_t nfs_attr_generation_counter;
32430
32431 static unsigned long nfs_read_attr_generation_counter(void)
32432 {
32433 - return atomic_long_read(&nfs_attr_generation_counter);
32434 + return atomic_long_read_unchecked(&nfs_attr_generation_counter);
32435 }
32436
32437 unsigned long nfs_inc_attr_generation_counter(void)
32438 {
32439 - return atomic_long_inc_return(&nfs_attr_generation_counter);
32440 + return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
32441 }
32442
32443 void nfs_fattr_init(struct nfs_fattr *fattr)
32444 diff -urNp linux-2.6.37/fs/nfs/nfs4proc.c linux-2.6.37/fs/nfs/nfs4proc.c
32445 --- linux-2.6.37/fs/nfs/nfs4proc.c 2011-01-04 19:50:19.000000000 -0500
32446 +++ linux-2.6.37/fs/nfs/nfs4proc.c 2011-01-17 02:41:01.000000000 -0500
32447 @@ -1184,7 +1184,7 @@ static int _nfs4_do_open_reclaim(struct
32448 static int nfs4_do_open_reclaim(struct nfs_open_context *ctx, struct nfs4_state *state)
32449 {
32450 struct nfs_server *server = NFS_SERVER(state->inode);
32451 - struct nfs4_exception exception = { };
32452 + struct nfs4_exception exception = {0, 0};
32453 int err;
32454 do {
32455 err = _nfs4_do_open_reclaim(ctx, state);
32456 @@ -1226,7 +1226,7 @@ static int _nfs4_open_delegation_recall(
32457
32458 int nfs4_open_delegation_recall(struct nfs_open_context *ctx, struct nfs4_state *state, const nfs4_stateid *stateid)
32459 {
32460 - struct nfs4_exception exception = { };
32461 + struct nfs4_exception exception = {0, 0};
32462 struct nfs_server *server = NFS_SERVER(state->inode);
32463 int err;
32464 do {
32465 @@ -1602,7 +1602,7 @@ static int _nfs4_open_expired(struct nfs
32466 static int nfs4_do_open_expired(struct nfs_open_context *ctx, struct nfs4_state *state)
32467 {
32468 struct nfs_server *server = NFS_SERVER(state->inode);
32469 - struct nfs4_exception exception = { };
32470 + struct nfs4_exception exception = {0, 0};
32471 int err;
32472
32473 do {
32474 @@ -1717,7 +1717,7 @@ out_err:
32475
32476 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)
32477 {
32478 - struct nfs4_exception exception = { };
32479 + struct nfs4_exception exception = {0, 0};
32480 struct nfs4_state *res;
32481 int status;
32482
32483 @@ -1808,7 +1808,7 @@ static int nfs4_do_setattr(struct inode
32484 struct nfs4_state *state)
32485 {
32486 struct nfs_server *server = NFS_SERVER(inode);
32487 - struct nfs4_exception exception = { };
32488 + struct nfs4_exception exception = {0, 0};
32489 int err;
32490 do {
32491 err = nfs4_handle_exception(server,
32492 @@ -2081,7 +2081,7 @@ static int _nfs4_server_capabilities(str
32493
32494 int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle)
32495 {
32496 - struct nfs4_exception exception = { };
32497 + struct nfs4_exception exception = {0, 0};
32498 int err;
32499 do {
32500 err = nfs4_handle_exception(server,
32501 @@ -2115,7 +2115,7 @@ static int _nfs4_lookup_root(struct nfs_
32502 static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle,
32503 struct nfs_fsinfo *info)
32504 {
32505 - struct nfs4_exception exception = { };
32506 + struct nfs4_exception exception = {0, 0};
32507 int err;
32508 do {
32509 err = nfs4_handle_exception(server,
32510 @@ -2203,7 +2203,7 @@ static int _nfs4_proc_getattr(struct nfs
32511
32512 static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr)
32513 {
32514 - struct nfs4_exception exception = { };
32515 + struct nfs4_exception exception = {0, 0};
32516 int err;
32517 do {
32518 err = nfs4_handle_exception(server,
32519 @@ -2291,7 +2291,7 @@ static int nfs4_proc_lookupfh(struct nfs
32520 struct qstr *name, struct nfs_fh *fhandle,
32521 struct nfs_fattr *fattr)
32522 {
32523 - struct nfs4_exception exception = { };
32524 + struct nfs4_exception exception = {0, 0};
32525 int err;
32526 do {
32527 err = _nfs4_proc_lookupfh(server, dirfh, name, fhandle, fattr);
32528 @@ -2320,7 +2320,7 @@ static int _nfs4_proc_lookup(struct inod
32529
32530 static int nfs4_proc_lookup(struct inode *dir, struct qstr *name, struct nfs_fh *fhandle, struct nfs_fattr *fattr)
32531 {
32532 - struct nfs4_exception exception = { };
32533 + struct nfs4_exception exception = {0, 0};
32534 int err;
32535 do {
32536 err = nfs4_handle_exception(NFS_SERVER(dir),
32537 @@ -2387,7 +2387,7 @@ static int _nfs4_proc_access(struct inod
32538
32539 static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry)
32540 {
32541 - struct nfs4_exception exception = { };
32542 + struct nfs4_exception exception = {0, 0};
32543 int err;
32544 do {
32545 err = nfs4_handle_exception(NFS_SERVER(inode),
32546 @@ -2443,7 +2443,7 @@ static int _nfs4_proc_readlink(struct in
32547 static int nfs4_proc_readlink(struct inode *inode, struct page *page,
32548 unsigned int pgbase, unsigned int pglen)
32549 {
32550 - struct nfs4_exception exception = { };
32551 + struct nfs4_exception exception = {0, 0};
32552 int err;
32553 do {
32554 err = nfs4_handle_exception(NFS_SERVER(inode),
32555 @@ -2537,7 +2537,7 @@ out:
32556
32557 static int nfs4_proc_remove(struct inode *dir, struct qstr *name)
32558 {
32559 - struct nfs4_exception exception = { };
32560 + struct nfs4_exception exception = {0, 0};
32561 int err;
32562 do {
32563 err = nfs4_handle_exception(NFS_SERVER(dir),
32564 @@ -2642,7 +2642,7 @@ out:
32565 static int nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name,
32566 struct inode *new_dir, struct qstr *new_name)
32567 {
32568 - struct nfs4_exception exception = { };
32569 + struct nfs4_exception exception = {0, 0};
32570 int err;
32571 do {
32572 err = nfs4_handle_exception(NFS_SERVER(old_dir),
32573 @@ -2691,7 +2691,7 @@ out:
32574
32575 static int nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name)
32576 {
32577 - struct nfs4_exception exception = { };
32578 + struct nfs4_exception exception = {0, 0};
32579 int err;
32580 do {
32581 err = nfs4_handle_exception(NFS_SERVER(inode),
32582 @@ -2783,7 +2783,7 @@ out:
32583 static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry,
32584 struct page *page, unsigned int len, struct iattr *sattr)
32585 {
32586 - struct nfs4_exception exception = { };
32587 + struct nfs4_exception exception = {0, 0};
32588 int err;
32589 do {
32590 err = nfs4_handle_exception(NFS_SERVER(dir),
32591 @@ -2814,7 +2814,7 @@ out:
32592 static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry,
32593 struct iattr *sattr)
32594 {
32595 - struct nfs4_exception exception = { };
32596 + struct nfs4_exception exception = {0, 0};
32597 int err;
32598 do {
32599 err = nfs4_handle_exception(NFS_SERVER(dir),
32600 @@ -2866,7 +2866,7 @@ static int _nfs4_proc_readdir(struct den
32601 static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred,
32602 u64 cookie, struct page **pages, unsigned int count, int plus)
32603 {
32604 - struct nfs4_exception exception = { };
32605 + struct nfs4_exception exception = {0, 0};
32606 int err;
32607 do {
32608 err = nfs4_handle_exception(NFS_SERVER(dentry->d_inode),
32609 @@ -2914,7 +2914,7 @@ out:
32610 static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry,
32611 struct iattr *sattr, dev_t rdev)
32612 {
32613 - struct nfs4_exception exception = { };
32614 + struct nfs4_exception exception = {0, 0};
32615 int err;
32616 do {
32617 err = nfs4_handle_exception(NFS_SERVER(dir),
32618 @@ -2946,7 +2946,7 @@ static int _nfs4_proc_statfs(struct nfs_
32619
32620 static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat)
32621 {
32622 - struct nfs4_exception exception = { };
32623 + struct nfs4_exception exception = {0, 0};
32624 int err;
32625 do {
32626 err = nfs4_handle_exception(server,
32627 @@ -2977,7 +2977,7 @@ static int _nfs4_do_fsinfo(struct nfs_se
32628
32629 static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo)
32630 {
32631 - struct nfs4_exception exception = { };
32632 + struct nfs4_exception exception = {0, 0};
32633 int err;
32634
32635 do {
32636 @@ -3023,7 +3023,7 @@ static int _nfs4_proc_pathconf(struct nf
32637 static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle,
32638 struct nfs_pathconf *pathconf)
32639 {
32640 - struct nfs4_exception exception = { };
32641 + struct nfs4_exception exception = {0, 0};
32642 int err;
32643
32644 do {
32645 @@ -3340,7 +3340,7 @@ out_free:
32646
32647 static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen)
32648 {
32649 - struct nfs4_exception exception = { };
32650 + struct nfs4_exception exception = {0, 0};
32651 ssize_t ret;
32652 do {
32653 ret = __nfs4_get_acl_uncached(inode, buf, buflen);
32654 @@ -3405,7 +3405,7 @@ static int __nfs4_proc_set_acl(struct in
32655
32656 static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen)
32657 {
32658 - struct nfs4_exception exception = { };
32659 + struct nfs4_exception exception = {0, 0};
32660 int err;
32661 do {
32662 err = nfs4_handle_exception(NFS_SERVER(inode),
32663 @@ -3685,7 +3685,7 @@ out:
32664 int nfs4_proc_delegreturn(struct inode *inode, struct rpc_cred *cred, const nfs4_stateid *stateid, int issync)
32665 {
32666 struct nfs_server *server = NFS_SERVER(inode);
32667 - struct nfs4_exception exception = { };
32668 + struct nfs4_exception exception = {0, 0};
32669 int err;
32670 do {
32671 err = _nfs4_proc_delegreturn(inode, cred, stateid, issync);
32672 @@ -3758,7 +3758,7 @@ out:
32673
32674 static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request)
32675 {
32676 - struct nfs4_exception exception = { };
32677 + struct nfs4_exception exception = {0, 0};
32678 int err;
32679
32680 do {
32681 @@ -4167,7 +4167,7 @@ static int _nfs4_do_setlk(struct nfs4_st
32682 static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request)
32683 {
32684 struct nfs_server *server = NFS_SERVER(state->inode);
32685 - struct nfs4_exception exception = { };
32686 + struct nfs4_exception exception = {0, 0};
32687 int err;
32688
32689 do {
32690 @@ -4185,7 +4185,7 @@ static int nfs4_lock_reclaim(struct nfs4
32691 static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request)
32692 {
32693 struct nfs_server *server = NFS_SERVER(state->inode);
32694 - struct nfs4_exception exception = { };
32695 + struct nfs4_exception exception = {0, 0};
32696 int err;
32697
32698 err = nfs4_set_lock_state(state, request);
32699 @@ -4249,7 +4249,7 @@ out:
32700
32701 static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request)
32702 {
32703 - struct nfs4_exception exception = { };
32704 + struct nfs4_exception exception = {0, 0};
32705 int err;
32706
32707 do {
32708 @@ -4309,7 +4309,7 @@ nfs4_proc_lock(struct file *filp, int cm
32709 int nfs4_lock_delegation_recall(struct nfs4_state *state, struct file_lock *fl)
32710 {
32711 struct nfs_server *server = NFS_SERVER(state->inode);
32712 - struct nfs4_exception exception = { };
32713 + struct nfs4_exception exception = {0, 0};
32714 int err;
32715
32716 err = nfs4_set_lock_state(state, fl);
32717 diff -urNp linux-2.6.37/fs/nfsd/lockd.c linux-2.6.37/fs/nfsd/lockd.c
32718 --- linux-2.6.37/fs/nfsd/lockd.c 2011-01-04 19:50:19.000000000 -0500
32719 +++ linux-2.6.37/fs/nfsd/lockd.c 2011-01-17 02:41:01.000000000 -0500
32720 @@ -61,7 +61,7 @@ nlm_fclose(struct file *filp)
32721 fput(filp);
32722 }
32723
32724 -static struct nlmsvc_binding nfsd_nlm_ops = {
32725 +static const struct nlmsvc_binding nfsd_nlm_ops = {
32726 .fopen = nlm_fopen, /* open file for locking */
32727 .fclose = nlm_fclose, /* close file */
32728 };
32729 diff -urNp linux-2.6.37/fs/nfsd/nfsctl.c linux-2.6.37/fs/nfsd/nfsctl.c
32730 --- linux-2.6.37/fs/nfsd/nfsctl.c 2011-01-04 19:50:19.000000000 -0500
32731 +++ linux-2.6.37/fs/nfsd/nfsctl.c 2011-01-17 02:41:01.000000000 -0500
32732 @@ -178,7 +178,7 @@ static int export_features_open(struct i
32733 return single_open(file, export_features_show, NULL);
32734 }
32735
32736 -static struct file_operations export_features_operations = {
32737 +static const struct file_operations export_features_operations = {
32738 .open = export_features_open,
32739 .read = seq_read,
32740 .llseek = seq_lseek,
32741 diff -urNp linux-2.6.37/fs/nfsd/vfs.c linux-2.6.37/fs/nfsd/vfs.c
32742 --- linux-2.6.37/fs/nfsd/vfs.c 2011-01-04 19:50:19.000000000 -0500
32743 +++ linux-2.6.37/fs/nfsd/vfs.c 2011-01-17 02:41:01.000000000 -0500
32744 @@ -916,7 +916,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, st
32745 } else {
32746 oldfs = get_fs();
32747 set_fs(KERNEL_DS);
32748 - host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
32749 + host_err = vfs_readv(file, (__force struct iovec __user *)vec, vlen, &offset);
32750 set_fs(oldfs);
32751 }
32752
32753 @@ -1029,7 +1029,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, s
32754
32755 /* Write the data. */
32756 oldfs = get_fs(); set_fs(KERNEL_DS);
32757 - host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &offset);
32758 + host_err = vfs_writev(file, (__force struct iovec __user *)vec, vlen, &offset);
32759 set_fs(oldfs);
32760 if (host_err < 0)
32761 goto out_nfserr;
32762 @@ -1546,7 +1546,7 @@ nfsd_readlink(struct svc_rqst *rqstp, st
32763 */
32764
32765 oldfs = get_fs(); set_fs(KERNEL_DS);
32766 - host_err = inode->i_op->readlink(dentry, buf, *lenp);
32767 + host_err = inode->i_op->readlink(dentry, (__force char __user *)buf, *lenp);
32768 set_fs(oldfs);
32769
32770 if (host_err < 0)
32771 diff -urNp linux-2.6.37/fs/nls/nls_base.c linux-2.6.37/fs/nls/nls_base.c
32772 --- linux-2.6.37/fs/nls/nls_base.c 2011-01-04 19:50:19.000000000 -0500
32773 +++ linux-2.6.37/fs/nls/nls_base.c 2011-01-17 02:41:01.000000000 -0500
32774 @@ -41,7 +41,7 @@ static const struct utf8_table utf8_tabl
32775 {0xF8, 0xF0, 3*6, 0x1FFFFF, 0x10000, /* 4 byte sequence */},
32776 {0xFC, 0xF8, 4*6, 0x3FFFFFF, 0x200000, /* 5 byte sequence */},
32777 {0xFE, 0xFC, 5*6, 0x7FFFFFFF, 0x4000000, /* 6 byte sequence */},
32778 - {0, /* end of table */}
32779 + {0, 0, 0, 0, 0, /* end of table */}
32780 };
32781
32782 #define UNICODE_MAX 0x0010ffff
32783 diff -urNp linux-2.6.37/fs/ntfs/dir.c linux-2.6.37/fs/ntfs/dir.c
32784 --- linux-2.6.37/fs/ntfs/dir.c 2011-01-04 19:50:19.000000000 -0500
32785 +++ linux-2.6.37/fs/ntfs/dir.c 2011-01-17 02:41:01.000000000 -0500
32786 @@ -1329,7 +1329,7 @@ find_next_index_buffer:
32787 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
32788 ~(s64)(ndir->itype.index.block_size - 1)));
32789 /* Bounds checks. */
32790 - if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
32791 + if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
32792 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
32793 "inode 0x%lx or driver bug.", vdir->i_ino);
32794 goto err_out;
32795 diff -urNp linux-2.6.37/fs/ntfs/file.c linux-2.6.37/fs/ntfs/file.c
32796 --- linux-2.6.37/fs/ntfs/file.c 2011-01-04 19:50:19.000000000 -0500
32797 +++ linux-2.6.37/fs/ntfs/file.c 2011-01-17 02:41:01.000000000 -0500
32798 @@ -2223,6 +2223,6 @@ const struct inode_operations ntfs_file_
32799 #endif /* NTFS_RW */
32800 };
32801
32802 -const struct file_operations ntfs_empty_file_ops = {};
32803 +const struct file_operations ntfs_empty_file_ops __read_only;
32804
32805 -const struct inode_operations ntfs_empty_inode_ops = {};
32806 +const struct inode_operations ntfs_empty_inode_ops __read_only;
32807 diff -urNp linux-2.6.37/fs/ocfs2/localalloc.c linux-2.6.37/fs/ocfs2/localalloc.c
32808 --- linux-2.6.37/fs/ocfs2/localalloc.c 2011-01-04 19:50:19.000000000 -0500
32809 +++ linux-2.6.37/fs/ocfs2/localalloc.c 2011-01-17 02:41:01.000000000 -0500
32810 @@ -1307,7 +1307,7 @@ static int ocfs2_local_alloc_slide_windo
32811 goto bail;
32812 }
32813
32814 - atomic_inc(&osb->alloc_stats.moves);
32815 + atomic_inc_unchecked(&osb->alloc_stats.moves);
32816
32817 bail:
32818 if (handle)
32819 diff -urNp linux-2.6.37/fs/ocfs2/ocfs2.h linux-2.6.37/fs/ocfs2/ocfs2.h
32820 --- linux-2.6.37/fs/ocfs2/ocfs2.h 2011-01-04 19:50:19.000000000 -0500
32821 +++ linux-2.6.37/fs/ocfs2/ocfs2.h 2011-01-17 02:41:01.000000000 -0500
32822 @@ -230,11 +230,11 @@ enum ocfs2_vol_state
32823
32824 struct ocfs2_alloc_stats
32825 {
32826 - atomic_t moves;
32827 - atomic_t local_data;
32828 - atomic_t bitmap_data;
32829 - atomic_t bg_allocs;
32830 - atomic_t bg_extends;
32831 + atomic_unchecked_t moves;
32832 + atomic_unchecked_t local_data;
32833 + atomic_unchecked_t bitmap_data;
32834 + atomic_unchecked_t bg_allocs;
32835 + atomic_unchecked_t bg_extends;
32836 };
32837
32838 enum ocfs2_local_alloc_state
32839 diff -urNp linux-2.6.37/fs/ocfs2/suballoc.c linux-2.6.37/fs/ocfs2/suballoc.c
32840 --- linux-2.6.37/fs/ocfs2/suballoc.c 2011-01-04 19:50:19.000000000 -0500
32841 +++ linux-2.6.37/fs/ocfs2/suballoc.c 2011-01-17 02:41:01.000000000 -0500
32842 @@ -877,7 +877,7 @@ static int ocfs2_reserve_suballoc_bits(s
32843 mlog_errno(status);
32844 goto bail;
32845 }
32846 - atomic_inc(&osb->alloc_stats.bg_extends);
32847 + atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
32848
32849 /* You should never ask for this much metadata */
32850 BUG_ON(bits_wanted >
32851 @@ -2012,7 +2012,7 @@ int ocfs2_claim_metadata(handle_t *handl
32852 mlog_errno(status);
32853 goto bail;
32854 }
32855 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
32856 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
32857
32858 *suballoc_loc = res.sr_bg_blkno;
32859 *suballoc_bit_start = res.sr_bit_offset;
32860 @@ -2219,7 +2219,7 @@ int ocfs2_claim_new_inode(handle_t *hand
32861 mlog_errno(status);
32862 goto bail;
32863 }
32864 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
32865 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
32866
32867 BUG_ON(res.sr_bits != 1);
32868
32869 @@ -2324,7 +2324,7 @@ int __ocfs2_claim_clusters(handle_t *han
32870 cluster_start,
32871 num_clusters);
32872 if (!status)
32873 - atomic_inc(&osb->alloc_stats.local_data);
32874 + atomic_inc_unchecked(&osb->alloc_stats.local_data);
32875 } else {
32876 if (min_clusters > (osb->bitmap_cpg - 1)) {
32877 /* The only paths asking for contiguousness
32878 @@ -2350,7 +2350,7 @@ int __ocfs2_claim_clusters(handle_t *han
32879 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
32880 res.sr_bg_blkno,
32881 res.sr_bit_offset);
32882 - atomic_inc(&osb->alloc_stats.bitmap_data);
32883 + atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
32884 *num_clusters = res.sr_bits;
32885 }
32886 }
32887 diff -urNp linux-2.6.37/fs/ocfs2/super.c linux-2.6.37/fs/ocfs2/super.c
32888 --- linux-2.6.37/fs/ocfs2/super.c 2011-01-04 19:50:19.000000000 -0500
32889 +++ linux-2.6.37/fs/ocfs2/super.c 2011-01-17 02:41:01.000000000 -0500
32890 @@ -297,11 +297,11 @@ static int ocfs2_osb_dump(struct ocfs2_s
32891 "%10s => GlobalAllocs: %d LocalAllocs: %d "
32892 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
32893 "Stats",
32894 - atomic_read(&osb->alloc_stats.bitmap_data),
32895 - atomic_read(&osb->alloc_stats.local_data),
32896 - atomic_read(&osb->alloc_stats.bg_allocs),
32897 - atomic_read(&osb->alloc_stats.moves),
32898 - atomic_read(&osb->alloc_stats.bg_extends));
32899 + atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
32900 + atomic_read_unchecked(&osb->alloc_stats.local_data),
32901 + atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
32902 + atomic_read_unchecked(&osb->alloc_stats.moves),
32903 + atomic_read_unchecked(&osb->alloc_stats.bg_extends));
32904
32905 out += snprintf(buf + out, len - out,
32906 "%10s => State: %u Descriptor: %llu Size: %u bits "
32907 @@ -2122,11 +2122,11 @@ static int ocfs2_initialize_super(struct
32908 spin_lock_init(&osb->osb_xattr_lock);
32909 ocfs2_init_steal_slots(osb);
32910
32911 - atomic_set(&osb->alloc_stats.moves, 0);
32912 - atomic_set(&osb->alloc_stats.local_data, 0);
32913 - atomic_set(&osb->alloc_stats.bitmap_data, 0);
32914 - atomic_set(&osb->alloc_stats.bg_allocs, 0);
32915 - atomic_set(&osb->alloc_stats.bg_extends, 0);
32916 + atomic_set_unchecked(&osb->alloc_stats.moves, 0);
32917 + atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
32918 + atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
32919 + atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
32920 + atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
32921
32922 /* Copy the blockcheck stats from the superblock probe */
32923 osb->osb_ecc_stats = *stats;
32924 diff -urNp linux-2.6.37/fs/ocfs2/symlink.c linux-2.6.37/fs/ocfs2/symlink.c
32925 --- linux-2.6.37/fs/ocfs2/symlink.c 2011-01-04 19:50:19.000000000 -0500
32926 +++ linux-2.6.37/fs/ocfs2/symlink.c 2011-01-17 02:41:01.000000000 -0500
32927 @@ -148,7 +148,7 @@ bail:
32928
32929 static void ocfs2_fast_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
32930 {
32931 - char *link = nd_get_link(nd);
32932 + const char *link = nd_get_link(nd);
32933 if (!IS_ERR(link))
32934 kfree(link);
32935 }
32936 diff -urNp linux-2.6.37/fs/open.c linux-2.6.37/fs/open.c
32937 --- linux-2.6.37/fs/open.c 2011-01-04 19:50:19.000000000 -0500
32938 +++ linux-2.6.37/fs/open.c 2011-01-17 02:49:14.000000000 -0500
32939 @@ -112,6 +112,10 @@ static long do_sys_truncate(const char _
32940 error = locks_verify_truncate(inode, NULL, length);
32941 if (!error)
32942 error = security_path_truncate(&path);
32943 +
32944 + if (!error && !gr_acl_handle_truncate(path.dentry, path.mnt))
32945 + error = -EACCES;
32946 +
32947 if (!error)
32948 error = do_truncate(path.dentry, length, 0, NULL);
32949
32950 @@ -345,6 +349,9 @@ SYSCALL_DEFINE3(faccessat, int, dfd, con
32951 if (__mnt_is_readonly(path.mnt))
32952 res = -EROFS;
32953
32954 + if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
32955 + res = -EACCES;
32956 +
32957 out_path_release:
32958 path_put(&path);
32959 out:
32960 @@ -371,6 +378,8 @@ SYSCALL_DEFINE1(chdir, const char __user
32961 if (error)
32962 goto dput_and_out;
32963
32964 + gr_log_chdir(path.dentry, path.mnt);
32965 +
32966 set_fs_pwd(current->fs, &path);
32967
32968 dput_and_out:
32969 @@ -397,6 +406,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd
32970 goto out_putf;
32971
32972 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
32973 +
32974 + if (!error && !gr_chroot_fchdir(file->f_path.dentry, file->f_path.mnt))
32975 + error = -EPERM;
32976 +
32977 + if (!error)
32978 + gr_log_chdir(file->f_path.dentry, file->f_path.mnt);
32979 +
32980 if (!error)
32981 set_fs_pwd(current->fs, &file->f_path);
32982 out_putf:
32983 @@ -425,7 +441,18 @@ SYSCALL_DEFINE1(chroot, const char __use
32984 if (error)
32985 goto dput_and_out;
32986
32987 + if (gr_handle_chroot_chroot(path.dentry, path.mnt))
32988 + goto dput_and_out;
32989 +
32990 + if (gr_handle_chroot_caps(&path)) {
32991 + error = -ENOMEM;
32992 + goto dput_and_out;
32993 + }
32994 +
32995 set_fs_root(current->fs, &path);
32996 +
32997 + gr_handle_chroot_chdir(&path);
32998 +
32999 error = 0;
33000 dput_and_out:
33001 path_put(&path);
33002 @@ -453,12 +480,25 @@ SYSCALL_DEFINE2(fchmod, unsigned int, fd
33003 err = mnt_want_write_file(file);
33004 if (err)
33005 goto out_putf;
33006 +
33007 mutex_lock(&inode->i_mutex);
33008 +
33009 + if (!gr_acl_handle_fchmod(dentry, file->f_vfsmnt, mode)) {
33010 + err = -EACCES;
33011 + goto out_unlock;
33012 + }
33013 +
33014 err = security_path_chmod(dentry, file->f_vfsmnt, mode);
33015 if (err)
33016 goto out_unlock;
33017 if (mode == (mode_t) -1)
33018 mode = inode->i_mode;
33019 +
33020 + if (gr_handle_chroot_chmod(dentry, file->f_vfsmnt, mode)) {
33021 + err = -EACCES;
33022 + goto out_unlock;
33023 + }
33024 +
33025 newattrs.ia_mode = (mode & S_IALLUGO) | (inode->i_mode & ~S_IALLUGO);
33026 newattrs.ia_valid = ATTR_MODE | ATTR_CTIME;
33027 err = notify_change(dentry, &newattrs);
33028 @@ -486,12 +526,25 @@ SYSCALL_DEFINE3(fchmodat, int, dfd, cons
33029 error = mnt_want_write(path.mnt);
33030 if (error)
33031 goto dput_and_out;
33032 +
33033 mutex_lock(&inode->i_mutex);
33034 +
33035 + if (!gr_acl_handle_chmod(path.dentry, path.mnt, mode)) {
33036 + error = -EACCES;
33037 + goto out_unlock;
33038 + }
33039 +
33040 error = security_path_chmod(path.dentry, path.mnt, mode);
33041 if (error)
33042 goto out_unlock;
33043 if (mode == (mode_t) -1)
33044 mode = inode->i_mode;
33045 +
33046 + if (gr_handle_chroot_chmod(path.dentry, path.mnt, mode)) {
33047 + error = -EACCES;
33048 + goto out_unlock;
33049 + }
33050 +
33051 newattrs.ia_mode = (mode & S_IALLUGO) | (inode->i_mode & ~S_IALLUGO);
33052 newattrs.ia_valid = ATTR_MODE | ATTR_CTIME;
33053 error = notify_change(path.dentry, &newattrs);
33054 @@ -515,6 +568,9 @@ static int chown_common(struct path *pat
33055 int error;
33056 struct iattr newattrs;
33057
33058 + if (!gr_acl_handle_chown(path->dentry, path->mnt))
33059 + return -EACCES;
33060 +
33061 newattrs.ia_valid = ATTR_CTIME;
33062 if (user != (uid_t) -1) {
33063 newattrs.ia_valid |= ATTR_UID;
33064 @@ -883,7 +939,10 @@ long do_sys_open(int dfd, const char __u
33065 if (!IS_ERR(tmp)) {
33066 fd = get_unused_fd_flags(flags);
33067 if (fd >= 0) {
33068 - struct file *f = do_filp_open(dfd, tmp, flags, mode, 0);
33069 + struct file *f;
33070 + /* don't allow to be set by userland */
33071 + flags &= ~FMODE_GREXEC;
33072 + f = do_filp_open(dfd, tmp, flags, mode, 0);
33073 if (IS_ERR(f)) {
33074 put_unused_fd(fd);
33075 fd = PTR_ERR(f);
33076 diff -urNp linux-2.6.37/fs/pipe.c linux-2.6.37/fs/pipe.c
33077 --- linux-2.6.37/fs/pipe.c 2011-01-04 19:50:19.000000000 -0500
33078 +++ linux-2.6.37/fs/pipe.c 2011-01-17 02:41:01.000000000 -0500
33079 @@ -420,9 +420,9 @@ redo:
33080 }
33081 if (bufs) /* More to do? */
33082 continue;
33083 - if (!pipe->writers)
33084 + if (!atomic_read(&pipe->writers))
33085 break;
33086 - if (!pipe->waiting_writers) {
33087 + if (!atomic_read(&pipe->waiting_writers)) {
33088 /* syscall merging: Usually we must not sleep
33089 * if O_NONBLOCK is set, or if we got some data.
33090 * But if a writer sleeps in kernel space, then
33091 @@ -481,7 +481,7 @@ pipe_write(struct kiocb *iocb, const str
33092 mutex_lock(&inode->i_mutex);
33093 pipe = inode->i_pipe;
33094
33095 - if (!pipe->readers) {
33096 + if (!atomic_read(&pipe->readers)) {
33097 send_sig(SIGPIPE, current, 0);
33098 ret = -EPIPE;
33099 goto out;
33100 @@ -530,7 +530,7 @@ redo1:
33101 for (;;) {
33102 int bufs;
33103
33104 - if (!pipe->readers) {
33105 + if (!atomic_read(&pipe->readers)) {
33106 send_sig(SIGPIPE, current, 0);
33107 if (!ret)
33108 ret = -EPIPE;
33109 @@ -616,9 +616,9 @@ redo2:
33110 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
33111 do_wakeup = 0;
33112 }
33113 - pipe->waiting_writers++;
33114 + atomic_inc(&pipe->waiting_writers);
33115 pipe_wait(pipe);
33116 - pipe->waiting_writers--;
33117 + atomic_dec(&pipe->waiting_writers);
33118 }
33119 out:
33120 mutex_unlock(&inode->i_mutex);
33121 @@ -685,7 +685,7 @@ pipe_poll(struct file *filp, poll_table
33122 mask = 0;
33123 if (filp->f_mode & FMODE_READ) {
33124 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
33125 - if (!pipe->writers && filp->f_version != pipe->w_counter)
33126 + if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
33127 mask |= POLLHUP;
33128 }
33129
33130 @@ -695,7 +695,7 @@ pipe_poll(struct file *filp, poll_table
33131 * Most Unices do not set POLLERR for FIFOs but on Linux they
33132 * behave exactly like pipes for poll().
33133 */
33134 - if (!pipe->readers)
33135 + if (!atomic_read(&pipe->readers))
33136 mask |= POLLERR;
33137 }
33138
33139 @@ -709,10 +709,10 @@ pipe_release(struct inode *inode, int de
33140
33141 mutex_lock(&inode->i_mutex);
33142 pipe = inode->i_pipe;
33143 - pipe->readers -= decr;
33144 - pipe->writers -= decw;
33145 + atomic_sub(decr, &pipe->readers);
33146 + atomic_sub(decw, &pipe->writers);
33147
33148 - if (!pipe->readers && !pipe->writers) {
33149 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
33150 free_pipe_info(inode);
33151 } else {
33152 wake_up_interruptible_sync(&pipe->wait);
33153 @@ -802,7 +802,7 @@ pipe_read_open(struct inode *inode, stru
33154
33155 if (inode->i_pipe) {
33156 ret = 0;
33157 - inode->i_pipe->readers++;
33158 + atomic_inc(&inode->i_pipe->readers);
33159 }
33160
33161 mutex_unlock(&inode->i_mutex);
33162 @@ -819,7 +819,7 @@ pipe_write_open(struct inode *inode, str
33163
33164 if (inode->i_pipe) {
33165 ret = 0;
33166 - inode->i_pipe->writers++;
33167 + atomic_inc(&inode->i_pipe->writers);
33168 }
33169
33170 mutex_unlock(&inode->i_mutex);
33171 @@ -837,9 +837,9 @@ pipe_rdwr_open(struct inode *inode, stru
33172 if (inode->i_pipe) {
33173 ret = 0;
33174 if (filp->f_mode & FMODE_READ)
33175 - inode->i_pipe->readers++;
33176 + atomic_inc(&inode->i_pipe->readers);
33177 if (filp->f_mode & FMODE_WRITE)
33178 - inode->i_pipe->writers++;
33179 + atomic_inc(&inode->i_pipe->writers);
33180 }
33181
33182 mutex_unlock(&inode->i_mutex);
33183 @@ -931,7 +931,7 @@ void free_pipe_info(struct inode *inode)
33184 inode->i_pipe = NULL;
33185 }
33186
33187 -static struct vfsmount *pipe_mnt __read_mostly;
33188 +struct vfsmount *pipe_mnt __read_mostly;
33189
33190 /*
33191 * pipefs_dname() is called from d_path().
33192 @@ -961,7 +961,8 @@ static struct inode * get_pipe_inode(voi
33193 goto fail_iput;
33194 inode->i_pipe = pipe;
33195
33196 - pipe->readers = pipe->writers = 1;
33197 + atomic_set(&pipe->readers, 1);
33198 + atomic_set(&pipe->writers, 1);
33199 inode->i_fop = &rdwr_pipefifo_fops;
33200
33201 /*
33202 diff -urNp linux-2.6.37/fs/proc/array.c linux-2.6.37/fs/proc/array.c
33203 --- linux-2.6.37/fs/proc/array.c 2011-01-04 19:50:19.000000000 -0500
33204 +++ linux-2.6.37/fs/proc/array.c 2011-01-17 02:41:01.000000000 -0500
33205 @@ -60,6 +60,7 @@
33206 #include <linux/tty.h>
33207 #include <linux/string.h>
33208 #include <linux/mman.h>
33209 +#include <linux/grsecurity.h>
33210 #include <linux/proc_fs.h>
33211 #include <linux/ioport.h>
33212 #include <linux/uaccess.h>
33213 @@ -337,6 +338,21 @@ static void task_cpus_allowed(struct seq
33214 seq_printf(m, "\n");
33215 }
33216
33217 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
33218 +static inline void task_pax(struct seq_file *m, struct task_struct *p)
33219 +{
33220 + if (p->mm)
33221 + seq_printf(m, "PaX:\t%c%c%c%c%c\n",
33222 + p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
33223 + p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
33224 + p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
33225 + p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
33226 + p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
33227 + else
33228 + seq_printf(m, "PaX:\t-----\n");
33229 +}
33230 +#endif
33231 +
33232 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
33233 struct pid *pid, struct task_struct *task)
33234 {
33235 @@ -357,9 +373,24 @@ int proc_pid_status(struct seq_file *m,
33236 task_show_regs(m, task);
33237 #endif
33238 task_context_switch_counts(m, task);
33239 +
33240 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
33241 + task_pax(m, task);
33242 +#endif
33243 +
33244 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
33245 + task_grsec_rbac(m, task);
33246 +#endif
33247 +
33248 return 0;
33249 }
33250
33251 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
33252 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
33253 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
33254 + _mm->pax_flags & MF_PAX_SEGMEXEC))
33255 +#endif
33256 +
33257 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
33258 struct pid *pid, struct task_struct *task, int whole)
33259 {
33260 @@ -452,6 +483,19 @@ static int do_task_stat(struct seq_file
33261 gtime = task->gtime;
33262 }
33263
33264 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
33265 + if (PAX_RAND_FLAGS(mm)) {
33266 + eip = 0;
33267 + esp = 0;
33268 + wchan = 0;
33269 + }
33270 +#endif
33271 +#ifdef CONFIG_GRKERNSEC_HIDESYM
33272 + wchan = 0;
33273 + eip =0;
33274 + esp =0;
33275 +#endif
33276 +
33277 /* scale priority and nice values from timeslices to -20..20 */
33278 /* to make it look like a "normal" Unix priority/nice value */
33279 priority = task_prio(task);
33280 @@ -492,9 +536,15 @@ static int do_task_stat(struct seq_file
33281 vsize,
33282 mm ? get_mm_rss(mm) : 0,
33283 rsslim,
33284 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
33285 + PAX_RAND_FLAGS(mm) ? 1 : (mm ? mm->start_code : 0),
33286 + PAX_RAND_FLAGS(mm) ? 1 : (mm ? mm->end_code : 0),
33287 + PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0),
33288 +#else
33289 mm ? mm->start_code : 0,
33290 mm ? mm->end_code : 0,
33291 (permitted && mm) ? mm->start_stack : 0,
33292 +#endif
33293 esp,
33294 eip,
33295 /* The signal information here is obsolete.
33296 @@ -547,3 +597,10 @@ int proc_pid_statm(struct seq_file *m, s
33297
33298 return 0;
33299 }
33300 +
33301 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
33302 +int proc_pid_ipaddr(struct task_struct *task, char *buffer)
33303 +{
33304 + return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
33305 +}
33306 +#endif
33307 diff -urNp linux-2.6.37/fs/proc/base.c linux-2.6.37/fs/proc/base.c
33308 --- linux-2.6.37/fs/proc/base.c 2011-01-04 19:50:19.000000000 -0500
33309 +++ linux-2.6.37/fs/proc/base.c 2011-01-17 02:41:01.000000000 -0500
33310 @@ -104,6 +104,22 @@ struct pid_entry {
33311 union proc_op op;
33312 };
33313
33314 +struct getdents_callback {
33315 + struct linux_dirent __user * current_dir;
33316 + struct linux_dirent __user * previous;
33317 + struct file * file;
33318 + int count;
33319 + int error;
33320 +};
33321 +
33322 +static int gr_fake_filldir(void * __buf, const char *name, int namlen,
33323 + loff_t offset, u64 ino, unsigned int d_type)
33324 +{
33325 + struct getdents_callback * buf = (struct getdents_callback *) __buf;
33326 + buf->error = -EINVAL;
33327 + return 0;
33328 +}
33329 +
33330 #define NOD(NAME, MODE, IOP, FOP, OP) { \
33331 .name = (NAME), \
33332 .len = sizeof(NAME) - 1, \
33333 @@ -203,6 +219,9 @@ static int check_mem_permission(struct t
33334 if (task == current)
33335 return 0;
33336
33337 + if (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))
33338 + return -EPERM;
33339 +
33340 /*
33341 * If current is actively ptrace'ing, and would also be
33342 * permitted to freshly attach with ptrace now, permit it.
33343 @@ -250,6 +269,9 @@ static int proc_pid_cmdline(struct task_
33344 if (!mm->arg_end)
33345 goto out_mm; /* Shh! No looking before we're done */
33346
33347 + if (gr_acl_handle_procpidmem(task))
33348 + goto out_mm;
33349 +
33350 len = mm->arg_end - mm->arg_start;
33351
33352 if (len > PAGE_SIZE)
33353 @@ -277,12 +299,28 @@ out:
33354 return res;
33355 }
33356
33357 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
33358 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
33359 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
33360 + _mm->pax_flags & MF_PAX_SEGMEXEC))
33361 +#endif
33362 +
33363 static int proc_pid_auxv(struct task_struct *task, char *buffer)
33364 {
33365 int res = 0;
33366 struct mm_struct *mm = get_task_mm(task);
33367 if (mm) {
33368 unsigned int nwords = 0;
33369 +
33370 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
33371 + /* allow if we're currently ptracing this task */
33372 + if (PAX_RAND_FLAGS(mm) &&
33373 + (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
33374 + mmput(mm);
33375 + return res;
33376 + }
33377 +#endif
33378 +
33379 do {
33380 nwords += 2;
33381 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
33382 @@ -296,7 +334,7 @@ static int proc_pid_auxv(struct task_str
33383 }
33384
33385
33386 -#ifdef CONFIG_KALLSYMS
33387 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
33388 /*
33389 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
33390 * Returns the resolved symbol. If that fails, simply return the address.
33391 @@ -318,7 +356,7 @@ static int proc_pid_wchan(struct task_st
33392 }
33393 #endif /* CONFIG_KALLSYMS */
33394
33395 -#ifdef CONFIG_STACKTRACE
33396 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
33397
33398 #define MAX_STACK_TRACE_DEPTH 64
33399
33400 @@ -509,7 +547,7 @@ static int proc_pid_limits(struct task_s
33401 return count;
33402 }
33403
33404 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
33405 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
33406 static int proc_pid_syscall(struct task_struct *task, char *buffer)
33407 {
33408 long nr;
33409 @@ -930,6 +968,9 @@ static ssize_t environ_read(struct file
33410 if (!task)
33411 goto out_no_task;
33412
33413 + if (gr_acl_handle_procpidmem(task))
33414 + goto out;
33415 +
33416 if (!ptrace_may_access(task, PTRACE_MODE_READ))
33417 goto out;
33418
33419 @@ -1663,7 +1704,11 @@ static struct inode *proc_pid_make_inode
33420 rcu_read_lock();
33421 cred = __task_cred(task);
33422 inode->i_uid = cred->euid;
33423 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
33424 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
33425 +#else
33426 inode->i_gid = cred->egid;
33427 +#endif
33428 rcu_read_unlock();
33429 }
33430 security_task_to_inode(task, inode);
33431 @@ -1681,6 +1726,9 @@ static int pid_getattr(struct vfsmount *
33432 struct inode *inode = dentry->d_inode;
33433 struct task_struct *task;
33434 const struct cred *cred;
33435 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
33436 + const struct cred *tmpcred = current_cred();
33437 +#endif
33438
33439 generic_fillattr(inode, stat);
33440
33441 @@ -1688,12 +1736,34 @@ static int pid_getattr(struct vfsmount *
33442 stat->uid = 0;
33443 stat->gid = 0;
33444 task = pid_task(proc_pid(inode), PIDTYPE_PID);
33445 +
33446 + if (task && (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))) {
33447 + rcu_read_unlock();
33448 + return -ENOENT;
33449 + }
33450 +
33451 if (task) {
33452 + cred = __task_cred(task);
33453 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
33454 + if (!tmpcred->uid || (tmpcred->uid == cred->uid)
33455 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
33456 + || in_group_p(CONFIG_GRKERNSEC_PROC_GID)
33457 +#endif
33458 + )
33459 +#endif
33460 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
33461 +#ifdef CONFIG_GRKERNSEC_PROC_USER
33462 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
33463 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
33464 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
33465 +#endif
33466 task_dumpable(task)) {
33467 - cred = __task_cred(task);
33468 stat->uid = cred->euid;
33469 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
33470 + stat->gid = CONFIG_GRKERNSEC_PROC_GID;
33471 +#else
33472 stat->gid = cred->egid;
33473 +#endif
33474 }
33475 }
33476 rcu_read_unlock();
33477 @@ -1725,11 +1795,20 @@ static int pid_revalidate(struct dentry
33478
33479 if (task) {
33480 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
33481 +#ifdef CONFIG_GRKERNSEC_PROC_USER
33482 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
33483 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
33484 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
33485 +#endif
33486 task_dumpable(task)) {
33487 rcu_read_lock();
33488 cred = __task_cred(task);
33489 inode->i_uid = cred->euid;
33490 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
33491 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
33492 +#else
33493 inode->i_gid = cred->egid;
33494 +#endif
33495 rcu_read_unlock();
33496 } else {
33497 inode->i_uid = 0;
33498 @@ -1850,7 +1929,8 @@ static int proc_fd_info(struct inode *in
33499 int fd = proc_fd(inode);
33500
33501 if (task) {
33502 - files = get_files_struct(task);
33503 + if (!gr_acl_handle_procpidmem(task))
33504 + files = get_files_struct(task);
33505 put_task_struct(task);
33506 }
33507 if (files) {
33508 @@ -2104,12 +2184,22 @@ static const struct file_operations proc
33509 static int proc_fd_permission(struct inode *inode, int mask)
33510 {
33511 int rv;
33512 + struct task_struct *task;
33513
33514 rv = generic_permission(inode, mask, NULL);
33515 - if (rv == 0)
33516 - return 0;
33517 +
33518 if (task_pid(current) == proc_pid(inode))
33519 rv = 0;
33520 +
33521 + task = get_proc_task(inode);
33522 + if (task == NULL)
33523 + return rv;
33524 +
33525 + if (gr_acl_handle_procpidmem(task))
33526 + rv = -EACCES;
33527 +
33528 + put_task_struct(task);
33529 +
33530 return rv;
33531 }
33532
33533 @@ -2219,6 +2309,9 @@ static struct dentry *proc_pident_lookup
33534 if (!task)
33535 goto out_no_task;
33536
33537 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
33538 + goto out;
33539 +
33540 /*
33541 * Yes, it does not scale. And it should not. Don't add
33542 * new entries into /proc/<tgid>/ without very good reasons.
33543 @@ -2263,6 +2356,9 @@ static int proc_pident_readdir(struct fi
33544 if (!task)
33545 goto out_no_task;
33546
33547 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
33548 + goto out;
33549 +
33550 ret = 0;
33551 i = filp->f_pos;
33552 switch (i) {
33553 @@ -2533,7 +2629,7 @@ static void *proc_self_follow_link(struc
33554 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
33555 void *cookie)
33556 {
33557 - char *s = nd_get_link(nd);
33558 + const char *s = nd_get_link(nd);
33559 if (!IS_ERR(s))
33560 __putname(s);
33561 }
33562 @@ -2734,7 +2830,7 @@ static const struct pid_entry tgid_base_
33563 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
33564 #endif
33565 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
33566 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
33567 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
33568 INF("syscall", S_IRUSR, proc_pid_syscall),
33569 #endif
33570 INF("cmdline", S_IRUGO, proc_pid_cmdline),
33571 @@ -2759,10 +2855,10 @@ static const struct pid_entry tgid_base_
33572 #ifdef CONFIG_SECURITY
33573 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
33574 #endif
33575 -#ifdef CONFIG_KALLSYMS
33576 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
33577 INF("wchan", S_IRUGO, proc_pid_wchan),
33578 #endif
33579 -#ifdef CONFIG_STACKTRACE
33580 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
33581 ONE("stack", S_IRUSR, proc_pid_stack),
33582 #endif
33583 #ifdef CONFIG_SCHEDSTATS
33584 @@ -2793,6 +2889,9 @@ static const struct pid_entry tgid_base_
33585 #ifdef CONFIG_TASK_IO_ACCOUNTING
33586 INF("io", S_IRUGO, proc_tgid_io_accounting),
33587 #endif
33588 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
33589 + INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
33590 +#endif
33591 };
33592
33593 static int proc_tgid_base_readdir(struct file * filp,
33594 @@ -2918,7 +3017,14 @@ static struct dentry *proc_pid_instantia
33595 if (!inode)
33596 goto out;
33597
33598 +#ifdef CONFIG_GRKERNSEC_PROC_USER
33599 + inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
33600 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
33601 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
33602 + inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
33603 +#else
33604 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
33605 +#endif
33606 inode->i_op = &proc_tgid_base_inode_operations;
33607 inode->i_fop = &proc_tgid_base_operations;
33608 inode->i_flags|=S_IMMUTABLE;
33609 @@ -2960,7 +3066,11 @@ struct dentry *proc_pid_lookup(struct in
33610 if (!task)
33611 goto out;
33612
33613 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
33614 + goto out_put_task;
33615 +
33616 result = proc_pid_instantiate(dir, dentry, task, NULL);
33617 +out_put_task:
33618 put_task_struct(task);
33619 out:
33620 return result;
33621 @@ -3025,6 +3135,11 @@ int proc_pid_readdir(struct file * filp,
33622 {
33623 unsigned int nr = filp->f_pos - FIRST_PROCESS_ENTRY;
33624 struct task_struct *reaper = get_proc_task(filp->f_path.dentry->d_inode);
33625 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
33626 + const struct cred *tmpcred = current_cred();
33627 + const struct cred *itercred;
33628 +#endif
33629 + filldir_t __filldir = filldir;
33630 struct tgid_iter iter;
33631 struct pid_namespace *ns;
33632
33633 @@ -3043,8 +3158,27 @@ int proc_pid_readdir(struct file * filp,
33634 for (iter = next_tgid(ns, iter);
33635 iter.task;
33636 iter.tgid += 1, iter = next_tgid(ns, iter)) {
33637 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
33638 + rcu_read_lock();
33639 + itercred = __task_cred(iter.task);
33640 +#endif
33641 + if (gr_pid_is_chrooted(iter.task) || gr_check_hidden_task(iter.task)
33642 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
33643 + || (tmpcred->uid && (itercred->uid != tmpcred->uid)
33644 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
33645 + && !in_group_p(CONFIG_GRKERNSEC_PROC_GID)
33646 +#endif
33647 + )
33648 +#endif
33649 + )
33650 + __filldir = &gr_fake_filldir;
33651 + else
33652 + __filldir = filldir;
33653 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
33654 + rcu_read_unlock();
33655 +#endif
33656 filp->f_pos = iter.tgid + TGID_OFFSET;
33657 - if (proc_pid_fill_cache(filp, dirent, filldir, iter) < 0) {
33658 + if (proc_pid_fill_cache(filp, dirent, __filldir, iter) < 0) {
33659 put_task_struct(iter.task);
33660 goto out;
33661 }
33662 @@ -3071,7 +3205,7 @@ static const struct pid_entry tid_base_s
33663 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
33664 #endif
33665 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
33666 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
33667 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
33668 INF("syscall", S_IRUSR, proc_pid_syscall),
33669 #endif
33670 INF("cmdline", S_IRUGO, proc_pid_cmdline),
33671 @@ -3095,10 +3229,10 @@ static const struct pid_entry tid_base_s
33672 #ifdef CONFIG_SECURITY
33673 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
33674 #endif
33675 -#ifdef CONFIG_KALLSYMS
33676 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
33677 INF("wchan", S_IRUGO, proc_pid_wchan),
33678 #endif
33679 -#ifdef CONFIG_STACKTRACE
33680 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
33681 ONE("stack", S_IRUSR, proc_pid_stack),
33682 #endif
33683 #ifdef CONFIG_SCHEDSTATS
33684 diff -urNp linux-2.6.37/fs/proc/cmdline.c linux-2.6.37/fs/proc/cmdline.c
33685 --- linux-2.6.37/fs/proc/cmdline.c 2011-01-04 19:50:19.000000000 -0500
33686 +++ linux-2.6.37/fs/proc/cmdline.c 2011-01-17 02:41:01.000000000 -0500
33687 @@ -23,7 +23,11 @@ static const struct file_operations cmdl
33688
33689 static int __init proc_cmdline_init(void)
33690 {
33691 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
33692 + proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
33693 +#else
33694 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
33695 +#endif
33696 return 0;
33697 }
33698 module_init(proc_cmdline_init);
33699 diff -urNp linux-2.6.37/fs/proc/devices.c linux-2.6.37/fs/proc/devices.c
33700 --- linux-2.6.37/fs/proc/devices.c 2011-01-04 19:50:19.000000000 -0500
33701 +++ linux-2.6.37/fs/proc/devices.c 2011-01-17 02:41:01.000000000 -0500
33702 @@ -64,7 +64,11 @@ static const struct file_operations proc
33703
33704 static int __init proc_devices_init(void)
33705 {
33706 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
33707 + proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
33708 +#else
33709 proc_create("devices", 0, NULL, &proc_devinfo_operations);
33710 +#endif
33711 return 0;
33712 }
33713 module_init(proc_devices_init);
33714 diff -urNp linux-2.6.37/fs/proc/inode.c linux-2.6.37/fs/proc/inode.c
33715 --- linux-2.6.37/fs/proc/inode.c 2011-01-04 19:50:19.000000000 -0500
33716 +++ linux-2.6.37/fs/proc/inode.c 2011-01-17 02:41:01.000000000 -0500
33717 @@ -425,7 +425,11 @@ struct inode *proc_get_inode(struct supe
33718 if (de->mode) {
33719 inode->i_mode = de->mode;
33720 inode->i_uid = de->uid;
33721 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
33722 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
33723 +#else
33724 inode->i_gid = de->gid;
33725 +#endif
33726 }
33727 if (de->size)
33728 inode->i_size = de->size;
33729 diff -urNp linux-2.6.37/fs/proc/internal.h linux-2.6.37/fs/proc/internal.h
33730 --- linux-2.6.37/fs/proc/internal.h 2011-01-04 19:50:19.000000000 -0500
33731 +++ linux-2.6.37/fs/proc/internal.h 2011-01-17 02:41:01.000000000 -0500
33732 @@ -51,6 +51,9 @@ extern int proc_pid_status(struct seq_fi
33733 struct pid *pid, struct task_struct *task);
33734 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
33735 struct pid *pid, struct task_struct *task);
33736 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
33737 +extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
33738 +#endif
33739 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
33740
33741 extern const struct file_operations proc_maps_operations;
33742 diff -urNp linux-2.6.37/fs/proc/Kconfig linux-2.6.37/fs/proc/Kconfig
33743 --- linux-2.6.37/fs/proc/Kconfig 2011-01-04 19:50:19.000000000 -0500
33744 +++ linux-2.6.37/fs/proc/Kconfig 2011-01-17 02:41:01.000000000 -0500
33745 @@ -30,12 +30,12 @@ config PROC_FS
33746
33747 config PROC_KCORE
33748 bool "/proc/kcore support" if !ARM
33749 - depends on PROC_FS && MMU
33750 + depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
33751
33752 config PROC_VMCORE
33753 bool "/proc/vmcore support"
33754 - depends on PROC_FS && CRASH_DUMP
33755 - default y
33756 + depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
33757 + default n
33758 help
33759 Exports the dump image of crashed kernel in ELF format.
33760
33761 @@ -59,8 +59,8 @@ config PROC_SYSCTL
33762 limited in memory.
33763
33764 config PROC_PAGE_MONITOR
33765 - default y
33766 - depends on PROC_FS && MMU
33767 + default n
33768 + depends on PROC_FS && MMU && !GRKERNSEC
33769 bool "Enable /proc page monitoring" if EMBEDDED
33770 help
33771 Various /proc files exist to monitor process memory utilization:
33772 diff -urNp linux-2.6.37/fs/proc/kcore.c linux-2.6.37/fs/proc/kcore.c
33773 --- linux-2.6.37/fs/proc/kcore.c 2011-01-04 19:50:19.000000000 -0500
33774 +++ linux-2.6.37/fs/proc/kcore.c 2011-01-17 02:41:01.000000000 -0500
33775 @@ -478,9 +478,10 @@ read_kcore(struct file *file, char __use
33776 * the addresses in the elf_phdr on our list.
33777 */
33778 start = kc_offset_to_vaddr(*fpos - elf_buflen);
33779 - if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
33780 + tsz = PAGE_SIZE - (start & ~PAGE_MASK);
33781 + if (tsz > buflen)
33782 tsz = buflen;
33783 -
33784 +
33785 while (buflen) {
33786 struct kcore_list *m;
33787
33788 @@ -509,20 +510,23 @@ read_kcore(struct file *file, char __use
33789 kfree(elf_buf);
33790 } else {
33791 if (kern_addr_valid(start)) {
33792 - unsigned long n;
33793 + char *elf_buf;
33794 + mm_segment_t oldfs;
33795
33796 - n = copy_to_user(buffer, (char *)start, tsz);
33797 - /*
33798 - * We cannot distingush between fault on source
33799 - * and fault on destination. When this happens
33800 - * we clear too and hope it will trigger the
33801 - * EFAULT again.
33802 - */
33803 - if (n) {
33804 - if (clear_user(buffer + tsz - n,
33805 - n))
33806 + elf_buf = kmalloc(tsz, GFP_KERNEL);
33807 + if (!elf_buf)
33808 + return -ENOMEM;
33809 + oldfs = get_fs();
33810 + set_fs(KERNEL_DS);
33811 + if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
33812 + set_fs(oldfs);
33813 + if (copy_to_user(buffer, elf_buf, tsz)) {
33814 + kfree(elf_buf);
33815 return -EFAULT;
33816 + }
33817 }
33818 + set_fs(oldfs);
33819 + kfree(elf_buf);
33820 } else {
33821 if (clear_user(buffer, tsz))
33822 return -EFAULT;
33823 @@ -542,6 +546,9 @@ read_kcore(struct file *file, char __use
33824
33825 static int open_kcore(struct inode *inode, struct file *filp)
33826 {
33827 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
33828 + return -EPERM;
33829 +#endif
33830 if (!capable(CAP_SYS_RAWIO))
33831 return -EPERM;
33832 if (kcore_need_update)
33833 diff -urNp linux-2.6.37/fs/proc/meminfo.c linux-2.6.37/fs/proc/meminfo.c
33834 --- linux-2.6.37/fs/proc/meminfo.c 2011-01-04 19:50:19.000000000 -0500
33835 +++ linux-2.6.37/fs/proc/meminfo.c 2011-01-17 02:41:01.000000000 -0500
33836 @@ -149,7 +149,7 @@ static int meminfo_proc_show(struct seq_
33837 vmi.used >> 10,
33838 vmi.largest_chunk >> 10
33839 #ifdef CONFIG_MEMORY_FAILURE
33840 - ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10)
33841 + ,atomic_long_read_unchecked(&mce_bad_pages) << (PAGE_SHIFT - 10)
33842 #endif
33843 );
33844
33845 diff -urNp linux-2.6.37/fs/proc/nommu.c linux-2.6.37/fs/proc/nommu.c
33846 --- linux-2.6.37/fs/proc/nommu.c 2011-01-04 19:50:19.000000000 -0500
33847 +++ linux-2.6.37/fs/proc/nommu.c 2011-01-17 02:41:01.000000000 -0500
33848 @@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_
33849 if (len < 1)
33850 len = 1;
33851 seq_printf(m, "%*c", len, ' ');
33852 - seq_path(m, &file->f_path, "");
33853 + seq_path(m, &file->f_path, "\n\\");
33854 }
33855
33856 seq_putc(m, '\n');
33857 diff -urNp linux-2.6.37/fs/proc/proc_net.c linux-2.6.37/fs/proc/proc_net.c
33858 --- linux-2.6.37/fs/proc/proc_net.c 2011-01-04 19:50:19.000000000 -0500
33859 +++ linux-2.6.37/fs/proc/proc_net.c 2011-01-17 02:41:01.000000000 -0500
33860 @@ -105,6 +105,17 @@ static struct net *get_proc_task_net(str
33861 struct task_struct *task;
33862 struct nsproxy *ns;
33863 struct net *net = NULL;
33864 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
33865 + const struct cred *cred = current_cred();
33866 +#endif
33867 +
33868 +#ifdef CONFIG_GRKERNSEC_PROC_USER
33869 + if (cred->fsuid)
33870 + return net;
33871 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
33872 + if (cred->fsuid && !in_group_p(CONFIG_GRKERNSEC_PROC_GID))
33873 + return net;
33874 +#endif
33875
33876 rcu_read_lock();
33877 task = pid_task(proc_pid(dir), PIDTYPE_PID);
33878 diff -urNp linux-2.6.37/fs/proc/proc_sysctl.c linux-2.6.37/fs/proc/proc_sysctl.c
33879 --- linux-2.6.37/fs/proc/proc_sysctl.c 2011-01-04 19:50:19.000000000 -0500
33880 +++ linux-2.6.37/fs/proc/proc_sysctl.c 2011-01-17 02:41:01.000000000 -0500
33881 @@ -7,6 +7,8 @@
33882 #include <linux/security.h>
33883 #include "internal.h"
33884
33885 +extern __u32 gr_handle_sysctl(const struct ctl_table *table, const int op);
33886 +
33887 static const struct dentry_operations proc_sys_dentry_operations;
33888 static const struct file_operations proc_sys_file_operations;
33889 static const struct inode_operations proc_sys_inode_operations;
33890 @@ -111,6 +113,9 @@ static struct dentry *proc_sys_lookup(st
33891 if (!p)
33892 goto out;
33893
33894 + if (gr_handle_sysctl(p, MAY_EXEC))
33895 + goto out;
33896 +
33897 err = ERR_PTR(-ENOMEM);
33898 inode = proc_sys_make_inode(dir->i_sb, h ? h : head, p);
33899 if (h)
33900 @@ -230,6 +235,9 @@ static int scan(struct ctl_table_header
33901 if (*pos < file->f_pos)
33902 continue;
33903
33904 + if (gr_handle_sysctl(table, 0))
33905 + continue;
33906 +
33907 res = proc_sys_fill_cache(file, dirent, filldir, head, table);
33908 if (res)
33909 return res;
33910 @@ -355,6 +363,9 @@ static int proc_sys_getattr(struct vfsmo
33911 if (IS_ERR(head))
33912 return PTR_ERR(head);
33913
33914 + if (table && gr_handle_sysctl(table, MAY_EXEC))
33915 + return -ENOENT;
33916 +
33917 generic_fillattr(inode, stat);
33918 if (table)
33919 stat->mode = (stat->mode & S_IFMT) | table->mode;
33920 diff -urNp linux-2.6.37/fs/proc/root.c linux-2.6.37/fs/proc/root.c
33921 --- linux-2.6.37/fs/proc/root.c 2011-01-04 19:50:19.000000000 -0500
33922 +++ linux-2.6.37/fs/proc/root.c 2011-01-17 02:41:01.000000000 -0500
33923 @@ -132,7 +132,15 @@ void __init proc_root_init(void)
33924 #ifdef CONFIG_PROC_DEVICETREE
33925 proc_device_tree_init();
33926 #endif
33927 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
33928 +#ifdef CONFIG_GRKERNSEC_PROC_USER
33929 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
33930 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
33931 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
33932 +#endif
33933 +#else
33934 proc_mkdir("bus", NULL);
33935 +#endif
33936 proc_sys_init();
33937 }
33938
33939 diff -urNp linux-2.6.37/fs/proc/task_mmu.c linux-2.6.37/fs/proc/task_mmu.c
33940 --- linux-2.6.37/fs/proc/task_mmu.c 2011-01-04 19:50:19.000000000 -0500
33941 +++ linux-2.6.37/fs/proc/task_mmu.c 2011-01-17 02:41:01.000000000 -0500
33942 @@ -49,8 +49,13 @@ void task_mem(struct seq_file *m, struct
33943 "VmExe:\t%8lu kB\n"
33944 "VmLib:\t%8lu kB\n"
33945 "VmPTE:\t%8lu kB\n"
33946 - "VmSwap:\t%8lu kB\n",
33947 - hiwater_vm << (PAGE_SHIFT-10),
33948 + "VmSwap:\t%8lu kB\n"
33949 +
33950 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
33951 + "CsBase:\t%8lx\nCsLim:\t%8lx\n"
33952 +#endif
33953 +
33954 + ,hiwater_vm << (PAGE_SHIFT-10),
33955 (total_vm - mm->reserved_vm) << (PAGE_SHIFT-10),
33956 mm->locked_vm << (PAGE_SHIFT-10),
33957 hiwater_rss << (PAGE_SHIFT-10),
33958 @@ -58,7 +63,13 @@ void task_mem(struct seq_file *m, struct
33959 data << (PAGE_SHIFT-10),
33960 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
33961 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
33962 - swap << (PAGE_SHIFT-10));
33963 + swap << (PAGE_SHIFT-10)
33964 +
33965 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
33966 + , mm->context.user_cs_base, mm->context.user_cs_limit
33967 +#endif
33968 +
33969 + );
33970 }
33971
33972 unsigned long task_vsize(struct mm_struct *mm)
33973 @@ -203,6 +214,12 @@ static int do_maps_open(struct inode *in
33974 return ret;
33975 }
33976
33977 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
33978 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
33979 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
33980 + _mm->pax_flags & MF_PAX_SEGMEXEC))
33981 +#endif
33982 +
33983 static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
33984 {
33985 struct mm_struct *mm = vma->vm_mm;
33986 @@ -210,7 +227,6 @@ static void show_map_vma(struct seq_file
33987 int flags = vma->vm_flags;
33988 unsigned long ino = 0;
33989 unsigned long long pgoff = 0;
33990 - unsigned long start;
33991 dev_t dev = 0;
33992 int len;
33993
33994 @@ -221,20 +237,24 @@ static void show_map_vma(struct seq_file
33995 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
33996 }
33997
33998 - /* We don't show the stack guard page in /proc/maps */
33999 - start = vma->vm_start;
34000 - if (vma->vm_flags & VM_GROWSDOWN)
34001 - if (!vma_stack_continue(vma->vm_prev, vma->vm_start))
34002 - start += PAGE_SIZE;
34003
34004 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
34005 - start,
34006 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
34007 + PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start,
34008 + PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end,
34009 +#else
34010 + vma->vm_start,
34011 vma->vm_end,
34012 +#endif
34013 flags & VM_READ ? 'r' : '-',
34014 flags & VM_WRITE ? 'w' : '-',
34015 flags & VM_EXEC ? 'x' : '-',
34016 flags & VM_MAYSHARE ? 's' : 'p',
34017 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
34018 + PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
34019 +#else
34020 pgoff,
34021 +#endif
34022 MAJOR(dev), MINOR(dev), ino, &len);
34023
34024 /*
34025 @@ -243,16 +263,16 @@ static void show_map_vma(struct seq_file
34026 */
34027 if (file) {
34028 pad_len_spaces(m, len);
34029 - seq_path(m, &file->f_path, "\n");
34030 + seq_path(m, &file->f_path, "\n\\");
34031 } else {
34032 const char *name = arch_vma_name(vma);
34033 if (!name) {
34034 if (mm) {
34035 - if (vma->vm_start <= mm->start_brk &&
34036 - vma->vm_end >= mm->brk) {
34037 + if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
34038 name = "[heap]";
34039 - } else if (vma->vm_start <= mm->start_stack &&
34040 - vma->vm_end >= mm->start_stack) {
34041 + } else if ((vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
34042 + (vma->vm_start <= mm->start_stack &&
34043 + vma->vm_end >= mm->start_stack)) {
34044 name = "[stack]";
34045 }
34046 } else {
34047 @@ -398,11 +418,16 @@ static int show_smap(struct seq_file *m,
34048 };
34049
34050 memset(&mss, 0, sizeof mss);
34051 - mss.vma = vma;
34052 - /* mmap_sem is held in m_start */
34053 - if (vma->vm_mm && !is_vm_hugetlb_page(vma))
34054 - walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
34055 -
34056 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
34057 + if (!PAX_RAND_FLAGS(vma->vm_mm)) {
34058 +#endif
34059 + mss.vma = vma;
34060 + /* mmap_sem is held in m_start */
34061 + if (vma->vm_mm && !is_vm_hugetlb_page(vma))
34062 + walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
34063 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
34064 + }
34065 +#endif
34066 show_map_vma(m, vma);
34067
34068 seq_printf(m,
34069 @@ -418,7 +443,11 @@ static int show_smap(struct seq_file *m,
34070 "Swap: %8lu kB\n"
34071 "KernelPageSize: %8lu kB\n"
34072 "MMUPageSize: %8lu kB\n",
34073 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
34074 + PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
34075 +#else
34076 (vma->vm_end - vma->vm_start) >> 10,
34077 +#endif
34078 mss.resident >> 10,
34079 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
34080 mss.shared_clean >> 10,
34081 diff -urNp linux-2.6.37/fs/proc/task_nommu.c linux-2.6.37/fs/proc/task_nommu.c
34082 --- linux-2.6.37/fs/proc/task_nommu.c 2011-01-04 19:50:19.000000000 -0500
34083 +++ linux-2.6.37/fs/proc/task_nommu.c 2011-01-17 02:41:01.000000000 -0500
34084 @@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct
34085 else
34086 bytes += kobjsize(mm);
34087
34088 - if (current->fs && current->fs->users > 1)
34089 + if (current->fs && atomic_read(&current->fs->users) > 1)
34090 sbytes += kobjsize(current->fs);
34091 else
34092 bytes += kobjsize(current->fs);
34093 @@ -165,7 +165,7 @@ static int nommu_vma_show(struct seq_fil
34094
34095 if (file) {
34096 pad_len_spaces(m, len);
34097 - seq_path(m, &file->f_path, "");
34098 + seq_path(m, &file->f_path, "\n\\");
34099 } else if (mm) {
34100 if (vma->vm_start <= mm->start_stack &&
34101 vma->vm_end >= mm->start_stack) {
34102 diff -urNp linux-2.6.37/fs/readdir.c linux-2.6.37/fs/readdir.c
34103 --- linux-2.6.37/fs/readdir.c 2011-01-04 19:50:19.000000000 -0500
34104 +++ linux-2.6.37/fs/readdir.c 2011-01-17 02:41:01.000000000 -0500
34105 @@ -17,6 +17,7 @@
34106 #include <linux/security.h>
34107 #include <linux/syscalls.h>
34108 #include <linux/unistd.h>
34109 +#include <linux/namei.h>
34110
34111 #include <asm/uaccess.h>
34112
34113 @@ -67,6 +68,7 @@ struct old_linux_dirent {
34114
34115 struct readdir_callback {
34116 struct old_linux_dirent __user * dirent;
34117 + struct file * file;
34118 int result;
34119 };
34120
34121 @@ -84,6 +86,10 @@ static int fillonedir(void * __buf, cons
34122 buf->result = -EOVERFLOW;
34123 return -EOVERFLOW;
34124 }
34125 +
34126 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
34127 + return 0;
34128 +
34129 buf->result++;
34130 dirent = buf->dirent;
34131 if (!access_ok(VERIFY_WRITE, dirent,
34132 @@ -116,6 +122,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned in
34133
34134 buf.result = 0;
34135 buf.dirent = dirent;
34136 + buf.file = file;
34137
34138 error = vfs_readdir(file, fillonedir, &buf);
34139 if (buf.result)
34140 @@ -142,6 +149,7 @@ struct linux_dirent {
34141 struct getdents_callback {
34142 struct linux_dirent __user * current_dir;
34143 struct linux_dirent __user * previous;
34144 + struct file * file;
34145 int count;
34146 int error;
34147 };
34148 @@ -163,6 +171,10 @@ static int filldir(void * __buf, const c
34149 buf->error = -EOVERFLOW;
34150 return -EOVERFLOW;
34151 }
34152 +
34153 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
34154 + return 0;
34155 +
34156 dirent = buf->previous;
34157 if (dirent) {
34158 if (__put_user(offset, &dirent->d_off))
34159 @@ -210,6 +222,7 @@ SYSCALL_DEFINE3(getdents, unsigned int,
34160 buf.previous = NULL;
34161 buf.count = count;
34162 buf.error = 0;
34163 + buf.file = file;
34164
34165 error = vfs_readdir(file, filldir, &buf);
34166 if (error >= 0)
34167 @@ -229,6 +242,7 @@ out:
34168 struct getdents_callback64 {
34169 struct linux_dirent64 __user * current_dir;
34170 struct linux_dirent64 __user * previous;
34171 + struct file *file;
34172 int count;
34173 int error;
34174 };
34175 @@ -244,6 +258,10 @@ static int filldir64(void * __buf, const
34176 buf->error = -EINVAL; /* only used if we fail.. */
34177 if (reclen > buf->count)
34178 return -EINVAL;
34179 +
34180 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
34181 + return 0;
34182 +
34183 dirent = buf->previous;
34184 if (dirent) {
34185 if (__put_user(offset, &dirent->d_off))
34186 @@ -291,6 +309,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int
34187
34188 buf.current_dir = dirent;
34189 buf.previous = NULL;
34190 + buf.file = file;
34191 buf.count = count;
34192 buf.error = 0;
34193
34194 diff -urNp linux-2.6.37/fs/reiserfs/do_balan.c linux-2.6.37/fs/reiserfs/do_balan.c
34195 --- linux-2.6.37/fs/reiserfs/do_balan.c 2011-01-04 19:50:19.000000000 -0500
34196 +++ linux-2.6.37/fs/reiserfs/do_balan.c 2011-01-17 02:41:02.000000000 -0500
34197 @@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb,
34198 return;
34199 }
34200
34201 - atomic_inc(&(fs_generation(tb->tb_sb)));
34202 + atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
34203 do_balance_starts(tb);
34204
34205 /* balance leaf returns 0 except if combining L R and S into
34206 diff -urNp linux-2.6.37/fs/reiserfs/item_ops.c linux-2.6.37/fs/reiserfs/item_ops.c
34207 --- linux-2.6.37/fs/reiserfs/item_ops.c 2011-01-04 19:50:19.000000000 -0500
34208 +++ linux-2.6.37/fs/reiserfs/item_ops.c 2011-01-17 02:41:02.000000000 -0500
34209 @@ -102,7 +102,7 @@ static void sd_print_vi(struct virtual_i
34210 vi->vi_index, vi->vi_type, vi->vi_ih);
34211 }
34212
34213 -static struct item_operations stat_data_ops = {
34214 +static const struct item_operations stat_data_ops = {
34215 .bytes_number = sd_bytes_number,
34216 .decrement_key = sd_decrement_key,
34217 .is_left_mergeable = sd_is_left_mergeable,
34218 @@ -196,7 +196,7 @@ static void direct_print_vi(struct virtu
34219 vi->vi_index, vi->vi_type, vi->vi_ih);
34220 }
34221
34222 -static struct item_operations direct_ops = {
34223 +static const struct item_operations direct_ops = {
34224 .bytes_number = direct_bytes_number,
34225 .decrement_key = direct_decrement_key,
34226 .is_left_mergeable = direct_is_left_mergeable,
34227 @@ -341,7 +341,7 @@ static void indirect_print_vi(struct vir
34228 vi->vi_index, vi->vi_type, vi->vi_ih);
34229 }
34230
34231 -static struct item_operations indirect_ops = {
34232 +static const struct item_operations indirect_ops = {
34233 .bytes_number = indirect_bytes_number,
34234 .decrement_key = indirect_decrement_key,
34235 .is_left_mergeable = indirect_is_left_mergeable,
34236 @@ -628,7 +628,7 @@ static void direntry_print_vi(struct vir
34237 printk("\n");
34238 }
34239
34240 -static struct item_operations direntry_ops = {
34241 +static const struct item_operations direntry_ops = {
34242 .bytes_number = direntry_bytes_number,
34243 .decrement_key = direntry_decrement_key,
34244 .is_left_mergeable = direntry_is_left_mergeable,
34245 @@ -724,7 +724,7 @@ static void errcatch_print_vi(struct vir
34246 "Invalid item type observed, run fsck ASAP");
34247 }
34248
34249 -static struct item_operations errcatch_ops = {
34250 +static const struct item_operations errcatch_ops = {
34251 errcatch_bytes_number,
34252 errcatch_decrement_key,
34253 errcatch_is_left_mergeable,
34254 @@ -746,7 +746,7 @@ static struct item_operations errcatch_o
34255 #error Item types must use disk-format assigned values.
34256 #endif
34257
34258 -struct item_operations *item_ops[TYPE_ANY + 1] = {
34259 +const struct item_operations * const item_ops[TYPE_ANY + 1] = {
34260 &stat_data_ops,
34261 &indirect_ops,
34262 &direct_ops,
34263 diff -urNp linux-2.6.37/fs/reiserfs/procfs.c linux-2.6.37/fs/reiserfs/procfs.c
34264 --- linux-2.6.37/fs/reiserfs/procfs.c 2011-01-04 19:50:19.000000000 -0500
34265 +++ linux-2.6.37/fs/reiserfs/procfs.c 2011-01-17 02:41:02.000000000 -0500
34266 @@ -113,7 +113,7 @@ static int show_super(struct seq_file *m
34267 "SMALL_TAILS " : "NO_TAILS ",
34268 replay_only(sb) ? "REPLAY_ONLY " : "",
34269 convert_reiserfs(sb) ? "CONV " : "",
34270 - atomic_read(&r->s_generation_counter),
34271 + atomic_read_unchecked(&r->s_generation_counter),
34272 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
34273 SF(s_do_balance), SF(s_unneeded_left_neighbor),
34274 SF(s_good_search_by_key_reada), SF(s_bmaps),
34275 diff -urNp linux-2.6.37/fs/select.c linux-2.6.37/fs/select.c
34276 --- linux-2.6.37/fs/select.c 2011-01-04 19:50:19.000000000 -0500
34277 +++ linux-2.6.37/fs/select.c 2011-01-17 02:41:02.000000000 -0500
34278 @@ -20,6 +20,7 @@
34279 #include <linux/module.h>
34280 #include <linux/slab.h>
34281 #include <linux/poll.h>
34282 +#include <linux/security.h>
34283 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
34284 #include <linux/file.h>
34285 #include <linux/fdtable.h>
34286 @@ -838,6 +839,7 @@ int do_sys_poll(struct pollfd __user *uf
34287 struct poll_list *walk = head;
34288 unsigned long todo = nfds;
34289
34290 + gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
34291 if (nfds > rlimit(RLIMIT_NOFILE))
34292 return -EINVAL;
34293
34294 diff -urNp linux-2.6.37/fs/seq_file.c linux-2.6.37/fs/seq_file.c
34295 --- linux-2.6.37/fs/seq_file.c 2011-01-04 19:50:19.000000000 -0500
34296 +++ linux-2.6.37/fs/seq_file.c 2011-01-17 02:41:02.000000000 -0500
34297 @@ -76,7 +76,8 @@ static int traverse(struct seq_file *m,
34298 return 0;
34299 }
34300 if (!m->buf) {
34301 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
34302 + m->size = PAGE_SIZE;
34303 + m->buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
34304 if (!m->buf)
34305 return -ENOMEM;
34306 }
34307 @@ -116,7 +117,8 @@ static int traverse(struct seq_file *m,
34308 Eoverflow:
34309 m->op->stop(m, p);
34310 kfree(m->buf);
34311 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
34312 + m->size <<= 1;
34313 + m->buf = kmalloc(m->size, GFP_KERNEL);
34314 return !m->buf ? -ENOMEM : -EAGAIN;
34315 }
34316
34317 @@ -169,7 +171,8 @@ ssize_t seq_read(struct file *file, char
34318 m->version = file->f_version;
34319 /* grab buffer if we didn't have one */
34320 if (!m->buf) {
34321 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
34322 + m->size = PAGE_SIZE;
34323 + m->buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
34324 if (!m->buf)
34325 goto Enomem;
34326 }
34327 @@ -210,7 +213,8 @@ ssize_t seq_read(struct file *file, char
34328 goto Fill;
34329 m->op->stop(m, p);
34330 kfree(m->buf);
34331 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
34332 + m->size <<= 1;
34333 + m->buf = kmalloc(m->size, GFP_KERNEL);
34334 if (!m->buf)
34335 goto Enomem;
34336 m->count = 0;
34337 diff -urNp linux-2.6.37/fs/splice.c linux-2.6.37/fs/splice.c
34338 --- linux-2.6.37/fs/splice.c 2011-01-04 19:50:19.000000000 -0500
34339 +++ linux-2.6.37/fs/splice.c 2011-01-17 02:41:02.000000000 -0500
34340 @@ -186,7 +186,7 @@ ssize_t splice_to_pipe(struct pipe_inode
34341 pipe_lock(pipe);
34342
34343 for (;;) {
34344 - if (!pipe->readers) {
34345 + if (!atomic_read(&pipe->readers)) {
34346 send_sig(SIGPIPE, current, 0);
34347 if (!ret)
34348 ret = -EPIPE;
34349 @@ -240,9 +240,9 @@ ssize_t splice_to_pipe(struct pipe_inode
34350 do_wakeup = 0;
34351 }
34352
34353 - pipe->waiting_writers++;
34354 + atomic_inc(&pipe->waiting_writers);
34355 pipe_wait(pipe);
34356 - pipe->waiting_writers--;
34357 + atomic_dec(&pipe->waiting_writers);
34358 }
34359
34360 pipe_unlock(pipe);
34361 @@ -556,7 +556,7 @@ static ssize_t kernel_readv(struct file
34362 old_fs = get_fs();
34363 set_fs(get_ds());
34364 /* The cast to a user pointer is valid due to the set_fs() */
34365 - res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
34366 + res = vfs_readv(file, (__force const struct iovec __user *)vec, vlen, &pos);
34367 set_fs(old_fs);
34368
34369 return res;
34370 @@ -571,7 +571,7 @@ static ssize_t kernel_write(struct file
34371 old_fs = get_fs();
34372 set_fs(get_ds());
34373 /* The cast to a user pointer is valid due to the set_fs() */
34374 - res = vfs_write(file, (const char __user *)buf, count, &pos);
34375 + res = vfs_write(file, (__force const char __user *)buf, count, &pos);
34376 set_fs(old_fs);
34377
34378 return res;
34379 @@ -622,7 +622,7 @@ ssize_t default_file_splice_read(struct
34380 goto err;
34381
34382 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
34383 - vec[i].iov_base = (void __user *) page_address(page);
34384 + vec[i].iov_base = (__force void __user *) page_address(page);
34385 vec[i].iov_len = this_len;
34386 spd.pages[i] = page;
34387 spd.nr_pages++;
34388 @@ -849,10 +849,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
34389 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
34390 {
34391 while (!pipe->nrbufs) {
34392 - if (!pipe->writers)
34393 + if (!atomic_read(&pipe->writers))
34394 return 0;
34395
34396 - if (!pipe->waiting_writers && sd->num_spliced)
34397 + if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
34398 return 0;
34399
34400 if (sd->flags & SPLICE_F_NONBLOCK)
34401 @@ -1189,7 +1189,7 @@ ssize_t splice_direct_to_actor(struct fi
34402 * out of the pipe right after the splice_to_pipe(). So set
34403 * PIPE_READERS appropriately.
34404 */
34405 - pipe->readers = 1;
34406 + atomic_set(&pipe->readers, 1);
34407
34408 current->splice_pipe = pipe;
34409 }
34410 @@ -1745,9 +1745,9 @@ static int ipipe_prep(struct pipe_inode_
34411 ret = -ERESTARTSYS;
34412 break;
34413 }
34414 - if (!pipe->writers)
34415 + if (!atomic_read(&pipe->writers))
34416 break;
34417 - if (!pipe->waiting_writers) {
34418 + if (!atomic_read(&pipe->waiting_writers)) {
34419 if (flags & SPLICE_F_NONBLOCK) {
34420 ret = -EAGAIN;
34421 break;
34422 @@ -1779,7 +1779,7 @@ static int opipe_prep(struct pipe_inode_
34423 pipe_lock(pipe);
34424
34425 while (pipe->nrbufs >= pipe->buffers) {
34426 - if (!pipe->readers) {
34427 + if (!atomic_read(&pipe->readers)) {
34428 send_sig(SIGPIPE, current, 0);
34429 ret = -EPIPE;
34430 break;
34431 @@ -1792,9 +1792,9 @@ static int opipe_prep(struct pipe_inode_
34432 ret = -ERESTARTSYS;
34433 break;
34434 }
34435 - pipe->waiting_writers++;
34436 + atomic_inc(&pipe->waiting_writers);
34437 pipe_wait(pipe);
34438 - pipe->waiting_writers--;
34439 + atomic_dec(&pipe->waiting_writers);
34440 }
34441
34442 pipe_unlock(pipe);
34443 @@ -1830,14 +1830,14 @@ retry:
34444 pipe_double_lock(ipipe, opipe);
34445
34446 do {
34447 - if (!opipe->readers) {
34448 + if (!atomic_read(&opipe->readers)) {
34449 send_sig(SIGPIPE, current, 0);
34450 if (!ret)
34451 ret = -EPIPE;
34452 break;
34453 }
34454
34455 - if (!ipipe->nrbufs && !ipipe->writers)
34456 + if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
34457 break;
34458
34459 /*
34460 @@ -1937,7 +1937,7 @@ static int link_pipe(struct pipe_inode_i
34461 pipe_double_lock(ipipe, opipe);
34462
34463 do {
34464 - if (!opipe->readers) {
34465 + if (!atomic_read(&opipe->readers)) {
34466 send_sig(SIGPIPE, current, 0);
34467 if (!ret)
34468 ret = -EPIPE;
34469 @@ -1982,7 +1982,7 @@ static int link_pipe(struct pipe_inode_i
34470 * return EAGAIN if we have the potential of some data in the
34471 * future, otherwise just return 0
34472 */
34473 - if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
34474 + if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
34475 ret = -EAGAIN;
34476
34477 pipe_unlock(ipipe);
34478 diff -urNp linux-2.6.37/fs/sysfs/symlink.c linux-2.6.37/fs/sysfs/symlink.c
34479 --- linux-2.6.37/fs/sysfs/symlink.c 2011-01-04 19:50:19.000000000 -0500
34480 +++ linux-2.6.37/fs/sysfs/symlink.c 2011-01-17 02:41:02.000000000 -0500
34481 @@ -286,7 +286,7 @@ static void *sysfs_follow_link(struct de
34482
34483 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
34484 {
34485 - char *page = nd_get_link(nd);
34486 + const char *page = nd_get_link(nd);
34487 if (!IS_ERR(page))
34488 free_page((unsigned long)page);
34489 }
34490 diff -urNp linux-2.6.37/fs/udf/misc.c linux-2.6.37/fs/udf/misc.c
34491 --- linux-2.6.37/fs/udf/misc.c 2011-01-04 19:50:19.000000000 -0500
34492 +++ linux-2.6.37/fs/udf/misc.c 2011-01-17 02:41:02.000000000 -0500
34493 @@ -142,8 +142,8 @@ struct genericFormat *udf_add_extendedat
34494 iinfo->i_lenEAttr += size;
34495 return (struct genericFormat *)&ea[offset];
34496 }
34497 - if (loc & 0x02)
34498 - ;
34499 + if (loc & 0x02) {
34500 + }
34501
34502 return NULL;
34503 }
34504 @@ -286,7 +286,7 @@ void udf_new_tag(char *data, uint16_t id
34505
34506 u8 udf_tag_checksum(const struct tag *t)
34507 {
34508 - u8 *data = (u8 *)t;
34509 + const u8 *data = (const u8 *)t;
34510 u8 checksum = 0;
34511 int i;
34512 for (i = 0; i < sizeof(struct tag); ++i)
34513 diff -urNp linux-2.6.37/fs/udf/udfdecl.h linux-2.6.37/fs/udf/udfdecl.h
34514 --- linux-2.6.37/fs/udf/udfdecl.h 2011-01-04 19:50:19.000000000 -0500
34515 +++ linux-2.6.37/fs/udf/udfdecl.h 2011-01-17 02:41:02.000000000 -0500
34516 @@ -26,7 +26,7 @@ do { \
34517 printk(f, ##a); \
34518 } while (0)
34519 #else
34520 -#define udf_debug(f, a...) /**/
34521 +#define udf_debug(f, a...) do {} while (0)
34522 #endif
34523
34524 #define udf_info(f, a...) \
34525 diff -urNp linux-2.6.37/fs/utimes.c linux-2.6.37/fs/utimes.c
34526 --- linux-2.6.37/fs/utimes.c 2011-01-04 19:50:19.000000000 -0500
34527 +++ linux-2.6.37/fs/utimes.c 2011-01-17 02:41:02.000000000 -0500
34528 @@ -1,6 +1,7 @@
34529 #include <linux/compiler.h>
34530 #include <linux/file.h>
34531 #include <linux/fs.h>
34532 +#include <linux/security.h>
34533 #include <linux/linkage.h>
34534 #include <linux/mount.h>
34535 #include <linux/namei.h>
34536 @@ -101,6 +102,12 @@ static int utimes_common(struct path *pa
34537 goto mnt_drop_write_and_out;
34538 }
34539 }
34540 +
34541 + if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
34542 + error = -EACCES;
34543 + goto mnt_drop_write_and_out;
34544 + }
34545 +
34546 mutex_lock(&inode->i_mutex);
34547 error = notify_change(path->dentry, &newattrs);
34548 mutex_unlock(&inode->i_mutex);
34549 diff -urNp linux-2.6.37/fs/xattr_acl.c linux-2.6.37/fs/xattr_acl.c
34550 --- linux-2.6.37/fs/xattr_acl.c 2011-01-04 19:50:19.000000000 -0500
34551 +++ linux-2.6.37/fs/xattr_acl.c 2011-01-17 02:41:02.000000000 -0500
34552 @@ -17,8 +17,8 @@
34553 struct posix_acl *
34554 posix_acl_from_xattr(const void *value, size_t size)
34555 {
34556 - posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
34557 - posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
34558 + const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
34559 + const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
34560 int count;
34561 struct posix_acl *acl;
34562 struct posix_acl_entry *acl_e;
34563 diff -urNp linux-2.6.37/fs/xattr.c linux-2.6.37/fs/xattr.c
34564 --- linux-2.6.37/fs/xattr.c 2011-01-04 19:50:19.000000000 -0500
34565 +++ linux-2.6.37/fs/xattr.c 2011-01-17 02:41:02.000000000 -0500
34566 @@ -247,7 +247,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
34567 * Extended attribute SET operations
34568 */
34569 static long
34570 -setxattr(struct dentry *d, const char __user *name, const void __user *value,
34571 +setxattr(struct path *path, const char __user *name, const void __user *value,
34572 size_t size, int flags)
34573 {
34574 int error;
34575 @@ -271,7 +271,13 @@ setxattr(struct dentry *d, const char __
34576 return PTR_ERR(kvalue);
34577 }
34578
34579 - error = vfs_setxattr(d, kname, kvalue, size, flags);
34580 + if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
34581 + error = -EACCES;
34582 + goto out;
34583 + }
34584 +
34585 + error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
34586 +out:
34587 kfree(kvalue);
34588 return error;
34589 }
34590 @@ -288,7 +294,7 @@ SYSCALL_DEFINE5(setxattr, const char __u
34591 return error;
34592 error = mnt_want_write(path.mnt);
34593 if (!error) {
34594 - error = setxattr(path.dentry, name, value, size, flags);
34595 + error = setxattr(&path, name, value, size, flags);
34596 mnt_drop_write(path.mnt);
34597 }
34598 path_put(&path);
34599 @@ -307,7 +313,7 @@ SYSCALL_DEFINE5(lsetxattr, const char __
34600 return error;
34601 error = mnt_want_write(path.mnt);
34602 if (!error) {
34603 - error = setxattr(path.dentry, name, value, size, flags);
34604 + error = setxattr(&path, name, value, size, flags);
34605 mnt_drop_write(path.mnt);
34606 }
34607 path_put(&path);
34608 @@ -318,17 +324,15 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, cons
34609 const void __user *,value, size_t, size, int, flags)
34610 {
34611 struct file *f;
34612 - struct dentry *dentry;
34613 int error = -EBADF;
34614
34615 f = fget(fd);
34616 if (!f)
34617 return error;
34618 - dentry = f->f_path.dentry;
34619 - audit_inode(NULL, dentry);
34620 + audit_inode(NULL, f->f_path.dentry);
34621 error = mnt_want_write_file(f);
34622 if (!error) {
34623 - error = setxattr(dentry, name, value, size, flags);
34624 + error = setxattr(&f->f_path, name, value, size, flags);
34625 mnt_drop_write(f->f_path.mnt);
34626 }
34627 fput(f);
34628 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
34629 --- linux-2.6.37/fs/xfs/linux-2.6/xfs_ioctl.c 2011-01-04 19:50:19.000000000 -0500
34630 +++ linux-2.6.37/fs/xfs/linux-2.6/xfs_ioctl.c 2011-01-17 02:41:02.000000000 -0500
34631 @@ -127,7 +127,7 @@ xfs_find_handle(
34632 }
34633
34634 error = -EFAULT;
34635 - if (copy_to_user(hreq->ohandle, &handle, hsize) ||
34636 + if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
34637 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
34638 goto out_put;
34639
34640 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
34641 --- linux-2.6.37/fs/xfs/linux-2.6/xfs_iops.c 2011-01-04 19:50:19.000000000 -0500
34642 +++ linux-2.6.37/fs/xfs/linux-2.6/xfs_iops.c 2011-01-17 02:41:02.000000000 -0500
34643 @@ -437,7 +437,7 @@ xfs_vn_put_link(
34644 struct nameidata *nd,
34645 void *p)
34646 {
34647 - char *s = nd_get_link(nd);
34648 + const char *s = nd_get_link(nd);
34649
34650 if (!IS_ERR(s))
34651 kfree(s);
34652 diff -urNp linux-2.6.37/fs/xfs/xfs_bmap.c linux-2.6.37/fs/xfs/xfs_bmap.c
34653 --- linux-2.6.37/fs/xfs/xfs_bmap.c 2011-01-04 19:50:19.000000000 -0500
34654 +++ linux-2.6.37/fs/xfs/xfs_bmap.c 2011-01-17 02:41:02.000000000 -0500
34655 @@ -287,7 +287,7 @@ xfs_bmap_validate_ret(
34656 int nmap,
34657 int ret_nmap);
34658 #else
34659 -#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
34660 +#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
34661 #endif /* DEBUG */
34662
34663 STATIC int
34664 diff -urNp linux-2.6.37/grsecurity/gracl_alloc.c linux-2.6.37/grsecurity/gracl_alloc.c
34665 --- linux-2.6.37/grsecurity/gracl_alloc.c 1969-12-31 19:00:00.000000000 -0500
34666 +++ linux-2.6.37/grsecurity/gracl_alloc.c 2011-01-17 02:41:02.000000000 -0500
34667 @@ -0,0 +1,105 @@
34668 +#include <linux/kernel.h>
34669 +#include <linux/mm.h>
34670 +#include <linux/slab.h>
34671 +#include <linux/vmalloc.h>
34672 +#include <linux/gracl.h>
34673 +#include <linux/grsecurity.h>
34674 +
34675 +static unsigned long alloc_stack_next = 1;
34676 +static unsigned long alloc_stack_size = 1;
34677 +static void **alloc_stack;
34678 +
34679 +static __inline__ int
34680 +alloc_pop(void)
34681 +{
34682 + if (alloc_stack_next == 1)
34683 + return 0;
34684 +
34685 + kfree(alloc_stack[alloc_stack_next - 2]);
34686 +
34687 + alloc_stack_next--;
34688 +
34689 + return 1;
34690 +}
34691 +
34692 +static __inline__ int
34693 +alloc_push(void *buf)
34694 +{
34695 + if (alloc_stack_next >= alloc_stack_size)
34696 + return 1;
34697 +
34698 + alloc_stack[alloc_stack_next - 1] = buf;
34699 +
34700 + alloc_stack_next++;
34701 +
34702 + return 0;
34703 +}
34704 +
34705 +void *
34706 +acl_alloc(unsigned long len)
34707 +{
34708 + void *ret = NULL;
34709 +
34710 + if (!len || len > PAGE_SIZE)
34711 + goto out;
34712 +
34713 + ret = kmalloc(len, GFP_KERNEL);
34714 +
34715 + if (ret) {
34716 + if (alloc_push(ret)) {
34717 + kfree(ret);
34718 + ret = NULL;
34719 + }
34720 + }
34721 +
34722 +out:
34723 + return ret;
34724 +}
34725 +
34726 +void *
34727 +acl_alloc_num(unsigned long num, unsigned long len)
34728 +{
34729 + if (!len || (num > (PAGE_SIZE / len)))
34730 + return NULL;
34731 +
34732 + return acl_alloc(num * len);
34733 +}
34734 +
34735 +void
34736 +acl_free_all(void)
34737 +{
34738 + if (gr_acl_is_enabled() || !alloc_stack)
34739 + return;
34740 +
34741 + while (alloc_pop()) ;
34742 +
34743 + if (alloc_stack) {
34744 + if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
34745 + kfree(alloc_stack);
34746 + else
34747 + vfree(alloc_stack);
34748 + }
34749 +
34750 + alloc_stack = NULL;
34751 + alloc_stack_size = 1;
34752 + alloc_stack_next = 1;
34753 +
34754 + return;
34755 +}
34756 +
34757 +int
34758 +acl_alloc_stack_init(unsigned long size)
34759 +{
34760 + if ((size * sizeof (void *)) <= PAGE_SIZE)
34761 + alloc_stack =
34762 + (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
34763 + else
34764 + alloc_stack = (void **) vmalloc(size * sizeof (void *));
34765 +
34766 + alloc_stack_size = size;
34767 +
34768 + if (!alloc_stack)
34769 + return 0;
34770 + else
34771 + return 1;
34772 +}
34773 diff -urNp linux-2.6.37/grsecurity/gracl.c linux-2.6.37/grsecurity/gracl.c
34774 --- linux-2.6.37/grsecurity/gracl.c 1969-12-31 19:00:00.000000000 -0500
34775 +++ linux-2.6.37/grsecurity/gracl.c 2011-01-17 02:41:02.000000000 -0500
34776 @@ -0,0 +1,3991 @@
34777 +#include <linux/kernel.h>
34778 +#include <linux/module.h>
34779 +#include <linux/sched.h>
34780 +#include <linux/mm.h>
34781 +#include <linux/file.h>
34782 +#include <linux/fs.h>
34783 +#include <linux/namei.h>
34784 +#include <linux/mount.h>
34785 +#include <linux/tty.h>
34786 +#include <linux/proc_fs.h>
34787 +#include <linux/smp_lock.h>
34788 +#include <linux/lglock.h>
34789 +#include <linux/slab.h>
34790 +#include <linux/vmalloc.h>
34791 +#include <linux/types.h>
34792 +#include <linux/sysctl.h>
34793 +#include <linux/netdevice.h>
34794 +#include <linux/ptrace.h>
34795 +#include <linux/gracl.h>
34796 +#include <linux/gralloc.h>
34797 +#include <linux/grsecurity.h>
34798 +#include <linux/grinternal.h>
34799 +#include <linux/pid_namespace.h>
34800 +#include <linux/fdtable.h>
34801 +#include <linux/percpu.h>
34802 +
34803 +#include <asm/uaccess.h>
34804 +#include <asm/errno.h>
34805 +#include <asm/mman.h>
34806 +
34807 +static struct acl_role_db acl_role_set;
34808 +static struct name_db name_set;
34809 +static struct inodev_db inodev_set;
34810 +
34811 +/* for keeping track of userspace pointers used for subjects, so we
34812 + can share references in the kernel as well
34813 +*/
34814 +
34815 +static struct path real_root;
34816 +
34817 +static struct acl_subj_map_db subj_map_set;
34818 +
34819 +static struct acl_role_label *default_role;
34820 +
34821 +static struct acl_role_label *role_list;
34822 +
34823 +static u16 acl_sp_role_value;
34824 +
34825 +extern char *gr_shared_page[4];
34826 +static DEFINE_MUTEX(gr_dev_mutex);
34827 +DEFINE_RWLOCK(gr_inode_lock);
34828 +
34829 +struct gr_arg *gr_usermode;
34830 +
34831 +static unsigned int gr_status __read_only = GR_STATUS_INIT;
34832 +
34833 +extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
34834 +extern void gr_clear_learn_entries(void);
34835 +
34836 +#ifdef CONFIG_GRKERNSEC_RESLOG
34837 +extern void gr_log_resource(const struct task_struct *task,
34838 + const int res, const unsigned long wanted, const int gt);
34839 +#endif
34840 +
34841 +unsigned char *gr_system_salt;
34842 +unsigned char *gr_system_sum;
34843 +
34844 +static struct sprole_pw **acl_special_roles = NULL;
34845 +static __u16 num_sprole_pws = 0;
34846 +
34847 +static struct acl_role_label *kernel_role = NULL;
34848 +
34849 +static unsigned int gr_auth_attempts = 0;
34850 +static unsigned long gr_auth_expires = 0UL;
34851 +
34852 +extern struct vfsmount *sock_mnt;
34853 +extern struct vfsmount *pipe_mnt;
34854 +extern struct vfsmount *shm_mnt;
34855 +#ifdef CONFIG_HUGETLBFS
34856 +extern struct vfsmount *hugetlbfs_vfsmount;
34857 +#endif
34858 +
34859 +static struct acl_object_label *fakefs_obj;
34860 +
34861 +extern int gr_init_uidset(void);
34862 +extern void gr_free_uidset(void);
34863 +extern void gr_remove_uid(uid_t uid);
34864 +extern int gr_find_uid(uid_t uid);
34865 +
34866 +DECLARE_BRLOCK(vfsmount_lock);
34867 +
34868 +__inline__ int
34869 +gr_acl_is_enabled(void)
34870 +{
34871 + return (gr_status & GR_READY);
34872 +}
34873 +
34874 +static char gr_task_roletype_to_char(struct task_struct *task)
34875 +{
34876 + switch (task->role->roletype &
34877 + (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
34878 + GR_ROLE_SPECIAL)) {
34879 + case GR_ROLE_DEFAULT:
34880 + return 'D';
34881 + case GR_ROLE_USER:
34882 + return 'U';
34883 + case GR_ROLE_GROUP:
34884 + return 'G';
34885 + case GR_ROLE_SPECIAL:
34886 + return 'S';
34887 + }
34888 +
34889 + return 'X';
34890 +}
34891 +
34892 +char gr_roletype_to_char(void)
34893 +{
34894 + return gr_task_roletype_to_char(current);
34895 +}
34896 +
34897 +__inline__ int
34898 +gr_acl_tpe_check(void)
34899 +{
34900 + if (unlikely(!(gr_status & GR_READY)))
34901 + return 0;
34902 + if (current->role->roletype & GR_ROLE_TPE)
34903 + return 1;
34904 + else
34905 + return 0;
34906 +}
34907 +
34908 +int
34909 +gr_handle_rawio(const struct inode *inode)
34910 +{
34911 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
34912 + if (inode && S_ISBLK(inode->i_mode) &&
34913 + grsec_enable_chroot_caps && proc_is_chrooted(current) &&
34914 + !capable(CAP_SYS_RAWIO))
34915 + return 1;
34916 +#endif
34917 + return 0;
34918 +}
34919 +
34920 +static int
34921 +gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
34922 +{
34923 + if (likely(lena != lenb))
34924 + return 0;
34925 +
34926 + return !memcmp(a, b, lena);
34927 +}
34928 +
34929 +static int prepend(char **buffer, int *buflen, const char *str, int namelen)
34930 +{
34931 + *buflen -= namelen;
34932 + if (*buflen < 0)
34933 + return -ENAMETOOLONG;
34934 + *buffer -= namelen;
34935 + memcpy(*buffer, str, namelen);
34936 + return 0;
34937 +}
34938 +
34939 +static int prepend_name(char **buffer, int *buflen, struct qstr *name)
34940 +{
34941 + return prepend(buffer, buflen, name->name, name->len);
34942 +}
34943 +
34944 +static int prepend_path(const struct path *path, struct path *root,
34945 + char **buffer, int *buflen)
34946 +{
34947 + struct dentry *dentry = path->dentry;
34948 + struct vfsmount *vfsmnt = path->mnt;
34949 + bool slash = false;
34950 + int error = 0;
34951 +
34952 + while (dentry != root->dentry || vfsmnt != root->mnt) {
34953 + struct dentry * parent;
34954 +
34955 + if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
34956 + /* Global root? */
34957 + if (vfsmnt->mnt_parent == vfsmnt) {
34958 + goto out;
34959 + }
34960 + dentry = vfsmnt->mnt_mountpoint;
34961 + vfsmnt = vfsmnt->mnt_parent;
34962 + continue;
34963 + }
34964 + parent = dentry->d_parent;
34965 + prefetch(parent);
34966 + error = prepend_name(buffer, buflen, &dentry->d_name);
34967 + if (!error)
34968 + error = prepend(buffer, buflen, "/", 1);
34969 + if (error)
34970 + break;
34971 +
34972 + slash = true;
34973 + dentry = parent;
34974 + }
34975 +
34976 +out:
34977 + if (!error && !slash)
34978 + error = prepend(buffer, buflen, "/", 1);
34979 +
34980 + return error;
34981 +}
34982 +
34983 +/* this must be called with vfsmount_lock and dcache_lock held */
34984 +
34985 +static char *__our_d_path(const struct path *path, struct path *root,
34986 + char *buf, int buflen)
34987 +{
34988 + char *res = buf + buflen;
34989 + int error;
34990 +
34991 + prepend(&res, &buflen, "\0", 1);
34992 + error = prepend_path(path, root, &res, &buflen);
34993 + if (error)
34994 + return ERR_PTR(error);
34995 +
34996 + return res;
34997 +}
34998 +
34999 +static char *
35000 +gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
35001 +{
35002 + char *retval;
35003 +
35004 + retval = __our_d_path(path, root, buf, buflen);
35005 + if (unlikely(IS_ERR(retval)))
35006 + retval = strcpy(buf, "<path too long>");
35007 + else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
35008 + retval[1] = '\0';
35009 +
35010 + return retval;
35011 +}
35012 +
35013 +static char *
35014 +__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
35015 + char *buf, int buflen)
35016 +{
35017 + struct path path;
35018 + char *res;
35019 +
35020 + path.dentry = (struct dentry *)dentry;
35021 + path.mnt = (struct vfsmount *)vfsmnt;
35022 +
35023 + /* we can use real_root.dentry, real_root.mnt, because this is only called
35024 + by the RBAC system */
35025 + res = gen_full_path(&path, &real_root, buf, buflen);
35026 +
35027 + return res;
35028 +}
35029 +
35030 +static char *
35031 +d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
35032 + char *buf, int buflen)
35033 +{
35034 + char *res;
35035 + struct path path;
35036 + struct path root;
35037 + struct task_struct *reaper = &init_task;
35038 +
35039 + path.dentry = (struct dentry *)dentry;
35040 + path.mnt = (struct vfsmount *)vfsmnt;
35041 +
35042 + /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
35043 + get_fs_root(reaper->fs, &root);
35044 +
35045 + spin_lock(&dcache_lock);
35046 + br_read_lock(vfsmount_lock);
35047 + res = gen_full_path(&path, &root, buf, buflen);
35048 + br_read_unlock(vfsmount_lock);
35049 + spin_unlock(&dcache_lock);
35050 +
35051 + path_put(&root);
35052 + return res;
35053 +}
35054 +
35055 +static char *
35056 +gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
35057 +{
35058 + char *ret;
35059 + spin_lock(&dcache_lock);
35060 + br_read_lock(vfsmount_lock);
35061 + ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
35062 + PAGE_SIZE);
35063 + br_read_unlock(vfsmount_lock);
35064 + spin_unlock(&dcache_lock);
35065 + return ret;
35066 +}
35067 +
35068 +char *
35069 +gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
35070 +{
35071 + return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
35072 + PAGE_SIZE);
35073 +}
35074 +
35075 +char *
35076 +gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
35077 +{
35078 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
35079 + PAGE_SIZE);
35080 +}
35081 +
35082 +char *
35083 +gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
35084 +{
35085 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
35086 + PAGE_SIZE);
35087 +}
35088 +
35089 +char *
35090 +gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
35091 +{
35092 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
35093 + PAGE_SIZE);
35094 +}
35095 +
35096 +char *
35097 +gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
35098 +{
35099 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
35100 + PAGE_SIZE);
35101 +}
35102 +
35103 +__inline__ __u32
35104 +to_gr_audit(const __u32 reqmode)
35105 +{
35106 + /* masks off auditable permission flags, then shifts them to create
35107 + auditing flags, and adds the special case of append auditing if
35108 + we're requesting write */
35109 + return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
35110 +}
35111 +
35112 +struct acl_subject_label *
35113 +lookup_subject_map(const struct acl_subject_label *userp)
35114 +{
35115 + unsigned int index = shash(userp, subj_map_set.s_size);
35116 + struct subject_map *match;
35117 +
35118 + match = subj_map_set.s_hash[index];
35119 +
35120 + while (match && match->user != userp)
35121 + match = match->next;
35122 +
35123 + if (match != NULL)
35124 + return match->kernel;
35125 + else
35126 + return NULL;
35127 +}
35128 +
35129 +static void
35130 +insert_subj_map_entry(struct subject_map *subjmap)
35131 +{
35132 + unsigned int index = shash(subjmap->user, subj_map_set.s_size);
35133 + struct subject_map **curr;
35134 +
35135 + subjmap->prev = NULL;
35136 +
35137 + curr = &subj_map_set.s_hash[index];
35138 + if (*curr != NULL)
35139 + (*curr)->prev = subjmap;
35140 +
35141 + subjmap->next = *curr;
35142 + *curr = subjmap;
35143 +
35144 + return;
35145 +}
35146 +
35147 +static struct acl_role_label *
35148 +lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
35149 + const gid_t gid)
35150 +{
35151 + unsigned int index = rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
35152 + struct acl_role_label *match;
35153 + struct role_allowed_ip *ipp;
35154 + unsigned int x;
35155 + u32 curr_ip = task->signal->curr_ip;
35156 +
35157 + task->signal->saved_ip = curr_ip;
35158 +
35159 + match = acl_role_set.r_hash[index];
35160 +
35161 + while (match) {
35162 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
35163 + for (x = 0; x < match->domain_child_num; x++) {
35164 + if (match->domain_children[x] == uid)
35165 + goto found;
35166 + }
35167 + } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
35168 + break;
35169 + match = match->next;
35170 + }
35171 +found:
35172 + if (match == NULL) {
35173 + try_group:
35174 + index = rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
35175 + match = acl_role_set.r_hash[index];
35176 +
35177 + while (match) {
35178 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
35179 + for (x = 0; x < match->domain_child_num; x++) {
35180 + if (match->domain_children[x] == gid)
35181 + goto found2;
35182 + }
35183 + } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
35184 + break;
35185 + match = match->next;
35186 + }
35187 +found2:
35188 + if (match == NULL)
35189 + match = default_role;
35190 + if (match->allowed_ips == NULL)
35191 + return match;
35192 + else {
35193 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
35194 + if (likely
35195 + ((ntohl(curr_ip) & ipp->netmask) ==
35196 + (ntohl(ipp->addr) & ipp->netmask)))
35197 + return match;
35198 + }
35199 + match = default_role;
35200 + }
35201 + } else if (match->allowed_ips == NULL) {
35202 + return match;
35203 + } else {
35204 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
35205 + if (likely
35206 + ((ntohl(curr_ip) & ipp->netmask) ==
35207 + (ntohl(ipp->addr) & ipp->netmask)))
35208 + return match;
35209 + }
35210 + goto try_group;
35211 + }
35212 +
35213 + return match;
35214 +}
35215 +
35216 +struct acl_subject_label *
35217 +lookup_acl_subj_label(const ino_t ino, const dev_t dev,
35218 + const struct acl_role_label *role)
35219 +{
35220 + unsigned int index = fhash(ino, dev, role->subj_hash_size);
35221 + struct acl_subject_label *match;
35222 +
35223 + match = role->subj_hash[index];
35224 +
35225 + while (match && (match->inode != ino || match->device != dev ||
35226 + (match->mode & GR_DELETED))) {
35227 + match = match->next;
35228 + }
35229 +
35230 + if (match && !(match->mode & GR_DELETED))
35231 + return match;
35232 + else
35233 + return NULL;
35234 +}
35235 +
35236 +struct acl_subject_label *
35237 +lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
35238 + const struct acl_role_label *role)
35239 +{
35240 + unsigned int index = fhash(ino, dev, role->subj_hash_size);
35241 + struct acl_subject_label *match;
35242 +
35243 + match = role->subj_hash[index];
35244 +
35245 + while (match && (match->inode != ino || match->device != dev ||
35246 + !(match->mode & GR_DELETED))) {
35247 + match = match->next;
35248 + }
35249 +
35250 + if (match && (match->mode & GR_DELETED))
35251 + return match;
35252 + else
35253 + return NULL;
35254 +}
35255 +
35256 +static struct acl_object_label *
35257 +lookup_acl_obj_label(const ino_t ino, const dev_t dev,
35258 + const struct acl_subject_label *subj)
35259 +{
35260 + unsigned int index = fhash(ino, dev, subj->obj_hash_size);
35261 + struct acl_object_label *match;
35262 +
35263 + match = subj->obj_hash[index];
35264 +
35265 + while (match && (match->inode != ino || match->device != dev ||
35266 + (match->mode & GR_DELETED))) {
35267 + match = match->next;
35268 + }
35269 +
35270 + if (match && !(match->mode & GR_DELETED))
35271 + return match;
35272 + else
35273 + return NULL;
35274 +}
35275 +
35276 +static struct acl_object_label *
35277 +lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
35278 + const struct acl_subject_label *subj)
35279 +{
35280 + unsigned int index = fhash(ino, dev, subj->obj_hash_size);
35281 + struct acl_object_label *match;
35282 +
35283 + match = subj->obj_hash[index];
35284 +
35285 + while (match && (match->inode != ino || match->device != dev ||
35286 + !(match->mode & GR_DELETED))) {
35287 + match = match->next;
35288 + }
35289 +
35290 + if (match && (match->mode & GR_DELETED))
35291 + return match;
35292 +
35293 + match = subj->obj_hash[index];
35294 +
35295 + while (match && (match->inode != ino || match->device != dev ||
35296 + (match->mode & GR_DELETED))) {
35297 + match = match->next;
35298 + }
35299 +
35300 + if (match && !(match->mode & GR_DELETED))
35301 + return match;
35302 + else
35303 + return NULL;
35304 +}
35305 +
35306 +static struct name_entry *
35307 +lookup_name_entry(const char *name)
35308 +{
35309 + unsigned int len = strlen(name);
35310 + unsigned int key = full_name_hash(name, len);
35311 + unsigned int index = key % name_set.n_size;
35312 + struct name_entry *match;
35313 +
35314 + match = name_set.n_hash[index];
35315 +
35316 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
35317 + match = match->next;
35318 +
35319 + return match;
35320 +}
35321 +
35322 +static struct name_entry *
35323 +lookup_name_entry_create(const char *name)
35324 +{
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;
35329 +
35330 + match = name_set.n_hash[index];
35331 +
35332 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
35333 + !match->deleted))
35334 + match = match->next;
35335 +
35336 + if (match && match->deleted)
35337 + return match;
35338 +
35339 + match = name_set.n_hash[index];
35340 +
35341 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
35342 + match->deleted))
35343 + match = match->next;
35344 +
35345 + if (match && !match->deleted)
35346 + return match;
35347 + else
35348 + return NULL;
35349 +}
35350 +
35351 +static struct inodev_entry *
35352 +lookup_inodev_entry(const ino_t ino, const dev_t dev)
35353 +{
35354 + unsigned int index = fhash(ino, dev, inodev_set.i_size);
35355 + struct inodev_entry *match;
35356 +
35357 + match = inodev_set.i_hash[index];
35358 +
35359 + while (match && (match->nentry->inode != ino || match->nentry->device != dev))
35360 + match = match->next;
35361 +
35362 + return match;
35363 +}
35364 +
35365 +static void
35366 +insert_inodev_entry(struct inodev_entry *entry)
35367 +{
35368 + unsigned int index = fhash(entry->nentry->inode, entry->nentry->device,
35369 + inodev_set.i_size);
35370 + struct inodev_entry **curr;
35371 +
35372 + entry->prev = NULL;
35373 +
35374 + curr = &inodev_set.i_hash[index];
35375 + if (*curr != NULL)
35376 + (*curr)->prev = entry;
35377 +
35378 + entry->next = *curr;
35379 + *curr = entry;
35380 +
35381 + return;
35382 +}
35383 +
35384 +static void
35385 +__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
35386 +{
35387 + unsigned int index =
35388 + rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
35389 + struct acl_role_label **curr;
35390 + struct acl_role_label *tmp;
35391 +
35392 + curr = &acl_role_set.r_hash[index];
35393 +
35394 + /* if role was already inserted due to domains and already has
35395 + a role in the same bucket as it attached, then we need to
35396 + combine these two buckets
35397 + */
35398 + if (role->next) {
35399 + tmp = role->next;
35400 + while (tmp->next)
35401 + tmp = tmp->next;
35402 + tmp->next = *curr;
35403 + } else
35404 + role->next = *curr;
35405 + *curr = role;
35406 +
35407 + return;
35408 +}
35409 +
35410 +static void
35411 +insert_acl_role_label(struct acl_role_label *role)
35412 +{
35413 + int i;
35414 +
35415 + if (role_list == NULL) {
35416 + role_list = role;
35417 + role->prev = NULL;
35418 + } else {
35419 + role->prev = role_list;
35420 + role_list = role;
35421 + }
35422 +
35423 + /* used for hash chains */
35424 + role->next = NULL;
35425 +
35426 + if (role->roletype & GR_ROLE_DOMAIN) {
35427 + for (i = 0; i < role->domain_child_num; i++)
35428 + __insert_acl_role_label(role, role->domain_children[i]);
35429 + } else
35430 + __insert_acl_role_label(role, role->uidgid);
35431 +}
35432 +
35433 +static int
35434 +insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
35435 +{
35436 + struct name_entry **curr, *nentry;
35437 + struct inodev_entry *ientry;
35438 + unsigned int len = strlen(name);
35439 + unsigned int key = full_name_hash(name, len);
35440 + unsigned int index = key % name_set.n_size;
35441 +
35442 + curr = &name_set.n_hash[index];
35443 +
35444 + while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
35445 + curr = &((*curr)->next);
35446 +
35447 + if (*curr != NULL)
35448 + return 1;
35449 +
35450 + nentry = acl_alloc(sizeof (struct name_entry));
35451 + if (nentry == NULL)
35452 + return 0;
35453 + ientry = acl_alloc(sizeof (struct inodev_entry));
35454 + if (ientry == NULL)
35455 + return 0;
35456 + ientry->nentry = nentry;
35457 +
35458 + nentry->key = key;
35459 + nentry->name = name;
35460 + nentry->inode = inode;
35461 + nentry->device = device;
35462 + nentry->len = len;
35463 + nentry->deleted = deleted;
35464 +
35465 + nentry->prev = NULL;
35466 + curr = &name_set.n_hash[index];
35467 + if (*curr != NULL)
35468 + (*curr)->prev = nentry;
35469 + nentry->next = *curr;
35470 + *curr = nentry;
35471 +
35472 + /* insert us into the table searchable by inode/dev */
35473 + insert_inodev_entry(ientry);
35474 +
35475 + return 1;
35476 +}
35477 +
35478 +static void
35479 +insert_acl_obj_label(struct acl_object_label *obj,
35480 + struct acl_subject_label *subj)
35481 +{
35482 + unsigned int index =
35483 + fhash(obj->inode, obj->device, subj->obj_hash_size);
35484 + struct acl_object_label **curr;
35485 +
35486 +
35487 + obj->prev = NULL;
35488 +
35489 + curr = &subj->obj_hash[index];
35490 + if (*curr != NULL)
35491 + (*curr)->prev = obj;
35492 +
35493 + obj->next = *curr;
35494 + *curr = obj;
35495 +
35496 + return;
35497 +}
35498 +
35499 +static void
35500 +insert_acl_subj_label(struct acl_subject_label *obj,
35501 + struct acl_role_label *role)
35502 +{
35503 + unsigned int index = fhash(obj->inode, obj->device, role->subj_hash_size);
35504 + struct acl_subject_label **curr;
35505 +
35506 + obj->prev = NULL;
35507 +
35508 + curr = &role->subj_hash[index];
35509 + if (*curr != NULL)
35510 + (*curr)->prev = obj;
35511 +
35512 + obj->next = *curr;
35513 + *curr = obj;
35514 +
35515 + return;
35516 +}
35517 +
35518 +/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
35519 +
35520 +static void *
35521 +create_table(__u32 * len, int elementsize)
35522 +{
35523 + unsigned int table_sizes[] = {
35524 + 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
35525 + 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
35526 + 4194301, 8388593, 16777213, 33554393, 67108859
35527 + };
35528 + void *newtable = NULL;
35529 + unsigned int pwr = 0;
35530 +
35531 + while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
35532 + table_sizes[pwr] <= *len)
35533 + pwr++;
35534 +
35535 + if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
35536 + return newtable;
35537 +
35538 + if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
35539 + newtable =
35540 + kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
35541 + else
35542 + newtable = vmalloc(table_sizes[pwr] * elementsize);
35543 +
35544 + *len = table_sizes[pwr];
35545 +
35546 + return newtable;
35547 +}
35548 +
35549 +static int
35550 +init_variables(const struct gr_arg *arg)
35551 +{
35552 + struct task_struct *reaper = &init_task;
35553 + unsigned int stacksize;
35554 +
35555 + subj_map_set.s_size = arg->role_db.num_subjects;
35556 + acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
35557 + name_set.n_size = arg->role_db.num_objects;
35558 + inodev_set.i_size = arg->role_db.num_objects;
35559 +
35560 + if (!subj_map_set.s_size || !acl_role_set.r_size ||
35561 + !name_set.n_size || !inodev_set.i_size)
35562 + return 1;
35563 +
35564 + if (!gr_init_uidset())
35565 + return 1;
35566 +
35567 + /* set up the stack that holds allocation info */
35568 +
35569 + stacksize = arg->role_db.num_pointers + 5;
35570 +
35571 + if (!acl_alloc_stack_init(stacksize))
35572 + return 1;
35573 +
35574 + /* grab reference for the real root dentry and vfsmount */
35575 + get_fs_root(reaper->fs, &real_root);
35576 +
35577 + fakefs_obj = acl_alloc(sizeof(struct acl_object_label));
35578 + if (fakefs_obj == NULL)
35579 + return 1;
35580 + fakefs_obj->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
35581 +
35582 + subj_map_set.s_hash =
35583 + (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
35584 + acl_role_set.r_hash =
35585 + (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
35586 + name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
35587 + inodev_set.i_hash =
35588 + (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
35589 +
35590 + if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
35591 + !name_set.n_hash || !inodev_set.i_hash)
35592 + return 1;
35593 +
35594 + memset(subj_map_set.s_hash, 0,
35595 + sizeof(struct subject_map *) * subj_map_set.s_size);
35596 + memset(acl_role_set.r_hash, 0,
35597 + sizeof (struct acl_role_label *) * acl_role_set.r_size);
35598 + memset(name_set.n_hash, 0,
35599 + sizeof (struct name_entry *) * name_set.n_size);
35600 + memset(inodev_set.i_hash, 0,
35601 + sizeof (struct inodev_entry *) * inodev_set.i_size);
35602 +
35603 + return 0;
35604 +}
35605 +
35606 +/* free information not needed after startup
35607 + currently contains user->kernel pointer mappings for subjects
35608 +*/
35609 +
35610 +static void
35611 +free_init_variables(void)
35612 +{
35613 + __u32 i;
35614 +
35615 + if (subj_map_set.s_hash) {
35616 + for (i = 0; i < subj_map_set.s_size; i++) {
35617 + if (subj_map_set.s_hash[i]) {
35618 + kfree(subj_map_set.s_hash[i]);
35619 + subj_map_set.s_hash[i] = NULL;
35620 + }
35621 + }
35622 +
35623 + if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
35624 + PAGE_SIZE)
35625 + kfree(subj_map_set.s_hash);
35626 + else
35627 + vfree(subj_map_set.s_hash);
35628 + }
35629 +
35630 + return;
35631 +}
35632 +
35633 +static void
35634 +free_variables(void)
35635 +{
35636 + struct acl_subject_label *s;
35637 + struct acl_role_label *r;
35638 + struct task_struct *task, *task2;
35639 + unsigned int x;
35640 +
35641 + gr_clear_learn_entries();
35642 +
35643 + read_lock(&tasklist_lock);
35644 + do_each_thread(task2, task) {
35645 + task->acl_sp_role = 0;
35646 + task->acl_role_id = 0;
35647 + task->acl = NULL;
35648 + task->role = NULL;
35649 + } while_each_thread(task2, task);
35650 + read_unlock(&tasklist_lock);
35651 +
35652 + /* release the reference to the real root dentry and vfsmount */
35653 + path_put(&real_root);
35654 +
35655 + /* free all object hash tables */
35656 +
35657 + FOR_EACH_ROLE_START(r)
35658 + if (r->subj_hash == NULL)
35659 + goto next_role;
35660 + FOR_EACH_SUBJECT_START(r, s, x)
35661 + if (s->obj_hash == NULL)
35662 + break;
35663 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
35664 + kfree(s->obj_hash);
35665 + else
35666 + vfree(s->obj_hash);
35667 + FOR_EACH_SUBJECT_END(s, x)
35668 + FOR_EACH_NESTED_SUBJECT_START(r, s)
35669 + if (s->obj_hash == NULL)
35670 + break;
35671 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
35672 + kfree(s->obj_hash);
35673 + else
35674 + vfree(s->obj_hash);
35675 + FOR_EACH_NESTED_SUBJECT_END(s)
35676 + if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
35677 + kfree(r->subj_hash);
35678 + else
35679 + vfree(r->subj_hash);
35680 + r->subj_hash = NULL;
35681 +next_role:
35682 + FOR_EACH_ROLE_END(r)
35683 +
35684 + acl_free_all();
35685 +
35686 + if (acl_role_set.r_hash) {
35687 + if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
35688 + PAGE_SIZE)
35689 + kfree(acl_role_set.r_hash);
35690 + else
35691 + vfree(acl_role_set.r_hash);
35692 + }
35693 + if (name_set.n_hash) {
35694 + if ((name_set.n_size * sizeof (struct name_entry *)) <=
35695 + PAGE_SIZE)
35696 + kfree(name_set.n_hash);
35697 + else
35698 + vfree(name_set.n_hash);
35699 + }
35700 +
35701 + if (inodev_set.i_hash) {
35702 + if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
35703 + PAGE_SIZE)
35704 + kfree(inodev_set.i_hash);
35705 + else
35706 + vfree(inodev_set.i_hash);
35707 + }
35708 +
35709 + gr_free_uidset();
35710 +
35711 + memset(&name_set, 0, sizeof (struct name_db));
35712 + memset(&inodev_set, 0, sizeof (struct inodev_db));
35713 + memset(&acl_role_set, 0, sizeof (struct acl_role_db));
35714 + memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
35715 +
35716 + default_role = NULL;
35717 + role_list = NULL;
35718 +
35719 + return;
35720 +}
35721 +
35722 +static __u32
35723 +count_user_objs(struct acl_object_label *userp)
35724 +{
35725 + struct acl_object_label o_tmp;
35726 + __u32 num = 0;
35727 +
35728 + while (userp) {
35729 + if (copy_from_user(&o_tmp, userp,
35730 + sizeof (struct acl_object_label)))
35731 + break;
35732 +
35733 + userp = o_tmp.prev;
35734 + num++;
35735 + }
35736 +
35737 + return num;
35738 +}
35739 +
35740 +static struct acl_subject_label *
35741 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role);
35742 +
35743 +static int
35744 +copy_user_glob(struct acl_object_label *obj)
35745 +{
35746 + struct acl_object_label *g_tmp, **guser;
35747 + unsigned int len;
35748 + char *tmp;
35749 +
35750 + if (obj->globbed == NULL)
35751 + return 0;
35752 +
35753 + guser = &obj->globbed;
35754 + while (*guser) {
35755 + g_tmp = (struct acl_object_label *)
35756 + acl_alloc(sizeof (struct acl_object_label));
35757 + if (g_tmp == NULL)
35758 + return -ENOMEM;
35759 +
35760 + if (copy_from_user(g_tmp, *guser,
35761 + sizeof (struct acl_object_label)))
35762 + return -EFAULT;
35763 +
35764 + len = strnlen_user(g_tmp->filename, PATH_MAX);
35765 +
35766 + if (!len || len >= PATH_MAX)
35767 + return -EINVAL;
35768 +
35769 + if ((tmp = (char *) acl_alloc(len)) == NULL)
35770 + return -ENOMEM;
35771 +
35772 + if (copy_from_user(tmp, g_tmp->filename, len))
35773 + return -EFAULT;
35774 + tmp[len-1] = '\0';
35775 + g_tmp->filename = tmp;
35776 +
35777 + *guser = g_tmp;
35778 + guser = &(g_tmp->next);
35779 + }
35780 +
35781 + return 0;
35782 +}
35783 +
35784 +static int
35785 +copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
35786 + struct acl_role_label *role)
35787 +{
35788 + struct acl_object_label *o_tmp;
35789 + unsigned int len;
35790 + int ret;
35791 + char *tmp;
35792 +
35793 + while (userp) {
35794 + if ((o_tmp = (struct acl_object_label *)
35795 + acl_alloc(sizeof (struct acl_object_label))) == NULL)
35796 + return -ENOMEM;
35797 +
35798 + if (copy_from_user(o_tmp, userp,
35799 + sizeof (struct acl_object_label)))
35800 + return -EFAULT;
35801 +
35802 + userp = o_tmp->prev;
35803 +
35804 + len = strnlen_user(o_tmp->filename, PATH_MAX);
35805 +
35806 + if (!len || len >= PATH_MAX)
35807 + return -EINVAL;
35808 +
35809 + if ((tmp = (char *) acl_alloc(len)) == NULL)
35810 + return -ENOMEM;
35811 +
35812 + if (copy_from_user(tmp, o_tmp->filename, len))
35813 + return -EFAULT;
35814 + tmp[len-1] = '\0';
35815 + o_tmp->filename = tmp;
35816 +
35817 + insert_acl_obj_label(o_tmp, subj);
35818 + if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
35819 + o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
35820 + return -ENOMEM;
35821 +
35822 + ret = copy_user_glob(o_tmp);
35823 + if (ret)
35824 + return ret;
35825 +
35826 + if (o_tmp->nested) {
35827 + o_tmp->nested = do_copy_user_subj(o_tmp->nested, role);
35828 + if (IS_ERR(o_tmp->nested))
35829 + return PTR_ERR(o_tmp->nested);
35830 +
35831 + /* insert into nested subject list */
35832 + o_tmp->nested->next = role->hash->first;
35833 + role->hash->first = o_tmp->nested;
35834 + }
35835 + }
35836 +
35837 + return 0;
35838 +}
35839 +
35840 +static __u32
35841 +count_user_subjs(struct acl_subject_label *userp)
35842 +{
35843 + struct acl_subject_label s_tmp;
35844 + __u32 num = 0;
35845 +
35846 + while (userp) {
35847 + if (copy_from_user(&s_tmp, userp,
35848 + sizeof (struct acl_subject_label)))
35849 + break;
35850 +
35851 + userp = s_tmp.prev;
35852 + /* do not count nested subjects against this count, since
35853 + they are not included in the hash table, but are
35854 + attached to objects. We have already counted
35855 + the subjects in userspace for the allocation
35856 + stack
35857 + */
35858 + if (!(s_tmp.mode & GR_NESTED))
35859 + num++;
35860 + }
35861 +
35862 + return num;
35863 +}
35864 +
35865 +static int
35866 +copy_user_allowedips(struct acl_role_label *rolep)
35867 +{
35868 + struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
35869 +
35870 + ruserip = rolep->allowed_ips;
35871 +
35872 + while (ruserip) {
35873 + rlast = rtmp;
35874 +
35875 + if ((rtmp = (struct role_allowed_ip *)
35876 + acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
35877 + return -ENOMEM;
35878 +
35879 + if (copy_from_user(rtmp, ruserip,
35880 + sizeof (struct role_allowed_ip)))
35881 + return -EFAULT;
35882 +
35883 + ruserip = rtmp->prev;
35884 +
35885 + if (!rlast) {
35886 + rtmp->prev = NULL;
35887 + rolep->allowed_ips = rtmp;
35888 + } else {
35889 + rlast->next = rtmp;
35890 + rtmp->prev = rlast;
35891 + }
35892 +
35893 + if (!ruserip)
35894 + rtmp->next = NULL;
35895 + }
35896 +
35897 + return 0;
35898 +}
35899 +
35900 +static int
35901 +copy_user_transitions(struct acl_role_label *rolep)
35902 +{
35903 + struct role_transition *rusertp, *rtmp = NULL, *rlast;
35904 +
35905 + unsigned int len;
35906 + char *tmp;
35907 +
35908 + rusertp = rolep->transitions;
35909 +
35910 + while (rusertp) {
35911 + rlast = rtmp;
35912 +
35913 + if ((rtmp = (struct role_transition *)
35914 + acl_alloc(sizeof (struct role_transition))) == NULL)
35915 + return -ENOMEM;
35916 +
35917 + if (copy_from_user(rtmp, rusertp,
35918 + sizeof (struct role_transition)))
35919 + return -EFAULT;
35920 +
35921 + rusertp = rtmp->prev;
35922 +
35923 + len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
35924 +
35925 + if (!len || len >= GR_SPROLE_LEN)
35926 + return -EINVAL;
35927 +
35928 + if ((tmp = (char *) acl_alloc(len)) == NULL)
35929 + return -ENOMEM;
35930 +
35931 + if (copy_from_user(tmp, rtmp->rolename, len))
35932 + return -EFAULT;
35933 + tmp[len-1] = '\0';
35934 + rtmp->rolename = tmp;
35935 +
35936 + if (!rlast) {
35937 + rtmp->prev = NULL;
35938 + rolep->transitions = rtmp;
35939 + } else {
35940 + rlast->next = rtmp;
35941 + rtmp->prev = rlast;
35942 + }
35943 +
35944 + if (!rusertp)
35945 + rtmp->next = NULL;
35946 + }
35947 +
35948 + return 0;
35949 +}
35950 +
35951 +static struct acl_subject_label *
35952 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role)
35953 +{
35954 + struct acl_subject_label *s_tmp = NULL, *s_tmp2;
35955 + unsigned int len;
35956 + char *tmp;
35957 + __u32 num_objs;
35958 + struct acl_ip_label **i_tmp, *i_utmp2;
35959 + struct gr_hash_struct ghash;
35960 + struct subject_map *subjmap;
35961 + unsigned int i_num;
35962 + int err;
35963 +
35964 + s_tmp = lookup_subject_map(userp);
35965 +
35966 + /* we've already copied this subject into the kernel, just return
35967 + the reference to it, and don't copy it over again
35968 + */
35969 + if (s_tmp)
35970 + return(s_tmp);
35971 +
35972 + if ((s_tmp = (struct acl_subject_label *)
35973 + acl_alloc(sizeof (struct acl_subject_label))) == NULL)
35974 + return ERR_PTR(-ENOMEM);
35975 +
35976 + subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
35977 + if (subjmap == NULL)
35978 + return ERR_PTR(-ENOMEM);
35979 +
35980 + subjmap->user = userp;
35981 + subjmap->kernel = s_tmp;
35982 + insert_subj_map_entry(subjmap);
35983 +
35984 + if (copy_from_user(s_tmp, userp,
35985 + sizeof (struct acl_subject_label)))
35986 + return ERR_PTR(-EFAULT);
35987 +
35988 + len = strnlen_user(s_tmp->filename, PATH_MAX);
35989 +
35990 + if (!len || len >= PATH_MAX)
35991 + return ERR_PTR(-EINVAL);
35992 +
35993 + if ((tmp = (char *) acl_alloc(len)) == NULL)
35994 + return ERR_PTR(-ENOMEM);
35995 +
35996 + if (copy_from_user(tmp, s_tmp->filename, len))
35997 + return ERR_PTR(-EFAULT);
35998 + tmp[len-1] = '\0';
35999 + s_tmp->filename = tmp;
36000 +
36001 + if (!strcmp(s_tmp->filename, "/"))
36002 + role->root_label = s_tmp;
36003 +
36004 + if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
36005 + return ERR_PTR(-EFAULT);
36006 +
36007 + /* copy user and group transition tables */
36008 +
36009 + if (s_tmp->user_trans_num) {
36010 + uid_t *uidlist;
36011 +
36012 + uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
36013 + if (uidlist == NULL)
36014 + return ERR_PTR(-ENOMEM);
36015 + if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
36016 + return ERR_PTR(-EFAULT);
36017 +
36018 + s_tmp->user_transitions = uidlist;
36019 + }
36020 +
36021 + if (s_tmp->group_trans_num) {
36022 + gid_t *gidlist;
36023 +
36024 + gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
36025 + if (gidlist == NULL)
36026 + return ERR_PTR(-ENOMEM);
36027 + if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
36028 + return ERR_PTR(-EFAULT);
36029 +
36030 + s_tmp->group_transitions = gidlist;
36031 + }
36032 +
36033 + /* set up object hash table */
36034 + num_objs = count_user_objs(ghash.first);
36035 +
36036 + s_tmp->obj_hash_size = num_objs;
36037 + s_tmp->obj_hash =
36038 + (struct acl_object_label **)
36039 + create_table(&(s_tmp->obj_hash_size), sizeof(void *));
36040 +
36041 + if (!s_tmp->obj_hash)
36042 + return ERR_PTR(-ENOMEM);
36043 +
36044 + memset(s_tmp->obj_hash, 0,
36045 + s_tmp->obj_hash_size *
36046 + sizeof (struct acl_object_label *));
36047 +
36048 + /* add in objects */
36049 + err = copy_user_objs(ghash.first, s_tmp, role);
36050 +
36051 + if (err)
36052 + return ERR_PTR(err);
36053 +
36054 + /* set pointer for parent subject */
36055 + if (s_tmp->parent_subject) {
36056 + s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role);
36057 +
36058 + if (IS_ERR(s_tmp2))
36059 + return s_tmp2;
36060 +
36061 + s_tmp->parent_subject = s_tmp2;
36062 + }
36063 +
36064 + /* add in ip acls */
36065 +
36066 + if (!s_tmp->ip_num) {
36067 + s_tmp->ips = NULL;
36068 + goto insert;
36069 + }
36070 +
36071 + i_tmp =
36072 + (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
36073 + sizeof (struct acl_ip_label *));
36074 +
36075 + if (!i_tmp)
36076 + return ERR_PTR(-ENOMEM);
36077 +
36078 + for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
36079 + *(i_tmp + i_num) =
36080 + (struct acl_ip_label *)
36081 + acl_alloc(sizeof (struct acl_ip_label));
36082 + if (!*(i_tmp + i_num))
36083 + return ERR_PTR(-ENOMEM);
36084 +
36085 + if (copy_from_user
36086 + (&i_utmp2, s_tmp->ips + i_num,
36087 + sizeof (struct acl_ip_label *)))
36088 + return ERR_PTR(-EFAULT);
36089 +
36090 + if (copy_from_user
36091 + (*(i_tmp + i_num), i_utmp2,
36092 + sizeof (struct acl_ip_label)))
36093 + return ERR_PTR(-EFAULT);
36094 +
36095 + if ((*(i_tmp + i_num))->iface == NULL)
36096 + continue;
36097 +
36098 + len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
36099 + if (!len || len >= IFNAMSIZ)
36100 + return ERR_PTR(-EINVAL);
36101 + tmp = acl_alloc(len);
36102 + if (tmp == NULL)
36103 + return ERR_PTR(-ENOMEM);
36104 + if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
36105 + return ERR_PTR(-EFAULT);
36106 + (*(i_tmp + i_num))->iface = tmp;
36107 + }
36108 +
36109 + s_tmp->ips = i_tmp;
36110 +
36111 +insert:
36112 + if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
36113 + s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
36114 + return ERR_PTR(-ENOMEM);
36115 +
36116 + return s_tmp;
36117 +}
36118 +
36119 +static int
36120 +copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
36121 +{
36122 + struct acl_subject_label s_pre;
36123 + struct acl_subject_label * ret;
36124 + int err;
36125 +
36126 + while (userp) {
36127 + if (copy_from_user(&s_pre, userp,
36128 + sizeof (struct acl_subject_label)))
36129 + return -EFAULT;
36130 +
36131 + /* do not add nested subjects here, add
36132 + while parsing objects
36133 + */
36134 +
36135 + if (s_pre.mode & GR_NESTED) {
36136 + userp = s_pre.prev;
36137 + continue;
36138 + }
36139 +
36140 + ret = do_copy_user_subj(userp, role);
36141 +
36142 + err = PTR_ERR(ret);
36143 + if (IS_ERR(ret))
36144 + return err;
36145 +
36146 + insert_acl_subj_label(ret, role);
36147 +
36148 + userp = s_pre.prev;
36149 + }
36150 +
36151 + return 0;
36152 +}
36153 +
36154 +static int
36155 +copy_user_acl(struct gr_arg *arg)
36156 +{
36157 + struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
36158 + struct sprole_pw *sptmp;
36159 + struct gr_hash_struct *ghash;
36160 + uid_t *domainlist;
36161 + unsigned int r_num;
36162 + unsigned int len;
36163 + char *tmp;
36164 + int err = 0;
36165 + __u16 i;
36166 + __u32 num_subjs;
36167 +
36168 + /* we need a default and kernel role */
36169 + if (arg->role_db.num_roles < 2)
36170 + return -EINVAL;
36171 +
36172 + /* copy special role authentication info from userspace */
36173 +
36174 + num_sprole_pws = arg->num_sprole_pws;
36175 + acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
36176 +
36177 + if (!acl_special_roles) {
36178 + err = -ENOMEM;
36179 + goto cleanup;
36180 + }
36181 +
36182 + for (i = 0; i < num_sprole_pws; i++) {
36183 + sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
36184 + if (!sptmp) {
36185 + err = -ENOMEM;
36186 + goto cleanup;
36187 + }
36188 + if (copy_from_user(sptmp, arg->sprole_pws + i,
36189 + sizeof (struct sprole_pw))) {
36190 + err = -EFAULT;
36191 + goto cleanup;
36192 + }
36193 +
36194 + len =
36195 + strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
36196 +
36197 + if (!len || len >= GR_SPROLE_LEN) {
36198 + err = -EINVAL;
36199 + goto cleanup;
36200 + }
36201 +
36202 + if ((tmp = (char *) acl_alloc(len)) == NULL) {
36203 + err = -ENOMEM;
36204 + goto cleanup;
36205 + }
36206 +
36207 + if (copy_from_user(tmp, sptmp->rolename, len)) {
36208 + err = -EFAULT;
36209 + goto cleanup;
36210 + }
36211 + tmp[len-1] = '\0';
36212 +#ifdef CONFIG_GRKERNSEC_ACL_DEBUG
36213 + printk(KERN_ALERT "Copying special role %s\n", tmp);
36214 +#endif
36215 + sptmp->rolename = tmp;
36216 + acl_special_roles[i] = sptmp;
36217 + }
36218 +
36219 + r_utmp = (struct acl_role_label **) arg->role_db.r_table;
36220 +
36221 + for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
36222 + r_tmp = acl_alloc(sizeof (struct acl_role_label));
36223 +
36224 + if (!r_tmp) {
36225 + err = -ENOMEM;
36226 + goto cleanup;
36227 + }
36228 +
36229 + if (copy_from_user(&r_utmp2, r_utmp + r_num,
36230 + sizeof (struct acl_role_label *))) {
36231 + err = -EFAULT;
36232 + goto cleanup;
36233 + }
36234 +
36235 + if (copy_from_user(r_tmp, r_utmp2,
36236 + sizeof (struct acl_role_label))) {
36237 + err = -EFAULT;
36238 + goto cleanup;
36239 + }
36240 +
36241 + len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
36242 +
36243 + if (!len || len >= PATH_MAX) {
36244 + err = -EINVAL;
36245 + goto cleanup;
36246 + }
36247 +
36248 + if ((tmp = (char *) acl_alloc(len)) == NULL) {
36249 + err = -ENOMEM;
36250 + goto cleanup;
36251 + }
36252 + if (copy_from_user(tmp, r_tmp->rolename, len)) {
36253 + err = -EFAULT;
36254 + goto cleanup;
36255 + }
36256 + tmp[len-1] = '\0';
36257 + r_tmp->rolename = tmp;
36258 +
36259 + if (!strcmp(r_tmp->rolename, "default")
36260 + && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
36261 + default_role = r_tmp;
36262 + } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
36263 + kernel_role = r_tmp;
36264 + }
36265 +
36266 + if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL) {
36267 + err = -ENOMEM;
36268 + goto cleanup;
36269 + }
36270 + if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct))) {
36271 + err = -EFAULT;
36272 + goto cleanup;
36273 + }
36274 +
36275 + r_tmp->hash = ghash;
36276 +
36277 + num_subjs = count_user_subjs(r_tmp->hash->first);
36278 +
36279 + r_tmp->subj_hash_size = num_subjs;
36280 + r_tmp->subj_hash =
36281 + (struct acl_subject_label **)
36282 + create_table(&(r_tmp->subj_hash_size), sizeof(void *));
36283 +
36284 + if (!r_tmp->subj_hash) {
36285 + err = -ENOMEM;
36286 + goto cleanup;
36287 + }
36288 +
36289 + err = copy_user_allowedips(r_tmp);
36290 + if (err)
36291 + goto cleanup;
36292 +
36293 + /* copy domain info */
36294 + if (r_tmp->domain_children != NULL) {
36295 + domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
36296 + if (domainlist == NULL) {
36297 + err = -ENOMEM;
36298 + goto cleanup;
36299 + }
36300 + if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t))) {
36301 + err = -EFAULT;
36302 + goto cleanup;
36303 + }
36304 + r_tmp->domain_children = domainlist;
36305 + }
36306 +
36307 + err = copy_user_transitions(r_tmp);
36308 + if (err)
36309 + goto cleanup;
36310 +
36311 + memset(r_tmp->subj_hash, 0,
36312 + r_tmp->subj_hash_size *
36313 + sizeof (struct acl_subject_label *));
36314 +
36315 + err = copy_user_subjs(r_tmp->hash->first, r_tmp);
36316 +
36317 + if (err)
36318 + goto cleanup;
36319 +
36320 + /* set nested subject list to null */
36321 + r_tmp->hash->first = NULL;
36322 +
36323 + insert_acl_role_label(r_tmp);
36324 + }
36325 +
36326 + goto return_err;
36327 + cleanup:
36328 + free_variables();
36329 + return_err:
36330 + return err;
36331 +
36332 +}
36333 +
36334 +static int
36335 +gracl_init(struct gr_arg *args)
36336 +{
36337 + int error = 0;
36338 +
36339 + memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
36340 + memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
36341 +
36342 + if (init_variables(args)) {
36343 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
36344 + error = -ENOMEM;
36345 + free_variables();
36346 + goto out;
36347 + }
36348 +
36349 + error = copy_user_acl(args);
36350 + free_init_variables();
36351 + if (error) {
36352 + free_variables();
36353 + goto out;
36354 + }
36355 +
36356 + if ((error = gr_set_acls(0))) {
36357 + free_variables();
36358 + goto out;
36359 + }
36360 +
36361 + pax_open_kernel();
36362 + gr_status |= GR_READY;
36363 + pax_close_kernel();
36364 +
36365 + out:
36366 + return error;
36367 +}
36368 +
36369 +/* derived from glibc fnmatch() 0: match, 1: no match*/
36370 +
36371 +static int
36372 +glob_match(const char *p, const char *n)
36373 +{
36374 + char c;
36375 +
36376 + while ((c = *p++) != '\0') {
36377 + switch (c) {
36378 + case '?':
36379 + if (*n == '\0')
36380 + return 1;
36381 + else if (*n == '/')
36382 + return 1;
36383 + break;
36384 + case '\\':
36385 + if (*n != c)
36386 + return 1;
36387 + break;
36388 + case '*':
36389 + for (c = *p++; c == '?' || c == '*'; c = *p++) {
36390 + if (*n == '/')
36391 + return 1;
36392 + else if (c == '?') {
36393 + if (*n == '\0')
36394 + return 1;
36395 + else
36396 + ++n;
36397 + }
36398 + }
36399 + if (c == '\0') {
36400 + return 0;
36401 + } else {
36402 + const char *endp;
36403 +
36404 + if ((endp = strchr(n, '/')) == NULL)
36405 + endp = n + strlen(n);
36406 +
36407 + if (c == '[') {
36408 + for (--p; n < endp; ++n)
36409 + if (!glob_match(p, n))
36410 + return 0;
36411 + } else if (c == '/') {
36412 + while (*n != '\0' && *n != '/')
36413 + ++n;
36414 + if (*n == '/' && !glob_match(p, n + 1))
36415 + return 0;
36416 + } else {
36417 + for (--p; n < endp; ++n)
36418 + if (*n == c && !glob_match(p, n))
36419 + return 0;
36420 + }
36421 +
36422 + return 1;
36423 + }
36424 + case '[':
36425 + {
36426 + int not;
36427 + char cold;
36428 +
36429 + if (*n == '\0' || *n == '/')
36430 + return 1;
36431 +
36432 + not = (*p == '!' || *p == '^');
36433 + if (not)
36434 + ++p;
36435 +
36436 + c = *p++;
36437 + for (;;) {
36438 + unsigned char fn = (unsigned char)*n;
36439 +
36440 + if (c == '\0')
36441 + return 1;
36442 + else {
36443 + if (c == fn)
36444 + goto matched;
36445 + cold = c;
36446 + c = *p++;
36447 +
36448 + if (c == '-' && *p != ']') {
36449 + unsigned char cend = *p++;
36450 +
36451 + if (cend == '\0')
36452 + return 1;
36453 +
36454 + if (cold <= fn && fn <= cend)
36455 + goto matched;
36456 +
36457 + c = *p++;
36458 + }
36459 + }
36460 +
36461 + if (c == ']')
36462 + break;
36463 + }
36464 + if (!not)
36465 + return 1;
36466 + break;
36467 + matched:
36468 + while (c != ']') {
36469 + if (c == '\0')
36470 + return 1;
36471 +
36472 + c = *p++;
36473 + }
36474 + if (not)
36475 + return 1;
36476 + }
36477 + break;
36478 + default:
36479 + if (c != *n)
36480 + return 1;
36481 + }
36482 +
36483 + ++n;
36484 + }
36485 +
36486 + if (*n == '\0')
36487 + return 0;
36488 +
36489 + if (*n == '/')
36490 + return 0;
36491 +
36492 + return 1;
36493 +}
36494 +
36495 +static struct acl_object_label *
36496 +chk_glob_label(struct acl_object_label *globbed,
36497 + struct dentry *dentry, struct vfsmount *mnt, char **path)
36498 +{
36499 + struct acl_object_label *tmp;
36500 +
36501 + if (*path == NULL)
36502 + *path = gr_to_filename_nolock(dentry, mnt);
36503 +
36504 + tmp = globbed;
36505 +
36506 + while (tmp) {
36507 + if (!glob_match(tmp->filename, *path))
36508 + return tmp;
36509 + tmp = tmp->next;
36510 + }
36511 +
36512 + return NULL;
36513 +}
36514 +
36515 +static struct acl_object_label *
36516 +__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
36517 + const ino_t curr_ino, const dev_t curr_dev,
36518 + const struct acl_subject_label *subj, char **path, const int checkglob)
36519 +{
36520 + struct acl_subject_label *tmpsubj;
36521 + struct acl_object_label *retval;
36522 + struct acl_object_label *retval2;
36523 +
36524 + tmpsubj = (struct acl_subject_label *) subj;
36525 + read_lock(&gr_inode_lock);
36526 + do {
36527 + retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
36528 + if (retval) {
36529 + if (checkglob && retval->globbed) {
36530 + retval2 = chk_glob_label(retval->globbed, (struct dentry *)orig_dentry,
36531 + (struct vfsmount *)orig_mnt, path);
36532 + if (retval2)
36533 + retval = retval2;
36534 + }
36535 + break;
36536 + }
36537 + } while ((tmpsubj = tmpsubj->parent_subject));
36538 + read_unlock(&gr_inode_lock);
36539 +
36540 + return retval;
36541 +}
36542 +
36543 +static __inline__ struct acl_object_label *
36544 +full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
36545 + const struct dentry *curr_dentry,
36546 + const struct acl_subject_label *subj, char **path, const int checkglob)
36547 +{
36548 + int newglob = checkglob;
36549 +
36550 + /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
36551 + as we don't want a / * rule to match instead of the / object
36552 + don't do this for create lookups that call this function though, since they're looking up
36553 + on the parent and thus need globbing checks on all paths
36554 + */
36555 + if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
36556 + newglob = GR_NO_GLOB;
36557 +
36558 + return __full_lookup(orig_dentry, orig_mnt,
36559 + curr_dentry->d_inode->i_ino,
36560 + curr_dentry->d_inode->i_sb->s_dev, subj, path, newglob);
36561 +}
36562 +
36563 +static struct acl_object_label *
36564 +__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
36565 + const struct acl_subject_label *subj, char *path, const int checkglob)
36566 +{
36567 + struct dentry *dentry = (struct dentry *) l_dentry;
36568 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
36569 + struct acl_object_label *retval;
36570 +
36571 + spin_lock(&dcache_lock);
36572 + br_read_lock(vfsmount_lock);
36573 +
36574 + if (unlikely(mnt == shm_mnt || mnt == pipe_mnt || mnt == sock_mnt ||
36575 +#ifdef CONFIG_HUGETLBFS
36576 + mnt == hugetlbfs_vfsmount ||
36577 +#endif
36578 + /* ignore Eric Biederman */
36579 + IS_PRIVATE(l_dentry->d_inode))) {
36580 + retval = fakefs_obj;
36581 + goto out;
36582 + }
36583 +
36584 + for (;;) {
36585 + if (dentry == real_root.dentry && mnt == real_root.mnt)
36586 + break;
36587 +
36588 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
36589 + if (mnt->mnt_parent == mnt)
36590 + break;
36591 +
36592 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
36593 + if (retval != NULL)
36594 + goto out;
36595 +
36596 + dentry = mnt->mnt_mountpoint;
36597 + mnt = mnt->mnt_parent;
36598 + continue;
36599 + }
36600 +
36601 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
36602 + if (retval != NULL)
36603 + goto out;
36604 +
36605 + dentry = dentry->d_parent;
36606 + }
36607 +
36608 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
36609 +
36610 + if (retval == NULL)
36611 + retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
36612 +out:
36613 + br_read_unlock(vfsmount_lock);
36614 + spin_unlock(&dcache_lock);
36615 +
36616 + BUG_ON(retval == NULL);
36617 +
36618 + return retval;
36619 +}
36620 +
36621 +static __inline__ struct acl_object_label *
36622 +chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
36623 + const struct acl_subject_label *subj)
36624 +{
36625 + char *path = NULL;
36626 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
36627 +}
36628 +
36629 +static __inline__ struct acl_object_label *
36630 +chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
36631 + const struct acl_subject_label *subj)
36632 +{
36633 + char *path = NULL;
36634 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
36635 +}
36636 +
36637 +static __inline__ struct acl_object_label *
36638 +chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
36639 + const struct acl_subject_label *subj, char *path)
36640 +{
36641 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
36642 +}
36643 +
36644 +static struct acl_subject_label *
36645 +chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
36646 + const struct acl_role_label *role)
36647 +{
36648 + struct dentry *dentry = (struct dentry *) l_dentry;
36649 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
36650 + struct acl_subject_label *retval;
36651 +
36652 + spin_lock(&dcache_lock);
36653 + br_read_lock(vfsmount_lock);
36654 +
36655 + for (;;) {
36656 + if (dentry == real_root.dentry && mnt == real_root.mnt)
36657 + break;
36658 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
36659 + if (mnt->mnt_parent == mnt)
36660 + break;
36661 +
36662 + read_lock(&gr_inode_lock);
36663 + retval =
36664 + lookup_acl_subj_label(dentry->d_inode->i_ino,
36665 + dentry->d_inode->i_sb->s_dev, role);
36666 + read_unlock(&gr_inode_lock);
36667 + if (retval != NULL)
36668 + goto out;
36669 +
36670 + dentry = mnt->mnt_mountpoint;
36671 + mnt = mnt->mnt_parent;
36672 + continue;
36673 + }
36674 +
36675 + read_lock(&gr_inode_lock);
36676 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
36677 + dentry->d_inode->i_sb->s_dev, role);
36678 + read_unlock(&gr_inode_lock);
36679 + if (retval != NULL)
36680 + goto out;
36681 +
36682 + dentry = dentry->d_parent;
36683 + }
36684 +
36685 + read_lock(&gr_inode_lock);
36686 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
36687 + dentry->d_inode->i_sb->s_dev, role);
36688 + read_unlock(&gr_inode_lock);
36689 +
36690 + if (unlikely(retval == NULL)) {
36691 + read_lock(&gr_inode_lock);
36692 + retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
36693 + real_root.dentry->d_inode->i_sb->s_dev, role);
36694 + read_unlock(&gr_inode_lock);
36695 + }
36696 +out:
36697 + br_read_unlock(vfsmount_lock);
36698 + spin_unlock(&dcache_lock);
36699 +
36700 + BUG_ON(retval == NULL);
36701 +
36702 + return retval;
36703 +}
36704 +
36705 +static void
36706 +gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
36707 +{
36708 + struct task_struct *task = current;
36709 + const struct cred *cred = current_cred();
36710 +
36711 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
36712 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
36713 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
36714 + 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
36715 +
36716 + return;
36717 +}
36718 +
36719 +static void
36720 +gr_log_learn_sysctl(const char *path, const __u32 mode)
36721 +{
36722 + struct task_struct *task = current;
36723 + const struct cred *cred = current_cred();
36724 +
36725 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
36726 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
36727 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
36728 + 1UL, 1UL, path, (unsigned long) mode, &task->signal->saved_ip);
36729 +
36730 + return;
36731 +}
36732 +
36733 +static void
36734 +gr_log_learn_id_change(const char type, const unsigned int real,
36735 + const unsigned int effective, const unsigned int fs)
36736 +{
36737 + struct task_struct *task = current;
36738 + const struct cred *cred = current_cred();
36739 +
36740 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
36741 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
36742 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
36743 + type, real, effective, fs, &task->signal->saved_ip);
36744 +
36745 + return;
36746 +}
36747 +
36748 +__u32
36749 +gr_check_link(const struct dentry * new_dentry,
36750 + const struct dentry * parent_dentry,
36751 + const struct vfsmount * parent_mnt,
36752 + const struct dentry * old_dentry, const struct vfsmount * old_mnt)
36753 +{
36754 + struct acl_object_label *obj;
36755 + __u32 oldmode, newmode;
36756 + __u32 needmode;
36757 +
36758 + if (unlikely(!(gr_status & GR_READY)))
36759 + return (GR_CREATE | GR_LINK);
36760 +
36761 + obj = chk_obj_label(old_dentry, old_mnt, current->acl);
36762 + oldmode = obj->mode;
36763 +
36764 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
36765 + oldmode |= (GR_CREATE | GR_LINK);
36766 +
36767 + needmode = GR_CREATE | GR_AUDIT_CREATE | GR_SUPPRESS;
36768 + if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID))
36769 + needmode |= GR_SETID | GR_AUDIT_SETID;
36770 +
36771 + newmode =
36772 + gr_check_create(new_dentry, parent_dentry, parent_mnt,
36773 + oldmode | needmode);
36774 +
36775 + needmode = newmode & (GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC |
36776 + GR_SETID | GR_READ | GR_FIND | GR_DELETE |
36777 + GR_INHERIT | GR_AUDIT_INHERIT);
36778 +
36779 + if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID) && !(newmode & GR_SETID))
36780 + goto bad;
36781 +
36782 + if ((oldmode & needmode) != needmode)
36783 + goto bad;
36784 +
36785 + needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
36786 + if ((newmode & needmode) != needmode)
36787 + goto bad;
36788 +
36789 + if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
36790 + return newmode;
36791 +bad:
36792 + needmode = oldmode;
36793 + if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID))
36794 + needmode |= GR_SETID;
36795 +
36796 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
36797 + gr_log_learn(old_dentry, old_mnt, needmode);
36798 + return (GR_CREATE | GR_LINK);
36799 + } else if (newmode & GR_SUPPRESS)
36800 + return GR_SUPPRESS;
36801 + else
36802 + return 0;
36803 +}
36804 +
36805 +__u32
36806 +gr_search_file(const struct dentry * dentry, const __u32 mode,
36807 + const struct vfsmount * mnt)
36808 +{
36809 + __u32 retval = mode;
36810 + struct acl_subject_label *curracl;
36811 + struct acl_object_label *currobj;
36812 +
36813 + if (unlikely(!(gr_status & GR_READY)))
36814 + return (mode & ~GR_AUDITS);
36815 +
36816 + curracl = current->acl;
36817 +
36818 + currobj = chk_obj_label(dentry, mnt, curracl);
36819 + retval = currobj->mode & mode;
36820 +
36821 + if (unlikely
36822 + ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
36823 + && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
36824 + __u32 new_mode = mode;
36825 +
36826 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
36827 +
36828 + retval = new_mode;
36829 +
36830 + if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
36831 + new_mode |= GR_INHERIT;
36832 +
36833 + if (!(mode & GR_NOLEARN))
36834 + gr_log_learn(dentry, mnt, new_mode);
36835 + }
36836 +
36837 + return retval;
36838 +}
36839 +
36840 +__u32
36841 +gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
36842 + const struct vfsmount * mnt, const __u32 mode)
36843 +{
36844 + struct name_entry *match;
36845 + struct acl_object_label *matchpo;
36846 + struct acl_subject_label *curracl;
36847 + char *path;
36848 + __u32 retval;
36849 +
36850 + if (unlikely(!(gr_status & GR_READY)))
36851 + return (mode & ~GR_AUDITS);
36852 +
36853 + preempt_disable();
36854 + path = gr_to_filename_rbac(new_dentry, mnt);
36855 + match = lookup_name_entry_create(path);
36856 +
36857 + if (!match)
36858 + goto check_parent;
36859 +
36860 + curracl = current->acl;
36861 +
36862 + read_lock(&gr_inode_lock);
36863 + matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
36864 + read_unlock(&gr_inode_lock);
36865 +
36866 + if (matchpo) {
36867 + if ((matchpo->mode & mode) !=
36868 + (mode & ~(GR_AUDITS | GR_SUPPRESS))
36869 + && curracl->mode & (GR_LEARN | GR_INHERITLEARN)) {
36870 + __u32 new_mode = mode;
36871 +
36872 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
36873 +
36874 + gr_log_learn(new_dentry, mnt, new_mode);
36875 +
36876 + preempt_enable();
36877 + return new_mode;
36878 + }
36879 + preempt_enable();
36880 + return (matchpo->mode & mode);
36881 + }
36882 +
36883 + check_parent:
36884 + curracl = current->acl;
36885 +
36886 + matchpo = chk_obj_create_label(parent, mnt, curracl, path);
36887 + retval = matchpo->mode & mode;
36888 +
36889 + if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
36890 + && (curracl->mode & (GR_LEARN | GR_INHERITLEARN))) {
36891 + __u32 new_mode = mode;
36892 +
36893 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
36894 +
36895 + gr_log_learn(new_dentry, mnt, new_mode);
36896 + preempt_enable();
36897 + return new_mode;
36898 + }
36899 +
36900 + preempt_enable();
36901 + return retval;
36902 +}
36903 +
36904 +int
36905 +gr_check_hidden_task(const struct task_struct *task)
36906 +{
36907 + if (unlikely(!(gr_status & GR_READY)))
36908 + return 0;
36909 +
36910 + if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
36911 + return 1;
36912 +
36913 + return 0;
36914 +}
36915 +
36916 +int
36917 +gr_check_protected_task(const struct task_struct *task)
36918 +{
36919 + if (unlikely(!(gr_status & GR_READY) || !task))
36920 + return 0;
36921 +
36922 + if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
36923 + task->acl != current->acl)
36924 + return 1;
36925 +
36926 + return 0;
36927 +}
36928 +
36929 +int
36930 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
36931 +{
36932 + struct task_struct *p;
36933 + int ret = 0;
36934 +
36935 + if (unlikely(!(gr_status & GR_READY) || !pid))
36936 + return ret;
36937 +
36938 + read_lock(&tasklist_lock);
36939 + do_each_pid_task(pid, type, p) {
36940 + if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
36941 + p->acl != current->acl) {
36942 + ret = 1;
36943 + goto out;
36944 + }
36945 + } while_each_pid_task(pid, type, p);
36946 +out:
36947 + read_unlock(&tasklist_lock);
36948 +
36949 + return ret;
36950 +}
36951 +
36952 +void
36953 +gr_copy_label(struct task_struct *tsk)
36954 +{
36955 + tsk->signal->used_accept = 0;
36956 + tsk->acl_sp_role = 0;
36957 + tsk->acl_role_id = current->acl_role_id;
36958 + tsk->acl = current->acl;
36959 + tsk->role = current->role;
36960 + tsk->signal->curr_ip = current->signal->curr_ip;
36961 + tsk->signal->saved_ip = current->signal->saved_ip;
36962 + if (current->exec_file)
36963 + get_file(current->exec_file);
36964 + tsk->exec_file = current->exec_file;
36965 + tsk->is_writable = current->is_writable;
36966 + if (unlikely(current->signal->used_accept)) {
36967 + current->signal->curr_ip = 0;
36968 + current->signal->saved_ip = 0;
36969 + }
36970 +
36971 + return;
36972 +}
36973 +
36974 +static void
36975 +gr_set_proc_res(struct task_struct *task)
36976 +{
36977 + struct acl_subject_label *proc;
36978 + unsigned short i;
36979 +
36980 + proc = task->acl;
36981 +
36982 + if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
36983 + return;
36984 +
36985 + for (i = 0; i < RLIM_NLIMITS; i++) {
36986 + if (!(proc->resmask & (1 << i)))
36987 + continue;
36988 +
36989 + task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
36990 + task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
36991 + }
36992 +
36993 + return;
36994 +}
36995 +
36996 +int
36997 +gr_check_user_change(int real, int effective, int fs)
36998 +{
36999 + unsigned int i;
37000 + __u16 num;
37001 + uid_t *uidlist;
37002 + int curuid;
37003 + int realok = 0;
37004 + int effectiveok = 0;
37005 + int fsok = 0;
37006 +
37007 + if (unlikely(!(gr_status & GR_READY)))
37008 + return 0;
37009 +
37010 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
37011 + gr_log_learn_id_change('u', real, effective, fs);
37012 +
37013 + num = current->acl->user_trans_num;
37014 + uidlist = current->acl->user_transitions;
37015 +
37016 + if (uidlist == NULL)
37017 + return 0;
37018 +
37019 + if (real == -1)
37020 + realok = 1;
37021 + if (effective == -1)
37022 + effectiveok = 1;
37023 + if (fs == -1)
37024 + fsok = 1;
37025 +
37026 + if (current->acl->user_trans_type & GR_ID_ALLOW) {
37027 + for (i = 0; i < num; i++) {
37028 + curuid = (int)uidlist[i];
37029 + if (real == curuid)
37030 + realok = 1;
37031 + if (effective == curuid)
37032 + effectiveok = 1;
37033 + if (fs == curuid)
37034 + fsok = 1;
37035 + }
37036 + } else if (current->acl->user_trans_type & GR_ID_DENY) {
37037 + for (i = 0; i < num; i++) {
37038 + curuid = (int)uidlist[i];
37039 + if (real == curuid)
37040 + break;
37041 + if (effective == curuid)
37042 + break;
37043 + if (fs == curuid)
37044 + break;
37045 + }
37046 + /* not in deny list */
37047 + if (i == num) {
37048 + realok = 1;
37049 + effectiveok = 1;
37050 + fsok = 1;
37051 + }
37052 + }
37053 +
37054 + if (realok && effectiveok && fsok)
37055 + return 0;
37056 + else {
37057 + gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
37058 + return 1;
37059 + }
37060 +}
37061 +
37062 +int
37063 +gr_check_group_change(int real, int effective, int fs)
37064 +{
37065 + unsigned int i;
37066 + __u16 num;
37067 + gid_t *gidlist;
37068 + int curgid;
37069 + int realok = 0;
37070 + int effectiveok = 0;
37071 + int fsok = 0;
37072 +
37073 + if (unlikely(!(gr_status & GR_READY)))
37074 + return 0;
37075 +
37076 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
37077 + gr_log_learn_id_change('g', real, effective, fs);
37078 +
37079 + num = current->acl->group_trans_num;
37080 + gidlist = current->acl->group_transitions;
37081 +
37082 + if (gidlist == NULL)
37083 + return 0;
37084 +
37085 + if (real == -1)
37086 + realok = 1;
37087 + if (effective == -1)
37088 + effectiveok = 1;
37089 + if (fs == -1)
37090 + fsok = 1;
37091 +
37092 + if (current->acl->group_trans_type & GR_ID_ALLOW) {
37093 + for (i = 0; i < num; i++) {
37094 + curgid = (int)gidlist[i];
37095 + if (real == curgid)
37096 + realok = 1;
37097 + if (effective == curgid)
37098 + effectiveok = 1;
37099 + if (fs == curgid)
37100 + fsok = 1;
37101 + }
37102 + } else if (current->acl->group_trans_type & GR_ID_DENY) {
37103 + for (i = 0; i < num; i++) {
37104 + curgid = (int)gidlist[i];
37105 + if (real == curgid)
37106 + break;
37107 + if (effective == curgid)
37108 + break;
37109 + if (fs == curgid)
37110 + break;
37111 + }
37112 + /* not in deny list */
37113 + if (i == num) {
37114 + realok = 1;
37115 + effectiveok = 1;
37116 + fsok = 1;
37117 + }
37118 + }
37119 +
37120 + if (realok && effectiveok && fsok)
37121 + return 0;
37122 + else {
37123 + gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
37124 + return 1;
37125 + }
37126 +}
37127 +
37128 +void
37129 +gr_set_role_label(struct task_struct *task, const uid_t uid, const uid_t gid)
37130 +{
37131 + struct acl_role_label *role = task->role;
37132 + struct acl_subject_label *subj = NULL;
37133 + struct acl_object_label *obj;
37134 + struct file *filp;
37135 +
37136 + if (unlikely(!(gr_status & GR_READY)))
37137 + return;
37138 +
37139 + filp = task->exec_file;
37140 +
37141 + /* kernel process, we'll give them the kernel role */
37142 + if (unlikely(!filp)) {
37143 + task->role = kernel_role;
37144 + task->acl = kernel_role->root_label;
37145 + return;
37146 + } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
37147 + role = lookup_acl_role_label(task, uid, gid);
37148 +
37149 + /* perform subject lookup in possibly new role
37150 + we can use this result below in the case where role == task->role
37151 + */
37152 + subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
37153 +
37154 + /* if we changed uid/gid, but result in the same role
37155 + and are using inheritance, don't lose the inherited subject
37156 + if current subject is other than what normal lookup
37157 + would result in, we arrived via inheritance, don't
37158 + lose subject
37159 + */
37160 + if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
37161 + (subj == task->acl)))
37162 + task->acl = subj;
37163 +
37164 + task->role = role;
37165 +
37166 + task->is_writable = 0;
37167 +
37168 + /* ignore additional mmap checks for processes that are writable
37169 + by the default ACL */
37170 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
37171 + if (unlikely(obj->mode & GR_WRITE))
37172 + task->is_writable = 1;
37173 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
37174 + if (unlikely(obj->mode & GR_WRITE))
37175 + task->is_writable = 1;
37176 +
37177 +#ifdef CONFIG_GRKERNSEC_ACL_DEBUG
37178 + printk(KERN_ALERT "Set role label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
37179 +#endif
37180 +
37181 + gr_set_proc_res(task);
37182 +
37183 + return;
37184 +}
37185 +
37186 +int
37187 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
37188 + const int unsafe_share)
37189 +{
37190 + struct task_struct *task = current;
37191 + struct acl_subject_label *newacl;
37192 + struct acl_object_label *obj;
37193 + __u32 retmode;
37194 +
37195 + if (unlikely(!(gr_status & GR_READY)))
37196 + return 0;
37197 +
37198 + newacl = chk_subj_label(dentry, mnt, task->role);
37199 +
37200 + task_lock(task);
37201 + if ((((task->ptrace & PT_PTRACED) || unsafe_share) &&
37202 + !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
37203 + !(task->role->roletype & GR_ROLE_GOD) &&
37204 + !gr_search_file(dentry, GR_PTRACERD, mnt) &&
37205 + !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN)))) {
37206 + task_unlock(task);
37207 + if (unsafe_share)
37208 + gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
37209 + else
37210 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
37211 + return -EACCES;
37212 + }
37213 + task_unlock(task);
37214 +
37215 + obj = chk_obj_label(dentry, mnt, task->acl);
37216 + retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
37217 +
37218 + if (!(task->acl->mode & GR_INHERITLEARN) &&
37219 + ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
37220 + if (obj->nested)
37221 + task->acl = obj->nested;
37222 + else
37223 + task->acl = newacl;
37224 + } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
37225 + gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
37226 +
37227 + task->is_writable = 0;
37228 +
37229 + /* ignore additional mmap checks for processes that are writable
37230 + by the default ACL */
37231 + obj = chk_obj_label(dentry, mnt, default_role->root_label);
37232 + if (unlikely(obj->mode & GR_WRITE))
37233 + task->is_writable = 1;
37234 + obj = chk_obj_label(dentry, mnt, task->role->root_label);
37235 + if (unlikely(obj->mode & GR_WRITE))
37236 + task->is_writable = 1;
37237 +
37238 + gr_set_proc_res(task);
37239 +
37240 +#ifdef CONFIG_GRKERNSEC_ACL_DEBUG
37241 + printk(KERN_ALERT "Set subject label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
37242 +#endif
37243 + return 0;
37244 +}
37245 +
37246 +/* always called with valid inodev ptr */
37247 +static void
37248 +do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
37249 +{
37250 + struct acl_object_label *matchpo;
37251 + struct acl_subject_label *matchps;
37252 + struct acl_subject_label *subj;
37253 + struct acl_role_label *role;
37254 + unsigned int x;
37255 +
37256 + FOR_EACH_ROLE_START(role)
37257 + FOR_EACH_SUBJECT_START(role, subj, x)
37258 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
37259 + matchpo->mode |= GR_DELETED;
37260 + FOR_EACH_SUBJECT_END(subj,x)
37261 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
37262 + if (subj->inode == ino && subj->device == dev)
37263 + subj->mode |= GR_DELETED;
37264 + FOR_EACH_NESTED_SUBJECT_END(subj)
37265 + if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
37266 + matchps->mode |= GR_DELETED;
37267 + FOR_EACH_ROLE_END(role)
37268 +
37269 + inodev->nentry->deleted = 1;
37270 +
37271 + return;
37272 +}
37273 +
37274 +void
37275 +gr_handle_delete(const ino_t ino, const dev_t dev)
37276 +{
37277 + struct inodev_entry *inodev;
37278 +
37279 + if (unlikely(!(gr_status & GR_READY)))
37280 + return;
37281 +
37282 + write_lock(&gr_inode_lock);
37283 + inodev = lookup_inodev_entry(ino, dev);
37284 + if (inodev != NULL)
37285 + do_handle_delete(inodev, ino, dev);
37286 + write_unlock(&gr_inode_lock);
37287 +
37288 + return;
37289 +}
37290 +
37291 +static void
37292 +update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
37293 + const ino_t newinode, const dev_t newdevice,
37294 + struct acl_subject_label *subj)
37295 +{
37296 + unsigned int index = fhash(oldinode, olddevice, subj->obj_hash_size);
37297 + struct acl_object_label *match;
37298 +
37299 + match = subj->obj_hash[index];
37300 +
37301 + while (match && (match->inode != oldinode ||
37302 + match->device != olddevice ||
37303 + !(match->mode & GR_DELETED)))
37304 + match = match->next;
37305 +
37306 + if (match && (match->inode == oldinode)
37307 + && (match->device == olddevice)
37308 + && (match->mode & GR_DELETED)) {
37309 + if (match->prev == NULL) {
37310 + subj->obj_hash[index] = match->next;
37311 + if (match->next != NULL)
37312 + match->next->prev = NULL;
37313 + } else {
37314 + match->prev->next = match->next;
37315 + if (match->next != NULL)
37316 + match->next->prev = match->prev;
37317 + }
37318 + match->prev = NULL;
37319 + match->next = NULL;
37320 + match->inode = newinode;
37321 + match->device = newdevice;
37322 + match->mode &= ~GR_DELETED;
37323 +
37324 + insert_acl_obj_label(match, subj);
37325 + }
37326 +
37327 + return;
37328 +}
37329 +
37330 +static void
37331 +update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
37332 + const ino_t newinode, const dev_t newdevice,
37333 + struct acl_role_label *role)
37334 +{
37335 + unsigned int index = fhash(oldinode, olddevice, role->subj_hash_size);
37336 + struct acl_subject_label *match;
37337 +
37338 + match = role->subj_hash[index];
37339 +
37340 + while (match && (match->inode != oldinode ||
37341 + match->device != olddevice ||
37342 + !(match->mode & GR_DELETED)))
37343 + match = match->next;
37344 +
37345 + if (match && (match->inode == oldinode)
37346 + && (match->device == olddevice)
37347 + && (match->mode & GR_DELETED)) {
37348 + if (match->prev == NULL) {
37349 + role->subj_hash[index] = match->next;
37350 + if (match->next != NULL)
37351 + match->next->prev = NULL;
37352 + } else {
37353 + match->prev->next = match->next;
37354 + if (match->next != NULL)
37355 + match->next->prev = match->prev;
37356 + }
37357 + match->prev = NULL;
37358 + match->next = NULL;
37359 + match->inode = newinode;
37360 + match->device = newdevice;
37361 + match->mode &= ~GR_DELETED;
37362 +
37363 + insert_acl_subj_label(match, role);
37364 + }
37365 +
37366 + return;
37367 +}
37368 +
37369 +static void
37370 +update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
37371 + const ino_t newinode, const dev_t newdevice)
37372 +{
37373 + unsigned int index = fhash(oldinode, olddevice, inodev_set.i_size);
37374 + struct inodev_entry *match;
37375 +
37376 + match = inodev_set.i_hash[index];
37377 +
37378 + while (match && (match->nentry->inode != oldinode ||
37379 + match->nentry->device != olddevice || !match->nentry->deleted))
37380 + match = match->next;
37381 +
37382 + if (match && (match->nentry->inode == oldinode)
37383 + && (match->nentry->device == olddevice) &&
37384 + match->nentry->deleted) {
37385 + if (match->prev == NULL) {
37386 + inodev_set.i_hash[index] = match->next;
37387 + if (match->next != NULL)
37388 + match->next->prev = NULL;
37389 + } else {
37390 + match->prev->next = match->next;
37391 + if (match->next != NULL)
37392 + match->next->prev = match->prev;
37393 + }
37394 + match->prev = NULL;
37395 + match->next = NULL;
37396 + match->nentry->inode = newinode;
37397 + match->nentry->device = newdevice;
37398 + match->nentry->deleted = 0;
37399 +
37400 + insert_inodev_entry(match);
37401 + }
37402 +
37403 + return;
37404 +}
37405 +
37406 +static void
37407 +do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
37408 + const struct vfsmount *mnt)
37409 +{
37410 + struct acl_subject_label *subj;
37411 + struct acl_role_label *role;
37412 + unsigned int x;
37413 +
37414 + FOR_EACH_ROLE_START(role)
37415 + update_acl_subj_label(matchn->inode, matchn->device,
37416 + dentry->d_inode->i_ino,
37417 + dentry->d_inode->i_sb->s_dev, role);
37418 +
37419 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
37420 + if ((subj->inode == dentry->d_inode->i_ino) &&
37421 + (subj->device == dentry->d_inode->i_sb->s_dev)) {
37422 + subj->inode = dentry->d_inode->i_ino;
37423 + subj->device = dentry->d_inode->i_sb->s_dev;
37424 + }
37425 + FOR_EACH_NESTED_SUBJECT_END(subj)
37426 + FOR_EACH_SUBJECT_START(role, subj, x)
37427 + update_acl_obj_label(matchn->inode, matchn->device,
37428 + dentry->d_inode->i_ino,
37429 + dentry->d_inode->i_sb->s_dev, subj);
37430 + FOR_EACH_SUBJECT_END(subj,x)
37431 + FOR_EACH_ROLE_END(role)
37432 +
37433 + update_inodev_entry(matchn->inode, matchn->device,
37434 + dentry->d_inode->i_ino, dentry->d_inode->i_sb->s_dev);
37435 +
37436 + return;
37437 +}
37438 +
37439 +void
37440 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
37441 +{
37442 + struct name_entry *matchn;
37443 +
37444 + if (unlikely(!(gr_status & GR_READY)))
37445 + return;
37446 +
37447 + preempt_disable();
37448 + matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
37449 +
37450 + if (unlikely((unsigned long)matchn)) {
37451 + write_lock(&gr_inode_lock);
37452 + do_handle_create(matchn, dentry, mnt);
37453 + write_unlock(&gr_inode_lock);
37454 + }
37455 + preempt_enable();
37456 +
37457 + return;
37458 +}
37459 +
37460 +void
37461 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
37462 + struct dentry *old_dentry,
37463 + struct dentry *new_dentry,
37464 + struct vfsmount *mnt, const __u8 replace)
37465 +{
37466 + struct name_entry *matchn;
37467 + struct inodev_entry *inodev;
37468 +
37469 + /* vfs_rename swaps the name and parent link for old_dentry and
37470 + new_dentry
37471 + at this point, old_dentry has the new name, parent link, and inode
37472 + for the renamed file
37473 + if a file is being replaced by a rename, new_dentry has the inode
37474 + and name for the replaced file
37475 + */
37476 +
37477 + if (unlikely(!(gr_status & GR_READY)))
37478 + return;
37479 +
37480 + preempt_disable();
37481 + matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
37482 +
37483 + /* we wouldn't have to check d_inode if it weren't for
37484 + NFS silly-renaming
37485 + */
37486 +
37487 + write_lock(&gr_inode_lock);
37488 + if (unlikely(replace && new_dentry->d_inode)) {
37489 + inodev = lookup_inodev_entry(new_dentry->d_inode->i_ino,
37490 + new_dentry->d_inode->i_sb->s_dev);
37491 + if (inodev != NULL && (new_dentry->d_inode->i_nlink <= 1))
37492 + do_handle_delete(inodev, new_dentry->d_inode->i_ino,
37493 + new_dentry->d_inode->i_sb->s_dev);
37494 + }
37495 +
37496 + inodev = lookup_inodev_entry(old_dentry->d_inode->i_ino,
37497 + old_dentry->d_inode->i_sb->s_dev);
37498 + if (inodev != NULL && (old_dentry->d_inode->i_nlink <= 1))
37499 + do_handle_delete(inodev, old_dentry->d_inode->i_ino,
37500 + old_dentry->d_inode->i_sb->s_dev);
37501 +
37502 + if (unlikely((unsigned long)matchn))
37503 + do_handle_create(matchn, old_dentry, mnt);
37504 +
37505 + write_unlock(&gr_inode_lock);
37506 + preempt_enable();
37507 +
37508 + return;
37509 +}
37510 +
37511 +static int
37512 +lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
37513 + unsigned char **sum)
37514 +{
37515 + struct acl_role_label *r;
37516 + struct role_allowed_ip *ipp;
37517 + struct role_transition *trans;
37518 + unsigned int i;
37519 + int found = 0;
37520 + u32 curr_ip = current->signal->curr_ip;
37521 +
37522 + current->signal->saved_ip = curr_ip;
37523 +
37524 + /* check transition table */
37525 +
37526 + for (trans = current->role->transitions; trans; trans = trans->next) {
37527 + if (!strcmp(rolename, trans->rolename)) {
37528 + found = 1;
37529 + break;
37530 + }
37531 + }
37532 +
37533 + if (!found)
37534 + return 0;
37535 +
37536 + /* handle special roles that do not require authentication
37537 + and check ip */
37538 +
37539 + FOR_EACH_ROLE_START(r)
37540 + if (!strcmp(rolename, r->rolename) &&
37541 + (r->roletype & GR_ROLE_SPECIAL)) {
37542 + found = 0;
37543 + if (r->allowed_ips != NULL) {
37544 + for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
37545 + if ((ntohl(curr_ip) & ipp->netmask) ==
37546 + (ntohl(ipp->addr) & ipp->netmask))
37547 + found = 1;
37548 + }
37549 + } else
37550 + found = 2;
37551 + if (!found)
37552 + return 0;
37553 +
37554 + if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
37555 + ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
37556 + *salt = NULL;
37557 + *sum = NULL;
37558 + return 1;
37559 + }
37560 + }
37561 + FOR_EACH_ROLE_END(r)
37562 +
37563 + for (i = 0; i < num_sprole_pws; i++) {
37564 + if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
37565 + *salt = acl_special_roles[i]->salt;
37566 + *sum = acl_special_roles[i]->sum;
37567 + return 1;
37568 + }
37569 + }
37570 +
37571 + return 0;
37572 +}
37573 +
37574 +static void
37575 +assign_special_role(char *rolename)
37576 +{
37577 + struct acl_object_label *obj;
37578 + struct acl_role_label *r;
37579 + struct acl_role_label *assigned = NULL;
37580 + struct task_struct *tsk;
37581 + struct file *filp;
37582 +
37583 + FOR_EACH_ROLE_START(r)
37584 + if (!strcmp(rolename, r->rolename) &&
37585 + (r->roletype & GR_ROLE_SPECIAL)) {
37586 + assigned = r;
37587 + break;
37588 + }
37589 + FOR_EACH_ROLE_END(r)
37590 +
37591 + if (!assigned)
37592 + return;
37593 +
37594 + read_lock(&tasklist_lock);
37595 + read_lock(&grsec_exec_file_lock);
37596 +
37597 + tsk = current->real_parent;
37598 + if (tsk == NULL)
37599 + goto out_unlock;
37600 +
37601 + filp = tsk->exec_file;
37602 + if (filp == NULL)
37603 + goto out_unlock;
37604 +
37605 + tsk->is_writable = 0;
37606 +
37607 + tsk->acl_sp_role = 1;
37608 + tsk->acl_role_id = ++acl_sp_role_value;
37609 + tsk->role = assigned;
37610 + tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
37611 +
37612 + /* ignore additional mmap checks for processes that are writable
37613 + by the default ACL */
37614 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
37615 + if (unlikely(obj->mode & GR_WRITE))
37616 + tsk->is_writable = 1;
37617 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
37618 + if (unlikely(obj->mode & GR_WRITE))
37619 + tsk->is_writable = 1;
37620 +
37621 +#ifdef CONFIG_GRKERNSEC_ACL_DEBUG
37622 + printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename, tsk->acl->filename, tsk->comm, tsk->pid);
37623 +#endif
37624 +
37625 +out_unlock:
37626 + read_unlock(&grsec_exec_file_lock);
37627 + read_unlock(&tasklist_lock);
37628 + return;
37629 +}
37630 +
37631 +int gr_check_secure_terminal(struct task_struct *task)
37632 +{
37633 + struct task_struct *p, *p2, *p3;
37634 + struct files_struct *files;
37635 + struct fdtable *fdt;
37636 + struct file *our_file = NULL, *file;
37637 + int i;
37638 +
37639 + if (task->signal->tty == NULL)
37640 + return 1;
37641 +
37642 + files = get_files_struct(task);
37643 + if (files != NULL) {
37644 + rcu_read_lock();
37645 + fdt = files_fdtable(files);
37646 + for (i=0; i < fdt->max_fds; i++) {
37647 + file = fcheck_files(files, i);
37648 + if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
37649 + get_file(file);
37650 + our_file = file;
37651 + }
37652 + }
37653 + rcu_read_unlock();
37654 + put_files_struct(files);
37655 + }
37656 +
37657 + if (our_file == NULL)
37658 + return 1;
37659 +
37660 + read_lock(&tasklist_lock);
37661 + do_each_thread(p2, p) {
37662 + files = get_files_struct(p);
37663 + if (files == NULL ||
37664 + (p->signal && p->signal->tty == task->signal->tty)) {
37665 + if (files != NULL)
37666 + put_files_struct(files);
37667 + continue;
37668 + }
37669 + rcu_read_lock();
37670 + fdt = files_fdtable(files);
37671 + for (i=0; i < fdt->max_fds; i++) {
37672 + file = fcheck_files(files, i);
37673 + if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
37674 + file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
37675 + p3 = task;
37676 + while (p3->pid > 0) {
37677 + if (p3 == p)
37678 + break;
37679 + p3 = p3->real_parent;
37680 + }
37681 + if (p3 == p)
37682 + break;
37683 + gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
37684 + gr_handle_alertkill(p);
37685 + rcu_read_unlock();
37686 + put_files_struct(files);
37687 + read_unlock(&tasklist_lock);
37688 + fput(our_file);
37689 + return 0;
37690 + }
37691 + }
37692 + rcu_read_unlock();
37693 + put_files_struct(files);
37694 + } while_each_thread(p2, p);
37695 + read_unlock(&tasklist_lock);
37696 +
37697 + fput(our_file);
37698 + return 1;
37699 +}
37700 +
37701 +ssize_t
37702 +write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
37703 +{
37704 + struct gr_arg_wrapper uwrap;
37705 + unsigned char *sprole_salt = NULL;
37706 + unsigned char *sprole_sum = NULL;
37707 + int error = sizeof (struct gr_arg_wrapper);
37708 + int error2 = 0;
37709 +
37710 + mutex_lock(&gr_dev_mutex);
37711 +
37712 + if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
37713 + error = -EPERM;
37714 + goto out;
37715 + }
37716 +
37717 + if (count != sizeof (struct gr_arg_wrapper)) {
37718 + gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
37719 + error = -EINVAL;
37720 + goto out;
37721 + }
37722 +
37723 +
37724 + if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
37725 + gr_auth_expires = 0;
37726 + gr_auth_attempts = 0;
37727 + }
37728 +
37729 + if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
37730 + error = -EFAULT;
37731 + goto out;
37732 + }
37733 +
37734 + if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
37735 + error = -EINVAL;
37736 + goto out;
37737 + }
37738 +
37739 + if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
37740 + error = -EFAULT;
37741 + goto out;
37742 + }
37743 +
37744 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
37745 + gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
37746 + time_after(gr_auth_expires, get_seconds())) {
37747 + error = -EBUSY;
37748 + goto out;
37749 + }
37750 +
37751 + /* if non-root trying to do anything other than use a special role,
37752 + do not attempt authentication, do not count towards authentication
37753 + locking
37754 + */
37755 +
37756 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
37757 + gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
37758 + current_uid()) {
37759 + error = -EPERM;
37760 + goto out;
37761 + }
37762 +
37763 + /* ensure pw and special role name are null terminated */
37764 +
37765 + gr_usermode->pw[GR_PW_LEN - 1] = '\0';
37766 + gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
37767 +
37768 + /* Okay.
37769 + * We have our enough of the argument structure..(we have yet
37770 + * to copy_from_user the tables themselves) . Copy the tables
37771 + * only if we need them, i.e. for loading operations. */
37772 +
37773 + switch (gr_usermode->mode) {
37774 + case GR_STATUS:
37775 + if (gr_status & GR_READY) {
37776 + error = 1;
37777 + if (!gr_check_secure_terminal(current))
37778 + error = 3;
37779 + } else
37780 + error = 2;
37781 + goto out;
37782 + case GR_SHUTDOWN:
37783 + if ((gr_status & GR_READY)
37784 + && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
37785 + pax_open_kernel();
37786 + gr_status &= ~GR_READY;
37787 + pax_close_kernel();
37788 +
37789 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
37790 + free_variables();
37791 + memset(gr_usermode, 0, sizeof (struct gr_arg));
37792 + memset(gr_system_salt, 0, GR_SALT_LEN);
37793 + memset(gr_system_sum, 0, GR_SHA_LEN);
37794 + } else if (gr_status & GR_READY) {
37795 + gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
37796 + error = -EPERM;
37797 + } else {
37798 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
37799 + error = -EAGAIN;
37800 + }
37801 + break;
37802 + case GR_ENABLE:
37803 + if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
37804 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
37805 + else {
37806 + if (gr_status & GR_READY)
37807 + error = -EAGAIN;
37808 + else
37809 + error = error2;
37810 + gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
37811 + }
37812 + break;
37813 + case GR_RELOAD:
37814 + if (!(gr_status & GR_READY)) {
37815 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
37816 + error = -EAGAIN;
37817 + } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
37818 + lock_kernel();
37819 +
37820 + pax_open_kernel();
37821 + gr_status &= ~GR_READY;
37822 + pax_close_kernel();
37823 +
37824 + free_variables();
37825 + if (!(error2 = gracl_init(gr_usermode))) {
37826 + unlock_kernel();
37827 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
37828 + } else {
37829 + unlock_kernel();
37830 + error = error2;
37831 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
37832 + }
37833 + } else {
37834 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
37835 + error = -EPERM;
37836 + }
37837 + break;
37838 + case GR_SEGVMOD:
37839 + if (unlikely(!(gr_status & GR_READY))) {
37840 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
37841 + error = -EAGAIN;
37842 + break;
37843 + }
37844 +
37845 + if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
37846 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
37847 + if (gr_usermode->segv_device && gr_usermode->segv_inode) {
37848 + struct acl_subject_label *segvacl;
37849 + segvacl =
37850 + lookup_acl_subj_label(gr_usermode->segv_inode,
37851 + gr_usermode->segv_device,
37852 + current->role);
37853 + if (segvacl) {
37854 + segvacl->crashes = 0;
37855 + segvacl->expires = 0;
37856 + }
37857 + } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
37858 + gr_remove_uid(gr_usermode->segv_uid);
37859 + }
37860 + } else {
37861 + gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
37862 + error = -EPERM;
37863 + }
37864 + break;
37865 + case GR_SPROLE:
37866 + case GR_SPROLEPAM:
37867 + if (unlikely(!(gr_status & GR_READY))) {
37868 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
37869 + error = -EAGAIN;
37870 + break;
37871 + }
37872 +
37873 + if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
37874 + current->role->expires = 0;
37875 + current->role->auth_attempts = 0;
37876 + }
37877 +
37878 + if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
37879 + time_after(current->role->expires, get_seconds())) {
37880 + error = -EBUSY;
37881 + goto out;
37882 + }
37883 +
37884 + if (lookup_special_role_auth
37885 + (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
37886 + && ((!sprole_salt && !sprole_sum)
37887 + || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
37888 + char *p = "";
37889 + assign_special_role(gr_usermode->sp_role);
37890 + read_lock(&tasklist_lock);
37891 + if (current->real_parent)
37892 + p = current->real_parent->role->rolename;
37893 + read_unlock(&tasklist_lock);
37894 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
37895 + p, acl_sp_role_value);
37896 + } else {
37897 + gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
37898 + error = -EPERM;
37899 + if(!(current->role->auth_attempts++))
37900 + current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
37901 +
37902 + goto out;
37903 + }
37904 + break;
37905 + case GR_UNSPROLE:
37906 + if (unlikely(!(gr_status & GR_READY))) {
37907 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
37908 + error = -EAGAIN;
37909 + break;
37910 + }
37911 +
37912 + if (current->role->roletype & GR_ROLE_SPECIAL) {
37913 + char *p = "";
37914 + int i = 0;
37915 +
37916 + read_lock(&tasklist_lock);
37917 + if (current->real_parent) {
37918 + p = current->real_parent->role->rolename;
37919 + i = current->real_parent->acl_role_id;
37920 + }
37921 + read_unlock(&tasklist_lock);
37922 +
37923 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
37924 + gr_set_acls(1);
37925 + } else {
37926 + error = -EPERM;
37927 + goto out;
37928 + }
37929 + break;
37930 + default:
37931 + gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
37932 + error = -EINVAL;
37933 + break;
37934 + }
37935 +
37936 + if (error != -EPERM)
37937 + goto out;
37938 +
37939 + if(!(gr_auth_attempts++))
37940 + gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
37941 +
37942 + out:
37943 + mutex_unlock(&gr_dev_mutex);
37944 + return error;
37945 +}
37946 +
37947 +int
37948 +gr_set_acls(const int type)
37949 +{
37950 + struct acl_object_label *obj;
37951 + struct task_struct *task, *task2;
37952 + struct file *filp;
37953 + struct acl_role_label *role = current->role;
37954 + __u16 acl_role_id = current->acl_role_id;
37955 + const struct cred *cred;
37956 + char *tmpname;
37957 + struct name_entry *nmatch;
37958 + struct acl_subject_label *tmpsubj;
37959 +
37960 + rcu_read_lock();
37961 + read_lock(&tasklist_lock);
37962 + read_lock(&grsec_exec_file_lock);
37963 + do_each_thread(task2, task) {
37964 + /* check to see if we're called from the exit handler,
37965 + if so, only replace ACLs that have inherited the admin
37966 + ACL */
37967 +
37968 + if (type && (task->role != role ||
37969 + task->acl_role_id != acl_role_id))
37970 + continue;
37971 +
37972 + task->acl_role_id = 0;
37973 + task->acl_sp_role = 0;
37974 +
37975 + if ((filp = task->exec_file)) {
37976 + cred = __task_cred(task);
37977 + task->role = lookup_acl_role_label(task, cred->uid, cred->gid);
37978 +
37979 + /* the following is to apply the correct subject
37980 + on binaries running when the RBAC system
37981 + is enabled, when the binaries have been
37982 + replaced or deleted since their execution
37983 + -----
37984 + when the RBAC system starts, the inode/dev
37985 + from exec_file will be one the RBAC system
37986 + is unaware of. It only knows the inode/dev
37987 + of the present file on disk, or the absence
37988 + of it.
37989 + */
37990 + preempt_disable();
37991 + tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
37992 +
37993 + nmatch = lookup_name_entry(tmpname);
37994 + preempt_enable();
37995 + tmpsubj = NULL;
37996 + if (nmatch) {
37997 + if (nmatch->deleted)
37998 + tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
37999 + else
38000 + tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
38001 + if (tmpsubj != NULL)
38002 + task->acl = tmpsubj;
38003 + }
38004 + if (tmpsubj == NULL)
38005 + task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
38006 + task->role);
38007 + if (task->acl) {
38008 + struct acl_subject_label *curr;
38009 + curr = task->acl;
38010 +
38011 + task->is_writable = 0;
38012 + /* ignore additional mmap checks for processes that are writable
38013 + by the default ACL */
38014 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
38015 + if (unlikely(obj->mode & GR_WRITE))
38016 + task->is_writable = 1;
38017 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
38018 + if (unlikely(obj->mode & GR_WRITE))
38019 + task->is_writable = 1;
38020 +
38021 + gr_set_proc_res(task);
38022 +
38023 +#ifdef CONFIG_GRKERNSEC_ACL_DEBUG
38024 + printk(KERN_ALERT "gr_set_acls for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
38025 +#endif
38026 + } else {
38027 + read_unlock(&grsec_exec_file_lock);
38028 + read_unlock(&tasklist_lock);
38029 + rcu_read_unlock();
38030 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task->pid);
38031 + return 1;
38032 + }
38033 + } else {
38034 + // it's a kernel process
38035 + task->role = kernel_role;
38036 + task->acl = kernel_role->root_label;
38037 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
38038 + task->acl->mode &= ~GR_PROCFIND;
38039 +#endif
38040 + }
38041 + } while_each_thread(task2, task);
38042 + read_unlock(&grsec_exec_file_lock);
38043 + read_unlock(&tasklist_lock);
38044 + rcu_read_unlock();
38045 +
38046 + return 0;
38047 +}
38048 +
38049 +void
38050 +gr_learn_resource(const struct task_struct *task,
38051 + const int res, const unsigned long wanted, const int gt)
38052 +{
38053 + struct acl_subject_label *acl;
38054 + const struct cred *cred;
38055 +
38056 + if (unlikely((gr_status & GR_READY) &&
38057 + task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
38058 + goto skip_reslog;
38059 +
38060 +#ifdef CONFIG_GRKERNSEC_RESLOG
38061 + gr_log_resource(task, res, wanted, gt);
38062 +#endif
38063 + skip_reslog:
38064 +
38065 + if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
38066 + return;
38067 +
38068 + acl = task->acl;
38069 +
38070 + if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
38071 + !(acl->resmask & (1 << (unsigned short) res))))
38072 + return;
38073 +
38074 + if (wanted >= acl->res[res].rlim_cur) {
38075 + unsigned long res_add;
38076 +
38077 + res_add = wanted;
38078 + switch (res) {
38079 + case RLIMIT_CPU:
38080 + res_add += GR_RLIM_CPU_BUMP;
38081 + break;
38082 + case RLIMIT_FSIZE:
38083 + res_add += GR_RLIM_FSIZE_BUMP;
38084 + break;
38085 + case RLIMIT_DATA:
38086 + res_add += GR_RLIM_DATA_BUMP;
38087 + break;
38088 + case RLIMIT_STACK:
38089 + res_add += GR_RLIM_STACK_BUMP;
38090 + break;
38091 + case RLIMIT_CORE:
38092 + res_add += GR_RLIM_CORE_BUMP;
38093 + break;
38094 + case RLIMIT_RSS:
38095 + res_add += GR_RLIM_RSS_BUMP;
38096 + break;
38097 + case RLIMIT_NPROC:
38098 + res_add += GR_RLIM_NPROC_BUMP;
38099 + break;
38100 + case RLIMIT_NOFILE:
38101 + res_add += GR_RLIM_NOFILE_BUMP;
38102 + break;
38103 + case RLIMIT_MEMLOCK:
38104 + res_add += GR_RLIM_MEMLOCK_BUMP;
38105 + break;
38106 + case RLIMIT_AS:
38107 + res_add += GR_RLIM_AS_BUMP;
38108 + break;
38109 + case RLIMIT_LOCKS:
38110 + res_add += GR_RLIM_LOCKS_BUMP;
38111 + break;
38112 + case RLIMIT_SIGPENDING:
38113 + res_add += GR_RLIM_SIGPENDING_BUMP;
38114 + break;
38115 + case RLIMIT_MSGQUEUE:
38116 + res_add += GR_RLIM_MSGQUEUE_BUMP;
38117 + break;
38118 + case RLIMIT_NICE:
38119 + res_add += GR_RLIM_NICE_BUMP;
38120 + break;
38121 + case RLIMIT_RTPRIO:
38122 + res_add += GR_RLIM_RTPRIO_BUMP;
38123 + break;
38124 + case RLIMIT_RTTIME:
38125 + res_add += GR_RLIM_RTTIME_BUMP;
38126 + break;
38127 + }
38128 +
38129 + acl->res[res].rlim_cur = res_add;
38130 +
38131 + if (wanted > acl->res[res].rlim_max)
38132 + acl->res[res].rlim_max = res_add;
38133 +
38134 + /* only log the subject filename, since resource logging is supported for
38135 + single-subject learning only */
38136 + rcu_read_lock();
38137 + cred = __task_cred(task);
38138 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
38139 + task->role->roletype, cred->uid, cred->gid, acl->filename,
38140 + acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
38141 + "", (unsigned long) res, &task->signal->saved_ip);
38142 + rcu_read_unlock();
38143 + }
38144 +
38145 + return;
38146 +}
38147 +
38148 +#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
38149 +void
38150 +pax_set_initial_flags(struct linux_binprm *bprm)
38151 +{
38152 + struct task_struct *task = current;
38153 + struct acl_subject_label *proc;
38154 + unsigned long flags;
38155 +
38156 + if (unlikely(!(gr_status & GR_READY)))
38157 + return;
38158 +
38159 + flags = pax_get_flags(task);
38160 +
38161 + proc = task->acl;
38162 +
38163 + if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
38164 + flags &= ~MF_PAX_PAGEEXEC;
38165 + if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
38166 + flags &= ~MF_PAX_SEGMEXEC;
38167 + if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
38168 + flags &= ~MF_PAX_RANDMMAP;
38169 + if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
38170 + flags &= ~MF_PAX_EMUTRAMP;
38171 + if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
38172 + flags &= ~MF_PAX_MPROTECT;
38173 +
38174 + if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
38175 + flags |= MF_PAX_PAGEEXEC;
38176 + if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
38177 + flags |= MF_PAX_SEGMEXEC;
38178 + if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
38179 + flags |= MF_PAX_RANDMMAP;
38180 + if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
38181 + flags |= MF_PAX_EMUTRAMP;
38182 + if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
38183 + flags |= MF_PAX_MPROTECT;
38184 +
38185 + pax_set_flags(task, flags);
38186 +
38187 + return;
38188 +}
38189 +#endif
38190 +
38191 +#ifdef CONFIG_SYSCTL
38192 +/* Eric Biederman likes breaking userland ABI and every inode-based security
38193 + system to save 35kb of memory */
38194 +
38195 +/* we modify the passed in filename, but adjust it back before returning */
38196 +static struct acl_object_label *gr_lookup_by_name(char *name, unsigned int len)
38197 +{
38198 + struct name_entry *nmatch;
38199 + char *p, *lastp = NULL;
38200 + struct acl_object_label *obj = NULL, *tmp;
38201 + struct acl_subject_label *tmpsubj;
38202 + char c = '\0';
38203 +
38204 + read_lock(&gr_inode_lock);
38205 +
38206 + p = name + len - 1;
38207 + do {
38208 + nmatch = lookup_name_entry(name);
38209 + if (lastp != NULL)
38210 + *lastp = c;
38211 +
38212 + if (nmatch == NULL)
38213 + goto next_component;
38214 + tmpsubj = current->acl;
38215 + do {
38216 + obj = lookup_acl_obj_label(nmatch->inode, nmatch->device, tmpsubj);
38217 + if (obj != NULL) {
38218 + tmp = obj->globbed;
38219 + while (tmp) {
38220 + if (!glob_match(tmp->filename, name)) {
38221 + obj = tmp;
38222 + goto found_obj;
38223 + }
38224 + tmp = tmp->next;
38225 + }
38226 + goto found_obj;
38227 + }
38228 + } while ((tmpsubj = tmpsubj->parent_subject));
38229 +next_component:
38230 + /* end case */
38231 + if (p == name)
38232 + break;
38233 +
38234 + while (*p != '/')
38235 + p--;
38236 + if (p == name)
38237 + lastp = p + 1;
38238 + else {
38239 + lastp = p;
38240 + p--;
38241 + }
38242 + c = *lastp;
38243 + *lastp = '\0';
38244 + } while (1);
38245 +found_obj:
38246 + read_unlock(&gr_inode_lock);
38247 + /* obj returned will always be non-null */
38248 + return obj;
38249 +}
38250 +
38251 +/* returns 0 when allowing, non-zero on error
38252 + op of 0 is used for readdir, so we don't log the names of hidden files
38253 +*/
38254 +__u32
38255 +gr_handle_sysctl(const struct ctl_table *table, const int op)
38256 +{
38257 + struct ctl_table *tmp;
38258 + const char *proc_sys = "/proc/sys";
38259 + char *path;
38260 + struct acl_object_label *obj;
38261 + unsigned short len = 0, pos = 0, depth = 0, i;
38262 + __u32 err = 0;
38263 + __u32 mode = 0;
38264 +
38265 + if (unlikely(!(gr_status & GR_READY)))
38266 + return 0;
38267 +
38268 + /* for now, ignore operations on non-sysctl entries if it's not a
38269 + readdir*/
38270 + if (table->child != NULL && op != 0)
38271 + return 0;
38272 +
38273 + mode |= GR_FIND;
38274 + /* it's only a read if it's an entry, read on dirs is for readdir */
38275 + if (op & MAY_READ)
38276 + mode |= GR_READ;
38277 + if (op & MAY_WRITE)
38278 + mode |= GR_WRITE;
38279 +
38280 + preempt_disable();
38281 +
38282 + path = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
38283 +
38284 + /* it's only a read/write if it's an actual entry, not a dir
38285 + (which are opened for readdir)
38286 + */
38287 +
38288 + /* convert the requested sysctl entry into a pathname */
38289 +
38290 + for (tmp = (struct ctl_table *)table; tmp != NULL; tmp = tmp->parent) {
38291 + len += strlen(tmp->procname);
38292 + len++;
38293 + depth++;
38294 + }
38295 +
38296 + if ((len + depth + strlen(proc_sys) + 1) > PAGE_SIZE) {
38297 + /* deny */
38298 + goto out;
38299 + }
38300 +
38301 + memset(path, 0, PAGE_SIZE);
38302 +
38303 + memcpy(path, proc_sys, strlen(proc_sys));
38304 +
38305 + pos += strlen(proc_sys);
38306 +
38307 + for (; depth > 0; depth--) {
38308 + path[pos] = '/';
38309 + pos++;
38310 + for (i = 1, tmp = (struct ctl_table *)table; tmp != NULL; tmp = tmp->parent) {
38311 + if (depth == i) {
38312 + memcpy(path + pos, tmp->procname,
38313 + strlen(tmp->procname));
38314 + pos += strlen(tmp->procname);
38315 + }
38316 + i++;
38317 + }
38318 + }
38319 +
38320 + obj = gr_lookup_by_name(path, pos);
38321 + err = obj->mode & (mode | to_gr_audit(mode) | GR_SUPPRESS);
38322 +
38323 + if (unlikely((current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) &&
38324 + ((err & mode) != mode))) {
38325 + __u32 new_mode = mode;
38326 +
38327 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
38328 +
38329 + err = 0;
38330 + gr_log_learn_sysctl(path, new_mode);
38331 + } else if (!(err & GR_FIND) && !(err & GR_SUPPRESS) && op != 0) {
38332 + gr_log_hidden_sysctl(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, path);
38333 + err = -ENOENT;
38334 + } else if (!(err & GR_FIND)) {
38335 + err = -ENOENT;
38336 + } else if (((err & mode) & ~GR_FIND) != (mode & ~GR_FIND) && !(err & GR_SUPPRESS)) {
38337 + gr_log_str4(GR_DONT_AUDIT, GR_SYSCTL_ACL_MSG, "denied",
38338 + path, (mode & GR_READ) ? " reading" : "",
38339 + (mode & GR_WRITE) ? " writing" : "");
38340 + err = -EACCES;
38341 + } else if ((err & mode) != mode) {
38342 + err = -EACCES;
38343 + } else if ((((err & mode) & ~GR_FIND) == (mode & ~GR_FIND)) && (err & GR_AUDITS)) {
38344 + gr_log_str4(GR_DO_AUDIT, GR_SYSCTL_ACL_MSG, "successful",
38345 + path, (mode & GR_READ) ? " reading" : "",
38346 + (mode & GR_WRITE) ? " writing" : "");
38347 + err = 0;
38348 + } else
38349 + err = 0;
38350 +
38351 + out:
38352 + preempt_enable();
38353 +
38354 + return err;
38355 +}
38356 +#endif
38357 +
38358 +int
38359 +gr_handle_proc_ptrace(struct task_struct *task)
38360 +{
38361 + struct file *filp;
38362 + struct task_struct *tmp = task;
38363 + struct task_struct *curtemp = current;
38364 + __u32 retmode;
38365 +
38366 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
38367 + if (unlikely(!(gr_status & GR_READY)))
38368 + return 0;
38369 +#endif
38370 +
38371 + read_lock(&tasklist_lock);
38372 + read_lock(&grsec_exec_file_lock);
38373 + filp = task->exec_file;
38374 +
38375 + while (tmp->pid > 0) {
38376 + if (tmp == curtemp)
38377 + break;
38378 + tmp = tmp->real_parent;
38379 + }
38380 +
38381 + if (!filp || (tmp->pid == 0 && ((grsec_enable_harden_ptrace && current_uid() && !(gr_status & GR_READY)) ||
38382 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
38383 + read_unlock(&grsec_exec_file_lock);
38384 + read_unlock(&tasklist_lock);
38385 + return 1;
38386 + }
38387 +
38388 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
38389 + if (!(gr_status & GR_READY)) {
38390 + read_unlock(&grsec_exec_file_lock);
38391 + read_unlock(&tasklist_lock);
38392 + return 0;
38393 + }
38394 +#endif
38395 +
38396 + retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
38397 + read_unlock(&grsec_exec_file_lock);
38398 + read_unlock(&tasklist_lock);
38399 +
38400 + if (retmode & GR_NOPTRACE)
38401 + return 1;
38402 +
38403 + if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
38404 + && (current->acl != task->acl || (current->acl != current->role->root_label
38405 + && current->pid != task->pid)))
38406 + return 1;
38407 +
38408 + return 0;
38409 +}
38410 +
38411 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
38412 +{
38413 + if (unlikely(!(gr_status & GR_READY)))
38414 + return;
38415 +
38416 + if (!(current->role->roletype & GR_ROLE_GOD))
38417 + return;
38418 +
38419 + seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
38420 + p->role->rolename, gr_task_roletype_to_char(p),
38421 + p->acl->filename);
38422 +}
38423 +
38424 +int
38425 +gr_handle_ptrace(struct task_struct *task, const long request)
38426 +{
38427 + struct task_struct *tmp = task;
38428 + struct task_struct *curtemp = current;
38429 + __u32 retmode;
38430 +
38431 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
38432 + if (unlikely(!(gr_status & GR_READY)))
38433 + return 0;
38434 +#endif
38435 +
38436 + read_lock(&tasklist_lock);
38437 + while (tmp->pid > 0) {
38438 + if (tmp == curtemp)
38439 + break;
38440 + tmp = tmp->real_parent;
38441 + }
38442 +
38443 + if (tmp->pid == 0 && ((grsec_enable_harden_ptrace && current_uid() && !(gr_status & GR_READY)) ||
38444 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
38445 + read_unlock(&tasklist_lock);
38446 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
38447 + return 1;
38448 + }
38449 + read_unlock(&tasklist_lock);
38450 +
38451 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
38452 + if (!(gr_status & GR_READY))
38453 + return 0;
38454 +#endif
38455 +
38456 + read_lock(&grsec_exec_file_lock);
38457 + if (unlikely(!task->exec_file)) {
38458 + read_unlock(&grsec_exec_file_lock);
38459 + return 0;
38460 + }
38461 +
38462 + retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
38463 + read_unlock(&grsec_exec_file_lock);
38464 +
38465 + if (retmode & GR_NOPTRACE) {
38466 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
38467 + return 1;
38468 + }
38469 +
38470 + if (retmode & GR_PTRACERD) {
38471 + switch (request) {
38472 + case PTRACE_POKETEXT:
38473 + case PTRACE_POKEDATA:
38474 + case PTRACE_POKEUSR:
38475 +#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
38476 + case PTRACE_SETREGS:
38477 + case PTRACE_SETFPREGS:
38478 +#endif
38479 +#ifdef CONFIG_X86
38480 + case PTRACE_SETFPXREGS:
38481 +#endif
38482 +#ifdef CONFIG_ALTIVEC
38483 + case PTRACE_SETVRREGS:
38484 +#endif
38485 + return 1;
38486 + default:
38487 + return 0;
38488 + }
38489 + } else if (!(current->acl->mode & GR_POVERRIDE) &&
38490 + !(current->role->roletype & GR_ROLE_GOD) &&
38491 + (current->acl != task->acl)) {
38492 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
38493 + return 1;
38494 + }
38495 +
38496 + return 0;
38497 +}
38498 +
38499 +static int is_writable_mmap(const struct file *filp)
38500 +{
38501 + struct task_struct *task = current;
38502 + struct acl_object_label *obj, *obj2;
38503 +
38504 + if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
38505 + !task->is_writable && S_ISREG(filp->f_path.dentry->d_inode->i_mode) && filp->f_path.mnt != shm_mnt) {
38506 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
38507 + obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
38508 + task->role->root_label);
38509 + if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
38510 + gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
38511 + return 1;
38512 + }
38513 + }
38514 + return 0;
38515 +}
38516 +
38517 +int
38518 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
38519 +{
38520 + __u32 mode;
38521 +
38522 + if (unlikely(!file || !(prot & PROT_EXEC)))
38523 + return 1;
38524 +
38525 + if (is_writable_mmap(file))
38526 + return 0;
38527 +
38528 + mode =
38529 + gr_search_file(file->f_path.dentry,
38530 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
38531 + file->f_path.mnt);
38532 +
38533 + if (!gr_tpe_allow(file))
38534 + return 0;
38535 +
38536 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
38537 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
38538 + return 0;
38539 + } else if (unlikely(!(mode & GR_EXEC))) {
38540 + return 0;
38541 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
38542 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
38543 + return 1;
38544 + }
38545 +
38546 + return 1;
38547 +}
38548 +
38549 +int
38550 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
38551 +{
38552 + __u32 mode;
38553 +
38554 + if (unlikely(!file || !(prot & PROT_EXEC)))
38555 + return 1;
38556 +
38557 + if (is_writable_mmap(file))
38558 + return 0;
38559 +
38560 + mode =
38561 + gr_search_file(file->f_path.dentry,
38562 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
38563 + file->f_path.mnt);
38564 +
38565 + if (!gr_tpe_allow(file))
38566 + return 0;
38567 +
38568 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
38569 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
38570 + return 0;
38571 + } else if (unlikely(!(mode & GR_EXEC))) {
38572 + return 0;
38573 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
38574 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
38575 + return 1;
38576 + }
38577 +
38578 + return 1;
38579 +}
38580 +
38581 +void
38582 +gr_acl_handle_psacct(struct task_struct *task, const long code)
38583 +{
38584 + unsigned long runtime;
38585 + unsigned long cputime;
38586 + unsigned int wday, cday;
38587 + __u8 whr, chr;
38588 + __u8 wmin, cmin;
38589 + __u8 wsec, csec;
38590 + struct timespec timeval;
38591 +
38592 + if (unlikely(!(gr_status & GR_READY) || !task->acl ||
38593 + !(task->acl->mode & GR_PROCACCT)))
38594 + return;
38595 +
38596 + do_posix_clock_monotonic_gettime(&timeval);
38597 + runtime = timeval.tv_sec - task->start_time.tv_sec;
38598 + wday = runtime / (3600 * 24);
38599 + runtime -= wday * (3600 * 24);
38600 + whr = runtime / 3600;
38601 + runtime -= whr * 3600;
38602 + wmin = runtime / 60;
38603 + runtime -= wmin * 60;
38604 + wsec = runtime;
38605 +
38606 + cputime = (task->utime + task->stime) / HZ;
38607 + cday = cputime / (3600 * 24);
38608 + cputime -= cday * (3600 * 24);
38609 + chr = cputime / 3600;
38610 + cputime -= chr * 3600;
38611 + cmin = cputime / 60;
38612 + cputime -= cmin * 60;
38613 + csec = cputime;
38614 +
38615 + gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
38616 +
38617 + return;
38618 +}
38619 +
38620 +void gr_set_kernel_label(struct task_struct *task)
38621 +{
38622 + if (gr_status & GR_READY) {
38623 + task->role = kernel_role;
38624 + task->acl = kernel_role->root_label;
38625 + }
38626 + return;
38627 +}
38628 +
38629 +#ifdef CONFIG_TASKSTATS
38630 +int gr_is_taskstats_denied(int pid)
38631 +{
38632 + struct task_struct *task;
38633 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
38634 + const struct cred *cred;
38635 +#endif
38636 + int ret = 0;
38637 +
38638 + /* restrict taskstats viewing to un-chrooted root users
38639 + who have the 'view' subject flag if the RBAC system is enabled
38640 + */
38641 +
38642 + rcu_read_lock();
38643 + read_lock(&tasklist_lock);
38644 + task = find_task_by_vpid(pid);
38645 + if (task) {
38646 +#ifdef CONFIG_GRKERNSEC_CHROOT
38647 + if (proc_is_chrooted(task))
38648 + ret = -EACCES;
38649 +#endif
38650 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
38651 + cred = __task_cred(task);
38652 +#ifdef CONFIG_GRKERNSEC_PROC_USER
38653 + if (cred->uid != 0)
38654 + ret = -EACCES;
38655 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
38656 + if (cred->uid != 0 && !groups_search(cred->group_info, CONFIG_GRKERNSEC_PROC_GID))
38657 + ret = -EACCES;
38658 +#endif
38659 +#endif
38660 + if (gr_status & GR_READY) {
38661 + if (!(task->acl->mode & GR_VIEW))
38662 + ret = -EACCES;
38663 + }
38664 + } else
38665 + ret = -ENOENT;
38666 +
38667 + read_unlock(&tasklist_lock);
38668 + rcu_read_unlock();
38669 +
38670 + return ret;
38671 +}
38672 +#endif
38673 +
38674 +/* AUXV entries are filled via a descendant of search_binary_handler
38675 + after we've already applied the subject for the target
38676 +*/
38677 +int gr_acl_enable_at_secure(void)
38678 +{
38679 + if (unlikely(!(gr_status & GR_READY)))
38680 + return 0;
38681 +
38682 + if (current->acl->mode & GR_ATSECURE)
38683 + return 1;
38684 +
38685 + return 0;
38686 +}
38687 +
38688 +int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
38689 +{
38690 + struct task_struct *task = current;
38691 + struct dentry *dentry = file->f_path.dentry;
38692 + struct vfsmount *mnt = file->f_path.mnt;
38693 + struct acl_object_label *obj, *tmp;
38694 + struct acl_subject_label *subj;
38695 + unsigned int bufsize;
38696 + int is_not_root;
38697 + char *path;
38698 +
38699 + if (unlikely(!(gr_status & GR_READY)))
38700 + return 1;
38701 +
38702 + if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
38703 + return 1;
38704 +
38705 + /* ignore Eric Biederman */
38706 + if (IS_PRIVATE(dentry->d_inode))
38707 + return 1;
38708 +
38709 + subj = task->acl;
38710 + do {
38711 + obj = lookup_acl_obj_label(ino, dentry->d_inode->i_sb->s_dev, subj);
38712 + if (obj != NULL)
38713 + return (obj->mode & GR_FIND) ? 1 : 0;
38714 + } while ((subj = subj->parent_subject));
38715 +
38716 + /* this is purely an optimization since we're looking for an object
38717 + for the directory we're doing a readdir on
38718 + if it's possible for any globbed object to match the entry we're
38719 + filling into the directory, then the object we find here will be
38720 + an anchor point with attached globbed objects
38721 + */
38722 + obj = chk_obj_label_noglob(dentry, mnt, task->acl);
38723 + if (obj->globbed == NULL)
38724 + return (obj->mode & GR_FIND) ? 1 : 0;
38725 +
38726 + is_not_root = ((obj->filename[0] == '/') &&
38727 + (obj->filename[1] == '\0')) ? 0 : 1;
38728 + bufsize = PAGE_SIZE - namelen - is_not_root;
38729 +
38730 + /* check bufsize > PAGE_SIZE || bufsize == 0 */
38731 + if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
38732 + return 1;
38733 +
38734 + preempt_disable();
38735 + path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
38736 + bufsize);
38737 +
38738 + bufsize = strlen(path);
38739 +
38740 + /* if base is "/", don't append an additional slash */
38741 + if (is_not_root)
38742 + *(path + bufsize) = '/';
38743 + memcpy(path + bufsize + is_not_root, name, namelen);
38744 + *(path + bufsize + namelen + is_not_root) = '\0';
38745 +
38746 + tmp = obj->globbed;
38747 + while (tmp) {
38748 + if (!glob_match(tmp->filename, path)) {
38749 + preempt_enable();
38750 + return (tmp->mode & GR_FIND) ? 1 : 0;
38751 + }
38752 + tmp = tmp->next;
38753 + }
38754 + preempt_enable();
38755 + return (obj->mode & GR_FIND) ? 1 : 0;
38756 +}
38757 +
38758 +#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
38759 +EXPORT_SYMBOL(gr_acl_is_enabled);
38760 +#endif
38761 +EXPORT_SYMBOL(gr_learn_resource);
38762 +EXPORT_SYMBOL(gr_set_kernel_label);
38763 +#ifdef CONFIG_SECURITY
38764 +EXPORT_SYMBOL(gr_check_user_change);
38765 +EXPORT_SYMBOL(gr_check_group_change);
38766 +#endif
38767 +
38768 diff -urNp linux-2.6.37/grsecurity/gracl_cap.c linux-2.6.37/grsecurity/gracl_cap.c
38769 --- linux-2.6.37/grsecurity/gracl_cap.c 1969-12-31 19:00:00.000000000 -0500
38770 +++ linux-2.6.37/grsecurity/gracl_cap.c 2011-01-17 02:41:02.000000000 -0500
38771 @@ -0,0 +1,138 @@
38772 +#include <linux/kernel.h>
38773 +#include <linux/module.h>
38774 +#include <linux/sched.h>
38775 +#include <linux/gracl.h>
38776 +#include <linux/grsecurity.h>
38777 +#include <linux/grinternal.h>
38778 +
38779 +static const char *captab_log[] = {
38780 + "CAP_CHOWN",
38781 + "CAP_DAC_OVERRIDE",
38782 + "CAP_DAC_READ_SEARCH",
38783 + "CAP_FOWNER",
38784 + "CAP_FSETID",
38785 + "CAP_KILL",
38786 + "CAP_SETGID",
38787 + "CAP_SETUID",
38788 + "CAP_SETPCAP",
38789 + "CAP_LINUX_IMMUTABLE",
38790 + "CAP_NET_BIND_SERVICE",
38791 + "CAP_NET_BROADCAST",
38792 + "CAP_NET_ADMIN",
38793 + "CAP_NET_RAW",
38794 + "CAP_IPC_LOCK",
38795 + "CAP_IPC_OWNER",
38796 + "CAP_SYS_MODULE",
38797 + "CAP_SYS_RAWIO",
38798 + "CAP_SYS_CHROOT",
38799 + "CAP_SYS_PTRACE",
38800 + "CAP_SYS_PACCT",
38801 + "CAP_SYS_ADMIN",
38802 + "CAP_SYS_BOOT",
38803 + "CAP_SYS_NICE",
38804 + "CAP_SYS_RESOURCE",
38805 + "CAP_SYS_TIME",
38806 + "CAP_SYS_TTY_CONFIG",
38807 + "CAP_MKNOD",
38808 + "CAP_LEASE",
38809 + "CAP_AUDIT_WRITE",
38810 + "CAP_AUDIT_CONTROL",
38811 + "CAP_SETFCAP",
38812 + "CAP_MAC_OVERRIDE",
38813 + "CAP_MAC_ADMIN"
38814 +};
38815 +
38816 +EXPORT_SYMBOL(gr_is_capable);
38817 +EXPORT_SYMBOL(gr_is_capable_nolog);
38818 +
38819 +int
38820 +gr_is_capable(const int cap)
38821 +{
38822 + struct task_struct *task = current;
38823 + const struct cred *cred = current_cred();
38824 + struct acl_subject_label *curracl;
38825 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
38826 + kernel_cap_t cap_audit = __cap_empty_set;
38827 +
38828 + if (!gr_acl_is_enabled())
38829 + return 1;
38830 +
38831 + curracl = task->acl;
38832 +
38833 + cap_drop = curracl->cap_lower;
38834 + cap_mask = curracl->cap_mask;
38835 + cap_audit = curracl->cap_invert_audit;
38836 +
38837 + while ((curracl = curracl->parent_subject)) {
38838 + /* if the cap isn't specified in the current computed mask but is specified in the
38839 + current level subject, and is lowered in the current level subject, then add
38840 + it to the set of dropped capabilities
38841 + otherwise, add the current level subject's mask to the current computed mask
38842 + */
38843 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
38844 + cap_raise(cap_mask, cap);
38845 + if (cap_raised(curracl->cap_lower, cap))
38846 + cap_raise(cap_drop, cap);
38847 + if (cap_raised(curracl->cap_invert_audit, cap))
38848 + cap_raise(cap_audit, cap);
38849 + }
38850 + }
38851 +
38852 + if (!cap_raised(cap_drop, cap)) {
38853 + if (cap_raised(cap_audit, cap))
38854 + gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
38855 + return 1;
38856 + }
38857 +
38858 + curracl = task->acl;
38859 +
38860 + if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
38861 + && cap_raised(cred->cap_effective, cap)) {
38862 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
38863 + task->role->roletype, cred->uid,
38864 + cred->gid, task->exec_file ?
38865 + gr_to_filename(task->exec_file->f_path.dentry,
38866 + task->exec_file->f_path.mnt) : curracl->filename,
38867 + curracl->filename, 0UL,
38868 + 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
38869 + return 1;
38870 + }
38871 +
38872 + if ((cap >= 0) && (cap < (sizeof(captab_log)/sizeof(captab_log[0]))) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
38873 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
38874 + return 0;
38875 +}
38876 +
38877 +int
38878 +gr_is_capable_nolog(const int cap)
38879 +{
38880 + struct acl_subject_label *curracl;
38881 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
38882 +
38883 + if (!gr_acl_is_enabled())
38884 + return 1;
38885 +
38886 + curracl = current->acl;
38887 +
38888 + cap_drop = curracl->cap_lower;
38889 + cap_mask = curracl->cap_mask;
38890 +
38891 + while ((curracl = curracl->parent_subject)) {
38892 + /* if the cap isn't specified in the current computed mask but is specified in the
38893 + current level subject, and is lowered in the current level subject, then add
38894 + it to the set of dropped capabilities
38895 + otherwise, add the current level subject's mask to the current computed mask
38896 + */
38897 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
38898 + cap_raise(cap_mask, cap);
38899 + if (cap_raised(curracl->cap_lower, cap))
38900 + cap_raise(cap_drop, cap);
38901 + }
38902 + }
38903 +
38904 + if (!cap_raised(cap_drop, cap))
38905 + return 1;
38906 +
38907 + return 0;
38908 +}
38909 +
38910 diff -urNp linux-2.6.37/grsecurity/gracl_fs.c linux-2.6.37/grsecurity/gracl_fs.c
38911 --- linux-2.6.37/grsecurity/gracl_fs.c 1969-12-31 19:00:00.000000000 -0500
38912 +++ linux-2.6.37/grsecurity/gracl_fs.c 2011-01-17 02:41:02.000000000 -0500
38913 @@ -0,0 +1,430 @@
38914 +#include <linux/kernel.h>
38915 +#include <linux/sched.h>
38916 +#include <linux/types.h>
38917 +#include <linux/fs.h>
38918 +#include <linux/file.h>
38919 +#include <linux/stat.h>
38920 +#include <linux/grsecurity.h>
38921 +#include <linux/grinternal.h>
38922 +#include <linux/gracl.h>
38923 +
38924 +__u32
38925 +gr_acl_handle_hidden_file(const struct dentry * dentry,
38926 + const struct vfsmount * mnt)
38927 +{
38928 + __u32 mode;
38929 +
38930 + if (unlikely(!dentry->d_inode))
38931 + return GR_FIND;
38932 +
38933 + mode =
38934 + gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
38935 +
38936 + if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
38937 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
38938 + return mode;
38939 + } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
38940 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
38941 + return 0;
38942 + } else if (unlikely(!(mode & GR_FIND)))
38943 + return 0;
38944 +
38945 + return GR_FIND;
38946 +}
38947 +
38948 +__u32
38949 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
38950 + const int fmode)
38951 +{
38952 + __u32 reqmode = GR_FIND;
38953 + __u32 mode;
38954 +
38955 + if (unlikely(!dentry->d_inode))
38956 + return reqmode;
38957 +
38958 + if (unlikely(fmode & O_APPEND))
38959 + reqmode |= GR_APPEND;
38960 + else if (unlikely(fmode & FMODE_WRITE))
38961 + reqmode |= GR_WRITE;
38962 + if (likely((fmode & FMODE_READ) && !(fmode & O_DIRECTORY)))
38963 + reqmode |= GR_READ;
38964 + if ((fmode & FMODE_GREXEC) && (fmode & FMODE_EXEC))
38965 + reqmode &= ~GR_READ;
38966 + mode =
38967 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
38968 + mnt);
38969 +
38970 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
38971 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
38972 + reqmode & GR_READ ? " reading" : "",
38973 + reqmode & GR_WRITE ? " writing" : reqmode &
38974 + GR_APPEND ? " appending" : "");
38975 + return reqmode;
38976 + } else
38977 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
38978 + {
38979 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
38980 + reqmode & GR_READ ? " reading" : "",
38981 + reqmode & GR_WRITE ? " writing" : reqmode &
38982 + GR_APPEND ? " appending" : "");
38983 + return 0;
38984 + } else if (unlikely((mode & reqmode) != reqmode))
38985 + return 0;
38986 +
38987 + return reqmode;
38988 +}
38989 +
38990 +__u32
38991 +gr_acl_handle_creat(const struct dentry * dentry,
38992 + const struct dentry * p_dentry,
38993 + const struct vfsmount * p_mnt, const int fmode,
38994 + const int imode)
38995 +{
38996 + __u32 reqmode = GR_WRITE | GR_CREATE;
38997 + __u32 mode;
38998 +
38999 + if (unlikely(fmode & O_APPEND))
39000 + reqmode |= GR_APPEND;
39001 + if (unlikely((fmode & FMODE_READ) && !(fmode & O_DIRECTORY)))
39002 + reqmode |= GR_READ;
39003 + if (unlikely((fmode & O_CREAT) && (imode & (S_ISUID | S_ISGID))))
39004 + reqmode |= GR_SETID;
39005 +
39006 + mode =
39007 + gr_check_create(dentry, p_dentry, p_mnt,
39008 + reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
39009 +
39010 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
39011 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
39012 + reqmode & GR_READ ? " reading" : "",
39013 + reqmode & GR_WRITE ? " writing" : reqmode &
39014 + GR_APPEND ? " appending" : "");
39015 + return reqmode;
39016 + } else
39017 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
39018 + {
39019 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
39020 + reqmode & GR_READ ? " reading" : "",
39021 + reqmode & GR_WRITE ? " writing" : reqmode &
39022 + GR_APPEND ? " appending" : "");
39023 + return 0;
39024 + } else if (unlikely((mode & reqmode) != reqmode))
39025 + return 0;
39026 +
39027 + return reqmode;
39028 +}
39029 +
39030 +__u32
39031 +gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
39032 + const int fmode)
39033 +{
39034 + __u32 mode, reqmode = GR_FIND;
39035 +
39036 + if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
39037 + reqmode |= GR_EXEC;
39038 + if (fmode & S_IWOTH)
39039 + reqmode |= GR_WRITE;
39040 + if (fmode & S_IROTH)
39041 + reqmode |= GR_READ;
39042 +
39043 + mode =
39044 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
39045 + mnt);
39046 +
39047 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
39048 + gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
39049 + reqmode & GR_READ ? " reading" : "",
39050 + reqmode & GR_WRITE ? " writing" : "",
39051 + reqmode & GR_EXEC ? " executing" : "");
39052 + return reqmode;
39053 + } else
39054 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
39055 + {
39056 + gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
39057 + reqmode & GR_READ ? " reading" : "",
39058 + reqmode & GR_WRITE ? " writing" : "",
39059 + reqmode & GR_EXEC ? " executing" : "");
39060 + return 0;
39061 + } else if (unlikely((mode & reqmode) != reqmode))
39062 + return 0;
39063 +
39064 + return reqmode;
39065 +}
39066 +
39067 +static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
39068 +{
39069 + __u32 mode;
39070 +
39071 + mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
39072 +
39073 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
39074 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
39075 + return mode;
39076 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
39077 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
39078 + return 0;
39079 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
39080 + return 0;
39081 +
39082 + return (reqmode);
39083 +}
39084 +
39085 +__u32
39086 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
39087 +{
39088 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
39089 +}
39090 +
39091 +__u32
39092 +gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
39093 +{
39094 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
39095 +}
39096 +
39097 +__u32
39098 +gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
39099 +{
39100 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
39101 +}
39102 +
39103 +__u32
39104 +gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
39105 +{
39106 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
39107 +}
39108 +
39109 +__u32
39110 +gr_acl_handle_fchmod(const struct dentry *dentry, const struct vfsmount *mnt,
39111 + mode_t mode)
39112 +{
39113 + if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
39114 + return 1;
39115 +
39116 + if (unlikely((mode != (mode_t)-1) && (mode & (S_ISUID | S_ISGID)))) {
39117 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
39118 + GR_FCHMOD_ACL_MSG);
39119 + } else {
39120 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_FCHMOD_ACL_MSG);
39121 + }
39122 +}
39123 +
39124 +__u32
39125 +gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
39126 + mode_t mode)
39127 +{
39128 + if (unlikely((mode != (mode_t)-1) && (mode & (S_ISUID | S_ISGID)))) {
39129 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
39130 + GR_CHMOD_ACL_MSG);
39131 + } else {
39132 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
39133 + }
39134 +}
39135 +
39136 +__u32
39137 +gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
39138 +{
39139 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
39140 +}
39141 +
39142 +__u32
39143 +gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
39144 +{
39145 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
39146 +}
39147 +
39148 +__u32
39149 +gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
39150 +{
39151 + return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
39152 +}
39153 +
39154 +__u32
39155 +gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
39156 +{
39157 + return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
39158 + GR_UNIXCONNECT_ACL_MSG);
39159 +}
39160 +
39161 +/* hardlinks require at minimum create permission,
39162 + any additional privilege required is based on the
39163 + privilege of the file being linked to
39164 +*/
39165 +__u32
39166 +gr_acl_handle_link(const struct dentry * new_dentry,
39167 + const struct dentry * parent_dentry,
39168 + const struct vfsmount * parent_mnt,
39169 + const struct dentry * old_dentry,
39170 + const struct vfsmount * old_mnt, const char *to)
39171 +{
39172 + __u32 mode;
39173 + __u32 needmode = GR_CREATE | GR_LINK;
39174 + __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
39175 +
39176 + mode =
39177 + gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
39178 + old_mnt);
39179 +
39180 + if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
39181 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
39182 + return mode;
39183 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
39184 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
39185 + return 0;
39186 + } else if (unlikely((mode & needmode) != needmode))
39187 + return 0;
39188 +
39189 + return 1;
39190 +}
39191 +
39192 +__u32
39193 +gr_acl_handle_symlink(const struct dentry * new_dentry,
39194 + const struct dentry * parent_dentry,
39195 + const struct vfsmount * parent_mnt, const char *from)
39196 +{
39197 + __u32 needmode = GR_WRITE | GR_CREATE;
39198 + __u32 mode;
39199 +
39200 + mode =
39201 + gr_check_create(new_dentry, parent_dentry, parent_mnt,
39202 + GR_CREATE | GR_AUDIT_CREATE |
39203 + GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
39204 +
39205 + if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
39206 + gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
39207 + return mode;
39208 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
39209 + gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
39210 + return 0;
39211 + } else if (unlikely((mode & needmode) != needmode))
39212 + return 0;
39213 +
39214 + return (GR_WRITE | GR_CREATE);
39215 +}
39216 +
39217 +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)
39218 +{
39219 + __u32 mode;
39220 +
39221 + mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
39222 +
39223 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
39224 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
39225 + return mode;
39226 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
39227 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
39228 + return 0;
39229 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
39230 + return 0;
39231 +
39232 + return (reqmode);
39233 +}
39234 +
39235 +__u32
39236 +gr_acl_handle_mknod(const struct dentry * new_dentry,
39237 + const struct dentry * parent_dentry,
39238 + const struct vfsmount * parent_mnt,
39239 + const int mode)
39240 +{
39241 + __u32 reqmode = GR_WRITE | GR_CREATE;
39242 + if (unlikely(mode & (S_ISUID | S_ISGID)))
39243 + reqmode |= GR_SETID;
39244 +
39245 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
39246 + reqmode, GR_MKNOD_ACL_MSG);
39247 +}
39248 +
39249 +__u32
39250 +gr_acl_handle_mkdir(const struct dentry *new_dentry,
39251 + const struct dentry *parent_dentry,
39252 + const struct vfsmount *parent_mnt)
39253 +{
39254 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
39255 + GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
39256 +}
39257 +
39258 +#define RENAME_CHECK_SUCCESS(old, new) \
39259 + (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
39260 + ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
39261 +
39262 +int
39263 +gr_acl_handle_rename(struct dentry *new_dentry,
39264 + struct dentry *parent_dentry,
39265 + const struct vfsmount *parent_mnt,
39266 + struct dentry *old_dentry,
39267 + struct inode *old_parent_inode,
39268 + struct vfsmount *old_mnt, const char *newname)
39269 +{
39270 + __u32 comp1, comp2;
39271 + int error = 0;
39272 +
39273 + if (unlikely(!gr_acl_is_enabled()))
39274 + return 0;
39275 +
39276 + if (!new_dentry->d_inode) {
39277 + comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
39278 + GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
39279 + GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
39280 + comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
39281 + GR_DELETE | GR_AUDIT_DELETE |
39282 + GR_AUDIT_READ | GR_AUDIT_WRITE |
39283 + GR_SUPPRESS, old_mnt);
39284 + } else {
39285 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
39286 + GR_CREATE | GR_DELETE |
39287 + GR_AUDIT_CREATE | GR_AUDIT_DELETE |
39288 + GR_AUDIT_READ | GR_AUDIT_WRITE |
39289 + GR_SUPPRESS, parent_mnt);
39290 + comp2 =
39291 + gr_search_file(old_dentry,
39292 + GR_READ | GR_WRITE | GR_AUDIT_READ |
39293 + GR_DELETE | GR_AUDIT_DELETE |
39294 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
39295 + }
39296 +
39297 + if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
39298 + ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
39299 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
39300 + else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
39301 + && !(comp2 & GR_SUPPRESS)) {
39302 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
39303 + error = -EACCES;
39304 + } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
39305 + error = -EACCES;
39306 +
39307 + return error;
39308 +}
39309 +
39310 +void
39311 +gr_acl_handle_exit(void)
39312 +{
39313 + u16 id;
39314 + char *rolename;
39315 + struct file *exec_file;
39316 +
39317 + if (unlikely(current->acl_sp_role && gr_acl_is_enabled())) {
39318 + id = current->acl_role_id;
39319 + rolename = current->role->rolename;
39320 + gr_set_acls(1);
39321 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
39322 + }
39323 +
39324 + write_lock(&grsec_exec_file_lock);
39325 + exec_file = current->exec_file;
39326 + current->exec_file = NULL;
39327 + write_unlock(&grsec_exec_file_lock);
39328 +
39329 + if (exec_file)
39330 + fput(exec_file);
39331 +}
39332 +
39333 +int
39334 +gr_acl_handle_procpidmem(const struct task_struct *task)
39335 +{
39336 + if (unlikely(!gr_acl_is_enabled()))
39337 + return 0;
39338 +
39339 + if (task != current && task->acl->mode & GR_PROTPROCFD)
39340 + return -EACCES;
39341 +
39342 + return 0;
39343 +}
39344 diff -urNp linux-2.6.37/grsecurity/gracl_ip.c linux-2.6.37/grsecurity/gracl_ip.c
39345 --- linux-2.6.37/grsecurity/gracl_ip.c 1969-12-31 19:00:00.000000000 -0500
39346 +++ linux-2.6.37/grsecurity/gracl_ip.c 2011-01-17 02:41:02.000000000 -0500
39347 @@ -0,0 +1,382 @@
39348 +#include <linux/kernel.h>
39349 +#include <asm/uaccess.h>
39350 +#include <asm/errno.h>
39351 +#include <net/sock.h>
39352 +#include <linux/file.h>
39353 +#include <linux/fs.h>
39354 +#include <linux/net.h>
39355 +#include <linux/in.h>
39356 +#include <linux/skbuff.h>
39357 +#include <linux/ip.h>
39358 +#include <linux/udp.h>
39359 +#include <linux/smp_lock.h>
39360 +#include <linux/types.h>
39361 +#include <linux/sched.h>
39362 +#include <linux/netdevice.h>
39363 +#include <linux/inetdevice.h>
39364 +#include <linux/gracl.h>
39365 +#include <linux/grsecurity.h>
39366 +#include <linux/grinternal.h>
39367 +
39368 +#define GR_BIND 0x01
39369 +#define GR_CONNECT 0x02
39370 +#define GR_INVERT 0x04
39371 +#define GR_BINDOVERRIDE 0x08
39372 +#define GR_CONNECTOVERRIDE 0x10
39373 +#define GR_SOCK_FAMILY 0x20
39374 +
39375 +static const char * gr_protocols[IPPROTO_MAX] = {
39376 + "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
39377 + "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
39378 + "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
39379 + "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
39380 + "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
39381 + "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
39382 + "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
39383 + "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
39384 + "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
39385 + "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
39386 + "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
39387 + "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
39388 + "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
39389 + "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
39390 + "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
39391 + "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
39392 + "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
39393 + "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
39394 + "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
39395 + "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
39396 + "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
39397 + "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
39398 + "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
39399 + "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
39400 + "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
39401 + "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
39402 + "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
39403 + "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
39404 + "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
39405 + "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
39406 + "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
39407 + "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
39408 + };
39409 +
39410 +static const char * gr_socktypes[SOCK_MAX] = {
39411 + "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
39412 + "unknown:7", "unknown:8", "unknown:9", "packet"
39413 + };
39414 +
39415 +static const char * gr_sockfamilies[AF_MAX+1] = {
39416 + "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
39417 + "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
39418 + "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "tipc", "bluetooth",
39419 + "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
39420 + };
39421 +
39422 +const char *
39423 +gr_proto_to_name(unsigned char proto)
39424 +{
39425 + return gr_protocols[proto];
39426 +}
39427 +
39428 +const char *
39429 +gr_socktype_to_name(unsigned char type)
39430 +{
39431 + return gr_socktypes[type];
39432 +}
39433 +
39434 +const char *
39435 +gr_sockfamily_to_name(unsigned char family)
39436 +{
39437 + return gr_sockfamilies[family];
39438 +}
39439 +
39440 +int
39441 +gr_search_socket(const int domain, const int type, const int protocol)
39442 +{
39443 + struct acl_subject_label *curr;
39444 + const struct cred *cred = current_cred();
39445 +
39446 + if (unlikely(!gr_acl_is_enabled()))
39447 + goto exit;
39448 +
39449 + if ((domain < 0) || (type < 0) || (protocol < 0) ||
39450 + (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
39451 + goto exit; // let the kernel handle it
39452 +
39453 + curr = current->acl;
39454 +
39455 + if (curr->sock_families[domain / 32] & (1 << (domain % 32))) {
39456 + /* the family is allowed, if this is PF_INET allow it only if
39457 + the extra sock type/protocol checks pass */
39458 + if (domain == PF_INET)
39459 + goto inet_check;
39460 + goto exit;
39461 + } else {
39462 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
39463 + __u32 fakeip = 0;
39464 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
39465 + current->role->roletype, cred->uid,
39466 + cred->gid, current->exec_file ?
39467 + gr_to_filename(current->exec_file->f_path.dentry,
39468 + current->exec_file->f_path.mnt) :
39469 + curr->filename, curr->filename,
39470 + &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
39471 + &current->signal->saved_ip);
39472 + goto exit;
39473 + }
39474 + goto exit_fail;
39475 + }
39476 +
39477 +inet_check:
39478 + /* the rest of this checking is for IPv4 only */
39479 + if (!curr->ips)
39480 + goto exit;
39481 +
39482 + if ((curr->ip_type & (1 << type)) &&
39483 + (curr->ip_proto[protocol / 32] & (1 << (protocol % 32))))
39484 + goto exit;
39485 +
39486 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
39487 + /* we don't place acls on raw sockets , and sometimes
39488 + dgram/ip sockets are opened for ioctl and not
39489 + bind/connect, so we'll fake a bind learn log */
39490 + if (type == SOCK_RAW || type == SOCK_PACKET) {
39491 + __u32 fakeip = 0;
39492 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
39493 + current->role->roletype, cred->uid,
39494 + cred->gid, current->exec_file ?
39495 + gr_to_filename(current->exec_file->f_path.dentry,
39496 + current->exec_file->f_path.mnt) :
39497 + curr->filename, curr->filename,
39498 + &fakeip, 0, type,
39499 + protocol, GR_CONNECT, &current->signal->saved_ip);
39500 + } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
39501 + __u32 fakeip = 0;
39502 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
39503 + current->role->roletype, cred->uid,
39504 + cred->gid, current->exec_file ?
39505 + gr_to_filename(current->exec_file->f_path.dentry,
39506 + current->exec_file->f_path.mnt) :
39507 + curr->filename, curr->filename,
39508 + &fakeip, 0, type,
39509 + protocol, GR_BIND, &current->signal->saved_ip);
39510 + }
39511 + /* we'll log when they use connect or bind */
39512 + goto exit;
39513 + }
39514 +
39515 +exit_fail:
39516 + if (domain == PF_INET)
39517 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
39518 + gr_socktype_to_name(type), gr_proto_to_name(protocol));
39519 + else
39520 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
39521 + gr_socktype_to_name(type), protocol);
39522 +
39523 + return 0;
39524 +exit:
39525 + return 1;
39526 +}
39527 +
39528 +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)
39529 +{
39530 + if ((ip->mode & mode) &&
39531 + (ip_port >= ip->low) &&
39532 + (ip_port <= ip->high) &&
39533 + ((ntohl(ip_addr) & our_netmask) ==
39534 + (ntohl(our_addr) & our_netmask))
39535 + && (ip->proto[protocol / 32] & (1 << (protocol % 32)))
39536 + && (ip->type & (1 << type))) {
39537 + if (ip->mode & GR_INVERT)
39538 + return 2; // specifically denied
39539 + else
39540 + return 1; // allowed
39541 + }
39542 +
39543 + return 0; // not specifically allowed, may continue parsing
39544 +}
39545 +
39546 +static int
39547 +gr_search_connectbind(const int full_mode, struct sock *sk,
39548 + struct sockaddr_in *addr, const int type)
39549 +{
39550 + char iface[IFNAMSIZ] = {0};
39551 + struct acl_subject_label *curr;
39552 + struct acl_ip_label *ip;
39553 + struct inet_sock *isk;
39554 + struct net_device *dev;
39555 + struct in_device *idev;
39556 + unsigned long i;
39557 + int ret;
39558 + int mode = full_mode & (GR_BIND | GR_CONNECT);
39559 + __u32 ip_addr = 0;
39560 + __u32 our_addr;
39561 + __u32 our_netmask;
39562 + char *p;
39563 + __u16 ip_port = 0;
39564 + const struct cred *cred = current_cred();
39565 +
39566 + if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
39567 + return 0;
39568 +
39569 + curr = current->acl;
39570 + isk = inet_sk(sk);
39571 +
39572 + /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
39573 + if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
39574 + addr->sin_addr.s_addr = curr->inaddr_any_override;
39575 + if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
39576 + struct sockaddr_in saddr;
39577 + int err;
39578 +
39579 + saddr.sin_family = AF_INET;
39580 + saddr.sin_addr.s_addr = curr->inaddr_any_override;
39581 + saddr.sin_port = isk->inet_sport;
39582 +
39583 + err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
39584 + if (err)
39585 + return err;
39586 +
39587 + err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
39588 + if (err)
39589 + return err;
39590 + }
39591 +
39592 + if (!curr->ips)
39593 + return 0;
39594 +
39595 + ip_addr = addr->sin_addr.s_addr;
39596 + ip_port = ntohs(addr->sin_port);
39597 +
39598 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
39599 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
39600 + current->role->roletype, cred->uid,
39601 + cred->gid, current->exec_file ?
39602 + gr_to_filename(current->exec_file->f_path.dentry,
39603 + current->exec_file->f_path.mnt) :
39604 + curr->filename, curr->filename,
39605 + &ip_addr, ip_port, type,
39606 + sk->sk_protocol, mode, &current->signal->saved_ip);
39607 + return 0;
39608 + }
39609 +
39610 + for (i = 0; i < curr->ip_num; i++) {
39611 + ip = *(curr->ips + i);
39612 + if (ip->iface != NULL) {
39613 + strncpy(iface, ip->iface, IFNAMSIZ - 1);
39614 + p = strchr(iface, ':');
39615 + if (p != NULL)
39616 + *p = '\0';
39617 + dev = dev_get_by_name(sock_net(sk), iface);
39618 + if (dev == NULL)
39619 + continue;
39620 + idev = in_dev_get(dev);
39621 + if (idev == NULL) {
39622 + dev_put(dev);
39623 + continue;
39624 + }
39625 + rcu_read_lock();
39626 + for_ifa(idev) {
39627 + if (!strcmp(ip->iface, ifa->ifa_label)) {
39628 + our_addr = ifa->ifa_address;
39629 + our_netmask = 0xffffffff;
39630 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
39631 + if (ret == 1) {
39632 + rcu_read_unlock();
39633 + in_dev_put(idev);
39634 + dev_put(dev);
39635 + return 0;
39636 + } else if (ret == 2) {
39637 + rcu_read_unlock();
39638 + in_dev_put(idev);
39639 + dev_put(dev);
39640 + goto denied;
39641 + }
39642 + }
39643 + } endfor_ifa(idev);
39644 + rcu_read_unlock();
39645 + in_dev_put(idev);
39646 + dev_put(dev);
39647 + } else {
39648 + our_addr = ip->addr;
39649 + our_netmask = ip->netmask;
39650 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
39651 + if (ret == 1)
39652 + return 0;
39653 + else if (ret == 2)
39654 + goto denied;
39655 + }
39656 + }
39657 +
39658 +denied:
39659 + if (mode == GR_BIND)
39660 + 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));
39661 + else if (mode == GR_CONNECT)
39662 + 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));
39663 +
39664 + return -EACCES;
39665 +}
39666 +
39667 +int
39668 +gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
39669 +{
39670 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
39671 +}
39672 +
39673 +int
39674 +gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
39675 +{
39676 + return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
39677 +}
39678 +
39679 +int gr_search_listen(struct socket *sock)
39680 +{
39681 + struct sock *sk = sock->sk;
39682 + struct sockaddr_in addr;
39683 +
39684 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
39685 + addr.sin_port = inet_sk(sk)->inet_sport;
39686 +
39687 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
39688 +}
39689 +
39690 +int gr_search_accept(struct socket *sock)
39691 +{
39692 + struct sock *sk = sock->sk;
39693 + struct sockaddr_in addr;
39694 +
39695 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
39696 + addr.sin_port = inet_sk(sk)->inet_sport;
39697 +
39698 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
39699 +}
39700 +
39701 +int
39702 +gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
39703 +{
39704 + if (addr)
39705 + return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
39706 + else {
39707 + struct sockaddr_in sin;
39708 + const struct inet_sock *inet = inet_sk(sk);
39709 +
39710 + sin.sin_addr.s_addr = inet->inet_daddr;
39711 + sin.sin_port = inet->inet_dport;
39712 +
39713 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
39714 + }
39715 +}
39716 +
39717 +int
39718 +gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
39719 +{
39720 + struct sockaddr_in sin;
39721 +
39722 + if (unlikely(skb->len < sizeof (struct udphdr)))
39723 + return 0; // skip this packet
39724 +
39725 + sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
39726 + sin.sin_port = udp_hdr(skb)->source;
39727 +
39728 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
39729 +}
39730 diff -urNp linux-2.6.37/grsecurity/gracl_learn.c linux-2.6.37/grsecurity/gracl_learn.c
39731 --- linux-2.6.37/grsecurity/gracl_learn.c 1969-12-31 19:00:00.000000000 -0500
39732 +++ linux-2.6.37/grsecurity/gracl_learn.c 2011-01-17 02:41:02.000000000 -0500
39733 @@ -0,0 +1,211 @@
39734 +#include <linux/kernel.h>
39735 +#include <linux/mm.h>
39736 +#include <linux/sched.h>
39737 +#include <linux/poll.h>
39738 +#include <linux/smp_lock.h>
39739 +#include <linux/string.h>
39740 +#include <linux/file.h>
39741 +#include <linux/types.h>
39742 +#include <linux/vmalloc.h>
39743 +#include <linux/grinternal.h>
39744 +
39745 +extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
39746 + size_t count, loff_t *ppos);
39747 +extern int gr_acl_is_enabled(void);
39748 +
39749 +static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
39750 +static int gr_learn_attached;
39751 +
39752 +/* use a 512k buffer */
39753 +#define LEARN_BUFFER_SIZE (512 * 1024)
39754 +
39755 +static DEFINE_SPINLOCK(gr_learn_lock);
39756 +static DEFINE_MUTEX(gr_learn_user_mutex);
39757 +
39758 +/* we need to maintain two buffers, so that the kernel context of grlearn
39759 + uses a semaphore around the userspace copying, and the other kernel contexts
39760 + use a spinlock when copying into the buffer, since they cannot sleep
39761 +*/
39762 +static char *learn_buffer;
39763 +static char *learn_buffer_user;
39764 +static int learn_buffer_len;
39765 +static int learn_buffer_user_len;
39766 +
39767 +static ssize_t
39768 +read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
39769 +{
39770 + DECLARE_WAITQUEUE(wait, current);
39771 + ssize_t retval = 0;
39772 +
39773 + add_wait_queue(&learn_wait, &wait);
39774 + set_current_state(TASK_INTERRUPTIBLE);
39775 + do {
39776 + mutex_lock(&gr_learn_user_mutex);
39777 + spin_lock(&gr_learn_lock);
39778 + if (learn_buffer_len)
39779 + break;
39780 + spin_unlock(&gr_learn_lock);
39781 + mutex_unlock(&gr_learn_user_mutex);
39782 + if (file->f_flags & O_NONBLOCK) {
39783 + retval = -EAGAIN;
39784 + goto out;
39785 + }
39786 + if (signal_pending(current)) {
39787 + retval = -ERESTARTSYS;
39788 + goto out;
39789 + }
39790 +
39791 + schedule();
39792 + } while (1);
39793 +
39794 + memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
39795 + learn_buffer_user_len = learn_buffer_len;
39796 + retval = learn_buffer_len;
39797 + learn_buffer_len = 0;
39798 +
39799 + spin_unlock(&gr_learn_lock);
39800 +
39801 + if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
39802 + retval = -EFAULT;
39803 +
39804 + mutex_unlock(&gr_learn_user_mutex);
39805 +out:
39806 + set_current_state(TASK_RUNNING);
39807 + remove_wait_queue(&learn_wait, &wait);
39808 + return retval;
39809 +}
39810 +
39811 +static unsigned int
39812 +poll_learn(struct file * file, poll_table * wait)
39813 +{
39814 + poll_wait(file, &learn_wait, wait);
39815 +
39816 + if (learn_buffer_len)
39817 + return (POLLIN | POLLRDNORM);
39818 +
39819 + return 0;
39820 +}
39821 +
39822 +void
39823 +gr_clear_learn_entries(void)
39824 +{
39825 + char *tmp;
39826 +
39827 + mutex_lock(&gr_learn_user_mutex);
39828 + if (learn_buffer != NULL) {
39829 + spin_lock(&gr_learn_lock);
39830 + tmp = learn_buffer;
39831 + learn_buffer = NULL;
39832 + spin_unlock(&gr_learn_lock);
39833 + vfree(learn_buffer);
39834 + }
39835 + if (learn_buffer_user != NULL) {
39836 + vfree(learn_buffer_user);
39837 + learn_buffer_user = NULL;
39838 + }
39839 + learn_buffer_len = 0;
39840 + mutex_unlock(&gr_learn_user_mutex);
39841 +
39842 + return;
39843 +}
39844 +
39845 +void
39846 +gr_add_learn_entry(const char *fmt, ...)
39847 +{
39848 + va_list args;
39849 + unsigned int len;
39850 +
39851 + if (!gr_learn_attached)
39852 + return;
39853 +
39854 + spin_lock(&gr_learn_lock);
39855 +
39856 + /* leave a gap at the end so we know when it's "full" but don't have to
39857 + compute the exact length of the string we're trying to append
39858 + */
39859 + if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
39860 + spin_unlock(&gr_learn_lock);
39861 + wake_up_interruptible(&learn_wait);
39862 + return;
39863 + }
39864 + if (learn_buffer == NULL) {
39865 + spin_unlock(&gr_learn_lock);
39866 + return;
39867 + }
39868 +
39869 + va_start(args, fmt);
39870 + len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
39871 + va_end(args);
39872 +
39873 + learn_buffer_len += len + 1;
39874 +
39875 + spin_unlock(&gr_learn_lock);
39876 + wake_up_interruptible(&learn_wait);
39877 +
39878 + return;
39879 +}
39880 +
39881 +static int
39882 +open_learn(struct inode *inode, struct file *file)
39883 +{
39884 + if (file->f_mode & FMODE_READ && gr_learn_attached)
39885 + return -EBUSY;
39886 + if (file->f_mode & FMODE_READ) {
39887 + int retval = 0;
39888 + mutex_lock(&gr_learn_user_mutex);
39889 + if (learn_buffer == NULL)
39890 + learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
39891 + if (learn_buffer_user == NULL)
39892 + learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
39893 + if (learn_buffer == NULL) {
39894 + retval = -ENOMEM;
39895 + goto out_error;
39896 + }
39897 + if (learn_buffer_user == NULL) {
39898 + retval = -ENOMEM;
39899 + goto out_error;
39900 + }
39901 + learn_buffer_len = 0;
39902 + learn_buffer_user_len = 0;
39903 + gr_learn_attached = 1;
39904 +out_error:
39905 + mutex_unlock(&gr_learn_user_mutex);
39906 + return retval;
39907 + }
39908 + return 0;
39909 +}
39910 +
39911 +static int
39912 +close_learn(struct inode *inode, struct file *file)
39913 +{
39914 + char *tmp;
39915 +
39916 + if (file->f_mode & FMODE_READ) {
39917 + mutex_lock(&gr_learn_user_mutex);
39918 + if (learn_buffer != NULL) {
39919 + spin_lock(&gr_learn_lock);
39920 + tmp = learn_buffer;
39921 + learn_buffer = NULL;
39922 + spin_unlock(&gr_learn_lock);
39923 + vfree(tmp);
39924 + }
39925 + if (learn_buffer_user != NULL) {
39926 + vfree(learn_buffer_user);
39927 + learn_buffer_user = NULL;
39928 + }
39929 + learn_buffer_len = 0;
39930 + learn_buffer_user_len = 0;
39931 + gr_learn_attached = 0;
39932 + mutex_unlock(&gr_learn_user_mutex);
39933 + }
39934 +
39935 + return 0;
39936 +}
39937 +
39938 +const struct file_operations grsec_fops = {
39939 + .read = read_learn,
39940 + .write = write_grsec_handler,
39941 + .open = open_learn,
39942 + .release = close_learn,
39943 + .poll = poll_learn,
39944 +};
39945 diff -urNp linux-2.6.37/grsecurity/gracl_res.c linux-2.6.37/grsecurity/gracl_res.c
39946 --- linux-2.6.37/grsecurity/gracl_res.c 1969-12-31 19:00:00.000000000 -0500
39947 +++ linux-2.6.37/grsecurity/gracl_res.c 2011-01-17 02:41:02.000000000 -0500
39948 @@ -0,0 +1,68 @@
39949 +#include <linux/kernel.h>
39950 +#include <linux/sched.h>
39951 +#include <linux/gracl.h>
39952 +#include <linux/grinternal.h>
39953 +
39954 +static const char *restab_log[] = {
39955 + [RLIMIT_CPU] = "RLIMIT_CPU",
39956 + [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
39957 + [RLIMIT_DATA] = "RLIMIT_DATA",
39958 + [RLIMIT_STACK] = "RLIMIT_STACK",
39959 + [RLIMIT_CORE] = "RLIMIT_CORE",
39960 + [RLIMIT_RSS] = "RLIMIT_RSS",
39961 + [RLIMIT_NPROC] = "RLIMIT_NPROC",
39962 + [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
39963 + [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
39964 + [RLIMIT_AS] = "RLIMIT_AS",
39965 + [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
39966 + [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
39967 + [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
39968 + [RLIMIT_NICE] = "RLIMIT_NICE",
39969 + [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
39970 + [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
39971 + [GR_CRASH_RES] = "RLIMIT_CRASH"
39972 +};
39973 +
39974 +void
39975 +gr_log_resource(const struct task_struct *task,
39976 + const int res, const unsigned long wanted, const int gt)
39977 +{
39978 + const struct cred *cred;
39979 + unsigned long rlim;
39980 +
39981 + if (!gr_acl_is_enabled() && !grsec_resource_logging)
39982 + return;
39983 +
39984 + // not yet supported resource
39985 + if (unlikely(!restab_log[res]))
39986 + return;
39987 +
39988 + if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
39989 + rlim = task_rlimit_max(task, res);
39990 + else
39991 + rlim = task_rlimit(task, res);
39992 +
39993 + if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
39994 + return;
39995 +
39996 + rcu_read_lock();
39997 + cred = __task_cred(task);
39998 +
39999 + if (res == RLIMIT_NPROC &&
40000 + (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
40001 + cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
40002 + goto out_rcu_unlock;
40003 + else if (res == RLIMIT_MEMLOCK &&
40004 + cap_raised(cred->cap_effective, CAP_IPC_LOCK))
40005 + goto out_rcu_unlock;
40006 + else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
40007 + goto out_rcu_unlock;
40008 + rcu_read_unlock();
40009 +
40010 + gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
40011 +
40012 + return;
40013 +out_rcu_unlock:
40014 + rcu_read_unlock();
40015 + return;
40016 +}
40017 diff -urNp linux-2.6.37/grsecurity/gracl_segv.c linux-2.6.37/grsecurity/gracl_segv.c
40018 --- linux-2.6.37/grsecurity/gracl_segv.c 1969-12-31 19:00:00.000000000 -0500
40019 +++ linux-2.6.37/grsecurity/gracl_segv.c 2011-01-17 02:41:02.000000000 -0500
40020 @@ -0,0 +1,310 @@
40021 +#include <linux/kernel.h>
40022 +#include <linux/mm.h>
40023 +#include <asm/uaccess.h>
40024 +#include <asm/errno.h>
40025 +#include <asm/mman.h>
40026 +#include <net/sock.h>
40027 +#include <linux/file.h>
40028 +#include <linux/fs.h>
40029 +#include <linux/net.h>
40030 +#include <linux/in.h>
40031 +#include <linux/smp_lock.h>
40032 +#include <linux/slab.h>
40033 +#include <linux/types.h>
40034 +#include <linux/sched.h>
40035 +#include <linux/timer.h>
40036 +#include <linux/gracl.h>
40037 +#include <linux/grsecurity.h>
40038 +#include <linux/grinternal.h>
40039 +
40040 +static struct crash_uid *uid_set;
40041 +static unsigned short uid_used;
40042 +static DEFINE_SPINLOCK(gr_uid_lock);
40043 +extern rwlock_t gr_inode_lock;
40044 +extern struct acl_subject_label *
40045 + lookup_acl_subj_label(const ino_t inode, const dev_t dev,
40046 + struct acl_role_label *role);
40047 +extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
40048 +
40049 +int
40050 +gr_init_uidset(void)
40051 +{
40052 + uid_set =
40053 + kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
40054 + uid_used = 0;
40055 +
40056 + return uid_set ? 1 : 0;
40057 +}
40058 +
40059 +void
40060 +gr_free_uidset(void)
40061 +{
40062 + if (uid_set)
40063 + kfree(uid_set);
40064 +
40065 + return;
40066 +}
40067 +
40068 +int
40069 +gr_find_uid(const uid_t uid)
40070 +{
40071 + struct crash_uid *tmp = uid_set;
40072 + uid_t buid;
40073 + int low = 0, high = uid_used - 1, mid;
40074 +
40075 + while (high >= low) {
40076 + mid = (low + high) >> 1;
40077 + buid = tmp[mid].uid;
40078 + if (buid == uid)
40079 + return mid;
40080 + if (buid > uid)
40081 + high = mid - 1;
40082 + if (buid < uid)
40083 + low = mid + 1;
40084 + }
40085 +
40086 + return -1;
40087 +}
40088 +
40089 +static __inline__ void
40090 +gr_insertsort(void)
40091 +{
40092 + unsigned short i, j;
40093 + struct crash_uid index;
40094 +
40095 + for (i = 1; i < uid_used; i++) {
40096 + index = uid_set[i];
40097 + j = i;
40098 + while ((j > 0) && uid_set[j - 1].uid > index.uid) {
40099 + uid_set[j] = uid_set[j - 1];
40100 + j--;
40101 + }
40102 + uid_set[j] = index;
40103 + }
40104 +
40105 + return;
40106 +}
40107 +
40108 +static __inline__ void
40109 +gr_insert_uid(const uid_t uid, const unsigned long expires)
40110 +{
40111 + int loc;
40112 +
40113 + if (uid_used == GR_UIDTABLE_MAX)
40114 + return;
40115 +
40116 + loc = gr_find_uid(uid);
40117 +
40118 + if (loc >= 0) {
40119 + uid_set[loc].expires = expires;
40120 + return;
40121 + }
40122 +
40123 + uid_set[uid_used].uid = uid;
40124 + uid_set[uid_used].expires = expires;
40125 + uid_used++;
40126 +
40127 + gr_insertsort();
40128 +
40129 + return;
40130 +}
40131 +
40132 +void
40133 +gr_remove_uid(const unsigned short loc)
40134 +{
40135 + unsigned short i;
40136 +
40137 + for (i = loc + 1; i < uid_used; i++)
40138 + uid_set[i - 1] = uid_set[i];
40139 +
40140 + uid_used--;
40141 +
40142 + return;
40143 +}
40144 +
40145 +int
40146 +gr_check_crash_uid(const uid_t uid)
40147 +{
40148 + int loc;
40149 + int ret = 0;
40150 +
40151 + if (unlikely(!gr_acl_is_enabled()))
40152 + return 0;
40153 +
40154 + spin_lock(&gr_uid_lock);
40155 + loc = gr_find_uid(uid);
40156 +
40157 + if (loc < 0)
40158 + goto out_unlock;
40159 +
40160 + if (time_before_eq(uid_set[loc].expires, get_seconds()))
40161 + gr_remove_uid(loc);
40162 + else
40163 + ret = 1;
40164 +
40165 +out_unlock:
40166 + spin_unlock(&gr_uid_lock);
40167 + return ret;
40168 +}
40169 +
40170 +static __inline__ int
40171 +proc_is_setxid(const struct cred *cred)
40172 +{
40173 + if (cred->uid != cred->euid || cred->uid != cred->suid ||
40174 + cred->uid != cred->fsuid)
40175 + return 1;
40176 + if (cred->gid != cred->egid || cred->gid != cred->sgid ||
40177 + cred->gid != cred->fsgid)
40178 + return 1;
40179 +
40180 + return 0;
40181 +}
40182 +static __inline__ int
40183 +gr_fake_force_sig(int sig, struct task_struct *t)
40184 +{
40185 + unsigned long int flags;
40186 + int ret, blocked, ignored;
40187 + struct k_sigaction *action;
40188 +
40189 + spin_lock_irqsave(&t->sighand->siglock, flags);
40190 + action = &t->sighand->action[sig-1];
40191 + ignored = action->sa.sa_handler == SIG_IGN;
40192 + blocked = sigismember(&t->blocked, sig);
40193 + if (blocked || ignored) {
40194 + action->sa.sa_handler = SIG_DFL;
40195 + if (blocked) {
40196 + sigdelset(&t->blocked, sig);
40197 + recalc_sigpending_and_wake(t);
40198 + }
40199 + }
40200 + if (action->sa.sa_handler == SIG_DFL)
40201 + t->signal->flags &= ~SIGNAL_UNKILLABLE;
40202 + ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
40203 +
40204 + spin_unlock_irqrestore(&t->sighand->siglock, flags);
40205 +
40206 + return ret;
40207 +}
40208 +
40209 +void
40210 +gr_handle_crash(struct task_struct *task, const int sig)
40211 +{
40212 + struct acl_subject_label *curr;
40213 + struct acl_subject_label *curr2;
40214 + struct task_struct *tsk, *tsk2;
40215 + const struct cred *cred;
40216 + const struct cred *cred2;
40217 +
40218 + if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
40219 + return;
40220 +
40221 + if (unlikely(!gr_acl_is_enabled()))
40222 + return;
40223 +
40224 + curr = task->acl;
40225 +
40226 + if (!(curr->resmask & (1 << GR_CRASH_RES)))
40227 + return;
40228 +
40229 + if (time_before_eq(curr->expires, get_seconds())) {
40230 + curr->expires = 0;
40231 + curr->crashes = 0;
40232 + }
40233 +
40234 + curr->crashes++;
40235 +
40236 + if (!curr->expires)
40237 + curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
40238 +
40239 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
40240 + time_after(curr->expires, get_seconds())) {
40241 + rcu_read_lock();
40242 + cred = __task_cred(task);
40243 + if (cred->uid && proc_is_setxid(cred)) {
40244 + gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
40245 + spin_lock(&gr_uid_lock);
40246 + gr_insert_uid(cred->uid, curr->expires);
40247 + spin_unlock(&gr_uid_lock);
40248 + curr->expires = 0;
40249 + curr->crashes = 0;
40250 + read_lock(&tasklist_lock);
40251 + do_each_thread(tsk2, tsk) {
40252 + cred2 = __task_cred(tsk);
40253 + if (tsk != task && cred2->uid == cred->uid)
40254 + gr_fake_force_sig(SIGKILL, tsk);
40255 + } while_each_thread(tsk2, tsk);
40256 + read_unlock(&tasklist_lock);
40257 + } else {
40258 + gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
40259 + read_lock(&tasklist_lock);
40260 + do_each_thread(tsk2, tsk) {
40261 + if (likely(tsk != task)) {
40262 + curr2 = tsk->acl;
40263 +
40264 + if (curr2->device == curr->device &&
40265 + curr2->inode == curr->inode)
40266 + gr_fake_force_sig(SIGKILL, tsk);
40267 + }
40268 + } while_each_thread(tsk2, tsk);
40269 + read_unlock(&tasklist_lock);
40270 + }
40271 + rcu_read_unlock();
40272 + }
40273 +
40274 + return;
40275 +}
40276 +
40277 +int
40278 +gr_check_crash_exec(const struct file *filp)
40279 +{
40280 + struct acl_subject_label *curr;
40281 +
40282 + if (unlikely(!gr_acl_is_enabled()))
40283 + return 0;
40284 +
40285 + read_lock(&gr_inode_lock);
40286 + curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
40287 + filp->f_path.dentry->d_inode->i_sb->s_dev,
40288 + current->role);
40289 + read_unlock(&gr_inode_lock);
40290 +
40291 + if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) ||
40292 + (!curr->crashes && !curr->expires))
40293 + return 0;
40294 +
40295 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
40296 + time_after(curr->expires, get_seconds()))
40297 + return 1;
40298 + else if (time_before_eq(curr->expires, get_seconds())) {
40299 + curr->crashes = 0;
40300 + curr->expires = 0;
40301 + }
40302 +
40303 + return 0;
40304 +}
40305 +
40306 +void
40307 +gr_handle_alertkill(struct task_struct *task)
40308 +{
40309 + struct acl_subject_label *curracl;
40310 + __u32 curr_ip;
40311 + struct task_struct *p, *p2;
40312 +
40313 + if (unlikely(!gr_acl_is_enabled()))
40314 + return;
40315 +
40316 + curracl = task->acl;
40317 + curr_ip = task->signal->curr_ip;
40318 +
40319 + if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
40320 + read_lock(&tasklist_lock);
40321 + do_each_thread(p2, p) {
40322 + if (p->signal->curr_ip == curr_ip)
40323 + gr_fake_force_sig(SIGKILL, p);
40324 + } while_each_thread(p2, p);
40325 + read_unlock(&tasklist_lock);
40326 + } else if (curracl->mode & GR_KILLPROC)
40327 + gr_fake_force_sig(SIGKILL, task);
40328 +
40329 + return;
40330 +}
40331 diff -urNp linux-2.6.37/grsecurity/gracl_shm.c linux-2.6.37/grsecurity/gracl_shm.c
40332 --- linux-2.6.37/grsecurity/gracl_shm.c 1969-12-31 19:00:00.000000000 -0500
40333 +++ linux-2.6.37/grsecurity/gracl_shm.c 2011-01-17 02:41:02.000000000 -0500
40334 @@ -0,0 +1,40 @@
40335 +#include <linux/kernel.h>
40336 +#include <linux/mm.h>
40337 +#include <linux/sched.h>
40338 +#include <linux/file.h>
40339 +#include <linux/ipc.h>
40340 +#include <linux/gracl.h>
40341 +#include <linux/grsecurity.h>
40342 +#include <linux/grinternal.h>
40343 +
40344 +int
40345 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
40346 + const time_t shm_createtime, const uid_t cuid, const int shmid)
40347 +{
40348 + struct task_struct *task;
40349 +
40350 + if (!gr_acl_is_enabled())
40351 + return 1;
40352 +
40353 + rcu_read_lock();
40354 + read_lock(&tasklist_lock);
40355 +
40356 + task = find_task_by_vpid(shm_cprid);
40357 +
40358 + if (unlikely(!task))
40359 + task = find_task_by_vpid(shm_lapid);
40360 +
40361 + if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
40362 + (task->pid == shm_lapid)) &&
40363 + (task->acl->mode & GR_PROTSHM) &&
40364 + (task->acl != current->acl))) {
40365 + read_unlock(&tasklist_lock);
40366 + rcu_read_unlock();
40367 + gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, cuid, shm_cprid, shmid);
40368 + return 0;
40369 + }
40370 + read_unlock(&tasklist_lock);
40371 + rcu_read_unlock();
40372 +
40373 + return 1;
40374 +}
40375 diff -urNp linux-2.6.37/grsecurity/grsec_chdir.c linux-2.6.37/grsecurity/grsec_chdir.c
40376 --- linux-2.6.37/grsecurity/grsec_chdir.c 1969-12-31 19:00:00.000000000 -0500
40377 +++ linux-2.6.37/grsecurity/grsec_chdir.c 2011-01-17 02:41:02.000000000 -0500
40378 @@ -0,0 +1,19 @@
40379 +#include <linux/kernel.h>
40380 +#include <linux/sched.h>
40381 +#include <linux/fs.h>
40382 +#include <linux/file.h>
40383 +#include <linux/grsecurity.h>
40384 +#include <linux/grinternal.h>
40385 +
40386 +void
40387 +gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
40388 +{
40389 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
40390 + if ((grsec_enable_chdir && grsec_enable_group &&
40391 + in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
40392 + !grsec_enable_group)) {
40393 + gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
40394 + }
40395 +#endif
40396 + return;
40397 +}
40398 diff -urNp linux-2.6.37/grsecurity/grsec_chroot.c linux-2.6.37/grsecurity/grsec_chroot.c
40399 --- linux-2.6.37/grsecurity/grsec_chroot.c 1969-12-31 19:00:00.000000000 -0500
40400 +++ linux-2.6.37/grsecurity/grsec_chroot.c 2011-01-17 02:41:02.000000000 -0500
40401 @@ -0,0 +1,373 @@
40402 +#include <linux/kernel.h>
40403 +#include <linux/module.h>
40404 +#include <linux/sched.h>
40405 +#include <linux/file.h>
40406 +#include <linux/fs.h>
40407 +#include <linux/mount.h>
40408 +#include <linux/types.h>
40409 +#include <linux/pid_namespace.h>
40410 +#include <linux/grsecurity.h>
40411 +#include <linux/grinternal.h>
40412 +
40413 +void gr_set_chroot_entries(struct task_struct *task, struct path *path)
40414 +{
40415 +#ifdef CONFIG_GRKERNSEC
40416 + if (task->pid > 1 && path->dentry != init_task.fs->root.dentry &&
40417 + path->dentry != task->nsproxy->mnt_ns->root->mnt_root)
40418 + task->gr_is_chrooted = 1;
40419 + else
40420 + task->gr_is_chrooted = 0;
40421 +
40422 + task->gr_chroot_dentry = path->dentry;
40423 +#endif
40424 + return;
40425 +}
40426 +
40427 +void gr_clear_chroot_entries(struct task_struct *task)
40428 +{
40429 +#ifdef CONFIG_GRKERNSEC
40430 + task->gr_is_chrooted = 0;
40431 + task->gr_chroot_dentry = NULL;
40432 +#endif
40433 + return;
40434 +}
40435 +
40436 +int
40437 +gr_handle_chroot_unix(struct pid *pid)
40438 +{
40439 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
40440 + struct task_struct *p;
40441 +
40442 + if (unlikely(!grsec_enable_chroot_unix))
40443 + return 1;
40444 +
40445 + if (likely(!proc_is_chrooted(current)))
40446 + return 1;
40447 +
40448 + rcu_read_lock();
40449 + read_lock(&tasklist_lock);
40450 + p = pid_task(pid, PIDTYPE_PID);
40451 + if (unlikely(!have_same_root(current, p))) {
40452 + read_unlock(&tasklist_lock);
40453 + rcu_read_unlock();
40454 + gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
40455 + return 0;
40456 + }
40457 + read_unlock(&tasklist_lock);
40458 + rcu_read_unlock();
40459 +#endif
40460 + return 1;
40461 +}
40462 +
40463 +int
40464 +gr_handle_chroot_nice(void)
40465 +{
40466 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
40467 + if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
40468 + gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
40469 + return -EPERM;
40470 + }
40471 +#endif
40472 + return 0;
40473 +}
40474 +
40475 +int
40476 +gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
40477 +{
40478 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
40479 + if (grsec_enable_chroot_nice && (niceval < task_nice(p))
40480 + && proc_is_chrooted(current)) {
40481 + gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, p->pid);
40482 + return -EACCES;
40483 + }
40484 +#endif
40485 + return 0;
40486 +}
40487 +
40488 +int
40489 +gr_handle_chroot_rawio(const struct inode *inode)
40490 +{
40491 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
40492 + if (grsec_enable_chroot_caps && proc_is_chrooted(current) &&
40493 + inode && S_ISBLK(inode->i_mode) && !capable(CAP_SYS_RAWIO))
40494 + return 1;
40495 +#endif
40496 + return 0;
40497 +}
40498 +
40499 +int
40500 +gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
40501 +{
40502 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
40503 + struct task_struct *p;
40504 + int ret = 0;
40505 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
40506 + return ret;
40507 +
40508 + read_lock(&tasklist_lock);
40509 + do_each_pid_task(pid, type, p) {
40510 + if (!have_same_root(current, p)) {
40511 + ret = 1;
40512 + goto out;
40513 + }
40514 + } while_each_pid_task(pid, type, p);
40515 +out:
40516 + read_unlock(&tasklist_lock);
40517 + return ret;
40518 +#endif
40519 + return 0;
40520 +}
40521 +
40522 +int
40523 +gr_pid_is_chrooted(struct task_struct *p)
40524 +{
40525 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
40526 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
40527 + return 0;
40528 +
40529 + if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
40530 + !have_same_root(current, p)) {
40531 + return 1;
40532 + }
40533 +#endif
40534 + return 0;
40535 +}
40536 +
40537 +EXPORT_SYMBOL(gr_pid_is_chrooted);
40538 +
40539 +#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
40540 +int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
40541 +{
40542 + struct dentry *dentry = (struct dentry *)u_dentry;
40543 + struct vfsmount *mnt = (struct vfsmount *)u_mnt;
40544 + struct path realroot, currentroot;
40545 + struct task_struct *reaper = &init_task;
40546 + int ret = 1;
40547 +
40548 + get_fs_root(reaper->fs, &realroot);
40549 + get_fs_root(current->fs, &currentroot);
40550 +
40551 + spin_lock(&dcache_lock);
40552 + for (;;) {
40553 + if (unlikely((dentry == realroot.dentry && mnt == realroot.mnt)
40554 + || (dentry == currentroot.dentry && mnt == currentroot.mnt)))
40555 + break;
40556 + if (unlikely(dentry == mnt->mnt_root || IS_ROOT(dentry))) {
40557 + if (mnt->mnt_parent == mnt)
40558 + break;
40559 + dentry = mnt->mnt_mountpoint;
40560 + mnt = mnt->mnt_parent;
40561 + continue;
40562 + }
40563 + dentry = dentry->d_parent;
40564 + }
40565 + spin_unlock(&dcache_lock);
40566 +
40567 + path_put(&currentroot);
40568 +
40569 + /* access is outside of chroot */
40570 + if (dentry == realroot.dentry && mnt == realroot.mnt)
40571 + ret = 0;
40572 +
40573 + path_put(&realroot);
40574 + return ret;
40575 +}
40576 +#endif
40577 +
40578 +int
40579 +gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
40580 +{
40581 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
40582 + if (!grsec_enable_chroot_fchdir)
40583 + return 1;
40584 +
40585 + if (!proc_is_chrooted(current))
40586 + return 1;
40587 + else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
40588 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
40589 + return 0;
40590 + }
40591 +#endif
40592 + return 1;
40593 +}
40594 +
40595 +int
40596 +gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
40597 + const time_t shm_createtime)
40598 +{
40599 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
40600 + struct pid *pid = NULL;
40601 + time_t starttime;
40602 +
40603 + if (unlikely(!grsec_enable_chroot_shmat))
40604 + return 1;
40605 +
40606 + if (likely(!proc_is_chrooted(current)))
40607 + return 1;
40608 +
40609 + rcu_read_lock();
40610 + read_lock(&tasklist_lock);
40611 +
40612 + pid = find_vpid(shm_cprid);
40613 + if (pid) {
40614 + struct task_struct *p;
40615 + p = pid_task(pid, PIDTYPE_PID);
40616 + starttime = p->start_time.tv_sec;
40617 + if (unlikely(!have_same_root(current, p) &&
40618 + time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime))) {
40619 + read_unlock(&tasklist_lock);
40620 + rcu_read_unlock();
40621 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
40622 + return 0;
40623 + }
40624 + } else {
40625 + pid = find_vpid(shm_lapid);
40626 + if (pid) {
40627 + struct task_struct *p;
40628 + p = pid_task(pid, PIDTYPE_PID);
40629 + if (unlikely(!have_same_root(current, p))) {
40630 + read_unlock(&tasklist_lock);
40631 + rcu_read_unlock();
40632 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
40633 + return 0;
40634 + }
40635 + }
40636 + }
40637 +
40638 + read_unlock(&tasklist_lock);
40639 + rcu_read_unlock();
40640 +#endif
40641 + return 1;
40642 +}
40643 +
40644 +void
40645 +gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
40646 +{
40647 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
40648 + if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
40649 + gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
40650 +#endif
40651 + return;
40652 +}
40653 +
40654 +int
40655 +gr_handle_chroot_mknod(const struct dentry *dentry,
40656 + const struct vfsmount *mnt, const int mode)
40657 +{
40658 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
40659 + if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
40660 + proc_is_chrooted(current)) {
40661 + gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
40662 + return -EPERM;
40663 + }
40664 +#endif
40665 + return 0;
40666 +}
40667 +
40668 +int
40669 +gr_handle_chroot_mount(const struct dentry *dentry,
40670 + const struct vfsmount *mnt, const char *dev_name)
40671 +{
40672 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
40673 + if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
40674 + gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name, dentry, mnt);
40675 + return -EPERM;
40676 + }
40677 +#endif
40678 + return 0;
40679 +}
40680 +
40681 +int
40682 +gr_handle_chroot_pivot(void)
40683 +{
40684 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
40685 + if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
40686 + gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
40687 + return -EPERM;
40688 + }
40689 +#endif
40690 + return 0;
40691 +}
40692 +
40693 +int
40694 +gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
40695 +{
40696 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
40697 + if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
40698 + !gr_is_outside_chroot(dentry, mnt)) {
40699 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
40700 + return -EPERM;
40701 + }
40702 +#endif
40703 + return 0;
40704 +}
40705 +
40706 +int
40707 +gr_handle_chroot_caps(struct path *path)
40708 +{
40709 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
40710 + if (grsec_enable_chroot_caps && current->pid > 1 && current->fs != NULL &&
40711 + (init_task.fs->root.dentry != path->dentry) &&
40712 + (current->nsproxy->mnt_ns->root->mnt_root != path->dentry)) {
40713 +
40714 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
40715 + const struct cred *old = current_cred();
40716 + struct cred *new = prepare_creds();
40717 + if (new == NULL)
40718 + return 1;
40719 +
40720 + new->cap_permitted = cap_drop(old->cap_permitted,
40721 + chroot_caps);
40722 + new->cap_inheritable = cap_drop(old->cap_inheritable,
40723 + chroot_caps);
40724 + new->cap_effective = cap_drop(old->cap_effective,
40725 + chroot_caps);
40726 +
40727 + commit_creds(new);
40728 +
40729 + return 0;
40730 + }
40731 +#endif
40732 + return 0;
40733 +}
40734 +
40735 +int
40736 +gr_handle_chroot_sysctl(const int op)
40737 +{
40738 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
40739 + if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
40740 + proc_is_chrooted(current))
40741 + return -EACCES;
40742 +#endif
40743 + return 0;
40744 +}
40745 +
40746 +void
40747 +gr_handle_chroot_chdir(struct path *path)
40748 +{
40749 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
40750 + if (grsec_enable_chroot_chdir)
40751 + set_fs_pwd(current->fs, path);
40752 +#endif
40753 + return;
40754 +}
40755 +
40756 +int
40757 +gr_handle_chroot_chmod(const struct dentry *dentry,
40758 + const struct vfsmount *mnt, const int mode)
40759 +{
40760 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
40761 + /* allow chmod +s on directories, but not files */
40762 + if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
40763 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
40764 + proc_is_chrooted(current)) {
40765 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
40766 + return -EPERM;
40767 + }
40768 +#endif
40769 + return 0;
40770 +}
40771 +
40772 +#ifdef CONFIG_SECURITY
40773 +EXPORT_SYMBOL(gr_handle_chroot_caps);
40774 +#endif
40775 diff -urNp linux-2.6.37/grsecurity/grsec_disabled.c linux-2.6.37/grsecurity/grsec_disabled.c
40776 --- linux-2.6.37/grsecurity/grsec_disabled.c 1969-12-31 19:00:00.000000000 -0500
40777 +++ linux-2.6.37/grsecurity/grsec_disabled.c 2011-01-17 02:41:02.000000000 -0500
40778 @@ -0,0 +1,442 @@
40779 +#include <linux/kernel.h>
40780 +#include <linux/module.h>
40781 +#include <linux/sched.h>
40782 +#include <linux/file.h>
40783 +#include <linux/fs.h>
40784 +#include <linux/kdev_t.h>
40785 +#include <linux/net.h>
40786 +#include <linux/in.h>
40787 +#include <linux/ip.h>
40788 +#include <linux/skbuff.h>
40789 +#include <linux/sysctl.h>
40790 +
40791 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
40792 +void
40793 +pax_set_initial_flags(struct linux_binprm *bprm)
40794 +{
40795 + return;
40796 +}
40797 +#endif
40798 +
40799 +#ifdef CONFIG_SYSCTL
40800 +__u32
40801 +gr_handle_sysctl(const struct ctl_table * table, const int op)
40802 +{
40803 + return 0;
40804 +}
40805 +#endif
40806 +
40807 +#ifdef CONFIG_TASKSTATS
40808 +int gr_is_taskstats_denied(int pid)
40809 +{
40810 + return 0;
40811 +}
40812 +#endif
40813 +
40814 +int
40815 +gr_acl_is_enabled(void)
40816 +{
40817 + return 0;
40818 +}
40819 +
40820 +int
40821 +gr_handle_rawio(const struct inode *inode)
40822 +{
40823 + return 0;
40824 +}
40825 +
40826 +void
40827 +gr_acl_handle_psacct(struct task_struct *task, const long code)
40828 +{
40829 + return;
40830 +}
40831 +
40832 +int
40833 +gr_handle_ptrace(struct task_struct *task, const long request)
40834 +{
40835 + return 0;
40836 +}
40837 +
40838 +int
40839 +gr_handle_proc_ptrace(struct task_struct *task)
40840 +{
40841 + return 0;
40842 +}
40843 +
40844 +void
40845 +gr_learn_resource(const struct task_struct *task,
40846 + const int res, const unsigned long wanted, const int gt)
40847 +{
40848 + return;
40849 +}
40850 +
40851 +int
40852 +gr_set_acls(const int type)
40853 +{
40854 + return 0;
40855 +}
40856 +
40857 +int
40858 +gr_check_hidden_task(const struct task_struct *tsk)
40859 +{
40860 + return 0;
40861 +}
40862 +
40863 +int
40864 +gr_check_protected_task(const struct task_struct *task)
40865 +{
40866 + return 0;
40867 +}
40868 +
40869 +int
40870 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
40871 +{
40872 + return 0;
40873 +}
40874 +
40875 +void
40876 +gr_copy_label(struct task_struct *tsk)
40877 +{
40878 + return;
40879 +}
40880 +
40881 +void
40882 +gr_set_pax_flags(struct task_struct *task)
40883 +{
40884 + return;
40885 +}
40886 +
40887 +int
40888 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
40889 + const int unsafe_share)
40890 +{
40891 + return 0;
40892 +}
40893 +
40894 +void
40895 +gr_handle_delete(const ino_t ino, const dev_t dev)
40896 +{
40897 + return;
40898 +}
40899 +
40900 +void
40901 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
40902 +{
40903 + return;
40904 +}
40905 +
40906 +void
40907 +gr_handle_crash(struct task_struct *task, const int sig)
40908 +{
40909 + return;
40910 +}
40911 +
40912 +int
40913 +gr_check_crash_exec(const struct file *filp)
40914 +{
40915 + return 0;
40916 +}
40917 +
40918 +int
40919 +gr_check_crash_uid(const uid_t uid)
40920 +{
40921 + return 0;
40922 +}
40923 +
40924 +void
40925 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
40926 + struct dentry *old_dentry,
40927 + struct dentry *new_dentry,
40928 + struct vfsmount *mnt, const __u8 replace)
40929 +{
40930 + return;
40931 +}
40932 +
40933 +int
40934 +gr_search_socket(const int family, const int type, const int protocol)
40935 +{
40936 + return 1;
40937 +}
40938 +
40939 +int
40940 +gr_search_connectbind(const int mode, const struct socket *sock,
40941 + const struct sockaddr_in *addr)
40942 +{
40943 + return 0;
40944 +}
40945 +
40946 +int
40947 +gr_is_capable(const int cap)
40948 +{
40949 + return 1;
40950 +}
40951 +
40952 +int
40953 +gr_is_capable_nolog(const int cap)
40954 +{
40955 + return 1;
40956 +}
40957 +
40958 +void
40959 +gr_handle_alertkill(struct task_struct *task)
40960 +{
40961 + return;
40962 +}
40963 +
40964 +__u32
40965 +gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
40966 +{
40967 + return 1;
40968 +}
40969 +
40970 +__u32
40971 +gr_acl_handle_hidden_file(const struct dentry * dentry,
40972 + const struct vfsmount * mnt)
40973 +{
40974 + return 1;
40975 +}
40976 +
40977 +__u32
40978 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
40979 + const int fmode)
40980 +{
40981 + return 1;
40982 +}
40983 +
40984 +__u32
40985 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
40986 +{
40987 + return 1;
40988 +}
40989 +
40990 +__u32
40991 +gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
40992 +{
40993 + return 1;
40994 +}
40995 +
40996 +int
40997 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
40998 + unsigned int *vm_flags)
40999 +{
41000 + return 1;
41001 +}
41002 +
41003 +__u32
41004 +gr_acl_handle_truncate(const struct dentry * dentry,
41005 + const struct vfsmount * mnt)
41006 +{
41007 + return 1;
41008 +}
41009 +
41010 +__u32
41011 +gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
41012 +{
41013 + return 1;
41014 +}
41015 +
41016 +__u32
41017 +gr_acl_handle_access(const struct dentry * dentry,
41018 + const struct vfsmount * mnt, const int fmode)
41019 +{
41020 + return 1;
41021 +}
41022 +
41023 +__u32
41024 +gr_acl_handle_fchmod(const struct dentry * dentry, const struct vfsmount * mnt,
41025 + mode_t mode)
41026 +{
41027 + return 1;
41028 +}
41029 +
41030 +__u32
41031 +gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
41032 + mode_t mode)
41033 +{
41034 + return 1;
41035 +}
41036 +
41037 +__u32
41038 +gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
41039 +{
41040 + return 1;
41041 +}
41042 +
41043 +__u32
41044 +gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
41045 +{
41046 + return 1;
41047 +}
41048 +
41049 +void
41050 +grsecurity_init(void)
41051 +{
41052 + return;
41053 +}
41054 +
41055 +__u32
41056 +gr_acl_handle_mknod(const struct dentry * new_dentry,
41057 + const struct dentry * parent_dentry,
41058 + const struct vfsmount * parent_mnt,
41059 + const int mode)
41060 +{
41061 + return 1;
41062 +}
41063 +
41064 +__u32
41065 +gr_acl_handle_mkdir(const struct dentry * new_dentry,
41066 + const struct dentry * parent_dentry,
41067 + const struct vfsmount * parent_mnt)
41068 +{
41069 + return 1;
41070 +}
41071 +
41072 +__u32
41073 +gr_acl_handle_symlink(const struct dentry * new_dentry,
41074 + const struct dentry * parent_dentry,
41075 + const struct vfsmount * parent_mnt, const char *from)
41076 +{
41077 + return 1;
41078 +}
41079 +
41080 +__u32
41081 +gr_acl_handle_link(const struct dentry * new_dentry,
41082 + const struct dentry * parent_dentry,
41083 + const struct vfsmount * parent_mnt,
41084 + const struct dentry * old_dentry,
41085 + const struct vfsmount * old_mnt, const char *to)
41086 +{
41087 + return 1;
41088 +}
41089 +
41090 +int
41091 +gr_acl_handle_rename(const struct dentry *new_dentry,
41092 + const struct dentry *parent_dentry,
41093 + const struct vfsmount *parent_mnt,
41094 + const struct dentry *old_dentry,
41095 + const struct inode *old_parent_inode,
41096 + const struct vfsmount *old_mnt, const char *newname)
41097 +{
41098 + return 0;
41099 +}
41100 +
41101 +int
41102 +gr_acl_handle_filldir(const struct file *file, const char *name,
41103 + const int namelen, const ino_t ino)
41104 +{
41105 + return 1;
41106 +}
41107 +
41108 +int
41109 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
41110 + const time_t shm_createtime, const uid_t cuid, const int shmid)
41111 +{
41112 + return 1;
41113 +}
41114 +
41115 +int
41116 +gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
41117 +{
41118 + return 0;
41119 +}
41120 +
41121 +int
41122 +gr_search_accept(const struct socket *sock)
41123 +{
41124 + return 0;
41125 +}
41126 +
41127 +int
41128 +gr_search_listen(const struct socket *sock)
41129 +{
41130 + return 0;
41131 +}
41132 +
41133 +int
41134 +gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
41135 +{
41136 + return 0;
41137 +}
41138 +
41139 +__u32
41140 +gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
41141 +{
41142 + return 1;
41143 +}
41144 +
41145 +__u32
41146 +gr_acl_handle_creat(const struct dentry * dentry,
41147 + const struct dentry * p_dentry,
41148 + const struct vfsmount * p_mnt, const int fmode,
41149 + const int imode)
41150 +{
41151 + return 1;
41152 +}
41153 +
41154 +void
41155 +gr_acl_handle_exit(void)
41156 +{
41157 + return;
41158 +}
41159 +
41160 +int
41161 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
41162 +{
41163 + return 1;
41164 +}
41165 +
41166 +void
41167 +gr_set_role_label(const uid_t uid, const gid_t gid)
41168 +{
41169 + return;
41170 +}
41171 +
41172 +int
41173 +gr_acl_handle_procpidmem(const struct task_struct *task)
41174 +{
41175 + return 0;
41176 +}
41177 +
41178 +int
41179 +gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
41180 +{
41181 + return 0;
41182 +}
41183 +
41184 +int
41185 +gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
41186 +{
41187 + return 0;
41188 +}
41189 +
41190 +void
41191 +gr_set_kernel_label(struct task_struct *task)
41192 +{
41193 + return;
41194 +}
41195 +
41196 +int
41197 +gr_check_user_change(int real, int effective, int fs)
41198 +{
41199 + return 0;
41200 +}
41201 +
41202 +int
41203 +gr_check_group_change(int real, int effective, int fs)
41204 +{
41205 + return 0;
41206 +}
41207 +
41208 +int gr_acl_enable_at_secure(void)
41209 +{
41210 + return 0;
41211 +}
41212 +
41213 +EXPORT_SYMBOL(gr_is_capable);
41214 +EXPORT_SYMBOL(gr_is_capable_nolog);
41215 +EXPORT_SYMBOL(gr_learn_resource);
41216 +EXPORT_SYMBOL(gr_set_kernel_label);
41217 +#ifdef CONFIG_SECURITY
41218 +EXPORT_SYMBOL(gr_check_user_change);
41219 +EXPORT_SYMBOL(gr_check_group_change);
41220 +#endif
41221 diff -urNp linux-2.6.37/grsecurity/grsec_exec.c linux-2.6.37/grsecurity/grsec_exec.c
41222 --- linux-2.6.37/grsecurity/grsec_exec.c 1969-12-31 19:00:00.000000000 -0500
41223 +++ linux-2.6.37/grsecurity/grsec_exec.c 2011-01-17 02:41:02.000000000 -0500
41224 @@ -0,0 +1,147 @@
41225 +#include <linux/kernel.h>
41226 +#include <linux/sched.h>
41227 +#include <linux/file.h>
41228 +#include <linux/binfmts.h>
41229 +#include <linux/smp_lock.h>
41230 +#include <linux/fs.h>
41231 +#include <linux/types.h>
41232 +#include <linux/grdefs.h>
41233 +#include <linux/grinternal.h>
41234 +#include <linux/capability.h>
41235 +#include <linux/compat.h>
41236 +
41237 +#include <asm/uaccess.h>
41238 +
41239 +#ifdef CONFIG_GRKERNSEC_EXECLOG
41240 +static char gr_exec_arg_buf[132];
41241 +static DEFINE_MUTEX(gr_exec_arg_mutex);
41242 +#endif
41243 +
41244 +int
41245 +gr_handle_nproc(void)
41246 +{
41247 +#ifdef CONFIG_GRKERNSEC_EXECVE
41248 + const struct cred *cred = current_cred();
41249 + if (grsec_enable_execve && cred->user &&
41250 + (atomic_read(&cred->user->processes) > rlimit(RLIMIT_NPROC)) &&
41251 + !capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE)) {
41252 + gr_log_noargs(GR_DONT_AUDIT, GR_NPROC_MSG);
41253 + return -EAGAIN;
41254 + }
41255 +#endif
41256 + return 0;
41257 +}
41258 +
41259 +void
41260 +gr_handle_exec_args(struct linux_binprm *bprm, const char __user *const __user *argv)
41261 +{
41262 +#ifdef CONFIG_GRKERNSEC_EXECLOG
41263 + char *grarg = gr_exec_arg_buf;
41264 + unsigned int i, x, execlen = 0;
41265 + char c;
41266 +
41267 + if (!((grsec_enable_execlog && grsec_enable_group &&
41268 + in_group_p(grsec_audit_gid))
41269 + || (grsec_enable_execlog && !grsec_enable_group)))
41270 + return;
41271 +
41272 + mutex_lock(&gr_exec_arg_mutex);
41273 + memset(grarg, 0, sizeof(gr_exec_arg_buf));
41274 +
41275 + if (unlikely(argv == NULL))
41276 + goto log;
41277 +
41278 + for (i = 0; i < bprm->argc && execlen < 128; i++) {
41279 + const char __user *p;
41280 + unsigned int len;
41281 +
41282 + if (copy_from_user(&p, argv + i, sizeof(p)))
41283 + goto log;
41284 + if (!p)
41285 + goto log;
41286 + len = strnlen_user(p, 128 - execlen);
41287 + if (len > 128 - execlen)
41288 + len = 128 - execlen;
41289 + else if (len > 0)
41290 + len--;
41291 + if (copy_from_user(grarg + execlen, p, len))
41292 + goto log;
41293 +
41294 + /* rewrite unprintable characters */
41295 + for (x = 0; x < len; x++) {
41296 + c = *(grarg + execlen + x);
41297 + if (c < 32 || c > 126)
41298 + *(grarg + execlen + x) = ' ';
41299 + }
41300 +
41301 + execlen += len;
41302 + *(grarg + execlen) = ' ';
41303 + *(grarg + execlen + 1) = '\0';
41304 + execlen++;
41305 + }
41306 +
41307 + log:
41308 + gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
41309 + bprm->file->f_path.mnt, grarg);
41310 + mutex_unlock(&gr_exec_arg_mutex);
41311 +#endif
41312 + return;
41313 +}
41314 +
41315 +#ifdef CONFIG_COMPAT
41316 +void
41317 +gr_handle_exec_args_compat(struct linux_binprm *bprm, compat_uptr_t __user *argv)
41318 +{
41319 +#ifdef CONFIG_GRKERNSEC_EXECLOG
41320 + char *grarg = gr_exec_arg_buf;
41321 + unsigned int i, x, execlen = 0;
41322 + char c;
41323 +
41324 + if (!((grsec_enable_execlog && grsec_enable_group &&
41325 + in_group_p(grsec_audit_gid))
41326 + || (grsec_enable_execlog && !grsec_enable_group)))
41327 + return;
41328 +
41329 + mutex_lock(&gr_exec_arg_mutex);
41330 + memset(grarg, 0, sizeof(gr_exec_arg_buf));
41331 +
41332 + if (unlikely(argv == NULL))
41333 + goto log;
41334 +
41335 + for (i = 0; i < bprm->argc && execlen < 128; i++) {
41336 + compat_uptr_t p;
41337 + unsigned int len;
41338 +
41339 + if (get_user(p, argv + i))
41340 + goto log;
41341 + len = strnlen_user(compat_ptr(p), 128 - execlen);
41342 + if (len > 128 - execlen)
41343 + len = 128 - execlen;
41344 + else if (len > 0)
41345 + len--;
41346 + else
41347 + goto log;
41348 + if (copy_from_user(grarg + execlen, compat_ptr(p), len))
41349 + goto log;
41350 +
41351 + /* rewrite unprintable characters */
41352 + for (x = 0; x < len; x++) {
41353 + c = *(grarg + execlen + x);
41354 + if (c < 32 || c > 126)
41355 + *(grarg + execlen + x) = ' ';
41356 + }
41357 +
41358 + execlen += len;
41359 + *(grarg + execlen) = ' ';
41360 + *(grarg + execlen + 1) = '\0';
41361 + execlen++;
41362 + }
41363 +
41364 + log:
41365 + gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
41366 + bprm->file->f_path.mnt, grarg);
41367 + mutex_unlock(&gr_exec_arg_mutex);
41368 +#endif
41369 + return;
41370 +}
41371 +#endif
41372 diff -urNp linux-2.6.37/grsecurity/grsec_fifo.c linux-2.6.37/grsecurity/grsec_fifo.c
41373 --- linux-2.6.37/grsecurity/grsec_fifo.c 1969-12-31 19:00:00.000000000 -0500
41374 +++ linux-2.6.37/grsecurity/grsec_fifo.c 2011-01-17 02:41:02.000000000 -0500
41375 @@ -0,0 +1,24 @@
41376 +#include <linux/kernel.h>
41377 +#include <linux/sched.h>
41378 +#include <linux/fs.h>
41379 +#include <linux/file.h>
41380 +#include <linux/grinternal.h>
41381 +
41382 +int
41383 +gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
41384 + const struct dentry *dir, const int flag, const int acc_mode)
41385 +{
41386 +#ifdef CONFIG_GRKERNSEC_FIFO
41387 + const struct cred *cred = current_cred();
41388 +
41389 + if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
41390 + !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
41391 + (dentry->d_inode->i_uid != dir->d_inode->i_uid) &&
41392 + (cred->fsuid != dentry->d_inode->i_uid)) {
41393 + if (!generic_permission(dentry->d_inode, acc_mode, NULL))
41394 + gr_log_fs_int2(GR_DONT_AUDIT, GR_FIFO_MSG, dentry, mnt, dentry->d_inode->i_uid, dentry->d_inode->i_gid);
41395 + return -EACCES;
41396 + }
41397 +#endif
41398 + return 0;
41399 +}
41400 diff -urNp linux-2.6.37/grsecurity/grsec_fork.c linux-2.6.37/grsecurity/grsec_fork.c
41401 --- linux-2.6.37/grsecurity/grsec_fork.c 1969-12-31 19:00:00.000000000 -0500
41402 +++ linux-2.6.37/grsecurity/grsec_fork.c 2011-01-17 02:41:02.000000000 -0500
41403 @@ -0,0 +1,23 @@
41404 +#include <linux/kernel.h>
41405 +#include <linux/sched.h>
41406 +#include <linux/grsecurity.h>
41407 +#include <linux/grinternal.h>
41408 +#include <linux/errno.h>
41409 +
41410 +void
41411 +gr_log_forkfail(const int retval)
41412 +{
41413 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
41414 + if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
41415 + switch (retval) {
41416 + case -EAGAIN:
41417 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
41418 + break;
41419 + case -ENOMEM:
41420 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
41421 + break;
41422 + }
41423 + }
41424 +#endif
41425 + return;
41426 +}
41427 diff -urNp linux-2.6.37/grsecurity/grsec_init.c linux-2.6.37/grsecurity/grsec_init.c
41428 --- linux-2.6.37/grsecurity/grsec_init.c 1969-12-31 19:00:00.000000000 -0500
41429 +++ linux-2.6.37/grsecurity/grsec_init.c 2011-01-17 02:41:02.000000000 -0500
41430 @@ -0,0 +1,270 @@
41431 +#include <linux/kernel.h>
41432 +#include <linux/sched.h>
41433 +#include <linux/mm.h>
41434 +#include <linux/smp_lock.h>
41435 +#include <linux/gracl.h>
41436 +#include <linux/slab.h>
41437 +#include <linux/vmalloc.h>
41438 +#include <linux/percpu.h>
41439 +#include <linux/module.h>
41440 +
41441 +int grsec_enable_link;
41442 +int grsec_enable_dmesg;
41443 +int grsec_enable_harden_ptrace;
41444 +int grsec_enable_fifo;
41445 +int grsec_enable_execve;
41446 +int grsec_enable_execlog;
41447 +int grsec_enable_signal;
41448 +int grsec_enable_forkfail;
41449 +int grsec_enable_audit_ptrace;
41450 +int grsec_enable_time;
41451 +int grsec_enable_audit_textrel;
41452 +int grsec_enable_group;
41453 +int grsec_audit_gid;
41454 +int grsec_enable_chdir;
41455 +int grsec_enable_mount;
41456 +int grsec_enable_rofs;
41457 +int grsec_enable_chroot_findtask;
41458 +int grsec_enable_chroot_mount;
41459 +int grsec_enable_chroot_shmat;
41460 +int grsec_enable_chroot_fchdir;
41461 +int grsec_enable_chroot_double;
41462 +int grsec_enable_chroot_pivot;
41463 +int grsec_enable_chroot_chdir;
41464 +int grsec_enable_chroot_chmod;
41465 +int grsec_enable_chroot_mknod;
41466 +int grsec_enable_chroot_nice;
41467 +int grsec_enable_chroot_execlog;
41468 +int grsec_enable_chroot_caps;
41469 +int grsec_enable_chroot_sysctl;
41470 +int grsec_enable_chroot_unix;
41471 +int grsec_enable_tpe;
41472 +int grsec_tpe_gid;
41473 +int grsec_enable_blackhole;
41474 +#ifdef CONFIG_IPV6_MODULE
41475 +EXPORT_SYMBOL(grsec_enable_blackhole);
41476 +#endif
41477 +int grsec_lastack_retries;
41478 +int grsec_enable_tpe_all;
41479 +int grsec_enable_tpe_invert;
41480 +int grsec_enable_socket_all;
41481 +int grsec_socket_all_gid;
41482 +int grsec_enable_socket_client;
41483 +int grsec_socket_client_gid;
41484 +int grsec_enable_socket_server;
41485 +int grsec_socket_server_gid;
41486 +int grsec_resource_logging;
41487 +int grsec_disable_privio;
41488 +int grsec_enable_log_rwxmaps;
41489 +int grsec_lock;
41490 +
41491 +DEFINE_SPINLOCK(grsec_alert_lock);
41492 +unsigned long grsec_alert_wtime = 0;
41493 +unsigned long grsec_alert_fyet = 0;
41494 +
41495 +DEFINE_SPINLOCK(grsec_audit_lock);
41496 +
41497 +DEFINE_RWLOCK(grsec_exec_file_lock);
41498 +
41499 +char *gr_shared_page[4];
41500 +
41501 +char *gr_alert_log_fmt;
41502 +char *gr_audit_log_fmt;
41503 +char *gr_alert_log_buf;
41504 +char *gr_audit_log_buf;
41505 +
41506 +extern struct gr_arg *gr_usermode;
41507 +extern unsigned char *gr_system_salt;
41508 +extern unsigned char *gr_system_sum;
41509 +
41510 +void __init
41511 +grsecurity_init(void)
41512 +{
41513 + int j;
41514 + /* create the per-cpu shared pages */
41515 +
41516 +#ifdef CONFIG_X86
41517 + memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
41518 +#endif
41519 +
41520 + for (j = 0; j < 4; j++) {
41521 + gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
41522 + if (gr_shared_page[j] == NULL) {
41523 + panic("Unable to allocate grsecurity shared page");
41524 + return;
41525 + }
41526 + }
41527 +
41528 + /* allocate log buffers */
41529 + gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
41530 + if (!gr_alert_log_fmt) {
41531 + panic("Unable to allocate grsecurity alert log format buffer");
41532 + return;
41533 + }
41534 + gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
41535 + if (!gr_audit_log_fmt) {
41536 + panic("Unable to allocate grsecurity audit log format buffer");
41537 + return;
41538 + }
41539 + gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
41540 + if (!gr_alert_log_buf) {
41541 + panic("Unable to allocate grsecurity alert log buffer");
41542 + return;
41543 + }
41544 + gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
41545 + if (!gr_audit_log_buf) {
41546 + panic("Unable to allocate grsecurity audit log buffer");
41547 + return;
41548 + }
41549 +
41550 + /* allocate memory for authentication structure */
41551 + gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
41552 + gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
41553 + gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
41554 +
41555 + if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
41556 + panic("Unable to allocate grsecurity authentication structure");
41557 + return;
41558 + }
41559 +
41560 +
41561 +#ifdef CONFIG_GRKERNSEC_IO
41562 +#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
41563 + grsec_disable_privio = 1;
41564 +#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
41565 + grsec_disable_privio = 1;
41566 +#else
41567 + grsec_disable_privio = 0;
41568 +#endif
41569 +#endif
41570 +
41571 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
41572 + /* for backward compatibility, tpe_invert always defaults to on if
41573 + enabled in the kernel
41574 + */
41575 + grsec_enable_tpe_invert = 1;
41576 +#endif
41577 +
41578 +#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
41579 +#ifndef CONFIG_GRKERNSEC_SYSCTL
41580 + grsec_lock = 1;
41581 +#endif
41582 +
41583 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
41584 + grsec_enable_audit_textrel = 1;
41585 +#endif
41586 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
41587 + grsec_enable_log_rwxmaps = 1;
41588 +#endif
41589 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
41590 + grsec_enable_group = 1;
41591 + grsec_audit_gid = CONFIG_GRKERNSEC_AUDIT_GID;
41592 +#endif
41593 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
41594 + grsec_enable_chdir = 1;
41595 +#endif
41596 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
41597 + grsec_enable_harden_ptrace = 1;
41598 +#endif
41599 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
41600 + grsec_enable_mount = 1;
41601 +#endif
41602 +#ifdef CONFIG_GRKERNSEC_LINK
41603 + grsec_enable_link = 1;
41604 +#endif
41605 +#ifdef CONFIG_GRKERNSEC_DMESG
41606 + grsec_enable_dmesg = 1;
41607 +#endif
41608 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
41609 + grsec_enable_blackhole = 1;
41610 + grsec_lastack_retries = 4;
41611 +#endif
41612 +#ifdef CONFIG_GRKERNSEC_FIFO
41613 + grsec_enable_fifo = 1;
41614 +#endif
41615 +#ifdef CONFIG_GRKERNSEC_EXECVE
41616 + grsec_enable_execve = 1;
41617 +#endif
41618 +#ifdef CONFIG_GRKERNSEC_EXECLOG
41619 + grsec_enable_execlog = 1;
41620 +#endif
41621 +#ifdef CONFIG_GRKERNSEC_SIGNAL
41622 + grsec_enable_signal = 1;
41623 +#endif
41624 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
41625 + grsec_enable_forkfail = 1;
41626 +#endif
41627 +#ifdef CONFIG_GRKERNSEC_TIME
41628 + grsec_enable_time = 1;
41629 +#endif
41630 +#ifdef CONFIG_GRKERNSEC_RESLOG
41631 + grsec_resource_logging = 1;
41632 +#endif
41633 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
41634 + grsec_enable_chroot_findtask = 1;
41635 +#endif
41636 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
41637 + grsec_enable_chroot_unix = 1;
41638 +#endif
41639 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
41640 + grsec_enable_chroot_mount = 1;
41641 +#endif
41642 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
41643 + grsec_enable_chroot_fchdir = 1;
41644 +#endif
41645 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
41646 + grsec_enable_chroot_shmat = 1;
41647 +#endif
41648 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
41649 + grsec_enable_audit_ptrace = 1;
41650 +#endif
41651 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
41652 + grsec_enable_chroot_double = 1;
41653 +#endif
41654 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
41655 + grsec_enable_chroot_pivot = 1;
41656 +#endif
41657 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
41658 + grsec_enable_chroot_chdir = 1;
41659 +#endif
41660 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
41661 + grsec_enable_chroot_chmod = 1;
41662 +#endif
41663 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
41664 + grsec_enable_chroot_mknod = 1;
41665 +#endif
41666 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
41667 + grsec_enable_chroot_nice = 1;
41668 +#endif
41669 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
41670 + grsec_enable_chroot_execlog = 1;
41671 +#endif
41672 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
41673 + grsec_enable_chroot_caps = 1;
41674 +#endif
41675 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
41676 + grsec_enable_chroot_sysctl = 1;
41677 +#endif
41678 +#ifdef CONFIG_GRKERNSEC_TPE
41679 + grsec_enable_tpe = 1;
41680 + grsec_tpe_gid = CONFIG_GRKERNSEC_TPE_GID;
41681 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
41682 + grsec_enable_tpe_all = 1;
41683 +#endif
41684 +#endif
41685 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
41686 + grsec_enable_socket_all = 1;
41687 + grsec_socket_all_gid = CONFIG_GRKERNSEC_SOCKET_ALL_GID;
41688 +#endif
41689 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
41690 + grsec_enable_socket_client = 1;
41691 + grsec_socket_client_gid = CONFIG_GRKERNSEC_SOCKET_CLIENT_GID;
41692 +#endif
41693 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
41694 + grsec_enable_socket_server = 1;
41695 + grsec_socket_server_gid = CONFIG_GRKERNSEC_SOCKET_SERVER_GID;
41696 +#endif
41697 +#endif
41698 +
41699 + return;
41700 +}
41701 diff -urNp linux-2.6.37/grsecurity/grsec_link.c linux-2.6.37/grsecurity/grsec_link.c
41702 --- linux-2.6.37/grsecurity/grsec_link.c 1969-12-31 19:00:00.000000000 -0500
41703 +++ linux-2.6.37/grsecurity/grsec_link.c 2011-01-17 02:41:02.000000000 -0500
41704 @@ -0,0 +1,43 @@
41705 +#include <linux/kernel.h>
41706 +#include <linux/sched.h>
41707 +#include <linux/fs.h>
41708 +#include <linux/file.h>
41709 +#include <linux/grinternal.h>
41710 +
41711 +int
41712 +gr_handle_follow_link(const struct inode *parent,
41713 + const struct inode *inode,
41714 + const struct dentry *dentry, const struct vfsmount *mnt)
41715 +{
41716 +#ifdef CONFIG_GRKERNSEC_LINK
41717 + const struct cred *cred = current_cred();
41718 +
41719 + if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
41720 + (parent->i_mode & S_ISVTX) && (parent->i_uid != inode->i_uid) &&
41721 + (parent->i_mode & S_IWOTH) && (cred->fsuid != inode->i_uid)) {
41722 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
41723 + return -EACCES;
41724 + }
41725 +#endif
41726 + return 0;
41727 +}
41728 +
41729 +int
41730 +gr_handle_hardlink(const struct dentry *dentry,
41731 + const struct vfsmount *mnt,
41732 + struct inode *inode, const int mode, const char *to)
41733 +{
41734 +#ifdef CONFIG_GRKERNSEC_LINK
41735 + const struct cred *cred = current_cred();
41736 +
41737 + if (grsec_enable_link && cred->fsuid != inode->i_uid &&
41738 + (!S_ISREG(mode) || (mode & S_ISUID) ||
41739 + ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP)) ||
41740 + (generic_permission(inode, MAY_READ | MAY_WRITE, NULL))) &&
41741 + !capable(CAP_FOWNER) && cred->uid) {
41742 + gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to);
41743 + return -EPERM;
41744 + }
41745 +#endif
41746 + return 0;
41747 +}
41748 diff -urNp linux-2.6.37/grsecurity/grsec_log.c linux-2.6.37/grsecurity/grsec_log.c
41749 --- linux-2.6.37/grsecurity/grsec_log.c 1969-12-31 19:00:00.000000000 -0500
41750 +++ linux-2.6.37/grsecurity/grsec_log.c 2011-01-17 02:41:02.000000000 -0500
41751 @@ -0,0 +1,310 @@
41752 +#include <linux/kernel.h>
41753 +#include <linux/sched.h>
41754 +#include <linux/file.h>
41755 +#include <linux/tty.h>
41756 +#include <linux/fs.h>
41757 +#include <linux/grinternal.h>
41758 +
41759 +#ifdef CONFIG_TREE_PREEMPT_RCU
41760 +#define DISABLE_PREEMPT() preempt_disable()
41761 +#define ENABLE_PREEMPT() preempt_enable()
41762 +#else
41763 +#define DISABLE_PREEMPT()
41764 +#define ENABLE_PREEMPT()
41765 +#endif
41766 +
41767 +#define BEGIN_LOCKS(x) \
41768 + DISABLE_PREEMPT(); \
41769 + rcu_read_lock(); \
41770 + read_lock(&tasklist_lock); \
41771 + read_lock(&grsec_exec_file_lock); \
41772 + if (x != GR_DO_AUDIT) \
41773 + spin_lock(&grsec_alert_lock); \
41774 + else \
41775 + spin_lock(&grsec_audit_lock)
41776 +
41777 +#define END_LOCKS(x) \
41778 + if (x != GR_DO_AUDIT) \
41779 + spin_unlock(&grsec_alert_lock); \
41780 + else \
41781 + spin_unlock(&grsec_audit_lock); \
41782 + read_unlock(&grsec_exec_file_lock); \
41783 + read_unlock(&tasklist_lock); \
41784 + rcu_read_unlock(); \
41785 + ENABLE_PREEMPT(); \
41786 + if (x == GR_DONT_AUDIT) \
41787 + gr_handle_alertkill(current)
41788 +
41789 +enum {
41790 + FLOODING,
41791 + NO_FLOODING
41792 +};
41793 +
41794 +extern char *gr_alert_log_fmt;
41795 +extern char *gr_audit_log_fmt;
41796 +extern char *gr_alert_log_buf;
41797 +extern char *gr_audit_log_buf;
41798 +
41799 +static int gr_log_start(int audit)
41800 +{
41801 + char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
41802 + char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
41803 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
41804 +
41805 + if (audit == GR_DO_AUDIT)
41806 + goto set_fmt;
41807 +
41808 + if (!grsec_alert_wtime || jiffies - grsec_alert_wtime > CONFIG_GRKERNSEC_FLOODTIME * HZ) {
41809 + grsec_alert_wtime = jiffies;
41810 + grsec_alert_fyet = 0;
41811 + } else if ((jiffies - grsec_alert_wtime < CONFIG_GRKERNSEC_FLOODTIME * HZ) && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
41812 + grsec_alert_fyet++;
41813 + } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
41814 + grsec_alert_wtime = jiffies;
41815 + grsec_alert_fyet++;
41816 + printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
41817 + return FLOODING;
41818 + } else return FLOODING;
41819 +
41820 +set_fmt:
41821 + memset(buf, 0, PAGE_SIZE);
41822 + if (current->signal->curr_ip && gr_acl_is_enabled()) {
41823 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
41824 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
41825 + } else if (current->signal->curr_ip) {
41826 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
41827 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
41828 + } else if (gr_acl_is_enabled()) {
41829 + sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
41830 + snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
41831 + } else {
41832 + sprintf(fmt, "%s%s", loglevel, "grsec: ");
41833 + strcpy(buf, fmt);
41834 + }
41835 +
41836 + return NO_FLOODING;
41837 +}
41838 +
41839 +static void gr_log_middle(int audit, const char *msg, va_list ap)
41840 + __attribute__ ((format (printf, 2, 0)));
41841 +
41842 +static void gr_log_middle(int audit, const char *msg, va_list ap)
41843 +{
41844 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
41845 + unsigned int len = strlen(buf);
41846 +
41847 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
41848 +
41849 + return;
41850 +}
41851 +
41852 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
41853 + __attribute__ ((format (printf, 2, 3)));
41854 +
41855 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
41856 +{
41857 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
41858 + unsigned int len = strlen(buf);
41859 + va_list ap;
41860 +
41861 + va_start(ap, msg);
41862 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
41863 + va_end(ap);
41864 +
41865 + return;
41866 +}
41867 +
41868 +static void gr_log_end(int audit)
41869 +{
41870 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
41871 + unsigned int len = strlen(buf);
41872 +
41873 + snprintf(buf + len, PAGE_SIZE - len - 1, DEFAULTSECMSG, DEFAULTSECARGS(current, current_cred(), __task_cred(current->real_parent)));
41874 + printk("%s\n", buf);
41875 +
41876 + return;
41877 +}
41878 +
41879 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
41880 +{
41881 + int logtype;
41882 + char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
41883 + char *str1, *str2, *str3;
41884 + void *voidptr;
41885 + int num1, num2;
41886 + unsigned long ulong1, ulong2;
41887 + struct dentry *dentry;
41888 + struct vfsmount *mnt;
41889 + struct file *file;
41890 + struct task_struct *task;
41891 + const struct cred *cred, *pcred;
41892 + va_list ap;
41893 +
41894 + BEGIN_LOCKS(audit);
41895 + logtype = gr_log_start(audit);
41896 + if (logtype == FLOODING) {
41897 + END_LOCKS(audit);
41898 + return;
41899 + }
41900 + va_start(ap, argtypes);
41901 + switch (argtypes) {
41902 + case GR_TTYSNIFF:
41903 + task = va_arg(ap, struct task_struct *);
41904 + 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);
41905 + break;
41906 + case GR_SYSCTL_HIDDEN:
41907 + str1 = va_arg(ap, char *);
41908 + gr_log_middle_varargs(audit, msg, result, str1);
41909 + break;
41910 + case GR_RBAC:
41911 + dentry = va_arg(ap, struct dentry *);
41912 + mnt = va_arg(ap, struct vfsmount *);
41913 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
41914 + break;
41915 + case GR_RBAC_STR:
41916 + dentry = va_arg(ap, struct dentry *);
41917 + mnt = va_arg(ap, struct vfsmount *);
41918 + str1 = va_arg(ap, char *);
41919 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
41920 + break;
41921 + case GR_STR_RBAC:
41922 + str1 = va_arg(ap, char *);
41923 + dentry = va_arg(ap, struct dentry *);
41924 + mnt = va_arg(ap, struct vfsmount *);
41925 + gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
41926 + break;
41927 + case GR_RBAC_MODE2:
41928 + dentry = va_arg(ap, struct dentry *);
41929 + mnt = va_arg(ap, struct vfsmount *);
41930 + str1 = va_arg(ap, char *);
41931 + str2 = va_arg(ap, char *);
41932 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
41933 + break;
41934 + case GR_RBAC_MODE3:
41935 + dentry = va_arg(ap, struct dentry *);
41936 + mnt = va_arg(ap, struct vfsmount *);
41937 + str1 = va_arg(ap, char *);
41938 + str2 = va_arg(ap, char *);
41939 + str3 = va_arg(ap, char *);
41940 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
41941 + break;
41942 + case GR_FILENAME:
41943 + dentry = va_arg(ap, struct dentry *);
41944 + mnt = va_arg(ap, struct vfsmount *);
41945 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
41946 + break;
41947 + case GR_STR_FILENAME:
41948 + str1 = va_arg(ap, char *);
41949 + dentry = va_arg(ap, struct dentry *);
41950 + mnt = va_arg(ap, struct vfsmount *);
41951 + gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
41952 + break;
41953 + case GR_FILENAME_STR:
41954 + dentry = va_arg(ap, struct dentry *);
41955 + mnt = va_arg(ap, struct vfsmount *);
41956 + str1 = va_arg(ap, char *);
41957 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
41958 + break;
41959 + case GR_FILENAME_TWO_INT:
41960 + dentry = va_arg(ap, struct dentry *);
41961 + mnt = va_arg(ap, struct vfsmount *);
41962 + num1 = va_arg(ap, int);
41963 + num2 = va_arg(ap, int);
41964 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
41965 + break;
41966 + case GR_FILENAME_TWO_INT_STR:
41967 + dentry = va_arg(ap, struct dentry *);
41968 + mnt = va_arg(ap, struct vfsmount *);
41969 + num1 = va_arg(ap, int);
41970 + num2 = va_arg(ap, int);
41971 + str1 = va_arg(ap, char *);
41972 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
41973 + break;
41974 + case GR_TEXTREL:
41975 + file = va_arg(ap, struct file *);
41976 + ulong1 = va_arg(ap, unsigned long);
41977 + ulong2 = va_arg(ap, unsigned long);
41978 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
41979 + break;
41980 + case GR_PTRACE:
41981 + task = va_arg(ap, struct task_struct *);
41982 + 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);
41983 + break;
41984 + case GR_RESOURCE:
41985 + task = va_arg(ap, struct task_struct *);
41986 + cred = __task_cred(task);
41987 + pcred = __task_cred(task->real_parent);
41988 + ulong1 = va_arg(ap, unsigned long);
41989 + str1 = va_arg(ap, char *);
41990 + ulong2 = va_arg(ap, unsigned long);
41991 + 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);
41992 + break;
41993 + case GR_CAP:
41994 + task = va_arg(ap, struct task_struct *);
41995 + cred = __task_cred(task);
41996 + pcred = __task_cred(task->real_parent);
41997 + str1 = va_arg(ap, char *);
41998 + 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);
41999 + break;
42000 + case GR_SIG:
42001 + str1 = va_arg(ap, char *);
42002 + voidptr = va_arg(ap, void *);
42003 + gr_log_middle_varargs(audit, msg, str1, voidptr);
42004 + break;
42005 + case GR_SIG2:
42006 + task = va_arg(ap, struct task_struct *);
42007 + cred = __task_cred(task);
42008 + pcred = __task_cred(task->real_parent);
42009 + num1 = va_arg(ap, int);
42010 + 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);
42011 + break;
42012 + case GR_CRASH1:
42013 + task = va_arg(ap, struct task_struct *);
42014 + cred = __task_cred(task);
42015 + pcred = __task_cred(task->real_parent);
42016 + ulong1 = va_arg(ap, unsigned long);
42017 + 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);
42018 + break;
42019 + case GR_CRASH2:
42020 + task = va_arg(ap, struct task_struct *);
42021 + cred = __task_cred(task);
42022 + pcred = __task_cred(task->real_parent);
42023 + ulong1 = va_arg(ap, unsigned long);
42024 + 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);
42025 + break;
42026 + case GR_RWXMAP:
42027 + file = va_arg(ap, struct file *);
42028 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
42029 + break;
42030 + case GR_PSACCT:
42031 + {
42032 + unsigned int wday, cday;
42033 + __u8 whr, chr;
42034 + __u8 wmin, cmin;
42035 + __u8 wsec, csec;
42036 + char cur_tty[64] = { 0 };
42037 + char parent_tty[64] = { 0 };
42038 +
42039 + task = va_arg(ap, struct task_struct *);
42040 + wday = va_arg(ap, unsigned int);
42041 + cday = va_arg(ap, unsigned int);
42042 + whr = va_arg(ap, int);
42043 + chr = va_arg(ap, int);
42044 + wmin = va_arg(ap, int);
42045 + cmin = va_arg(ap, int);
42046 + wsec = va_arg(ap, int);
42047 + csec = va_arg(ap, int);
42048 + ulong1 = va_arg(ap, unsigned long);
42049 + cred = __task_cred(task);
42050 + pcred = __task_cred(task->real_parent);
42051 +
42052 + 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);
42053 + }
42054 + break;
42055 + default:
42056 + gr_log_middle(audit, msg, ap);
42057 + }
42058 + va_end(ap);
42059 + gr_log_end(audit);
42060 + END_LOCKS(audit);
42061 +}
42062 diff -urNp linux-2.6.37/grsecurity/grsec_mem.c linux-2.6.37/grsecurity/grsec_mem.c
42063 --- linux-2.6.37/grsecurity/grsec_mem.c 1969-12-31 19:00:00.000000000 -0500
42064 +++ linux-2.6.37/grsecurity/grsec_mem.c 2011-01-17 02:41:02.000000000 -0500
42065 @@ -0,0 +1,85 @@
42066 +#include <linux/kernel.h>
42067 +#include <linux/sched.h>
42068 +#include <linux/mm.h>
42069 +#include <linux/mman.h>
42070 +#include <linux/grinternal.h>
42071 +
42072 +void
42073 +gr_handle_ioperm(void)
42074 +{
42075 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
42076 + return;
42077 +}
42078 +
42079 +void
42080 +gr_handle_iopl(void)
42081 +{
42082 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
42083 + return;
42084 +}
42085 +
42086 +void
42087 +gr_handle_mem_write(void)
42088 +{
42089 + gr_log_noargs(GR_DONT_AUDIT, GR_MEM_WRITE_MSG);
42090 + return;
42091 +}
42092 +
42093 +void
42094 +gr_handle_kmem_write(void)
42095 +{
42096 + gr_log_noargs(GR_DONT_AUDIT, GR_KMEM_MSG);
42097 + return;
42098 +}
42099 +
42100 +void
42101 +gr_handle_open_port(void)
42102 +{
42103 + gr_log_noargs(GR_DONT_AUDIT, GR_PORT_OPEN_MSG);
42104 + return;
42105 +}
42106 +
42107 +int
42108 +gr_handle_mem_mmap(const unsigned long offset, struct vm_area_struct *vma)
42109 +{
42110 + unsigned long start, end;
42111 +
42112 + start = offset;
42113 + end = start + vma->vm_end - vma->vm_start;
42114 +
42115 + if (start > end) {
42116 + gr_log_noargs(GR_DONT_AUDIT, GR_MEM_MMAP_MSG);
42117 + return -EPERM;
42118 + }
42119 +
42120 + /* allowed ranges : ISA I/O BIOS */
42121 + if ((start >= __pa(high_memory))
42122 +#if defined(CONFIG_X86) || defined(CONFIG_PPC)
42123 + || (start >= 0x000a0000 && end <= 0x00100000)
42124 + || (start >= 0x00000000 && end <= 0x00001000)
42125 +#endif
42126 + )
42127 + return 0;
42128 +
42129 + if (vma->vm_flags & VM_WRITE) {
42130 + gr_log_noargs(GR_DONT_AUDIT, GR_MEM_MMAP_MSG);
42131 + return -EPERM;
42132 + } else
42133 + vma->vm_flags &= ~VM_MAYWRITE;
42134 +
42135 + return 0;
42136 +}
42137 +
42138 +void
42139 +gr_log_nonroot_mod_load(const char *modname)
42140 +{
42141 + gr_log_str(GR_DONT_AUDIT, GR_NONROOT_MODLOAD_MSG, modname);
42142 + return;
42143 +}
42144 +
42145 +void
42146 +gr_handle_vm86(void)
42147 +{
42148 + gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
42149 + return;
42150 +}
42151 diff -urNp linux-2.6.37/grsecurity/grsec_mount.c linux-2.6.37/grsecurity/grsec_mount.c
42152 --- linux-2.6.37/grsecurity/grsec_mount.c 1969-12-31 19:00:00.000000000 -0500
42153 +++ linux-2.6.37/grsecurity/grsec_mount.c 2011-01-17 02:41:02.000000000 -0500
42154 @@ -0,0 +1,62 @@
42155 +#include <linux/kernel.h>
42156 +#include <linux/sched.h>
42157 +#include <linux/mount.h>
42158 +#include <linux/grsecurity.h>
42159 +#include <linux/grinternal.h>
42160 +
42161 +void
42162 +gr_log_remount(const char *devname, const int retval)
42163 +{
42164 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
42165 + if (grsec_enable_mount && (retval >= 0))
42166 + gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
42167 +#endif
42168 + return;
42169 +}
42170 +
42171 +void
42172 +gr_log_unmount(const char *devname, const int retval)
42173 +{
42174 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
42175 + if (grsec_enable_mount && (retval >= 0))
42176 + gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
42177 +#endif
42178 + return;
42179 +}
42180 +
42181 +void
42182 +gr_log_mount(const char *from, const char *to, const int retval)
42183 +{
42184 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
42185 + if (grsec_enable_mount && (retval >= 0))
42186 + gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from, to);
42187 +#endif
42188 + return;
42189 +}
42190 +
42191 +int
42192 +gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
42193 +{
42194 +#ifdef CONFIG_GRKERNSEC_ROFS
42195 + if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
42196 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
42197 + return -EPERM;
42198 + } else
42199 + return 0;
42200 +#endif
42201 + return 0;
42202 +}
42203 +
42204 +int
42205 +gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
42206 +{
42207 +#ifdef CONFIG_GRKERNSEC_ROFS
42208 + if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
42209 + dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
42210 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
42211 + return -EPERM;
42212 + } else
42213 + return 0;
42214 +#endif
42215 + return 0;
42216 +}
42217 diff -urNp linux-2.6.37/grsecurity/grsec_pax.c linux-2.6.37/grsecurity/grsec_pax.c
42218 --- linux-2.6.37/grsecurity/grsec_pax.c 1969-12-31 19:00:00.000000000 -0500
42219 +++ linux-2.6.37/grsecurity/grsec_pax.c 2011-01-17 02:41:02.000000000 -0500
42220 @@ -0,0 +1,36 @@
42221 +#include <linux/kernel.h>
42222 +#include <linux/sched.h>
42223 +#include <linux/mm.h>
42224 +#include <linux/file.h>
42225 +#include <linux/grinternal.h>
42226 +#include <linux/grsecurity.h>
42227 +
42228 +void
42229 +gr_log_textrel(struct vm_area_struct * vma)
42230 +{
42231 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
42232 + if (grsec_enable_audit_textrel)
42233 + gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
42234 +#endif
42235 + return;
42236 +}
42237 +
42238 +void
42239 +gr_log_rwxmmap(struct file *file)
42240 +{
42241 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
42242 + if (grsec_enable_log_rwxmaps)
42243 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
42244 +#endif
42245 + return;
42246 +}
42247 +
42248 +void
42249 +gr_log_rwxmprotect(struct file *file)
42250 +{
42251 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
42252 + if (grsec_enable_log_rwxmaps)
42253 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
42254 +#endif
42255 + return;
42256 +}
42257 diff -urNp linux-2.6.37/grsecurity/grsec_ptrace.c linux-2.6.37/grsecurity/grsec_ptrace.c
42258 --- linux-2.6.37/grsecurity/grsec_ptrace.c 1969-12-31 19:00:00.000000000 -0500
42259 +++ linux-2.6.37/grsecurity/grsec_ptrace.c 2011-01-17 02:41:02.000000000 -0500
42260 @@ -0,0 +1,14 @@
42261 +#include <linux/kernel.h>
42262 +#include <linux/sched.h>
42263 +#include <linux/grinternal.h>
42264 +#include <linux/grsecurity.h>
42265 +
42266 +void
42267 +gr_audit_ptrace(struct task_struct *task)
42268 +{
42269 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
42270 + if (grsec_enable_audit_ptrace)
42271 + gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
42272 +#endif
42273 + return;
42274 +}
42275 diff -urNp linux-2.6.37/grsecurity/grsec_sig.c linux-2.6.37/grsecurity/grsec_sig.c
42276 --- linux-2.6.37/grsecurity/grsec_sig.c 1969-12-31 19:00:00.000000000 -0500
42277 +++ linux-2.6.37/grsecurity/grsec_sig.c 2011-01-17 02:41:02.000000000 -0500
42278 @@ -0,0 +1,65 @@
42279 +#include <linux/kernel.h>
42280 +#include <linux/sched.h>
42281 +#include <linux/delay.h>
42282 +#include <linux/grsecurity.h>
42283 +#include <linux/grinternal.h>
42284 +
42285 +char *signames[] = {
42286 + [SIGSEGV] = "Segmentation fault",
42287 + [SIGILL] = "Illegal instruction",
42288 + [SIGABRT] = "Abort",
42289 + [SIGBUS] = "Invalid alignment/Bus error"
42290 +};
42291 +
42292 +void
42293 +gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
42294 +{
42295 +#ifdef CONFIG_GRKERNSEC_SIGNAL
42296 + if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
42297 + (sig == SIGABRT) || (sig == SIGBUS))) {
42298 + if (t->pid == current->pid) {
42299 + gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
42300 + } else {
42301 + gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
42302 + }
42303 + }
42304 +#endif
42305 + return;
42306 +}
42307 +
42308 +int
42309 +gr_handle_signal(const struct task_struct *p, const int sig)
42310 +{
42311 +#ifdef CONFIG_GRKERNSEC
42312 + if (current->pid > 1 && gr_check_protected_task(p)) {
42313 + gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
42314 + return -EPERM;
42315 + } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
42316 + return -EPERM;
42317 + }
42318 +#endif
42319 + return 0;
42320 +}
42321 +
42322 +void gr_handle_brute_attach(struct task_struct *p)
42323 +{
42324 +#ifdef CONFIG_GRKERNSEC_BRUTE
42325 + read_lock(&tasklist_lock);
42326 + read_lock(&grsec_exec_file_lock);
42327 + if (p->real_parent && p->real_parent->exec_file == p->exec_file)
42328 + p->real_parent->brute = 1;
42329 + read_unlock(&grsec_exec_file_lock);
42330 + read_unlock(&tasklist_lock);
42331 +#endif
42332 + return;
42333 +}
42334 +
42335 +void gr_handle_brute_check(void)
42336 +{
42337 +#ifdef CONFIG_GRKERNSEC_BRUTE
42338 + if (current->brute)
42339 + msleep(30 * 1000);
42340 +#endif
42341 + return;
42342 +}
42343 +
42344 diff -urNp linux-2.6.37/grsecurity/grsec_sock.c linux-2.6.37/grsecurity/grsec_sock.c
42345 --- linux-2.6.37/grsecurity/grsec_sock.c 1969-12-31 19:00:00.000000000 -0500
42346 +++ linux-2.6.37/grsecurity/grsec_sock.c 2011-01-17 02:41:02.000000000 -0500
42347 @@ -0,0 +1,275 @@
42348 +#include <linux/kernel.h>
42349 +#include <linux/module.h>
42350 +#include <linux/sched.h>
42351 +#include <linux/file.h>
42352 +#include <linux/net.h>
42353 +#include <linux/in.h>
42354 +#include <linux/ip.h>
42355 +#include <net/sock.h>
42356 +#include <net/inet_sock.h>
42357 +#include <linux/grsecurity.h>
42358 +#include <linux/grinternal.h>
42359 +#include <linux/gracl.h>
42360 +
42361 +kernel_cap_t gr_cap_rtnetlink(struct sock *sock);
42362 +EXPORT_SYMBOL(gr_cap_rtnetlink);
42363 +
42364 +extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
42365 +extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
42366 +
42367 +EXPORT_SYMBOL(gr_search_udp_recvmsg);
42368 +EXPORT_SYMBOL(gr_search_udp_sendmsg);
42369 +
42370 +#ifdef CONFIG_UNIX_MODULE
42371 +EXPORT_SYMBOL(gr_acl_handle_unix);
42372 +EXPORT_SYMBOL(gr_acl_handle_mknod);
42373 +EXPORT_SYMBOL(gr_handle_chroot_unix);
42374 +EXPORT_SYMBOL(gr_handle_create);
42375 +#endif
42376 +
42377 +#ifdef CONFIG_GRKERNSEC
42378 +#define gr_conn_table_size 32749
42379 +struct conn_table_entry {
42380 + struct conn_table_entry *next;
42381 + struct signal_struct *sig;
42382 +};
42383 +
42384 +struct conn_table_entry *gr_conn_table[gr_conn_table_size];
42385 +DEFINE_SPINLOCK(gr_conn_table_lock);
42386 +
42387 +extern const char * gr_socktype_to_name(unsigned char type);
42388 +extern const char * gr_proto_to_name(unsigned char proto);
42389 +extern const char * gr_sockfamily_to_name(unsigned char family);
42390 +
42391 +static __inline__ int
42392 +conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
42393 +{
42394 + return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
42395 +}
42396 +
42397 +static __inline__ int
42398 +conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
42399 + __u16 sport, __u16 dport)
42400 +{
42401 + if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
42402 + sig->gr_sport == sport && sig->gr_dport == dport))
42403 + return 1;
42404 + else
42405 + return 0;
42406 +}
42407 +
42408 +static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
42409 +{
42410 + struct conn_table_entry **match;
42411 + unsigned int index;
42412 +
42413 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
42414 + sig->gr_sport, sig->gr_dport,
42415 + gr_conn_table_size);
42416 +
42417 + newent->sig = sig;
42418 +
42419 + match = &gr_conn_table[index];
42420 + newent->next = *match;
42421 + *match = newent;
42422 +
42423 + return;
42424 +}
42425 +
42426 +static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
42427 +{
42428 + struct conn_table_entry *match, *last = NULL;
42429 + unsigned int index;
42430 +
42431 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
42432 + sig->gr_sport, sig->gr_dport,
42433 + gr_conn_table_size);
42434 +
42435 + match = gr_conn_table[index];
42436 + while (match && !conn_match(match->sig,
42437 + sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
42438 + sig->gr_dport)) {
42439 + last = match;
42440 + match = match->next;
42441 + }
42442 +
42443 + if (match) {
42444 + if (last)
42445 + last->next = match->next;
42446 + else
42447 + gr_conn_table[index] = NULL;
42448 + kfree(match);
42449 + }
42450 +
42451 + return;
42452 +}
42453 +
42454 +static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
42455 + __u16 sport, __u16 dport)
42456 +{
42457 + struct conn_table_entry *match;
42458 + unsigned int index;
42459 +
42460 + index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
42461 +
42462 + match = gr_conn_table[index];
42463 + while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
42464 + match = match->next;
42465 +
42466 + if (match)
42467 + return match->sig;
42468 + else
42469 + return NULL;
42470 +}
42471 +
42472 +#endif
42473 +
42474 +void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
42475 +{
42476 +#ifdef CONFIG_GRKERNSEC
42477 + struct signal_struct *sig = task->signal;
42478 + struct conn_table_entry *newent;
42479 +
42480 + newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
42481 + if (newent == NULL)
42482 + return;
42483 + /* no bh lock needed since we are called with bh disabled */
42484 + spin_lock(&gr_conn_table_lock);
42485 + gr_del_task_from_ip_table_nolock(sig);
42486 + sig->gr_saddr = inet->inet_rcv_saddr;
42487 + sig->gr_daddr = inet->inet_daddr;
42488 + sig->gr_sport = inet->inet_sport;
42489 + sig->gr_dport = inet->inet_dport;
42490 + gr_add_to_task_ip_table_nolock(sig, newent);
42491 + spin_unlock(&gr_conn_table_lock);
42492 +#endif
42493 + return;
42494 +}
42495 +
42496 +void gr_del_task_from_ip_table(struct task_struct *task)
42497 +{
42498 +#ifdef CONFIG_GRKERNSEC
42499 + spin_lock_bh(&gr_conn_table_lock);
42500 + gr_del_task_from_ip_table_nolock(task->signal);
42501 + spin_unlock_bh(&gr_conn_table_lock);
42502 +#endif
42503 + return;
42504 +}
42505 +
42506 +void
42507 +gr_attach_curr_ip(const struct sock *sk)
42508 +{
42509 +#ifdef CONFIG_GRKERNSEC
42510 + struct signal_struct *p, *set;
42511 + const struct inet_sock *inet = inet_sk(sk);
42512 +
42513 + if (unlikely(sk->sk_protocol != IPPROTO_TCP))
42514 + return;
42515 +
42516 + set = current->signal;
42517 +
42518 + spin_lock_bh(&gr_conn_table_lock);
42519 + p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
42520 + inet->inet_dport, inet->inet_sport);
42521 + if (unlikely(p != NULL)) {
42522 + set->curr_ip = p->curr_ip;
42523 + set->used_accept = 1;
42524 + gr_del_task_from_ip_table_nolock(p);
42525 + spin_unlock_bh(&gr_conn_table_lock);
42526 + return;
42527 + }
42528 + spin_unlock_bh(&gr_conn_table_lock);
42529 +
42530 + set->curr_ip = inet->inet_daddr;
42531 + set->used_accept = 1;
42532 +#endif
42533 + return;
42534 +}
42535 +
42536 +int
42537 +gr_handle_sock_all(const int family, const int type, const int protocol)
42538 +{
42539 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
42540 + if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
42541 + (family != AF_UNIX)) {
42542 + if (family == AF_INET)
42543 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
42544 + else
42545 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
42546 + return -EACCES;
42547 + }
42548 +#endif
42549 + return 0;
42550 +}
42551 +
42552 +int
42553 +gr_handle_sock_server(const struct sockaddr *sck)
42554 +{
42555 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
42556 + if (grsec_enable_socket_server &&
42557 + in_group_p(grsec_socket_server_gid) &&
42558 + sck && (sck->sa_family != AF_UNIX) &&
42559 + (sck->sa_family != AF_LOCAL)) {
42560 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
42561 + return -EACCES;
42562 + }
42563 +#endif
42564 + return 0;
42565 +}
42566 +
42567 +int
42568 +gr_handle_sock_server_other(const struct sock *sck)
42569 +{
42570 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
42571 + if (grsec_enable_socket_server &&
42572 + in_group_p(grsec_socket_server_gid) &&
42573 + sck && (sck->sk_family != AF_UNIX) &&
42574 + (sck->sk_family != AF_LOCAL)) {
42575 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
42576 + return -EACCES;
42577 + }
42578 +#endif
42579 + return 0;
42580 +}
42581 +
42582 +int
42583 +gr_handle_sock_client(const struct sockaddr *sck)
42584 +{
42585 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
42586 + if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
42587 + sck && (sck->sa_family != AF_UNIX) &&
42588 + (sck->sa_family != AF_LOCAL)) {
42589 + gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
42590 + return -EACCES;
42591 + }
42592 +#endif
42593 + return 0;
42594 +}
42595 +
42596 +kernel_cap_t
42597 +gr_cap_rtnetlink(struct sock *sock)
42598 +{
42599 +#ifdef CONFIG_GRKERNSEC
42600 + if (!gr_acl_is_enabled())
42601 + return current_cap();
42602 + else if (sock->sk_protocol == NETLINK_ISCSI &&
42603 + cap_raised(current_cap(), CAP_SYS_ADMIN) &&
42604 + gr_is_capable(CAP_SYS_ADMIN))
42605 + return current_cap();
42606 + else if (sock->sk_protocol == NETLINK_AUDIT &&
42607 + cap_raised(current_cap(), CAP_AUDIT_WRITE) &&
42608 + gr_is_capable(CAP_AUDIT_WRITE) &&
42609 + cap_raised(current_cap(), CAP_AUDIT_CONTROL) &&
42610 + gr_is_capable(CAP_AUDIT_CONTROL))
42611 + return current_cap();
42612 + else if (cap_raised(current_cap(), CAP_NET_ADMIN) &&
42613 + ((sock->sk_protocol == NETLINK_ROUTE) ?
42614 + gr_is_capable_nolog(CAP_NET_ADMIN) :
42615 + gr_is_capable(CAP_NET_ADMIN)))
42616 + return current_cap();
42617 + else
42618 + return __cap_empty_set;
42619 +#else
42620 + return current_cap();
42621 +#endif
42622 +}
42623 diff -urNp linux-2.6.37/grsecurity/grsec_sysctl.c linux-2.6.37/grsecurity/grsec_sysctl.c
42624 --- linux-2.6.37/grsecurity/grsec_sysctl.c 1969-12-31 19:00:00.000000000 -0500
42625 +++ linux-2.6.37/grsecurity/grsec_sysctl.c 2011-01-17 02:41:02.000000000 -0500
42626 @@ -0,0 +1,433 @@
42627 +#include <linux/kernel.h>
42628 +#include <linux/sched.h>
42629 +#include <linux/sysctl.h>
42630 +#include <linux/grsecurity.h>
42631 +#include <linux/grinternal.h>
42632 +
42633 +int
42634 +gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
42635 +{
42636 +#ifdef CONFIG_GRKERNSEC_SYSCTL
42637 + if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
42638 + gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
42639 + return -EACCES;
42640 + }
42641 +#endif
42642 + return 0;
42643 +}
42644 +
42645 +#ifdef CONFIG_GRKERNSEC_ROFS
42646 +static int __maybe_unused one = 1;
42647 +#endif
42648 +
42649 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
42650 +struct ctl_table grsecurity_table[] = {
42651 +#ifdef CONFIG_GRKERNSEC_SYSCTL
42652 +#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
42653 +#ifdef CONFIG_GRKERNSEC_IO
42654 + {
42655 + .procname = "disable_priv_io",
42656 + .data = &grsec_disable_privio,
42657 + .maxlen = sizeof(int),
42658 + .mode = 0600,
42659 + .proc_handler = &proc_dointvec,
42660 + },
42661 +#endif
42662 +#endif
42663 +#ifdef CONFIG_GRKERNSEC_LINK
42664 + {
42665 + .procname = "linking_restrictions",
42666 + .data = &grsec_enable_link,
42667 + .maxlen = sizeof(int),
42668 + .mode = 0600,
42669 + .proc_handler = &proc_dointvec,
42670 + },
42671 +#endif
42672 +#ifdef CONFIG_GRKERNSEC_FIFO
42673 + {
42674 + .procname = "fifo_restrictions",
42675 + .data = &grsec_enable_fifo,
42676 + .maxlen = sizeof(int),
42677 + .mode = 0600,
42678 + .proc_handler = &proc_dointvec,
42679 + },
42680 +#endif
42681 +#ifdef CONFIG_GRKERNSEC_EXECVE
42682 + {
42683 + .procname = "execve_limiting",
42684 + .data = &grsec_enable_execve,
42685 + .maxlen = sizeof(int),
42686 + .mode = 0600,
42687 + .proc_handler = &proc_dointvec,
42688 + },
42689 +#endif
42690 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
42691 + {
42692 + .procname = "ip_blackhole",
42693 + .data = &grsec_enable_blackhole,
42694 + .maxlen = sizeof(int),
42695 + .mode = 0600,
42696 + .proc_handler = &proc_dointvec,
42697 + },
42698 + {
42699 + .procname = "lastack_retries",
42700 + .data = &grsec_lastack_retries,
42701 + .maxlen = sizeof(int),
42702 + .mode = 0600,
42703 + .proc_handler = &proc_dointvec,
42704 + },
42705 +#endif
42706 +#ifdef CONFIG_GRKERNSEC_EXECLOG
42707 + {
42708 + .procname = "exec_logging",
42709 + .data = &grsec_enable_execlog,
42710 + .maxlen = sizeof(int),
42711 + .mode = 0600,
42712 + .proc_handler = &proc_dointvec,
42713 + },
42714 +#endif
42715 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
42716 + {
42717 + .procname = "rwxmap_logging",
42718 + .data = &grsec_enable_log_rwxmaps,
42719 + .maxlen = sizeof(int),
42720 + .mode = 0600,
42721 + .proc_handler = &proc_dointvec,
42722 + },
42723 +#endif
42724 +#ifdef CONFIG_GRKERNSEC_SIGNAL
42725 + {
42726 + .procname = "signal_logging",
42727 + .data = &grsec_enable_signal,
42728 + .maxlen = sizeof(int),
42729 + .mode = 0600,
42730 + .proc_handler = &proc_dointvec,
42731 + },
42732 +#endif
42733 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
42734 + {
42735 + .procname = "forkfail_logging",
42736 + .data = &grsec_enable_forkfail,
42737 + .maxlen = sizeof(int),
42738 + .mode = 0600,
42739 + .proc_handler = &proc_dointvec,
42740 + },
42741 +#endif
42742 +#ifdef CONFIG_GRKERNSEC_TIME
42743 + {
42744 + .procname = "timechange_logging",
42745 + .data = &grsec_enable_time,
42746 + .maxlen = sizeof(int),
42747 + .mode = 0600,
42748 + .proc_handler = &proc_dointvec,
42749 + },
42750 +#endif
42751 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
42752 + {
42753 + .procname = "chroot_deny_shmat",
42754 + .data = &grsec_enable_chroot_shmat,
42755 + .maxlen = sizeof(int),
42756 + .mode = 0600,
42757 + .proc_handler = &proc_dointvec,
42758 + },
42759 +#endif
42760 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
42761 + {
42762 + .procname = "chroot_deny_unix",
42763 + .data = &grsec_enable_chroot_unix,
42764 + .maxlen = sizeof(int),
42765 + .mode = 0600,
42766 + .proc_handler = &proc_dointvec,
42767 + },
42768 +#endif
42769 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
42770 + {
42771 + .procname = "chroot_deny_mount",
42772 + .data = &grsec_enable_chroot_mount,
42773 + .maxlen = sizeof(int),
42774 + .mode = 0600,
42775 + .proc_handler = &proc_dointvec,
42776 + },
42777 +#endif
42778 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
42779 + {
42780 + .procname = "chroot_deny_fchdir",
42781 + .data = &grsec_enable_chroot_fchdir,
42782 + .maxlen = sizeof(int),
42783 + .mode = 0600,
42784 + .proc_handler = &proc_dointvec,
42785 + },
42786 +#endif
42787 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
42788 + {
42789 + .procname = "chroot_deny_chroot",
42790 + .data = &grsec_enable_chroot_double,
42791 + .maxlen = sizeof(int),
42792 + .mode = 0600,
42793 + .proc_handler = &proc_dointvec,
42794 + },
42795 +#endif
42796 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
42797 + {
42798 + .procname = "chroot_deny_pivot",
42799 + .data = &grsec_enable_chroot_pivot,
42800 + .maxlen = sizeof(int),
42801 + .mode = 0600,
42802 + .proc_handler = &proc_dointvec,
42803 + },
42804 +#endif
42805 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
42806 + {
42807 + .procname = "chroot_enforce_chdir",
42808 + .data = &grsec_enable_chroot_chdir,
42809 + .maxlen = sizeof(int),
42810 + .mode = 0600,
42811 + .proc_handler = &proc_dointvec,
42812 + },
42813 +#endif
42814 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
42815 + {
42816 + .procname = "chroot_deny_chmod",
42817 + .data = &grsec_enable_chroot_chmod,
42818 + .maxlen = sizeof(int),
42819 + .mode = 0600,
42820 + .proc_handler = &proc_dointvec,
42821 + },
42822 +#endif
42823 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
42824 + {
42825 + .procname = "chroot_deny_mknod",
42826 + .data = &grsec_enable_chroot_mknod,
42827 + .maxlen = sizeof(int),
42828 + .mode = 0600,
42829 + .proc_handler = &proc_dointvec,
42830 + },
42831 +#endif
42832 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
42833 + {
42834 + .procname = "chroot_restrict_nice",
42835 + .data = &grsec_enable_chroot_nice,
42836 + .maxlen = sizeof(int),
42837 + .mode = 0600,
42838 + .proc_handler = &proc_dointvec,
42839 + },
42840 +#endif
42841 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
42842 + {
42843 + .procname = "chroot_execlog",
42844 + .data = &grsec_enable_chroot_execlog,
42845 + .maxlen = sizeof(int),
42846 + .mode = 0600,
42847 + .proc_handler = &proc_dointvec,
42848 + },
42849 +#endif
42850 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
42851 + {
42852 + .procname = "chroot_caps",
42853 + .data = &grsec_enable_chroot_caps,
42854 + .maxlen = sizeof(int),
42855 + .mode = 0600,
42856 + .proc_handler = &proc_dointvec,
42857 + },
42858 +#endif
42859 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
42860 + {
42861 + .procname = "chroot_deny_sysctl",
42862 + .data = &grsec_enable_chroot_sysctl,
42863 + .maxlen = sizeof(int),
42864 + .mode = 0600,
42865 + .proc_handler = &proc_dointvec,
42866 + },
42867 +#endif
42868 +#ifdef CONFIG_GRKERNSEC_TPE
42869 + {
42870 + .procname = "tpe",
42871 + .data = &grsec_enable_tpe,
42872 + .maxlen = sizeof(int),
42873 + .mode = 0600,
42874 + .proc_handler = &proc_dointvec,
42875 + },
42876 + {
42877 + .procname = "tpe_gid",
42878 + .data = &grsec_tpe_gid,
42879 + .maxlen = sizeof(int),
42880 + .mode = 0600,
42881 + .proc_handler = &proc_dointvec,
42882 + },
42883 +#endif
42884 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
42885 + {
42886 + .procname = "tpe_invert",
42887 + .data = &grsec_enable_tpe_invert,
42888 + .maxlen = sizeof(int),
42889 + .mode = 0600,
42890 + .proc_handler = &proc_dointvec,
42891 + },
42892 +#endif
42893 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
42894 + {
42895 + .procname = "tpe_restrict_all",
42896 + .data = &grsec_enable_tpe_all,
42897 + .maxlen = sizeof(int),
42898 + .mode = 0600,
42899 + .proc_handler = &proc_dointvec,
42900 + },
42901 +#endif
42902 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
42903 + {
42904 + .procname = "socket_all",
42905 + .data = &grsec_enable_socket_all,
42906 + .maxlen = sizeof(int),
42907 + .mode = 0600,
42908 + .proc_handler = &proc_dointvec,
42909 + },
42910 + {
42911 + .procname = "socket_all_gid",
42912 + .data = &grsec_socket_all_gid,
42913 + .maxlen = sizeof(int),
42914 + .mode = 0600,
42915 + .proc_handler = &proc_dointvec,
42916 + },
42917 +#endif
42918 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
42919 + {
42920 + .procname = "socket_client",
42921 + .data = &grsec_enable_socket_client,
42922 + .maxlen = sizeof(int),
42923 + .mode = 0600,
42924 + .proc_handler = &proc_dointvec,
42925 + },
42926 + {
42927 + .procname = "socket_client_gid",
42928 + .data = &grsec_socket_client_gid,
42929 + .maxlen = sizeof(int),
42930 + .mode = 0600,
42931 + .proc_handler = &proc_dointvec,
42932 + },
42933 +#endif
42934 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
42935 + {
42936 + .procname = "socket_server",
42937 + .data = &grsec_enable_socket_server,
42938 + .maxlen = sizeof(int),
42939 + .mode = 0600,
42940 + .proc_handler = &proc_dointvec,
42941 + },
42942 + {
42943 + .procname = "socket_server_gid",
42944 + .data = &grsec_socket_server_gid,
42945 + .maxlen = sizeof(int),
42946 + .mode = 0600,
42947 + .proc_handler = &proc_dointvec,
42948 + },
42949 +#endif
42950 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
42951 + {
42952 + .procname = "audit_group",
42953 + .data = &grsec_enable_group,
42954 + .maxlen = sizeof(int),
42955 + .mode = 0600,
42956 + .proc_handler = &proc_dointvec,
42957 + },
42958 + {
42959 + .procname = "audit_gid",
42960 + .data = &grsec_audit_gid,
42961 + .maxlen = sizeof(int),
42962 + .mode = 0600,
42963 + .proc_handler = &proc_dointvec,
42964 + },
42965 +#endif
42966 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
42967 + {
42968 + .procname = "audit_chdir",
42969 + .data = &grsec_enable_chdir,
42970 + .maxlen = sizeof(int),
42971 + .mode = 0600,
42972 + .proc_handler = &proc_dointvec,
42973 + },
42974 +#endif
42975 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
42976 + {
42977 + .procname = "audit_mount",
42978 + .data = &grsec_enable_mount,
42979 + .maxlen = sizeof(int),
42980 + .mode = 0600,
42981 + .proc_handler = &proc_dointvec,
42982 + },
42983 +#endif
42984 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
42985 + {
42986 + .procname = "audit_textrel",
42987 + .data = &grsec_enable_audit_textrel,
42988 + .maxlen = sizeof(int),
42989 + .mode = 0600,
42990 + .proc_handler = &proc_dointvec,
42991 + },
42992 +#endif
42993 +#ifdef CONFIG_GRKERNSEC_DMESG
42994 + {
42995 + .procname = "dmesg",
42996 + .data = &grsec_enable_dmesg,
42997 + .maxlen = sizeof(int),
42998 + .mode = 0600,
42999 + .proc_handler = &proc_dointvec,
43000 + },
43001 +#endif
43002 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
43003 + {
43004 + .procname = "chroot_findtask",
43005 + .data = &grsec_enable_chroot_findtask,
43006 + .maxlen = sizeof(int),
43007 + .mode = 0600,
43008 + .proc_handler = &proc_dointvec,
43009 + },
43010 +#endif
43011 +#ifdef CONFIG_GRKERNSEC_RESLOG
43012 + {
43013 + .procname = "resource_logging",
43014 + .data = &grsec_resource_logging,
43015 + .maxlen = sizeof(int),
43016 + .mode = 0600,
43017 + .proc_handler = &proc_dointvec,
43018 + },
43019 +#endif
43020 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
43021 + {
43022 + .procname = "audit_ptrace",
43023 + .data = &grsec_enable_audit_ptrace,
43024 + .maxlen = sizeof(int),
43025 + .mode = 0600,
43026 + .proc_handler = &proc_dointvec,
43027 + },
43028 +#endif
43029 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
43030 + {
43031 + .procname = "harden_ptrace",
43032 + .data = &grsec_enable_harden_ptrace,
43033 + .maxlen = sizeof(int),
43034 + .mode = 0600,
43035 + .proc_handler = &proc_dointvec,
43036 + },
43037 +#endif
43038 + {
43039 + .procname = "grsec_lock",
43040 + .data = &grsec_lock,
43041 + .maxlen = sizeof(int),
43042 + .mode = 0600,
43043 + .proc_handler = &proc_dointvec,
43044 + },
43045 +#endif
43046 +#ifdef CONFIG_GRKERNSEC_ROFS
43047 + {
43048 + .procname = "romount_protect",
43049 + .data = &grsec_enable_rofs,
43050 + .maxlen = sizeof(int),
43051 + .mode = 0600,
43052 + .proc_handler = &proc_dointvec_minmax,
43053 + .extra1 = &one,
43054 + .extra2 = &one,
43055 + },
43056 +#endif
43057 + { }
43058 +};
43059 +#endif
43060 diff -urNp linux-2.6.37/grsecurity/grsec_time.c linux-2.6.37/grsecurity/grsec_time.c
43061 --- linux-2.6.37/grsecurity/grsec_time.c 1969-12-31 19:00:00.000000000 -0500
43062 +++ linux-2.6.37/grsecurity/grsec_time.c 2011-01-17 02:41:02.000000000 -0500
43063 @@ -0,0 +1,16 @@
43064 +#include <linux/kernel.h>
43065 +#include <linux/sched.h>
43066 +#include <linux/grinternal.h>
43067 +#include <linux/module.h>
43068 +
43069 +void
43070 +gr_log_timechange(void)
43071 +{
43072 +#ifdef CONFIG_GRKERNSEC_TIME
43073 + if (grsec_enable_time)
43074 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
43075 +#endif
43076 + return;
43077 +}
43078 +
43079 +EXPORT_SYMBOL(gr_log_timechange);
43080 diff -urNp linux-2.6.37/grsecurity/grsec_tpe.c linux-2.6.37/grsecurity/grsec_tpe.c
43081 --- linux-2.6.37/grsecurity/grsec_tpe.c 1969-12-31 19:00:00.000000000 -0500
43082 +++ linux-2.6.37/grsecurity/grsec_tpe.c 2011-01-17 02:41:02.000000000 -0500
43083 @@ -0,0 +1,39 @@
43084 +#include <linux/kernel.h>
43085 +#include <linux/sched.h>
43086 +#include <linux/file.h>
43087 +#include <linux/fs.h>
43088 +#include <linux/grinternal.h>
43089 +
43090 +extern int gr_acl_tpe_check(void);
43091 +
43092 +int
43093 +gr_tpe_allow(const struct file *file)
43094 +{
43095 +#ifdef CONFIG_GRKERNSEC
43096 + struct inode *inode = file->f_path.dentry->d_parent->d_inode;
43097 + const struct cred *cred = current_cred();
43098 +
43099 + if (cred->uid && ((grsec_enable_tpe &&
43100 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
43101 + ((grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid)) ||
43102 + (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid)))
43103 +#else
43104 + in_group_p(grsec_tpe_gid)
43105 +#endif
43106 + ) || gr_acl_tpe_check()) &&
43107 + (inode->i_uid || (!inode->i_uid && ((inode->i_mode & S_IWGRP) ||
43108 + (inode->i_mode & S_IWOTH))))) {
43109 + gr_log_fs_generic(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, file->f_path.dentry, file->f_path.mnt);
43110 + return 0;
43111 + }
43112 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
43113 + if (cred->uid && grsec_enable_tpe && grsec_enable_tpe_all &&
43114 + ((inode->i_uid && (inode->i_uid != cred->uid)) ||
43115 + (inode->i_mode & S_IWGRP) || (inode->i_mode & S_IWOTH))) {
43116 + gr_log_fs_generic(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, file->f_path.dentry, file->f_path.mnt);
43117 + return 0;
43118 + }
43119 +#endif
43120 +#endif
43121 + return 1;
43122 +}
43123 diff -urNp linux-2.6.37/grsecurity/grsum.c linux-2.6.37/grsecurity/grsum.c
43124 --- linux-2.6.37/grsecurity/grsum.c 1969-12-31 19:00:00.000000000 -0500
43125 +++ linux-2.6.37/grsecurity/grsum.c 2011-01-17 02:41:02.000000000 -0500
43126 @@ -0,0 +1,61 @@
43127 +#include <linux/err.h>
43128 +#include <linux/kernel.h>
43129 +#include <linux/sched.h>
43130 +#include <linux/mm.h>
43131 +#include <linux/scatterlist.h>
43132 +#include <linux/crypto.h>
43133 +#include <linux/gracl.h>
43134 +
43135 +
43136 +#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
43137 +#error "crypto and sha256 must be built into the kernel"
43138 +#endif
43139 +
43140 +int
43141 +chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
43142 +{
43143 + char *p;
43144 + struct crypto_hash *tfm;
43145 + struct hash_desc desc;
43146 + struct scatterlist sg;
43147 + unsigned char temp_sum[GR_SHA_LEN];
43148 + volatile int retval = 0;
43149 + volatile int dummy = 0;
43150 + unsigned int i;
43151 +
43152 + sg_init_table(&sg, 1);
43153 +
43154 + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
43155 + if (IS_ERR(tfm)) {
43156 + /* should never happen, since sha256 should be built in */
43157 + return 1;
43158 + }
43159 +
43160 + desc.tfm = tfm;
43161 + desc.flags = 0;
43162 +
43163 + crypto_hash_init(&desc);
43164 +
43165 + p = salt;
43166 + sg_set_buf(&sg, p, GR_SALT_LEN);
43167 + crypto_hash_update(&desc, &sg, sg.length);
43168 +
43169 + p = entry->pw;
43170 + sg_set_buf(&sg, p, strlen(p));
43171 +
43172 + crypto_hash_update(&desc, &sg, sg.length);
43173 +
43174 + crypto_hash_final(&desc, temp_sum);
43175 +
43176 + memset(entry->pw, 0, GR_PW_LEN);
43177 +
43178 + for (i = 0; i < GR_SHA_LEN; i++)
43179 + if (sum[i] != temp_sum[i])
43180 + retval = 1;
43181 + else
43182 + dummy = 1; // waste a cycle
43183 +
43184 + crypto_free_hash(tfm);
43185 +
43186 + return retval;
43187 +}
43188 diff -urNp linux-2.6.37/grsecurity/Kconfig linux-2.6.37/grsecurity/Kconfig
43189 --- linux-2.6.37/grsecurity/Kconfig 1969-12-31 19:00:00.000000000 -0500
43190 +++ linux-2.6.37/grsecurity/Kconfig 2011-01-17 02:41:02.000000000 -0500
43191 @@ -0,0 +1,1000 @@
43192 +#
43193 +# grecurity configuration
43194 +#
43195 +
43196 +menu "Grsecurity"
43197 +
43198 +config GRKERNSEC
43199 + bool "Grsecurity"
43200 + select CRYPTO
43201 + select CRYPTO_SHA256
43202 + help
43203 + If you say Y here, you will be able to configure many features
43204 + that will enhance the security of your system. It is highly
43205 + recommended that you say Y here and read through the help
43206 + for each option so that you fully understand the features and
43207 + can evaluate their usefulness for your machine.
43208 +
43209 +choice
43210 + prompt "Security Level"
43211 + depends on GRKERNSEC
43212 + default GRKERNSEC_CUSTOM
43213 +
43214 +config GRKERNSEC_LOW
43215 + bool "Low"
43216 + select GRKERNSEC_LINK
43217 + select GRKERNSEC_FIFO
43218 + select GRKERNSEC_EXECVE
43219 + select GRKERNSEC_RANDNET
43220 + select GRKERNSEC_DMESG
43221 + select GRKERNSEC_CHROOT
43222 + select GRKERNSEC_CHROOT_CHDIR
43223 +
43224 + help
43225 + If you choose this option, several of the grsecurity options will
43226 + be enabled that will give you greater protection against a number
43227 + of attacks, while assuring that none of your software will have any
43228 + conflicts with the additional security measures. If you run a lot
43229 + of unusual software, or you are having problems with the higher
43230 + security levels, you should say Y here. With this option, the
43231 + following features are enabled:
43232 +
43233 + - Linking restrictions
43234 + - FIFO restrictions
43235 + - Enforcing RLIMIT_NPROC on execve
43236 + - Restricted dmesg
43237 + - Enforced chdir("/") on chroot
43238 + - Runtime module disabling
43239 +
43240 +config GRKERNSEC_MEDIUM
43241 + bool "Medium"
43242 + select PAX
43243 + select PAX_EI_PAX
43244 + select PAX_PT_PAX_FLAGS
43245 + select PAX_HAVE_ACL_FLAGS
43246 + select GRKERNSEC_PROC_MEMMAP if (PAX_NOEXEC || PAX_ASLR)
43247 + select GRKERNSEC_CHROOT
43248 + select GRKERNSEC_CHROOT_SYSCTL
43249 + select GRKERNSEC_LINK
43250 + select GRKERNSEC_FIFO
43251 + select GRKERNSEC_EXECVE
43252 + select GRKERNSEC_DMESG
43253 + select GRKERNSEC_RANDNET
43254 + select GRKERNSEC_FORKFAIL
43255 + select GRKERNSEC_TIME
43256 + select GRKERNSEC_SIGNAL
43257 + select GRKERNSEC_CHROOT
43258 + select GRKERNSEC_CHROOT_UNIX
43259 + select GRKERNSEC_CHROOT_MOUNT
43260 + select GRKERNSEC_CHROOT_PIVOT
43261 + select GRKERNSEC_CHROOT_DOUBLE
43262 + select GRKERNSEC_CHROOT_CHDIR
43263 + select GRKERNSEC_CHROOT_MKNOD
43264 + select GRKERNSEC_PROC
43265 + select GRKERNSEC_PROC_USERGROUP
43266 + select PAX_RANDUSTACK
43267 + select PAX_ASLR
43268 + select PAX_RANDMMAP
43269 + select PAX_REFCOUNT if (X86 || SPARC64)
43270 + select PAX_USERCOPY if ((X86 || SPARC32 || SPARC64 || PPC) && (SLAB || SLUB || SLOB))
43271 +
43272 + help
43273 + If you say Y here, several features in addition to those included
43274 + in the low additional security level will be enabled. These
43275 + features provide even more security to your system, though in rare
43276 + cases they may be incompatible with very old or poorly written
43277 + software. If you enable this option, make sure that your auth
43278 + service (identd) is running as gid 1001. With this option,
43279 + the following features (in addition to those provided in the
43280 + low additional security level) will be enabled:
43281 +
43282 + - Failed fork logging
43283 + - Time change logging
43284 + - Signal logging
43285 + - Deny mounts in chroot
43286 + - Deny double chrooting
43287 + - Deny sysctl writes in chroot
43288 + - Deny mknod in chroot
43289 + - Deny access to abstract AF_UNIX sockets out of chroot
43290 + - Deny pivot_root in chroot
43291 + - Denied writes of /dev/kmem, /dev/mem, and /dev/port
43292 + - /proc restrictions with special GID set to 10 (usually wheel)
43293 + - Address Space Layout Randomization (ASLR)
43294 + - Prevent exploitation of most refcount overflows
43295 + - Bounds checking of copying between the kernel and userland
43296 +
43297 +config GRKERNSEC_HIGH
43298 + bool "High"
43299 + select GRKERNSEC_LINK
43300 + select GRKERNSEC_FIFO
43301 + select GRKERNSEC_EXECVE
43302 + select GRKERNSEC_DMESG
43303 + select GRKERNSEC_FORKFAIL
43304 + select GRKERNSEC_TIME
43305 + select GRKERNSEC_SIGNAL
43306 + select GRKERNSEC_CHROOT
43307 + select GRKERNSEC_CHROOT_SHMAT
43308 + select GRKERNSEC_CHROOT_UNIX
43309 + select GRKERNSEC_CHROOT_MOUNT
43310 + select GRKERNSEC_CHROOT_FCHDIR
43311 + select GRKERNSEC_CHROOT_PIVOT
43312 + select GRKERNSEC_CHROOT_DOUBLE
43313 + select GRKERNSEC_CHROOT_CHDIR
43314 + select GRKERNSEC_CHROOT_MKNOD
43315 + select GRKERNSEC_CHROOT_CAPS
43316 + select GRKERNSEC_CHROOT_SYSCTL
43317 + select GRKERNSEC_CHROOT_FINDTASK
43318 + select GRKERNSEC_PROC
43319 + select GRKERNSEC_PROC_MEMMAP if (PAX_NOEXEC || PAX_ASLR)
43320 + select GRKERNSEC_HIDESYM
43321 + select GRKERNSEC_BRUTE
43322 + select GRKERNSEC_PROC_USERGROUP
43323 + select GRKERNSEC_KMEM
43324 + select GRKERNSEC_RESLOG
43325 + select GRKERNSEC_RANDNET
43326 + select GRKERNSEC_PROC_ADD
43327 + select GRKERNSEC_CHROOT_CHMOD
43328 + select GRKERNSEC_CHROOT_NICE
43329 + select GRKERNSEC_AUDIT_MOUNT
43330 + select GRKERNSEC_MODHARDEN if (MODULES)
43331 + select GRKERNSEC_HARDEN_PTRACE
43332 + select GRKERNSEC_VM86 if (X86_32)
43333 + select PAX
43334 + select PAX_RANDUSTACK
43335 + select PAX_ASLR
43336 + select PAX_RANDMMAP
43337 + select PAX_NOEXEC
43338 + select PAX_MPROTECT
43339 + select PAX_EI_PAX
43340 + select PAX_PT_PAX_FLAGS
43341 + select PAX_HAVE_ACL_FLAGS
43342 + select PAX_KERNEXEC if ((PPC || X86) && (!X86_32 || X86_WP_WORKS_OK) && !XEN)
43343 + select PAX_MEMORY_UDEREF if (X86 && !XEN)
43344 + select PAX_RANDKSTACK if (X86_TSC && !X86_64)
43345 + select PAX_SEGMEXEC if (X86_32)
43346 + select PAX_PAGEEXEC
43347 + select PAX_EMUPLT if (ALPHA || PARISC || SPARC32 || SPARC64)
43348 + select PAX_EMUTRAMP if (PARISC)
43349 + select PAX_EMUSIGRT if (PARISC)
43350 + select PAX_ETEXECRELOCS if (ALPHA || IA64 || PARISC)
43351 + select PAX_ELFRELOCS if (PAX_ETEXECRELOCS || (IA64 || PPC || X86))
43352 + select PAX_REFCOUNT if (X86 || SPARC64)
43353 + select PAX_USERCOPY if ((X86 || PPC || SPARC32 || SPARC64) && (SLAB || SLUB || SLOB))
43354 + help
43355 + If you say Y here, many of the features of grsecurity will be
43356 + enabled, which will protect you against many kinds of attacks
43357 + against your system. The heightened security comes at a cost
43358 + of an increased chance of incompatibilities with rare software
43359 + on your machine. Since this security level enables PaX, you should
43360 + view <http://pax.grsecurity.net> and read about the PaX
43361 + project. While you are there, download chpax and run it on
43362 + binaries that cause problems with PaX. Also remember that
43363 + since the /proc restrictions are enabled, you must run your
43364 + identd as gid 1001. This security level enables the following
43365 + features in addition to those listed in the low and medium
43366 + security levels:
43367 +
43368 + - Additional /proc restrictions
43369 + - Chmod restrictions in chroot
43370 + - No signals, ptrace, or viewing of processes outside of chroot
43371 + - Capability restrictions in chroot
43372 + - Deny fchdir out of chroot
43373 + - Priority restrictions in chroot
43374 + - Segmentation-based implementation of PaX
43375 + - Mprotect restrictions
43376 + - Removal of addresses from /proc/<pid>/[smaps|maps|stat]
43377 + - Kernel stack randomization
43378 + - Mount/unmount/remount logging
43379 + - Kernel symbol hiding
43380 + - Prevention of memory exhaustion-based exploits
43381 + - Hardening of module auto-loading
43382 + - Ptrace restrictions
43383 + - Restricted vm86 mode
43384 +
43385 +config GRKERNSEC_CUSTOM
43386 + bool "Custom"
43387 + help
43388 + If you say Y here, you will be able to configure every grsecurity
43389 + option, which allows you to enable many more features that aren't
43390 + covered in the basic security levels. These additional features
43391 + include TPE, socket restrictions, and the sysctl system for
43392 + grsecurity. It is advised that you read through the help for
43393 + each option to determine its usefulness in your situation.
43394 +
43395 +endchoice
43396 +
43397 +menu "Address Space Protection"
43398 +depends on GRKERNSEC
43399 +
43400 +config GRKERNSEC_KMEM
43401 + bool "Deny writing to /dev/kmem, /dev/mem, and /dev/port"
43402 + help
43403 + If you say Y here, /dev/kmem and /dev/mem won't be allowed to
43404 + be written to via mmap or otherwise to modify the running kernel.
43405 + /dev/port will also not be allowed to be opened. If you have module
43406 + support disabled, enabling this will close up four ways that are
43407 + currently used to insert malicious code into the running kernel.
43408 + Even with all these features enabled, we still highly recommend that
43409 + you use the RBAC system, as it is still possible for an attacker to
43410 + modify the running kernel through privileged I/O granted by ioperm/iopl.
43411 + If you are not using XFree86, you may be able to stop this additional
43412 + case by enabling the 'Disable privileged I/O' option. Though nothing
43413 + legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
43414 + but only to video memory, which is the only writing we allow in this
43415 + case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
43416 + not be allowed to mprotect it with PROT_WRITE later.
43417 + It is highly recommended that you say Y here if you meet all the
43418 + conditions above.
43419 +
43420 +config GRKERNSEC_VM86
43421 + bool "Restrict VM86 mode"
43422 + depends on X86_32
43423 +
43424 + help
43425 + If you say Y here, only processes with CAP_SYS_RAWIO will be able to
43426 + make use of a special execution mode on 32bit x86 processors called
43427 + Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
43428 + video cards and will still work with this option enabled. The purpose
43429 + of the option is to prevent exploitation of emulation errors in
43430 + virtualization of vm86 mode like the one discovered in VMWare in 2009.
43431 + Nearly all users should be able to enable this option.
43432 +
43433 +config GRKERNSEC_IO
43434 + bool "Disable privileged I/O"
43435 + depends on X86
43436 + select RTC_CLASS
43437 + select RTC_INTF_DEV
43438 + select RTC_DRV_CMOS
43439 +
43440 + help
43441 + If you say Y here, all ioperm and iopl calls will return an error.
43442 + Ioperm and iopl can be used to modify the running kernel.
43443 + Unfortunately, some programs need this access to operate properly,
43444 + the most notable of which are XFree86 and hwclock. hwclock can be
43445 + remedied by having RTC support in the kernel, so real-time
43446 + clock support is enabled if this option is enabled, to ensure
43447 + that hwclock operates correctly. XFree86 still will not
43448 + operate correctly with this option enabled, so DO NOT CHOOSE Y
43449 + IF YOU USE XFree86. If you use XFree86 and you still want to
43450 + protect your kernel against modification, use the RBAC system.
43451 +
43452 +config GRKERNSEC_PROC_MEMMAP
43453 + bool "Remove addresses from /proc/<pid>/[smaps|maps|stat]"
43454 + default y if (PAX_NOEXEC || PAX_ASLR)
43455 + depends on PAX_NOEXEC || PAX_ASLR
43456 + help
43457 + If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
43458 + give no information about the addresses of its mappings if
43459 + PaX features that rely on random addresses are enabled on the task.
43460 + If you use PaX it is greatly recommended that you say Y here as it
43461 + closes up a hole that makes the full ASLR useless for suid
43462 + binaries.
43463 +
43464 +config GRKERNSEC_BRUTE
43465 + bool "Deter exploit bruteforcing"
43466 + help
43467 + If you say Y here, attempts to bruteforce exploits against forking
43468 + daemons such as apache or sshd will be deterred. When a child of a
43469 + forking daemon is killed by PaX or crashes due to an illegal
43470 + instruction, the parent process will be delayed 30 seconds upon every
43471 + subsequent fork until the administrator is able to assess the
43472 + situation and restart the daemon. It is recommended that you also
43473 + enable signal logging in the auditing section so that logs are
43474 + generated when a process performs an illegal instruction.
43475 +
43476 +config GRKERNSEC_MODHARDEN
43477 + bool "Harden module auto-loading"
43478 + depends on MODULES
43479 + help
43480 + If you say Y here, module auto-loading in response to use of some
43481 + feature implemented by an unloaded module will be restricted to
43482 + root users. Enabling this option helps defend against attacks
43483 + by unprivileged users who abuse the auto-loading behavior to
43484 + cause a vulnerable module to load that is then exploited.
43485 +
43486 + If this option prevents a legitimate use of auto-loading for a
43487 + non-root user, the administrator can execute modprobe manually
43488 + with the exact name of the module mentioned in the alert log.
43489 + Alternatively, the administrator can add the module to the list
43490 + of modules loaded at boot by modifying init scripts.
43491 +
43492 + Modification of init scripts will most likely be needed on
43493 + Ubuntu servers with encrypted home directory support enabled,
43494 + as the first non-root user logging in will cause the ecb(aes),
43495 + ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
43496 +
43497 +config GRKERNSEC_HIDESYM
43498 + bool "Hide kernel symbols"
43499 + help
43500 + If you say Y here, getting information on loaded modules, and
43501 + displaying all kernel symbols through a syscall will be restricted
43502 + to users with CAP_SYS_MODULE. For software compatibility reasons,
43503 + /proc/kallsyms will be restricted to the root user. The RBAC
43504 + system can hide that entry even from root.
43505 +
43506 + This option also prevents leaking of kernel addresses through
43507 + several /proc entries.
43508 +
43509 + Note that this option is only effective provided the following
43510 + conditions are met:
43511 + 1) The kernel using grsecurity is not precompiled by some distribution
43512 + 2) You have also enabled GRKERNSEC_DMESG
43513 + 3) You are using the RBAC system and hiding other files such as your
43514 + kernel image and System.map. Alternatively, enabling this option
43515 + causes the permissions on /boot, /lib/modules, and the kernel
43516 + source directory to change at compile time to prevent
43517 + reading by non-root users.
43518 + If the above conditions are met, this option will aid in providing a
43519 + useful protection against local kernel exploitation of overflows
43520 + and arbitrary read/write vulnerabilities.
43521 +
43522 +endmenu
43523 +menu "Role Based Access Control Options"
43524 +depends on GRKERNSEC
43525 +
43526 +config GRKERNSEC_NO_RBAC
43527 + bool "Disable RBAC system"
43528 + help
43529 + If you say Y here, the /dev/grsec device will be removed from the kernel,
43530 + preventing the RBAC system from being enabled. You should only say Y
43531 + here if you have no intention of using the RBAC system, so as to prevent
43532 + an attacker with root access from misusing the RBAC system to hide files
43533 + and processes when loadable module support and /dev/[k]mem have been
43534 + locked down.
43535 +
43536 +config GRKERNSEC_ACL_HIDEKERN
43537 + bool "Hide kernel processes"
43538 + help
43539 + If you say Y here, all kernel threads will be hidden to all
43540 + processes but those whose subject has the "view hidden processes"
43541 + flag.
43542 +
43543 +config GRKERNSEC_ACL_MAXTRIES
43544 + int "Maximum tries before password lockout"
43545 + default 3
43546 + help
43547 + This option enforces the maximum number of times a user can attempt
43548 + to authorize themselves with the grsecurity RBAC system before being
43549 + denied the ability to attempt authorization again for a specified time.
43550 + The lower the number, the harder it will be to brute-force a password.
43551 +
43552 +config GRKERNSEC_ACL_TIMEOUT
43553 + int "Time to wait after max password tries, in seconds"
43554 + default 30
43555 + help
43556 + This option specifies the time the user must wait after attempting to
43557 + authorize to the RBAC system with the maximum number of invalid
43558 + passwords. The higher the number, the harder it will be to brute-force
43559 + a password.
43560 +
43561 +endmenu
43562 +menu "Filesystem Protections"
43563 +depends on GRKERNSEC
43564 +
43565 +config GRKERNSEC_PROC
43566 + bool "Proc restrictions"
43567 + help
43568 + If you say Y here, the permissions of the /proc filesystem
43569 + will be altered to enhance system security and privacy. You MUST
43570 + choose either a user only restriction or a user and group restriction.
43571 + Depending upon the option you choose, you can either restrict users to
43572 + see only the processes they themselves run, or choose a group that can
43573 + view all processes and files normally restricted to root if you choose
43574 + the "restrict to user only" option. NOTE: If you're running identd as
43575 + a non-root user, you will have to run it as the group you specify here.
43576 +
43577 +config GRKERNSEC_PROC_USER
43578 + bool "Restrict /proc to user only"
43579 + depends on GRKERNSEC_PROC
43580 + help
43581 + If you say Y here, non-root users will only be able to view their own
43582 + processes, and restricts them from viewing network-related information,
43583 + and viewing kernel symbol and module information.
43584 +
43585 +config GRKERNSEC_PROC_USERGROUP
43586 + bool "Allow special group"
43587 + depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
43588 + help
43589 + If you say Y here, you will be able to select a group that will be
43590 + able to view all processes and network-related information. If you've
43591 + enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
43592 + remain hidden. This option is useful if you want to run identd as
43593 + a non-root user.
43594 +
43595 +config GRKERNSEC_PROC_GID
43596 + int "GID for special group"
43597 + depends on GRKERNSEC_PROC_USERGROUP
43598 + default 1001
43599 +
43600 +config GRKERNSEC_PROC_ADD
43601 + bool "Additional restrictions"
43602 + depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
43603 + help
43604 + If you say Y here, additional restrictions will be placed on
43605 + /proc that keep normal users from viewing device information and
43606 + slabinfo information that could be useful for exploits.
43607 +
43608 +config GRKERNSEC_LINK
43609 + bool "Linking restrictions"
43610 + help
43611 + If you say Y here, /tmp race exploits will be prevented, since users
43612 + will no longer be able to follow symlinks owned by other users in
43613 + world-writable +t directories (i.e. /tmp), unless the owner of the
43614 + symlink is the owner of the directory. users will also not be
43615 + able to hardlink to files they do not own. If the sysctl option is
43616 + enabled, a sysctl option with name "linking_restrictions" is created.
43617 +
43618 +config GRKERNSEC_FIFO
43619 + bool "FIFO restrictions"
43620 + help
43621 + If you say Y here, users will not be able to write to FIFOs they don't
43622 + own in world-writable +t directories (i.e. /tmp), unless the owner of
43623 + the FIFO is the same owner of the directory it's held in. If the sysctl
43624 + option is enabled, a sysctl option with name "fifo_restrictions" is
43625 + created.
43626 +
43627 +config GRKERNSEC_ROFS
43628 + bool "Runtime read-only mount protection"
43629 + help
43630 + If you say Y here, a sysctl option with name "romount_protect" will
43631 + be created. By setting this option to 1 at runtime, filesystems
43632 + will be protected in the following ways:
43633 + * No new writable mounts will be allowed
43634 + * Existing read-only mounts won't be able to be remounted read/write
43635 + * Write operations will be denied on all block devices
43636 + This option acts independently of grsec_lock: once it is set to 1,
43637 + it cannot be turned off. Therefore, please be mindful of the resulting
43638 + behavior if this option is enabled in an init script on a read-only
43639 + filesystem. This feature is mainly intended for secure embedded systems.
43640 +
43641 +config GRKERNSEC_CHROOT
43642 + bool "Chroot jail restrictions"
43643 + help
43644 + If you say Y here, you will be able to choose several options that will
43645 + make breaking out of a chrooted jail much more difficult. If you
43646 + encounter no software incompatibilities with the following options, it
43647 + is recommended that you enable each one.
43648 +
43649 +config GRKERNSEC_CHROOT_MOUNT
43650 + bool "Deny mounts"
43651 + depends on GRKERNSEC_CHROOT
43652 + help
43653 + If you say Y here, processes inside a chroot will not be able to
43654 + mount or remount filesystems. If the sysctl option is enabled, a
43655 + sysctl option with name "chroot_deny_mount" is created.
43656 +
43657 +config GRKERNSEC_CHROOT_DOUBLE
43658 + bool "Deny double-chroots"
43659 + depends on GRKERNSEC_CHROOT
43660 + help
43661 + If you say Y here, processes inside a chroot will not be able to chroot
43662 + again outside the chroot. This is a widely used method of breaking
43663 + out of a chroot jail and should not be allowed. If the sysctl
43664 + option is enabled, a sysctl option with name
43665 + "chroot_deny_chroot" is created.
43666 +
43667 +config GRKERNSEC_CHROOT_PIVOT
43668 + bool "Deny pivot_root in chroot"
43669 + depends on GRKERNSEC_CHROOT
43670 + help
43671 + If you say Y here, processes inside a chroot will not be able to use
43672 + a function called pivot_root() that was introduced in Linux 2.3.41. It
43673 + works similar to chroot in that it changes the root filesystem. This
43674 + function could be misused in a chrooted process to attempt to break out
43675 + of the chroot, and therefore should not be allowed. If the sysctl
43676 + option is enabled, a sysctl option with name "chroot_deny_pivot" is
43677 + created.
43678 +
43679 +config GRKERNSEC_CHROOT_CHDIR
43680 + bool "Enforce chdir(\"/\") on all chroots"
43681 + depends on GRKERNSEC_CHROOT
43682 + help
43683 + If you say Y here, the current working directory of all newly-chrooted
43684 + applications will be set to the the root directory of the chroot.
43685 + The man page on chroot(2) states:
43686 + Note that this call does not change the current working
43687 + directory, so that `.' can be outside the tree rooted at
43688 + `/'. In particular, the super-user can escape from a
43689 + `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
43690 +
43691 + It is recommended that you say Y here, since it's not known to break
43692 + any software. If the sysctl option is enabled, a sysctl option with
43693 + name "chroot_enforce_chdir" is created.
43694 +
43695 +config GRKERNSEC_CHROOT_CHMOD
43696 + bool "Deny (f)chmod +s"
43697 + depends on GRKERNSEC_CHROOT
43698 + help
43699 + If you say Y here, processes inside a chroot will not be able to chmod
43700 + or fchmod files to make them have suid or sgid bits. This protects
43701 + against another published method of breaking a chroot. If the sysctl
43702 + option is enabled, a sysctl option with name "chroot_deny_chmod" is
43703 + created.
43704 +
43705 +config GRKERNSEC_CHROOT_FCHDIR
43706 + bool "Deny fchdir out of chroot"
43707 + depends on GRKERNSEC_CHROOT
43708 + help
43709 + If you say Y here, a well-known method of breaking chroots by fchdir'ing
43710 + to a file descriptor of the chrooting process that points to a directory
43711 + outside the filesystem will be stopped. If the sysctl option
43712 + is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
43713 +
43714 +config GRKERNSEC_CHROOT_MKNOD
43715 + bool "Deny mknod"
43716 + depends on GRKERNSEC_CHROOT
43717 + help
43718 + If you say Y here, processes inside a chroot will not be allowed to
43719 + mknod. The problem with using mknod inside a chroot is that it
43720 + would allow an attacker to create a device entry that is the same
43721 + as one on the physical root of your system, which could range from
43722 + anything from the console device to a device for your harddrive (which
43723 + they could then use to wipe the drive or steal data). It is recommended
43724 + that you say Y here, unless you run into software incompatibilities.
43725 + If the sysctl option is enabled, a sysctl option with name
43726 + "chroot_deny_mknod" is created.
43727 +
43728 +config GRKERNSEC_CHROOT_SHMAT
43729 + bool "Deny shmat() out of chroot"
43730 + depends on GRKERNSEC_CHROOT
43731 + help
43732 + If you say Y here, processes inside a chroot will not be able to attach
43733 + to shared memory segments that were created outside of the chroot jail.
43734 + It is recommended that you say Y here. If the sysctl option is enabled,
43735 + a sysctl option with name "chroot_deny_shmat" is created.
43736 +
43737 +config GRKERNSEC_CHROOT_UNIX
43738 + bool "Deny access to abstract AF_UNIX sockets out of chroot"
43739 + depends on GRKERNSEC_CHROOT
43740 + help
43741 + If you say Y here, processes inside a chroot will not be able to
43742 + connect to abstract (meaning not belonging to a filesystem) Unix
43743 + domain sockets that were bound outside of a chroot. It is recommended
43744 + that you say Y here. If the sysctl option is enabled, a sysctl option
43745 + with name "chroot_deny_unix" is created.
43746 +
43747 +config GRKERNSEC_CHROOT_FINDTASK
43748 + bool "Protect outside processes"
43749 + depends on GRKERNSEC_CHROOT
43750 + help
43751 + If you say Y here, processes inside a chroot will not be able to
43752 + kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
43753 + getsid, or view any process outside of the chroot. If the sysctl
43754 + option is enabled, a sysctl option with name "chroot_findtask" is
43755 + created.
43756 +
43757 +config GRKERNSEC_CHROOT_NICE
43758 + bool "Restrict priority changes"
43759 + depends on GRKERNSEC_CHROOT
43760 + help
43761 + If you say Y here, processes inside a chroot will not be able to raise
43762 + the priority of processes in the chroot, or alter the priority of
43763 + processes outside the chroot. This provides more security than simply
43764 + removing CAP_SYS_NICE from the process' capability set. If the
43765 + sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
43766 + is created.
43767 +
43768 +config GRKERNSEC_CHROOT_SYSCTL
43769 + bool "Deny sysctl writes"
43770 + depends on GRKERNSEC_CHROOT
43771 + help
43772 + If you say Y here, an attacker in a chroot will not be able to
43773 + write to sysctl entries, either by sysctl(2) or through a /proc
43774 + interface. It is strongly recommended that you say Y here. If the
43775 + sysctl option is enabled, a sysctl option with name
43776 + "chroot_deny_sysctl" is created.
43777 +
43778 +config GRKERNSEC_CHROOT_CAPS
43779 + bool "Capability restrictions"
43780 + depends on GRKERNSEC_CHROOT
43781 + help
43782 + If you say Y here, the capabilities on all root processes within a
43783 + chroot jail will be lowered to stop module insertion, raw i/o,
43784 + system and net admin tasks, rebooting the system, modifying immutable
43785 + files, modifying IPC owned by another, and changing the system time.
43786 + This is left an option because it can break some apps. Disable this
43787 + if your chrooted apps are having problems performing those kinds of
43788 + tasks. If the sysctl option is enabled, a sysctl option with
43789 + name "chroot_caps" is created.
43790 +
43791 +endmenu
43792 +menu "Kernel Auditing"
43793 +depends on GRKERNSEC
43794 +
43795 +config GRKERNSEC_AUDIT_GROUP
43796 + bool "Single group for auditing"
43797 + help
43798 + If you say Y here, the exec, chdir, and (un)mount logging features
43799 + will only operate on a group you specify. This option is recommended
43800 + if you only want to watch certain users instead of having a large
43801 + amount of logs from the entire system. If the sysctl option is enabled,
43802 + a sysctl option with name "audit_group" is created.
43803 +
43804 +config GRKERNSEC_AUDIT_GID
43805 + int "GID for auditing"
43806 + depends on GRKERNSEC_AUDIT_GROUP
43807 + default 1007
43808 +
43809 +config GRKERNSEC_EXECLOG
43810 + bool "Exec logging"
43811 + help
43812 + If you say Y here, all execve() calls will be logged (since the
43813 + other exec*() calls are frontends to execve(), all execution
43814 + will be logged). Useful for shell-servers that like to keep track
43815 + of their users. If the sysctl option is enabled, a sysctl option with
43816 + name "exec_logging" is created.
43817 + WARNING: This option when enabled will produce a LOT of logs, especially
43818 + on an active system.
43819 +
43820 +config GRKERNSEC_RESLOG
43821 + bool "Resource logging"
43822 + help
43823 + If you say Y here, all attempts to overstep resource limits will
43824 + be logged with the resource name, the requested size, and the current
43825 + limit. It is highly recommended that you say Y here. If the sysctl
43826 + option is enabled, a sysctl option with name "resource_logging" is
43827 + created. If the RBAC system is enabled, the sysctl value is ignored.
43828 +
43829 +config GRKERNSEC_CHROOT_EXECLOG
43830 + bool "Log execs within chroot"
43831 + help
43832 + If you say Y here, all executions inside a chroot jail will be logged
43833 + to syslog. This can cause a large amount of logs if certain
43834 + applications (eg. djb's daemontools) are installed on the system, and
43835 + is therefore left as an option. If the sysctl option is enabled, a
43836 + sysctl option with name "chroot_execlog" is created.
43837 +
43838 +config GRKERNSEC_AUDIT_PTRACE
43839 + bool "Ptrace logging"
43840 + help
43841 + If you say Y here, all attempts to attach to a process via ptrace
43842 + will be logged. If the sysctl option is enabled, a sysctl option
43843 + with name "audit_ptrace" is created.
43844 +
43845 +config GRKERNSEC_AUDIT_CHDIR
43846 + bool "Chdir logging"
43847 + help
43848 + If you say Y here, all chdir() calls will be logged. If the sysctl
43849 + option is enabled, a sysctl option with name "audit_chdir" is created.
43850 +
43851 +config GRKERNSEC_AUDIT_MOUNT
43852 + bool "(Un)Mount logging"
43853 + help
43854 + If you say Y here, all mounts and unmounts will be logged. If the
43855 + sysctl option is enabled, a sysctl option with name "audit_mount" is
43856 + created.
43857 +
43858 +config GRKERNSEC_SIGNAL
43859 + bool "Signal logging"
43860 + help
43861 + If you say Y here, certain important signals will be logged, such as
43862 + SIGSEGV, which will as a result inform you of when a error in a program
43863 + occurred, which in some cases could mean a possible exploit attempt.
43864 + If the sysctl option is enabled, a sysctl option with name
43865 + "signal_logging" is created.
43866 +
43867 +config GRKERNSEC_FORKFAIL
43868 + bool "Fork failure logging"
43869 + help
43870 + If you say Y here, all failed fork() attempts will be logged.
43871 + This could suggest a fork bomb, or someone attempting to overstep
43872 + their process limit. If the sysctl option is enabled, a sysctl option
43873 + with name "forkfail_logging" is created.
43874 +
43875 +config GRKERNSEC_TIME
43876 + bool "Time change logging"
43877 + help
43878 + If you say Y here, any changes of the system clock will be logged.
43879 + If the sysctl option is enabled, a sysctl option with name
43880 + "timechange_logging" is created.
43881 +
43882 +config GRKERNSEC_PROC_IPADDR
43883 + bool "/proc/<pid>/ipaddr support"
43884 + help
43885 + If you say Y here, a new entry will be added to each /proc/<pid>
43886 + directory that contains the IP address of the person using the task.
43887 + The IP is carried across local TCP and AF_UNIX stream sockets.
43888 + This information can be useful for IDS/IPSes to perform remote response
43889 + to a local attack. The entry is readable by only the owner of the
43890 + process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
43891 + the RBAC system), and thus does not create privacy concerns.
43892 +
43893 +config GRKERNSEC_RWXMAP_LOG
43894 + bool 'Denied RWX mmap/mprotect logging'
43895 + depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
43896 + help
43897 + If you say Y here, calls to mmap() and mprotect() with explicit
43898 + usage of PROT_WRITE and PROT_EXEC together will be logged when
43899 + denied by the PAX_MPROTECT feature. If the sysctl option is
43900 + enabled, a sysctl option with name "rwxmap_logging" is created.
43901 +
43902 +config GRKERNSEC_AUDIT_TEXTREL
43903 + bool 'ELF text relocations logging (READ HELP)'
43904 + depends on PAX_MPROTECT
43905 + help
43906 + If you say Y here, text relocations will be logged with the filename
43907 + of the offending library or binary. The purpose of the feature is
43908 + to help Linux distribution developers get rid of libraries and
43909 + binaries that need text relocations which hinder the future progress
43910 + of PaX. Only Linux distribution developers should say Y here, and
43911 + never on a production machine, as this option creates an information
43912 + leak that could aid an attacker in defeating the randomization of
43913 + a single memory region. If the sysctl option is enabled, a sysctl
43914 + option with name "audit_textrel" is created.
43915 +
43916 +endmenu
43917 +
43918 +menu "Executable Protections"
43919 +depends on GRKERNSEC
43920 +
43921 +config GRKERNSEC_EXECVE
43922 + bool "Enforce RLIMIT_NPROC on execs"
43923 + help
43924 + If you say Y here, users with a resource limit on processes will
43925 + have the value checked during execve() calls. The current system
43926 + only checks the system limit during fork() calls. If the sysctl option
43927 + is enabled, a sysctl option with name "execve_limiting" is created.
43928 +
43929 +config GRKERNSEC_DMESG
43930 + bool "Dmesg(8) restriction"
43931 + help
43932 + If you say Y here, non-root users will not be able to use dmesg(8)
43933 + to view up to the last 4kb of messages in the kernel's log buffer.
43934 + The kernel's log buffer often contains kernel addresses and other
43935 + identifying information useful to an attacker in fingerprinting a
43936 + system for a targeted exploit.
43937 + If the sysctl option is enabled, a sysctl option with name "dmesg" is
43938 + created.
43939 +
43940 +config GRKERNSEC_HARDEN_PTRACE
43941 + bool "Deter ptrace-based process snooping"
43942 + help
43943 + If you say Y here, TTY sniffers and other malicious monitoring
43944 + programs implemented through ptrace will be defeated. If you
43945 + have been using the RBAC system, this option has already been
43946 + enabled for several years for all users, with the ability to make
43947 + fine-grained exceptions.
43948 +
43949 + This option only affects the ability of non-root users to ptrace
43950 + processes that are not a descendent of the ptracing process.
43951 + This means that strace ./binary and gdb ./binary will still work,
43952 + but attaching to arbitrary processes will not. If the sysctl
43953 + option is enabled, a sysctl option with name "harden_ptrace" is
43954 + created.
43955 +
43956 +config GRKERNSEC_TPE
43957 + bool "Trusted Path Execution (TPE)"
43958 + help
43959 + If you say Y here, you will be able to choose a gid to add to the
43960 + supplementary groups of users you want to mark as "untrusted."
43961 + These users will not be able to execute any files that are not in
43962 + root-owned directories writable only by root. If the sysctl option
43963 + is enabled, a sysctl option with name "tpe" is created.
43964 +
43965 +config GRKERNSEC_TPE_ALL
43966 + bool "Partially restrict all non-root users"
43967 + depends on GRKERNSEC_TPE
43968 + help
43969 + If you say Y here, all non-root users will be covered under
43970 + a weaker TPE restriction. This is separate from, and in addition to,
43971 + the main TPE options that you have selected elsewhere. Thus, if a
43972 + "trusted" GID is chosen, this restriction applies to even that GID.
43973 + Under this restriction, all non-root users will only be allowed to
43974 + execute files in directories they own that are not group or
43975 + world-writable, or in directories owned by root and writable only by
43976 + root. If the sysctl option is enabled, a sysctl option with name
43977 + "tpe_restrict_all" is created.
43978 +
43979 +config GRKERNSEC_TPE_INVERT
43980 + bool "Invert GID option"
43981 + depends on GRKERNSEC_TPE
43982 + help
43983 + If you say Y here, the group you specify in the TPE configuration will
43984 + decide what group TPE restrictions will be *disabled* for. This
43985 + option is useful if you want TPE restrictions to be applied to most
43986 + users on the system. If the sysctl option is enabled, a sysctl option
43987 + with name "tpe_invert" is created. Unlike other sysctl options, this
43988 + entry will default to on for backward-compatibility.
43989 +
43990 +config GRKERNSEC_TPE_GID
43991 + int "GID for untrusted users"
43992 + depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
43993 + default 1005
43994 + help
43995 + Setting this GID determines what group TPE restrictions will be
43996 + *enabled* for. If the sysctl option is enabled, a sysctl option
43997 + with name "tpe_gid" is created.
43998 +
43999 +config GRKERNSEC_TPE_GID
44000 + int "GID for trusted users"
44001 + depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
44002 + default 1005
44003 + help
44004 + Setting this GID determines what group TPE restrictions will be
44005 + *disabled* for. If the sysctl option is enabled, a sysctl option
44006 + with name "tpe_gid" is created.
44007 +
44008 +endmenu
44009 +menu "Network Protections"
44010 +depends on GRKERNSEC
44011 +
44012 +config GRKERNSEC_RANDNET
44013 + bool "Larger entropy pools"
44014 + help
44015 + If you say Y here, the entropy pools used for many features of Linux
44016 + and grsecurity will be doubled in size. Since several grsecurity
44017 + features use additional randomness, it is recommended that you say Y
44018 + here. Saying Y here has a similar effect as modifying
44019 + /proc/sys/kernel/random/poolsize.
44020 +
44021 +config GRKERNSEC_BLACKHOLE
44022 + bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
44023 + help
44024 + If you say Y here, neither TCP resets nor ICMP
44025 + destination-unreachable packets will be sent in response to packets
44026 + sent to ports for which no associated listening process exists.
44027 + This feature supports both IPV4 and IPV6 and exempts the
44028 + loopback interface from blackholing. Enabling this feature
44029 + makes a host more resilient to DoS attacks and reduces network
44030 + visibility against scanners.
44031 +
44032 + The blackhole feature as-implemented is equivalent to the FreeBSD
44033 + blackhole feature, as it prevents RST responses to all packets, not
44034 + just SYNs. Under most application behavior this causes no
44035 + problems, but applications (like haproxy) may not close certain
44036 + connections in a way that cleanly terminates them on the remote
44037 + end, leaving the remote host in LAST_ACK state. Because of this
44038 + side-effect and to prevent intentional LAST_ACK DoSes, this
44039 + feature also adds automatic mitigation against such attacks.
44040 + The mitigation drastically reduces the amount of time a socket
44041 + can spend in LAST_ACK state. If you're using haproxy and not
44042 + all servers it connects to have this option enabled, consider
44043 + disabling this feature on the haproxy host.
44044 +
44045 + If the sysctl option is enabled, two sysctl options with names
44046 + "ip_blackhole" and "lastack_retries" will be created.
44047 + While "ip_blackhole" takes the standard zero/non-zero on/off
44048 + toggle, "lastack_retries" uses the same kinds of values as
44049 + "tcp_retries1" and "tcp_retries2". The default value of 4
44050 + prevents a socket from lasting more than 45 seconds in LAST_ACK
44051 + state.
44052 +
44053 +config GRKERNSEC_SOCKET
44054 + bool "Socket restrictions"
44055 + help
44056 + If you say Y here, you will be able to choose from several options.
44057 + If you assign a GID on your system and add it to the supplementary
44058 + groups of users you want to restrict socket access to, this patch
44059 + will perform up to three things, based on the option(s) you choose.
44060 +
44061 +config GRKERNSEC_SOCKET_ALL
44062 + bool "Deny any sockets to group"
44063 + depends on GRKERNSEC_SOCKET
44064 + help
44065 + If you say Y here, you will be able to choose a GID of whose users will
44066 + be unable to connect to other hosts from your machine or run server
44067 + applications from your machine. If the sysctl option is enabled, a
44068 + sysctl option with name "socket_all" is created.
44069 +
44070 +config GRKERNSEC_SOCKET_ALL_GID
44071 + int "GID to deny all sockets for"
44072 + depends on GRKERNSEC_SOCKET_ALL
44073 + default 1004
44074 + help
44075 + Here you can choose the GID to disable socket access for. Remember to
44076 + add the users you want socket access disabled for to the GID
44077 + specified here. If the sysctl option is enabled, a sysctl option
44078 + with name "socket_all_gid" is created.
44079 +
44080 +config GRKERNSEC_SOCKET_CLIENT
44081 + bool "Deny client sockets to group"
44082 + depends on GRKERNSEC_SOCKET
44083 + help
44084 + If you say Y here, you will be able to choose a GID of whose users will
44085 + be unable to connect to other hosts from your machine, but will be
44086 + able to run servers. If this option is enabled, all users in the group
44087 + you specify will have to use passive mode when initiating ftp transfers
44088 + from the shell on your machine. If the sysctl option is enabled, a
44089 + sysctl option with name "socket_client" is created.
44090 +
44091 +config GRKERNSEC_SOCKET_CLIENT_GID
44092 + int "GID to deny client sockets for"
44093 + depends on GRKERNSEC_SOCKET_CLIENT
44094 + default 1003
44095 + help
44096 + Here you can choose the GID to disable client socket access for.
44097 + Remember to add the users you want client socket access disabled for to
44098 + the GID specified here. If the sysctl option is enabled, a sysctl
44099 + option with name "socket_client_gid" is created.
44100 +
44101 +config GRKERNSEC_SOCKET_SERVER
44102 + bool "Deny server sockets to group"
44103 + depends on GRKERNSEC_SOCKET
44104 + help
44105 + If you say Y here, you will be able to choose a GID of whose users will
44106 + be unable to run server applications from your machine. If the sysctl
44107 + option is enabled, a sysctl option with name "socket_server" is created.
44108 +
44109 +config GRKERNSEC_SOCKET_SERVER_GID
44110 + int "GID to deny server sockets for"
44111 + depends on GRKERNSEC_SOCKET_SERVER
44112 + default 1002
44113 + help
44114 + Here you can choose the GID to disable server socket access for.
44115 + Remember to add the users you want server socket access disabled for to
44116 + the GID specified here. If the sysctl option is enabled, a sysctl
44117 + option with name "socket_server_gid" is created.
44118 +
44119 +endmenu
44120 +menu "Sysctl support"
44121 +depends on GRKERNSEC && SYSCTL
44122 +
44123 +config GRKERNSEC_SYSCTL
44124 + bool "Sysctl support"
44125 + help
44126 + If you say Y here, you will be able to change the options that
44127 + grsecurity runs with at bootup, without having to recompile your
44128 + kernel. You can echo values to files in /proc/sys/kernel/grsecurity
44129 + to enable (1) or disable (0) various features. All the sysctl entries
44130 + are mutable until the "grsec_lock" entry is set to a non-zero value.
44131 + All features enabled in the kernel configuration are disabled at boot
44132 + if you do not say Y to the "Turn on features by default" option.
44133 + All options should be set at startup, and the grsec_lock entry should
44134 + be set to a non-zero value after all the options are set.
44135 + *THIS IS EXTREMELY IMPORTANT*
44136 +
44137 +config GRKERNSEC_SYSCTL_DISTRO
44138 + bool "Extra sysctl support for distro makers (READ HELP)"
44139 + depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
44140 + help
44141 + If you say Y here, additional sysctl options will be created
44142 + for features that affect processes running as root. Therefore,
44143 + it is critical when using this option that the grsec_lock entry be
44144 + enabled after boot. Only distros with prebuilt kernel packages
44145 + with this option enabled that can ensure grsec_lock is enabled
44146 + after boot should use this option.
44147 + *Failure to set grsec_lock after boot makes all grsec features
44148 + this option covers useless*
44149 +
44150 + Currently this option creates the following sysctl entries:
44151 + "Disable Privileged I/O": "disable_priv_io"
44152 +
44153 +config GRKERNSEC_SYSCTL_ON
44154 + bool "Turn on features by default"
44155 + depends on GRKERNSEC_SYSCTL
44156 + help
44157 + If you say Y here, instead of having all features enabled in the
44158 + kernel configuration disabled at boot time, the features will be
44159 + enabled at boot time. It is recommended you say Y here unless
44160 + there is some reason you would want all sysctl-tunable features to
44161 + be disabled by default. As mentioned elsewhere, it is important
44162 + to enable the grsec_lock entry once you have finished modifying
44163 + the sysctl entries.
44164 +
44165 +endmenu
44166 +menu "Logging Options"
44167 +depends on GRKERNSEC
44168 +
44169 +config GRKERNSEC_FLOODTIME
44170 + int "Seconds in between log messages (minimum)"
44171 + default 10
44172 + help
44173 + This option allows you to enforce the number of seconds between
44174 + grsecurity log messages. The default should be suitable for most
44175 + people, however, if you choose to change it, choose a value small enough
44176 + to allow informative logs to be produced, but large enough to
44177 + prevent flooding.
44178 +
44179 +config GRKERNSEC_FLOODBURST
44180 + int "Number of messages in a burst (maximum)"
44181 + default 4
44182 + help
44183 + This option allows you to choose the maximum number of messages allowed
44184 + within the flood time interval you chose in a separate option. The
44185 + default should be suitable for most people, however if you find that
44186 + many of your logs are being interpreted as flooding, you may want to
44187 + raise this value.
44188 +
44189 +endmenu
44190 +
44191 +endmenu
44192 diff -urNp linux-2.6.37/grsecurity/Makefile linux-2.6.37/grsecurity/Makefile
44193 --- linux-2.6.37/grsecurity/Makefile 1969-12-31 19:00:00.000000000 -0500
44194 +++ linux-2.6.37/grsecurity/Makefile 2011-01-17 02:41:02.000000000 -0500
44195 @@ -0,0 +1,29 @@
44196 +# grsecurity's ACL system was originally written in 2001 by Michael Dalton
44197 +# during 2001-2009 it has been completely redesigned by Brad Spengler
44198 +# into an RBAC system
44199 +#
44200 +# All code in this directory and various hooks inserted throughout the kernel
44201 +# are copyright Brad Spengler - Open Source Security, Inc., and released
44202 +# under the GPL v2 or higher
44203 +
44204 +obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
44205 + grsec_mount.o grsec_sig.o grsec_sock.o grsec_sysctl.o \
44206 + grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
44207 +
44208 +obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_ip.o gracl_segv.o \
44209 + gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
44210 + gracl_learn.o grsec_log.o
44211 +obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
44212 +
44213 +ifndef CONFIG_GRKERNSEC
44214 +obj-y += grsec_disabled.o
44215 +endif
44216 +
44217 +ifdef CONFIG_GRKERNSEC_HIDESYM
44218 +extra-y := grsec_hidesym.o
44219 +$(obj)/grsec_hidesym.o:
44220 + @-chmod -f 500 /boot
44221 + @-chmod -f 500 /lib/modules
44222 + @-chmod -f 700 .
44223 + @echo ' grsec: protected kernel image paths'
44224 +endif
44225 diff -urNp linux-2.6.37/include/acpi/acoutput.h linux-2.6.37/include/acpi/acoutput.h
44226 --- linux-2.6.37/include/acpi/acoutput.h 2011-01-04 19:50:19.000000000 -0500
44227 +++ linux-2.6.37/include/acpi/acoutput.h 2011-01-17 02:41:02.000000000 -0500
44228 @@ -269,8 +269,8 @@
44229 * leaving no executable debug code!
44230 */
44231 #define ACPI_FUNCTION_NAME(a)
44232 -#define ACPI_DEBUG_PRINT(pl)
44233 -#define ACPI_DEBUG_PRINT_RAW(pl)
44234 +#define ACPI_DEBUG_PRINT(pl) do {} while (0)
44235 +#define ACPI_DEBUG_PRINT_RAW(pl) do {} while (0)
44236
44237 #endif /* ACPI_DEBUG_OUTPUT */
44238
44239 diff -urNp linux-2.6.37/include/acpi/acpi_drivers.h linux-2.6.37/include/acpi/acpi_drivers.h
44240 --- linux-2.6.37/include/acpi/acpi_drivers.h 2011-01-04 19:50:19.000000000 -0500
44241 +++ linux-2.6.37/include/acpi/acpi_drivers.h 2011-01-17 02:41:02.000000000 -0500
44242 @@ -119,8 +119,8 @@ void pci_acpi_crs_quirks(void);
44243 Dock Station
44244 -------------------------------------------------------------------------- */
44245 struct acpi_dock_ops {
44246 - acpi_notify_handler handler;
44247 - acpi_notify_handler uevent;
44248 + const acpi_notify_handler handler;
44249 + const acpi_notify_handler uevent;
44250 };
44251
44252 #if defined(CONFIG_ACPI_DOCK) || defined(CONFIG_ACPI_DOCK_MODULE)
44253 @@ -128,7 +128,7 @@ extern int is_dock_device(acpi_handle ha
44254 extern int register_dock_notifier(struct notifier_block *nb);
44255 extern void unregister_dock_notifier(struct notifier_block *nb);
44256 extern int register_hotplug_dock_device(acpi_handle handle,
44257 - struct acpi_dock_ops *ops,
44258 + const struct acpi_dock_ops *ops,
44259 void *context);
44260 extern void unregister_hotplug_dock_device(acpi_handle handle);
44261 #else
44262 @@ -144,7 +144,7 @@ static inline void unregister_dock_notif
44263 {
44264 }
44265 static inline int register_hotplug_dock_device(acpi_handle handle,
44266 - struct acpi_dock_ops *ops,
44267 + const struct acpi_dock_ops *ops,
44268 void *context)
44269 {
44270 return -ENODEV;
44271 diff -urNp linux-2.6.37/include/asm-generic/atomic-long.h linux-2.6.37/include/asm-generic/atomic-long.h
44272 --- linux-2.6.37/include/asm-generic/atomic-long.h 2011-01-04 19:50:19.000000000 -0500
44273 +++ linux-2.6.37/include/asm-generic/atomic-long.h 2011-01-17 02:41:02.000000000 -0500
44274 @@ -22,6 +22,12 @@
44275
44276 typedef atomic64_t atomic_long_t;
44277
44278 +#ifdef CONFIG_PAX_REFCOUNT
44279 +typedef atomic64_unchecked_t atomic_long_unchecked_t;
44280 +#else
44281 +typedef atomic64_t atomic_long_unchecked_t;
44282 +#endif
44283 +
44284 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
44285
44286 static inline long atomic_long_read(atomic_long_t *l)
44287 @@ -31,6 +37,15 @@ static inline long atomic_long_read(atom
44288 return (long)atomic64_read(v);
44289 }
44290
44291 +#ifdef CONFIG_PAX_REFCOUNT
44292 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
44293 +{
44294 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
44295 +
44296 + return (long)atomic64_read_unchecked(v);
44297 +}
44298 +#endif
44299 +
44300 static inline void atomic_long_set(atomic_long_t *l, long i)
44301 {
44302 atomic64_t *v = (atomic64_t *)l;
44303 @@ -38,6 +53,15 @@ static inline void atomic_long_set(atomi
44304 atomic64_set(v, i);
44305 }
44306
44307 +#ifdef CONFIG_PAX_REFCOUNT
44308 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
44309 +{
44310 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
44311 +
44312 + atomic64_set_unchecked(v, i);
44313 +}
44314 +#endif
44315 +
44316 static inline void atomic_long_inc(atomic_long_t *l)
44317 {
44318 atomic64_t *v = (atomic64_t *)l;
44319 @@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomi
44320 atomic64_inc(v);
44321 }
44322
44323 +#ifdef CONFIG_PAX_REFCOUNT
44324 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
44325 +{
44326 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
44327 +
44328 + atomic64_inc_unchecked(v);
44329 +}
44330 +#endif
44331 +
44332 static inline void atomic_long_dec(atomic_long_t *l)
44333 {
44334 atomic64_t *v = (atomic64_t *)l;
44335 @@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomi
44336 atomic64_dec(v);
44337 }
44338
44339 +#ifdef CONFIG_PAX_REFCOUNT
44340 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
44341 +{
44342 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
44343 +
44344 + atomic64_dec_unchecked(v);
44345 +}
44346 +#endif
44347 +
44348 static inline void atomic_long_add(long i, atomic_long_t *l)
44349 {
44350 atomic64_t *v = (atomic64_t *)l;
44351 @@ -59,6 +101,15 @@ static inline void atomic_long_add(long
44352 atomic64_add(i, v);
44353 }
44354
44355 +#ifdef CONFIG_PAX_REFCOUNT
44356 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
44357 +{
44358 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
44359 +
44360 + atomic64_add_unchecked(i, v);
44361 +}
44362 +#endif
44363 +
44364 static inline void atomic_long_sub(long i, atomic_long_t *l)
44365 {
44366 atomic64_t *v = (atomic64_t *)l;
44367 @@ -66,6 +117,15 @@ static inline void atomic_long_sub(long
44368 atomic64_sub(i, v);
44369 }
44370
44371 +#ifdef CONFIG_PAX_REFCOUNT
44372 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
44373 +{
44374 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
44375 +
44376 + atomic64_sub_unchecked(i, v);
44377 +}
44378 +#endif
44379 +
44380 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
44381 {
44382 atomic64_t *v = (atomic64_t *)l;
44383 @@ -115,6 +175,15 @@ static inline long atomic_long_inc_retur
44384 return (long)atomic64_inc_return(v);
44385 }
44386
44387 +#ifdef CONFIG_PAX_REFCOUNT
44388 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
44389 +{
44390 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
44391 +
44392 + return (long)atomic64_inc_return_unchecked(v);
44393 +}
44394 +#endif
44395 +
44396 static inline long atomic_long_dec_return(atomic_long_t *l)
44397 {
44398 atomic64_t *v = (atomic64_t *)l;
44399 @@ -140,6 +209,12 @@ static inline long atomic_long_add_unles
44400
44401 typedef atomic_t atomic_long_t;
44402
44403 +#ifdef CONFIG_PAX_REFCOUNT
44404 +typedef atomic_unchecked_t atomic_long_unchecked_t;
44405 +#else
44406 +typedef atomic_t atomic_long_unchecked_t;
44407 +#endif
44408 +
44409 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
44410 static inline long atomic_long_read(atomic_long_t *l)
44411 {
44412 @@ -148,6 +223,15 @@ static inline long atomic_long_read(atom
44413 return (long)atomic_read(v);
44414 }
44415
44416 +#ifdef CONFIG_PAX_REFCOUNT
44417 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
44418 +{
44419 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
44420 +
44421 + return (long)atomic_read_unchecked(v);
44422 +}
44423 +#endif
44424 +
44425 static inline void atomic_long_set(atomic_long_t *l, long i)
44426 {
44427 atomic_t *v = (atomic_t *)l;
44428 @@ -155,6 +239,15 @@ static inline void atomic_long_set(atomi
44429 atomic_set(v, i);
44430 }
44431
44432 +#ifdef CONFIG_PAX_REFCOUNT
44433 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
44434 +{
44435 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
44436 +
44437 + atomic_set_unchecked(v, i);
44438 +}
44439 +#endif
44440 +
44441 static inline void atomic_long_inc(atomic_long_t *l)
44442 {
44443 atomic_t *v = (atomic_t *)l;
44444 @@ -162,6 +255,15 @@ static inline void atomic_long_inc(atomi
44445 atomic_inc(v);
44446 }
44447
44448 +#ifdef CONFIG_PAX_REFCOUNT
44449 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
44450 +{
44451 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
44452 +
44453 + atomic_inc_unchecked(v);
44454 +}
44455 +#endif
44456 +
44457 static inline void atomic_long_dec(atomic_long_t *l)
44458 {
44459 atomic_t *v = (atomic_t *)l;
44460 @@ -169,6 +271,15 @@ static inline void atomic_long_dec(atomi
44461 atomic_dec(v);
44462 }
44463
44464 +#ifdef CONFIG_PAX_REFCOUNT
44465 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
44466 +{
44467 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
44468 +
44469 + atomic_dec_unchecked(v);
44470 +}
44471 +#endif
44472 +
44473 static inline void atomic_long_add(long i, atomic_long_t *l)
44474 {
44475 atomic_t *v = (atomic_t *)l;
44476 @@ -176,6 +287,15 @@ static inline void atomic_long_add(long
44477 atomic_add(i, v);
44478 }
44479
44480 +#ifdef CONFIG_PAX_REFCOUNT
44481 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
44482 +{
44483 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
44484 +
44485 + atomic_add_unchecked(i, v);
44486 +}
44487 +#endif
44488 +
44489 static inline void atomic_long_sub(long i, atomic_long_t *l)
44490 {
44491 atomic_t *v = (atomic_t *)l;
44492 @@ -183,6 +303,15 @@ static inline void atomic_long_sub(long
44493 atomic_sub(i, v);
44494 }
44495
44496 +#ifdef CONFIG_PAX_REFCOUNT
44497 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
44498 +{
44499 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
44500 +
44501 + atomic_sub_unchecked(i, v);
44502 +}
44503 +#endif
44504 +
44505 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
44506 {
44507 atomic_t *v = (atomic_t *)l;
44508 @@ -232,6 +361,15 @@ static inline long atomic_long_inc_retur
44509 return (long)atomic_inc_return(v);
44510 }
44511
44512 +#ifdef CONFIG_PAX_REFCOUNT
44513 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
44514 +{
44515 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
44516 +
44517 + return (long)atomic_inc_return_unchecked(v);
44518 +}
44519 +#endif
44520 +
44521 static inline long atomic_long_dec_return(atomic_long_t *l)
44522 {
44523 atomic_t *v = (atomic_t *)l;
44524 @@ -255,4 +393,41 @@ static inline long atomic_long_add_unles
44525
44526 #endif /* BITS_PER_LONG == 64 */
44527
44528 +#ifdef CONFIG_PAX_REFCOUNT
44529 +static inline void pax_refcount_needs_these_functions(void)
44530 +{
44531 + atomic_read_unchecked((atomic_unchecked_t *)NULL);
44532 + atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
44533 + atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
44534 + atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
44535 + atomic_inc_unchecked((atomic_unchecked_t *)NULL);
44536 + atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
44537 + atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
44538 +
44539 + atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
44540 + atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
44541 + atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
44542 + atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
44543 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
44544 + atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
44545 + atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
44546 +}
44547 +#else
44548 +#define atomic_read_unchecked(v) atomic_read(v)
44549 +#define atomic_set_unchecked(v, i) atomic_set((v), (i))
44550 +#define atomic_add_unchecked(i, v) atomic_add((i), (v))
44551 +#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
44552 +#define atomic_inc_unchecked(v) atomic_inc(v)
44553 +#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
44554 +#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
44555 +
44556 +#define atomic_long_read_unchecked(v) atomic_long_read(v)
44557 +#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
44558 +#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
44559 +#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
44560 +#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
44561 +#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
44562 +#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
44563 +#endif
44564 +
44565 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
44566 diff -urNp linux-2.6.37/include/asm-generic/dma-mapping-common.h linux-2.6.37/include/asm-generic/dma-mapping-common.h
44567 --- linux-2.6.37/include/asm-generic/dma-mapping-common.h 2011-01-04 19:50:19.000000000 -0500
44568 +++ linux-2.6.37/include/asm-generic/dma-mapping-common.h 2011-01-17 02:41:02.000000000 -0500
44569 @@ -11,7 +11,7 @@ static inline dma_addr_t dma_map_single_
44570 enum dma_data_direction dir,
44571 struct dma_attrs *attrs)
44572 {
44573 - struct dma_map_ops *ops = get_dma_ops(dev);
44574 + const struct dma_map_ops *ops = get_dma_ops(dev);
44575 dma_addr_t addr;
44576
44577 kmemcheck_mark_initialized(ptr, size);
44578 @@ -30,7 +30,7 @@ static inline void dma_unmap_single_attr
44579 enum dma_data_direction dir,
44580 struct dma_attrs *attrs)
44581 {
44582 - struct dma_map_ops *ops = get_dma_ops(dev);
44583 + const struct dma_map_ops *ops = get_dma_ops(dev);
44584
44585 BUG_ON(!valid_dma_direction(dir));
44586 if (ops->unmap_page)
44587 @@ -42,7 +42,7 @@ static inline int dma_map_sg_attrs(struc
44588 int nents, enum dma_data_direction dir,
44589 struct dma_attrs *attrs)
44590 {
44591 - struct dma_map_ops *ops = get_dma_ops(dev);
44592 + const struct dma_map_ops *ops = get_dma_ops(dev);
44593 int i, ents;
44594 struct scatterlist *s;
44595
44596 @@ -59,7 +59,7 @@ static inline void dma_unmap_sg_attrs(st
44597 int nents, enum dma_data_direction dir,
44598 struct dma_attrs *attrs)
44599 {
44600 - struct dma_map_ops *ops = get_dma_ops(dev);
44601 + const struct dma_map_ops *ops = get_dma_ops(dev);
44602
44603 BUG_ON(!valid_dma_direction(dir));
44604 debug_dma_unmap_sg(dev, sg, nents, dir);
44605 @@ -71,7 +71,7 @@ static inline dma_addr_t dma_map_page(st
44606 size_t offset, size_t size,
44607 enum dma_data_direction dir)
44608 {
44609 - struct dma_map_ops *ops = get_dma_ops(dev);
44610 + const struct dma_map_ops *ops = get_dma_ops(dev);
44611 dma_addr_t addr;
44612
44613 kmemcheck_mark_initialized(page_address(page) + offset, size);
44614 @@ -85,7 +85,7 @@ static inline dma_addr_t dma_map_page(st
44615 static inline void dma_unmap_page(struct device *dev, dma_addr_t addr,
44616 size_t size, enum dma_data_direction dir)
44617 {
44618 - struct dma_map_ops *ops = get_dma_ops(dev);
44619 + const struct dma_map_ops *ops = get_dma_ops(dev);
44620
44621 BUG_ON(!valid_dma_direction(dir));
44622 if (ops->unmap_page)
44623 @@ -97,7 +97,7 @@ static inline void dma_sync_single_for_c
44624 size_t size,
44625 enum dma_data_direction dir)
44626 {
44627 - struct dma_map_ops *ops = get_dma_ops(dev);
44628 + const struct dma_map_ops *ops = get_dma_ops(dev);
44629
44630 BUG_ON(!valid_dma_direction(dir));
44631 if (ops->sync_single_for_cpu)
44632 @@ -109,7 +109,7 @@ static inline void dma_sync_single_for_d
44633 dma_addr_t addr, size_t size,
44634 enum dma_data_direction dir)
44635 {
44636 - struct dma_map_ops *ops = get_dma_ops(dev);
44637 + const struct dma_map_ops *ops = get_dma_ops(dev);
44638
44639 BUG_ON(!valid_dma_direction(dir));
44640 if (ops->sync_single_for_device)
44641 @@ -139,7 +139,7 @@ static inline void
44642 dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg,
44643 int nelems, enum dma_data_direction dir)
44644 {
44645 - struct dma_map_ops *ops = get_dma_ops(dev);
44646 + const struct dma_map_ops *ops = get_dma_ops(dev);
44647
44648 BUG_ON(!valid_dma_direction(dir));
44649 if (ops->sync_sg_for_cpu)
44650 @@ -151,7 +151,7 @@ static inline void
44651 dma_sync_sg_for_device(struct device *dev, struct scatterlist *sg,
44652 int nelems, enum dma_data_direction dir)
44653 {
44654 - struct dma_map_ops *ops = get_dma_ops(dev);
44655 + const struct dma_map_ops *ops = get_dma_ops(dev);
44656
44657 BUG_ON(!valid_dma_direction(dir));
44658 if (ops->sync_sg_for_device)
44659 diff -urNp linux-2.6.37/include/asm-generic/futex.h linux-2.6.37/include/asm-generic/futex.h
44660 --- linux-2.6.37/include/asm-generic/futex.h 2011-01-04 19:50:19.000000000 -0500
44661 +++ linux-2.6.37/include/asm-generic/futex.h 2011-01-17 02:41:02.000000000 -0500
44662 @@ -6,7 +6,7 @@
44663 #include <asm/errno.h>
44664
44665 static inline int
44666 -futex_atomic_op_inuser (int encoded_op, int __user *uaddr)
44667 +futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
44668 {
44669 int op = (encoded_op >> 28) & 7;
44670 int cmp = (encoded_op >> 24) & 15;
44671 @@ -48,7 +48,7 @@ futex_atomic_op_inuser (int encoded_op,
44672 }
44673
44674 static inline int
44675 -futex_atomic_cmpxchg_inatomic(int __user *uaddr, int oldval, int newval)
44676 +futex_atomic_cmpxchg_inatomic(u32 __user *uaddr, int oldval, int newval)
44677 {
44678 return -ENOSYS;
44679 }
44680 diff -urNp linux-2.6.37/include/asm-generic/int-l64.h linux-2.6.37/include/asm-generic/int-l64.h
44681 --- linux-2.6.37/include/asm-generic/int-l64.h 2011-01-04 19:50:19.000000000 -0500
44682 +++ linux-2.6.37/include/asm-generic/int-l64.h 2011-01-17 02:41:02.000000000 -0500
44683 @@ -46,6 +46,8 @@ typedef unsigned int u32;
44684 typedef signed long s64;
44685 typedef unsigned long u64;
44686
44687 +typedef unsigned int intoverflow_t __attribute__ ((mode(TI)));
44688 +
44689 #define S8_C(x) x
44690 #define U8_C(x) x ## U
44691 #define S16_C(x) x
44692 diff -urNp linux-2.6.37/include/asm-generic/int-ll64.h linux-2.6.37/include/asm-generic/int-ll64.h
44693 --- linux-2.6.37/include/asm-generic/int-ll64.h 2011-01-04 19:50:19.000000000 -0500
44694 +++ linux-2.6.37/include/asm-generic/int-ll64.h 2011-01-17 02:41:02.000000000 -0500
44695 @@ -51,6 +51,8 @@ typedef unsigned int u32;
44696 typedef signed long long s64;
44697 typedef unsigned long long u64;
44698
44699 +typedef unsigned long long intoverflow_t;
44700 +
44701 #define S8_C(x) x
44702 #define U8_C(x) x ## U
44703 #define S16_C(x) x
44704 diff -urNp linux-2.6.37/include/asm-generic/kmap_types.h linux-2.6.37/include/asm-generic/kmap_types.h
44705 --- linux-2.6.37/include/asm-generic/kmap_types.h 2011-01-04 19:50:19.000000000 -0500
44706 +++ linux-2.6.37/include/asm-generic/kmap_types.h 2011-01-17 02:41:02.000000000 -0500
44707 @@ -29,10 +29,11 @@ KMAP_D(16) KM_IRQ_PTE,
44708 KMAP_D(17) KM_NMI,
44709 KMAP_D(18) KM_NMI_PTE,
44710 KMAP_D(19) KM_KDB,
44711 +KMAP_D(20) KM_CLEARPAGE,
44712 /*
44713 * Remember to update debug_kmap_atomic() when adding new kmap types!
44714 */
44715 -KMAP_D(20) KM_TYPE_NR
44716 +KMAP_D(21) KM_TYPE_NR
44717 };
44718
44719 #undef KMAP_D
44720 diff -urNp linux-2.6.37/include/asm-generic/pgtable.h linux-2.6.37/include/asm-generic/pgtable.h
44721 --- linux-2.6.37/include/asm-generic/pgtable.h 2011-01-04 19:50:19.000000000 -0500
44722 +++ linux-2.6.37/include/asm-generic/pgtable.h 2011-01-17 02:41:02.000000000 -0500
44723 @@ -348,6 +348,14 @@ extern void untrack_pfn_vma(struct vm_ar
44724 unsigned long size);
44725 #endif
44726
44727 +#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
44728 +static inline unsigned long pax_open_kernel(void) { return 0; }
44729 +#endif
44730 +
44731 +#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
44732 +static inline unsigned long pax_close_kernel(void) { return 0; }
44733 +#endif
44734 +
44735 #endif /* !__ASSEMBLY__ */
44736
44737 #endif /* _ASM_GENERIC_PGTABLE_H */
44738 diff -urNp linux-2.6.37/include/asm-generic/pgtable-nopmd.h linux-2.6.37/include/asm-generic/pgtable-nopmd.h
44739 --- linux-2.6.37/include/asm-generic/pgtable-nopmd.h 2011-01-04 19:50:19.000000000 -0500
44740 +++ linux-2.6.37/include/asm-generic/pgtable-nopmd.h 2011-01-17 02:41:02.000000000 -0500
44741 @@ -1,14 +1,19 @@
44742 #ifndef _PGTABLE_NOPMD_H
44743 #define _PGTABLE_NOPMD_H
44744
44745 -#ifndef __ASSEMBLY__
44746 -
44747 #include <asm-generic/pgtable-nopud.h>
44748
44749 -struct mm_struct;
44750 -
44751 #define __PAGETABLE_PMD_FOLDED
44752
44753 +#define PMD_SHIFT PUD_SHIFT
44754 +#define PTRS_PER_PMD 1
44755 +#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
44756 +#define PMD_MASK (~(PMD_SIZE-1))
44757 +
44758 +#ifndef __ASSEMBLY__
44759 +
44760 +struct mm_struct;
44761 +
44762 /*
44763 * Having the pmd type consist of a pud gets the size right, and allows
44764 * us to conceptually access the pud entry that this pmd is folded into
44765 @@ -16,11 +21,6 @@ struct mm_struct;
44766 */
44767 typedef struct { pud_t pud; } pmd_t;
44768
44769 -#define PMD_SHIFT PUD_SHIFT
44770 -#define PTRS_PER_PMD 1
44771 -#define PMD_SIZE (1UL << PMD_SHIFT)
44772 -#define PMD_MASK (~(PMD_SIZE-1))
44773 -
44774 /*
44775 * The "pud_xxx()" functions here are trivial for a folded two-level
44776 * setup: the pmd is never bad, and a pmd always exists (as it's folded
44777 diff -urNp linux-2.6.37/include/asm-generic/pgtable-nopud.h linux-2.6.37/include/asm-generic/pgtable-nopud.h
44778 --- linux-2.6.37/include/asm-generic/pgtable-nopud.h 2011-01-04 19:50:19.000000000 -0500
44779 +++ linux-2.6.37/include/asm-generic/pgtable-nopud.h 2011-01-17 02:41:02.000000000 -0500
44780 @@ -1,10 +1,15 @@
44781 #ifndef _PGTABLE_NOPUD_H
44782 #define _PGTABLE_NOPUD_H
44783
44784 -#ifndef __ASSEMBLY__
44785 -
44786 #define __PAGETABLE_PUD_FOLDED
44787
44788 +#define PUD_SHIFT PGDIR_SHIFT
44789 +#define PTRS_PER_PUD 1
44790 +#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
44791 +#define PUD_MASK (~(PUD_SIZE-1))
44792 +
44793 +#ifndef __ASSEMBLY__
44794 +
44795 /*
44796 * Having the pud type consist of a pgd gets the size right, and allows
44797 * us to conceptually access the pgd entry that this pud is folded into
44798 @@ -12,11 +17,6 @@
44799 */
44800 typedef struct { pgd_t pgd; } pud_t;
44801
44802 -#define PUD_SHIFT PGDIR_SHIFT
44803 -#define PTRS_PER_PUD 1
44804 -#define PUD_SIZE (1UL << PUD_SHIFT)
44805 -#define PUD_MASK (~(PUD_SIZE-1))
44806 -
44807 /*
44808 * The "pgd_xxx()" functions here are trivial for a folded two-level
44809 * setup: the pud is never bad, and a pud always exists (as it's folded
44810 diff -urNp linux-2.6.37/include/asm-generic/vmlinux.lds.h linux-2.6.37/include/asm-generic/vmlinux.lds.h
44811 --- linux-2.6.37/include/asm-generic/vmlinux.lds.h 2011-01-04 19:50:19.000000000 -0500
44812 +++ linux-2.6.37/include/asm-generic/vmlinux.lds.h 2011-01-17 02:41:02.000000000 -0500
44813 @@ -210,6 +210,7 @@
44814 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
44815 VMLINUX_SYMBOL(__start_rodata) = .; \
44816 *(.rodata) *(.rodata.*) \
44817 + *(.data..read_only) \
44818 *(__vermagic) /* Kernel version magic */ \
44819 *(__markers_strings) /* Markers: strings */ \
44820 *(__tracepoints_strings)/* Tracepoints: strings */ \
44821 @@ -679,14 +680,15 @@
44822 * section in the linker script will go there too. @phdr should have
44823 * a leading colon.
44824 *
44825 - * Note that this macros defines __per_cpu_load as an absolute symbol.
44826 + * Note that this macros defines per_cpu_load as an absolute symbol.
44827 * If there is no need to put the percpu section at a predetermined
44828 * address, use PERCPU().
44829 */
44830 #define PERCPU_VADDR(vaddr, phdr) \
44831 - VMLINUX_SYMBOL(__per_cpu_load) = .; \
44832 - .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
44833 + per_cpu_load = .; \
44834 + .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
44835 - LOAD_OFFSET) { \
44836 + VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
44837 VMLINUX_SYMBOL(__per_cpu_start) = .; \
44838 *(.data..percpu..first) \
44839 . = ALIGN(PAGE_SIZE); \
44840 @@ -696,7 +698,7 @@
44841 *(.data..percpu..shared_aligned) \
44842 VMLINUX_SYMBOL(__per_cpu_end) = .; \
44843 } phdr \
44844 - . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
44845 + . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
44846
44847 /**
44848 * PERCPU - define output section for percpu area, simple version
44849 diff -urNp linux-2.6.37/include/drm/drm_pciids.h linux-2.6.37/include/drm/drm_pciids.h
44850 --- linux-2.6.37/include/drm/drm_pciids.h 2011-01-04 19:50:19.000000000 -0500
44851 +++ linux-2.6.37/include/drm/drm_pciids.h 2011-01-17 02:41:02.000000000 -0500
44852 @@ -419,7 +419,7 @@
44853 {0x1002, 0x9713, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS880|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP|RADEON_IS_IGP}, \
44854 {0x1002, 0x9714, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS880|RADEON_NEW_MEMMAP|RADEON_IS_IGP}, \
44855 {0x1002, 0x9715, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS880|RADEON_NEW_MEMMAP|RADEON_IS_IGP}, \
44856 - {0, 0, 0}
44857 + {0, 0, 0, 0, 0, 0}
44858
44859 #define r128_PCI_IDS \
44860 {0x1002, 0x4c45, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
44861 @@ -459,14 +459,14 @@
44862 {0x1002, 0x5446, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
44863 {0x1002, 0x544C, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
44864 {0x1002, 0x5452, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
44865 - {0, 0, 0}
44866 + {0, 0, 0, 0, 0, 0}
44867
44868 #define mga_PCI_IDS \
44869 {0x102b, 0x0520, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MGA_CARD_TYPE_G200}, \
44870 {0x102b, 0x0521, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MGA_CARD_TYPE_G200}, \
44871 {0x102b, 0x0525, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MGA_CARD_TYPE_G400}, \
44872 {0x102b, 0x2527, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MGA_CARD_TYPE_G550}, \
44873 - {0, 0, 0}
44874 + {0, 0, 0, 0, 0, 0}
44875
44876 #define mach64_PCI_IDS \
44877 {0x1002, 0x4749, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
44878 @@ -489,7 +489,7 @@
44879 {0x1002, 0x4c53, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
44880 {0x1002, 0x4c4d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
44881 {0x1002, 0x4c4e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
44882 - {0, 0, 0}
44883 + {0, 0, 0, 0, 0, 0}
44884
44885 #define sisdrv_PCI_IDS \
44886 {0x1039, 0x0300, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
44887 @@ -500,7 +500,7 @@
44888 {0x1039, 0x7300, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
44889 {0x18CA, 0x0040, PCI_ANY_ID, PCI_ANY_ID, 0, 0, SIS_CHIP_315}, \
44890 {0x18CA, 0x0042, PCI_ANY_ID, PCI_ANY_ID, 0, 0, SIS_CHIP_315}, \
44891 - {0, 0, 0}
44892 + {0, 0, 0, 0, 0, 0}
44893
44894 #define tdfx_PCI_IDS \
44895 {0x121a, 0x0003, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
44896 @@ -509,7 +509,7 @@
44897 {0x121a, 0x0007, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
44898 {0x121a, 0x0009, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
44899 {0x121a, 0x000b, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
44900 - {0, 0, 0}
44901 + {0, 0, 0, 0, 0, 0}
44902
44903 #define viadrv_PCI_IDS \
44904 {0x1106, 0x3022, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
44905 @@ -521,14 +521,14 @@
44906 {0x1106, 0x3343, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
44907 {0x1106, 0x3230, PCI_ANY_ID, PCI_ANY_ID, 0, 0, VIA_DX9_0}, \
44908 {0x1106, 0x3157, PCI_ANY_ID, PCI_ANY_ID, 0, 0, VIA_PRO_GROUP_A}, \
44909 - {0, 0, 0}
44910 + {0, 0, 0, 0, 0, 0}
44911
44912 #define i810_PCI_IDS \
44913 {0x8086, 0x7121, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
44914 {0x8086, 0x7123, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
44915 {0x8086, 0x7125, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
44916 {0x8086, 0x1132, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
44917 - {0, 0, 0}
44918 + {0, 0, 0, 0, 0, 0}
44919
44920 #define i830_PCI_IDS \
44921 {0x8086, 0x3577, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
44922 @@ -536,11 +536,11 @@
44923 {0x8086, 0x3582, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
44924 {0x8086, 0x2572, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
44925 {0x8086, 0x358e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
44926 - {0, 0, 0}
44927 + {0, 0, 0, 0, 0, 0}
44928
44929 #define gamma_PCI_IDS \
44930 {0x3d3d, 0x0008, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
44931 - {0, 0, 0}
44932 + {0, 0, 0, 0, 0, 0}
44933
44934 #define savage_PCI_IDS \
44935 {0x5333, 0x8a20, PCI_ANY_ID, PCI_ANY_ID, 0, 0, S3_SAVAGE3D}, \
44936 @@ -566,10 +566,10 @@
44937 {0x5333, 0x8d02, PCI_ANY_ID, PCI_ANY_ID, 0, 0, S3_TWISTER}, \
44938 {0x5333, 0x8d03, PCI_ANY_ID, PCI_ANY_ID, 0, 0, S3_PROSAVAGEDDR}, \
44939 {0x5333, 0x8d04, PCI_ANY_ID, PCI_ANY_ID, 0, 0, S3_PROSAVAGEDDR}, \
44940 - {0, 0, 0}
44941 + {0, 0, 0, 0, 0, 0}
44942
44943 #define ffb_PCI_IDS \
44944 - {0, 0, 0}
44945 + {0, 0, 0, 0, 0, 0}
44946
44947 #define i915_PCI_IDS \
44948 {0x8086, 0x3577, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_DISPLAY_VGA << 8, 0xffff00, 0}, \
44949 @@ -603,4 +603,4 @@
44950 {0x8086, 0x0042, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_DISPLAY_VGA << 8, 0xffff00, 0}, \
44951 {0x8086, 0x0046, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_DISPLAY_VGA << 8, 0xffff00, 0}, \
44952 {0x8086, 0x0102, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_DISPLAY_VGA << 8, 0xffff00, 0}, \
44953 - {0, 0, 0}
44954 + {0, 0, 0, 0, 0, 0}
44955 diff -urNp linux-2.6.37/include/drm/drmP.h linux-2.6.37/include/drm/drmP.h
44956 --- linux-2.6.37/include/drm/drmP.h 2011-01-04 19:50:19.000000000 -0500
44957 +++ linux-2.6.37/include/drm/drmP.h 2011-01-17 02:41:02.000000000 -0500
44958 @@ -804,7 +804,7 @@ struct drm_driver {
44959 void (*vgaarb_irq)(struct drm_device *dev, bool state);
44960
44961 /* Driver private ops for this object */
44962 - struct vm_operations_struct *gem_vm_ops;
44963 + const struct vm_operations_struct *gem_vm_ops;
44964
44965 int major;
44966 int minor;
44967 @@ -817,7 +817,7 @@ struct drm_driver {
44968 int dev_priv_size;
44969 struct drm_ioctl_desc *ioctls;
44970 int num_ioctls;
44971 - struct file_operations fops;
44972 + const struct file_operations fops;
44973 struct pci_driver pci_driver;
44974 struct platform_device *platform_device;
44975 /* List of devices hanging off this driver */
44976 @@ -914,7 +914,7 @@ struct drm_device {
44977
44978 /** \name Usage Counters */
44979 /*@{ */
44980 - int open_count; /**< Outstanding files open */
44981 + atomic_t open_count; /**< Outstanding files open */
44982 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
44983 atomic_t vma_count; /**< Outstanding vma areas open */
44984 int buf_use; /**< Buffers in use -- cannot alloc */
44985 @@ -925,7 +925,7 @@ struct drm_device {
44986 /*@{ */
44987 unsigned long counters;
44988 enum drm_stat_type types[15];
44989 - atomic_t counts[15];
44990 + atomic_unchecked_t counts[15];
44991 /*@} */
44992
44993 struct list_head filelist;
44994 diff -urNp linux-2.6.37/include/linux/a.out.h linux-2.6.37/include/linux/a.out.h
44995 --- linux-2.6.37/include/linux/a.out.h 2011-01-04 19:50:19.000000000 -0500
44996 +++ linux-2.6.37/include/linux/a.out.h 2011-01-17 02:41:02.000000000 -0500
44997 @@ -39,6 +39,14 @@ enum machine_type {
44998 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
44999 };
45000
45001 +/* Constants for the N_FLAGS field */
45002 +#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
45003 +#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
45004 +#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
45005 +#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
45006 +/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
45007 +#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
45008 +
45009 #if !defined (N_MAGIC)
45010 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
45011 #endif
45012 diff -urNp linux-2.6.37/include/linux/atmdev.h linux-2.6.37/include/linux/atmdev.h
45013 --- linux-2.6.37/include/linux/atmdev.h 2011-01-04 19:50:19.000000000 -0500
45014 +++ linux-2.6.37/include/linux/atmdev.h 2011-01-17 02:41:02.000000000 -0500
45015 @@ -237,7 +237,7 @@ struct compat_atm_iobuf {
45016 #endif
45017
45018 struct k_atm_aal_stats {
45019 -#define __HANDLE_ITEM(i) atomic_t i
45020 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
45021 __AAL_STAT_ITEMS
45022 #undef __HANDLE_ITEM
45023 };
45024 diff -urNp linux-2.6.37/include/linux/binfmts.h linux-2.6.37/include/linux/binfmts.h
45025 --- linux-2.6.37/include/linux/binfmts.h 2011-01-04 19:50:19.000000000 -0500
45026 +++ linux-2.6.37/include/linux/binfmts.h 2011-01-17 02:41:02.000000000 -0500
45027 @@ -92,6 +92,7 @@ struct linux_binfmt {
45028 int (*load_binary)(struct linux_binprm *, struct pt_regs * regs);
45029 int (*load_shlib)(struct file *);
45030 int (*core_dump)(struct coredump_params *cprm);
45031 + void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
45032 unsigned long min_coredump; /* minimal dump size */
45033 int hasvdso;
45034 };
45035 diff -urNp linux-2.6.37/include/linux/blkdev.h linux-2.6.37/include/linux/blkdev.h
45036 --- linux-2.6.37/include/linux/blkdev.h 2011-01-04 19:50:19.000000000 -0500
45037 +++ linux-2.6.37/include/linux/blkdev.h 2011-01-17 02:41:02.000000000 -0500
45038 @@ -1250,19 +1250,19 @@ queue_max_integrity_segments(struct requ
45039 #endif /* CONFIG_BLK_DEV_INTEGRITY */
45040
45041 struct block_device_operations {
45042 - int (*open) (struct block_device *, fmode_t);
45043 - int (*release) (struct gendisk *, fmode_t);
45044 - int (*ioctl) (struct block_device *, fmode_t, unsigned, unsigned long);
45045 - int (*compat_ioctl) (struct block_device *, fmode_t, unsigned, unsigned long);
45046 - int (*direct_access) (struct block_device *, sector_t,
45047 + int (* const open) (struct block_device *, fmode_t);
45048 + int (* const release) (struct gendisk *, fmode_t);
45049 + int (* const ioctl) (struct block_device *, fmode_t, unsigned, unsigned long);
45050 + int (* const compat_ioctl) (struct block_device *, fmode_t, unsigned, unsigned long);
45051 + int (* const direct_access) (struct block_device *, sector_t,
45052 void **, unsigned long *);
45053 - int (*media_changed) (struct gendisk *);
45054 - void (*unlock_native_capacity) (struct gendisk *);
45055 - int (*revalidate_disk) (struct gendisk *);
45056 - int (*getgeo)(struct block_device *, struct hd_geometry *);
45057 + int (* const media_changed) (struct gendisk *);
45058 + void (* const unlock_native_capacity) (struct gendisk *);
45059 + int (* const revalidate_disk) (struct gendisk *);
45060 + int (* const getgeo)(struct block_device *, struct hd_geometry *);
45061 /* this callback is with swap_lock and sometimes page table lock held */
45062 - void (*swap_slot_free_notify) (struct block_device *, unsigned long);
45063 - struct module *owner;
45064 + void (* const swap_slot_free_notify) (struct block_device *, unsigned long);
45065 + struct module * const owner;
45066 };
45067
45068 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
45069 diff -urNp linux-2.6.37/include/linux/byteorder/little_endian.h linux-2.6.37/include/linux/byteorder/little_endian.h
45070 --- linux-2.6.37/include/linux/byteorder/little_endian.h 2011-01-04 19:50:19.000000000 -0500
45071 +++ linux-2.6.37/include/linux/byteorder/little_endian.h 2011-01-17 02:41:02.000000000 -0500
45072 @@ -42,51 +42,51 @@
45073
45074 static inline __le64 __cpu_to_le64p(const __u64 *p)
45075 {
45076 - return (__force __le64)*p;
45077 + return (__force const __le64)*p;
45078 }
45079 static inline __u64 __le64_to_cpup(const __le64 *p)
45080 {
45081 - return (__force __u64)*p;
45082 + return (__force const __u64)*p;
45083 }
45084 static inline __le32 __cpu_to_le32p(const __u32 *p)
45085 {
45086 - return (__force __le32)*p;
45087 + return (__force const __le32)*p;
45088 }
45089 static inline __u32 __le32_to_cpup(const __le32 *p)
45090 {
45091 - return (__force __u32)*p;
45092 + return (__force const __u32)*p;
45093 }
45094 static inline __le16 __cpu_to_le16p(const __u16 *p)
45095 {
45096 - return (__force __le16)*p;
45097 + return (__force const __le16)*p;
45098 }
45099 static inline __u16 __le16_to_cpup(const __le16 *p)
45100 {
45101 - return (__force __u16)*p;
45102 + return (__force const __u16)*p;
45103 }
45104 static inline __be64 __cpu_to_be64p(const __u64 *p)
45105 {
45106 - return (__force __be64)__swab64p(p);
45107 + return (__force const __be64)__swab64p(p);
45108 }
45109 static inline __u64 __be64_to_cpup(const __be64 *p)
45110 {
45111 - return __swab64p((__u64 *)p);
45112 + return __swab64p((const __u64 *)p);
45113 }
45114 static inline __be32 __cpu_to_be32p(const __u32 *p)
45115 {
45116 - return (__force __be32)__swab32p(p);
45117 + return (__force const __be32)__swab32p(p);
45118 }
45119 static inline __u32 __be32_to_cpup(const __be32 *p)
45120 {
45121 - return __swab32p((__u32 *)p);
45122 + return __swab32p((const __u32 *)p);
45123 }
45124 static inline __be16 __cpu_to_be16p(const __u16 *p)
45125 {
45126 - return (__force __be16)__swab16p(p);
45127 + return (__force const __be16)__swab16p(p);
45128 }
45129 static inline __u16 __be16_to_cpup(const __be16 *p)
45130 {
45131 - return __swab16p((__u16 *)p);
45132 + return __swab16p((const __u16 *)p);
45133 }
45134 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
45135 #define __le64_to_cpus(x) do { (void)(x); } while (0)
45136 diff -urNp linux-2.6.37/include/linux/cache.h linux-2.6.37/include/linux/cache.h
45137 --- linux-2.6.37/include/linux/cache.h 2011-01-04 19:50:19.000000000 -0500
45138 +++ linux-2.6.37/include/linux/cache.h 2011-01-17 02:41:02.000000000 -0500
45139 @@ -16,6 +16,10 @@
45140 #define __read_mostly
45141 #endif
45142
45143 +#ifndef __read_only
45144 +#define __read_only __read_mostly
45145 +#endif
45146 +
45147 #ifndef ____cacheline_aligned
45148 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
45149 #endif
45150 diff -urNp linux-2.6.37/include/linux/capability.h linux-2.6.37/include/linux/capability.h
45151 --- linux-2.6.37/include/linux/capability.h 2011-01-04 19:50:19.000000000 -0500
45152 +++ linux-2.6.37/include/linux/capability.h 2011-01-17 02:41:02.000000000 -0500
45153 @@ -558,6 +558,7 @@ extern const kernel_cap_t __cap_init_eff
45154 (security_real_capable_noaudit((t), (cap)) == 0)
45155
45156 extern int capable(int cap);
45157 +int capable_nolog(int cap);
45158
45159 /* audit system wants to get cap info from files as well */
45160 struct dentry;
45161 diff -urNp linux-2.6.37/include/linux/compiler-gcc4.h linux-2.6.37/include/linux/compiler-gcc4.h
45162 --- linux-2.6.37/include/linux/compiler-gcc4.h 2011-01-04 19:50:19.000000000 -0500
45163 +++ linux-2.6.37/include/linux/compiler-gcc4.h 2011-01-17 02:41:02.000000000 -0500
45164 @@ -54,6 +54,10 @@
45165
45166 #endif
45167
45168 +#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
45169 +#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
45170 +#define __bos0(ptr) __bos((ptr), 0)
45171 +#define __bos1(ptr) __bos((ptr), 1)
45172 #endif
45173
45174 #if __GNUC_MINOR__ > 0
45175 diff -urNp linux-2.6.37/include/linux/compiler.h linux-2.6.37/include/linux/compiler.h
45176 --- linux-2.6.37/include/linux/compiler.h 2011-01-04 19:50:19.000000000 -0500
45177 +++ linux-2.6.37/include/linux/compiler.h 2011-01-17 02:41:02.000000000 -0500
45178 @@ -273,6 +273,22 @@ void ftrace_likely_update(struct ftrace_
45179 #define __cold
45180 #endif
45181
45182 +#ifndef __alloc_size
45183 +#define __alloc_size
45184 +#endif
45185 +
45186 +#ifndef __bos
45187 +#define __bos
45188 +#endif
45189 +
45190 +#ifndef __bos0
45191 +#define __bos0
45192 +#endif
45193 +
45194 +#ifndef __bos1
45195 +#define __bos1
45196 +#endif
45197 +
45198 /* Simple shorthand for a section definition */
45199 #ifndef __section
45200 # define __section(S) __attribute__ ((__section__(#S)))
45201 @@ -306,6 +322,7 @@ void ftrace_likely_update(struct ftrace_
45202 * use is to mediate communication between process-level code and irq/NMI
45203 * handlers, all running on the same CPU.
45204 */
45205 -#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
45206 +#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
45207 +#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
45208
45209 #endif /* __LINUX_COMPILER_H */
45210 diff -urNp linux-2.6.37/include/linux/cpuset.h linux-2.6.37/include/linux/cpuset.h
45211 --- linux-2.6.37/include/linux/cpuset.h 2011-01-04 19:50:19.000000000 -0500
45212 +++ linux-2.6.37/include/linux/cpuset.h 2011-01-17 02:41:02.000000000 -0500
45213 @@ -118,7 +118,7 @@ static inline void put_mems_allowed(void
45214 * nodemask.
45215 */
45216 smp_mb();
45217 - --ACCESS_ONCE(current->mems_allowed_change_disable);
45218 + --ACCESS_ONCE_RW(current->mems_allowed_change_disable);
45219 }
45220
45221 static inline void set_mems_allowed(nodemask_t nodemask)
45222 diff -urNp linux-2.6.37/include/linux/decompress/mm.h linux-2.6.37/include/linux/decompress/mm.h
45223 --- linux-2.6.37/include/linux/decompress/mm.h 2011-01-04 19:50:19.000000000 -0500
45224 +++ linux-2.6.37/include/linux/decompress/mm.h 2011-01-17 02:41:02.000000000 -0500
45225 @@ -78,7 +78,7 @@ static void free(void *where)
45226 * warnings when not needed (indeed large_malloc / large_free are not
45227 * needed by inflate */
45228
45229 -#define malloc(a) kmalloc(a, GFP_KERNEL)
45230 +#define malloc(a) kmalloc((a), GFP_KERNEL)
45231 #define free(a) kfree(a)
45232
45233 #define large_malloc(a) vmalloc(a)
45234 diff -urNp linux-2.6.37/include/linux/dma-mapping.h linux-2.6.37/include/linux/dma-mapping.h
45235 --- linux-2.6.37/include/linux/dma-mapping.h 2011-01-04 19:50:19.000000000 -0500
45236 +++ linux-2.6.37/include/linux/dma-mapping.h 2011-01-17 02:41:02.000000000 -0500
45237 @@ -16,40 +16,40 @@ enum dma_data_direction {
45238 };
45239
45240 struct dma_map_ops {
45241 - void* (*alloc_coherent)(struct device *dev, size_t size,
45242 + void* (* const alloc_coherent)(struct device *dev, size_t size,
45243 dma_addr_t *dma_handle, gfp_t gfp);
45244 - void (*free_coherent)(struct device *dev, size_t size,
45245 + void (* const free_coherent)(struct device *dev, size_t size,
45246 void *vaddr, dma_addr_t dma_handle);
45247 - dma_addr_t (*map_page)(struct device *dev, struct page *page,
45248 + dma_addr_t (* const map_page)(struct device *dev, struct page *page,
45249 unsigned long offset, size_t size,
45250 enum dma_data_direction dir,
45251 struct dma_attrs *attrs);
45252 - void (*unmap_page)(struct device *dev, dma_addr_t dma_handle,
45253 + void (* const unmap_page)(struct device *dev, dma_addr_t dma_handle,
45254 size_t size, enum dma_data_direction dir,
45255 struct dma_attrs *attrs);
45256 - int (*map_sg)(struct device *dev, struct scatterlist *sg,
45257 + int (* const map_sg)(struct device *dev, struct scatterlist *sg,
45258 int nents, enum dma_data_direction dir,
45259 struct dma_attrs *attrs);
45260 - void (*unmap_sg)(struct device *dev,
45261 + void (* const unmap_sg)(struct device *dev,
45262 struct scatterlist *sg, int nents,
45263 enum dma_data_direction dir,
45264 struct dma_attrs *attrs);
45265 - void (*sync_single_for_cpu)(struct device *dev,
45266 + void (* const sync_single_for_cpu)(struct device *dev,
45267 dma_addr_t dma_handle, size_t size,
45268 enum dma_data_direction dir);
45269 - void (*sync_single_for_device)(struct device *dev,
45270 + void (* const sync_single_for_device)(struct device *dev,
45271 dma_addr_t dma_handle, size_t size,
45272 enum dma_data_direction dir);
45273 - void (*sync_sg_for_cpu)(struct device *dev,
45274 + void (* const sync_sg_for_cpu)(struct device *dev,
45275 struct scatterlist *sg, int nents,
45276 enum dma_data_direction dir);
45277 - void (*sync_sg_for_device)(struct device *dev,
45278 + void (* const sync_sg_for_device)(struct device *dev,
45279 struct scatterlist *sg, int nents,
45280 enum dma_data_direction dir);
45281 - int (*mapping_error)(struct device *dev, dma_addr_t dma_addr);
45282 - int (*dma_supported)(struct device *dev, u64 mask);
45283 - int (*set_dma_mask)(struct device *dev, u64 mask);
45284 - int is_phys;
45285 + int (* const mapping_error)(struct device *dev, dma_addr_t dma_addr);
45286 + int (* const dma_supported)(struct device *dev, u64 mask);
45287 + int (* set_dma_mask)(struct device *dev, u64 mask);
45288 + const int is_phys;
45289 };
45290
45291 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
45292 diff -urNp linux-2.6.37/include/linux/elf.h linux-2.6.37/include/linux/elf.h
45293 --- linux-2.6.37/include/linux/elf.h 2011-01-04 19:50:19.000000000 -0500
45294 +++ linux-2.6.37/include/linux/elf.h 2011-01-17 02:41:02.000000000 -0500
45295 @@ -49,6 +49,17 @@ typedef __s64 Elf64_Sxword;
45296 #define PT_GNU_EH_FRAME 0x6474e550
45297
45298 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
45299 +#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
45300 +
45301 +#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
45302 +
45303 +/* Constants for the e_flags field */
45304 +#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
45305 +#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
45306 +#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
45307 +#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
45308 +/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
45309 +#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
45310
45311 /*
45312 * Extended Numbering
45313 @@ -106,6 +117,8 @@ typedef __s64 Elf64_Sxword;
45314 #define DT_DEBUG 21
45315 #define DT_TEXTREL 22
45316 #define DT_JMPREL 23
45317 +#define DT_FLAGS 30
45318 + #define DF_TEXTREL 0x00000004
45319 #define DT_ENCODING 32
45320 #define OLD_DT_LOOS 0x60000000
45321 #define DT_LOOS 0x6000000d
45322 @@ -252,6 +265,19 @@ typedef struct elf64_hdr {
45323 #define PF_W 0x2
45324 #define PF_X 0x1
45325
45326 +#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
45327 +#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
45328 +#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
45329 +#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
45330 +#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
45331 +#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
45332 +/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
45333 +/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
45334 +#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
45335 +#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
45336 +#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
45337 +#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
45338 +
45339 typedef struct elf32_phdr{
45340 Elf32_Word p_type;
45341 Elf32_Off p_offset;
45342 @@ -344,6 +370,8 @@ typedef struct elf64_shdr {
45343 #define EI_OSABI 7
45344 #define EI_PAD 8
45345
45346 +#define EI_PAX 14
45347 +
45348 #define ELFMAG0 0x7f /* EI_MAG */
45349 #define ELFMAG1 'E'
45350 #define ELFMAG2 'L'
45351 @@ -421,6 +449,7 @@ extern Elf32_Dyn _DYNAMIC [];
45352 #define elf_note elf32_note
45353 #define elf_addr_t Elf32_Off
45354 #define Elf_Half Elf32_Half
45355 +#define elf_dyn Elf32_Dyn
45356
45357 #else
45358
45359 @@ -431,6 +460,7 @@ extern Elf64_Dyn _DYNAMIC [];
45360 #define elf_note elf64_note
45361 #define elf_addr_t Elf64_Off
45362 #define Elf_Half Elf64_Half
45363 +#define elf_dyn Elf64_Dyn
45364
45365 #endif
45366
45367 diff -urNp linux-2.6.37/include/linux/fs.h linux-2.6.37/include/linux/fs.h
45368 --- linux-2.6.37/include/linux/fs.h 2011-01-04 19:50:19.000000000 -0500
45369 +++ linux-2.6.37/include/linux/fs.h 2011-01-17 02:43:32.000000000 -0500
45370 @@ -105,6 +105,11 @@ struct inodes_stat_t {
45371 /* File was opened by fanotify and shouldn't generate fanotify events */
45372 #define FMODE_NONOTIFY ((__force fmode_t)0x1000000)
45373
45374 +/* Hack for grsec so as not to require read permission simply to execute
45375 + * a binary
45376 + */
45377 +#define FMODE_GREXEC ((__force fmode_t)0x2000000)
45378 +
45379 /*
45380 * The below are the various read and write types that we support. Some of
45381 * them include behavioral modifiers that send information down to the
45382 @@ -578,42 +583,42 @@ typedef int (*read_actor_t)(read_descrip
45383 unsigned long, unsigned long);
45384
45385 struct address_space_operations {
45386 - int (*writepage)(struct page *page, struct writeback_control *wbc);
45387 - int (*readpage)(struct file *, struct page *);
45388 - void (*sync_page)(struct page *);
45389 + int (* const writepage)(struct page *page, struct writeback_control *wbc);
45390 + int (* const readpage)(struct file *, struct page *);
45391 + void (* const sync_page)(struct page *);
45392
45393 /* Write back some dirty pages from this mapping. */
45394 - int (*writepages)(struct address_space *, struct writeback_control *);
45395 + int (* const writepages)(struct address_space *, struct writeback_control *);
45396
45397 /* Set a page dirty. Return true if this dirtied it */
45398 - int (*set_page_dirty)(struct page *page);
45399 + int (* const set_page_dirty)(struct page *page);
45400
45401 - int (*readpages)(struct file *filp, struct address_space *mapping,
45402 + int (* const readpages)(struct file *filp, struct address_space *mapping,
45403 struct list_head *pages, unsigned nr_pages);
45404
45405 - int (*write_begin)(struct file *, struct address_space *mapping,
45406 + int (* const write_begin)(struct file *, struct address_space *mapping,
45407 loff_t pos, unsigned len, unsigned flags,
45408 struct page **pagep, void **fsdata);
45409 - int (*write_end)(struct file *, struct address_space *mapping,
45410 + int (* const write_end)(struct file *, struct address_space *mapping,
45411 loff_t pos, unsigned len, unsigned copied,
45412 struct page *page, void *fsdata);
45413
45414 /* Unfortunately this kludge is needed for FIBMAP. Don't use it */
45415 - sector_t (*bmap)(struct address_space *, sector_t);
45416 - void (*invalidatepage) (struct page *, unsigned long);
45417 - int (*releasepage) (struct page *, gfp_t);
45418 - void (*freepage)(struct page *);
45419 - ssize_t (*direct_IO)(int, struct kiocb *, const struct iovec *iov,
45420 + sector_t (* const bmap)(struct address_space *, sector_t);
45421 + void (* const invalidatepage) (struct page *, unsigned long);
45422 + int (* const releasepage) (struct page *, gfp_t);
45423 + void (* const freepage)(struct page *);
45424 + ssize_t (* const direct_IO)(int, struct kiocb *, const struct iovec *iov,
45425 loff_t offset, unsigned long nr_segs);
45426 - int (*get_xip_mem)(struct address_space *, pgoff_t, int,
45427 + int (* const get_xip_mem)(struct address_space *, pgoff_t, int,
45428 void **, unsigned long *);
45429 /* migrate the contents of a page to the specified target */
45430 - int (*migratepage) (struct address_space *,
45431 + int (* const migratepage) (struct address_space *,
45432 struct page *, struct page *);
45433 - int (*launder_page) (struct page *);
45434 - int (*is_partially_uptodate) (struct page *, read_descriptor_t *,
45435 + int (* const launder_page) (struct page *);
45436 + int (* const is_partially_uptodate) (struct page *, read_descriptor_t *,
45437 unsigned long);
45438 - int (*error_remove_page)(struct address_space *, struct page *);
45439 + int (* const error_remove_page)(struct address_space *, struct page *);
45440 };
45441
45442 /*
45443 @@ -1049,18 +1054,18 @@ static inline int file_check_writeable(s
45444 typedef struct files_struct *fl_owner_t;
45445
45446 struct file_lock_operations {
45447 - void (*fl_copy_lock)(struct file_lock *, struct file_lock *);
45448 - void (*fl_release_private)(struct file_lock *);
45449 + void (* const fl_copy_lock)(struct file_lock *, struct file_lock *);
45450 + void (* const fl_release_private)(struct file_lock *);
45451 };
45452
45453 struct lock_manager_operations {
45454 - int (*fl_compare_owner)(struct file_lock *, struct file_lock *);
45455 - void (*fl_notify)(struct file_lock *); /* unblock callback */
45456 - int (*fl_grant)(struct file_lock *, struct file_lock *, int);
45457 - void (*fl_release_private)(struct file_lock *);
45458 - void (*fl_break)(struct file_lock *);
45459 - int (*fl_mylease)(struct file_lock *, struct file_lock *);
45460 - int (*fl_change)(struct file_lock **, int);
45461 + int (* const fl_compare_owner)(struct file_lock *, struct file_lock *);
45462 + void (* const fl_notify)(struct file_lock *); /* unblock callback */
45463 + int (* const fl_grant)(struct file_lock *, struct file_lock *, int);
45464 + void (* const fl_release_private)(struct file_lock *);
45465 + void (* const fl_break)(struct file_lock *);
45466 + int (* const fl_mylease)(struct file_lock *, struct file_lock *);
45467 + int (* const fl_change)(struct file_lock **, int);
45468 };
45469
45470 struct lock_manager {
45471 @@ -1474,7 +1479,7 @@ struct fiemap_extent_info {
45472 unsigned int fi_flags; /* Flags as passed from user */
45473 unsigned int fi_extents_mapped; /* Number of mapped extents */
45474 unsigned int fi_extents_max; /* Size of fiemap_extent array */
45475 - struct fiemap_extent *fi_extents_start; /* Start of fiemap_extent
45476 + struct fiemap_extent __user *fi_extents_start; /* Start of fiemap_extent
45477 * array */
45478 };
45479 int fiemap_fill_next_extent(struct fiemap_extent_info *info, u64 logical,
45480 @@ -1590,29 +1595,29 @@ extern ssize_t vfs_writev(struct file *,
45481 unsigned long, loff_t *);
45482
45483 struct super_operations {
45484 - struct inode *(*alloc_inode)(struct super_block *sb);
45485 - void (*destroy_inode)(struct inode *);
45486 + struct inode *(* const alloc_inode)(struct super_block *sb);
45487 + void (* const destroy_inode)(struct inode *);
45488
45489 - void (*dirty_inode) (struct inode *);
45490 - int (*write_inode) (struct inode *, struct writeback_control *wbc);
45491 - int (*drop_inode) (struct inode *);
45492 - void (*evict_inode) (struct inode *);
45493 - void (*put_super) (struct super_block *);
45494 - void (*write_super) (struct super_block *);
45495 - int (*sync_fs)(struct super_block *sb, int wait);
45496 - int (*freeze_fs) (struct super_block *);
45497 - int (*unfreeze_fs) (struct super_block *);
45498 - int (*statfs) (struct dentry *, struct kstatfs *);
45499 - int (*remount_fs) (struct super_block *, int *, char *);
45500 - void (*umount_begin) (struct super_block *);
45501 + void (* const dirty_inode) (struct inode *);
45502 + int (* const write_inode) (struct inode *, struct writeback_control *wbc);
45503 + int (* const drop_inode) (struct inode *);
45504 + void (* const evict_inode) (struct inode *);
45505 + void (* const put_super) (struct super_block *);
45506 + void (* const write_super) (struct super_block *);
45507 + int (* const sync_fs)(struct super_block *sb, int wait);
45508 + int (* const freeze_fs) (struct super_block *);
45509 + int (* const unfreeze_fs) (struct super_block *);
45510 + int (* const statfs) (struct dentry *, struct kstatfs *);
45511 + int (* const remount_fs) (struct super_block *, int *, char *);
45512 + void (* const umount_begin) (struct super_block *);
45513
45514 - int (*show_options)(struct seq_file *, struct vfsmount *);
45515 - int (*show_stats)(struct seq_file *, struct vfsmount *);
45516 + int (* const show_options)(struct seq_file *, struct vfsmount *);
45517 + int (* const show_stats)(struct seq_file *, struct vfsmount *);
45518 #ifdef CONFIG_QUOTA
45519 - ssize_t (*quota_read)(struct super_block *, int, char *, size_t, loff_t);
45520 - ssize_t (*quota_write)(struct super_block *, int, const char *, size_t, loff_t);
45521 + ssize_t (* const quota_read)(struct super_block *, int, char *, size_t, loff_t);
45522 + ssize_t (* const quota_write)(struct super_block *, int, const char *, size_t, loff_t);
45523 #endif
45524 - int (*bdev_try_to_free_page)(struct super_block*, struct page*, gfp_t);
45525 + int (* const bdev_try_to_free_page)(struct super_block*, struct page*, gfp_t);
45526 };
45527
45528 /*
45529 diff -urNp linux-2.6.37/include/linux/fs_struct.h linux-2.6.37/include/linux/fs_struct.h
45530 --- linux-2.6.37/include/linux/fs_struct.h 2011-01-04 19:50:19.000000000 -0500
45531 +++ linux-2.6.37/include/linux/fs_struct.h 2011-01-17 02:41:02.000000000 -0500
45532 @@ -4,7 +4,7 @@
45533 #include <linux/path.h>
45534
45535 struct fs_struct {
45536 - int users;
45537 + atomic_t users;
45538 spinlock_t lock;
45539 int umask;
45540 int in_exec;
45541 diff -urNp linux-2.6.37/include/linux/genhd.h linux-2.6.37/include/linux/genhd.h
45542 --- linux-2.6.37/include/linux/genhd.h 2011-01-04 19:50:19.000000000 -0500
45543 +++ linux-2.6.37/include/linux/genhd.h 2011-01-17 02:41:02.000000000 -0500
45544 @@ -172,7 +172,7 @@ struct gendisk {
45545
45546 struct timer_rand_state *random;
45547
45548 - atomic_t sync_io; /* RAID */
45549 + atomic_unchecked_t sync_io; /* RAID */
45550 struct work_struct async_notify;
45551 #ifdef CONFIG_BLK_DEV_INTEGRITY
45552 struct blk_integrity *integrity;
45553 diff -urNp linux-2.6.37/include/linux/gracl.h linux-2.6.37/include/linux/gracl.h
45554 --- linux-2.6.37/include/linux/gracl.h 1969-12-31 19:00:00.000000000 -0500
45555 +++ linux-2.6.37/include/linux/gracl.h 2011-01-17 02:41:02.000000000 -0500
45556 @@ -0,0 +1,317 @@
45557 +#ifndef GR_ACL_H
45558 +#define GR_ACL_H
45559 +
45560 +#include <linux/grdefs.h>
45561 +#include <linux/resource.h>
45562 +#include <linux/capability.h>
45563 +#include <linux/dcache.h>
45564 +#include <asm/resource.h>
45565 +
45566 +/* Major status information */
45567 +
45568 +#define GR_VERSION "grsecurity 2.2.1"
45569 +#define GRSECURITY_VERSION 0x2201
45570 +
45571 +enum {
45572 + GR_SHUTDOWN = 0,
45573 + GR_ENABLE = 1,
45574 + GR_SPROLE = 2,
45575 + GR_RELOAD = 3,
45576 + GR_SEGVMOD = 4,
45577 + GR_STATUS = 5,
45578 + GR_UNSPROLE = 6,
45579 + GR_PASSSET = 7,
45580 + GR_SPROLEPAM = 8,
45581 +};
45582 +
45583 +/* Password setup definitions
45584 + * kernel/grhash.c */
45585 +enum {
45586 + GR_PW_LEN = 128,
45587 + GR_SALT_LEN = 16,
45588 + GR_SHA_LEN = 32,
45589 +};
45590 +
45591 +enum {
45592 + GR_SPROLE_LEN = 64,
45593 +};
45594 +
45595 +enum {
45596 + GR_NO_GLOB = 0,
45597 + GR_REG_GLOB,
45598 + GR_CREATE_GLOB
45599 +};
45600 +
45601 +#define GR_NLIMITS 32
45602 +
45603 +/* Begin Data Structures */
45604 +
45605 +struct sprole_pw {
45606 + unsigned char *rolename;
45607 + unsigned char salt[GR_SALT_LEN];
45608 + unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
45609 +};
45610 +
45611 +struct name_entry {
45612 + __u32 key;
45613 + ino_t inode;
45614 + dev_t device;
45615 + char *name;
45616 + __u16 len;
45617 + __u8 deleted;
45618 + struct name_entry *prev;
45619 + struct name_entry *next;
45620 +};
45621 +
45622 +struct inodev_entry {
45623 + struct name_entry *nentry;
45624 + struct inodev_entry *prev;
45625 + struct inodev_entry *next;
45626 +};
45627 +
45628 +struct acl_role_db {
45629 + struct acl_role_label **r_hash;
45630 + __u32 r_size;
45631 +};
45632 +
45633 +struct inodev_db {
45634 + struct inodev_entry **i_hash;
45635 + __u32 i_size;
45636 +};
45637 +
45638 +struct name_db {
45639 + struct name_entry **n_hash;
45640 + __u32 n_size;
45641 +};
45642 +
45643 +struct crash_uid {
45644 + uid_t uid;
45645 + unsigned long expires;
45646 +};
45647 +
45648 +struct gr_hash_struct {
45649 + void **table;
45650 + void **nametable;
45651 + void *first;
45652 + __u32 table_size;
45653 + __u32 used_size;
45654 + int type;
45655 +};
45656 +
45657 +/* Userspace Grsecurity ACL data structures */
45658 +
45659 +struct acl_subject_label {
45660 + char *filename;
45661 + ino_t inode;
45662 + dev_t device;
45663 + __u32 mode;
45664 + kernel_cap_t cap_mask;
45665 + kernel_cap_t cap_lower;
45666 + kernel_cap_t cap_invert_audit;
45667 +
45668 + struct rlimit res[GR_NLIMITS];
45669 + __u32 resmask;
45670 +
45671 + __u8 user_trans_type;
45672 + __u8 group_trans_type;
45673 + uid_t *user_transitions;
45674 + gid_t *group_transitions;
45675 + __u16 user_trans_num;
45676 + __u16 group_trans_num;
45677 +
45678 + __u32 sock_families[2];
45679 + __u32 ip_proto[8];
45680 + __u32 ip_type;
45681 + struct acl_ip_label **ips;
45682 + __u32 ip_num;
45683 + __u32 inaddr_any_override;
45684 +
45685 + __u32 crashes;
45686 + unsigned long expires;
45687 +
45688 + struct acl_subject_label *parent_subject;
45689 + struct gr_hash_struct *hash;
45690 + struct acl_subject_label *prev;
45691 + struct acl_subject_label *next;
45692 +
45693 + struct acl_object_label **obj_hash;
45694 + __u32 obj_hash_size;
45695 + __u16 pax_flags;
45696 +};
45697 +
45698 +struct role_allowed_ip {
45699 + __u32 addr;
45700 + __u32 netmask;
45701 +
45702 + struct role_allowed_ip *prev;
45703 + struct role_allowed_ip *next;
45704 +};
45705 +
45706 +struct role_transition {
45707 + char *rolename;
45708 +
45709 + struct role_transition *prev;
45710 + struct role_transition *next;
45711 +};
45712 +
45713 +struct acl_role_label {
45714 + char *rolename;
45715 + uid_t uidgid;
45716 + __u16 roletype;
45717 +
45718 + __u16 auth_attempts;
45719 + unsigned long expires;
45720 +
45721 + struct acl_subject_label *root_label;
45722 + struct gr_hash_struct *hash;
45723 +
45724 + struct acl_role_label *prev;
45725 + struct acl_role_label *next;
45726 +
45727 + struct role_transition *transitions;
45728 + struct role_allowed_ip *allowed_ips;
45729 + uid_t *domain_children;
45730 + __u16 domain_child_num;
45731 +
45732 + struct acl_subject_label **subj_hash;
45733 + __u32 subj_hash_size;
45734 +};
45735 +
45736 +struct user_acl_role_db {
45737 + struct acl_role_label **r_table;
45738 + __u32 num_pointers; /* Number of allocations to track */
45739 + __u32 num_roles; /* Number of roles */
45740 + __u32 num_domain_children; /* Number of domain children */
45741 + __u32 num_subjects; /* Number of subjects */
45742 + __u32 num_objects; /* Number of objects */
45743 +};
45744 +
45745 +struct acl_object_label {
45746 + char *filename;
45747 + ino_t inode;
45748 + dev_t device;
45749 + __u32 mode;
45750 +
45751 + struct acl_subject_label *nested;
45752 + struct acl_object_label *globbed;
45753 +
45754 + /* next two structures not used */
45755 +
45756 + struct acl_object_label *prev;
45757 + struct acl_object_label *next;
45758 +};
45759 +
45760 +struct acl_ip_label {
45761 + char *iface;
45762 + __u32 addr;
45763 + __u32 netmask;
45764 + __u16 low, high;
45765 + __u8 mode;
45766 + __u32 type;
45767 + __u32 proto[8];
45768 +
45769 + /* next two structures not used */
45770 +
45771 + struct acl_ip_label *prev;
45772 + struct acl_ip_label *next;
45773 +};
45774 +
45775 +struct gr_arg {
45776 + struct user_acl_role_db role_db;
45777 + unsigned char pw[GR_PW_LEN];
45778 + unsigned char salt[GR_SALT_LEN];
45779 + unsigned char sum[GR_SHA_LEN];
45780 + unsigned char sp_role[GR_SPROLE_LEN];
45781 + struct sprole_pw *sprole_pws;
45782 + dev_t segv_device;
45783 + ino_t segv_inode;
45784 + uid_t segv_uid;
45785 + __u16 num_sprole_pws;
45786 + __u16 mode;
45787 +};
45788 +
45789 +struct gr_arg_wrapper {
45790 + struct gr_arg *arg;
45791 + __u32 version;
45792 + __u32 size;
45793 +};
45794 +
45795 +struct subject_map {
45796 + struct acl_subject_label *user;
45797 + struct acl_subject_label *kernel;
45798 + struct subject_map *prev;
45799 + struct subject_map *next;
45800 +};
45801 +
45802 +struct acl_subj_map_db {
45803 + struct subject_map **s_hash;
45804 + __u32 s_size;
45805 +};
45806 +
45807 +/* End Data Structures Section */
45808 +
45809 +/* Hash functions generated by empirical testing by Brad Spengler
45810 + Makes good use of the low bits of the inode. Generally 0-1 times
45811 + in loop for successful match. 0-3 for unsuccessful match.
45812 + Shift/add algorithm with modulus of table size and an XOR*/
45813 +
45814 +static __inline__ unsigned int
45815 +rhash(const uid_t uid, const __u16 type, const unsigned int sz)
45816 +{
45817 + return ((((uid + type) << (16 + type)) ^ uid) % sz);
45818 +}
45819 +
45820 + static __inline__ unsigned int
45821 +shash(const struct acl_subject_label *userp, const unsigned int sz)
45822 +{
45823 + return ((const unsigned long)userp % sz);
45824 +}
45825 +
45826 +static __inline__ unsigned int
45827 +fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
45828 +{
45829 + return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
45830 +}
45831 +
45832 +static __inline__ unsigned int
45833 +nhash(const char *name, const __u16 len, const unsigned int sz)
45834 +{
45835 + return full_name_hash((const unsigned char *)name, len) % sz;
45836 +}
45837 +
45838 +#define FOR_EACH_ROLE_START(role) \
45839 + role = role_list; \
45840 + while (role) {
45841 +
45842 +#define FOR_EACH_ROLE_END(role) \
45843 + role = role->prev; \
45844 + }
45845 +
45846 +#define FOR_EACH_SUBJECT_START(role,subj,iter) \
45847 + subj = NULL; \
45848 + iter = 0; \
45849 + while (iter < role->subj_hash_size) { \
45850 + if (subj == NULL) \
45851 + subj = role->subj_hash[iter]; \
45852 + if (subj == NULL) { \
45853 + iter++; \
45854 + continue; \
45855 + }
45856 +
45857 +#define FOR_EACH_SUBJECT_END(subj,iter) \
45858 + subj = subj->next; \
45859 + if (subj == NULL) \
45860 + iter++; \
45861 + }
45862 +
45863 +
45864 +#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
45865 + subj = role->hash->first; \
45866 + while (subj != NULL) {
45867 +
45868 +#define FOR_EACH_NESTED_SUBJECT_END(subj) \
45869 + subj = subj->next; \
45870 + }
45871 +
45872 +#endif
45873 +
45874 diff -urNp linux-2.6.37/include/linux/gralloc.h linux-2.6.37/include/linux/gralloc.h
45875 --- linux-2.6.37/include/linux/gralloc.h 1969-12-31 19:00:00.000000000 -0500
45876 +++ linux-2.6.37/include/linux/gralloc.h 2011-01-17 02:41:02.000000000 -0500
45877 @@ -0,0 +1,9 @@
45878 +#ifndef __GRALLOC_H
45879 +#define __GRALLOC_H
45880 +
45881 +void acl_free_all(void);
45882 +int acl_alloc_stack_init(unsigned long size);
45883 +void *acl_alloc(unsigned long len);
45884 +void *acl_alloc_num(unsigned long num, unsigned long len);
45885 +
45886 +#endif
45887 diff -urNp linux-2.6.37/include/linux/grdefs.h linux-2.6.37/include/linux/grdefs.h
45888 --- linux-2.6.37/include/linux/grdefs.h 1969-12-31 19:00:00.000000000 -0500
45889 +++ linux-2.6.37/include/linux/grdefs.h 2011-01-17 02:41:02.000000000 -0500
45890 @@ -0,0 +1,137 @@
45891 +#ifndef GRDEFS_H
45892 +#define GRDEFS_H
45893 +
45894 +/* Begin grsecurity status declarations */
45895 +
45896 +enum {
45897 + GR_READY = 0x01,
45898 + GR_STATUS_INIT = 0x00 // disabled state
45899 +};
45900 +
45901 +/* Begin ACL declarations */
45902 +
45903 +/* Role flags */
45904 +
45905 +enum {
45906 + GR_ROLE_USER = 0x0001,
45907 + GR_ROLE_GROUP = 0x0002,
45908 + GR_ROLE_DEFAULT = 0x0004,
45909 + GR_ROLE_SPECIAL = 0x0008,
45910 + GR_ROLE_AUTH = 0x0010,
45911 + GR_ROLE_NOPW = 0x0020,
45912 + GR_ROLE_GOD = 0x0040,
45913 + GR_ROLE_LEARN = 0x0080,
45914 + GR_ROLE_TPE = 0x0100,
45915 + GR_ROLE_DOMAIN = 0x0200,
45916 + GR_ROLE_PAM = 0x0400
45917 +};
45918 +
45919 +/* ACL Subject and Object mode flags */
45920 +enum {
45921 + GR_DELETED = 0x80000000
45922 +};
45923 +
45924 +/* ACL Object-only mode flags */
45925 +enum {
45926 + GR_READ = 0x00000001,
45927 + GR_APPEND = 0x00000002,
45928 + GR_WRITE = 0x00000004,
45929 + GR_EXEC = 0x00000008,
45930 + GR_FIND = 0x00000010,
45931 + GR_INHERIT = 0x00000020,
45932 + GR_SETID = 0x00000040,
45933 + GR_CREATE = 0x00000080,
45934 + GR_DELETE = 0x00000100,
45935 + GR_LINK = 0x00000200,
45936 + GR_AUDIT_READ = 0x00000400,
45937 + GR_AUDIT_APPEND = 0x00000800,
45938 + GR_AUDIT_WRITE = 0x00001000,
45939 + GR_AUDIT_EXEC = 0x00002000,
45940 + GR_AUDIT_FIND = 0x00004000,
45941 + GR_AUDIT_INHERIT= 0x00008000,
45942 + GR_AUDIT_SETID = 0x00010000,
45943 + GR_AUDIT_CREATE = 0x00020000,
45944 + GR_AUDIT_DELETE = 0x00040000,
45945 + GR_AUDIT_LINK = 0x00080000,
45946 + GR_PTRACERD = 0x00100000,
45947 + GR_NOPTRACE = 0x00200000,
45948 + GR_SUPPRESS = 0x00400000,
45949 + GR_NOLEARN = 0x00800000
45950 +};
45951 +
45952 +#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
45953 + GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
45954 + GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
45955 +
45956 +/* ACL subject-only mode flags */
45957 +enum {
45958 + GR_KILL = 0x00000001,
45959 + GR_VIEW = 0x00000002,
45960 + GR_PROTECTED = 0x00000004,
45961 + GR_LEARN = 0x00000008,
45962 + GR_OVERRIDE = 0x00000010,
45963 + /* just a placeholder, this mode is only used in userspace */
45964 + GR_DUMMY = 0x00000020,
45965 + GR_PROTSHM = 0x00000040,
45966 + GR_KILLPROC = 0x00000080,
45967 + GR_KILLIPPROC = 0x00000100,
45968 + /* just a placeholder, this mode is only used in userspace */
45969 + GR_NOTROJAN = 0x00000200,
45970 + GR_PROTPROCFD = 0x00000400,
45971 + GR_PROCACCT = 0x00000800,
45972 + GR_RELAXPTRACE = 0x00001000,
45973 + GR_NESTED = 0x00002000,
45974 + GR_INHERITLEARN = 0x00004000,
45975 + GR_PROCFIND = 0x00008000,
45976 + GR_POVERRIDE = 0x00010000,
45977 + GR_KERNELAUTH = 0x00020000,
45978 + GR_ATSECURE = 0x00040000
45979 +};
45980 +
45981 +enum {
45982 + GR_PAX_ENABLE_SEGMEXEC = 0x0001,
45983 + GR_PAX_ENABLE_PAGEEXEC = 0x0002,
45984 + GR_PAX_ENABLE_MPROTECT = 0x0004,
45985 + GR_PAX_ENABLE_RANDMMAP = 0x0008,
45986 + GR_PAX_ENABLE_EMUTRAMP = 0x0010,
45987 + GR_PAX_DISABLE_SEGMEXEC = 0x0100,
45988 + GR_PAX_DISABLE_PAGEEXEC = 0x0200,
45989 + GR_PAX_DISABLE_MPROTECT = 0x0400,
45990 + GR_PAX_DISABLE_RANDMMAP = 0x0800,
45991 + GR_PAX_DISABLE_EMUTRAMP = 0x1000,
45992 +};
45993 +
45994 +enum {
45995 + GR_ID_USER = 0x01,
45996 + GR_ID_GROUP = 0x02,
45997 +};
45998 +
45999 +enum {
46000 + GR_ID_ALLOW = 0x01,
46001 + GR_ID_DENY = 0x02,
46002 +};
46003 +
46004 +#define GR_CRASH_RES 31
46005 +#define GR_UIDTABLE_MAX 500
46006 +
46007 +/* begin resource learning section */
46008 +enum {
46009 + GR_RLIM_CPU_BUMP = 60,
46010 + GR_RLIM_FSIZE_BUMP = 50000,
46011 + GR_RLIM_DATA_BUMP = 10000,
46012 + GR_RLIM_STACK_BUMP = 1000,
46013 + GR_RLIM_CORE_BUMP = 10000,
46014 + GR_RLIM_RSS_BUMP = 500000,
46015 + GR_RLIM_NPROC_BUMP = 1,
46016 + GR_RLIM_NOFILE_BUMP = 5,
46017 + GR_RLIM_MEMLOCK_BUMP = 50000,
46018 + GR_RLIM_AS_BUMP = 500000,
46019 + GR_RLIM_LOCKS_BUMP = 2,
46020 + GR_RLIM_SIGPENDING_BUMP = 5,
46021 + GR_RLIM_MSGQUEUE_BUMP = 10000,
46022 + GR_RLIM_NICE_BUMP = 1,
46023 + GR_RLIM_RTPRIO_BUMP = 1,
46024 + GR_RLIM_RTTIME_BUMP = 1000000
46025 +};
46026 +
46027 +#endif
46028 diff -urNp linux-2.6.37/include/linux/grinternal.h linux-2.6.37/include/linux/grinternal.h
46029 --- linux-2.6.37/include/linux/grinternal.h 1969-12-31 19:00:00.000000000 -0500
46030 +++ linux-2.6.37/include/linux/grinternal.h 2011-01-17 02:41:02.000000000 -0500
46031 @@ -0,0 +1,216 @@
46032 +#ifndef __GRINTERNAL_H
46033 +#define __GRINTERNAL_H
46034 +
46035 +#ifdef CONFIG_GRKERNSEC
46036 +
46037 +#include <linux/fs.h>
46038 +#include <linux/mnt_namespace.h>
46039 +#include <linux/nsproxy.h>
46040 +#include <linux/gracl.h>
46041 +#include <linux/grdefs.h>
46042 +#include <linux/grmsg.h>
46043 +
46044 +void gr_add_learn_entry(const char *fmt, ...)
46045 + __attribute__ ((format (printf, 1, 2)));
46046 +__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
46047 + const struct vfsmount *mnt);
46048 +__u32 gr_check_create(const struct dentry *new_dentry,
46049 + const struct dentry *parent,
46050 + const struct vfsmount *mnt, const __u32 mode);
46051 +int gr_check_protected_task(const struct task_struct *task);
46052 +__u32 to_gr_audit(const __u32 reqmode);
46053 +int gr_set_acls(const int type);
46054 +
46055 +int gr_acl_is_enabled(void);
46056 +char gr_roletype_to_char(void);
46057 +
46058 +void gr_handle_alertkill(struct task_struct *task);
46059 +char *gr_to_filename(const struct dentry *dentry,
46060 + const struct vfsmount *mnt);
46061 +char *gr_to_filename1(const struct dentry *dentry,
46062 + const struct vfsmount *mnt);
46063 +char *gr_to_filename2(const struct dentry *dentry,
46064 + const struct vfsmount *mnt);
46065 +char *gr_to_filename3(const struct dentry *dentry,
46066 + const struct vfsmount *mnt);
46067 +
46068 +extern int grsec_enable_harden_ptrace;
46069 +extern int grsec_enable_link;
46070 +extern int grsec_enable_fifo;
46071 +extern int grsec_enable_execve;
46072 +extern int grsec_enable_shm;
46073 +extern int grsec_enable_execlog;
46074 +extern int grsec_enable_signal;
46075 +extern int grsec_enable_audit_ptrace;
46076 +extern int grsec_enable_forkfail;
46077 +extern int grsec_enable_time;
46078 +extern int grsec_enable_rofs;
46079 +extern int grsec_enable_chroot_shmat;
46080 +extern int grsec_enable_chroot_findtask;
46081 +extern int grsec_enable_chroot_mount;
46082 +extern int grsec_enable_chroot_double;
46083 +extern int grsec_enable_chroot_pivot;
46084 +extern int grsec_enable_chroot_chdir;
46085 +extern int grsec_enable_chroot_chmod;
46086 +extern int grsec_enable_chroot_mknod;
46087 +extern int grsec_enable_chroot_fchdir;
46088 +extern int grsec_enable_chroot_nice;
46089 +extern int grsec_enable_chroot_execlog;
46090 +extern int grsec_enable_chroot_caps;
46091 +extern int grsec_enable_chroot_sysctl;
46092 +extern int grsec_enable_chroot_unix;
46093 +extern int grsec_enable_tpe;
46094 +extern int grsec_tpe_gid;
46095 +extern int grsec_enable_tpe_all;
46096 +extern int grsec_enable_tpe_invert;
46097 +extern int grsec_enable_socket_all;
46098 +extern int grsec_socket_all_gid;
46099 +extern int grsec_enable_socket_client;
46100 +extern int grsec_socket_client_gid;
46101 +extern int grsec_enable_socket_server;
46102 +extern int grsec_socket_server_gid;
46103 +extern int grsec_audit_gid;
46104 +extern int grsec_enable_group;
46105 +extern int grsec_enable_audit_textrel;
46106 +extern int grsec_enable_log_rwxmaps;
46107 +extern int grsec_enable_mount;
46108 +extern int grsec_enable_chdir;
46109 +extern int grsec_resource_logging;
46110 +extern int grsec_enable_blackhole;
46111 +extern int grsec_lastack_retries;
46112 +extern int grsec_lock;
46113 +
46114 +extern spinlock_t grsec_alert_lock;
46115 +extern unsigned long grsec_alert_wtime;
46116 +extern unsigned long grsec_alert_fyet;
46117 +
46118 +extern spinlock_t grsec_audit_lock;
46119 +
46120 +extern rwlock_t grsec_exec_file_lock;
46121 +
46122 +#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
46123 + gr_to_filename2((tsk)->exec_file->f_path.dentry, \
46124 + (tsk)->exec_file->f_vfsmnt) : "/")
46125 +
46126 +#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
46127 + gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
46128 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
46129 +
46130 +#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
46131 + gr_to_filename((tsk)->exec_file->f_path.dentry, \
46132 + (tsk)->exec_file->f_vfsmnt) : "/")
46133 +
46134 +#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
46135 + gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
46136 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
46137 +
46138 +#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
46139 +
46140 +#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
46141 +
46142 +#define DEFAULTSECARGS(task, cred, pcred) gr_task_fullpath(task), (task)->comm, \
46143 + (task)->pid, (cred)->uid, \
46144 + (cred)->euid, (cred)->gid, (cred)->egid, \
46145 + gr_parent_task_fullpath(task), \
46146 + (task)->real_parent->comm, (task)->real_parent->pid, \
46147 + (pcred)->uid, (pcred)->euid, \
46148 + (pcred)->gid, (pcred)->egid
46149 +
46150 +#define GR_CHROOT_CAPS {{ \
46151 + CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
46152 + CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
46153 + CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
46154 + CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
46155 + CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
46156 + CAP_TO_MASK(CAP_IPC_OWNER) , 0 }}
46157 +
46158 +#define security_learn(normal_msg,args...) \
46159 +({ \
46160 + read_lock(&grsec_exec_file_lock); \
46161 + gr_add_learn_entry(normal_msg "\n", ## args); \
46162 + read_unlock(&grsec_exec_file_lock); \
46163 +})
46164 +
46165 +enum {
46166 + GR_DO_AUDIT,
46167 + GR_DONT_AUDIT,
46168 + GR_DONT_AUDIT_GOOD
46169 +};
46170 +
46171 +enum {
46172 + GR_TTYSNIFF,
46173 + GR_RBAC,
46174 + GR_RBAC_STR,
46175 + GR_STR_RBAC,
46176 + GR_RBAC_MODE2,
46177 + GR_RBAC_MODE3,
46178 + GR_FILENAME,
46179 + GR_SYSCTL_HIDDEN,
46180 + GR_NOARGS,
46181 + GR_ONE_INT,
46182 + GR_ONE_INT_TWO_STR,
46183 + GR_ONE_STR,
46184 + GR_STR_INT,
46185 + GR_TWO_STR_INT,
46186 + GR_TWO_INT,
46187 + GR_THREE_INT,
46188 + GR_FIVE_INT_TWO_STR,
46189 + GR_TWO_STR,
46190 + GR_THREE_STR,
46191 + GR_FOUR_STR,
46192 + GR_STR_FILENAME,
46193 + GR_FILENAME_STR,
46194 + GR_FILENAME_TWO_INT,
46195 + GR_FILENAME_TWO_INT_STR,
46196 + GR_TEXTREL,
46197 + GR_PTRACE,
46198 + GR_RESOURCE,
46199 + GR_CAP,
46200 + GR_SIG,
46201 + GR_SIG2,
46202 + GR_CRASH1,
46203 + GR_CRASH2,
46204 + GR_PSACCT,
46205 + GR_RWXMAP
46206 +};
46207 +
46208 +#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
46209 +#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
46210 +#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
46211 +#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
46212 +#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
46213 +#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
46214 +#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)
46215 +#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
46216 +#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
46217 +#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
46218 +#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
46219 +#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
46220 +#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
46221 +#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
46222 +#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
46223 +#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)
46224 +#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
46225 +#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
46226 +#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
46227 +#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
46228 +#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
46229 +#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
46230 +#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
46231 +#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)
46232 +#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
46233 +#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
46234 +#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
46235 +#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
46236 +#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
46237 +#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
46238 +#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
46239 +#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
46240 +#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)
46241 +#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
46242 +
46243 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
46244 +
46245 +#endif
46246 +
46247 +#endif
46248 diff -urNp linux-2.6.37/include/linux/grmsg.h linux-2.6.37/include/linux/grmsg.h
46249 --- linux-2.6.37/include/linux/grmsg.h 1969-12-31 19:00:00.000000000 -0500
46250 +++ linux-2.6.37/include/linux/grmsg.h 2011-01-17 02:41:02.000000000 -0500
46251 @@ -0,0 +1,111 @@
46252 +#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"
46253 +#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"
46254 +#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
46255 +#define GR_STOPMOD_MSG "denied modification of module state by "
46256 +#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
46257 +#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
46258 +#define GR_IOPERM_MSG "denied use of ioperm() by "
46259 +#define GR_IOPL_MSG "denied use of iopl() by "
46260 +#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
46261 +#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
46262 +#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
46263 +#define GR_KMEM_MSG "denied write of /dev/kmem by "
46264 +#define GR_PORT_OPEN_MSG "denied open of /dev/port by "
46265 +#define GR_MEM_WRITE_MSG "denied write of /dev/mem by "
46266 +#define GR_MEM_MMAP_MSG "denied mmap write of /dev/[k]mem by "
46267 +#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
46268 +#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"
46269 +#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"
46270 +#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
46271 +#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
46272 +#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
46273 +#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
46274 +#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
46275 +#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
46276 +#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
46277 +#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
46278 +#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
46279 +#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
46280 +#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
46281 +#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
46282 +#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
46283 +#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
46284 +#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
46285 +#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
46286 +#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
46287 +#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
46288 +#define GR_NPROC_MSG "denied overstep of process limit by "
46289 +#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
46290 +#define GR_EXEC_TPE_MSG "denied untrusted exec of %.950s by "
46291 +#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
46292 +#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
46293 +#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
46294 +#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
46295 +#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
46296 +#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
46297 +#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
46298 +#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
46299 +#define GR_FCHMOD_ACL_MSG "%s fchmod of %.950s by "
46300 +#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
46301 +#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
46302 +#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
46303 +#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
46304 +#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
46305 +#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
46306 +#define GR_INITF_ACL_MSG "init_variables() failed %s by "
46307 +#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"
46308 +#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbaged by "
46309 +#define GR_SHUTS_ACL_MSG "shutdown auth success for "
46310 +#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
46311 +#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
46312 +#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
46313 +#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
46314 +#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
46315 +#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
46316 +#define GR_ENABLEF_ACL_MSG "unable to load %s for "
46317 +#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
46318 +#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
46319 +#define GR_RELOADF_ACL_MSG "failed reload of %s for "
46320 +#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
46321 +#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
46322 +#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
46323 +#define GR_SPROLEF_ACL_MSG "special role %s failure for "
46324 +#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
46325 +#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
46326 +#define GR_INVMODE_ACL_MSG "invalid mode %d by "
46327 +#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
46328 +#define GR_FAILFORK_MSG "failed fork with errno %s by "
46329 +#define GR_NICE_CHROOT_MSG "denied priority change by "
46330 +#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
46331 +#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
46332 +#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
46333 +#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
46334 +#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
46335 +#define GR_TIME_MSG "time set by "
46336 +#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
46337 +#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
46338 +#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
46339 +#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
46340 +#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
46341 +#define GR_BIND_MSG "denied bind() by "
46342 +#define GR_CONNECT_MSG "denied connect() by "
46343 +#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
46344 +#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
46345 +#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"
46346 +#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
46347 +#define GR_CAP_ACL_MSG "use of %s denied for "
46348 +#define GR_CAP_ACL_MSG2 "use of %s permitted for "
46349 +#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
46350 +#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
46351 +#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
46352 +#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
46353 +#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
46354 +#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
46355 +#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
46356 +#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
46357 +#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
46358 +#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
46359 +#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
46360 +#define GR_NONROOT_MODLOAD_MSG "denied kernel module auto-load of %.64s by "
46361 +#define GR_VM86_MSG "denied use of vm86 by "
46362 +#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
46363 diff -urNp linux-2.6.37/include/linux/grsecurity.h linux-2.6.37/include/linux/grsecurity.h
46364 --- linux-2.6.37/include/linux/grsecurity.h 1969-12-31 19:00:00.000000000 -0500
46365 +++ linux-2.6.37/include/linux/grsecurity.h 2011-01-17 02:41:02.000000000 -0500
46366 @@ -0,0 +1,214 @@
46367 +#ifndef GR_SECURITY_H
46368 +#define GR_SECURITY_H
46369 +#include <linux/fs.h>
46370 +#include <linux/fs_struct.h>
46371 +#include <linux/binfmts.h>
46372 +#include <linux/gracl.h>
46373 +#include <linux/compat.h>
46374 +
46375 +/* notify of brain-dead configs */
46376 +#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
46377 +#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
46378 +#endif
46379 +#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_EI_PAX) && !defined(CONFIG_PAX_PT_PAX_FLAGS)
46380 +#error "CONFIG_PAX_NOEXEC enabled, but neither CONFIG_PAX_EI_PAX nor CONFIG_PAX_PT_PAX_FLAGS are enabled."
46381 +#endif
46382 +#if defined(CONFIG_PAX_ASLR) && (defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)) && !defined(CONFIG_PAX_EI_PAX) && !defined(CONFIG_PAX_PT_PAX_FLAGS)
46383 +#error "CONFIG_PAX_ASLR enabled, but neither CONFIG_PAX_EI_PAX nor CONFIG_PAX_PT_PAX_FLAGS are enabled."
46384 +#endif
46385 +#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
46386 +#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
46387 +#endif
46388 +#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
46389 +#error "CONFIG_PAX enabled, but no PaX options are enabled."
46390 +#endif
46391 +
46392 +void gr_handle_brute_attach(struct task_struct *p);
46393 +void gr_handle_brute_check(void);
46394 +
46395 +char gr_roletype_to_char(void);
46396 +
46397 +int gr_acl_enable_at_secure(void);
46398 +
46399 +int gr_check_user_change(int real, int effective, int fs);
46400 +int gr_check_group_change(int real, int effective, int fs);
46401 +
46402 +void gr_del_task_from_ip_table(struct task_struct *p);
46403 +
46404 +int gr_pid_is_chrooted(struct task_struct *p);
46405 +int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
46406 +int gr_handle_chroot_nice(void);
46407 +int gr_handle_chroot_sysctl(const int op);
46408 +int gr_handle_chroot_setpriority(struct task_struct *p,
46409 + const int niceval);
46410 +int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
46411 +int gr_handle_chroot_chroot(const struct dentry *dentry,
46412 + const struct vfsmount *mnt);
46413 +int gr_handle_chroot_caps(struct path *path);
46414 +void gr_handle_chroot_chdir(struct path *path);
46415 +int gr_handle_chroot_chmod(const struct dentry *dentry,
46416 + const struct vfsmount *mnt, const int mode);
46417 +int gr_handle_chroot_mknod(const struct dentry *dentry,
46418 + const struct vfsmount *mnt, const int mode);
46419 +int gr_handle_chroot_mount(const struct dentry *dentry,
46420 + const struct vfsmount *mnt,
46421 + const char *dev_name);
46422 +int gr_handle_chroot_pivot(void);
46423 +int gr_handle_chroot_unix(struct pid *pid);
46424 +
46425 +int gr_handle_rawio(const struct inode *inode);
46426 +int gr_handle_nproc(void);
46427 +
46428 +void gr_handle_ioperm(void);
46429 +void gr_handle_iopl(void);
46430 +
46431 +int gr_tpe_allow(const struct file *file);
46432 +
46433 +void gr_set_chroot_entries(struct task_struct *task, struct path *path);
46434 +void gr_clear_chroot_entries(struct task_struct *task);
46435 +
46436 +void gr_log_forkfail(const int retval);
46437 +void gr_log_timechange(void);
46438 +void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
46439 +void gr_log_chdir(const struct dentry *dentry,
46440 + const struct vfsmount *mnt);
46441 +void gr_log_chroot_exec(const struct dentry *dentry,
46442 + const struct vfsmount *mnt);
46443 +void gr_handle_exec_args(struct linux_binprm *bprm, const char __user *const __user *argv);
46444 +#ifdef CONFIG_COMPAT
46445 +void gr_handle_exec_args_compat(struct linux_binprm *bprm, compat_uptr_t __user *argv);
46446 +#endif
46447 +void gr_log_remount(const char *devname, const int retval);
46448 +void gr_log_unmount(const char *devname, const int retval);
46449 +void gr_log_mount(const char *from, const char *to, const int retval);
46450 +void gr_log_textrel(struct vm_area_struct *vma);
46451 +void gr_log_rwxmmap(struct file *file);
46452 +void gr_log_rwxmprotect(struct file *file);
46453 +
46454 +int gr_handle_follow_link(const struct inode *parent,
46455 + const struct inode *inode,
46456 + const struct dentry *dentry,
46457 + const struct vfsmount *mnt);
46458 +int gr_handle_fifo(const struct dentry *dentry,
46459 + const struct vfsmount *mnt,
46460 + const struct dentry *dir, const int flag,
46461 + const int acc_mode);
46462 +int gr_handle_hardlink(const struct dentry *dentry,
46463 + const struct vfsmount *mnt,
46464 + struct inode *inode,
46465 + const int mode, const char *to);
46466 +
46467 +int gr_is_capable(const int cap);
46468 +int gr_is_capable_nolog(const int cap);
46469 +void gr_learn_resource(const struct task_struct *task, const int limit,
46470 + const unsigned long wanted, const int gt);
46471 +void gr_copy_label(struct task_struct *tsk);
46472 +void gr_handle_crash(struct task_struct *task, const int sig);
46473 +int gr_handle_signal(const struct task_struct *p, const int sig);
46474 +int gr_check_crash_uid(const uid_t uid);
46475 +int gr_check_protected_task(const struct task_struct *task);
46476 +int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
46477 +int gr_acl_handle_mmap(const struct file *file,
46478 + const unsigned long prot);
46479 +int gr_acl_handle_mprotect(const struct file *file,
46480 + const unsigned long prot);
46481 +int gr_check_hidden_task(const struct task_struct *tsk);
46482 +__u32 gr_acl_handle_truncate(const struct dentry *dentry,
46483 + const struct vfsmount *mnt);
46484 +__u32 gr_acl_handle_utime(const struct dentry *dentry,
46485 + const struct vfsmount *mnt);
46486 +__u32 gr_acl_handle_access(const struct dentry *dentry,
46487 + const struct vfsmount *mnt, const int fmode);
46488 +__u32 gr_acl_handle_fchmod(const struct dentry *dentry,
46489 + const struct vfsmount *mnt, mode_t mode);
46490 +__u32 gr_acl_handle_chmod(const struct dentry *dentry,
46491 + const struct vfsmount *mnt, mode_t mode);
46492 +__u32 gr_acl_handle_chown(const struct dentry *dentry,
46493 + const struct vfsmount *mnt);
46494 +__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
46495 + const struct vfsmount *mnt);
46496 +int gr_handle_ptrace(struct task_struct *task, const long request);
46497 +int gr_handle_proc_ptrace(struct task_struct *task);
46498 +__u32 gr_acl_handle_execve(const struct dentry *dentry,
46499 + const struct vfsmount *mnt);
46500 +int gr_check_crash_exec(const struct file *filp);
46501 +int gr_acl_is_enabled(void);
46502 +void gr_set_kernel_label(struct task_struct *task);
46503 +void gr_set_role_label(struct task_struct *task, const uid_t uid,
46504 + const gid_t gid);
46505 +int gr_set_proc_label(const struct dentry *dentry,
46506 + const struct vfsmount *mnt,
46507 + const int unsafe_share);
46508 +__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
46509 + const struct vfsmount *mnt);
46510 +__u32 gr_acl_handle_open(const struct dentry *dentry,
46511 + const struct vfsmount *mnt, const int fmode);
46512 +__u32 gr_acl_handle_creat(const struct dentry *dentry,
46513 + const struct dentry *p_dentry,
46514 + const struct vfsmount *p_mnt, const int fmode,
46515 + const int imode);
46516 +void gr_handle_create(const struct dentry *dentry,
46517 + const struct vfsmount *mnt);
46518 +__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
46519 + const struct dentry *parent_dentry,
46520 + const struct vfsmount *parent_mnt,
46521 + const int mode);
46522 +__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
46523 + const struct dentry *parent_dentry,
46524 + const struct vfsmount *parent_mnt);
46525 +__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
46526 + const struct vfsmount *mnt);
46527 +void gr_handle_delete(const ino_t ino, const dev_t dev);
46528 +__u32 gr_acl_handle_unlink(const struct dentry *dentry,
46529 + const struct vfsmount *mnt);
46530 +__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
46531 + const struct dentry *parent_dentry,
46532 + const struct vfsmount *parent_mnt,
46533 + const char *from);
46534 +__u32 gr_acl_handle_link(const struct dentry *new_dentry,
46535 + const struct dentry *parent_dentry,
46536 + const struct vfsmount *parent_mnt,
46537 + const struct dentry *old_dentry,
46538 + const struct vfsmount *old_mnt, const char *to);
46539 +int gr_acl_handle_rename(struct dentry *new_dentry,
46540 + struct dentry *parent_dentry,
46541 + const struct vfsmount *parent_mnt,
46542 + struct dentry *old_dentry,
46543 + struct inode *old_parent_inode,
46544 + struct vfsmount *old_mnt, const char *newname);
46545 +void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
46546 + struct dentry *old_dentry,
46547 + struct dentry *new_dentry,
46548 + struct vfsmount *mnt, const __u8 replace);
46549 +__u32 gr_check_link(const struct dentry *new_dentry,
46550 + const struct dentry *parent_dentry,
46551 + const struct vfsmount *parent_mnt,
46552 + const struct dentry *old_dentry,
46553 + const struct vfsmount *old_mnt);
46554 +int gr_acl_handle_filldir(const struct file *file, const char *name,
46555 + const unsigned int namelen, const ino_t ino);
46556 +
46557 +__u32 gr_acl_handle_unix(const struct dentry *dentry,
46558 + const struct vfsmount *mnt);
46559 +void gr_acl_handle_exit(void);
46560 +void gr_acl_handle_psacct(struct task_struct *task, const long code);
46561 +int gr_acl_handle_procpidmem(const struct task_struct *task);
46562 +int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
46563 +int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
46564 +void gr_audit_ptrace(struct task_struct *task);
46565 +
46566 +#ifdef CONFIG_GRKERNSEC
46567 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
46568 +void gr_log_nonroot_mod_load(const char *modname);
46569 +void gr_handle_vm86(void);
46570 +void gr_handle_mem_write(void);
46571 +void gr_handle_kmem_write(void);
46572 +void gr_handle_open_port(void);
46573 +int gr_handle_mem_mmap(const unsigned long offset,
46574 + struct vm_area_struct *vma);
46575 +
46576 +extern int grsec_enable_dmesg;
46577 +extern int grsec_disable_privio;
46578 +#endif
46579 +
46580 +#endif
46581 diff -urNp linux-2.6.37/include/linux/grsock.h linux-2.6.37/include/linux/grsock.h
46582 --- linux-2.6.37/include/linux/grsock.h 1969-12-31 19:00:00.000000000 -0500
46583 +++ linux-2.6.37/include/linux/grsock.h 2011-01-17 02:41:02.000000000 -0500
46584 @@ -0,0 +1,19 @@
46585 +#ifndef __GRSOCK_H
46586 +#define __GRSOCK_H
46587 +
46588 +extern void gr_attach_curr_ip(const struct sock *sk);
46589 +extern int gr_handle_sock_all(const int family, const int type,
46590 + const int protocol);
46591 +extern int gr_handle_sock_server(const struct sockaddr *sck);
46592 +extern int gr_handle_sock_server_other(const struct sock *sck);
46593 +extern int gr_handle_sock_client(const struct sockaddr *sck);
46594 +extern int gr_search_connect(struct socket * sock,
46595 + struct sockaddr_in * addr);
46596 +extern int gr_search_bind(struct socket * sock,
46597 + struct sockaddr_in * addr);
46598 +extern int gr_search_listen(struct socket * sock);
46599 +extern int gr_search_accept(struct socket * sock);
46600 +extern int gr_search_socket(const int domain, const int type,
46601 + const int protocol);
46602 +
46603 +#endif
46604 diff -urNp linux-2.6.37/include/linux/highmem.h linux-2.6.37/include/linux/highmem.h
46605 --- linux-2.6.37/include/linux/highmem.h 2011-01-04 19:50:19.000000000 -0500
46606 +++ linux-2.6.37/include/linux/highmem.h 2011-01-17 02:41:02.000000000 -0500
46607 @@ -182,6 +182,18 @@ static inline void clear_highpage(struct
46608 kunmap_atomic(kaddr, KM_USER0);
46609 }
46610
46611 +static inline void sanitize_highpage(struct page *page)
46612 +{
46613 + void *kaddr;
46614 + unsigned long flags;
46615 +
46616 + local_irq_save(flags);
46617 + kaddr = kmap_atomic(page, KM_CLEARPAGE);
46618 + clear_page(kaddr);
46619 + kunmap_atomic(kaddr, KM_CLEARPAGE);
46620 + local_irq_restore(flags);
46621 +}
46622 +
46623 static inline void zero_user_segments(struct page *page,
46624 unsigned start1, unsigned end1,
46625 unsigned start2, unsigned end2)
46626 diff -urNp linux-2.6.37/include/linux/init.h linux-2.6.37/include/linux/init.h
46627 --- linux-2.6.37/include/linux/init.h 2011-01-04 19:50:19.000000000 -0500
46628 +++ linux-2.6.37/include/linux/init.h 2011-01-17 02:41:02.000000000 -0500
46629 @@ -293,13 +293,13 @@ void __init parse_early_options(char *cm
46630
46631 /* Each module must use one module_init(). */
46632 #define module_init(initfn) \
46633 - static inline initcall_t __inittest(void) \
46634 + static inline __used initcall_t __inittest(void) \
46635 { return initfn; } \
46636 int init_module(void) __attribute__((alias(#initfn)));
46637
46638 /* This is only required if you want to be unloadable. */
46639 #define module_exit(exitfn) \
46640 - static inline exitcall_t __exittest(void) \
46641 + static inline __used exitcall_t __exittest(void) \
46642 { return exitfn; } \
46643 void cleanup_module(void) __attribute__((alias(#exitfn)));
46644
46645 diff -urNp linux-2.6.37/include/linux/interrupt.h linux-2.6.37/include/linux/interrupt.h
46646 --- linux-2.6.37/include/linux/interrupt.h 2011-01-04 19:50:19.000000000 -0500
46647 +++ linux-2.6.37/include/linux/interrupt.h 2011-01-17 02:41:02.000000000 -0500
46648 @@ -393,7 +393,7 @@ enum
46649 /* map softirq index to softirq name. update 'softirq_to_name' in
46650 * kernel/softirq.c when adding a new softirq.
46651 */
46652 -extern char *softirq_to_name[NR_SOFTIRQS];
46653 +extern const char * const softirq_to_name[NR_SOFTIRQS];
46654
46655 /* softirq mask and active fields moved to irq_cpustat_t in
46656 * asm/hardirq.h to get better cache usage. KAO
46657 @@ -401,12 +401,12 @@ extern char *softirq_to_name[NR_SOFTIRQS
46658
46659 struct softirq_action
46660 {
46661 - void (*action)(struct softirq_action *);
46662 + void (*action)(void);
46663 };
46664
46665 asmlinkage void do_softirq(void);
46666 asmlinkage void __do_softirq(void);
46667 -extern void open_softirq(int nr, void (*action)(struct softirq_action *));
46668 +extern void open_softirq(int nr, void (*action)(void));
46669 extern void softirq_init(void);
46670 static inline void __raise_softirq_irqoff(unsigned int nr)
46671 {
46672 diff -urNp linux-2.6.37/include/linux/jbd2.h linux-2.6.37/include/linux/jbd2.h
46673 --- linux-2.6.37/include/linux/jbd2.h 2011-01-04 19:50:19.000000000 -0500
46674 +++ linux-2.6.37/include/linux/jbd2.h 2011-01-17 02:41:02.000000000 -0500
46675 @@ -67,7 +67,7 @@ extern u8 jbd2_journal_enable_debug;
46676 } \
46677 } while (0)
46678 #else
46679 -#define jbd_debug(f, a...) /**/
46680 +#define jbd_debug(f, a...) do {} while (0)
46681 #endif
46682
46683 extern void *jbd2_alloc(size_t size, gfp_t flags);
46684 diff -urNp linux-2.6.37/include/linux/jbd.h linux-2.6.37/include/linux/jbd.h
46685 --- linux-2.6.37/include/linux/jbd.h 2011-01-04 19:50:19.000000000 -0500
46686 +++ linux-2.6.37/include/linux/jbd.h 2011-01-17 02:41:02.000000000 -0500
46687 @@ -67,7 +67,7 @@ extern u8 journal_enable_debug;
46688 } \
46689 } while (0)
46690 #else
46691 -#define jbd_debug(f, a...) /**/
46692 +#define jbd_debug(f, a...) do {} while (0)
46693 #endif
46694
46695 static inline void *jbd_alloc(size_t size, gfp_t flags)
46696 diff -urNp linux-2.6.37/include/linux/kallsyms.h linux-2.6.37/include/linux/kallsyms.h
46697 --- linux-2.6.37/include/linux/kallsyms.h 2011-01-04 19:50:19.000000000 -0500
46698 +++ linux-2.6.37/include/linux/kallsyms.h 2011-01-17 02:41:02.000000000 -0500
46699 @@ -15,7 +15,8 @@
46700
46701 struct module;
46702
46703 -#ifdef CONFIG_KALLSYMS
46704 +#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
46705 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
46706 /* Lookup the address for a symbol. Returns 0 if not found. */
46707 unsigned long kallsyms_lookup_name(const char *name);
46708
46709 @@ -92,6 +93,15 @@ static inline int lookup_symbol_attrs(un
46710 /* Stupid that this does nothing, but I didn't create this mess. */
46711 #define __print_symbol(fmt, addr)
46712 #endif /*CONFIG_KALLSYMS*/
46713 +#else /* when included by kallsyms.c, vsnprintf.c, or
46714 + arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
46715 +extern void __print_symbol(const char *fmt, unsigned long address);
46716 +extern int sprint_symbol(char *buffer, unsigned long address);
46717 +const char *kallsyms_lookup(unsigned long addr,
46718 + unsigned long *symbolsize,
46719 + unsigned long *offset,
46720 + char **modname, char *namebuf);
46721 +#endif
46722
46723 /* This macro allows us to keep printk typechecking */
46724 static void __check_printsym_format(const char *fmt, ...)
46725 diff -urNp linux-2.6.37/include/linux/kgdb.h linux-2.6.37/include/linux/kgdb.h
46726 --- linux-2.6.37/include/linux/kgdb.h 2011-01-04 19:50:19.000000000 -0500
46727 +++ linux-2.6.37/include/linux/kgdb.h 2011-01-17 02:41:02.000000000 -0500
46728 @@ -269,22 +269,22 @@ struct kgdb_arch {
46729 */
46730 struct kgdb_io {
46731 const char *name;
46732 - int (*read_char) (void);
46733 - void (*write_char) (u8);
46734 - void (*flush) (void);
46735 - int (*init) (void);
46736 - void (*pre_exception) (void);
46737 - void (*post_exception) (void);
46738 + int (* const read_char) (void);
46739 + void (* const write_char) (u8);
46740 + void (* const flush) (void);
46741 + int (* const init) (void);
46742 + void (* const pre_exception) (void);
46743 + void (* const post_exception) (void);
46744 int is_console;
46745 };
46746
46747 -extern struct kgdb_arch arch_kgdb_ops;
46748 +extern const struct kgdb_arch arch_kgdb_ops;
46749
46750 extern unsigned long __weak kgdb_arch_pc(int exception, struct pt_regs *regs);
46751
46752 -extern int kgdb_register_io_module(struct kgdb_io *local_kgdb_io_ops);
46753 -extern void kgdb_unregister_io_module(struct kgdb_io *local_kgdb_io_ops);
46754 -extern struct kgdb_io *dbg_io_ops;
46755 +extern int kgdb_register_io_module(const struct kgdb_io *local_kgdb_io_ops);
46756 +extern void kgdb_unregister_io_module(const struct kgdb_io *local_kgdb_io_ops);
46757 +extern const struct kgdb_io *dbg_io_ops;
46758
46759 extern int kgdb_hex2long(char **ptr, unsigned long *long_val);
46760 extern char *kgdb_mem2hex(char *mem, char *buf, int count);
46761 diff -urNp linux-2.6.37/include/linux/kvm_host.h linux-2.6.37/include/linux/kvm_host.h
46762 --- linux-2.6.37/include/linux/kvm_host.h 2011-01-04 19:50:19.000000000 -0500
46763 +++ linux-2.6.37/include/linux/kvm_host.h 2011-01-17 02:41:02.000000000 -0500
46764 @@ -246,7 +246,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vc
46765 void vcpu_load(struct kvm_vcpu *vcpu);
46766 void vcpu_put(struct kvm_vcpu *vcpu);
46767
46768 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
46769 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
46770 struct module *module);
46771 void kvm_exit(void);
46772
46773 @@ -375,7 +375,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(
46774 struct kvm_guest_debug *dbg);
46775 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
46776
46777 -int kvm_arch_init(void *opaque);
46778 +int kvm_arch_init(const void *opaque);
46779 void kvm_arch_exit(void);
46780
46781 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
46782 diff -urNp linux-2.6.37/include/linux/libata.h linux-2.6.37/include/linux/libata.h
46783 --- linux-2.6.37/include/linux/libata.h 2011-01-04 19:50:19.000000000 -0500
46784 +++ linux-2.6.37/include/linux/libata.h 2011-01-17 02:41:02.000000000 -0500
46785 @@ -65,11 +65,11 @@
46786 #ifdef ATA_VERBOSE_DEBUG
46787 #define VPRINTK(fmt, args...) printk(KERN_ERR "%s: " fmt, __func__, ## args)
46788 #else
46789 -#define VPRINTK(fmt, args...)
46790 +#define VPRINTK(fmt, args...) do {} while (0)
46791 #endif /* ATA_VERBOSE_DEBUG */
46792 #else
46793 -#define DPRINTK(fmt, args...)
46794 -#define VPRINTK(fmt, args...)
46795 +#define DPRINTK(fmt, args...) do {} while (0)
46796 +#define VPRINTK(fmt, args...) do {} while (0)
46797 #endif /* ATA_DEBUG */
46798
46799 #define BPRINTK(fmt, args...) if (ap->flags & ATA_FLAG_DEBUGMSG) printk(KERN_ERR "%s: " fmt, __func__, ## args)
46800 @@ -530,11 +530,11 @@ struct ata_ioports {
46801
46802 struct ata_host {
46803 spinlock_t lock;
46804 - struct device *dev;
46805 + struct device *dev;
46806 void __iomem * const *iomap;
46807 unsigned int n_ports;
46808 void *private_data;
46809 - struct ata_port_operations *ops;
46810 + const struct ata_port_operations *ops;
46811 unsigned long flags;
46812
46813 struct mutex eh_mutex;
46814 @@ -725,7 +725,7 @@ struct ata_link {
46815
46816 struct ata_port {
46817 struct Scsi_Host *scsi_host; /* our co-allocated scsi host */
46818 - struct ata_port_operations *ops;
46819 + const struct ata_port_operations *ops;
46820 spinlock_t *lock;
46821 /* Flags owned by the EH context. Only EH should touch these once the
46822 port is active */
46823 @@ -913,7 +913,7 @@ struct ata_port_info {
46824 unsigned long pio_mask;
46825 unsigned long mwdma_mask;
46826 unsigned long udma_mask;
46827 - struct ata_port_operations *port_ops;
46828 + const struct ata_port_operations *port_ops;
46829 void *private_data;
46830 };
46831
46832 @@ -937,7 +937,7 @@ extern const unsigned long sata_deb_timi
46833 extern const unsigned long sata_deb_timing_hotplug[];
46834 extern const unsigned long sata_deb_timing_long[];
46835
46836 -extern struct ata_port_operations ata_dummy_port_ops;
46837 +extern const struct ata_port_operations ata_dummy_port_ops;
46838 extern const struct ata_port_info ata_dummy_port_info;
46839
46840 static inline const unsigned long *
46841 @@ -983,7 +983,7 @@ extern int ata_host_activate(struct ata_
46842 struct scsi_host_template *sht);
46843 extern void ata_host_detach(struct ata_host *host);
46844 extern void ata_host_init(struct ata_host *, struct device *,
46845 - unsigned long, struct ata_port_operations *);
46846 + unsigned long, const struct ata_port_operations *);
46847 extern int ata_scsi_detect(struct scsi_host_template *sht);
46848 extern int ata_scsi_ioctl(struct scsi_device *dev, int cmd, void __user *arg);
46849 extern int ata_scsi_queuecmd(struct Scsi_Host *h, struct scsi_cmnd *cmd);
46850 diff -urNp linux-2.6.37/include/linux/lockd/bind.h linux-2.6.37/include/linux/lockd/bind.h
46851 --- linux-2.6.37/include/linux/lockd/bind.h 2011-01-04 19:50:19.000000000 -0500
46852 +++ linux-2.6.37/include/linux/lockd/bind.h 2011-01-17 02:41:02.000000000 -0500
46853 @@ -23,13 +23,13 @@ struct svc_rqst;
46854 * This is the set of functions for lockd->nfsd communication
46855 */
46856 struct nlmsvc_binding {
46857 - __be32 (*fopen)(struct svc_rqst *,
46858 + __be32 (* const fopen)(struct svc_rqst *,
46859 struct nfs_fh *,
46860 struct file **);
46861 - void (*fclose)(struct file *);
46862 + void (* const fclose)(struct file *);
46863 };
46864
46865 -extern struct nlmsvc_binding * nlmsvc_ops;
46866 +extern const struct nlmsvc_binding * nlmsvc_ops;
46867
46868 /*
46869 * Similar to nfs_client_initdata, but without the NFS-specific
46870 diff -urNp linux-2.6.37/include/linux/mm.h linux-2.6.37/include/linux/mm.h
46871 --- linux-2.6.37/include/linux/mm.h 2011-01-04 19:50:19.000000000 -0500
46872 +++ linux-2.6.37/include/linux/mm.h 2011-01-17 02:41:02.000000000 -0500
46873 @@ -107,7 +107,14 @@ extern unsigned int kobjsize(const void
46874
46875 #define VM_CAN_NONLINEAR 0x08000000 /* Has ->fault & does nonlinear pages */
46876 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
46877 +
46878 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
46879 +#define VM_SAO 0x00000000 /* Strong Access Ordering (powerpc) */
46880 +#define VM_PAGEEXEC 0x20000000 /* vma->vm_page_prot needs special handling */
46881 +#else
46882 #define VM_SAO 0x20000000 /* Strong Access Ordering (powerpc) */
46883 +#endif
46884 +
46885 #define VM_PFN_AT_MMAP 0x40000000 /* PFNMAP vma that is fully mapped at mmap time */
46886 #define VM_MERGEABLE 0x80000000 /* KSM may merge identical pages */
46887
46888 @@ -875,12 +882,6 @@ int set_page_dirty(struct page *page);
46889 int set_page_dirty_lock(struct page *page);
46890 int clear_page_dirty_for_io(struct page *page);
46891
46892 -/* Is the vma a continuation of the stack vma above it? */
46893 -static inline int vma_stack_continue(struct vm_area_struct *vma, unsigned long addr)
46894 -{
46895 - return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
46896 -}
46897 -
46898 extern unsigned long move_page_tables(struct vm_area_struct *vma,
46899 unsigned long old_addr, struct vm_area_struct *new_vma,
46900 unsigned long new_addr, unsigned long len);
46901 @@ -1032,6 +1033,15 @@ struct shrinker {
46902 extern void register_shrinker(struct shrinker *);
46903 extern void unregister_shrinker(struct shrinker *);
46904
46905 +#ifdef CONFIG_MMU
46906 +pgprot_t vm_get_page_prot(unsigned long vm_flags);
46907 +#else
46908 +static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
46909 +{
46910 + return __pgprot(0);
46911 +}
46912 +#endif
46913 +
46914 int vma_wants_writenotify(struct vm_area_struct *vma);
46915
46916 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
46917 @@ -1318,6 +1328,7 @@ out:
46918 }
46919
46920 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
46921 +extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
46922
46923 extern unsigned long do_brk(unsigned long, unsigned long);
46924
46925 @@ -1374,6 +1385,10 @@ extern struct vm_area_struct * find_vma(
46926 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
46927 struct vm_area_struct **pprev);
46928
46929 +extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
46930 +extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
46931 +extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
46932 +
46933 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
46934 NULL if none. Assume start_addr < end_addr. */
46935 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
46936 @@ -1390,15 +1405,6 @@ static inline unsigned long vma_pages(st
46937 return (vma->vm_end - vma->vm_start) >> PAGE_SHIFT;
46938 }
46939
46940 -#ifdef CONFIG_MMU
46941 -pgprot_t vm_get_page_prot(unsigned long vm_flags);
46942 -#else
46943 -static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
46944 -{
46945 - return __pgprot(0);
46946 -}
46947 -#endif
46948 -
46949 struct vm_area_struct *find_extend_vma(struct mm_struct *, unsigned long addr);
46950 int remap_pfn_range(struct vm_area_struct *, unsigned long addr,
46951 unsigned long pfn, unsigned long size, pgprot_t);
46952 @@ -1505,7 +1511,7 @@ extern int unpoison_memory(unsigned long
46953 extern int sysctl_memory_failure_early_kill;
46954 extern int sysctl_memory_failure_recovery;
46955 extern void shake_page(struct page *p, int access);
46956 -extern atomic_long_t mce_bad_pages;
46957 +extern atomic_long_unchecked_t mce_bad_pages;
46958 extern int soft_offline_page(struct page *page, int flags);
46959 #ifdef CONFIG_MEMORY_FAILURE
46960 int is_hwpoison_address(unsigned long addr);
46961 @@ -1518,5 +1524,11 @@ static inline int is_hwpoison_address(un
46962
46963 extern void dump_page(struct page *page);
46964
46965 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
46966 +extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
46967 +#else
46968 +static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
46969 +#endif
46970 +
46971 #endif /* __KERNEL__ */
46972 #endif /* _LINUX_MM_H */
46973 diff -urNp linux-2.6.37/include/linux/mm_types.h linux-2.6.37/include/linux/mm_types.h
46974 --- linux-2.6.37/include/linux/mm_types.h 2011-01-04 19:50:19.000000000 -0500
46975 +++ linux-2.6.37/include/linux/mm_types.h 2011-01-17 02:41:02.000000000 -0500
46976 @@ -183,6 +183,8 @@ struct vm_area_struct {
46977 #ifdef CONFIG_NUMA
46978 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
46979 #endif
46980 +
46981 + struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
46982 };
46983
46984 struct core_thread {
46985 @@ -312,6 +314,24 @@ struct mm_struct {
46986 #endif
46987 /* How many tasks sharing this mm are OOM_DISABLE */
46988 atomic_t oom_disable_count;
46989 +
46990 +#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS) || defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
46991 + unsigned long pax_flags;
46992 +#endif
46993 +
46994 +#ifdef CONFIG_PAX_DLRESOLVE
46995 + unsigned long call_dl_resolve;
46996 +#endif
46997 +
46998 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
46999 + unsigned long call_syscall;
47000 +#endif
47001 +
47002 +#ifdef CONFIG_PAX_ASLR
47003 + unsigned long delta_mmap; /* randomized offset */
47004 + unsigned long delta_stack; /* randomized offset */
47005 +#endif
47006 +
47007 };
47008
47009 /* Future-safe accessor for struct mm_struct's cpu_vm_mask. */
47010 diff -urNp linux-2.6.37/include/linux/mmu_notifier.h linux-2.6.37/include/linux/mmu_notifier.h
47011 --- linux-2.6.37/include/linux/mmu_notifier.h 2011-01-04 19:50:19.000000000 -0500
47012 +++ linux-2.6.37/include/linux/mmu_notifier.h 2011-01-17 02:41:02.000000000 -0500
47013 @@ -235,12 +235,12 @@ static inline void mmu_notifier_mm_destr
47014 */
47015 #define ptep_clear_flush_notify(__vma, __address, __ptep) \
47016 ({ \
47017 - pte_t __pte; \
47018 + pte_t ___pte; \
47019 struct vm_area_struct *___vma = __vma; \
47020 unsigned long ___address = __address; \
47021 - __pte = ptep_clear_flush(___vma, ___address, __ptep); \
47022 + ___pte = ptep_clear_flush(___vma, ___address, __ptep); \
47023 mmu_notifier_invalidate_page(___vma->vm_mm, ___address); \
47024 - __pte; \
47025 + ___pte; \
47026 })
47027
47028 #define ptep_clear_flush_young_notify(__vma, __address, __ptep) \
47029 diff -urNp linux-2.6.37/include/linux/mmzone.h linux-2.6.37/include/linux/mmzone.h
47030 --- linux-2.6.37/include/linux/mmzone.h 2011-01-04 19:50:19.000000000 -0500
47031 +++ linux-2.6.37/include/linux/mmzone.h 2011-01-17 02:41:02.000000000 -0500
47032 @@ -354,7 +354,7 @@ struct zone {
47033 unsigned long flags; /* zone flags, see below */
47034
47035 /* Zone statistics */
47036 - atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
47037 + atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
47038
47039 /*
47040 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
47041 diff -urNp linux-2.6.37/include/linux/mod_devicetable.h linux-2.6.37/include/linux/mod_devicetable.h
47042 --- linux-2.6.37/include/linux/mod_devicetable.h 2011-01-04 19:50:19.000000000 -0500
47043 +++ linux-2.6.37/include/linux/mod_devicetable.h 2011-01-17 02:41:02.000000000 -0500
47044 @@ -12,7 +12,7 @@
47045 typedef unsigned long kernel_ulong_t;
47046 #endif
47047
47048 -#define PCI_ANY_ID (~0)
47049 +#define PCI_ANY_ID ((__u16)~0)
47050
47051 struct pci_device_id {
47052 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
47053 @@ -131,7 +131,7 @@ struct usb_device_id {
47054 #define USB_DEVICE_ID_MATCH_INT_SUBCLASS 0x0100
47055 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
47056
47057 -#define HID_ANY_ID (~0)
47058 +#define HID_ANY_ID (~0U)
47059
47060 struct hid_device_id {
47061 __u16 bus;
47062 diff -urNp linux-2.6.37/include/linux/module.h linux-2.6.37/include/linux/module.h
47063 --- linux-2.6.37/include/linux/module.h 2011-01-04 19:50:19.000000000 -0500
47064 +++ linux-2.6.37/include/linux/module.h 2011-01-17 02:41:02.000000000 -0500
47065 @@ -297,16 +297,16 @@ struct module
47066 int (*init)(void);
47067
47068 /* If this is non-NULL, vfree after init() returns */
47069 - void *module_init;
47070 + void *module_init_rx, *module_init_rw;
47071
47072 /* Here is the actual code + data, vfree'd on unload. */
47073 - void *module_core;
47074 + void *module_core_rx, *module_core_rw;
47075
47076 /* Here are the sizes of the init and core sections */
47077 - unsigned int init_size, core_size;
47078 + unsigned int init_size_rw, core_size_rw;
47079
47080 /* The size of the executable code in each section. */
47081 - unsigned int init_text_size, core_text_size;
47082 + unsigned int init_size_rx, core_size_rx;
47083
47084 /* Arch-specific module values */
47085 struct mod_arch_specific arch;
47086 @@ -411,16 +411,46 @@ bool is_module_address(unsigned long add
47087 bool is_module_percpu_address(unsigned long addr);
47088 bool is_module_text_address(unsigned long addr);
47089
47090 +static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
47091 +{
47092 +
47093 +#ifdef CONFIG_PAX_KERNEXEC
47094 + if (ktla_ktva(addr) >= (unsigned long)start &&
47095 + ktla_ktva(addr) < (unsigned long)start + size)
47096 + return 1;
47097 +#endif
47098 +
47099 + return ((void *)addr >= start && (void *)addr < start + size);
47100 +}
47101 +
47102 +static inline int within_module_core_rx(unsigned long addr, struct module *mod)
47103 +{
47104 + return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
47105 +}
47106 +
47107 +static inline int within_module_core_rw(unsigned long addr, struct module *mod)
47108 +{
47109 + return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
47110 +}
47111 +
47112 +static inline int within_module_init_rx(unsigned long addr, struct module *mod)
47113 +{
47114 + return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
47115 +}
47116 +
47117 +static inline int within_module_init_rw(unsigned long addr, struct module *mod)
47118 +{
47119 + return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
47120 +}
47121 +
47122 static inline int within_module_core(unsigned long addr, struct module *mod)
47123 {
47124 - return (unsigned long)mod->module_core <= addr &&
47125 - addr < (unsigned long)mod->module_core + mod->core_size;
47126 + return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
47127 }
47128
47129 static inline int within_module_init(unsigned long addr, struct module *mod)
47130 {
47131 - return (unsigned long)mod->module_init <= addr &&
47132 - addr < (unsigned long)mod->module_init + mod->init_size;
47133 + return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
47134 }
47135
47136 /* Search for module by name: must hold module_mutex. */
47137 diff -urNp linux-2.6.37/include/linux/moduleloader.h linux-2.6.37/include/linux/moduleloader.h
47138 --- linux-2.6.37/include/linux/moduleloader.h 2011-01-04 19:50:19.000000000 -0500
47139 +++ linux-2.6.37/include/linux/moduleloader.h 2011-01-17 02:41:02.000000000 -0500
47140 @@ -20,9 +20,21 @@ unsigned int arch_mod_section_prepend(st
47141 sections. Returns NULL on failure. */
47142 void *module_alloc(unsigned long size);
47143
47144 +#ifdef CONFIG_PAX_KERNEXEC
47145 +void *module_alloc_exec(unsigned long size);
47146 +#else
47147 +#define module_alloc_exec(x) module_alloc(x)
47148 +#endif
47149 +
47150 /* Free memory returned from module_alloc. */
47151 void module_free(struct module *mod, void *module_region);
47152
47153 +#ifdef CONFIG_PAX_KERNEXEC
47154 +void module_free_exec(struct module *mod, void *module_region);
47155 +#else
47156 +#define module_free_exec(x, y) module_free((x), (y))
47157 +#endif
47158 +
47159 /* Apply the given relocation to the (simplified) ELF. Return -error
47160 or 0. */
47161 int apply_relocate(Elf_Shdr *sechdrs,
47162 diff -urNp linux-2.6.37/include/linux/moduleparam.h linux-2.6.37/include/linux/moduleparam.h
47163 --- linux-2.6.37/include/linux/moduleparam.h 2011-01-04 19:50:19.000000000 -0500
47164 +++ linux-2.6.37/include/linux/moduleparam.h 2011-01-17 02:41:02.000000000 -0500
47165 @@ -253,7 +253,7 @@ static inline void __kernel_param_unlock
47166 * @len is usually just sizeof(string).
47167 */
47168 #define module_param_string(name, string, len, perm) \
47169 - static const struct kparam_string __param_string_##name \
47170 + static const struct kparam_string __param_string_##name __used \
47171 = { len, string }; \
47172 __module_param_call(MODULE_PARAM_PREFIX, name, \
47173 &param_ops_string, \
47174 @@ -368,7 +368,7 @@ extern int param_get_invbool(char *buffe
47175 * module_param_named() for why this might be necessary.
47176 */
47177 #define module_param_array_named(name, array, type, nump, perm) \
47178 - static const struct kparam_array __param_arr_##name \
47179 + static const struct kparam_array __param_arr_##name __used \
47180 = { ARRAY_SIZE(array), nump, &param_ops_##type, \
47181 sizeof(array[0]), array }; \
47182 __module_param_call(MODULE_PARAM_PREFIX, name, \
47183 diff -urNp linux-2.6.37/include/linux/namei.h linux-2.6.37/include/linux/namei.h
47184 --- linux-2.6.37/include/linux/namei.h 2011-01-04 19:50:19.000000000 -0500
47185 +++ linux-2.6.37/include/linux/namei.h 2011-01-17 02:41:02.000000000 -0500
47186 @@ -22,7 +22,7 @@ struct nameidata {
47187 unsigned int flags;
47188 int last_type;
47189 unsigned depth;
47190 - char *saved_names[MAX_NESTED_LINKS + 1];
47191 + const char *saved_names[MAX_NESTED_LINKS + 1];
47192
47193 /* Intent data */
47194 union {
47195 @@ -81,12 +81,12 @@ extern int follow_up(struct path *);
47196 extern struct dentry *lock_rename(struct dentry *, struct dentry *);
47197 extern void unlock_rename(struct dentry *, struct dentry *);
47198
47199 -static inline void nd_set_link(struct nameidata *nd, char *path)
47200 +static inline void nd_set_link(struct nameidata *nd, const char *path)
47201 {
47202 nd->saved_names[nd->depth] = path;
47203 }
47204
47205 -static inline char *nd_get_link(struct nameidata *nd)
47206 +static inline const char *nd_get_link(const struct nameidata *nd)
47207 {
47208 return nd->saved_names[nd->depth];
47209 }
47210 diff -urNp linux-2.6.37/include/linux/netfilter/xt_gradm.h linux-2.6.37/include/linux/netfilter/xt_gradm.h
47211 --- linux-2.6.37/include/linux/netfilter/xt_gradm.h 1969-12-31 19:00:00.000000000 -0500
47212 +++ linux-2.6.37/include/linux/netfilter/xt_gradm.h 2011-01-17 02:41:02.000000000 -0500
47213 @@ -0,0 +1,9 @@
47214 +#ifndef _LINUX_NETFILTER_XT_GRADM_H
47215 +#define _LINUX_NETFILTER_XT_GRADM_H 1
47216 +
47217 +struct xt_gradm_mtinfo {
47218 + __u16 flags;
47219 + __u16 invflags;
47220 +};
47221 +
47222 +#endif
47223 diff -urNp linux-2.6.37/include/linux/oprofile.h linux-2.6.37/include/linux/oprofile.h
47224 --- linux-2.6.37/include/linux/oprofile.h 2011-01-04 19:50:19.000000000 -0500
47225 +++ linux-2.6.37/include/linux/oprofile.h 2011-01-17 02:41:02.000000000 -0500
47226 @@ -130,9 +130,9 @@ int oprofilefs_create_ulong(struct super
47227 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
47228 char const * name, ulong * val);
47229
47230 -/** Create a file for read-only access to an atomic_t. */
47231 +/** Create a file for read-only access to an atomic_unchecked_t. */
47232 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
47233 - char const * name, atomic_t * val);
47234 + char const * name, atomic_unchecked_t * val);
47235
47236 /** create a directory */
47237 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
47238 diff -urNp linux-2.6.37/include/linux/pipe_fs_i.h linux-2.6.37/include/linux/pipe_fs_i.h
47239 --- linux-2.6.37/include/linux/pipe_fs_i.h 2011-01-04 19:50:19.000000000 -0500
47240 +++ linux-2.6.37/include/linux/pipe_fs_i.h 2011-01-17 02:41:02.000000000 -0500
47241 @@ -45,9 +45,9 @@ struct pipe_buffer {
47242 struct pipe_inode_info {
47243 wait_queue_head_t wait;
47244 unsigned int nrbufs, curbuf, buffers;
47245 - unsigned int readers;
47246 - unsigned int writers;
47247 - unsigned int waiting_writers;
47248 + atomic_t readers;
47249 + atomic_t writers;
47250 + atomic_t waiting_writers;
47251 unsigned int r_counter;
47252 unsigned int w_counter;
47253 struct page *tmp_page;
47254 diff -urNp linux-2.6.37/include/linux/pm_runtime.h linux-2.6.37/include/linux/pm_runtime.h
47255 --- linux-2.6.37/include/linux/pm_runtime.h 2011-01-04 19:50:19.000000000 -0500
47256 +++ linux-2.6.37/include/linux/pm_runtime.h 2011-01-17 02:41:02.000000000 -0500
47257 @@ -83,7 +83,7 @@ static inline bool pm_runtime_suspended(
47258
47259 static inline void pm_runtime_mark_last_busy(struct device *dev)
47260 {
47261 - ACCESS_ONCE(dev->power.last_busy) = jiffies;
47262 + ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
47263 }
47264
47265 #else /* !CONFIG_PM_RUNTIME */
47266 diff -urNp linux-2.6.37/include/linux/poison.h linux-2.6.37/include/linux/poison.h
47267 --- linux-2.6.37/include/linux/poison.h 2011-01-04 19:50:19.000000000 -0500
47268 +++ linux-2.6.37/include/linux/poison.h 2011-01-17 02:41:02.000000000 -0500
47269 @@ -19,8 +19,8 @@
47270 * under normal circumstances, used to verify that nobody uses
47271 * non-initialized list entries.
47272 */
47273 -#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
47274 -#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
47275 +#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
47276 +#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
47277
47278 /********** include/linux/timer.h **********/
47279 /*
47280 diff -urNp linux-2.6.37/include/linux/proc_fs.h linux-2.6.37/include/linux/proc_fs.h
47281 --- linux-2.6.37/include/linux/proc_fs.h 2011-01-04 19:50:19.000000000 -0500
47282 +++ linux-2.6.37/include/linux/proc_fs.h 2011-01-17 02:41:02.000000000 -0500
47283 @@ -155,6 +155,19 @@ static inline struct proc_dir_entry *pro
47284 return proc_create_data(name, mode, parent, proc_fops, NULL);
47285 }
47286
47287 +static inline struct proc_dir_entry *proc_create_grsec(const char *name, mode_t mode,
47288 + struct proc_dir_entry *parent, const struct file_operations *proc_fops)
47289 +{
47290 +#ifdef CONFIG_GRKERNSEC_PROC_USER
47291 + return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
47292 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
47293 + return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
47294 +#else
47295 + return proc_create_data(name, mode, parent, proc_fops, NULL);
47296 +#endif
47297 +}
47298 +
47299 +
47300 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
47301 mode_t mode, struct proc_dir_entry *base,
47302 read_proc_t *read_proc, void * data)
47303 diff -urNp linux-2.6.37/include/linux/random.h linux-2.6.37/include/linux/random.h
47304 --- linux-2.6.37/include/linux/random.h 2011-01-04 19:50:19.000000000 -0500
47305 +++ linux-2.6.37/include/linux/random.h 2011-01-17 02:41:02.000000000 -0500
47306 @@ -80,12 +80,17 @@ void srandom32(u32 seed);
47307
47308 u32 prandom32(struct rnd_state *);
47309
47310 +static inline unsigned long pax_get_random_long(void)
47311 +{
47312 + return random32() + (sizeof(long) > 4 ? (unsigned long)random32() << 32 : 0);
47313 +}
47314 +
47315 /*
47316 * Handle minimum values for seeds
47317 */
47318 static inline u32 __seed(u32 x, u32 m)
47319 {
47320 - return (x < m) ? x + m : x;
47321 + return (x <= m) ? x + m + 1 : x;
47322 }
47323
47324 /**
47325 diff -urNp linux-2.6.37/include/linux/reiserfs_fs.h linux-2.6.37/include/linux/reiserfs_fs.h
47326 --- linux-2.6.37/include/linux/reiserfs_fs.h 2011-01-04 19:50:19.000000000 -0500
47327 +++ linux-2.6.37/include/linux/reiserfs_fs.h 2011-01-17 02:41:02.000000000 -0500
47328 @@ -1403,7 +1403,7 @@ static inline loff_t max_reiserfs_offset
47329 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
47330
47331 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
47332 -#define get_generation(s) atomic_read (&fs_generation(s))
47333 +#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
47334 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
47335 #define __fs_changed(gen,s) (gen != get_generation (s))
47336 #define fs_changed(gen,s) \
47337 @@ -1615,24 +1615,24 @@ static inline struct super_block *sb_fro
47338 */
47339
47340 struct item_operations {
47341 - int (*bytes_number) (struct item_head * ih, int block_size);
47342 - void (*decrement_key) (struct cpu_key *);
47343 - int (*is_left_mergeable) (struct reiserfs_key * ih,
47344 + int (* const bytes_number) (struct item_head * ih, int block_size);
47345 + void (* const decrement_key) (struct cpu_key *);
47346 + int (* const is_left_mergeable) (struct reiserfs_key * ih,
47347 unsigned long bsize);
47348 - void (*print_item) (struct item_head *, char *item);
47349 - void (*check_item) (struct item_head *, char *item);
47350 + void (* const print_item) (struct item_head *, char *item);
47351 + void (* const check_item) (struct item_head *, char *item);
47352
47353 - int (*create_vi) (struct virtual_node * vn, struct virtual_item * vi,
47354 + int (* const create_vi) (struct virtual_node * vn, struct virtual_item * vi,
47355 int is_affected, int insert_size);
47356 - int (*check_left) (struct virtual_item * vi, int free,
47357 + int (* const check_left) (struct virtual_item * vi, int free,
47358 int start_skip, int end_skip);
47359 - int (*check_right) (struct virtual_item * vi, int free);
47360 - int (*part_size) (struct virtual_item * vi, int from, int to);
47361 - int (*unit_num) (struct virtual_item * vi);
47362 - void (*print_vi) (struct virtual_item * vi);
47363 + int (* const check_right) (struct virtual_item * vi, int free);
47364 + int (* const part_size) (struct virtual_item * vi, int from, int to);
47365 + int (* const unit_num) (struct virtual_item * vi);
47366 + void (* const print_vi) (struct virtual_item * vi);
47367 };
47368
47369 -extern struct item_operations *item_ops[TYPE_ANY + 1];
47370 +extern const struct item_operations * const item_ops[TYPE_ANY + 1];
47371
47372 #define op_bytes_number(ih,bsize) item_ops[le_ih_k_type (ih)]->bytes_number (ih, bsize)
47373 #define op_is_left_mergeable(key,bsize) item_ops[le_key_k_type (le_key_version (key), key)]->is_left_mergeable (key, bsize)
47374 diff -urNp linux-2.6.37/include/linux/reiserfs_fs_sb.h linux-2.6.37/include/linux/reiserfs_fs_sb.h
47375 --- linux-2.6.37/include/linux/reiserfs_fs_sb.h 2011-01-04 19:50:19.000000000 -0500
47376 +++ linux-2.6.37/include/linux/reiserfs_fs_sb.h 2011-01-17 02:41:02.000000000 -0500
47377 @@ -386,7 +386,7 @@ struct reiserfs_sb_info {
47378 /* Comment? -Hans */
47379 wait_queue_head_t s_wait;
47380 /* To be obsoleted soon by per buffer seals.. -Hans */
47381 - atomic_t s_generation_counter; // increased by one every time the
47382 + atomic_unchecked_t s_generation_counter; // increased by one every time the
47383 // tree gets re-balanced
47384 unsigned long s_properties; /* File system properties. Currently holds
47385 on-disk FS format */
47386 diff -urNp linux-2.6.37/include/linux/rmap.h linux-2.6.37/include/linux/rmap.h
47387 --- linux-2.6.37/include/linux/rmap.h 2011-01-04 19:50:19.000000000 -0500
47388 +++ linux-2.6.37/include/linux/rmap.h 2011-01-17 02:41:02.000000000 -0500
47389 @@ -145,8 +145,8 @@ static inline void anon_vma_unlock(struc
47390 void anon_vma_init(void); /* create anon_vma_cachep */
47391 int anon_vma_prepare(struct vm_area_struct *);
47392 void unlink_anon_vmas(struct vm_area_struct *);
47393 -int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
47394 -int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
47395 +int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
47396 +int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
47397 void __anon_vma_link(struct vm_area_struct *);
47398 void anon_vma_free(struct anon_vma *);
47399
47400 diff -urNp linux-2.6.37/include/linux/sched.h linux-2.6.37/include/linux/sched.h
47401 --- linux-2.6.37/include/linux/sched.h 2011-01-04 19:50:19.000000000 -0500
47402 +++ linux-2.6.37/include/linux/sched.h 2011-01-17 02:41:02.000000000 -0500
47403 @@ -100,6 +100,7 @@ struct robust_list_head;
47404 struct bio_list;
47405 struct fs_struct;
47406 struct perf_event_context;
47407 +struct linux_binprm;
47408
47409 /*
47410 * List of flags we want to share for kernel threads,
47411 @@ -377,10 +378,12 @@ struct user_namespace;
47412 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
47413
47414 extern int sysctl_max_map_count;
47415 +extern unsigned long sysctl_heap_stack_gap;
47416
47417 #include <linux/aio.h>
47418
47419 #ifdef CONFIG_MMU
47420 +extern bool check_heap_stack_gap(struct vm_area_struct *vma, unsigned long addr, unsigned long len);
47421 extern void arch_pick_mmap_layout(struct mm_struct *mm);
47422 extern unsigned long
47423 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
47424 @@ -624,6 +627,16 @@ struct signal_struct {
47425 struct tty_audit_buf *tty_audit_buf;
47426 #endif
47427
47428 +#ifdef CONFIG_GRKERNSEC
47429 + u32 curr_ip;
47430 + u32 saved_ip;
47431 + u32 gr_saddr;
47432 + u32 gr_daddr;
47433 + u16 gr_sport;
47434 + u16 gr_dport;
47435 + u8 used_accept:1;
47436 +#endif
47437 +
47438 int oom_adj; /* OOM kill score adjustment (bit shift) */
47439 int oom_score_adj; /* OOM kill score adjustment */
47440
47441 @@ -1181,7 +1194,7 @@ enum perf_event_task_context {
47442
47443 struct task_struct {
47444 volatile long state; /* -1 unrunnable, 0 runnable, >0 stopped */
47445 - void *stack;
47446 + struct thread_info *stack;
47447 atomic_t usage;
47448 unsigned int flags; /* per process flags, defined below */
47449 unsigned int ptrace;
47450 @@ -1291,8 +1304,8 @@ struct task_struct {
47451 struct list_head thread_group;
47452
47453 struct completion *vfork_done; /* for vfork() */
47454 - int __user *set_child_tid; /* CLONE_CHILD_SETTID */
47455 - int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
47456 + pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
47457 + pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
47458
47459 cputime_t utime, stime, utimescaled, stimescaled;
47460 cputime_t gtime;
47461 @@ -1308,13 +1321,6 @@ struct task_struct {
47462 struct task_cputime cputime_expires;
47463 struct list_head cpu_timers[3];
47464
47465 -/* process credentials */
47466 - const struct cred __rcu *real_cred; /* objective and real subjective task
47467 - * credentials (COW) */
47468 - const struct cred __rcu *cred; /* effective (overridable) subjective task
47469 - * credentials (COW) */
47470 - struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */
47471 -
47472 char comm[TASK_COMM_LEN]; /* executable name excluding path
47473 - access with [gs]et_task_comm (which lock
47474 it with task_lock())
47475 @@ -1333,6 +1339,10 @@ struct task_struct {
47476 struct thread_struct thread;
47477 /* filesystem information */
47478 struct fs_struct *fs;
47479 +
47480 + const struct cred __rcu *cred; /* effective (overridable) subjective task
47481 + * credentials (COW) */
47482 +
47483 /* open file information */
47484 struct files_struct *files;
47485 /* namespaces */
47486 @@ -1379,6 +1389,11 @@ struct task_struct {
47487 struct rt_mutex_waiter *pi_blocked_on;
47488 #endif
47489
47490 +/* process credentials */
47491 + const struct cred __rcu *real_cred; /* objective and real subjective task
47492 + * credentials (COW) */
47493 + struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */
47494 +
47495 #ifdef CONFIG_DEBUG_MUTEXES
47496 /* mutex deadlock detection */
47497 struct mutex_waiter *blocked_on;
47498 @@ -1483,6 +1498,20 @@ struct task_struct {
47499 unsigned long default_timer_slack_ns;
47500
47501 struct list_head *scm_work_list;
47502 +
47503 +#ifdef CONFIG_GRKERNSEC
47504 + /* grsecurity */
47505 + struct dentry *gr_chroot_dentry;
47506 + struct acl_subject_label *acl;
47507 + struct acl_role_label *role;
47508 + struct file *exec_file;
47509 + u16 acl_role_id;
47510 + u8 acl_sp_role;
47511 + u8 is_writable;
47512 + u8 brute;
47513 + u8 gr_is_chrooted;
47514 +#endif
47515 +
47516 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
47517 /* Index of current stored address in ret_stack */
47518 int curr_ret_stack;
47519 @@ -1514,6 +1543,52 @@ struct task_struct {
47520 #endif
47521 };
47522
47523 +#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
47524 +#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
47525 +#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
47526 +#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
47527 +/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
47528 +#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
47529 +
47530 +#ifdef CONFIG_PAX_SOFTMODE
47531 +extern unsigned int pax_softmode;
47532 +#endif
47533 +
47534 +extern int pax_check_flags(unsigned long *);
47535 +
47536 +/* if tsk != current then task_lock must be held on it */
47537 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
47538 +static inline unsigned long pax_get_flags(struct task_struct *tsk)
47539 +{
47540 + if (likely(tsk->mm))
47541 + return tsk->mm->pax_flags;
47542 + else
47543 + return 0UL;
47544 +}
47545 +
47546 +/* if tsk != current then task_lock must be held on it */
47547 +static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
47548 +{
47549 + if (likely(tsk->mm)) {
47550 + tsk->mm->pax_flags = flags;
47551 + return 0;
47552 + }
47553 + return -EINVAL;
47554 +}
47555 +#endif
47556 +
47557 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
47558 +extern void pax_set_initial_flags(struct linux_binprm *bprm);
47559 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
47560 +extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
47561 +#endif
47562 +
47563 +void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
47564 +void pax_report_insns(void *pc, void *sp);
47565 +void pax_report_refcount_overflow(struct pt_regs *regs);
47566 +void pax_report_leak_to_user(const void *ptr, unsigned long len);
47567 +void pax_report_overflow_from_user(const void *ptr, unsigned long len);
47568 +
47569 /* Future-safe accessor for struct task_struct's cpus_allowed. */
47570 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
47571
47572 @@ -2134,7 +2209,7 @@ extern void __cleanup_sighand(struct sig
47573 extern void exit_itimers(struct signal_struct *);
47574 extern void flush_itimer_signals(void);
47575
47576 -extern NORET_TYPE void do_group_exit(int);
47577 +extern NORET_TYPE void do_group_exit(int) ATTRIB_NORET;
47578
47579 extern void daemonize(const char *, ...);
47580 extern int allow_signal(int);
47581 @@ -2259,8 +2334,8 @@ static inline void unlock_task_sighand(s
47582
47583 #ifndef __HAVE_THREAD_FUNCTIONS
47584
47585 -#define task_thread_info(task) ((struct thread_info *)(task)->stack)
47586 -#define task_stack_page(task) ((task)->stack)
47587 +#define task_thread_info(task) ((task)->stack)
47588 +#define task_stack_page(task) ((void *)(task)->stack)
47589
47590 static inline void setup_thread_stack(struct task_struct *p, struct task_struct *org)
47591 {
47592 @@ -2275,13 +2350,17 @@ static inline unsigned long *end_of_stac
47593
47594 #endif
47595
47596 -static inline int object_is_on_stack(void *obj)
47597 +static inline int object_starts_on_stack(void *obj)
47598 {
47599 - void *stack = task_stack_page(current);
47600 + const void *stack = task_stack_page(current);
47601
47602 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
47603 }
47604
47605 +#ifdef CONFIG_PAX_USERCOPY
47606 +extern int object_is_on_stack(const void *obj, unsigned long len);
47607 +#endif
47608 +
47609 extern void thread_info_cache_init(void);
47610
47611 #ifdef CONFIG_DEBUG_STACK_USAGE
47612 diff -urNp linux-2.6.37/include/linux/screen_info.h linux-2.6.37/include/linux/screen_info.h
47613 --- linux-2.6.37/include/linux/screen_info.h 2011-01-04 19:50:19.000000000 -0500
47614 +++ linux-2.6.37/include/linux/screen_info.h 2011-01-17 02:41:02.000000000 -0500
47615 @@ -43,7 +43,8 @@ struct screen_info {
47616 __u16 pages; /* 0x32 */
47617 __u16 vesa_attributes; /* 0x34 */
47618 __u32 capabilities; /* 0x36 */
47619 - __u8 _reserved[6]; /* 0x3a */
47620 + __u16 vesapm_size; /* 0x3a */
47621 + __u8 _reserved[4]; /* 0x3c */
47622 } __attribute__((packed));
47623
47624 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
47625 diff -urNp linux-2.6.37/include/linux/security.h linux-2.6.37/include/linux/security.h
47626 --- linux-2.6.37/include/linux/security.h 2011-01-04 19:50:19.000000000 -0500
47627 +++ linux-2.6.37/include/linux/security.h 2011-01-17 02:41:02.000000000 -0500
47628 @@ -35,6 +35,7 @@
47629 #include <linux/key.h>
47630 #include <linux/xfrm.h>
47631 #include <linux/slab.h>
47632 +#include <linux/grsecurity.h>
47633 #include <net/flow.h>
47634
47635 /* Maximum number of letters for an LSM name string */
47636 diff -urNp linux-2.6.37/include/linux/shm.h linux-2.6.37/include/linux/shm.h
47637 --- linux-2.6.37/include/linux/shm.h 2011-01-04 19:50:19.000000000 -0500
47638 +++ linux-2.6.37/include/linux/shm.h 2011-01-17 02:41:02.000000000 -0500
47639 @@ -95,6 +95,10 @@ struct shmid_kernel /* private to the ke
47640 pid_t shm_cprid;
47641 pid_t shm_lprid;
47642 struct user_struct *mlock_user;
47643 +#ifdef CONFIG_GRKERNSEC
47644 + time_t shm_createtime;
47645 + pid_t shm_lapid;
47646 +#endif
47647 };
47648
47649 /* shm_mode upper byte flags */
47650 diff -urNp linux-2.6.37/include/linux/skbuff.h linux-2.6.37/include/linux/skbuff.h
47651 --- linux-2.6.37/include/linux/skbuff.h 2011-01-04 19:50:19.000000000 -0500
47652 +++ linux-2.6.37/include/linux/skbuff.h 2011-01-17 02:41:02.000000000 -0500
47653 @@ -581,7 +581,7 @@ static inline struct skb_shared_hwtstamp
47654 */
47655 static inline int skb_queue_empty(const struct sk_buff_head *list)
47656 {
47657 - return list->next == (struct sk_buff *)list;
47658 + return list->next == (const struct sk_buff *)list;
47659 }
47660
47661 /**
47662 @@ -594,7 +594,7 @@ static inline int skb_queue_empty(const
47663 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
47664 const struct sk_buff *skb)
47665 {
47666 - return skb->next == (struct sk_buff *)list;
47667 + return skb->next == (const struct sk_buff *)list;
47668 }
47669
47670 /**
47671 @@ -607,7 +607,7 @@ static inline bool skb_queue_is_last(con
47672 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
47673 const struct sk_buff *skb)
47674 {
47675 - return skb->prev == (struct sk_buff *)list;
47676 + return skb->prev == (const struct sk_buff *)list;
47677 }
47678
47679 /**
47680 diff -urNp linux-2.6.37/include/linux/slab.h linux-2.6.37/include/linux/slab.h
47681 --- linux-2.6.37/include/linux/slab.h 2011-01-04 19:50:19.000000000 -0500
47682 +++ linux-2.6.37/include/linux/slab.h 2011-01-17 02:41:02.000000000 -0500
47683 @@ -11,6 +11,7 @@
47684
47685 #include <linux/gfp.h>
47686 #include <linux/types.h>
47687 +#include <linux/err.h>
47688
47689 /*
47690 * Flags to pass to kmem_cache_create().
47691 @@ -87,10 +88,13 @@
47692 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
47693 * Both make kfree a no-op.
47694 */
47695 -#define ZERO_SIZE_PTR ((void *)16)
47696 +#define ZERO_SIZE_PTR \
47697 +({ \
47698 + BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
47699 + (void *)(-MAX_ERRNO-1L); \
47700 +})
47701
47702 -#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
47703 - (unsigned long)ZERO_SIZE_PTR)
47704 +#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
47705
47706 /*
47707 * struct kmem_cache related prototypes
47708 @@ -144,6 +148,7 @@ void * __must_check krealloc(const void
47709 void kfree(const void *);
47710 void kzfree(const void *);
47711 size_t ksize(const void *);
47712 +void check_object_size(const void *ptr, unsigned long n, bool to);
47713
47714 /*
47715 * Allocator specific definitions. These are mainly used to establish optimized
47716 @@ -336,4 +341,37 @@ static inline void *kzalloc_node(size_t
47717
47718 void __init kmem_cache_init_late(void);
47719
47720 +#define kmalloc(x, y) \
47721 +({ \
47722 + void *___retval; \
47723 + intoverflow_t ___x = (intoverflow_t)x; \
47724 + if (WARN(___x > ULONG_MAX, "kmalloc size overflow\n"))\
47725 + ___retval = NULL; \
47726 + else \
47727 + ___retval = kmalloc((size_t)___x, (y)); \
47728 + ___retval; \
47729 +})
47730 +
47731 +#define kmalloc_node(x, y, z) \
47732 +({ \
47733 + void *___retval; \
47734 + intoverflow_t ___x = (intoverflow_t)x; \
47735 + if (WARN(___x > ULONG_MAX, "kmalloc_node size overflow\n"))\
47736 + ___retval = NULL; \
47737 + else \
47738 + ___retval = kmalloc_node((size_t)___x, (y), (z));\
47739 + ___retval; \
47740 +})
47741 +
47742 +#define kzalloc(x, y) \
47743 +({ \
47744 + void *___retval; \
47745 + intoverflow_t ___x = (intoverflow_t)x; \
47746 + if (WARN(___x > ULONG_MAX, "kzalloc size overflow\n"))\
47747 + ___retval = NULL; \
47748 + else \
47749 + ___retval = kzalloc((size_t)___x, (y)); \
47750 + ___retval; \
47751 +})
47752 +
47753 #endif /* _LINUX_SLAB_H */
47754 diff -urNp linux-2.6.37/include/linux/slub_def.h linux-2.6.37/include/linux/slub_def.h
47755 --- linux-2.6.37/include/linux/slub_def.h 2011-01-04 19:50:19.000000000 -0500
47756 +++ linux-2.6.37/include/linux/slub_def.h 2011-01-17 02:41:02.000000000 -0500
47757 @@ -80,7 +80,7 @@ struct kmem_cache {
47758 struct kmem_cache_order_objects max;
47759 struct kmem_cache_order_objects min;
47760 gfp_t allocflags; /* gfp flags to use on each alloc */
47761 - int refcount; /* Refcount for slab cache destroy */
47762 + atomic_t refcount; /* Refcount for slab cache destroy */
47763 void (*ctor)(void *);
47764 int inuse; /* Offset to metadata */
47765 int align; /* Alignment */
47766 diff -urNp linux-2.6.37/include/linux/sonet.h linux-2.6.37/include/linux/sonet.h
47767 --- linux-2.6.37/include/linux/sonet.h 2011-01-04 19:50:19.000000000 -0500
47768 +++ linux-2.6.37/include/linux/sonet.h 2011-01-17 02:41:02.000000000 -0500
47769 @@ -61,7 +61,7 @@ struct sonet_stats {
47770 #include <asm/atomic.h>
47771
47772 struct k_sonet_stats {
47773 -#define __HANDLE_ITEM(i) atomic_t i
47774 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
47775 __SONET_ITEMS
47776 #undef __HANDLE_ITEM
47777 };
47778 diff -urNp linux-2.6.37/include/linux/sunrpc/clnt.h linux-2.6.37/include/linux/sunrpc/clnt.h
47779 --- linux-2.6.37/include/linux/sunrpc/clnt.h 2011-01-04 19:50:19.000000000 -0500
47780 +++ linux-2.6.37/include/linux/sunrpc/clnt.h 2011-01-17 02:41:02.000000000 -0500
47781 @@ -168,9 +168,9 @@ static inline unsigned short rpc_get_por
47782 {
47783 switch (sap->sa_family) {
47784 case AF_INET:
47785 - return ntohs(((struct sockaddr_in *)sap)->sin_port);
47786 + return ntohs(((const struct sockaddr_in *)sap)->sin_port);
47787 case AF_INET6:
47788 - return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
47789 + return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
47790 }
47791 return 0;
47792 }
47793 @@ -203,7 +203,7 @@ static inline bool __rpc_cmp_addr4(const
47794 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
47795 const struct sockaddr *src)
47796 {
47797 - const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
47798 + const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
47799 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
47800
47801 dsin->sin_family = ssin->sin_family;
47802 @@ -300,7 +300,7 @@ static inline u32 rpc_get_scope_id(const
47803 if (sa->sa_family != AF_INET6)
47804 return 0;
47805
47806 - return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
47807 + return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
47808 }
47809
47810 #endif /* __KERNEL__ */
47811 diff -urNp linux-2.6.37/include/linux/suspend.h linux-2.6.37/include/linux/suspend.h
47812 --- linux-2.6.37/include/linux/suspend.h 2011-01-04 19:50:19.000000000 -0500
47813 +++ linux-2.6.37/include/linux/suspend.h 2011-01-17 02:41:02.000000000 -0500
47814 @@ -106,15 +106,15 @@ typedef int __bitwise suspend_state_t;
47815 * which require special recovery actions in that situation.
47816 */
47817 struct platform_suspend_ops {
47818 - int (*valid)(suspend_state_t state);
47819 - int (*begin)(suspend_state_t state);
47820 - int (*prepare)(void);
47821 - int (*prepare_late)(void);
47822 - int (*enter)(suspend_state_t state);
47823 - void (*wake)(void);
47824 - void (*finish)(void);
47825 - void (*end)(void);
47826 - void (*recover)(void);
47827 + int (* const valid)(suspend_state_t state);
47828 + int (* const begin)(suspend_state_t state);
47829 + int (* const prepare)(void);
47830 + int (* const prepare_late)(void);
47831 + int (* const enter)(suspend_state_t state);
47832 + void (* const wake)(void);
47833 + void (* const finish)(void);
47834 + void (* const end)(void);
47835 + void (* const recover)(void);
47836 };
47837
47838 #ifdef CONFIG_SUSPEND
47839 @@ -122,7 +122,7 @@ struct platform_suspend_ops {
47840 * suspend_set_ops - set platform dependent suspend operations
47841 * @ops: The new suspend operations to set.
47842 */
47843 -extern void suspend_set_ops(struct platform_suspend_ops *ops);
47844 +extern void suspend_set_ops(const struct platform_suspend_ops *ops);
47845 extern int suspend_valid_only_mem(suspend_state_t state);
47846
47847 /**
47848 @@ -147,7 +147,7 @@ extern int pm_suspend(suspend_state_t st
47849 #else /* !CONFIG_SUSPEND */
47850 #define suspend_valid_only_mem NULL
47851
47852 -static inline void suspend_set_ops(struct platform_suspend_ops *ops) {}
47853 +static inline void suspend_set_ops(const struct platform_suspend_ops *ops) {}
47854 static inline int pm_suspend(suspend_state_t state) { return -ENOSYS; }
47855 #endif /* !CONFIG_SUSPEND */
47856
47857 @@ -217,16 +217,16 @@ extern void mark_free_pages(struct zone
47858 * platforms which require special recovery actions in that situation.
47859 */
47860 struct platform_hibernation_ops {
47861 - int (*begin)(void);
47862 - void (*end)(void);
47863 - int (*pre_snapshot)(void);
47864 - void (*finish)(void);
47865 - int (*prepare)(void);
47866 - int (*enter)(void);
47867 - void (*leave)(void);
47868 - int (*pre_restore)(void);
47869 - void (*restore_cleanup)(void);
47870 - void (*recover)(void);
47871 + int (* const begin)(void);
47872 + void (* const end)(void);
47873 + int (* const pre_snapshot)(void);
47874 + void (* const finish)(void);
47875 + int (* const prepare)(void);
47876 + int (* const enter)(void);
47877 + void (* const leave)(void);
47878 + int (* const pre_restore)(void);
47879 + void (* const restore_cleanup)(void);
47880 + void (* const recover)(void);
47881 };
47882
47883 #ifdef CONFIG_HIBERNATION
47884 @@ -245,7 +245,7 @@ extern void swsusp_set_page_free(struct
47885 extern void swsusp_unset_page_free(struct page *);
47886 extern unsigned long get_safe_page(gfp_t gfp_mask);
47887
47888 -extern void hibernation_set_ops(struct platform_hibernation_ops *ops);
47889 +extern void hibernation_set_ops(const struct platform_hibernation_ops *ops);
47890 extern int hibernate(void);
47891 extern bool system_entering_hibernation(void);
47892 #else /* CONFIG_HIBERNATION */
47893 @@ -253,7 +253,7 @@ static inline int swsusp_page_is_forbidd
47894 static inline void swsusp_set_page_free(struct page *p) {}
47895 static inline void swsusp_unset_page_free(struct page *p) {}
47896
47897 -static inline void hibernation_set_ops(struct platform_hibernation_ops *ops) {}
47898 +static inline void hibernation_set_ops(const struct platform_hibernation_ops *ops) {}
47899 static inline int hibernate(void) { return -ENOSYS; }
47900 static inline bool system_entering_hibernation(void) { return false; }
47901 #endif /* CONFIG_HIBERNATION */
47902 diff -urNp linux-2.6.37/include/linux/sysctl.h linux-2.6.37/include/linux/sysctl.h
47903 --- linux-2.6.37/include/linux/sysctl.h 2011-01-04 19:50:19.000000000 -0500
47904 +++ linux-2.6.37/include/linux/sysctl.h 2011-01-17 02:41:02.000000000 -0500
47905 @@ -155,7 +155,11 @@ enum
47906 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
47907 };
47908
47909 -
47910 +#ifdef CONFIG_PAX_SOFTMODE
47911 +enum {
47912 + PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
47913 +};
47914 +#endif
47915
47916 /* CTL_VM names: */
47917 enum
47918 @@ -966,6 +970,8 @@ typedef int proc_handler (struct ctl_tab
47919
47920 extern int proc_dostring(struct ctl_table *, int,
47921 void __user *, size_t *, loff_t *);
47922 +extern int proc_dostring_modpriv(struct ctl_table *, int,
47923 + void __user *, size_t *, loff_t *);
47924 extern int proc_dointvec(struct ctl_table *, int,
47925 void __user *, size_t *, loff_t *);
47926 extern int proc_dointvec_minmax(struct ctl_table *, int,
47927 diff -urNp linux-2.6.37/include/linux/sysfs.h linux-2.6.37/include/linux/sysfs.h
47928 --- linux-2.6.37/include/linux/sysfs.h 2011-01-04 19:50:19.000000000 -0500
47929 +++ linux-2.6.37/include/linux/sysfs.h 2011-01-17 02:41:02.000000000 -0500
47930 @@ -110,8 +110,8 @@ struct bin_attribute {
47931 #define sysfs_bin_attr_init(bin_attr) sysfs_attr_init(&(bin_attr)->attr)
47932
47933 struct sysfs_ops {
47934 - ssize_t (*show)(struct kobject *, struct attribute *,char *);
47935 - ssize_t (*store)(struct kobject *,struct attribute *,const char *, size_t);
47936 + ssize_t (* const show)(struct kobject *, struct attribute *,char *);
47937 + ssize_t (* const store)(struct kobject *,struct attribute *,const char *, size_t);
47938 };
47939
47940 struct sysfs_dirent;
47941 diff -urNp linux-2.6.37/include/linux/tty.h linux-2.6.37/include/linux/tty.h
47942 --- linux-2.6.37/include/linux/tty.h 2011-01-04 19:50:19.000000000 -0500
47943 +++ linux-2.6.37/include/linux/tty.h 2011-01-17 02:41:02.000000000 -0500
47944 @@ -13,6 +13,8 @@
47945 #include <linux/tty_driver.h>
47946 #include <linux/tty_ldisc.h>
47947 #include <linux/mutex.h>
47948 +#include <linux/poll.h>
47949 +#include <linux/smp_lock.h>
47950
47951 #include <asm/system.h>
47952
47953 @@ -465,7 +467,6 @@ extern int tty_perform_flush(struct tty_
47954 extern dev_t tty_devnum(struct tty_struct *tty);
47955 extern void proc_clear_tty(struct task_struct *p);
47956 extern struct tty_struct *get_current_tty(void);
47957 -extern void tty_default_fops(struct file_operations *fops);
47958 extern struct tty_struct *alloc_tty_struct(void);
47959 extern int tty_add_file(struct tty_struct *tty, struct file *file);
47960 extern void free_tty_struct(struct tty_struct *tty);
47961 @@ -528,6 +529,18 @@ extern void tty_ldisc_begin(void);
47962 /* This last one is just for the tty layer internals and shouldn't be used elsewhere */
47963 extern void tty_ldisc_enable(struct tty_struct *tty);
47964
47965 +/* tty_io.c */
47966 +extern ssize_t tty_read(struct file *, char __user *, size_t, loff_t *);
47967 +extern ssize_t tty_write(struct file *, const char __user *, size_t, loff_t *);
47968 +extern unsigned int tty_poll(struct file *, poll_table *);
47969 +#ifdef CONFIG_COMPAT
47970 +extern long tty_compat_ioctl(struct file *file, unsigned int cmd,
47971 + unsigned long arg);
47972 +#else
47973 +#define tty_compat_ioctl NULL
47974 +#endif
47975 +extern int tty_release(struct inode *, struct file *);
47976 +extern int tty_fasync(int fd, struct file *filp, int on);
47977
47978 /* n_tty.c */
47979 extern struct tty_ldisc_ops tty_ldisc_N_TTY;
47980 diff -urNp linux-2.6.37/include/linux/tty_ldisc.h linux-2.6.37/include/linux/tty_ldisc.h
47981 --- linux-2.6.37/include/linux/tty_ldisc.h 2011-01-04 19:50:19.000000000 -0500
47982 +++ linux-2.6.37/include/linux/tty_ldisc.h 2011-01-17 02:41:02.000000000 -0500
47983 @@ -147,7 +147,7 @@ struct tty_ldisc_ops {
47984
47985 struct module *owner;
47986
47987 - int refcount;
47988 + atomic_t refcount;
47989 };
47990
47991 struct tty_ldisc {
47992 diff -urNp linux-2.6.37/include/linux/types.h linux-2.6.37/include/linux/types.h
47993 --- linux-2.6.37/include/linux/types.h 2011-01-04 19:50:19.000000000 -0500
47994 +++ linux-2.6.37/include/linux/types.h 2011-01-17 02:41:02.000000000 -0500
47995 @@ -207,10 +207,26 @@ typedef struct {
47996 int counter;
47997 } atomic_t;
47998
47999 +#ifdef CONFIG_PAX_REFCOUNT
48000 +typedef struct {
48001 + int counter;
48002 +} atomic_unchecked_t;
48003 +#else
48004 +typedef atomic_t atomic_unchecked_t;
48005 +#endif
48006 +
48007 #ifdef CONFIG_64BIT
48008 typedef struct {
48009 long counter;
48010 } atomic64_t;
48011 +
48012 +#ifdef CONFIG_PAX_REFCOUNT
48013 +typedef struct {
48014 + long counter;
48015 +} atomic64_unchecked_t;
48016 +#else
48017 +typedef atomic64_t atomic64_unchecked_t;
48018 +#endif
48019 #endif
48020
48021 struct list_head {
48022 diff -urNp linux-2.6.37/include/linux/u64_stats_sync.h linux-2.6.37/include/linux/u64_stats_sync.h
48023 --- linux-2.6.37/include/linux/u64_stats_sync.h 2011-01-04 19:50:19.000000000 -0500
48024 +++ linux-2.6.37/include/linux/u64_stats_sync.h 2011-01-17 02:41:02.000000000 -0500
48025 @@ -67,21 +67,21 @@ struct u64_stats_sync {
48026 #endif
48027 };
48028
48029 -static void inline u64_stats_update_begin(struct u64_stats_sync *syncp)
48030 +static inline void u64_stats_update_begin(struct u64_stats_sync *syncp)
48031 {
48032 #if BITS_PER_LONG==32 && defined(CONFIG_SMP)
48033 write_seqcount_begin(&syncp->seq);
48034 #endif
48035 }
48036
48037 -static void inline u64_stats_update_end(struct u64_stats_sync *syncp)
48038 +static inline void u64_stats_update_end(struct u64_stats_sync *syncp)
48039 {
48040 #if BITS_PER_LONG==32 && defined(CONFIG_SMP)
48041 write_seqcount_end(&syncp->seq);
48042 #endif
48043 }
48044
48045 -static unsigned int inline u64_stats_fetch_begin(const struct u64_stats_sync *syncp)
48046 +static inline unsigned int u64_stats_fetch_begin(const struct u64_stats_sync *syncp)
48047 {
48048 #if BITS_PER_LONG==32 && defined(CONFIG_SMP)
48049 return read_seqcount_begin(&syncp->seq);
48050 @@ -93,7 +93,7 @@ static unsigned int inline u64_stats_fet
48051 #endif
48052 }
48053
48054 -static bool inline u64_stats_fetch_retry(const struct u64_stats_sync *syncp,
48055 +static inline bool u64_stats_fetch_retry(const struct u64_stats_sync *syncp,
48056 unsigned int start)
48057 {
48058 #if BITS_PER_LONG==32 && defined(CONFIG_SMP)
48059 @@ -112,7 +112,7 @@ static bool inline u64_stats_fetch_retry
48060 * - UP 32bit must disable BH.
48061 * - 64bit have no problem atomically reading u64 values, irq safe.
48062 */
48063 -static unsigned int inline u64_stats_fetch_begin_bh(const struct u64_stats_sync *syncp)
48064 +static inline unsigned int u64_stats_fetch_begin_bh(const struct u64_stats_sync *syncp)
48065 {
48066 #if BITS_PER_LONG==32 && defined(CONFIG_SMP)
48067 return read_seqcount_begin(&syncp->seq);
48068 @@ -124,7 +124,7 @@ static unsigned int inline u64_stats_fet
48069 #endif
48070 }
48071
48072 -static bool inline u64_stats_fetch_retry_bh(const struct u64_stats_sync *syncp,
48073 +static inline bool u64_stats_fetch_retry_bh(const struct u64_stats_sync *syncp,
48074 unsigned int start)
48075 {
48076 #if BITS_PER_LONG==32 && defined(CONFIG_SMP)
48077 diff -urNp linux-2.6.37/include/linux/uaccess.h linux-2.6.37/include/linux/uaccess.h
48078 --- linux-2.6.37/include/linux/uaccess.h 2011-01-04 19:50:19.000000000 -0500
48079 +++ linux-2.6.37/include/linux/uaccess.h 2011-01-17 02:41:02.000000000 -0500
48080 @@ -76,11 +76,11 @@ static inline unsigned long __copy_from_
48081 long ret; \
48082 mm_segment_t old_fs = get_fs(); \
48083 \
48084 - set_fs(KERNEL_DS); \
48085 pagefault_disable(); \
48086 + set_fs(KERNEL_DS); \
48087 ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
48088 - pagefault_enable(); \
48089 set_fs(old_fs); \
48090 + pagefault_enable(); \
48091 ret; \
48092 })
48093
48094 @@ -93,8 +93,8 @@ static inline unsigned long __copy_from_
48095 * Safely read from address @src to the buffer at @dst. If a kernel fault
48096 * happens, handle that and return -EFAULT.
48097 */
48098 -extern long probe_kernel_read(void *dst, void *src, size_t size);
48099 -extern long __probe_kernel_read(void *dst, void *src, size_t size);
48100 +extern long probe_kernel_read(void *dst, const void *src, size_t size);
48101 +extern long __probe_kernel_read(void *dst, const void *src, size_t size);
48102
48103 /*
48104 * probe_kernel_write(): safely attempt to write to a location
48105 @@ -105,7 +105,7 @@ extern long __probe_kernel_read(void *ds
48106 * Safely write to address @dst from the buffer at @src. If a kernel fault
48107 * happens, handle that and return -EFAULT.
48108 */
48109 -extern long notrace probe_kernel_write(void *dst, void *src, size_t size);
48110 -extern long notrace __probe_kernel_write(void *dst, void *src, size_t size);
48111 +extern long notrace probe_kernel_write(void *dst, const void *src, size_t size);
48112 +extern long notrace __probe_kernel_write(void *dst, const void *src, size_t size);
48113
48114 #endif /* __LINUX_UACCESS_H__ */
48115 diff -urNp linux-2.6.37/include/linux/unaligned/access_ok.h linux-2.6.37/include/linux/unaligned/access_ok.h
48116 --- linux-2.6.37/include/linux/unaligned/access_ok.h 2011-01-04 19:50:19.000000000 -0500
48117 +++ linux-2.6.37/include/linux/unaligned/access_ok.h 2011-01-17 02:41:02.000000000 -0500
48118 @@ -6,32 +6,32 @@
48119
48120 static inline u16 get_unaligned_le16(const void *p)
48121 {
48122 - return le16_to_cpup((__le16 *)p);
48123 + return le16_to_cpup((const __le16 *)p);
48124 }
48125
48126 static inline u32 get_unaligned_le32(const void *p)
48127 {
48128 - return le32_to_cpup((__le32 *)p);
48129 + return le32_to_cpup((const __le32 *)p);
48130 }
48131
48132 static inline u64 get_unaligned_le64(const void *p)
48133 {
48134 - return le64_to_cpup((__le64 *)p);
48135 + return le64_to_cpup((const __le64 *)p);
48136 }
48137
48138 static inline u16 get_unaligned_be16(const void *p)
48139 {
48140 - return be16_to_cpup((__be16 *)p);
48141 + return be16_to_cpup((const __be16 *)p);
48142 }
48143
48144 static inline u32 get_unaligned_be32(const void *p)
48145 {
48146 - return be32_to_cpup((__be32 *)p);
48147 + return be32_to_cpup((const __be32 *)p);
48148 }
48149
48150 static inline u64 get_unaligned_be64(const void *p)
48151 {
48152 - return be64_to_cpup((__be64 *)p);
48153 + return be64_to_cpup((const __be64 *)p);
48154 }
48155
48156 static inline void put_unaligned_le16(u16 val, void *p)
48157 diff -urNp linux-2.6.37/include/linux/usb/hcd.h linux-2.6.37/include/linux/usb/hcd.h
48158 --- linux-2.6.37/include/linux/usb/hcd.h 2011-01-04 19:50:19.000000000 -0500
48159 +++ linux-2.6.37/include/linux/usb/hcd.h 2011-01-17 02:41:02.000000000 -0500
48160 @@ -580,7 +580,7 @@ struct usb_mon_operations {
48161 /* void (*urb_unlink)(struct usb_bus *bus, struct urb *urb); */
48162 };
48163
48164 -extern struct usb_mon_operations *mon_ops;
48165 +extern const struct usb_mon_operations *mon_ops;
48166
48167 static inline void usbmon_urb_submit(struct usb_bus *bus, struct urb *urb)
48168 {
48169 @@ -602,7 +602,7 @@ static inline void usbmon_urb_complete(s
48170 (*mon_ops->urb_complete)(bus, urb, status);
48171 }
48172
48173 -int usb_mon_register(struct usb_mon_operations *ops);
48174 +int usb_mon_register(const struct usb_mon_operations *ops);
48175 void usb_mon_deregister(void);
48176
48177 #else
48178 diff -urNp linux-2.6.37/include/linux/vmalloc.h linux-2.6.37/include/linux/vmalloc.h
48179 --- linux-2.6.37/include/linux/vmalloc.h 2011-01-04 19:50:19.000000000 -0500
48180 +++ linux-2.6.37/include/linux/vmalloc.h 2011-01-17 02:41:02.000000000 -0500
48181 @@ -13,6 +13,11 @@ struct vm_area_struct; /* vma defining
48182 #define VM_MAP 0x00000004 /* vmap()ed pages */
48183 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
48184 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
48185 +
48186 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
48187 +#define VM_KERNEXEC 0x00000020 /* allocate from executable kernel memory range */
48188 +#endif
48189 +
48190 /* bits [20..32] reserved for arch specific ioremap internals */
48191
48192 /*
48193 @@ -125,4 +130,103 @@ struct vm_struct **pcpu_get_vm_areas(con
48194 void pcpu_free_vm_areas(struct vm_struct **vms, int nr_vms);
48195 #endif
48196
48197 +#define vmalloc(x) \
48198 +({ \
48199 + void *___retval; \
48200 + intoverflow_t ___x = (intoverflow_t)x; \
48201 + if (WARN(___x > ULONG_MAX, "vmalloc size overflow\n")) \
48202 + ___retval = NULL; \
48203 + else \
48204 + ___retval = vmalloc((unsigned long)___x); \
48205 + ___retval; \
48206 +})
48207 +
48208 +#define vzalloc(x) \
48209 +({ \
48210 + void *___retval; \
48211 + intoverflow_t ___x = (intoverflow_t)x; \
48212 + if (WARN(___x > ULONG_MAX, "vzalloc size overflow\n")) \
48213 + ___retval = NULL; \
48214 + else \
48215 + ___retval = vzalloc((unsigned long)___x); \
48216 + ___retval; \
48217 +})
48218 +
48219 +#define __vmalloc(x, y, z) \
48220 +({ \
48221 + void *___retval; \
48222 + intoverflow_t ___x = (intoverflow_t)x; \
48223 + if (WARN(___x > ULONG_MAX, "__vmalloc size overflow\n"))\
48224 + ___retval = NULL; \
48225 + else \
48226 + ___retval = __vmalloc((unsigned long)___x, (y), (z));\
48227 + ___retval; \
48228 +})
48229 +
48230 +#define vmalloc_user(x) \
48231 +({ \
48232 + void *___retval; \
48233 + intoverflow_t ___x = (intoverflow_t)x; \
48234 + if (WARN(___x > ULONG_MAX, "vmalloc_user size overflow\n"))\
48235 + ___retval = NULL; \
48236 + else \
48237 + ___retval = vmalloc_user((unsigned long)___x); \
48238 + ___retval; \
48239 +})
48240 +
48241 +#define vmalloc_exec(x) \
48242 +({ \
48243 + void *___retval; \
48244 + intoverflow_t ___x = (intoverflow_t)x; \
48245 + if (WARN(___x > ULONG_MAX, "vmalloc_exec size overflow\n"))\
48246 + ___retval = NULL; \
48247 + else \
48248 + ___retval = vmalloc_exec((unsigned long)___x); \
48249 + ___retval; \
48250 +})
48251 +
48252 +#define vmalloc_node(x, y) \
48253 +({ \
48254 + void *___retval; \
48255 + intoverflow_t ___x = (intoverflow_t)x; \
48256 + if (WARN(___x > ULONG_MAX, "vmalloc_node size overflow\n"))\
48257 + ___retval = NULL; \
48258 + else \
48259 + ___retval = vmalloc_node((unsigned long)___x, (y));\
48260 + ___retval; \
48261 +})
48262 +
48263 +#define vzalloc_node(x, y) \
48264 +({ \
48265 + void *___retval; \
48266 + intoverflow_t ___x = (intoverflow_t)x; \
48267 + if (WARN(___x > ULONG_MAX, "vzalloc_node size overflow\n"))\
48268 + ___retval = NULL; \
48269 + else \
48270 + ___retval = vzalloc_node((unsigned long)___x, (y));\
48271 + ___retval; \
48272 +})
48273 +
48274 +#define vmalloc_32(x) \
48275 +({ \
48276 + void *___retval; \
48277 + intoverflow_t ___x = (intoverflow_t)x; \
48278 + if (WARN(___x > ULONG_MAX, "vmalloc_32 size overflow\n"))\
48279 + ___retval = NULL; \
48280 + else \
48281 + ___retval = vmalloc_32((unsigned long)___x); \
48282 + ___retval; \
48283 +})
48284 +
48285 +#define vmalloc_32_user(x) \
48286 +({ \
48287 +void *___retval; \
48288 + intoverflow_t ___x = (intoverflow_t)x; \
48289 + if (WARN(___x > ULONG_MAX, "vmalloc_32_user size overflow\n"))\
48290 + ___retval = NULL; \
48291 + else \
48292 + ___retval = vmalloc_32_user((unsigned long)___x);\
48293 + ___retval; \
48294 +})
48295 +
48296 #endif /* _LINUX_VMALLOC_H */
48297 diff -urNp linux-2.6.37/include/linux/vmstat.h linux-2.6.37/include/linux/vmstat.h
48298 --- linux-2.6.37/include/linux/vmstat.h 2011-01-04 19:50:19.000000000 -0500
48299 +++ linux-2.6.37/include/linux/vmstat.h 2011-01-17 02:41:02.000000000 -0500
48300 @@ -140,18 +140,18 @@ static inline void vm_events_fold_cpu(in
48301 /*
48302 * Zone based page accounting with per cpu differentials.
48303 */
48304 -extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
48305 +extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
48306
48307 static inline void zone_page_state_add(long x, struct zone *zone,
48308 enum zone_stat_item item)
48309 {
48310 - atomic_long_add(x, &zone->vm_stat[item]);
48311 - atomic_long_add(x, &vm_stat[item]);
48312 + atomic_long_add_unchecked(x, &zone->vm_stat[item]);
48313 + atomic_long_add_unchecked(x, &vm_stat[item]);
48314 }
48315
48316 static inline unsigned long global_page_state(enum zone_stat_item item)
48317 {
48318 - long x = atomic_long_read(&vm_stat[item]);
48319 + long x = atomic_long_read_unchecked(&vm_stat[item]);
48320 #ifdef CONFIG_SMP
48321 if (x < 0)
48322 x = 0;
48323 @@ -162,7 +162,7 @@ static inline unsigned long global_page_
48324 static inline unsigned long zone_page_state(struct zone *zone,
48325 enum zone_stat_item item)
48326 {
48327 - long x = atomic_long_read(&zone->vm_stat[item]);
48328 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
48329 #ifdef CONFIG_SMP
48330 if (x < 0)
48331 x = 0;
48332 @@ -179,7 +179,7 @@ static inline unsigned long zone_page_st
48333 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
48334 enum zone_stat_item item)
48335 {
48336 - long x = atomic_long_read(&zone->vm_stat[item]);
48337 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
48338
48339 #ifdef CONFIG_SMP
48340 int cpu;
48341 @@ -268,8 +268,8 @@ static inline void __mod_zone_page_state
48342
48343 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
48344 {
48345 - atomic_long_inc(&zone->vm_stat[item]);
48346 - atomic_long_inc(&vm_stat[item]);
48347 + atomic_long_inc_unchecked(&zone->vm_stat[item]);
48348 + atomic_long_inc_unchecked(&vm_stat[item]);
48349 }
48350
48351 static inline void __inc_zone_page_state(struct page *page,
48352 @@ -280,8 +280,8 @@ static inline void __inc_zone_page_state
48353
48354 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
48355 {
48356 - atomic_long_dec(&zone->vm_stat[item]);
48357 - atomic_long_dec(&vm_stat[item]);
48358 + atomic_long_dec_unchecked(&zone->vm_stat[item]);
48359 + atomic_long_dec_unchecked(&vm_stat[item]);
48360 }
48361
48362 static inline void __dec_zone_page_state(struct page *page,
48363 diff -urNp linux-2.6.37/include/net/inetpeer.h linux-2.6.37/include/net/inetpeer.h
48364 --- linux-2.6.37/include/net/inetpeer.h 2011-01-04 19:50:19.000000000 -0500
48365 +++ linux-2.6.37/include/net/inetpeer.h 2011-01-17 02:41:02.000000000 -0500
48366 @@ -30,8 +30,8 @@ struct inet_peer {
48367 */
48368 union {
48369 struct {
48370 - atomic_t rid; /* Frag reception counter */
48371 - atomic_t ip_id_count; /* IP ID for the next packet */
48372 + atomic_unchecked_t rid; /* Frag reception counter */
48373 + atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
48374 __u32 tcp_ts;
48375 __u32 tcp_ts_stamp;
48376 };
48377 @@ -62,7 +62,7 @@ static inline __u16 inet_getid(struct in
48378 {
48379 more++;
48380 inet_peer_refcheck(p);
48381 - return atomic_add_return(more, &p->ip_id_count) - more;
48382 + return atomic_add_return_unchecked(more, &p->ip_id_count) - more;
48383 }
48384
48385 #endif /* _NET_INETPEER_H */
48386 diff -urNp linux-2.6.37/include/net/irda/ircomm_tty.h linux-2.6.37/include/net/irda/ircomm_tty.h
48387 --- linux-2.6.37/include/net/irda/ircomm_tty.h 2011-01-04 19:50:19.000000000 -0500
48388 +++ linux-2.6.37/include/net/irda/ircomm_tty.h 2011-01-17 02:41:02.000000000 -0500
48389 @@ -105,8 +105,8 @@ struct ircomm_tty_cb {
48390 unsigned short close_delay;
48391 unsigned short closing_wait; /* time to wait before closing */
48392
48393 - int open_count;
48394 - int blocked_open; /* # of blocked opens */
48395 + atomic_t open_count;
48396 + atomic_t blocked_open; /* # of blocked opens */
48397
48398 /* Protect concurent access to :
48399 * o self->open_count
48400 diff -urNp linux-2.6.37/include/net/neighbour.h linux-2.6.37/include/net/neighbour.h
48401 --- linux-2.6.37/include/net/neighbour.h 2011-01-04 19:50:19.000000000 -0500
48402 +++ linux-2.6.37/include/net/neighbour.h 2011-01-17 02:41:02.000000000 -0500
48403 @@ -118,12 +118,12 @@ struct neighbour {
48404
48405 struct neigh_ops {
48406 int family;
48407 - void (*solicit)(struct neighbour *, struct sk_buff*);
48408 - void (*error_report)(struct neighbour *, struct sk_buff*);
48409 - int (*output)(struct sk_buff*);
48410 - int (*connected_output)(struct sk_buff*);
48411 - int (*hh_output)(struct sk_buff*);
48412 - int (*queue_xmit)(struct sk_buff*);
48413 + void (* const solicit)(struct neighbour *, struct sk_buff*);
48414 + void (* const error_report)(struct neighbour *, struct sk_buff*);
48415 + int (* const output)(struct sk_buff*);
48416 + int (* const connected_output)(struct sk_buff*);
48417 + int (* const hh_output)(struct sk_buff*);
48418 + int (* const queue_xmit)(struct sk_buff*);
48419 };
48420
48421 struct pneigh_entry {
48422 diff -urNp linux-2.6.37/include/net/netlink.h linux-2.6.37/include/net/netlink.h
48423 --- linux-2.6.37/include/net/netlink.h 2011-01-04 19:50:19.000000000 -0500
48424 +++ linux-2.6.37/include/net/netlink.h 2011-01-17 02:41:02.000000000 -0500
48425 @@ -558,7 +558,7 @@ static inline void *nlmsg_get_pos(struct
48426 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
48427 {
48428 if (mark)
48429 - skb_trim(skb, (unsigned char *) mark - skb->data);
48430 + skb_trim(skb, (const unsigned char *) mark - skb->data);
48431 }
48432
48433 /**
48434 diff -urNp linux-2.6.37/include/net/sctp/sctp.h linux-2.6.37/include/net/sctp/sctp.h
48435 --- linux-2.6.37/include/net/sctp/sctp.h 2011-01-04 19:50:19.000000000 -0500
48436 +++ linux-2.6.37/include/net/sctp/sctp.h 2011-01-17 02:41:02.000000000 -0500
48437 @@ -316,9 +316,9 @@ do { \
48438
48439 #else /* SCTP_DEBUG */
48440
48441 -#define SCTP_DEBUG_PRINTK(whatever...)
48442 -#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
48443 -#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
48444 +#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
48445 +#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
48446 +#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
48447 #define SCTP_ENABLE_DEBUG
48448 #define SCTP_DISABLE_DEBUG
48449 #define SCTP_ASSERT(expr, str, func)
48450 diff -urNp linux-2.6.37/include/net/tcp.h linux-2.6.37/include/net/tcp.h
48451 --- linux-2.6.37/include/net/tcp.h 2011-01-04 19:50:19.000000000 -0500
48452 +++ linux-2.6.37/include/net/tcp.h 2011-01-17 02:41:02.000000000 -0500
48453 @@ -1380,6 +1380,7 @@ enum tcp_seq_states {
48454 struct tcp_seq_afinfo {
48455 char *name;
48456 sa_family_t family;
48457 + /* cannot be const */
48458 struct file_operations seq_fops;
48459 struct seq_operations seq_ops;
48460 };
48461 diff -urNp linux-2.6.37/include/net/udp.h linux-2.6.37/include/net/udp.h
48462 --- linux-2.6.37/include/net/udp.h 2011-01-04 19:50:19.000000000 -0500
48463 +++ linux-2.6.37/include/net/udp.h 2011-01-17 02:41:02.000000000 -0500
48464 @@ -223,6 +223,7 @@ struct udp_seq_afinfo {
48465 char *name;
48466 sa_family_t family;
48467 struct udp_table *udp_table;
48468 + /* cannot be const */
48469 struct file_operations seq_fops;
48470 struct seq_operations seq_ops;
48471 };
48472 diff -urNp linux-2.6.37/include/sound/ac97_codec.h linux-2.6.37/include/sound/ac97_codec.h
48473 --- linux-2.6.37/include/sound/ac97_codec.h 2011-01-04 19:50:19.000000000 -0500
48474 +++ linux-2.6.37/include/sound/ac97_codec.h 2011-01-17 02:41:02.000000000 -0500
48475 @@ -419,15 +419,15 @@
48476 struct snd_ac97;
48477
48478 struct snd_ac97_build_ops {
48479 - int (*build_3d) (struct snd_ac97 *ac97);
48480 - int (*build_specific) (struct snd_ac97 *ac97);
48481 - int (*build_spdif) (struct snd_ac97 *ac97);
48482 - int (*build_post_spdif) (struct snd_ac97 *ac97);
48483 + int (* const build_3d) (struct snd_ac97 *ac97);
48484 + int (* const build_specific) (struct snd_ac97 *ac97);
48485 + int (* const build_spdif) (struct snd_ac97 *ac97);
48486 + int (* const build_post_spdif) (struct snd_ac97 *ac97);
48487 #ifdef CONFIG_PM
48488 - void (*suspend) (struct snd_ac97 *ac97);
48489 - void (*resume) (struct snd_ac97 *ac97);
48490 + void (* const suspend) (struct snd_ac97 *ac97);
48491 + void (* const resume) (struct snd_ac97 *ac97);
48492 #endif
48493 - void (*update_jacks) (struct snd_ac97 *ac97); /* for jack-sharing */
48494 + void (* const update_jacks) (struct snd_ac97 *ac97); /* for jack-sharing */
48495 };
48496
48497 struct snd_ac97_bus_ops {
48498 @@ -477,7 +477,7 @@ struct snd_ac97_template {
48499
48500 struct snd_ac97 {
48501 /* -- lowlevel (hardware) driver specific -- */
48502 - struct snd_ac97_build_ops * build_ops;
48503 + const struct snd_ac97_build_ops * build_ops;
48504 void *private_data;
48505 void (*private_free) (struct snd_ac97 *ac97);
48506 /* --- */
48507 diff -urNp linux-2.6.37/include/trace/events/irq.h linux-2.6.37/include/trace/events/irq.h
48508 --- linux-2.6.37/include/trace/events/irq.h 2011-01-04 19:50:19.000000000 -0500
48509 +++ linux-2.6.37/include/trace/events/irq.h 2011-01-17 02:41:02.000000000 -0500
48510 @@ -36,7 +36,7 @@ struct softirq_action;
48511 */
48512 TRACE_EVENT(irq_handler_entry,
48513
48514 - TP_PROTO(int irq, struct irqaction *action),
48515 + TP_PROTO(int irq, const struct irqaction *action),
48516
48517 TP_ARGS(irq, action),
48518
48519 @@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
48520 */
48521 TRACE_EVENT(irq_handler_exit,
48522
48523 - TP_PROTO(int irq, struct irqaction *action, int ret),
48524 + TP_PROTO(int irq, const struct irqaction *action, int ret),
48525
48526 TP_ARGS(irq, action, ret),
48527
48528 diff -urNp linux-2.6.37/include/video/uvesafb.h linux-2.6.37/include/video/uvesafb.h
48529 --- linux-2.6.37/include/video/uvesafb.h 2011-01-04 19:50:19.000000000 -0500
48530 +++ linux-2.6.37/include/video/uvesafb.h 2011-01-17 02:41:02.000000000 -0500
48531 @@ -177,6 +177,7 @@ struct uvesafb_par {
48532 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
48533 u8 pmi_setpal; /* PMI for palette changes */
48534 u16 *pmi_base; /* protected mode interface location */
48535 + u8 *pmi_code; /* protected mode code location */
48536 void *pmi_start;
48537 void *pmi_pal;
48538 u8 *vbe_state_orig; /*
48539 diff -urNp linux-2.6.37/init/do_mounts.c linux-2.6.37/init/do_mounts.c
48540 --- linux-2.6.37/init/do_mounts.c 2011-01-04 19:50:19.000000000 -0500
48541 +++ linux-2.6.37/init/do_mounts.c 2011-01-17 02:41:02.000000000 -0500
48542 @@ -287,7 +287,7 @@ static void __init get_fs_names(char *pa
48543
48544 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
48545 {
48546 - int err = sys_mount(name, "/root", fs, flags, data);
48547 + int err = sys_mount((__force char __user *)name, (__force char __user *)"/root", (__force char __user *)fs, flags, (__force void __user *)data);
48548 if (err)
48549 return err;
48550
48551 @@ -382,18 +382,18 @@ void __init change_floppy(char *fmt, ...
48552 va_start(args, fmt);
48553 vsprintf(buf, fmt, args);
48554 va_end(args);
48555 - fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
48556 + fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
48557 if (fd >= 0) {
48558 sys_ioctl(fd, FDEJECT, 0);
48559 sys_close(fd);
48560 }
48561 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
48562 - fd = sys_open("/dev/console", O_RDWR, 0);
48563 + fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
48564 if (fd >= 0) {
48565 sys_ioctl(fd, TCGETS, (long)&termios);
48566 termios.c_lflag &= ~ICANON;
48567 sys_ioctl(fd, TCSETSF, (long)&termios);
48568 - sys_read(fd, &c, 1);
48569 + sys_read(fd, (char __user *)&c, 1);
48570 termios.c_lflag |= ICANON;
48571 sys_ioctl(fd, TCSETSF, (long)&termios);
48572 sys_close(fd);
48573 @@ -487,6 +487,6 @@ void __init prepare_namespace(void)
48574 mount_root();
48575 out:
48576 devtmpfs_mount("dev");
48577 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
48578 + sys_mount((__force char __user *)".", (__force char __user *)"/", NULL, MS_MOVE, NULL);
48579 sys_chroot((const char __user __force *)".");
48580 }
48581 diff -urNp linux-2.6.37/init/do_mounts.h linux-2.6.37/init/do_mounts.h
48582 --- linux-2.6.37/init/do_mounts.h 2011-01-04 19:50:19.000000000 -0500
48583 +++ linux-2.6.37/init/do_mounts.h 2011-01-17 02:41:02.000000000 -0500
48584 @@ -15,15 +15,15 @@ extern int root_mountflags;
48585
48586 static inline int create_dev(char *name, dev_t dev)
48587 {
48588 - sys_unlink(name);
48589 - return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
48590 + sys_unlink((__force char __user *)name);
48591 + return sys_mknod((__force char __user *)name, S_IFBLK|0600, new_encode_dev(dev));
48592 }
48593
48594 #if BITS_PER_LONG == 32
48595 static inline u32 bstat(char *name)
48596 {
48597 struct stat64 stat;
48598 - if (sys_stat64(name, &stat) != 0)
48599 + if (sys_stat64((__force char __user *)name, (__force struct stat64 __user *)&stat) != 0)
48600 return 0;
48601 if (!S_ISBLK(stat.st_mode))
48602 return 0;
48603 diff -urNp linux-2.6.37/init/do_mounts_initrd.c linux-2.6.37/init/do_mounts_initrd.c
48604 --- linux-2.6.37/init/do_mounts_initrd.c 2011-01-04 19:50:19.000000000 -0500
48605 +++ linux-2.6.37/init/do_mounts_initrd.c 2011-01-17 02:41:02.000000000 -0500
48606 @@ -44,13 +44,13 @@ static void __init handle_initrd(void)
48607 create_dev("/dev/root.old", Root_RAM0);
48608 /* mount initrd on rootfs' /root */
48609 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
48610 - sys_mkdir("/old", 0700);
48611 - root_fd = sys_open("/", 0, 0);
48612 - old_fd = sys_open("/old", 0, 0);
48613 + sys_mkdir((__force const char __user *)"/old", 0700);
48614 + root_fd = sys_open((__force const char __user *)"/", 0, 0);
48615 + old_fd = sys_open((__force const char __user *)"/old", 0, 0);
48616 /* move initrd over / and chdir/chroot in initrd root */
48617 - sys_chdir("/root");
48618 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
48619 - sys_chroot(".");
48620 + sys_chdir((__force const char __user *)"/root");
48621 + sys_mount((__force char __user *)".", (__force char __user *)"/", NULL, MS_MOVE, NULL);
48622 + sys_chroot((__force const char __user *)".");
48623
48624 /*
48625 * In case that a resume from disk is carried out by linuxrc or one of
48626 @@ -67,15 +67,15 @@ static void __init handle_initrd(void)
48627
48628 /* move initrd to rootfs' /old */
48629 sys_fchdir(old_fd);
48630 - sys_mount("/", ".", NULL, MS_MOVE, NULL);
48631 + sys_mount((__force char __user *)"/", (__force char __user *)".", NULL, MS_MOVE, NULL);
48632 /* switch root and cwd back to / of rootfs */
48633 sys_fchdir(root_fd);
48634 - sys_chroot(".");
48635 + sys_chroot((__force const char __user *)".");
48636 sys_close(old_fd);
48637 sys_close(root_fd);
48638
48639 if (new_decode_dev(real_root_dev) == Root_RAM0) {
48640 - sys_chdir("/old");
48641 + sys_chdir((__force const char __user *)"/old");
48642 return;
48643 }
48644
48645 @@ -83,17 +83,17 @@ static void __init handle_initrd(void)
48646 mount_root();
48647
48648 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
48649 - error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
48650 + error = sys_mount((__force char __user *)"/old", (__force char __user *)"/root/initrd", NULL, MS_MOVE, NULL);
48651 if (!error)
48652 printk("okay\n");
48653 else {
48654 - int fd = sys_open("/dev/root.old", O_RDWR, 0);
48655 + int fd = sys_open((__force const char __user *)"/dev/root.old", O_RDWR, 0);
48656 if (error == -ENOENT)
48657 printk("/initrd does not exist. Ignored.\n");
48658 else
48659 printk("failed\n");
48660 printk(KERN_NOTICE "Unmounting old root\n");
48661 - sys_umount("/old", MNT_DETACH);
48662 + sys_umount((__force char __user *)"/old", MNT_DETACH);
48663 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
48664 if (fd < 0) {
48665 error = fd;
48666 @@ -116,11 +116,11 @@ int __init initrd_load(void)
48667 * mounted in the normal path.
48668 */
48669 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
48670 - sys_unlink("/initrd.image");
48671 + sys_unlink((__force const char __user *)"/initrd.image");
48672 handle_initrd();
48673 return 1;
48674 }
48675 }
48676 - sys_unlink("/initrd.image");
48677 + sys_unlink((__force const char __user *)"/initrd.image");
48678 return 0;
48679 }
48680 diff -urNp linux-2.6.37/init/do_mounts_md.c linux-2.6.37/init/do_mounts_md.c
48681 --- linux-2.6.37/init/do_mounts_md.c 2011-01-04 19:50:19.000000000 -0500
48682 +++ linux-2.6.37/init/do_mounts_md.c 2011-01-17 02:41:02.000000000 -0500
48683 @@ -170,7 +170,7 @@ static void __init md_setup_drive(void)
48684 partitioned ? "_d" : "", minor,
48685 md_setup_args[ent].device_names);
48686
48687 - fd = sys_open(name, 0, 0);
48688 + fd = sys_open((__force char __user *)name, 0, 0);
48689 if (fd < 0) {
48690 printk(KERN_ERR "md: open failed - cannot start "
48691 "array %s\n", name);
48692 @@ -233,7 +233,7 @@ static void __init md_setup_drive(void)
48693 * array without it
48694 */
48695 sys_close(fd);
48696 - fd = sys_open(name, 0, 0);
48697 + fd = sys_open((__force char __user *)name, 0, 0);
48698 sys_ioctl(fd, BLKRRPART, 0);
48699 }
48700 sys_close(fd);
48701 diff -urNp linux-2.6.37/init/initramfs.c linux-2.6.37/init/initramfs.c
48702 --- linux-2.6.37/init/initramfs.c 2011-01-04 19:50:19.000000000 -0500
48703 +++ linux-2.6.37/init/initramfs.c 2011-01-17 02:41:02.000000000 -0500
48704 @@ -74,7 +74,7 @@ static void __init free_hash(void)
48705 }
48706 }
48707
48708 -static long __init do_utime(char __user *filename, time_t mtime)
48709 +static long __init do_utime(__force char __user *filename, time_t mtime)
48710 {
48711 struct timespec t[2];
48712
48713 @@ -109,7 +109,7 @@ static void __init dir_utime(void)
48714 struct dir_entry *de, *tmp;
48715 list_for_each_entry_safe(de, tmp, &dir_list, list) {
48716 list_del(&de->list);
48717 - do_utime(de->name, de->mtime);
48718 + do_utime((__force char __user *)de->name, de->mtime);
48719 kfree(de->name);
48720 kfree(de);
48721 }
48722 @@ -271,7 +271,7 @@ static int __init maybe_link(void)
48723 if (nlink >= 2) {
48724 char *old = find_link(major, minor, ino, mode, collected);
48725 if (old)
48726 - return (sys_link(old, collected) < 0) ? -1 : 1;
48727 + return (sys_link((__force char __user *)old, (__force char __user *)collected) < 0) ? -1 : 1;
48728 }
48729 return 0;
48730 }
48731 @@ -280,11 +280,11 @@ static void __init clean_path(char *path
48732 {
48733 struct stat st;
48734
48735 - if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
48736 + if (!sys_newlstat((__force char __user *)path, (__force struct stat __user *)&st) && (st.st_mode^mode) & S_IFMT) {
48737 if (S_ISDIR(st.st_mode))
48738 - sys_rmdir(path);
48739 + sys_rmdir((__force char __user *)path);
48740 else
48741 - sys_unlink(path);
48742 + sys_unlink((__force char __user *)path);
48743 }
48744 }
48745
48746 @@ -305,7 +305,7 @@ static int __init do_name(void)
48747 int openflags = O_WRONLY|O_CREAT;
48748 if (ml != 1)
48749 openflags |= O_TRUNC;
48750 - wfd = sys_open(collected, openflags, mode);
48751 + wfd = sys_open((__force char __user *)collected, openflags, mode);
48752
48753 if (wfd >= 0) {
48754 sys_fchown(wfd, uid, gid);
48755 @@ -317,17 +317,17 @@ static int __init do_name(void)
48756 }
48757 }
48758 } else if (S_ISDIR(mode)) {
48759 - sys_mkdir(collected, mode);
48760 - sys_chown(collected, uid, gid);
48761 - sys_chmod(collected, mode);
48762 + sys_mkdir((__force char __user *)collected, mode);
48763 + sys_chown((__force char __user *)collected, uid, gid);
48764 + sys_chmod((__force char __user *)collected, mode);
48765 dir_add(collected, mtime);
48766 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
48767 S_ISFIFO(mode) || S_ISSOCK(mode)) {
48768 if (maybe_link() == 0) {
48769 - sys_mknod(collected, mode, rdev);
48770 - sys_chown(collected, uid, gid);
48771 - sys_chmod(collected, mode);
48772 - do_utime(collected, mtime);
48773 + sys_mknod((__force char __user *)collected, mode, rdev);
48774 + sys_chown((__force char __user *)collected, uid, gid);
48775 + sys_chmod((__force char __user *)collected, mode);
48776 + do_utime((__force char __user *)collected, mtime);
48777 }
48778 }
48779 return 0;
48780 @@ -336,15 +336,15 @@ static int __init do_name(void)
48781 static int __init do_copy(void)
48782 {
48783 if (count >= body_len) {
48784 - sys_write(wfd, victim, body_len);
48785 + sys_write(wfd, (__force char __user *)victim, body_len);
48786 sys_close(wfd);
48787 - do_utime(vcollected, mtime);
48788 + do_utime((__force char __user *)vcollected, mtime);
48789 kfree(vcollected);
48790 eat(body_len);
48791 state = SkipIt;
48792 return 0;
48793 } else {
48794 - sys_write(wfd, victim, count);
48795 + sys_write(wfd, (__force char __user *)victim, count);
48796 body_len -= count;
48797 eat(count);
48798 return 1;
48799 @@ -355,9 +355,9 @@ static int __init do_symlink(void)
48800 {
48801 collected[N_ALIGN(name_len) + body_len] = '\0';
48802 clean_path(collected, 0);
48803 - sys_symlink(collected + N_ALIGN(name_len), collected);
48804 - sys_lchown(collected, uid, gid);
48805 - do_utime(collected, mtime);
48806 + sys_symlink((__force char __user *)collected + N_ALIGN(name_len), (__force char __user *)collected);
48807 + sys_lchown((__force char __user *)collected, uid, gid);
48808 + do_utime((__force char __user *)collected, mtime);
48809 state = SkipIt;
48810 next_state = Reset;
48811 return 0;
48812 diff -urNp linux-2.6.37/init/Kconfig linux-2.6.37/init/Kconfig
48813 --- linux-2.6.37/init/Kconfig 2011-01-04 19:50:19.000000000 -0500
48814 +++ linux-2.6.37/init/Kconfig 2011-01-17 02:41:02.000000000 -0500
48815 @@ -1108,7 +1108,7 @@ config SLUB_DEBUG
48816
48817 config COMPAT_BRK
48818 bool "Disable heap randomization"
48819 - default y
48820 + default n
48821 help
48822 Randomizing heap placement makes heap exploits harder, but it
48823 also breaks ancient binaries (including anything libc5 based).
48824 diff -urNp linux-2.6.37/init/main.c linux-2.6.37/init/main.c
48825 --- linux-2.6.37/init/main.c 2011-01-04 19:50:19.000000000 -0500
48826 +++ linux-2.6.37/init/main.c 2011-01-17 02:41:02.000000000 -0500
48827 @@ -94,6 +94,7 @@ static inline void mark_rodata_ro(void)
48828 #ifdef CONFIG_TC
48829 extern void tc_init(void);
48830 #endif
48831 +extern void grsecurity_init(void);
48832
48833 enum system_states system_state __read_mostly;
48834 EXPORT_SYMBOL(system_state);
48835 @@ -196,6 +197,47 @@ static int __init set_reset_devices(char
48836
48837 __setup("reset_devices", set_reset_devices);
48838
48839 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
48840 +extern char pax_enter_kernel_user[];
48841 +extern char pax_exit_kernel_user[];
48842 +extern pgdval_t clone_pgd_mask;
48843 +#endif
48844 +
48845 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
48846 +static int __init setup_pax_nouderef(char *str)
48847 +{
48848 +#ifdef CONFIG_X86_32
48849 + unsigned int cpu;
48850 +
48851 + for (cpu = 0; cpu < NR_CPUS; cpu++) {
48852 + get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_DS].type = 3;
48853 + get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_DS].limit = 0xf;
48854 + get_cpu_gdt_table(cpu)[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
48855 + get_cpu_gdt_table(cpu)[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
48856 + }
48857 + asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r" (__KERNEL_DS) : "memory");
48858 +#else
48859 + memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
48860 + memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
48861 + clone_pgd_mask = ~(pgdval_t)0UL;
48862 +#endif
48863 +
48864 + return 0;
48865 +}
48866 +early_param("pax_nouderef", setup_pax_nouderef);
48867 +#endif
48868 +
48869 +#ifdef CONFIG_PAX_SOFTMODE
48870 +unsigned int pax_softmode;
48871 +
48872 +static int __init setup_pax_softmode(char *str)
48873 +{
48874 + get_option(&str, &pax_softmode);
48875 + return 1;
48876 +}
48877 +__setup("pax_softmode=", setup_pax_softmode);
48878 +#endif
48879 +
48880 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
48881 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
48882 static const char *panic_later, *panic_param;
48883 @@ -740,6 +782,7 @@ int __init_or_module do_one_initcall(ini
48884 {
48885 int count = preempt_count();
48886 int ret;
48887 + const char *msg1 = "", *msg2 = "";
48888
48889 if (initcall_debug)
48890 ret = do_one_initcall_debug(fn);
48891 @@ -752,15 +795,15 @@ int __init_or_module do_one_initcall(ini
48892 sprintf(msgbuf, "error code %d ", ret);
48893
48894 if (preempt_count() != count) {
48895 - strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
48896 + msg1 = " preemption imbalance";
48897 preempt_count() = count;
48898 }
48899 if (irqs_disabled()) {
48900 - strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
48901 + msg2 = " disabled interrupts";
48902 local_irq_enable();
48903 }
48904 - if (msgbuf[0]) {
48905 - printk("initcall %pF returned with %s\n", fn, msgbuf);
48906 + if (msgbuf[0] || *msg1 || *msg2) {
48907 + printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
48908 }
48909
48910 return ret;
48911 @@ -889,7 +932,7 @@ static int __init kernel_init(void * unu
48912 do_basic_setup();
48913
48914 /* Open the /dev/console on the rootfs, this should never fail */
48915 - if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
48916 + if (sys_open((__force const char __user *) "/dev/console", O_RDWR, 0) < 0)
48917 printk(KERN_WARNING "Warning: unable to open an initial console.\n");
48918
48919 (void) sys_dup(0);
48920 @@ -902,11 +945,13 @@ static int __init kernel_init(void * unu
48921 if (!ramdisk_execute_command)
48922 ramdisk_execute_command = "/init";
48923
48924 - if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
48925 + if (sys_access((__force const char __user *) ramdisk_execute_command, 0) != 0) {
48926 ramdisk_execute_command = NULL;
48927 prepare_namespace();
48928 }
48929
48930 + grsecurity_init();
48931 +
48932 /*
48933 * Ok, we have completed the initial bootup, and
48934 * we're essentially up and running. Get rid of the
48935 diff -urNp linux-2.6.37/ipc/mqueue.c linux-2.6.37/ipc/mqueue.c
48936 --- linux-2.6.37/ipc/mqueue.c 2011-01-04 19:50:19.000000000 -0500
48937 +++ linux-2.6.37/ipc/mqueue.c 2011-01-17 02:41:02.000000000 -0500
48938 @@ -154,6 +154,7 @@ static struct inode *mqueue_get_inode(st
48939 mq_bytes = (mq_msg_tblsz +
48940 (info->attr.mq_maxmsg * info->attr.mq_msgsize));
48941
48942 + gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
48943 spin_lock(&mq_lock);
48944 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
48945 u->mq_bytes + mq_bytes >
48946 diff -urNp linux-2.6.37/ipc/shm.c linux-2.6.37/ipc/shm.c
48947 --- linux-2.6.37/ipc/shm.c 2011-01-04 19:50:19.000000000 -0500
48948 +++ linux-2.6.37/ipc/shm.c 2011-01-17 02:41:02.000000000 -0500
48949 @@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_name
48950 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
48951 #endif
48952
48953 +#ifdef CONFIG_GRKERNSEC
48954 +extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
48955 + const time_t shm_createtime, const uid_t cuid,
48956 + const int shmid);
48957 +extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
48958 + const time_t shm_createtime);
48959 +#endif
48960 +
48961 void shm_init_ns(struct ipc_namespace *ns)
48962 {
48963 ns->shm_ctlmax = SHMMAX;
48964 @@ -401,6 +409,14 @@ static int newseg(struct ipc_namespace *
48965 shp->shm_lprid = 0;
48966 shp->shm_atim = shp->shm_dtim = 0;
48967 shp->shm_ctim = get_seconds();
48968 +#ifdef CONFIG_GRKERNSEC
48969 + {
48970 + struct timespec timeval;
48971 + do_posix_clock_monotonic_gettime(&timeval);
48972 +
48973 + shp->shm_createtime = timeval.tv_sec;
48974 + }
48975 +#endif
48976 shp->shm_segsz = size;
48977 shp->shm_nattch = 0;
48978 shp->shm_file = file;
48979 @@ -895,9 +911,21 @@ long do_shmat(int shmid, char __user *sh
48980 if (err)
48981 goto out_unlock;
48982
48983 +#ifdef CONFIG_GRKERNSEC
48984 + if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
48985 + shp->shm_perm.cuid, shmid) ||
48986 + !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
48987 + err = -EACCES;
48988 + goto out_unlock;
48989 + }
48990 +#endif
48991 +
48992 path = shp->shm_file->f_path;
48993 path_get(&path);
48994 shp->shm_nattch++;
48995 +#ifdef CONFIG_GRKERNSEC
48996 + shp->shm_lapid = current->pid;
48997 +#endif
48998 size = i_size_read(path.dentry->d_inode);
48999 shm_unlock(shp);
49000
49001 diff -urNp linux-2.6.37/kernel/acct.c linux-2.6.37/kernel/acct.c
49002 --- linux-2.6.37/kernel/acct.c 2011-01-04 19:50:19.000000000 -0500
49003 +++ linux-2.6.37/kernel/acct.c 2011-01-17 02:41:02.000000000 -0500
49004 @@ -570,7 +570,7 @@ static void do_acct_process(struct bsd_a
49005 */
49006 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
49007 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
49008 - file->f_op->write(file, (char *)&ac,
49009 + file->f_op->write(file, (__force char __user *)&ac,
49010 sizeof(acct_t), &file->f_pos);
49011 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
49012 set_fs(fs);
49013 diff -urNp linux-2.6.37/kernel/capability.c linux-2.6.37/kernel/capability.c
49014 --- linux-2.6.37/kernel/capability.c 2011-01-04 19:50:19.000000000 -0500
49015 +++ linux-2.6.37/kernel/capability.c 2011-01-17 02:41:02.000000000 -0500
49016 @@ -205,6 +205,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_
49017 * before modification is attempted and the application
49018 * fails.
49019 */
49020 + if (tocopy > ARRAY_SIZE(kdata))
49021 + return -EFAULT;
49022 +
49023 if (copy_to_user(dataptr, kdata, tocopy
49024 * sizeof(struct __user_cap_data_struct))) {
49025 return -EFAULT;
49026 @@ -306,10 +309,26 @@ int capable(int cap)
49027 BUG();
49028 }
49029
49030 - if (security_capable(cap) == 0) {
49031 + if (security_capable(cap) == 0 && gr_is_capable(cap)) {
49032 current->flags |= PF_SUPERPRIV;
49033 return 1;
49034 }
49035 return 0;
49036 }
49037 +
49038 +int capable_nolog(int cap)
49039 +{
49040 + if (unlikely(!cap_valid(cap))) {
49041 + printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
49042 + BUG();
49043 + }
49044 +
49045 + if (security_capable(cap) == 0 && gr_is_capable_nolog(cap)) {
49046 + current->flags |= PF_SUPERPRIV;
49047 + return 1;
49048 + }
49049 + return 0;
49050 +}
49051 +
49052 EXPORT_SYMBOL(capable);
49053 +EXPORT_SYMBOL(capable_nolog);
49054 diff -urNp linux-2.6.37/kernel/compat.c linux-2.6.37/kernel/compat.c
49055 --- linux-2.6.37/kernel/compat.c 2011-01-04 19:50:19.000000000 -0500
49056 +++ linux-2.6.37/kernel/compat.c 2011-01-17 02:41:02.000000000 -0500
49057 @@ -13,6 +13,7 @@
49058
49059 #include <linux/linkage.h>
49060 #include <linux/compat.h>
49061 +#include <linux/module.h>
49062 #include <linux/errno.h>
49063 #include <linux/time.h>
49064 #include <linux/signal.h>
49065 diff -urNp linux-2.6.37/kernel/configs.c linux-2.6.37/kernel/configs.c
49066 --- linux-2.6.37/kernel/configs.c 2011-01-04 19:50:19.000000000 -0500
49067 +++ linux-2.6.37/kernel/configs.c 2011-01-17 02:41:02.000000000 -0500
49068 @@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
49069 struct proc_dir_entry *entry;
49070
49071 /* create the current config file */
49072 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
49073 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
49074 + entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
49075 + &ikconfig_file_ops);
49076 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49077 + entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
49078 + &ikconfig_file_ops);
49079 +#endif
49080 +#else
49081 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
49082 &ikconfig_file_ops);
49083 +#endif
49084 +
49085 if (!entry)
49086 return -ENOMEM;
49087
49088 diff -urNp linux-2.6.37/kernel/cred.c linux-2.6.37/kernel/cred.c
49089 --- linux-2.6.37/kernel/cred.c 2011-01-04 19:50:19.000000000 -0500
49090 +++ linux-2.6.37/kernel/cred.c 2011-01-17 02:41:02.000000000 -0500
49091 @@ -483,6 +483,8 @@ int commit_creds(struct cred *new)
49092
49093 get_cred(new); /* we will require a ref for the subj creds too */
49094
49095 + gr_set_role_label(task, new->uid, new->gid);
49096 +
49097 /* dumpability changes */
49098 if (old->euid != new->euid ||
49099 old->egid != new->egid ||
49100 diff -urNp linux-2.6.37/kernel/debug/debug_core.c linux-2.6.37/kernel/debug/debug_core.c
49101 --- linux-2.6.37/kernel/debug/debug_core.c 2011-01-04 19:50:19.000000000 -0500
49102 +++ linux-2.6.37/kernel/debug/debug_core.c 2011-01-17 02:41:02.000000000 -0500
49103 @@ -72,7 +72,7 @@ int kgdb_io_module_registered;
49104 /* Guard for recursive entry */
49105 static int exception_level;
49106
49107 -struct kgdb_io *dbg_io_ops;
49108 +const struct kgdb_io *dbg_io_ops;
49109 static DEFINE_SPINLOCK(kgdb_registration_lock);
49110
49111 /* kgdb console driver is loaded */
49112 @@ -864,7 +864,7 @@ static void kgdb_initial_breakpoint(void
49113 *
49114 * Register it with the KGDB core.
49115 */
49116 -int kgdb_register_io_module(struct kgdb_io *new_dbg_io_ops)
49117 +int kgdb_register_io_module(const struct kgdb_io *new_dbg_io_ops)
49118 {
49119 int err;
49120
49121 @@ -909,7 +909,7 @@ EXPORT_SYMBOL_GPL(kgdb_register_io_modul
49122 *
49123 * Unregister it with the KGDB core.
49124 */
49125 -void kgdb_unregister_io_module(struct kgdb_io *old_dbg_io_ops)
49126 +void kgdb_unregister_io_module(const struct kgdb_io *old_dbg_io_ops)
49127 {
49128 BUG_ON(kgdb_connected);
49129
49130 diff -urNp linux-2.6.37/kernel/debug/kdb/kdb_main.c linux-2.6.37/kernel/debug/kdb/kdb_main.c
49131 --- linux-2.6.37/kernel/debug/kdb/kdb_main.c 2011-01-04 19:50:19.000000000 -0500
49132 +++ linux-2.6.37/kernel/debug/kdb/kdb_main.c 2011-01-17 02:41:02.000000000 -0500
49133 @@ -1980,7 +1980,7 @@ static int kdb_lsmod(int argc, const cha
49134 list_for_each_entry(mod, kdb_modules, list) {
49135
49136 kdb_printf("%-20s%8u 0x%p ", mod->name,
49137 - mod->core_size, (void *)mod);
49138 + mod->core_size_rx + mod->core_size_rw, (void *)mod);
49139 #ifdef CONFIG_MODULE_UNLOAD
49140 kdb_printf("%4d ", module_refcount(mod));
49141 #endif
49142 @@ -1990,7 +1990,7 @@ static int kdb_lsmod(int argc, const cha
49143 kdb_printf(" (Loading)");
49144 else
49145 kdb_printf(" (Live)");
49146 - kdb_printf(" 0x%p", mod->module_core);
49147 + kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
49148
49149 #ifdef CONFIG_MODULE_UNLOAD
49150 {
49151 diff -urNp linux-2.6.37/kernel/exit.c linux-2.6.37/kernel/exit.c
49152 --- linux-2.6.37/kernel/exit.c 2011-01-04 19:50:19.000000000 -0500
49153 +++ linux-2.6.37/kernel/exit.c 2011-01-17 02:41:02.000000000 -0500
49154 @@ -57,6 +57,10 @@
49155 #include <asm/pgtable.h>
49156 #include <asm/mmu_context.h>
49157
49158 +#ifdef CONFIG_GRKERNSEC
49159 +extern rwlock_t grsec_exec_file_lock;
49160 +#endif
49161 +
49162 static void exit_mm(struct task_struct * tsk);
49163
49164 static void __unhash_process(struct task_struct *p, bool group_dead)
49165 @@ -169,6 +173,8 @@ void release_task(struct task_struct * p
49166 struct task_struct *leader;
49167 int zap_leader;
49168 repeat:
49169 + gr_del_task_from_ip_table(p);
49170 +
49171 tracehook_prepare_release_task(p);
49172 /* don't need to get the RCU readlock here - the process is dead and
49173 * can't be modifying its own credentials. But shut RCU-lockdep up */
49174 @@ -338,11 +344,22 @@ static void reparent_to_kthreadd(void)
49175 {
49176 write_lock_irq(&tasklist_lock);
49177
49178 +#ifdef CONFIG_GRKERNSEC
49179 + write_lock(&grsec_exec_file_lock);
49180 + if (current->exec_file) {
49181 + fput(current->exec_file);
49182 + current->exec_file = NULL;
49183 + }
49184 + write_unlock(&grsec_exec_file_lock);
49185 +#endif
49186 +
49187 ptrace_unlink(current);
49188 /* Reparent to init */
49189 current->real_parent = current->parent = kthreadd_task;
49190 list_move_tail(&current->sibling, &current->real_parent->children);
49191
49192 + gr_set_kernel_label(current);
49193 +
49194 /* Set the exit signal to SIGCHLD so we signal init on exit */
49195 current->exit_signal = SIGCHLD;
49196
49197 @@ -394,7 +411,7 @@ int allow_signal(int sig)
49198 * know it'll be handled, so that they don't get converted to
49199 * SIGKILL or just silently dropped.
49200 */
49201 - current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
49202 + current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
49203 recalc_sigpending();
49204 spin_unlock_irq(&current->sighand->siglock);
49205 return 0;
49206 @@ -430,6 +447,17 @@ void daemonize(const char *name, ...)
49207 vsnprintf(current->comm, sizeof(current->comm), name, args);
49208 va_end(args);
49209
49210 +#ifdef CONFIG_GRKERNSEC
49211 + write_lock(&grsec_exec_file_lock);
49212 + if (current->exec_file) {
49213 + fput(current->exec_file);
49214 + current->exec_file = NULL;
49215 + }
49216 + write_unlock(&grsec_exec_file_lock);
49217 +#endif
49218 +
49219 + gr_set_kernel_label(current);
49220 +
49221 /*
49222 * If we were started as result of loading a module, close all of the
49223 * user space pages. We don't need them, and if we didn't close them
49224 @@ -905,17 +933,17 @@ NORET_TYPE void do_exit(long code)
49225 struct task_struct *tsk = current;
49226 int group_dead;
49227
49228 - profile_task_exit(tsk);
49229 -
49230 - WARN_ON(atomic_read(&tsk->fs_excl));
49231 -
49232 + /*
49233 + * Check this first since set_fs() below depends on
49234 + * current_thread_info(), which we better not access when we're in
49235 + * interrupt context. Other than that, we want to do the set_fs()
49236 + * as early as possible.
49237 + */
49238 if (unlikely(in_interrupt()))
49239 panic("Aiee, killing interrupt handler!");
49240 - if (unlikely(!tsk->pid))
49241 - panic("Attempted to kill the idle task!");
49242
49243 /*
49244 - * If do_exit is called because this processes oopsed, it's possible
49245 + * If do_exit is called because this processes Oops'ed, it's possible
49246 * that get_fs() was left as KERNEL_DS, so reset it to USER_DS before
49247 * continuing. Amongst other possible reasons, this is to prevent
49248 * mm_release()->clear_child_tid() from writing to a user-controlled
49249 @@ -923,6 +951,13 @@ NORET_TYPE void do_exit(long code)
49250 */
49251 set_fs(USER_DS);
49252
49253 + profile_task_exit(tsk);
49254 +
49255 + WARN_ON(atomic_read(&tsk->fs_excl));
49256 +
49257 + if (unlikely(!tsk->pid))
49258 + panic("Attempted to kill the idle task!");
49259 +
49260 tracehook_report_exit(&code);
49261
49262 validate_creds_for_do_exit(tsk);
49263 @@ -983,6 +1018,9 @@ NORET_TYPE void do_exit(long code)
49264 tsk->exit_code = code;
49265 taskstats_exit(tsk, group_dead);
49266
49267 + gr_acl_handle_psacct(tsk, code);
49268 + gr_acl_handle_exit();
49269 +
49270 exit_mm(tsk);
49271
49272 if (group_dead)
49273 diff -urNp linux-2.6.37/kernel/fork.c linux-2.6.37/kernel/fork.c
49274 --- linux-2.6.37/kernel/fork.c 2011-01-04 19:50:19.000000000 -0500
49275 +++ linux-2.6.37/kernel/fork.c 2011-01-17 02:41:02.000000000 -0500
49276 @@ -278,7 +278,7 @@ static struct task_struct *dup_task_stru
49277 *stackend = STACK_END_MAGIC; /* for overflow detection */
49278
49279 #ifdef CONFIG_CC_STACKPROTECTOR
49280 - tsk->stack_canary = get_random_int();
49281 + tsk->stack_canary = pax_get_random_long();
49282 #endif
49283
49284 /* One for us, one for whoever does the "release_task()" (usually parent) */
49285 @@ -300,13 +300,78 @@ out:
49286 }
49287
49288 #ifdef CONFIG_MMU
49289 +static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct vm_area_struct *mpnt)
49290 +{
49291 + struct vm_area_struct *tmp;
49292 + unsigned long charge;
49293 + struct mempolicy *pol;
49294 + struct file *file;
49295 +
49296 + charge = 0;
49297 + if (mpnt->vm_flags & VM_ACCOUNT) {
49298 + unsigned int len = (mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT;
49299 + if (security_vm_enough_memory(len))
49300 + goto fail_nomem;
49301 + charge = len;
49302 + }
49303 + tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
49304 + if (!tmp)
49305 + goto fail_nomem;
49306 + *tmp = *mpnt;
49307 + tmp->vm_mm = mm;
49308 + INIT_LIST_HEAD(&tmp->anon_vma_chain);
49309 + pol = mpol_dup(vma_policy(mpnt));
49310 + if (IS_ERR(pol))
49311 + goto fail_nomem_policy;
49312 + vma_set_policy(tmp, pol);
49313 + if (anon_vma_fork(tmp, mpnt))
49314 + goto fail_nomem_anon_vma_fork;
49315 + tmp->vm_flags &= ~VM_LOCKED;
49316 + tmp->vm_next = tmp->vm_prev = NULL;
49317 + tmp->vm_mirror = NULL;
49318 + file = tmp->vm_file;
49319 + if (file) {
49320 + struct inode *inode = file->f_path.dentry->d_inode;
49321 + struct address_space *mapping = file->f_mapping;
49322 +
49323 + get_file(file);
49324 + if (tmp->vm_flags & VM_DENYWRITE)
49325 + atomic_dec(&inode->i_writecount);
49326 + spin_lock(&mapping->i_mmap_lock);
49327 + if (tmp->vm_flags & VM_SHARED)
49328 + mapping->i_mmap_writable++;
49329 + tmp->vm_truncate_count = mpnt->vm_truncate_count;
49330 + flush_dcache_mmap_lock(mapping);
49331 + /* insert tmp into the share list, just after mpnt */
49332 + vma_prio_tree_add(tmp, mpnt);
49333 + flush_dcache_mmap_unlock(mapping);
49334 + spin_unlock(&mapping->i_mmap_lock);
49335 + }
49336 +
49337 + /*
49338 + * Clear hugetlb-related page reserves for children. This only
49339 + * affects MAP_PRIVATE mappings. Faults generated by the child
49340 + * are not guaranteed to succeed, even if read-only
49341 + */
49342 + if (is_vm_hugetlb_page(tmp))
49343 + reset_vma_resv_huge_pages(tmp);
49344 +
49345 + return tmp;
49346 +
49347 +fail_nomem_anon_vma_fork:
49348 + mpol_put(pol);
49349 +fail_nomem_policy:
49350 + kmem_cache_free(vm_area_cachep, tmp);
49351 +fail_nomem:
49352 + vm_unacct_memory(charge);
49353 + return NULL;
49354 +}
49355 +
49356 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
49357 {
49358 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
49359 struct rb_node **rb_link, *rb_parent;
49360 int retval;
49361 - unsigned long charge;
49362 - struct mempolicy *pol;
49363
49364 down_write(&oldmm->mmap_sem);
49365 flush_cache_dup_mm(oldmm);
49366 @@ -318,8 +383,8 @@ static int dup_mmap(struct mm_struct *mm
49367 mm->locked_vm = 0;
49368 mm->mmap = NULL;
49369 mm->mmap_cache = NULL;
49370 - mm->free_area_cache = oldmm->mmap_base;
49371 - mm->cached_hole_size = ~0UL;
49372 + mm->free_area_cache = oldmm->free_area_cache;
49373 + mm->cached_hole_size = oldmm->cached_hole_size;
49374 mm->map_count = 0;
49375 cpumask_clear(mm_cpumask(mm));
49376 mm->mm_rb = RB_ROOT;
49377 @@ -332,8 +397,6 @@ static int dup_mmap(struct mm_struct *mm
49378
49379 prev = NULL;
49380 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
49381 - struct file *file;
49382 -
49383 if (mpnt->vm_flags & VM_DONTCOPY) {
49384 long pages = vma_pages(mpnt);
49385 mm->total_vm -= pages;
49386 @@ -341,56 +404,13 @@ static int dup_mmap(struct mm_struct *mm
49387 -pages);
49388 continue;
49389 }
49390 - charge = 0;
49391 - if (mpnt->vm_flags & VM_ACCOUNT) {
49392 - unsigned int len = (mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT;
49393 - if (security_vm_enough_memory(len))
49394 - goto fail_nomem;
49395 - charge = len;
49396 - }
49397 - tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
49398 - if (!tmp)
49399 - goto fail_nomem;
49400 - *tmp = *mpnt;
49401 - INIT_LIST_HEAD(&tmp->anon_vma_chain);
49402 - pol = mpol_dup(vma_policy(mpnt));
49403 - retval = PTR_ERR(pol);
49404 - if (IS_ERR(pol))
49405 - goto fail_nomem_policy;
49406 - vma_set_policy(tmp, pol);
49407 - tmp->vm_mm = mm;
49408 - if (anon_vma_fork(tmp, mpnt))
49409 - goto fail_nomem_anon_vma_fork;
49410 - tmp->vm_flags &= ~VM_LOCKED;
49411 - tmp->vm_next = tmp->vm_prev = NULL;
49412 - file = tmp->vm_file;
49413 - if (file) {
49414 - struct inode *inode = file->f_path.dentry->d_inode;
49415 - struct address_space *mapping = file->f_mapping;
49416 -
49417 - get_file(file);
49418 - if (tmp->vm_flags & VM_DENYWRITE)
49419 - atomic_dec(&inode->i_writecount);
49420 - spin_lock(&mapping->i_mmap_lock);
49421 - if (tmp->vm_flags & VM_SHARED)
49422 - mapping->i_mmap_writable++;
49423 - tmp->vm_truncate_count = mpnt->vm_truncate_count;
49424 - flush_dcache_mmap_lock(mapping);
49425 - /* insert tmp into the share list, just after mpnt */
49426 - vma_prio_tree_add(tmp, mpnt);
49427 - flush_dcache_mmap_unlock(mapping);
49428 - spin_unlock(&mapping->i_mmap_lock);
49429 + tmp = dup_vma(mm, mpnt);
49430 + if (!tmp) {
49431 + retval = -ENOMEM;
49432 + goto out;
49433 }
49434
49435 /*
49436 - * Clear hugetlb-related page reserves for children. This only
49437 - * affects MAP_PRIVATE mappings. Faults generated by the child
49438 - * are not guaranteed to succeed, even if read-only
49439 - */
49440 - if (is_vm_hugetlb_page(tmp))
49441 - reset_vma_resv_huge_pages(tmp);
49442 -
49443 - /*
49444 * Link in the new vma and copy the page table entries.
49445 */
49446 *pprev = tmp;
49447 @@ -411,6 +431,31 @@ static int dup_mmap(struct mm_struct *mm
49448 if (retval)
49449 goto out;
49450 }
49451 +
49452 +#ifdef CONFIG_PAX_SEGMEXEC
49453 + if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
49454 + struct vm_area_struct *mpnt_m;
49455 +
49456 + for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
49457 + BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
49458 +
49459 + if (!mpnt->vm_mirror)
49460 + continue;
49461 +
49462 + if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
49463 + BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
49464 + mpnt->vm_mirror = mpnt_m;
49465 + } else {
49466 + BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
49467 + mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
49468 + mpnt_m->vm_mirror->vm_mirror = mpnt_m;
49469 + mpnt->vm_mirror->vm_mirror = mpnt;
49470 + }
49471 + }
49472 + BUG_ON(mpnt_m);
49473 + }
49474 +#endif
49475 +
49476 /* a new mm has just been created */
49477 arch_dup_mmap(oldmm, mm);
49478 retval = 0;
49479 @@ -419,14 +464,6 @@ out:
49480 flush_tlb_mm(oldmm);
49481 up_write(&oldmm->mmap_sem);
49482 return retval;
49483 -fail_nomem_anon_vma_fork:
49484 - mpol_put(pol);
49485 -fail_nomem_policy:
49486 - kmem_cache_free(vm_area_cachep, tmp);
49487 -fail_nomem:
49488 - retval = -ENOMEM;
49489 - vm_unacct_memory(charge);
49490 - goto out;
49491 }
49492
49493 static inline int mm_alloc_pgd(struct mm_struct * mm)
49494 @@ -765,13 +802,14 @@ static int copy_fs(unsigned long clone_f
49495 spin_unlock(&fs->lock);
49496 return -EAGAIN;
49497 }
49498 - fs->users++;
49499 + atomic_inc(&fs->users);
49500 spin_unlock(&fs->lock);
49501 return 0;
49502 }
49503 tsk->fs = copy_fs_struct(fs);
49504 if (!tsk->fs)
49505 return -ENOMEM;
49506 + gr_set_chroot_entries(tsk, &tsk->fs->root);
49507 return 0;
49508 }
49509
49510 @@ -1027,10 +1065,13 @@ static struct task_struct *copy_process(
49511 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
49512 #endif
49513 retval = -EAGAIN;
49514 +
49515 + gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
49516 +
49517 if (atomic_read(&p->real_cred->user->processes) >=
49518 task_rlimit(p, RLIMIT_NPROC)) {
49519 - if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
49520 - p->real_cred->user != INIT_USER)
49521 + if (p->real_cred->user != INIT_USER &&
49522 + !capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE))
49523 goto bad_fork_free;
49524 }
49525
49526 @@ -1184,6 +1225,8 @@ static struct task_struct *copy_process(
49527 goto bad_fork_free_pid;
49528 }
49529
49530 + gr_copy_label(p);
49531 +
49532 p->set_child_tid = (clone_flags & CLONE_CHILD_SETTID) ? child_tidptr : NULL;
49533 /*
49534 * Clear TID on mm_release()?
49535 @@ -1341,6 +1384,8 @@ bad_fork_cleanup_count:
49536 bad_fork_free:
49537 free_task(p);
49538 fork_out:
49539 + gr_log_forkfail(retval);
49540 +
49541 return ERR_PTR(retval);
49542 }
49543
49544 @@ -1446,6 +1491,8 @@ long do_fork(unsigned long clone_flags,
49545 if (clone_flags & CLONE_PARENT_SETTID)
49546 put_user(nr, parent_tidptr);
49547
49548 + gr_handle_brute_check();
49549 +
49550 if (clone_flags & CLONE_VFORK) {
49551 p->vfork_done = &vfork;
49552 init_completion(&vfork);
49553 @@ -1570,7 +1617,7 @@ static int unshare_fs(unsigned long unsh
49554 return 0;
49555
49556 /* don't need lock here; in the worst case we'll do useless copy */
49557 - if (fs->users == 1)
49558 + if (atomic_read(&fs->users) == 1)
49559 return 0;
49560
49561 *new_fsp = copy_fs_struct(fs);
49562 @@ -1693,7 +1740,8 @@ SYSCALL_DEFINE1(unshare, unsigned long,
49563 fs = current->fs;
49564 spin_lock(&fs->lock);
49565 current->fs = new_fs;
49566 - if (--fs->users)
49567 + gr_set_chroot_entries(current, &current->fs->root);
49568 + if (atomic_dec_return(&fs->users))
49569 new_fs = NULL;
49570 else
49571 new_fs = fs;
49572 diff -urNp linux-2.6.37/kernel/futex.c linux-2.6.37/kernel/futex.c
49573 --- linux-2.6.37/kernel/futex.c 2011-01-04 19:50:19.000000000 -0500
49574 +++ linux-2.6.37/kernel/futex.c 2011-01-17 02:41:02.000000000 -0500
49575 @@ -54,6 +54,7 @@
49576 #include <linux/mount.h>
49577 #include <linux/pagemap.h>
49578 #include <linux/syscalls.h>
49579 +#include <linux/ptrace.h>
49580 #include <linux/signal.h>
49581 #include <linux/module.h>
49582 #include <linux/magic.h>
49583 @@ -222,6 +223,11 @@ get_futex_key(u32 __user *uaddr, int fsh
49584 struct page *page;
49585 int err;
49586
49587 +#ifdef CONFIG_PAX_SEGMEXEC
49588 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
49589 + return -EFAULT;
49590 +#endif
49591 +
49592 /*
49593 * The futex address must be "naturally" aligned.
49594 */
49595 @@ -2384,7 +2390,9 @@ SYSCALL_DEFINE3(get_robust_list, int, pi
49596 {
49597 struct robust_list_head __user *head;
49598 unsigned long ret;
49599 +#ifndef CONFIG_GRKERNSEC_PROC_MEMMAP
49600 const struct cred *cred = current_cred(), *pcred;
49601 +#endif
49602
49603 if (!futex_cmpxchg_enabled)
49604 return -ENOSYS;
49605 @@ -2400,11 +2408,16 @@ SYSCALL_DEFINE3(get_robust_list, int, pi
49606 if (!p)
49607 goto err_unlock;
49608 ret = -EPERM;
49609 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49610 + if (!ptrace_may_access(p, PTRACE_MODE_READ))
49611 + goto err_unlock;
49612 +#else
49613 pcred = __task_cred(p);
49614 if (cred->euid != pcred->euid &&
49615 cred->euid != pcred->uid &&
49616 !capable(CAP_SYS_PTRACE))
49617 goto err_unlock;
49618 +#endif
49619 head = p->robust_list;
49620 rcu_read_unlock();
49621 }
49622 @@ -2648,6 +2661,7 @@ static int __init futex_init(void)
49623 {
49624 u32 curval;
49625 int i;
49626 + mm_segment_t oldfs;
49627
49628 /*
49629 * This will fail and we want it. Some arch implementations do
49630 @@ -2659,7 +2673,10 @@ static int __init futex_init(void)
49631 * implementation, the non-functional ones will return
49632 * -ENOSYS.
49633 */
49634 + oldfs = get_fs();
49635 + set_fs(USER_DS);
49636 curval = cmpxchg_futex_value_locked(NULL, 0, 0);
49637 + set_fs(oldfs);
49638 if (curval == -EFAULT)
49639 futex_cmpxchg_enabled = 1;
49640
49641 diff -urNp linux-2.6.37/kernel/futex_compat.c linux-2.6.37/kernel/futex_compat.c
49642 --- linux-2.6.37/kernel/futex_compat.c 2011-01-04 19:50:19.000000000 -0500
49643 +++ linux-2.6.37/kernel/futex_compat.c 2011-01-17 02:41:02.000000000 -0500
49644 @@ -10,6 +10,7 @@
49645 #include <linux/compat.h>
49646 #include <linux/nsproxy.h>
49647 #include <linux/futex.h>
49648 +#include <linux/ptrace.h>
49649
49650 #include <asm/uaccess.h>
49651
49652 @@ -136,7 +137,10 @@ compat_sys_get_robust_list(int pid, comp
49653 {
49654 struct compat_robust_list_head __user *head;
49655 unsigned long ret;
49656 - const struct cred *cred = current_cred(), *pcred;
49657 +#ifndef CONFIG_GRKERNSEC_PROC_MEMMAP
49658 + const struct cred *cred = current_cred();
49659 + const struct cred *pcred;
49660 +#endif
49661
49662 if (!futex_cmpxchg_enabled)
49663 return -ENOSYS;
49664 @@ -152,11 +156,16 @@ compat_sys_get_robust_list(int pid, comp
49665 if (!p)
49666 goto err_unlock;
49667 ret = -EPERM;
49668 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49669 + if (!ptrace_may_access(p, PTRACE_MODE_READ))
49670 + goto err_unlock;
49671 +#else
49672 pcred = __task_cred(p);
49673 if (cred->euid != pcred->euid &&
49674 cred->euid != pcred->uid &&
49675 !capable(CAP_SYS_PTRACE))
49676 goto err_unlock;
49677 +#endif
49678 head = p->compat_robust_list;
49679 rcu_read_unlock();
49680 }
49681 diff -urNp linux-2.6.37/kernel/gcov/base.c linux-2.6.37/kernel/gcov/base.c
49682 --- linux-2.6.37/kernel/gcov/base.c 2011-01-04 19:50:19.000000000 -0500
49683 +++ linux-2.6.37/kernel/gcov/base.c 2011-01-17 02:41:02.000000000 -0500
49684 @@ -102,11 +102,6 @@ void gcov_enable_events(void)
49685 }
49686
49687 #ifdef CONFIG_MODULES
49688 -static inline int within(void *addr, void *start, unsigned long size)
49689 -{
49690 - return ((addr >= start) && (addr < start + size));
49691 -}
49692 -
49693 /* Update list and generate events when modules are unloaded. */
49694 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
49695 void *data)
49696 @@ -121,7 +116,7 @@ static int gcov_module_notifier(struct n
49697 prev = NULL;
49698 /* Remove entries located in module from linked list. */
49699 for (info = gcov_info_head; info; info = info->next) {
49700 - if (within(info, mod->module_core, mod->core_size)) {
49701 + if (within_module_core_rw((unsigned long)info, mod)) {
49702 if (prev)
49703 prev->next = info->next;
49704 else
49705 diff -urNp linux-2.6.37/kernel/hrtimer.c linux-2.6.37/kernel/hrtimer.c
49706 --- linux-2.6.37/kernel/hrtimer.c 2011-01-04 19:50:19.000000000 -0500
49707 +++ linux-2.6.37/kernel/hrtimer.c 2011-01-17 02:41:02.000000000 -0500
49708 @@ -1401,7 +1401,7 @@ void hrtimer_peek_ahead_timers(void)
49709 local_irq_restore(flags);
49710 }
49711
49712 -static void run_hrtimer_softirq(struct softirq_action *h)
49713 +static void run_hrtimer_softirq(void)
49714 {
49715 hrtimer_peek_ahead_timers();
49716 }
49717 diff -urNp linux-2.6.37/kernel/jump_label.c linux-2.6.37/kernel/jump_label.c
49718 --- linux-2.6.37/kernel/jump_label.c 2011-01-04 19:50:19.000000000 -0500
49719 +++ linux-2.6.37/kernel/jump_label.c 2011-01-17 02:41:02.000000000 -0500
49720 @@ -49,6 +49,17 @@ void jump_label_unlock(void)
49721 mutex_unlock(&jump_label_mutex);
49722 }
49723
49724 +static void jump_label_swap(void *a, void *b, int size)
49725 +{
49726 + struct jump_entry t;
49727 +
49728 + t = *(struct jump_entry *)a;
49729 + pax_open_kernel();
49730 + *(struct jump_entry *)a = *(struct jump_entry *)b;
49731 + *(struct jump_entry *)b = t;
49732 + pax_close_kernel();
49733 +}
49734 +
49735 static int jump_label_cmp(const void *a, const void *b)
49736 {
49737 const struct jump_entry *jea = a;
49738 @@ -70,7 +81,7 @@ sort_jump_label_entries(struct jump_entr
49739
49740 size = (((unsigned long)stop - (unsigned long)start)
49741 / sizeof(struct jump_entry));
49742 - sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
49743 + sort(start, size, sizeof(struct jump_entry), jump_label_cmp, jump_label_swap);
49744 }
49745
49746 static struct jump_label_entry *get_jump_label_entry(jump_label_t key)
49747 @@ -407,8 +418,11 @@ static void remove_jump_label_module_ini
49748 count = e_module->nr_entries;
49749 iter = e_module->table;
49750 while (count--) {
49751 - if (within_module_init(iter->code, mod))
49752 + if (within_module_init(iter->code, mod)) {
49753 + pax_open_kernel();
49754 iter->key = 0;
49755 + pax_close_kernel();
49756 + }
49757 iter++;
49758 }
49759 }
49760 diff -urNp linux-2.6.37/kernel/kallsyms.c linux-2.6.37/kernel/kallsyms.c
49761 --- linux-2.6.37/kernel/kallsyms.c 2011-01-04 19:50:19.000000000 -0500
49762 +++ linux-2.6.37/kernel/kallsyms.c 2011-01-17 02:41:02.000000000 -0500
49763 @@ -11,6 +11,9 @@
49764 * Changed the compression method from stem compression to "table lookup"
49765 * compression (see scripts/kallsyms.c for a more complete description)
49766 */
49767 +#ifdef CONFIG_GRKERNSEC_HIDESYM
49768 +#define __INCLUDED_BY_HIDESYM 1
49769 +#endif
49770 #include <linux/kallsyms.h>
49771 #include <linux/module.h>
49772 #include <linux/init.h>
49773 @@ -53,12 +56,33 @@ extern const unsigned long kallsyms_mark
49774
49775 static inline int is_kernel_inittext(unsigned long addr)
49776 {
49777 + if (system_state != SYSTEM_BOOTING)
49778 + return 0;
49779 +
49780 if (addr >= (unsigned long)_sinittext
49781 && addr <= (unsigned long)_einittext)
49782 return 1;
49783 return 0;
49784 }
49785
49786 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
49787 +#ifdef CONFIG_MODULES
49788 +static inline int is_module_text(unsigned long addr)
49789 +{
49790 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
49791 + return 1;
49792 +
49793 + addr = ktla_ktva(addr);
49794 + return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
49795 +}
49796 +#else
49797 +static inline int is_module_text(unsigned long addr)
49798 +{
49799 + return 0;
49800 +}
49801 +#endif
49802 +#endif
49803 +
49804 static inline int is_kernel_text(unsigned long addr)
49805 {
49806 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
49807 @@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigne
49808
49809 static inline int is_kernel(unsigned long addr)
49810 {
49811 +
49812 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
49813 + if (is_kernel_text(addr) || is_kernel_inittext(addr))
49814 + return 1;
49815 +
49816 + if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
49817 +#else
49818 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
49819 +#endif
49820 +
49821 return 1;
49822 return in_gate_area_no_task(addr);
49823 }
49824
49825 static int is_ksym_addr(unsigned long addr)
49826 {
49827 +
49828 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
49829 + if (is_module_text(addr))
49830 + return 0;
49831 +#endif
49832 +
49833 if (all_var)
49834 return is_kernel(addr);
49835
49836 @@ -416,7 +455,6 @@ static unsigned long get_ksymbol_core(st
49837
49838 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
49839 {
49840 - iter->name[0] = '\0';
49841 iter->nameoff = get_symbol_offset(new_pos);
49842 iter->pos = new_pos;
49843 }
49844 @@ -464,6 +502,11 @@ static int s_show(struct seq_file *m, vo
49845 {
49846 struct kallsym_iter *iter = m->private;
49847
49848 +#ifdef CONFIG_GRKERNSEC_HIDESYM
49849 + if (current_uid())
49850 + return 0;
49851 +#endif
49852 +
49853 /* Some debugging symbols have no name. Ignore them. */
49854 if (!iter->name[0])
49855 return 0;
49856 @@ -504,7 +547,7 @@ static int kallsyms_open(struct inode *i
49857 struct kallsym_iter *iter;
49858 int ret;
49859
49860 - iter = kmalloc(sizeof(*iter), GFP_KERNEL);
49861 + iter = kzalloc(sizeof(*iter), GFP_KERNEL);
49862 if (!iter)
49863 return -ENOMEM;
49864 reset_iter(iter, 0);
49865 diff -urNp linux-2.6.37/kernel/kmod.c linux-2.6.37/kernel/kmod.c
49866 --- linux-2.6.37/kernel/kmod.c 2011-01-04 19:50:19.000000000 -0500
49867 +++ linux-2.6.37/kernel/kmod.c 2011-01-17 02:41:02.000000000 -0500
49868 @@ -90,6 +90,18 @@ int __request_module(bool wait, const ch
49869 if (ret)
49870 return ret;
49871
49872 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
49873 + /* we could do a tighter check here, but some distros
49874 + are taking it upon themselves to remove CAP_SYS_MODULE
49875 + from even root-running apps which cause modules to be
49876 + auto-loaded
49877 + */
49878 + if (current_uid()) {
49879 + gr_log_nonroot_mod_load(module_name);
49880 + return -EPERM;
49881 + }
49882 +#endif
49883 +
49884 /* If modprobe needs a service that is in a module, we get a recursive
49885 * loop. Limit the number of running kmod threads to max_threads/2 or
49886 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
49887 diff -urNp linux-2.6.37/kernel/kprobes.c linux-2.6.37/kernel/kprobes.c
49888 --- linux-2.6.37/kernel/kprobes.c 2011-01-04 19:50:19.000000000 -0500
49889 +++ linux-2.6.37/kernel/kprobes.c 2011-01-17 02:41:02.000000000 -0500
49890 @@ -185,7 +185,7 @@ static kprobe_opcode_t __kprobes *__get_
49891 * kernel image and loaded module images reside. This is required
49892 * so x86_64 can correctly handle the %rip-relative fixups.
49893 */
49894 - kip->insns = module_alloc(PAGE_SIZE);
49895 + kip->insns = module_alloc_exec(PAGE_SIZE);
49896 if (!kip->insns) {
49897 kfree(kip);
49898 return NULL;
49899 @@ -225,7 +225,7 @@ static int __kprobes collect_one_slot(st
49900 */
49901 if (!list_is_singular(&kip->list)) {
49902 list_del(&kip->list);
49903 - module_free(NULL, kip->insns);
49904 + module_free_exec(NULL, kip->insns);
49905 kfree(kip);
49906 }
49907 return 1;
49908 @@ -1724,7 +1724,7 @@ static int __init init_kprobes(void)
49909 {
49910 int i, err = 0;
49911 unsigned long offset = 0, size = 0;
49912 - char *modname, namebuf[128];
49913 + char *modname, namebuf[KSYM_NAME_LEN];
49914 const char *symbol_name;
49915 void *addr;
49916 struct kprobe_blackpoint *kb;
49917 @@ -1850,7 +1850,7 @@ static int __kprobes show_kprobe_addr(st
49918 const char *sym = NULL;
49919 unsigned int i = *(loff_t *) v;
49920 unsigned long offset = 0;
49921 - char *modname, namebuf[128];
49922 + char *modname, namebuf[KSYM_NAME_LEN];
49923
49924 head = &kprobe_table[i];
49925 preempt_disable();
49926 diff -urNp linux-2.6.37/kernel/lockdep.c linux-2.6.37/kernel/lockdep.c
49927 --- linux-2.6.37/kernel/lockdep.c 2011-01-04 19:50:19.000000000 -0500
49928 +++ linux-2.6.37/kernel/lockdep.c 2011-01-17 02:41:02.000000000 -0500
49929 @@ -571,6 +571,10 @@ static int static_obj(void *obj)
49930 end = (unsigned long) &_end,
49931 addr = (unsigned long) obj;
49932
49933 +#ifdef CONFIG_PAX_KERNEXEC
49934 + start = ktla_ktva(start);
49935 +#endif
49936 +
49937 /*
49938 * static variable?
49939 */
49940 @@ -706,6 +710,7 @@ register_lock_class(struct lockdep_map *
49941 if (!static_obj(lock->key)) {
49942 debug_locks_off();
49943 printk("INFO: trying to register non-static key.\n");
49944 + printk("lock:%pS key:%pS.\n", lock, lock->key);
49945 printk("the code is fine but needs lockdep annotation.\n");
49946 printk("turning off the locking correctness validator.\n");
49947 dump_stack();
49948 @@ -2768,7 +2773,7 @@ static int __lock_acquire(struct lockdep
49949 if (!class)
49950 return 0;
49951 }
49952 - atomic_inc((atomic_t *)&class->ops);
49953 + atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
49954 if (very_verbose(class)) {
49955 printk("\nacquire class [%p] %s", class->key, class->name);
49956 if (class->name_version > 1)
49957 diff -urNp linux-2.6.37/kernel/lockdep_proc.c linux-2.6.37/kernel/lockdep_proc.c
49958 --- linux-2.6.37/kernel/lockdep_proc.c 2011-01-04 19:50:19.000000000 -0500
49959 +++ linux-2.6.37/kernel/lockdep_proc.c 2011-01-17 02:41:02.000000000 -0500
49960 @@ -39,7 +39,7 @@ static void l_stop(struct seq_file *m, v
49961
49962 static void print_name(struct seq_file *m, struct lock_class *class)
49963 {
49964 - char str[128];
49965 + char str[KSYM_NAME_LEN];
49966 const char *name = class->name;
49967
49968 if (!name) {
49969 diff -urNp linux-2.6.37/kernel/module.c linux-2.6.37/kernel/module.c
49970 --- linux-2.6.37/kernel/module.c 2011-01-04 19:50:19.000000000 -0500
49971 +++ linux-2.6.37/kernel/module.c 2011-01-17 02:41:02.000000000 -0500
49972 @@ -97,7 +97,8 @@ static BLOCKING_NOTIFIER_HEAD(module_not
49973
49974 /* Bounds of module allocation, for speeding __module_address.
49975 * Protected by module_mutex. */
49976 -static unsigned long module_addr_min = -1UL, module_addr_max = 0;
49977 +static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
49978 +static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
49979
49980 int register_module_notifier(struct notifier_block * nb)
49981 {
49982 @@ -261,7 +262,7 @@ bool each_symbol(bool (*fn)(const struct
49983 return true;
49984
49985 list_for_each_entry_rcu(mod, &modules, list) {
49986 - struct symsearch arr[] = {
49987 + struct symsearch modarr[] = {
49988 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
49989 NOT_GPL_ONLY, false },
49990 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
49991 @@ -283,7 +284,7 @@ bool each_symbol(bool (*fn)(const struct
49992 #endif
49993 };
49994
49995 - if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
49996 + if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
49997 return true;
49998 }
49999 return false;
50000 @@ -394,7 +395,7 @@ static inline void __percpu *mod_percpu(
50001 static int percpu_modalloc(struct module *mod,
50002 unsigned long size, unsigned long align)
50003 {
50004 - if (align > PAGE_SIZE) {
50005 + if (align-1 >= PAGE_SIZE) {
50006 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
50007 mod->name, align, PAGE_SIZE);
50008 align = PAGE_SIZE;
50009 @@ -1566,15 +1567,18 @@ static void free_module(struct module *m
50010 destroy_params(mod->kp, mod->num_kp);
50011
50012 /* This may be NULL, but that's OK */
50013 - module_free(mod, mod->module_init);
50014 + module_free(mod, mod->module_init_rw);
50015 + module_free_exec(mod, mod->module_init_rx);
50016 kfree(mod->args);
50017 percpu_modfree(mod);
50018
50019 /* Free lock-classes: */
50020 - lockdep_free_key_range(mod->module_core, mod->core_size);
50021 + lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
50022 + lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
50023
50024 /* Finally, free the core (containing the module structure) */
50025 - module_free(mod, mod->module_core);
50026 + module_free_exec(mod, mod->module_core_rx);
50027 + module_free(mod, mod->module_core_rw);
50028
50029 #ifdef CONFIG_MPU
50030 update_protections(current->mm);
50031 @@ -1667,7 +1671,9 @@ static int simplify_symbols(struct modul
50032 ksym = resolve_symbol_wait(mod, info, name);
50033 /* Ok if resolved. */
50034 if (ksym && !IS_ERR(ksym)) {
50035 + pax_open_kernel();
50036 sym[i].st_value = ksym->value;
50037 + pax_close_kernel();
50038 break;
50039 }
50040
50041 @@ -1686,7 +1692,9 @@ static int simplify_symbols(struct modul
50042 secbase = (unsigned long)mod_percpu(mod);
50043 else
50044 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
50045 + pax_open_kernel();
50046 sym[i].st_value += secbase;
50047 + pax_close_kernel();
50048 break;
50049 }
50050 }
50051 @@ -1774,11 +1782,12 @@ static void layout_sections(struct modul
50052 || s->sh_entsize != ~0UL
50053 || strstarts(sname, ".init"))
50054 continue;
50055 - s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
50056 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
50057 + s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
50058 + else
50059 + s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
50060 DEBUGP("\t%s\n", name);
50061 }
50062 - if (m == 0)
50063 - mod->core_text_size = mod->core_size;
50064 }
50065
50066 DEBUGP("Init section allocation order:\n");
50067 @@ -1792,12 +1801,13 @@ static void layout_sections(struct modul
50068 || s->sh_entsize != ~0UL
50069 || !strstarts(sname, ".init"))
50070 continue;
50071 - s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
50072 - | INIT_OFFSET_MASK);
50073 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
50074 + s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
50075 + else
50076 + s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
50077 + s->sh_entsize |= INIT_OFFSET_MASK;
50078 DEBUGP("\t%s\n", sname);
50079 }
50080 - if (m == 0)
50081 - mod->init_text_size = mod->init_size;
50082 }
50083 }
50084
50085 @@ -1965,7 +1975,7 @@ static void layout_symtab(struct module
50086
50087 /* Put symbol section at end of init part of module. */
50088 symsect->sh_flags |= SHF_ALLOC;
50089 - symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
50090 + symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
50091 info->index.sym) | INIT_OFFSET_MASK;
50092 DEBUGP("\t%s\n", info->secstrings + symsect->sh_name);
50093
50094 @@ -1982,19 +1992,19 @@ static void layout_symtab(struct module
50095 }
50096
50097 /* Append room for core symbols at end of core part. */
50098 - info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
50099 - mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
50100 + info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
50101 + mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
50102
50103 /* Put string table section at end of init part of module. */
50104 strsect->sh_flags |= SHF_ALLOC;
50105 - strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
50106 + strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
50107 info->index.str) | INIT_OFFSET_MASK;
50108 DEBUGP("\t%s\n", info->secstrings + strsect->sh_name);
50109
50110 /* Append room for core symbols' strings at end of core part. */
50111 - info->stroffs = mod->core_size;
50112 + info->stroffs = mod->core_size_rx;
50113 __set_bit(0, info->strmap);
50114 - mod->core_size += bitmap_weight(info->strmap, strsect->sh_size);
50115 + mod->core_size_rx += bitmap_weight(info->strmap, strsect->sh_size);
50116 }
50117
50118 static void add_kallsyms(struct module *mod, const struct load_info *info)
50119 @@ -2010,11 +2020,13 @@ static void add_kallsyms(struct module *
50120 /* Make sure we get permanent strtab: don't use info->strtab. */
50121 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
50122
50123 + pax_open_kernel();
50124 +
50125 /* Set types up while we still have access to sections. */
50126 for (i = 0; i < mod->num_symtab; i++)
50127 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
50128
50129 - mod->core_symtab = dst = mod->module_core + info->symoffs;
50130 + mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
50131 src = mod->symtab;
50132 *dst = *src;
50133 for (ndst = i = 1; i < mod->num_symtab; ++i, ++src) {
50134 @@ -2027,10 +2039,12 @@ static void add_kallsyms(struct module *
50135 }
50136 mod->core_num_syms = ndst;
50137
50138 - mod->core_strtab = s = mod->module_core + info->stroffs;
50139 + mod->core_strtab = s = mod->module_core_rx + info->stroffs;
50140 for (*s = 0, i = 1; i < info->sechdrs[info->index.str].sh_size; ++i)
50141 if (test_bit(i, info->strmap))
50142 *++s = mod->strtab[i];
50143 +
50144 + pax_close_kernel();
50145 }
50146 #else
50147 static inline void layout_symtab(struct module *mod, struct load_info *info)
50148 @@ -2059,17 +2073,33 @@ static void dynamic_debug_remove(struct
50149 ddebug_remove_module(debug->modname);
50150 }
50151
50152 -static void *module_alloc_update_bounds(unsigned long size)
50153 +static void *module_alloc_update_bounds_rw(unsigned long size)
50154 {
50155 void *ret = module_alloc(size);
50156
50157 if (ret) {
50158 mutex_lock(&module_mutex);
50159 /* Update module bounds. */
50160 - if ((unsigned long)ret < module_addr_min)
50161 - module_addr_min = (unsigned long)ret;
50162 - if ((unsigned long)ret + size > module_addr_max)
50163 - module_addr_max = (unsigned long)ret + size;
50164 + if ((unsigned long)ret < module_addr_min_rw)
50165 + module_addr_min_rw = (unsigned long)ret;
50166 + if ((unsigned long)ret + size > module_addr_max_rw)
50167 + module_addr_max_rw = (unsigned long)ret + size;
50168 + mutex_unlock(&module_mutex);
50169 + }
50170 + return ret;
50171 +}
50172 +
50173 +static void *module_alloc_update_bounds_rx(unsigned long size)
50174 +{
50175 + void *ret = module_alloc_exec(size);
50176 +
50177 + if (ret) {
50178 + mutex_lock(&module_mutex);
50179 + /* Update module bounds. */
50180 + if ((unsigned long)ret < module_addr_min_rx)
50181 + module_addr_min_rx = (unsigned long)ret;
50182 + if ((unsigned long)ret + size > module_addr_max_rx)
50183 + module_addr_max_rx = (unsigned long)ret + size;
50184 mutex_unlock(&module_mutex);
50185 }
50186 return ret;
50187 @@ -2362,7 +2392,7 @@ static int move_module(struct module *mo
50188 void *ptr;
50189
50190 /* Do the allocs. */
50191 - ptr = module_alloc_update_bounds(mod->core_size);
50192 + ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
50193 /*
50194 * The pointer to this block is stored in the module structure
50195 * which is inside the block. Just mark it as not being a
50196 @@ -2372,23 +2402,50 @@ static int move_module(struct module *mo
50197 if (!ptr)
50198 return -ENOMEM;
50199
50200 - memset(ptr, 0, mod->core_size);
50201 - mod->module_core = ptr;
50202 + memset(ptr, 0, mod->core_size_rw);
50203 + mod->module_core_rw = ptr;
50204
50205 - ptr = module_alloc_update_bounds(mod->init_size);
50206 + ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
50207 /*
50208 * The pointer to this block is stored in the module structure
50209 * which is inside the block. This block doesn't need to be
50210 * scanned as it contains data and code that will be freed
50211 * after the module is initialized.
50212 */
50213 - kmemleak_ignore(ptr);
50214 - if (!ptr && mod->init_size) {
50215 - module_free(mod, mod->module_core);
50216 + kmemleak_not_leak(ptr);
50217 + if (!ptr && mod->init_size_rw) {
50218 + module_free(mod, mod->module_core_rw);
50219 + return -ENOMEM;
50220 + }
50221 + memset(ptr, 0, mod->init_size_rw);
50222 + mod->module_init_rw = ptr;
50223 +
50224 + ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
50225 + kmemleak_not_leak(ptr);
50226 + if (!ptr) {
50227 + module_free(mod, mod->module_init_rw);
50228 + module_free(mod, mod->module_core_rw);
50229 return -ENOMEM;
50230 }
50231 - memset(ptr, 0, mod->init_size);
50232 - mod->module_init = ptr;
50233 +
50234 + pax_open_kernel();
50235 + memset(ptr, 0, mod->core_size_rx);
50236 + pax_close_kernel();
50237 + mod->module_core_rx = ptr;
50238 +
50239 + ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
50240 + kmemleak_not_leak(ptr);
50241 + if (!ptr && mod->init_size_rx) {
50242 + module_free_exec(mod, mod->module_core_rx);
50243 + module_free(mod, mod->module_init_rw);
50244 + module_free(mod, mod->module_core_rw);
50245 + return -ENOMEM;
50246 + }
50247 +
50248 + pax_open_kernel();
50249 + memset(ptr, 0, mod->init_size_rx);
50250 + pax_close_kernel();
50251 + mod->module_init_rx = ptr;
50252
50253 /* Transfer each section which specifies SHF_ALLOC */
50254 DEBUGP("final section addresses:\n");
50255 @@ -2399,16 +2456,45 @@ static int move_module(struct module *mo
50256 if (!(shdr->sh_flags & SHF_ALLOC))
50257 continue;
50258
50259 - if (shdr->sh_entsize & INIT_OFFSET_MASK)
50260 - dest = mod->module_init
50261 - + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
50262 - else
50263 - dest = mod->module_core + shdr->sh_entsize;
50264 + if (shdr->sh_entsize & INIT_OFFSET_MASK) {
50265 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
50266 + dest = mod->module_init_rw
50267 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
50268 + else
50269 + dest = mod->module_init_rx
50270 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
50271 + } else {
50272 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
50273 + dest = mod->module_core_rw + shdr->sh_entsize;
50274 + else
50275 + dest = mod->module_core_rx + shdr->sh_entsize;
50276 + }
50277 +
50278 + if (shdr->sh_type != SHT_NOBITS) {
50279 +
50280 +#ifdef CONFIG_PAX_KERNEXEC
50281 +#ifdef CONFIG_X86_64
50282 + if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
50283 + set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
50284 +#endif
50285 + if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
50286 + pax_open_kernel();
50287 + memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
50288 + pax_close_kernel();
50289 + } else
50290 +#endif
50291
50292 - if (shdr->sh_type != SHT_NOBITS)
50293 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
50294 + }
50295 /* Update sh_addr to point to copy in image. */
50296 - shdr->sh_addr = (unsigned long)dest;
50297 +
50298 +#ifdef CONFIG_PAX_KERNEXEC
50299 + if (shdr->sh_flags & SHF_EXECINSTR)
50300 + shdr->sh_addr = ktva_ktla((unsigned long)dest);
50301 + else
50302 +#endif
50303 +
50304 + shdr->sh_addr = (unsigned long)dest;
50305 DEBUGP("\t0x%lx %s\n",
50306 shdr->sh_addr, info->secstrings + shdr->sh_name);
50307 }
50308 @@ -2459,12 +2545,12 @@ static void flush_module_icache(const st
50309 * Do it before processing of module parameters, so the module
50310 * can provide parameter accessor functions of its own.
50311 */
50312 - if (mod->module_init)
50313 - flush_icache_range((unsigned long)mod->module_init,
50314 - (unsigned long)mod->module_init
50315 - + mod->init_size);
50316 - flush_icache_range((unsigned long)mod->module_core,
50317 - (unsigned long)mod->module_core + mod->core_size);
50318 + if (mod->module_init_rx)
50319 + flush_icache_range((unsigned long)mod->module_init_rx,
50320 + (unsigned long)mod->module_init_rx
50321 + + mod->init_size_rx);
50322 + flush_icache_range((unsigned long)mod->module_core_rx,
50323 + (unsigned long)mod->module_core_rx + mod->core_size_rx);
50324
50325 set_fs(old_fs);
50326 }
50327 @@ -2536,8 +2622,10 @@ static void module_deallocate(struct mod
50328 {
50329 kfree(info->strmap);
50330 percpu_modfree(mod);
50331 - module_free(mod, mod->module_init);
50332 - module_free(mod, mod->module_core);
50333 + module_free_exec(mod, mod->module_init_rx);
50334 + module_free_exec(mod, mod->module_core_rx);
50335 + module_free(mod, mod->module_init_rw);
50336 + module_free(mod, mod->module_core_rw);
50337 }
50338
50339 static int post_relocation(struct module *mod, const struct load_info *info)
50340 @@ -2765,10 +2853,12 @@ SYSCALL_DEFINE3(init_module, void __user
50341 mod->symtab = mod->core_symtab;
50342 mod->strtab = mod->core_strtab;
50343 #endif
50344 - module_free(mod, mod->module_init);
50345 - mod->module_init = NULL;
50346 - mod->init_size = 0;
50347 - mod->init_text_size = 0;
50348 + module_free(mod, mod->module_init_rw);
50349 + module_free_exec(mod, mod->module_init_rx);
50350 + mod->module_init_rw = NULL;
50351 + mod->module_init_rx = NULL;
50352 + mod->init_size_rw = 0;
50353 + mod->init_size_rx = 0;
50354 mutex_unlock(&module_mutex);
50355
50356 return 0;
50357 @@ -2799,10 +2889,16 @@ static const char *get_ksymbol(struct mo
50358 unsigned long nextval;
50359
50360 /* At worse, next value is at end of module */
50361 - if (within_module_init(addr, mod))
50362 - nextval = (unsigned long)mod->module_init+mod->init_text_size;
50363 + if (within_module_init_rx(addr, mod))
50364 + nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
50365 + else if (within_module_init_rw(addr, mod))
50366 + nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
50367 + else if (within_module_core_rx(addr, mod))
50368 + nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
50369 + else if (within_module_core_rw(addr, mod))
50370 + nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
50371 else
50372 - nextval = (unsigned long)mod->module_core+mod->core_text_size;
50373 + return NULL;
50374
50375 /* Scan for closest preceeding symbol, and next symbol. (ELF
50376 starts real symbols at 1). */
50377 @@ -3048,7 +3144,7 @@ static int m_show(struct seq_file *m, vo
50378 char buf[8];
50379
50380 seq_printf(m, "%s %u",
50381 - mod->name, mod->init_size + mod->core_size);
50382 + mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
50383 print_unload_info(m, mod);
50384
50385 /* Informative for users. */
50386 @@ -3057,7 +3153,7 @@ static int m_show(struct seq_file *m, vo
50387 mod->state == MODULE_STATE_COMING ? "Loading":
50388 "Live");
50389 /* Used by oprofile and other similar tools. */
50390 - seq_printf(m, " 0x%p", mod->module_core);
50391 + seq_printf(m, " 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
50392
50393 /* Taints info */
50394 if (mod->taints)
50395 @@ -3093,7 +3189,17 @@ static const struct file_operations proc
50396
50397 static int __init proc_modules_init(void)
50398 {
50399 +#ifndef CONFIG_GRKERNSEC_HIDESYM
50400 +#ifdef CONFIG_GRKERNSEC_PROC_USER
50401 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
50402 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
50403 + proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
50404 +#else
50405 proc_create("modules", 0, NULL, &proc_modules_operations);
50406 +#endif
50407 +#else
50408 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
50409 +#endif
50410 return 0;
50411 }
50412 module_init(proc_modules_init);
50413 @@ -3152,12 +3258,12 @@ struct module *__module_address(unsigned
50414 {
50415 struct module *mod;
50416
50417 - if (addr < module_addr_min || addr > module_addr_max)
50418 + if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
50419 + (addr < module_addr_min_rw || addr > module_addr_max_rw))
50420 return NULL;
50421
50422 list_for_each_entry_rcu(mod, &modules, list)
50423 - if (within_module_core(addr, mod)
50424 - || within_module_init(addr, mod))
50425 + if (within_module_init(addr, mod) || within_module_core(addr, mod))
50426 return mod;
50427 return NULL;
50428 }
50429 @@ -3191,11 +3297,20 @@ bool is_module_text_address(unsigned lon
50430 */
50431 struct module *__module_text_address(unsigned long addr)
50432 {
50433 - struct module *mod = __module_address(addr);
50434 + struct module *mod;
50435 +
50436 +#ifdef CONFIG_X86_32
50437 + addr = ktla_ktva(addr);
50438 +#endif
50439 +
50440 + if (addr < module_addr_min_rx || addr > module_addr_max_rx)
50441 + return NULL;
50442 +
50443 + mod = __module_address(addr);
50444 +
50445 if (mod) {
50446 /* Make sure it's within the text section. */
50447 - if (!within(addr, mod->module_init, mod->init_text_size)
50448 - && !within(addr, mod->module_core, mod->core_text_size))
50449 + if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
50450 mod = NULL;
50451 }
50452 return mod;
50453 diff -urNp linux-2.6.37/kernel/panic.c linux-2.6.37/kernel/panic.c
50454 --- linux-2.6.37/kernel/panic.c 2011-01-04 19:50:19.000000000 -0500
50455 +++ linux-2.6.37/kernel/panic.c 2011-01-17 02:41:02.000000000 -0500
50456 @@ -368,7 +368,7 @@ static void warn_slowpath_common(const c
50457 const char *board;
50458
50459 printk(KERN_WARNING "------------[ cut here ]------------\n");
50460 - printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
50461 + printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
50462 board = dmi_get_system_info(DMI_PRODUCT_NAME);
50463 if (board)
50464 printk(KERN_WARNING "Hardware name: %s\n", board);
50465 @@ -423,7 +423,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
50466 */
50467 void __stack_chk_fail(void)
50468 {
50469 - panic("stack-protector: Kernel stack is corrupted in: %p\n",
50470 + dump_stack();
50471 + panic("stack-protector: Kernel stack is corrupted in: %pA\n",
50472 __builtin_return_address(0));
50473 }
50474 EXPORT_SYMBOL(__stack_chk_fail);
50475 diff -urNp linux-2.6.37/kernel/pid.c linux-2.6.37/kernel/pid.c
50476 --- linux-2.6.37/kernel/pid.c 2011-01-04 19:50:19.000000000 -0500
50477 +++ linux-2.6.37/kernel/pid.c 2011-01-17 02:41:02.000000000 -0500
50478 @@ -33,6 +33,7 @@
50479 #include <linux/rculist.h>
50480 #include <linux/bootmem.h>
50481 #include <linux/hash.h>
50482 +#include <linux/security.h>
50483 #include <linux/pid_namespace.h>
50484 #include <linux/init_task.h>
50485 #include <linux/syscalls.h>
50486 @@ -45,7 +46,7 @@ struct pid init_struct_pid = INIT_STRUCT
50487
50488 int pid_max = PID_MAX_DEFAULT;
50489
50490 -#define RESERVED_PIDS 300
50491 +#define RESERVED_PIDS 500
50492
50493 int pid_max_min = RESERVED_PIDS + 1;
50494 int pid_max_max = PID_MAX_LIMIT;
50495 @@ -416,8 +417,15 @@ EXPORT_SYMBOL(pid_task);
50496 */
50497 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
50498 {
50499 + struct task_struct *task;
50500 +
50501 rcu_lockdep_assert(rcu_read_lock_held());
50502 - return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
50503 + task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
50504 +
50505 + if (gr_pid_is_chrooted(task))
50506 + return NULL;
50507 +
50508 + return task;
50509 }
50510
50511 struct task_struct *find_task_by_vpid(pid_t vnr)
50512 diff -urNp linux-2.6.37/kernel/posix-cpu-timers.c linux-2.6.37/kernel/posix-cpu-timers.c
50513 --- linux-2.6.37/kernel/posix-cpu-timers.c 2011-01-04 19:50:19.000000000 -0500
50514 +++ linux-2.6.37/kernel/posix-cpu-timers.c 2011-01-17 02:41:02.000000000 -0500
50515 @@ -6,6 +6,7 @@
50516 #include <linux/posix-timers.h>
50517 #include <linux/errno.h>
50518 #include <linux/math64.h>
50519 +#include <linux/security.h>
50520 #include <asm/uaccess.h>
50521 #include <linux/kernel_stat.h>
50522 #include <trace/events/timer.h>
50523 diff -urNp linux-2.6.37/kernel/posix-timers.c linux-2.6.37/kernel/posix-timers.c
50524 --- linux-2.6.37/kernel/posix-timers.c 2011-01-04 19:50:19.000000000 -0500
50525 +++ linux-2.6.37/kernel/posix-timers.c 2011-01-17 02:41:02.000000000 -0500
50526 @@ -42,6 +42,7 @@
50527 #include <linux/compiler.h>
50528 #include <linux/idr.h>
50529 #include <linux/posix-timers.h>
50530 +#include <linux/grsecurity.h>
50531 #include <linux/syscalls.h>
50532 #include <linux/wait.h>
50533 #include <linux/workqueue.h>
50534 @@ -949,6 +950,13 @@ SYSCALL_DEFINE2(clock_settime, const clo
50535 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
50536 return -EFAULT;
50537
50538 + /* only the CLOCK_REALTIME clock can be set, all other clocks
50539 + have their clock_set fptr set to a nosettime dummy function
50540 + CLOCK_REALTIME has a NULL clock_set fptr which causes it to
50541 + call common_clock_set, which calls do_sys_settimeofday, which
50542 + we hook
50543 + */
50544 +
50545 return CLOCK_DISPATCH(which_clock, clock_set, (which_clock, &new_tp));
50546 }
50547
50548 diff -urNp linux-2.6.37/kernel/power/hibernate.c linux-2.6.37/kernel/power/hibernate.c
50549 --- linux-2.6.37/kernel/power/hibernate.c 2011-01-04 19:50:19.000000000 -0500
50550 +++ linux-2.6.37/kernel/power/hibernate.c 2011-01-17 02:41:02.000000000 -0500
50551 @@ -51,14 +51,14 @@ enum {
50552
50553 static int hibernation_mode = HIBERNATION_SHUTDOWN;
50554
50555 -static struct platform_hibernation_ops *hibernation_ops;
50556 +static const struct platform_hibernation_ops *hibernation_ops;
50557
50558 /**
50559 * hibernation_set_ops - set the global hibernate operations
50560 * @ops: the hibernation operations to use in subsequent hibernation transitions
50561 */
50562
50563 -void hibernation_set_ops(struct platform_hibernation_ops *ops)
50564 +void hibernation_set_ops(const struct platform_hibernation_ops *ops)
50565 {
50566 if (ops && !(ops->begin && ops->end && ops->pre_snapshot
50567 && ops->prepare && ops->finish && ops->enter && ops->pre_restore
50568 diff -urNp linux-2.6.37/kernel/power/poweroff.c linux-2.6.37/kernel/power/poweroff.c
50569 --- linux-2.6.37/kernel/power/poweroff.c 2011-01-04 19:50:19.000000000 -0500
50570 +++ linux-2.6.37/kernel/power/poweroff.c 2011-01-17 02:41:02.000000000 -0500
50571 @@ -37,7 +37,7 @@ static struct sysrq_key_op sysrq_powerof
50572 .enable_mask = SYSRQ_ENABLE_BOOT,
50573 };
50574
50575 -static int pm_sysrq_init(void)
50576 +static int __init pm_sysrq_init(void)
50577 {
50578 register_sysrq_key('o', &sysrq_poweroff_op);
50579 return 0;
50580 diff -urNp linux-2.6.37/kernel/power/process.c linux-2.6.37/kernel/power/process.c
50581 --- linux-2.6.37/kernel/power/process.c 2011-01-04 19:50:19.000000000 -0500
50582 +++ linux-2.6.37/kernel/power/process.c 2011-01-17 02:41:02.000000000 -0500
50583 @@ -41,6 +41,7 @@ static int try_to_freeze_tasks(bool sig_
50584 u64 elapsed_csecs64;
50585 unsigned int elapsed_csecs;
50586 bool wakeup = false;
50587 + bool timedout = false;
50588
50589 do_gettimeofday(&start);
50590
50591 @@ -51,6 +52,8 @@ static int try_to_freeze_tasks(bool sig_
50592
50593 while (true) {
50594 todo = 0;
50595 + if (time_after(jiffies, end_time))
50596 + timedout = true;
50597 read_lock(&tasklist_lock);
50598 do_each_thread(g, p) {
50599 if (frozen(p) || !freezeable(p))
50600 @@ -65,9 +68,13 @@ static int try_to_freeze_tasks(bool sig_
50601 * It is "frozen enough". If the task does wake
50602 * up, it will immediately call try_to_freeze.
50603 */
50604 - if (!task_is_stopped_or_traced(p) &&
50605 - !freezer_should_skip(p))
50606 + if (!task_is_stopped_or_traced(p) && !freezer_should_skip(p)) {
50607 todo++;
50608 + if (timedout) {
50609 + printk(KERN_ERR "Task refusing to freeze:\n");
50610 + sched_show_task(p);
50611 + }
50612 + }
50613 } while_each_thread(g, p);
50614 read_unlock(&tasklist_lock);
50615
50616 @@ -76,7 +83,7 @@ static int try_to_freeze_tasks(bool sig_
50617 todo += wq_busy;
50618 }
50619
50620 - if (!todo || time_after(jiffies, end_time))
50621 + if (!todo || timedout)
50622 break;
50623
50624 if (!pm_check_wakeup_events()) {
50625 diff -urNp linux-2.6.37/kernel/power/suspend.c linux-2.6.37/kernel/power/suspend.c
50626 --- linux-2.6.37/kernel/power/suspend.c 2011-01-04 19:50:19.000000000 -0500
50627 +++ linux-2.6.37/kernel/power/suspend.c 2011-01-17 02:41:02.000000000 -0500
50628 @@ -30,13 +30,13 @@ const char *const pm_states[PM_SUSPEND_M
50629 [PM_SUSPEND_MEM] = "mem",
50630 };
50631
50632 -static struct platform_suspend_ops *suspend_ops;
50633 +static const struct platform_suspend_ops *suspend_ops;
50634
50635 /**
50636 * suspend_set_ops - Set the global suspend method table.
50637 * @ops: Pointer to ops structure.
50638 */
50639 -void suspend_set_ops(struct platform_suspend_ops *ops)
50640 +void suspend_set_ops(const struct platform_suspend_ops *ops)
50641 {
50642 mutex_lock(&pm_mutex);
50643 suspend_ops = ops;
50644 diff -urNp linux-2.6.37/kernel/printk.c linux-2.6.37/kernel/printk.c
50645 --- linux-2.6.37/kernel/printk.c 2011-01-04 19:50:19.000000000 -0500
50646 +++ linux-2.6.37/kernel/printk.c 2011-01-17 02:41:02.000000000 -0500
50647 @@ -274,6 +274,11 @@ int do_syslog(int type, char __user *buf
50648 char c;
50649 int error = 0;
50650
50651 +#ifdef CONFIG_GRKERNSEC_DMESG
50652 + if (grsec_enable_dmesg && !capable(CAP_SYS_ADMIN))
50653 + return -EPERM;
50654 +#endif
50655 +
50656 /*
50657 * If this is from /proc/kmsg we only do the capabilities checks
50658 * at open time.
50659 diff -urNp linux-2.6.37/kernel/ptrace.c linux-2.6.37/kernel/ptrace.c
50660 --- linux-2.6.37/kernel/ptrace.c 2011-01-04 19:50:19.000000000 -0500
50661 +++ linux-2.6.37/kernel/ptrace.c 2011-01-17 02:41:02.000000000 -0500
50662 @@ -140,7 +140,7 @@ int __ptrace_may_access(struct task_stru
50663 cred->gid != tcred->egid ||
50664 cred->gid != tcred->sgid ||
50665 cred->gid != tcred->gid) &&
50666 - !capable(CAP_SYS_PTRACE)) {
50667 + !capable_nolog(CAP_SYS_PTRACE)) {
50668 rcu_read_unlock();
50669 return -EPERM;
50670 }
50671 @@ -148,7 +148,7 @@ int __ptrace_may_access(struct task_stru
50672 smp_rmb();
50673 if (task->mm)
50674 dumpable = get_dumpable(task->mm);
50675 - if (!dumpable && !capable(CAP_SYS_PTRACE))
50676 + if (!dumpable && !capable_nolog(CAP_SYS_PTRACE))
50677 return -EPERM;
50678
50679 return security_ptrace_access_check(task, mode);
50680 @@ -198,7 +198,7 @@ int ptrace_attach(struct task_struct *ta
50681 goto unlock_tasklist;
50682
50683 task->ptrace = PT_PTRACED;
50684 - if (capable(CAP_SYS_PTRACE))
50685 + if (capable_nolog(CAP_SYS_PTRACE))
50686 task->ptrace |= PT_PTRACE_CAP;
50687
50688 __ptrace_link(task, current);
50689 @@ -369,7 +369,7 @@ int ptrace_readdata(struct task_struct *
50690 break;
50691 return -EIO;
50692 }
50693 - if (copy_to_user(dst, buf, retval))
50694 + if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
50695 return -EFAULT;
50696 copied += retval;
50697 src += retval;
50698 @@ -565,7 +565,7 @@ int ptrace_request(struct task_struct *c
50699 {
50700 int ret = -EIO;
50701 siginfo_t siginfo;
50702 - void __user *datavp = (void __user *) data;
50703 + void __user *datavp = (__force void __user *) data;
50704 unsigned long __user *datalp = datavp;
50705
50706 switch (request) {
50707 @@ -713,14 +713,21 @@ SYSCALL_DEFINE4(ptrace, long, request, l
50708 goto out;
50709 }
50710
50711 + if (gr_handle_ptrace(child, request)) {
50712 + ret = -EPERM;
50713 + goto out_put_task_struct;
50714 + }
50715 +
50716 if (request == PTRACE_ATTACH) {
50717 ret = ptrace_attach(child);
50718 /*
50719 * Some architectures need to do book-keeping after
50720 * a ptrace attach.
50721 */
50722 - if (!ret)
50723 + if (!ret) {
50724 arch_ptrace_attach(child);
50725 + gr_audit_ptrace(child);
50726 + }
50727 goto out_put_task_struct;
50728 }
50729
50730 @@ -745,7 +752,7 @@ int generic_ptrace_peekdata(struct task_
50731 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
50732 if (copied != sizeof(tmp))
50733 return -EIO;
50734 - return put_user(tmp, (unsigned long __user *)data);
50735 + return put_user(tmp, (__force unsigned long __user *)data);
50736 }
50737
50738 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
50739 @@ -855,14 +862,21 @@ asmlinkage long compat_sys_ptrace(compat
50740 goto out;
50741 }
50742
50743 + if (gr_handle_ptrace(child, request)) {
50744 + ret = -EPERM;
50745 + goto out_put_task_struct;
50746 + }
50747 +
50748 if (request == PTRACE_ATTACH) {
50749 ret = ptrace_attach(child);
50750 /*
50751 * Some architectures need to do book-keeping after
50752 * a ptrace attach.
50753 */
50754 - if (!ret)
50755 + if (!ret) {
50756 arch_ptrace_attach(child);
50757 + gr_audit_ptrace(child);
50758 + }
50759 goto out_put_task_struct;
50760 }
50761
50762 diff -urNp linux-2.6.37/kernel/rcutree.c linux-2.6.37/kernel/rcutree.c
50763 --- linux-2.6.37/kernel/rcutree.c 2011-01-04 19:50:19.000000000 -0500
50764 +++ linux-2.6.37/kernel/rcutree.c 2011-01-17 02:41:02.000000000 -0500
50765 @@ -1394,7 +1394,7 @@ __rcu_process_callbacks(struct rcu_state
50766 /*
50767 * Do softirq processing for the current CPU.
50768 */
50769 -static void rcu_process_callbacks(struct softirq_action *unused)
50770 +static void rcu_process_callbacks(void)
50771 {
50772 /*
50773 * Memory references from any prior RCU read-side critical sections
50774 diff -urNp linux-2.6.37/kernel/rcutree_plugin.h linux-2.6.37/kernel/rcutree_plugin.h
50775 --- linux-2.6.37/kernel/rcutree_plugin.h 2011-01-04 19:50:19.000000000 -0500
50776 +++ linux-2.6.37/kernel/rcutree_plugin.h 2011-01-17 02:41:02.000000000 -0500
50777 @@ -729,7 +729,7 @@ void synchronize_rcu_expedited(void)
50778
50779 /* Clean up and exit. */
50780 smp_mb(); /* ensure expedited GP seen before counter increment. */
50781 - ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
50782 + ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
50783 unlock_mb_ret:
50784 mutex_unlock(&sync_rcu_preempt_exp_mutex);
50785 mb_ret:
50786 diff -urNp linux-2.6.37/kernel/resource.c linux-2.6.37/kernel/resource.c
50787 --- linux-2.6.37/kernel/resource.c 2011-01-04 19:50:19.000000000 -0500
50788 +++ linux-2.6.37/kernel/resource.c 2011-01-17 02:41:02.000000000 -0500
50789 @@ -133,8 +133,18 @@ static const struct file_operations proc
50790
50791 static int __init ioresources_init(void)
50792 {
50793 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
50794 +#ifdef CONFIG_GRKERNSEC_PROC_USER
50795 + proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
50796 + proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
50797 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
50798 + proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
50799 + proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
50800 +#endif
50801 +#else
50802 proc_create("ioports", 0, NULL, &proc_ioports_operations);
50803 proc_create("iomem", 0, NULL, &proc_iomem_operations);
50804 +#endif
50805 return 0;
50806 }
50807 __initcall(ioresources_init);
50808 diff -urNp linux-2.6.37/kernel/rtmutex.c linux-2.6.37/kernel/rtmutex.c
50809 --- linux-2.6.37/kernel/rtmutex.c 2011-01-04 19:50:19.000000000 -0500
50810 +++ linux-2.6.37/kernel/rtmutex.c 2011-01-17 02:41:02.000000000 -0500
50811 @@ -511,7 +511,7 @@ static void wakeup_next_waiter(struct rt
50812 */
50813 raw_spin_lock_irqsave(&pendowner->pi_lock, flags);
50814
50815 - WARN_ON(!pendowner->pi_blocked_on);
50816 + BUG_ON(!pendowner->pi_blocked_on);
50817 WARN_ON(pendowner->pi_blocked_on != waiter);
50818 WARN_ON(pendowner->pi_blocked_on->lock != lock);
50819
50820 diff -urNp linux-2.6.37/kernel/sched.c linux-2.6.37/kernel/sched.c
50821 --- linux-2.6.37/kernel/sched.c 2011-01-04 19:50:19.000000000 -0500
50822 +++ linux-2.6.37/kernel/sched.c 2011-01-17 02:41:02.000000000 -0500
50823 @@ -4770,6 +4770,8 @@ int can_nice(const struct task_struct *p
50824 /* convert nice value [19,-20] to rlimit style value [1,40] */
50825 int nice_rlim = 20 - nice;
50826
50827 + gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
50828 +
50829 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
50830 capable(CAP_SYS_NICE));
50831 }
50832 @@ -4803,7 +4805,8 @@ SYSCALL_DEFINE1(nice, int, increment)
50833 if (nice > 19)
50834 nice = 19;
50835
50836 - if (increment < 0 && !can_nice(current, nice))
50837 + if (increment < 0 && (!can_nice(current, nice) ||
50838 + gr_handle_chroot_nice()))
50839 return -EPERM;
50840
50841 retval = security_task_setnice(current, nice);
50842 @@ -4946,6 +4949,7 @@ recheck:
50843 unsigned long rlim_rtprio =
50844 task_rlimit(p, RLIMIT_RTPRIO);
50845
50846 + gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
50847 /* can't set/change the rt policy */
50848 if (policy != p->policy && !rlim_rtprio)
50849 return -EPERM;
50850 @@ -7155,7 +7159,7 @@ static void init_sched_groups_power(int
50851 long power;
50852 int weight;
50853
50854 - WARN_ON(!sd || !sd->groups);
50855 + BUG_ON(!sd || !sd->groups);
50856
50857 if (cpu != group_first_cpu(sd->groups))
50858 return;
50859 diff -urNp linux-2.6.37/kernel/sched_fair.c linux-2.6.37/kernel/sched_fair.c
50860 --- linux-2.6.37/kernel/sched_fair.c 2011-01-04 19:50:19.000000000 -0500
50861 +++ linux-2.6.37/kernel/sched_fair.c 2011-01-17 02:41:02.000000000 -0500
50862 @@ -3724,7 +3724,7 @@ static void nohz_idle_balance(int this_c
50863 * run_rebalance_domains is triggered when needed from the scheduler tick.
50864 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
50865 */
50866 -static void run_rebalance_domains(struct softirq_action *h)
50867 +static void run_rebalance_domains(void)
50868 {
50869 int this_cpu = smp_processor_id();
50870 struct rq *this_rq = cpu_rq(this_cpu);
50871 diff -urNp linux-2.6.37/kernel/signal.c linux-2.6.37/kernel/signal.c
50872 --- linux-2.6.37/kernel/signal.c 2011-01-04 19:50:19.000000000 -0500
50873 +++ linux-2.6.37/kernel/signal.c 2011-01-17 02:41:02.000000000 -0500
50874 @@ -45,12 +45,12 @@ static struct kmem_cache *sigqueue_cache
50875
50876 int print_fatal_signals __read_mostly;
50877
50878 -static void __user *sig_handler(struct task_struct *t, int sig)
50879 +static __sighandler_t sig_handler(struct task_struct *t, int sig)
50880 {
50881 return t->sighand->action[sig - 1].sa.sa_handler;
50882 }
50883
50884 -static int sig_handler_ignored(void __user *handler, int sig)
50885 +static int sig_handler_ignored(__sighandler_t handler, int sig)
50886 {
50887 /* Is it explicitly or implicitly ignored? */
50888 return handler == SIG_IGN ||
50889 @@ -60,7 +60,7 @@ static int sig_handler_ignored(void __us
50890 static int sig_task_ignored(struct task_struct *t, int sig,
50891 int from_ancestor_ns)
50892 {
50893 - void __user *handler;
50894 + __sighandler_t handler;
50895
50896 handler = sig_handler(t, sig);
50897
50898 @@ -243,6 +243,9 @@ __sigqueue_alloc(int sig, struct task_st
50899 atomic_inc(&user->sigpending);
50900 rcu_read_unlock();
50901
50902 + if (!override_rlimit)
50903 + gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
50904 +
50905 if (override_rlimit ||
50906 atomic_read(&user->sigpending) <=
50907 task_rlimit(t, RLIMIT_SIGPENDING)) {
50908 @@ -367,7 +370,7 @@ flush_signal_handlers(struct task_struct
50909
50910 int unhandled_signal(struct task_struct *tsk, int sig)
50911 {
50912 - void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
50913 + __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
50914 if (is_global_init(tsk))
50915 return 1;
50916 if (handler != SIG_IGN && handler != SIG_DFL)
50917 @@ -678,6 +681,9 @@ static int check_kill_permission(int sig
50918 }
50919 }
50920
50921 + if (gr_handle_signal(t, sig))
50922 + return -EPERM;
50923 +
50924 return security_task_kill(t, info, sig, 0);
50925 }
50926
50927 @@ -1025,7 +1031,7 @@ __group_send_sig_info(int sig, struct si
50928 return send_signal(sig, info, p, 1);
50929 }
50930
50931 -static int
50932 +int
50933 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
50934 {
50935 return send_signal(sig, info, t, 0);
50936 @@ -1079,6 +1085,9 @@ force_sig_info(int sig, struct siginfo *
50937 ret = specific_send_sig_info(sig, info, t);
50938 spin_unlock_irqrestore(&t->sighand->siglock, flags);
50939
50940 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
50941 + gr_handle_crash(t, sig);
50942 +
50943 return ret;
50944 }
50945
50946 @@ -1137,8 +1146,11 @@ int group_send_sig_info(int sig, struct
50947 ret = check_kill_permission(sig, info, p);
50948 rcu_read_unlock();
50949
50950 - if (!ret && sig)
50951 + if (!ret && sig) {
50952 ret = do_send_sig_info(sig, info, p, true);
50953 + if (!ret)
50954 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
50955 + }
50956
50957 return ret;
50958 }
50959 diff -urNp linux-2.6.37/kernel/smp.c linux-2.6.37/kernel/smp.c
50960 --- linux-2.6.37/kernel/smp.c 2011-01-04 19:50:19.000000000 -0500
50961 +++ linux-2.6.37/kernel/smp.c 2011-01-17 02:41:02.000000000 -0500
50962 @@ -510,22 +510,22 @@ int smp_call_function(smp_call_func_t fu
50963 }
50964 EXPORT_SYMBOL(smp_call_function);
50965
50966 -void ipi_call_lock(void)
50967 +void ipi_call_lock(void) __acquires(call_function.lock)
50968 {
50969 raw_spin_lock(&call_function.lock);
50970 }
50971
50972 -void ipi_call_unlock(void)
50973 +void ipi_call_unlock(void) __releases(call_function.lock)
50974 {
50975 raw_spin_unlock(&call_function.lock);
50976 }
50977
50978 -void ipi_call_lock_irq(void)
50979 +void ipi_call_lock_irq(void) __acquires(call_function.lock)
50980 {
50981 raw_spin_lock_irq(&call_function.lock);
50982 }
50983
50984 -void ipi_call_unlock_irq(void)
50985 +void ipi_call_unlock_irq(void) __releases(call_function.lock)
50986 {
50987 raw_spin_unlock_irq(&call_function.lock);
50988 }
50989 diff -urNp linux-2.6.37/kernel/softirq.c linux-2.6.37/kernel/softirq.c
50990 --- linux-2.6.37/kernel/softirq.c 2011-01-04 19:50:19.000000000 -0500
50991 +++ linux-2.6.37/kernel/softirq.c 2011-01-17 02:41:02.000000000 -0500
50992 @@ -56,7 +56,7 @@ static struct softirq_action softirq_vec
50993
50994 static DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
50995
50996 -char *softirq_to_name[NR_SOFTIRQS] = {
50997 +const char * const softirq_to_name[NR_SOFTIRQS] = {
50998 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
50999 "TASKLET", "SCHED", "HRTIMER", "RCU"
51000 };
51001 @@ -206,7 +206,7 @@ EXPORT_SYMBOL(local_bh_enable_ip);
51002
51003 asmlinkage void __do_softirq(void)
51004 {
51005 - struct softirq_action *h;
51006 + const struct softirq_action *h;
51007 __u32 pending;
51008 int max_restart = MAX_SOFTIRQ_RESTART;
51009 int cpu;
51010 @@ -235,7 +235,7 @@ restart:
51011 kstat_incr_softirqs_this_cpu(vec_nr);
51012
51013 trace_softirq_entry(vec_nr);
51014 - h->action(h);
51015 + h->action();
51016 trace_softirq_exit(vec_nr);
51017 if (unlikely(prev_count != preempt_count())) {
51018 printk(KERN_ERR "huh, entered softirq %u %s %p"
51019 @@ -365,7 +365,7 @@ void raise_softirq(unsigned int nr)
51020 local_irq_restore(flags);
51021 }
51022
51023 -void open_softirq(int nr, void (*action)(struct softirq_action *))
51024 +void open_softirq(int nr, void (*action)(void))
51025 {
51026 softirq_vec[nr].action = action;
51027 }
51028 @@ -421,7 +421,7 @@ void __tasklet_hi_schedule_first(struct
51029
51030 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
51031
51032 -static void tasklet_action(struct softirq_action *a)
51033 +static void tasklet_action(void)
51034 {
51035 struct tasklet_struct *list;
51036
51037 @@ -456,7 +456,7 @@ static void tasklet_action(struct softir
51038 }
51039 }
51040
51041 -static void tasklet_hi_action(struct softirq_action *a)
51042 +static void tasklet_hi_action(void)
51043 {
51044 struct tasklet_struct *list;
51045
51046 diff -urNp linux-2.6.37/kernel/sys.c linux-2.6.37/kernel/sys.c
51047 --- linux-2.6.37/kernel/sys.c 2011-01-04 19:50:19.000000000 -0500
51048 +++ linux-2.6.37/kernel/sys.c 2011-01-17 02:41:02.000000000 -0500
51049 @@ -134,6 +134,12 @@ static int set_one_prio(struct task_stru
51050 error = -EACCES;
51051 goto out;
51052 }
51053 +
51054 + if (gr_handle_chroot_setpriority(p, niceval)) {
51055 + error = -EACCES;
51056 + goto out;
51057 + }
51058 +
51059 no_nice = security_task_setnice(p, niceval);
51060 if (no_nice) {
51061 error = no_nice;
51062 @@ -511,6 +517,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, g
51063 goto error;
51064 }
51065
51066 + if (gr_check_group_change(new->gid, new->egid, -1))
51067 + goto error;
51068 +
51069 if (rgid != (gid_t) -1 ||
51070 (egid != (gid_t) -1 && egid != old->gid))
51071 new->sgid = new->egid;
51072 @@ -540,6 +549,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
51073 old = current_cred();
51074
51075 retval = -EPERM;
51076 +
51077 + if (gr_check_group_change(gid, gid, gid))
51078 + goto error;
51079 +
51080 if (capable(CAP_SETGID))
51081 new->gid = new->egid = new->sgid = new->fsgid = gid;
51082 else if (gid == old->gid || gid == old->sgid)
51083 @@ -620,6 +633,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, u
51084 goto error;
51085 }
51086
51087 + if (gr_check_user_change(new->uid, new->euid, -1))
51088 + goto error;
51089 +
51090 if (new->uid != old->uid) {
51091 retval = set_user(new);
51092 if (retval < 0)
51093 @@ -664,6 +680,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
51094 old = current_cred();
51095
51096 retval = -EPERM;
51097 +
51098 + if (gr_check_crash_uid(uid))
51099 + goto error;
51100 + if (gr_check_user_change(uid, uid, uid))
51101 + goto error;
51102 +
51103 if (capable(CAP_SETUID)) {
51104 new->suid = new->uid = uid;
51105 if (uid != old->uid) {
51106 @@ -718,6 +740,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid,
51107 goto error;
51108 }
51109
51110 + if (gr_check_user_change(ruid, euid, -1))
51111 + goto error;
51112 +
51113 if (ruid != (uid_t) -1) {
51114 new->uid = ruid;
51115 if (ruid != old->uid) {
51116 @@ -782,6 +807,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid,
51117 goto error;
51118 }
51119
51120 + if (gr_check_group_change(rgid, egid, -1))
51121 + goto error;
51122 +
51123 if (rgid != (gid_t) -1)
51124 new->gid = rgid;
51125 if (egid != (gid_t) -1)
51126 @@ -828,6 +856,9 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
51127 old = current_cred();
51128 old_fsuid = old->fsuid;
51129
51130 + if (gr_check_user_change(-1, -1, uid))
51131 + goto error;
51132 +
51133 if (uid == old->uid || uid == old->euid ||
51134 uid == old->suid || uid == old->fsuid ||
51135 capable(CAP_SETUID)) {
51136 @@ -838,6 +869,7 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
51137 }
51138 }
51139
51140 +error:
51141 abort_creds(new);
51142 return old_fsuid;
51143
51144 @@ -864,12 +896,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
51145 if (gid == old->gid || gid == old->egid ||
51146 gid == old->sgid || gid == old->fsgid ||
51147 capable(CAP_SETGID)) {
51148 + if (gr_check_group_change(-1, -1, gid))
51149 + goto error;
51150 +
51151 if (gid != old_fsgid) {
51152 new->fsgid = gid;
51153 goto change_okay;
51154 }
51155 }
51156
51157 +error:
51158 abort_creds(new);
51159 return old_fsgid;
51160
51161 @@ -1607,7 +1643,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsi
51162 error = get_dumpable(me->mm);
51163 break;
51164 case PR_SET_DUMPABLE:
51165 - if (arg2 < 0 || arg2 > 1) {
51166 + if (arg2 > 1) {
51167 error = -EINVAL;
51168 break;
51169 }
51170 diff -urNp linux-2.6.37/kernel/sysctl.c linux-2.6.37/kernel/sysctl.c
51171 --- linux-2.6.37/kernel/sysctl.c 2011-01-04 19:50:19.000000000 -0500
51172 +++ linux-2.6.37/kernel/sysctl.c 2011-01-17 02:41:02.000000000 -0500
51173 @@ -83,6 +83,13 @@
51174
51175
51176 #if defined(CONFIG_SYSCTL)
51177 +#include <linux/grsecurity.h>
51178 +#include <linux/grinternal.h>
51179 +
51180 +extern __u32 gr_handle_sysctl(const ctl_table *table, const int op);
51181 +extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
51182 + const int op);
51183 +extern int gr_handle_chroot_sysctl(const int op);
51184
51185 /* External variables not in a header file. */
51186 extern int sysctl_overcommit_memory;
51187 @@ -188,6 +195,7 @@ static int sysrq_sysctl_handler(ctl_tabl
51188 }
51189
51190 #endif
51191 +extern struct ctl_table grsecurity_table[];
51192
51193 static struct ctl_table root_table[];
51194 static struct ctl_table_root sysctl_table_root;
51195 @@ -217,6 +225,20 @@ extern struct ctl_table epoll_table[];
51196 int sysctl_legacy_va_layout;
51197 #endif
51198
51199 +#ifdef CONFIG_PAX_SOFTMODE
51200 +static ctl_table pax_table[] = {
51201 + {
51202 + .procname = "softmode",
51203 + .data = &pax_softmode,
51204 + .maxlen = sizeof(unsigned int),
51205 + .mode = 0600,
51206 + .proc_handler = &proc_dointvec,
51207 + },
51208 +
51209 + { }
51210 +};
51211 +#endif
51212 +
51213 /* The default sysctl tables: */
51214
51215 static struct ctl_table root_table[] = {
51216 @@ -269,6 +291,22 @@ static int max_extfrag_threshold = 1000;
51217 #endif
51218
51219 static struct ctl_table kern_table[] = {
51220 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
51221 + {
51222 + .procname = "grsecurity",
51223 + .mode = 0500,
51224 + .child = grsecurity_table,
51225 + },
51226 +#endif
51227 +
51228 +#ifdef CONFIG_PAX_SOFTMODE
51229 + {
51230 + .procname = "pax",
51231 + .mode = 0500,
51232 + .child = pax_table,
51233 + },
51234 +#endif
51235 +
51236 {
51237 .procname = "sched_child_runs_first",
51238 .data = &sysctl_sched_child_runs_first,
51239 @@ -549,7 +587,7 @@ static struct ctl_table kern_table[] = {
51240 .data = &modprobe_path,
51241 .maxlen = KMOD_PATH_LEN,
51242 .mode = 0644,
51243 - .proc_handler = proc_dostring,
51244 + .proc_handler = proc_dostring_modpriv,
51245 },
51246 {
51247 .procname = "modules_disabled",
51248 @@ -1180,6 +1218,13 @@ static struct ctl_table vm_table[] = {
51249 .proc_handler = proc_dointvec_minmax,
51250 .extra1 = &zero,
51251 },
51252 + {
51253 + .procname = "heap_stack_gap",
51254 + .data = &sysctl_heap_stack_gap,
51255 + .maxlen = sizeof(sysctl_heap_stack_gap),
51256 + .mode = 0644,
51257 + .proc_handler = proc_doulongvec_minmax,
51258 + },
51259 #else
51260 {
51261 .procname = "nr_trim_pages",
51262 @@ -1695,6 +1740,16 @@ int sysctl_perm(struct ctl_table_root *r
51263 int error;
51264 int mode;
51265
51266 + if (table->parent != NULL && table->parent->procname != NULL &&
51267 + table->procname != NULL &&
51268 + gr_handle_sysctl_mod(table->parent->procname, table->procname, op))
51269 + return -EACCES;
51270 + if (gr_handle_chroot_sysctl(op))
51271 + return -EACCES;
51272 + error = gr_handle_sysctl(table, op);
51273 + if (error)
51274 + return error;
51275 +
51276 error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
51277 if (error)
51278 return error;
51279 @@ -2102,6 +2157,16 @@ int proc_dostring(struct ctl_table *tabl
51280 buffer, lenp, ppos);
51281 }
51282
51283 +int proc_dostring_modpriv(struct ctl_table *table, int write,
51284 + void __user *buffer, size_t *lenp, loff_t *ppos)
51285 +{
51286 + if (write && !capable(CAP_SYS_MODULE))
51287 + return -EPERM;
51288 +
51289 + return _proc_do_string(table->data, table->maxlen, write,
51290 + buffer, lenp, ppos);
51291 +}
51292 +
51293 static size_t proc_skip_spaces(char **buf)
51294 {
51295 size_t ret;
51296 @@ -2207,6 +2272,8 @@ static int proc_put_long(void __user **b
51297 len = strlen(tmp);
51298 if (len > *size)
51299 len = *size;
51300 + if (len > sizeof(tmp))
51301 + len = sizeof(tmp);
51302 if (copy_to_user(*buf, tmp, len))
51303 return -EFAULT;
51304 *size -= len;
51305 @@ -2512,8 +2579,11 @@ static int __do_proc_doulongvec_minmax(v
51306 *i = val;
51307 } else {
51308 val = convdiv * (*i) / convmul;
51309 - if (!first)
51310 + if (!first) {
51311 err = proc_put_char(&buffer, &left, '\t');
51312 + if (err)
51313 + break;
51314 + }
51315 err = proc_put_long(&buffer, &left, val, false);
51316 if (err)
51317 break;
51318 @@ -2908,6 +2978,12 @@ int proc_dostring(struct ctl_table *tabl
51319 return -ENOSYS;
51320 }
51321
51322 +int proc_dostring_modpriv(struct ctl_table *table, int write,
51323 + void __user *buffer, size_t *lenp, loff_t *ppos)
51324 +{
51325 + return -ENOSYS;
51326 +}
51327 +
51328 int proc_dointvec(struct ctl_table *table, int write,
51329 void __user *buffer, size_t *lenp, loff_t *ppos)
51330 {
51331 @@ -2964,6 +3040,7 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
51332 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
51333 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
51334 EXPORT_SYMBOL(proc_dostring);
51335 +EXPORT_SYMBOL(proc_dostring_modpriv);
51336 EXPORT_SYMBOL(proc_doulongvec_minmax);
51337 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
51338 EXPORT_SYMBOL(register_sysctl_table);
51339 diff -urNp linux-2.6.37/kernel/sysctl_check.c linux-2.6.37/kernel/sysctl_check.c
51340 --- linux-2.6.37/kernel/sysctl_check.c 2011-01-04 19:50:19.000000000 -0500
51341 +++ linux-2.6.37/kernel/sysctl_check.c 2011-01-17 02:41:02.000000000 -0500
51342 @@ -131,6 +131,7 @@ int sysctl_check_table(struct nsproxy *n
51343 set_fail(&fail, table, "Directory with extra2");
51344 } else {
51345 if ((table->proc_handler == proc_dostring) ||
51346 + (table->proc_handler == proc_dostring_modpriv) ||
51347 (table->proc_handler == proc_dointvec) ||
51348 (table->proc_handler == proc_dointvec_minmax) ||
51349 (table->proc_handler == proc_dointvec_jiffies) ||
51350 diff -urNp linux-2.6.37/kernel/taskstats.c linux-2.6.37/kernel/taskstats.c
51351 --- linux-2.6.37/kernel/taskstats.c 2011-01-04 19:50:19.000000000 -0500
51352 +++ linux-2.6.37/kernel/taskstats.c 2011-01-17 02:41:02.000000000 -0500
51353 @@ -27,9 +27,12 @@
51354 #include <linux/cgroup.h>
51355 #include <linux/fs.h>
51356 #include <linux/file.h>
51357 +#include <linux/grsecurity.h>
51358 #include <net/genetlink.h>
51359 #include <asm/atomic.h>
51360
51361 +extern int gr_is_taskstats_denied(int pid);
51362 +
51363 /*
51364 * Maximum length of a cpumask that can be specified in
51365 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
51366 @@ -550,6 +553,9 @@ err:
51367
51368 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
51369 {
51370 + if (gr_is_taskstats_denied(current->pid))
51371 + return -EACCES;
51372 +
51373 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
51374 return cmd_attr_register_cpumask(info);
51375 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
51376 diff -urNp linux-2.6.37/kernel/time/tick-broadcast.c linux-2.6.37/kernel/time/tick-broadcast.c
51377 --- linux-2.6.37/kernel/time/tick-broadcast.c 2011-01-04 19:50:19.000000000 -0500
51378 +++ linux-2.6.37/kernel/time/tick-broadcast.c 2011-01-17 02:41:02.000000000 -0500
51379 @@ -116,7 +116,7 @@ int tick_device_uses_broadcast(struct cl
51380 * then clear the broadcast bit.
51381 */
51382 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
51383 - int cpu = smp_processor_id();
51384 + cpu = smp_processor_id();
51385
51386 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
51387 tick_broadcast_clear_oneshot(cpu);
51388 diff -urNp linux-2.6.37/kernel/time/timekeeping.c linux-2.6.37/kernel/time/timekeeping.c
51389 --- linux-2.6.37/kernel/time/timekeeping.c 2011-01-04 19:50:19.000000000 -0500
51390 +++ linux-2.6.37/kernel/time/timekeeping.c 2011-01-17 02:41:02.000000000 -0500
51391 @@ -14,6 +14,7 @@
51392 #include <linux/init.h>
51393 #include <linux/mm.h>
51394 #include <linux/sched.h>
51395 +#include <linux/grsecurity.h>
51396 #include <linux/sysdev.h>
51397 #include <linux/clocksource.h>
51398 #include <linux/jiffies.h>
51399 @@ -314,6 +315,8 @@ int do_settimeofday(struct timespec *tv)
51400 if ((unsigned long)tv->tv_nsec >= NSEC_PER_SEC)
51401 return -EINVAL;
51402
51403 + gr_log_timechange();
51404 +
51405 write_seqlock_irqsave(&xtime_lock, flags);
51406
51407 timekeeping_forward_now();
51408 diff -urNp linux-2.6.37/kernel/time/timer_list.c linux-2.6.37/kernel/time/timer_list.c
51409 --- linux-2.6.37/kernel/time/timer_list.c 2011-01-04 19:50:19.000000000 -0500
51410 +++ linux-2.6.37/kernel/time/timer_list.c 2011-01-17 02:41:02.000000000 -0500
51411 @@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base,
51412
51413 static void print_name_offset(struct seq_file *m, void *sym)
51414 {
51415 +#ifdef CONFIG_GRKERNSEC_HIDESYM
51416 + SEQ_printf(m, "<%p>", NULL);
51417 +#else
51418 char symname[KSYM_NAME_LEN];
51419
51420 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
51421 SEQ_printf(m, "<%p>", sym);
51422 else
51423 SEQ_printf(m, "%s", symname);
51424 +#endif
51425 }
51426
51427 static void
51428 @@ -112,7 +116,11 @@ next_one:
51429 static void
51430 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
51431 {
51432 +#ifdef CONFIG_GRKERNSEC_HIDESYM
51433 + SEQ_printf(m, " .base: %p\n", NULL);
51434 +#else
51435 SEQ_printf(m, " .base: %p\n", base);
51436 +#endif
51437 SEQ_printf(m, " .index: %d\n",
51438 base->index);
51439 SEQ_printf(m, " .resolution: %Lu nsecs\n",
51440 @@ -293,7 +301,11 @@ static int __init init_timer_list_procfs
51441 {
51442 struct proc_dir_entry *pe;
51443
51444 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
51445 + pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
51446 +#else
51447 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
51448 +#endif
51449 if (!pe)
51450 return -ENOMEM;
51451 return 0;
51452 diff -urNp linux-2.6.37/kernel/time/timer_stats.c linux-2.6.37/kernel/time/timer_stats.c
51453 --- linux-2.6.37/kernel/time/timer_stats.c 2011-01-04 19:50:19.000000000 -0500
51454 +++ linux-2.6.37/kernel/time/timer_stats.c 2011-01-17 02:41:02.000000000 -0500
51455 @@ -269,12 +269,16 @@ void timer_stats_update_stats(void *time
51456
51457 static void print_name_offset(struct seq_file *m, unsigned long addr)
51458 {
51459 +#ifdef CONFIG_GRKERNSEC_HIDESYM
51460 + seq_printf(m, "<%p>", NULL);
51461 +#else
51462 char symname[KSYM_NAME_LEN];
51463
51464 if (lookup_symbol_name(addr, symname) < 0)
51465 seq_printf(m, "<%p>", (void *)addr);
51466 else
51467 seq_printf(m, "%s", symname);
51468 +#endif
51469 }
51470
51471 static int tstats_show(struct seq_file *m, void *v)
51472 @@ -417,7 +421,11 @@ static int __init init_tstats_procfs(voi
51473 {
51474 struct proc_dir_entry *pe;
51475
51476 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
51477 + pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
51478 +#else
51479 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
51480 +#endif
51481 if (!pe)
51482 return -ENOMEM;
51483 return 0;
51484 diff -urNp linux-2.6.37/kernel/time.c linux-2.6.37/kernel/time.c
51485 --- linux-2.6.37/kernel/time.c 2011-01-04 19:50:19.000000000 -0500
51486 +++ linux-2.6.37/kernel/time.c 2011-01-17 02:41:02.000000000 -0500
51487 @@ -163,6 +163,11 @@ int do_sys_settimeofday(struct timespec
51488 return error;
51489
51490 if (tz) {
51491 + /* we log in do_settimeofday called below, so don't log twice
51492 + */
51493 + if (!tv)
51494 + gr_log_timechange();
51495 +
51496 /* SMP safe, global irq locking makes it work. */
51497 sys_tz = *tz;
51498 update_vsyscall_tz();
51499 @@ -238,7 +243,7 @@ EXPORT_SYMBOL(current_fs_time);
51500 * Avoid unnecessary multiplications/divisions in the
51501 * two most common HZ cases:
51502 */
51503 -unsigned int inline jiffies_to_msecs(const unsigned long j)
51504 +inline unsigned int jiffies_to_msecs(const unsigned long j)
51505 {
51506 #if HZ <= MSEC_PER_SEC && !(MSEC_PER_SEC % HZ)
51507 return (MSEC_PER_SEC / HZ) * j;
51508 @@ -254,7 +259,7 @@ unsigned int inline jiffies_to_msecs(con
51509 }
51510 EXPORT_SYMBOL(jiffies_to_msecs);
51511
51512 -unsigned int inline jiffies_to_usecs(const unsigned long j)
51513 +inline unsigned int jiffies_to_usecs(const unsigned long j)
51514 {
51515 #if HZ <= USEC_PER_SEC && !(USEC_PER_SEC % HZ)
51516 return (USEC_PER_SEC / HZ) * j;
51517 diff -urNp linux-2.6.37/kernel/timer.c linux-2.6.37/kernel/timer.c
51518 --- linux-2.6.37/kernel/timer.c 2011-01-04 19:50:19.000000000 -0500
51519 +++ linux-2.6.37/kernel/timer.c 2011-01-17 02:41:02.000000000 -0500
51520 @@ -1296,7 +1296,7 @@ void update_process_times(int user_tick)
51521 /*
51522 * This function runs timers and the timer-tq in bottom half context.
51523 */
51524 -static void run_timer_softirq(struct softirq_action *h)
51525 +static void run_timer_softirq(void)
51526 {
51527 struct tvec_base *base = __get_cpu_var(tvec_bases);
51528
51529 diff -urNp linux-2.6.37/kernel/trace/ftrace.c linux-2.6.37/kernel/trace/ftrace.c
51530 --- linux-2.6.37/kernel/trace/ftrace.c 2011-01-04 19:50:19.000000000 -0500
51531 +++ linux-2.6.37/kernel/trace/ftrace.c 2011-01-17 02:41:02.000000000 -0500
51532 @@ -1107,13 +1107,18 @@ ftrace_code_disable(struct module *mod,
51533
51534 ip = rec->ip;
51535
51536 + ret = ftrace_arch_code_modify_prepare();
51537 + FTRACE_WARN_ON(ret);
51538 + if (ret)
51539 + return 0;
51540 +
51541 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
51542 + FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
51543 if (ret) {
51544 ftrace_bug(ret, ip);
51545 rec->flags |= FTRACE_FL_FAILED;
51546 - return 0;
51547 }
51548 - return 1;
51549 + return ret ? 0 : 1;
51550 }
51551
51552 /*
51553 diff -urNp linux-2.6.37/kernel/trace/ring_buffer.c linux-2.6.37/kernel/trace/ring_buffer.c
51554 --- linux-2.6.37/kernel/trace/ring_buffer.c 2011-01-04 19:50:19.000000000 -0500
51555 +++ linux-2.6.37/kernel/trace/ring_buffer.c 2011-01-17 02:41:02.000000000 -0500
51556 @@ -669,7 +669,7 @@ static struct list_head *rb_list_head(st
51557 * the reader page). But if the next page is a header page,
51558 * its flags will be non zero.
51559 */
51560 -static int inline
51561 +static inline int
51562 rb_is_head_page(struct ring_buffer_per_cpu *cpu_buffer,
51563 struct buffer_page *page, struct list_head *list)
51564 {
51565 diff -urNp linux-2.6.37/kernel/trace/trace.c linux-2.6.37/kernel/trace/trace.c
51566 --- linux-2.6.37/kernel/trace/trace.c 2011-01-04 19:50:19.000000000 -0500
51567 +++ linux-2.6.37/kernel/trace/trace.c 2011-01-17 02:41:02.000000000 -0500
51568 @@ -3969,10 +3969,9 @@ static const struct file_operations trac
51569 };
51570 #endif
51571
51572 -static struct dentry *d_tracer;
51573 -
51574 struct dentry *tracing_init_dentry(void)
51575 {
51576 + static struct dentry *d_tracer;
51577 static int once;
51578
51579 if (d_tracer)
51580 @@ -3992,10 +3991,9 @@ struct dentry *tracing_init_dentry(void)
51581 return d_tracer;
51582 }
51583
51584 -static struct dentry *d_percpu;
51585 -
51586 struct dentry *tracing_dentry_percpu(void)
51587 {
51588 + static struct dentry *d_percpu;
51589 static int once;
51590 struct dentry *d_tracer;
51591
51592 diff -urNp linux-2.6.37/kernel/trace/trace_events.c linux-2.6.37/kernel/trace/trace_events.c
51593 --- linux-2.6.37/kernel/trace/trace_events.c 2011-01-04 19:50:19.000000000 -0500
51594 +++ linux-2.6.37/kernel/trace/trace_events.c 2011-01-17 02:41:02.000000000 -0500
51595 @@ -1231,6 +1231,7 @@ static LIST_HEAD(ftrace_module_file_list
51596 * Modules must own their file_operations to keep up with
51597 * reference counting.
51598 */
51599 +/* cannot be const, see trace_create_file_ops() */
51600 struct ftrace_module_file_ops {
51601 struct list_head list;
51602 struct module *mod;
51603 diff -urNp linux-2.6.37/kernel/trace/trace_output.c linux-2.6.37/kernel/trace/trace_output.c
51604 --- linux-2.6.37/kernel/trace/trace_output.c 2011-01-04 19:50:19.000000000 -0500
51605 +++ linux-2.6.37/kernel/trace/trace_output.c 2011-01-17 02:41:02.000000000 -0500
51606 @@ -278,7 +278,7 @@ int trace_seq_path(struct trace_seq *s,
51607
51608 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
51609 if (!IS_ERR(p)) {
51610 - p = mangle_path(s->buffer + s->len, p, "\n");
51611 + p = mangle_path(s->buffer + s->len, p, "\n\\");
51612 if (p) {
51613 s->len = p - s->buffer;
51614 return 1;
51615 diff -urNp linux-2.6.37/kernel/trace/trace_stack.c linux-2.6.37/kernel/trace/trace_stack.c
51616 --- linux-2.6.37/kernel/trace/trace_stack.c 2011-01-04 19:50:19.000000000 -0500
51617 +++ linux-2.6.37/kernel/trace/trace_stack.c 2011-01-17 02:41:02.000000000 -0500
51618 @@ -50,7 +50,7 @@ static inline void check_stack(void)
51619 return;
51620
51621 /* we do not handle interrupt stacks yet */
51622 - if (!object_is_on_stack(&this_size))
51623 + if (!object_starts_on_stack(&this_size))
51624 return;
51625
51626 local_irq_save(flags);
51627 diff -urNp linux-2.6.37/lib/bug.c linux-2.6.37/lib/bug.c
51628 --- linux-2.6.37/lib/bug.c 2011-01-04 19:50:19.000000000 -0500
51629 +++ linux-2.6.37/lib/bug.c 2011-01-17 02:41:02.000000000 -0500
51630 @@ -133,6 +133,8 @@ enum bug_trap_type report_bug(unsigned l
51631 return BUG_TRAP_TYPE_NONE;
51632
51633 bug = find_bug(bugaddr);
51634 + if (!bug)
51635 + return BUG_TRAP_TYPE_NONE;
51636
51637 file = NULL;
51638 line = 0;
51639 diff -urNp linux-2.6.37/lib/debugobjects.c linux-2.6.37/lib/debugobjects.c
51640 --- linux-2.6.37/lib/debugobjects.c 2011-01-04 19:50:19.000000000 -0500
51641 +++ linux-2.6.37/lib/debugobjects.c 2011-01-17 02:41:02.000000000 -0500
51642 @@ -281,7 +281,7 @@ static void debug_object_is_on_stack(voi
51643 if (limit > 4)
51644 return;
51645
51646 - is_on_stack = object_is_on_stack(addr);
51647 + is_on_stack = object_starts_on_stack(addr);
51648 if (is_on_stack == onstack)
51649 return;
51650
51651 diff -urNp linux-2.6.37/lib/dma-debug.c linux-2.6.37/lib/dma-debug.c
51652 --- linux-2.6.37/lib/dma-debug.c 2011-01-04 19:50:19.000000000 -0500
51653 +++ linux-2.6.37/lib/dma-debug.c 2011-01-17 02:41:02.000000000 -0500
51654 @@ -862,7 +862,7 @@ out:
51655
51656 static void check_for_stack(struct device *dev, void *addr)
51657 {
51658 - if (object_is_on_stack(addr))
51659 + if (object_starts_on_stack(addr))
51660 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
51661 "stack [addr=%p]\n", addr);
51662 }
51663 diff -urNp linux-2.6.37/lib/inflate.c linux-2.6.37/lib/inflate.c
51664 --- linux-2.6.37/lib/inflate.c 2011-01-04 19:50:19.000000000 -0500
51665 +++ linux-2.6.37/lib/inflate.c 2011-01-17 02:41:02.000000000 -0500
51666 @@ -269,7 +269,7 @@ static void free(void *where)
51667 malloc_ptr = free_mem_ptr;
51668 }
51669 #else
51670 -#define malloc(a) kmalloc(a, GFP_KERNEL)
51671 +#define malloc(a) kmalloc((a), GFP_KERNEL)
51672 #define free(a) kfree(a)
51673 #endif
51674
51675 diff -urNp linux-2.6.37/lib/Kconfig.debug linux-2.6.37/lib/Kconfig.debug
51676 --- linux-2.6.37/lib/Kconfig.debug 2011-01-04 19:50:19.000000000 -0500
51677 +++ linux-2.6.37/lib/Kconfig.debug 2011-01-17 02:41:02.000000000 -0500
51678 @@ -1065,6 +1065,7 @@ config LATENCYTOP
51679 depends on DEBUG_KERNEL
51680 depends on STACKTRACE_SUPPORT
51681 depends on PROC_FS
51682 + depends on !GRKERNSEC_HIDESYM
51683 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE
51684 select KALLSYMS
51685 select KALLSYMS_ALL
51686 diff -urNp linux-2.6.37/lib/kref.c linux-2.6.37/lib/kref.c
51687 --- linux-2.6.37/lib/kref.c 2011-01-04 19:50:19.000000000 -0500
51688 +++ linux-2.6.37/lib/kref.c 2011-01-17 02:41:02.000000000 -0500
51689 @@ -52,7 +52,7 @@ void kref_get(struct kref *kref)
51690 */
51691 int kref_put(struct kref *kref, void (*release)(struct kref *kref))
51692 {
51693 - WARN_ON(release == NULL);
51694 + BUG_ON(release == NULL);
51695 WARN_ON(release == (void (*)(struct kref *))kfree);
51696
51697 if (atomic_dec_and_test(&kref->refcount)) {
51698 diff -urNp linux-2.6.37/lib/radix-tree.c linux-2.6.37/lib/radix-tree.c
51699 --- linux-2.6.37/lib/radix-tree.c 2011-01-04 19:50:19.000000000 -0500
51700 +++ linux-2.6.37/lib/radix-tree.c 2011-01-17 02:41:02.000000000 -0500
51701 @@ -80,7 +80,7 @@ struct radix_tree_preload {
51702 int nr;
51703 struct radix_tree_node *nodes[RADIX_TREE_MAX_PATH];
51704 };
51705 -static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
51706 +static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
51707
51708 static inline void *ptr_to_indirect(void *ptr)
51709 {
51710 diff -urNp linux-2.6.37/lib/vsprintf.c linux-2.6.37/lib/vsprintf.c
51711 --- linux-2.6.37/lib/vsprintf.c 2011-01-04 19:50:19.000000000 -0500
51712 +++ linux-2.6.37/lib/vsprintf.c 2011-01-17 02:41:02.000000000 -0500
51713 @@ -16,6 +16,9 @@
51714 * - scnprintf and vscnprintf
51715 */
51716
51717 +#ifdef CONFIG_GRKERNSEC_HIDESYM
51718 +#define __INCLUDED_BY_HIDESYM 1
51719 +#endif
51720 #include <stdarg.h>
51721 #include <linux/module.h>
51722 #include <linux/types.h>
51723 @@ -574,7 +577,7 @@ char *symbol_string(char *buf, char *end
51724 unsigned long value = (unsigned long) ptr;
51725 #ifdef CONFIG_KALLSYMS
51726 char sym[KSYM_SYMBOL_LEN];
51727 - if (ext != 'f' && ext != 's')
51728 + if (ext != 'f' && ext != 's' && ext != 'a')
51729 sprint_symbol(sym, value);
51730 else
51731 kallsyms_lookup(value, NULL, NULL, NULL, sym);
51732 @@ -947,6 +950,8 @@ char *uuid_string(char *buf, char *end,
51733 * - 'f' For simple symbolic function names without offset
51734 * - 'S' For symbolic direct pointers with offset
51735 * - 's' For symbolic direct pointers without offset
51736 + * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
51737 + * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
51738 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
51739 * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
51740 * - 'M' For a 6-byte MAC address, it prints the address in the
51741 @@ -990,12 +995,12 @@ char *pointer(const char *fmt, char *buf
51742 {
51743 if (!ptr) {
51744 /*
51745 - * Print (null) with the same width as a pointer so it makes
51746 + * Print (nil) with the same width as a pointer so it makes
51747 * tabular output look nice.
51748 */
51749 if (spec.field_width == -1)
51750 spec.field_width = 2 * sizeof(void *);
51751 - return string(buf, end, "(null)", spec);
51752 + return string(buf, end, "(nil)", spec);
51753 }
51754
51755 switch (*fmt) {
51756 @@ -1005,6 +1010,13 @@ char *pointer(const char *fmt, char *buf
51757 /* Fallthrough */
51758 case 'S':
51759 case 's':
51760 +#ifdef CONFIG_GRKERNSEC_HIDESYM
51761 + break;
51762 +#else
51763 + return symbol_string(buf, end, ptr, spec, *fmt);
51764 +#endif
51765 + case 'A':
51766 + case 'a':
51767 return symbol_string(buf, end, ptr, spec, *fmt);
51768 case 'R':
51769 case 'r':
51770 @@ -1750,11 +1762,11 @@ int bstr_printf(char *buf, size_t size,
51771 typeof(type) value; \
51772 if (sizeof(type) == 8) { \
51773 args = PTR_ALIGN(args, sizeof(u32)); \
51774 - *(u32 *)&value = *(u32 *)args; \
51775 - *((u32 *)&value + 1) = *(u32 *)(args + 4); \
51776 + *(u32 *)&value = *(const u32 *)args; \
51777 + *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
51778 } else { \
51779 args = PTR_ALIGN(args, sizeof(type)); \
51780 - value = *(typeof(type) *)args; \
51781 + value = *(const typeof(type) *)args; \
51782 } \
51783 args += sizeof(type); \
51784 value; \
51785 @@ -1817,7 +1829,7 @@ int bstr_printf(char *buf, size_t size,
51786 case FORMAT_TYPE_STR: {
51787 const char *str_arg = args;
51788 args += strlen(str_arg) + 1;
51789 - str = string(str, end, (char *)str_arg, spec);
51790 + str = string(str, end, str_arg, spec);
51791 break;
51792 }
51793
51794 diff -urNp linux-2.6.37/localversion-grsec linux-2.6.37/localversion-grsec
51795 --- linux-2.6.37/localversion-grsec 1969-12-31 19:00:00.000000000 -0500
51796 +++ linux-2.6.37/localversion-grsec 2011-01-17 02:41:02.000000000 -0500
51797 @@ -0,0 +1 @@
51798 +-grsec
51799 diff -urNp linux-2.6.37/Makefile linux-2.6.37/Makefile
51800 --- linux-2.6.37/Makefile 2011-01-04 19:50:19.000000000 -0500
51801 +++ linux-2.6.37/Makefile 2011-01-17 02:41:02.000000000 -0500
51802 @@ -232,8 +232,8 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH"
51803
51804 HOSTCC = gcc
51805 HOSTCXX = g++
51806 -HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
51807 -HOSTCXXFLAGS = -O2
51808 +HOSTCFLAGS = -Wall -W -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer -fno-delete-null-pointer-checks
51809 +HOSTCXXFLAGS = -O2 -fno-delete-null-pointer-checks
51810
51811 # Decide whether to build built-in, modular, or both.
51812 # Normally, just do built-in.
51813 @@ -680,7 +680,7 @@ export mod_strip_cmd
51814
51815
51816 ifeq ($(KBUILD_EXTMOD),)
51817 -core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
51818 +core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
51819
51820 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
51821 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
51822 diff -urNp linux-2.6.37/mm/bootmem.c linux-2.6.37/mm/bootmem.c
51823 --- linux-2.6.37/mm/bootmem.c 2011-01-04 19:50:19.000000000 -0500
51824 +++ linux-2.6.37/mm/bootmem.c 2011-01-17 02:41:02.000000000 -0500
51825 @@ -201,19 +201,30 @@ static void __init __free_pages_memory(u
51826 unsigned long __init free_all_memory_core_early(int nodeid)
51827 {
51828 int i;
51829 - u64 start, end;
51830 + u64 start, end, startrange, endrange;
51831 unsigned long count = 0;
51832 - struct range *range = NULL;
51833 + struct range *range = NULL, rangerange = { 0, 0 };
51834 int nr_range;
51835
51836 nr_range = get_free_all_memory_range(&range, nodeid);
51837 + startrange = __pa(range) >> PAGE_SHIFT;
51838 + endrange = (__pa(range + nr_range) - 1) >> PAGE_SHIFT;
51839
51840 for (i = 0; i < nr_range; i++) {
51841 start = range[i].start;
51842 end = range[i].end;
51843 + if (start <= endrange && startrange < end) {
51844 + BUG_ON(rangerange.start | rangerange.end);
51845 + rangerange = range[i];
51846 + continue;
51847 + }
51848 count += end - start;
51849 __free_pages_memory(start, end);
51850 }
51851 + start = rangerange.start;
51852 + end = rangerange.end;
51853 + count += end - start;
51854 + __free_pages_memory(start, end);
51855
51856 return count;
51857 }
51858 diff -urNp linux-2.6.37/mm/filemap.c linux-2.6.37/mm/filemap.c
51859 --- linux-2.6.37/mm/filemap.c 2011-01-04 19:50:19.000000000 -0500
51860 +++ linux-2.6.37/mm/filemap.c 2011-01-17 02:41:02.000000000 -0500
51861 @@ -1660,7 +1660,7 @@ int generic_file_mmap(struct file * file
51862 struct address_space *mapping = file->f_mapping;
51863
51864 if (!mapping->a_ops->readpage)
51865 - return -ENOEXEC;
51866 + return -ENODEV;
51867 file_accessed(file);
51868 vma->vm_ops = &generic_file_vm_ops;
51869 vma->vm_flags |= VM_CAN_NONLINEAR;
51870 @@ -2056,6 +2056,7 @@ inline int generic_write_checks(struct f
51871 *pos = i_size_read(inode);
51872
51873 if (limit != RLIM_INFINITY) {
51874 + gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
51875 if (*pos >= limit) {
51876 send_sig(SIGXFSZ, current, 0);
51877 return -EFBIG;
51878 diff -urNp linux-2.6.37/mm/fremap.c linux-2.6.37/mm/fremap.c
51879 --- linux-2.6.37/mm/fremap.c 2011-01-04 19:50:19.000000000 -0500
51880 +++ linux-2.6.37/mm/fremap.c 2011-01-17 02:41:02.000000000 -0500
51881 @@ -156,6 +156,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsign
51882 retry:
51883 vma = find_vma(mm, start);
51884
51885 +#ifdef CONFIG_PAX_SEGMEXEC
51886 + if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
51887 + goto out;
51888 +#endif
51889 +
51890 /*
51891 * Make sure the vma is shared, that it supports prefaulting,
51892 * and that the remapped range is valid and fully within
51893 @@ -224,7 +229,7 @@ SYSCALL_DEFINE5(remap_file_pages, unsign
51894 /*
51895 * drop PG_Mlocked flag for over-mapped range
51896 */
51897 - unsigned int saved_flags = vma->vm_flags;
51898 + unsigned long saved_flags = vma->vm_flags;
51899 munlock_vma_pages_range(vma, start, start + size);
51900 vma->vm_flags = saved_flags;
51901 }
51902 diff -urNp linux-2.6.37/mm/highmem.c linux-2.6.37/mm/highmem.c
51903 --- linux-2.6.37/mm/highmem.c 2011-01-04 19:50:19.000000000 -0500
51904 +++ linux-2.6.37/mm/highmem.c 2011-01-17 02:41:02.000000000 -0500
51905 @@ -125,9 +125,10 @@ static void flush_all_zero_pkmaps(void)
51906 * So no dangers, even with speculative execution.
51907 */
51908 page = pte_page(pkmap_page_table[i]);
51909 + pax_open_kernel();
51910 pte_clear(&init_mm, (unsigned long)page_address(page),
51911 &pkmap_page_table[i]);
51912 -
51913 + pax_close_kernel();
51914 set_page_address(page, NULL);
51915 need_flush = 1;
51916 }
51917 @@ -186,9 +187,11 @@ start:
51918 }
51919 }
51920 vaddr = PKMAP_ADDR(last_pkmap_nr);
51921 +
51922 + pax_open_kernel();
51923 set_pte_at(&init_mm, vaddr,
51924 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
51925 -
51926 + pax_close_kernel();
51927 pkmap_count[last_pkmap_nr] = 1;
51928 set_page_address(page, (void *)vaddr);
51929
51930 diff -urNp linux-2.6.37/mm/hugetlb.c linux-2.6.37/mm/hugetlb.c
51931 --- linux-2.6.37/mm/hugetlb.c 2011-01-04 19:50:19.000000000 -0500
51932 +++ linux-2.6.37/mm/hugetlb.c 2011-01-17 02:41:02.000000000 -0500
51933 @@ -2373,6 +2373,27 @@ static int unmap_ref_private(struct mm_s
51934 return 1;
51935 }
51936
51937 +#ifdef CONFIG_PAX_SEGMEXEC
51938 +static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
51939 +{
51940 + struct mm_struct *mm = vma->vm_mm;
51941 + struct vm_area_struct *vma_m;
51942 + unsigned long address_m;
51943 + pte_t *ptep_m;
51944 +
51945 + vma_m = pax_find_mirror_vma(vma);
51946 + if (!vma_m)
51947 + return;
51948 +
51949 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
51950 + address_m = address + SEGMEXEC_TASK_SIZE;
51951 + ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
51952 + get_page(page_m);
51953 + hugepage_add_anon_rmap(page_m, vma_m, address_m);
51954 + set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
51955 +}
51956 +#endif
51957 +
51958 /*
51959 * Hugetlb_cow() should be called with page lock of the original hugepage held.
51960 */
51961 @@ -2473,6 +2494,11 @@ retry_avoidcopy:
51962 make_huge_pte(vma, new_page, 1));
51963 page_remove_rmap(old_page);
51964 hugepage_add_new_anon_rmap(new_page, vma, address);
51965 +
51966 +#ifdef CONFIG_PAX_SEGMEXEC
51967 + pax_mirror_huge_pte(vma, address, new_page);
51968 +#endif
51969 +
51970 /* Make the old page be freed below */
51971 new_page = old_page;
51972 mmu_notifier_invalidate_range_end(mm,
51973 @@ -2624,6 +2650,10 @@ retry:
51974 && (vma->vm_flags & VM_SHARED)));
51975 set_huge_pte_at(mm, address, ptep, new_pte);
51976
51977 +#ifdef CONFIG_PAX_SEGMEXEC
51978 + pax_mirror_huge_pte(vma, address, page);
51979 +#endif
51980 +
51981 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
51982 /* Optimization, do the COW without a second fault */
51983 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
51984 @@ -2653,6 +2683,10 @@ int hugetlb_fault(struct mm_struct *mm,
51985 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
51986 struct hstate *h = hstate_vma(vma);
51987
51988 +#ifdef CONFIG_PAX_SEGMEXEC
51989 + struct vm_area_struct *vma_m;
51990 +#endif
51991 +
51992 ptep = huge_pte_offset(mm, address);
51993 if (ptep) {
51994 entry = huge_ptep_get(ptep);
51995 @@ -2664,6 +2698,26 @@ int hugetlb_fault(struct mm_struct *mm,
51996 VM_FAULT_SET_HINDEX(h - hstates);
51997 }
51998
51999 +#ifdef CONFIG_PAX_SEGMEXEC
52000 + vma_m = pax_find_mirror_vma(vma);
52001 + if (vma_m) {
52002 + unsigned long address_m;
52003 +
52004 + if (vma->vm_start > vma_m->vm_start) {
52005 + address_m = address;
52006 + address -= SEGMEXEC_TASK_SIZE;
52007 + vma = vma_m;
52008 + h = hstate_vma(vma);
52009 + } else
52010 + address_m = address + SEGMEXEC_TASK_SIZE;
52011 +
52012 + if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
52013 + return VM_FAULT_OOM;
52014 + address_m &= HPAGE_MASK;
52015 + unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
52016 + }
52017 +#endif
52018 +
52019 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
52020 if (!ptep)
52021 return VM_FAULT_OOM;
52022 diff -urNp linux-2.6.37/mm/Kconfig linux-2.6.37/mm/Kconfig
52023 --- linux-2.6.37/mm/Kconfig 2011-01-04 19:50:19.000000000 -0500
52024 +++ linux-2.6.37/mm/Kconfig 2011-01-17 02:41:02.000000000 -0500
52025 @@ -240,7 +240,7 @@ config KSM
52026 config DEFAULT_MMAP_MIN_ADDR
52027 int "Low address space to protect from user allocation"
52028 depends on MMU
52029 - default 4096
52030 + default 65536
52031 help
52032 This is the portion of low virtual memory which should be protected
52033 from userspace allocation. Keeping a user from writing to low pages
52034 diff -urNp linux-2.6.37/mm/kmemleak.c linux-2.6.37/mm/kmemleak.c
52035 --- linux-2.6.37/mm/kmemleak.c 2011-01-04 19:50:19.000000000 -0500
52036 +++ linux-2.6.37/mm/kmemleak.c 2011-01-17 02:41:02.000000000 -0500
52037 @@ -355,7 +355,7 @@ static void print_unreferenced(struct se
52038
52039 for (i = 0; i < object->trace_len; i++) {
52040 void *ptr = (void *)object->trace[i];
52041 - seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
52042 + seq_printf(seq, " [<%p>] %pA\n", ptr, ptr);
52043 }
52044 }
52045
52046 diff -urNp linux-2.6.37/mm/maccess.c linux-2.6.37/mm/maccess.c
52047 --- linux-2.6.37/mm/maccess.c 2011-01-04 19:50:19.000000000 -0500
52048 +++ linux-2.6.37/mm/maccess.c 2011-01-17 02:41:02.000000000 -0500
52049 @@ -15,10 +15,10 @@
52050 * happens, handle that and return -EFAULT.
52051 */
52052
52053 -long __weak probe_kernel_read(void *dst, void *src, size_t size)
52054 +long __weak probe_kernel_read(void *dst, const void *src, size_t size)
52055 __attribute__((alias("__probe_kernel_read")));
52056
52057 -long __probe_kernel_read(void *dst, void *src, size_t size)
52058 +long __probe_kernel_read(void *dst, const void *src, size_t size)
52059 {
52060 long ret;
52061 mm_segment_t old_fs = get_fs();
52062 @@ -43,10 +43,10 @@ EXPORT_SYMBOL_GPL(probe_kernel_read);
52063 * Safely write to address @dst from the buffer at @src. If a kernel fault
52064 * happens, handle that and return -EFAULT.
52065 */
52066 -long __weak probe_kernel_write(void *dst, void *src, size_t size)
52067 +long __weak probe_kernel_write(void *dst, const void *src, size_t size)
52068 __attribute__((alias("__probe_kernel_write")));
52069
52070 -long __probe_kernel_write(void *dst, void *src, size_t size)
52071 +long __probe_kernel_write(void *dst, const void *src, size_t size)
52072 {
52073 long ret;
52074 mm_segment_t old_fs = get_fs();
52075 diff -urNp linux-2.6.37/mm/madvise.c linux-2.6.37/mm/madvise.c
52076 --- linux-2.6.37/mm/madvise.c 2011-01-04 19:50:19.000000000 -0500
52077 +++ linux-2.6.37/mm/madvise.c 2011-01-17 02:41:02.000000000 -0500
52078 @@ -45,6 +45,10 @@ static long madvise_behavior(struct vm_a
52079 pgoff_t pgoff;
52080 unsigned long new_flags = vma->vm_flags;
52081
52082 +#ifdef CONFIG_PAX_SEGMEXEC
52083 + struct vm_area_struct *vma_m;
52084 +#endif
52085 +
52086 switch (behavior) {
52087 case MADV_NORMAL:
52088 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
52089 @@ -104,6 +108,13 @@ success:
52090 /*
52091 * vm_flags is protected by the mmap_sem held in write mode.
52092 */
52093 +
52094 +#ifdef CONFIG_PAX_SEGMEXEC
52095 + vma_m = pax_find_mirror_vma(vma);
52096 + if (vma_m)
52097 + vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
52098 +#endif
52099 +
52100 vma->vm_flags = new_flags;
52101
52102 out:
52103 @@ -162,6 +173,11 @@ static long madvise_dontneed(struct vm_a
52104 struct vm_area_struct ** prev,
52105 unsigned long start, unsigned long end)
52106 {
52107 +
52108 +#ifdef CONFIG_PAX_SEGMEXEC
52109 + struct vm_area_struct *vma_m;
52110 +#endif
52111 +
52112 *prev = vma;
52113 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
52114 return -EINVAL;
52115 @@ -174,6 +190,21 @@ static long madvise_dontneed(struct vm_a
52116 zap_page_range(vma, start, end - start, &details);
52117 } else
52118 zap_page_range(vma, start, end - start, NULL);
52119 +
52120 +#ifdef CONFIG_PAX_SEGMEXEC
52121 + vma_m = pax_find_mirror_vma(vma);
52122 + if (vma_m) {
52123 + if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
52124 + struct zap_details details = {
52125 + .nonlinear_vma = vma_m,
52126 + .last_index = ULONG_MAX,
52127 + };
52128 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
52129 + } else
52130 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
52131 + }
52132 +#endif
52133 +
52134 return 0;
52135 }
52136
52137 @@ -366,6 +397,16 @@ SYSCALL_DEFINE3(madvise, unsigned long,
52138 if (end < start)
52139 goto out;
52140
52141 +#ifdef CONFIG_PAX_SEGMEXEC
52142 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
52143 + if (end > SEGMEXEC_TASK_SIZE)
52144 + goto out;
52145 + } else
52146 +#endif
52147 +
52148 + if (end > TASK_SIZE)
52149 + goto out;
52150 +
52151 error = 0;
52152 if (end == start)
52153 goto out;
52154 diff -urNp linux-2.6.37/mm/memory.c linux-2.6.37/mm/memory.c
52155 --- linux-2.6.37/mm/memory.c 2011-01-04 19:50:19.000000000 -0500
52156 +++ linux-2.6.37/mm/memory.c 2011-01-17 02:41:02.000000000 -0500
52157 @@ -259,8 +259,12 @@ static inline void free_pmd_range(struct
52158 return;
52159
52160 pmd = pmd_offset(pud, start);
52161 +
52162 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
52163 pud_clear(pud);
52164 pmd_free_tlb(tlb, pmd, start);
52165 +#endif
52166 +
52167 }
52168
52169 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
52170 @@ -291,9 +295,12 @@ static inline void free_pud_range(struct
52171 if (end - 1 > ceiling - 1)
52172 return;
52173
52174 +#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
52175 pud = pud_offset(pgd, start);
52176 pgd_clear(pgd);
52177 pud_free_tlb(tlb, pud, start);
52178 +#endif
52179 +
52180 }
52181
52182 /*
52183 @@ -1361,10 +1368,10 @@ int __get_user_pages(struct task_struct
52184 (VM_MAYREAD | VM_MAYWRITE) : (VM_READ | VM_WRITE);
52185 i = 0;
52186
52187 - do {
52188 + while (nr_pages) {
52189 struct vm_area_struct *vma;
52190
52191 - vma = find_extend_vma(mm, start);
52192 + vma = find_vma(mm, start);
52193 if (!vma && in_gate_area(tsk, start)) {
52194 unsigned long pg = start & PAGE_MASK;
52195 struct vm_area_struct *gate_vma = get_gate_vma(tsk);
52196 @@ -1416,7 +1423,7 @@ int __get_user_pages(struct task_struct
52197 continue;
52198 }
52199
52200 - if (!vma ||
52201 + if (!vma || start < vma->vm_start ||
52202 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
52203 !(vm_flags & vma->vm_flags))
52204 return i ? : -EFAULT;
52205 @@ -1492,7 +1499,7 @@ int __get_user_pages(struct task_struct
52206 start += PAGE_SIZE;
52207 nr_pages--;
52208 } while (nr_pages && start < vma->vm_end);
52209 - } while (nr_pages);
52210 + }
52211 return i;
52212 }
52213
52214 @@ -1637,6 +1644,10 @@ static int insert_page(struct vm_area_st
52215 page_add_file_rmap(page);
52216 set_pte_at(mm, addr, pte, mk_pte(page, prot));
52217
52218 +#ifdef CONFIG_PAX_SEGMEXEC
52219 + pax_mirror_file_pte(vma, addr, page, ptl);
52220 +#endif
52221 +
52222 retval = 0;
52223 pte_unmap_unlock(pte, ptl);
52224 return retval;
52225 @@ -1671,10 +1682,22 @@ out:
52226 int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
52227 struct page *page)
52228 {
52229 +
52230 +#ifdef CONFIG_PAX_SEGMEXEC
52231 + struct vm_area_struct *vma_m;
52232 +#endif
52233 +
52234 if (addr < vma->vm_start || addr >= vma->vm_end)
52235 return -EFAULT;
52236 if (!page_count(page))
52237 return -EINVAL;
52238 +
52239 +#ifdef CONFIG_PAX_SEGMEXEC
52240 + vma_m = pax_find_mirror_vma(vma);
52241 + if (vma_m)
52242 + vma_m->vm_flags |= VM_INSERTPAGE;
52243 +#endif
52244 +
52245 vma->vm_flags |= VM_INSERTPAGE;
52246 return insert_page(vma, addr, page, vma->vm_page_prot);
52247 }
52248 @@ -1760,6 +1783,7 @@ int vm_insert_mixed(struct vm_area_struc
52249 unsigned long pfn)
52250 {
52251 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
52252 + BUG_ON(vma->vm_mirror);
52253
52254 if (addr < vma->vm_start || addr >= vma->vm_end)
52255 return -EFAULT;
52256 @@ -2087,6 +2111,186 @@ static inline void cow_user_page(struct
52257 copy_user_highpage(dst, src, va, vma);
52258 }
52259
52260 +#ifdef CONFIG_PAX_SEGMEXEC
52261 +static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
52262 +{
52263 + struct mm_struct *mm = vma->vm_mm;
52264 + spinlock_t *ptl;
52265 + pte_t *pte, entry;
52266 +
52267 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
52268 + entry = *pte;
52269 + if (!pte_present(entry)) {
52270 + if (!pte_none(entry)) {
52271 + BUG_ON(pte_file(entry));
52272 + free_swap_and_cache(pte_to_swp_entry(entry));
52273 + pte_clear_not_present_full(mm, address, pte, 0);
52274 + }
52275 + } else {
52276 + struct page *page;
52277 +
52278 + flush_cache_page(vma, address, pte_pfn(entry));
52279 + entry = ptep_clear_flush(vma, address, pte);
52280 + BUG_ON(pte_dirty(entry));
52281 + page = vm_normal_page(vma, address, entry);
52282 + if (page) {
52283 + update_hiwater_rss(mm);
52284 + if (PageAnon(page))
52285 + dec_mm_counter_fast(mm, MM_ANONPAGES);
52286 + else
52287 + dec_mm_counter_fast(mm, MM_FILEPAGES);
52288 + page_remove_rmap(page);
52289 + page_cache_release(page);
52290 + }
52291 + }
52292 + pte_unmap_unlock(pte, ptl);
52293 +}
52294 +
52295 +/* PaX: if vma is mirrored, synchronize the mirror's PTE
52296 + *
52297 + * the ptl of the lower mapped page is held on entry and is not released on exit
52298 + * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
52299 + */
52300 +static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
52301 +{
52302 + struct mm_struct *mm = vma->vm_mm;
52303 + unsigned long address_m;
52304 + spinlock_t *ptl_m;
52305 + struct vm_area_struct *vma_m;
52306 + pmd_t *pmd_m;
52307 + pte_t *pte_m, entry_m;
52308 +
52309 + BUG_ON(!page_m || !PageAnon(page_m));
52310 +
52311 + vma_m = pax_find_mirror_vma(vma);
52312 + if (!vma_m)
52313 + return;
52314 +
52315 + BUG_ON(!PageLocked(page_m));
52316 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
52317 + address_m = address + SEGMEXEC_TASK_SIZE;
52318 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
52319 + pte_m = pte_offset_map(pmd_m, address_m);
52320 + ptl_m = pte_lockptr(mm, pmd_m);
52321 + if (ptl != ptl_m) {
52322 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
52323 + if (!pte_none(*pte_m))
52324 + goto out;
52325 + }
52326 +
52327 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
52328 + page_cache_get(page_m);
52329 + page_add_anon_rmap(page_m, vma_m, address_m);
52330 + inc_mm_counter_fast(mm, MM_ANONPAGES);
52331 + set_pte_at(mm, address_m, pte_m, entry_m);
52332 + update_mmu_cache(vma_m, address_m, entry_m);
52333 +out:
52334 + if (ptl != ptl_m)
52335 + spin_unlock(ptl_m);
52336 + pte_unmap(pte_m);
52337 + unlock_page(page_m);
52338 +}
52339 +
52340 +void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
52341 +{
52342 + struct mm_struct *mm = vma->vm_mm;
52343 + unsigned long address_m;
52344 + spinlock_t *ptl_m;
52345 + struct vm_area_struct *vma_m;
52346 + pmd_t *pmd_m;
52347 + pte_t *pte_m, entry_m;
52348 +
52349 + BUG_ON(!page_m || PageAnon(page_m));
52350 +
52351 + vma_m = pax_find_mirror_vma(vma);
52352 + if (!vma_m)
52353 + return;
52354 +
52355 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
52356 + address_m = address + SEGMEXEC_TASK_SIZE;
52357 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
52358 + pte_m = pte_offset_map(pmd_m, address_m);
52359 + ptl_m = pte_lockptr(mm, pmd_m);
52360 + if (ptl != ptl_m) {
52361 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
52362 + if (!pte_none(*pte_m))
52363 + goto out;
52364 + }
52365 +
52366 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
52367 + page_cache_get(page_m);
52368 + page_add_file_rmap(page_m);
52369 + inc_mm_counter_fast(mm, MM_FILEPAGES);
52370 + set_pte_at(mm, address_m, pte_m, entry_m);
52371 + update_mmu_cache(vma_m, address_m, entry_m);
52372 +out:
52373 + if (ptl != ptl_m)
52374 + spin_unlock(ptl_m);
52375 + pte_unmap(pte_m);
52376 +}
52377 +
52378 +static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
52379 +{
52380 + struct mm_struct *mm = vma->vm_mm;
52381 + unsigned long address_m;
52382 + spinlock_t *ptl_m;
52383 + struct vm_area_struct *vma_m;
52384 + pmd_t *pmd_m;
52385 + pte_t *pte_m, entry_m;
52386 +
52387 + vma_m = pax_find_mirror_vma(vma);
52388 + if (!vma_m)
52389 + return;
52390 +
52391 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
52392 + address_m = address + SEGMEXEC_TASK_SIZE;
52393 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
52394 + pte_m = pte_offset_map(pmd_m, address_m);
52395 + ptl_m = pte_lockptr(mm, pmd_m);
52396 + if (ptl != ptl_m) {
52397 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
52398 + if (!pte_none(*pte_m))
52399 + goto out;
52400 + }
52401 +
52402 + entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
52403 + set_pte_at(mm, address_m, pte_m, entry_m);
52404 +out:
52405 + if (ptl != ptl_m)
52406 + spin_unlock(ptl_m);
52407 + pte_unmap(pte_m);
52408 +}
52409 +
52410 +static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
52411 +{
52412 + struct page *page_m;
52413 + pte_t entry;
52414 +
52415 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
52416 + goto out;
52417 +
52418 + entry = *pte;
52419 + page_m = vm_normal_page(vma, address, entry);
52420 + if (!page_m)
52421 + pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
52422 + else if (PageAnon(page_m)) {
52423 + if (pax_find_mirror_vma(vma)) {
52424 + pte_unmap_unlock(pte, ptl);
52425 + lock_page(page_m);
52426 + pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
52427 + if (pte_same(entry, *pte))
52428 + pax_mirror_anon_pte(vma, address, page_m, ptl);
52429 + else
52430 + unlock_page(page_m);
52431 + }
52432 + } else
52433 + pax_mirror_file_pte(vma, address, page_m, ptl);
52434 +
52435 +out:
52436 + pte_unmap_unlock(pte, ptl);
52437 +}
52438 +#endif
52439 +
52440 /*
52441 * This routine handles present pages, when users try to write
52442 * to a shared page. It is done by copying the page to a new address
52443 @@ -2274,6 +2478,12 @@ gotten:
52444 */
52445 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
52446 if (likely(pte_same(*page_table, orig_pte))) {
52447 +
52448 +#ifdef CONFIG_PAX_SEGMEXEC
52449 + if (pax_find_mirror_vma(vma))
52450 + BUG_ON(!trylock_page(new_page));
52451 +#endif
52452 +
52453 if (old_page) {
52454 if (!PageAnon(old_page)) {
52455 dec_mm_counter_fast(mm, MM_FILEPAGES);
52456 @@ -2325,6 +2535,10 @@ gotten:
52457 page_remove_rmap(old_page);
52458 }
52459
52460 +#ifdef CONFIG_PAX_SEGMEXEC
52461 + pax_mirror_anon_pte(vma, address, new_page, ptl);
52462 +#endif
52463 +
52464 /* Free the old page.. */
52465 new_page = old_page;
52466 ret |= VM_FAULT_WRITE;
52467 @@ -2756,6 +2970,11 @@ static int do_swap_page(struct mm_struct
52468 swap_free(entry);
52469 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
52470 try_to_free_swap(page);
52471 +
52472 +#ifdef CONFIG_PAX_SEGMEXEC
52473 + if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
52474 +#endif
52475 +
52476 unlock_page(page);
52477 if (swapcache) {
52478 /*
52479 @@ -2779,6 +2998,11 @@ static int do_swap_page(struct mm_struct
52480
52481 /* No need to invalidate - it was non-present before */
52482 update_mmu_cache(vma, address, page_table);
52483 +
52484 +#ifdef CONFIG_PAX_SEGMEXEC
52485 + pax_mirror_anon_pte(vma, address, page, ptl);
52486 +#endif
52487 +
52488 unlock:
52489 pte_unmap_unlock(page_table, ptl);
52490 out:
52491 @@ -2798,40 +3022,6 @@ out_release:
52492 }
52493
52494 /*
52495 - * This is like a special single-page "expand_{down|up}wards()",
52496 - * except we must first make sure that 'address{-|+}PAGE_SIZE'
52497 - * doesn't hit another vma.
52498 - */
52499 -static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
52500 -{
52501 - address &= PAGE_MASK;
52502 - if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
52503 - struct vm_area_struct *prev = vma->vm_prev;
52504 -
52505 - /*
52506 - * Is there a mapping abutting this one below?
52507 - *
52508 - * That's only ok if it's the same stack mapping
52509 - * that has gotten split..
52510 - */
52511 - if (prev && prev->vm_end == address)
52512 - return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
52513 -
52514 - expand_stack(vma, address - PAGE_SIZE);
52515 - }
52516 - if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
52517 - struct vm_area_struct *next = vma->vm_next;
52518 -
52519 - /* As VM_GROWSDOWN but s/below/above/ */
52520 - if (next && next->vm_start == address + PAGE_SIZE)
52521 - return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
52522 -
52523 - expand_upwards(vma, address + PAGE_SIZE);
52524 - }
52525 - return 0;
52526 -}
52527 -
52528 -/*
52529 * We enter with non-exclusive mmap_sem (to exclude vma changes,
52530 * but allow concurrent faults), and pte mapped but not yet locked.
52531 * We return with mmap_sem still held, but pte unmapped and unlocked.
52532 @@ -2840,27 +3030,23 @@ static int do_anonymous_page(struct mm_s
52533 unsigned long address, pte_t *page_table, pmd_t *pmd,
52534 unsigned int flags)
52535 {
52536 - struct page *page;
52537 + struct page *page = NULL;
52538 spinlock_t *ptl;
52539 pte_t entry;
52540
52541 - pte_unmap(page_table);
52542 -
52543 - /* Check if we need to add a guard page to the stack */
52544 - if (check_stack_guard_page(vma, address) < 0)
52545 - return VM_FAULT_SIGBUS;
52546 -
52547 - /* Use the zero-page for reads */
52548 if (!(flags & FAULT_FLAG_WRITE)) {
52549 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
52550 vma->vm_page_prot));
52551 - page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
52552 + ptl = pte_lockptr(mm, pmd);
52553 + spin_lock(ptl);
52554 if (!pte_none(*page_table))
52555 goto unlock;
52556 goto setpte;
52557 }
52558
52559 /* Allocate our own private page. */
52560 + pte_unmap(page_table);
52561 +
52562 if (unlikely(anon_vma_prepare(vma)))
52563 goto oom;
52564 page = alloc_zeroed_user_highpage_movable(vma, address);
52565 @@ -2879,6 +3065,11 @@ static int do_anonymous_page(struct mm_s
52566 if (!pte_none(*page_table))
52567 goto release;
52568
52569 +#ifdef CONFIG_PAX_SEGMEXEC
52570 + if (pax_find_mirror_vma(vma))
52571 + BUG_ON(!trylock_page(page));
52572 +#endif
52573 +
52574 inc_mm_counter_fast(mm, MM_ANONPAGES);
52575 page_add_new_anon_rmap(page, vma, address);
52576 setpte:
52577 @@ -2886,6 +3077,12 @@ setpte:
52578
52579 /* No need to invalidate - it was non-present before */
52580 update_mmu_cache(vma, address, page_table);
52581 +
52582 +#ifdef CONFIG_PAX_SEGMEXEC
52583 + if (page)
52584 + pax_mirror_anon_pte(vma, address, page, ptl);
52585 +#endif
52586 +
52587 unlock:
52588 pte_unmap_unlock(page_table, ptl);
52589 return 0;
52590 @@ -3029,6 +3226,12 @@ static int __do_fault(struct mm_struct *
52591 */
52592 /* Only go through if we didn't race with anybody else... */
52593 if (likely(pte_same(*page_table, orig_pte))) {
52594 +
52595 +#ifdef CONFIG_PAX_SEGMEXEC
52596 + if (anon && pax_find_mirror_vma(vma))
52597 + BUG_ON(!trylock_page(page));
52598 +#endif
52599 +
52600 flush_icache_page(vma, page);
52601 entry = mk_pte(page, vma->vm_page_prot);
52602 if (flags & FAULT_FLAG_WRITE)
52603 @@ -3048,6 +3251,14 @@ static int __do_fault(struct mm_struct *
52604
52605 /* no need to invalidate: a not-present page won't be cached */
52606 update_mmu_cache(vma, address, page_table);
52607 +
52608 +#ifdef CONFIG_PAX_SEGMEXEC
52609 + if (anon)
52610 + pax_mirror_anon_pte(vma, address, page, ptl);
52611 + else
52612 + pax_mirror_file_pte(vma, address, page, ptl);
52613 +#endif
52614 +
52615 } else {
52616 if (charged)
52617 mem_cgroup_uncharge_page(page);
52618 @@ -3195,6 +3406,12 @@ static inline int handle_pte_fault(struc
52619 if (flags & FAULT_FLAG_WRITE)
52620 flush_tlb_fix_spurious_fault(vma, address);
52621 }
52622 +
52623 +#ifdef CONFIG_PAX_SEGMEXEC
52624 + pax_mirror_pte(vma, address, pte, pmd, ptl);
52625 + return 0;
52626 +#endif
52627 +
52628 unlock:
52629 pte_unmap_unlock(pte, ptl);
52630 return 0;
52631 @@ -3211,6 +3428,10 @@ int handle_mm_fault(struct mm_struct *mm
52632 pmd_t *pmd;
52633 pte_t *pte;
52634
52635 +#ifdef CONFIG_PAX_SEGMEXEC
52636 + struct vm_area_struct *vma_m;
52637 +#endif
52638 +
52639 __set_current_state(TASK_RUNNING);
52640
52641 count_vm_event(PGFAULT);
52642 @@ -3221,6 +3442,34 @@ int handle_mm_fault(struct mm_struct *mm
52643 if (unlikely(is_vm_hugetlb_page(vma)))
52644 return hugetlb_fault(mm, vma, address, flags);
52645
52646 +#ifdef CONFIG_PAX_SEGMEXEC
52647 + vma_m = pax_find_mirror_vma(vma);
52648 + if (vma_m) {
52649 + unsigned long address_m;
52650 + pgd_t *pgd_m;
52651 + pud_t *pud_m;
52652 + pmd_t *pmd_m;
52653 +
52654 + if (vma->vm_start > vma_m->vm_start) {
52655 + address_m = address;
52656 + address -= SEGMEXEC_TASK_SIZE;
52657 + vma = vma_m;
52658 + } else
52659 + address_m = address + SEGMEXEC_TASK_SIZE;
52660 +
52661 + pgd_m = pgd_offset(mm, address_m);
52662 + pud_m = pud_alloc(mm, pgd_m, address_m);
52663 + if (!pud_m)
52664 + return VM_FAULT_OOM;
52665 + pmd_m = pmd_alloc(mm, pud_m, address_m);
52666 + if (!pmd_m)
52667 + return VM_FAULT_OOM;
52668 + if (!pmd_present(*pmd_m) && __pte_alloc(mm, pmd_m, address_m))
52669 + return VM_FAULT_OOM;
52670 + pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
52671 + }
52672 +#endif
52673 +
52674 pgd = pgd_offset(mm, address);
52675 pud = pud_alloc(mm, pgd, address);
52676 if (!pud)
52677 @@ -3318,7 +3567,7 @@ static int __init gate_vma_init(void)
52678 gate_vma.vm_start = FIXADDR_USER_START;
52679 gate_vma.vm_end = FIXADDR_USER_END;
52680 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
52681 - gate_vma.vm_page_prot = __P101;
52682 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
52683 /*
52684 * Make sure the vDSO gets into every core dump.
52685 * Dumping its contents makes post-mortem fully interpretable later
52686 diff -urNp linux-2.6.37/mm/memory-failure.c linux-2.6.37/mm/memory-failure.c
52687 --- linux-2.6.37/mm/memory-failure.c 2011-01-04 19:50:19.000000000 -0500
52688 +++ linux-2.6.37/mm/memory-failure.c 2011-01-17 02:41:02.000000000 -0500
52689 @@ -58,7 +58,7 @@ int sysctl_memory_failure_early_kill __r
52690
52691 int sysctl_memory_failure_recovery __read_mostly = 1;
52692
52693 -atomic_long_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
52694 +atomic_long_unchecked_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
52695
52696 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
52697
52698 @@ -967,7 +967,7 @@ int __memory_failure(unsigned long pfn,
52699 }
52700
52701 nr_pages = 1 << compound_order(hpage);
52702 - atomic_long_add(nr_pages, &mce_bad_pages);
52703 + atomic_long_add_unchecked(nr_pages, &mce_bad_pages);
52704
52705 /*
52706 * We need/can do nothing about count=0 pages.
52707 @@ -997,7 +997,7 @@ int __memory_failure(unsigned long pfn,
52708 if (!PageHWPoison(hpage)
52709 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
52710 || (p != hpage && TestSetPageHWPoison(hpage))) {
52711 - atomic_long_sub(nr_pages, &mce_bad_pages);
52712 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
52713 return 0;
52714 }
52715 set_page_hwpoison_huge_page(hpage);
52716 @@ -1052,7 +1052,7 @@ int __memory_failure(unsigned long pfn,
52717 }
52718 if (hwpoison_filter(p)) {
52719 if (TestClearPageHWPoison(p))
52720 - atomic_long_sub(nr_pages, &mce_bad_pages);
52721 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
52722 unlock_page(hpage);
52723 put_page(hpage);
52724 return 0;
52725 @@ -1178,7 +1178,7 @@ int unpoison_memory(unsigned long pfn)
52726 return 0;
52727 }
52728 if (TestClearPageHWPoison(p))
52729 - atomic_long_sub(nr_pages, &mce_bad_pages);
52730 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
52731 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
52732 return 0;
52733 }
52734 @@ -1192,7 +1192,7 @@ int unpoison_memory(unsigned long pfn)
52735 */
52736 if (TestClearPageHWPoison(page)) {
52737 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
52738 - atomic_long_sub(nr_pages, &mce_bad_pages);
52739 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
52740 freeit = 1;
52741 if (PageHuge(page))
52742 clear_page_hwpoison_huge_page(page);
52743 @@ -1301,7 +1301,7 @@ static int soft_offline_huge_page(struct
52744 }
52745 done:
52746 if (!PageHWPoison(hpage))
52747 - atomic_long_add(1 << compound_order(hpage), &mce_bad_pages);
52748 + atomic_long_add_unchecked(1 << compound_order(hpage), &mce_bad_pages);
52749 set_page_hwpoison_huge_page(hpage);
52750 dequeue_hwpoisoned_huge_page(hpage);
52751 /* keep elevated page count for bad page */
52752 @@ -1428,7 +1428,7 @@ int soft_offline_page(struct page *page,
52753 return ret;
52754
52755 done:
52756 - atomic_long_add(1, &mce_bad_pages);
52757 + atomic_long_add_unchecked(1, &mce_bad_pages);
52758 SetPageHWPoison(page);
52759 /* keep elevated page count for bad page */
52760 return ret;
52761 diff -urNp linux-2.6.37/mm/mempolicy.c linux-2.6.37/mm/mempolicy.c
52762 --- linux-2.6.37/mm/mempolicy.c 2011-01-04 19:50:19.000000000 -0500
52763 +++ linux-2.6.37/mm/mempolicy.c 2011-01-17 02:41:02.000000000 -0500
52764 @@ -642,6 +642,10 @@ static int mbind_range(struct mm_struct
52765 unsigned long vmstart;
52766 unsigned long vmend;
52767
52768 +#ifdef CONFIG_PAX_SEGMEXEC
52769 + struct vm_area_struct *vma_m;
52770 +#endif
52771 +
52772 vma = find_vma_prev(mm, start, &prev);
52773 if (!vma || vma->vm_start > start)
52774 return -EFAULT;
52775 @@ -672,6 +676,16 @@ static int mbind_range(struct mm_struct
52776 err = policy_vma(vma, new_pol);
52777 if (err)
52778 goto out;
52779 +
52780 +#ifdef CONFIG_PAX_SEGMEXEC
52781 + vma_m = pax_find_mirror_vma(vma);
52782 + if (vma_m) {
52783 + err = policy_vma(vma_m, new_pol);
52784 + if (err)
52785 + goto out;
52786 + }
52787 +#endif
52788 +
52789 }
52790
52791 out:
52792 @@ -1104,6 +1118,17 @@ static long do_mbind(unsigned long start
52793
52794 if (end < start)
52795 return -EINVAL;
52796 +
52797 +#ifdef CONFIG_PAX_SEGMEXEC
52798 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
52799 + if (end > SEGMEXEC_TASK_SIZE)
52800 + return -EINVAL;
52801 + } else
52802 +#endif
52803 +
52804 + if (end > TASK_SIZE)
52805 + return -EINVAL;
52806 +
52807 if (end == start)
52808 return 0;
52809
52810 @@ -1324,6 +1349,14 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pi
52811 if (!mm)
52812 goto out;
52813
52814 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52815 + if (mm != current->mm &&
52816 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
52817 + err = -EPERM;
52818 + goto out;
52819 + }
52820 +#endif
52821 +
52822 /*
52823 * Check if this process has the right to modify the specified
52824 * process. The right exists if the process has administrative
52825 @@ -1333,8 +1366,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pi
52826 rcu_read_lock();
52827 tcred = __task_cred(task);
52828 if (cred->euid != tcred->suid && cred->euid != tcred->uid &&
52829 - cred->uid != tcred->suid && cred->uid != tcred->uid &&
52830 - !capable(CAP_SYS_NICE)) {
52831 + cred->uid != tcred->suid && !capable(CAP_SYS_NICE)) {
52832 rcu_read_unlock();
52833 err = -EPERM;
52834 goto out;
52835 @@ -2632,7 +2664,7 @@ int show_numa_map(struct seq_file *m, vo
52836
52837 if (file) {
52838 seq_printf(m, " file=");
52839 - seq_path(m, &file->f_path, "\n\t= ");
52840 + seq_path(m, &file->f_path, "\n\t\\= ");
52841 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
52842 seq_printf(m, " heap");
52843 } else if (vma->vm_start <= mm->start_stack &&
52844 diff -urNp linux-2.6.37/mm/migrate.c linux-2.6.37/mm/migrate.c
52845 --- linux-2.6.37/mm/migrate.c 2011-01-04 19:50:19.000000000 -0500
52846 +++ linux-2.6.37/mm/migrate.c 2011-01-17 02:41:02.000000000 -0500
52847 @@ -1299,6 +1299,14 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid,
52848 if (!mm)
52849 return -EINVAL;
52850
52851 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52852 + if (mm != current->mm &&
52853 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
52854 + err = -EPERM;
52855 + goto out;
52856 + }
52857 +#endif
52858 +
52859 /*
52860 * Check if this process has the right to modify the specified
52861 * process. The right exists if the process has administrative
52862 @@ -1308,8 +1316,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid,
52863 rcu_read_lock();
52864 tcred = __task_cred(task);
52865 if (cred->euid != tcred->suid && cred->euid != tcred->uid &&
52866 - cred->uid != tcred->suid && cred->uid != tcred->uid &&
52867 - !capable(CAP_SYS_NICE)) {
52868 + cred->uid != tcred->suid && !capable(CAP_SYS_NICE)) {
52869 rcu_read_unlock();
52870 err = -EPERM;
52871 goto out;
52872 diff -urNp linux-2.6.37/mm/mlock.c linux-2.6.37/mm/mlock.c
52873 --- linux-2.6.37/mm/mlock.c 2011-01-04 19:50:19.000000000 -0500
52874 +++ linux-2.6.37/mm/mlock.c 2011-01-17 02:41:02.000000000 -0500
52875 @@ -13,6 +13,7 @@
52876 #include <linux/pagemap.h>
52877 #include <linux/mempolicy.h>
52878 #include <linux/syscalls.h>
52879 +#include <linux/security.h>
52880 #include <linux/sched.h>
52881 #include <linux/module.h>
52882 #include <linux/rmap.h>
52883 @@ -135,13 +136,6 @@ void munlock_vma_page(struct page *page)
52884 }
52885 }
52886
52887 -static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
52888 -{
52889 - return (vma->vm_flags & VM_GROWSDOWN) &&
52890 - (vma->vm_start == addr) &&
52891 - !vma_stack_continue(vma->vm_prev, addr);
52892 -}
52893 -
52894 /**
52895 * __mlock_vma_pages_range() - mlock a range of pages in the vma.
52896 * @vma: target vma
52897 @@ -174,12 +168,6 @@ static long __mlock_vma_pages_range(stru
52898 if (vma->vm_flags & VM_WRITE)
52899 gup_flags |= FOLL_WRITE;
52900
52901 - /* We don't try to access the guard page of a stack vma */
52902 - if (stack_guard_page(vma, start)) {
52903 - addr += PAGE_SIZE;
52904 - nr_pages--;
52905 - }
52906 -
52907 while (nr_pages > 0) {
52908 int i;
52909
52910 @@ -445,6 +433,9 @@ static int do_mlock(unsigned long start,
52911 return -EINVAL;
52912 if (end == start)
52913 return 0;
52914 + if (end > TASK_SIZE)
52915 + return -EINVAL;
52916 +
52917 vma = find_vma_prev(current->mm, start, &prev);
52918 if (!vma || vma->vm_start > start)
52919 return -ENOMEM;
52920 @@ -455,6 +446,11 @@ static int do_mlock(unsigned long start,
52921 for (nstart = start ; ; ) {
52922 unsigned int newflags;
52923
52924 +#ifdef CONFIG_PAX_SEGMEXEC
52925 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
52926 + break;
52927 +#endif
52928 +
52929 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
52930
52931 newflags = vma->vm_flags | VM_LOCKED;
52932 @@ -504,6 +500,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, st
52933 lock_limit >>= PAGE_SHIFT;
52934
52935 /* check against resource limits */
52936 + gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
52937 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
52938 error = do_mlock(start, len, 1);
52939 up_write(&current->mm->mmap_sem);
52940 @@ -525,17 +522,23 @@ SYSCALL_DEFINE2(munlock, unsigned long,
52941 static int do_mlockall(int flags)
52942 {
52943 struct vm_area_struct * vma, * prev = NULL;
52944 - unsigned int def_flags = 0;
52945
52946 if (flags & MCL_FUTURE)
52947 - def_flags = VM_LOCKED;
52948 - current->mm->def_flags = def_flags;
52949 + current->mm->def_flags |= VM_LOCKED;
52950 + else
52951 + current->mm->def_flags &= ~VM_LOCKED;
52952 if (flags == MCL_FUTURE)
52953 goto out;
52954
52955 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
52956 - unsigned int newflags;
52957 + unsigned long newflags;
52958 +
52959 +#ifdef CONFIG_PAX_SEGMEXEC
52960 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
52961 + break;
52962 +#endif
52963
52964 + BUG_ON(vma->vm_end > TASK_SIZE);
52965 newflags = vma->vm_flags | VM_LOCKED;
52966 if (!(flags & MCL_CURRENT))
52967 newflags &= ~VM_LOCKED;
52968 @@ -567,6 +570,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
52969 lock_limit >>= PAGE_SHIFT;
52970
52971 ret = -ENOMEM;
52972 + gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
52973 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
52974 capable(CAP_IPC_LOCK))
52975 ret = do_mlockall(flags);
52976 diff -urNp linux-2.6.37/mm/mmap.c linux-2.6.37/mm/mmap.c
52977 --- linux-2.6.37/mm/mmap.c 2011-01-04 19:50:19.000000000 -0500
52978 +++ linux-2.6.37/mm/mmap.c 2011-01-17 02:41:02.000000000 -0500
52979 @@ -45,6 +45,16 @@
52980 #define arch_rebalance_pgtables(addr, len) (addr)
52981 #endif
52982
52983 +static inline void verify_mm_writelocked(struct mm_struct *mm)
52984 +{
52985 +#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
52986 + if (unlikely(down_read_trylock(&mm->mmap_sem))) {
52987 + up_read(&mm->mmap_sem);
52988 + BUG();
52989 + }
52990 +#endif
52991 +}
52992 +
52993 static void unmap_region(struct mm_struct *mm,
52994 struct vm_area_struct *vma, struct vm_area_struct *prev,
52995 unsigned long start, unsigned long end);
52996 @@ -70,22 +80,32 @@ static void unmap_region(struct mm_struc
52997 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
52998 *
52999 */
53000 -pgprot_t protection_map[16] = {
53001 +pgprot_t protection_map[16] __read_only = {
53002 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
53003 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
53004 };
53005
53006 pgprot_t vm_get_page_prot(unsigned long vm_flags)
53007 {
53008 - return __pgprot(pgprot_val(protection_map[vm_flags &
53009 + pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
53010 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
53011 pgprot_val(arch_vm_get_page_prot(vm_flags)));
53012 +
53013 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
53014 + if (!(__supported_pte_mask & _PAGE_NX) &&
53015 + (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
53016 + (vm_flags & (VM_READ | VM_WRITE)))
53017 + prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
53018 +#endif
53019 +
53020 + return prot;
53021 }
53022 EXPORT_SYMBOL(vm_get_page_prot);
53023
53024 int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
53025 int sysctl_overcommit_ratio = 50; /* default is 50% */
53026 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
53027 +unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
53028 struct percpu_counter vm_committed_as;
53029
53030 /*
53031 @@ -231,6 +251,7 @@ static struct vm_area_struct *remove_vma
53032 struct vm_area_struct *next = vma->vm_next;
53033
53034 might_sleep();
53035 + BUG_ON(vma->vm_mirror);
53036 if (vma->vm_ops && vma->vm_ops->close)
53037 vma->vm_ops->close(vma);
53038 if (vma->vm_file) {
53039 @@ -267,6 +288,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
53040 * not page aligned -Ram Gupta
53041 */
53042 rlim = rlimit(RLIMIT_DATA);
53043 + gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
53044 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
53045 (mm->end_data - mm->start_data) > rlim)
53046 goto out;
53047 @@ -708,6 +730,12 @@ static int
53048 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
53049 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
53050 {
53051 +
53052 +#ifdef CONFIG_PAX_SEGMEXEC
53053 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
53054 + return 0;
53055 +#endif
53056 +
53057 if (is_mergeable_vma(vma, file, vm_flags) &&
53058 is_mergeable_anon_vma(anon_vma, vma->anon_vma)) {
53059 if (vma->vm_pgoff == vm_pgoff)
53060 @@ -727,6 +755,12 @@ static int
53061 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
53062 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
53063 {
53064 +
53065 +#ifdef CONFIG_PAX_SEGMEXEC
53066 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
53067 + return 0;
53068 +#endif
53069 +
53070 if (is_mergeable_vma(vma, file, vm_flags) &&
53071 is_mergeable_anon_vma(anon_vma, vma->anon_vma)) {
53072 pgoff_t vm_pglen;
53073 @@ -769,13 +803,20 @@ can_vma_merge_after(struct vm_area_struc
53074 struct vm_area_struct *vma_merge(struct mm_struct *mm,
53075 struct vm_area_struct *prev, unsigned long addr,
53076 unsigned long end, unsigned long vm_flags,
53077 - struct anon_vma *anon_vma, struct file *file,
53078 + struct anon_vma *anon_vma, struct file *file,
53079 pgoff_t pgoff, struct mempolicy *policy)
53080 {
53081 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
53082 struct vm_area_struct *area, *next;
53083 int err;
53084
53085 +#ifdef CONFIG_PAX_SEGMEXEC
53086 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
53087 + struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
53088 +
53089 + BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
53090 +#endif
53091 +
53092 /*
53093 * We later require that vma->vm_flags == vm_flags,
53094 * so this tests vma->vm_flags & VM_SPECIAL, too.
53095 @@ -791,6 +832,15 @@ struct vm_area_struct *vma_merge(struct
53096 if (next && next->vm_end == end) /* cases 6, 7, 8 */
53097 next = next->vm_next;
53098
53099 +#ifdef CONFIG_PAX_SEGMEXEC
53100 + if (prev)
53101 + prev_m = pax_find_mirror_vma(prev);
53102 + if (area)
53103 + area_m = pax_find_mirror_vma(area);
53104 + if (next)
53105 + next_m = pax_find_mirror_vma(next);
53106 +#endif
53107 +
53108 /*
53109 * Can it merge with the predecessor?
53110 */
53111 @@ -810,9 +860,24 @@ struct vm_area_struct *vma_merge(struct
53112 /* cases 1, 6 */
53113 err = vma_adjust(prev, prev->vm_start,
53114 next->vm_end, prev->vm_pgoff, NULL);
53115 - } else /* cases 2, 5, 7 */
53116 +
53117 +#ifdef CONFIG_PAX_SEGMEXEC
53118 + if (!err && prev_m)
53119 + err = vma_adjust(prev_m, prev_m->vm_start,
53120 + next_m->vm_end, prev_m->vm_pgoff, NULL);
53121 +#endif
53122 +
53123 + } else { /* cases 2, 5, 7 */
53124 err = vma_adjust(prev, prev->vm_start,
53125 end, prev->vm_pgoff, NULL);
53126 +
53127 +#ifdef CONFIG_PAX_SEGMEXEC
53128 + if (!err && prev_m)
53129 + err = vma_adjust(prev_m, prev_m->vm_start,
53130 + end_m, prev_m->vm_pgoff, NULL);
53131 +#endif
53132 +
53133 + }
53134 if (err)
53135 return NULL;
53136 return prev;
53137 @@ -825,12 +890,27 @@ struct vm_area_struct *vma_merge(struct
53138 mpol_equal(policy, vma_policy(next)) &&
53139 can_vma_merge_before(next, vm_flags,
53140 anon_vma, file, pgoff+pglen)) {
53141 - if (prev && addr < prev->vm_end) /* case 4 */
53142 + if (prev && addr < prev->vm_end) { /* case 4 */
53143 err = vma_adjust(prev, prev->vm_start,
53144 addr, prev->vm_pgoff, NULL);
53145 - else /* cases 3, 8 */
53146 +
53147 +#ifdef CONFIG_PAX_SEGMEXEC
53148 + if (!err && prev_m)
53149 + err = vma_adjust(prev_m, prev_m->vm_start,
53150 + addr_m, prev_m->vm_pgoff, NULL);
53151 +#endif
53152 +
53153 + } else { /* cases 3, 8 */
53154 err = vma_adjust(area, addr, next->vm_end,
53155 next->vm_pgoff - pglen, NULL);
53156 +
53157 +#ifdef CONFIG_PAX_SEGMEXEC
53158 + if (!err && area_m)
53159 + err = vma_adjust(area_m, addr_m, next_m->vm_end,
53160 + next_m->vm_pgoff - pglen, NULL);
53161 +#endif
53162 +
53163 + }
53164 if (err)
53165 return NULL;
53166 return area;
53167 @@ -945,14 +1025,11 @@ none:
53168 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
53169 struct file *file, long pages)
53170 {
53171 - const unsigned long stack_flags
53172 - = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
53173 -
53174 if (file) {
53175 mm->shared_vm += pages;
53176 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
53177 mm->exec_vm += pages;
53178 - } else if (flags & stack_flags)
53179 + } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
53180 mm->stack_vm += pages;
53181 if (flags & (VM_RESERVED|VM_IO))
53182 mm->reserved_vm += pages;
53183 @@ -979,7 +1056,7 @@ unsigned long do_mmap_pgoff(struct file
53184 * (the exception is when the underlying filesystem is noexec
53185 * mounted, in which case we dont add PROT_EXEC.)
53186 */
53187 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
53188 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
53189 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
53190 prot |= PROT_EXEC;
53191
53192 @@ -1005,7 +1082,7 @@ unsigned long do_mmap_pgoff(struct file
53193 /* Obtain the address to map to. we verify (or select) it and ensure
53194 * that it represents a valid section of the address space.
53195 */
53196 - addr = get_unmapped_area(file, addr, len, pgoff, flags);
53197 + addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
53198 if (addr & ~PAGE_MASK)
53199 return addr;
53200
53201 @@ -1016,6 +1093,31 @@ unsigned long do_mmap_pgoff(struct file
53202 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
53203 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
53204
53205 +#ifdef CONFIG_PAX_MPROTECT
53206 + if (mm->pax_flags & MF_PAX_MPROTECT) {
53207 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
53208 + gr_log_rwxmmap(file);
53209 +
53210 +#ifdef CONFIG_PAX_EMUPLT
53211 + vm_flags &= ~VM_EXEC;
53212 +#else
53213 + return -EPERM;
53214 +#endif
53215 +
53216 + }
53217 +
53218 + if (!(vm_flags & VM_EXEC))
53219 + vm_flags &= ~VM_MAYEXEC;
53220 + else
53221 + vm_flags &= ~VM_MAYWRITE;
53222 + }
53223 +#endif
53224 +
53225 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
53226 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
53227 + vm_flags &= ~VM_PAGEEXEC;
53228 +#endif
53229 +
53230 if (flags & MAP_LOCKED)
53231 if (!can_do_mlock())
53232 return -EPERM;
53233 @@ -1027,6 +1129,7 @@ unsigned long do_mmap_pgoff(struct file
53234 locked += mm->locked_vm;
53235 lock_limit = rlimit(RLIMIT_MEMLOCK);
53236 lock_limit >>= PAGE_SHIFT;
53237 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
53238 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
53239 return -EAGAIN;
53240 }
53241 @@ -1097,6 +1200,9 @@ unsigned long do_mmap_pgoff(struct file
53242 if (error)
53243 return error;
53244
53245 + if (!gr_acl_handle_mmap(file, prot))
53246 + return -EACCES;
53247 +
53248 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
53249 }
53250 EXPORT_SYMBOL(do_mmap_pgoff);
53251 @@ -1174,10 +1280,10 @@ SYSCALL_DEFINE1(old_mmap, struct mmap_ar
53252 */
53253 int vma_wants_writenotify(struct vm_area_struct *vma)
53254 {
53255 - unsigned int vm_flags = vma->vm_flags;
53256 + unsigned long vm_flags = vma->vm_flags;
53257
53258 /* If it was private or non-writable, the write bit is already clear */
53259 - if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
53260 + if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
53261 return 0;
53262
53263 /* The backer wishes to know when pages are first written to? */
53264 @@ -1226,14 +1332,24 @@ unsigned long mmap_region(struct file *f
53265 unsigned long charged = 0;
53266 struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
53267
53268 +#ifdef CONFIG_PAX_SEGMEXEC
53269 + struct vm_area_struct *vma_m = NULL;
53270 +#endif
53271 +
53272 + /*
53273 + * mm->mmap_sem is required to protect against another thread
53274 + * changing the mappings in case we sleep.
53275 + */
53276 + verify_mm_writelocked(mm);
53277 +
53278 /* Clear old maps */
53279 error = -ENOMEM;
53280 -munmap_back:
53281 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
53282 if (vma && vma->vm_start < addr + len) {
53283 if (do_munmap(mm, addr, len))
53284 return -ENOMEM;
53285 - goto munmap_back;
53286 + vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
53287 + BUG_ON(vma && vma->vm_start < addr + len);
53288 }
53289
53290 /* Check against address space limit. */
53291 @@ -1282,6 +1398,16 @@ munmap_back:
53292 goto unacct_error;
53293 }
53294
53295 +#ifdef CONFIG_PAX_SEGMEXEC
53296 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
53297 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
53298 + if (!vma_m) {
53299 + error = -ENOMEM;
53300 + goto free_vma;
53301 + }
53302 + }
53303 +#endif
53304 +
53305 vma->vm_mm = mm;
53306 vma->vm_start = addr;
53307 vma->vm_end = addr + len;
53308 @@ -1305,6 +1431,19 @@ munmap_back:
53309 error = file->f_op->mmap(file, vma);
53310 if (error)
53311 goto unmap_and_free_vma;
53312 +
53313 +#ifdef CONFIG_PAX_SEGMEXEC
53314 + if (vma_m && (vm_flags & VM_EXECUTABLE))
53315 + added_exe_file_vma(mm);
53316 +#endif
53317 +
53318 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
53319 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
53320 + vma->vm_flags |= VM_PAGEEXEC;
53321 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
53322 + }
53323 +#endif
53324 +
53325 if (vm_flags & VM_EXECUTABLE)
53326 added_exe_file_vma(mm);
53327
53328 @@ -1340,6 +1479,11 @@ munmap_back:
53329 vma_link(mm, vma, prev, rb_link, rb_parent);
53330 file = vma->vm_file;
53331
53332 +#ifdef CONFIG_PAX_SEGMEXEC
53333 + if (vma_m)
53334 + BUG_ON(pax_mirror_vma(vma_m, vma));
53335 +#endif
53336 +
53337 /* Once vma denies write, undo our temporary denial count */
53338 if (correct_wcount)
53339 atomic_inc(&inode->i_writecount);
53340 @@ -1348,6 +1492,7 @@ out:
53341
53342 mm->total_vm += len >> PAGE_SHIFT;
53343 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
53344 + track_exec_limit(mm, addr, addr + len, vm_flags);
53345 if (vm_flags & VM_LOCKED) {
53346 if (!mlock_vma_pages_range(vma, addr, addr + len))
53347 mm->locked_vm += (len >> PAGE_SHIFT);
53348 @@ -1365,6 +1510,12 @@ unmap_and_free_vma:
53349 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
53350 charged = 0;
53351 free_vma:
53352 +
53353 +#ifdef CONFIG_PAX_SEGMEXEC
53354 + if (vma_m)
53355 + kmem_cache_free(vm_area_cachep, vma_m);
53356 +#endif
53357 +
53358 kmem_cache_free(vm_area_cachep, vma);
53359 unacct_error:
53360 if (charged)
53361 @@ -1372,6 +1523,33 @@ unacct_error:
53362 return error;
53363 }
53364
53365 +bool check_heap_stack_gap(struct vm_area_struct *vma, unsigned long addr, unsigned long len)
53366 +{
53367 + if (!vma) {
53368 +#ifdef CONFIG_STACK_GROWSUP
53369 + if (addr > sysctl_heap_stack_gap)
53370 + vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
53371 + else
53372 + vma = find_vma(current->mm, 0);
53373 + if (vma && (vma->vm_flags & VM_GROWSUP))
53374 + return false;
53375 +#endif
53376 + return true;
53377 + }
53378 +
53379 + if (addr + len > vma->vm_start)
53380 + return false;
53381 +
53382 + if (vma->vm_flags & VM_GROWSDOWN)
53383 + return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
53384 +#ifdef CONFIG_STACK_GROWSUP
53385 + else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
53386 + return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
53387 +#endif
53388 +
53389 + return true;
53390 +}
53391 +
53392 /* Get an address range which is currently unmapped.
53393 * For shmat() with addr=0.
53394 *
53395 @@ -1398,18 +1576,23 @@ arch_get_unmapped_area(struct file *filp
53396 if (flags & MAP_FIXED)
53397 return addr;
53398
53399 +#ifdef CONFIG_PAX_RANDMMAP
53400 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
53401 +#endif
53402 +
53403 if (addr) {
53404 addr = PAGE_ALIGN(addr);
53405 - vma = find_vma(mm, addr);
53406 - if (TASK_SIZE - len >= addr &&
53407 - (!vma || addr + len <= vma->vm_start))
53408 - return addr;
53409 + if (TASK_SIZE - len >= addr) {
53410 + vma = find_vma(mm, addr);
53411 + if (check_heap_stack_gap(vma, addr, len))
53412 + return addr;
53413 + }
53414 }
53415 if (len > mm->cached_hole_size) {
53416 - start_addr = addr = mm->free_area_cache;
53417 + start_addr = addr = mm->free_area_cache;
53418 } else {
53419 - start_addr = addr = TASK_UNMAPPED_BASE;
53420 - mm->cached_hole_size = 0;
53421 + start_addr = addr = mm->mmap_base;
53422 + mm->cached_hole_size = 0;
53423 }
53424
53425 full_search:
53426 @@ -1420,34 +1603,40 @@ full_search:
53427 * Start a new search - just in case we missed
53428 * some holes.
53429 */
53430 - if (start_addr != TASK_UNMAPPED_BASE) {
53431 - addr = TASK_UNMAPPED_BASE;
53432 - start_addr = addr;
53433 + if (start_addr != mm->mmap_base) {
53434 + start_addr = addr = mm->mmap_base;
53435 mm->cached_hole_size = 0;
53436 goto full_search;
53437 }
53438 return -ENOMEM;
53439 }
53440 - if (!vma || addr + len <= vma->vm_start) {
53441 - /*
53442 - * Remember the place where we stopped the search:
53443 - */
53444 - mm->free_area_cache = addr + len;
53445 - return addr;
53446 - }
53447 + if (check_heap_stack_gap(vma, addr, len))
53448 + break;
53449 if (addr + mm->cached_hole_size < vma->vm_start)
53450 mm->cached_hole_size = vma->vm_start - addr;
53451 addr = vma->vm_end;
53452 }
53453 +
53454 + /*
53455 + * Remember the place where we stopped the search:
53456 + */
53457 + mm->free_area_cache = addr + len;
53458 + return addr;
53459 }
53460 #endif
53461
53462 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
53463 {
53464 +
53465 +#ifdef CONFIG_PAX_SEGMEXEC
53466 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
53467 + return;
53468 +#endif
53469 +
53470 /*
53471 * Is this a new hole at the lowest possible address?
53472 */
53473 - if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache) {
53474 + if (addr >= mm->mmap_base && addr < mm->free_area_cache) {
53475 mm->free_area_cache = addr;
53476 mm->cached_hole_size = ~0UL;
53477 }
53478 @@ -1465,7 +1654,7 @@ arch_get_unmapped_area_topdown(struct fi
53479 {
53480 struct vm_area_struct *vma;
53481 struct mm_struct *mm = current->mm;
53482 - unsigned long addr = addr0;
53483 + unsigned long base = mm->mmap_base, addr = addr0;
53484
53485 /* requested length too big for entire address space */
53486 if (len > TASK_SIZE)
53487 @@ -1474,13 +1663,18 @@ arch_get_unmapped_area_topdown(struct fi
53488 if (flags & MAP_FIXED)
53489 return addr;
53490
53491 +#ifdef CONFIG_PAX_RANDMMAP
53492 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
53493 +#endif
53494 +
53495 /* requesting a specific address */
53496 if (addr) {
53497 addr = PAGE_ALIGN(addr);
53498 - vma = find_vma(mm, addr);
53499 - if (TASK_SIZE - len >= addr &&
53500 - (!vma || addr + len <= vma->vm_start))
53501 - return addr;
53502 + if (TASK_SIZE - len >= addr) {
53503 + vma = find_vma(mm, addr);
53504 + if (check_heap_stack_gap(vma, addr, len))
53505 + return addr;
53506 + }
53507 }
53508
53509 /* check if free_area_cache is useful for us */
53510 @@ -1495,7 +1689,7 @@ arch_get_unmapped_area_topdown(struct fi
53511 /* make sure it can fit in the remaining address space */
53512 if (addr > len) {
53513 vma = find_vma(mm, addr-len);
53514 - if (!vma || addr <= vma->vm_start)
53515 + if (check_heap_stack_gap(vma, addr - len, len))
53516 /* remember the address as a hint for next time */
53517 return (mm->free_area_cache = addr-len);
53518 }
53519 @@ -1512,7 +1706,7 @@ arch_get_unmapped_area_topdown(struct fi
53520 * return with success:
53521 */
53522 vma = find_vma(mm, addr);
53523 - if (!vma || addr+len <= vma->vm_start)
53524 + if (check_heap_stack_gap(vma, addr, len))
53525 /* remember the address as a hint for next time */
53526 return (mm->free_area_cache = addr);
53527
53528 @@ -1531,13 +1725,21 @@ bottomup:
53529 * can happen with large stack limits and large mmap()
53530 * allocations.
53531 */
53532 + mm->mmap_base = TASK_UNMAPPED_BASE;
53533 +
53534 +#ifdef CONFIG_PAX_RANDMMAP
53535 + if (mm->pax_flags & MF_PAX_RANDMMAP)
53536 + mm->mmap_base += mm->delta_mmap;
53537 +#endif
53538 +
53539 + mm->free_area_cache = mm->mmap_base;
53540 mm->cached_hole_size = ~0UL;
53541 - mm->free_area_cache = TASK_UNMAPPED_BASE;
53542 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
53543 /*
53544 * Restore the topdown base:
53545 */
53546 - mm->free_area_cache = mm->mmap_base;
53547 + mm->mmap_base = base;
53548 + mm->free_area_cache = base;
53549 mm->cached_hole_size = ~0UL;
53550
53551 return addr;
53552 @@ -1546,6 +1748,12 @@ bottomup:
53553
53554 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
53555 {
53556 +
53557 +#ifdef CONFIG_PAX_SEGMEXEC
53558 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
53559 + return;
53560 +#endif
53561 +
53562 /*
53563 * Is this a new hole at the highest possible address?
53564 */
53565 @@ -1553,8 +1761,10 @@ void arch_unmap_area_topdown(struct mm_s
53566 mm->free_area_cache = addr;
53567
53568 /* dont allow allocations above current base */
53569 - if (mm->free_area_cache > mm->mmap_base)
53570 + if (mm->free_area_cache > mm->mmap_base) {
53571 mm->free_area_cache = mm->mmap_base;
53572 + mm->cached_hole_size = ~0UL;
53573 + }
53574 }
53575
53576 unsigned long
53577 @@ -1662,6 +1872,28 @@ out:
53578 return prev ? prev->vm_next : vma;
53579 }
53580
53581 +#ifdef CONFIG_PAX_SEGMEXEC
53582 +struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
53583 +{
53584 + struct vm_area_struct *vma_m;
53585 +
53586 + BUG_ON(!vma || vma->vm_start >= vma->vm_end);
53587 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
53588 + BUG_ON(vma->vm_mirror);
53589 + return NULL;
53590 + }
53591 + BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
53592 + vma_m = vma->vm_mirror;
53593 + BUG_ON(!vma_m || vma_m->vm_mirror != vma);
53594 + BUG_ON(vma->vm_file != vma_m->vm_file);
53595 + BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
53596 + BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
53597 + BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
53598 + BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED | VM_RESERVED));
53599 + return vma_m;
53600 +}
53601 +#endif
53602 +
53603 /*
53604 * Verify that the stack growth is acceptable and
53605 * update accounting. This is shared with both the
53606 @@ -1678,6 +1910,7 @@ static int acct_stack_growth(struct vm_a
53607 return -ENOMEM;
53608
53609 /* Stack limit test */
53610 + gr_learn_resource(current, RLIMIT_STACK, size, 1);
53611 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
53612 return -ENOMEM;
53613
53614 @@ -1688,6 +1921,7 @@ static int acct_stack_growth(struct vm_a
53615 locked = mm->locked_vm + grow;
53616 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
53617 limit >>= PAGE_SHIFT;
53618 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
53619 if (locked > limit && !capable(CAP_IPC_LOCK))
53620 return -ENOMEM;
53621 }
53622 @@ -1718,37 +1952,48 @@ static int acct_stack_growth(struct vm_a
53623 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
53624 * vma is the last one with address > vma->vm_end. Have to extend vma.
53625 */
53626 +#ifndef CONFIG_IA64
53627 +static
53628 +#endif
53629 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
53630 {
53631 int error;
53632 + bool locknext;
53633
53634 if (!(vma->vm_flags & VM_GROWSUP))
53635 return -EFAULT;
53636
53637 + /* Also guard against wrapping around to address 0. */
53638 + if (address < PAGE_ALIGN(address+1))
53639 + address = PAGE_ALIGN(address+1);
53640 + else
53641 + return -ENOMEM;
53642 +
53643 /*
53644 * We must make sure the anon_vma is allocated
53645 * so that the anon_vma locking is not a noop.
53646 */
53647 if (unlikely(anon_vma_prepare(vma)))
53648 return -ENOMEM;
53649 + locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
53650 + if (locknext && anon_vma_prepare(vma->vm_next))
53651 + return -ENOMEM;
53652 vma_lock_anon_vma(vma);
53653 + if (locknext)
53654 + vma_lock_anon_vma(vma->vm_next);
53655
53656 /*
53657 * vma->vm_start/vm_end cannot change under us because the caller
53658 * is required to hold the mmap_sem in read mode. We need the
53659 - * anon_vma lock to serialize against concurrent expand_stacks.
53660 - * Also guard against wrapping around to address 0.
53661 + * anon_vma locks to serialize against concurrent expand_stacks
53662 + * and expand_upwards.
53663 */
53664 - if (address < PAGE_ALIGN(address+4))
53665 - address = PAGE_ALIGN(address+4);
53666 - else {
53667 - vma_unlock_anon_vma(vma);
53668 - return -ENOMEM;
53669 - }
53670 error = 0;
53671
53672 /* Somebody else might have raced and expanded it already */
53673 - if (address > vma->vm_end) {
53674 + 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)
53675 + error = -ENOMEM;
53676 + else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
53677 unsigned long size, grow;
53678
53679 size = address - vma->vm_start;
53680 @@ -1760,6 +2005,8 @@ int expand_upwards(struct vm_area_struct
53681 perf_event_mmap(vma);
53682 }
53683 }
53684 + if (locknext)
53685 + vma_unlock_anon_vma(vma->vm_next);
53686 vma_unlock_anon_vma(vma);
53687 return error;
53688 }
53689 @@ -1772,6 +2019,8 @@ static int expand_downwards(struct vm_ar
53690 unsigned long address)
53691 {
53692 int error;
53693 + bool lockprev = false;
53694 + struct vm_area_struct *prev;
53695
53696 /*
53697 * We must make sure the anon_vma is allocated
53698 @@ -1785,6 +2034,15 @@ static int expand_downwards(struct vm_ar
53699 if (error)
53700 return error;
53701
53702 + prev = vma->vm_prev;
53703 +#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
53704 + lockprev = prev && (prev->vm_flags & VM_GROWSUP);
53705 +#endif
53706 + if (lockprev && anon_vma_prepare(prev))
53707 + return -ENOMEM;
53708 + if (lockprev)
53709 + vma_lock_anon_vma(prev);
53710 +
53711 vma_lock_anon_vma(vma);
53712
53713 /*
53714 @@ -1794,9 +2052,17 @@ static int expand_downwards(struct vm_ar
53715 */
53716
53717 /* Somebody else might have raced and expanded it already */
53718 - if (address < vma->vm_start) {
53719 + if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
53720 + error = -ENOMEM;
53721 + else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
53722 unsigned long size, grow;
53723
53724 +#ifdef CONFIG_PAX_SEGMEXEC
53725 + struct vm_area_struct *vma_m;
53726 +
53727 + vma_m = pax_find_mirror_vma(vma);
53728 +#endif
53729 +
53730 size = vma->vm_end - address;
53731 grow = (vma->vm_start - address) >> PAGE_SHIFT;
53732
53733 @@ -1804,10 +2070,21 @@ static int expand_downwards(struct vm_ar
53734 if (!error) {
53735 vma->vm_start = address;
53736 vma->vm_pgoff -= grow;
53737 + track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
53738 +
53739 +#ifdef CONFIG_PAX_SEGMEXEC
53740 + if (vma_m) {
53741 + vma_m->vm_start -= grow << PAGE_SHIFT;
53742 + vma_m->vm_pgoff -= grow;
53743 + }
53744 +#endif
53745 +
53746 perf_event_mmap(vma);
53747 }
53748 }
53749 vma_unlock_anon_vma(vma);
53750 + if (lockprev)
53751 + vma_unlock_anon_vma(prev);
53752 return error;
53753 }
53754
53755 @@ -1881,6 +2158,13 @@ static void remove_vma_list(struct mm_st
53756 do {
53757 long nrpages = vma_pages(vma);
53758
53759 +#ifdef CONFIG_PAX_SEGMEXEC
53760 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
53761 + vma = remove_vma(vma);
53762 + continue;
53763 + }
53764 +#endif
53765 +
53766 mm->total_vm -= nrpages;
53767 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
53768 vma = remove_vma(vma);
53769 @@ -1926,6 +2210,16 @@ detach_vmas_to_be_unmapped(struct mm_str
53770 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
53771 vma->vm_prev = NULL;
53772 do {
53773 +
53774 +#ifdef CONFIG_PAX_SEGMEXEC
53775 + if (vma->vm_mirror) {
53776 + BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
53777 + vma->vm_mirror->vm_mirror = NULL;
53778 + vma->vm_mirror->vm_flags &= ~VM_EXEC;
53779 + vma->vm_mirror = NULL;
53780 + }
53781 +#endif
53782 +
53783 rb_erase(&vma->vm_rb, &mm->mm_rb);
53784 mm->map_count--;
53785 tail_vma = vma;
53786 @@ -1954,14 +2248,33 @@ static int __split_vma(struct mm_struct
53787 struct vm_area_struct *new;
53788 int err = -ENOMEM;
53789
53790 +#ifdef CONFIG_PAX_SEGMEXEC
53791 + struct vm_area_struct *vma_m, *new_m = NULL;
53792 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
53793 +#endif
53794 +
53795 if (is_vm_hugetlb_page(vma) && (addr &
53796 ~(huge_page_mask(hstate_vma(vma)))))
53797 return -EINVAL;
53798
53799 +#ifdef CONFIG_PAX_SEGMEXEC
53800 + vma_m = pax_find_mirror_vma(vma);
53801 +#endif
53802 +
53803 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
53804 if (!new)
53805 goto out_err;
53806
53807 +#ifdef CONFIG_PAX_SEGMEXEC
53808 + if (vma_m) {
53809 + new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
53810 + if (!new_m) {
53811 + kmem_cache_free(vm_area_cachep, new);
53812 + goto out_err;
53813 + }
53814 + }
53815 +#endif
53816 +
53817 /* most fields are the same, copy all, and then fixup */
53818 *new = *vma;
53819
53820 @@ -1974,6 +2287,22 @@ static int __split_vma(struct mm_struct
53821 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
53822 }
53823
53824 +#ifdef CONFIG_PAX_SEGMEXEC
53825 + if (vma_m) {
53826 + *new_m = *vma_m;
53827 + INIT_LIST_HEAD(&new_m->anon_vma_chain);
53828 + new_m->vm_mirror = new;
53829 + new->vm_mirror = new_m;
53830 +
53831 + if (new_below)
53832 + new_m->vm_end = addr_m;
53833 + else {
53834 + new_m->vm_start = addr_m;
53835 + new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
53836 + }
53837 + }
53838 +#endif
53839 +
53840 pol = mpol_dup(vma_policy(vma));
53841 if (IS_ERR(pol)) {
53842 err = PTR_ERR(pol);
53843 @@ -1999,6 +2328,42 @@ static int __split_vma(struct mm_struct
53844 else
53845 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
53846
53847 +#ifdef CONFIG_PAX_SEGMEXEC
53848 + if (!err && vma_m) {
53849 + if (anon_vma_clone(new_m, vma_m))
53850 + goto out_free_mpol;
53851 +
53852 + mpol_get(pol);
53853 + vma_set_policy(new_m, pol);
53854 +
53855 + if (new_m->vm_file) {
53856 + get_file(new_m->vm_file);
53857 + if (vma_m->vm_flags & VM_EXECUTABLE)
53858 + added_exe_file_vma(mm);
53859 + }
53860 +
53861 + if (new_m->vm_ops && new_m->vm_ops->open)
53862 + new_m->vm_ops->open(new_m);
53863 +
53864 + if (new_below)
53865 + err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
53866 + ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
53867 + else
53868 + err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
53869 +
53870 + if (err) {
53871 + if (new_m->vm_ops && new_m->vm_ops->close)
53872 + new_m->vm_ops->close(new_m);
53873 + if (new_m->vm_file) {
53874 + if (vma_m->vm_flags & VM_EXECUTABLE)
53875 + removed_exe_file_vma(mm);
53876 + fput(new_m->vm_file);
53877 + }
53878 + mpol_put(pol);
53879 + }
53880 + }
53881 +#endif
53882 +
53883 /* Success. */
53884 if (!err)
53885 return 0;
53886 @@ -2011,10 +2376,18 @@ static int __split_vma(struct mm_struct
53887 removed_exe_file_vma(mm);
53888 fput(new->vm_file);
53889 }
53890 - unlink_anon_vmas(new);
53891 out_free_mpol:
53892 mpol_put(pol);
53893 out_free_vma:
53894 +
53895 +#ifdef CONFIG_PAX_SEGMEXEC
53896 + if (new_m) {
53897 + unlink_anon_vmas(new_m);
53898 + kmem_cache_free(vm_area_cachep, new_m);
53899 + }
53900 +#endif
53901 +
53902 + unlink_anon_vmas(new);
53903 kmem_cache_free(vm_area_cachep, new);
53904 out_err:
53905 return err;
53906 @@ -2027,6 +2400,15 @@ static int __split_vma(struct mm_struct
53907 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
53908 unsigned long addr, int new_below)
53909 {
53910 +
53911 +#ifdef CONFIG_PAX_SEGMEXEC
53912 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
53913 + BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
53914 + if (mm->map_count >= sysctl_max_map_count-1)
53915 + return -ENOMEM;
53916 + } else
53917 +#endif
53918 +
53919 if (mm->map_count >= sysctl_max_map_count)
53920 return -ENOMEM;
53921
53922 @@ -2038,11 +2420,30 @@ int split_vma(struct mm_struct *mm, stru
53923 * work. This now handles partial unmappings.
53924 * Jeremy Fitzhardinge <jeremy@goop.org>
53925 */
53926 +#ifdef CONFIG_PAX_SEGMEXEC
53927 +int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
53928 +{
53929 + int ret = __do_munmap(mm, start, len);
53930 + if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
53931 + return ret;
53932 +
53933 + return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
53934 +}
53935 +
53936 +int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
53937 +#else
53938 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
53939 +#endif
53940 {
53941 unsigned long end;
53942 struct vm_area_struct *vma, *prev, *last;
53943
53944 + /*
53945 + * mm->mmap_sem is required to protect against another thread
53946 + * changing the mappings in case we sleep.
53947 + */
53948 + verify_mm_writelocked(mm);
53949 +
53950 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
53951 return -EINVAL;
53952
53953 @@ -2116,6 +2517,8 @@ int do_munmap(struct mm_struct *mm, unsi
53954 /* Fix up all other VM information */
53955 remove_vma_list(mm, vma);
53956
53957 + track_exec_limit(mm, start, end, 0UL);
53958 +
53959 return 0;
53960 }
53961
53962 @@ -2128,22 +2531,18 @@ SYSCALL_DEFINE2(munmap, unsigned long, a
53963
53964 profile_munmap(addr);
53965
53966 +#ifdef CONFIG_PAX_SEGMEXEC
53967 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
53968 + (len > SEGMEXEC_TASK_SIZE || addr > SEGMEXEC_TASK_SIZE-len))
53969 + return -EINVAL;
53970 +#endif
53971 +
53972 down_write(&mm->mmap_sem);
53973 ret = do_munmap(mm, addr, len);
53974 up_write(&mm->mmap_sem);
53975 return ret;
53976 }
53977
53978 -static inline void verify_mm_writelocked(struct mm_struct *mm)
53979 -{
53980 -#ifdef CONFIG_DEBUG_VM
53981 - if (unlikely(down_read_trylock(&mm->mmap_sem))) {
53982 - WARN_ON(1);
53983 - up_read(&mm->mmap_sem);
53984 - }
53985 -#endif
53986 -}
53987 -
53988 /*
53989 * this is really a simplified "do_mmap". it only handles
53990 * anonymous maps. eventually we may be able to do some
53991 @@ -2157,6 +2556,7 @@ unsigned long do_brk(unsigned long addr,
53992 struct rb_node ** rb_link, * rb_parent;
53993 pgoff_t pgoff = addr >> PAGE_SHIFT;
53994 int error;
53995 + unsigned long charged;
53996
53997 len = PAGE_ALIGN(len);
53998 if (!len)
53999 @@ -2168,16 +2568,30 @@ unsigned long do_brk(unsigned long addr,
54000
54001 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
54002
54003 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
54004 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
54005 + flags &= ~VM_EXEC;
54006 +
54007 +#ifdef CONFIG_PAX_MPROTECT
54008 + if (mm->pax_flags & MF_PAX_MPROTECT)
54009 + flags &= ~VM_MAYEXEC;
54010 +#endif
54011 +
54012 + }
54013 +#endif
54014 +
54015 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
54016 if (error & ~PAGE_MASK)
54017 return error;
54018
54019 + charged = len >> PAGE_SHIFT;
54020 +
54021 /*
54022 * mlock MCL_FUTURE?
54023 */
54024 if (mm->def_flags & VM_LOCKED) {
54025 unsigned long locked, lock_limit;
54026 - locked = len >> PAGE_SHIFT;
54027 + locked = charged;
54028 locked += mm->locked_vm;
54029 lock_limit = rlimit(RLIMIT_MEMLOCK);
54030 lock_limit >>= PAGE_SHIFT;
54031 @@ -2194,22 +2608,22 @@ unsigned long do_brk(unsigned long addr,
54032 /*
54033 * Clear old maps. this also does some error checking for us
54034 */
54035 - munmap_back:
54036 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
54037 if (vma && vma->vm_start < addr + len) {
54038 if (do_munmap(mm, addr, len))
54039 return -ENOMEM;
54040 - goto munmap_back;
54041 + vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
54042 + BUG_ON(vma && vma->vm_start < addr + len);
54043 }
54044
54045 /* Check against address space limits *after* clearing old maps... */
54046 - if (!may_expand_vm(mm, len >> PAGE_SHIFT))
54047 + if (!may_expand_vm(mm, charged))
54048 return -ENOMEM;
54049
54050 if (mm->map_count > sysctl_max_map_count)
54051 return -ENOMEM;
54052
54053 - if (security_vm_enough_memory(len >> PAGE_SHIFT))
54054 + if (security_vm_enough_memory(charged))
54055 return -ENOMEM;
54056
54057 /* Can we just expand an old private anonymous mapping? */
54058 @@ -2223,7 +2637,7 @@ unsigned long do_brk(unsigned long addr,
54059 */
54060 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
54061 if (!vma) {
54062 - vm_unacct_memory(len >> PAGE_SHIFT);
54063 + vm_unacct_memory(charged);
54064 return -ENOMEM;
54065 }
54066
54067 @@ -2237,11 +2651,12 @@ unsigned long do_brk(unsigned long addr,
54068 vma_link(mm, vma, prev, rb_link, rb_parent);
54069 out:
54070 perf_event_mmap(vma);
54071 - mm->total_vm += len >> PAGE_SHIFT;
54072 + mm->total_vm += charged;
54073 if (flags & VM_LOCKED) {
54074 if (!mlock_vma_pages_range(vma, addr, addr + len))
54075 - mm->locked_vm += (len >> PAGE_SHIFT);
54076 + mm->locked_vm += charged;
54077 }
54078 + track_exec_limit(mm, addr, addr + len, flags);
54079 return addr;
54080 }
54081
54082 @@ -2288,8 +2703,10 @@ void exit_mmap(struct mm_struct *mm)
54083 * Walk the list again, actually closing and freeing it,
54084 * with preemption enabled, without holding any MM locks.
54085 */
54086 - while (vma)
54087 + while (vma) {
54088 + vma->vm_mirror = NULL;
54089 vma = remove_vma(vma);
54090 + }
54091
54092 BUG_ON(mm->nr_ptes > (FIRST_USER_ADDRESS+PMD_SIZE-1)>>PMD_SHIFT);
54093 }
54094 @@ -2303,6 +2720,13 @@ int insert_vm_struct(struct mm_struct *
54095 struct vm_area_struct * __vma, * prev;
54096 struct rb_node ** rb_link, * rb_parent;
54097
54098 +#ifdef CONFIG_PAX_SEGMEXEC
54099 + struct vm_area_struct *vma_m = NULL;
54100 +#endif
54101 +
54102 + if (security_file_mmap(NULL, 0, 0, 0, vma->vm_start, 1))
54103 + return -EPERM;
54104 +
54105 /*
54106 * The vm_pgoff of a purely anonymous vma should be irrelevant
54107 * until its first write fault, when page's anon_vma and index
54108 @@ -2325,7 +2749,22 @@ int insert_vm_struct(struct mm_struct *
54109 if ((vma->vm_flags & VM_ACCOUNT) &&
54110 security_vm_enough_memory_mm(mm, vma_pages(vma)))
54111 return -ENOMEM;
54112 +
54113 +#ifdef CONFIG_PAX_SEGMEXEC
54114 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
54115 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
54116 + if (!vma_m)
54117 + return -ENOMEM;
54118 + }
54119 +#endif
54120 +
54121 vma_link(mm, vma, prev, rb_link, rb_parent);
54122 +
54123 +#ifdef CONFIG_PAX_SEGMEXEC
54124 + if (vma_m)
54125 + BUG_ON(pax_mirror_vma(vma_m, vma));
54126 +#endif
54127 +
54128 return 0;
54129 }
54130
54131 @@ -2343,6 +2782,8 @@ struct vm_area_struct *copy_vma(struct v
54132 struct rb_node **rb_link, *rb_parent;
54133 struct mempolicy *pol;
54134
54135 + BUG_ON(vma->vm_mirror);
54136 +
54137 /*
54138 * If anonymous vma has not yet been faulted, update new pgoff
54139 * to match new location, to increase its chance of merging.
54140 @@ -2392,6 +2833,39 @@ struct vm_area_struct *copy_vma(struct v
54141 kmem_cache_free(vm_area_cachep, new_vma);
54142 return NULL;
54143 }
54144 +
54145 +#ifdef CONFIG_PAX_SEGMEXEC
54146 +long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
54147 +{
54148 + struct vm_area_struct *prev_m;
54149 + struct rb_node **rb_link_m, *rb_parent_m;
54150 + struct mempolicy *pol_m;
54151 +
54152 + BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
54153 + BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
54154 + BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
54155 + *vma_m = *vma;
54156 + INIT_LIST_HEAD(&vma_m->anon_vma_chain);
54157 + if (anon_vma_clone(vma_m, vma))
54158 + return -ENOMEM;
54159 + pol_m = vma_policy(vma_m);
54160 + mpol_get(pol_m);
54161 + vma_set_policy(vma_m, pol_m);
54162 + vma_m->vm_start += SEGMEXEC_TASK_SIZE;
54163 + vma_m->vm_end += SEGMEXEC_TASK_SIZE;
54164 + vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
54165 + vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
54166 + if (vma_m->vm_file)
54167 + get_file(vma_m->vm_file);
54168 + if (vma_m->vm_ops && vma_m->vm_ops->open)
54169 + vma_m->vm_ops->open(vma_m);
54170 + find_vma_prepare(vma->vm_mm, vma_m->vm_start, &prev_m, &rb_link_m, &rb_parent_m);
54171 + vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
54172 + vma_m->vm_mirror = vma;
54173 + vma->vm_mirror = vma_m;
54174 + return 0;
54175 +}
54176 +#endif
54177
54178 /*
54179 * Return true if the calling process may expand its vm space by the passed
54180 @@ -2403,7 +2877,7 @@ int may_expand_vm(struct mm_struct *mm,
54181 unsigned long lim;
54182
54183 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
54184 -
54185 + gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
54186 if (cur + npages > lim)
54187 return 0;
54188 return 1;
54189 @@ -2474,6 +2948,17 @@ int install_special_mapping(struct mm_st
54190 vma->vm_start = addr;
54191 vma->vm_end = addr + len;
54192
54193 +#ifdef CONFIG_PAX_MPROTECT
54194 + if (mm->pax_flags & MF_PAX_MPROTECT) {
54195 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
54196 + return -EPERM;
54197 + if (!(vm_flags & VM_EXEC))
54198 + vm_flags &= ~VM_MAYEXEC;
54199 + else
54200 + vm_flags &= ~VM_MAYWRITE;
54201 + }
54202 +#endif
54203 +
54204 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
54205 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
54206
54207 diff -urNp linux-2.6.37/mm/mprotect.c linux-2.6.37/mm/mprotect.c
54208 --- linux-2.6.37/mm/mprotect.c 2011-01-04 19:50:19.000000000 -0500
54209 +++ linux-2.6.37/mm/mprotect.c 2011-01-17 02:41:02.000000000 -0500
54210 @@ -23,10 +23,16 @@
54211 #include <linux/mmu_notifier.h>
54212 #include <linux/migrate.h>
54213 #include <linux/perf_event.h>
54214 +
54215 +#ifdef CONFIG_PAX_MPROTECT
54216 +#include <linux/elf.h>
54217 +#endif
54218 +
54219 #include <asm/uaccess.h>
54220 #include <asm/pgtable.h>
54221 #include <asm/cacheflush.h>
54222 #include <asm/tlbflush.h>
54223 +#include <asm/mmu_context.h>
54224
54225 #ifndef pgprot_modify
54226 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
54227 @@ -131,6 +137,48 @@ static void change_protection(struct vm_
54228 flush_tlb_range(vma, start, end);
54229 }
54230
54231 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
54232 +/* called while holding the mmap semaphor for writing except stack expansion */
54233 +void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
54234 +{
54235 + unsigned long oldlimit, newlimit = 0UL;
54236 +
54237 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
54238 + return;
54239 +
54240 + spin_lock(&mm->page_table_lock);
54241 + oldlimit = mm->context.user_cs_limit;
54242 + if ((prot & VM_EXEC) && oldlimit < end)
54243 + /* USER_CS limit moved up */
54244 + newlimit = end;
54245 + else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
54246 + /* USER_CS limit moved down */
54247 + newlimit = start;
54248 +
54249 + if (newlimit) {
54250 + mm->context.user_cs_limit = newlimit;
54251 +
54252 +#ifdef CONFIG_SMP
54253 + wmb();
54254 + cpus_clear(mm->context.cpu_user_cs_mask);
54255 + cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
54256 +#endif
54257 +
54258 + set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
54259 + }
54260 + spin_unlock(&mm->page_table_lock);
54261 + if (newlimit == end) {
54262 + struct vm_area_struct *vma = find_vma(mm, oldlimit);
54263 +
54264 + for (; vma && vma->vm_start < end; vma = vma->vm_next)
54265 + if (is_vm_hugetlb_page(vma))
54266 + hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
54267 + else
54268 + change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma));
54269 + }
54270 +}
54271 +#endif
54272 +
54273 int
54274 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
54275 unsigned long start, unsigned long end, unsigned long newflags)
54276 @@ -143,11 +191,29 @@ mprotect_fixup(struct vm_area_struct *vm
54277 int error;
54278 int dirty_accountable = 0;
54279
54280 +#ifdef CONFIG_PAX_SEGMEXEC
54281 + struct vm_area_struct *vma_m = NULL;
54282 + unsigned long start_m, end_m;
54283 +
54284 + start_m = start + SEGMEXEC_TASK_SIZE;
54285 + end_m = end + SEGMEXEC_TASK_SIZE;
54286 +#endif
54287 +
54288 if (newflags == oldflags) {
54289 *pprev = vma;
54290 return 0;
54291 }
54292
54293 + if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
54294 + struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
54295 +
54296 + if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
54297 + return -ENOMEM;
54298 +
54299 + if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
54300 + return -ENOMEM;
54301 + }
54302 +
54303 /*
54304 * If we make a private mapping writable we increase our commit;
54305 * but (without finer accounting) cannot reduce our commit if we
54306 @@ -164,6 +230,42 @@ mprotect_fixup(struct vm_area_struct *vm
54307 }
54308 }
54309
54310 +#ifdef CONFIG_PAX_SEGMEXEC
54311 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
54312 + if (start != vma->vm_start) {
54313 + error = split_vma(mm, vma, start, 1);
54314 + if (error)
54315 + goto fail;
54316 + BUG_ON(!*pprev || (*pprev)->vm_next == vma);
54317 + *pprev = (*pprev)->vm_next;
54318 + }
54319 +
54320 + if (end != vma->vm_end) {
54321 + error = split_vma(mm, vma, end, 0);
54322 + if (error)
54323 + goto fail;
54324 + }
54325 +
54326 + if (pax_find_mirror_vma(vma)) {
54327 + error = __do_munmap(mm, start_m, end_m - start_m);
54328 + if (error)
54329 + goto fail;
54330 + } else {
54331 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
54332 + if (!vma_m) {
54333 + error = -ENOMEM;
54334 + goto fail;
54335 + }
54336 + vma->vm_flags = newflags;
54337 + error = pax_mirror_vma(vma_m, vma);
54338 + if (error) {
54339 + vma->vm_flags = oldflags;
54340 + goto fail;
54341 + }
54342 + }
54343 + }
54344 +#endif
54345 +
54346 /*
54347 * First try to merge with previous and/or next vma.
54348 */
54349 @@ -194,9 +296,21 @@ success:
54350 * vm_flags and vm_page_prot are protected by the mmap_sem
54351 * held in write mode.
54352 */
54353 +
54354 +#ifdef CONFIG_PAX_SEGMEXEC
54355 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
54356 + pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
54357 +#endif
54358 +
54359 vma->vm_flags = newflags;
54360 +
54361 +#ifdef CONFIG_PAX_MPROTECT
54362 + if (mm->binfmt && mm->binfmt->handle_mprotect)
54363 + mm->binfmt->handle_mprotect(vma, newflags);
54364 +#endif
54365 +
54366 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
54367 - vm_get_page_prot(newflags));
54368 + vm_get_page_prot(vma->vm_flags));
54369
54370 if (vma_wants_writenotify(vma)) {
54371 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
54372 @@ -238,6 +352,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long,
54373 end = start + len;
54374 if (end <= start)
54375 return -ENOMEM;
54376 +
54377 +#ifdef CONFIG_PAX_SEGMEXEC
54378 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
54379 + if (end > SEGMEXEC_TASK_SIZE)
54380 + return -EINVAL;
54381 + } else
54382 +#endif
54383 +
54384 + if (end > TASK_SIZE)
54385 + return -EINVAL;
54386 +
54387 if (!arch_validate_prot(prot))
54388 return -EINVAL;
54389
54390 @@ -245,7 +370,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long,
54391 /*
54392 * Does the application expect PROT_READ to imply PROT_EXEC:
54393 */
54394 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
54395 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
54396 prot |= PROT_EXEC;
54397
54398 vm_flags = calc_vm_prot_bits(prot);
54399 @@ -277,6 +402,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long,
54400 if (start > vma->vm_start)
54401 prev = vma;
54402
54403 +#ifdef CONFIG_PAX_MPROTECT
54404 + if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
54405 + current->mm->binfmt->handle_mprotect(vma, vm_flags);
54406 +#endif
54407 +
54408 for (nstart = start ; ; ) {
54409 unsigned long newflags;
54410
54411 @@ -286,6 +416,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long,
54412
54413 /* newflags >> 4 shift VM_MAY% in place of VM_% */
54414 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
54415 + if (prot & (PROT_WRITE | PROT_EXEC))
54416 + gr_log_rwxmprotect(vma->vm_file);
54417 +
54418 + error = -EACCES;
54419 + goto out;
54420 + }
54421 +
54422 + if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
54423 error = -EACCES;
54424 goto out;
54425 }
54426 @@ -300,6 +438,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long,
54427 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
54428 if (error)
54429 goto out;
54430 +
54431 + track_exec_limit(current->mm, nstart, tmp, vm_flags);
54432 +
54433 nstart = tmp;
54434
54435 if (nstart < prev->vm_end)
54436 diff -urNp linux-2.6.37/mm/mremap.c linux-2.6.37/mm/mremap.c
54437 --- linux-2.6.37/mm/mremap.c 2011-01-04 19:50:19.000000000 -0500
54438 +++ linux-2.6.37/mm/mremap.c 2011-01-17 02:41:02.000000000 -0500
54439 @@ -113,6 +113,12 @@ static void move_ptes(struct vm_area_str
54440 continue;
54441 pte = ptep_clear_flush(vma, old_addr, old_pte);
54442 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
54443 +
54444 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
54445 + if (!(__supported_pte_mask & _PAGE_NX) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
54446 + pte = pte_exprotect(pte);
54447 +#endif
54448 +
54449 set_pte_at(mm, new_addr, new_pte, pte);
54450 }
54451
54452 @@ -272,6 +278,11 @@ static struct vm_area_struct *vma_to_res
54453 if (is_vm_hugetlb_page(vma))
54454 goto Einval;
54455
54456 +#ifdef CONFIG_PAX_SEGMEXEC
54457 + if (pax_find_mirror_vma(vma))
54458 + goto Einval;
54459 +#endif
54460 +
54461 /* We can't remap across vm area boundaries */
54462 if (old_len > vma->vm_end - addr)
54463 goto Efault;
54464 @@ -321,20 +332,25 @@ static unsigned long mremap_to(unsigned
54465 unsigned long ret = -EINVAL;
54466 unsigned long charged = 0;
54467 unsigned long map_flags;
54468 + unsigned long pax_task_size = TASK_SIZE;
54469
54470 if (new_addr & ~PAGE_MASK)
54471 goto out;
54472
54473 - if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
54474 +#ifdef CONFIG_PAX_SEGMEXEC
54475 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
54476 + pax_task_size = SEGMEXEC_TASK_SIZE;
54477 +#endif
54478 +
54479 + pax_task_size -= PAGE_SIZE;
54480 +
54481 + if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
54482 goto out;
54483
54484 /* Check if the location we're moving into overlaps the
54485 * old location at all, and fail if it does.
54486 */
54487 - if ((new_addr <= addr) && (new_addr+new_len) > addr)
54488 - goto out;
54489 -
54490 - if ((addr <= new_addr) && (addr+old_len) > new_addr)
54491 + if (addr + old_len > new_addr && new_addr + new_len > addr)
54492 goto out;
54493
54494 ret = security_file_mmap(NULL, 0, 0, 0, new_addr, 1);
54495 @@ -406,6 +422,7 @@ unsigned long do_mremap(unsigned long ad
54496 struct vm_area_struct *vma;
54497 unsigned long ret = -EINVAL;
54498 unsigned long charged = 0;
54499 + unsigned long pax_task_size = TASK_SIZE;
54500
54501 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
54502 goto out;
54503 @@ -424,6 +441,17 @@ unsigned long do_mremap(unsigned long ad
54504 if (!new_len)
54505 goto out;
54506
54507 +#ifdef CONFIG_PAX_SEGMEXEC
54508 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
54509 + pax_task_size = SEGMEXEC_TASK_SIZE;
54510 +#endif
54511 +
54512 + pax_task_size -= PAGE_SIZE;
54513 +
54514 + if (new_len > pax_task_size || addr > pax_task_size-new_len ||
54515 + old_len > pax_task_size || addr > pax_task_size-old_len)
54516 + goto out;
54517 +
54518 if (flags & MREMAP_FIXED) {
54519 if (flags & MREMAP_MAYMOVE)
54520 ret = mremap_to(addr, old_len, new_addr, new_len);
54521 @@ -473,6 +501,7 @@ unsigned long do_mremap(unsigned long ad
54522 addr + new_len);
54523 }
54524 ret = addr;
54525 + track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
54526 goto out;
54527 }
54528 }
54529 @@ -499,7 +528,13 @@ unsigned long do_mremap(unsigned long ad
54530 ret = security_file_mmap(NULL, 0, 0, 0, new_addr, 1);
54531 if (ret)
54532 goto out;
54533 +
54534 + map_flags = vma->vm_flags;
54535 ret = move_vma(vma, addr, old_len, new_len, new_addr);
54536 + if (!(ret & ~PAGE_MASK)) {
54537 + track_exec_limit(current->mm, addr, addr + old_len, 0UL);
54538 + track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
54539 + }
54540 }
54541 out:
54542 if (ret & ~PAGE_MASK)
54543 diff -urNp linux-2.6.37/mm/nommu.c linux-2.6.37/mm/nommu.c
54544 --- linux-2.6.37/mm/nommu.c 2011-01-04 19:50:19.000000000 -0500
54545 +++ linux-2.6.37/mm/nommu.c 2011-01-17 02:41:02.000000000 -0500
54546 @@ -63,7 +63,6 @@ int sysctl_overcommit_memory = OVERCOMMI
54547 int sysctl_overcommit_ratio = 50; /* default is 50% */
54548 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
54549 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
54550 -int heap_stack_gap = 0;
54551
54552 atomic_long_t mmap_pages_allocated;
54553
54554 @@ -831,15 +830,6 @@ struct vm_area_struct *find_vma(struct m
54555 EXPORT_SYMBOL(find_vma);
54556
54557 /*
54558 - * find a VMA
54559 - * - we don't extend stack VMAs under NOMMU conditions
54560 - */
54561 -struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
54562 -{
54563 - return find_vma(mm, addr);
54564 -}
54565 -
54566 -/*
54567 * expand a stack to a given address
54568 * - not supported under NOMMU conditions
54569 */
54570 @@ -1561,6 +1551,7 @@ int split_vma(struct mm_struct *mm, stru
54571
54572 /* most fields are the same, copy all, and then fixup */
54573 *new = *vma;
54574 + INIT_LIST_HEAD(&new->anon_vma_chain);
54575 *region = *vma->vm_region;
54576 new->vm_region = region;
54577
54578 diff -urNp linux-2.6.37/mm/page_alloc.c linux-2.6.37/mm/page_alloc.c
54579 --- linux-2.6.37/mm/page_alloc.c 2011-01-04 19:50:19.000000000 -0500
54580 +++ linux-2.6.37/mm/page_alloc.c 2011-01-17 02:41:02.000000000 -0500
54581 @@ -648,6 +648,10 @@ static bool free_pages_prepare(struct pa
54582 int i;
54583 int bad = 0;
54584
54585 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
54586 + unsigned long index = 1UL << order;
54587 +#endif
54588 +
54589 trace_mm_page_free_direct(page, order);
54590 kmemcheck_free_shadow(page, order);
54591
54592 @@ -666,6 +670,12 @@ static bool free_pages_prepare(struct pa
54593 debug_check_no_obj_freed(page_address(page),
54594 PAGE_SIZE << order);
54595 }
54596 +
54597 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
54598 + for (; index; --index)
54599 + sanitize_highpage(page + index - 1);
54600 +#endif
54601 +
54602 arch_free_page(page, order);
54603 kernel_map_pages(page, 1 << order, 0);
54604
54605 @@ -780,8 +790,10 @@ static int prep_new_page(struct page *pa
54606 arch_alloc_page(page, order);
54607 kernel_map_pages(page, 1 << order, 1);
54608
54609 +#ifndef CONFIG_PAX_MEMORY_SANITIZE
54610 if (gfp_flags & __GFP_ZERO)
54611 prep_zero_page(page, order, gfp_flags);
54612 +#endif
54613
54614 if (order && (gfp_flags & __GFP_COMP))
54615 prep_compound_page(page, order);
54616 @@ -4014,7 +4026,7 @@ static void __init setup_usemap(struct p
54617 zone->pageblock_flags = alloc_bootmem_node(pgdat, usemapsize);
54618 }
54619 #else
54620 -static void inline setup_usemap(struct pglist_data *pgdat,
54621 +static inline void setup_usemap(struct pglist_data *pgdat,
54622 struct zone *zone, unsigned long zonesize) {}
54623 #endif /* CONFIG_SPARSEMEM */
54624
54625 diff -urNp linux-2.6.37/mm/percpu.c linux-2.6.37/mm/percpu.c
54626 --- linux-2.6.37/mm/percpu.c 2011-01-04 19:50:19.000000000 -0500
54627 +++ linux-2.6.37/mm/percpu.c 2011-01-17 02:41:02.000000000 -0500
54628 @@ -121,7 +121,7 @@ static unsigned int pcpu_first_unit_cpu
54629 static unsigned int pcpu_last_unit_cpu __read_mostly;
54630
54631 /* the address of the first chunk which starts with the kernel static area */
54632 -void *pcpu_base_addr __read_mostly;
54633 +void *pcpu_base_addr __read_only;
54634 EXPORT_SYMBOL_GPL(pcpu_base_addr);
54635
54636 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
54637 diff -urNp linux-2.6.37/mm/rmap.c linux-2.6.37/mm/rmap.c
54638 --- linux-2.6.37/mm/rmap.c 2011-01-04 19:50:19.000000000 -0500
54639 +++ linux-2.6.37/mm/rmap.c 2011-01-17 02:41:02.000000000 -0500
54640 @@ -117,6 +117,10 @@ int anon_vma_prepare(struct vm_area_stru
54641 struct anon_vma *anon_vma = vma->anon_vma;
54642 struct anon_vma_chain *avc;
54643
54644 +#ifdef CONFIG_PAX_SEGMEXEC
54645 + struct anon_vma_chain *avc_m = NULL;
54646 +#endif
54647 +
54648 might_sleep();
54649 if (unlikely(!anon_vma)) {
54650 struct mm_struct *mm = vma->vm_mm;
54651 @@ -126,6 +130,12 @@ int anon_vma_prepare(struct vm_area_stru
54652 if (!avc)
54653 goto out_enomem;
54654
54655 +#ifdef CONFIG_PAX_SEGMEXEC
54656 + avc_m = anon_vma_chain_alloc();
54657 + if (!avc_m)
54658 + goto out_enomem_free_avc;
54659 +#endif
54660 +
54661 anon_vma = find_mergeable_anon_vma(vma);
54662 allocated = NULL;
54663 if (!anon_vma) {
54664 @@ -144,6 +154,21 @@ int anon_vma_prepare(struct vm_area_stru
54665 /* page_table_lock to protect against threads */
54666 spin_lock(&mm->page_table_lock);
54667 if (likely(!vma->anon_vma)) {
54668 +
54669 +#ifdef CONFIG_PAX_SEGMEXEC
54670 + struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
54671 +
54672 + if (vma_m) {
54673 + BUG_ON(vma_m->anon_vma);
54674 + vma_m->anon_vma = anon_vma;
54675 + avc_m->anon_vma = anon_vma;
54676 + avc_m->vma = vma;
54677 + list_add(&avc_m->same_vma, &vma_m->anon_vma_chain);
54678 + list_add(&avc_m->same_anon_vma, &anon_vma->head);
54679 + avc_m = NULL;
54680 + }
54681 +#endif
54682 +
54683 vma->anon_vma = anon_vma;
54684 avc->anon_vma = anon_vma;
54685 avc->vma = vma;
54686 @@ -157,12 +182,24 @@ int anon_vma_prepare(struct vm_area_stru
54687
54688 if (unlikely(allocated))
54689 anon_vma_free(allocated);
54690 +
54691 +#ifdef CONFIG_PAX_SEGMEXEC
54692 + if (unlikely(avc_m))
54693 + anon_vma_chain_free(avc_m);
54694 +#endif
54695 +
54696 if (unlikely(avc))
54697 anon_vma_chain_free(avc);
54698 }
54699 return 0;
54700
54701 out_enomem_free_avc:
54702 +
54703 +#ifdef CONFIG_PAX_SEGMEXEC
54704 + if (avc_m)
54705 + anon_vma_chain_free(avc_m);
54706 +#endif
54707 +
54708 anon_vma_chain_free(avc);
54709 out_enomem:
54710 return -ENOMEM;
54711 @@ -185,7 +222,7 @@ static void anon_vma_chain_link(struct v
54712 * Attach the anon_vmas from src to dst.
54713 * Returns 0 on success, -ENOMEM on failure.
54714 */
54715 -int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
54716 +int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
54717 {
54718 struct anon_vma_chain *avc, *pavc;
54719
54720 @@ -207,7 +244,7 @@ int anon_vma_clone(struct vm_area_struct
54721 * the corresponding VMA in the parent process is attached to.
54722 * Returns 0 on success, non-zero on failure.
54723 */
54724 -int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
54725 +int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
54726 {
54727 struct anon_vma_chain *avc;
54728 struct anon_vma *anon_vma;
54729 diff -urNp linux-2.6.37/mm/shmem.c linux-2.6.37/mm/shmem.c
54730 --- linux-2.6.37/mm/shmem.c 2011-01-04 19:50:19.000000000 -0500
54731 +++ linux-2.6.37/mm/shmem.c 2011-01-17 02:41:02.000000000 -0500
54732 @@ -31,7 +31,7 @@
54733 #include <linux/percpu_counter.h>
54734 #include <linux/swap.h>
54735
54736 -static struct vfsmount *shm_mnt;
54737 +struct vfsmount *shm_mnt;
54738
54739 #ifdef CONFIG_SHMEM
54740 /*
54741 diff -urNp linux-2.6.37/mm/slab.c linux-2.6.37/mm/slab.c
54742 --- linux-2.6.37/mm/slab.c 2011-01-04 19:50:19.000000000 -0500
54743 +++ linux-2.6.37/mm/slab.c 2011-01-17 02:41:02.000000000 -0500
54744 @@ -284,7 +284,7 @@ struct kmem_list3 {
54745 * Need this for bootstrapping a per node allocator.
54746 */
54747 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
54748 -struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
54749 +struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
54750 #define CACHE_CACHE 0
54751 #define SIZE_AC MAX_NUMNODES
54752 #define SIZE_L3 (2 * MAX_NUMNODES)
54753 @@ -534,7 +534,7 @@ static inline void *index_to_obj(struct
54754 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
54755 */
54756 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
54757 - const struct slab *slab, void *obj)
54758 + const struct slab *slab, const void *obj)
54759 {
54760 u32 offset = (obj - slab->s_mem);
54761 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
54762 @@ -560,14 +560,14 @@ struct cache_names {
54763 static struct cache_names __initdata cache_names[] = {
54764 #define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
54765 #include <linux/kmalloc_sizes.h>
54766 - {NULL,}
54767 + {NULL, NULL}
54768 #undef CACHE
54769 };
54770
54771 static struct arraycache_init initarray_cache __initdata =
54772 - { {0, BOOT_CPUCACHE_ENTRIES, 1, 0} };
54773 + { {0, BOOT_CPUCACHE_ENTRIES, 1, 0}, {NULL} };
54774 static struct arraycache_init initarray_generic =
54775 - { {0, BOOT_CPUCACHE_ENTRIES, 1, 0} };
54776 + { {0, BOOT_CPUCACHE_ENTRIES, 1, 0}, {NULL} };
54777
54778 /* internal cache of cache description objs */
54779 static struct kmem_cache cache_cache = {
54780 @@ -4557,15 +4557,66 @@ static const struct file_operations proc
54781
54782 static int __init slab_proc_init(void)
54783 {
54784 - proc_create("slabinfo",S_IWUSR|S_IRUGO,NULL,&proc_slabinfo_operations);
54785 + mode_t gr_mode = S_IRUGO;
54786 +
54787 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
54788 + gr_mode = S_IRUSR;
54789 +#endif
54790 +
54791 + proc_create("slabinfo",S_IWUSR|gr_mode,NULL,&proc_slabinfo_operations);
54792 #ifdef CONFIG_DEBUG_SLAB_LEAK
54793 - proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
54794 + proc_create("slab_allocators", gr_mode, NULL, &proc_slabstats_operations);
54795 #endif
54796 return 0;
54797 }
54798 module_init(slab_proc_init);
54799 #endif
54800
54801 +void check_object_size(const void *ptr, unsigned long n, bool to)
54802 +{
54803 +
54804 +#ifdef CONFIG_PAX_USERCOPY
54805 + struct kmem_cache *cachep;
54806 + struct slab *slabp;
54807 + struct page *page;
54808 + unsigned int objnr;
54809 + unsigned long offset;
54810 +
54811 + if (!n)
54812 + return;
54813 +
54814 + if (ZERO_OR_NULL_PTR(ptr))
54815 + goto report;
54816 +
54817 + if (!virt_addr_valid(ptr))
54818 + return;
54819 +
54820 + page = virt_to_head_page(ptr);
54821 +
54822 + if (!PageSlab(page)) {
54823 + if (object_is_on_stack(ptr, n) == -1)
54824 + goto report;
54825 + return;
54826 + }
54827 +
54828 + cachep = page_get_cache(page);
54829 + slabp = page_get_slab(page);
54830 + objnr = obj_to_index(cachep, slabp, ptr);
54831 + BUG_ON(objnr >= cachep->num);
54832 + offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
54833 + if (offset <= obj_size(cachep) && n <= obj_size(cachep) - offset)
54834 + return;
54835 +
54836 +report:
54837 + if (to)
54838 + pax_report_leak_to_user(ptr, n);
54839 + else
54840 + pax_report_overflow_from_user(ptr, n);
54841 +#endif
54842 +
54843 +}
54844 +EXPORT_SYMBOL(check_object_size);
54845 +
54846 /**
54847 * ksize - get the actual amount of memory allocated for a given object
54848 * @objp: Pointer to the object
54849 diff -urNp linux-2.6.37/mm/slob.c linux-2.6.37/mm/slob.c
54850 --- linux-2.6.37/mm/slob.c 2011-01-04 19:50:19.000000000 -0500
54851 +++ linux-2.6.37/mm/slob.c 2011-01-17 02:41:02.000000000 -0500
54852 @@ -29,7 +29,7 @@
54853 * If kmalloc is asked for objects of PAGE_SIZE or larger, it calls
54854 * alloc_pages() directly, allocating compound pages so the page order
54855 * does not have to be separately tracked, and also stores the exact
54856 - * allocation size in page->private so that it can be used to accurately
54857 + * allocation size in slob_page->size so that it can be used to accurately
54858 * provide ksize(). These objects are detected in kfree() because slob_page()
54859 * is false for them.
54860 *
54861 @@ -58,6 +58,7 @@
54862 */
54863
54864 #include <linux/kernel.h>
54865 +#include <linux/sched.h>
54866 #include <linux/slab.h>
54867 #include <linux/mm.h>
54868 #include <linux/swap.h> /* struct reclaim_state */
54869 @@ -102,7 +103,8 @@ struct slob_page {
54870 unsigned long flags; /* mandatory */
54871 atomic_t _count; /* mandatory */
54872 slobidx_t units; /* free units left in page */
54873 - unsigned long pad[2];
54874 + unsigned long pad[1];
54875 + unsigned long size; /* size when >=PAGE_SIZE */
54876 slob_t *free; /* first free slob_t in page */
54877 struct list_head list; /* linked list of free pages */
54878 };
54879 @@ -135,7 +137,7 @@ static LIST_HEAD(free_slob_large);
54880 */
54881 static inline int is_slob_page(struct slob_page *sp)
54882 {
54883 - return PageSlab((struct page *)sp);
54884 + return PageSlab((struct page *)sp) && !sp->size;
54885 }
54886
54887 static inline void set_slob_page(struct slob_page *sp)
54888 @@ -150,7 +152,7 @@ static inline void clear_slob_page(struc
54889
54890 static inline struct slob_page *slob_page(const void *addr)
54891 {
54892 - return (struct slob_page *)virt_to_page(addr);
54893 + return (struct slob_page *)virt_to_head_page(addr);
54894 }
54895
54896 /*
54897 @@ -210,7 +212,7 @@ static void set_slob(slob_t *s, slobidx_
54898 /*
54899 * Return the size of a slob block.
54900 */
54901 -static slobidx_t slob_units(slob_t *s)
54902 +static slobidx_t slob_units(const slob_t *s)
54903 {
54904 if (s->units > 0)
54905 return s->units;
54906 @@ -220,7 +222,7 @@ static slobidx_t slob_units(slob_t *s)
54907 /*
54908 * Return the next free slob block pointer after this one.
54909 */
54910 -static slob_t *slob_next(slob_t *s)
54911 +static slob_t *slob_next(const slob_t *s)
54912 {
54913 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
54914 slobidx_t next;
54915 @@ -235,7 +237,7 @@ static slob_t *slob_next(slob_t *s)
54916 /*
54917 * Returns true if s is the last free block in its page.
54918 */
54919 -static int slob_last(slob_t *s)
54920 +static int slob_last(const slob_t *s)
54921 {
54922 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
54923 }
54924 @@ -254,6 +256,7 @@ static void *slob_new_pages(gfp_t gfp, i
54925 if (!page)
54926 return NULL;
54927
54928 + set_slob_page(page);
54929 return page_address(page);
54930 }
54931
54932 @@ -370,11 +373,11 @@ static void *slob_alloc(size_t size, gfp
54933 if (!b)
54934 return NULL;
54935 sp = slob_page(b);
54936 - set_slob_page(sp);
54937
54938 spin_lock_irqsave(&slob_lock, flags);
54939 sp->units = SLOB_UNITS(PAGE_SIZE);
54940 sp->free = b;
54941 + sp->size = 0;
54942 INIT_LIST_HEAD(&sp->list);
54943 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
54944 set_slob_page_free(sp, slob_list);
54945 @@ -476,10 +479,9 @@ out:
54946 * End of slob allocator proper. Begin kmem_cache_alloc and kmalloc frontend.
54947 */
54948
54949 -void *__kmalloc_node(size_t size, gfp_t gfp, int node)
54950 +static void *__kmalloc_node_align(size_t size, gfp_t gfp, int node, int align)
54951 {
54952 - unsigned int *m;
54953 - int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
54954 + slob_t *m;
54955 void *ret;
54956
54957 lockdep_trace_alloc(gfp);
54958 @@ -492,7 +494,10 @@ void *__kmalloc_node(size_t size, gfp_t
54959
54960 if (!m)
54961 return NULL;
54962 - *m = size;
54963 + BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
54964 + BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
54965 + m[0].units = size;
54966 + m[1].units = align;
54967 ret = (void *)m + align;
54968
54969 trace_kmalloc_node(_RET_IP_, ret,
54970 @@ -504,9 +509,9 @@ void *__kmalloc_node(size_t size, gfp_t
54971 gfp |= __GFP_COMP;
54972 ret = slob_new_pages(gfp, order, node);
54973 if (ret) {
54974 - struct page *page;
54975 - page = virt_to_page(ret);
54976 - page->private = size;
54977 + struct slob_page *sp;
54978 + sp = slob_page(ret);
54979 + sp->size = size;
54980 }
54981
54982 trace_kmalloc_node(_RET_IP_, ret,
54983 @@ -516,6 +521,13 @@ void *__kmalloc_node(size_t size, gfp_t
54984 kmemleak_alloc(ret, size, 1, gfp);
54985 return ret;
54986 }
54987 +
54988 +void *__kmalloc_node(size_t size, gfp_t gfp, int node)
54989 +{
54990 + int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
54991 +
54992 + return __kmalloc_node_align(size, gfp, node, align);
54993 +}
54994 EXPORT_SYMBOL(__kmalloc_node);
54995
54996 void kfree(const void *block)
54997 @@ -531,13 +543,84 @@ void kfree(const void *block)
54998 sp = slob_page(block);
54999 if (is_slob_page(sp)) {
55000 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
55001 - unsigned int *m = (unsigned int *)(block - align);
55002 - slob_free(m, *m + align);
55003 - } else
55004 + slob_t *m = (slob_t *)(block - align);
55005 + slob_free(m, m[0].units + align);
55006 + } else {
55007 + clear_slob_page(sp);
55008 + free_slob_page(sp);
55009 + sp->size = 0;
55010 put_page(&sp->page);
55011 + }
55012 }
55013 EXPORT_SYMBOL(kfree);
55014
55015 +void check_object_size(const void *ptr, unsigned long n, bool to)
55016 +{
55017 +
55018 +#ifdef CONFIG_PAX_USERCOPY
55019 + struct slob_page *sp;
55020 + const slob_t *free;
55021 + const void *base;
55022 +
55023 + if (!n)
55024 + return;
55025 +
55026 + if (ZERO_OR_NULL_PTR(ptr))
55027 + goto report;
55028 +
55029 + if (!virt_addr_valid(ptr))
55030 + return;
55031 +
55032 + sp = slob_page(ptr);
55033 + if (!PageSlab((struct page*)sp)) {
55034 + if (object_is_on_stack(ptr, n) == -1)
55035 + goto report;
55036 + return;
55037 + }
55038 +
55039 + if (sp->size) {
55040 + base = page_address(&sp->page);
55041 + if (base <= ptr && n <= sp->size - (ptr - base))
55042 + return;
55043 + goto report;
55044 + }
55045 +
55046 + /* some tricky double walking to find the chunk */
55047 + base = (void *)((unsigned long)ptr & PAGE_MASK);
55048 + free = sp->free;
55049 +
55050 + while (!slob_last(free) && (void *)free <= ptr) {
55051 + base = free + slob_units(free);
55052 + free = slob_next(free);
55053 + }
55054 +
55055 + while (base < (void *)free) {
55056 + slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
55057 + int size = SLOB_UNIT * SLOB_UNITS(m + align);
55058 + int offset;
55059 +
55060 + if (ptr < base + align)
55061 + goto report;
55062 +
55063 + offset = ptr - base - align;
55064 + if (offset < m) {
55065 + if (n <= m - offset)
55066 + return;
55067 + goto report;
55068 + }
55069 + base += size;
55070 + }
55071 +
55072 +report:
55073 + if (to)
55074 + pax_report_leak_to_user(ptr, n);
55075 + else
55076 + pax_report_overflow_from_user(ptr, n);
55077 +#endif
55078 +
55079 +}
55080 +EXPORT_SYMBOL(check_object_size);
55081 +
55082 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
55083 size_t ksize(const void *block)
55084 {
55085 @@ -550,10 +633,10 @@ size_t ksize(const void *block)
55086 sp = slob_page(block);
55087 if (is_slob_page(sp)) {
55088 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
55089 - unsigned int *m = (unsigned int *)(block - align);
55090 - return SLOB_UNITS(*m) * SLOB_UNIT;
55091 + slob_t *m = (slob_t *)(block - align);
55092 + return SLOB_UNITS(m[0].units) * SLOB_UNIT;
55093 } else
55094 - return sp->page.private;
55095 + return sp->size;
55096 }
55097 EXPORT_SYMBOL(ksize);
55098
55099 @@ -608,17 +691,25 @@ void *kmem_cache_alloc_node(struct kmem_
55100 {
55101 void *b;
55102
55103 +#ifdef CONFIG_PAX_USERCOPY
55104 + b = __kmalloc_node_align(c->size, flags, node, c->align);
55105 +#else
55106 if (c->size < PAGE_SIZE) {
55107 b = slob_alloc(c->size, flags, c->align, node);
55108 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
55109 SLOB_UNITS(c->size) * SLOB_UNIT,
55110 flags, node);
55111 } else {
55112 + struct slob_page *sp;
55113 +
55114 b = slob_new_pages(flags, get_order(c->size), node);
55115 + sp = slob_page(b);
55116 + sp->size = c->size;
55117 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
55118 PAGE_SIZE << get_order(c->size),
55119 flags, node);
55120 }
55121 +#endif
55122
55123 if (c->ctor)
55124 c->ctor(b);
55125 @@ -630,10 +721,16 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
55126
55127 static void __kmem_cache_free(void *b, int size)
55128 {
55129 - if (size < PAGE_SIZE)
55130 + struct slob_page *sp = slob_page(b);
55131 +
55132 + if (is_slob_page(sp))
55133 slob_free(b, size);
55134 - else
55135 + else {
55136 + clear_slob_page(sp);
55137 + free_slob_page(sp);
55138 + sp->size = 0;
55139 slob_free_pages(b, get_order(size));
55140 + }
55141 }
55142
55143 static void kmem_rcu_free(struct rcu_head *head)
55144 @@ -646,14 +743,23 @@ static void kmem_rcu_free(struct rcu_hea
55145
55146 void kmem_cache_free(struct kmem_cache *c, void *b)
55147 {
55148 + int size = c->size;
55149 +
55150 +#ifdef CONFIG_PAX_USERCOPY
55151 + if (size + c->align < PAGE_SIZE) {
55152 + size += c->align;
55153 + b -= c->align;
55154 + }
55155 +#endif
55156 +
55157 kmemleak_free_recursive(b, c->flags);
55158 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
55159 struct slob_rcu *slob_rcu;
55160 - slob_rcu = b + (c->size - sizeof(struct slob_rcu));
55161 - slob_rcu->size = c->size;
55162 + slob_rcu = b + (size - sizeof(struct slob_rcu));
55163 + slob_rcu->size = size;
55164 call_rcu(&slob_rcu->head, kmem_rcu_free);
55165 } else {
55166 - __kmem_cache_free(b, c->size);
55167 + __kmem_cache_free(b, size);
55168 }
55169
55170 trace_kmem_cache_free(_RET_IP_, b);
55171 diff -urNp linux-2.6.37/mm/slub.c linux-2.6.37/mm/slub.c
55172 --- linux-2.6.37/mm/slub.c 2011-01-04 19:50:19.000000000 -0500
55173 +++ linux-2.6.37/mm/slub.c 2011-01-17 02:41:02.000000000 -0500
55174 @@ -388,7 +388,7 @@ static void print_track(const char *s, s
55175 if (!t->addr)
55176 return;
55177
55178 - printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
55179 + printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
55180 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
55181 }
55182
55183 @@ -1911,6 +1911,8 @@ void kmem_cache_free(struct kmem_cache *
55184
55185 page = virt_to_head_page(x);
55186
55187 + BUG_ON(!PageSlab(page));
55188 +
55189 slab_free(s, page, x, _RET_IP_);
55190
55191 trace_kmem_cache_free(_RET_IP_, x);
55192 @@ -1955,7 +1957,7 @@ static int slub_min_objects;
55193 * Merge control. If this is set then no merging of slab caches will occur.
55194 * (Could be removed. This was introduced to pacify the merge skeptics.)
55195 */
55196 -static int slub_nomerge;
55197 +static int slub_nomerge = 1;
55198
55199 /*
55200 * Calculate the order of allocation given an slab object size.
55201 @@ -2365,7 +2367,7 @@ static int kmem_cache_open(struct kmem_c
55202 * list to avoid pounding the page allocator excessively.
55203 */
55204 set_min_partial(s, ilog2(s->size));
55205 - s->refcount = 1;
55206 + atomic_set(&s->refcount, 1);
55207 #ifdef CONFIG_NUMA
55208 s->remote_node_defrag_ratio = 1000;
55209 #endif
55210 @@ -2506,8 +2508,7 @@ static inline int kmem_cache_close(struc
55211 void kmem_cache_destroy(struct kmem_cache *s)
55212 {
55213 down_write(&slub_lock);
55214 - s->refcount--;
55215 - if (!s->refcount) {
55216 + if (atomic_dec_and_test(&s->refcount)) {
55217 list_del(&s->list);
55218 if (kmem_cache_close(s)) {
55219 printk(KERN_ERR "SLUB %s: %s called for cache that "
55220 @@ -2717,6 +2718,46 @@ void *__kmalloc_node(size_t size, gfp_t
55221 EXPORT_SYMBOL(__kmalloc_node);
55222 #endif
55223
55224 +void check_object_size(const void *ptr, unsigned long n, bool to)
55225 +{
55226 +
55227 +#ifdef CONFIG_PAX_USERCOPY
55228 + struct page *page;
55229 + struct kmem_cache *s;
55230 + unsigned long offset;
55231 +
55232 + if (!n)
55233 + return;
55234 +
55235 + if (ZERO_OR_NULL_PTR(ptr))
55236 + goto report;
55237 +
55238 + if (!virt_addr_valid(ptr))
55239 + return;
55240 +
55241 + page = get_object_page(ptr);
55242 +
55243 + if (!page) {
55244 + if (object_is_on_stack(ptr, n) == -1)
55245 + goto report;
55246 + return;
55247 + }
55248 +
55249 + s = page->slab;
55250 + offset = (ptr - page_address(page)) % s->size;
55251 + if (offset <= s->objsize && n <= s->objsize - offset)
55252 + return;
55253 +
55254 +report:
55255 + if (to)
55256 + pax_report_leak_to_user(ptr, n);
55257 + else
55258 + pax_report_overflow_from_user(ptr, n);
55259 +#endif
55260 +
55261 +}
55262 +EXPORT_SYMBOL(check_object_size);
55263 +
55264 size_t ksize(const void *object)
55265 {
55266 struct page *page;
55267 @@ -2982,7 +3023,7 @@ static void __init kmem_cache_bootstrap_
55268 int node;
55269
55270 list_add(&s->list, &slab_caches);
55271 - s->refcount = -1;
55272 + atomic_set(&s->refcount, -1);
55273
55274 for_each_node_state(node, N_NORMAL_MEMORY) {
55275 struct kmem_cache_node *n = get_node(s, node);
55276 @@ -3177,7 +3218,7 @@ static int slab_unmergeable(struct kmem_
55277 /*
55278 * We may have set a slab to be unmergeable during bootstrap.
55279 */
55280 - if (s->refcount < 0)
55281 + if (atomic_read(&s->refcount) < 0)
55282 return 1;
55283
55284 return 0;
55285 @@ -3236,7 +3277,7 @@ struct kmem_cache *kmem_cache_create(con
55286 down_write(&slub_lock);
55287 s = find_mergeable(size, align, flags, name, ctor);
55288 if (s) {
55289 - s->refcount++;
55290 + atomic_inc(&s->refcount);
55291 /*
55292 * Adjust the object sizes so that we clear
55293 * the complete object on kzalloc.
55294 @@ -3245,7 +3286,7 @@ struct kmem_cache *kmem_cache_create(con
55295 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
55296
55297 if (sysfs_slab_alias(s, name)) {
55298 - s->refcount--;
55299 + atomic_dec(&s->refcount);
55300 goto err;
55301 }
55302 up_write(&slub_lock);
55303 @@ -3981,7 +4022,7 @@ SLAB_ATTR_RO(ctor);
55304
55305 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
55306 {
55307 - return sprintf(buf, "%d\n", s->refcount - 1);
55308 + return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
55309 }
55310 SLAB_ATTR_RO(aliases);
55311
55312 @@ -4718,7 +4759,13 @@ static const struct file_operations proc
55313
55314 static int __init slab_proc_init(void)
55315 {
55316 - proc_create("slabinfo", S_IRUGO, NULL, &proc_slabinfo_operations);
55317 + mode_t gr_mode = S_IRUGO;
55318 +
55319 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
55320 + gr_mode = S_IRUSR;
55321 +#endif
55322 +
55323 + proc_create("slabinfo", gr_mode, NULL, &proc_slabinfo_operations);
55324 return 0;
55325 }
55326 module_init(slab_proc_init);
55327 diff -urNp linux-2.6.37/mm/util.c linux-2.6.37/mm/util.c
55328 --- linux-2.6.37/mm/util.c 2011-01-04 19:50:19.000000000 -0500
55329 +++ linux-2.6.37/mm/util.c 2011-01-17 02:41:02.000000000 -0500
55330 @@ -240,6 +240,12 @@ EXPORT_SYMBOL(strndup_user);
55331 void arch_pick_mmap_layout(struct mm_struct *mm)
55332 {
55333 mm->mmap_base = TASK_UNMAPPED_BASE;
55334 +
55335 +#ifdef CONFIG_PAX_RANDMMAP
55336 + if (mm->pax_flags & MF_PAX_RANDMMAP)
55337 + mm->mmap_base += mm->delta_mmap;
55338 +#endif
55339 +
55340 mm->get_unmapped_area = arch_get_unmapped_area;
55341 mm->unmap_area = arch_unmap_area;
55342 }
55343 diff -urNp linux-2.6.37/mm/vmalloc.c linux-2.6.37/mm/vmalloc.c
55344 --- linux-2.6.37/mm/vmalloc.c 2011-01-04 19:50:19.000000000 -0500
55345 +++ linux-2.6.37/mm/vmalloc.c 2011-01-17 02:41:02.000000000 -0500
55346 @@ -39,8 +39,19 @@ static void vunmap_pte_range(pmd_t *pmd,
55347
55348 pte = pte_offset_kernel(pmd, addr);
55349 do {
55350 - pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
55351 - WARN_ON(!pte_none(ptent) && !pte_present(ptent));
55352 +
55353 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
55354 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
55355 + BUG_ON(!pte_exec(*pte));
55356 + set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
55357 + continue;
55358 + }
55359 +#endif
55360 +
55361 + {
55362 + pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
55363 + WARN_ON(!pte_none(ptent) && !pte_present(ptent));
55364 + }
55365 } while (pte++, addr += PAGE_SIZE, addr != end);
55366 }
55367
55368 @@ -91,6 +102,7 @@ static int vmap_pte_range(pmd_t *pmd, un
55369 unsigned long end, pgprot_t prot, struct page **pages, int *nr)
55370 {
55371 pte_t *pte;
55372 + int ret = -ENOMEM;
55373
55374 /*
55375 * nr is a running index into the array which helps higher level
55376 @@ -100,17 +112,30 @@ static int vmap_pte_range(pmd_t *pmd, un
55377 pte = pte_alloc_kernel(pmd, addr);
55378 if (!pte)
55379 return -ENOMEM;
55380 +
55381 + pax_open_kernel();
55382 do {
55383 struct page *page = pages[*nr];
55384
55385 - if (WARN_ON(!pte_none(*pte)))
55386 - return -EBUSY;
55387 - if (WARN_ON(!page))
55388 - return -ENOMEM;
55389 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
55390 + if (pgprot_val(prot) & _PAGE_NX)
55391 +#endif
55392 +
55393 + if (WARN_ON(!pte_none(*pte))) {
55394 + ret = -EBUSY;
55395 + goto out;
55396 + }
55397 + if (WARN_ON(!page)) {
55398 + ret = -ENOMEM;
55399 + goto out;
55400 + }
55401 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
55402 (*nr)++;
55403 } while (pte++, addr += PAGE_SIZE, addr != end);
55404 - return 0;
55405 + ret = 0;
55406 +out:
55407 + pax_close_kernel();
55408 + return ret;
55409 }
55410
55411 static int vmap_pmd_range(pud_t *pud, unsigned long addr,
55412 @@ -191,11 +216,20 @@ int is_vmalloc_or_module_addr(const void
55413 * and fall back on vmalloc() if that fails. Others
55414 * just put it in the vmalloc space.
55415 */
55416 -#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
55417 +#ifdef CONFIG_MODULES
55418 +#ifdef MODULES_VADDR
55419 unsigned long addr = (unsigned long)x;
55420 if (addr >= MODULES_VADDR && addr < MODULES_END)
55421 return 1;
55422 #endif
55423 +
55424 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
55425 + if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
55426 + return 1;
55427 +#endif
55428 +
55429 +#endif
55430 +
55431 return is_vmalloc_addr(x);
55432 }
55433
55434 @@ -216,8 +250,14 @@ struct page *vmalloc_to_page(const void
55435
55436 if (!pgd_none(*pgd)) {
55437 pud_t *pud = pud_offset(pgd, addr);
55438 +#ifdef CONFIG_X86
55439 + if (!pud_large(*pud))
55440 +#endif
55441 if (!pud_none(*pud)) {
55442 pmd_t *pmd = pmd_offset(pud, addr);
55443 +#ifdef CONFIG_X86
55444 + if (!pmd_large(*pmd))
55445 +#endif
55446 if (!pmd_none(*pmd)) {
55447 pte_t *ptep, pte;
55448
55449 @@ -1243,6 +1283,16 @@ static struct vm_struct *__get_vm_area_n
55450 struct vm_struct *area;
55451
55452 BUG_ON(in_interrupt());
55453 +
55454 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
55455 + if (flags & VM_KERNEXEC) {
55456 + if (start != VMALLOC_START || end != VMALLOC_END)
55457 + return NULL;
55458 + start = (unsigned long)MODULES_EXEC_VADDR;
55459 + end = (unsigned long)MODULES_EXEC_END;
55460 + }
55461 +#endif
55462 +
55463 if (flags & VM_IOREMAP) {
55464 int bit = fls(size);
55465
55466 @@ -1468,6 +1518,11 @@ void *vmap(struct page **pages, unsigned
55467 if (count > totalram_pages)
55468 return NULL;
55469
55470 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
55471 + if (!(pgprot_val(prot) & _PAGE_NX))
55472 + flags |= VM_KERNEXEC;
55473 +#endif
55474 +
55475 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
55476 __builtin_return_address(0));
55477 if (!area)
55478 @@ -1577,6 +1632,13 @@ static void *__vmalloc_node(unsigned lon
55479 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
55480 return NULL;
55481
55482 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
55483 + if (!(pgprot_val(prot) & _PAGE_NX))
55484 + area = __get_vm_area_node(size, align, VM_ALLOC | VM_KERNEXEC, VMALLOC_START, VMALLOC_END,
55485 + node, gfp_mask, caller);
55486 + else
55487 +#endif
55488 +
55489 area = __get_vm_area_node(size, align, VM_ALLOC, VMALLOC_START,
55490 VMALLOC_END, node, gfp_mask, caller);
55491
55492 @@ -1595,6 +1657,7 @@ static void *__vmalloc_node(unsigned lon
55493 return addr;
55494 }
55495
55496 +#undef __vmalloc
55497 void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot)
55498 {
55499 return __vmalloc_node(size, 1, gfp_mask, prot, -1,
55500 @@ -1618,6 +1681,7 @@ static inline void *__vmalloc_node_flags
55501 * For tight control over page level allocator and protection flags
55502 * use __vmalloc() instead.
55503 */
55504 +#undef vmalloc
55505 void *vmalloc(unsigned long size)
55506 {
55507 return __vmalloc_node_flags(size, -1, GFP_KERNEL | __GFP_HIGHMEM);
55508 @@ -1634,6 +1698,7 @@ EXPORT_SYMBOL(vmalloc);
55509 * For tight control over page level allocator and protection flags
55510 * use __vmalloc() instead.
55511 */
55512 +#undef vzalloc
55513 void *vzalloc(unsigned long size)
55514 {
55515 return __vmalloc_node_flags(size, -1,
55516 @@ -1648,6 +1713,7 @@ EXPORT_SYMBOL(vzalloc);
55517 * The resulting memory area is zeroed so it can be mapped to userspace
55518 * without leaking data.
55519 */
55520 +#undef vmalloc_user
55521 void *vmalloc_user(unsigned long size)
55522 {
55523 struct vm_struct *area;
55524 @@ -1675,6 +1741,7 @@ EXPORT_SYMBOL(vmalloc_user);
55525 * For tight control over page level allocator and protection flags
55526 * use __vmalloc() instead.
55527 */
55528 +#undef vmalloc_node
55529 void *vmalloc_node(unsigned long size, int node)
55530 {
55531 return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL,
55532 @@ -1694,6 +1761,7 @@ EXPORT_SYMBOL(vmalloc_node);
55533 * For tight control over page level allocator and protection flags
55534 * use __vmalloc_node() instead.
55535 */
55536 +#undef vzalloc_node
55537 void *vzalloc_node(unsigned long size, int node)
55538 {
55539 return __vmalloc_node_flags(size, node,
55540 @@ -1716,10 +1784,10 @@ EXPORT_SYMBOL(vzalloc_node);
55541 * For tight control over page level allocator and protection flags
55542 * use __vmalloc() instead.
55543 */
55544 -
55545 +#undef vmalloc_exec
55546 void *vmalloc_exec(unsigned long size)
55547 {
55548 - return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
55549 + return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
55550 -1, __builtin_return_address(0));
55551 }
55552
55553 @@ -1738,6 +1806,7 @@ void *vmalloc_exec(unsigned long size)
55554 * Allocate enough 32bit PA addressable pages to cover @size from the
55555 * page level allocator and map them into contiguous kernel virtual space.
55556 */
55557 +#undef vmalloc_32
55558 void *vmalloc_32(unsigned long size)
55559 {
55560 return __vmalloc_node(size, 1, GFP_VMALLOC32, PAGE_KERNEL,
55561 @@ -1752,6 +1821,7 @@ EXPORT_SYMBOL(vmalloc_32);
55562 * The resulting memory area is 32bit addressable and zeroed so it can be
55563 * mapped to userspace without leaking data.
55564 */
55565 +#undef vmalloc_32_user
55566 void *vmalloc_32_user(unsigned long size)
55567 {
55568 struct vm_struct *area;
55569 @@ -2016,6 +2086,8 @@ int remap_vmalloc_range(struct vm_area_s
55570 unsigned long uaddr = vma->vm_start;
55571 unsigned long usize = vma->vm_end - vma->vm_start;
55572
55573 + BUG_ON(vma->vm_mirror);
55574 +
55575 if ((PAGE_SIZE-1) & (unsigned long)addr)
55576 return -EINVAL;
55577
55578 diff -urNp linux-2.6.37/mm/vmstat.c linux-2.6.37/mm/vmstat.c
55579 --- linux-2.6.37/mm/vmstat.c 2011-01-04 19:50:19.000000000 -0500
55580 +++ linux-2.6.37/mm/vmstat.c 2011-01-17 02:41:02.000000000 -0500
55581 @@ -78,7 +78,7 @@ void vm_events_fold_cpu(int cpu)
55582 *
55583 * vm_stat contains the global counters
55584 */
55585 -atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
55586 +atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
55587 EXPORT_SYMBOL(vm_stat);
55588
55589 #ifdef CONFIG_SMP
55590 @@ -330,7 +330,7 @@ void refresh_cpu_vm_stats(int cpu)
55591 v = p->vm_stat_diff[i];
55592 p->vm_stat_diff[i] = 0;
55593 local_irq_restore(flags);
55594 - atomic_long_add(v, &zone->vm_stat[i]);
55595 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
55596 global_diff[i] += v;
55597 #ifdef CONFIG_NUMA
55598 /* 3 seconds idle till flush */
55599 @@ -368,7 +368,7 @@ void refresh_cpu_vm_stats(int cpu)
55600
55601 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
55602 if (global_diff[i])
55603 - atomic_long_add(global_diff[i], &vm_stat[i]);
55604 + atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
55605 }
55606
55607 #endif
55608 @@ -1066,10 +1066,20 @@ static int __init setup_vmstat(void)
55609 start_cpu_timer(cpu);
55610 #endif
55611 #ifdef CONFIG_PROC_FS
55612 - proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
55613 - proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
55614 - proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
55615 - proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
55616 + {
55617 + mode_t gr_mode = S_IRUGO;
55618 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
55619 + gr_mode = S_IRUSR;
55620 +#endif
55621 + proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
55622 + proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
55623 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
55624 + proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
55625 +#else
55626 + proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
55627 +#endif
55628 + proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
55629 + }
55630 #endif
55631 return 0;
55632 }
55633 diff -urNp linux-2.6.37/net/8021q/vlan.c linux-2.6.37/net/8021q/vlan.c
55634 --- linux-2.6.37/net/8021q/vlan.c 2011-01-04 19:50:19.000000000 -0500
55635 +++ linux-2.6.37/net/8021q/vlan.c 2011-01-17 02:41:02.000000000 -0500
55636 @@ -588,8 +588,7 @@ static int vlan_ioctl_handler(struct net
55637 err = -EPERM;
55638 if (!capable(CAP_NET_ADMIN))
55639 break;
55640 - if ((args.u.name_type >= 0) &&
55641 - (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
55642 + if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
55643 struct vlan_net *vn;
55644
55645 vn = net_generic(net, vlan_net_id);
55646 diff -urNp linux-2.6.37/net/atm/atm_misc.c linux-2.6.37/net/atm/atm_misc.c
55647 --- linux-2.6.37/net/atm/atm_misc.c 2011-01-04 19:50:19.000000000 -0500
55648 +++ linux-2.6.37/net/atm/atm_misc.c 2011-01-17 02:41:02.000000000 -0500
55649 @@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int
55650 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
55651 return 1;
55652 atm_return(vcc, truesize);
55653 - atomic_inc(&vcc->stats->rx_drop);
55654 + atomic_inc_unchecked(&vcc->stats->rx_drop);
55655 return 0;
55656 }
55657 EXPORT_SYMBOL(atm_charge);
55658 @@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct
55659 }
55660 }
55661 atm_return(vcc, guess);
55662 - atomic_inc(&vcc->stats->rx_drop);
55663 + atomic_inc_unchecked(&vcc->stats->rx_drop);
55664 return NULL;
55665 }
55666 EXPORT_SYMBOL(atm_alloc_charge);
55667 @@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
55668
55669 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
55670 {
55671 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
55672 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
55673 __SONET_ITEMS
55674 #undef __HANDLE_ITEM
55675 }
55676 @@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
55677
55678 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
55679 {
55680 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
55681 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
55682 __SONET_ITEMS
55683 #undef __HANDLE_ITEM
55684 }
55685 diff -urNp linux-2.6.37/net/atm/proc.c linux-2.6.37/net/atm/proc.c
55686 --- linux-2.6.37/net/atm/proc.c 2011-01-04 19:50:19.000000000 -0500
55687 +++ linux-2.6.37/net/atm/proc.c 2011-01-17 02:41:02.000000000 -0500
55688 @@ -45,9 +45,9 @@ static void add_stats(struct seq_file *s
55689 const struct k_atm_aal_stats *stats)
55690 {
55691 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
55692 - atomic_read(&stats->tx), atomic_read(&stats->tx_err),
55693 - atomic_read(&stats->rx), atomic_read(&stats->rx_err),
55694 - atomic_read(&stats->rx_drop));
55695 + atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
55696 + atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
55697 + atomic_read_unchecked(&stats->rx_drop));
55698 }
55699
55700 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
55701 @@ -191,7 +191,12 @@ static void vcc_info(struct seq_file *se
55702 {
55703 struct sock *sk = sk_atm(vcc);
55704
55705 +#ifdef CONFIG_GRKERNSEC_HIDESYM
55706 + seq_printf(seq, "%p ", NULL);
55707 +#else
55708 seq_printf(seq, "%p ", vcc);
55709 +#endif
55710 +
55711 if (!vcc->dev)
55712 seq_printf(seq, "Unassigned ");
55713 else
55714 diff -urNp linux-2.6.37/net/atm/resources.c linux-2.6.37/net/atm/resources.c
55715 --- linux-2.6.37/net/atm/resources.c 2011-01-04 19:50:19.000000000 -0500
55716 +++ linux-2.6.37/net/atm/resources.c 2011-01-17 02:41:02.000000000 -0500
55717 @@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
55718 static void copy_aal_stats(struct k_atm_aal_stats *from,
55719 struct atm_aal_stats *to)
55720 {
55721 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
55722 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
55723 __AAL_STAT_ITEMS
55724 #undef __HANDLE_ITEM
55725 }
55726 @@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_
55727 static void subtract_aal_stats(struct k_atm_aal_stats *from,
55728 struct atm_aal_stats *to)
55729 {
55730 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
55731 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
55732 __AAL_STAT_ITEMS
55733 #undef __HANDLE_ITEM
55734 }
55735 diff -urNp linux-2.6.37/net/ax25/af_ax25.c linux-2.6.37/net/ax25/af_ax25.c
55736 --- linux-2.6.37/net/ax25/af_ax25.c 2011-01-04 19:50:19.000000000 -0500
55737 +++ linux-2.6.37/net/ax25/af_ax25.c 2011-01-17 02:41:02.000000000 -0500
55738 @@ -1392,7 +1392,7 @@ static int ax25_getname(struct socket *s
55739 ax25_cb *ax25;
55740 int err = 0;
55741
55742 - memset(fsa, 0, sizeof(fsa));
55743 + memset(fsa, 0, sizeof(*fsa));
55744 lock_sock(sk);
55745 ax25 = ax25_sk(sk);
55746
55747 diff -urNp linux-2.6.37/net/bridge/br_multicast.c linux-2.6.37/net/bridge/br_multicast.c
55748 --- linux-2.6.37/net/bridge/br_multicast.c 2011-01-04 19:50:19.000000000 -0500
55749 +++ linux-2.6.37/net/bridge/br_multicast.c 2011-01-17 02:41:02.000000000 -0500
55750 @@ -1461,7 +1461,7 @@ static int br_multicast_ipv6_rcv(struct
55751 nexthdr = ip6h->nexthdr;
55752 offset = ipv6_skip_exthdr(skb, sizeof(*ip6h), &nexthdr);
55753
55754 - if (offset < 0 || nexthdr != IPPROTO_ICMPV6)
55755 + if (nexthdr != IPPROTO_ICMPV6)
55756 return 0;
55757
55758 /* Okay, we found ICMPv6 header */
55759 diff -urNp linux-2.6.37/net/bridge/br_stp_if.c linux-2.6.37/net/bridge/br_stp_if.c
55760 --- linux-2.6.37/net/bridge/br_stp_if.c 2011-01-04 19:50:19.000000000 -0500
55761 +++ linux-2.6.37/net/bridge/br_stp_if.c 2011-01-17 02:41:02.000000000 -0500
55762 @@ -145,7 +145,7 @@ static void br_stp_stop(struct net_bridg
55763 char *envp[] = { NULL };
55764
55765 if (br->stp_enabled == BR_USER_STP) {
55766 - r = call_usermodehelper(BR_STP_PROG, argv, envp, 1);
55767 + r = call_usermodehelper(BR_STP_PROG, argv, envp, UMH_WAIT_PROC);
55768 br_info(br, "userspace STP stopped, return code %d\n", r);
55769
55770 /* To start timers on any ports left in blocking */
55771 diff -urNp linux-2.6.37/net/bridge/netfilter/ebtables.c linux-2.6.37/net/bridge/netfilter/ebtables.c
55772 --- linux-2.6.37/net/bridge/netfilter/ebtables.c 2011-01-04 19:50:19.000000000 -0500
55773 +++ linux-2.6.37/net/bridge/netfilter/ebtables.c 2011-01-17 02:41:02.000000000 -0500
55774 @@ -1511,7 +1511,7 @@ static int do_ebt_get_ctl(struct sock *s
55775 tmp.valid_hooks = t->table->valid_hooks;
55776 }
55777 mutex_unlock(&ebt_mutex);
55778 - if (copy_to_user(user, &tmp, *len) != 0){
55779 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
55780 BUGPRINT("c2u Didn't work\n");
55781 ret = -EFAULT;
55782 break;
55783 diff -urNp linux-2.6.37/net/core/dev.c linux-2.6.37/net/core/dev.c
55784 --- linux-2.6.37/net/core/dev.c 2011-01-04 19:50:19.000000000 -0500
55785 +++ linux-2.6.37/net/core/dev.c 2011-01-17 02:41:02.000000000 -0500
55786 @@ -2654,7 +2654,7 @@ int netif_rx_ni(struct sk_buff *skb)
55787 }
55788 EXPORT_SYMBOL(netif_rx_ni);
55789
55790 -static void net_tx_action(struct softirq_action *h)
55791 +static void net_tx_action(void)
55792 {
55793 struct softnet_data *sd = &__get_cpu_var(softnet_data);
55794
55795 @@ -3570,7 +3570,7 @@ void netif_napi_del(struct napi_struct *
55796 }
55797 EXPORT_SYMBOL(netif_napi_del);
55798
55799 -static void net_rx_action(struct softirq_action *h)
55800 +static void net_rx_action(void)
55801 {
55802 struct softnet_data *sd = &__get_cpu_var(softnet_data);
55803 unsigned long time_limit = jiffies + 2;
55804 diff -urNp linux-2.6.37/net/core/sock.c linux-2.6.37/net/core/sock.c
55805 --- linux-2.6.37/net/core/sock.c 2011-01-04 19:50:19.000000000 -0500
55806 +++ linux-2.6.37/net/core/sock.c 2011-01-17 02:41:02.000000000 -0500
55807 @@ -934,7 +934,7 @@ int sock_getsockopt(struct socket *sock,
55808 return -ENOTCONN;
55809 if (lv < len)
55810 return -EINVAL;
55811 - if (copy_to_user(optval, address, len))
55812 + if (len > sizeof(address) || copy_to_user(optval, address, len))
55813 return -EFAULT;
55814 goto lenout;
55815 }
55816 @@ -967,7 +967,7 @@ int sock_getsockopt(struct socket *sock,
55817
55818 if (len > lv)
55819 len = lv;
55820 - if (copy_to_user(optval, &v, len))
55821 + if (len > sizeof(v) || copy_to_user(optval, &v, len))
55822 return -EFAULT;
55823 lenout:
55824 if (put_user(len, optlen))
55825 diff -urNp linux-2.6.37/net/dccp/ccids/ccid3.c linux-2.6.37/net/dccp/ccids/ccid3.c
55826 --- linux-2.6.37/net/dccp/ccids/ccid3.c 2011-01-04 19:50:19.000000000 -0500
55827 +++ linux-2.6.37/net/dccp/ccids/ccid3.c 2011-01-17 02:41:02.000000000 -0500
55828 @@ -41,7 +41,7 @@
55829 static int ccid3_debug;
55830 #define ccid3_pr_debug(format, a...) DCCP_PR_DEBUG(ccid3_debug, format, ##a)
55831 #else
55832 -#define ccid3_pr_debug(format, a...)
55833 +#define ccid3_pr_debug(format, a...) do {} while (0)
55834 #endif
55835
55836 /*
55837 diff -urNp linux-2.6.37/net/dccp/dccp.h linux-2.6.37/net/dccp/dccp.h
55838 --- linux-2.6.37/net/dccp/dccp.h 2011-01-04 19:50:19.000000000 -0500
55839 +++ linux-2.6.37/net/dccp/dccp.h 2011-01-17 02:41:02.000000000 -0500
55840 @@ -44,9 +44,9 @@ extern int dccp_debug;
55841 #define dccp_pr_debug_cat(format, a...) DCCP_PRINTK(dccp_debug, format, ##a)
55842 #define dccp_debug(fmt, a...) dccp_pr_debug_cat(KERN_DEBUG fmt, ##a)
55843 #else
55844 -#define dccp_pr_debug(format, a...)
55845 -#define dccp_pr_debug_cat(format, a...)
55846 -#define dccp_debug(format, a...)
55847 +#define dccp_pr_debug(format, a...) do {} while (0)
55848 +#define dccp_pr_debug_cat(format, a...) do {} while (0)
55849 +#define dccp_debug(format, a...) do {} while (0)
55850 #endif
55851
55852 extern struct inet_hashinfo dccp_hashinfo;
55853 diff -urNp linux-2.6.37/net/decnet/sysctl_net_decnet.c linux-2.6.37/net/decnet/sysctl_net_decnet.c
55854 --- linux-2.6.37/net/decnet/sysctl_net_decnet.c 2011-01-04 19:50:19.000000000 -0500
55855 +++ linux-2.6.37/net/decnet/sysctl_net_decnet.c 2011-01-17 02:41:02.000000000 -0500
55856 @@ -173,7 +173,7 @@ static int dn_node_address_handler(ctl_t
55857
55858 if (len > *lenp) len = *lenp;
55859
55860 - if (copy_to_user(buffer, addr, len))
55861 + if (len > sizeof addr || copy_to_user(buffer, addr, len))
55862 return -EFAULT;
55863
55864 *lenp = len;
55865 @@ -236,7 +236,7 @@ static int dn_def_dev_handler(ctl_table
55866
55867 if (len > *lenp) len = *lenp;
55868
55869 - if (copy_to_user(buffer, devname, len))
55870 + if (len > sizeof devname || copy_to_user(buffer, devname, len))
55871 return -EFAULT;
55872
55873 *lenp = len;
55874 diff -urNp linux-2.6.37/net/econet/Kconfig linux-2.6.37/net/econet/Kconfig
55875 --- linux-2.6.37/net/econet/Kconfig 2011-01-04 19:50:19.000000000 -0500
55876 +++ linux-2.6.37/net/econet/Kconfig 2011-01-17 02:41:02.000000000 -0500
55877 @@ -4,7 +4,7 @@
55878
55879 config ECONET
55880 tristate "Acorn Econet/AUN protocols (EXPERIMENTAL)"
55881 - depends on EXPERIMENTAL && INET
55882 + depends on EXPERIMENTAL && INET && BROKEN
55883 ---help---
55884 Econet is a fairly old and slow networking protocol mainly used by
55885 Acorn computers to access file and print servers. It uses native
55886 diff -urNp linux-2.6.37/net/ipv4/inet_diag.c linux-2.6.37/net/ipv4/inet_diag.c
55887 --- linux-2.6.37/net/ipv4/inet_diag.c 2011-01-04 19:50:19.000000000 -0500
55888 +++ linux-2.6.37/net/ipv4/inet_diag.c 2011-01-17 02:41:02.000000000 -0500
55889 @@ -114,8 +114,14 @@ static int inet_csk_diag_fill(struct soc
55890 r->idiag_retrans = 0;
55891
55892 r->id.idiag_if = sk->sk_bound_dev_if;
55893 +
55894 +#ifdef CONFIG_GRKERNSEC_HIDESYM
55895 + r->id.idiag_cookie[0] = 0;
55896 + r->id.idiag_cookie[1] = 0;
55897 +#else
55898 r->id.idiag_cookie[0] = (u32)(unsigned long)sk;
55899 r->id.idiag_cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
55900 +#endif
55901
55902 r->id.idiag_sport = inet->inet_sport;
55903 r->id.idiag_dport = inet->inet_dport;
55904 @@ -201,8 +207,15 @@ static int inet_twsk_diag_fill(struct in
55905 r->idiag_family = tw->tw_family;
55906 r->idiag_retrans = 0;
55907 r->id.idiag_if = tw->tw_bound_dev_if;
55908 +
55909 +#ifdef CONFIG_GRKERNSEC_HIDESYM
55910 + r->id.idiag_cookie[0] = 0;
55911 + r->id.idiag_cookie[1] = 0;
55912 +#else
55913 r->id.idiag_cookie[0] = (u32)(unsigned long)tw;
55914 r->id.idiag_cookie[1] = (u32)(((unsigned long)tw >> 31) >> 1);
55915 +#endif
55916 +
55917 r->id.idiag_sport = tw->tw_sport;
55918 r->id.idiag_dport = tw->tw_dport;
55919 r->id.idiag_src[0] = tw->tw_rcv_saddr;
55920 @@ -285,12 +298,14 @@ static int inet_diag_get_exact(struct sk
55921 if (sk == NULL)
55922 goto unlock;
55923
55924 +#ifndef CONFIG_GRKERNSEC_HIDESYM
55925 err = -ESTALE;
55926 if ((req->id.idiag_cookie[0] != INET_DIAG_NOCOOKIE ||
55927 req->id.idiag_cookie[1] != INET_DIAG_NOCOOKIE) &&
55928 ((u32)(unsigned long)sk != req->id.idiag_cookie[0] ||
55929 (u32)((((unsigned long)sk) >> 31) >> 1) != req->id.idiag_cookie[1]))
55930 goto out;
55931 +#endif
55932
55933 err = -ENOMEM;
55934 rep = alloc_skb(NLMSG_SPACE((sizeof(struct inet_diag_msg) +
55935 @@ -582,8 +597,14 @@ static int inet_diag_fill_req(struct sk_
55936 r->idiag_retrans = req->retrans;
55937
55938 r->id.idiag_if = sk->sk_bound_dev_if;
55939 +
55940 +#ifdef CONFIG_GRKERNSEC_HIDESYM
55941 + r->id.idiag_cookie[0] = 0;
55942 + r->id.idiag_cookie[1] = 0;
55943 +#else
55944 r->id.idiag_cookie[0] = (u32)(unsigned long)req;
55945 r->id.idiag_cookie[1] = (u32)(((unsigned long)req >> 31) >> 1);
55946 +#endif
55947
55948 tmo = req->expires - jiffies;
55949 if (tmo < 0)
55950 diff -urNp linux-2.6.37/net/ipv4/inet_hashtables.c linux-2.6.37/net/ipv4/inet_hashtables.c
55951 --- linux-2.6.37/net/ipv4/inet_hashtables.c 2011-01-04 19:50:19.000000000 -0500
55952 +++ linux-2.6.37/net/ipv4/inet_hashtables.c 2011-01-17 02:41:02.000000000 -0500
55953 @@ -18,11 +18,14 @@
55954 #include <linux/sched.h>
55955 #include <linux/slab.h>
55956 #include <linux/wait.h>
55957 +#include <linux/security.h>
55958
55959 #include <net/inet_connection_sock.h>
55960 #include <net/inet_hashtables.h>
55961 #include <net/ip.h>
55962
55963 +extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
55964 +
55965 /*
55966 * Allocate and initialize a new local port bind bucket.
55967 * The bindhash mutex for snum's hash chain must be held here.
55968 @@ -529,6 +532,8 @@ ok:
55969 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
55970 spin_unlock(&head->lock);
55971
55972 + gr_update_task_in_ip_table(current, inet_sk(sk));
55973 +
55974 if (tw) {
55975 inet_twsk_deschedule(tw, death_row);
55976 while (twrefcnt) {
55977 diff -urNp linux-2.6.37/net/ipv4/inetpeer.c linux-2.6.37/net/ipv4/inetpeer.c
55978 --- linux-2.6.37/net/ipv4/inetpeer.c 2011-01-04 19:50:19.000000000 -0500
55979 +++ linux-2.6.37/net/ipv4/inetpeer.c 2011-01-17 02:41:02.000000000 -0500
55980 @@ -469,8 +469,8 @@ struct inet_peer *inet_getpeer(__be32 da
55981 if (p) {
55982 p->v4daddr = daddr;
55983 atomic_set(&p->refcnt, 1);
55984 - atomic_set(&p->rid, 0);
55985 - atomic_set(&p->ip_id_count, secure_ip_id(daddr));
55986 + atomic_set_unchecked(&p->rid, 0);
55987 + atomic_set_unchecked(&p->ip_id_count, secure_ip_id(daddr));
55988 p->tcp_ts_stamp = 0;
55989 INIT_LIST_HEAD(&p->unused);
55990
55991 diff -urNp linux-2.6.37/net/ipv4/ip_fragment.c linux-2.6.37/net/ipv4/ip_fragment.c
55992 --- linux-2.6.37/net/ipv4/ip_fragment.c 2011-01-04 19:50:19.000000000 -0500
55993 +++ linux-2.6.37/net/ipv4/ip_fragment.c 2011-01-17 02:41:02.000000000 -0500
55994 @@ -279,7 +279,7 @@ static inline int ip_frag_too_far(struct
55995 return 0;
55996
55997 start = qp->rid;
55998 - end = atomic_inc_return(&peer->rid);
55999 + end = atomic_inc_return_unchecked(&peer->rid);
56000 qp->rid = end;
56001
56002 rc = qp->q.fragments && (end - start) > max;
56003 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
56004 --- linux-2.6.37/net/ipv4/netfilter/nf_nat_snmp_basic.c 2011-01-04 19:50:19.000000000 -0500
56005 +++ linux-2.6.37/net/ipv4/netfilter/nf_nat_snmp_basic.c 2011-01-17 02:41:02.000000000 -0500
56006 @@ -398,7 +398,7 @@ static unsigned char asn1_octets_decode(
56007
56008 *len = 0;
56009
56010 - *octets = kmalloc(eoc - ctx->pointer, GFP_ATOMIC);
56011 + *octets = kmalloc((eoc - ctx->pointer), GFP_ATOMIC);
56012 if (*octets == NULL) {
56013 if (net_ratelimit())
56014 pr_notice("OOM in bsalg (%d)\n", __LINE__);
56015 diff -urNp linux-2.6.37/net/ipv4/route.c linux-2.6.37/net/ipv4/route.c
56016 --- linux-2.6.37/net/ipv4/route.c 2011-01-04 19:50:19.000000000 -0500
56017 +++ linux-2.6.37/net/ipv4/route.c 2011-01-17 02:41:02.000000000 -0500
56018 @@ -2876,7 +2876,7 @@ static int rt_fill_info(struct net *net,
56019 expires = rt->dst.expires ? rt->dst.expires - jiffies : 0;
56020 if (rt->peer) {
56021 inet_peer_refcheck(rt->peer);
56022 - id = atomic_read(&rt->peer->ip_id_count) & 0xffff;
56023 + id = atomic_read_unchecked(&rt->peer->ip_id_count) & 0xffff;
56024 if (rt->peer->tcp_ts_stamp) {
56025 ts = rt->peer->tcp_ts;
56026 tsage = get_seconds() - rt->peer->tcp_ts_stamp;
56027 diff -urNp linux-2.6.37/net/ipv4/tcp_ipv4.c linux-2.6.37/net/ipv4/tcp_ipv4.c
56028 --- linux-2.6.37/net/ipv4/tcp_ipv4.c 2011-01-04 19:50:19.000000000 -0500
56029 +++ linux-2.6.37/net/ipv4/tcp_ipv4.c 2011-01-17 02:41:02.000000000 -0500
56030 @@ -86,6 +86,9 @@ int sysctl_tcp_tw_reuse __read_mostly;
56031 int sysctl_tcp_low_latency __read_mostly;
56032 EXPORT_SYMBOL(sysctl_tcp_low_latency);
56033
56034 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
56035 +extern int grsec_enable_blackhole;
56036 +#endif
56037
56038 #ifdef CONFIG_TCP_MD5SIG
56039 static struct tcp_md5sig_key *tcp_v4_md5_do_lookup(struct sock *sk,
56040 @@ -1599,6 +1602,9 @@ int tcp_v4_do_rcv(struct sock *sk, struc
56041 return 0;
56042
56043 reset:
56044 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
56045 + if (!grsec_enable_blackhole)
56046 +#endif
56047 tcp_v4_send_reset(rsk, skb);
56048 discard:
56049 kfree_skb(skb);
56050 @@ -1661,12 +1667,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
56051 TCP_SKB_CB(skb)->sacked = 0;
56052
56053 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
56054 - if (!sk)
56055 + if (!sk) {
56056 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
56057 + ret = 1;
56058 +#endif
56059 goto no_tcp_socket;
56060 -
56061 + }
56062 process:
56063 - if (sk->sk_state == TCP_TIME_WAIT)
56064 + if (sk->sk_state == TCP_TIME_WAIT) {
56065 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
56066 + ret = 2;
56067 +#endif
56068 goto do_time_wait;
56069 + }
56070
56071 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
56072 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
56073 @@ -1716,6 +1729,10 @@ no_tcp_socket:
56074 bad_packet:
56075 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
56076 } else {
56077 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
56078 + if (!grsec_enable_blackhole || (ret == 1 &&
56079 + (skb->dev->flags & IFF_LOOPBACK)))
56080 +#endif
56081 tcp_v4_send_reset(NULL, skb);
56082 }
56083
56084 @@ -2404,7 +2421,11 @@ static void get_openreq4(struct sock *sk
56085 0, /* non standard timer */
56086 0, /* open_requests have no inode */
56087 atomic_read(&sk->sk_refcnt),
56088 +#ifdef CONFIG_GRKERNSEC_HIDESYM
56089 + NULL,
56090 +#else
56091 req,
56092 +#endif
56093 len);
56094 }
56095
56096 @@ -2454,7 +2475,12 @@ static void get_tcp4_sock(struct sock *s
56097 sock_i_uid(sk),
56098 icsk->icsk_probes_out,
56099 sock_i_ino(sk),
56100 - atomic_read(&sk->sk_refcnt), sk,
56101 + atomic_read(&sk->sk_refcnt),
56102 +#ifdef CONFIG_GRKERNSEC_HIDESYM
56103 + NULL,
56104 +#else
56105 + sk,
56106 +#endif
56107 jiffies_to_clock_t(icsk->icsk_rto),
56108 jiffies_to_clock_t(icsk->icsk_ack.ato),
56109 (icsk->icsk_ack.quick << 1) | icsk->icsk_ack.pingpong,
56110 @@ -2482,7 +2508,13 @@ static void get_timewait4_sock(struct in
56111 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %p%n",
56112 i, src, srcp, dest, destp, tw->tw_substate, 0, 0,
56113 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
56114 - atomic_read(&tw->tw_refcnt), tw, len);
56115 + atomic_read(&tw->tw_refcnt),
56116 +#ifdef CONFIG_GRKERNSEC_HIDESYM
56117 + NULL,
56118 +#else
56119 + tw,
56120 +#endif
56121 + len);
56122 }
56123
56124 #define TMPSZ 150
56125 diff -urNp linux-2.6.37/net/ipv4/tcp_minisocks.c linux-2.6.37/net/ipv4/tcp_minisocks.c
56126 --- linux-2.6.37/net/ipv4/tcp_minisocks.c 2011-01-04 19:50:19.000000000 -0500
56127 +++ linux-2.6.37/net/ipv4/tcp_minisocks.c 2011-01-17 02:41:02.000000000 -0500
56128 @@ -27,6 +27,10 @@
56129 #include <net/inet_common.h>
56130 #include <net/xfrm.h>
56131
56132 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
56133 +extern int grsec_enable_blackhole;
56134 +#endif
56135 +
56136 int sysctl_tcp_syncookies __read_mostly = 1;
56137 EXPORT_SYMBOL(sysctl_tcp_syncookies);
56138
56139 @@ -700,6 +704,10 @@ listen_overflow:
56140
56141 embryonic_reset:
56142 NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_EMBRYONICRSTS);
56143 +
56144 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
56145 + if (!grsec_enable_blackhole)
56146 +#endif
56147 if (!(flg & TCP_FLAG_RST))
56148 req->rsk_ops->send_reset(sk, skb);
56149
56150 diff -urNp linux-2.6.37/net/ipv4/tcp_probe.c linux-2.6.37/net/ipv4/tcp_probe.c
56151 --- linux-2.6.37/net/ipv4/tcp_probe.c 2011-01-04 19:50:19.000000000 -0500
56152 +++ linux-2.6.37/net/ipv4/tcp_probe.c 2011-01-17 02:41:02.000000000 -0500
56153 @@ -202,7 +202,7 @@ static ssize_t tcpprobe_read(struct file
56154 if (cnt + width >= len)
56155 break;
56156
56157 - if (copy_to_user(buf + cnt, tbuf, width))
56158 + if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
56159 return -EFAULT;
56160 cnt += width;
56161 }
56162 diff -urNp linux-2.6.37/net/ipv4/tcp_timer.c linux-2.6.37/net/ipv4/tcp_timer.c
56163 --- linux-2.6.37/net/ipv4/tcp_timer.c 2011-01-04 19:50:19.000000000 -0500
56164 +++ linux-2.6.37/net/ipv4/tcp_timer.c 2011-01-17 02:41:02.000000000 -0500
56165 @@ -22,6 +22,10 @@
56166 #include <linux/gfp.h>
56167 #include <net/tcp.h>
56168
56169 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
56170 +extern int grsec_lastack_retries;
56171 +#endif
56172 +
56173 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
56174 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
56175 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
56176 @@ -199,6 +203,13 @@ static int tcp_write_timeout(struct sock
56177 }
56178 }
56179
56180 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
56181 + if ((sk->sk_state == TCP_LAST_ACK) &&
56182 + (grsec_lastack_retries > 0) &&
56183 + (grsec_lastack_retries < retry_until))
56184 + retry_until = grsec_lastack_retries;
56185 +#endif
56186 +
56187 if (retransmits_timed_out(sk, retry_until,
56188 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
56189 /* Has it gone just too far? */
56190 diff -urNp linux-2.6.37/net/ipv4/udp.c linux-2.6.37/net/ipv4/udp.c
56191 --- linux-2.6.37/net/ipv4/udp.c 2011-01-04 19:50:19.000000000 -0500
56192 +++ linux-2.6.37/net/ipv4/udp.c 2011-01-17 02:41:02.000000000 -0500
56193 @@ -86,6 +86,7 @@
56194 #include <linux/types.h>
56195 #include <linux/fcntl.h>
56196 #include <linux/module.h>
56197 +#include <linux/security.h>
56198 #include <linux/socket.h>
56199 #include <linux/sockios.h>
56200 #include <linux/igmp.h>
56201 @@ -107,6 +108,10 @@
56202 #include <net/xfrm.h>
56203 #include "udp_impl.h"
56204
56205 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
56206 +extern int grsec_enable_blackhole;
56207 +#endif
56208 +
56209 struct udp_table udp_table __read_mostly;
56210 EXPORT_SYMBOL(udp_table);
56211
56212 @@ -564,6 +569,9 @@ found:
56213 return s;
56214 }
56215
56216 +extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
56217 +extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
56218 +
56219 /*
56220 * This routine is called by the ICMP module when it gets some
56221 * sort of error condition. If err < 0 then the socket should
56222 @@ -832,9 +840,18 @@ int udp_sendmsg(struct kiocb *iocb, stru
56223 dport = usin->sin_port;
56224 if (dport == 0)
56225 return -EINVAL;
56226 +
56227 + err = gr_search_udp_sendmsg(sk, usin);
56228 + if (err)
56229 + return err;
56230 } else {
56231 if (sk->sk_state != TCP_ESTABLISHED)
56232 return -EDESTADDRREQ;
56233 +
56234 + err = gr_search_udp_sendmsg(sk, NULL);
56235 + if (err)
56236 + return err;
56237 +
56238 daddr = inet->inet_daddr;
56239 dport = inet->inet_dport;
56240 /* Open fast path for connected socket.
56241 @@ -1141,6 +1158,10 @@ try_again:
56242 if (!skb)
56243 goto out;
56244
56245 + err = gr_search_udp_recvmsg(sk, skb);
56246 + if (err)
56247 + goto out_free;
56248 +
56249 ulen = skb->len - sizeof(struct udphdr);
56250 if (len > ulen)
56251 len = ulen;
56252 @@ -1625,6 +1646,9 @@ int __udp4_lib_rcv(struct sk_buff *skb,
56253 goto csum_error;
56254
56255 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
56256 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
56257 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
56258 +#endif
56259 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
56260
56261 /*
56262 @@ -2052,7 +2076,12 @@ static void udp4_format_sock(struct sock
56263 sk_wmem_alloc_get(sp),
56264 sk_rmem_alloc_get(sp),
56265 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
56266 - atomic_read(&sp->sk_refcnt), sp,
56267 + atomic_read(&sp->sk_refcnt),
56268 +#ifdef CONFIG_GRKERNSEC_HIDESYM
56269 + NULL,
56270 +#else
56271 + sp,
56272 +#endif
56273 atomic_read(&sp->sk_drops), len);
56274 }
56275
56276 diff -urNp linux-2.6.37/net/ipv6/exthdrs.c linux-2.6.37/net/ipv6/exthdrs.c
56277 --- linux-2.6.37/net/ipv6/exthdrs.c 2011-01-04 19:50:19.000000000 -0500
56278 +++ linux-2.6.37/net/ipv6/exthdrs.c 2011-01-17 02:41:02.000000000 -0500
56279 @@ -634,7 +634,7 @@ static struct tlvtype_proc tlvprochopopt
56280 .type = IPV6_TLV_JUMBO,
56281 .func = ipv6_hop_jumbo,
56282 },
56283 - { -1, }
56284 + { -1, NULL }
56285 };
56286
56287 int ipv6_parse_hopopts(struct sk_buff *skb)
56288 diff -urNp linux-2.6.37/net/ipv6/raw.c linux-2.6.37/net/ipv6/raw.c
56289 --- linux-2.6.37/net/ipv6/raw.c 2011-01-04 19:50:19.000000000 -0500
56290 +++ linux-2.6.37/net/ipv6/raw.c 2011-01-17 02:41:02.000000000 -0500
56291 @@ -601,7 +601,7 @@ out:
56292 return err;
56293 }
56294
56295 -static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
56296 +static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
56297 struct flowi *fl, struct dst_entry **dstp,
56298 unsigned int flags)
56299 {
56300 @@ -1243,7 +1243,13 @@ static void raw6_sock_seq_show(struct se
56301 0, 0L, 0,
56302 sock_i_uid(sp), 0,
56303 sock_i_ino(sp),
56304 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
56305 + atomic_read(&sp->sk_refcnt),
56306 +#ifdef CONFIG_GRKERNSEC_HIDESYM
56307 + NULL,
56308 +#else
56309 + sp,
56310 +#endif
56311 + atomic_read(&sp->sk_drops));
56312 }
56313
56314 static int raw6_seq_show(struct seq_file *seq, void *v)
56315 diff -urNp linux-2.6.37/net/ipv6/tcp_ipv6.c linux-2.6.37/net/ipv6/tcp_ipv6.c
56316 --- linux-2.6.37/net/ipv6/tcp_ipv6.c 2011-01-04 19:50:19.000000000 -0500
56317 +++ linux-2.6.37/net/ipv6/tcp_ipv6.c 2011-01-17 02:41:02.000000000 -0500
56318 @@ -92,6 +92,10 @@ static struct tcp_md5sig_key *tcp_v6_md5
56319 }
56320 #endif
56321
56322 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
56323 +extern int grsec_enable_blackhole;
56324 +#endif
56325 +
56326 static void tcp_v6_hash(struct sock *sk)
56327 {
56328 if (sk->sk_state != TCP_CLOSE) {
56329 @@ -1631,6 +1635,9 @@ static int tcp_v6_do_rcv(struct sock *sk
56330 return 0;
56331
56332 reset:
56333 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
56334 + if (!grsec_enable_blackhole)
56335 +#endif
56336 tcp_v6_send_reset(sk, skb);
56337 discard:
56338 if (opt_skb)
56339 @@ -1710,12 +1717,20 @@ static int tcp_v6_rcv(struct sk_buff *sk
56340 TCP_SKB_CB(skb)->sacked = 0;
56341
56342 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
56343 - if (!sk)
56344 + if (!sk) {
56345 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
56346 + ret = 1;
56347 +#endif
56348 goto no_tcp_socket;
56349 + }
56350
56351 process:
56352 - if (sk->sk_state == TCP_TIME_WAIT)
56353 + if (sk->sk_state == TCP_TIME_WAIT) {
56354 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
56355 + ret = 2;
56356 +#endif
56357 goto do_time_wait;
56358 + }
56359
56360 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
56361 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
56362 @@ -1763,6 +1778,10 @@ no_tcp_socket:
56363 bad_packet:
56364 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
56365 } else {
56366 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
56367 + if (!grsec_enable_blackhole || (ret == 1 &&
56368 + (skb->dev->flags & IFF_LOOPBACK)))
56369 +#endif
56370 tcp_v6_send_reset(NULL, skb);
56371 }
56372
56373 @@ -1991,7 +2010,13 @@ static void get_openreq6(struct seq_file
56374 uid,
56375 0, /* non standard timer */
56376 0, /* open_requests have no inode */
56377 - 0, req);
56378 + 0,
56379 +#ifdef CONFIG_GRKERNSEC_HIDESYM
56380 + NULL
56381 +#else
56382 + req
56383 +#endif
56384 + );
56385 }
56386
56387 static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
56388 @@ -2041,7 +2066,12 @@ static void get_tcp6_sock(struct seq_fil
56389 sock_i_uid(sp),
56390 icsk->icsk_probes_out,
56391 sock_i_ino(sp),
56392 - atomic_read(&sp->sk_refcnt), sp,
56393 + atomic_read(&sp->sk_refcnt),
56394 +#ifdef CONFIG_GRKERNSEC_HIDESYM
56395 + NULL,
56396 +#else
56397 + sp,
56398 +#endif
56399 jiffies_to_clock_t(icsk->icsk_rto),
56400 jiffies_to_clock_t(icsk->icsk_ack.ato),
56401 (icsk->icsk_ack.quick << 1 ) | icsk->icsk_ack.pingpong,
56402 @@ -2076,7 +2106,13 @@ static void get_timewait6_sock(struct se
56403 dest->s6_addr32[2], dest->s6_addr32[3], destp,
56404 tw->tw_substate, 0, 0,
56405 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
56406 - atomic_read(&tw->tw_refcnt), tw);
56407 + atomic_read(&tw->tw_refcnt),
56408 +#ifdef CONFIG_GRKERNSEC_HIDESYM
56409 + NULL
56410 +#else
56411 + tw
56412 +#endif
56413 + );
56414 }
56415
56416 static int tcp6_seq_show(struct seq_file *seq, void *v)
56417 diff -urNp linux-2.6.37/net/ipv6/udp.c linux-2.6.37/net/ipv6/udp.c
56418 --- linux-2.6.37/net/ipv6/udp.c 2011-01-04 19:50:19.000000000 -0500
56419 +++ linux-2.6.37/net/ipv6/udp.c 2011-01-17 02:41:02.000000000 -0500
56420 @@ -50,6 +50,10 @@
56421 #include <linux/seq_file.h>
56422 #include "udp_impl.h"
56423
56424 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
56425 +extern int grsec_enable_blackhole;
56426 +#endif
56427 +
56428 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
56429 {
56430 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
56431 @@ -773,6 +777,9 @@ int __udp6_lib_rcv(struct sk_buff *skb,
56432 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS,
56433 proto == IPPROTO_UDPLITE);
56434
56435 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
56436 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
56437 +#endif
56438 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
56439
56440 kfree_skb(skb);
56441 @@ -1407,7 +1414,12 @@ static void udp6_sock_seq_show(struct se
56442 0, 0L, 0,
56443 sock_i_uid(sp), 0,
56444 sock_i_ino(sp),
56445 - atomic_read(&sp->sk_refcnt), sp,
56446 + atomic_read(&sp->sk_refcnt),
56447 +#ifdef CONFIG_GRKERNSEC_HIDESYM
56448 + NULL,
56449 +#else
56450 + sp,
56451 +#endif
56452 atomic_read(&sp->sk_drops));
56453 }
56454
56455 diff -urNp linux-2.6.37/net/irda/ircomm/ircomm_tty.c linux-2.6.37/net/irda/ircomm/ircomm_tty.c
56456 --- linux-2.6.37/net/irda/ircomm/ircomm_tty.c 2011-01-04 19:50:19.000000000 -0500
56457 +++ linux-2.6.37/net/irda/ircomm/ircomm_tty.c 2011-01-17 02:41:02.000000000 -0500
56458 @@ -281,16 +281,16 @@ static int ircomm_tty_block_til_ready(st
56459 add_wait_queue(&self->open_wait, &wait);
56460
56461 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
56462 - __FILE__,__LINE__, tty->driver->name, self->open_count );
56463 + __FILE__,__LINE__, tty->driver->name, atomic_read(&self->open_count) );
56464
56465 /* As far as I can see, we protect open_count - Jean II */
56466 spin_lock_irqsave(&self->spinlock, flags);
56467 if (!tty_hung_up_p(filp)) {
56468 extra_count = 1;
56469 - self->open_count--;
56470 + atomic_dec(&self->open_count);
56471 }
56472 spin_unlock_irqrestore(&self->spinlock, flags);
56473 - self->blocked_open++;
56474 + atomic_inc(&self->blocked_open);
56475
56476 while (1) {
56477 if (tty->termios->c_cflag & CBAUD) {
56478 @@ -330,7 +330,7 @@ static int ircomm_tty_block_til_ready(st
56479 }
56480
56481 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
56482 - __FILE__,__LINE__, tty->driver->name, self->open_count );
56483 + __FILE__,__LINE__, tty->driver->name, atomic_read(&self->open_count) );
56484
56485 schedule();
56486 }
56487 @@ -341,13 +341,13 @@ static int ircomm_tty_block_til_ready(st
56488 if (extra_count) {
56489 /* ++ is not atomic, so this should be protected - Jean II */
56490 spin_lock_irqsave(&self->spinlock, flags);
56491 - self->open_count++;
56492 + atomic_inc(&self->open_count);
56493 spin_unlock_irqrestore(&self->spinlock, flags);
56494 }
56495 - self->blocked_open--;
56496 + atomic_dec(&self->blocked_open);
56497
56498 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
56499 - __FILE__,__LINE__, tty->driver->name, self->open_count);
56500 + __FILE__,__LINE__, tty->driver->name, atomic_read(&self->open_count));
56501
56502 if (!retval)
56503 self->flags |= ASYNC_NORMAL_ACTIVE;
56504 @@ -416,14 +416,14 @@ static int ircomm_tty_open(struct tty_st
56505 }
56506 /* ++ is not atomic, so this should be protected - Jean II */
56507 spin_lock_irqsave(&self->spinlock, flags);
56508 - self->open_count++;
56509 + atomic_inc(&self->open_count);
56510
56511 tty->driver_data = self;
56512 self->tty = tty;
56513 spin_unlock_irqrestore(&self->spinlock, flags);
56514
56515 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
56516 - self->line, self->open_count);
56517 + self->line, atomic_read(&self->open_count));
56518
56519 /* Not really used by us, but lets do it anyway */
56520 self->tty->low_latency = (self->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
56521 @@ -509,7 +509,7 @@ static void ircomm_tty_close(struct tty_
56522 return;
56523 }
56524
56525 - if ((tty->count == 1) && (self->open_count != 1)) {
56526 + if ((tty->count == 1) && (atomic_read(&self->open_count) != 1)) {
56527 /*
56528 * Uh, oh. tty->count is 1, which means that the tty
56529 * structure will be freed. state->count should always
56530 @@ -519,16 +519,16 @@ static void ircomm_tty_close(struct tty_
56531 */
56532 IRDA_DEBUG(0, "%s(), bad serial port count; "
56533 "tty->count is 1, state->count is %d\n", __func__ ,
56534 - self->open_count);
56535 - self->open_count = 1;
56536 + atomic_read(&self->open_count));
56537 + atomic_set(&self->open_count, 1);
56538 }
56539
56540 - if (--self->open_count < 0) {
56541 + if (atomic_dec_return(&self->open_count) < 0) {
56542 IRDA_ERROR("%s(), bad serial port count for ttys%d: %d\n",
56543 - __func__, self->line, self->open_count);
56544 - self->open_count = 0;
56545 + __func__, self->line, atomic_read(&self->open_count));
56546 + atomic_set(&self->open_count, 0);
56547 }
56548 - if (self->open_count) {
56549 + if (atomic_read(&self->open_count)) {
56550 spin_unlock_irqrestore(&self->spinlock, flags);
56551
56552 IRDA_DEBUG(0, "%s(), open count > 0\n", __func__ );
56553 @@ -560,7 +560,7 @@ static void ircomm_tty_close(struct tty_
56554 tty->closing = 0;
56555 self->tty = NULL;
56556
56557 - if (self->blocked_open) {
56558 + if (atomic_read(&self->blocked_open)) {
56559 if (self->close_delay)
56560 schedule_timeout_interruptible(self->close_delay);
56561 wake_up_interruptible(&self->open_wait);
56562 @@ -1012,7 +1012,7 @@ static void ircomm_tty_hangup(struct tty
56563 spin_lock_irqsave(&self->spinlock, flags);
56564 self->flags &= ~ASYNC_NORMAL_ACTIVE;
56565 self->tty = NULL;
56566 - self->open_count = 0;
56567 + atomic_set(&self->open_count, 0);
56568 spin_unlock_irqrestore(&self->spinlock, flags);
56569
56570 wake_up_interruptible(&self->open_wait);
56571 @@ -1364,7 +1364,7 @@ static void ircomm_tty_line_info(struct
56572 seq_putc(m, '\n');
56573
56574 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
56575 - seq_printf(m, "Open count: %d\n", self->open_count);
56576 + seq_printf(m, "Open count: %d\n", atomic_read(&self->open_count));
56577 seq_printf(m, "Max data size: %d\n", self->max_data_size);
56578 seq_printf(m, "Max header size: %d\n", self->max_header_size);
56579
56580 diff -urNp linux-2.6.37/net/key/af_key.c linux-2.6.37/net/key/af_key.c
56581 --- linux-2.6.37/net/key/af_key.c 2011-01-04 19:50:19.000000000 -0500
56582 +++ linux-2.6.37/net/key/af_key.c 2011-01-17 02:41:02.000000000 -0500
56583 @@ -3644,7 +3644,11 @@ static int pfkey_seq_show(struct seq_fil
56584 seq_printf(f ,"sk RefCnt Rmem Wmem User Inode\n");
56585 else
56586 seq_printf(f ,"%p %-6d %-6u %-6u %-6u %-6lu\n",
56587 +#ifdef CONFIG_GRKERNSEC_HIDESYM
56588 + NULL,
56589 +#else
56590 s,
56591 +#endif
56592 atomic_read(&s->sk_refcnt),
56593 sk_rmem_alloc_get(s),
56594 sk_wmem_alloc_get(s),
56595 diff -urNp linux-2.6.37/net/mac80211/ieee80211_i.h linux-2.6.37/net/mac80211/ieee80211_i.h
56596 --- linux-2.6.37/net/mac80211/ieee80211_i.h 2011-01-04 19:50:19.000000000 -0500
56597 +++ linux-2.6.37/net/mac80211/ieee80211_i.h 2011-01-17 02:41:02.000000000 -0500
56598 @@ -704,7 +704,7 @@ struct ieee80211_local {
56599 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
56600 spinlock_t queue_stop_reason_lock;
56601
56602 - int open_count;
56603 + atomic_t open_count;
56604 int monitors, cooked_mntrs;
56605 /* number of interfaces with corresponding FIF_ flags */
56606 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
56607 diff -urNp linux-2.6.37/net/mac80211/iface.c linux-2.6.37/net/mac80211/iface.c
56608 --- linux-2.6.37/net/mac80211/iface.c 2011-01-04 19:50:19.000000000 -0500
56609 +++ linux-2.6.37/net/mac80211/iface.c 2011-01-17 02:41:02.000000000 -0500
56610 @@ -216,7 +216,7 @@ static int ieee80211_do_open(struct net_
56611 break;
56612 }
56613
56614 - if (local->open_count == 0) {
56615 + if (atomic_read(&local->open_count) == 0) {
56616 res = drv_start(local);
56617 if (res)
56618 goto err_del_bss;
56619 @@ -238,7 +238,7 @@ static int ieee80211_do_open(struct net_
56620 memcpy(dev->perm_addr, dev->dev_addr, ETH_ALEN);
56621
56622 if (!is_valid_ether_addr(dev->dev_addr)) {
56623 - if (!local->open_count)
56624 + if (!atomic_read(&local->open_count))
56625 drv_stop(local);
56626 return -EADDRNOTAVAIL;
56627 }
56628 @@ -335,7 +335,7 @@ static int ieee80211_do_open(struct net_
56629 mutex_unlock(&local->mtx);
56630
56631 if (coming_up)
56632 - local->open_count++;
56633 + atomic_inc(&local->open_count);
56634
56635 if (hw_reconf_flags) {
56636 ieee80211_hw_config(local, hw_reconf_flags);
56637 @@ -355,7 +355,7 @@ static int ieee80211_do_open(struct net_
56638 err_del_interface:
56639 drv_remove_interface(local, &sdata->vif);
56640 err_stop:
56641 - if (!local->open_count)
56642 + if (!atomic_read(&local->open_count))
56643 drv_stop(local);
56644 err_del_bss:
56645 sdata->bss = NULL;
56646 @@ -481,7 +481,7 @@ static void ieee80211_do_stop(struct iee
56647 }
56648
56649 if (going_down)
56650 - local->open_count--;
56651 + atomic_dec(&local->open_count);
56652
56653 switch (sdata->vif.type) {
56654 case NL80211_IFTYPE_AP_VLAN:
56655 @@ -552,7 +552,7 @@ static void ieee80211_do_stop(struct iee
56656
56657 ieee80211_recalc_ps(local, -1);
56658
56659 - if (local->open_count == 0) {
56660 + if (atomic_read(&local->open_count) == 0) {
56661 if (local->ops->napi_poll)
56662 napi_disable(&local->napi);
56663 ieee80211_clear_tx_pending(local);
56664 diff -urNp linux-2.6.37/net/mac80211/main.c linux-2.6.37/net/mac80211/main.c
56665 --- linux-2.6.37/net/mac80211/main.c 2011-01-04 19:50:19.000000000 -0500
56666 +++ linux-2.6.37/net/mac80211/main.c 2011-01-17 02:41:02.000000000 -0500
56667 @@ -159,7 +159,7 @@ int ieee80211_hw_config(struct ieee80211
56668 local->hw.conf.power_level = power;
56669 }
56670
56671 - if (changed && local->open_count) {
56672 + if (changed && atomic_read(&local->open_count)) {
56673 ret = drv_config(local, changed);
56674 /*
56675 * Goal:
56676 diff -urNp linux-2.6.37/net/mac80211/pm.c linux-2.6.37/net/mac80211/pm.c
56677 --- linux-2.6.37/net/mac80211/pm.c 2011-01-04 19:50:19.000000000 -0500
56678 +++ linux-2.6.37/net/mac80211/pm.c 2011-01-17 02:41:02.000000000 -0500
56679 @@ -95,7 +95,7 @@ int __ieee80211_suspend(struct ieee80211
56680 }
56681
56682 /* stop hardware - this must stop RX */
56683 - if (local->open_count)
56684 + if (atomic_read(&local->open_count))
56685 ieee80211_stop_device(local);
56686
56687 local->suspended = true;
56688 diff -urNp linux-2.6.37/net/mac80211/rate.c linux-2.6.37/net/mac80211/rate.c
56689 --- linux-2.6.37/net/mac80211/rate.c 2011-01-04 19:50:19.000000000 -0500
56690 +++ linux-2.6.37/net/mac80211/rate.c 2011-01-17 02:41:02.000000000 -0500
56691 @@ -361,7 +361,7 @@ int ieee80211_init_rate_ctrl_alg(struct
56692
56693 ASSERT_RTNL();
56694
56695 - if (local->open_count)
56696 + if (atomic_read(&local->open_count))
56697 return -EBUSY;
56698
56699 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
56700 diff -urNp linux-2.6.37/net/mac80211/rc80211_pid_debugfs.c linux-2.6.37/net/mac80211/rc80211_pid_debugfs.c
56701 --- linux-2.6.37/net/mac80211/rc80211_pid_debugfs.c 2011-01-04 19:50:19.000000000 -0500
56702 +++ linux-2.6.37/net/mac80211/rc80211_pid_debugfs.c 2011-01-17 02:41:02.000000000 -0500
56703 @@ -192,7 +192,7 @@ static ssize_t rate_control_pid_events_r
56704
56705 spin_unlock_irqrestore(&events->lock, status);
56706
56707 - if (copy_to_user(buf, pb, p))
56708 + if (p > sizeof(pb) || copy_to_user(buf, pb, p))
56709 return -EFAULT;
56710
56711 return p;
56712 diff -urNp linux-2.6.37/net/mac80211/tx.c linux-2.6.37/net/mac80211/tx.c
56713 --- linux-2.6.37/net/mac80211/tx.c 2011-01-04 19:50:19.000000000 -0500
56714 +++ linux-2.6.37/net/mac80211/tx.c 2011-01-17 02:41:02.000000000 -0500
56715 @@ -173,7 +173,7 @@ static __le16 ieee80211_duration(struct
56716 return cpu_to_le16(dur);
56717 }
56718
56719 -static int inline is_ieee80211_device(struct ieee80211_local *local,
56720 +static inline int is_ieee80211_device(struct ieee80211_local *local,
56721 struct net_device *dev)
56722 {
56723 return local == wdev_priv(dev->ieee80211_ptr);
56724 diff -urNp linux-2.6.37/net/mac80211/util.c linux-2.6.37/net/mac80211/util.c
56725 --- linux-2.6.37/net/mac80211/util.c 2011-01-04 19:50:19.000000000 -0500
56726 +++ linux-2.6.37/net/mac80211/util.c 2011-01-17 02:41:02.000000000 -0500
56727 @@ -1111,7 +1111,7 @@ int ieee80211_reconfig(struct ieee80211_
56728 local->resuming = true;
56729
56730 /* restart hardware */
56731 - if (local->open_count) {
56732 + if (atomic_read(&local->open_count)) {
56733 /*
56734 * Upon resume hardware can sometimes be goofy due to
56735 * various platform / driver / bus issues, so restarting
56736 diff -urNp linux-2.6.37/net/netfilter/Kconfig linux-2.6.37/net/netfilter/Kconfig
56737 --- linux-2.6.37/net/netfilter/Kconfig 2011-01-04 19:50:19.000000000 -0500
56738 +++ linux-2.6.37/net/netfilter/Kconfig 2011-01-17 02:41:02.000000000 -0500
56739 @@ -709,6 +709,16 @@ config NETFILTER_XT_MATCH_ESP
56740
56741 To compile it as a module, choose M here. If unsure, say N.
56742
56743 +config NETFILTER_XT_MATCH_GRADM
56744 + tristate '"gradm" match support'
56745 + depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
56746 + depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
56747 + ---help---
56748 + The gradm match allows to match on grsecurity RBAC being enabled.
56749 + It is useful when iptables rules are applied early on bootup to
56750 + prevent connections to the machine (except from a trusted host)
56751 + while the RBAC system is disabled.
56752 +
56753 config NETFILTER_XT_MATCH_HASHLIMIT
56754 tristate '"hashlimit" match support'
56755 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
56756 diff -urNp linux-2.6.37/net/netfilter/Makefile linux-2.6.37/net/netfilter/Makefile
56757 --- linux-2.6.37/net/netfilter/Makefile 2011-01-04 19:50:19.000000000 -0500
56758 +++ linux-2.6.37/net/netfilter/Makefile 2011-01-17 02:41:02.000000000 -0500
56759 @@ -74,6 +74,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_CPU) +=
56760 obj-$(CONFIG_NETFILTER_XT_MATCH_DCCP) += xt_dccp.o
56761 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
56762 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
56763 +obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
56764 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
56765 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
56766 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
56767 diff -urNp linux-2.6.37/net/netfilter/nf_conntrack_netlink.c linux-2.6.37/net/netfilter/nf_conntrack_netlink.c
56768 --- linux-2.6.37/net/netfilter/nf_conntrack_netlink.c 2011-01-04 19:50:19.000000000 -0500
56769 +++ linux-2.6.37/net/netfilter/nf_conntrack_netlink.c 2011-01-17 02:41:02.000000000 -0500
56770 @@ -761,7 +761,7 @@ static const struct nla_policy tuple_nla
56771 static int
56772 ctnetlink_parse_tuple(const struct nlattr * const cda[],
56773 struct nf_conntrack_tuple *tuple,
56774 - enum ctattr_tuple type, u_int8_t l3num)
56775 + enum ctattr_type type, u_int8_t l3num)
56776 {
56777 struct nlattr *tb[CTA_TUPLE_MAX+1];
56778 int err;
56779 diff -urNp linux-2.6.37/net/netfilter/xt_gradm.c linux-2.6.37/net/netfilter/xt_gradm.c
56780 --- linux-2.6.37/net/netfilter/xt_gradm.c 1969-12-31 19:00:00.000000000 -0500
56781 +++ linux-2.6.37/net/netfilter/xt_gradm.c 2011-01-17 02:41:02.000000000 -0500
56782 @@ -0,0 +1,51 @@
56783 +/*
56784 + * gradm match for netfilter
56785 + * Copyright © Zbigniew Krzystolik, 2010
56786 + *
56787 + * This program is free software; you can redistribute it and/or modify
56788 + * it under the terms of the GNU General Public License; either version
56789 + * 2 or 3 as published by the Free Software Foundation.
56790 + */
56791 +#include <linux/module.h>
56792 +#include <linux/moduleparam.h>
56793 +#include <linux/skbuff.h>
56794 +#include <linux/netfilter/x_tables.h>
56795 +#include <linux/grsecurity.h>
56796 +#include <linux/netfilter/xt_gradm.h>
56797 +
56798 +static bool
56799 +gradm_mt(const struct sk_buff *skb, struct xt_action_param *par)
56800 +{
56801 + const struct xt_gradm_mtinfo *info = par->matchinfo;
56802 + bool retval = false;
56803 + if (gr_acl_is_enabled())
56804 + retval = true;
56805 + return retval ^ info->invflags;
56806 +}
56807 +
56808 +static struct xt_match gradm_mt_reg __read_mostly = {
56809 + .name = "gradm",
56810 + .revision = 0,
56811 + .family = NFPROTO_UNSPEC,
56812 + .match = gradm_mt,
56813 + .matchsize = XT_ALIGN(sizeof(struct xt_gradm_mtinfo)),
56814 + .me = THIS_MODULE,
56815 +};
56816 +
56817 +static int __init gradm_mt_init(void)
56818 +{
56819 + return xt_register_match(&gradm_mt_reg);
56820 +}
56821 +
56822 +static void __exit gradm_mt_exit(void)
56823 +{
56824 + xt_unregister_match(&gradm_mt_reg);
56825 +}
56826 +
56827 +module_init(gradm_mt_init);
56828 +module_exit(gradm_mt_exit);
56829 +MODULE_AUTHOR("Zbigniew Krzystolik <zbyniu@destrukcja.pl>");
56830 +MODULE_DESCRIPTION("Xtables: Grsecurity RBAC match");
56831 +MODULE_LICENSE("GPL");
56832 +MODULE_ALIAS("ipt_gradm");
56833 +MODULE_ALIAS("ip6t_gradm");
56834 diff -urNp linux-2.6.37/net/netlink/af_netlink.c linux-2.6.37/net/netlink/af_netlink.c
56835 --- linux-2.6.37/net/netlink/af_netlink.c 2011-01-04 19:50:19.000000000 -0500
56836 +++ linux-2.6.37/net/netlink/af_netlink.c 2011-01-17 02:41:02.000000000 -0500
56837 @@ -1991,13 +1991,21 @@ static int netlink_seq_show(struct seq_f
56838 struct netlink_sock *nlk = nlk_sk(s);
56839
56840 seq_printf(seq, "%p %-3d %-6d %08x %-8d %-8d %p %-8d %-8d %-8lu\n",
56841 +#ifdef CONFIG_GRKERNSEC_HIDESYM
56842 + NULL,
56843 +#else
56844 s,
56845 +#endif
56846 s->sk_protocol,
56847 nlk->pid,
56848 nlk->groups ? (u32)nlk->groups[0] : 0,
56849 sk_rmem_alloc_get(s),
56850 sk_wmem_alloc_get(s),
56851 +#ifdef CONFIG_GRKERNSEC_HIDESYM
56852 + NULL,
56853 +#else
56854 nlk->cb,
56855 +#endif
56856 atomic_read(&s->sk_refcnt),
56857 atomic_read(&s->sk_drops),
56858 sock_i_ino(s)
56859 diff -urNp linux-2.6.37/net/netrom/af_netrom.c linux-2.6.37/net/netrom/af_netrom.c
56860 --- linux-2.6.37/net/netrom/af_netrom.c 2011-01-04 19:50:19.000000000 -0500
56861 +++ linux-2.6.37/net/netrom/af_netrom.c 2011-01-17 02:41:02.000000000 -0500
56862 @@ -840,6 +840,7 @@ static int nr_getname(struct socket *soc
56863 struct sock *sk = sock->sk;
56864 struct nr_sock *nr = nr_sk(sk);
56865
56866 + memset(sax, 0, sizeof(*sax));
56867 lock_sock(sk);
56868 if (peer != 0) {
56869 if (sk->sk_state != TCP_ESTABLISHED) {
56870 @@ -854,7 +855,6 @@ static int nr_getname(struct socket *soc
56871 *uaddr_len = sizeof(struct full_sockaddr_ax25);
56872 } else {
56873 sax->fsa_ax25.sax25_family = AF_NETROM;
56874 - sax->fsa_ax25.sax25_ndigis = 0;
56875 sax->fsa_ax25.sax25_call = nr->source_addr;
56876 *uaddr_len = sizeof(struct sockaddr_ax25);
56877 }
56878 diff -urNp linux-2.6.37/net/packet/af_packet.c linux-2.6.37/net/packet/af_packet.c
56879 --- linux-2.6.37/net/packet/af_packet.c 2011-01-04 19:50:19.000000000 -0500
56880 +++ linux-2.6.37/net/packet/af_packet.c 2011-01-17 02:41:02.000000000 -0500
56881 @@ -2123,7 +2123,7 @@ static int packet_getsockopt(struct sock
56882 case PACKET_HDRLEN:
56883 if (len > sizeof(int))
56884 len = sizeof(int);
56885 - if (copy_from_user(&val, optval, len))
56886 + if (len > sizeof(val) || copy_from_user(&val, optval, len))
56887 return -EFAULT;
56888 switch (val) {
56889 case TPACKET_V1:
56890 @@ -2161,7 +2161,7 @@ static int packet_getsockopt(struct sock
56891
56892 if (put_user(len, optlen))
56893 return -EFAULT;
56894 - if (copy_to_user(optval, data, len))
56895 + if (len > sizeof(st) || copy_to_user(optval, data, len))
56896 return -EFAULT;
56897 return 0;
56898 }
56899 @@ -2640,7 +2640,11 @@ static int packet_seq_show(struct seq_fi
56900
56901 seq_printf(seq,
56902 "%p %-6d %-4d %04x %-5d %1d %-6u %-6u %-6lu\n",
56903 +#ifdef CONFIG_GRKERNSEC_HIDESYM
56904 + NULL,
56905 +#else
56906 s,
56907 +#endif
56908 atomic_read(&s->sk_refcnt),
56909 s->sk_type,
56910 ntohs(po->num),
56911 diff -urNp linux-2.6.37/net/phonet/af_phonet.c linux-2.6.37/net/phonet/af_phonet.c
56912 --- linux-2.6.37/net/phonet/af_phonet.c 2011-01-04 19:50:19.000000000 -0500
56913 +++ linux-2.6.37/net/phonet/af_phonet.c 2011-01-17 02:41:02.000000000 -0500
56914 @@ -41,7 +41,7 @@ static struct phonet_protocol *phonet_pr
56915 {
56916 struct phonet_protocol *pp;
56917
56918 - if (protocol >= PHONET_NPROTO)
56919 + if (protocol < 0 || protocol >= PHONET_NPROTO)
56920 return NULL;
56921
56922 rcu_read_lock();
56923 @@ -463,7 +463,7 @@ int __init_or_module phonet_proto_regist
56924 {
56925 int err = 0;
56926
56927 - if (protocol >= PHONET_NPROTO)
56928 + if (protocol < 0 || protocol >= PHONET_NPROTO)
56929 return -EINVAL;
56930
56931 err = proto_register(pp->prot, 1);
56932 diff -urNp linux-2.6.37/net/phonet/socket.c linux-2.6.37/net/phonet/socket.c
56933 --- linux-2.6.37/net/phonet/socket.c 2011-01-04 19:50:19.000000000 -0500
56934 +++ linux-2.6.37/net/phonet/socket.c 2011-01-17 02:41:02.000000000 -0500
56935 @@ -637,7 +637,12 @@ static int pn_sock_seq_show(struct seq_f
56936 sk->sk_state,
56937 sk_wmem_alloc_get(sk), sk_rmem_alloc_get(sk),
56938 sock_i_uid(sk), sock_i_ino(sk),
56939 - atomic_read(&sk->sk_refcnt), sk,
56940 + atomic_read(&sk->sk_refcnt),
56941 +#ifdef CONFIG_GRKERNSEC_HIDESYM
56942 + NULL,
56943 +#else
56944 + sk,
56945 +#endif
56946 atomic_read(&sk->sk_drops), &len);
56947 }
56948 seq_printf(seq, "%*s\n", 127 - len, "");
56949 diff -urNp linux-2.6.37/net/sctp/proc.c linux-2.6.37/net/sctp/proc.c
56950 --- linux-2.6.37/net/sctp/proc.c 2011-01-04 19:50:19.000000000 -0500
56951 +++ linux-2.6.37/net/sctp/proc.c 2011-01-17 02:41:02.000000000 -0500
56952 @@ -212,7 +212,12 @@ static int sctp_eps_seq_show(struct seq_
56953 sctp_for_each_hentry(epb, node, &head->chain) {
56954 ep = sctp_ep(epb);
56955 sk = epb->sk;
56956 - seq_printf(seq, "%8p %8p %-3d %-3d %-4d %-5d %5d %5lu ", ep, sk,
56957 + seq_printf(seq, "%8p %8p %-3d %-3d %-4d %-5d %5d %5lu ",
56958 +#ifdef CONFIG_GRKERNSEC_HIDESYM
56959 + NULL, NULL,
56960 +#else
56961 + ep, sk,
56962 +#endif
56963 sctp_sk(sk)->type, sk->sk_state, hash,
56964 epb->bind_addr.port,
56965 sock_i_uid(sk), sock_i_ino(sk));
56966 @@ -318,7 +323,12 @@ static int sctp_assocs_seq_show(struct s
56967 seq_printf(seq,
56968 "%8p %8p %-3d %-3d %-2d %-4d "
56969 "%4d %8d %8d %7d %5lu %-5d %5d ",
56970 - assoc, sk, sctp_sk(sk)->type, sk->sk_state,
56971 +#ifdef CONFIG_GRKERNSEC_HIDESYM
56972 + NULL, NULL,
56973 +#else
56974 + assoc, sk,
56975 +#endif
56976 + sctp_sk(sk)->type, sk->sk_state,
56977 assoc->state, hash,
56978 assoc->assoc_id,
56979 assoc->sndbuf_used,
56980 diff -urNp linux-2.6.37/net/sctp/socket.c linux-2.6.37/net/sctp/socket.c
56981 --- linux-2.6.37/net/sctp/socket.c 2011-01-04 19:50:19.000000000 -0500
56982 +++ linux-2.6.37/net/sctp/socket.c 2011-01-17 02:41:02.000000000 -0500
56983 @@ -1496,7 +1496,7 @@ SCTP_STATIC int sctp_sendmsg(struct kioc
56984 struct sctp_sndrcvinfo *sinfo;
56985 struct sctp_initmsg *sinit;
56986 sctp_assoc_t associd = 0;
56987 - sctp_cmsgs_t cmsgs = { NULL };
56988 + sctp_cmsgs_t cmsgs = { NULL, NULL };
56989 int err;
56990 sctp_scope_t scope;
56991 long timeo;
56992 @@ -4435,7 +4435,7 @@ static int sctp_getsockopt_peer_addrs(st
56993 addrlen = sctp_get_af_specific(temp.sa.sa_family)->sockaddr_len;
56994 if (space_left < addrlen)
56995 return -ENOMEM;
56996 - if (copy_to_user(to, &temp, addrlen))
56997 + if (addrlen > sizeof(temp) || copy_to_user(to, &temp, addrlen))
56998 return -EFAULT;
56999 to += addrlen;
57000 cnt++;
57001 diff -urNp linux-2.6.37/net/socket.c linux-2.6.37/net/socket.c
57002 --- linux-2.6.37/net/socket.c 2011-01-04 19:50:19.000000000 -0500
57003 +++ linux-2.6.37/net/socket.c 2011-01-17 02:41:02.000000000 -0500
57004 @@ -88,6 +88,7 @@
57005 #include <linux/nsproxy.h>
57006 #include <linux/magic.h>
57007 #include <linux/slab.h>
57008 +#include <linux/in.h>
57009
57010 #include <asm/uaccess.h>
57011 #include <asm/unistd.h>
57012 @@ -105,6 +106,8 @@
57013 #include <linux/sockios.h>
57014 #include <linux/atalk.h>
57015
57016 +#include <linux/grsock.h>
57017 +
57018 static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
57019 static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
57020 unsigned long nr_segs, loff_t pos);
57021 @@ -311,7 +314,7 @@ static struct dentry *sockfs_mount(struc
57022 return mount_pseudo(fs_type, "socket:", &sockfs_ops, SOCKFS_MAGIC);
57023 }
57024
57025 -static struct vfsmount *sock_mnt __read_mostly;
57026 +struct vfsmount *sock_mnt __read_mostly;
57027
57028 static struct file_system_type sock_fs_type = {
57029 .name = "sockfs",
57030 @@ -1173,6 +1176,8 @@ int __sock_create(struct net *net, int f
57031 return -EAFNOSUPPORT;
57032 if (type < 0 || type >= SOCK_MAX)
57033 return -EINVAL;
57034 + if (protocol < 0)
57035 + return -EINVAL;
57036
57037 /* Compatibility.
57038
57039 @@ -1305,6 +1310,16 @@ SYSCALL_DEFINE3(socket, int, family, int
57040 if (SOCK_NONBLOCK != O_NONBLOCK && (flags & SOCK_NONBLOCK))
57041 flags = (flags & ~SOCK_NONBLOCK) | O_NONBLOCK;
57042
57043 + if(!gr_search_socket(family, type, protocol)) {
57044 + retval = -EACCES;
57045 + goto out;
57046 + }
57047 +
57048 + if (gr_handle_sock_all(family, type, protocol)) {
57049 + retval = -EACCES;
57050 + goto out;
57051 + }
57052 +
57053 retval = sock_create(family, type, protocol, &sock);
57054 if (retval < 0)
57055 goto out;
57056 @@ -1417,6 +1432,14 @@ SYSCALL_DEFINE3(bind, int, fd, struct so
57057 if (sock) {
57058 err = move_addr_to_kernel(umyaddr, addrlen, (struct sockaddr *)&address);
57059 if (err >= 0) {
57060 + if (gr_handle_sock_server((struct sockaddr *)&address)) {
57061 + err = -EACCES;
57062 + goto error;
57063 + }
57064 + err = gr_search_bind(sock, (struct sockaddr_in *)&address);
57065 + if (err)
57066 + goto error;
57067 +
57068 err = security_socket_bind(sock,
57069 (struct sockaddr *)&address,
57070 addrlen);
57071 @@ -1425,6 +1448,7 @@ SYSCALL_DEFINE3(bind, int, fd, struct so
57072 (struct sockaddr *)
57073 &address, addrlen);
57074 }
57075 +error:
57076 fput_light(sock->file, fput_needed);
57077 }
57078 return err;
57079 @@ -1448,10 +1472,20 @@ SYSCALL_DEFINE2(listen, int, fd, int, ba
57080 if ((unsigned)backlog > somaxconn)
57081 backlog = somaxconn;
57082
57083 + if (gr_handle_sock_server_other(sock->sk)) {
57084 + err = -EPERM;
57085 + goto error;
57086 + }
57087 +
57088 + err = gr_search_listen(sock);
57089 + if (err)
57090 + goto error;
57091 +
57092 err = security_socket_listen(sock, backlog);
57093 if (!err)
57094 err = sock->ops->listen(sock, backlog);
57095
57096 +error:
57097 fput_light(sock->file, fput_needed);
57098 }
57099 return err;
57100 @@ -1495,6 +1529,18 @@ SYSCALL_DEFINE4(accept4, int, fd, struct
57101 newsock->type = sock->type;
57102 newsock->ops = sock->ops;
57103
57104 + if (gr_handle_sock_server_other(sock->sk)) {
57105 + err = -EPERM;
57106 + sock_release(newsock);
57107 + goto out_put;
57108 + }
57109 +
57110 + err = gr_search_accept(sock);
57111 + if (err) {
57112 + sock_release(newsock);
57113 + goto out_put;
57114 + }
57115 +
57116 /*
57117 * We don't need try_module_get here, as the listening socket (sock)
57118 * has the protocol module (sock->ops->owner) held.
57119 @@ -1533,6 +1579,8 @@ SYSCALL_DEFINE4(accept4, int, fd, struct
57120 fd_install(newfd, newfile);
57121 err = newfd;
57122
57123 + gr_attach_curr_ip(newsock->sk);
57124 +
57125 out_put:
57126 fput_light(sock->file, fput_needed);
57127 out:
57128 @@ -1565,6 +1613,7 @@ SYSCALL_DEFINE3(connect, int, fd, struct
57129 int, addrlen)
57130 {
57131 struct socket *sock;
57132 + struct sockaddr *sck;
57133 struct sockaddr_storage address;
57134 int err, fput_needed;
57135
57136 @@ -1575,6 +1624,17 @@ SYSCALL_DEFINE3(connect, int, fd, struct
57137 if (err < 0)
57138 goto out_put;
57139
57140 + sck = (struct sockaddr *)&address;
57141 +
57142 + if (gr_handle_sock_client(sck)) {
57143 + err = -EACCES;
57144 + goto out_put;
57145 + }
57146 +
57147 + err = gr_search_connect(sock, (struct sockaddr_in *)sck);
57148 + if (err)
57149 + goto out_put;
57150 +
57151 err =
57152 security_socket_connect(sock, (struct sockaddr *)&address, addrlen);
57153 if (err)
57154 diff -urNp linux-2.6.37/net/sunrpc/sched.c linux-2.6.37/net/sunrpc/sched.c
57155 --- linux-2.6.37/net/sunrpc/sched.c 2011-01-04 19:50:19.000000000 -0500
57156 +++ linux-2.6.37/net/sunrpc/sched.c 2011-01-17 02:41:02.000000000 -0500
57157 @@ -234,9 +234,9 @@ static int rpc_wait_bit_killable(void *w
57158 #ifdef RPC_DEBUG
57159 static void rpc_task_set_debuginfo(struct rpc_task *task)
57160 {
57161 - static atomic_t rpc_pid;
57162 + static atomic_unchecked_t rpc_pid;
57163
57164 - task->tk_pid = atomic_inc_return(&rpc_pid);
57165 + task->tk_pid = atomic_inc_return_unchecked(&rpc_pid);
57166 }
57167 #else
57168 static inline void rpc_task_set_debuginfo(struct rpc_task *task)
57169 diff -urNp linux-2.6.37/net/sunrpc/xprtrdma/svc_rdma.c linux-2.6.37/net/sunrpc/xprtrdma/svc_rdma.c
57170 --- linux-2.6.37/net/sunrpc/xprtrdma/svc_rdma.c 2011-01-04 19:50:19.000000000 -0500
57171 +++ linux-2.6.37/net/sunrpc/xprtrdma/svc_rdma.c 2011-01-17 02:41:02.000000000 -0500
57172 @@ -109,7 +109,7 @@ static int read_reset_stat(ctl_table *ta
57173 len -= *ppos;
57174 if (len > *lenp)
57175 len = *lenp;
57176 - if (len && copy_to_user(buffer, str_buf, len))
57177 + if (len > sizeof str_buf || (len && copy_to_user(buffer, str_buf, len)))
57178 return -EFAULT;
57179 *lenp = len;
57180 *ppos += len;
57181 diff -urNp linux-2.6.37/net/sysctl_net.c linux-2.6.37/net/sysctl_net.c
57182 --- linux-2.6.37/net/sysctl_net.c 2011-01-04 19:50:19.000000000 -0500
57183 +++ linux-2.6.37/net/sysctl_net.c 2011-01-17 02:41:02.000000000 -0500
57184 @@ -46,7 +46,7 @@ static int net_ctl_permissions(struct ct
57185 struct ctl_table *table)
57186 {
57187 /* Allow network administrator to have same access as root. */
57188 - if (capable(CAP_NET_ADMIN)) {
57189 + if (capable_nolog(CAP_NET_ADMIN)) {
57190 int mode = (table->mode >> 6) & 7;
57191 return (mode << 6) | (mode << 3) | mode;
57192 }
57193 diff -urNp linux-2.6.37/net/tipc/socket.c linux-2.6.37/net/tipc/socket.c
57194 --- linux-2.6.37/net/tipc/socket.c 2011-01-04 19:50:19.000000000 -0500
57195 +++ linux-2.6.37/net/tipc/socket.c 2011-01-17 02:41:02.000000000 -0500
57196 @@ -1475,8 +1475,9 @@ static int connect(struct socket *sock,
57197 } else {
57198 if (res == 0)
57199 res = -ETIMEDOUT;
57200 - else
57201 - ; /* leave "res" unchanged */
57202 + else {
57203 + /* leave "res" unchanged */
57204 + }
57205 sock->state = SS_DISCONNECTING;
57206 }
57207
57208 diff -urNp linux-2.6.37/net/unix/af_unix.c linux-2.6.37/net/unix/af_unix.c
57209 --- linux-2.6.37/net/unix/af_unix.c 2011-01-04 19:50:19.000000000 -0500
57210 +++ linux-2.6.37/net/unix/af_unix.c 2011-01-17 02:41:02.000000000 -0500
57211 @@ -764,6 +764,12 @@ static struct sock *unix_find_other(stru
57212 err = -ECONNREFUSED;
57213 if (!S_ISSOCK(inode->i_mode))
57214 goto put_fail;
57215 +
57216 + if (!gr_acl_handle_unix(path.dentry, path.mnt)) {
57217 + err = -EACCES;
57218 + goto put_fail;
57219 + }
57220 +
57221 u = unix_find_socket_byinode(inode);
57222 if (!u)
57223 goto put_fail;
57224 @@ -784,6 +790,13 @@ static struct sock *unix_find_other(stru
57225 if (u) {
57226 struct dentry *dentry;
57227 dentry = unix_sk(u)->dentry;
57228 +
57229 + if (!gr_handle_chroot_unix(u->sk_peer_pid)) {
57230 + err = -EPERM;
57231 + sock_put(u);
57232 + goto fail;
57233 + }
57234 +
57235 if (dentry)
57236 touch_atime(unix_sk(u)->mnt, dentry);
57237 } else
57238 @@ -869,11 +882,18 @@ static int unix_bind(struct socket *sock
57239 err = security_path_mknod(&nd.path, dentry, mode, 0);
57240 if (err)
57241 goto out_mknod_drop_write;
57242 + if (!gr_acl_handle_mknod(dentry, nd.path.dentry, nd.path.mnt, mode)) {
57243 + err = -EACCES;
57244 + goto out_mknod_drop_write;
57245 + }
57246 err = vfs_mknod(nd.path.dentry->d_inode, dentry, mode, 0);
57247 out_mknod_drop_write:
57248 mnt_drop_write(nd.path.mnt);
57249 if (err)
57250 goto out_mknod_dput;
57251 +
57252 + gr_handle_create(dentry, nd.path.mnt);
57253 +
57254 mutex_unlock(&nd.path.dentry->d_inode->i_mutex);
57255 dput(nd.path.dentry);
57256 nd.path.dentry = dentry;
57257 @@ -891,6 +911,11 @@ out_mknod_drop_write:
57258 goto out_unlock;
57259 }
57260
57261 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
57262 + put_pid(sk->sk_peer_pid);
57263 + sk->sk_peer_pid = get_pid(task_tgid(current));
57264 +#endif
57265 +
57266 list = &unix_socket_table[addr->hash];
57267 } else {
57268 list = &unix_socket_table[dentry->d_inode->i_ino & (UNIX_HASH_SIZE-1)];
57269 @@ -2226,7 +2251,11 @@ static int unix_seq_show(struct seq_file
57270 unix_state_lock(s);
57271
57272 seq_printf(seq, "%p: %08X %08X %08X %04X %02X %5lu",
57273 +#ifdef CONFIG_GRKERNSEC_HIDESYM
57274 + NULL,
57275 +#else
57276 s,
57277 +#endif
57278 atomic_read(&s->sk_refcnt),
57279 0,
57280 s->sk_state == TCP_LISTEN ? __SO_ACCEPTCON : 0,
57281 diff -urNp linux-2.6.37/net/wireless/reg.c linux-2.6.37/net/wireless/reg.c
57282 --- linux-2.6.37/net/wireless/reg.c 2011-01-04 19:50:19.000000000 -0500
57283 +++ linux-2.6.37/net/wireless/reg.c 2011-01-17 02:41:02.000000000 -0500
57284 @@ -51,7 +51,7 @@
57285 printk(KERN_DEBUG format , ## args); \
57286 } while (0)
57287 #else
57288 -#define REG_DBG_PRINT(args...)
57289 +#define REG_DBG_PRINT(args...) do {} while (0)
57290 #endif
57291
57292 /* Receipt of information from last regulatory request */
57293 diff -urNp linux-2.6.37/net/wireless/wext-core.c linux-2.6.37/net/wireless/wext-core.c
57294 --- linux-2.6.37/net/wireless/wext-core.c 2011-01-04 19:50:19.000000000 -0500
57295 +++ linux-2.6.37/net/wireless/wext-core.c 2011-01-17 02:41:02.000000000 -0500
57296 @@ -744,8 +744,7 @@ static int ioctl_standard_iw_point(struc
57297 */
57298
57299 /* Support for very large requests */
57300 - if ((descr->flags & IW_DESCR_FLAG_NOMAX) &&
57301 - (user_length > descr->max_tokens)) {
57302 + if (user_length > descr->max_tokens) {
57303 /* Allow userspace to GET more than max so
57304 * we can support any size GET requests.
57305 * There is still a limit : -ENOMEM.
57306 @@ -782,22 +781,6 @@ static int ioctl_standard_iw_point(struc
57307 }
57308 }
57309
57310 - if (IW_IS_GET(cmd) && !(descr->flags & IW_DESCR_FLAG_NOMAX)) {
57311 - /*
57312 - * If this is a GET, but not NOMAX, it means that the extra
57313 - * data is not bounded by userspace, but by max_tokens. Thus
57314 - * set the length to max_tokens. This matches the extra data
57315 - * allocation.
57316 - * The driver should fill it with the number of tokens it
57317 - * provided, and it may check iwp->length rather than having
57318 - * knowledge of max_tokens. If the driver doesn't change the
57319 - * iwp->length, this ioctl just copies back max_token tokens
57320 - * filled with zeroes. Hopefully the driver isn't claiming
57321 - * them to be valid data.
57322 - */
57323 - iwp->length = descr->max_tokens;
57324 - }
57325 -
57326 err = handler(dev, info, (union iwreq_data *) iwp, extra);
57327
57328 iwp->length += essid_compat;
57329 diff -urNp linux-2.6.37/net/x25/x25_facilities.c linux-2.6.37/net/x25/x25_facilities.c
57330 --- linux-2.6.37/net/x25/x25_facilities.c 2011-01-04 19:50:19.000000000 -0500
57331 +++ linux-2.6.37/net/x25/x25_facilities.c 2011-01-17 02:41:02.000000000 -0500
57332 @@ -157,7 +157,8 @@ int x25_parse_facilities(struct sk_buff
57333 break;
57334 default:
57335 printk(KERN_DEBUG "X.25: unknown facility %02X,"
57336 - "length %d\n", p[0], p[1]);
57337 + "length %d, values %02X, %02X\n",
57338 + p[0], p[1], p[2], p[3]);
57339 break;
57340 }
57341 len -= p[1] + 2;
57342 diff -urNp linux-2.6.37/net/xfrm/xfrm_policy.c linux-2.6.37/net/xfrm/xfrm_policy.c
57343 --- linux-2.6.37/net/xfrm/xfrm_policy.c 2011-01-04 19:50:19.000000000 -0500
57344 +++ linux-2.6.37/net/xfrm/xfrm_policy.c 2011-01-17 02:41:02.000000000 -0500
57345 @@ -1504,7 +1504,7 @@ free_dst:
57346 goto out;
57347 }
57348
57349 -static int inline
57350 +static inline int
57351 xfrm_dst_alloc_copy(void **target, void *src, int size)
57352 {
57353 if (!*target) {
57354 @@ -1516,7 +1516,7 @@ xfrm_dst_alloc_copy(void **target, void
57355 return 0;
57356 }
57357
57358 -static int inline
57359 +static inline int
57360 xfrm_dst_update_parent(struct dst_entry *dst, struct xfrm_selector *sel)
57361 {
57362 #ifdef CONFIG_XFRM_SUB_POLICY
57363 @@ -1528,7 +1528,7 @@ xfrm_dst_update_parent(struct dst_entry
57364 #endif
57365 }
57366
57367 -static int inline
57368 +static inline int
57369 xfrm_dst_update_origin(struct dst_entry *dst, struct flowi *fl)
57370 {
57371 #ifdef CONFIG_XFRM_SUB_POLICY
57372 diff -urNp linux-2.6.37/scripts/basic/fixdep.c linux-2.6.37/scripts/basic/fixdep.c
57373 --- linux-2.6.37/scripts/basic/fixdep.c 2011-01-04 19:50:19.000000000 -0500
57374 +++ linux-2.6.37/scripts/basic/fixdep.c 2011-01-17 02:41:02.000000000 -0500
57375 @@ -222,9 +222,9 @@ static void use_config(char *m, int slen
57376
57377 static void parse_config_file(char *map, size_t len)
57378 {
57379 - int *end = (int *) (map + len);
57380 + unsigned int *end = (unsigned int *) (map + len);
57381 /* start at +1, so that p can never be < map */
57382 - int *m = (int *) map + 1;
57383 + unsigned int *m = (unsigned int *) map + 1;
57384 char *p, *q;
57385
57386 for (; m < end; m++) {
57387 @@ -371,7 +371,7 @@ static void print_deps(void)
57388 static void traps(void)
57389 {
57390 static char test[] __attribute__((aligned(sizeof(int)))) = "CONF";
57391 - int *p = (int *)test;
57392 + unsigned int *p = (unsigned int *)test;
57393
57394 if (*p != INT_CONF) {
57395 fprintf(stderr, "fixdep: sizeof(int) != 4 or wrong endianess? %#x\n",
57396 diff -urNp linux-2.6.37/scripts/kallsyms.c linux-2.6.37/scripts/kallsyms.c
57397 --- linux-2.6.37/scripts/kallsyms.c 2011-01-04 19:50:19.000000000 -0500
57398 +++ linux-2.6.37/scripts/kallsyms.c 2011-01-17 02:41:02.000000000 -0500
57399 @@ -43,10 +43,10 @@ struct text_range {
57400
57401 static unsigned long long _text;
57402 static struct text_range text_ranges[] = {
57403 - { "_stext", "_etext" },
57404 - { "_sinittext", "_einittext" },
57405 - { "_stext_l1", "_etext_l1" }, /* Blackfin on-chip L1 inst SRAM */
57406 - { "_stext_l2", "_etext_l2" }, /* Blackfin on-chip L2 SRAM */
57407 + { "_stext", "_etext", 0, 0 },
57408 + { "_sinittext", "_einittext", 0, 0 },
57409 + { "_stext_l1", "_etext_l1", 0, 0 }, /* Blackfin on-chip L1 inst SRAM */
57410 + { "_stext_l2", "_etext_l2", 0, 0 }, /* Blackfin on-chip L2 SRAM */
57411 };
57412 #define text_range_text (&text_ranges[0])
57413 #define text_range_inittext (&text_ranges[1])
57414 diff -urNp linux-2.6.37/scripts/mod/file2alias.c linux-2.6.37/scripts/mod/file2alias.c
57415 --- linux-2.6.37/scripts/mod/file2alias.c 2011-01-04 19:50:19.000000000 -0500
57416 +++ linux-2.6.37/scripts/mod/file2alias.c 2011-01-17 02:41:02.000000000 -0500
57417 @@ -72,7 +72,7 @@ static void device_id_check(const char *
57418 unsigned long size, unsigned long id_size,
57419 void *symval)
57420 {
57421 - int i;
57422 + unsigned int i;
57423
57424 if (size % id_size || size < id_size) {
57425 if (cross_build != 0)
57426 @@ -102,7 +102,7 @@ static void device_id_check(const char *
57427 /* USB is special because the bcdDevice can be matched against a numeric range */
57428 /* Looks like "usb:vNpNdNdcNdscNdpNicNiscNipN" */
57429 static void do_usb_entry(struct usb_device_id *id,
57430 - unsigned int bcdDevice_initial, int bcdDevice_initial_digits,
57431 + unsigned int bcdDevice_initial, unsigned int bcdDevice_initial_digits,
57432 unsigned char range_lo, unsigned char range_hi,
57433 unsigned char max, struct module *mod)
57434 {
57435 @@ -437,7 +437,7 @@ static void do_pnp_device_entry(void *sy
57436 for (i = 0; i < count; i++) {
57437 const char *id = (char *)devs[i].id;
57438 char acpi_id[sizeof(devs[0].id)];
57439 - int j;
57440 + unsigned int j;
57441
57442 buf_printf(&mod->dev_table_buf,
57443 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
57444 @@ -467,7 +467,7 @@ static void do_pnp_card_entries(void *sy
57445
57446 for (j = 0; j < PNP_MAX_DEVICES; j++) {
57447 const char *id = (char *)card->devs[j].id;
57448 - int i2, j2;
57449 + unsigned int i2, j2;
57450 int dup = 0;
57451
57452 if (!id[0])
57453 @@ -493,7 +493,7 @@ static void do_pnp_card_entries(void *sy
57454 /* add an individual alias for every device entry */
57455 if (!dup) {
57456 char acpi_id[sizeof(card->devs[0].id)];
57457 - int k;
57458 + unsigned int k;
57459
57460 buf_printf(&mod->dev_table_buf,
57461 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
57462 @@ -768,7 +768,7 @@ static void dmi_ascii_filter(char *d, co
57463 static int do_dmi_entry(const char *filename, struct dmi_system_id *id,
57464 char *alias)
57465 {
57466 - int i, j;
57467 + unsigned int i, j;
57468
57469 sprintf(alias, "dmi*");
57470
57471 diff -urNp linux-2.6.37/scripts/mod/modpost.c linux-2.6.37/scripts/mod/modpost.c
57472 --- linux-2.6.37/scripts/mod/modpost.c 2011-01-04 19:50:19.000000000 -0500
57473 +++ linux-2.6.37/scripts/mod/modpost.c 2011-01-17 02:41:02.000000000 -0500
57474 @@ -895,6 +895,7 @@ enum mismatch {
57475 ANY_INIT_TO_ANY_EXIT,
57476 ANY_EXIT_TO_ANY_INIT,
57477 EXPORT_TO_INIT_EXIT,
57478 + DATA_TO_TEXT
57479 };
57480
57481 struct sectioncheck {
57482 @@ -1003,6 +1004,12 @@ const struct sectioncheck sectioncheck[]
57483 .tosec = { INIT_SECTIONS, EXIT_SECTIONS, NULL },
57484 .mismatch = EXPORT_TO_INIT_EXIT,
57485 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
57486 +},
57487 +/* Do not reference code from writable data */
57488 +{
57489 + .fromsec = { DATA_SECTIONS, NULL },
57490 + .tosec = { TEXT_SECTIONS, NULL },
57491 + .mismatch = DATA_TO_TEXT
57492 }
57493 };
57494
57495 @@ -1125,10 +1132,10 @@ static Elf_Sym *find_elf_symbol(struct e
57496 continue;
57497 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
57498 continue;
57499 - if (sym->st_value == addr)
57500 - return sym;
57501 /* Find a symbol nearby - addr are maybe negative */
57502 d = sym->st_value - addr;
57503 + if (d == 0)
57504 + return sym;
57505 if (d < 0)
57506 d = addr - sym->st_value;
57507 if (d < distance) {
57508 @@ -1400,6 +1407,14 @@ static void report_sec_mismatch(const ch
57509 tosym, prl_to, prl_to, tosym);
57510 free(prl_to);
57511 break;
57512 + case DATA_TO_TEXT:
57513 +/*
57514 + fprintf(stderr,
57515 + "The variable %s references\n"
57516 + "the %s %s%s%s\n",
57517 + fromsym, to, sec2annotation(tosec), tosym, to_p);
57518 +*/
57519 + break;
57520 }
57521 fprintf(stderr, "\n");
57522 }
57523 @@ -1723,7 +1738,7 @@ void __attribute__((format(printf, 2, 3)
57524 va_end(ap);
57525 }
57526
57527 -void buf_write(struct buffer *buf, const char *s, int len)
57528 +void buf_write(struct buffer *buf, const char *s, unsigned int len)
57529 {
57530 if (buf->size - buf->pos < len) {
57531 buf->size += len + SZ;
57532 @@ -1935,7 +1950,7 @@ static void write_if_changed(struct buff
57533 if (fstat(fileno(file), &st) < 0)
57534 goto close_write;
57535
57536 - if (st.st_size != b->pos)
57537 + if (st.st_size != (off_t)b->pos)
57538 goto close_write;
57539
57540 tmp = NOFAIL(malloc(b->pos));
57541 diff -urNp linux-2.6.37/scripts/mod/modpost.h linux-2.6.37/scripts/mod/modpost.h
57542 --- linux-2.6.37/scripts/mod/modpost.h 2011-01-04 19:50:19.000000000 -0500
57543 +++ linux-2.6.37/scripts/mod/modpost.h 2011-01-17 02:41:02.000000000 -0500
57544 @@ -92,15 +92,15 @@ void *do_nofail(void *ptr, const char *e
57545
57546 struct buffer {
57547 char *p;
57548 - int pos;
57549 - int size;
57550 + unsigned int pos;
57551 + unsigned int size;
57552 };
57553
57554 void __attribute__((format(printf, 2, 3)))
57555 buf_printf(struct buffer *buf, const char *fmt, ...);
57556
57557 void
57558 -buf_write(struct buffer *buf, const char *s, int len);
57559 +buf_write(struct buffer *buf, const char *s, unsigned int len);
57560
57561 struct module {
57562 struct module *next;
57563 diff -urNp linux-2.6.37/scripts/mod/sumversion.c linux-2.6.37/scripts/mod/sumversion.c
57564 --- linux-2.6.37/scripts/mod/sumversion.c 2011-01-04 19:50:19.000000000 -0500
57565 +++ linux-2.6.37/scripts/mod/sumversion.c 2011-01-17 02:41:02.000000000 -0500
57566 @@ -455,7 +455,7 @@ static void write_version(const char *fi
57567 goto out;
57568 }
57569
57570 - if (write(fd, sum, strlen(sum)+1) != strlen(sum)+1) {
57571 + if (write(fd, sum, strlen(sum)+1) != (ssize_t)strlen(sum)+1) {
57572 warn("writing sum in %s failed: %s\n",
57573 filename, strerror(errno));
57574 goto out;
57575 diff -urNp linux-2.6.37/scripts/pnmtologo.c linux-2.6.37/scripts/pnmtologo.c
57576 --- linux-2.6.37/scripts/pnmtologo.c 2011-01-04 19:50:19.000000000 -0500
57577 +++ linux-2.6.37/scripts/pnmtologo.c 2011-01-17 02:41:02.000000000 -0500
57578 @@ -237,14 +237,14 @@ static void write_header(void)
57579 fprintf(out, " * Linux logo %s\n", logoname);
57580 fputs(" */\n\n", out);
57581 fputs("#include <linux/linux_logo.h>\n\n", out);
57582 - fprintf(out, "static unsigned char %s_data[] __initdata = {\n",
57583 + fprintf(out, "static unsigned char %s_data[] = {\n",
57584 logoname);
57585 }
57586
57587 static void write_footer(void)
57588 {
57589 fputs("\n};\n\n", out);
57590 - fprintf(out, "const struct linux_logo %s __initconst = {\n", logoname);
57591 + fprintf(out, "const struct linux_logo %s = {\n", logoname);
57592 fprintf(out, "\t.type\t\t= %s,\n", logo_types[logo_type]);
57593 fprintf(out, "\t.width\t\t= %d,\n", logo_width);
57594 fprintf(out, "\t.height\t\t= %d,\n", logo_height);
57595 @@ -374,7 +374,7 @@ static void write_logo_clut224(void)
57596 fputs("\n};\n\n", out);
57597
57598 /* write logo clut */
57599 - fprintf(out, "static unsigned char %s_clut[] __initdata = {\n",
57600 + fprintf(out, "static unsigned char %s_clut[] = {\n",
57601 logoname);
57602 write_hex_cnt = 0;
57603 for (i = 0; i < logo_clutsize; i++) {
57604 diff -urNp linux-2.6.37/security/apparmor/lsm.c linux-2.6.37/security/apparmor/lsm.c
57605 --- linux-2.6.37/security/apparmor/lsm.c 2011-01-04 19:50:19.000000000 -0500
57606 +++ linux-2.6.37/security/apparmor/lsm.c 2011-01-17 02:41:02.000000000 -0500
57607 @@ -619,7 +619,7 @@ static int apparmor_task_setrlimit(struc
57608 return error;
57609 }
57610
57611 -static struct security_operations apparmor_ops = {
57612 +static struct security_operations apparmor_ops __read_only = {
57613 .name = "apparmor",
57614
57615 .ptrace_access_check = apparmor_ptrace_access_check,
57616 diff -urNp linux-2.6.37/security/commoncap.c linux-2.6.37/security/commoncap.c
57617 --- linux-2.6.37/security/commoncap.c 2011-01-04 19:50:19.000000000 -0500
57618 +++ linux-2.6.37/security/commoncap.c 2011-01-17 02:41:02.000000000 -0500
57619 @@ -27,6 +27,7 @@
57620 #include <linux/sched.h>
57621 #include <linux/prctl.h>
57622 #include <linux/securebits.h>
57623 +#include <net/sock.h>
57624
57625 /*
57626 * If a non-root user executes a setuid-root binary in
57627 @@ -50,9 +51,11 @@ static void warn_setuid_and_fcaps_mixed(
57628 }
57629 }
57630
57631 +extern kernel_cap_t gr_cap_rtnetlink(struct sock *sk);
57632 +
57633 int cap_netlink_send(struct sock *sk, struct sk_buff *skb)
57634 {
57635 - NETLINK_CB(skb).eff_cap = current_cap();
57636 + NETLINK_CB(skb).eff_cap = gr_cap_rtnetlink(sk);
57637 return 0;
57638 }
57639
57640 @@ -534,6 +537,9 @@ int cap_bprm_secureexec(struct linux_bin
57641 {
57642 const struct cred *cred = current_cred();
57643
57644 + if (gr_acl_enable_at_secure())
57645 + return 1;
57646 +
57647 if (cred->uid != 0) {
57648 if (bprm->cap_effective)
57649 return 1;
57650 diff -urNp linux-2.6.37/security/integrity/ima/ima_api.c linux-2.6.37/security/integrity/ima/ima_api.c
57651 --- linux-2.6.37/security/integrity/ima/ima_api.c 2011-01-04 19:50:19.000000000 -0500
57652 +++ linux-2.6.37/security/integrity/ima/ima_api.c 2011-01-17 02:41:02.000000000 -0500
57653 @@ -75,7 +75,7 @@ void ima_add_violation(struct inode *ino
57654 int result;
57655
57656 /* can overflow, only indicator */
57657 - atomic_long_inc(&ima_htable.violations);
57658 + atomic_long_inc_unchecked(&ima_htable.violations);
57659
57660 entry = kmalloc(sizeof(*entry), GFP_KERNEL);
57661 if (!entry) {
57662 diff -urNp linux-2.6.37/security/integrity/ima/ima_fs.c linux-2.6.37/security/integrity/ima/ima_fs.c
57663 --- linux-2.6.37/security/integrity/ima/ima_fs.c 2011-01-04 19:50:19.000000000 -0500
57664 +++ linux-2.6.37/security/integrity/ima/ima_fs.c 2011-01-17 02:41:02.000000000 -0500
57665 @@ -28,12 +28,12 @@
57666 static int valid_policy = 1;
57667 #define TMPBUFLEN 12
57668 static ssize_t ima_show_htable_value(char __user *buf, size_t count,
57669 - loff_t *ppos, atomic_long_t *val)
57670 + loff_t *ppos, atomic_long_unchecked_t *val)
57671 {
57672 char tmpbuf[TMPBUFLEN];
57673 ssize_t len;
57674
57675 - len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read(val));
57676 + len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read_unchecked(val));
57677 return simple_read_from_buffer(buf, count, ppos, tmpbuf, len);
57678 }
57679
57680 diff -urNp linux-2.6.37/security/integrity/ima/ima.h linux-2.6.37/security/integrity/ima/ima.h
57681 --- linux-2.6.37/security/integrity/ima/ima.h 2011-01-04 19:50:19.000000000 -0500
57682 +++ linux-2.6.37/security/integrity/ima/ima.h 2011-01-17 02:41:02.000000000 -0500
57683 @@ -85,8 +85,8 @@ void ima_add_violation(struct inode *ino
57684 extern spinlock_t ima_queue_lock;
57685
57686 struct ima_h_table {
57687 - atomic_long_t len; /* number of stored measurements in the list */
57688 - atomic_long_t violations;
57689 + atomic_long_unchecked_t len; /* number of stored measurements in the list */
57690 + atomic_long_unchecked_t violations;
57691 struct hlist_head queue[IMA_MEASURE_HTABLE_SIZE];
57692 };
57693 extern struct ima_h_table ima_htable;
57694 diff -urNp linux-2.6.37/security/integrity/ima/ima_queue.c linux-2.6.37/security/integrity/ima/ima_queue.c
57695 --- linux-2.6.37/security/integrity/ima/ima_queue.c 2011-01-04 19:50:19.000000000 -0500
57696 +++ linux-2.6.37/security/integrity/ima/ima_queue.c 2011-01-17 02:41:02.000000000 -0500
57697 @@ -79,7 +79,7 @@ static int ima_add_digest_entry(struct i
57698 INIT_LIST_HEAD(&qe->later);
57699 list_add_tail_rcu(&qe->later, &ima_measurements);
57700
57701 - atomic_long_inc(&ima_htable.len);
57702 + atomic_long_inc_unchecked(&ima_htable.len);
57703 key = ima_hash_key(entry->digest);
57704 hlist_add_head_rcu(&qe->hnext, &ima_htable.queue[key]);
57705 return 0;
57706 diff -urNp linux-2.6.37/security/Kconfig linux-2.6.37/security/Kconfig
57707 --- linux-2.6.37/security/Kconfig 2011-01-04 19:50:19.000000000 -0500
57708 +++ linux-2.6.37/security/Kconfig 2011-01-17 02:41:02.000000000 -0500
57709 @@ -4,6 +4,509 @@
57710
57711 menu "Security options"
57712
57713 +source grsecurity/Kconfig
57714 +
57715 +menu "PaX"
57716 +
57717 + config ARCH_TRACK_EXEC_LIMIT
57718 + bool
57719 +
57720 + config PAX_PER_CPU_PGD
57721 + bool
57722 +
57723 + config TASK_SIZE_MAX_SHIFT
57724 + int
57725 + depends on X86_64
57726 + default 47 if !PAX_PER_CPU_PGD
57727 + default 42 if PAX_PER_CPU_PGD
57728 +
57729 + config PAX_ENABLE_PAE
57730 + bool
57731 + default y if (X86_32 && (MPENTIUM4 || MK8 || MPSC || MCORE2 || MATOM))
57732 +
57733 +config PAX
57734 + bool "Enable various PaX features"
57735 + depends on GRKERNSEC && (ALPHA || ARM || AVR32 || IA64 || MIPS || PARISC || PPC || SPARC || X86)
57736 + help
57737 + This allows you to enable various PaX features. PaX adds
57738 + intrusion prevention mechanisms to the kernel that reduce
57739 + the risks posed by exploitable memory corruption bugs.
57740 +
57741 +menu "PaX Control"
57742 + depends on PAX
57743 +
57744 +config PAX_SOFTMODE
57745 + bool 'Support soft mode'
57746 + select PAX_PT_PAX_FLAGS
57747 + help
57748 + Enabling this option will allow you to run PaX in soft mode, that
57749 + is, PaX features will not be enforced by default, only on executables
57750 + marked explicitly. You must also enable PT_PAX_FLAGS support as it
57751 + is the only way to mark executables for soft mode use.
57752 +
57753 + Soft mode can be activated by using the "pax_softmode=1" kernel command
57754 + line option on boot. Furthermore you can control various PaX features
57755 + at runtime via the entries in /proc/sys/kernel/pax.
57756 +
57757 +config PAX_EI_PAX
57758 + bool 'Use legacy ELF header marking'
57759 + help
57760 + Enabling this option will allow you to control PaX features on
57761 + a per executable basis via the 'chpax' utility available at
57762 + http://pax.grsecurity.net/. The control flags will be read from
57763 + an otherwise reserved part of the ELF header. This marking has
57764 + numerous drawbacks (no support for soft-mode, toolchain does not
57765 + know about the non-standard use of the ELF header) therefore it
57766 + has been deprecated in favour of PT_PAX_FLAGS support.
57767 +
57768 + If you have applications not marked by the PT_PAX_FLAGS ELF
57769 + program header then you MUST enable this option otherwise they
57770 + will not get any protection.
57771 +
57772 + Note that if you enable PT_PAX_FLAGS marking support as well,
57773 + the PT_PAX_FLAG marks will override the legacy EI_PAX marks.
57774 +
57775 +config PAX_PT_PAX_FLAGS
57776 + bool 'Use ELF program header marking'
57777 + help
57778 + Enabling this option will allow you to control PaX features on
57779 + a per executable basis via the 'paxctl' utility available at
57780 + http://pax.grsecurity.net/. The control flags will be read from
57781 + a PaX specific ELF program header (PT_PAX_FLAGS). This marking
57782 + has the benefits of supporting both soft mode and being fully
57783 + integrated into the toolchain (the binutils patch is available
57784 + from http://pax.grsecurity.net).
57785 +
57786 + If you have applications not marked by the PT_PAX_FLAGS ELF
57787 + program header then you MUST enable the EI_PAX marking support
57788 + otherwise they will not get any protection.
57789 +
57790 + Note that if you enable the legacy EI_PAX marking support as well,
57791 + the EI_PAX marks will be overridden by the PT_PAX_FLAGS marks.
57792 +
57793 +choice
57794 + prompt 'MAC system integration'
57795 + default PAX_HAVE_ACL_FLAGS
57796 + help
57797 + Mandatory Access Control systems have the option of controlling
57798 + PaX flags on a per executable basis, choose the method supported
57799 + by your particular system.
57800 +
57801 + - "none": if your MAC system does not interact with PaX,
57802 + - "direct": if your MAC system defines pax_set_initial_flags() itself,
57803 + - "hook": if your MAC system uses the pax_set_initial_flags_func callback.
57804 +
57805 + NOTE: this option is for developers/integrators only.
57806 +
57807 + config PAX_NO_ACL_FLAGS
57808 + bool 'none'
57809 +
57810 + config PAX_HAVE_ACL_FLAGS
57811 + bool 'direct'
57812 +
57813 + config PAX_HOOK_ACL_FLAGS
57814 + bool 'hook'
57815 +endchoice
57816 +
57817 +endmenu
57818 +
57819 +menu "Non-executable pages"
57820 + depends on PAX
57821 +
57822 +config PAX_NOEXEC
57823 + bool "Enforce non-executable pages"
57824 + 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)
57825 + help
57826 + By design some architectures do not allow for protecting memory
57827 + pages against execution or even if they do, Linux does not make
57828 + use of this feature. In practice this means that if a page is
57829 + readable (such as the stack or heap) it is also executable.
57830 +
57831 + There is a well known exploit technique that makes use of this
57832 + fact and a common programming mistake where an attacker can
57833 + introduce code of his choice somewhere in the attacked program's
57834 + memory (typically the stack or the heap) and then execute it.
57835 +
57836 + If the attacked program was running with different (typically
57837 + higher) privileges than that of the attacker, then he can elevate
57838 + his own privilege level (e.g. get a root shell, write to files for
57839 + which he does not have write access to, etc).
57840 +
57841 + Enabling this option will let you choose from various features
57842 + that prevent the injection and execution of 'foreign' code in
57843 + a program.
57844 +
57845 + This will also break programs that rely on the old behaviour and
57846 + expect that dynamically allocated memory via the malloc() family
57847 + of functions is executable (which it is not). Notable examples
57848 + are the XFree86 4.x server, the java runtime and wine.
57849 +
57850 +config PAX_PAGEEXEC
57851 + bool "Paging based non-executable pages"
57852 + 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)
57853 + select S390_SWITCH_AMODE if S390
57854 + select S390_EXEC_PROTECT if S390
57855 + select ARCH_TRACK_EXEC_LIMIT if X86_32
57856 + help
57857 + This implementation is based on the paging feature of the CPU.
57858 + On i386 without hardware non-executable bit support there is a
57859 + variable but usually low performance impact, however on Intel's
57860 + P4 core based CPUs it is very high so you should not enable this
57861 + for kernels meant to be used on such CPUs.
57862 +
57863 + On alpha, avr32, ia64, parisc, sparc, sparc64, x86_64 and i386
57864 + with hardware non-executable bit support there is no performance
57865 + impact, on ppc the impact is negligible.
57866 +
57867 + Note that several architectures require various emulations due to
57868 + badly designed userland ABIs, this will cause a performance impact
57869 + but will disappear as soon as userland is fixed. For example, ppc
57870 + userland MUST have been built with secure-plt by a recent toolchain.
57871 +
57872 +config PAX_SEGMEXEC
57873 + bool "Segmentation based non-executable pages"
57874 + depends on PAX_NOEXEC && X86_32
57875 + help
57876 + This implementation is based on the segmentation feature of the
57877 + CPU and has a very small performance impact, however applications
57878 + will be limited to a 1.5 GB address space instead of the normal
57879 + 3 GB.
57880 +
57881 +config PAX_EMUTRAMP
57882 + bool "Emulate trampolines" if (PAX_PAGEEXEC || PAX_SEGMEXEC) && (PARISC || X86)
57883 + default y if PARISC
57884 + help
57885 + There are some programs and libraries that for one reason or
57886 + another attempt to execute special small code snippets from
57887 + non-executable memory pages. Most notable examples are the
57888 + signal handler return code generated by the kernel itself and
57889 + the GCC trampolines.
57890 +
57891 + If you enabled CONFIG_PAX_PAGEEXEC or CONFIG_PAX_SEGMEXEC then
57892 + such programs will no longer work under your kernel.
57893 +
57894 + As a remedy you can say Y here and use the 'chpax' or 'paxctl'
57895 + utilities to enable trampoline emulation for the affected programs
57896 + yet still have the protection provided by the non-executable pages.
57897 +
57898 + On parisc you MUST enable this option and EMUSIGRT as well, otherwise
57899 + your system will not even boot.
57900 +
57901 + Alternatively you can say N here and use the 'chpax' or 'paxctl'
57902 + utilities to disable CONFIG_PAX_PAGEEXEC and CONFIG_PAX_SEGMEXEC
57903 + for the affected files.
57904 +
57905 + NOTE: enabling this feature *may* open up a loophole in the
57906 + protection provided by non-executable pages that an attacker
57907 + could abuse. Therefore the best solution is to not have any
57908 + files on your system that would require this option. This can
57909 + be achieved by not using libc5 (which relies on the kernel
57910 + signal handler return code) and not using or rewriting programs
57911 + that make use of the nested function implementation of GCC.
57912 + Skilled users can just fix GCC itself so that it implements
57913 + nested function calls in a way that does not interfere with PaX.
57914 +
57915 +config PAX_EMUSIGRT
57916 + bool "Automatically emulate sigreturn trampolines"
57917 + depends on PAX_EMUTRAMP && PARISC
57918 + default y
57919 + help
57920 + Enabling this option will have the kernel automatically detect
57921 + and emulate signal return trampolines executing on the stack
57922 + that would otherwise lead to task termination.
57923 +
57924 + This solution is intended as a temporary one for users with
57925 + legacy versions of libc (libc5, glibc 2.0, uClibc before 0.9.17,
57926 + Modula-3 runtime, etc) or executables linked to such, basically
57927 + everything that does not specify its own SA_RESTORER function in
57928 + normal executable memory like glibc 2.1+ does.
57929 +
57930 + On parisc you MUST enable this option, otherwise your system will
57931 + not even boot.
57932 +
57933 + NOTE: this feature cannot be disabled on a per executable basis
57934 + and since it *does* open up a loophole in the protection provided
57935 + by non-executable pages, the best solution is to not have any
57936 + files on your system that would require this option.
57937 +
57938 +config PAX_MPROTECT
57939 + bool "Restrict mprotect()"
57940 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC)
57941 + help
57942 + Enabling this option will prevent programs from
57943 + - changing the executable status of memory pages that were
57944 + not originally created as executable,
57945 + - making read-only executable pages writable again,
57946 + - creating executable pages from anonymous memory,
57947 + - making read-only-after-relocations (RELRO) data pages writable again.
57948 +
57949 + You should say Y here to complete the protection provided by
57950 + the enforcement of non-executable pages.
57951 +
57952 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
57953 + this feature on a per file basis.
57954 +
57955 +config PAX_ELFRELOCS
57956 + bool "Allow ELF text relocations (read help)"
57957 + depends on PAX_MPROTECT
57958 + default n
57959 + help
57960 + Non-executable pages and mprotect() restrictions are effective
57961 + in preventing the introduction of new executable code into an
57962 + attacked task's address space. There remain only two venues
57963 + for this kind of attack: if the attacker can execute already
57964 + existing code in the attacked task then he can either have it
57965 + create and mmap() a file containing his code or have it mmap()
57966 + an already existing ELF library that does not have position
57967 + independent code in it and use mprotect() on it to make it
57968 + writable and copy his code there. While protecting against
57969 + the former approach is beyond PaX, the latter can be prevented
57970 + by having only PIC ELF libraries on one's system (which do not
57971 + need to relocate their code). If you are sure this is your case,
57972 + as is the case with all modern Linux distributions, then leave
57973 + this option disabled. You should say 'n' here.
57974 +
57975 +config PAX_ETEXECRELOCS
57976 + bool "Allow ELF ET_EXEC text relocations"
57977 + depends on PAX_MPROTECT && (ALPHA || IA64 || PARISC)
57978 + select PAX_ELFRELOCS
57979 + default y
57980 + help
57981 + On some architectures there are incorrectly created applications
57982 + that require text relocations and would not work without enabling
57983 + this option. If you are an alpha, ia64 or parisc user, you should
57984 + enable this option and disable it once you have made sure that
57985 + none of your applications need it.
57986 +
57987 +config PAX_EMUPLT
57988 + bool "Automatically emulate ELF PLT"
57989 + depends on PAX_MPROTECT && (ALPHA || PARISC || SPARC)
57990 + default y
57991 + help
57992 + Enabling this option will have the kernel automatically detect
57993 + and emulate the Procedure Linkage Table entries in ELF files.
57994 + On some architectures such entries are in writable memory, and
57995 + become non-executable leading to task termination. Therefore
57996 + it is mandatory that you enable this option on alpha, parisc,
57997 + sparc and sparc64, otherwise your system would not even boot.
57998 +
57999 + NOTE: this feature *does* open up a loophole in the protection
58000 + provided by the non-executable pages, therefore the proper
58001 + solution is to modify the toolchain to produce a PLT that does
58002 + not need to be writable.
58003 +
58004 +config PAX_DLRESOLVE
58005 + bool 'Emulate old glibc resolver stub'
58006 + depends on PAX_EMUPLT && SPARC
58007 + default n
58008 + help
58009 + This option is needed if userland has an old glibc (before 2.4)
58010 + that puts a 'save' instruction into the runtime generated resolver
58011 + stub that needs special emulation.
58012 +
58013 +config PAX_KERNEXEC
58014 + bool "Enforce non-executable kernel pages"
58015 + depends on PAX_NOEXEC && (PPC || X86) && (!X86_32 || X86_WP_WORKS_OK) && !XEN
58016 + select PAX_PER_CPU_PGD if X86_64 || (X86_32 && X86_PAE)
58017 + help
58018 + This is the kernel land equivalent of PAGEEXEC and MPROTECT,
58019 + that is, enabling this option will make it harder to inject
58020 + and execute 'foreign' code in kernel memory itself.
58021 +
58022 +config PAX_KERNEXEC_MODULE_TEXT
58023 + int "Minimum amount of memory reserved for module code"
58024 + default "4"
58025 + depends on PAX_KERNEXEC && X86_32 && MODULES
58026 + help
58027 + Due to implementation details the kernel must reserve a fixed
58028 + amount of memory for module code at compile time that cannot be
58029 + changed at runtime. Here you can specify the minimum amount
58030 + in MB that will be reserved. Due to the same implementation
58031 + details this size will always be rounded up to the next 2/4 MB
58032 + boundary (depends on PAE) so the actually available memory for
58033 + module code will usually be more than this minimum.
58034 +
58035 + The default 4 MB should be enough for most users but if you have
58036 + an excessive number of modules (e.g., most distribution configs
58037 + compile many drivers as modules) or use huge modules such as
58038 + nvidia's kernel driver, you will need to adjust this amount.
58039 + A good rule of thumb is to look at your currently loaded kernel
58040 + modules and add up their sizes.
58041 +
58042 +endmenu
58043 +
58044 +menu "Address Space Layout Randomization"
58045 + depends on PAX
58046 +
58047 +config PAX_ASLR
58048 + bool "Address Space Layout Randomization"
58049 + depends on PAX_EI_PAX || PAX_PT_PAX_FLAGS || PAX_HAVE_ACL_FLAGS || PAX_HOOK_ACL_FLAGS
58050 + help
58051 + Many if not most exploit techniques rely on the knowledge of
58052 + certain addresses in the attacked program. The following options
58053 + will allow the kernel to apply a certain amount of randomization
58054 + to specific parts of the program thereby forcing an attacker to
58055 + guess them in most cases. Any failed guess will most likely crash
58056 + the attacked program which allows the kernel to detect such attempts
58057 + and react on them. PaX itself provides no reaction mechanisms,
58058 + instead it is strongly encouraged that you make use of Nergal's
58059 + segvguard (ftp://ftp.pl.openwall.com/misc/segvguard/) or grsecurity's
58060 + (http://www.grsecurity.net/) built-in crash detection features or
58061 + develop one yourself.
58062 +
58063 + By saying Y here you can choose to randomize the following areas:
58064 + - top of the task's kernel stack
58065 + - top of the task's userland stack
58066 + - base address for mmap() requests that do not specify one
58067 + (this includes all libraries)
58068 + - base address of the main executable
58069 +
58070 + It is strongly recommended to say Y here as address space layout
58071 + randomization has negligible impact on performance yet it provides
58072 + a very effective protection.
58073 +
58074 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
58075 + this feature on a per file basis.
58076 +
58077 +config PAX_RANDKSTACK
58078 + bool "Randomize kernel stack base"
58079 + depends on PAX_ASLR && X86_TSC && X86_32
58080 + help
58081 + By saying Y here the kernel will randomize every task's kernel
58082 + stack on every system call. This will not only force an attacker
58083 + to guess it but also prevent him from making use of possible
58084 + leaked information about it.
58085 +
58086 + Since the kernel stack is a rather scarce resource, randomization
58087 + may cause unexpected stack overflows, therefore you should very
58088 + carefully test your system. Note that once enabled in the kernel
58089 + configuration, this feature cannot be disabled on a per file basis.
58090 +
58091 +config PAX_RANDUSTACK
58092 + bool "Randomize user stack base"
58093 + depends on PAX_ASLR
58094 + help
58095 + By saying Y here the kernel will randomize every task's userland
58096 + stack. The randomization is done in two steps where the second
58097 + one may apply a big amount of shift to the top of the stack and
58098 + cause problems for programs that want to use lots of memory (more
58099 + than 2.5 GB if SEGMEXEC is not active, or 1.25 GB when it is).
58100 + For this reason the second step can be controlled by 'chpax' or
58101 + 'paxctl' on a per file basis.
58102 +
58103 +config PAX_RANDMMAP
58104 + bool "Randomize mmap() base"
58105 + depends on PAX_ASLR
58106 + help
58107 + By saying Y here the kernel will use a randomized base address for
58108 + mmap() requests that do not specify one themselves. As a result
58109 + all dynamically loaded libraries will appear at random addresses
58110 + and therefore be harder to exploit by a technique where an attacker
58111 + attempts to execute library code for his purposes (e.g. spawn a
58112 + shell from an exploited program that is running at an elevated
58113 + privilege level).
58114 +
58115 + Furthermore, if a program is relinked as a dynamic ELF file, its
58116 + base address will be randomized as well, completing the full
58117 + randomization of the address space layout. Attacking such programs
58118 + becomes a guess game. You can find an example of doing this at
58119 + http://pax.grsecurity.net/et_dyn.tar.gz and practical samples at
58120 + http://www.grsecurity.net/grsec-gcc-specs.tar.gz .
58121 +
58122 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control this
58123 + feature on a per file basis.
58124 +
58125 +endmenu
58126 +
58127 +menu "Miscellaneous hardening features"
58128 +
58129 +config PAX_MEMORY_SANITIZE
58130 + bool "Sanitize all freed memory"
58131 + help
58132 + By saying Y here the kernel will erase memory pages as soon as they
58133 + are freed. This in turn reduces the lifetime of data stored in the
58134 + pages, making it less likely that sensitive information such as
58135 + passwords, cryptographic secrets, etc stay in memory for too long.
58136 +
58137 + This is especially useful for programs whose runtime is short, long
58138 + lived processes and the kernel itself benefit from this as long as
58139 + they operate on whole memory pages and ensure timely freeing of pages
58140 + that may hold sensitive information.
58141 +
58142 + The tradeoff is performance impact, on a single CPU system kernel
58143 + compilation sees a 3% slowdown, other systems and workloads may vary
58144 + and you are advised to test this feature on your expected workload
58145 + before deploying it.
58146 +
58147 + Note that this feature does not protect data stored in live pages,
58148 + e.g., process memory swapped to disk may stay there for a long time.
58149 +
58150 +config PAX_MEMORY_UDEREF
58151 + bool "Prevent invalid userland pointer dereference"
58152 + depends on X86 && !UML_X86 && !XEN
58153 + select PAX_PER_CPU_PGD if X86_64
58154 + help
58155 + By saying Y here the kernel will be prevented from dereferencing
58156 + userland pointers in contexts where the kernel expects only kernel
58157 + pointers. This is both a useful runtime debugging feature and a
58158 + security measure that prevents exploiting a class of kernel bugs.
58159 +
58160 + The tradeoff is that some virtualization solutions may experience
58161 + a huge slowdown and therefore you should not enable this feature
58162 + for kernels meant to run in such environments. Whether a given VM
58163 + solution is affected or not is best determined by simply trying it
58164 + out, the performance impact will be obvious right on boot as this
58165 + mechanism engages from very early on. A good rule of thumb is that
58166 + VMs running on CPUs without hardware virtualization support (i.e.,
58167 + the majority of IA-32 CPUs) will likely experience the slowdown.
58168 +
58169 +config PAX_REFCOUNT
58170 + bool "Prevent various kernel object reference counter overflows"
58171 + depends on GRKERNSEC && (X86 || SPARC64)
58172 + help
58173 + By saying Y here the kernel will detect and prevent overflowing
58174 + various (but not all) kinds of object reference counters. Such
58175 + overflows can normally occur due to bugs only and are often, if
58176 + not always, exploitable.
58177 +
58178 + The tradeoff is that data structures protected by an overflowed
58179 + refcount will never be freed and therefore will leak memory. Note
58180 + that this leak also happens even without this protection but in
58181 + that case the overflow can eventually trigger the freeing of the
58182 + data structure while it is still being used elsewhere, resulting
58183 + in the exploitable situation that this feature prevents.
58184 +
58185 + Since this has a negligible performance impact, you should enable
58186 + this feature.
58187 +
58188 +config PAX_USERCOPY
58189 + bool "Bounds check heap object copies between kernel and userland"
58190 + depends on X86 || PPC || SPARC
58191 + depends on GRKERNSEC && (SLAB || SLUB || SLOB)
58192 + help
58193 + By saying Y here the kernel will enforce the size of heap objects
58194 + when they are copied in either direction between the kernel and
58195 + userland, even if only a part of the heap object is copied.
58196 +
58197 + Specifically, this checking prevents information leaking from the
58198 + kernel heap during kernel to userland copies (if the kernel heap
58199 + object is otherwise fully initialized) and prevents kernel heap
58200 + overflows during userland to kernel copies.
58201 +
58202 + Note that the current implementation provides the strictest checks
58203 + for the SLUB allocator.
58204 +
58205 + If frame pointers are enabled on x86, this option will also restrict
58206 + copies into and out of the kernel stack to local variables within a
58207 + single frame.
58208 +
58209 + Since this has a negligible performance impact, you should enable
58210 + this feature.
58211 +
58212 +endmenu
58213 +
58214 +endmenu
58215 +
58216 config KEYS
58217 bool "Enable access key retention support"
58218 help
58219 @@ -136,7 +639,7 @@ config INTEL_TXT
58220 config LSM_MMAP_MIN_ADDR
58221 int "Low address space for LSM to protect from user allocation"
58222 depends on SECURITY && SECURITY_SELINUX
58223 - default 65536
58224 + default 32768
58225 help
58226 This is the portion of low virtual memory which should be protected
58227 from userspace allocation. Keeping a user from writing to low pages
58228 diff -urNp linux-2.6.37/security/min_addr.c linux-2.6.37/security/min_addr.c
58229 --- linux-2.6.37/security/min_addr.c 2011-01-04 19:50:19.000000000 -0500
58230 +++ linux-2.6.37/security/min_addr.c 2011-01-17 02:41:02.000000000 -0500
58231 @@ -14,6 +14,7 @@ unsigned long dac_mmap_min_addr = CONFIG
58232 */
58233 static void update_mmap_min_addr(void)
58234 {
58235 +#ifndef SPARC
58236 #ifdef CONFIG_LSM_MMAP_MIN_ADDR
58237 if (dac_mmap_min_addr > CONFIG_LSM_MMAP_MIN_ADDR)
58238 mmap_min_addr = dac_mmap_min_addr;
58239 @@ -22,6 +23,7 @@ static void update_mmap_min_addr(void)
58240 #else
58241 mmap_min_addr = dac_mmap_min_addr;
58242 #endif
58243 +#endif
58244 }
58245
58246 /*
58247 diff -urNp linux-2.6.37/security/security.c linux-2.6.37/security/security.c
58248 --- linux-2.6.37/security/security.c 2011-01-04 19:50:19.000000000 -0500
58249 +++ linux-2.6.37/security/security.c 2011-01-17 02:41:02.000000000 -0500
58250 @@ -25,8 +25,8 @@ static __initdata char chosen_lsm[SECURI
58251 /* things that live in capability.c */
58252 extern void __init security_fixup_ops(struct security_operations *ops);
58253
58254 -static struct security_operations *security_ops;
58255 -static struct security_operations default_security_ops = {
58256 +static struct security_operations *security_ops __read_only;
58257 +static struct security_operations default_security_ops __read_only = {
58258 .name = "default",
58259 };
58260
58261 @@ -67,7 +67,9 @@ int __init security_init(void)
58262
58263 void reset_security_ops(void)
58264 {
58265 + pax_open_kernel();
58266 security_ops = &default_security_ops;
58267 + pax_close_kernel();
58268 }
58269
58270 /* Save user chosen LSM */
58271 diff -urNp linux-2.6.37/security/selinux/hooks.c linux-2.6.37/security/selinux/hooks.c
58272 --- linux-2.6.37/security/selinux/hooks.c 2011-01-04 19:50:19.000000000 -0500
58273 +++ linux-2.6.37/security/selinux/hooks.c 2011-01-17 02:41:02.000000000 -0500
58274 @@ -90,7 +90,6 @@
58275 #define NUM_SEL_MNT_OPTS 5
58276
58277 extern int selinux_nlmsg_lookup(u16 sclass, u16 nlmsg_type, u32 *perm);
58278 -extern struct security_operations *security_ops;
58279
58280 /* SECMARK reference count */
58281 atomic_t selinux_secmark_refcount = ATOMIC_INIT(0);
58282 @@ -5388,7 +5387,7 @@ static int selinux_key_getsecurity(struc
58283
58284 #endif
58285
58286 -static struct security_operations selinux_ops = {
58287 +static struct security_operations selinux_ops __read_only = {
58288 .name = "selinux",
58289
58290 .ptrace_access_check = selinux_ptrace_access_check,
58291 diff -urNp linux-2.6.37/security/smack/smack_lsm.c linux-2.6.37/security/smack/smack_lsm.c
58292 --- linux-2.6.37/security/smack/smack_lsm.c 2011-01-04 19:50:19.000000000 -0500
58293 +++ linux-2.6.37/security/smack/smack_lsm.c 2011-01-17 02:41:02.000000000 -0500
58294 @@ -3052,7 +3052,7 @@ static int smack_inode_getsecctx(struct
58295 return 0;
58296 }
58297
58298 -struct security_operations smack_ops = {
58299 +struct security_operations smack_ops __read_only = {
58300 .name = "smack",
58301
58302 .ptrace_access_check = smack_ptrace_access_check,
58303 diff -urNp linux-2.6.37/security/tomoyo/tomoyo.c linux-2.6.37/security/tomoyo/tomoyo.c
58304 --- linux-2.6.37/security/tomoyo/tomoyo.c 2011-01-04 19:50:19.000000000 -0500
58305 +++ linux-2.6.37/security/tomoyo/tomoyo.c 2011-01-17 02:41:02.000000000 -0500
58306 @@ -240,7 +240,7 @@ static int tomoyo_sb_pivotroot(struct pa
58307 * tomoyo_security_ops is a "struct security_operations" which is used for
58308 * registering TOMOYO.
58309 */
58310 -static struct security_operations tomoyo_security_ops = {
58311 +static struct security_operations tomoyo_security_ops __read_only = {
58312 .name = "tomoyo",
58313 .cred_alloc_blank = tomoyo_cred_alloc_blank,
58314 .cred_prepare = tomoyo_cred_prepare,
58315 diff -urNp linux-2.6.37/sound/aoa/codecs/onyx.c linux-2.6.37/sound/aoa/codecs/onyx.c
58316 --- linux-2.6.37/sound/aoa/codecs/onyx.c 2011-01-04 19:50:19.000000000 -0500
58317 +++ linux-2.6.37/sound/aoa/codecs/onyx.c 2011-01-17 02:41:02.000000000 -0500
58318 @@ -54,7 +54,7 @@ struct onyx {
58319 spdif_locked:1,
58320 analog_locked:1,
58321 original_mute:2;
58322 - int open_count;
58323 + atomic_t open_count;
58324 struct codec_info *codec_info;
58325
58326 /* mutex serializes concurrent access to the device
58327 @@ -753,7 +753,7 @@ static int onyx_open(struct codec_info_i
58328 struct onyx *onyx = cii->codec_data;
58329
58330 mutex_lock(&onyx->mutex);
58331 - onyx->open_count++;
58332 + atomic_inc(&onyx->open_count);
58333 mutex_unlock(&onyx->mutex);
58334
58335 return 0;
58336 @@ -765,8 +765,7 @@ static int onyx_close(struct codec_info_
58337 struct onyx *onyx = cii->codec_data;
58338
58339 mutex_lock(&onyx->mutex);
58340 - onyx->open_count--;
58341 - if (!onyx->open_count)
58342 + if (atomic_dec_and_test(&onyx->open_count))
58343 onyx->spdif_locked = onyx->analog_locked = 0;
58344 mutex_unlock(&onyx->mutex);
58345
58346 diff -urNp linux-2.6.37/sound/core/oss/pcm_oss.c linux-2.6.37/sound/core/oss/pcm_oss.c
58347 --- linux-2.6.37/sound/core/oss/pcm_oss.c 2011-01-04 19:50:19.000000000 -0500
58348 +++ linux-2.6.37/sound/core/oss/pcm_oss.c 2011-01-17 02:41:02.000000000 -0500
58349 @@ -2969,8 +2969,8 @@ static void snd_pcm_oss_proc_done(struct
58350 }
58351 }
58352 #else /* !CONFIG_SND_VERBOSE_PROCFS */
58353 -#define snd_pcm_oss_proc_init(pcm)
58354 -#define snd_pcm_oss_proc_done(pcm)
58355 +#define snd_pcm_oss_proc_init(pcm) do {} while (0)
58356 +#define snd_pcm_oss_proc_done(pcm) do {} while (0)
58357 #endif /* CONFIG_SND_VERBOSE_PROCFS */
58358
58359 /*
58360 diff -urNp linux-2.6.37/sound/core/seq/seq_lock.h linux-2.6.37/sound/core/seq/seq_lock.h
58361 --- linux-2.6.37/sound/core/seq/seq_lock.h 2011-01-04 19:50:19.000000000 -0500
58362 +++ linux-2.6.37/sound/core/seq/seq_lock.h 2011-01-17 02:41:02.000000000 -0500
58363 @@ -23,10 +23,10 @@ void snd_use_lock_sync_helper(snd_use_lo
58364 #else /* SMP || CONFIG_SND_DEBUG */
58365
58366 typedef spinlock_t snd_use_lock_t; /* dummy */
58367 -#define snd_use_lock_init(lockp) /**/
58368 -#define snd_use_lock_use(lockp) /**/
58369 -#define snd_use_lock_free(lockp) /**/
58370 -#define snd_use_lock_sync(lockp) /**/
58371 +#define snd_use_lock_init(lockp) do {} while (0)
58372 +#define snd_use_lock_use(lockp) do {} while (0)
58373 +#define snd_use_lock_free(lockp) do {} while (0)
58374 +#define snd_use_lock_sync(lockp) do {} while (0)
58375
58376 #endif /* SMP || CONFIG_SND_DEBUG */
58377
58378 diff -urNp linux-2.6.37/sound/drivers/mts64.c linux-2.6.37/sound/drivers/mts64.c
58379 --- linux-2.6.37/sound/drivers/mts64.c 2011-01-04 19:50:19.000000000 -0500
58380 +++ linux-2.6.37/sound/drivers/mts64.c 2011-01-17 02:41:02.000000000 -0500
58381 @@ -66,7 +66,7 @@ struct mts64 {
58382 struct pardevice *pardev;
58383 int pardev_claimed;
58384
58385 - int open_count;
58386 + atomic_t open_count;
58387 int current_midi_output_port;
58388 int current_midi_input_port;
58389 u8 mode[MTS64_NUM_INPUT_PORTS];
58390 @@ -696,7 +696,7 @@ static int snd_mts64_rawmidi_open(struct
58391 {
58392 struct mts64 *mts = substream->rmidi->private_data;
58393
58394 - if (mts->open_count == 0) {
58395 + if (atomic_read(&mts->open_count) == 0) {
58396 /* We don't need a spinlock here, because this is just called
58397 if the device has not been opened before.
58398 So there aren't any IRQs from the device */
58399 @@ -704,7 +704,7 @@ static int snd_mts64_rawmidi_open(struct
58400
58401 msleep(50);
58402 }
58403 - ++(mts->open_count);
58404 + atomic_inc(&mts->open_count);
58405
58406 return 0;
58407 }
58408 @@ -714,8 +714,7 @@ static int snd_mts64_rawmidi_close(struc
58409 struct mts64 *mts = substream->rmidi->private_data;
58410 unsigned long flags;
58411
58412 - --(mts->open_count);
58413 - if (mts->open_count == 0) {
58414 + if (atomic_dec_return(&mts->open_count) == 0) {
58415 /* We need the spinlock_irqsave here because we can still
58416 have IRQs at this point */
58417 spin_lock_irqsave(&mts->lock, flags);
58418 @@ -724,8 +723,8 @@ static int snd_mts64_rawmidi_close(struc
58419
58420 msleep(500);
58421
58422 - } else if (mts->open_count < 0)
58423 - mts->open_count = 0;
58424 + } else if (atomic_read(&mts->open_count) < 0)
58425 + atomic_set(&mts->open_count, 0);
58426
58427 return 0;
58428 }
58429 diff -urNp linux-2.6.37/sound/drivers/portman2x4.c linux-2.6.37/sound/drivers/portman2x4.c
58430 --- linux-2.6.37/sound/drivers/portman2x4.c 2011-01-04 19:50:19.000000000 -0500
58431 +++ linux-2.6.37/sound/drivers/portman2x4.c 2011-01-17 02:41:02.000000000 -0500
58432 @@ -84,7 +84,7 @@ struct portman {
58433 struct pardevice *pardev;
58434 int pardev_claimed;
58435
58436 - int open_count;
58437 + atomic_t open_count;
58438 int mode[PORTMAN_NUM_INPUT_PORTS];
58439 struct snd_rawmidi_substream *midi_input[PORTMAN_NUM_INPUT_PORTS];
58440 };
58441 diff -urNp linux-2.6.37/sound/oss/sb_audio.c linux-2.6.37/sound/oss/sb_audio.c
58442 --- linux-2.6.37/sound/oss/sb_audio.c 2011-01-04 19:50:19.000000000 -0500
58443 +++ linux-2.6.37/sound/oss/sb_audio.c 2011-01-17 02:41:02.000000000 -0500
58444 @@ -901,7 +901,7 @@ sb16_copy_from_user(int dev,
58445 buf16 = (signed short *)(localbuf + localoffs);
58446 while (c)
58447 {
58448 - locallen = (c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
58449 + locallen = ((unsigned)c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
58450 if (copy_from_user(lbuf8,
58451 userbuf+useroffs + p,
58452 locallen))
58453 diff -urNp linux-2.6.37/sound/oss/swarm_cs4297a.c linux-2.6.37/sound/oss/swarm_cs4297a.c
58454 --- linux-2.6.37/sound/oss/swarm_cs4297a.c 2011-01-04 19:50:19.000000000 -0500
58455 +++ linux-2.6.37/sound/oss/swarm_cs4297a.c 2011-01-17 02:41:02.000000000 -0500
58456 @@ -2606,7 +2606,6 @@ static int __init cs4297a_init(void)
58457 {
58458 struct cs4297a_state *s;
58459 u32 pwr, id;
58460 - mm_segment_t fs;
58461 int rval;
58462 #ifndef CONFIG_BCM_CS4297A_CSWARM
58463 u64 cfg;
58464 @@ -2696,22 +2695,23 @@ static int __init cs4297a_init(void)
58465 if (!rval) {
58466 char *sb1250_duart_present;
58467
58468 +#if 0
58469 + mm_segment_t fs;
58470 fs = get_fs();
58471 set_fs(KERNEL_DS);
58472 -#if 0
58473 val = SOUND_MASK_LINE;
58474 mixer_ioctl(s, SOUND_MIXER_WRITE_RECSRC, (unsigned long) &val);
58475 for (i = 0; i < ARRAY_SIZE(initvol); i++) {
58476 val = initvol[i].vol;
58477 mixer_ioctl(s, initvol[i].mixch, (unsigned long) &val);
58478 }
58479 + set_fs(fs);
58480 // cs4297a_write_ac97(s, 0x18, 0x0808);
58481 #else
58482 // cs4297a_write_ac97(s, 0x5e, 0x180);
58483 cs4297a_write_ac97(s, 0x02, 0x0808);
58484 cs4297a_write_ac97(s, 0x18, 0x0808);
58485 #endif
58486 - set_fs(fs);
58487
58488 list_add(&s->list, &cs4297a_devs);
58489
58490 diff -urNp linux-2.6.37/sound/pci/ac97/ac97_codec.c linux-2.6.37/sound/pci/ac97/ac97_codec.c
58491 --- linux-2.6.37/sound/pci/ac97/ac97_codec.c 2011-01-04 19:50:19.000000000 -0500
58492 +++ linux-2.6.37/sound/pci/ac97/ac97_codec.c 2011-01-17 02:41:02.000000000 -0500
58493 @@ -1962,7 +1962,7 @@ static int snd_ac97_dev_disconnect(struc
58494 }
58495
58496 /* build_ops to do nothing */
58497 -static struct snd_ac97_build_ops null_build_ops;
58498 +static const struct snd_ac97_build_ops null_build_ops;
58499
58500 #ifdef CONFIG_SND_AC97_POWER_SAVE
58501 static void do_update_power(struct work_struct *work)
58502 diff -urNp linux-2.6.37/sound/pci/ac97/ac97_patch.c linux-2.6.37/sound/pci/ac97/ac97_patch.c
58503 --- linux-2.6.37/sound/pci/ac97/ac97_patch.c 2011-01-04 19:50:19.000000000 -0500
58504 +++ linux-2.6.37/sound/pci/ac97/ac97_patch.c 2011-01-17 02:41:02.000000000 -0500
58505 @@ -371,7 +371,7 @@ static int patch_yamaha_ymf743_build_spd
58506 return 0;
58507 }
58508
58509 -static struct snd_ac97_build_ops patch_yamaha_ymf743_ops = {
58510 +static const struct snd_ac97_build_ops patch_yamaha_ymf743_ops = {
58511 .build_spdif = patch_yamaha_ymf743_build_spdif,
58512 .build_3d = patch_yamaha_ymf7x3_3d,
58513 };
58514 @@ -455,7 +455,7 @@ static int patch_yamaha_ymf753_post_spdi
58515 return 0;
58516 }
58517
58518 -static struct snd_ac97_build_ops patch_yamaha_ymf753_ops = {
58519 +static const struct snd_ac97_build_ops patch_yamaha_ymf753_ops = {
58520 .build_3d = patch_yamaha_ymf7x3_3d,
58521 .build_post_spdif = patch_yamaha_ymf753_post_spdif
58522 };
58523 @@ -502,7 +502,7 @@ static int patch_wolfson_wm9703_specific
58524 return 0;
58525 }
58526
58527 -static struct snd_ac97_build_ops patch_wolfson_wm9703_ops = {
58528 +static const struct snd_ac97_build_ops patch_wolfson_wm9703_ops = {
58529 .build_specific = patch_wolfson_wm9703_specific,
58530 };
58531
58532 @@ -533,7 +533,7 @@ static int patch_wolfson_wm9704_specific
58533 return 0;
58534 }
58535
58536 -static struct snd_ac97_build_ops patch_wolfson_wm9704_ops = {
58537 +static const struct snd_ac97_build_ops patch_wolfson_wm9704_ops = {
58538 .build_specific = patch_wolfson_wm9704_specific,
58539 };
58540
58541 @@ -677,7 +677,7 @@ static int patch_wolfson_wm9711_specific
58542 return 0;
58543 }
58544
58545 -static struct snd_ac97_build_ops patch_wolfson_wm9711_ops = {
58546 +static const struct snd_ac97_build_ops patch_wolfson_wm9711_ops = {
58547 .build_specific = patch_wolfson_wm9711_specific,
58548 };
58549
58550 @@ -871,7 +871,7 @@ static void patch_wolfson_wm9713_resume
58551 }
58552 #endif
58553
58554 -static struct snd_ac97_build_ops patch_wolfson_wm9713_ops = {
58555 +static const struct snd_ac97_build_ops patch_wolfson_wm9713_ops = {
58556 .build_specific = patch_wolfson_wm9713_specific,
58557 .build_3d = patch_wolfson_wm9713_3d,
58558 #ifdef CONFIG_PM
58559 @@ -976,7 +976,7 @@ static int patch_sigmatel_stac97xx_speci
58560 return 0;
58561 }
58562
58563 -static struct snd_ac97_build_ops patch_sigmatel_stac9700_ops = {
58564 +static const struct snd_ac97_build_ops patch_sigmatel_stac9700_ops = {
58565 .build_3d = patch_sigmatel_stac9700_3d,
58566 .build_specific = patch_sigmatel_stac97xx_specific
58567 };
58568 @@ -1023,7 +1023,7 @@ static int patch_sigmatel_stac9708_speci
58569 return patch_sigmatel_stac97xx_specific(ac97);
58570 }
58571
58572 -static struct snd_ac97_build_ops patch_sigmatel_stac9708_ops = {
58573 +static const struct snd_ac97_build_ops patch_sigmatel_stac9708_ops = {
58574 .build_3d = patch_sigmatel_stac9708_3d,
58575 .build_specific = patch_sigmatel_stac9708_specific
58576 };
58577 @@ -1252,7 +1252,7 @@ static int patch_sigmatel_stac9758_speci
58578 return 0;
58579 }
58580
58581 -static struct snd_ac97_build_ops patch_sigmatel_stac9758_ops = {
58582 +static const struct snd_ac97_build_ops patch_sigmatel_stac9758_ops = {
58583 .build_3d = patch_sigmatel_stac9700_3d,
58584 .build_specific = patch_sigmatel_stac9758_specific
58585 };
58586 @@ -1327,7 +1327,7 @@ static int patch_cirrus_build_spdif(stru
58587 return 0;
58588 }
58589
58590 -static struct snd_ac97_build_ops patch_cirrus_ops = {
58591 +static const struct snd_ac97_build_ops patch_cirrus_ops = {
58592 .build_spdif = patch_cirrus_build_spdif
58593 };
58594
58595 @@ -1384,7 +1384,7 @@ static int patch_conexant_build_spdif(st
58596 return 0;
58597 }
58598
58599 -static struct snd_ac97_build_ops patch_conexant_ops = {
58600 +static const struct snd_ac97_build_ops patch_conexant_ops = {
58601 .build_spdif = patch_conexant_build_spdif
58602 };
58603
58604 @@ -1486,7 +1486,7 @@ static const struct snd_ac97_res_table a
58605 { AC97_VIDEO, 0x9f1f },
58606 { AC97_AUX, 0x9f1f },
58607 { AC97_PCM, 0x9f1f },
58608 - { } /* terminator */
58609 + { 0, 0 } /* terminator */
58610 };
58611
58612 static int patch_ad1819(struct snd_ac97 * ac97)
58613 @@ -1560,7 +1560,7 @@ static void patch_ad1881_chained(struct
58614 }
58615 }
58616
58617 -static struct snd_ac97_build_ops patch_ad1881_build_ops = {
58618 +static const struct snd_ac97_build_ops patch_ad1881_build_ops = {
58619 #ifdef CONFIG_PM
58620 .resume = ad18xx_resume
58621 #endif
58622 @@ -1647,7 +1647,7 @@ static int patch_ad1885_specific(struct
58623 return 0;
58624 }
58625
58626 -static struct snd_ac97_build_ops patch_ad1885_build_ops = {
58627 +static const struct snd_ac97_build_ops patch_ad1885_build_ops = {
58628 .build_specific = &patch_ad1885_specific,
58629 #ifdef CONFIG_PM
58630 .resume = ad18xx_resume
58631 @@ -1674,7 +1674,7 @@ static int patch_ad1886_specific(struct
58632 return 0;
58633 }
58634
58635 -static struct snd_ac97_build_ops patch_ad1886_build_ops = {
58636 +static const struct snd_ac97_build_ops patch_ad1886_build_ops = {
58637 .build_specific = &patch_ad1886_specific,
58638 #ifdef CONFIG_PM
58639 .resume = ad18xx_resume
58640 @@ -1881,7 +1881,7 @@ static int patch_ad1981a_specific(struct
58641 ARRAY_SIZE(snd_ac97_ad1981x_jack_sense));
58642 }
58643
58644 -static struct snd_ac97_build_ops patch_ad1981a_build_ops = {
58645 +static const struct snd_ac97_build_ops patch_ad1981a_build_ops = {
58646 .build_post_spdif = patch_ad198x_post_spdif,
58647 .build_specific = patch_ad1981a_specific,
58648 #ifdef CONFIG_PM
58649 @@ -1936,7 +1936,7 @@ static int patch_ad1981b_specific(struct
58650 ARRAY_SIZE(snd_ac97_ad1981x_jack_sense));
58651 }
58652
58653 -static struct snd_ac97_build_ops patch_ad1981b_build_ops = {
58654 +static const struct snd_ac97_build_ops patch_ad1981b_build_ops = {
58655 .build_post_spdif = patch_ad198x_post_spdif,
58656 .build_specific = patch_ad1981b_specific,
58657 #ifdef CONFIG_PM
58658 @@ -2075,7 +2075,7 @@ static int patch_ad1888_specific(struct
58659 return patch_build_controls(ac97, snd_ac97_ad1888_controls, ARRAY_SIZE(snd_ac97_ad1888_controls));
58660 }
58661
58662 -static struct snd_ac97_build_ops patch_ad1888_build_ops = {
58663 +static const struct snd_ac97_build_ops patch_ad1888_build_ops = {
58664 .build_post_spdif = patch_ad198x_post_spdif,
58665 .build_specific = patch_ad1888_specific,
58666 #ifdef CONFIG_PM
58667 @@ -2124,7 +2124,7 @@ static int patch_ad1980_specific(struct
58668 return patch_build_controls(ac97, &snd_ac97_ad198x_2cmic, 1);
58669 }
58670
58671 -static struct snd_ac97_build_ops patch_ad1980_build_ops = {
58672 +static const struct snd_ac97_build_ops patch_ad1980_build_ops = {
58673 .build_post_spdif = patch_ad198x_post_spdif,
58674 .build_specific = patch_ad1980_specific,
58675 #ifdef CONFIG_PM
58676 @@ -2239,7 +2239,7 @@ static int patch_ad1985_specific(struct
58677 ARRAY_SIZE(snd_ac97_ad1985_controls));
58678 }
58679
58680 -static struct snd_ac97_build_ops patch_ad1985_build_ops = {
58681 +static const struct snd_ac97_build_ops patch_ad1985_build_ops = {
58682 .build_post_spdif = patch_ad198x_post_spdif,
58683 .build_specific = patch_ad1985_specific,
58684 #ifdef CONFIG_PM
58685 @@ -2531,7 +2531,7 @@ static int patch_ad1986_specific(struct
58686 ARRAY_SIZE(snd_ac97_ad1985_controls));
58687 }
58688
58689 -static struct snd_ac97_build_ops patch_ad1986_build_ops = {
58690 +static const struct snd_ac97_build_ops patch_ad1986_build_ops = {
58691 .build_post_spdif = patch_ad198x_post_spdif,
58692 .build_specific = patch_ad1986_specific,
58693 #ifdef CONFIG_PM
58694 @@ -2636,7 +2636,7 @@ static int patch_alc650_specific(struct
58695 return 0;
58696 }
58697
58698 -static struct snd_ac97_build_ops patch_alc650_ops = {
58699 +static const struct snd_ac97_build_ops patch_alc650_ops = {
58700 .build_specific = patch_alc650_specific,
58701 .update_jacks = alc650_update_jacks
58702 };
58703 @@ -2788,7 +2788,7 @@ static int patch_alc655_specific(struct
58704 return 0;
58705 }
58706
58707 -static struct snd_ac97_build_ops patch_alc655_ops = {
58708 +static const struct snd_ac97_build_ops patch_alc655_ops = {
58709 .build_specific = patch_alc655_specific,
58710 .update_jacks = alc655_update_jacks
58711 };
58712 @@ -2900,7 +2900,7 @@ static int patch_alc850_specific(struct
58713 return 0;
58714 }
58715
58716 -static struct snd_ac97_build_ops patch_alc850_ops = {
58717 +static const struct snd_ac97_build_ops patch_alc850_ops = {
58718 .build_specific = patch_alc850_specific,
58719 .update_jacks = alc850_update_jacks
58720 };
58721 @@ -2962,7 +2962,7 @@ static int patch_cm9738_specific(struct
58722 return patch_build_controls(ac97, snd_ac97_cm9738_controls, ARRAY_SIZE(snd_ac97_cm9738_controls));
58723 }
58724
58725 -static struct snd_ac97_build_ops patch_cm9738_ops = {
58726 +static const struct snd_ac97_build_ops patch_cm9738_ops = {
58727 .build_specific = patch_cm9738_specific,
58728 .update_jacks = cm9738_update_jacks
58729 };
58730 @@ -3053,7 +3053,7 @@ static int patch_cm9739_post_spdif(struc
58731 return patch_build_controls(ac97, snd_ac97_cm9739_controls_spdif, ARRAY_SIZE(snd_ac97_cm9739_controls_spdif));
58732 }
58733
58734 -static struct snd_ac97_build_ops patch_cm9739_ops = {
58735 +static const struct snd_ac97_build_ops patch_cm9739_ops = {
58736 .build_specific = patch_cm9739_specific,
58737 .build_post_spdif = patch_cm9739_post_spdif,
58738 .update_jacks = cm9739_update_jacks
58739 @@ -3227,7 +3227,7 @@ static int patch_cm9761_specific(struct
58740 return patch_build_controls(ac97, snd_ac97_cm9761_controls, ARRAY_SIZE(snd_ac97_cm9761_controls));
58741 }
58742
58743 -static struct snd_ac97_build_ops patch_cm9761_ops = {
58744 +static const struct snd_ac97_build_ops patch_cm9761_ops = {
58745 .build_specific = patch_cm9761_specific,
58746 .build_post_spdif = patch_cm9761_post_spdif,
58747 .update_jacks = cm9761_update_jacks
58748 @@ -3323,7 +3323,7 @@ static int patch_cm9780_specific(struct
58749 return patch_build_controls(ac97, cm9780_controls, ARRAY_SIZE(cm9780_controls));
58750 }
58751
58752 -static struct snd_ac97_build_ops patch_cm9780_ops = {
58753 +static const struct snd_ac97_build_ops patch_cm9780_ops = {
58754 .build_specific = patch_cm9780_specific,
58755 .build_post_spdif = patch_cm9761_post_spdif /* identical with CM9761 */
58756 };
58757 @@ -3443,7 +3443,7 @@ static int patch_vt1616_specific(struct
58758 return 0;
58759 }
58760
58761 -static struct snd_ac97_build_ops patch_vt1616_ops = {
58762 +static const struct snd_ac97_build_ops patch_vt1616_ops = {
58763 .build_specific = patch_vt1616_specific
58764 };
58765
58766 @@ -3797,7 +3797,7 @@ static int patch_it2646_specific(struct
58767 return 0;
58768 }
58769
58770 -static struct snd_ac97_build_ops patch_it2646_ops = {
58771 +static const struct snd_ac97_build_ops patch_it2646_ops = {
58772 .build_specific = patch_it2646_specific,
58773 .update_jacks = it2646_update_jacks
58774 };
58775 @@ -3831,7 +3831,7 @@ static int patch_si3036_specific(struct
58776 return 0;
58777 }
58778
58779 -static struct snd_ac97_build_ops patch_si3036_ops = {
58780 +static const struct snd_ac97_build_ops patch_si3036_ops = {
58781 .build_specific = patch_si3036_specific,
58782 };
58783
58784 @@ -3864,7 +3864,7 @@ static struct snd_ac97_res_table lm4550_
58785 { AC97_AUX, 0x1f1f },
58786 { AC97_PCM, 0x1f1f },
58787 { AC97_REC_GAIN, 0x0f0f },
58788 - { } /* terminator */
58789 + { 0, 0 } /* terminator */
58790 };
58791
58792 static int patch_lm4550(struct snd_ac97 *ac97)
58793 @@ -3898,7 +3898,7 @@ static int patch_ucb1400_specific(struct
58794 return 0;
58795 }
58796
58797 -static struct snd_ac97_build_ops patch_ucb1400_ops = {
58798 +static const struct snd_ac97_build_ops patch_ucb1400_ops = {
58799 .build_specific = patch_ucb1400_specific,
58800 };
58801
58802 diff -urNp linux-2.6.37/sound/pci/ens1370.c linux-2.6.37/sound/pci/ens1370.c
58803 --- linux-2.6.37/sound/pci/ens1370.c 2011-01-04 19:50:19.000000000 -0500
58804 +++ linux-2.6.37/sound/pci/ens1370.c 2011-01-17 02:41:02.000000000 -0500
58805 @@ -452,7 +452,7 @@ static DEFINE_PCI_DEVICE_TABLE(snd_audio
58806 { PCI_VDEVICE(ENSONIQ, 0x5880), 0, }, /* ES1373 - CT5880 */
58807 { PCI_VDEVICE(ECTIVA, 0x8938), 0, }, /* Ectiva EV1938 */
58808 #endif
58809 - { 0, }
58810 + { 0, 0, 0, 0, 0, 0, 0 }
58811 };
58812
58813 MODULE_DEVICE_TABLE(pci, snd_audiopci_ids);
58814 diff -urNp linux-2.6.37/sound/pci/hda/patch_hdmi.c linux-2.6.37/sound/pci/hda/patch_hdmi.c
58815 --- linux-2.6.37/sound/pci/hda/patch_hdmi.c 2011-01-04 19:50:19.000000000 -0500
58816 +++ linux-2.6.37/sound/pci/hda/patch_hdmi.c 2011-01-17 02:41:02.000000000 -0500
58817 @@ -726,10 +726,10 @@ static void hdmi_non_intrinsic_event(str
58818 cp_ready);
58819
58820 /* TODO */
58821 - if (cp_state)
58822 - ;
58823 - if (cp_ready)
58824 - ;
58825 + if (cp_state) {
58826 + }
58827 + if (cp_ready) {
58828 + }
58829 }
58830
58831
58832 diff -urNp linux-2.6.37/sound/pci/intel8x0.c linux-2.6.37/sound/pci/intel8x0.c
58833 --- linux-2.6.37/sound/pci/intel8x0.c 2011-01-04 19:50:19.000000000 -0500
58834 +++ linux-2.6.37/sound/pci/intel8x0.c 2011-01-17 02:41:02.000000000 -0500
58835 @@ -444,7 +444,7 @@ static DEFINE_PCI_DEVICE_TABLE(snd_intel
58836 { PCI_VDEVICE(AMD, 0x746d), DEVICE_INTEL }, /* AMD8111 */
58837 { PCI_VDEVICE(AMD, 0x7445), DEVICE_INTEL }, /* AMD768 */
58838 { PCI_VDEVICE(AL, 0x5455), DEVICE_ALI }, /* Ali5455 */
58839 - { 0, }
58840 + { 0, 0, 0, 0, 0, 0, 0 }
58841 };
58842
58843 MODULE_DEVICE_TABLE(pci, snd_intel8x0_ids);
58844 @@ -2141,7 +2141,7 @@ static struct ac97_quirk ac97_quirks[] _
58845 .type = AC97_TUNE_HP_ONLY
58846 },
58847 #endif
58848 - { } /* terminator */
58849 + { 0, 0, 0, 0, NULL, 0 } /* terminator */
58850 };
58851
58852 static int __devinit snd_intel8x0_mixer(struct intel8x0 *chip, int ac97_clock,
58853 diff -urNp linux-2.6.37/sound/pci/intel8x0m.c linux-2.6.37/sound/pci/intel8x0m.c
58854 --- linux-2.6.37/sound/pci/intel8x0m.c 2011-01-04 19:50:19.000000000 -0500
58855 +++ linux-2.6.37/sound/pci/intel8x0m.c 2011-01-17 02:41:02.000000000 -0500
58856 @@ -239,7 +239,7 @@ static DEFINE_PCI_DEVICE_TABLE(snd_intel
58857 { PCI_VDEVICE(AMD, 0x746d), DEVICE_INTEL }, /* AMD8111 */
58858 { PCI_VDEVICE(AL, 0x5455), DEVICE_ALI }, /* Ali5455 */
58859 #endif
58860 - { 0, }
58861 + { 0, 0, 0, 0, 0, 0, 0 }
58862 };
58863
58864 MODULE_DEVICE_TABLE(pci, snd_intel8x0m_ids);
58865 @@ -1264,7 +1264,7 @@ static struct shortname_table {
58866 { 0x5455, "ALi M5455" },
58867 { 0x746d, "AMD AMD8111" },
58868 #endif
58869 - { 0 },
58870 + { 0, NULL },
58871 };
58872
58873 static int __devinit snd_intel8x0m_probe(struct pci_dev *pci,
58874 diff -urNp linux-2.6.37/usr/gen_init_cpio.c linux-2.6.37/usr/gen_init_cpio.c
58875 --- linux-2.6.37/usr/gen_init_cpio.c 2011-01-04 19:50:19.000000000 -0500
58876 +++ linux-2.6.37/usr/gen_init_cpio.c 2011-01-17 02:41:02.000000000 -0500
58877 @@ -299,7 +299,7 @@ static int cpio_mkfile(const char *name,
58878 int retval;
58879 int rc = -1;
58880 int namesize;
58881 - int i;
58882 + unsigned int i;
58883
58884 mode |= S_IFREG;
58885
58886 @@ -386,9 +386,10 @@ static char *cpio_replace_env(char *new_
58887 *env_var = *expanded = '\0';
58888 strncat(env_var, start + 2, end - start - 2);
58889 strncat(expanded, new_location, start - new_location);
58890 - strncat(expanded, getenv(env_var), PATH_MAX);
58891 - strncat(expanded, end + 1, PATH_MAX);
58892 + strncat(expanded, getenv(env_var), PATH_MAX - strlen(expanded));
58893 + strncat(expanded, end + 1, PATH_MAX - strlen(expanded));
58894 strncpy(new_location, expanded, PATH_MAX);
58895 + new_location[PATH_MAX] = 0;
58896 } else
58897 break;
58898 }
58899 diff -urNp linux-2.6.37/virt/kvm/kvm_main.c linux-2.6.37/virt/kvm/kvm_main.c
58900 --- linux-2.6.37/virt/kvm/kvm_main.c 2011-01-04 19:50:19.000000000 -0500
58901 +++ linux-2.6.37/virt/kvm/kvm_main.c 2011-01-17 02:41:02.000000000 -0500
58902 @@ -1344,6 +1344,7 @@ static int kvm_vcpu_release(struct inode
58903 return 0;
58904 }
58905
58906 +/* cannot be const */
58907 static struct file_operations kvm_vcpu_fops = {
58908 .release = kvm_vcpu_release,
58909 .unlocked_ioctl = kvm_vcpu_ioctl,
58910 @@ -1812,6 +1813,7 @@ static int kvm_vm_mmap(struct file *file
58911 return 0;
58912 }
58913
58914 +/* cannot be const */
58915 static struct file_operations kvm_vm_fops = {
58916 .release = kvm_vm_release,
58917 .unlocked_ioctl = kvm_vm_ioctl,
58918 @@ -1910,6 +1912,7 @@ out:
58919 return r;
58920 }
58921
58922 +/* cannot be const */
58923 static struct file_operations kvm_chardev_ops = {
58924 .unlocked_ioctl = kvm_dev_ioctl,
58925 .compat_ioctl = kvm_dev_ioctl,
58926 @@ -1920,6 +1923,9 @@ static struct miscdevice kvm_dev = {
58927 KVM_MINOR,
58928 "kvm",
58929 &kvm_chardev_ops,
58930 + {NULL, NULL},
58931 + NULL,
58932 + NULL
58933 };
58934
58935 static void hardware_enable(void *junk)
58936 @@ -2259,7 +2265,7 @@ static void kvm_sched_out(struct preempt
58937 kvm_arch_vcpu_put(vcpu);
58938 }
58939
58940 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
58941 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
58942 struct module *module)
58943 {
58944 int r;