Gentoo Archives: gentoo-commits

From: "Gordon Malm (gengor)" <gengor@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] linux-patches r1484 - in hardened/2.6/tags: . 2.6.27-7
Date: Sat, 24 Jan 2009 22:35:46
Message-Id: E1LQr54-0006yN-Mn@stork.gentoo.org
1 Author: gengor
2 Date: 2009-01-24 22:34:22 +0000 (Sat, 24 Jan 2009)
3 New Revision: 1484
4
5 Added:
6 hardened/2.6/tags/2.6.27-7/
7 hardened/2.6/tags/2.6.27-7/0000_README
8 hardened/2.6/tags/2.6.27-7/4420_grsec-2.1.12-2.6.27.10-200812271347.patch
9 hardened/2.6/tags/2.6.27-7/4421_grsec-remove-localversion-grsec.patch
10 hardened/2.6/tags/2.6.27-7/4422_grsec-mute-warnings.patch
11 hardened/2.6/tags/2.6.27-7/4425_grsec-pax-without-grsec.patch
12 hardened/2.6/tags/2.6.27-7/4430_grsec-kconfig-default-gids.patch
13 hardened/2.6/tags/2.6.27-7/4435_grsec-kconfig-gentoo.patch
14 hardened/2.6/tags/2.6.27-7/4440_selinux-avc_audit-log-curr_ip.patch
15 hardened/2.6/tags/2.6.27-7/4445_disable-compat_vdso.patch
16 hardened/2.6/tags/2.6.27-7/4450_grsec-add-offender-IP-to-pax_refcount-logging.patch
17 hardened/2.6/tags/2.6.27-7/4455_pax-revert-fix-false-RLIMIT_STACK-warnings.patch
18 Log:
19 Add hardened-extras 2.6.27-7 tag
20
21 Added: hardened/2.6/tags/2.6.27-7/0000_README
22 ===================================================================
23 --- hardened/2.6/tags/2.6.27-7/0000_README (rev 0)
24 +++ hardened/2.6/tags/2.6.27-7/0000_README 2009-01-24 22:34:22 UTC (rev 1484)
25 @@ -0,0 +1,50 @@
26 +README
27 +-----------------------------------------------------------------------------
28 +
29 +Individual Patch Descriptions:
30 +-----------------------------------------------------------------------------
31 +Patch: 4420_grsec-2.1.12-2.6.27.10-200812271347.patch
32 +From: http://www.grsecurity.net
33 +Desc: hardened-sources base patch from upstream grsecurity
34 +
35 +Patch: 4421_grsec-remove-localversion-grsec.patch
36 +From: Kerin Millar <kerframil@×××××.com>
37 +Desc: Removes grsecurity's localversion-grsec file
38 +
39 +Patch: 4422_grsec-mute-warnings.patch
40 +From: Alexander Gabert <gaberta@××××××××.de>
41 + Gordon Malm <gengor@g.o>
42 +Desc: Removes verbose compile warning settings from grsecurity, restores
43 + mainline Linux kernel behavior
44 +
45 +Patch: 4425_grsec-pax-without-grsec.patch
46 +From: Gordon Malm <gengor@g.o>
47 +Desc: Allows PaX features to be selected without enabling GRKERNSEC
48 +
49 +Patch: 4430_grsec-kconfig-default-gids.patch
50 +From: Kerin Millar <kerframil@×××××.com>
51 +Desc: Sets sane(r) default GIDs on various grsecurity group-dependent
52 + features
53 +
54 +Patch: 4435_grsec-kconfig-gentoo.patch
55 +From: Gordon Malm <gengor@g.o>
56 + Kerin Millar <kerframil@×××××.com>
57 +Desc: Adds Hardened Gentoo [server/workstation] security levels, sets
58 + Hardened Gentoo [workstation] as default
59 +
60 +Patch: 4440_selinux-avc_audit-log-curr_ip.patch
61 +From: Gordon Malm <gengor@g.o>
62 +Desc: Configurable option to add src IP address to SELinux log messages
63 +
64 +Patch: 4445_disable-compat_vdso.patch
65 +From: Gordon Malm <gengor@g.o>
66 + Kerin Millar <kerframil@×××××.com>
67 +Desc: Disables VDSO_COMPAT operation completely
68 +
69 +Patch: 4450_grsec-add-offender-IP-to-pax_refcount-logging.patch
70 +From: Gordon Malm <gengor@g.o>
71 +Desc: Add offender's IP to PAX_REFCOUNT log messages if it is available
72 +
73 +Patch: 4455_pax-revert-fix-false-RLIMIT_STACK-warnings.patch
74 +From: Gordon Malm <gengor@g.o>
75 +Desc: Revert RLIMIT_STACK false-positives-avoidance change in PaX
76
77 Added: hardened/2.6/tags/2.6.27-7/4420_grsec-2.1.12-2.6.27.10-200812271347.patch
78 ===================================================================
79 --- hardened/2.6/tags/2.6.27-7/4420_grsec-2.1.12-2.6.27.10-200812271347.patch (rev 0)
80 +++ hardened/2.6/tags/2.6.27-7/4420_grsec-2.1.12-2.6.27.10-200812271347.patch 2009-01-24 22:34:22 UTC (rev 1484)
81 @@ -0,0 +1,37200 @@
82 + !
83 + -~*~-
84 + /!\
85 + /%;@\
86 + o/@,%\o
87 + /%;`@,\
88 + o/@'%',\o
89 + '^^^N^^^`
90 +
91 +diff -urNp linux-2.6.27.10/arch/alpha/include/asm/elf.h linux-2.6.27.10/arch/alpha/include/asm/elf.h
92 +--- linux-2.6.27.10/arch/alpha/include/asm/elf.h 2008-11-07 12:55:34.000000000 -0500
93 ++++ linux-2.6.27.10/arch/alpha/include/asm/elf.h 2008-11-18 03:39:50.000000000 -0500
94 +@@ -91,6 +91,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_N
95 +
96 + #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
97 +
98 ++#ifdef CONFIG_PAX_ASLR
99 ++#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
100 ++
101 ++#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
102 ++#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
103 ++#endif
104 ++
105 + /* $0 is set by ld.so to a pointer to a function which might be
106 + registered using atexit. This provides a mean for the dynamic
107 + linker to call DT_FINI functions for shared libraries that have
108 +diff -urNp linux-2.6.27.10/arch/alpha/include/asm/kmap_types.h linux-2.6.27.10/arch/alpha/include/asm/kmap_types.h
109 +--- linux-2.6.27.10/arch/alpha/include/asm/kmap_types.h 2008-11-07 12:55:34.000000000 -0500
110 ++++ linux-2.6.27.10/arch/alpha/include/asm/kmap_types.h 2008-11-18 03:39:50.000000000 -0500
111 +@@ -24,7 +24,8 @@ D(9) KM_IRQ0,
112 + D(10) KM_IRQ1,
113 + D(11) KM_SOFTIRQ0,
114 + D(12) KM_SOFTIRQ1,
115 +-D(13) KM_TYPE_NR
116 ++D(13) KM_CLEARPAGE,
117 ++D(14) KM_TYPE_NR
118 + };
119 +
120 + #undef D
121 +diff -urNp linux-2.6.27.10/arch/alpha/include/asm/pgtable.h linux-2.6.27.10/arch/alpha/include/asm/pgtable.h
122 +--- linux-2.6.27.10/arch/alpha/include/asm/pgtable.h 2008-11-07 12:55:34.000000000 -0500
123 ++++ linux-2.6.27.10/arch/alpha/include/asm/pgtable.h 2008-11-18 03:39:50.000000000 -0500
124 +@@ -101,6 +101,17 @@ struct vm_area_struct;
125 + #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
126 + #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
127 + #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
128 ++
129 ++#ifdef CONFIG_PAX_PAGEEXEC
130 ++# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
131 ++# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
132 ++# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
133 ++#else
134 ++# define PAGE_SHARED_NOEXEC PAGE_SHARED
135 ++# define PAGE_COPY_NOEXEC PAGE_COPY
136 ++# define PAGE_READONLY_NOEXEC PAGE_READONLY
137 ++#endif
138 ++
139 + #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
140 +
141 + #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
142 +diff -urNp linux-2.6.27.10/arch/alpha/kernel/module.c linux-2.6.27.10/arch/alpha/kernel/module.c
143 +--- linux-2.6.27.10/arch/alpha/kernel/module.c 2008-11-07 12:55:34.000000000 -0500
144 ++++ linux-2.6.27.10/arch/alpha/kernel/module.c 2008-11-18 03:38:43.000000000 -0500
145 +@@ -182,7 +182,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs,
146 +
147 + /* The small sections were sorted to the end of the segment.
148 + The following should definitely cover them. */
149 +- gp = (u64)me->module_core + me->core_size - 0x8000;
150 ++ gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
151 + got = sechdrs[me->arch.gotsecindex].sh_addr;
152 +
153 + for (i = 0; i < n; i++) {
154 +diff -urNp linux-2.6.27.10/arch/alpha/kernel/osf_sys.c linux-2.6.27.10/arch/alpha/kernel/osf_sys.c
155 +--- linux-2.6.27.10/arch/alpha/kernel/osf_sys.c 2008-11-07 12:55:34.000000000 -0500
156 ++++ linux-2.6.27.10/arch/alpha/kernel/osf_sys.c 2008-11-18 03:38:43.000000000 -0500
157 +@@ -1232,6 +1232,10 @@ arch_get_unmapped_area(struct file *filp
158 + merely specific addresses, but regions of memory -- perhaps
159 + this feature should be incorporated into all ports? */
160 +
161 ++#ifdef CONFIG_PAX_RANDMMAP
162 ++ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP) || !filp)
163 ++#endif
164 ++
165 + if (addr) {
166 + addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
167 + if (addr != (unsigned long) -ENOMEM)
168 +@@ -1239,8 +1243,8 @@ arch_get_unmapped_area(struct file *filp
169 + }
170 +
171 + /* Next, try allocating at TASK_UNMAPPED_BASE. */
172 +- addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
173 +- len, limit);
174 ++ addr = arch_get_unmapped_area_1 (PAGE_ALIGN(current->mm->mmap_base), len, limit);
175 ++
176 + if (addr != (unsigned long) -ENOMEM)
177 + return addr;
178 +
179 +diff -urNp linux-2.6.27.10/arch/alpha/kernel/ptrace.c linux-2.6.27.10/arch/alpha/kernel/ptrace.c
180 +--- linux-2.6.27.10/arch/alpha/kernel/ptrace.c 2008-11-07 12:55:34.000000000 -0500
181 ++++ linux-2.6.27.10/arch/alpha/kernel/ptrace.c 2008-11-18 03:38:43.000000000 -0500
182 +@@ -15,6 +15,7 @@
183 + #include <linux/slab.h>
184 + #include <linux/security.h>
185 + #include <linux/signal.h>
186 ++#include <linux/grsecurity.h>
187 +
188 + #include <asm/uaccess.h>
189 + #include <asm/pgtable.h>
190 +@@ -266,6 +267,9 @@ long arch_ptrace(struct task_struct *chi
191 + size_t copied;
192 + long ret;
193 +
194 ++ if (gr_handle_ptrace(child, request))
195 ++ return -EPERM;
196 ++
197 + switch (request) {
198 + /* When I and D space are separate, these will need to be fixed. */
199 + case PTRACE_PEEKTEXT: /* read word at location addr. */
200 +diff -urNp linux-2.6.27.10/arch/alpha/mm/fault.c linux-2.6.27.10/arch/alpha/mm/fault.c
201 +--- linux-2.6.27.10/arch/alpha/mm/fault.c 2008-11-07 12:55:34.000000000 -0500
202 ++++ linux-2.6.27.10/arch/alpha/mm/fault.c 2008-11-18 03:38:43.000000000 -0500
203 +@@ -54,6 +54,124 @@ __load_new_mm_context(struct mm_struct *
204 + __reload_thread(pcb);
205 + }
206 +
207 ++#ifdef CONFIG_PAX_PAGEEXEC
208 ++/*
209 ++ * PaX: decide what to do with offenders (regs->pc = fault address)
210 ++ *
211 ++ * returns 1 when task should be killed
212 ++ * 2 when patched PLT trampoline was detected
213 ++ * 3 when unpatched PLT trampoline was detected
214 ++ */
215 ++static int pax_handle_fetch_fault(struct pt_regs *regs)
216 ++{
217 ++
218 ++#ifdef CONFIG_PAX_EMUPLT
219 ++ int err;
220 ++
221 ++ do { /* PaX: patched PLT emulation #1 */
222 ++ unsigned int ldah, ldq, jmp;
223 ++
224 ++ err = get_user(ldah, (unsigned int *)regs->pc);
225 ++ err |= get_user(ldq, (unsigned int *)(regs->pc+4));
226 ++ err |= get_user(jmp, (unsigned int *)(regs->pc+8));
227 ++
228 ++ if (err)
229 ++ break;
230 ++
231 ++ if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
232 ++ (ldq & 0xFFFF0000U) == 0xA77B0000U &&
233 ++ jmp == 0x6BFB0000U)
234 ++ {
235 ++ unsigned long r27, addr;
236 ++ unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
237 ++ unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
238 ++
239 ++ addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
240 ++ err = get_user(r27, (unsigned long *)addr);
241 ++ if (err)
242 ++ break;
243 ++
244 ++ regs->r27 = r27;
245 ++ regs->pc = r27;
246 ++ return 2;
247 ++ }
248 ++ } while (0);
249 ++
250 ++ do { /* PaX: patched PLT emulation #2 */
251 ++ unsigned int ldah, lda, br;
252 ++
253 ++ err = get_user(ldah, (unsigned int *)regs->pc);
254 ++ err |= get_user(lda, (unsigned int *)(regs->pc+4));
255 ++ err |= get_user(br, (unsigned int *)(regs->pc+8));
256 ++
257 ++ if (err)
258 ++ break;
259 ++
260 ++ if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
261 ++ (lda & 0xFFFF0000U) == 0xA77B0000U &&
262 ++ (br & 0xFFE00000U) == 0xC3E00000U)
263 ++ {
264 ++ unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
265 ++ unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
266 ++ unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
267 ++
268 ++ regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
269 ++ regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
270 ++ return 2;
271 ++ }
272 ++ } while (0);
273 ++
274 ++ do { /* PaX: unpatched PLT emulation */
275 ++ unsigned int br;
276 ++
277 ++ err = get_user(br, (unsigned int *)regs->pc);
278 ++
279 ++ if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
280 ++ unsigned int br2, ldq, nop, jmp;
281 ++ unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
282 ++
283 ++ addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
284 ++ err = get_user(br2, (unsigned int *)addr);
285 ++ err |= get_user(ldq, (unsigned int *)(addr+4));
286 ++ err |= get_user(nop, (unsigned int *)(addr+8));
287 ++ err |= get_user(jmp, (unsigned int *)(addr+12));
288 ++ err |= get_user(resolver, (unsigned long *)(addr+16));
289 ++
290 ++ if (err)
291 ++ break;
292 ++
293 ++ if (br2 == 0xC3600000U &&
294 ++ ldq == 0xA77B000CU &&
295 ++ nop == 0x47FF041FU &&
296 ++ jmp == 0x6B7B0000U)
297 ++ {
298 ++ regs->r28 = regs->pc+4;
299 ++ regs->r27 = addr+16;
300 ++ regs->pc = resolver;
301 ++ return 3;
302 ++ }
303 ++ }
304 ++ } while (0);
305 ++#endif
306 ++
307 ++ return 1;
308 ++}
309 ++
310 ++void pax_report_insns(void *pc, void *sp)
311 ++{
312 ++ unsigned long i;
313 ++
314 ++ printk(KERN_ERR "PAX: bytes at PC: ");
315 ++ for (i = 0; i < 5; i++) {
316 ++ unsigned int c;
317 ++ if (get_user(c, (unsigned int *)pc+i))
318 ++ printk(KERN_CONT "???????? ");
319 ++ else
320 ++ printk(KERN_CONT "%08x ", c);
321 ++ }
322 ++ printk("\n");
323 ++}
324 ++#endif
325 +
326 + /*
327 + * This routine handles page faults. It determines the address,
328 +@@ -131,8 +249,29 @@ do_page_fault(unsigned long address, uns
329 + good_area:
330 + si_code = SEGV_ACCERR;
331 + if (cause < 0) {
332 +- if (!(vma->vm_flags & VM_EXEC))
333 ++ if (!(vma->vm_flags & VM_EXEC)) {
334 ++
335 ++#ifdef CONFIG_PAX_PAGEEXEC
336 ++ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
337 ++ goto bad_area;
338 ++
339 ++ up_read(&mm->mmap_sem);
340 ++ switch (pax_handle_fetch_fault(regs)) {
341 ++
342 ++#ifdef CONFIG_PAX_EMUPLT
343 ++ case 2:
344 ++ case 3:
345 ++ return;
346 ++#endif
347 ++
348 ++ }
349 ++ pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
350 ++ do_group_exit(SIGKILL);
351 ++#else
352 + goto bad_area;
353 ++#endif
354 ++
355 ++ }
356 + } else if (!cause) {
357 + /* Allow reads even for write-only mappings */
358 + if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
359 +diff -urNp linux-2.6.27.10/arch/arm/include/asm/elf.h linux-2.6.27.10/arch/arm/include/asm/elf.h
360 +--- linux-2.6.27.10/arch/arm/include/asm/elf.h 2008-11-07 12:55:34.000000000 -0500
361 ++++ linux-2.6.27.10/arch/arm/include/asm/elf.h 2008-11-18 03:39:50.000000000 -0500
362 +@@ -87,7 +87,14 @@ extern char elf_platform[];
363 + the loader. We need to make sure that it is out of the way of the program
364 + that it will "exec", and that there is sufficient room for the brk. */
365 +
366 +-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
367 ++#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
368 ++
369 ++#ifdef CONFIG_PAX_ASLR
370 ++#define PAX_ELF_ET_DYN_BASE 0x00008000UL
371 ++
372 ++#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
373 ++#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
374 ++#endif
375 +
376 + /* When the program starts, a1 contains a pointer to a function to be
377 + registered with atexit, as per the SVR4 ABI. A value of 0 means we
378 +diff -urNp linux-2.6.27.10/arch/arm/include/asm/kmap_types.h linux-2.6.27.10/arch/arm/include/asm/kmap_types.h
379 +--- linux-2.6.27.10/arch/arm/include/asm/kmap_types.h 2008-11-07 12:55:34.000000000 -0500
380 ++++ linux-2.6.27.10/arch/arm/include/asm/kmap_types.h 2008-11-18 03:39:50.000000000 -0500
381 +@@ -18,6 +18,7 @@ enum km_type {
382 + KM_IRQ1,
383 + KM_SOFTIRQ0,
384 + KM_SOFTIRQ1,
385 ++ KM_CLEARPAGE,
386 + KM_TYPE_NR
387 + };
388 +
389 +diff -urNp linux-2.6.27.10/arch/arm/mm/mmap.c linux-2.6.27.10/arch/arm/mm/mmap.c
390 +--- linux-2.6.27.10/arch/arm/mm/mmap.c 2008-11-07 12:55:34.000000000 -0500
391 ++++ linux-2.6.27.10/arch/arm/mm/mmap.c 2008-11-18 03:38:43.000000000 -0500
392 +@@ -60,6 +60,10 @@ arch_get_unmapped_area(struct file *filp
393 + if (len > TASK_SIZE)
394 + return -ENOMEM;
395 +
396 ++#ifdef CONFIG_PAX_RANDMMAP
397 ++ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || !filp)
398 ++#endif
399 ++
400 + if (addr) {
401 + if (do_align)
402 + addr = COLOUR_ALIGN(addr, pgoff);
403 +@@ -72,10 +76,10 @@ arch_get_unmapped_area(struct file *filp
404 + return addr;
405 + }
406 + if (len > mm->cached_hole_size) {
407 +- start_addr = addr = mm->free_area_cache;
408 ++ start_addr = addr = mm->free_area_cache;
409 + } else {
410 +- start_addr = addr = TASK_UNMAPPED_BASE;
411 +- mm->cached_hole_size = 0;
412 ++ start_addr = addr = mm->mmap_base;
413 ++ mm->cached_hole_size = 0;
414 + }
415 +
416 + full_search:
417 +@@ -91,8 +95,8 @@ full_search:
418 + * Start a new search - just in case we missed
419 + * some holes.
420 + */
421 +- if (start_addr != TASK_UNMAPPED_BASE) {
422 +- start_addr = addr = TASK_UNMAPPED_BASE;
423 ++ if (start_addr != mm->mmap_base) {
424 ++ start_addr = addr = mm->mmap_base;
425 + mm->cached_hole_size = 0;
426 + goto full_search;
427 + }
428 +diff -urNp linux-2.6.27.10/arch/avr32/include/asm/elf.h linux-2.6.27.10/arch/avr32/include/asm/elf.h
429 +--- linux-2.6.27.10/arch/avr32/include/asm/elf.h 2008-11-07 12:55:34.000000000 -0500
430 ++++ linux-2.6.27.10/arch/avr32/include/asm/elf.h 2008-11-18 03:39:50.000000000 -0500
431 +@@ -85,8 +85,14 @@ typedef struct user_fpu_struct elf_fpreg
432 + the loader. We need to make sure that it is out of the way of the program
433 + that it will "exec", and that there is sufficient room for the brk. */
434 +
435 +-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
436 ++#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
437 +
438 ++#ifdef CONFIG_PAX_ASLR
439 ++#define PAX_ELF_ET_DYN_BASE 0x00001000UL
440 ++
441 ++#define PAX_DELTA_MMAP_LEN 15
442 ++#define PAX_DELTA_STACK_LEN 15
443 ++#endif
444 +
445 + /* This yields a mask that user programs can use to figure out what
446 + instruction set this CPU supports. This could be done in user space,
447 +diff -urNp linux-2.6.27.10/arch/avr32/include/asm/kmap_types.h linux-2.6.27.10/arch/avr32/include/asm/kmap_types.h
448 +--- linux-2.6.27.10/arch/avr32/include/asm/kmap_types.h 2008-11-07 12:55:34.000000000 -0500
449 ++++ linux-2.6.27.10/arch/avr32/include/asm/kmap_types.h 2008-11-18 03:39:50.000000000 -0500
450 +@@ -22,7 +22,8 @@ D(10) KM_IRQ0,
451 + D(11) KM_IRQ1,
452 + D(12) KM_SOFTIRQ0,
453 + D(13) KM_SOFTIRQ1,
454 +-D(14) KM_TYPE_NR
455 ++D(14) KM_CLEARPAGE,
456 ++D(15) KM_TYPE_NR
457 + };
458 +
459 + #undef D
460 +diff -urNp linux-2.6.27.10/arch/avr32/mm/fault.c linux-2.6.27.10/arch/avr32/mm/fault.c
461 +--- linux-2.6.27.10/arch/avr32/mm/fault.c 2008-11-07 12:55:34.000000000 -0500
462 ++++ linux-2.6.27.10/arch/avr32/mm/fault.c 2008-11-18 03:38:43.000000000 -0500
463 +@@ -41,6 +41,23 @@ static inline int notify_page_fault(stru
464 +
465 + int exception_trace = 1;
466 +
467 ++#ifdef CONFIG_PAX_PAGEEXEC
468 ++void pax_report_insns(void *pc, void *sp)
469 ++{
470 ++ unsigned long i;
471 ++
472 ++ printk(KERN_ERR "PAX: bytes at PC: ");
473 ++ for (i = 0; i < 20; i++) {
474 ++ unsigned char c;
475 ++ if (get_user(c, (unsigned char *)pc+i))
476 ++ printk(KERN_CONT "???????? ");
477 ++ else
478 ++ printk(KERN_CONT "%02x ", c);
479 ++ }
480 ++ printk("\n");
481 ++}
482 ++#endif
483 ++
484 + /*
485 + * This routine handles page faults. It determines the address and the
486 + * problem, and then passes it off to one of the appropriate routines.
487 +@@ -157,6 +174,16 @@ bad_area:
488 + up_read(&mm->mmap_sem);
489 +
490 + if (user_mode(regs)) {
491 ++
492 ++#ifdef CONFIG_PAX_PAGEEXEC
493 ++ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
494 ++ if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
495 ++ pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
496 ++ do_group_exit(SIGKILL);
497 ++ }
498 ++ }
499 ++#endif
500 ++
501 + if (exception_trace && printk_ratelimit())
502 + printk("%s%s[%d]: segfault at %08lx pc %08lx "
503 + "sp %08lx ecr %lu\n",
504 +diff -urNp linux-2.6.27.10/arch/blackfin/include/asm/kmap_types.h linux-2.6.27.10/arch/blackfin/include/asm/kmap_types.h
505 +--- linux-2.6.27.10/arch/blackfin/include/asm/kmap_types.h 2008-11-07 12:55:34.000000000 -0500
506 ++++ linux-2.6.27.10/arch/blackfin/include/asm/kmap_types.h 2008-11-18 03:39:50.000000000 -0500
507 +@@ -15,6 +15,7 @@ enum km_type {
508 + KM_IRQ1,
509 + KM_SOFTIRQ0,
510 + KM_SOFTIRQ1,
511 ++ KM_CLEARPAGE,
512 + KM_TYPE_NR
513 + };
514 +
515 +diff -urNp linux-2.6.27.10/arch/h8300/include/asm/kmap_types.h linux-2.6.27.10/arch/h8300/include/asm/kmap_types.h
516 +--- linux-2.6.27.10/arch/h8300/include/asm/kmap_types.h 2008-11-07 12:55:34.000000000 -0500
517 ++++ linux-2.6.27.10/arch/h8300/include/asm/kmap_types.h 2008-11-18 03:39:50.000000000 -0500
518 +@@ -15,6 +15,7 @@ enum km_type {
519 + KM_IRQ1,
520 + KM_SOFTIRQ0,
521 + KM_SOFTIRQ1,
522 ++ KM_CLEARPAGE,
523 + KM_TYPE_NR
524 + };
525 +
526 +diff -urNp linux-2.6.27.10/arch/ia64/ia32/binfmt_elf32.c linux-2.6.27.10/arch/ia64/ia32/binfmt_elf32.c
527 +--- linux-2.6.27.10/arch/ia64/ia32/binfmt_elf32.c 2008-11-07 12:55:34.000000000 -0500
528 ++++ linux-2.6.27.10/arch/ia64/ia32/binfmt_elf32.c 2008-11-18 03:38:43.000000000 -0500
529 +@@ -45,6 +45,13 @@ randomize_stack_top(unsigned long stack_
530 +
531 + #define elf_read_implies_exec(ex, have_pt_gnu_stack) (!(have_pt_gnu_stack))
532 +
533 ++#ifdef CONFIG_PAX_ASLR
534 ++#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
535 ++
536 ++#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
537 ++#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
538 ++#endif
539 ++
540 + /* Ugly but avoids duplication */
541 + #include "../../../fs/binfmt_elf.c"
542 +
543 +diff -urNp linux-2.6.27.10/arch/ia64/ia32/ia32priv.h linux-2.6.27.10/arch/ia64/ia32/ia32priv.h
544 +--- linux-2.6.27.10/arch/ia64/ia32/ia32priv.h 2008-11-07 12:55:34.000000000 -0500
545 ++++ linux-2.6.27.10/arch/ia64/ia32/ia32priv.h 2008-11-18 03:38:43.000000000 -0500
546 +@@ -296,7 +296,14 @@ typedef struct compat_siginfo {
547 + #define ELF_DATA ELFDATA2LSB
548 + #define ELF_ARCH EM_386
549 +
550 +-#define IA32_STACK_TOP IA32_PAGE_OFFSET
551 ++#ifdef CONFIG_PAX_RANDUSTACK
552 ++#define __IA32_DELTA_STACK (current->mm->delta_stack)
553 ++#else
554 ++#define __IA32_DELTA_STACK 0UL
555 ++#endif
556 ++
557 ++#define IA32_STACK_TOP (IA32_PAGE_OFFSET - __IA32_DELTA_STACK)
558 ++
559 + #define IA32_GATE_OFFSET IA32_PAGE_OFFSET
560 + #define IA32_GATE_END IA32_PAGE_OFFSET + PAGE_SIZE
561 +
562 +diff -urNp linux-2.6.27.10/arch/ia64/include/asm/elf.h linux-2.6.27.10/arch/ia64/include/asm/elf.h
563 +--- linux-2.6.27.10/arch/ia64/include/asm/elf.h 2008-11-07 12:55:34.000000000 -0500
564 ++++ linux-2.6.27.10/arch/ia64/include/asm/elf.h 2008-11-18 03:39:50.000000000 -0500
565 +@@ -43,6 +43,13 @@
566 + */
567 + #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
568 +
569 ++#ifdef CONFIG_PAX_ASLR
570 ++#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
571 ++
572 ++#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
573 ++#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
574 ++#endif
575 ++
576 + #define PT_IA_64_UNWIND 0x70000001
577 +
578 + /* IA-64 relocations: */
579 +diff -urNp linux-2.6.27.10/arch/ia64/include/asm/kmap_types.h linux-2.6.27.10/arch/ia64/include/asm/kmap_types.h
580 +--- linux-2.6.27.10/arch/ia64/include/asm/kmap_types.h 2008-11-07 12:55:34.000000000 -0500
581 ++++ linux-2.6.27.10/arch/ia64/include/asm/kmap_types.h 2008-11-18 03:39:50.000000000 -0500
582 +@@ -22,7 +22,8 @@ D(9) KM_IRQ0,
583 + D(10) KM_IRQ1,
584 + D(11) KM_SOFTIRQ0,
585 + D(12) KM_SOFTIRQ1,
586 +-D(13) KM_TYPE_NR
587 ++D(13) KM_CLEARPAGE,
588 ++D(14) KM_TYPE_NR
589 + };
590 +
591 + #undef D
592 +diff -urNp linux-2.6.27.10/arch/ia64/include/asm/pgtable.h linux-2.6.27.10/arch/ia64/include/asm/pgtable.h
593 +--- linux-2.6.27.10/arch/ia64/include/asm/pgtable.h 2008-11-07 12:55:34.000000000 -0500
594 ++++ linux-2.6.27.10/arch/ia64/include/asm/pgtable.h 2008-11-18 03:39:50.000000000 -0500
595 +@@ -143,6 +143,17 @@
596 + #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
597 + #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
598 + #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
599 ++
600 ++#ifdef CONFIG_PAX_PAGEEXEC
601 ++# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
602 ++# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
603 ++# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
604 ++#else
605 ++# define PAGE_SHARED_NOEXEC PAGE_SHARED
606 ++# define PAGE_READONLY_NOEXEC PAGE_READONLY
607 ++# define PAGE_COPY_NOEXEC PAGE_COPY
608 ++#endif
609 ++
610 + #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
611 + #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
612 + #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
613 +diff -urNp linux-2.6.27.10/arch/ia64/kernel/module.c linux-2.6.27.10/arch/ia64/kernel/module.c
614 +--- linux-2.6.27.10/arch/ia64/kernel/module.c 2008-11-07 12:55:34.000000000 -0500
615 ++++ linux-2.6.27.10/arch/ia64/kernel/module.c 2008-11-18 03:38:43.000000000 -0500
616 +@@ -312,8 +312,7 @@ module_alloc (unsigned long size)
617 + void
618 + module_free (struct module *mod, void *module_region)
619 + {
620 +- if (mod && mod->arch.init_unw_table &&
621 +- module_region == mod->module_init) {
622 ++ if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
623 + unw_remove_unwind_table(mod->arch.init_unw_table);
624 + mod->arch.init_unw_table = NULL;
625 + }
626 +@@ -491,15 +490,39 @@ module_frob_arch_sections (Elf_Ehdr *ehd
627 + }
628 +
629 + static inline int
630 ++in_init_rx (const struct module *mod, uint64_t addr)
631 ++{
632 ++ return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
633 ++}
634 ++
635 ++static inline int
636 ++in_init_rw (const struct module *mod, uint64_t addr)
637 ++{
638 ++ return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
639 ++}
640 ++
641 ++static inline int
642 + in_init (const struct module *mod, uint64_t addr)
643 + {
644 +- return addr - (uint64_t) mod->module_init < mod->init_size;
645 ++ return in_init_rx(mod, addr) || in_init_rw(mod, addr);
646 ++}
647 ++
648 ++static inline int
649 ++in_core_rx (const struct module *mod, uint64_t addr)
650 ++{
651 ++ return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
652 ++}
653 ++
654 ++static inline int
655 ++in_core_rw (const struct module *mod, uint64_t addr)
656 ++{
657 ++ return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
658 + }
659 +
660 + static inline int
661 + in_core (const struct module *mod, uint64_t addr)
662 + {
663 +- return addr - (uint64_t) mod->module_core < mod->core_size;
664 ++ return in_core_rx(mod, addr) || in_core_rw(mod, addr);
665 + }
666 +
667 + static inline int
668 +@@ -683,7 +706,14 @@ do_reloc (struct module *mod, uint8_t r_
669 + break;
670 +
671 + case RV_BDREL:
672 +- val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
673 ++ if (in_init_rx(mod, val))
674 ++ val -= (uint64_t) mod->module_init_rx;
675 ++ else if (in_init_rw(mod, val))
676 ++ val -= (uint64_t) mod->module_init_rw;
677 ++ else if (in_core_rx(mod, val))
678 ++ val -= (uint64_t) mod->module_core_rx;
679 ++ else if (in_core_rw(mod, val))
680 ++ val -= (uint64_t) mod->module_core_rw;
681 + break;
682 +
683 + case RV_LTV:
684 +@@ -817,15 +847,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs,
685 + * addresses have been selected...
686 + */
687 + uint64_t gp;
688 +- if (mod->core_size > MAX_LTOFF)
689 ++ if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
690 + /*
691 + * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
692 + * at the end of the module.
693 + */
694 +- gp = mod->core_size - MAX_LTOFF / 2;
695 ++ gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
696 + else
697 +- gp = mod->core_size / 2;
698 +- gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
699 ++ gp = (mod->core_size_rx + mod->core_size_rw) / 2;
700 ++ gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
701 + mod->arch.gp = gp;
702 + DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
703 + }
704 +diff -urNp linux-2.6.27.10/arch/ia64/kernel/sys_ia64.c linux-2.6.27.10/arch/ia64/kernel/sys_ia64.c
705 +--- linux-2.6.27.10/arch/ia64/kernel/sys_ia64.c 2008-11-07 12:55:34.000000000 -0500
706 ++++ linux-2.6.27.10/arch/ia64/kernel/sys_ia64.c 2008-11-18 03:38:43.000000000 -0500
707 +@@ -43,6 +43,13 @@ arch_get_unmapped_area (struct file *fil
708 + if (REGION_NUMBER(addr) == RGN_HPAGE)
709 + addr = 0;
710 + #endif
711 ++
712 ++#ifdef CONFIG_PAX_RANDMMAP
713 ++ if ((mm->pax_flags & MF_PAX_RANDMMAP) && addr && filp)
714 ++ addr = mm->free_area_cache;
715 ++ else
716 ++#endif
717 ++
718 + if (!addr)
719 + addr = mm->free_area_cache;
720 +
721 +@@ -61,9 +68,9 @@ arch_get_unmapped_area (struct file *fil
722 + for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
723 + /* At this point: (!vma || addr < vma->vm_end). */
724 + if (TASK_SIZE - len < addr || RGN_MAP_LIMIT - len < REGION_OFFSET(addr)) {
725 +- if (start_addr != TASK_UNMAPPED_BASE) {
726 ++ if (start_addr != mm->mmap_base) {
727 + /* Start a new search --- just in case we missed some holes. */
728 +- addr = TASK_UNMAPPED_BASE;
729 ++ addr = mm->mmap_base;
730 + goto full_search;
731 + }
732 + return -ENOMEM;
733 +diff -urNp linux-2.6.27.10/arch/ia64/mm/fault.c linux-2.6.27.10/arch/ia64/mm/fault.c
734 +--- linux-2.6.27.10/arch/ia64/mm/fault.c 2008-11-07 12:55:34.000000000 -0500
735 ++++ linux-2.6.27.10/arch/ia64/mm/fault.c 2008-11-18 03:38:43.000000000 -0500
736 +@@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned
737 + return pte_present(pte);
738 + }
739 +
740 ++#ifdef CONFIG_PAX_PAGEEXEC
741 ++void pax_report_insns(void *pc, void *sp)
742 ++{
743 ++ unsigned long i;
744 ++
745 ++ printk(KERN_ERR "PAX: bytes at PC: ");
746 ++ for (i = 0; i < 8; i++) {
747 ++ unsigned int c;
748 ++ if (get_user(c, (unsigned int *)pc+i))
749 ++ printk(KERN_CONT "???????? ");
750 ++ else
751 ++ printk(KERN_CONT "%08x ", c);
752 ++ }
753 ++ printk("\n");
754 ++}
755 ++#endif
756 ++
757 + void __kprobes
758 + ia64_do_page_fault (unsigned long address, unsigned long isr, struct pt_regs *regs)
759 + {
760 +@@ -145,9 +162,23 @@ ia64_do_page_fault (unsigned long addres
761 + mask = ( (((isr >> IA64_ISR_X_BIT) & 1UL) << VM_EXEC_BIT)
762 + | (((isr >> IA64_ISR_W_BIT) & 1UL) << VM_WRITE_BIT));
763 +
764 +- if ((vma->vm_flags & mask) != mask)
765 ++ if ((vma->vm_flags & mask) != mask) {
766 ++
767 ++#ifdef CONFIG_PAX_PAGEEXEC
768 ++ if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
769 ++ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
770 ++ goto bad_area;
771 ++
772 ++ up_read(&mm->mmap_sem);
773 ++ pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
774 ++ do_group_exit(SIGKILL);
775 ++ }
776 ++#endif
777 ++
778 + goto bad_area;
779 +
780 ++ }
781 ++
782 + survive:
783 + /*
784 + * If for any reason at all we couldn't handle the fault, make
785 +diff -urNp linux-2.6.27.10/arch/ia64/mm/init.c linux-2.6.27.10/arch/ia64/mm/init.c
786 +--- linux-2.6.27.10/arch/ia64/mm/init.c 2008-11-07 12:55:34.000000000 -0500
787 ++++ linux-2.6.27.10/arch/ia64/mm/init.c 2008-11-18 03:38:43.000000000 -0500
788 +@@ -122,6 +122,19 @@ ia64_init_addr_space (void)
789 + vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
790 + vma->vm_end = vma->vm_start + PAGE_SIZE;
791 + vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
792 ++
793 ++#ifdef CONFIG_PAX_PAGEEXEC
794 ++ if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
795 ++ vma->vm_flags &= ~VM_EXEC;
796 ++
797 ++#ifdef CONFIG_PAX_MPROTECT
798 ++ if (current->mm->pax_flags & MF_PAX_MPROTECT)
799 ++ vma->vm_flags &= ~VM_MAYEXEC;
800 ++#endif
801 ++
802 ++ }
803 ++#endif
804 ++
805 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
806 + down_write(&current->mm->mmap_sem);
807 + if (insert_vm_struct(current->mm, vma)) {
808 +diff -urNp linux-2.6.27.10/arch/m68knommu/include/asm/kmap_types.h linux-2.6.27.10/arch/m68knommu/include/asm/kmap_types.h
809 +--- linux-2.6.27.10/arch/m68knommu/include/asm/kmap_types.h 2008-11-07 12:55:34.000000000 -0500
810 ++++ linux-2.6.27.10/arch/m68knommu/include/asm/kmap_types.h 2008-11-18 03:39:50.000000000 -0500
811 +@@ -15,6 +15,7 @@ enum km_type {
812 + KM_IRQ1,
813 + KM_SOFTIRQ0,
814 + KM_SOFTIRQ1,
815 ++ KM_CLEARPAGE,
816 + KM_TYPE_NR
817 + };
818 +
819 +diff -urNp linux-2.6.27.10/arch/mips/kernel/binfmt_elfn32.c linux-2.6.27.10/arch/mips/kernel/binfmt_elfn32.c
820 +--- linux-2.6.27.10/arch/mips/kernel/binfmt_elfn32.c 2008-11-07 12:55:34.000000000 -0500
821 ++++ linux-2.6.27.10/arch/mips/kernel/binfmt_elfn32.c 2008-11-18 03:38:43.000000000 -0500
822 +@@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_N
823 + #undef ELF_ET_DYN_BASE
824 + #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
825 +
826 ++#ifdef CONFIG_PAX_ASLR
827 ++#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT_ADDR) ? 0x00400000UL : 0x00400000UL)
828 ++
829 ++#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT_ADDR) ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
830 ++#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT_ADDR) ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
831 ++#endif
832 ++
833 + #include <asm/processor.h>
834 + #include <linux/module.h>
835 + #include <linux/elfcore.h>
836 +diff -urNp linux-2.6.27.10/arch/mips/kernel/binfmt_elfo32.c linux-2.6.27.10/arch/mips/kernel/binfmt_elfo32.c
837 +--- linux-2.6.27.10/arch/mips/kernel/binfmt_elfo32.c 2008-11-07 12:55:34.000000000 -0500
838 ++++ linux-2.6.27.10/arch/mips/kernel/binfmt_elfo32.c 2008-11-18 03:38:43.000000000 -0500
839 +@@ -52,6 +52,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_N
840 + #undef ELF_ET_DYN_BASE
841 + #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
842 +
843 ++#ifdef CONFIG_PAX_ASLR
844 ++#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT_ADDR) ? 0x00400000UL : 0x00400000UL)
845 ++
846 ++#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT_ADDR) ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
847 ++#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT_ADDR) ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
848 ++#endif
849 ++
850 + #include <asm/processor.h>
851 + #include <linux/module.h>
852 + #include <linux/elfcore.h>
853 +diff -urNp linux-2.6.27.10/arch/mips/kernel/process.c linux-2.6.27.10/arch/mips/kernel/process.c
854 +--- linux-2.6.27.10/arch/mips/kernel/process.c 2008-11-07 12:55:34.000000000 -0500
855 ++++ linux-2.6.27.10/arch/mips/kernel/process.c 2008-11-18 03:38:43.000000000 -0500
856 +@@ -458,15 +458,3 @@ unsigned long get_wchan(struct task_stru
857 + out:
858 + return pc;
859 + }
860 +-
861 +-/*
862 +- * Don't forget that the stack pointer must be aligned on a 8 bytes
863 +- * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
864 +- */
865 +-unsigned long arch_align_stack(unsigned long sp)
866 +-{
867 +- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
868 +- sp -= get_random_int() & ~PAGE_MASK;
869 +-
870 +- return sp & ALMASK;
871 +-}
872 +diff -urNp linux-2.6.27.10/arch/mips/kernel/syscall.c linux-2.6.27.10/arch/mips/kernel/syscall.c
873 +--- linux-2.6.27.10/arch/mips/kernel/syscall.c 2008-11-07 12:55:34.000000000 -0500
874 ++++ linux-2.6.27.10/arch/mips/kernel/syscall.c 2008-11-18 03:38:43.000000000 -0500
875 +@@ -100,6 +100,11 @@ unsigned long arch_get_unmapped_area(str
876 + do_color_align = 0;
877 + if (filp || (flags & MAP_SHARED))
878 + do_color_align = 1;
879 ++
880 ++#ifdef CONFIG_PAX_RANDMMAP
881 ++ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP) || !filp)
882 ++#endif
883 ++
884 + if (addr) {
885 + if (do_color_align)
886 + addr = COLOUR_ALIGN(addr, pgoff);
887 +@@ -110,7 +115,7 @@ unsigned long arch_get_unmapped_area(str
888 + (!vmm || addr + len <= vmm->vm_start))
889 + return addr;
890 + }
891 +- addr = TASK_UNMAPPED_BASE;
892 ++ addr = current->mm->mmap_base;
893 + if (do_color_align)
894 + addr = COLOUR_ALIGN(addr, pgoff);
895 + else
896 +diff -urNp linux-2.6.27.10/arch/mips/mm/fault.c linux-2.6.27.10/arch/mips/mm/fault.c
897 +--- linux-2.6.27.10/arch/mips/mm/fault.c 2008-11-07 12:55:34.000000000 -0500
898 ++++ linux-2.6.27.10/arch/mips/mm/fault.c 2008-11-18 03:38:43.000000000 -0500
899 +@@ -26,6 +26,23 @@
900 + #include <asm/ptrace.h>
901 + #include <asm/highmem.h> /* For VMALLOC_END */
902 +
903 ++#ifdef CONFIG_PAX_PAGEEXEC
904 ++void pax_report_insns(void *pc)
905 ++{
906 ++ unsigned long i;
907 ++
908 ++ printk(KERN_ERR "PAX: bytes at PC: ");
909 ++ for (i = 0; i < 5; i++) {
910 ++ unsigned int c;
911 ++ if (get_user(c, (unsigned int *)pc+i))
912 ++ printk(KERN_CONT "???????? ");
913 ++ else
914 ++ printk(KERN_CONT "%08x ", c);
915 ++ }
916 ++ printk("\n");
917 ++}
918 ++#endif
919 ++
920 + /*
921 + * This routine handles page faults. It determines the address,
922 + * and the problem, and then passes it off to one of the appropriate
923 +diff -urNp linux-2.6.27.10/arch/parisc/kernel/module.c linux-2.6.27.10/arch/parisc/kernel/module.c
924 +--- linux-2.6.27.10/arch/parisc/kernel/module.c 2008-11-07 12:55:34.000000000 -0500
925 ++++ linux-2.6.27.10/arch/parisc/kernel/module.c 2008-11-18 03:38:43.000000000 -0500
926 +@@ -75,16 +75,38 @@
927 +
928 + /* three functions to determine where in the module core
929 + * or init pieces the location is */
930 ++static inline int in_init_rx(struct module *me, void *loc)
931 ++{
932 ++ return (loc >= me->module_init_rx &&
933 ++ loc < (me->module_init_rx + me->init_size_rx));
934 ++}
935 ++
936 ++static inline int in_init_rw(struct module *me, void *loc)
937 ++{
938 ++ return (loc >= me->module_init_rw &&
939 ++ loc < (me->module_init_rw + me->init_size_rw));
940 ++}
941 ++
942 + static inline int in_init(struct module *me, void *loc)
943 + {
944 +- return (loc >= me->module_init &&
945 +- loc <= (me->module_init + me->init_size));
946 ++ return in_init_rx(me, loc) || in_init_rw(me, loc);
947 ++}
948 ++
949 ++static inline int in_core_rx(struct module *me, void *loc)
950 ++{
951 ++ return (loc >= me->module_core_rx &&
952 ++ loc < (me->module_core_rx + me->core_size_rx));
953 ++}
954 ++
955 ++static inline int in_core_rw(struct module *me, void *loc)
956 ++{
957 ++ return (loc >= me->module_core_rw &&
958 ++ loc < (me->module_core_rw + me->core_size_rw));
959 + }
960 +
961 + static inline int in_core(struct module *me, void *loc)
962 + {
963 +- return (loc >= me->module_core &&
964 +- loc <= (me->module_core + me->core_size));
965 ++ return in_core_rx(me, loc) || in_core_rw(me, loc);
966 + }
967 +
968 + static inline int in_local(struct module *me, void *loc)
969 +@@ -298,21 +320,21 @@ int module_frob_arch_sections(CONST Elf_
970 + }
971 +
972 + /* align things a bit */
973 +- me->core_size = ALIGN(me->core_size, 16);
974 +- me->arch.got_offset = me->core_size;
975 +- me->core_size += gots * sizeof(struct got_entry);
976 +-
977 +- me->core_size = ALIGN(me->core_size, 16);
978 +- me->arch.fdesc_offset = me->core_size;
979 +- me->core_size += fdescs * sizeof(Elf_Fdesc);
980 +-
981 +- me->core_size = ALIGN(me->core_size, 16);
982 +- me->arch.stub_offset = me->core_size;
983 +- me->core_size += stubs * sizeof(struct stub_entry);
984 +-
985 +- me->init_size = ALIGN(me->init_size, 16);
986 +- me->arch.init_stub_offset = me->init_size;
987 +- me->init_size += init_stubs * sizeof(struct stub_entry);
988 ++ me->core_size_rw = ALIGN(me->core_size_rw, 16);
989 ++ me->arch.got_offset = me->core_size_rw;
990 ++ me->core_size_rw += gots * sizeof(struct got_entry);
991 ++
992 ++ me->core_size_rw = ALIGN(me->core_size_rw, 16);
993 ++ me->arch.fdesc_offset = me->core_size_rw;
994 ++ me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
995 ++
996 ++ me->core_size_rx = ALIGN(me->core_size_rx, 16);
997 ++ me->arch.stub_offset = me->core_size_rx;
998 ++ me->core_size_rx += stubs * sizeof(struct stub_entry);
999 ++
1000 ++ me->init_size_rx = ALIGN(me->init_size_rx, 16);
1001 ++ me->arch.init_stub_offset = me->init_size_rx;
1002 ++ me->init_size_rx += init_stubs * sizeof(struct stub_entry);
1003 +
1004 + me->arch.got_max = gots;
1005 + me->arch.fdesc_max = fdescs;
1006 +@@ -332,7 +354,7 @@ static Elf64_Word get_got(struct module
1007 +
1008 + BUG_ON(value == 0);
1009 +
1010 +- got = me->module_core + me->arch.got_offset;
1011 ++ got = me->module_core_rw + me->arch.got_offset;
1012 + for (i = 0; got[i].addr; i++)
1013 + if (got[i].addr == value)
1014 + goto out;
1015 +@@ -350,7 +372,7 @@ static Elf64_Word get_got(struct module
1016 + #ifdef CONFIG_64BIT
1017 + static Elf_Addr get_fdesc(struct module *me, unsigned long value)
1018 + {
1019 +- Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
1020 ++ Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
1021 +
1022 + if (!value) {
1023 + printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
1024 +@@ -368,7 +390,7 @@ static Elf_Addr get_fdesc(struct module
1025 +
1026 + /* Create new one */
1027 + fdesc->addr = value;
1028 +- fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
1029 ++ fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
1030 + return (Elf_Addr)fdesc;
1031 + }
1032 + #endif /* CONFIG_64BIT */
1033 +@@ -388,12 +410,12 @@ static Elf_Addr get_stub(struct module *
1034 + if(init_section) {
1035 + i = me->arch.init_stub_count++;
1036 + BUG_ON(me->arch.init_stub_count > me->arch.init_stub_max);
1037 +- stub = me->module_init + me->arch.init_stub_offset +
1038 ++ stub = me->module_init_rx + me->arch.init_stub_offset +
1039 + i * sizeof(struct stub_entry);
1040 + } else {
1041 + i = me->arch.stub_count++;
1042 + BUG_ON(me->arch.stub_count > me->arch.stub_max);
1043 +- stub = me->module_core + me->arch.stub_offset +
1044 ++ stub = me->module_core_rx + me->arch.stub_offset +
1045 + i * sizeof(struct stub_entry);
1046 + }
1047 +
1048 +@@ -761,7 +783,7 @@ register_unwind_table(struct module *me,
1049 +
1050 + table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
1051 + end = table + sechdrs[me->arch.unwind_section].sh_size;
1052 +- gp = (Elf_Addr)me->module_core + me->arch.got_offset;
1053 ++ gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
1054 +
1055 + DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
1056 + me->arch.unwind_section, table, end, gp);
1057 +diff -urNp linux-2.6.27.10/arch/parisc/kernel/sys_parisc.c linux-2.6.27.10/arch/parisc/kernel/sys_parisc.c
1058 +--- linux-2.6.27.10/arch/parisc/kernel/sys_parisc.c 2008-11-07 12:55:34.000000000 -0500
1059 ++++ linux-2.6.27.10/arch/parisc/kernel/sys_parisc.c 2008-11-18 03:38:43.000000000 -0500
1060 +@@ -98,7 +98,7 @@ unsigned long arch_get_unmapped_area(str
1061 + if (flags & MAP_FIXED)
1062 + return addr;
1063 + if (!addr)
1064 +- addr = TASK_UNMAPPED_BASE;
1065 ++ addr = current->mm->mmap_base;
1066 +
1067 + if (filp) {
1068 + addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
1069 +diff -urNp linux-2.6.27.10/arch/parisc/kernel/traps.c linux-2.6.27.10/arch/parisc/kernel/traps.c
1070 +--- linux-2.6.27.10/arch/parisc/kernel/traps.c 2008-12-10 22:35:36.000000000 -0500
1071 ++++ linux-2.6.27.10/arch/parisc/kernel/traps.c 2008-12-10 22:35:46.000000000 -0500
1072 +@@ -731,9 +731,7 @@ void handle_interruption(int code, struc
1073 +
1074 + down_read(&current->mm->mmap_sem);
1075 + vma = find_vma(current->mm,regs->iaoq[0]);
1076 +- if (vma && (regs->iaoq[0] >= vma->vm_start)
1077 +- && (vma->vm_flags & VM_EXEC)) {
1078 +-
1079 ++ if (vma && (regs->iaoq[0] >= vma->vm_start)) {
1080 + fault_address = regs->iaoq[0];
1081 + fault_space = regs->iasq[0];
1082 +
1083 +diff -urNp linux-2.6.27.10/arch/parisc/mm/fault.c linux-2.6.27.10/arch/parisc/mm/fault.c
1084 +--- linux-2.6.27.10/arch/parisc/mm/fault.c 2008-11-07 12:55:34.000000000 -0500
1085 ++++ linux-2.6.27.10/arch/parisc/mm/fault.c 2008-11-18 03:38:43.000000000 -0500
1086 +@@ -16,6 +16,7 @@
1087 + #include <linux/sched.h>
1088 + #include <linux/interrupt.h>
1089 + #include <linux/module.h>
1090 ++#include <linux/unistd.h>
1091 +
1092 + #include <asm/uaccess.h>
1093 + #include <asm/traps.h>
1094 +@@ -53,7 +54,7 @@ DEFINE_PER_CPU(struct exception_data, ex
1095 + static unsigned long
1096 + parisc_acctyp(unsigned long code, unsigned int inst)
1097 + {
1098 +- if (code == 6 || code == 16)
1099 ++ if (code == 6 || code == 7 || code == 16)
1100 + return VM_EXEC;
1101 +
1102 + switch (inst & 0xf0000000) {
1103 +@@ -139,6 +140,116 @@ parisc_acctyp(unsigned long code, unsign
1104 + }
1105 + #endif
1106 +
1107 ++#ifdef CONFIG_PAX_PAGEEXEC
1108 ++/*
1109 ++ * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
1110 ++ *
1111 ++ * returns 1 when task should be killed
1112 ++ * 2 when rt_sigreturn trampoline was detected
1113 ++ * 3 when unpatched PLT trampoline was detected
1114 ++ */
1115 ++static int pax_handle_fetch_fault(struct pt_regs *regs)
1116 ++{
1117 ++
1118 ++#ifdef CONFIG_PAX_EMUPLT
1119 ++ int err;
1120 ++
1121 ++ do { /* PaX: unpatched PLT emulation */
1122 ++ unsigned int bl, depwi;
1123 ++
1124 ++ err = get_user(bl, (unsigned int *)instruction_pointer(regs));
1125 ++ err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
1126 ++
1127 ++ if (err)
1128 ++ break;
1129 ++
1130 ++ if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
1131 ++ unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
1132 ++
1133 ++ err = get_user(ldw, (unsigned int *)addr);
1134 ++ err |= get_user(bv, (unsigned int *)(addr+4));
1135 ++ err |= get_user(ldw2, (unsigned int *)(addr+8));
1136 ++
1137 ++ if (err)
1138 ++ break;
1139 ++
1140 ++ if (ldw == 0x0E801096U &&
1141 ++ bv == 0xEAC0C000U &&
1142 ++ ldw2 == 0x0E881095U)
1143 ++ {
1144 ++ unsigned int resolver, map;
1145 ++
1146 ++ err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
1147 ++ err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
1148 ++ if (err)
1149 ++ break;
1150 ++
1151 ++ regs->gr[20] = instruction_pointer(regs)+8;
1152 ++ regs->gr[21] = map;
1153 ++ regs->gr[22] = resolver;
1154 ++ regs->iaoq[0] = resolver | 3UL;
1155 ++ regs->iaoq[1] = regs->iaoq[0] + 4;
1156 ++ return 3;
1157 ++ }
1158 ++ }
1159 ++ } while (0);
1160 ++#endif
1161 ++
1162 ++#ifdef CONFIG_PAX_EMUTRAMP
1163 ++
1164 ++#ifndef CONFIG_PAX_EMUSIGRT
1165 ++ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
1166 ++ return 1;
1167 ++#endif
1168 ++
1169 ++ do { /* PaX: rt_sigreturn emulation */
1170 ++ unsigned int ldi1, ldi2, bel, nop;
1171 ++
1172 ++ err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
1173 ++ err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
1174 ++ err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
1175 ++ err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
1176 ++
1177 ++ if (err)
1178 ++ break;
1179 ++
1180 ++ if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
1181 ++ ldi2 == 0x3414015AU &&
1182 ++ bel == 0xE4008200U &&
1183 ++ nop == 0x08000240U)
1184 ++ {
1185 ++ regs->gr[25] = (ldi1 & 2) >> 1;
1186 ++ regs->gr[20] = __NR_rt_sigreturn;
1187 ++ regs->gr[31] = regs->iaoq[1] + 16;
1188 ++ regs->sr[0] = regs->iasq[1];
1189 ++ regs->iaoq[0] = 0x100UL;
1190 ++ regs->iaoq[1] = regs->iaoq[0] + 4;
1191 ++ regs->iasq[0] = regs->sr[2];
1192 ++ regs->iasq[1] = regs->sr[2];
1193 ++ return 2;
1194 ++ }
1195 ++ } while (0);
1196 ++#endif
1197 ++
1198 ++ return 1;
1199 ++}
1200 ++
1201 ++void pax_report_insns(void *pc, void *sp)
1202 ++{
1203 ++ unsigned long i;
1204 ++
1205 ++ printk(KERN_ERR "PAX: bytes at PC: ");
1206 ++ for (i = 0; i < 5; i++) {
1207 ++ unsigned int c;
1208 ++ if (get_user(c, (unsigned int *)pc+i))
1209 ++ printk(KERN_CONT "???????? ");
1210 ++ else
1211 ++ printk(KERN_CONT "%08x ", c);
1212 ++ }
1213 ++ printk("\n");
1214 ++}
1215 ++#endif
1216 ++
1217 + void do_page_fault(struct pt_regs *regs, unsigned long code,
1218 + unsigned long address)
1219 + {
1220 +@@ -165,8 +276,33 @@ good_area:
1221 +
1222 + acc_type = parisc_acctyp(code,regs->iir);
1223 +
1224 +- if ((vma->vm_flags & acc_type) != acc_type)
1225 ++ if ((vma->vm_flags & acc_type) != acc_type) {
1226 ++
1227 ++#ifdef CONFIG_PAX_PAGEEXEC
1228 ++ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
1229 ++ (address & ~3UL) == instruction_pointer(regs))
1230 ++ {
1231 ++ up_read(&mm->mmap_sem);
1232 ++ switch (pax_handle_fetch_fault(regs)) {
1233 ++
1234 ++#ifdef CONFIG_PAX_EMUPLT
1235 ++ case 3:
1236 ++ return;
1237 ++#endif
1238 ++
1239 ++#ifdef CONFIG_PAX_EMUTRAMP
1240 ++ case 2:
1241 ++ return;
1242 ++#endif
1243 ++
1244 ++ }
1245 ++ pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
1246 ++ do_group_exit(SIGKILL);
1247 ++ }
1248 ++#endif
1249 ++
1250 + goto bad_area;
1251 ++ }
1252 +
1253 + /*
1254 + * If for any reason at all we couldn't handle the fault, make
1255 +diff -urNp linux-2.6.27.10/arch/powerpc/include/asm/elf.h linux-2.6.27.10/arch/powerpc/include/asm/elf.h
1256 +--- linux-2.6.27.10/arch/powerpc/include/asm/elf.h 2008-11-07 12:55:34.000000000 -0500
1257 ++++ linux-2.6.27.10/arch/powerpc/include/asm/elf.h 2008-11-18 03:39:50.000000000 -0500
1258 +@@ -180,6 +180,18 @@ typedef elf_fpreg_t elf_vsrreghalf_t32[E
1259 +
1260 + #define ELF_ET_DYN_BASE (0x20000000)
1261 +
1262 ++#ifdef CONFIG_PAX_ASLR
1263 ++#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
1264 ++
1265 ++#ifdef __powerpc64__
1266 ++#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 16 : 28)
1267 ++#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 16 : 28)
1268 ++#else
1269 ++#define PAX_DELTA_MMAP_LEN 15
1270 ++#define PAX_DELTA_STACK_LEN 15
1271 ++#endif
1272 ++#endif
1273 ++
1274 + /*
1275 + * Our registers are always unsigned longs, whether we're a 32 bit
1276 + * process or 64 bit, on either a 64 bit or 32 bit kernel.
1277 +diff -urNp linux-2.6.27.10/arch/powerpc/include/asm/kmap_types.h linux-2.6.27.10/arch/powerpc/include/asm/kmap_types.h
1278 +--- linux-2.6.27.10/arch/powerpc/include/asm/kmap_types.h 2008-11-07 12:55:34.000000000 -0500
1279 ++++ linux-2.6.27.10/arch/powerpc/include/asm/kmap_types.h 2008-11-18 03:39:50.000000000 -0500
1280 +@@ -26,6 +26,7 @@ enum km_type {
1281 + KM_SOFTIRQ1,
1282 + KM_PPC_SYNC_PAGE,
1283 + KM_PPC_SYNC_ICACHE,
1284 ++ KM_CLEARPAGE,
1285 + KM_TYPE_NR
1286 + };
1287 +
1288 +diff -urNp linux-2.6.27.10/arch/powerpc/include/asm/page_64.h linux-2.6.27.10/arch/powerpc/include/asm/page_64.h
1289 +--- linux-2.6.27.10/arch/powerpc/include/asm/page_64.h 2008-11-07 12:55:34.000000000 -0500
1290 ++++ linux-2.6.27.10/arch/powerpc/include/asm/page_64.h 2008-11-18 03:39:50.000000000 -0500
1291 +@@ -170,15 +170,18 @@ do { \
1292 + * stack by default, so in the absense of a PT_GNU_STACK program header
1293 + * we turn execute permission off.
1294 + */
1295 +-#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
1296 +- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
1297 ++#define VM_STACK_DEFAULT_FLAGS32 \
1298 ++ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
1299 ++ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
1300 +
1301 + #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
1302 + VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
1303 +
1304 ++#ifndef CONFIG_PAX_PAGEEXEC
1305 + #define VM_STACK_DEFAULT_FLAGS \
1306 + (test_thread_flag(TIF_32BIT) ? \
1307 + VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
1308 ++#endif
1309 +
1310 + #include <asm-generic/page.h>
1311 +
1312 +diff -urNp linux-2.6.27.10/arch/powerpc/include/asm/page.h linux-2.6.27.10/arch/powerpc/include/asm/page.h
1313 +--- linux-2.6.27.10/arch/powerpc/include/asm/page.h 2008-11-07 12:55:34.000000000 -0500
1314 ++++ linux-2.6.27.10/arch/powerpc/include/asm/page.h 2008-11-18 03:39:50.000000000 -0500
1315 +@@ -100,8 +100,9 @@ extern phys_addr_t kernstart_addr;
1316 + * and needs to be executable. This means the whole heap ends
1317 + * up being executable.
1318 + */
1319 +-#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
1320 +- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
1321 ++#define VM_DATA_DEFAULT_FLAGS32 \
1322 ++ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
1323 ++ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
1324 +
1325 + #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
1326 + VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
1327 +diff -urNp linux-2.6.27.10/arch/powerpc/kernel/module_32.c linux-2.6.27.10/arch/powerpc/kernel/module_32.c
1328 +--- linux-2.6.27.10/arch/powerpc/kernel/module_32.c 2008-11-07 12:55:34.000000000 -0500
1329 ++++ linux-2.6.27.10/arch/powerpc/kernel/module_32.c 2008-11-18 03:38:43.000000000 -0500
1330 +@@ -158,7 +158,7 @@ int module_frob_arch_sections(Elf32_Ehdr
1331 + me->arch.core_plt_section = i;
1332 + }
1333 + if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
1334 +- printk("Module doesn't contain .plt or .init.plt sections.\n");
1335 ++ printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
1336 + return -ENOEXEC;
1337 + }
1338 +
1339 +@@ -199,11 +199,16 @@ static uint32_t do_plt_call(void *locati
1340 +
1341 + DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
1342 + /* Init, or core PLT? */
1343 +- if (location >= mod->module_core
1344 +- && location < mod->module_core + mod->core_size)
1345 ++ if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
1346 ++ (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
1347 + entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
1348 +- else
1349 ++ else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
1350 ++ (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
1351 + entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
1352 ++ else {
1353 ++ printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
1354 ++ return ~0UL;
1355 ++ }
1356 +
1357 + /* Find this entry, or if that fails, the next avail. entry */
1358 + while (entry->jump[0]) {
1359 +diff -urNp linux-2.6.27.10/arch/powerpc/kernel/signal_32.c linux-2.6.27.10/arch/powerpc/kernel/signal_32.c
1360 +--- linux-2.6.27.10/arch/powerpc/kernel/signal_32.c 2008-11-07 12:55:34.000000000 -0500
1361 ++++ linux-2.6.27.10/arch/powerpc/kernel/signal_32.c 2008-11-18 03:38:43.000000000 -0500
1362 +@@ -857,7 +857,7 @@ int handle_rt_signal32(unsigned long sig
1363 + /* Save user registers on the stack */
1364 + frame = &rt_sf->uc.uc_mcontext;
1365 + addr = frame;
1366 +- if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
1367 ++ if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
1368 + if (save_user_regs(regs, frame, 0))
1369 + goto badframe;
1370 + regs->link = current->mm->context.vdso_base + vdso32_rt_sigtramp;
1371 +diff -urNp linux-2.6.27.10/arch/powerpc/kernel/signal_64.c linux-2.6.27.10/arch/powerpc/kernel/signal_64.c
1372 +--- linux-2.6.27.10/arch/powerpc/kernel/signal_64.c 2008-11-07 12:55:34.000000000 -0500
1373 ++++ linux-2.6.27.10/arch/powerpc/kernel/signal_64.c 2008-11-18 03:38:43.000000000 -0500
1374 +@@ -434,7 +434,7 @@ int handle_rt_signal64(int signr, struct
1375 + current->thread.fpscr.val = 0;
1376 +
1377 + /* Set up to return from userspace. */
1378 +- if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
1379 ++ if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
1380 + regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
1381 + } else {
1382 + err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
1383 +diff -urNp linux-2.6.27.10/arch/powerpc/kernel/vdso.c linux-2.6.27.10/arch/powerpc/kernel/vdso.c
1384 +--- linux-2.6.27.10/arch/powerpc/kernel/vdso.c 2008-11-07 12:55:34.000000000 -0500
1385 ++++ linux-2.6.27.10/arch/powerpc/kernel/vdso.c 2008-11-18 03:38:43.000000000 -0500
1386 +@@ -212,7 +212,7 @@ int arch_setup_additional_pages(struct l
1387 + vdso_base = VDSO32_MBASE;
1388 + #endif
1389 +
1390 +- current->mm->context.vdso_base = 0;
1391 ++ current->mm->context.vdso_base = ~0UL;
1392 +
1393 + /* vDSO has a problem and was disabled, just don't "enable" it for the
1394 + * process
1395 +@@ -229,7 +229,7 @@ int arch_setup_additional_pages(struct l
1396 + */
1397 + down_write(&mm->mmap_sem);
1398 + vdso_base = get_unmapped_area(NULL, vdso_base,
1399 +- vdso_pages << PAGE_SHIFT, 0, 0);
1400 ++ vdso_pages << PAGE_SHIFT, 0, MAP_PRIVATE | MAP_EXECUTABLE);
1401 + if (IS_ERR_VALUE(vdso_base)) {
1402 + rc = vdso_base;
1403 + goto fail_mmapsem;
1404 +diff -urNp linux-2.6.27.10/arch/powerpc/mm/fault.c linux-2.6.27.10/arch/powerpc/mm/fault.c
1405 +--- linux-2.6.27.10/arch/powerpc/mm/fault.c 2008-11-07 12:55:34.000000000 -0500
1406 ++++ linux-2.6.27.10/arch/powerpc/mm/fault.c 2008-11-18 03:38:43.000000000 -0500
1407 +@@ -29,6 +29,10 @@
1408 + #include <linux/module.h>
1409 + #include <linux/kprobes.h>
1410 + #include <linux/kdebug.h>
1411 ++#include <linux/slab.h>
1412 ++#include <linux/pagemap.h>
1413 ++#include <linux/compiler.h>
1414 ++#include <linux/unistd.h>
1415 +
1416 + #include <asm/page.h>
1417 + #include <asm/pgtable.h>
1418 +@@ -62,6 +66,363 @@ static inline int notify_page_fault(stru
1419 + }
1420 + #endif
1421 +
1422 ++#ifdef CONFIG_PAX_EMUSIGRT
1423 ++void pax_syscall_close(struct vm_area_struct *vma)
1424 ++{
1425 ++ vma->vm_mm->call_syscall = 0UL;
1426 ++}
1427 ++
1428 ++static int pax_syscall_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
1429 ++{
1430 ++ unsigned int *kaddr;
1431 ++
1432 ++ vmf->page = alloc_page(GFP_HIGHUSER);
1433 ++ if (!vmf->page)
1434 ++ return VM_FAULT_OOM;
1435 ++
1436 ++ kaddr = kmap(vmf->page);
1437 ++ memset(kaddr, 0, PAGE_SIZE);
1438 ++ kaddr[0] = 0x44000002U; /* sc */
1439 ++ __flush_dcache_icache(kaddr);
1440 ++ kunmap(vmf->page);
1441 ++ return VM_FAULT_MAJOR;
1442 ++}
1443 ++
1444 ++static struct vm_operations_struct pax_vm_ops = {
1445 ++ .close = pax_syscall_close,
1446 ++ .fault = pax_syscall_fault
1447 ++};
1448 ++
1449 ++static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
1450 ++{
1451 ++ int ret;
1452 ++
1453 ++ vma->vm_mm = current->mm;
1454 ++ vma->vm_start = addr;
1455 ++ vma->vm_end = addr + PAGE_SIZE;
1456 ++ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
1457 ++ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
1458 ++ vma->vm_ops = &pax_vm_ops;
1459 ++
1460 ++ ret = insert_vm_struct(current->mm, vma);
1461 ++ if (ret)
1462 ++ return ret;
1463 ++
1464 ++ ++current->mm->total_vm;
1465 ++ return 0;
1466 ++}
1467 ++#endif
1468 ++
1469 ++#ifdef CONFIG_PAX_PAGEEXEC
1470 ++/*
1471 ++ * PaX: decide what to do with offenders (regs->nip = fault address)
1472 ++ *
1473 ++ * returns 1 when task should be killed
1474 ++ * 2 when patched GOT trampoline was detected
1475 ++ * 3 when patched PLT trampoline was detected
1476 ++ * 4 when unpatched PLT trampoline was detected
1477 ++ * 5 when sigreturn trampoline was detected
1478 ++ * 6 when rt_sigreturn trampoline was detected
1479 ++ */
1480 ++static int pax_handle_fetch_fault(struct pt_regs *regs)
1481 ++{
1482 ++
1483 ++#if defined(CONFIG_PAX_EMUPLT) || defined(CONFIG_PAX_EMUSIGRT)
1484 ++ int err;
1485 ++#endif
1486 ++
1487 ++#ifdef CONFIG_PAX_EMUPLT
1488 ++ do { /* PaX: patched GOT emulation */
1489 ++ unsigned int blrl;
1490 ++
1491 ++ err = get_user(blrl, (unsigned int *)regs->nip);
1492 ++
1493 ++ if (!err && blrl == 0x4E800021U) {
1494 ++ unsigned long temp = regs->nip;
1495 ++
1496 ++ regs->nip = regs->link & 0xFFFFFFFCUL;
1497 ++ regs->link = temp + 4UL;
1498 ++ return 2;
1499 ++ }
1500 ++ } while (0);
1501 ++
1502 ++ do { /* PaX: patched PLT emulation #1 */
1503 ++ unsigned int b;
1504 ++
1505 ++ err = get_user(b, (unsigned int *)regs->nip);
1506 ++
1507 ++ if (!err && (b & 0xFC000003U) == 0x48000000U) {
1508 ++ regs->nip += (((b | 0xFC000000UL) ^ 0x02000000UL) + 0x02000000UL);
1509 ++ return 3;
1510 ++ }
1511 ++ } while (0);
1512 ++
1513 ++ do { /* PaX: unpatched PLT emulation #1 */
1514 ++ unsigned int li, b;
1515 ++
1516 ++ err = get_user(li, (unsigned int *)regs->nip);
1517 ++ err |= get_user(b, (unsigned int *)(regs->nip+4));
1518 ++
1519 ++ if (!err && (li & 0xFFFF0000U) == 0x39600000U && (b & 0xFC000003U) == 0x48000000U) {
1520 ++ unsigned int rlwinm, add, li2, addis2, mtctr, li3, addis3, bctr;
1521 ++ unsigned long addr = b | 0xFC000000UL;
1522 ++
1523 ++ addr = regs->nip + 4 + ((addr ^ 0x02000000UL) + 0x02000000UL);
1524 ++ err = get_user(rlwinm, (unsigned int *)addr);
1525 ++ err |= get_user(add, (unsigned int *)(addr+4));
1526 ++ err |= get_user(li2, (unsigned int *)(addr+8));
1527 ++ err |= get_user(addis2, (unsigned int *)(addr+12));
1528 ++ err |= get_user(mtctr, (unsigned int *)(addr+16));
1529 ++ err |= get_user(li3, (unsigned int *)(addr+20));
1530 ++ err |= get_user(addis3, (unsigned int *)(addr+24));
1531 ++ err |= get_user(bctr, (unsigned int *)(addr+28));
1532 ++
1533 ++ if (err)
1534 ++ break;
1535 ++
1536 ++ if (rlwinm == 0x556C083CU &&
1537 ++ add == 0x7D6C5A14U &&
1538 ++ (li2 & 0xFFFF0000U) == 0x39800000U &&
1539 ++ (addis2 & 0xFFFF0000U) == 0x3D8C0000U &&
1540 ++ mtctr == 0x7D8903A6U &&
1541 ++ (li3 & 0xFFFF0000U) == 0x39800000U &&
1542 ++ (addis3 & 0xFFFF0000U) == 0x3D8C0000U &&
1543 ++ bctr == 0x4E800420U)
1544 ++ {
1545 ++ regs->gpr[PT_R11] = 3 * (((li | 0xFFFF0000UL) ^ 0x00008000UL) + 0x00008000UL);
1546 ++ regs->gpr[PT_R12] = (((li3 | 0xFFFF0000UL) ^ 0x00008000UL) + 0x00008000UL);
1547 ++ regs->gpr[PT_R12] += (addis3 & 0xFFFFU) << 16;
1548 ++ regs->ctr = (((li2 | 0xFFFF0000UL) ^ 0x00008000UL) + 0x00008000UL);
1549 ++ regs->ctr += (addis2 & 0xFFFFU) << 16;
1550 ++ regs->nip = regs->ctr;
1551 ++ return 4;
1552 ++ }
1553 ++ }
1554 ++ } while (0);
1555 ++
1556 ++#if 0
1557 ++ do { /* PaX: unpatched PLT emulation #2 */
1558 ++ unsigned int lis, lwzu, b, bctr;
1559 ++
1560 ++ err = get_user(lis, (unsigned int *)regs->nip);
1561 ++ err |= get_user(lwzu, (unsigned int *)(regs->nip+4));
1562 ++ err |= get_user(b, (unsigned int *)(regs->nip+8));
1563 ++ err |= get_user(bctr, (unsigned int *)(regs->nip+12));
1564 ++
1565 ++ if (err)
1566 ++ break;
1567 ++
1568 ++ if ((lis & 0xFFFF0000U) == 0x39600000U &&
1569 ++ (lwzu & 0xU) == 0xU &&
1570 ++ (b & 0xFC000003U) == 0x48000000U &&
1571 ++ bctr == 0x4E800420U)
1572 ++ {
1573 ++ unsigned int addis, addi, rlwinm, add, li2, addis2, mtctr, li3, addis3, bctr;
1574 ++ unsigned long addr = b | 0xFC000000UL;
1575 ++
1576 ++ addr = regs->nip + 12 + ((addr ^ 0x02000000UL) + 0x02000000UL);
1577 ++ err = get_user(addis, (unsigned int *)addr);
1578 ++ err |= get_user(addi, (unsigned int *)(addr+4));
1579 ++ err |= get_user(rlwinm, (unsigned int *)(addr+8));
1580 ++ err |= get_user(add, (unsigned int *)(addr+12));
1581 ++ err |= get_user(li2, (unsigned int *)(addr+16));
1582 ++ err |= get_user(addis2, (unsigned int *)(addr+20));
1583 ++ err |= get_user(mtctr, (unsigned int *)(addr+24));
1584 ++ err |= get_user(li3, (unsigned int *)(addr+28));
1585 ++ err |= get_user(addis3, (unsigned int *)(addr+32));
1586 ++ err |= get_user(bctr, (unsigned int *)(addr+36));
1587 ++
1588 ++ if (err)
1589 ++ break;
1590 ++
1591 ++ if ((addis & 0xFFFF0000U) == 0x3D6B0000U &&
1592 ++ (addi & 0xFFFF0000U) == 0x396B0000U &&
1593 ++ rlwinm == 0x556C083CU &&
1594 ++ add == 0x7D6C5A14U &&
1595 ++ (li2 & 0xFFFF0000U) == 0x39800000U &&
1596 ++ (addis2 & 0xFFFF0000U) == 0x3D8C0000U &&
1597 ++ mtctr == 0x7D8903A6U &&
1598 ++ (li3 & 0xFFFF0000U) == 0x39800000U &&
1599 ++ (addis3 & 0xFFFF0000U) == 0x3D8C0000U &&
1600 ++ bctr == 0x4E800420U)
1601 ++ {
1602 ++ regs->gpr[PT_R11] = 3 * (((li | 0xFFFF0000UL) ^ 0x00008000UL) + 0x00008000UL);
1603 ++ regs->gpr[PT_R12] = (((li3 | 0xFFFF0000UL) ^ 0x00008000UL) + 0x00008000UL);
1604 ++ regs->gpr[PT_R12] += (addis3 & 0xFFFFU) << 16;
1605 ++ regs->ctr = (((li2 | 0xFFFF0000UL) ^ 0x00008000UL) + 0x00008000UL);
1606 ++ regs->ctr += (addis2 & 0xFFFFU) << 16;
1607 ++ regs->nip = regs->ctr;
1608 ++ return 4;
1609 ++ }
1610 ++ }
1611 ++ } while (0);
1612 ++#endif
1613 ++
1614 ++ do { /* PaX: unpatched PLT emulation #3 */
1615 ++ unsigned int li, b;
1616 ++
1617 ++ err = get_user(li, (unsigned int *)regs->nip);
1618 ++ err |= get_user(b, (unsigned int *)(regs->nip+4));
1619 ++
1620 ++ if (!err && (li & 0xFFFF0000U) == 0x39600000U && (b & 0xFC000003U) == 0x48000000U) {
1621 ++ unsigned int addis, lwz, mtctr, bctr;
1622 ++ unsigned long addr = b | 0xFC000000UL;
1623 ++
1624 ++ addr = regs->nip + 4 + ((addr ^ 0x02000000UL) + 0x02000000UL);
1625 ++ err = get_user(addis, (unsigned int *)addr);
1626 ++ err |= get_user(lwz, (unsigned int *)(addr+4));
1627 ++ err |= get_user(mtctr, (unsigned int *)(addr+8));
1628 ++ err |= get_user(bctr, (unsigned int *)(addr+12));
1629 ++
1630 ++ if (err)
1631 ++ break;
1632 ++
1633 ++ if ((addis & 0xFFFF0000U) == 0x3D6B0000U &&
1634 ++ (lwz & 0xFFFF0000U) == 0x816B0000U &&
1635 ++ mtctr == 0x7D6903A6U &&
1636 ++ bctr == 0x4E800420U)
1637 ++ {
1638 ++ unsigned int r11;
1639 ++
1640 ++ addr = (addis << 16) + (((li | 0xFFFF0000UL) ^ 0x00008000UL) + 0x00008000UL);
1641 ++ addr += (((lwz | 0xFFFF0000UL) ^ 0x00008000UL) + 0x00008000UL);
1642 ++
1643 ++ err = get_user(r11, (unsigned int *)addr);
1644 ++ if (err)
1645 ++ break;
1646 ++
1647 ++ regs->gpr[PT_R11] = r11;
1648 ++ regs->ctr = r11;
1649 ++ regs->nip = r11;
1650 ++ return 4;
1651 ++ }
1652 ++ }
1653 ++ } while (0);
1654 ++#endif
1655 ++
1656 ++#ifdef CONFIG_PAX_EMUSIGRT
1657 ++ do { /* PaX: sigreturn emulation */
1658 ++ unsigned int li, sc;
1659 ++
1660 ++ err = get_user(li, (unsigned int *)regs->nip);
1661 ++ err |= get_user(sc, (unsigned int *)(regs->nip+4));
1662 ++
1663 ++ if (!err && li == 0x38000000U + __NR_sigreturn && sc == 0x44000002U) {
1664 ++ struct vm_area_struct *vma;
1665 ++ unsigned long call_syscall;
1666 ++
1667 ++ down_read(&current->mm->mmap_sem);
1668 ++ call_syscall = current->mm->call_syscall;
1669 ++ up_read(&current->mm->mmap_sem);
1670 ++ if (likely(call_syscall))
1671 ++ goto emulate;
1672 ++
1673 ++ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
1674 ++
1675 ++ down_write(&current->mm->mmap_sem);
1676 ++ if (current->mm->call_syscall) {
1677 ++ call_syscall = current->mm->call_syscall;
1678 ++ up_write(&current->mm->mmap_sem);
1679 ++ if (vma)
1680 ++ kmem_cache_free(vm_area_cachep, vma);
1681 ++ goto emulate;
1682 ++ }
1683 ++
1684 ++ call_syscall = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
1685 ++ if (!vma || (call_syscall & ~PAGE_MASK)) {
1686 ++ up_write(&current->mm->mmap_sem);
1687 ++ if (vma)
1688 ++ kmem_cache_free(vm_area_cachep, vma);
1689 ++ return 1;
1690 ++ }
1691 ++
1692 ++ if (pax_insert_vma(vma, call_syscall)) {
1693 ++ up_write(&current->mm->mmap_sem);
1694 ++ kmem_cache_free(vm_area_cachep, vma);
1695 ++ return 1;
1696 ++ }
1697 ++
1698 ++ current->mm->call_syscall = call_syscall;
1699 ++ up_write(&current->mm->mmap_sem);
1700 ++
1701 ++emulate:
1702 ++ regs->gpr[PT_R0] = __NR_sigreturn;
1703 ++ regs->nip = call_syscall;
1704 ++ return 5;
1705 ++ }
1706 ++ } while (0);
1707 ++
1708 ++ do { /* PaX: rt_sigreturn emulation */
1709 ++ unsigned int li, sc;
1710 ++
1711 ++ err = get_user(li, (unsigned int *)regs->nip);
1712 ++ err |= get_user(sc, (unsigned int *)(regs->nip+4));
1713 ++
1714 ++ if (!err && li == 0x38000000U + __NR_rt_sigreturn && sc == 0x44000002U) {
1715 ++ struct vm_area_struct *vma;
1716 ++ unsigned int call_syscall;
1717 ++
1718 ++ down_read(&current->mm->mmap_sem);
1719 ++ call_syscall = current->mm->call_syscall;
1720 ++ up_read(&current->mm->mmap_sem);
1721 ++ if (likely(call_syscall))
1722 ++ goto rt_emulate;
1723 ++
1724 ++ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
1725 ++
1726 ++ down_write(&current->mm->mmap_sem);
1727 ++ if (current->mm->call_syscall) {
1728 ++ call_syscall = current->mm->call_syscall;
1729 ++ up_write(&current->mm->mmap_sem);
1730 ++ if (vma)
1731 ++ kmem_cache_free(vm_area_cachep, vma);
1732 ++ goto rt_emulate;
1733 ++ }
1734 ++
1735 ++ call_syscall = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
1736 ++ if (!vma || (call_syscall & ~PAGE_MASK)) {
1737 ++ up_write(&current->mm->mmap_sem);
1738 ++ if (vma)
1739 ++ kmem_cache_free(vm_area_cachep, vma);
1740 ++ return 1;
1741 ++ }
1742 ++
1743 ++ if (pax_insert_vma(vma, call_syscall)) {
1744 ++ up_write(&current->mm->mmap_sem);
1745 ++ kmem_cache_free(vm_area_cachep, vma);
1746 ++ return 1;
1747 ++ }
1748 ++
1749 ++ current->mm->call_syscall = call_syscall;
1750 ++ up_write(&current->mm->mmap_sem);
1751 ++
1752 ++rt_emulate:
1753 ++ regs->gpr[PT_R0] = __NR_rt_sigreturn;
1754 ++ regs->nip = call_syscall;
1755 ++ return 6;
1756 ++ }
1757 ++ } while (0);
1758 ++#endif
1759 ++
1760 ++ return 1;
1761 ++}
1762 ++
1763 ++void pax_report_insns(void *pc, void *sp)
1764 ++{
1765 ++ unsigned long i;
1766 ++
1767 ++ printk(KERN_ERR "PAX: bytes at PC: ");
1768 ++ for (i = 0; i < 5; i++) {
1769 ++ unsigned int c;
1770 ++ if (get_user(c, (unsigned int *)pc+i))
1771 ++ printk(KERN_CONT "???????? ");
1772 ++ else
1773 ++ printk(KERN_CONT "%08x ", c);
1774 ++ }
1775 ++ printk("\n");
1776 ++}
1777 ++#endif
1778 ++
1779 + /*
1780 + * Check whether the instruction at regs->nip is a store using
1781 + * an update addressing form which will update r1.
1782 +@@ -132,7 +493,7 @@ int __kprobes do_page_fault(struct pt_re
1783 + * indicate errors in DSISR but can validly be set in SRR1.
1784 + */
1785 + if (trap == 0x400)
1786 +- error_code &= 0x48200000;
1787 ++ error_code &= 0x58200000;
1788 + else
1789 + is_write = error_code & DSISR_ISSTORE;
1790 + #else
1791 +@@ -331,6 +692,37 @@ bad_area:
1792 + bad_area_nosemaphore:
1793 + /* User mode accesses cause a SIGSEGV */
1794 + if (user_mode(regs)) {
1795 ++
1796 ++#ifdef CONFIG_PAX_PAGEEXEC
1797 ++ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
1798 ++#ifdef CONFIG_PPC64
1799 ++ if (is_exec && (error_code & DSISR_PROTFAULT)) {
1800 ++#else
1801 ++ if (is_exec && regs->nip == address) {
1802 ++#endif
1803 ++ switch (pax_handle_fetch_fault(regs)) {
1804 ++
1805 ++#ifdef CONFIG_PAX_EMUPLT
1806 ++ case 2:
1807 ++ case 3:
1808 ++ case 4:
1809 ++ return 0;
1810 ++#endif
1811 ++
1812 ++#ifdef CONFIG_PAX_EMUSIGRT
1813 ++ case 5:
1814 ++ case 6:
1815 ++ return 0;
1816 ++#endif
1817 ++
1818 ++ }
1819 ++
1820 ++ pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
1821 ++ do_group_exit(SIGKILL);
1822 ++ }
1823 ++ }
1824 ++#endif
1825 ++
1826 + _exception(SIGSEGV, regs, code, address);
1827 + return 0;
1828 + }
1829 +diff -urNp linux-2.6.27.10/arch/powerpc/mm/mmap.c linux-2.6.27.10/arch/powerpc/mm/mmap.c
1830 +--- linux-2.6.27.10/arch/powerpc/mm/mmap.c 2008-11-07 12:55:34.000000000 -0500
1831 ++++ linux-2.6.27.10/arch/powerpc/mm/mmap.c 2008-11-18 03:38:43.000000000 -0500
1832 +@@ -75,10 +75,22 @@ void arch_pick_mmap_layout(struct mm_str
1833 + */
1834 + if (mmap_is_legacy()) {
1835 + mm->mmap_base = TASK_UNMAPPED_BASE;
1836 ++
1837 ++#ifdef CONFIG_PAX_RANDMMAP
1838 ++ if (mm->pax_flags & MF_PAX_RANDMMAP)
1839 ++ mm->mmap_base += mm->delta_mmap;
1840 ++#endif
1841 ++
1842 + mm->get_unmapped_area = arch_get_unmapped_area;
1843 + mm->unmap_area = arch_unmap_area;
1844 + } else {
1845 + mm->mmap_base = mmap_base();
1846 ++
1847 ++#ifdef CONFIG_PAX_RANDMMAP
1848 ++ if (mm->pax_flags & MF_PAX_RANDMMAP)
1849 ++ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
1850 ++#endif
1851 ++
1852 + mm->get_unmapped_area = arch_get_unmapped_area_topdown;
1853 + mm->unmap_area = arch_unmap_area_topdown;
1854 + }
1855 +diff -urNp linux-2.6.27.10/arch/s390/include/asm/kmap_types.h linux-2.6.27.10/arch/s390/include/asm/kmap_types.h
1856 +--- linux-2.6.27.10/arch/s390/include/asm/kmap_types.h 2008-11-07 12:55:34.000000000 -0500
1857 ++++ linux-2.6.27.10/arch/s390/include/asm/kmap_types.h 2008-11-18 03:39:50.000000000 -0500
1858 +@@ -16,6 +16,7 @@ enum km_type {
1859 + KM_IRQ1,
1860 + KM_SOFTIRQ0,
1861 + KM_SOFTIRQ1,
1862 ++ KM_CLEARPAGE,
1863 + KM_TYPE_NR
1864 + };
1865 +
1866 +diff -urNp linux-2.6.27.10/arch/s390/kernel/module.c linux-2.6.27.10/arch/s390/kernel/module.c
1867 +--- linux-2.6.27.10/arch/s390/kernel/module.c 2008-11-07 12:55:34.000000000 -0500
1868 ++++ linux-2.6.27.10/arch/s390/kernel/module.c 2008-11-18 03:38:43.000000000 -0500
1869 +@@ -166,11 +166,11 @@ module_frob_arch_sections(Elf_Ehdr *hdr,
1870 +
1871 + /* Increase core size by size of got & plt and set start
1872 + offsets for got and plt. */
1873 +- me->core_size = ALIGN(me->core_size, 4);
1874 +- me->arch.got_offset = me->core_size;
1875 +- me->core_size += me->arch.got_size;
1876 +- me->arch.plt_offset = me->core_size;
1877 +- me->core_size += me->arch.plt_size;
1878 ++ me->core_size_rw = ALIGN(me->core_size_rw, 4);
1879 ++ me->arch.got_offset = me->core_size_rw;
1880 ++ me->core_size_rw += me->arch.got_size;
1881 ++ me->arch.plt_offset = me->core_size_rx;
1882 ++ me->core_size_rx += me->arch.plt_size;
1883 + return 0;
1884 + }
1885 +
1886 +@@ -256,7 +256,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base
1887 + if (info->got_initialized == 0) {
1888 + Elf_Addr *gotent;
1889 +
1890 +- gotent = me->module_core + me->arch.got_offset +
1891 ++ gotent = me->module_core_rw + me->arch.got_offset +
1892 + info->got_offset;
1893 + *gotent = val;
1894 + info->got_initialized = 1;
1895 +@@ -280,7 +280,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base
1896 + else if (r_type == R_390_GOTENT ||
1897 + r_type == R_390_GOTPLTENT)
1898 + *(unsigned int *) loc =
1899 +- (val + (Elf_Addr) me->module_core - loc) >> 1;
1900 ++ (val + (Elf_Addr) me->module_core_rw - loc) >> 1;
1901 + else if (r_type == R_390_GOT64 ||
1902 + r_type == R_390_GOTPLT64)
1903 + *(unsigned long *) loc = val;
1904 +@@ -294,7 +294,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base
1905 + case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
1906 + if (info->plt_initialized == 0) {
1907 + unsigned int *ip;
1908 +- ip = me->module_core + me->arch.plt_offset +
1909 ++ ip = me->module_core_rx + me->arch.plt_offset +
1910 + info->plt_offset;
1911 + #ifndef CONFIG_64BIT
1912 + ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
1913 +@@ -316,7 +316,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base
1914 + val = me->arch.plt_offset - me->arch.got_offset +
1915 + info->plt_offset + rela->r_addend;
1916 + else
1917 +- val = (Elf_Addr) me->module_core +
1918 ++ val = (Elf_Addr) me->module_core_rx +
1919 + me->arch.plt_offset + info->plt_offset +
1920 + rela->r_addend - loc;
1921 + if (r_type == R_390_PLT16DBL)
1922 +@@ -336,7 +336,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base
1923 + case R_390_GOTOFF32: /* 32 bit offset to GOT. */
1924 + case R_390_GOTOFF64: /* 64 bit offset to GOT. */
1925 + val = val + rela->r_addend -
1926 +- ((Elf_Addr) me->module_core + me->arch.got_offset);
1927 ++ ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
1928 + if (r_type == R_390_GOTOFF16)
1929 + *(unsigned short *) loc = val;
1930 + else if (r_type == R_390_GOTOFF32)
1931 +@@ -346,7 +346,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base
1932 + break;
1933 + case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
1934 + case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
1935 +- val = (Elf_Addr) me->module_core + me->arch.got_offset +
1936 ++ val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
1937 + rela->r_addend - loc;
1938 + if (r_type == R_390_GOTPC)
1939 + *(unsigned int *) loc = val;
1940 +diff -urNp linux-2.6.27.10/arch/sh/include/asm/kmap_types.h linux-2.6.27.10/arch/sh/include/asm/kmap_types.h
1941 +--- linux-2.6.27.10/arch/sh/include/asm/kmap_types.h 2008-11-07 12:55:34.000000000 -0500
1942 ++++ linux-2.6.27.10/arch/sh/include/asm/kmap_types.h 2008-11-18 03:39:50.000000000 -0500
1943 +@@ -24,7 +24,8 @@ D(9) KM_IRQ0,
1944 + D(10) KM_IRQ1,
1945 + D(11) KM_SOFTIRQ0,
1946 + D(12) KM_SOFTIRQ1,
1947 +-D(13) KM_TYPE_NR
1948 ++D(13) KM_CLEARPAGE,
1949 ++D(14) KM_TYPE_NR
1950 + };
1951 +
1952 + #undef D
1953 +diff -urNp linux-2.6.27.10/arch/sparc/include/asm/elf_32.h linux-2.6.27.10/arch/sparc/include/asm/elf_32.h
1954 +--- linux-2.6.27.10/arch/sparc/include/asm/elf_32.h 2008-11-07 12:55:34.000000000 -0500
1955 ++++ linux-2.6.27.10/arch/sparc/include/asm/elf_32.h 2008-11-18 03:39:50.000000000 -0500
1956 +@@ -119,6 +119,13 @@ typedef struct {
1957 +
1958 + #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
1959 +
1960 ++#ifdef CONFIG_PAX_ASLR
1961 ++#define PAX_ELF_ET_DYN_BASE 0x10000UL
1962 ++
1963 ++#define PAX_DELTA_MMAP_LEN 16
1964 ++#define PAX_DELTA_STACK_LEN 16
1965 ++#endif
1966 ++
1967 + /* This yields a mask that user programs can use to figure out what
1968 + instruction set this cpu supports. This can NOT be done in userspace
1969 + on Sparc. */
1970 +diff -urNp linux-2.6.27.10/arch/sparc/include/asm/elf_64.h linux-2.6.27.10/arch/sparc/include/asm/elf_64.h
1971 +--- linux-2.6.27.10/arch/sparc/include/asm/elf_64.h 2008-11-07 12:55:34.000000000 -0500
1972 ++++ linux-2.6.27.10/arch/sparc/include/asm/elf_64.h 2008-11-18 03:39:50.000000000 -0500
1973 +@@ -163,6 +163,12 @@ typedef struct {
1974 + #define ELF_ET_DYN_BASE 0x0000010000000000UL
1975 + #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
1976 +
1977 ++#ifdef CONFIG_PAX_ASLR
1978 ++#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
1979 ++
1980 ++#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28 )
1981 ++#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29 )
1982 ++#endif
1983 +
1984 + /* This yields a mask that user programs can use to figure out what
1985 + instruction set this cpu supports. */
1986 +diff -urNp linux-2.6.27.10/arch/sparc/include/asm/kmap_types.h linux-2.6.27.10/arch/sparc/include/asm/kmap_types.h
1987 +--- linux-2.6.27.10/arch/sparc/include/asm/kmap_types.h 2008-11-07 12:55:34.000000000 -0500
1988 ++++ linux-2.6.27.10/arch/sparc/include/asm/kmap_types.h 2008-11-18 03:39:50.000000000 -0500
1989 +@@ -19,6 +19,7 @@ enum km_type {
1990 + KM_IRQ1,
1991 + KM_SOFTIRQ0,
1992 + KM_SOFTIRQ1,
1993 ++ KM_CLEARPAGE,
1994 + KM_TYPE_NR
1995 + };
1996 +
1997 +diff -urNp linux-2.6.27.10/arch/sparc/include/asm/pgtable_32.h linux-2.6.27.10/arch/sparc/include/asm/pgtable_32.h
1998 +--- linux-2.6.27.10/arch/sparc/include/asm/pgtable_32.h 2008-11-07 12:55:34.000000000 -0500
1999 ++++ linux-2.6.27.10/arch/sparc/include/asm/pgtable_32.h 2008-11-18 03:39:50.000000000 -0500
2000 +@@ -47,6 +47,13 @@ BTFIXUPDEF_SIMM13(user_ptrs_per_pgd)
2001 + BTFIXUPDEF_INT(page_none)
2002 + BTFIXUPDEF_INT(page_copy)
2003 + BTFIXUPDEF_INT(page_readonly)
2004 ++
2005 ++#ifdef CONFIG_PAX_PAGEEXEC
2006 ++BTFIXUPDEF_INT(page_shared_noexec)
2007 ++BTFIXUPDEF_INT(page_copy_noexec)
2008 ++BTFIXUPDEF_INT(page_readonly_noexec)
2009 ++#endif
2010 ++
2011 + BTFIXUPDEF_INT(page_kernel)
2012 +
2013 + #define PMD_SHIFT SUN4C_PMD_SHIFT
2014 +@@ -68,6 +75,16 @@ extern pgprot_t PAGE_SHARED;
2015 + #define PAGE_COPY __pgprot(BTFIXUP_INT(page_copy))
2016 + #define PAGE_READONLY __pgprot(BTFIXUP_INT(page_readonly))
2017 +
2018 ++#ifdef CONFIG_PAX_PAGEEXEC
2019 ++extern pgprot_t PAGE_SHARED_NOEXEC;
2020 ++# define PAGE_COPY_NOEXEC __pgprot(BTFIXUP_INT(page_copy_noexec))
2021 ++# define PAGE_READONLY_NOEXEC __pgprot(BTFIXUP_INT(page_readonly_noexec))
2022 ++#else
2023 ++# define PAGE_SHARED_NOEXEC PAGE_SHARED
2024 ++# define PAGE_COPY_NOEXEC PAGE_COPY
2025 ++# define PAGE_READONLY_NOEXEC PAGE_READONLY
2026 ++#endif
2027 ++
2028 + extern unsigned long page_kernel;
2029 +
2030 + #ifdef MODULE
2031 +diff -urNp linux-2.6.27.10/arch/sparc/include/asm/pgtsrmmu.h linux-2.6.27.10/arch/sparc/include/asm/pgtsrmmu.h
2032 +--- linux-2.6.27.10/arch/sparc/include/asm/pgtsrmmu.h 2008-11-07 12:55:34.000000000 -0500
2033 ++++ linux-2.6.27.10/arch/sparc/include/asm/pgtsrmmu.h 2008-11-18 03:39:50.000000000 -0500
2034 +@@ -115,6 +115,13 @@
2035 + SRMMU_EXEC | SRMMU_REF)
2036 + #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
2037 + SRMMU_EXEC | SRMMU_REF)
2038 ++
2039 ++#ifdef CONFIG_PAX_PAGEEXEC
2040 ++#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
2041 ++#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
2042 ++#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
2043 ++#endif
2044 ++
2045 + #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
2046 + SRMMU_DIRTY | SRMMU_REF)
2047 +
2048 +diff -urNp linux-2.6.27.10/arch/sparc/kernel/sys_sparc.c linux-2.6.27.10/arch/sparc/kernel/sys_sparc.c
2049 +--- linux-2.6.27.10/arch/sparc/kernel/sys_sparc.c 2008-11-07 12:55:34.000000000 -0500
2050 ++++ linux-2.6.27.10/arch/sparc/kernel/sys_sparc.c 2008-11-18 03:38:43.000000000 -0500
2051 +@@ -56,7 +56,7 @@ unsigned long arch_get_unmapped_area(str
2052 + if (ARCH_SUN4C_SUN4 && len > 0x20000000)
2053 + return -ENOMEM;
2054 + if (!addr)
2055 +- addr = TASK_UNMAPPED_BASE;
2056 ++ addr = current->mm->mmap_base;
2057 +
2058 + if (flags & MAP_SHARED)
2059 + addr = COLOUR_ALIGN(addr);
2060 +diff -urNp linux-2.6.27.10/arch/sparc/Makefile linux-2.6.27.10/arch/sparc/Makefile
2061 +--- linux-2.6.27.10/arch/sparc/Makefile 2008-11-07 12:55:34.000000000 -0500
2062 ++++ linux-2.6.27.10/arch/sparc/Makefile 2008-11-18 03:38:43.000000000 -0500
2063 +@@ -37,7 +37,7 @@ drivers-$(CONFIG_OPROFILE) += arch/sparc
2064 + # Renaming is done to avoid confusing pattern matching rules in 2.5.45 (multy-)
2065 + INIT_Y := $(patsubst %/, %/built-in.o, $(init-y))
2066 + CORE_Y := $(core-y)
2067 +-CORE_Y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
2068 ++CORE_Y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
2069 + CORE_Y := $(patsubst %/, %/built-in.o, $(CORE_Y))
2070 + DRIVERS_Y := $(patsubst %/, %/built-in.o, $(drivers-y))
2071 + NET_Y := $(patsubst %/, %/built-in.o, $(net-y))
2072 +diff -urNp linux-2.6.27.10/arch/sparc/mm/fault.c linux-2.6.27.10/arch/sparc/mm/fault.c
2073 +--- linux-2.6.27.10/arch/sparc/mm/fault.c 2008-11-07 12:55:34.000000000 -0500
2074 ++++ linux-2.6.27.10/arch/sparc/mm/fault.c 2008-11-18 03:38:43.000000000 -0500
2075 +@@ -21,6 +21,9 @@
2076 + #include <linux/interrupt.h>
2077 + #include <linux/module.h>
2078 + #include <linux/kdebug.h>
2079 ++#include <linux/slab.h>
2080 ++#include <linux/pagemap.h>
2081 ++#include <linux/compiler.h>
2082 +
2083 + #include <asm/system.h>
2084 + #include <asm/page.h>
2085 +@@ -167,6 +170,249 @@ static unsigned long compute_si_addr(str
2086 + return safe_compute_effective_address(regs, insn);
2087 + }
2088 +
2089 ++#ifdef CONFIG_PAX_PAGEEXEC
2090 ++void pax_emuplt_close(struct vm_area_struct *vma)
2091 ++{
2092 ++ vma->vm_mm->call_dl_resolve = 0UL;
2093 ++}
2094 ++
2095 ++static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
2096 ++{
2097 ++ unsigned int *kaddr;
2098 ++
2099 ++ vmf->page = alloc_page(GFP_HIGHUSER);
2100 ++ if (!vmf->page)
2101 ++ return VM_FAULT_OOM;
2102 ++
2103 ++ kaddr = kmap(vmf->page);
2104 ++ memset(kaddr, 0, PAGE_SIZE);
2105 ++ kaddr[0] = 0x9DE3BFA8U; /* save */
2106 ++ flush_dcache_page(vmf->page);
2107 ++ kunmap(vmf->page);
2108 ++ return VM_FAULT_MAJOR;
2109 ++}
2110 ++
2111 ++static struct vm_operations_struct pax_vm_ops = {
2112 ++ .close = pax_emuplt_close,
2113 ++ .fault = pax_emuplt_fault
2114 ++};
2115 ++
2116 ++static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
2117 ++{
2118 ++ int ret;
2119 ++
2120 ++ vma->vm_mm = current->mm;
2121 ++ vma->vm_start = addr;
2122 ++ vma->vm_end = addr + PAGE_SIZE;
2123 ++ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
2124 ++ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
2125 ++ vma->vm_ops = &pax_vm_ops;
2126 ++
2127 ++ ret = insert_vm_struct(current->mm, vma);
2128 ++ if (ret)
2129 ++ return ret;
2130 ++
2131 ++ ++current->mm->total_vm;
2132 ++ return 0;
2133 ++}
2134 ++
2135 ++/*
2136 ++ * PaX: decide what to do with offenders (regs->pc = fault address)
2137 ++ *
2138 ++ * returns 1 when task should be killed
2139 ++ * 2 when patched PLT trampoline was detected
2140 ++ * 3 when unpatched PLT trampoline was detected
2141 ++ */
2142 ++static int pax_handle_fetch_fault(struct pt_regs *regs)
2143 ++{
2144 ++
2145 ++#ifdef CONFIG_PAX_EMUPLT
2146 ++ int err;
2147 ++
2148 ++ do { /* PaX: patched PLT emulation #1 */
2149 ++ unsigned int sethi1, sethi2, jmpl;
2150 ++
2151 ++ err = get_user(sethi1, (unsigned int *)regs->pc);
2152 ++ err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
2153 ++ err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
2154 ++
2155 ++ if (err)
2156 ++ break;
2157 ++
2158 ++ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
2159 ++ (sethi2 & 0xFFC00000U) == 0x03000000U &&
2160 ++ (jmpl & 0xFFFFE000U) == 0x81C06000U)
2161 ++ {
2162 ++ unsigned int addr;
2163 ++
2164 ++ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
2165 ++ addr = regs->u_regs[UREG_G1];
2166 ++ addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
2167 ++ regs->pc = addr;
2168 ++ regs->npc = addr+4;
2169 ++ return 2;
2170 ++ }
2171 ++ } while (0);
2172 ++
2173 ++ { /* PaX: patched PLT emulation #2 */
2174 ++ unsigned int ba;
2175 ++
2176 ++ err = get_user(ba, (unsigned int *)regs->pc);
2177 ++
2178 ++ if (!err && (ba & 0xFFC00000U) == 0x30800000U) {
2179 ++ unsigned int addr;
2180 ++
2181 ++ addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
2182 ++ regs->pc = addr;
2183 ++ regs->npc = addr+4;
2184 ++ return 2;
2185 ++ }
2186 ++ }
2187 ++
2188 ++ do { /* PaX: patched PLT emulation #3 */
2189 ++ unsigned int sethi, jmpl, nop;
2190 ++
2191 ++ err = get_user(sethi, (unsigned int *)regs->pc);
2192 ++ err |= get_user(jmpl, (unsigned int *)(regs->pc+4));
2193 ++ err |= get_user(nop, (unsigned int *)(regs->pc+8));
2194 ++
2195 ++ if (err)
2196 ++ break;
2197 ++
2198 ++ if ((sethi & 0xFFC00000U) == 0x03000000U &&
2199 ++ (jmpl & 0xFFFFE000U) == 0x81C06000U &&
2200 ++ nop == 0x01000000U)
2201 ++ {
2202 ++ unsigned int addr;
2203 ++
2204 ++ addr = (sethi & 0x003FFFFFU) << 10;
2205 ++ regs->u_regs[UREG_G1] = addr;
2206 ++ addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
2207 ++ regs->pc = addr;
2208 ++ regs->npc = addr+4;
2209 ++ return 2;
2210 ++ }
2211 ++ } while (0);
2212 ++
2213 ++ do { /* PaX: unpatched PLT emulation step 1 */
2214 ++ unsigned int sethi, ba, nop;
2215 ++
2216 ++ err = get_user(sethi, (unsigned int *)regs->pc);
2217 ++ err |= get_user(ba, (unsigned int *)(regs->pc+4));
2218 ++ err |= get_user(nop, (unsigned int *)(regs->pc+8));
2219 ++
2220 ++ if (err)
2221 ++ break;
2222 ++
2223 ++ if ((sethi & 0xFFC00000U) == 0x03000000U &&
2224 ++ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
2225 ++ nop == 0x01000000U)
2226 ++ {
2227 ++ unsigned int addr, save, call;
2228 ++
2229 ++ if ((ba & 0xFFC00000U) == 0x30800000U)
2230 ++ addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
2231 ++ else
2232 ++ addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
2233 ++
2234 ++ err = get_user(save, (unsigned int *)addr);
2235 ++ err |= get_user(call, (unsigned int *)(addr+4));
2236 ++ err |= get_user(nop, (unsigned int *)(addr+8));
2237 ++ if (err)
2238 ++ break;
2239 ++
2240 ++ if (save == 0x9DE3BFA8U &&
2241 ++ (call & 0xC0000000U) == 0x40000000U &&
2242 ++ nop == 0x01000000U)
2243 ++ {
2244 ++ struct vm_area_struct *vma;
2245 ++ unsigned long call_dl_resolve;
2246 ++
2247 ++ down_read(&current->mm->mmap_sem);
2248 ++ call_dl_resolve = current->mm->call_dl_resolve;
2249 ++ up_read(&current->mm->mmap_sem);
2250 ++ if (likely(call_dl_resolve))
2251 ++ goto emulate;
2252 ++
2253 ++ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
2254 ++
2255 ++ down_write(&current->mm->mmap_sem);
2256 ++ if (current->mm->call_dl_resolve) {
2257 ++ call_dl_resolve = current->mm->call_dl_resolve;
2258 ++ up_write(&current->mm->mmap_sem);
2259 ++ if (vma)
2260 ++ kmem_cache_free(vm_area_cachep, vma);
2261 ++ goto emulate;
2262 ++ }
2263 ++
2264 ++ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
2265 ++ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
2266 ++ up_write(&current->mm->mmap_sem);
2267 ++ if (vma)
2268 ++ kmem_cache_free(vm_area_cachep, vma);
2269 ++ return 1;
2270 ++ }
2271 ++
2272 ++ if (pax_insert_vma(vma, call_dl_resolve)) {
2273 ++ up_write(&current->mm->mmap_sem);
2274 ++ kmem_cache_free(vm_area_cachep, vma);
2275 ++ return 1;
2276 ++ }
2277 ++
2278 ++ current->mm->call_dl_resolve = call_dl_resolve;
2279 ++ up_write(&current->mm->mmap_sem);
2280 ++
2281 ++emulate:
2282 ++ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
2283 ++ regs->pc = call_dl_resolve;
2284 ++ regs->npc = addr+4;
2285 ++ return 3;
2286 ++ }
2287 ++ }
2288 ++ } while (0);
2289 ++
2290 ++ do { /* PaX: unpatched PLT emulation step 2 */
2291 ++ unsigned int save, call, nop;
2292 ++
2293 ++ err = get_user(save, (unsigned int *)(regs->pc-4));
2294 ++ err |= get_user(call, (unsigned int *)regs->pc);
2295 ++ err |= get_user(nop, (unsigned int *)(regs->pc+4));
2296 ++ if (err)
2297 ++ break;
2298 ++
2299 ++ if (save == 0x9DE3BFA8U &&
2300 ++ (call & 0xC0000000U) == 0x40000000U &&
2301 ++ nop == 0x01000000U)
2302 ++ {
2303 ++ unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
2304 ++
2305 ++ regs->u_regs[UREG_RETPC] = regs->pc;
2306 ++ regs->pc = dl_resolve;
2307 ++ regs->npc = dl_resolve+4;
2308 ++ return 3;
2309 ++ }
2310 ++ } while (0);
2311 ++#endif
2312 ++
2313 ++ return 1;
2314 ++}
2315 ++
2316 ++void pax_report_insns(void *pc, void *sp)
2317 ++{
2318 ++ unsigned long i;
2319 ++
2320 ++ printk(KERN_ERR "PAX: bytes at PC: ");
2321 ++ for (i = 0; i < 5; i++) {
2322 ++ unsigned int c;
2323 ++ if (get_user(c, (unsigned int *)pc+i))
2324 ++ printk(KERN_CONT "???????? ");
2325 ++ else
2326 ++ printk(KERN_CONT "%08x ", c);
2327 ++ }
2328 ++ printk("\n");
2329 ++}
2330 ++#endif
2331 ++
2332 + asmlinkage void do_sparc_fault(struct pt_regs *regs, int text_fault, int write,
2333 + unsigned long address)
2334 + {
2335 +@@ -231,6 +477,24 @@ good_area:
2336 + if(!(vma->vm_flags & VM_WRITE))
2337 + goto bad_area;
2338 + } else {
2339 ++
2340 ++#ifdef CONFIG_PAX_PAGEEXEC
2341 ++ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
2342 ++ up_read(&mm->mmap_sem);
2343 ++ switch (pax_handle_fetch_fault(regs)) {
2344 ++
2345 ++#ifdef CONFIG_PAX_EMUPLT
2346 ++ case 2:
2347 ++ case 3:
2348 ++ return;
2349 ++#endif
2350 ++
2351 ++ }
2352 ++ pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
2353 ++ do_group_exit(SIGKILL);
2354 ++ }
2355 ++#endif
2356 ++
2357 + /* Allow reads even for write-only mappings */
2358 + if(!(vma->vm_flags & (VM_READ | VM_EXEC)))
2359 + goto bad_area;
2360 +diff -urNp linux-2.6.27.10/arch/sparc/mm/init.c linux-2.6.27.10/arch/sparc/mm/init.c
2361 +--- linux-2.6.27.10/arch/sparc/mm/init.c 2008-11-07 12:55:34.000000000 -0500
2362 ++++ linux-2.6.27.10/arch/sparc/mm/init.c 2008-11-18 03:38:43.000000000 -0500
2363 +@@ -312,6 +312,9 @@ extern void device_scan(void);
2364 + pgprot_t PAGE_SHARED __read_mostly;
2365 + EXPORT_SYMBOL(PAGE_SHARED);
2366 +
2367 ++pgprot_t PAGE_SHARED_NOEXEC __read_mostly;
2368 ++EXPORT_SYMBOL(PAGE_SHARED_NOEXEC);
2369 ++
2370 + void __init paging_init(void)
2371 + {
2372 + switch(sparc_cpu_model) {
2373 +@@ -337,17 +340,17 @@ void __init paging_init(void)
2374 +
2375 + /* Initialize the protection map with non-constant, MMU dependent values. */
2376 + protection_map[0] = PAGE_NONE;
2377 +- protection_map[1] = PAGE_READONLY;
2378 +- protection_map[2] = PAGE_COPY;
2379 +- protection_map[3] = PAGE_COPY;
2380 ++ protection_map[1] = PAGE_READONLY_NOEXEC;
2381 ++ protection_map[2] = PAGE_COPY_NOEXEC;
2382 ++ protection_map[3] = PAGE_COPY_NOEXEC;
2383 + protection_map[4] = PAGE_READONLY;
2384 + protection_map[5] = PAGE_READONLY;
2385 + protection_map[6] = PAGE_COPY;
2386 + protection_map[7] = PAGE_COPY;
2387 + protection_map[8] = PAGE_NONE;
2388 +- protection_map[9] = PAGE_READONLY;
2389 +- protection_map[10] = PAGE_SHARED;
2390 +- protection_map[11] = PAGE_SHARED;
2391 ++ protection_map[9] = PAGE_READONLY_NOEXEC;
2392 ++ protection_map[10] = PAGE_SHARED_NOEXEC;
2393 ++ protection_map[11] = PAGE_SHARED_NOEXEC;
2394 + protection_map[12] = PAGE_READONLY;
2395 + protection_map[13] = PAGE_READONLY;
2396 + protection_map[14] = PAGE_SHARED;
2397 +diff -urNp linux-2.6.27.10/arch/sparc/mm/srmmu.c linux-2.6.27.10/arch/sparc/mm/srmmu.c
2398 +--- linux-2.6.27.10/arch/sparc/mm/srmmu.c 2008-11-07 12:55:34.000000000 -0500
2399 ++++ linux-2.6.27.10/arch/sparc/mm/srmmu.c 2008-11-18 03:38:43.000000000 -0500
2400 +@@ -2163,6 +2163,13 @@ void __init ld_mmu_srmmu(void)
2401 + PAGE_SHARED = pgprot_val(SRMMU_PAGE_SHARED);
2402 + BTFIXUPSET_INT(page_copy, pgprot_val(SRMMU_PAGE_COPY));
2403 + BTFIXUPSET_INT(page_readonly, pgprot_val(SRMMU_PAGE_RDONLY));
2404 ++
2405 ++#ifdef CONFIG_PAX_PAGEEXEC
2406 ++ PAGE_SHARED_NOEXEC = pgprot_val(SRMMU_PAGE_SHARED_NOEXEC);
2407 ++ BTFIXUPSET_INT(page_copy_noexec, pgprot_val(SRMMU_PAGE_COPY_NOEXEC));
2408 ++ BTFIXUPSET_INT(page_readonly_noexec, pgprot_val(SRMMU_PAGE_RDONLY_NOEXEC));
2409 ++#endif
2410 ++
2411 + BTFIXUPSET_INT(page_kernel, pgprot_val(SRMMU_PAGE_KERNEL));
2412 + page_kernel = pgprot_val(SRMMU_PAGE_KERNEL);
2413 +
2414 +diff -urNp linux-2.6.27.10/arch/sparc64/kernel/Makefile linux-2.6.27.10/arch/sparc64/kernel/Makefile
2415 +--- linux-2.6.27.10/arch/sparc64/kernel/Makefile 2008-11-07 12:55:34.000000000 -0500
2416 ++++ linux-2.6.27.10/arch/sparc64/kernel/Makefile 2008-11-18 03:38:43.000000000 -0500
2417 +@@ -3,7 +3,7 @@
2418 + #
2419 +
2420 + EXTRA_AFLAGS := -ansi
2421 +-EXTRA_CFLAGS := -Werror
2422 ++#EXTRA_CFLAGS := -Werror
2423 +
2424 + extra-y := head.o init_task.o vmlinux.lds
2425 +
2426 +diff -urNp linux-2.6.27.10/arch/sparc64/kernel/sys_sparc.c linux-2.6.27.10/arch/sparc64/kernel/sys_sparc.c
2427 +--- linux-2.6.27.10/arch/sparc64/kernel/sys_sparc.c 2008-11-07 12:55:34.000000000 -0500
2428 ++++ linux-2.6.27.10/arch/sparc64/kernel/sys_sparc.c 2008-11-18 03:38:43.000000000 -0500
2429 +@@ -124,7 +124,7 @@ unsigned long arch_get_unmapped_area(str
2430 + /* We do not accept a shared mapping if it would violate
2431 + * cache aliasing constraints.
2432 + */
2433 +- if ((flags & MAP_SHARED) &&
2434 ++ if ((filp || (flags & MAP_SHARED)) &&
2435 + ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
2436 + return -EINVAL;
2437 + return addr;
2438 +@@ -139,6 +139,10 @@ unsigned long arch_get_unmapped_area(str
2439 + if (filp || (flags & MAP_SHARED))
2440 + do_color_align = 1;
2441 +
2442 ++#ifdef CONFIG_PAX_RANDMMAP
2443 ++ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || !filp)
2444 ++#endif
2445 ++
2446 + if (addr) {
2447 + if (do_color_align)
2448 + addr = COLOUR_ALIGN(addr, pgoff);
2449 +@@ -152,9 +156,9 @@ unsigned long arch_get_unmapped_area(str
2450 + }
2451 +
2452 + if (len > mm->cached_hole_size) {
2453 +- start_addr = addr = mm->free_area_cache;
2454 ++ start_addr = addr = mm->free_area_cache;
2455 + } else {
2456 +- start_addr = addr = TASK_UNMAPPED_BASE;
2457 ++ start_addr = addr = mm->mmap_base;
2458 + mm->cached_hole_size = 0;
2459 + }
2460 +
2461 +@@ -174,8 +178,8 @@ full_search:
2462 + vma = find_vma(mm, VA_EXCLUDE_END);
2463 + }
2464 + if (unlikely(task_size < addr)) {
2465 +- if (start_addr != TASK_UNMAPPED_BASE) {
2466 +- start_addr = addr = TASK_UNMAPPED_BASE;
2467 ++ if (start_addr != mm->mmap_base) {
2468 ++ start_addr = addr = mm->mmap_base;
2469 + mm->cached_hole_size = 0;
2470 + goto full_search;
2471 + }
2472 +@@ -215,7 +219,7 @@ arch_get_unmapped_area_topdown(struct fi
2473 + /* We do not accept a shared mapping if it would violate
2474 + * cache aliasing constraints.
2475 + */
2476 +- if ((flags & MAP_SHARED) &&
2477 ++ if ((filp || (flags & MAP_SHARED)) &&
2478 + ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
2479 + return -EINVAL;
2480 + return addr;
2481 +@@ -378,6 +382,12 @@ void arch_pick_mmap_layout(struct mm_str
2482 + current->signal->rlim[RLIMIT_STACK].rlim_cur == RLIM_INFINITY ||
2483 + sysctl_legacy_va_layout) {
2484 + mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
2485 ++
2486 ++#ifdef CONFIG_PAX_RANDMMAP
2487 ++ if (mm->pax_flags & MF_PAX_RANDMMAP)
2488 ++ mm->mmap_base += mm->delta_mmap;
2489 ++#endif
2490 ++
2491 + mm->get_unmapped_area = arch_get_unmapped_area;
2492 + mm->unmap_area = arch_unmap_area;
2493 + } else {
2494 +@@ -392,6 +402,12 @@ void arch_pick_mmap_layout(struct mm_str
2495 + gap = (task_size / 6 * 5);
2496 +
2497 + mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
2498 ++
2499 ++#ifdef CONFIG_PAX_RANDMMAP
2500 ++ if (mm->pax_flags & MF_PAX_RANDMMAP)
2501 ++ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
2502 ++#endif
2503 ++
2504 + mm->get_unmapped_area = arch_get_unmapped_area_topdown;
2505 + mm->unmap_area = arch_unmap_area_topdown;
2506 + }
2507 +diff -urNp linux-2.6.27.10/arch/sparc64/mm/fault.c linux-2.6.27.10/arch/sparc64/mm/fault.c
2508 +--- linux-2.6.27.10/arch/sparc64/mm/fault.c 2008-11-07 12:55:34.000000000 -0500
2509 ++++ linux-2.6.27.10/arch/sparc64/mm/fault.c 2008-11-18 03:38:43.000000000 -0500
2510 +@@ -19,6 +19,9 @@
2511 + #include <linux/interrupt.h>
2512 + #include <linux/kprobes.h>
2513 + #include <linux/kdebug.h>
2514 ++#include <linux/slab.h>
2515 ++#include <linux/pagemap.h>
2516 ++#include <linux/compiler.h>
2517 +
2518 + #include <asm/page.h>
2519 + #include <asm/pgtable.h>
2520 +@@ -261,6 +264,367 @@ cannot_handle:
2521 + unhandled_fault (address, current, regs);
2522 + }
2523 +
2524 ++#ifdef CONFIG_PAX_PAGEEXEC
2525 ++#ifdef CONFIG_PAX_EMUPLT
2526 ++static void pax_emuplt_close(struct vm_area_struct *vma)
2527 ++{
2528 ++ vma->vm_mm->call_dl_resolve = 0UL;
2529 ++}
2530 ++
2531 ++static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
2532 ++{
2533 ++ unsigned int *kaddr;
2534 ++
2535 ++ vmf->page = alloc_page(GFP_HIGHUSER);
2536 ++ if (!vmf->page)
2537 ++ return VM_FAULT_OOM;
2538 ++
2539 ++ kaddr = kmap(vmf->page);
2540 ++ memset(kaddr, 0, PAGE_SIZE);
2541 ++ kaddr[0] = 0x9DE3BFA8U; /* save */
2542 ++ flush_dcache_page(vmf->page);
2543 ++ kunmap(vmf->page);
2544 ++ return VM_FAULT_MAJOR;
2545 ++}
2546 ++
2547 ++static struct vm_operations_struct pax_vm_ops = {
2548 ++ .close = pax_emuplt_close,
2549 ++ .fault = pax_emuplt_fault
2550 ++};
2551 ++
2552 ++static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
2553 ++{
2554 ++ int ret;
2555 ++
2556 ++ vma->vm_mm = current->mm;
2557 ++ vma->vm_start = addr;
2558 ++ vma->vm_end = addr + PAGE_SIZE;
2559 ++ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
2560 ++ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
2561 ++ vma->vm_ops = &pax_vm_ops;
2562 ++
2563 ++ ret = insert_vm_struct(current->mm, vma);
2564 ++ if (ret)
2565 ++ return ret;
2566 ++
2567 ++ ++current->mm->total_vm;
2568 ++ return 0;
2569 ++}
2570 ++#endif
2571 ++
2572 ++/*
2573 ++ * PaX: decide what to do with offenders (regs->tpc = fault address)
2574 ++ *
2575 ++ * returns 1 when task should be killed
2576 ++ * 2 when patched PLT trampoline was detected
2577 ++ * 3 when unpatched PLT trampoline was detected
2578 ++ */
2579 ++static int pax_handle_fetch_fault(struct pt_regs *regs)
2580 ++{
2581 ++
2582 ++#ifdef CONFIG_PAX_EMUPLT
2583 ++ int err;
2584 ++
2585 ++ do { /* PaX: patched PLT emulation #1 */
2586 ++ unsigned int sethi1, sethi2, jmpl;
2587 ++
2588 ++ err = get_user(sethi1, (unsigned int *)regs->tpc);
2589 ++ err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
2590 ++ err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
2591 ++
2592 ++ if (err)
2593 ++ break;
2594 ++
2595 ++ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
2596 ++ (sethi2 & 0xFFC00000U) == 0x03000000U &&
2597 ++ (jmpl & 0xFFFFE000U) == 0x81C06000U)
2598 ++ {
2599 ++ unsigned long addr;
2600 ++
2601 ++ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
2602 ++ addr = regs->u_regs[UREG_G1];
2603 ++ addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
2604 ++ regs->tpc = addr;
2605 ++ regs->tnpc = addr+4;
2606 ++ return 2;
2607 ++ }
2608 ++ } while (0);
2609 ++
2610 ++ { /* PaX: patched PLT emulation #2 */
2611 ++ unsigned int ba;
2612 ++
2613 ++ err = get_user(ba, (unsigned int *)regs->tpc);
2614 ++
2615 ++ if (!err && (ba & 0xFFC00000U) == 0x30800000U) {
2616 ++ unsigned long addr;
2617 ++
2618 ++ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
2619 ++ regs->tpc = addr;
2620 ++ regs->tnpc = addr+4;
2621 ++ return 2;
2622 ++ }
2623 ++ }
2624 ++
2625 ++ do { /* PaX: patched PLT emulation #3 */
2626 ++ unsigned int sethi, jmpl, nop;
2627 ++
2628 ++ err = get_user(sethi, (unsigned int *)regs->tpc);
2629 ++ err |= get_user(jmpl, (unsigned int *)(regs->tpc+4));
2630 ++ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
2631 ++
2632 ++ if (err)
2633 ++ break;
2634 ++
2635 ++ if ((sethi & 0xFFC00000U) == 0x03000000U &&
2636 ++ (jmpl & 0xFFFFE000U) == 0x81C06000U &&
2637 ++ nop == 0x01000000U)
2638 ++ {
2639 ++ unsigned long addr;
2640 ++
2641 ++ addr = (sethi & 0x003FFFFFU) << 10;
2642 ++ regs->u_regs[UREG_G1] = addr;
2643 ++ addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
2644 ++ regs->tpc = addr;
2645 ++ regs->tnpc = addr+4;
2646 ++ return 2;
2647 ++ }
2648 ++ } while (0);
2649 ++
2650 ++ do { /* PaX: patched PLT emulation #4 */
2651 ++ unsigned int mov1, call, mov2;
2652 ++
2653 ++ err = get_user(mov1, (unsigned int *)regs->tpc);
2654 ++ err |= get_user(call, (unsigned int *)(regs->tpc+4));
2655 ++ err |= get_user(mov2, (unsigned int *)(regs->tpc+8));
2656 ++
2657 ++ if (err)
2658 ++ break;
2659 ++
2660 ++ if (mov1 == 0x8210000FU &&
2661 ++ (call & 0xC0000000U) == 0x40000000U &&
2662 ++ mov2 == 0x9E100001U)
2663 ++ {
2664 ++ unsigned long addr;
2665 ++
2666 ++ regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
2667 ++ addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
2668 ++ regs->tpc = addr;
2669 ++ regs->tnpc = addr+4;
2670 ++ return 2;
2671 ++ }
2672 ++ } while (0);
2673 ++
2674 ++ do { /* PaX: patched PLT emulation #5 */
2675 ++ unsigned int sethi1, sethi2, or1, or2, sllx, jmpl, nop;
2676 ++
2677 ++ err = get_user(sethi1, (unsigned int *)regs->tpc);
2678 ++ err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
2679 ++ err |= get_user(or1, (unsigned int *)(regs->tpc+8));
2680 ++ err |= get_user(or2, (unsigned int *)(regs->tpc+12));
2681 ++ err |= get_user(sllx, (unsigned int *)(regs->tpc+16));
2682 ++ err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
2683 ++ err |= get_user(nop, (unsigned int *)(regs->tpc+24));
2684 ++
2685 ++ if (err)
2686 ++ break;
2687 ++
2688 ++ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
2689 ++ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
2690 ++ (or1 & 0xFFFFE000U) == 0x82106000U &&
2691 ++ (or2 & 0xFFFFE000U) == 0x8A116000U &&
2692 ++ sllx == 0x83287020 &&
2693 ++ jmpl == 0x81C04005U &&
2694 ++ nop == 0x01000000U)
2695 ++ {
2696 ++ unsigned long addr;
2697 ++
2698 ++ regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
2699 ++ regs->u_regs[UREG_G1] <<= 32;
2700 ++ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
2701 ++ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
2702 ++ regs->tpc = addr;
2703 ++ regs->tnpc = addr+4;
2704 ++ return 2;
2705 ++ }
2706 ++ } while (0);
2707 ++
2708 ++ do { /* PaX: patched PLT emulation #6 */
2709 ++ unsigned int sethi1, sethi2, sllx, or, jmpl, nop;
2710 ++
2711 ++ err = get_user(sethi1, (unsigned int *)regs->tpc);
2712 ++ err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
2713 ++ err |= get_user(sllx, (unsigned int *)(regs->tpc+8));
2714 ++ err |= get_user(or, (unsigned int *)(regs->tpc+12));
2715 ++ err |= get_user(jmpl, (unsigned int *)(regs->tpc+16));
2716 ++ err |= get_user(nop, (unsigned int *)(regs->tpc+20));
2717 ++
2718 ++ if (err)
2719 ++ break;
2720 ++
2721 ++ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
2722 ++ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
2723 ++ sllx == 0x83287020 &&
2724 ++ (or & 0xFFFFE000U) == 0x8A116000U &&
2725 ++ jmpl == 0x81C04005U &&
2726 ++ nop == 0x01000000U)
2727 ++ {
2728 ++ unsigned long addr;
2729 ++
2730 ++ regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
2731 ++ regs->u_regs[UREG_G1] <<= 32;
2732 ++ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
2733 ++ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
2734 ++ regs->tpc = addr;
2735 ++ regs->tnpc = addr+4;
2736 ++ return 2;
2737 ++ }
2738 ++ } while (0);
2739 ++
2740 ++ do { /* PaX: patched PLT emulation #7 */
2741 ++ unsigned int sethi, ba, nop;
2742 ++
2743 ++ err = get_user(sethi, (unsigned int *)regs->tpc);
2744 ++ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
2745 ++ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
2746 ++
2747 ++ if (err)
2748 ++ break;
2749 ++
2750 ++ if ((sethi & 0xFFC00000U) == 0x03000000U &&
2751 ++ (ba & 0xFFF00000U) == 0x30600000U &&
2752 ++ nop == 0x01000000U)
2753 ++ {
2754 ++ unsigned long addr;
2755 ++
2756 ++ addr = (sethi & 0x003FFFFFU) << 10;
2757 ++ regs->u_regs[UREG_G1] = addr;
2758 ++ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
2759 ++ regs->tpc = addr;
2760 ++ regs->tnpc = addr+4;
2761 ++ return 2;
2762 ++ }
2763 ++ } while (0);
2764 ++
2765 ++ do { /* PaX: unpatched PLT emulation step 1 */
2766 ++ unsigned int sethi, ba, nop;
2767 ++
2768 ++ err = get_user(sethi, (unsigned int *)regs->tpc);
2769 ++ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
2770 ++ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
2771 ++
2772 ++ if (err)
2773 ++ break;
2774 ++
2775 ++ if ((sethi & 0xFFC00000U) == 0x03000000U &&
2776 ++ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
2777 ++ nop == 0x01000000U)
2778 ++ {
2779 ++ unsigned long addr;
2780 ++ unsigned int save, call;
2781 ++
2782 ++ if ((ba & 0xFFC00000U) == 0x30800000U)
2783 ++ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
2784 ++ else
2785 ++ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
2786 ++
2787 ++ err = get_user(save, (unsigned int *)addr);
2788 ++ err |= get_user(call, (unsigned int *)(addr+4));
2789 ++ err |= get_user(nop, (unsigned int *)(addr+8));
2790 ++ if (err)
2791 ++ break;
2792 ++
2793 ++ if (save == 0x9DE3BFA8U &&
2794 ++ (call & 0xC0000000U) == 0x40000000U &&
2795 ++ nop == 0x01000000U)
2796 ++ {
2797 ++ struct vm_area_struct *vma;
2798 ++ unsigned long call_dl_resolve;
2799 ++
2800 ++ down_read(&current->mm->mmap_sem);
2801 ++ call_dl_resolve = current->mm->call_dl_resolve;
2802 ++ up_read(&current->mm->mmap_sem);
2803 ++ if (likely(call_dl_resolve))
2804 ++ goto emulate;
2805 ++
2806 ++ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
2807 ++
2808 ++ down_write(&current->mm->mmap_sem);
2809 ++ if (current->mm->call_dl_resolve) {
2810 ++ call_dl_resolve = current->mm->call_dl_resolve;
2811 ++ up_write(&current->mm->mmap_sem);
2812 ++ if (vma)
2813 ++ kmem_cache_free(vm_area_cachep, vma);
2814 ++ goto emulate;
2815 ++ }
2816 ++
2817 ++ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
2818 ++ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
2819 ++ up_write(&current->mm->mmap_sem);
2820 ++ if (vma)
2821 ++ kmem_cache_free(vm_area_cachep, vma);
2822 ++ return 1;
2823 ++ }
2824 ++
2825 ++ if (pax_insert_vma(vma, call_dl_resolve)) {
2826 ++ up_write(&current->mm->mmap_sem);
2827 ++ kmem_cache_free(vm_area_cachep, vma);
2828 ++ return 1;
2829 ++ }
2830 ++
2831 ++ current->mm->call_dl_resolve = call_dl_resolve;
2832 ++ up_write(&current->mm->mmap_sem);
2833 ++
2834 ++emulate:
2835 ++ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
2836 ++ regs->tpc = call_dl_resolve;
2837 ++ regs->tnpc = addr+4;
2838 ++ return 3;
2839 ++ }
2840 ++ }
2841 ++ } while (0);
2842 ++
2843 ++ do { /* PaX: unpatched PLT emulation step 2 */
2844 ++ unsigned int save, call, nop;
2845 ++
2846 ++ err = get_user(save, (unsigned int *)(regs->tpc-4));
2847 ++ err |= get_user(call, (unsigned int *)regs->tpc);
2848 ++ err |= get_user(nop, (unsigned int *)(regs->tpc+4));
2849 ++ if (err)
2850 ++ break;
2851 ++
2852 ++ if (save == 0x9DE3BFA8U &&
2853 ++ (call & 0xC0000000U) == 0x40000000U &&
2854 ++ nop == 0x01000000U)
2855 ++ {
2856 ++ unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
2857 ++
2858 ++ regs->u_regs[UREG_RETPC] = regs->tpc;
2859 ++ regs->tpc = dl_resolve;
2860 ++ regs->tnpc = dl_resolve+4;
2861 ++ return 3;
2862 ++ }
2863 ++ } while (0);
2864 ++#endif
2865 ++
2866 ++ return 1;
2867 ++}
2868 ++
2869 ++void pax_report_insns(void *pc, void *sp)
2870 ++{
2871 ++ unsigned long i;
2872 ++
2873 ++ printk(KERN_ERR "PAX: bytes at PC: ");
2874 ++ for (i = 0; i < 5; i++) {
2875 ++ unsigned int c;
2876 ++ if (get_user(c, (unsigned int *)pc+i))
2877 ++ printk(KERN_CONT "???????? ");
2878 ++ else
2879 ++ printk(KERN_CONT "%08x ", c);
2880 ++ }
2881 ++ printk("\n");
2882 ++}
2883 ++#endif
2884 ++
2885 + asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
2886 + {
2887 + struct mm_struct *mm = current->mm;
2888 +@@ -302,8 +666,10 @@ asmlinkage void __kprobes do_sparc64_fau
2889 + goto intr_or_no_mm;
2890 +
2891 + if (test_thread_flag(TIF_32BIT)) {
2892 +- if (!(regs->tstate & TSTATE_PRIV))
2893 ++ if (!(regs->tstate & TSTATE_PRIV)) {
2894 + regs->tpc &= 0xffffffff;
2895 ++ regs->tnpc &= 0xffffffff;
2896 ++ }
2897 + address &= 0xffffffff;
2898 + }
2899 +
2900 +@@ -320,6 +686,29 @@ asmlinkage void __kprobes do_sparc64_fau
2901 + if (!vma)
2902 + goto bad_area;
2903 +
2904 ++#ifdef CONFIG_PAX_PAGEEXEC
2905 ++ /* PaX: detect ITLB misses on non-exec pages */
2906 ++ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
2907 ++ !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
2908 ++ {
2909 ++ if (address != regs->tpc)
2910 ++ goto good_area;
2911 ++
2912 ++ up_read(&mm->mmap_sem);
2913 ++ switch (pax_handle_fetch_fault(regs)) {
2914 ++
2915 ++#ifdef CONFIG_PAX_EMUPLT
2916 ++ case 2:
2917 ++ case 3:
2918 ++ return;
2919 ++#endif
2920 ++
2921 ++ }
2922 ++ pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
2923 ++ do_group_exit(SIGKILL);
2924 ++ }
2925 ++#endif
2926 ++
2927 + /* Pure DTLB misses do not tell us whether the fault causing
2928 + * load/store/atomic was a write or not, it only says that there
2929 + * was no match. So in such a case we (carefully) read the
2930 +diff -urNp linux-2.6.27.10/arch/sparc64/mm/Makefile linux-2.6.27.10/arch/sparc64/mm/Makefile
2931 +--- linux-2.6.27.10/arch/sparc64/mm/Makefile 2008-11-07 12:55:34.000000000 -0500
2932 ++++ linux-2.6.27.10/arch/sparc64/mm/Makefile 2008-11-18 03:38:43.000000000 -0500
2933 +@@ -2,7 +2,7 @@
2934 + #
2935 +
2936 + EXTRA_AFLAGS := -ansi
2937 +-EXTRA_CFLAGS := -Werror
2938 ++#EXTRA_CFLAGS := -Werror
2939 +
2940 + obj-y := ultra.o tlb.o tsb.o fault.o init.o generic.o
2941 +
2942 +diff -urNp linux-2.6.27.10/arch/um/sys-i386/syscalls.c linux-2.6.27.10/arch/um/sys-i386/syscalls.c
2943 +--- linux-2.6.27.10/arch/um/sys-i386/syscalls.c 2008-11-07 12:55:34.000000000 -0500
2944 ++++ linux-2.6.27.10/arch/um/sys-i386/syscalls.c 2008-11-18 03:38:43.000000000 -0500
2945 +@@ -10,6 +10,21 @@
2946 + #include "asm/uaccess.h"
2947 + #include "asm/unistd.h"
2948 +
2949 ++int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
2950 ++{
2951 ++ unsigned long pax_task_size = TASK_SIZE;
2952 ++
2953 ++#ifdef CONFIG_PAX_SEGMEXEC
2954 ++ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
2955 ++ pax_task_size = SEGMEXEC_TASK_SIZE;
2956 ++#endif
2957 ++
2958 ++ if (len > pax_task_size || addr > pax_task_size - len)
2959 ++ return -EINVAL;
2960 ++
2961 ++ return 0;
2962 ++}
2963 ++
2964 + /*
2965 + * Perform the select(nd, in, out, ex, tv) and mmap() system
2966 + * calls. Linux/i386 didn't use to be able to handle more than
2967 +diff -urNp linux-2.6.27.10/arch/x86/boot/bitops.h linux-2.6.27.10/arch/x86/boot/bitops.h
2968 +--- linux-2.6.27.10/arch/x86/boot/bitops.h 2008-11-07 12:55:34.000000000 -0500
2969 ++++ linux-2.6.27.10/arch/x86/boot/bitops.h 2008-11-18 03:38:44.000000000 -0500
2970 +@@ -26,7 +26,7 @@ static inline int variable_test_bit(int
2971 + u8 v;
2972 + const u32 *p = (const u32 *)addr;
2973 +
2974 +- asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
2975 ++ asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
2976 + return v;
2977 + }
2978 +
2979 +@@ -37,7 +37,7 @@ static inline int variable_test_bit(int
2980 +
2981 + static inline void set_bit(int nr, void *addr)
2982 + {
2983 +- asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
2984 ++ asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
2985 + }
2986 +
2987 + #endif /* BOOT_BITOPS_H */
2988 +diff -urNp linux-2.6.27.10/arch/x86/boot/boot.h linux-2.6.27.10/arch/x86/boot/boot.h
2989 +--- linux-2.6.27.10/arch/x86/boot/boot.h 2008-11-07 12:55:34.000000000 -0500
2990 ++++ linux-2.6.27.10/arch/x86/boot/boot.h 2008-11-18 03:38:44.000000000 -0500
2991 +@@ -80,7 +80,7 @@ static inline void io_delay(void)
2992 + static inline u16 ds(void)
2993 + {
2994 + u16 seg;
2995 +- asm("movw %%ds,%0" : "=rm" (seg));
2996 ++ asm volatile("movw %%ds,%0" : "=rm" (seg));
2997 + return seg;
2998 + }
2999 +
3000 +@@ -176,7 +176,7 @@ static inline void wrgs32(u32 v, addr_t
3001 + static inline int memcmp(const void *s1, const void *s2, size_t len)
3002 + {
3003 + u8 diff;
3004 +- asm("repe; cmpsb; setnz %0"
3005 ++ asm volatile("repe; cmpsb; setnz %0"
3006 + : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
3007 + return diff;
3008 + }
3009 +diff -urNp linux-2.6.27.10/arch/x86/boot/compressed/head_32.S linux-2.6.27.10/arch/x86/boot/compressed/head_32.S
3010 +--- linux-2.6.27.10/arch/x86/boot/compressed/head_32.S 2008-11-07 12:55:34.000000000 -0500
3011 ++++ linux-2.6.27.10/arch/x86/boot/compressed/head_32.S 2008-11-18 03:38:44.000000000 -0500
3012 +@@ -70,7 +70,7 @@ startup_32:
3013 + addl $(CONFIG_PHYSICAL_ALIGN - 1), %ebx
3014 + andl $(~(CONFIG_PHYSICAL_ALIGN - 1)), %ebx
3015 + #else
3016 +- movl $LOAD_PHYSICAL_ADDR, %ebx
3017 ++ movl $____LOAD_PHYSICAL_ADDR, %ebx
3018 + #endif
3019 +
3020 + /* Replace the compressed data size with the uncompressed size */
3021 +@@ -105,7 +105,7 @@ startup_32:
3022 + addl $(CONFIG_PHYSICAL_ALIGN - 1), %ebp
3023 + andl $(~(CONFIG_PHYSICAL_ALIGN - 1)), %ebp
3024 + #else
3025 +- movl $LOAD_PHYSICAL_ADDR, %ebp
3026 ++ movl $____LOAD_PHYSICAL_ADDR, %ebp
3027 + #endif
3028 +
3029 + /*
3030 +@@ -159,16 +159,15 @@ relocated:
3031 + * and where it was actually loaded.
3032 + */
3033 + movl %ebp, %ebx
3034 +- subl $LOAD_PHYSICAL_ADDR, %ebx
3035 ++ subl $____LOAD_PHYSICAL_ADDR, %ebx
3036 + jz 2f /* Nothing to be done if loaded at compiled addr. */
3037 + /*
3038 + * Process relocations.
3039 + */
3040 +
3041 + 1: subl $4, %edi
3042 +- movl 0(%edi), %ecx
3043 +- testl %ecx, %ecx
3044 +- jz 2f
3045 ++ movl (%edi), %ecx
3046 ++ jecxz 2f
3047 + addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
3048 + jmp 1b
3049 + 2:
3050 +diff -urNp linux-2.6.27.10/arch/x86/boot/compressed/misc.c linux-2.6.27.10/arch/x86/boot/compressed/misc.c
3051 +--- linux-2.6.27.10/arch/x86/boot/compressed/misc.c 2008-11-07 12:55:34.000000000 -0500
3052 ++++ linux-2.6.27.10/arch/x86/boot/compressed/misc.c 2008-11-18 03:38:44.000000000 -0500
3053 +@@ -371,7 +371,7 @@ static void parse_elf(void *output)
3054 + case PT_LOAD:
3055 + #ifdef CONFIG_RELOCATABLE
3056 + dest = output;
3057 +- dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
3058 ++ dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
3059 + #else
3060 + dest = (void *)(phdr->p_paddr);
3061 + #endif
3062 +@@ -423,7 +423,7 @@ asmlinkage void decompress_kernel(void *
3063 + if (heap > ((-__PAGE_OFFSET-(512<<20)-1) & 0x7fffffff))
3064 + error("Destination address too large");
3065 + #ifndef CONFIG_RELOCATABLE
3066 +- if ((u32)output != LOAD_PHYSICAL_ADDR)
3067 ++ if ((u32)output != ____LOAD_PHYSICAL_ADDR)
3068 + error("Wrong destination address");
3069 + #endif
3070 + #endif
3071 +diff -urNp linux-2.6.27.10/arch/x86/boot/compressed/relocs.c linux-2.6.27.10/arch/x86/boot/compressed/relocs.c
3072 +--- linux-2.6.27.10/arch/x86/boot/compressed/relocs.c 2008-11-07 12:55:34.000000000 -0500
3073 ++++ linux-2.6.27.10/arch/x86/boot/compressed/relocs.c 2008-11-18 03:38:44.000000000 -0500
3074 +@@ -10,8 +10,11 @@
3075 + #define USE_BSD
3076 + #include <endian.h>
3077 +
3078 ++#include "../../../../include/linux/autoconf.h"
3079 ++
3080 + #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
3081 + static Elf32_Ehdr ehdr;
3082 ++static Elf32_Phdr *phdr;
3083 + static unsigned long reloc_count, reloc_idx;
3084 + static unsigned long *relocs;
3085 +
3086 +@@ -245,6 +248,36 @@ static void read_ehdr(FILE *fp)
3087 + }
3088 + }
3089 +
3090 ++static void read_phdrs(FILE *fp)
3091 ++{
3092 ++ int i;
3093 ++
3094 ++ phdr = calloc(ehdr.e_phnum, sizeof(Elf32_Phdr));
3095 ++ if (!phdr) {
3096 ++ die("Unable to allocate %d program headers\n",
3097 ++ ehdr.e_phnum);
3098 ++ }
3099 ++ if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
3100 ++ die("Seek to %d failed: %s\n",
3101 ++ ehdr.e_phoff, strerror(errno));
3102 ++ }
3103 ++ if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
3104 ++ die("Cannot read ELF program headers: %s\n",
3105 ++ strerror(errno));
3106 ++ }
3107 ++ for(i = 0; i < ehdr.e_phnum; i++) {
3108 ++ phdr[i].p_type = elf32_to_cpu(phdr[i].p_type);
3109 ++ phdr[i].p_offset = elf32_to_cpu(phdr[i].p_offset);
3110 ++ phdr[i].p_vaddr = elf32_to_cpu(phdr[i].p_vaddr);
3111 ++ phdr[i].p_paddr = elf32_to_cpu(phdr[i].p_paddr);
3112 ++ phdr[i].p_filesz = elf32_to_cpu(phdr[i].p_filesz);
3113 ++ phdr[i].p_memsz = elf32_to_cpu(phdr[i].p_memsz);
3114 ++ phdr[i].p_flags = elf32_to_cpu(phdr[i].p_flags);
3115 ++ phdr[i].p_align = elf32_to_cpu(phdr[i].p_align);
3116 ++ }
3117 ++
3118 ++}
3119 ++
3120 + static void read_shdrs(FILE *fp)
3121 + {
3122 + int i;
3123 +@@ -341,6 +374,8 @@ static void read_symtabs(FILE *fp)
3124 + static void read_relocs(FILE *fp)
3125 + {
3126 + int i,j;
3127 ++ uint32_t base;
3128 ++
3129 + for (i = 0; i < ehdr.e_shnum; i++) {
3130 + struct section *sec = &secs[i];
3131 + if (sec->shdr.sh_type != SHT_REL) {
3132 +@@ -360,9 +395,18 @@ static void read_relocs(FILE *fp)
3133 + die("Cannot read symbol table: %s\n",
3134 + strerror(errno));
3135 + }
3136 ++ base = 0;
3137 ++ for (j = 0; j < ehdr.e_phnum; j++) {
3138 ++ if (phdr[j].p_type != PT_LOAD )
3139 ++ continue;
3140 ++ if (secs[secs[i].shdr.sh_info].shdr.sh_offset < phdr[j].p_offset || secs[secs[i].shdr.sh_info].shdr.sh_offset > phdr[j].p_offset + phdr[j].p_filesz)
3141 ++ continue;
3142 ++ base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
3143 ++ break;
3144 ++ }
3145 + for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Rel); j++) {
3146 + Elf32_Rel *rel = &sec->reltab[j];
3147 +- rel->r_offset = elf32_to_cpu(rel->r_offset);
3148 ++ rel->r_offset = elf32_to_cpu(rel->r_offset) + base;
3149 + rel->r_info = elf32_to_cpu(rel->r_info);
3150 + }
3151 + }
3152 +@@ -504,6 +548,23 @@ static void walk_relocs(void (*visit)(El
3153 + if (sym->st_shndx == SHN_ABS) {
3154 + continue;
3155 + }
3156 ++ /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
3157 ++ if (!strcmp(sec_name(sym->st_shndx), ".data.percpu") && strncmp(sym_name(sym_strtab, sym), "__per_cpu_", 10))
3158 ++ continue;
3159 ++#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
3160 ++ /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
3161 ++ if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
3162 ++ continue;
3163 ++ if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
3164 ++ continue;
3165 ++ if (!strcmp(sec_name(sym->st_shndx), ".text.head")) {
3166 ++ if (strcmp(sym_name(sym_strtab, sym), "__init_end") &&
3167 ++ strcmp(sym_name(sym_strtab, sym), "KERNEL_TEXT_OFFSET"))
3168 ++ continue;
3169 ++ }
3170 ++ if (!strcmp(sec_name(sym->st_shndx), ".text"))
3171 ++ continue;
3172 ++#endif
3173 + if (r_type == R_386_PC32) {
3174 + /* PC relative relocations don't need to be adjusted */
3175 + }
3176 +@@ -631,6 +692,7 @@ int main(int argc, char **argv)
3177 + fname, strerror(errno));
3178 + }
3179 + read_ehdr(fp);
3180 ++ read_phdrs(fp);
3181 + read_shdrs(fp);
3182 + read_strtabs(fp);
3183 + read_symtabs(fp);
3184 +diff -urNp linux-2.6.27.10/arch/x86/boot/cpucheck.c linux-2.6.27.10/arch/x86/boot/cpucheck.c
3185 +--- linux-2.6.27.10/arch/x86/boot/cpucheck.c 2008-11-07 12:55:34.000000000 -0500
3186 ++++ linux-2.6.27.10/arch/x86/boot/cpucheck.c 2008-11-18 03:38:44.000000000 -0500
3187 +@@ -74,7 +74,7 @@ static int has_fpu(void)
3188 + u16 fcw = -1, fsw = -1;
3189 + u32 cr0;
3190 +
3191 +- asm("movl %%cr0,%0" : "=r" (cr0));
3192 ++ asm volatile("movl %%cr0,%0" : "=r" (cr0));
3193 + if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
3194 + cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
3195 + asm volatile("movl %0,%%cr0" : : "r" (cr0));
3196 +@@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
3197 + {
3198 + u32 f0, f1;
3199 +
3200 +- asm("pushfl ; "
3201 ++ asm volatile("pushfl ; "
3202 + "pushfl ; "
3203 + "popl %0 ; "
3204 + "movl %0,%1 ; "
3205 +@@ -115,7 +115,7 @@ static void get_flags(void)
3206 + set_bit(X86_FEATURE_FPU, cpu.flags);
3207 +
3208 + if (has_eflag(X86_EFLAGS_ID)) {
3209 +- asm("cpuid"
3210 ++ asm volatile("cpuid"
3211 + : "=a" (max_intel_level),
3212 + "=b" (cpu_vendor[0]),
3213 + "=d" (cpu_vendor[1]),
3214 +@@ -124,7 +124,7 @@ static void get_flags(void)
3215 +
3216 + if (max_intel_level >= 0x00000001 &&
3217 + max_intel_level <= 0x0000ffff) {
3218 +- asm("cpuid"
3219 ++ asm volatile("cpuid"
3220 + : "=a" (tfms),
3221 + "=c" (cpu.flags[4]),
3222 + "=d" (cpu.flags[0])
3223 +@@ -136,7 +136,7 @@ static void get_flags(void)
3224 + cpu.model += ((tfms >> 16) & 0xf) << 4;
3225 + }
3226 +
3227 +- asm("cpuid"
3228 ++ asm volatile("cpuid"
3229 + : "=a" (max_amd_level)
3230 + : "a" (0x80000000)
3231 + : "ebx", "ecx", "edx");
3232 +@@ -144,7 +144,7 @@ static void get_flags(void)
3233 + if (max_amd_level >= 0x80000001 &&
3234 + max_amd_level <= 0x8000ffff) {
3235 + u32 eax = 0x80000001;
3236 +- asm("cpuid"
3237 ++ asm volatile("cpuid"
3238 + : "+a" (eax),
3239 + "=c" (cpu.flags[6]),
3240 + "=d" (cpu.flags[1])
3241 +@@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *r
3242 + u32 ecx = MSR_K7_HWCR;
3243 + u32 eax, edx;
3244 +
3245 +- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
3246 ++ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
3247 + eax &= ~(1 << 15);
3248 +- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
3249 ++ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
3250 +
3251 + get_flags(); /* Make sure it really did something */
3252 + err = check_flags();
3253 +@@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *r
3254 + u32 ecx = MSR_VIA_FCR;
3255 + u32 eax, edx;
3256 +
3257 +- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
3258 ++ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
3259 + eax |= (1<<1)|(1<<7);
3260 +- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
3261 ++ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
3262 +
3263 + set_bit(X86_FEATURE_CX8, cpu.flags);
3264 + err = check_flags();
3265 +@@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *r
3266 + u32 eax, edx;
3267 + u32 level = 1;
3268 +
3269 +- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
3270 +- asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
3271 +- asm("cpuid"
3272 ++ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
3273 ++ asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
3274 ++ asm volatile("cpuid"
3275 + : "+a" (level), "=d" (cpu.flags[0])
3276 + : : "ecx", "ebx");
3277 +- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
3278 ++ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
3279 +
3280 + err = check_flags();
3281 + }
3282 +diff -urNp linux-2.6.27.10/arch/x86/boot/edd.c linux-2.6.27.10/arch/x86/boot/edd.c
3283 +--- linux-2.6.27.10/arch/x86/boot/edd.c 2008-11-07 12:55:34.000000000 -0500
3284 ++++ linux-2.6.27.10/arch/x86/boot/edd.c 2008-11-18 03:38:44.000000000 -0500
3285 +@@ -76,7 +76,7 @@ static int get_edd_info(u8 devno, struct
3286 + ax = 0x4100;
3287 + bx = EDDMAGIC1;
3288 + dx = devno;
3289 +- asm("pushfl; stc; int $0x13; setc %%al; popfl"
3290 ++ asm volatile("pushfl; stc; int $0x13; setc %%al; popfl"
3291 + : "+a" (ax), "+b" (bx), "=c" (cx), "+d" (dx)
3292 + : : "esi", "edi");
3293 +
3294 +@@ -95,7 +95,7 @@ static int get_edd_info(u8 devno, struct
3295 + ei->params.length = sizeof(ei->params);
3296 + ax = 0x4800;
3297 + dx = devno;
3298 +- asm("pushfl; int $0x13; popfl"
3299 ++ asm volatile("pushfl; int $0x13; popfl"
3300 + : "+a" (ax), "+d" (dx), "=m" (ei->params)
3301 + : "S" (&ei->params)
3302 + : "ebx", "ecx", "edi");
3303 +@@ -106,7 +106,7 @@ static int get_edd_info(u8 devno, struct
3304 + ax = 0x0800;
3305 + dx = devno;
3306 + di = 0;
3307 +- asm("pushw %%es; "
3308 ++ asm volatile("pushw %%es; "
3309 + "movw %%di,%%es; "
3310 + "pushfl; stc; int $0x13; setc %%al; popfl; "
3311 + "popw %%es"
3312 +diff -urNp linux-2.6.27.10/arch/x86/boot/main.c linux-2.6.27.10/arch/x86/boot/main.c
3313 +--- linux-2.6.27.10/arch/x86/boot/main.c 2008-11-07 12:55:34.000000000 -0500
3314 ++++ linux-2.6.27.10/arch/x86/boot/main.c 2008-11-18 03:38:44.000000000 -0500
3315 +@@ -78,7 +78,7 @@ static void query_ist(void)
3316 + if (cpu.level < 6)
3317 + return;
3318 +
3319 +- asm("int $0x15"
3320 ++ asm volatile("int $0x15"
3321 + : "=a" (boot_params.ist_info.signature),
3322 + "=b" (boot_params.ist_info.command),
3323 + "=c" (boot_params.ist_info.event),
3324 +diff -urNp linux-2.6.27.10/arch/x86/boot/mca.c linux-2.6.27.10/arch/x86/boot/mca.c
3325 +--- linux-2.6.27.10/arch/x86/boot/mca.c 2008-11-07 12:55:34.000000000 -0500
3326 ++++ linux-2.6.27.10/arch/x86/boot/mca.c 2008-11-18 03:38:44.000000000 -0500
3327 +@@ -19,7 +19,7 @@ int query_mca(void)
3328 + u8 err;
3329 + u16 es, bx, len;
3330 +
3331 +- asm("pushw %%es ; "
3332 ++ asm volatile("pushw %%es ; "
3333 + "int $0x15 ; "
3334 + "setc %0 ; "
3335 + "movw %%es, %1 ; "
3336 +diff -urNp linux-2.6.27.10/arch/x86/boot/memory.c linux-2.6.27.10/arch/x86/boot/memory.c
3337 +--- linux-2.6.27.10/arch/x86/boot/memory.c 2008-11-07 12:55:34.000000000 -0500
3338 ++++ linux-2.6.27.10/arch/x86/boot/memory.c 2008-11-18 03:38:44.000000000 -0500
3339 +@@ -30,7 +30,7 @@ static int detect_memory_e820(void)
3340 + /* Important: %edx is clobbered by some BIOSes,
3341 + so it must be either used for the error output
3342 + or explicitly marked clobbered. */
3343 +- asm("int $0x15; setc %0"
3344 ++ asm volatile("int $0x15; setc %0"
3345 + : "=d" (err), "+b" (next), "=a" (id), "+c" (size),
3346 + "=m" (*desc)
3347 + : "D" (desc), "d" (SMAP), "a" (0xe820));
3348 +@@ -65,7 +65,7 @@ static int detect_memory_e801(void)
3349 +
3350 + bx = cx = dx = 0;
3351 + ax = 0xe801;
3352 +- asm("stc; int $0x15; setc %0"
3353 ++ asm volatile("stc; int $0x15; setc %0"
3354 + : "=m" (err), "+a" (ax), "+b" (bx), "+c" (cx), "+d" (dx));
3355 +
3356 + if (err)
3357 +@@ -95,7 +95,7 @@ static int detect_memory_88(void)
3358 + u8 err;
3359 +
3360 + ax = 0x8800;
3361 +- asm("stc; int $0x15; setc %0" : "=bcdm" (err), "+a" (ax));
3362 ++ asm volatile("stc; int $0x15; setc %0" : "=bcdm" (err), "+a" (ax));
3363 +
3364 + boot_params.screen_info.ext_mem_k = ax;
3365 +
3366 +diff -urNp linux-2.6.27.10/arch/x86/boot/video.c linux-2.6.27.10/arch/x86/boot/video.c
3367 +--- linux-2.6.27.10/arch/x86/boot/video.c 2008-11-07 12:55:34.000000000 -0500
3368 ++++ linux-2.6.27.10/arch/x86/boot/video.c 2008-11-18 03:38:44.000000000 -0500
3369 +@@ -23,7 +23,7 @@ static void store_cursor_position(void)
3370 +
3371 + ax = 0x0300;
3372 + bx = 0;
3373 +- asm(INT10
3374 ++ asm volatile(INT10
3375 + : "=d" (curpos), "+a" (ax), "+b" (bx)
3376 + : : "ecx", "esi", "edi");
3377 +
3378 +@@ -38,7 +38,7 @@ static void store_video_mode(void)
3379 + /* N.B.: the saving of the video page here is a bit silly,
3380 + since we pretty much assume page 0 everywhere. */
3381 + ax = 0x0f00;
3382 +- asm(INT10
3383 ++ asm volatile(INT10
3384 + : "+a" (ax), "=b" (page)
3385 + : : "ecx", "edx", "esi", "edi");
3386 +
3387 +diff -urNp linux-2.6.27.10/arch/x86/boot/video-vesa.c linux-2.6.27.10/arch/x86/boot/video-vesa.c
3388 +--- linux-2.6.27.10/arch/x86/boot/video-vesa.c 2008-11-07 12:55:34.000000000 -0500
3389 ++++ linux-2.6.27.10/arch/x86/boot/video-vesa.c 2008-11-18 03:38:44.000000000 -0500
3390 +@@ -41,7 +41,7 @@ static int vesa_probe(void)
3391 +
3392 + ax = 0x4f00;
3393 + di = (size_t)&vginfo;
3394 +- asm(INT10
3395 ++ asm volatile(INT10
3396 + : "+a" (ax), "+D" (di), "=m" (vginfo)
3397 + : : "ebx", "ecx", "edx", "esi");
3398 +
3399 +@@ -68,7 +68,7 @@ static int vesa_probe(void)
3400 + ax = 0x4f01;
3401 + cx = mode;
3402 + di = (size_t)&vminfo;
3403 +- asm(INT10
3404 ++ asm volatile(INT10
3405 + : "+a" (ax), "+c" (cx), "+D" (di), "=m" (vminfo)
3406 + : : "ebx", "edx", "esi");
3407 +
3408 +@@ -123,7 +123,7 @@ static int vesa_set_mode(struct mode_inf
3409 + ax = 0x4f01;
3410 + cx = vesa_mode;
3411 + di = (size_t)&vminfo;
3412 +- asm(INT10
3413 ++ asm volatile(INT10
3414 + : "+a" (ax), "+c" (cx), "+D" (di), "=m" (vminfo)
3415 + : : "ebx", "edx", "esi");
3416 +
3417 +@@ -203,19 +203,20 @@ static void vesa_dac_set_8bits(void)
3418 + /* Save the VESA protected mode info */
3419 + static void vesa_store_pm_info(void)
3420 + {
3421 +- u16 ax, bx, di, es;
3422 ++ u16 ax, bx, cx, di, es;
3423 +
3424 + ax = 0x4f0a;
3425 +- bx = di = 0;
3426 +- asm("pushw %%es; "INT10"; movw %%es,%0; popw %%es"
3427 +- : "=d" (es), "+a" (ax), "+b" (bx), "+D" (di)
3428 +- : : "ecx", "esi");
3429 ++ bx = cx = di = 0;
3430 ++ asm volatile("pushw %%es; "INT10"; movw %%es,%0; popw %%es"
3431 ++ : "=d" (es), "+a" (ax), "+b" (bx), "+c" (cx), "+D" (di)
3432 ++ : : "esi");
3433 +
3434 + if (ax != 0x004f)
3435 + return;
3436 +
3437 + boot_params.screen_info.vesapm_seg = es;
3438 + boot_params.screen_info.vesapm_off = di;
3439 ++ boot_params.screen_info.vesapm_size = cx;
3440 + }
3441 +
3442 + /*
3443 +@@ -269,7 +270,7 @@ void vesa_store_edid(void)
3444 + /* Note: The VBE DDC spec is different from the main VESA spec;
3445 + we genuinely have to assume all registers are destroyed here. */
3446 +
3447 +- asm("pushw %%es; movw %2,%%es; "INT10"; popw %%es"
3448 ++ asm volatile("pushw %%es; movw %2,%%es; "INT10"; popw %%es"
3449 + : "+a" (ax), "+b" (bx)
3450 + : "c" (cx), "D" (di)
3451 + : "esi");
3452 +@@ -285,7 +286,7 @@ void vesa_store_edid(void)
3453 + cx = 0; /* Controller 0 */
3454 + dx = 0; /* EDID block number */
3455 + di =(size_t) &boot_params.edid_info; /* (ES:)Pointer to block */
3456 +- asm(INT10
3457 ++ asm volatile(INT10
3458 + : "+a" (ax), "+b" (bx), "+d" (dx), "=m" (boot_params.edid_info)
3459 + : "c" (cx), "D" (di)
3460 + : "esi");
3461 +diff -urNp linux-2.6.27.10/arch/x86/boot/video-vga.c linux-2.6.27.10/arch/x86/boot/video-vga.c
3462 +--- linux-2.6.27.10/arch/x86/boot/video-vga.c 2008-11-07 12:55:34.000000000 -0500
3463 ++++ linux-2.6.27.10/arch/x86/boot/video-vga.c 2008-11-18 03:38:44.000000000 -0500
3464 +@@ -225,7 +225,7 @@ static int vga_probe(void)
3465 + };
3466 + u8 vga_flag;
3467 +
3468 +- asm(INT10
3469 ++ asm volatile(INT10
3470 + : "=b" (ega_bx)
3471 + : "a" (0x1200), "b" (0x10) /* Check EGA/VGA */
3472 + : "ecx", "edx", "esi", "edi");
3473 +@@ -237,7 +237,7 @@ static int vga_probe(void)
3474 + /* If we have MDA/CGA/HGC then BL will be unchanged at 0x10 */
3475 + if ((u8)ega_bx != 0x10) {
3476 + /* EGA/VGA */
3477 +- asm(INT10
3478 ++ asm volatile(INT10
3479 + : "=a" (vga_flag)
3480 + : "a" (0x1a00)
3481 + : "ebx", "ecx", "edx", "esi", "edi");
3482 +diff -urNp linux-2.6.27.10/arch/x86/boot/voyager.c linux-2.6.27.10/arch/x86/boot/voyager.c
3483 +--- linux-2.6.27.10/arch/x86/boot/voyager.c 2008-11-07 12:55:34.000000000 -0500
3484 ++++ linux-2.6.27.10/arch/x86/boot/voyager.c 2008-11-18 03:38:44.000000000 -0500
3485 +@@ -23,7 +23,7 @@ int query_voyager(void)
3486 +
3487 + data_ptr[0] = 0xff; /* Flag on config not found(?) */
3488 +
3489 +- asm("pushw %%es ; "
3490 ++ asm volatile("pushw %%es ; "
3491 + "int $0x15 ; "
3492 + "setc %0 ; "
3493 + "movw %%es, %1 ; "
3494 +diff -urNp linux-2.6.27.10/arch/x86/ia32/ia32_signal.c linux-2.6.27.10/arch/x86/ia32/ia32_signal.c
3495 +--- linux-2.6.27.10/arch/x86/ia32/ia32_signal.c 2008-11-07 12:55:34.000000000 -0500
3496 ++++ linux-2.6.27.10/arch/x86/ia32/ia32_signal.c 2008-11-18 03:38:44.000000000 -0500
3497 +@@ -535,6 +535,7 @@ int ia32_setup_rt_frame(int sig, struct
3498 + __NR_ia32_rt_sigreturn,
3499 + 0x80cd,
3500 + 0,
3501 ++ 0
3502 + };
3503 +
3504 + frame = get_sigframe(ka, regs, sizeof(*frame));
3505 +diff -urNp linux-2.6.27.10/arch/x86/Kconfig linux-2.6.27.10/arch/x86/Kconfig
3506 +--- linux-2.6.27.10/arch/x86/Kconfig 2008-11-17 20:03:30.000000000 -0500
3507 ++++ linux-2.6.27.10/arch/x86/Kconfig 2008-11-18 03:38:44.000000000 -0500
3508 +@@ -912,7 +912,7 @@ config PAGE_OFFSET
3509 + hex
3510 + default 0xB0000000 if VMSPLIT_3G_OPT
3511 + default 0x80000000 if VMSPLIT_2G
3512 +- default 0x78000000 if VMSPLIT_2G_OPT
3513 ++ default 0x70000000 if VMSPLIT_2G_OPT
3514 + default 0x40000000 if VMSPLIT_1G
3515 + default 0xC0000000
3516 + depends on X86_32
3517 +@@ -1293,8 +1293,7 @@ config KEXEC_JUMP
3518 + config PHYSICAL_START
3519 + hex "Physical address where the kernel is loaded" if (EMBEDDED || CRASH_DUMP)
3520 + default "0x1000000" if X86_NUMAQ
3521 +- default "0x200000" if X86_64
3522 +- default "0x100000"
3523 ++ default "0x200000"
3524 + help
3525 + This gives the physical address where the kernel is loaded.
3526 +
3527 +@@ -1386,9 +1385,9 @@ config HOTPLUG_CPU
3528 + suspend.
3529 +
3530 + config COMPAT_VDSO
3531 +- def_bool y
3532 ++ def_bool n
3533 + prompt "Compat VDSO support"
3534 +- depends on X86_32 || IA32_EMULATION
3535 ++ depends on (X86_32 || IA32_EMULATION) && !PAX_NOEXEC
3536 + help
3537 + Map the 32-bit VDSO to the predictable old-style address too.
3538 + ---help---
3539 +diff -urNp linux-2.6.27.10/arch/x86/Kconfig.cpu linux-2.6.27.10/arch/x86/Kconfig.cpu
3540 +--- linux-2.6.27.10/arch/x86/Kconfig.cpu 2008-11-07 12:55:34.000000000 -0500
3541 ++++ linux-2.6.27.10/arch/x86/Kconfig.cpu 2008-11-18 03:38:44.000000000 -0500
3542 +@@ -340,7 +340,7 @@ config X86_PPRO_FENCE
3543 +
3544 + config X86_F00F_BUG
3545 + def_bool y
3546 +- depends on M586MMX || M586TSC || M586 || M486 || M386
3547 ++ depends on (M586MMX || M586TSC || M586 || M486 || M386) && !PAX_KERNEXEC
3548 +
3549 + config X86_WP_WORKS_OK
3550 + def_bool y
3551 +@@ -360,7 +360,7 @@ config X86_POPAD_OK
3552 +
3553 + config X86_ALIGNMENT_16
3554 + def_bool y
3555 +- depends on MWINCHIP3D || MWINCHIP2 || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
3556 ++ depends on MWINCHIP3D || MWINCHIP2 || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
3557 +
3558 + config X86_INTEL_USERCOPY
3559 + def_bool y
3560 +@@ -406,7 +406,7 @@ config X86_CMPXCHG64
3561 + # generates cmov.
3562 + config X86_CMOV
3563 + def_bool y
3564 +- depends on (MK7 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || X86_64)
3565 ++ depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || X86_64)
3566 +
3567 + config X86_MINIMUM_CPU_FAMILY
3568 + int
3569 +diff -urNp linux-2.6.27.10/arch/x86/Kconfig.debug linux-2.6.27.10/arch/x86/Kconfig.debug
3570 +--- linux-2.6.27.10/arch/x86/Kconfig.debug 2008-11-07 12:55:34.000000000 -0500
3571 ++++ linux-2.6.27.10/arch/x86/Kconfig.debug 2008-11-18 03:38:44.000000000 -0500
3572 +@@ -94,7 +94,7 @@ config X86_PTDUMP
3573 + config DEBUG_RODATA
3574 + bool "Write protect kernel read-only data structures"
3575 + default y
3576 +- depends on DEBUG_KERNEL
3577 ++ depends on DEBUG_KERNEL && BROKEN
3578 + help
3579 + Mark the kernel read-only data as write-protected in the pagetables,
3580 + in order to catch accidental (and incorrect) writes to such const
3581 +diff -urNp linux-2.6.27.10/arch/x86/kernel/acpi/boot.c linux-2.6.27.10/arch/x86/kernel/acpi/boot.c
3582 +--- linux-2.6.27.10/arch/x86/kernel/acpi/boot.c 2008-12-10 22:35:36.000000000 -0500
3583 ++++ linux-2.6.27.10/arch/x86/kernel/acpi/boot.c 2008-12-10 22:35:46.000000000 -0500
3584 +@@ -1640,7 +1640,7 @@ static struct dmi_system_id __initdata a
3585 + DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq 6715b"),
3586 + },
3587 + },
3588 +- {}
3589 ++ { NULL, NULL, {{0, NULL}}, NULL}
3590 + };
3591 +
3592 + /*
3593 +diff -urNp linux-2.6.27.10/arch/x86/kernel/acpi/realmode/wakeup.S linux-2.6.27.10/arch/x86/kernel/acpi/realmode/wakeup.S
3594 +--- linux-2.6.27.10/arch/x86/kernel/acpi/realmode/wakeup.S 2008-11-07 12:55:34.000000000 -0500
3595 ++++ linux-2.6.27.10/arch/x86/kernel/acpi/realmode/wakeup.S 2008-11-18 03:38:44.000000000 -0500
3596 +@@ -104,7 +104,7 @@ _start:
3597 + movl %eax, %ecx
3598 + orl %edx, %ecx
3599 + jz 1f
3600 +- movl $0xc0000080, %ecx
3601 ++ mov $MSR_EFER, %ecx
3602 + wrmsr
3603 + 1:
3604 +
3605 +diff -urNp linux-2.6.27.10/arch/x86/kernel/acpi/sleep.c linux-2.6.27.10/arch/x86/kernel/acpi/sleep.c
3606 +--- linux-2.6.27.10/arch/x86/kernel/acpi/sleep.c 2008-11-07 12:55:34.000000000 -0500
3607 ++++ linux-2.6.27.10/arch/x86/kernel/acpi/sleep.c 2008-11-18 11:45:34.000000000 -0500
3608 +@@ -37,6 +37,10 @@ int acpi_save_state_mem(void)
3609 + {
3610 + struct wakeup_header *header;
3611 +
3612 ++#if defined(CONFIG_64BIT) && defined(CONFIG_SMP) && defined(CONFIG_PAX_KERNEXEC)
3613 ++ unsigned long cr0;
3614 ++#endif
3615 ++
3616 + if (!acpi_realmode) {
3617 + printk(KERN_ERR "Could not allocate memory during boot, "
3618 + "S3 disabled\n");
3619 +@@ -99,8 +103,18 @@ int acpi_save_state_mem(void)
3620 + header->trampoline_segment = setup_trampoline() >> 4;
3621 + #ifdef CONFIG_SMP
3622 + stack_start.sp = temp_stack + 4096;
3623 ++
3624 ++#ifdef CONFIG_PAX_KERNEXEC
3625 ++ pax_open_kernel(cr0);
3626 ++#endif
3627 ++
3628 + early_gdt_descr.address =
3629 + (unsigned long)get_cpu_gdt_table(smp_processor_id());
3630 ++
3631 ++#ifdef CONFIG_PAX_KERNEXEC
3632 ++ pax_close_kernel(cr0);
3633 ++#endif
3634 ++
3635 + #endif
3636 + initial_code = (unsigned long)wakeup_long64;
3637 + saved_magic = 0x123456789abcdef0;
3638 +diff -urNp linux-2.6.27.10/arch/x86/kernel/acpi/wakeup_32.S linux-2.6.27.10/arch/x86/kernel/acpi/wakeup_32.S
3639 +--- linux-2.6.27.10/arch/x86/kernel/acpi/wakeup_32.S 2008-11-07 12:55:34.000000000 -0500
3640 ++++ linux-2.6.27.10/arch/x86/kernel/acpi/wakeup_32.S 2008-11-18 03:38:44.000000000 -0500
3641 +@@ -30,13 +30,11 @@ wakeup_pmode_return:
3642 + # and restore the stack ... but you need gdt for this to work
3643 + movl saved_context_esp, %esp
3644 +
3645 +- movl %cs:saved_magic, %eax
3646 +- cmpl $0x12345678, %eax
3647 ++ cmpl $0x12345678, saved_magic
3648 + jne bogus_magic
3649 +
3650 + # jump to place where we left off
3651 +- movl saved_eip, %eax
3652 +- jmp *%eax
3653 ++ jmp *(saved_eip)
3654 +
3655 + bogus_magic:
3656 + jmp bogus_magic
3657 +diff -urNp linux-2.6.27.10/arch/x86/kernel/alternative.c linux-2.6.27.10/arch/x86/kernel/alternative.c
3658 +--- linux-2.6.27.10/arch/x86/kernel/alternative.c 2008-11-07 12:55:34.000000000 -0500
3659 ++++ linux-2.6.27.10/arch/x86/kernel/alternative.c 2008-11-18 03:38:44.000000000 -0500
3660 +@@ -393,7 +393,7 @@ void apply_paravirt(struct paravirt_patc
3661 +
3662 + BUG_ON(p->len > MAX_PATCH_LEN);
3663 + /* prep the buffer with the original instructions */
3664 +- memcpy(insnbuf, p->instr, p->len);
3665 ++ memcpy(insnbuf, ktla_ktva(p->instr), p->len);
3666 + used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
3667 + (unsigned long)p->instr, p->len);
3668 +
3669 +@@ -473,11 +473,26 @@ void __init alternative_instructions(voi
3670 + * instructions. And on the local CPU you need to be protected again NMI or MCE
3671 + * handlers seeing an inconsistent instruction while you patch.
3672 + */
3673 +-void *text_poke_early(void *addr, const void *opcode, size_t len)
3674 ++void *__kprobes text_poke_early(void *addr, const void *opcode, size_t len)
3675 + {
3676 + unsigned long flags;
3677 ++
3678 ++#ifdef CONFIG_PAX_KERNEXEC
3679 ++ unsigned long cr0;
3680 ++#endif
3681 ++
3682 + local_irq_save(flags);
3683 +- memcpy(addr, opcode, len);
3684 ++
3685 ++#ifdef CONFIG_PAX_KERNEXEC
3686 ++ pax_open_kernel(cr0);
3687 ++#endif
3688 ++
3689 ++ memcpy(ktla_ktva(addr), opcode, len);
3690 ++
3691 ++#ifdef CONFIG_PAX_KERNEXEC
3692 ++ pax_close_kernel(cr0);
3693 ++#endif
3694 ++
3695 + local_irq_restore(flags);
3696 + sync_core();
3697 + /* Could also do a CLFLUSH here to speed up CPU recovery; but
3698 +@@ -498,33 +513,27 @@ void *text_poke_early(void *addr, const
3699 + */
3700 + void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
3701 + {
3702 +- unsigned long flags;
3703 +- char *vaddr;
3704 +- int nr_pages = 2;
3705 ++ unsigned char *vaddr = ktla_ktva(addr);
3706 + struct page *pages[2];
3707 +- int i;
3708 ++ size_t i;
3709 ++
3710 ++ if (!core_kernel_text((unsigned long)addr)
3711 +
3712 +- if (!core_kernel_text((unsigned long)addr)) {
3713 +- pages[0] = vmalloc_to_page(addr);
3714 +- pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
3715 ++#if defined(CONFIG_X86_32) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
3716 ++ && (vaddr < MODULES_VADDR || MODULES_END < vaddr)
3717 ++#endif
3718 ++
3719 ++ ) {
3720 ++ pages[0] = vmalloc_to_page(vaddr);
3721 ++ pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
3722 + } else {
3723 +- pages[0] = virt_to_page(addr);
3724 ++ pages[0] = virt_to_page(vaddr);
3725 + WARN_ON(!PageReserved(pages[0]));
3726 +- pages[1] = virt_to_page(addr + PAGE_SIZE);
3727 ++ pages[1] = virt_to_page(vaddr + PAGE_SIZE);
3728 + }
3729 + BUG_ON(!pages[0]);
3730 +- if (!pages[1])
3731 +- nr_pages = 1;
3732 +- vaddr = vmap(pages, nr_pages, VM_MAP, PAGE_KERNEL);
3733 +- BUG_ON(!vaddr);
3734 +- local_irq_save(flags);
3735 +- memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
3736 +- local_irq_restore(flags);
3737 +- vunmap(vaddr);
3738 +- sync_core();
3739 +- /* Could also do a CLFLUSH here to speed up CPU recovery; but
3740 +- that causes hangs on some VIA CPUs. */
3741 ++ text_poke_early(addr, opcode, len);
3742 + for (i = 0; i < len; i++)
3743 +- BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
3744 ++ BUG_ON((vaddr)[i] != ((unsigned char *)opcode)[i]);
3745 + return addr;
3746 + }
3747 +diff -urNp linux-2.6.27.10/arch/x86/kernel/apm_32.c linux-2.6.27.10/arch/x86/kernel/apm_32.c
3748 +--- linux-2.6.27.10/arch/x86/kernel/apm_32.c 2008-11-07 12:55:34.000000000 -0500
3749 ++++ linux-2.6.27.10/arch/x86/kernel/apm_32.c 2008-11-18 03:38:44.000000000 -0500
3750 +@@ -408,7 +408,7 @@ static DECLARE_WAIT_QUEUE_HEAD(apm_waitq
3751 + static DECLARE_WAIT_QUEUE_HEAD(apm_suspend_waitqueue);
3752 + static struct apm_user *user_list;
3753 + static DEFINE_SPINLOCK(user_list_lock);
3754 +-static const struct desc_struct bad_bios_desc = { { { 0, 0x00409200 } } };
3755 ++static const struct desc_struct bad_bios_desc = { { { 0, 0x00409300 } } };
3756 +
3757 + static const char driver_version[] = "1.16ac"; /* no spaces */
3758 +
3759 +@@ -603,19 +603,42 @@ static u8 apm_bios_call(u32 func, u32 eb
3760 + struct desc_struct save_desc_40;
3761 + struct desc_struct *gdt;
3762 +
3763 ++#ifdef CONFIG_PAX_KERNEXEC
3764 ++ unsigned long cr0;
3765 ++#endif
3766 ++
3767 + cpus = apm_save_cpus();
3768 +
3769 + cpu = get_cpu();
3770 + gdt = get_cpu_gdt_table(cpu);
3771 + save_desc_40 = gdt[0x40 / 8];
3772 ++
3773 ++#ifdef CONFIG_PAX_KERNEXEC
3774 ++ pax_open_kernel(cr0);
3775 ++#endif
3776 ++
3777 + gdt[0x40 / 8] = bad_bios_desc;
3778 +
3779 ++#ifdef CONFIG_PAX_KERNEXEC
3780 ++ pax_close_kernel(cr0);
3781 ++#endif
3782 ++
3783 + apm_irq_save(flags);
3784 + APM_DO_SAVE_SEGS;
3785 + apm_bios_call_asm(func, ebx_in, ecx_in, eax, ebx, ecx, edx, esi);
3786 + APM_DO_RESTORE_SEGS;
3787 + apm_irq_restore(flags);
3788 ++
3789 ++#ifdef CONFIG_PAX_KERNEXEC
3790 ++ pax_open_kernel(cr0);
3791 ++#endif
3792 ++
3793 + gdt[0x40 / 8] = save_desc_40;
3794 ++
3795 ++#ifdef CONFIG_PAX_KERNEXEC
3796 ++ pax_close_kernel(cr0);
3797 ++#endif
3798 ++
3799 + put_cpu();
3800 + apm_restore_cpus(cpus);
3801 +
3802 +@@ -646,19 +669,42 @@ static u8 apm_bios_call_simple(u32 func,
3803 + struct desc_struct save_desc_40;
3804 + struct desc_struct *gdt;
3805 +
3806 ++#ifdef CONFIG_PAX_KERNEXEC
3807 ++ unsigned long cr0;
3808 ++#endif
3809 ++
3810 + cpus = apm_save_cpus();
3811 +
3812 + cpu = get_cpu();
3813 + gdt = get_cpu_gdt_table(cpu);
3814 + save_desc_40 = gdt[0x40 / 8];
3815 ++
3816 ++#ifdef CONFIG_PAX_KERNEXEC
3817 ++ pax_open_kernel(cr0);
3818 ++#endif
3819 ++
3820 + gdt[0x40 / 8] = bad_bios_desc;
3821 +
3822 ++#ifdef CONFIG_PAX_KERNEXEC
3823 ++ pax_close_kernel(cr0);
3824 ++#endif
3825 ++
3826 + apm_irq_save(flags);
3827 + APM_DO_SAVE_SEGS;
3828 + error = apm_bios_call_simple_asm(func, ebx_in, ecx_in, eax);
3829 + APM_DO_RESTORE_SEGS;
3830 + apm_irq_restore(flags);
3831 ++
3832 ++#ifdef CONFIG_PAX_KERNEXEC
3833 ++ pax_open_kernel(cr0);
3834 ++#endif
3835 ++
3836 + gdt[0x40 / 8] = save_desc_40;
3837 ++
3838 ++#ifdef CONFIG_PAX_KERNEXEC
3839 ++ pax_close_kernel(cr0);
3840 ++#endif
3841 ++
3842 + put_cpu();
3843 + apm_restore_cpus(cpus);
3844 + return error;
3845 +@@ -930,7 +976,7 @@ recalc:
3846 +
3847 + static void apm_power_off(void)
3848 + {
3849 +- unsigned char po_bios_call[] = {
3850 ++ const unsigned char po_bios_call[] = {
3851 + 0xb8, 0x00, 0x10, /* movw $0x1000,ax */
3852 + 0x8e, 0xd0, /* movw ax,ss */
3853 + 0xbc, 0x00, 0xf0, /* movw $0xf000,sp */
3854 +@@ -1877,7 +1923,10 @@ static const struct file_operations apm_
3855 + static struct miscdevice apm_device = {
3856 + APM_MINOR_DEV,
3857 + "apm_bios",
3858 +- &apm_bios_fops
3859 ++ &apm_bios_fops,
3860 ++ {NULL, NULL},
3861 ++ NULL,
3862 ++ NULL
3863 + };
3864 +
3865 +
3866 +@@ -2198,7 +2247,7 @@ static struct dmi_system_id __initdata a
3867 + { DMI_MATCH(DMI_SYS_VENDOR, "IBM"), },
3868 + },
3869 +
3870 +- { }
3871 ++ { NULL, NULL, {DMI_MATCH(DMI_NONE, NULL)}, NULL}
3872 + };
3873 +
3874 + /*
3875 +@@ -2216,6 +2265,10 @@ static int __init apm_init(void)
3876 + struct desc_struct *gdt;
3877 + int err;
3878 +
3879 ++#ifdef CONFIG_PAX_KERNEXEC
3880 ++ unsigned long cr0;
3881 ++#endif
3882 ++
3883 + dmi_check_system(apm_dmi_table);
3884 +
3885 + if (apm_info.bios.version == 0 || paravirt_enabled() || machine_is_olpc()) {
3886 +@@ -2289,9 +2342,18 @@ static int __init apm_init(void)
3887 + * This is for buggy BIOS's that refer to (real mode) segment 0x40
3888 + * even though they are called in protected mode.
3889 + */
3890 ++
3891 ++#ifdef CONFIG_PAX_KERNEXEC
3892 ++ pax_open_kernel(cr0);
3893 ++#endif
3894 ++
3895 + set_base(bad_bios_desc, __va((unsigned long)0x40 << 4));
3896 + _set_limit((char *)&bad_bios_desc, 4095 - (0x40 << 4));
3897 +
3898 ++#ifdef CONFIG_PAX_KERNEXEC
3899 ++ pax_close_kernel(cr0);
3900 ++#endif
3901 ++
3902 + /*
3903 + * Set up the long jump entry point to the APM BIOS, which is called
3904 + * from inline assembly.
3905 +@@ -2310,6 +2372,11 @@ static int __init apm_init(void)
3906 + * code to that CPU.
3907 + */
3908 + gdt = get_cpu_gdt_table(0);
3909 ++
3910 ++#ifdef CONFIG_PAX_KERNEXEC
3911 ++ pax_open_kernel(cr0);
3912 ++#endif
3913 ++
3914 + set_base(gdt[APM_CS >> 3],
3915 + __va((unsigned long)apm_info.bios.cseg << 4));
3916 + set_base(gdt[APM_CS_16 >> 3],
3917 +@@ -2317,6 +2384,10 @@ static int __init apm_init(void)
3918 + set_base(gdt[APM_DS >> 3],
3919 + __va((unsigned long)apm_info.bios.dseg << 4));
3920 +
3921 ++#ifdef CONFIG_PAX_KERNEXEC
3922 ++ pax_close_kernel(cr0);
3923 ++#endif
3924 ++
3925 + proc_create("apm", 0, NULL, &apm_file_ops);
3926 +
3927 + kapmd_task = kthread_create(apm, NULL, "kapmd");
3928 +diff -urNp linux-2.6.27.10/arch/x86/kernel/asm-offsets_32.c linux-2.6.27.10/arch/x86/kernel/asm-offsets_32.c
3929 +--- linux-2.6.27.10/arch/x86/kernel/asm-offsets_32.c 2008-11-07 12:55:34.000000000 -0500
3930 ++++ linux-2.6.27.10/arch/x86/kernel/asm-offsets_32.c 2008-11-18 03:38:44.000000000 -0500
3931 +@@ -100,6 +100,7 @@ void foo(void)
3932 + DEFINE(PTRS_PER_PTE, PTRS_PER_PTE);
3933 + DEFINE(PTRS_PER_PMD, PTRS_PER_PMD);
3934 + DEFINE(PTRS_PER_PGD, PTRS_PER_PGD);
3935 ++ DEFINE(PERCPU_MODULE_RESERVE, PERCPU_MODULE_RESERVE);
3936 +
3937 + OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
3938 +
3939 +@@ -113,6 +114,7 @@ void foo(void)
3940 + OFFSET(PV_CPU_iret, pv_cpu_ops, iret);
3941 + OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
3942 + OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
3943 ++ OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
3944 + #endif
3945 +
3946 + #ifdef CONFIG_XEN
3947 +diff -urNp linux-2.6.27.10/arch/x86/kernel/asm-offsets_64.c linux-2.6.27.10/arch/x86/kernel/asm-offsets_64.c
3948 +--- linux-2.6.27.10/arch/x86/kernel/asm-offsets_64.c 2008-11-07 12:55:34.000000000 -0500
3949 ++++ linux-2.6.27.10/arch/x86/kernel/asm-offsets_64.c 2008-11-18 03:38:44.000000000 -0500
3950 +@@ -122,6 +122,7 @@ int main(void)
3951 + ENTRY(cr8);
3952 + BLANK();
3953 + #undef ENTRY
3954 ++ DEFINE(TSS_size, sizeof(struct tss_struct));
3955 + DEFINE(TSS_ist, offsetof(struct tss_struct, x86_tss.ist));
3956 + BLANK();
3957 + DEFINE(crypto_tfm_ctx_offset, offsetof(struct crypto_tfm, __crt_ctx));
3958 +diff -urNp linux-2.6.27.10/arch/x86/kernel/cpu/common_64.c linux-2.6.27.10/arch/x86/kernel/cpu/common_64.c
3959 +--- linux-2.6.27.10/arch/x86/kernel/cpu/common_64.c 2008-11-07 12:55:34.000000000 -0500
3960 ++++ linux-2.6.27.10/arch/x86/kernel/cpu/common_64.c 2008-11-18 03:38:44.000000000 -0500
3961 +@@ -37,22 +37,6 @@
3962 +
3963 + #include "cpu.h"
3964 +
3965 +-/* We need valid kernel segments for data and code in long mode too
3966 +- * IRET will check the segment types kkeil 2000/10/28
3967 +- * Also sysret mandates a special GDT layout
3968 +- */
3969 +-/* The TLS descriptors are currently at a different place compared to i386.
3970 +- Hopefully nobody expects them at a fixed place (Wine?) */
3971 +-DEFINE_PER_CPU(struct gdt_page, gdt_page) = { .gdt = {
3972 +- [GDT_ENTRY_KERNEL32_CS] = { { { 0x0000ffff, 0x00cf9b00 } } },
3973 +- [GDT_ENTRY_KERNEL_CS] = { { { 0x0000ffff, 0x00af9b00 } } },
3974 +- [GDT_ENTRY_KERNEL_DS] = { { { 0x0000ffff, 0x00cf9300 } } },
3975 +- [GDT_ENTRY_DEFAULT_USER32_CS] = { { { 0x0000ffff, 0x00cffb00 } } },
3976 +- [GDT_ENTRY_DEFAULT_USER_DS] = { { { 0x0000ffff, 0x00cff300 } } },
3977 +- [GDT_ENTRY_DEFAULT_USER_CS] = { { { 0x0000ffff, 0x00affb00 } } },
3978 +-} };
3979 +-EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
3980 +-
3981 + __u32 cleared_cpu_caps[NCAPINTS] __cpuinitdata;
3982 +
3983 + /* Current gdt points %fs at the "master" per-cpu area: after this,
3984 +@@ -457,15 +441,13 @@ cpumask_t cpu_initialized __cpuinitdata
3985 + struct x8664_pda **_cpu_pda __read_mostly;
3986 + EXPORT_SYMBOL(_cpu_pda);
3987 +
3988 +-struct desc_ptr idt_descr = { 256 * 16 - 1, (unsigned long) idt_table };
3989 ++struct desc_ptr idt_descr __read_only = { 256 * 16 - 1, (unsigned long) idt_table };
3990 +
3991 + char boot_cpu_stack[IRQSTACKSIZE] __page_aligned_bss;
3992 +
3993 + unsigned long __supported_pte_mask __read_mostly = ~0UL;
3994 + EXPORT_SYMBOL_GPL(__supported_pte_mask);
3995 +
3996 +-static int do_not_nx __cpuinitdata;
3997 +-
3998 + /* noexec=on|off
3999 + Control non executable mappings for 64bit processes.
4000 +
4001 +@@ -478,9 +460,7 @@ static int __init nonx_setup(char *str)
4002 + return -EINVAL;
4003 + if (!strncmp(str, "on", 2)) {
4004 + __supported_pte_mask |= _PAGE_NX;
4005 +- do_not_nx = 0;
4006 + } else if (!strncmp(str, "off", 3)) {
4007 +- do_not_nx = 1;
4008 + __supported_pte_mask &= ~_PAGE_NX;
4009 + }
4010 + return 0;
4011 +@@ -576,7 +556,7 @@ void __cpuinit check_efer(void)
4012 + unsigned long efer;
4013 +
4014 + rdmsrl(MSR_EFER, efer);
4015 +- if (!(efer & EFER_NX) || do_not_nx)
4016 ++ if (!(efer & EFER_NX))
4017 + __supported_pte_mask &= ~_PAGE_NX;
4018 + }
4019 +
4020 +@@ -598,7 +578,7 @@ DEFINE_PER_CPU(struct orig_ist, orig_ist
4021 + void __cpuinit cpu_init(void)
4022 + {
4023 + int cpu = stack_smp_processor_id();
4024 +- struct tss_struct *t = &per_cpu(init_tss, cpu);
4025 ++ struct tss_struct *t = init_tss + cpu;
4026 + struct orig_ist *orig_ist = &per_cpu(orig_ist, cpu);
4027 + unsigned long v;
4028 + char *estacks = NULL;
4029 +diff -urNp linux-2.6.27.10/arch/x86/kernel/cpu/common.c linux-2.6.27.10/arch/x86/kernel/cpu/common.c
4030 +--- linux-2.6.27.10/arch/x86/kernel/cpu/common.c 2008-11-07 12:55:34.000000000 -0500
4031 ++++ linux-2.6.27.10/arch/x86/kernel/cpu/common.c 2008-11-18 03:38:44.000000000 -0500
4032 +@@ -4,7 +4,6 @@
4033 + #include <linux/smp.h>
4034 + #include <linux/module.h>
4035 + #include <linux/percpu.h>
4036 +-#include <linux/bootmem.h>
4037 + #include <asm/processor.h>
4038 + #include <asm/i387.h>
4039 + #include <asm/msr.h>
4040 +@@ -22,42 +21,6 @@
4041 +
4042 + #include "cpu.h"
4043 +
4044 +-DEFINE_PER_CPU(struct gdt_page, gdt_page) = { .gdt = {
4045 +- [GDT_ENTRY_KERNEL_CS] = { { { 0x0000ffff, 0x00cf9a00 } } },
4046 +- [GDT_ENTRY_KERNEL_DS] = { { { 0x0000ffff, 0x00cf9200 } } },
4047 +- [GDT_ENTRY_DEFAULT_USER_CS] = { { { 0x0000ffff, 0x00cffa00 } } },
4048 +- [GDT_ENTRY_DEFAULT_USER_DS] = { { { 0x0000ffff, 0x00cff200 } } },
4049 +- /*
4050 +- * Segments used for calling PnP BIOS have byte granularity.
4051 +- * They code segments and data segments have fixed 64k limits,
4052 +- * the transfer segment sizes are set at run time.
4053 +- */
4054 +- /* 32-bit code */
4055 +- [GDT_ENTRY_PNPBIOS_CS32] = { { { 0x0000ffff, 0x00409a00 } } },
4056 +- /* 16-bit code */
4057 +- [GDT_ENTRY_PNPBIOS_CS16] = { { { 0x0000ffff, 0x00009a00 } } },
4058 +- /* 16-bit data */
4059 +- [GDT_ENTRY_PNPBIOS_DS] = { { { 0x0000ffff, 0x00009200 } } },
4060 +- /* 16-bit data */
4061 +- [GDT_ENTRY_PNPBIOS_TS1] = { { { 0x00000000, 0x00009200 } } },
4062 +- /* 16-bit data */
4063 +- [GDT_ENTRY_PNPBIOS_TS2] = { { { 0x00000000, 0x00009200 } } },
4064 +- /*
4065 +- * The APM segments have byte granularity and their bases
4066 +- * are set at run time. All have 64k limits.
4067 +- */
4068 +- /* 32-bit code */
4069 +- [GDT_ENTRY_APMBIOS_BASE] = { { { 0x0000ffff, 0x00409a00 } } },
4070 +- /* 16-bit code */
4071 +- [GDT_ENTRY_APMBIOS_BASE+1] = { { { 0x0000ffff, 0x00009a00 } } },
4072 +- /* data */
4073 +- [GDT_ENTRY_APMBIOS_BASE+2] = { { { 0x0000ffff, 0x00409200 } } },
4074 +-
4075 +- [GDT_ENTRY_ESPFIX_SS] = { { { 0x00000000, 0x00c09200 } } },
4076 +- [GDT_ENTRY_PERCPU] = { { { 0x00000000, 0x00000000 } } },
4077 +-} };
4078 +-EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
4079 +-
4080 + __u32 cleared_cpu_caps[NCAPINTS] __cpuinitdata;
4081 +
4082 + static int cachesize_override __cpuinitdata = -1;
4083 +@@ -493,6 +456,10 @@ static void __cpuinit identify_cpu(struc
4084 + * we do "generic changes."
4085 + */
4086 +
4087 ++#if defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
4088 ++ setup_clear_cpu_cap(X86_FEATURE_SEP);
4089 ++#endif
4090 ++
4091 + /* If the model name is still unset, do table lookup. */
4092 + if (!c->x86_model_id[0]) {
4093 + char *p;
4094 +@@ -629,7 +596,7 @@ static __init int setup_disablecpuid(cha
4095 + }
4096 + __setup("clearcpuid=", setup_disablecpuid);
4097 +
4098 +-cpumask_t cpu_initialized __cpuinitdata = CPU_MASK_NONE;
4099 ++cpumask_t cpu_initialized = CPU_MASK_NONE;
4100 +
4101 + void __init early_cpu_init(void)
4102 + {
4103 +@@ -658,7 +625,7 @@ void switch_to_new_gdt(void)
4104 + {
4105 + struct desc_ptr gdt_descr;
4106 +
4107 +- gdt_descr.address = (long)get_cpu_gdt_table(smp_processor_id());
4108 ++ gdt_descr.address = (unsigned long)get_cpu_gdt_table(smp_processor_id());
4109 + gdt_descr.size = GDT_SIZE - 1;
4110 + load_gdt(&gdt_descr);
4111 + asm("mov %0, %%fs" : : "r" (__KERNEL_PERCPU) : "memory");
4112 +@@ -674,7 +641,7 @@ void __cpuinit cpu_init(void)
4113 + {
4114 + int cpu = smp_processor_id();
4115 + struct task_struct *curr = current;
4116 +- struct tss_struct *t = &per_cpu(init_tss, cpu);
4117 ++ struct tss_struct *t = init_tss + cpu;
4118 + struct thread_struct *thread = &curr->thread;
4119 +
4120 + if (cpu_test_and_set(cpu, cpu_initialized)) {
4121 +@@ -729,7 +696,7 @@ void __cpuinit cpu_init(void)
4122 + }
4123 +
4124 + #ifdef CONFIG_HOTPLUG_CPU
4125 +-void __cpuinit cpu_uninit(void)
4126 ++void cpu_uninit(void)
4127 + {
4128 + int cpu = raw_smp_processor_id();
4129 + cpu_clear(cpu, cpu_initialized);
4130 +diff -urNp linux-2.6.27.10/arch/x86/kernel/cpu/cpufreq/acpi-cpufreq.c linux-2.6.27.10/arch/x86/kernel/cpu/cpufreq/acpi-cpufreq.c
4131 +--- linux-2.6.27.10/arch/x86/kernel/cpu/cpufreq/acpi-cpufreq.c 2008-11-07 12:55:34.000000000 -0500
4132 ++++ linux-2.6.27.10/arch/x86/kernel/cpu/cpufreq/acpi-cpufreq.c 2008-11-18 03:38:44.000000000 -0500
4133 +@@ -560,7 +560,7 @@ static const struct dmi_system_id sw_any
4134 + DMI_MATCH(DMI_PRODUCT_NAME, "X6DLP"),
4135 + },
4136 + },
4137 +- { }
4138 ++ { NULL, NULL, {DMI_MATCH(DMI_NONE, NULL)}, NULL }
4139 + };
4140 + #endif
4141 +
4142 +diff -urNp linux-2.6.27.10/arch/x86/kernel/cpu/cpufreq/speedstep-centrino.c linux-2.6.27.10/arch/x86/kernel/cpu/cpufreq/speedstep-centrino.c
4143 +--- linux-2.6.27.10/arch/x86/kernel/cpu/cpufreq/speedstep-centrino.c 2008-11-07 12:55:34.000000000 -0500
4144 ++++ linux-2.6.27.10/arch/x86/kernel/cpu/cpufreq/speedstep-centrino.c 2008-11-18 03:38:44.000000000 -0500
4145 +@@ -225,7 +225,7 @@ static struct cpu_model models[] =
4146 + { &cpu_ids[CPU_MP4HT_D0], NULL, 0, NULL },
4147 + { &cpu_ids[CPU_MP4HT_E0], NULL, 0, NULL },
4148 +
4149 +- { NULL, }
4150 ++ { NULL, NULL, 0, NULL}
4151 + };
4152 + #undef _BANIAS
4153 + #undef BANIAS
4154 +diff -urNp linux-2.6.27.10/arch/x86/kernel/cpu/intel.c linux-2.6.27.10/arch/x86/kernel/cpu/intel.c
4155 +--- linux-2.6.27.10/arch/x86/kernel/cpu/intel.c 2008-11-07 12:55:34.000000000 -0500
4156 ++++ linux-2.6.27.10/arch/x86/kernel/cpu/intel.c 2008-11-18 03:38:44.000000000 -0500
4157 +@@ -107,7 +107,7 @@ static void __cpuinit trap_init_f00f_bug
4158 + * Update the IDT descriptor and reload the IDT so that
4159 + * it uses the read-only mapped virtual address.
4160 + */
4161 +- idt_descr.address = fix_to_virt(FIX_F00F_IDT);
4162 ++ idt_descr.address = (struct desc_struct *)fix_to_virt(FIX_F00F_IDT);
4163 + load_idt(&idt_descr);
4164 + }
4165 + #endif
4166 +diff -urNp linux-2.6.27.10/arch/x86/kernel/cpu/mcheck/mce_64.c linux-2.6.27.10/arch/x86/kernel/cpu/mcheck/mce_64.c
4167 +--- linux-2.6.27.10/arch/x86/kernel/cpu/mcheck/mce_64.c 2008-11-07 12:55:34.000000000 -0500
4168 ++++ linux-2.6.27.10/arch/x86/kernel/cpu/mcheck/mce_64.c 2008-11-18 03:38:44.000000000 -0500
4169 +@@ -681,6 +681,7 @@ static struct miscdevice mce_log_device
4170 + MISC_MCELOG_MINOR,
4171 + "mcelog",
4172 + &mce_chrdev_ops,
4173 ++ {NULL, NULL}, NULL, NULL
4174 + };
4175 +
4176 + static unsigned long old_cr4 __initdata;
4177 +diff -urNp linux-2.6.27.10/arch/x86/kernel/cpu/mtrr/generic.c linux-2.6.27.10/arch/x86/kernel/cpu/mtrr/generic.c
4178 +--- linux-2.6.27.10/arch/x86/kernel/cpu/mtrr/generic.c 2008-11-07 12:55:34.000000000 -0500
4179 ++++ linux-2.6.27.10/arch/x86/kernel/cpu/mtrr/generic.c 2008-11-18 03:38:44.000000000 -0500
4180 +@@ -31,11 +31,11 @@ static struct fixed_range_block fixed_ra
4181 + { MTRRfix64K_00000_MSR, 1 }, /* one 64k MTRR */
4182 + { MTRRfix16K_80000_MSR, 2 }, /* two 16k MTRRs */
4183 + { MTRRfix4K_C0000_MSR, 8 }, /* eight 4k MTRRs */
4184 +- {}
4185 ++ { 0, 0 }
4186 + };
4187 +
4188 + static unsigned long smp_changes_mask;
4189 +-static struct mtrr_state mtrr_state = {};
4190 ++static struct mtrr_state mtrr_state;
4191 + static int mtrr_state_set;
4192 + u64 mtrr_tom2;
4193 +
4194 +diff -urNp linux-2.6.27.10/arch/x86/kernel/crash.c linux-2.6.27.10/arch/x86/kernel/crash.c
4195 +--- linux-2.6.27.10/arch/x86/kernel/crash.c 2008-11-07 12:55:34.000000000 -0500
4196 ++++ linux-2.6.27.10/arch/x86/kernel/crash.c 2008-11-18 03:38:44.000000000 -0500
4197 +@@ -59,7 +59,7 @@ static int crash_nmi_callback(struct not
4198 + local_irq_disable();
4199 +
4200 + #ifdef CONFIG_X86_32
4201 +- if (!user_mode_vm(regs)) {
4202 ++ if (!user_mode(regs)) {
4203 + crash_fixup_ss_esp(&fixed_regs, regs);
4204 + regs = &fixed_regs;
4205 + }
4206 +diff -urNp linux-2.6.27.10/arch/x86/kernel/doublefault_32.c linux-2.6.27.10/arch/x86/kernel/doublefault_32.c
4207 +--- linux-2.6.27.10/arch/x86/kernel/doublefault_32.c 2008-11-07 12:55:34.000000000 -0500
4208 ++++ linux-2.6.27.10/arch/x86/kernel/doublefault_32.c 2008-11-18 03:38:44.000000000 -0500
4209 +@@ -11,7 +11,7 @@
4210 +
4211 + #define DOUBLEFAULT_STACKSIZE (1024)
4212 + static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
4213 +-#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
4214 ++#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
4215 +
4216 + #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
4217 +
4218 +@@ -21,7 +21,7 @@ static void doublefault_fn(void)
4219 + unsigned long gdt, tss;
4220 +
4221 + store_gdt(&gdt_desc);
4222 +- gdt = gdt_desc.address;
4223 ++ gdt = (unsigned long)gdt_desc.address;
4224 +
4225 + printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
4226 +
4227 +@@ -60,10 +60,10 @@ struct tss_struct doublefault_tss __cach
4228 + /* 0x2 bit is always set */
4229 + .flags = X86_EFLAGS_SF | 0x2,
4230 + .sp = STACK_START,
4231 +- .es = __USER_DS,
4232 ++ .es = __KERNEL_DS,
4233 + .cs = __KERNEL_CS,
4234 + .ss = __KERNEL_DS,
4235 +- .ds = __USER_DS,
4236 ++ .ds = __KERNEL_DS,
4237 + .fs = __KERNEL_PERCPU,
4238 +
4239 + .__cr3 = __pa(swapper_pg_dir)
4240 +diff -urNp linux-2.6.27.10/arch/x86/kernel/efi_32.c linux-2.6.27.10/arch/x86/kernel/efi_32.c
4241 +--- linux-2.6.27.10/arch/x86/kernel/efi_32.c 2008-11-07 12:55:34.000000000 -0500
4242 ++++ linux-2.6.27.10/arch/x86/kernel/efi_32.c 2008-11-18 03:38:44.000000000 -0500
4243 +@@ -38,70 +38,38 @@
4244 + */
4245 +
4246 + static unsigned long efi_rt_eflags;
4247 +-static pgd_t efi_bak_pg_dir_pointer[2];
4248 ++static pgd_t __initdata efi_bak_pg_dir_pointer[KERNEL_PGD_PTRS];
4249 +
4250 +-void efi_call_phys_prelog(void)
4251 ++void __init efi_call_phys_prelog(void)
4252 + {
4253 +- unsigned long cr4;
4254 +- unsigned long temp;
4255 + struct desc_ptr gdt_descr;
4256 +
4257 + local_irq_save(efi_rt_eflags);
4258 +
4259 +- /*
4260 +- * If I don't have PAE, I should just duplicate two entries in page
4261 +- * directory. If I have PAE, I just need to duplicate one entry in
4262 +- * page directory.
4263 +- */
4264 +- cr4 = read_cr4_safe();
4265 +
4266 +- if (cr4 & X86_CR4_PAE) {
4267 +- efi_bak_pg_dir_pointer[0].pgd =
4268 +- swapper_pg_dir[pgd_index(0)].pgd;
4269 +- swapper_pg_dir[0].pgd =
4270 +- swapper_pg_dir[pgd_index(PAGE_OFFSET)].pgd;
4271 +- } else {
4272 +- efi_bak_pg_dir_pointer[0].pgd =
4273 +- swapper_pg_dir[pgd_index(0)].pgd;
4274 +- efi_bak_pg_dir_pointer[1].pgd =
4275 +- swapper_pg_dir[pgd_index(0x400000)].pgd;
4276 +- swapper_pg_dir[pgd_index(0)].pgd =
4277 +- swapper_pg_dir[pgd_index(PAGE_OFFSET)].pgd;
4278 +- temp = PAGE_OFFSET + 0x400000;
4279 +- swapper_pg_dir[pgd_index(0x400000)].pgd =
4280 +- swapper_pg_dir[pgd_index(temp)].pgd;
4281 +- }
4282 ++ clone_pgd_range(efi_bak_pg_dir_pointer, swapper_pg_dir, KERNEL_PGD_PTRS);
4283 ++ clone_pgd_range(swapper_pg_dir, swapper_pg_dir + KERNEL_PGD_BOUNDARY,
4284 ++ min_t(unsigned long, KERNEL_PGD_PTRS, KERNEL_PGD_BOUNDARY));
4285 +
4286 + /*
4287 + * After the lock is released, the original page table is restored.
4288 + */
4289 + __flush_tlb_all();
4290 +
4291 +- gdt_descr.address = __pa(get_cpu_gdt_table(0));
4292 ++ gdt_descr.address = (struct desc_struct *)__pa(get_cpu_gdt_table(0));
4293 + gdt_descr.size = GDT_SIZE - 1;
4294 + load_gdt(&gdt_descr);
4295 + }
4296 +
4297 +-void efi_call_phys_epilog(void)
4298 ++void __init efi_call_phys_epilog(void)
4299 + {
4300 +- unsigned long cr4;
4301 + struct desc_ptr gdt_descr;
4302 +
4303 +- gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
4304 ++ gdt_descr.address = get_cpu_gdt_table(0);
4305 + gdt_descr.size = GDT_SIZE - 1;
4306 + load_gdt(&gdt_descr);
4307 +
4308 +- cr4 = read_cr4_safe();
4309 +-
4310 +- if (cr4 & X86_CR4_PAE) {
4311 +- swapper_pg_dir[pgd_index(0)].pgd =
4312 +- efi_bak_pg_dir_pointer[0].pgd;
4313 +- } else {
4314 +- swapper_pg_dir[pgd_index(0)].pgd =
4315 +- efi_bak_pg_dir_pointer[0].pgd;
4316 +- swapper_pg_dir[pgd_index(0x400000)].pgd =
4317 +- efi_bak_pg_dir_pointer[1].pgd;
4318 +- }
4319 ++ clone_pgd_range(swapper_pg_dir, efi_bak_pg_dir_pointer, KERNEL_PGD_PTRS);
4320 +
4321 + /*
4322 + * After the lock is released, the original page table is restored.
4323 +diff -urNp linux-2.6.27.10/arch/x86/kernel/efi_stub_32.S linux-2.6.27.10/arch/x86/kernel/efi_stub_32.S
4324 +--- linux-2.6.27.10/arch/x86/kernel/efi_stub_32.S 2008-11-07 12:55:34.000000000 -0500
4325 ++++ linux-2.6.27.10/arch/x86/kernel/efi_stub_32.S 2008-11-18 03:38:44.000000000 -0500
4326 +@@ -6,6 +6,7 @@
4327 + */
4328 +
4329 + #include <linux/linkage.h>
4330 ++#include <linux/init.h>
4331 + #include <asm/page.h>
4332 +
4333 + /*
4334 +@@ -20,7 +21,7 @@
4335 + * service functions will comply with gcc calling convention, too.
4336 + */
4337 +
4338 +-.text
4339 ++__INIT
4340 + ENTRY(efi_call_phys)
4341 + /*
4342 + * 0. The function can only be called in Linux kernel. So CS has been
4343 +@@ -36,9 +37,7 @@ ENTRY(efi_call_phys)
4344 + * The mapping of lower virtual memory has been created in prelog and
4345 + * epilog.
4346 + */
4347 +- movl $1f, %edx
4348 +- subl $__PAGE_OFFSET, %edx
4349 +- jmp *%edx
4350 ++ jmp 1f-__PAGE_OFFSET
4351 + 1:
4352 +
4353 + /*
4354 +@@ -47,14 +46,8 @@ ENTRY(efi_call_phys)
4355 + * parameter 2, ..., param n. To make things easy, we save the return
4356 + * address of efi_call_phys in a global variable.
4357 + */
4358 +- popl %edx
4359 +- movl %edx, saved_return_addr
4360 +- /* get the function pointer into ECX*/
4361 +- popl %ecx
4362 +- movl %ecx, efi_rt_function_ptr
4363 +- movl $2f, %edx
4364 +- subl $__PAGE_OFFSET, %edx
4365 +- pushl %edx
4366 ++ popl (saved_return_addr)
4367 ++ popl (efi_rt_function_ptr)
4368 +
4369 + /*
4370 + * 3. Clear PG bit in %CR0.
4371 +@@ -73,9 +66,8 @@ ENTRY(efi_call_phys)
4372 + /*
4373 + * 5. Call the physical function.
4374 + */
4375 +- jmp *%ecx
4376 ++ call *(efi_rt_function_ptr-__PAGE_OFFSET)
4377 +
4378 +-2:
4379 + /*
4380 + * 6. After EFI runtime service returns, control will return to
4381 + * following instruction. We'd better readjust stack pointer first.
4382 +@@ -88,34 +80,27 @@ ENTRY(efi_call_phys)
4383 + movl %cr0, %edx
4384 + orl $0x80000000, %edx
4385 + movl %edx, %cr0
4386 +- jmp 1f
4387 +-1:
4388 ++
4389 + /*
4390 + * 8. Now restore the virtual mode from flat mode by
4391 + * adding EIP with PAGE_OFFSET.
4392 + */
4393 +- movl $1f, %edx
4394 +- jmp *%edx
4395 ++ jmp 1f+__PAGE_OFFSET
4396 + 1:
4397 +
4398 + /*
4399 + * 9. Balance the stack. And because EAX contain the return value,
4400 + * we'd better not clobber it.
4401 + */
4402 +- leal efi_rt_function_ptr, %edx
4403 +- movl (%edx), %ecx
4404 +- pushl %ecx
4405 ++ pushl (efi_rt_function_ptr)
4406 +
4407 + /*
4408 +- * 10. Push the saved return address onto the stack and return.
4409 ++ * 10. Return to the saved return address.
4410 + */
4411 +- leal saved_return_addr, %edx
4412 +- movl (%edx), %ecx
4413 +- pushl %ecx
4414 +- ret
4415 ++ jmpl *(saved_return_addr)
4416 + .previous
4417 +
4418 +-.data
4419 ++__INITDATA
4420 + saved_return_addr:
4421 + .long 0
4422 + efi_rt_function_ptr:
4423 +diff -urNp linux-2.6.27.10/arch/x86/kernel/entry_32.S linux-2.6.27.10/arch/x86/kernel/entry_32.S
4424 +--- linux-2.6.27.10/arch/x86/kernel/entry_32.S 2008-11-07 12:55:34.000000000 -0500
4425 ++++ linux-2.6.27.10/arch/x86/kernel/entry_32.S 2008-11-18 03:38:44.000000000 -0500
4426 +@@ -101,7 +101,7 @@
4427 + #define resume_userspace_sig resume_userspace
4428 + #endif
4429 +
4430 +-#define SAVE_ALL \
4431 ++#define __SAVE_ALL(_DS) \
4432 + cld; \
4433 + pushl %fs; \
4434 + CFI_ADJUST_CFA_OFFSET 4;\
4435 +@@ -133,12 +133,26 @@
4436 + pushl %ebx; \
4437 + CFI_ADJUST_CFA_OFFSET 4;\
4438 + CFI_REL_OFFSET ebx, 0;\
4439 +- movl $(__USER_DS), %edx; \
4440 ++ movl $(_DS), %edx; \
4441 + movl %edx, %ds; \
4442 + movl %edx, %es; \
4443 + movl $(__KERNEL_PERCPU), %edx; \
4444 + movl %edx, %fs
4445 +
4446 ++#ifdef CONFIG_PAX_KERNEXEC
4447 ++#define SAVE_ALL \
4448 ++ __SAVE_ALL(__KERNEL_DS); \
4449 ++ GET_CR0_INTO_EDX; \
4450 ++ movl %edx, %esi; \
4451 ++ orl $X86_CR0_WP, %edx; \
4452 ++ xorl %edx, %esi; \
4453 ++ SET_CR0_FROM_EDX
4454 ++#elif defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
4455 ++#define SAVE_ALL __SAVE_ALL(__KERNEL_DS)
4456 ++#else
4457 ++#define SAVE_ALL __SAVE_ALL(__USER_DS)
4458 ++#endif
4459 ++
4460 + #define RESTORE_INT_REGS \
4461 + popl %ebx; \
4462 + CFI_ADJUST_CFA_OFFSET -4;\
4463 +@@ -229,6 +243,11 @@ ENTRY(ret_from_fork)
4464 + CFI_ADJUST_CFA_OFFSET 4
4465 + popfl
4466 + CFI_ADJUST_CFA_OFFSET -4
4467 ++
4468 ++#ifdef CONFIG_PAX_KERNEXEC
4469 ++ xorl %esi, %esi
4470 ++#endif
4471 ++
4472 + jmp syscall_exit
4473 + CFI_ENDPROC
4474 + END(ret_from_fork)
4475 +@@ -252,7 +271,17 @@ check_userspace:
4476 + movb PT_CS(%esp), %al
4477 + andl $(X86_EFLAGS_VM | SEGMENT_RPL_MASK), %eax
4478 + cmpl $USER_RPL, %eax
4479 ++
4480 ++#ifdef CONFIG_PAX_KERNEXEC
4481 ++ jae resume_userspace
4482 ++
4483 ++ GET_CR0_INTO_EDX
4484 ++ xorl %esi, %edx
4485 ++ SET_CR0_FROM_EDX
4486 ++ jmp resume_kernel
4487 ++#else
4488 + jb resume_kernel # not returning to v8086 or userspace
4489 ++#endif
4490 +
4491 + ENTRY(resume_userspace)
4492 + LOCKDEP_SYS_EXIT
4493 +@@ -314,10 +343,9 @@ sysenter_past_esp:
4494 + /*CFI_REL_OFFSET cs, 0*/
4495 + /*
4496 + * Push current_thread_info()->sysenter_return to the stack.
4497 +- * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
4498 +- * pushed above; +8 corresponds to copy_thread's esp0 setting.
4499 + */
4500 +- pushl (TI_sysenter_return-THREAD_SIZE+8+4*4)(%esp)
4501 ++ GET_THREAD_INFO(%ebp)
4502 ++ pushl TI_sysenter_return(%ebp)
4503 + CFI_ADJUST_CFA_OFFSET 4
4504 + CFI_REL_OFFSET eip, 0
4505 +
4506 +@@ -330,9 +358,17 @@ sysenter_past_esp:
4507 + * Load the potential sixth argument from user stack.
4508 + * Careful about security.
4509 + */
4510 ++ movl PT_OLDESP(%esp),%ebp
4511 ++
4512 ++#ifdef CONFIG_PAX_MEMORY_UDEREF
4513 ++ mov PT_OLDSS(%esp),%ds
4514 ++1: movl %ds:(%ebp),%ebp
4515 ++#else
4516 + cmpl $__PAGE_OFFSET-3,%ebp
4517 + jae syscall_fault
4518 + 1: movl (%ebp),%ebp
4519 ++#endif
4520 ++
4521 + movl %ebp,PT_EBP(%esp)
4522 + .section __ex_table,"a"
4523 + .align 4
4524 +@@ -356,12 +392,23 @@ sysenter_do_call:
4525 + testw $_TIF_ALLWORK_MASK, %cx
4526 + jne sysexit_audit
4527 + sysenter_exit:
4528 ++
4529 ++#ifdef CONFIG_PAX_RANDKSTACK
4530 ++ pushl %eax
4531 ++ CFI_ADJUST_CFA_OFFSET 4
4532 ++ call pax_randomize_kstack
4533 ++ popl %eax
4534 ++ CFI_ADJUST_CFA_OFFSET -4
4535 ++#endif
4536 ++
4537 + /* if something modifies registers it must also disable sysexit */
4538 + movl PT_EIP(%esp), %edx
4539 + movl PT_OLDESP(%esp), %ecx
4540 + xorl %ebp,%ebp
4541 + TRACE_IRQS_ON
4542 + 1: mov PT_FS(%esp), %fs
4543 ++2: mov PT_DS(%esp), %ds
4544 ++3: mov PT_ES(%esp), %es
4545 + ENABLE_INTERRUPTS_SYSEXIT
4546 +
4547 + #ifdef CONFIG_AUDITSYSCALL
4548 +@@ -404,11 +451,17 @@ sysexit_audit:
4549 +
4550 + CFI_ENDPROC
4551 + .pushsection .fixup,"ax"
4552 +-2: movl $0,PT_FS(%esp)
4553 ++4: movl $0,PT_FS(%esp)
4554 ++ jmp 1b
4555 ++5: movl $0,PT_DS(%esp)
4556 ++ jmp 1b
4557 ++6: movl $0,PT_ES(%esp)
4558 + jmp 1b
4559 + .section __ex_table,"a"
4560 + .align 4
4561 +- .long 1b,2b
4562 ++ .long 1b,4b
4563 ++ .long 2b,5b
4564 ++ .long 3b,6b
4565 + .popsection
4566 + ENDPROC(ia32_sysenter_target)
4567 +
4568 +@@ -438,6 +491,10 @@ syscall_exit:
4569 + testw $_TIF_ALLWORK_MASK, %cx # current->work
4570 + jne syscall_exit_work
4571 +
4572 ++#ifdef CONFIG_PAX_RANDKSTACK
4573 ++ call pax_randomize_kstack
4574 ++#endif
4575 ++
4576 + restore_all:
4577 + movl PT_EFLAGS(%esp), %eax # mix EFLAGS, SS and CS
4578 + # Warning: PT_OLDSS(%esp) contains the wrong/random values if we
4579 +@@ -531,25 +588,19 @@ work_resched:
4580 +
4581 + work_notifysig: # deal with pending signals and
4582 + # notify-resume requests
4583 ++ movl %esp, %eax
4584 + #ifdef CONFIG_VM86
4585 + testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
4586 +- movl %esp, %eax
4587 +- jne work_notifysig_v86 # returning to kernel-space or
4588 ++ jz 1f # returning to kernel-space or
4589 + # vm86-space
4590 +- xorl %edx, %edx
4591 +- call do_notify_resume
4592 +- jmp resume_userspace_sig
4593 +
4594 +- ALIGN
4595 +-work_notifysig_v86:
4596 + pushl %ecx # save ti_flags for do_notify_resume
4597 + CFI_ADJUST_CFA_OFFSET 4
4598 + call save_v86_state # %eax contains pt_regs pointer
4599 + popl %ecx
4600 + CFI_ADJUST_CFA_OFFSET -4
4601 + movl %eax, %esp
4602 +-#else
4603 +- movl %esp, %eax
4604 ++1:
4605 + #endif
4606 + xorl %edx, %edx
4607 + call do_notify_resume
4608 +@@ -595,17 +646,24 @@ syscall_badsys:
4609 + END(syscall_badsys)
4610 + CFI_ENDPROC
4611 +
4612 +-#define FIXUP_ESPFIX_STACK \
4613 +- /* since we are on a wrong stack, we cant make it a C code :( */ \
4614 +- PER_CPU(gdt_page, %ebx); \
4615 +- GET_DESC_BASE(GDT_ENTRY_ESPFIX_SS, %ebx, %eax, %ax, %al, %ah); \
4616 +- addl %esp, %eax; \
4617 +- pushl $__KERNEL_DS; \
4618 +- CFI_ADJUST_CFA_OFFSET 4; \
4619 +- pushl %eax; \
4620 +- CFI_ADJUST_CFA_OFFSET 4; \
4621 +- lss (%esp), %esp; \
4622 ++.macro FIXUP_ESPFIX_STACK
4623 ++ /* since we are on a wrong stack, we cant make it a C code :( */
4624 ++#ifdef CONFIG_SMP
4625 ++ movl PER_CPU_VAR(cpu_number), %ebx;
4626 ++ shll $PAGE_SHIFT_asm, %ebx;
4627 ++ addl $cpu_gdt_table, %ebx;
4628 ++#else
4629 ++ movl $cpu_gdt_table, %ebx;
4630 ++#endif
4631 ++ GET_DESC_BASE(GDT_ENTRY_ESPFIX_SS, %ebx, %eax, %ax, %al, %ah);
4632 ++ addl %esp, %eax;
4633 ++ pushl $__KERNEL_DS;
4634 ++ CFI_ADJUST_CFA_OFFSET 4;
4635 ++ pushl %eax;
4636 ++ CFI_ADJUST_CFA_OFFSET 4;
4637 ++ lss (%esp), %esp;
4638 + CFI_ADJUST_CFA_OFFSET -8;
4639 ++.endm
4640 + #define UNWIND_ESPFIX_STACK \
4641 + movl %ss, %eax; \
4642 + /* see if on espfix stack */ \
4643 +@@ -622,7 +680,7 @@ END(syscall_badsys)
4644 + * Build the entry stubs and pointer table with
4645 + * some assembler magic.
4646 + */
4647 +-.section .rodata,"a"
4648 ++.section .rodata,"a",@progbits
4649 + ENTRY(interrupt)
4650 + .text
4651 +
4652 +@@ -722,12 +780,21 @@ error_code:
4653 + popl %ecx
4654 + CFI_ADJUST_CFA_OFFSET -4
4655 + /*CFI_REGISTER es, ecx*/
4656 ++
4657 ++#ifdef CONFIG_PAX_KERNEXEC
4658 ++ GET_CR0_INTO_EDX
4659 ++ movl %edx, %esi
4660 ++ orl $X86_CR0_WP, %edx
4661 ++ xorl %edx, %esi
4662 ++ SET_CR0_FROM_EDX
4663 ++#endif
4664 ++
4665 + movl PT_FS(%esp), %edi # get the function address
4666 + movl PT_ORIG_EAX(%esp), %edx # get the error code
4667 + movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
4668 + mov %ecx, PT_FS(%esp)
4669 + /*CFI_REL_OFFSET fs, ES*/
4670 +- movl $(__USER_DS), %ecx
4671 ++ movl $(__KERNEL_DS), %ecx
4672 + movl %ecx, %ds
4673 + movl %ecx, %es
4674 + movl %esp,%eax # pt_regs pointer
4675 +@@ -861,6 +928,13 @@ nmi_stack_correct:
4676 + xorl %edx,%edx # zero error code
4677 + movl %esp,%eax # pt_regs pointer
4678 + call do_nmi
4679 ++
4680 ++#ifdef CONFIG_PAX_KERNEXEC
4681 ++ GET_CR0_INTO_EDX
4682 ++ xorl %esi, %edx
4683 ++ SET_CR0_FROM_EDX
4684 ++#endif
4685 ++
4686 + jmp restore_nocheck_notrace
4687 + CFI_ENDPROC
4688 +
4689 +@@ -901,6 +975,13 @@ nmi_espfix_stack:
4690 + FIXUP_ESPFIX_STACK # %eax == %esp
4691 + xorl %edx,%edx # zero error code
4692 + call do_nmi
4693 ++
4694 ++#ifdef CONFIG_PAX_KERNEXEC
4695 ++ GET_CR0_INTO_EDX
4696 ++ xorl %esi, %edx
4697 ++ SET_CR0_FROM_EDX
4698 ++#endif
4699 ++
4700 + RESTORE_REGS
4701 + lss 12+4(%esp), %esp # back to espfix stack
4702 + CFI_ADJUST_CFA_OFFSET -24
4703 +@@ -1226,7 +1307,6 @@ END(mcount)
4704 + #endif /* CONFIG_DYNAMIC_FTRACE */
4705 + #endif /* CONFIG_FTRACE */
4706 +
4707 +-.section .rodata,"a"
4708 + #include "syscall_table_32.S"
4709 +
4710 + syscall_table_size=(.-sys_call_table)
4711 +diff -urNp linux-2.6.27.10/arch/x86/kernel/entry_64.S linux-2.6.27.10/arch/x86/kernel/entry_64.S
4712 +--- linux-2.6.27.10/arch/x86/kernel/entry_64.S 2008-11-07 12:55:34.000000000 -0500
4713 ++++ linux-2.6.27.10/arch/x86/kernel/entry_64.S 2008-11-18 03:38:44.000000000 -0500
4714 +@@ -930,17 +930,18 @@ END(spurious_interrupt)
4715 + xorl %ebx,%ebx
4716 + 1:
4717 + .if \ist
4718 +- movq %gs:pda_data_offset, %rbp
4719 ++ imul $TSS_size, %gs:pda_cpunumber, %ebp
4720 ++ lea init_tss(%rbp), %rbp
4721 + .endif
4722 + movq %rsp,%rdi
4723 + movq ORIG_RAX(%rsp),%rsi
4724 + movq $-1,ORIG_RAX(%rsp)
4725 + .if \ist
4726 +- subq $EXCEPTION_STKSZ, per_cpu__init_tss + TSS_ist + (\ist - 1) * 8(%rbp)
4727 ++ subq $EXCEPTION_STKSZ, TSS_ist + (\ist - 1) * 8(%rbp)
4728 + .endif
4729 + call \sym
4730 + .if \ist
4731 +- addq $EXCEPTION_STKSZ, per_cpu__init_tss + TSS_ist + (\ist - 1) * 8(%rbp)
4732 ++ addq $EXCEPTION_STKSZ, TSS_ist + (\ist - 1) * 8(%rbp)
4733 + .endif
4734 + DISABLE_INTERRUPTS(CLBR_NONE)
4735 + .if \irqtrace
4736 +diff -urNp linux-2.6.27.10/arch/x86/kernel/ftrace.c linux-2.6.27.10/arch/x86/kernel/ftrace.c
4737 +--- linux-2.6.27.10/arch/x86/kernel/ftrace.c 2008-11-07 12:55:34.000000000 -0500
4738 ++++ linux-2.6.27.10/arch/x86/kernel/ftrace.c 2008-12-10 22:28:27.000000000 -0500
4739 +@@ -103,9 +103,9 @@ notrace int ftrace_update_ftrace_func(ft
4740 + unsigned char old[MCOUNT_INSN_SIZE], *new;
4741 + int ret;
4742 +
4743 +- memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
4744 ++ memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
4745 + new = ftrace_call_replace(ip, (unsigned long)func);
4746 +- ret = ftrace_modify_code(ip, old, new);
4747 ++ ret = ftrace_modify_code(ktla_ktva(ip), old, new);
4748 +
4749 + return ret;
4750 + }
4751 +@@ -120,9 +120,9 @@ notrace int ftrace_mcount_set(unsigned l
4752 + * Replace the mcount stub with a pointer to the
4753 + * ip recorder function.
4754 + */
4755 +- memcpy(old, &mcount_call, MCOUNT_INSN_SIZE);
4756 ++ memcpy(old, ktla_ktva(mcount_call), MCOUNT_INSN_SIZE);
4757 + new = ftrace_call_replace(ip, *addr);
4758 +- *addr = ftrace_modify_code(ip, old, new);
4759 ++ *addr = ftrace_modify_code(ktla_ktva(ip), old, new);
4760 +
4761 + return 0;
4762 + }
4763 +diff -urNp linux-2.6.27.10/arch/x86/kernel/head32.c linux-2.6.27.10/arch/x86/kernel/head32.c
4764 +--- linux-2.6.27.10/arch/x86/kernel/head32.c 2008-11-07 12:55:34.000000000 -0500
4765 ++++ linux-2.6.27.10/arch/x86/kernel/head32.c 2008-11-18 03:38:44.000000000 -0500
4766 +@@ -12,10 +12,11 @@
4767 + #include <asm/sections.h>
4768 + #include <asm/e820.h>
4769 + #include <asm/bios_ebda.h>
4770 ++#include <asm/boot.h>
4771 +
4772 + void __init i386_start_kernel(void)
4773 + {
4774 +- reserve_early(__pa_symbol(&_text), __pa_symbol(&_end), "TEXT DATA BSS");
4775 ++ reserve_early(LOAD_PHYSICAL_ADDR, __pa_symbol(&_end), "TEXT DATA BSS");
4776 +
4777 + #ifdef CONFIG_BLK_DEV_INITRD
4778 + /* Reserve INITRD */
4779 +diff -urNp linux-2.6.27.10/arch/x86/kernel/head_32.S linux-2.6.27.10/arch/x86/kernel/head_32.S
4780 +--- linux-2.6.27.10/arch/x86/kernel/head_32.S 2008-11-07 12:55:34.000000000 -0500
4781 ++++ linux-2.6.27.10/arch/x86/kernel/head_32.S 2008-11-18 03:38:44.000000000 -0500
4782 +@@ -19,6 +19,7 @@
4783 + #include <asm/asm-offsets.h>
4784 + #include <asm/setup.h>
4785 + #include <asm/processor-flags.h>
4786 ++#include <asm/msr-index.h>
4787 +
4788 + /* Physical address */
4789 + #define pa(X) ((X) - __PAGE_OFFSET)
4790 +@@ -64,17 +65,22 @@ LOW_PAGES = 1<<(32-PAGE_SHIFT_asm)
4791 + LOW_PAGES = LOW_PAGES + 0x1000000
4792 + #endif
4793 +
4794 +-#if PTRS_PER_PMD > 1
4795 +-PAGE_TABLE_SIZE = (LOW_PAGES / PTRS_PER_PMD) + PTRS_PER_PGD
4796 +-#else
4797 +-PAGE_TABLE_SIZE = (LOW_PAGES / PTRS_PER_PGD)
4798 +-#endif
4799 ++PAGE_TABLE_SIZE = (LOW_PAGES / PTRS_PER_PTE)
4800 + BOOTBITMAP_SIZE = LOW_PAGES / 8
4801 + ALLOCATOR_SLOP = 4
4802 +
4803 + INIT_MAP_BEYOND_END = BOOTBITMAP_SIZE + (PAGE_TABLE_SIZE + ALLOCATOR_SLOP)*PAGE_SIZE_asm
4804 +
4805 + /*
4806 ++ * Real beginning of normal "text" segment
4807 ++ */
4808 ++ENTRY(stext)
4809 ++ENTRY(_stext)
4810 ++
4811 ++.section .text.startup,"ax",@progbits
4812 ++ ljmp $(__BOOT_CS),$phys_startup_32
4813 ++
4814 ++/*
4815 + * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
4816 + * %esi points to the real-mode code as a 32-bit pointer.
4817 + * CS and DS must be 4 GB flat segments, but we don't depend on
4818 +@@ -82,6 +88,12 @@ INIT_MAP_BEYOND_END = BOOTBITMAP_SIZE +
4819 + * can.
4820 + */
4821 + .section .text.head,"ax",@progbits
4822 ++
4823 ++#ifdef CONFIG_PAX_KERNEXEC
4824 ++/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
4825 ++.fill 4096,1,0xcc
4826 ++#endif
4827 ++
4828 + ENTRY(startup_32)
4829 + /* test KEEP_SEGMENTS flag to see if the bootloader is asking
4830 + us to not reload segments */
4831 +@@ -99,6 +111,56 @@ ENTRY(startup_32)
4832 + movl %eax,%gs
4833 + 2:
4834 +
4835 ++ movl $pa(cpu_gdt_table),%edi
4836 ++ movl $__per_cpu_start,%eax
4837 ++ movw %ax,__KERNEL_PERCPU + 2(%edi)
4838 ++ rorl $16,%eax
4839 ++ movb %al,__KERNEL_PERCPU + 4(%edi)
4840 ++ movb %ah,__KERNEL_PERCPU + 7(%edi)
4841 ++ movl $__per_cpu_end + PERCPU_MODULE_RESERVE - 1,%eax
4842 ++ subl $__per_cpu_start,%eax
4843 ++ movw %ax,__KERNEL_PERCPU + 0(%edi)
4844 ++
4845 ++#ifdef CONFIG_PAX_MEMORY_UDEREF
4846 ++ /* check for VMware */
4847 ++ movl $0x564d5868,%eax
4848 ++ xorl %ebx,%ebx
4849 ++ movl $0xa,%ecx
4850 ++ movl $0x5658,%edx
4851 ++ in (%dx),%eax
4852 ++ cmpl $0x564d5868,%ebx
4853 ++ jz 2f
4854 ++
4855 ++ movl $NR_CPUS,%ecx
4856 ++ movl $pa(cpu_gdt_table),%edi
4857 ++1:
4858 ++ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
4859 ++ addl $PAGE_SIZE_asm,%edi
4860 ++ loop 1b
4861 ++2:
4862 ++#endif
4863 ++
4864 ++#ifdef CONFIG_PAX_KERNEXEC
4865 ++ movl $pa(boot_gdt),%edi
4866 ++ movl $KERNEL_TEXT_OFFSET,%eax
4867 ++ movw %ax,__BOOT_CS + 2(%edi)
4868 ++ rorl $16,%eax
4869 ++ movb %al,__BOOT_CS + 4(%edi)
4870 ++ movb %ah,__BOOT_CS + 7(%edi)
4871 ++ rorl $16,%eax
4872 ++
4873 ++ movl $NR_CPUS,%ecx
4874 ++ movl $pa(cpu_gdt_table),%edi
4875 ++1:
4876 ++ movw %ax,__KERNEL_CS + 2(%edi)
4877 ++ rorl $16,%eax
4878 ++ movb %al,__KERNEL_CS + 4(%edi)
4879 ++ movb %ah,__KERNEL_CS + 7(%edi)
4880 ++ rorl $16,%eax
4881 ++ addl $PAGE_SIZE_asm,%edi
4882 ++ loop 1b
4883 ++#endif
4884 ++
4885 + /*
4886 + * Clear BSS first so that there are no surprises...
4887 + */
4888 +@@ -142,9 +204,7 @@ ENTRY(startup_32)
4889 + cmpl $num_subarch_entries, %eax
4890 + jae bad_subarch
4891 +
4892 +- movl pa(subarch_entries)(,%eax,4), %eax
4893 +- subl $__PAGE_OFFSET, %eax
4894 +- jmp *%eax
4895 ++ jmp *pa(subarch_entries)(,%eax,4)
4896 +
4897 + bad_subarch:
4898 + WEAK(lguest_entry)
4899 +@@ -156,9 +216,9 @@ WEAK(xen_entry)
4900 + __INITDATA
4901 +
4902 + subarch_entries:
4903 +- .long default_entry /* normal x86/PC */
4904 +- .long lguest_entry /* lguest hypervisor */
4905 +- .long xen_entry /* Xen hypervisor */
4906 ++ .long pa(default_entry) /* normal x86/PC */
4907 ++ .long pa(lguest_entry) /* lguest hypervisor */
4908 ++ .long pa(xen_entry) /* Xen hypervisor */
4909 + num_subarch_entries = (. - subarch_entries) / 4
4910 + .previous
4911 + #endif /* CONFIG_PARAVIRT */
4912 +@@ -172,7 +232,7 @@ num_subarch_entries = (. - subarch_entri
4913 + *
4914 + * Note that the stack is not yet set up!
4915 + */
4916 +-#define PTE_ATTR 0x007 /* PRESENT+RW+USER */
4917 ++#define PTE_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
4918 + #define PDE_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
4919 + #define PGD_ATTR 0x001 /* PRESENT (no other attributes) */
4920 +
4921 +@@ -224,8 +284,7 @@ default_entry:
4922 + movl %eax, pa(max_pfn_mapped)
4923 +
4924 + /* Do early initialization of the fixmap area */
4925 +- movl $pa(swapper_pg_fixmap)+PDE_ATTR,%eax
4926 +- movl %eax,pa(swapper_pg_pmd+0x1000*KPMDS-8)
4927 ++ movl $pa(swapper_pg_fixmap)+PDE_ATTR,pa(swapper_pg_pmd+0x1000*KPMDS-8)
4928 + #else /* Not PAE */
4929 +
4930 + page_pde_offset = (__PAGE_OFFSET >> 20);
4931 +@@ -257,8 +316,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
4932 + movl %eax, pa(max_pfn_mapped)
4933 +
4934 + /* Do early initialization of the fixmap area */
4935 +- movl $pa(swapper_pg_fixmap)+PDE_ATTR,%eax
4936 +- movl %eax,pa(swapper_pg_dir+0xffc)
4937 ++ movl $pa(swapper_pg_fixmap)+PDE_ATTR,pa(swapper_pg_dir+0xffc)
4938 + #endif
4939 + jmp 3f
4940 + /*
4941 +@@ -322,13 +380,16 @@ ENTRY(startup_32_smp)
4942 + jnc 6f
4943 +
4944 + /* Setup EFER (Extended Feature Enable Register) */
4945 +- movl $0xc0000080, %ecx
4946 ++ movl $MSR_EFER, %ecx
4947 + rdmsr
4948 +
4949 + btsl $11, %eax
4950 + /* Make changes effective */
4951 + wrmsr
4952 +
4953 ++ btsl $63-32,pa(__supported_pte_mask+4)
4954 ++ movl $1,pa(nx_enabled)
4955 ++
4956 + 6:
4957 +
4958 + /*
4959 +@@ -354,9 +415,7 @@ ENTRY(startup_32_smp)
4960 +
4961 + #ifdef CONFIG_SMP
4962 + cmpb $0, ready
4963 +- jz 1f /* Initial CPU cleans BSS */
4964 +- jmp checkCPUtype
4965 +-1:
4966 ++ jnz checkCPUtype /* Initial CPU cleans BSS */
4967 + #endif /* CONFIG_SMP */
4968 +
4969 + /*
4970 +@@ -433,12 +492,12 @@ is386: movl $2,%ecx # set MP
4971 + ljmp $(__KERNEL_CS),$1f
4972 + 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
4973 + movl %eax,%ss # after changing gdt.
4974 +- movl %eax,%fs # gets reset once there's real percpu
4975 +-
4976 +- movl $(__USER_DS),%eax # DS/ES contains default USER segment
4977 + movl %eax,%ds
4978 + movl %eax,%es
4979 +
4980 ++ movl $(__KERNEL_PERCPU), %eax
4981 ++ movl %eax,%fs # set this cpu's percpu
4982 ++
4983 + xorl %eax,%eax # Clear GS and LDT
4984 + movl %eax,%gs
4985 + lldt %ax
4986 +@@ -448,12 +507,6 @@ is386: movl $2,%ecx # set MP
4987 + #ifdef CONFIG_SMP
4988 + movb ready, %cl
4989 + movb $1, ready
4990 +- cmpb $0,%cl # the first CPU calls start_kernel
4991 +- je 1f
4992 +- movl $(__KERNEL_PERCPU), %eax
4993 +- movl %eax,%fs # set this cpu's percpu
4994 +- movl (stack_start), %esp
4995 +-1:
4996 + #endif /* CONFIG_SMP */
4997 + jmp *(initial_code)
4998 +
4999 +@@ -539,15 +592,15 @@ early_page_fault:
5000 + jmp early_fault
5001 +
5002 + early_fault:
5003 +- cld
5004 + #ifdef CONFIG_PRINTK
5005 ++ cmpl $2,%ss:early_recursion_flag
5006 ++ je hlt_loop
5007 ++ incl %ss:early_recursion_flag
5008 ++ cld
5009 + pusha
5010 + movl $(__KERNEL_DS),%eax
5011 + movl %eax,%ds
5012 + movl %eax,%es
5013 +- cmpl $2,early_recursion_flag
5014 +- je hlt_loop
5015 +- incl early_recursion_flag
5016 + movl %cr2,%eax
5017 + pushl %eax
5018 + pushl %edx /* trapno */
5019 +@@ -557,8 +610,8 @@ early_fault:
5020 + #else
5021 + call printk
5022 + #endif
5023 +-#endif
5024 + call dump_stack
5025 ++#endif
5026 + hlt_loop:
5027 + hlt
5028 + jmp hlt_loop
5029 +@@ -566,8 +619,11 @@ hlt_loop:
5030 + /* This is the default interrupt "handler" :-) */
5031 + ALIGN
5032 + ignore_int:
5033 +- cld
5034 + #ifdef CONFIG_PRINTK
5035 ++ cmpl $2,%ss:early_recursion_flag
5036 ++ je hlt_loop
5037 ++ incl %ss:early_recursion_flag
5038 ++ cld
5039 + pushl %eax
5040 + pushl %ecx
5041 + pushl %edx
5042 +@@ -576,9 +632,6 @@ ignore_int:
5043 + movl $(__KERNEL_DS),%eax
5044 + movl %eax,%ds
5045 + movl %eax,%es
5046 +- cmpl $2,early_recursion_flag
5047 +- je hlt_loop
5048 +- incl early_recursion_flag
5049 + pushl 16(%esp)
5050 + pushl 24(%esp)
5051 + pushl 32(%esp)
5052 +@@ -603,36 +656,41 @@ ignore_int:
5053 + ENTRY(initial_code)
5054 + .long i386_start_kernel
5055 +
5056 +-.section .text
5057 +-/*
5058 +- * Real beginning of normal "text" segment
5059 +- */
5060 +-ENTRY(stext)
5061 +-ENTRY(_stext)
5062 +-
5063 + /*
5064 + * BSS section
5065 + */
5066 +-.section ".bss.page_aligned","wa"
5067 +- .align PAGE_SIZE_asm
5068 + #ifdef CONFIG_X86_PAE
5069 ++.section .swapper_pg_pmd,"a",@progbits
5070 + swapper_pg_pmd:
5071 + .fill 1024*KPMDS,4,0
5072 + #else
5073 ++.section .swapper_pg_dir,"a",@progbits
5074 + ENTRY(swapper_pg_dir)
5075 + .fill 1024,4,0
5076 + #endif
5077 + swapper_pg_fixmap:
5078 + .fill 1024,4,0
5079 ++
5080 ++.section .empty_zero_page,"a",@progbits
5081 + ENTRY(empty_zero_page)
5082 + .fill 4096,1,0
5083 ++
5084 ++/*
5085 ++ * The IDT has to be page-aligned to simplify the Pentium
5086 ++ * F0 0F bug workaround.. We have a special link segment
5087 ++ * for this.
5088 ++ */
5089 ++.section .idt,"a",@progbits
5090 ++ENTRY(idt_table)
5091 ++ .fill 256,8,0
5092 ++
5093 + /*
5094 + * This starts the data section.
5095 + */
5096 ++.data
5097 ++
5098 + #ifdef CONFIG_X86_PAE
5099 +-.section ".data.page_aligned","wa"
5100 +- /* Page-aligned for the benefit of paravirt? */
5101 +- .align PAGE_SIZE_asm
5102 ++.section .swapper_pg_dir,"a",@progbits
5103 + ENTRY(swapper_pg_dir)
5104 + .long pa(swapper_pg_pmd+PGD_ATTR),0 /* low identity map */
5105 + # if KPMDS == 3
5106 +@@ -655,11 +713,12 @@ ENTRY(swapper_pg_dir)
5107 +
5108 + .data
5109 + ENTRY(stack_start)
5110 +- .long init_thread_union+THREAD_SIZE
5111 ++ .long init_thread_union+THREAD_SIZE-8
5112 + .long __BOOT_DS
5113 +
5114 + ready: .byte 0
5115 +
5116 ++.section .rodata,"a",@progbits
5117 + early_recursion_flag:
5118 + .long 0
5119 +
5120 +@@ -695,7 +754,7 @@ fault_msg:
5121 + .word 0 # 32 bit align gdt_desc.address
5122 + boot_gdt_descr:
5123 + .word __BOOT_DS+7
5124 +- .long boot_gdt - __PAGE_OFFSET
5125 ++ .long pa(boot_gdt)
5126 +
5127 + .word 0 # 32-bit align idt_desc.address
5128 + idt_descr:
5129 +@@ -706,7 +765,7 @@ idt_descr:
5130 + .word 0 # 32 bit align gdt_desc.address
5131 + ENTRY(early_gdt_descr)
5132 + .word GDT_ENTRIES*8-1
5133 +- .long per_cpu__gdt_page /* Overwritten for secondary CPUs */
5134 ++ .long cpu_gdt_table /* Overwritten for secondary CPUs */
5135 +
5136 + /*
5137 + * The boot_gdt must mirror the equivalent in setup.S and is
5138 +@@ -715,5 +774,59 @@ ENTRY(early_gdt_descr)
5139 + .align L1_CACHE_BYTES
5140 + ENTRY(boot_gdt)
5141 + .fill GDT_ENTRY_BOOT_CS,8,0
5142 +- .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
5143 +- .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
5144 ++ .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
5145 ++ .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
5146 ++
5147 ++ .align PAGE_SIZE_asm
5148 ++ENTRY(cpu_gdt_table)
5149 ++ .rept NR_CPUS
5150 ++ .quad 0x0000000000000000 /* NULL descriptor */
5151 ++ .quad 0x0000000000000000 /* 0x0b reserved */
5152 ++ .quad 0x0000000000000000 /* 0x13 reserved */
5153 ++ .quad 0x0000000000000000 /* 0x1b reserved */
5154 ++ .quad 0x0000000000000000 /* 0x20 unused */
5155 ++ .quad 0x0000000000000000 /* 0x28 unused */
5156 ++ .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
5157 ++ .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
5158 ++ .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
5159 ++ .quad 0x0000000000000000 /* 0x4b reserved */
5160 ++ .quad 0x0000000000000000 /* 0x53 reserved */
5161 ++ .quad 0x0000000000000000 /* 0x5b reserved */
5162 ++
5163 ++ .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
5164 ++ .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
5165 ++ .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
5166 ++ .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
5167 ++
5168 ++ .quad 0x0000000000000000 /* 0x80 TSS descriptor */
5169 ++ .quad 0x0000000000000000 /* 0x88 LDT descriptor */
5170 ++
5171 ++ /*
5172 ++ * Segments used for calling PnP BIOS have byte granularity.
5173 ++ * The code segments and data segments have fixed 64k limits,
5174 ++ * the transfer segment sizes are set at run time.
5175 ++ */
5176 ++ .quad 0x00409b000000ffff /* 0x90 32-bit code */
5177 ++ .quad 0x00009b000000ffff /* 0x98 16-bit code */
5178 ++ .quad 0x000093000000ffff /* 0xa0 16-bit data */
5179 ++ .quad 0x0000930000000000 /* 0xa8 16-bit data */
5180 ++ .quad 0x0000930000000000 /* 0xb0 16-bit data */
5181 ++
5182 ++ /*
5183 ++ * The APM segments have byte granularity and their bases
5184 ++ * are set at run time. All have 64k limits.
5185 ++ */
5186 ++ .quad 0x00409b000000ffff /* 0xb8 APM CS code */
5187 ++ .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
5188 ++ .quad 0x004093000000ffff /* 0xc8 APM DS data */
5189 ++
5190 ++ .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
5191 ++ .quad 0x0040930000000000 /* 0xd8 - PERCPU */
5192 ++ .quad 0x0000000000000000 /* 0xe0 - PCIBIOS_CS */
5193 ++ .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_DS */
5194 ++ .quad 0x0000000000000000 /* 0xf0 - unused */
5195 ++ .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
5196 ++
5197 ++ /* Be sure this is zeroed to avoid false validations in Xen */
5198 ++ .fill PAGE_SIZE_asm - GDT_SIZE,1,0
5199 ++ .endr
5200 +diff -urNp linux-2.6.27.10/arch/x86/kernel/head64.c linux-2.6.27.10/arch/x86/kernel/head64.c
5201 +--- linux-2.6.27.10/arch/x86/kernel/head64.c 2008-11-07 12:55:34.000000000 -0500
5202 ++++ linux-2.6.27.10/arch/x86/kernel/head64.c 2008-11-18 03:38:44.000000000 -0500
5203 +@@ -93,6 +93,8 @@ void __init x86_64_start_kernel(char * r
5204 + /* clear bss before set_intr_gate with early_idt_handler */
5205 + clear_bss();
5206 +
5207 ++ x86_64_init_pda();
5208 ++
5209 + /* Make NULL pointers segfault */
5210 + zap_identity_mappings();
5211 +
5212 +@@ -110,8 +112,6 @@ void __init x86_64_start_kernel(char * r
5213 +
5214 + early_printk("Kernel alive\n");
5215 +
5216 +- x86_64_init_pda();
5217 +-
5218 + early_printk("Kernel really alive\n");
5219 +
5220 + x86_64_start_reservations(real_mode_data);
5221 +diff -urNp linux-2.6.27.10/arch/x86/kernel/head_64.S linux-2.6.27.10/arch/x86/kernel/head_64.S
5222 +--- linux-2.6.27.10/arch/x86/kernel/head_64.S 2008-11-07 12:55:34.000000000 -0500
5223 ++++ linux-2.6.27.10/arch/x86/kernel/head_64.S 2008-11-18 03:38:44.000000000 -0500
5224 +@@ -38,6 +38,10 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET
5225 + L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
5226 + L4_START_KERNEL = pgd_index(__START_KERNEL_map)
5227 + L3_START_KERNEL = pud_index(__START_KERNEL_map)
5228 ++L4_VMALLOC_START = pgd_index(VMALLOC_START)
5229 ++L3_VMALLOC_START = pud_index(VMALLOC_START)
5230 ++L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
5231 ++L3_VMEMMAP_START = pud_index(VMEMMAP_START)
5232 +
5233 + .text
5234 + .section .text.head
5235 +@@ -85,14 +89,17 @@ startup_64:
5236 + */
5237 + addq %rbp, init_level4_pgt + 0(%rip)
5238 + addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
5239 ++ addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
5240 ++ addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
5241 + addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
5242 +
5243 + addq %rbp, level3_ident_pgt + 0(%rip)
5244 +
5245 +- addq %rbp, level3_kernel_pgt + (510*8)(%rip)
5246 +- addq %rbp, level3_kernel_pgt + (511*8)(%rip)
5247 ++ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
5248 ++ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8+8)(%rip)
5249 +
5250 + addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
5251 ++ addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
5252 +
5253 + /* Add an Identity mapping if I am above 1G */
5254 + leaq _text(%rip), %rdi
5255 +@@ -187,6 +194,10 @@ ENTRY(secondary_startup_64)
5256 + btl $20,%edi /* No Execute supported? */
5257 + jnc 1f
5258 + btsl $_EFER_NX, %eax
5259 ++ leaq init_level4_pgt(%rip), %rdi
5260 ++ btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
5261 ++ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
5262 ++ btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
5263 + 1: wrmsr /* Make changes effective */
5264 +
5265 + /* Setup cr0 */
5266 +@@ -257,16 +268,16 @@ ENTRY(secondary_startup_64)
5267 + .align 8
5268 + ENTRY(initial_code)
5269 + .quad x86_64_start_kernel
5270 +- __FINITDATA
5271 +
5272 + ENTRY(stack_start)
5273 + .quad init_thread_union+THREAD_SIZE-8
5274 + .word 0
5275 ++ __FINITDATA
5276 +
5277 + bad_address:
5278 + jmp bad_address
5279 +
5280 +- .section ".init.text","ax"
5281 ++ __INIT
5282 + #ifdef CONFIG_EARLY_PRINTK
5283 + .globl early_idt_handlers
5284 + early_idt_handlers:
5285 +@@ -311,18 +322,23 @@ ENTRY(early_idt_handler)
5286 + #endif /* EARLY_PRINTK */
5287 + 1: hlt
5288 + jmp 1b
5289 ++ .previous
5290 +
5291 + #ifdef CONFIG_EARLY_PRINTK
5292 ++ __INITDATA
5293 + early_recursion_flag:
5294 + .long 0
5295 ++ .previous
5296 +
5297 ++ .section .rodata,"a",@progbits
5298 + early_idt_msg:
5299 + .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
5300 + early_idt_ripmsg:
5301 + .asciz "RIP %s\n"
5302 +-#endif /* CONFIG_EARLY_PRINTK */
5303 + .previous
5304 ++#endif /* CONFIG_EARLY_PRINTK */
5305 +
5306 ++ .section .rodata,"a",@progbits
5307 + .balign PAGE_SIZE
5308 +
5309 + #define NEXT_PAGE(name) \
5310 +@@ -347,6 +363,10 @@ NEXT_PAGE(init_level4_pgt)
5311 + .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
5312 + .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
5313 + .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
5314 ++ .org init_level4_pgt + L4_VMALLOC_START*8, 0
5315 ++ .quad level3_vmalloc_pgt - __START_KERNEL_map + _KERNPG_TABLE
5316 ++ .org init_level4_pgt + L4_VMEMMAP_START*8, 0
5317 ++ .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
5318 + .org init_level4_pgt + L4_START_KERNEL*8, 0
5319 + /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
5320 + .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
5321 +@@ -355,6 +375,12 @@ NEXT_PAGE(level3_ident_pgt)
5322 + .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
5323 + .fill 511,8,0
5324 +
5325 ++NEXT_PAGE(level3_vmalloc_pgt)
5326 ++ .fill 512,8,0
5327 ++
5328 ++NEXT_PAGE(level3_vmemmap_pgt)
5329 ++ .fill 512,8,0
5330 ++
5331 + NEXT_PAGE(level3_kernel_pgt)
5332 + .fill L3_START_KERNEL,8,0
5333 + /* (2^48-(2*1024*1024*1024)-((2^39)*511))/(2^30) = 510 */
5334 +@@ -364,12 +390,16 @@ NEXT_PAGE(level3_kernel_pgt)
5335 + NEXT_PAGE(level2_fixmap_pgt)
5336 + .fill 506,8,0
5337 + .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
5338 +- /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
5339 +- .fill 5,8,0
5340 ++ .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
5341 ++ /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
5342 ++ .fill 4,8,0
5343 +
5344 + NEXT_PAGE(level1_fixmap_pgt)
5345 + .fill 512,8,0
5346 +
5347 ++NEXT_PAGE(level1_vsyscall_pgt)
5348 ++ .fill 512,8,0
5349 ++
5350 + NEXT_PAGE(level2_ident_pgt)
5351 + /* Since I easily can, map the first 1G.
5352 + * Don't set NX because code runs from these pages.
5353 +@@ -396,19 +426,39 @@ NEXT_PAGE(level2_spare_pgt)
5354 + #undef PMDS
5355 + #undef NEXT_PAGE
5356 +
5357 +- .data
5358 ++ .align PAGE_SIZE
5359 ++ENTRY(cpu_gdt_table)
5360 ++ .rept NR_CPUS
5361 ++ .quad 0x0000000000000000 /* NULL descriptor */
5362 ++ .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
5363 ++ .quad 0x00af9b000000ffff /* __KERNEL_CS */
5364 ++ .quad 0x00cf93000000ffff /* __KERNEL_DS */
5365 ++ .quad 0x00cffb000000ffff /* __USER32_CS */
5366 ++ .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
5367 ++ .quad 0x00affb000000ffff /* __USER_CS */
5368 ++ .quad 0x0 /* unused */
5369 ++ .quad 0,0 /* TSS */
5370 ++ .quad 0,0 /* LDT */
5371 ++ .quad 0,0,0 /* three TLS descriptors */
5372 ++ .quad 0x0000f40000000000 /* node/CPU stored in limit */
5373 ++ /* asm/segment.h:GDT_ENTRIES must match this */
5374 ++
5375 ++ /* zero the remaining page */
5376 ++ .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
5377 ++ .endr
5378 ++
5379 + .align 16
5380 + .globl early_gdt_descr
5381 + early_gdt_descr:
5382 + .word GDT_ENTRIES*8-1
5383 +- .quad per_cpu__gdt_page
5384 ++ .quad cpu_gdt_table
5385 +
5386 + ENTRY(phys_base)
5387 + /* This must match the first entry in level2_kernel_pgt */
5388 + .quad 0x0000000000000000
5389 +
5390 + #include "../../x86/xen/xen-head.S"
5391 +-
5392 ++
5393 + .section .bss, "aw", @nobits
5394 + .align L1_CACHE_BYTES
5395 + ENTRY(idt_table)
5396 +diff -urNp linux-2.6.27.10/arch/x86/kernel/i386_ksyms_32.c linux-2.6.27.10/arch/x86/kernel/i386_ksyms_32.c
5397 +--- linux-2.6.27.10/arch/x86/kernel/i386_ksyms_32.c 2008-11-07 12:55:34.000000000 -0500
5398 ++++ linux-2.6.27.10/arch/x86/kernel/i386_ksyms_32.c 2008-11-18 03:38:44.000000000 -0500
5399 +@@ -10,8 +10,12 @@
5400 + EXPORT_SYMBOL(mcount);
5401 + #endif
5402 +
5403 ++EXPORT_SYMBOL_GPL(cpu_gdt_table);
5404 ++
5405 + /* Networking helper routines. */
5406 + EXPORT_SYMBOL(csum_partial_copy_generic);
5407 ++EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
5408 ++EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
5409 +
5410 + EXPORT_SYMBOL(__get_user_1);
5411 + EXPORT_SYMBOL(__get_user_2);
5412 +@@ -26,3 +30,7 @@ EXPORT_SYMBOL(strstr);
5413 +
5414 + EXPORT_SYMBOL(csum_partial);
5415 + EXPORT_SYMBOL(empty_zero_page);
5416 ++
5417 ++#ifdef CONFIG_PAX_KERNEXEC
5418 ++EXPORT_SYMBOL(KERNEL_TEXT_OFFSET);
5419 ++#endif
5420 +diff -urNp linux-2.6.27.10/arch/x86/kernel/init_task.c linux-2.6.27.10/arch/x86/kernel/init_task.c
5421 +--- linux-2.6.27.10/arch/x86/kernel/init_task.c 2008-11-07 12:55:34.000000000 -0500
5422 ++++ linux-2.6.27.10/arch/x86/kernel/init_task.c 2008-11-18 03:38:44.000000000 -0500
5423 +@@ -42,5 +42,5 @@ EXPORT_SYMBOL(init_task);
5424 + * section. Since TSS's are completely CPU-local, we want them
5425 + * on exact cacheline boundaries, to eliminate cacheline ping-pong.
5426 + */
5427 +-DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
5428 +-
5429 ++struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
5430 ++EXPORT_SYMBOL(init_tss);
5431 +diff -urNp linux-2.6.27.10/arch/x86/kernel/ioport.c linux-2.6.27.10/arch/x86/kernel/ioport.c
5432 +--- linux-2.6.27.10/arch/x86/kernel/ioport.c 2008-11-07 12:55:34.000000000 -0500
5433 ++++ linux-2.6.27.10/arch/x86/kernel/ioport.c 2008-11-18 03:38:44.000000000 -0500
5434 +@@ -14,6 +14,7 @@
5435 + #include <linux/slab.h>
5436 + #include <linux/thread_info.h>
5437 + #include <linux/syscalls.h>
5438 ++#include <linux/grsecurity.h>
5439 +
5440 + /* Set EXTENT bits starting at BASE in BITMAP to value TURN_ON. */
5441 + static void set_bitmap(unsigned long *bitmap, unsigned int base,
5442 +@@ -40,6 +41,12 @@ asmlinkage long sys_ioperm(unsigned long
5443 +
5444 + if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
5445 + return -EINVAL;
5446 ++#ifdef CONFIG_GRKERNSEC_IO
5447 ++ if (turn_on) {
5448 ++ gr_handle_ioperm();
5449 ++ return -EPERM;
5450 ++ }
5451 ++#endif
5452 + if (turn_on && !capable(CAP_SYS_RAWIO))
5453 + return -EPERM;
5454 +
5455 +@@ -66,7 +73,7 @@ asmlinkage long sys_ioperm(unsigned long
5456 + * because the ->io_bitmap_max value must match the bitmap
5457 + * contents:
5458 + */
5459 +- tss = &per_cpu(init_tss, get_cpu());
5460 ++ tss = init_tss + get_cpu();
5461 +
5462 + set_bitmap(t->io_bitmap_ptr, from, num, !turn_on);
5463 +
5464 +@@ -121,8 +128,13 @@ static int do_iopl(unsigned int level, s
5465 + return -EINVAL;
5466 + /* Trying to gain more privileges? */
5467 + if (level > old) {
5468 ++#ifdef CONFIG_GRKERNSEC_IO
5469 ++ gr_handle_iopl();
5470 ++ return -EPERM;
5471 ++#else
5472 + if (!capable(CAP_SYS_RAWIO))
5473 + return -EPERM;
5474 ++#endif
5475 + }
5476 + regs->flags = (regs->flags & ~X86_EFLAGS_IOPL) | (level << 12);
5477 +
5478 +diff -urNp linux-2.6.27.10/arch/x86/kernel/irq_32.c linux-2.6.27.10/arch/x86/kernel/irq_32.c
5479 +--- linux-2.6.27.10/arch/x86/kernel/irq_32.c 2008-11-07 12:55:34.000000000 -0500
5480 ++++ linux-2.6.27.10/arch/x86/kernel/irq_32.c 2008-11-18 03:38:44.000000000 -0500
5481 +@@ -116,7 +116,7 @@ execute_on_irq_stack(int overflow, struc
5482 + return 0;
5483 +
5484 + /* build the stack frame on the IRQ stack */
5485 +- isp = (u32 *) ((char*)irqctx + sizeof(*irqctx));
5486 ++ isp = (u32 *) ((char*)irqctx + sizeof(*irqctx) - 8);
5487 + irqctx->tinfo.task = curctx->tinfo.task;
5488 + irqctx->tinfo.previous_esp = current_stack_pointer;
5489 +
5490 +@@ -197,7 +197,7 @@ asmlinkage void do_softirq(void)
5491 + irqctx->tinfo.previous_esp = current_stack_pointer;
5492 +
5493 + /* build the stack frame on the softirq stack */
5494 +- isp = (u32*) ((char*)irqctx + sizeof(*irqctx));
5495 ++ isp = (u32*) ((char*)irqctx + sizeof(*irqctx) - 8);
5496 +
5497 + call_on_stack(__do_softirq, isp);
5498 + /*
5499 +diff -urNp linux-2.6.27.10/arch/x86/kernel/kprobes.c linux-2.6.27.10/arch/x86/kernel/kprobes.c
5500 +--- linux-2.6.27.10/arch/x86/kernel/kprobes.c 2008-11-07 12:55:34.000000000 -0500
5501 ++++ linux-2.6.27.10/arch/x86/kernel/kprobes.c 2008-11-18 04:48:35.000000000 -0500
5502 +@@ -166,9 +166,24 @@ static void __kprobes set_jmp_op(void *f
5503 + char op;
5504 + s32 raddr;
5505 + } __attribute__((packed)) * jop;
5506 +- jop = (struct __arch_jmp_op *)from;
5507 ++
5508 ++#ifdef CONFIG_PAX_KERNEXEC
5509 ++ unsigned long cr0;
5510 ++#endif
5511 ++
5512 ++ jop = (struct __arch_jmp_op *)(ktla_ktva(from));
5513 ++
5514 ++#ifdef CONFIG_PAX_KERNEXEC
5515 ++ pax_open_kernel(cr0);
5516 ++#endif
5517 ++
5518 + jop->raddr = (s32)((long)(to) - ((long)(from) + 5));
5519 + jop->op = RELATIVEJUMP_INSTRUCTION;
5520 ++
5521 ++#ifdef CONFIG_PAX_KERNEXEC
5522 ++ pax_close_kernel(cr0);
5523 ++#endif
5524 ++
5525 + }
5526 +
5527 + /*
5528 +@@ -342,16 +357,29 @@ static void __kprobes fix_riprel(struct
5529 +
5530 + static void __kprobes arch_copy_kprobe(struct kprobe *p)
5531 + {
5532 +- memcpy(p->ainsn.insn, p->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
5533 ++
5534 ++#ifdef CONFIG_PAX_KERNEXEC
5535 ++ unsigned long cr0;
5536 ++#endif
5537 ++
5538 ++#ifdef CONFIG_PAX_KERNEXEC
5539 ++ pax_open_kernel(cr0);
5540 ++#endif
5541 ++
5542 ++ memcpy(p->ainsn.insn, ktla_ktva(p->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
5543 ++
5544 ++#ifdef CONFIG_PAX_KERNEXEC
5545 ++ pax_close_kernel(cr0);
5546 ++#endif
5547 +
5548 + fix_riprel(p);
5549 +
5550 +- if (can_boost(p->addr))
5551 ++ if (can_boost(ktla_ktva(p->addr)))
5552 + p->ainsn.boostable = 0;
5553 + else
5554 + p->ainsn.boostable = -1;
5555 +
5556 +- p->opcode = *p->addr;
5557 ++ p->opcode = *(ktla_ktva(p->addr));
5558 + }
5559 +
5560 + int __kprobes arch_prepare_kprobe(struct kprobe *p)
5561 +@@ -428,7 +456,7 @@ static void __kprobes prepare_singlestep
5562 + if (p->opcode == BREAKPOINT_INSTRUCTION)
5563 + regs->ip = (unsigned long)p->addr;
5564 + else
5565 +- regs->ip = (unsigned long)p->ainsn.insn;
5566 ++ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
5567 + }
5568 +
5569 + void __kprobes arch_prepare_kretprobe(struct kretprobe_instance *ri,
5570 +@@ -449,7 +477,7 @@ static void __kprobes setup_singlestep(s
5571 + if (p->ainsn.boostable == 1 && !p->post_handler) {
5572 + /* Boost up -- we can execute copied instructions directly */
5573 + reset_current_kprobe();
5574 +- regs->ip = (unsigned long)p->ainsn.insn;
5575 ++ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
5576 + preempt_enable_no_resched();
5577 + return;
5578 + }
5579 +@@ -519,7 +547,7 @@ static int __kprobes kprobe_handler(stru
5580 + struct kprobe_ctlblk *kcb;
5581 +
5582 + addr = (kprobe_opcode_t *)(regs->ip - sizeof(kprobe_opcode_t));
5583 +- if (*addr != BREAKPOINT_INSTRUCTION) {
5584 ++ if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
5585 + /*
5586 + * The breakpoint instruction was removed right
5587 + * after we hit it. Another cpu has removed
5588 +@@ -770,7 +798,7 @@ static void __kprobes resume_execution(s
5589 + struct pt_regs *regs, struct kprobe_ctlblk *kcb)
5590 + {
5591 + unsigned long *tos = stack_addr(regs);
5592 +- unsigned long copy_ip = (unsigned long)p->ainsn.insn;
5593 ++ unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
5594 + unsigned long orig_ip = (unsigned long)p->addr;
5595 + kprobe_opcode_t *insn = p->ainsn.insn;
5596 +
5597 +@@ -953,7 +981,7 @@ int __kprobes kprobe_exceptions_notify(s
5598 + struct die_args *args = data;
5599 + int ret = NOTIFY_DONE;
5600 +
5601 +- if (args->regs && user_mode_vm(args->regs))
5602 ++ if (args->regs && user_mode(args->regs))
5603 + return ret;
5604 +
5605 + switch (val) {
5606 +diff -urNp linux-2.6.27.10/arch/x86/kernel/ldt.c linux-2.6.27.10/arch/x86/kernel/ldt.c
5607 +--- linux-2.6.27.10/arch/x86/kernel/ldt.c 2008-11-07 12:55:34.000000000 -0500
5608 ++++ linux-2.6.27.10/arch/x86/kernel/ldt.c 2008-11-18 03:38:44.000000000 -0500
5609 +@@ -63,13 +63,13 @@ static int alloc_ldt(mm_context_t *pc, i
5610 + if (reload) {
5611 + #ifdef CONFIG_SMP
5612 + preempt_disable();
5613 +- load_LDT(pc);
5614 ++ load_LDT_nolock(pc);
5615 + if (!cpus_equal(current->mm->cpu_vm_mask,
5616 + cpumask_of_cpu(smp_processor_id())))
5617 + smp_call_function(flush_ldt, current->mm, 1);
5618 + preempt_enable();
5619 + #else
5620 +- load_LDT(pc);
5621 ++ load_LDT_nolock(pc);
5622 + #endif
5623 + }
5624 + if (oldsize) {
5625 +@@ -108,6 +108,24 @@ int init_new_context(struct task_struct
5626 + retval = copy_ldt(&mm->context, &old_mm->context);
5627 + mutex_unlock(&old_mm->context.lock);
5628 + }
5629 ++
5630 ++ if (tsk == current) {
5631 ++ mm->context.vdso = ~0UL;
5632 ++
5633 ++#ifdef CONFIG_X86_32
5634 ++#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
5635 ++ mm->context.user_cs_base = 0UL;
5636 ++ mm->context.user_cs_limit = ~0UL;
5637 ++
5638 ++#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
5639 ++ cpus_clear(mm->context.cpu_user_cs_mask);
5640 ++#endif
5641 ++
5642 ++#endif
5643 ++#endif
5644 ++
5645 ++ }
5646 ++
5647 + return retval;
5648 + }
5649 +
5650 +@@ -221,6 +239,13 @@ static int write_ldt(void __user *ptr, u
5651 + }
5652 + }
5653 +
5654 ++#ifdef CONFIG_PAX_SEGMEXEC
5655 ++ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
5656 ++ error = -EINVAL;
5657 ++ goto out_unlock;
5658 ++ }
5659 ++#endif
5660 ++
5661 + fill_ldt(&ldt, &ldt_info);
5662 + if (oldmode)
5663 + ldt.avl = 0;
5664 +diff -urNp linux-2.6.27.10/arch/x86/kernel/machine_kexec_32.c linux-2.6.27.10/arch/x86/kernel/machine_kexec_32.c
5665 +--- linux-2.6.27.10/arch/x86/kernel/machine_kexec_32.c 2008-11-07 12:55:34.000000000 -0500
5666 ++++ linux-2.6.27.10/arch/x86/kernel/machine_kexec_32.c 2008-11-18 03:38:44.000000000 -0500
5667 +@@ -34,7 +34,7 @@ static u32 kexec_pmd1[1024] PAGE_ALIGNED
5668 + static u32 kexec_pte0[1024] PAGE_ALIGNED;
5669 + static u32 kexec_pte1[1024] PAGE_ALIGNED;
5670 +
5671 +-static void set_idt(void *newidt, __u16 limit)
5672 ++static void set_idt(struct desc_struct *newidt, __u16 limit)
5673 + {
5674 + struct desc_ptr curidt;
5675 +
5676 +@@ -46,7 +46,7 @@ static void set_idt(void *newidt, __u16
5677 + }
5678 +
5679 +
5680 +-static void set_gdt(void *newgdt, __u16 limit)
5681 ++static void set_gdt(struct desc_struct *newgdt, __u16 limit)
5682 + {
5683 + struct desc_ptr curgdt;
5684 +
5685 +@@ -145,7 +145,7 @@ void machine_kexec(struct kimage *image)
5686 + }
5687 +
5688 + control_page = page_address(image->control_code_page);
5689 +- memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
5690 ++ memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
5691 +
5692 + relocate_kernel_ptr = control_page;
5693 + page_list[PA_CONTROL_PAGE] = __pa(control_page);
5694 +diff -urNp linux-2.6.27.10/arch/x86/kernel/module_32.c linux-2.6.27.10/arch/x86/kernel/module_32.c
5695 +--- linux-2.6.27.10/arch/x86/kernel/module_32.c 2008-11-07 12:55:34.000000000 -0500
5696 ++++ linux-2.6.27.10/arch/x86/kernel/module_32.c 2008-11-18 03:38:44.000000000 -0500
5697 +@@ -23,6 +23,9 @@
5698 + #include <linux/kernel.h>
5699 + #include <linux/bug.h>
5700 +
5701 ++#include <asm/desc.h>
5702 ++#include <asm/pgtable.h>
5703 ++
5704 + #if 0
5705 + #define DEBUGP printk
5706 + #else
5707 +@@ -33,9 +36,31 @@ void *module_alloc(unsigned long size)
5708 + {
5709 + if (size == 0)
5710 + return NULL;
5711 ++
5712 ++#ifdef CONFIG_PAX_KERNEXEC
5713 ++ return __vmalloc(size, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL);
5714 ++#else
5715 + return vmalloc_exec(size);
5716 ++#endif
5717 ++
5718 + }
5719 +
5720 ++#ifdef CONFIG_PAX_KERNEXEC
5721 ++void *module_alloc_exec(unsigned long size)
5722 ++{
5723 ++ struct vm_struct *area;
5724 ++
5725 ++ if (size == 0)
5726 ++ return NULL;
5727 ++
5728 ++ area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_VADDR, (unsigned long)&MODULES_END);
5729 ++ if (area)
5730 ++ return area->addr;
5731 ++
5732 ++ return NULL;
5733 ++}
5734 ++EXPORT_SYMBOL(module_alloc_exec);
5735 ++#endif
5736 +
5737 + /* Free memory returned from module_alloc */
5738 + void module_free(struct module *mod, void *module_region)
5739 +@@ -45,6 +70,45 @@ void module_free(struct module *mod, voi
5740 + table entries. */
5741 + }
5742 +
5743 ++#ifdef CONFIG_PAX_KERNEXEC
5744 ++void module_free_exec(struct module *mod, void *module_region)
5745 ++{
5746 ++ struct vm_struct **p, *tmp;
5747 ++
5748 ++ if (!module_region)
5749 ++ return;
5750 ++
5751 ++ if ((PAGE_SIZE-1) & (unsigned long)module_region) {
5752 ++ printk(KERN_ERR "Trying to module_free_exec() bad address (%p)\n", module_region);
5753 ++ WARN_ON(1);
5754 ++ return;
5755 ++ }
5756 ++
5757 ++ write_lock(&vmlist_lock);
5758 ++ for (p = &vmlist; (tmp = *p) != NULL; p = &tmp->next)
5759 ++ if (tmp->addr == module_region)
5760 ++ break;
5761 ++
5762 ++ if (tmp) {
5763 ++ unsigned long cr0;
5764 ++
5765 ++ pax_open_kernel(cr0);
5766 ++ memset(tmp->addr, 0xCC, tmp->size);
5767 ++ pax_close_kernel(cr0);
5768 ++
5769 ++ *p = tmp->next;
5770 ++ kfree(tmp);
5771 ++ }
5772 ++ write_unlock(&vmlist_lock);
5773 ++
5774 ++ if (!tmp) {
5775 ++ printk(KERN_ERR "Trying to module_free_exec() nonexistent vm area (%p)\n",
5776 ++ module_region);
5777 ++ WARN_ON(1);
5778 ++ }
5779 ++}
5780 ++#endif
5781 ++
5782 + /* We don't need anything special. */
5783 + int module_frob_arch_sections(Elf_Ehdr *hdr,
5784 + Elf_Shdr *sechdrs,
5785 +@@ -63,14 +127,20 @@ int apply_relocate(Elf32_Shdr *sechdrs,
5786 + unsigned int i;
5787 + Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
5788 + Elf32_Sym *sym;
5789 +- uint32_t *location;
5790 ++ uint32_t *plocation, location;
5791 ++
5792 ++#ifdef CONFIG_PAX_KERNEXEC
5793 ++ unsigned long cr0;
5794 ++#endif
5795 +
5796 + DEBUGP("Applying relocate section %u to %u\n", relsec,
5797 + sechdrs[relsec].sh_info);
5798 + for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
5799 + /* This is where to make the change */
5800 +- location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
5801 +- + rel[i].r_offset;
5802 ++ plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
5803 ++ location = (uint32_t)plocation;
5804 ++ if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
5805 ++ plocation = ktla_ktva((void *)plocation);
5806 + /* This is the symbol it is referring to. Note that all
5807 + undefined symbols have been resolved. */
5808 + sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
5809 +@@ -78,12 +148,32 @@ int apply_relocate(Elf32_Shdr *sechdrs,
5810 +
5811 + switch (ELF32_R_TYPE(rel[i].r_info)) {
5812 + case R_386_32:
5813 ++
5814 ++#ifdef CONFIG_PAX_KERNEXEC
5815 ++ pax_open_kernel(cr0);
5816 ++#endif
5817 ++
5818 + /* We add the value into the location given */
5819 +- *location += sym->st_value;
5820 ++ *plocation += sym->st_value;
5821 ++
5822 ++#ifdef CONFIG_PAX_KERNEXEC
5823 ++ pax_close_kernel(cr0);
5824 ++#endif
5825 ++
5826 + break;
5827 + case R_386_PC32:
5828 ++
5829 ++#ifdef CONFIG_PAX_KERNEXEC
5830 ++ pax_open_kernel(cr0);
5831 ++#endif
5832 ++
5833 + /* Add the value, subtract its postition */
5834 +- *location += sym->st_value - (uint32_t)location;
5835 ++ *plocation += sym->st_value - location;
5836 ++
5837 ++#ifdef CONFIG_PAX_KERNEXEC
5838 ++ pax_close_kernel(cr0);
5839 ++#endif
5840 ++
5841 + break;
5842 + default:
5843 + printk(KERN_ERR "module %s: Unknown relocation: %u\n",
5844 +diff -urNp linux-2.6.27.10/arch/x86/kernel/module_64.c linux-2.6.27.10/arch/x86/kernel/module_64.c
5845 +--- linux-2.6.27.10/arch/x86/kernel/module_64.c 2008-11-07 12:55:34.000000000 -0500
5846 ++++ linux-2.6.27.10/arch/x86/kernel/module_64.c 2008-11-18 03:38:44.000000000 -0500
5847 +@@ -40,7 +40,7 @@ void module_free(struct module *mod, voi
5848 + table entries. */
5849 + }
5850 +
5851 +-void *module_alloc(unsigned long size)
5852 ++static void *__module_alloc(unsigned long size, pgprot_t prot)
5853 + {
5854 + struct vm_struct *area;
5855 +
5856 +@@ -54,8 +54,31 @@ void *module_alloc(unsigned long size)
5857 + if (!area)
5858 + return NULL;
5859 +
5860 +- return __vmalloc_area(area, GFP_KERNEL, PAGE_KERNEL_EXEC);
5861 ++ return __vmalloc_area(area, GFP_KERNEL | __GFP_ZERO, prot);
5862 ++}
5863 ++
5864 ++#ifdef CONFIG_PAX_KERNEXEC
5865 ++void *module_alloc(unsigned long size)
5866 ++{
5867 ++ return __module_alloc(size, PAGE_KERNEL);
5868 ++}
5869 ++
5870 ++void module_free_exec(struct module *mod, void *module_region)
5871 ++{
5872 ++ module_free(mod, module_region);
5873 ++}
5874 ++
5875 ++void *module_alloc_exec(unsigned long size)
5876 ++{
5877 ++ return __module_alloc(size, PAGE_KERNEL_RX);
5878 + }
5879 ++#else
5880 ++void *module_alloc(unsigned long size)
5881 ++{
5882 ++ return __module_alloc(size, PAGE_KERNEL_EXEC);
5883 ++}
5884 ++#endif
5885 ++
5886 + #endif
5887 +
5888 + /* We don't need anything special. */
5889 +@@ -77,7 +100,11 @@ int apply_relocate_add(Elf64_Shdr *sechd
5890 + Elf64_Rela *rel = (void *)sechdrs[relsec].sh_addr;
5891 + Elf64_Sym *sym;
5892 + void *loc;
5893 +- u64 val;
5894 ++ u64 val;
5895 ++
5896 ++#ifdef CONFIG_PAX_KERNEXEC
5897 ++ unsigned long cr0;
5898 ++#endif
5899 +
5900 + DEBUGP("Applying relocate section %u to %u\n", relsec,
5901 + sechdrs[relsec].sh_info);
5902 +@@ -101,21 +128,61 @@ int apply_relocate_add(Elf64_Shdr *sechd
5903 + case R_X86_64_NONE:
5904 + break;
5905 + case R_X86_64_64:
5906 ++
5907 ++#ifdef CONFIG_PAX_KERNEXEC
5908 ++ pax_open_kernel(cr0);
5909 ++#endif
5910 ++
5911 + *(u64 *)loc = val;
5912 ++
5913 ++#ifdef CONFIG_PAX_KERNEXEC
5914 ++ pax_close_kernel(cr0);
5915 ++#endif
5916 ++
5917 + break;
5918 + case R_X86_64_32:
5919 ++
5920 ++#ifdef CONFIG_PAX_KERNEXEC
5921 ++ pax_open_kernel(cr0);
5922 ++#endif
5923 ++
5924 + *(u32 *)loc = val;
5925 ++
5926 ++#ifdef CONFIG_PAX_KERNEXEC
5927 ++ pax_close_kernel(cr0);
5928 ++#endif
5929 ++
5930 + if (val != *(u32 *)loc)
5931 + goto overflow;
5932 + break;
5933 + case R_X86_64_32S:
5934 ++
5935 ++#ifdef CONFIG_PAX_KERNEXEC
5936 ++ pax_open_kernel(cr0);
5937 ++#endif
5938 ++
5939 + *(s32 *)loc = val;
5940 ++
5941 ++#ifdef CONFIG_PAX_KERNEXEC
5942 ++ pax_close_kernel(cr0);
5943 ++#endif
5944 ++
5945 + if ((s64)val != *(s32 *)loc)
5946 + goto overflow;
5947 + break;
5948 + case R_X86_64_PC32:
5949 + val -= (u64)loc;
5950 ++
5951 ++#ifdef CONFIG_PAX_KERNEXEC
5952 ++ pax_open_kernel(cr0);
5953 ++#endif
5954 ++
5955 + *(u32 *)loc = val;
5956 ++
5957 ++#ifdef CONFIG_PAX_KERNEXEC
5958 ++ pax_close_kernel(cr0);
5959 ++#endif
5960 ++
5961 + #if 0
5962 + if ((s64)val != *(s32 *)loc)
5963 + goto overflow;
5964 +diff -urNp linux-2.6.27.10/arch/x86/kernel/paravirt.c linux-2.6.27.10/arch/x86/kernel/paravirt.c
5965 +--- linux-2.6.27.10/arch/x86/kernel/paravirt.c 2008-11-07 12:55:34.000000000 -0500
5966 ++++ linux-2.6.27.10/arch/x86/kernel/paravirt.c 2008-11-18 03:38:44.000000000 -0500
5967 +@@ -44,7 +44,7 @@ void _paravirt_nop(void)
5968 + {
5969 + }
5970 +
5971 +-static void __init default_banner(void)
5972 ++static void default_banner(void)
5973 + {
5974 + printk(KERN_INFO "Booting paravirtualized kernel on %s\n",
5975 + pv_info.name);
5976 +@@ -164,7 +164,7 @@ unsigned paravirt_patch_insns(void *insn
5977 + if (insn_len > len || start == NULL)
5978 + insn_len = len;
5979 + else
5980 +- memcpy(insnbuf, start, insn_len);
5981 ++ memcpy(insnbuf, ktla_ktva(start), insn_len);
5982 +
5983 + return insn_len;
5984 + }
5985 +@@ -279,21 +279,21 @@ void __init paravirt_use_bytelocks(void)
5986 + #endif
5987 + }
5988 +
5989 +-struct pv_info pv_info = {
5990 ++struct pv_info pv_info __read_only = {
5991 + .name = "bare hardware",
5992 + .paravirt_enabled = 0,
5993 + .kernel_rpl = 0,
5994 + .shared_kernel_pmd = 1, /* Only used when CONFIG_X86_PAE is set */
5995 + };
5996 +
5997 +-struct pv_init_ops pv_init_ops = {
5998 ++struct pv_init_ops pv_init_ops __read_only = {
5999 + .patch = native_patch,
6000 + .banner = default_banner,
6001 + .arch_setup = paravirt_nop,
6002 + .memory_setup = machine_specific_memory_setup,
6003 + };
6004 +
6005 +-struct pv_time_ops pv_time_ops = {
6006 ++struct pv_time_ops pv_time_ops __read_only = {
6007 + .time_init = hpet_time_init,
6008 + .get_wallclock = native_get_wallclock,
6009 + .set_wallclock = native_set_wallclock,
6010 +@@ -301,7 +301,7 @@ struct pv_time_ops pv_time_ops = {
6011 + .get_tsc_khz = native_calibrate_tsc,
6012 + };
6013 +
6014 +-struct pv_irq_ops pv_irq_ops = {
6015 ++struct pv_irq_ops pv_irq_ops __read_only = {
6016 + .init_IRQ = native_init_IRQ,
6017 + .save_fl = native_save_fl,
6018 + .restore_fl = native_restore_fl,
6019 +@@ -314,7 +314,7 @@ struct pv_irq_ops pv_irq_ops = {
6020 + #endif
6021 + };
6022 +
6023 +-struct pv_cpu_ops pv_cpu_ops = {
6024 ++struct pv_cpu_ops pv_cpu_ops __read_only = {
6025 + .cpuid = native_cpuid,
6026 + .get_debugreg = native_get_debugreg,
6027 + .set_debugreg = native_set_debugreg,
6028 +@@ -371,7 +371,7 @@ struct pv_cpu_ops pv_cpu_ops = {
6029 + },
6030 + };
6031 +
6032 +-struct pv_apic_ops pv_apic_ops = {
6033 ++struct pv_apic_ops pv_apic_ops __read_only = {
6034 + #ifdef CONFIG_X86_LOCAL_APIC
6035 + .apic_write = native_apic_write,
6036 + .apic_read = native_apic_read,
6037 +@@ -381,7 +381,7 @@ struct pv_apic_ops pv_apic_ops = {
6038 + #endif
6039 + };
6040 +
6041 +-struct pv_mmu_ops pv_mmu_ops = {
6042 ++struct pv_mmu_ops pv_mmu_ops __read_only = {
6043 + #ifndef CONFIG_X86_64
6044 + .pagetable_setup_start = native_pagetable_setup_start,
6045 + .pagetable_setup_done = native_pagetable_setup_done,
6046 +@@ -461,7 +461,7 @@ struct pv_mmu_ops pv_mmu_ops = {
6047 + .set_fixmap = native_set_fixmap,
6048 + };
6049 +
6050 +-struct pv_lock_ops pv_lock_ops = {
6051 ++struct pv_lock_ops pv_lock_ops __read_only = {
6052 + #ifdef CONFIG_SMP
6053 + .spin_is_locked = __ticket_spin_is_locked,
6054 + .spin_is_contended = __ticket_spin_is_contended,
6055 +diff -urNp linux-2.6.27.10/arch/x86/kernel/process_32.c linux-2.6.27.10/arch/x86/kernel/process_32.c
6056 +--- linux-2.6.27.10/arch/x86/kernel/process_32.c 2008-11-07 12:55:34.000000000 -0500
6057 ++++ linux-2.6.27.10/arch/x86/kernel/process_32.c 2008-11-18 03:38:44.000000000 -0500
6058 +@@ -62,8 +62,10 @@ asmlinkage void ret_from_fork(void) __as
6059 + DEFINE_PER_CPU(struct task_struct *, current_task) = &init_task;
6060 + EXPORT_PER_CPU_SYMBOL(current_task);
6061 +
6062 ++#ifdef CONFIG_SMP
6063 + DEFINE_PER_CPU(int, cpu_number);
6064 + EXPORT_PER_CPU_SYMBOL(cpu_number);
6065 ++#endif
6066 +
6067 + /*
6068 + * Return saved PC of a blocked thread.
6069 +@@ -71,6 +73,7 @@ EXPORT_PER_CPU_SYMBOL(cpu_number);
6070 + unsigned long thread_saved_pc(struct task_struct *tsk)
6071 + {
6072 + return ((unsigned long *)tsk->thread.sp)[3];
6073 ++//XXX return tsk->thread.eip;
6074 + }
6075 +
6076 + #ifdef CONFIG_HOTPLUG_CPU
6077 +@@ -162,7 +165,7 @@ void __show_registers(struct pt_regs *re
6078 + unsigned long sp;
6079 + unsigned short ss, gs;
6080 +
6081 +- if (user_mode_vm(regs)) {
6082 ++ if (user_mode(regs)) {
6083 + sp = regs->sp;
6084 + ss = regs->ss & 0xffff;
6085 + savesegment(gs, gs);
6086 +@@ -239,8 +242,8 @@ int kernel_thread(int (*fn)(void *), voi
6087 + regs.bx = (unsigned long) fn;
6088 + regs.dx = (unsigned long) arg;
6089 +
6090 +- regs.ds = __USER_DS;
6091 +- regs.es = __USER_DS;
6092 ++ regs.ds = __KERNEL_DS;
6093 ++ regs.es = __KERNEL_DS;
6094 + regs.fs = __KERNEL_PERCPU;
6095 + regs.orig_ax = -1;
6096 + regs.ip = (unsigned long) kernel_thread_helper;
6097 +@@ -262,7 +265,7 @@ void exit_thread(void)
6098 + struct task_struct *tsk = current;
6099 + struct thread_struct *t = &tsk->thread;
6100 + int cpu = get_cpu();
6101 +- struct tss_struct *tss = &per_cpu(init_tss, cpu);
6102 ++ struct tss_struct *tss = init_tss + cpu;
6103 +
6104 + kfree(t->io_bitmap_ptr);
6105 + t->io_bitmap_ptr = NULL;
6106 +@@ -283,6 +286,7 @@ void flush_thread(void)
6107 + {
6108 + struct task_struct *tsk = current;
6109 +
6110 ++ loadsegment(gs, 0);
6111 + tsk->thread.debugreg0 = 0;
6112 + tsk->thread.debugreg1 = 0;
6113 + tsk->thread.debugreg2 = 0;
6114 +@@ -322,7 +326,7 @@ int copy_thread(int nr, unsigned long cl
6115 + struct task_struct *tsk;
6116 + int err;
6117 +
6118 +- childregs = task_pt_regs(p);
6119 ++ childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
6120 + *childregs = *regs;
6121 + childregs->ax = 0;
6122 + childregs->sp = sp;
6123 +@@ -351,6 +355,7 @@ int copy_thread(int nr, unsigned long cl
6124 + * Set a new TLS for the child thread?
6125 + */
6126 + if (clone_flags & CLONE_SETTLS)
6127 ++//XXX needs set_fs()?
6128 + err = do_set_thread_area(p, -1,
6129 + (struct user_desc __user *)childregs->si, 0);
6130 +
6131 +@@ -550,7 +555,7 @@ struct task_struct * __switch_to(struct
6132 + struct thread_struct *prev = &prev_p->thread,
6133 + *next = &next_p->thread;
6134 + int cpu = smp_processor_id();
6135 +- struct tss_struct *tss = &per_cpu(init_tss, cpu);
6136 ++ struct tss_struct *tss = init_tss + cpu;
6137 +
6138 + /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
6139 +
6140 +@@ -578,6 +583,11 @@ struct task_struct * __switch_to(struct
6141 + */
6142 + savesegment(gs, prev->gs);
6143 +
6144 ++#ifdef CONFIG_PAX_MEMORY_UDEREF
6145 ++ if (!segment_eq(task_thread_info(prev_p)->addr_limit, task_thread_info(next_p)->addr_limit))
6146 ++ __set_fs(task_thread_info(next_p)->addr_limit, cpu);
6147 ++#endif
6148 ++
6149 + /*
6150 + * Load the per-thread Thread-Local Storage descriptor.
6151 + */
6152 +@@ -716,15 +726,27 @@ unsigned long get_wchan(struct task_stru
6153 + return 0;
6154 + }
6155 +
6156 +-unsigned long arch_align_stack(unsigned long sp)
6157 ++#ifdef CONFIG_PAX_RANDKSTACK
6158 ++asmlinkage void pax_randomize_kstack(void)
6159 + {
6160 +- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
6161 +- sp -= get_random_int() % 8192;
6162 +- return sp & ~0xf;
6163 +-}
6164 ++ struct thread_struct *thread = &current->thread;
6165 ++ unsigned long time;
6166 +
6167 +-unsigned long arch_randomize_brk(struct mm_struct *mm)
6168 +-{
6169 +- unsigned long range_end = mm->brk + 0x02000000;
6170 +- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
6171 ++ if (!randomize_va_space)
6172 ++ return;
6173 ++
6174 ++ rdtscl(time);
6175 ++
6176 ++ /* P4 seems to return a 0 LSB, ignore it */
6177 ++#ifdef CONFIG_MPENTIUM4
6178 ++ time &= 0x1EUL;
6179 ++ time <<= 2;
6180 ++#else
6181 ++ time &= 0xFUL;
6182 ++ time <<= 3;
6183 ++#endif
6184 ++
6185 ++ thread->sp0 ^= time;
6186 ++ load_sp0(init_tss + smp_processor_id(), thread);
6187 + }
6188 ++#endif
6189 +diff -urNp linux-2.6.27.10/arch/x86/kernel/process_64.c linux-2.6.27.10/arch/x86/kernel/process_64.c
6190 +--- linux-2.6.27.10/arch/x86/kernel/process_64.c 2008-11-07 12:55:34.000000000 -0500
6191 ++++ linux-2.6.27.10/arch/x86/kernel/process_64.c 2008-11-18 03:38:44.000000000 -0500
6192 +@@ -119,6 +119,8 @@ static inline void play_dead(void)
6193 + void cpu_idle(void)
6194 + {
6195 + current_thread_info()->status |= TS_POLLING;
6196 ++ current->stack_canary = pax_get_random_long();
6197 ++ write_pda(stack_canary, current->stack_canary);
6198 + /* endless idle loop with no priority at all */
6199 + while (1) {
6200 + tick_nohz_stop_sched_tick(1);
6201 +@@ -228,7 +230,7 @@ void exit_thread(void)
6202 + struct thread_struct *t = &me->thread;
6203 +
6204 + if (me->thread.io_bitmap_ptr) {
6205 +- struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
6206 ++ struct tss_struct *tss = init_tss + get_cpu();
6207 +
6208 + kfree(t->io_bitmap_ptr);
6209 + t->io_bitmap_ptr = NULL;
6210 +@@ -541,7 +543,7 @@ __switch_to(struct task_struct *prev_p,
6211 + struct thread_struct *prev = &prev_p->thread;
6212 + struct thread_struct *next = &next_p->thread;
6213 + int cpu = smp_processor_id();
6214 +- struct tss_struct *tss = &per_cpu(init_tss, cpu);
6215 ++ struct tss_struct *tss = init_tss + cpu;
6216 + unsigned fsindex, gsindex;
6217 +
6218 + /* we're going to use this soon, after a few expensive things */
6219 +@@ -630,7 +632,6 @@ __switch_to(struct task_struct *prev_p,
6220 + (unsigned long)task_stack_page(next_p) +
6221 + THREAD_SIZE - PDA_STACKOFFSET);
6222 + #ifdef CONFIG_CC_STACKPROTECTOR
6223 +- write_pda(stack_canary, next_p->stack_canary);
6224 + /*
6225 + * Build time only check to make sure the stack_canary is at
6226 + * offset 40 in the pda; this is a gcc ABI requirement
6227 +@@ -729,12 +730,11 @@ unsigned long get_wchan(struct task_stru
6228 + if (!p || p == current || p->state==TASK_RUNNING)
6229 + return 0;
6230 + stack = (unsigned long)task_stack_page(p);
6231 +- if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
6232 ++ if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-8-sizeof(u64))
6233 + return 0;
6234 + fp = *(u64 *)(p->thread.sp);
6235 + do {
6236 +- if (fp < (unsigned long)stack ||
6237 +- fp >= (unsigned long)stack+THREAD_SIZE)
6238 ++ if (fp < stack || fp > stack+THREAD_SIZE-8-sizeof(u64))
6239 + return 0;
6240 + ip = *(u64 *)(fp+8);
6241 + if (!in_sched_functions(ip))
6242 +@@ -844,16 +844,3 @@ long sys_arch_prctl(int code, unsigned l
6243 + {
6244 + return do_arch_prctl(current, code, addr);
6245 + }
6246 +-
6247 +-unsigned long arch_align_stack(unsigned long sp)
6248 +-{
6249 +- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
6250 +- sp -= get_random_int() % 8192;
6251 +- return sp & ~0xf;
6252 +-}
6253 +-
6254 +-unsigned long arch_randomize_brk(struct mm_struct *mm)
6255 +-{
6256 +- unsigned long range_end = mm->brk + 0x02000000;
6257 +- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
6258 +-}
6259 +diff -urNp linux-2.6.27.10/arch/x86/kernel/ptrace.c linux-2.6.27.10/arch/x86/kernel/ptrace.c
6260 +--- linux-2.6.27.10/arch/x86/kernel/ptrace.c 2008-11-07 12:55:34.000000000 -0500
6261 ++++ linux-2.6.27.10/arch/x86/kernel/ptrace.c 2008-11-18 03:38:44.000000000 -0500
6262 +@@ -1369,7 +1369,7 @@ void send_sigtrap(struct task_struct *ts
6263 + info.si_code = TRAP_BRKPT;
6264 +
6265 + /* User-mode ip? */
6266 +- info.si_addr = user_mode_vm(regs) ? (void __user *) regs->ip : NULL;
6267 ++ info.si_addr = user_mode(regs) ? (void __user *) regs->ip : NULL;
6268 +
6269 + /* Send us the fake SIGTRAP */
6270 + force_sig_info(SIGTRAP, &info, tsk);
6271 +diff -urNp linux-2.6.27.10/arch/x86/kernel/reboot.c linux-2.6.27.10/arch/x86/kernel/reboot.c
6272 +--- linux-2.6.27.10/arch/x86/kernel/reboot.c 2008-11-07 12:55:34.000000000 -0500
6273 ++++ linux-2.6.27.10/arch/x86/kernel/reboot.c 2008-11-18 03:38:44.000000000 -0500
6274 +@@ -28,7 +28,7 @@ void (*pm_power_off)(void);
6275 + EXPORT_SYMBOL(pm_power_off);
6276 +
6277 + static const struct desc_ptr no_idt = {};
6278 +-static int reboot_mode;
6279 ++static unsigned short reboot_mode;
6280 + enum reboot_type reboot_type = BOOT_KBD;
6281 + int reboot_force;
6282 +
6283 +@@ -193,7 +193,7 @@ static struct dmi_system_id __initdata r
6284 + DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq"),
6285 + },
6286 + },
6287 +- { }
6288 ++ { NULL, NULL, {{0, NULL}}, NULL}
6289 + };
6290 +
6291 + static int __init reboot_init(void)
6292 +@@ -209,12 +209,12 @@ core_initcall(reboot_init);
6293 + controller to pulse the CPU reset line, which is more thorough, but
6294 + doesn't work with at least one type of 486 motherboard. It is easy
6295 + to stop this code working; hence the copious comments. */
6296 +-static const unsigned long long
6297 +-real_mode_gdt_entries [3] =
6298 ++static struct desc_struct
6299 ++real_mode_gdt_entries [3] __read_only =
6300 + {
6301 +- 0x0000000000000000ULL, /* Null descriptor */
6302 +- 0x00009b000000ffffULL, /* 16-bit real-mode 64k code at 0x00000000 */
6303 +- 0x000093000100ffffULL /* 16-bit real-mode 64k data at 0x00000100 */
6304 ++ {{{0x00000000, 0x00000000}}}, /* Null descriptor */
6305 ++ {{{0x0000ffff, 0x00009b00}}}, /* 16-bit real-mode 64k code at 0x00000000 */
6306 ++ {{{0x0100ffff, 0x00009300}}} /* 16-bit real-mode 64k data at 0x00000100 */
6307 + };
6308 +
6309 + static const struct desc_ptr
6310 +@@ -263,7 +263,7 @@ static const unsigned char jump_to_bios
6311 + * specified by the code and length parameters.
6312 + * We assume that length will aways be less that 100!
6313 + */
6314 +-void machine_real_restart(const unsigned char *code, int length)
6315 ++void machine_real_restart(const unsigned char *code, unsigned int length)
6316 + {
6317 + local_irq_disable();
6318 +
6319 +@@ -283,8 +283,8 @@ void machine_real_restart(const unsigned
6320 + /* Remap the kernel at virtual address zero, as well as offset zero
6321 + from the kernel segment. This assumes the kernel segment starts at
6322 + virtual address PAGE_OFFSET. */
6323 +- memcpy(swapper_pg_dir, swapper_pg_dir + KERNEL_PGD_BOUNDARY,
6324 +- sizeof(swapper_pg_dir [0]) * KERNEL_PGD_PTRS);
6325 ++ clone_pgd_range(swapper_pg_dir, swapper_pg_dir + KERNEL_PGD_BOUNDARY,
6326 ++ min_t(unsigned long, KERNEL_PGD_PTRS, KERNEL_PGD_BOUNDARY));
6327 +
6328 + /*
6329 + * Use `swapper_pg_dir' as our page directory.
6330 +@@ -296,16 +296,15 @@ void machine_real_restart(const unsigned
6331 + boot)". This seems like a fairly standard thing that gets set by
6332 + REBOOT.COM programs, and the previous reset routine did this
6333 + too. */
6334 +- *((unsigned short *)0x472) = reboot_mode;
6335 ++ *(unsigned short *)(__va(0x472)) = reboot_mode;
6336 +
6337 + /* For the switch to real mode, copy some code to low memory. It has
6338 + to be in the first 64k because it is running in 16-bit mode, and it
6339 + has to have the same physical and virtual address, because it turns
6340 + off paging. Copy it near the end of the first page, out of the way
6341 + of BIOS variables. */
6342 +- memcpy((void *)(0x1000 - sizeof(real_mode_switch) - 100),
6343 +- real_mode_switch, sizeof (real_mode_switch));
6344 +- memcpy((void *)(0x1000 - 100), code, length);
6345 ++ memcpy(__va(0x1000 - sizeof (real_mode_switch) - 100), real_mode_switch, sizeof (real_mode_switch));
6346 ++ memcpy(__va(0x1000 - 100), code, length);
6347 +
6348 + /* Set up the IDT for real mode. */
6349 + load_idt(&real_mode_idt);
6350 +diff -urNp linux-2.6.27.10/arch/x86/kernel/setup.c linux-2.6.27.10/arch/x86/kernel/setup.c
6351 +--- linux-2.6.27.10/arch/x86/kernel/setup.c 2008-12-21 01:18:11.000000000 -0500
6352 ++++ linux-2.6.27.10/arch/x86/kernel/setup.c 2008-12-21 01:18:21.000000000 -0500
6353 +@@ -578,6 +578,7 @@ static struct x86_quirks default_x86_qui
6354 +
6355 + struct x86_quirks *x86_quirks __initdata = &default_x86_quirks;
6356 +
6357 ++#ifdef CONFIG_X86_RESERVE_LOW_64K
6358 + static int __init dmi_low_memory_corruption(const struct dmi_system_id *d)
6359 + {
6360 + printk(KERN_NOTICE
6361 +@@ -589,6 +590,7 @@ static int __init dmi_low_memory_corrupt
6362 +
6363 + return 0;
6364 + }
6365 ++#endif
6366 +
6367 + /* List of systems that have known low memory corruption BIOS problems */
6368 + static struct dmi_system_id __initdata bad_bios_dmi_table[] = {
6369 +@@ -685,8 +687,8 @@ void __init setup_arch(char **cmdline_p)
6370 +
6371 + if (!boot_params.hdr.root_flags)
6372 + root_mountflags &= ~MS_RDONLY;
6373 +- init_mm.start_code = (unsigned long) _text;
6374 +- init_mm.end_code = (unsigned long) _etext;
6375 ++ init_mm.start_code = ktla_ktva((unsigned long) _text);
6376 ++ init_mm.end_code = ktla_ktva((unsigned long) _etext);
6377 + init_mm.end_data = (unsigned long) _edata;
6378 + #ifdef CONFIG_X86_32
6379 + init_mm.brk = init_pg_tables_end + PAGE_OFFSET;
6380 +@@ -694,9 +696,9 @@ void __init setup_arch(char **cmdline_p)
6381 + init_mm.brk = (unsigned long) &_end;
6382 + #endif
6383 +
6384 +- code_resource.start = virt_to_phys(_text);
6385 +- code_resource.end = virt_to_phys(_etext)-1;
6386 +- data_resource.start = virt_to_phys(_etext);
6387 ++ code_resource.start = virt_to_phys(ktla_ktva(_text));
6388 ++ code_resource.end = virt_to_phys(ktla_ktva(_etext))-1;
6389 ++ data_resource.start = virt_to_phys(_data);
6390 + data_resource.end = virt_to_phys(_edata)-1;
6391 + bss_resource.start = virt_to_phys(&__bss_start);
6392 + bss_resource.end = virt_to_phys(&__bss_stop)-1;
6393 +diff -urNp linux-2.6.27.10/arch/x86/kernel/setup_percpu.c linux-2.6.27.10/arch/x86/kernel/setup_percpu.c
6394 +--- linux-2.6.27.10/arch/x86/kernel/setup_percpu.c 2008-11-07 12:55:34.000000000 -0500
6395 ++++ linux-2.6.27.10/arch/x86/kernel/setup_percpu.c 2008-11-18 03:38:44.000000000 -0500
6396 +@@ -166,7 +166,11 @@ void __init setup_per_cpu_areas(void)
6397 + else
6398 + ptr = alloc_bootmem_pages_node(NODE_DATA(node), size);
6399 + #endif
6400 ++#ifdef CONFIG_X86_32
6401 ++ __per_cpu_offset[cpu] = ptr - __per_cpu_start;
6402 ++#else
6403 + per_cpu_offset(cpu) = ptr - __per_cpu_start;
6404 ++#endif
6405 + memcpy(ptr, __per_cpu_start, __per_cpu_end - __per_cpu_start);
6406 +
6407 + }
6408 +diff -urNp linux-2.6.27.10/arch/x86/kernel/signal_32.c linux-2.6.27.10/arch/x86/kernel/signal_32.c
6409 +--- linux-2.6.27.10/arch/x86/kernel/signal_32.c 2008-11-07 12:55:34.000000000 -0500
6410 ++++ linux-2.6.27.10/arch/x86/kernel/signal_32.c 2008-11-18 03:38:44.000000000 -0500
6411 +@@ -378,9 +378,9 @@ setup_frame(int sig, struct k_sigaction
6412 + }
6413 +
6414 + if (current->mm->context.vdso)
6415 +- restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
6416 ++ restorer = (void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
6417 + else
6418 +- restorer = &frame->retcode;
6419 ++ restorer = (void __user *)&frame->retcode;
6420 + if (ka->sa.sa_flags & SA_RESTORER)
6421 + restorer = ka->sa.sa_restorer;
6422 +
6423 +@@ -460,7 +460,7 @@ static int setup_rt_frame(int sig, struc
6424 + goto give_sigsegv;
6425 +
6426 + /* Set up to return from userspace. */
6427 +- restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
6428 ++ restorer = (void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
6429 + if (ka->sa.sa_flags & SA_RESTORER)
6430 + restorer = ka->sa.sa_restorer;
6431 + err |= __put_user(restorer, &frame->pretcode);
6432 +@@ -590,7 +590,7 @@ static void do_signal(struct pt_regs *re
6433 + * X86_32: vm86 regs switched out by assembly code before reaching
6434 + * here, so testing against kernel CS suffices.
6435 + */
6436 +- if (!user_mode(regs))
6437 ++ if (!user_mode_novm(regs))
6438 + return;
6439 +
6440 + if (current_thread_info()->status & TS_RESTORE_SIGMASK)
6441 +diff -urNp linux-2.6.27.10/arch/x86/kernel/signal_64.c linux-2.6.27.10/arch/x86/kernel/signal_64.c
6442 +--- linux-2.6.27.10/arch/x86/kernel/signal_64.c 2008-11-07 12:55:34.000000000 -0500
6443 ++++ linux-2.6.27.10/arch/x86/kernel/signal_64.c 2008-11-18 03:38:44.000000000 -0500
6444 +@@ -312,8 +312,8 @@ static int setup_rt_frame(int sig, struc
6445 + err |= setup_sigcontext(&frame->uc.uc_mcontext, regs, set->sig[0], me);
6446 + err |= __put_user(fp, &frame->uc.uc_mcontext.fpstate);
6447 + if (sizeof(*set) == 16) {
6448 +- __put_user(set->sig[0], &frame->uc.uc_sigmask.sig[0]);
6449 +- __put_user(set->sig[1], &frame->uc.uc_sigmask.sig[1]);
6450 ++ err |= __put_user(set->sig[0], &frame->uc.uc_sigmask.sig[0]);
6451 ++ err |= __put_user(set->sig[1], &frame->uc.uc_sigmask.sig[1]);
6452 + } else
6453 + err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
6454 +
6455 +diff -urNp linux-2.6.27.10/arch/x86/kernel/smpboot.c linux-2.6.27.10/arch/x86/kernel/smpboot.c
6456 +--- linux-2.6.27.10/arch/x86/kernel/smpboot.c 2008-12-21 01:18:11.000000000 -0500
6457 ++++ linux-2.6.27.10/arch/x86/kernel/smpboot.c 2008-12-21 01:18:21.000000000 -0500
6458 +@@ -814,6 +814,11 @@ static int __cpuinit do_boot_cpu(int api
6459 + .cpu = cpu,
6460 + .done = COMPLETION_INITIALIZER_ONSTACK(c_idle.done),
6461 + };
6462 ++
6463 ++#ifdef CONFIG_PAX_KERNEXEC
6464 ++ unsigned long cr0;
6465 ++#endif
6466 ++
6467 + INIT_WORK(&c_idle.work, do_fork_idle);
6468 +
6469 + #ifdef CONFIG_X86_64
6470 +@@ -864,7 +869,17 @@ do_rest:
6471 + cpu_pda(cpu)->pcurrent = c_idle.idle;
6472 + clear_tsk_thread_flag(c_idle.idle, TIF_FORK);
6473 + #endif
6474 ++
6475 ++#ifdef CONFIG_PAX_KERNEXEC
6476 ++ pax_open_kernel(cr0);
6477 ++#endif
6478 ++
6479 + early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
6480 ++
6481 ++#ifdef CONFIG_PAX_KERNEXEC
6482 ++ pax_close_kernel(cr0);
6483 ++#endif
6484 ++
6485 + initial_code = (unsigned long)start_secondary;
6486 + stack_start.sp = (void *) c_idle.idle->thread.sp;
6487 +
6488 +diff -urNp linux-2.6.27.10/arch/x86/kernel/smpcommon.c linux-2.6.27.10/arch/x86/kernel/smpcommon.c
6489 +--- linux-2.6.27.10/arch/x86/kernel/smpcommon.c 2008-11-07 12:55:34.000000000 -0500
6490 ++++ linux-2.6.27.10/arch/x86/kernel/smpcommon.c 2008-11-18 03:38:44.000000000 -0500
6491 +@@ -3,9 +3,10 @@
6492 + */
6493 + #include <linux/module.h>
6494 + #include <asm/smp.h>
6495 ++#include <asm/sections.h>
6496 +
6497 + #ifdef CONFIG_X86_32
6498 +-DEFINE_PER_CPU(unsigned long, this_cpu_off);
6499 ++DEFINE_PER_CPU(unsigned long, this_cpu_off) = (unsigned long)__per_cpu_start;
6500 + EXPORT_PER_CPU_SYMBOL(this_cpu_off);
6501 +
6502 + /*
6503 +@@ -15,16 +16,19 @@ EXPORT_PER_CPU_SYMBOL(this_cpu_off);
6504 + */
6505 + __cpuinit void init_gdt(int cpu)
6506 + {
6507 +- struct desc_struct gdt;
6508 ++ struct desc_struct d, *gdt = get_cpu_gdt_table(cpu);
6509 ++ unsigned long base, limit;
6510 +
6511 +- pack_descriptor(&gdt, __per_cpu_offset[cpu], 0xFFFFF,
6512 +- 0x2 | DESCTYPE_S, 0x8);
6513 +- gdt.s = 1;
6514 ++ base = per_cpu_offset(cpu);
6515 ++ limit = PERCPU_ENOUGH_ROOM - 1;
6516 ++ if (limit < 64*1024)
6517 ++ pack_descriptor(&d, base, limit, 0x80 | DESCTYPE_S | 0x3, 0x4);
6518 ++ else
6519 ++ pack_descriptor(&d, base, limit >> PAGE_SHIFT, 0x80 | DESCTYPE_S | 0x3, 0xC);
6520 +
6521 +- write_gdt_entry(get_cpu_gdt_table(cpu),
6522 +- GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
6523 ++ write_gdt_entry(gdt, GDT_ENTRY_PERCPU, &d, DESCTYPE_S);
6524 +
6525 +- per_cpu(this_cpu_off, cpu) = __per_cpu_offset[cpu];
6526 ++ per_cpu(this_cpu_off, cpu) = base;
6527 + per_cpu(cpu_number, cpu) = cpu;
6528 + }
6529 + #endif
6530 +diff -urNp linux-2.6.27.10/arch/x86/kernel/step.c linux-2.6.27.10/arch/x86/kernel/step.c
6531 +--- linux-2.6.27.10/arch/x86/kernel/step.c 2008-11-07 12:55:34.000000000 -0500
6532 ++++ linux-2.6.27.10/arch/x86/kernel/step.c 2008-11-18 03:38:44.000000000 -0500
6533 +@@ -23,22 +23,20 @@ unsigned long convert_ip_to_linear(struc
6534 + * and APM bios ones we just ignore here.
6535 + */
6536 + if ((seg & SEGMENT_TI_MASK) == SEGMENT_LDT) {
6537 +- u32 *desc;
6538 ++ struct desc_struct *desc;
6539 + unsigned long base;
6540 +
6541 +- seg &= ~7UL;
6542 ++ seg >>= 3;
6543 +
6544 + mutex_lock(&child->mm->context.lock);
6545 +- if (unlikely((seg >> 3) >= child->mm->context.size))
6546 +- addr = -1L; /* bogus selector, access would fault */
6547 ++ if (unlikely(seg >= child->mm->context.size))
6548 ++ addr = -EINVAL;
6549 + else {
6550 +- desc = child->mm->context.ldt + seg;
6551 +- base = ((desc[0] >> 16) |
6552 +- ((desc[1] & 0xff) << 16) |
6553 +- (desc[1] & 0xff000000));
6554 ++ desc = &child->mm->context.ldt[seg];
6555 ++ base = (desc->a >> 16) | ((desc->b & 0xff) << 16) | (desc->b & 0xff000000);
6556 +
6557 + /* 16-bit code segment? */
6558 +- if (!((desc[1] >> 22) & 1))
6559 ++ if (!((desc->b >> 22) & 1))
6560 + addr &= 0xffff;
6561 + addr += base;
6562 + }
6563 +@@ -54,6 +52,9 @@ static int is_setting_trap_flag(struct t
6564 + unsigned char opcode[15];
6565 + unsigned long addr = convert_ip_to_linear(child, regs);
6566 +
6567 ++ if (addr == -EINVAL)
6568 ++ return 0;
6569 ++
6570 + copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
6571 + for (i = 0; i < copied; i++) {
6572 + switch (opcode[i]) {
6573 +@@ -75,7 +76,7 @@ static int is_setting_trap_flag(struct t
6574 +
6575 + #ifdef CONFIG_X86_64
6576 + case 0x40 ... 0x4f:
6577 +- if (regs->cs != __USER_CS)
6578 ++ if ((regs->cs & 0xffff) != __USER_CS)
6579 + /* 32-bit mode: register increment */
6580 + return 0;
6581 + /* 64-bit mode: REX prefix */
6582 +diff -urNp linux-2.6.27.10/arch/x86/kernel/syscall_table_32.S linux-2.6.27.10/arch/x86/kernel/syscall_table_32.S
6583 +--- linux-2.6.27.10/arch/x86/kernel/syscall_table_32.S 2008-11-07 12:55:34.000000000 -0500
6584 ++++ linux-2.6.27.10/arch/x86/kernel/syscall_table_32.S 2008-11-18 03:38:44.000000000 -0500
6585 +@@ -1,3 +1,4 @@
6586 ++.section .rodata,"a",@progbits
6587 + ENTRY(sys_call_table)
6588 + .long sys_restart_syscall /* 0 - old "setup()" system call, used for restarting */
6589 + .long sys_exit
6590 +diff -urNp linux-2.6.27.10/arch/x86/kernel/sys_i386_32.c linux-2.6.27.10/arch/x86/kernel/sys_i386_32.c
6591 +--- linux-2.6.27.10/arch/x86/kernel/sys_i386_32.c 2008-11-07 12:55:34.000000000 -0500
6592 ++++ linux-2.6.27.10/arch/x86/kernel/sys_i386_32.c 2008-11-18 03:38:44.000000000 -0500
6593 +@@ -22,6 +22,21 @@
6594 + #include <linux/uaccess.h>
6595 + #include <linux/unistd.h>
6596 +
6597 ++int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
6598 ++{
6599 ++ unsigned long pax_task_size = TASK_SIZE;
6600 ++
6601 ++#ifdef CONFIG_PAX_SEGMEXEC
6602 ++ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
6603 ++ pax_task_size = SEGMEXEC_TASK_SIZE;
6604 ++#endif
6605 ++
6606 ++ if (len > pax_task_size || addr > pax_task_size - len)
6607 ++ return -EINVAL;
6608 ++
6609 ++ return 0;
6610 ++}
6611 ++
6612 + asmlinkage long sys_mmap2(unsigned long addr, unsigned long len,
6613 + unsigned long prot, unsigned long flags,
6614 + unsigned long fd, unsigned long pgoff)
6615 +@@ -81,6 +96,205 @@ out:
6616 + return err;
6617 + }
6618 +
6619 ++unsigned long
6620 ++arch_get_unmapped_area(struct file *filp, unsigned long addr,
6621 ++ unsigned long len, unsigned long pgoff, unsigned long flags)
6622 ++{
6623 ++ struct mm_struct *mm = current->mm;
6624 ++ struct vm_area_struct *vma;
6625 ++ unsigned long start_addr, pax_task_size = TASK_SIZE;
6626 ++
6627 ++#ifdef CONFIG_PAX_SEGMEXEC
6628 ++ if (mm->pax_flags & MF_PAX_SEGMEXEC)
6629 ++ pax_task_size = SEGMEXEC_TASK_SIZE;
6630 ++#endif
6631 ++
6632 ++ if (len > pax_task_size)
6633 ++ return -ENOMEM;
6634 ++
6635 ++ if (flags & MAP_FIXED)
6636 ++ return addr;
6637 ++
6638 ++#ifdef CONFIG_PAX_RANDMMAP
6639 ++ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || !filp)
6640 ++#endif
6641 ++
6642 ++ if (addr) {
6643 ++ addr = PAGE_ALIGN(addr);
6644 ++ vma = find_vma(mm, addr);
6645 ++ if (pax_task_size - len >= addr &&
6646 ++ (!vma || addr + len <= vma->vm_start))
6647 ++ return addr;
6648 ++ }
6649 ++ if (len > mm->cached_hole_size) {
6650 ++ start_addr = addr = mm->free_area_cache;
6651 ++ } else {
6652 ++ start_addr = addr = mm->mmap_base;
6653 ++ mm->cached_hole_size = 0;
6654 ++ }
6655 ++
6656 ++#ifdef CONFIG_PAX_PAGEEXEC
6657 ++ if (!nx_enabled && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE) && start_addr >= mm->mmap_base) {
6658 ++ start_addr = 0x00110000UL;
6659 ++
6660 ++#ifdef CONFIG_PAX_RANDMMAP
6661 ++ if (mm->pax_flags & MF_PAX_RANDMMAP)
6662 ++ start_addr += mm->delta_mmap & 0x03FFF000UL;
6663 ++#endif
6664 ++
6665 ++ if (mm->start_brk <= start_addr && start_addr < mm->mmap_base)
6666 ++ start_addr = addr = mm->mmap_base;
6667 ++ else
6668 ++ addr = start_addr;
6669 ++ }
6670 ++#endif
6671 ++
6672 ++full_search:
6673 ++ for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
6674 ++ /* At this point: (!vma || addr < vma->vm_end). */
6675 ++ if (pax_task_size - len < addr) {
6676 ++ /*
6677 ++ * Start a new search - just in case we missed
6678 ++ * some holes.
6679 ++ */
6680 ++ if (start_addr != mm->mmap_base) {
6681 ++ start_addr = addr = mm->mmap_base;
6682 ++ mm->cached_hole_size = 0;
6683 ++ goto full_search;
6684 ++ }
6685 ++ return -ENOMEM;
6686 ++ }
6687 ++ if (!vma || addr + len <= vma->vm_start) {
6688 ++ /*
6689 ++ * Remember the place where we stopped the search:
6690 ++ */
6691 ++ mm->free_area_cache = addr + len;
6692 ++ return addr;
6693 ++ }
6694 ++ if (addr + mm->cached_hole_size < vma->vm_start)
6695 ++ mm->cached_hole_size = vma->vm_start - addr;
6696 ++ addr = vma->vm_end;
6697 ++ if (mm->start_brk <= addr && addr < mm->mmap_base) {
6698 ++ start_addr = addr = mm->mmap_base;
6699 ++ mm->cached_hole_size = 0;
6700 ++ goto full_search;
6701 ++ }
6702 ++ }
6703 ++}
6704 ++
6705 ++unsigned long
6706 ++arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
6707 ++ const unsigned long len, const unsigned long pgoff,
6708 ++ const unsigned long flags)
6709 ++{
6710 ++ struct vm_area_struct *vma;
6711 ++ struct mm_struct *mm = current->mm;
6712 ++ unsigned long base = mm->mmap_base, addr = addr0, pax_task_size = TASK_SIZE;
6713 ++
6714 ++#ifdef CONFIG_PAX_SEGMEXEC
6715 ++ if (mm->pax_flags & MF_PAX_SEGMEXEC)
6716 ++ pax_task_size = SEGMEXEC_TASK_SIZE;
6717 ++#endif
6718 ++
6719 ++ /* requested length too big for entire address space */
6720 ++ if (len > pax_task_size)
6721 ++ return -ENOMEM;
6722 ++
6723 ++ if (flags & MAP_FIXED)
6724 ++ return addr;
6725 ++
6726 ++#ifdef CONFIG_PAX_PAGEEXEC
6727 ++ if (!nx_enabled && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
6728 ++ goto bottomup;
6729 ++#endif
6730 ++
6731 ++#ifdef CONFIG_PAX_RANDMMAP
6732 ++ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || !filp)
6733 ++#endif
6734 ++
6735 ++ /* requesting a specific address */
6736 ++ if (addr) {
6737 ++ addr = PAGE_ALIGN(addr);
6738 ++ vma = find_vma(mm, addr);
6739 ++ if (pax_task_size - len >= addr &&
6740 ++ (!vma || addr + len <= vma->vm_start))
6741 ++ return addr;
6742 ++ }
6743 ++
6744 ++ /* check if free_area_cache is useful for us */
6745 ++ if (len <= mm->cached_hole_size) {
6746 ++ mm->cached_hole_size = 0;
6747 ++ mm->free_area_cache = mm->mmap_base;
6748 ++ }
6749 ++
6750 ++ /* either no address requested or can't fit in requested address hole */
6751 ++ addr = mm->free_area_cache;
6752 ++
6753 ++ /* make sure it can fit in the remaining address space */
6754 ++ if (addr > len) {
6755 ++ vma = find_vma(mm, addr-len);
6756 ++ if (!vma || addr <= vma->vm_start)
6757 ++ /* remember the address as a hint for next time */
6758 ++ return (mm->free_area_cache = addr-len);
6759 ++ }
6760 ++
6761 ++ if (mm->mmap_base < len)
6762 ++ goto bottomup;
6763 ++
6764 ++ addr = mm->mmap_base-len;
6765 ++
6766 ++ do {
6767 ++ /*
6768 ++ * Lookup failure means no vma is above this address,
6769 ++ * else if new region fits below vma->vm_start,
6770 ++ * return with success:
6771 ++ */
6772 ++ vma = find_vma(mm, addr);
6773 ++ if (!vma || addr+len <= vma->vm_start)
6774 ++ /* remember the address as a hint for next time */
6775 ++ return (mm->free_area_cache = addr);
6776 ++
6777 ++ /* remember the largest hole we saw so far */
6778 ++ if (addr + mm->cached_hole_size < vma->vm_start)
6779 ++ mm->cached_hole_size = vma->vm_start - addr;
6780 ++
6781 ++ /* try just below the current vma->vm_start */
6782 ++ addr = vma->vm_start-len;
6783 ++ } while (len < vma->vm_start);
6784 ++
6785 ++bottomup:
6786 ++ /*
6787 ++ * A failed mmap() very likely causes application failure,
6788 ++ * so fall back to the bottom-up function here. This scenario
6789 ++ * can happen with large stack limits and large mmap()
6790 ++ * allocations.
6791 ++ */
6792 ++
6793 ++#ifdef CONFIG_PAX_SEGMEXEC
6794 ++ if (mm->pax_flags & MF_PAX_SEGMEXEC)
6795 ++ mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
6796 ++ else
6797 ++#endif
6798 ++
6799 ++ mm->mmap_base = TASK_UNMAPPED_BASE;
6800 ++
6801 ++#ifdef CONFIG_PAX_RANDMMAP
6802 ++ if (mm->pax_flags & MF_PAX_RANDMMAP)
6803 ++ mm->mmap_base += mm->delta_mmap;
6804 ++#endif
6805 ++
6806 ++ mm->free_area_cache = mm->mmap_base;
6807 ++ mm->cached_hole_size = ~0UL;
6808 ++ addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
6809 ++ /*
6810 ++ * Restore the topdown base:
6811 ++ */
6812 ++ mm->mmap_base = base;
6813 ++ mm->free_area_cache = base;
6814 ++ mm->cached_hole_size = ~0UL;
6815 ++
6816 ++ return addr;
6817 ++}
6818 +
6819 + struct sel_arg_struct {
6820 + unsigned long n;
6821 +diff -urNp linux-2.6.27.10/arch/x86/kernel/sys_x86_64.c linux-2.6.27.10/arch/x86/kernel/sys_x86_64.c
6822 +--- linux-2.6.27.10/arch/x86/kernel/sys_x86_64.c 2008-11-07 12:55:34.000000000 -0500
6823 ++++ linux-2.6.27.10/arch/x86/kernel/sys_x86_64.c 2008-11-18 03:38:44.000000000 -0500
6824 +@@ -45,8 +45,8 @@ out:
6825 + return error;
6826 + }
6827 +
6828 +-static void find_start_end(unsigned long flags, unsigned long *begin,
6829 +- unsigned long *end)
6830 ++static void find_start_end(struct mm_struct *mm, unsigned long flags,
6831 ++ unsigned long *begin, unsigned long *end)
6832 + {
6833 + if (!test_thread_flag(TIF_IA32) && (flags & MAP_32BIT)) {
6834 + unsigned long new_begin;
6835 +@@ -65,7 +65,7 @@ static void find_start_end(unsigned long
6836 + *begin = new_begin;
6837 + }
6838 + } else {
6839 +- *begin = TASK_UNMAPPED_BASE;
6840 ++ *begin = mm->mmap_base;
6841 + *end = TASK_SIZE;
6842 + }
6843 + }
6844 +@@ -82,11 +82,15 @@ arch_get_unmapped_area(struct file *filp
6845 + if (flags & MAP_FIXED)
6846 + return addr;
6847 +
6848 +- find_start_end(flags, &begin, &end);
6849 ++ find_start_end(mm, flags, &begin, &end);
6850 +
6851 + if (len > end)
6852 + return -ENOMEM;
6853 +
6854 ++#ifdef CONFIG_PAX_RANDMMAP
6855 ++ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || !filp)
6856 ++#endif
6857 ++
6858 + if (addr) {
6859 + addr = PAGE_ALIGN(addr);
6860 + vma = find_vma(mm, addr);
6861 +@@ -141,7 +145,7 @@ arch_get_unmapped_area_topdown(struct fi
6862 + {
6863 + struct vm_area_struct *vma;
6864 + struct mm_struct *mm = current->mm;
6865 +- unsigned long addr = addr0;
6866 ++ unsigned long base = mm->mmap_base, addr = addr0;
6867 +
6868 + /* requested length too big for entire address space */
6869 + if (len > TASK_SIZE)
6870 +@@ -154,6 +158,10 @@ arch_get_unmapped_area_topdown(struct fi
6871 + if (!test_thread_flag(TIF_IA32) && (flags & MAP_32BIT))
6872 + goto bottomup;
6873 +
6874 ++#ifdef CONFIG_PAX_RANDMMAP
6875 ++ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
6876 ++#endif
6877 ++
6878 + /* requesting a specific address */
6879 + if (addr) {
6880 + addr = PAGE_ALIGN(addr);
6881 +@@ -211,13 +219,21 @@ bottomup:
6882 + * can happen with large stack limits and large mmap()
6883 + * allocations.
6884 + */
6885 ++ mm->mmap_base = TASK_UNMAPPED_BASE;
6886 ++
6887 ++#ifdef CONFIG_PAX_RANDMMAP
6888 ++ if (mm->pax_flags & MF_PAX_RANDMMAP)
6889 ++ mm->mmap_base += mm->delta_mmap;
6890 ++#endif
6891 ++
6892 ++ mm->free_area_cache = mm->mmap_base;
6893 + mm->cached_hole_size = ~0UL;
6894 +- mm->free_area_cache = TASK_UNMAPPED_BASE;
6895 + addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
6896 + /*
6897 + * Restore the topdown base:
6898 + */
6899 +- mm->free_area_cache = mm->mmap_base;
6900 ++ mm->mmap_base = base;
6901 ++ mm->free_area_cache = base;
6902 + mm->cached_hole_size = ~0UL;
6903 +
6904 + return addr;
6905 +diff -urNp linux-2.6.27.10/arch/x86/kernel/time_32.c linux-2.6.27.10/arch/x86/kernel/time_32.c
6906 +--- linux-2.6.27.10/arch/x86/kernel/time_32.c 2008-11-07 12:55:34.000000000 -0500
6907 ++++ linux-2.6.27.10/arch/x86/kernel/time_32.c 2008-11-18 03:38:44.000000000 -0500
6908 +@@ -49,20 +49,30 @@ unsigned long profile_pc(struct pt_regs
6909 + if (!v8086_mode(regs) && SEGMENT_IS_KERNEL_CODE(regs->cs) &&
6910 + in_lock_functions(pc)) {
6911 + #ifdef CONFIG_FRAME_POINTER
6912 +- return *(unsigned long *)(regs->bp + 4);
6913 ++ return ktla_ktva(*(unsigned long *)(regs->bp + 4));
6914 + #else
6915 + unsigned long *sp = (unsigned long *)&regs->sp;
6916 +
6917 + /* Return address is either directly at stack pointer
6918 + or above a saved flags. Eflags has bits 22-31 zero,
6919 + kernel addresses don't. */
6920 ++
6921 ++#ifdef CONFIG_PAX_KERNEXEC
6922 ++ return ktla_ktva(sp[0]);
6923 ++#else
6924 + if (sp[0] >> 22)
6925 + return sp[0];
6926 + if (sp[1] >> 22)
6927 + return sp[1];
6928 + #endif
6929 ++
6930 ++#endif
6931 + }
6932 + #endif
6933 ++
6934 ++ if (!v8086_mode(regs) && SEGMENT_IS_KERNEL_CODE(regs->cs))
6935 ++ pc = ktla_ktva(pc);
6936 ++
6937 + return pc;
6938 + }
6939 + EXPORT_SYMBOL(profile_pc);
6940 +diff -urNp linux-2.6.27.10/arch/x86/kernel/tlb_32.c linux-2.6.27.10/arch/x86/kernel/tlb_32.c
6941 +--- linux-2.6.27.10/arch/x86/kernel/tlb_32.c 2008-11-07 12:55:34.000000000 -0500
6942 ++++ linux-2.6.27.10/arch/x86/kernel/tlb_32.c 2008-11-18 03:38:44.000000000 -0500
6943 +@@ -5,7 +5,7 @@
6944 + #include <asm/tlbflush.h>
6945 +
6946 + DEFINE_PER_CPU(struct tlb_state, cpu_tlbstate)
6947 +- ____cacheline_aligned = { &init_mm, 0, };
6948 ++ ____cacheline_aligned = { &init_mm, 0, {0} };
6949 +
6950 + /* must come after the send_IPI functions above for inlining */
6951 + #include <mach_ipi.h>
6952 +diff -urNp linux-2.6.27.10/arch/x86/kernel/tls.c linux-2.6.27.10/arch/x86/kernel/tls.c
6953 +--- linux-2.6.27.10/arch/x86/kernel/tls.c 2008-11-07 12:55:34.000000000 -0500
6954 ++++ linux-2.6.27.10/arch/x86/kernel/tls.c 2008-11-18 03:38:44.000000000 -0500
6955 +@@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struc
6956 + if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
6957 + return -EINVAL;
6958 +
6959 ++#ifdef CONFIG_PAX_SEGMEXEC
6960 ++ if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
6961 ++ return -EINVAL;
6962 ++#endif
6963 ++
6964 + set_tls_desc(p, idx, &info, 1);
6965 +
6966 + return 0;
6967 +diff -urNp linux-2.6.27.10/arch/x86/kernel/traps_32.c linux-2.6.27.10/arch/x86/kernel/traps_32.c
6968 +--- linux-2.6.27.10/arch/x86/kernel/traps_32.c 2008-11-07 12:55:34.000000000 -0500
6969 ++++ linux-2.6.27.10/arch/x86/kernel/traps_32.c 2008-12-10 22:28:27.000000000 -0500
6970 +@@ -70,14 +70,6 @@ asmlinkage int system_call(void);
6971 + /* Do we ignore FPU interrupts ? */
6972 + char ignore_fpu_irq;
6973 +
6974 +-/*
6975 +- * The IDT has to be page-aligned to simplify the Pentium
6976 +- * F0 0F bug workaround.. We have a special link segment
6977 +- * for this.
6978 +- */
6979 +-gate_desc idt_table[256]
6980 +- __attribute__((__section__(".data.idt"))) = { { { { 0, 0 } } }, };
6981 +-
6982 + int panic_on_unrecovered_nmi;
6983 + int kstack_depth_to_print = 24;
6984 + static unsigned int code_bytes = 64;
6985 +@@ -320,21 +312,22 @@ void show_registers(struct pt_regs *regs
6986 + * When in-kernel, we also print out the stack and code at the
6987 + * time of the fault..
6988 + */
6989 +- if (!user_mode_vm(regs)) {
6990 ++ if (!user_mode(regs)) {
6991 + unsigned int code_prologue = code_bytes * 43 / 64;
6992 + unsigned int code_len = code_bytes;
6993 + unsigned char c;
6994 + u8 *ip;
6995 ++ unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(smp_processor_id())[(0xffff & regs->cs) >> 3]);
6996 +
6997 + printk("\n" KERN_EMERG "Stack: ");
6998 + show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
6999 +
7000 + printk(KERN_EMERG "Code: ");
7001 +
7002 +- ip = (u8 *)regs->ip - code_prologue;
7003 ++ ip = (u8 *)regs->ip - code_prologue + cs_base;
7004 + if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
7005 + /* try starting at EIP */
7006 +- ip = (u8 *)regs->ip;
7007 ++ ip = (u8 *)regs->ip + cs_base;
7008 + code_len = code_len - code_prologue + 1;
7009 + }
7010 + for (i = 0; i < code_len; i++, ip++) {
7011 +@@ -343,7 +336,7 @@ void show_registers(struct pt_regs *regs
7012 + printk(" Bad EIP value.");
7013 + break;
7014 + }
7015 +- if (ip == (u8 *)regs->ip)
7016 ++ if (ip == (u8 *)regs->ip + cs_base)
7017 + printk("<%02x> ", c);
7018 + else
7019 + printk("%02x ", c);
7020 +@@ -356,6 +349,7 @@ int is_valid_bugaddr(unsigned long ip)
7021 + {
7022 + unsigned short ud2;
7023 +
7024 ++ ip = ktla_ktva(ip);
7025 + if (ip < PAGE_OFFSET)
7026 + return 0;
7027 + if (probe_kernel_address((unsigned short *)ip, ud2))
7028 +@@ -469,7 +463,7 @@ void die(const char *str, struct pt_regs
7029 + static inline void
7030 + die_if_kernel(const char *str, struct pt_regs *regs, long err)
7031 + {
7032 +- if (!user_mode_vm(regs))
7033 ++ if (!user_mode(regs))
7034 + die(str, regs, err);
7035 + }
7036 +
7037 +@@ -479,13 +473,13 @@ do_trap(int trapnr, int signr, char *str
7038 + {
7039 + struct task_struct *tsk = current;
7040 +
7041 +- if (regs->flags & X86_VM_MASK) {
7042 ++ if (v8086_mode(regs)) {
7043 + if (vm86)
7044 + goto vm86_trap;
7045 + goto trap_signal;
7046 + }
7047 +
7048 +- if (!user_mode(regs))
7049 ++ if (!user_mode_novm(regs))
7050 + goto kernel_trap;
7051 +
7052 + trap_signal:
7053 +@@ -513,6 +507,12 @@ kernel_trap:
7054 + tsk->thread.trap_no = trapnr;
7055 + die(str, regs, error_code);
7056 + }
7057 ++
7058 ++#ifdef CONFIG_PAX_REFCOUNT
7059 ++ if (trapnr == 4)
7060 ++ pax_report_refcount_overflow(regs);
7061 ++#endif
7062 ++
7063 + return;
7064 +
7065 + vm86_trap:
7066 +@@ -595,7 +595,7 @@ do_general_protection(struct pt_regs *re
7067 + int cpu;
7068 +
7069 + cpu = get_cpu();
7070 +- tss = &per_cpu(init_tss, cpu);
7071 ++ tss = init_tss + cpu;
7072 + thread = &current->thread;
7073 +
7074 + /*
7075 +@@ -627,13 +627,29 @@ do_general_protection(struct pt_regs *re
7076 + }
7077 + put_cpu();
7078 +
7079 +- if (regs->flags & X86_VM_MASK)
7080 ++ if (v8086_mode(regs))
7081 + goto gp_in_vm86;
7082 +
7083 + tsk = current;
7084 +- if (!user_mode(regs))
7085 ++ if (!user_mode_novm(regs))
7086 + goto gp_in_kernel;
7087 +
7088 ++#ifdef CONFIG_PAX_PAGEEXEC
7089 ++ if (!nx_enabled && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
7090 ++ struct mm_struct *mm = tsk->mm;
7091 ++ unsigned long limit;
7092 ++
7093 ++ down_write(&mm->mmap_sem);
7094 ++ limit = mm->context.user_cs_limit;
7095 ++ if (limit < TASK_SIZE) {
7096 ++ track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
7097 ++ up_write(&mm->mmap_sem);
7098 ++ return;
7099 ++ }
7100 ++ up_write(&mm->mmap_sem);
7101 ++ }
7102 ++#endif
7103 ++
7104 + tsk->thread.error_code = error_code;
7105 + tsk->thread.trap_no = 13;
7106 +
7107 +@@ -664,6 +680,13 @@ gp_in_kernel:
7108 + if (notify_die(DIE_GPF, "general protection fault", regs,
7109 + error_code, 13, SIGSEGV) == NOTIFY_STOP)
7110 + return;
7111 ++
7112 ++#ifdef CONFIG_PAX_KERNEXEC
7113 ++ if ((regs->cs & 0xFFFF) == __KERNEL_CS)
7114 ++ die("PAX: suspicious general protection fault", regs, error_code);
7115 ++ else
7116 ++#endif
7117 ++
7118 + die("general protection fault", regs, error_code);
7119 + }
7120 +
7121 +@@ -766,7 +789,7 @@ void notrace __kprobes die_nmi(char *str
7122 + * If we are in kernel we are probably nested up pretty bad
7123 + * and might aswell get out now while we still can:
7124 + */
7125 +- if (!user_mode_vm(regs)) {
7126 ++ if (!user_mode(regs)) {
7127 + current->thread.trap_no = 2;
7128 + crash_kexec(regs);
7129 + }
7130 +@@ -915,7 +938,7 @@ void __kprobes do_debug(struct pt_regs *
7131 + goto clear_dr7;
7132 + }
7133 +
7134 +- if (regs->flags & X86_VM_MASK)
7135 ++ if (v8086_mode(regs))
7136 + goto debug_vm86;
7137 +
7138 + /* Save debug status register where ptrace can see it */
7139 +@@ -931,7 +954,7 @@ void __kprobes do_debug(struct pt_regs *
7140 + * check for kernel mode by just checking the CPL
7141 + * of CS.
7142 + */
7143 +- if (!user_mode(regs))
7144 ++ if (!user_mode_novm(regs))
7145 + goto clear_TF_reenable;
7146 + }
7147 +
7148 +@@ -1086,7 +1109,7 @@ void do_simd_coprocessor_error(struct pt
7149 + * Handle strange cache flush from user space exception
7150 + * in all other cases. This is undocumented behaviour.
7151 + */
7152 +- if (regs->flags & X86_VM_MASK) {
7153 ++ if (v8086_mode(regs)) {
7154 + handle_vm86_fault((struct kernel_vm86_regs *)regs, error_code);
7155 + return;
7156 + }
7157 +@@ -1106,19 +1129,14 @@ void do_spurious_interrupt_bug(struct pt
7158 +
7159 + unsigned long patch_espfix_desc(unsigned long uesp, unsigned long kesp)
7160 + {
7161 +- struct desc_struct *gdt = get_cpu_gdt_table(smp_processor_id());
7162 + unsigned long base = (kesp - uesp) & -THREAD_SIZE;
7163 + unsigned long new_kesp = kesp - base;
7164 + unsigned long lim_pages = (new_kesp | (THREAD_SIZE - 1)) >> PAGE_SHIFT;
7165 +- __u64 desc = *(__u64 *)&gdt[GDT_ENTRY_ESPFIX_SS];
7166 ++ struct desc_struct ss;
7167 +
7168 + /* Set up base for espfix segment */
7169 +- desc &= 0x00f0ff0000000000ULL;
7170 +- desc |= ((((__u64)base) << 16) & 0x000000ffffff0000ULL) |
7171 +- ((((__u64)base) << 32) & 0xff00000000000000ULL) |
7172 +- ((((__u64)lim_pages) << 32) & 0x000f000000000000ULL) |
7173 +- (lim_pages & 0xffff);
7174 +- *(__u64 *)&gdt[GDT_ENTRY_ESPFIX_SS] = desc;
7175 ++ pack_descriptor(&ss, base, lim_pages, 0x93, 0xC);
7176 ++ write_gdt_entry(get_cpu_gdt_table(smp_processor_id()), GDT_ENTRY_ESPFIX_SS, &ss, DESCTYPE_S);
7177 +
7178 + return new_kesp;
7179 + }
7180 +diff -urNp linux-2.6.27.10/arch/x86/kernel/traps_64.c linux-2.6.27.10/arch/x86/kernel/traps_64.c
7181 +--- linux-2.6.27.10/arch/x86/kernel/traps_64.c 2008-11-07 12:55:34.000000000 -0500
7182 ++++ linux-2.6.27.10/arch/x86/kernel/traps_64.c 2008-11-18 03:38:44.000000000 -0500
7183 +@@ -634,6 +634,12 @@ kernel_trap:
7184 + tsk->thread.trap_no = trapnr;
7185 + die(str, regs, error_code);
7186 + }
7187 ++
7188 ++#ifdef CONFIG_PAX_REFCOUNT
7189 ++ if (trapnr == 4)
7190 ++ pax_report_refcount_overflow(regs);
7191 ++#endif
7192 ++
7193 + return;
7194 + }
7195 +
7196 +diff -urNp linux-2.6.27.10/arch/x86/kernel/tsc.c linux-2.6.27.10/arch/x86/kernel/tsc.c
7197 +--- linux-2.6.27.10/arch/x86/kernel/tsc.c 2008-11-17 20:03:30.000000000 -0500
7198 ++++ linux-2.6.27.10/arch/x86/kernel/tsc.c 2008-11-18 03:38:44.000000000 -0500
7199 +@@ -554,7 +554,7 @@ static struct dmi_system_id __initdata b
7200 + DMI_MATCH(DMI_BOARD_NAME, "2635FA0"),
7201 + },
7202 + },
7203 +- {}
7204 ++ { NULL, NULL, {{0, NULL}}, NULL}
7205 + };
7206 +
7207 + /*
7208 +diff -urNp linux-2.6.27.10/arch/x86/kernel/vm86_32.c linux-2.6.27.10/arch/x86/kernel/vm86_32.c
7209 +--- linux-2.6.27.10/arch/x86/kernel/vm86_32.c 2008-11-07 12:55:34.000000000 -0500
7210 ++++ linux-2.6.27.10/arch/x86/kernel/vm86_32.c 2008-11-18 03:38:44.000000000 -0500
7211 +@@ -147,7 +147,7 @@ struct pt_regs *save_v86_state(struct ke
7212 + do_exit(SIGSEGV);
7213 + }
7214 +
7215 +- tss = &per_cpu(init_tss, get_cpu());
7216 ++ tss = init_tss + get_cpu();
7217 + current->thread.sp0 = current->thread.saved_sp0;
7218 + current->thread.sysenter_cs = __KERNEL_CS;
7219 + load_sp0(tss, &current->thread);
7220 +@@ -324,7 +324,7 @@ static void do_sys_vm86(struct kernel_vm
7221 + tsk->thread.saved_fs = info->regs32->fs;
7222 + savesegment(gs, tsk->thread.saved_gs);
7223 +
7224 +- tss = &per_cpu(init_tss, get_cpu());
7225 ++ tss = init_tss + get_cpu();
7226 + tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
7227 + if (cpu_has_sep)
7228 + tsk->thread.sysenter_cs = 0;
7229 +diff -urNp linux-2.6.27.10/arch/x86/kernel/vmi_32.c linux-2.6.27.10/arch/x86/kernel/vmi_32.c
7230 +--- linux-2.6.27.10/arch/x86/kernel/vmi_32.c 2008-12-21 01:18:11.000000000 -0500
7231 ++++ linux-2.6.27.10/arch/x86/kernel/vmi_32.c 2008-12-21 01:18:21.000000000 -0500
7232 +@@ -102,18 +102,43 @@ static unsigned patch_internal(int call,
7233 + {
7234 + u64 reloc;
7235 + struct vmi_relocation_info *const rel = (struct vmi_relocation_info *)&reloc;
7236 ++
7237 ++#ifdef CONFIG_PAX_KERNEXEC
7238 ++ unsigned long cr0;
7239 ++#endif
7240 ++
7241 + reloc = call_vrom_long_func(vmi_rom, get_reloc, call);
7242 + switch(rel->type) {
7243 + case VMI_RELOCATION_CALL_REL:
7244 + BUG_ON(len < 5);
7245 ++
7246 ++#ifdef CONFIG_PAX_KERNEXEC
7247 ++ pax_open_kernel(cr0);
7248 ++#endif
7249 ++
7250 + *(char *)insnbuf = MNEM_CALL;
7251 + patch_offset(insnbuf, ip, (unsigned long)rel->eip);
7252 ++
7253 ++#ifdef CONFIG_PAX_KERNEXEC
7254 ++ pax_close_kernel(cr0);
7255 ++#endif
7256 ++
7257 + return 5;
7258 +
7259 + case VMI_RELOCATION_JUMP_REL:
7260 + BUG_ON(len < 5);
7261 ++
7262 ++#ifdef CONFIG_PAX_KERNEXEC
7263 ++ pax_open_kernel(cr0);
7264 ++#endif
7265 ++
7266 + *(char *)insnbuf = MNEM_JMP;
7267 + patch_offset(insnbuf, ip, (unsigned long)rel->eip);
7268 ++
7269 ++#ifdef CONFIG_PAX_KERNEXEC
7270 ++ pax_close_kernel(cr0);
7271 ++#endif
7272 ++
7273 + return 5;
7274 +
7275 + case VMI_RELOCATION_NOP:
7276 +@@ -516,14 +541,14 @@ static void vmi_set_pud(pud_t *pudp, pud
7277 +
7278 + static void vmi_pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
7279 + {
7280 +- const pte_t pte = { .pte = 0 };
7281 ++ const pte_t pte = __pte(0ULL);
7282 + vmi_check_page_type(__pa(ptep) >> PAGE_SHIFT, VMI_PAGE_PTE);
7283 + vmi_ops.set_pte(pte, ptep, vmi_flags_addr(mm, addr, VMI_PAGE_PT, 0));
7284 + }
7285 +
7286 + static void vmi_pmd_clear(pmd_t *pmd)
7287 + {
7288 +- const pte_t pte = { .pte = 0 };
7289 ++ const pte_t pte = __pte(0ULL);
7290 + vmi_check_page_type(__pa(pmd) >> PAGE_SHIFT, VMI_PAGE_PMD);
7291 + vmi_ops.set_pte(pte, (pte_t *)pmd, VMI_PAGE_PD);
7292 + }
7293 +@@ -552,8 +577,8 @@ vmi_startup_ipi_hook(int phys_apicid, un
7294 + ap.ss = __KERNEL_DS;
7295 + ap.esp = (unsigned long) start_esp;
7296 +
7297 +- ap.ds = __USER_DS;
7298 +- ap.es = __USER_DS;
7299 ++ ap.ds = __KERNEL_DS;
7300 ++ ap.es = __KERNEL_DS;
7301 + ap.fs = __KERNEL_PERCPU;
7302 + ap.gs = 0;
7303 +
7304 +@@ -748,12 +773,20 @@ static inline int __init activate_vmi(vo
7305 + u64 reloc;
7306 + const struct vmi_relocation_info *rel = (struct vmi_relocation_info *)&reloc;
7307 +
7308 ++#ifdef CONFIG_PAX_KERNEXEC
7309 ++ unsigned long cr0;
7310 ++#endif
7311 ++
7312 + if (call_vrom_func(vmi_rom, vmi_init) != 0) {
7313 + printk(KERN_ERR "VMI ROM failed to initialize!");
7314 + return 0;
7315 + }
7316 + savesegment(cs, kernel_cs);
7317 +
7318 ++#ifdef CONFIG_PAX_KERNEXEC
7319 ++ pax_open_kernel(cr0);
7320 ++#endif
7321 ++
7322 + pv_info.paravirt_enabled = 1;
7323 + pv_info.kernel_rpl = kernel_cs & SEGMENT_RPL_MASK;
7324 + pv_info.name = "vmi";
7325 +@@ -943,6 +976,10 @@ static inline int __init activate_vmi(vo
7326 +
7327 + para_fill(pv_irq_ops.safe_halt, Halt);
7328 +
7329 ++#ifdef CONFIG_PAX_KERNEXEC
7330 ++ pax_close_kernel(cr0);
7331 ++#endif
7332 ++
7333 + /*
7334 + * Alternative instruction rewriting doesn't happen soon enough
7335 + * to convert VMI_IRET to a call instead of a jump; so we have
7336 +diff -urNp linux-2.6.27.10/arch/x86/kernel/vmlinux_32.lds.S linux-2.6.27.10/arch/x86/kernel/vmlinux_32.lds.S
7337 +--- linux-2.6.27.10/arch/x86/kernel/vmlinux_32.lds.S 2008-11-07 12:55:34.000000000 -0500
7338 ++++ linux-2.6.27.10/arch/x86/kernel/vmlinux_32.lds.S 2008-11-18 03:38:44.000000000 -0500
7339 +@@ -15,6 +15,20 @@
7340 + #include <asm/page.h>
7341 + #include <asm/cache.h>
7342 + #include <asm/boot.h>
7343 ++#include <asm/segment.h>
7344 ++
7345 ++#ifdef CONFIG_X86_PAE
7346 ++#define PMD_SHIFT 21
7347 ++#else
7348 ++#define PMD_SHIFT 22
7349 ++#endif
7350 ++#define PMD_SIZE (1 << PMD_SHIFT)
7351 ++
7352 ++#ifdef CONFIG_PAX_KERNEXEC
7353 ++#define __KERNEL_TEXT_OFFSET (__PAGE_OFFSET + (((____LOAD_PHYSICAL_ADDR + 2*(PMD_SIZE - 1)) - 1) & ~(PMD_SIZE - 1)))
7354 ++#else
7355 ++#define __KERNEL_TEXT_OFFSET 0
7356 ++#endif
7357 +
7358 + OUTPUT_FORMAT("elf32-i386", "elf32-i386", "elf32-i386")
7359 + OUTPUT_ARCH(i386)
7360 +@@ -22,81 +36,23 @@ ENTRY(phys_startup_32)
7361 + jiffies = jiffies_64;
7362 +
7363 + PHDRS {
7364 +- text PT_LOAD FLAGS(5); /* R_E */
7365 +- data PT_LOAD FLAGS(7); /* RWE */
7366 +- note PT_NOTE FLAGS(0); /* ___ */
7367 ++ initdata PT_LOAD FLAGS(6); /* RW_ */
7368 ++ percpu PT_LOAD FLAGS(6); /* RW_ */
7369 ++ inittext PT_LOAD FLAGS(5); /* R_E */
7370 ++ text PT_LOAD FLAGS(5); /* R_E */
7371 ++ rodata PT_LOAD FLAGS(4); /* R__ */
7372 ++ data PT_LOAD FLAGS(6); /* RW_ */
7373 ++ note PT_NOTE FLAGS(0); /* ___ */
7374 + }
7375 + SECTIONS
7376 + {
7377 +- . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
7378 +- phys_startup_32 = startup_32 - LOAD_OFFSET;
7379 +-
7380 +- .text.head : AT(ADDR(.text.head) - LOAD_OFFSET) {
7381 +- _text = .; /* Text and read-only data */
7382 +- *(.text.head)
7383 +- } :text = 0x9090
7384 +-
7385 +- /* read-only */
7386 +- .text : AT(ADDR(.text) - LOAD_OFFSET) {
7387 +- . = ALIGN(PAGE_SIZE); /* not really needed, already page aligned */
7388 +- *(.text.page_aligned)
7389 +- TEXT_TEXT
7390 +- SCHED_TEXT
7391 +- LOCK_TEXT
7392 +- KPROBES_TEXT
7393 +- *(.fixup)
7394 +- *(.gnu.warning)
7395 +- _etext = .; /* End of text section */
7396 +- } :text = 0x9090
7397 +-
7398 +- NOTES :text :note
7399 ++ . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
7400 +
7401 +- . = ALIGN(16); /* Exception table */
7402 +- __ex_table : AT(ADDR(__ex_table) - LOAD_OFFSET) {
7403 +- __start___ex_table = .;
7404 +- *(__ex_table)
7405 +- __stop___ex_table = .;
7406 +- } :text = 0x9090
7407 +-
7408 +- RODATA
7409 +-
7410 +- /* writeable */
7411 +- . = ALIGN(PAGE_SIZE);
7412 +- .data : AT(ADDR(.data) - LOAD_OFFSET) { /* Data */
7413 +- DATA_DATA
7414 +- CONSTRUCTORS
7415 +- } :data
7416 +-
7417 +- . = ALIGN(PAGE_SIZE);
7418 +- .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
7419 +- __nosave_begin = .;
7420 +- *(.data.nosave)
7421 +- . = ALIGN(PAGE_SIZE);
7422 +- __nosave_end = .;
7423 +- }
7424 +-
7425 +- . = ALIGN(PAGE_SIZE);
7426 +- .data.page_aligned : AT(ADDR(.data.page_aligned) - LOAD_OFFSET) {
7427 +- *(.data.page_aligned)
7428 +- *(.data.idt)
7429 +- }
7430 +-
7431 +- . = ALIGN(32);
7432 +- .data.cacheline_aligned : AT(ADDR(.data.cacheline_aligned) - LOAD_OFFSET) {
7433 +- *(.data.cacheline_aligned)
7434 +- }
7435 +-
7436 +- /* rarely changed data like cpu maps */
7437 +- . = ALIGN(32);
7438 +- .data.read_mostly : AT(ADDR(.data.read_mostly) - LOAD_OFFSET) {
7439 +- *(.data.read_mostly)
7440 +- _edata = .; /* End of data section */
7441 +- }
7442 +-
7443 +- . = ALIGN(THREAD_SIZE); /* init_task */
7444 +- .data.init_task : AT(ADDR(.data.init_task) - LOAD_OFFSET) {
7445 +- *(.data.init_task)
7446 +- }
7447 ++ .text.startup : AT(ADDR(.text.startup) - LOAD_OFFSET) {
7448 ++ __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET;
7449 ++ phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
7450 ++ *(.text.startup)
7451 ++ } :initdata
7452 +
7453 + /* might get freed after init */
7454 + . = ALIGN(PAGE_SIZE);
7455 +@@ -114,14 +70,8 @@ SECTIONS
7456 + . = ALIGN(PAGE_SIZE);
7457 +
7458 + /* will be freed after init */
7459 +- . = ALIGN(PAGE_SIZE); /* Init code and data */
7460 +- .init.text : AT(ADDR(.init.text) - LOAD_OFFSET) {
7461 +- __init_begin = .;
7462 +- _sinittext = .;
7463 +- INIT_TEXT
7464 +- _einittext = .;
7465 +- }
7466 + .init.data : AT(ADDR(.init.data) - LOAD_OFFSET) {
7467 ++ __init_begin = .;
7468 + INIT_DATA
7469 + }
7470 + . = ALIGN(16);
7471 +@@ -161,11 +111,6 @@ SECTIONS
7472 + *(.parainstructions)
7473 + __parainstructions_end = .;
7474 + }
7475 +- /* .exit.text is discard at runtime, not link time, to deal with references
7476 +- from .altinstructions and .eh_frame */
7477 +- .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
7478 +- EXIT_TEXT
7479 +- }
7480 + .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
7481 + EXIT_DATA
7482 + }
7483 +@@ -178,17 +123,136 @@ SECTIONS
7484 + }
7485 + #endif
7486 + . = ALIGN(PAGE_SIZE);
7487 +- .data.percpu : AT(ADDR(.data.percpu) - LOAD_OFFSET) {
7488 +- __per_cpu_start = .;
7489 ++ per_cpu_start = .;
7490 ++ .data.percpu (0) : AT(ADDR(.data.percpu) - LOAD_OFFSET + per_cpu_start) {
7491 ++ __per_cpu_start = . + per_cpu_start;
7492 ++ LONG(0)
7493 + *(.data.percpu)
7494 + *(.data.percpu.shared_aligned)
7495 +- __per_cpu_end = .;
7496 +- }
7497 ++ __per_cpu_end = . + per_cpu_start;
7498 ++ } :percpu
7499 ++ . += per_cpu_start;
7500 + . = ALIGN(PAGE_SIZE);
7501 + /* freed after init ends here */
7502 +
7503 ++ . = ALIGN(PAGE_SIZE); /* Init code and data */
7504 ++ .init.text (. - __KERNEL_TEXT_OFFSET) : AT(ADDR(.init.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
7505 ++ _sinittext = .;
7506 ++ INIT_TEXT
7507 ++ _einittext = .;
7508 ++ } :inittext
7509 ++
7510 ++ /* .exit.text is discard at runtime, not link time, to deal with references
7511 ++ from .altinstructions and .eh_frame */
7512 ++ .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
7513 ++ EXIT_TEXT
7514 ++ }
7515 ++
7516 ++ .filler : AT(ADDR(.filler) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
7517 ++ BYTE(0)
7518 ++ . = ALIGN(2*PMD_SIZE) - 1;
7519 ++ }
7520 ++
7521 ++ /* freed after init ends here */
7522 ++
7523 ++ .text.head : AT(ADDR(.text.head) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
7524 ++ __init_end = . + __KERNEL_TEXT_OFFSET;
7525 ++ KERNEL_TEXT_OFFSET = . + __KERNEL_TEXT_OFFSET;
7526 ++ _text = .; /* Text and read-only data */
7527 ++ *(.text.head)
7528 ++ } :text = 0x9090
7529 ++
7530 ++ /* read-only */
7531 ++ .text : AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
7532 ++ . = ALIGN(PAGE_SIZE); /* not really needed, already page aligned */
7533 ++ *(.text.page_aligned)
7534 ++ TEXT_TEXT
7535 ++ SCHED_TEXT
7536 ++ LOCK_TEXT
7537 ++ KPROBES_TEXT
7538 ++ *(.fixup)
7539 ++ *(.gnu.warning)
7540 ++ _etext = .; /* End of text section */
7541 ++ } :text = 0x9090
7542 ++
7543 ++ . += __KERNEL_TEXT_OFFSET;
7544 ++
7545 ++ . = ALIGN(4096); /* Exception table */
7546 ++ __ex_table : AT(ADDR(__ex_table) - LOAD_OFFSET) {
7547 ++ __start___ex_table = .;
7548 ++ *(__ex_table)
7549 ++ __stop___ex_table = .;
7550 ++ } :rodata
7551 ++
7552 ++ NOTES :rodata :note
7553 ++
7554 ++ RO_DATA(PAGE_SIZE)
7555 ++
7556 ++ . = ALIGN(PAGE_SIZE);
7557 ++ .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
7558 ++ *(.idt)
7559 ++ . = ALIGN(PAGE_SIZE);
7560 ++ *(.empty_zero_page)
7561 ++ *(.swapper_pg_pmd)
7562 ++ *(.swapper_pg_dir)
7563 ++ }
7564 ++
7565 ++#ifdef CONFIG_PAX_KERNEXEC
7566 ++
7567 ++#ifdef CONFIG_MODULES
7568 ++ . = ALIGN(PAGE_SIZE);
7569 ++ .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
7570 ++ MODULES_VADDR = .;
7571 ++ BYTE(0)
7572 ++ . += (6 * 1024 * 1024);
7573 ++ . = ALIGN( PMD_SIZE) - 1;
7574 ++ MODULES_END = .;
7575 ++ }
7576 ++#else
7577 ++ . = ALIGN(PMD_SIZE) - 1;
7578 ++#endif
7579 ++
7580 ++#endif
7581 ++
7582 ++ /* writeable */
7583 ++ . = ALIGN(PAGE_SIZE);
7584 ++ .data : AT(ADDR(.data) - LOAD_OFFSET) { /* Data */
7585 ++ _data = .;
7586 ++ DATA_DATA
7587 ++ CONSTRUCTORS
7588 ++ } :data
7589 ++
7590 ++ . = ALIGN(PAGE_SIZE);
7591 ++ .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
7592 ++ __nosave_begin = .;
7593 ++ *(.data.nosave)
7594 ++ . = ALIGN(PAGE_SIZE);
7595 ++ __nosave_end = .;
7596 ++ }
7597 ++
7598 ++ . = ALIGN(PAGE_SIZE);
7599 ++ .data.page_aligned : AT(ADDR(.data.page_aligned) - LOAD_OFFSET) {
7600 ++ *(.data.page_aligned)
7601 ++ }
7602 ++
7603 ++ . = ALIGN(32);
7604 ++ .data.cacheline_aligned : AT(ADDR(.data.cacheline_aligned) - LOAD_OFFSET) {
7605 ++ *(.data.cacheline_aligned)
7606 ++ }
7607 ++
7608 ++ /* rarely changed data like cpu maps */
7609 ++ . = ALIGN(32);
7610 ++ .data.read_mostly : AT(ADDR(.data.read_mostly) - LOAD_OFFSET) {
7611 ++ *(.data.read_mostly)
7612 ++ _edata = .; /* End of data section */
7613 ++ }
7614 ++
7615 ++ . = ALIGN(THREAD_SIZE); /* init_task */
7616 ++ .data.init_task : AT(ADDR(.data.init_task) - LOAD_OFFSET) {
7617 ++ *(.data.init_task)
7618 ++ }
7619 ++
7620 + .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
7621 +- __init_end = .;
7622 + __bss_start = .; /* BSS */
7623 + *(.bss.page_aligned)
7624 + *(.bss)
7625 +diff -urNp linux-2.6.27.10/arch/x86/kernel/vmlinux_64.lds.S linux-2.6.27.10/arch/x86/kernel/vmlinux_64.lds.S
7626 +--- linux-2.6.27.10/arch/x86/kernel/vmlinux_64.lds.S 2008-11-07 12:55:34.000000000 -0500
7627 ++++ linux-2.6.27.10/arch/x86/kernel/vmlinux_64.lds.S 2008-11-18 03:38:44.000000000 -0500
7628 +@@ -16,7 +16,7 @@ jiffies_64 = jiffies;
7629 + _proxy_pda = 1;
7630 + PHDRS {
7631 + text PT_LOAD FLAGS(5); /* R_E */
7632 +- data PT_LOAD FLAGS(7); /* RWE */
7633 ++ data PT_LOAD FLAGS(6); /* RW_ */
7634 + user PT_LOAD FLAGS(7); /* RWE */
7635 + data.init PT_LOAD FLAGS(7); /* RWE */
7636 + note PT_NOTE FLAGS(0); /* ___ */
7637 +@@ -49,17 +49,20 @@ SECTIONS
7638 + __stop___ex_table = .;
7639 + } :text = 0x9090
7640 +
7641 +- RODATA
7642 ++ RO_DATA(PAGE_SIZE)
7643 +
7644 ++#ifdef CONFIG_PAX_KERNEXEC
7645 ++ . = ALIGN(2*1024*1024); /* Align data segment to PMD size boundary */
7646 ++#else
7647 + . = ALIGN(PAGE_SIZE); /* Align data segment to page size boundary */
7648 ++#endif
7649 + /* Data */
7650 ++ _data = .;
7651 + .data : AT(ADDR(.data) - LOAD_OFFSET) {
7652 + DATA_DATA
7653 + CONSTRUCTORS
7654 + } :data
7655 +
7656 +- _edata = .; /* End of data section */
7657 +-
7658 + . = ALIGN(PAGE_SIZE);
7659 + . = ALIGN(CONFIG_X86_L1_CACHE_BYTES);
7660 + .data.cacheline_aligned : AT(ADDR(.data.cacheline_aligned) - LOAD_OFFSET) {
7661 +@@ -70,9 +73,27 @@ SECTIONS
7662 + *(.data.read_mostly)
7663 + }
7664 +
7665 ++ . = ALIGN(THREAD_SIZE); /* init_task */
7666 ++ .data.init_task : AT(ADDR(.data.init_task) - LOAD_OFFSET) {
7667 ++ *(.data.init_task)
7668 ++ }
7669 ++
7670 ++ . = ALIGN(PAGE_SIZE);
7671 ++ .data.page_aligned : AT(ADDR(.data.page_aligned) - LOAD_OFFSET) {
7672 ++ *(.data.page_aligned)
7673 ++ }
7674 ++
7675 ++ . = ALIGN(PAGE_SIZE);
7676 ++ __nosave_begin = .;
7677 ++ .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) { *(.data.nosave) }
7678 ++ . = ALIGN(PAGE_SIZE);
7679 ++ __nosave_end = .;
7680 ++
7681 ++ _edata = .; /* End of data section */
7682 ++
7683 + #define VSYSCALL_ADDR (-10*1024*1024)
7684 +-#define VSYSCALL_PHYS_ADDR ((LOADADDR(.data.read_mostly) + SIZEOF(.data.read_mostly) + 4095) & ~(4095))
7685 +-#define VSYSCALL_VIRT_ADDR ((ADDR(.data.read_mostly) + SIZEOF(.data.read_mostly) + 4095) & ~(4095))
7686 ++#define VSYSCALL_PHYS_ADDR ((LOADADDR(.data_nosave) + SIZEOF(.data_nosave) + 4095) & ~(4095))
7687 ++#define VSYSCALL_VIRT_ADDR ((ADDR(.data_nosave) + SIZEOF(.data_nosave) + 4095) & ~(4095))
7688 +
7689 + #define VLOAD_OFFSET (VSYSCALL_ADDR - VSYSCALL_PHYS_ADDR)
7690 + #define VLOAD(x) (ADDR(x) - VLOAD_OFFSET)
7691 +@@ -120,23 +141,13 @@ SECTIONS
7692 + #undef VVIRT_OFFSET
7693 + #undef VVIRT
7694 +
7695 +- . = ALIGN(THREAD_SIZE); /* init_task */
7696 +- .data.init_task : AT(ADDR(.data.init_task) - LOAD_OFFSET) {
7697 +- *(.data.init_task)
7698 +- }:data.init
7699 +-
7700 +- . = ALIGN(PAGE_SIZE);
7701 +- .data.page_aligned : AT(ADDR(.data.page_aligned) - LOAD_OFFSET) {
7702 +- *(.data.page_aligned)
7703 +- }
7704 +-
7705 + /* might get freed after init */
7706 + . = ALIGN(PAGE_SIZE);
7707 + __smp_alt_begin = .;
7708 + __smp_locks = .;
7709 + .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
7710 + *(.smp_locks)
7711 +- }
7712 ++ } :data.init
7713 + __smp_locks_end = .;
7714 + . = ALIGN(PAGE_SIZE);
7715 + __smp_alt_end = .;
7716 +@@ -213,16 +224,11 @@ SECTIONS
7717 + . = ALIGN(PAGE_SIZE);
7718 + __init_end = .;
7719 +
7720 +- . = ALIGN(PAGE_SIZE);
7721 +- __nosave_begin = .;
7722 +- .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) { *(.data.nosave) }
7723 +- . = ALIGN(PAGE_SIZE);
7724 +- __nosave_end = .;
7725 +-
7726 + __bss_start = .; /* BSS */
7727 + .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
7728 + *(.bss.page_aligned)
7729 + *(.bss)
7730 ++ . = ALIGN(2*1024*1024);
7731 + }
7732 + __bss_stop = .;
7733 +
7734 +diff -urNp linux-2.6.27.10/arch/x86/kernel/vsyscall_64.c linux-2.6.27.10/arch/x86/kernel/vsyscall_64.c
7735 +--- linux-2.6.27.10/arch/x86/kernel/vsyscall_64.c 2008-11-07 12:55:34.000000000 -0500
7736 ++++ linux-2.6.27.10/arch/x86/kernel/vsyscall_64.c 2008-11-18 03:38:44.000000000 -0500
7737 +@@ -236,13 +236,13 @@ static ctl_table kernel_table2[] = {
7738 + .data = &vsyscall_gtod_data.sysctl_enabled, .maxlen = sizeof(int),
7739 + .mode = 0644,
7740 + .proc_handler = vsyscall_sysctl_change },
7741 +- {}
7742 ++ { 0, NULL, NULL, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL }
7743 + };
7744 +
7745 + static ctl_table kernel_root_table2[] = {
7746 + { .ctl_name = CTL_KERN, .procname = "kernel", .mode = 0555,
7747 + .child = kernel_table2 },
7748 +- {}
7749 ++ { 0, NULL, NULL, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL }
7750 + };
7751 + #endif
7752 +
7753 +diff -urNp linux-2.6.27.10/arch/x86/kvm/svm.c linux-2.6.27.10/arch/x86/kvm/svm.c
7754 +--- linux-2.6.27.10/arch/x86/kvm/svm.c 2008-11-07 12:55:34.000000000 -0500
7755 ++++ linux-2.6.27.10/arch/x86/kvm/svm.c 2008-11-18 03:38:44.000000000 -0500
7756 +@@ -1515,7 +1515,19 @@ static void reload_tss(struct kvm_vcpu *
7757 + int cpu = raw_smp_processor_id();
7758 +
7759 + struct svm_cpu_data *svm_data = per_cpu(svm_data, cpu);
7760 ++
7761 ++#ifdef CONFIG_PAX_KERNEXEC
7762 ++ unsigned long cr0;
7763 ++
7764 ++ pax_open_kernel(cr0);
7765 ++#endif
7766 ++
7767 + svm_data->tss_desc->type = 9; /* available 32/64-bit TSS */
7768 ++
7769 ++#ifdef CONFIG_PAX_KERNEXEC
7770 ++ pax_close_kernel(cr0);
7771 ++#endif
7772 ++
7773 + load_TR_desc();
7774 + }
7775 +
7776 +diff -urNp linux-2.6.27.10/arch/x86/kvm/vmx.c linux-2.6.27.10/arch/x86/kvm/vmx.c
7777 +--- linux-2.6.27.10/arch/x86/kvm/vmx.c 2008-11-07 12:55:34.000000000 -0500
7778 ++++ linux-2.6.27.10/arch/x86/kvm/vmx.c 2008-11-18 03:38:44.000000000 -0500
7779 +@@ -115,7 +115,7 @@ static struct vmcs_config {
7780 + u32 vmentry_ctrl;
7781 + } vmcs_config;
7782 +
7783 +-struct vmx_capability {
7784 ++static struct vmx_capability {
7785 + u32 ept;
7786 + u32 vpid;
7787 + } vmx_capability;
7788 +@@ -484,9 +484,23 @@ static void reload_tss(void)
7789 + struct descriptor_table gdt;
7790 + struct desc_struct *descs;
7791 +
7792 ++#ifdef CONFIG_PAX_KERNEXEC
7793 ++ unsigned long cr0;
7794 ++#endif
7795 ++
7796 + kvm_get_gdt(&gdt);
7797 + descs = (void *)gdt.base;
7798 ++
7799 ++#ifdef CONFIG_PAX_KERNEXEC
7800 ++ pax_open_kernel(cr0);
7801 ++#endif
7802 ++
7803 + descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
7804 ++
7805 ++#ifdef CONFIG_PAX_KERNEXEC
7806 ++ pax_close_kernel(cr0);
7807 ++#endif
7808 ++
7809 + load_TR_desc();
7810 + }
7811 +
7812 +@@ -3069,7 +3083,7 @@ static void vmx_vcpu_run(struct kvm_vcpu
7813 + (vmcs_read32(GUEST_INTERRUPTIBILITY_INFO) &
7814 + (GUEST_INTR_STATE_STI | GUEST_INTR_STATE_MOV_SS)) == 0;
7815 +
7816 +- asm("mov %0, %%ds; mov %0, %%es" : : "r"(__USER_DS));
7817 ++ asm("mov %0, %%ds; mov %0, %%es" : : "r"(__KERNEL_DS));
7818 + vmx->launched = 1;
7819 +
7820 + intr_info = vmcs_read32(VM_EXIT_INTR_INFO);
7821 +diff -urNp linux-2.6.27.10/arch/x86/kvm/x86.c linux-2.6.27.10/arch/x86/kvm/x86.c
7822 +--- linux-2.6.27.10/arch/x86/kvm/x86.c 2008-11-07 12:55:34.000000000 -0500
7823 ++++ linux-2.6.27.10/arch/x86/kvm/x86.c 2008-11-18 03:38:44.000000000 -0500
7824 +@@ -63,35 +63,35 @@ static int kvm_dev_ioctl_get_supported_c
7825 + struct kvm_x86_ops *kvm_x86_ops;
7826 +
7827 + struct kvm_stats_debugfs_item debugfs_entries[] = {
7828 +- { "pf_fixed", VCPU_STAT(pf_fixed) },
7829 +- { "pf_guest", VCPU_STAT(pf_guest) },
7830 +- { "tlb_flush", VCPU_STAT(tlb_flush) },
7831 +- { "invlpg", VCPU_STAT(invlpg) },
7832 +- { "exits", VCPU_STAT(exits) },
7833 +- { "io_exits", VCPU_STAT(io_exits) },
7834 +- { "mmio_exits", VCPU_STAT(mmio_exits) },
7835 +- { "signal_exits", VCPU_STAT(signal_exits) },
7836 +- { "irq_window", VCPU_STAT(irq_window_exits) },
7837 +- { "nmi_window", VCPU_STAT(nmi_window_exits) },
7838 +- { "halt_exits", VCPU_STAT(halt_exits) },
7839 +- { "halt_wakeup", VCPU_STAT(halt_wakeup) },
7840 +- { "hypercalls", VCPU_STAT(hypercalls) },
7841 +- { "request_irq", VCPU_STAT(request_irq_exits) },
7842 +- { "irq_exits", VCPU_STAT(irq_exits) },
7843 +- { "host_state_reload", VCPU_STAT(host_state_reload) },
7844 +- { "efer_reload", VCPU_STAT(efer_reload) },
7845 +- { "fpu_reload", VCPU_STAT(fpu_reload) },
7846 +- { "insn_emulation", VCPU_STAT(insn_emulation) },
7847 +- { "insn_emulation_fail", VCPU_STAT(insn_emulation_fail) },
7848 +- { "mmu_shadow_zapped", VM_STAT(mmu_shadow_zapped) },
7849 +- { "mmu_pte_write", VM_STAT(mmu_pte_write) },
7850 +- { "mmu_pte_updated", VM_STAT(mmu_pte_updated) },
7851 +- { "mmu_pde_zapped", VM_STAT(mmu_pde_zapped) },
7852 +- { "mmu_flooded", VM_STAT(mmu_flooded) },
7853 +- { "mmu_recycled", VM_STAT(mmu_recycled) },
7854 +- { "mmu_cache_miss", VM_STAT(mmu_cache_miss) },
7855 +- { "remote_tlb_flush", VM_STAT(remote_tlb_flush) },
7856 +- { "largepages", VM_STAT(lpages) },
7857 ++ { "pf_fixed", VCPU_STAT(pf_fixed), NULL },
7858 ++ { "pf_guest", VCPU_STAT(pf_guest), NULL },
7859 ++ { "tlb_flush", VCPU_STAT(tlb_flush), NULL },
7860 ++ { "invlpg", VCPU_STAT(invlpg), NULL },
7861 ++ { "exits", VCPU_STAT(exits), NULL },
7862 ++ { "io_exits", VCPU_STAT(io_exits), NULL },
7863 ++ { "mmio_exits", VCPU_STAT(mmio_exits), NULL },
7864 ++ { "signal_exits", VCPU_STAT(signal_exits), NULL },
7865 ++ { "irq_window", VCPU_STAT(irq_window_exits), NULL },
7866 ++ { "nmi_window", VCPU_STAT(nmi_window_exits), NULL },
7867 ++ { "halt_exits", VCPU_STAT(halt_exits), NULL },
7868 ++ { "halt_wakeup", VCPU_STAT(halt_wakeup), NULL },
7869 ++ { "hypercalls", VCPU_STAT(hypercalls), NULL },
7870 ++ { "request_irq", VCPU_STAT(request_irq_exits), NULL },
7871 ++ { "irq_exits", VCPU_STAT(irq_exits), NULL },
7872 ++ { "host_state_reload", VCPU_STAT(host_state_reload), NULL },
7873 ++ { "efer_reload", VCPU_STAT(efer_reload), NULL },
7874 ++ { "fpu_reload", VCPU_STAT(fpu_reload), NULL },
7875 ++ { "insn_emulation", VCPU_STAT(insn_emulation), NULL },
7876 ++ { "insn_emulation_fail", VCPU_STAT(insn_emulation_fail), NULL },
7877 ++ { "mmu_shadow_zapped", VM_STAT(mmu_shadow_zapped), NULL },
7878 ++ { "mmu_pte_write", VM_STAT(mmu_pte_write), NULL },
7879 ++ { "mmu_pte_updated", VM_STAT(mmu_pte_updated), NULL },
7880 ++ { "mmu_pde_zapped", VM_STAT(mmu_pde_zapped), NULL },
7881 ++ { "mmu_flooded", VM_STAT(mmu_flooded), NULL },
7882 ++ { "mmu_recycled", VM_STAT(mmu_recycled), NULL },
7883 ++ { "mmu_cache_miss", VM_STAT(mmu_cache_miss), NULL },
7884 ++ { "remote_tlb_flush", VM_STAT(remote_tlb_flush), NULL },
7885 ++ { "largepages", VM_STAT(lpages), NULL },
7886 + { NULL }
7887 + };
7888 +
7889 +@@ -1274,7 +1274,7 @@ static int kvm_vcpu_ioctl_set_lapic(stru
7890 + static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
7891 + struct kvm_interrupt *irq)
7892 + {
7893 +- if (irq->irq < 0 || irq->irq >= 256)
7894 ++ if (irq->irq >= 256)
7895 + return -EINVAL;
7896 + if (irqchip_in_kernel(vcpu->kvm))
7897 + return -ENXIO;
7898 +diff -urNp linux-2.6.27.10/arch/x86/lib/checksum_32.S linux-2.6.27.10/arch/x86/lib/checksum_32.S
7899 +--- linux-2.6.27.10/arch/x86/lib/checksum_32.S 2008-11-07 12:55:34.000000000 -0500
7900 ++++ linux-2.6.27.10/arch/x86/lib/checksum_32.S 2008-11-18 03:38:44.000000000 -0500
7901 +@@ -28,7 +28,8 @@
7902 + #include <linux/linkage.h>
7903 + #include <asm/dwarf2.h>
7904 + #include <asm/errno.h>
7905 +-
7906 ++#include <asm/segment.h>
7907 ++
7908 + /*
7909 + * computes a partial checksum, e.g. for TCP/UDP fragments
7910 + */
7911 +@@ -304,9 +305,22 @@ unsigned int csum_partial_copy_generic (
7912 +
7913 + #define ARGBASE 16
7914 + #define FP 12
7915 +-
7916 +-ENTRY(csum_partial_copy_generic)
7917 ++
7918 ++ENTRY(csum_partial_copy_generic_to_user)
7919 + CFI_STARTPROC
7920 ++ pushl $(__USER_DS)
7921 ++ CFI_ADJUST_CFA_OFFSET 4
7922 ++ popl %es
7923 ++ CFI_ADJUST_CFA_OFFSET -4
7924 ++ jmp csum_partial_copy_generic
7925 ++
7926 ++ENTRY(csum_partial_copy_generic_from_user)
7927 ++ pushl $(__USER_DS)
7928 ++ CFI_ADJUST_CFA_OFFSET 4
7929 ++ popl %ds
7930 ++ CFI_ADJUST_CFA_OFFSET -4
7931 ++
7932 ++ENTRY(csum_partial_copy_generic)
7933 + subl $4,%esp
7934 + CFI_ADJUST_CFA_OFFSET 4
7935 + pushl %edi
7936 +@@ -331,7 +345,7 @@ ENTRY(csum_partial_copy_generic)
7937 + jmp 4f
7938 + SRC(1: movw (%esi), %bx )
7939 + addl $2, %esi
7940 +-DST( movw %bx, (%edi) )
7941 ++DST( movw %bx, %es:(%edi) )
7942 + addl $2, %edi
7943 + addw %bx, %ax
7944 + adcl $0, %eax
7945 +@@ -343,30 +357,30 @@ DST( movw %bx, (%edi) )
7946 + SRC(1: movl (%esi), %ebx )
7947 + SRC( movl 4(%esi), %edx )
7948 + adcl %ebx, %eax
7949 +-DST( movl %ebx, (%edi) )
7950 ++DST( movl %ebx, %es:(%edi) )
7951 + adcl %edx, %eax
7952 +-DST( movl %edx, 4(%edi) )
7953 ++DST( movl %edx, %es:4(%edi) )
7954 +
7955 + SRC( movl 8(%esi), %ebx )
7956 + SRC( movl 12(%esi), %edx )
7957 + adcl %ebx, %eax
7958 +-DST( movl %ebx, 8(%edi) )
7959 ++DST( movl %ebx, %es:8(%edi) )
7960 + adcl %edx, %eax
7961 +-DST( movl %edx, 12(%edi) )
7962 ++DST( movl %edx, %es:12(%edi) )
7963 +
7964 + SRC( movl 16(%esi), %ebx )
7965 + SRC( movl 20(%esi), %edx )
7966 + adcl %ebx, %eax
7967 +-DST( movl %ebx, 16(%edi) )
7968 ++DST( movl %ebx, %es:16(%edi) )
7969 + adcl %edx, %eax
7970 +-DST( movl %edx, 20(%edi) )
7971 ++DST( movl %edx, %es:20(%edi) )
7972 +
7973 + SRC( movl 24(%esi), %ebx )
7974 + SRC( movl 28(%esi), %edx )
7975 + adcl %ebx, %eax
7976 +-DST( movl %ebx, 24(%edi) )
7977 ++DST( movl %ebx, %es:24(%edi) )
7978 + adcl %edx, %eax
7979 +-DST( movl %edx, 28(%edi) )
7980 ++DST( movl %edx, %es:28(%edi) )
7981 +
7982 + lea 32(%esi), %esi
7983 + lea 32(%edi), %edi
7984 +@@ -380,7 +394,7 @@ DST( movl %edx, 28(%edi) )
7985 + shrl $2, %edx # This clears CF
7986 + SRC(3: movl (%esi), %ebx )
7987 + adcl %ebx, %eax
7988 +-DST( movl %ebx, (%edi) )
7989 ++DST( movl %ebx, %es:(%edi) )
7990 + lea 4(%esi), %esi
7991 + lea 4(%edi), %edi
7992 + dec %edx
7993 +@@ -392,12 +406,12 @@ DST( movl %ebx, (%edi) )
7994 + jb 5f
7995 + SRC( movw (%esi), %cx )
7996 + leal 2(%esi), %esi
7997 +-DST( movw %cx, (%edi) )
7998 ++DST( movw %cx, %es:(%edi) )
7999 + leal 2(%edi), %edi
8000 + je 6f
8001 + shll $16,%ecx
8002 + SRC(5: movb (%esi), %cl )
8003 +-DST( movb %cl, (%edi) )
8004 ++DST( movb %cl, %es:(%edi) )
8005 + 6: addl %ecx, %eax
8006 + adcl $0, %eax
8007 + 7:
8008 +@@ -408,7 +422,7 @@ DST( movb %cl, (%edi) )
8009 +
8010 + 6001:
8011 + movl ARGBASE+20(%esp), %ebx # src_err_ptr
8012 +- movl $-EFAULT, (%ebx)
8013 ++ movl $-EFAULT, %ss:(%ebx)
8014 +
8015 + # zero the complete destination - computing the rest
8016 + # is too much work
8017 +@@ -421,11 +435,19 @@ DST( movb %cl, (%edi) )
8018 +
8019 + 6002:
8020 + movl ARGBASE+24(%esp), %ebx # dst_err_ptr
8021 +- movl $-EFAULT,(%ebx)
8022 ++ movl $-EFAULT,%ss:(%ebx)
8023 + jmp 5000b
8024 +
8025 + .previous
8026 +
8027 ++ pushl %ss
8028 ++ CFI_ADJUST_CFA_OFFSET 4
8029 ++ popl %ds
8030 ++ CFI_ADJUST_CFA_OFFSET -4
8031 ++ pushl %ss
8032 ++ CFI_ADJUST_CFA_OFFSET 4
8033 ++ popl %es
8034 ++ CFI_ADJUST_CFA_OFFSET -4
8035 + popl %ebx
8036 + CFI_ADJUST_CFA_OFFSET -4
8037 + CFI_RESTORE ebx
8038 +@@ -439,26 +461,41 @@ DST( movb %cl, (%edi) )
8039 + CFI_ADJUST_CFA_OFFSET -4
8040 + ret
8041 + CFI_ENDPROC
8042 +-ENDPROC(csum_partial_copy_generic)
8043 ++ENDPROC(csum_partial_copy_generic_to_user)
8044 +
8045 + #else
8046 +
8047 + /* Version for PentiumII/PPro */
8048 +
8049 + #define ROUND1(x) \
8050 ++ nop; nop; nop; \
8051 + SRC(movl x(%esi), %ebx ) ; \
8052 + addl %ebx, %eax ; \
8053 +- DST(movl %ebx, x(%edi) ) ;
8054 ++ DST(movl %ebx, %es:x(%edi)) ;
8055 +
8056 + #define ROUND(x) \
8057 ++ nop; nop; nop; \
8058 + SRC(movl x(%esi), %ebx ) ; \
8059 + adcl %ebx, %eax ; \
8060 +- DST(movl %ebx, x(%edi) ) ;
8061 ++ DST(movl %ebx, %es:x(%edi)) ;
8062 +
8063 + #define ARGBASE 12
8064 +-
8065 +-ENTRY(csum_partial_copy_generic)
8066 ++
8067 ++ENTRY(csum_partial_copy_generic_to_user)
8068 + CFI_STARTPROC
8069 ++ pushl $(__USER_DS)
8070 ++ CFI_ADJUST_CFA_OFFSET 4
8071 ++ popl %es
8072 ++ CFI_ADJUST_CFA_OFFSET -4
8073 ++ jmp csum_partial_copy_generic
8074 ++
8075 ++ENTRY(csum_partial_copy_generic_from_user)
8076 ++ pushl $(__USER_DS)
8077 ++ CFI_ADJUST_CFA_OFFSET 4
8078 ++ popl %ds
8079 ++ CFI_ADJUST_CFA_OFFSET -4
8080 ++
8081 ++ENTRY(csum_partial_copy_generic)
8082 + pushl %ebx
8083 + CFI_ADJUST_CFA_OFFSET 4
8084 + CFI_REL_OFFSET ebx, 0
8085 +@@ -482,7 +519,7 @@ ENTRY(csum_partial_copy_generic)
8086 + subl %ebx, %edi
8087 + lea -1(%esi),%edx
8088 + andl $-32,%edx
8089 +- lea 3f(%ebx,%ebx), %ebx
8090 ++ lea 3f(%ebx,%ebx,2), %ebx
8091 + testl %esi, %esi
8092 + jmp *%ebx
8093 + 1: addl $64,%esi
8094 +@@ -503,19 +540,19 @@ ENTRY(csum_partial_copy_generic)
8095 + jb 5f
8096 + SRC( movw (%esi), %dx )
8097 + leal 2(%esi), %esi
8098 +-DST( movw %dx, (%edi) )
8099 ++DST( movw %dx, %es:(%edi) )
8100 + leal 2(%edi), %edi
8101 + je 6f
8102 + shll $16,%edx
8103 + 5:
8104 + SRC( movb (%esi), %dl )
8105 +-DST( movb %dl, (%edi) )
8106 ++DST( movb %dl, %es:(%edi) )
8107 + 6: addl %edx, %eax
8108 + adcl $0, %eax
8109 + 7:
8110 + .section .fixup, "ax"
8111 + 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
8112 +- movl $-EFAULT, (%ebx)
8113 ++ movl $-EFAULT, %ss:(%ebx)
8114 + # zero the complete destination (computing the rest is too much work)
8115 + movl ARGBASE+8(%esp),%edi # dst
8116 + movl ARGBASE+12(%esp),%ecx # len
8117 +@@ -523,10 +560,18 @@ DST( movb %dl, (%edi) )
8118 + rep; stosb
8119 + jmp 7b
8120 + 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
8121 +- movl $-EFAULT, (%ebx)
8122 ++ movl $-EFAULT, %ss:(%ebx)
8123 + jmp 7b
8124 + .previous
8125 +
8126 ++ pushl %ss
8127 ++ CFI_ADJUST_CFA_OFFSET 4
8128 ++ popl %ds
8129 ++ CFI_ADJUST_CFA_OFFSET -4
8130 ++ pushl %ss
8131 ++ CFI_ADJUST_CFA_OFFSET 4
8132 ++ popl %es
8133 ++ CFI_ADJUST_CFA_OFFSET -4
8134 + popl %esi
8135 + CFI_ADJUST_CFA_OFFSET -4
8136 + CFI_RESTORE esi
8137 +@@ -538,7 +583,7 @@ DST( movb %dl, (%edi) )
8138 + CFI_RESTORE ebx
8139 + ret
8140 + CFI_ENDPROC
8141 +-ENDPROC(csum_partial_copy_generic)
8142 ++ENDPROC(csum_partial_copy_generic_to_user)
8143 +
8144 + #undef ROUND
8145 + #undef ROUND1
8146 +diff -urNp linux-2.6.27.10/arch/x86/lib/clear_page_64.S linux-2.6.27.10/arch/x86/lib/clear_page_64.S
8147 +--- linux-2.6.27.10/arch/x86/lib/clear_page_64.S 2008-11-07 12:55:34.000000000 -0500
8148 ++++ linux-2.6.27.10/arch/x86/lib/clear_page_64.S 2008-11-18 03:38:44.000000000 -0500
8149 +@@ -44,7 +44,7 @@ ENDPROC(clear_page)
8150 +
8151 + #include <asm/cpufeature.h>
8152 +
8153 +- .section .altinstr_replacement,"ax"
8154 ++ .section .altinstr_replacement,"a"
8155 + 1: .byte 0xeb /* jmp <disp8> */
8156 + .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
8157 + 2:
8158 +diff -urNp linux-2.6.27.10/arch/x86/lib/copy_page_64.S linux-2.6.27.10/arch/x86/lib/copy_page_64.S
8159 +--- linux-2.6.27.10/arch/x86/lib/copy_page_64.S 2008-11-07 12:55:34.000000000 -0500
8160 ++++ linux-2.6.27.10/arch/x86/lib/copy_page_64.S 2008-11-18 03:38:44.000000000 -0500
8161 +@@ -104,7 +104,7 @@ ENDPROC(copy_page)
8162 +
8163 + #include <asm/cpufeature.h>
8164 +
8165 +- .section .altinstr_replacement,"ax"
8166 ++ .section .altinstr_replacement,"a"
8167 + 1: .byte 0xeb /* jmp <disp8> */
8168 + .byte (copy_page_c - copy_page) - (2f - 1b) /* offset */
8169 + 2:
8170 +diff -urNp linux-2.6.27.10/arch/x86/lib/copy_user_64.S linux-2.6.27.10/arch/x86/lib/copy_user_64.S
8171 +--- linux-2.6.27.10/arch/x86/lib/copy_user_64.S 2008-11-07 12:55:34.000000000 -0500
8172 ++++ linux-2.6.27.10/arch/x86/lib/copy_user_64.S 2008-11-18 03:38:44.000000000 -0500
8173 +@@ -21,7 +21,7 @@
8174 + .byte 0xe9 /* 32bit jump */
8175 + .long \orig-1f /* by default jump to orig */
8176 + 1:
8177 +- .section .altinstr_replacement,"ax"
8178 ++ .section .altinstr_replacement,"a"
8179 + 2: .byte 0xe9 /* near jump with 32bit immediate */
8180 + .long \alt-1b /* offset */ /* or alternatively to alt */
8181 + .previous
8182 +@@ -106,6 +106,8 @@ ENDPROC(__copy_from_user_inatomic)
8183 + ENTRY(bad_from_user)
8184 + bad_from_user:
8185 + CFI_STARTPROC
8186 ++ testl %edx,%edx
8187 ++ js bad_to_user
8188 + movl %edx,%ecx
8189 + xorl %eax,%eax
8190 + rep
8191 +diff -urNp linux-2.6.27.10/arch/x86/lib/getuser.S linux-2.6.27.10/arch/x86/lib/getuser.S
8192 +--- linux-2.6.27.10/arch/x86/lib/getuser.S 2008-11-07 12:55:34.000000000 -0500
8193 ++++ linux-2.6.27.10/arch/x86/lib/getuser.S 2008-11-18 03:38:44.000000000 -0500
8194 +@@ -33,6 +33,7 @@
8195 + #include <asm/asm-offsets.h>
8196 + #include <asm/thread_info.h>
8197 + #include <asm/asm.h>
8198 ++#include <asm/segment.h>
8199 +
8200 + .text
8201 + ENTRY(__get_user_1)
8202 +@@ -40,7 +41,19 @@ ENTRY(__get_user_1)
8203 + GET_THREAD_INFO(%_ASM_DX)
8204 + cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
8205 + jae bad_get_user
8206 ++
8207 ++#ifdef CONFIG_X86_32
8208 ++ pushl $(__USER_DS)
8209 ++ popl %ds
8210 ++#endif
8211 ++
8212 + 1: movzb (%_ASM_AX),%edx
8213 ++
8214 ++#ifdef CONFIG_X86_32
8215 ++ pushl %ss
8216 ++ pop %ds
8217 ++#endif
8218 ++
8219 + xor %eax,%eax
8220 + ret
8221 + CFI_ENDPROC
8222 +@@ -53,7 +66,19 @@ ENTRY(__get_user_2)
8223 + GET_THREAD_INFO(%_ASM_DX)
8224 + cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
8225 + jae bad_get_user
8226 ++
8227 ++#ifdef CONFIG_X86_32
8228 ++ pushl $(__USER_DS)
8229 ++ popl %ds
8230 ++#endif
8231 ++
8232 + 2: movzwl -1(%_ASM_AX),%edx
8233 ++
8234 ++#ifdef CONFIG_X86_32
8235 ++ pushl %ss
8236 ++ pop %ds
8237 ++#endif
8238 ++
8239 + xor %eax,%eax
8240 + ret
8241 + CFI_ENDPROC
8242 +@@ -66,7 +91,19 @@ ENTRY(__get_user_4)
8243 + GET_THREAD_INFO(%_ASM_DX)
8244 + cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
8245 + jae bad_get_user
8246 ++
8247 ++#ifdef CONFIG_X86_32
8248 ++ pushl $(__USER_DS)
8249 ++ popl %ds
8250 ++#endif
8251 ++
8252 + 3: mov -3(%_ASM_AX),%edx
8253 ++
8254 ++#ifdef CONFIG_X86_32
8255 ++ pushl %ss
8256 ++ pop %ds
8257 ++#endif
8258 ++
8259 + xor %eax,%eax
8260 + ret
8261 + CFI_ENDPROC
8262 +@@ -89,6 +126,12 @@ ENDPROC(__get_user_8)
8263 +
8264 + bad_get_user:
8265 + CFI_STARTPROC
8266 ++
8267 ++#ifdef CONFIG_X86_32
8268 ++ pushl %ss
8269 ++ pop %ds
8270 ++#endif
8271 ++
8272 + xor %edx,%edx
8273 + mov $(-EFAULT),%_ASM_AX
8274 + ret
8275 +diff -urNp linux-2.6.27.10/arch/x86/lib/memcpy_64.S linux-2.6.27.10/arch/x86/lib/memcpy_64.S
8276 +--- linux-2.6.27.10/arch/x86/lib/memcpy_64.S 2008-11-07 12:55:34.000000000 -0500
8277 ++++ linux-2.6.27.10/arch/x86/lib/memcpy_64.S 2008-11-18 03:38:44.000000000 -0500
8278 +@@ -114,7 +114,7 @@ ENDPROC(__memcpy)
8279 + /* Some CPUs run faster using the string copy instructions.
8280 + It is also a lot simpler. Use this when possible */
8281 +
8282 +- .section .altinstr_replacement,"ax"
8283 ++ .section .altinstr_replacement,"a"
8284 + 1: .byte 0xeb /* jmp <disp8> */
8285 + .byte (memcpy_c - memcpy) - (2f - 1b) /* offset */
8286 + 2:
8287 +diff -urNp linux-2.6.27.10/arch/x86/lib/memset_64.S linux-2.6.27.10/arch/x86/lib/memset_64.S
8288 +--- linux-2.6.27.10/arch/x86/lib/memset_64.S 2008-11-07 12:55:34.000000000 -0500
8289 ++++ linux-2.6.27.10/arch/x86/lib/memset_64.S 2008-11-18 03:38:44.000000000 -0500
8290 +@@ -118,7 +118,7 @@ ENDPROC(__memset)
8291 +
8292 + #include <asm/cpufeature.h>
8293 +
8294 +- .section .altinstr_replacement,"ax"
8295 ++ .section .altinstr_replacement,"a"
8296 + 1: .byte 0xeb /* jmp <disp8> */
8297 + .byte (memset_c - memset) - (2f - 1b) /* offset */
8298 + 2:
8299 +diff -urNp linux-2.6.27.10/arch/x86/lib/mmx_32.c linux-2.6.27.10/arch/x86/lib/mmx_32.c
8300 +--- linux-2.6.27.10/arch/x86/lib/mmx_32.c 2008-11-07 12:55:34.000000000 -0500
8301 ++++ linux-2.6.27.10/arch/x86/lib/mmx_32.c 2008-11-18 03:38:44.000000000 -0500
8302 +@@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *
8303 + {
8304 + void *p;
8305 + int i;
8306 ++ unsigned long cr0;
8307 +
8308 + if (unlikely(in_interrupt()))
8309 + return __memcpy(to, from, len);
8310 +@@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *
8311 + kernel_fpu_begin();
8312 +
8313 + __asm__ __volatile__ (
8314 +- "1: prefetch (%0)\n" /* This set is 28 bytes */
8315 +- " prefetch 64(%0)\n"
8316 +- " prefetch 128(%0)\n"
8317 +- " prefetch 192(%0)\n"
8318 +- " prefetch 256(%0)\n"
8319 ++ "1: prefetch (%1)\n" /* This set is 28 bytes */
8320 ++ " prefetch 64(%1)\n"
8321 ++ " prefetch 128(%1)\n"
8322 ++ " prefetch 192(%1)\n"
8323 ++ " prefetch 256(%1)\n"
8324 + "2: \n"
8325 + ".section .fixup, \"ax\"\n"
8326 +- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
8327 ++ "3: \n"
8328 ++
8329 ++#ifdef CONFIG_PAX_KERNEXEC
8330 ++ " movl %%cr0, %0\n"
8331 ++ " movl %0, %%eax\n"
8332 ++ " andl $0xFFFEFFFF, %%eax\n"
8333 ++ " movl %%eax, %%cr0\n"
8334 ++#endif
8335 ++
8336 ++ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
8337 ++
8338 ++#ifdef CONFIG_PAX_KERNEXEC
8339 ++ " movl %0, %%cr0\n"
8340 ++#endif
8341 ++
8342 + " jmp 2b\n"
8343 + ".previous\n"
8344 + _ASM_EXTABLE(1b, 3b)
8345 +- : : "r" (from));
8346 ++ : "=&r" (cr0) : "r" (from) : "ax");
8347 +
8348 + for ( ; i > 5; i--) {
8349 + __asm__ __volatile__ (
8350 +- "1: prefetch 320(%0)\n"
8351 +- "2: movq (%0), %%mm0\n"
8352 +- " movq 8(%0), %%mm1\n"
8353 +- " movq 16(%0), %%mm2\n"
8354 +- " movq 24(%0), %%mm3\n"
8355 +- " movq %%mm0, (%1)\n"
8356 +- " movq %%mm1, 8(%1)\n"
8357 +- " movq %%mm2, 16(%1)\n"
8358 +- " movq %%mm3, 24(%1)\n"
8359 +- " movq 32(%0), %%mm0\n"
8360 +- " movq 40(%0), %%mm1\n"
8361 +- " movq 48(%0), %%mm2\n"
8362 +- " movq 56(%0), %%mm3\n"
8363 +- " movq %%mm0, 32(%1)\n"
8364 +- " movq %%mm1, 40(%1)\n"
8365 +- " movq %%mm2, 48(%1)\n"
8366 +- " movq %%mm3, 56(%1)\n"
8367 ++ "1: prefetch 320(%1)\n"
8368 ++ "2: movq (%1), %%mm0\n"
8369 ++ " movq 8(%1), %%mm1\n"
8370 ++ " movq 16(%1), %%mm2\n"
8371 ++ " movq 24(%1), %%mm3\n"
8372 ++ " movq %%mm0, (%2)\n"
8373 ++ " movq %%mm1, 8(%2)\n"
8374 ++ " movq %%mm2, 16(%2)\n"
8375 ++ " movq %%mm3, 24(%2)\n"
8376 ++ " movq 32(%1), %%mm0\n"
8377 ++ " movq 40(%1), %%mm1\n"
8378 ++ " movq 48(%1), %%mm2\n"
8379 ++ " movq 56(%1), %%mm3\n"
8380 ++ " movq %%mm0, 32(%2)\n"
8381 ++ " movq %%mm1, 40(%2)\n"
8382 ++ " movq %%mm2, 48(%2)\n"
8383 ++ " movq %%mm3, 56(%2)\n"
8384 + ".section .fixup, \"ax\"\n"
8385 +- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
8386 ++ "3:\n"
8387 ++
8388 ++#ifdef CONFIG_PAX_KERNEXEC
8389 ++ " movl %%cr0, %0\n"
8390 ++ " movl %0, %%eax\n"
8391 ++ " andl $0xFFFEFFFF, %%eax\n"
8392 ++ " movl %%eax, %%cr0\n"
8393 ++#endif
8394 ++
8395 ++ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
8396 ++
8397 ++#ifdef CONFIG_PAX_KERNEXEC
8398 ++ " movl %0, %%cr0\n"
8399 ++#endif
8400 ++
8401 + " jmp 2b\n"
8402 + ".previous\n"
8403 + _ASM_EXTABLE(1b, 3b)
8404 +- : : "r" (from), "r" (to) : "memory");
8405 ++ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
8406 +
8407 + from += 64;
8408 + to += 64;
8409 +@@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
8410 + static void fast_copy_page(void *to, void *from)
8411 + {
8412 + int i;
8413 ++ unsigned long cr0;
8414 +
8415 + kernel_fpu_begin();
8416 +
8417 +@@ -166,42 +196,70 @@ static void fast_copy_page(void *to, voi
8418 + * but that is for later. -AV
8419 + */
8420 + __asm__ __volatile__(
8421 +- "1: prefetch (%0)\n"
8422 +- " prefetch 64(%0)\n"
8423 +- " prefetch 128(%0)\n"
8424 +- " prefetch 192(%0)\n"
8425 +- " prefetch 256(%0)\n"
8426 ++ "1: prefetch (%1)\n"
8427 ++ " prefetch 64(%1)\n"
8428 ++ " prefetch 128(%1)\n"
8429 ++ " prefetch 192(%1)\n"
8430 ++ " prefetch 256(%1)\n"
8431 + "2: \n"
8432 + ".section .fixup, \"ax\"\n"
8433 +- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
8434 ++ "3: \n"
8435 ++
8436 ++#ifdef CONFIG_PAX_KERNEXEC
8437 ++ " movl %%cr0, %0\n"
8438 ++ " movl %0, %%eax\n"
8439 ++ " andl $0xFFFEFFFF, %%eax\n"
8440 ++ " movl %%eax, %%cr0\n"
8441 ++#endif
8442 ++
8443 ++ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
8444 ++
8445 ++#ifdef CONFIG_PAX_KERNEXEC
8446 ++ " movl %0, %%cr0\n"
8447 ++#endif
8448 ++
8449 + " jmp 2b\n"
8450 + ".previous\n"
8451 +- _ASM_EXTABLE(1b, 3b) : : "r" (from));
8452 ++ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
8453 +
8454 + for (i = 0; i < (4096-320)/64; i++) {
8455 + __asm__ __volatile__ (
8456 +- "1: prefetch 320(%0)\n"
8457 +- "2: movq (%0), %%mm0\n"
8458 +- " movntq %%mm0, (%1)\n"
8459 +- " movq 8(%0), %%mm1\n"
8460 +- " movntq %%mm1, 8(%1)\n"
8461 +- " movq 16(%0), %%mm2\n"
8462 +- " movntq %%mm2, 16(%1)\n"
8463 +- " movq 24(%0), %%mm3\n"
8464 +- " movntq %%mm3, 24(%1)\n"
8465 +- " movq 32(%0), %%mm4\n"
8466 +- " movntq %%mm4, 32(%1)\n"
8467 +- " movq 40(%0), %%mm5\n"
8468 +- " movntq %%mm5, 40(%1)\n"
8469 +- " movq 48(%0), %%mm6\n"
8470 +- " movntq %%mm6, 48(%1)\n"
8471 +- " movq 56(%0), %%mm7\n"
8472 +- " movntq %%mm7, 56(%1)\n"
8473 ++ "1: prefetch 320(%1)\n"
8474 ++ "2: movq (%1), %%mm0\n"
8475 ++ " movntq %%mm0, (%2)\n"
8476 ++ " movq 8(%1), %%mm1\n"
8477 ++ " movntq %%mm1, 8(%2)\n"
8478 ++ " movq 16(%1), %%mm2\n"
8479 ++ " movntq %%mm2, 16(%2)\n"
8480 ++ " movq 24(%1), %%mm3\n"
8481 ++ " movntq %%mm3, 24(%2)\n"
8482 ++ " movq 32(%1), %%mm4\n"
8483 ++ " movntq %%mm4, 32(%2)\n"
8484 ++ " movq 40(%1), %%mm5\n"
8485 ++ " movntq %%mm5, 40(%2)\n"
8486 ++ " movq 48(%1), %%mm6\n"
8487 ++ " movntq %%mm6, 48(%2)\n"
8488 ++ " movq 56(%1), %%mm7\n"
8489 ++ " movntq %%mm7, 56(%2)\n"
8490 + ".section .fixup, \"ax\"\n"
8491 +- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
8492 ++ "3:\n"
8493 ++
8494 ++#ifdef CONFIG_PAX_KERNEXEC
8495 ++ " movl %%cr0, %0\n"
8496 ++ " movl %0, %%eax\n"
8497 ++ " andl $0xFFFEFFFF, %%eax\n"
8498 ++ " movl %%eax, %%cr0\n"
8499 ++#endif
8500 ++
8501 ++ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
8502 ++
8503 ++#ifdef CONFIG_PAX_KERNEXEC
8504 ++ " movl %0, %%cr0\n"
8505 ++#endif
8506 ++
8507 + " jmp 2b\n"
8508 + ".previous\n"
8509 +- _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
8510 ++ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
8511 +
8512 + from += 64;
8513 + to += 64;
8514 +@@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
8515 + static void fast_copy_page(void *to, void *from)
8516 + {
8517 + int i;
8518 ++ unsigned long cr0;
8519 +
8520 + kernel_fpu_begin();
8521 +
8522 + __asm__ __volatile__ (
8523 +- "1: prefetch (%0)\n"
8524 +- " prefetch 64(%0)\n"
8525 +- " prefetch 128(%0)\n"
8526 +- " prefetch 192(%0)\n"
8527 +- " prefetch 256(%0)\n"
8528 ++ "1: prefetch (%1)\n"
8529 ++ " prefetch 64(%1)\n"
8530 ++ " prefetch 128(%1)\n"
8531 ++ " prefetch 192(%1)\n"
8532 ++ " prefetch 256(%1)\n"
8533 + "2: \n"
8534 + ".section .fixup, \"ax\"\n"
8535 +- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
8536 ++ "3: \n"
8537 ++
8538 ++#ifdef CONFIG_PAX_KERNEXEC
8539 ++ " movl %%cr0, %0\n"
8540 ++ " movl %0, %%eax\n"
8541 ++ " andl $0xFFFEFFFF, %%eax\n"
8542 ++ " movl %%eax, %%cr0\n"
8543 ++#endif
8544 ++
8545 ++ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
8546 ++
8547 ++#ifdef CONFIG_PAX_KERNEXEC
8548 ++ " movl %0, %%cr0\n"
8549 ++#endif
8550 ++
8551 + " jmp 2b\n"
8552 + ".previous\n"
8553 +- _ASM_EXTABLE(1b, 3b) : : "r" (from));
8554 ++ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
8555 +
8556 + for (i = 0; i < 4096/64; i++) {
8557 + __asm__ __volatile__ (
8558 +- "1: prefetch 320(%0)\n"
8559 +- "2: movq (%0), %%mm0\n"
8560 +- " movq 8(%0), %%mm1\n"
8561 +- " movq 16(%0), %%mm2\n"
8562 +- " movq 24(%0), %%mm3\n"
8563 +- " movq %%mm0, (%1)\n"
8564 +- " movq %%mm1, 8(%1)\n"
8565 +- " movq %%mm2, 16(%1)\n"
8566 +- " movq %%mm3, 24(%1)\n"
8567 +- " movq 32(%0), %%mm0\n"
8568 +- " movq 40(%0), %%mm1\n"
8569 +- " movq 48(%0), %%mm2\n"
8570 +- " movq 56(%0), %%mm3\n"
8571 +- " movq %%mm0, 32(%1)\n"
8572 +- " movq %%mm1, 40(%1)\n"
8573 +- " movq %%mm2, 48(%1)\n"
8574 +- " movq %%mm3, 56(%1)\n"
8575 ++ "1: prefetch 320(%1)\n"
8576 ++ "2: movq (%1), %%mm0\n"
8577 ++ " movq 8(%1), %%mm1\n"
8578 ++ " movq 16(%1), %%mm2\n"
8579 ++ " movq 24(%1), %%mm3\n"
8580 ++ " movq %%mm0, (%2)\n"
8581 ++ " movq %%mm1, 8(%2)\n"
8582 ++ " movq %%mm2, 16(%2)\n"
8583 ++ " movq %%mm3, 24(%2)\n"
8584 ++ " movq 32(%1), %%mm0\n"
8585 ++ " movq 40(%1), %%mm1\n"
8586 ++ " movq 48(%1), %%mm2\n"
8587 ++ " movq 56(%1), %%mm3\n"
8588 ++ " movq %%mm0, 32(%2)\n"
8589 ++ " movq %%mm1, 40(%2)\n"
8590 ++ " movq %%mm2, 48(%2)\n"
8591 ++ " movq %%mm3, 56(%2)\n"
8592 + ".section .fixup, \"ax\"\n"
8593 +- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
8594 ++ "3:\n"
8595 ++
8596 ++#ifdef CONFIG_PAX_KERNEXEC
8597 ++ " movl %%cr0, %0\n"
8598 ++ " movl %0, %%eax\n"
8599 ++ " andl $0xFFFEFFFF, %%eax\n"
8600 ++ " movl %%eax, %%cr0\n"
8601 ++#endif
8602 ++
8603 ++ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
8604 ++
8605 ++#ifdef CONFIG_PAX_KERNEXEC
8606 ++ " movl %0, %%cr0\n"
8607 ++#endif
8608 ++
8609 + " jmp 2b\n"
8610 + ".previous\n"
8611 + _ASM_EXTABLE(1b, 3b)
8612 +- : : "r" (from), "r" (to) : "memory");
8613 ++ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
8614 +
8615 + from += 64;
8616 + to += 64;
8617 +diff -urNp linux-2.6.27.10/arch/x86/lib/putuser.S linux-2.6.27.10/arch/x86/lib/putuser.S
8618 +--- linux-2.6.27.10/arch/x86/lib/putuser.S 2008-11-07 12:55:34.000000000 -0500
8619 ++++ linux-2.6.27.10/arch/x86/lib/putuser.S 2008-11-18 03:38:44.000000000 -0500
8620 +@@ -15,6 +15,7 @@
8621 + #include <asm/thread_info.h>
8622 + #include <asm/errno.h>
8623 + #include <asm/asm.h>
8624 ++#include <asm/segment.h>
8625 +
8626 +
8627 + /*
8628 +@@ -39,7 +40,19 @@ ENTRY(__put_user_1)
8629 + ENTER
8630 + cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
8631 + jae bad_put_user
8632 ++
8633 ++#ifdef CONFIG_X86_32
8634 ++ pushl $(__USER_DS)
8635 ++ popl %ds
8636 ++#endif
8637 ++
8638 + 1: movb %al,(%_ASM_CX)
8639 ++
8640 ++#ifdef CONFIG_X86_32
8641 ++ pushl %ss
8642 ++ popl %ds
8643 ++#endif
8644 ++
8645 + xor %eax,%eax
8646 + EXIT
8647 + ENDPROC(__put_user_1)
8648 +@@ -50,7 +63,19 @@ ENTRY(__put_user_2)
8649 + sub $1,%_ASM_BX
8650 + cmp %_ASM_BX,%_ASM_CX
8651 + jae bad_put_user
8652 ++
8653 ++#ifdef CONFIG_X86_32
8654 ++ pushl $(__USER_DS)
8655 ++ popl %ds
8656 ++#endif
8657 ++
8658 + 2: movw %ax,(%_ASM_CX)
8659 ++
8660 ++#ifdef CONFIG_X86_32
8661 ++ pushl %ss
8662 ++ popl %ds
8663 ++#endif
8664 ++
8665 + xor %eax,%eax
8666 + EXIT
8667 + ENDPROC(__put_user_2)
8668 +@@ -61,7 +86,19 @@ ENTRY(__put_user_4)
8669 + sub $3,%_ASM_BX
8670 + cmp %_ASM_BX,%_ASM_CX
8671 + jae bad_put_user
8672 ++
8673 ++#ifdef CONFIG_X86_32
8674 ++ pushl $(__USER_DS)
8675 ++ popl %ds
8676 ++#endif
8677 ++
8678 + 3: movl %eax,(%_ASM_CX)
8679 ++
8680 ++#ifdef CONFIG_X86_32
8681 ++ pushl %ss
8682 ++ popl %ds
8683 ++#endif
8684 ++
8685 + xor %eax,%eax
8686 + EXIT
8687 + ENDPROC(__put_user_4)
8688 +@@ -72,16 +109,34 @@ ENTRY(__put_user_8)
8689 + sub $7,%_ASM_BX
8690 + cmp %_ASM_BX,%_ASM_CX
8691 + jae bad_put_user
8692 ++
8693 ++#ifdef CONFIG_X86_32
8694 ++ pushl $(__USER_DS)
8695 ++ popl %ds
8696 ++#endif
8697 ++
8698 + 4: mov %_ASM_AX,(%_ASM_CX)
8699 + #ifdef CONFIG_X86_32
8700 + 5: movl %edx,4(%_ASM_CX)
8701 + #endif
8702 ++
8703 ++#ifdef CONFIG_X86_32
8704 ++ pushl %ss
8705 ++ popl %ds
8706 ++#endif
8707 ++
8708 + xor %eax,%eax
8709 + EXIT
8710 + ENDPROC(__put_user_8)
8711 +
8712 + bad_put_user:
8713 + CFI_STARTPROC
8714 ++
8715 ++#ifdef CONFIG_X86_32
8716 ++ pushl %ss
8717 ++ popl %ds
8718 ++#endif
8719 ++
8720 + movl $-EFAULT,%eax
8721 + EXIT
8722 + END(bad_put_user)
8723 +diff -urNp linux-2.6.27.10/arch/x86/lib/usercopy_32.c linux-2.6.27.10/arch/x86/lib/usercopy_32.c
8724 +--- linux-2.6.27.10/arch/x86/lib/usercopy_32.c 2008-11-07 12:55:34.000000000 -0500
8725 ++++ linux-2.6.27.10/arch/x86/lib/usercopy_32.c 2008-11-18 03:38:44.000000000 -0500
8726 +@@ -29,31 +29,38 @@ static inline int __movsl_is_ok(unsigned
8727 + * Copy a null terminated string from userspace.
8728 + */
8729 +
8730 +-#define __do_strncpy_from_user(dst, src, count, res) \
8731 +-do { \
8732 +- int __d0, __d1, __d2; \
8733 +- might_sleep(); \
8734 +- __asm__ __volatile__( \
8735 +- " testl %1,%1\n" \
8736 +- " jz 2f\n" \
8737 +- "0: lodsb\n" \
8738 +- " stosb\n" \
8739 +- " testb %%al,%%al\n" \
8740 +- " jz 1f\n" \
8741 +- " decl %1\n" \
8742 +- " jnz 0b\n" \
8743 +- "1: subl %1,%0\n" \
8744 +- "2:\n" \
8745 +- ".section .fixup,\"ax\"\n" \
8746 +- "3: movl %5,%0\n" \
8747 +- " jmp 2b\n" \
8748 +- ".previous\n" \
8749 +- _ASM_EXTABLE(0b,3b) \
8750 +- : "=d"(res), "=c"(count), "=&a" (__d0), "=&S" (__d1), \
8751 +- "=&D" (__d2) \
8752 +- : "i"(-EFAULT), "0"(count), "1"(count), "3"(src), "4"(dst) \
8753 +- : "memory"); \
8754 +-} while (0)
8755 ++static long __do_strncpy_from_user(char *dst, const char __user *src, long count)
8756 ++{
8757 ++ int __d0, __d1, __d2;
8758 ++ long res = -EFAULT;
8759 ++
8760 ++ might_sleep();
8761 ++ __asm__ __volatile__(
8762 ++ " movw %w10,%%ds\n"
8763 ++ " testl %1,%1\n"
8764 ++ " jz 2f\n"
8765 ++ "0: lodsb\n"
8766 ++ " stosb\n"
8767 ++ " testb %%al,%%al\n"
8768 ++ " jz 1f\n"
8769 ++ " decl %1\n"
8770 ++ " jnz 0b\n"
8771 ++ "1: subl %1,%0\n"
8772 ++ "2:\n"
8773 ++ " pushl %%ss\n"
8774 ++ " popl %%ds\n"
8775 ++ ".section .fixup,\"ax\"\n"
8776 ++ "3: movl %5,%0\n"
8777 ++ " jmp 2b\n"
8778 ++ ".previous\n"
8779 ++ _ASM_EXTABLE(0b,3b)
8780 ++ : "=d"(res), "=c"(count), "=&a" (__d0), "=&S" (__d1),
8781 ++ "=&D" (__d2)
8782 ++ : "i"(-EFAULT), "0"(count), "1"(count), "3"(src), "4"(dst),
8783 ++ "r"(__USER_DS)
8784 ++ : "memory");
8785 ++ return res;
8786 ++}
8787 +
8788 + /**
8789 + * __strncpy_from_user: - Copy a NUL terminated string from userspace, with less checking.
8790 +@@ -78,9 +85,7 @@ do { \
8791 + long
8792 + __strncpy_from_user(char *dst, const char __user *src, long count)
8793 + {
8794 +- long res;
8795 +- __do_strncpy_from_user(dst, src, count, res);
8796 +- return res;
8797 ++ return __do_strncpy_from_user(dst, src, count);
8798 + }
8799 + EXPORT_SYMBOL(__strncpy_from_user);
8800 +
8801 +@@ -107,7 +112,7 @@ strncpy_from_user(char *dst, const char
8802 + {
8803 + long res = -EFAULT;
8804 + if (access_ok(VERIFY_READ, src, 1))
8805 +- __do_strncpy_from_user(dst, src, count, res);
8806 ++ res = __do_strncpy_from_user(dst, src, count);
8807 + return res;
8808 + }
8809 + EXPORT_SYMBOL(strncpy_from_user);
8810 +@@ -116,24 +121,30 @@ EXPORT_SYMBOL(strncpy_from_user);
8811 + * Zero Userspace
8812 + */
8813 +
8814 +-#define __do_clear_user(addr,size) \
8815 +-do { \
8816 +- int __d0; \
8817 +- might_sleep(); \
8818 +- __asm__ __volatile__( \
8819 +- "0: rep; stosl\n" \
8820 +- " movl %2,%0\n" \
8821 +- "1: rep; stosb\n" \
8822 +- "2:\n" \
8823 +- ".section .fixup,\"ax\"\n" \
8824 +- "3: lea 0(%2,%0,4),%0\n" \
8825 +- " jmp 2b\n" \
8826 +- ".previous\n" \
8827 +- _ASM_EXTABLE(0b,3b) \
8828 +- _ASM_EXTABLE(1b,2b) \
8829 +- : "=&c"(size), "=&D" (__d0) \
8830 +- : "r"(size & 3), "0"(size / 4), "1"(addr), "a"(0)); \
8831 +-} while (0)
8832 ++static unsigned long __do_clear_user(void __user *addr, unsigned long size)
8833 ++{
8834 ++ int __d0;
8835 ++
8836 ++ might_sleep();
8837 ++ __asm__ __volatile__(
8838 ++ " movw %w6,%%es\n"
8839 ++ "0: rep; stosl\n"
8840 ++ " movl %2,%0\n"
8841 ++ "1: rep; stosb\n"
8842 ++ "2:\n"
8843 ++ " pushl %%ss\n"
8844 ++ " popl %%es\n"
8845 ++ ".section .fixup,\"ax\"\n"
8846 ++ "3: lea 0(%2,%0,4),%0\n"
8847 ++ " jmp 2b\n"
8848 ++ ".previous\n"
8849 ++ _ASM_EXTABLE(0b,3b)
8850 ++ _ASM_EXTABLE(1b,2b)
8851 ++ : "=&c"(size), "=&D" (__d0)
8852 ++ : "r"(size & 3), "0"(size / 4), "1"(addr), "a"(0),
8853 ++ "r"(__USER_DS));
8854 ++ return size;
8855 ++}
8856 +
8857 + /**
8858 + * clear_user: - Zero a block of memory in user space.
8859 +@@ -150,7 +161,7 @@ clear_user(void __user *to, unsigned lon
8860 + {
8861 + might_sleep();
8862 + if (access_ok(VERIFY_WRITE, to, n))
8863 +- __do_clear_user(to, n);
8864 ++ n = __do_clear_user(to, n);
8865 + return n;
8866 + }
8867 + EXPORT_SYMBOL(clear_user);
8868 +@@ -169,8 +180,7 @@ EXPORT_SYMBOL(clear_user);
8869 + unsigned long
8870 + __clear_user(void __user *to, unsigned long n)
8871 + {
8872 +- __do_clear_user(to, n);
8873 +- return n;
8874 ++ return __do_clear_user(to, n);
8875 + }
8876 + EXPORT_SYMBOL(__clear_user);
8877 +
8878 +@@ -193,14 +203,17 @@ long strnlen_user(const char __user *s,
8879 + might_sleep();
8880 +
8881 + __asm__ __volatile__(
8882 ++ " movw %w8,%%es\n"
8883 + " testl %0, %0\n"
8884 + " jz 3f\n"
8885 +- " andl %0,%%ecx\n"
8886 ++ " movl %0,%%ecx\n"
8887 + "0: repne; scasb\n"
8888 + " setne %%al\n"
8889 + " subl %%ecx,%0\n"
8890 + " addl %0,%%eax\n"
8891 + "1:\n"
8892 ++ " pushl %%ss\n"
8893 ++ " popl %%es\n"
8894 + ".section .fixup,\"ax\"\n"
8895 + "2: xorl %%eax,%%eax\n"
8896 + " jmp 1b\n"
8897 +@@ -212,7 +225,7 @@ long strnlen_user(const char __user *s,
8898 + " .long 0b,2b\n"
8899 + ".previous"
8900 + :"=r" (n), "=D" (s), "=a" (res), "=c" (tmp)
8901 +- :"0" (n), "1" (s), "2" (0), "3" (mask)
8902 ++ :"0" (n), "1" (s), "2" (0), "3" (mask), "r" (__USER_DS)
8903 + :"cc");
8904 + return res & mask;
8905 + }
8906 +@@ -220,10 +233,11 @@ EXPORT_SYMBOL(strnlen_user);
8907 +
8908 + #ifdef CONFIG_X86_INTEL_USERCOPY
8909 + static unsigned long
8910 +-__copy_user_intel(void __user *to, const void *from, unsigned long size)
8911 ++__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
8912 + {
8913 + int d0, d1;
8914 + __asm__ __volatile__(
8915 ++ " movw %w6, %%es\n"
8916 + " .align 2,0x90\n"
8917 + "1: movl 32(%4), %%eax\n"
8918 + " cmpl $67, %0\n"
8919 +@@ -232,36 +246,36 @@ __copy_user_intel(void __user *to, const
8920 + " .align 2,0x90\n"
8921 + "3: movl 0(%4), %%eax\n"
8922 + "4: movl 4(%4), %%edx\n"
8923 +- "5: movl %%eax, 0(%3)\n"
8924 +- "6: movl %%edx, 4(%3)\n"
8925 ++ "5: movl %%eax, %%es:0(%3)\n"
8926 ++ "6: movl %%edx, %%es:4(%3)\n"
8927 + "7: movl 8(%4), %%eax\n"
8928 + "8: movl 12(%4),%%edx\n"
8929 +- "9: movl %%eax, 8(%3)\n"
8930 +- "10: movl %%edx, 12(%3)\n"
8931 ++ "9: movl %%eax, %%es:8(%3)\n"
8932 ++ "10: movl %%edx, %%es:12(%3)\n"
8933 + "11: movl 16(%4), %%eax\n"
8934 + "12: movl 20(%4), %%edx\n"
8935 +- "13: movl %%eax, 16(%3)\n"
8936 +- "14: movl %%edx, 20(%3)\n"
8937 ++ "13: movl %%eax, %%es:16(%3)\n"
8938 ++ "14: movl %%edx, %%es:20(%3)\n"
8939 + "15: movl 24(%4), %%eax\n"
8940 + "16: movl 28(%4), %%edx\n"
8941 +- "17: movl %%eax, 24(%3)\n"
8942 +- "18: movl %%edx, 28(%3)\n"
8943 ++ "17: movl %%eax, %%es:24(%3)\n"
8944 ++ "18: movl %%edx, %%es:28(%3)\n"
8945 + "19: movl 32(%4), %%eax\n"
8946 + "20: movl 36(%4), %%edx\n"
8947 +- "21: movl %%eax, 32(%3)\n"
8948 +- "22: movl %%edx, 36(%3)\n"
8949 ++ "21: movl %%eax, %%es:32(%3)\n"
8950 ++ "22: movl %%edx, %%es:36(%3)\n"
8951 + "23: movl 40(%4), %%eax\n"
8952 + "24: movl 44(%4), %%edx\n"
8953 +- "25: movl %%eax, 40(%3)\n"
8954 +- "26: movl %%edx, 44(%3)\n"
8955 ++ "25: movl %%eax, %%es:40(%3)\n"
8956 ++ "26: movl %%edx, %%es:44(%3)\n"
8957 + "27: movl 48(%4), %%eax\n"
8958 + "28: movl 52(%4), %%edx\n"
8959 +- "29: movl %%eax, 48(%3)\n"
8960 +- "30: movl %%edx, 52(%3)\n"
8961 ++ "29: movl %%eax, %%es:48(%3)\n"
8962 ++ "30: movl %%edx, %%es:52(%3)\n"
8963 + "31: movl 56(%4), %%eax\n"
8964 + "32: movl 60(%4), %%edx\n"
8965 +- "33: movl %%eax, 56(%3)\n"
8966 +- "34: movl %%edx, 60(%3)\n"
8967 ++ "33: movl %%eax, %%es:56(%3)\n"
8968 ++ "34: movl %%edx, %%es:60(%3)\n"
8969 + " addl $-64, %0\n"
8970 + " addl $64, %4\n"
8971 + " addl $64, %3\n"
8972 +@@ -275,6 +289,8 @@ __copy_user_intel(void __user *to, const
8973 + "36: movl %%eax, %0\n"
8974 + "37: rep; movsb\n"
8975 + "100:\n"
8976 ++ " pushl %%ss\n"
8977 ++ " popl %%es\n"
8978 + ".section .fixup,\"ax\"\n"
8979 + "101: lea 0(%%eax,%0,4),%0\n"
8980 + " jmp 100b\n"
8981 +@@ -321,7 +337,117 @@ __copy_user_intel(void __user *to, const
8982 + " .long 99b,101b\n"
8983 + ".previous"
8984 + : "=&c"(size), "=&D" (d0), "=&S" (d1)
8985 +- : "1"(to), "2"(from), "0"(size)
8986 ++ : "1"(to), "2"(from), "0"(size), "r"(__USER_DS)
8987 ++ : "eax", "edx", "memory");
8988 ++ return size;
8989 ++}
8990 ++
8991 ++static unsigned long
8992 ++__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
8993 ++{
8994 ++ int d0, d1;
8995 ++ __asm__ __volatile__(
8996 ++ " movw %w6, %%ds\n"
8997 ++ " .align 2,0x90\n"
8998 ++ "1: movl 32(%4), %%eax\n"
8999 ++ " cmpl $67, %0\n"
9000 ++ " jbe 3f\n"
9001 ++ "2: movl 64(%4), %%eax\n"
9002 ++ " .align 2,0x90\n"
9003 ++ "3: movl 0(%4), %%eax\n"
9004 ++ "4: movl 4(%4), %%edx\n"
9005 ++ "5: movl %%eax, %%es:0(%3)\n"
9006 ++ "6: movl %%edx, %%es:4(%3)\n"
9007 ++ "7: movl 8(%4), %%eax\n"
9008 ++ "8: movl 12(%4),%%edx\n"
9009 ++ "9: movl %%eax, %%es:8(%3)\n"
9010 ++ "10: movl %%edx, %%es:12(%3)\n"
9011 ++ "11: movl 16(%4), %%eax\n"
9012 ++ "12: movl 20(%4), %%edx\n"
9013 ++ "13: movl %%eax, %%es:16(%3)\n"
9014 ++ "14: movl %%edx, %%es:20(%3)\n"
9015 ++ "15: movl 24(%4), %%eax\n"
9016 ++ "16: movl 28(%4), %%edx\n"
9017 ++ "17: movl %%eax, %%es:24(%3)\n"
9018 ++ "18: movl %%edx, %%es:28(%3)\n"
9019 ++ "19: movl 32(%4), %%eax\n"
9020 ++ "20: movl 36(%4), %%edx\n"
9021 ++ "21: movl %%eax, %%es:32(%3)\n"
9022 ++ "22: movl %%edx, %%es:36(%3)\n"
9023 ++ "23: movl 40(%4), %%eax\n"
9024 ++ "24: movl 44(%4), %%edx\n"
9025 ++ "25: movl %%eax, %%es:40(%3)\n"
9026 ++ "26: movl %%edx, %%es:44(%3)\n"
9027 ++ "27: movl 48(%4), %%eax\n"
9028 ++ "28: movl 52(%4), %%edx\n"
9029 ++ "29: movl %%eax, %%es:48(%3)\n"
9030 ++ "30: movl %%edx, %%es:52(%3)\n"
9031 ++ "31: movl 56(%4), %%eax\n"
9032 ++ "32: movl 60(%4), %%edx\n"
9033 ++ "33: movl %%eax, %%es:56(%3)\n"
9034 ++ "34: movl %%edx, %%es:60(%3)\n"
9035 ++ " addl $-64, %0\n"
9036 ++ " addl $64, %4\n"
9037 ++ " addl $64, %3\n"
9038 ++ " cmpl $63, %0\n"
9039 ++ " ja 1b\n"
9040 ++ "35: movl %0, %%eax\n"
9041 ++ " shrl $2, %0\n"
9042 ++ " andl $3, %%eax\n"
9043 ++ " cld\n"
9044 ++ "99: rep; movsl\n"
9045 ++ "36: movl %%eax, %0\n"
9046 ++ "37: rep; movsb\n"
9047 ++ "100:\n"
9048 ++ " pushl %%ss\n"
9049 ++ " popl %%ds\n"
9050 ++ ".section .fixup,\"ax\"\n"
9051 ++ "101: lea 0(%%eax,%0,4),%0\n"
9052 ++ " jmp 100b\n"
9053 ++ ".previous\n"
9054 ++ ".section __ex_table,\"a\"\n"
9055 ++ " .align 4\n"
9056 ++ " .long 1b,100b\n"
9057 ++ " .long 2b,100b\n"
9058 ++ " .long 3b,100b\n"
9059 ++ " .long 4b,100b\n"
9060 ++ " .long 5b,100b\n"
9061 ++ " .long 6b,100b\n"
9062 ++ " .long 7b,100b\n"
9063 ++ " .long 8b,100b\n"
9064 ++ " .long 9b,100b\n"
9065 ++ " .long 10b,100b\n"
9066 ++ " .long 11b,100b\n"
9067 ++ " .long 12b,100b\n"
9068 ++ " .long 13b,100b\n"
9069 ++ " .long 14b,100b\n"
9070 ++ " .long 15b,100b\n"
9071 ++ " .long 16b,100b\n"
9072 ++ " .long 17b,100b\n"
9073 ++ " .long 18b,100b\n"
9074 ++ " .long 19b,100b\n"
9075 ++ " .long 20b,100b\n"
9076 ++ " .long 21b,100b\n"
9077 ++ " .long 22b,100b\n"
9078 ++ " .long 23b,100b\n"
9079 ++ " .long 24b,100b\n"
9080 ++ " .long 25b,100b\n"
9081 ++ " .long 26b,100b\n"
9082 ++ " .long 27b,100b\n"
9083 ++ " .long 28b,100b\n"
9084 ++ " .long 29b,100b\n"
9085 ++ " .long 30b,100b\n"
9086 ++ " .long 31b,100b\n"
9087 ++ " .long 32b,100b\n"
9088 ++ " .long 33b,100b\n"
9089 ++ " .long 34b,100b\n"
9090 ++ " .long 35b,100b\n"
9091 ++ " .long 36b,100b\n"
9092 ++ " .long 37b,100b\n"
9093 ++ " .long 99b,101b\n"
9094 ++ ".previous"
9095 ++ : "=&c"(size), "=&D" (d0), "=&S" (d1)
9096 ++ : "1"(to), "2"(from), "0"(size), "r"(__USER_DS)
9097 + : "eax", "edx", "memory");
9098 + return size;
9099 + }
9100 +@@ -331,6 +457,7 @@ __copy_user_zeroing_intel(void *to, cons
9101 + {
9102 + int d0, d1;
9103 + __asm__ __volatile__(
9104 ++ " movw %w6, %%ds\n"
9105 + " .align 2,0x90\n"
9106 + "0: movl 32(%4), %%eax\n"
9107 + " cmpl $67, %0\n"
9108 +@@ -339,36 +466,36 @@ __copy_user_zeroing_intel(void *to, cons
9109 + " .align 2,0x90\n"
9110 + "2: movl 0(%4), %%eax\n"
9111 + "21: movl 4(%4), %%edx\n"
9112 +- " movl %%eax, 0(%3)\n"
9113 +- " movl %%edx, 4(%3)\n"
9114 ++ " movl %%eax, %%es:0(%3)\n"
9115 ++ " movl %%edx, %%es:4(%3)\n"
9116 + "3: movl 8(%4), %%eax\n"
9117 + "31: movl 12(%4),%%edx\n"
9118 +- " movl %%eax, 8(%3)\n"
9119 +- " movl %%edx, 12(%3)\n"
9120 ++ " movl %%eax, %%es:8(%3)\n"
9121 ++ " movl %%edx, %%es:12(%3)\n"
9122 + "4: movl 16(%4), %%eax\n"
9123 + "41: movl 20(%4), %%edx\n"
9124 +- " movl %%eax, 16(%3)\n"
9125 +- " movl %%edx, 20(%3)\n"
9126 ++ " movl %%eax, %%es:16(%3)\n"
9127 ++ " movl %%edx, %%es:20(%3)\n"
9128 + "10: movl 24(%4), %%eax\n"
9129 + "51: movl 28(%4), %%edx\n"
9130 +- " movl %%eax, 24(%3)\n"
9131 +- " movl %%edx, 28(%3)\n"
9132 ++ " movl %%eax, %%es:24(%3)\n"
9133 ++ " movl %%edx, %%es:28(%3)\n"
9134 + "11: movl 32(%4), %%eax\n"
9135 + "61: movl 36(%4), %%edx\n"
9136 +- " movl %%eax, 32(%3)\n"
9137 +- " movl %%edx, 36(%3)\n"
9138 ++ " movl %%eax, %%es:32(%3)\n"
9139 ++ " movl %%edx, %%es:36(%3)\n"
9140 + "12: movl 40(%4), %%eax\n"
9141 + "71: movl 44(%4), %%edx\n"
9142 +- " movl %%eax, 40(%3)\n"
9143 +- " movl %%edx, 44(%3)\n"
9144 ++ " movl %%eax, %%es:40(%3)\n"
9145 ++ " movl %%edx, %%es:44(%3)\n"
9146 + "13: movl 48(%4), %%eax\n"
9147 + "81: movl 52(%4), %%edx\n"
9148 +- " movl %%eax, 48(%3)\n"
9149 +- " movl %%edx, 52(%3)\n"
9150 ++ " movl %%eax, %%es:48(%3)\n"
9151 ++ " movl %%edx, %%es:52(%3)\n"
9152 + "14: movl 56(%4), %%eax\n"
9153 + "91: movl 60(%4), %%edx\n"
9154 +- " movl %%eax, 56(%3)\n"
9155 +- " movl %%edx, 60(%3)\n"
9156 ++ " movl %%eax, %%es:56(%3)\n"
9157 ++ " movl %%edx, %%es:60(%3)\n"
9158 + " addl $-64, %0\n"
9159 + " addl $64, %4\n"
9160 + " addl $64, %3\n"
9161 +@@ -382,6 +509,8 @@ __copy_user_zeroing_intel(void *to, cons
9162 + " movl %%eax,%0\n"
9163 + "7: rep; movsb\n"
9164 + "8:\n"
9165 ++ " pushl %%ss\n"
9166 ++ " popl %%ds\n"
9167 + ".section .fixup,\"ax\"\n"
9168 + "9: lea 0(%%eax,%0,4),%0\n"
9169 + "16: pushl %0\n"
9170 +@@ -416,7 +545,7 @@ __copy_user_zeroing_intel(void *to, cons
9171 + " .long 7b,16b\n"
9172 + ".previous"
9173 + : "=&c"(size), "=&D" (d0), "=&S" (d1)
9174 +- : "1"(to), "2"(from), "0"(size)
9175 ++ : "1"(to), "2"(from), "0"(size), "r"(__USER_DS)
9176 + : "eax", "edx", "memory");
9177 + return size;
9178 + }
9179 +@@ -432,6 +561,7 @@ static unsigned long __copy_user_zeroing
9180 + int d0, d1;
9181 +
9182 + __asm__ __volatile__(
9183 ++ " movw %w6, %%ds\n"
9184 + " .align 2,0x90\n"
9185 + "0: movl 32(%4), %%eax\n"
9186 + " cmpl $67, %0\n"
9187 +@@ -440,36 +570,36 @@ static unsigned long __copy_user_zeroing
9188 + " .align 2,0x90\n"
9189 + "2: movl 0(%4), %%eax\n"
9190 + "21: movl 4(%4), %%edx\n"
9191 +- " movnti %%eax, 0(%3)\n"
9192 +- " movnti %%edx, 4(%3)\n"
9193 ++ " movnti %%eax, %%es:0(%3)\n"
9194 ++ " movnti %%edx, %%es:4(%3)\n"
9195 + "3: movl 8(%4), %%eax\n"
9196 + "31: movl 12(%4),%%edx\n"
9197 +- " movnti %%eax, 8(%3)\n"
9198 +- " movnti %%edx, 12(%3)\n"
9199 ++ " movnti %%eax, %%es:8(%3)\n"
9200 ++ " movnti %%edx, %%es:12(%3)\n"
9201 + "4: movl 16(%4), %%eax\n"
9202 + "41: movl 20(%4), %%edx\n"
9203 +- " movnti %%eax, 16(%3)\n"
9204 +- " movnti %%edx, 20(%3)\n"
9205 ++ " movnti %%eax, %%es:16(%3)\n"
9206 ++ " movnti %%edx, %%es:20(%3)\n"
9207 + "10: movl 24(%4), %%eax\n"
9208 + "51: movl 28(%4), %%edx\n"
9209 +- " movnti %%eax, 24(%3)\n"
9210 +- " movnti %%edx, 28(%3)\n"
9211 ++ " movnti %%eax, %%es:24(%3)\n"
9212 ++ " movnti %%edx, %%es:28(%3)\n"
9213 + "11: movl 32(%4), %%eax\n"
9214 + "61: movl 36(%4), %%edx\n"
9215 +- " movnti %%eax, 32(%3)\n"
9216 +- " movnti %%edx, 36(%3)\n"
9217 ++ " movnti %%eax, %%es:32(%3)\n"
9218 ++ " movnti %%edx, %%es:36(%3)\n"
9219 + "12: movl 40(%4), %%eax\n"
9220 + "71: movl 44(%4), %%edx\n"
9221 +- " movnti %%eax, 40(%3)\n"
9222 +- " movnti %%edx, 44(%3)\n"
9223 ++ " movnti %%eax, %%es:40(%3)\n"
9224 ++ " movnti %%edx, %%es:44(%3)\n"
9225 + "13: movl 48(%4), %%eax\n"
9226 + "81: movl 52(%4), %%edx\n"
9227 +- " movnti %%eax, 48(%3)\n"
9228 +- " movnti %%edx, 52(%3)\n"
9229 ++ " movnti %%eax, %%es:48(%3)\n"
9230 ++ " movnti %%edx, %%es:52(%3)\n"
9231 + "14: movl 56(%4), %%eax\n"
9232 + "91: movl 60(%4), %%edx\n"
9233 +- " movnti %%eax, 56(%3)\n"
9234 +- " movnti %%edx, 60(%3)\n"
9235 ++ " movnti %%eax, %%es:56(%3)\n"
9236 ++ " movnti %%edx, %%es:60(%3)\n"
9237 + " addl $-64, %0\n"
9238 + " addl $64, %4\n"
9239 + " addl $64, %3\n"
9240 +@@ -484,6 +614,8 @@ static unsigned long __copy_user_zeroing
9241 + " movl %%eax,%0\n"
9242 + "7: rep; movsb\n"
9243 + "8:\n"
9244 ++ " pushl %%ss\n"
9245 ++ " popl %%ds\n"
9246 + ".section .fixup,\"ax\"\n"
9247 + "9: lea 0(%%eax,%0,4),%0\n"
9248 + "16: pushl %0\n"
9249 +@@ -518,7 +650,7 @@ static unsigned long __copy_user_zeroing
9250 + " .long 7b,16b\n"
9251 + ".previous"
9252 + : "=&c"(size), "=&D" (d0), "=&S" (d1)
9253 +- : "1"(to), "2"(from), "0"(size)
9254 ++ : "1"(to), "2"(from), "0"(size), "r"(__USER_DS)
9255 + : "eax", "edx", "memory");
9256 + return size;
9257 + }
9258 +@@ -529,6 +661,7 @@ static unsigned long __copy_user_intel_n
9259 + int d0, d1;
9260 +
9261 + __asm__ __volatile__(
9262 ++ " movw %w6, %%ds\n"
9263 + " .align 2,0x90\n"
9264 + "0: movl 32(%4), %%eax\n"
9265 + " cmpl $67, %0\n"
9266 +@@ -537,36 +670,36 @@ static unsigned long __copy_user_intel_n
9267 + " .align 2,0x90\n"
9268 + "2: movl 0(%4), %%eax\n"
9269 + "21: movl 4(%4), %%edx\n"
9270 +- " movnti %%eax, 0(%3)\n"
9271 +- " movnti %%edx, 4(%3)\n"
9272 ++ " movnti %%eax, %%es:0(%3)\n"
9273 ++ " movnti %%edx, %%es:4(%3)\n"
9274 + "3: movl 8(%4), %%eax\n"
9275 + "31: movl 12(%4),%%edx\n"
9276 +- " movnti %%eax, 8(%3)\n"
9277 +- " movnti %%edx, 12(%3)\n"
9278 ++ " movnti %%eax, %%es:8(%3)\n"
9279 ++ " movnti %%edx, %%es:12(%3)\n"
9280 + "4: movl 16(%4), %%eax\n"
9281 + "41: movl 20(%4), %%edx\n"
9282 +- " movnti %%eax, 16(%3)\n"
9283 +- " movnti %%edx, 20(%3)\n"
9284 ++ " movnti %%eax, %%es:16(%3)\n"
9285 ++ " movnti %%edx, %%es:20(%3)\n"
9286 + "10: movl 24(%4), %%eax\n"
9287 + "51: movl 28(%4), %%edx\n"
9288 +- " movnti %%eax, 24(%3)\n"
9289 +- " movnti %%edx, 28(%3)\n"
9290 ++ " movnti %%eax, %%es:24(%3)\n"
9291 ++ " movnti %%edx, %%es:28(%3)\n"
9292 + "11: movl 32(%4), %%eax\n"
9293 + "61: movl 36(%4), %%edx\n"
9294 +- " movnti %%eax, 32(%3)\n"
9295 +- " movnti %%edx, 36(%3)\n"
9296 ++ " movnti %%eax, %%es:32(%3)\n"
9297 ++ " movnti %%edx, %%es:36(%3)\n"
9298 + "12: movl 40(%4), %%eax\n"
9299 + "71: movl 44(%4), %%edx\n"
9300 +- " movnti %%eax, 40(%3)\n"
9301 +- " movnti %%edx, 44(%3)\n"
9302 ++ " movnti %%eax, %%es:40(%3)\n"
9303 ++ " movnti %%edx, %%es:44(%3)\n"
9304 + "13: movl 48(%4), %%eax\n"
9305 + "81: movl 52(%4), %%edx\n"
9306 +- " movnti %%eax, 48(%3)\n"
9307 +- " movnti %%edx, 52(%3)\n"
9308 ++ " movnti %%eax, %%es:48(%3)\n"
9309 ++ " movnti %%edx, %%es:52(%3)\n"
9310 + "14: movl 56(%4), %%eax\n"
9311 + "91: movl 60(%4), %%edx\n"
9312 +- " movnti %%eax, 56(%3)\n"
9313 +- " movnti %%edx, 60(%3)\n"
9314 ++ " movnti %%eax, %%es:56(%3)\n"
9315 ++ " movnti %%edx, %%es:60(%3)\n"
9316 + " addl $-64, %0\n"
9317 + " addl $64, %4\n"
9318 + " addl $64, %3\n"
9319 +@@ -581,6 +714,8 @@ static unsigned long __copy_user_intel_n
9320 + " movl %%eax,%0\n"
9321 + "7: rep; movsb\n"
9322 + "8:\n"
9323 ++ " pushl %%ss\n"
9324 ++ " popl %%ds\n"
9325 + ".section .fixup,\"ax\"\n"
9326 + "9: lea 0(%%eax,%0,4),%0\n"
9327 + "16: jmp 8b\n"
9328 +@@ -609,7 +744,7 @@ static unsigned long __copy_user_intel_n
9329 + " .long 7b,16b\n"
9330 + ".previous"
9331 + : "=&c"(size), "=&D" (d0), "=&S" (d1)
9332 +- : "1"(to), "2"(from), "0"(size)
9333 ++ : "1"(to), "2"(from), "0"(size), "r"(__USER_DS)
9334 + : "eax", "edx", "memory");
9335 + return size;
9336 + }
9337 +@@ -622,90 +757,146 @@ static unsigned long __copy_user_intel_n
9338 + */
9339 + unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
9340 + unsigned long size);
9341 +-unsigned long __copy_user_intel(void __user *to, const void *from,
9342 ++unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
9343 ++ unsigned long size);
9344 ++unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
9345 + unsigned long size);
9346 + unsigned long __copy_user_zeroing_intel_nocache(void *to,
9347 + const void __user *from, unsigned long size);
9348 + #endif /* CONFIG_X86_INTEL_USERCOPY */
9349 +
9350 + /* Generic arbitrary sized copy. */
9351 +-#define __copy_user(to, from, size) \
9352 +-do { \
9353 +- int __d0, __d1, __d2; \
9354 +- __asm__ __volatile__( \
9355 +- " cmp $7,%0\n" \
9356 +- " jbe 1f\n" \
9357 +- " movl %1,%0\n" \
9358 +- " negl %0\n" \
9359 +- " andl $7,%0\n" \
9360 +- " subl %0,%3\n" \
9361 +- "4: rep; movsb\n" \
9362 +- " movl %3,%0\n" \
9363 +- " shrl $2,%0\n" \
9364 +- " andl $3,%3\n" \
9365 +- " .align 2,0x90\n" \
9366 +- "0: rep; movsl\n" \
9367 +- " movl %3,%0\n" \
9368 +- "1: rep; movsb\n" \
9369 +- "2:\n" \
9370 +- ".section .fixup,\"ax\"\n" \
9371 +- "5: addl %3,%0\n" \
9372 +- " jmp 2b\n" \
9373 +- "3: lea 0(%3,%0,4),%0\n" \
9374 +- " jmp 2b\n" \
9375 +- ".previous\n" \
9376 +- ".section __ex_table,\"a\"\n" \
9377 +- " .align 4\n" \
9378 +- " .long 4b,5b\n" \
9379 +- " .long 0b,3b\n" \
9380 +- " .long 1b,2b\n" \
9381 +- ".previous" \
9382 +- : "=&c"(size), "=&D" (__d0), "=&S" (__d1), "=r"(__d2) \
9383 +- : "3"(size), "0"(size), "1"(to), "2"(from) \
9384 +- : "memory"); \
9385 +-} while (0)
9386 +-
9387 +-#define __copy_user_zeroing(to, from, size) \
9388 +-do { \
9389 +- int __d0, __d1, __d2; \
9390 +- __asm__ __volatile__( \
9391 +- " cmp $7,%0\n" \
9392 +- " jbe 1f\n" \
9393 +- " movl %1,%0\n" \
9394 +- " negl %0\n" \
9395 +- " andl $7,%0\n" \
9396 +- " subl %0,%3\n" \
9397 +- "4: rep; movsb\n" \
9398 +- " movl %3,%0\n" \
9399 +- " shrl $2,%0\n" \
9400 +- " andl $3,%3\n" \
9401 +- " .align 2,0x90\n" \
9402 +- "0: rep; movsl\n" \
9403 +- " movl %3,%0\n" \
9404 +- "1: rep; movsb\n" \
9405 +- "2:\n" \
9406 +- ".section .fixup,\"ax\"\n" \
9407 +- "5: addl %3,%0\n" \
9408 +- " jmp 6f\n" \
9409 +- "3: lea 0(%3,%0,4),%0\n" \
9410 +- "6: pushl %0\n" \
9411 +- " pushl %%eax\n" \
9412 +- " xorl %%eax,%%eax\n" \
9413 +- " rep; stosb\n" \
9414 +- " popl %%eax\n" \
9415 +- " popl %0\n" \
9416 +- " jmp 2b\n" \
9417 +- ".previous\n" \
9418 +- ".section __ex_table,\"a\"\n" \
9419 +- " .align 4\n" \
9420 +- " .long 4b,5b\n" \
9421 +- " .long 0b,3b\n" \
9422 +- " .long 1b,6b\n" \
9423 +- ".previous" \
9424 +- : "=&c"(size), "=&D" (__d0), "=&S" (__d1), "=r"(__d2) \
9425 +- : "3"(size), "0"(size), "1"(to), "2"(from) \
9426 +- : "memory"); \
9427 +-} while (0)
9428 ++static unsigned long
9429 ++__generic_copy_to_user(void __user *to, const void *from, unsigned long size)
9430 ++{
9431 ++ int __d0, __d1, __d2;
9432 ++
9433 ++ __asm__ __volatile__(
9434 ++ " movw %w8,%%es\n"
9435 ++ " cmp $7,%0\n"
9436 ++ " jbe 1f\n"
9437 ++ " movl %1,%0\n"
9438 ++ " negl %0\n"
9439 ++ " andl $7,%0\n"
9440 ++ " subl %0,%3\n"
9441 ++ "4: rep; movsb\n"
9442 ++ " movl %3,%0\n"
9443 ++ " shrl $2,%0\n"
9444 ++ " andl $3,%3\n"
9445 ++ " .align 2,0x90\n"
9446 ++ "0: rep; movsl\n"
9447 ++ " movl %3,%0\n"
9448 ++ "1: rep; movsb\n"
9449 ++ "2:\n"
9450 ++ " pushl %%ss\n"
9451 ++ " popl %%es\n"
9452 ++ ".section .fixup,\"ax\"\n"
9453 ++ "5: addl %3,%0\n"
9454 ++ " jmp 2b\n"
9455 ++ "3: lea 0(%3,%0,4),%0\n"
9456 ++ " jmp 2b\n"
9457 ++ ".previous\n"
9458 ++ ".section __ex_table,\"a\"\n"
9459 ++ " .align 4\n"
9460 ++ " .long 4b,5b\n"
9461 ++ " .long 0b,3b\n"
9462 ++ " .long 1b,2b\n"
9463 ++ ".previous"
9464 ++ : "=&c"(size), "=&D" (__d0), "=&S" (__d1), "=r"(__d2)
9465 ++ : "3"(size), "0"(size), "1"(to), "2"(from), "r"(__USER_DS)
9466 ++ : "memory");
9467 ++ return size;
9468 ++}
9469 ++
9470 ++static unsigned long
9471 ++__generic_copy_from_user(void *to, const void __user *from, unsigned long size)
9472 ++{
9473 ++ int __d0, __d1, __d2;
9474 ++
9475 ++ __asm__ __volatile__(
9476 ++ " movw %w8,%%ds\n"
9477 ++ " cmp $7,%0\n"
9478 ++ " jbe 1f\n"
9479 ++ " movl %1,%0\n"
9480 ++ " negl %0\n"
9481 ++ " andl $7,%0\n"
9482 ++ " subl %0,%3\n"
9483 ++ "4: rep; movsb\n"
9484 ++ " movl %3,%0\n"
9485 ++ " shrl $2,%0\n"
9486 ++ " andl $3,%3\n"
9487 ++ " .align 2,0x90\n"
9488 ++ "0: rep; movsl\n"
9489 ++ " movl %3,%0\n"
9490 ++ "1: rep; movsb\n"
9491 ++ "2:\n"
9492 ++ " pushl %%ss\n"
9493 ++ " popl %%ds\n"
9494 ++ ".section .fixup,\"ax\"\n"
9495 ++ "5: addl %3,%0\n"
9496 ++ " jmp 2b\n"
9497 ++ "3: lea 0(%3,%0,4),%0\n"
9498 ++ " jmp 2b\n"
9499 ++ ".previous\n"
9500 ++ ".section __ex_table,\"a\"\n"
9501 ++ " .align 4\n"
9502 ++ " .long 4b,5b\n"
9503 ++ " .long 0b,3b\n"
9504 ++ " .long 1b,2b\n"
9505 ++ ".previous"
9506 ++ : "=&c"(size), "=&D" (__d0), "=&S" (__d1), "=r"(__d2)
9507 ++ : "3"(size), "0"(size), "1"(to), "2"(from), "r"(__USER_DS)
9508 ++ : "memory");
9509 ++ return size;
9510 ++}
9511 ++
9512 ++static unsigned long
9513 ++__copy_user_zeroing(void *to, const void __user *from, unsigned long size)
9514 ++{
9515 ++ int __d0, __d1, __d2;
9516 ++
9517 ++ __asm__ __volatile__(
9518 ++ " movw %w8,%%ds\n"
9519 ++ " cmp $7,%0\n"
9520 ++ " jbe 1f\n"
9521 ++ " movl %1,%0\n"
9522 ++ " negl %0\n"
9523 ++ " andl $7,%0\n"
9524 ++ " subl %0,%3\n"
9525 ++ "4: rep; movsb\n"
9526 ++ " movl %3,%0\n"
9527 ++ " shrl $2,%0\n"
9528 ++ " andl $3,%3\n"
9529 ++ " .align 2,0x90\n"
9530 ++ "0: rep; movsl\n"
9531 ++ " movl %3,%0\n"
9532 ++ "1: rep; movsb\n"
9533 ++ "2:\n"
9534 ++ " pushl %%ss\n"
9535 ++ " popl %%ds\n"
9536 ++ ".section .fixup,\"ax\"\n"
9537 ++ "5: addl %3,%0\n"
9538 ++ " jmp 6f\n"
9539 ++ "3: lea 0(%3,%0,4),%0\n"
9540 ++ "6: pushl %0\n"
9541 ++ " pushl %%eax\n"
9542 ++ " xorl %%eax,%%eax\n"
9543 ++ " rep; stosb\n"
9544 ++ " popl %%eax\n"
9545 ++ " popl %0\n"
9546 ++ " jmp 2b\n"
9547 ++ ".previous\n"
9548 ++ ".section __ex_table,\"a\"\n"
9549 ++ " .align 4\n"
9550 ++ " .long 4b,5b\n"
9551 ++ " .long 0b,3b\n"
9552 ++ " .long 1b,6b\n"
9553 ++ ".previous"
9554 ++ : "=&c"(size), "=&D" (__d0), "=&S" (__d1), "=r"(__d2)
9555 ++ : "3"(size), "0"(size), "1"(to), "2"(from), "r"(__USER_DS)
9556 ++ : "memory");
9557 ++ return size;
9558 ++}
9559 +
9560 + unsigned long __copy_to_user_ll(void __user *to, const void *from,
9561 + unsigned long n)
9562 +@@ -768,9 +959,9 @@ survive:
9563 + }
9564 + #endif
9565 + if (movsl_is_ok(to, from, n))
9566 +- __copy_user(to, from, n);
9567 ++ n = __generic_copy_to_user(to, from, n);
9568 + else
9569 +- n = __copy_user_intel(to, from, n);
9570 ++ n = __generic_copy_to_user_intel(to, from, n);
9571 + return n;
9572 + }
9573 + EXPORT_SYMBOL(__copy_to_user_ll);
9574 +@@ -779,7 +970,7 @@ unsigned long __copy_from_user_ll(void *
9575 + unsigned long n)
9576 + {
9577 + if (movsl_is_ok(to, from, n))
9578 +- __copy_user_zeroing(to, from, n);
9579 ++ n = __copy_user_zeroing(to, from, n);
9580 + else
9581 + n = __copy_user_zeroing_intel(to, from, n);
9582 + return n;
9583 +@@ -790,10 +981,9 @@ unsigned long __copy_from_user_ll_nozero
9584 + unsigned long n)
9585 + {
9586 + if (movsl_is_ok(to, from, n))
9587 +- __copy_user(to, from, n);
9588 ++ n = __generic_copy_from_user(to, from, n);
9589 + else
9590 +- n = __copy_user_intel((void __user *)to,
9591 +- (const void *)from, n);
9592 ++ n = __generic_copy_from_user_intel(to, from, n);
9593 + return n;
9594 + }
9595 + EXPORT_SYMBOL(__copy_from_user_ll_nozero);
9596 +@@ -802,12 +992,12 @@ unsigned long __copy_from_user_ll_nocach
9597 + unsigned long n)
9598 + {
9599 + #ifdef CONFIG_X86_INTEL_USERCOPY
9600 +- if (n > 64 && cpu_has_xmm2)
9601 ++ if ( n > 64 && cpu_has_xmm2)
9602 + n = __copy_user_zeroing_intel_nocache(to, from, n);
9603 + else
9604 +- __copy_user_zeroing(to, from, n);
9605 ++ n = __copy_user_zeroing(to, from, n);
9606 + #else
9607 +- __copy_user_zeroing(to, from, n);
9608 ++ n = __copy_user_zeroing(to, from, n);
9609 + #endif
9610 + return n;
9611 + }
9612 +@@ -817,12 +1007,12 @@ unsigned long __copy_from_user_ll_nocach
9613 + unsigned long n)
9614 + {
9615 + #ifdef CONFIG_X86_INTEL_USERCOPY
9616 +- if (n > 64 && cpu_has_xmm2)
9617 ++ if ( n > 64 && cpu_has_xmm2)
9618 + n = __copy_user_intel_nocache(to, from, n);
9619 + else
9620 +- __copy_user(to, from, n);
9621 ++ n = __generic_copy_from_user(to, from, n);
9622 + #else
9623 +- __copy_user(to, from, n);
9624 ++ n = __generic_copy_from_user(to, from, n);
9625 + #endif
9626 + return n;
9627 + }
9628 +@@ -871,8 +1061,35 @@ copy_from_user(void *to, const void __us
9629 + {
9630 + if (access_ok(VERIFY_READ, from, n))
9631 + n = __copy_from_user(to, from, n);
9632 +- else
9633 ++ else if ((long)n > 0)
9634 + memset(to, 0, n);
9635 + return n;
9636 + }
9637 + EXPORT_SYMBOL(copy_from_user);
9638 ++
9639 ++#ifdef CONFIG_PAX_MEMORY_UDEREF
9640 ++void __set_fs(mm_segment_t x, int cpu)
9641 ++{
9642 ++ unsigned long limit = x.seg;
9643 ++ struct desc_struct d;
9644 ++
9645 ++ current_thread_info()->addr_limit = x;
9646 ++ if (likely(limit))
9647 ++ limit = (limit - 1UL) >> PAGE_SHIFT;
9648 ++ pack_descriptor(&d, 0UL, limit, 0xF3, 0xC);
9649 ++ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_DS, &d, DESCTYPE_S);
9650 ++}
9651 ++
9652 ++void set_fs(mm_segment_t x)
9653 ++{
9654 ++ __set_fs(x, get_cpu());
9655 ++ put_cpu_no_resched();
9656 ++}
9657 ++#else
9658 ++void set_fs(mm_segment_t x)
9659 ++{
9660 ++ current_thread_info()->addr_limit = x;
9661 ++}
9662 ++#endif
9663 ++
9664 ++EXPORT_SYMBOL(set_fs);
9665 +diff -urNp linux-2.6.27.10/arch/x86/mach-voyager/voyager_basic.c linux-2.6.27.10/arch/x86/mach-voyager/voyager_basic.c
9666 +--- linux-2.6.27.10/arch/x86/mach-voyager/voyager_basic.c 2008-11-07 12:55:34.000000000 -0500
9667 ++++ linux-2.6.27.10/arch/x86/mach-voyager/voyager_basic.c 2008-11-18 03:38:44.000000000 -0500
9668 +@@ -123,7 +123,7 @@ int __init voyager_memory_detect(int reg
9669 + __u8 cmos[4];
9670 + ClickMap_t *map;
9671 + unsigned long map_addr;
9672 +- unsigned long old;
9673 ++ pte_t old;
9674 +
9675 + if (region >= CLICK_ENTRIES) {
9676 + printk("Voyager: Illegal ClickMap region %d\n", region);
9677 +@@ -138,7 +138,7 @@ int __init voyager_memory_detect(int reg
9678 +
9679 + /* steal page 0 for this */
9680 + old = pg0[0];
9681 +- pg0[0] = ((map_addr & PAGE_MASK) | _PAGE_RW | _PAGE_PRESENT);
9682 ++ pg0[0] = __pte((map_addr & PAGE_MASK) | _PAGE_RW | _PAGE_PRESENT);
9683 + local_flush_tlb();
9684 + /* now clear everything out but page 0 */
9685 + map = (ClickMap_t *) (map_addr & (~PAGE_MASK));
9686 +diff -urNp linux-2.6.27.10/arch/x86/mach-voyager/voyager_smp.c linux-2.6.27.10/arch/x86/mach-voyager/voyager_smp.c
9687 +--- linux-2.6.27.10/arch/x86/mach-voyager/voyager_smp.c 2008-11-07 12:55:34.000000000 -0500
9688 ++++ linux-2.6.27.10/arch/x86/mach-voyager/voyager_smp.c 2008-11-18 03:38:44.000000000 -0500
9689 +@@ -510,6 +510,10 @@ static void __init do_boot_cpu(__u8 cpu)
9690 + __u32 *hijack_vector;
9691 + __u32 start_phys_address = setup_trampoline();
9692 +
9693 ++#ifdef CONFIG_PAX_KERNEXEC
9694 ++ unsigned long cr0;
9695 ++#endif
9696 ++
9697 + /* There's a clever trick to this: The linux trampoline is
9698 + * compiled to begin at absolute location zero, so make the
9699 + * address zero but have the data segment selector compensate
9700 +@@ -529,7 +533,17 @@ static void __init do_boot_cpu(__u8 cpu)
9701 +
9702 + init_gdt(cpu);
9703 + per_cpu(current_task, cpu) = idle;
9704 +- early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
9705 ++
9706 ++#ifdef CONFIG_PAX_KERNEXEC
9707 ++ pax_open_kernel(cr0);
9708 ++#endif
9709 ++
9710 ++ early_gdt_descr.address = get_cpu_gdt_table(cpu);
9711 ++
9712 ++#ifdef CONFIG_PAX_KERNEXEC
9713 ++ pax_close_kernel(cr0);
9714 ++#endif
9715 ++
9716 + irq_ctx_init(cpu);
9717 +
9718 + /* Note: Don't modify initial ss override */
9719 +@@ -1141,7 +1155,7 @@ void smp_local_timer_interrupt(void)
9720 + per_cpu(prof_counter, cpu);
9721 + }
9722 +
9723 +- update_process_times(user_mode_vm(get_irq_regs()));
9724 ++ update_process_times(user_mode(get_irq_regs()));
9725 + }
9726 +
9727 + if (((1 << cpu) & voyager_extended_vic_processors) == 0)
9728 +diff -urNp linux-2.6.27.10/arch/x86/Makefile linux-2.6.27.10/arch/x86/Makefile
9729 +--- linux-2.6.27.10/arch/x86/Makefile 2008-11-07 12:55:34.000000000 -0500
9730 ++++ linux-2.6.27.10/arch/x86/Makefile 2008-11-18 03:38:44.000000000 -0500
9731 +@@ -232,3 +232,12 @@ endef
9732 + CLEAN_FILES += arch/x86/boot/fdimage \
9733 + arch/x86/boot/image.iso \
9734 + arch/x86/boot/mtools.conf
9735 ++
9736 ++define OLD_LD
9737 ++
9738 ++*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
9739 ++*** Please upgrade your binutils to 2.18 or newer
9740 ++endef
9741 ++
9742 ++archprepare:
9743 ++ $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
9744 +diff -urNp linux-2.6.27.10/arch/x86/mm/discontig_32.c linux-2.6.27.10/arch/x86/mm/discontig_32.c
9745 +--- linux-2.6.27.10/arch/x86/mm/discontig_32.c 2008-12-10 22:35:36.000000000 -0500
9746 ++++ linux-2.6.27.10/arch/x86/mm/discontig_32.c 2008-12-10 22:35:46.000000000 -0500
9747 +@@ -98,7 +98,6 @@ unsigned long node_memmap_size_bytes(int
9748 + }
9749 + #endif
9750 +
9751 +-extern unsigned long find_max_low_pfn(void);
9752 + extern unsigned long highend_pfn, highstart_pfn;
9753 +
9754 + #define LARGE_PAGE_BYTES (PTRS_PER_PTE * PAGE_SIZE)
9755 +diff -urNp linux-2.6.27.10/arch/x86/mm/extable.c linux-2.6.27.10/arch/x86/mm/extable.c
9756 +--- linux-2.6.27.10/arch/x86/mm/extable.c 2008-11-07 12:55:34.000000000 -0500
9757 ++++ linux-2.6.27.10/arch/x86/mm/extable.c 2008-11-18 03:38:44.000000000 -0500
9758 +@@ -1,14 +1,62 @@
9759 + #include <linux/module.h>
9760 + #include <linux/spinlock.h>
9761 ++#include <linux/sort.h>
9762 + #include <asm/uaccess.h>
9763 +
9764 ++/*
9765 ++ * The exception table needs to be sorted so that the binary
9766 ++ * search that we use to find entries in it works properly.
9767 ++ * This is used both for the kernel exception table and for
9768 ++ * the exception tables of modules that get loaded.
9769 ++ */
9770 ++static int cmp_ex(const void *a, const void *b)
9771 ++{
9772 ++ const struct exception_table_entry *x = a, *y = b;
9773 ++
9774 ++ /* avoid overflow */
9775 ++ if (x->insn > y->insn)
9776 ++ return 1;
9777 ++ if (x->insn < y->insn)
9778 ++ return -1;
9779 ++ return 0;
9780 ++}
9781 ++
9782 ++static void swap_ex(void *a, void *b, int size)
9783 ++{
9784 ++ struct exception_table_entry t, *x = a, *y = b;
9785 ++
9786 ++#ifdef CONFIG_PAX_KERNEXEC
9787 ++ unsigned long cr0;
9788 ++#endif
9789 ++
9790 ++ t = *x;
9791 ++
9792 ++#ifdef CONFIG_PAX_KERNEXEC
9793 ++ pax_open_kernel(cr0);
9794 ++#endif
9795 ++
9796 ++ *x = *y;
9797 ++ *y = t;
9798 ++
9799 ++#ifdef CONFIG_PAX_KERNEXEC
9800 ++ pax_close_kernel(cr0);
9801 ++#endif
9802 ++
9803 ++}
9804 ++
9805 ++void sort_extable(struct exception_table_entry *start,
9806 ++ struct exception_table_entry *finish)
9807 ++{
9808 ++ sort(start, finish - start, sizeof(struct exception_table_entry),
9809 ++ cmp_ex, swap_ex);
9810 ++}
9811 +
9812 + int fixup_exception(struct pt_regs *regs)
9813 + {
9814 + const struct exception_table_entry *fixup;
9815 +
9816 + #ifdef CONFIG_PNPBIOS
9817 +- if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
9818 ++ if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
9819 + extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
9820 + extern u32 pnp_bios_is_utter_crap;
9821 + pnp_bios_is_utter_crap = 1;
9822 +diff -urNp linux-2.6.27.10/arch/x86/mm/fault.c linux-2.6.27.10/arch/x86/mm/fault.c
9823 +--- linux-2.6.27.10/arch/x86/mm/fault.c 2008-11-07 12:55:34.000000000 -0500
9824 ++++ linux-2.6.27.10/arch/x86/mm/fault.c 2008-12-10 22:28:27.000000000 -0500
9825 +@@ -26,6 +26,8 @@
9826 + #include <linux/kprobes.h>
9827 + #include <linux/uaccess.h>
9828 + #include <linux/kdebug.h>
9829 ++#include <linux/unistd.h>
9830 ++#include <linux/compiler.h>
9831 +
9832 + #include <asm/system.h>
9833 + #include <asm/desc.h>
9834 +@@ -66,7 +68,7 @@ static inline int notify_page_fault(stru
9835 + int ret = 0;
9836 +
9837 + /* kprobe_running() needs smp_processor_id() */
9838 +- if (!user_mode_vm(regs)) {
9839 ++ if (!user_mode(regs)) {
9840 + preempt_disable();
9841 + if (kprobe_running() && kprobe_fault_handler(regs, 14))
9842 + ret = 1;
9843 +@@ -264,6 +266,30 @@ bad:
9844 + #endif
9845 + }
9846 +
9847 ++#ifdef CONFIG_PAX_EMUTRAMP
9848 ++static int pax_handle_fetch_fault(struct pt_regs *regs);
9849 ++#endif
9850 ++
9851 ++#ifdef CONFIG_PAX_PAGEEXEC
9852 ++static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
9853 ++{
9854 ++ pgd_t *pgd;
9855 ++ pud_t *pud;
9856 ++ pmd_t *pmd;
9857 ++
9858 ++ pgd = pgd_offset(mm, address);
9859 ++ if (!pgd_present(*pgd))
9860 ++ return NULL;
9861 ++ pud = pud_offset(pgd, address);
9862 ++ if (!pud_present(*pud))
9863 ++ return NULL;
9864 ++ pmd = pmd_offset(pud, address);
9865 ++ if (!pmd_present(*pmd))
9866 ++ return NULL;
9867 ++ return pmd;
9868 ++}
9869 ++#endif
9870 ++
9871 + #ifdef CONFIG_X86_32
9872 + static inline pmd_t *vmalloc_sync_one(pgd_t *pgd, unsigned long address)
9873 + {
9874 +@@ -350,7 +376,7 @@ static int is_errata93(struct pt_regs *r
9875 + static int is_errata100(struct pt_regs *regs, unsigned long address)
9876 + {
9877 + #ifdef CONFIG_X86_64
9878 +- if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) &&
9879 ++ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) &&
9880 + (address >> 32))
9881 + return 1;
9882 + #endif
9883 +@@ -387,14 +413,31 @@ static void show_fault_oops(struct pt_re
9884 + #endif
9885 +
9886 + #ifdef CONFIG_X86_PAE
9887 +- if (error_code & PF_INSTR) {
9888 ++ if (nx_enabled && (error_code & PF_INSTR)) {
9889 + unsigned int level;
9890 + pte_t *pte = lookup_address(address, &level);
9891 +
9892 + if (pte && pte_present(*pte) && !pte_exec(*pte))
9893 + printk(KERN_CRIT "kernel tried to execute "
9894 + "NX-protected page - exploit attempt? "
9895 +- "(uid: %d)\n", current->uid);
9896 ++ "(uid: %d, task: %s, pid: %d)\n",
9897 ++ current->uid, current->comm, task_pid_nr(current));
9898 ++ }
9899 ++#endif
9900 ++
9901 ++#ifdef CONFIG_PAX_KERNEXEC
9902 ++#ifdef CONFIG_MODULES
9903 ++ if (init_mm.start_code <= address && address < (unsigned long)MODULES_END)
9904 ++#else
9905 ++ if (init_mm.start_code <= address && address < init_mm.end_code)
9906 ++#endif
9907 ++ {
9908 ++ if (current->signal->curr_ip)
9909 ++ printk(KERN_ERR "PAX: From %u.%u.%u.%u: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
9910 ++ NIPQUAD(current->signal->curr_ip), current->comm, task_pid_nr(current), current->uid, current->euid);
9911 ++ else
9912 ++ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
9913 ++ current->comm, task_pid_nr(current), current->uid, current->euid);
9914 + }
9915 + #endif
9916 +
9917 +@@ -586,13 +629,22 @@ void __kprobes do_page_fault(struct pt_r
9918 + struct task_struct *tsk;
9919 + struct mm_struct *mm;
9920 + struct vm_area_struct *vma;
9921 +- unsigned long address;
9922 + int write, si_code;
9923 + int fault;
9924 + #ifdef CONFIG_X86_64
9925 + unsigned long flags;
9926 + #endif
9927 +
9928 ++#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
9929 ++ pte_t *pte;
9930 ++ pmd_t *pmd;
9931 ++ spinlock_t *ptl;
9932 ++ unsigned char pte_mask;
9933 ++#endif
9934 ++
9935 ++ /* get the address */
9936 ++ const unsigned long address = read_cr2();
9937 ++
9938 + /*
9939 + * We can fault from pretty much anywhere, with unknown IRQ state.
9940 + */
9941 +@@ -602,9 +654,6 @@ void __kprobes do_page_fault(struct pt_r
9942 + mm = tsk->mm;
9943 + prefetchw(&mm->mmap_sem);
9944 +
9945 +- /* get the address */
9946 +- address = read_cr2();
9947 +-
9948 + si_code = SEGV_MAPERR;
9949 +
9950 + if (notify_page_fault(regs))
9951 +@@ -657,7 +706,7 @@ void __kprobes do_page_fault(struct pt_r
9952 + * atomic region then we must not take the fault.
9953 + */
9954 + if (in_atomic() || !mm)
9955 +- goto bad_area_nosemaphore;
9956 ++ goto bad_area_nopax;
9957 + #else /* CONFIG_X86_64 */
9958 + if (likely(regs->flags & X86_EFLAGS_IF))
9959 + local_irq_enable();
9960 +@@ -670,13 +719,13 @@ void __kprobes do_page_fault(struct pt_r
9961 + * atomic region then we must not take the fault.
9962 + */
9963 + if (unlikely(in_atomic() || !mm))
9964 +- goto bad_area_nosemaphore;
9965 ++ goto bad_area_nopax;
9966 +
9967 + /*
9968 + * User-mode registers count as a user access even for any
9969 + * potential system fault or CPU buglet.
9970 + */
9971 +- if (user_mode_vm(regs))
9972 ++ if (user_mode(regs))
9973 + error_code |= PF_USER;
9974 + again:
9975 + #endif
9976 +@@ -698,10 +747,104 @@ again:
9977 + if (!down_read_trylock(&mm->mmap_sem)) {
9978 + if ((error_code & PF_USER) == 0 &&
9979 + !search_exception_tables(regs->ip))
9980 +- goto bad_area_nosemaphore;
9981 ++ goto bad_area_nopax;
9982 + down_read(&mm->mmap_sem);
9983 + }
9984 +
9985 ++#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
9986 ++ if (nx_enabled || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
9987 ++ !(mm->pax_flags & MF_PAX_PAGEEXEC))
9988 ++ goto not_pax_fault;
9989 ++
9990 ++ /* PaX: it's our fault, let's handle it if we can */
9991 ++
9992 ++ /* PaX: take a look at read faults before acquiring any locks */
9993 ++ if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
9994 ++ /* instruction fetch attempt from a protected page in user mode */
9995 ++ up_read(&mm->mmap_sem);
9996 ++
9997 ++#ifdef CONFIG_PAX_EMUTRAMP
9998 ++ switch (pax_handle_fetch_fault(regs)) {
9999 ++ case 2:
10000 ++ return;
10001 ++ }
10002 ++#endif
10003 ++
10004 ++ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
10005 ++ do_group_exit(SIGKILL);
10006 ++ }
10007 ++
10008 ++ pmd = pax_get_pmd(mm, address);
10009 ++ if (unlikely(!pmd))
10010 ++ goto not_pax_fault;
10011 ++
10012 ++ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
10013 ++ if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
10014 ++ pte_unmap_unlock(pte, ptl);
10015 ++ goto not_pax_fault;
10016 ++ }
10017 ++
10018 ++ if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
10019 ++ /* write attempt to a protected page in user mode */
10020 ++ pte_unmap_unlock(pte, ptl);
10021 ++ goto not_pax_fault;
10022 ++ }
10023 ++
10024 ++#ifdef CONFIG_SMP
10025 ++ if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
10026 ++#else
10027 ++ if (likely(address > get_limit(regs->cs)))
10028 ++#endif
10029 ++ {
10030 ++ set_pte(pte, pte_mkread(*pte));
10031 ++ __flush_tlb_one(address);
10032 ++ pte_unmap_unlock(pte, ptl);
10033 ++ up_read(&mm->mmap_sem);
10034 ++ return;
10035 ++ }
10036 ++
10037 ++ pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
10038 ++
10039 ++ /*
10040 ++ * PaX: fill DTLB with user rights and retry
10041 ++ */
10042 ++ __asm__ __volatile__ (
10043 ++#ifdef CONFIG_PAX_MEMORY_UDEREF
10044 ++ "movw %w4,%%es\n"
10045 ++#endif
10046 ++ "orb %2,(%1)\n"
10047 ++#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
10048 ++/*
10049 ++ * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
10050 ++ * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
10051 ++ * page fault when examined during a TLB load attempt. this is true not only
10052 ++ * for PTEs holding a non-present entry but also present entries that will
10053 ++ * raise a page fault (such as those set up by PaX, or the copy-on-write
10054 ++ * mechanism). in effect it means that we do *not* need to flush the TLBs
10055 ++ * for our target pages since their PTEs are simply not in the TLBs at all.
10056 ++
10057 ++ * the best thing in omitting it is that we gain around 15-20% speed in the
10058 ++ * fast path of the page fault handler and can get rid of tracing since we
10059 ++ * can no longer flush unintended entries.
10060 ++ */
10061 ++ "invlpg (%0)\n"
10062 ++#endif
10063 ++ "testb $0,%%es:(%0)\n"
10064 ++ "xorb %3,(%1)\n"
10065 ++#ifdef CONFIG_PAX_MEMORY_UDEREF
10066 ++ "pushl %%ss\n"
10067 ++ "popl %%es\n"
10068 ++#endif
10069 ++ :
10070 ++ : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER), "r" (__USER_DS)
10071 ++ : "memory", "cc");
10072 ++ pte_unmap_unlock(pte, ptl);
10073 ++ up_read(&mm->mmap_sem);
10074 ++ return;
10075 ++
10076 ++not_pax_fault:
10077 ++#endif
10078 ++
10079 + vma = find_vma(mm, address);
10080 + if (!vma)
10081 + goto bad_area;
10082 +@@ -709,16 +852,20 @@ again:
10083 + goto good_area;
10084 + if (!(vma->vm_flags & VM_GROWSDOWN))
10085 + goto bad_area;
10086 +- if (error_code & PF_USER) {
10087 +- /*
10088 +- * Accessing the stack below %sp is always a bug.
10089 +- * The large cushion allows instructions like enter
10090 +- * and pusha to work. ("enter $65535,$31" pushes
10091 +- * 32 pointers and then decrements %sp by 65535.)
10092 +- */
10093 +- if (address + 65536 + 32 * sizeof(unsigned long) < regs->sp)
10094 +- goto bad_area;
10095 +- }
10096 ++ /*
10097 ++ * Accessing the stack below %sp is always a bug.
10098 ++ * The large cushion allows instructions like enter
10099 ++ * and pusha to work. ("enter $65535,$31" pushes
10100 ++ * 32 pointers and then decrements %sp by 65535.)
10101 ++ */
10102 ++ if (address + 65536 + 32 * sizeof(unsigned long) < regs->sp)
10103 ++ goto bad_area;
10104 ++
10105 ++#ifdef CONFIG_PAX_SEGMEXEC
10106 ++ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)
10107 ++ goto bad_area;
10108 ++#endif
10109 ++
10110 + if (expand_stack(vma, address))
10111 + goto bad_area;
10112 + /*
10113 +@@ -728,6 +875,8 @@ again:
10114 + good_area:
10115 + si_code = SEGV_ACCERR;
10116 + write = 0;
10117 ++ if (nx_enabled && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
10118 ++ goto bad_area;
10119 + switch (error_code & (PF_PROT|PF_WRITE)) {
10120 + default: /* 3: write, present */
10121 + /* fall through */
10122 +@@ -785,6 +934,54 @@ bad_area:
10123 + up_read(&mm->mmap_sem);
10124 +
10125 + bad_area_nosemaphore:
10126 ++
10127 ++#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
10128 ++ if (mm && (error_code & PF_USER)) {
10129 ++ unsigned long ip = regs->ip;
10130 ++
10131 ++ if (v8086_mode(regs))
10132 ++ ip = ((regs->cs & 0xffff) << 4) + (regs->ip & 0xffff);
10133 ++
10134 ++ /*
10135 ++ * It's possible to have interrupts off here.
10136 ++ */
10137 ++ local_irq_enable();
10138 ++
10139 ++#ifdef CONFIG_PAX_PAGEEXEC
10140 ++ if ((mm->pax_flags & MF_PAX_PAGEEXEC) &&
10141 ++ ((nx_enabled && (error_code & PF_INSTR)) || (!(error_code & (PF_PROT | PF_WRITE)) && regs->ip == address))) {
10142 ++
10143 ++#ifdef CONFIG_PAX_EMUTRAMP
10144 ++ switch (pax_handle_fetch_fault(regs)) {
10145 ++ case 2:
10146 ++ return;
10147 ++ }
10148 ++#endif
10149 ++
10150 ++ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
10151 ++ do_group_exit(SIGKILL);
10152 ++ }
10153 ++#endif
10154 ++
10155 ++#ifdef CONFIG_PAX_SEGMEXEC
10156 ++ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && !(error_code & (PF_PROT | PF_WRITE)) && (regs->ip + SEGMEXEC_TASK_SIZE == address)) {
10157 ++
10158 ++#ifdef CONFIG_PAX_EMUTRAMP
10159 ++ switch (pax_handle_fetch_fault(regs)) {
10160 ++ case 2:
10161 ++ return;
10162 ++ }
10163 ++#endif
10164 ++
10165 ++ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
10166 ++ do_group_exit(SIGKILL);
10167 ++ }
10168 ++#endif
10169 ++
10170 ++ }
10171 ++#endif
10172 ++
10173 ++bad_area_nopax:
10174 + /* User mode accesses just cause a SIGSEGV */
10175 + if (error_code & PF_USER) {
10176 + /*
10177 +@@ -863,7 +1060,7 @@ no_context:
10178 + #ifdef CONFIG_X86_32
10179 + die("Oops", regs, error_code);
10180 + bust_spinlocks(0);
10181 +- do_exit(SIGKILL);
10182 ++ do_group_exit(SIGKILL);
10183 + #else
10184 + if (__die("Oops", regs, error_code))
10185 + regs = NULL;
10186 +@@ -877,17 +1074,17 @@ no_context:
10187 + * us unable to handle the page fault gracefully.
10188 + */
10189 + out_of_memory:
10190 +- up_read(&mm->mmap_sem);
10191 + if (is_global_init(tsk)) {
10192 + yield();
10193 + #ifdef CONFIG_X86_32
10194 +- down_read(&mm->mmap_sem);
10195 + goto survive;
10196 + #else
10197 ++ up_read(&mm->mmap_sem);
10198 + goto again;
10199 + #endif
10200 + }
10201 +
10202 ++ up_read(&mm->mmap_sem);
10203 + printk("VM: killing process %s\n", tsk->comm);
10204 + if (error_code & PF_USER)
10205 + do_group_exit(SIGKILL);
10206 +@@ -959,3 +1156,174 @@ void vmalloc_sync_all(void)
10207 + }
10208 + #endif
10209 + }
10210 ++
10211 ++#ifdef CONFIG_PAX_EMUTRAMP
10212 ++static int pax_handle_fetch_fault_32(struct pt_regs *regs)
10213 ++{
10214 ++ int err;
10215 ++
10216 ++ do { /* PaX: gcc trampoline emulation #1 */
10217 ++ unsigned char mov1, mov2;
10218 ++ unsigned short jmp;
10219 ++ unsigned int addr1, addr2;
10220 ++
10221 ++#ifdef CONFIG_X86_64
10222 ++ if ((regs->ip + 11) >> 32)
10223 ++ break;
10224 ++#endif
10225 ++
10226 ++ err = get_user(mov1, (unsigned char __user *)regs->ip);
10227 ++ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
10228 ++ err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
10229 ++ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
10230 ++ err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
10231 ++
10232 ++ if (err)
10233 ++ break;
10234 ++
10235 ++ if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
10236 ++ regs->cx = addr1;
10237 ++ regs->ax = addr2;
10238 ++ regs->ip = addr2;
10239 ++ return 2;
10240 ++ }
10241 ++ } while (0);
10242 ++
10243 ++ do { /* PaX: gcc trampoline emulation #2 */
10244 ++ unsigned char mov, jmp;
10245 ++ unsigned int addr1, addr2;
10246 ++
10247 ++#ifdef CONFIG_X86_64
10248 ++ if ((regs->ip + 9) >> 32)
10249 ++ break;
10250 ++#endif
10251 ++
10252 ++ err = get_user(mov, (unsigned char __user *)regs->ip);
10253 ++ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
10254 ++ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
10255 ++ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
10256 ++
10257 ++ if (err)
10258 ++ break;
10259 ++
10260 ++ if (mov == 0xB9 && jmp == 0xE9) {
10261 ++ regs->cx = addr1;
10262 ++ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
10263 ++ return 2;
10264 ++ }
10265 ++ } while (0);
10266 ++
10267 ++ return 1; /* PaX in action */
10268 ++}
10269 ++
10270 ++#ifdef CONFIG_X86_64
10271 ++static int pax_handle_fetch_fault_64(struct pt_regs *regs)
10272 ++{
10273 ++ int err;
10274 ++
10275 ++ do { /* PaX: gcc trampoline emulation #1 */
10276 ++ unsigned short mov1, mov2, jmp1;
10277 ++ unsigned char jmp2;
10278 ++ unsigned int addr1;
10279 ++ unsigned long addr2;
10280 ++
10281 ++ err = get_user(mov1, (unsigned short __user *)regs->ip);
10282 ++ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
10283 ++ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
10284 ++ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
10285 ++ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
10286 ++ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
10287 ++
10288 ++ if (err)
10289 ++ break;
10290 ++
10291 ++ if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
10292 ++ regs->r11 = addr1;
10293 ++ regs->r10 = addr2;
10294 ++ regs->ip = addr1;
10295 ++ return 2;
10296 ++ }
10297 ++ } while (0);
10298 ++
10299 ++ do { /* PaX: gcc trampoline emulation #2 */
10300 ++ unsigned short mov1, mov2, jmp1;
10301 ++ unsigned char jmp2;
10302 ++ unsigned long addr1, addr2;
10303 ++
10304 ++ err = get_user(mov1, (unsigned short __user *)regs->ip);
10305 ++ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
10306 ++ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
10307 ++ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
10308 ++ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
10309 ++ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
10310 ++
10311 ++ if (err)
10312 ++ break;
10313 ++
10314 ++ if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
10315 ++ regs->r11 = addr1;
10316 ++ regs->r10 = addr2;
10317 ++ regs->ip = addr1;
10318 ++ return 2;
10319 ++ }
10320 ++ } while (0);
10321 ++
10322 ++ return 1; /* PaX in action */
10323 ++}
10324 ++#endif
10325 ++
10326 ++/*
10327 ++ * PaX: decide what to do with offenders (regs->ip = fault address)
10328 ++ *
10329 ++ * returns 1 when task should be killed
10330 ++ * 2 when gcc trampoline was detected
10331 ++ */
10332 ++static int pax_handle_fetch_fault(struct pt_regs *regs)
10333 ++{
10334 ++ if (v8086_mode(regs))
10335 ++ return 1;
10336 ++
10337 ++ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
10338 ++ return 1;
10339 ++
10340 ++#ifdef CONFIG_X86_32
10341 ++ return pax_handle_fetch_fault_32(regs);
10342 ++#else
10343 ++ if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
10344 ++ return pax_handle_fetch_fault_32(regs);
10345 ++ else
10346 ++ return pax_handle_fetch_fault_64(regs);
10347 ++#endif
10348 ++}
10349 ++#endif
10350 ++
10351 ++#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
10352 ++void pax_report_insns(void *pc, void *sp)
10353 ++{
10354 ++ long i;
10355 ++
10356 ++ printk(KERN_ERR "PAX: bytes at PC: ");
10357 ++ for (i = 0; i < 20; i++) {
10358 ++ unsigned char c;
10359 ++ if (get_user(c, (unsigned char __user *)pc+i))
10360 ++ printk(KERN_CONT "?? ");
10361 ++ else
10362 ++ printk(KERN_CONT "%02x ", c);
10363 ++ }
10364 ++ printk("\n");
10365 ++
10366 ++ printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
10367 ++ for (i = -1; i < 80 / sizeof(long); i++) {
10368 ++ unsigned long c;
10369 ++ if (get_user(c, (unsigned long __user *)sp+i))
10370 ++#ifdef CONFIG_X86_32
10371 ++ printk(KERN_CONT "???????? ");
10372 ++#else
10373 ++ printk(KERN_CONT "???????????????? ");
10374 ++#endif
10375 ++ else
10376 ++ printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
10377 ++ }
10378 ++ printk("\n");
10379 ++}
10380 ++#endif
10381 +diff -urNp linux-2.6.27.10/arch/x86/mm/highmem_32.c linux-2.6.27.10/arch/x86/mm/highmem_32.c
10382 +--- linux-2.6.27.10/arch/x86/mm/highmem_32.c 2008-11-07 12:55:34.000000000 -0500
10383 ++++ linux-2.6.27.10/arch/x86/mm/highmem_32.c 2008-11-18 03:38:44.000000000 -0500
10384 +@@ -74,6 +74,10 @@ void *kmap_atomic_prot(struct page *page
10385 + enum fixed_addresses idx;
10386 + unsigned long vaddr;
10387 +
10388 ++#ifdef CONFIG_PAX_KERNEXEC
10389 ++ unsigned long cr0;
10390 ++#endif
10391 ++
10392 + /* even !CONFIG_PREEMPT needs this, for in_atomic in do_page_fault */
10393 + pagefault_disable();
10394 +
10395 +@@ -85,7 +89,17 @@ void *kmap_atomic_prot(struct page *page
10396 + idx = type + KM_TYPE_NR*smp_processor_id();
10397 + vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
10398 + BUG_ON(!pte_none(*(kmap_pte-idx)));
10399 ++
10400 ++#ifdef CONFIG_PAX_KERNEXEC
10401 ++ pax_open_kernel(cr0);
10402 ++#endif
10403 ++
10404 + set_pte(kmap_pte-idx, mk_pte(page, prot));
10405 ++
10406 ++#ifdef CONFIG_PAX_KERNEXEC
10407 ++ pax_close_kernel(cr0);
10408 ++#endif
10409 ++
10410 + arch_flush_lazy_mmu_mode();
10411 +
10412 + return (void *)vaddr;
10413 +@@ -101,15 +115,29 @@ void kunmap_atomic(void *kvaddr, enum km
10414 + unsigned long vaddr = (unsigned long) kvaddr & PAGE_MASK;
10415 + enum fixed_addresses idx = type + KM_TYPE_NR*smp_processor_id();
10416 +
10417 ++#ifdef CONFIG_PAX_KERNEXEC
10418 ++ unsigned long cr0;
10419 ++#endif
10420 ++
10421 + /*
10422 + * Force other mappings to Oops if they'll try to access this pte
10423 + * without first remap it. Keeping stale mappings around is a bad idea
10424 + * also, in case the page changes cacheability attributes or becomes
10425 + * a protected page in a hypervisor.
10426 + */
10427 +- if (vaddr == __fix_to_virt(FIX_KMAP_BEGIN+idx))
10428 ++ if (vaddr == __fix_to_virt(FIX_KMAP_BEGIN+idx)) {
10429 ++
10430 ++#ifdef CONFIG_PAX_KERNEXEC
10431 ++ pax_open_kernel(cr0);
10432 ++#endif
10433 ++
10434 + kpte_clear_flush(kmap_pte-idx, vaddr);
10435 +- else {
10436 ++
10437 ++#ifdef CONFIG_PAX_KERNEXEC
10438 ++ pax_close_kernel(cr0);
10439 ++#endif
10440 ++
10441 ++ } else {
10442 + #ifdef CONFIG_DEBUG_HIGHMEM
10443 + BUG_ON(vaddr < PAGE_OFFSET);
10444 + BUG_ON(vaddr >= (unsigned long)high_memory);
10445 +@@ -128,11 +156,25 @@ void *kmap_atomic_pfn(unsigned long pfn,
10446 + enum fixed_addresses idx;
10447 + unsigned long vaddr;
10448 +
10449 ++#ifdef CONFIG_PAX_KERNEXEC
10450 ++ unsigned long cr0;
10451 ++#endif
10452 ++
10453 + pagefault_disable();
10454 +
10455 + idx = type + KM_TYPE_NR*smp_processor_id();
10456 + vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
10457 ++
10458 ++#ifdef CONFIG_PAX_KERNEXEC
10459 ++ pax_open_kernel(cr0);
10460 ++#endif
10461 ++
10462 + set_pte(kmap_pte-idx, pfn_pte(pfn, kmap_prot));
10463 ++
10464 ++#ifdef CONFIG_PAX_KERNEXEC
10465 ++ pax_close_kernel(cr0);
10466 ++#endif
10467 ++
10468 + arch_flush_lazy_mmu_mode();
10469 +
10470 + return (void*) vaddr;
10471 +diff -urNp linux-2.6.27.10/arch/x86/mm/hugetlbpage.c linux-2.6.27.10/arch/x86/mm/hugetlbpage.c
10472 +--- linux-2.6.27.10/arch/x86/mm/hugetlbpage.c 2008-11-07 12:55:34.000000000 -0500
10473 ++++ linux-2.6.27.10/arch/x86/mm/hugetlbpage.c 2008-11-18 03:38:44.000000000 -0500
10474 +@@ -263,13 +263,18 @@ static unsigned long hugetlb_get_unmappe
10475 + struct hstate *h = hstate_file(file);
10476 + struct mm_struct *mm = current->mm;
10477 + struct vm_area_struct *vma;
10478 +- unsigned long start_addr;
10479 ++ unsigned long start_addr, pax_task_size = TASK_SIZE;
10480 ++
10481 ++#ifdef CONFIG_PAX_SEGMEXEC
10482 ++ if (mm->pax_flags & MF_PAX_SEGMEXEC)
10483 ++ pax_task_size = SEGMEXEC_TASK_SIZE;
10484 ++#endif
10485 +
10486 + if (len > mm->cached_hole_size) {
10487 +- start_addr = mm->free_area_cache;
10488 ++ start_addr = mm->free_area_cache;
10489 + } else {
10490 +- start_addr = TASK_UNMAPPED_BASE;
10491 +- mm->cached_hole_size = 0;
10492 ++ start_addr = mm->mmap_base;
10493 ++ mm->cached_hole_size = 0;
10494 + }
10495 +
10496 + full_search:
10497 +@@ -277,13 +282,13 @@ full_search:
10498 +
10499 + for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
10500 + /* At this point: (!vma || addr < vma->vm_end). */
10501 +- if (TASK_SIZE - len < addr) {
10502 ++ if (pax_task_size - len < addr) {
10503 + /*
10504 + * Start a new search - just in case we missed
10505 + * some holes.
10506 + */
10507 +- if (start_addr != TASK_UNMAPPED_BASE) {
10508 +- start_addr = TASK_UNMAPPED_BASE;
10509 ++ if (start_addr != mm->mmap_base) {
10510 ++ start_addr = mm->mmap_base;
10511 + mm->cached_hole_size = 0;
10512 + goto full_search;
10513 + }
10514 +@@ -306,9 +311,8 @@ static unsigned long hugetlb_get_unmappe
10515 + struct hstate *h = hstate_file(file);
10516 + struct mm_struct *mm = current->mm;
10517 + struct vm_area_struct *vma, *prev_vma;
10518 +- unsigned long base = mm->mmap_base, addr = addr0;
10519 ++ unsigned long base = mm->mmap_base, addr;
10520 + unsigned long largest_hole = mm->cached_hole_size;
10521 +- int first_time = 1;
10522 +
10523 + /* don't allow allocations above current base */
10524 + if (mm->free_area_cache > base)
10525 +@@ -318,7 +322,7 @@ static unsigned long hugetlb_get_unmappe
10526 + largest_hole = 0;
10527 + mm->free_area_cache = base;
10528 + }
10529 +-try_again:
10530 ++
10531 + /* make sure it can fit in the remaining address space */
10532 + if (mm->free_area_cache < len)
10533 + goto fail;
10534 +@@ -360,22 +364,26 @@ try_again:
10535 +
10536 + fail:
10537 + /*
10538 +- * if hint left us with no space for the requested
10539 +- * mapping then try again:
10540 +- */
10541 +- if (first_time) {
10542 +- mm->free_area_cache = base;
10543 +- largest_hole = 0;
10544 +- first_time = 0;
10545 +- goto try_again;
10546 +- }
10547 +- /*
10548 + * A failed mmap() very likely causes application failure,
10549 + * so fall back to the bottom-up function here. This scenario
10550 + * can happen with large stack limits and large mmap()
10551 + * allocations.
10552 + */
10553 +- mm->free_area_cache = TASK_UNMAPPED_BASE;
10554 ++
10555 ++#ifdef CONFIG_PAX_SEGMEXEC
10556 ++ if (mm->pax_flags & MF_PAX_SEGMEXEC)
10557 ++ mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
10558 ++ else
10559 ++#endif
10560 ++
10561 ++ mm->mmap_base = TASK_UNMAPPED_BASE;
10562 ++
10563 ++#ifdef CONFIG_PAX_RANDMMAP
10564 ++ if (mm->pax_flags & MF_PAX_RANDMMAP)
10565 ++ mm->mmap_base += mm->delta_mmap;
10566 ++#endif
10567 ++
10568 ++ mm->free_area_cache = mm->mmap_base;
10569 + mm->cached_hole_size = ~0UL;
10570 + addr = hugetlb_get_unmapped_area_bottomup(file, addr0,
10571 + len, pgoff, flags);
10572 +@@ -383,6 +391,7 @@ fail:
10573 + /*
10574 + * Restore the topdown base:
10575 + */
10576 ++ mm->mmap_base = base;
10577 + mm->free_area_cache = base;
10578 + mm->cached_hole_size = ~0UL;
10579 +
10580 +@@ -396,10 +405,17 @@ hugetlb_get_unmapped_area(struct file *f
10581 + struct hstate *h = hstate_file(file);
10582 + struct mm_struct *mm = current->mm;
10583 + struct vm_area_struct *vma;
10584 ++ unsigned long pax_task_size = TASK_SIZE;
10585 +
10586 + if (len & ~huge_page_mask(h))
10587 + return -EINVAL;
10588 +- if (len > TASK_SIZE)
10589 ++
10590 ++#ifdef CONFIG_PAX_SEGMEXEC
10591 ++ if (mm->pax_flags & MF_PAX_SEGMEXEC)
10592 ++ pax_task_size = SEGMEXEC_TASK_SIZE;
10593 ++#endif
10594 ++
10595 ++ if (len > pax_task_size)
10596 + return -ENOMEM;
10597 +
10598 + if (flags & MAP_FIXED) {
10599 +@@ -411,7 +427,7 @@ hugetlb_get_unmapped_area(struct file *f
10600 + if (addr) {
10601 + addr = ALIGN(addr, huge_page_size(h));
10602 + vma = find_vma(mm, addr);
10603 +- if (TASK_SIZE - len >= addr &&
10604 ++ if (pax_task_size - len >= addr &&
10605 + (!vma || addr + len <= vma->vm_start))
10606 + return addr;
10607 + }
10608 +diff -urNp linux-2.6.27.10/arch/x86/mm/init_32.c linux-2.6.27.10/arch/x86/mm/init_32.c
10609 +--- linux-2.6.27.10/arch/x86/mm/init_32.c 2008-11-07 12:55:34.000000000 -0500
10610 ++++ linux-2.6.27.10/arch/x86/mm/init_32.c 2008-11-18 03:38:44.000000000 -0500
10611 +@@ -47,6 +47,7 @@
10612 + #include <asm/paravirt.h>
10613 + #include <asm/setup.h>
10614 + #include <asm/cacheflush.h>
10615 ++#include <asm/desc.h>
10616 +
10617 + unsigned int __VMALLOC_RESERVE = 128 << 20;
10618 +
10619 +@@ -80,35 +81,6 @@ static __init void *alloc_low_page(unsig
10620 + }
10621 +
10622 + /*
10623 +- * Creates a middle page table and puts a pointer to it in the
10624 +- * given global directory entry. This only returns the gd entry
10625 +- * in non-PAE compilation mode, since the middle layer is folded.
10626 +- */
10627 +-static pmd_t * __init one_md_table_init(pgd_t *pgd)
10628 +-{
10629 +- pud_t *pud;
10630 +- pmd_t *pmd_table;
10631 +-
10632 +-#ifdef CONFIG_X86_PAE
10633 +- unsigned long phys;
10634 +- if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
10635 +- if (after_init_bootmem)
10636 +- pmd_table = (pmd_t *)alloc_bootmem_low_pages(PAGE_SIZE);
10637 +- else
10638 +- pmd_table = (pmd_t *)alloc_low_page(&phys);
10639 +- paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
10640 +- set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
10641 +- pud = pud_offset(pgd, 0);
10642 +- BUG_ON(pmd_table != pmd_offset(pud, 0));
10643 +- }
10644 +-#endif
10645 +- pud = pud_offset(pgd, 0);
10646 +- pmd_table = pmd_offset(pud, 0);
10647 +-
10648 +- return pmd_table;
10649 +-}
10650 +-
10651 +-/*
10652 + * Create a page table and place a pointer to it in a middle page
10653 + * directory entry:
10654 + */
10655 +@@ -130,7 +102,11 @@ static pte_t * __init one_page_table_ini
10656 + }
10657 +
10658 + paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
10659 ++#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
10660 ++ set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
10661 ++#else
10662 + set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
10663 ++#endif
10664 + BUG_ON(page_table != pte_offset_kernel(pmd, 0));
10665 + }
10666 +
10667 +@@ -152,6 +128,7 @@ page_table_range_init(unsigned long star
10668 + int pgd_idx, pmd_idx;
10669 + unsigned long vaddr;
10670 + pgd_t *pgd;
10671 ++ pud_t *pud;
10672 + pmd_t *pmd;
10673 +
10674 + vaddr = start;
10675 +@@ -160,8 +137,13 @@ page_table_range_init(unsigned long star
10676 + pgd = pgd_base + pgd_idx;
10677 +
10678 + for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
10679 +- pmd = one_md_table_init(pgd);
10680 +- pmd = pmd + pmd_index(vaddr);
10681 ++ pud = pud_offset(pgd, vaddr);
10682 ++ pmd = pmd_offset(pud, vaddr);
10683 ++
10684 ++#ifdef CONFIG_X86_PAE
10685 ++ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
10686 ++#endif
10687 ++
10688 + for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
10689 + pmd++, pmd_idx++) {
10690 + one_page_table_init(pmd);
10691 +@@ -172,11 +154,23 @@ page_table_range_init(unsigned long star
10692 + }
10693 + }
10694 +
10695 +-static inline int is_kernel_text(unsigned long addr)
10696 ++static inline int is_kernel_text(unsigned long start, unsigned long end)
10697 + {
10698 +- if (addr >= PAGE_OFFSET && addr <= (unsigned long)__init_end)
10699 +- return 1;
10700 +- return 0;
10701 ++ unsigned long etext;
10702 ++
10703 ++#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
10704 ++ etext = ktva_ktla((unsigned long)&MODULES_END);
10705 ++#else
10706 ++ etext = (unsigned long)&_etext;
10707 ++#endif
10708 ++
10709 ++ if ((start > ktla_ktva(etext) ||
10710 ++ end <= ktla_ktva((unsigned long)_stext)) &&
10711 ++ (start > ktla_ktva((unsigned long)_einittext) ||
10712 ++ end <= ktla_ktva((unsigned long)_sinittext)) &&
10713 ++ (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
10714 ++ return 0;
10715 ++ return 1;
10716 + }
10717 +
10718 + /*
10719 +@@ -189,9 +183,10 @@ static void __init kernel_physical_mappi
10720 + unsigned long end_pfn,
10721 + int use_pse)
10722 + {
10723 +- int pgd_idx, pmd_idx, pte_ofs;
10724 ++ unsigned int pgd_idx, pmd_idx, pte_ofs;
10725 + unsigned long pfn;
10726 + pgd_t *pgd;
10727 ++ pud_t *pud;
10728 + pmd_t *pmd;
10729 + pte_t *pte;
10730 + unsigned pages_2m = 0, pages_4k = 0;
10731 +@@ -202,8 +197,13 @@ static void __init kernel_physical_mappi
10732 + pfn = start_pfn;
10733 + pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
10734 + pgd = pgd_base + pgd_idx;
10735 +- for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
10736 +- pmd = one_md_table_init(pgd);
10737 ++ for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
10738 ++ pud = pud_offset(pgd, 0);
10739 ++ pmd = pmd_offset(pud, 0);
10740 ++
10741 ++#ifdef CONFIG_X86_PAE
10742 ++ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
10743 ++#endif
10744 +
10745 + if (pfn >= end_pfn)
10746 + continue;
10747 +@@ -215,21 +215,16 @@ static void __init kernel_physical_mappi
10748 + #endif
10749 + for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
10750 + pmd++, pmd_idx++) {
10751 +- unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
10752 ++ unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
10753 +
10754 + /*
10755 + * Map with big pages if possible, otherwise
10756 + * create normal page tables:
10757 + */
10758 + if (use_pse) {
10759 +- unsigned int addr2;
10760 + pgprot_t prot = PAGE_KERNEL_LARGE;
10761 +
10762 +- addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
10763 +- PAGE_OFFSET + PAGE_SIZE-1;
10764 +-
10765 +- if (is_kernel_text(addr) ||
10766 +- is_kernel_text(addr2))
10767 ++ if (is_kernel_text(address, address + PMD_SIZE))
10768 + prot = PAGE_KERNEL_LARGE_EXEC;
10769 +
10770 + pages_2m++;
10771 +@@ -243,10 +238,10 @@ static void __init kernel_physical_mappi
10772 + pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
10773 + pte += pte_ofs;
10774 + for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
10775 +- pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
10776 ++ pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
10777 + pgprot_t prot = PAGE_KERNEL;
10778 +
10779 +- if (is_kernel_text(addr))
10780 ++ if (is_kernel_text(address, address + PAGE_SIZE))
10781 + prot = PAGE_KERNEL_EXEC;
10782 +
10783 + pages_4k++;
10784 +@@ -270,7 +265,9 @@ static void __init kernel_physical_mappi
10785 + */
10786 + int devmem_is_allowed(unsigned long pagenr)
10787 + {
10788 +- if (pagenr <= 256)
10789 ++ if (!pagenr)
10790 ++ return 1;
10791 ++ if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
10792 + return 1;
10793 + if (!page_is_ram(pagenr))
10794 + return 1;
10795 +@@ -404,7 +401,7 @@ void __init native_pagetable_setup_start
10796 +
10797 + pud = pud_offset(pgd, va);
10798 + pmd = pmd_offset(pud, va);
10799 +- if (!pmd_present(*pmd))
10800 ++ if (!pmd_present(*pmd) || pmd_huge(*pmd))
10801 + break;
10802 +
10803 + pte = pte_offset_kernel(pmd, va);
10804 +@@ -456,9 +453,7 @@ static void __init early_ioremap_page_ta
10805 +
10806 + static void __init pagetable_init(void)
10807 + {
10808 +- pgd_t *pgd_base = swapper_pg_dir;
10809 +-
10810 +- permanent_kmaps_init(pgd_base);
10811 ++ permanent_kmaps_init(swapper_pg_dir);
10812 + }
10813 +
10814 + #ifdef CONFIG_ACPI_SLEEP
10815 +@@ -466,12 +461,12 @@ static void __init pagetable_init(void)
10816 + * ACPI suspend needs this for resume, because things like the intel-agp
10817 + * driver might have split up a kernel 4MB mapping.
10818 + */
10819 +-char swsusp_pg_dir[PAGE_SIZE]
10820 ++pgd_t swsusp_pg_dir[PTRS_PER_PGD]
10821 + __attribute__ ((aligned(PAGE_SIZE)));
10822 +
10823 + static inline void save_pg_dir(void)
10824 + {
10825 +- memcpy(swsusp_pg_dir, swapper_pg_dir, PAGE_SIZE);
10826 ++ clone_pgd_range(swsusp_pg_dir, swapper_pg_dir, PTRS_PER_PGD);
10827 + }
10828 + #else /* !CONFIG_ACPI_SLEEP */
10829 + static inline void save_pg_dir(void)
10830 +@@ -501,13 +496,11 @@ void zap_low_mappings(void)
10831 +
10832 + int nx_enabled;
10833 +
10834 +-pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL);
10835 ++pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL);
10836 + EXPORT_SYMBOL_GPL(__supported_pte_mask);
10837 +
10838 + #ifdef CONFIG_X86_PAE
10839 +
10840 +-static int disable_nx __initdata;
10841 +-
10842 + /*
10843 + * noexec = on|off
10844 + *
10845 +@@ -516,40 +509,33 @@ static int disable_nx __initdata;
10846 + * on Enable
10847 + * off Disable
10848 + */
10849 ++#if !defined(CONFIG_PAX_PAGEEXEC)
10850 + static int __init noexec_setup(char *str)
10851 + {
10852 + if (!str || !strcmp(str, "on")) {
10853 +- if (cpu_has_nx) {
10854 +- __supported_pte_mask |= _PAGE_NX;
10855 +- disable_nx = 0;
10856 +- }
10857 ++ if (cpu_has_nx)
10858 ++ nx_enabled = 1;
10859 + } else {
10860 +- if (!strcmp(str, "off")) {
10861 +- disable_nx = 1;
10862 +- __supported_pte_mask &= ~_PAGE_NX;
10863 +- } else {
10864 ++ if (!strcmp(str, "off"))
10865 ++ nx_enabled = 0;
10866 ++ else
10867 + return -EINVAL;
10868 +- }
10869 + }
10870 +
10871 + return 0;
10872 + }
10873 + early_param("noexec", noexec_setup);
10874 ++#endif
10875 +
10876 + static void __init set_nx(void)
10877 + {
10878 +- unsigned int v[4], l, h;
10879 +-
10880 +- if (cpu_has_pae && (cpuid_eax(0x80000000) > 0x80000001)) {
10881 +- cpuid(0x80000001, &v[0], &v[1], &v[2], &v[3]);
10882 ++ if (!nx_enabled && cpu_has_nx) {
10883 ++ unsigned l, h;
10884 +
10885 +- if ((v[3] & (1 << 20)) && !disable_nx) {
10886 +- rdmsr(MSR_EFER, l, h);
10887 +- l |= EFER_NX;
10888 +- wrmsr(MSR_EFER, l, h);
10889 +- nx_enabled = 1;
10890 +- __supported_pte_mask |= _PAGE_NX;
10891 +- }
10892 ++ __supported_pte_mask &= ~_PAGE_NX;
10893 ++ rdmsr(MSR_EFER, l, h);
10894 ++ l &= ~EFER_NX;
10895 ++ wrmsr(MSR_EFER, l, h);
10896 + }
10897 + }
10898 + #endif
10899 +@@ -920,7 +906,7 @@ void __init mem_init(void)
10900 + set_highmem_pages_init();
10901 +
10902 + codesize = (unsigned long) &_etext - (unsigned long) &_text;
10903 +- datasize = (unsigned long) &_edata - (unsigned long) &_etext;
10904 ++ datasize = (unsigned long) &_edata - (unsigned long) &_data;
10905 + initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
10906 +
10907 + kclist_add(&kcore_mem, __va(0), max_low_pfn << PAGE_SHIFT);
10908 +@@ -966,10 +952,10 @@ void __init mem_init(void)
10909 + ((unsigned long)&__init_end -
10910 + (unsigned long)&__init_begin) >> 10,
10911 +
10912 +- (unsigned long)&_etext, (unsigned long)&_edata,
10913 +- ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
10914 ++ (unsigned long)&_data, (unsigned long)&_edata,
10915 ++ ((unsigned long)&_edata - (unsigned long)&_data) >> 10,
10916 +
10917 +- (unsigned long)&_text, (unsigned long)&_etext,
10918 ++ ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
10919 + ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
10920 +
10921 + #ifdef CONFIG_HIGHMEM
10922 +@@ -1099,6 +1085,46 @@ void free_init_pages(char *what, unsigne
10923 +
10924 + void free_initmem(void)
10925 + {
10926 ++
10927 ++#ifdef CONFIG_PAX_KERNEXEC
10928 ++ /* PaX: limit KERNEL_CS to actual size */
10929 ++ unsigned long addr, limit;
10930 ++ struct desc_struct d;
10931 ++ int cpu;
10932 ++ pgd_t *pgd;
10933 ++ pud_t *pud;
10934 ++ pmd_t *pmd;
10935 ++
10936 ++#ifdef CONFIG_MODULES
10937 ++ limit = ktva_ktla((unsigned long)&MODULES_END);
10938 ++#else
10939 ++ limit = (unsigned long)&_etext;
10940 ++#endif
10941 ++ limit = (limit - 1UL) >> PAGE_SHIFT;
10942 ++
10943 ++ for (cpu = 0; cpu < NR_CPUS; cpu++) {
10944 ++ pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
10945 ++ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
10946 ++ }
10947 ++
10948 ++ /* PaX: make KERNEL_CS read-only */
10949 ++ for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_data; addr += PMD_SIZE) {
10950 ++ pgd = pgd_offset_k(addr);
10951 ++ pud = pud_offset(pgd, addr);
10952 ++ pmd = pmd_offset(pud, addr);
10953 ++ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
10954 ++ }
10955 ++#ifdef CONFIG_X86_PAE
10956 ++ for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
10957 ++ pgd = pgd_offset_k(addr);
10958 ++ pud = pud_offset(pgd, addr);
10959 ++ pmd = pmd_offset(pud, addr);
10960 ++ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
10961 ++ }
10962 ++#endif
10963 ++ flush_tlb_all();
10964 ++#endif
10965 ++
10966 + free_init_pages("unused kernel memory",
10967 + (unsigned long)(&__init_begin),
10968 + (unsigned long)(&__init_end));
10969 +diff -urNp linux-2.6.27.10/arch/x86/mm/init_64.c linux-2.6.27.10/arch/x86/mm/init_64.c
10970 +--- linux-2.6.27.10/arch/x86/mm/init_64.c 2008-12-21 01:16:51.000000000 -0500
10971 ++++ linux-2.6.27.10/arch/x86/mm/init_64.c 2008-12-21 01:13:45.000000000 -0500
10972 +@@ -118,6 +118,10 @@ set_pte_vaddr_pud(pud_t *pud_page, unsig
10973 + pmd_t *pmd;
10974 + pte_t *pte;
10975 +
10976 ++#ifdef CONFIG_PAX_KERNEXEC
10977 ++ unsigned long cr0;
10978 ++#endif
10979 ++
10980 + pud = pud_page + pud_index(vaddr);
10981 + if (pud_none(*pud)) {
10982 + pmd = (pmd_t *) spp_getpage();
10983 +@@ -142,8 +146,17 @@ set_pte_vaddr_pud(pud_t *pud_page, unsig
10984 + if (!pte_none(*pte) && pte_val(new_pte) &&
10985 + pte_val(*pte) != (pte_val(new_pte) & __supported_pte_mask))
10986 + pte_ERROR(*pte);
10987 ++
10988 ++#ifdef CONFIG_PAX_KERNEXEC
10989 ++ pax_open_kernel(cr0);
10990 ++#endif
10991 ++
10992 + set_pte(pte, new_pte);
10993 +
10994 ++#ifdef CONFIG_PAX_KERNEXEC
10995 ++ pax_close_kernel(cr0);
10996 ++#endif
10997 ++
10998 + /*
10999 + * It's enough to flush this one mapping.
11000 + * (PGE mappings get flushed as well)
11001 +@@ -184,14 +197,12 @@ static void __init __init_extra_mapping(
11002 + pgd = pgd_offset_k((unsigned long)__va(phys));
11003 + if (pgd_none(*pgd)) {
11004 + pud = (pud_t *) spp_getpage();
11005 +- set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
11006 +- _PAGE_USER));
11007 ++ set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
11008 + }
11009 + pud = pud_offset(pgd, (unsigned long)__va(phys));
11010 + if (pud_none(*pud)) {
11011 + pmd = (pmd_t *) spp_getpage();
11012 +- set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
11013 +- _PAGE_USER));
11014 ++ set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
11015 + }
11016 + pmd = pmd_offset(pud, phys);
11017 + BUG_ON(!pmd_none(*pmd));
11018 +@@ -754,7 +765,9 @@ EXPORT_SYMBOL_GPL(memory_add_physaddr_to
11019 + */
11020 + int devmem_is_allowed(unsigned long pagenr)
11021 + {
11022 +- if (pagenr <= 256)
11023 ++ if (!pagenr)
11024 ++ return 1;
11025 ++ if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
11026 + return 1;
11027 + if (!page_is_ram(pagenr))
11028 + return 1;
11029 +@@ -842,6 +855,39 @@ void free_init_pages(char *what, unsigne
11030 +
11031 + void free_initmem(void)
11032 + {
11033 ++
11034 ++#ifdef CONFIG_PAX_KERNEXEC
11035 ++ unsigned long addr, end;
11036 ++ pgd_t *pgd;
11037 ++ pud_t *pud;
11038 ++ pmd_t *pmd;
11039 ++
11040 ++ /* PaX: make kernel code/rodata read-only, rest non-executable */
11041 ++ for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
11042 ++ pgd = pgd_offset_k(addr);
11043 ++ pud = pud_offset(pgd, addr);
11044 ++ pmd = pmd_offset(pud, addr);
11045 ++ if ((unsigned long)_text <= addr && addr < (unsigned long)_data)
11046 ++ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
11047 ++ else
11048 ++ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
11049 ++ }
11050 ++
11051 ++ addr = (unsigned long)__va(__pa(__START_KERNEL_map));
11052 ++ end = addr + KERNEL_IMAGE_SIZE;
11053 ++ for (; addr < end; addr += PMD_SIZE) {
11054 ++ pgd = pgd_offset_k(addr);
11055 ++ pud = pud_offset(pgd, addr);
11056 ++ pmd = pmd_offset(pud, addr);
11057 ++ if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_data)))
11058 ++ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
11059 ++ else
11060 ++ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
11061 ++ }
11062 ++
11063 ++ flush_tlb_all();
11064 ++#endif
11065 ++
11066 + free_init_pages("unused kernel memory",
11067 + (unsigned long)(&__init_begin),
11068 + (unsigned long)(&__init_end));
11069 +@@ -1014,7 +1060,7 @@ int in_gate_area_no_task(unsigned long a
11070 +
11071 + const char *arch_vma_name(struct vm_area_struct *vma)
11072 + {
11073 +- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
11074 ++ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
11075 + return "[vdso]";
11076 + if (vma == &gate_vma)
11077 + return "[vsyscall]";
11078 +diff -urNp linux-2.6.27.10/arch/x86/mm/ioremap.c linux-2.6.27.10/arch/x86/mm/ioremap.c
11079 +--- linux-2.6.27.10/arch/x86/mm/ioremap.c 2008-11-07 12:55:34.000000000 -0500
11080 ++++ linux-2.6.27.10/arch/x86/mm/ioremap.c 2008-11-18 03:38:44.000000000 -0500
11081 +@@ -63,8 +63,8 @@ int page_is_ram(unsigned long pagenr)
11082 + * Second special case: Some BIOSen report the PC BIOS
11083 + * area (640->1Mb) as ram even though it is not.
11084 + */
11085 +- if (pagenr >= (BIOS_BEGIN >> PAGE_SHIFT) &&
11086 +- pagenr < (BIOS_END >> PAGE_SHIFT))
11087 ++ if (pagenr >= (ISA_START_ADDRESS >> PAGE_SHIFT) &&
11088 ++ pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
11089 + return 0;
11090 +
11091 + for (i = 0; i < e820.nr_map; i++) {
11092 +@@ -217,6 +217,8 @@ static void __iomem *__ioremap_caller(re
11093 + break;
11094 + }
11095 +
11096 ++ prot = canon_pgprot(prot);
11097 ++
11098 + /*
11099 + * Ok, go for it..
11100 + */
11101 +diff -urNp linux-2.6.27.10/arch/x86/mm/mmap.c linux-2.6.27.10/arch/x86/mm/mmap.c
11102 +--- linux-2.6.27.10/arch/x86/mm/mmap.c 2008-11-07 12:55:34.000000000 -0500
11103 ++++ linux-2.6.27.10/arch/x86/mm/mmap.c 2008-11-18 03:38:44.000000000 -0500
11104 +@@ -36,7 +36,7 @@
11105 + * Leave an at least ~128 MB hole.
11106 + */
11107 + #define MIN_GAP (128*1024*1024)
11108 +-#define MAX_GAP (TASK_SIZE/6*5)
11109 ++#define MAX_GAP (pax_task_size/6*5)
11110 +
11111 + /*
11112 + * True on X86_32 or when emulating IA32 on X86_64
11113 +@@ -81,27 +81,40 @@ static unsigned long mmap_rnd(void)
11114 + return rnd << PAGE_SHIFT;
11115 + }
11116 +
11117 +-static unsigned long mmap_base(void)
11118 ++static unsigned long mmap_base(struct mm_struct *mm)
11119 + {
11120 + unsigned long gap = current->signal->rlim[RLIMIT_STACK].rlim_cur;
11121 ++ unsigned long pax_task_size = TASK_SIZE;
11122 ++
11123 ++#ifdef CONFIG_PAX_SEGMEXEC
11124 ++ if (mm->pax_flags & MF_PAX_SEGMEXEC)
11125 ++ pax_task_size = SEGMEXEC_TASK_SIZE;
11126 ++#endif
11127 +
11128 + if (gap < MIN_GAP)
11129 + gap = MIN_GAP;
11130 + else if (gap > MAX_GAP)
11131 + gap = MAX_GAP;
11132 +
11133 +- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
11134 ++ return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
11135 + }
11136 +
11137 + /*
11138 + * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
11139 + * does, but not when emulating X86_32
11140 + */
11141 +-static unsigned long mmap_legacy_base(void)
11142 ++static unsigned long mmap_legacy_base(struct mm_struct *mm)
11143 + {
11144 +- if (mmap_is_ia32())
11145 ++ if (mmap_is_ia32()) {
11146 ++
11147 ++#ifdef CONFIG_PAX_SEGMEXEC
11148 ++ if (mm->pax_flags & MF_PAX_SEGMEXEC)
11149 ++ return SEGMEXEC_TASK_UNMAPPED_BASE;
11150 ++ else
11151 ++#endif
11152 ++
11153 + return TASK_UNMAPPED_BASE;
11154 +- else
11155 ++ } else
11156 + return TASK_UNMAPPED_BASE + mmap_rnd();
11157 + }
11158 +
11159 +@@ -112,11 +125,23 @@ static unsigned long mmap_legacy_base(vo
11160 + void arch_pick_mmap_layout(struct mm_struct *mm)
11161 + {
11162 + if (mmap_is_legacy()) {
11163 +- mm->mmap_base = mmap_legacy_base();
11164 ++ mm->mmap_base = mmap_legacy_base(mm);
11165 ++
11166 ++#ifdef CONFIG_PAX_RANDMMAP
11167 ++ if (mm->pax_flags & MF_PAX_RANDMMAP)
11168 ++ mm->mmap_base += mm->delta_mmap;
11169 ++#endif
11170 ++
11171 + mm->get_unmapped_area = arch_get_unmapped_area;
11172 + mm->unmap_area = arch_unmap_area;
11173 + } else {
11174 +- mm->mmap_base = mmap_base();
11175 ++ mm->mmap_base = mmap_base(mm);
11176 ++
11177 ++#ifdef CONFIG_PAX_RANDMMAP
11178 ++ if (mm->pax_flags & MF_PAX_RANDMMAP)
11179 ++ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
11180 ++#endif
11181 ++
11182 + mm->get_unmapped_area = arch_get_unmapped_area_topdown;
11183 + mm->unmap_area = arch_unmap_area_topdown;
11184 + }
11185 +diff -urNp linux-2.6.27.10/arch/x86/mm/pageattr.c linux-2.6.27.10/arch/x86/mm/pageattr.c
11186 +--- linux-2.6.27.10/arch/x86/mm/pageattr.c 2008-11-07 12:55:34.000000000 -0500
11187 ++++ linux-2.6.27.10/arch/x86/mm/pageattr.c 2008-11-18 03:38:44.000000000 -0500
11188 +@@ -20,6 +20,7 @@
11189 + #include <asm/pgalloc.h>
11190 + #include <asm/proto.h>
11191 + #include <asm/pat.h>
11192 ++#include <asm/desc.h>
11193 +
11194 + /*
11195 + * The current flushing context - we pass it instead of 5 arguments:
11196 +@@ -213,7 +214,7 @@ static inline pgprot_t static_protection
11197 + * Does not cover __inittext since that is gone later on. On
11198 + * 64bit we do not enforce !NX on the low mapping
11199 + */
11200 +- if (within(address, (unsigned long)_text, (unsigned long)_etext))
11201 ++ if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
11202 + pgprot_val(forbidden) |= _PAGE_NX;
11203 +
11204 + /*
11205 +@@ -275,8 +276,20 @@ EXPORT_SYMBOL_GPL(lookup_address);
11206 + */
11207 + static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
11208 + {
11209 ++
11210 ++#ifdef CONFIG_PAX_KERNEXEC
11211 ++ unsigned long cr0;
11212 ++
11213 ++ pax_open_kernel(cr0);
11214 ++#endif
11215 ++
11216 + /* change init_mm */
11217 + set_pte_atomic(kpte, pte);
11218 ++
11219 ++#ifdef CONFIG_PAX_KERNEXEC
11220 ++ pax_close_kernel(cr0);
11221 ++#endif
11222 ++
11223 + #ifdef CONFIG_X86_32
11224 + if (!SHARED_KERNEL_PMD) {
11225 + struct page *page;
11226 +diff -urNp linux-2.6.27.10/arch/x86/mm/pat.c linux-2.6.27.10/arch/x86/mm/pat.c
11227 +--- linux-2.6.27.10/arch/x86/mm/pat.c 2008-11-07 12:55:34.000000000 -0500
11228 ++++ linux-2.6.27.10/arch/x86/mm/pat.c 2008-11-18 03:38:44.000000000 -0500
11229 +@@ -396,7 +396,7 @@ pgprot_t phys_mem_access_prot(struct fil
11230 + return vma_prot;
11231 + }
11232 +
11233 +-#ifdef CONFIG_STRICT_DEVMEM
11234 ++#ifndef CONFIG_STRICT_DEVMEM
11235 + /* This check is done in drivers/char/mem.c in case of STRICT_DEVMEM*/
11236 + static inline int range_is_allowed(unsigned long pfn, unsigned long size)
11237 + {
11238 +diff -urNp linux-2.6.27.10/arch/x86/mm/pgtable_32.c linux-2.6.27.10/arch/x86/mm/pgtable_32.c
11239 +--- linux-2.6.27.10/arch/x86/mm/pgtable_32.c 2008-11-07 12:55:34.000000000 -0500
11240 ++++ linux-2.6.27.10/arch/x86/mm/pgtable_32.c 2008-11-18 03:38:44.000000000 -0500
11241 +@@ -31,6 +31,10 @@ void set_pte_vaddr(unsigned long vaddr,
11242 + pmd_t *pmd;
11243 + pte_t *pte;
11244 +
11245 ++#ifdef CONFIG_PAX_KERNEXEC
11246 ++ unsigned long cr0;
11247 ++#endif
11248 ++
11249 + pgd = swapper_pg_dir + pgd_index(vaddr);
11250 + if (pgd_none(*pgd)) {
11251 + BUG();
11252 +@@ -47,11 +51,20 @@ void set_pte_vaddr(unsigned long vaddr,
11253 + return;
11254 + }
11255 + pte = pte_offset_kernel(pmd, vaddr);
11256 ++
11257 ++#ifdef CONFIG_PAX_KERNEXEC
11258 ++ pax_open_kernel(cr0);
11259 ++#endif
11260 ++
11261 + if (pte_val(pteval))
11262 + set_pte_present(&init_mm, vaddr, pte, pteval);
11263 + else
11264 + pte_clear(&init_mm, vaddr, pte);
11265 +
11266 ++#ifdef CONFIG_PAX_KERNEXEC
11267 ++ pax_close_kernel(cr0);
11268 ++#endif
11269 ++
11270 + /*
11271 + * It's enough to flush this one mapping.
11272 + * (PGE mappings get flushed as well)
11273 +diff -urNp linux-2.6.27.10/arch/x86/oprofile/backtrace.c linux-2.6.27.10/arch/x86/oprofile/backtrace.c
11274 +--- linux-2.6.27.10/arch/x86/oprofile/backtrace.c 2008-11-07 12:55:34.000000000 -0500
11275 ++++ linux-2.6.27.10/arch/x86/oprofile/backtrace.c 2008-11-18 03:38:44.000000000 -0500
11276 +@@ -37,7 +37,7 @@ static void backtrace_address(void *data
11277 + unsigned int *depth = data;
11278 +
11279 + if ((*depth)--)
11280 +- oprofile_add_trace(addr);
11281 ++ oprofile_add_trace(ktla_ktva(addr));
11282 + }
11283 +
11284 + static struct stacktrace_ops backtrace_ops = {
11285 +@@ -79,7 +79,7 @@ x86_backtrace(struct pt_regs * const reg
11286 + struct frame_head *head = (struct frame_head *)frame_pointer(regs);
11287 + unsigned long stack = kernel_trap_sp(regs);
11288 +
11289 +- if (!user_mode_vm(regs)) {
11290 ++ if (!user_mode(regs)) {
11291 + if (depth)
11292 + dump_trace(NULL, regs, (unsigned long *)stack, 0,
11293 + &backtrace_ops, &depth);
11294 +diff -urNp linux-2.6.27.10/arch/x86/oprofile/op_model_p4.c linux-2.6.27.10/arch/x86/oprofile/op_model_p4.c
11295 +--- linux-2.6.27.10/arch/x86/oprofile/op_model_p4.c 2008-11-07 12:55:34.000000000 -0500
11296 ++++ linux-2.6.27.10/arch/x86/oprofile/op_model_p4.c 2008-11-18 03:38:44.000000000 -0500
11297 +@@ -47,7 +47,7 @@ static inline void setup_num_counters(vo
11298 + #endif
11299 + }
11300 +
11301 +-static int inline addr_increment(void)
11302 ++static inline int addr_increment(void)
11303 + {
11304 + #ifdef CONFIG_SMP
11305 + return smp_num_siblings == 2 ? 2 : 1;
11306 +diff -urNp linux-2.6.27.10/arch/x86/pci/common.c linux-2.6.27.10/arch/x86/pci/common.c
11307 +--- linux-2.6.27.10/arch/x86/pci/common.c 2008-11-07 12:55:34.000000000 -0500
11308 ++++ linux-2.6.27.10/arch/x86/pci/common.c 2008-11-18 03:38:44.000000000 -0500
11309 +@@ -362,7 +362,7 @@ static struct dmi_system_id __devinitdat
11310 + DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant DL585 G2"),
11311 + },
11312 + },
11313 +- {}
11314 ++ { NULL, NULL, {DMI_MATCH(DMI_NONE, NULL)}, NULL}
11315 + };
11316 +
11317 + void __init dmi_check_pciprobe(void)
11318 +diff -urNp linux-2.6.27.10/arch/x86/pci/fixup.c linux-2.6.27.10/arch/x86/pci/fixup.c
11319 +--- linux-2.6.27.10/arch/x86/pci/fixup.c 2008-11-07 12:55:34.000000000 -0500
11320 ++++ linux-2.6.27.10/arch/x86/pci/fixup.c 2008-11-18 03:38:44.000000000 -0500
11321 +@@ -365,7 +365,7 @@ static struct dmi_system_id __devinitdat
11322 + DMI_MATCH(DMI_PRODUCT_NAME, "MS-6702E"),
11323 + },
11324 + },
11325 +- {}
11326 ++ { NULL, NULL, {DMI_MATCH(DMI_NONE, NULL)}, NULL }
11327 + };
11328 +
11329 + /*
11330 +@@ -436,7 +436,7 @@ static struct dmi_system_id __devinitdat
11331 + DMI_MATCH(DMI_PRODUCT_VERSION, "PSA40U"),
11332 + },
11333 + },
11334 +- { }
11335 ++ { NULL, NULL, {DMI_MATCH(DMI_NONE, NULL)}, NULL }
11336 + };
11337 +
11338 + static void __devinit pci_pre_fixup_toshiba_ohci1394(struct pci_dev *dev)
11339 +diff -urNp linux-2.6.27.10/arch/x86/pci/irq.c linux-2.6.27.10/arch/x86/pci/irq.c
11340 +--- linux-2.6.27.10/arch/x86/pci/irq.c 2008-11-07 12:55:34.000000000 -0500
11341 ++++ linux-2.6.27.10/arch/x86/pci/irq.c 2008-11-18 03:38:44.000000000 -0500
11342 +@@ -544,7 +544,7 @@ static __init int intel_router_probe(str
11343 + static struct pci_device_id __initdata pirq_440gx[] = {
11344 + { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443GX_0) },
11345 + { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443GX_2) },
11346 +- { },
11347 ++ { PCI_DEVICE(0, 0) }
11348 + };
11349 +
11350 + /* 440GX has a proprietary PIRQ router -- don't use it */
11351 +@@ -1131,7 +1131,7 @@ static struct dmi_system_id __initdata p
11352 + DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 360"),
11353 + },
11354 + },
11355 +- { }
11356 ++ { NULL, NULL, {DMI_MATCH(DMI_NONE, NULL)}, NULL }
11357 + };
11358 +
11359 + int __init pcibios_irq_init(void)
11360 +diff -urNp linux-2.6.27.10/arch/x86/pci/pcbios.c linux-2.6.27.10/arch/x86/pci/pcbios.c
11361 +--- linux-2.6.27.10/arch/x86/pci/pcbios.c 2008-11-07 12:55:34.000000000 -0500
11362 ++++ linux-2.6.27.10/arch/x86/pci/pcbios.c 2008-11-18 03:38:44.000000000 -0500
11363 +@@ -57,50 +57,120 @@ union bios32 {
11364 + static struct {
11365 + unsigned long address;
11366 + unsigned short segment;
11367 +-} bios32_indirect = { 0, __KERNEL_CS };
11368 ++} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
11369 +
11370 + /*
11371 + * Returns the entry point for the given service, NULL on error
11372 + */
11373 +
11374 +-static unsigned long bios32_service(unsigned long service)
11375 ++static unsigned long __devinit bios32_service(unsigned long service)
11376 + {
11377 + unsigned char return_code; /* %al */
11378 + unsigned long address; /* %ebx */
11379 + unsigned long length; /* %ecx */
11380 + unsigned long entry; /* %edx */
11381 + unsigned long flags;
11382 ++ struct desc_struct d, *gdt;
11383 ++
11384 ++#ifdef CONFIG_PAX_KERNEXEC
11385 ++ unsigned long cr0;
11386 ++#endif
11387 +
11388 + local_irq_save(flags);
11389 +- __asm__("lcall *(%%edi); cld"
11390 ++
11391 ++ gdt = get_cpu_gdt_table(smp_processor_id());
11392 ++
11393 ++#ifdef CONFIG_PAX_KERNEXEC
11394 ++ pax_open_kernel(cr0);
11395 ++#endif
11396 ++
11397 ++ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
11398 ++ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
11399 ++ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
11400 ++ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
11401 ++
11402 ++#ifdef CONFIG_PAX_KERNEXEC
11403 ++ pax_close_kernel(cr0);
11404 ++#endif
11405 ++
11406 ++ __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
11407 + : "=a" (return_code),
11408 + "=b" (address),
11409 + "=c" (length),
11410 + "=d" (entry)
11411 + : "0" (service),
11412 + "1" (0),
11413 +- "D" (&bios32_indirect));
11414 ++ "D" (&bios32_indirect),
11415 ++ "r"(__PCIBIOS_DS)
11416 ++ : "memory");
11417 ++
11418 ++#ifdef CONFIG_PAX_KERNEXEC
11419 ++ pax_open_kernel(cr0);
11420 ++#endif
11421 ++
11422 ++ gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
11423 ++ gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
11424 ++ gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
11425 ++ gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
11426 ++
11427 ++#ifdef CONFIG_PAX_KERNEXEC
11428 ++ pax_close_kernel(cr0);
11429 ++#endif
11430 ++
11431 + local_irq_restore(flags);
11432 +
11433 + switch (return_code) {
11434 +- case 0:
11435 +- return address + entry;
11436 +- case 0x80: /* Not present */
11437 +- printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
11438 +- return 0;
11439 +- default: /* Shouldn't happen */
11440 +- printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
11441 +- service, return_code);
11442 ++ case 0: {
11443 ++ int cpu;
11444 ++ unsigned char flags;
11445 ++
11446 ++ printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
11447 ++ if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
11448 ++ printk(KERN_WARNING "bios32_service: not valid\n");
11449 + return 0;
11450 ++ }
11451 ++ address = address + PAGE_OFFSET;
11452 ++ length += 16UL; /* some BIOSs underreport this... */
11453 ++ flags = 4;
11454 ++ if (length >= 64*1024*1024) {
11455 ++ length >>= PAGE_SHIFT;
11456 ++ flags |= 8;
11457 ++ }
11458 ++
11459 ++#ifdef CONFIG_PAX_KERNEXEC
11460 ++ pax_open_kernel(cr0);
11461 ++#endif
11462 ++
11463 ++ for (cpu = 0; cpu < NR_CPUS; cpu++) {
11464 ++ gdt = get_cpu_gdt_table(cpu);
11465 ++ pack_descriptor(&d, address, length, 0x9b, flags);
11466 ++ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
11467 ++ pack_descriptor(&d, address, length, 0x93, flags);
11468 ++ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
11469 ++ }
11470 ++
11471 ++#ifdef CONFIG_PAX_KERNEXEC
11472 ++ pax_close_kernel(cr0);
11473 ++#endif
11474 ++
11475 ++ return entry;
11476 ++ }
11477 ++ case 0x80: /* Not present */
11478 ++ printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
11479 ++ return 0;
11480 ++ default: /* Shouldn't happen */
11481 ++ printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
11482 ++ service, return_code);
11483 ++ return 0;
11484 + }
11485 + }
11486 +
11487 + static struct {
11488 + unsigned long address;
11489 + unsigned short segment;
11490 +-} pci_indirect = { 0, __KERNEL_CS };
11491 ++} pci_indirect __read_only = { 0, __PCIBIOS_CS };
11492 +
11493 +-static int pci_bios_present;
11494 ++static int pci_bios_present __read_only;
11495 +
11496 + static int __devinit check_pcibios(void)
11497 + {
11498 +@@ -109,11 +179,13 @@ static int __devinit check_pcibios(void)
11499 + unsigned long flags, pcibios_entry;
11500 +
11501 + if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
11502 +- pci_indirect.address = pcibios_entry + PAGE_OFFSET;
11503 ++ pci_indirect.address = pcibios_entry;
11504 +
11505 + local_irq_save(flags);
11506 +- __asm__(
11507 +- "lcall *(%%edi); cld\n\t"
11508 ++ __asm__("movw %w6, %%ds\n\t"
11509 ++ "lcall *%%ss:(%%edi); cld\n\t"
11510 ++ "push %%ss\n\t"
11511 ++ "pop %%ds\n\t"
11512 + "jc 1f\n\t"
11513 + "xor %%ah, %%ah\n"
11514 + "1:"
11515 +@@ -122,7 +194,8 @@ static int __devinit check_pcibios(void)
11516 + "=b" (ebx),
11517 + "=c" (ecx)
11518 + : "1" (PCIBIOS_PCI_BIOS_PRESENT),
11519 +- "D" (&pci_indirect)
11520 ++ "D" (&pci_indirect),
11521 ++ "r" (__PCIBIOS_DS)
11522 + : "memory");
11523 + local_irq_restore(flags);
11524 +
11525 +@@ -166,7 +239,10 @@ static int pci_bios_read(unsigned int se
11526 +
11527 + switch (len) {
11528 + case 1:
11529 +- __asm__("lcall *(%%esi); cld\n\t"
11530 ++ __asm__("movw %w6, %%ds\n\t"
11531 ++ "lcall *%%ss:(%%esi); cld\n\t"
11532 ++ "push %%ss\n\t"
11533 ++ "pop %%ds\n\t"
11534 + "jc 1f\n\t"
11535 + "xor %%ah, %%ah\n"
11536 + "1:"
11537 +@@ -175,7 +251,8 @@ static int pci_bios_read(unsigned int se
11538 + : "1" (PCIBIOS_READ_CONFIG_BYTE),
11539 + "b" (bx),
11540 + "D" ((long)reg),
11541 +- "S" (&pci_indirect));
11542 ++ "S" (&pci_indirect),
11543 ++ "r" (__PCIBIOS_DS));
11544 + /*
11545 + * Zero-extend the result beyond 8 bits, do not trust the
11546 + * BIOS having done it:
11547 +@@ -183,7 +260,10 @@ static int pci_bios_read(unsigned int se
11548 + *value &= 0xff;
11549 + break;
11550 + case 2:
11551 +- __asm__("lcall *(%%esi); cld\n\t"
11552 ++ __asm__("movw %w6, %%ds\n\t"
11553 ++ "lcall *%%ss:(%%esi); cld\n\t"
11554 ++ "push %%ss\n\t"
11555 ++ "pop %%ds\n\t"
11556 + "jc 1f\n\t"
11557 + "xor %%ah, %%ah\n"
11558 + "1:"
11559 +@@ -192,7 +272,8 @@ static int pci_bios_read(unsigned int se
11560 + : "1" (PCIBIOS_READ_CONFIG_WORD),
11561 + "b" (bx),
11562 + "D" ((long)reg),
11563 +- "S" (&pci_indirect));
11564 ++ "S" (&pci_indirect),
11565 ++ "r" (__PCIBIOS_DS));
11566 + /*
11567 + * Zero-extend the result beyond 16 bits, do not trust the
11568 + * BIOS having done it:
11569 +@@ -200,7 +281,10 @@ static int pci_bios_read(unsigned int se
11570 + *value &= 0xffff;
11571 + break;
11572 + case 4:
11573 +- __asm__("lcall *(%%esi); cld\n\t"
11574 ++ __asm__("movw %w6, %%ds\n\t"
11575 ++ "lcall *%%ss:(%%esi); cld\n\t"
11576 ++ "push %%ss\n\t"
11577 ++ "pop %%ds\n\t"
11578 + "jc 1f\n\t"
11579 + "xor %%ah, %%ah\n"
11580 + "1:"
11581 +@@ -209,7 +293,8 @@ static int pci_bios_read(unsigned int se
11582 + : "1" (PCIBIOS_READ_CONFIG_DWORD),
11583 + "b" (bx),
11584 + "D" ((long)reg),
11585 +- "S" (&pci_indirect));
11586 ++ "S" (&pci_indirect),
11587 ++ "r" (__PCIBIOS_DS));
11588 + break;
11589 + }
11590 +
11591 +@@ -232,7 +317,10 @@ static int pci_bios_write(unsigned int s
11592 +
11593 + switch (len) {
11594 + case 1:
11595 +- __asm__("lcall *(%%esi); cld\n\t"
11596 ++ __asm__("movw %w6, %%ds\n\t"
11597 ++ "lcall *%%ss:(%%esi); cld\n\t"
11598 ++ "push %%ss\n\t"
11599 ++ "pop %%ds\n\t"
11600 + "jc 1f\n\t"
11601 + "xor %%ah, %%ah\n"
11602 + "1:"
11603 +@@ -241,10 +329,14 @@ static int pci_bios_write(unsigned int s
11604 + "c" (value),
11605 + "b" (bx),
11606 + "D" ((long)reg),
11607 +- "S" (&pci_indirect));
11608 ++ "S" (&pci_indirect),
11609 ++ "r" (__PCIBIOS_DS));
11610 + break;
11611 + case 2:
11612 +- __asm__("lcall *(%%esi); cld\n\t"
11613 ++ __asm__("movw %w6, %%ds\n\t"
11614 ++ "lcall *%%ss:(%%esi); cld\n\t"
11615 ++ "push %%ss\n\t"
11616 ++ "pop %%ds\n\t"
11617 + "jc 1f\n\t"
11618 + "xor %%ah, %%ah\n"
11619 + "1:"
11620 +@@ -253,10 +345,14 @@ static int pci_bios_write(unsigned int s
11621 + "c" (value),
11622 + "b" (bx),
11623 + "D" ((long)reg),
11624 +- "S" (&pci_indirect));
11625 ++ "S" (&pci_indirect),
11626 ++ "r" (__PCIBIOS_DS));
11627 + break;
11628 + case 4:
11629 +- __asm__("lcall *(%%esi); cld\n\t"
11630 ++ __asm__("movw %w6, %%ds\n\t"
11631 ++ "lcall *%%ss:(%%esi); cld\n\t"
11632 ++ "push %%ss\n\t"
11633 ++ "pop %%ds\n\t"
11634 + "jc 1f\n\t"
11635 + "xor %%ah, %%ah\n"
11636 + "1:"
11637 +@@ -265,7 +361,8 @@ static int pci_bios_write(unsigned int s
11638 + "c" (value),
11639 + "b" (bx),
11640 + "D" ((long)reg),
11641 +- "S" (&pci_indirect));
11642 ++ "S" (&pci_indirect),
11643 ++ "r" (__PCIBIOS_DS));
11644 + break;
11645 + }
11646 +
11647 +@@ -369,10 +466,13 @@ struct irq_routing_table * pcibios_get_i
11648 +
11649 + DBG("PCI: Fetching IRQ routing table... ");
11650 + __asm__("push %%es\n\t"
11651 ++ "movw %w8, %%ds\n\t"
11652 + "push %%ds\n\t"
11653 + "pop %%es\n\t"
11654 +- "lcall *(%%esi); cld\n\t"
11655 ++ "lcall *%%ss:(%%esi); cld\n\t"
11656 + "pop %%es\n\t"
11657 ++ "push %%ss\n\t"
11658 ++ "pop %%ds\n"
11659 + "jc 1f\n\t"
11660 + "xor %%ah, %%ah\n"
11661 + "1:"
11662 +@@ -383,7 +483,8 @@ struct irq_routing_table * pcibios_get_i
11663 + "1" (0),
11664 + "D" ((long) &opt),
11665 + "S" (&pci_indirect),
11666 +- "m" (opt)
11667 ++ "m" (opt),
11668 ++ "r" (__PCIBIOS_DS)
11669 + : "memory");
11670 + DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
11671 + if (ret & 0xff00)
11672 +@@ -407,7 +508,10 @@ int pcibios_set_irq_routing(struct pci_d
11673 + {
11674 + int ret;
11675 +
11676 +- __asm__("lcall *(%%esi); cld\n\t"
11677 ++ __asm__("movw %w5, %%ds\n\t"
11678 ++ "lcall *%%ss:(%%esi); cld\n\t"
11679 ++ "push %%ss\n\t"
11680 ++ "pop %%ds\n"
11681 + "jc 1f\n\t"
11682 + "xor %%ah, %%ah\n"
11683 + "1:"
11684 +@@ -415,7 +519,8 @@ int pcibios_set_irq_routing(struct pci_d
11685 + : "0" (PCIBIOS_SET_PCI_HW_INT),
11686 + "b" ((dev->bus->number << 8) | dev->devfn),
11687 + "c" ((irq << 8) | (pin + 10)),
11688 +- "S" (&pci_indirect));
11689 ++ "S" (&pci_indirect),
11690 ++ "r" (__PCIBIOS_DS));
11691 + return !(ret & 0xff00);
11692 + }
11693 + EXPORT_SYMBOL(pcibios_set_irq_routing);
11694 +diff -urNp linux-2.6.27.10/arch/x86/power/cpu_32.c linux-2.6.27.10/arch/x86/power/cpu_32.c
11695 +--- linux-2.6.27.10/arch/x86/power/cpu_32.c 2008-11-07 12:55:34.000000000 -0500
11696 ++++ linux-2.6.27.10/arch/x86/power/cpu_32.c 2008-11-18 03:38:44.000000000 -0500
11697 +@@ -66,7 +66,7 @@ static void do_fpu_end(void)
11698 + static void fix_processor_context(void)
11699 + {
11700 + int cpu = smp_processor_id();
11701 +- struct tss_struct *t = &per_cpu(init_tss, cpu);
11702 ++ struct tss_struct *t = init_tss + cpu;
11703 +
11704 + set_tss_desc(cpu, t); /*
11705 + * This just modifies memory; should not be
11706 +diff -urNp linux-2.6.27.10/arch/x86/power/cpu_64.c linux-2.6.27.10/arch/x86/power/cpu_64.c
11707 +--- linux-2.6.27.10/arch/x86/power/cpu_64.c 2008-11-07 12:55:34.000000000 -0500
11708 ++++ linux-2.6.27.10/arch/x86/power/cpu_64.c 2008-11-18 03:38:44.000000000 -0500
11709 +@@ -136,7 +136,11 @@ void restore_processor_state(void)
11710 + static void fix_processor_context(void)
11711 + {
11712 + int cpu = smp_processor_id();
11713 +- struct tss_struct *t = &per_cpu(init_tss, cpu);
11714 ++ struct tss_struct *t = init_tss + cpu;
11715 ++
11716 ++#ifdef CONFIG_PAX_KERNEXEC
11717 ++ unsigned long cr0;
11718 ++#endif
11719 +
11720 + /*
11721 + * This just modifies memory; should not be necessary. But... This
11722 +@@ -145,8 +149,16 @@ static void fix_processor_context(void)
11723 + */
11724 + set_tss_desc(cpu, t);
11725 +
11726 ++#ifdef CONFIG_PAX_KERNEXEC
11727 ++ pax_open_kernel(cr0);
11728 ++#endif
11729 ++
11730 + get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
11731 +
11732 ++#ifdef CONFIG_PAX_KERNEXEC
11733 ++ pax_close_kernel(cr0);
11734 ++#endif
11735 ++
11736 + syscall_init(); /* This sets MSR_*STAR and related */
11737 + load_TR_desc(); /* This does ltr */
11738 + load_LDT(&current->active_mm->context); /* This does lldt */
11739 +diff -urNp linux-2.6.27.10/arch/x86/vdso/vdso32-setup.c linux-2.6.27.10/arch/x86/vdso/vdso32-setup.c
11740 +--- linux-2.6.27.10/arch/x86/vdso/vdso32-setup.c 2008-11-07 12:55:34.000000000 -0500
11741 ++++ linux-2.6.27.10/arch/x86/vdso/vdso32-setup.c 2008-11-18 03:38:44.000000000 -0500
11742 +@@ -226,7 +226,7 @@ static inline void map_compat_vdso(int m
11743 + void enable_sep_cpu(void)
11744 + {
11745 + int cpu = get_cpu();
11746 +- struct tss_struct *tss = &per_cpu(init_tss, cpu);
11747 ++ struct tss_struct *tss = init_tss + cpu;
11748 +
11749 + if (!boot_cpu_has(X86_FEATURE_SEP)) {
11750 + put_cpu();
11751 +@@ -249,7 +249,7 @@ static int __init gate_vma_init(void)
11752 + gate_vma.vm_start = FIXADDR_USER_START;
11753 + gate_vma.vm_end = FIXADDR_USER_END;
11754 + gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
11755 +- gate_vma.vm_page_prot = __P101;
11756 ++ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
11757 + /*
11758 + * Make sure the vDSO gets into every core dump.
11759 + * Dumping its contents makes post-mortem fully interpretable later
11760 +@@ -331,7 +331,7 @@ int arch_setup_additional_pages(struct l
11761 + if (compat)
11762 + addr = VDSO_HIGH_BASE;
11763 + else {
11764 +- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
11765 ++ addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
11766 + if (IS_ERR_VALUE(addr)) {
11767 + ret = addr;
11768 + goto up_fail;
11769 +@@ -358,7 +358,7 @@ int arch_setup_additional_pages(struct l
11770 + goto up_fail;
11771 + }
11772 +
11773 +- current->mm->context.vdso = (void *)addr;
11774 ++ current->mm->context.vdso = addr;
11775 + current_thread_info()->sysenter_return =
11776 + VDSO32_SYMBOL(addr, SYSENTER_RETURN);
11777 +
11778 +@@ -384,7 +384,7 @@ static ctl_table abi_table2[] = {
11779 + .mode = 0644,
11780 + .proc_handler = proc_dointvec
11781 + },
11782 +- {}
11783 ++ { 0, NULL, NULL, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL }
11784 + };
11785 +
11786 + static ctl_table abi_root_table2[] = {
11787 +@@ -394,7 +394,7 @@ static ctl_table abi_root_table2[] = {
11788 + .mode = 0555,
11789 + .child = abi_table2
11790 + },
11791 +- {}
11792 ++ { 0, NULL, NULL, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL }
11793 + };
11794 +
11795 + static __init int ia32_binfmt_init(void)
11796 +@@ -409,8 +409,14 @@ __initcall(ia32_binfmt_init);
11797 +
11798 + const char *arch_vma_name(struct vm_area_struct *vma)
11799 + {
11800 +- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
11801 ++ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
11802 + return "[vdso]";
11803 ++
11804 ++#ifdef CONFIG_PAX_SEGMEXEC
11805 ++ if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
11806 ++ return "[vdso]";
11807 ++#endif
11808 ++
11809 + return NULL;
11810 + }
11811 +
11812 +@@ -419,7 +425,7 @@ struct vm_area_struct *get_gate_vma(stru
11813 + struct mm_struct *mm = tsk->mm;
11814 +
11815 + /* Check to see if this task was created in compat vdso mode */
11816 +- if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
11817 ++ if (mm && mm->context.vdso == VDSO_HIGH_BASE)
11818 + return &gate_vma;
11819 + return NULL;
11820 + }
11821 +diff -urNp linux-2.6.27.10/arch/x86/vdso/vma.c linux-2.6.27.10/arch/x86/vdso/vma.c
11822 +--- linux-2.6.27.10/arch/x86/vdso/vma.c 2008-11-07 12:55:34.000000000 -0500
11823 ++++ linux-2.6.27.10/arch/x86/vdso/vma.c 2008-11-18 03:38:44.000000000 -0500
11824 +@@ -123,7 +123,7 @@ int arch_setup_additional_pages(struct l
11825 + if (ret)
11826 + goto up_fail;
11827 +
11828 +- current->mm->context.vdso = (void *)addr;
11829 ++ current->mm->context.vdso = addr;
11830 + up_fail:
11831 + up_write(&mm->mmap_sem);
11832 + return ret;
11833 +diff -urNp linux-2.6.27.10/arch/x86/xen/enlighten.c linux-2.6.27.10/arch/x86/xen/enlighten.c
11834 +--- linux-2.6.27.10/arch/x86/xen/enlighten.c 2008-12-10 22:35:37.000000000 -0500
11835 ++++ linux-2.6.27.10/arch/x86/xen/enlighten.c 2008-12-10 22:35:46.000000000 -0500
11836 +@@ -343,7 +343,7 @@ static void xen_set_ldt(const void *addr
11837 + static void xen_load_gdt(const struct desc_ptr *dtr)
11838 + {
11839 + unsigned long *frames;
11840 +- unsigned long va = dtr->address;
11841 ++ unsigned long va = (unsigned long)dtr->address;
11842 + unsigned int size = dtr->size + 1;
11843 + unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
11844 + int f;
11845 +@@ -358,7 +358,7 @@ static void xen_load_gdt(const struct de
11846 + mcs = xen_mc_entry(sizeof(*frames) * pages);
11847 + frames = mcs.args;
11848 +
11849 +- for (f = 0; va < dtr->address + size; va += PAGE_SIZE, f++) {
11850 ++ for (f = 0; va < (unsigned long)dtr->address + size; va += PAGE_SIZE, f++) {
11851 + frames[f] = virt_to_mfn(va);
11852 + make_lowmem_page_readonly((void *)va);
11853 + }
11854 +@@ -467,7 +467,7 @@ static void xen_write_idt_entry(gate_des
11855 +
11856 + preempt_disable();
11857 +
11858 +- start = __get_cpu_var(idt_desc).address;
11859 ++ start = (unsigned long)__get_cpu_var(idt_desc).address;
11860 + end = start + __get_cpu_var(idt_desc).size + 1;
11861 +
11862 + xen_mc_flush();
11863 +@@ -1574,6 +1574,8 @@ static __init pgd_t *xen_setup_kernel_pa
11864 + convert_pfn_mfn(init_level4_pgt);
11865 + convert_pfn_mfn(level3_ident_pgt);
11866 + convert_pfn_mfn(level3_kernel_pgt);
11867 ++ convert_pfn_mfn(level3_vmalloc_pgt);
11868 ++ convert_pfn_mfn(level3_vmemmap_pgt);
11869 +
11870 + l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
11871 + l2 = m2v(l3[pud_index(__START_KERNEL_map)].pud);
11872 +@@ -1592,9 +1594,12 @@ static __init pgd_t *xen_setup_kernel_pa
11873 + set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
11874 + set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
11875 + set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
11876 ++ set_page_prot(level3_vmalloc_pgt, PAGE_KERNEL_RO);
11877 ++ set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
11878 + set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
11879 + set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
11880 + set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
11881 ++ set_page_prot(level1_fixmap_pgt, PAGE_KERNEL_RO);
11882 +
11883 + /* Pin down new L4 */
11884 + pin_pagetable_pfn(MMUEXT_PIN_L4_TABLE,
11885 +diff -urNp linux-2.6.27.10/arch/x86/xen/smp.c linux-2.6.27.10/arch/x86/xen/smp.c
11886 +--- linux-2.6.27.10/arch/x86/xen/smp.c 2008-11-07 12:55:34.000000000 -0500
11887 ++++ linux-2.6.27.10/arch/x86/xen/smp.c 2008-11-18 03:38:44.000000000 -0500
11888 +@@ -170,11 +170,6 @@ static void __init xen_smp_prepare_boot_
11889 + {
11890 + BUG_ON(smp_processor_id() != 0);
11891 + native_smp_prepare_boot_cpu();
11892 +-
11893 +- /* We've switched to the "real" per-cpu gdt, so make sure the
11894 +- old memory can be recycled */
11895 +- make_lowmem_page_readwrite(&per_cpu_var(gdt_page));
11896 +-
11897 + xen_setup_vcpu_info_placement();
11898 + }
11899 +
11900 +@@ -232,8 +227,8 @@ cpu_initialize_context(unsigned int cpu,
11901 + gdt = get_cpu_gdt_table(cpu);
11902 +
11903 + ctxt->flags = VGCF_IN_KERNEL;
11904 +- ctxt->user_regs.ds = __USER_DS;
11905 +- ctxt->user_regs.es = __USER_DS;
11906 ++ ctxt->user_regs.ds = __KERNEL_DS;
11907 ++ ctxt->user_regs.es = __KERNEL_DS;
11908 + ctxt->user_regs.ss = __KERNEL_DS;
11909 + #ifdef CONFIG_X86_32
11910 + ctxt->user_regs.fs = __KERNEL_PERCPU;
11911 +diff -urNp linux-2.6.27.10/crypto/async_tx/async_tx.c linux-2.6.27.10/crypto/async_tx/async_tx.c
11912 +--- linux-2.6.27.10/crypto/async_tx/async_tx.c 2008-11-07 12:55:34.000000000 -0500
11913 ++++ linux-2.6.27.10/crypto/async_tx/async_tx.c 2008-11-18 03:38:44.000000000 -0500
11914 +@@ -358,8 +358,8 @@ async_tx_init(void)
11915 + err:
11916 + printk(KERN_ERR "async_tx: initialization failure\n");
11917 +
11918 +- while (--cap >= 0)
11919 +- free_percpu(channel_table[cap]);
11920 ++ while (cap)
11921 ++ free_percpu(channel_table[--cap]);
11922 +
11923 + return 1;
11924 + }
11925 +diff -urNp linux-2.6.27.10/crypto/lrw.c linux-2.6.27.10/crypto/lrw.c
11926 +--- linux-2.6.27.10/crypto/lrw.c 2008-11-07 12:55:34.000000000 -0500
11927 ++++ linux-2.6.27.10/crypto/lrw.c 2008-11-18 03:38:44.000000000 -0500
11928 +@@ -54,7 +54,7 @@ static int setkey(struct crypto_tfm *par
11929 + struct priv *ctx = crypto_tfm_ctx(parent);
11930 + struct crypto_cipher *child = ctx->child;
11931 + int err, i;
11932 +- be128 tmp = { 0 };
11933 ++ be128 tmp = { 0, 0 };
11934 + int bsize = crypto_cipher_blocksize(child);
11935 +
11936 + crypto_cipher_clear_flags(child, CRYPTO_TFM_REQ_MASK);
11937 +diff -urNp linux-2.6.27.10/Documentation/dontdiff linux-2.6.27.10/Documentation/dontdiff
11938 +--- linux-2.6.27.10/Documentation/dontdiff 2008-11-07 12:55:34.000000000 -0500
11939 ++++ linux-2.6.27.10/Documentation/dontdiff 2008-11-18 03:39:50.000000000 -0500
11940 +@@ -3,6 +3,7 @@
11941 + *.bin
11942 + *.cpio
11943 + *.css
11944 ++*.dbg
11945 + *.dvi
11946 + *.eps
11947 + *.fw.gen.S
11948 +@@ -53,9 +54,14 @@ COPYING
11949 + CREDITS
11950 + CVS
11951 + ChangeSet
11952 ++GPATH
11953 ++GRTAGS
11954 ++GSYMS
11955 ++GTAGS
11956 + Image
11957 + Kerntypes
11958 + MODS.txt
11959 ++Module.markers
11960 + Module.symvers
11961 + PENDING
11962 + SCCS
11963 +@@ -66,7 +72,6 @@ aic7*reg_print.c*
11964 + aic7*seq.h*
11965 + aicasm
11966 + aicdb.h*
11967 +-asm
11968 + asm-offsets.h
11969 + asm_offsets.h
11970 + autoconf.h*
11971 +@@ -74,6 +79,7 @@ bbootsect
11972 + bin2c
11973 + binkernel.spec
11974 + bootsect
11975 ++bounds.h
11976 + bsetup
11977 + btfixupprep
11978 + build
11979 +@@ -90,6 +96,7 @@ config_data.gz*
11980 + conmakehash
11981 + consolemap_deftbl.c*
11982 + crc32table.h*
11983 ++cpustr.h
11984 + cscope.*
11985 + defkeymap.c*
11986 + devlist.h*
11987 +@@ -138,6 +145,7 @@ miboot*
11988 + mk_elfconfig
11989 + mkboot
11990 + mkbugboot
11991 ++mkcpustr
11992 + mkdep
11993 + mkprep
11994 + mktables
11995 +@@ -179,16 +187,21 @@ times.h*
11996 + tkparse
11997 + trix_boot.h
11998 + utsrelease.h*
11999 +-vdso.lds
12000 ++vdso*.lds
12001 + version.h*
12002 + vmlinux
12003 + vmlinux-*
12004 + vmlinux.aout
12005 +-vmlinux*.lds*
12006 ++vmlinux.bin.all
12007 ++vmlinux*.lds
12008 ++vmlinux.relocs
12009 + vmlinux*.scr
12010 +-vsyscall.lds
12011 ++vsyscall*.lds
12012 ++wakeup.elf
12013 ++wakeup.lds
12014 + wanxlfw.inc
12015 + uImage
12016 + unifdef
12017 ++utsrelease.h
12018 + zImage*
12019 + zconf.hash.c
12020 +diff -urNp linux-2.6.27.10/drivers/acpi/blacklist.c linux-2.6.27.10/drivers/acpi/blacklist.c
12021 +--- linux-2.6.27.10/drivers/acpi/blacklist.c 2008-11-07 12:55:34.000000000 -0500
12022 ++++ linux-2.6.27.10/drivers/acpi/blacklist.c 2008-11-18 03:38:44.000000000 -0500
12023 +@@ -71,7 +71,7 @@ static struct acpi_blacklist_item acpi_b
12024 + {"IBM ", "TP600E ", 0x00000105, ACPI_SIG_DSDT, less_than_or_equal,
12025 + "Incorrect _ADR", 1},
12026 +
12027 +- {""}
12028 ++ {"", "", 0, 0, 0, all_versions, 0}
12029 + };
12030 +
12031 + #if CONFIG_ACPI_BLACKLIST_YEAR
12032 +diff -urNp linux-2.6.27.10/drivers/acpi/osl.c linux-2.6.27.10/drivers/acpi/osl.c
12033 +--- linux-2.6.27.10/drivers/acpi/osl.c 2008-12-21 01:16:51.000000000 -0500
12034 ++++ linux-2.6.27.10/drivers/acpi/osl.c 2008-12-21 01:13:45.000000000 -0500
12035 +@@ -494,6 +494,8 @@ acpi_os_read_memory(acpi_physical_addres
12036 + void __iomem *virt_addr;
12037 +
12038 + virt_addr = ioremap(phys_addr, width);
12039 ++ if (!virt_addr)
12040 ++ return AE_NO_MEMORY;
12041 + if (!value)
12042 + value = &dummy;
12043 +
12044 +@@ -522,6 +524,8 @@ acpi_os_write_memory(acpi_physical_addre
12045 + void __iomem *virt_addr;
12046 +
12047 + virt_addr = ioremap(phys_addr, width);
12048 ++ if (!virt_addr)
12049 ++ return AE_NO_MEMORY;
12050 +
12051 + switch (width) {
12052 + case 8:
12053 +diff -urNp linux-2.6.27.10/drivers/acpi/processor_core.c linux-2.6.27.10/drivers/acpi/processor_core.c
12054 +--- linux-2.6.27.10/drivers/acpi/processor_core.c 2008-11-07 12:55:34.000000000 -0500
12055 ++++ linux-2.6.27.10/drivers/acpi/processor_core.c 2008-11-18 03:38:44.000000000 -0500
12056 +@@ -667,7 +667,7 @@ static int __cpuinit acpi_processor_star
12057 + return 0;
12058 + }
12059 +
12060 +- BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
12061 ++ BUG_ON(pr->id >= nr_cpu_ids);
12062 +
12063 + /*
12064 + * Buggy BIOS check
12065 +diff -urNp linux-2.6.27.10/drivers/acpi/processor_idle.c linux-2.6.27.10/drivers/acpi/processor_idle.c
12066 +--- linux-2.6.27.10/drivers/acpi/processor_idle.c 2008-11-07 12:55:34.000000000 -0500
12067 ++++ linux-2.6.27.10/drivers/acpi/processor_idle.c 2008-11-18 03:38:44.000000000 -0500
12068 +@@ -182,7 +182,7 @@ static struct dmi_system_id __cpuinitdat
12069 + DMI_MATCH(DMI_BIOS_VENDOR,"Phoenix Technologies LTD"),
12070 + DMI_MATCH(DMI_BIOS_VERSION,"SHE845M0.86C.0013.D.0302131307")},
12071 + (void *)2},
12072 +- {},
12073 ++ { NULL, NULL, {DMI_MATCH(DMI_NONE, NULL)}, NULL},
12074 + };
12075 +
12076 + static inline u32 ticks_elapsed(u32 t1, u32 t2)
12077 +diff -urNp linux-2.6.27.10/drivers/acpi/tables/tbfadt.c linux-2.6.27.10/drivers/acpi/tables/tbfadt.c
12078 +--- linux-2.6.27.10/drivers/acpi/tables/tbfadt.c 2008-11-07 12:55:34.000000000 -0500
12079 ++++ linux-2.6.27.10/drivers/acpi/tables/tbfadt.c 2008-11-18 03:38:44.000000000 -0500
12080 +@@ -48,7 +48,7 @@
12081 + ACPI_MODULE_NAME("tbfadt")
12082 +
12083 + /* Local prototypes */
12084 +-static void inline
12085 ++static inline void
12086 + acpi_tb_init_generic_address(struct acpi_generic_address *generic_address,
12087 + u8 bit_width, u64 address);
12088 +
12089 +@@ -122,7 +122,7 @@ static struct acpi_fadt_info fadt_info_t
12090 + *
12091 + ******************************************************************************/
12092 +
12093 +-static void inline
12094 ++static inline void
12095 + acpi_tb_init_generic_address(struct acpi_generic_address *generic_address,
12096 + u8 bit_width, u64 address)
12097 + {
12098 +diff -urNp linux-2.6.27.10/drivers/ata/ahci.c linux-2.6.27.10/drivers/ata/ahci.c
12099 +--- linux-2.6.27.10/drivers/ata/ahci.c 2008-11-07 12:55:34.000000000 -0500
12100 ++++ linux-2.6.27.10/drivers/ata/ahci.c 2008-11-18 03:38:44.000000000 -0500
12101 +@@ -591,7 +591,7 @@ static const struct pci_device_id ahci_p
12102 + { PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
12103 + PCI_CLASS_STORAGE_SATA_AHCI, 0xffffff, board_ahci },
12104 +
12105 +- { } /* terminate list */
12106 ++ { 0, 0, 0, 0, 0, 0, 0 } /* terminate list */
12107 + };
12108 +
12109 +
12110 +diff -urNp linux-2.6.27.10/drivers/ata/ata_piix.c linux-2.6.27.10/drivers/ata/ata_piix.c
12111 +--- linux-2.6.27.10/drivers/ata/ata_piix.c 2008-11-07 12:55:34.000000000 -0500
12112 ++++ linux-2.6.27.10/drivers/ata/ata_piix.c 2008-11-18 03:38:44.000000000 -0500
12113 +@@ -284,7 +284,7 @@ static const struct pci_device_id piix_p
12114 + /* SATA Controller IDE (PCH) */
12115 + { 0x8086, 0x3b2e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_sata },
12116 +
12117 +- { } /* terminate list */
12118 ++ { 0, 0, 0, 0, 0, 0, 0 } /* terminate list */
12119 + };
12120 +
12121 + static struct pci_driver piix_pci_driver = {
12122 +@@ -587,7 +587,7 @@ static const struct ich_laptop ich_lapto
12123 + { 0x266F, 0x1025, 0x0066 }, /* ICH6 on ACER Aspire 1694WLMi */
12124 + { 0x2653, 0x1043, 0x82D8 }, /* ICH6M on Asus Eee 701 */
12125 + /* end marker */
12126 +- { 0, }
12127 ++ { 0, 0, 0 }
12128 + };
12129 +
12130 + /**
12131 +@@ -1143,7 +1143,7 @@ static int piix_broken_suspend(void)
12132 + },
12133 + },
12134 +
12135 +- { } /* terminate list */
12136 ++ { NULL, NULL, {DMI_MATCH(DMI_NONE, NULL)}, NULL } /* terminate list */
12137 + };
12138 + static const char *oemstrs[] = {
12139 + "Tecra M3,",
12140 +diff -urNp linux-2.6.27.10/drivers/ata/libata-core.c linux-2.6.27.10/drivers/ata/libata-core.c
12141 +--- linux-2.6.27.10/drivers/ata/libata-core.c 2008-12-21 01:18:11.000000000 -0500
12142 ++++ linux-2.6.27.10/drivers/ata/libata-core.c 2008-12-21 01:18:21.000000000 -0500
12143 +@@ -746,7 +746,7 @@ static const struct ata_xfer_ent {
12144 + { ATA_SHIFT_PIO, ATA_NR_PIO_MODES, XFER_PIO_0 },
12145 + { ATA_SHIFT_MWDMA, ATA_NR_MWDMA_MODES, XFER_MW_DMA_0 },
12146 + { ATA_SHIFT_UDMA, ATA_NR_UDMA_MODES, XFER_UDMA_0 },
12147 +- { -1, },
12148 ++ { -1, 0, 0 }
12149 + };
12150 +
12151 + /**
12152 +@@ -2917,7 +2917,7 @@ static const struct ata_timing ata_timin
12153 + { XFER_UDMA_5, 0, 0, 0, 0, 0, 0, 0, 20 },
12154 + { XFER_UDMA_6, 0, 0, 0, 0, 0, 0, 0, 15 },
12155 +
12156 +- { 0xFF }
12157 ++ { 0xFF, 0, 0, 0, 0, 0, 0, 0, 0 }
12158 + };
12159 +
12160 + #define ENOUGH(v, unit) (((v)-1)/(unit)+1)
12161 +@@ -4073,7 +4073,7 @@ static const struct ata_blacklist_entry
12162 + { "TSSTcorp CDDVDW SH-S202N", "SB01", ATA_HORKAGE_IVB, },
12163 +
12164 + /* End Marker */
12165 +- { }
12166 ++ { NULL, NULL, 0 }
12167 + };
12168 +
12169 + static int strn_pattern_cmp(const char *patt, const char *name, int wildchar)
12170 +diff -urNp linux-2.6.27.10/drivers/char/agp/frontend.c linux-2.6.27.10/drivers/char/agp/frontend.c
12171 +--- linux-2.6.27.10/drivers/char/agp/frontend.c 2008-11-07 12:55:34.000000000 -0500
12172 ++++ linux-2.6.27.10/drivers/char/agp/frontend.c 2008-11-18 03:38:44.000000000 -0500
12173 +@@ -824,7 +824,7 @@ static int agpioc_reserve_wrap(struct ag
12174 + if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
12175 + return -EFAULT;
12176 +
12177 +- if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
12178 ++ if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
12179 + return -EFAULT;
12180 +
12181 + client = agp_find_client_by_pid(reserve.pid);
12182 +diff -urNp linux-2.6.27.10/drivers/char/agp/intel-agp.c linux-2.6.27.10/drivers/char/agp/intel-agp.c
12183 +--- linux-2.6.27.10/drivers/char/agp/intel-agp.c 2008-11-07 12:55:34.000000000 -0500
12184 ++++ linux-2.6.27.10/drivers/char/agp/intel-agp.c 2008-11-18 03:38:44.000000000 -0500
12185 +@@ -2332,7 +2332,7 @@ static struct pci_device_id agp_intel_pc
12186 + ID(PCI_DEVICE_ID_INTEL_IGD_E_HB),
12187 + ID(PCI_DEVICE_ID_INTEL_Q45_HB),
12188 + ID(PCI_DEVICE_ID_INTEL_G45_HB),
12189 +- { }
12190 ++ { 0, 0, 0, 0, 0, 0, 0 }
12191 + };
12192 +
12193 + MODULE_DEVICE_TABLE(pci, agp_intel_pci_table);
12194 +diff -urNp linux-2.6.27.10/drivers/char/hpet.c linux-2.6.27.10/drivers/char/hpet.c
12195 +--- linux-2.6.27.10/drivers/char/hpet.c 2008-11-07 12:55:34.000000000 -0500
12196 ++++ linux-2.6.27.10/drivers/char/hpet.c 2008-11-18 03:38:44.000000000 -0500
12197 +@@ -959,7 +959,7 @@ static struct acpi_driver hpet_acpi_driv
12198 + },
12199 + };
12200 +
12201 +-static struct miscdevice hpet_misc = { HPET_MINOR, "hpet", &hpet_fops };
12202 ++static struct miscdevice hpet_misc = { HPET_MINOR, "hpet", &hpet_fops, {NULL, NULL}, NULL, NULL };
12203 +
12204 + static int __init hpet_init(void)
12205 + {
12206 +diff -urNp linux-2.6.27.10/drivers/char/keyboard.c linux-2.6.27.10/drivers/char/keyboard.c
12207 +--- linux-2.6.27.10/drivers/char/keyboard.c 2008-11-07 12:55:34.000000000 -0500
12208 ++++ linux-2.6.27.10/drivers/char/keyboard.c 2008-11-18 03:38:44.000000000 -0500
12209 +@@ -635,6 +635,16 @@ static void k_spec(struct vc_data *vc, u
12210 + kbd->kbdmode == VC_MEDIUMRAW) &&
12211 + value != KVAL(K_SAK))
12212 + return; /* SAK is allowed even in raw mode */
12213 ++
12214 ++#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
12215 ++ {
12216 ++ void *func = fn_handler[value];
12217 ++ if (func == fn_show_state || func == fn_show_ptregs ||
12218 ++ func == fn_show_mem)
12219 ++ return;
12220 ++ }
12221 ++#endif
12222 ++
12223 + fn_handler[value](vc);
12224 + }
12225 +
12226 +@@ -1388,7 +1398,7 @@ static const struct input_device_id kbd_
12227 + .evbit = { BIT_MASK(EV_SND) },
12228 + },
12229 +
12230 +- { }, /* Terminating entry */
12231 ++ { 0 }, /* Terminating entry */
12232 + };
12233 +
12234 + MODULE_DEVICE_TABLE(input, kbd_ids);
12235 +diff -urNp linux-2.6.27.10/drivers/char/mem.c linux-2.6.27.10/drivers/char/mem.c
12236 +--- linux-2.6.27.10/drivers/char/mem.c 2008-11-07 12:55:34.000000000 -0500
12237 ++++ linux-2.6.27.10/drivers/char/mem.c 2008-11-18 03:38:44.000000000 -0500
12238 +@@ -27,6 +27,7 @@
12239 + #include <linux/splice.h>
12240 + #include <linux/pfn.h>
12241 + #include <linux/smp_lock.h>
12242 ++#include <linux/grsecurity.h>
12243 +
12244 + #include <asm/uaccess.h>
12245 + #include <asm/io.h>
12246 +@@ -35,6 +36,10 @@
12247 + # include <linux/efi.h>
12248 + #endif
12249 +
12250 ++#ifdef CONFIG_GRKERNSEC
12251 ++extern struct file_operations grsec_fops;
12252 ++#endif
12253 ++
12254 + /*
12255 + * Architectures vary in how they handle caching for addresses
12256 + * outside of main memory.
12257 +@@ -192,6 +197,11 @@ static ssize_t write_mem(struct file * f
12258 + if (!valid_phys_addr_range(p, count))
12259 + return -EFAULT;
12260 +
12261 ++#ifdef CONFIG_GRKERNSEC_KMEM
12262 ++ gr_handle_mem_write();
12263 ++ return -EPERM;
12264 ++#endif
12265 ++
12266 + written = 0;
12267 +
12268 + #ifdef __ARCH_HAS_NO_PAGE_ZERO_MAPPED
12269 +@@ -350,6 +360,11 @@ static int mmap_mem(struct file * file,
12270 + &vma->vm_page_prot))
12271 + return -EINVAL;
12272 +
12273 ++#ifdef CONFIG_GRKERNSEC_KMEM
12274 ++ if (gr_handle_mem_mmap(vma->vm_pgoff << PAGE_SHIFT, vma))
12275 ++ return -EPERM;
12276 ++#endif
12277 ++
12278 + vma->vm_page_prot = phys_mem_access_prot(file, vma->vm_pgoff,
12279 + size,
12280 + vma->vm_page_prot);
12281 +@@ -588,6 +603,11 @@ static ssize_t write_kmem(struct file *
12282 + ssize_t written;
12283 + char * kbuf; /* k-addr because vwrite() takes vmlist_lock rwlock */
12284 +
12285 ++#ifdef CONFIG_GRKERNSEC_KMEM
12286 ++ gr_handle_kmem_write();
12287 ++ return -EPERM;
12288 ++#endif
12289 ++
12290 + if (p < (unsigned long) high_memory) {
12291 +
12292 + wrote = count;
12293 +@@ -791,6 +811,16 @@ static loff_t memory_lseek(struct file *
12294 +
12295 + static int open_port(struct inode * inode, struct file * filp)
12296 + {
12297 ++#ifdef CONFIG_GRKERNSEC_KMEM
12298 ++ gr_handle_open_port();
12299 ++ return -EPERM;
12300 ++#endif
12301 ++
12302 ++ return capable(CAP_SYS_RAWIO) ? 0 : -EPERM;
12303 ++}
12304 ++
12305 ++static int open_mem(struct inode * inode, struct file * filp)
12306 ++{
12307 + return capable(CAP_SYS_RAWIO) ? 0 : -EPERM;
12308 + }
12309 +
12310 +@@ -798,7 +828,6 @@ static int open_port(struct inode * inod
12311 + #define full_lseek null_lseek
12312 + #define write_zero write_null
12313 + #define read_full read_zero
12314 +-#define open_mem open_port
12315 + #define open_kmem open_mem
12316 + #define open_oldmem open_mem
12317 +
12318 +@@ -938,6 +967,11 @@ static int memory_open(struct inode * in
12319 + filp->f_op = &oldmem_fops;
12320 + break;
12321 + #endif
12322 ++#ifdef CONFIG_GRKERNSEC
12323 ++ case 13:
12324 ++ filp->f_op = &grsec_fops;
12325 ++ break;
12326 ++#endif
12327 + default:
12328 + unlock_kernel();
12329 + return -ENXIO;
12330 +@@ -974,6 +1008,9 @@ static const struct {
12331 + #ifdef CONFIG_CRASH_DUMP
12332 + {12,"oldmem", S_IRUSR | S_IWUSR | S_IRGRP, &oldmem_fops},
12333 + #endif
12334 ++#ifdef CONFIG_GRKERNSEC
12335 ++ {13,"grsec", S_IRUSR | S_IWUGO, &grsec_fops},
12336 ++#endif
12337 + };
12338 +
12339 + static struct class *mem_class;
12340 +diff -urNp linux-2.6.27.10/drivers/char/nvram.c linux-2.6.27.10/drivers/char/nvram.c
12341 +--- linux-2.6.27.10/drivers/char/nvram.c 2008-11-07 12:55:34.000000000 -0500
12342 ++++ linux-2.6.27.10/drivers/char/nvram.c 2008-11-18 03:38:44.000000000 -0500
12343 +@@ -433,7 +433,10 @@ static const struct file_operations nvra
12344 + static struct miscdevice nvram_dev = {
12345 + NVRAM_MINOR,
12346 + "nvram",
12347 +- &nvram_fops
12348 ++ &nvram_fops,
12349 ++ {NULL, NULL},
12350 ++ NULL,
12351 ++ NULL
12352 + };
12353 +
12354 + static int __init
12355 +diff -urNp linux-2.6.27.10/drivers/char/random.c linux-2.6.27.10/drivers/char/random.c
12356 +--- linux-2.6.27.10/drivers/char/random.c 2008-11-07 12:55:34.000000000 -0500
12357 ++++ linux-2.6.27.10/drivers/char/random.c 2008-11-18 03:38:44.000000000 -0500
12358 +@@ -249,8 +249,13 @@
12359 + /*
12360 + * Configuration information
12361 + */
12362 ++#ifdef CONFIG_GRKERNSEC_RANDNET
12363 ++#define INPUT_POOL_WORDS 512
12364 ++#define OUTPUT_POOL_WORDS 128
12365 ++#else
12366 + #define INPUT_POOL_WORDS 128
12367 + #define OUTPUT_POOL_WORDS 32
12368 ++#endif
12369 + #define SEC_XFER_SIZE 512
12370 +
12371 + /*
12372 +@@ -287,10 +292,17 @@ static struct poolinfo {
12373 + int poolwords;
12374 + int tap1, tap2, tap3, tap4, tap5;
12375 + } poolinfo_table[] = {
12376 ++#ifdef CONFIG_GRKERNSEC_RANDNET
12377 ++ /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
12378 ++ { 512, 411, 308, 208, 104, 1 },
12379 ++ /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
12380 ++ { 128, 103, 76, 51, 25, 1 },
12381 ++#else
12382 + /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
12383 + { 128, 103, 76, 51, 25, 1 },
12384 + /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
12385 + { 32, 26, 20, 14, 7, 1 },
12386 ++#endif
12387 + #if 0
12388 + /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
12389 + { 2048, 1638, 1231, 819, 411, 1 },
12390 +@@ -1166,7 +1178,7 @@ EXPORT_SYMBOL(generate_random_uuid);
12391 + #include <linux/sysctl.h>
12392 +
12393 + static int min_read_thresh = 8, min_write_thresh;
12394 +-static int max_read_thresh = INPUT_POOL_WORDS * 32;
12395 ++static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
12396 + static int max_write_thresh = INPUT_POOL_WORDS * 32;
12397 + static char sysctl_bootid[16];
12398 +
12399 +diff -urNp linux-2.6.27.10/drivers/char/tpm/tpm.c linux-2.6.27.10/drivers/char/tpm/tpm.c
12400 +--- linux-2.6.27.10/drivers/char/tpm/tpm.c 2008-11-07 12:55:34.000000000 -0500
12401 ++++ linux-2.6.27.10/drivers/char/tpm/tpm.c 2008-11-18 03:38:44.000000000 -0500
12402 +@@ -1037,7 +1037,7 @@ ssize_t tpm_write(struct file *file, con
12403 +
12404 + mutex_lock(&chip->buffer_mutex);
12405 +
12406 +- if (in_size > TPM_BUFSIZE)
12407 ++ if (in_size > (unsigned int)TPM_BUFSIZE)
12408 + in_size = TPM_BUFSIZE;
12409 +
12410 + if (copy_from_user
12411 +diff -urNp linux-2.6.27.10/drivers/char/vt_ioctl.c linux-2.6.27.10/drivers/char/vt_ioctl.c
12412 +--- linux-2.6.27.10/drivers/char/vt_ioctl.c 2008-11-07 12:55:34.000000000 -0500
12413 ++++ linux-2.6.27.10/drivers/char/vt_ioctl.c 2008-11-18 03:38:44.000000000 -0500
12414 +@@ -96,6 +96,12 @@ do_kdsk_ioctl(int cmd, struct kbentry __
12415 + case KDSKBENT:
12416 + if (!perm)
12417 + return -EPERM;
12418 ++
12419 ++#ifdef CONFIG_GRKERNSEC
12420 ++ if (!capable(CAP_SYS_TTY_CONFIG))
12421 ++ return -EPERM;
12422 ++#endif
12423 ++
12424 + if (!i && v == K_NOSUCHMAP) {
12425 + /* deallocate map */
12426 + key_map = key_maps[s];
12427 +@@ -236,6 +242,13 @@ do_kdgkb_ioctl(int cmd, struct kbsentry
12428 + goto reterr;
12429 + }
12430 +
12431 ++#ifdef CONFIG_GRKERNSEC
12432 ++ if (!capable(CAP_SYS_TTY_CONFIG)) {
12433 ++ ret = -EPERM;
12434 ++ goto reterr;
12435 ++ }
12436 ++#endif
12437 ++
12438 + q = func_table[i];
12439 + first_free = funcbufptr + (funcbufsize - funcbufleft);
12440 + for (j = i+1; j < MAX_NR_FUNC && !func_table[j]; j++)
12441 +diff -urNp linux-2.6.27.10/drivers/edac/edac_core.h linux-2.6.27.10/drivers/edac/edac_core.h
12442 +--- linux-2.6.27.10/drivers/edac/edac_core.h 2008-11-07 12:55:34.000000000 -0500
12443 ++++ linux-2.6.27.10/drivers/edac/edac_core.h 2008-11-18 03:38:44.000000000 -0500
12444 +@@ -85,11 +85,11 @@ extern int edac_debug_level;
12445 +
12446 + #else /* !CONFIG_EDAC_DEBUG */
12447 +
12448 +-#define debugf0( ... )
12449 +-#define debugf1( ... )
12450 +-#define debugf2( ... )
12451 +-#define debugf3( ... )
12452 +-#define debugf4( ... )
12453 ++#define debugf0( ... ) do {} while (0)
12454 ++#define debugf1( ... ) do {} while (0)
12455 ++#define debugf2( ... ) do {} while (0)
12456 ++#define debugf3( ... ) do {} while (0)
12457 ++#define debugf4( ... ) do {} while (0)
12458 +
12459 + #endif /* !CONFIG_EDAC_DEBUG */
12460 +
12461 +diff -urNp linux-2.6.27.10/drivers/firmware/dmi_scan.c linux-2.6.27.10/drivers/firmware/dmi_scan.c
12462 +--- linux-2.6.27.10/drivers/firmware/dmi_scan.c 2008-11-07 12:55:34.000000000 -0500
12463 ++++ linux-2.6.27.10/drivers/firmware/dmi_scan.c 2008-11-18 03:38:44.000000000 -0500
12464 +@@ -384,11 +384,6 @@ void __init dmi_scan_machine(void)
12465 + }
12466 + }
12467 + else {
12468 +- /*
12469 +- * no iounmap() for that ioremap(); it would be a no-op, but
12470 +- * it's so early in setup that sucker gets confused into doing
12471 +- * what it shouldn't if we actually call it.
12472 +- */
12473 + p = dmi_ioremap(0xF0000, 0x10000);
12474 + if (p == NULL)
12475 + goto out;
12476 +diff -urNp linux-2.6.27.10/drivers/hwmon/fscpos.c linux-2.6.27.10/drivers/hwmon/fscpos.c
12477 +--- linux-2.6.27.10/drivers/hwmon/fscpos.c 2008-11-07 12:55:34.000000000 -0500
12478 ++++ linux-2.6.27.10/drivers/hwmon/fscpos.c 2008-11-18 03:38:44.000000000 -0500
12479 +@@ -240,7 +240,6 @@ static ssize_t set_pwm(struct i2c_client
12480 + unsigned long v = simple_strtoul(buf, NULL, 10);
12481 +
12482 + /* Range: 0..255 */
12483 +- if (v < 0) v = 0;
12484 + if (v > 255) v = 255;
12485 +
12486 + mutex_lock(&data->update_lock);
12487 +diff -urNp linux-2.6.27.10/drivers/hwmon/k8temp.c linux-2.6.27.10/drivers/hwmon/k8temp.c
12488 +--- linux-2.6.27.10/drivers/hwmon/k8temp.c 2008-11-07 12:55:34.000000000 -0500
12489 ++++ linux-2.6.27.10/drivers/hwmon/k8temp.c 2008-11-18 03:38:44.000000000 -0500
12490 +@@ -130,7 +130,7 @@ static DEVICE_ATTR(name, S_IRUGO, show_n
12491 +
12492 + static struct pci_device_id k8temp_ids[] = {
12493 + { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_K8_NB_MISC) },
12494 +- { 0 },
12495 ++ { 0, 0, 0, 0, 0, 0, 0 },
12496 + };
12497 +
12498 + MODULE_DEVICE_TABLE(pci, k8temp_ids);
12499 +diff -urNp linux-2.6.27.10/drivers/hwmon/sis5595.c linux-2.6.27.10/drivers/hwmon/sis5595.c
12500 +--- linux-2.6.27.10/drivers/hwmon/sis5595.c 2008-11-07 12:55:34.000000000 -0500
12501 ++++ linux-2.6.27.10/drivers/hwmon/sis5595.c 2008-11-18 03:38:44.000000000 -0500
12502 +@@ -698,7 +698,7 @@ static struct sis5595_data *sis5595_upda
12503 +
12504 + static struct pci_device_id sis5595_pci_ids[] = {
12505 + { PCI_DEVICE(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_503) },
12506 +- { 0, }
12507 ++ { 0, 0, 0, 0, 0, 0, 0 }
12508 + };
12509 +
12510 + MODULE_DEVICE_TABLE(pci, sis5595_pci_ids);
12511 +diff -urNp linux-2.6.27.10/drivers/hwmon/via686a.c linux-2.6.27.10/drivers/hwmon/via686a.c
12512 +--- linux-2.6.27.10/drivers/hwmon/via686a.c 2008-11-07 12:55:34.000000000 -0500
12513 ++++ linux-2.6.27.10/drivers/hwmon/via686a.c 2008-11-18 03:38:44.000000000 -0500
12514 +@@ -768,7 +768,7 @@ static struct via686a_data *via686a_upda
12515 +
12516 + static struct pci_device_id via686a_pci_ids[] = {
12517 + { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C686_4) },
12518 +- { 0, }
12519 ++ { 0, 0, 0, 0, 0, 0, 0 }
12520 + };
12521 +
12522 + MODULE_DEVICE_TABLE(pci, via686a_pci_ids);
12523 +diff -urNp linux-2.6.27.10/drivers/hwmon/vt8231.c linux-2.6.27.10/drivers/hwmon/vt8231.c
12524 +--- linux-2.6.27.10/drivers/hwmon/vt8231.c 2008-11-07 12:55:34.000000000 -0500
12525 ++++ linux-2.6.27.10/drivers/hwmon/vt8231.c 2008-11-18 03:38:44.000000000 -0500
12526 +@@ -698,7 +698,7 @@ static struct platform_driver vt8231_dri
12527 +
12528 + static struct pci_device_id vt8231_pci_ids[] = {
12529 + { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8231_4) },
12530 +- { 0, }
12531 ++ { 0, 0, 0, 0, 0, 0, 0 }
12532 + };
12533 +
12534 + MODULE_DEVICE_TABLE(pci, vt8231_pci_ids);
12535 +diff -urNp linux-2.6.27.10/drivers/hwmon/w83791d.c linux-2.6.27.10/drivers/hwmon/w83791d.c
12536 +--- linux-2.6.27.10/drivers/hwmon/w83791d.c 2008-11-07 12:55:34.000000000 -0500
12537 ++++ linux-2.6.27.10/drivers/hwmon/w83791d.c 2008-11-18 03:38:44.000000000 -0500
12538 +@@ -289,8 +289,8 @@ static int w83791d_detect(struct i2c_cli
12539 + struct i2c_board_info *info);
12540 + static int w83791d_remove(struct i2c_client *client);
12541 +
12542 +-static int w83791d_read(struct i2c_client *client, u8 register);
12543 +-static int w83791d_write(struct i2c_client *client, u8 register, u8 value);
12544 ++static int w83791d_read(struct i2c_client *client, u8 reg);
12545 ++static int w83791d_write(struct i2c_client *client, u8 reg, u8 value);
12546 + static struct w83791d_data *w83791d_update_device(struct device *dev);
12547 +
12548 + #ifdef DEBUG
12549 +diff -urNp linux-2.6.27.10/drivers/i2c/busses/i2c-i801.c linux-2.6.27.10/drivers/i2c/busses/i2c-i801.c
12550 +--- linux-2.6.27.10/drivers/i2c/busses/i2c-i801.c 2008-11-07 12:55:34.000000000 -0500
12551 ++++ linux-2.6.27.10/drivers/i2c/busses/i2c-i801.c 2008-11-18 03:38:44.000000000 -0500
12552 +@@ -576,7 +576,7 @@ static struct pci_device_id i801_ids[] =
12553 + { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_TOLAPAI_1) },
12554 + { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH10_4) },
12555 + { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH10_5) },
12556 +- { 0, }
12557 ++ { 0, 0, 0, 0, 0, 0, 0 }
12558 + };
12559 +
12560 + MODULE_DEVICE_TABLE (pci, i801_ids);
12561 +diff -urNp linux-2.6.27.10/drivers/i2c/busses/i2c-piix4.c linux-2.6.27.10/drivers/i2c/busses/i2c-piix4.c
12562 +--- linux-2.6.27.10/drivers/i2c/busses/i2c-piix4.c 2008-11-07 12:55:34.000000000 -0500
12563 ++++ linux-2.6.27.10/drivers/i2c/busses/i2c-piix4.c 2008-11-18 03:38:44.000000000 -0500
12564 +@@ -123,7 +123,7 @@ static struct dmi_system_id __devinitdat
12565 + .ident = "IBM",
12566 + .matches = { DMI_MATCH(DMI_SYS_VENDOR, "IBM"), },
12567 + },
12568 +- { },
12569 ++ { NULL, NULL, {DMI_MATCH(DMI_NONE, NULL)}, NULL },
12570 + };
12571 +
12572 + static int __devinit piix4_setup(struct pci_dev *PIIX4_dev,
12573 +@@ -424,7 +424,7 @@ static struct pci_device_id piix4_ids[]
12574 + PCI_DEVICE_ID_SERVERWORKS_CSB6) },
12575 + { PCI_DEVICE(PCI_VENDOR_ID_SERVERWORKS,
12576 + PCI_DEVICE_ID_SERVERWORKS_HT1000SB) },
12577 +- { 0, }
12578 ++ { 0, 0, 0, 0, 0, 0, 0 }
12579 + };
12580 +
12581 + MODULE_DEVICE_TABLE (pci, piix4_ids);
12582 +diff -urNp linux-2.6.27.10/drivers/i2c/busses/i2c-sis630.c linux-2.6.27.10/drivers/i2c/busses/i2c-sis630.c
12583 +--- linux-2.6.27.10/drivers/i2c/busses/i2c-sis630.c 2008-11-07 12:55:34.000000000 -0500
12584 ++++ linux-2.6.27.10/drivers/i2c/busses/i2c-sis630.c 2008-11-18 03:38:44.000000000 -0500
12585 +@@ -472,7 +472,7 @@ static struct i2c_adapter sis630_adapter
12586 + static struct pci_device_id sis630_ids[] __devinitdata = {
12587 + { PCI_DEVICE(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_503) },
12588 + { PCI_DEVICE(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_LPC) },
12589 +- { 0, }
12590 ++ { 0, 0, 0, 0, 0, 0, 0 }
12591 + };
12592 +
12593 + MODULE_DEVICE_TABLE (pci, sis630_ids);
12594 +diff -urNp linux-2.6.27.10/drivers/i2c/busses/i2c-sis96x.c linux-2.6.27.10/drivers/i2c/busses/i2c-sis96x.c
12595 +--- linux-2.6.27.10/drivers/i2c/busses/i2c-sis96x.c 2008-11-07 12:55:34.000000000 -0500
12596 ++++ linux-2.6.27.10/drivers/i2c/busses/i2c-sis96x.c 2008-11-18 03:38:44.000000000 -0500
12597 +@@ -248,7 +248,7 @@ static struct i2c_adapter sis96x_adapter
12598 +
12599 + static struct pci_device_id sis96x_ids[] = {
12600 + { PCI_DEVICE(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_SMBUS) },
12601 +- { 0, }
12602 ++ { 0, 0, 0, 0, 0, 0, 0 }
12603 + };
12604 +
12605 + MODULE_DEVICE_TABLE (pci, sis96x_ids);
12606 +diff -urNp linux-2.6.27.10/drivers/ieee1394/dv1394.c linux-2.6.27.10/drivers/ieee1394/dv1394.c
12607 +--- linux-2.6.27.10/drivers/ieee1394/dv1394.c 2008-11-07 12:55:34.000000000 -0500
12608 ++++ linux-2.6.27.10/drivers/ieee1394/dv1394.c 2008-11-18 03:38:44.000000000 -0500
12609 +@@ -739,7 +739,7 @@ static void frame_prepare(struct video_c
12610 + based upon DIF section and sequence
12611 + */
12612 +
12613 +-static void inline
12614 ++static inline void
12615 + frame_put_packet (struct frame *f, struct packet *p)
12616 + {
12617 + int section_type = p->data[0] >> 5; /* section type is in bits 5 - 7 */
12618 +@@ -918,7 +918,7 @@ static int do_dv1394_init(struct video_c
12619 + /* default SYT offset is 3 cycles */
12620 + init->syt_offset = 3;
12621 +
12622 +- if ( (init->channel > 63) || (init->channel < 0) )
12623 ++ if (init->channel > 63)
12624 + init->channel = 63;
12625 +
12626 + chan_mask = (u64)1 << init->channel;
12627 +@@ -2174,7 +2174,7 @@ static struct ieee1394_device_id dv1394_
12628 + .specifier_id = AVC_UNIT_SPEC_ID_ENTRY & 0xffffff,
12629 + .version = AVC_SW_VERSION_ENTRY & 0xffffff
12630 + },
12631 +- { }
12632 ++ { 0, 0, 0, 0, 0, 0 }
12633 + };
12634 +
12635 + MODULE_DEVICE_TABLE(ieee1394, dv1394_id_table);
12636 +diff -urNp linux-2.6.27.10/drivers/ieee1394/eth1394.c linux-2.6.27.10/drivers/ieee1394/eth1394.c
12637 +--- linux-2.6.27.10/drivers/ieee1394/eth1394.c 2008-11-07 12:55:34.000000000 -0500
12638 ++++ linux-2.6.27.10/drivers/ieee1394/eth1394.c 2008-11-18 03:38:44.000000000 -0500
12639 +@@ -451,7 +451,7 @@ static struct ieee1394_device_id eth1394
12640 + .specifier_id = ETHER1394_GASP_SPECIFIER_ID,
12641 + .version = ETHER1394_GASP_VERSION,
12642 + },
12643 +- {}
12644 ++ { 0, 0, 0, 0, 0, 0 }
12645 + };
12646 +
12647 + MODULE_DEVICE_TABLE(ieee1394, eth1394_id_table);
12648 +diff -urNp linux-2.6.27.10/drivers/ieee1394/hosts.c linux-2.6.27.10/drivers/ieee1394/hosts.c
12649 +--- linux-2.6.27.10/drivers/ieee1394/hosts.c 2008-11-07 12:55:34.000000000 -0500
12650 ++++ linux-2.6.27.10/drivers/ieee1394/hosts.c 2008-11-18 03:38:44.000000000 -0500
12651 +@@ -78,6 +78,7 @@ static int dummy_isoctl(struct hpsb_iso
12652 + }
12653 +
12654 + static struct hpsb_host_driver dummy_driver = {
12655 ++ .name = "dummy",
12656 + .transmit_packet = dummy_transmit_packet,
12657 + .devctl = dummy_devctl,
12658 + .isoctl = dummy_isoctl
12659 +diff -urNp linux-2.6.27.10/drivers/ieee1394/ohci1394.c linux-2.6.27.10/drivers/ieee1394/ohci1394.c
12660 +--- linux-2.6.27.10/drivers/ieee1394/ohci1394.c 2008-11-07 12:55:34.000000000 -0500
12661 ++++ linux-2.6.27.10/drivers/ieee1394/ohci1394.c 2008-11-18 03:38:44.000000000 -0500
12662 +@@ -147,9 +147,9 @@ printk(level "%s: " fmt "\n" , OHCI1394_
12663 + printk(level "%s: fw-host%d: " fmt "\n" , OHCI1394_DRIVER_NAME, ohci->host->id , ## args)
12664 +
12665 + /* Module Parameters */
12666 +-static int phys_dma = 1;
12667 ++static int phys_dma;
12668 + module_param(phys_dma, int, 0444);
12669 +-MODULE_PARM_DESC(phys_dma, "Enable physical DMA (default = 1).");
12670 ++MODULE_PARM_DESC(phys_dma, "Enable physical DMA (default = 0).");
12671 +
12672 + static void dma_trm_tasklet(unsigned long data);
12673 + static void dma_trm_reset(struct dma_trm_ctx *d);
12674 +@@ -3437,7 +3437,7 @@ static struct pci_device_id ohci1394_pci
12675 + .subvendor = PCI_ANY_ID,
12676 + .subdevice = PCI_ANY_ID,
12677 + },
12678 +- { 0, },
12679 ++ { 0, 0, 0, 0, 0, 0, 0 },
12680 + };
12681 +
12682 + MODULE_DEVICE_TABLE(pci, ohci1394_pci_tbl);
12683 +diff -urNp linux-2.6.27.10/drivers/ieee1394/raw1394.c linux-2.6.27.10/drivers/ieee1394/raw1394.c
12684 +--- linux-2.6.27.10/drivers/ieee1394/raw1394.c 2008-11-07 12:55:34.000000000 -0500
12685 ++++ linux-2.6.27.10/drivers/ieee1394/raw1394.c 2008-11-18 03:38:44.000000000 -0500
12686 +@@ -2968,7 +2968,7 @@ static struct ieee1394_device_id raw1394
12687 + .match_flags = IEEE1394_MATCH_SPECIFIER_ID | IEEE1394_MATCH_VERSION,
12688 + .specifier_id = CAMERA_UNIT_SPEC_ID_ENTRY & 0xffffff,
12689 + .version = (CAMERA_SW_VERSION_ENTRY + 2) & 0xffffff},
12690 +- {}
12691 ++ { 0, 0, 0, 0, 0, 0 }
12692 + };
12693 +
12694 + MODULE_DEVICE_TABLE(ieee1394, raw1394_id_table);
12695 +diff -urNp linux-2.6.27.10/drivers/ieee1394/sbp2.c linux-2.6.27.10/drivers/ieee1394/sbp2.c
12696 +--- linux-2.6.27.10/drivers/ieee1394/sbp2.c 2008-12-10 22:35:37.000000000 -0500
12697 ++++ linux-2.6.27.10/drivers/ieee1394/sbp2.c 2008-12-10 22:35:46.000000000 -0500
12698 +@@ -290,7 +290,7 @@ static struct ieee1394_device_id sbp2_id
12699 + .match_flags = IEEE1394_MATCH_SPECIFIER_ID | IEEE1394_MATCH_VERSION,
12700 + .specifier_id = SBP2_UNIT_SPEC_ID_ENTRY & 0xffffff,
12701 + .version = SBP2_SW_VERSION_ENTRY & 0xffffff},
12702 +- {}
12703 ++ { 0, 0, 0, 0, 0, 0 }
12704 + };
12705 + MODULE_DEVICE_TABLE(ieee1394, sbp2_id_table);
12706 +
12707 +@@ -2135,7 +2135,7 @@ MODULE_DESCRIPTION("IEEE-1394 SBP-2 prot
12708 + MODULE_SUPPORTED_DEVICE(SBP2_DEVICE_NAME);
12709 + MODULE_LICENSE("GPL");
12710 +
12711 +-static int sbp2_module_init(void)
12712 ++static int __init sbp2_module_init(void)
12713 + {
12714 + int ret;
12715 +
12716 +diff -urNp linux-2.6.27.10/drivers/ieee1394/video1394.c linux-2.6.27.10/drivers/ieee1394/video1394.c
12717 +--- linux-2.6.27.10/drivers/ieee1394/video1394.c 2008-11-07 12:55:34.000000000 -0500
12718 ++++ linux-2.6.27.10/drivers/ieee1394/video1394.c 2008-11-18 03:38:44.000000000 -0500
12719 +@@ -893,7 +893,7 @@ static long video1394_ioctl(struct file
12720 + if (unlikely(d == NULL))
12721 + return -EFAULT;
12722 +
12723 +- if (unlikely((v.buffer<0) || (v.buffer>=d->num_desc - 1))) {
12724 ++ if (unlikely(v.buffer>=d->num_desc - 1)) {
12725 + PRINT(KERN_ERR, ohci->host->id,
12726 + "Buffer %d out of range",v.buffer);
12727 + return -EINVAL;
12728 +@@ -959,7 +959,7 @@ static long video1394_ioctl(struct file
12729 + if (unlikely(d == NULL))
12730 + return -EFAULT;
12731 +
12732 +- if (unlikely((v.buffer<0) || (v.buffer>d->num_desc - 1))) {
12733 ++ if (unlikely(v.buffer>d->num_desc - 1)) {
12734 + PRINT(KERN_ERR, ohci->host->id,
12735 + "Buffer %d out of range",v.buffer);
12736 + return -EINVAL;
12737 +@@ -1030,7 +1030,7 @@ static long video1394_ioctl(struct file
12738 + d = find_ctx(&ctx->context_list, OHCI_ISO_TRANSMIT, v.channel);
12739 + if (d == NULL) return -EFAULT;
12740 +
12741 +- if ((v.buffer<0) || (v.buffer>=d->num_desc - 1)) {
12742 ++ if (v.buffer>=d->num_desc - 1) {
12743 + PRINT(KERN_ERR, ohci->host->id,
12744 + "Buffer %d out of range",v.buffer);
12745 + return -EINVAL;
12746 +@@ -1137,7 +1137,7 @@ static long video1394_ioctl(struct file
12747 + d = find_ctx(&ctx->context_list, OHCI_ISO_TRANSMIT, v.channel);
12748 + if (d == NULL) return -EFAULT;
12749 +
12750 +- if ((v.buffer<0) || (v.buffer>=d->num_desc-1)) {
12751 ++ if (v.buffer>=d->num_desc-1) {
12752 + PRINT(KERN_ERR, ohci->host->id,
12753 + "Buffer %d out of range",v.buffer);
12754 + return -EINVAL;
12755 +@@ -1310,7 +1310,7 @@ static struct ieee1394_device_id video13
12756 + .specifier_id = CAMERA_UNIT_SPEC_ID_ENTRY & 0xffffff,
12757 + .version = (CAMERA_SW_VERSION_ENTRY + 2) & 0xffffff
12758 + },
12759 +- { }
12760 ++ { 0, 0, 0, 0, 0, 0 }
12761 + };
12762 +
12763 + MODULE_DEVICE_TABLE(ieee1394, video1394_id_table);
12764 +diff -urNp linux-2.6.27.10/drivers/input/keyboard/atkbd.c linux-2.6.27.10/drivers/input/keyboard/atkbd.c
12765 +--- linux-2.6.27.10/drivers/input/keyboard/atkbd.c 2008-12-10 22:35:37.000000000 -0500
12766 ++++ linux-2.6.27.10/drivers/input/keyboard/atkbd.c 2008-12-10 22:35:46.000000000 -0500
12767 +@@ -1148,7 +1148,7 @@ static struct serio_device_id atkbd_seri
12768 + .id = SERIO_ANY,
12769 + .extra = SERIO_ANY,
12770 + },
12771 +- { 0 }
12772 ++ { 0, 0, 0, 0 }
12773 + };
12774 +
12775 + MODULE_DEVICE_TABLE(serio, atkbd_serio_ids);
12776 +diff -urNp linux-2.6.27.10/drivers/input/mouse/lifebook.c linux-2.6.27.10/drivers/input/mouse/lifebook.c
12777 +--- linux-2.6.27.10/drivers/input/mouse/lifebook.c 2008-11-07 12:55:34.000000000 -0500
12778 ++++ linux-2.6.27.10/drivers/input/mouse/lifebook.c 2008-11-18 03:38:44.000000000 -0500
12779 +@@ -110,7 +110,7 @@ static const struct dmi_system_id lifebo
12780 + DMI_MATCH(DMI_PRODUCT_NAME, "LifeBook B142"),
12781 + },
12782 + },
12783 +- { }
12784 ++ { NULL, NULL, {DMI_MATCH(DMI_NONE, NULL)}, NULL}
12785 + };
12786 +
12787 + static psmouse_ret_t lifebook_process_byte(struct psmouse *psmouse)
12788 +diff -urNp linux-2.6.27.10/drivers/input/mouse/psmouse-base.c linux-2.6.27.10/drivers/input/mouse/psmouse-base.c
12789 +--- linux-2.6.27.10/drivers/input/mouse/psmouse-base.c 2008-11-07 12:55:34.000000000 -0500
12790 ++++ linux-2.6.27.10/drivers/input/mouse/psmouse-base.c 2008-11-18 03:38:44.000000000 -0500
12791 +@@ -1328,7 +1328,7 @@ static struct serio_device_id psmouse_se
12792 + .id = SERIO_ANY,
12793 + .extra = SERIO_ANY,
12794 + },
12795 +- { 0 }
12796 ++ { 0, 0, 0, 0 }
12797 + };
12798 +
12799 + MODULE_DEVICE_TABLE(serio, psmouse_serio_ids);
12800 +diff -urNp linux-2.6.27.10/drivers/input/mouse/synaptics.c linux-2.6.27.10/drivers/input/mouse/synaptics.c
12801 +--- linux-2.6.27.10/drivers/input/mouse/synaptics.c 2008-11-07 12:55:34.000000000 -0500
12802 ++++ linux-2.6.27.10/drivers/input/mouse/synaptics.c 2008-11-18 03:38:45.000000000 -0500
12803 +@@ -417,7 +417,7 @@ static void synaptics_process_packet(str
12804 + break;
12805 + case 2:
12806 + if (SYN_MODEL_PEN(priv->model_id))
12807 +- ; /* Nothing, treat a pen as a single finger */
12808 ++ break; /* Nothing, treat a pen as a single finger */
12809 + break;
12810 + case 4 ... 15:
12811 + if (SYN_CAP_PALMDETECT(priv->capabilities))
12812 +@@ -624,7 +624,7 @@ static const struct dmi_system_id toshib
12813 + DMI_MATCH(DMI_PRODUCT_NAME, "PORTEGE M300"),
12814 + },
12815 + },
12816 +- { }
12817 ++ { NULL, NULL, {DMI_MATCH(DMI_NONE, NULL)}, NULL }
12818 + };
12819 + #endif
12820 +
12821 +diff -urNp linux-2.6.27.10/drivers/input/mousedev.c linux-2.6.27.10/drivers/input/mousedev.c
12822 +--- linux-2.6.27.10/drivers/input/mousedev.c 2008-11-07 12:55:34.000000000 -0500
12823 ++++ linux-2.6.27.10/drivers/input/mousedev.c 2008-11-18 03:38:45.000000000 -0500
12824 +@@ -1064,7 +1064,7 @@ static struct input_handler mousedev_han
12825 +
12826 + #ifdef CONFIG_INPUT_MOUSEDEV_PSAUX
12827 + static struct miscdevice psaux_mouse = {
12828 +- PSMOUSE_MINOR, "psaux", &mousedev_fops
12829 ++ PSMOUSE_MINOR, "psaux", &mousedev_fops, {NULL, NULL}, NULL, NULL
12830 + };
12831 + static int psaux_registered;
12832 + #endif
12833 +diff -urNp linux-2.6.27.10/drivers/input/serio/i8042-x86ia64io.h linux-2.6.27.10/drivers/input/serio/i8042-x86ia64io.h
12834 +--- linux-2.6.27.10/drivers/input/serio/i8042-x86ia64io.h 2008-12-21 01:16:51.000000000 -0500
12835 ++++ linux-2.6.27.10/drivers/input/serio/i8042-x86ia64io.h 2008-12-21 01:16:00.000000000 -0500
12836 +@@ -143,7 +143,7 @@ static struct dmi_system_id __initdata i
12837 + DMI_MATCH(DMI_PRODUCT_VERSION, "M606"),
12838 + },
12839 + },
12840 +- { }
12841 ++ { NULL, NULL, {DMI_MATCH(DMI_NONE, NULL)}, NULL }
12842 + };
12843 +
12844 + /*
12845 +@@ -351,7 +351,7 @@ static struct dmi_system_id __initdata i
12846 + DMI_MATCH(DMI_PRODUCT_NAME, "HEL80I"),
12847 + },
12848 + },
12849 +- { }
12850 ++ { NULL, NULL, {DMI_MATCH(DMI_NONE, NULL)}, NULL }
12851 + };
12852 +
12853 + #ifdef CONFIG_PNP
12854 +@@ -363,7 +363,7 @@ static struct dmi_system_id __initdata i
12855 + DMI_MATCH(DMI_BOARD_VENDOR, "Intel Corporation"),
12856 + },
12857 + },
12858 +- { }
12859 ++ { NULL, NULL, {DMI_MATCH(DMI_NONE, NULL)}, NULL }
12860 + };
12861 + #endif
12862 +
12863 +@@ -430,7 +430,7 @@ static struct dmi_system_id __initdata i
12864 + DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 4280"),
12865 + },
12866 + },
12867 +- { }
12868 ++ { NULL, NULL, {DMI_MATCH(DMI_NONE, NULL)}, NULL }
12869 + };
12870 +
12871 + #endif /* CONFIG_X86 */
12872 +diff -urNp linux-2.6.27.10/drivers/input/serio/serio_raw.c linux-2.6.27.10/drivers/input/serio/serio_raw.c
12873 +--- linux-2.6.27.10/drivers/input/serio/serio_raw.c 2008-11-07 12:55:34.000000000 -0500
12874 ++++ linux-2.6.27.10/drivers/input/serio/serio_raw.c 2008-11-18 03:38:45.000000000 -0500
12875 +@@ -373,7 +373,7 @@ static struct serio_device_id serio_raw_
12876 + .id = SERIO_ANY,
12877 + .extra = SERIO_ANY,
12878 + },
12879 +- { 0 }
12880 ++ { 0, 0, 0, 0 }
12881 + };
12882 +
12883 + MODULE_DEVICE_TABLE(serio, serio_raw_serio_ids);
12884 +diff -urNp linux-2.6.27.10/drivers/md/bitmap.c linux-2.6.27.10/drivers/md/bitmap.c
12885 +--- linux-2.6.27.10/drivers/md/bitmap.c 2008-11-07 12:55:34.000000000 -0500
12886 ++++ linux-2.6.27.10/drivers/md/bitmap.c 2008-11-18 03:38:45.000000000 -0500
12887 +@@ -57,7 +57,7 @@
12888 + # if DEBUG > 0
12889 + # define PRINTK(x...) printk(KERN_DEBUG x)
12890 + # else
12891 +-# define PRINTK(x...)
12892 ++# define PRINTK(x...) do {} while (0)
12893 + # endif
12894 + #endif
12895 +
12896 +diff -urNp linux-2.6.27.10/drivers/mtd/devices/doc2000.c linux-2.6.27.10/drivers/mtd/devices/doc2000.c
12897 +--- linux-2.6.27.10/drivers/mtd/devices/doc2000.c 2008-11-07 12:55:34.000000000 -0500
12898 ++++ linux-2.6.27.10/drivers/mtd/devices/doc2000.c 2008-11-18 03:38:45.000000000 -0500
12899 +@@ -777,7 +777,7 @@ static int doc_write(struct mtd_info *mt
12900 +
12901 + /* The ECC will not be calculated correctly if less than 512 is written */
12902 + /* DBB-
12903 +- if (len != 0x200 && eccbuf)
12904 ++ if (len != 0x200)
12905 + printk(KERN_WARNING
12906 + "ECC needs a full sector write (adr: %lx size %lx)\n",
12907 + (long) to, (long) len);
12908 +diff -urNp linux-2.6.27.10/drivers/mtd/devices/doc2001.c linux-2.6.27.10/drivers/mtd/devices/doc2001.c
12909 +--- linux-2.6.27.10/drivers/mtd/devices/doc2001.c 2008-11-07 12:55:34.000000000 -0500
12910 ++++ linux-2.6.27.10/drivers/mtd/devices/doc2001.c 2008-11-18 03:38:45.000000000 -0500
12911 +@@ -396,6 +396,8 @@ static int doc_read (struct mtd_info *mt
12912 + /* Don't allow read past end of device */
12913 + if (from >= this->totlen)
12914 + return -EINVAL;
12915 ++ if (!len)
12916 ++ return -EINVAL;
12917 +
12918 + /* Don't allow a single read to cross a 512-byte block boundary */
12919 + if (from + len > ((from | 0x1ff) + 1))
12920 +diff -urNp linux-2.6.27.10/drivers/mtd/devices/slram.c linux-2.6.27.10/drivers/mtd/devices/slram.c
12921 +--- linux-2.6.27.10/drivers/mtd/devices/slram.c 2008-11-07 12:55:34.000000000 -0500
12922 ++++ linux-2.6.27.10/drivers/mtd/devices/slram.c 2008-11-18 03:38:45.000000000 -0500
12923 +@@ -273,7 +273,7 @@ static int parse_cmdline(char *devname,
12924 + }
12925 + T("slram: devname=%s, devstart=0x%lx, devlength=0x%lx\n",
12926 + devname, devstart, devlength);
12927 +- if ((devstart < 0) || (devlength < 0) || (devlength % SLRAM_BLK_SZ != 0)) {
12928 ++ if (devlength % SLRAM_BLK_SZ != 0) {
12929 + E("slram: Illegal start / length parameter.\n");
12930 + return(-EINVAL);
12931 + }
12932 +diff -urNp linux-2.6.27.10/drivers/mtd/ubi/build.c linux-2.6.27.10/drivers/mtd/ubi/build.c
12933 +--- linux-2.6.27.10/drivers/mtd/ubi/build.c 2008-11-07 12:55:34.000000000 -0500
12934 ++++ linux-2.6.27.10/drivers/mtd/ubi/build.c 2008-11-18 03:38:45.000000000 -0500
12935 +@@ -1104,7 +1104,7 @@ static int __init bytes_str_to_int(const
12936 + unsigned long result;
12937 +
12938 + result = simple_strtoul(str, &endp, 0);
12939 +- if (str == endp || result < 0) {
12940 ++ if (str == endp) {
12941 + printk(KERN_ERR "UBI error: incorrect bytes count: \"%s\"\n",
12942 + str);
12943 + return -EINVAL;
12944 +diff -urNp linux-2.6.27.10/drivers/net/eepro100.c linux-2.6.27.10/drivers/net/eepro100.c
12945 +--- linux-2.6.27.10/drivers/net/eepro100.c 2008-11-07 12:55:34.000000000 -0500
12946 ++++ linux-2.6.27.10/drivers/net/eepro100.c 2008-11-18 03:38:45.000000000 -0500
12947 +@@ -47,7 +47,7 @@ static int rxdmacount /* = 0 */;
12948 + # define rx_align(skb) skb_reserve((skb), 2)
12949 + # define RxFD_ALIGNMENT __attribute__ ((aligned (2), packed))
12950 + #else
12951 +-# define rx_align(skb)
12952 ++# define rx_align(skb) do {} while (0)
12953 + # define RxFD_ALIGNMENT
12954 + #endif
12955 +
12956 +@@ -2334,33 +2334,33 @@ static void __devexit eepro100_remove_on
12957 + }
12958 +
12959 + static struct pci_device_id eepro100_pci_tbl[] = {
12960 +- { PCI_VENDOR_ID_INTEL, 0x1229, PCI_ANY_ID, PCI_ANY_ID, },
12961 +- { PCI_VENDOR_ID_INTEL, 0x1209, PCI_ANY_ID, PCI_ANY_ID, },
12962 +- { PCI_VENDOR_ID_INTEL, 0x1029, PCI_ANY_ID, PCI_ANY_ID, },
12963 +- { PCI_VENDOR_ID_INTEL, 0x1030, PCI_ANY_ID, PCI_ANY_ID, },
12964 +- { PCI_VENDOR_ID_INTEL, 0x1031, PCI_ANY_ID, PCI_ANY_ID, },
12965 +- { PCI_VENDOR_ID_INTEL, 0x1032, PCI_ANY_ID, PCI_ANY_ID, },
12966 +- { PCI_VENDOR_ID_INTEL, 0x1033, PCI_ANY_ID, PCI_ANY_ID, },
12967 +- { PCI_VENDOR_ID_INTEL, 0x1034, PCI_ANY_ID, PCI_ANY_ID, },
12968 +- { PCI_VENDOR_ID_INTEL, 0x1035, PCI_ANY_ID, PCI_ANY_ID, },
12969 +- { PCI_VENDOR_ID_INTEL, 0x1036, PCI_ANY_ID, PCI_ANY_ID, },
12970 +- { PCI_VENDOR_ID_INTEL, 0x1037, PCI_ANY_ID, PCI_ANY_ID, },
12971 +- { PCI_VENDOR_ID_INTEL, 0x1038, PCI_ANY_ID, PCI_ANY_ID, },
12972 +- { PCI_VENDOR_ID_INTEL, 0x1039, PCI_ANY_ID, PCI_ANY_ID, },
12973 +- { PCI_VENDOR_ID_INTEL, 0x103A, PCI_ANY_ID, PCI_ANY_ID, },
12974 +- { PCI_VENDOR_ID_INTEL, 0x103B, PCI_ANY_ID, PCI_ANY_ID, },
12975 +- { PCI_VENDOR_ID_INTEL, 0x103C, PCI_ANY_ID, PCI_ANY_ID, },
12976 +- { PCI_VENDOR_ID_INTEL, 0x103D, PCI_ANY_ID, PCI_ANY_ID, },
12977 +- { PCI_VENDOR_ID_INTEL, 0x103E, PCI_ANY_ID, PCI_ANY_ID, },
12978 +- { PCI_VENDOR_ID_INTEL, 0x1050, PCI_ANY_ID, PCI_ANY_ID, },
12979 +- { PCI_VENDOR_ID_INTEL, 0x1059, PCI_ANY_ID, PCI_ANY_ID, },
12980 +- { PCI_VENDOR_ID_INTEL, 0x1227, PCI_ANY_ID, PCI_ANY_ID, },
12981 +- { PCI_VENDOR_ID_INTEL, 0x2449, PCI_ANY_ID, PCI_ANY_ID, },
12982 +- { PCI_VENDOR_ID_INTEL, 0x2459, PCI_ANY_ID, PCI_ANY_ID, },
12983 +- { PCI_VENDOR_ID_INTEL, 0x245D, PCI_ANY_ID, PCI_ANY_ID, },
12984 +- { PCI_VENDOR_ID_INTEL, 0x5200, PCI_ANY_ID, PCI_ANY_ID, },
12985 +- { PCI_VENDOR_ID_INTEL, 0x5201, PCI_ANY_ID, PCI_ANY_ID, },
12986 +- { 0,}
12987 ++ { PCI_VENDOR_ID_INTEL, 0x1229, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
12988 ++ { PCI_VENDOR_ID_INTEL, 0x1209, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
12989 ++ { PCI_VENDOR_ID_INTEL, 0x1029, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
12990 ++ { PCI_VENDOR_ID_INTEL, 0x1030, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
12991 ++ { PCI_VENDOR_ID_INTEL, 0x1031, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
12992 ++ { PCI_VENDOR_ID_INTEL, 0x1032, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
12993 ++ { PCI_VENDOR_ID_INTEL, 0x1033, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
12994 ++ { PCI_VENDOR_ID_INTEL, 0x1034, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
12995 ++ { PCI_VENDOR_ID_INTEL, 0x1035, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
12996 ++ { PCI_VENDOR_ID_INTEL, 0x1036, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
12997 ++ { PCI_VENDOR_ID_INTEL, 0x1037, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
12998 ++ { PCI_VENDOR_ID_INTEL, 0x1038, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
12999 ++ { PCI_VENDOR_ID_INTEL, 0x1039, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
13000 ++ { PCI_VENDOR_ID_INTEL, 0x103A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
13001 ++ { PCI_VENDOR_ID_INTEL, 0x103B, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
13002 ++ { PCI_VENDOR_ID_INTEL, 0x103C, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
13003 ++ { PCI_VENDOR_ID_INTEL, 0x103D, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
13004 ++ { PCI_VENDOR_ID_INTEL, 0x103E, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
13005 ++ { PCI_VENDOR_ID_INTEL, 0x1050, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
13006 ++ { PCI_VENDOR_ID_INTEL, 0x1059, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
13007 ++ { PCI_VENDOR_ID_INTEL, 0x1227, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
13008 ++ { PCI_VENDOR_ID_INTEL, 0x2449, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
13009 ++ { PCI_VENDOR_ID_INTEL, 0x2459, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
13010 ++ { PCI_VENDOR_ID_INTEL, 0x245D, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
13011 ++ { PCI_VENDOR_ID_INTEL, 0x5200, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
13012 ++ { PCI_VENDOR_ID_INTEL, 0x5201, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
13013 ++ { 0, 0, 0, 0, 0, 0, 0 }
13014 + };
13015 + MODULE_DEVICE_TABLE(pci, eepro100_pci_tbl);
13016 +
13017 +diff -urNp linux-2.6.27.10/drivers/net/irda/vlsi_ir.c linux-2.6.27.10/drivers/net/irda/vlsi_ir.c
13018 +--- linux-2.6.27.10/drivers/net/irda/vlsi_ir.c 2008-11-07 12:55:34.000000000 -0500
13019 ++++ linux-2.6.27.10/drivers/net/irda/vlsi_ir.c 2008-11-18 03:38:45.000000000 -0500
13020 +@@ -906,13 +906,12 @@ static int vlsi_hard_start_xmit(struct s
13021 + /* no race - tx-ring already empty */
13022 + vlsi_set_baud(idev, iobase);
13023 + netif_wake_queue(ndev);
13024 +- }
13025 +- else
13026 +- ;
13027 ++ } else {
13028 + /* keep the speed change pending like it would
13029 + * for any len>0 packet. tx completion interrupt
13030 + * will apply it when the tx ring becomes empty.
13031 + */
13032 ++ }
13033 + spin_unlock_irqrestore(&idev->lock, flags);
13034 + dev_kfree_skb_any(skb);
13035 + return 0;
13036 +diff -urNp linux-2.6.27.10/drivers/net/pcnet32.c linux-2.6.27.10/drivers/net/pcnet32.c
13037 +--- linux-2.6.27.10/drivers/net/pcnet32.c 2008-11-07 12:55:34.000000000 -0500
13038 ++++ linux-2.6.27.10/drivers/net/pcnet32.c 2008-11-18 03:38:45.000000000 -0500
13039 +@@ -78,7 +78,7 @@ static int cards_found;
13040 + /*
13041 + * VLB I/O addresses
13042 + */
13043 +-static unsigned int pcnet32_portlist[] __initdata =
13044 ++static unsigned int pcnet32_portlist[] __devinitdata =
13045 + { 0x300, 0x320, 0x340, 0x360, 0 };
13046 +
13047 + static int pcnet32_debug = 0;
13048 +diff -urNp linux-2.6.27.10/drivers/net/tg3.h linux-2.6.27.10/drivers/net/tg3.h
13049 +--- linux-2.6.27.10/drivers/net/tg3.h 2008-11-07 12:55:34.000000000 -0500
13050 ++++ linux-2.6.27.10/drivers/net/tg3.h 2008-11-18 03:38:45.000000000 -0500
13051 +@@ -102,6 +102,7 @@
13052 + #define CHIPREV_ID_5750_A0 0x4000
13053 + #define CHIPREV_ID_5750_A1 0x4001
13054 + #define CHIPREV_ID_5750_A3 0x4003
13055 ++#define CHIPREV_ID_5750_C1 0x4201
13056 + #define CHIPREV_ID_5750_C2 0x4202
13057 + #define CHIPREV_ID_5752_A0_HW 0x5000
13058 + #define CHIPREV_ID_5752_A0 0x6000
13059 +diff -urNp linux-2.6.27.10/drivers/net/wireless/iwlwifi/iwl3945-base.c linux-2.6.27.10/drivers/net/wireless/iwlwifi/iwl3945-base.c
13060 +--- linux-2.6.27.10/drivers/net/wireless/iwlwifi/iwl3945-base.c 2008-11-17 20:03:30.000000000 -0500
13061 ++++ linux-2.6.27.10/drivers/net/wireless/iwlwifi/iwl3945-base.c 2008-12-27 13:44:22.000000000 -0500
13062 +@@ -785,7 +785,7 @@ static int iwl3945_send_cmd_sync(struct
13063 + IWL_ERROR("Error: Response NULL in '%s'\n",
13064 + get_cmd_string(cmd->id));
13065 + ret = -EIO;
13066 +- goto out;
13067 ++ goto cancel;
13068 + }
13069 +
13070 + ret = 0;
13071 +diff -urNp linux-2.6.27.10/drivers/pci/hotplug/cpqphp_nvram.c linux-2.6.27.10/drivers/pci/hotplug/cpqphp_nvram.c
13072 +--- linux-2.6.27.10/drivers/pci/hotplug/cpqphp_nvram.c 2008-11-07 12:55:34.000000000 -0500
13073 ++++ linux-2.6.27.10/drivers/pci/hotplug/cpqphp_nvram.c 2008-11-18 03:38:45.000000000 -0500
13074 +@@ -425,9 +425,13 @@ static u32 store_HRT (void __iomem *rom_
13075 +
13076 + void compaq_nvram_init (void __iomem *rom_start)
13077 + {
13078 ++
13079 ++#ifndef CONFIG_PAX_KERNEXEC
13080 + if (rom_start) {
13081 + compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
13082 + }
13083 ++#endif
13084 ++
13085 + dbg("int15 entry = %p\n", compaq_int15_entry_point);
13086 +
13087 + /* initialize our int15 lock */
13088 +diff -urNp linux-2.6.27.10/drivers/pci/pcie/aer/aerdrv.c linux-2.6.27.10/drivers/pci/pcie/aer/aerdrv.c
13089 +--- linux-2.6.27.10/drivers/pci/pcie/aer/aerdrv.c 2008-11-07 12:55:34.000000000 -0500
13090 ++++ linux-2.6.27.10/drivers/pci/pcie/aer/aerdrv.c 2008-11-18 03:38:45.000000000 -0500
13091 +@@ -59,7 +59,7 @@ static struct pcie_port_service_id aer_i
13092 + .port_type = PCIE_RC_PORT,
13093 + .service_type = PCIE_PORT_SERVICE_AER,
13094 + },
13095 +- { /* end: all zeroes */ }
13096 ++ { 0, 0, 0, 0, 0, 0, 0, 0, 0 }
13097 + };
13098 +
13099 + static struct pci_error_handlers aer_error_handlers = {
13100 +diff -urNp linux-2.6.27.10/drivers/pci/pcie/aer/aerdrv_core.c linux-2.6.27.10/drivers/pci/pcie/aer/aerdrv_core.c
13101 +--- linux-2.6.27.10/drivers/pci/pcie/aer/aerdrv_core.c 2008-11-07 12:55:34.000000000 -0500
13102 ++++ linux-2.6.27.10/drivers/pci/pcie/aer/aerdrv_core.c 2008-11-18 03:38:45.000000000 -0500
13103 +@@ -663,7 +663,7 @@ static void aer_isr_one_error(struct pci
13104 + struct aer_err_source *e_src)
13105 + {
13106 + struct device *s_device;
13107 +- struct aer_err_info e_info = {0, 0, 0,};
13108 ++ struct aer_err_info e_info = {0, 0, 0, {0, 0, 0, 0}};
13109 + int i;
13110 + u16 id;
13111 +
13112 +diff -urNp linux-2.6.27.10/drivers/pci/pcie/portdrv_pci.c linux-2.6.27.10/drivers/pci/pcie/portdrv_pci.c
13113 +--- linux-2.6.27.10/drivers/pci/pcie/portdrv_pci.c 2008-11-07 12:55:34.000000000 -0500
13114 ++++ linux-2.6.27.10/drivers/pci/pcie/portdrv_pci.c 2008-11-18 03:38:45.000000000 -0500
13115 +@@ -264,7 +264,7 @@ static void pcie_portdrv_err_resume(stru
13116 + static const struct pci_device_id port_pci_ids[] = { {
13117 + /* handle any PCI-Express port */
13118 + PCI_DEVICE_CLASS(((PCI_CLASS_BRIDGE_PCI << 8) | 0x00), ~0),
13119 +- }, { /* end: all zeroes */ }
13120 ++ }, { 0, 0, 0, 0, 0, 0, 0 }
13121 + };
13122 + MODULE_DEVICE_TABLE(pci, port_pci_ids);
13123 +
13124 +diff -urNp linux-2.6.27.10/drivers/pci/proc.c linux-2.6.27.10/drivers/pci/proc.c
13125 +--- linux-2.6.27.10/drivers/pci/proc.c 2008-11-07 12:55:34.000000000 -0500
13126 ++++ linux-2.6.27.10/drivers/pci/proc.c 2008-11-18 03:38:45.000000000 -0500
13127 +@@ -470,7 +470,16 @@ static const struct file_operations proc
13128 + static int __init pci_proc_init(void)
13129 + {
13130 + struct pci_dev *dev = NULL;
13131 ++
13132 ++#ifdef CONFIG_GRKERNSEC_PROC_ADD
13133 ++#ifdef CONFIG_GRKERNSEC_PROC_USER
13134 ++ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
13135 ++#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
13136 ++ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
13137 ++#endif
13138 ++#else
13139 + proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
13140 ++#endif
13141 + proc_create("devices", 0, proc_bus_pci_dir,
13142 + &proc_bus_pci_dev_operations);
13143 + proc_initialized = 1;
13144 +diff -urNp linux-2.6.27.10/drivers/pcmcia/ti113x.h linux-2.6.27.10/drivers/pcmcia/ti113x.h
13145 +--- linux-2.6.27.10/drivers/pcmcia/ti113x.h 2008-11-07 12:55:34.000000000 -0500
13146 ++++ linux-2.6.27.10/drivers/pcmcia/ti113x.h 2008-11-18 03:38:45.000000000 -0500
13147 +@@ -897,7 +897,7 @@ static struct pci_device_id ene_tune_tbl
13148 + DEVID(PCI_VENDOR_ID_MOTOROLA, 0x3410, 0xECC0, PCI_ANY_ID,
13149 + ENE_TEST_C9_TLTENABLE | ENE_TEST_C9_PFENABLE, ENE_TEST_C9_TLTENABLE),
13150 +
13151 +- {}
13152 ++ { 0, 0, 0, 0, 0, 0, 0 }
13153 + };
13154 +
13155 + static void ene_tune_bridge(struct pcmcia_socket *sock, struct pci_bus *bus)
13156 +diff -urNp linux-2.6.27.10/drivers/pcmcia/yenta_socket.c linux-2.6.27.10/drivers/pcmcia/yenta_socket.c
13157 +--- linux-2.6.27.10/drivers/pcmcia/yenta_socket.c 2008-11-07 12:55:34.000000000 -0500
13158 ++++ linux-2.6.27.10/drivers/pcmcia/yenta_socket.c 2008-11-18 03:38:45.000000000 -0500
13159 +@@ -1358,7 +1358,7 @@ static struct pci_device_id yenta_table
13160 +
13161 + /* match any cardbus bridge */
13162 + CB_ID(PCI_ANY_ID, PCI_ANY_ID, DEFAULT),
13163 +- { /* all zeroes */ }
13164 ++ { 0, 0, 0, 0, 0, 0, 0 }
13165 + };
13166 + MODULE_DEVICE_TABLE(pci, yenta_table);
13167 +
13168 +diff -urNp linux-2.6.27.10/drivers/pnp/pnpbios/bioscalls.c linux-2.6.27.10/drivers/pnp/pnpbios/bioscalls.c
13169 +--- linux-2.6.27.10/drivers/pnp/pnpbios/bioscalls.c 2008-11-07 12:55:34.000000000 -0500
13170 ++++ linux-2.6.27.10/drivers/pnp/pnpbios/bioscalls.c 2008-11-18 03:38:45.000000000 -0500
13171 +@@ -60,7 +60,7 @@ set_base(gdt[(selname) >> 3], (u32)(addr
13172 + set_limit(gdt[(selname) >> 3], size); \
13173 + } while(0)
13174 +
13175 +-static struct desc_struct bad_bios_desc;
13176 ++static struct desc_struct bad_bios_desc __read_only;
13177 +
13178 + /*
13179 + * At some point we want to use this stack frame pointer to unwind
13180 +@@ -87,6 +87,10 @@ static inline u16 call_pnp_bios(u16 func
13181 + struct desc_struct save_desc_40;
13182 + int cpu;
13183 +
13184 ++#ifdef CONFIG_PAX_KERNEXEC
13185 ++ unsigned long cr0;
13186 ++#endif
13187 ++
13188 + /*
13189 + * PnP BIOSes are generally not terribly re-entrant.
13190 + * Also, don't rely on them to save everything correctly.
13191 +@@ -96,8 +100,17 @@ static inline u16 call_pnp_bios(u16 func
13192 +
13193 + cpu = get_cpu();
13194 + save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
13195 ++
13196 ++#ifdef CONFIG_PAX_KERNEXEC
13197 ++ pax_open_kernel(cr0);
13198 ++#endif
13199 ++
13200 + get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
13201 +
13202 ++#ifdef CONFIG_PAX_KERNEXEC
13203 ++ pax_close_kernel(cr0);
13204 ++#endif
13205 ++
13206 + /* On some boxes IRQ's during PnP BIOS calls are deadly. */
13207 + spin_lock_irqsave(&pnp_bios_lock, flags);
13208 +
13209 +@@ -134,7 +147,16 @@ static inline u16 call_pnp_bios(u16 func
13210 + :"memory");
13211 + spin_unlock_irqrestore(&pnp_bios_lock, flags);
13212 +
13213 ++#ifdef CONFIG_PAX_KERNEXEC
13214 ++ pax_open_kernel(cr0);
13215 ++#endif
13216 ++
13217 + get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
13218 ++
13219 ++#ifdef CONFIG_PAX_KERNEXEC
13220 ++ pax_close_kernel(cr0);
13221 ++#endif
13222 ++
13223 + put_cpu();
13224 +
13225 + /* If we get here and this is set then the PnP BIOS faulted on us. */
13226 +@@ -468,16 +490,24 @@ int pnp_bios_read_escd(char *data, u32 n
13227 + return status;
13228 + }
13229 +
13230 +-void pnpbios_calls_init(union pnp_bios_install_struct *header)
13231 ++void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
13232 + {
13233 + int i;
13234 +
13235 ++#ifdef CONFIG_PAX_KERNEXEC
13236 ++ unsigned long cr0;
13237 ++#endif
13238 ++
13239 + spin_lock_init(&pnp_bios_lock);
13240 + pnp_bios_callpoint.offset = header->fields.pm16offset;
13241 + pnp_bios_callpoint.segment = PNP_CS16;
13242 +
13243 ++#ifdef CONFIG_PAX_KERNEXEC
13244 ++ pax_open_kernel(cr0);
13245 ++#endif
13246 ++
13247 + bad_bios_desc.a = 0;
13248 +- bad_bios_desc.b = 0x00409200;
13249 ++ bad_bios_desc.b = 0x00409300;
13250 +
13251 + set_base(bad_bios_desc, __va((unsigned long)0x40 << 4));
13252 + _set_limit((char *)&bad_bios_desc, 4095 - (0x40 << 4));
13253 +@@ -491,4 +521,9 @@ void pnpbios_calls_init(union pnp_bios_i
13254 + set_base(gdt[GDT_ENTRY_PNPBIOS_DS],
13255 + __va(header->fields.pm16dseg));
13256 + }
13257 ++
13258 ++#ifdef CONFIG_PAX_KERNEXEC
13259 ++ pax_close_kernel(cr0);
13260 ++#endif
13261 ++
13262 + }
13263 +diff -urNp linux-2.6.27.10/drivers/pnp/quirks.c linux-2.6.27.10/drivers/pnp/quirks.c
13264 +--- linux-2.6.27.10/drivers/pnp/quirks.c 2008-12-21 01:16:51.000000000 -0500
13265 ++++ linux-2.6.27.10/drivers/pnp/quirks.c 2008-12-21 01:13:46.000000000 -0500
13266 +@@ -327,7 +327,7 @@ static struct pnp_fixup pnp_fixups[] = {
13267 + /* PnP resources that might overlap PCI BARs */
13268 + {"PNP0c01", quirk_system_pci_resources},
13269 + {"PNP0c02", quirk_system_pci_resources},
13270 +- {""}
13271 ++ {"", NULL}
13272 + };
13273 +
13274 + void pnp_fixup_device(struct pnp_dev *dev)
13275 +diff -urNp linux-2.6.27.10/drivers/pnp/resource.c linux-2.6.27.10/drivers/pnp/resource.c
13276 +--- linux-2.6.27.10/drivers/pnp/resource.c 2008-12-21 01:16:51.000000000 -0500
13277 ++++ linux-2.6.27.10/drivers/pnp/resource.c 2008-12-21 01:13:46.000000000 -0500
13278 +@@ -355,7 +355,7 @@ int pnp_check_irq(struct pnp_dev *dev, s
13279 + return 1;
13280 +
13281 + /* check if the resource is valid */
13282 +- if (*irq < 0 || *irq > 15)
13283 ++ if (*irq > 15)
13284 + return 0;
13285 +
13286 + /* check if the resource is reserved */
13287 +@@ -419,7 +419,7 @@ int pnp_check_dma(struct pnp_dev *dev, s
13288 + return 1;
13289 +
13290 + /* check if the resource is valid */
13291 +- if (*dma < 0 || *dma == 4 || *dma > 7)
13292 ++ if (*dma == 4 || *dma > 7)
13293 + return 0;
13294 +
13295 + /* check if the resource is reserved */
13296 +diff -urNp linux-2.6.27.10/drivers/scsi/scsi_logging.h linux-2.6.27.10/drivers/scsi/scsi_logging.h
13297 +--- linux-2.6.27.10/drivers/scsi/scsi_logging.h 2008-11-07 12:55:34.000000000 -0500
13298 ++++ linux-2.6.27.10/drivers/scsi/scsi_logging.h 2008-11-18 03:38:45.000000000 -0500
13299 +@@ -51,7 +51,7 @@ do { \
13300 + } while (0); \
13301 + } while (0)
13302 + #else
13303 +-#define SCSI_CHECK_LOGGING(SHIFT, BITS, LEVEL, CMD)
13304 ++#define SCSI_CHECK_LOGGING(SHIFT, BITS, LEVEL, CMD) do {} while (0)
13305 + #endif /* CONFIG_SCSI_LOGGING */
13306 +
13307 + /*
13308 +diff -urNp linux-2.6.27.10/drivers/serial/8250_pci.c linux-2.6.27.10/drivers/serial/8250_pci.c
13309 +--- linux-2.6.27.10/drivers/serial/8250_pci.c 2008-11-07 12:55:34.000000000 -0500
13310 ++++ linux-2.6.27.10/drivers/serial/8250_pci.c 2008-11-18 03:38:45.000000000 -0500
13311 +@@ -2859,7 +2859,7 @@ static struct pci_device_id serial_pci_t
13312 + PCI_ANY_ID, PCI_ANY_ID,
13313 + PCI_CLASS_COMMUNICATION_MULTISERIAL << 8,
13314 + 0xffff00, pbn_default },
13315 +- { 0, }
13316 ++ { 0, 0, 0, 0, 0, 0, 0 }
13317 + };
13318 +
13319 + static struct pci_driver serial_pci_driver = {
13320 +diff -urNp linux-2.6.27.10/drivers/usb/class/cdc-acm.c linux-2.6.27.10/drivers/usb/class/cdc-acm.c
13321 +--- linux-2.6.27.10/drivers/usb/class/cdc-acm.c 2008-11-18 11:38:40.000000000 -0500
13322 ++++ linux-2.6.27.10/drivers/usb/class/cdc-acm.c 2008-11-18 11:40:52.000000000 -0500
13323 +@@ -1381,7 +1381,7 @@ static struct usb_device_id acm_ids[] =
13324 + USB_CDC_ACM_PROTO_AT_CDMA) },
13325 +
13326 + /* NOTE: COMM/ACM/0xff is likely MSFT RNDIS ... NOT a modem!! */
13327 +- { }
13328 ++ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
13329 + };
13330 +
13331 + MODULE_DEVICE_TABLE (usb, acm_ids);
13332 +diff -urNp linux-2.6.27.10/drivers/usb/class/usblp.c linux-2.6.27.10/drivers/usb/class/usblp.c
13333 +--- linux-2.6.27.10/drivers/usb/class/usblp.c 2008-11-07 12:55:34.000000000 -0500
13334 ++++ linux-2.6.27.10/drivers/usb/class/usblp.c 2008-11-18 03:38:45.000000000 -0500
13335 +@@ -227,7 +227,7 @@ static const struct quirk_printer_struct
13336 + { 0x0409, 0xf1be, USBLP_QUIRK_BIDIR }, /* NEC Picty800 (HP OEM) */
13337 + { 0x0482, 0x0010, USBLP_QUIRK_BIDIR }, /* Kyocera Mita FS 820, by zut <kernel@×××.de> */
13338 + { 0x04b8, 0x0202, USBLP_QUIRK_BAD_CLASS }, /* Seiko Epson Receipt Printer M129C */
13339 +- { 0, 0 }
13340 ++ { 0, 0, 0 }
13341 + };
13342 +
13343 + static int usblp_wwait(struct usblp *usblp, int nonblock);
13344 +@@ -1401,7 +1401,7 @@ static struct usb_device_id usblp_ids []
13345 + { USB_INTERFACE_INFO(7, 1, 2) },
13346 + { USB_INTERFACE_INFO(7, 1, 3) },
13347 + { USB_DEVICE(0x04b8, 0x0202) }, /* Seiko Epson Receipt Printer M129C */
13348 +- { } /* Terminating entry */
13349 ++ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } /* Terminating entry */
13350 + };
13351 +
13352 + MODULE_DEVICE_TABLE (usb, usblp_ids);
13353 +diff -urNp linux-2.6.27.10/drivers/usb/core/hub.c linux-2.6.27.10/drivers/usb/core/hub.c
13354 +--- linux-2.6.27.10/drivers/usb/core/hub.c 2008-11-07 12:55:34.000000000 -0500
13355 ++++ linux-2.6.27.10/drivers/usb/core/hub.c 2008-11-18 03:38:45.000000000 -0500
13356 +@@ -3111,7 +3111,7 @@ static struct usb_device_id hub_id_table
13357 + .bDeviceClass = USB_CLASS_HUB},
13358 + { .match_flags = USB_DEVICE_ID_MATCH_INT_CLASS,
13359 + .bInterfaceClass = USB_CLASS_HUB},
13360 +- { } /* Terminating entry */
13361 ++ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } /* Terminating entry */
13362 + };
13363 +
13364 + MODULE_DEVICE_TABLE (usb, hub_id_table);
13365 +diff -urNp linux-2.6.27.10/drivers/usb/host/ehci-pci.c linux-2.6.27.10/drivers/usb/host/ehci-pci.c
13366 +--- linux-2.6.27.10/drivers/usb/host/ehci-pci.c 2008-12-10 22:35:37.000000000 -0500
13367 ++++ linux-2.6.27.10/drivers/usb/host/ehci-pci.c 2008-12-10 22:35:46.000000000 -0500
13368 +@@ -414,7 +414,7 @@ static const struct pci_device_id pci_id
13369 + PCI_DEVICE_CLASS(PCI_CLASS_SERIAL_USB_EHCI, ~0),
13370 + .driver_data = (unsigned long) &ehci_pci_hc_driver,
13371 + },
13372 +- { /* end: all zeroes */ }
13373 ++ { 0, 0, 0, 0, 0, 0, 0 }
13374 + };
13375 + MODULE_DEVICE_TABLE(pci, pci_ids);
13376 +
13377 +diff -urNp linux-2.6.27.10/drivers/usb/host/uhci-hcd.c linux-2.6.27.10/drivers/usb/host/uhci-hcd.c
13378 +--- linux-2.6.27.10/drivers/usb/host/uhci-hcd.c 2008-11-07 12:55:34.000000000 -0500
13379 ++++ linux-2.6.27.10/drivers/usb/host/uhci-hcd.c 2008-11-18 03:38:45.000000000 -0500
13380 +@@ -928,7 +928,7 @@ static const struct pci_device_id uhci_p
13381 + /* handle any USB UHCI controller */
13382 + PCI_DEVICE_CLASS(PCI_CLASS_SERIAL_USB_UHCI, ~0),
13383 + .driver_data = (unsigned long) &uhci_driver,
13384 +- }, { /* end: all zeroes */ }
13385 ++ }, { 0, 0, 0, 0, 0, 0, 0 }
13386 + };
13387 +
13388 + MODULE_DEVICE_TABLE(pci, uhci_pci_ids);
13389 +diff -urNp linux-2.6.27.10/drivers/usb/storage/debug.h linux-2.6.27.10/drivers/usb/storage/debug.h
13390 +--- linux-2.6.27.10/drivers/usb/storage/debug.h 2008-11-07 12:55:34.000000000 -0500
13391 ++++ linux-2.6.27.10/drivers/usb/storage/debug.h 2008-11-18 03:38:45.000000000 -0500
13392 +@@ -54,9 +54,9 @@ void usb_stor_show_sense( unsigned char
13393 + #define US_DEBUGPX(x...) printk( x )
13394 + #define US_DEBUG(x) x
13395 + #else
13396 +-#define US_DEBUGP(x...)
13397 +-#define US_DEBUGPX(x...)
13398 +-#define US_DEBUG(x)
13399 ++#define US_DEBUGP(x...) do {} while (0)
13400 ++#define US_DEBUGPX(x...) do {} while (0)
13401 ++#define US_DEBUG(x) do {} while (0)
13402 + #endif
13403 +
13404 + #endif
13405 +diff -urNp linux-2.6.27.10/drivers/usb/storage/usb.c linux-2.6.27.10/drivers/usb/storage/usb.c
13406 +--- linux-2.6.27.10/drivers/usb/storage/usb.c 2008-11-07 12:55:34.000000000 -0500
13407 ++++ linux-2.6.27.10/drivers/usb/storage/usb.c 2008-11-18 03:38:45.000000000 -0500
13408 +@@ -136,7 +136,7 @@ static struct usb_device_id storage_usb_
13409 + #undef UNUSUAL_DEV
13410 + #undef USUAL_DEV
13411 + /* Terminating entry */
13412 +- { }
13413 ++ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
13414 + };
13415 +
13416 + MODULE_DEVICE_TABLE (usb, storage_usb_ids);
13417 +@@ -176,7 +176,7 @@ static struct us_unusual_dev us_unusual_
13418 + # undef USUAL_DEV
13419 +
13420 + /* Terminating entry */
13421 +- { NULL }
13422 ++ { NULL, NULL, 0, 0, NULL }
13423 + };
13424 +
13425 +
13426 +diff -urNp linux-2.6.27.10/drivers/video/fbcmap.c linux-2.6.27.10/drivers/video/fbcmap.c
13427 +--- linux-2.6.27.10/drivers/video/fbcmap.c 2008-11-07 12:55:34.000000000 -0500
13428 ++++ linux-2.6.27.10/drivers/video/fbcmap.c 2008-11-18 03:38:45.000000000 -0500
13429 +@@ -250,8 +250,7 @@ int fb_set_user_cmap(struct fb_cmap_user
13430 + int rc, size = cmap->len * sizeof(u16);
13431 + struct fb_cmap umap;
13432 +
13433 +- if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
13434 +- !info->fbops->fb_setcmap))
13435 ++ if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap)
13436 + return -EINVAL;
13437 +
13438 + memset(&umap, 0, sizeof(struct fb_cmap));
13439 +diff -urNp linux-2.6.27.10/drivers/video/fbmem.c linux-2.6.27.10/drivers/video/fbmem.c
13440 +--- linux-2.6.27.10/drivers/video/fbmem.c 2008-12-10 22:35:37.000000000 -0500
13441 ++++ linux-2.6.27.10/drivers/video/fbmem.c 2008-12-10 22:35:46.000000000 -0500
13442 +@@ -395,7 +395,7 @@ static void fb_do_show_logo(struct fb_in
13443 + image->dx += image->width + 8;
13444 + }
13445 + } else if (rotate == FB_ROTATE_UD) {
13446 +- for (x = 0; x < num && image->dx >= 0; x++) {
13447 ++ for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
13448 + info->fbops->fb_imageblit(info, image);
13449 + image->dx -= image->width + 8;
13450 + }
13451 +@@ -407,7 +407,7 @@ static void fb_do_show_logo(struct fb_in
13452 + image->dy += image->height + 8;
13453 + }
13454 + } else if (rotate == FB_ROTATE_CCW) {
13455 +- for (x = 0; x < num && image->dy >= 0; x++) {
13456 ++ for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
13457 + info->fbops->fb_imageblit(info, image);
13458 + image->dy -= image->height + 8;
13459 + }
13460 +@@ -1083,7 +1083,7 @@ fb_ioctl(struct inode *inode, struct fil
13461 + return - EFAULT;
13462 + if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
13463 + return -EINVAL;
13464 +- if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
13465 ++ if (con2fb.framebuffer >= FB_MAX)
13466 + return -EINVAL;
13467 + #ifdef CONFIG_KMOD
13468 + if (!registered_fb[con2fb.framebuffer])
13469 +diff -urNp linux-2.6.27.10/drivers/video/fbmon.c linux-2.6.27.10/drivers/video/fbmon.c
13470 +--- linux-2.6.27.10/drivers/video/fbmon.c 2008-11-07 12:55:34.000000000 -0500
13471 ++++ linux-2.6.27.10/drivers/video/fbmon.c 2008-11-18 03:38:45.000000000 -0500
13472 +@@ -45,7 +45,7 @@
13473 + #ifdef DEBUG
13474 + #define DPRINTK(fmt, args...) printk(fmt,## args)
13475 + #else
13476 +-#define DPRINTK(fmt, args...)
13477 ++#define DPRINTK(fmt, args...) do {} while (0)
13478 + #endif
13479 +
13480 + #define FBMON_FIX_HEADER 1
13481 +diff -urNp linux-2.6.27.10/drivers/video/i810/i810_accel.c linux-2.6.27.10/drivers/video/i810/i810_accel.c
13482 +--- linux-2.6.27.10/drivers/video/i810/i810_accel.c 2008-11-07 12:55:34.000000000 -0500
13483 ++++ linux-2.6.27.10/drivers/video/i810/i810_accel.c 2008-11-18 03:38:45.000000000 -0500
13484 +@@ -73,6 +73,7 @@ static inline int wait_for_space(struct
13485 + }
13486 + }
13487 + printk("ringbuffer lockup!!!\n");
13488 ++ printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
13489 + i810_report_error(mmio);
13490 + par->dev_flags |= LOCKUP;
13491 + info->pixmap.scan_align = 1;
13492 +diff -urNp linux-2.6.27.10/drivers/video/i810/i810_main.c linux-2.6.27.10/drivers/video/i810/i810_main.c
13493 +--- linux-2.6.27.10/drivers/video/i810/i810_main.c 2008-11-07 12:55:34.000000000 -0500
13494 ++++ linux-2.6.27.10/drivers/video/i810/i810_main.c 2008-11-18 03:38:45.000000000 -0500
13495 +@@ -120,7 +120,7 @@ static struct pci_device_id i810fb_pci_t
13496 + PCI_ANY_ID, PCI_ANY_ID, 0, 0, 4 },
13497 + { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82815_CGC,
13498 + PCI_ANY_ID, PCI_ANY_ID, 0, 0, 5 },
13499 +- { 0 },
13500 ++ { 0, 0, 0, 0, 0, 0, 0 },
13501 + };
13502 +
13503 + static struct pci_driver i810fb_driver = {
13504 +@@ -1509,7 +1509,7 @@ static int i810fb_cursor(struct fb_info
13505 + int size = ((cursor->image.width + 7) >> 3) *
13506 + cursor->image.height;
13507 + int i;
13508 +- u8 *data = kmalloc(64 * 8, GFP_ATOMIC);
13509 ++ u8 *data = kmalloc(64 * 8, GFP_KERNEL);
13510 +
13511 + if (data == NULL)
13512 + return -ENOMEM;
13513 +diff -urNp linux-2.6.27.10/drivers/video/modedb.c linux-2.6.27.10/drivers/video/modedb.c
13514 +--- linux-2.6.27.10/drivers/video/modedb.c 2008-11-07 12:55:34.000000000 -0500
13515 ++++ linux-2.6.27.10/drivers/video/modedb.c 2008-11-18 03:38:45.000000000 -0500
13516 +@@ -38,232 +38,232 @@ static const struct fb_videomode modedb[
13517 + {
13518 + /* 640x400 @ 70 Hz, 31.5 kHz hsync */
13519 + NULL, 70, 640, 400, 39721, 40, 24, 39, 9, 96, 2,
13520 +- 0, FB_VMODE_NONINTERLACED
13521 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13522 + }, {
13523 + /* 640x480 @ 60 Hz, 31.5 kHz hsync */
13524 + NULL, 60, 640, 480, 39721, 40, 24, 32, 11, 96, 2,
13525 +- 0, FB_VMODE_NONINTERLACED
13526 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13527 + }, {
13528 + /* 800x600 @ 56 Hz, 35.15 kHz hsync */
13529 + NULL, 56, 800, 600, 27777, 128, 24, 22, 1, 72, 2,
13530 +- 0, FB_VMODE_NONINTERLACED
13531 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13532 + }, {
13533 + /* 1024x768 @ 87 Hz interlaced, 35.5 kHz hsync */
13534 + NULL, 87, 1024, 768, 22271, 56, 24, 33, 8, 160, 8,
13535 +- 0, FB_VMODE_INTERLACED
13536 ++ 0, FB_VMODE_INTERLACED, FB_MODE_IS_UNKNOWN
13537 + }, {
13538 + /* 640x400 @ 85 Hz, 37.86 kHz hsync */
13539 + NULL, 85, 640, 400, 31746, 96, 32, 41, 1, 64, 3,
13540 +- FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
13541 ++ FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13542 + }, {
13543 + /* 640x480 @ 72 Hz, 36.5 kHz hsync */
13544 + NULL, 72, 640, 480, 31746, 144, 40, 30, 8, 40, 3,
13545 +- 0, FB_VMODE_NONINTERLACED
13546 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13547 + }, {
13548 + /* 640x480 @ 75 Hz, 37.50 kHz hsync */
13549 + NULL, 75, 640, 480, 31746, 120, 16, 16, 1, 64, 3,
13550 +- 0, FB_VMODE_NONINTERLACED
13551 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13552 + }, {
13553 + /* 800x600 @ 60 Hz, 37.8 kHz hsync */
13554 + NULL, 60, 800, 600, 25000, 88, 40, 23, 1, 128, 4,
13555 +- FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
13556 ++ FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13557 + }, {
13558 + /* 640x480 @ 85 Hz, 43.27 kHz hsync */
13559 + NULL, 85, 640, 480, 27777, 80, 56, 25, 1, 56, 3,
13560 +- 0, FB_VMODE_NONINTERLACED
13561 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13562 + }, {
13563 + /* 1152x864 @ 89 Hz interlaced, 44 kHz hsync */
13564 + NULL, 89, 1152, 864, 15384, 96, 16, 110, 1, 216, 10,
13565 +- 0, FB_VMODE_INTERLACED
13566 ++ 0, FB_VMODE_INTERLACED, FB_MODE_IS_UNKNOWN
13567 + }, {
13568 + /* 800x600 @ 72 Hz, 48.0 kHz hsync */
13569 + NULL, 72, 800, 600, 20000, 64, 56, 23, 37, 120, 6,
13570 +- FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
13571 ++ FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13572 + }, {
13573 + /* 1024x768 @ 60 Hz, 48.4 kHz hsync */
13574 + NULL, 60, 1024, 768, 15384, 168, 8, 29, 3, 144, 6,
13575 +- 0, FB_VMODE_NONINTERLACED
13576 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13577 + }, {
13578 + /* 640x480 @ 100 Hz, 53.01 kHz hsync */
13579 + NULL, 100, 640, 480, 21834, 96, 32, 36, 8, 96, 6,
13580 +- 0, FB_VMODE_NONINTERLACED
13581 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13582 + }, {
13583 + /* 1152x864 @ 60 Hz, 53.5 kHz hsync */
13584 + NULL, 60, 1152, 864, 11123, 208, 64, 16, 4, 256, 8,
13585 +- 0, FB_VMODE_NONINTERLACED
13586 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13587 + }, {
13588 + /* 800x600 @ 85 Hz, 55.84 kHz hsync */
13589 + NULL, 85, 800, 600, 16460, 160, 64, 36, 16, 64, 5,
13590 +- 0, FB_VMODE_NONINTERLACED
13591 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13592 + }, {
13593 + /* 1024x768 @ 70 Hz, 56.5 kHz hsync */
13594 + NULL, 70, 1024, 768, 13333, 144, 24, 29, 3, 136, 6,
13595 +- 0, FB_VMODE_NONINTERLACED
13596 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13597 + }, {
13598 + /* 1280x1024 @ 87 Hz interlaced, 51 kHz hsync */
13599 + NULL, 87, 1280, 1024, 12500, 56, 16, 128, 1, 216, 12,
13600 +- 0, FB_VMODE_INTERLACED
13601 ++ 0, FB_VMODE_INTERLACED, FB_MODE_IS_UNKNOWN
13602 + }, {
13603 + /* 800x600 @ 100 Hz, 64.02 kHz hsync */
13604 + NULL, 100, 800, 600, 14357, 160, 64, 30, 4, 64, 6,
13605 +- 0, FB_VMODE_NONINTERLACED
13606 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13607 + }, {
13608 + /* 1024x768 @ 76 Hz, 62.5 kHz hsync */
13609 + NULL, 76, 1024, 768, 11764, 208, 8, 36, 16, 120, 3,
13610 +- 0, FB_VMODE_NONINTERLACED
13611 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13612 + }, {
13613 + /* 1152x864 @ 70 Hz, 62.4 kHz hsync */
13614 + NULL, 70, 1152, 864, 10869, 106, 56, 20, 1, 160, 10,
13615 +- 0, FB_VMODE_NONINTERLACED
13616 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13617 + }, {
13618 + /* 1280x1024 @ 61 Hz, 64.2 kHz hsync */
13619 + NULL, 61, 1280, 1024, 9090, 200, 48, 26, 1, 184, 3,
13620 +- 0, FB_VMODE_NONINTERLACED
13621 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13622 + }, {
13623 + /* 1400x1050 @ 60Hz, 63.9 kHz hsync */
13624 + NULL, 60, 1400, 1050, 9259, 136, 40, 13, 1, 112, 3,
13625 +- 0, FB_VMODE_NONINTERLACED
13626 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13627 + }, {
13628 + /* 1400x1050 @ 75,107 Hz, 82,392 kHz +hsync +vsync*/
13629 + NULL, 75, 1400, 1050, 7190, 120, 56, 23, 10, 112, 13,
13630 +- FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
13631 ++ FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13632 + }, {
13633 + /* 1400x1050 @ 60 Hz, ? kHz +hsync +vsync*/
13634 + NULL, 60, 1400, 1050, 9259, 128, 40, 12, 0, 112, 3,
13635 +- FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
13636 ++ FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13637 + }, {
13638 + /* 1024x768 @ 85 Hz, 70.24 kHz hsync */
13639 + NULL, 85, 1024, 768, 10111, 192, 32, 34, 14, 160, 6,
13640 +- 0, FB_VMODE_NONINTERLACED
13641 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13642 + }, {
13643 + /* 1152x864 @ 78 Hz, 70.8 kHz hsync */
13644 + NULL, 78, 1152, 864, 9090, 228, 88, 32, 0, 84, 12,
13645 +- 0, FB_VMODE_NONINTERLACED
13646 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13647 + }, {
13648 + /* 1280x1024 @ 70 Hz, 74.59 kHz hsync */
13649 + NULL, 70, 1280, 1024, 7905, 224, 32, 28, 8, 160, 8,
13650 +- 0, FB_VMODE_NONINTERLACED
13651 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13652 + }, {
13653 + /* 1600x1200 @ 60Hz, 75.00 kHz hsync */
13654 + NULL, 60, 1600, 1200, 6172, 304, 64, 46, 1, 192, 3,
13655 +- FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
13656 ++ FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13657 + }, {
13658 + /* 1152x864 @ 84 Hz, 76.0 kHz hsync */
13659 + NULL, 84, 1152, 864, 7407, 184, 312, 32, 0, 128, 12,
13660 +- 0, FB_VMODE_NONINTERLACED
13661 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13662 + }, {
13663 + /* 1280x1024 @ 74 Hz, 78.85 kHz hsync */
13664 + NULL, 74, 1280, 1024, 7407, 256, 32, 34, 3, 144, 3,
13665 +- 0, FB_VMODE_NONINTERLACED
13666 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13667 + }, {
13668 + /* 1024x768 @ 100Hz, 80.21 kHz hsync */
13669 + NULL, 100, 1024, 768, 8658, 192, 32, 21, 3, 192, 10,
13670 +- 0, FB_VMODE_NONINTERLACED
13671 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13672 + }, {
13673 + /* 1280x1024 @ 76 Hz, 81.13 kHz hsync */
13674 + NULL, 76, 1280, 1024, 7407, 248, 32, 34, 3, 104, 3,
13675 +- 0, FB_VMODE_NONINTERLACED
13676 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13677 + }, {
13678 + /* 1600x1200 @ 70 Hz, 87.50 kHz hsync */
13679 + NULL, 70, 1600, 1200, 5291, 304, 64, 46, 1, 192, 3,
13680 +- 0, FB_VMODE_NONINTERLACED
13681 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13682 + }, {
13683 + /* 1152x864 @ 100 Hz, 89.62 kHz hsync */
13684 + NULL, 100, 1152, 864, 7264, 224, 32, 17, 2, 128, 19,
13685 +- 0, FB_VMODE_NONINTERLACED
13686 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13687 + }, {
13688 + /* 1280x1024 @ 85 Hz, 91.15 kHz hsync */
13689 + NULL, 85, 1280, 1024, 6349, 224, 64, 44, 1, 160, 3,
13690 +- FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
13691 ++ FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13692 + }, {
13693 + /* 1600x1200 @ 75 Hz, 93.75 kHz hsync */
13694 + NULL, 75, 1600, 1200, 4938, 304, 64, 46, 1, 192, 3,
13695 +- FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
13696 ++ FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13697 + }, {
13698 + /* 1680x1050 @ 60 Hz, 65.191 kHz hsync */
13699 + NULL, 60, 1680, 1050, 6848, 280, 104, 30, 3, 176, 6,
13700 +- FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
13701 ++ FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13702 + }, {
13703 + /* 1600x1200 @ 85 Hz, 105.77 kHz hsync */
13704 + NULL, 85, 1600, 1200, 4545, 272, 16, 37, 4, 192, 3,
13705 +- FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
13706 ++ FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13707 + }, {
13708 + /* 1280x1024 @ 100 Hz, 107.16 kHz hsync */
13709 + NULL, 100, 1280, 1024, 5502, 256, 32, 26, 7, 128, 15,
13710 +- 0, FB_VMODE_NONINTERLACED
13711 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13712 + }, {
13713 + /* 1800x1440 @ 64Hz, 96.15 kHz hsync */
13714 + NULL, 64, 1800, 1440, 4347, 304, 96, 46, 1, 192, 3,
13715 +- FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
13716 ++ FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13717 + }, {
13718 + /* 1800x1440 @ 70Hz, 104.52 kHz hsync */
13719 + NULL, 70, 1800, 1440, 4000, 304, 96, 46, 1, 192, 3,
13720 +- FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
13721 ++ FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13722 + }, {
13723 + /* 512x384 @ 78 Hz, 31.50 kHz hsync */
13724 + NULL, 78, 512, 384, 49603, 48, 16, 16, 1, 64, 3,
13725 +- 0, FB_VMODE_NONINTERLACED
13726 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13727 + }, {
13728 + /* 512x384 @ 85 Hz, 34.38 kHz hsync */
13729 + NULL, 85, 512, 384, 45454, 48, 16, 16, 1, 64, 3,
13730 +- 0, FB_VMODE_NONINTERLACED
13731 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13732 + }, {
13733 + /* 320x200 @ 70 Hz, 31.5 kHz hsync, 8:5 aspect ratio */
13734 + NULL, 70, 320, 200, 79440, 16, 16, 20, 4, 48, 1,
13735 +- 0, FB_VMODE_DOUBLE
13736 ++ 0, FB_VMODE_DOUBLE, FB_MODE_IS_UNKNOWN
13737 + }, {
13738 + /* 320x240 @ 60 Hz, 31.5 kHz hsync, 4:3 aspect ratio */
13739 + NULL, 60, 320, 240, 79440, 16, 16, 16, 5, 48, 1,
13740 +- 0, FB_VMODE_DOUBLE
13741 ++ 0, FB_VMODE_DOUBLE, FB_MODE_IS_UNKNOWN
13742 + }, {
13743 + /* 320x240 @ 72 Hz, 36.5 kHz hsync */
13744 + NULL, 72, 320, 240, 63492, 16, 16, 16, 4, 48, 2,
13745 +- 0, FB_VMODE_DOUBLE
13746 ++ 0, FB_VMODE_DOUBLE, FB_MODE_IS_UNKNOWN
13747 + }, {
13748 + /* 400x300 @ 56 Hz, 35.2 kHz hsync, 4:3 aspect ratio */
13749 + NULL, 56, 400, 300, 55555, 64, 16, 10, 1, 32, 1,
13750 +- 0, FB_VMODE_DOUBLE
13751 ++ 0, FB_VMODE_DOUBLE, FB_MODE_IS_UNKNOWN
13752 + }, {
13753 + /* 400x300 @ 60 Hz, 37.8 kHz hsync */
13754 + NULL, 60, 400, 300, 50000, 48, 16, 11, 1, 64, 2,
13755 +- 0, FB_VMODE_DOUBLE
13756 ++ 0, FB_VMODE_DOUBLE, FB_MODE_IS_UNKNOWN
13757 + }, {
13758 + /* 400x300 @ 72 Hz, 48.0 kHz hsync */
13759 + NULL, 72, 400, 300, 40000, 32, 24, 11, 19, 64, 3,
13760 +- 0, FB_VMODE_DOUBLE
13761 ++ 0, FB_VMODE_DOUBLE, FB_MODE_IS_UNKNOWN
13762 + }, {
13763 + /* 480x300 @ 56 Hz, 35.2 kHz hsync, 8:5 aspect ratio */
13764 + NULL, 56, 480, 300, 46176, 80, 16, 10, 1, 40, 1,
13765 +- 0, FB_VMODE_DOUBLE
13766 ++ 0, FB_VMODE_DOUBLE, FB_MODE_IS_UNKNOWN
13767 + }, {
13768 + /* 480x300 @ 60 Hz, 37.8 kHz hsync */
13769 + NULL, 60, 480, 300, 41858, 56, 16, 11, 1, 80, 2,
13770 +- 0, FB_VMODE_DOUBLE
13771 ++ 0, FB_VMODE_DOUBLE, FB_MODE_IS_UNKNOWN
13772 + }, {
13773 + /* 480x300 @ 63 Hz, 39.6 kHz hsync */
13774 + NULL, 63, 480, 300, 40000, 56, 16, 11, 1, 80, 2,
13775 +- 0, FB_VMODE_DOUBLE
13776 ++ 0, FB_VMODE_DOUBLE, FB_MODE_IS_UNKNOWN
13777 + }, {
13778 + /* 480x300 @ 72 Hz, 48.0 kHz hsync */
13779 + NULL, 72, 480, 300, 33386, 40, 24, 11, 19, 80, 3,
13780 +- 0, FB_VMODE_DOUBLE
13781 ++ 0, FB_VMODE_DOUBLE, FB_MODE_IS_UNKNOWN
13782 + }, {
13783 + /* 1920x1200 @ 60 Hz, 74.5 Khz hsync */
13784 + NULL, 60, 1920, 1200, 5177, 128, 336, 1, 38, 208, 3,
13785 + FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
13786 +- FB_VMODE_NONINTERLACED
13787 ++ FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13788 + }, {
13789 + /* 1152x768, 60 Hz, PowerBook G4 Titanium I and II */
13790 + NULL, 60, 1152, 768, 14047, 158, 26, 29, 3, 136, 6,
13791 +- FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
13792 ++ FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13793 + }, {
13794 + /* 1366x768, 60 Hz, 47.403 kHz hsync, WXGA 16:9 aspect ratio */
13795 + NULL, 60, 1366, 768, 13806, 120, 10, 14, 3, 32, 5,
13796 +- 0, FB_VMODE_NONINTERLACED
13797 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13798 + }, {
13799 + /* 1280x800, 60 Hz, 47.403 kHz hsync, WXGA 16:10 aspect ratio */
13800 + NULL, 60, 1280, 800, 12048, 200, 64, 24, 1, 136, 3,
13801 +- 0, FB_VMODE_NONINTERLACED
13802 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
13803 + },
13804 + };
13805 +
13806 +diff -urNp linux-2.6.27.10/drivers/video/uvesafb.c linux-2.6.27.10/drivers/video/uvesafb.c
13807 +--- linux-2.6.27.10/drivers/video/uvesafb.c 2008-11-07 12:55:34.000000000 -0500
13808 ++++ linux-2.6.27.10/drivers/video/uvesafb.c 2008-11-18 03:38:45.000000000 -0500
13809 +@@ -18,6 +18,7 @@
13810 + #include <linux/fb.h>
13811 + #include <linux/io.h>
13812 + #include <linux/mutex.h>
13813 ++#include <linux/moduleloader.h>
13814 + #include <video/edid.h>
13815 + #include <video/uvesafb.h>
13816 + #ifdef CONFIG_X86
13817 +@@ -117,7 +118,7 @@ static int uvesafb_helper_start(void)
13818 + NULL,
13819 + };
13820 +
13821 +- return call_usermodehelper(v86d_path, argv, envp, 1);
13822 ++ return call_usermodehelper(v86d_path, argv, envp, UMH_WAIT_PROC);
13823 + }
13824 +
13825 + /*
13826 +@@ -569,10 +570,34 @@ static int __devinit uvesafb_vbe_getpmi(
13827 + if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
13828 + par->pmi_setpal = par->ypan = 0;
13829 + } else {
13830 ++
13831 ++#ifdef CONFIG_PAX_KERNEXEC
13832 ++#ifdef CONFIG_MODULES
13833 ++ unsigned long cr0;
13834 ++
13835 ++ par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
13836 ++#endif
13837 ++ if (!par->pmi_code) {
13838 ++ par->pmi_setpal = par->ypan = 0;
13839 ++ return 0;
13840 ++ }
13841 ++#endif
13842 ++
13843 + par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
13844 + + task->t.regs.edi);
13845 ++
13846 ++#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
13847 ++ pax_open_kernel(cr0);
13848 ++ memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
13849 ++ pax_close_kernel(cr0);
13850 ++
13851 ++ par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
13852 ++ par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
13853 ++#else
13854 + par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
13855 + par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
13856 ++#endif
13857 ++
13858 + printk(KERN_INFO "uvesafb: protected mode interface info at "
13859 + "%04x:%04x\n",
13860 + (u16)task->t.regs.es, (u16)task->t.regs.edi);
13861 +@@ -1827,6 +1852,11 @@ out:
13862 + if (par->vbe_modes)
13863 + kfree(par->vbe_modes);
13864 +
13865 ++#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
13866 ++ if (par->pmi_code)
13867 ++ module_free_exec(NULL, par->pmi_code);
13868 ++#endif
13869 ++
13870 + framebuffer_release(info);
13871 + return err;
13872 + }
13873 +@@ -1853,6 +1883,12 @@ static int uvesafb_remove(struct platfor
13874 + kfree(par->vbe_state_orig);
13875 + if (par->vbe_state_saved)
13876 + kfree(par->vbe_state_saved);
13877 ++
13878 ++#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
13879 ++ if (par->pmi_code)
13880 ++ module_free_exec(NULL, par->pmi_code);
13881 ++#endif
13882 ++
13883 + }
13884 +
13885 + framebuffer_release(info);
13886 +diff -urNp linux-2.6.27.10/drivers/video/vesafb.c linux-2.6.27.10/drivers/video/vesafb.c
13887 +--- linux-2.6.27.10/drivers/video/vesafb.c 2008-11-07 12:55:34.000000000 -0500
13888 ++++ linux-2.6.27.10/drivers/video/vesafb.c 2008-11-18 03:38:45.000000000 -0500
13889 +@@ -9,6 +9,7 @@
13890 + */
13891 +
13892 + #include <linux/module.h>
13893 ++#include <linux/moduleloader.h>
13894 + #include <linux/kernel.h>
13895 + #include <linux/errno.h>
13896 + #include <linux/string.h>
13897 +@@ -53,8 +54,8 @@ static int vram_remap __initdata; /*
13898 + static int vram_total __initdata; /* Set total amount of memory */
13899 + static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
13900 + static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
13901 +-static void (*pmi_start)(void) __read_mostly;
13902 +-static void (*pmi_pal) (void) __read_mostly;
13903 ++static void (*pmi_start)(void) __read_only;
13904 ++static void (*pmi_pal) (void) __read_only;
13905 + static int depth __read_mostly;
13906 + static int vga_compat __read_mostly;
13907 + /* --------------------------------------------------------------------- */
13908 +@@ -224,6 +225,7 @@ static int __init vesafb_probe(struct pl
13909 + unsigned int size_vmode;
13910 + unsigned int size_remap;
13911 + unsigned int size_total;
13912 ++ void *pmi_code = NULL;
13913 +
13914 + if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
13915 + return -ENODEV;
13916 +@@ -266,10 +268,6 @@ static int __init vesafb_probe(struct pl
13917 + size_remap = size_total;
13918 + vesafb_fix.smem_len = size_remap;
13919 +
13920 +-#ifndef __i386__
13921 +- screen_info.vesapm_seg = 0;
13922 +-#endif
13923 +-
13924 + if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
13925 + printk(KERN_WARNING
13926 + "vesafb: cannot reserve video memory at 0x%lx\n",
13927 +@@ -302,9 +300,21 @@ static int __init vesafb_probe(struct pl
13928 + printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
13929 + vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
13930 +
13931 ++#ifdef __i386__
13932 ++
13933 ++#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
13934 ++ pmi_code = module_alloc_exec(screen_info.vesapm_size);
13935 ++ if (!pmi_code)
13936 ++#elif !defined(CONFIG_PAX_KERNEXEC)
13937 ++ if (0)
13938 ++#endif
13939 ++
13940 ++#endif
13941 ++ screen_info.vesapm_seg = 0;
13942 ++
13943 + if (screen_info.vesapm_seg) {
13944 +- printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
13945 +- screen_info.vesapm_seg,screen_info.vesapm_off);
13946 ++ printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
13947 ++ screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
13948 + }
13949 +
13950 + if (screen_info.vesapm_seg < 0xc000)
13951 +@@ -312,9 +322,29 @@ static int __init vesafb_probe(struct pl
13952 +
13953 + if (ypan || pmi_setpal) {
13954 + unsigned short *pmi_base;
13955 +- pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
13956 +- pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
13957 +- pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
13958 ++
13959 ++#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
13960 ++ unsigned long cr0;
13961 ++#endif
13962 ++
13963 ++ pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
13964 ++
13965 ++#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
13966 ++ pax_open_kernel(cr0);
13967 ++ memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
13968 ++#else
13969 ++ pmi_code = pmi_base;
13970 ++#endif
13971 ++
13972 ++ pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
13973 ++ pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
13974 ++
13975 ++#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
13976 ++ pmi_start = ktva_ktla(pmi_start);
13977 ++ pmi_pal = ktva_ktla(pmi_pal);
13978 ++ pax_close_kernel(cr0);
13979 ++#endif
13980 ++
13981 + printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
13982 + if (pmi_base[3]) {
13983 + printk(KERN_INFO "vesafb: pmi: ports = ");
13984 +@@ -456,6 +486,11 @@ static int __init vesafb_probe(struct pl
13985 + info->node, info->fix.id);
13986 + return 0;
13987 + err:
13988 ++
13989 ++#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
13990 ++ module_free_exec(NULL, pmi_code);
13991 ++#endif
13992 ++
13993 + if (info->screen_base)
13994 + iounmap(info->screen_base);
13995 + framebuffer_release(info);
13996 +diff -urNp linux-2.6.27.10/fs/9p/vfs_inode.c linux-2.6.27.10/fs/9p/vfs_inode.c
13997 +--- linux-2.6.27.10/fs/9p/vfs_inode.c 2008-11-07 12:55:34.000000000 -0500
13998 ++++ linux-2.6.27.10/fs/9p/vfs_inode.c 2008-11-18 03:38:45.000000000 -0500
13999 +@@ -1021,7 +1021,7 @@ static void *v9fs_vfs_follow_link(struct
14000 + static void
14001 + v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
14002 + {
14003 +- char *s = nd_get_link(nd);
14004 ++ const char *s = nd_get_link(nd);
14005 +
14006 + P9_DPRINTK(P9_DEBUG_VFS, " %s %s\n", dentry->d_name.name, s);
14007 + if (!IS_ERR(s))
14008 +diff -urNp linux-2.6.27.10/fs/aio.c linux-2.6.27.10/fs/aio.c
14009 +--- linux-2.6.27.10/fs/aio.c 2008-11-07 12:55:34.000000000 -0500
14010 ++++ linux-2.6.27.10/fs/aio.c 2008-11-18 03:38:45.000000000 -0500
14011 +@@ -114,7 +114,7 @@ static int aio_setup_ring(struct kioctx
14012 + size += sizeof(struct io_event) * nr_events;
14013 + nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
14014 +
14015 +- if (nr_pages < 0)
14016 ++ if (nr_pages <= 0)
14017 + return -EINVAL;
14018 +
14019 + nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
14020 +diff -urNp linux-2.6.27.10/fs/autofs4/symlink.c linux-2.6.27.10/fs/autofs4/symlink.c
14021 +--- linux-2.6.27.10/fs/autofs4/symlink.c 2008-11-07 12:55:34.000000000 -0500
14022 ++++ linux-2.6.27.10/fs/autofs4/symlink.c 2008-11-18 03:38:45.000000000 -0500
14023 +@@ -15,7 +15,7 @@
14024 + static void *autofs4_follow_link(struct dentry *dentry, struct nameidata *nd)
14025 + {
14026 + struct autofs_info *ino = autofs4_dentry_ino(dentry);
14027 +- nd_set_link(nd, (char *)ino->u.symlink);
14028 ++ nd_set_link(nd, ino->u.symlink);
14029 + return NULL;
14030 + }
14031 +
14032 +diff -urNp linux-2.6.27.10/fs/befs/linuxvfs.c linux-2.6.27.10/fs/befs/linuxvfs.c
14033 +--- linux-2.6.27.10/fs/befs/linuxvfs.c 2008-11-07 12:55:34.000000000 -0500
14034 ++++ linux-2.6.27.10/fs/befs/linuxvfs.c 2008-11-18 03:38:45.000000000 -0500
14035 +@@ -490,7 +490,7 @@ static void befs_put_link(struct dentry
14036 + {
14037 + befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
14038 + if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
14039 +- char *link = nd_get_link(nd);
14040 ++ const char *link = nd_get_link(nd);
14041 + if (!IS_ERR(link))
14042 + kfree(link);
14043 + }
14044 +diff -urNp linux-2.6.27.10/fs/binfmt_aout.c linux-2.6.27.10/fs/binfmt_aout.c
14045 +--- linux-2.6.27.10/fs/binfmt_aout.c 2008-11-07 12:55:34.000000000 -0500
14046 ++++ linux-2.6.27.10/fs/binfmt_aout.c 2008-11-18 03:38:45.000000000 -0500
14047 +@@ -24,6 +24,7 @@
14048 + #include <linux/binfmts.h>
14049 + #include <linux/personality.h>
14050 + #include <linux/init.h>
14051 ++#include <linux/grsecurity.h>
14052 +
14053 + #include <asm/system.h>
14054 + #include <asm/uaccess.h>
14055 +@@ -124,18 +125,22 @@ static int aout_core_dump(long signr, st
14056 + /* If the size of the dump file exceeds the rlimit, then see what would happen
14057 + if we wrote the stack, but not the data area. */
14058 + #ifdef __sparc__
14059 ++ gr_learn_resource(current, RLIMIT_CORE, dump.u_dsize + dump.u_ssize, 1);
14060 + if ((dump.u_dsize + dump.u_ssize) > limit)
14061 + dump.u_dsize = 0;
14062 + #else
14063 ++ gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
14064 + if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > limit)
14065 + dump.u_dsize = 0;
14066 + #endif
14067 +
14068 + /* Make sure we have enough room to write the stack and data areas. */
14069 + #ifdef __sparc__
14070 ++ gr_learn_resource(current, RLIMIT_CORE, dump.u_ssize, 1);
14071 + if (dump.u_ssize > limit)
14072 + dump.u_ssize = 0;
14073 + #else
14074 ++ gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
14075 + if ((dump.u_ssize + 1) * PAGE_SIZE > limit)
14076 + dump.u_ssize = 0;
14077 + #endif
14078 +@@ -291,6 +296,8 @@ static int load_aout_binary(struct linux
14079 + rlim = current->signal->rlim[RLIMIT_DATA].rlim_cur;
14080 + if (rlim >= RLIM_INFINITY)
14081 + rlim = ~0;
14082 ++
14083 ++ gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
14084 + if (ex.a_data + ex.a_bss > rlim)
14085 + return -ENOMEM;
14086 +
14087 +@@ -322,6 +329,28 @@ static int load_aout_binary(struct linux
14088 +
14089 + compute_creds(bprm);
14090 + current->flags &= ~PF_FORKNOEXEC;
14091 ++
14092 ++#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
14093 ++ current->mm->pax_flags = 0UL;
14094 ++#endif
14095 ++
14096 ++#ifdef CONFIG_PAX_PAGEEXEC
14097 ++ if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
14098 ++ current->mm->pax_flags |= MF_PAX_PAGEEXEC;
14099 ++
14100 ++#ifdef CONFIG_PAX_EMUTRAMP
14101 ++ if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
14102 ++ current->mm->pax_flags |= MF_PAX_EMUTRAMP;
14103 ++#endif
14104 ++
14105 ++#ifdef CONFIG_PAX_MPROTECT
14106 ++ if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
14107 ++ current->mm->pax_flags |= MF_PAX_MPROTECT;
14108 ++#endif
14109 ++
14110 ++ }
14111 ++#endif
14112 ++
14113 + #ifdef __sparc__
14114 + if (N_MAGIC(ex) == NMAGIC) {
14115 + loff_t pos = fd_offset;
14116 +@@ -413,7 +442,7 @@ static int load_aout_binary(struct linux
14117 +
14118 + down_write(&current->mm->mmap_sem);
14119 + error = do_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
14120 +- PROT_READ | PROT_WRITE | PROT_EXEC,
14121 ++ PROT_READ | PROT_WRITE,
14122 + MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
14123 + fd_offset + ex.a_text);
14124 + up_write(&current->mm->mmap_sem);
14125 +diff -urNp linux-2.6.27.10/fs/binfmt_elf.c linux-2.6.27.10/fs/binfmt_elf.c
14126 +--- linux-2.6.27.10/fs/binfmt_elf.c 2008-11-07 12:55:34.000000000 -0500
14127 ++++ linux-2.6.27.10/fs/binfmt_elf.c 2008-12-21 00:51:06.000000000 -0500
14128 +@@ -38,10 +38,16 @@
14129 + #include <linux/random.h>
14130 + #include <linux/elf.h>
14131 + #include <linux/utsname.h>
14132 ++#include <linux/grsecurity.h>
14133 ++
14134 + #include <asm/uaccess.h>
14135 + #include <asm/param.h>
14136 + #include <asm/page.h>
14137 +
14138 ++#ifdef CONFIG_PAX_SEGMEXEC
14139 ++#include <asm/desc.h>
14140 ++#endif
14141 ++
14142 + static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs);
14143 + static int load_elf_library(struct file *);
14144 + static unsigned long elf_map(struct file *, unsigned long, struct elf_phdr *,
14145 +@@ -57,6 +63,10 @@ static int elf_core_dump(long signr, str
14146 + #define elf_core_dump NULL
14147 + #endif
14148 +
14149 ++#ifdef CONFIG_PAX_MPROTECT
14150 ++static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
14151 ++#endif
14152 ++
14153 + #if ELF_EXEC_PAGESIZE > PAGE_SIZE
14154 + #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
14155 + #else
14156 +@@ -76,6 +86,11 @@ static struct linux_binfmt elf_format =
14157 + .load_binary = load_elf_binary,
14158 + .load_shlib = load_elf_library,
14159 + .core_dump = elf_core_dump,
14160 ++
14161 ++#ifdef CONFIG_PAX_MPROTECT
14162 ++ .handle_mprotect= elf_handle_mprotect,
14163 ++#endif
14164 ++
14165 + .min_coredump = ELF_EXEC_PAGESIZE,
14166 + .hasvdso = 1
14167 + };
14168 +@@ -84,6 +99,8 @@ static struct linux_binfmt elf_format =
14169 +
14170 + static int set_brk(unsigned long start, unsigned long end)
14171 + {
14172 ++ unsigned long e = end;
14173 ++
14174 + start = ELF_PAGEALIGN(start);
14175 + end = ELF_PAGEALIGN(end);
14176 + if (end > start) {
14177 +@@ -94,7 +111,7 @@ static int set_brk(unsigned long start,
14178 + if (BAD_ADDR(addr))
14179 + return addr;
14180 + }
14181 +- current->mm->start_brk = current->mm->brk = end;
14182 ++ current->mm->start_brk = current->mm->brk = e;
14183 + return 0;
14184 + }
14185 +
14186 +@@ -380,10 +397,10 @@ static unsigned long load_elf_interp(str
14187 + {
14188 + struct elf_phdr *elf_phdata;
14189 + struct elf_phdr *eppnt;
14190 +- unsigned long load_addr = 0;
14191 ++ unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
14192 + int load_addr_set = 0;
14193 + unsigned long last_bss = 0, elf_bss = 0;
14194 +- unsigned long error = ~0UL;
14195 ++ unsigned long error = -EINVAL;
14196 + unsigned long total_size;
14197 + int retval, i, size;
14198 +
14199 +@@ -429,6 +446,11 @@ static unsigned long load_elf_interp(str
14200 + goto out_close;
14201 + }
14202 +
14203 ++#ifdef CONFIG_PAX_SEGMEXEC
14204 ++ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
14205 ++ pax_task_size = SEGMEXEC_TASK_SIZE;
14206 ++#endif
14207 ++
14208 + eppnt = elf_phdata;
14209 + for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
14210 + if (eppnt->p_type == PT_LOAD) {
14211 +@@ -472,8 +494,8 @@ static unsigned long load_elf_interp(str
14212 + k = load_addr + eppnt->p_vaddr;
14213 + if (BAD_ADDR(k) ||
14214 + eppnt->p_filesz > eppnt->p_memsz ||
14215 +- eppnt->p_memsz > TASK_SIZE ||
14216 +- TASK_SIZE - eppnt->p_memsz < k) {
14217 ++ eppnt->p_memsz > pax_task_size ||
14218 ++ pax_task_size - eppnt->p_memsz < k) {
14219 + error = -ENOMEM;
14220 + goto out_close;
14221 + }
14222 +@@ -527,6 +549,177 @@ out:
14223 + return error;
14224 + }
14225 +
14226 ++#if (defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS)) && defined(CONFIG_PAX_SOFTMODE)
14227 ++static unsigned long pax_parse_softmode(const struct elf_phdr * const elf_phdata)
14228 ++{
14229 ++ unsigned long pax_flags = 0UL;
14230 ++
14231 ++#ifdef CONFIG_PAX_PAGEEXEC
14232 ++ if (elf_phdata->p_flags & PF_PAGEEXEC)
14233 ++ pax_flags |= MF_PAX_PAGEEXEC;
14234 ++#endif
14235 ++
14236 ++#ifdef CONFIG_PAX_SEGMEXEC
14237 ++ if (elf_phdata->p_flags & PF_SEGMEXEC)
14238 ++ pax_flags |= MF_PAX_SEGMEXEC;
14239 ++#endif
14240 ++
14241 ++#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
14242 ++ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
14243 ++ if (nx_enabled)
14244 ++ pax_flags &= ~MF_PAX_SEGMEXEC;
14245 ++ else
14246 ++ pax_flags &= ~MF_PAX_PAGEEXEC;
14247 ++ }
14248 ++#endif
14249 ++
14250 ++#ifdef CONFIG_PAX_EMUTRAMP
14251 ++ if (elf_phdata->p_flags & PF_EMUTRAMP)
14252 ++ pax_flags |= MF_PAX_EMUTRAMP;
14253 ++#endif
14254 ++
14255 ++#ifdef CONFIG_PAX_MPROTECT
14256 ++ if (elf_phdata->p_flags & PF_MPROTECT)
14257 ++ pax_flags |= MF_PAX_MPROTECT;
14258 ++#endif
14259 ++
14260 ++#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
14261 ++ if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
14262 ++ pax_flags |= MF_PAX_RANDMMAP;
14263 ++#endif
14264 ++
14265 ++ return pax_flags;
14266 ++}
14267 ++#endif
14268 ++
14269 ++#ifdef CONFIG_PAX_PT_PAX_FLAGS
14270 ++static unsigned long pax_parse_hardmode(const struct elf_phdr * const elf_phdata)
14271 ++{
14272 ++ unsigned long pax_flags = 0UL;
14273 ++
14274 ++#ifdef CONFIG_PAX_PAGEEXEC
14275 ++ if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
14276 ++ pax_flags |= MF_PAX_PAGEEXEC;
14277 ++#endif
14278 ++
14279 ++#ifdef CONFIG_PAX_SEGMEXEC
14280 ++ if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
14281 ++ pax_flags |= MF_PAX_SEGMEXEC;
14282 ++#endif
14283 ++
14284 ++#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
14285 ++ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
14286 ++ if (nx_enabled)
14287 ++ pax_flags &= ~MF_PAX_SEGMEXEC;
14288 ++ else
14289 ++ pax_flags &= ~MF_PAX_PAGEEXEC;
14290 ++ }
14291 ++#endif
14292 ++
14293 ++#ifdef CONFIG_PAX_EMUTRAMP
14294 ++ if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
14295 ++ pax_flags |= MF_PAX_EMUTRAMP;
14296 ++#endif
14297 ++
14298 ++#ifdef CONFIG_PAX_MPROTECT
14299 ++ if (!(elf_phdata->p_flags & PF_NOMPROTECT))
14300 ++ pax_flags |= MF_PAX_MPROTECT;
14301 ++#endif
14302 ++
14303 ++#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
14304 ++ if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
14305 ++ pax_flags |= MF_PAX_RANDMMAP;
14306 ++#endif
14307 ++
14308 ++ return pax_flags;
14309 ++}
14310 ++#endif
14311 ++
14312 ++#ifdef CONFIG_PAX_EI_PAX
14313 ++static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
14314 ++{
14315 ++ unsigned long pax_flags = 0UL;
14316 ++
14317 ++#ifdef CONFIG_PAX_PAGEEXEC
14318 ++ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
14319 ++ pax_flags |= MF_PAX_PAGEEXEC;
14320 ++#endif
14321 ++
14322 ++#ifdef CONFIG_PAX_SEGMEXEC
14323 ++ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
14324 ++ pax_flags |= MF_PAX_SEGMEXEC;
14325 ++#endif
14326 ++
14327 ++#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
14328 ++ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
14329 ++ if (nx_enabled)
14330 ++ pax_flags &= ~MF_PAX_SEGMEXEC;
14331 ++ else
14332 ++ pax_flags &= ~MF_PAX_PAGEEXEC;
14333 ++ }
14334 ++#endif
14335 ++
14336 ++#ifdef CONFIG_PAX_EMUTRAMP
14337 ++ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
14338 ++ pax_flags |= MF_PAX_EMUTRAMP;
14339 ++#endif
14340 ++
14341 ++#ifdef CONFIG_PAX_MPROTECT
14342 ++ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
14343 ++ pax_flags |= MF_PAX_MPROTECT;
14344 ++#endif
14345 ++
14346 ++#ifdef CONFIG_PAX_ASLR
14347 ++ if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
14348 ++ pax_flags |= MF_PAX_RANDMMAP;
14349 ++#endif
14350 ++
14351 ++ return pax_flags;
14352 ++}
14353 ++#endif
14354 ++
14355 ++#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS)
14356 ++static long pax_parse_elf_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
14357 ++{
14358 ++ unsigned long pax_flags = 0UL;
14359 ++
14360 ++#ifdef CONFIG_PAX_PT_PAX_FLAGS
14361 ++ unsigned long i;
14362 ++#endif
14363 ++
14364 ++#ifdef CONFIG_PAX_EI_PAX
14365 ++ pax_flags = pax_parse_ei_pax(elf_ex);
14366 ++#endif
14367 ++
14368 ++#ifdef CONFIG_PAX_PT_PAX_FLAGS
14369 ++ for (i = 0UL; i < elf_ex->e_phnum; i++)
14370 ++ if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
14371 ++ if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
14372 ++ ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
14373 ++ ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
14374 ++ ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
14375 ++ ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
14376 ++ return -EINVAL;
14377 ++
14378 ++#ifdef CONFIG_PAX_SOFTMODE
14379 ++ if (pax_softmode)
14380 ++ pax_flags = pax_parse_softmode(&elf_phdata[i]);
14381 ++ else
14382 ++#endif
14383 ++
14384 ++ pax_flags = pax_parse_hardmode(&elf_phdata[i]);
14385 ++ break;
14386 ++ }
14387 ++#endif
14388 ++
14389 ++ if (0 > pax_check_flags(&pax_flags))
14390 ++ return -EINVAL;
14391 ++
14392 ++ current->mm->pax_flags = pax_flags;
14393 ++ return 0;
14394 ++}
14395 ++#endif
14396 ++
14397 + /*
14398 + * These are the functions used to load ELF style executables and shared
14399 + * libraries. There is no binary dependent code anywhere else.
14400 +@@ -543,6 +736,11 @@ static unsigned long randomize_stack_top
14401 + {
14402 + unsigned int random_variable = 0;
14403 +
14404 ++#ifdef CONFIG_PAX_RANDUSTACK
14405 ++ if (randomize_va_space)
14406 ++ return stack_top - current->mm->delta_stack;
14407 ++#endif
14408 ++
14409 + if ((current->flags & PF_RANDOMIZE) &&
14410 + !(current->personality & ADDR_NO_RANDOMIZE)) {
14411 + random_variable = get_random_int() & STACK_RND_MASK;
14412 +@@ -561,7 +759,7 @@ static int load_elf_binary(struct linux_
14413 + unsigned long load_addr = 0, load_bias = 0;
14414 + int load_addr_set = 0;
14415 + char * elf_interpreter = NULL;
14416 +- unsigned long error;
14417 ++ unsigned long error = 0;
14418 + struct elf_phdr *elf_ppnt, *elf_phdata;
14419 + unsigned long elf_bss, elf_brk;
14420 + int elf_exec_fileno;
14421 +@@ -572,11 +770,11 @@ static int load_elf_binary(struct linux_
14422 + unsigned long start_code, end_code, start_data, end_data;
14423 + unsigned long reloc_func_desc = 0;
14424 + int executable_stack = EXSTACK_DEFAULT;
14425 +- unsigned long def_flags = 0;
14426 + struct {
14427 + struct elfhdr elf_ex;
14428 + struct elfhdr interp_elf_ex;
14429 + } *loc;
14430 ++ unsigned long pax_task_size = TASK_SIZE;
14431 +
14432 + loc = kmalloc(sizeof(*loc), GFP_KERNEL);
14433 + if (!loc) {
14434 +@@ -744,11 +942,80 @@ static int load_elf_binary(struct linux_
14435 +
14436 + /* OK, This is the point of no return */
14437 + current->flags &= ~PF_FORKNOEXEC;
14438 +- current->mm->def_flags = def_flags;
14439 ++
14440 ++#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
14441 ++ current->mm->pax_flags = 0UL;
14442 ++#endif
14443 ++
14444 ++#ifdef CONFIG_PAX_DLRESOLVE
14445 ++ current->mm->call_dl_resolve = 0UL;
14446 ++#endif
14447 ++
14448 ++#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
14449 ++ current->mm->call_syscall = 0UL;
14450 ++#endif
14451 ++
14452 ++#ifdef CONFIG_PAX_ASLR
14453 ++ current->mm->delta_mmap = 0UL;
14454 ++ current->mm->delta_stack = 0UL;
14455 ++#endif
14456 ++
14457 ++ current->mm->def_flags = 0;
14458 ++
14459 ++#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS)
14460 ++ if (0 > pax_parse_elf_flags(&loc->elf_ex, elf_phdata)) {
14461 ++ send_sig(SIGKILL, current, 0);
14462 ++ goto out_free_dentry;
14463 ++ }
14464 ++#endif
14465 ++
14466 ++#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
14467 ++ pax_set_initial_flags(bprm);
14468 ++#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
14469 ++ if (pax_set_initial_flags_func)
14470 ++ (pax_set_initial_flags_func)(bprm);
14471 ++#endif
14472 ++
14473 ++#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
14474 ++ if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !nx_enabled) {
14475 ++ current->mm->context.user_cs_limit = PAGE_SIZE;
14476 ++ current->mm->def_flags |= VM_PAGEEXEC;
14477 ++ }
14478 ++#endif
14479 ++
14480 ++#ifdef CONFIG_PAX_SEGMEXEC
14481 ++ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
14482 ++ current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
14483 ++ current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
14484 ++ pax_task_size = SEGMEXEC_TASK_SIZE;
14485 ++ }
14486 ++#endif
14487 ++
14488 ++#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
14489 ++ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
14490 ++ set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
14491 ++ put_cpu_no_resched();
14492 ++ }
14493 ++#endif
14494 ++
14495 ++#ifdef CONFIG_PAX_ASLR
14496 ++ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
14497 ++ current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
14498 ++ current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
14499 ++ }
14500 ++#endif
14501 +
14502 + /* Do this immediately, since STACK_TOP as used in setup_arg_pages
14503 + may depend on the personality. */
14504 + SET_PERSONALITY(loc->elf_ex, 0);
14505 ++
14506 ++#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
14507 ++ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
14508 ++ executable_stack = EXSTACK_DISABLE_X;
14509 ++ current->personality &= ~READ_IMPLIES_EXEC;
14510 ++ } else
14511 ++#endif
14512 ++
14513 + if (elf_read_implies_exec(loc->elf_ex, executable_stack))
14514 + current->personality |= READ_IMPLIES_EXEC;
14515 +
14516 +@@ -829,6 +1096,20 @@ static int load_elf_binary(struct linux_
14517 + #else
14518 + load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
14519 + #endif
14520 ++
14521 ++#ifdef CONFIG_PAX_RANDMMAP
14522 ++ /* PaX: randomize base address at the default exe base if requested */
14523 ++ if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
14524 ++#ifdef CONFIG_SPARC64
14525 ++ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
14526 ++#else
14527 ++ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
14528 ++#endif
14529 ++ load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
14530 ++ elf_flags |= MAP_FIXED;
14531 ++ }
14532 ++#endif
14533 ++
14534 + }
14535 +
14536 + error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
14537 +@@ -861,9 +1142,9 @@ static int load_elf_binary(struct linux_
14538 + * allowed task size. Note that p_filesz must always be
14539 + * <= p_memsz so it is only necessary to check p_memsz.
14540 + */
14541 +- if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
14542 +- elf_ppnt->p_memsz > TASK_SIZE ||
14543 +- TASK_SIZE - elf_ppnt->p_memsz < k) {
14544 ++ if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
14545 ++ elf_ppnt->p_memsz > pax_task_size ||
14546 ++ pax_task_size - elf_ppnt->p_memsz < k) {
14547 + /* set_brk can never work. Avoid overflows. */
14548 + send_sig(SIGKILL, current, 0);
14549 + retval = -EINVAL;
14550 +@@ -891,6 +1172,11 @@ static int load_elf_binary(struct linux_
14551 + start_data += load_bias;
14552 + end_data += load_bias;
14553 +
14554 ++#ifdef CONFIG_PAX_RANDMMAP
14555 ++ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
14556 ++ elf_brk += PAGE_SIZE + ((pax_get_random_long() & ~PAGE_MASK) << 4);
14557 ++#endif
14558 ++
14559 + /* Calling set_brk effectively mmaps the pages that we need
14560 + * for the bss and break sections. We must do this before
14561 + * mapping in the interpreter, to make sure it doesn't wind
14562 +@@ -902,9 +1188,11 @@ static int load_elf_binary(struct linux_
14563 + goto out_free_dentry;
14564 + }
14565 + if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
14566 +- send_sig(SIGSEGV, current, 0);
14567 +- retval = -EFAULT; /* Nobody gets to see this, but.. */
14568 +- goto out_free_dentry;
14569 ++ /*
14570 ++ * This bss-zeroing can fail if the ELF
14571 ++ * file specifies odd protections. So
14572 ++ * we don't check the return value
14573 ++ */
14574 + }
14575 +
14576 + if (elf_interpreter) {
14577 +@@ -1141,8 +1429,10 @@ static int dump_seek(struct file *file,
14578 + unsigned long n = off;
14579 + if (n > PAGE_SIZE)
14580 + n = PAGE_SIZE;
14581 +- if (!dump_write(file, buf, n))
14582 ++ if (!dump_write(file, buf, n)) {
14583 ++ free_page((unsigned long)buf);
14584 + return 0;
14585 ++ }
14586 + off -= n;
14587 + }
14588 + free_page((unsigned long)buf);
14589 +@@ -1154,7 +1444,7 @@ static int dump_seek(struct file *file,
14590 + * Decide what to dump of a segment, part, all or none.
14591 + */
14592 + static unsigned long vma_dump_size(struct vm_area_struct *vma,
14593 +- unsigned long mm_flags)
14594 ++ unsigned long mm_flags, long signr)
14595 + {
14596 + /* The vma can be set up to tell us the answer directly. */
14597 + if (vma->vm_flags & VM_ALWAYSDUMP)
14598 +@@ -1180,7 +1470,7 @@ static unsigned long vma_dump_size(struc
14599 + if (vma->vm_file == NULL)
14600 + return 0;
14601 +
14602 +- if (FILTER(MAPPED_PRIVATE))
14603 ++ if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
14604 + goto whole;
14605 +
14606 + /*
14607 +@@ -1266,8 +1556,11 @@ static int writenote(struct memelfnote *
14608 + #undef DUMP_WRITE
14609 +
14610 + #define DUMP_WRITE(addr, nr) \
14611 ++ do { \
14612 ++ gr_learn_resource(current, RLIMIT_CORE, size + (nr), 1); \
14613 + if ((size += (nr)) > limit || !dump_write(file, (addr), (nr))) \
14614 +- goto end_coredump;
14615 ++ goto end_coredump; \
14616 ++ } while (0);
14617 + #define DUMP_SEEK(off) \
14618 + if (!dump_seek(file, (off))) \
14619 + goto end_coredump;
14620 +@@ -1973,7 +2266,7 @@ static int elf_core_dump(long signr, str
14621 + phdr.p_offset = offset;
14622 + phdr.p_vaddr = vma->vm_start;
14623 + phdr.p_paddr = 0;
14624 +- phdr.p_filesz = vma_dump_size(vma, mm_flags);
14625 ++ phdr.p_filesz = vma_dump_size(vma, mm_flags, signr);
14626 + phdr.p_memsz = vma->vm_end - vma->vm_start;
14627 + offset += phdr.p_filesz;
14628 + phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
14629 +@@ -2005,7 +2298,7 @@ static int elf_core_dump(long signr, str
14630 + unsigned long addr;
14631 + unsigned long end;
14632 +
14633 +- end = vma->vm_start + vma_dump_size(vma, mm_flags);
14634 ++ end = vma->vm_start + vma_dump_size(vma, mm_flags, signr);
14635 +
14636 + for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
14637 + struct page *page;
14638 +@@ -2025,6 +2318,7 @@ static int elf_core_dump(long signr, str
14639 + flush_cache_page(tmp_vma, addr,
14640 + page_to_pfn(page));
14641 + kaddr = kmap(page);
14642 ++ gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
14643 + if ((size += PAGE_SIZE) > limit ||
14644 + !dump_write(file, kaddr,
14645 + PAGE_SIZE)) {
14646 +@@ -2055,6 +2349,99 @@ out:
14647 +
14648 + #endif /* USE_ELF_CORE_DUMP */
14649 +
14650 ++#ifdef CONFIG_PAX_MPROTECT
14651 ++/* PaX: non-PIC ELF libraries need relocations on their executable segments
14652 ++ * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
14653 ++ * we'll remove VM_MAYWRITE for good on RELRO segments.
14654 ++ *
14655 ++ * The checks favour ld-linux.so behaviour which operates on a per ELF segment
14656 ++ * basis because we want to allow the common case and not the special ones.
14657 ++ */
14658 ++static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
14659 ++{
14660 ++ struct elfhdr elf_h;
14661 ++ struct elf_phdr elf_p;
14662 ++ unsigned long i;
14663 ++ unsigned long oldflags;
14664 ++ bool is_textrel_rw, is_textrel_rx, is_relro;
14665 ++
14666 ++ if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
14667 ++ return;
14668 ++
14669 ++ oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
14670 ++ newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
14671 ++
14672 ++#ifdef CONFIG_PAX_NOELFRELOCS
14673 ++ is_textrel_rw = false;
14674 ++ is_textrel_rx = false;
14675 ++#else
14676 ++ /* possible TEXTREL */
14677 ++ is_textrel_rw = vma->vm_file && !vma->anon_vma && !vma->vm_pgoff && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
14678 ++ is_textrel_rx = vma->vm_file && vma->anon_vma && !vma->vm_pgoff && oldflags == (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_WRITE | VM_READ) && newflags == (VM_EXEC | VM_READ);
14679 ++#endif
14680 ++
14681 ++ /* possible RELRO */
14682 ++ is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
14683 ++
14684 ++ if (!is_textrel_rw && !is_textrel_rx && !is_relro)
14685 ++ return;
14686 ++
14687 ++ if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
14688 ++ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
14689 ++
14690 ++#ifdef CONFIG_PAX_ETEXECRELOCS
14691 ++ ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
14692 ++#else
14693 ++ ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
14694 ++#endif
14695 ++
14696 ++ (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
14697 ++ !elf_check_arch(&elf_h) ||
14698 ++ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
14699 ++ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
14700 ++ return;
14701 ++
14702 ++ for (i = 0UL; i < elf_h.e_phnum; i++) {
14703 ++ if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
14704 ++ return;
14705 ++ switch (elf_p.p_type) {
14706 ++ case PT_DYNAMIC: {
14707 ++ elf_addr_t dyn_offset = 0UL;
14708 ++ elf_dyn dyn;
14709 ++
14710 ++ if (!is_textrel_rw && !is_textrel_rx)
14711 ++ continue;
14712 ++ dyn_offset = elf_p.p_offset;
14713 ++ i = 0UL;
14714 ++ do {
14715 ++ if (sizeof(dyn) != kernel_read(vma->vm_file, dyn_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
14716 ++ return;
14717 ++ if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
14718 ++ gr_log_textrel(vma);
14719 ++ if (is_textrel_rw)
14720 ++ vma->vm_flags |= VM_MAYWRITE;
14721 ++ else
14722 ++ /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
14723 ++ vma->vm_flags &= ~VM_MAYWRITE;
14724 ++ return;
14725 ++ }
14726 ++ i++;
14727 ++ } while (dyn.d_tag != DT_NULL);
14728 ++ return;
14729 ++ }
14730 ++
14731 ++ case PT_GNU_RELRO:
14732 ++ if (!is_relro)
14733 ++ continue;
14734 ++ if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start) {
14735 ++ vma->vm_flags &= ~VM_MAYWRITE;
14736 ++ }
14737 ++ return;
14738 ++ }
14739 ++ }
14740 ++}
14741 ++#endif
14742 ++
14743 + static int __init init_elf_binfmt(void)
14744 + {
14745 + return register_binfmt(&elf_format);
14746 +diff -urNp linux-2.6.27.10/fs/binfmt_flat.c linux-2.6.27.10/fs/binfmt_flat.c
14747 +--- linux-2.6.27.10/fs/binfmt_flat.c 2008-11-07 12:55:34.000000000 -0500
14748 ++++ linux-2.6.27.10/fs/binfmt_flat.c 2008-11-18 03:38:45.000000000 -0500
14749 +@@ -561,7 +561,9 @@ static int load_flat_file(struct linux_b
14750 + realdatastart = (unsigned long) -ENOMEM;
14751 + printk("Unable to allocate RAM for process data, errno %d\n",
14752 + (int)-realdatastart);
14753 ++ down_write(&current->mm->mmap_sem);
14754 + do_munmap(current->mm, textpos, text_len);
14755 ++ up_write(&current->mm->mmap_sem);
14756 + ret = realdatastart;
14757 + goto err;
14758 + }
14759 +@@ -583,8 +585,10 @@ static int load_flat_file(struct linux_b
14760 + }
14761 + if (result >= (unsigned long)-4096) {
14762 + printk("Unable to read data+bss, errno %d\n", (int)-result);
14763 ++ down_write(&current->mm->mmap_sem);
14764 + do_munmap(current->mm, textpos, text_len);
14765 + do_munmap(current->mm, realdatastart, data_len + extra);
14766 ++ up_write(&current->mm->mmap_sem);
14767 + ret = result;
14768 + goto err;
14769 + }
14770 +@@ -657,8 +661,10 @@ static int load_flat_file(struct linux_b
14771 + }
14772 + if (result >= (unsigned long)-4096) {
14773 + printk("Unable to read code+data+bss, errno %d\n",(int)-result);
14774 ++ down_write(&current->mm->mmap_sem);
14775 + do_munmap(current->mm, textpos, text_len + data_len + extra +
14776 + MAX_SHARED_LIBS * sizeof(unsigned long));
14777 ++ up_write(&current->mm->mmap_sem);
14778 + ret = result;
14779 + goto err;
14780 + }
14781 +diff -urNp linux-2.6.27.10/fs/binfmt_misc.c linux-2.6.27.10/fs/binfmt_misc.c
14782 +--- linux-2.6.27.10/fs/binfmt_misc.c 2008-12-21 01:16:51.000000000 -0500
14783 ++++ linux-2.6.27.10/fs/binfmt_misc.c 2008-12-21 01:13:46.000000000 -0500
14784 +@@ -696,7 +696,7 @@ static int bm_fill_super(struct super_bl
14785 + static struct tree_descr bm_files[] = {
14786 + [2] = {"status", &bm_status_operations, S_IWUSR|S_IRUGO},
14787 + [3] = {"register", &bm_register_operations, S_IWUSR},
14788 +- /* last one */ {""}
14789 ++ /* last one */ {"", NULL, 0}
14790 + };
14791 + int err = simple_fill_super(sb, 0x42494e4d, bm_files);
14792 + if (!err)
14793 +diff -urNp linux-2.6.27.10/fs/bio.c linux-2.6.27.10/fs/bio.c
14794 +--- linux-2.6.27.10/fs/bio.c 2008-11-07 12:55:34.000000000 -0500
14795 ++++ linux-2.6.27.10/fs/bio.c 2008-11-18 03:38:45.000000000 -0500
14796 +@@ -507,7 +507,7 @@ static int __bio_copy_iov(struct bio *bi
14797 +
14798 + while (bv_len && iov_idx < iov_count) {
14799 + unsigned int bytes;
14800 +- char *iov_addr;
14801 ++ char __user *iov_addr;
14802 +
14803 + bytes = min_t(unsigned int,
14804 + iov[iov_idx].iov_len - iov_off, bv_len);
14805 +diff -urNp linux-2.6.27.10/fs/buffer.c linux-2.6.27.10/fs/buffer.c
14806 +--- linux-2.6.27.10/fs/buffer.c 2008-11-07 12:55:34.000000000 -0500
14807 ++++ linux-2.6.27.10/fs/buffer.c 2008-11-18 03:38:45.000000000 -0500
14808 +@@ -41,6 +41,7 @@
14809 + #include <linux/bitops.h>
14810 + #include <linux/mpage.h>
14811 + #include <linux/bit_spinlock.h>
14812 ++#include <linux/grsecurity.h>
14813 +
14814 + static int fsync_buffers_list(spinlock_t *lock, struct list_head *list);
14815 +
14816 +@@ -2249,6 +2250,7 @@ int generic_cont_expand_simple(struct in
14817 +
14818 + err = -EFBIG;
14819 + limit = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
14820 ++ gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long) size, 1);
14821 + if (limit != RLIM_INFINITY && size > (loff_t)limit) {
14822 + send_sig(SIGXFSZ, current, 0);
14823 + goto out;
14824 +diff -urNp linux-2.6.27.10/fs/cifs/cifs_uniupr.h linux-2.6.27.10/fs/cifs/cifs_uniupr.h
14825 +--- linux-2.6.27.10/fs/cifs/cifs_uniupr.h 2008-11-07 12:55:34.000000000 -0500
14826 ++++ linux-2.6.27.10/fs/cifs/cifs_uniupr.h 2008-11-18 03:38:45.000000000 -0500
14827 +@@ -132,7 +132,7 @@ const struct UniCaseRange CifsUniUpperRa
14828 + {0x0490, 0x04cc, UniCaseRangeU0490},
14829 + {0x1e00, 0x1ffc, UniCaseRangeU1e00},
14830 + {0xff40, 0xff5a, UniCaseRangeUff40},
14831 +- {0}
14832 ++ {0, 0, NULL}
14833 + };
14834 + #endif
14835 +
14836 +diff -urNp linux-2.6.27.10/fs/cifs/link.c linux-2.6.27.10/fs/cifs/link.c
14837 +--- linux-2.6.27.10/fs/cifs/link.c 2008-11-07 12:55:34.000000000 -0500
14838 ++++ linux-2.6.27.10/fs/cifs/link.c 2008-11-18 03:38:45.000000000 -0500
14839 +@@ -318,7 +318,7 @@ cifs_readlink(struct dentry *direntry, c
14840 +
14841 + void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
14842 + {
14843 +- char *p = nd_get_link(nd);
14844 ++ const char *p = nd_get_link(nd);
14845 + if (!IS_ERR(p))
14846 + kfree(p);
14847 + }
14848 +diff -urNp linux-2.6.27.10/fs/compat.c linux-2.6.27.10/fs/compat.c
14849 +--- linux-2.6.27.10/fs/compat.c 2008-11-07 12:55:34.000000000 -0500
14850 ++++ linux-2.6.27.10/fs/compat.c 2008-11-18 03:38:45.000000000 -0500
14851 +@@ -51,6 +51,7 @@
14852 + #include <linux/poll.h>
14853 + #include <linux/mm.h>
14854 + #include <linux/eventpoll.h>
14855 ++#include <linux/grsecurity.h>
14856 +
14857 + #include <asm/uaccess.h>
14858 + #include <asm/mmu_context.h>
14859 +@@ -1298,14 +1299,12 @@ static int compat_copy_strings(int argc,
14860 + if (!kmapped_page || kpos != (pos & PAGE_MASK)) {
14861 + struct page *page;
14862 +
14863 +-#ifdef CONFIG_STACK_GROWSUP
14864 + ret = expand_stack_downwards(bprm->vma, pos);
14865 + if (ret < 0) {
14866 + /* We've exceed the stack rlimit. */
14867 + ret = -E2BIG;
14868 + goto out;
14869 + }
14870 +-#endif
14871 + ret = get_user_pages(current, bprm->mm, pos,
14872 + 1, 1, 1, &page, NULL);
14873 + if (ret <= 0) {
14874 +@@ -1351,6 +1350,11 @@ int compat_do_execve(char * filename,
14875 + compat_uptr_t __user *envp,
14876 + struct pt_regs * regs)
14877 + {
14878 ++#ifdef CONFIG_GRKERNSEC
14879 ++ struct file *old_exec_file;
14880 ++ struct acl_subject_label *old_acl;
14881 ++ struct rlimit old_rlim[RLIM_NLIMITS];
14882 ++#endif
14883 + struct linux_binprm *bprm;
14884 + struct file *file;
14885 + int retval;
14886 +@@ -1371,6 +1375,14 @@ int compat_do_execve(char * filename,
14887 + bprm->filename = filename;
14888 + bprm->interp = filename;
14889 +
14890 ++ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->user->processes), 1);
14891 ++ retval = -EAGAIN;
14892 ++ if (gr_handle_nproc())
14893 ++ goto out_file;
14894 ++ retval = -EACCES;
14895 ++ if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt))
14896 ++ goto out_file;
14897 ++
14898 + retval = bprm_mm_init(bprm);
14899 + if (retval)
14900 + goto out_file;
14901 +@@ -1404,8 +1416,36 @@ int compat_do_execve(char * filename,
14902 + if (retval < 0)
14903 + goto out;
14904 +
14905 ++ if (!gr_tpe_allow(file)) {
14906 ++ retval = -EACCES;
14907 ++ goto out;
14908 ++ }
14909 ++
14910 ++ if (gr_check_crash_exec(file)) {
14911 ++ retval = -EACCES;
14912 ++ goto out;
14913 ++ }
14914 ++
14915 ++ gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
14916 ++
14917 ++ gr_handle_exec_args(bprm, (char __user * __user *)argv);
14918 ++
14919 ++#ifdef CONFIG_GRKERNSEC
14920 ++ old_acl = current->acl;
14921 ++ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
14922 ++ old_exec_file = current->exec_file;
14923 ++ get_file(file);
14924 ++ current->exec_file = file;
14925 ++#endif
14926 ++
14927 ++ gr_set_proc_label(file->f_dentry, file->f_vfsmnt);
14928 ++
14929 + retval = search_binary_handler(bprm, regs);
14930 + if (retval >= 0) {
14931 ++#ifdef CONFIG_GRKERNSEC
14932 ++ if (old_exec_file)
14933 ++ fput(old_exec_file);
14934 ++#endif
14935 + /* execve success */
14936 + security_bprm_free(bprm);
14937 + acct_update_integrals(current);
14938 +@@ -1413,6 +1453,13 @@ int compat_do_execve(char * filename,
14939 + return retval;
14940 + }
14941 +
14942 ++#ifdef CONFIG_GRKERNSEC
14943 ++ current->acl = old_acl;
14944 ++ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
14945 ++ fput(current->exec_file);
14946 ++ current->exec_file = old_exec_file;
14947 ++#endif
14948 ++
14949 + out:
14950 + if (bprm->security)
14951 + security_bprm_free(bprm);
14952 +diff -urNp linux-2.6.27.10/fs/compat_ioctl.c linux-2.6.27.10/fs/compat_ioctl.c
14953 +--- linux-2.6.27.10/fs/compat_ioctl.c 2008-11-07 12:55:34.000000000 -0500
14954 ++++ linux-2.6.27.10/fs/compat_ioctl.c 2008-11-18 03:38:45.000000000 -0500
14955 +@@ -1831,15 +1831,15 @@ struct ioctl_trans {
14956 + };
14957 +
14958 + #define HANDLE_IOCTL(cmd,handler) \
14959 +- { (cmd), (ioctl_trans_handler_t)(handler) },
14960 ++ { (cmd), (ioctl_trans_handler_t)(handler), NULL },
14961 +
14962 + /* pointer to compatible structure or no argument */
14963 + #define COMPATIBLE_IOCTL(cmd) \
14964 +- { (cmd), do_ioctl32_pointer },
14965 ++ { (cmd), do_ioctl32_pointer, NULL },
14966 +
14967 + /* argument is an unsigned long integer, not a pointer */
14968 + #define ULONG_IOCTL(cmd) \
14969 +- { (cmd), (ioctl_trans_handler_t)sys_ioctl },
14970 ++ { (cmd), (ioctl_trans_handler_t)sys_ioctl, NULL },
14971 +
14972 + /* ioctl should not be warned about even if it's not implemented.
14973 + Valid reasons to use this:
14974 +diff -urNp linux-2.6.27.10/fs/debugfs/inode.c linux-2.6.27.10/fs/debugfs/inode.c
14975 +--- linux-2.6.27.10/fs/debugfs/inode.c 2008-11-07 12:55:34.000000000 -0500
14976 ++++ linux-2.6.27.10/fs/debugfs/inode.c 2008-11-18 03:38:45.000000000 -0500
14977 +@@ -121,7 +121,7 @@ static inline int debugfs_positive(struc
14978 +
14979 + static int debug_fill_super(struct super_block *sb, void *data, int silent)
14980 + {
14981 +- static struct tree_descr debug_files[] = {{""}};
14982 ++ static struct tree_descr debug_files[] = {{"", NULL, 0}};
14983 +
14984 + return simple_fill_super(sb, DEBUGFS_MAGIC, debug_files);
14985 + }
14986 +diff -urNp linux-2.6.27.10/fs/exec.c linux-2.6.27.10/fs/exec.c
14987 +--- linux-2.6.27.10/fs/exec.c 2008-12-21 01:16:51.000000000 -0500
14988 ++++ linux-2.6.27.10/fs/exec.c 2008-12-21 01:13:46.000000000 -0500
14989 +@@ -50,6 +50,13 @@
14990 + #include <linux/cn_proc.h>
14991 + #include <linux/audit.h>
14992 + #include <linux/tracehook.h>
14993 ++#include <linux/random.h>
14994 ++#include <linux/grsecurity.h>
14995 ++
14996 ++#ifdef CONFIG_PAX_REFCOUNT
14997 ++#include <linux/kallsyms.h>
14998 ++#include <linux/kdebug.h>
14999 ++#endif
15000 +
15001 + #include <asm/uaccess.h>
15002 + #include <asm/mmu_context.h>
15003 +@@ -64,6 +71,11 @@
15004 + #include <linux/a.out.h>
15005 + #endif
15006 +
15007 ++#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
15008 ++void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
15009 ++EXPORT_SYMBOL(pax_set_initial_flags_func);
15010 ++#endif
15011 ++
15012 + int core_uses_pid;
15013 + char core_pattern[CORENAME_MAX_SIZE] = "core";
15014 + int suid_dumpable = 0;
15015 +@@ -172,18 +184,10 @@ static struct page *get_arg_page(struct
15016 + int write)
15017 + {
15018 + struct page *page;
15019 +- int ret;
15020 +
15021 +-#ifdef CONFIG_STACK_GROWSUP
15022 +- if (write) {
15023 +- ret = expand_stack_downwards(bprm->vma, pos);
15024 +- if (ret < 0)
15025 +- return NULL;
15026 +- }
15027 +-#endif
15028 +- ret = get_user_pages(current, bprm->mm, pos,
15029 +- 1, write, 1, &page, NULL);
15030 +- if (ret <= 0)
15031 ++ if (0 > expand_stack_downwards(bprm->vma, pos))
15032 ++ return NULL;
15033 ++ if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
15034 + return NULL;
15035 +
15036 + if (write) {
15037 +@@ -256,6 +260,11 @@ static int __bprm_mm_init(struct linux_b
15038 + vma->vm_start = vma->vm_end - PAGE_SIZE;
15039 +
15040 + vma->vm_flags = VM_STACK_FLAGS;
15041 ++
15042 ++#ifdef CONFIG_PAX_SEGMEXEC
15043 ++ vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
15044 ++#endif
15045 ++
15046 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
15047 + err = insert_vm_struct(mm, vma);
15048 + if (err) {
15049 +@@ -268,6 +277,11 @@ static int __bprm_mm_init(struct linux_b
15050 +
15051 + bprm->p = vma->vm_end - sizeof(void *);
15052 +
15053 ++#ifdef CONFIG_PAX_RANDUSTACK
15054 ++ if (randomize_va_space)
15055 ++ bprm->p ^= (pax_get_random_long() & ~15) & ~PAGE_MASK;
15056 ++#endif
15057 ++
15058 + return 0;
15059 +
15060 + err:
15061 +@@ -391,7 +405,7 @@ static int count(char __user * __user *
15062 + if (!p)
15063 + break;
15064 + argv++;
15065 +- if(++i > max)
15066 ++ if (++i > max)
15067 + return -E2BIG;
15068 + cond_resched();
15069 + }
15070 +@@ -531,6 +545,10 @@ static int shift_arg_pages(struct vm_are
15071 + if (vma != find_vma(mm, new_start))
15072 + return -EFAULT;
15073 +
15074 ++#ifdef CONFIG_PAX_SEGMEXEC
15075 ++ BUG_ON(pax_find_mirror_vma(vma));
15076 ++#endif
15077 ++
15078 + /*
15079 + * cover the whole range: [new_start, old_end)
15080 + */
15081 +@@ -619,6 +637,14 @@ int setup_arg_pages(struct linux_binprm
15082 + bprm->exec -= stack_shift;
15083 +
15084 + down_write(&mm->mmap_sem);
15085 ++
15086 ++ /* Move stack pages down in memory. */
15087 ++ if (stack_shift) {
15088 ++ ret = shift_arg_pages(vma, stack_shift);
15089 ++ if (ret)
15090 ++ goto out_unlock;
15091 ++ }
15092 ++
15093 + vm_flags = VM_STACK_FLAGS;
15094 +
15095 + /*
15096 +@@ -632,21 +658,24 @@ int setup_arg_pages(struct linux_binprm
15097 + vm_flags &= ~VM_EXEC;
15098 + vm_flags |= mm->def_flags;
15099 +
15100 ++#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
15101 ++ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
15102 ++ vm_flags &= ~VM_EXEC;
15103 ++
15104 ++#ifdef CONFIG_PAX_MPROTECT
15105 ++ if (mm->pax_flags & MF_PAX_MPROTECT)
15106 ++ vm_flags &= ~VM_MAYEXEC;
15107 ++#endif
15108 ++
15109 ++ }
15110 ++#endif
15111 ++
15112 + ret = mprotect_fixup(vma, &prev, vma->vm_start, vma->vm_end,
15113 + vm_flags);
15114 + if (ret)
15115 + goto out_unlock;
15116 + BUG_ON(prev != vma);
15117 +
15118 +- /* Move stack pages down in memory. */
15119 +- if (stack_shift) {
15120 +- ret = shift_arg_pages(vma, stack_shift);
15121 +- if (ret) {
15122 +- up_write(&mm->mmap_sem);
15123 +- return ret;
15124 +- }
15125 +- }
15126 +-
15127 + #ifdef CONFIG_STACK_GROWSUP
15128 + stack_base = vma->vm_end + EXTRA_STACK_VM_PAGES * PAGE_SIZE;
15129 + #else
15130 +@@ -658,7 +687,7 @@ int setup_arg_pages(struct linux_binprm
15131 +
15132 + out_unlock:
15133 + up_write(&mm->mmap_sem);
15134 +- return 0;
15135 ++ return ret;
15136 + }
15137 + EXPORT_SYMBOL(setup_arg_pages);
15138 +
15139 +@@ -1286,6 +1315,11 @@ int do_execve(char * filename,
15140 + char __user *__user *envp,
15141 + struct pt_regs * regs)
15142 + {
15143 ++#ifdef CONFIG_GRKERNSEC
15144 ++ struct file *old_exec_file;
15145 ++ struct acl_subject_label *old_acl;
15146 ++ struct rlimit old_rlim[RLIM_NLIMITS];
15147 ++#endif
15148 + struct linux_binprm *bprm;
15149 + struct file *file;
15150 + struct files_struct *displaced;
15151 +@@ -1305,6 +1339,20 @@ int do_execve(char * filename,
15152 + if (IS_ERR(file))
15153 + goto out_kfree;
15154 +
15155 ++ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->user->processes), 1);
15156 ++
15157 ++ if (gr_handle_nproc()) {
15158 ++ allow_write_access(file);
15159 ++ fput(file);
15160 ++ return -EAGAIN;
15161 ++ }
15162 ++
15163 ++ if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
15164 ++ allow_write_access(file);
15165 ++ fput(file);
15166 ++ return -EACCES;
15167 ++ }
15168 ++
15169 + sched_exec();
15170 +
15171 + bprm->file = file;
15172 +@@ -1344,9 +1392,39 @@ int do_execve(char * filename,
15173 + if (retval < 0)
15174 + goto out;
15175 +
15176 ++ if (!gr_tpe_allow(file)) {
15177 ++ retval = -EACCES;
15178 ++ goto out;
15179 ++ }
15180 ++
15181 ++ if (gr_check_crash_exec(file)) {
15182 ++ retval = -EACCES;
15183 ++ goto out;
15184 ++ }
15185 ++
15186 ++ gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
15187 ++
15188 ++ gr_handle_exec_args(bprm, argv);
15189 ++
15190 ++#ifdef CONFIG_GRKERNSEC
15191 ++ old_acl = current->acl;
15192 ++ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
15193 ++ old_exec_file = current->exec_file;
15194 ++ get_file(file);
15195 ++ current->exec_file = file;
15196 ++#endif
15197 ++
15198 ++ retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt);
15199 ++ if (retval < 0)
15200 ++ goto out_fail;
15201 ++
15202 + current->flags &= ~PF_KTHREAD;
15203 + retval = search_binary_handler(bprm,regs);
15204 + if (retval >= 0) {
15205 ++#ifdef CONFIG_GRKERNSEC
15206 ++ if (old_exec_file)
15207 ++ fput(old_exec_file);
15208 ++#endif
15209 + /* execve success */
15210 + security_bprm_free(bprm);
15211 + acct_update_integrals(current);
15212 +@@ -1356,6 +1434,14 @@ int do_execve(char * filename,
15213 + return retval;
15214 + }
15215 +
15216 ++out_fail:
15217 ++#ifdef CONFIG_GRKERNSEC
15218 ++ current->acl = old_acl;
15219 ++ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
15220 ++ fput(current->exec_file);
15221 ++ current->exec_file = old_exec_file;
15222 ++#endif
15223 ++
15224 + out:
15225 + if (bprm->security)
15226 + security_bprm_free(bprm);
15227 +@@ -1519,6 +1605,125 @@ out:
15228 + return ispipe;
15229 + }
15230 +
15231 ++int pax_check_flags(unsigned long *flags)
15232 ++{
15233 ++ int retval = 0;
15234 ++
15235 ++#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
15236 ++ if (*flags & MF_PAX_SEGMEXEC)
15237 ++ {
15238 ++ *flags &= ~MF_PAX_SEGMEXEC;
15239 ++ retval = -EINVAL;
15240 ++ }
15241 ++#endif
15242 ++
15243 ++ if ((*flags & MF_PAX_PAGEEXEC)
15244 ++
15245 ++#ifdef CONFIG_PAX_PAGEEXEC
15246 ++ && (*flags & MF_PAX_SEGMEXEC)
15247 ++#endif
15248 ++
15249 ++ )
15250 ++ {
15251 ++ *flags &= ~MF_PAX_PAGEEXEC;
15252 ++ retval = -EINVAL;
15253 ++ }
15254 ++
15255 ++ if ((*flags & MF_PAX_MPROTECT)
15256 ++
15257 ++#ifdef CONFIG_PAX_MPROTECT
15258 ++ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
15259 ++#endif
15260 ++
15261 ++ )
15262 ++ {
15263 ++ *flags &= ~MF_PAX_MPROTECT;
15264 ++ retval = -EINVAL;
15265 ++ }
15266 ++
15267 ++ if ((*flags & MF_PAX_EMUTRAMP)
15268 ++
15269 ++#ifdef CONFIG_PAX_EMUTRAMP
15270 ++ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
15271 ++#endif
15272 ++
15273 ++ )
15274 ++ {
15275 ++ *flags &= ~MF_PAX_EMUTRAMP;
15276 ++ retval = -EINVAL;
15277 ++ }
15278 ++
15279 ++ return retval;
15280 ++}
15281 ++
15282 ++EXPORT_SYMBOL(pax_check_flags);
15283 ++
15284 ++#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
15285 ++void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
15286 ++{
15287 ++ struct task_struct *tsk = current;
15288 ++ struct mm_struct *mm = current->mm;
15289 ++ char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
15290 ++ char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
15291 ++ char *path_exec = NULL;
15292 ++ char *path_fault = NULL;
15293 ++ unsigned long start = 0UL, end = 0UL, offset = 0UL;
15294 ++
15295 ++ if (buffer_exec && buffer_fault) {
15296 ++ struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
15297 ++
15298 ++ down_read(&mm->mmap_sem);
15299 ++ vma = mm->mmap;
15300 ++ while (vma && (!vma_exec || !vma_fault)) {
15301 ++ if ((vma->vm_flags & VM_EXECUTABLE) && vma->vm_file)
15302 ++ vma_exec = vma;
15303 ++ if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
15304 ++ vma_fault = vma;
15305 ++ vma = vma->vm_next;
15306 ++ }
15307 ++ if (vma_exec) {
15308 ++ path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
15309 ++ if (IS_ERR(path_exec))
15310 ++ path_exec = "<path too long>";
15311 ++ }
15312 ++ if (vma_fault) {
15313 ++ start = vma_fault->vm_start;
15314 ++ end = vma_fault->vm_end;
15315 ++ offset = vma_fault->vm_pgoff << PAGE_SHIFT;
15316 ++ if (vma_fault->vm_file) {
15317 ++ path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
15318 ++ if (IS_ERR(path_fault))
15319 ++ path_fault = "<path too long>";
15320 ++ } else
15321 ++ path_fault = "<anonymous mapping>";
15322 ++ }
15323 ++ up_read(&mm->mmap_sem);
15324 ++ }
15325 ++ if (tsk->signal->curr_ip)
15326 ++ printk(KERN_ERR "PAX: From %u.%u.%u.%u: execution attempt in: %s, %08lx-%08lx %08lx\n", NIPQUAD(tsk->signal->curr_ip), path_fault, start, end, offset);
15327 ++ else
15328 ++ printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
15329 ++ printk(KERN_ERR "PAX: terminating task: %s(%s):%d, uid/euid: %u/%u, "
15330 ++ "PC: %p, SP: %p\n", path_exec, tsk->comm, task_pid_nr(tsk),
15331 ++ tsk->uid, tsk->euid, pc, sp);
15332 ++ free_page((unsigned long)buffer_exec);
15333 ++ free_page((unsigned long)buffer_fault);
15334 ++ pax_report_insns(pc, sp);
15335 ++ do_coredump(SIGKILL, SIGKILL, regs);
15336 ++}
15337 ++#endif
15338 ++
15339 ++#ifdef CONFIG_PAX_REFCOUNT
15340 ++void pax_report_refcount_overflow(struct pt_regs *regs)
15341 ++{
15342 ++ printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
15343 ++ current->comm, task_pid_nr(current), current->uid, current->euid);
15344 ++ print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
15345 ++ show_registers(regs);
15346 ++ force_sig_specific(SIGKILL, current);
15347 ++}
15348 ++#endif
15349 ++
15350 + static int zap_process(struct task_struct *start)
15351 + {
15352 + struct task_struct *t;
15353 +@@ -1765,6 +1970,10 @@ int do_coredump(long signr, int exit_cod
15354 + */
15355 + clear_thread_flag(TIF_SIGPENDING);
15356 +
15357 ++ if (signr == SIGKILL || signr == SIGILL)
15358 ++ gr_handle_brute_attach(current);
15359 ++ gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
15360 ++
15361 + /*
15362 + * lock_kernel() because format_corename() is controlled by sysctl, which
15363 + * uses lock_kernel()
15364 +@@ -1785,6 +1994,8 @@ int do_coredump(long signr, int exit_cod
15365 +
15366 + if (ispipe) {
15367 + helper_argv = argv_split(GFP_KERNEL, corename+1, &helper_argc);
15368 ++ if (!helper_argv)
15369 ++ goto fail_unlock;
15370 + /* Terminate the string before the first option */
15371 + delimit = strchr(corename, ' ');
15372 + if (delimit)
15373 +diff -urNp linux-2.6.27.10/fs/ext2/balloc.c linux-2.6.27.10/fs/ext2/balloc.c
15374 +--- linux-2.6.27.10/fs/ext2/balloc.c 2008-12-10 22:35:37.000000000 -0500
15375 ++++ linux-2.6.27.10/fs/ext2/balloc.c 2008-12-10 22:35:46.000000000 -0500
15376 +@@ -1192,7 +1192,7 @@ static int ext2_has_free_blocks(struct e
15377 +
15378 + free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
15379 + root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
15380 +- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
15381 ++ if (free_blocks < root_blocks + 1 && !capable_nolog(CAP_SYS_RESOURCE) &&
15382 + sbi->s_resuid != current->fsuid &&
15383 + (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
15384 + return 0;
15385 +diff -urNp linux-2.6.27.10/fs/ext3/balloc.c linux-2.6.27.10/fs/ext3/balloc.c
15386 +--- linux-2.6.27.10/fs/ext3/balloc.c 2008-12-10 22:35:37.000000000 -0500
15387 ++++ linux-2.6.27.10/fs/ext3/balloc.c 2008-12-10 22:35:46.000000000 -0500
15388 +@@ -1421,7 +1421,7 @@ static int ext3_has_free_blocks(struct e
15389 +
15390 + free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
15391 + root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
15392 +- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
15393 ++ if (free_blocks < root_blocks + 1 && !capable_nolog(CAP_SYS_RESOURCE) &&
15394 + sbi->s_resuid != current->fsuid &&
15395 + (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
15396 + return 0;
15397 +diff -urNp linux-2.6.27.10/fs/ext3/namei.c linux-2.6.27.10/fs/ext3/namei.c
15398 +--- linux-2.6.27.10/fs/ext3/namei.c 2008-11-07 12:55:34.000000000 -0500
15399 ++++ linux-2.6.27.10/fs/ext3/namei.c 2008-11-18 03:38:45.000000000 -0500
15400 +@@ -1173,9 +1173,9 @@ static struct ext3_dir_entry_2 *do_split
15401 + u32 hash2;
15402 + struct dx_map_entry *map;
15403 + char *data1 = (*bh)->b_data, *data2;
15404 +- unsigned split, move, size, i;
15405 ++ unsigned split, move, size;
15406 + struct ext3_dir_entry_2 *de = NULL, *de2;
15407 +- int err = 0;
15408 ++ int i, err = 0;
15409 +
15410 + bh2 = ext3_append (handle, dir, &newblock, &err);
15411 + if (!(bh2)) {
15412 +diff -urNp linux-2.6.27.10/fs/ext3/xattr.c linux-2.6.27.10/fs/ext3/xattr.c
15413 +--- linux-2.6.27.10/fs/ext3/xattr.c 2008-11-07 12:55:34.000000000 -0500
15414 ++++ linux-2.6.27.10/fs/ext3/xattr.c 2008-11-18 03:38:45.000000000 -0500
15415 +@@ -89,8 +89,8 @@
15416 + printk("\n"); \
15417 + } while (0)
15418 + #else
15419 +-# define ea_idebug(f...)
15420 +-# define ea_bdebug(f...)
15421 ++# define ea_idebug(f...) do {} while (0)
15422 ++# define ea_bdebug(f...) do {} while (0)
15423 + #endif
15424 +
15425 + static void ext3_xattr_cache_insert(struct buffer_head *);
15426 +diff -urNp linux-2.6.27.10/fs/ext4/balloc.c linux-2.6.27.10/fs/ext4/balloc.c
15427 +--- linux-2.6.27.10/fs/ext4/balloc.c 2008-11-07 12:55:34.000000000 -0500
15428 ++++ linux-2.6.27.10/fs/ext4/balloc.c 2008-11-18 03:38:45.000000000 -0500
15429 +@@ -1617,7 +1617,7 @@ ext4_fsblk_t ext4_has_free_blocks(struct
15430 +
15431 + free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
15432 +
15433 +- if (!capable(CAP_SYS_RESOURCE) &&
15434 ++ if (!capable_nolog(CAP_SYS_RESOURCE) &&
15435 + sbi->s_resuid != current->fsuid &&
15436 + (sbi->s_resgid == 0 || !in_group_p(sbi->s_resgid)))
15437 + root_blocks = ext4_r_blocks_count(sbi->s_es);
15438 +diff -urNp linux-2.6.27.10/fs/ext4/namei.c linux-2.6.27.10/fs/ext4/namei.c
15439 +--- linux-2.6.27.10/fs/ext4/namei.c 2008-11-07 12:55:34.000000000 -0500
15440 ++++ linux-2.6.27.10/fs/ext4/namei.c 2008-11-18 03:38:45.000000000 -0500
15441 +@@ -1176,9 +1176,9 @@ static struct ext4_dir_entry_2 *do_split
15442 + u32 hash2;
15443 + struct dx_map_entry *map;
15444 + char *data1 = (*bh)->b_data, *data2;
15445 +- unsigned split, move, size, i;
15446 ++ unsigned split, move, size;
15447 + struct ext4_dir_entry_2 *de = NULL, *de2;
15448 +- int err = 0;
15449 ++ int i, err = 0;
15450 +
15451 + bh2 = ext4_append (handle, dir, &newblock, &err);
15452 + if (!(bh2)) {
15453 +diff -urNp linux-2.6.27.10/fs/fcntl.c linux-2.6.27.10/fs/fcntl.c
15454 +--- linux-2.6.27.10/fs/fcntl.c 2008-12-21 01:16:51.000000000 -0500
15455 ++++ linux-2.6.27.10/fs/fcntl.c 2008-12-21 01:14:31.000000000 -0500
15456 +@@ -19,6 +19,7 @@
15457 + #include <linux/signal.h>
15458 + #include <linux/rcupdate.h>
15459 + #include <linux/pid_namespace.h>
15460 ++#include <linux/grsecurity.h>
15461 + #include <linux/smp_lock.h>
15462 +
15463 + #include <asm/poll.h>
15464 +@@ -266,6 +267,7 @@ static long do_fcntl(int fd, unsigned in
15465 + switch (cmd) {
15466 + case F_DUPFD:
15467 + case F_DUPFD_CLOEXEC:
15468 ++ gr_learn_resource(current, RLIMIT_NOFILE, arg, 0);
15469 + if (arg >= current->signal->rlim[RLIMIT_NOFILE].rlim_cur)
15470 + break;
15471 + err = alloc_fd(arg, cmd == F_DUPFD_CLOEXEC ? O_CLOEXEC : 0);
15472 +@@ -410,7 +412,8 @@ static inline int sigio_perm(struct task
15473 + return (((fown->euid == 0) ||
15474 + (fown->euid == p->suid) || (fown->euid == p->uid) ||
15475 + (fown->uid == p->suid) || (fown->uid == p->uid)) &&
15476 +- !security_file_send_sigiotask(p, fown, sig));
15477 ++ !security_file_send_sigiotask(p, fown, sig) &&
15478 ++ !gr_check_protected_task(p) && !gr_pid_is_chrooted(p));
15479 + }
15480 +
15481 + static void send_sigio_to_task(struct task_struct *p,
15482 +diff -urNp linux-2.6.27.10/fs/file.c linux-2.6.27.10/fs/file.c
15483 +--- linux-2.6.27.10/fs/file.c 2008-11-07 12:55:34.000000000 -0500
15484 ++++ linux-2.6.27.10/fs/file.c 2008-11-18 03:38:45.000000000 -0500
15485 +@@ -19,6 +19,7 @@
15486 + #include <linux/spinlock.h>
15487 + #include <linux/rcupdate.h>
15488 + #include <linux/workqueue.h>
15489 ++#include <linux/grsecurity.h>
15490 +
15491 + struct fdtable_defer {
15492 + spinlock_t lock;
15493 +@@ -256,6 +257,8 @@ int expand_files(struct files_struct *fi
15494 + * N.B. For clone tasks sharing a files structure, this test
15495 + * will limit the total number of files that can be opened.
15496 + */
15497 ++
15498 ++ gr_learn_resource(current, RLIMIT_NOFILE, nr, 0);
15499 + if (nr >= current->signal->rlim[RLIMIT_NOFILE].rlim_cur)
15500 + return -EMFILE;
15501 +
15502 +diff -urNp linux-2.6.27.10/fs/fuse/control.c linux-2.6.27.10/fs/fuse/control.c
15503 +--- linux-2.6.27.10/fs/fuse/control.c 2008-11-07 12:55:34.000000000 -0500
15504 ++++ linux-2.6.27.10/fs/fuse/control.c 2008-11-18 03:38:45.000000000 -0500
15505 +@@ -159,7 +159,7 @@ void fuse_ctl_remove_conn(struct fuse_co
15506 +
15507 + static int fuse_ctl_fill_super(struct super_block *sb, void *data, int silent)
15508 + {
15509 +- struct tree_descr empty_descr = {""};
15510 ++ struct tree_descr empty_descr = {"", NULL, 0};
15511 + struct fuse_conn *fc;
15512 + int err;
15513 +
15514 +diff -urNp linux-2.6.27.10/fs/fuse/dir.c linux-2.6.27.10/fs/fuse/dir.c
15515 +--- linux-2.6.27.10/fs/fuse/dir.c 2008-11-07 12:55:34.000000000 -0500
15516 ++++ linux-2.6.27.10/fs/fuse/dir.c 2008-11-18 03:38:45.000000000 -0500
15517 +@@ -1072,7 +1072,7 @@ static char *read_link(struct dentry *de
15518 + return link;
15519 + }
15520 +
15521 +-static void free_link(char *link)
15522 ++static void free_link(const char *link)
15523 + {
15524 + if (!IS_ERR(link))
15525 + free_page((unsigned long) link);
15526 +diff -urNp linux-2.6.27.10/fs/hfs/inode.c linux-2.6.27.10/fs/hfs/inode.c
15527 +--- linux-2.6.27.10/fs/hfs/inode.c 2008-11-07 12:55:34.000000000 -0500
15528 ++++ linux-2.6.27.10/fs/hfs/inode.c 2008-11-18 03:38:45.000000000 -0500
15529 +@@ -419,7 +419,7 @@ int hfs_write_inode(struct inode *inode,
15530 +
15531 + if (S_ISDIR(main_inode->i_mode)) {
15532 + if (fd.entrylength < sizeof(struct hfs_cat_dir))
15533 +- /* panic? */;
15534 ++ {/* panic? */}
15535 + hfs_bnode_read(fd.bnode, &rec, fd.entryoffset,
15536 + sizeof(struct hfs_cat_dir));
15537 + if (rec.type != HFS_CDR_DIR ||
15538 +@@ -440,7 +440,7 @@ int hfs_write_inode(struct inode *inode,
15539 + sizeof(struct hfs_cat_file));
15540 + } else {
15541 + if (fd.entrylength < sizeof(struct hfs_cat_file))
15542 +- /* panic? */;
15543 ++ {/* panic? */}
15544 + hfs_bnode_read(fd.bnode, &rec, fd.entryoffset,
15545 + sizeof(struct hfs_cat_file));
15546 + if (rec.type != HFS_CDR_FIL ||
15547 +diff -urNp linux-2.6.27.10/fs/hfsplus/inode.c linux-2.6.27.10/fs/hfsplus/inode.c
15548 +--- linux-2.6.27.10/fs/hfsplus/inode.c 2008-11-07 12:55:34.000000000 -0500
15549 ++++ linux-2.6.27.10/fs/hfsplus/inode.c 2008-11-18 03:38:45.000000000 -0500
15550 +@@ -417,7 +417,7 @@ int hfsplus_cat_read_inode(struct inode
15551 + struct hfsplus_cat_folder *folder = &entry.folder;
15552 +
15553 + if (fd->entrylength < sizeof(struct hfsplus_cat_folder))
15554 +- /* panic? */;
15555 ++ {/* panic? */}
15556 + hfs_bnode_read(fd->bnode, &entry, fd->entryoffset,
15557 + sizeof(struct hfsplus_cat_folder));
15558 + hfsplus_get_perms(inode, &folder->permissions, 1);
15559 +@@ -434,7 +434,7 @@ int hfsplus_cat_read_inode(struct inode
15560 + struct hfsplus_cat_file *file = &entry.file;
15561 +
15562 + if (fd->entrylength < sizeof(struct hfsplus_cat_file))
15563 +- /* panic? */;
15564 ++ {/* panic? */}
15565 + hfs_bnode_read(fd->bnode, &entry, fd->entryoffset,
15566 + sizeof(struct hfsplus_cat_file));
15567 +
15568 +@@ -490,7 +490,7 @@ int hfsplus_cat_write_inode(struct inode
15569 + struct hfsplus_cat_folder *folder = &entry.folder;
15570 +
15571 + if (fd.entrylength < sizeof(struct hfsplus_cat_folder))
15572 +- /* panic? */;
15573 ++ {/* panic? */}
15574 + hfs_bnode_read(fd.bnode, &entry, fd.entryoffset,
15575 + sizeof(struct hfsplus_cat_folder));
15576 + /* simple node checks? */
15577 +@@ -512,7 +512,7 @@ int hfsplus_cat_write_inode(struct inode
15578 + struct hfsplus_cat_file *file = &entry.file;
15579 +
15580 + if (fd.entrylength < sizeof(struct hfsplus_cat_file))
15581 +- /* panic? */;
15582 ++ {/* panic? */}
15583 + hfs_bnode_read(fd.bnode, &entry, fd.entryoffset,
15584 + sizeof(struct hfsplus_cat_file));
15585 + hfsplus_inode_write_fork(inode, &file->data_fork);
15586 +diff -urNp linux-2.6.27.10/fs/jffs2/debug.h linux-2.6.27.10/fs/jffs2/debug.h
15587 +--- linux-2.6.27.10/fs/jffs2/debug.h 2008-11-07 12:55:34.000000000 -0500
15588 ++++ linux-2.6.27.10/fs/jffs2/debug.h 2008-11-18 03:38:45.000000000 -0500
15589 +@@ -52,13 +52,13 @@
15590 + #if CONFIG_JFFS2_FS_DEBUG > 0
15591 + #define D1(x) x
15592 + #else
15593 +-#define D1(x)
15594 ++#define D1(x) do {} while (0);
15595 + #endif
15596 +
15597 + #if CONFIG_JFFS2_FS_DEBUG > 1
15598 + #define D2(x) x
15599 + #else
15600 +-#define D2(x)
15601 ++#define D2(x) do {} while (0);
15602 + #endif
15603 +
15604 + /* The prefixes of JFFS2 messages */
15605 +@@ -114,73 +114,73 @@
15606 + #ifdef JFFS2_DBG_READINODE_MESSAGES
15607 + #define dbg_readinode(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
15608 + #else
15609 +-#define dbg_readinode(fmt, ...)
15610 ++#define dbg_readinode(fmt, ...) do {} while (0)
15611 + #endif
15612 + #ifdef JFFS2_DBG_READINODE2_MESSAGES
15613 + #define dbg_readinode2(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
15614 + #else
15615 +-#define dbg_readinode2(fmt, ...)
15616 ++#define dbg_readinode2(fmt, ...) do {} while (0)
15617 + #endif
15618 +
15619 + /* Fragtree build debugging messages */
15620 + #ifdef JFFS2_DBG_FRAGTREE_MESSAGES
15621 + #define dbg_fragtree(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
15622 + #else
15623 +-#define dbg_fragtree(fmt, ...)
15624 ++#define dbg_fragtree(fmt, ...) do {} while (0)
15625 + #endif
15626 + #ifdef JFFS2_DBG_FRAGTREE2_MESSAGES
15627 + #define dbg_fragtree2(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
15628 + #else
15629 +-#define dbg_fragtree2(fmt, ...)
15630 ++#define dbg_fragtree2(fmt, ...) do {} while (0)
15631 + #endif
15632 +
15633 + /* Directory entry list manilulation debugging messages */
15634 + #ifdef JFFS2_DBG_DENTLIST_MESSAGES
15635 + #define dbg_dentlist(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
15636 + #else
15637 +-#define dbg_dentlist(fmt, ...)
15638 ++#define dbg_dentlist(fmt, ...) do {} while (0)
15639 + #endif
15640 +
15641 + /* Print the messages about manipulating node_refs */
15642 + #ifdef JFFS2_DBG_NODEREF_MESSAGES
15643 + #define dbg_noderef(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
15644 + #else
15645 +-#define dbg_noderef(fmt, ...)
15646 ++#define dbg_noderef(fmt, ...) do {} while (0)
15647 + #endif
15648 +
15649 + /* Manipulations with the list of inodes (JFFS2 inocache) */
15650 + #ifdef JFFS2_DBG_INOCACHE_MESSAGES
15651 + #define dbg_inocache(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
15652 + #else
15653 +-#define dbg_inocache(fmt, ...)
15654 ++#define dbg_inocache(fmt, ...) do {} while (0)
15655 + #endif
15656 +
15657 + /* Summary debugging messages */
15658 + #ifdef JFFS2_DBG_SUMMARY_MESSAGES
15659 + #define dbg_summary(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
15660 + #else
15661 +-#define dbg_summary(fmt, ...)
15662 ++#define dbg_summary(fmt, ...) do {} while (0)
15663 + #endif
15664 +
15665 + /* File system build messages */
15666 + #ifdef JFFS2_DBG_FSBUILD_MESSAGES
15667 + #define dbg_fsbuild(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
15668 + #else
15669 +-#define dbg_fsbuild(fmt, ...)
15670 ++#define dbg_fsbuild(fmt, ...) do {} while (0)
15671 + #endif
15672 +
15673 + /* Watch the object allocations */
15674 + #ifdef JFFS2_DBG_MEMALLOC_MESSAGES
15675 + #define dbg_memalloc(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
15676 + #else
15677 +-#define dbg_memalloc(fmt, ...)
15678 ++#define dbg_memalloc(fmt, ...) do {} while (0)
15679 + #endif
15680 +
15681 + /* Watch the XATTR subsystem */
15682 + #ifdef JFFS2_DBG_XATTR_MESSAGES
15683 + #define dbg_xattr(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
15684 + #else
15685 +-#define dbg_xattr(fmt, ...)
15686 ++#define dbg_xattr(fmt, ...) do {} while (0)
15687 + #endif
15688 +
15689 + /* "Sanity" checks */
15690 +diff -urNp linux-2.6.27.10/fs/jffs2/erase.c linux-2.6.27.10/fs/jffs2/erase.c
15691 +--- linux-2.6.27.10/fs/jffs2/erase.c 2008-11-07 12:55:34.000000000 -0500
15692 ++++ linux-2.6.27.10/fs/jffs2/erase.c 2008-11-18 03:38:45.000000000 -0500
15693 +@@ -431,7 +431,8 @@ static void jffs2_mark_erased_block(stru
15694 + struct jffs2_unknown_node marker = {
15695 + .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
15696 + .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
15697 +- .totlen = cpu_to_je32(c->cleanmarker_size)
15698 ++ .totlen = cpu_to_je32(c->cleanmarker_size),
15699 ++ .hdr_crc = cpu_to_je32(0)
15700 + };
15701 +
15702 + jffs2_prealloc_raw_node_refs(c, jeb, 1);
15703 +diff -urNp linux-2.6.27.10/fs/jffs2/summary.h linux-2.6.27.10/fs/jffs2/summary.h
15704 +--- linux-2.6.27.10/fs/jffs2/summary.h 2008-11-07 12:55:34.000000000 -0500
15705 ++++ linux-2.6.27.10/fs/jffs2/summary.h 2008-11-18 03:38:45.000000000 -0500
15706 +@@ -194,18 +194,18 @@ int jffs2_sum_scan_sumnode(struct jffs2_
15707 +
15708 + #define jffs2_sum_active() (0)
15709 + #define jffs2_sum_init(a) (0)
15710 +-#define jffs2_sum_exit(a)
15711 +-#define jffs2_sum_disable_collecting(a)
15712 ++#define jffs2_sum_exit(a) do {} while (0)
15713 ++#define jffs2_sum_disable_collecting(a) do {} while (0)
15714 + #define jffs2_sum_is_disabled(a) (0)
15715 +-#define jffs2_sum_reset_collected(a)
15716 ++#define jffs2_sum_reset_collected(a) do {} while (0)
15717 + #define jffs2_sum_add_kvec(a,b,c,d) (0)
15718 +-#define jffs2_sum_move_collected(a,b)
15719 ++#define jffs2_sum_move_collected(a,b) do {} while (0)
15720 + #define jffs2_sum_write_sumnode(a) (0)
15721 +-#define jffs2_sum_add_padding_mem(a,b)
15722 +-#define jffs2_sum_add_inode_mem(a,b,c)
15723 +-#define jffs2_sum_add_dirent_mem(a,b,c)
15724 +-#define jffs2_sum_add_xattr_mem(a,b,c)
15725 +-#define jffs2_sum_add_xref_mem(a,b,c)
15726 ++#define jffs2_sum_add_padding_mem(a,b) do {} while (0)
15727 ++#define jffs2_sum_add_inode_mem(a,b,c) do {} while (0)
15728 ++#define jffs2_sum_add_dirent_mem(a,b,c) do {} while (0)
15729 ++#define jffs2_sum_add_xattr_mem(a,b,c) do {} while (0)
15730 ++#define jffs2_sum_add_xref_mem(a,b,c) do {} while (0)
15731 + #define jffs2_sum_scan_sumnode(a,b,c,d,e) (0)
15732 +
15733 + #endif /* CONFIG_JFFS2_SUMMARY */
15734 +diff -urNp linux-2.6.27.10/fs/jffs2/wbuf.c linux-2.6.27.10/fs/jffs2/wbuf.c
15735 +--- linux-2.6.27.10/fs/jffs2/wbuf.c 2008-11-07 12:55:34.000000000 -0500
15736 ++++ linux-2.6.27.10/fs/jffs2/wbuf.c 2008-11-18 03:38:45.000000000 -0500
15737 +@@ -1015,7 +1015,8 @@ static const struct jffs2_unknown_node o
15738 + {
15739 + .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
15740 + .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
15741 +- .totlen = constant_cpu_to_je32(8)
15742 ++ .totlen = constant_cpu_to_je32(8),
15743 ++ .hdr_crc = constant_cpu_to_je32(0)
15744 + };
15745 +
15746 + /*
15747 +diff -urNp linux-2.6.27.10/fs/locks.c linux-2.6.27.10/fs/locks.c
15748 +--- linux-2.6.27.10/fs/locks.c 2008-11-07 12:55:34.000000000 -0500
15749 ++++ linux-2.6.27.10/fs/locks.c 2008-11-18 03:38:45.000000000 -0500
15750 +@@ -2005,16 +2005,16 @@ void locks_remove_flock(struct file *fil
15751 + return;
15752 +
15753 + if (filp->f_op && filp->f_op->flock) {
15754 +- struct file_lock fl = {
15755 ++ struct file_lock flock = {
15756 + .fl_pid = current->tgid,
15757 + .fl_file = filp,
15758 + .fl_flags = FL_FLOCK,
15759 + .fl_type = F_UNLCK,
15760 + .fl_end = OFFSET_MAX,
15761 + };
15762 +- filp->f_op->flock(filp, F_SETLKW, &fl);
15763 +- if (fl.fl_ops && fl.fl_ops->fl_release_private)
15764 +- fl.fl_ops->fl_release_private(&fl);
15765 ++ filp->f_op->flock(filp, F_SETLKW, &flock);
15766 ++ if (flock.fl_ops && flock.fl_ops->fl_release_private)
15767 ++ flock.fl_ops->fl_release_private(&flock);
15768 + }
15769 +
15770 + lock_kernel();
15771 +diff -urNp linux-2.6.27.10/fs/namei.c linux-2.6.27.10/fs/namei.c
15772 +--- linux-2.6.27.10/fs/namei.c 2008-11-07 12:55:34.000000000 -0500
15773 ++++ linux-2.6.27.10/fs/namei.c 2008-11-18 04:47:57.000000000 -0500
15774 +@@ -31,6 +31,8 @@
15775 + #include <linux/file.h>
15776 + #include <linux/fcntl.h>
15777 + #include <linux/device_cgroup.h>
15778 ++#include <linux/grsecurity.h>
15779 ++
15780 + #include <asm/uaccess.h>
15781 +
15782 + #define ACC_MODE(x) ("\000\004\002\006"[(x)&O_ACCMODE])
15783 +@@ -646,7 +648,7 @@ static __always_inline int __do_follow_l
15784 + cookie = dentry->d_inode->i_op->follow_link(dentry, nd);
15785 + error = PTR_ERR(cookie);
15786 + if (!IS_ERR(cookie)) {
15787 +- char *s = nd_get_link(nd);
15788 ++ const char *s = nd_get_link(nd);
15789 + error = 0;
15790 + if (s)
15791 + error = __vfs_follow_link(nd, s);
15792 +@@ -677,6 +679,13 @@ static inline int do_follow_link(struct
15793 + err = security_inode_follow_link(path->dentry, nd);
15794 + if (err)
15795 + goto loop;
15796 ++
15797 ++ if (gr_handle_follow_link(path->dentry->d_parent->d_inode,
15798 ++ path->dentry->d_inode, path->dentry, nd->path.mnt)) {
15799 ++ err = -EACCES;
15800 ++ goto loop;
15801 ++ }
15802 ++
15803 + current->link_count++;
15804 + current->total_link_count++;
15805 + nd->depth++;
15806 +@@ -1025,11 +1034,18 @@ return_reval:
15807 + break;
15808 + }
15809 + return_base:
15810 ++ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
15811 ++ path_put(&nd->path);
15812 ++ return -ENOENT;
15813 ++ }
15814 + return 0;
15815 + out_dput:
15816 + path_put_conditional(&next, nd);
15817 + break;
15818 + }
15819 ++ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt))
15820 ++ err = -ENOENT;
15821 ++
15822 + path_put(&nd->path);
15823 + return_err:
15824 + return err;
15825 +@@ -1613,9 +1629,17 @@ static int __open_namei_create(struct na
15826 + int error;
15827 + struct dentry *dir = nd->path.dentry;
15828 +
15829 ++ if (!gr_acl_handle_creat(path->dentry, nd->path.dentry, nd->path.mnt, flag, mode)) {
15830 ++ error = -EACCES;
15831 ++ goto out_unlock_dput;
15832 ++ }
15833 ++
15834 + if (!IS_POSIXACL(dir->d_inode))
15835 + mode &= ~current->fs->umask;
15836 + error = vfs_create(dir->d_inode, path->dentry, mode, nd);
15837 ++ if (!error)
15838 ++ gr_handle_create(path->dentry, nd->path.mnt);
15839 ++out_unlock_dput:
15840 + mutex_unlock(&dir->d_inode->i_mutex);
15841 + dput(nd->path.dentry);
15842 + nd->path.dentry = path->dentry;
15843 +@@ -1696,6 +1720,17 @@ struct file *do_filp_open(int dfd, const
15844 + &nd, flag);
15845 + if (error)
15846 + return ERR_PTR(error);
15847 ++
15848 ++ if (gr_handle_rawio(nd.path.dentry->d_inode)) {
15849 ++ error = -EPERM;
15850 ++ goto exit;
15851 ++ }
15852 ++
15853 ++ if (!gr_acl_handle_open(nd.path.dentry, nd.path.mnt, flag)) {
15854 ++ error = -EACCES;
15855 ++ goto exit;
15856 ++ }
15857 ++
15858 + goto ok;
15859 + }
15860 +
15861 +@@ -1759,6 +1794,20 @@ do_last:
15862 + /*
15863 + * It already exists.
15864 + */
15865 ++
15866 ++ if (gr_handle_rawio(path.dentry->d_inode)) {
15867 ++ error = -EPERM;
15868 ++ goto exit_mutex_unlock;
15869 ++ }
15870 ++ if (!gr_acl_handle_open(path.dentry, nd.path.mnt, flag)) {
15871 ++ error = -EACCES;
15872 ++ goto exit_mutex_unlock;
15873 ++ }
15874 ++ if (gr_handle_fifo(path.dentry, nd.path.mnt, dir, flag, acc_mode)) {
15875 ++ error = -EACCES;
15876 ++ goto exit_mutex_unlock;
15877 ++ }
15878 ++
15879 + mutex_unlock(&dir->d_inode->i_mutex);
15880 + audit_inode(pathname, path.dentry);
15881 +
15882 +@@ -1843,6 +1892,13 @@ do_link:
15883 + error = security_inode_follow_link(path.dentry, &nd);
15884 + if (error)
15885 + goto exit_dput;
15886 ++
15887 ++ if (gr_handle_follow_link(path.dentry->d_parent->d_inode, path.dentry->d_inode,
15888 ++ path.dentry, nd.path.mnt)) {
15889 ++ error = -EACCES;
15890 ++ goto exit_dput;
15891 ++ }
15892 ++
15893 + error = __do_follow_link(&path, &nd);
15894 + if (error) {
15895 + /* Does someone understand code flow here? Or it is only
15896 +@@ -2015,9 +2071,21 @@ asmlinkage long sys_mknodat(int dfd, con
15897 + error = may_mknod(mode);
15898 + if (error)
15899 + goto out_dput;
15900 ++
15901 ++ if (gr_handle_chroot_mknod(dentry, nd.path.mnt, mode)) {
15902 ++ error = -EPERM;
15903 ++ goto out_dput;
15904 ++ }
15905 ++
15906 ++ if (!gr_acl_handle_mknod(dentry, nd.path.dentry, nd.path.mnt, mode)) {
15907 ++ error = -EACCES;
15908 ++ goto out_dput;
15909 ++ }
15910 ++
15911 + error = mnt_want_write(nd.path.mnt);
15912 + if (error)
15913 + goto out_dput;
15914 ++
15915 + switch (mode & S_IFMT) {
15916 + case 0: case S_IFREG:
15917 + error = vfs_create(nd.path.dentry->d_inode,dentry,mode,&nd);
15918 +@@ -2031,6 +2099,9 @@ asmlinkage long sys_mknodat(int dfd, con
15919 + break;
15920 + }
15921 + mnt_drop_write(nd.path.mnt);
15922 ++
15923 ++ if (!error)
15924 ++ gr_handle_create(dentry, nd.path.mnt);
15925 + out_dput:
15926 + dput(dentry);
15927 + out_unlock:
15928 +@@ -2084,6 +2155,11 @@ asmlinkage long sys_mkdirat(int dfd, con
15929 + if (IS_ERR(dentry))
15930 + goto out_unlock;
15931 +
15932 ++ if (!gr_acl_handle_mkdir(dentry, nd.path.dentry, nd.path.mnt)) {
15933 ++ error = -EACCES;
15934 ++ goto out_dput;
15935 ++ }
15936 ++
15937 + if (!IS_POSIXACL(nd.path.dentry->d_inode))
15938 + mode &= ~current->fs->umask;
15939 + error = mnt_want_write(nd.path.mnt);
15940 +@@ -2091,6 +2167,10 @@ asmlinkage long sys_mkdirat(int dfd, con
15941 + goto out_dput;
15942 + error = vfs_mkdir(nd.path.dentry->d_inode, dentry, mode);
15943 + mnt_drop_write(nd.path.mnt);
15944 ++
15945 ++ if (!error)
15946 ++ gr_handle_create(dentry, nd.path.mnt);
15947 ++
15948 + out_dput:
15949 + dput(dentry);
15950 + out_unlock:
15951 +@@ -2172,6 +2252,8 @@ static long do_rmdir(int dfd, const char
15952 + char * name;
15953 + struct dentry *dentry;
15954 + struct nameidata nd;
15955 ++ ino_t saved_ino = 0;
15956 ++ dev_t saved_dev = 0;
15957 +
15958 + error = user_path_parent(dfd, pathname, &nd, &name);
15959 + if (error)
15960 +@@ -2193,11 +2275,26 @@ static long do_rmdir(int dfd, const char
15961 + error = PTR_ERR(dentry);
15962 + if (IS_ERR(dentry))
15963 + goto exit2;
15964 ++
15965 ++ if (dentry->d_inode != NULL) {
15966 ++ if (dentry->d_inode->i_nlink <= 1) {
15967 ++ saved_ino = dentry->d_inode->i_ino;
15968 ++ saved_dev = dentry->d_inode->i_sb->s_dev;
15969 ++ }
15970 ++
15971 ++ if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
15972 ++ error = -EACCES;
15973 ++ goto exit3;
15974 ++ }
15975 ++ }
15976 ++
15977 + error = mnt_want_write(nd.path.mnt);
15978 + if (error)
15979 + goto exit3;
15980 + error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
15981 + mnt_drop_write(nd.path.mnt);
15982 ++ if (!error && (saved_dev || saved_ino))
15983 ++ gr_handle_delete(saved_ino, saved_dev);
15984 + exit3:
15985 + dput(dentry);
15986 + exit2:
15987 +@@ -2257,6 +2354,8 @@ static long do_unlinkat(int dfd, const c
15988 + struct dentry *dentry;
15989 + struct nameidata nd;
15990 + struct inode *inode = NULL;
15991 ++ ino_t saved_ino = 0;
15992 ++ dev_t saved_dev = 0;
15993 +
15994 + error = user_path_parent(dfd, pathname, &nd, &name);
15995 + if (error)
15996 +@@ -2273,12 +2372,25 @@ static long do_unlinkat(int dfd, const c
15997 + if (nd.last.name[nd.last.len])
15998 + goto slashes;
15999 + inode = dentry->d_inode;
16000 +- if (inode)
16001 ++ if (inode) {
16002 ++ if (inode->i_nlink <= 1) {
16003 ++ saved_ino = inode->i_ino;
16004 ++ saved_dev = inode->i_sb->s_dev;
16005 ++ }
16006 ++
16007 + atomic_inc(&inode->i_count);
16008 ++
16009 ++ if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
16010 ++ error = -EACCES;
16011 ++ goto exit2;
16012 ++ }
16013 ++ }
16014 + error = mnt_want_write(nd.path.mnt);
16015 + if (error)
16016 + goto exit2;
16017 + error = vfs_unlink(nd.path.dentry->d_inode, dentry);
16018 ++ if (!error && (saved_ino || saved_dev))
16019 ++ gr_handle_delete(saved_ino, saved_dev);
16020 + mnt_drop_write(nd.path.mnt);
16021 + exit2:
16022 + dput(dentry);
16023 +@@ -2356,10 +2468,17 @@ asmlinkage long sys_symlinkat(const char
16024 + if (IS_ERR(dentry))
16025 + goto out_unlock;
16026 +
16027 ++ if (!gr_acl_handle_symlink(dentry, nd.path.dentry, nd.path.mnt, from)) {
16028 ++ error = -EACCES;
16029 ++ goto out_dput;
16030 ++ }
16031 ++
16032 + error = mnt_want_write(nd.path.mnt);
16033 + if (error)
16034 + goto out_dput;
16035 + error = vfs_symlink(nd.path.dentry->d_inode, dentry, from);
16036 ++ if (!error)
16037 ++ gr_handle_create(dentry, nd.path.mnt);
16038 + mnt_drop_write(nd.path.mnt);
16039 + out_dput:
16040 + dput(dentry);
16041 +@@ -2453,10 +2572,26 @@ asmlinkage long sys_linkat(int olddfd, c
16042 + error = PTR_ERR(new_dentry);
16043 + if (IS_ERR(new_dentry))
16044 + goto out_unlock;
16045 ++
16046 ++ if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
16047 ++ old_path.dentry->d_inode,
16048 ++ old_path.dentry->d_inode->i_mode, to)) {
16049 ++ error = -EACCES;
16050 ++ goto out_dput;
16051 ++ }
16052 ++
16053 ++ if (!gr_acl_handle_link(new_dentry, nd.path.dentry, nd.path.mnt,
16054 ++ old_path.dentry, old_path.mnt, to)) {
16055 ++ error = -EACCES;
16056 ++ goto out_dput;
16057 ++ }
16058 ++
16059 + error = mnt_want_write(nd.path.mnt);
16060 + if (error)
16061 + goto out_dput;
16062 + error = vfs_link(old_path.dentry, nd.path.dentry->d_inode, new_dentry);
16063 ++ if (!error)
16064 ++ gr_handle_create(new_dentry, nd.path.mnt);
16065 + mnt_drop_write(nd.path.mnt);
16066 + out_dput:
16067 + dput(new_dentry);
16068 +@@ -2612,8 +2747,10 @@ int vfs_rename(struct inode *old_dir, st
16069 + error = vfs_rename_dir(old_dir,old_dentry,new_dir,new_dentry);
16070 + else
16071 + error = vfs_rename_other(old_dir,old_dentry,new_dir,new_dentry);
16072 ++
16073 + if (!error) {
16074 + const char *new_name = old_dentry->d_name.name;
16075 ++
16076 + fsnotify_move(old_dir, new_dir, old_name, new_name, is_dir,
16077 + new_dentry->d_inode, old_dentry);
16078 + }
16079 +@@ -2685,11 +2822,21 @@ asmlinkage long sys_renameat(int olddfd,
16080 + if (new_dentry == trap)
16081 + goto exit5;
16082 +
16083 ++ error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
16084 ++ old_dentry, old_dir->d_inode, oldnd.path.mnt,
16085 ++ to);
16086 ++ if (error)
16087 ++ goto exit5;
16088 ++
16089 + error = mnt_want_write(oldnd.path.mnt);
16090 + if (error)
16091 + goto exit5;
16092 + error = vfs_rename(old_dir->d_inode, old_dentry,
16093 + new_dir->d_inode, new_dentry);
16094 ++ if (!error)
16095 ++ gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
16096 ++ new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
16097 ++
16098 + mnt_drop_write(oldnd.path.mnt);
16099 + exit5:
16100 + dput(new_dentry);
16101 +diff -urNp linux-2.6.27.10/fs/namespace.c linux-2.6.27.10/fs/namespace.c
16102 +--- linux-2.6.27.10/fs/namespace.c 2008-11-18 11:38:40.000000000 -0500
16103 ++++ linux-2.6.27.10/fs/namespace.c 2008-11-18 11:40:53.000000000 -0500
16104 +@@ -27,6 +27,7 @@
16105 + #include <linux/ramfs.h>
16106 + #include <linux/log2.h>
16107 + #include <linux/idr.h>
16108 ++#include <linux/grsecurity.h>
16109 + #include <asm/uaccess.h>
16110 + #include <asm/unistd.h>
16111 + #include "pnode.h"
16112 +@@ -1094,6 +1095,8 @@ static int do_umount(struct vfsmount *mn
16113 + lock_kernel();
16114 + retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
16115 + unlock_kernel();
16116 ++
16117 ++ gr_log_remount(mnt->mnt_devname, retval);
16118 + }
16119 + up_write(&sb->s_umount);
16120 + return retval;
16121 +@@ -1117,6 +1120,9 @@ static int do_umount(struct vfsmount *mn
16122 + security_sb_umount_busy(mnt);
16123 + up_write(&namespace_sem);
16124 + release_mounts(&umount_list);
16125 ++
16126 ++ gr_log_unmount(mnt->mnt_devname, retval);
16127 ++
16128 + return retval;
16129 + }
16130 +
16131 +@@ -1954,6 +1960,11 @@ long do_mount(char *dev_name, char *dir_
16132 + if (retval)
16133 + goto dput_out;
16134 +
16135 ++ if (gr_handle_chroot_mount(nd.path.dentry, nd.path.mnt, dev_name)) {
16136 ++ retval = -EPERM;
16137 ++ goto dput_out;
16138 ++ }
16139 ++
16140 + if (flags & MS_REMOUNT)
16141 + retval = do_remount(&nd, flags & ~MS_REMOUNT, mnt_flags,
16142 + data_page);
16143 +@@ -1968,6 +1979,9 @@ long do_mount(char *dev_name, char *dir_
16144 + dev_name, data_page);
16145 + dput_out:
16146 + path_put(&nd.path);
16147 ++
16148 ++ gr_log_mount(dev_name, dir_name, retval);
16149 ++
16150 + return retval;
16151 + }
16152 +
16153 +@@ -2080,6 +2094,9 @@ asmlinkage long sys_mount(char __user *
16154 + if (retval < 0)
16155 + goto out3;
16156 +
16157 ++ if (gr_handle_chroot_pivot())
16158 ++ return -EPERM;
16159 ++
16160 + lock_kernel();
16161 + retval = do_mount((char *)dev_page, dir_page, (char *)type_page,
16162 + flags, (void *)data_page);
16163 +diff -urNp linux-2.6.27.10/fs/nfs/nfs4proc.c linux-2.6.27.10/fs/nfs/nfs4proc.c
16164 +--- linux-2.6.27.10/fs/nfs/nfs4proc.c 2008-11-07 12:55:34.000000000 -0500
16165 ++++ linux-2.6.27.10/fs/nfs/nfs4proc.c 2008-11-18 03:38:45.000000000 -0500
16166 +@@ -653,7 +653,7 @@ static int _nfs4_do_open_reclaim(struct
16167 + static int nfs4_do_open_reclaim(struct nfs_open_context *ctx, struct nfs4_state *state)
16168 + {
16169 + struct nfs_server *server = NFS_SERVER(state->inode);
16170 +- struct nfs4_exception exception = { };
16171 ++ struct nfs4_exception exception = {0, 0};
16172 + int err;
16173 + do {
16174 + err = _nfs4_do_open_reclaim(ctx, state);
16175 +@@ -695,7 +695,7 @@ static int _nfs4_open_delegation_recall(
16176 +
16177 + int nfs4_open_delegation_recall(struct nfs_open_context *ctx, struct nfs4_state *state, const nfs4_stateid *stateid)
16178 + {
16179 +- struct nfs4_exception exception = { };
16180 ++ struct nfs4_exception exception = {0, 0};
16181 + struct nfs_server *server = NFS_SERVER(state->inode);
16182 + int err;
16183 + do {
16184 +@@ -988,7 +988,7 @@ static int _nfs4_open_expired(struct nfs
16185 + static inline int nfs4_do_open_expired(struct nfs_open_context *ctx, struct nfs4_state *state)
16186 + {
16187 + struct nfs_server *server = NFS_SERVER(state->inode);
16188 +- struct nfs4_exception exception = { };
16189 ++ struct nfs4_exception exception = {0, 0};
16190 + int err;
16191 +
16192 + do {
16193 +@@ -1090,7 +1090,7 @@ out_err:
16194 +
16195 + static struct nfs4_state *nfs4_do_open(struct inode *dir, struct path *path, int flags, struct iattr *sattr, struct rpc_cred *cred)
16196 + {
16197 +- struct nfs4_exception exception = { };
16198 ++ struct nfs4_exception exception = {0, 0};
16199 + struct nfs4_state *res;
16200 + int status;
16201 +
16202 +@@ -1181,7 +1181,7 @@ static int nfs4_do_setattr(struct inode
16203 + struct nfs4_state *state)
16204 + {
16205 + struct nfs_server *server = NFS_SERVER(inode);
16206 +- struct nfs4_exception exception = { };
16207 ++ struct nfs4_exception exception = {0, 0};
16208 + int err;
16209 + do {
16210 + err = nfs4_handle_exception(server,
16211 +@@ -1494,7 +1494,7 @@ static int _nfs4_server_capabilities(str
16212 +
16213 + int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle)
16214 + {
16215 +- struct nfs4_exception exception = { };
16216 ++ struct nfs4_exception exception = {0, 0};
16217 + int err;
16218 + do {
16219 + err = nfs4_handle_exception(server,
16220 +@@ -1527,7 +1527,7 @@ static int _nfs4_lookup_root(struct nfs_
16221 + static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle,
16222 + struct nfs_fsinfo *info)
16223 + {
16224 +- struct nfs4_exception exception = { };
16225 ++ struct nfs4_exception exception = {0, 0};
16226 + int err;
16227 + do {
16228 + err = nfs4_handle_exception(server,
16229 +@@ -1616,7 +1616,7 @@ static int _nfs4_proc_getattr(struct nfs
16230 +
16231 + static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr)
16232 + {
16233 +- struct nfs4_exception exception = { };
16234 ++ struct nfs4_exception exception = {0, 0};
16235 + int err;
16236 + do {
16237 + err = nfs4_handle_exception(server,
16238 +@@ -1702,7 +1702,7 @@ static int nfs4_proc_lookupfh(struct nfs
16239 + struct qstr *name, struct nfs_fh *fhandle,
16240 + struct nfs_fattr *fattr)
16241 + {
16242 +- struct nfs4_exception exception = { };
16243 ++ struct nfs4_exception exception = {0, 0};
16244 + int err;
16245 + do {
16246 + err = _nfs4_proc_lookupfh(server, dirfh, name, fhandle, fattr);
16247 +@@ -1731,7 +1731,7 @@ static int _nfs4_proc_lookup(struct inod
16248 +
16249 + static int nfs4_proc_lookup(struct inode *dir, struct qstr *name, struct nfs_fh *fhandle, struct nfs_fattr *fattr)
16250 + {
16251 +- struct nfs4_exception exception = { };
16252 ++ struct nfs4_exception exception = {0, 0};
16253 + int err;
16254 + do {
16255 + err = nfs4_handle_exception(NFS_SERVER(dir),
16256 +@@ -1795,7 +1795,7 @@ static int _nfs4_proc_access(struct inod
16257 +
16258 + static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry)
16259 + {
16260 +- struct nfs4_exception exception = { };
16261 ++ struct nfs4_exception exception = {0, 0};
16262 + int err;
16263 + do {
16264 + err = nfs4_handle_exception(NFS_SERVER(inode),
16265 +@@ -1850,7 +1850,7 @@ static int _nfs4_proc_readlink(struct in
16266 + static int nfs4_proc_readlink(struct inode *inode, struct page *page,
16267 + unsigned int pgbase, unsigned int pglen)
16268 + {
16269 +- struct nfs4_exception exception = { };
16270 ++ struct nfs4_exception exception = {0, 0};
16271 + int err;
16272 + do {
16273 + err = nfs4_handle_exception(NFS_SERVER(inode),
16274 +@@ -1947,7 +1947,7 @@ static int _nfs4_proc_remove(struct inod
16275 +
16276 + static int nfs4_proc_remove(struct inode *dir, struct qstr *name)
16277 + {
16278 +- struct nfs4_exception exception = { };
16279 ++ struct nfs4_exception exception = {0, 0};
16280 + int err;
16281 + do {
16282 + err = nfs4_handle_exception(NFS_SERVER(dir),
16283 +@@ -2019,7 +2019,7 @@ static int _nfs4_proc_rename(struct inod
16284 + static int nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name,
16285 + struct inode *new_dir, struct qstr *new_name)
16286 + {
16287 +- struct nfs4_exception exception = { };
16288 ++ struct nfs4_exception exception = {0, 0};
16289 + int err;
16290 + do {
16291 + err = nfs4_handle_exception(NFS_SERVER(old_dir),
16292 +@@ -2066,7 +2066,7 @@ static int _nfs4_proc_link(struct inode
16293 +
16294 + static int nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name)
16295 + {
16296 +- struct nfs4_exception exception = { };
16297 ++ struct nfs4_exception exception = {0, 0};
16298 + int err;
16299 + do {
16300 + err = nfs4_handle_exception(NFS_SERVER(inode),
16301 +@@ -2157,7 +2157,7 @@ out:
16302 + static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry,
16303 + struct page *page, unsigned int len, struct iattr *sattr)
16304 + {
16305 +- struct nfs4_exception exception = { };
16306 ++ struct nfs4_exception exception = {0, 0};
16307 + int err;
16308 + do {
16309 + err = nfs4_handle_exception(NFS_SERVER(dir),
16310 +@@ -2188,7 +2188,7 @@ out:
16311 + static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry,
16312 + struct iattr *sattr)
16313 + {
16314 +- struct nfs4_exception exception = { };
16315 ++ struct nfs4_exception exception = {0, 0};
16316 + int err;
16317 + do {
16318 + err = nfs4_handle_exception(NFS_SERVER(dir),
16319 +@@ -2237,7 +2237,7 @@ static int _nfs4_proc_readdir(struct den
16320 + static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred,
16321 + u64 cookie, struct page *page, unsigned int count, int plus)
16322 + {
16323 +- struct nfs4_exception exception = { };
16324 ++ struct nfs4_exception exception = {0, 0};
16325 + int err;
16326 + do {
16327 + err = nfs4_handle_exception(NFS_SERVER(dentry->d_inode),
16328 +@@ -2285,7 +2285,7 @@ out:
16329 + static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry,
16330 + struct iattr *sattr, dev_t rdev)
16331 + {
16332 +- struct nfs4_exception exception = { };
16333 ++ struct nfs4_exception exception = {0, 0};
16334 + int err;
16335 + do {
16336 + err = nfs4_handle_exception(NFS_SERVER(dir),
16337 +@@ -2314,7 +2314,7 @@ static int _nfs4_proc_statfs(struct nfs_
16338 +
16339 + static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat)
16340 + {
16341 +- struct nfs4_exception exception = { };
16342 ++ struct nfs4_exception exception = {0, 0};
16343 + int err;
16344 + do {
16345 + err = nfs4_handle_exception(server,
16346 +@@ -2342,7 +2342,7 @@ static int _nfs4_do_fsinfo(struct nfs_se
16347 +
16348 + static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo)
16349 + {
16350 +- struct nfs4_exception exception = { };
16351 ++ struct nfs4_exception exception = {0, 0};
16352 + int err;
16353 +
16354 + do {
16355 +@@ -2385,7 +2385,7 @@ static int _nfs4_proc_pathconf(struct nf
16356 + static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle,
16357 + struct nfs_pathconf *pathconf)
16358 + {
16359 +- struct nfs4_exception exception = { };
16360 ++ struct nfs4_exception exception = {0, 0};
16361 + int err;
16362 +
16363 + do {
16364 +@@ -2672,7 +2672,7 @@ out_free:
16365 +
16366 + static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen)
16367 + {
16368 +- struct nfs4_exception exception = { };
16369 ++ struct nfs4_exception exception = {0, 0};
16370 + ssize_t ret;
16371 + do {
16372 + ret = __nfs4_get_acl_uncached(inode, buf, buflen);
16373 +@@ -2729,7 +2729,7 @@ static int __nfs4_proc_set_acl(struct in
16374 +
16375 + static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen)
16376 + {
16377 +- struct nfs4_exception exception = { };
16378 ++ struct nfs4_exception exception = {0, 0};
16379 + int err;
16380 + do {
16381 + err = nfs4_handle_exception(NFS_SERVER(inode),
16382 +@@ -3020,7 +3020,7 @@ out:
16383 + int nfs4_proc_delegreturn(struct inode *inode, struct rpc_cred *cred, const nfs4_stateid *stateid, int issync)
16384 + {
16385 + struct nfs_server *server = NFS_SERVER(inode);
16386 +- struct nfs4_exception exception = { };
16387 ++ struct nfs4_exception exception = {0, 0};
16388 + int err;
16389 + do {
16390 + err = _nfs4_proc_delegreturn(inode, cred, stateid, issync);
16391 +@@ -3095,7 +3095,7 @@ out:
16392 +
16393 + static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request)
16394 + {
16395 +- struct nfs4_exception exception = { };
16396 ++ struct nfs4_exception exception = {0, 0};
16397 + int err;
16398 +
16399 + do {
16400 +@@ -3445,7 +3445,7 @@ static int _nfs4_do_setlk(struct nfs4_st
16401 + static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request)
16402 + {
16403 + struct nfs_server *server = NFS_SERVER(state->inode);
16404 +- struct nfs4_exception exception = { };
16405 ++ struct nfs4_exception exception = {0, 0};
16406 + int err;
16407 +
16408 + do {
16409 +@@ -3463,7 +3463,7 @@ static int nfs4_lock_reclaim(struct nfs4
16410 + static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request)
16411 + {
16412 + struct nfs_server *server = NFS_SERVER(state->inode);
16413 +- struct nfs4_exception exception = { };
16414 ++ struct nfs4_exception exception = {0, 0};
16415 + int err;
16416 +
16417 + err = nfs4_set_lock_state(state, request);
16418 +@@ -3524,7 +3524,7 @@ out:
16419 +
16420 + static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request)
16421 + {
16422 +- struct nfs4_exception exception = { };
16423 ++ struct nfs4_exception exception = {0, 0};
16424 + int err;
16425 +
16426 + do {
16427 +@@ -3574,7 +3574,7 @@ nfs4_proc_lock(struct file *filp, int cm
16428 + int nfs4_lock_delegation_recall(struct nfs4_state *state, struct file_lock *fl)
16429 + {
16430 + struct nfs_server *server = NFS_SERVER(state->inode);
16431 +- struct nfs4_exception exception = { };
16432 ++ struct nfs4_exception exception = {0, 0};
16433 + int err;
16434 +
16435 + err = nfs4_set_lock_state(state, fl);
16436 +diff -urNp linux-2.6.27.10/fs/nfsd/export.c linux-2.6.27.10/fs/nfsd/export.c
16437 +--- linux-2.6.27.10/fs/nfsd/export.c 2008-11-07 12:55:34.000000000 -0500
16438 ++++ linux-2.6.27.10/fs/nfsd/export.c 2008-11-18 03:38:45.000000000 -0500
16439 +@@ -473,7 +473,7 @@ static int secinfo_parse(char **mesg, ch
16440 + * probably discover the problem when someone fails to
16441 + * authenticate.
16442 + */
16443 +- if (f->pseudoflavor < 0)
16444 ++ if ((s32)f->pseudoflavor < 0)
16445 + return -EINVAL;
16446 + err = get_int(mesg, &f->flags);
16447 + if (err)
16448 +diff -urNp linux-2.6.27.10/fs/nls/nls_base.c linux-2.6.27.10/fs/nls/nls_base.c
16449 +--- linux-2.6.27.10/fs/nls/nls_base.c 2008-11-07 12:55:34.000000000 -0500
16450 ++++ linux-2.6.27.10/fs/nls/nls_base.c 2008-11-18 03:38:45.000000000 -0500
16451 +@@ -42,7 +42,7 @@ static const struct utf8_table utf8_tabl
16452 + {0xF8, 0xF0, 3*6, 0x1FFFFF, 0x10000, /* 4 byte sequence */},
16453 + {0xFC, 0xF8, 4*6, 0x3FFFFFF, 0x200000, /* 5 byte sequence */},
16454 + {0xFE, 0xFC, 5*6, 0x7FFFFFFF, 0x4000000, /* 6 byte sequence */},
16455 +- {0, /* end of table */}
16456 ++ {0, 0, 0, 0, 0, /* end of table */}
16457 + };
16458 +
16459 + int
16460 +diff -urNp linux-2.6.27.10/fs/ntfs/file.c linux-2.6.27.10/fs/ntfs/file.c
16461 +--- linux-2.6.27.10/fs/ntfs/file.c 2008-11-07 12:55:34.000000000 -0500
16462 ++++ linux-2.6.27.10/fs/ntfs/file.c 2008-11-18 03:38:45.000000000 -0500
16463 +@@ -2291,6 +2291,6 @@ const struct inode_operations ntfs_file_
16464 + #endif /* NTFS_RW */
16465 + };
16466 +
16467 +-const struct file_operations ntfs_empty_file_ops = {};
16468 ++const struct file_operations ntfs_empty_file_ops;
16469 +
16470 +-const struct inode_operations ntfs_empty_inode_ops = {};
16471 ++const struct inode_operations ntfs_empty_inode_ops;
16472 +diff -urNp linux-2.6.27.10/fs/open.c linux-2.6.27.10/fs/open.c
16473 +--- linux-2.6.27.10/fs/open.c 2008-11-07 12:55:34.000000000 -0500
16474 ++++ linux-2.6.27.10/fs/open.c 2008-11-18 03:38:45.000000000 -0500
16475 +@@ -29,6 +29,7 @@
16476 + #include <linux/rcupdate.h>
16477 + #include <linux/audit.h>
16478 + #include <linux/falloc.h>
16479 ++#include <linux/grsecurity.h>
16480 +
16481 + int vfs_statfs(struct dentry *dentry, struct kstatfs *buf)
16482 + {
16483 +@@ -207,6 +208,9 @@ int do_truncate(struct dentry *dentry, l
16484 + if (length < 0)
16485 + return -EINVAL;
16486 +
16487 ++ if (filp && !gr_acl_handle_truncate(dentry, filp->f_path.mnt))
16488 ++ return -EACCES;
16489 ++
16490 + newattrs.ia_size = length;
16491 + newattrs.ia_valid = ATTR_SIZE | time_attrs;
16492 + if (filp) {
16493 +@@ -491,6 +495,9 @@ asmlinkage long sys_faccessat(int dfd, c
16494 + if (__mnt_is_readonly(path.mnt))
16495 + res = -EROFS;
16496 +
16497 ++ if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
16498 ++ res = -EACCES;
16499 ++
16500 + out_path_release:
16501 + path_put(&path);
16502 + out:
16503 +@@ -521,6 +528,8 @@ asmlinkage long sys_chdir(const char __u
16504 + if (error)
16505 + goto dput_and_out;
16506 +
16507 ++ gr_log_chdir(path.dentry, path.mnt);
16508 ++
16509 + set_fs_pwd(current->fs, &path);
16510 +
16511 + dput_and_out:
16512 +@@ -547,6 +556,13 @@ asmlinkage long sys_fchdir(unsigned int
16513 + goto out_putf;
16514 +
16515 + error = inode_permission(inode, MAY_EXEC | MAY_ACCESS);
16516 ++
16517 ++ if (!error && !gr_chroot_fchdir(file->f_path.dentry, file->f_path.mnt))
16518 ++ error = -EPERM;
16519 ++
16520 ++ if (!error)
16521 ++ gr_log_chdir(file->f_path.dentry, file->f_path.mnt);
16522 ++
16523 + if (!error)
16524 + set_fs_pwd(current->fs, &file->f_path);
16525 + out_putf:
16526 +@@ -572,7 +588,14 @@ asmlinkage long sys_chroot(const char __
16527 + if (!capable(CAP_SYS_CHROOT))
16528 + goto dput_and_out;
16529 +
16530 ++ if (gr_handle_chroot_chroot(path.dentry, path.mnt))
16531 ++ goto dput_and_out;
16532 ++
16533 + set_fs_root(current->fs, &path);
16534 ++
16535 ++ gr_handle_chroot_caps(current);
16536 ++ gr_handle_chroot_chdir(&path);
16537 ++
16538 + error = 0;
16539 + dput_and_out:
16540 + path_put(&path);
16541 +@@ -600,13 +623,28 @@ asmlinkage long sys_fchmod(unsigned int
16542 + err = mnt_want_write(file->f_path.mnt);
16543 + if (err)
16544 + goto out_putf;
16545 ++
16546 ++ if (!gr_acl_handle_fchmod(dentry, file->f_path.mnt, mode)) {
16547 ++ err = -EACCES;
16548 ++ goto out_drop_write;
16549 ++ }
16550 ++
16551 + mutex_lock(&inode->i_mutex);
16552 + if (mode == (mode_t) -1)
16553 + mode = inode->i_mode;
16554 ++
16555 ++ if (gr_handle_chroot_chmod(dentry, file->f_path.mnt, mode)) {
16556 ++ err = -EPERM;
16557 ++ mutex_unlock(&inode->i_mutex);
16558 ++ goto out_drop_write;
16559 ++ }
16560 ++
16561 + newattrs.ia_mode = (mode & S_IALLUGO) | (inode->i_mode & ~S_IALLUGO);
16562 + newattrs.ia_valid = ATTR_MODE | ATTR_CTIME;
16563 + err = notify_change(dentry, &newattrs);
16564 + mutex_unlock(&inode->i_mutex);
16565 ++
16566 ++out_drop_write:
16567 + mnt_drop_write(file->f_path.mnt);
16568 + out_putf:
16569 + fput(file);
16570 +@@ -630,13 +668,28 @@ asmlinkage long sys_fchmodat(int dfd, co
16571 + error = mnt_want_write(path.mnt);
16572 + if (error)
16573 + goto dput_and_out;
16574 ++
16575 ++ if (!gr_acl_handle_chmod(path.dentry, path.mnt, mode)) {
16576 ++ error = -EACCES;
16577 ++ goto out_drop_write;
16578 ++ }
16579 ++
16580 + mutex_lock(&inode->i_mutex);
16581 + if (mode == (mode_t) -1)
16582 + mode = inode->i_mode;
16583 ++
16584 ++ if (gr_handle_chroot_chmod(path.dentry, path.mnt, mode)) {
16585 ++ error = -EACCES;
16586 ++ mutex_unlock(&inode->i_mutex);
16587 ++ goto out_drop_write;
16588 ++ }
16589 ++
16590 + newattrs.ia_mode = (mode & S_IALLUGO) | (inode->i_mode & ~S_IALLUGO);
16591 + newattrs.ia_valid = ATTR_MODE | ATTR_CTIME;
16592 + error = notify_change(path.dentry, &newattrs);
16593 + mutex_unlock(&inode->i_mutex);
16594 ++
16595 ++out_drop_write:
16596 + mnt_drop_write(path.mnt);
16597 + dput_and_out:
16598 + path_put(&path);
16599 +@@ -649,12 +702,15 @@ asmlinkage long sys_chmod(const char __u
16600 + return sys_fchmodat(AT_FDCWD, filename, mode);
16601 + }
16602 +
16603 +-static int chown_common(struct dentry * dentry, uid_t user, gid_t group)
16604 ++static int chown_common(struct dentry * dentry, uid_t user, gid_t group, struct vfsmount *mnt)
16605 + {
16606 + struct inode *inode = dentry->d_inode;
16607 + int error;
16608 + struct iattr newattrs;
16609 +
16610 ++ if (!gr_acl_handle_chown(dentry, mnt))
16611 ++ return -EACCES;
16612 ++
16613 + newattrs.ia_valid = ATTR_CTIME;
16614 + if (user != (uid_t) -1) {
16615 + newattrs.ia_valid |= ATTR_UID;
16616 +@@ -685,7 +741,7 @@ asmlinkage long sys_chown(const char __u
16617 + error = mnt_want_write(path.mnt);
16618 + if (error)
16619 + goto out_release;
16620 +- error = chown_common(path.dentry, user, group);
16621 ++ error = chown_common(path.dentry, user, group, path.mnt);
16622 + mnt_drop_write(path.mnt);
16623 + out_release:
16624 + path_put(&path);
16625 +@@ -710,7 +766,7 @@ asmlinkage long sys_fchownat(int dfd, co
16626 + error = mnt_want_write(path.mnt);
16627 + if (error)
16628 + goto out_release;
16629 +- error = chown_common(path.dentry, user, group);
16630 ++ error = chown_common(path.dentry, user, group, path.mnt);
16631 + mnt_drop_write(path.mnt);
16632 + out_release:
16633 + path_put(&path);
16634 +@@ -729,7 +785,7 @@ asmlinkage long sys_lchown(const char __
16635 + error = mnt_want_write(path.mnt);
16636 + if (error)
16637 + goto out_release;
16638 +- error = chown_common(path.dentry, user, group);
16639 ++ error = chown_common(path.dentry, user, group, path.mnt);
16640 + mnt_drop_write(path.mnt);
16641 + out_release:
16642 + path_put(&path);
16643 +@@ -753,7 +809,7 @@ asmlinkage long sys_fchown(unsigned int
16644 + goto out_fput;
16645 + dentry = file->f_path.dentry;
16646 + audit_inode(NULL, dentry);
16647 +- error = chown_common(dentry, user, group);
16648 ++ error = chown_common(dentry, user, group, file->f_path.mnt);
16649 + mnt_drop_write(file->f_path.mnt);
16650 + out_fput:
16651 + fput(file);
16652 +diff -urNp linux-2.6.27.10/fs/pipe.c linux-2.6.27.10/fs/pipe.c
16653 +--- linux-2.6.27.10/fs/pipe.c 2008-11-07 12:55:34.000000000 -0500
16654 ++++ linux-2.6.27.10/fs/pipe.c 2008-11-18 03:38:45.000000000 -0500
16655 +@@ -851,7 +851,7 @@ void free_pipe_info(struct inode *inode)
16656 + inode->i_pipe = NULL;
16657 + }
16658 +
16659 +-static struct vfsmount *pipe_mnt __read_mostly;
16660 ++struct vfsmount *pipe_mnt __read_mostly;
16661 + static int pipefs_delete_dentry(struct dentry *dentry)
16662 + {
16663 + /*
16664 +diff -urNp linux-2.6.27.10/fs/proc/array.c linux-2.6.27.10/fs/proc/array.c
16665 +--- linux-2.6.27.10/fs/proc/array.c 2008-11-07 12:55:34.000000000 -0500
16666 ++++ linux-2.6.27.10/fs/proc/array.c 2008-11-18 03:38:45.000000000 -0500
16667 +@@ -315,6 +315,21 @@ static inline void task_context_switch_c
16668 + p->nivcsw);
16669 + }
16670 +
16671 ++#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
16672 ++static inline void task_pax(struct seq_file *m, struct task_struct *p)
16673 ++{
16674 ++ if (p->mm)
16675 ++ seq_printf(m, "PaX:\t%c%c%c%c%c\n",
16676 ++ p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
16677 ++ p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
16678 ++ p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
16679 ++ p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
16680 ++ p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
16681 ++ else
16682 ++ seq_printf(m, "PaX:\t-----\n");
16683 ++}
16684 ++#endif
16685 ++
16686 + int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
16687 + struct pid *pid, struct task_struct *task)
16688 + {
16689 +@@ -334,9 +349,20 @@ int proc_pid_status(struct seq_file *m,
16690 + task_show_regs(m, task);
16691 + #endif
16692 + task_context_switch_counts(m, task);
16693 ++
16694 ++#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
16695 ++ task_pax(m, task);
16696 ++#endif
16697 ++
16698 + return 0;
16699 + }
16700 +
16701 ++#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
16702 ++#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
16703 ++ (_mm->pax_flags & MF_PAX_RANDMMAP || \
16704 ++ _mm->pax_flags & MF_PAX_SEGMEXEC))
16705 ++#endif
16706 ++
16707 + static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
16708 + struct pid *pid, struct task_struct *task, int whole)
16709 + {
16710 +@@ -429,6 +455,19 @@ static int do_task_stat(struct seq_file
16711 + gtime = task_gtime(task);
16712 + }
16713 +
16714 ++#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
16715 ++ if (PAX_RAND_FLAGS(mm)) {
16716 ++ eip = 0;
16717 ++ esp = 0;
16718 ++ wchan = 0;
16719 ++ }
16720 ++#endif
16721 ++#ifdef CONFIG_GRKERNSEC_HIDESYM
16722 ++ wchan = 0;
16723 ++ eip =0;
16724 ++ esp =0;
16725 ++#endif
16726 ++
16727 + /* scale priority and nice values from timeslices to -20..20 */
16728 + /* to make it look like a "normal" Unix priority/nice value */
16729 + priority = task_prio(task);
16730 +@@ -469,9 +508,15 @@ static int do_task_stat(struct seq_file
16731 + vsize,
16732 + mm ? get_mm_rss(mm) : 0,
16733 + rsslim,
16734 ++#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
16735 ++ PAX_RAND_FLAGS(mm) ? 1 : (mm ? mm->start_code : 0),
16736 ++ PAX_RAND_FLAGS(mm) ? 1 : (mm ? mm->end_code : 0),
16737 ++ PAX_RAND_FLAGS(mm) ? 0 : (mm ? mm->start_stack : 0),
16738 ++#else
16739 + mm ? mm->start_code : 0,
16740 + mm ? mm->end_code : 0,
16741 + mm ? mm->start_stack : 0,
16742 ++#endif
16743 + esp,
16744 + eip,
16745 + /* The signal information here is obsolete.
16746 +@@ -524,3 +569,10 @@ int proc_pid_statm(struct seq_file *m, s
16747 +
16748 + return 0;
16749 + }
16750 ++
16751 ++#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
16752 ++int proc_pid_ipaddr(struct task_struct *task, char *buffer)
16753 ++{
16754 ++ return sprintf(buffer, "%u.%u.%u.%u\n", NIPQUAD(task->signal->curr_ip));
16755 ++}
16756 ++#endif
16757 +diff -urNp linux-2.6.27.10/fs/proc/base.c linux-2.6.27.10/fs/proc/base.c
16758 +--- linux-2.6.27.10/fs/proc/base.c 2008-11-07 12:55:34.000000000 -0500
16759 ++++ linux-2.6.27.10/fs/proc/base.c 2008-11-18 03:38:45.000000000 -0500
16760 +@@ -79,6 +79,8 @@
16761 + #include <linux/oom.h>
16762 + #include <linux/elf.h>
16763 + #include <linux/pid_namespace.h>
16764 ++#include <linux/grsecurity.h>
16765 ++
16766 + #include "internal.h"
16767 +
16768 + /* NOTE:
16769 +@@ -148,7 +150,7 @@ static unsigned int pid_entry_count_dirs
16770 + return count;
16771 + }
16772 +
16773 +-int maps_protect;
16774 ++int maps_protect = 1;
16775 + EXPORT_SYMBOL(maps_protect);
16776 +
16777 + static struct fs_struct *get_fs_struct(struct task_struct *task)
16778 +@@ -229,6 +231,9 @@ static int check_mem_permission(struct t
16779 + if (task == current)
16780 + return 0;
16781 +
16782 ++ if (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))
16783 ++ return -EPERM;
16784 ++
16785 + /*
16786 + * If current is actively ptrace'ing, and would also be
16787 + * permitted to freshly attach with ptrace now, permit it.
16788 +@@ -312,9 +317,9 @@ static int proc_pid_auxv(struct task_str
16789 + struct mm_struct *mm = get_task_mm(task);
16790 + if (mm) {
16791 + unsigned int nwords = 0;
16792 +- do
16793 ++ do {
16794 + nwords += 2;
16795 +- while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
16796 ++ } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
16797 + res = nwords * sizeof(mm->saved_auxv[0]);
16798 + if (res > PAGE_SIZE)
16799 + res = PAGE_SIZE;
16800 +@@ -1437,7 +1442,11 @@ static struct inode *proc_pid_make_inode
16801 + inode->i_gid = 0;
16802 + if (task_dumpable(task)) {
16803 + inode->i_uid = task->euid;
16804 ++#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
16805 ++ inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
16806 ++#else
16807 + inode->i_gid = task->egid;
16808 ++#endif
16809 + }
16810 + security_task_to_inode(task, inode);
16811 +
16812 +@@ -1453,17 +1462,45 @@ static int pid_getattr(struct vfsmount *
16813 + {
16814 + struct inode *inode = dentry->d_inode;
16815 + struct task_struct *task;
16816 ++#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
16817 ++ struct task_struct *tmp = current;
16818 ++#endif
16819 ++
16820 + generic_fillattr(inode, stat);
16821 +
16822 + rcu_read_lock();
16823 + stat->uid = 0;
16824 + stat->gid = 0;
16825 + task = pid_task(proc_pid(inode), PIDTYPE_PID);
16826 +- if (task) {
16827 ++
16828 ++ if (task && (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))) {
16829 ++ rcu_read_unlock();
16830 ++ return -ENOENT;
16831 ++ }
16832 ++
16833 ++
16834 ++ if (task
16835 ++#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
16836 ++ && (!tmp->uid || (tmp->uid == task->uid)
16837 ++#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
16838 ++ || in_group_p(CONFIG_GRKERNSEC_PROC_GID)
16839 ++#endif
16840 ++ )
16841 ++#endif
16842 ++ ) {
16843 + if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
16844 ++#ifdef CONFIG_GRKERNSEC_PROC_USER
16845 ++ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
16846 ++#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
16847 ++ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
16848 ++#endif
16849 + task_dumpable(task)) {
16850 + stat->uid = task->euid;
16851 ++#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
16852 ++ stat->gid = CONFIG_GRKERNSEC_PROC_GID;
16853 ++#else
16854 + stat->gid = task->egid;
16855 ++#endif
16856 + }
16857 + }
16858 + rcu_read_unlock();
16859 +@@ -1491,11 +1528,21 @@ static int pid_revalidate(struct dentry
16860 + {
16861 + struct inode *inode = dentry->d_inode;
16862 + struct task_struct *task = get_proc_task(inode);
16863 ++
16864 + if (task) {
16865 + if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
16866 ++#ifdef CONFIG_GRKERNSEC_PROC_USER
16867 ++ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
16868 ++#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
16869 ++ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
16870 ++#endif
16871 + task_dumpable(task)) {
16872 + inode->i_uid = task->euid;
16873 ++#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
16874 ++ inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
16875 ++#else
16876 + inode->i_gid = task->egid;
16877 ++#endif
16878 + } else {
16879 + inode->i_uid = 0;
16880 + inode->i_gid = 0;
16881 +@@ -1863,12 +1910,22 @@ static const struct file_operations proc
16882 + static int proc_fd_permission(struct inode *inode, int mask)
16883 + {
16884 + int rv;
16885 ++ struct task_struct *task;
16886 +
16887 + rv = generic_permission(inode, mask, NULL);
16888 +- if (rv == 0)
16889 +- return 0;
16890 ++
16891 + if (task_pid(current) == proc_pid(inode))
16892 + rv = 0;
16893 ++
16894 ++ task = get_proc_task(inode);
16895 ++ if (task == NULL)
16896 ++ return rv;
16897 ++
16898 ++ if (gr_acl_handle_procpidmem(task))
16899 ++ rv = -EACCES;
16900 ++
16901 ++ put_task_struct(task);
16902 ++
16903 + return rv;
16904 + }
16905 +
16906 +@@ -1979,6 +2036,9 @@ static struct dentry *proc_pident_lookup
16907 + if (!task)
16908 + goto out_no_task;
16909 +
16910 ++ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
16911 ++ goto out;
16912 ++
16913 + /*
16914 + * Yes, it does not scale. And it should not. Don't add
16915 + * new entries into /proc/<tgid>/ without very good reasons.
16916 +@@ -2023,6 +2083,9 @@ static int proc_pident_readdir(struct fi
16917 + if (!task)
16918 + goto out_no_task;
16919 +
16920 ++ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
16921 ++ goto out;
16922 ++
16923 + ret = 0;
16924 + i = filp->f_pos;
16925 + switch (i) {
16926 +@@ -2385,6 +2448,9 @@ static struct dentry *proc_base_lookup(s
16927 + if (p > last)
16928 + goto out;
16929 +
16930 ++ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
16931 ++ goto out;
16932 ++
16933 + error = proc_base_instantiate(dir, dentry, task, p);
16934 +
16935 + out:
16936 +@@ -2518,6 +2584,9 @@ static const struct pid_entry tgid_base_
16937 + #ifdef CONFIG_TASK_IO_ACCOUNTING
16938 + INF("io", S_IRUGO, tgid_io_accounting),
16939 + #endif
16940 ++#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
16941 ++ INF("ipaddr", S_IRUSR, pid_ipaddr),
16942 ++#endif
16943 + };
16944 +
16945 + static int proc_tgid_base_readdir(struct file * filp,
16946 +@@ -2647,7 +2716,14 @@ static struct dentry *proc_pid_instantia
16947 + if (!inode)
16948 + goto out;
16949 +
16950 ++#ifdef CONFIG_GRKERNSEC_PROC_USER
16951 ++ inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
16952 ++#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
16953 ++ inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
16954 ++ inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
16955 ++#else
16956 + inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
16957 ++#endif
16958 + inode->i_op = &proc_tgid_base_inode_operations;
16959 + inode->i_fop = &proc_tgid_base_operations;
16960 + inode->i_flags|=S_IMMUTABLE;
16961 +@@ -2689,7 +2765,11 @@ struct dentry *proc_pid_lookup(struct in
16962 + if (!task)
16963 + goto out;
16964 +
16965 ++ if (gr_check_hidden_task(task))
16966 ++ goto out_put_task;
16967 ++
16968 + result = proc_pid_instantiate(dir, dentry, task, NULL);
16969 ++out_put_task:
16970 + put_task_struct(task);
16971 + out:
16972 + return result;
16973 +@@ -2754,6 +2834,9 @@ int proc_pid_readdir(struct file * filp,
16974 + {
16975 + unsigned int nr = filp->f_pos - FIRST_PROCESS_ENTRY;
16976 + struct task_struct *reaper = get_proc_task(filp->f_path.dentry->d_inode);
16977 ++#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
16978 ++ struct task_struct *tmp = current;
16979 ++#endif
16980 + struct tgid_iter iter;
16981 + struct pid_namespace *ns;
16982 +
16983 +@@ -2772,6 +2855,17 @@ int proc_pid_readdir(struct file * filp,
16984 + for (iter = next_tgid(ns, iter);
16985 + iter.task;
16986 + iter.tgid += 1, iter = next_tgid(ns, iter)) {
16987 ++ if (gr_pid_is_chrooted(iter.task) || gr_check_hidden_task(iter.task)
16988 ++#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
16989 ++ || (tmp->uid && (iter.task->uid != tmp->uid)
16990 ++#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
16991 ++ && !in_group_p(CONFIG_GRKERNSEC_PROC_GID)
16992 ++#endif
16993 ++ )
16994 ++#endif
16995 ++ )
16996 ++ continue;
16997 ++
16998 + filp->f_pos = iter.tgid + TGID_OFFSET;
16999 + if (proc_pid_fill_cache(filp, dirent, filldir, iter) < 0) {
17000 + put_task_struct(iter.task);
17001 +diff -urNp linux-2.6.27.10/fs/proc/inode.c linux-2.6.27.10/fs/proc/inode.c
17002 +--- linux-2.6.27.10/fs/proc/inode.c 2008-11-07 12:55:34.000000000 -0500
17003 ++++ linux-2.6.27.10/fs/proc/inode.c 2008-11-18 03:38:45.000000000 -0500
17004 +@@ -467,7 +467,11 @@ struct inode *proc_get_inode(struct supe
17005 + if (de->mode) {
17006 + inode->i_mode = de->mode;
17007 + inode->i_uid = de->uid;
17008 ++#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
17009 ++ inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
17010 ++#else
17011 + inode->i_gid = de->gid;
17012 ++#endif
17013 + }
17014 + if (de->size)
17015 + inode->i_size = de->size;
17016 +diff -urNp linux-2.6.27.10/fs/proc/internal.h linux-2.6.27.10/fs/proc/internal.h
17017 +--- linux-2.6.27.10/fs/proc/internal.h 2008-11-07 12:55:34.000000000 -0500
17018 ++++ linux-2.6.27.10/fs/proc/internal.h 2008-11-18 03:38:45.000000000 -0500
17019 +@@ -55,6 +55,9 @@ extern int proc_pid_status(struct seq_fi
17020 + struct pid *pid, struct task_struct *task);
17021 + extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
17022 + struct pid *pid, struct task_struct *task);
17023 ++#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
17024 ++extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
17025 ++#endif
17026 + extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
17027 +
17028 + extern const struct file_operations proc_maps_operations;
17029 +diff -urNp linux-2.6.27.10/fs/proc/Kconfig linux-2.6.27.10/fs/proc/Kconfig
17030 +--- linux-2.6.27.10/fs/proc/Kconfig 2008-11-07 12:55:34.000000000 -0500
17031 ++++ linux-2.6.27.10/fs/proc/Kconfig 2008-11-18 03:38:45.000000000 -0500
17032 +@@ -30,12 +30,12 @@ config PROC_FS
17033 +
17034 + config PROC_KCORE
17035 + bool "/proc/kcore support" if !ARM
17036 +- depends on PROC_FS && MMU
17037 ++ depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
17038 +
17039 + config PROC_VMCORE
17040 + bool "/proc/vmcore support (EXPERIMENTAL)"
17041 +- depends on PROC_FS && CRASH_DUMP
17042 +- default y
17043 ++ depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
17044 ++ default n
17045 + help
17046 + Exports the dump image of crashed kernel in ELF format.
17047 +
17048 +diff -urNp linux-2.6.27.10/fs/proc/proc_misc.c linux-2.6.27.10/fs/proc/proc_misc.c
17049 +--- linux-2.6.27.10/fs/proc/proc_misc.c 2008-11-07 12:55:34.000000000 -0500
17050 ++++ linux-2.6.27.10/fs/proc/proc_misc.c 2008-11-18 03:38:45.000000000 -0500
17051 +@@ -860,6 +860,8 @@ struct proc_dir_entry *proc_root_kcore;
17052 +
17053 + void __init proc_misc_init(void)
17054 + {
17055 ++ int gr_mode = 0;
17056 ++
17057 + static struct {
17058 + char *name;
17059 + int (*read_proc)(char*,char**,off_t,int,int*,void*);
17060 +@@ -875,13 +877,24 @@ void __init proc_misc_init(void)
17061 + {"stram", stram_read_proc},
17062 + #endif
17063 + {"filesystems", filesystems_read_proc},
17064 ++#ifndef CONFIG_GRKERNSEC_PROC_ADD
17065 + {"cmdline", cmdline_read_proc},
17066 ++#endif
17067 + {"execdomains", execdomains_read_proc},
17068 + {NULL,}
17069 + };
17070 + for (p = simple_ones; p->name; p++)
17071 + create_proc_read_entry(p->name, 0, NULL, p->read_proc, NULL);
17072 +
17073 ++#ifdef CONFIG_GRKERNSEC_PROC_USER
17074 ++ gr_mode = S_IRUSR;
17075 ++#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
17076 ++ gr_mode = S_IRUSR | S_IRGRP;
17077 ++#endif
17078 ++#ifdef CONFIG_GRKERNSEC_PROC_ADD
17079 ++ create_proc_read_entry("cmdline", gr_mode, NULL, &cmdline_read_proc, NULL);
17080 ++#endif
17081 ++
17082 + proc_symlink("mounts", NULL, "self/mounts");
17083 +
17084 + /* And now for trickier ones */
17085 +@@ -889,14 +902,18 @@ void __init proc_misc_init(void)
17086 + proc_create("kmsg", S_IRUSR, NULL, &proc_kmsg_operations);
17087 + #endif
17088 + proc_create("locks", 0, NULL, &proc_locks_operations);
17089 ++#ifdef CONFIG_GRKERNSEC_PROC_ADD
17090 ++ proc_create("devices", gr_mode, NULL, &proc_devinfo_operations);
17091 ++#else
17092 + proc_create("devices", 0, NULL, &proc_devinfo_operations);
17093 ++#endif
17094 + proc_create("cpuinfo", 0, NULL, &proc_cpuinfo_operations);
17095 + #ifdef CONFIG_BLOCK
17096 + proc_create("partitions", 0, NULL, &proc_partitions_operations);
17097 + #endif
17098 + proc_create("stat", 0, NULL, &proc_stat_operations);
17099 + proc_create("interrupts", 0, NULL, &proc_interrupts_operations);
17100 +-#ifdef CONFIG_SLABINFO
17101 ++#if defined(CONFIG_SLABINFO) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
17102 + proc_create("slabinfo",S_IWUSR|S_IRUGO,NULL,&proc_slabinfo_operations);
17103 + #ifdef CONFIG_DEBUG_SLAB_LEAK
17104 + proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
17105 +@@ -918,7 +935,7 @@ void __init proc_misc_init(void)
17106 + #ifdef CONFIG_SCHEDSTATS
17107 + proc_create("schedstat", 0, NULL, &proc_schedstat_operations);
17108 + #endif
17109 +-#ifdef CONFIG_PROC_KCORE
17110 ++#if defined(CONFIG_PROC_KCORE) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
17111 + proc_root_kcore = proc_create("kcore", S_IRUSR, NULL, &proc_kcore_operations);
17112 + if (proc_root_kcore)
17113 + proc_root_kcore->size =
17114 +diff -urNp linux-2.6.27.10/fs/proc/proc_net.c linux-2.6.27.10/fs/proc/proc_net.c
17115 +--- linux-2.6.27.10/fs/proc/proc_net.c 2008-11-07 12:55:34.000000000 -0500
17116 ++++ linux-2.6.27.10/fs/proc/proc_net.c 2008-11-18 03:38:45.000000000 -0500
17117 +@@ -106,6 +106,14 @@ static struct net *get_proc_task_net(str
17118 + struct nsproxy *ns;
17119 + struct net *net = NULL;
17120 +
17121 ++#ifdef CONFIG_GRKERNSEC_PROC_USER
17122 ++ if (current->fsuid)
17123 ++ return net;
17124 ++#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
17125 ++ if (current->fsuid && !in_group_p(CONFIG_GRKERNSEC_PROC_GID))
17126 ++ return net;
17127 ++#endif
17128 ++
17129 + rcu_read_lock();
17130 + task = pid_task(proc_pid(dir), PIDTYPE_PID);
17131 + if (task != NULL) {
17132 +diff -urNp linux-2.6.27.10/fs/proc/proc_sysctl.c linux-2.6.27.10/fs/proc/proc_sysctl.c
17133 +--- linux-2.6.27.10/fs/proc/proc_sysctl.c 2008-11-18 11:38:40.000000000 -0500
17134 ++++ linux-2.6.27.10/fs/proc/proc_sysctl.c 2008-11-18 11:40:53.000000000 -0500
17135 +@@ -7,6 +7,8 @@
17136 + #include <linux/security.h>
17137 + #include "internal.h"
17138 +
17139 ++extern __u32 gr_handle_sysctl(const struct ctl_table *table, const int op);
17140 ++
17141 + static struct dentry_operations proc_sys_dentry_operations;
17142 + static const struct file_operations proc_sys_file_operations;
17143 + static const struct inode_operations proc_sys_inode_operations;
17144 +@@ -110,6 +112,9 @@ static struct dentry *proc_sys_lookup(st
17145 + if (!p)
17146 + goto out;
17147 +
17148 ++ if (gr_handle_sysctl(p, MAY_EXEC))
17149 ++ goto out;
17150 ++
17151 + err = ERR_PTR(-ENOMEM);
17152 + inode = proc_sys_make_inode(dir->i_sb, h ? h : head, p);
17153 + if (h)
17154 +@@ -229,6 +234,9 @@ static int scan(struct ctl_table_header
17155 + if (*pos < file->f_pos)
17156 + continue;
17157 +
17158 ++ if (gr_handle_sysctl(table, 0))
17159 ++ continue;
17160 ++
17161 + res = proc_sys_fill_cache(file, dirent, filldir, head, table);
17162 + if (res)
17163 + return res;
17164 +@@ -339,6 +347,9 @@ static int proc_sys_getattr(struct vfsmo
17165 + if (IS_ERR(head))
17166 + return PTR_ERR(head);
17167 +
17168 ++ if (table && gr_handle_sysctl(table, MAY_EXEC))
17169 ++ return -ENOENT;
17170 ++
17171 + generic_fillattr(inode, stat);
17172 + if (table)
17173 + stat->mode = (stat->mode & S_IFMT) | table->mode;
17174 +diff -urNp linux-2.6.27.10/fs/proc/root.c linux-2.6.27.10/fs/proc/root.c
17175 +--- linux-2.6.27.10/fs/proc/root.c 2008-11-07 12:55:34.000000000 -0500
17176 ++++ linux-2.6.27.10/fs/proc/root.c 2008-11-18 03:38:45.000000000 -0500
17177 +@@ -135,7 +135,15 @@ void __init proc_root_init(void)
17178 + #ifdef CONFIG_PROC_DEVICETREE
17179 + proc_device_tree_init();
17180 + #endif
17181 ++#ifdef CONFIG_GRKERNSEC_PROC_ADD
17182 ++#ifdef CONFIG_GRKERNSEC_PROC_USER
17183 ++ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
17184 ++#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
17185 ++ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
17186 ++#endif
17187 ++#else
17188 + proc_mkdir("bus", NULL);
17189 ++#endif
17190 + proc_sys_init();
17191 + }
17192 +
17193 +diff -urNp linux-2.6.27.10/fs/proc/task_mmu.c linux-2.6.27.10/fs/proc/task_mmu.c
17194 +--- linux-2.6.27.10/fs/proc/task_mmu.c 2008-12-21 01:16:51.000000000 -0500
17195 ++++ linux-2.6.27.10/fs/proc/task_mmu.c 2008-12-21 01:13:46.000000000 -0500
17196 +@@ -46,15 +46,26 @@ void task_mem(struct seq_file *m, struct
17197 + "VmStk:\t%8lu kB\n"
17198 + "VmExe:\t%8lu kB\n"
17199 + "VmLib:\t%8lu kB\n"
17200 +- "VmPTE:\t%8lu kB\n",
17201 +- hiwater_vm << (PAGE_SHIFT-10),
17202 ++ "VmPTE:\t%8lu kB\n"
17203 ++
17204 ++#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
17205 ++ "CsBase:\t%8lx\nCsLim:\t%8lx\n"
17206 ++#endif
17207 ++
17208 ++ ,hiwater_vm << (PAGE_SHIFT-10),
17209 + (total_vm - mm->reserved_vm) << (PAGE_SHIFT-10),
17210 + mm->locked_vm << (PAGE_SHIFT-10),
17211 + hiwater_rss << (PAGE_SHIFT-10),
17212 + total_rss << (PAGE_SHIFT-10),
17213 + data << (PAGE_SHIFT-10),
17214 + mm->stack_vm << (PAGE_SHIFT-10), text, lib,
17215 +- (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10);
17216 ++ (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10
17217 ++
17218 ++#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
17219 ++ , mm->context.user_cs_base, mm->context.user_cs_limit
17220 ++#endif
17221 ++
17222 ++ );
17223 + }
17224 +
17225 + unsigned long task_vsize(struct mm_struct *mm)
17226 +@@ -198,6 +209,12 @@ static int do_maps_open(struct inode *in
17227 + return ret;
17228 + }
17229 +
17230 ++#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
17231 ++#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
17232 ++ (_mm->pax_flags & MF_PAX_RANDMMAP || \
17233 ++ _mm->pax_flags & MF_PAX_SEGMEXEC))
17234 ++#endif
17235 ++
17236 + static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
17237 + {
17238 + struct mm_struct *mm = vma->vm_mm;
17239 +@@ -214,13 +231,22 @@ static void show_map_vma(struct seq_file
17240 + }
17241 +
17242 + seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
17243 ++#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
17244 ++ PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start,
17245 ++ PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end,
17246 ++#else
17247 + vma->vm_start,
17248 + vma->vm_end,
17249 ++#endif
17250 + flags & VM_READ ? 'r' : '-',
17251 + flags & VM_WRITE ? 'w' : '-',
17252 + flags & VM_EXEC ? 'x' : '-',
17253 + flags & VM_MAYSHARE ? 's' : 'p',
17254 ++#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
17255 ++ PAX_RAND_FLAGS(mm) ? 0UL : ((loff_t)vma->vm_pgoff) << PAGE_SHIFT,
17256 ++#else
17257 + ((loff_t)vma->vm_pgoff) << PAGE_SHIFT,
17258 ++#endif
17259 + MAJOR(dev), MINOR(dev), ino, &len);
17260 +
17261 + /*
17262 +@@ -234,11 +260,11 @@ static void show_map_vma(struct seq_file
17263 + const char *name = arch_vma_name(vma);
17264 + if (!name) {
17265 + if (mm) {
17266 +- if (vma->vm_start <= mm->start_brk &&
17267 +- vma->vm_end >= mm->brk) {
17268 ++ if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
17269 + name = "[heap]";
17270 +- } else if (vma->vm_start <= mm->start_stack &&
17271 +- vma->vm_end >= mm->start_stack) {
17272 ++ } else if ((vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
17273 ++ (vma->vm_start <= mm->start_stack &&
17274 ++ vma->vm_end >= mm->start_stack)) {
17275 + name = "[stack]";
17276 + }
17277 + } else {
17278 +@@ -387,9 +413,16 @@ static int show_smap(struct seq_file *m,
17279 + return -EACCES;
17280 +
17281 + memset(&mss, 0, sizeof mss);
17282 +- mss.vma = vma;
17283 +- if (vma->vm_mm && !is_vm_hugetlb_page(vma))
17284 +- walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
17285 ++
17286 ++#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
17287 ++ if (!PAX_RAND_FLAGS(vma->vm_mm)) {
17288 ++#endif
17289 ++ mss.vma = vma;
17290 ++ if (vma->vm_mm && !is_vm_hugetlb_page(vma))
17291 ++ walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
17292 ++#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
17293 ++ }
17294 ++#endif
17295 +
17296 + show_map_vma(m, vma);
17297 +
17298 +@@ -403,7 +436,11 @@ static int show_smap(struct seq_file *m,
17299 + "Private_Dirty: %8lu kB\n"
17300 + "Referenced: %8lu kB\n"
17301 + "Swap: %8lu kB\n",
17302 ++#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
17303 ++ PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
17304 ++#else
17305 + (vma->vm_end - vma->vm_start) >> 10,
17306 ++#endif
17307 + mss.resident >> 10,
17308 + (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
17309 + mss.shared_clean >> 10,
17310 +@@ -757,6 +794,11 @@ static int show_numa_map_checked(struct
17311 + struct proc_maps_private *priv = m->private;
17312 + struct task_struct *task = priv->task;
17313 +
17314 ++#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
17315 ++ if (!ptrace_may_access(task, PTRACE_MODE_READ))
17316 ++ return -EACCES;
17317 ++#endif
17318 ++
17319 + if (maps_protect && !ptrace_may_access(task, PTRACE_MODE_READ))
17320 + return -EACCES;
17321 +
17322 +diff -urNp linux-2.6.27.10/fs/readdir.c linux-2.6.27.10/fs/readdir.c
17323 +--- linux-2.6.27.10/fs/readdir.c 2008-11-07 12:55:34.000000000 -0500
17324 ++++ linux-2.6.27.10/fs/readdir.c 2008-11-18 03:38:45.000000000 -0500
17325 +@@ -16,6 +16,8 @@
17326 + #include <linux/security.h>
17327 + #include <linux/syscalls.h>
17328 + #include <linux/unistd.h>
17329 ++#include <linux/namei.h>
17330 ++#include <linux/grsecurity.h>
17331 +
17332 + #include <asm/uaccess.h>
17333 +
17334 +@@ -67,6 +69,7 @@ struct old_linux_dirent {
17335 +
17336 + struct readdir_callback {
17337 + struct old_linux_dirent __user * dirent;
17338 ++ struct file * file;
17339 + int result;
17340 + };
17341 +
17342 +@@ -84,6 +87,10 @@ static int fillonedir(void * __buf, cons
17343 + buf->result = -EOVERFLOW;
17344 + return -EOVERFLOW;
17345 + }
17346 ++
17347 ++ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
17348 ++ return 0;
17349 ++
17350 + buf->result++;
17351 + dirent = buf->dirent;
17352 + if (!access_ok(VERIFY_WRITE, dirent,
17353 +@@ -115,6 +122,7 @@ asmlinkage long old_readdir(unsigned int
17354 +
17355 + buf.result = 0;
17356 + buf.dirent = dirent;
17357 ++ buf.file = file;
17358 +
17359 + error = vfs_readdir(file, fillonedir, &buf);
17360 + if (error >= 0)
17361 +@@ -141,6 +149,7 @@ struct linux_dirent {
17362 + struct getdents_callback {
17363 + struct linux_dirent __user * current_dir;
17364 + struct linux_dirent __user * previous;
17365 ++ struct file * file;
17366 + int count;
17367 + int error;
17368 + };
17369 +@@ -161,6 +170,10 @@ static int filldir(void * __buf, const c
17370 + buf->error = -EOVERFLOW;
17371 + return -EOVERFLOW;
17372 + }
17373 ++
17374 ++ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
17375 ++ return 0;
17376 ++
17377 + dirent = buf->previous;
17378 + if (dirent) {
17379 + if (__put_user(offset, &dirent->d_off))
17380 +@@ -207,6 +220,7 @@ asmlinkage long sys_getdents(unsigned in
17381 + buf.previous = NULL;
17382 + buf.count = count;
17383 + buf.error = 0;
17384 ++ buf.file = file;
17385 +
17386 + error = vfs_readdir(file, filldir, &buf);
17387 + if (error < 0)
17388 +@@ -229,6 +243,7 @@ out:
17389 + struct getdents_callback64 {
17390 + struct linux_dirent64 __user * current_dir;
17391 + struct linux_dirent64 __user * previous;
17392 ++ struct file *file;
17393 + int count;
17394 + int error;
17395 + };
17396 +@@ -243,6 +258,10 @@ static int filldir64(void * __buf, const
17397 + buf->error = -EINVAL; /* only used if we fail.. */
17398 + if (reclen > buf->count)
17399 + return -EINVAL;
17400 ++
17401 ++ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
17402 ++ return 0;
17403 ++
17404 + dirent = buf->previous;
17405 + if (dirent) {
17406 + if (__put_user(offset, &dirent->d_off))
17407 +@@ -289,6 +308,7 @@ asmlinkage long sys_getdents64(unsigned
17408 +
17409 + buf.current_dir = dirent;
17410 + buf.previous = NULL;
17411 ++ buf.file = file;
17412 + buf.count = count;
17413 + buf.error = 0;
17414 +
17415 +diff -urNp linux-2.6.27.10/fs/select.c linux-2.6.27.10/fs/select.c
17416 +--- linux-2.6.27.10/fs/select.c 2008-11-07 12:55:34.000000000 -0500
17417 ++++ linux-2.6.27.10/fs/select.c 2008-11-18 03:38:45.000000000 -0500
17418 +@@ -24,6 +24,7 @@
17419 + #include <linux/fdtable.h>
17420 + #include <linux/fs.h>
17421 + #include <linux/rcupdate.h>
17422 ++#include <linux/grsecurity.h>
17423 +
17424 + #include <asm/uaccess.h>
17425 +
17426 +@@ -658,6 +659,7 @@ int do_sys_poll(struct pollfd __user *uf
17427 + struct poll_list *walk = head;
17428 + unsigned long todo = nfds;
17429 +
17430 ++ gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
17431 + if (nfds > current->signal->rlim[RLIMIT_NOFILE].rlim_cur)
17432 + return -EINVAL;
17433 +
17434 +diff -urNp linux-2.6.27.10/fs/smbfs/symlink.c linux-2.6.27.10/fs/smbfs/symlink.c
17435 +--- linux-2.6.27.10/fs/smbfs/symlink.c 2008-11-07 12:55:34.000000000 -0500
17436 ++++ linux-2.6.27.10/fs/smbfs/symlink.c 2008-11-18 03:38:45.000000000 -0500
17437 +@@ -55,7 +55,7 @@ static void *smb_follow_link(struct dent
17438 +
17439 + static void smb_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
17440 + {
17441 +- char *s = nd_get_link(nd);
17442 ++ const char *s = nd_get_link(nd);
17443 + if (!IS_ERR(s))
17444 + __putname(s);
17445 + }
17446 +diff -urNp linux-2.6.27.10/fs/sysfs/symlink.c linux-2.6.27.10/fs/sysfs/symlink.c
17447 +--- linux-2.6.27.10/fs/sysfs/symlink.c 2008-11-07 12:55:34.000000000 -0500
17448 ++++ linux-2.6.27.10/fs/sysfs/symlink.c 2008-11-18 03:38:45.000000000 -0500
17449 +@@ -200,7 +200,7 @@ static void *sysfs_follow_link(struct de
17450 +
17451 + static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
17452 + {
17453 +- char *page = nd_get_link(nd);
17454 ++ const char *page = nd_get_link(nd);
17455 + if (!IS_ERR(page))
17456 + free_page((unsigned long)page);
17457 + }
17458 +diff -urNp linux-2.6.27.10/fs/udf/balloc.c linux-2.6.27.10/fs/udf/balloc.c
17459 +--- linux-2.6.27.10/fs/udf/balloc.c 2008-11-07 12:55:34.000000000 -0500
17460 ++++ linux-2.6.27.10/fs/udf/balloc.c 2008-11-18 03:38:45.000000000 -0500
17461 +@@ -169,9 +169,7 @@ static void udf_bitmap_free_blocks(struc
17462 + unsigned long overflow;
17463 +
17464 + mutex_lock(&sbi->s_alloc_mutex);
17465 +- if (bloc.logicalBlockNum < 0 ||
17466 +- (bloc.logicalBlockNum + count) >
17467 +- sbi->s_partmaps[bloc.partitionReferenceNum].s_partition_len) {
17468 ++ if (bloc.logicalBlockNum + count > sbi->s_partmaps[bloc.partitionReferenceNum].s_partition_len) {
17469 + udf_debug("%d < %d || %d + %d > %d\n",
17470 + bloc.logicalBlockNum, 0, bloc.logicalBlockNum, count,
17471 + sbi->s_partmaps[bloc.partitionReferenceNum].
17472 +@@ -239,7 +237,7 @@ static int udf_bitmap_prealloc_blocks(st
17473 +
17474 + mutex_lock(&sbi->s_alloc_mutex);
17475 + part_len = sbi->s_partmaps[partition].s_partition_len;
17476 +- if (first_block < 0 || first_block >= part_len)
17477 ++ if (first_block >= part_len)
17478 + goto out;
17479 +
17480 + if (first_block + block_count > part_len)
17481 +@@ -300,7 +298,7 @@ static int udf_bitmap_new_block(struct s
17482 + mutex_lock(&sbi->s_alloc_mutex);
17483 +
17484 + repeat:
17485 +- if (goal < 0 || goal >= sbi->s_partmaps[partition].s_partition_len)
17486 ++ if (goal >= sbi->s_partmaps[partition].s_partition_len)
17487 + goal = 0;
17488 +
17489 + nr_groups = bitmap->s_nr_groups;
17490 +@@ -438,9 +436,7 @@ static void udf_table_free_blocks(struct
17491 + struct udf_inode_info *iinfo;
17492 +
17493 + mutex_lock(&sbi->s_alloc_mutex);
17494 +- if (bloc.logicalBlockNum < 0 ||
17495 +- (bloc.logicalBlockNum + count) >
17496 +- sbi->s_partmaps[bloc.partitionReferenceNum].s_partition_len) {
17497 ++ if (bloc.logicalBlockNum + count > sbi->s_partmaps[bloc.partitionReferenceNum].s_partition_len) {
17498 + udf_debug("%d < %d || %d + %d > %d\n",
17499 + bloc.logicalBlockNum, 0, bloc.logicalBlockNum, count,
17500 + sbi->s_partmaps[bloc.partitionReferenceNum].
17501 +@@ -671,8 +667,7 @@ static int udf_table_prealloc_blocks(str
17502 + int8_t etype = -1;
17503 + struct udf_inode_info *iinfo;
17504 +
17505 +- if (first_block < 0 ||
17506 +- first_block >= sbi->s_partmaps[partition].s_partition_len)
17507 ++ if (first_block >= sbi->s_partmaps[partition].s_partition_len)
17508 + return 0;
17509 +
17510 + iinfo = UDF_I(table);
17511 +@@ -750,7 +745,7 @@ static int udf_table_new_block(struct su
17512 + return newblock;
17513 +
17514 + mutex_lock(&sbi->s_alloc_mutex);
17515 +- if (goal < 0 || goal >= sbi->s_partmaps[partition].s_partition_len)
17516 ++ if (goal >= sbi->s_partmaps[partition].s_partition_len)
17517 + goal = 0;
17518 +
17519 + /* We search for the closest matching block to goal. If we find
17520 +diff -urNp linux-2.6.27.10/fs/ufs/inode.c linux-2.6.27.10/fs/ufs/inode.c
17521 +--- linux-2.6.27.10/fs/ufs/inode.c 2008-11-07 12:55:34.000000000 -0500
17522 ++++ linux-2.6.27.10/fs/ufs/inode.c 2008-11-18 03:38:45.000000000 -0500
17523 +@@ -56,9 +56,7 @@ static int ufs_block_to_path(struct inod
17524 +
17525 +
17526 + UFSD("ptrs=uspi->s_apb = %d,double_blocks=%ld \n",ptrs,double_blocks);
17527 +- if (i_block < 0) {
17528 +- ufs_warning(inode->i_sb, "ufs_block_to_path", "block < 0");
17529 +- } else if (i_block < direct_blocks) {
17530 ++ if (i_block < direct_blocks) {
17531 + offsets[n++] = i_block;
17532 + } else if ((i_block -= direct_blocks) < indirect_blocks) {
17533 + offsets[n++] = UFS_IND_BLOCK;
17534 +@@ -440,8 +438,6 @@ int ufs_getfrag_block(struct inode *inod
17535 + lock_kernel();
17536 +
17537 + UFSD("ENTER, ino %lu, fragment %llu\n", inode->i_ino, (unsigned long long)fragment);
17538 +- if (fragment < 0)
17539 +- goto abort_negative;
17540 + if (fragment >
17541 + ((UFS_NDADDR + uspi->s_apb + uspi->s_2apb + uspi->s_3apb)
17542 + << uspi->s_fpbshift))
17543 +@@ -504,10 +500,6 @@ abort:
17544 + unlock_kernel();
17545 + return err;
17546 +
17547 +-abort_negative:
17548 +- ufs_warning(sb, "ufs_get_block", "block < 0");
17549 +- goto abort;
17550 +-
17551 + abort_too_big:
17552 + ufs_warning(sb, "ufs_get_block", "block > big");
17553 + goto abort;
17554 +diff -urNp linux-2.6.27.10/fs/utimes.c linux-2.6.27.10/fs/utimes.c
17555 +--- linux-2.6.27.10/fs/utimes.c 2008-11-07 12:55:34.000000000 -0500
17556 ++++ linux-2.6.27.10/fs/utimes.c 2008-11-18 03:38:45.000000000 -0500
17557 +@@ -8,6 +8,7 @@
17558 + #include <linux/stat.h>
17559 + #include <linux/utime.h>
17560 + #include <linux/syscalls.h>
17561 ++#include <linux/grsecurity.h>
17562 + #include <asm/uaccess.h>
17563 + #include <asm/unistd.h>
17564 +
17565 +@@ -101,6 +102,12 @@ static int utimes_common(struct path *pa
17566 + goto mnt_drop_write_and_out;
17567 + }
17568 + }
17569 ++
17570 ++ if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
17571 ++ error = -EACCES;
17572 ++ goto mnt_drop_write_and_out;
17573 ++ }
17574 ++
17575 + mutex_lock(&inode->i_mutex);
17576 + error = notify_change(path->dentry, &newattrs);
17577 + mutex_unlock(&inode->i_mutex);
17578 +diff -urNp linux-2.6.27.10/fs/xfs/linux-2.6/xfs_iops.c linux-2.6.27.10/fs/xfs/linux-2.6/xfs_iops.c
17579 +--- linux-2.6.27.10/fs/xfs/linux-2.6/xfs_iops.c 2008-11-07 12:55:34.000000000 -0500
17580 ++++ linux-2.6.27.10/fs/xfs/linux-2.6/xfs_iops.c 2008-11-18 03:38:45.000000000 -0500
17581 +@@ -500,7 +500,7 @@ xfs_vn_put_link(
17582 + struct nameidata *nd,
17583 + void *p)
17584 + {
17585 +- char *s = nd_get_link(nd);
17586 ++ const char *s = nd_get_link(nd);
17587 +
17588 + if (!IS_ERR(s))
17589 + kfree(s);
17590 +diff -urNp linux-2.6.27.10/fs/xfs/xfs_bmap.c linux-2.6.27.10/fs/xfs/xfs_bmap.c
17591 +--- linux-2.6.27.10/fs/xfs/xfs_bmap.c 2008-11-07 12:55:34.000000000 -0500
17592 ++++ linux-2.6.27.10/fs/xfs/xfs_bmap.c 2008-11-18 03:38:45.000000000 -0500
17593 +@@ -360,7 +360,7 @@ xfs_bmap_validate_ret(
17594 + int nmap,
17595 + int ret_nmap);
17596 + #else
17597 +-#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
17598 ++#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
17599 + #endif /* DEBUG */
17600 +
17601 + #if defined(XFS_RW_TRACE)
17602 +diff -urNp linux-2.6.27.10/grsecurity/gracl_alloc.c linux-2.6.27.10/grsecurity/gracl_alloc.c
17603 +--- linux-2.6.27.10/grsecurity/gracl_alloc.c 1969-12-31 19:00:00.000000000 -0500
17604 ++++ linux-2.6.27.10/grsecurity/gracl_alloc.c 2008-11-18 03:38:45.000000000 -0500
17605 +@@ -0,0 +1,91 @@
17606 ++#include <linux/kernel.h>
17607 ++#include <linux/mm.h>
17608 ++#include <linux/slab.h>
17609 ++#include <linux/vmalloc.h>
17610 ++#include <linux/gracl.h>
17611 ++#include <linux/grsecurity.h>
17612 ++
17613 ++static unsigned long alloc_stack_next = 1;
17614 ++static unsigned long alloc_stack_size = 1;
17615 ++static void **alloc_stack;
17616 ++
17617 ++static __inline__ int
17618 ++alloc_pop(void)
17619 ++{
17620 ++ if (alloc_stack_next == 1)
17621 ++ return 0;
17622 ++
17623 ++ kfree(alloc_stack[alloc_stack_next - 2]);
17624 ++
17625 ++ alloc_stack_next--;
17626 ++
17627 ++ return 1;
17628 ++}
17629 ++
17630 ++static __inline__ void
17631 ++alloc_push(void *buf)
17632 ++{
17633 ++ if (alloc_stack_next >= alloc_stack_size)
17634 ++ BUG();
17635 ++
17636 ++ alloc_stack[alloc_stack_next - 1] = buf;
17637 ++
17638 ++ alloc_stack_next++;
17639 ++
17640 ++ return;
17641 ++}
17642 ++
17643 ++void *
17644 ++acl_alloc(unsigned long len)
17645 ++{
17646 ++ void *ret;
17647 ++
17648 ++ if (len > PAGE_SIZE)
17649 ++ BUG();
17650 ++
17651 ++ ret = kmalloc(len, GFP_KERNEL);
17652 ++
17653 ++ if (ret)
17654 ++ alloc_push(ret);
17655 ++
17656 ++ return ret;
17657 ++}
17658 ++
17659 ++void
17660 ++acl_free_all(void)
17661 ++{
17662 ++ if (gr_acl_is_enabled() || !alloc_stack)
17663 ++ return;
17664 ++
17665 ++ while (alloc_pop()) ;
17666 ++
17667 ++ if (alloc_stack) {
17668 ++ if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
17669 ++ kfree(alloc_stack);
17670 ++ else
17671 ++ vfree(alloc_stack);
17672 ++ }
17673 ++
17674 ++ alloc_stack = NULL;
17675 ++ alloc_stack_size = 1;
17676 ++ alloc_stack_next = 1;
17677 ++
17678 ++ return;
17679 ++}
17680 ++
17681 ++int
17682 ++acl_alloc_stack_init(unsigned long size)
17683 ++{
17684 ++ if ((size * sizeof (void *)) <= PAGE_SIZE)
17685 ++ alloc_stack =
17686 ++ (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
17687 ++ else
17688 ++ alloc_stack = (void **) vmalloc(size * sizeof (void *));
17689 ++
17690 ++ alloc_stack_size = size;
17691 ++
17692 ++ if (!alloc_stack)
17693 ++ return 0;
17694 ++ else
17695 ++ return 1;
17696 ++}
17697 +diff -urNp linux-2.6.27.10/grsecurity/gracl.c linux-2.6.27.10/grsecurity/gracl.c
17698 +--- linux-2.6.27.10/grsecurity/gracl.c 1969-12-31 19:00:00.000000000 -0500
17699 ++++ linux-2.6.27.10/grsecurity/gracl.c 2008-11-18 03:38:45.000000000 -0500
17700 +@@ -0,0 +1,3722 @@
17701 ++#include <linux/kernel.h>
17702 ++#include <linux/module.h>
17703 ++#include <linux/sched.h>
17704 ++#include <linux/mm.h>
17705 ++#include <linux/file.h>
17706 ++#include <linux/fs.h>
17707 ++#include <linux/namei.h>
17708 ++#include <linux/mount.h>
17709 ++#include <linux/tty.h>
17710 ++#include <linux/proc_fs.h>
17711 ++#include <linux/smp_lock.h>
17712 ++#include <linux/slab.h>
17713 ++#include <linux/vmalloc.h>
17714 ++#include <linux/types.h>
17715 ++#include <linux/sysctl.h>
17716 ++#include <linux/netdevice.h>
17717 ++#include <linux/ptrace.h>
17718 ++#include <linux/gracl.h>
17719 ++#include <linux/gralloc.h>
17720 ++#include <linux/grsecurity.h>
17721 ++#include <linux/grinternal.h>
17722 ++#include <linux/pid_namespace.h>
17723 ++#include <linux/fdtable.h>
17724 ++#include <linux/percpu.h>
17725 ++
17726 ++#include <asm/uaccess.h>
17727 ++#include <asm/errno.h>
17728 ++#include <asm/mman.h>
17729 ++
17730 ++static struct acl_role_db acl_role_set;
17731 ++static struct name_db name_set;
17732 ++static struct inodev_db inodev_set;
17733 ++
17734 ++/* for keeping track of userspace pointers used for subjects, so we
17735 ++ can share references in the kernel as well
17736 ++*/
17737 ++
17738 ++static struct dentry *real_root;
17739 ++static struct vfsmount *real_root_mnt;
17740 ++
17741 ++static struct acl_subj_map_db subj_map_set;
17742 ++
17743 ++static struct acl_role_label *default_role;
17744 ++
17745 ++static u16 acl_sp_role_value;
17746 ++
17747 ++extern char *gr_shared_page[4];
17748 ++static DECLARE_MUTEX(gr_dev_sem);
17749 ++DEFINE_RWLOCK(gr_inode_lock);
17750 ++
17751 ++struct gr_arg *gr_usermode;
17752 ++
17753 ++static unsigned int gr_status = GR_STATUS_INIT;
17754 ++
17755 ++extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
17756 ++extern void gr_clear_learn_entries(void);
17757 ++
17758 ++#ifdef CONFIG_GRKERNSEC_RESLOG
17759 ++extern void gr_log_resource(const struct task_struct *task,
17760 ++ const int res, const unsigned long wanted, const int gt);
17761 ++#endif
17762 ++
17763 ++unsigned char *gr_system_salt;
17764 ++unsigned char *gr_system_sum;
17765 ++
17766 ++static struct sprole_pw **acl_special_roles = NULL;
17767 ++static __u16 num_sprole_pws = 0;
17768 ++
17769 ++static struct acl_role_label *kernel_role = NULL;
17770 ++
17771 ++static unsigned int gr_auth_attempts = 0;
17772 ++static unsigned long gr_auth_expires = 0UL;
17773 ++
17774 ++extern struct vfsmount *sock_mnt;
17775 ++extern struct vfsmount *pipe_mnt;
17776 ++extern struct vfsmount *shm_mnt;
17777 ++static struct acl_object_label *fakefs_obj;
17778 ++
17779 ++extern int gr_init_uidset(void);
17780 ++extern void gr_free_uidset(void);
17781 ++extern void gr_remove_uid(uid_t uid);
17782 ++extern int gr_find_uid(uid_t uid);
17783 ++
17784 ++__inline__ int
17785 ++gr_acl_is_enabled(void)
17786 ++{
17787 ++ return (gr_status & GR_READY);
17788 ++}
17789 ++
17790 ++char gr_roletype_to_char(void)
17791 ++{
17792 ++ switch (current->role->roletype &
17793 ++ (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
17794 ++ GR_ROLE_SPECIAL)) {
17795 ++ case GR_ROLE_DEFAULT:
17796 ++ return 'D';
17797 ++ case GR_ROLE_USER:
17798 ++ return 'U';
17799 ++ case GR_ROLE_GROUP:
17800 ++ return 'G';
17801 ++ case GR_ROLE_SPECIAL:
17802 ++ return 'S';
17803 ++ }
17804 ++
17805 ++ return 'X';
17806 ++}
17807 ++
17808 ++__inline__ int
17809 ++gr_acl_tpe_check(void)
17810 ++{
17811 ++ if (unlikely(!(gr_status & GR_READY)))
17812 ++ return 0;
17813 ++ if (current->role->roletype & GR_ROLE_TPE)
17814 ++ return 1;
17815 ++ else
17816 ++ return 0;
17817 ++}
17818 ++
17819 ++int
17820 ++gr_handle_rawio(const struct inode *inode)
17821 ++{
17822 ++#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
17823 ++ if (inode && S_ISBLK(inode->i_mode) &&
17824 ++ grsec_enable_chroot_caps && proc_is_chrooted(current) &&
17825 ++ !capable(CAP_SYS_RAWIO))
17826 ++ return 1;
17827 ++#endif
17828 ++ return 0;
17829 ++}
17830 ++
17831 ++static int
17832 ++gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
17833 ++{
17834 ++ int i;
17835 ++ unsigned long *l1;
17836 ++ unsigned long *l2;
17837 ++ unsigned char *c1;
17838 ++ unsigned char *c2;
17839 ++ int num_longs;
17840 ++
17841 ++ if (likely(lena != lenb))
17842 ++ return 0;
17843 ++
17844 ++ l1 = (unsigned long *)a;
17845 ++ l2 = (unsigned long *)b;
17846 ++
17847 ++ num_longs = lena / sizeof(unsigned long);
17848 ++
17849 ++ for (i = num_longs; i--; l1++, l2++) {
17850 ++ if (unlikely(*l1 != *l2))
17851 ++ return 0;
17852 ++ }
17853 ++
17854 ++ c1 = (unsigned char *) l1;
17855 ++ c2 = (unsigned char *) l2;
17856 ++
17857 ++ i = lena - (num_longs * sizeof(unsigned long));
17858 ++
17859 ++ for (; i--; c1++, c2++) {
17860 ++ if (unlikely(*c1 != *c2))
17861 ++ return 0;
17862 ++ }
17863 ++
17864 ++ return 1;
17865 ++}
17866 ++
17867 ++static char * __our_d_path(struct dentry *dentry, struct vfsmount *vfsmnt,
17868 ++ struct dentry *root, struct vfsmount *rootmnt,
17869 ++ char *buffer, int buflen)
17870 ++{
17871 ++ char * end = buffer+buflen;
17872 ++ char * retval;
17873 ++ int namelen;
17874 ++
17875 ++ *--end = '\0';
17876 ++ buflen--;
17877 ++
17878 ++ if (buflen < 1)
17879 ++ goto Elong;
17880 ++ /* Get '/' right */
17881 ++ retval = end-1;
17882 ++ *retval = '/';
17883 ++
17884 ++ for (;;) {
17885 ++ struct dentry * parent;
17886 ++
17887 ++ if (dentry == root && vfsmnt == rootmnt)
17888 ++ break;
17889 ++ if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
17890 ++ /* Global root? */
17891 ++ spin_lock(&vfsmount_lock);
17892 ++ if (vfsmnt->mnt_parent == vfsmnt) {
17893 ++ spin_unlock(&vfsmount_lock);
17894 ++ goto global_root;
17895 ++ }
17896 ++ dentry = vfsmnt->mnt_mountpoint;
17897 ++ vfsmnt = vfsmnt->mnt_parent;
17898 ++ spin_unlock(&vfsmount_lock);
17899 ++ continue;
17900 ++ }
17901 ++ parent = dentry->d_parent;
17902 ++ prefetch(parent);
17903 ++ namelen = dentry->d_name.len;
17904 ++ buflen -= namelen + 1;
17905 ++ if (buflen < 0)
17906 ++ goto Elong;
17907 ++ end -= namelen;
17908 ++ memcpy(end, dentry->d_name.name, namelen);
17909 ++ *--end = '/';
17910 ++ retval = end;
17911 ++ dentry = parent;
17912 ++ }
17913 ++
17914 ++ return retval;
17915 ++
17916 ++global_root:
17917 ++ namelen = dentry->d_name.len;
17918 ++ buflen -= namelen;
17919 ++ if (buflen < 0)
17920 ++ goto Elong;
17921 ++ retval -= namelen-1; /* hit the slash */
17922 ++ memcpy(retval, dentry->d_name.name, namelen);
17923 ++ return retval;
17924 ++Elong:
17925 ++ return ERR_PTR(-ENAMETOOLONG);
17926 ++}
17927 ++
17928 ++static char *
17929 ++gen_full_path(struct dentry *dentry, struct vfsmount *vfsmnt,
17930 ++ struct dentry *root, struct vfsmount *rootmnt, char *buf, int buflen)
17931 ++{
17932 ++ char *retval;
17933 ++
17934 ++ retval = __our_d_path(dentry, vfsmnt, root, rootmnt, buf, buflen);
17935 ++ if (unlikely(IS_ERR(retval)))
17936 ++ retval = strcpy(buf, "<path too long>");
17937 ++ else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
17938 ++ retval[1] = '\0';
17939 ++
17940 ++ return retval;
17941 ++}
17942 ++
17943 ++static char *
17944 ++__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
17945 ++ char *buf, int buflen)
17946 ++{
17947 ++ char *res;
17948 ++
17949 ++ /* we can use real_root, real_root_mnt, because this is only called
17950 ++ by the RBAC system */
17951 ++ res = gen_full_path((struct dentry *)dentry, (struct vfsmount *)vfsmnt, real_root, real_root_mnt, buf, buflen);
17952 ++
17953 ++ return res;
17954 ++}
17955 ++
17956 ++static char *
17957 ++d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
17958 ++ char *buf, int buflen)
17959 ++{
17960 ++ char *res;
17961 ++ struct dentry *root;
17962 ++ struct vfsmount *rootmnt;
17963 ++ struct task_struct *reaper = current->nsproxy->pid_ns->child_reaper;
17964 ++
17965 ++ /* we can't use real_root, real_root_mnt, because they belong only to the RBAC system */
17966 ++ read_lock(&reaper->fs->lock);
17967 ++ root = dget(reaper->fs->root.dentry);
17968 ++ rootmnt = mntget(reaper->fs->root.mnt);
17969 ++ read_unlock(&reaper->fs->lock);
17970 ++
17971 ++ spin_lock(&dcache_lock);
17972 ++ res = gen_full_path((struct dentry *)dentry, (struct vfsmount *)vfsmnt, root, rootmnt, buf, buflen);
17973 ++ spin_unlock(&dcache_lock);
17974 ++
17975 ++ dput(root);
17976 ++ mntput(rootmnt);
17977 ++ return res;
17978 ++}
17979 ++
17980 ++static char *
17981 ++gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
17982 ++{
17983 ++ char *ret;
17984 ++ spin_lock(&dcache_lock);
17985 ++ ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
17986 ++ PAGE_SIZE);
17987 ++ spin_unlock(&dcache_lock);
17988 ++ return ret;
17989 ++}
17990 ++
17991 ++char *
17992 ++gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
17993 ++{
17994 ++ return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
17995 ++ PAGE_SIZE);
17996 ++}
17997 ++
17998 ++char *
17999 ++gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
18000 ++{
18001 ++ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
18002 ++ PAGE_SIZE);
18003 ++}
18004 ++
18005 ++char *
18006 ++gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
18007 ++{
18008 ++ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
18009 ++ PAGE_SIZE);
18010 ++}
18011 ++
18012 ++char *
18013 ++gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
18014 ++{
18015 ++ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
18016 ++ PAGE_SIZE);
18017 ++}
18018 ++
18019 ++char *
18020 ++gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
18021 ++{
18022 ++ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
18023 ++ PAGE_SIZE);
18024 ++}
18025 ++
18026 ++__inline__ __u32
18027 ++to_gr_audit(const __u32 reqmode)
18028 ++{
18029 ++ /* masks off auditable permission flags, then shifts them to create
18030 ++ auditing flags, and adds the special case of append auditing if
18031 ++ we're requesting write */
18032 ++ return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
18033 ++}
18034 ++
18035 ++struct acl_subject_label *
18036 ++lookup_subject_map(const struct acl_subject_label *userp)
18037 ++{
18038 ++ unsigned int index = shash(userp, subj_map_set.s_size);
18039 ++ struct subject_map *match;
18040 ++
18041 ++ match = subj_map_set.s_hash[index];
18042 ++
18043 ++ while (match && match->user != userp)
18044 ++ match = match->next;
18045 ++
18046 ++ if (match != NULL)
18047 ++ return match->kernel;
18048 ++ else
18049 ++ return NULL;
18050 ++}
18051 ++
18052 ++static void
18053 ++insert_subj_map_entry(struct subject_map *subjmap)
18054 ++{
18055 ++ unsigned int index = shash(subjmap->user, subj_map_set.s_size);
18056 ++ struct subject_map **curr;
18057 ++
18058 ++ subjmap->prev = NULL;
18059 ++
18060 ++ curr = &subj_map_set.s_hash[index];
18061 ++ if (*curr != NULL)
18062 ++ (*curr)->prev = subjmap;
18063 ++
18064 ++ subjmap->next = *curr;
18065 ++ *curr = subjmap;
18066 ++
18067 ++ return;
18068 ++}
18069 ++
18070 ++static struct acl_role_label *
18071 ++lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
18072 ++ const gid_t gid)
18073 ++{
18074 ++ unsigned int index = rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
18075 ++ struct acl_role_label *match;
18076 ++ struct role_allowed_ip *ipp;
18077 ++ unsigned int x;
18078 ++
18079 ++ match = acl_role_set.r_hash[index];
18080 ++
18081 ++ while (match) {
18082 ++ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
18083 ++ for (x = 0; x < match->domain_child_num; x++) {
18084 ++ if (match->domain_children[x] == uid)
18085 ++ goto found;
18086 ++ }
18087 ++ } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
18088 ++ break;
18089 ++ match = match->next;
18090 ++ }
18091 ++found:
18092 ++ if (match == NULL) {
18093 ++ try_group:
18094 ++ index = rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
18095 ++ match = acl_role_set.r_hash[index];
18096 ++
18097 ++ while (match) {
18098 ++ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
18099 ++ for (x = 0; x < match->domain_child_num; x++) {
18100 ++ if (match->domain_children[x] == gid)
18101 ++ goto found2;
18102 ++ }
18103 ++ } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
18104 ++ break;
18105 ++ match = match->next;
18106 ++ }
18107 ++found2:
18108 ++ if (match == NULL)
18109 ++ match = default_role;
18110 ++ if (match->allowed_ips == NULL)
18111 ++ return match;
18112 ++ else {
18113 ++ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
18114 ++ if (likely
18115 ++ ((ntohl(task->signal->curr_ip) & ipp->netmask) ==
18116 ++ (ntohl(ipp->addr) & ipp->netmask)))
18117 ++ return match;
18118 ++ }
18119 ++ match = default_role;
18120 ++ }
18121 ++ } else if (match->allowed_ips == NULL) {
18122 ++ return match;
18123 ++ } else {
18124 ++ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
18125 ++ if (likely
18126 ++ ((ntohl(task->signal->curr_ip) & ipp->netmask) ==
18127 ++ (ntohl(ipp->addr) & ipp->netmask)))
18128 ++ return match;
18129 ++ }
18130 ++ goto try_group;
18131 ++ }
18132 ++
18133 ++ return match;
18134 ++}
18135 ++
18136 ++struct acl_subject_label *
18137 ++lookup_acl_subj_label(const ino_t ino, const dev_t dev,
18138 ++ const struct acl_role_label *role)
18139 ++{
18140 ++ unsigned int index = fhash(ino, dev, role->subj_hash_size);
18141 ++ struct acl_subject_label *match;
18142 ++
18143 ++ match = role->subj_hash[index];
18144 ++
18145 ++ while (match && (match->inode != ino || match->device != dev ||
18146 ++ (match->mode & GR_DELETED))) {
18147 ++ match = match->next;
18148 ++ }
18149 ++
18150 ++ if (match && !(match->mode & GR_DELETED))
18151 ++ return match;
18152 ++ else
18153 ++ return NULL;
18154 ++}
18155 ++
18156 ++static struct acl_object_label *
18157 ++lookup_acl_obj_label(const ino_t ino, const dev_t dev,
18158 ++ const struct acl_subject_label *subj)
18159 ++{
18160 ++ unsigned int index = fhash(ino, dev, subj->obj_hash_size);
18161 ++ struct acl_object_label *match;
18162 ++
18163 ++ match = subj->obj_hash[index];
18164 ++
18165 ++ while (match && (match->inode != ino || match->device != dev ||
18166 ++ (match->mode & GR_DELETED))) {
18167 ++ match = match->next;
18168 ++ }
18169 ++
18170 ++ if (match && !(match->mode & GR_DELETED))
18171 ++ return match;
18172 ++ else
18173 ++ return NULL;
18174 ++}
18175 ++
18176 ++static struct acl_object_label *
18177 ++lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
18178 ++ const struct acl_subject_label *subj)
18179 ++{
18180 ++ unsigned int index = fhash(ino, dev, subj->obj_hash_size);
18181 ++ struct acl_object_label *match;
18182 ++
18183 ++ match = subj->obj_hash[index];
18184 ++
18185 ++ while (match && (match->inode != ino || match->device != dev ||
18186 ++ !(match->mode & GR_DELETED))) {
18187 ++ match = match->next;
18188 ++ }
18189 ++
18190 ++ if (match && (match->mode & GR_DELETED))
18191 ++ return match;
18192 ++
18193 ++ match = subj->obj_hash[index];
18194 ++
18195 ++ while (match && (match->inode != ino || match->device != dev ||
18196 ++ (match->mode & GR_DELETED))) {
18197 ++ match = match->next;
18198 ++ }
18199 ++
18200 ++ if (match && !(match->mode & GR_DELETED))
18201 ++ return match;
18202 ++ else
18203 ++ return NULL;
18204 ++}
18205 ++
18206 ++static struct name_entry *
18207 ++lookup_name_entry(const char *name)
18208 ++{
18209 ++ unsigned int len = strlen(name);
18210 ++ unsigned int key = full_name_hash(name, len);
18211 ++ unsigned int index = key % name_set.n_size;
18212 ++ struct name_entry *match;
18213 ++
18214 ++ match = name_set.n_hash[index];
18215 ++
18216 ++ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
18217 ++ match = match->next;
18218 ++
18219 ++ return match;
18220 ++}
18221 ++
18222 ++static struct name_entry *
18223 ++lookup_name_entry_create(const char *name)
18224 ++{
18225 ++ unsigned int len = strlen(name);
18226 ++ unsigned int key = full_name_hash(name, len);
18227 ++ unsigned int index = key % name_set.n_size;
18228 ++ struct name_entry *match;
18229 ++
18230 ++ match = name_set.n_hash[index];
18231 ++
18232 ++ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
18233 ++ !match->deleted))
18234 ++ match = match->next;
18235 ++
18236 ++ if (match && match->deleted)
18237 ++ return match;
18238 ++
18239 ++ match = name_set.n_hash[index];
18240 ++
18241 ++ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
18242 ++ match->deleted))
18243 ++ match = match->next;
18244 ++
18245 ++ if (match && !match->deleted)
18246 ++ return match;
18247 ++ else
18248 ++ return NULL;
18249 ++}
18250 ++
18251 ++static struct inodev_entry *
18252 ++lookup_inodev_entry(const ino_t ino, const dev_t dev)
18253 ++{
18254 ++ unsigned int index = fhash(ino, dev, inodev_set.i_size);
18255 ++ struct inodev_entry *match;
18256 ++
18257 ++ match = inodev_set.i_hash[index];
18258 ++
18259 ++ while (match && (match->nentry->inode != ino || match->nentry->device != dev))
18260 ++ match = match->next;
18261 ++
18262 ++ return match;
18263 ++}
18264 ++
18265 ++static void
18266 ++insert_inodev_entry(struct inodev_entry *entry)
18267 ++{
18268 ++ unsigned int index = fhash(entry->nentry->inode, entry->nentry->device,
18269 ++ inodev_set.i_size);
18270 ++ struct inodev_entry **curr;
18271 ++
18272 ++ entry->prev = NULL;
18273 ++
18274 ++ curr = &inodev_set.i_hash[index];
18275 ++ if (*curr != NULL)
18276 ++ (*curr)->prev = entry;
18277 ++
18278 ++ entry->next = *curr;
18279 ++ *curr = entry;
18280 ++
18281 ++ return;
18282 ++}
18283 ++
18284 ++static void
18285 ++__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
18286 ++{
18287 ++ unsigned int index =
18288 ++ rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
18289 ++ struct acl_role_label **curr;
18290 ++
18291 ++ role->prev = NULL;
18292 ++
18293 ++ curr = &acl_role_set.r_hash[index];
18294 ++ if (*curr != NULL)
18295 ++ (*curr)->prev = role;
18296 ++
18297 ++ role->next = *curr;
18298 ++ *curr = role;
18299 ++
18300 ++ return;
18301 ++}
18302 ++
18303 ++static void
18304 ++insert_acl_role_label(struct acl_role_label *role)
18305 ++{
18306 ++ int i;
18307 ++
18308 ++ if (role->roletype & GR_ROLE_DOMAIN) {
18309 ++ for (i = 0; i < role->domain_child_num; i++)
18310 ++ __insert_acl_role_label(role, role->domain_children[i]);
18311 ++ } else
18312 ++ __insert_acl_role_label(role, role->uidgid);
18313 ++}
18314 ++
18315 ++static int
18316 ++insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
18317 ++{
18318 ++ struct name_entry **curr, *nentry;
18319 ++ struct inodev_entry *ientry;
18320 ++ unsigned int len = strlen(name);
18321 ++ unsigned int key = full_name_hash(name, len);
18322 ++ unsigned int index = key % name_set.n_size;
18323 ++
18324 ++ curr = &name_set.n_hash[index];
18325 ++
18326 ++ while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
18327 ++ curr = &((*curr)->next);
18328 ++
18329 ++ if (*curr != NULL)
18330 ++ return 1;
18331 ++
18332 ++ nentry = acl_alloc(sizeof (struct name_entry));
18333 ++ if (nentry == NULL)
18334 ++ return 0;
18335 ++ ientry = acl_alloc(sizeof (struct inodev_entry));
18336 ++ if (ientry == NULL)
18337 ++ return 0;
18338 ++ ientry->nentry = nentry;
18339 ++
18340 ++ nentry->key = key;
18341 ++ nentry->name = name;
18342 ++ nentry->inode = inode;
18343 ++ nentry->device = device;
18344 ++ nentry->len = len;
18345 ++ nentry->deleted = deleted;
18346 ++
18347 ++ nentry->prev = NULL;
18348 ++ curr = &name_set.n_hash[index];
18349 ++ if (*curr != NULL)
18350 ++ (*curr)->prev = nentry;
18351 ++ nentry->next = *curr;
18352 ++ *curr = nentry;
18353 ++
18354 ++ /* insert us into the table searchable by inode/dev */
18355 ++ insert_inodev_entry(ientry);
18356 ++
18357 ++ return 1;
18358 ++}
18359 ++
18360 ++static void
18361 ++insert_acl_obj_label(struct acl_object_label *obj,
18362 ++ struct acl_subject_label *subj)
18363 ++{
18364 ++ unsigned int index =
18365 ++ fhash(obj->inode, obj->device, subj->obj_hash_size);
18366 ++ struct acl_object_label **curr;
18367 ++
18368 ++
18369 ++ obj->prev = NULL;
18370 ++
18371 ++ curr = &subj->obj_hash[index];
18372 ++ if (*curr != NULL)
18373 ++ (*curr)->prev = obj;
18374 ++
18375 ++ obj->next = *curr;
18376 ++ *curr = obj;
18377 ++
18378 ++ return;
18379 ++}
18380 ++
18381 ++static void
18382 ++insert_acl_subj_label(struct acl_subject_label *obj,
18383 ++ struct acl_role_label *role)
18384 ++{
18385 ++ unsigned int index = fhash(obj->inode, obj->device, role->subj_hash_size);
18386 ++ struct acl_subject_label **curr;
18387 ++
18388 ++ obj->prev = NULL;
18389 ++
18390 ++ curr = &role->subj_hash[index];
18391 ++ if (*curr != NULL)
18392 ++ (*curr)->prev = obj;
18393 ++
18394 ++ obj->next = *curr;
18395 ++ *curr = obj;
18396 ++
18397 ++ return;
18398 ++}
18399 ++
18400 ++/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
18401 ++
18402 ++static void *
18403 ++create_table(__u32 * len, int elementsize)
18404 ++{
18405 ++ unsigned int table_sizes[] = {
18406 ++ 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
18407 ++ 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
18408 ++ 4194301, 8388593, 16777213, 33554393, 67108859, 134217689,
18409 ++ 268435399, 536870909, 1073741789, 2147483647
18410 ++ };
18411 ++ void *newtable = NULL;
18412 ++ unsigned int pwr = 0;
18413 ++
18414 ++ while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
18415 ++ table_sizes[pwr] <= *len)
18416 ++ pwr++;
18417 ++
18418 ++ if (table_sizes[pwr] <= *len)
18419 ++ return newtable;
18420 ++
18421 ++ if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
18422 ++ newtable =
18423 ++ kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
18424 ++ else
18425 ++ newtable = vmalloc(table_sizes[pwr] * elementsize);
18426 ++
18427 ++ *len = table_sizes[pwr];
18428 ++
18429 ++ return newtable;
18430 ++}
18431 ++
18432 ++static int
18433 ++init_variables(const struct gr_arg *arg)
18434 ++{
18435 ++ struct task_struct *reaper = current->nsproxy->pid_ns->child_reaper;
18436 ++ unsigned int stacksize;
18437 ++
18438 ++ subj_map_set.s_size = arg->role_db.num_subjects;
18439 ++ acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
18440 ++ name_set.n_size = arg->role_db.num_objects;
18441 ++ inodev_set.i_size = arg->role_db.num_objects;
18442 ++
18443 ++ if (!subj_map_set.s_size || !acl_role_set.r_size ||
18444 ++ !name_set.n_size || !inodev_set.i_size)
18445 ++ return 1;
18446 ++
18447 ++ if (!gr_init_uidset())
18448 ++ return 1;
18449 ++
18450 ++ /* set up the stack that holds allocation info */
18451 ++
18452 ++ stacksize = arg->role_db.num_pointers + 5;
18453 ++
18454 ++ if (!acl_alloc_stack_init(stacksize))
18455 ++ return 1;
18456 ++
18457 ++ /* grab reference for the real root dentry and vfsmount */
18458 ++ read_lock(&reaper->fs->lock);
18459 ++ real_root_mnt = mntget(reaper->fs->root.mnt);
18460 ++ real_root = dget(reaper->fs->root.dentry);
18461 ++ read_unlock(&reaper->fs->lock);
18462 ++
18463 ++ fakefs_obj = acl_alloc(sizeof(struct acl_object_label));
18464 ++ if (fakefs_obj == NULL)
18465 ++ return 1;
18466 ++ fakefs_obj->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
18467 ++
18468 ++ subj_map_set.s_hash =
18469 ++ (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
18470 ++ acl_role_set.r_hash =
18471 ++ (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
18472 ++ name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
18473 ++ inodev_set.i_hash =
18474 ++ (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
18475 ++
18476 ++ if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
18477 ++ !name_set.n_hash || !inodev_set.i_hash)
18478 ++ return 1;
18479 ++
18480 ++ memset(subj_map_set.s_hash, 0,
18481 ++ sizeof(struct subject_map *) * subj_map_set.s_size);
18482 ++ memset(acl_role_set.r_hash, 0,
18483 ++ sizeof (struct acl_role_label *) * acl_role_set.r_size);
18484 ++ memset(name_set.n_hash, 0,
18485 ++ sizeof (struct name_entry *) * name_set.n_size);
18486 ++ memset(inodev_set.i_hash, 0,
18487 ++ sizeof (struct inodev_entry *) * inodev_set.i_size);
18488 ++
18489 ++ return 0;
18490 ++}
18491 ++
18492 ++/* free information not needed after startup
18493 ++ currently contains user->kernel pointer mappings for subjects
18494 ++*/
18495 ++
18496 ++static void
18497 ++free_init_variables(void)
18498 ++{
18499 ++ __u32 i;
18500 ++
18501 ++ if (subj_map_set.s_hash) {
18502 ++ for (i = 0; i < subj_map_set.s_size; i++) {
18503 ++ if (subj_map_set.s_hash[i]) {
18504 ++ kfree(subj_map_set.s_hash[i]);
18505 ++ subj_map_set.s_hash[i] = NULL;
18506 ++ }
18507 ++ }
18508 ++
18509 ++ if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
18510 ++ PAGE_SIZE)
18511 ++ kfree(subj_map_set.s_hash);
18512 ++ else
18513 ++ vfree(subj_map_set.s_hash);
18514 ++ }
18515 ++
18516 ++ return;
18517 ++}
18518 ++
18519 ++static void
18520 ++free_variables(void)
18521 ++{
18522 ++ struct acl_subject_label *s;
18523 ++ struct acl_role_label *r;
18524 ++ struct task_struct *task, *task2;
18525 ++ unsigned int i, x;
18526 ++
18527 ++ gr_clear_learn_entries();
18528 ++
18529 ++ read_lock(&tasklist_lock);
18530 ++ do_each_thread(task2, task) {
18531 ++ task->acl_sp_role = 0;
18532 ++ task->acl_role_id = 0;
18533 ++ task->acl = NULL;
18534 ++ task->role = NULL;
18535 ++ } while_each_thread(task2, task);
18536 ++ read_unlock(&tasklist_lock);
18537 ++
18538 ++ /* release the reference to the real root dentry and vfsmount */
18539 ++ if (real_root)
18540 ++ dput(real_root);
18541 ++ real_root = NULL;
18542 ++ if (real_root_mnt)
18543 ++ mntput(real_root_mnt);
18544 ++ real_root_mnt = NULL;
18545 ++
18546 ++ /* free all object hash tables */
18547 ++
18548 ++ FOR_EACH_ROLE_START(r, i)
18549 ++ if (r->subj_hash == NULL)
18550 ++ break;
18551 ++ FOR_EACH_SUBJECT_START(r, s, x)
18552 ++ if (s->obj_hash == NULL)
18553 ++ break;
18554 ++ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
18555 ++ kfree(s->obj_hash);
18556 ++ else
18557 ++ vfree(s->obj_hash);
18558 ++ FOR_EACH_SUBJECT_END(s, x)
18559 ++ FOR_EACH_NESTED_SUBJECT_START(r, s)
18560 ++ if (s->obj_hash == NULL)
18561 ++ break;
18562 ++ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
18563 ++ kfree(s->obj_hash);
18564 ++ else
18565 ++ vfree(s->obj_hash);
18566 ++ FOR_EACH_NESTED_SUBJECT_END(s)
18567 ++ if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
18568 ++ kfree(r->subj_hash);
18569 ++ else
18570 ++ vfree(r->subj_hash);
18571 ++ r->subj_hash = NULL;
18572 ++ FOR_EACH_ROLE_END(r,i)
18573 ++
18574 ++ acl_free_all();
18575 ++
18576 ++ if (acl_role_set.r_hash) {
18577 ++ if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
18578 ++ PAGE_SIZE)
18579 ++ kfree(acl_role_set.r_hash);
18580 ++ else
18581 ++ vfree(acl_role_set.r_hash);
18582 ++ }
18583 ++ if (name_set.n_hash) {
18584 ++ if ((name_set.n_size * sizeof (struct name_entry *)) <=
18585 ++ PAGE_SIZE)
18586 ++ kfree(name_set.n_hash);
18587 ++ else
18588 ++ vfree(name_set.n_hash);
18589 ++ }
18590 ++
18591 ++ if (inodev_set.i_hash) {
18592 ++ if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
18593 ++ PAGE_SIZE)
18594 ++ kfree(inodev_set.i_hash);
18595 ++ else
18596 ++ vfree(inodev_set.i_hash);
18597 ++ }
18598 ++
18599 ++ gr_free_uidset();
18600 ++
18601 ++ memset(&name_set, 0, sizeof (struct name_db));
18602 ++ memset(&inodev_set, 0, sizeof (struct inodev_db));
18603 ++ memset(&acl_role_set, 0, sizeof (struct acl_role_db));
18604 ++ memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
18605 ++
18606 ++ default_role = NULL;
18607 ++
18608 ++ return;
18609 ++}
18610 ++
18611 ++static __u32
18612 ++count_user_objs(struct acl_object_label *userp)
18613 ++{
18614 ++ struct acl_object_label o_tmp;
18615 ++ __u32 num = 0;
18616 ++
18617 ++ while (userp) {
18618 ++ if (copy_from_user(&o_tmp, userp,
18619 ++ sizeof (struct acl_object_label)))
18620 ++ break;
18621 ++
18622 ++ userp = o_tmp.prev;
18623 ++ num++;
18624 ++ }
18625 ++
18626 ++ return num;
18627 ++}
18628 ++
18629 ++static struct acl_subject_label *
18630 ++do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role);
18631 ++
18632 ++static int
18633 ++copy_user_glob(struct acl_object_label *obj)
18634 ++{
18635 ++ struct acl_object_label *g_tmp, **guser;
18636 ++ unsigned int len;
18637 ++ char *tmp;
18638 ++
18639 ++ if (obj->globbed == NULL)
18640 ++ return 0;
18641 ++
18642 ++ guser = &obj->globbed;
18643 ++ while (*guser) {
18644 ++ g_tmp = (struct acl_object_label *)
18645 ++ acl_alloc(sizeof (struct acl_object_label));
18646 ++ if (g_tmp == NULL)
18647 ++ return -ENOMEM;
18648 ++
18649 ++ if (copy_from_user(g_tmp, *guser,
18650 ++ sizeof (struct acl_object_label)))
18651 ++ return -EFAULT;
18652 ++
18653 ++ len = strnlen_user(g_tmp->filename, PATH_MAX);
18654 ++
18655 ++ if (!len || len >= PATH_MAX)
18656 ++ return -EINVAL;
18657 ++
18658 ++ if ((tmp = (char *) acl_alloc(len)) == NULL)
18659 ++ return -ENOMEM;
18660 ++
18661 ++ if (copy_from_user(tmp, g_tmp->filename, len))
18662 ++ return -EFAULT;
18663 ++
18664 ++ g_tmp->filename = tmp;
18665 ++
18666 ++ *guser = g_tmp;
18667 ++ guser = &(g_tmp->next);
18668 ++ }
18669 ++
18670 ++ return 0;
18671 ++}
18672 ++
18673 ++static int
18674 ++copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
18675 ++ struct acl_role_label *role)
18676 ++{
18677 ++ struct acl_object_label *o_tmp;
18678 ++ unsigned int len;
18679 ++ int ret;
18680 ++ char *tmp;
18681 ++
18682 ++ while (userp) {
18683 ++ if ((o_tmp = (struct acl_object_label *)
18684 ++ acl_alloc(sizeof (struct acl_object_label))) == NULL)
18685 ++ return -ENOMEM;
18686 ++
18687 ++ if (copy_from_user(o_tmp, userp,
18688 ++ sizeof (struct acl_object_label)))
18689 ++ return -EFAULT;
18690 ++
18691 ++ userp = o_tmp->prev;
18692 ++
18693 ++ len = strnlen_user(o_tmp->filename, PATH_MAX);
18694 ++
18695 ++ if (!len || len >= PATH_MAX)
18696 ++ return -EINVAL;
18697 ++
18698 ++ if ((tmp = (char *) acl_alloc(len)) == NULL)
18699 ++ return -ENOMEM;
18700 ++
18701 ++ if (copy_from_user(tmp, o_tmp->filename, len))
18702 ++ return -EFAULT;
18703 ++
18704 ++ o_tmp->filename = tmp;
18705 ++
18706 ++ insert_acl_obj_label(o_tmp, subj);
18707 ++ if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
18708 ++ o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
18709 ++ return -ENOMEM;
18710 ++
18711 ++ ret = copy_user_glob(o_tmp);
18712 ++ if (ret)
18713 ++ return ret;
18714 ++
18715 ++ if (o_tmp->nested) {
18716 ++ o_tmp->nested = do_copy_user_subj(o_tmp->nested, role);
18717 ++ if (IS_ERR(o_tmp->nested))
18718 ++ return PTR_ERR(o_tmp->nested);
18719 ++
18720 ++ /* insert into nested subject list */
18721 ++ o_tmp->nested->next = role->hash->first;
18722 ++ role->hash->first = o_tmp->nested;
18723 ++ }
18724 ++ }
18725 ++
18726 ++ return 0;
18727 ++}
18728 ++
18729 ++static __u32
18730 ++count_user_subjs(struct acl_subject_label *userp)
18731 ++{
18732 ++ struct acl_subject_label s_tmp;
18733 ++ __u32 num = 0;
18734 ++
18735 ++ while (userp) {
18736 ++ if (copy_from_user(&s_tmp, userp,
18737 ++ sizeof (struct acl_subject_label)))
18738 ++ break;
18739 ++
18740 ++ userp = s_tmp.prev;
18741 ++ /* do not count nested subjects against this count, since
18742 ++ they are not included in the hash table, but are
18743 ++ attached to objects. We have already counted
18744 ++ the subjects in userspace for the allocation
18745 ++ stack
18746 ++ */
18747 ++ if (!(s_tmp.mode & GR_NESTED))
18748 ++ num++;
18749 ++ }
18750 ++
18751 ++ return num;
18752 ++}
18753 ++
18754 ++static int
18755 ++copy_user_allowedips(struct acl_role_label *rolep)
18756 ++{
18757 ++ struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
18758 ++
18759 ++ ruserip = rolep->allowed_ips;
18760 ++
18761 ++ while (ruserip) {
18762 ++ rlast = rtmp;
18763 ++
18764 ++ if ((rtmp = (struct role_allowed_ip *)
18765 ++ acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
18766 ++ return -ENOMEM;
18767 ++
18768 ++ if (copy_from_user(rtmp, ruserip,
18769 ++ sizeof (struct role_allowed_ip)))
18770 ++ return -EFAULT;
18771 ++
18772 ++ ruserip = rtmp->prev;
18773 ++
18774 ++ if (!rlast) {
18775 ++ rtmp->prev = NULL;
18776 ++ rolep->allowed_ips = rtmp;
18777 ++ } else {
18778 ++ rlast->next = rtmp;
18779 ++ rtmp->prev = rlast;
18780 ++ }
18781 ++
18782 ++ if (!ruserip)
18783 ++ rtmp->next = NULL;
18784 ++ }
18785 ++
18786 ++ return 0;
18787 ++}
18788 ++
18789 ++static int
18790 ++copy_user_transitions(struct acl_role_label *rolep)
18791 ++{
18792 ++ struct role_transition *rusertp, *rtmp = NULL, *rlast;
18793 ++
18794 ++ unsigned int len;
18795 ++ char *tmp;
18796 ++
18797 ++ rusertp = rolep->transitions;
18798 ++
18799 ++ while (rusertp) {
18800 ++ rlast = rtmp;
18801 ++
18802 ++ if ((rtmp = (struct role_transition *)
18803 ++ acl_alloc(sizeof (struct role_transition))) == NULL)
18804 ++ return -ENOMEM;
18805 ++
18806 ++ if (copy_from_user(rtmp, rusertp,
18807 ++ sizeof (struct role_transition)))
18808 ++ return -EFAULT;
18809 ++
18810 ++ rusertp = rtmp->prev;
18811 ++
18812 ++ len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
18813 ++
18814 ++ if (!len || len >= GR_SPROLE_LEN)
18815 ++ return -EINVAL;
18816 ++
18817 ++ if ((tmp = (char *) acl_alloc(len)) == NULL)
18818 ++ return -ENOMEM;
18819 ++
18820 ++ if (copy_from_user(tmp, rtmp->rolename, len))
18821 ++ return -EFAULT;
18822 ++
18823 ++ rtmp->rolename = tmp;
18824 ++
18825 ++ if (!rlast) {
18826 ++ rtmp->prev = NULL;
18827 ++ rolep->transitions = rtmp;
18828 ++ } else {
18829 ++ rlast->next = rtmp;
18830 ++ rtmp->prev = rlast;
18831 ++ }
18832 ++
18833 ++ if (!rusertp)
18834 ++ rtmp->next = NULL;
18835 ++ }
18836 ++
18837 ++ return 0;
18838 ++}
18839 ++
18840 ++static struct acl_subject_label *
18841 ++do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role)
18842 ++{
18843 ++ struct acl_subject_label *s_tmp = NULL, *s_tmp2;
18844 ++ unsigned int len;
18845 ++ char *tmp;
18846 ++ __u32 num_objs;
18847 ++ struct acl_ip_label **i_tmp, *i_utmp2;
18848 ++ struct gr_hash_struct ghash;
18849 ++ struct subject_map *subjmap;
18850 ++ unsigned int i_num;
18851 ++ int err;
18852 ++
18853 ++ s_tmp = lookup_subject_map(userp);
18854 ++
18855 ++ /* we've already copied this subject into the kernel, just return
18856 ++ the reference to it, and don't copy it over again
18857 ++ */
18858 ++ if (s_tmp)
18859 ++ return(s_tmp);
18860 ++
18861 ++ if ((s_tmp = (struct acl_subject_label *)
18862 ++ acl_alloc(sizeof (struct acl_subject_label))) == NULL)
18863 ++ return ERR_PTR(-ENOMEM);
18864 ++
18865 ++ subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
18866 ++ if (subjmap == NULL)
18867 ++ return ERR_PTR(-ENOMEM);
18868 ++
18869 ++ subjmap->user = userp;
18870 ++ subjmap->kernel = s_tmp;
18871 ++ insert_subj_map_entry(subjmap);
18872 ++
18873 ++ if (copy_from_user(s_tmp, userp,
18874 ++ sizeof (struct acl_subject_label)))
18875 ++ return ERR_PTR(-EFAULT);
18876 ++
18877 ++ len = strnlen_user(s_tmp->filename, PATH_MAX);
18878 ++
18879 ++ if (!len || len >= PATH_MAX)
18880 ++ return ERR_PTR(-EINVAL);
18881 ++
18882 ++ if ((tmp = (char *) acl_alloc(len)) == NULL)
18883 ++ return ERR_PTR(-ENOMEM);
18884 ++
18885 ++ if (copy_from_user(tmp, s_tmp->filename, len))
18886 ++ return ERR_PTR(-EFAULT);
18887 ++
18888 ++ s_tmp->filename = tmp;
18889 ++
18890 ++ if (!strcmp(s_tmp->filename, "/"))
18891 ++ role->root_label = s_tmp;
18892 ++
18893 ++ if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
18894 ++ return ERR_PTR(-EFAULT);
18895 ++
18896 ++ /* copy user and group transition tables */
18897 ++
18898 ++ if (s_tmp->user_trans_num) {
18899 ++ uid_t *uidlist;
18900 ++
18901 ++ uidlist = (uid_t *)acl_alloc(s_tmp->user_trans_num * sizeof(uid_t));
18902 ++ if (uidlist == NULL)
18903 ++ return ERR_PTR(-ENOMEM);
18904 ++ if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
18905 ++ return ERR_PTR(-EFAULT);
18906 ++
18907 ++ s_tmp->user_transitions = uidlist;
18908 ++ }
18909 ++
18910 ++ if (s_tmp->group_trans_num) {
18911 ++ gid_t *gidlist;
18912 ++
18913 ++ gidlist = (gid_t *)acl_alloc(s_tmp->group_trans_num * sizeof(gid_t));
18914 ++ if (gidlist == NULL)
18915 ++ return ERR_PTR(-ENOMEM);
18916 ++ if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
18917 ++ return ERR_PTR(-EFAULT);
18918 ++
18919 ++ s_tmp->group_transitions = gidlist;
18920 ++ }
18921 ++
18922 ++ /* set up object hash table */
18923 ++ num_objs = count_user_objs(ghash.first);
18924 ++
18925 ++ s_tmp->obj_hash_size = num_objs;
18926 ++ s_tmp->obj_hash =
18927 ++ (struct acl_object_label **)
18928 ++ create_table(&(s_tmp->obj_hash_size), sizeof(void *));
18929 ++
18930 ++ if (!s_tmp->obj_hash)
18931 ++ return ERR_PTR(-ENOMEM);
18932 ++
18933 ++ memset(s_tmp->obj_hash, 0,
18934 ++ s_tmp->obj_hash_size *
18935 ++ sizeof (struct acl_object_label *));
18936 ++
18937 ++ /* add in objects */
18938 ++ err = copy_user_objs(ghash.first, s_tmp, role);
18939 ++
18940 ++ if (err)
18941 ++ return ERR_PTR(err);
18942 ++
18943 ++ /* set pointer for parent subject */
18944 ++ if (s_tmp->parent_subject) {
18945 ++ s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role);
18946 ++
18947 ++ if (IS_ERR(s_tmp2))
18948 ++ return s_tmp2;
18949 ++
18950 ++ s_tmp->parent_subject = s_tmp2;
18951 ++ }
18952 ++
18953 ++ /* add in ip acls */
18954 ++
18955 ++ if (!s_tmp->ip_num) {
18956 ++ s_tmp->ips = NULL;
18957 ++ goto insert;
18958 ++ }
18959 ++
18960 ++ i_tmp =
18961 ++ (struct acl_ip_label **) acl_alloc(s_tmp->ip_num *
18962 ++ sizeof (struct
18963 ++ acl_ip_label *));
18964 ++
18965 ++ if (!i_tmp)
18966 ++ return ERR_PTR(-ENOMEM);
18967 ++
18968 ++ for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
18969 ++ *(i_tmp + i_num) =
18970 ++ (struct acl_ip_label *)
18971 ++ acl_alloc(sizeof (struct acl_ip_label));
18972 ++ if (!*(i_tmp + i_num))
18973 ++ return ERR_PTR(-ENOMEM);
18974 ++
18975 ++ if (copy_from_user
18976 ++ (&i_utmp2, s_tmp->ips + i_num,
18977 ++ sizeof (struct acl_ip_label *)))
18978 ++ return ERR_PTR(-EFAULT);
18979 ++
18980 ++ if (copy_from_user
18981 ++ (*(i_tmp + i_num), i_utmp2,
18982 ++ sizeof (struct acl_ip_label)))
18983 ++ return ERR_PTR(-EFAULT);
18984 ++
18985 ++ if ((*(i_tmp + i_num))->iface == NULL)
18986 ++ continue;
18987 ++
18988 ++ len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
18989 ++ if (!len || len >= IFNAMSIZ)
18990 ++ return ERR_PTR(-EINVAL);
18991 ++ tmp = acl_alloc(len);
18992 ++ if (tmp == NULL)
18993 ++ return ERR_PTR(-ENOMEM);
18994 ++ if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
18995 ++ return ERR_PTR(-EFAULT);
18996 ++ (*(i_tmp + i_num))->iface = tmp;
18997 ++ }
18998 ++
18999 ++ s_tmp->ips = i_tmp;
19000 ++
19001 ++insert:
19002 ++ if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
19003 ++ s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
19004 ++ return ERR_PTR(-ENOMEM);
19005 ++
19006 ++ return s_tmp;
19007 ++}
19008 ++
19009 ++static int
19010 ++copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
19011 ++{
19012 ++ struct acl_subject_label s_pre;
19013 ++ struct acl_subject_label * ret;
19014 ++ int err;
19015 ++
19016 ++ while (userp) {
19017 ++ if (copy_from_user(&s_pre, userp,
19018 ++ sizeof (struct acl_subject_label)))
19019 ++ return -EFAULT;
19020 ++
19021 ++ /* do not add nested subjects here, add
19022 ++ while parsing objects
19023 ++ */
19024 ++
19025 ++ if (s_pre.mode & GR_NESTED) {
19026 ++ userp = s_pre.prev;
19027 ++ continue;
19028 ++ }
19029 ++
19030 ++ ret = do_copy_user_subj(userp, role);
19031 ++
19032 ++ err = PTR_ERR(ret);
19033 ++ if (IS_ERR(ret))
19034 ++ return err;
19035 ++
19036 ++ insert_acl_subj_label(ret, role);
19037 ++
19038 ++ userp = s_pre.prev;
19039 ++ }
19040 ++
19041 ++ return 0;
19042 ++}
19043 ++
19044 ++static int
19045 ++copy_user_acl(struct gr_arg *arg)
19046 ++{
19047 ++ struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
19048 ++ struct sprole_pw *sptmp;
19049 ++ struct gr_hash_struct *ghash;
19050 ++ uid_t *domainlist;
19051 ++ unsigned int r_num;
19052 ++ unsigned int len;
19053 ++ char *tmp;
19054 ++ int err = 0;
19055 ++ __u16 i;
19056 ++ __u32 num_subjs;
19057 ++
19058 ++ /* we need a default and kernel role */
19059 ++ if (arg->role_db.num_roles < 2)
19060 ++ return -EINVAL;
19061 ++
19062 ++ /* copy special role authentication info from userspace */
19063 ++
19064 ++ num_sprole_pws = arg->num_sprole_pws;
19065 ++ acl_special_roles = (struct sprole_pw **) acl_alloc(num_sprole_pws * sizeof(struct sprole_pw *));
19066 ++
19067 ++ if (!acl_special_roles) {
19068 ++ err = -ENOMEM;
19069 ++ goto cleanup;
19070 ++ }
19071 ++
19072 ++ for (i = 0; i < num_sprole_pws; i++) {
19073 ++ sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
19074 ++ if (!sptmp) {
19075 ++ err = -ENOMEM;
19076 ++ goto cleanup;
19077 ++ }
19078 ++ if (copy_from_user(sptmp, arg->sprole_pws + i,
19079 ++ sizeof (struct sprole_pw))) {
19080 ++ err = -EFAULT;
19081 ++ goto cleanup;
19082 ++ }
19083 ++
19084 ++ len =
19085 ++ strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
19086 ++
19087 ++ if (!len || len >= GR_SPROLE_LEN) {
19088 ++ err = -EINVAL;
19089 ++ goto cleanup;
19090 ++ }
19091 ++
19092 ++ if ((tmp = (char *) acl_alloc(len)) == NULL) {
19093 ++ err = -ENOMEM;
19094 ++ goto cleanup;
19095 ++ }
19096 ++
19097 ++ if (copy_from_user(tmp, sptmp->rolename, len)) {
19098 ++ err = -EFAULT;
19099 ++ goto cleanup;
19100 ++ }
19101 ++
19102 ++#ifdef CONFIG_GRKERNSEC_ACL_DEBUG
19103 ++ printk(KERN_ALERT "Copying special role %s\n", tmp);
19104 ++#endif
19105 ++ sptmp->rolename = tmp;
19106 ++ acl_special_roles[i] = sptmp;
19107 ++ }
19108 ++
19109 ++ r_utmp = (struct acl_role_label **) arg->role_db.r_table;
19110 ++
19111 ++ for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
19112 ++ r_tmp = acl_alloc(sizeof (struct acl_role_label));
19113 ++
19114 ++ if (!r_tmp) {
19115 ++ err = -ENOMEM;
19116 ++ goto cleanup;
19117 ++ }
19118 ++
19119 ++ if (copy_from_user(&r_utmp2, r_utmp + r_num,
19120 ++ sizeof (struct acl_role_label *))) {
19121 ++ err = -EFAULT;
19122 ++ goto cleanup;
19123 ++ }
19124 ++
19125 ++ if (copy_from_user(r_tmp, r_utmp2,
19126 ++ sizeof (struct acl_role_label))) {
19127 ++ err = -EFAULT;
19128 ++ goto cleanup;
19129 ++ }
19130 ++
19131 ++ len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
19132 ++
19133 ++ if (!len || len >= PATH_MAX) {
19134 ++ err = -EINVAL;
19135 ++ goto cleanup;
19136 ++ }
19137 ++
19138 ++ if ((tmp = (char *) acl_alloc(len)) == NULL) {
19139 ++ err = -ENOMEM;
19140 ++ goto cleanup;
19141 ++ }
19142 ++ if (copy_from_user(tmp, r_tmp->rolename, len)) {
19143 ++ err = -EFAULT;
19144 ++ goto cleanup;
19145 ++ }
19146 ++ r_tmp->rolename = tmp;
19147 ++
19148 ++ if (!strcmp(r_tmp->rolename, "default")
19149 ++ && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
19150 ++ default_role = r_tmp;
19151 ++ } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
19152 ++ kernel_role = r_tmp;
19153 ++ }
19154 ++
19155 ++ if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL) {
19156 ++ err = -ENOMEM;
19157 ++ goto cleanup;
19158 ++ }
19159 ++ if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct))) {
19160 ++ err = -EFAULT;
19161 ++ goto cleanup;
19162 ++ }
19163 ++
19164 ++ r_tmp->hash = ghash;
19165 ++
19166 ++ num_subjs = count_user_subjs(r_tmp->hash->first);
19167 ++
19168 ++ r_tmp->subj_hash_size = num_subjs;
19169 ++ r_tmp->subj_hash =
19170 ++ (struct acl_subject_label **)
19171 ++ create_table(&(r_tmp->subj_hash_size), sizeof(void *));
19172 ++
19173 ++ if (!r_tmp->subj_hash) {
19174 ++ err = -ENOMEM;
19175 ++ goto cleanup;
19176 ++ }
19177 ++
19178 ++ err = copy_user_allowedips(r_tmp);
19179 ++ if (err)
19180 ++ goto cleanup;
19181 ++
19182 ++ /* copy domain info */
19183 ++ if (r_tmp->domain_children != NULL) {
19184 ++ domainlist = acl_alloc(r_tmp->domain_child_num * sizeof(uid_t));
19185 ++ if (domainlist == NULL) {
19186 ++ err = -ENOMEM;
19187 ++ goto cleanup;
19188 ++ }
19189 ++ if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t))) {
19190 ++ err = -EFAULT;
19191 ++ goto cleanup;
19192 ++ }
19193 ++ r_tmp->domain_children = domainlist;
19194 ++ }
19195 ++
19196 ++ err = copy_user_transitions(r_tmp);
19197 ++ if (err)
19198 ++ goto cleanup;
19199 ++
19200 ++ memset(r_tmp->subj_hash, 0,
19201 ++ r_tmp->subj_hash_size *
19202 ++ sizeof (struct acl_subject_label *));
19203 ++
19204 ++ err = copy_user_subjs(r_tmp->hash->first, r_tmp);
19205 ++
19206 ++ if (err)
19207 ++ goto cleanup;
19208 ++
19209 ++ /* set nested subject list to null */
19210 ++ r_tmp->hash->first = NULL;
19211 ++
19212 ++ insert_acl_role_label(r_tmp);
19213 ++ }
19214 ++
19215 ++ goto return_err;
19216 ++ cleanup:
19217 ++ free_variables();
19218 ++ return_err:
19219 ++ return err;
19220 ++
19221 ++}
19222 ++
19223 ++static int
19224 ++gracl_init(struct gr_arg *args)
19225 ++{
19226 ++ int error = 0;
19227 ++
19228 ++ memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
19229 ++ memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
19230 ++
19231 ++ if (init_variables(args)) {
19232 ++ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
19233 ++ error = -ENOMEM;
19234 ++ free_variables();
19235 ++ goto out;
19236 ++ }
19237 ++
19238 ++ error = copy_user_acl(args);
19239 ++ free_init_variables();
19240 ++ if (error) {
19241 ++ free_variables();
19242 ++ goto out;
19243 ++ }
19244 ++
19245 ++ if ((error = gr_set_acls(0))) {
19246 ++ free_variables();
19247 ++ goto out;
19248 ++ }
19249 ++
19250 ++ gr_status |= GR_READY;
19251 ++ out:
19252 ++ return error;
19253 ++}
19254 ++
19255 ++/* derived from glibc fnmatch() 0: match, 1: no match*/
19256 ++
19257 ++static int
19258 ++glob_match(const char *p, const char *n)
19259 ++{
19260 ++ char c;
19261 ++
19262 ++ while ((c = *p++) != '\0') {
19263 ++ switch (c) {
19264 ++ case '?':
19265 ++ if (*n == '\0')
19266 ++ return 1;
19267 ++ else if (*n == '/')
19268 ++ return 1;
19269 ++ break;
19270 ++ case '\\':
19271 ++ if (*n != c)
19272 ++ return 1;
19273 ++ break;
19274 ++ case '*':
19275 ++ for (c = *p++; c == '?' || c == '*'; c = *p++) {
19276 ++ if (*n == '/')
19277 ++ return 1;
19278 ++ else if (c == '?') {
19279 ++ if (*n == '\0')
19280 ++ return 1;
19281 ++ else
19282 ++ ++n;
19283 ++ }
19284 ++ }
19285 ++ if (c == '\0') {
19286 ++ return 0;
19287 ++ } else {
19288 ++ const char *endp;
19289 ++
19290 ++ if ((endp = strchr(n, '/')) == NULL)
19291 ++ endp = n + strlen(n);
19292 ++
19293 ++ if (c == '[') {
19294 ++ for (--p; n < endp; ++n)
19295 ++ if (!glob_match(p, n))
19296 ++ return 0;
19297 ++ } else if (c == '/') {
19298 ++ while (*n != '\0' && *n != '/')
19299 ++ ++n;
19300 ++ if (*n == '/' && !glob_match(p, n + 1))
19301 ++ return 0;
19302 ++ } else {
19303 ++ for (--p; n < endp; ++n)
19304 ++ if (*n == c && !glob_match(p, n))
19305 ++ return 0;
19306 ++ }
19307 ++
19308 ++ return 1;
19309 ++ }
19310 ++ case '[':
19311 ++ {
19312 ++ int not;
19313 ++ char cold;
19314 ++
19315 ++ if (*n == '\0' || *n == '/')
19316 ++ return 1;
19317 ++
19318 ++ not = (*p == '!' || *p == '^');
19319 ++ if (not)
19320 ++ ++p;
19321 ++
19322 ++ c = *p++;
19323 ++ for (;;) {
19324 ++ unsigned char fn = (unsigned char)*n;
19325 ++
19326 ++ if (c == '\0')
19327 ++ return 1;
19328 ++ else {
19329 ++ if (c == fn)
19330 ++ goto matched;
19331 ++ cold = c;
19332 ++ c = *p++;
19333 ++
19334 ++ if (c == '-' && *p != ']') {
19335 ++ unsigned char cend = *p++;
19336 ++
19337 ++ if (cend == '\0')
19338 ++ return 1;
19339 ++
19340 ++ if (cold <= fn && fn <= cend)
19341 ++ goto matched;
19342 ++
19343 ++ c = *p++;
19344 ++ }
19345 ++ }
19346 ++
19347 ++ if (c == ']')
19348 ++ break;
19349 ++ }
19350 ++ if (!not)
19351 ++ return 1;
19352 ++ break;
19353 ++ matched:
19354 ++ while (c != ']') {
19355 ++ if (c == '\0')
19356 ++ return 1;
19357 ++
19358 ++ c = *p++;
19359 ++ }
19360 ++ if (not)
19361 ++ return 1;
19362 ++ }
19363 ++ break;
19364 ++ default:
19365 ++ if (c != *n)
19366 ++ return 1;
19367 ++ }
19368 ++
19369 ++ ++n;
19370 ++ }
19371 ++
19372 ++ if (*n == '\0')
19373 ++ return 0;
19374 ++
19375 ++ if (*n == '/')
19376 ++ return 0;
19377 ++
19378 ++ return 1;
19379 ++}
19380 ++
19381 ++static struct acl_object_label *
19382 ++chk_glob_label(struct acl_object_label *globbed,
19383 ++ struct dentry *dentry, struct vfsmount *mnt, char **path)
19384 ++{
19385 ++ struct acl_object_label *tmp;
19386 ++
19387 ++ if (*path == NULL)
19388 ++ *path = gr_to_filename_nolock(dentry, mnt);
19389 ++
19390 ++ tmp = globbed;
19391 ++
19392 ++ while (tmp) {
19393 ++ if (!glob_match(tmp->filename, *path))
19394 ++ return tmp;
19395 ++ tmp = tmp->next;
19396 ++ }
19397 ++
19398 ++ return NULL;
19399 ++}
19400 ++
19401 ++static struct acl_object_label *
19402 ++__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
19403 ++ const ino_t curr_ino, const dev_t curr_dev,
19404 ++ const struct acl_subject_label *subj, char **path)
19405 ++{
19406 ++ struct acl_subject_label *tmpsubj;
19407 ++ struct acl_object_label *retval;
19408 ++ struct acl_object_label *retval2;
19409 ++
19410 ++ tmpsubj = (struct acl_subject_label *) subj;
19411 ++ read_lock(&gr_inode_lock);
19412 ++ do {
19413 ++ retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
19414 ++ if (retval) {
19415 ++ if (retval->globbed) {
19416 ++ retval2 = chk_glob_label(retval->globbed, (struct dentry *)orig_dentry,
19417 ++ (struct vfsmount *)orig_mnt, path);
19418 ++ if (retval2)
19419 ++ retval = retval2;
19420 ++ }
19421 ++ break;
19422 ++ }
19423 ++ } while ((tmpsubj = tmpsubj->parent_subject));
19424 ++ read_unlock(&gr_inode_lock);
19425 ++
19426 ++ return retval;
19427 ++}
19428 ++
19429 ++static __inline__ struct acl_object_label *
19430 ++full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
19431 ++ const struct dentry *curr_dentry,
19432 ++ const struct acl_subject_label *subj, char **path)
19433 ++{
19434 ++ return __full_lookup(orig_dentry, orig_mnt,
19435 ++ curr_dentry->d_inode->i_ino,
19436 ++ curr_dentry->d_inode->i_sb->s_dev, subj, path);
19437 ++}
19438 ++
19439 ++static struct acl_object_label *
19440 ++__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
19441 ++ const struct acl_subject_label *subj, char *path)
19442 ++{
19443 ++ struct dentry *dentry = (struct dentry *) l_dentry;
19444 ++ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
19445 ++ struct acl_object_label *retval;
19446 ++
19447 ++ spin_lock(&dcache_lock);
19448 ++
19449 ++ if (unlikely(mnt == shm_mnt || mnt == pipe_mnt || mnt == sock_mnt ||
19450 ++ /* ignore Eric Biederman */
19451 ++ IS_PRIVATE(l_dentry->d_inode))) {
19452 ++ retval = fakefs_obj;
19453 ++ goto out;
19454 ++ }
19455 ++
19456 ++ for (;;) {
19457 ++ if (dentry == real_root && mnt == real_root_mnt)
19458 ++ break;
19459 ++
19460 ++ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
19461 ++ if (mnt->mnt_parent == mnt)
19462 ++ break;
19463 ++
19464 ++ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path);
19465 ++ if (retval != NULL)
19466 ++ goto out;
19467 ++
19468 ++ dentry = mnt->mnt_mountpoint;
19469 ++ mnt = mnt->mnt_parent;
19470 ++ continue;
19471 ++ }
19472 ++
19473 ++ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path);
19474 ++ if (retval != NULL)
19475 ++ goto out;
19476 ++
19477 ++ dentry = dentry->d_parent;
19478 ++ }
19479 ++
19480 ++ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path);
19481 ++
19482 ++ if (retval == NULL)
19483 ++ retval = full_lookup(l_dentry, l_mnt, real_root, subj, &path);
19484 ++out:
19485 ++ spin_unlock(&dcache_lock);
19486 ++ return retval;
19487 ++}
19488 ++
19489 ++static __inline__ struct acl_object_label *
19490 ++chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
19491 ++ const struct acl_subject_label *subj)
19492 ++{
19493 ++ char *path = NULL;
19494 ++ return __chk_obj_label(l_dentry, l_mnt, subj, path);
19495 ++}
19496 ++
19497 ++static __inline__ struct acl_object_label *
19498 ++chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
19499 ++ const struct acl_subject_label *subj, char *path)
19500 ++{
19501 ++ return __chk_obj_label(l_dentry, l_mnt, subj, path);
19502 ++}
19503 ++
19504 ++static struct acl_subject_label *
19505 ++chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
19506 ++ const struct acl_role_label *role)
19507 ++{
19508 ++ struct dentry *dentry = (struct dentry *) l_dentry;
19509 ++ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
19510 ++ struct acl_subject_label *retval;
19511 ++
19512 ++ spin_lock(&dcache_lock);
19513 ++
19514 ++ for (;;) {
19515 ++ if (dentry == real_root && mnt == real_root_mnt)
19516 ++ break;
19517 ++ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
19518 ++ if (mnt->mnt_parent == mnt)
19519 ++ break;
19520 ++
19521 ++ read_lock(&gr_inode_lock);
19522 ++ retval =
19523 ++ lookup_acl_subj_label(dentry->d_inode->i_ino,
19524 ++ dentry->d_inode->i_sb->s_dev, role);
19525 ++ read_unlock(&gr_inode_lock);
19526 ++ if (retval != NULL)
19527 ++ goto out;
19528 ++
19529 ++ dentry = mnt->mnt_mountpoint;
19530 ++ mnt = mnt->mnt_parent;
19531 ++ continue;
19532 ++ }
19533 ++
19534 ++ read_lock(&gr_inode_lock);
19535 ++ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
19536 ++ dentry->d_inode->i_sb->s_dev, role);
19537 ++ read_unlock(&gr_inode_lock);
19538 ++ if (retval != NULL)
19539 ++ goto out;
19540 ++
19541 ++ dentry = dentry->d_parent;
19542 ++ }
19543 ++
19544 ++ read_lock(&gr_inode_lock);
19545 ++ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
19546 ++ dentry->d_inode->i_sb->s_dev, role);
19547 ++ read_unlock(&gr_inode_lock);
19548 ++
19549 ++ if (unlikely(retval == NULL)) {
19550 ++ read_lock(&gr_inode_lock);
19551 ++ retval = lookup_acl_subj_label(real_root->d_inode->i_ino,
19552 ++ real_root->d_inode->i_sb->s_dev, role);
19553 ++ read_unlock(&gr_inode_lock);
19554 ++ }
19555 ++out:
19556 ++ spin_unlock(&dcache_lock);
19557 ++
19558 ++ return retval;
19559 ++}
19560 ++
19561 ++static void
19562 ++gr_log_learn(const struct task_struct *task, const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
19563 ++{
19564 ++ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
19565 ++ task->uid, task->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
19566 ++ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
19567 ++ 1, 1, gr_to_filename(dentry, mnt), (unsigned long) mode, NIPQUAD(task->signal->curr_ip));
19568 ++
19569 ++ return;
19570 ++}
19571 ++
19572 ++static void
19573 ++gr_log_learn_sysctl(const struct task_struct *task, const char *path, const __u32 mode)
19574 ++{
19575 ++ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
19576 ++ task->uid, task->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
19577 ++ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
19578 ++ 1, 1, path, (unsigned long) mode, NIPQUAD(task->signal->curr_ip));
19579 ++
19580 ++ return;
19581 ++}
19582 ++
19583 ++static void
19584 ++gr_log_learn_id_change(const struct task_struct *task, const char type, const unsigned int real,
19585 ++ const unsigned int effective, const unsigned int fs)
19586 ++{
19587 ++ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
19588 ++ task->uid, task->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
19589 ++ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
19590 ++ type, real, effective, fs, NIPQUAD(task->signal->curr_ip));
19591 ++
19592 ++ return;
19593 ++}
19594 ++
19595 ++__u32
19596 ++gr_check_link(const struct dentry * new_dentry,
19597 ++ const struct dentry * parent_dentry,
19598 ++ const struct vfsmount * parent_mnt,
19599 ++ const struct dentry * old_dentry, const struct vfsmount * old_mnt)
19600 ++{
19601 ++ struct acl_object_label *obj;
19602 ++ __u32 oldmode, newmode;
19603 ++ __u32 needmode;
19604 ++
19605 ++ if (unlikely(!(gr_status & GR_READY)))
19606 ++ return (GR_CREATE | GR_LINK);
19607 ++
19608 ++ obj = chk_obj_label(old_dentry, old_mnt, current->acl);
19609 ++ oldmode = obj->mode;
19610 ++
19611 ++ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
19612 ++ oldmode |= (GR_CREATE | GR_LINK);
19613 ++
19614 ++ needmode = GR_CREATE | GR_AUDIT_CREATE | GR_SUPPRESS;
19615 ++ if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID))
19616 ++ needmode |= GR_SETID | GR_AUDIT_SETID;
19617 ++
19618 ++ newmode =
19619 ++ gr_check_create(new_dentry, parent_dentry, parent_mnt,
19620 ++ oldmode | needmode);
19621 ++
19622 ++ needmode = newmode & (GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC |
19623 ++ GR_SETID | GR_READ | GR_FIND | GR_DELETE |
19624 ++ GR_INHERIT | GR_AUDIT_INHERIT);
19625 ++
19626 ++ if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID) && !(newmode & GR_SETID))
19627 ++ goto bad;
19628 ++
19629 ++ if ((oldmode & needmode) != needmode)
19630 ++ goto bad;
19631 ++
19632 ++ needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
19633 ++ if ((newmode & needmode) != needmode)
19634 ++ goto bad;
19635 ++
19636 ++ if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
19637 ++ return newmode;
19638 ++bad:
19639 ++ needmode = oldmode;
19640 ++ if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID))
19641 ++ needmode |= GR_SETID;
19642 ++
19643 ++ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
19644 ++ gr_log_learn(current, old_dentry, old_mnt, needmode);
19645 ++ return (GR_CREATE | GR_LINK);
19646 ++ } else if (newmode & GR_SUPPRESS)
19647 ++ return GR_SUPPRESS;
19648 ++ else
19649 ++ return 0;
19650 ++}
19651 ++
19652 ++__u32
19653 ++gr_search_file(const struct dentry * dentry, const __u32 mode,
19654 ++ const struct vfsmount * mnt)
19655 ++{
19656 ++ __u32 retval = mode;
19657 ++ struct acl_subject_label *curracl;
19658 ++ struct acl_object_label *currobj;
19659 ++
19660 ++ if (unlikely(!(gr_status & GR_READY)))
19661 ++ return (mode & ~GR_AUDITS);
19662 ++
19663 ++ curracl = current->acl;
19664 ++
19665 ++ currobj = chk_obj_label(dentry, mnt, curracl);
19666 ++ retval = currobj->mode & mode;
19667 ++
19668 ++ if (unlikely
19669 ++ ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
19670 ++ && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
19671 ++ __u32 new_mode = mode;
19672 ++
19673 ++ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
19674 ++
19675 ++ retval = new_mode;
19676 ++
19677 ++ if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
19678 ++ new_mode |= GR_INHERIT;
19679 ++
19680 ++ if (!(mode & GR_NOLEARN))
19681 ++ gr_log_learn(current, dentry, mnt, new_mode);
19682 ++ }
19683 ++
19684 ++ return retval;
19685 ++}
19686 ++
19687 ++__u32
19688 ++gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
19689 ++ const struct vfsmount * mnt, const __u32 mode)
19690 ++{
19691 ++ struct name_entry *match;
19692 ++ struct acl_object_label *matchpo;
19693 ++ struct acl_subject_label *curracl;
19694 ++ char *path;
19695 ++ __u32 retval;
19696 ++
19697 ++ if (unlikely(!(gr_status & GR_READY)))
19698 ++ return (mode & ~GR_AUDITS);
19699 ++
19700 ++ preempt_disable();
19701 ++ path = gr_to_filename_rbac(new_dentry, mnt);
19702 ++ match = lookup_name_entry_create(path);
19703 ++
19704 ++ if (!match)
19705 ++ goto check_parent;
19706 ++
19707 ++ curracl = current->acl;
19708 ++
19709 ++ read_lock(&gr_inode_lock);
19710 ++ matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
19711 ++ read_unlock(&gr_inode_lock);
19712 ++
19713 ++ if (matchpo) {
19714 ++ if ((matchpo->mode & mode) !=
19715 ++ (mode & ~(GR_AUDITS | GR_SUPPRESS))
19716 ++ && curracl->mode & (GR_LEARN | GR_INHERITLEARN)) {
19717 ++ __u32 new_mode = mode;
19718 ++
19719 ++ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
19720 ++
19721 ++ gr_log_learn(current, new_dentry, mnt, new_mode);
19722 ++
19723 ++ preempt_enable();
19724 ++ return new_mode;
19725 ++ }
19726 ++ preempt_enable();
19727 ++ return (matchpo->mode & mode);
19728 ++ }
19729 ++
19730 ++ check_parent:
19731 ++ curracl = current->acl;
19732 ++
19733 ++ matchpo = chk_obj_create_label(parent, mnt, curracl, path);
19734 ++ retval = matchpo->mode & mode;
19735 ++
19736 ++ if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
19737 ++ && (curracl->mode & (GR_LEARN | GR_INHERITLEARN))) {
19738 ++ __u32 new_mode = mode;
19739 ++
19740 ++ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
19741 ++
19742 ++ gr_log_learn(current, new_dentry, mnt, new_mode);
19743 ++ preempt_enable();
19744 ++ return new_mode;
19745 ++ }
19746 ++
19747 ++ preempt_enable();
19748 ++ return retval;
19749 ++}
19750 ++
19751 ++int
19752 ++gr_check_hidden_task(const struct task_struct *task)
19753 ++{
19754 ++ if (unlikely(!(gr_status & GR_READY)))
19755 ++ return 0;
19756 ++
19757 ++ if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
19758 ++ return 1;
19759 ++
19760 ++ return 0;
19761 ++}
19762 ++
19763 ++int
19764 ++gr_check_protected_task(const struct task_struct *task)
19765 ++{
19766 ++ if (unlikely(!(gr_status & GR_READY) || !task))
19767 ++ return 0;
19768 ++
19769 ++ if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
19770 ++ task->acl != current->acl)
19771 ++ return 1;
19772 ++
19773 ++ return 0;
19774 ++}
19775 ++
19776 ++void
19777 ++gr_copy_label(struct task_struct *tsk)
19778 ++{
19779 ++ tsk->signal->used_accept = 0;
19780 ++ tsk->acl_sp_role = 0;
19781 ++ tsk->acl_role_id = current->acl_role_id;
19782 ++ tsk->acl = current->acl;
19783 ++ tsk->role = current->role;
19784 ++ tsk->signal->curr_ip = current->signal->curr_ip;
19785 ++ if (current->exec_file)
19786 ++ get_file(current->exec_file);
19787 ++ tsk->exec_file = current->exec_file;
19788 ++ tsk->is_writable = current->is_writable;
19789 ++ if (unlikely(current->signal->used_accept))
19790 ++ current->signal->curr_ip = 0;
19791 ++
19792 ++ return;
19793 ++}
19794 ++
19795 ++static void
19796 ++gr_set_proc_res(struct task_struct *task)
19797 ++{
19798 ++ struct acl_subject_label *proc;
19799 ++ unsigned short i;
19800 ++
19801 ++ proc = task->acl;
19802 ++
19803 ++ if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
19804 ++ return;
19805 ++
19806 ++ for (i = 0; i < (GR_NLIMITS - 1); i++) {
19807 ++ if (!(proc->resmask & (1 << i)))
19808 ++ continue;
19809 ++
19810 ++ task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
19811 ++ task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
19812 ++ }
19813 ++
19814 ++ return;
19815 ++}
19816 ++
19817 ++int
19818 ++gr_check_user_change(int real, int effective, int fs)
19819 ++{
19820 ++ unsigned int i;
19821 ++ __u16 num;
19822 ++ uid_t *uidlist;
19823 ++ int curuid;
19824 ++ int realok = 0;
19825 ++ int effectiveok = 0;
19826 ++ int fsok = 0;
19827 ++
19828 ++ if (unlikely(!(gr_status & GR_READY)))
19829 ++ return 0;
19830 ++
19831 ++ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
19832 ++ gr_log_learn_id_change(current, 'u', real, effective, fs);
19833 ++
19834 ++ num = current->acl->user_trans_num;
19835 ++ uidlist = current->acl->user_transitions;
19836 ++
19837 ++ if (uidlist == NULL)
19838 ++ return 0;
19839 ++
19840 ++ if (real == -1)
19841 ++ realok = 1;
19842 ++ if (effective == -1)
19843 ++ effectiveok = 1;
19844 ++ if (fs == -1)
19845 ++ fsok = 1;
19846 ++
19847 ++ if (current->acl->user_trans_type & GR_ID_ALLOW) {
19848 ++ for (i = 0; i < num; i++) {
19849 ++ curuid = (int)uidlist[i];
19850 ++ if (real == curuid)
19851 ++ realok = 1;
19852 ++ if (effective == curuid)
19853 ++ effectiveok = 1;
19854 ++ if (fs == curuid)
19855 ++ fsok = 1;
19856 ++ }
19857 ++ } else if (current->acl->user_trans_type & GR_ID_DENY) {
19858 ++ for (i = 0; i < num; i++) {
19859 ++ curuid = (int)uidlist[i];
19860 ++ if (real == curuid)
19861 ++ break;
19862 ++ if (effective == curuid)
19863 ++ break;
19864 ++ if (fs == curuid)
19865 ++ break;
19866 ++ }
19867 ++ /* not in deny list */
19868 ++ if (i == num) {
19869 ++ realok = 1;
19870 ++ effectiveok = 1;
19871 ++ fsok = 1;
19872 ++ }
19873 ++ }
19874 ++
19875 ++ if (realok && effectiveok && fsok)
19876 ++ return 0;
19877 ++ else {
19878 ++ gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
19879 ++ return 1;
19880 ++ }
19881 ++}
19882 ++
19883 ++int
19884 ++gr_check_group_change(int real, int effective, int fs)
19885 ++{
19886 ++ unsigned int i;
19887 ++ __u16 num;
19888 ++ gid_t *gidlist;
19889 ++ int curgid;
19890 ++ int realok = 0;
19891 ++ int effectiveok = 0;
19892 ++ int fsok = 0;
19893 ++
19894 ++ if (unlikely(!(gr_status & GR_READY)))
19895 ++ return 0;
19896 ++
19897 ++ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
19898 ++ gr_log_learn_id_change(current, 'g', real, effective, fs);
19899 ++
19900 ++ num = current->acl->group_trans_num;
19901 ++ gidlist = current->acl->group_transitions;
19902 ++
19903 ++ if (gidlist == NULL)
19904 ++ return 0;
19905 ++
19906 ++ if (real == -1)
19907 ++ realok = 1;
19908 ++ if (effective == -1)
19909 ++ effectiveok = 1;
19910 ++ if (fs == -1)
19911 ++ fsok = 1;
19912 ++
19913 ++ if (current->acl->group_trans_type & GR_ID_ALLOW) {
19914 ++ for (i = 0; i < num; i++) {
19915 ++ curgid = (int)gidlist[i];
19916 ++ if (real == curgid)
19917 ++ realok = 1;
19918 ++ if (effective == curgid)
19919 ++ effectiveok = 1;
19920 ++ if (fs == curgid)
19921 ++ fsok = 1;
19922 ++ }
19923 ++ } else if (current->acl->group_trans_type & GR_ID_DENY) {
19924 ++ for (i = 0; i < num; i++) {
19925 ++ curgid = (int)gidlist[i];
19926 ++ if (real == curgid)
19927 ++ break;
19928 ++ if (effective == curgid)
19929 ++ break;
19930 ++ if (fs == curgid)
19931 ++ break;
19932 ++ }
19933 ++ /* not in deny list */
19934 ++ if (i == num) {
19935 ++ realok = 1;
19936 ++ effectiveok = 1;
19937 ++ fsok = 1;
19938 ++ }
19939 ++ }
19940 ++
19941 ++ if (realok && effectiveok && fsok)
19942 ++ return 0;
19943 ++ else {
19944 ++ gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
19945 ++ return 1;
19946 ++ }
19947 ++}
19948 ++
19949 ++void
19950 ++gr_set_role_label(struct task_struct *task, const uid_t uid, const uid_t gid)
19951 ++{
19952 ++ struct acl_role_label *role = task->role;
19953 ++ struct acl_subject_label *subj = NULL;
19954 ++ struct acl_object_label *obj;
19955 ++ struct file *filp;
19956 ++
19957 ++ if (unlikely(!(gr_status & GR_READY)))
19958 ++ return;
19959 ++
19960 ++ filp = task->exec_file;
19961 ++
19962 ++ /* kernel process, we'll give them the kernel role */
19963 ++ if (unlikely(!filp)) {
19964 ++ task->role = kernel_role;
19965 ++ task->acl = kernel_role->root_label;
19966 ++ return;
19967 ++ } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
19968 ++ role = lookup_acl_role_label(task, uid, gid);
19969 ++
19970 ++ /* perform subject lookup in possibly new role
19971 ++ we can use this result below in the case where role == task->role
19972 ++ */
19973 ++ subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
19974 ++
19975 ++ /* if we changed uid/gid, but result in the same role
19976 ++ and are using inheritance, don't lose the inherited subject
19977 ++ if current subject is other than what normal lookup
19978 ++ would result in, we arrived via inheritance, don't
19979 ++ lose subject
19980 ++ */
19981 ++ if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
19982 ++ (subj == task->acl)))
19983 ++ task->acl = subj;
19984 ++
19985 ++ task->role = role;
19986 ++
19987 ++ task->is_writable = 0;
19988 ++
19989 ++ /* ignore additional mmap checks for processes that are writable
19990 ++ by the default ACL */
19991 ++ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
19992 ++ if (unlikely(obj->mode & GR_WRITE))
19993 ++ task->is_writable = 1;
19994 ++ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
19995 ++ if (unlikely(obj->mode & GR_WRITE))
19996 ++ task->is_writable = 1;
19997 ++
19998 ++#ifdef CONFIG_GRKERNSEC_ACL_DEBUG
19999 ++ printk(KERN_ALERT "Set role label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
20000 ++#endif
20001 ++
20002 ++ gr_set_proc_res(task);
20003 ++
20004 ++ return;
20005 ++}
20006 ++
20007 ++int
20008 ++gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt)
20009 ++{
20010 ++ struct task_struct *task = current;
20011 ++ struct acl_subject_label *newacl;
20012 ++ struct acl_object_label *obj;
20013 ++ __u32 retmode;
20014 ++
20015 ++ if (unlikely(!(gr_status & GR_READY)))
20016 ++ return 0;
20017 ++
20018 ++ newacl = chk_subj_label(dentry, mnt, task->role);
20019 ++
20020 ++ task_lock(task);
20021 ++ if (((task->ptrace & PT_PTRACED) && !(task->acl->mode &
20022 ++ GR_POVERRIDE) && (task->acl != newacl) &&
20023 ++ !(task->role->roletype & GR_ROLE_GOD) &&
20024 ++ !gr_search_file(dentry, GR_PTRACERD, mnt) &&
20025 ++ !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) ||
20026 ++ (atomic_read(&task->fs->count) > 1 ||
20027 ++ atomic_read(&task->files->count) > 1 ||
20028 ++ atomic_read(&task->sighand->count) > 1)) {
20029 ++ task_unlock(task);
20030 ++ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
20031 ++ return -EACCES;
20032 ++ }
20033 ++ task_unlock(task);
20034 ++
20035 ++ obj = chk_obj_label(dentry, mnt, task->acl);
20036 ++ retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
20037 ++
20038 ++ if (!(task->acl->mode & GR_INHERITLEARN) &&
20039 ++ ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
20040 ++ if (obj->nested)
20041 ++ task->acl = obj->nested;
20042 ++ else
20043 ++ task->acl = newacl;
20044 ++ } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
20045 ++ gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
20046 ++
20047 ++ task->is_writable = 0;
20048 ++
20049 ++ /* ignore additional mmap checks for processes that are writable
20050 ++ by the default ACL */
20051 ++ obj = chk_obj_label(dentry, mnt, default_role->root_label);
20052 ++ if (unlikely(obj->mode & GR_WRITE))
20053 ++ task->is_writable = 1;
20054 ++ obj = chk_obj_label(dentry, mnt, task->role->root_label);
20055 ++ if (unlikely(obj->mode & GR_WRITE))
20056 ++ task->is_writable = 1;
20057 ++
20058 ++ gr_set_proc_res(task);
20059 ++
20060 ++#ifdef CONFIG_GRKERNSEC_ACL_DEBUG
20061 ++ printk(KERN_ALERT "Set subject label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
20062 ++#endif
20063 ++ return 0;
20064 ++}
20065 ++
20066 ++/* always called with valid inodev ptr */
20067 ++static void
20068 ++do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
20069 ++{
20070 ++ struct acl_object_label *matchpo;
20071 ++ struct acl_subject_label *matchps;
20072 ++ struct acl_subject_label *subj;
20073 ++ struct acl_role_label *role;
20074 ++ unsigned int i, x;
20075 ++
20076 ++ FOR_EACH_ROLE_START(role, i)
20077 ++ FOR_EACH_SUBJECT_START(role, subj, x)
20078 ++ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
20079 ++ matchpo->mode |= GR_DELETED;
20080 ++ FOR_EACH_SUBJECT_END(subj,x)
20081 ++ FOR_EACH_NESTED_SUBJECT_START(role, subj)
20082 ++ if (subj->inode == ino && subj->device == dev)
20083 ++ subj->mode |= GR_DELETED;
20084 ++ FOR_EACH_NESTED_SUBJECT_END(subj)
20085 ++ if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
20086 ++ matchps->mode |= GR_DELETED;
20087 ++ FOR_EACH_ROLE_END(role,i)
20088 ++
20089 ++ inodev->nentry->deleted = 1;
20090 ++
20091 ++ return;
20092 ++}
20093 ++
20094 ++void
20095 ++gr_handle_delete(const ino_t ino, const dev_t dev)
20096 ++{
20097 ++ struct inodev_entry *inodev;
20098 ++
20099 ++ if (unlikely(!(gr_status & GR_READY)))
20100 ++ return;
20101 ++
20102 ++ write_lock(&gr_inode_lock);
20103 ++ inodev = lookup_inodev_entry(ino, dev);
20104 ++ if (inodev != NULL)
20105 ++ do_handle_delete(inodev, ino, dev);
20106 ++ write_unlock(&gr_inode_lock);
20107 ++
20108 ++ return;
20109 ++}
20110 ++
20111 ++static void
20112 ++update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
20113 ++ const ino_t newinode, const dev_t newdevice,
20114 ++ struct acl_subject_label *subj)
20115 ++{
20116 ++ unsigned int index = fhash(oldinode, olddevice, subj->obj_hash_size);
20117 ++ struct acl_object_label *match;
20118 ++
20119 ++ match = subj->obj_hash[index];
20120 ++
20121 ++ while (match && (match->inode != oldinode ||
20122 ++ match->device != olddevice ||
20123 ++ !(match->mode & GR_DELETED)))
20124 ++ match = match->next;
20125 ++
20126 ++ if (match && (match->inode == oldinode)
20127 ++ && (match->device == olddevice)
20128 ++ && (match->mode & GR_DELETED)) {
20129 ++ if (match->prev == NULL) {
20130 ++ subj->obj_hash[index] = match->next;
20131 ++ if (match->next != NULL)
20132 ++ match->next->prev = NULL;
20133 ++ } else {
20134 ++ match->prev->next = match->next;
20135 ++ if (match->next != NULL)
20136 ++ match->next->prev = match->prev;
20137 ++ }
20138 ++ match->prev = NULL;
20139 ++ match->next = NULL;
20140 ++ match->inode = newinode;
20141 ++ match->device = newdevice;
20142 ++ match->mode &= ~GR_DELETED;
20143 ++
20144 ++ insert_acl_obj_label(match, subj);
20145 ++ }
20146 ++
20147 ++ return;
20148 ++}
20149 ++
20150 ++static void
20151 ++update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
20152 ++ const ino_t newinode, const dev_t newdevice,
20153 ++ struct acl_role_label *role)
20154 ++{
20155 ++ unsigned int index = fhash(oldinode, olddevice, role->subj_hash_size);
20156 ++ struct acl_subject_label *match;
20157 ++
20158 ++ match = role->subj_hash[index];
20159 ++
20160 ++ while (match && (match->inode != oldinode ||
20161 ++ match->device != olddevice ||
20162 ++ !(match->mode & GR_DELETED)))
20163 ++ match = match->next;
20164 ++
20165 ++ if (match && (match->inode == oldinode)
20166 ++ && (match->device == olddevice)
20167 ++ && (match->mode & GR_DELETED)) {
20168 ++ if (match->prev == NULL) {
20169 ++ role->subj_hash[index] = match->next;
20170 ++ if (match->next != NULL)
20171 ++ match->next->prev = NULL;
20172 ++ } else {
20173 ++ match->prev->next = match->next;
20174 ++ if (match->next != NULL)
20175 ++ match->next->prev = match->prev;
20176 ++ }
20177 ++ match->prev = NULL;
20178 ++ match->next = NULL;
20179 ++ match->inode = newinode;
20180 ++ match->device = newdevice;
20181 ++ match->mode &= ~GR_DELETED;
20182 ++
20183 ++ insert_acl_subj_label(match, role);
20184 ++ }
20185 ++
20186 ++ return;
20187 ++}
20188 ++
20189 ++static void
20190 ++update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
20191 ++ const ino_t newinode, const dev_t newdevice)
20192 ++{
20193 ++ unsigned int index = fhash(oldinode, olddevice, inodev_set.i_size);
20194 ++ struct inodev_entry *match;
20195 ++
20196 ++ match = inodev_set.i_hash[index];
20197 ++
20198 ++ while (match && (match->nentry->inode != oldinode ||
20199 ++ match->nentry->device != olddevice || !match->nentry->deleted))
20200 ++ match = match->next;
20201 ++
20202 ++ if (match && (match->nentry->inode == oldinode)
20203 ++ && (match->nentry->device == olddevice) &&
20204 ++ match->nentry->deleted) {
20205 ++ if (match->prev == NULL) {
20206 ++ inodev_set.i_hash[index] = match->next;
20207 ++ if (match->next != NULL)
20208 ++ match->next->prev = NULL;
20209 ++ } else {
20210 ++ match->prev->next = match->next;
20211 ++ if (match->next != NULL)
20212 ++ match->next->prev = match->prev;
20213 ++ }
20214 ++ match->prev = NULL;
20215 ++ match->next = NULL;
20216 ++ match->nentry->inode = newinode;
20217 ++ match->nentry->device = newdevice;
20218 ++ match->nentry->deleted = 0;
20219 ++
20220 ++ insert_inodev_entry(match);
20221 ++ }
20222 ++
20223 ++ return;
20224 ++}
20225 ++
20226 ++static void
20227 ++do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
20228 ++ const struct vfsmount *mnt)
20229 ++{
20230 ++ struct acl_subject_label *subj;
20231 ++ struct acl_role_label *role;
20232 ++ unsigned int i, x;
20233 ++
20234 ++ FOR_EACH_ROLE_START(role, i)
20235 ++ update_acl_subj_label(matchn->inode, matchn->device,
20236 ++ dentry->d_inode->i_ino,
20237 ++ dentry->d_inode->i_sb->s_dev, role);
20238 ++
20239 ++ FOR_EACH_NESTED_SUBJECT_START(role, subj)
20240 ++ if ((subj->inode == dentry->d_inode->i_ino) &&
20241 ++ (subj->device == dentry->d_inode->i_sb->s_dev)) {
20242 ++ subj->inode = dentry->d_inode->i_ino;
20243 ++ subj->device = dentry->d_inode->i_sb->s_dev;
20244 ++ }
20245 ++ FOR_EACH_NESTED_SUBJECT_END(subj)
20246 ++ FOR_EACH_SUBJECT_START(role, subj, x)
20247 ++ update_acl_obj_label(matchn->inode, matchn->device,
20248 ++ dentry->d_inode->i_ino,
20249 ++ dentry->d_inode->i_sb->s_dev, subj);
20250 ++ FOR_EACH_SUBJECT_END(subj,x)
20251 ++ FOR_EACH_ROLE_END(role,i)
20252 ++
20253 ++ update_inodev_entry(matchn->inode, matchn->device,
20254 ++ dentry->d_inode->i_ino, dentry->d_inode->i_sb->s_dev);
20255 ++
20256 ++ return;
20257 ++}
20258 ++
20259 ++void
20260 ++gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
20261 ++{
20262 ++ struct name_entry *matchn;
20263 ++
20264 ++ if (unlikely(!(gr_status & GR_READY)))
20265 ++ return;
20266 ++
20267 ++ preempt_disable();
20268 ++ matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
20269 ++
20270 ++ if (unlikely((unsigned long)matchn)) {
20271 ++ write_lock(&gr_inode_lock);
20272 ++ do_handle_create(matchn, dentry, mnt);
20273 ++ write_unlock(&gr_inode_lock);
20274 ++ }
20275 ++ preempt_enable();
20276 ++
20277 ++ return;
20278 ++}
20279 ++
20280 ++void
20281 ++gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
20282 ++ struct dentry *old_dentry,
20283 ++ struct dentry *new_dentry,
20284 ++ struct vfsmount *mnt, const __u8 replace)
20285 ++{
20286 ++ struct name_entry *matchn;
20287 ++ struct inodev_entry *inodev;
20288 ++
20289 ++ /* vfs_rename swaps the name and parent link for old_dentry and
20290 ++ new_dentry
20291 ++ at this point, old_dentry has the new name, parent link, and inode
20292 ++ for the renamed file
20293 ++ if a file is being replaced by a rename, new_dentry has the inode
20294 ++ and name for the replaced file
20295 ++ */
20296 ++
20297 ++ if (unlikely(!(gr_status & GR_READY)))
20298 ++ return;
20299 ++
20300 ++ preempt_disable();
20301 ++ matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
20302 ++
20303 ++ /* we wouldn't have to check d_inode if it weren't for
20304 ++ NFS silly-renaming
20305 ++ */
20306 ++
20307 ++ write_lock(&gr_inode_lock);
20308 ++ if (unlikely(replace && new_dentry->d_inode)) {
20309 ++ inodev = lookup_inodev_entry(new_dentry->d_inode->i_ino,
20310 ++ new_dentry->d_inode->i_sb->s_dev);
20311 ++ if (inodev != NULL && (new_dentry->d_inode->i_nlink <= 1))
20312 ++ do_handle_delete(inodev, new_dentry->d_inode->i_ino,
20313 ++ new_dentry->d_inode->i_sb->s_dev);
20314 ++ }
20315 ++
20316 ++ inodev = lookup_inodev_entry(old_dentry->d_inode->i_ino,
20317 ++ old_dentry->d_inode->i_sb->s_dev);
20318 ++ if (inodev != NULL && (old_dentry->d_inode->i_nlink <= 1))
20319 ++ do_handle_delete(inodev, old_dentry->d_inode->i_ino,
20320 ++ old_dentry->d_inode->i_sb->s_dev);
20321 ++
20322 ++ if (unlikely((unsigned long)matchn))
20323 ++ do_handle_create(matchn, old_dentry, mnt);
20324 ++
20325 ++ write_unlock(&gr_inode_lock);
20326 ++ preempt_enable();
20327 ++
20328 ++ return;
20329 ++}
20330 ++
20331 ++static int
20332 ++lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
20333 ++ unsigned char **sum)
20334 ++{
20335 ++ struct acl_role_label *r;
20336 ++ struct role_allowed_ip *ipp;
20337 ++ struct role_transition *trans;
20338 ++ unsigned int i;
20339 ++ int found = 0;
20340 ++
20341 ++ /* check transition table */
20342 ++
20343 ++ for (trans = current->role->transitions; trans; trans = trans->next) {
20344 ++ if (!strcmp(rolename, trans->rolename)) {
20345 ++ found = 1;
20346 ++ break;
20347 ++ }
20348 ++ }
20349 ++
20350 ++ if (!found)
20351 ++ return 0;
20352 ++
20353 ++ /* handle special roles that do not require authentication
20354 ++ and check ip */
20355 ++
20356 ++ FOR_EACH_ROLE_START(r, i)
20357 ++ if (!strcmp(rolename, r->rolename) &&
20358 ++ (r->roletype & GR_ROLE_SPECIAL)) {
20359 ++ found = 0;
20360 ++ if (r->allowed_ips != NULL) {
20361 ++ for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
20362 ++ if ((ntohl(current->signal->curr_ip) & ipp->netmask) ==
20363 ++ (ntohl(ipp->addr) & ipp->netmask))
20364 ++ found = 1;
20365 ++ }
20366 ++ } else
20367 ++ found = 2;
20368 ++ if (!found)
20369 ++ return 0;
20370 ++
20371 ++ if (((mode == SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
20372 ++ ((mode == SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
20373 ++ *salt = NULL;
20374 ++ *sum = NULL;
20375 ++ return 1;
20376 ++ }
20377 ++ }
20378 ++ FOR_EACH_ROLE_END(r,i)
20379 ++
20380 ++ for (i = 0; i < num_sprole_pws; i++) {
20381 ++ if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
20382 ++ *salt = acl_special_roles[i]->salt;
20383 ++ *sum = acl_special_roles[i]->sum;
20384 ++ return 1;
20385 ++ }
20386 ++ }
20387 ++
20388 ++ return 0;
20389 ++}
20390 ++
20391 ++static void
20392 ++assign_special_role(char *rolename)
20393 ++{
20394 ++ struct acl_object_label *obj;
20395 ++ struct acl_role_label *r;
20396 ++ struct acl_role_label *assigned = NULL;
20397 ++ struct task_struct *tsk;
20398 ++ struct file *filp;
20399 ++ unsigned int i;
20400 ++
20401 ++ FOR_EACH_ROLE_START(r, i)
20402 ++ if (!strcmp(rolename, r->rolename) &&
20403 ++ (r->roletype & GR_ROLE_SPECIAL))
20404 ++ assigned = r;
20405 ++ FOR_EACH_ROLE_END(r,i)
20406 ++
20407 ++ if (!assigned)
20408 ++ return;
20409 ++
20410 ++ read_lock(&tasklist_lock);
20411 ++ read_lock(&grsec_exec_file_lock);
20412 ++
20413 ++ tsk = current->parent;
20414 ++ if (tsk == NULL)
20415 ++ goto out_unlock;
20416 ++
20417 ++ filp = tsk->exec_file;
20418 ++ if (filp == NULL)
20419 ++ goto out_unlock;
20420 ++
20421 ++ tsk->is_writable = 0;
20422 ++
20423 ++ tsk->acl_sp_role = 1;
20424 ++ tsk->acl_role_id = ++acl_sp_role_value;
20425 ++ tsk->role = assigned;
20426 ++ tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
20427 ++
20428 ++ /* ignore additional mmap checks for processes that are writable
20429 ++ by the default ACL */
20430 ++ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
20431 ++ if (unlikely(obj->mode & GR_WRITE))
20432 ++ tsk->is_writable = 1;
20433 ++ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
20434 ++ if (unlikely(obj->mode & GR_WRITE))
20435 ++ tsk->is_writable = 1;
20436 ++
20437 ++#ifdef CONFIG_GRKERNSEC_ACL_DEBUG
20438 ++ printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename, tsk->acl->filename, tsk->comm, tsk->pid);
20439 ++#endif
20440 ++
20441 ++out_unlock:
20442 ++ read_unlock(&grsec_exec_file_lock);
20443 ++ read_unlock(&tasklist_lock);
20444 ++ return;
20445 ++}
20446 ++
20447 ++int gr_check_secure_terminal(struct task_struct *task)
20448 ++{
20449 ++ struct task_struct *p, *p2, *p3;
20450 ++ struct files_struct *files;
20451 ++ struct fdtable *fdt;
20452 ++ struct file *our_file = NULL, *file;
20453 ++ int i;
20454 ++
20455 ++ if (task->signal->tty == NULL)
20456 ++ return 1;
20457 ++
20458 ++ files = get_files_struct(task);
20459 ++ if (files != NULL) {
20460 ++ rcu_read_lock();
20461 ++ fdt = files_fdtable(files);
20462 ++ for (i=0; i < fdt->max_fds; i++) {
20463 ++ file = fcheck_files(files, i);
20464 ++ if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
20465 ++ get_file(file);
20466 ++ our_file = file;
20467 ++ }
20468 ++ }
20469 ++ rcu_read_unlock();
20470 ++ put_files_struct(files);
20471 ++ }
20472 ++
20473 ++ if (our_file == NULL)
20474 ++ return 1;
20475 ++
20476 ++ read_lock(&tasklist_lock);
20477 ++ do_each_thread(p2, p) {
20478 ++ files = get_files_struct(p);
20479 ++ if (files == NULL ||
20480 ++ (p->signal && p->signal->tty == task->signal->tty)) {
20481 ++ if (files != NULL)
20482 ++ put_files_struct(files);
20483 ++ continue;
20484 ++ }
20485 ++ rcu_read_lock();
20486 ++ fdt = files_fdtable(files);
20487 ++ for (i=0; i < fdt->max_fds; i++) {
20488 ++ file = fcheck_files(files, i);
20489 ++ if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
20490 ++ file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
20491 ++ p3 = task;
20492 ++ while (p3->pid > 0) {
20493 ++ if (p3 == p)
20494 ++ break;
20495 ++ p3 = p3->parent;
20496 ++ }
20497 ++ if (p3 == p)
20498 ++ break;
20499 ++ gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
20500 ++ gr_handle_alertkill(p);
20501 ++ rcu_read_unlock();
20502 ++ put_files_struct(files);
20503 ++ read_unlock(&tasklist_lock);
20504 ++ fput(our_file);
20505 ++ return 0;
20506 ++ }
20507 ++ }
20508 ++ rcu_read_unlock();
20509 ++ put_files_struct(files);
20510 ++ } while_each_thread(p2, p);
20511 ++ read_unlock(&tasklist_lock);
20512 ++
20513 ++ fput(our_file);
20514 ++ return 1;
20515 ++}
20516 ++
20517 ++ssize_t
20518 ++write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
20519 ++{
20520 ++ struct gr_arg_wrapper uwrap;
20521 ++ unsigned char *sprole_salt;
20522 ++ unsigned char *sprole_sum;
20523 ++ int error = sizeof (struct gr_arg_wrapper);
20524 ++ int error2 = 0;
20525 ++
20526 ++ down(&gr_dev_sem);
20527 ++
20528 ++ if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
20529 ++ error = -EPERM;
20530 ++ goto out;
20531 ++ }
20532 ++
20533 ++ if (count != sizeof (struct gr_arg_wrapper)) {
20534 ++ gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
20535 ++ error = -EINVAL;
20536 ++ goto out;
20537 ++ }
20538 ++
20539 ++
20540 ++ if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
20541 ++ gr_auth_expires = 0;
20542 ++ gr_auth_attempts = 0;
20543 ++ }
20544 ++
20545 ++ if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
20546 ++ error = -EFAULT;
20547 ++ goto out;
20548 ++ }
20549 ++
20550 ++ if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
20551 ++ error = -EINVAL;
20552 ++ goto out;
20553 ++ }
20554 ++
20555 ++ if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
20556 ++ error = -EFAULT;
20557 ++ goto out;
20558 ++ }
20559 ++
20560 ++ if (gr_usermode->mode != SPROLE && gr_usermode->mode != SPROLEPAM &&
20561 ++ gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
20562 ++ time_after(gr_auth_expires, get_seconds())) {
20563 ++ error = -EBUSY;
20564 ++ goto out;
20565 ++ }
20566 ++
20567 ++ /* if non-root trying to do anything other than use a special role,
20568 ++ do not attempt authentication, do not count towards authentication
20569 ++ locking
20570 ++ */
20571 ++
20572 ++ if (gr_usermode->mode != SPROLE && gr_usermode->mode != STATUS &&
20573 ++ gr_usermode->mode != UNSPROLE && gr_usermode->mode != SPROLEPAM &&
20574 ++ current->uid) {
20575 ++ error = -EPERM;
20576 ++ goto out;
20577 ++ }
20578 ++
20579 ++ /* ensure pw and special role name are null terminated */
20580 ++
20581 ++ gr_usermode->pw[GR_PW_LEN - 1] = '\0';
20582 ++ gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
20583 ++
20584 ++ /* Okay.
20585 ++ * We have our enough of the argument structure..(we have yet
20586 ++ * to copy_from_user the tables themselves) . Copy the tables
20587 ++ * only if we need them, i.e. for loading operations. */
20588 ++
20589 ++ switch (gr_usermode->mode) {
20590 ++ case STATUS:
20591 ++ if (gr_status & GR_READY) {
20592 ++ error = 1;
20593 ++ if (!gr_check_secure_terminal(current))
20594 ++ error = 3;
20595 ++ } else
20596 ++ error = 2;
20597 ++ goto out;
20598 ++ case SHUTDOWN:
20599 ++ if ((gr_status & GR_READY)
20600 ++ && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
20601 ++ gr_status &= ~GR_READY;
20602 ++ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
20603 ++ free_variables();
20604 ++ memset(gr_usermode, 0, sizeof (struct gr_arg));
20605 ++ memset(gr_system_salt, 0, GR_SALT_LEN);
20606 ++ memset(gr_system_sum, 0, GR_SHA_LEN);
20607 ++ } else if (gr_status & GR_READY) {
20608 ++ gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
20609 ++ error = -EPERM;
20610 ++ } else {
20611 ++ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
20612 ++ error = -EAGAIN;
20613 ++ }
20614 ++ break;
20615 ++ case ENABLE:
20616 ++ if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
20617 ++ gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
20618 ++ else {
20619 ++ if (gr_status & GR_READY)
20620 ++ error = -EAGAIN;
20621 ++ else
20622 ++ error = error2;
20623 ++ gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
20624 ++ }
20625 ++ break;
20626 ++ case RELOAD:
20627 ++ if (!(gr_status & GR_READY)) {
20628 ++ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
20629 ++ error = -EAGAIN;
20630 ++ } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
20631 ++ lock_kernel();
20632 ++ gr_status &= ~GR_READY;
20633 ++ free_variables();
20634 ++ if (!(error2 = gracl_init(gr_usermode))) {
20635 ++ unlock_kernel();
20636 ++ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
20637 ++ } else {
20638 ++ unlock_kernel();
20639 ++ error = error2;
20640 ++ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
20641 ++ }
20642 ++ } else {
20643 ++ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
20644 ++ error = -EPERM;
20645 ++ }
20646 ++ break;
20647 ++ case SEGVMOD:
20648 ++ if (unlikely(!(gr_status & GR_READY))) {
20649 ++ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
20650 ++ error = -EAGAIN;
20651 ++ break;
20652 ++ }
20653 ++
20654 ++ if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
20655 ++ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
20656 ++ if (gr_usermode->segv_device && gr_usermode->segv_inode) {
20657 ++ struct acl_subject_label *segvacl;
20658 ++ segvacl =
20659 ++ lookup_acl_subj_label(gr_usermode->segv_inode,
20660 ++ gr_usermode->segv_device,
20661 ++ current->role);
20662 ++ if (segvacl) {
20663 ++ segvacl->crashes = 0;
20664 ++ segvacl->expires = 0;
20665 ++ }
20666 ++ } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
20667 ++ gr_remove_uid(gr_usermode->segv_uid);
20668 ++ }
20669 ++ } else {
20670 ++ gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
20671 ++ error = -EPERM;
20672 ++ }
20673 ++ break;
20674 ++ case SPROLE:
20675 ++ case SPROLEPAM:
20676 ++ if (unlikely(!(gr_status & GR_READY))) {
20677 ++ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
20678 ++ error = -EAGAIN;
20679 ++ break;
20680 ++ }
20681 ++
20682 ++ if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
20683 ++ current->role->expires = 0;
20684 ++ current->role->auth_attempts = 0;
20685 ++ }
20686 ++
20687 ++ if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
20688 ++ time_after(current->role->expires, get_seconds())) {
20689 ++ error = -EBUSY;
20690 ++ goto out;
20691 ++ }
20692 ++
20693 ++ if (lookup_special_role_auth
20694 ++ (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
20695 ++ && ((!sprole_salt && !sprole_sum)
20696 ++ || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
20697 ++ char *p = "";
20698 ++ assign_special_role(gr_usermode->sp_role);
20699 ++ read_lock(&tasklist_lock);
20700 ++ if (current->parent)
20701 ++ p = current->parent->role->rolename;
20702 ++ read_unlock(&tasklist_lock);
20703 ++ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
20704 ++ p, acl_sp_role_value);
20705 ++ } else {
20706 ++ gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
20707 ++ error = -EPERM;
20708 ++ if(!(current->role->auth_attempts++))
20709 ++ current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
20710 ++
20711 ++ goto out;
20712 ++ }
20713 ++ break;
20714 ++ case UNSPROLE:
20715 ++ if (unlikely(!(gr_status & GR_READY))) {
20716 ++ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
20717 ++ error = -EAGAIN;
20718 ++ break;
20719 ++ }
20720 ++
20721 ++ if (current->role->roletype & GR_ROLE_SPECIAL) {
20722 ++ char *p = "";
20723 ++ int i = 0;
20724 ++
20725 ++ read_lock(&tasklist_lock);
20726 ++ if (current->parent) {
20727 ++ p = current->parent->role->rolename;
20728 ++ i = current->parent->acl_role_id;
20729 ++ }
20730 ++ read_unlock(&tasklist_lock);
20731 ++
20732 ++ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
20733 ++ gr_set_acls(1);
20734 ++ } else {
20735 ++ gr_log_str(GR_DONT_AUDIT, GR_UNSPROLEF_ACL_MSG, current->role->rolename);
20736 ++ error = -EPERM;
20737 ++ goto out;
20738 ++ }
20739 ++ break;
20740 ++ default:
20741 ++ gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
20742 ++ error = -EINVAL;
20743 ++ break;
20744 ++ }
20745 ++
20746 ++ if (error != -EPERM)
20747 ++ goto out;
20748 ++
20749 ++ if(!(gr_auth_attempts++))
20750 ++ gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
20751 ++
20752 ++ out:
20753 ++ up(&gr_dev_sem);
20754 ++ return error;
20755 ++}
20756 ++
20757 ++int
20758 ++gr_set_acls(const int type)
20759 ++{
20760 ++ struct acl_object_label *obj;
20761 ++ struct task_struct *task, *task2;
20762 ++ struct file *filp;
20763 ++ struct acl_role_label *role = current->role;
20764 ++ __u16 acl_role_id = current->acl_role_id;
20765 ++
20766 ++ read_lock(&tasklist_lock);
20767 ++ read_lock(&grsec_exec_file_lock);
20768 ++ do_each_thread(task2, task) {
20769 ++ /* check to see if we're called from the exit handler,
20770 ++ if so, only replace ACLs that have inherited the admin
20771 ++ ACL */
20772 ++
20773 ++ if (type && (task->role != role ||
20774 ++ task->acl_role_id != acl_role_id))
20775 ++ continue;
20776 ++
20777 ++ task->acl_role_id = 0;
20778 ++ task->acl_sp_role = 0;
20779 ++
20780 ++ if ((filp = task->exec_file)) {
20781 ++ task->role = lookup_acl_role_label(task, task->uid, task->gid);
20782 ++
20783 ++ task->acl =
20784 ++ chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
20785 ++ task->role);
20786 ++ if (task->acl) {
20787 ++ struct acl_subject_label *curr;
20788 ++ curr = task->acl;
20789 ++
20790 ++ task->is_writable = 0;
20791 ++ /* ignore additional mmap checks for processes that are writable
20792 ++ by the default ACL */
20793 ++ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
20794 ++ if (unlikely(obj->mode & GR_WRITE))
20795 ++ task->is_writable = 1;
20796 ++ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
20797 ++ if (unlikely(obj->mode & GR_WRITE))
20798 ++ task->is_writable = 1;
20799 ++
20800 ++ gr_set_proc_res(task);
20801 ++
20802 ++#ifdef CONFIG_GRKERNSEC_ACL_DEBUG
20803 ++ printk(KERN_ALERT "gr_set_acls for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
20804 ++#endif
20805 ++ } else {
20806 ++ read_unlock(&grsec_exec_file_lock);
20807 ++ read_unlock(&tasklist_lock);
20808 ++ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task->pid);
20809 ++ return 1;
20810 ++ }
20811 ++ } else {
20812 ++ // it's a kernel process
20813 ++ task->role = kernel_role;
20814 ++ task->acl = kernel_role->root_label;
20815 ++#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
20816 ++ task->acl->mode &= ~GR_PROCFIND;
20817 ++#endif
20818 ++ }
20819 ++ } while_each_thread(task2, task);
20820 ++ read_unlock(&grsec_exec_file_lock);
20821 ++ read_unlock(&tasklist_lock);
20822 ++ return 0;
20823 ++}
20824 ++
20825 ++void
20826 ++gr_learn_resource(const struct task_struct *task,
20827 ++ const int res, const unsigned long wanted, const int gt)
20828 ++{
20829 ++ struct acl_subject_label *acl;
20830 ++
20831 ++ if (unlikely((gr_status & GR_READY) &&
20832 ++ task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
20833 ++ goto skip_reslog;
20834 ++
20835 ++#ifdef CONFIG_GRKERNSEC_RESLOG
20836 ++ gr_log_resource(task, res, wanted, gt);
20837 ++#endif
20838 ++ skip_reslog:
20839 ++
20840 ++ if (unlikely(!(gr_status & GR_READY) || !wanted))
20841 ++ return;
20842 ++
20843 ++ acl = task->acl;
20844 ++
20845 ++ if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
20846 ++ !(acl->resmask & (1 << (unsigned short) res))))
20847 ++ return;
20848 ++
20849 ++ if (wanted >= acl->res[res].rlim_cur) {
20850 ++ unsigned long res_add;
20851 ++
20852 ++ res_add = wanted;
20853 ++ switch (res) {
20854 ++ case RLIMIT_CPU:
20855 ++ res_add += GR_RLIM_CPU_BUMP;
20856 ++ break;
20857 ++ case RLIMIT_FSIZE:
20858 ++ res_add += GR_RLIM_FSIZE_BUMP;
20859 ++ break;
20860 ++ case RLIMIT_DATA:
20861 ++ res_add += GR_RLIM_DATA_BUMP;
20862 ++ break;
20863 ++ case RLIMIT_STACK:
20864 ++ res_add += GR_RLIM_STACK_BUMP;
20865 ++ break;
20866 ++ case RLIMIT_CORE:
20867 ++ res_add += GR_RLIM_CORE_BUMP;
20868 ++ break;
20869 ++ case RLIMIT_RSS:
20870 ++ res_add += GR_RLIM_RSS_BUMP;
20871 ++ break;
20872 ++ case RLIMIT_NPROC:
20873 ++ res_add += GR_RLIM_NPROC_BUMP;
20874 ++ break;
20875 ++ case RLIMIT_NOFILE:
20876 ++ res_add += GR_RLIM_NOFILE_BUMP;
20877 ++ break;
20878 ++ case RLIMIT_MEMLOCK:
20879 ++ res_add += GR_RLIM_MEMLOCK_BUMP;
20880 ++ break;
20881 ++ case RLIMIT_AS:
20882 ++ res_add += GR_RLIM_AS_BUMP;
20883 ++ break;
20884 ++ case RLIMIT_LOCKS:
20885 ++ res_add += GR_RLIM_LOCKS_BUMP;
20886 ++ break;
20887 ++ }
20888 ++
20889 ++ acl->res[res].rlim_cur = res_add;
20890 ++
20891 ++ if (wanted > acl->res[res].rlim_max)
20892 ++ acl->res[res].rlim_max = res_add;
20893 ++
20894 ++ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
20895 ++ task->role->roletype, acl->filename,
20896 ++ acl->res[res].rlim_cur, acl->res[res].rlim_max,
20897 ++ "", (unsigned long) res);
20898 ++ }
20899 ++
20900 ++ return;
20901 ++}
20902 ++
20903 ++#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
20904 ++void
20905 ++pax_set_initial_flags(struct linux_binprm *bprm)
20906 ++{
20907 ++ struct task_struct *task = current;
20908 ++ struct acl_subject_label *proc;
20909 ++ unsigned long flags;
20910 ++
20911 ++ if (unlikely(!(gr_status & GR_READY)))
20912 ++ return;
20913 ++
20914 ++ flags = pax_get_flags(task);
20915 ++
20916 ++ proc = task->acl;
20917 ++
20918 ++ if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
20919 ++ flags &= ~MF_PAX_PAGEEXEC;
20920 ++ if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
20921 ++ flags &= ~MF_PAX_SEGMEXEC;
20922 ++ if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
20923 ++ flags &= ~MF_PAX_RANDMMAP;
20924 ++ if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
20925 ++ flags &= ~MF_PAX_EMUTRAMP;
20926 ++ if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
20927 ++ flags &= ~MF_PAX_MPROTECT;
20928 ++
20929 ++ if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
20930 ++ flags |= MF_PAX_PAGEEXEC;
20931 ++ if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
20932 ++ flags |= MF_PAX_SEGMEXEC;
20933 ++ if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
20934 ++ flags |= MF_PAX_RANDMMAP;
20935 ++ if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
20936 ++ flags |= MF_PAX_EMUTRAMP;
20937 ++ if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
20938 ++ flags |= MF_PAX_MPROTECT;
20939 ++
20940 ++ pax_set_flags(task, flags);
20941 ++
20942 ++ return;
20943 ++}
20944 ++#endif
20945 ++
20946 ++#ifdef CONFIG_SYSCTL
20947 ++/* Eric Biederman likes breaking userland ABI and every inode-based security
20948 ++ system to save 35kb of memory */
20949 ++
20950 ++/* we modify the passed in filename, but adjust it back before returning */
20951 ++static struct acl_object_label *gr_lookup_by_name(char *name, unsigned int len)
20952 ++{
20953 ++ struct name_entry *nmatch;
20954 ++ char *p, *lastp = NULL;
20955 ++ struct acl_object_label *obj = NULL, *tmp;
20956 ++ struct acl_subject_label *tmpsubj;
20957 ++ char c = '\0';
20958 ++
20959 ++ read_lock(&gr_inode_lock);
20960 ++
20961 ++ p = name + len - 1;
20962 ++ do {
20963 ++ nmatch = lookup_name_entry(name);
20964 ++ if (lastp != NULL)
20965 ++ *lastp = c;
20966 ++
20967 ++ if (nmatch == NULL)
20968 ++ goto next_component;
20969 ++ tmpsubj = current->acl;
20970 ++ do {
20971 ++ obj = lookup_acl_obj_label(nmatch->inode, nmatch->device, tmpsubj);
20972 ++ if (obj != NULL) {
20973 ++ tmp = obj->globbed;
20974 ++ while (tmp) {
20975 ++ if (!glob_match(tmp->filename, name)) {
20976 ++ obj = tmp;
20977 ++ goto found_obj;
20978 ++ }
20979 ++ tmp = tmp->next;
20980 ++ }
20981 ++ goto found_obj;
20982 ++ }
20983 ++ } while ((tmpsubj = tmpsubj->parent_subject));
20984 ++next_component:
20985 ++ /* end case */
20986 ++ if (p == name)
20987 ++ break;
20988 ++
20989 ++ while (*p != '/')
20990 ++ p--;
20991 ++ if (p == name)
20992 ++ lastp = p + 1;
20993 ++ else {
20994 ++ lastp = p;
20995 ++ p--;
20996 ++ }
20997 ++ c = *lastp;
20998 ++ *lastp = '\0';
20999 ++ } while (1);
21000 ++found_obj:
21001 ++ read_unlock(&gr_inode_lock);
21002 ++ /* obj returned will always be non-null */
21003 ++ return obj;
21004 ++}
21005 ++
21006 ++/* returns 0 when allowing, non-zero on error
21007 ++ op of 0 is used for readdir, so we don't log the names of hidden files
21008 ++*/
21009 ++__u32
21010 ++gr_handle_sysctl(const struct ctl_table *table, const int op)
21011 ++{
21012 ++ ctl_table *tmp;
21013 ++ const char *proc_sys = "/proc/sys";
21014 ++ char *path;
21015 ++ struct acl_object_label *obj;
21016 ++ unsigned short len = 0, pos = 0, depth = 0, i;
21017 ++ __u32 err = 0;
21018 ++ __u32 mode = 0;
21019 ++
21020 ++ if (unlikely(!(gr_status & GR_READY)))
21021 ++ return 0;
21022 ++
21023 ++ /* for now, ignore operations on non-sysctl entries if it's not a
21024 ++ readdir*/
21025 ++ if (table->child != NULL && op != 0)
21026 ++ return 0;
21027 ++
21028 ++ mode |= GR_FIND;
21029 ++ /* it's only a read if it's an entry, read on dirs is for readdir */
21030 ++ if (op & MAY_READ)
21031 ++ mode |= GR_READ;
21032 ++ if (op & MAY_WRITE)
21033 ++ mode |= GR_WRITE;
21034 ++
21035 ++ preempt_disable();
21036 ++
21037 ++ path = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
21038 ++
21039 ++ /* it's only a read/write if it's an actual entry, not a dir
21040 ++ (which are opened for readdir)
21041 ++ */
21042 ++
21043 ++ /* convert the requested sysctl entry into a pathname */
21044 ++
21045 ++ for (tmp = (ctl_table *)table; tmp != NULL; tmp = tmp->parent) {
21046 ++ len += strlen(tmp->procname);
21047 ++ len++;
21048 ++ depth++;
21049 ++ }
21050 ++
21051 ++ if ((len + depth + strlen(proc_sys) + 1) > PAGE_SIZE) {
21052 ++ /* deny */
21053 ++ goto out;
21054 ++ }
21055 ++
21056 ++ memset(path, 0, PAGE_SIZE);
21057 ++
21058 ++ memcpy(path, proc_sys, strlen(proc_sys));
21059 ++
21060 ++ pos += strlen(proc_sys);
21061 ++
21062 ++ for (; depth > 0; depth--) {
21063 ++ path[pos] = '/';
21064 ++ pos++;
21065 ++ for (i = 1, tmp = (ctl_table *)table; tmp != NULL; tmp = tmp->parent) {
21066 ++ if (depth == i) {
21067 ++ memcpy(path + pos, tmp->procname,
21068 ++ strlen(tmp->procname));
21069 ++ pos += strlen(tmp->procname);
21070 ++ }
21071 ++ i++;
21072 ++ }
21073 ++ }
21074 ++
21075 ++ obj = gr_lookup_by_name(path, pos);
21076 ++ err = obj->mode & (mode | to_gr_audit(mode) | GR_SUPPRESS);
21077 ++
21078 ++ if (unlikely((current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) &&
21079 ++ ((err & mode) != mode))) {
21080 ++ __u32 new_mode = mode;
21081 ++
21082 ++ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
21083 ++
21084 ++ err = 0;
21085 ++ gr_log_learn_sysctl(current, path, new_mode);
21086 ++ } else if (!(err & GR_FIND) && !(err & GR_SUPPRESS) && op != 0) {
21087 ++ gr_log_hidden_sysctl(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, path);
21088 ++ err = -ENOENT;
21089 ++ } else if (!(err & GR_FIND)) {
21090 ++ err = -ENOENT;
21091 ++ } else if (((err & mode) & ~GR_FIND) != (mode & ~GR_FIND) && !(err & GR_SUPPRESS)) {
21092 ++ gr_log_str4(GR_DONT_AUDIT, GR_SYSCTL_ACL_MSG, "denied",
21093 ++ path, (mode & GR_READ) ? " reading" : "",
21094 ++ (mode & GR_WRITE) ? " writing" : "");
21095 ++ err = -EACCES;
21096 ++ } else if ((err & mode) != mode) {
21097 ++ err = -EACCES;
21098 ++ } else if ((((err & mode) & ~GR_FIND) == (mode & ~GR_FIND)) && (err & GR_AUDITS)) {
21099 ++ gr_log_str4(GR_DO_AUDIT, GR_SYSCTL_ACL_MSG, "successful",
21100 ++ path, (mode & GR_READ) ? " reading" : "",
21101 ++ (mode & GR_WRITE) ? " writing" : "");
21102 ++ err = 0;
21103 ++ } else
21104 ++ err = 0;
21105 ++
21106 ++ out:
21107 ++ preempt_enable();
21108 ++
21109 ++ return err;
21110 ++}
21111 ++#endif
21112 ++
21113 ++int
21114 ++gr_handle_proc_ptrace(struct task_struct *task)
21115 ++{
21116 ++ struct file *filp;
21117 ++ struct task_struct *tmp = task;
21118 ++ struct task_struct *curtemp = current;
21119 ++ __u32 retmode;
21120 ++
21121 ++ if (unlikely(!(gr_status & GR_READY)))
21122 ++ return 0;
21123 ++
21124 ++ read_lock(&tasklist_lock);
21125 ++ read_lock(&grsec_exec_file_lock);
21126 ++ filp = task->exec_file;
21127 ++
21128 ++ while (tmp->pid > 0) {
21129 ++ if (tmp == curtemp)
21130 ++ break;
21131 ++ tmp = tmp->parent;
21132 ++ }
21133 ++
21134 ++ if (!filp || (tmp->pid == 0 && !(current->acl->mode & GR_RELAXPTRACE))) {
21135 ++ read_unlock(&grsec_exec_file_lock);
21136 ++ read_unlock(&tasklist_lock);
21137 ++ return 1;
21138 ++ }
21139 ++
21140 ++ retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
21141 ++ read_unlock(&grsec_exec_file_lock);
21142 ++ read_unlock(&tasklist_lock);
21143 ++
21144 ++ if (retmode & GR_NOPTRACE)
21145 ++ return 1;
21146 ++
21147 ++ if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
21148 ++ && (current->acl != task->acl || (current->acl != current->role->root_label
21149 ++ && current->pid != task->pid)))
21150 ++ return 1;
21151 ++
21152 ++ return 0;
21153 ++}
21154 ++
21155 ++int
21156 ++gr_handle_ptrace(struct task_struct *task, const long request)
21157 ++{
21158 ++ struct task_struct *tmp = task;
21159 ++ struct task_struct *curtemp = current;
21160 ++ __u32 retmode;
21161 ++
21162 ++ if (unlikely(!(gr_status & GR_READY)))
21163 ++ return 0;
21164 ++
21165 ++ read_lock(&tasklist_lock);
21166 ++ while (tmp->pid > 0) {
21167 ++ if (tmp == curtemp)
21168 ++ break;
21169 ++ tmp = tmp->parent;
21170 ++ }
21171 ++
21172 ++ if (tmp->pid == 0 && !(current->acl->mode & GR_RELAXPTRACE)) {
21173 ++ read_unlock(&tasklist_lock);
21174 ++ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
21175 ++ return 1;
21176 ++ }
21177 ++ read_unlock(&tasklist_lock);
21178 ++
21179 ++ read_lock(&grsec_exec_file_lock);
21180 ++ if (unlikely(!task->exec_file)) {
21181 ++ read_unlock(&grsec_exec_file_lock);
21182 ++ return 0;
21183 ++ }
21184 ++
21185 ++ retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
21186 ++ read_unlock(&grsec_exec_file_lock);
21187 ++
21188 ++ if (retmode & GR_NOPTRACE) {
21189 ++ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
21190 ++ return 1;
21191 ++ }
21192 ++
21193 ++ if (retmode & GR_PTRACERD) {
21194 ++ switch (request) {
21195 ++ case PTRACE_POKETEXT:
21196 ++ case PTRACE_POKEDATA:
21197 ++ case PTRACE_POKEUSR:
21198 ++#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
21199 ++ case PTRACE_SETREGS:
21200 ++ case PTRACE_SETFPREGS:
21201 ++#endif
21202 ++#ifdef CONFIG_X86
21203 ++ case PTRACE_SETFPXREGS:
21204 ++#endif
21205 ++#ifdef CONFIG_ALTIVEC
21206 ++ case PTRACE_SETVRREGS:
21207 ++#endif
21208 ++ return 1;
21209 ++ default:
21210 ++ return 0;
21211 ++ }
21212 ++ } else if (!(current->acl->mode & GR_POVERRIDE) &&
21213 ++ !(current->role->roletype & GR_ROLE_GOD) &&
21214 ++ (current->acl != task->acl)) {
21215 ++ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
21216 ++ return 1;
21217 ++ }
21218 ++
21219 ++ return 0;
21220 ++}
21221 ++
21222 ++static int is_writable_mmap(const struct file *filp)
21223 ++{
21224 ++ struct task_struct *task = current;
21225 ++ struct acl_object_label *obj, *obj2;
21226 ++
21227 ++ if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
21228 ++ !task->is_writable && S_ISREG(filp->f_path.dentry->d_inode->i_mode)) {
21229 ++ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
21230 ++ obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
21231 ++ task->role->root_label);
21232 ++ if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
21233 ++ gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
21234 ++ return 1;
21235 ++ }
21236 ++ }
21237 ++ return 0;
21238 ++}
21239 ++
21240 ++int
21241 ++gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
21242 ++{
21243 ++ __u32 mode;
21244 ++
21245 ++ if (unlikely(!file || !(prot & PROT_EXEC)))
21246 ++ return 1;
21247 ++
21248 ++ if (is_writable_mmap(file))
21249 ++ return 0;
21250 ++
21251 ++ mode =
21252 ++ gr_search_file(file->f_path.dentry,
21253 ++ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
21254 ++ file->f_path.mnt);
21255 ++
21256 ++ if (!gr_tpe_allow(file))
21257 ++ return 0;
21258 ++
21259 ++ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
21260 ++ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
21261 ++ return 0;
21262 ++ } else if (unlikely(!(mode & GR_EXEC))) {
21263 ++ return 0;
21264 ++ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
21265 ++ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
21266 ++ return 1;
21267 ++ }
21268 ++
21269 ++ return 1;
21270 ++}
21271 ++
21272 ++int
21273 ++gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
21274 ++{
21275 ++ __u32 mode;
21276 ++
21277 ++ if (unlikely(!file || !(prot & PROT_EXEC)))
21278 ++ return 1;
21279 ++
21280 ++ if (is_writable_mmap(file))
21281 ++ return 0;
21282 ++
21283 ++ mode =
21284 ++ gr_search_file(file->f_path.dentry,
21285 ++ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
21286 ++ file->f_path.mnt);
21287 ++
21288 ++ if (!gr_tpe_allow(file))
21289 ++ return 0;
21290 ++
21291 ++ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
21292 ++ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
21293 ++ return 0;
21294 ++ } else if (unlikely(!(mode & GR_EXEC))) {
21295 ++ return 0;
21296 ++ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
21297 ++ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
21298 ++ return 1;
21299 ++ }
21300 ++
21301 ++ return 1;
21302 ++}
21303 ++
21304 ++void
21305 ++gr_acl_handle_psacct(struct task_struct *task, const long code)
21306 ++{
21307 ++ unsigned long runtime;
21308 ++ unsigned long cputime;
21309 ++ unsigned int wday, cday;
21310 ++ __u8 whr, chr;
21311 ++ __u8 wmin, cmin;
21312 ++ __u8 wsec, csec;
21313 ++ struct timespec timeval;
21314 ++
21315 ++ if (unlikely(!(gr_status & GR_READY) || !task->acl ||
21316 ++ !(task->acl->mode & GR_PROCACCT)))
21317 ++ return;
21318 ++
21319 ++ do_posix_clock_monotonic_gettime(&timeval);
21320 ++ runtime = timeval.tv_sec - task->start_time.tv_sec;
21321 ++ wday = runtime / (3600 * 24);
21322 ++ runtime -= wday * (3600 * 24);
21323 ++ whr = runtime / 3600;
21324 ++ runtime -= whr * 3600;
21325 ++ wmin = runtime / 60;
21326 ++ runtime -= wmin * 60;
21327 ++ wsec = runtime;
21328 ++
21329 ++ cputime = (task->utime + task->stime) / HZ;
21330 ++ cday = cputime / (3600 * 24);
21331 ++ cputime -= cday * (3600 * 24);
21332 ++ chr = cputime / 3600;
21333 ++ cputime -= chr * 3600;
21334 ++ cmin = cputime / 60;
21335 ++ cputime -= cmin * 60;
21336 ++ csec = cputime;
21337 ++
21338 ++ gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
21339 ++
21340 ++ return;
21341 ++}
21342 ++
21343 ++void gr_set_kernel_label(struct task_struct *task)
21344 ++{
21345 ++ if (gr_status & GR_READY) {
21346 ++ task->role = kernel_role;
21347 ++ task->acl = kernel_role->root_label;
21348 ++ }
21349 ++ return;
21350 ++}
21351 ++
21352 ++int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
21353 ++{
21354 ++ struct task_struct *task = current;
21355 ++ struct dentry *dentry = file->f_path.dentry;
21356 ++ struct vfsmount *mnt = file->f_path.mnt;
21357 ++ struct acl_object_label *obj, *tmp;
21358 ++ struct acl_subject_label *subj;
21359 ++ unsigned int bufsize;
21360 ++ int is_not_root;
21361 ++ char *path;
21362 ++
21363 ++ if (unlikely(!(gr_status & GR_READY)))
21364 ++ return 1;
21365 ++
21366 ++ if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
21367 ++ return 1;
21368 ++
21369 ++ /* ignore Eric Biederman */
21370 ++ if (IS_PRIVATE(dentry->d_inode))
21371 ++ return 1;
21372 ++
21373 ++ subj = task->acl;
21374 ++ do {
21375 ++ obj = lookup_acl_obj_label(ino, dentry->d_inode->i_sb->s_dev, subj);
21376 ++ if (obj != NULL)
21377 ++ return (obj->mode & GR_FIND) ? 1 : 0;
21378 ++ } while ((subj = subj->parent_subject));
21379 ++
21380 ++ obj = chk_obj_label(dentry, mnt, task->acl);
21381 ++ if (obj->globbed == NULL)
21382 ++ return (obj->mode & GR_FIND) ? 1 : 0;
21383 ++
21384 ++ is_not_root = ((obj->filename[0] == '/') &&
21385 ++ (obj->filename[1] == '\0')) ? 0 : 1;
21386 ++ bufsize = PAGE_SIZE - namelen - is_not_root;
21387 ++
21388 ++ /* check bufsize > PAGE_SIZE || bufsize == 0 */
21389 ++ if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
21390 ++ return 1;
21391 ++
21392 ++ preempt_disable();
21393 ++ path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
21394 ++ bufsize);
21395 ++
21396 ++ bufsize = strlen(path);
21397 ++
21398 ++ /* if base is "/", don't append an additional slash */
21399 ++ if (is_not_root)
21400 ++ *(path + bufsize) = '/';
21401 ++ memcpy(path + bufsize + is_not_root, name, namelen);
21402 ++ *(path + bufsize + namelen + is_not_root) = '\0';
21403 ++
21404 ++ tmp = obj->globbed;
21405 ++ while (tmp) {
21406 ++ if (!glob_match(tmp->filename, path)) {
21407 ++ preempt_enable();
21408 ++ return (tmp->mode & GR_FIND) ? 1 : 0;
21409 ++ }
21410 ++ tmp = tmp->next;
21411 ++ }
21412 ++ preempt_enable();
21413 ++ return (obj->mode & GR_FIND) ? 1 : 0;
21414 ++}
21415 ++
21416 ++EXPORT_SYMBOL(gr_learn_resource);
21417 ++EXPORT_SYMBOL(gr_set_kernel_label);
21418 ++#ifdef CONFIG_SECURITY
21419 ++EXPORT_SYMBOL(gr_check_user_change);
21420 ++EXPORT_SYMBOL(gr_check_group_change);
21421 ++#endif
21422 ++
21423 +diff -urNp linux-2.6.27.10/grsecurity/gracl_cap.c linux-2.6.27.10/grsecurity/gracl_cap.c
21424 +--- linux-2.6.27.10/grsecurity/gracl_cap.c 1969-12-31 19:00:00.000000000 -0500
21425 ++++ linux-2.6.27.10/grsecurity/gracl_cap.c 2008-11-18 03:38:45.000000000 -0500
21426 +@@ -0,0 +1,129 @@
21427 ++#include <linux/kernel.h>
21428 ++#include <linux/module.h>
21429 ++#include <linux/sched.h>
21430 ++#include <linux/gracl.h>
21431 ++#include <linux/grsecurity.h>
21432 ++#include <linux/grinternal.h>
21433 ++
21434 ++static const char *captab_log[] = {
21435 ++ "CAP_CHOWN",
21436 ++ "CAP_DAC_OVERRIDE",
21437 ++ "CAP_DAC_READ_SEARCH",
21438 ++ "CAP_FOWNER",
21439 ++ "CAP_FSETID",
21440 ++ "CAP_KILL",
21441 ++ "CAP_SETGID",
21442 ++ "CAP_SETUID",
21443 ++ "CAP_SETPCAP",
21444 ++ "CAP_LINUX_IMMUTABLE",
21445 ++ "CAP_NET_BIND_SERVICE",
21446 ++ "CAP_NET_BROADCAST",
21447 ++ "CAP_NET_ADMIN",
21448 ++ "CAP_NET_RAW",
21449 ++ "CAP_IPC_LOCK",
21450 ++ "CAP_IPC_OWNER",
21451 ++ "CAP_SYS_MODULE",
21452 ++ "CAP_SYS_RAWIO",
21453 ++ "CAP_SYS_CHROOT",
21454 ++ "CAP_SYS_PTRACE",
21455 ++ "CAP_SYS_PACCT",
21456 ++ "CAP_SYS_ADMIN",
21457 ++ "CAP_SYS_BOOT",
21458 ++ "CAP_SYS_NICE",
21459 ++ "CAP_SYS_RESOURCE",
21460 ++ "CAP_SYS_TIME",
21461 ++ "CAP_SYS_TTY_CONFIG",
21462 ++ "CAP_MKNOD",
21463 ++ "CAP_LEASE",
21464 ++ "CAP_AUDIT_WRITE",
21465 ++ "CAP_AUDIT_CONTROL",
21466 ++ "CAP_SETFCAP",
21467 ++ "CAP_MAC_OVERRIDE",
21468 ++ "CAP_MAC_ADMIN"
21469 ++};
21470 ++
21471 ++EXPORT_SYMBOL(gr_task_is_capable);
21472 ++EXPORT_SYMBOL(gr_is_capable_nolog);
21473 ++
21474 ++int
21475 ++gr_task_is_capable(struct task_struct *task, const int cap)
21476 ++{
21477 ++ struct acl_subject_label *curracl;
21478 ++ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
21479 ++
21480 ++ if (!gr_acl_is_enabled())
21481 ++ return 1;
21482 ++
21483 ++ curracl = task->acl;
21484 ++
21485 ++ cap_drop = curracl->cap_lower;
21486 ++ cap_mask = curracl->cap_mask;
21487 ++
21488 ++ while ((curracl = curracl->parent_subject)) {
21489 ++ /* if the cap isn't specified in the current computed mask but is specified in the
21490 ++ current level subject, and is lowered in the current level subject, then add
21491 ++ it to the set of dropped capabilities
21492 ++ otherwise, add the current level subject's mask to the current computed mask
21493 ++ */
21494 ++ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
21495 ++ cap_raise(cap_mask, cap);
21496 ++ if (cap_raised(curracl->cap_lower, cap))
21497 ++ cap_raise(cap_drop, cap);
21498 ++ }
21499 ++ }
21500 ++
21501 ++ if (!cap_raised(cap_drop, cap))
21502 ++ return 1;
21503 ++
21504 ++ curracl = task->acl;
21505 ++
21506 ++ if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
21507 ++ && cap_raised(task->cap_effective, cap)) {
21508 ++ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
21509 ++ task->role->roletype, task->uid,
21510 ++ task->gid, task->exec_file ?
21511 ++ gr_to_filename(task->exec_file->f_path.dentry,
21512 ++ task->exec_file->f_path.mnt) : curracl->filename,
21513 ++ curracl->filename, 0UL,
21514 ++ 0UL, "", (unsigned long) cap, NIPQUAD(task->signal->curr_ip));
21515 ++ return 1;
21516 ++ }
21517 ++
21518 ++ if ((cap >= 0) && (cap < (sizeof(captab_log)/sizeof(captab_log[0]))) && cap_raised(task->cap_effective, cap))
21519 ++ gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
21520 ++ return 0;
21521 ++}
21522 ++
21523 ++int
21524 ++gr_is_capable_nolog(const int cap)
21525 ++{
21526 ++ struct acl_subject_label *curracl;
21527 ++ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
21528 ++
21529 ++ if (!gr_acl_is_enabled())
21530 ++ return 1;
21531 ++
21532 ++ curracl = current->acl;
21533 ++
21534 ++ cap_drop = curracl->cap_lower;
21535 ++ cap_mask = curracl->cap_mask;
21536 ++
21537 ++ while ((curracl = curracl->parent_subject)) {
21538 ++ /* if the cap isn't specified in the current computed mask but is specified in the
21539 ++ current level subject, and is lowered in the current level subject, then add
21540 ++ it to the set of dropped capabilities
21541 ++ otherwise, add the current level subject's mask to the current computed mask
21542 ++ */
21543 ++ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
21544 ++ cap_raise(cap_mask, cap);
21545 ++ if (cap_raised(curracl->cap_lower, cap))
21546 ++ cap_raise(cap_drop, cap);
21547 ++ }
21548 ++ }
21549 ++
21550 ++ if (!cap_raised(cap_drop, cap))
21551 ++ return 1;
21552 ++
21553 ++ return 0;
21554 ++}
21555 ++
21556 +diff -urNp linux-2.6.27.10/grsecurity/gracl_fs.c linux-2.6.27.10/grsecurity/gracl_fs.c
21557 +--- linux-2.6.27.10/grsecurity/gracl_fs.c 1969-12-31 19:00:00.000000000 -0500
21558 ++++ linux-2.6.27.10/grsecurity/gracl_fs.c 2008-11-18 03:38:45.000000000 -0500
21559 +@@ -0,0 +1,423 @@
21560 ++#include <linux/kernel.h>
21561 ++#include <linux/sched.h>
21562 ++#include <linux/types.h>
21563 ++#include <linux/fs.h>
21564 ++#include <linux/file.h>
21565 ++#include <linux/stat.h>
21566 ++#include <linux/grsecurity.h>
21567 ++#include <linux/grinternal.h>
21568 ++#include <linux/gracl.h>
21569 ++
21570 ++__u32
21571 ++gr_acl_handle_hidden_file(const struct dentry * dentry,
21572 ++ const struct vfsmount * mnt)
21573 ++{
21574 ++ __u32 mode;
21575 ++
21576 ++ if (unlikely(!dentry->d_inode))
21577 ++ return GR_FIND;
21578 ++
21579 ++ mode =
21580 ++ gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
21581 ++
21582 ++ if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
21583 ++ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
21584 ++ return mode;
21585 ++ } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
21586 ++ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
21587 ++ return 0;
21588 ++ } else if (unlikely(!(mode & GR_FIND)))
21589 ++ return 0;
21590 ++
21591 ++ return GR_FIND;
21592 ++}
21593 ++
21594 ++__u32
21595 ++gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
21596 ++ const int fmode)
21597 ++{
21598 ++ __u32 reqmode = GR_FIND;
21599 ++ __u32 mode;
21600 ++
21601 ++ if (unlikely(!dentry->d_inode))
21602 ++ return reqmode;
21603 ++
21604 ++ if (unlikely(fmode & O_APPEND))
21605 ++ reqmode |= GR_APPEND;
21606 ++ else if (unlikely(fmode & FMODE_WRITE))
21607 ++ reqmode |= GR_WRITE;
21608 ++ if (likely((fmode & FMODE_READ) && !(fmode & O_DIRECTORY)))
21609 ++ reqmode |= GR_READ;
21610 ++
21611 ++ mode =
21612 ++ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
21613 ++ mnt);
21614 ++
21615 ++ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
21616 ++ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
21617 ++ reqmode & GR_READ ? " reading" : "",
21618 ++ reqmode & GR_WRITE ? " writing" : reqmode &
21619 ++ GR_APPEND ? " appending" : "");
21620 ++ return reqmode;
21621 ++ } else
21622 ++ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
21623 ++ {
21624 ++ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
21625 ++ reqmode & GR_READ ? " reading" : "",
21626 ++ reqmode & GR_WRITE ? " writing" : reqmode &
21627 ++ GR_APPEND ? " appending" : "");
21628 ++ return 0;
21629 ++ } else if (unlikely((mode & reqmode) != reqmode))
21630 ++ return 0;
21631 ++
21632 ++ return reqmode;
21633 ++}
21634 ++
21635 ++__u32
21636 ++gr_acl_handle_creat(const struct dentry * dentry,
21637 ++ const struct dentry * p_dentry,
21638 ++ const struct vfsmount * p_mnt, const int fmode,
21639 ++ const int imode)
21640 ++{
21641 ++ __u32 reqmode = GR_WRITE | GR_CREATE;
21642 ++ __u32 mode;
21643 ++
21644 ++ if (unlikely(fmode & O_APPEND))
21645 ++ reqmode |= GR_APPEND;
21646 ++ if (unlikely((fmode & FMODE_READ) && !(fmode & O_DIRECTORY)))
21647 ++ reqmode |= GR_READ;
21648 ++ if (unlikely((fmode & O_CREAT) && (imode & (S_ISUID | S_ISGID))))
21649 ++ reqmode |= GR_SETID;
21650 ++
21651 ++ mode =
21652 ++ gr_check_create(dentry, p_dentry, p_mnt,
21653 ++ reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
21654 ++
21655 ++ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
21656 ++ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
21657 ++ reqmode & GR_READ ? " reading" : "",
21658 ++ reqmode & GR_WRITE ? " writing" : reqmode &
21659 ++ GR_APPEND ? " appending" : "");
21660 ++ return reqmode;
21661 ++ } else
21662 ++ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
21663 ++ {
21664 ++ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
21665 ++ reqmode & GR_READ ? " reading" : "",
21666 ++ reqmode & GR_WRITE ? " writing" : reqmode &
21667 ++ GR_APPEND ? " appending" : "");
21668 ++ return 0;
21669 ++ } else if (unlikely((mode & reqmode) != reqmode))
21670 ++ return 0;
21671 ++
21672 ++ return reqmode;
21673 ++}
21674 ++
21675 ++__u32
21676 ++gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
21677 ++ const int fmode)
21678 ++{
21679 ++ __u32 mode, reqmode = GR_FIND;
21680 ++
21681 ++ if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
21682 ++ reqmode |= GR_EXEC;
21683 ++ if (fmode & S_IWOTH)
21684 ++ reqmode |= GR_WRITE;
21685 ++ if (fmode & S_IROTH)
21686 ++ reqmode |= GR_READ;
21687 ++
21688 ++ mode =
21689 ++ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
21690 ++ mnt);
21691 ++
21692 ++ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
21693 ++ gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
21694 ++ reqmode & GR_READ ? " reading" : "",
21695 ++ reqmode & GR_WRITE ? " writing" : "",
21696 ++ reqmode & GR_EXEC ? " executing" : "");
21697 ++ return reqmode;
21698 ++ } else
21699 ++ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
21700 ++ {
21701 ++ gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
21702 ++ reqmode & GR_READ ? " reading" : "",
21703 ++ reqmode & GR_WRITE ? " writing" : "",
21704 ++ reqmode & GR_EXEC ? " executing" : "");
21705 ++ return 0;
21706 ++ } else if (unlikely((mode & reqmode) != reqmode))
21707 ++ return 0;
21708 ++
21709 ++ return reqmode;
21710 ++}
21711 ++
21712 ++static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
21713 ++{
21714 ++ __u32 mode;
21715 ++
21716 ++ mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
21717 ++
21718 ++ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
21719 ++ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
21720 ++ return mode;
21721 ++ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
21722 ++ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
21723 ++ return 0;
21724 ++ } else if (unlikely((mode & (reqmode)) != (reqmode)))
21725 ++ return 0;
21726 ++
21727 ++ return (reqmode);
21728 ++}
21729 ++
21730 ++__u32
21731 ++gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
21732 ++{
21733 ++ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
21734 ++}
21735 ++
21736 ++__u32
21737 ++gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
21738 ++{
21739 ++ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
21740 ++}
21741 ++
21742 ++__u32
21743 ++gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
21744 ++{
21745 ++ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
21746 ++}
21747 ++
21748 ++__u32
21749 ++gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
21750 ++{
21751 ++ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
21752 ++}
21753 ++
21754 ++__u32
21755 ++gr_acl_handle_fchmod(const struct dentry *dentry, const struct vfsmount *mnt,
21756 ++ mode_t mode)
21757 ++{
21758 ++ if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
21759 ++ return 1;
21760 ++
21761 ++ if (unlikely((mode != (mode_t)-1) && (mode & (S_ISUID | S_ISGID)))) {
21762 ++ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
21763 ++ GR_FCHMOD_ACL_MSG);
21764 ++ } else {
21765 ++ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_FCHMOD_ACL_MSG);
21766 ++ }
21767 ++}
21768 ++
21769 ++__u32
21770 ++gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
21771 ++ mode_t mode)
21772 ++{
21773 ++ if (unlikely((mode != (mode_t)-1) && (mode & (S_ISUID | S_ISGID)))) {
21774 ++ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
21775 ++ GR_CHMOD_ACL_MSG);
21776 ++ } else {
21777 ++ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
21778 ++ }
21779 ++}
21780 ++
21781 ++__u32
21782 ++gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
21783 ++{
21784 ++ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
21785 ++}
21786 ++
21787 ++__u32
21788 ++gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
21789 ++{
21790 ++ return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
21791 ++}
21792 ++
21793 ++__u32
21794 ++gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
21795 ++{
21796 ++ return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
21797 ++ GR_UNIXCONNECT_ACL_MSG);
21798 ++}
21799 ++
21800 ++/* hardlinks require at minimum create permission,
21801 ++ any additional privilege required is based on the
21802 ++ privilege of the file being linked to
21803 ++*/
21804 ++__u32
21805 ++gr_acl_handle_link(const struct dentry * new_dentry,
21806 ++ const struct dentry * parent_dentry,
21807 ++ const struct vfsmount * parent_mnt,
21808 ++ const struct dentry * old_dentry,
21809 ++ const struct vfsmount * old_mnt, const char *to)
21810 ++{
21811 ++ __u32 mode;
21812 ++ __u32 needmode = GR_CREATE | GR_LINK;
21813 ++ __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
21814 ++
21815 ++ mode =
21816 ++ gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
21817 ++ old_mnt);
21818 ++
21819 ++ if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
21820 ++ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
21821 ++ return mode;
21822 ++ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
21823 ++ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
21824 ++ return 0;
21825 ++ } else if (unlikely((mode & needmode) != needmode))
21826 ++ return 0;
21827 ++
21828 ++ return 1;
21829 ++}
21830 ++
21831 ++__u32
21832 ++gr_acl_handle_symlink(const struct dentry * new_dentry,
21833 ++ const struct dentry * parent_dentry,
21834 ++ const struct vfsmount * parent_mnt, const char *from)
21835 ++{
21836 ++ __u32 needmode = GR_WRITE | GR_CREATE;
21837 ++ __u32 mode;
21838 ++
21839 ++ mode =
21840 ++ gr_check_create(new_dentry, parent_dentry, parent_mnt,
21841 ++ GR_CREATE | GR_AUDIT_CREATE |
21842 ++ GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
21843 ++
21844 ++ if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
21845 ++ gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
21846 ++ return mode;
21847 ++ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
21848 ++ gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
21849 ++ return 0;
21850 ++ } else if (unlikely((mode & needmode) != needmode))
21851 ++ return 0;
21852 ++
21853 ++ return (GR_WRITE | GR_CREATE);
21854 ++}
21855 ++
21856 ++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)
21857 ++{
21858 ++ __u32 mode;
21859 ++
21860 ++ mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
21861 ++
21862 ++ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
21863 ++ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
21864 ++ return mode;
21865 ++ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
21866 ++ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
21867 ++ return 0;
21868 ++ } else if (unlikely((mode & (reqmode)) != (reqmode)))
21869 ++ return 0;
21870 ++
21871 ++ return (reqmode);
21872 ++}
21873 ++
21874 ++__u32
21875 ++gr_acl_handle_mknod(const struct dentry * new_dentry,
21876 ++ const struct dentry * parent_dentry,
21877 ++ const struct vfsmount * parent_mnt,
21878 ++ const int mode)
21879 ++{
21880 ++ __u32 reqmode = GR_WRITE | GR_CREATE;
21881 ++ if (unlikely(mode & (S_ISUID | S_ISGID)))
21882 ++ reqmode |= GR_SETID;
21883 ++
21884 ++ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
21885 ++ reqmode, GR_MKNOD_ACL_MSG);
21886 ++}
21887 ++
21888 ++__u32
21889 ++gr_acl_handle_mkdir(const struct dentry *new_dentry,
21890 ++ const struct dentry *parent_dentry,
21891 ++ const struct vfsmount *parent_mnt)
21892 ++{
21893 ++ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
21894 ++ GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
21895 ++}
21896 ++
21897 ++#define RENAME_CHECK_SUCCESS(old, new) \
21898 ++ (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
21899 ++ ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
21900 ++
21901 ++int
21902 ++gr_acl_handle_rename(struct dentry *new_dentry,
21903 ++ struct dentry *parent_dentry,
21904 ++ const struct vfsmount *parent_mnt,
21905 ++ struct dentry *old_dentry,
21906 ++ struct inode *old_parent_inode,
21907 ++ struct vfsmount *old_mnt, const char *newname)
21908 ++{
21909 ++ __u32 comp1, comp2;
21910 ++ int error = 0;
21911 ++
21912 ++ if (unlikely(!gr_acl_is_enabled()))
21913 ++ return 0;
21914 ++
21915 ++ if (!new_dentry->d_inode) {
21916 ++ comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
21917 ++ GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
21918 ++ GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
21919 ++ comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
21920 ++ GR_DELETE | GR_AUDIT_DELETE |
21921 ++ GR_AUDIT_READ | GR_AUDIT_WRITE |
21922 ++ GR_SUPPRESS, old_mnt);
21923 ++ } else {
21924 ++ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
21925 ++ GR_CREATE | GR_DELETE |
21926 ++ GR_AUDIT_CREATE | GR_AUDIT_DELETE |
21927 ++ GR_AUDIT_READ | GR_AUDIT_WRITE |
21928 ++ GR_SUPPRESS, parent_mnt);
21929 ++ comp2 =
21930 ++ gr_search_file(old_dentry,
21931 ++ GR_READ | GR_WRITE | GR_AUDIT_READ |
21932 ++ GR_DELETE | GR_AUDIT_DELETE |
21933 ++ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
21934 ++ }
21935 ++
21936 ++ if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
21937 ++ ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
21938 ++ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
21939 ++ else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
21940 ++ && !(comp2 & GR_SUPPRESS)) {
21941 ++ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
21942 ++ error = -EACCES;
21943 ++ } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
21944 ++ error = -EACCES;
21945 ++
21946 ++ return error;
21947 ++}
21948 ++
21949 ++void
21950 ++gr_acl_handle_exit(void)
21951 ++{
21952 ++ u16 id;
21953 ++ char *rolename;
21954 ++ struct file *exec_file;
21955 ++
21956 ++ if (unlikely(current->acl_sp_role && gr_acl_is_enabled())) {
21957 ++ id = current->acl_role_id;
21958 ++ rolename = current->role->rolename;
21959 ++ gr_set_acls(1);
21960 ++ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
21961 ++ }
21962 ++
21963 ++ write_lock(&grsec_exec_file_lock);
21964 ++ exec_file = current->exec_file;
21965 ++ current->exec_file = NULL;
21966 ++ write_unlock(&grsec_exec_file_lock);
21967 ++
21968 ++ if (exec_file)
21969 ++ fput(exec_file);
21970 ++}
21971 ++
21972 ++int
21973 ++gr_acl_handle_procpidmem(const struct task_struct *task)
21974 ++{
21975 ++ if (unlikely(!gr_acl_is_enabled()))
21976 ++ return 0;
21977 ++
21978 ++ if (task != current && task->acl->mode & GR_PROTPROCFD)
21979 ++ return -EACCES;
21980 ++
21981 ++ return 0;
21982 ++}
21983 +diff -urNp linux-2.6.27.10/grsecurity/gracl_ip.c linux-2.6.27.10/grsecurity/gracl_ip.c
21984 +--- linux-2.6.27.10/grsecurity/gracl_ip.c 1969-12-31 19:00:00.000000000 -0500
21985 ++++ linux-2.6.27.10/grsecurity/gracl_ip.c 2008-11-18 03:38:45.000000000 -0500
21986 +@@ -0,0 +1,313 @@
21987 ++#include <linux/kernel.h>
21988 ++#include <asm/uaccess.h>
21989 ++#include <asm/errno.h>
21990 ++#include <net/sock.h>
21991 ++#include <linux/file.h>
21992 ++#include <linux/fs.h>
21993 ++#include <linux/net.h>
21994 ++#include <linux/in.h>
21995 ++#include <linux/skbuff.h>
21996 ++#include <linux/ip.h>
21997 ++#include <linux/udp.h>
21998 ++#include <linux/smp_lock.h>
21999 ++#include <linux/types.h>
22000 ++#include <linux/sched.h>
22001 ++#include <linux/netdevice.h>
22002 ++#include <linux/inetdevice.h>
22003 ++#include <linux/gracl.h>
22004 ++#include <linux/grsecurity.h>
22005 ++#include <linux/grinternal.h>
22006 ++
22007 ++#define GR_BIND 0x01
22008 ++#define GR_CONNECT 0x02
22009 ++#define GR_INVERT 0x04
22010 ++
22011 ++static const char * gr_protocols[256] = {
22012 ++ "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
22013 ++ "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
22014 ++ "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
22015 ++ "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
22016 ++ "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
22017 ++ "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
22018 ++ "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
22019 ++ "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
22020 ++ "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
22021 ++ "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
22022 ++ "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
22023 ++ "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
22024 ++ "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
22025 ++ "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
22026 ++ "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
22027 ++ "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
22028 ++ "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
22029 ++ "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
22030 ++ "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
22031 ++ "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
22032 ++ "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
22033 ++ "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
22034 ++ "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
22035 ++ "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
22036 ++ "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
22037 ++ "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
22038 ++ "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
22039 ++ "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
22040 ++ "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
22041 ++ "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
22042 ++ "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
22043 ++ "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
22044 ++ };
22045 ++
22046 ++static const char * gr_socktypes[11] = {
22047 ++ "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
22048 ++ "unknown:7", "unknown:8", "unknown:9", "packet"
22049 ++ };
22050 ++
22051 ++const char *
22052 ++gr_proto_to_name(unsigned char proto)
22053 ++{
22054 ++ return gr_protocols[proto];
22055 ++}
22056 ++
22057 ++const char *
22058 ++gr_socktype_to_name(unsigned char type)
22059 ++{
22060 ++ return gr_socktypes[type];
22061 ++}
22062 ++
22063 ++int
22064 ++gr_search_socket(const int domain, const int type, const int protocol)
22065 ++{
22066 ++ struct acl_subject_label *curr;
22067 ++
22068 ++ if (unlikely(!gr_acl_is_enabled()))
22069 ++ goto exit;
22070 ++
22071 ++ if ((domain < 0) || (type < 0) || (protocol < 0) || (domain != PF_INET)
22072 ++ || (domain >= NPROTO) || (type >= SOCK_MAX) || (protocol > 255))
22073 ++ goto exit; // let the kernel handle it
22074 ++
22075 ++ curr = current->acl;
22076 ++
22077 ++ if (!curr->ips)
22078 ++ goto exit;
22079 ++
22080 ++ if ((curr->ip_type & (1 << type)) &&
22081 ++ (curr->ip_proto[protocol / 32] & (1 << (protocol % 32))))
22082 ++ goto exit;
22083 ++
22084 ++ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
22085 ++ /* we don't place acls on raw sockets , and sometimes
22086 ++ dgram/ip sockets are opened for ioctl and not
22087 ++ bind/connect, so we'll fake a bind learn log */
22088 ++ if (type == SOCK_RAW || type == SOCK_PACKET) {
22089 ++ __u32 fakeip = 0;
22090 ++ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
22091 ++ current->role->roletype, current->uid,
22092 ++ current->gid, current->exec_file ?
22093 ++ gr_to_filename(current->exec_file->f_path.dentry,
22094 ++ current->exec_file->f_path.mnt) :
22095 ++ curr->filename, curr->filename,
22096 ++ NIPQUAD(fakeip), 0, type,
22097 ++ protocol, GR_CONNECT,
22098 ++NIPQUAD(current->signal->curr_ip));
22099 ++ } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
22100 ++ __u32 fakeip = 0;
22101 ++ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
22102 ++ current->role->roletype, current->uid,
22103 ++ current->gid, current->exec_file ?
22104 ++ gr_to_filename(current->exec_file->f_path.dentry,
22105 ++ current->exec_file->f_path.mnt) :
22106 ++ curr->filename, curr->filename,
22107 ++ NIPQUAD(fakeip), 0, type,
22108 ++ protocol, GR_BIND, NIPQUAD(current->signal->curr_ip));
22109 ++ }
22110 ++ /* we'll log when they use connect or bind */
22111 ++ goto exit;
22112 ++ }
22113 ++
22114 ++ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, "inet",
22115 ++ gr_socktype_to_name(type), gr_proto_to_name(protocol));
22116 ++
22117 ++ return 0;
22118 ++ exit:
22119 ++ return 1;
22120 ++}
22121 ++
22122 ++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)
22123 ++{
22124 ++ if ((ip->mode & mode) &&
22125 ++ (ip_port >= ip->low) &&
22126 ++ (ip_port <= ip->high) &&
22127 ++ ((ntohl(ip_addr) & our_netmask) ==
22128 ++ (ntohl(our_addr) & our_netmask))
22129 ++ && (ip->proto[protocol / 32] & (1 << (protocol % 32)))
22130 ++ && (ip->type & (1 << type))) {
22131 ++ if (ip->mode & GR_INVERT)
22132 ++ return 2; // specifically denied
22133 ++ else
22134 ++ return 1; // allowed
22135 ++ }
22136 ++
22137 ++ return 0; // not specifically allowed, may continue parsing
22138 ++}
22139 ++
22140 ++static int
22141 ++gr_search_connectbind(const int mode, const struct sock *sk,
22142 ++ const struct sockaddr_in *addr, const int type)
22143 ++{
22144 ++ char iface[IFNAMSIZ] = {0};
22145 ++ struct acl_subject_label *curr;
22146 ++ struct acl_ip_label *ip;
22147 ++ struct net_device *dev;
22148 ++ struct in_device *idev;
22149 ++ unsigned long i;
22150 ++ int ret;
22151 ++ __u32 ip_addr = 0;
22152 ++ __u32 our_addr;
22153 ++ __u32 our_netmask;
22154 ++ char *p;
22155 ++ __u16 ip_port = 0;
22156 ++
22157 ++ if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
22158 ++ return 1;
22159 ++
22160 ++ curr = current->acl;
22161 ++
22162 ++ if (!curr->ips)
22163 ++ return 1;
22164 ++
22165 ++ ip_addr = addr->sin_addr.s_addr;
22166 ++ ip_port = ntohs(addr->sin_port);
22167 ++
22168 ++ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
22169 ++ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
22170 ++ current->role->roletype, current->uid,
22171 ++ current->gid, current->exec_file ?
22172 ++ gr_to_filename(current->exec_file->f_path.dentry,
22173 ++ current->exec_file->f_path.mnt) :
22174 ++ curr->filename, curr->filename,
22175 ++ NIPQUAD(ip_addr), ip_port, type,
22176 ++ sk->sk_protocol, mode, NIPQUAD(current->signal->curr_ip));
22177 ++ return 1;
22178 ++ }
22179 ++
22180 ++ for (i = 0; i < curr->ip_num; i++) {
22181 ++ ip = *(curr->ips + i);
22182 ++ if (ip->iface != NULL) {
22183 ++ strncpy(iface, ip->iface, IFNAMSIZ - 1);
22184 ++ p = strchr(iface, ':');
22185 ++ if (p != NULL)
22186 ++ *p = '\0';
22187 ++ dev = dev_get_by_name(sock_net(sk), iface);
22188 ++ if (dev == NULL)
22189 ++ continue;
22190 ++ idev = in_dev_get(dev);
22191 ++ if (idev == NULL) {
22192 ++ dev_put(dev);
22193 ++ continue;
22194 ++ }
22195 ++ rcu_read_lock();
22196 ++ for_ifa(idev) {
22197 ++ if (!strcmp(ip->iface, ifa->ifa_label)) {
22198 ++ our_addr = ifa->ifa_address;
22199 ++ our_netmask = 0xffffffff;
22200 ++ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
22201 ++ if (ret == 1) {
22202 ++ rcu_read_unlock();
22203 ++ in_dev_put(idev);
22204 ++ dev_put(dev);
22205 ++ return 1;
22206 ++ } else if (ret == 2) {
22207 ++ rcu_read_unlock();
22208 ++ in_dev_put(idev);
22209 ++ dev_put(dev);
22210 ++ goto denied;
22211 ++ }
22212 ++ }
22213 ++ } endfor_ifa(idev);
22214 ++ rcu_read_unlock();
22215 ++ in_dev_put(idev);
22216 ++ dev_put(dev);
22217 ++ } else {
22218 ++ our_addr = ip->addr;
22219 ++ our_netmask = ip->netmask;
22220 ++ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
22221 ++ if (ret == 1)
22222 ++ return 1;
22223 ++ else if (ret == 2)
22224 ++ goto denied;
22225 ++ }
22226 ++ }
22227 ++
22228 ++denied:
22229 ++ if (mode == GR_BIND)
22230 ++ gr_log_int5_str2(GR_DONT_AUDIT, GR_BIND_ACL_MSG, NIPQUAD(ip_addr), ip_port, gr_socktype_to_name(type), gr_proto_to_name(sk->sk_protocol));
22231 ++ else if (mode == GR_CONNECT)
22232 ++ gr_log_int5_str2(GR_DONT_AUDIT, GR_CONNECT_ACL_MSG, NIPQUAD(ip_addr), ip_port, gr_socktype_to_name(type), gr_proto_to_name(sk->sk_protocol));
22233 ++
22234 ++ return 0;
22235 ++}
22236 ++
22237 ++int
22238 ++gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
22239 ++{
22240 ++ return gr_search_connectbind(GR_CONNECT, sock->sk, addr, sock->type);
22241 ++}
22242 ++
22243 ++int
22244 ++gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
22245 ++{
22246 ++ return gr_search_connectbind(GR_BIND, sock->sk, addr, sock->type);
22247 ++}
22248 ++
22249 ++int gr_search_listen(const struct socket *sock)
22250 ++{
22251 ++ struct sock *sk = sock->sk;
22252 ++ struct sockaddr_in addr;
22253 ++
22254 ++ addr.sin_addr.s_addr = inet_sk(sk)->saddr;
22255 ++ addr.sin_port = inet_sk(sk)->sport;
22256 ++
22257 ++ return gr_search_connectbind(GR_BIND, sock->sk, &addr, sock->type);
22258 ++}
22259 ++
22260 ++int gr_search_accept(const struct socket *sock)
22261 ++{
22262 ++ struct sock *sk = sock->sk;
22263 ++ struct sockaddr_in addr;
22264 ++
22265 ++ addr.sin_addr.s_addr = inet_sk(sk)->saddr;
22266 ++ addr.sin_port = inet_sk(sk)->sport;
22267 ++
22268 ++ return gr_search_connectbind(GR_BIND, sock->sk, &addr, sock->type);
22269 ++}
22270 ++
22271 ++int
22272 ++gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
22273 ++{
22274 ++ if (addr)
22275 ++ return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
22276 ++ else {
22277 ++ struct sockaddr_in sin;
22278 ++ const struct inet_sock *inet = inet_sk(sk);
22279 ++
22280 ++ sin.sin_addr.s_addr = inet->daddr;
22281 ++ sin.sin_port = inet->dport;
22282 ++
22283 ++ return gr_search_connectbind(GR_CONNECT, sk, &sin, SOCK_DGRAM);
22284 ++ }
22285 ++}
22286 ++
22287 ++int
22288 ++gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
22289 ++{
22290 ++ struct sockaddr_in sin;
22291 ++
22292 ++ if (unlikely(skb->len < sizeof (struct udphdr)))
22293 ++ return 1; // skip this packet
22294 ++
22295 ++ sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
22296 ++ sin.sin_port = udp_hdr(skb)->source;
22297 ++
22298 ++ return gr_search_connectbind(GR_CONNECT, sk, &sin, SOCK_DGRAM);
22299 ++}
22300 +diff -urNp linux-2.6.27.10/grsecurity/gracl_learn.c linux-2.6.27.10/grsecurity/gracl_learn.c
22301 +--- linux-2.6.27.10/grsecurity/gracl_learn.c 1969-12-31 19:00:00.000000000 -0500
22302 ++++ linux-2.6.27.10/grsecurity/gracl_learn.c 2008-11-18 03:38:45.000000000 -0500
22303 +@@ -0,0 +1,211 @@
22304 ++#include <linux/kernel.h>
22305 ++#include <linux/mm.h>
22306 ++#include <linux/sched.h>
22307 ++#include <linux/poll.h>
22308 ++#include <linux/smp_lock.h>
22309 ++#include <linux/string.h>
22310 ++#include <linux/file.h>
22311 ++#include <linux/types.h>
22312 ++#include <linux/vmalloc.h>
22313 ++#include <linux/grinternal.h>
22314 ++
22315 ++extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
22316 ++ size_t count, loff_t *ppos);
22317 ++extern int gr_acl_is_enabled(void);
22318 ++
22319 ++static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
22320 ++static int gr_learn_attached;
22321 ++
22322 ++/* use a 512k buffer */
22323 ++#define LEARN_BUFFER_SIZE (512 * 1024)
22324 ++
22325 ++static DEFINE_SPINLOCK(gr_learn_lock);
22326 ++static DECLARE_MUTEX(gr_learn_user_sem);
22327 ++
22328 ++/* we need to maintain two buffers, so that the kernel context of grlearn
22329 ++ uses a semaphore around the userspace copying, and the other kernel contexts
22330 ++ use a spinlock when copying into the buffer, since they cannot sleep
22331 ++*/
22332 ++static char *learn_buffer;
22333 ++static char *learn_buffer_user;
22334 ++static int learn_buffer_len;
22335 ++static int learn_buffer_user_len;
22336 ++
22337 ++static ssize_t
22338 ++read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
22339 ++{
22340 ++ DECLARE_WAITQUEUE(wait, current);
22341 ++ ssize_t retval = 0;
22342 ++
22343 ++ add_wait_queue(&learn_wait, &wait);
22344 ++ set_current_state(TASK_INTERRUPTIBLE);
22345 ++ do {
22346 ++ down(&gr_learn_user_sem);
22347 ++ spin_lock(&gr_learn_lock);
22348 ++ if (learn_buffer_len)
22349 ++ break;
22350 ++ spin_unlock(&gr_learn_lock);
22351 ++ up(&gr_learn_user_sem);
22352 ++ if (file->f_flags & O_NONBLOCK) {
22353 ++ retval = -EAGAIN;
22354 ++ goto out;
22355 ++ }
22356 ++ if (signal_pending(current)) {
22357 ++ retval = -ERESTARTSYS;
22358 ++ goto out;
22359 ++ }
22360 ++
22361 ++ schedule();
22362 ++ } while (1);
22363 ++
22364 ++ memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
22365 ++ learn_buffer_user_len = learn_buffer_len;
22366 ++ retval = learn_buffer_len;
22367 ++ learn_buffer_len = 0;
22368 ++
22369 ++ spin_unlock(&gr_learn_lock);
22370 ++
22371 ++ if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
22372 ++ retval = -EFAULT;
22373 ++
22374 ++ up(&gr_learn_user_sem);
22375 ++out:
22376 ++ set_current_state(TASK_RUNNING);
22377 ++ remove_wait_queue(&learn_wait, &wait);
22378 ++ return retval;
22379 ++}
22380 ++
22381 ++static unsigned int
22382 ++poll_learn(struct file * file, poll_table * wait)
22383 ++{
22384 ++ poll_wait(file, &learn_wait, wait);
22385 ++
22386 ++ if (learn_buffer_len)
22387 ++ return (POLLIN | POLLRDNORM);
22388 ++
22389 ++ return 0;
22390 ++}
22391 ++
22392 ++void
22393 ++gr_clear_learn_entries(void)
22394 ++{
22395 ++ char *tmp;
22396 ++
22397 ++ down(&gr_learn_user_sem);
22398 ++ if (learn_buffer != NULL) {
22399 ++ spin_lock(&gr_learn_lock);
22400 ++ tmp = learn_buffer;
22401 ++ learn_buffer = NULL;
22402 ++ spin_unlock(&gr_learn_lock);
22403 ++ vfree(learn_buffer);
22404 ++ }
22405 ++ if (learn_buffer_user != NULL) {
22406 ++ vfree(learn_buffer_user);
22407 ++ learn_buffer_user = NULL;
22408 ++ }
22409 ++ learn_buffer_len = 0;
22410 ++ up(&gr_learn_user_sem);
22411 ++
22412 ++ return;
22413 ++}
22414 ++
22415 ++void
22416 ++gr_add_learn_entry(const char *fmt, ...)
22417 ++{
22418 ++ va_list args;
22419 ++ unsigned int len;
22420 ++
22421 ++ if (!gr_learn_attached)
22422 ++ return;
22423 ++
22424 ++ spin_lock(&gr_learn_lock);
22425 ++
22426 ++ /* leave a gap at the end so we know when it's "full" but don't have to
22427 ++ compute the exact length of the string we're trying to append
22428 ++ */
22429 ++ if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
22430 ++ spin_unlock(&gr_learn_lock);
22431 ++ wake_up_interruptible(&learn_wait);
22432 ++ return;
22433 ++ }
22434 ++ if (learn_buffer == NULL) {
22435 ++ spin_unlock(&gr_learn_lock);
22436 ++ return;
22437 ++ }
22438 ++
22439 ++ va_start(args, fmt);
22440 ++ len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
22441 ++ va_end(args);
22442 ++
22443 ++ learn_buffer_len += len + 1;
22444 ++
22445 ++ spin_unlock(&gr_learn_lock);
22446 ++ wake_up_interruptible(&learn_wait);
22447 ++
22448 ++ return;
22449 ++}
22450 ++
22451 ++static int
22452 ++open_learn(struct inode *inode, struct file *file)
22453 ++{
22454 ++ if (file->f_mode & FMODE_READ && gr_learn_attached)
22455 ++ return -EBUSY;
22456 ++ if (file->f_mode & FMODE_READ) {
22457 ++ int retval = 0;
22458 ++ down(&gr_learn_user_sem);
22459 ++ if (learn_buffer == NULL)
22460 ++ learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
22461 ++ if (learn_buffer_user == NULL)
22462 ++ learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
22463 ++ if (learn_buffer == NULL) {
22464 ++ retval = -ENOMEM;
22465 ++ goto out_error;
22466 ++ }
22467 ++ if (learn_buffer_user == NULL) {
22468 ++ retval = -ENOMEM;
22469 ++ goto out_error;
22470 ++ }
22471 ++ learn_buffer_len = 0;
22472 ++ learn_buffer_user_len = 0;
22473 ++ gr_learn_attached = 1;
22474 ++out_error:
22475 ++ up(&gr_learn_user_sem);
22476 ++ return retval;
22477 ++ }
22478 ++ return 0;
22479 ++}
22480 ++
22481 ++static int
22482 ++close_learn(struct inode *inode, struct file *file)
22483 ++{
22484 ++ char *tmp;
22485 ++
22486 ++ if (file->f_mode & FMODE_READ) {
22487 ++ down(&gr_learn_user_sem);
22488 ++ if (learn_buffer != NULL) {
22489 ++ spin_lock(&gr_learn_lock);
22490 ++ tmp = learn_buffer;
22491 ++ learn_buffer = NULL;
22492 ++ spin_unlock(&gr_learn_lock);
22493 ++ vfree(tmp);
22494 ++ }
22495 ++ if (learn_buffer_user != NULL) {
22496 ++ vfree(learn_buffer_user);
22497 ++ learn_buffer_user = NULL;
22498 ++ }
22499 ++ learn_buffer_len = 0;
22500 ++ learn_buffer_user_len = 0;
22501 ++ gr_learn_attached = 0;
22502 ++ up(&gr_learn_user_sem);
22503 ++ }
22504 ++
22505 ++ return 0;
22506 ++}
22507 ++
22508 ++struct file_operations grsec_fops = {
22509 ++ .read = read_learn,
22510 ++ .write = write_grsec_handler,
22511 ++ .open = open_learn,
22512 ++ .release = close_learn,
22513 ++ .poll = poll_learn,
22514 ++};
22515 +diff -urNp linux-2.6.27.10/grsecurity/gracl_res.c linux-2.6.27.10/grsecurity/gracl_res.c
22516 +--- linux-2.6.27.10/grsecurity/gracl_res.c 1969-12-31 19:00:00.000000000 -0500
22517 ++++ linux-2.6.27.10/grsecurity/gracl_res.c 2008-11-18 03:38:45.000000000 -0500
22518 +@@ -0,0 +1,45 @@
22519 ++#include <linux/kernel.h>
22520 ++#include <linux/sched.h>
22521 ++#include <linux/gracl.h>
22522 ++#include <linux/grinternal.h>
22523 ++
22524 ++static const char *restab_log[] = {
22525 ++ [RLIMIT_CPU] = "RLIMIT_CPU",
22526 ++ [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
22527 ++ [RLIMIT_DATA] = "RLIMIT_DATA",
22528 ++ [RLIMIT_STACK] = "RLIMIT_STACK",
22529 ++ [RLIMIT_CORE] = "RLIMIT_CORE",
22530 ++ [RLIMIT_RSS] = "RLIMIT_RSS",
22531 ++ [RLIMIT_NPROC] = "RLIMIT_NPROC",
22532 ++ [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
22533 ++ [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
22534 ++ [RLIMIT_AS] = "RLIMIT_AS",
22535 ++ [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
22536 ++ [RLIMIT_LOCKS + 1] = "RLIMIT_CRASH"
22537 ++};
22538 ++
22539 ++void
22540 ++gr_log_resource(const struct task_struct *task,
22541 ++ const int res, const unsigned long wanted, const int gt)
22542 ++{
22543 ++ if (res == RLIMIT_NPROC &&
22544 ++ (cap_raised(task->cap_effective, CAP_SYS_ADMIN) ||
22545 ++ cap_raised(task->cap_effective, CAP_SYS_RESOURCE)))
22546 ++ return;
22547 ++ else if (res == RLIMIT_MEMLOCK &&
22548 ++ cap_raised(task->cap_effective, CAP_IPC_LOCK))
22549 ++ return;
22550 ++
22551 ++ if (!gr_acl_is_enabled() && !grsec_resource_logging)
22552 ++ return;
22553 ++
22554 ++ preempt_disable();
22555 ++
22556 ++ if (unlikely(((gt && wanted > task->signal->rlim[res].rlim_cur) ||
22557 ++ (!gt && wanted >= task->signal->rlim[res].rlim_cur)) &&
22558 ++ task->signal->rlim[res].rlim_cur != RLIM_INFINITY))
22559 ++ gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], task->signal->rlim[res].rlim_cur);
22560 ++ preempt_enable_no_resched();
22561 ++
22562 ++ return;
22563 ++}
22564 +diff -urNp linux-2.6.27.10/grsecurity/gracl_segv.c linux-2.6.27.10/grsecurity/gracl_segv.c
22565 +--- linux-2.6.27.10/grsecurity/gracl_segv.c 1969-12-31 19:00:00.000000000 -0500
22566 ++++ linux-2.6.27.10/grsecurity/gracl_segv.c 2008-11-18 03:38:45.000000000 -0500
22567 +@@ -0,0 +1,304 @@
22568 ++#include <linux/kernel.h>
22569 ++#include <linux/mm.h>
22570 ++#include <asm/uaccess.h>
22571 ++#include <asm/errno.h>
22572 ++#include <asm/mman.h>
22573 ++#include <net/sock.h>
22574 ++#include <linux/file.h>
22575 ++#include <linux/fs.h>
22576 ++#include <linux/net.h>
22577 ++#include <linux/in.h>
22578 ++#include <linux/smp_lock.h>
22579 ++#include <linux/slab.h>
22580 ++#include <linux/types.h>
22581 ++#include <linux/sched.h>
22582 ++#include <linux/timer.h>
22583 ++#include <linux/gracl.h>
22584 ++#include <linux/grsecurity.h>
22585 ++#include <linux/grinternal.h>
22586 ++
22587 ++static struct crash_uid *uid_set;
22588 ++static unsigned short uid_used;
22589 ++static DEFINE_SPINLOCK(gr_uid_lock);
22590 ++extern rwlock_t gr_inode_lock;
22591 ++extern struct acl_subject_label *
22592 ++ lookup_acl_subj_label(const ino_t inode, const dev_t dev,
22593 ++ struct acl_role_label *role);
22594 ++extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
22595 ++
22596 ++int
22597 ++gr_init_uidset(void)
22598 ++{
22599 ++ uid_set =
22600 ++ kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
22601 ++ uid_used = 0;
22602 ++
22603 ++ return uid_set ? 1 : 0;
22604 ++}
22605 ++
22606 ++void
22607 ++gr_free_uidset(void)
22608 ++{
22609 ++ if (uid_set)
22610 ++ kfree(uid_set);
22611 ++
22612 ++ return;
22613 ++}
22614 ++
22615 ++int
22616 ++gr_find_uid(const uid_t uid)
22617 ++{
22618 ++ struct crash_uid *tmp = uid_set;
22619 ++ uid_t buid;
22620 ++ int low = 0, high = uid_used - 1, mid;
22621 ++
22622 ++ while (high >= low) {
22623 ++ mid = (low + high) >> 1;
22624 ++ buid = tmp[mid].uid;
22625 ++ if (buid == uid)
22626 ++ return mid;
22627 ++ if (buid > uid)
22628 ++ high = mid - 1;
22629 ++ if (buid < uid)
22630 ++ low = mid + 1;
22631 ++ }
22632 ++
22633 ++ return -1;
22634 ++}
22635 ++
22636 ++static __inline__ void
22637 ++gr_insertsort(void)
22638 ++{
22639 ++ unsigned short i, j;
22640 ++ struct crash_uid index;
22641 ++
22642 ++ for (i = 1; i < uid_used; i++) {
22643 ++ index = uid_set[i];
22644 ++ j = i;
22645 ++ while ((j > 0) && uid_set[j - 1].uid > index.uid) {
22646 ++ uid_set[j] = uid_set[j - 1];
22647 ++ j--;
22648 ++ }
22649 ++ uid_set[j] = index;
22650 ++ }
22651 ++
22652 ++ return;
22653 ++}
22654 ++
22655 ++static __inline__ void
22656 ++gr_insert_uid(const uid_t uid, const unsigned long expires)
22657 ++{
22658 ++ int loc;
22659 ++
22660 ++ if (uid_used == GR_UIDTABLE_MAX)
22661 ++ return;
22662 ++
22663 ++ loc = gr_find_uid(uid);
22664 ++
22665 ++ if (loc >= 0) {
22666 ++ uid_set[loc].expires = expires;
22667 ++ return;
22668 ++ }
22669 ++
22670 ++ uid_set[uid_used].uid = uid;
22671 ++ uid_set[uid_used].expires = expires;
22672 ++ uid_used++;
22673 ++
22674 ++ gr_insertsort();
22675 ++
22676 ++ return;
22677 ++}
22678 ++
22679 ++void
22680 ++gr_remove_uid(const unsigned short loc)
22681 ++{
22682 ++ unsigned short i;
22683 ++
22684 ++ for (i = loc + 1; i < uid_used; i++)
22685 ++ uid_set[i - 1] = uid_set[i];
22686 ++
22687 ++ uid_used--;
22688 ++
22689 ++ return;
22690 ++}
22691 ++
22692 ++int
22693 ++gr_check_crash_uid(const uid_t uid)
22694 ++{
22695 ++ int loc;
22696 ++ int ret = 0;
22697 ++
22698 ++ if (unlikely(!gr_acl_is_enabled()))
22699 ++ return 0;
22700 ++
22701 ++ spin_lock(&gr_uid_lock);
22702 ++ loc = gr_find_uid(uid);
22703 ++
22704 ++ if (loc < 0)
22705 ++ goto out_unlock;
22706 ++
22707 ++ if (time_before_eq(uid_set[loc].expires, get_seconds()))
22708 ++ gr_remove_uid(loc);
22709 ++ else
22710 ++ ret = 1;
22711 ++
22712 ++out_unlock:
22713 ++ spin_unlock(&gr_uid_lock);
22714 ++ return ret;
22715 ++}
22716 ++
22717 ++static __inline__ int
22718 ++proc_is_setxid(const struct task_struct *task)
22719 ++{
22720 ++ if (task->uid != task->euid || task->uid != task->suid ||
22721 ++ task->uid != task->fsuid)
22722 ++ return 1;
22723 ++ if (task->gid != task->egid || task->gid != task->sgid ||
22724 ++ task->gid != task->fsgid)
22725 ++ return 1;
22726 ++
22727 ++ return 0;
22728 ++}
22729 ++static __inline__ int
22730 ++gr_fake_force_sig(int sig, struct task_struct *t)
22731 ++{
22732 ++ unsigned long int flags;
22733 ++ int ret, blocked, ignored;
22734 ++ struct k_sigaction *action;
22735 ++
22736 ++ spin_lock_irqsave(&t->sighand->siglock, flags);
22737 ++ action = &t->sighand->action[sig-1];
22738 ++ ignored = action->sa.sa_handler == SIG_IGN;
22739 ++ blocked = sigismember(&t->blocked, sig);
22740 ++ if (blocked || ignored) {
22741 ++ action->sa.sa_handler = SIG_DFL;
22742 ++ if (blocked) {
22743 ++ sigdelset(&t->blocked, sig);
22744 ++ recalc_sigpending_and_wake(t);
22745 ++ }
22746 ++ }
22747 ++ if (action->sa.sa_handler == SIG_DFL)
22748 ++ t->signal->flags &= ~SIGNAL_UNKILLABLE;
22749 ++ ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
22750 ++
22751 ++ spin_unlock_irqrestore(&t->sighand->siglock, flags);
22752 ++
22753 ++ return ret;
22754 ++}
22755 ++
22756 ++void
22757 ++gr_handle_crash(struct task_struct *task, const int sig)
22758 ++{
22759 ++ struct acl_subject_label *curr;
22760 ++ struct acl_subject_label *curr2;
22761 ++ struct task_struct *tsk, *tsk2;
22762 ++
22763 ++ if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
22764 ++ return;
22765 ++
22766 ++ if (unlikely(!gr_acl_is_enabled()))
22767 ++ return;
22768 ++
22769 ++ curr = task->acl;
22770 ++
22771 ++ if (!(curr->resmask & (1 << GR_CRASH_RES)))
22772 ++ return;
22773 ++
22774 ++ if (time_before_eq(curr->expires, get_seconds())) {
22775 ++ curr->expires = 0;
22776 ++ curr->crashes = 0;
22777 ++ }
22778 ++
22779 ++ curr->crashes++;
22780 ++
22781 ++ if (!curr->expires)
22782 ++ curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
22783 ++
22784 ++ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
22785 ++ time_after(curr->expires, get_seconds())) {
22786 ++ if (task->uid && proc_is_setxid(task)) {
22787 ++ gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
22788 ++ spin_lock(&gr_uid_lock);
22789 ++ gr_insert_uid(task->uid, curr->expires);
22790 ++ spin_unlock(&gr_uid_lock);
22791 ++ curr->expires = 0;
22792 ++ curr->crashes = 0;
22793 ++ read_lock(&tasklist_lock);
22794 ++ do_each_thread(tsk2, tsk) {
22795 ++ if (tsk != task && tsk->uid == task->uid)
22796 ++ gr_fake_force_sig(SIGKILL, tsk);
22797 ++ } while_each_thread(tsk2, tsk);
22798 ++ read_unlock(&tasklist_lock);
22799 ++ } else {
22800 ++ gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
22801 ++ read_lock(&tasklist_lock);
22802 ++ do_each_thread(tsk2, tsk) {
22803 ++ if (likely(tsk != task)) {
22804 ++ curr2 = tsk->acl;
22805 ++
22806 ++ if (curr2->device == curr->device &&
22807 ++ curr2->inode == curr->inode)
22808 ++ gr_fake_force_sig(SIGKILL, tsk);
22809 ++ }
22810 ++ } while_each_thread(tsk2, tsk);
22811 ++ read_unlock(&tasklist_lock);
22812 ++ }
22813 ++ }
22814 ++
22815 ++ return;
22816 ++}
22817 ++
22818 ++int
22819 ++gr_check_crash_exec(const struct file *filp)
22820 ++{
22821 ++ struct acl_subject_label *curr;
22822 ++
22823 ++ if (unlikely(!gr_acl_is_enabled()))
22824 ++ return 0;
22825 ++
22826 ++ read_lock(&gr_inode_lock);
22827 ++ curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
22828 ++ filp->f_path.dentry->d_inode->i_sb->s_dev,
22829 ++ current->role);
22830 ++ read_unlock(&gr_inode_lock);
22831 ++
22832 ++ if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) ||
22833 ++ (!curr->crashes && !curr->expires))
22834 ++ return 0;
22835 ++
22836 ++ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
22837 ++ time_after(curr->expires, get_seconds()))
22838 ++ return 1;
22839 ++ else if (time_before_eq(curr->expires, get_seconds())) {
22840 ++ curr->crashes = 0;
22841 ++ curr->expires = 0;
22842 ++ }
22843 ++
22844 ++ return 0;
22845 ++}
22846 ++
22847 ++void
22848 ++gr_handle_alertkill(struct task_struct *task)
22849 ++{
22850 ++ struct acl_subject_label *curracl;
22851 ++ __u32 curr_ip;
22852 ++ struct task_struct *p, *p2;
22853 ++
22854 ++ if (unlikely(!gr_acl_is_enabled()))
22855 ++ return;
22856 ++
22857 ++ curracl = task->acl;
22858 ++ curr_ip = task->signal->curr_ip;
22859 ++
22860 ++ if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
22861 ++ read_lock(&tasklist_lock);
22862 ++ do_each_thread(p2, p) {
22863 ++ if (p->signal->curr_ip == curr_ip)
22864 ++ gr_fake_force_sig(SIGKILL, p);
22865 ++ } while_each_thread(p2, p);
22866 ++ read_unlock(&tasklist_lock);
22867 ++ } else if (curracl->mode & GR_KILLPROC)
22868 ++ gr_fake_force_sig(SIGKILL, task);
22869 ++
22870 ++ return;
22871 ++}
22872 +diff -urNp linux-2.6.27.10/grsecurity/gracl_shm.c linux-2.6.27.10/grsecurity/gracl_shm.c
22873 +--- linux-2.6.27.10/grsecurity/gracl_shm.c 1969-12-31 19:00:00.000000000 -0500
22874 ++++ linux-2.6.27.10/grsecurity/gracl_shm.c 2008-11-18 03:38:45.000000000 -0500
22875 +@@ -0,0 +1,33 @@
22876 ++#include <linux/kernel.h>
22877 ++#include <linux/mm.h>
22878 ++#include <linux/sched.h>
22879 ++#include <linux/file.h>
22880 ++#include <linux/ipc.h>
22881 ++#include <linux/gracl.h>
22882 ++#include <linux/grsecurity.h>
22883 ++#include <linux/grinternal.h>
22884 ++
22885 ++int
22886 ++gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
22887 ++ const time_t shm_createtime, const uid_t cuid, const int shmid)
22888 ++{
22889 ++ struct task_struct *task;
22890 ++
22891 ++ if (!gr_acl_is_enabled())
22892 ++ return 1;
22893 ++
22894 ++ task = find_task_by_vpid(shm_cprid);
22895 ++
22896 ++ if (unlikely(!task))
22897 ++ task = find_task_by_vpid(shm_lapid);
22898 ++
22899 ++ if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
22900 ++ (task->pid == shm_lapid)) &&
22901 ++ (task->acl->mode & GR_PROTSHM) &&
22902 ++ (task->acl != current->acl))) {
22903 ++ gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, cuid, shm_cprid, shmid);
22904 ++ return 0;
22905 ++ }
22906 ++
22907 ++ return 1;
22908 ++}
22909 +diff -urNp linux-2.6.27.10/grsecurity/grsec_chdir.c linux-2.6.27.10/grsecurity/grsec_chdir.c
22910 +--- linux-2.6.27.10/grsecurity/grsec_chdir.c 1969-12-31 19:00:00.000000000 -0500
22911 ++++ linux-2.6.27.10/grsecurity/grsec_chdir.c 2008-11-18 03:38:45.000000000 -0500
22912 +@@ -0,0 +1,19 @@
22913 ++#include <linux/kernel.h>
22914 ++#include <linux/sched.h>
22915 ++#include <linux/fs.h>
22916 ++#include <linux/file.h>
22917 ++#include <linux/grsecurity.h>
22918 ++#include <linux/grinternal.h>
22919 ++
22920 ++void
22921 ++gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
22922 ++{
22923 ++#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
22924 ++ if ((grsec_enable_chdir && grsec_enable_group &&
22925 ++ in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
22926 ++ !grsec_enable_group)) {
22927 ++ gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
22928 ++ }
22929 ++#endif
22930 ++ return;
22931 ++}
22932 +diff -urNp linux-2.6.27.10/grsecurity/grsec_chroot.c linux-2.6.27.10/grsecurity/grsec_chroot.c
22933 +--- linux-2.6.27.10/grsecurity/grsec_chroot.c 1969-12-31 19:00:00.000000000 -0500
22934 ++++ linux-2.6.27.10/grsecurity/grsec_chroot.c 2008-11-18 03:38:45.000000000 -0500
22935 +@@ -0,0 +1,336 @@
22936 ++#include <linux/kernel.h>
22937 ++#include <linux/module.h>
22938 ++#include <linux/sched.h>
22939 ++#include <linux/file.h>
22940 ++#include <linux/fs.h>
22941 ++#include <linux/mount.h>
22942 ++#include <linux/types.h>
22943 ++#include <linux/pid_namespace.h>
22944 ++#include <linux/grsecurity.h>
22945 ++#include <linux/grinternal.h>
22946 ++
22947 ++int
22948 ++gr_handle_chroot_unix(const pid_t pid)
22949 ++{
22950 ++#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
22951 ++ struct pid *spid = NULL;
22952 ++
22953 ++ if (unlikely(!grsec_enable_chroot_unix))
22954 ++ return 1;
22955 ++
22956 ++ if (likely(!proc_is_chrooted(current)))
22957 ++ return 1;
22958 ++
22959 ++ read_lock(&tasklist_lock);
22960 ++
22961 ++ spid = find_vpid(pid);
22962 ++ if (spid) {
22963 ++ struct task_struct *p;
22964 ++ p = pid_task(spid, PIDTYPE_PID);
22965 ++ task_lock(p);
22966 ++ if (unlikely(!have_same_root(current, p))) {
22967 ++ task_unlock(p);
22968 ++ read_unlock(&tasklist_lock);
22969 ++ gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
22970 ++ return 0;
22971 ++ }
22972 ++ task_unlock(p);
22973 ++ }
22974 ++ read_unlock(&tasklist_lock);
22975 ++#endif
22976 ++ return 1;
22977 ++}
22978 ++
22979 ++int
22980 ++gr_handle_chroot_nice(void)
22981 ++{
22982 ++#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
22983 ++ if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
22984 ++ gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
22985 ++ return -EPERM;
22986 ++ }
22987 ++#endif
22988 ++ return 0;
22989 ++}
22990 ++
22991 ++int
22992 ++gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
22993 ++{
22994 ++#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
22995 ++ if (grsec_enable_chroot_nice && (niceval < task_nice(p))
22996 ++ && proc_is_chrooted(current)) {
22997 ++ gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, p->pid);
22998 ++ return -EACCES;
22999 ++ }
23000 ++#endif
23001 ++ return 0;
23002 ++}
23003 ++
23004 ++int
23005 ++gr_handle_chroot_rawio(const struct inode *inode)
23006 ++{
23007 ++#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
23008 ++ if (grsec_enable_chroot_caps && proc_is_chrooted(current) &&
23009 ++ inode && S_ISBLK(inode->i_mode) && !capable(CAP_SYS_RAWIO))
23010 ++ return 1;
23011 ++#endif
23012 ++ return 0;
23013 ++}
23014 ++
23015 ++int
23016 ++gr_pid_is_chrooted(struct task_struct *p)
23017 ++{
23018 ++#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
23019 ++ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
23020 ++ return 0;
23021 ++
23022 ++ task_lock(p);
23023 ++ if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
23024 ++ !have_same_root(current, p)) {
23025 ++ task_unlock(p);
23026 ++ return 1;
23027 ++ }
23028 ++ task_unlock(p);
23029 ++#endif
23030 ++ return 0;
23031 ++}
23032 ++
23033 ++EXPORT_SYMBOL(gr_pid_is_chrooted);
23034 ++
23035 ++#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
23036 ++int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
23037 ++{
23038 ++ struct dentry *dentry = (struct dentry *)u_dentry;
23039 ++ struct vfsmount *mnt = (struct vfsmount *)u_mnt;
23040 ++ struct dentry *realroot;
23041 ++ struct vfsmount *realrootmnt;
23042 ++ struct dentry *currentroot;
23043 ++ struct vfsmount *currentmnt;
23044 ++ struct task_struct *reaper = current->nsproxy->pid_ns->child_reaper;
23045 ++ int ret = 1;
23046 ++
23047 ++ read_lock(&reaper->fs->lock);
23048 ++ realrootmnt = mntget(reaper->fs->root.mnt);
23049 ++ realroot = dget(reaper->fs->root.dentry);
23050 ++ read_unlock(&reaper->fs->lock);
23051 ++
23052 ++ read_lock(&current->fs->lock);
23053 ++ currentmnt = mntget(current->fs->root.mnt);
23054 ++ currentroot = dget(current->fs->root.dentry);
23055 ++ read_unlock(&current->fs->lock);
23056 ++
23057 ++ spin_lock(&dcache_lock);
23058 ++ for (;;) {
23059 ++ if (unlikely((dentry == realroot && mnt == realrootmnt)
23060 ++ || (dentry == currentroot && mnt == currentmnt)))
23061 ++ break;
23062 ++ if (unlikely(dentry == mnt->mnt_root || IS_ROOT(dentry))) {
23063 ++ if (mnt->mnt_parent == mnt)
23064 ++ break;
23065 ++ dentry = mnt->mnt_mountpoint;
23066 ++ mnt = mnt->mnt_parent;
23067 ++ continue;
23068 ++ }
23069 ++ dentry = dentry->d_parent;
23070 ++ }
23071 ++ spin_unlock(&dcache_lock);
23072 ++
23073 ++ dput(currentroot);
23074 ++ mntput(currentmnt);
23075 ++
23076 ++ /* access is outside of chroot */
23077 ++ if (dentry == realroot && mnt == realrootmnt)
23078 ++ ret = 0;
23079 ++
23080 ++ dput(realroot);
23081 ++ mntput(realrootmnt);
23082 ++ return ret;
23083 ++}
23084 ++#endif
23085 ++
23086 ++int
23087 ++gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
23088 ++{
23089 ++#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
23090 ++ if (!grsec_enable_chroot_fchdir)
23091 ++ return 1;
23092 ++
23093 ++ if (!proc_is_chrooted(current))
23094 ++ return 1;
23095 ++ else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
23096 ++ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
23097 ++ return 0;
23098 ++ }
23099 ++#endif
23100 ++ return 1;
23101 ++}
23102 ++
23103 ++int
23104 ++gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
23105 ++ const time_t shm_createtime)
23106 ++{
23107 ++#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
23108 ++ struct pid *pid = NULL;
23109 ++ time_t starttime;
23110 ++
23111 ++ if (unlikely(!grsec_enable_chroot_shmat))
23112 ++ return 1;
23113 ++
23114 ++ if (likely(!proc_is_chrooted(current)))
23115 ++ return 1;
23116 ++
23117 ++ read_lock(&tasklist_lock);
23118 ++
23119 ++ pid = find_vpid(shm_cprid);
23120 ++ if (pid) {
23121 ++ struct task_struct *p;
23122 ++ p = pid_task(pid, PIDTYPE_PID);
23123 ++ task_lock(p);
23124 ++ starttime = p->start_time.tv_sec;
23125 ++ if (unlikely(!have_same_root(current, p) &&
23126 ++ time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime))) {
23127 ++ task_unlock(p);
23128 ++ read_unlock(&tasklist_lock);
23129 ++ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
23130 ++ return 0;
23131 ++ }
23132 ++ task_unlock(p);
23133 ++ } else {
23134 ++ pid = find_vpid(shm_lapid);
23135 ++ if (pid) {
23136 ++ struct task_struct *p;
23137 ++ p = pid_task(pid, PIDTYPE_PID);
23138 ++ task_lock(p);
23139 ++ if (unlikely(!have_same_root(current, p))) {
23140 ++ task_unlock(p);
23141 ++ read_unlock(&tasklist_lock);
23142 ++ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
23143 ++ return 0;
23144 ++ }
23145 ++ task_unlock(p);
23146 ++ }
23147 ++ }
23148 ++
23149 ++ read_unlock(&tasklist_lock);
23150 ++#endif
23151 ++ return 1;
23152 ++}
23153 ++
23154 ++void
23155 ++gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
23156 ++{
23157 ++#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
23158 ++ if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
23159 ++ gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
23160 ++#endif
23161 ++ return;
23162 ++}
23163 ++
23164 ++int
23165 ++gr_handle_chroot_mknod(const struct dentry *dentry,
23166 ++ const struct vfsmount *mnt, const int mode)
23167 ++{
23168 ++#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
23169 ++ if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
23170 ++ proc_is_chrooted(current)) {
23171 ++ gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
23172 ++ return -EPERM;
23173 ++ }
23174 ++#endif
23175 ++ return 0;
23176 ++}
23177 ++
23178 ++int
23179 ++gr_handle_chroot_mount(const struct dentry *dentry,
23180 ++ const struct vfsmount *mnt, const char *dev_name)
23181 ++{
23182 ++#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
23183 ++ if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
23184 ++ gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name, dentry, mnt);
23185 ++ return -EPERM;
23186 ++ }
23187 ++#endif
23188 ++ return 0;
23189 ++}
23190 ++
23191 ++int
23192 ++gr_handle_chroot_pivot(void)
23193 ++{
23194 ++#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
23195 ++ if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
23196 ++ gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
23197 ++ return -EPERM;
23198 ++ }
23199 ++#endif
23200 ++ return 0;
23201 ++}
23202 ++
23203 ++int
23204 ++gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
23205 ++{
23206 ++#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
23207 ++ if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
23208 ++ !gr_is_outside_chroot(dentry, mnt)) {
23209 ++ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
23210 ++ return -EPERM;
23211 ++ }
23212 ++#endif
23213 ++ return 0;
23214 ++}
23215 ++
23216 ++void
23217 ++gr_handle_chroot_caps(struct task_struct *task)
23218 ++{
23219 ++#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
23220 ++ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
23221 ++ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
23222 ++ task->cap_permitted =
23223 ++ cap_drop(task->cap_permitted, chroot_caps);
23224 ++ task->cap_inheritable =
23225 ++ cap_drop(task->cap_inheritable, chroot_caps);
23226 ++ task->cap_effective =
23227 ++ cap_drop(task->cap_effective, chroot_caps);
23228 ++ }
23229 ++#endif
23230 ++ return;
23231 ++}
23232 ++
23233 ++int
23234 ++gr_handle_chroot_sysctl(const int op)
23235 ++{
23236 ++#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
23237 ++ if (grsec_enable_chroot_sysctl && proc_is_chrooted(current)
23238 ++ && (op & MAY_WRITE))
23239 ++ return -EACCES;
23240 ++#endif
23241 ++ return 0;
23242 ++}
23243 ++
23244 ++void
23245 ++gr_handle_chroot_chdir(struct path *path)
23246 ++{
23247 ++#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
23248 ++ if (grsec_enable_chroot_chdir)
23249 ++ set_fs_pwd(current->fs, path);
23250 ++#endif
23251 ++ return;
23252 ++}
23253 ++
23254 ++int
23255 ++gr_handle_chroot_chmod(const struct dentry *dentry,
23256 ++ const struct vfsmount *mnt, const int mode)
23257 ++{
23258 ++#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
23259 ++ if (grsec_enable_chroot_chmod &&
23260 ++ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
23261 ++ proc_is_chrooted(current)) {
23262 ++ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
23263 ++ return -EPERM;
23264 ++ }
23265 ++#endif
23266 ++ return 0;
23267 ++}
23268 ++
23269 ++#ifdef CONFIG_SECURITY
23270 ++EXPORT_SYMBOL(gr_handle_chroot_caps);
23271 ++#endif
23272 +diff -urNp linux-2.6.27.10/grsecurity/grsec_disabled.c linux-2.6.27.10/grsecurity/grsec_disabled.c
23273 +--- linux-2.6.27.10/grsecurity/grsec_disabled.c 1969-12-31 19:00:00.000000000 -0500
23274 ++++ linux-2.6.27.10/grsecurity/grsec_disabled.c 2008-11-18 03:38:45.000000000 -0500
23275 +@@ -0,0 +1,418 @@
23276 ++#include <linux/kernel.h>
23277 ++#include <linux/module.h>
23278 ++#include <linux/sched.h>
23279 ++#include <linux/file.h>
23280 ++#include <linux/fs.h>
23281 ++#include <linux/kdev_t.h>
23282 ++#include <linux/net.h>
23283 ++#include <linux/in.h>
23284 ++#include <linux/ip.h>
23285 ++#include <linux/skbuff.h>
23286 ++#include <linux/sysctl.h>
23287 ++
23288 ++#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
23289 ++void
23290 ++pax_set_initial_flags(struct linux_binprm *bprm)
23291 ++{
23292 ++ return;
23293 ++}
23294 ++#endif
23295 ++
23296 ++#ifdef CONFIG_SYSCTL
23297 ++__u32
23298 ++gr_handle_sysctl(const struct ctl_table * table, const int op)
23299 ++{
23300 ++ return 0;
23301 ++}
23302 ++#endif
23303 ++
23304 ++int
23305 ++gr_acl_is_enabled(void)
23306 ++{
23307 ++ return 0;
23308 ++}
23309 ++
23310 ++int
23311 ++gr_handle_rawio(const struct inode *inode)
23312 ++{
23313 ++ return 0;
23314 ++}
23315 ++
23316 ++void
23317 ++gr_acl_handle_psacct(struct task_struct *task, const long code)
23318 ++{
23319 ++ return;
23320 ++}
23321 ++
23322 ++int
23323 ++gr_handle_ptrace(struct task_struct *task, const long request)
23324 ++{
23325 ++ return 0;
23326 ++}
23327 ++
23328 ++int
23329 ++gr_handle_proc_ptrace(struct task_struct *task)
23330 ++{
23331 ++ return 0;
23332 ++}
23333 ++
23334 ++void
23335 ++gr_learn_resource(const struct task_struct *task,
23336 ++ const int res, const unsigned long wanted, const int gt)
23337 ++{
23338 ++ return;
23339 ++}
23340 ++
23341 ++int
23342 ++gr_set_acls(const int type)
23343 ++{
23344 ++ return 0;
23345 ++}
23346 ++
23347 ++int
23348 ++gr_check_hidden_task(const struct task_struct *tsk)
23349 ++{
23350 ++ return 0;
23351 ++}
23352 ++
23353 ++int
23354 ++gr_check_protected_task(const struct task_struct *task)
23355 ++{
23356 ++ return 0;
23357 ++}
23358 ++
23359 ++void
23360 ++gr_copy_label(struct task_struct *tsk)
23361 ++{
23362 ++ return;
23363 ++}
23364 ++
23365 ++void
23366 ++gr_set_pax_flags(struct task_struct *task)
23367 ++{
23368 ++ return;
23369 ++}
23370 ++
23371 ++int
23372 ++gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt)
23373 ++{
23374 ++ return 0;
23375 ++}
23376 ++
23377 ++void
23378 ++gr_handle_delete(const ino_t ino, const dev_t dev)
23379 ++{
23380 ++ return;
23381 ++}
23382 ++
23383 ++void
23384 ++gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
23385 ++{
23386 ++ return;
23387 ++}
23388 ++
23389 ++void
23390 ++gr_handle_crash(struct task_struct *task, const int sig)
23391 ++{
23392 ++ return;
23393 ++}
23394 ++
23395 ++int
23396 ++gr_check_crash_exec(const struct file *filp)
23397 ++{
23398 ++ return 0;
23399 ++}
23400 ++
23401 ++int
23402 ++gr_check_crash_uid(const uid_t uid)
23403 ++{
23404 ++ return 0;
23405 ++}
23406 ++
23407 ++void
23408 ++gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
23409 ++ struct dentry *old_dentry,
23410 ++ struct dentry *new_dentry,
23411 ++ struct vfsmount *mnt, const __u8 replace)
23412 ++{
23413 ++ return;
23414 ++}
23415 ++
23416 ++int
23417 ++gr_search_socket(const int family, const int type, const int protocol)
23418 ++{
23419 ++ return 1;
23420 ++}
23421 ++
23422 ++int
23423 ++gr_search_connectbind(const int mode, const struct socket *sock,
23424 ++ const struct sockaddr_in *addr)
23425 ++{
23426 ++ return 1;
23427 ++}
23428 ++
23429 ++int
23430 ++gr_task_is_capable(struct task_struct *task, const int cap)
23431 ++{
23432 ++ return 1;
23433 ++}
23434 ++
23435 ++int
23436 ++gr_is_capable_nolog(const int cap)
23437 ++{
23438 ++ return 1;
23439 ++}
23440 ++
23441 ++void
23442 ++gr_handle_alertkill(struct task_struct *task)
23443 ++{
23444 ++ return;
23445 ++}
23446 ++
23447 ++__u32
23448 ++gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
23449 ++{
23450 ++ return 1;
23451 ++}
23452 ++
23453 ++__u32
23454 ++gr_acl_handle_hidden_file(const struct dentry * dentry,
23455 ++ const struct vfsmount * mnt)
23456 ++{
23457 ++ return 1;
23458 ++}
23459 ++
23460 ++__u32
23461 ++gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
23462 ++ const int fmode)
23463 ++{
23464 ++ return 1;
23465 ++}
23466 ++
23467 ++__u32
23468 ++gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
23469 ++{
23470 ++ return 1;
23471 ++}
23472 ++
23473 ++__u32
23474 ++gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
23475 ++{
23476 ++ return 1;
23477 ++}
23478 ++
23479 ++int
23480 ++gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
23481 ++ unsigned int *vm_flags)
23482 ++{
23483 ++ return 1;
23484 ++}
23485 ++
23486 ++__u32
23487 ++gr_acl_handle_truncate(const struct dentry * dentry,
23488 ++ const struct vfsmount * mnt)
23489 ++{
23490 ++ return 1;
23491 ++}
23492 ++
23493 ++__u32
23494 ++gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
23495 ++{
23496 ++ return 1;
23497 ++}
23498 ++
23499 ++__u32
23500 ++gr_acl_handle_access(const struct dentry * dentry,
23501 ++ const struct vfsmount * mnt, const int fmode)
23502 ++{
23503 ++ return 1;
23504 ++}
23505 ++
23506 ++__u32
23507 ++gr_acl_handle_fchmod(const struct dentry * dentry, const struct vfsmount * mnt,
23508 ++ mode_t mode)
23509 ++{
23510 ++ return 1;
23511 ++}
23512 ++
23513 ++__u32
23514 ++gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
23515 ++ mode_t mode)
23516 ++{
23517 ++ return 1;
23518 ++}
23519 ++
23520 ++__u32
23521 ++gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
23522 ++{
23523 ++ return 1;
23524 ++}
23525 ++
23526 ++void
23527 ++grsecurity_init(void)
23528 ++{
23529 ++ return;
23530 ++}
23531 ++
23532 ++__u32
23533 ++gr_acl_handle_mknod(const struct dentry * new_dentry,
23534 ++ const struct dentry * parent_dentry,
23535 ++ const struct vfsmount * parent_mnt,
23536 ++ const int mode)
23537 ++{
23538 ++ return 1;
23539 ++}
23540 ++
23541 ++__u32
23542 ++gr_acl_handle_mkdir(const struct dentry * new_dentry,
23543 ++ const struct dentry * parent_dentry,
23544 ++ const struct vfsmount * parent_mnt)
23545 ++{
23546 ++ return 1;
23547 ++}
23548 ++
23549 ++__u32
23550 ++gr_acl_handle_symlink(const struct dentry * new_dentry,
23551 ++ const struct dentry * parent_dentry,
23552 ++ const struct vfsmount * parent_mnt, const char *from)
23553 ++{
23554 ++ return 1;
23555 ++}
23556 ++
23557 ++__u32
23558 ++gr_acl_handle_link(const struct dentry * new_dentry,
23559 ++ const struct dentry * parent_dentry,
23560 ++ const struct vfsmount * parent_mnt,
23561 ++ const struct dentry * old_dentry,
23562 ++ const struct vfsmount * old_mnt, const char *to)
23563 ++{
23564 ++ return 1;
23565 ++}
23566 ++
23567 ++int
23568 ++gr_acl_handle_rename(const struct dentry *new_dentry,
23569 ++ const struct dentry *parent_dentry,
23570 ++ const struct vfsmount *parent_mnt,
23571 ++ const struct dentry *old_dentry,
23572 ++ const struct inode *old_parent_inode,
23573 ++ const struct vfsmount *old_mnt, const char *newname)
23574 ++{
23575 ++ return 0;
23576 ++}
23577 ++
23578 ++int
23579 ++gr_acl_handle_filldir(const struct file *file, const char *name,
23580 ++ const int namelen, const ino_t ino)
23581 ++{
23582 ++ return 1;
23583 ++}
23584 ++
23585 ++int
23586 ++gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
23587 ++ const time_t shm_createtime, const uid_t cuid, const int shmid)
23588 ++{
23589 ++ return 1;
23590 ++}
23591 ++
23592 ++int
23593 ++gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
23594 ++{
23595 ++ return 1;
23596 ++}
23597 ++
23598 ++int
23599 ++gr_search_accept(const struct socket *sock)
23600 ++{
23601 ++ return 1;
23602 ++}
23603 ++
23604 ++int
23605 ++gr_search_listen(const struct socket *sock)
23606 ++{
23607 ++ return 1;
23608 ++}
23609 ++
23610 ++int
23611 ++gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
23612 ++{
23613 ++ return 1;
23614 ++}
23615 ++
23616 ++__u32
23617 ++gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
23618 ++{
23619 ++ return 1;
23620 ++}
23621 ++
23622 ++__u32
23623 ++gr_acl_handle_creat(const struct dentry * dentry,
23624 ++ const struct dentry * p_dentry,
23625 ++ const struct vfsmount * p_mnt, const int fmode,
23626 ++ const int imode)
23627 ++{
23628 ++ return 1;
23629 ++}
23630 ++
23631 ++void
23632 ++gr_acl_handle_exit(void)
23633 ++{
23634 ++ return;
23635 ++}
23636 ++
23637 ++int
23638 ++gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
23639 ++{
23640 ++ return 1;
23641 ++}
23642 ++
23643 ++void
23644 ++gr_set_role_label(const uid_t uid, const gid_t gid)
23645 ++{
23646 ++ return;
23647 ++}
23648 ++
23649 ++int
23650 ++gr_acl_handle_procpidmem(const struct task_struct *task)
23651 ++{
23652 ++ return 0;
23653 ++}
23654 ++
23655 ++int
23656 ++gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
23657 ++{
23658 ++ return 1;
23659 ++}
23660 ++
23661 ++int
23662 ++gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
23663 ++{
23664 ++ return 1;
23665 ++}
23666 ++
23667 ++void
23668 ++gr_set_kernel_label(struct task_struct *task)
23669 ++{
23670 ++ return;
23671 ++}
23672 ++
23673 ++int
23674 ++gr_check_user_change(int real, int effective, int fs)
23675 ++{
23676 ++ return 0;
23677 ++}
23678 ++
23679 ++int
23680 ++gr_check_group_change(int real, int effective, int fs)
23681 ++{
23682 ++ return 0;
23683 ++}
23684 ++
23685 ++
23686 ++EXPORT_SYMBOL(gr_task_is_capable);
23687 ++EXPORT_SYMBOL(gr_is_capable_nolog);
23688 ++EXPORT_SYMBOL(gr_learn_resource);
23689 ++EXPORT_SYMBOL(gr_set_kernel_label);
23690 ++#ifdef CONFIG_SECURITY
23691 ++EXPORT_SYMBOL(gr_check_user_change);
23692 ++EXPORT_SYMBOL(gr_check_group_change);
23693 ++#endif
23694 +diff -urNp linux-2.6.27.10/grsecurity/grsec_exec.c linux-2.6.27.10/grsecurity/grsec_exec.c
23695 +--- linux-2.6.27.10/grsecurity/grsec_exec.c 1969-12-31 19:00:00.000000000 -0500
23696 ++++ linux-2.6.27.10/grsecurity/grsec_exec.c 2008-11-18 03:38:45.000000000 -0500
23697 +@@ -0,0 +1,88 @@
23698 ++#include <linux/kernel.h>
23699 ++#include <linux/sched.h>
23700 ++#include <linux/file.h>
23701 ++#include <linux/binfmts.h>
23702 ++#include <linux/smp_lock.h>
23703 ++#include <linux/fs.h>
23704 ++#include <linux/types.h>
23705 ++#include <linux/grdefs.h>
23706 ++#include <linux/grinternal.h>
23707 ++#include <linux/capability.h>
23708 ++
23709 ++#include <asm/uaccess.h>
23710 ++
23711 ++#ifdef CONFIG_GRKERNSEC_EXECLOG
23712 ++static char gr_exec_arg_buf[132];
23713 ++static DECLARE_MUTEX(gr_exec_arg_sem);
23714 ++#endif
23715 ++
23716 ++int
23717 ++gr_handle_nproc(void)
23718 ++{
23719 ++#ifdef CONFIG_GRKERNSEC_EXECVE
23720 ++ if (grsec_enable_execve && current->user &&
23721 ++ (atomic_read(&current->user->processes) >
23722 ++ current->signal->rlim[RLIMIT_NPROC].rlim_cur) &&
23723 ++ !capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE)) {
23724 ++ gr_log_noargs(GR_DONT_AUDIT, GR_NPROC_MSG);
23725 ++ return -EAGAIN;
23726 ++ }
23727 ++#endif
23728 ++ return 0;
23729 ++}
23730 ++
23731 ++void
23732 ++gr_handle_exec_args(struct linux_binprm *bprm, const char __user *__user *argv)
23733 ++{
23734 ++#ifdef CONFIG_GRKERNSEC_EXECLOG
23735 ++ char *grarg = gr_exec_arg_buf;
23736 ++ unsigned int i, x, execlen = 0;
23737 ++ char c;
23738 ++
23739 ++ if (!((grsec_enable_execlog && grsec_enable_group &&
23740 ++ in_group_p(grsec_audit_gid))
23741 ++ || (grsec_enable_execlog && !grsec_enable_group)))
23742 ++ return;
23743 ++
23744 ++ down(&gr_exec_arg_sem);
23745 ++ memset(grarg, 0, sizeof(gr_exec_arg_buf));
23746 ++
23747 ++ if (unlikely(argv == NULL))
23748 ++ goto log;
23749 ++
23750 ++ for (i = 0; i < bprm->argc && execlen < 128; i++) {
23751 ++ const char __user *p;
23752 ++ unsigned int len;
23753 ++
23754 ++ if (copy_from_user(&p, argv + i, sizeof(p)))
23755 ++ goto log;
23756 ++ if (!p)
23757 ++ goto log;
23758 ++ len = strnlen_user(p, 128 - execlen);
23759 ++ if (len > 128 - execlen)
23760 ++ len = 128 - execlen;
23761 ++ else if (len > 0)
23762 ++ len--;
23763 ++ if (copy_from_user(grarg + execlen, p, len))
23764 ++ goto log;
23765 ++
23766 ++ /* rewrite unprintable characters */
23767 ++ for (x = 0; x < len; x++) {
23768 ++ c = *(grarg + execlen + x);
23769 ++ if (c < 32 || c > 126)
23770 ++ *(grarg + execlen + x) = ' ';
23771 ++ }
23772 ++
23773 ++ execlen += len;
23774 ++ *(grarg + execlen) = ' ';
23775 ++ *(grarg + execlen + 1) = '\0';
23776 ++ execlen++;
23777 ++ }
23778 ++
23779 ++ log:
23780 ++ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
23781 ++ bprm->file->f_path.mnt, grarg);
23782 ++ up(&gr_exec_arg_sem);
23783 ++#endif
23784 ++ return;
23785 ++}
23786 +diff -urNp linux-2.6.27.10/grsecurity/grsec_fifo.c linux-2.6.27.10/grsecurity/grsec_fifo.c
23787 +--- linux-2.6.27.10/grsecurity/grsec_fifo.c 1969-12-31 19:00:00.000000000 -0500
23788 ++++ linux-2.6.27.10/grsecurity/grsec_fifo.c 2008-11-18 03:38:45.000000000 -0500
23789 +@@ -0,0 +1,22 @@
23790 ++#include <linux/kernel.h>
23791 ++#include <linux/sched.h>
23792 ++#include <linux/fs.h>
23793 ++#include <linux/file.h>
23794 ++#include <linux/grinternal.h>
23795 ++
23796 ++int
23797 ++gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
23798 ++ const struct dentry *dir, const int flag, const int acc_mode)
23799 ++{
23800 ++#ifdef CONFIG_GRKERNSEC_FIFO
23801 ++ if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
23802 ++ !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
23803 ++ (dentry->d_inode->i_uid != dir->d_inode->i_uid) &&
23804 ++ (current->fsuid != dentry->d_inode->i_uid)) {
23805 ++ if (!generic_permission(dentry->d_inode, acc_mode, NULL))
23806 ++ gr_log_fs_int2(GR_DONT_AUDIT, GR_FIFO_MSG, dentry, mnt, dentry->d_inode->i_uid, dentry->d_inode->i_gid);
23807 ++ return -EACCES;
23808 ++ }
23809 ++#endif
23810 ++ return 0;
23811 ++}
23812 +diff -urNp linux-2.6.27.10/grsecurity/grsec_fork.c linux-2.6.27.10/grsecurity/grsec_fork.c
23813 +--- linux-2.6.27.10/grsecurity/grsec_fork.c 1969-12-31 19:00:00.000000000 -0500
23814 ++++ linux-2.6.27.10/grsecurity/grsec_fork.c 2008-11-18 03:38:45.000000000 -0500
23815 +@@ -0,0 +1,15 @@
23816 ++#include <linux/kernel.h>
23817 ++#include <linux/sched.h>
23818 ++#include <linux/grsecurity.h>
23819 ++#include <linux/grinternal.h>
23820 ++#include <linux/errno.h>
23821 ++
23822 ++void
23823 ++gr_log_forkfail(const int retval)
23824 ++{
23825 ++#ifdef CONFIG_GRKERNSEC_FORKFAIL
23826 ++ if (grsec_enable_forkfail && retval != -ERESTARTNOINTR)
23827 ++ gr_log_int(GR_DONT_AUDIT, GR_FAILFORK_MSG, retval);
23828 ++#endif
23829 ++ return;
23830 ++}
23831 +diff -urNp linux-2.6.27.10/grsecurity/grsec_init.c linux-2.6.27.10/grsecurity/grsec_init.c
23832 +--- linux-2.6.27.10/grsecurity/grsec_init.c 1969-12-31 19:00:00.000000000 -0500
23833 ++++ linux-2.6.27.10/grsecurity/grsec_init.c 2008-11-18 03:38:45.000000000 -0500
23834 +@@ -0,0 +1,230 @@
23835 ++#include <linux/kernel.h>
23836 ++#include <linux/sched.h>
23837 ++#include <linux/mm.h>
23838 ++#include <linux/smp_lock.h>
23839 ++#include <linux/gracl.h>
23840 ++#include <linux/slab.h>
23841 ++#include <linux/vmalloc.h>
23842 ++#include <linux/percpu.h>
23843 ++
23844 ++int grsec_enable_link;
23845 ++int grsec_enable_dmesg;
23846 ++int grsec_enable_fifo;
23847 ++int grsec_enable_execve;
23848 ++int grsec_enable_execlog;
23849 ++int grsec_enable_signal;
23850 ++int grsec_enable_forkfail;
23851 ++int grsec_enable_time;
23852 ++int grsec_enable_audit_textrel;
23853 ++int grsec_enable_group;
23854 ++int grsec_audit_gid;
23855 ++int grsec_enable_chdir;
23856 ++int grsec_enable_audit_ipc;
23857 ++int grsec_enable_mount;
23858 ++int grsec_enable_chroot_findtask;
23859 ++int grsec_enable_chroot_mount;
23860 ++int grsec_enable_chroot_shmat;
23861 ++int grsec_enable_chroot_fchdir;
23862 ++int grsec_enable_chroot_double;
23863 ++int grsec_enable_chroot_pivot;
23864 ++int grsec_enable_chroot_chdir;
23865 ++int grsec_enable_chroot_chmod;
23866 ++int grsec_enable_chroot_mknod;
23867 ++int grsec_enable_chroot_nice;
23868 ++int grsec_enable_chroot_execlog;
23869 ++int grsec_enable_chroot_caps;
23870 ++int grsec_enable_chroot_sysctl;
23871 ++int grsec_enable_chroot_unix;
23872 ++int grsec_enable_tpe;
23873 ++int grsec_tpe_gid;
23874 ++int grsec_enable_tpe_all;
23875 ++int grsec_enable_socket_all;
23876 ++int grsec_socket_all_gid;
23877 ++int grsec_enable_socket_client;
23878 ++int grsec_socket_client_gid;
23879 ++int grsec_enable_socket_server;
23880 ++int grsec_socket_server_gid;
23881 ++int grsec_resource_logging;
23882 ++int grsec_lock;
23883 ++
23884 ++DEFINE_SPINLOCK(grsec_alert_lock);
23885 ++unsigned long grsec_alert_wtime = 0;
23886 ++unsigned long grsec_alert_fyet = 0;
23887 ++
23888 ++DEFINE_SPINLOCK(grsec_audit_lock);
23889 ++
23890 ++DEFINE_RWLOCK(grsec_exec_file_lock);
23891 ++
23892 ++char *gr_shared_page[4];
23893 ++
23894 ++char *gr_alert_log_fmt;
23895 ++char *gr_audit_log_fmt;
23896 ++char *gr_alert_log_buf;
23897 ++char *gr_audit_log_buf;
23898 ++
23899 ++extern struct gr_arg *gr_usermode;
23900 ++extern unsigned char *gr_system_salt;
23901 ++extern unsigned char *gr_system_sum;
23902 ++
23903 ++void
23904 ++grsecurity_init(void)
23905 ++{
23906 ++ int j;
23907 ++ /* create the per-cpu shared pages */
23908 ++
23909 ++#ifdef CONFIG_X86
23910 ++ memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
23911 ++#endif
23912 ++
23913 ++ for (j = 0; j < 4; j++) {
23914 ++ gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE);
23915 ++ if (gr_shared_page[j] == NULL) {
23916 ++ panic("Unable to allocate grsecurity shared page");
23917 ++ return;
23918 ++ }
23919 ++ }
23920 ++
23921 ++ /* allocate log buffers */
23922 ++ gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
23923 ++ if (!gr_alert_log_fmt) {
23924 ++ panic("Unable to allocate grsecurity alert log format buffer");
23925 ++ return;
23926 ++ }
23927 ++ gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
23928 ++ if (!gr_audit_log_fmt) {
23929 ++ panic("Unable to allocate grsecurity audit log format buffer");
23930 ++ return;
23931 ++ }
23932 ++ gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
23933 ++ if (!gr_alert_log_buf) {
23934 ++ panic("Unable to allocate grsecurity alert log buffer");
23935 ++ return;
23936 ++ }
23937 ++ gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
23938 ++ if (!gr_audit_log_buf) {
23939 ++ panic("Unable to allocate grsecurity audit log buffer");
23940 ++ return;
23941 ++ }
23942 ++
23943 ++ /* allocate memory for authentication structure */
23944 ++ gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
23945 ++ gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
23946 ++ gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
23947 ++
23948 ++ if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
23949 ++ panic("Unable to allocate grsecurity authentication structure");
23950 ++ return;
23951 ++ }
23952 ++
23953 ++#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
23954 ++#ifndef CONFIG_GRKERNSEC_SYSCTL
23955 ++ grsec_lock = 1;
23956 ++#endif
23957 ++#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
23958 ++ grsec_enable_audit_textrel = 1;
23959 ++#endif
23960 ++#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
23961 ++ grsec_enable_group = 1;
23962 ++ grsec_audit_gid = CONFIG_GRKERNSEC_AUDIT_GID;
23963 ++#endif
23964 ++#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
23965 ++ grsec_enable_chdir = 1;
23966 ++#endif
23967 ++#ifdef CONFIG_GRKERNSEC_AUDIT_IPC
23968 ++ grsec_enable_audit_ipc = 1;
23969 ++#endif
23970 ++#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
23971 ++ grsec_enable_mount = 1;
23972 ++#endif
23973 ++#ifdef CONFIG_GRKERNSEC_LINK
23974 ++ grsec_enable_link = 1;
23975 ++#endif
23976 ++#ifdef CONFIG_GRKERNSEC_DMESG
23977 ++ grsec_enable_dmesg = 1;
23978 ++#endif
23979 ++#ifdef CONFIG_GRKERNSEC_FIFO
23980 ++ grsec_enable_fifo = 1;
23981 ++#endif
23982 ++#ifdef CONFIG_GRKERNSEC_EXECVE
23983 ++ grsec_enable_execve = 1;
23984 ++#endif
23985 ++#ifdef CONFIG_GRKERNSEC_EXECLOG
23986 ++ grsec_enable_execlog = 1;
23987 ++#endif
23988 ++#ifdef CONFIG_GRKERNSEC_SIGNAL
23989 ++ grsec_enable_signal = 1;
23990 ++#endif
23991 ++#ifdef CONFIG_GRKERNSEC_FORKFAIL
23992 ++ grsec_enable_forkfail = 1;
23993 ++#endif
23994 ++#ifdef CONFIG_GRKERNSEC_TIME
23995 ++ grsec_enable_time = 1;
23996 ++#endif
23997 ++#ifdef CONFIG_GRKERNSEC_RESLOG
23998 ++ grsec_resource_logging = 1;
23999 ++#endif
24000 ++#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
24001 ++ grsec_enable_chroot_findtask = 1;
24002 ++#endif
24003 ++#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
24004 ++ grsec_enable_chroot_unix = 1;
24005 ++#endif
24006 ++#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
24007 ++ grsec_enable_chroot_mount = 1;
24008 ++#endif
24009 ++#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
24010 ++ grsec_enable_chroot_fchdir = 1;
24011 ++#endif
24012 ++#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
24013 ++ grsec_enable_chroot_shmat = 1;
24014 ++#endif
24015 ++#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
24016 ++ grsec_enable_chroot_double = 1;
24017 ++#endif
24018 ++#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
24019 ++ grsec_enable_chroot_pivot = 1;
24020 ++#endif
24021 ++#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
24022 ++ grsec_enable_chroot_chdir = 1;
24023 ++#endif
24024 ++#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
24025 ++ grsec_enable_chroot_chmod = 1;
24026 ++#endif
24027 ++#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
24028 ++ grsec_enable_chroot_mknod = 1;
24029 ++#endif
24030 ++#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
24031 ++ grsec_enable_chroot_nice = 1;
24032 ++#endif
24033 ++#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
24034 ++ grsec_enable_chroot_execlog = 1;
24035 ++#endif
24036 ++#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
24037 ++ grsec_enable_chroot_caps = 1;
24038 ++#endif
24039 ++#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
24040 ++ grsec_enable_chroot_sysctl = 1;
24041 ++#endif
24042 ++#ifdef CONFIG_GRKERNSEC_TPE
24043 ++ grsec_enable_tpe = 1;
24044 ++ grsec_tpe_gid = CONFIG_GRKERNSEC_TPE_GID;
24045 ++#ifdef CONFIG_GRKERNSEC_TPE_ALL
24046 ++ grsec_enable_tpe_all = 1;
24047 ++#endif
24048 ++#endif
24049 ++#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
24050 ++ grsec_enable_socket_all = 1;
24051 ++ grsec_socket_all_gid = CONFIG_GRKERNSEC_SOCKET_ALL_GID;
24052 ++#endif
24053 ++#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
24054 ++ grsec_enable_socket_client = 1;
24055 ++ grsec_socket_client_gid = CONFIG_GRKERNSEC_SOCKET_CLIENT_GID;
24056 ++#endif
24057 ++#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
24058 ++ grsec_enable_socket_server = 1;
24059 ++ grsec_socket_server_gid = CONFIG_GRKERNSEC_SOCKET_SERVER_GID;
24060 ++#endif
24061 ++#endif
24062 ++
24063 ++ return;
24064 ++}
24065 +diff -urNp linux-2.6.27.10/grsecurity/grsec_ipc.c linux-2.6.27.10/grsecurity/grsec_ipc.c
24066 +--- linux-2.6.27.10/grsecurity/grsec_ipc.c 1969-12-31 19:00:00.000000000 -0500
24067 ++++ linux-2.6.27.10/grsecurity/grsec_ipc.c 2008-11-18 03:38:45.000000000 -0500
24068 +@@ -0,0 +1,81 @@
24069 ++#include <linux/kernel.h>
24070 ++#include <linux/sched.h>
24071 ++#include <linux/types.h>
24072 ++#include <linux/ipc.h>
24073 ++#include <linux/grsecurity.h>
24074 ++#include <linux/grinternal.h>
24075 ++
24076 ++void
24077 ++gr_log_msgget(const int ret, const int msgflg)
24078 ++{
24079 ++#ifdef CONFIG_GRKERNSEC_AUDIT_IPC
24080 ++ if (((grsec_enable_group && in_group_p(grsec_audit_gid) &&
24081 ++ grsec_enable_audit_ipc) || (grsec_enable_audit_ipc &&
24082 ++ !grsec_enable_group)) && (ret >= 0)
24083 ++ && (msgflg & IPC_CREAT))
24084 ++ gr_log_noargs(GR_DO_AUDIT, GR_MSGQ_AUDIT_MSG);
24085 ++#endif
24086 ++ return;
24087 ++}
24088 ++
24089 ++void
24090 ++gr_log_msgrm(const uid_t uid, const uid_t cuid)
24091 ++{
24092 ++#ifdef CONFIG_GRKERNSEC_AUDIT_IPC
24093 ++ if ((grsec_enable_group && in_group_p(grsec_audit_gid) &&
24094 ++ grsec_enable_audit_ipc) ||
24095 ++ (grsec_enable_audit_ipc && !grsec_enable_group))
24096 ++ gr_log_int_int(GR_DO_AUDIT, GR_MSGQR_AUDIT_MSG, uid, cuid);
24097 ++#endif
24098 ++ return;
24099 ++}
24100 ++
24101 ++void
24102 ++gr_log_semget(const int err, const int semflg)
24103 ++{
24104 ++#ifdef CONFIG_GRKERNSEC_AUDIT_IPC
24105 ++ if (((grsec_enable_group && in_group_p(grsec_audit_gid) &&
24106 ++ grsec_enable_audit_ipc) || (grsec_enable_audit_ipc &&
24107 ++ !grsec_enable_group)) && (err >= 0)
24108 ++ && (semflg & IPC_CREAT))
24109 ++ gr_log_noargs(GR_DO_AUDIT, GR_SEM_AUDIT_MSG);
24110 ++#endif
24111 ++ return;
24112 ++}
24113 ++
24114 ++void
24115 ++gr_log_semrm(const uid_t uid, const uid_t cuid)
24116 ++{
24117 ++#ifdef CONFIG_GRKERNSEC_AUDIT_IPC
24118 ++ if ((grsec_enable_group && in_group_p(grsec_audit_gid) &&
24119 ++ grsec_enable_audit_ipc) ||
24120 ++ (grsec_enable_audit_ipc && !grsec_enable_group))
24121 ++ gr_log_int_int(GR_DO_AUDIT, GR_SEMR_AUDIT_MSG, uid, cuid);
24122 ++#endif
24123 ++ return;
24124 ++}
24125 ++
24126 ++void
24127 ++gr_log_shmget(const int err, const int shmflg, const size_t size)
24128 ++{
24129 ++#ifdef CONFIG_GRKERNSEC_AUDIT_IPC
24130 ++ if (((grsec_enable_group && in_group_p(grsec_audit_gid) &&
24131 ++ grsec_enable_audit_ipc) || (grsec_enable_audit_ipc &&
24132 ++ !grsec_enable_group)) && (err >= 0)
24133 ++ && (shmflg & IPC_CREAT))
24134 ++ gr_log_int(GR_DO_AUDIT, GR_SHM_AUDIT_MSG, size);
24135 ++#endif
24136 ++ return;
24137 ++}
24138 ++
24139 ++void
24140 ++gr_log_shmrm(const uid_t uid, const uid_t cuid)
24141 ++{
24142 ++#ifdef CONFIG_GRKERNSEC_AUDIT_IPC
24143 ++ if ((grsec_enable_group && in_group_p(grsec_audit_gid) &&
24144 ++ grsec_enable_audit_ipc) ||
24145 ++ (grsec_enable_audit_ipc && !grsec_enable_group))
24146 ++ gr_log_int_int(GR_DO_AUDIT, GR_SHMR_AUDIT_MSG, uid, cuid);
24147 ++#endif
24148 ++ return;
24149 ++}
24150 +diff -urNp linux-2.6.27.10/grsecurity/grsec_link.c linux-2.6.27.10/grsecurity/grsec_link.c
24151 +--- linux-2.6.27.10/grsecurity/grsec_link.c 1969-12-31 19:00:00.000000000 -0500
24152 ++++ linux-2.6.27.10/grsecurity/grsec_link.c 2008-11-18 03:38:45.000000000 -0500
24153 +@@ -0,0 +1,39 @@
24154 ++#include <linux/kernel.h>
24155 ++#include <linux/sched.h>
24156 ++#include <linux/fs.h>
24157 ++#include <linux/file.h>
24158 ++#include <linux/grinternal.h>
24159 ++
24160 ++int
24161 ++gr_handle_follow_link(const struct inode *parent,
24162 ++ const struct inode *inode,
24163 ++ const struct dentry *dentry, const struct vfsmount *mnt)
24164 ++{
24165 ++#ifdef CONFIG_GRKERNSEC_LINK
24166 ++ if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
24167 ++ (parent->i_mode & S_ISVTX) && (parent->i_uid != inode->i_uid) &&
24168 ++ (parent->i_mode & S_IWOTH) && (current->fsuid != inode->i_uid)) {
24169 ++ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
24170 ++ return -EACCES;
24171 ++ }
24172 ++#endif
24173 ++ return 0;
24174 ++}
24175 ++
24176 ++int
24177 ++gr_handle_hardlink(const struct dentry *dentry,
24178 ++ const struct vfsmount *mnt,
24179 ++ struct inode *inode, const int mode, const char *to)
24180 ++{
24181 ++#ifdef CONFIG_GRKERNSEC_LINK
24182 ++ if (grsec_enable_link && current->fsuid != inode->i_uid &&
24183 ++ (!S_ISREG(mode) || (mode & S_ISUID) ||
24184 ++ ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP)) ||
24185 ++ (generic_permission(inode, MAY_READ | MAY_WRITE, NULL))) &&
24186 ++ !capable(CAP_FOWNER) && current->uid) {
24187 ++ gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to);
24188 ++ return -EPERM;
24189 ++ }
24190 ++#endif
24191 ++ return 0;
24192 ++}
24193 +diff -urNp linux-2.6.27.10/grsecurity/grsec_log.c linux-2.6.27.10/grsecurity/grsec_log.c
24194 +--- linux-2.6.27.10/grsecurity/grsec_log.c 1969-12-31 19:00:00.000000000 -0500
24195 ++++ linux-2.6.27.10/grsecurity/grsec_log.c 2008-11-18 03:38:45.000000000 -0500
24196 +@@ -0,0 +1,269 @@
24197 ++#include <linux/kernel.h>
24198 ++#include <linux/sched.h>
24199 ++#include <linux/file.h>
24200 ++#include <linux/tty.h>
24201 ++#include <linux/fs.h>
24202 ++#include <linux/grinternal.h>
24203 ++
24204 ++#define BEGIN_LOCKS(x) \
24205 ++ read_lock(&tasklist_lock); \
24206 ++ read_lock(&grsec_exec_file_lock); \
24207 ++ if (x != GR_DO_AUDIT) \
24208 ++ spin_lock(&grsec_alert_lock); \
24209 ++ else \
24210 ++ spin_lock(&grsec_audit_lock)
24211 ++
24212 ++#define END_LOCKS(x) \
24213 ++ if (x != GR_DO_AUDIT) \
24214 ++ spin_unlock(&grsec_alert_lock); \
24215 ++ else \
24216 ++ spin_unlock(&grsec_audit_lock); \
24217 ++ read_unlock(&grsec_exec_file_lock); \
24218 ++ read_unlock(&tasklist_lock); \
24219 ++ if (x == GR_DONT_AUDIT) \
24220 ++ gr_handle_alertkill(current)
24221 ++
24222 ++enum {
24223 ++ FLOODING,
24224 ++ NO_FLOODING
24225 ++};
24226 ++
24227 ++extern char *gr_alert_log_fmt;
24228 ++extern char *gr_audit_log_fmt;
24229 ++extern char *gr_alert_log_buf;
24230 ++extern char *gr_audit_log_buf;
24231 ++
24232 ++static int gr_log_start(int audit)
24233 ++{
24234 ++ char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
24235 ++ char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
24236 ++ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
24237 ++
24238 ++ if (audit == GR_DO_AUDIT)
24239 ++ goto set_fmt;
24240 ++
24241 ++ if (!grsec_alert_wtime || jiffies - grsec_alert_wtime > CONFIG_GRKERNSEC_FLOODTIME * HZ) {
24242 ++ grsec_alert_wtime = jiffies;
24243 ++ grsec_alert_fyet = 0;
24244 ++ } else if ((jiffies - grsec_alert_wtime < CONFIG_GRKERNSEC_FLOODTIME * HZ) && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
24245 ++ grsec_alert_fyet++;
24246 ++ } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
24247 ++ grsec_alert_wtime = jiffies;
24248 ++ grsec_alert_fyet++;
24249 ++ printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
24250 ++ return FLOODING;
24251 ++ } else return FLOODING;
24252 ++
24253 ++set_fmt:
24254 ++ memset(buf, 0, PAGE_SIZE);
24255 ++ if (current->signal->curr_ip && gr_acl_is_enabled()) {
24256 ++ sprintf(fmt, "%s%s", loglevel, "grsec: From %u.%u.%u.%u: (%.64s:%c:%.950s) ");
24257 ++ snprintf(buf, PAGE_SIZE - 1, fmt, NIPQUAD(current->signal->curr_ip), current->role->rolename, gr_roletype_to_char(), current->acl->filename);
24258 ++ } else if (current->signal->curr_ip) {
24259 ++ sprintf(fmt, "%s%s", loglevel, "grsec: From %u.%u.%u.%u: ");
24260 ++ snprintf(buf, PAGE_SIZE - 1, fmt, NIPQUAD(current->signal->curr_ip));
24261 ++ } else if (gr_acl_is_enabled()) {
24262 ++ sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
24263 ++ snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
24264 ++ } else {
24265 ++ sprintf(fmt, "%s%s", loglevel, "grsec: ");
24266 ++ strcpy(buf, fmt);
24267 ++ }
24268 ++
24269 ++ return NO_FLOODING;
24270 ++}
24271 ++
24272 ++static void gr_log_middle(int audit, const char *msg, va_list ap)
24273 ++{
24274 ++ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
24275 ++ unsigned int len = strlen(buf);
24276 ++
24277 ++ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
24278 ++
24279 ++ return;
24280 ++}
24281 ++
24282 ++static void gr_log_middle_varargs(int audit, const char *msg, ...)
24283 ++{
24284 ++ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
24285 ++ unsigned int len = strlen(buf);
24286 ++ va_list ap;
24287 ++
24288 ++ va_start(ap, msg);
24289 ++ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
24290 ++ va_end(ap);
24291 ++
24292 ++ return;
24293 ++}
24294 ++
24295 ++static void gr_log_end(int audit)
24296 ++{
24297 ++ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
24298 ++ unsigned int len = strlen(buf);
24299 ++
24300 ++ snprintf(buf + len, PAGE_SIZE - len - 1, DEFAULTSECMSG, DEFAULTSECARGS(current));
24301 ++ printk("%s\n", buf);
24302 ++
24303 ++ return;
24304 ++}
24305 ++
24306 ++void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
24307 ++{
24308 ++ int logtype;
24309 ++ char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
24310 ++ char *str1, *str2, *str3;
24311 ++ int num1, num2;
24312 ++ unsigned long ulong1, ulong2;
24313 ++ struct dentry *dentry;
24314 ++ struct vfsmount *mnt;
24315 ++ struct file *file;
24316 ++ struct task_struct *task;
24317 ++ va_list ap;
24318 ++
24319 ++ BEGIN_LOCKS(audit);
24320 ++ logtype = gr_log_start(audit);
24321 ++ if (logtype == FLOODING) {
24322 ++ END_LOCKS(audit);
24323 ++ return;
24324 ++ }
24325 ++ va_start(ap, argtypes);
24326 ++ switch (argtypes) {
24327 ++ case GR_TTYSNIFF:
24328 ++ task = va_arg(ap, struct task_struct *);
24329 ++ gr_log_middle_varargs(audit, msg, NIPQUAD(task->signal->curr_ip), gr_task_fullpath0(task), task->comm, task->pid, gr_parent_task_fullpath0(task), task->parent->comm, task->parent->pid);
24330 ++ break;
24331 ++ case GR_SYSCTL_HIDDEN:
24332 ++ str1 = va_arg(ap, char *);
24333 ++ gr_log_middle_varargs(audit, msg, result, str1);
24334 ++ break;
24335 ++ case GR_RBAC:
24336 ++ dentry = va_arg(ap, struct dentry *);
24337 ++ mnt = va_arg(ap, struct vfsmount *);
24338 ++ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
24339 ++ break;
24340 ++ case GR_RBAC_STR:
24341 ++ dentry = va_arg(ap, struct dentry *);
24342 ++ mnt = va_arg(ap, struct vfsmount *);
24343 ++ str1 = va_arg(ap, char *);
24344 ++ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
24345 ++ break;
24346 ++ case GR_STR_RBAC:
24347 ++ str1 = va_arg(ap, char *);
24348 ++ dentry = va_arg(ap, struct dentry *);
24349 ++ mnt = va_arg(ap, struct vfsmount *);
24350 ++ gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
24351 ++ break;
24352 ++ case GR_RBAC_MODE2:
24353 ++ dentry = va_arg(ap, struct dentry *);
24354 ++ mnt = va_arg(ap, struct vfsmount *);
24355 ++ str1 = va_arg(ap, char *);
24356 ++ str2 = va_arg(ap, char *);
24357 ++ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
24358 ++ break;
24359 ++ case GR_RBAC_MODE3:
24360 ++ dentry = va_arg(ap, struct dentry *);
24361 ++ mnt = va_arg(ap, struct vfsmount *);
24362 ++ str1 = va_arg(ap, char *);
24363 ++ str2 = va_arg(ap, char *);
24364 ++ str3 = va_arg(ap, char *);
24365 ++ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
24366 ++ break;
24367 ++ case GR_FILENAME:
24368 ++ dentry = va_arg(ap, struct dentry *);
24369 ++ mnt = va_arg(ap, struct vfsmount *);
24370 ++ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
24371 ++ break;
24372 ++ case GR_STR_FILENAME:
24373 ++ str1 = va_arg(ap, char *);
24374 ++ dentry = va_arg(ap, struct dentry *);
24375 ++ mnt = va_arg(ap, struct vfsmount *);
24376 ++ gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
24377 ++ break;
24378 ++ case GR_FILENAME_STR:
24379 ++ dentry = va_arg(ap, struct dentry *);
24380 ++ mnt = va_arg(ap, struct vfsmount *);
24381 ++ str1 = va_arg(ap, char *);
24382 ++ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
24383 ++ break;
24384 ++ case GR_FILENAME_TWO_INT:
24385 ++ dentry = va_arg(ap, struct dentry *);
24386 ++ mnt = va_arg(ap, struct vfsmount *);
24387 ++ num1 = va_arg(ap, int);
24388 ++ num2 = va_arg(ap, int);
24389 ++ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
24390 ++ break;
24391 ++ case GR_FILENAME_TWO_INT_STR:
24392 ++ dentry = va_arg(ap, struct dentry *);
24393 ++ mnt = va_arg(ap, struct vfsmount *);
24394 ++ num1 = va_arg(ap, int);
24395 ++ num2 = va_arg(ap, int);
24396 ++ str1 = va_arg(ap, char *);
24397 ++ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
24398 ++ break;
24399 ++ case GR_TEXTREL:
24400 ++ file = va_arg(ap, struct file *);
24401 ++ ulong1 = va_arg(ap, unsigned long);
24402 ++ ulong2 = va_arg(ap, unsigned long);
24403 ++ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
24404 ++ break;
24405 ++ case GR_PTRACE:
24406 ++ task = va_arg(ap, struct task_struct *);
24407 ++ 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);
24408 ++ break;
24409 ++ case GR_RESOURCE:
24410 ++ task = va_arg(ap, struct task_struct *);
24411 ++ ulong1 = va_arg(ap, unsigned long);
24412 ++ str1 = va_arg(ap, char *);
24413 ++ ulong2 = va_arg(ap, unsigned long);
24414 ++ gr_log_middle_varargs(audit, msg, ulong1, str1, ulong2, gr_task_fullpath(task), task->comm, task->pid, task->uid, task->euid, task->gid, task->egid, gr_parent_task_fullpath(task), task->parent->comm, task->parent->pid, task->parent->uid, task->parent->euid, task->parent->gid, task->parent->egid);
24415 ++ break;
24416 ++ case GR_CAP:
24417 ++ task = va_arg(ap, struct task_struct *);
24418 ++ str1 = va_arg(ap, char *);
24419 ++ gr_log_middle_varargs(audit, msg, str1, gr_task_fullpath(task), task->comm, task->pid, task->uid, task->euid, task->gid, task->egid, gr_parent_task_fullpath(task), task->parent->comm, task->parent->pid, task->parent->uid, task->parent->euid, task->parent->gid, task->parent->egid);
24420 ++ break;
24421 ++ case GR_SIG:
24422 ++ task = va_arg(ap, struct task_struct *);
24423 ++ num1 = va_arg(ap, int);
24424 ++ gr_log_middle_varargs(audit, msg, num1, gr_task_fullpath0(task), task->comm, task->pid, task->uid, task->euid, task->gid, task->egid, gr_parent_task_fullpath0(task), task->parent->comm, task->parent->pid, task->parent->uid, task->parent->euid, task->parent->gid, task->parent->egid);
24425 ++ break;
24426 ++ case GR_CRASH1:
24427 ++ task = va_arg(ap, struct task_struct *);
24428 ++ ulong1 = va_arg(ap, unsigned long);
24429 ++ gr_log_middle_varargs(audit, msg, gr_task_fullpath(task), task->comm, task->pid, task->uid, task->euid, task->gid, task->egid, gr_parent_task_fullpath(task), task->parent->comm, task->parent->pid, task->parent->uid, task->parent->euid, task->parent->gid, task->parent->egid, task->uid, ulong1);
24430 ++ break;
24431 ++ case GR_CRASH2:
24432 ++ task = va_arg(ap, struct task_struct *);
24433 ++ ulong1 = va_arg(ap, unsigned long);
24434 ++ gr_log_middle_varargs(audit, msg, gr_task_fullpath(task), task->comm, task->pid, task->uid, task->euid, task->gid, task->egid, gr_parent_task_fullpath(task), task->parent->comm, task->parent->pid, task->parent->uid, task->parent->euid, task->parent->gid, task->parent->egid, ulong1);
24435 ++ break;
24436 ++ case GR_PSACCT:
24437 ++ {
24438 ++ unsigned int wday, cday;
24439 ++ __u8 whr, chr;
24440 ++ __u8 wmin, cmin;
24441 ++ __u8 wsec, csec;
24442 ++ char cur_tty[64] = { 0 };
24443 ++ char parent_tty[64] = { 0 };
24444 ++
24445 ++ task = va_arg(ap, struct task_struct *);
24446 ++ wday = va_arg(ap, unsigned int);
24447 ++ cday = va_arg(ap, unsigned int);
24448 ++ whr = va_arg(ap, int);
24449 ++ chr = va_arg(ap, int);
24450 ++ wmin = va_arg(ap, int);
24451 ++ cmin = va_arg(ap, int);
24452 ++ wsec = va_arg(ap, int);
24453 ++ csec = va_arg(ap, int);
24454 ++ ulong1 = va_arg(ap, unsigned long);
24455 ++
24456 ++ gr_log_middle_varargs(audit, msg, gr_task_fullpath(task), task->comm, task->pid, NIPQUAD(task->signal->curr_ip), tty_name(task->signal->tty, cur_tty), task->uid, task->euid, task->gid, task->egid, wday, whr, wmin, wsec, cday, chr, cmin, csec, (task->flags & PF_SIGNALED) ? "killed by signal" : "exited", ulong1, gr_parent_task_fullpath(task), task->parent->comm, task->parent->pid, NIPQUAD(task->parent->signal->curr_ip), tty_name(task->parent->signal->tty, parent_tty), task->parent->uid, task->parent->euid, task->parent->gid, task->parent->egid);
24457 ++ }
24458 ++ break;
24459 ++ default:
24460 ++ gr_log_middle(audit, msg, ap);
24461 ++ }
24462 ++ va_end(ap);
24463 ++ gr_log_end(audit);
24464 ++ END_LOCKS(audit);
24465 ++}
24466 +diff -urNp linux-2.6.27.10/grsecurity/grsec_mem.c linux-2.6.27.10/grsecurity/grsec_mem.c
24467 +--- linux-2.6.27.10/grsecurity/grsec_mem.c 1969-12-31 19:00:00.000000000 -0500
24468 ++++ linux-2.6.27.10/grsecurity/grsec_mem.c 2008-11-18 03:38:45.000000000 -0500
24469 +@@ -0,0 +1,71 @@
24470 ++#include <linux/kernel.h>
24471 ++#include <linux/sched.h>
24472 ++#include <linux/mm.h>
24473 ++#include <linux/mman.h>
24474 ++#include <linux/grinternal.h>
24475 ++
24476 ++void
24477 ++gr_handle_ioperm(void)
24478 ++{
24479 ++ gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
24480 ++ return;
24481 ++}
24482 ++
24483 ++void
24484 ++gr_handle_iopl(void)
24485 ++{
24486 ++ gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
24487 ++ return;
24488 ++}
24489 ++
24490 ++void
24491 ++gr_handle_mem_write(void)
24492 ++{
24493 ++ gr_log_noargs(GR_DONT_AUDIT, GR_MEM_WRITE_MSG);
24494 ++ return;
24495 ++}
24496 ++
24497 ++void
24498 ++gr_handle_kmem_write(void)
24499 ++{
24500 ++ gr_log_noargs(GR_DONT_AUDIT, GR_KMEM_MSG);
24501 ++ return;
24502 ++}
24503 ++
24504 ++void
24505 ++gr_handle_open_port(void)
24506 ++{
24507 ++ gr_log_noargs(GR_DONT_AUDIT, GR_PORT_OPEN_MSG);
24508 ++ return;
24509 ++}
24510 ++
24511 ++int
24512 ++gr_handle_mem_mmap(const unsigned long offset, struct vm_area_struct *vma)
24513 ++{
24514 ++ unsigned long start, end;
24515 ++
24516 ++ start = offset;
24517 ++ end = start + vma->vm_end - vma->vm_start;
24518 ++
24519 ++ if (start > end) {
24520 ++ gr_log_noargs(GR_DONT_AUDIT, GR_MEM_MMAP_MSG);
24521 ++ return -EPERM;
24522 ++ }
24523 ++
24524 ++ /* allowed ranges : ISA I/O BIOS */
24525 ++ if ((start >= __pa(high_memory))
24526 ++#ifdef CONFIG_X86
24527 ++ || (start >= 0x000a0000 && end <= 0x00100000)
24528 ++ || (start >= 0x00000000 && end <= 0x00001000)
24529 ++#endif
24530 ++ )
24531 ++ return 0;
24532 ++
24533 ++ if (vma->vm_flags & VM_WRITE) {
24534 ++ gr_log_noargs(GR_DONT_AUDIT, GR_MEM_MMAP_MSG);
24535 ++ return -EPERM;
24536 ++ } else
24537 ++ vma->vm_flags &= ~VM_MAYWRITE;
24538 ++
24539 ++ return 0;
24540 ++}
24541 +diff -urNp linux-2.6.27.10/grsecurity/grsec_mount.c linux-2.6.27.10/grsecurity/grsec_mount.c
24542 +--- linux-2.6.27.10/grsecurity/grsec_mount.c 1969-12-31 19:00:00.000000000 -0500
24543 ++++ linux-2.6.27.10/grsecurity/grsec_mount.c 2008-11-18 03:38:45.000000000 -0500
24544 +@@ -0,0 +1,34 @@
24545 ++#include <linux/kernel.h>
24546 ++#include <linux/sched.h>
24547 ++#include <linux/grsecurity.h>
24548 ++#include <linux/grinternal.h>
24549 ++
24550 ++void
24551 ++gr_log_remount(const char *devname, const int retval)
24552 ++{
24553 ++#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
24554 ++ if (grsec_enable_mount && (retval >= 0))
24555 ++ gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
24556 ++#endif
24557 ++ return;
24558 ++}
24559 ++
24560 ++void
24561 ++gr_log_unmount(const char *devname, const int retval)
24562 ++{
24563 ++#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
24564 ++ if (grsec_enable_mount && (retval >= 0))
24565 ++ gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
24566 ++#endif
24567 ++ return;
24568 ++}
24569 ++
24570 ++void
24571 ++gr_log_mount(const char *from, const char *to, const int retval)
24572 ++{
24573 ++#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
24574 ++ if (grsec_enable_mount && (retval >= 0))
24575 ++ gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from, to);
24576 ++#endif
24577 ++ return;
24578 ++}
24579 +diff -urNp linux-2.6.27.10/grsecurity/grsec_sig.c linux-2.6.27.10/grsecurity/grsec_sig.c
24580 +--- linux-2.6.27.10/grsecurity/grsec_sig.c 1969-12-31 19:00:00.000000000 -0500
24581 ++++ linux-2.6.27.10/grsecurity/grsec_sig.c 2008-11-18 03:38:45.000000000 -0500
24582 +@@ -0,0 +1,58 @@
24583 ++#include <linux/kernel.h>
24584 ++#include <linux/sched.h>
24585 ++#include <linux/delay.h>
24586 ++#include <linux/grsecurity.h>
24587 ++#include <linux/grinternal.h>
24588 ++
24589 ++void
24590 ++gr_log_signal(const int sig, const struct task_struct *t)
24591 ++{
24592 ++#ifdef CONFIG_GRKERNSEC_SIGNAL
24593 ++ if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
24594 ++ (sig == SIGABRT) || (sig == SIGBUS))) {
24595 ++ if (t->pid == current->pid) {
24596 ++ gr_log_int(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, sig);
24597 ++ } else {
24598 ++ gr_log_sig(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
24599 ++ }
24600 ++ }
24601 ++#endif
24602 ++ return;
24603 ++}
24604 ++
24605 ++int
24606 ++gr_handle_signal(const struct task_struct *p, const int sig)
24607 ++{
24608 ++#ifdef CONFIG_GRKERNSEC
24609 ++ if (current->pid > 1 && gr_check_protected_task(p)) {
24610 ++ gr_log_sig(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
24611 ++ return -EPERM;
24612 ++ } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
24613 ++ return -EPERM;
24614 ++ }
24615 ++#endif
24616 ++ return 0;
24617 ++}
24618 ++
24619 ++void gr_handle_brute_attach(struct task_struct *p)
24620 ++{
24621 ++#ifdef CONFIG_GRKERNSEC_BRUTE
24622 ++ read_lock(&tasklist_lock);
24623 ++ read_lock(&grsec_exec_file_lock);
24624 ++ if (p->parent && p->parent->exec_file == p->exec_file)
24625 ++ p->parent->brute = 1;
24626 ++ read_unlock(&grsec_exec_file_lock);
24627 ++ read_unlock(&tasklist_lock);
24628 ++#endif
24629 ++ return;
24630 ++}
24631 ++
24632 ++void gr_handle_brute_check(void)
24633 ++{
24634 ++#ifdef CONFIG_GRKERNSEC_BRUTE
24635 ++ if (current->brute)
24636 ++ msleep(30 * 1000);
24637 ++#endif
24638 ++ return;
24639 ++}
24640 ++
24641 +diff -urNp linux-2.6.27.10/grsecurity/grsec_sock.c linux-2.6.27.10/grsecurity/grsec_sock.c
24642 +--- linux-2.6.27.10/grsecurity/grsec_sock.c 1969-12-31 19:00:00.000000000 -0500
24643 ++++ linux-2.6.27.10/grsecurity/grsec_sock.c 2008-11-18 11:35:13.000000000 -0500
24644 +@@ -0,0 +1,274 @@
24645 ++#include <linux/kernel.h>
24646 ++#include <linux/module.h>
24647 ++#include <linux/sched.h>
24648 ++#include <linux/file.h>
24649 ++#include <linux/net.h>
24650 ++#include <linux/in.h>
24651 ++#include <linux/ip.h>
24652 ++#include <net/sock.h>
24653 ++#include <net/inet_sock.h>
24654 ++#include <linux/grsecurity.h>
24655 ++#include <linux/grinternal.h>
24656 ++#include <linux/gracl.h>
24657 ++
24658 ++#if defined(CONFIG_IP_NF_MATCH_STEALTH_MODULE)
24659 ++extern struct sock *udp_v4_lookup(u32 saddr, u16 sport, u32 daddr, u16 dport, int dif);
24660 ++EXPORT_SYMBOL(udp_v4_lookup);
24661 ++#endif
24662 ++
24663 ++kernel_cap_t gr_cap_rtnetlink(struct sock *sock);
24664 ++EXPORT_SYMBOL(gr_cap_rtnetlink);
24665 ++
24666 ++extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
24667 ++extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
24668 ++
24669 ++EXPORT_SYMBOL(gr_search_udp_recvmsg);
24670 ++EXPORT_SYMBOL(gr_search_udp_sendmsg);
24671 ++
24672 ++#ifdef CONFIG_UNIX_MODULE
24673 ++EXPORT_SYMBOL(gr_acl_handle_unix);
24674 ++EXPORT_SYMBOL(gr_acl_handle_mknod);
24675 ++EXPORT_SYMBOL(gr_handle_chroot_unix);
24676 ++EXPORT_SYMBOL(gr_handle_create);
24677 ++#endif
24678 ++
24679 ++#ifdef CONFIG_GRKERNSEC
24680 ++#define gr_conn_table_size 32749
24681 ++struct conn_table_entry {
24682 ++ struct conn_table_entry *next;
24683 ++ struct signal_struct *sig;
24684 ++};
24685 ++
24686 ++struct conn_table_entry *gr_conn_table[gr_conn_table_size];
24687 ++DEFINE_SPINLOCK(gr_conn_table_lock);
24688 ++
24689 ++extern const char * gr_socktype_to_name(unsigned char type);
24690 ++extern const char * gr_proto_to_name(unsigned char proto);
24691 ++
24692 ++static __inline__ int
24693 ++conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
24694 ++{
24695 ++ return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
24696 ++}
24697 ++
24698 ++static __inline__ int
24699 ++conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
24700 ++ __u16 sport, __u16 dport)
24701 ++{
24702 ++ if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
24703 ++ sig->gr_sport == sport && sig->gr_dport == dport))
24704 ++ return 1;
24705 ++ else
24706 ++ return 0;
24707 ++}
24708 ++
24709 ++static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
24710 ++{
24711 ++ struct conn_table_entry **match;
24712 ++ unsigned int index;
24713 ++
24714 ++ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
24715 ++ sig->gr_sport, sig->gr_dport,
24716 ++ gr_conn_table_size);
24717 ++
24718 ++ newent->sig = sig;
24719 ++
24720 ++ match = &gr_conn_table[index];
24721 ++ newent->next = *match;
24722 ++ *match = newent;
24723 ++
24724 ++ return;
24725 ++}
24726 ++
24727 ++static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
24728 ++{
24729 ++ struct conn_table_entry *match, *last = NULL;
24730 ++ unsigned int index;
24731 ++
24732 ++ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
24733 ++ sig->gr_sport, sig->gr_dport,
24734 ++ gr_conn_table_size);
24735 ++
24736 ++ match = gr_conn_table[index];
24737 ++ while (match && !conn_match(match->sig,
24738 ++ sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
24739 ++ sig->gr_dport)) {
24740 ++ last = match;
24741 ++ match = match->next;
24742 ++ }
24743 ++
24744 ++ if (match) {
24745 ++ if (last)
24746 ++ last->next = match->next;
24747 ++ else
24748 ++ gr_conn_table[index] = NULL;
24749 ++ kfree(match);
24750 ++ }
24751 ++
24752 ++ return;
24753 ++}
24754 ++
24755 ++static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
24756 ++ __u16 sport, __u16 dport)
24757 ++{
24758 ++ struct conn_table_entry *match;
24759 ++ unsigned int index;
24760 ++
24761 ++ index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
24762 ++
24763 ++ match = gr_conn_table[index];
24764 ++ while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
24765 ++ match = match->next;
24766 ++
24767 ++ if (match)
24768 ++ return match->sig;
24769 ++ else
24770 ++ return NULL;
24771 ++}
24772 ++
24773 ++#endif
24774 ++
24775 ++void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
24776 ++{
24777 ++#ifdef CONFIG_GRKERNSEC
24778 ++ struct signal_struct *sig = task->signal;
24779 ++ struct conn_table_entry *newent;
24780 ++
24781 ++ newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
24782 ++ if (newent == NULL)
24783 ++ return;
24784 ++ /* no bh lock needed since we are called with bh disabled */
24785 ++ spin_lock(&gr_conn_table_lock);
24786 ++ gr_del_task_from_ip_table_nolock(sig);
24787 ++ sig->gr_saddr = inet->rcv_saddr;
24788 ++ sig->gr_daddr = inet->daddr;
24789 ++ sig->gr_sport = inet->sport;
24790 ++ sig->gr_dport = inet->dport;
24791 ++ gr_add_to_task_ip_table_nolock(sig, newent);
24792 ++ spin_unlock(&gr_conn_table_lock);
24793 ++#endif
24794 ++ return;
24795 ++}
24796 ++
24797 ++void gr_del_task_from_ip_table(struct task_struct *task)
24798 ++{
24799 ++#ifdef CONFIG_GRKERNSEC
24800 ++ spin_lock_bh(&gr_conn_table_lock);
24801 ++ gr_del_task_from_ip_table_nolock(task->signal);
24802 ++ spin_unlock_bh(&gr_conn_table_lock);
24803 ++#endif
24804 ++ return;
24805 ++}
24806 ++
24807 ++void
24808 ++gr_attach_curr_ip(const struct sock *sk)
24809 ++{
24810 ++#ifdef CONFIG_GRKERNSEC
24811 ++ struct signal_struct *p, *set;
24812 ++ const struct inet_sock *inet = inet_sk(sk);
24813 ++
24814 ++ if (unlikely(sk->sk_protocol != IPPROTO_TCP))
24815 ++ return;
24816 ++
24817 ++ set = current->signal;
24818 ++
24819 ++ spin_lock_bh(&gr_conn_table_lock);
24820 ++ p = gr_lookup_task_ip_table(inet->daddr, inet->rcv_saddr,
24821 ++ inet->dport, inet->sport);
24822 ++ if (unlikely(p != NULL)) {
24823 ++ set->curr_ip = p->curr_ip;
24824 ++ set->used_accept = 1;
24825 ++ gr_del_task_from_ip_table_nolock(p);
24826 ++ spin_unlock_bh(&gr_conn_table_lock);
24827 ++ return;
24828 ++ }
24829 ++ spin_unlock_bh(&gr_conn_table_lock);
24830 ++
24831 ++ set->curr_ip = inet->daddr;
24832 ++ set->used_accept = 1;
24833 ++#endif
24834 ++ return;
24835 ++}
24836 ++
24837 ++int
24838 ++gr_handle_sock_all(const int family, const int type, const int protocol)
24839 ++{
24840 ++#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
24841 ++ if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
24842 ++ (family != AF_UNIX) && (family != AF_LOCAL)) {
24843 ++ gr_log_int_str2(GR_DONT_AUDIT, GR_SOCK2_MSG, family, gr_socktype_to_name(type), gr_proto_to_name(protocol));
24844 ++ return -EACCES;
24845 ++ }
24846 ++#endif
24847 ++ return 0;
24848 ++}
24849 ++
24850 ++int
24851 ++gr_handle_sock_server(const struct sockaddr *sck)
24852 ++{
24853 ++#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
24854 ++ if (grsec_enable_socket_server &&
24855 ++ in_group_p(grsec_socket_server_gid) &&
24856 ++ sck && (sck->sa_family != AF_UNIX) &&
24857 ++ (sck->sa_family != AF_LOCAL)) {
24858 ++ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
24859 ++ return -EACCES;
24860 ++ }
24861 ++#endif
24862 ++ return 0;
24863 ++}
24864 ++
24865 ++int
24866 ++gr_handle_sock_server_other(const struct sock *sck)
24867 ++{
24868 ++#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
24869 ++ if (grsec_enable_socket_server &&
24870 ++ in_group_p(grsec_socket_server_gid) &&
24871 ++ sck && (sck->sk_family != AF_UNIX) &&
24872 ++ (sck->sk_family != AF_LOCAL)) {
24873 ++ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
24874 ++ return -EACCES;
24875 ++ }
24876 ++#endif
24877 ++ return 0;
24878 ++}
24879 ++
24880 ++int
24881 ++gr_handle_sock_client(const struct sockaddr *sck)
24882 ++{
24883 ++#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
24884 ++ if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
24885 ++ sck && (sck->sa_family != AF_UNIX) &&
24886 ++ (sck->sa_family != AF_LOCAL)) {
24887 ++ gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
24888 ++ return -EACCES;
24889 ++ }
24890 ++#endif
24891 ++ return 0;
24892 ++}
24893 ++
24894 ++kernel_cap_t
24895 ++gr_cap_rtnetlink(struct sock *sock)
24896 ++{
24897 ++#ifdef CONFIG_GRKERNSEC
24898 ++ if (!gr_acl_is_enabled())
24899 ++ return current->cap_effective;
24900 ++ else if (sock->sk_protocol == NETLINK_ISCSI &&
24901 ++ cap_raised(current->cap_effective, CAP_SYS_ADMIN) &&
24902 ++ gr_task_is_capable(current, CAP_SYS_ADMIN))
24903 ++ return current->cap_effective;
24904 ++ else if (sock->sk_protocol == NETLINK_AUDIT &&
24905 ++ cap_raised(current->cap_effective, CAP_AUDIT_WRITE) &&
24906 ++ gr_task_is_capable(current, CAP_AUDIT_WRITE) &&
24907 ++ cap_raised(current->cap_effective, CAP_AUDIT_CONTROL) &&
24908 ++ gr_task_is_capable(current, CAP_AUDIT_CONTROL))
24909 ++ return current->cap_effective;
24910 ++ else if (cap_raised(current->cap_effective, CAP_NET_ADMIN) &&
24911 ++ gr_task_is_capable(current, CAP_NET_ADMIN))
24912 ++ return current->cap_effective;
24913 ++ else
24914 ++ return __cap_empty_set;
24915 ++#else
24916 ++ return current->cap_effective;
24917 ++#endif
24918 ++}
24919 +diff -urNp linux-2.6.27.10/grsecurity/grsec_sysctl.c linux-2.6.27.10/grsecurity/grsec_sysctl.c
24920 +--- linux-2.6.27.10/grsecurity/grsec_sysctl.c 1969-12-31 19:00:00.000000000 -0500
24921 ++++ linux-2.6.27.10/grsecurity/grsec_sysctl.c 2008-11-18 03:38:45.000000000 -0500
24922 +@@ -0,0 +1,435 @@
24923 ++#include <linux/kernel.h>
24924 ++#include <linux/sched.h>
24925 ++#include <linux/sysctl.h>
24926 ++#include <linux/grsecurity.h>
24927 ++#include <linux/grinternal.h>
24928 ++
24929 ++#ifdef CONFIG_GRKERNSEC_MODSTOP
24930 ++int grsec_modstop;
24931 ++#endif
24932 ++
24933 ++int
24934 ++gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
24935 ++{
24936 ++#ifdef CONFIG_GRKERNSEC_SYSCTL
24937 ++ if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
24938 ++ gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
24939 ++ return -EACCES;
24940 ++ }
24941 ++#endif
24942 ++#ifdef CONFIG_GRKERNSEC_MODSTOP
24943 ++ if (!strcmp(dirname, "grsecurity") && !strcmp(name, "disable_modules") &&
24944 ++ grsec_modstop && (op & MAY_WRITE)) {
24945 ++ gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
24946 ++ return -EACCES;
24947 ++ }
24948 ++#endif
24949 ++ return 0;
24950 ++}
24951 ++
24952 ++#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_MODSTOP)
24953 ++ctl_table grsecurity_table[] = {
24954 ++#ifdef CONFIG_GRKERNSEC_SYSCTL
24955 ++#ifdef CONFIG_GRKERNSEC_LINK
24956 ++ {
24957 ++ .ctl_name = CTL_UNNUMBERED,
24958 ++ .procname = "linking_restrictions",
24959 ++ .data = &grsec_enable_link,
24960 ++ .maxlen = sizeof(int),
24961 ++ .mode = 0600,
24962 ++ .proc_handler = &proc_dointvec,
24963 ++ },
24964 ++#endif
24965 ++#ifdef CONFIG_GRKERNSEC_FIFO
24966 ++ {
24967 ++ .ctl_name = CTL_UNNUMBERED,
24968 ++ .procname = "fifo_restrictions",
24969 ++ .data = &grsec_enable_fifo,
24970 ++ .maxlen = sizeof(int),
24971 ++ .mode = 0600,
24972 ++ .proc_handler = &proc_dointvec,
24973 ++ },
24974 ++#endif
24975 ++#ifdef CONFIG_GRKERNSEC_EXECVE
24976 ++ {
24977 ++ .ctl_name = CTL_UNNUMBERED,
24978 ++ .procname = "execve_limiting",
24979 ++ .data = &grsec_enable_execve,
24980 ++ .maxlen = sizeof(int),
24981 ++ .mode = 0600,
24982 ++ .proc_handler = &proc_dointvec,
24983 ++ },
24984 ++#endif
24985 ++#ifdef CONFIG_GRKERNSEC_EXECLOG
24986 ++ {
24987 ++ .ctl_name = CTL_UNNUMBERED,
24988 ++ .procname = "exec_logging",
24989 ++ .data = &grsec_enable_execlog,
24990 ++ .maxlen = sizeof(int),
24991 ++ .mode = 0600,
24992 ++ .proc_handler = &proc_dointvec,
24993 ++ },
24994 ++#endif
24995 ++#ifdef CONFIG_GRKERNSEC_SIGNAL
24996 ++ {
24997 ++ .ctl_name = CTL_UNNUMBERED,
24998 ++ .procname = "signal_logging",
24999 ++ .data = &grsec_enable_signal,
25000 ++ .maxlen = sizeof(int),
25001 ++ .mode = 0600,
25002 ++ .proc_handler = &proc_dointvec,
25003 ++ },
25004 ++#endif
25005 ++#ifdef CONFIG_GRKERNSEC_FORKFAIL
25006 ++ {
25007 ++ .ctl_name = CTL_UNNUMBERED,
25008 ++ .procname = "forkfail_logging",
25009 ++ .data = &grsec_enable_forkfail,
25010 ++ .maxlen = sizeof(int),
25011 ++ .mode = 0600,
25012 ++ .proc_handler = &proc_dointvec,
25013 ++ },
25014 ++#endif
25015 ++#ifdef CONFIG_GRKERNSEC_TIME
25016 ++ {
25017 ++ .ctl_name = CTL_UNNUMBERED,
25018 ++ .procname = "timechange_logging",
25019 ++ .data = &grsec_enable_time,
25020 ++ .maxlen = sizeof(int),
25021 ++ .mode = 0600,
25022 ++ .proc_handler = &proc_dointvec,
25023 ++ },
25024 ++#endif
25025 ++#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
25026 ++ {
25027 ++ .ctl_name = CTL_UNNUMBERED,
25028 ++ .procname = "chroot_deny_shmat",
25029 ++ .data = &grsec_enable_chroot_shmat,
25030 ++ .maxlen = sizeof(int),
25031 ++ .mode = 0600,
25032 ++ .proc_handler = &proc_dointvec,
25033 ++ },
25034 ++#endif
25035 ++#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
25036 ++ {
25037 ++ .ctl_name = CTL_UNNUMBERED,
25038 ++ .procname = "chroot_deny_unix",
25039 ++ .data = &grsec_enable_chroot_unix,
25040 ++ .maxlen = sizeof(int),
25041 ++ .mode = 0600,
25042 ++ .proc_handler = &proc_dointvec,
25043 ++ },
25044 ++#endif
25045 ++#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
25046 ++ {
25047 ++ .ctl_name = CTL_UNNUMBERED,
25048 ++ .procname = "chroot_deny_mount",
25049 ++ .data = &grsec_enable_chroot_mount,
25050 ++ .maxlen = sizeof(int),
25051 ++ .mode = 0600,
25052 ++ .proc_handler = &proc_dointvec,
25053 ++ },
25054 ++#endif
25055 ++#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
25056 ++ {
25057 ++ .ctl_name = CTL_UNNUMBERED,
25058 ++ .procname = "chroot_deny_fchdir",
25059 ++ .data = &grsec_enable_chroot_fchdir,
25060 ++ .maxlen = sizeof(int),
25061 ++ .mode = 0600,
25062 ++ .proc_handler = &proc_dointvec,
25063 ++ },
25064 ++#endif
25065 ++#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
25066 ++ {
25067 ++ .ctl_name = CTL_UNNUMBERED,
25068 ++ .procname = "chroot_deny_chroot",
25069 ++ .data = &grsec_enable_chroot_double,
25070 ++ .maxlen = sizeof(int),
25071 ++ .mode = 0600,
25072 ++ .proc_handler = &proc_dointvec,
25073 ++ },
25074 ++#endif
25075 ++#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
25076 ++ {
25077 ++ .ctl_name = CTL_UNNUMBERED,
25078 ++ .procname = "chroot_deny_pivot",
25079 ++ .data = &grsec_enable_chroot_pivot,
25080 ++ .maxlen = sizeof(int),
25081 ++ .mode = 0600,
25082 ++ .proc_handler = &proc_dointvec,
25083 ++ },
25084 ++#endif
25085 ++#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
25086 ++ {
25087 ++ .ctl_name = CTL_UNNUMBERED,
25088 ++ .procname = "chroot_enforce_chdir",
25089 ++ .data = &grsec_enable_chroot_chdir,
25090 ++ .maxlen = sizeof(int),
25091 ++ .mode = 0600,
25092 ++ .proc_handler = &proc_dointvec,
25093 ++ },
25094 ++#endif
25095 ++#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
25096 ++ {
25097 ++ .ctl_name = CTL_UNNUMBERED,
25098 ++ .procname = "chroot_deny_chmod",
25099 ++ .data = &grsec_enable_chroot_chmod,
25100 ++ .maxlen = sizeof(int),
25101 ++ .mode = 0600,
25102 ++ .proc_handler = &proc_dointvec,
25103 ++ },
25104 ++#endif
25105 ++#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
25106 ++ {
25107 ++ .ctl_name = CTL_UNNUMBERED,
25108 ++ .procname = "chroot_deny_mknod",
25109 ++ .data = &grsec_enable_chroot_mknod,
25110 ++ .maxlen = sizeof(int),
25111 ++ .mode = 0600,
25112 ++ .proc_handler = &proc_dointvec,
25113 ++ },
25114 ++#endif
25115 ++#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
25116 ++ {
25117 ++ .ctl_name = CTL_UNNUMBERED,
25118 ++ .procname = "chroot_restrict_nice",
25119 ++ .data = &grsec_enable_chroot_nice,
25120 ++ .maxlen = sizeof(int),
25121 ++ .mode = 0600,
25122 ++ .proc_handler = &proc_dointvec,
25123 ++ },
25124 ++#endif
25125 ++#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
25126 ++ {
25127 ++ .ctl_name = CTL_UNNUMBERED,
25128 ++ .procname = "chroot_execlog",
25129 ++ .data = &grsec_enable_chroot_execlog,
25130 ++ .maxlen = sizeof(int),
25131 ++ .mode = 0600,
25132 ++ .proc_handler = &proc_dointvec,
25133 ++ },
25134 ++#endif
25135 ++#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
25136 ++ {
25137 ++ .ctl_name = CTL_UNNUMBERED,
25138 ++ .procname = "chroot_caps",
25139 ++ .data = &grsec_enable_chroot_caps,
25140 ++ .maxlen = sizeof(int),
25141 ++ .mode = 0600,
25142 ++ .proc_handler = &proc_dointvec,
25143 ++ },
25144 ++#endif
25145 ++#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
25146 ++ {
25147 ++ .ctl_name = CTL_UNNUMBERED,
25148 ++ .procname = "chroot_deny_sysctl",
25149 ++ .data = &grsec_enable_chroot_sysctl,
25150 ++ .maxlen = sizeof(int),
25151 ++ .mode = 0600,
25152 ++ .proc_handler = &proc_dointvec,
25153 ++ },
25154 ++#endif
25155 ++#ifdef CONFIG_GRKERNSEC_TPE
25156 ++ {
25157 ++ .ctl_name = CTL_UNNUMBERED,
25158 ++ .procname = "tpe",
25159 ++ .data = &grsec_enable_tpe,
25160 ++ .maxlen = sizeof(int),
25161 ++ .mode = 0600,
25162 ++ .proc_handler = &proc_dointvec,
25163 ++ },
25164 ++ {
25165 ++ .ctl_name = CTL_UNNUMBERED,
25166 ++ .procname = "tpe_gid",
25167 ++ .data = &grsec_tpe_gid,
25168 ++ .maxlen = sizeof(int),
25169 ++ .mode = 0600,
25170 ++ .proc_handler = &proc_dointvec,
25171 ++ },
25172 ++#endif
25173 ++#ifdef CONFIG_GRKERNSEC_TPE_ALL
25174 ++ {
25175 ++ .ctl_name = CTL_UNNUMBERED,
25176 ++ .procname = "tpe_restrict_all",
25177 ++ .data = &grsec_enable_tpe_all,
25178 ++ .maxlen = sizeof(int),
25179 ++ .mode = 0600,
25180 ++ .proc_handler = &proc_dointvec,
25181 ++ },
25182 ++#endif
25183 ++#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
25184 ++ {
25185 ++ .ctl_name = CTL_UNNUMBERED,
25186 ++ .procname = "socket_all",
25187 ++ .data = &grsec_enable_socket_all,
25188 ++ .maxlen = sizeof(int),
25189 ++ .mode = 0600,
25190 ++ .proc_handler = &proc_dointvec,
25191 ++ },
25192 ++ {
25193 ++ .ctl_name = CTL_UNNUMBERED,
25194 ++ .procname = "socket_all_gid",
25195 ++ .data = &grsec_socket_all_gid,
25196 ++ .maxlen = sizeof(int),
25197 ++ .mode = 0600,
25198 ++ .proc_handler = &proc_dointvec,
25199 ++ },
25200 ++#endif
25201 ++#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
25202 ++ {
25203 ++ .ctl_name = CTL_UNNUMBERED,
25204 ++ .procname = "socket_client",
25205 ++ .data = &grsec_enable_socket_client,
25206 ++ .maxlen = sizeof(int),
25207 ++ .mode = 0600,
25208 ++ .proc_handler = &proc_dointvec,
25209 ++ },
25210 ++ {
25211 ++ .ctl_name = CTL_UNNUMBERED,
25212 ++ .procname = "socket_client_gid",
25213 ++ .data = &grsec_socket_client_gid,
25214 ++ .maxlen = sizeof(int),
25215 ++ .mode = 0600,
25216 ++ .proc_handler = &proc_dointvec,
25217 ++ },
25218 ++#endif
25219 ++#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
25220 ++ {
25221 ++ .ctl_name = CTL_UNNUMBERED,
25222 ++ .procname = "socket_server",
25223 ++ .data = &grsec_enable_socket_server,
25224 ++ .maxlen = sizeof(int),
25225 ++ .mode = 0600,
25226 ++ .proc_handler = &proc_dointvec,
25227 ++ },
25228 ++ {
25229 ++ .ctl_name = CTL_UNNUMBERED,
25230 ++ .procname = "socket_server_gid",
25231 ++ .data = &grsec_socket_server_gid,
25232 ++ .maxlen = sizeof(int),
25233 ++ .mode = 0600,
25234 ++ .proc_handler = &proc_dointvec,
25235 ++ },
25236 ++#endif
25237 ++#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
25238 ++ {
25239 ++ .ctl_name = CTL_UNNUMBERED,
25240 ++ .procname = "audit_group",
25241 ++ .data = &grsec_enable_group,
25242 ++ .maxlen = sizeof(int),
25243 ++ .mode = 0600,
25244 ++ .proc_handler = &proc_dointvec,
25245 ++ },
25246 ++ {
25247 ++ .ctl_name = CTL_UNNUMBERED,
25248 ++ .procname = "audit_gid",
25249 ++ .data = &grsec_audit_gid,
25250 ++ .maxlen = sizeof(int),
25251 ++ .mode = 0600,
25252 ++ .proc_handler = &proc_dointvec,
25253 ++ },
25254 ++#endif
25255 ++#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
25256 ++ {
25257 ++ .ctl_name = CTL_UNNUMBERED,
25258 ++ .procname = "audit_chdir",
25259 ++ .data = &grsec_enable_chdir,
25260 ++ .maxlen = sizeof(int),
25261 ++ .mode = 0600,
25262 ++ .proc_handler = &proc_dointvec,
25263 ++ },
25264 ++#endif
25265 ++#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
25266 ++ {
25267 ++ .ctl_name = CTL_UNNUMBERED,
25268 ++ .procname = "audit_mount",
25269 ++ .data = &grsec_enable_mount,
25270 ++ .maxlen = sizeof(int),
25271 ++ .mode = 0600,
25272 ++ .proc_handler = &proc_dointvec,
25273 ++ },
25274 ++#endif
25275 ++#ifdef CONFIG_GRKERNSEC_AUDIT_IPC
25276 ++ {
25277 ++ .ctl_name = CTL_UNNUMBERED,
25278 ++ .procname = "audit_ipc",
25279 ++ .data = &grsec_enable_audit_ipc,
25280 ++ .maxlen = sizeof(int),
25281 ++ .mode = 0600,
25282 ++ .proc_handler = &proc_dointvec,
25283 ++ },
25284 ++#endif
25285 ++#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
25286 ++ {
25287 ++ .ctl_name = CTL_UNNUMBERED,
25288 ++ .procname = "audit_textrel",
25289 ++ .data = &grsec_enable_audit_textrel,
25290 ++ .maxlen = sizeof(int),
25291 ++ .mode = 0600,
25292 ++ .proc_handler = &proc_dointvec,
25293 ++ },
25294 ++#endif
25295 ++#ifdef CONFIG_GRKERNSEC_DMESG
25296 ++ {
25297 ++ .ctl_name = CTL_UNNUMBERED,
25298 ++ .procname = "dmesg",
25299 ++ .data = &grsec_enable_dmesg,
25300 ++ .maxlen = sizeof(int),
25301 ++ .mode = 0600,
25302 ++ .proc_handler = &proc_dointvec,
25303 ++ },
25304 ++#endif
25305 ++#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
25306 ++ {
25307 ++ .ctl_name = CTL_UNNUMBERED,
25308 ++ .procname = "chroot_findtask",
25309 ++ .data = &grsec_enable_chroot_findtask,
25310 ++ .maxlen = sizeof(int),
25311 ++ .mode = 0600,
25312 ++ .proc_handler = &proc_dointvec,
25313 ++ },
25314 ++#endif
25315 ++#ifdef CONFIG_GRKERNSEC_RESLOG
25316 ++ {
25317 ++ .ctl_name = CTL_UNNUMBERED,
25318 ++ .procname = "resource_logging",
25319 ++ .data = &grsec_resource_logging,
25320 ++ .maxlen = sizeof(int),
25321 ++ .mode = 0600,
25322 ++ .proc_handler = &proc_dointvec,
25323 ++ },
25324 ++#endif
25325 ++ {
25326 ++ .ctl_name = CTL_UNNUMBERED,
25327 ++ .procname = "grsec_lock",
25328 ++ .data = &grsec_lock,
25329 ++ .maxlen = sizeof(int),
25330 ++ .mode = 0600,
25331 ++ .proc_handler = &proc_dointvec,
25332 ++ },
25333 ++#endif
25334 ++#ifdef CONFIG_GRKERNSEC_MODSTOP
25335 ++ {
25336 ++ .ctl_name = CTL_UNNUMBERED,
25337 ++ .procname = "disable_modules",
25338 ++ .data = &grsec_modstop,
25339 ++ .maxlen = sizeof(int),
25340 ++ .mode = 0600,
25341 ++ .proc_handler = &proc_dointvec,
25342 ++ },
25343 ++#endif
25344 ++ { .ctl_name = 0 }
25345 ++};
25346 ++#endif
25347 ++
25348 ++int gr_check_modstop(void)
25349 ++{
25350 ++#ifdef CONFIG_GRKERNSEC_MODSTOP
25351 ++ if (grsec_modstop == 1) {
25352 ++ gr_log_noargs(GR_DONT_AUDIT, GR_STOPMOD_MSG);
25353 ++ return 1;
25354 ++ }
25355 ++#endif
25356 ++ return 0;
25357 ++}
25358 +diff -urNp linux-2.6.27.10/grsecurity/grsec_textrel.c linux-2.6.27.10/grsecurity/grsec_textrel.c
25359 +--- linux-2.6.27.10/grsecurity/grsec_textrel.c 1969-12-31 19:00:00.000000000 -0500
25360 ++++ linux-2.6.27.10/grsecurity/grsec_textrel.c 2008-11-18 03:38:45.000000000 -0500
25361 +@@ -0,0 +1,16 @@
25362 ++#include <linux/kernel.h>
25363 ++#include <linux/sched.h>
25364 ++#include <linux/mm.h>
25365 ++#include <linux/file.h>
25366 ++#include <linux/grinternal.h>
25367 ++#include <linux/grsecurity.h>
25368 ++
25369 ++void
25370 ++gr_log_textrel(struct vm_area_struct * vma)
25371 ++{
25372 ++#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
25373 ++ if (grsec_enable_audit_textrel)
25374 ++ gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
25375 ++#endif
25376 ++ return;
25377 ++}
25378 +diff -urNp linux-2.6.27.10/grsecurity/grsec_time.c linux-2.6.27.10/grsecurity/grsec_time.c
25379 +--- linux-2.6.27.10/grsecurity/grsec_time.c 1969-12-31 19:00:00.000000000 -0500
25380 ++++ linux-2.6.27.10/grsecurity/grsec_time.c 2008-11-18 03:38:45.000000000 -0500
25381 +@@ -0,0 +1,13 @@
25382 ++#include <linux/kernel.h>
25383 ++#include <linux/sched.h>
25384 ++#include <linux/grinternal.h>
25385 ++
25386 ++void
25387 ++gr_log_timechange(void)
25388 ++{
25389 ++#ifdef CONFIG_GRKERNSEC_TIME
25390 ++ if (grsec_enable_time)
25391 ++ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
25392 ++#endif
25393 ++ return;
25394 ++}
25395 +diff -urNp linux-2.6.27.10/grsecurity/grsec_tpe.c linux-2.6.27.10/grsecurity/grsec_tpe.c
25396 +--- linux-2.6.27.10/grsecurity/grsec_tpe.c 1969-12-31 19:00:00.000000000 -0500
25397 ++++ linux-2.6.27.10/grsecurity/grsec_tpe.c 2008-11-18 03:38:45.000000000 -0500
25398 +@@ -0,0 +1,37 @@
25399 ++#include <linux/kernel.h>
25400 ++#include <linux/sched.h>
25401 ++#include <linux/file.h>
25402 ++#include <linux/fs.h>
25403 ++#include <linux/grinternal.h>
25404 ++
25405 ++extern int gr_acl_tpe_check(void);
25406 ++
25407 ++int
25408 ++gr_tpe_allow(const struct file *file)
25409 ++{
25410 ++#ifdef CONFIG_GRKERNSEC
25411 ++ struct inode *inode = file->f_path.dentry->d_parent->d_inode;
25412 ++
25413 ++ if (current->uid && ((grsec_enable_tpe &&
25414 ++#ifdef CONFIG_GRKERNSEC_TPE_INVERT
25415 ++ !in_group_p(grsec_tpe_gid)
25416 ++#else
25417 ++ in_group_p(grsec_tpe_gid)
25418 ++#endif
25419 ++ ) || gr_acl_tpe_check()) &&
25420 ++ (inode->i_uid || (!inode->i_uid && ((inode->i_mode & S_IWGRP) ||
25421 ++ (inode->i_mode & S_IWOTH))))) {
25422 ++ gr_log_fs_generic(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, file->f_path.dentry, file->f_path.mnt);
25423 ++ return 0;
25424 ++ }
25425 ++#ifdef CONFIG_GRKERNSEC_TPE_ALL
25426 ++ if (current->uid && grsec_enable_tpe && grsec_enable_tpe_all &&
25427 ++ ((inode->i_uid && (inode->i_uid != current->uid)) ||
25428 ++ (inode->i_mode & S_IWGRP) || (inode->i_mode & S_IWOTH))) {
25429 ++ gr_log_fs_generic(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, file->f_path.dentry, file->f_path.mnt);
25430 ++ return 0;
25431 ++ }
25432 ++#endif
25433 ++#endif
25434 ++ return 1;
25435 ++}
25436 +diff -urNp linux-2.6.27.10/grsecurity/grsum.c linux-2.6.27.10/grsecurity/grsum.c
25437 +--- linux-2.6.27.10/grsecurity/grsum.c 1969-12-31 19:00:00.000000000 -0500
25438 ++++ linux-2.6.27.10/grsecurity/grsum.c 2008-11-18 03:38:45.000000000 -0500
25439 +@@ -0,0 +1,59 @@
25440 ++#include <linux/err.h>
25441 ++#include <linux/kernel.h>
25442 ++#include <linux/sched.h>
25443 ++#include <linux/mm.h>
25444 ++#include <linux/scatterlist.h>
25445 ++#include <linux/crypto.h>
25446 ++#include <linux/gracl.h>
25447 ++
25448 ++
25449 ++#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
25450 ++#error "crypto and sha256 must be built into the kernel"
25451 ++#endif
25452 ++
25453 ++int
25454 ++chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
25455 ++{
25456 ++ char *p;
25457 ++ struct crypto_hash *tfm;
25458 ++ struct hash_desc desc;
25459 ++ struct scatterlist sg;
25460 ++ unsigned char temp_sum[GR_SHA_LEN];
25461 ++ volatile int retval = 0;
25462 ++ volatile int dummy = 0;
25463 ++ unsigned int i;
25464 ++
25465 ++ tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
25466 ++ if (IS_ERR(tfm)) {
25467 ++ /* should never happen, since sha256 should be built in */
25468 ++ return 1;
25469 ++ }
25470 ++
25471 ++ desc.tfm = tfm;
25472 ++ desc.flags = 0;
25473 ++
25474 ++ crypto_hash_init(&desc);
25475 ++
25476 ++ p = salt;
25477 ++ sg_set_buf(&sg, p, GR_SALT_LEN);
25478 ++ crypto_hash_update(&desc, &sg, sg.length);
25479 ++
25480 ++ p = entry->pw;
25481 ++ sg_set_buf(&sg, p, strlen(p));
25482 ++
25483 ++ crypto_hash_update(&desc, &sg, sg.length);
25484 ++
25485 ++ crypto_hash_final(&desc, temp_sum);
25486 ++
25487 ++ memset(entry->pw, 0, GR_PW_LEN);
25488 ++
25489 ++ for (i = 0; i < GR_SHA_LEN; i++)
25490 ++ if (sum[i] != temp_sum[i])
25491 ++ retval = 1;
25492 ++ else
25493 ++ dummy = 1; // waste a cycle
25494 ++
25495 ++ crypto_free_hash(tfm);
25496 ++
25497 ++ return retval;
25498 ++}
25499 +diff -urNp linux-2.6.27.10/grsecurity/Kconfig linux-2.6.27.10/grsecurity/Kconfig
25500 +--- linux-2.6.27.10/grsecurity/Kconfig 1969-12-31 19:00:00.000000000 -0500
25501 ++++ linux-2.6.27.10/grsecurity/Kconfig 2008-11-18 11:18:57.000000000 -0500
25502 +@@ -0,0 +1,863 @@
25503 ++#
25504 ++# grecurity configuration
25505 ++#
25506 ++
25507 ++menu "Grsecurity"
25508 ++
25509 ++config GRKERNSEC
25510 ++ bool "Grsecurity"
25511 ++ select CRYPTO
25512 ++ select CRYPTO_SHA256
25513 ++ select SECURITY
25514 ++ select SECURITY_CAPABILITIES
25515 ++ help
25516 ++ If you say Y here, you will be able to configure many features
25517 ++ that will enhance the security of your system. It is highly
25518 ++ recommended that you say Y here and read through the help
25519 ++ for each option so that you fully understand the features and
25520 ++ can evaluate their usefulness for your machine.
25521 ++
25522 ++choice
25523 ++ prompt "Security Level"
25524 ++ depends on GRKERNSEC
25525 ++ default GRKERNSEC_CUSTOM
25526 ++
25527 ++config GRKERNSEC_LOW
25528 ++ bool "Low"
25529 ++ select GRKERNSEC_LINK
25530 ++ select GRKERNSEC_FIFO
25531 ++ select GRKERNSEC_EXECVE
25532 ++ select GRKERNSEC_RANDNET
25533 ++ select GRKERNSEC_DMESG
25534 ++ select GRKERNSEC_CHROOT_CHDIR
25535 ++ select GRKERNSEC_MODSTOP if (MODULES)
25536 ++
25537 ++ help
25538 ++ If you choose this option, several of the grsecurity options will
25539 ++ be enabled that will give you greater protection against a number
25540 ++ of attacks, while assuring that none of your software will have any
25541 ++ conflicts with the additional security measures. If you run a lot
25542 ++ of unusual software, or you are having problems with the higher
25543 ++ security levels, you should say Y here. With this option, the
25544 ++ following features are enabled:
25545 ++
25546 ++ - Linking restrictions
25547 ++ - FIFO restrictions
25548 ++ - Enforcing RLIMIT_NPROC on execve
25549 ++ - Restricted dmesg
25550 ++ - Enforced chdir("/") on chroot
25551 ++ - Runtime module disabling
25552 ++
25553 ++config GRKERNSEC_MEDIUM
25554 ++ bool "Medium"
25555 ++ select PAX
25556 ++ select PAX_EI_PAX
25557 ++ select PAX_PT_PAX_FLAGS
25558 ++ select PAX_HAVE_ACL_FLAGS
25559 ++ select GRKERNSEC_PROC_MEMMAP if (PAX_NOEXEC || PAX_ASLR)
25560 ++ select GRKERNSEC_CHROOT_SYSCTL
25561 ++ select GRKERNSEC_LINK
25562 ++ select GRKERNSEC_FIFO
25563 ++ select GRKERNSEC_EXECVE
25564 ++ select GRKERNSEC_DMESG
25565 ++ select GRKERNSEC_RANDNET
25566 ++ select GRKERNSEC_FORKFAIL
25567 ++ select GRKERNSEC_TIME
25568 ++ select GRKERNSEC_SIGNAL
25569 ++ select GRKERNSEC_CHROOT
25570 ++ select GRKERNSEC_CHROOT_UNIX
25571 ++ select GRKERNSEC_CHROOT_MOUNT
25572 ++ select GRKERNSEC_CHROOT_PIVOT
25573 ++ select GRKERNSEC_CHROOT_DOUBLE
25574 ++ select GRKERNSEC_CHROOT_CHDIR
25575 ++ select GRKERNSEC_CHROOT_MKNOD
25576 ++ select GRKERNSEC_PROC
25577 ++ select GRKERNSEC_PROC_USERGROUP
25578 ++ select GRKERNSEC_MODSTOP if (MODULES)
25579 ++ select PAX_RANDUSTACK
25580 ++ select PAX_ASLR
25581 ++ select PAX_RANDMMAP
25582 ++ select PAX_REFCOUNT if (X86)
25583 ++
25584 ++ help
25585 ++ If you say Y here, several features in addition to those included
25586 ++ in the low additional security level will be enabled. These
25587 ++ features provide even more security to your system, though in rare
25588 ++ cases they may be incompatible with very old or poorly written
25589 ++ software. If you enable this option, make sure that your auth
25590 ++ service (identd) is running as gid 1001. With this option,
25591 ++ the following features (in addition to those provided in the
25592 ++ low additional security level) will be enabled:
25593 ++
25594 ++ - Failed fork logging
25595 ++ - Time change logging
25596 ++ - Signal logging
25597 ++ - Deny mounts in chroot
25598 ++ - Deny double chrooting
25599 ++ - Deny sysctl writes in chroot
25600 ++ - Deny mknod in chroot
25601 ++ - Deny access to abstract AF_UNIX sockets out of chroot
25602 ++ - Deny pivot_root in chroot
25603 ++ - Denied writes of /dev/kmem, /dev/mem, and /dev/port
25604 ++ - /proc restrictions with special GID set to 10 (usually wheel)
25605 ++ - Address Space Layout Randomization (ASLR)
25606 ++
25607 ++config GRKERNSEC_HIGH
25608 ++ bool "High"
25609 ++ select GRKERNSEC_LINK
25610 ++ select GRKERNSEC_FIFO
25611 ++ select GRKERNSEC_EXECVE
25612 ++ select GRKERNSEC_DMESG
25613 ++ select GRKERNSEC_FORKFAIL
25614 ++ select GRKERNSEC_TIME
25615 ++ select GRKERNSEC_SIGNAL
25616 ++ select GRKERNSEC_CHROOT_SHMAT
25617 ++ select GRKERNSEC_CHROOT_UNIX
25618 ++ select GRKERNSEC_CHROOT_MOUNT
25619 ++ select GRKERNSEC_CHROOT_FCHDIR
25620 ++ select GRKERNSEC_CHROOT_PIVOT
25621 ++ select GRKERNSEC_CHROOT_DOUBLE
25622 ++ select GRKERNSEC_CHROOT_CHDIR
25623 ++ select GRKERNSEC_CHROOT_MKNOD
25624 ++ select GRKERNSEC_CHROOT_CAPS
25625 ++ select GRKERNSEC_CHROOT_SYSCTL
25626 ++ select GRKERNSEC_CHROOT_FINDTASK
25627 ++ select GRKERNSEC_PROC
25628 ++ select GRKERNSEC_PROC_MEMMAP if (PAX_NOEXEC || PAX_ASLR)
25629 ++ select GRKERNSEC_HIDESYM
25630 ++ select GRKERNSEC_BRUTE
25631 ++ select GRKERNSEC_PROC_USERGROUP
25632 ++ select GRKERNSEC_KMEM
25633 ++ select GRKERNSEC_RESLOG
25634 ++ select GRKERNSEC_RANDNET
25635 ++ select GRKERNSEC_PROC_ADD
25636 ++ select GRKERNSEC_CHROOT_CHMOD
25637 ++ select GRKERNSEC_CHROOT_NICE
25638 ++ select GRKERNSEC_AUDIT_MOUNT
25639 ++ select GRKERNSEC_MODSTOP if (MODULES)
25640 ++ select PAX
25641 ++ select PAX_RANDUSTACK
25642 ++ select PAX_ASLR
25643 ++ select PAX_RANDMMAP
25644 ++ select PAX_NOEXEC
25645 ++ select PAX_MPROTECT
25646 ++ select PAX_EI_PAX
25647 ++ select PAX_PT_PAX_FLAGS
25648 ++ select PAX_HAVE_ACL_FLAGS
25649 ++ select PAX_KERNEXEC if (X86 && !EFI && !COMPAT_VDSO && !PARAVIRT && (!X86_32 || X86_WP_WORKS_OK))
25650 ++ select PAX_MEMORY_UDEREF if (!X86_64 && !COMPAT_VDSO)
25651 ++ select PAX_RANDKSTACK if (X86_TSC && !X86_64)
25652 ++ select PAX_SEGMEXEC if (X86 && !X86_64)
25653 ++ select PAX_PAGEEXEC if (!X86)
25654 ++ select PAX_EMUPLT if (ALPHA || PARISC || PPC32 || SPARC32 || SPARC64)
25655 ++ select PAX_DLRESOLVE if (SPARC32 || SPARC64)
25656 ++ select PAX_SYSCALL if (PPC32)
25657 ++ select PAX_EMUTRAMP if (PARISC)
25658 ++ select PAX_EMUSIGRT if (PARISC)
25659 ++ select PAX_ETEXECRELOCS if (ALPHA || IA64 || PARISC)
25660 ++ select PAX_REFCOUNT if (X86)
25661 ++ help
25662 ++ If you say Y here, many of the features of grsecurity will be
25663 ++ enabled, which will protect you against many kinds of attacks
25664 ++ against your system. The heightened security comes at a cost
25665 ++ of an increased chance of incompatibilities with rare software
25666 ++ on your machine. Since this security level enables PaX, you should
25667 ++ view <http://pax.grsecurity.net> and read about the PaX
25668 ++ project. While you are there, download chpax and run it on
25669 ++ binaries that cause problems with PaX. Also remember that
25670 ++ since the /proc restrictions are enabled, you must run your
25671 ++ identd as gid 1001. This security level enables the following
25672 ++ features in addition to those listed in the low and medium
25673 ++ security levels:
25674 ++
25675 ++ - Additional /proc restrictions
25676 ++ - Chmod restrictions in chroot
25677 ++ - No signals, ptrace, or viewing of processes outside of chroot
25678 ++ - Capability restrictions in chroot
25679 ++ - Deny fchdir out of chroot
25680 ++ - Priority restrictions in chroot
25681 ++ - Segmentation-based implementation of PaX
25682 ++ - Mprotect restrictions
25683 ++ - Removal of addresses from /proc/<pid>/[smaps|maps|stat]
25684 ++ - Kernel stack randomization
25685 ++ - Mount/unmount/remount logging
25686 ++ - Kernel symbol hiding
25687 ++ - Prevention of memory exhaustion-based exploits
25688 ++config GRKERNSEC_CUSTOM
25689 ++ bool "Custom"
25690 ++ help
25691 ++ If you say Y here, you will be able to configure every grsecurity
25692 ++ option, which allows you to enable many more features that aren't
25693 ++ covered in the basic security levels. These additional features
25694 ++ include TPE, socket restrictions, and the sysctl system for
25695 ++ grsecurity. It is advised that you read through the help for
25696 ++ each option to determine its usefulness in your situation.
25697 ++
25698 ++endchoice
25699 ++
25700 ++menu "Address Space Protection"
25701 ++depends on GRKERNSEC
25702 ++
25703 ++config GRKERNSEC_KMEM
25704 ++ bool "Deny writing to /dev/kmem, /dev/mem, and /dev/port"
25705 ++ help
25706 ++ If you say Y here, /dev/kmem and /dev/mem won't be allowed to
25707 ++ be written to via mmap or otherwise to modify the running kernel.
25708 ++ /dev/port will also not be allowed to be opened. If you have module
25709 ++ support disabled, enabling this will close up four ways that are
25710 ++ currently used to insert malicious code into the running kernel.
25711 ++ Even with all these features enabled, we still highly recommend that
25712 ++ you use the RBAC system, as it is still possible for an attacker to
25713 ++ modify the running kernel through privileged I/O granted by ioperm/iopl.
25714 ++ If you are not using XFree86, you may be able to stop this additional
25715 ++ case by enabling the 'Disable privileged I/O' option. Though nothing
25716 ++ legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
25717 ++ but only to video memory, which is the only writing we allow in this
25718 ++ case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
25719 ++ not be allowed to mprotect it with PROT_WRITE later.
25720 ++ It is highly recommended that you say Y here if you meet all the
25721 ++ conditions above.
25722 ++
25723 ++config GRKERNSEC_IO
25724 ++ bool "Disable privileged I/O"
25725 ++ depends on X86
25726 ++ select RTC
25727 ++ help
25728 ++ If you say Y here, all ioperm and iopl calls will return an error.
25729 ++ Ioperm and iopl can be used to modify the running kernel.
25730 ++ Unfortunately, some programs need this access to operate properly,
25731 ++ the most notable of which are XFree86 and hwclock. hwclock can be
25732 ++ remedied by having RTC support in the kernel, so CONFIG_RTC is
25733 ++ enabled if this option is enabled, to ensure that hwclock operates
25734 ++ correctly. XFree86 still will not operate correctly with this option
25735 ++ enabled, so DO NOT CHOOSE Y IF YOU USE XFree86. If you use XFree86
25736 ++ and you still want to protect your kernel against modification,
25737 ++ use the RBAC system.
25738 ++
25739 ++config GRKERNSEC_PROC_MEMMAP
25740 ++ bool "Remove addresses from /proc/<pid>/[smaps|maps|stat]"
25741 ++ depends on PAX_NOEXEC || PAX_ASLR
25742 ++ help
25743 ++ If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
25744 ++ give no information about the addresses of its mappings if
25745 ++ PaX features that rely on random addresses are enabled on the task.
25746 ++ If you use PaX it is greatly recommended that you say Y here as it
25747 ++ closes up a hole that makes the full ASLR useless for suid
25748 ++ binaries.
25749 ++
25750 ++config GRKERNSEC_BRUTE
25751 ++ bool "Deter exploit bruteforcing"
25752 ++ help
25753 ++ If you say Y here, attempts to bruteforce exploits against forking
25754 ++ daemons such as apache or sshd will be deterred. When a child of a
25755 ++ forking daemon is killed by PaX or crashes due to an illegal
25756 ++ instruction, the parent process will be delayed 30 seconds upon every
25757 ++ subsequent fork until the administrator is able to assess the
25758 ++ situation and restart the daemon. It is recommended that you also
25759 ++ enable signal logging in the auditing section so that logs are
25760 ++ generated when a process performs an illegal instruction.
25761 ++
25762 ++config GRKERNSEC_MODSTOP
25763 ++ bool "Runtime module disabling"
25764 ++ depends on MODULES
25765 ++ help
25766 ++ If you say Y here, you will be able to disable the ability to (un)load
25767 ++ modules at runtime. This feature is useful if you need the ability
25768 ++ to load kernel modules at boot time, but do not want to allow an
25769 ++ attacker to load a rootkit kernel module into the system, or to remove
25770 ++ a loaded kernel module important to system functioning. You should
25771 ++ enable the /dev/mem protection feature as well, since rootkits can be
25772 ++ inserted into the kernel via other methods than kernel modules. Since
25773 ++ an untrusted module could still be loaded by modifying init scripts and
25774 ++ rebooting the system, it is also recommended that you enable the RBAC
25775 ++ system. If you enable this option, a sysctl option with name
25776 ++ "disable_modules" will be created. Setting this option to "1" disables
25777 ++ module loading. After this option is set, no further writes to it are
25778 ++ allowed until the system is rebooted.
25779 ++
25780 ++config GRKERNSEC_HIDESYM
25781 ++ bool "Hide kernel symbols"
25782 ++ help
25783 ++ If you say Y here, getting information on loaded modules, and
25784 ++ displaying all kernel symbols through a syscall will be restricted
25785 ++ to users with CAP_SYS_MODULE. This option is only effective
25786 ++ provided the following conditions are met:
25787 ++ 1) The kernel using grsecurity is not precompiled by some distribution
25788 ++ 2) You are using the RBAC system and hiding other files such as your
25789 ++ kernel image and System.map
25790 ++ 3) You have the additional /proc restrictions enabled, which removes
25791 ++ /proc/kcore
25792 ++ If the above conditions are met, this option will aid to provide a
25793 ++ useful protection against local and remote kernel exploitation of
25794 ++ overflows and arbitrary read/write vulnerabilities.
25795 ++
25796 ++endmenu
25797 ++menu "Role Based Access Control Options"
25798 ++depends on GRKERNSEC
25799 ++
25800 ++config GRKERNSEC_ACL_HIDEKERN
25801 ++ bool "Hide kernel processes"
25802 ++ help
25803 ++ If you say Y here, all kernel threads will be hidden to all
25804 ++ processes but those whose subject has the "view hidden processes"
25805 ++ flag.
25806 ++
25807 ++config GRKERNSEC_ACL_MAXTRIES
25808 ++ int "Maximum tries before password lockout"
25809 ++ default 3
25810 ++ help
25811 ++ This option enforces the maximum number of times a user can attempt
25812 ++ to authorize themselves with the grsecurity RBAC system before being
25813 ++ denied the ability to attempt authorization again for a specified time.
25814 ++ The lower the number, the harder it will be to brute-force a password.
25815 ++
25816 ++config GRKERNSEC_ACL_TIMEOUT
25817 ++ int "Time to wait after max password tries, in seconds"
25818 ++ default 30
25819 ++ help
25820 ++ This option specifies the time the user must wait after attempting to
25821 ++ authorize to the RBAC system with the maximum number of invalid
25822 ++ passwords. The higher the number, the harder it will be to brute-force
25823 ++ a password.
25824 ++
25825 ++endmenu
25826 ++menu "Filesystem Protections"
25827 ++depends on GRKERNSEC
25828 ++
25829 ++config GRKERNSEC_PROC
25830 ++ bool "Proc restrictions"
25831 ++ help
25832 ++ If you say Y here, the permissions of the /proc filesystem
25833 ++ will be altered to enhance system security and privacy. You MUST
25834 ++ choose either a user only restriction or a user and group restriction.
25835 ++ Depending upon the option you choose, you can either restrict users to
25836 ++ see only the processes they themselves run, or choose a group that can
25837 ++ view all processes and files normally restricted to root if you choose
25838 ++ the "restrict to user only" option. NOTE: If you're running identd as
25839 ++ a non-root user, you will have to run it as the group you specify here.
25840 ++
25841 ++config GRKERNSEC_PROC_USER
25842 ++ bool "Restrict /proc to user only"
25843 ++ depends on GRKERNSEC_PROC
25844 ++ help
25845 ++ If you say Y here, non-root users will only be able to view their own
25846 ++ processes, and restricts them from viewing network-related information,
25847 ++ and viewing kernel symbol and module information.
25848 ++
25849 ++config GRKERNSEC_PROC_USERGROUP
25850 ++ bool "Allow special group"
25851 ++ depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
25852 ++ help
25853 ++ If you say Y here, you will be able to select a group that will be
25854 ++ able to view all processes, network-related information, and
25855 ++ kernel and symbol information. This option is useful if you want
25856 ++ to run identd as a non-root user.
25857 ++
25858 ++config GRKERNSEC_PROC_GID
25859 ++ int "GID for special group"
25860 ++ depends on GRKERNSEC_PROC_USERGROUP
25861 ++ default 1001
25862 ++
25863 ++config GRKERNSEC_PROC_ADD
25864 ++ bool "Additional restrictions"
25865 ++ depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
25866 ++ help
25867 ++ If you say Y here, additional restrictions will be placed on
25868 ++ /proc that keep normal users from viewing device information and
25869 ++ slabinfo information that could be useful for exploits.
25870 ++
25871 ++config GRKERNSEC_LINK
25872 ++ bool "Linking restrictions"
25873 ++ help
25874 ++ If you say Y here, /tmp race exploits will be prevented, since users
25875 ++ will no longer be able to follow symlinks owned by other users in
25876 ++ world-writable +t directories (i.e. /tmp), unless the owner of the
25877 ++ symlink is the owner of the directory. users will also not be
25878 ++ able to hardlink to files they do not own. If the sysctl option is
25879 ++ enabled, a sysctl option with name "linking_restrictions" is created.
25880 ++
25881 ++config GRKERNSEC_FIFO
25882 ++ bool "FIFO restrictions"
25883 ++ help
25884 ++ If you say Y here, users will not be able to write to FIFOs they don't
25885 ++ own in world-writable +t directories (i.e. /tmp), unless the owner of
25886 ++ the FIFO is the same owner of the directory it's held in. If the sysctl
25887 ++ option is enabled, a sysctl option with name "fifo_restrictions" is
25888 ++ created.
25889 ++
25890 ++config GRKERNSEC_CHROOT
25891 ++ bool "Chroot jail restrictions"
25892 ++ help
25893 ++ If you say Y here, you will be able to choose several options that will
25894 ++ make breaking out of a chrooted jail much more difficult. If you
25895 ++ encounter no software incompatibilities with the following options, it
25896 ++ is recommended that you enable each one.
25897 ++
25898 ++config GRKERNSEC_CHROOT_MOUNT
25899 ++ bool "Deny mounts"
25900 ++ depends on GRKERNSEC_CHROOT
25901 ++ help
25902 ++ If you say Y here, processes inside a chroot will not be able to
25903 ++ mount or remount filesystems. If the sysctl option is enabled, a
25904 ++ sysctl option with name "chroot_deny_mount" is created.
25905 ++
25906 ++config GRKERNSEC_CHROOT_DOUBLE
25907 ++ bool "Deny double-chroots"
25908 ++ depends on GRKERNSEC_CHROOT
25909 ++ help
25910 ++ If you say Y here, processes inside a chroot will not be able to chroot
25911 ++ again outside the chroot. This is a widely used method of breaking
25912 ++ out of a chroot jail and should not be allowed. If the sysctl
25913 ++ option is enabled, a sysctl option with name
25914 ++ "chroot_deny_chroot" is created.
25915 ++
25916 ++config GRKERNSEC_CHROOT_PIVOT
25917 ++ bool "Deny pivot_root in chroot"
25918 ++ depends on GRKERNSEC_CHROOT
25919 ++ help
25920 ++ If you say Y here, processes inside a chroot will not be able to use
25921 ++ a function called pivot_root() that was introduced in Linux 2.3.41. It
25922 ++ works similar to chroot in that it changes the root filesystem. This
25923 ++ function could be misused in a chrooted process to attempt to break out
25924 ++ of the chroot, and therefore should not be allowed. If the sysctl
25925 ++ option is enabled, a sysctl option with name "chroot_deny_pivot" is
25926 ++ created.
25927 ++
25928 ++config GRKERNSEC_CHROOT_CHDIR
25929 ++ bool "Enforce chdir(\"/\") on all chroots"
25930 ++ depends on GRKERNSEC_CHROOT
25931 ++ help
25932 ++ If you say Y here, the current working directory of all newly-chrooted
25933 ++ applications will be set to the the root directory of the chroot.
25934 ++ The man page on chroot(2) states:
25935 ++ Note that this call does not change the current working
25936 ++ directory, so that `.' can be outside the tree rooted at
25937 ++ `/'. In particular, the super-user can escape from a
25938 ++ `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
25939 ++
25940 ++ It is recommended that you say Y here, since it's not known to break
25941 ++ any software. If the sysctl option is enabled, a sysctl option with
25942 ++ name "chroot_enforce_chdir" is created.
25943 ++
25944 ++config GRKERNSEC_CHROOT_CHMOD
25945 ++ bool "Deny (f)chmod +s"
25946 ++ depends on GRKERNSEC_CHROOT
25947 ++ help
25948 ++ If you say Y here, processes inside a chroot will not be able to chmod
25949 ++ or fchmod files to make them have suid or sgid bits. This protects
25950 ++ against another published method of breaking a chroot. If the sysctl
25951 ++ option is enabled, a sysctl option with name "chroot_deny_chmod" is
25952 ++ created.
25953 ++
25954 ++config GRKERNSEC_CHROOT_FCHDIR
25955 ++ bool "Deny fchdir out of chroot"
25956 ++ depends on GRKERNSEC_CHROOT
25957 ++ help
25958 ++ If you say Y here, a well-known method of breaking chroots by fchdir'ing
25959 ++ to a file descriptor of the chrooting process that points to a directory
25960 ++ outside the filesystem will be stopped. If the sysctl option
25961 ++ is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
25962 ++
25963 ++config GRKERNSEC_CHROOT_MKNOD
25964 ++ bool "Deny mknod"
25965 ++ depends on GRKERNSEC_CHROOT
25966 ++ help
25967 ++ If you say Y here, processes inside a chroot will not be allowed to
25968 ++ mknod. The problem with using mknod inside a chroot is that it
25969 ++ would allow an attacker to create a device entry that is the same
25970 ++ as one on the physical root of your system, which could range from
25971 ++ anything from the console device to a device for your harddrive (which
25972 ++ they could then use to wipe the drive or steal data). It is recommended
25973 ++ that you say Y here, unless you run into software incompatibilities.
25974 ++ If the sysctl option is enabled, a sysctl option with name
25975 ++ "chroot_deny_mknod" is created.
25976 ++
25977 ++config GRKERNSEC_CHROOT_SHMAT
25978 ++ bool "Deny shmat() out of chroot"
25979 ++ depends on GRKERNSEC_CHROOT
25980 ++ help
25981 ++ If you say Y here, processes inside a chroot will not be able to attach
25982 ++ to shared memory segments that were created outside of the chroot jail.
25983 ++ It is recommended that you say Y here. If the sysctl option is enabled,
25984 ++ a sysctl option with name "chroot_deny_shmat" is created.
25985 ++
25986 ++config GRKERNSEC_CHROOT_UNIX
25987 ++ bool "Deny access to abstract AF_UNIX sockets out of chroot"
25988 ++ depends on GRKERNSEC_CHROOT
25989 ++ help
25990 ++ If you say Y here, processes inside a chroot will not be able to
25991 ++ connect to abstract (meaning not belonging to a filesystem) Unix
25992 ++ domain sockets that were bound outside of a chroot. It is recommended
25993 ++ that you say Y here. If the sysctl option is enabled, a sysctl option
25994 ++ with name "chroot_deny_unix" is created.
25995 ++
25996 ++config GRKERNSEC_CHROOT_FINDTASK
25997 ++ bool "Protect outside processes"
25998 ++ depends on GRKERNSEC_CHROOT
25999 ++ help
26000 ++ If you say Y here, processes inside a chroot will not be able to
26001 ++ kill, send signals with fcntl, ptrace, capget, getpgid, getsid,
26002 ++ or view any process outside of the chroot. If the sysctl
26003 ++ option is enabled, a sysctl option with name "chroot_findtask" is
26004 ++ created.
26005 ++
26006 ++config GRKERNSEC_CHROOT_NICE
26007 ++ bool "Restrict priority changes"
26008 ++ depends on GRKERNSEC_CHROOT
26009 ++ help
26010 ++ If you say Y here, processes inside a chroot will not be able to raise
26011 ++ the priority of processes in the chroot, or alter the priority of
26012 ++ processes outside the chroot. This provides more security than simply
26013 ++ removing CAP_SYS_NICE from the process' capability set. If the
26014 ++ sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
26015 ++ is created.
26016 ++
26017 ++config GRKERNSEC_CHROOT_SYSCTL
26018 ++ bool "Deny sysctl writes"
26019 ++ depends on GRKERNSEC_CHROOT
26020 ++ help
26021 ++ If you say Y here, an attacker in a chroot will not be able to
26022 ++ write to sysctl entries, either by sysctl(2) or through a /proc
26023 ++ interface. It is strongly recommended that you say Y here. If the
26024 ++ sysctl option is enabled, a sysctl option with name
26025 ++ "chroot_deny_sysctl" is created.
26026 ++
26027 ++config GRKERNSEC_CHROOT_CAPS
26028 ++ bool "Capability restrictions"
26029 ++ depends on GRKERNSEC_CHROOT
26030 ++ help
26031 ++ If you say Y here, the capabilities on all root processes within a
26032 ++ chroot jail will be lowered to stop module insertion, raw i/o,
26033 ++ system and net admin tasks, rebooting the system, modifying immutable
26034 ++ files, modifying IPC owned by another, and changing the system time.
26035 ++ This is left an option because it can break some apps. Disable this
26036 ++ if your chrooted apps are having problems performing those kinds of
26037 ++ tasks. If the sysctl option is enabled, a sysctl option with
26038 ++ name "chroot_caps" is created.
26039 ++
26040 ++endmenu
26041 ++menu "Kernel Auditing"
26042 ++depends on GRKERNSEC
26043 ++
26044 ++config GRKERNSEC_AUDIT_GROUP
26045 ++ bool "Single group for auditing"
26046 ++ help
26047 ++ If you say Y here, the exec, chdir, (un)mount, and ipc logging features
26048 ++ will only operate on a group you specify. This option is recommended
26049 ++ if you only want to watch certain users instead of having a large
26050 ++ amount of logs from the entire system. If the sysctl option is enabled,
26051 ++ a sysctl option with name "audit_group" is created.
26052 ++
26053 ++config GRKERNSEC_AUDIT_GID
26054 ++ int "GID for auditing"
26055 ++ depends on GRKERNSEC_AUDIT_GROUP
26056 ++ default 1007
26057 ++
26058 ++config GRKERNSEC_EXECLOG
26059 ++ bool "Exec logging"
26060 ++ help
26061 ++ If you say Y here, all execve() calls will be logged (since the
26062 ++ other exec*() calls are frontends to execve(), all execution
26063 ++ will be logged). Useful for shell-servers that like to keep track
26064 ++ of their users. If the sysctl option is enabled, a sysctl option with
26065 ++ name "exec_logging" is created.
26066 ++ WARNING: This option when enabled will produce a LOT of logs, especially
26067 ++ on an active system.
26068 ++
26069 ++config GRKERNSEC_RESLOG
26070 ++ bool "Resource logging"
26071 ++ help
26072 ++ If you say Y here, all attempts to overstep resource limits will
26073 ++ be logged with the resource name, the requested size, and the current
26074 ++ limit. It is highly recommended that you say Y here. If the sysctl
26075 ++ option is enabled, a sysctl option with name "resource_logging" is
26076 ++ created. If the RBAC system is enabled, the sysctl value is ignored.
26077 ++
26078 ++config GRKERNSEC_CHROOT_EXECLOG
26079 ++ bool "Log execs within chroot"
26080 ++ help
26081 ++ If you say Y here, all executions inside a chroot jail will be logged
26082 ++ to syslog. This can cause a large amount of logs if certain
26083 ++ applications (eg. djb's daemontools) are installed on the system, and
26084 ++ is therefore left as an option. If the sysctl option is enabled, a
26085 ++ sysctl option with name "chroot_execlog" is created.
26086 ++
26087 ++config GRKERNSEC_AUDIT_CHDIR
26088 ++ bool "Chdir logging"
26089 ++ help
26090 ++ If you say Y here, all chdir() calls will be logged. If the sysctl
26091 ++ option is enabled, a sysctl option with name "audit_chdir" is created.
26092 ++
26093 ++config GRKERNSEC_AUDIT_MOUNT
26094 ++ bool "(Un)Mount logging"
26095 ++ help
26096 ++ If you say Y here, all mounts and unmounts will be logged. If the
26097 ++ sysctl option is enabled, a sysctl option with name "audit_mount" is
26098 ++ created.
26099 ++
26100 ++config GRKERNSEC_AUDIT_IPC
26101 ++ bool "IPC logging"
26102 ++ help
26103 ++ If you say Y here, creation and removal of message queues, semaphores,
26104 ++ and shared memory will be logged. If the sysctl option is enabled, a
26105 ++ sysctl option with name "audit_ipc" is created.
26106 ++
26107 ++config GRKERNSEC_SIGNAL
26108 ++ bool "Signal logging"
26109 ++ help
26110 ++ If you say Y here, certain important signals will be logged, such as
26111 ++ SIGSEGV, which will as a result inform you of when a error in a program
26112 ++ occurred, which in some cases could mean a possible exploit attempt.
26113 ++ If the sysctl option is enabled, a sysctl option with name
26114 ++ "signal_logging" is created.
26115 ++
26116 ++config GRKERNSEC_FORKFAIL
26117 ++ bool "Fork failure logging"
26118 ++ help
26119 ++ If you say Y here, all failed fork() attempts will be logged.
26120 ++ This could suggest a fork bomb, or someone attempting to overstep
26121 ++ their process limit. If the sysctl option is enabled, a sysctl option
26122 ++ with name "forkfail_logging" is created.
26123 ++
26124 ++config GRKERNSEC_TIME
26125 ++ bool "Time change logging"
26126 ++ help
26127 ++ If you say Y here, any changes of the system clock will be logged.
26128 ++ If the sysctl option is enabled, a sysctl option with name
26129 ++ "timechange_logging" is created.
26130 ++
26131 ++config GRKERNSEC_PROC_IPADDR
26132 ++ bool "/proc/<pid>/ipaddr support"
26133 ++ help
26134 ++ If you say Y here, a new entry will be added to each /proc/<pid>
26135 ++ directory that contains the IP address of the person using the task.
26136 ++ The IP is carried across local TCP and AF_UNIX stream sockets.
26137 ++ This information can be useful for IDS/IPSes to perform remote response
26138 ++ to a local attack. The entry is readable by only the owner of the
26139 ++ process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
26140 ++ the RBAC system), and thus does not create privacy concerns.
26141 ++
26142 ++config GRKERNSEC_AUDIT_TEXTREL
26143 ++ bool 'ELF text relocations logging (READ HELP)'
26144 ++ depends on PAX_MPROTECT
26145 ++ help
26146 ++ If you say Y here, text relocations will be logged with the filename
26147 ++ of the offending library or binary. The purpose of the feature is
26148 ++ to help Linux distribution developers get rid of libraries and
26149 ++ binaries that need text relocations which hinder the future progress
26150 ++ of PaX. Only Linux distribution developers should say Y here, and
26151 ++ never on a production machine, as this option creates an information
26152 ++ leak that could aid an attacker in defeating the randomization of
26153 ++ a single memory region. If the sysctl option is enabled, a sysctl
26154 ++ option with name "audit_textrel" is created.
26155 ++
26156 ++endmenu
26157 ++
26158 ++menu "Executable Protections"
26159 ++depends on GRKERNSEC
26160 ++
26161 ++config GRKERNSEC_EXECVE
26162 ++ bool "Enforce RLIMIT_NPROC on execs"
26163 ++ help
26164 ++ If you say Y here, users with a resource limit on processes will
26165 ++ have the value checked during execve() calls. The current system
26166 ++ only checks the system limit during fork() calls. If the sysctl option
26167 ++ is enabled, a sysctl option with name "execve_limiting" is created.
26168 ++
26169 ++config GRKERNSEC_DMESG
26170 ++ bool "Dmesg(8) restriction"
26171 ++ help
26172 ++ If you say Y here, non-root users will not be able to use dmesg(8)
26173 ++ to view up to the last 4kb of messages in the kernel's log buffer.
26174 ++ If the sysctl option is enabled, a sysctl option with name "dmesg" is
26175 ++ created.
26176 ++
26177 ++config GRKERNSEC_TPE
26178 ++ bool "Trusted Path Execution (TPE)"
26179 ++ help
26180 ++ If you say Y here, you will be able to choose a gid to add to the
26181 ++ supplementary groups of users you want to mark as "untrusted."
26182 ++ These users will not be able to execute any files that are not in
26183 ++ root-owned directories writable only by root. If the sysctl option
26184 ++ is enabled, a sysctl option with name "tpe" is created.
26185 ++
26186 ++config GRKERNSEC_TPE_ALL
26187 ++ bool "Partially restrict non-root users"
26188 ++ depends on GRKERNSEC_TPE
26189 ++ help
26190 ++ If you say Y here, All non-root users other than the ones in the
26191 ++ group specified in the main TPE option will only be allowed to
26192 ++ execute files in directories they own that are not group or
26193 ++ world-writable, or in directories owned by root and writable only by
26194 ++ root. If the sysctl option is enabled, a sysctl option with name
26195 ++ "tpe_restrict_all" is created.
26196 ++
26197 ++config GRKERNSEC_TPE_INVERT
26198 ++ bool "Invert GID option"
26199 ++ depends on GRKERNSEC_TPE
26200 ++ help
26201 ++ If you say Y here, the group you specify in the TPE configuration will
26202 ++ decide what group TPE restrictions will be *disabled* for. This
26203 ++ option is useful if you want TPE restrictions to be applied to most
26204 ++ users on the system.
26205 ++
26206 ++config GRKERNSEC_TPE_GID
26207 ++ int "GID for untrusted users"
26208 ++ depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
26209 ++ default 1005
26210 ++ help
26211 ++ If you have selected the "Invert GID option" above, setting this
26212 ++ GID determines what group TPE restrictions will be *disabled* for.
26213 ++ If you have not selected the "Invert GID option" above, setting this
26214 ++ GID determines what group TPE restrictions will be *enabled* for.
26215 ++ If the sysctl option is enabled, a sysctl option with name "tpe_gid"
26216 ++ is created.
26217 ++
26218 ++config GRKERNSEC_TPE_GID
26219 ++ int "GID for trusted users"
26220 ++ depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
26221 ++ default 1005
26222 ++ help
26223 ++ If you have selected the "Invert GID option" above, setting this
26224 ++ GID determines what group TPE restrictions will be *disabled* for.
26225 ++ If you have not selected the "Invert GID option" above, setting this
26226 ++ GID determines what group TPE restrictions will be *enabled* for.
26227 ++ If the sysctl option is enabled, a sysctl option with name "tpe_gid"
26228 ++ is created.
26229 ++
26230 ++endmenu
26231 ++menu "Network Protections"
26232 ++depends on GRKERNSEC
26233 ++
26234 ++config GRKERNSEC_RANDNET
26235 ++ bool "Larger entropy pools"
26236 ++ help
26237 ++ If you say Y here, the entropy pools used for many features of Linux
26238 ++ and grsecurity will be doubled in size. Since several grsecurity
26239 ++ features use additional randomness, it is recommended that you say Y
26240 ++ here. Saying Y here has a similar effect as modifying
26241 ++ /proc/sys/kernel/random/poolsize.
26242 ++
26243 ++config GRKERNSEC_SOCKET
26244 ++ bool "Socket restrictions"
26245 ++ help
26246 ++ If you say Y here, you will be able to choose from several options.
26247 ++ If you assign a GID on your system and add it to the supplementary
26248 ++ groups of users you want to restrict socket access to, this patch
26249 ++ will perform up to three things, based on the option(s) you choose.
26250 ++
26251 ++config GRKERNSEC_SOCKET_ALL
26252 ++ bool "Deny any sockets to group"
26253 ++ depends on GRKERNSEC_SOCKET
26254 ++ help
26255 ++ If you say Y here, you will be able to choose a GID of whose users will
26256 ++ be unable to connect to other hosts from your machine or run server
26257 ++ applications from your machine. If the sysctl option is enabled, a
26258 ++ sysctl option with name "socket_all" is created.
26259 ++
26260 ++config GRKERNSEC_SOCKET_ALL_GID
26261 ++ int "GID to deny all sockets for"
26262 ++ depends on GRKERNSEC_SOCKET_ALL
26263 ++ default 1004
26264 ++ help
26265 ++ Here you can choose the GID to disable socket access for. Remember to
26266 ++ add the users you want socket access disabled for to the GID
26267 ++ specified here. If the sysctl option is enabled, a sysctl option
26268 ++ with name "socket_all_gid" is created.
26269 ++
26270 ++config GRKERNSEC_SOCKET_CLIENT
26271 ++ bool "Deny client sockets to group"
26272 ++ depends on GRKERNSEC_SOCKET
26273 ++ help
26274 ++ If you say Y here, you will be able to choose a GID of whose users will
26275 ++ be unable to connect to other hosts from your machine, but will be
26276 ++ able to run servers. If this option is enabled, all users in the group
26277 ++ you specify will have to use passive mode when initiating ftp transfers
26278 ++ from the shell on your machine. If the sysctl option is enabled, a
26279 ++ sysctl option with name "socket_client" is created.
26280 ++
26281 ++config GRKERNSEC_SOCKET_CLIENT_GID
26282 ++ int "GID to deny client sockets for"
26283 ++ depends on GRKERNSEC_SOCKET_CLIENT
26284 ++ default 1003
26285 ++ help
26286 ++ Here you can choose the GID to disable client socket access for.
26287 ++ Remember to add the users you want client socket access disabled for to
26288 ++ the GID specified here. If the sysctl option is enabled, a sysctl
26289 ++ option with name "socket_client_gid" is created.
26290 ++
26291 ++config GRKERNSEC_SOCKET_SERVER
26292 ++ bool "Deny server sockets to group"
26293 ++ depends on GRKERNSEC_SOCKET
26294 ++ help
26295 ++ If you say Y here, you will be able to choose a GID of whose users will
26296 ++ be unable to run server applications from your machine. If the sysctl
26297 ++ option is enabled, a sysctl option with name "socket_server" is created.
26298 ++
26299 ++config GRKERNSEC_SOCKET_SERVER_GID
26300 ++ int "GID to deny server sockets for"
26301 ++ depends on GRKERNSEC_SOCKET_SERVER
26302 ++ default 1002
26303 ++ help
26304 ++ Here you can choose the GID to disable server socket access for.
26305 ++ Remember to add the users you want server socket access disabled for to
26306 ++ the GID specified here. If the sysctl option is enabled, a sysctl
26307 ++ option with name "socket_server_gid" is created.
26308 ++
26309 ++endmenu
26310 ++menu "Sysctl support"
26311 ++depends on GRKERNSEC && SYSCTL
26312 ++
26313 ++config GRKERNSEC_SYSCTL
26314 ++ bool "Sysctl support"
26315 ++ help
26316 ++ If you say Y here, you will be able to change the options that
26317 ++ grsecurity runs with at bootup, without having to recompile your
26318 ++ kernel. You can echo values to files in /proc/sys/kernel/grsecurity
26319 ++ to enable (1) or disable (0) various features. All the sysctl entries
26320 ++ are mutable until the "grsec_lock" entry is set to a non-zero value.
26321 ++ All features enabled in the kernel configuration are disabled at boot
26322 ++ if you do not say Y to the "Turn on features by default" option.
26323 ++ All options should be set at startup, and the grsec_lock entry should
26324 ++ be set to a non-zero value after all the options are set.
26325 ++ *THIS IS EXTREMELY IMPORTANT*
26326 ++
26327 ++config GRKERNSEC_SYSCTL_ON
26328 ++ bool "Turn on features by default"
26329 ++ depends on GRKERNSEC_SYSCTL
26330 ++ help
26331 ++ If you say Y here, instead of having all features enabled in the
26332 ++ kernel configuration disabled at boot time, the features will be
26333 ++ enabled at boot time. It is recommended you say Y here unless
26334 ++ there is some reason you would want all sysctl-tunable features to
26335 ++ be disabled by default. As mentioned elsewhere, it is important
26336 ++ to enable the grsec_lock entry once you have finished modifying
26337 ++ the sysctl entries.
26338 ++
26339 ++endmenu
26340 ++menu "Logging Options"
26341 ++depends on GRKERNSEC
26342 ++
26343 ++config GRKERNSEC_FLOODTIME
26344 ++ int "Seconds in between log messages (minimum)"
26345 ++ default 10
26346 ++ help
26347 ++ This option allows you to enforce the number of seconds between
26348 ++ grsecurity log messages. The default should be suitable for most
26349 ++ people, however, if you choose to change it, choose a value small enough
26350 ++ to allow informative logs to be produced, but large enough to
26351 ++ prevent flooding.
26352 ++
26353 ++config GRKERNSEC_FLOODBURST
26354 ++ int "Number of messages in a burst (maximum)"
26355 ++ default 4
26356 ++ help
26357 ++ This option allows you to choose the maximum number of messages allowed
26358 ++ within the flood time interval you chose in a separate option. The
26359 ++ default should be suitable for most people, however if you find that
26360 ++ many of your logs are being interpreted as flooding, you may want to
26361 ++ raise this value.
26362 ++
26363 ++endmenu
26364 ++
26365 ++endmenu
26366 +diff -urNp linux-2.6.27.10/grsecurity/Makefile linux-2.6.27.10/grsecurity/Makefile
26367 +--- linux-2.6.27.10/grsecurity/Makefile 1969-12-31 19:00:00.000000000 -0500
26368 ++++ linux-2.6.27.10/grsecurity/Makefile 2008-11-18 03:38:45.000000000 -0500
26369 +@@ -0,0 +1,20 @@
26370 ++# grsecurity's ACL system was originally written in 2001 by Michael Dalton
26371 ++# during 2001-2005 it has been completely redesigned by Brad Spengler
26372 ++# into an RBAC system
26373 ++#
26374 ++# All code in this directory and various hooks inserted throughout the kernel
26375 ++# are copyright Brad Spengler, and released under the GPL v2 or higher
26376 ++
26377 ++obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
26378 ++ grsec_mount.o grsec_sig.o grsec_sock.o grsec_sysctl.o \
26379 ++ grsec_time.o grsec_tpe.o grsec_ipc.o grsec_link.o grsec_textrel.o
26380 ++
26381 ++obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_ip.o gracl_segv.o \
26382 ++ gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
26383 ++ gracl_learn.o grsec_log.o
26384 ++obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
26385 ++
26386 ++ifndef CONFIG_GRKERNSEC
26387 ++obj-y += grsec_disabled.o
26388 ++endif
26389 ++
26390 +diff -urNp linux-2.6.27.10/include/asm-cris/kmap_types.h linux-2.6.27.10/include/asm-cris/kmap_types.h
26391 +--- linux-2.6.27.10/include/asm-cris/kmap_types.h 2008-11-07 12:55:34.000000000 -0500
26392 ++++ linux-2.6.27.10/include/asm-cris/kmap_types.h 2008-11-18 03:38:45.000000000 -0500
26393 +@@ -19,6 +19,7 @@ enum km_type {
26394 + KM_IRQ1,
26395 + KM_SOFTIRQ0,
26396 + KM_SOFTIRQ1,
26397 ++ KM_CLEARPAGE,
26398 + KM_TYPE_NR
26399 + };
26400 +
26401 +diff -urNp linux-2.6.27.10/include/asm-frv/kmap_types.h linux-2.6.27.10/include/asm-frv/kmap_types.h
26402 +--- linux-2.6.27.10/include/asm-frv/kmap_types.h 2008-11-07 12:55:34.000000000 -0500
26403 ++++ linux-2.6.27.10/include/asm-frv/kmap_types.h 2008-11-18 03:38:45.000000000 -0500
26404 +@@ -23,6 +23,7 @@ enum km_type {
26405 + KM_IRQ1,
26406 + KM_SOFTIRQ0,
26407 + KM_SOFTIRQ1,
26408 ++ KM_CLEARPAGE,
26409 + KM_TYPE_NR
26410 + };
26411 +
26412 +diff -urNp linux-2.6.27.10/include/asm-generic/futex.h linux-2.6.27.10/include/asm-generic/futex.h
26413 +--- linux-2.6.27.10/include/asm-generic/futex.h 2008-11-07 12:55:34.000000000 -0500
26414 ++++ linux-2.6.27.10/include/asm-generic/futex.h 2008-11-18 03:38:45.000000000 -0500
26415 +@@ -6,7 +6,7 @@
26416 + #include <asm/errno.h>
26417 +
26418 + static inline int
26419 +-futex_atomic_op_inuser (int encoded_op, int __user *uaddr)
26420 ++futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
26421 + {
26422 + int op = (encoded_op >> 28) & 7;
26423 + int cmp = (encoded_op >> 24) & 15;
26424 +@@ -48,7 +48,7 @@ futex_atomic_op_inuser (int encoded_op,
26425 + }
26426 +
26427 + static inline int
26428 +-futex_atomic_cmpxchg_inatomic(int __user *uaddr, int oldval, int newval)
26429 ++futex_atomic_cmpxchg_inatomic(u32 __user *uaddr, int oldval, int newval)
26430 + {
26431 + return -ENOSYS;
26432 + }
26433 +diff -urNp linux-2.6.27.10/include/asm-generic/vmlinux.lds.h linux-2.6.27.10/include/asm-generic/vmlinux.lds.h
26434 +--- linux-2.6.27.10/include/asm-generic/vmlinux.lds.h 2008-11-07 12:55:34.000000000 -0500
26435 ++++ linux-2.6.27.10/include/asm-generic/vmlinux.lds.h 2008-11-18 03:38:45.000000000 -0500
26436 +@@ -59,6 +59,7 @@
26437 + .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
26438 + VMLINUX_SYMBOL(__start_rodata) = .; \
26439 + *(.rodata) *(.rodata.*) \
26440 ++ *(.data.read_only) \
26441 + *(__vermagic) /* Kernel version magic */ \
26442 + *(__markers_strings) /* Markers: strings */ \
26443 + } \
26444 +diff -urNp linux-2.6.27.10/include/asm-m32r/kmap_types.h linux-2.6.27.10/include/asm-m32r/kmap_types.h
26445 +--- linux-2.6.27.10/include/asm-m32r/kmap_types.h 2008-11-07 12:55:34.000000000 -0500
26446 ++++ linux-2.6.27.10/include/asm-m32r/kmap_types.h 2008-11-18 03:38:45.000000000 -0500
26447 +@@ -21,7 +21,8 @@ D(9) KM_IRQ0,
26448 + D(10) KM_IRQ1,
26449 + D(11) KM_SOFTIRQ0,
26450 + D(12) KM_SOFTIRQ1,
26451 +-D(13) KM_TYPE_NR
26452 ++D(13) KM_CLEARPAGE,
26453 ++D(14) KM_TYPE_NR
26454 + };
26455 +
26456 + #undef D
26457 +diff -urNp linux-2.6.27.10/include/asm-m68k/kmap_types.h linux-2.6.27.10/include/asm-m68k/kmap_types.h
26458 +--- linux-2.6.27.10/include/asm-m68k/kmap_types.h 2008-11-07 12:55:34.000000000 -0500
26459 ++++ linux-2.6.27.10/include/asm-m68k/kmap_types.h 2008-11-18 03:38:45.000000000 -0500
26460 +@@ -15,6 +15,7 @@ enum km_type {
26461 + KM_IRQ1,
26462 + KM_SOFTIRQ0,
26463 + KM_SOFTIRQ1,
26464 ++ KM_CLEARPAGE,
26465 + KM_TYPE_NR
26466 + };
26467 +
26468 +diff -urNp linux-2.6.27.10/include/asm-mips/elf.h linux-2.6.27.10/include/asm-mips/elf.h
26469 +--- linux-2.6.27.10/include/asm-mips/elf.h 2008-11-07 12:55:34.000000000 -0500
26470 ++++ linux-2.6.27.10/include/asm-mips/elf.h 2008-11-18 03:38:45.000000000 -0500
26471 +@@ -368,4 +368,11 @@ extern int dump_task_fpu(struct task_str
26472 + #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
26473 + #endif
26474 +
26475 ++#ifdef CONFIG_PAX_ASLR
26476 ++#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT_ADDR) ? 0x00400000UL : 0x00400000UL)
26477 ++
26478 ++#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT_ADDR) ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
26479 ++#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT_ADDR) ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
26480 ++#endif
26481 ++
26482 + #endif /* _ASM_ELF_H */
26483 +diff -urNp linux-2.6.27.10/include/asm-mips/kmap_types.h linux-2.6.27.10/include/asm-mips/kmap_types.h
26484 +--- linux-2.6.27.10/include/asm-mips/kmap_types.h 2008-11-07 12:55:34.000000000 -0500
26485 ++++ linux-2.6.27.10/include/asm-mips/kmap_types.h 2008-11-18 03:38:45.000000000 -0500
26486 +@@ -22,7 +22,8 @@ D(9) KM_IRQ0,
26487 + D(10) KM_IRQ1,
26488 + D(11) KM_SOFTIRQ0,
26489 + D(12) KM_SOFTIRQ1,
26490 +-D(13) KM_TYPE_NR
26491 ++D(13) KM_CLEARPAGE,
26492 ++D(14) KM_TYPE_NR
26493 + };
26494 +
26495 + #undef D
26496 +diff -urNp linux-2.6.27.10/include/asm-mips/page.h linux-2.6.27.10/include/asm-mips/page.h
26497 +--- linux-2.6.27.10/include/asm-mips/page.h 2008-11-07 12:55:34.000000000 -0500
26498 ++++ linux-2.6.27.10/include/asm-mips/page.h 2008-11-18 03:38:45.000000000 -0500
26499 +@@ -82,7 +82,7 @@ extern void copy_user_highpage(struct pa
26500 + #ifdef CONFIG_CPU_MIPS32
26501 + typedef struct { unsigned long pte_low, pte_high; } pte_t;
26502 + #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
26503 +- #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
26504 ++ #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
26505 + #else
26506 + typedef struct { unsigned long long pte; } pte_t;
26507 + #define pte_val(x) ((x).pte)
26508 +diff -urNp linux-2.6.27.10/include/asm-mips/system.h linux-2.6.27.10/include/asm-mips/system.h
26509 +--- linux-2.6.27.10/include/asm-mips/system.h 2008-11-07 12:55:34.000000000 -0500
26510 ++++ linux-2.6.27.10/include/asm-mips/system.h 2008-11-18 03:38:45.000000000 -0500
26511 +@@ -215,6 +215,6 @@ extern void per_cpu_trap_init(void);
26512 + */
26513 + #define __ARCH_WANT_UNLOCKED_CTXSW
26514 +
26515 +-extern unsigned long arch_align_stack(unsigned long sp);
26516 ++#define arch_align_stack(x) ((x) & ALMASK)
26517 +
26518 + #endif /* _ASM_SYSTEM_H */
26519 +diff -urNp linux-2.6.27.10/include/asm-mn10300/kmap_types.h linux-2.6.27.10/include/asm-mn10300/kmap_types.h
26520 +--- linux-2.6.27.10/include/asm-mn10300/kmap_types.h 2008-11-07 12:55:34.000000000 -0500
26521 ++++ linux-2.6.27.10/include/asm-mn10300/kmap_types.h 2008-11-18 03:39:50.000000000 -0500
26522 +@@ -25,6 +25,7 @@ enum km_type {
26523 + KM_IRQ1,
26524 + KM_SOFTIRQ0,
26525 + KM_SOFTIRQ1,
26526 ++ KM_CLEARPAGE,
26527 + KM_TYPE_NR
26528 + };
26529 +
26530 +diff -urNp linux-2.6.27.10/include/asm-parisc/elf.h linux-2.6.27.10/include/asm-parisc/elf.h
26531 +--- linux-2.6.27.10/include/asm-parisc/elf.h 2008-11-07 12:55:34.000000000 -0500
26532 ++++ linux-2.6.27.10/include/asm-parisc/elf.h 2008-11-18 03:38:45.000000000 -0500
26533 +@@ -333,6 +333,13 @@ struct pt_regs; /* forward declaration..
26534 +
26535 + #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
26536 +
26537 ++#ifdef CONFIG_PAX_ASLR
26538 ++#define PAX_ELF_ET_DYN_BASE 0x10000UL
26539 ++
26540 ++#define PAX_DELTA_MMAP_LEN 16
26541 ++#define PAX_DELTA_STACK_LEN 16
26542 ++#endif
26543 ++
26544 + /* This yields a mask that user programs can use to figure out what
26545 + instruction set this CPU supports. This could be done in user space,
26546 + but it's not easy, and we've already done it here. */
26547 +diff -urNp linux-2.6.27.10/include/asm-parisc/kmap_types.h linux-2.6.27.10/include/asm-parisc/kmap_types.h
26548 +--- linux-2.6.27.10/include/asm-parisc/kmap_types.h 2008-11-07 12:55:34.000000000 -0500
26549 ++++ linux-2.6.27.10/include/asm-parisc/kmap_types.h 2008-11-18 03:38:45.000000000 -0500
26550 +@@ -22,7 +22,8 @@ D(9) KM_IRQ0,
26551 + D(10) KM_IRQ1,
26552 + D(11) KM_SOFTIRQ0,
26553 + D(12) KM_SOFTIRQ1,
26554 +-D(13) KM_TYPE_NR
26555 ++D(13) KM_CLEARPAGE,
26556 ++D(14) KM_TYPE_NR
26557 + };
26558 +
26559 + #undef D
26560 +diff -urNp linux-2.6.27.10/include/asm-parisc/pgtable.h linux-2.6.27.10/include/asm-parisc/pgtable.h
26561 +--- linux-2.6.27.10/include/asm-parisc/pgtable.h 2008-11-07 12:55:34.000000000 -0500
26562 ++++ linux-2.6.27.10/include/asm-parisc/pgtable.h 2008-11-18 03:38:45.000000000 -0500
26563 +@@ -202,6 +202,17 @@
26564 + #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
26565 + #define PAGE_COPY PAGE_EXECREAD
26566 + #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
26567 ++
26568 ++#ifdef CONFIG_PAX_PAGEEXEC
26569 ++# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
26570 ++# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
26571 ++# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
26572 ++#else
26573 ++# define PAGE_SHARED_NOEXEC PAGE_SHARED
26574 ++# define PAGE_COPY_NOEXEC PAGE_COPY
26575 ++# define PAGE_READONLY_NOEXEC PAGE_READONLY
26576 ++#endif
26577 ++
26578 + #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
26579 + #define PAGE_KERNEL_RO __pgprot(_PAGE_KERNEL & ~_PAGE_WRITE)
26580 + #define PAGE_KERNEL_UNC __pgprot(_PAGE_KERNEL | _PAGE_NO_CACHE)
26581 +diff -urNp linux-2.6.27.10/include/asm-um/kmap_types.h linux-2.6.27.10/include/asm-um/kmap_types.h
26582 +--- linux-2.6.27.10/include/asm-um/kmap_types.h 2008-11-07 12:55:34.000000000 -0500
26583 ++++ linux-2.6.27.10/include/asm-um/kmap_types.h 2008-11-18 03:38:45.000000000 -0500
26584 +@@ -23,6 +23,7 @@ enum km_type {
26585 + KM_IRQ1,
26586 + KM_SOFTIRQ0,
26587 + KM_SOFTIRQ1,
26588 ++ KM_CLEARPAGE,
26589 + KM_TYPE_NR
26590 + };
26591 +
26592 +diff -urNp linux-2.6.27.10/include/asm-um/page.h linux-2.6.27.10/include/asm-um/page.h
26593 +--- linux-2.6.27.10/include/asm-um/page.h 2008-11-07 12:55:34.000000000 -0500
26594 ++++ linux-2.6.27.10/include/asm-um/page.h 2008-11-18 03:38:45.000000000 -0500
26595 +@@ -14,6 +14,9 @@
26596 + #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
26597 + #define PAGE_MASK (~(PAGE_SIZE-1))
26598 +
26599 ++#define ktla_ktva(addr) (addr)
26600 ++#define ktva_ktla(addr) (addr)
26601 ++
26602 + #ifndef __ASSEMBLY__
26603 +
26604 + struct page;
26605 +diff -urNp linux-2.6.27.10/include/asm-x86/alternative.h linux-2.6.27.10/include/asm-x86/alternative.h
26606 +--- linux-2.6.27.10/include/asm-x86/alternative.h 2008-11-07 12:55:34.000000000 -0500
26607 ++++ linux-2.6.27.10/include/asm-x86/alternative.h 2008-11-18 03:38:45.000000000 -0500
26608 +@@ -96,7 +96,7 @@ const unsigned char *const *find_nop_tab
26609 + " .byte 662b-661b\n" /* sourcelen */ \
26610 + " .byte 664f-663f\n" /* replacementlen */ \
26611 + ".previous\n" \
26612 +- ".section .altinstr_replacement,\"ax\"\n" \
26613 ++ ".section .altinstr_replacement,\"a\"\n" \
26614 + "663:\n\t" newinstr "\n664:\n" /* replacement */ \
26615 + ".previous" :: "i" (feature) : "memory")
26616 +
26617 +@@ -120,7 +120,7 @@ const unsigned char *const *find_nop_tab
26618 + " .byte 662b-661b\n" /* sourcelen */ \
26619 + " .byte 664f-663f\n" /* replacementlen */ \
26620 + ".previous\n" \
26621 +- ".section .altinstr_replacement,\"ax\"\n" \
26622 ++ ".section .altinstr_replacement,\"a\"\n" \
26623 + "663:\n\t" newinstr "\n664:\n" /* replacement */ \
26624 + ".previous" :: "i" (feature), ##input)
26625 +
26626 +@@ -135,7 +135,7 @@ const unsigned char *const *find_nop_tab
26627 + " .byte 662b-661b\n" /* sourcelen */ \
26628 + " .byte 664f-663f\n" /* replacementlen */ \
26629 + ".previous\n" \
26630 +- ".section .altinstr_replacement,\"ax\"\n" \
26631 ++ ".section .altinstr_replacement,\"a\"\n" \
26632 + "663:\n\t" newinstr "\n664:\n" /* replacement */ \
26633 + ".previous" : output : [feat] "i" (feature), ##input)
26634 +
26635 +diff -urNp linux-2.6.27.10/include/asm-x86/atomic_32.h linux-2.6.27.10/include/asm-x86/atomic_32.h
26636 +--- linux-2.6.27.10/include/asm-x86/atomic_32.h 2008-11-07 12:55:34.000000000 -0500
26637 ++++ linux-2.6.27.10/include/asm-x86/atomic_32.h 2008-11-18 03:38:45.000000000 -0500
26638 +@@ -47,7 +47,15 @@ typedef struct {
26639 + */
26640 + static inline void atomic_add(int i, atomic_t *v)
26641 + {
26642 +- asm volatile(LOCK_PREFIX "addl %1,%0"
26643 ++ asm volatile(LOCK_PREFIX "addl %1,%0\n"
26644 ++
26645 ++#ifdef CONFIG_PAX_REFCOUNT
26646 ++ "jno 0f\n"
26647 ++ LOCK_PREFIX "subl %1,%0\n"
26648 ++ "into\n0:\n"
26649 ++ _ASM_EXTABLE(0b, 0b)
26650 ++#endif
26651 ++
26652 + : "+m" (v->counter)
26653 + : "ir" (i));
26654 + }
26655 +@@ -61,7 +69,15 @@ static inline void atomic_add(int i, ato
26656 + */
26657 + static inline void atomic_sub(int i, atomic_t *v)
26658 + {
26659 +- asm volatile(LOCK_PREFIX "subl %1,%0"
26660 ++ asm volatile(LOCK_PREFIX "subl %1,%0\n"
26661 ++
26662 ++#ifdef CONFIG_PAX_REFCOUNT
26663 ++ "jno 0f\n"
26664 ++ LOCK_PREFIX "addl %1,%0\n"
26665 ++ "into\n0:\n"
26666 ++ _ASM_EXTABLE(0b, 0b)
26667 ++#endif
26668 ++
26669 + : "+m" (v->counter)
26670 + : "ir" (i));
26671 + }
26672 +@@ -79,7 +95,16 @@ static inline int atomic_sub_and_test(in
26673 + {
26674 + unsigned char c;
26675 +
26676 +- asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
26677 ++ asm volatile(LOCK_PREFIX "subl %2,%0\n"
26678 ++
26679 ++#ifdef CONFIG_PAX_REFCOUNT
26680 ++ "jno 0f\n"
26681 ++ LOCK_PREFIX "addl %2,%0\n"
26682 ++ "into\n0:\n"
26683 ++ _ASM_EXTABLE(0b, 0b)
26684 ++#endif
26685 ++
26686 ++ "sete %1\n"
26687 + : "+m" (v->counter), "=qm" (c)
26688 + : "ir" (i) : "memory");
26689 + return c;
26690 +@@ -93,7 +118,18 @@ static inline int atomic_sub_and_test(in
26691 + */
26692 + static inline void atomic_inc(atomic_t *v)
26693 + {
26694 +- asm volatile(LOCK_PREFIX "incl %0"
26695 ++ asm volatile(LOCK_PREFIX "incl %0\n"
26696 ++
26697 ++#ifdef CONFIG_PAX_REFCOUNT
26698 ++ "into\n0:\n"
26699 ++ ".pushsection .fixup,\"ax\"\n"
26700 ++ "1:\n"
26701 ++ LOCK_PREFIX "decl %0\n"
26702 ++ "jmp 0b\n"
26703 ++ ".popsection\n"
26704 ++ _ASM_EXTABLE(0b, 1b)
26705 ++#endif
26706 ++
26707 + : "+m" (v->counter));
26708 + }
26709 +
26710 +@@ -105,7 +141,18 @@ static inline void atomic_inc(atomic_t *
26711 + */
26712 + static inline void atomic_dec(atomic_t *v)
26713 + {
26714 +- asm volatile(LOCK_PREFIX "decl %0"
26715 ++ asm volatile(LOCK_PREFIX "decl %0\n"
26716 ++
26717 ++#ifdef CONFIG_PAX_REFCOUNT
26718 ++ "into\n0:\n"
26719 ++ ".pushsection .fixup,\"ax\"\n"
26720 ++ "1: \n"
26721 ++ LOCK_PREFIX "incl %0\n"
26722 ++ "jmp 0b\n"
26723 ++ ".popsection\n"
26724 ++ _ASM_EXTABLE(0b, 1b)
26725 ++#endif
26726 ++
26727 + : "+m" (v->counter));
26728 + }
26729 +
26730 +@@ -121,7 +168,19 @@ static inline int atomic_dec_and_test(at
26731 + {
26732 + unsigned char c;
26733 +
26734 +- asm volatile(LOCK_PREFIX "decl %0; sete %1"
26735 ++ asm volatile(LOCK_PREFIX "decl %0\n"
26736 ++
26737 ++#ifdef CONFIG_PAX_REFCOUNT
26738 ++ "into\n0:\n"
26739 ++ ".pushsection .fixup,\"ax\"\n"
26740 ++ "1: \n"
26741 ++ LOCK_PREFIX "incl %0\n"
26742 ++ "jmp 0b\n"
26743 ++ ".popsection\n"
26744 ++ _ASM_EXTABLE(0b, 1b)
26745 ++#endif
26746 ++
26747 ++ "sete %1\n"
26748 + : "+m" (v->counter), "=qm" (c)
26749 + : : "memory");
26750 + return c != 0;
26751 +@@ -139,7 +198,19 @@ static inline int atomic_inc_and_test(at
26752 + {
26753 + unsigned char c;
26754 +
26755 +- asm volatile(LOCK_PREFIX "incl %0; sete %1"
26756 ++ asm volatile(LOCK_PREFIX "incl %0\n"
26757 ++
26758 ++#ifdef CONFIG_PAX_REFCOUNT
26759 ++ "into\n0:\n"
26760 ++ ".pushsection .fixup,\"ax\"\n"
26761 ++ "1: \n"
26762 ++ LOCK_PREFIX "decl %0\n"
26763 ++ "jmp 0b\n"
26764 ++ ".popsection\n"
26765 ++ _ASM_EXTABLE(0b, 1b)
26766 ++#endif
26767 ++
26768 ++ "sete %1\n"
26769 + : "+m" (v->counter), "=qm" (c)
26770 + : : "memory");
26771 + return c != 0;
26772 +@@ -158,7 +229,16 @@ static inline int atomic_add_negative(in
26773 + {
26774 + unsigned char c;
26775 +
26776 +- asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
26777 ++ asm volatile(LOCK_PREFIX "addl %2,%0\n"
26778 ++
26779 ++#ifdef CONFIG_PAX_REFCOUNT
26780 ++ "jno 0f\n"
26781 ++ LOCK_PREFIX "subl %2,%0\n"
26782 ++ "into\n0:\n"
26783 ++ _ASM_EXTABLE(0b, 0b)
26784 ++#endif
26785 ++
26786 ++ "sets %1\n"
26787 + : "+m" (v->counter), "=qm" (c)
26788 + : "ir" (i) : "memory");
26789 + return c;
26790 +@@ -181,7 +261,15 @@ static inline int atomic_add_return(int
26791 + #endif
26792 + /* Modern 486+ processor */
26793 + __i = i;
26794 +- asm volatile(LOCK_PREFIX "xaddl %0, %1"
26795 ++ asm volatile(LOCK_PREFIX "xaddl %0, %1\n"
26796 ++
26797 ++#ifdef CONFIG_PAX_REFCOUNT
26798 ++ "jno 0f\n"
26799 ++ "movl %0, %1\n"
26800 ++ "into\n0:\n"
26801 ++ _ASM_EXTABLE(0b, 0b)
26802 ++#endif
26803 ++
26804 + : "+r" (i), "+m" (v->counter)
26805 + : : "memory");
26806 + return i + __i;
26807 +diff -urNp linux-2.6.27.10/include/asm-x86/atomic_64.h linux-2.6.27.10/include/asm-x86/atomic_64.h
26808 +--- linux-2.6.27.10/include/asm-x86/atomic_64.h 2008-11-07 12:55:34.000000000 -0500
26809 ++++ linux-2.6.27.10/include/asm-x86/atomic_64.h 2008-11-18 03:38:45.000000000 -0500
26810 +@@ -48,7 +48,15 @@ typedef struct {
26811 + */
26812 + static inline void atomic_add(int i, atomic_t *v)
26813 + {
26814 +- asm volatile(LOCK_PREFIX "addl %1,%0"
26815 ++ asm volatile(LOCK_PREFIX "addl %1,%0\n"
26816 ++
26817 ++#ifdef CONFIG_PAX_REFCOUNT
26818 ++ "jno 0f\n"
26819 ++ LOCK_PREFIX "subl %1,%0\n"
26820 ++ "int $4\n0:\n"
26821 ++ _ASM_EXTABLE(0b, 0b)
26822 ++#endif
26823 ++
26824 + : "=m" (v->counter)
26825 + : "ir" (i), "m" (v->counter));
26826 + }
26827 +@@ -62,7 +70,15 @@ static inline void atomic_add(int i, ato
26828 + */
26829 + static inline void atomic_sub(int i, atomic_t *v)
26830 + {
26831 +- asm volatile(LOCK_PREFIX "subl %1,%0"
26832 ++ asm volatile(LOCK_PREFIX "subl %1,%0\n"
26833 ++
26834 ++#ifdef CONFIG_PAX_REFCOUNT
26835 ++ "jno 0f\n"
26836 ++ LOCK_PREFIX "addl %1,%0\n"
26837 ++ "int $4\n0:\n"
26838 ++ _ASM_EXTABLE(0b, 0b)
26839 ++#endif
26840 ++
26841 + : "=m" (v->counter)
26842 + : "ir" (i), "m" (v->counter));
26843 + }
26844 +@@ -80,7 +96,16 @@ static inline int atomic_sub_and_test(in
26845 + {
26846 + unsigned char c;
26847 +
26848 +- asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
26849 ++ asm volatile(LOCK_PREFIX "subl %2,%0\n"
26850 ++
26851 ++#ifdef CONFIG_PAX_REFCOUNT
26852 ++ "jno 0f\n"
26853 ++ LOCK_PREFIX "addl %2,%0\n"
26854 ++ "int $4\n0:\n"
26855 ++ _ASM_EXTABLE(0b, 0b)
26856 ++#endif
26857 ++
26858 ++ "sete %1\n"
26859 + : "=m" (v->counter), "=qm" (c)
26860 + : "ir" (i), "m" (v->counter) : "memory");
26861 + return c;
26862 +@@ -94,7 +119,19 @@ static inline int atomic_sub_and_test(in
26863 + */
26864 + static inline void atomic_inc(atomic_t *v)
26865 + {
26866 +- asm volatile(LOCK_PREFIX "incl %0"
26867 ++ asm volatile(LOCK_PREFIX "incl %0\n"
26868 ++
26869 ++#ifdef CONFIG_PAX_REFCOUNT
26870 ++ "jno 0f\n"
26871 ++ "int $4\n0:\n"
26872 ++ ".pushsection .fixup,\"ax\"\n"
26873 ++ "1:\n"
26874 ++ LOCK_PREFIX "decl %0\n"
26875 ++ "jmp 0b\n"
26876 ++ ".popsection\n"
26877 ++ _ASM_EXTABLE(0b, 1b)
26878 ++#endif
26879 ++
26880 + : "=m" (v->counter)
26881 + : "m" (v->counter));
26882 + }
26883 +@@ -107,7 +144,19 @@ static inline void atomic_inc(atomic_t *
26884 + */
26885 + static inline void atomic_dec(atomic_t *v)
26886 + {
26887 +- asm volatile(LOCK_PREFIX "decl %0"
26888 ++ asm volatile(LOCK_PREFIX "decl %0\n"
26889 ++
26890 ++#ifdef CONFIG_PAX_REFCOUNT
26891 ++ "jno 0f\n"
26892 ++ "int $4\n0:\n"
26893 ++ ".pushsection .fixup,\"ax\"\n"
26894 ++ "1: \n"
26895 ++ LOCK_PREFIX "incl %0\n"
26896 ++ "jmp 0b\n"
26897 ++ ".popsection\n"
26898 ++ _ASM_EXTABLE(0b, 1b)
26899 ++#endif
26900 ++
26901 + : "=m" (v->counter)
26902 + : "m" (v->counter));
26903 + }
26904 +@@ -124,7 +173,20 @@ static inline int atomic_dec_and_test(at
26905 + {
26906 + unsigned char c;
26907 +
26908 +- asm volatile(LOCK_PREFIX "decl %0; sete %1"
26909 ++ asm volatile(LOCK_PREFIX "decl %0\n"
26910 ++
26911 ++#ifdef CONFIG_PAX_REFCOUNT
26912 ++ "jno 0f\n"
26913 ++ "int $4\n0:\n"
26914 ++ ".pushsection .fixup,\"ax\"\n"
26915 ++ "1: \n"
26916 ++ LOCK_PREFIX "incl %0\n"
26917 ++ "jmp 0b\n"
26918 ++ ".popsection\n"
26919 ++ _ASM_EXTABLE(0b, 1b)
26920 ++#endif
26921 ++
26922 ++ "sete %1\n"
26923 + : "=m" (v->counter), "=qm" (c)
26924 + : "m" (v->counter) : "memory");
26925 + return c != 0;
26926 +@@ -142,7 +204,20 @@ static inline int atomic_inc_and_test(at
26927 + {
26928 + unsigned char c;
26929 +
26930 +- asm volatile(LOCK_PREFIX "incl %0; sete %1"
26931 ++ asm volatile(LOCK_PREFIX "incl %0\n"
26932 ++
26933 ++#ifdef CONFIG_PAX_REFCOUNT
26934 ++ "jno 0f\n"
26935 ++ "int $4\n0:\n"
26936 ++ ".pushsection .fixup,\"ax\"\n"
26937 ++ "1: \n"
26938 ++ LOCK_PREFIX "decl %0\n"
26939 ++ "jmp 0b\n"
26940 ++ ".popsection\n"
26941 ++ _ASM_EXTABLE(0b, 1b)
26942 ++#endif
26943 ++
26944 ++ "sete %1\n"
26945 + : "=m" (v->counter), "=qm" (c)
26946 + : "m" (v->counter) : "memory");
26947 + return c != 0;
26948 +@@ -161,7 +236,16 @@ static inline int atomic_add_negative(in
26949 + {
26950 + unsigned char c;
26951 +
26952 +- asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
26953 ++ asm volatile(LOCK_PREFIX "addl %2,%0\n"
26954 ++
26955 ++#ifdef CONFIG_PAX_REFCOUNT
26956 ++ "jno 0f\n"
26957 ++ LOCK_PREFIX "subl %2,%0\n"
26958 ++ "int $4\n0:\n"
26959 ++ _ASM_EXTABLE(0b, 0b)
26960 ++#endif
26961 ++
26962 ++ "sets %1\n"
26963 + : "=m" (v->counter), "=qm" (c)
26964 + : "ir" (i), "m" (v->counter) : "memory");
26965 + return c;
26966 +@@ -177,7 +261,15 @@ static inline int atomic_add_negative(in
26967 + static inline int atomic_add_return(int i, atomic_t *v)
26968 + {
26969 + int __i = i;
26970 +- asm volatile(LOCK_PREFIX "xaddl %0, %1"
26971 ++ asm volatile(LOCK_PREFIX "xaddl %0, %1\n"
26972 ++
26973 ++#ifdef CONFIG_PAX_REFCOUNT
26974 ++ "jno 0f\n"
26975 ++ "movl %0, %1\n"
26976 ++ "int $4\n0:\n"
26977 ++ _ASM_EXTABLE(0b, 0b)
26978 ++#endif
26979 ++
26980 + : "+r" (i), "+m" (v->counter)
26981 + : : "memory");
26982 + return i + __i;
26983 +@@ -226,7 +318,15 @@ typedef struct {
26984 + */
26985 + static inline void atomic64_add(long i, atomic64_t *v)
26986 + {
26987 +- asm volatile(LOCK_PREFIX "addq %1,%0"
26988 ++ asm volatile(LOCK_PREFIX "addq %1,%0\n"
26989 ++
26990 ++#ifdef CONFIG_PAX_REFCOUNT
26991 ++ "jno 0f\n"
26992 ++ LOCK_PREFIX "subq %1,%0\n"
26993 ++ "int $4\n0:\n"
26994 ++ _ASM_EXTABLE(0b, 0b)
26995 ++#endif
26996 ++
26997 + : "=m" (v->counter)
26998 + : "er" (i), "m" (v->counter));
26999 + }
27000 +@@ -240,7 +340,15 @@ static inline void atomic64_add(long i,
27001 + */
27002 + static inline void atomic64_sub(long i, atomic64_t *v)
27003 + {
27004 +- asm volatile(LOCK_PREFIX "subq %1,%0"
27005 ++ asm volatile(LOCK_PREFIX "subq %1,%0\n"
27006 ++
27007 ++#ifdef CONFIG_PAX_REFCOUNT
27008 ++ "jno 0f\n"
27009 ++ LOCK_PREFIX "addq %1,%0\n"
27010 ++ "int $4\n0:\n"
27011 ++ _ASM_EXTABLE(0b, 0b)
27012 ++#endif
27013 ++
27014 + : "=m" (v->counter)
27015 + : "er" (i), "m" (v->counter));
27016 + }
27017 +@@ -258,7 +366,16 @@ static inline int atomic64_sub_and_test(
27018 + {
27019 + unsigned char c;
27020 +
27021 +- asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
27022 ++ asm volatile(LOCK_PREFIX "subq %2,%0\n"
27023 ++
27024 ++#ifdef CONFIG_PAX_REFCOUNT
27025 ++ "jno 0f\n"
27026 ++ LOCK_PREFIX "addq %2,%0\n"
27027 ++ "int $4\n0:\n"
27028 ++ _ASM_EXTABLE(0b, 0b)
27029 ++#endif
27030 ++
27031 ++ "sete %1\n"
27032 + : "=m" (v->counter), "=qm" (c)
27033 + : "er" (i), "m" (v->counter) : "memory");
27034 + return c;
27035 +@@ -272,7 +389,19 @@ static inline int atomic64_sub_and_test(
27036 + */
27037 + static inline void atomic64_inc(atomic64_t *v)
27038 + {
27039 +- asm volatile(LOCK_PREFIX "incq %0"
27040 ++ asm volatile(LOCK_PREFIX "incq %0\n"
27041 ++
27042 ++#ifdef CONFIG_PAX_REFCOUNT
27043 ++ "jno 0f\n"
27044 ++ "int $4\n0:\n"
27045 ++ ".pushsection .fixup,\"ax\"\n"
27046 ++ "1:\n"
27047 ++ LOCK_PREFIX "decq %0\n"
27048 ++ "jmp 0b\n"
27049 ++ ".popsection\n"
27050 ++ _ASM_EXTABLE(0b, 1b)
27051 ++#endif
27052 ++
27053 + : "=m" (v->counter)
27054 + : "m" (v->counter));
27055 + }
27056 +@@ -285,7 +414,19 @@ static inline void atomic64_inc(atomic64
27057 + */
27058 + static inline void atomic64_dec(atomic64_t *v)
27059 + {
27060 +- asm volatile(LOCK_PREFIX "decq %0"
27061 ++ asm volatile(LOCK_PREFIX "decq %0\n"
27062 ++
27063 ++#ifdef CONFIG_PAX_REFCOUNT
27064 ++ "jno 0f\n"
27065 ++ "int $4\n0:\n"
27066 ++ ".pushsection .fixup,\"ax\"\n"
27067 ++ "1: \n"
27068 ++ LOCK_PREFIX "incq %0\n"
27069 ++ "jmp 0b\n"
27070 ++ ".popsection\n"
27071 ++ _ASM_EXTABLE(0b, 1b)
27072 ++#endif
27073 ++
27074 + : "=m" (v->counter)
27075 + : "m" (v->counter));
27076 + }
27077 +@@ -302,7 +443,20 @@ static inline int atomic64_dec_and_test(
27078 + {
27079 + unsigned char c;
27080 +
27081 +- asm volatile(LOCK_PREFIX "decq %0; sete %1"
27082 ++ asm volatile(LOCK_PREFIX "decq %0\n"
27083 ++
27084 ++#ifdef CONFIG_PAX_REFCOUNT
27085 ++ "jno 0f\n"
27086 ++ "int $4\n0:\n"
27087 ++ ".pushsection .fixup,\"ax\"\n"
27088 ++ "1: \n"
27089 ++ LOCK_PREFIX "incq %0\n"
27090 ++ "jmp 0b\n"
27091 ++ ".popsection\n"
27092 ++ _ASM_EXTABLE(0b, 1b)
27093 ++#endif
27094 ++
27095 ++ "sete %1\n"
27096 + : "=m" (v->counter), "=qm" (c)
27097 + : "m" (v->counter) : "memory");
27098 + return c != 0;
27099 +@@ -320,7 +474,20 @@ static inline int atomic64_inc_and_test(
27100 + {
27101 + unsigned char c;
27102 +
27103 +- asm volatile(LOCK_PREFIX "incq %0; sete %1"
27104 ++ asm volatile(LOCK_PREFIX "incq %0\n"
27105 ++
27106 ++#ifdef CONFIG_PAX_REFCOUNT
27107 ++ "jno 0f\n"
27108 ++ "int $4\n0:\n"
27109 ++ ".pushsection .fixup,\"ax\"\n"
27110 ++ "1: \n"
27111 ++ LOCK_PREFIX "decq %0\n"
27112 ++ "jmp 0b\n"
27113 ++ ".popsection\n"
27114 ++ _ASM_EXTABLE(0b, 1b)
27115 ++#endif
27116 ++
27117 ++ "sete %1\n"
27118 + : "=m" (v->counter), "=qm" (c)
27119 + : "m" (v->counter) : "memory");
27120 + return c != 0;
27121 +@@ -339,7 +506,16 @@ static inline int atomic64_add_negative(
27122 + {
27123 + unsigned char c;
27124 +
27125 +- asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
27126 ++ asm volatile(LOCK_PREFIX "addq %2,%0\n"
27127 ++
27128 ++#ifdef CONFIG_PAX_REFCOUNT
27129 ++ "jno 0f\n"
27130 ++ LOCK_PREFIX "subq %2,%0\n"
27131 ++ "int $4\n0:\n"
27132 ++ _ASM_EXTABLE(0b, 0b)
27133 ++#endif
27134 ++
27135 ++ "sets %1\n"
27136 + : "=m" (v->counter), "=qm" (c)
27137 + : "er" (i), "m" (v->counter) : "memory");
27138 + return c;
27139 +@@ -355,7 +531,15 @@ static inline int atomic64_add_negative(
27140 + static inline long atomic64_add_return(long i, atomic64_t *v)
27141 + {
27142 + long __i = i;
27143 +- asm volatile(LOCK_PREFIX "xaddq %0, %1;"
27144 ++ asm volatile(LOCK_PREFIX "xaddq %0, %1\n"
27145 ++
27146 ++#ifdef CONFIG_PAX_REFCOUNT
27147 ++ "jno 0f\n"
27148 ++ "movq %0, %1\n"
27149 ++ "int $4\n0:\n"
27150 ++ _ASM_EXTABLE(0b, 0b)
27151 ++#endif
27152 ++
27153 + : "+r" (i), "+m" (v->counter)
27154 + : : "memory");
27155 + return i + __i;
27156 +diff -urNp linux-2.6.27.10/include/asm-x86/boot.h linux-2.6.27.10/include/asm-x86/boot.h
27157 +--- linux-2.6.27.10/include/asm-x86/boot.h 2008-11-07 12:55:34.000000000 -0500
27158 ++++ linux-2.6.27.10/include/asm-x86/boot.h 2008-11-18 03:38:45.000000000 -0500
27159 +@@ -13,10 +13,15 @@
27160 + #define ASK_VGA 0xfffd /* ask for it at bootup */
27161 +
27162 + /* Physical address where kernel should be loaded. */
27163 +-#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
27164 ++#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
27165 + + (CONFIG_PHYSICAL_ALIGN - 1)) \
27166 + & ~(CONFIG_PHYSICAL_ALIGN - 1))
27167 +
27168 ++#ifndef __ASSEMBLY__
27169 ++extern unsigned char __LOAD_PHYSICAL_ADDR[];
27170 ++#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
27171 ++#endif
27172 ++
27173 + #ifdef CONFIG_X86_64
27174 + #define BOOT_HEAP_SIZE 0x7000
27175 + #define BOOT_STACK_SIZE 0x4000
27176 +diff -urNp linux-2.6.27.10/include/asm-x86/cache.h linux-2.6.27.10/include/asm-x86/cache.h
27177 +--- linux-2.6.27.10/include/asm-x86/cache.h 2008-11-07 12:55:34.000000000 -0500
27178 ++++ linux-2.6.27.10/include/asm-x86/cache.h 2008-11-18 03:38:45.000000000 -0500
27179 +@@ -6,6 +6,7 @@
27180 + #define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
27181 +
27182 + #define __read_mostly __attribute__((__section__(".data.read_mostly")))
27183 ++#define __read_only __attribute__((__section__(".data.read_only")))
27184 +
27185 + #ifdef CONFIG_X86_VSMP
27186 + /* vSMP Internode cacheline shift */
27187 +diff -urNp linux-2.6.27.10/include/asm-x86/checksum_32.h linux-2.6.27.10/include/asm-x86/checksum_32.h
27188 +--- linux-2.6.27.10/include/asm-x86/checksum_32.h 2008-11-07 12:55:34.000000000 -0500
27189 ++++ linux-2.6.27.10/include/asm-x86/checksum_32.h 2008-11-18 03:38:45.000000000 -0500
27190 +@@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_gene
27191 + int len, __wsum sum,
27192 + int *src_err_ptr, int *dst_err_ptr);
27193 +
27194 ++asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
27195 ++ int len, __wsum sum,
27196 ++ int *src_err_ptr, int *dst_err_ptr);
27197 ++
27198 ++asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
27199 ++ int len, __wsum sum,
27200 ++ int *src_err_ptr, int *dst_err_ptr);
27201 ++
27202 + /*
27203 + * Note: when you get a NULL pointer exception here this means someone
27204 + * passed in an incorrect kernel address to one of these functions.
27205 +@@ -50,7 +58,7 @@ static inline __wsum csum_partial_copy_f
27206 + int *err_ptr)
27207 + {
27208 + might_sleep();
27209 +- return csum_partial_copy_generic((__force void *)src, dst,
27210 ++ return csum_partial_copy_generic_from_user((__force void *)src, dst,
27211 + len, sum, err_ptr, NULL);
27212 + }
27213 +
27214 +@@ -177,7 +185,7 @@ static inline __wsum csum_and_copy_to_us
27215 + {
27216 + might_sleep();
27217 + if (access_ok(VERIFY_WRITE, dst, len))
27218 +- return csum_partial_copy_generic(src, (__force void *)dst,
27219 ++ return csum_partial_copy_generic_to_user(src, (__force void *)dst,
27220 + len, sum, NULL, err_ptr);
27221 +
27222 + if (len)
27223 +diff -urNp linux-2.6.27.10/include/asm-x86/desc.h linux-2.6.27.10/include/asm-x86/desc.h
27224 +--- linux-2.6.27.10/include/asm-x86/desc.h 2008-11-07 12:55:34.000000000 -0500
27225 ++++ linux-2.6.27.10/include/asm-x86/desc.h 2008-11-18 03:38:45.000000000 -0500
27226 +@@ -16,6 +16,7 @@ static inline void fill_ldt(struct desc_
27227 + desc->base1 = (info->base_addr & 0x00ff0000) >> 16;
27228 + desc->type = (info->read_exec_only ^ 1) << 1;
27229 + desc->type |= info->contents << 2;
27230 ++ desc->type |= info->seg_not_present ^ 1;
27231 + desc->s = 1;
27232 + desc->dpl = 0x3;
27233 + desc->p = info->seg_not_present ^ 1;
27234 +@@ -27,16 +28,12 @@ static inline void fill_ldt(struct desc_
27235 + }
27236 +
27237 + extern struct desc_ptr idt_descr;
27238 +-extern gate_desc idt_table[];
27239 +-
27240 +-struct gdt_page {
27241 +- struct desc_struct gdt[GDT_ENTRIES];
27242 +-} __attribute__((aligned(PAGE_SIZE)));
27243 +-DECLARE_PER_CPU(struct gdt_page, gdt_page);
27244 ++extern gate_desc idt_table[256];
27245 +
27246 ++extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
27247 + static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
27248 + {
27249 +- return per_cpu(gdt_page, cpu).gdt;
27250 ++ return cpu_gdt_table[cpu];
27251 + }
27252 +
27253 + #ifdef CONFIG_X86_64
27254 +@@ -65,7 +62,6 @@ static inline void pack_gate(gate_desc *
27255 + gate->b = (base & 0xffff0000) |
27256 + (((0x80 | type | (dpl << 5)) & 0xff) << 8);
27257 + }
27258 +-
27259 + #endif
27260 +
27261 + static inline int desc_empty(const void *ptr)
27262 +@@ -102,19 +98,48 @@ static inline int desc_empty(const void
27263 + static inline void native_write_idt_entry(gate_desc *idt, int entry,
27264 + const gate_desc *gate)
27265 + {
27266 ++
27267 ++#ifdef CONFIG_PAX_KERNEXEC
27268 ++ unsigned long cr0;
27269 ++
27270 ++ pax_open_kernel(cr0);
27271 ++#endif
27272 ++
27273 + memcpy(&idt[entry], gate, sizeof(*gate));
27274 ++
27275 ++#ifdef CONFIG_PAX_KERNEXEC
27276 ++ pax_close_kernel(cr0);
27277 ++#endif
27278 ++
27279 + }
27280 +
27281 + static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry,
27282 + const void *desc)
27283 + {
27284 ++
27285 ++#ifdef CONFIG_PAX_KERNEXEC
27286 ++ unsigned long cr0;
27287 ++
27288 ++ pax_open_kernel(cr0);
27289 ++#endif
27290 ++
27291 + memcpy(&ldt[entry], desc, 8);
27292 ++
27293 ++#ifdef CONFIG_PAX_KERNEXEC
27294 ++ pax_close_kernel(cr0);
27295 ++#endif
27296 ++
27297 + }
27298 +
27299 + static inline void native_write_gdt_entry(struct desc_struct *gdt, int entry,
27300 + const void *desc, int type)
27301 + {
27302 + unsigned int size;
27303 ++
27304 ++#ifdef CONFIG_PAX_KERNEXEC
27305 ++ unsigned long cr0;
27306 ++#endif
27307 ++
27308 + switch (type) {
27309 + case DESC_TSS:
27310 + size = sizeof(tss_desc);
27311 +@@ -126,7 +151,17 @@ static inline void native_write_gdt_entr
27312 + size = sizeof(struct desc_struct);
27313 + break;
27314 + }
27315 ++
27316 ++#ifdef CONFIG_PAX_KERNEXEC
27317 ++ pax_open_kernel(cr0);
27318 ++#endif
27319 ++
27320 + memcpy(&gdt[entry], desc, size);
27321 ++
27322 ++#ifdef CONFIG_PAX_KERNEXEC
27323 ++ pax_close_kernel(cr0);
27324 ++#endif
27325 ++
27326 + }
27327 +
27328 + static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
27329 +@@ -198,7 +233,19 @@ static inline void native_set_ldt(const
27330 +
27331 + static inline void native_load_tr_desc(void)
27332 + {
27333 ++
27334 ++#ifdef CONFIG_PAX_KERNEXEC
27335 ++ unsigned long cr0;
27336 ++
27337 ++ pax_open_kernel(cr0);
27338 ++#endif
27339 ++
27340 + asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
27341 ++
27342 ++#ifdef CONFIG_PAX_KERNEXEC
27343 ++ pax_close_kernel(cr0);
27344 ++#endif
27345 ++
27346 + }
27347 +
27348 + static inline void native_load_gdt(const struct desc_ptr *dtr)
27349 +@@ -233,8 +280,19 @@ static inline void native_load_tls(struc
27350 + unsigned int i;
27351 + struct desc_struct *gdt = get_cpu_gdt_table(cpu);
27352 +
27353 ++#ifdef CONFIG_PAX_KERNEXEC
27354 ++ unsigned long cr0;
27355 ++
27356 ++ pax_open_kernel(cr0);
27357 ++#endif
27358 ++
27359 + for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
27360 + gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
27361 ++
27362 ++#ifdef CONFIG_PAX_KERNEXEC
27363 ++ pax_close_kernel(cr0);
27364 ++#endif
27365 ++
27366 + }
27367 +
27368 + #define _LDT_empty(info) \
27369 +@@ -372,6 +430,18 @@ static inline void set_system_gate_ist(i
27370 + _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
27371 + }
27372 +
27373 ++#ifdef CONFIG_X86_32
27374 ++static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
27375 ++{
27376 ++ struct desc_struct d;
27377 ++
27378 ++ if (likely(limit))
27379 ++ limit = (limit - 1UL) >> PAGE_SHIFT;
27380 ++ pack_descriptor(&d, base, limit, 0xFB, 0xC);
27381 ++ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
27382 ++}
27383 ++#endif
27384 ++
27385 + #else
27386 + /*
27387 + * GET_DESC_BASE reads the descriptor base of the specified segment.
27388 +diff -urNp linux-2.6.27.10/include/asm-x86/e820.h linux-2.6.27.10/include/asm-x86/e820.h
27389 +--- linux-2.6.27.10/include/asm-x86/e820.h 2008-11-07 12:55:34.000000000 -0500
27390 ++++ linux-2.6.27.10/include/asm-x86/e820.h 2008-11-18 03:38:45.000000000 -0500
27391 +@@ -131,7 +131,7 @@ extern char *memory_setup(void);
27392 + #define ISA_END_ADDRESS 0x100000
27393 + #define is_ISA_range(s, e) ((s) >= ISA_START_ADDRESS && (e) < ISA_END_ADDRESS)
27394 +
27395 +-#define BIOS_BEGIN 0x000a0000
27396 ++#define BIOS_BEGIN 0x000c0000
27397 + #define BIOS_END 0x00100000
27398 +
27399 + #ifdef __KERNEL__
27400 +diff -urNp linux-2.6.27.10/include/asm-x86/elf.h linux-2.6.27.10/include/asm-x86/elf.h
27401 +--- linux-2.6.27.10/include/asm-x86/elf.h 2008-11-07 12:55:34.000000000 -0500
27402 ++++ linux-2.6.27.10/include/asm-x86/elf.h 2008-11-18 03:38:45.000000000 -0500
27403 +@@ -251,7 +251,25 @@ extern int force_personality32;
27404 + the loader. We need to make sure that it is out of the way of the program
27405 + that it will "exec", and that there is sufficient room for the brk. */
27406 +
27407 ++#ifdef CONFIG_PAX_SEGMEXEC
27408 ++#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
27409 ++#else
27410 + #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
27411 ++#endif
27412 ++
27413 ++#ifdef CONFIG_PAX_ASLR
27414 ++#ifdef CONFIG_X86_32
27415 ++#define PAX_ELF_ET_DYN_BASE 0x10000000UL
27416 ++
27417 ++#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
27418 ++#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
27419 ++#else
27420 ++#define PAX_ELF_ET_DYN_BASE 0x400000UL
27421 ++
27422 ++#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_IA32)) ? 16 : 32)
27423 ++#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_IA32)) ? 16 : 32)
27424 ++#endif
27425 ++#endif
27426 +
27427 + /* This yields a mask that user programs can use to figure out what
27428 + instruction set this CPU supports. This could be done in user space,
27429 +@@ -303,8 +321,7 @@ do { \
27430 + #define ARCH_DLINFO \
27431 + do { \
27432 + if (vdso_enabled) \
27433 +- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
27434 +- (unsigned long)current->mm->context.vdso); \
27435 ++ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso);\
27436 + } while (0)
27437 +
27438 + #define AT_SYSINFO 32
27439 +@@ -315,7 +332,7 @@ do { \
27440 +
27441 + #endif /* !CONFIG_X86_32 */
27442 +
27443 +-#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
27444 ++#define VDSO_CURRENT_BASE (current->mm->context.vdso)
27445 +
27446 + #define VDSO_ENTRY \
27447 + ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
27448 +@@ -329,7 +346,4 @@ extern int arch_setup_additional_pages(s
27449 + extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
27450 + #define compat_arch_setup_additional_pages syscall32_setup_pages
27451 +
27452 +-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
27453 +-#define arch_randomize_brk arch_randomize_brk
27454 +-
27455 + #endif
27456 +diff -urNp linux-2.6.27.10/include/asm-x86/futex.h linux-2.6.27.10/include/asm-x86/futex.h
27457 +--- linux-2.6.27.10/include/asm-x86/futex.h 2008-11-07 12:55:34.000000000 -0500
27458 ++++ linux-2.6.27.10/include/asm-x86/futex.h 2008-11-18 03:38:45.000000000 -0500
27459 +@@ -11,6 +11,40 @@
27460 + #include <asm/processor.h>
27461 + #include <asm/system.h>
27462 +
27463 ++#ifdef CONFIG_X86_32
27464 ++#define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
27465 ++ asm volatile( \
27466 ++ "movw\t%w6, %%ds\n" \
27467 ++ "1:\t" insn "\n" \
27468 ++ "2:\tpushl\t%%ss\n" \
27469 ++ "\tpopl\t%%ds\n" \
27470 ++ "\t.section .fixup,\"ax\"\n" \
27471 ++ "3:\tmov\t%3, %1\n" \
27472 ++ "\tjmp\t2b\n" \
27473 ++ "\t.previous\n" \
27474 ++ _ASM_EXTABLE(1b, 3b) \
27475 ++ : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
27476 ++ : "i" (-EFAULT), "0" (oparg), "1" (0), "r" (__USER_DS))
27477 ++
27478 ++#define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
27479 ++ asm volatile("movw\t%w7, %%es\n" \
27480 ++ "1:\tmovl\t%%es:%2, %0\n" \
27481 ++ "\tmovl\t%0, %3\n" \
27482 ++ "\t" insn "\n" \
27483 ++ "2:\tlock; cmpxchgl %3, %%es:%2\n" \
27484 ++ "\tjnz\t1b\n" \
27485 ++ "3:\tpushl\t%%ss\n" \
27486 ++ "\tpopl\t%%es\n" \
27487 ++ "\t.section .fixup,\"ax\"\n" \
27488 ++ "4:\tmov\t%5, %1\n" \
27489 ++ "\tjmp\t3b\n" \
27490 ++ "\t.previous\n" \
27491 ++ _ASM_EXTABLE(1b, 4b) \
27492 ++ _ASM_EXTABLE(2b, 4b) \
27493 ++ : "=&a" (oldval), "=&r" (ret), \
27494 ++ "+m" (*uaddr), "=&r" (tem) \
27495 ++ : "r" (oparg), "i" (-EFAULT), "1" (0), "r" (__USER_DS))
27496 ++#else
27497 + #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
27498 + asm volatile("1:\t" insn "\n" \
27499 + "2:\t.section .fixup,\"ax\"\n" \
27500 +@@ -36,8 +70,9 @@
27501 + : "=&a" (oldval), "=&r" (ret), \
27502 + "+m" (*uaddr), "=&r" (tem) \
27503 + : "r" (oparg), "i" (-EFAULT), "1" (0))
27504 ++#endif
27505 +
27506 +-static inline int futex_atomic_op_inuser(int encoded_op, int __user *uaddr)
27507 ++static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
27508 + {
27509 + int op = (encoded_op >> 28) & 7;
27510 + int cmp = (encoded_op >> 24) & 15;
27511 +@@ -61,11 +96,20 @@ static inline int futex_atomic_op_inuser
27512 +
27513 + switch (op) {
27514 + case FUTEX_OP_SET:
27515 ++#ifdef CONFIG_X86_32
27516 ++ __futex_atomic_op1("xchgl %0, %%ds:%2", ret, oldval, uaddr, oparg);
27517 ++#else
27518 + __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
27519 ++#endif
27520 + break;
27521 + case FUTEX_OP_ADD:
27522 ++#ifdef CONFIG_X86_32
27523 ++ __futex_atomic_op1("lock ; xaddl %0, %%ds:%2", ret, oldval,
27524 ++ uaddr, oparg);
27525 ++#else
27526 + __futex_atomic_op1("lock; xaddl %0, %2", ret, oldval,
27527 + uaddr, oparg);
27528 ++#endif
27529 + break;
27530 + case FUTEX_OP_OR:
27531 + __futex_atomic_op2("orl %4, %3", ret, oldval, uaddr, oparg);
27532 +@@ -109,7 +153,7 @@ static inline int futex_atomic_op_inuser
27533 + return ret;
27534 + }
27535 +
27536 +-static inline int futex_atomic_cmpxchg_inatomic(int __user *uaddr, int oldval,
27537 ++static inline int futex_atomic_cmpxchg_inatomic(u32 __user *uaddr, int oldval,
27538 + int newval)
27539 + {
27540 +
27541 +@@ -122,14 +166,27 @@ static inline int futex_atomic_cmpxchg_i
27542 + if (!access_ok(VERIFY_WRITE, uaddr, sizeof(int)))
27543 + return -EFAULT;
27544 +
27545 +- asm volatile("1:\tlock; cmpxchgl %3, %1\n"
27546 ++ asm volatile(
27547 ++#ifdef CONFIG_X86_32
27548 ++ "\tmovw %w5, %%ds\n"
27549 ++ "1:\tlock; cmpxchgl %3, %1\n"
27550 ++ "2:\tpushl %%ss\n"
27551 ++ "\tpopl %%ds\n"
27552 ++ "\t.section .fixup, \"ax\"\n"
27553 ++#else
27554 ++ "1:\tlock; cmpxchgl %3, %1\n"
27555 + "2:\t.section .fixup, \"ax\"\n"
27556 ++#endif
27557 + "3:\tmov %2, %0\n"
27558 + "\tjmp 2b\n"
27559 + "\t.previous\n"
27560 + _ASM_EXTABLE(1b, 3b)
27561 + : "=a" (oldval), "+m" (*uaddr)
27562 ++#ifdef CONFIG_X86_32
27563 ++ : "i" (-EFAULT), "r" (newval), "0" (oldval), "r" (__USER_DS)
27564 ++#else
27565 + : "i" (-EFAULT), "r" (newval), "0" (oldval)
27566 ++#endif
27567 + : "memory"
27568 + );
27569 +
27570 +diff -urNp linux-2.6.27.10/include/asm-x86/i387.h linux-2.6.27.10/include/asm-x86/i387.h
27571 +--- linux-2.6.27.10/include/asm-x86/i387.h 2008-11-07 12:55:34.000000000 -0500
27572 ++++ linux-2.6.27.10/include/asm-x86/i387.h 2008-11-18 03:38:45.000000000 -0500
27573 +@@ -159,13 +159,8 @@ static inline void restore_fpu(struct ta
27574 + }
27575 +
27576 + /* We need a safe address that is cheap to find and that is already
27577 +- in L1 during context switch. The best choices are unfortunately
27578 +- different for UP and SMP */
27579 +-#ifdef CONFIG_SMP
27580 +-#define safe_address (__per_cpu_offset[0])
27581 +-#else
27582 +-#define safe_address (kstat_cpu(0).cpustat.user)
27583 +-#endif
27584 ++ in L1 during context switch. */
27585 ++#define safe_address (init_tss[smp_processor_id()].x86_tss.sp0)
27586 +
27587 + /*
27588 + * These must be called with preempt disabled
27589 +diff -urNp linux-2.6.27.10/include/asm-x86/io_64.h linux-2.6.27.10/include/asm-x86/io_64.h
27590 +--- linux-2.6.27.10/include/asm-x86/io_64.h 2008-11-07 12:55:34.000000000 -0500
27591 ++++ linux-2.6.27.10/include/asm-x86/io_64.h 2008-11-18 03:38:45.000000000 -0500
27592 +@@ -158,6 +158,17 @@ static inline void *phys_to_virt(unsigne
27593 + }
27594 + #endif
27595 +
27596 ++#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
27597 ++static inline int valid_phys_addr_range (unsigned long addr, size_t count)
27598 ++{
27599 ++ return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1 << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
27600 ++}
27601 ++
27602 ++static inline int valid_mmap_phys_addr_range (unsigned long pfn, size_t count)
27603 ++{
27604 ++ return (pfn + (count >> PAGE_SHIFT)) < (1 << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
27605 ++}
27606 ++
27607 + /*
27608 + * Change "struct page" to physical address.
27609 + */
27610 +diff -urNp linux-2.6.27.10/include/asm-x86/irqflags.h linux-2.6.27.10/include/asm-x86/irqflags.h
27611 +--- linux-2.6.27.10/include/asm-x86/irqflags.h 2008-11-07 12:55:34.000000000 -0500
27612 ++++ linux-2.6.27.10/include/asm-x86/irqflags.h 2008-11-18 03:38:45.000000000 -0500
27613 +@@ -141,6 +141,8 @@ static inline unsigned long __raw_local_
27614 + #define INTERRUPT_RETURN iret
27615 + #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
27616 + #define GET_CR0_INTO_EAX movl %cr0, %eax
27617 ++#define GET_CR0_INTO_EDX movl %cr0, %edx
27618 ++#define SET_CR0_FROM_EDX movl %edx, %cr0
27619 + #endif
27620 +
27621 +
27622 +diff -urNp linux-2.6.27.10/include/asm-x86/kmap_types.h linux-2.6.27.10/include/asm-x86/kmap_types.h
27623 +--- linux-2.6.27.10/include/asm-x86/kmap_types.h 2008-11-07 12:55:34.000000000 -0500
27624 ++++ linux-2.6.27.10/include/asm-x86/kmap_types.h 2008-11-18 03:38:45.000000000 -0500
27625 +@@ -21,7 +21,8 @@ D(9) KM_IRQ0,
27626 + D(10) KM_IRQ1,
27627 + D(11) KM_SOFTIRQ0,
27628 + D(12) KM_SOFTIRQ1,
27629 +-D(13) KM_TYPE_NR
27630 ++D(13) KM_CLEARPAGE,
27631 ++D(14) KM_TYPE_NR
27632 + };
27633 +
27634 + #undef D
27635 +diff -urNp linux-2.6.27.10/include/asm-x86/linkage.h linux-2.6.27.10/include/asm-x86/linkage.h
27636 +--- linux-2.6.27.10/include/asm-x86/linkage.h 2008-11-07 12:55:34.000000000 -0500
27637 ++++ linux-2.6.27.10/include/asm-x86/linkage.h 2008-11-18 03:38:45.000000000 -0500
27638 +@@ -7,6 +7,11 @@
27639 + #ifdef CONFIG_X86_64
27640 + #define __ALIGN .p2align 4,,15
27641 + #define __ALIGN_STR ".p2align 4,,15"
27642 ++#else
27643 ++#ifdef CONFIG_X86_ALIGNMENT_16
27644 ++#define __ALIGN .align 16,0x90
27645 ++#define __ALIGN_STR ".align 16,0x90"
27646 ++#endif
27647 + #endif
27648 +
27649 + #ifdef CONFIG_X86_32
27650 +@@ -52,10 +57,5 @@
27651 +
27652 + #endif
27653 +
27654 +-#ifdef CONFIG_X86_ALIGNMENT_16
27655 +-#define __ALIGN .align 16,0x90
27656 +-#define __ALIGN_STR ".align 16,0x90"
27657 +-#endif
27658 +-
27659 + #endif
27660 +
27661 +diff -urNp linux-2.6.27.10/include/asm-x86/local.h linux-2.6.27.10/include/asm-x86/local.h
27662 +--- linux-2.6.27.10/include/asm-x86/local.h 2008-11-07 12:55:34.000000000 -0500
27663 ++++ linux-2.6.27.10/include/asm-x86/local.h 2008-11-18 03:38:45.000000000 -0500
27664 +@@ -18,26 +18,90 @@ typedef struct {
27665 +
27666 + static inline void local_inc(local_t *l)
27667 + {
27668 +- asm volatile(_ASM_INC "%0"
27669 ++ asm volatile(_ASM_INC "%0\n"
27670 ++
27671 ++#ifdef CONFIG_PAX_REFCOUNT
27672 ++#ifdef CONFIG_X86_32
27673 ++ "into\n0:\n"
27674 ++#else
27675 ++ "jno 0f\n"
27676 ++ "int $4\n0:\n"
27677 ++#endif
27678 ++ ".pushsection .fixup,\"ax\"\n"
27679 ++ "1:\n"
27680 ++ _ASM_DEC "%0\n"
27681 ++ "jmp 0b\n"
27682 ++ ".popsection\n"
27683 ++ _ASM_EXTABLE(0b, 1b)
27684 ++#endif
27685 ++
27686 + : "+m" (l->a.counter));
27687 + }
27688 +
27689 + static inline void local_dec(local_t *l)
27690 + {
27691 +- asm volatile(_ASM_DEC "%0"
27692 ++ asm volatile(_ASM_DEC "%0\n"
27693 ++
27694 ++#ifdef CONFIG_PAX_REFCOUNT
27695 ++#ifdef CONFIG_X86_32
27696 ++ "into\n0:\n"
27697 ++#else
27698 ++ "jno 0f\n"
27699 ++ "int $4\n0:\n"
27700 ++#endif
27701 ++ ".pushsection .fixup,\"ax\"\n"
27702 ++ "1:\n"
27703 ++ _ASM_INC "%0\n"
27704 ++ "jmp 0b\n"
27705 ++ ".popsection\n"
27706 ++ _ASM_EXTABLE(0b, 1b)
27707 ++#endif
27708 ++
27709 + : "+m" (l->a.counter));
27710 + }
27711 +
27712 + static inline void local_add(long i, local_t *l)
27713 + {
27714 +- asm volatile(_ASM_ADD "%1,%0"
27715 ++ asm volatile(_ASM_ADD "%1,%0\n"
27716 ++
27717 ++#ifdef CONFIG_PAX_REFCOUNT
27718 ++#ifdef CONFIG_X86_32
27719 ++ "into\n0:\n"
27720 ++#else
27721 ++ "jno 0f\n"
27722 ++ "int $4\n0:\n"
27723 ++#endif
27724 ++ ".pushsection .fixup,\"ax\"\n"
27725 ++ "1:\n"
27726 ++ _ASM_SUB "%1,%0\n"
27727 ++ "jmp 0b\n"
27728 ++ ".popsection\n"
27729 ++ _ASM_EXTABLE(0b, 1b)
27730 ++#endif
27731 ++
27732 + : "+m" (l->a.counter)
27733 + : "ir" (i));
27734 + }
27735 +
27736 + static inline void local_sub(long i, local_t *l)
27737 + {
27738 +- asm volatile(_ASM_SUB "%1,%0"
27739 ++ asm volatile(_ASM_SUB "%1,%0\n"
27740 ++
27741 ++#ifdef CONFIG_PAX_REFCOUNT
27742 ++#ifdef CONFIG_X86_32
27743 ++ "into\n0:\n"
27744 ++#else
27745 ++ "jno 0f\n"
27746 ++ "int $4\n0:\n"
27747 ++#endif
27748 ++ ".pushsection .fixup,\"ax\"\n"
27749 ++ "1:\n"
27750 ++ _ASM_ADD "%1,%0\n"
27751 ++ "jmp 0b\n"
27752 ++ ".popsection\n"
27753 ++ _ASM_EXTABLE(0b, 1b)
27754 ++#endif
27755 ++
27756 + : "+m" (l->a.counter)
27757 + : "ir" (i));
27758 + }
27759 +@@ -55,7 +119,24 @@ static inline int local_sub_and_test(lon
27760 + {
27761 + unsigned char c;
27762 +
27763 +- asm volatile(_ASM_SUB "%2,%0; sete %1"
27764 ++ asm volatile(_ASM_SUB "%2,%0\n"
27765 ++
27766 ++#ifdef CONFIG_PAX_REFCOUNT
27767 ++#ifdef CONFIG_X86_32
27768 ++ "into\n0:\n"
27769 ++#else
27770 ++ "jno 0f\n"
27771 ++ "int $4\n0:\n"
27772 ++#endif
27773 ++ ".pushsection .fixup,\"ax\"\n"
27774 ++ "1:\n"
27775 ++ _ASM_ADD "%2,%0\n"
27776 ++ "jmp 0b\n"
27777 ++ ".popsection\n"
27778 ++ _ASM_EXTABLE(0b, 1b)
27779 ++#endif
27780 ++
27781 ++ "sete %1\n"
27782 + : "+m" (l->a.counter), "=qm" (c)
27783 + : "ir" (i) : "memory");
27784 + return c;
27785 +@@ -73,7 +154,24 @@ static inline int local_dec_and_test(loc
27786 + {
27787 + unsigned char c;
27788 +
27789 +- asm volatile(_ASM_DEC "%0; sete %1"
27790 ++ asm volatile(_ASM_DEC "%0\n"
27791 ++
27792 ++#ifdef CONFIG_PAX_REFCOUNT
27793 ++#ifdef CONFIG_X86_32
27794 ++ "into\n0:\n"
27795 ++#else
27796 ++ "jno 0f\n"
27797 ++ "int $4\n0:\n"
27798 ++#endif
27799 ++ ".pushsection .fixup,\"ax\"\n"
27800 ++ "1:\n"
27801 ++ _ASM_INC "%0\n"
27802 ++ "jmp 0b\n"
27803 ++ ".popsection\n"
27804 ++ _ASM_EXTABLE(0b, 1b)
27805 ++#endif
27806 ++
27807 ++ "sete %1\n"
27808 + : "+m" (l->a.counter), "=qm" (c)
27809 + : : "memory");
27810 + return c != 0;
27811 +@@ -91,7 +189,24 @@ static inline int local_inc_and_test(loc
27812 + {
27813 + unsigned char c;
27814 +
27815 +- asm volatile(_ASM_INC "%0; sete %1"
27816 ++ asm volatile(_ASM_INC "%0\n"
27817 ++
27818 ++#ifdef CONFIG_PAX_REFCOUNT
27819 ++#ifdef CONFIG_X86_32
27820 ++ "into\n0:\n"
27821 ++#else
27822 ++ "jno 0f\n"
27823 ++ "int $4\n0:\n"
27824 ++#endif
27825 ++ ".pushsection .fixup,\"ax\"\n"
27826 ++ "1:\n"
27827 ++ _ASM_DEC "%0\n"
27828 ++ "jmp 0b\n"
27829 ++ ".popsection\n"
27830 ++ _ASM_EXTABLE(0b, 1b)
27831 ++#endif
27832 ++
27833 ++ "sete %1\n"
27834 + : "+m" (l->a.counter), "=qm" (c)
27835 + : : "memory");
27836 + return c != 0;
27837 +@@ -110,7 +225,24 @@ static inline int local_add_negative(lon
27838 + {
27839 + unsigned char c;
27840 +
27841 +- asm volatile(_ASM_ADD "%2,%0; sets %1"
27842 ++ asm volatile(_ASM_ADD "%2,%0\n"
27843 ++
27844 ++#ifdef CONFIG_PAX_REFCOUNT
27845 ++#ifdef CONFIG_X86_32
27846 ++ "into\n0:\n"
27847 ++#else
27848 ++ "jno 0f\n"
27849 ++ "int $4\n0:\n"
27850 ++#endif
27851 ++ ".pushsection .fixup,\"ax\"\n"
27852 ++ "1:\n"
27853 ++ _ASM_SUB "%2,%0\n"
27854 ++ "jmp 0b\n"
27855 ++ ".popsection\n"
27856 ++ _ASM_EXTABLE(0b, 1b)
27857 ++#endif
27858 ++
27859 ++ "sets %1\n"
27860 + : "+m" (l->a.counter), "=qm" (c)
27861 + : "ir" (i) : "memory");
27862 + return c;
27863 +@@ -133,7 +265,23 @@ static inline long local_add_return(long
27864 + #endif
27865 + /* Modern 486+ processor */
27866 + __i = i;
27867 +- asm volatile(_ASM_XADD "%0, %1;"
27868 ++ asm volatile(_ASM_XADD "%0, %1\n"
27869 ++
27870 ++#ifdef CONFIG_PAX_REFCOUNT
27871 ++#ifdef CONFIG_X86_32
27872 ++ "into\n0:\n"
27873 ++#else
27874 ++ "jno 0f\n"
27875 ++ "int $4\n0:\n"
27876 ++#endif
27877 ++ ".pushsection .fixup,\"ax\"\n"
27878 ++ "1:\n"
27879 ++ _ASM_MOV_UL "%0,%1\n"
27880 ++ "jmp 0b\n"
27881 ++ ".popsection\n"
27882 ++ _ASM_EXTABLE(0b, 1b)
27883 ++#endif
27884 ++
27885 + : "+r" (i), "+m" (l->a.counter)
27886 + : : "memory");
27887 + return i + __i;
27888 +diff -urNp linux-2.6.27.10/include/asm-x86/mach-default/apm.h linux-2.6.27.10/include/asm-x86/mach-default/apm.h
27889 +--- linux-2.6.27.10/include/asm-x86/mach-default/apm.h 2008-11-07 12:55:34.000000000 -0500
27890 ++++ linux-2.6.27.10/include/asm-x86/mach-default/apm.h 2008-11-18 03:38:45.000000000 -0500
27891 +@@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32
27892 + __asm__ __volatile__(APM_DO_ZERO_SEGS
27893 + "pushl %%edi\n\t"
27894 + "pushl %%ebp\n\t"
27895 +- "lcall *%%cs:apm_bios_entry\n\t"
27896 ++ "lcall *%%ss:apm_bios_entry\n\t"
27897 + "setc %%al\n\t"
27898 + "popl %%ebp\n\t"
27899 + "popl %%edi\n\t"
27900 +@@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_as
27901 + __asm__ __volatile__(APM_DO_ZERO_SEGS
27902 + "pushl %%edi\n\t"
27903 + "pushl %%ebp\n\t"
27904 +- "lcall *%%cs:apm_bios_entry\n\t"
27905 ++ "lcall *%%ss:apm_bios_entry\n\t"
27906 + "setc %%bl\n\t"
27907 + "popl %%ebp\n\t"
27908 + "popl %%edi\n\t"
27909 +diff -urNp linux-2.6.27.10/include/asm-x86/mman.h linux-2.6.27.10/include/asm-x86/mman.h
27910 +--- linux-2.6.27.10/include/asm-x86/mman.h 2008-11-07 12:55:34.000000000 -0500
27911 ++++ linux-2.6.27.10/include/asm-x86/mman.h 2008-11-18 03:38:45.000000000 -0500
27912 +@@ -17,4 +17,14 @@
27913 + #define MCL_CURRENT 1 /* lock all current mappings */
27914 + #define MCL_FUTURE 2 /* lock all future mappings */
27915 +
27916 ++#ifdef __KERNEL__
27917 ++#ifndef __ASSEMBLY__
27918 ++#ifdef CONFIG_X86_32
27919 ++#define arch_mmap_check i386_mmap_check
27920 ++int i386_mmap_check(unsigned long addr, unsigned long len,
27921 ++ unsigned long flags);
27922 ++#endif
27923 ++#endif
27924 ++#endif
27925 ++
27926 + #endif /* _ASM_X86_MMAN_H */
27927 +diff -urNp linux-2.6.27.10/include/asm-x86/mmu_context_32.h linux-2.6.27.10/include/asm-x86/mmu_context_32.h
27928 +--- linux-2.6.27.10/include/asm-x86/mmu_context_32.h 2008-11-07 12:55:34.000000000 -0500
27929 ++++ linux-2.6.27.10/include/asm-x86/mmu_context_32.h 2008-11-18 03:38:45.000000000 -0500
27930 +@@ -33,6 +33,22 @@ static inline void switch_mm(struct mm_s
27931 + */
27932 + if (unlikely(prev->context.ldt != next->context.ldt))
27933 + load_LDT_nolock(&next->context);
27934 ++
27935 ++#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
27936 ++ if (!nx_enabled) {
27937 ++ smp_mb__before_clear_bit();
27938 ++ cpu_clear(cpu, prev->context.cpu_user_cs_mask);
27939 ++ smp_mb__after_clear_bit();
27940 ++ cpu_set(cpu, next->context.cpu_user_cs_mask);
27941 ++ }
27942 ++#endif
27943 ++
27944 ++#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
27945 ++ if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
27946 ++ prev->context.user_cs_limit != next->context.user_cs_limit))
27947 ++ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
27948 ++#endif
27949 ++
27950 + }
27951 + #ifdef CONFIG_SMP
27952 + else {
27953 +@@ -45,6 +61,19 @@ static inline void switch_mm(struct mm_s
27954 + */
27955 + load_cr3(next->pgd);
27956 + load_LDT_nolock(&next->context);
27957 ++
27958 ++#ifdef CONFIG_PAX_PAGEEXEC
27959 ++ if (!nx_enabled)
27960 ++ cpu_set(cpu, next->context.cpu_user_cs_mask);
27961 ++#endif
27962 ++
27963 ++#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
27964 ++#ifdef CONFIG_PAX_PAGEEXEC
27965 ++ if (!((next->pax_flags & MF_PAX_PAGEEXEC) && nx_enabled))
27966 ++#endif
27967 ++ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
27968 ++#endif
27969 ++
27970 + }
27971 + }
27972 + #endif
27973 +diff -urNp linux-2.6.27.10/include/asm-x86/mmu.h linux-2.6.27.10/include/asm-x86/mmu.h
27974 +--- linux-2.6.27.10/include/asm-x86/mmu.h 2008-11-07 12:55:34.000000000 -0500
27975 ++++ linux-2.6.27.10/include/asm-x86/mmu.h 2008-11-18 03:38:45.000000000 -0500
27976 +@@ -11,13 +11,26 @@
27977 + * cpu_vm_mask is used to optimize ldt flushing.
27978 + */
27979 + typedef struct {
27980 +- void *ldt;
27981 ++ struct desc_struct *ldt;
27982 + #ifdef CONFIG_X86_64
27983 + rwlock_t ldtlock;
27984 + #endif
27985 + int size;
27986 + struct mutex lock;
27987 +- void *vdso;
27988 ++ unsigned long vdso;
27989 ++
27990 ++#ifdef CONFIG_X86_32
27991 ++#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
27992 ++ unsigned long user_cs_base;
27993 ++ unsigned long user_cs_limit;
27994 ++
27995 ++#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
27996 ++ cpumask_t cpu_user_cs_mask;
27997 ++#endif
27998 ++
27999 ++#endif
28000 ++#endif
28001 ++
28002 + } mm_context_t;
28003 +
28004 + #ifdef CONFIG_SMP
28005 +diff -urNp linux-2.6.27.10/include/asm-x86/module.h linux-2.6.27.10/include/asm-x86/module.h
28006 +--- linux-2.6.27.10/include/asm-x86/module.h 2008-11-07 12:55:34.000000000 -0500
28007 ++++ linux-2.6.27.10/include/asm-x86/module.h 2008-11-18 03:38:45.000000000 -0500
28008 +@@ -76,7 +76,12 @@ struct mod_arch_specific {};
28009 + # else
28010 + # define MODULE_STACKSIZE ""
28011 + # endif
28012 +-# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_STACKSIZE
28013 ++# ifdef CONFIG_GRKERNSEC
28014 ++# define MODULE_GRSEC "GRSECURITY "
28015 ++# else
28016 ++# define MODULE_GRSEC ""
28017 ++# endif
28018 ++# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_STACKSIZE MODULE_GRSEC
28019 + #endif
28020 +
28021 + #endif /* _ASM_MODULE_H */
28022 +diff -urNp linux-2.6.27.10/include/asm-x86/page_32.h linux-2.6.27.10/include/asm-x86/page_32.h
28023 +--- linux-2.6.27.10/include/asm-x86/page_32.h 2008-11-07 12:55:34.000000000 -0500
28024 ++++ linux-2.6.27.10/include/asm-x86/page_32.h 2008-11-18 03:38:45.000000000 -0500
28025 +@@ -13,6 +13,23 @@
28026 + */
28027 + #define __PAGE_OFFSET _AC(CONFIG_PAGE_OFFSET, UL)
28028 +
28029 ++#ifdef CONFIG_PAX_KERNEXEC
28030 ++#ifndef __ASSEMBLY__
28031 ++extern unsigned char MODULES_VADDR[];
28032 ++extern unsigned char MODULES_END[];
28033 ++extern unsigned char KERNEL_TEXT_OFFSET[];
28034 ++#define ktla_ktva(addr) (addr + (unsigned long)KERNEL_TEXT_OFFSET)
28035 ++#define ktva_ktla(addr) (addr - (unsigned long)KERNEL_TEXT_OFFSET)
28036 ++#endif
28037 ++#else
28038 ++#define ktla_ktva(addr) (addr)
28039 ++#define ktva_ktla(addr) (addr)
28040 ++#endif
28041 ++
28042 ++#ifdef CONFIG_PAX_PAGEEXEC
28043 ++#define CONFIG_ARCH_TRACK_EXEC_LIMIT 1
28044 ++#endif
28045 ++
28046 + #ifdef CONFIG_4KSTACKS
28047 + #define THREAD_ORDER 0
28048 + #else
28049 +diff -urNp linux-2.6.27.10/include/asm-x86/page_64.h linux-2.6.27.10/include/asm-x86/page_64.h
28050 +--- linux-2.6.27.10/include/asm-x86/page_64.h 2008-11-07 12:55:34.000000000 -0500
28051 ++++ linux-2.6.27.10/include/asm-x86/page_64.h 2008-11-18 03:38:45.000000000 -0500
28052 +@@ -49,6 +49,9 @@
28053 + #define __START_KERNEL (__START_KERNEL_map + __PHYSICAL_START)
28054 + #define __START_KERNEL_map _AC(0xffffffff80000000, UL)
28055 +
28056 ++#define ktla_ktva(addr) (addr)
28057 ++#define ktva_ktla(addr) (addr)
28058 ++
28059 + /* See Documentation/x86_64/mm.txt for a description of the memory map. */
28060 + #define __PHYSICAL_MASK_SHIFT 46
28061 + #define __VIRTUAL_MASK_SHIFT 48
28062 +@@ -101,5 +104,6 @@ extern void init_extra_mapping_wb(unsign
28063 + #define pfn_valid(pfn) ((pfn) < max_pfn)
28064 + #endif
28065 +
28066 ++#define nx_enabled (1)
28067 +
28068 + #endif /* _X86_64_PAGE_H */
28069 +diff -urNp linux-2.6.27.10/include/asm-x86/paravirt.h linux-2.6.27.10/include/asm-x86/paravirt.h
28070 +--- linux-2.6.27.10/include/asm-x86/paravirt.h 2008-11-07 12:55:34.000000000 -0500
28071 ++++ linux-2.6.27.10/include/asm-x86/paravirt.h 2008-11-18 03:38:45.000000000 -0500
28072 +@@ -1557,7 +1557,7 @@ static inline unsigned long __raw_local_
28073 + #define PV_RESTORE_REGS popl %edx; popl %ecx; popl %edi; popl %eax
28074 + #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
28075 + #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
28076 +-#define PARA_INDIRECT(addr) *%cs:addr
28077 ++#define PARA_INDIRECT(addr) *%ss:addr
28078 + #endif
28079 +
28080 + #define INTERRUPT_RETURN \
28081 +diff -urNp linux-2.6.27.10/include/asm-x86/pda.h linux-2.6.27.10/include/asm-x86/pda.h
28082 +--- linux-2.6.27.10/include/asm-x86/pda.h 2008-11-07 12:55:34.000000000 -0500
28083 ++++ linux-2.6.27.10/include/asm-x86/pda.h 2008-11-18 03:38:45.000000000 -0500
28084 +@@ -16,11 +16,9 @@ struct x8664_pda {
28085 + unsigned long oldrsp; /* 24 user rsp for system call */
28086 + int irqcount; /* 32 Irq nesting counter. Starts -1 */
28087 + unsigned int cpunumber; /* 36 Logical CPU number */
28088 +-#ifdef CONFIG_CC_STACKPROTECTOR
28089 + unsigned long stack_canary; /* 40 stack canary value */
28090 + /* gcc-ABI: this canary MUST be at
28091 + offset 40!!! */
28092 +-#endif
28093 + char *irqstackptr;
28094 + short nodenumber; /* number of current node (32k max) */
28095 + short in_bootmem; /* pda lives in bootmem */
28096 +diff -urNp linux-2.6.27.10/include/asm-x86/percpu.h linux-2.6.27.10/include/asm-x86/percpu.h
28097 +--- linux-2.6.27.10/include/asm-x86/percpu.h 2008-11-07 12:55:34.000000000 -0500
28098 ++++ linux-2.6.27.10/include/asm-x86/percpu.h 2008-11-18 03:38:45.000000000 -0500
28099 +@@ -93,6 +93,12 @@ DECLARE_PER_CPU(struct x8664_pda, pda);
28100 +
28101 + #define __my_cpu_offset x86_read_percpu(this_cpu_off)
28102 +
28103 ++#include <asm-generic/sections.h>
28104 ++#include <linux/threads.h>
28105 ++#define __per_cpu_offset __per_cpu_offset
28106 ++extern unsigned long __per_cpu_offset[NR_CPUS];
28107 ++#define per_cpu_offset(x) (__per_cpu_offset[x] + (unsigned long)__per_cpu_start)
28108 ++
28109 + /* fs segment starts at (positive) offset == __per_cpu_offset[cpu] */
28110 + #define __percpu_seg "%%fs:"
28111 +
28112 +diff -urNp linux-2.6.27.10/include/asm-x86/pgalloc.h linux-2.6.27.10/include/asm-x86/pgalloc.h
28113 +--- linux-2.6.27.10/include/asm-x86/pgalloc.h 2008-11-07 12:55:34.000000000 -0500
28114 ++++ linux-2.6.27.10/include/asm-x86/pgalloc.h 2008-11-18 03:38:45.000000000 -0500
28115 +@@ -51,7 +51,7 @@ static inline void pmd_populate_kernel(s
28116 + pmd_t *pmd, pte_t *pte)
28117 + {
28118 + paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
28119 +- set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
28120 ++ set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
28121 + }
28122 +
28123 + static inline void pmd_populate(struct mm_struct *mm, pmd_t *pmd,
28124 +diff -urNp linux-2.6.27.10/include/asm-x86/pgtable-2level.h linux-2.6.27.10/include/asm-x86/pgtable-2level.h
28125 +--- linux-2.6.27.10/include/asm-x86/pgtable-2level.h 2008-11-07 12:55:34.000000000 -0500
28126 ++++ linux-2.6.27.10/include/asm-x86/pgtable-2level.h 2008-11-18 03:38:45.000000000 -0500
28127 +@@ -18,7 +18,19 @@ static inline void native_set_pte(pte_t
28128 +
28129 + static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
28130 + {
28131 ++
28132 ++#ifdef CONFIG_PAX_KERNEXEC
28133 ++ unsigned long cr0;
28134 ++
28135 ++ pax_open_kernel(cr0);
28136 ++#endif
28137 ++
28138 + *pmdp = pmd;
28139 ++
28140 ++#ifdef CONFIG_PAX_KERNEXEC
28141 ++ pax_close_kernel(cr0);
28142 ++#endif
28143 ++
28144 + }
28145 +
28146 + static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
28147 +diff -urNp linux-2.6.27.10/include/asm-x86/pgtable_32.h linux-2.6.27.10/include/asm-x86/pgtable_32.h
28148 +--- linux-2.6.27.10/include/asm-x86/pgtable_32.h 2008-11-07 12:55:34.000000000 -0500
28149 ++++ linux-2.6.27.10/include/asm-x86/pgtable_32.h 2008-11-18 03:38:45.000000000 -0500
28150 +@@ -25,8 +25,6 @@
28151 + struct mm_struct;
28152 + struct vm_area_struct;
28153 +
28154 +-extern pgd_t swapper_pg_dir[1024];
28155 +-
28156 + static inline void pgtable_cache_init(void) { }
28157 + static inline void check_pgt_cache(void) { }
28158 + void paging_init(void);
28159 +@@ -45,6 +43,11 @@ void paging_init(void);
28160 + # include <asm/pgtable-2level-defs.h>
28161 + #endif
28162 +
28163 ++extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
28164 ++#ifdef CONFIG_X86_PAE
28165 ++extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
28166 ++#endif
28167 ++
28168 + #define PGDIR_SIZE (1UL << PGDIR_SHIFT)
28169 + #define PGDIR_MASK (~(PGDIR_SIZE - 1))
28170 +
28171 +@@ -81,7 +84,7 @@ void paging_init(void);
28172 + #undef TEST_ACCESS_OK
28173 +
28174 + /* The boot page tables (all created as a single array) */
28175 +-extern unsigned long pg0[];
28176 ++extern pte_t pg0[];
28177 +
28178 + #define pte_present(x) ((x).pte_low & (_PAGE_PRESENT | _PAGE_PROTNONE))
28179 +
28180 +@@ -173,6 +176,9 @@ do { \
28181 +
28182 + #endif /* !__ASSEMBLY__ */
28183 +
28184 ++#define HAVE_ARCH_UNMAPPED_AREA
28185 ++#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
28186 ++
28187 + /*
28188 + * kern_addr_valid() is (1) for FLATMEM and (0) for
28189 + * SPARSEMEM and DISCONTIGMEM
28190 +diff -urNp linux-2.6.27.10/include/asm-x86/pgtable-3level.h linux-2.6.27.10/include/asm-x86/pgtable-3level.h
28191 +--- linux-2.6.27.10/include/asm-x86/pgtable-3level.h 2008-11-07 12:55:34.000000000 -0500
28192 ++++ linux-2.6.27.10/include/asm-x86/pgtable-3level.h 2008-11-18 03:38:45.000000000 -0500
28193 +@@ -70,12 +70,36 @@ static inline void native_set_pte_atomic
28194 +
28195 + static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
28196 + {
28197 ++
28198 ++#ifdef CONFIG_PAX_KERNEXEC
28199 ++ unsigned long cr0;
28200 ++
28201 ++ pax_open_kernel(cr0);
28202 ++#endif
28203 ++
28204 + set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
28205 ++
28206 ++#ifdef CONFIG_PAX_KERNEXEC
28207 ++ pax_close_kernel(cr0);
28208 ++#endif
28209 ++
28210 + }
28211 +
28212 + static inline void native_set_pud(pud_t *pudp, pud_t pud)
28213 + {
28214 ++
28215 ++#ifdef CONFIG_PAX_KERNEXEC
28216 ++ unsigned long cr0;
28217 ++
28218 ++ pax_open_kernel(cr0);
28219 ++#endif
28220 ++
28221 + set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
28222 ++
28223 ++#ifdef CONFIG_PAX_KERNEXEC
28224 ++ pax_close_kernel(cr0);
28225 ++#endif
28226 ++
28227 + }
28228 +
28229 + /*
28230 +diff -urNp linux-2.6.27.10/include/asm-x86/pgtable_64.h linux-2.6.27.10/include/asm-x86/pgtable_64.h
28231 +--- linux-2.6.27.10/include/asm-x86/pgtable_64.h 2008-11-07 12:55:34.000000000 -0500
28232 ++++ linux-2.6.27.10/include/asm-x86/pgtable_64.h 2008-11-18 03:38:45.000000000 -0500
28233 +@@ -15,9 +15,12 @@
28234 +
28235 + extern pud_t level3_kernel_pgt[512];
28236 + extern pud_t level3_ident_pgt[512];
28237 ++extern pud_t level3_vmalloc_pgt[512];
28238 ++extern pud_t level3_vmemmap_pgt[512];
28239 + extern pmd_t level2_kernel_pgt[512];
28240 + extern pmd_t level2_fixmap_pgt[512];
28241 + extern pmd_t level2_ident_pgt[512];
28242 ++extern pte_t level1_fixmap_pgt[512];
28243 + extern pgd_t init_level4_pgt[];
28244 +
28245 + #define swapper_pg_dir init_level4_pgt
28246 +@@ -106,7 +109,19 @@ static inline pte_t native_ptep_get_and_
28247 +
28248 + static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
28249 + {
28250 ++
28251 ++#ifdef CONFIG_PAX_KERNEXEC
28252 ++ unsigned long cr0;
28253 ++
28254 ++ pax_open_kernel(cr0);
28255 ++#endif
28256 ++
28257 + *pmdp = pmd;
28258 ++
28259 ++#ifdef CONFIG_PAX_KERNEXEC
28260 ++ pax_close_kernel(cr0);
28261 ++#endif
28262 ++
28263 + }
28264 +
28265 + static inline void native_pmd_clear(pmd_t *pmd)
28266 +@@ -158,17 +173,17 @@ static inline void native_pgd_clear(pgd_
28267 +
28268 + static inline int pgd_bad(pgd_t pgd)
28269 + {
28270 +- return (pgd_val(pgd) & ~(PTE_PFN_MASK | _PAGE_USER)) != _KERNPG_TABLE;
28271 ++ return (pgd_val(pgd) & ~(PTE_PFN_MASK | _PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
28272 + }
28273 +
28274 + static inline int pud_bad(pud_t pud)
28275 + {
28276 +- return (pud_val(pud) & ~(PTE_PFN_MASK | _PAGE_USER)) != _KERNPG_TABLE;
28277 ++ return (pud_val(pud) & ~(PTE_PFN_MASK | _PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
28278 + }
28279 +
28280 + static inline int pmd_bad(pmd_t pmd)
28281 + {
28282 +- return (pmd_val(pmd) & ~(PTE_PFN_MASK | _PAGE_USER)) != _KERNPG_TABLE;
28283 ++ return (pmd_val(pmd) & ~(PTE_PFN_MASK | _PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
28284 + }
28285 +
28286 + #define pte_none(x) (!pte_val((x)))
28287 +diff -urNp linux-2.6.27.10/include/asm-x86/pgtable.h linux-2.6.27.10/include/asm-x86/pgtable.h
28288 +--- linux-2.6.27.10/include/asm-x86/pgtable.h 2008-11-07 12:55:34.000000000 -0500
28289 ++++ linux-2.6.27.10/include/asm-x86/pgtable.h 2008-11-18 03:38:45.000000000 -0500
28290 +@@ -41,7 +41,7 @@
28291 + #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
28292 + #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
28293 + #else
28294 +-#define _PAGE_NX (_AT(pteval_t, 0))
28295 ++#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED3)
28296 + #endif
28297 +
28298 + /* If _PAGE_PRESENT is clear, we use these: */
28299 +@@ -81,6 +81,9 @@
28300 + #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
28301 + _PAGE_ACCESSED)
28302 +
28303 ++#define PAGE_READONLY_NOEXEC PAGE_READONLY
28304 ++#define PAGE_SHARED_NOEXEC PAGE_SHARED
28305 ++
28306 + #define __PAGE_KERNEL_EXEC \
28307 + (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
28308 + #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
28309 +@@ -92,7 +95,7 @@
28310 + #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
28311 + #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
28312 + #define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
28313 +-#define __PAGE_KERNEL_VSYSCALL_NOCACHE (__PAGE_KERNEL_VSYSCALL | _PAGE_PCD | _PAGE_PWT)
28314 ++#define __PAGE_KERNEL_VSYSCALL_NOCACHE (__PAGE_KERNEL_RO | _PAGE_PCD | _PAGE_PWT | _PAGE_USER)
28315 + #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
28316 + #define __PAGE_KERNEL_LARGE_NOCACHE (__PAGE_KERNEL | _PAGE_CACHE_UC | _PAGE_PSE)
28317 + #define __PAGE_KERNEL_LARGE_EXEC (__PAGE_KERNEL_EXEC | _PAGE_PSE)
28318 +@@ -142,10 +145,17 @@ extern unsigned long empty_zero_page[PAG
28319 + extern spinlock_t pgd_lock;
28320 + extern struct list_head pgd_list;
28321 +
28322 ++extern pteval_t __supported_pte_mask;
28323 ++
28324 + /*
28325 + * The following only work if pte_present() is true.
28326 + * Undefined behaviour if not..
28327 + */
28328 ++static inline int pte_user(pte_t pte)
28329 ++{
28330 ++ return pte_val(pte) & _PAGE_USER;
28331 ++}
28332 ++
28333 + static inline int pte_dirty(pte_t pte)
28334 + {
28335 + return pte_flags(pte) & _PAGE_DIRTY;
28336 +@@ -207,9 +217,29 @@ static inline pte_t pte_wrprotect(pte_t
28337 + return __pte(pte_val(pte) & ~_PAGE_RW);
28338 + }
28339 +
28340 ++static inline pte_t pte_mkread(pte_t pte)
28341 ++{
28342 ++ return __pte(pte_val(pte) | _PAGE_USER);
28343 ++}
28344 ++
28345 + static inline pte_t pte_mkexec(pte_t pte)
28346 + {
28347 +- return __pte(pte_val(pte) & ~_PAGE_NX);
28348 ++#ifdef CONFIG_X86_PAE
28349 ++ if (__supported_pte_mask & _PAGE_NX)
28350 ++ return __pte(pte_val(pte) & ~(pteval_t)_PAGE_NX);
28351 ++ else
28352 ++#endif
28353 ++ return __pte(pte_val(pte) | _PAGE_USER);
28354 ++}
28355 ++
28356 ++static inline pte_t pte_exprotect(pte_t pte)
28357 ++{
28358 ++#ifdef CONFIG_X86_PAE
28359 ++ if (__supported_pte_mask & _PAGE_NX)
28360 ++ return __pte(pte_val(pte) | _PAGE_NX);
28361 ++ else
28362 ++#endif
28363 ++ return __pte(pte_val(pte) & ~_PAGE_USER);
28364 + }
28365 +
28366 + static inline pte_t pte_mkdirty(pte_t pte)
28367 +@@ -252,8 +282,6 @@ static inline pte_t pte_mkspecial(pte_t
28368 + return __pte(pte_val(pte) | _PAGE_SPECIAL);
28369 + }
28370 +
28371 +-extern pteval_t __supported_pte_mask;
28372 +-
28373 + static inline pte_t pfn_pte(unsigned long page_nr, pgprot_t pgprot)
28374 + {
28375 + return __pte((((phys_addr_t)page_nr << PAGE_SHIFT) |
28376 +@@ -514,7 +542,19 @@ static inline void ptep_set_wrprotect(st
28377 + */
28378 + static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
28379 + {
28380 +- memcpy(dst, src, count * sizeof(pgd_t));
28381 ++
28382 ++#ifdef CONFIG_PAX_KERNEXEC
28383 ++ unsigned long cr0;
28384 ++
28385 ++ pax_open_kernel(cr0);
28386 ++#endif
28387 ++
28388 ++ memcpy(dst, src, count * sizeof(pgd_t));
28389 ++
28390 ++#ifdef CONFIG_PAX_KERNEXEC
28391 ++ pax_close_kernel(cr0);
28392 ++#endif
28393 ++
28394 + }
28395 +
28396 +
28397 +diff -urNp linux-2.6.27.10/include/asm-x86/processor.h linux-2.6.27.10/include/asm-x86/processor.h
28398 +--- linux-2.6.27.10/include/asm-x86/processor.h 2008-11-07 12:55:34.000000000 -0500
28399 ++++ linux-2.6.27.10/include/asm-x86/processor.h 2008-11-18 03:38:45.000000000 -0500
28400 +@@ -269,7 +269,7 @@ struct tss_struct {
28401 +
28402 + } ____cacheline_aligned;
28403 +
28404 +-DECLARE_PER_CPU(struct tss_struct, init_tss);
28405 ++extern struct tss_struct init_tss[NR_CPUS];
28406 +
28407 + /*
28408 + * Save the original ist values for checking stack pointers during debugging
28409 +@@ -832,11 +832,20 @@ static inline void spin_lock_prefetch(co
28410 + * User space process size: 3GB (default).
28411 + */
28412 + #define TASK_SIZE PAGE_OFFSET
28413 ++
28414 ++#ifdef CONFIG_PAX_SEGMEXEC
28415 ++#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
28416 ++#endif
28417 ++
28418 ++#ifdef CONFIG_PAX_SEGMEXEC
28419 ++#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
28420 ++#else
28421 + #define STACK_TOP TASK_SIZE
28422 +-#define STACK_TOP_MAX STACK_TOP
28423 ++#endif
28424 ++#define STACK_TOP_MAX TASK_SIZE
28425 +
28426 + #define INIT_THREAD { \
28427 +- .sp0 = sizeof(init_stack) + (long)&init_stack, \
28428 ++ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
28429 + .vm86_info = NULL, \
28430 + .sysenter_cs = __KERNEL_CS, \
28431 + .io_bitmap_ptr = NULL, \
28432 +@@ -851,7 +860,7 @@ static inline void spin_lock_prefetch(co
28433 + */
28434 + #define INIT_TSS { \
28435 + .x86_tss = { \
28436 +- .sp0 = sizeof(init_stack) + (long)&init_stack, \
28437 ++ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
28438 + .ss0 = __KERNEL_DS, \
28439 + .ss1 = __KERNEL_CS, \
28440 + .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
28441 +@@ -862,11 +871,7 @@ static inline void spin_lock_prefetch(co
28442 + extern unsigned long thread_saved_pc(struct task_struct *tsk);
28443 +
28444 + #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
28445 +-#define KSTK_TOP(info) \
28446 +-({ \
28447 +- unsigned long *__ptr = (unsigned long *)(info); \
28448 +- (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
28449 +-})
28450 ++#define KSTK_TOP(info) ((info)->task.thread.sp0)
28451 +
28452 + /*
28453 + * The below -8 is to reserve 8 bytes on top of the ring0 stack.
28454 +@@ -881,7 +886,7 @@ extern unsigned long thread_saved_pc(str
28455 + #define task_pt_regs(task) \
28456 + ({ \
28457 + struct pt_regs *__regs__; \
28458 +- __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
28459 ++ __regs__ = (struct pt_regs *)((task)->thread.sp0); \
28460 + __regs__ - 1; \
28461 + })
28462 +
28463 +@@ -897,7 +902,7 @@ extern unsigned long thread_saved_pc(str
28464 + * space during mmap's.
28465 + */
28466 + #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
28467 +- 0xc0000000 : 0xFFFFe000)
28468 ++ 0xc0000000 : 0xFFFFf000)
28469 +
28470 + #define TASK_SIZE (test_thread_flag(TIF_IA32) ? \
28471 + IA32_PAGE_OFFSET : TASK_SIZE64)
28472 +@@ -934,6 +939,10 @@ extern void start_thread(struct pt_regs
28473 + */
28474 + #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
28475 +
28476 ++#ifdef CONFIG_PAX_SEGMEXEC
28477 ++#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
28478 ++#endif
28479 ++
28480 + #define KSTK_EIP(task) (task_pt_regs(task)->ip)
28481 +
28482 + /* Get/set a process' ability to use the timestamp counter instruction */
28483 +diff -urNp linux-2.6.27.10/include/asm-x86/ptrace.h linux-2.6.27.10/include/asm-x86/ptrace.h
28484 +--- linux-2.6.27.10/include/asm-x86/ptrace.h 2008-11-07 12:55:34.000000000 -0500
28485 ++++ linux-2.6.27.10/include/asm-x86/ptrace.h 2008-11-18 03:38:45.000000000 -0500
28486 +@@ -131,6 +131,7 @@ struct pt_regs {
28487 +
28488 + /* the DS BTS struct is used for ptrace as well */
28489 + #include <asm/ds.h>
28490 ++#include <asm/segment.h>
28491 +
28492 + struct task_struct;
28493 +
28494 +@@ -154,28 +155,29 @@ static inline unsigned long regs_return_
28495 + }
28496 +
28497 + /*
28498 +- * user_mode_vm(regs) determines whether a register set came from user mode.
28499 ++ * user_mode(regs) determines whether a register set came from user mode.
28500 + * This is true if V8086 mode was enabled OR if the register set was from
28501 + * protected mode with RPL-3 CS value. This tricky test checks that with
28502 + * one comparison. Many places in the kernel can bypass this full check
28503 +- * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
28504 ++ * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
28505 ++ * be used.
28506 + */
28507 +-static inline int user_mode(struct pt_regs *regs)
28508 ++static inline int user_mode_novm(struct pt_regs *regs)
28509 + {
28510 + #ifdef CONFIG_X86_32
28511 + return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
28512 + #else
28513 +- return !!(regs->cs & 3);
28514 ++ return !!(regs->cs & SEGMENT_RPL_MASK);
28515 + #endif
28516 + }
28517 +
28518 +-static inline int user_mode_vm(struct pt_regs *regs)
28519 ++static inline int user_mode(struct pt_regs *regs)
28520 + {
28521 + #ifdef CONFIG_X86_32
28522 + return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
28523 + USER_RPL;
28524 + #else
28525 +- return user_mode(regs);
28526 ++ return user_mode_novm(regs);
28527 + #endif
28528 + }
28529 +
28530 +diff -urNp linux-2.6.27.10/include/asm-x86/reboot.h linux-2.6.27.10/include/asm-x86/reboot.h
28531 +--- linux-2.6.27.10/include/asm-x86/reboot.h 2008-11-07 12:55:34.000000000 -0500
28532 ++++ linux-2.6.27.10/include/asm-x86/reboot.h 2008-11-18 03:38:45.000000000 -0500
28533 +@@ -16,6 +16,6 @@ extern struct machine_ops machine_ops;
28534 +
28535 + void native_machine_crash_shutdown(struct pt_regs *regs);
28536 + void native_machine_shutdown(void);
28537 +-void machine_real_restart(const unsigned char *code, int length);
28538 ++void machine_real_restart(const unsigned char *code, unsigned int length);
28539 +
28540 + #endif /* _ASM_REBOOT_H */
28541 +diff -urNp linux-2.6.27.10/include/asm-x86/rwsem.h linux-2.6.27.10/include/asm-x86/rwsem.h
28542 +--- linux-2.6.27.10/include/asm-x86/rwsem.h 2008-11-07 12:55:34.000000000 -0500
28543 ++++ linux-2.6.27.10/include/asm-x86/rwsem.h 2008-11-18 03:38:45.000000000 -0500
28544 +@@ -106,10 +106,26 @@ static inline void __down_read(struct rw
28545 + {
28546 + asm volatile("# beginning down_read\n\t"
28547 + LOCK_PREFIX " incl (%%eax)\n\t"
28548 ++
28549 ++#ifdef CONFIG_PAX_REFCOUNT
28550 ++#ifdef CONFIG_X86_32
28551 ++ "into\n0:\n"
28552 ++#else
28553 ++ "jno 0f\n"
28554 ++ "int $4\n0:\n"
28555 ++#endif
28556 ++ ".pushsection .fixup,\"ax\"\n"
28557 ++ "1:\n"
28558 ++ LOCK_PREFIX "decl (%%eax)\n"
28559 ++ "jmp 0b\n"
28560 ++ ".popsection\n"
28561 ++ _ASM_EXTABLE(0b, 1b)
28562 ++#endif
28563 ++
28564 + /* adds 0x00000001, returns the old value */
28565 +- " jns 1f\n"
28566 ++ " jns 2f\n"
28567 + " call call_rwsem_down_read_failed\n"
28568 +- "1:\n\t"
28569 ++ "2:\n\t"
28570 + "# ending down_read\n\t"
28571 + : "+m" (sem->count)
28572 + : "a" (sem)
28573 +@@ -124,13 +140,29 @@ static inline int __down_read_trylock(st
28574 + __s32 result, tmp;
28575 + asm volatile("# beginning __down_read_trylock\n\t"
28576 + " movl %0,%1\n\t"
28577 +- "1:\n\t"
28578 ++ "2:\n\t"
28579 + " movl %1,%2\n\t"
28580 + " addl %3,%2\n\t"
28581 +- " jle 2f\n\t"
28582 ++
28583 ++#ifdef CONFIG_PAX_REFCOUNT
28584 ++#ifdef CONFIG_X86_32
28585 ++ "into\n0:\n"
28586 ++#else
28587 ++ "jno 0f\n"
28588 ++ "int $4\n0:\n"
28589 ++#endif
28590 ++ ".pushsection .fixup,\"ax\"\n"
28591 ++ "1:\n"
28592 ++ "subl %3,%2\n"
28593 ++ "jmp 0b\n"
28594 ++ ".popsection\n"
28595 ++ _ASM_EXTABLE(0b, 1b)
28596 ++#endif
28597 ++
28598 ++ " jle 3f\n\t"
28599 + LOCK_PREFIX " cmpxchgl %2,%0\n\t"
28600 +- " jnz 1b\n\t"
28601 +- "2:\n\t"
28602 ++ " jnz 2b\n\t"
28603 ++ "3:\n\t"
28604 + "# ending __down_read_trylock\n\t"
28605 + : "+m" (sem->count), "=&a" (result), "=&r" (tmp)
28606 + : "i" (RWSEM_ACTIVE_READ_BIAS)
28607 +@@ -148,12 +180,28 @@ static inline void __down_write_nested(s
28608 + tmp = RWSEM_ACTIVE_WRITE_BIAS;
28609 + asm volatile("# beginning down_write\n\t"
28610 + LOCK_PREFIX " xadd %%edx,(%%eax)\n\t"
28611 ++
28612 ++#ifdef CONFIG_PAX_REFCOUNT
28613 ++#ifdef CONFIG_X86_32
28614 ++ "into\n0:\n"
28615 ++#else
28616 ++ "jno 0f\n"
28617 ++ "int $4\n0:\n"
28618 ++#endif
28619 ++ ".pushsection .fixup,\"ax\"\n"
28620 ++ "1:\n"
28621 ++ "movl %%edx,(%%eax)\n"
28622 ++ "jmp 0b\n"
28623 ++ ".popsection\n"
28624 ++ _ASM_EXTABLE(0b, 1b)
28625 ++#endif
28626 ++
28627 + /* subtract 0x0000ffff, returns the old value */
28628 + " testl %%edx,%%edx\n\t"
28629 + /* was the count 0 before? */
28630 +- " jz 1f\n"
28631 ++ " jz 2f\n"
28632 + " call call_rwsem_down_write_failed\n"
28633 +- "1:\n"
28634 ++ "2:\n"
28635 + "# ending down_write"
28636 + : "+m" (sem->count), "=d" (tmp)
28637 + : "a" (sem), "1" (tmp)
28638 +@@ -186,10 +234,26 @@ static inline void __up_read(struct rw_s
28639 + __s32 tmp = -RWSEM_ACTIVE_READ_BIAS;
28640 + asm volatile("# beginning __up_read\n\t"
28641 + LOCK_PREFIX " xadd %%edx,(%%eax)\n\t"
28642 ++
28643 ++#ifdef CONFIG_PAX_REFCOUNT
28644 ++#ifdef CONFIG_X86_32
28645 ++ "into\n0:\n"
28646 ++#else
28647 ++ "jno 0f\n"
28648 ++ "int $4\n0:\n"
28649 ++#endif
28650 ++ ".pushsection .fixup,\"ax\"\n"
28651 ++ "1:\n"
28652 ++ "movl %%edx,(%%eax)\n"
28653 ++ "jmp 0b\n"
28654 ++ ".popsection\n"
28655 ++ _ASM_EXTABLE(0b, 1b)
28656 ++#endif
28657 ++
28658 + /* subtracts 1, returns the old value */
28659 +- " jns 1f\n\t"
28660 ++ " jns 2f\n\t"
28661 + " call call_rwsem_wake\n"
28662 +- "1:\n"
28663 ++ "2:\n"
28664 + "# ending __up_read\n"
28665 + : "+m" (sem->count), "=d" (tmp)
28666 + : "a" (sem), "1" (tmp)
28667 +@@ -204,11 +268,27 @@ static inline void __up_write(struct rw_
28668 + asm volatile("# beginning __up_write\n\t"
28669 + " movl %2,%%edx\n\t"
28670 + LOCK_PREFIX " xaddl %%edx,(%%eax)\n\t"
28671 ++
28672 ++#ifdef CONFIG_PAX_REFCOUNT
28673 ++#ifdef CONFIG_X86_32
28674 ++ "into\n0:\n"
28675 ++#else
28676 ++ "jno 0f\n"
28677 ++ "int $4\n0:\n"
28678 ++#endif
28679 ++ ".pushsection .fixup,\"ax\"\n"
28680 ++ "1:\n"
28681 ++ "movl %%edx,(%%eax)\n"
28682 ++ "jmp 0b\n"
28683 ++ ".popsection\n"
28684 ++ _ASM_EXTABLE(0b, 1b)
28685 ++#endif
28686 ++
28687 + /* tries to transition
28688 + 0xffff0001 -> 0x00000000 */
28689 +- " jz 1f\n"
28690 ++ " jz 2f\n"
28691 + " call call_rwsem_wake\n"
28692 +- "1:\n\t"
28693 ++ "2:\n\t"
28694 + "# ending __up_write\n"
28695 + : "+m" (sem->count)
28696 + : "a" (sem), "i" (-RWSEM_ACTIVE_WRITE_BIAS)
28697 +@@ -222,10 +302,26 @@ static inline void __downgrade_write(str
28698 + {
28699 + asm volatile("# beginning __downgrade_write\n\t"
28700 + LOCK_PREFIX " addl %2,(%%eax)\n\t"
28701 ++
28702 ++#ifdef CONFIG_PAX_REFCOUNT
28703 ++#ifdef CONFIG_X86_32
28704 ++ "into\n0:\n"
28705 ++#else
28706 ++ "jno 0f\n"
28707 ++ "int $4\n0:\n"
28708 ++#endif
28709 ++ ".pushsection .fixup,\"ax\"\n"
28710 ++ "1:\n"
28711 ++ LOCK_PREFIX "subl %2,(%%eax)\n"
28712 ++ "jmp 0b\n"
28713 ++ ".popsection\n"
28714 ++ _ASM_EXTABLE(0b, 1b)
28715 ++#endif
28716 ++
28717 + /* transitions 0xZZZZ0001 -> 0xYYYY0001 */
28718 +- " jns 1f\n\t"
28719 ++ " jns 2f\n\t"
28720 + " call call_rwsem_downgrade_wake\n"
28721 +- "1:\n\t"
28722 ++ "2:\n\t"
28723 + "# ending __downgrade_write\n"
28724 + : "+m" (sem->count)
28725 + : "a" (sem), "i" (-RWSEM_WAITING_BIAS)
28726 +@@ -237,7 +333,23 @@ static inline void __downgrade_write(str
28727 + */
28728 + static inline void rwsem_atomic_add(int delta, struct rw_semaphore *sem)
28729 + {
28730 +- asm volatile(LOCK_PREFIX "addl %1,%0"
28731 ++ asm volatile(LOCK_PREFIX "addl %1,%0\n"
28732 ++
28733 ++#ifdef CONFIG_PAX_REFCOUNT
28734 ++#ifdef CONFIG_X86_32
28735 ++ "into\n0:\n"
28736 ++#else
28737 ++ "jno 0f\n"
28738 ++ "int $4\n0:\n"
28739 ++#endif
28740 ++ ".pushsection .fixup,\"ax\"\n"
28741 ++ "1:\n"
28742 ++ LOCK_PREFIX "subl %1,%0\n"
28743 ++ "jmp 0b\n"
28744 ++ ".popsection\n"
28745 ++ _ASM_EXTABLE(0b, 1b)
28746 ++#endif
28747 ++
28748 + : "+m" (sem->count)
28749 + : "ir" (delta));
28750 + }
28751 +@@ -249,7 +361,23 @@ static inline int rwsem_atomic_update(in
28752 + {
28753 + int tmp = delta;
28754 +
28755 +- asm volatile(LOCK_PREFIX "xadd %0,%1"
28756 ++ asm volatile(LOCK_PREFIX "xadd %0,%1\n"
28757 ++
28758 ++#ifdef CONFIG_PAX_REFCOUNT
28759 ++#ifdef CONFIG_X86_32
28760 ++ "into\n0:\n"
28761 ++#else
28762 ++ "jno 0f\n"
28763 ++ "int $4\n0:\n"
28764 ++#endif
28765 ++ ".pushsection .fixup,\"ax\"\n"
28766 ++ "1:\n"
28767 ++ "movl %0,%1\n"
28768 ++ "jmp 0b\n"
28769 ++ ".popsection\n"
28770 ++ _ASM_EXTABLE(0b, 1b)
28771 ++#endif
28772 ++
28773 + : "+r" (tmp), "+m" (sem->count)
28774 + : : "memory");
28775 +
28776 +diff -urNp linux-2.6.27.10/include/asm-x86/segment.h linux-2.6.27.10/include/asm-x86/segment.h
28777 +--- linux-2.6.27.10/include/asm-x86/segment.h 2008-11-07 12:55:34.000000000 -0500
28778 ++++ linux-2.6.27.10/include/asm-x86/segment.h 2008-11-18 03:38:45.000000000 -0500
28779 +@@ -88,13 +88,19 @@
28780 + #define GDT_ENTRY_ESPFIX_SS (GDT_ENTRY_KERNEL_BASE + 14)
28781 + #define __ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)
28782 +
28783 +-#define GDT_ENTRY_PERCPU (GDT_ENTRY_KERNEL_BASE + 15)
28784 ++#define GDT_ENTRY_PERCPU (GDT_ENTRY_KERNEL_BASE + 15)
28785 + #ifdef CONFIG_SMP
28786 + #define __KERNEL_PERCPU (GDT_ENTRY_PERCPU * 8)
28787 + #else
28788 + #define __KERNEL_PERCPU 0
28789 + #endif
28790 +
28791 ++#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE + 16)
28792 ++#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
28793 ++
28794 ++#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE + 17)
28795 ++#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
28796 ++
28797 + #define GDT_ENTRY_DOUBLEFAULT_TSS 31
28798 +
28799 + /*
28800 +@@ -135,10 +141,10 @@
28801 + #define SEGMENT_IS_KERNEL_CODE(x) (((x) & 0xfc) == GDT_ENTRY_KERNEL_CS * 8)
28802 +
28803 + /* Matches __KERNEL_CS and __USER_CS (they must be 2 entries apart) */
28804 +-#define SEGMENT_IS_FLAT_CODE(x) (((x) & 0xec) == GDT_ENTRY_KERNEL_CS * 8)
28805 ++#define SEGMENT_IS_FLAT_CODE(x) (((x) & 0xFFFCU) == __KERNEL_CS || ((x) & 0xFFFCU) == __USER_CS)
28806 +
28807 + /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
28808 +-#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
28809 ++#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
28810 +
28811 +
28812 + #else
28813 +diff -urNp linux-2.6.27.10/include/asm-x86/spinlock.h linux-2.6.27.10/include/asm-x86/spinlock.h
28814 +--- linux-2.6.27.10/include/asm-x86/spinlock.h 2008-11-07 12:55:34.000000000 -0500
28815 ++++ linux-2.6.27.10/include/asm-x86/spinlock.h 2008-11-18 03:38:45.000000000 -0500
28816 +@@ -315,18 +315,50 @@ static inline int __raw_write_can_lock(r
28817 + static inline void __raw_read_lock(raw_rwlock_t *rw)
28818 + {
28819 + asm volatile(LOCK_PREFIX " subl $1,(%0)\n\t"
28820 +- "jns 1f\n"
28821 +- "call __read_lock_failed\n\t"
28822 ++
28823 ++#ifdef CONFIG_PAX_REFCOUNT
28824 ++#ifdef CONFIG_X86_32
28825 ++ "into\n0:\n"
28826 ++#else
28827 ++ "jno 0f\n"
28828 ++ "int $4\n0:\n"
28829 ++#endif
28830 ++ ".pushsection .fixup,\"ax\"\n"
28831 + "1:\n"
28832 ++ LOCK_PREFIX " addl $1,(%0)\n"
28833 ++ "jmp 0b\n"
28834 ++ ".popsection\n"
28835 ++ _ASM_EXTABLE(0b, 1b)
28836 ++#endif
28837 ++
28838 ++ "jns 2f\n"
28839 ++ "call __read_lock_failed\n\t"
28840 ++ "2:\n"
28841 + ::LOCK_PTR_REG (rw) : "memory");
28842 + }
28843 +
28844 + static inline void __raw_write_lock(raw_rwlock_t *rw)
28845 + {
28846 + asm volatile(LOCK_PREFIX " subl %1,(%0)\n\t"
28847 +- "jz 1f\n"
28848 +- "call __write_lock_failed\n\t"
28849 ++
28850 ++#ifdef CONFIG_PAX_REFCOUNT
28851 ++#ifdef CONFIG_X86_32
28852 ++ "into\n0:\n"
28853 ++#else
28854 ++ "jno 0f\n"
28855 ++ "int $4\n0:\n"
28856 ++#endif
28857 ++ ".pushsection .fixup,\"ax\"\n"
28858 + "1:\n"
28859 ++ LOCK_PREFIX " addl %1,(%0)\n"
28860 ++ "jmp 0b\n"
28861 ++ ".popsection\n"
28862 ++ _ASM_EXTABLE(0b, 1b)
28863 ++#endif
28864 ++
28865 ++ "jz 2f\n"
28866 ++ "call __write_lock_failed\n\t"
28867 ++ "2:\n"
28868 + ::LOCK_PTR_REG (rw), "i" (RW_LOCK_BIAS) : "memory");
28869 + }
28870 +
28871 +@@ -353,12 +385,45 @@ static inline int __raw_write_trylock(ra
28872 +
28873 + static inline void __raw_read_unlock(raw_rwlock_t *rw)
28874 + {
28875 +- asm volatile(LOCK_PREFIX "incl %0" :"+m" (rw->lock) : : "memory");
28876 ++ asm volatile(LOCK_PREFIX "incl %0\n"
28877 ++
28878 ++#ifdef CONFIG_PAX_REFCOUNT
28879 ++#ifdef CONFIG_X86_32
28880 ++ "into\n0:\n"
28881 ++#else
28882 ++ "jno 0f\n"
28883 ++ "int $4\n0:\n"
28884 ++#endif
28885 ++ ".pushsection .fixup,\"ax\"\n"
28886 ++ "1:\n"
28887 ++ LOCK_PREFIX "decl %0\n"
28888 ++ "jmp 0b\n"
28889 ++ ".popsection\n"
28890 ++ _ASM_EXTABLE(0b, 1b)
28891 ++#endif
28892 ++
28893 ++ :"+m" (rw->lock) : : "memory");
28894 + }
28895 +
28896 + static inline void __raw_write_unlock(raw_rwlock_t *rw)
28897 + {
28898 +- asm volatile(LOCK_PREFIX "addl %1, %0"
28899 ++ asm volatile(LOCK_PREFIX "addl %1, %0\n"
28900 ++
28901 ++#ifdef CONFIG_PAX_REFCOUNT
28902 ++#ifdef CONFIG_X86_32
28903 ++ "into\n0:\n"
28904 ++#else
28905 ++ "jno 0f\n"
28906 ++ "int $4\n0:\n"
28907 ++#endif
28908 ++ ".pushsection .fixup,\"ax\"\n"
28909 ++ "1:\n"
28910 ++ LOCK_PREFIX "subl %1,%0\n"
28911 ++ "jmp 0b\n"
28912 ++ ".popsection\n"
28913 ++ _ASM_EXTABLE(0b, 1b)
28914 ++#endif
28915 ++
28916 + : "+m" (rw->lock) : "i" (RW_LOCK_BIAS) : "memory");
28917 + }
28918 +
28919 +diff -urNp linux-2.6.27.10/include/asm-x86/system.h linux-2.6.27.10/include/asm-x86/system.h
28920 +--- linux-2.6.27.10/include/asm-x86/system.h 2008-11-07 12:55:34.000000000 -0500
28921 ++++ linux-2.6.27.10/include/asm-x86/system.h 2008-11-18 03:38:45.000000000 -0500
28922 +@@ -92,6 +92,8 @@ do { \
28923 + ".globl thread_return\n" \
28924 + "thread_return:\n\t" \
28925 + "movq %%gs:%P[pda_pcurrent],%%rsi\n\t" \
28926 ++ "movq %P[task_canary](%%rsi),%%r8\n\t" \
28927 ++ "movq %%r8,%%gs:%P[pda_canary]\n\t" \
28928 + "movq %P[thread_info](%%rsi),%%r8\n\t" \
28929 + LOCK_PREFIX "btr %[tif_fork],%P[ti_flags](%%r8)\n\t" \
28930 + "movq %%rax,%%rdi\n\t" \
28931 +@@ -103,7 +105,9 @@ do { \
28932 + [ti_flags] "i" (offsetof(struct thread_info, flags)), \
28933 + [tif_fork] "i" (TIF_FORK), \
28934 + [thread_info] "i" (offsetof(struct task_struct, stack)), \
28935 +- [pda_pcurrent] "i" (offsetof(struct x8664_pda, pcurrent)) \
28936 ++ [task_canary] "i" (offsetof(struct task_struct, stack_canary)), \
28937 ++ [pda_pcurrent] "i" (offsetof(struct x8664_pda, pcurrent)), \
28938 ++ [pda_canary] "i" (offsetof(struct x8664_pda, stack_canary))\
28939 + : "memory", "cc" __EXTRA_CLOBBER)
28940 + #endif
28941 +
28942 +@@ -166,7 +170,7 @@ static inline unsigned long get_limit(un
28943 + {
28944 + unsigned long __limit;
28945 + asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
28946 +- return __limit + 1;
28947 ++ return __limit;
28948 + }
28949 +
28950 + static inline void native_clts(void)
28951 +@@ -292,6 +296,21 @@ static inline void native_wbinvd(void)
28952 +
28953 + #define stts() write_cr0(read_cr0() | X86_CR0_TS)
28954 +
28955 ++#define pax_open_kernel(cr0) \
28956 ++do { \
28957 ++ typecheck(unsigned long, cr0); \
28958 ++ preempt_disable(); \
28959 ++ cr0 = read_cr0(); \
28960 ++ write_cr0(cr0 & ~X86_CR0_WP); \
28961 ++} while (0)
28962 ++
28963 ++#define pax_close_kernel(cr0) \
28964 ++do { \
28965 ++ typecheck(unsigned long, cr0); \
28966 ++ write_cr0(cr0); \
28967 ++ preempt_enable_no_resched(); \
28968 ++} while (0)
28969 ++
28970 + #endif /* __KERNEL__ */
28971 +
28972 + static inline void clflush(volatile void *__p)
28973 +@@ -306,7 +325,7 @@ void enable_hlt(void);
28974 +
28975 + void cpu_idle_wait(void);
28976 +
28977 +-extern unsigned long arch_align_stack(unsigned long sp);
28978 ++#define arch_align_stack(x) ((x) & ~0xfUL)
28979 + extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
28980 +
28981 + void default_idle(void);
28982 +diff -urNp linux-2.6.27.10/include/asm-x86/uaccess_64.h linux-2.6.27.10/include/asm-x86/uaccess_64.h
28983 +--- linux-2.6.27.10/include/asm-x86/uaccess_64.h 2008-11-07 12:55:34.000000000 -0500
28984 ++++ linux-2.6.27.10/include/asm-x86/uaccess_64.h 2008-11-18 03:38:45.000000000 -0500
28985 +@@ -10,6 +10,8 @@
28986 + #include <linux/lockdep.h>
28987 + #include <asm/page.h>
28988 +
28989 ++#define set_fs(x) (current_thread_info()->addr_limit = (x))
28990 ++
28991 + /*
28992 + * Copy To/From Userspace
28993 + */
28994 +diff -urNp linux-2.6.27.10/include/asm-x86/uaccess.h linux-2.6.27.10/include/asm-x86/uaccess.h
28995 +--- linux-2.6.27.10/include/asm-x86/uaccess.h 2008-11-07 12:55:34.000000000 -0500
28996 ++++ linux-2.6.27.10/include/asm-x86/uaccess.h 2008-11-18 03:38:45.000000000 -0500
28997 +@@ -10,6 +10,7 @@
28998 + #include <linux/string.h>
28999 + #include <asm/asm.h>
29000 + #include <asm/page.h>
29001 ++#include <asm/segment.h>
29002 +
29003 + #define VERIFY_READ 0
29004 + #define VERIFY_WRITE 1
29005 +@@ -29,7 +30,12 @@
29006 +
29007 + #define get_ds() (KERNEL_DS)
29008 + #define get_fs() (current_thread_info()->addr_limit)
29009 ++#ifdef CONFIG_X86_32
29010 ++void __set_fs(mm_segment_t x, int cpu);
29011 ++void set_fs(mm_segment_t x);
29012 ++#else
29013 + #define set_fs(x) (current_thread_info()->addr_limit = (x))
29014 ++#endif
29015 +
29016 + #define segment_eq(a, b) ((a).seg == (b).seg)
29017 +
29018 +@@ -97,6 +103,7 @@ struct exception_table_entry {
29019 + };
29020 +
29021 + extern int fixup_exception(struct pt_regs *regs);
29022 ++#define ARCH_HAS_SORT_EXTABLE
29023 +
29024 + /*
29025 + * These are the main single-value transfer routines. They automatically
29026 +@@ -186,9 +193,12 @@ extern int __get_user_bad(void);
29027 +
29028 + #ifdef CONFIG_X86_32
29029 + #define __put_user_u64(x, addr, err) \
29030 +- asm volatile("1: movl %%eax,0(%2)\n" \
29031 +- "2: movl %%edx,4(%2)\n" \
29032 ++ asm volatile(" movw %w5,%%ds\n" \
29033 ++ "1: movl %%eax,%%ds:0(%2)\n" \
29034 ++ "2: movl %%edx,%%ds:4(%2)\n" \
29035 + "3:\n" \
29036 ++ " pushl %%ss\n" \
29037 ++ " popl %%ds\n" \
29038 + ".section .fixup,\"ax\"\n" \
29039 + "4: movl %3,%0\n" \
29040 + " jmp 3b\n" \
29041 +@@ -196,7 +206,8 @@ extern int __get_user_bad(void);
29042 + _ASM_EXTABLE(1b, 4b) \
29043 + _ASM_EXTABLE(2b, 4b) \
29044 + : "=r" (err) \
29045 +- : "A" (x), "r" (addr), "i" (-EFAULT), "0" (err))
29046 ++ : "A" (x), "r" (addr), "i" (-EFAULT), "0" (err), \
29047 ++ "r"(__USER_DS))
29048 +
29049 + #define __put_user_x8(x, ptr, __ret_pu) \
29050 + asm volatile("call __put_user_8" : "=a" (__ret_pu) \
29051 +@@ -336,6 +347,22 @@ do { \
29052 + } \
29053 + } while (0)
29054 +
29055 ++#ifdef CONFIG_X86_32
29056 ++#define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
29057 ++ asm volatile(" movw %w5,%%ds\n" \
29058 ++ "1: mov"itype" %%ds:%2,%"rtype"1\n" \
29059 ++ "2:\n" \
29060 ++ " pushl %%ss\n" \
29061 ++ " popl %%ds\n" \
29062 ++ ".section .fixup,\"ax\"\n" \
29063 ++ "3: movl %3,%0\n" \
29064 ++ " xor"itype" %"rtype"1,%"rtype"1\n" \
29065 ++ " jmp 2b\n" \
29066 ++ ".previous\n" \
29067 ++ _ASM_EXTABLE(1b, 3b) \
29068 ++ : "=r" (err), ltype (x) \
29069 ++ : "m" (__m(addr)), "i" (errret), "0" (err), "r"(__USER_DS))
29070 ++#else
29071 + #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
29072 + asm volatile("1: mov"itype" %2,%"rtype"1\n" \
29073 + "2:\n" \
29074 +@@ -347,6 +374,7 @@ do { \
29075 + _ASM_EXTABLE(1b, 3b) \
29076 + : "=r" (err), ltype(x) \
29077 + : "m" (__m(addr)), "i" (errret), "0" (err))
29078 ++#endif
29079 +
29080 + #define __put_user_nocheck(x, ptr, size) \
29081 + ({ \
29082 +@@ -373,6 +401,22 @@ struct __large_struct { unsigned long bu
29083 + * we do not write to any memory gcc knows about, so there are no
29084 + * aliasing issues.
29085 + */
29086 ++#ifdef CONFIG_X86_32
29087 ++#define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
29088 ++ asm volatile(" movw %w5,%%ds\n" \
29089 ++ "1: mov"itype" %"rtype"1,%%ds:%2\n" \
29090 ++ "2:\n" \
29091 ++ " pushl %%ss\n" \
29092 ++ " popl %%ds\n" \
29093 ++ ".section .fixup,\"ax\"\n" \
29094 ++ "3: movl %3,%0\n" \
29095 ++ " jmp 2b\n" \
29096 ++ ".previous\n" \
29097 ++ _ASM_EXTABLE(1b, 3b) \
29098 ++ : "=r"(err) \
29099 ++ : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err),\
29100 ++ "r"(__USER_DS))
29101 ++#else
29102 + #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
29103 + asm volatile("1: mov"itype" %"rtype"1,%2\n" \
29104 + "2:\n" \
29105 +@@ -383,6 +427,7 @@ struct __large_struct { unsigned long bu
29106 + _ASM_EXTABLE(1b, 3b) \
29107 + : "=r"(err) \
29108 + : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
29109 ++#endif
29110 + /**
29111 + * __get_user: - Get a simple variable from user space, with less checking.
29112 + * @x: Variable to store result.
29113 +@@ -447,6 +492,7 @@ extern struct movsl_mask {
29114 + # include "uaccess_32.h"
29115 + #else
29116 + # define ARCH_HAS_SEARCH_EXTABLE
29117 ++# define ARCH_HAS_SORT_EXTABLE
29118 + # include "uaccess_64.h"
29119 + #endif
29120 +
29121 +diff -urNp linux-2.6.27.10/include/asm-xtensa/kmap_types.h linux-2.6.27.10/include/asm-xtensa/kmap_types.h
29122 +--- linux-2.6.27.10/include/asm-xtensa/kmap_types.h 2008-11-07 12:55:34.000000000 -0500
29123 ++++ linux-2.6.27.10/include/asm-xtensa/kmap_types.h 2008-11-18 03:38:45.000000000 -0500
29124 +@@ -25,6 +25,7 @@ enum km_type {
29125 + KM_IRQ1,
29126 + KM_SOFTIRQ0,
29127 + KM_SOFTIRQ1,
29128 ++ KM_CLEARPAGE,
29129 + KM_TYPE_NR
29130 + };
29131 +
29132 +diff -urNp linux-2.6.27.10/include/drm/drm_pciids.h linux-2.6.27.10/include/drm/drm_pciids.h
29133 +--- linux-2.6.27.10/include/drm/drm_pciids.h 2008-11-07 12:55:34.000000000 -0500
29134 ++++ linux-2.6.27.10/include/drm/drm_pciids.h 2008-11-18 03:38:45.000000000 -0500
29135 +@@ -237,7 +237,7 @@
29136 + {0x1002, 0x7835, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS300|RADEON_IS_IGP|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \
29137 + {0x1002, 0x791e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS690|RADEON_IS_IGP|RADEON_NEW_MEMMAP|RADEON_IS_IGPGART}, \
29138 + {0x1002, 0x791f, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS690|RADEON_IS_IGP|RADEON_NEW_MEMMAP|RADEON_IS_IGPGART}, \
29139 +- {0, 0, 0}
29140 ++ {0, 0, 0, 0, 0, 0}
29141 +
29142 + #define r128_PCI_IDS \
29143 + {0x1002, 0x4c45, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
29144 +@@ -277,14 +277,14 @@
29145 + {0x1002, 0x5446, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
29146 + {0x1002, 0x544C, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
29147 + {0x1002, 0x5452, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
29148 +- {0, 0, 0}
29149 ++ {0, 0, 0, 0, 0, 0}
29150 +
29151 + #define mga_PCI_IDS \
29152 + {0x102b, 0x0520, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MGA_CARD_TYPE_G200}, \
29153 + {0x102b, 0x0521, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MGA_CARD_TYPE_G200}, \
29154 + {0x102b, 0x0525, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MGA_CARD_TYPE_G400}, \
29155 + {0x102b, 0x2527, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MGA_CARD_TYPE_G550}, \
29156 +- {0, 0, 0}
29157 ++ {0, 0, 0, 0, 0, 0}
29158 +
29159 + #define mach64_PCI_IDS \
29160 + {0x1002, 0x4749, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
29161 +@@ -307,7 +307,7 @@
29162 + {0x1002, 0x4c53, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
29163 + {0x1002, 0x4c4d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
29164 + {0x1002, 0x4c4e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
29165 +- {0, 0, 0}
29166 ++ {0, 0, 0, 0, 0, 0}
29167 +
29168 + #define sisdrv_PCI_IDS \
29169 + {0x1039, 0x0300, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
29170 +@@ -318,7 +318,7 @@
29171 + {0x1039, 0x7300, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
29172 + {0x18CA, 0x0040, PCI_ANY_ID, PCI_ANY_ID, 0, 0, SIS_CHIP_315}, \
29173 + {0x18CA, 0x0042, PCI_ANY_ID, PCI_ANY_ID, 0, 0, SIS_CHIP_315}, \
29174 +- {0, 0, 0}
29175 ++ {0, 0, 0, 0, 0, 0}
29176 +
29177 + #define tdfx_PCI_IDS \
29178 + {0x121a, 0x0003, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
29179 +@@ -327,7 +327,7 @@
29180 + {0x121a, 0x0007, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
29181 + {0x121a, 0x0009, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
29182 + {0x121a, 0x000b, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
29183 +- {0, 0, 0}
29184 ++ {0, 0, 0, 0, 0, 0}
29185 +
29186 + #define viadrv_PCI_IDS \
29187 + {0x1106, 0x3022, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
29188 +@@ -339,25 +339,25 @@
29189 + {0x1106, 0x3343, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
29190 + {0x1106, 0x3230, PCI_ANY_ID, PCI_ANY_ID, 0, 0, VIA_DX9_0}, \
29191 + {0x1106, 0x3157, PCI_ANY_ID, PCI_ANY_ID, 0, 0, VIA_PRO_GROUP_A}, \
29192 +- {0, 0, 0}
29193 ++ {0, 0, 0, 0, 0, 0}
29194 +
29195 + #define i810_PCI_IDS \
29196 + {0x8086, 0x7121, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
29197 + {0x8086, 0x7123, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
29198 + {0x8086, 0x7125, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
29199 + {0x8086, 0x1132, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
29200 +- {0, 0, 0}
29201 ++ {0, 0, 0, 0, 0, 0}
29202 +
29203 + #define i830_PCI_IDS \
29204 + {0x8086, 0x3577, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
29205 + {0x8086, 0x2562, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
29206 + {0x8086, 0x3582, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
29207 + {0x8086, 0x2572, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
29208 +- {0, 0, 0}
29209 ++ {0, 0, 0, 0, 0, 0}
29210 +
29211 + #define gamma_PCI_IDS \
29212 + {0x3d3d, 0x0008, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
29213 +- {0, 0, 0}
29214 ++ {0, 0, 0, 0, 0, 0}
29215 +
29216 + #define savage_PCI_IDS \
29217 + {0x5333, 0x8a20, PCI_ANY_ID, PCI_ANY_ID, 0, 0, S3_SAVAGE3D}, \
29218 +@@ -383,10 +383,10 @@
29219 + {0x5333, 0x8d02, PCI_ANY_ID, PCI_ANY_ID, 0, 0, S3_TWISTER}, \
29220 + {0x5333, 0x8d03, PCI_ANY_ID, PCI_ANY_ID, 0, 0, S3_PROSAVAGEDDR}, \
29221 + {0x5333, 0x8d04, PCI_ANY_ID, PCI_ANY_ID, 0, 0, S3_PROSAVAGEDDR}, \
29222 +- {0, 0, 0}
29223 ++ {0, 0, 0, 0, 0, 0}
29224 +
29225 + #define ffb_PCI_IDS \
29226 +- {0, 0, 0}
29227 ++ {0, 0, 0, 0, 0, 0}
29228 +
29229 + #define i915_PCI_IDS \
29230 + {0x8086, 0x3577, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
29231 +@@ -412,4 +412,4 @@
29232 + {0x8086, 0x2e02, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
29233 + {0x8086, 0x2e12, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
29234 + {0x8086, 0x2e22, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
29235 +- {0, 0, 0}
29236 ++ {0, 0, 0, 0, 0, 0}
29237 +diff -urNp linux-2.6.27.10/include/linux/a.out.h linux-2.6.27.10/include/linux/a.out.h
29238 +--- linux-2.6.27.10/include/linux/a.out.h 2008-11-07 12:55:34.000000000 -0500
29239 ++++ linux-2.6.27.10/include/linux/a.out.h 2008-11-18 03:38:45.000000000 -0500
29240 +@@ -39,6 +39,14 @@ enum machine_type {
29241 + M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
29242 + };
29243 +
29244 ++/* Constants for the N_FLAGS field */
29245 ++#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
29246 ++#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
29247 ++#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
29248 ++#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
29249 ++/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
29250 ++#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
29251 ++
29252 + #if !defined (N_MAGIC)
29253 + #define N_MAGIC(exec) ((exec).a_info & 0xffff)
29254 + #endif
29255 +diff -urNp linux-2.6.27.10/include/linux/binfmts.h linux-2.6.27.10/include/linux/binfmts.h
29256 +--- linux-2.6.27.10/include/linux/binfmts.h 2008-12-21 01:16:52.000000000 -0500
29257 ++++ linux-2.6.27.10/include/linux/binfmts.h 2008-12-21 01:13:46.000000000 -0500
29258 +@@ -71,6 +71,7 @@ struct linux_binfmt {
29259 + int (*load_binary)(struct linux_binprm *, struct pt_regs * regs);
29260 + int (*load_shlib)(struct file *);
29261 + int (*core_dump)(long signr, struct pt_regs *regs, struct file *file, unsigned long limit);
29262 ++ void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
29263 + unsigned long min_coredump; /* minimal dump size */
29264 + int hasvdso;
29265 + };
29266 +diff -urNp linux-2.6.27.10/include/linux/cache.h linux-2.6.27.10/include/linux/cache.h
29267 +--- linux-2.6.27.10/include/linux/cache.h 2008-11-07 12:55:34.000000000 -0500
29268 ++++ linux-2.6.27.10/include/linux/cache.h 2008-11-18 03:38:45.000000000 -0500
29269 +@@ -16,6 +16,10 @@
29270 + #define __read_mostly
29271 + #endif
29272 +
29273 ++#ifndef __read_only
29274 ++#define __read_only __read_mostly
29275 ++#endif
29276 ++
29277 + #ifndef ____cacheline_aligned
29278 + #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
29279 + #endif
29280 +diff -urNp linux-2.6.27.10/include/linux/capability.h linux-2.6.27.10/include/linux/capability.h
29281 +--- linux-2.6.27.10/include/linux/capability.h 2008-11-07 12:55:34.000000000 -0500
29282 ++++ linux-2.6.27.10/include/linux/capability.h 2008-11-18 03:38:45.000000000 -0500
29283 +@@ -516,6 +516,7 @@ kernel_cap_t cap_set_effective(const ker
29284 + #define has_capability(t, cap) (security_capable((t), (cap)) == 0)
29285 +
29286 + extern int capable(int cap);
29287 ++int capable_nolog(int cap);
29288 +
29289 + #endif /* __KERNEL__ */
29290 +
29291 +diff -urNp linux-2.6.27.10/include/linux/cpumask.h linux-2.6.27.10/include/linux/cpumask.h
29292 +--- linux-2.6.27.10/include/linux/cpumask.h 2008-11-07 12:55:34.000000000 -0500
29293 ++++ linux-2.6.27.10/include/linux/cpumask.h 2008-11-18 03:38:45.000000000 -0500
29294 +@@ -139,7 +139,6 @@
29295 + #include <linux/bitmap.h>
29296 +
29297 + typedef struct { DECLARE_BITMAP(bits, NR_CPUS); } cpumask_t;
29298 +-extern cpumask_t _unused_cpumask_arg_;
29299 +
29300 + #define cpu_set(cpu, dst) __cpu_set((cpu), &(dst))
29301 + static inline void __cpu_set(int cpu, volatile cpumask_t *dstp)
29302 +diff -urNp linux-2.6.27.10/include/linux/elf.h linux-2.6.27.10/include/linux/elf.h
29303 +--- linux-2.6.27.10/include/linux/elf.h 2008-11-07 12:55:34.000000000 -0500
29304 ++++ linux-2.6.27.10/include/linux/elf.h 2008-12-21 00:44:29.000000000 -0500
29305 +@@ -49,6 +49,17 @@ typedef __s64 Elf64_Sxword;
29306 + #define PT_GNU_EH_FRAME 0x6474e550
29307 +
29308 + #define PT_GNU_STACK (PT_LOOS + 0x474e551)
29309 ++#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
29310 ++
29311 ++#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
29312 ++
29313 ++/* Constants for the e_flags field */
29314 ++#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
29315 ++#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
29316 ++#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
29317 ++#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
29318 ++/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
29319 ++#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
29320 +
29321 + /* These constants define the different elf file types */
29322 + #define ET_NONE 0
29323 +@@ -84,6 +95,8 @@ typedef __s64 Elf64_Sxword;
29324 + #define DT_DEBUG 21
29325 + #define DT_TEXTREL 22
29326 + #define DT_JMPREL 23
29327 ++#define DT_FLAGS 30
29328 ++ #define DF_TEXTREL 0x00000004
29329 + #define DT_ENCODING 32
29330 + #define OLD_DT_LOOS 0x60000000
29331 + #define DT_LOOS 0x6000000d
29332 +@@ -230,6 +243,19 @@ typedef struct elf64_hdr {
29333 + #define PF_W 0x2
29334 + #define PF_X 0x1
29335 +
29336 ++#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
29337 ++#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
29338 ++#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
29339 ++#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
29340 ++#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
29341 ++#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
29342 ++/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
29343 ++/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
29344 ++#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
29345 ++#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
29346 ++#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
29347 ++#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
29348 ++
29349 + typedef struct elf32_phdr{
29350 + Elf32_Word p_type;
29351 + Elf32_Off p_offset;
29352 +@@ -322,6 +348,8 @@ typedef struct elf64_shdr {
29353 + #define EI_OSABI 7
29354 + #define EI_PAD 8
29355 +
29356 ++#define EI_PAX 14
29357 ++
29358 + #define ELFMAG0 0x7f /* EI_MAG */
29359 + #define ELFMAG1 'E'
29360 + #define ELFMAG2 'L'
29361 +@@ -383,6 +411,7 @@ extern Elf32_Dyn _DYNAMIC [];
29362 + #define elf_phdr elf32_phdr
29363 + #define elf_note elf32_note
29364 + #define elf_addr_t Elf32_Off
29365 ++#define elf_dyn Elf32_Dyn
29366 +
29367 + #else
29368 +
29369 +@@ -391,6 +420,7 @@ extern Elf64_Dyn _DYNAMIC [];
29370 + #define elf_phdr elf64_phdr
29371 + #define elf_note elf64_note
29372 + #define elf_addr_t Elf64_Off
29373 ++#define elf_dyn Elf64_Dyn
29374 +
29375 + #endif
29376 +
29377 +diff -urNp linux-2.6.27.10/include/linux/gracl.h linux-2.6.27.10/include/linux/gracl.h
29378 +--- linux-2.6.27.10/include/linux/gracl.h 1969-12-31 19:00:00.000000000 -0500
29379 ++++ linux-2.6.27.10/include/linux/gracl.h 2008-11-18 03:38:45.000000000 -0500
29380 +@@ -0,0 +1,318 @@
29381 ++#ifndef GR_ACL_H
29382 ++#define GR_ACL_H
29383 ++
29384 ++#include <linux/grdefs.h>
29385 ++#include <linux/resource.h>
29386 ++#include <linux/capability.h>
29387 ++#include <linux/dcache.h>
29388 ++#include <asm/resource.h>
29389 ++
29390 ++/* Major status information */
29391 ++
29392 ++#define GR_VERSION "grsecurity 2.1.12"
29393 ++#define GRSECURITY_VERSION 0x2112
29394 ++
29395 ++enum {
29396 ++
29397 ++ SHUTDOWN = 0,
29398 ++ ENABLE = 1,
29399 ++ SPROLE = 2,
29400 ++ RELOAD = 3,
29401 ++ SEGVMOD = 4,
29402 ++ STATUS = 5,
29403 ++ UNSPROLE = 6,
29404 ++ PASSSET = 7,
29405 ++ SPROLEPAM = 8
29406 ++};
29407 ++
29408 ++/* Password setup definitions
29409 ++ * kernel/grhash.c */
29410 ++enum {
29411 ++ GR_PW_LEN = 128,
29412 ++ GR_SALT_LEN = 16,
29413 ++ GR_SHA_LEN = 32,
29414 ++};
29415 ++
29416 ++enum {
29417 ++ GR_SPROLE_LEN = 64,
29418 ++};
29419 ++
29420 ++#define GR_NLIMITS (RLIMIT_LOCKS + 2)
29421 ++
29422 ++/* Begin Data Structures */
29423 ++
29424 ++struct sprole_pw {
29425 ++ unsigned char *rolename;
29426 ++ unsigned char salt[GR_SALT_LEN];
29427 ++ unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
29428 ++};
29429 ++
29430 ++struct name_entry {
29431 ++ __u32 key;
29432 ++ ino_t inode;
29433 ++ dev_t device;
29434 ++ char *name;
29435 ++ __u16 len;
29436 ++ __u8 deleted;
29437 ++ struct name_entry *prev;
29438 ++ struct name_entry *next;
29439 ++};
29440 ++
29441 ++struct inodev_entry {
29442 ++ struct name_entry *nentry;
29443 ++ struct inodev_entry *prev;
29444 ++ struct inodev_entry *next;
29445 ++};
29446 ++
29447 ++struct acl_role_db {
29448 ++ struct acl_role_label **r_hash;
29449 ++ __u32 r_size;
29450 ++};
29451 ++
29452 ++struct inodev_db {
29453 ++ struct inodev_entry **i_hash;
29454 ++ __u32 i_size;
29455 ++};
29456 ++
29457 ++struct name_db {
29458 ++ struct name_entry **n_hash;
29459 ++ __u32 n_size;
29460 ++};
29461 ++
29462 ++struct crash_uid {
29463 ++ uid_t uid;
29464 ++ unsigned long expires;
29465 ++};
29466 ++
29467 ++struct gr_hash_struct {
29468 ++ void **table;
29469 ++ void **nametable;
29470 ++ void *first;
29471 ++ __u32 table_size;
29472 ++ __u32 used_size;
29473 ++ int type;
29474 ++};
29475 ++
29476 ++/* Userspace Grsecurity ACL data structures */
29477 ++
29478 ++struct acl_subject_label {
29479 ++ char *filename;
29480 ++ ino_t inode;
29481 ++ dev_t device;
29482 ++ __u32 mode;
29483 ++ kernel_cap_t cap_mask;
29484 ++ kernel_cap_t cap_lower;
29485 ++
29486 ++ struct rlimit res[GR_NLIMITS];
29487 ++ __u16 resmask;
29488 ++
29489 ++ __u8 user_trans_type;
29490 ++ __u8 group_trans_type;
29491 ++ uid_t *user_transitions;
29492 ++ gid_t *group_transitions;
29493 ++ __u16 user_trans_num;
29494 ++ __u16 group_trans_num;
29495 ++
29496 ++ __u32 ip_proto[8];
29497 ++ __u32 ip_type;
29498 ++ struct acl_ip_label **ips;
29499 ++ __u32 ip_num;
29500 ++
29501 ++ __u32 crashes;
29502 ++ unsigned long expires;
29503 ++
29504 ++ struct acl_subject_label *parent_subject;
29505 ++ struct gr_hash_struct *hash;
29506 ++ struct acl_subject_label *prev;
29507 ++ struct acl_subject_label *next;
29508 ++
29509 ++ struct acl_object_label **obj_hash;
29510 ++ __u32 obj_hash_size;
29511 ++ __u16 pax_flags;
29512 ++};
29513 ++
29514 ++struct role_allowed_ip {
29515 ++ __u32 addr;
29516 ++ __u32 netmask;
29517 ++
29518 ++ struct role_allowed_ip *prev;
29519 ++ struct role_allowed_ip *next;
29520 ++};
29521 ++
29522 ++struct role_transition {
29523 ++ char *rolename;
29524 ++
29525 ++ struct role_transition *prev;
29526 ++ struct role_transition *next;
29527 ++};
29528 ++
29529 ++struct acl_role_label {
29530 ++ char *rolename;
29531 ++ uid_t uidgid;
29532 ++ __u16 roletype;
29533 ++
29534 ++ __u16 auth_attempts;
29535 ++ unsigned long expires;
29536 ++
29537 ++ struct acl_subject_label *root_label;
29538 ++ struct gr_hash_struct *hash;
29539 ++
29540 ++ struct acl_role_label *prev;
29541 ++ struct acl_role_label *next;
29542 ++
29543 ++ struct role_transition *transitions;
29544 ++ struct role_allowed_ip *allowed_ips;
29545 ++ uid_t *domain_children;
29546 ++ __u16 domain_child_num;
29547 ++
29548 ++ struct acl_subject_label **subj_hash;
29549 ++ __u32 subj_hash_size;
29550 ++};
29551 ++
29552 ++struct user_acl_role_db {
29553 ++ struct acl_role_label **r_table;
29554 ++ __u32 num_pointers; /* Number of allocations to track */
29555 ++ __u32 num_roles; /* Number of roles */
29556 ++ __u32 num_domain_children; /* Number of domain children */
29557 ++ __u32 num_subjects; /* Number of subjects */
29558 ++ __u32 num_objects; /* Number of objects */
29559 ++};
29560 ++
29561 ++struct acl_object_label {
29562 ++ char *filename;
29563 ++ ino_t inode;
29564 ++ dev_t device;
29565 ++ __u32 mode;
29566 ++
29567 ++ struct acl_subject_label *nested;
29568 ++ struct acl_object_label *globbed;
29569 ++
29570 ++ /* next two structures not used */
29571 ++
29572 ++ struct acl_object_label *prev;
29573 ++ struct acl_object_label *next;
29574 ++};
29575 ++
29576 ++struct acl_ip_label {
29577 ++ char *iface;
29578 ++ __u32 addr;
29579 ++ __u32 netmask;
29580 ++ __u16 low, high;
29581 ++ __u8 mode;
29582 ++ __u32 type;
29583 ++ __u32 proto[8];
29584 ++
29585 ++ /* next two structures not used */
29586 ++
29587 ++ struct acl_ip_label *prev;
29588 ++ struct acl_ip_label *next;
29589 ++};
29590 ++
29591 ++struct gr_arg {
29592 ++ struct user_acl_role_db role_db;
29593 ++ unsigned char pw[GR_PW_LEN];
29594 ++ unsigned char salt[GR_SALT_LEN];
29595 ++ unsigned char sum[GR_SHA_LEN];
29596 ++ unsigned char sp_role[GR_SPROLE_LEN];
29597 ++ struct sprole_pw *sprole_pws;
29598 ++ dev_t segv_device;
29599 ++ ino_t segv_inode;
29600 ++ uid_t segv_uid;
29601 ++ __u16 num_sprole_pws;
29602 ++ __u16 mode;
29603 ++};
29604 ++
29605 ++struct gr_arg_wrapper {
29606 ++ struct gr_arg *arg;
29607 ++ __u32 version;
29608 ++ __u32 size;
29609 ++};
29610 ++
29611 ++struct subject_map {
29612 ++ struct acl_subject_label *user;
29613 ++ struct acl_subject_label *kernel;
29614 ++ struct subject_map *prev;
29615 ++ struct subject_map *next;
29616 ++};
29617 ++
29618 ++struct acl_subj_map_db {
29619 ++ struct subject_map **s_hash;
29620 ++ __u32 s_size;
29621 ++};
29622 ++
29623 ++/* End Data Structures Section */
29624 ++
29625 ++/* Hash functions generated by empirical testing by Brad Spengler
29626 ++ Makes good use of the low bits of the inode. Generally 0-1 times
29627 ++ in loop for successful match. 0-3 for unsuccessful match.
29628 ++ Shift/add algorithm with modulus of table size and an XOR*/
29629 ++
29630 ++static __inline__ unsigned int
29631 ++rhash(const uid_t uid, const __u16 type, const unsigned int sz)
29632 ++{
29633 ++ return (((uid << type) + (uid ^ type)) % sz);
29634 ++}
29635 ++
29636 ++ static __inline__ unsigned int
29637 ++shash(const struct acl_subject_label *userp, const unsigned int sz)
29638 ++{
29639 ++ return ((const unsigned long)userp % sz);
29640 ++}
29641 ++
29642 ++static __inline__ unsigned int
29643 ++fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
29644 ++{
29645 ++ return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
29646 ++}
29647 ++
29648 ++static __inline__ unsigned int
29649 ++nhash(const char *name, const __u16 len, const unsigned int sz)
29650 ++{
29651 ++ return full_name_hash(name, len) % sz;
29652 ++}
29653 ++
29654 ++#define FOR_EACH_ROLE_START(role,iter) \
29655 ++ role = NULL; \
29656 ++ iter = 0; \
29657 ++ while (iter < acl_role_set.r_size) { \
29658 ++ if (role == NULL) \
29659 ++ role = acl_role_set.r_hash[iter]; \
29660 ++ if (role == NULL) { \
29661 ++ iter++; \
29662 ++ continue; \
29663 ++ }
29664 ++
29665 ++#define FOR_EACH_ROLE_END(role,iter) \
29666 ++ role = role->next; \
29667 ++ if (role == NULL) \
29668 ++ iter++; \
29669 ++ }
29670 ++
29671 ++#define FOR_EACH_SUBJECT_START(role,subj,iter) \
29672 ++ subj = NULL; \
29673 ++ iter = 0; \
29674 ++ while (iter < role->subj_hash_size) { \
29675 ++ if (subj == NULL) \
29676 ++ subj = role->subj_hash[iter]; \
29677 ++ if (subj == NULL) { \
29678 ++ iter++; \
29679 ++ continue; \
29680 ++ }
29681 ++
29682 ++#define FOR_EACH_SUBJECT_END(subj,iter) \
29683 ++ subj = subj->next; \
29684 ++ if (subj == NULL) \
29685 ++ iter++; \
29686 ++ }
29687 ++
29688 ++
29689 ++#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
29690 ++ subj = role->hash->first; \
29691 ++ while (subj != NULL) {
29692 ++
29693 ++#define FOR_EACH_NESTED_SUBJECT_END(subj) \
29694 ++ subj = subj->next; \
29695 ++ }
29696 ++
29697 ++#endif
29698 ++
29699 +diff -urNp linux-2.6.27.10/include/linux/gralloc.h linux-2.6.27.10/include/linux/gralloc.h
29700 +--- linux-2.6.27.10/include/linux/gralloc.h 1969-12-31 19:00:00.000000000 -0500
29701 ++++ linux-2.6.27.10/include/linux/gralloc.h 2008-11-18 03:38:45.000000000 -0500
29702 +@@ -0,0 +1,8 @@
29703 ++#ifndef __GRALLOC_H
29704 ++#define __GRALLOC_H
29705 ++
29706 ++void acl_free_all(void);
29707 ++int acl_alloc_stack_init(unsigned long size);
29708 ++void *acl_alloc(unsigned long len);
29709 ++
29710 ++#endif
29711 +diff -urNp linux-2.6.27.10/include/linux/grdefs.h linux-2.6.27.10/include/linux/grdefs.h
29712 +--- linux-2.6.27.10/include/linux/grdefs.h 1969-12-31 19:00:00.000000000 -0500
29713 ++++ linux-2.6.27.10/include/linux/grdefs.h 2008-11-18 03:38:45.000000000 -0500
29714 +@@ -0,0 +1,131 @@
29715 ++#ifndef GRDEFS_H
29716 ++#define GRDEFS_H
29717 ++
29718 ++/* Begin grsecurity status declarations */
29719 ++
29720 ++enum {
29721 ++ GR_READY = 0x01,
29722 ++ GR_STATUS_INIT = 0x00 // disabled state
29723 ++};
29724 ++
29725 ++/* Begin ACL declarations */
29726 ++
29727 ++/* Role flags */
29728 ++
29729 ++enum {
29730 ++ GR_ROLE_USER = 0x0001,
29731 ++ GR_ROLE_GROUP = 0x0002,
29732 ++ GR_ROLE_DEFAULT = 0x0004,
29733 ++ GR_ROLE_SPECIAL = 0x0008,
29734 ++ GR_ROLE_AUTH = 0x0010,
29735 ++ GR_ROLE_NOPW = 0x0020,
29736 ++ GR_ROLE_GOD = 0x0040,
29737 ++ GR_ROLE_LEARN = 0x0080,
29738 ++ GR_ROLE_TPE = 0x0100,
29739 ++ GR_ROLE_DOMAIN = 0x0200,
29740 ++ GR_ROLE_PAM = 0x0400
29741 ++};
29742 ++
29743 ++/* ACL Subject and Object mode flags */
29744 ++enum {
29745 ++ GR_DELETED = 0x80000000
29746 ++};
29747 ++
29748 ++/* ACL Object-only mode flags */
29749 ++enum {
29750 ++ GR_READ = 0x00000001,
29751 ++ GR_APPEND = 0x00000002,
29752 ++ GR_WRITE = 0x00000004,
29753 ++ GR_EXEC = 0x00000008,
29754 ++ GR_FIND = 0x00000010,
29755 ++ GR_INHERIT = 0x00000020,
29756 ++ GR_SETID = 0x00000040,
29757 ++ GR_CREATE = 0x00000080,
29758 ++ GR_DELETE = 0x00000100,
29759 ++ GR_LINK = 0x00000200,
29760 ++ GR_AUDIT_READ = 0x00000400,
29761 ++ GR_AUDIT_APPEND = 0x00000800,
29762 ++ GR_AUDIT_WRITE = 0x00001000,
29763 ++ GR_AUDIT_EXEC = 0x00002000,
29764 ++ GR_AUDIT_FIND = 0x00004000,
29765 ++ GR_AUDIT_INHERIT= 0x00008000,
29766 ++ GR_AUDIT_SETID = 0x00010000,
29767 ++ GR_AUDIT_CREATE = 0x00020000,
29768 ++ GR_AUDIT_DELETE = 0x00040000,
29769 ++ GR_AUDIT_LINK = 0x00080000,
29770 ++ GR_PTRACERD = 0x00100000,
29771 ++ GR_NOPTRACE = 0x00200000,
29772 ++ GR_SUPPRESS = 0x00400000,
29773 ++ GR_NOLEARN = 0x00800000
29774 ++};
29775 ++
29776 ++#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
29777 ++ GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
29778 ++ GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
29779 ++
29780 ++/* ACL subject-only mode flags */
29781 ++enum {
29782 ++ GR_KILL = 0x00000001,
29783 ++ GR_VIEW = 0x00000002,
29784 ++ GR_PROTECTED = 0x00000004,
29785 ++ GR_LEARN = 0x00000008,
29786 ++ GR_OVERRIDE = 0x00000010,
29787 ++ /* just a placeholder, this mode is only used in userspace */
29788 ++ GR_DUMMY = 0x00000020,
29789 ++ GR_PROTSHM = 0x00000040,
29790 ++ GR_KILLPROC = 0x00000080,
29791 ++ GR_KILLIPPROC = 0x00000100,
29792 ++ /* just a placeholder, this mode is only used in userspace */
29793 ++ GR_NOTROJAN = 0x00000200,
29794 ++ GR_PROTPROCFD = 0x00000400,
29795 ++ GR_PROCACCT = 0x00000800,
29796 ++ GR_RELAXPTRACE = 0x00001000,
29797 ++ GR_NESTED = 0x00002000,
29798 ++ GR_INHERITLEARN = 0x00004000,
29799 ++ GR_PROCFIND = 0x00008000,
29800 ++ GR_POVERRIDE = 0x00010000,
29801 ++ GR_KERNELAUTH = 0x00020000,
29802 ++};
29803 ++
29804 ++enum {
29805 ++ GR_PAX_ENABLE_SEGMEXEC = 0x0001,
29806 ++ GR_PAX_ENABLE_PAGEEXEC = 0x0002,
29807 ++ GR_PAX_ENABLE_MPROTECT = 0x0004,
29808 ++ GR_PAX_ENABLE_RANDMMAP = 0x0008,
29809 ++ GR_PAX_ENABLE_EMUTRAMP = 0x0010,
29810 ++ GR_PAX_DISABLE_SEGMEXEC = 0x0100,
29811 ++ GR_PAX_DISABLE_PAGEEXEC = 0x0200,
29812 ++ GR_PAX_DISABLE_MPROTECT = 0x0400,
29813 ++ GR_PAX_DISABLE_RANDMMAP = 0x0800,
29814 ++ GR_PAX_DISABLE_EMUTRAMP = 0x1000,
29815 ++};
29816 ++
29817 ++enum {
29818 ++ GR_ID_USER = 0x01,
29819 ++ GR_ID_GROUP = 0x02,
29820 ++};
29821 ++
29822 ++enum {
29823 ++ GR_ID_ALLOW = 0x01,
29824 ++ GR_ID_DENY = 0x02,
29825 ++};
29826 ++
29827 ++#define GR_CRASH_RES 11
29828 ++#define GR_UIDTABLE_MAX 500
29829 ++
29830 ++/* begin resource learning section */
29831 ++enum {
29832 ++ GR_RLIM_CPU_BUMP = 60,
29833 ++ GR_RLIM_FSIZE_BUMP = 50000,
29834 ++ GR_RLIM_DATA_BUMP = 10000,
29835 ++ GR_RLIM_STACK_BUMP = 1000,
29836 ++ GR_RLIM_CORE_BUMP = 10000,
29837 ++ GR_RLIM_RSS_BUMP = 500000,
29838 ++ GR_RLIM_NPROC_BUMP = 1,
29839 ++ GR_RLIM_NOFILE_BUMP = 5,
29840 ++ GR_RLIM_MEMLOCK_BUMP = 50000,
29841 ++ GR_RLIM_AS_BUMP = 500000,
29842 ++ GR_RLIM_LOCKS_BUMP = 2
29843 ++};
29844 ++
29845 ++#endif
29846 +diff -urNp linux-2.6.27.10/include/linux/grinternal.h linux-2.6.27.10/include/linux/grinternal.h
29847 +--- linux-2.6.27.10/include/linux/grinternal.h 1969-12-31 19:00:00.000000000 -0500
29848 ++++ linux-2.6.27.10/include/linux/grinternal.h 2008-11-18 03:38:45.000000000 -0500
29849 +@@ -0,0 +1,210 @@
29850 ++#ifndef __GRINTERNAL_H
29851 ++#define __GRINTERNAL_H
29852 ++
29853 ++#ifdef CONFIG_GRKERNSEC
29854 ++
29855 ++#include <linux/fs.h>
29856 ++#include <linux/gracl.h>
29857 ++#include <linux/grdefs.h>
29858 ++#include <linux/grmsg.h>
29859 ++
29860 ++void gr_add_learn_entry(const char *fmt, ...);
29861 ++__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
29862 ++ const struct vfsmount *mnt);
29863 ++__u32 gr_check_create(const struct dentry *new_dentry,
29864 ++ const struct dentry *parent,
29865 ++ const struct vfsmount *mnt, const __u32 mode);
29866 ++int gr_check_protected_task(const struct task_struct *task);
29867 ++__u32 to_gr_audit(const __u32 reqmode);
29868 ++int gr_set_acls(const int type);
29869 ++
29870 ++int gr_acl_is_enabled(void);
29871 ++char gr_roletype_to_char(void);
29872 ++
29873 ++void gr_handle_alertkill(struct task_struct *task);
29874 ++char *gr_to_filename(const struct dentry *dentry,
29875 ++ const struct vfsmount *mnt);
29876 ++char *gr_to_filename1(const struct dentry *dentry,
29877 ++ const struct vfsmount *mnt);
29878 ++char *gr_to_filename2(const struct dentry *dentry,
29879 ++ const struct vfsmount *mnt);
29880 ++char *gr_to_filename3(const struct dentry *dentry,
29881 ++ const struct vfsmount *mnt);
29882 ++
29883 ++extern int grsec_enable_link;
29884 ++extern int grsec_enable_fifo;
29885 ++extern int grsec_enable_execve;
29886 ++extern int grsec_enable_shm;
29887 ++extern int grsec_enable_execlog;
29888 ++extern int grsec_enable_signal;
29889 ++extern int grsec_enable_forkfail;
29890 ++extern int grsec_enable_time;
29891 ++extern int grsec_enable_chroot_shmat;
29892 ++extern int grsec_enable_chroot_findtask;
29893 ++extern int grsec_enable_chroot_mount;
29894 ++extern int grsec_enable_chroot_double;
29895 ++extern int grsec_enable_chroot_pivot;
29896 ++extern int grsec_enable_chroot_chdir;
29897 ++extern int grsec_enable_chroot_chmod;
29898 ++extern int grsec_enable_chroot_mknod;
29899 ++extern int grsec_enable_chroot_fchdir;
29900 ++extern int grsec_enable_chroot_nice;
29901 ++extern int grsec_enable_chroot_execlog;
29902 ++extern int grsec_enable_chroot_caps;
29903 ++extern int grsec_enable_chroot_sysctl;
29904 ++extern int grsec_enable_chroot_unix;
29905 ++extern int grsec_enable_tpe;
29906 ++extern int grsec_tpe_gid;
29907 ++extern int grsec_enable_tpe_all;
29908 ++extern int grsec_enable_sidcaps;
29909 ++extern int grsec_enable_socket_all;
29910 ++extern int grsec_socket_all_gid;
29911 ++extern int grsec_enable_socket_client;
29912 ++extern int grsec_socket_client_gid;
29913 ++extern int grsec_enable_socket_server;
29914 ++extern int grsec_socket_server_gid;
29915 ++extern int grsec_audit_gid;
29916 ++extern int grsec_enable_group;
29917 ++extern int grsec_enable_audit_ipc;
29918 ++extern int grsec_enable_audit_textrel;
29919 ++extern int grsec_enable_mount;
29920 ++extern int grsec_enable_chdir;
29921 ++extern int grsec_resource_logging;
29922 ++extern int grsec_lock;
29923 ++
29924 ++extern spinlock_t grsec_alert_lock;
29925 ++extern unsigned long grsec_alert_wtime;
29926 ++extern unsigned long grsec_alert_fyet;
29927 ++
29928 ++extern spinlock_t grsec_audit_lock;
29929 ++
29930 ++extern rwlock_t grsec_exec_file_lock;
29931 ++
29932 ++#define gr_task_fullpath(tsk) (tsk->exec_file ? \
29933 ++ gr_to_filename2(tsk->exec_file->f_path.dentry, \
29934 ++ tsk->exec_file->f_vfsmnt) : "/")
29935 ++
29936 ++#define gr_parent_task_fullpath(tsk) (tsk->parent->exec_file ? \
29937 ++ gr_to_filename3(tsk->parent->exec_file->f_path.dentry, \
29938 ++ tsk->parent->exec_file->f_vfsmnt) : "/")
29939 ++
29940 ++#define gr_task_fullpath0(tsk) (tsk->exec_file ? \
29941 ++ gr_to_filename(tsk->exec_file->f_path.dentry, \
29942 ++ tsk->exec_file->f_vfsmnt) : "/")
29943 ++
29944 ++#define gr_parent_task_fullpath0(tsk) (tsk->parent->exec_file ? \
29945 ++ gr_to_filename1(tsk->parent->exec_file->f_path.dentry, \
29946 ++ tsk->parent->exec_file->f_vfsmnt) : "/")
29947 ++
29948 ++#define proc_is_chrooted(tsk_a) ((tsk_a->pid > 1) && (tsk_a->fs != NULL) && \
29949 ++ ((tsk_a->fs->root.dentry->d_inode->i_sb->s_dev != \
29950 ++ tsk_a->nsproxy->pid_ns->child_reaper->fs->root.dentry->d_inode->i_sb->s_dev) || \
29951 ++ (tsk_a->fs->root.dentry->d_inode->i_ino != \
29952 ++ tsk_a->nsproxy->pid_ns->child_reaper->fs->root.dentry->d_inode->i_ino)))
29953 ++
29954 ++#define have_same_root(tsk_a,tsk_b) ((tsk_a->fs != NULL) && (tsk_b->fs != NULL) && \
29955 ++ (tsk_a->fs->root.dentry->d_inode->i_sb->s_dev == \
29956 ++ tsk_b->fs->root.dentry->d_inode->i_sb->s_dev) && \
29957 ++ (tsk_a->fs->root.dentry->d_inode->i_ino == \
29958 ++ tsk_b->fs->root.dentry->d_inode->i_ino))
29959 ++
29960 ++#define DEFAULTSECARGS(task) gr_task_fullpath(task), task->comm, \
29961 ++ task->pid, task->uid, \
29962 ++ task->euid, task->gid, task->egid, \
29963 ++ gr_parent_task_fullpath(task), \
29964 ++ task->parent->comm, task->parent->pid, \
29965 ++ task->parent->uid, task->parent->euid, \
29966 ++ task->parent->gid, task->parent->egid
29967 ++
29968 ++#define GR_CHROOT_CAPS {{ \
29969 ++ CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
29970 ++ CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
29971 ++ CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
29972 ++ CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
29973 ++ CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
29974 ++ CAP_TO_MASK(CAP_IPC_OWNER) , 0 }}
29975 ++
29976 ++#define security_learn(normal_msg,args...) \
29977 ++({ \
29978 ++ read_lock(&grsec_exec_file_lock); \
29979 ++ gr_add_learn_entry(normal_msg "\n", ## args); \
29980 ++ read_unlock(&grsec_exec_file_lock); \
29981 ++})
29982 ++
29983 ++enum {
29984 ++ GR_DO_AUDIT,
29985 ++ GR_DONT_AUDIT,
29986 ++ GR_DONT_AUDIT_GOOD
29987 ++};
29988 ++
29989 ++enum {
29990 ++ GR_TTYSNIFF,
29991 ++ GR_RBAC,
29992 ++ GR_RBAC_STR,
29993 ++ GR_STR_RBAC,
29994 ++ GR_RBAC_MODE2,
29995 ++ GR_RBAC_MODE3,
29996 ++ GR_FILENAME,
29997 ++ GR_SYSCTL_HIDDEN,
29998 ++ GR_NOARGS,
29999 ++ GR_ONE_INT,
30000 ++ GR_ONE_INT_TWO_STR,
30001 ++ GR_ONE_STR,
30002 ++ GR_STR_INT,
30003 ++ GR_TWO_INT,
30004 ++ GR_THREE_INT,
30005 ++ GR_FIVE_INT_TWO_STR,
30006 ++ GR_TWO_STR,
30007 ++ GR_THREE_STR,
30008 ++ GR_FOUR_STR,
30009 ++ GR_STR_FILENAME,
30010 ++ GR_FILENAME_STR,
30011 ++ GR_FILENAME_TWO_INT,
30012 ++ GR_FILENAME_TWO_INT_STR,
30013 ++ GR_TEXTREL,
30014 ++ GR_PTRACE,
30015 ++ GR_RESOURCE,
30016 ++ GR_CAP,
30017 ++ GR_SIG,
30018 ++ GR_CRASH1,
30019 ++ GR_CRASH2,
30020 ++ GR_PSACCT
30021 ++};
30022 ++
30023 ++#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
30024 ++#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
30025 ++#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
30026 ++#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
30027 ++#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
30028 ++#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
30029 ++#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)
30030 ++#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
30031 ++#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
30032 ++#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
30033 ++#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
30034 ++#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
30035 ++#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
30036 ++#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
30037 ++#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
30038 ++#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)
30039 ++#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
30040 ++#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
30041 ++#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
30042 ++#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
30043 ++#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
30044 ++#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
30045 ++#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)
30046 ++#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
30047 ++#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
30048 ++#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
30049 ++#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
30050 ++#define gr_log_sig(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG, task, num)
30051 ++#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
30052 ++#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
30053 ++#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)
30054 ++
30055 ++void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
30056 ++
30057 ++#endif
30058 ++
30059 ++#endif
30060 +diff -urNp linux-2.6.27.10/include/linux/grmsg.h linux-2.6.27.10/include/linux/grmsg.h
30061 +--- linux-2.6.27.10/include/linux/grmsg.h 1969-12-31 19:00:00.000000000 -0500
30062 ++++ linux-2.6.27.10/include/linux/grmsg.h 2008-11-18 03:38:45.000000000 -0500
30063 +@@ -0,0 +1,108 @@
30064 ++#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"
30065 ++#define GR_ACL_PROCACCT_MSG "%.256s[%.16s:%d] IP:%u.%u.%u.%u 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:%u.%u.%u.%u TTY:%.64s uid/euid:%u/%u gid/egid:%u/%u"
30066 ++#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
30067 ++#define GR_STOPMOD_MSG "denied modification of module state by "
30068 ++#define GR_IOPERM_MSG "denied use of ioperm() by "
30069 ++#define GR_IOPL_MSG "denied use of iopl() by "
30070 ++#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
30071 ++#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
30072 ++#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
30073 ++#define GR_KMEM_MSG "denied write of /dev/kmem by "
30074 ++#define GR_PORT_OPEN_MSG "denied open of /dev/port by "
30075 ++#define GR_MEM_WRITE_MSG "denied write of /dev/mem by "
30076 ++#define GR_MEM_MMAP_MSG "denied mmap write of /dev/[k]mem by "
30077 ++#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
30078 ++#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%u.%u.%u.%u"
30079 ++#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%u.%u.%u.%u"
30080 ++#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
30081 ++#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
30082 ++#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
30083 ++#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
30084 ++#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
30085 ++#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
30086 ++#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
30087 ++#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%u.%u.%u.%u %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
30088 ++#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
30089 ++#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
30090 ++#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
30091 ++#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
30092 ++#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
30093 ++#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
30094 ++#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
30095 ++#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
30096 ++#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
30097 ++#define GR_NPROC_MSG "denied overstep of process limit by "
30098 ++#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
30099 ++#define GR_EXEC_TPE_MSG "denied untrusted exec of %.950s by "
30100 ++#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
30101 ++#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
30102 ++#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
30103 ++#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
30104 ++#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
30105 ++#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
30106 ++#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
30107 ++#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
30108 ++#define GR_FCHMOD_ACL_MSG "%s fchmod of %.950s by "
30109 ++#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
30110 ++#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
30111 ++#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
30112 ++#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
30113 ++#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
30114 ++#define GR_INITF_ACL_MSG "init_variables() failed %s by "
30115 ++#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"
30116 ++#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbaged by "
30117 ++#define GR_SHUTS_ACL_MSG "shutdown auth success for "
30118 ++#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
30119 ++#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
30120 ++#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
30121 ++#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
30122 ++#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
30123 ++#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
30124 ++#define GR_ENABLEF_ACL_MSG "unable to load %s for "
30125 ++#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
30126 ++#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
30127 ++#define GR_RELOADF_ACL_MSG "failed reload of %s for "
30128 ++#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
30129 ++#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
30130 ++#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
30131 ++#define GR_SPROLEF_ACL_MSG "special role %s failure for "
30132 ++#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
30133 ++#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
30134 ++#define GR_UNSPROLEF_ACL_MSG "special role unauth of %s failure for "
30135 ++#define GR_INVMODE_ACL_MSG "invalid mode %d by "
30136 ++#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
30137 ++#define GR_FAILFORK_MSG "failed fork with errno %d by "
30138 ++#define GR_NICE_CHROOT_MSG "denied priority change by "
30139 ++#define GR_UNISIGLOG_MSG "signal %d sent to "
30140 ++#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
30141 ++#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
30142 ++#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
30143 ++#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
30144 ++#define GR_TIME_MSG "time set by "
30145 ++#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
30146 ++#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
30147 ++#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
30148 ++#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
30149 ++#define GR_SOCK2_MSG "denied socket(%d,%.16s,%.16s) by "
30150 ++#define GR_BIND_MSG "denied bind() by "
30151 ++#define GR_CONNECT_MSG "denied connect() by "
30152 ++#define GR_BIND_ACL_MSG "denied bind() to %u.%u.%u.%u port %u sock type %.16s protocol %.16s by "
30153 ++#define GR_CONNECT_ACL_MSG "denied connect() to %u.%u.%u.%u port %u sock type %.16s protocol %.16s by "
30154 ++#define GR_IP_LEARN_MSG "%s\t%u\t%u\t%u\t%.4095s\t%.4095s\t%u.%u.%u.%u\t%u\t%u\t%u\t%u\t%u.%u.%u.%u"
30155 ++#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
30156 ++#define GR_CAP_ACL_MSG "use of %s denied for "
30157 ++#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
30158 ++#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
30159 ++#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
30160 ++#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
30161 ++#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
30162 ++#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
30163 ++#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
30164 ++#define GR_MSGQ_AUDIT_MSG "message queue created by "
30165 ++#define GR_MSGQR_AUDIT_MSG "message queue of uid:%u euid:%u removed by "
30166 ++#define GR_SEM_AUDIT_MSG "semaphore created by "
30167 ++#define GR_SEMR_AUDIT_MSG "semaphore of uid:%u euid:%u removed by "
30168 ++#define GR_SHM_AUDIT_MSG "shared memory of size %d created by "
30169 ++#define GR_SHMR_AUDIT_MSG "shared memory of uid:%u euid:%u removed by "
30170 ++#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
30171 ++#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
30172 +diff -urNp linux-2.6.27.10/include/linux/grsecurity.h linux-2.6.27.10/include/linux/grsecurity.h
30173 +--- linux-2.6.27.10/include/linux/grsecurity.h 1969-12-31 19:00:00.000000000 -0500
30174 ++++ linux-2.6.27.10/include/linux/grsecurity.h 2008-11-18 03:38:45.000000000 -0500
30175 +@@ -0,0 +1,200 @@
30176 ++#ifndef GR_SECURITY_H
30177 ++#define GR_SECURITY_H
30178 ++#include <linux/fs.h>
30179 ++#include <linux/binfmts.h>
30180 ++#include <linux/gracl.h>
30181 ++
30182 ++/* notify of brain-dead configs */
30183 ++#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
30184 ++#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
30185 ++#endif
30186 ++#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_EI_PAX) && !defined(CONFIG_PAX_PT_PAX_FLAGS)
30187 ++#error "CONFIG_PAX_NOEXEC enabled, but neither CONFIG_PAX_EI_PAX nor CONFIG_PAX_PT_PAX_FLAGS are enabled."
30188 ++#endif
30189 ++#if defined(CONFIG_PAX_ASLR) && (defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)) && !defined(CONFIG_PAX_EI_PAX) && !defined(CONFIG_PAX_PT_PAX_FLAGS)
30190 ++#error "CONFIG_PAX_ASLR enabled, but neither CONFIG_PAX_EI_PAX nor CONFIG_PAX_PT_PAX_FLAGS are enabled."
30191 ++#endif
30192 ++#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
30193 ++#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
30194 ++#endif
30195 ++#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
30196 ++#error "CONFIG_PAX enabled, but no PaX options are enabled."
30197 ++#endif
30198 ++
30199 ++void gr_handle_brute_attach(struct task_struct *p);
30200 ++void gr_handle_brute_check(void);
30201 ++
30202 ++char gr_roletype_to_char(void);
30203 ++
30204 ++int gr_check_user_change(int real, int effective, int fs);
30205 ++int gr_check_group_change(int real, int effective, int fs);
30206 ++
30207 ++void gr_del_task_from_ip_table(struct task_struct *p);
30208 ++
30209 ++int gr_pid_is_chrooted(struct task_struct *p);
30210 ++int gr_handle_chroot_nice(void);
30211 ++int gr_handle_chroot_sysctl(const int op);
30212 ++int gr_handle_chroot_setpriority(struct task_struct *p,
30213 ++ const int niceval);
30214 ++int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
30215 ++int gr_handle_chroot_chroot(const struct dentry *dentry,
30216 ++ const struct vfsmount *mnt);
30217 ++void gr_handle_chroot_caps(struct task_struct *task);
30218 ++void gr_handle_chroot_chdir(struct path *path);
30219 ++int gr_handle_chroot_chmod(const struct dentry *dentry,
30220 ++ const struct vfsmount *mnt, const int mode);
30221 ++int gr_handle_chroot_mknod(const struct dentry *dentry,
30222 ++ const struct vfsmount *mnt, const int mode);
30223 ++int gr_handle_chroot_mount(const struct dentry *dentry,
30224 ++ const struct vfsmount *mnt,
30225 ++ const char *dev_name);
30226 ++int gr_handle_chroot_pivot(void);
30227 ++int gr_handle_chroot_unix(const pid_t pid);
30228 ++
30229 ++int gr_handle_rawio(const struct inode *inode);
30230 ++int gr_handle_nproc(void);
30231 ++
30232 ++void gr_handle_ioperm(void);
30233 ++void gr_handle_iopl(void);
30234 ++
30235 ++int gr_tpe_allow(const struct file *file);
30236 ++
30237 ++int gr_random_pid(void);
30238 ++
30239 ++void gr_log_forkfail(const int retval);
30240 ++void gr_log_timechange(void);
30241 ++void gr_log_signal(const int sig, const struct task_struct *t);
30242 ++void gr_log_chdir(const struct dentry *dentry,
30243 ++ const struct vfsmount *mnt);
30244 ++void gr_log_chroot_exec(const struct dentry *dentry,
30245 ++ const struct vfsmount *mnt);
30246 ++void gr_handle_exec_args(struct linux_binprm *bprm, char **argv);
30247 ++void gr_log_remount(const char *devname, const int retval);
30248 ++void gr_log_unmount(const char *devname, const int retval);
30249 ++void gr_log_mount(const char *from, const char *to, const int retval);
30250 ++void gr_log_msgget(const int ret, const int msgflg);
30251 ++void gr_log_msgrm(const uid_t uid, const uid_t cuid);
30252 ++void gr_log_semget(const int err, const int semflg);
30253 ++void gr_log_semrm(const uid_t uid, const uid_t cuid);
30254 ++void gr_log_shmget(const int err, const int shmflg, const size_t size);
30255 ++void gr_log_shmrm(const uid_t uid, const uid_t cuid);
30256 ++void gr_log_textrel(struct vm_area_struct *vma);
30257 ++
30258 ++int gr_handle_follow_link(const struct inode *parent,
30259 ++ const struct inode *inode,
30260 ++ const struct dentry *dentry,
30261 ++ const struct vfsmount *mnt);
30262 ++int gr_handle_fifo(const struct dentry *dentry,
30263 ++ const struct vfsmount *mnt,
30264 ++ const struct dentry *dir, const int flag,
30265 ++ const int acc_mode);
30266 ++int gr_handle_hardlink(const struct dentry *dentry,
30267 ++ const struct vfsmount *mnt,
30268 ++ struct inode *inode,
30269 ++ const int mode, const char *to);
30270 ++
30271 ++int gr_task_is_capable(struct task_struct *task, const int cap);
30272 ++int gr_is_capable_nolog(const int cap);
30273 ++void gr_learn_resource(const struct task_struct *task, const int limit,
30274 ++ const unsigned long wanted, const int gt);
30275 ++void gr_copy_label(struct task_struct *tsk);
30276 ++void gr_handle_crash(struct task_struct *task, const int sig);
30277 ++int gr_handle_signal(const struct task_struct *p, const int sig);
30278 ++int gr_check_crash_uid(const uid_t uid);
30279 ++int gr_check_protected_task(const struct task_struct *task);
30280 ++int gr_acl_handle_mmap(const struct file *file,
30281 ++ const unsigned long prot);
30282 ++int gr_acl_handle_mprotect(const struct file *file,
30283 ++ const unsigned long prot);
30284 ++int gr_check_hidden_task(const struct task_struct *tsk);
30285 ++__u32 gr_acl_handle_truncate(const struct dentry *dentry,
30286 ++ const struct vfsmount *mnt);
30287 ++__u32 gr_acl_handle_utime(const struct dentry *dentry,
30288 ++ const struct vfsmount *mnt);
30289 ++__u32 gr_acl_handle_access(const struct dentry *dentry,
30290 ++ const struct vfsmount *mnt, const int fmode);
30291 ++__u32 gr_acl_handle_fchmod(const struct dentry *dentry,
30292 ++ const struct vfsmount *mnt, mode_t mode);
30293 ++__u32 gr_acl_handle_chmod(const struct dentry *dentry,
30294 ++ const struct vfsmount *mnt, mode_t mode);
30295 ++__u32 gr_acl_handle_chown(const struct dentry *dentry,
30296 ++ const struct vfsmount *mnt);
30297 ++int gr_handle_ptrace(struct task_struct *task, const long request);
30298 ++int gr_handle_proc_ptrace(struct task_struct *task);
30299 ++__u32 gr_acl_handle_execve(const struct dentry *dentry,
30300 ++ const struct vfsmount *mnt);
30301 ++int gr_check_crash_exec(const struct file *filp);
30302 ++int gr_acl_is_enabled(void);
30303 ++void gr_set_kernel_label(struct task_struct *task);
30304 ++void gr_set_role_label(struct task_struct *task, const uid_t uid,
30305 ++ const gid_t gid);
30306 ++int gr_set_proc_label(const struct dentry *dentry,
30307 ++ const struct vfsmount *mnt);
30308 ++__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
30309 ++ const struct vfsmount *mnt);
30310 ++__u32 gr_acl_handle_open(const struct dentry *dentry,
30311 ++ const struct vfsmount *mnt, const int fmode);
30312 ++__u32 gr_acl_handle_creat(const struct dentry *dentry,
30313 ++ const struct dentry *p_dentry,
30314 ++ const struct vfsmount *p_mnt, const int fmode,
30315 ++ const int imode);
30316 ++void gr_handle_create(const struct dentry *dentry,
30317 ++ const struct vfsmount *mnt);
30318 ++__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
30319 ++ const struct dentry *parent_dentry,
30320 ++ const struct vfsmount *parent_mnt,
30321 ++ const int mode);
30322 ++__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
30323 ++ const struct dentry *parent_dentry,
30324 ++ const struct vfsmount *parent_mnt);
30325 ++__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
30326 ++ const struct vfsmount *mnt);
30327 ++void gr_handle_delete(const ino_t ino, const dev_t dev);
30328 ++__u32 gr_acl_handle_unlink(const struct dentry *dentry,
30329 ++ const struct vfsmount *mnt);
30330 ++__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
30331 ++ const struct dentry *parent_dentry,
30332 ++ const struct vfsmount *parent_mnt,
30333 ++ const char *from);
30334 ++__u32 gr_acl_handle_link(const struct dentry *new_dentry,
30335 ++ const struct dentry *parent_dentry,
30336 ++ const struct vfsmount *parent_mnt,
30337 ++ const struct dentry *old_dentry,
30338 ++ const struct vfsmount *old_mnt, const char *to);
30339 ++int gr_acl_handle_rename(struct dentry *new_dentry,
30340 ++ struct dentry *parent_dentry,
30341 ++ const struct vfsmount *parent_mnt,
30342 ++ struct dentry *old_dentry,
30343 ++ struct inode *old_parent_inode,
30344 ++ struct vfsmount *old_mnt, const char *newname);
30345 ++void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
30346 ++ struct dentry *old_dentry,
30347 ++ struct dentry *new_dentry,
30348 ++ struct vfsmount *mnt, const __u8 replace);
30349 ++__u32 gr_check_link(const struct dentry *new_dentry,
30350 ++ const struct dentry *parent_dentry,
30351 ++ const struct vfsmount *parent_mnt,
30352 ++ const struct dentry *old_dentry,
30353 ++ const struct vfsmount *old_mnt);
30354 ++int gr_acl_handle_filldir(const struct file *file, const char *name,
30355 ++ const unsigned int namelen, const ino_t ino);
30356 ++
30357 ++__u32 gr_acl_handle_unix(const struct dentry *dentry,
30358 ++ const struct vfsmount *mnt);
30359 ++void gr_acl_handle_exit(void);
30360 ++void gr_acl_handle_psacct(struct task_struct *task, const long code);
30361 ++int gr_acl_handle_procpidmem(const struct task_struct *task);
30362 ++
30363 ++#ifdef CONFIG_GRKERNSEC
30364 ++void gr_handle_mem_write(void);
30365 ++void gr_handle_kmem_write(void);
30366 ++void gr_handle_open_port(void);
30367 ++int gr_handle_mem_mmap(const unsigned long offset,
30368 ++ struct vm_area_struct *vma);
30369 ++
30370 ++extern int grsec_enable_dmesg;
30371 ++extern int grsec_enable_randsrc;
30372 ++extern int grsec_enable_shm;
30373 ++#endif
30374 ++
30375 ++#endif
30376 +diff -urNp linux-2.6.27.10/include/linux/highmem.h linux-2.6.27.10/include/linux/highmem.h
30377 +--- linux-2.6.27.10/include/linux/highmem.h 2008-11-07 12:55:34.000000000 -0500
30378 ++++ linux-2.6.27.10/include/linux/highmem.h 2008-11-18 03:38:45.000000000 -0500
30379 +@@ -122,6 +122,13 @@ static inline void clear_highpage(struct
30380 + kunmap_atomic(kaddr, KM_USER0);
30381 + }
30382 +
30383 ++static inline void sanitize_highpage(struct page *page)
30384 ++{
30385 ++ void *kaddr = kmap_atomic(page, KM_CLEARPAGE);
30386 ++ clear_page(kaddr);
30387 ++ kunmap_atomic(kaddr, KM_CLEARPAGE);
30388 ++}
30389 ++
30390 + static inline void zero_user_segments(struct page *page,
30391 + unsigned start1, unsigned end1,
30392 + unsigned start2, unsigned end2)
30393 +diff -urNp linux-2.6.27.10/include/linux/jbd2.h linux-2.6.27.10/include/linux/jbd2.h
30394 +--- linux-2.6.27.10/include/linux/jbd2.h 2008-12-10 22:35:38.000000000 -0500
30395 ++++ linux-2.6.27.10/include/linux/jbd2.h 2008-12-10 22:35:46.000000000 -0500
30396 +@@ -66,7 +66,7 @@ extern u8 jbd2_journal_enable_debug;
30397 + } \
30398 + } while (0)
30399 + #else
30400 +-#define jbd_debug(f, a...) /**/
30401 ++#define jbd_debug(f, a...) do {} while (0)
30402 + #endif
30403 +
30404 + static inline void *jbd2_alloc(size_t size, gfp_t flags)
30405 +diff -urNp linux-2.6.27.10/include/linux/jbd.h linux-2.6.27.10/include/linux/jbd.h
30406 +--- linux-2.6.27.10/include/linux/jbd.h 2008-12-21 01:16:52.000000000 -0500
30407 ++++ linux-2.6.27.10/include/linux/jbd.h 2008-12-21 01:13:46.000000000 -0500
30408 +@@ -66,7 +66,7 @@ extern u8 journal_enable_debug;
30409 + } \
30410 + } while (0)
30411 + #else
30412 +-#define jbd_debug(f, a...) /**/
30413 ++#define jbd_debug(f, a...) do {} while (0)
30414 + #endif
30415 +
30416 + static inline void *jbd_alloc(size_t size, gfp_t flags)
30417 +diff -urNp linux-2.6.27.10/include/linux/libata.h linux-2.6.27.10/include/linux/libata.h
30418 +--- linux-2.6.27.10/include/linux/libata.h 2008-12-10 22:35:38.000000000 -0500
30419 ++++ linux-2.6.27.10/include/linux/libata.h 2008-12-10 22:35:46.000000000 -0500
30420 +@@ -64,11 +64,11 @@
30421 + #ifdef ATA_VERBOSE_DEBUG
30422 + #define VPRINTK(fmt, args...) printk(KERN_ERR "%s: " fmt, __func__, ## args)
30423 + #else
30424 +-#define VPRINTK(fmt, args...)
30425 ++#define VPRINTK(fmt, args...) do {} while (0)
30426 + #endif /* ATA_VERBOSE_DEBUG */
30427 + #else
30428 +-#define DPRINTK(fmt, args...)
30429 +-#define VPRINTK(fmt, args...)
30430 ++#define DPRINTK(fmt, args...) do {} while (0)
30431 ++#define VPRINTK(fmt, args...) do {} while (0)
30432 + #endif /* ATA_DEBUG */
30433 +
30434 + #define BPRINTK(fmt, args...) if (ap->flags & ATA_FLAG_DEBUGMSG) printk(KERN_ERR "%s: " fmt, __func__, ## args)
30435 +diff -urNp linux-2.6.27.10/include/linux/mm.h linux-2.6.27.10/include/linux/mm.h
30436 +--- linux-2.6.27.10/include/linux/mm.h 2008-11-07 12:55:34.000000000 -0500
30437 ++++ linux-2.6.27.10/include/linux/mm.h 2008-12-21 00:44:29.000000000 -0500
30438 +@@ -38,6 +38,7 @@ extern unsigned long mmap_min_addr;
30439 + #include <asm/page.h>
30440 + #include <asm/pgtable.h>
30441 + #include <asm/processor.h>
30442 ++#include <asm/mman.h>
30443 +
30444 + #define nth_page(page,n) pfn_to_page(page_to_pfn((page)) + (n))
30445 +
30446 +@@ -114,6 +115,10 @@ extern unsigned int kobjsize(const void
30447 + #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
30448 + #define VM_SAO 0x20000000 /* Strong Access Ordering (powerpc) */
30449 +
30450 ++#ifdef CONFIG_PAX_PAGEEXEC
30451 ++#define VM_PAGEEXEC 0x40000000 /* vma->vm_page_prot needs special handling */
30452 ++#endif
30453 ++
30454 + #ifndef VM_STACK_DEFAULT_FLAGS /* arch can override this */
30455 + #define VM_STACK_DEFAULT_FLAGS VM_DATA_DEFAULT_FLAGS
30456 + #endif
30457 +@@ -874,6 +879,8 @@ struct shrinker {
30458 + extern void register_shrinker(struct shrinker *);
30459 + extern void unregister_shrinker(struct shrinker *);
30460 +
30461 ++pgprot_t vm_get_page_prot(unsigned long vm_flags);
30462 ++
30463 + int vma_wants_writenotify(struct vm_area_struct *vma);
30464 +
30465 + extern pte_t *get_locked_pte(struct mm_struct *mm, unsigned long addr, spinlock_t **ptl);
30466 +@@ -1129,6 +1136,7 @@ out:
30467 + }
30468 +
30469 + extern int do_munmap(struct mm_struct *, unsigned long, size_t);
30470 ++extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
30471 +
30472 + extern unsigned long do_brk(unsigned long, unsigned long);
30473 +
30474 +@@ -1181,6 +1189,10 @@ extern struct vm_area_struct * find_vma(
30475 + extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
30476 + struct vm_area_struct **pprev);
30477 +
30478 ++extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
30479 ++extern void pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
30480 ++extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
30481 ++
30482 + /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
30483 + NULL if none. Assume start_addr < end_addr. */
30484 + static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
30485 +@@ -1197,7 +1209,6 @@ static inline unsigned long vma_pages(st
30486 + return (vma->vm_end - vma->vm_start) >> PAGE_SHIFT;
30487 + }
30488 +
30489 +-pgprot_t vm_get_page_prot(unsigned long vm_flags);
30490 + struct vm_area_struct *find_extend_vma(struct mm_struct *, unsigned long addr);
30491 + int remap_pfn_range(struct vm_area_struct *, unsigned long addr,
30492 + unsigned long pfn, unsigned long size, pgprot_t);
30493 +@@ -1286,5 +1297,11 @@ int vmemmap_populate_basepages(struct pa
30494 + int vmemmap_populate(struct page *start_page, unsigned long pages, int node);
30495 + void vmemmap_populate_print_last(void);
30496 +
30497 ++#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
30498 ++extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
30499 ++#else
30500 ++static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
30501 ++#endif
30502 ++
30503 + #endif /* __KERNEL__ */
30504 + #endif /* _LINUX_MM_H */
30505 +diff -urNp linux-2.6.27.10/include/linux/mm_types.h linux-2.6.27.10/include/linux/mm_types.h
30506 +--- linux-2.6.27.10/include/linux/mm_types.h 2008-11-07 12:55:34.000000000 -0500
30507 ++++ linux-2.6.27.10/include/linux/mm_types.h 2008-11-18 03:38:45.000000000 -0500
30508 +@@ -158,6 +158,8 @@ struct vm_area_struct {
30509 + #ifdef CONFIG_NUMA
30510 + struct mempolicy *vm_policy; /* NUMA policy for the VMA */
30511 + #endif
30512 ++
30513 ++ struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
30514 + };
30515 +
30516 + struct core_thread {
30517 +@@ -257,6 +259,24 @@ struct mm_struct {
30518 + #ifdef CONFIG_MMU_NOTIFIER
30519 + struct mmu_notifier_mm *mmu_notifier_mm;
30520 + #endif
30521 ++
30522 ++#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS) || defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
30523 ++ unsigned long pax_flags;
30524 ++#endif
30525 ++
30526 ++#ifdef CONFIG_PAX_DLRESOLVE
30527 ++ unsigned long call_dl_resolve;
30528 ++#endif
30529 ++
30530 ++#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
30531 ++ unsigned long call_syscall;
30532 ++#endif
30533 ++
30534 ++#ifdef CONFIG_PAX_ASLR
30535 ++ unsigned long delta_mmap; /* randomized offset */
30536 ++ unsigned long delta_stack; /* randomized offset */
30537 ++#endif
30538 ++
30539 + };
30540 +
30541 + #endif /* _LINUX_MM_TYPES_H */
30542 +diff -urNp linux-2.6.27.10/include/linux/module.h linux-2.6.27.10/include/linux/module.h
30543 +--- linux-2.6.27.10/include/linux/module.h 2008-11-07 12:55:34.000000000 -0500
30544 ++++ linux-2.6.27.10/include/linux/module.h 2008-11-18 03:38:45.000000000 -0500
30545 +@@ -282,16 +282,16 @@ struct module
30546 + int (*init)(void);
30547 +
30548 + /* If this is non-NULL, vfree after init() returns */
30549 +- void *module_init;
30550 ++ void *module_init_rx, *module_init_rw;
30551 +
30552 + /* Here is the actual code + data, vfree'd on unload. */
30553 +- void *module_core;
30554 ++ void *module_core_rx, *module_core_rw;
30555 +
30556 + /* Here are the sizes of the init and core sections */
30557 +- unsigned int init_size, core_size;
30558 ++ unsigned int init_size_rw, core_size_rw;
30559 +
30560 + /* The size of the executable code in each section. */
30561 +- unsigned int init_text_size, core_text_size;
30562 ++ unsigned int init_size_rx, core_size_rx;
30563 +
30564 + /* The handle returned from unwind_add_table. */
30565 + void *unwind_info;
30566 +diff -urNp linux-2.6.27.10/include/linux/moduleloader.h linux-2.6.27.10/include/linux/moduleloader.h
30567 +--- linux-2.6.27.10/include/linux/moduleloader.h 2008-11-07 12:55:34.000000000 -0500
30568 ++++ linux-2.6.27.10/include/linux/moduleloader.h 2008-11-18 03:38:45.000000000 -0500
30569 +@@ -17,9 +17,21 @@ int module_frob_arch_sections(Elf_Ehdr *
30570 + sections. Returns NULL on failure. */
30571 + void *module_alloc(unsigned long size);
30572 +
30573 ++#ifdef CONFIG_PAX_KERNEXEC
30574 ++void *module_alloc_exec(unsigned long size);
30575 ++#else
30576 ++#define module_alloc_exec(x) module_alloc(x)
30577 ++#endif
30578 ++
30579 + /* Free memory returned from module_alloc. */
30580 + void module_free(struct module *mod, void *module_region);
30581 +
30582 ++#ifdef CONFIG_PAX_KERNEXEC
30583 ++void module_free_exec(struct module *mod, void *module_region);
30584 ++#else
30585 ++#define module_free_exec(x, y) module_free(x, y)
30586 ++#endif
30587 ++
30588 + /* Apply the given relocation to the (simplified) ELF. Return -error
30589 + or 0. */
30590 + int apply_relocate(Elf_Shdr *sechdrs,
30591 +diff -urNp linux-2.6.27.10/include/linux/namei.h linux-2.6.27.10/include/linux/namei.h
30592 +--- linux-2.6.27.10/include/linux/namei.h 2008-11-07 12:55:34.000000000 -0500
30593 ++++ linux-2.6.27.10/include/linux/namei.h 2008-11-18 03:38:45.000000000 -0500
30594 +@@ -21,7 +21,7 @@ struct nameidata {
30595 + unsigned int flags;
30596 + int last_type;
30597 + unsigned depth;
30598 +- char *saved_names[MAX_NESTED_LINKS + 1];
30599 ++ const char *saved_names[MAX_NESTED_LINKS + 1];
30600 +
30601 + /* Intent data */
30602 + union {
30603 +@@ -80,12 +80,12 @@ extern int follow_up(struct vfsmount **,
30604 + extern struct dentry *lock_rename(struct dentry *, struct dentry *);
30605 + extern void unlock_rename(struct dentry *, struct dentry *);
30606 +
30607 +-static inline void nd_set_link(struct nameidata *nd, char *path)
30608 ++static inline void nd_set_link(struct nameidata *nd, const char *path)
30609 + {
30610 + nd->saved_names[nd->depth] = path;
30611 + }
30612 +
30613 +-static inline char *nd_get_link(struct nameidata *nd)
30614 ++static inline const char *nd_get_link(struct nameidata *nd)
30615 + {
30616 + return nd->saved_names[nd->depth];
30617 + }
30618 +diff -urNp linux-2.6.27.10/include/linux/nodemask.h linux-2.6.27.10/include/linux/nodemask.h
30619 +--- linux-2.6.27.10/include/linux/nodemask.h 2008-11-07 12:55:34.000000000 -0500
30620 ++++ linux-2.6.27.10/include/linux/nodemask.h 2008-11-18 03:38:45.000000000 -0500
30621 +@@ -442,11 +442,11 @@ static inline int num_node_state(enum no
30622 +
30623 + #define any_online_node(mask) \
30624 + ({ \
30625 +- int node; \
30626 +- for_each_node_mask(node, (mask)) \
30627 +- if (node_online(node)) \
30628 ++ int __node; \
30629 ++ for_each_node_mask(__node, (mask)) \
30630 ++ if (node_online(__node)) \
30631 + break; \
30632 +- node; \
30633 ++ __node; \
30634 + })
30635 +
30636 + #define num_online_nodes() num_node_state(N_ONLINE)
30637 +diff -urNp linux-2.6.27.10/include/linux/percpu.h linux-2.6.27.10/include/linux/percpu.h
30638 +--- linux-2.6.27.10/include/linux/percpu.h 2008-11-07 12:55:34.000000000 -0500
30639 ++++ linux-2.6.27.10/include/linux/percpu.h 2008-11-18 03:38:45.000000000 -0500
30640 +@@ -43,7 +43,7 @@
30641 + #endif
30642 +
30643 + #define PERCPU_ENOUGH_ROOM \
30644 +- (__per_cpu_end - __per_cpu_start + PERCPU_MODULE_RESERVE)
30645 ++ ((unsigned long)(__per_cpu_end - __per_cpu_start + PERCPU_MODULE_RESERVE))
30646 + #endif /* PERCPU_ENOUGH_ROOM */
30647 +
30648 + /*
30649 +diff -urNp linux-2.6.27.10/include/linux/poison.h linux-2.6.27.10/include/linux/poison.h
30650 +--- linux-2.6.27.10/include/linux/poison.h 2008-11-07 12:55:34.000000000 -0500
30651 ++++ linux-2.6.27.10/include/linux/poison.h 2008-11-18 03:38:45.000000000 -0500
30652 +@@ -7,8 +7,8 @@
30653 + * under normal circumstances, used to verify that nobody uses
30654 + * non-initialized list entries.
30655 + */
30656 +-#define LIST_POISON1 ((void *) 0x00100100)
30657 +-#define LIST_POISON2 ((void *) 0x00200200)
30658 ++#define LIST_POISON1 ((void *) 0xFF1001FFFF1001FFULL)
30659 ++#define LIST_POISON2 ((void *) 0xFF2002FFFF2002FFULL)
30660 +
30661 + /********** include/linux/timer.h **********/
30662 + /*
30663 +diff -urNp linux-2.6.27.10/include/linux/random.h linux-2.6.27.10/include/linux/random.h
30664 +--- linux-2.6.27.10/include/linux/random.h 2008-11-07 12:55:34.000000000 -0500
30665 ++++ linux-2.6.27.10/include/linux/random.h 2008-11-18 03:38:45.000000000 -0500
30666 +@@ -72,6 +72,11 @@ unsigned long randomize_range(unsigned l
30667 + u32 random32(void);
30668 + void srandom32(u32 seed);
30669 +
30670 ++static inline unsigned long pax_get_random_long(void)
30671 ++{
30672 ++ return random32() + (sizeof(long) > 4 ? (unsigned long)random32() << 32 : 0);
30673 ++}
30674 ++
30675 + #endif /* __KERNEL___ */
30676 +
30677 + #endif /* _LINUX_RANDOM_H */
30678 +diff -urNp linux-2.6.27.10/include/linux/sched.h linux-2.6.27.10/include/linux/sched.h
30679 +--- linux-2.6.27.10/include/linux/sched.h 2008-12-10 22:35:38.000000000 -0500
30680 ++++ linux-2.6.27.10/include/linux/sched.h 2008-12-10 22:35:46.000000000 -0500
30681 +@@ -96,6 +96,7 @@ struct exec_domain;
30682 + struct futex_pi_state;
30683 + struct robust_list_head;
30684 + struct bio;
30685 ++struct linux_binprm;
30686 +
30687 + /*
30688 + * List of flags we want to share for kernel threads,
30689 +@@ -545,6 +546,15 @@ struct signal_struct {
30690 + unsigned audit_tty;
30691 + struct tty_audit_buf *tty_audit_buf;
30692 + #endif
30693 ++
30694 ++#ifdef CONFIG_GRKERNSEC
30695 ++ u32 curr_ip;
30696 ++ u32 gr_saddr;
30697 ++ u32 gr_daddr;
30698 ++ u16 gr_sport;
30699 ++ u16 gr_dport;
30700 ++ u8 used_accept:1;
30701 ++#endif
30702 + };
30703 +
30704 + /* Context switch must be unlocked if interrupts are to be enabled */
30705 +@@ -1030,7 +1040,7 @@ struct sched_rt_entity {
30706 +
30707 + struct task_struct {
30708 + volatile long state; /* -1 unrunnable, 0 runnable, >0 stopped */
30709 +- void *stack;
30710 ++ struct thread_info *stack;
30711 + atomic_t usage;
30712 + unsigned int flags; /* per process flags, defined below */
30713 + unsigned int ptrace;
30714 +@@ -1095,10 +1105,9 @@ struct task_struct {
30715 + pid_t pid;
30716 + pid_t tgid;
30717 +
30718 +-#ifdef CONFIG_CC_STACKPROTECTOR
30719 + /* Canary value for the -fstack-protector gcc feature */
30720 + unsigned long stack_canary;
30721 +-#endif
30722 ++
30723 + /*
30724 + * pointers to (original) parent process, youngest child, younger sibling,
30725 + * older sibling, respectively. (p->father can be replaced with
30726 +@@ -1126,8 +1135,8 @@ struct task_struct {
30727 + struct list_head thread_group;
30728 +
30729 + struct completion *vfork_done; /* for vfork() */
30730 +- int __user *set_child_tid; /* CLONE_CHILD_SETTID */
30731 +- int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
30732 ++ pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
30733 ++ pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
30734 +
30735 + cputime_t utime, stime, utimescaled, stimescaled;
30736 + cputime_t gtime;
30737 +@@ -1307,8 +1316,64 @@ struct task_struct {
30738 + int latency_record_count;
30739 + struct latency_record latency_record[LT_SAVECOUNT];
30740 + #endif
30741 ++
30742 ++#ifdef CONFIG_GRKERNSEC
30743 ++ /* grsecurity */
30744 ++ struct acl_subject_label *acl;
30745 ++ struct acl_role_label *role;
30746 ++ struct file *exec_file;
30747 ++ u16 acl_role_id;
30748 ++ u8 acl_sp_role;
30749 ++ u8 is_writable;
30750 ++ u8 brute;
30751 ++#endif
30752 ++
30753 + };
30754 +
30755 ++#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
30756 ++#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
30757 ++#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
30758 ++#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
30759 ++/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
30760 ++#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
30761 ++
30762 ++#ifdef CONFIG_PAX_SOFTMODE
30763 ++extern unsigned int pax_softmode;
30764 ++#endif
30765 ++
30766 ++extern int pax_check_flags(unsigned long *);
30767 ++
30768 ++/* if tsk != current then task_lock must be held on it */
30769 ++#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
30770 ++static inline unsigned long pax_get_flags(struct task_struct *tsk)
30771 ++{
30772 ++ if (likely(tsk->mm))
30773 ++ return tsk->mm->pax_flags;
30774 ++ else
30775 ++ return 0UL;
30776 ++}
30777 ++
30778 ++/* if tsk != current then task_lock must be held on it */
30779 ++static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
30780 ++{
30781 ++ if (likely(tsk->mm)) {
30782 ++ tsk->mm->pax_flags = flags;
30783 ++ return 0;
30784 ++ }
30785 ++ return -EINVAL;
30786 ++}
30787 ++#endif
30788 ++
30789 ++#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
30790 ++extern void pax_set_initial_flags(struct linux_binprm *bprm);
30791 ++#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
30792 ++extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
30793 ++#endif
30794 ++
30795 ++void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
30796 ++void pax_report_insns(void *pc, void *sp);
30797 ++void pax_report_refcount_overflow(struct pt_regs *regs);
30798 ++
30799 + /*
30800 + * Priority of a process goes from 0..MAX_PRIO-1, valid RT
30801 + * priority is 0..MAX_RT_PRIO-1, and SCHED_NORMAL/SCHED_BATCH
30802 +@@ -1849,7 +1914,7 @@ extern void __cleanup_sighand(struct sig
30803 + extern void exit_itimers(struct signal_struct *);
30804 + extern void flush_itimer_signals(void);
30805 +
30806 +-extern NORET_TYPE void do_group_exit(int);
30807 ++extern NORET_TYPE void do_group_exit(int) ATTRIB_NORET;
30808 +
30809 + extern void daemonize(const char *, ...);
30810 + extern int allow_signal(int);
30811 +@@ -1952,8 +2017,8 @@ static inline void unlock_task_sighand(s
30812 +
30813 + #ifndef __HAVE_THREAD_FUNCTIONS
30814 +
30815 +-#define task_thread_info(task) ((struct thread_info *)(task)->stack)
30816 +-#define task_stack_page(task) ((task)->stack)
30817 ++#define task_thread_info(task) ((task)->stack)
30818 ++#define task_stack_page(task) ((void *)(task)->stack)
30819 +
30820 + static inline void setup_thread_stack(struct task_struct *p, struct task_struct *org)
30821 + {
30822 +diff -urNp linux-2.6.27.10/include/linux/screen_info.h linux-2.6.27.10/include/linux/screen_info.h
30823 +--- linux-2.6.27.10/include/linux/screen_info.h 2008-11-07 12:55:34.000000000 -0500
30824 ++++ linux-2.6.27.10/include/linux/screen_info.h 2008-11-18 03:38:45.000000000 -0500
30825 +@@ -42,7 +42,8 @@ struct screen_info {
30826 + __u16 pages; /* 0x32 */
30827 + __u16 vesa_attributes; /* 0x34 */
30828 + __u32 capabilities; /* 0x36 */
30829 +- __u8 _reserved[6]; /* 0x3a */
30830 ++ __u16 vesapm_size; /* 0x3a */
30831 ++ __u8 _reserved[4]; /* 0x3c */
30832 + } __attribute__((packed));
30833 +
30834 + #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
30835 +diff -urNp linux-2.6.27.10/include/linux/shm.h linux-2.6.27.10/include/linux/shm.h
30836 +--- linux-2.6.27.10/include/linux/shm.h 2008-11-07 12:55:34.000000000 -0500
30837 ++++ linux-2.6.27.10/include/linux/shm.h 2008-11-18 03:38:45.000000000 -0500
30838 +@@ -95,6 +95,10 @@ struct shmid_kernel /* private to the ke
30839 + pid_t shm_cprid;
30840 + pid_t shm_lprid;
30841 + struct user_struct *mlock_user;
30842 ++#ifdef CONFIG_GRKERNSEC
30843 ++ time_t shm_createtime;
30844 ++ pid_t shm_lapid;
30845 ++#endif
30846 + };
30847 +
30848 + /* shm_mode upper byte flags */
30849 +diff -urNp linux-2.6.27.10/include/linux/slab.h linux-2.6.27.10/include/linux/slab.h
30850 +--- linux-2.6.27.10/include/linux/slab.h 2008-11-07 12:55:34.000000000 -0500
30851 ++++ linux-2.6.27.10/include/linux/slab.h 2008-11-18 03:38:45.000000000 -0500
30852 +@@ -45,10 +45,9 @@
30853 + * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
30854 + * Both make kfree a no-op.
30855 + */
30856 +-#define ZERO_SIZE_PTR ((void *)16)
30857 ++#define ZERO_SIZE_PTR ((void *)-1024L)
30858 +
30859 +-#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
30860 +- (unsigned long)ZERO_SIZE_PTR)
30861 ++#define ZERO_OR_NULL_PTR(x) (!(x) || (x) == ZERO_SIZE_PTR)
30862 +
30863 + /*
30864 + * struct kmem_cache related prototypes
30865 +diff -urNp linux-2.6.27.10/include/linux/sysctl.h linux-2.6.27.10/include/linux/sysctl.h
30866 +--- linux-2.6.27.10/include/linux/sysctl.h 2008-11-07 12:55:34.000000000 -0500
30867 ++++ linux-2.6.27.10/include/linux/sysctl.h 2008-11-18 03:38:45.000000000 -0500
30868 +@@ -165,7 +165,11 @@ enum
30869 + KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
30870 + };
30871 +
30872 +-
30873 ++#ifdef CONFIG_PAX_SOFTMODE
30874 ++enum {
30875 ++ PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
30876 ++};
30877 ++#endif
30878 +
30879 + /* CTL_VM names: */
30880 + enum
30881 +diff -urNp linux-2.6.27.10/include/linux/thread_info.h linux-2.6.27.10/include/linux/thread_info.h
30882 +--- linux-2.6.27.10/include/linux/thread_info.h 2008-11-07 12:55:34.000000000 -0500
30883 ++++ linux-2.6.27.10/include/linux/thread_info.h 2008-11-18 03:38:45.000000000 -0500
30884 +@@ -23,7 +23,7 @@ struct restart_block {
30885 + };
30886 + /* For futex_wait */
30887 + struct {
30888 +- u32 *uaddr;
30889 ++ u32 __user *uaddr;
30890 + u32 val;
30891 + u32 flags;
30892 + u32 bitset;
30893 +diff -urNp linux-2.6.27.10/include/linux/uaccess.h linux-2.6.27.10/include/linux/uaccess.h
30894 +--- linux-2.6.27.10/include/linux/uaccess.h 2008-11-07 12:55:34.000000000 -0500
30895 ++++ linux-2.6.27.10/include/linux/uaccess.h 2008-11-18 03:38:45.000000000 -0500
30896 +@@ -76,11 +76,11 @@ static inline unsigned long __copy_from_
30897 + long ret; \
30898 + mm_segment_t old_fs = get_fs(); \
30899 + \
30900 +- set_fs(KERNEL_DS); \
30901 + pagefault_disable(); \
30902 ++ set_fs(KERNEL_DS); \
30903 + ret = __get_user(retval, (__force typeof(retval) __user *)(addr)); \
30904 +- pagefault_enable(); \
30905 + set_fs(old_fs); \
30906 ++ pagefault_enable(); \
30907 + ret; \
30908 + })
30909 +
30910 +diff -urNp linux-2.6.27.10/include/linux/vmalloc.h linux-2.6.27.10/include/linux/vmalloc.h
30911 +--- linux-2.6.27.10/include/linux/vmalloc.h 2008-11-07 12:55:34.000000000 -0500
30912 ++++ linux-2.6.27.10/include/linux/vmalloc.h 2008-11-18 03:38:45.000000000 -0500
30913 +@@ -12,6 +12,11 @@ struct vm_area_struct; /* vma defining
30914 + #define VM_MAP 0x00000004 /* vmap()ed pages */
30915 + #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
30916 + #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
30917 ++
30918 ++#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
30919 ++#define VM_KERNEXEC 0x00000020 /* allocate from executable kernel memory range */
30920 ++#endif
30921 ++
30922 + /* bits [20..32] reserved for arch specific ioremap internals */
30923 +
30924 + /*
30925 +diff -urNp linux-2.6.27.10/include/net/sctp/sctp.h linux-2.6.27.10/include/net/sctp/sctp.h
30926 +--- linux-2.6.27.10/include/net/sctp/sctp.h 2008-11-07 12:55:34.000000000 -0500
30927 ++++ linux-2.6.27.10/include/net/sctp/sctp.h 2008-11-18 03:38:45.000000000 -0500
30928 +@@ -309,8 +309,8 @@ extern int sctp_debug_flag;
30929 +
30930 + #else /* SCTP_DEBUG */
30931 +
30932 +-#define SCTP_DEBUG_PRINTK(whatever...)
30933 +-#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
30934 ++#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
30935 ++#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
30936 + #define SCTP_ENABLE_DEBUG
30937 + #define SCTP_DISABLE_DEBUG
30938 + #define SCTP_ASSERT(expr, str, func)
30939 +diff -urNp linux-2.6.27.10/include/sound/core.h linux-2.6.27.10/include/sound/core.h
30940 +--- linux-2.6.27.10/include/sound/core.h 2008-11-07 12:55:34.000000000 -0500
30941 ++++ linux-2.6.27.10/include/sound/core.h 2008-11-18 03:38:45.000000000 -0500
30942 +@@ -406,9 +406,9 @@ void snd_verbose_printd(const char *file
30943 +
30944 + #else /* !CONFIG_SND_DEBUG */
30945 +
30946 +-#define snd_printd(fmt, args...) /* nothing */
30947 ++#define snd_printd(fmt, args...) do {} while (0)
30948 + #define snd_assert(expr, args...) (void)(expr)
30949 +-#define snd_BUG() /* nothing */
30950 ++#define snd_BUG() do {} while (0)
30951 +
30952 + #endif /* CONFIG_SND_DEBUG */
30953 +
30954 +@@ -422,7 +422,7 @@ void snd_verbose_printd(const char *file
30955 + */
30956 + #define snd_printdd(format, args...) snd_printk(format, ##args)
30957 + #else
30958 +-#define snd_printdd(format, args...) /* nothing */
30959 ++#define snd_printdd(format, args...) do {} while (0)
30960 + #endif
30961 +
30962 +
30963 +diff -urNp linux-2.6.27.10/include/video/uvesafb.h linux-2.6.27.10/include/video/uvesafb.h
30964 +--- linux-2.6.27.10/include/video/uvesafb.h 2008-11-07 12:55:34.000000000 -0500
30965 ++++ linux-2.6.27.10/include/video/uvesafb.h 2008-11-18 03:38:45.000000000 -0500
30966 +@@ -175,6 +175,7 @@ struct uvesafb_par {
30967 + u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
30968 + u8 pmi_setpal; /* PMI for palette changes */
30969 + u16 *pmi_base; /* protected mode interface location */
30970 ++ u8 *pmi_code; /* protected mode code location */
30971 + void *pmi_start;
30972 + void *pmi_pal;
30973 + u8 *vbe_state_orig; /*
30974 +diff -urNp linux-2.6.27.10/init/do_mounts.c linux-2.6.27.10/init/do_mounts.c
30975 +--- linux-2.6.27.10/init/do_mounts.c 2008-11-07 12:55:34.000000000 -0500
30976 ++++ linux-2.6.27.10/init/do_mounts.c 2008-11-18 03:38:45.000000000 -0500
30977 +@@ -214,11 +214,11 @@ static void __init get_fs_names(char *pa
30978 +
30979 + static int __init do_mount_root(char *name, char *fs, int flags, void *data)
30980 + {
30981 +- int err = sys_mount(name, "/root", fs, flags, data);
30982 ++ int err = sys_mount((char __user *)name, (char __user *)"/root", (char __user *)fs, flags, (void __user *)data);
30983 + if (err)
30984 + return err;
30985 +
30986 +- sys_chdir("/root");
30987 ++ sys_chdir((char __user *)"/root");
30988 + ROOT_DEV = current->fs->pwd.mnt->mnt_sb->s_dev;
30989 + printk("VFS: Mounted root (%s filesystem)%s.\n",
30990 + current->fs->pwd.mnt->mnt_sb->s_type->name,
30991 +@@ -304,18 +304,18 @@ void __init change_floppy(char *fmt, ...
30992 + va_start(args, fmt);
30993 + vsprintf(buf, fmt, args);
30994 + va_end(args);
30995 +- fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
30996 ++ fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
30997 + if (fd >= 0) {
30998 + sys_ioctl(fd, FDEJECT, 0);
30999 + sys_close(fd);
31000 + }
31001 + printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
31002 +- fd = sys_open("/dev/console", O_RDWR, 0);
31003 ++ fd = sys_open((char __user *)"/dev/console", O_RDWR, 0);
31004 + if (fd >= 0) {
31005 + sys_ioctl(fd, TCGETS, (long)&termios);
31006 + termios.c_lflag &= ~ICANON;
31007 + sys_ioctl(fd, TCSETSF, (long)&termios);
31008 +- sys_read(fd, &c, 1);
31009 ++ sys_read(fd, (char __user *)&c, 1);
31010 + termios.c_lflag |= ICANON;
31011 + sys_ioctl(fd, TCSETSF, (long)&termios);
31012 + sys_close(fd);
31013 +@@ -402,7 +402,7 @@ void __init prepare_namespace(void)
31014 +
31015 + mount_root();
31016 + out:
31017 +- sys_mount(".", "/", NULL, MS_MOVE, NULL);
31018 +- sys_chroot(".");
31019 ++ sys_mount((char __user *)".", (char __user *)"/", NULL, MS_MOVE, NULL);
31020 ++ sys_chroot((char __user *)".");
31021 + }
31022 +
31023 +diff -urNp linux-2.6.27.10/init/do_mounts.h linux-2.6.27.10/init/do_mounts.h
31024 +--- linux-2.6.27.10/init/do_mounts.h 2008-11-07 12:55:34.000000000 -0500
31025 ++++ linux-2.6.27.10/init/do_mounts.h 2008-11-18 03:38:45.000000000 -0500
31026 +@@ -14,15 +14,15 @@ extern int root_mountflags;
31027 +
31028 + static inline int create_dev(char *name, dev_t dev)
31029 + {
31030 +- sys_unlink(name);
31031 +- return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
31032 ++ sys_unlink((char __user *)name);
31033 ++ return sys_mknod((char __user *)name, S_IFBLK|0600, new_encode_dev(dev));
31034 + }
31035 +
31036 + #if BITS_PER_LONG == 32
31037 + static inline u32 bstat(char *name)
31038 + {
31039 + struct stat64 stat;
31040 +- if (sys_stat64(name, &stat) != 0)
31041 ++ if (sys_stat64((char __user *)name, (struct stat64 __user *)&stat) != 0)
31042 + return 0;
31043 + if (!S_ISBLK(stat.st_mode))
31044 + return 0;
31045 +diff -urNp linux-2.6.27.10/init/do_mounts_initrd.c linux-2.6.27.10/init/do_mounts_initrd.c
31046 +--- linux-2.6.27.10/init/do_mounts_initrd.c 2008-11-07 12:55:34.000000000 -0500
31047 ++++ linux-2.6.27.10/init/do_mounts_initrd.c 2008-11-18 03:38:45.000000000 -0500
31048 +@@ -32,7 +32,7 @@ static int __init do_linuxrc(void * shel
31049 + sys_close(old_fd);sys_close(root_fd);
31050 + sys_close(0);sys_close(1);sys_close(2);
31051 + sys_setsid();
31052 +- (void) sys_open("/dev/console",O_RDWR,0);
31053 ++ (void) sys_open((const char __user *)"/dev/console",O_RDWR,0);
31054 + (void) sys_dup(0);
31055 + (void) sys_dup(0);
31056 + return kernel_execve(shell, argv, envp_init);
31057 +@@ -47,13 +47,13 @@ static void __init handle_initrd(void)
31058 + create_dev("/dev/root.old", Root_RAM0);
31059 + /* mount initrd on rootfs' /root */
31060 + mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
31061 +- sys_mkdir("/old", 0700);
31062 +- root_fd = sys_open("/", 0, 0);
31063 +- old_fd = sys_open("/old", 0, 0);
31064 ++ sys_mkdir((const char __user *)"/old", 0700);
31065 ++ root_fd = sys_open((const char __user *)"/", 0, 0);
31066 ++ old_fd = sys_open((const char __user *)"/old", 0, 0);
31067 + /* move initrd over / and chdir/chroot in initrd root */
31068 +- sys_chdir("/root");
31069 +- sys_mount(".", "/", NULL, MS_MOVE, NULL);
31070 +- sys_chroot(".");
31071 ++ sys_chdir((const char __user *)"/root");
31072 ++ sys_mount((char __user *)".", (char __user *)"/", NULL, MS_MOVE, NULL);
31073 ++ sys_chroot((const char __user *)".");
31074 +
31075 + /*
31076 + * In case that a resume from disk is carried out by linuxrc or one of
31077 +@@ -70,15 +70,15 @@ static void __init handle_initrd(void)
31078 +
31079 + /* move initrd to rootfs' /old */
31080 + sys_fchdir(old_fd);
31081 +- sys_mount("/", ".", NULL, MS_MOVE, NULL);
31082 ++ sys_mount((char __user *)"/", (char __user *)".", NULL, MS_MOVE, NULL);
31083 + /* switch root and cwd back to / of rootfs */
31084 + sys_fchdir(root_fd);
31085 +- sys_chroot(".");
31086 ++ sys_chroot((const char __user *)".");
31087 + sys_close(old_fd);
31088 + sys_close(root_fd);
31089 +
31090 + if (new_decode_dev(real_root_dev) == Root_RAM0) {
31091 +- sys_chdir("/old");
31092 ++ sys_chdir((const char __user *)"/old");
31093 + return;
31094 + }
31095 +
31096 +@@ -86,17 +86,17 @@ static void __init handle_initrd(void)
31097 + mount_root();
31098 +
31099 + printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
31100 +- error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
31101 ++ error = sys_mount((char __user *)"/old", (char __user *)"/root/initrd", NULL, MS_MOVE, NULL);
31102 + if (!error)
31103 + printk("okay\n");
31104 + else {
31105 +- int fd = sys_open("/dev/root.old", O_RDWR, 0);
31106 ++ int fd = sys_open((const char __user *)"/dev/root.old", O_RDWR, 0);
31107 + if (error == -ENOENT)
31108 + printk("/initrd does not exist. Ignored.\n");
31109 + else
31110 + printk("failed\n");
31111 + printk(KERN_NOTICE "Unmounting old root\n");
31112 +- sys_umount("/old", MNT_DETACH);
31113 ++ sys_umount((char __user *)"/old", MNT_DETACH);
31114 + printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
31115 + if (fd < 0) {
31116 + error = fd;
31117 +@@ -119,11 +119,11 @@ int __init initrd_load(void)
31118 + * mounted in the normal path.
31119 + */
31120 + if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
31121 +- sys_unlink("/initrd.image");
31122 ++ sys_unlink((const char __user *)"/initrd.image");
31123 + handle_initrd();
31124 + return 1;
31125 + }
31126 + }
31127 +- sys_unlink("/initrd.image");
31128 ++ sys_unlink((const char __user *)"/initrd.image");
31129 + return 0;
31130 + }
31131 +diff -urNp linux-2.6.27.10/init/do_mounts_md.c linux-2.6.27.10/init/do_mounts_md.c
31132 +--- linux-2.6.27.10/init/do_mounts_md.c 2008-11-07 12:55:34.000000000 -0500
31133 ++++ linux-2.6.27.10/init/do_mounts_md.c 2008-11-18 03:38:45.000000000 -0500
31134 +@@ -166,7 +166,7 @@ static void __init md_setup_drive(void)
31135 + partitioned ? "_d" : "", minor,
31136 + md_setup_args[ent].device_names);
31137 +
31138 +- fd = sys_open(name, 0, 0);
31139 ++ fd = sys_open((char __user *)name, 0, 0);
31140 + if (fd < 0) {
31141 + printk(KERN_ERR "md: open failed - cannot start "
31142 + "array %s\n", name);
31143 +@@ -229,7 +229,7 @@ static void __init md_setup_drive(void)
31144 + * array without it
31145 + */
31146 + sys_close(fd);
31147 +- fd = sys_open(name, 0, 0);
31148 ++ fd = sys_open((char __user *)name, 0, 0);
31149 + sys_ioctl(fd, BLKRRPART, 0);
31150 + }
31151 + sys_close(fd);
31152 +@@ -270,7 +270,7 @@ void __init md_run_setup(void)
31153 + if (raid_noautodetect)
31154 + printk(KERN_INFO "md: Skipping autodetection of RAID arrays. (raid=noautodetect)\n");
31155 + else {
31156 +- int fd = sys_open("/dev/md0", 0, 0);
31157 ++ int fd = sys_open((char __user *)"/dev/md0", 0, 0);
31158 + if (fd >= 0) {
31159 + sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
31160 + sys_close(fd);
31161 +diff -urNp linux-2.6.27.10/init/initramfs.c linux-2.6.27.10/init/initramfs.c
31162 +--- linux-2.6.27.10/init/initramfs.c 2008-11-07 12:55:34.000000000 -0500
31163 ++++ linux-2.6.27.10/init/initramfs.c 2008-11-18 03:38:45.000000000 -0500
31164 +@@ -230,7 +230,7 @@ static int __init maybe_link(void)
31165 + if (nlink >= 2) {
31166 + char *old = find_link(major, minor, ino, mode, collected);
31167 + if (old)
31168 +- return (sys_link(old, collected) < 0) ? -1 : 1;
31169 ++ return (sys_link((char __user *)old, (char __user *)collected) < 0) ? -1 : 1;
31170 + }
31171 + return 0;
31172 + }
31173 +@@ -239,11 +239,11 @@ static void __init clean_path(char *path
31174 + {
31175 + struct stat st;
31176 +
31177 +- if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
31178 ++ if (!sys_newlstat((char __user *)path, (struct stat __user *)&st) && (st.st_mode^mode) & S_IFMT) {
31179 + if (S_ISDIR(st.st_mode))
31180 +- sys_rmdir(path);
31181 ++ sys_rmdir((char __user *)path);
31182 + else
31183 +- sys_unlink(path);
31184 ++ sys_unlink((char __user *)path);
31185 + }
31186 + }
31187 +
31188 +@@ -266,7 +266,7 @@ static int __init do_name(void)
31189 + int openflags = O_WRONLY|O_CREAT;
31190 + if (ml != 1)
31191 + openflags |= O_TRUNC;
31192 +- wfd = sys_open(collected, openflags, mode);
31193 ++ wfd = sys_open((char __user *)collected, openflags, mode);
31194 +
31195 + if (wfd >= 0) {
31196 + sys_fchown(wfd, uid, gid);
31197 +@@ -275,15 +275,15 @@ static int __init do_name(void)
31198 + }
31199 + }
31200 + } else if (S_ISDIR(mode)) {
31201 +- sys_mkdir(collected, mode);
31202 +- sys_chown(collected, uid, gid);
31203 +- sys_chmod(collected, mode);
31204 ++ sys_mkdir((char __user *)collected, mode);
31205 ++ sys_chown((char __user *)collected, uid, gid);
31206 ++ sys_chmod((char __user *)collected, mode);
31207 + } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
31208 + S_ISFIFO(mode) || S_ISSOCK(mode)) {
31209 + if (maybe_link() == 0) {
31210 +- sys_mknod(collected, mode, rdev);
31211 +- sys_chown(collected, uid, gid);
31212 +- sys_chmod(collected, mode);
31213 ++ sys_mknod((char __user *)collected, mode, rdev);
31214 ++ sys_chown((char __user *)collected, uid, gid);
31215 ++ sys_chmod((char __user *)collected, mode);
31216 + }
31217 + }
31218 + return 0;
31219 +@@ -292,13 +292,13 @@ static int __init do_name(void)
31220 + static int __init do_copy(void)
31221 + {
31222 + if (count >= body_len) {
31223 +- sys_write(wfd, victim, body_len);
31224 ++ sys_write(wfd, (char __user *)victim, body_len);
31225 + sys_close(wfd);
31226 + eat(body_len);
31227 + state = SkipIt;
31228 + return 0;
31229 + } else {
31230 +- sys_write(wfd, victim, count);
31231 ++ sys_write(wfd, (char __user *)victim, count);
31232 + body_len -= count;
31233 + eat(count);
31234 + return 1;
31235 +@@ -309,8 +309,8 @@ static int __init do_symlink(void)
31236 + {
31237 + collected[N_ALIGN(name_len) + body_len] = '\0';
31238 + clean_path(collected, 0);
31239 +- sys_symlink(collected + N_ALIGN(name_len), collected);
31240 +- sys_lchown(collected, uid, gid);
31241 ++ sys_symlink((char __user *)collected + N_ALIGN(name_len), (char __user *)collected);
31242 ++ sys_lchown((char __user *)collected, uid, gid);
31243 + state = SkipIt;
31244 + next_state = Reset;
31245 + return 0;
31246 +diff -urNp linux-2.6.27.10/init/Kconfig linux-2.6.27.10/init/Kconfig
31247 +--- linux-2.6.27.10/init/Kconfig 2008-11-07 12:55:34.000000000 -0500
31248 ++++ linux-2.6.27.10/init/Kconfig 2008-11-18 03:38:45.000000000 -0500
31249 +@@ -561,6 +561,7 @@ config SYSCTL_SYSCALL
31250 + config KALLSYMS
31251 + bool "Load all symbols for debugging/ksymoops" if EMBEDDED
31252 + default y
31253 ++ depends on !GRKERNSEC_HIDESYM
31254 + help
31255 + Say Y here to let the kernel print out symbolic crash information and
31256 + symbolic stack backtraces. This increases the size of the kernel
31257 +@@ -780,8 +781,8 @@ config MARKERS
31258 + source "arch/Kconfig"
31259 +
31260 + config PROC_PAGE_MONITOR
31261 +- default y
31262 +- depends on PROC_FS && MMU
31263 ++ default n
31264 ++ depends on PROC_FS && MMU && !GRKERNSEC
31265 + bool "Enable /proc page monitoring" if EMBEDDED
31266 + help
31267 + Various /proc files exist to monitor process memory utilization:
31268 +@@ -797,9 +798,9 @@ config HAVE_GENERIC_DMA_COHERENT
31269 +
31270 + config SLABINFO
31271 + bool
31272 +- depends on PROC_FS
31273 ++ depends on PROC_FS && !GRKERNSEC_PROC_ADD
31274 + depends on SLAB || SLUB_DEBUG
31275 +- default y
31276 ++ default n
31277 +
31278 + config RT_MUTEXES
31279 + boolean
31280 +diff -urNp linux-2.6.27.10/init/main.c linux-2.6.27.10/init/main.c
31281 +--- linux-2.6.27.10/init/main.c 2008-11-07 12:55:34.000000000 -0500
31282 ++++ linux-2.6.27.10/init/main.c 2008-11-18 03:38:45.000000000 -0500
31283 +@@ -101,6 +101,7 @@ static inline void mark_rodata_ro(void)
31284 + #ifdef CONFIG_TC
31285 + extern void tc_init(void);
31286 + #endif
31287 ++extern void grsecurity_init(void);
31288 +
31289 + enum system_states system_state;
31290 + EXPORT_SYMBOL(system_state);
31291 +@@ -187,6 +188,40 @@ static int __init set_reset_devices(char
31292 +
31293 + __setup("reset_devices", set_reset_devices);
31294 +
31295 ++#if defined(CONFIG_PAX_MEMORY_UDEREF) && defined(CONFIG_X86_32)
31296 ++static int __init setup_pax_nouderef(char *str)
31297 ++{
31298 ++ unsigned int cpu;
31299 ++
31300 ++#ifdef CONFIG_PAX_KERNEXEC
31301 ++ unsigned long cr0;
31302 ++
31303 ++ pax_open_kernel(cr0);
31304 ++#endif
31305 ++
31306 ++ for (cpu = 0; cpu < NR_CPUS; cpu++)
31307 ++ get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_DS].b = 0x00cf9300;
31308 ++
31309 ++#ifdef CONFIG_PAX_KERNEXEC
31310 ++ pax_close_kernel(cr0);
31311 ++#endif
31312 ++
31313 ++ return 1;
31314 ++}
31315 ++__setup("pax_nouderef", setup_pax_nouderef);
31316 ++#endif
31317 ++
31318 ++#ifdef CONFIG_PAX_SOFTMODE
31319 ++unsigned int pax_softmode;
31320 ++
31321 ++static int __init setup_pax_softmode(char *str)
31322 ++{
31323 ++ get_option(&str, &pax_softmode);
31324 ++ return 1;
31325 ++}
31326 ++__setup("pax_softmode=", setup_pax_softmode);
31327 ++#endif
31328 ++
31329 + static char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
31330 + char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
31331 + static const char *panic_later, *panic_param;
31332 +@@ -385,7 +420,7 @@ static void __init setup_nr_cpu_ids(void
31333 + }
31334 +
31335 + #ifndef CONFIG_HAVE_SETUP_PER_CPU_AREA
31336 +-unsigned long __per_cpu_offset[NR_CPUS] __read_mostly;
31337 ++unsigned long __per_cpu_offset[NR_CPUS] __read_only;
31338 +
31339 + EXPORT_SYMBOL(__per_cpu_offset);
31340 +
31341 +@@ -704,6 +739,7 @@ int do_one_initcall(initcall_t fn)
31342 + {
31343 + int count = preempt_count();
31344 + ktime_t t0, t1, delta;
31345 ++ const char *msg1 = "", *msg2 = "";
31346 + char msgbuf[64];
31347 + int result;
31348 +
31349 +@@ -729,15 +765,15 @@ int do_one_initcall(initcall_t fn)
31350 + sprintf(msgbuf, "error code %d ", result);
31351 +
31352 + if (preempt_count() != count) {
31353 +- strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
31354 ++ msg1 = " preemption imbalance";
31355 + preempt_count() = count;
31356 + }
31357 + if (irqs_disabled()) {
31358 +- strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
31359 ++ msg2 = " disabled interrupts";
31360 + local_irq_enable();
31361 + }
31362 +- if (msgbuf[0]) {
31363 +- printk("initcall %pF returned with %s\n", fn, msgbuf);
31364 ++ if (msgbuf[0] || *msg1 || *msg2) {
31365 ++ printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
31366 + }
31367 +
31368 + return result;
31369 +@@ -876,6 +912,8 @@ static int __init kernel_init(void * unu
31370 + prepare_namespace();
31371 + }
31372 +
31373 ++ grsecurity_init();
31374 ++
31375 + /*
31376 + * Ok, we have completed the initial bootup, and
31377 + * we're essentially up and running. Get rid of the
31378 +diff -urNp linux-2.6.27.10/init/noinitramfs.c linux-2.6.27.10/init/noinitramfs.c
31379 +--- linux-2.6.27.10/init/noinitramfs.c 2008-11-07 12:55:34.000000000 -0500
31380 ++++ linux-2.6.27.10/init/noinitramfs.c 2008-11-18 03:38:45.000000000 -0500
31381 +@@ -29,7 +29,7 @@ static int __init default_rootfs(void)
31382 + {
31383 + int err;
31384 +
31385 +- err = sys_mkdir("/dev", 0755);
31386 ++ err = sys_mkdir((const char __user *)"/dev", 0755);
31387 + if (err < 0)
31388 + goto out;
31389 +
31390 +@@ -39,7 +39,7 @@ static int __init default_rootfs(void)
31391 + if (err < 0)
31392 + goto out;
31393 +
31394 +- err = sys_mkdir("/root", 0700);
31395 ++ err = sys_mkdir((const char __user *)"/root", 0700);
31396 + if (err < 0)
31397 + goto out;
31398 +
31399 +diff -urNp linux-2.6.27.10/ipc/ipc_sysctl.c linux-2.6.27.10/ipc/ipc_sysctl.c
31400 +--- linux-2.6.27.10/ipc/ipc_sysctl.c 2008-11-07 12:55:34.000000000 -0500
31401 ++++ linux-2.6.27.10/ipc/ipc_sysctl.c 2008-11-18 03:38:45.000000000 -0500
31402 +@@ -268,7 +268,7 @@ static struct ctl_table ipc_kern_table[]
31403 + .extra1 = &zero,
31404 + .extra2 = &one,
31405 + },
31406 +- {}
31407 ++ { 0, NULL, NULL, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL }
31408 + };
31409 +
31410 + static struct ctl_table ipc_root_table[] = {
31411 +@@ -278,7 +278,7 @@ static struct ctl_table ipc_root_table[]
31412 + .mode = 0555,
31413 + .child = ipc_kern_table,
31414 + },
31415 +- {}
31416 ++ { 0, NULL, NULL, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL }
31417 + };
31418 +
31419 + static int __init ipc_sysctl_init(void)
31420 +diff -urNp linux-2.6.27.10/ipc/msg.c linux-2.6.27.10/ipc/msg.c
31421 +--- linux-2.6.27.10/ipc/msg.c 2008-11-07 12:55:34.000000000 -0500
31422 ++++ linux-2.6.27.10/ipc/msg.c 2008-11-18 03:38:45.000000000 -0500
31423 +@@ -38,6 +38,7 @@
31424 + #include <linux/rwsem.h>
31425 + #include <linux/nsproxy.h>
31426 + #include <linux/ipc_namespace.h>
31427 ++#include <linux/grsecurity.h>
31428 +
31429 + #include <asm/current.h>
31430 + #include <asm/uaccess.h>
31431 +@@ -314,6 +315,7 @@ asmlinkage long sys_msgget(key_t key, in
31432 + struct ipc_namespace *ns;
31433 + struct ipc_ops msg_ops;
31434 + struct ipc_params msg_params;
31435 ++ long err;
31436 +
31437 + ns = current->nsproxy->ipc_ns;
31438 +
31439 +@@ -324,7 +326,11 @@ asmlinkage long sys_msgget(key_t key, in
31440 + msg_params.key = key;
31441 + msg_params.flg = msgflg;
31442 +
31443 +- return ipcget(ns, &msg_ids(ns), &msg_ops, &msg_params);
31444 ++ err = ipcget(ns, &msg_ids(ns), &msg_ops, &msg_params);
31445 ++
31446 ++ gr_log_msgget(err, msgflg);
31447 ++
31448 ++ return err;
31449 + }
31450 +
31451 + static inline unsigned long
31452 +@@ -434,6 +440,7 @@ static int msgctl_down(struct ipc_namesp
31453 +
31454 + switch (cmd) {
31455 + case IPC_RMID:
31456 ++ gr_log_msgrm(ipcp->uid, ipcp->cuid);
31457 + freeque(ns, ipcp);
31458 + goto out_up;
31459 + case IPC_SET:
31460 +diff -urNp linux-2.6.27.10/ipc/sem.c linux-2.6.27.10/ipc/sem.c
31461 +--- linux-2.6.27.10/ipc/sem.c 2008-11-07 12:55:34.000000000 -0500
31462 ++++ linux-2.6.27.10/ipc/sem.c 2008-11-18 03:38:45.000000000 -0500
31463 +@@ -83,6 +83,7 @@
31464 + #include <linux/rwsem.h>
31465 + #include <linux/nsproxy.h>
31466 + #include <linux/ipc_namespace.h>
31467 ++#include <linux/grsecurity.h>
31468 +
31469 + #include <asm/uaccess.h>
31470 + #include "util.h"
31471 +@@ -313,6 +314,7 @@ asmlinkage long sys_semget(key_t key, in
31472 + struct ipc_namespace *ns;
31473 + struct ipc_ops sem_ops;
31474 + struct ipc_params sem_params;
31475 ++ long err;
31476 +
31477 + ns = current->nsproxy->ipc_ns;
31478 +
31479 +@@ -327,7 +329,11 @@ asmlinkage long sys_semget(key_t key, in
31480 + sem_params.flg = semflg;
31481 + sem_params.u.nsems = nsems;
31482 +
31483 +- return ipcget(ns, &sem_ids(ns), &sem_ops, &sem_params);
31484 ++ err = ipcget(ns, &sem_ids(ns), &sem_ops, &sem_params);
31485 ++
31486 ++ gr_log_semget(err, semflg);
31487 ++
31488 ++ return err;
31489 + }
31490 +
31491 + /*
31492 +@@ -870,6 +876,7 @@ static int semctl_down(struct ipc_namesp
31493 +
31494 + switch(cmd){
31495 + case IPC_RMID:
31496 ++ gr_log_semrm(ipcp->uid, ipcp->cuid);
31497 + freeary(ns, ipcp);
31498 + goto out_up;
31499 + case IPC_SET:
31500 +diff -urNp linux-2.6.27.10/ipc/shm.c linux-2.6.27.10/ipc/shm.c
31501 +--- linux-2.6.27.10/ipc/shm.c 2008-11-07 12:55:34.000000000 -0500
31502 ++++ linux-2.6.27.10/ipc/shm.c 2008-11-18 03:38:45.000000000 -0500
31503 +@@ -39,6 +39,7 @@
31504 + #include <linux/nsproxy.h>
31505 + #include <linux/mount.h>
31506 + #include <linux/ipc_namespace.h>
31507 ++#include <linux/grsecurity.h>
31508 +
31509 + #include <asm/uaccess.h>
31510 +
31511 +@@ -69,6 +70,14 @@ static void shm_destroy (struct ipc_name
31512 + static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
31513 + #endif
31514 +
31515 ++#ifdef CONFIG_GRKERNSEC
31516 ++extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
31517 ++ const time_t shm_createtime, const uid_t cuid,
31518 ++ const int shmid);
31519 ++extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
31520 ++ const time_t shm_createtime);
31521 ++#endif
31522 ++
31523 + void shm_init_ns(struct ipc_namespace *ns)
31524 + {
31525 + ns->shm_ctlmax = SHMMAX;
31526 +@@ -87,6 +96,8 @@ static void do_shm_rmid(struct ipc_names
31527 + struct shmid_kernel *shp;
31528 + shp = container_of(ipcp, struct shmid_kernel, shm_perm);
31529 +
31530 ++ gr_log_shmrm(shp->shm_perm.uid, shp->shm_perm.cuid);
31531 ++
31532 + if (shp->shm_nattch){
31533 + shp->shm_perm.mode |= SHM_DEST;
31534 + /* Do not find it any more */
31535 +@@ -392,6 +403,14 @@ static int newseg(struct ipc_namespace *
31536 + shp->shm_lprid = 0;
31537 + shp->shm_atim = shp->shm_dtim = 0;
31538 + shp->shm_ctim = get_seconds();
31539 ++#ifdef CONFIG_GRKERNSEC
31540 ++ {
31541 ++ struct timespec timeval;
31542 ++ do_posix_clock_monotonic_gettime(&timeval);
31543 ++
31544 ++ shp->shm_createtime = timeval.tv_sec;
31545 ++ }
31546 ++#endif
31547 + shp->shm_segsz = size;
31548 + shp->shm_nattch = 0;
31549 + shp->shm_file = file;
31550 +@@ -445,6 +464,7 @@ asmlinkage long sys_shmget (key_t key, s
31551 + struct ipc_namespace *ns;
31552 + struct ipc_ops shm_ops;
31553 + struct ipc_params shm_params;
31554 ++ long err;
31555 +
31556 + ns = current->nsproxy->ipc_ns;
31557 +
31558 +@@ -456,7 +476,11 @@ asmlinkage long sys_shmget (key_t key, s
31559 + shm_params.flg = shmflg;
31560 + shm_params.u.size = size;
31561 +
31562 +- return ipcget(ns, &shm_ids(ns), &shm_ops, &shm_params);
31563 ++ err = ipcget(ns, &shm_ids(ns), &shm_ops, &shm_params);
31564 ++
31565 ++ gr_log_shmget(err, shmflg, size);
31566 ++
31567 ++ return err;
31568 + }
31569 +
31570 + static inline unsigned long copy_shmid_to_user(void __user *buf, struct shmid64_ds *in, int version)
31571 +@@ -869,9 +893,21 @@ long do_shmat(int shmid, char __user *sh
31572 + if (err)
31573 + goto out_unlock;
31574 +
31575 ++#ifdef CONFIG_GRKERNSEC
31576 ++ if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
31577 ++ shp->shm_perm.cuid, shmid) ||
31578 ++ !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
31579 ++ err = -EACCES;
31580 ++ goto out_unlock;
31581 ++ }
31582 ++#endif
31583 ++
31584 + path.dentry = dget(shp->shm_file->f_path.dentry);
31585 + path.mnt = shp->shm_file->f_path.mnt;
31586 + shp->shm_nattch++;
31587 ++#ifdef CONFIG_GRKERNSEC
31588 ++ shp->shm_lapid = current->pid;
31589 ++#endif
31590 + size = i_size_read(path.dentry->d_inode);
31591 + shm_unlock(shp);
31592 +
31593 +diff -urNp linux-2.6.27.10/kernel/acct.c linux-2.6.27.10/kernel/acct.c
31594 +--- linux-2.6.27.10/kernel/acct.c 2008-11-07 12:55:34.000000000 -0500
31595 ++++ linux-2.6.27.10/kernel/acct.c 2008-11-18 03:38:45.000000000 -0500
31596 +@@ -573,7 +573,7 @@ static void do_acct_process(struct bsd_a
31597 + */
31598 + flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
31599 + current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
31600 +- file->f_op->write(file, (char *)&ac,
31601 ++ file->f_op->write(file, (char __user *)&ac,
31602 + sizeof(acct_t), &file->f_pos);
31603 + current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
31604 + set_fs(fs);
31605 +diff -urNp linux-2.6.27.10/kernel/capability.c linux-2.6.27.10/kernel/capability.c
31606 +--- linux-2.6.27.10/kernel/capability.c 2008-11-07 12:55:34.000000000 -0500
31607 ++++ linux-2.6.27.10/kernel/capability.c 2008-11-18 03:38:45.000000000 -0500
31608 +@@ -13,6 +13,7 @@
31609 + #include <linux/security.h>
31610 + #include <linux/syscalls.h>
31611 + #include <linux/pid_namespace.h>
31612 ++#include <linux/grsecurity.h>
31613 + #include <asm/uaccess.h>
31614 +
31615 + /*
31616 +@@ -498,10 +499,21 @@ asmlinkage long sys_capset(cap_user_head
31617 + */
31618 + int capable(int cap)
31619 + {
31620 +- if (has_capability(current, cap)) {
31621 ++ if (has_capability(current, cap) && gr_task_is_capable(current, cap)) {
31622 + current->flags |= PF_SUPERPRIV;
31623 + return 1;
31624 + }
31625 + return 0;
31626 + }
31627 ++
31628 ++int capable_nolog(int cap)
31629 ++{
31630 ++ if (has_capability(current, cap) && gr_is_capable_nolog(cap)) {
31631 ++ current->flags |= PF_SUPERPRIV;
31632 ++ return 1;
31633 ++ }
31634 ++ return 0;
31635 ++}
31636 ++
31637 + EXPORT_SYMBOL(capable);
31638 ++EXPORT_SYMBOL(capable_nolog);
31639 +diff -urNp linux-2.6.27.10/kernel/configs.c linux-2.6.27.10/kernel/configs.c
31640 +--- linux-2.6.27.10/kernel/configs.c 2008-11-07 12:55:34.000000000 -0500
31641 ++++ linux-2.6.27.10/kernel/configs.c 2008-11-18 03:38:45.000000000 -0500
31642 +@@ -79,8 +79,19 @@ static int __init ikconfig_init(void)
31643 + struct proc_dir_entry *entry;
31644 +
31645 + /* create the current config file */
31646 ++#ifdef CONFIG_GRKERNSEC_PROC_ADD
31647 ++#ifdef CONFIG_GRKERNSEC_PROC_USER
31648 ++ entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
31649 ++ &ikconfig_file_ops);
31650 ++#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
31651 ++ entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
31652 ++ &ikconfig_file_ops);
31653 ++#endif
31654 ++#else
31655 + entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
31656 + &ikconfig_file_ops);
31657 ++#endif
31658 ++
31659 + if (!entry)
31660 + return -ENOMEM;
31661 +
31662 +diff -urNp linux-2.6.27.10/kernel/cpu.c linux-2.6.27.10/kernel/cpu.c
31663 +--- linux-2.6.27.10/kernel/cpu.c 2008-11-07 12:55:34.000000000 -0500
31664 ++++ linux-2.6.27.10/kernel/cpu.c 2008-11-18 03:38:45.000000000 -0500
31665 +@@ -40,7 +40,7 @@ EXPORT_SYMBOL(cpu_possible_map);
31666 + /* Serializes the updates to cpu_online_map, cpu_present_map */
31667 + static DEFINE_MUTEX(cpu_add_remove_lock);
31668 +
31669 +-static __cpuinitdata RAW_NOTIFIER_HEAD(cpu_chain);
31670 ++static RAW_NOTIFIER_HEAD(cpu_chain);
31671 +
31672 + /* If set, cpu_up and cpu_down will return -EBUSY and do nothing.
31673 + * Should always be manipulated under cpu_add_remove_lock
31674 +diff -urNp linux-2.6.27.10/kernel/exit.c linux-2.6.27.10/kernel/exit.c
31675 +--- linux-2.6.27.10/kernel/exit.c 2008-11-07 12:55:34.000000000 -0500
31676 ++++ linux-2.6.27.10/kernel/exit.c 2008-11-29 19:01:27.000000000 -0500
31677 +@@ -40,13 +40,17 @@
31678 + #include <linux/cn_proc.h>
31679 + #include <linux/mutex.h>
31680 + #include <linux/futex.h>
31681 +-#include <linux/compat.h>
31682 + #include <linux/pipe_fs_i.h>
31683 + #include <linux/audit.h> /* for audit_free() */
31684 + #include <linux/resource.h>
31685 + #include <linux/blkdev.h>
31686 + #include <linux/task_io_accounting_ops.h>
31687 + #include <linux/tracehook.h>
31688 ++#include <linux/grsecurity.h>
31689 ++
31690 ++#ifdef CONFIG_GRKERNSEC
31691 ++extern rwlock_t grsec_exec_file_lock;
31692 ++#endif
31693 +
31694 + #include <asm/uaccess.h>
31695 + #include <asm/unistd.h>
31696 +@@ -133,7 +137,6 @@ static void __exit_signal(struct task_st
31697 + * doing sigqueue_free() if we have SIGQUEUE_PREALLOC signals.
31698 + */
31699 + flush_sigqueue(&tsk->pending);
31700 +-
31701 + tsk->signal = NULL;
31702 + tsk->sighand = NULL;
31703 + spin_unlock(&sighand->siglock);
31704 +@@ -158,6 +161,8 @@ void release_task(struct task_struct * p
31705 + struct task_struct *leader;
31706 + int zap_leader;
31707 + repeat:
31708 ++ gr_del_task_from_ip_table(p);
31709 ++
31710 + tracehook_prepare_release_task(p);
31711 + atomic_dec(&p->user->processes);
31712 + proc_flush_task(p);
31713 +@@ -321,11 +326,22 @@ static void reparent_to_kthreadd(void)
31714 + {
31715 + write_lock_irq(&tasklist_lock);
31716 +
31717 ++#ifdef CONFIG_GRKERNSEC
31718 ++ write_lock(&grsec_exec_file_lock);
31719 ++ if (current->exec_file) {
31720 ++ fput(current->exec_file);
31721 ++ current->exec_file = NULL;
31722 ++ }
31723 ++ write_unlock(&grsec_exec_file_lock);
31724 ++#endif
31725 ++
31726 + ptrace_unlink(current);
31727 + /* Reparent to init */
31728 + current->real_parent = current->parent = kthreadd_task;
31729 + list_move_tail(&current->sibling, &current->real_parent->children);
31730 +
31731 ++ gr_set_kernel_label(current);
31732 ++
31733 + /* Set the exit signal to SIGCHLD so we signal init on exit */
31734 + current->exit_signal = SIGCHLD;
31735 +
31736 +@@ -419,6 +435,17 @@ void daemonize(const char *name, ...)
31737 + vsnprintf(current->comm, sizeof(current->comm), name, args);
31738 + va_end(args);
31739 +
31740 ++#ifdef CONFIG_GRKERNSEC
31741 ++ write_lock(&grsec_exec_file_lock);
31742 ++ if (current->exec_file) {
31743 ++ fput(current->exec_file);
31744 ++ current->exec_file = NULL;
31745 ++ }
31746 ++ write_unlock(&grsec_exec_file_lock);
31747 ++#endif
31748 ++
31749 ++ gr_set_kernel_label(current);
31750 ++
31751 + /*
31752 + * If we were started as result of loading a module, close all of the
31753 + * user space pages. We don't need them, and if we didn't close them
31754 +@@ -1054,14 +1081,6 @@ NORET_TYPE void do_exit(long code)
31755 + exit_itimers(tsk->signal);
31756 + }
31757 + acct_collect(code, group_dead);
31758 +-#ifdef CONFIG_FUTEX
31759 +- if (unlikely(tsk->robust_list))
31760 +- exit_robust_list(tsk);
31761 +-#ifdef CONFIG_COMPAT
31762 +- if (unlikely(tsk->compat_robust_list))
31763 +- compat_exit_robust_list(tsk);
31764 +-#endif
31765 +-#endif
31766 + if (group_dead)
31767 + tty_audit_exit();
31768 + if (unlikely(tsk->audit_context))
31769 +@@ -1070,6 +1089,9 @@ NORET_TYPE void do_exit(long code)
31770 + tsk->exit_code = code;
31771 + taskstats_exit(tsk, group_dead);
31772 +
31773 ++ gr_acl_handle_psacct(tsk, code);
31774 ++ gr_acl_handle_exit();
31775 ++
31776 + exit_mm(tsk);
31777 +
31778 + if (group_dead)
31779 +@@ -1272,7 +1294,7 @@ static int wait_task_zombie(struct task_
31780 + if (unlikely(options & WNOWAIT)) {
31781 + uid_t uid = p->uid;
31782 + int exit_code = p->exit_code;
31783 +- int why, status;
31784 ++ int why;
31785 +
31786 + get_task_struct(p);
31787 + read_unlock(&tasklist_lock);
31788 +diff -urNp linux-2.6.27.10/kernel/fork.c linux-2.6.27.10/kernel/fork.c
31789 +--- linux-2.6.27.10/kernel/fork.c 2008-12-21 01:16:52.000000000 -0500
31790 ++++ linux-2.6.27.10/kernel/fork.c 2008-12-21 01:13:46.000000000 -0500
31791 +@@ -40,6 +40,7 @@
31792 + #include <linux/jiffies.h>
31793 + #include <linux/tracehook.h>
31794 + #include <linux/futex.h>
31795 ++#include <linux/compat.h>
31796 + #include <linux/task_io_accounting_ops.h>
31797 + #include <linux/rcupdate.h>
31798 + #include <linux/ptrace.h>
31799 +@@ -58,6 +59,7 @@
31800 + #include <linux/tty.h>
31801 + #include <linux/proc_fs.h>
31802 + #include <linux/blkdev.h>
31803 ++#include <linux/grsecurity.h>
31804 +
31805 + #include <asm/pgtable.h>
31806 + #include <asm/pgalloc.h>
31807 +@@ -234,7 +236,7 @@ static struct task_struct *dup_task_stru
31808 + setup_thread_stack(tsk, orig);
31809 +
31810 + #ifdef CONFIG_CC_STACKPROTECTOR
31811 +- tsk->stack_canary = get_random_int();
31812 ++ tsk->stack_canary = pax_get_random_long();
31813 + #endif
31814 +
31815 + /* One for us, one for whoever does the "release_task()" (usually parent) */
31816 +@@ -271,8 +273,8 @@ static int dup_mmap(struct mm_struct *mm
31817 + mm->locked_vm = 0;
31818 + mm->mmap = NULL;
31819 + mm->mmap_cache = NULL;
31820 +- mm->free_area_cache = oldmm->mmap_base;
31821 +- mm->cached_hole_size = ~0UL;
31822 ++ mm->free_area_cache = oldmm->free_area_cache;
31823 ++ mm->cached_hole_size = oldmm->cached_hole_size;
31824 + mm->map_count = 0;
31825 + cpus_clear(mm->cpu_vm_mask);
31826 + mm->mm_rb = RB_ROOT;
31827 +@@ -309,6 +311,7 @@ static int dup_mmap(struct mm_struct *mm
31828 + tmp->vm_flags &= ~VM_LOCKED;
31829 + tmp->vm_mm = mm;
31830 + tmp->vm_next = NULL;
31831 ++ tmp->vm_mirror = NULL;
31832 + anon_vma_link(tmp);
31833 + file = tmp->vm_file;
31834 + if (file) {
31835 +@@ -356,6 +359,31 @@ static int dup_mmap(struct mm_struct *mm
31836 + if (retval)
31837 + goto out;
31838 + }
31839 ++
31840 ++#ifdef CONFIG_PAX_SEGMEXEC
31841 ++ if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
31842 ++ struct vm_area_struct *mpnt_m;
31843 ++
31844 ++ for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
31845 ++ BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
31846 ++
31847 ++ if (!mpnt->vm_mirror)
31848 ++ continue;
31849 ++
31850 ++ if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
31851 ++ BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
31852 ++ mpnt->vm_mirror = mpnt_m;
31853 ++ } else {
31854 ++ BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
31855 ++ mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
31856 ++ mpnt_m->vm_mirror->vm_mirror = mpnt_m;
31857 ++ mpnt->vm_mirror->vm_mirror = mpnt;
31858 ++ }
31859 ++ }
31860 ++ BUG_ON(mpnt_m);
31861 ++ }
31862 ++#endif
31863 ++
31864 + /* a new mm has just been created */
31865 + arch_dup_mmap(oldmm, mm);
31866 + retval = 0;
31867 +@@ -521,6 +549,18 @@ void mm_release(struct task_struct *tsk,
31868 + {
31869 + struct completion *vfork_done = tsk->vfork_done;
31870 +
31871 ++ /* Get rid of any futexes when releasing the mm */
31872 ++#ifdef CONFIG_FUTEX
31873 ++ if (unlikely(tsk->robust_list))
31874 ++ exit_robust_list(tsk);
31875 ++ tsk->robust_list = NULL;
31876 ++#ifdef CONFIG_COMPAT
31877 ++ if (unlikely(tsk->compat_robust_list))
31878 ++ compat_exit_robust_list(tsk);
31879 ++ tsk->compat_robust_list = NULL;
31880 ++#endif
31881 ++#endif
31882 ++
31883 + /* Get rid of any cached register state */
31884 + deactivate_mm(tsk, mm);
31885 +
31886 +@@ -539,7 +579,7 @@ void mm_release(struct task_struct *tsk,
31887 + if (tsk->clear_child_tid
31888 + && !(tsk->flags & PF_SIGNALED)
31889 + && atomic_read(&mm->mm_users) > 1) {
31890 +- u32 __user * tidptr = tsk->clear_child_tid;
31891 ++ pid_t __user * tidptr = tsk->clear_child_tid;
31892 + tsk->clear_child_tid = NULL;
31893 +
31894 + /*
31895 +@@ -547,7 +587,7 @@ void mm_release(struct task_struct *tsk,
31896 + * not set up a proper pointer then tough luck.
31897 + */
31898 + put_user(0, tidptr);
31899 +- sys_futex(tidptr, FUTEX_WAKE, 1, NULL, NULL, 0);
31900 ++ sys_futex((u32 __user *)tidptr, FUTEX_WAKE, 1, NULL, NULL, 0);
31901 + }
31902 + }
31903 +
31904 +@@ -942,6 +982,9 @@ static struct task_struct *copy_process(
31905 + DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
31906 + #endif
31907 + retval = -EAGAIN;
31908 ++
31909 ++ gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->user->processes), 0);
31910 ++
31911 + if (atomic_read(&p->user->processes) >=
31912 + p->signal->rlim[RLIMIT_NPROC].rlim_cur) {
31913 + if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
31914 +@@ -1108,6 +1151,8 @@ static struct task_struct *copy_process(
31915 + goto bad_fork_free_pid;
31916 + }
31917 +
31918 ++ gr_copy_label(p);
31919 ++
31920 + p->set_child_tid = (clone_flags & CLONE_CHILD_SETTID) ? child_tidptr : NULL;
31921 + /*
31922 + * Clear TID on mm_release()?
31923 +@@ -1293,6 +1338,8 @@ bad_fork_cleanup_count:
31924 + bad_fork_free:
31925 + free_task(p);
31926 + fork_out:
31927 ++ gr_log_forkfail(retval);
31928 ++
31929 + return ERR_PTR(retval);
31930 + }
31931 +
31932 +@@ -1369,6 +1416,8 @@ long do_fork(unsigned long clone_flags,
31933 + if (clone_flags & CLONE_PARENT_SETTID)
31934 + put_user(nr, parent_tidptr);
31935 +
31936 ++ gr_handle_brute_check();
31937 ++
31938 + if (clone_flags & CLONE_VFORK) {
31939 + p->vfork_done = &vfork;
31940 + init_completion(&vfork);
31941 +diff -urNp linux-2.6.27.10/kernel/futex.c linux-2.6.27.10/kernel/futex.c
31942 +--- linux-2.6.27.10/kernel/futex.c 2008-11-07 12:55:34.000000000 -0500
31943 ++++ linux-2.6.27.10/kernel/futex.c 2008-11-18 03:38:45.000000000 -0500
31944 +@@ -188,6 +188,11 @@ static int get_futex_key(u32 __user *uad
31945 + struct page *page;
31946 + int err;
31947 +
31948 ++#ifdef CONFIG_PAX_SEGMEXEC
31949 ++ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
31950 ++ return -EFAULT;
31951 ++#endif
31952 ++
31953 + /*
31954 + * The futex address must be "naturally" aligned.
31955 + */
31956 +@@ -214,8 +219,8 @@ static int get_futex_key(u32 __user *uad
31957 + * The futex is hashed differently depending on whether
31958 + * it's in a shared or private mapping. So check vma first.
31959 + */
31960 +- vma = find_extend_vma(mm, address);
31961 +- if (unlikely(!vma))
31962 ++ vma = find_vma(mm, address);
31963 ++ if (unlikely(!vma || address < vma->vm_start))
31964 + return -EFAULT;
31965 +
31966 + /*
31967 +@@ -1345,7 +1350,7 @@ static int futex_wait(u32 __user *uaddr,
31968 + struct restart_block *restart;
31969 + restart = &current_thread_info()->restart_block;
31970 + restart->fn = futex_wait_restart;
31971 +- restart->futex.uaddr = (u32 *)uaddr;
31972 ++ restart->futex.uaddr = uaddr;
31973 + restart->futex.val = val;
31974 + restart->futex.time = abs_time->tv64;
31975 + restart->futex.bitset = bitset;
31976 +@@ -1906,7 +1911,7 @@ retry:
31977 + */
31978 + static inline int fetch_robust_entry(struct robust_list __user **entry,
31979 + struct robust_list __user * __user *head,
31980 +- int *pi)
31981 ++ unsigned int *pi)
31982 + {
31983 + unsigned long uentry;
31984 +
31985 +diff -urNp linux-2.6.27.10/kernel/irq/handle.c linux-2.6.27.10/kernel/irq/handle.c
31986 +--- linux-2.6.27.10/kernel/irq/handle.c 2008-11-07 12:55:34.000000000 -0500
31987 ++++ linux-2.6.27.10/kernel/irq/handle.c 2008-11-18 03:38:45.000000000 -0500
31988 +@@ -55,7 +55,8 @@ struct irq_desc irq_desc[NR_IRQS] __cach
31989 + .depth = 1,
31990 + .lock = __SPIN_LOCK_UNLOCKED(irq_desc->lock),
31991 + #ifdef CONFIG_SMP
31992 +- .affinity = CPU_MASK_ALL
31993 ++ .affinity = CPU_MASK_ALL,
31994 ++ .cpu = 0,
31995 + #endif
31996 + }
31997 + };
31998 +diff -urNp linux-2.6.27.10/kernel/kallsyms.c linux-2.6.27.10/kernel/kallsyms.c
31999 +--- linux-2.6.27.10/kernel/kallsyms.c 2008-11-07 12:55:34.000000000 -0500
32000 ++++ linux-2.6.27.10/kernel/kallsyms.c 2008-11-18 03:38:45.000000000 -0500
32001 +@@ -62,6 +62,19 @@ static inline int is_kernel_text(unsigne
32002 +
32003 + static inline int is_kernel(unsigned long addr)
32004 + {
32005 ++
32006 ++#ifdef CONFIG_PAX_KERNEXEC
32007 ++
32008 ++#ifdef CONFIG_MODULES
32009 ++ if ((unsigned long)MODULES_VADDR <= ktla_ktva(addr) &&
32010 ++ ktla_ktva(addr) < (unsigned long)MODULES_END)
32011 ++ return 0;
32012 ++#endif
32013 ++
32014 ++ if (is_kernel_inittext(addr))
32015 ++ return 1;
32016 ++#endif
32017 ++
32018 + if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
32019 + return 1;
32020 + return in_gate_area_no_task(addr);
32021 +@@ -366,7 +379,6 @@ static unsigned long get_ksymbol_core(st
32022 +
32023 + static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
32024 + {
32025 +- iter->name[0] = '\0';
32026 + iter->nameoff = get_symbol_offset(new_pos);
32027 + iter->pos = new_pos;
32028 + }
32029 +@@ -450,7 +462,7 @@ static int kallsyms_open(struct inode *i
32030 + struct kallsym_iter *iter;
32031 + int ret;
32032 +
32033 +- iter = kmalloc(sizeof(*iter), GFP_KERNEL);
32034 ++ iter = kzalloc(sizeof(*iter), GFP_KERNEL);
32035 + if (!iter)
32036 + return -ENOMEM;
32037 + reset_iter(iter, 0);
32038 +@@ -472,7 +484,15 @@ static const struct file_operations kall
32039 +
32040 + static int __init kallsyms_init(void)
32041 + {
32042 ++#ifdef CONFIG_GRKERNSEC_PROC_ADD
32043 ++#ifdef CONFIG_GRKERNSEC_PROC_USER
32044 ++ proc_create("kallsyms", S_IFREG | S_IRUSR, NULL, &kallsyms_operations);
32045 ++#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
32046 ++ proc_create("kallsyms", S_IFREG | S_IRUSR | S_IRGRP, NULL, &kallsyms_operations);
32047 ++#endif
32048 ++#else
32049 + proc_create("kallsyms", 0444, NULL, &kallsyms_operations);
32050 ++#endif
32051 + return 0;
32052 + }
32053 + __initcall(kallsyms_init);
32054 +diff -urNp linux-2.6.27.10/kernel/kmod.c linux-2.6.27.10/kernel/kmod.c
32055 +--- linux-2.6.27.10/kernel/kmod.c 2008-11-07 12:55:34.000000000 -0500
32056 ++++ linux-2.6.27.10/kernel/kmod.c 2008-11-18 03:38:45.000000000 -0500
32057 +@@ -108,7 +108,7 @@ int request_module(const char *fmt, ...)
32058 + return -ENOMEM;
32059 + }
32060 +
32061 +- ret = call_usermodehelper(modprobe_path, argv, envp, 1);
32062 ++ ret = call_usermodehelper(modprobe_path, argv, envp, UMH_WAIT_PROC);
32063 + atomic_dec(&kmod_concurrent);
32064 + return ret;
32065 + }
32066 +diff -urNp linux-2.6.27.10/kernel/kprobes.c linux-2.6.27.10/kernel/kprobes.c
32067 +--- linux-2.6.27.10/kernel/kprobes.c 2008-11-07 12:55:34.000000000 -0500
32068 ++++ linux-2.6.27.10/kernel/kprobes.c 2008-11-18 03:38:45.000000000 -0500
32069 +@@ -182,7 +182,7 @@ kprobe_opcode_t __kprobes *get_insn_slot
32070 + * kernel image and loaded module images reside. This is required
32071 + * so x86_64 can correctly handle the %rip-relative fixups.
32072 + */
32073 +- kip->insns = module_alloc(PAGE_SIZE);
32074 ++ kip->insns = module_alloc_exec(PAGE_SIZE);
32075 + if (!kip->insns) {
32076 + kfree(kip);
32077 + return NULL;
32078 +@@ -214,7 +214,7 @@ static int __kprobes collect_one_slot(st
32079 + hlist_add_head(&kip->hlist,
32080 + &kprobe_insn_pages);
32081 + } else {
32082 +- module_free(NULL, kip->insns);
32083 ++ module_free_exec(NULL, kip->insns);
32084 + kfree(kip);
32085 + }
32086 + return 1;
32087 +diff -urNp linux-2.6.27.10/kernel/lockdep.c linux-2.6.27.10/kernel/lockdep.c
32088 +--- linux-2.6.27.10/kernel/lockdep.c 2008-11-07 12:55:34.000000000 -0500
32089 ++++ linux-2.6.27.10/kernel/lockdep.c 2008-11-18 03:38:45.000000000 -0500
32090 +@@ -627,6 +627,10 @@ static int static_obj(void *obj)
32091 + int i;
32092 + #endif
32093 +
32094 ++#ifdef CONFIG_PAX_KERNEXEC
32095 ++ start = (unsigned long )&_data;
32096 ++#endif
32097 ++
32098 + /*
32099 + * static variable?
32100 + */
32101 +@@ -638,9 +642,12 @@ static int static_obj(void *obj)
32102 + * percpu var?
32103 + */
32104 + for_each_possible_cpu(i) {
32105 ++#ifdef CONFIG_X86_32
32106 ++ start = per_cpu_offset(i);
32107 ++#else
32108 + start = (unsigned long) &__per_cpu_start + per_cpu_offset(i);
32109 +- end = (unsigned long) &__per_cpu_start + PERCPU_ENOUGH_ROOM
32110 +- + per_cpu_offset(i);
32111 ++#endif
32112 ++ end = start + PERCPU_ENOUGH_ROOM;
32113 +
32114 + if ((addr >= start) && (addr < end))
32115 + return 1;
32116 +diff -urNp linux-2.6.27.10/kernel/module.c linux-2.6.27.10/kernel/module.c
32117 +--- linux-2.6.27.10/kernel/module.c 2008-11-07 12:55:34.000000000 -0500
32118 ++++ linux-2.6.27.10/kernel/module.c 2008-12-21 01:17:47.000000000 -0500
32119 +@@ -44,6 +44,11 @@
32120 + #include <linux/unwind.h>
32121 + #include <asm/uaccess.h>
32122 + #include <asm/cacheflush.h>
32123 ++
32124 ++#ifdef CONFIG_PAX_KERNEXEC
32125 ++#include <asm/desc.h>
32126 ++#endif
32127 ++
32128 + #include <linux/license.h>
32129 + #include <asm/sections.h>
32130 +
32131 +@@ -71,7 +76,10 @@ static DECLARE_WAIT_QUEUE_HEAD(module_wq
32132 + static BLOCKING_NOTIFIER_HEAD(module_notify_list);
32133 +
32134 + /* Bounds of module allocation, for speeding __module_text_address */
32135 +-static unsigned long module_addr_min = -1UL, module_addr_max = 0;
32136 ++static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
32137 ++static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
32138 ++
32139 ++extern int gr_check_modstop(void);
32140 +
32141 + int register_module_notifier(struct notifier_block * nb)
32142 + {
32143 +@@ -217,7 +225,7 @@ static bool each_symbol(bool (*fn)(const
32144 + return true;
32145 +
32146 + list_for_each_entry(mod, &modules, list) {
32147 +- struct symsearch arr[] = {
32148 ++ struct symsearch modarr[] = {
32149 + { mod->syms, mod->syms + mod->num_syms, mod->crcs,
32150 + NOT_GPL_ONLY, false },
32151 + { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
32152 +@@ -239,7 +247,7 @@ static bool each_symbol(bool (*fn)(const
32153 + #endif
32154 + };
32155 +
32156 +- if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
32157 ++ if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
32158 + return true;
32159 + }
32160 + return false;
32161 +@@ -375,6 +383,8 @@ static inline unsigned int block_size(in
32162 + return val;
32163 + }
32164 +
32165 ++EXPORT_SYMBOL(__per_cpu_start);
32166 ++
32167 + static void *percpu_modalloc(unsigned long size, unsigned long align,
32168 + const char *name)
32169 + {
32170 +@@ -382,7 +392,7 @@ static void *percpu_modalloc(unsigned lo
32171 + unsigned int i;
32172 + void *ptr;
32173 +
32174 +- if (align > PAGE_SIZE) {
32175 ++ if (align-1 >= PAGE_SIZE) {
32176 + printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
32177 + name, align, PAGE_SIZE);
32178 + align = PAGE_SIZE;
32179 +@@ -464,7 +474,11 @@ static void percpu_modcopy(void *pcpudes
32180 + int cpu;
32181 +
32182 + for_each_possible_cpu(cpu)
32183 ++#ifdef CONFIG_X86_32
32184 ++ memcpy(pcpudest + __per_cpu_offset[cpu], from, size);
32185 ++#else
32186 + memcpy(pcpudest + per_cpu_offset(cpu), from, size);
32187 ++#endif
32188 + }
32189 +
32190 + static int percpu_modinit(void)
32191 +@@ -722,6 +736,9 @@ sys_delete_module(const char __user *nam
32192 + char name[MODULE_NAME_LEN];
32193 + int ret, forced = 0;
32194 +
32195 ++ if (gr_check_modstop())
32196 ++ return -EPERM;
32197 ++
32198 + if (!capable(CAP_SYS_MODULE))
32199 + return -EPERM;
32200 +
32201 +@@ -1430,16 +1447,19 @@ static void free_module(struct module *m
32202 + module_unload_free(mod);
32203 +
32204 + /* This may be NULL, but that's OK */
32205 +- module_free(mod, mod->module_init);
32206 ++ module_free(mod, mod->module_init_rw);
32207 ++ module_free_exec(mod, mod->module_init_rx);
32208 + kfree(mod->args);
32209 + if (mod->percpu)
32210 + percpu_modfree(mod->percpu);
32211 +
32212 + /* Free lock-classes: */
32213 +- lockdep_free_key_range(mod->module_core, mod->core_size);
32214 ++ lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
32215 ++ lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
32216 +
32217 + /* Finally, free the core (containing the module structure) */
32218 +- module_free(mod, mod->module_core);
32219 ++ module_free_exec(mod, mod->module_core_rx);
32220 ++ module_free(mod, mod->module_core_rw);
32221 + }
32222 +
32223 + void *__symbol_get(const char *symbol)
32224 +@@ -1505,10 +1525,14 @@ static int simplify_symbols(Elf_Shdr *se
32225 + struct module *mod)
32226 + {
32227 + Elf_Sym *sym = (void *)sechdrs[symindex].sh_addr;
32228 +- unsigned long secbase;
32229 ++ unsigned long secbase, symbol;
32230 + unsigned int i, n = sechdrs[symindex].sh_size / sizeof(Elf_Sym);
32231 + int ret = 0;
32232 +
32233 ++#ifdef CONFIG_PAX_KERNEXEC
32234 ++ unsigned long cr0;
32235 ++#endif
32236 ++
32237 + for (i = 1; i < n; i++) {
32238 + switch (sym[i].st_shndx) {
32239 + case SHN_COMMON:
32240 +@@ -1527,10 +1551,19 @@ static int simplify_symbols(Elf_Shdr *se
32241 + break;
32242 +
32243 + case SHN_UNDEF:
32244 +- sym[i].st_value
32245 +- = resolve_symbol(sechdrs, versindex,
32246 ++ symbol = resolve_symbol(sechdrs, versindex,
32247 + strtab + sym[i].st_name, mod);
32248 +
32249 ++#ifdef CONFIG_PAX_KERNEXEC
32250 ++ pax_open_kernel(cr0);
32251 ++#endif
32252 ++
32253 ++ sym[i].st_value = symbol;
32254 ++
32255 ++#ifdef CONFIG_PAX_KERNEXEC
32256 ++ pax_close_kernel(cr0);
32257 ++#endif
32258 ++
32259 + /* Ok if resolved. */
32260 + if (!IS_ERR_VALUE(sym[i].st_value))
32261 + break;
32262 +@@ -1545,11 +1578,27 @@ static int simplify_symbols(Elf_Shdr *se
32263 +
32264 + default:
32265 + /* Divert to percpu allocation if a percpu var. */
32266 +- if (sym[i].st_shndx == pcpuindex)
32267 ++ if (sym[i].st_shndx == pcpuindex) {
32268 ++
32269 ++#if defined(CONFIG_X86_32) && defined(CONFIG_SMP)
32270 ++ secbase = (unsigned long)mod->percpu - (unsigned long)__per_cpu_start;
32271 ++#else
32272 + secbase = (unsigned long)mod->percpu;
32273 +- else
32274 ++#endif
32275 ++
32276 ++ } else
32277 + secbase = sechdrs[sym[i].st_shndx].sh_addr;
32278 ++
32279 ++#ifdef CONFIG_PAX_KERNEXEC
32280 ++ pax_open_kernel(cr0);
32281 ++#endif
32282 ++
32283 + sym[i].st_value += secbase;
32284 ++
32285 ++#ifdef CONFIG_PAX_KERNEXEC
32286 ++ pax_close_kernel(cr0);
32287 ++#endif
32288 ++
32289 + break;
32290 + }
32291 + }
32292 +@@ -1601,11 +1650,12 @@ static void layout_sections(struct modul
32293 + || strncmp(secstrings + s->sh_name,
32294 + ".init", 5) == 0)
32295 + continue;
32296 +- s->sh_entsize = get_offset(&mod->core_size, s);
32297 ++ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
32298 ++ s->sh_entsize = get_offset(&mod->core_size_rw, s);
32299 ++ else
32300 ++ s->sh_entsize = get_offset(&mod->core_size_rx, s);
32301 + DEBUGP("\t%s\n", secstrings + s->sh_name);
32302 + }
32303 +- if (m == 0)
32304 +- mod->core_text_size = mod->core_size;
32305 + }
32306 +
32307 + DEBUGP("Init section allocation order:\n");
32308 +@@ -1619,12 +1669,13 @@ static void layout_sections(struct modul
32309 + || strncmp(secstrings + s->sh_name,
32310 + ".init", 5) != 0)
32311 + continue;
32312 +- s->sh_entsize = (get_offset(&mod->init_size, s)
32313 +- | INIT_OFFSET_MASK);
32314 ++ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
32315 ++ s->sh_entsize = get_offset(&mod->init_size_rw, s);
32316 ++ else
32317 ++ s->sh_entsize = get_offset(&mod->init_size_rx, s);
32318 ++ s->sh_entsize |= INIT_OFFSET_MASK;
32319 + DEBUGP("\t%s\n", secstrings + s->sh_name);
32320 + }
32321 +- if (m == 0)
32322 +- mod->init_text_size = mod->init_size;
32323 + }
32324 + }
32325 +
32326 +@@ -1764,14 +1815,31 @@ static void add_kallsyms(struct module *
32327 + {
32328 + unsigned int i;
32329 +
32330 ++#ifdef CONFIG_PAX_KERNEXEC
32331 ++ unsigned long cr0;
32332 ++#endif
32333 ++
32334 + mod->symtab = (void *)sechdrs[symindex].sh_addr;
32335 + mod->num_symtab = sechdrs[symindex].sh_size / sizeof(Elf_Sym);
32336 + mod->strtab = (void *)sechdrs[strindex].sh_addr;
32337 +
32338 + /* Set types up while we still have access to sections. */
32339 +- for (i = 0; i < mod->num_symtab; i++)
32340 +- mod->symtab[i].st_info
32341 +- = elf_type(&mod->symtab[i], sechdrs, secstrings, mod);
32342 ++
32343 ++ for (i = 0; i < mod->num_symtab; i++) {
32344 ++ char type = elf_type(&mod->symtab[i], sechdrs, secstrings, mod);
32345 ++
32346 ++#ifdef CONFIG_PAX_KERNEXEC
32347 ++ pax_open_kernel(cr0);
32348 ++#endif
32349 ++
32350 ++ mod->symtab[i].st_info = type;
32351 ++
32352 ++#ifdef CONFIG_PAX_KERNEXEC
32353 ++ pax_close_kernel(cr0);
32354 ++#endif
32355 ++
32356 ++ }
32357 ++
32358 + }
32359 + #else
32360 + static inline void add_kallsyms(struct module *mod,
32361 +@@ -1783,16 +1851,30 @@ static inline void add_kallsyms(struct m
32362 + }
32363 + #endif /* CONFIG_KALLSYMS */
32364 +
32365 +-static void *module_alloc_update_bounds(unsigned long size)
32366 ++static void *module_alloc_update_bounds_rw(unsigned long size)
32367 + {
32368 + void *ret = module_alloc(size);
32369 +
32370 + if (ret) {
32371 + /* Update module bounds. */
32372 +- if ((unsigned long)ret < module_addr_min)
32373 +- module_addr_min = (unsigned long)ret;
32374 +- if ((unsigned long)ret + size > module_addr_max)
32375 +- module_addr_max = (unsigned long)ret + size;
32376 ++ if ((unsigned long)ret < module_addr_min_rw)
32377 ++ module_addr_min_rw = (unsigned long)ret;
32378 ++ if ((unsigned long)ret + size > module_addr_max_rw)
32379 ++ module_addr_max_rw = (unsigned long)ret + size;
32380 ++ }
32381 ++ return ret;
32382 ++}
32383 ++
32384 ++static void *module_alloc_update_bounds_rx(unsigned long size)
32385 ++{
32386 ++ void *ret = module_alloc_exec(size);
32387 ++
32388 ++ if (ret) {
32389 ++ /* Update module bounds. */
32390 ++ if ((unsigned long)ret < module_addr_min_rx)
32391 ++ module_addr_min_rx = (unsigned long)ret;
32392 ++ if ((unsigned long)ret + size > module_addr_max_rx)
32393 ++ module_addr_max_rx = (unsigned long)ret + size;
32394 + }
32395 + return ret;
32396 + }
32397 +@@ -1837,6 +1919,10 @@ static noinline struct module *load_modu
32398 + struct exception_table_entry *extable;
32399 + mm_segment_t old_fs;
32400 +
32401 ++#ifdef CONFIG_PAX_KERNEXEC
32402 ++ unsigned long cr0;
32403 ++#endif
32404 ++
32405 + DEBUGP("load_module: umod=%p, len=%lu, uargs=%p\n",
32406 + umod, len, uargs);
32407 + if (len < sizeof(*hdr))
32408 +@@ -1998,22 +2084,57 @@ static noinline struct module *load_modu
32409 + layout_sections(mod, hdr, sechdrs, secstrings);
32410 +
32411 + /* Do the allocs. */
32412 +- ptr = module_alloc_update_bounds(mod->core_size);
32413 ++ ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
32414 + if (!ptr) {
32415 + err = -ENOMEM;
32416 + goto free_percpu;
32417 + }
32418 +- memset(ptr, 0, mod->core_size);
32419 +- mod->module_core = ptr;
32420 ++ memset(ptr, 0, mod->core_size_rw);
32421 ++ mod->module_core_rw = ptr;
32422 ++
32423 ++ ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
32424 ++ if (!ptr && mod->init_size_rw) {
32425 ++ err = -ENOMEM;
32426 ++ goto free_core_rw;
32427 ++ }
32428 ++ memset(ptr, 0, mod->init_size_rw);
32429 ++ mod->module_init_rw = ptr;
32430 ++
32431 ++ ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
32432 ++ if (!ptr) {
32433 ++ err = -ENOMEM;
32434 ++ goto free_init_rw;
32435 ++ }
32436 ++
32437 ++#ifdef CONFIG_PAX_KERNEXEC
32438 ++ pax_open_kernel(cr0);
32439 ++#endif
32440 ++
32441 ++ memset(ptr, 0, mod->core_size_rx);
32442 +
32443 +- ptr = module_alloc_update_bounds(mod->init_size);
32444 +- if (!ptr && mod->init_size) {
32445 ++#ifdef CONFIG_PAX_KERNEXEC
32446 ++ pax_close_kernel(cr0);
32447 ++#endif
32448 ++
32449 ++ mod->module_core_rx = ptr;
32450 ++
32451 ++ ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
32452 ++ if (!ptr && mod->init_size_rx) {
32453 + err = -ENOMEM;
32454 +- goto free_core;
32455 ++ goto free_core_rx;
32456 + }
32457 +- memset(ptr, 0, mod->init_size);
32458 +- mod->module_init = ptr;
32459 +
32460 ++#ifdef CONFIG_PAX_KERNEXEC
32461 ++ pax_open_kernel(cr0);
32462 ++#endif
32463 ++
32464 ++ memset(ptr, 0, mod->init_size_rx);
32465 ++
32466 ++#ifdef CONFIG_PAX_KERNEXEC
32467 ++ pax_close_kernel(cr0);
32468 ++#endif
32469 ++
32470 ++ mod->module_init_rx = ptr;
32471 + /* Transfer each section which specifies SHF_ALLOC */
32472 + DEBUGP("final section addresses:\n");
32473 + for (i = 0; i < hdr->e_shnum; i++) {
32474 +@@ -2022,17 +2143,41 @@ static noinline struct module *load_modu
32475 + if (!(sechdrs[i].sh_flags & SHF_ALLOC))
32476 + continue;
32477 +
32478 +- if (sechdrs[i].sh_entsize & INIT_OFFSET_MASK)
32479 +- dest = mod->module_init
32480 +- + (sechdrs[i].sh_entsize & ~INIT_OFFSET_MASK);
32481 +- else
32482 +- dest = mod->module_core + sechdrs[i].sh_entsize;
32483 ++ if (sechdrs[i].sh_entsize & INIT_OFFSET_MASK) {
32484 ++ if ((sechdrs[i].sh_flags & SHF_WRITE) || !(sechdrs[i].sh_flags & SHF_ALLOC))
32485 ++ dest = mod->module_init_rw
32486 ++ + (sechdrs[i].sh_entsize & ~INIT_OFFSET_MASK);
32487 ++ else
32488 ++ dest = mod->module_init_rx
32489 ++ + (sechdrs[i].sh_entsize & ~INIT_OFFSET_MASK);
32490 ++ } else {
32491 ++ if ((sechdrs[i].sh_flags & SHF_WRITE) || !(sechdrs[i].sh_flags & SHF_ALLOC))
32492 ++ dest = mod->module_core_rw + sechdrs[i].sh_entsize;
32493 ++ else
32494 ++ dest = mod->module_core_rx + sechdrs[i].sh_entsize;
32495 ++ }
32496 +
32497 +- if (sechdrs[i].sh_type != SHT_NOBITS)
32498 +- memcpy(dest, (void *)sechdrs[i].sh_addr,
32499 +- sechdrs[i].sh_size);
32500 ++ if (sechdrs[i].sh_type != SHT_NOBITS) {
32501 ++
32502 ++#ifdef CONFIG_PAX_KERNEXEC
32503 ++ if (!(sechdrs[i].sh_flags & SHF_WRITE) && (sechdrs[i].sh_flags & SHF_ALLOC)) {
32504 ++ pax_open_kernel(cr0);
32505 ++ memcpy(dest, (void *)sechdrs[i].sh_addr, sechdrs[i].sh_size);
32506 ++ pax_close_kernel(cr0);
32507 ++ } else
32508 ++#endif
32509 ++
32510 ++ memcpy(dest, (void *)sechdrs[i].sh_addr, sechdrs[i].sh_size);
32511 ++ }
32512 + /* Update sh_addr to point to copy in image. */
32513 +- sechdrs[i].sh_addr = (unsigned long)dest;
32514 ++
32515 ++#ifdef CONFIG_PAX_KERNEXEC
32516 ++ if (sechdrs[i].sh_flags & SHF_EXECINSTR)
32517 ++ sechdrs[i].sh_addr = ktva_ktla((unsigned long)dest);
32518 ++ else
32519 ++#endif
32520 ++
32521 ++ sechdrs[i].sh_addr = (unsigned long)dest;
32522 + DEBUGP("\t0x%lx %s\n", sechdrs[i].sh_addr, secstrings + sechdrs[i].sh_name);
32523 + }
32524 + /* Module has been moved. */
32525 +@@ -2120,8 +2265,8 @@ static noinline struct module *load_modu
32526 +
32527 + /* Now do relocations. */
32528 + for (i = 1; i < hdr->e_shnum; i++) {
32529 +- const char *strtab = (char *)sechdrs[strindex].sh_addr;
32530 + unsigned int info = sechdrs[i].sh_info;
32531 ++ strtab = (char *)sechdrs[strindex].sh_addr;
32532 +
32533 + /* Not a valid relocation section? */
32534 + if (info >= hdr->e_shnum)
32535 +@@ -2180,12 +2325,12 @@ static noinline struct module *load_modu
32536 + * Do it before processing of module parameters, so the module
32537 + * can provide parameter accessor functions of its own.
32538 + */
32539 +- if (mod->module_init)
32540 +- flush_icache_range((unsigned long)mod->module_init,
32541 +- (unsigned long)mod->module_init
32542 +- + mod->init_size);
32543 +- flush_icache_range((unsigned long)mod->module_core,
32544 +- (unsigned long)mod->module_core + mod->core_size);
32545 ++ if (mod->module_init_rx)
32546 ++ flush_icache_range((unsigned long)mod->module_init_rx,
32547 ++ (unsigned long)mod->module_init_rx
32548 ++ + mod->init_size_rx);
32549 ++ flush_icache_range((unsigned long)mod->module_core_rx,
32550 ++ (unsigned long)mod->module_core_rx + mod->core_size_rx);
32551 +
32552 + set_fs(old_fs);
32553 +
32554 +@@ -2238,9 +2383,13 @@ static noinline struct module *load_modu
32555 + kobject_put(&mod->mkobj.kobj);
32556 + free_unload:
32557 + module_unload_free(mod);
32558 +- module_free(mod, mod->module_init);
32559 +- free_core:
32560 +- module_free(mod, mod->module_core);
32561 ++ module_free_exec(mod, mod->module_init_rx);
32562 ++ free_core_rx:
32563 ++ module_free_exec(mod, mod->module_core_rx);
32564 ++ free_init_rw:
32565 ++ module_free(mod, mod->module_init_rw);
32566 ++ free_core_rw:
32567 ++ module_free(mod, mod->module_core_rw);
32568 + free_percpu:
32569 + if (percpu)
32570 + percpu_modfree(percpu);
32571 +@@ -2265,6 +2414,9 @@ sys_init_module(void __user *umod,
32572 + struct module *mod;
32573 + int ret = 0;
32574 +
32575 ++ if (gr_check_modstop())
32576 ++ return -EPERM;
32577 ++
32578 + /* Must have permission */
32579 + if (!capable(CAP_SYS_MODULE))
32580 + return -EPERM;
32581 +@@ -2320,10 +2472,12 @@ sys_init_module(void __user *umod,
32582 + /* Drop initial reference. */
32583 + module_put(mod);
32584 + unwind_remove_table(mod->unwind_info, 1);
32585 +- module_free(mod, mod->module_init);
32586 +- mod->module_init = NULL;
32587 +- mod->init_size = 0;
32588 +- mod->init_text_size = 0;
32589 ++ module_free(mod, mod->module_init_rw);
32590 ++ module_free_exec(mod, mod->module_init_rx);
32591 ++ mod->module_init_rw = NULL;
32592 ++ mod->module_init_rx = NULL;
32593 ++ mod->init_size_rw = 0;
32594 ++ mod->init_size_rx = 0;
32595 + mutex_unlock(&module_mutex);
32596 +
32597 + return 0;
32598 +@@ -2331,6 +2485,13 @@ sys_init_module(void __user *umod,
32599 +
32600 + static inline int within(unsigned long addr, void *start, unsigned long size)
32601 + {
32602 ++
32603 ++#ifdef CONFIG_PAX_KERNEXEC
32604 ++ if (ktla_ktva(addr) >= (unsigned long)start &&
32605 ++ ktla_ktva(addr) < (unsigned long)start + size)
32606 ++ return 1;
32607 ++#endif
32608 ++
32609 + return ((void *)addr >= start && (void *)addr < start + size);
32610 + }
32611 +
32612 +@@ -2354,10 +2515,14 @@ static const char *get_ksymbol(struct mo
32613 + unsigned long nextval;
32614 +
32615 + /* At worse, next value is at end of module */
32616 +- if (within(addr, mod->module_init, mod->init_size))
32617 +- nextval = (unsigned long)mod->module_init+mod->init_text_size;
32618 ++ if (within(addr, mod->module_init_rx, mod->init_size_rx))
32619 ++ nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
32620 ++ else if (within(addr, mod->module_init_rw, mod->init_size_rw))
32621 ++ nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
32622 ++ else if (within(addr, mod->module_core_rx, mod->core_size_rx))
32623 ++ nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
32624 + else
32625 +- nextval = (unsigned long)mod->module_core+mod->core_text_size;
32626 ++ nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
32627 +
32628 + /* Scan for closest preceeding symbol, and next symbol. (ELF
32629 + starts real symbols at 1). */
32630 +@@ -2402,8 +2567,10 @@ const char *module_address_lookup(unsign
32631 +
32632 + preempt_disable();
32633 + list_for_each_entry(mod, &modules, list) {
32634 +- if (within(addr, mod->module_init, mod->init_size)
32635 +- || within(addr, mod->module_core, mod->core_size)) {
32636 ++ if (within(addr, mod->module_init_rx, mod->init_size_rx) ||
32637 ++ within(addr, mod->module_init_rw, mod->init_size_rw) ||
32638 ++ within(addr, mod->module_core_rx, mod->core_size_rx) ||
32639 ++ within(addr, mod->module_core_rw, mod->core_size_rw)) {
32640 + if (modname)
32641 + *modname = mod->name;
32642 + ret = get_ksymbol(mod, addr, size, offset);
32643 +@@ -2425,8 +2592,10 @@ int lookup_module_symbol_name(unsigned l
32644 +
32645 + preempt_disable();
32646 + list_for_each_entry(mod, &modules, list) {
32647 +- if (within(addr, mod->module_init, mod->init_size) ||
32648 +- within(addr, mod->module_core, mod->core_size)) {
32649 ++ if (within(addr, mod->module_init_rx, mod->init_size_rx) ||
32650 ++ within(addr, mod->module_init_rw, mod->init_size_rw) ||
32651 ++ within(addr, mod->module_core_rx, mod->core_size_rx) ||
32652 ++ within(addr, mod->module_core_rw, mod->core_size_rw)) {
32653 + const char *sym;
32654 +
32655 + sym = get_ksymbol(mod, addr, NULL, NULL);
32656 +@@ -2449,8 +2618,10 @@ int lookup_module_symbol_attrs(unsigned
32657 +
32658 + preempt_disable();
32659 + list_for_each_entry(mod, &modules, list) {
32660 +- if (within(addr, mod->module_init, mod->init_size) ||
32661 +- within(addr, mod->module_core, mod->core_size)) {
32662 ++ if (within(addr, mod->module_init_rx, mod->init_size_rx) ||
32663 ++ within(addr, mod->module_init_rw, mod->init_size_rw) ||
32664 ++ within(addr, mod->module_core_rx, mod->core_size_rx) ||
32665 ++ within(addr, mod->module_core_rw, mod->core_size_rw)) {
32666 + const char *sym;
32667 +
32668 + sym = get_ksymbol(mod, addr, size, offset);
32669 +@@ -2581,7 +2752,7 @@ static int m_show(struct seq_file *m, vo
32670 + char buf[8];
32671 +
32672 + seq_printf(m, "%s %u",
32673 +- mod->name, mod->init_size + mod->core_size);
32674 ++ mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
32675 + print_unload_info(m, mod);
32676 +
32677 + /* Informative for users. */
32678 +@@ -2590,7 +2761,7 @@ static int m_show(struct seq_file *m, vo
32679 + mod->state == MODULE_STATE_COMING ? "Loading":
32680 + "Live");
32681 + /* Used by oprofile and other similar tools. */
32682 +- seq_printf(m, " 0x%p", mod->module_core);
32683 ++ seq_printf(m, " 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
32684 +
32685 + /* Taints info */
32686 + if (mod->taints)
32687 +@@ -2646,7 +2817,8 @@ int is_module_address(unsigned long addr
32688 + preempt_disable();
32689 +
32690 + list_for_each_entry(mod, &modules, list) {
32691 +- if (within(addr, mod->module_core, mod->core_size)) {
32692 ++ if (within(addr, mod->module_core_rx, mod->core_size_rx) ||
32693 ++ within(addr, mod->module_core_rw, mod->core_size_rw)) {
32694 + preempt_enable();
32695 + return 1;
32696 + }
32697 +@@ -2663,12 +2835,16 @@ struct module *__module_text_address(uns
32698 + {
32699 + struct module *mod;
32700 +
32701 +- if (addr < module_addr_min || addr > module_addr_max)
32702 ++#ifdef CONFIG_X86_32
32703 ++ addr = ktla_ktva(addr);
32704 ++#endif
32705 ++
32706 ++ if (addr < module_addr_min_rx || addr > module_addr_max_rx)
32707 + return NULL;
32708 +
32709 + list_for_each_entry(mod, &modules, list)
32710 +- if (within(addr, mod->module_init, mod->init_text_size)
32711 +- || within(addr, mod->module_core, mod->core_text_size))
32712 ++ if (within(addr, mod->module_init_rx, mod->init_size_rx)
32713 ++ || within(addr, mod->module_core_rx, mod->core_size_rx))
32714 + return mod;
32715 + return NULL;
32716 + }
32717 +diff -urNp linux-2.6.27.10/kernel/mutex.c linux-2.6.27.10/kernel/mutex.c
32718 +--- linux-2.6.27.10/kernel/mutex.c 2008-11-07 12:55:34.000000000 -0500
32719 ++++ linux-2.6.27.10/kernel/mutex.c 2008-11-18 03:38:45.000000000 -0500
32720 +@@ -83,7 +83,7 @@ __mutex_lock_slowpath(atomic_t *lock_cou
32721 + *
32722 + * This function is similar to (but not equivalent to) down().
32723 + */
32724 +-void inline __sched mutex_lock(struct mutex *lock)
32725 ++inline void __sched mutex_lock(struct mutex *lock)
32726 + {
32727 + might_sleep();
32728 + /*
32729 +diff -urNp linux-2.6.27.10/kernel/panic.c linux-2.6.27.10/kernel/panic.c
32730 +--- linux-2.6.27.10/kernel/panic.c 2008-11-07 12:55:34.000000000 -0500
32731 ++++ linux-2.6.27.10/kernel/panic.c 2008-11-18 03:38:45.000000000 -0500
32732 +@@ -349,6 +349,8 @@ EXPORT_SYMBOL(warn_slowpath);
32733 + */
32734 + void __stack_chk_fail(void)
32735 + {
32736 ++ print_symbol("stack corrupted in: %s\n", (unsigned long)__builtin_return_address(0));
32737 ++ dump_stack();
32738 + panic("stack-protector: Kernel stack is corrupted");
32739 + }
32740 + EXPORT_SYMBOL(__stack_chk_fail);
32741 +diff -urNp linux-2.6.27.10/kernel/pid.c linux-2.6.27.10/kernel/pid.c
32742 +--- linux-2.6.27.10/kernel/pid.c 2008-11-07 12:55:34.000000000 -0500
32743 ++++ linux-2.6.27.10/kernel/pid.c 2008-11-18 03:38:45.000000000 -0500
32744 +@@ -36,6 +36,7 @@
32745 + #include <linux/pid_namespace.h>
32746 + #include <linux/init_task.h>
32747 + #include <linux/syscalls.h>
32748 ++#include <linux/grsecurity.h>
32749 +
32750 + #define pid_hashfn(nr, ns) \
32751 + hash_long((unsigned long)nr + (unsigned long)ns, pidhash_shift)
32752 +@@ -45,7 +46,7 @@ struct pid init_struct_pid = INIT_STRUCT
32753 +
32754 + int pid_max = PID_MAX_DEFAULT;
32755 +
32756 +-#define RESERVED_PIDS 300
32757 ++#define RESERVED_PIDS 500
32758 +
32759 + int pid_max_min = RESERVED_PIDS + 1;
32760 + int pid_max_max = PID_MAX_LIMIT;
32761 +@@ -381,7 +382,14 @@ EXPORT_SYMBOL(pid_task);
32762 + struct task_struct *find_task_by_pid_type_ns(int type, int nr,
32763 + struct pid_namespace *ns)
32764 + {
32765 +- return pid_task(find_pid_ns(nr, ns), type);
32766 ++ struct task_struct *task;
32767 ++
32768 ++ task = pid_task(find_pid_ns(nr, ns), type);
32769 ++
32770 ++ if (gr_pid_is_chrooted(task))
32771 ++ return NULL;
32772 ++
32773 ++ return task;
32774 + }
32775 +
32776 + EXPORT_SYMBOL(find_task_by_pid_type_ns);
32777 +diff -urNp linux-2.6.27.10/kernel/posix-cpu-timers.c linux-2.6.27.10/kernel/posix-cpu-timers.c
32778 +--- linux-2.6.27.10/kernel/posix-cpu-timers.c 2008-11-07 12:55:34.000000000 -0500
32779 ++++ linux-2.6.27.10/kernel/posix-cpu-timers.c 2008-11-18 03:38:45.000000000 -0500
32780 +@@ -6,6 +6,7 @@
32781 + #include <linux/posix-timers.h>
32782 + #include <linux/errno.h>
32783 + #include <linux/math64.h>
32784 ++#include <linux/grsecurity.h>
32785 + #include <asm/uaccess.h>
32786 +
32787 + static int check_clock(const clockid_t which_clock)
32788 +@@ -1176,6 +1177,7 @@ static void check_process_timers(struct
32789 + __group_send_sig_info(SIGKILL, SEND_SIG_PRIV, tsk);
32790 + return;
32791 + }
32792 ++ gr_learn_resource(tsk, RLIMIT_CPU, psecs, 1);
32793 + if (psecs >= sig->rlim[RLIMIT_CPU].rlim_cur) {
32794 + /*
32795 + * At the soft limit, send a SIGXCPU every second.
32796 +@@ -1370,17 +1372,17 @@ void run_posix_cpu_timers(struct task_st
32797 + * timer call will interfere.
32798 + */
32799 + list_for_each_entry_safe(timer, next, &firing, it.cpu.entry) {
32800 +- int firing;
32801 ++ int __firing;
32802 + spin_lock(&timer->it_lock);
32803 + list_del_init(&timer->it.cpu.entry);
32804 +- firing = timer->it.cpu.firing;
32805 ++ __firing = timer->it.cpu.firing;
32806 + timer->it.cpu.firing = 0;
32807 + /*
32808 + * The firing flag is -1 if we collided with a reset
32809 + * of the timer, which already reported this
32810 + * almost-firing as an overrun. So don't generate an event.
32811 + */
32812 +- if (likely(firing >= 0)) {
32813 ++ if (likely(__firing >= 0)) {
32814 + cpu_timer_fire(timer);
32815 + }
32816 + spin_unlock(&timer->it_lock);
32817 +diff -urNp linux-2.6.27.10/kernel/power/poweroff.c linux-2.6.27.10/kernel/power/poweroff.c
32818 +--- linux-2.6.27.10/kernel/power/poweroff.c 2008-11-07 12:55:34.000000000 -0500
32819 ++++ linux-2.6.27.10/kernel/power/poweroff.c 2008-11-18 03:38:45.000000000 -0500
32820 +@@ -37,7 +37,7 @@ static struct sysrq_key_op sysrq_powerof
32821 + .enable_mask = SYSRQ_ENABLE_BOOT,
32822 + };
32823 +
32824 +-static int pm_sysrq_init(void)
32825 ++static int __init pm_sysrq_init(void)
32826 + {
32827 + register_sysrq_key('o', &sysrq_poweroff_op);
32828 + return 0;
32829 +diff -urNp linux-2.6.27.10/kernel/printk.c linux-2.6.27.10/kernel/printk.c
32830 +--- linux-2.6.27.10/kernel/printk.c 2008-11-07 12:55:34.000000000 -0500
32831 ++++ linux-2.6.27.10/kernel/printk.c 2008-11-18 03:38:45.000000000 -0500
32832 +@@ -32,6 +32,7 @@
32833 + #include <linux/security.h>
32834 + #include <linux/bootmem.h>
32835 + #include <linux/syscalls.h>
32836 ++#include <linux/grsecurity.h>
32837 +
32838 + #include <asm/uaccess.h>
32839 +
32840 +@@ -293,6 +294,11 @@ int do_syslog(int type, char __user *buf
32841 + char c;
32842 + int error = 0;
32843 +
32844 ++#ifdef CONFIG_GRKERNSEC_DMESG
32845 ++ if (grsec_enable_dmesg && !capable(CAP_SYS_ADMIN))
32846 ++ return -EPERM;
32847 ++#endif
32848 ++
32849 + error = security_syslog(type);
32850 + if (error)
32851 + return error;
32852 +diff -urNp linux-2.6.27.10/kernel/ptrace.c linux-2.6.27.10/kernel/ptrace.c
32853 +--- linux-2.6.27.10/kernel/ptrace.c 2008-11-07 12:55:34.000000000 -0500
32854 ++++ linux-2.6.27.10/kernel/ptrace.c 2008-11-18 03:38:45.000000000 -0500
32855 +@@ -21,6 +21,7 @@
32856 + #include <linux/audit.h>
32857 + #include <linux/pid_namespace.h>
32858 + #include <linux/syscalls.h>
32859 ++#include <linux/grsecurity.h>
32860 +
32861 + #include <asm/pgtable.h>
32862 + #include <asm/uaccess.h>
32863 +@@ -132,12 +133,12 @@ int __ptrace_may_access(struct task_stru
32864 + (current->uid != task->uid) ||
32865 + (current->gid != task->egid) ||
32866 + (current->gid != task->sgid) ||
32867 +- (current->gid != task->gid)) && !capable(CAP_SYS_PTRACE))
32868 ++ (current->gid != task->gid)) && !capable_nolog(CAP_SYS_PTRACE))
32869 + return -EPERM;
32870 + smp_rmb();
32871 + if (task->mm)
32872 + dumpable = get_dumpable(task->mm);
32873 +- if (!dumpable && !capable(CAP_SYS_PTRACE))
32874 ++ if (!dumpable && !capable_nolog(CAP_SYS_PTRACE))
32875 + return -EPERM;
32876 +
32877 + return security_ptrace_may_access(task, mode);
32878 +@@ -193,7 +194,7 @@ repeat:
32879 +
32880 + /* Go */
32881 + task->ptrace |= PT_PTRACED;
32882 +- if (capable(CAP_SYS_PTRACE))
32883 ++ if (capable_nolog(CAP_SYS_PTRACE))
32884 + task->ptrace |= PT_PTRACE_CAP;
32885 +
32886 + __ptrace_link(task, current);
32887 +@@ -582,6 +583,11 @@ asmlinkage long sys_ptrace(long request,
32888 + if (ret < 0)
32889 + goto out_put_task_struct;
32890 +
32891 ++ if (gr_handle_ptrace(child, request)) {
32892 ++ ret = -EPERM;
32893 ++ goto out_put_task_struct;
32894 ++ }
32895 ++
32896 + ret = arch_ptrace(child, request, addr, data);
32897 + if (ret < 0)
32898 + goto out_put_task_struct;
32899 +diff -urNp linux-2.6.27.10/kernel/relay.c linux-2.6.27.10/kernel/relay.c
32900 +--- linux-2.6.27.10/kernel/relay.c 2008-11-07 12:55:34.000000000 -0500
32901 ++++ linux-2.6.27.10/kernel/relay.c 2008-11-18 03:38:45.000000000 -0500
32902 +@@ -1291,7 +1291,7 @@ static int subbuf_splice_actor(struct fi
32903 + return 0;
32904 +
32905 + ret = *nonpad_ret = splice_to_pipe(pipe, &spd);
32906 +- if (ret < 0 || ret < total_len)
32907 ++ if ((int)ret < 0 || ret < total_len)
32908 + return ret;
32909 +
32910 + if (read_start + ret == nonpad_end)
32911 +diff -urNp linux-2.6.27.10/kernel/resource.c linux-2.6.27.10/kernel/resource.c
32912 +--- linux-2.6.27.10/kernel/resource.c 2008-11-07 12:55:34.000000000 -0500
32913 ++++ linux-2.6.27.10/kernel/resource.c 2008-11-18 03:38:45.000000000 -0500
32914 +@@ -131,8 +131,18 @@ static const struct file_operations proc
32915 +
32916 + static int __init ioresources_init(void)
32917 + {
32918 ++#ifdef CONFIG_GRKERNSEC_PROC_ADD
32919 ++#ifdef CONFIG_GRKERNSEC_PROC_USER
32920 ++ proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
32921 ++ proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
32922 ++#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
32923 ++ proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
32924 ++ proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
32925 ++#endif
32926 ++#else
32927 + proc_create("ioports", 0, NULL, &proc_ioports_operations);
32928 + proc_create("iomem", 0, NULL, &proc_iomem_operations);
32929 ++#endif
32930 + return 0;
32931 + }
32932 + __initcall(ioresources_init);
32933 +diff -urNp linux-2.6.27.10/kernel/sched.c linux-2.6.27.10/kernel/sched.c
32934 +--- linux-2.6.27.10/kernel/sched.c 2008-12-21 01:16:52.000000000 -0500
32935 ++++ linux-2.6.27.10/kernel/sched.c 2008-12-21 01:13:46.000000000 -0500
32936 +@@ -71,6 +71,7 @@
32937 + #include <linux/debugfs.h>
32938 + #include <linux/ctype.h>
32939 + #include <linux/ftrace.h>
32940 ++#include <linux/grsecurity.h>
32941 +
32942 + #include <asm/tlb.h>
32943 + #include <asm/irq_regs.h>
32944 +@@ -4962,7 +4963,8 @@ asmlinkage long sys_nice(int increment)
32945 + if (nice > 19)
32946 + nice = 19;
32947 +
32948 +- if (increment < 0 && !can_nice(current, nice))
32949 ++ if (increment < 0 && (!can_nice(current, nice) ||
32950 ++ gr_handle_chroot_nice()))
32951 + return -EPERM;
32952 +
32953 + retval = security_task_setnice(current, nice);
32954 +@@ -6225,7 +6227,7 @@ static struct ctl_table sd_ctl_dir[] = {
32955 + .procname = "sched_domain",
32956 + .mode = 0555,
32957 + },
32958 +- {0, },
32959 ++ { 0, NULL, NULL, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL }
32960 + };
32961 +
32962 + static struct ctl_table sd_ctl_root[] = {
32963 +@@ -6235,7 +6237,7 @@ static struct ctl_table sd_ctl_root[] =
32964 + .mode = 0555,
32965 + .child = sd_ctl_dir,
32966 + },
32967 +- {0, },
32968 ++ { 0, NULL, NULL, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL }
32969 + };
32970 +
32971 + static struct ctl_table *sd_alloc_ctl_entry(int n)
32972 +diff -urNp linux-2.6.27.10/kernel/signal.c linux-2.6.27.10/kernel/signal.c
32973 +--- linux-2.6.27.10/kernel/signal.c 2008-11-07 12:55:34.000000000 -0500
32974 ++++ linux-2.6.27.10/kernel/signal.c 2008-11-18 03:38:45.000000000 -0500
32975 +@@ -26,6 +26,7 @@
32976 + #include <linux/capability.h>
32977 + #include <linux/freezer.h>
32978 + #include <linux/pid_namespace.h>
32979 ++#include <linux/grsecurity.h>
32980 + #include <linux/nsproxy.h>
32981 +
32982 + #include <asm/param.h>
32983 +@@ -595,6 +596,9 @@ static int check_kill_permission(int sig
32984 + }
32985 + }
32986 +
32987 ++ if (gr_handle_signal(t, sig))
32988 ++ return -EPERM;
32989 ++
32990 + return security_task_kill(t, info, sig, 0);
32991 + }
32992 +
32993 +@@ -884,8 +888,8 @@ static void print_fatal_signal(struct pt
32994 + for (i = 0; i < 16; i++) {
32995 + unsigned char insn;
32996 +
32997 +- __get_user(insn, (unsigned char *)(regs->ip + i));
32998 +- printk("%02x ", insn);
32999 ++ if (!get_user(insn, (unsigned char __user *)(regs->ip + i)))
33000 ++ printk("%02x ", insn);
33001 + }
33002 + }
33003 + #endif
33004 +@@ -908,7 +912,7 @@ __group_send_sig_info(int sig, struct si
33005 + return send_signal(sig, info, p, 1);
33006 + }
33007 +
33008 +-static int
33009 ++int
33010 + specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
33011 + {
33012 + return send_signal(sig, info, t, 0);
33013 +@@ -946,8 +950,12 @@ force_sig_info(int sig, struct siginfo *
33014 + if (action->sa.sa_handler == SIG_DFL)
33015 + t->signal->flags &= ~SIGNAL_UNKILLABLE;
33016 + ret = specific_send_sig_info(sig, info, t);
33017 ++
33018 + spin_unlock_irqrestore(&t->sighand->siglock, flags);
33019 +
33020 ++ gr_log_signal(sig, t);
33021 ++ gr_handle_crash(t, sig);
33022 ++
33023 + return ret;
33024 + }
33025 +
33026 +@@ -1018,6 +1026,8 @@ int group_send_sig_info(int sig, struct
33027 + ret = __group_send_sig_info(sig, info, p);
33028 + unlock_task_sighand(p, &flags);
33029 + }
33030 ++ if (!ret)
33031 ++ gr_log_signal(sig, p);
33032 + }
33033 +
33034 + return ret;
33035 +diff -urNp linux-2.6.27.10/kernel/softirq.c linux-2.6.27.10/kernel/softirq.c
33036 +--- linux-2.6.27.10/kernel/softirq.c 2008-11-07 12:55:34.000000000 -0500
33037 ++++ linux-2.6.27.10/kernel/softirq.c 2008-11-18 03:38:45.000000000 -0500
33038 +@@ -453,9 +453,9 @@ void tasklet_kill(struct tasklet_struct
33039 + printk("Attempt to kill tasklet from interrupt\n");
33040 +
33041 + while (test_and_set_bit(TASKLET_STATE_SCHED, &t->state)) {
33042 +- do
33043 ++ do {
33044 + yield();
33045 +- while (test_bit(TASKLET_STATE_SCHED, &t->state));
33046 ++ } while (test_bit(TASKLET_STATE_SCHED, &t->state));
33047 + }
33048 + tasklet_unlock_wait(t);
33049 + clear_bit(TASKLET_STATE_SCHED, &t->state);
33050 +diff -urNp linux-2.6.27.10/kernel/sys.c linux-2.6.27.10/kernel/sys.c
33051 +--- linux-2.6.27.10/kernel/sys.c 2008-11-07 12:55:34.000000000 -0500
33052 ++++ linux-2.6.27.10/kernel/sys.c 2008-11-18 03:38:45.000000000 -0500
33053 +@@ -33,6 +33,7 @@
33054 + #include <linux/task_io_accounting_ops.h>
33055 + #include <linux/seccomp.h>
33056 + #include <linux/cpu.h>
33057 ++#include <linux/grsecurity.h>
33058 +
33059 + #include <linux/compat.h>
33060 + #include <linux/syscalls.h>
33061 +@@ -125,6 +126,12 @@ static int set_one_prio(struct task_stru
33062 + error = -EACCES;
33063 + goto out;
33064 + }
33065 ++
33066 ++ if (gr_handle_chroot_setpriority(p, niceval)) {
33067 ++ error = -EACCES;
33068 ++ goto out;
33069 ++ }
33070 ++
33071 + no_nice = security_task_setnice(p, niceval);
33072 + if (no_nice) {
33073 + error = no_nice;
33074 +@@ -181,10 +188,10 @@ asmlinkage long sys_setpriority(int whic
33075 + if ((who != current->uid) && !(user = find_user(who)))
33076 + goto out_unlock; /* No processes for this user */
33077 +
33078 +- do_each_thread(g, p)
33079 ++ do_each_thread(g, p) {
33080 + if (p->uid == who)
33081 + error = set_one_prio(p, niceval, error);
33082 +- while_each_thread(g, p);
33083 ++ } while_each_thread(g, p);
33084 + if (who != current->uid)
33085 + free_uid(user); /* For find_user() */
33086 + break;
33087 +@@ -243,13 +250,13 @@ asmlinkage long sys_getpriority(int whic
33088 + if ((who != current->uid) && !(user = find_user(who)))
33089 + goto out_unlock; /* No processes for this user */
33090 +
33091 +- do_each_thread(g, p)
33092 ++ do_each_thread(g, p) {
33093 + if (p->uid == who) {
33094 + niceval = 20 - task_nice(p);
33095 + if (niceval > retval)
33096 + retval = niceval;
33097 + }
33098 +- while_each_thread(g, p);
33099 ++ } while_each_thread(g, p);
33100 + if (who != current->uid)
33101 + free_uid(user); /* for find_user() */
33102 + break;
33103 +@@ -499,6 +506,10 @@ asmlinkage long sys_setregid(gid_t rgid,
33104 + else
33105 + return -EPERM;
33106 + }
33107 ++
33108 ++ if (gr_check_group_change(new_rgid, new_egid, -1))
33109 ++ return -EPERM;
33110 ++
33111 + if (new_egid != old_egid) {
33112 + set_dumpable(current->mm, suid_dumpable);
33113 + smp_wmb();
33114 +@@ -506,6 +517,9 @@ asmlinkage long sys_setregid(gid_t rgid,
33115 + if (rgid != (gid_t) -1 ||
33116 + (egid != (gid_t) -1 && egid != old_rgid))
33117 + current->sgid = new_egid;
33118 ++
33119 ++ gr_set_role_label(current, current->uid, new_rgid);
33120 ++
33121 + current->fsgid = new_egid;
33122 + current->egid = new_egid;
33123 + current->gid = new_rgid;
33124 +@@ -528,11 +542,17 @@ asmlinkage long sys_setgid(gid_t gid)
33125 + if (retval)
33126 + return retval;
33127 +
33128 ++ if (gr_check_group_change(gid, gid, gid))
33129 ++ return -EPERM;
33130 ++
33131 + if (capable(CAP_SETGID)) {
33132 + if (old_egid != gid) {
33133 + set_dumpable(current->mm, suid_dumpable);
33134 + smp_wmb();
33135 + }
33136 ++
33137 ++ gr_set_role_label(current, current->uid, gid);
33138 ++
33139 + current->gid = current->egid = current->sgid = current->fsgid = gid;
33140 + } else if ((gid == current->gid) || (gid == current->sgid)) {
33141 + if (old_egid != gid) {
33142 +@@ -570,6 +590,9 @@ static int set_user(uid_t new_ruid, int
33143 + set_dumpable(current->mm, suid_dumpable);
33144 + smp_wmb();
33145 + }
33146 ++
33147 ++ gr_set_role_label(current, new_ruid, current->gid);
33148 ++
33149 + current->uid = new_ruid;
33150 + return 0;
33151 + }
33152 +@@ -619,6 +642,9 @@ asmlinkage long sys_setreuid(uid_t ruid,
33153 + return -EPERM;
33154 + }
33155 +
33156 ++ if (gr_check_user_change(new_ruid, new_euid, -1))
33157 ++ return -EPERM;
33158 ++
33159 + if (new_ruid != old_ruid && set_user(new_ruid, new_euid != old_euid) < 0)
33160 + return -EAGAIN;
33161 +
33162 +@@ -665,6 +691,12 @@ asmlinkage long sys_setuid(uid_t uid)
33163 + old_suid = current->suid;
33164 + new_suid = old_suid;
33165 +
33166 ++ if (gr_check_crash_uid(uid))
33167 ++ return -EPERM;
33168 ++
33169 ++ if (gr_check_user_change(uid, uid, uid))
33170 ++ return -EPERM;
33171 ++
33172 + if (capable(CAP_SETUID)) {
33173 + if (uid != old_ruid && set_user(uid, old_euid != uid) < 0)
33174 + return -EAGAIN;
33175 +@@ -712,6 +744,10 @@ asmlinkage long sys_setresuid(uid_t ruid
33176 + (suid != current->euid) && (suid != current->suid))
33177 + return -EPERM;
33178 + }
33179 ++
33180 ++ if (gr_check_user_change(ruid, euid, -1))
33181 ++ return -EPERM;
33182 ++
33183 + if (ruid != (uid_t) -1) {
33184 + if (ruid != current->uid && set_user(ruid, euid != current->euid) < 0)
33185 + return -EAGAIN;
33186 +@@ -766,6 +802,10 @@ asmlinkage long sys_setresgid(gid_t rgid
33187 + (sgid != current->egid) && (sgid != current->sgid))
33188 + return -EPERM;
33189 + }
33190 ++
33191 ++ if (gr_check_group_change(rgid, egid, -1))
33192 ++ return -EPERM;
33193 ++
33194 + if (egid != (gid_t) -1) {
33195 + if (egid != current->egid) {
33196 + set_dumpable(current->mm, suid_dumpable);
33197 +@@ -774,8 +814,10 @@ asmlinkage long sys_setresgid(gid_t rgid
33198 + current->egid = egid;
33199 + }
33200 + current->fsgid = current->egid;
33201 +- if (rgid != (gid_t) -1)
33202 ++ if (rgid != (gid_t) -1) {
33203 ++ gr_set_role_label(current, current->uid, rgid);
33204 + current->gid = rgid;
33205 ++ }
33206 + if (sgid != (gid_t) -1)
33207 + current->sgid = sgid;
33208 +
33209 +@@ -810,6 +852,9 @@ asmlinkage long sys_setfsuid(uid_t uid)
33210 + if (security_task_setuid(uid, (uid_t)-1, (uid_t)-1, LSM_SETID_FS))
33211 + return old_fsuid;
33212 +
33213 ++ if (gr_check_user_change(-1, -1, uid))
33214 ++ return old_fsuid;
33215 ++
33216 + if (uid == current->uid || uid == current->euid ||
33217 + uid == current->suid || uid == current->fsuid ||
33218 + capable(CAP_SETUID)) {
33219 +@@ -842,6 +887,9 @@ asmlinkage long sys_setfsgid(gid_t gid)
33220 + if (gid == current->gid || gid == current->egid ||
33221 + gid == current->sgid || gid == current->fsgid ||
33222 + capable(CAP_SETGID)) {
33223 ++ if (gr_check_group_change(-1, -1, gid))
33224 ++ return old_fsgid;
33225 ++
33226 + if (gid != old_fsgid) {
33227 + set_dumpable(current->mm, suid_dumpable);
33228 + smp_wmb();
33229 +@@ -923,7 +971,10 @@ asmlinkage long sys_setpgid(pid_t pid, p
33230 + write_lock_irq(&tasklist_lock);
33231 +
33232 + err = -ESRCH;
33233 +- p = find_task_by_vpid(pid);
33234 ++ /* grsec: replaced find_task_by_vpid with equivalent call which
33235 ++ lacks the chroot restriction
33236 ++ */
33237 ++ p = pid_task(find_pid_ns(pid, current->nsproxy->pid_ns), PIDTYPE_PID);
33238 + if (!p)
33239 + goto out;
33240 +
33241 +@@ -1655,7 +1706,7 @@ asmlinkage long sys_prctl(int option, un
33242 + error = get_dumpable(current->mm);
33243 + break;
33244 + case PR_SET_DUMPABLE:
33245 +- if (arg2 < 0 || arg2 > 1) {
33246 ++ if (arg2 > 1) {
33247 + error = -EINVAL;
33248 + break;
33249 + }
33250 +diff -urNp linux-2.6.27.10/kernel/sysctl.c linux-2.6.27.10/kernel/sysctl.c
33251 +--- linux-2.6.27.10/kernel/sysctl.c 2008-12-10 22:35:38.000000000 -0500
33252 ++++ linux-2.6.27.10/kernel/sysctl.c 2008-12-10 22:35:46.000000000 -0500
33253 +@@ -61,6 +61,13 @@
33254 + static int deprecated_sysctl_warning(struct __sysctl_args *args);
33255 +
33256 + #if defined(CONFIG_SYSCTL)
33257 ++#include <linux/grsecurity.h>
33258 ++#include <linux/grinternal.h>
33259 ++
33260 ++extern __u32 gr_handle_sysctl(const ctl_table *table, const int op);
33261 ++extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
33262 ++ const int op);
33263 ++extern int gr_handle_chroot_sysctl(const int op);
33264 +
33265 + /* External variables not in a header file. */
33266 + extern int C_A_D;
33267 +@@ -155,6 +162,7 @@ static int proc_do_cad_pid(struct ctl_ta
33268 + static int proc_dointvec_taint(struct ctl_table *table, int write, struct file *filp,
33269 + void __user *buffer, size_t *lenp, loff_t *ppos);
33270 + #endif
33271 ++extern ctl_table grsecurity_table[];
33272 +
33273 + static struct ctl_table root_table[];
33274 + static struct ctl_table_root sysctl_table_root;
33275 +@@ -187,6 +195,21 @@ extern struct ctl_table epoll_table[];
33276 + int sysctl_legacy_va_layout;
33277 + #endif
33278 +
33279 ++#ifdef CONFIG_PAX_SOFTMODE
33280 ++static ctl_table pax_table[] = {
33281 ++ {
33282 ++ .ctl_name = CTL_UNNUMBERED,
33283 ++ .procname = "softmode",
33284 ++ .data = &pax_softmode,
33285 ++ .maxlen = sizeof(unsigned int),
33286 ++ .mode = 0600,
33287 ++ .proc_handler = &proc_dointvec,
33288 ++ },
33289 ++
33290 ++ { .ctl_name = 0 }
33291 ++};
33292 ++#endif
33293 ++
33294 + extern int prove_locking;
33295 + extern int lock_stat;
33296 +
33297 +@@ -223,6 +246,7 @@ static struct ctl_table root_table[] = {
33298 + .mode = 0555,
33299 + .child = dev_table,
33300 + },
33301 ++
33302 + /*
33303 + * NOTE: do not add new entries to this table unless you have read
33304 + * Documentation/sysctl/ctl_unnumbered.txt
33305 +@@ -850,6 +874,25 @@ static struct ctl_table kern_table[] = {
33306 + .proc_handler = &proc_dointvec,
33307 + },
33308 + #endif
33309 ++
33310 ++#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_MODSTOP)
33311 ++ {
33312 ++ .ctl_name = CTL_UNNUMBERED,
33313 ++ .procname = "grsecurity",
33314 ++ .mode = 0500,
33315 ++ .child = grsecurity_table,
33316 ++ },
33317 ++#endif
33318 ++
33319 ++#ifdef CONFIG_PAX_SOFTMODE
33320 ++ {
33321 ++ .ctl_name = CTL_UNNUMBERED,
33322 ++ .procname = "pax",
33323 ++ .mode = 0500,
33324 ++ .child = pax_table,
33325 ++ },
33326 ++#endif
33327 ++
33328 + /*
33329 + * NOTE: do not add new entries to this table unless you have read
33330 + * Documentation/sysctl/ctl_unnumbered.txt
33331 +@@ -1179,6 +1222,7 @@ static struct ctl_table vm_table[] = {
33332 + .extra2 = &one,
33333 + },
33334 + #endif
33335 ++
33336 + /*
33337 + * NOTE: do not add new entries to this table unless you have read
33338 + * Documentation/sysctl/ctl_unnumbered.txt
33339 +@@ -1553,6 +1597,8 @@ static int do_sysctl_strategy(struct ctl
33340 + return 0;
33341 + }
33342 +
33343 ++static int sysctl_perm_nochk(struct ctl_table_root *root, struct ctl_table *table, int op);
33344 ++
33345 + static int parse_table(int __user *name, int nlen,
33346 + void __user *oldval, size_t __user *oldlenp,
33347 + void __user *newval, size_t newlen,
33348 +@@ -1571,7 +1617,7 @@ repeat:
33349 + if (n == table->ctl_name) {
33350 + int error;
33351 + if (table->child) {
33352 +- if (sysctl_perm(root, table, MAY_EXEC))
33353 ++ if (sysctl_perm_nochk(root, table, MAY_EXEC))
33354 + return -EPERM;
33355 + name++;
33356 + nlen--;
33357 +@@ -1656,6 +1702,33 @@ int sysctl_perm(struct ctl_table_root *r
33358 + int error;
33359 + int mode;
33360 +
33361 ++ if (table->parent != NULL && table->parent->procname != NULL &&
33362 ++ table->procname != NULL &&
33363 ++ gr_handle_sysctl_mod(table->parent->procname, table->procname, op))
33364 ++ return -EACCES;
33365 ++ if (gr_handle_chroot_sysctl(op))
33366 ++ return -EACCES;
33367 ++ error = gr_handle_sysctl(table, op);
33368 ++ if (error)
33369 ++ return error;
33370 ++
33371 ++ error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
33372 ++ if (error)
33373 ++ return error;
33374 ++
33375 ++ if (root->permissions)
33376 ++ mode = root->permissions(root, current->nsproxy, table);
33377 ++ else
33378 ++ mode = table->mode;
33379 ++
33380 ++ return test_perm(mode, op);
33381 ++}
33382 ++
33383 ++int sysctl_perm_nochk(struct ctl_table_root *root, struct ctl_table *table, int op)
33384 ++{
33385 ++ int error;
33386 ++ int mode;
33387 ++
33388 + error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
33389 + if (error)
33390 + return error;
33391 +diff -urNp linux-2.6.27.10/kernel/time/tick-broadcast.c linux-2.6.27.10/kernel/time/tick-broadcast.c
33392 +--- linux-2.6.27.10/kernel/time/tick-broadcast.c 2008-11-07 12:55:34.000000000 -0500
33393 ++++ linux-2.6.27.10/kernel/time/tick-broadcast.c 2008-11-18 03:38:45.000000000 -0500
33394 +@@ -114,7 +114,7 @@ int tick_device_uses_broadcast(struct cl
33395 + * then clear the broadcast bit.
33396 + */
33397 + if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
33398 +- int cpu = smp_processor_id();
33399 ++ cpu = smp_processor_id();
33400 +
33401 + cpu_clear(cpu, tick_broadcast_mask);
33402 + tick_broadcast_clear_oneshot(cpu);
33403 +diff -urNp linux-2.6.27.10/kernel/time.c linux-2.6.27.10/kernel/time.c
33404 +--- linux-2.6.27.10/kernel/time.c 2008-11-07 12:55:34.000000000 -0500
33405 ++++ linux-2.6.27.10/kernel/time.c 2008-11-18 03:38:45.000000000 -0500
33406 +@@ -37,6 +37,7 @@
33407 + #include <linux/fs.h>
33408 + #include <linux/slab.h>
33409 + #include <linux/math64.h>
33410 ++#include <linux/grsecurity.h>
33411 +
33412 + #include <asm/uaccess.h>
33413 + #include <asm/unistd.h>
33414 +@@ -92,6 +93,9 @@ asmlinkage long sys_stime(time_t __user
33415 + return err;
33416 +
33417 + do_settimeofday(&tv);
33418 ++
33419 ++ gr_log_timechange();
33420 ++
33421 + return 0;
33422 + }
33423 +
33424 +@@ -200,6 +204,8 @@ asmlinkage long sys_settimeofday(struct
33425 + return -EFAULT;
33426 + }
33427 +
33428 ++ gr_log_timechange();
33429 ++
33430 + return do_sys_settimeofday(tv ? &new_ts : NULL, tz ? &new_tz : NULL);
33431 + }
33432 +
33433 +@@ -238,7 +244,7 @@ EXPORT_SYMBOL(current_fs_time);
33434 + * Avoid unnecessary multiplications/divisions in the
33435 + * two most common HZ cases:
33436 + */
33437 +-unsigned int inline jiffies_to_msecs(const unsigned long j)
33438 ++inline unsigned int jiffies_to_msecs(const unsigned long j)
33439 + {
33440 + #if HZ <= MSEC_PER_SEC && !(MSEC_PER_SEC % HZ)
33441 + return (MSEC_PER_SEC / HZ) * j;
33442 +@@ -254,7 +260,7 @@ unsigned int inline jiffies_to_msecs(con
33443 + }
33444 + EXPORT_SYMBOL(jiffies_to_msecs);
33445 +
33446 +-unsigned int inline jiffies_to_usecs(const unsigned long j)
33447 ++inline unsigned int jiffies_to_usecs(const unsigned long j)
33448 + {
33449 + #if HZ <= USEC_PER_SEC && !(USEC_PER_SEC % HZ)
33450 + return (USEC_PER_SEC / HZ) * j;
33451 +diff -urNp linux-2.6.27.10/kernel/utsname_sysctl.c linux-2.6.27.10/kernel/utsname_sysctl.c
33452 +--- linux-2.6.27.10/kernel/utsname_sysctl.c 2008-11-07 12:55:34.000000000 -0500
33453 ++++ linux-2.6.27.10/kernel/utsname_sysctl.c 2008-11-18 03:38:45.000000000 -0500
33454 +@@ -124,7 +124,7 @@ static struct ctl_table uts_kern_table[]
33455 + .proc_handler = proc_do_uts_string,
33456 + .strategy = sysctl_uts_string,
33457 + },
33458 +- {}
33459 ++ { 0, NULL, NULL, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL }
33460 + };
33461 +
33462 + static struct ctl_table uts_root_table[] = {
33463 +@@ -134,7 +134,7 @@ static struct ctl_table uts_root_table[]
33464 + .mode = 0555,
33465 + .child = uts_kern_table,
33466 + },
33467 +- {}
33468 ++ { 0, NULL, NULL, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL }
33469 + };
33470 +
33471 + static int __init utsname_sysctl_init(void)
33472 +diff -urNp linux-2.6.27.10/lib/radix-tree.c linux-2.6.27.10/lib/radix-tree.c
33473 +--- linux-2.6.27.10/lib/radix-tree.c 2008-11-07 12:55:34.000000000 -0500
33474 ++++ linux-2.6.27.10/lib/radix-tree.c 2008-11-18 03:38:45.000000000 -0500
33475 +@@ -81,7 +81,7 @@ struct radix_tree_preload {
33476 + int nr;
33477 + struct radix_tree_node *nodes[RADIX_TREE_MAX_PATH];
33478 + };
33479 +-DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
33480 ++DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
33481 +
33482 + static inline gfp_t root_gfp_mask(struct radix_tree_root *root)
33483 + {
33484 +diff -urNp linux-2.6.27.10/localversion-grsec linux-2.6.27.10/localversion-grsec
33485 +--- linux-2.6.27.10/localversion-grsec 1969-12-31 19:00:00.000000000 -0500
33486 ++++ linux-2.6.27.10/localversion-grsec 2008-11-18 03:38:45.000000000 -0500
33487 +@@ -0,0 +1 @@
33488 ++-grsec
33489 +diff -urNp linux-2.6.27.10/Makefile linux-2.6.27.10/Makefile
33490 +--- linux-2.6.27.10/Makefile 2008-12-21 01:18:11.000000000 -0500
33491 ++++ linux-2.6.27.10/Makefile 2008-12-21 01:18:21.000000000 -0500
33492 +@@ -221,7 +221,7 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH"
33493 +
33494 + HOSTCC = gcc
33495 + HOSTCXX = g++
33496 +-HOSTCFLAGS = -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer
33497 ++HOSTCFLAGS = -Wall -W -Wno-unused -Wno-sign-compare -Wstrict-prototypes -O2 -fomit-frame-pointer
33498 + HOSTCXXFLAGS = -O2
33499 +
33500 + # Decide whether to build built-in, modular, or both.
33501 +@@ -619,7 +619,7 @@ export mod_strip_cmd
33502 +
33503 +
33504 + ifeq ($(KBUILD_EXTMOD),)
33505 +-core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
33506 ++core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
33507 +
33508 + vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
33509 + $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
33510 +diff -urNp linux-2.6.27.10/mm/filemap.c linux-2.6.27.10/mm/filemap.c
33511 +--- linux-2.6.27.10/mm/filemap.c 2008-11-07 12:55:34.000000000 -0500
33512 ++++ linux-2.6.27.10/mm/filemap.c 2008-11-18 03:38:45.000000000 -0500
33513 +@@ -33,6 +33,7 @@
33514 + #include <linux/cpuset.h>
33515 + #include <linux/hardirq.h> /* for BUG_ON(!in_atomic()) only */
33516 + #include <linux/memcontrol.h>
33517 ++#include <linux/grsecurity.h>
33518 + #include "internal.h"
33519 +
33520 + /*
33521 +@@ -1588,7 +1589,7 @@ int generic_file_mmap(struct file * file
33522 + struct address_space *mapping = file->f_mapping;
33523 +
33524 + if (!mapping->a_ops->readpage)
33525 +- return -ENOEXEC;
33526 ++ return -ENODEV;
33527 + file_accessed(file);
33528 + vma->vm_ops = &generic_file_vm_ops;
33529 + vma->vm_flags |= VM_CAN_NONLINEAR;
33530 +@@ -1949,6 +1950,7 @@ inline int generic_write_checks(struct f
33531 + *pos = i_size_read(inode);
33532 +
33533 + if (limit != RLIM_INFINITY) {
33534 ++ gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
33535 + if (*pos >= limit) {
33536 + send_sig(SIGXFSZ, current, 0);
33537 + return -EFBIG;
33538 +diff -urNp linux-2.6.27.10/mm/fremap.c linux-2.6.27.10/mm/fremap.c
33539 +--- linux-2.6.27.10/mm/fremap.c 2008-11-07 12:55:34.000000000 -0500
33540 ++++ linux-2.6.27.10/mm/fremap.c 2008-11-18 03:38:45.000000000 -0500
33541 +@@ -151,6 +151,13 @@ asmlinkage long sys_remap_file_pages(uns
33542 + retry:
33543 + vma = find_vma(mm, start);
33544 +
33545 ++#ifdef CONFIG_PAX_SEGMEXEC
33546 ++ if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC)) {
33547 ++ up_read(&mm->mmap_sem);
33548 ++ return err;
33549 ++ }
33550 ++#endif
33551 ++
33552 + /*
33553 + * Make sure the vma is shared, that it supports prefaulting,
33554 + * and that the remapped range is valid and fully within
33555 +diff -urNp linux-2.6.27.10/mm/hugetlb.c linux-2.6.27.10/mm/hugetlb.c
33556 +--- linux-2.6.27.10/mm/hugetlb.c 2008-11-18 11:38:40.000000000 -0500
33557 ++++ linux-2.6.27.10/mm/hugetlb.c 2008-11-18 11:40:53.000000000 -0500
33558 +@@ -1833,6 +1833,26 @@ int unmap_ref_private(struct mm_struct *
33559 + return 1;
33560 + }
33561 +
33562 ++#ifdef CONFIG_PAX_SEGMEXEC
33563 ++static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
33564 ++{
33565 ++ struct mm_struct *mm = vma->vm_mm;
33566 ++ struct vm_area_struct *vma_m;
33567 ++ unsigned long address_m;
33568 ++ pte_t *ptep_m;
33569 ++
33570 ++ vma_m = pax_find_mirror_vma(vma);
33571 ++ if (!vma_m)
33572 ++ return;
33573 ++
33574 ++ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
33575 ++ address_m = address + SEGMEXEC_TASK_SIZE;
33576 ++ ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
33577 ++ get_page(page_m);
33578 ++ set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
33579 ++}
33580 ++#endif
33581 ++
33582 + static int hugetlb_cow(struct mm_struct *mm, struct vm_area_struct *vma,
33583 + unsigned long address, pte_t *ptep, pte_t pte,
33584 + struct page *pagecache_page)
33585 +@@ -1904,6 +1924,11 @@ retry_avoidcopy:
33586 + huge_ptep_clear_flush(vma, address, ptep);
33587 + set_huge_pte_at(mm, address, ptep,
33588 + make_huge_pte(vma, new_page, 1));
33589 ++
33590 ++#ifdef CONFIG_PAX_SEGMEXEC
33591 ++ pax_mirror_huge_pte(vma, address, new_page);
33592 ++#endif
33593 ++
33594 + /* Make the old page be freed below */
33595 + new_page = old_page;
33596 + }
33597 +@@ -2013,6 +2038,10 @@ retry:
33598 + && (vma->vm_flags & VM_SHARED)));
33599 + set_huge_pte_at(mm, address, ptep, new_pte);
33600 +
33601 ++#ifdef CONFIG_PAX_SEGMEXEC
33602 ++ pax_mirror_huge_pte(vma, address, page);
33603 ++#endif
33604 ++
33605 + if (write_access && !(vma->vm_flags & VM_SHARED)) {
33606 + /* Optimization, do the COW without a second fault */
33607 + ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
33608 +@@ -2041,6 +2070,28 @@ int hugetlb_fault(struct mm_struct *mm,
33609 + static DEFINE_MUTEX(hugetlb_instantiation_mutex);
33610 + struct hstate *h = hstate_vma(vma);
33611 +
33612 ++#ifdef CONFIG_PAX_SEGMEXEC
33613 ++ struct vm_area_struct *vma_m;
33614 ++
33615 ++ vma_m = pax_find_mirror_vma(vma);
33616 ++ if (vma_m) {
33617 ++ unsigned long address_m;
33618 ++
33619 ++ if (vma->vm_start > vma_m->vm_start) {
33620 ++ address_m = address;
33621 ++ address -= SEGMEXEC_TASK_SIZE;
33622 ++ vma = vma_m;
33623 ++ h = hstate_vma(vma);
33624 ++ } else
33625 ++ address_m = address + SEGMEXEC_TASK_SIZE;
33626 ++
33627 ++ if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
33628 ++ return VM_FAULT_OOM;
33629 ++ address_m &= HPAGE_MASK;
33630 ++ unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
33631 ++ }
33632 ++#endif
33633 ++
33634 + ptep = huge_pte_alloc(mm, address, huge_page_size(h));
33635 + if (!ptep)
33636 + return VM_FAULT_OOM;
33637 +diff -urNp linux-2.6.27.10/mm/madvise.c linux-2.6.27.10/mm/madvise.c
33638 +--- linux-2.6.27.10/mm/madvise.c 2008-11-07 12:55:34.000000000 -0500
33639 ++++ linux-2.6.27.10/mm/madvise.c 2008-11-18 03:38:45.000000000 -0500
33640 +@@ -43,6 +43,10 @@ static long madvise_behavior(struct vm_a
33641 + pgoff_t pgoff;
33642 + int new_flags = vma->vm_flags;
33643 +
33644 ++#ifdef CONFIG_PAX_SEGMEXEC
33645 ++ struct vm_area_struct *vma_m;
33646 ++#endif
33647 ++
33648 + switch (behavior) {
33649 + case MADV_NORMAL:
33650 + new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
33651 +@@ -92,6 +96,13 @@ success:
33652 + /*
33653 + * vm_flags is protected by the mmap_sem held in write mode.
33654 + */
33655 ++
33656 ++#ifdef CONFIG_PAX_SEGMEXEC
33657 ++ vma_m = pax_find_mirror_vma(vma);
33658 ++ if (vma_m)
33659 ++ vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
33660 ++#endif
33661 ++
33662 + vma->vm_flags = new_flags;
33663 +
33664 + out:
33665 +@@ -236,6 +247,17 @@ madvise_vma(struct vm_area_struct *vma,
33666 +
33667 + case MADV_DONTNEED:
33668 + error = madvise_dontneed(vma, prev, start, end);
33669 ++
33670 ++#ifdef CONFIG_PAX_SEGMEXEC
33671 ++ if (!error) {
33672 ++ struct vm_area_struct *vma_m, *prev_m;
33673 ++
33674 ++ vma_m = pax_find_mirror_vma(vma);
33675 ++ if (vma_m)
33676 ++ error = madvise_dontneed(vma_m, &prev_m, start + SEGMEXEC_TASK_SIZE, end + SEGMEXEC_TASK_SIZE);
33677 ++ }
33678 ++#endif
33679 ++
33680 + break;
33681 +
33682 + default:
33683 +@@ -308,6 +330,16 @@ asmlinkage long sys_madvise(unsigned lon
33684 + if (end < start)
33685 + goto out;
33686 +
33687 ++#ifdef CONFIG_PAX_SEGMEXEC
33688 ++ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
33689 ++ if (end > SEGMEXEC_TASK_SIZE)
33690 ++ goto out;
33691 ++ } else
33692 ++#endif
33693 ++
33694 ++ if (end > TASK_SIZE)
33695 ++ goto out;
33696 ++
33697 + error = 0;
33698 + if (end == start)
33699 + goto out;
33700 +diff -urNp linux-2.6.27.10/mm/memory.c linux-2.6.27.10/mm/memory.c
33701 +--- linux-2.6.27.10/mm/memory.c 2008-11-07 12:55:34.000000000 -0500
33702 ++++ linux-2.6.27.10/mm/memory.c 2008-11-18 03:38:45.000000000 -0500
33703 +@@ -52,6 +52,7 @@
33704 + #include <linux/writeback.h>
33705 + #include <linux/memcontrol.h>
33706 + #include <linux/mmu_notifier.h>
33707 ++#include <linux/grsecurity.h>
33708 +
33709 + #include <asm/pgalloc.h>
33710 + #include <asm/uaccess.h>
33711 +@@ -1146,11 +1147,11 @@ int get_user_pages(struct task_struct *t
33712 + vm_flags &= force ? (VM_MAYREAD | VM_MAYWRITE) : (VM_READ | VM_WRITE);
33713 + i = 0;
33714 +
33715 +- do {
33716 ++ while (len) {
33717 + struct vm_area_struct *vma;
33718 + unsigned int foll_flags;
33719 +
33720 +- vma = find_extend_vma(mm, start);
33721 ++ vma = find_vma(mm, start);
33722 + if (!vma && in_gate_area(tsk, start)) {
33723 + unsigned long pg = start & PAGE_MASK;
33724 + struct vm_area_struct *gate_vma = get_gate_vma(tsk);
33725 +@@ -1190,7 +1191,7 @@ int get_user_pages(struct task_struct *t
33726 + continue;
33727 + }
33728 +
33729 +- if (!vma || (vma->vm_flags & (VM_IO | VM_PFNMAP))
33730 ++ if (!vma || start < vma->vm_start || (vma->vm_flags & (VM_IO | VM_PFNMAP))
33731 + || !(vm_flags & vma->vm_flags))
33732 + return i ? : -EFAULT;
33733 +
33734 +@@ -1263,7 +1264,7 @@ int get_user_pages(struct task_struct *t
33735 + start += PAGE_SIZE;
33736 + len--;
33737 + } while (len && start < vma->vm_end);
33738 +- } while (len);
33739 ++ }
33740 + return i;
33741 + }
33742 + EXPORT_SYMBOL(get_user_pages);
33743 +@@ -1741,6 +1742,186 @@ static inline void cow_user_page(struct
33744 + copy_user_highpage(dst, src, va, vma);
33745 + }
33746 +
33747 ++#ifdef CONFIG_PAX_SEGMEXEC
33748 ++static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
33749 ++{
33750 ++ struct mm_struct *mm = vma->vm_mm;
33751 ++ spinlock_t *ptl;
33752 ++ pte_t *pte, entry;
33753 ++
33754 ++ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
33755 ++ entry = *pte;
33756 ++ if (!pte_present(entry)) {
33757 ++ if (!pte_none(entry)) {
33758 ++ BUG_ON(pte_file(entry));
33759 ++ free_swap_and_cache(pte_to_swp_entry(entry));
33760 ++ pte_clear_not_present_full(mm, address, pte, 0);
33761 ++ }
33762 ++ } else {
33763 ++ struct page *page;
33764 ++
33765 ++ flush_cache_page(vma, address, pte_pfn(entry));
33766 ++ entry = ptep_clear_flush(vma, address, pte);
33767 ++ BUG_ON(pte_dirty(entry));
33768 ++ page = vm_normal_page(vma, address, entry);
33769 ++ if (page) {
33770 ++ update_hiwater_rss(mm);
33771 ++ if (PageAnon(page))
33772 ++ dec_mm_counter(mm, anon_rss);
33773 ++ else
33774 ++ dec_mm_counter(mm, file_rss);
33775 ++ page_remove_rmap(page, vma);
33776 ++ page_cache_release(page);
33777 ++ }
33778 ++ }
33779 ++ pte_unmap_unlock(pte, ptl);
33780 ++}
33781 ++
33782 ++/* PaX: if vma is mirrored, synchronize the mirror's PTE
33783 ++ *
33784 ++ * the ptl of the lower mapped page is held on entry and is not released on exit
33785 ++ * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
33786 ++ */
33787 ++static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
33788 ++{
33789 ++ struct mm_struct *mm = vma->vm_mm;
33790 ++ unsigned long address_m;
33791 ++ spinlock_t *ptl_m;
33792 ++ struct vm_area_struct *vma_m;
33793 ++ pmd_t *pmd_m;
33794 ++ pte_t *pte_m, entry_m;
33795 ++
33796 ++ BUG_ON(!page_m || !PageAnon(page_m));
33797 ++
33798 ++ vma_m = pax_find_mirror_vma(vma);
33799 ++ if (!vma_m)
33800 ++ return;
33801 ++
33802 ++ BUG_ON(!PageLocked(page_m));
33803 ++ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
33804 ++ address_m = address + SEGMEXEC_TASK_SIZE;
33805 ++ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
33806 ++ pte_m = pte_offset_map_nested(pmd_m, address_m);
33807 ++ ptl_m = pte_lockptr(mm, pmd_m);
33808 ++ if (ptl != ptl_m) {
33809 ++ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
33810 ++ if (!pte_none(*pte_m))
33811 ++ goto out;
33812 ++ }
33813 ++
33814 ++ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
33815 ++ page_cache_get(page_m);
33816 ++ page_add_anon_rmap(page_m, vma_m, address_m);
33817 ++ inc_mm_counter(mm, anon_rss);
33818 ++ set_pte_at(mm, address_m, pte_m, entry_m);
33819 ++ update_mmu_cache(vma_m, address_m, entry_m);
33820 ++out:
33821 ++ if (ptl != ptl_m)
33822 ++ spin_unlock(ptl_m);
33823 ++ pte_unmap_nested(pte_m);
33824 ++ unlock_page(page_m);
33825 ++}
33826 ++
33827 ++void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
33828 ++{
33829 ++ struct mm_struct *mm = vma->vm_mm;
33830 ++ unsigned long address_m;
33831 ++ spinlock_t *ptl_m;
33832 ++ struct vm_area_struct *vma_m;
33833 ++ pmd_t *pmd_m;
33834 ++ pte_t *pte_m, entry_m;
33835 ++
33836 ++ BUG_ON(!page_m || PageAnon(page_m));
33837 ++
33838 ++ vma_m = pax_find_mirror_vma(vma);
33839 ++ if (!vma_m)
33840 ++ return;
33841 ++
33842 ++ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
33843 ++ address_m = address + SEGMEXEC_TASK_SIZE;
33844 ++ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
33845 ++ pte_m = pte_offset_map_nested(pmd_m, address_m);
33846 ++ ptl_m = pte_lockptr(mm, pmd_m);
33847 ++ if (ptl != ptl_m) {
33848 ++ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
33849 ++ if (!pte_none(*pte_m))
33850 ++ goto out;
33851 ++ }
33852 ++
33853 ++ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
33854 ++ page_cache_get(page_m);
33855 ++ page_add_file_rmap(page_m);
33856 ++ inc_mm_counter(mm, file_rss);
33857 ++ set_pte_at(mm, address_m, pte_m, entry_m);
33858 ++ update_mmu_cache(vma_m, address_m, entry_m);
33859 ++out:
33860 ++ if (ptl != ptl_m)
33861 ++ spin_unlock(ptl_m);
33862 ++ pte_unmap_nested(pte_m);
33863 ++}
33864 ++
33865 ++static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
33866 ++{
33867 ++ struct mm_struct *mm = vma->vm_mm;
33868 ++ unsigned long address_m;
33869 ++ spinlock_t *ptl_m;
33870 ++ struct vm_area_struct *vma_m;
33871 ++ pmd_t *pmd_m;
33872 ++ pte_t *pte_m, entry_m;
33873 ++
33874 ++ vma_m = pax_find_mirror_vma(vma);
33875 ++ if (!vma_m)
33876 ++ return;
33877 ++
33878 ++ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
33879 ++ address_m = address + SEGMEXEC_TASK_SIZE;
33880 ++ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
33881 ++ pte_m = pte_offset_map_nested(pmd_m, address_m);
33882 ++ ptl_m = pte_lockptr(mm, pmd_m);
33883 ++ if (ptl != ptl_m) {
33884 ++ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
33885 ++ if (!pte_none(*pte_m))
33886 ++ goto out;
33887 ++ }
33888 ++
33889 ++ entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
33890 ++ set_pte_at(mm, address_m, pte_m, entry_m);
33891 ++out:
33892 ++ if (ptl != ptl_m)
33893 ++ spin_unlock(ptl_m);
33894 ++ pte_unmap_nested(pte_m);
33895 ++}
33896 ++
33897 ++static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
33898 ++{
33899 ++ struct page *page_m;
33900 ++ pte_t entry;
33901 ++
33902 ++ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
33903 ++ goto out;
33904 ++
33905 ++ entry = *pte;
33906 ++ page_m = vm_normal_page(vma, address, entry);
33907 ++ if (!page_m)
33908 ++ pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
33909 ++ else if (PageAnon(page_m)) {
33910 ++ if (pax_find_mirror_vma(vma)) {
33911 ++ pte_unmap_unlock(pte, ptl);
33912 ++ lock_page(page_m);
33913 ++ pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
33914 ++ if (pte_same(entry, *pte))
33915 ++ pax_mirror_anon_pte(vma, address, page_m, ptl);
33916 ++ else
33917 ++ unlock_page(page_m);
33918 ++ }
33919 ++ } else
33920 ++ pax_mirror_file_pte(vma, address, page_m, ptl);
33921 ++
33922 ++out:
33923 ++ pte_unmap_unlock(pte, ptl);
33924 ++}
33925 ++#endif
33926 ++
33927 + /*
33928 + * This routine handles present pages, when users try to write
33929 + * to a shared page. It is done by copying the page to a new address
33930 +@@ -1869,6 +2050,12 @@ gotten:
33931 + */
33932 + page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
33933 + if (likely(pte_same(*page_table, orig_pte))) {
33934 ++
33935 ++#ifdef CONFIG_PAX_SEGMEXEC
33936 ++ if (pax_find_mirror_vma(vma))
33937 ++ BUG_ON(!trylock_page(new_page));
33938 ++#endif
33939 ++
33940 + if (old_page) {
33941 + if (!PageAnon(old_page)) {
33942 + dec_mm_counter(mm, file_rss);
33943 +@@ -1917,6 +2104,10 @@ gotten:
33944 + page_remove_rmap(old_page, vma);
33945 + }
33946 +
33947 ++#ifdef CONFIG_PAX_SEGMEXEC
33948 ++ pax_mirror_anon_pte(vma, address, new_page, ptl);
33949 ++#endif
33950 ++
33951 + /* Free the old page.. */
33952 + new_page = old_page;
33953 + ret |= VM_FAULT_WRITE;
33954 +@@ -2176,6 +2367,7 @@ int vmtruncate(struct inode * inode, lof
33955 + unsigned long limit;
33956 +
33957 + limit = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
33958 ++ gr_learn_resource(current, RLIMIT_FSIZE, offset, 1);
33959 + if (limit != RLIM_INFINITY && offset > limit)
33960 + goto out_sig;
33961 + if (offset > inode->i_sb->s_maxbytes)
33962 +@@ -2326,6 +2518,11 @@ static int do_swap_page(struct mm_struct
33963 + swap_free(entry);
33964 + if (vm_swap_full())
33965 + remove_exclusive_swap_page(page);
33966 ++
33967 ++#ifdef CONFIG_PAX_SEGMEXEC
33968 ++ if (write_access || !pax_find_mirror_vma(vma))
33969 ++#endif
33970 ++
33971 + unlock_page(page);
33972 +
33973 + if (write_access) {
33974 +@@ -2337,6 +2534,11 @@ static int do_swap_page(struct mm_struct
33975 +
33976 + /* No need to invalidate - it was non-present before */
33977 + update_mmu_cache(vma, address, pte);
33978 ++
33979 ++#ifdef CONFIG_PAX_SEGMEXEC
33980 ++ pax_mirror_anon_pte(vma, address, page, ptl);
33981 ++#endif
33982 ++
33983 + unlock:
33984 + pte_unmap_unlock(page_table, ptl);
33985 + out:
33986 +@@ -2381,6 +2583,12 @@ static int do_anonymous_page(struct mm_s
33987 + page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
33988 + if (!pte_none(*page_table))
33989 + goto release;
33990 ++
33991 ++#ifdef CONFIG_PAX_SEGMEXEC
33992 ++ if (pax_find_mirror_vma(vma))
33993 ++ BUG_ON(!trylock_page(page));
33994 ++#endif
33995 ++
33996 + inc_mm_counter(mm, anon_rss);
33997 + lru_cache_add_active(page);
33998 + page_add_new_anon_rmap(page, vma, address);
33999 +@@ -2388,6 +2596,11 @@ static int do_anonymous_page(struct mm_s
34000 +
34001 + /* No need to invalidate - it was non-present before */
34002 + update_mmu_cache(vma, address, entry);
34003 ++
34004 ++#ifdef CONFIG_PAX_SEGMEXEC
34005 ++ pax_mirror_anon_pte(vma, address, page, ptl);
34006 ++#endif
34007 ++
34008 + unlock:
34009 + pte_unmap_unlock(page_table, ptl);
34010 + return 0;
34011 +@@ -2516,6 +2729,12 @@ static int __do_fault(struct mm_struct *
34012 + */
34013 + /* Only go through if we didn't race with anybody else... */
34014 + if (likely(pte_same(*page_table, orig_pte))) {
34015 ++
34016 ++#ifdef CONFIG_PAX_SEGMEXEC
34017 ++ if (anon && pax_find_mirror_vma(vma))
34018 ++ BUG_ON(!trylock_page(page));
34019 ++#endif
34020 ++
34021 + flush_icache_page(vma, page);
34022 + entry = mk_pte(page, vma->vm_page_prot);
34023 + if (flags & FAULT_FLAG_WRITE)
34024 +@@ -2536,6 +2755,14 @@ static int __do_fault(struct mm_struct *
34025 +
34026 + /* no need to invalidate: a not-present page won't be cached */
34027 + update_mmu_cache(vma, address, entry);
34028 ++
34029 ++#ifdef CONFIG_PAX_SEGMEXEC
34030 ++ if (anon)
34031 ++ pax_mirror_anon_pte(vma, address, page, ptl);
34032 ++ else
34033 ++ pax_mirror_file_pte(vma, address, page, ptl);
34034 ++#endif
34035 ++
34036 + } else {
34037 + mem_cgroup_uncharge_page(page);
34038 + if (anon)
34039 +@@ -2668,6 +2895,12 @@ static inline int handle_pte_fault(struc
34040 + if (write_access)
34041 + flush_tlb_page(vma, address);
34042 + }
34043 ++
34044 ++#ifdef CONFIG_PAX_SEGMEXEC
34045 ++ pax_mirror_pte(vma, address, pte, pmd, ptl);
34046 ++ return 0;
34047 ++#endif
34048 ++
34049 + unlock:
34050 + pte_unmap_unlock(pte, ptl);
34051 + return 0;
34052 +@@ -2684,6 +2917,10 @@ int handle_mm_fault(struct mm_struct *mm
34053 + pmd_t *pmd;
34054 + pte_t *pte;
34055 +
34056 ++#ifdef CONFIG_PAX_SEGMEXEC
34057 ++ struct vm_area_struct *vma_m;
34058 ++#endif
34059 ++
34060 + __set_current_state(TASK_RUNNING);
34061 +
34062 + count_vm_event(PGFAULT);
34063 +@@ -2691,6 +2928,34 @@ int handle_mm_fault(struct mm_struct *mm
34064 + if (unlikely(is_vm_hugetlb_page(vma)))
34065 + return hugetlb_fault(mm, vma, address, write_access);
34066 +
34067 ++#ifdef CONFIG_PAX_SEGMEXEC
34068 ++ vma_m = pax_find_mirror_vma(vma);
34069 ++ if (vma_m) {
34070 ++ unsigned long address_m;
34071 ++ pgd_t *pgd_m;
34072 ++ pud_t *pud_m;
34073 ++ pmd_t *pmd_m;
34074 ++
34075 ++ if (vma->vm_start > vma_m->vm_start) {
34076 ++ address_m = address;
34077 ++ address -= SEGMEXEC_TASK_SIZE;
34078 ++ vma = vma_m;
34079 ++ } else
34080 ++ address_m = address + SEGMEXEC_TASK_SIZE;
34081 ++
34082 ++ pgd_m = pgd_offset(mm, address_m);
34083 ++ pud_m = pud_alloc(mm, pgd_m, address_m);
34084 ++ if (!pud_m)
34085 ++ return VM_FAULT_OOM;
34086 ++ pmd_m = pmd_alloc(mm, pud_m, address_m);
34087 ++ if (!pmd_m)
34088 ++ return VM_FAULT_OOM;
34089 ++ if (!pmd_present(*pmd_m) && __pte_alloc(mm, pmd_m, address_m))
34090 ++ return VM_FAULT_OOM;
34091 ++ pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
34092 ++ }
34093 ++#endif
34094 ++
34095 + pgd = pgd_offset(mm, address);
34096 + pud = pud_alloc(mm, pgd, address);
34097 + if (!pud)
34098 +@@ -2798,7 +3063,7 @@ static int __init gate_vma_init(void)
34099 + gate_vma.vm_start = FIXADDR_USER_START;
34100 + gate_vma.vm_end = FIXADDR_USER_END;
34101 + gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
34102 +- gate_vma.vm_page_prot = __P101;
34103 ++ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
34104 + /*
34105 + * Make sure the vDSO gets into every core dump.
34106 + * Dumping its contents makes post-mortem fully interpretable later
34107 +diff -urNp linux-2.6.27.10/mm/mempolicy.c linux-2.6.27.10/mm/mempolicy.c
34108 +--- linux-2.6.27.10/mm/mempolicy.c 2008-11-07 12:55:34.000000000 -0500
34109 ++++ linux-2.6.27.10/mm/mempolicy.c 2008-11-18 03:38:45.000000000 -0500
34110 +@@ -555,6 +555,10 @@ static int mbind_range(struct vm_area_st
34111 + struct vm_area_struct *next;
34112 + int err;
34113 +
34114 ++#ifdef CONFIG_PAX_SEGMEXEC
34115 ++ struct vm_area_struct *vma_m;
34116 ++#endif
34117 ++
34118 + err = 0;
34119 + for (; vma && vma->vm_start < end; vma = next) {
34120 + next = vma->vm_next;
34121 +@@ -566,6 +570,16 @@ static int mbind_range(struct vm_area_st
34122 + err = policy_vma(vma, new);
34123 + if (err)
34124 + break;
34125 ++
34126 ++#ifdef CONFIG_PAX_SEGMEXEC
34127 ++ vma_m = pax_find_mirror_vma(vma);
34128 ++ if (vma_m) {
34129 ++ err = policy_vma(vma_m, new);
34130 ++ if (err)
34131 ++ break;
34132 ++ }
34133 ++#endif
34134 ++
34135 + }
34136 + return err;
34137 + }
34138 +@@ -951,6 +965,17 @@ static long do_mbind(unsigned long start
34139 +
34140 + if (end < start)
34141 + return -EINVAL;
34142 ++
34143 ++#ifdef CONFIG_PAX_SEGMEXEC
34144 ++ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
34145 ++ if (end > SEGMEXEC_TASK_SIZE)
34146 ++ return -EINVAL;
34147 ++ } else
34148 ++#endif
34149 ++
34150 ++ if (end > TASK_SIZE)
34151 ++ return -EINVAL;
34152 ++
34153 + if (end == start)
34154 + return 0;
34155 +
34156 +diff -urNp linux-2.6.27.10/mm/mlock.c linux-2.6.27.10/mm/mlock.c
34157 +--- linux-2.6.27.10/mm/mlock.c 2008-11-07 12:55:34.000000000 -0500
34158 ++++ linux-2.6.27.10/mm/mlock.c 2008-11-18 03:38:45.000000000 -0500
34159 +@@ -12,6 +12,7 @@
34160 + #include <linux/syscalls.h>
34161 + #include <linux/sched.h>
34162 + #include <linux/module.h>
34163 ++#include <linux/grsecurity.h>
34164 +
34165 + int can_do_mlock(void)
34166 + {
34167 +@@ -93,6 +94,17 @@ static int do_mlock(unsigned long start,
34168 + return -EINVAL;
34169 + if (end == start)
34170 + return 0;
34171 ++
34172 ++#ifdef CONFIG_PAX_SEGMEXEC
34173 ++ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
34174 ++ if (end > SEGMEXEC_TASK_SIZE)
34175 ++ return -EINVAL;
34176 ++ } else
34177 ++#endif
34178 ++
34179 ++ if (end > TASK_SIZE)
34180 ++ return -EINVAL;
34181 ++
34182 + vma = find_vma_prev(current->mm, start, &prev);
34183 + if (!vma || vma->vm_start > start)
34184 + return -ENOMEM;
34185 +@@ -150,6 +162,7 @@ asmlinkage long sys_mlock(unsigned long
34186 + lock_limit >>= PAGE_SHIFT;
34187 +
34188 + /* check against resource limits */
34189 ++ gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
34190 + if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
34191 + error = do_mlock(start, len, 1);
34192 + up_write(&current->mm->mmap_sem);
34193 +@@ -171,10 +184,10 @@ asmlinkage long sys_munlock(unsigned lon
34194 + static int do_mlockall(int flags)
34195 + {
34196 + struct vm_area_struct * vma, * prev = NULL;
34197 +- unsigned int def_flags = 0;
34198 ++ unsigned int def_flags = current->mm->def_flags & ~VM_LOCKED;
34199 +
34200 + if (flags & MCL_FUTURE)
34201 +- def_flags = VM_LOCKED;
34202 ++ def_flags |= VM_LOCKED;
34203 + current->mm->def_flags = def_flags;
34204 + if (flags == MCL_FUTURE)
34205 + goto out;
34206 +@@ -182,6 +195,12 @@ static int do_mlockall(int flags)
34207 + for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
34208 + unsigned int newflags;
34209 +
34210 ++#ifdef CONFIG_PAX_SEGMEXEC
34211 ++ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
34212 ++ break;
34213 ++#endif
34214 ++
34215 ++ BUG_ON(vma->vm_end > TASK_SIZE);
34216 + newflags = vma->vm_flags | VM_LOCKED;
34217 + if (!(flags & MCL_CURRENT))
34218 + newflags &= ~VM_LOCKED;
34219 +@@ -211,6 +230,7 @@ asmlinkage long sys_mlockall(int flags)
34220 + lock_limit >>= PAGE_SHIFT;
34221 +
34222 + ret = -ENOMEM;
34223 ++ gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm, 1);
34224 + if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
34225 + capable(CAP_IPC_LOCK))
34226 + ret = do_mlockall(flags);
34227 +diff -urNp linux-2.6.27.10/mm/mmap.c linux-2.6.27.10/mm/mmap.c
34228 +--- linux-2.6.27.10/mm/mmap.c 2008-11-07 12:55:34.000000000 -0500
34229 ++++ linux-2.6.27.10/mm/mmap.c 2008-12-21 00:44:29.000000000 -0500
34230 +@@ -27,6 +27,7 @@
34231 + #include <linux/mempolicy.h>
34232 + #include <linux/rmap.h>
34233 + #include <linux/mmu_notifier.h>
34234 ++#include <linux/grsecurity.h>
34235 +
34236 + #include <asm/uaccess.h>
34237 + #include <asm/cacheflush.h>
34238 +@@ -43,6 +44,16 @@
34239 + #define arch_rebalance_pgtables(addr, len) (addr)
34240 + #endif
34241 +
34242 ++static inline void verify_mm_writelocked(struct mm_struct *mm)
34243 ++{
34244 ++#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
34245 ++ if (unlikely(down_read_trylock(&mm->mmap_sem))) {
34246 ++ up_read(&mm->mmap_sem);
34247 ++ BUG();
34248 ++ }
34249 ++#endif
34250 ++}
34251 ++
34252 + static void unmap_region(struct mm_struct *mm,
34253 + struct vm_area_struct *vma, struct vm_area_struct *prev,
34254 + unsigned long start, unsigned long end);
34255 +@@ -68,16 +79,25 @@ static void unmap_region(struct mm_struc
34256 + * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
34257 + *
34258 + */
34259 +-pgprot_t protection_map[16] = {
34260 ++pgprot_t protection_map[16] __read_only = {
34261 + __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
34262 + __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
34263 + };
34264 +
34265 + pgprot_t vm_get_page_prot(unsigned long vm_flags)
34266 + {
34267 +- return __pgprot(pgprot_val(protection_map[vm_flags &
34268 ++ pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
34269 + (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
34270 + pgprot_val(arch_vm_get_page_prot(vm_flags)));
34271 ++
34272 ++#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
34273 ++ if (!nx_enabled &&
34274 ++ (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
34275 ++ (vm_flags & (VM_READ | VM_WRITE)))
34276 ++ prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
34277 ++#endif
34278 ++
34279 ++ return prot;
34280 + }
34281 + EXPORT_SYMBOL(vm_get_page_prot);
34282 +
34283 +@@ -232,6 +252,7 @@ static struct vm_area_struct *remove_vma
34284 + struct vm_area_struct *next = vma->vm_next;
34285 +
34286 + might_sleep();
34287 ++ BUG_ON(vma->vm_mirror);
34288 + if (vma->vm_ops && vma->vm_ops->close)
34289 + vma->vm_ops->close(vma);
34290 + if (vma->vm_file) {
34291 +@@ -268,6 +289,7 @@ asmlinkage unsigned long sys_brk(unsigne
34292 + * not page aligned -Ram Gupta
34293 + */
34294 + rlim = current->signal->rlim[RLIMIT_DATA].rlim_cur;
34295 ++ gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
34296 + if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
34297 + (mm->end_data - mm->start_data) > rlim)
34298 + goto out;
34299 +@@ -697,6 +719,12 @@ static int
34300 + can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
34301 + struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
34302 + {
34303 ++
34304 ++#ifdef CONFIG_PAX_SEGMEXEC
34305 ++ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
34306 ++ return 0;
34307 ++#endif
34308 ++
34309 + if (is_mergeable_vma(vma, file, vm_flags) &&
34310 + is_mergeable_anon_vma(anon_vma, vma->anon_vma)) {
34311 + if (vma->vm_pgoff == vm_pgoff)
34312 +@@ -716,6 +744,12 @@ static int
34313 + can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
34314 + struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
34315 + {
34316 ++
34317 ++#ifdef CONFIG_PAX_SEGMEXEC
34318 ++ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
34319 ++ return 0;
34320 ++#endif
34321 ++
34322 + if (is_mergeable_vma(vma, file, vm_flags) &&
34323 + is_mergeable_anon_vma(anon_vma, vma->anon_vma)) {
34324 + pgoff_t vm_pglen;
34325 +@@ -758,12 +792,19 @@ can_vma_merge_after(struct vm_area_struc
34326 + struct vm_area_struct *vma_merge(struct mm_struct *mm,
34327 + struct vm_area_struct *prev, unsigned long addr,
34328 + unsigned long end, unsigned long vm_flags,
34329 +- struct anon_vma *anon_vma, struct file *file,
34330 ++ struct anon_vma *anon_vma, struct file *file,
34331 + pgoff_t pgoff, struct mempolicy *policy)
34332 + {
34333 + pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
34334 + struct vm_area_struct *area, *next;
34335 +
34336 ++#ifdef CONFIG_PAX_SEGMEXEC
34337 ++ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
34338 ++ struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
34339 ++
34340 ++ BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
34341 ++#endif
34342 ++
34343 + /*
34344 + * We later require that vma->vm_flags == vm_flags,
34345 + * so this tests vma->vm_flags & VM_SPECIAL, too.
34346 +@@ -779,6 +820,15 @@ struct vm_area_struct *vma_merge(struct
34347 + if (next && next->vm_end == end) /* cases 6, 7, 8 */
34348 + next = next->vm_next;
34349 +
34350 ++#ifdef CONFIG_PAX_SEGMEXEC
34351 ++ if (prev)
34352 ++ prev_m = pax_find_mirror_vma(prev);
34353 ++ if (area)
34354 ++ area_m = pax_find_mirror_vma(area);
34355 ++ if (next)
34356 ++ next_m = pax_find_mirror_vma(next);
34357 ++#endif
34358 ++
34359 + /*
34360 + * Can it merge with the predecessor?
34361 + */
34362 +@@ -798,9 +848,24 @@ struct vm_area_struct *vma_merge(struct
34363 + /* cases 1, 6 */
34364 + vma_adjust(prev, prev->vm_start,
34365 + next->vm_end, prev->vm_pgoff, NULL);
34366 +- } else /* cases 2, 5, 7 */
34367 ++
34368 ++#ifdef CONFIG_PAX_SEGMEXEC
34369 ++ if (prev_m)
34370 ++ vma_adjust(prev_m, prev_m->vm_start,
34371 ++ next_m->vm_end, prev_m->vm_pgoff, NULL);
34372 ++#endif
34373 ++
34374 ++ } else { /* cases 2, 5, 7 */
34375 + vma_adjust(prev, prev->vm_start,
34376 + end, prev->vm_pgoff, NULL);
34377 ++
34378 ++#ifdef CONFIG_PAX_SEGMEXEC
34379 ++ if (prev_m)
34380 ++ vma_adjust(prev_m, prev_m->vm_start,
34381 ++ end_m, prev_m->vm_pgoff, NULL);
34382 ++#endif
34383 ++
34384 ++ }
34385 + return prev;
34386 + }
34387 +
34388 +@@ -811,12 +876,27 @@ struct vm_area_struct *vma_merge(struct
34389 + mpol_equal(policy, vma_policy(next)) &&
34390 + can_vma_merge_before(next, vm_flags,
34391 + anon_vma, file, pgoff+pglen)) {
34392 +- if (prev && addr < prev->vm_end) /* case 4 */
34393 ++ if (prev && addr < prev->vm_end) { /* case 4 */
34394 + vma_adjust(prev, prev->vm_start,
34395 + addr, prev->vm_pgoff, NULL);
34396 +- else /* cases 3, 8 */
34397 ++
34398 ++#ifdef CONFIG_PAX_SEGMEXEC
34399 ++ if (prev_m)
34400 ++ vma_adjust(prev_m, prev_m->vm_start,
34401 ++ addr_m, prev_m->vm_pgoff, NULL);
34402 ++#endif
34403 ++
34404 ++ } else { /* cases 3, 8 */
34405 + vma_adjust(area, addr, next->vm_end,
34406 + next->vm_pgoff - pglen, NULL);
34407 ++
34408 ++#ifdef CONFIG_PAX_SEGMEXEC
34409 ++ if (area_m)
34410 ++ vma_adjust(area_m, addr_m, next_m->vm_end,
34411 ++ next_m->vm_pgoff - pglen, NULL);
34412 ++#endif
34413 ++
34414 ++ }
34415 + return area;
34416 + }
34417 +
34418 +@@ -891,14 +971,11 @@ none:
34419 + void vm_stat_account(struct mm_struct *mm, unsigned long flags,
34420 + struct file *file, long pages)
34421 + {
34422 +- const unsigned long stack_flags
34423 +- = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
34424 +-
34425 + if (file) {
34426 + mm->shared_vm += pages;
34427 + if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
34428 + mm->exec_vm += pages;
34429 +- } else if (flags & stack_flags)
34430 ++ } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
34431 + mm->stack_vm += pages;
34432 + if (flags & (VM_RESERVED|VM_IO))
34433 + mm->reserved_vm += pages;
34434 +@@ -926,7 +1003,7 @@ unsigned long do_mmap_pgoff(struct file
34435 + * (the exception is when the underlying filesystem is noexec
34436 + * mounted, in which case we dont add PROT_EXEC.)
34437 + */
34438 +- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
34439 ++ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
34440 + if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
34441 + prot |= PROT_EXEC;
34442 +
34443 +@@ -936,15 +1013,15 @@ unsigned long do_mmap_pgoff(struct file
34444 + if (!(flags & MAP_FIXED))
34445 + addr = round_hint_to_min(addr);
34446 +
34447 +- error = arch_mmap_check(addr, len, flags);
34448 +- if (error)
34449 +- return error;
34450 +-
34451 + /* Careful about overflows.. */
34452 + len = PAGE_ALIGN(len);
34453 + if (!len || len > TASK_SIZE)
34454 + return -ENOMEM;
34455 +
34456 ++ error = arch_mmap_check(addr, len, flags);
34457 ++ if (error)
34458 ++ return error;
34459 ++
34460 + /* offset overflow? */
34461 + if ((pgoff + (len >> PAGE_SHIFT)) < pgoff)
34462 + return -EOVERFLOW;
34463 +@@ -956,7 +1033,7 @@ unsigned long do_mmap_pgoff(struct file
34464 + /* Obtain the address to map to. we verify (or select) it and ensure
34465 + * that it represents a valid section of the address space.
34466 + */
34467 +- addr = get_unmapped_area(file, addr, len, pgoff, flags);
34468 ++ addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
34469 + if (addr & ~PAGE_MASK)
34470 + return addr;
34471 +
34472 +@@ -967,6 +1044,26 @@ unsigned long do_mmap_pgoff(struct file
34473 + vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
34474 + mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
34475 +
34476 ++#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
34477 ++ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
34478 ++
34479 ++#ifdef CONFIG_PAX_MPROTECT
34480 ++ if (mm->pax_flags & MF_PAX_MPROTECT) {
34481 ++ if ((prot & (PROT_WRITE | PROT_EXEC)) != PROT_EXEC)
34482 ++ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
34483 ++ else
34484 ++ vm_flags &= ~(VM_WRITE | VM_MAYWRITE);
34485 ++ }
34486 ++#endif
34487 ++
34488 ++ }
34489 ++#endif
34490 ++
34491 ++#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
34492 ++ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
34493 ++ vm_flags &= ~VM_PAGEEXEC;
34494 ++#endif
34495 ++
34496 + if (flags & MAP_LOCKED) {
34497 + if (!can_do_mlock())
34498 + return -EPERM;
34499 +@@ -979,6 +1076,7 @@ unsigned long do_mmap_pgoff(struct file
34500 + locked += mm->locked_vm;
34501 + lock_limit = current->signal->rlim[RLIMIT_MEMLOCK].rlim_cur;
34502 + lock_limit >>= PAGE_SHIFT;
34503 ++ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
34504 + if (locked > lock_limit && !capable(CAP_IPC_LOCK))
34505 + return -EAGAIN;
34506 + }
34507 +@@ -1051,6 +1149,9 @@ unsigned long do_mmap_pgoff(struct file
34508 + if (error)
34509 + return error;
34510 +
34511 ++ if (!gr_acl_handle_mmap(file, prot))
34512 ++ return -EACCES;
34513 ++
34514 + return mmap_region(file, addr, len, flags, vm_flags, pgoff,
34515 + accountable);
34516 + }
34517 +@@ -1064,10 +1165,10 @@ EXPORT_SYMBOL(do_mmap_pgoff);
34518 + */
34519 + int vma_wants_writenotify(struct vm_area_struct *vma)
34520 + {
34521 +- unsigned int vm_flags = vma->vm_flags;
34522 ++ unsigned long vm_flags = vma->vm_flags;
34523 +
34524 + /* If it was private or non-writable, the write bit is already clear */
34525 +- if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
34526 ++ if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
34527 + return 0;
34528 +
34529 + /* The backer wishes to know when pages are first written to? */
34530 +@@ -1101,14 +1202,24 @@ unsigned long mmap_region(struct file *f
34531 + unsigned long charged = 0;
34532 + struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
34533 +
34534 ++#ifdef CONFIG_PAX_SEGMEXEC
34535 ++ struct vm_area_struct *vma_m = NULL;
34536 ++#endif
34537 ++
34538 ++ /*
34539 ++ * mm->mmap_sem is required to protect against another thread
34540 ++ * changing the mappings in case we sleep.
34541 ++ */
34542 ++ verify_mm_writelocked(mm);
34543 ++
34544 + /* Clear old maps */
34545 + error = -ENOMEM;
34546 +-munmap_back:
34547 + vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
34548 + if (vma && vma->vm_start < addr + len) {
34549 + if (do_munmap(mm, addr, len))
34550 + return -ENOMEM;
34551 +- goto munmap_back;
34552 ++ vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
34553 ++ BUG_ON(vma && vma->vm_start < addr + len);
34554 + }
34555 +
34556 + /* Check against address space limit. */
34557 +@@ -1155,6 +1266,16 @@ munmap_back:
34558 + goto unacct_error;
34559 + }
34560 +
34561 ++#ifdef CONFIG_PAX_SEGMEXEC
34562 ++ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
34563 ++ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
34564 ++ if (!vma_m) {
34565 ++ error = -ENOMEM;
34566 ++ goto free_vma;
34567 ++ }
34568 ++ }
34569 ++#endif
34570 ++
34571 + vma->vm_mm = mm;
34572 + vma->vm_start = addr;
34573 + vma->vm_end = addr + len;
34574 +@@ -1177,6 +1298,19 @@ munmap_back:
34575 + error = file->f_op->mmap(file, vma);
34576 + if (error)
34577 + goto unmap_and_free_vma;
34578 ++
34579 ++#ifdef CONFIG_PAX_SEGMEXEC
34580 ++ if (vma_m && (vm_flags & VM_EXECUTABLE))
34581 ++ added_exe_file_vma(mm);
34582 ++#endif
34583 ++
34584 ++#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
34585 ++ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
34586 ++ vma->vm_flags |= VM_PAGEEXEC;
34587 ++ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
34588 ++ }
34589 ++#endif
34590 ++
34591 + if (vm_flags & VM_EXECUTABLE)
34592 + added_exe_file_vma(mm);
34593 + } else if (vm_flags & VM_SHARED) {
34594 +@@ -1209,12 +1343,29 @@ munmap_back:
34595 + vma->vm_flags, NULL, file, pgoff, vma_policy(vma))) {
34596 + mpol_put(vma_policy(vma));
34597 + kmem_cache_free(vm_area_cachep, vma);
34598 ++ vma = NULL;
34599 + fput(file);
34600 ++
34601 ++#ifdef CONFIG_PAX_SEGMEXEC
34602 ++ if (vma_m) {
34603 ++ kmem_cache_free(vm_area_cachep, vma_m);
34604 ++
34605 ++ if (vm_flags & VM_EXECUTABLE)
34606 ++ removed_exe_file_vma(mm);
34607 ++ }
34608 ++#endif
34609 ++
34610 + if (vm_flags & VM_EXECUTABLE)
34611 + removed_exe_file_vma(mm);
34612 + } else {
34613 + vma_link(mm, vma, prev, rb_link, rb_parent);
34614 + file = vma->vm_file;
34615 ++
34616 ++#ifdef CONFIG_PAX_SEGMEXEC
34617 ++ if (vma_m)
34618 ++ pax_mirror_vma(vma_m, vma);
34619 ++#endif
34620 ++
34621 + }
34622 +
34623 + /* Once vma denies write, undo our temporary denial count */
34624 +@@ -1223,6 +1374,7 @@ munmap_back:
34625 + out:
34626 + mm->total_vm += len >> PAGE_SHIFT;
34627 + vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
34628 ++ track_exec_limit(mm, addr, addr + len, vm_flags);
34629 + if (vm_flags & VM_LOCKED) {
34630 + mm->locked_vm += len >> PAGE_SHIFT;
34631 + make_pages_present(addr, addr + len);
34632 +@@ -1241,6 +1393,12 @@ unmap_and_free_vma:
34633 + unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
34634 + charged = 0;
34635 + free_vma:
34636 ++
34637 ++#ifdef CONFIG_PAX_SEGMEXEC
34638 ++ if (vma_m)
34639 ++ kmem_cache_free(vm_area_cachep, vma_m);
34640 ++#endif
34641 ++
34642 + kmem_cache_free(vm_area_cachep, vma);
34643 + unacct_error:
34644 + if (charged)
34645 +@@ -1274,6 +1432,10 @@ arch_get_unmapped_area(struct file *filp
34646 + if (flags & MAP_FIXED)
34647 + return addr;
34648 +
34649 ++#ifdef CONFIG_PAX_RANDMMAP
34650 ++ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
34651 ++#endif
34652 ++
34653 + if (addr) {
34654 + addr = PAGE_ALIGN(addr);
34655 + vma = find_vma(mm, addr);
34656 +@@ -1282,10 +1444,10 @@ arch_get_unmapped_area(struct file *filp
34657 + return addr;
34658 + }
34659 + if (len > mm->cached_hole_size) {
34660 +- start_addr = addr = mm->free_area_cache;
34661 ++ start_addr = addr = mm->free_area_cache;
34662 + } else {
34663 +- start_addr = addr = TASK_UNMAPPED_BASE;
34664 +- mm->cached_hole_size = 0;
34665 ++ start_addr = addr = mm->mmap_base;
34666 ++ mm->cached_hole_size = 0;
34667 + }
34668 +
34669 + full_search:
34670 +@@ -1296,9 +1458,8 @@ full_search:
34671 + * Start a new search - just in case we missed
34672 + * some holes.
34673 + */
34674 +- if (start_addr != TASK_UNMAPPED_BASE) {
34675 +- addr = TASK_UNMAPPED_BASE;
34676 +- start_addr = addr;
34677 ++ if (start_addr != mm->mmap_base) {
34678 ++ start_addr = addr = mm->mmap_base;
34679 + mm->cached_hole_size = 0;
34680 + goto full_search;
34681 + }
34682 +@@ -1320,10 +1481,16 @@ full_search:
34683 +
34684 + void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
34685 + {
34686 ++
34687 ++#ifdef CONFIG_PAX_SEGMEXEC
34688 ++ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
34689 ++ return;
34690 ++#endif
34691 ++
34692 + /*
34693 + * Is this a new hole at the lowest possible address?
34694 + */
34695 +- if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache) {
34696 ++ if (addr >= mm->mmap_base && addr < mm->free_area_cache) {
34697 + mm->free_area_cache = addr;
34698 + mm->cached_hole_size = ~0UL;
34699 + }
34700 +@@ -1341,7 +1508,7 @@ arch_get_unmapped_area_topdown(struct fi
34701 + {
34702 + struct vm_area_struct *vma;
34703 + struct mm_struct *mm = current->mm;
34704 +- unsigned long addr = addr0;
34705 ++ unsigned long base = mm->mmap_base, addr = addr0;
34706 +
34707 + /* requested length too big for entire address space */
34708 + if (len > TASK_SIZE)
34709 +@@ -1350,6 +1517,10 @@ arch_get_unmapped_area_topdown(struct fi
34710 + if (flags & MAP_FIXED)
34711 + return addr;
34712 +
34713 ++#ifdef CONFIG_PAX_RANDMMAP
34714 ++ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
34715 ++#endif
34716 ++
34717 + /* requesting a specific address */
34718 + if (addr) {
34719 + addr = PAGE_ALIGN(addr);
34720 +@@ -1407,13 +1578,21 @@ bottomup:
34721 + * can happen with large stack limits and large mmap()
34722 + * allocations.
34723 + */
34724 ++ mm->mmap_base = TASK_UNMAPPED_BASE;
34725 ++
34726 ++#ifdef CONFIG_PAX_RANDMMAP
34727 ++ if (mm->pax_flags & MF_PAX_RANDMMAP)
34728 ++ mm->mmap_base += mm->delta_mmap;
34729 ++#endif
34730 ++
34731 ++ mm->free_area_cache = mm->mmap_base;
34732 + mm->cached_hole_size = ~0UL;
34733 +- mm->free_area_cache = TASK_UNMAPPED_BASE;
34734 + addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
34735 + /*
34736 + * Restore the topdown base:
34737 + */
34738 +- mm->free_area_cache = mm->mmap_base;
34739 ++ mm->mmap_base = base;
34740 ++ mm->free_area_cache = base;
34741 + mm->cached_hole_size = ~0UL;
34742 +
34743 + return addr;
34744 +@@ -1422,6 +1601,12 @@ bottomup:
34745 +
34746 + void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
34747 + {
34748 ++
34749 ++#ifdef CONFIG_PAX_SEGMEXEC
34750 ++ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
34751 ++ return;
34752 ++#endif
34753 ++
34754 + /*
34755 + * Is this a new hole at the highest possible address?
34756 + */
34757 +@@ -1429,8 +1614,10 @@ void arch_unmap_area_topdown(struct mm_s
34758 + mm->free_area_cache = addr;
34759 +
34760 + /* dont allow allocations above current base */
34761 +- if (mm->free_area_cache > mm->mmap_base)
34762 ++ if (mm->free_area_cache > mm->mmap_base) {
34763 + mm->free_area_cache = mm->mmap_base;
34764 ++ mm->cached_hole_size = ~0UL;
34765 ++ }
34766 + }
34767 +
34768 + unsigned long
34769 +@@ -1530,6 +1717,27 @@ out:
34770 + return prev ? prev->vm_next : vma;
34771 + }
34772 +
34773 ++#ifdef CONFIG_PAX_SEGMEXEC
34774 ++struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
34775 ++{
34776 ++ struct vm_area_struct *vma_m;
34777 ++
34778 ++ BUG_ON(!vma || vma->vm_start >= vma->vm_end);
34779 ++ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
34780 ++ BUG_ON(vma->vm_mirror);
34781 ++ return NULL;
34782 ++ }
34783 ++ BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
34784 ++ vma_m = vma->vm_mirror;
34785 ++ BUG_ON(!vma_m || vma_m->vm_mirror != vma);
34786 ++ BUG_ON(vma->vm_file != vma_m->vm_file);
34787 ++ BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
34788 ++ BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff || vma->anon_vma != vma_m->anon_vma);
34789 ++ BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
34790 ++ return vma_m;
34791 ++}
34792 ++#endif
34793 ++
34794 + /*
34795 + * Verify that the stack growth is acceptable and
34796 + * update accounting. This is shared with both the
34797 +@@ -1546,6 +1754,7 @@ static int acct_stack_growth(struct vm_a
34798 + return -ENOMEM;
34799 +
34800 + /* Stack limit test */
34801 ++ gr_learn_resource(current, RLIMIT_STACK, size, 1);
34802 + if (size > rlim[RLIMIT_STACK].rlim_cur)
34803 + return -ENOMEM;
34804 +
34805 +@@ -1555,6 +1764,7 @@ static int acct_stack_growth(struct vm_a
34806 + unsigned long limit;
34807 + locked = mm->locked_vm + grow;
34808 + limit = rlim[RLIMIT_MEMLOCK].rlim_cur >> PAGE_SHIFT;
34809 ++ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
34810 + if (locked > limit && !capable(CAP_IPC_LOCK))
34811 + return -ENOMEM;
34812 + }
34813 +@@ -1569,7 +1779,7 @@ static int acct_stack_growth(struct vm_a
34814 + * Overcommit.. This must be the final test, as it will
34815 + * update security statistics.
34816 + */
34817 +- if (security_vm_enough_memory(grow))
34818 ++ if (security_vm_enough_memory_mm(mm, grow))
34819 + return -ENOMEM;
34820 +
34821 + /* Ok, everything looks good - let it rip */
34822 +@@ -1590,35 +1800,40 @@ static inline
34823 + #endif
34824 + int expand_upwards(struct vm_area_struct *vma, unsigned long address)
34825 + {
34826 +- int error;
34827 ++ int error, locknext;
34828 +
34829 + if (!(vma->vm_flags & VM_GROWSUP))
34830 + return -EFAULT;
34831 +
34832 ++ /* Also guard against wrapping around to address 0. */
34833 ++ if (address < PAGE_ALIGN(address+1))
34834 ++ address = PAGE_ALIGN(address+1);
34835 ++ else
34836 ++ return -ENOMEM;
34837 ++
34838 + /*
34839 + * We must make sure the anon_vma is allocated
34840 + * so that the anon_vma locking is not a noop.
34841 + */
34842 + if (unlikely(anon_vma_prepare(vma)))
34843 + return -ENOMEM;
34844 ++ locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
34845 ++ if (locknext && unlikely(anon_vma_prepare(vma->vm_next)))
34846 ++ return -ENOMEM;
34847 + anon_vma_lock(vma);
34848 ++ if (locknext)
34849 ++ anon_vma_lock(vma->vm_next);
34850 +
34851 + /*
34852 + * vma->vm_start/vm_end cannot change under us because the caller
34853 + * is required to hold the mmap_sem in read mode. We need the
34854 +- * anon_vma lock to serialize against concurrent expand_stacks.
34855 +- * Also guard against wrapping around to address 0.
34856 ++ * anon_vma locks to serialize against concurrent expand_stacks
34857 ++ * and expand_upwards.
34858 + */
34859 +- if (address < PAGE_ALIGN(address+4))
34860 +- address = PAGE_ALIGN(address+4);
34861 +- else {
34862 +- anon_vma_unlock(vma);
34863 +- return -ENOMEM;
34864 +- }
34865 + error = 0;
34866 +
34867 + /* Somebody else might have raced and expanded it already */
34868 +- if (address > vma->vm_end) {
34869 ++ if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
34870 + unsigned long size, grow;
34871 +
34872 + size = address - vma->vm_start;
34873 +@@ -1628,6 +1843,8 @@ int expand_upwards(struct vm_area_struct
34874 + if (!error)
34875 + vma->vm_end = address;
34876 + }
34877 ++ if (locknext)
34878 ++ anon_vma_unlock(vma->vm_next);
34879 + anon_vma_unlock(vma);
34880 + return error;
34881 + }
34882 +@@ -1639,7 +1856,8 @@ int expand_upwards(struct vm_area_struct
34883 + static inline int expand_downwards(struct vm_area_struct *vma,
34884 + unsigned long address)
34885 + {
34886 +- int error;
34887 ++ int error, lockprev = 0;
34888 ++ struct vm_area_struct *prev = NULL;
34889 +
34890 + /*
34891 + * We must make sure the anon_vma is allocated
34892 +@@ -1653,6 +1871,15 @@ static inline int expand_downwards(struc
34893 + if (error)
34894 + return error;
34895 +
34896 ++#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
34897 ++ find_vma_prev(vma->vm_mm, address, &prev);
34898 ++ lockprev = prev && (prev->vm_flags & VM_GROWSUP);
34899 ++#endif
34900 ++ if (lockprev && unlikely(anon_vma_prepare(prev)))
34901 ++ return -ENOMEM;
34902 ++ if (lockprev)
34903 ++ anon_vma_lock(prev);
34904 ++
34905 + anon_vma_lock(vma);
34906 +
34907 + /*
34908 +@@ -1662,9 +1889,15 @@ static inline int expand_downwards(struc
34909 + */
34910 +
34911 + /* Somebody else might have raced and expanded it already */
34912 +- if (address < vma->vm_start) {
34913 ++ if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
34914 + unsigned long size, grow;
34915 +
34916 ++#ifdef CONFIG_PAX_SEGMEXEC
34917 ++ struct vm_area_struct *vma_m;
34918 ++
34919 ++ vma_m = pax_find_mirror_vma(vma);
34920 ++#endif
34921 ++
34922 + size = vma->vm_end - address;
34923 + grow = (vma->vm_start - address) >> PAGE_SHIFT;
34924 +
34925 +@@ -1672,9 +1905,20 @@ static inline int expand_downwards(struc
34926 + if (!error) {
34927 + vma->vm_start = address;
34928 + vma->vm_pgoff -= grow;
34929 ++ track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
34930 ++
34931 ++#ifdef CONFIG_PAX_SEGMEXEC
34932 ++ if (vma_m) {
34933 ++ vma_m->vm_start -= grow << PAGE_SHIFT;
34934 ++ vma_m->vm_pgoff -= grow;
34935 ++ }
34936 ++#endif
34937 ++
34938 + }
34939 + }
34940 + anon_vma_unlock(vma);
34941 ++ if (lockprev)
34942 ++ anon_vma_unlock(prev);
34943 + return error;
34944 + }
34945 +
34946 +@@ -1746,6 +1990,13 @@ static void remove_vma_list(struct mm_st
34947 + do {
34948 + long nrpages = vma_pages(vma);
34949 +
34950 ++#ifdef CONFIG_PAX_SEGMEXEC
34951 ++ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
34952 ++ vma = remove_vma(vma);
34953 ++ continue;
34954 ++ }
34955 ++#endif
34956 ++
34957 + mm->total_vm -= nrpages;
34958 + if (vma->vm_flags & VM_LOCKED)
34959 + mm->locked_vm -= nrpages;
34960 +@@ -1792,6 +2043,16 @@ detach_vmas_to_be_unmapped(struct mm_str
34961 +
34962 + insertion_point = (prev ? &prev->vm_next : &mm->mmap);
34963 + do {
34964 ++
34965 ++#ifdef CONFIG_PAX_SEGMEXEC
34966 ++ if (vma->vm_mirror) {
34967 ++ BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
34968 ++ vma->vm_mirror->vm_mirror = NULL;
34969 ++ vma->vm_mirror->vm_flags &= ~VM_EXEC;
34970 ++ vma->vm_mirror = NULL;
34971 ++ }
34972 ++#endif
34973 ++
34974 + rb_erase(&vma->vm_rb, &mm->mm_rb);
34975 + mm->map_count--;
34976 + tail_vma = vma;
34977 +@@ -1811,6 +2072,108 @@ detach_vmas_to_be_unmapped(struct mm_str
34978 + * Split a vma into two pieces at address 'addr', a new vma is allocated
34979 + * either for the first part or the tail.
34980 + */
34981 ++
34982 ++#ifdef CONFIG_PAX_SEGMEXEC
34983 ++int split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
34984 ++ unsigned long addr, int new_below)
34985 ++{
34986 ++ struct mempolicy *pol;
34987 ++ struct vm_area_struct *new, *vma_m, *new_m = NULL;
34988 ++ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
34989 ++
34990 ++ if (is_vm_hugetlb_page(vma) && (addr & ~HPAGE_MASK))
34991 ++ return -EINVAL;
34992 ++
34993 ++ vma_m = pax_find_mirror_vma(vma);
34994 ++ if (vma_m) {
34995 ++ BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
34996 ++ if (mm->map_count >= sysctl_max_map_count-1)
34997 ++ return -ENOMEM;
34998 ++ } else if (mm->map_count >= sysctl_max_map_count)
34999 ++ return -ENOMEM;
35000 ++
35001 ++ new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
35002 ++ if (!new)
35003 ++ return -ENOMEM;
35004 ++
35005 ++ if (vma_m) {
35006 ++ new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
35007 ++ if (!new_m) {
35008 ++ kmem_cache_free(vm_area_cachep, new);
35009 ++ return -ENOMEM;
35010 ++ }
35011 ++ }
35012 ++
35013 ++ /* most fields are the same, copy all, and then fixup */
35014 ++ *new = *vma;
35015 ++
35016 ++ if (new_below)
35017 ++ new->vm_end = addr;
35018 ++ else {
35019 ++ new->vm_start = addr;
35020 ++ new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
35021 ++ }
35022 ++
35023 ++ if (vma_m) {
35024 ++ *new_m = *vma_m;
35025 ++ new_m->vm_mirror = new;
35026 ++ new->vm_mirror = new_m;
35027 ++
35028 ++ if (new_below)
35029 ++ new_m->vm_end = addr_m;
35030 ++ else {
35031 ++ new_m->vm_start = addr_m;
35032 ++ new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
35033 ++ }
35034 ++ }
35035 ++
35036 ++ pol = mpol_dup(vma_policy(vma));
35037 ++ if (IS_ERR(pol)) {
35038 ++ if (new_m)
35039 ++ kmem_cache_free(vm_area_cachep, new_m);
35040 ++ kmem_cache_free(vm_area_cachep, new);
35041 ++ return PTR_ERR(pol);
35042 ++ }
35043 ++ vma_set_policy(new, pol);
35044 ++
35045 ++ if (new->vm_file) {
35046 ++ get_file(new->vm_file);
35047 ++ if (vma->vm_flags & VM_EXECUTABLE)
35048 ++ added_exe_file_vma(mm);
35049 ++ }
35050 ++
35051 ++ if (new->vm_ops && new->vm_ops->open)
35052 ++ new->vm_ops->open(new);
35053 ++
35054 ++ if (new_below)
35055 ++ vma_adjust(vma, addr, vma->vm_end, vma->vm_pgoff +
35056 ++ ((addr - new->vm_start) >> PAGE_SHIFT), new);
35057 ++ else
35058 ++ vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
35059 ++
35060 ++ if (vma_m) {
35061 ++ mpol_get(pol);
35062 ++ vma_set_policy(new_m, pol);
35063 ++
35064 ++ if (new_m->vm_file) {
35065 ++ get_file(new_m->vm_file);
35066 ++ if (vma_m->vm_flags & VM_EXECUTABLE)
35067 ++ added_exe_file_vma(mm);
35068 ++ }
35069 ++
35070 ++ if (new_m->vm_ops && new_m->vm_ops->open)
35071 ++ new_m->vm_ops->open(new_m);
35072 ++
35073 ++ if (new_below)
35074 ++ vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
35075 ++ ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
35076 ++ else
35077 ++ vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
35078 ++ }
35079 ++
35080 ++ return 0;
35081 ++}
35082 ++#else
35083 + int split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
35084 + unsigned long addr, int new_below)
35085 + {
35086 +@@ -1862,17 +2225,37 @@ int split_vma(struct mm_struct * mm, str
35087 +
35088 + return 0;
35089 + }
35090 ++#endif
35091 +
35092 + /* Munmap is split into 2 main parts -- this part which finds
35093 + * what needs doing, and the areas themselves, which do the
35094 + * work. This now handles partial unmappings.
35095 + * Jeremy Fitzhardinge <jeremy@××××.org>
35096 + */
35097 ++#ifdef CONFIG_PAX_SEGMEXEC
35098 + int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
35099 + {
35100 ++ int ret = __do_munmap(mm, start, len);
35101 ++ if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
35102 ++ return ret;
35103 ++
35104 ++ return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
35105 ++}
35106 ++
35107 ++int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
35108 ++#else
35109 ++int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
35110 ++#endif
35111 ++{
35112 + unsigned long end;
35113 + struct vm_area_struct *vma, *prev, *last;
35114 +
35115 ++ /*
35116 ++ * mm->mmap_sem is required to protect against another thread
35117 ++ * changing the mappings in case we sleep.
35118 ++ */
35119 ++ verify_mm_writelocked(mm);
35120 ++
35121 + if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
35122 + return -EINVAL;
35123 +
35124 +@@ -1922,6 +2305,8 @@ int do_munmap(struct mm_struct *mm, unsi
35125 + /* Fix up all other VM information */
35126 + remove_vma_list(mm, vma);
35127 +
35128 ++ track_exec_limit(mm, start, end, 0UL);
35129 ++
35130 + return 0;
35131 + }
35132 +
35133 +@@ -1934,22 +2319,18 @@ asmlinkage long sys_munmap(unsigned long
35134 +
35135 + profile_munmap(addr);
35136 +
35137 ++#ifdef CONFIG_PAX_SEGMEXEC
35138 ++ if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
35139 ++ (len > SEGMEXEC_TASK_SIZE || addr > SEGMEXEC_TASK_SIZE-len))
35140 ++ return -EINVAL;
35141 ++#endif
35142 ++
35143 + down_write(&mm->mmap_sem);
35144 + ret = do_munmap(mm, addr, len);
35145 + up_write(&mm->mmap_sem);
35146 + return ret;
35147 + }
35148 +
35149 +-static inline void verify_mm_writelocked(struct mm_struct *mm)
35150 +-{
35151 +-#ifdef CONFIG_DEBUG_VM
35152 +- if (unlikely(down_read_trylock(&mm->mmap_sem))) {
35153 +- WARN_ON(1);
35154 +- up_read(&mm->mmap_sem);
35155 +- }
35156 +-#endif
35157 +-}
35158 +-
35159 + /*
35160 + * this is really a simplified "do_mmap". it only handles
35161 + * anonymous maps. eventually we may be able to do some
35162 +@@ -1963,6 +2344,11 @@ unsigned long do_brk(unsigned long addr,
35163 + struct rb_node ** rb_link, * rb_parent;
35164 + pgoff_t pgoff = addr >> PAGE_SHIFT;
35165 + int error;
35166 ++ unsigned long charged;
35167 ++
35168 ++#ifdef CONFIG_PAX_SEGMEXEC
35169 ++ struct vm_area_struct *vma_m = NULL;
35170 ++#endif
35171 +
35172 + len = PAGE_ALIGN(len);
35173 + if (!len)
35174 +@@ -1980,19 +2366,34 @@ unsigned long do_brk(unsigned long addr,
35175 +
35176 + flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
35177 +
35178 ++#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
35179 ++ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
35180 ++ flags &= ~VM_EXEC;
35181 ++
35182 ++#ifdef CONFIG_PAX_MPROTECT
35183 ++ if (mm->pax_flags & MF_PAX_MPROTECT)
35184 ++ flags &= ~VM_MAYEXEC;
35185 ++#endif
35186 ++
35187 ++ }
35188 ++#endif
35189 ++
35190 + error = arch_mmap_check(addr, len, flags);
35191 + if (error)
35192 + return error;
35193 +
35194 ++ charged = len >> PAGE_SHIFT;
35195 ++
35196 + /*
35197 + * mlock MCL_FUTURE?
35198 + */
35199 + if (mm->def_flags & VM_LOCKED) {
35200 + unsigned long locked, lock_limit;
35201 +- locked = len >> PAGE_SHIFT;
35202 ++ locked = charged;
35203 + locked += mm->locked_vm;
35204 + lock_limit = current->signal->rlim[RLIMIT_MEMLOCK].rlim_cur;
35205 + lock_limit >>= PAGE_SHIFT;
35206 ++ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
35207 + if (locked > lock_limit && !capable(CAP_IPC_LOCK))
35208 + return -EAGAIN;
35209 + }
35210 +@@ -2006,22 +2407,22 @@ unsigned long do_brk(unsigned long addr,
35211 + /*
35212 + * Clear old maps. this also does some error checking for us
35213 + */
35214 +- munmap_back:
35215 + vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
35216 + if (vma && vma->vm_start < addr + len) {
35217 + if (do_munmap(mm, addr, len))
35218 + return -ENOMEM;
35219 +- goto munmap_back;
35220 ++ vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
35221 ++ BUG_ON(vma && vma->vm_start < addr + len);
35222 + }
35223 +
35224 + /* Check against address space limits *after* clearing old maps... */
35225 +- if (!may_expand_vm(mm, len >> PAGE_SHIFT))
35226 ++ if (!may_expand_vm(mm, charged))
35227 + return -ENOMEM;
35228 +
35229 + if (mm->map_count > sysctl_max_map_count)
35230 + return -ENOMEM;
35231 +
35232 +- if (security_vm_enough_memory(len >> PAGE_SHIFT))
35233 ++ if (security_vm_enough_memory(charged))
35234 + return -ENOMEM;
35235 +
35236 + /* Can we just expand an old private anonymous mapping? */
35237 +@@ -2034,10 +2435,21 @@ unsigned long do_brk(unsigned long addr,
35238 + */
35239 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
35240 + if (!vma) {
35241 +- vm_unacct_memory(len >> PAGE_SHIFT);
35242 ++ vm_unacct_memory(charged);
35243 + return -ENOMEM;
35244 + }
35245 +
35246 ++#ifdef CONFIG_PAX_SEGMEXEC
35247 ++ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (flags & VM_EXEC)) {
35248 ++ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
35249 ++ if (!vma_m) {
35250 ++ kmem_cache_free(vm_area_cachep, vma);
35251 ++ vm_unacct_memory(charged);
35252 ++ return -ENOMEM;
35253 ++ }
35254 ++ }
35255 ++#endif
35256 ++
35257 + vma->vm_mm = mm;
35258 + vma->vm_start = addr;
35259 + vma->vm_end = addr + len;
35260 +@@ -2045,12 +2457,19 @@ unsigned long do_brk(unsigned long addr,
35261 + vma->vm_flags = flags;
35262 + vma->vm_page_prot = vm_get_page_prot(flags);
35263 + vma_link(mm, vma, prev, rb_link, rb_parent);
35264 ++
35265 ++#ifdef CONFIG_PAX_SEGMEXEC
35266 ++ if (vma_m)
35267 ++ pax_mirror_vma(vma_m, vma);
35268 ++#endif
35269 ++
35270 + out:
35271 +- mm->total_vm += len >> PAGE_SHIFT;
35272 ++ mm->total_vm += charged;
35273 + if (flags & VM_LOCKED) {
35274 +- mm->locked_vm += len >> PAGE_SHIFT;
35275 ++ mm->locked_vm += charged;
35276 + make_pages_present(addr, addr + len);
35277 + }
35278 ++ track_exec_limit(mm, addr, addr + len, flags);
35279 + return addr;
35280 + }
35281 +
35282 +@@ -2082,8 +2501,10 @@ void exit_mmap(struct mm_struct *mm)
35283 + * Walk the list again, actually closing and freeing it,
35284 + * with preemption enabled, without holding any MM locks.
35285 + */
35286 +- while (vma)
35287 ++ while (vma) {
35288 ++ vma->vm_mirror = NULL;
35289 + vma = remove_vma(vma);
35290 ++ }
35291 +
35292 + BUG_ON(mm->nr_ptes > (FIRST_USER_ADDRESS+PMD_SIZE-1)>>PMD_SHIFT);
35293 + }
35294 +@@ -2097,6 +2518,10 @@ int insert_vm_struct(struct mm_struct *
35295 + struct vm_area_struct * __vma, * prev;
35296 + struct rb_node ** rb_link, * rb_parent;
35297 +
35298 ++#ifdef CONFIG_PAX_SEGMEXEC
35299 ++ struct vm_area_struct *vma_m = NULL;
35300 ++#endif
35301 ++
35302 + /*
35303 + * The vm_pgoff of a purely anonymous vma should be irrelevant
35304 + * until its first write fault, when page's anon_vma and index
35305 +@@ -2119,7 +2544,22 @@ int insert_vm_struct(struct mm_struct *
35306 + if ((vma->vm_flags & VM_ACCOUNT) &&
35307 + security_vm_enough_memory_mm(mm, vma_pages(vma)))
35308 + return -ENOMEM;
35309 ++
35310 ++#ifdef CONFIG_PAX_SEGMEXEC
35311 ++ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
35312 ++ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
35313 ++ if (!vma_m)
35314 ++ return -ENOMEM;
35315 ++ }
35316 ++#endif
35317 ++
35318 + vma_link(mm, vma, prev, rb_link, rb_parent);
35319 ++
35320 ++#ifdef CONFIG_PAX_SEGMEXEC
35321 ++ if (vma_m)
35322 ++ pax_mirror_vma(vma_m, vma);
35323 ++#endif
35324 ++
35325 + return 0;
35326 + }
35327 +
35328 +@@ -2137,6 +2577,8 @@ struct vm_area_struct *copy_vma(struct v
35329 + struct rb_node **rb_link, *rb_parent;
35330 + struct mempolicy *pol;
35331 +
35332 ++ BUG_ON(vma->vm_mirror);
35333 ++
35334 + /*
35335 + * If anonymous vma has not yet been faulted, update new pgoff
35336 + * to match new location, to increase its chance of merging.
35337 +@@ -2180,6 +2622,35 @@ struct vm_area_struct *copy_vma(struct v
35338 + return new_vma;
35339 + }
35340 +
35341 ++#ifdef CONFIG_PAX_SEGMEXEC
35342 ++void pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
35343 ++{
35344 ++ struct vm_area_struct *prev_m;
35345 ++ struct rb_node **rb_link_m, *rb_parent_m;
35346 ++ struct mempolicy *pol_m;
35347 ++
35348 ++ BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
35349 ++ BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
35350 ++ BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
35351 ++ *vma_m = *vma;
35352 ++ pol_m = vma_policy(vma_m);
35353 ++ mpol_get(pol_m);
35354 ++ vma_set_policy(vma_m, pol_m);
35355 ++ vma_m->vm_start += SEGMEXEC_TASK_SIZE;
35356 ++ vma_m->vm_end += SEGMEXEC_TASK_SIZE;
35357 ++ vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
35358 ++ vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
35359 ++ if (vma_m->vm_file)
35360 ++ get_file(vma_m->vm_file);
35361 ++ if (vma_m->vm_ops && vma_m->vm_ops->open)
35362 ++ vma_m->vm_ops->open(vma_m);
35363 ++ find_vma_prepare(vma->vm_mm, vma_m->vm_start, &prev_m, &rb_link_m, &rb_parent_m);
35364 ++ vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
35365 ++ vma_m->vm_mirror = vma;
35366 ++ vma->vm_mirror = vma_m;
35367 ++}
35368 ++#endif
35369 ++
35370 + /*
35371 + * Return true if the calling process may expand its vm space by the passed
35372 + * number of pages
35373 +@@ -2190,7 +2661,7 @@ int may_expand_vm(struct mm_struct *mm,
35374 + unsigned long lim;
35375 +
35376 + lim = current->signal->rlim[RLIMIT_AS].rlim_cur >> PAGE_SHIFT;
35377 +-
35378 ++ gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
35379 + if (cur + npages > lim)
35380 + return 0;
35381 + return 1;
35382 +@@ -2259,6 +2730,15 @@ int install_special_mapping(struct mm_st
35383 + vma->vm_start = addr;
35384 + vma->vm_end = addr + len;
35385 +
35386 ++#ifdef CONFIG_PAX_MPROTECT
35387 ++ if (mm->pax_flags & MF_PAX_MPROTECT) {
35388 ++ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
35389 ++ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
35390 ++ else
35391 ++ vm_flags &= ~(VM_WRITE | VM_MAYWRITE);
35392 ++ }
35393 ++#endif
35394 ++
35395 + vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
35396 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
35397 +
35398 +diff -urNp linux-2.6.27.10/mm/mprotect.c linux-2.6.27.10/mm/mprotect.c
35399 +--- linux-2.6.27.10/mm/mprotect.c 2008-11-07 12:55:34.000000000 -0500
35400 ++++ linux-2.6.27.10/mm/mprotect.c 2008-12-21 00:45:45.000000000 -0500
35401 +@@ -22,10 +22,17 @@
35402 + #include <linux/swap.h>
35403 + #include <linux/swapops.h>
35404 + #include <linux/mmu_notifier.h>
35405 ++#include <linux/grsecurity.h>
35406 ++
35407 ++#ifdef CONFIG_PAX_MPROTECT
35408 ++#include <linux/elf.h>
35409 ++#endif
35410 ++
35411 + #include <asm/uaccess.h>
35412 + #include <asm/pgtable.h>
35413 + #include <asm/cacheflush.h>
35414 + #include <asm/tlbflush.h>
35415 ++#include <asm/mmu_context.h>
35416 +
35417 + #ifndef pgprot_modify
35418 + static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
35419 +@@ -133,6 +140,48 @@ static void change_protection(struct vm_
35420 + flush_tlb_range(vma, start, end);
35421 + }
35422 +
35423 ++#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
35424 ++/* called while holding the mmap semaphor for writing except stack expansion */
35425 ++void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
35426 ++{
35427 ++ unsigned long oldlimit, newlimit = 0UL;
35428 ++
35429 ++ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || nx_enabled)
35430 ++ return;
35431 ++
35432 ++ spin_lock(&mm->page_table_lock);
35433 ++ oldlimit = mm->context.user_cs_limit;
35434 ++ if ((prot & VM_EXEC) && oldlimit < end)
35435 ++ /* USER_CS limit moved up */
35436 ++ newlimit = end;
35437 ++ else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
35438 ++ /* USER_CS limit moved down */
35439 ++ newlimit = start;
35440 ++
35441 ++ if (newlimit) {
35442 ++ mm->context.user_cs_limit = newlimit;
35443 ++
35444 ++#ifdef CONFIG_SMP
35445 ++ wmb();
35446 ++ cpus_clear(mm->context.cpu_user_cs_mask);
35447 ++ cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
35448 ++#endif
35449 ++
35450 ++ set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
35451 ++ }
35452 ++ spin_unlock(&mm->page_table_lock);
35453 ++ if (newlimit == end) {
35454 ++ struct vm_area_struct *vma = find_vma(mm, oldlimit);
35455 ++
35456 ++ for (; vma && vma->vm_start < end; vma = vma->vm_next)
35457 ++ if (is_vm_hugetlb_page(vma))
35458 ++ hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
35459 ++ else
35460 ++ change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma));
35461 ++ }
35462 ++}
35463 ++#endif
35464 ++
35465 + int
35466 + mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
35467 + unsigned long start, unsigned long end, unsigned long newflags)
35468 +@@ -145,6 +194,14 @@ mprotect_fixup(struct vm_area_struct *vm
35469 + int error;
35470 + int dirty_accountable = 0;
35471 +
35472 ++#ifdef CONFIG_PAX_SEGMEXEC
35473 ++ struct vm_area_struct *vma_m = NULL;
35474 ++ unsigned long start_m, end_m;
35475 ++
35476 ++ start_m = start + SEGMEXEC_TASK_SIZE;
35477 ++ end_m = end + SEGMEXEC_TASK_SIZE;
35478 ++#endif
35479 ++
35480 + if (newflags == oldflags) {
35481 + *pprev = vma;
35482 + return 0;
35483 +@@ -165,6 +222,38 @@ mprotect_fixup(struct vm_area_struct *vm
35484 + }
35485 + }
35486 +
35487 ++#ifdef CONFIG_PAX_SEGMEXEC
35488 ++ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
35489 ++ if (start != vma->vm_start) {
35490 ++ error = split_vma(mm, vma, start, 1);
35491 ++ if (error)
35492 ++ goto fail;
35493 ++ BUG_ON(!*pprev || (*pprev)->vm_next == vma);
35494 ++ *pprev = (*pprev)->vm_next;
35495 ++ }
35496 ++
35497 ++ if (end != vma->vm_end) {
35498 ++ error = split_vma(mm, vma, end, 0);
35499 ++ if (error)
35500 ++ goto fail;
35501 ++ }
35502 ++
35503 ++ if (pax_find_mirror_vma(vma)) {
35504 ++ error = __do_munmap(mm, start_m, end_m - start_m);
35505 ++ if (error)
35506 ++ goto fail;
35507 ++ } else {
35508 ++ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
35509 ++ if (!vma_m) {
35510 ++ error = -ENOMEM;
35511 ++ goto fail;
35512 ++ }
35513 ++ vma->vm_flags = newflags;
35514 ++ pax_mirror_vma(vma_m, vma);
35515 ++ }
35516 ++ }
35517 ++#endif
35518 ++
35519 + /*
35520 + * First try to merge with previous and/or next vma.
35521 + */
35522 +@@ -196,8 +285,14 @@ success:
35523 + * held in write mode.
35524 + */
35525 + vma->vm_flags = newflags;
35526 ++
35527 ++#ifdef CONFIG_PAX_MPROTECT
35528 ++ if (current->binfmt && current->binfmt->handle_mprotect)
35529 ++ current->binfmt->handle_mprotect(vma, newflags);
35530 ++#endif
35531 ++
35532 + vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
35533 +- vm_get_page_prot(newflags));
35534 ++ vm_get_page_prot(vma->vm_flags));
35535 +
35536 + if (vma_wants_writenotify(vma)) {
35537 + vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
35538 +@@ -238,6 +333,17 @@ sys_mprotect(unsigned long start, size_t
35539 + end = start + len;
35540 + if (end <= start)
35541 + return -ENOMEM;
35542 ++
35543 ++#ifdef CONFIG_PAX_SEGMEXEC
35544 ++ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
35545 ++ if (end > SEGMEXEC_TASK_SIZE)
35546 ++ return -EINVAL;
35547 ++ } else
35548 ++#endif
35549 ++
35550 ++ if (end > TASK_SIZE)
35551 ++ return -EINVAL;
35552 ++
35553 + if (!arch_validate_prot(prot))
35554 + return -EINVAL;
35555 +
35556 +@@ -245,7 +351,7 @@ sys_mprotect(unsigned long start, size_t
35557 + /*
35558 + * Does the application expect PROT_READ to imply PROT_EXEC:
35559 + */
35560 +- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
35561 ++ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
35562 + prot |= PROT_EXEC;
35563 +
35564 + vm_flags = calc_vm_prot_bits(prot);
35565 +@@ -277,6 +383,16 @@ sys_mprotect(unsigned long start, size_t
35566 + if (start > vma->vm_start)
35567 + prev = vma;
35568 +
35569 ++ if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
35570 ++ error = -EACCES;
35571 ++ goto out;
35572 ++ }
35573 ++
35574 ++#ifdef CONFIG_PAX_MPROTECT
35575 ++ if (current->binfmt && current->binfmt->handle_mprotect)
35576 ++ current->binfmt->handle_mprotect(vma, vm_flags);
35577 ++#endif
35578 ++
35579 + for (nstart = start ; ; ) {
35580 + unsigned long newflags;
35581 +
35582 +@@ -300,6 +416,9 @@ sys_mprotect(unsigned long start, size_t
35583 + error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
35584 + if (error)
35585 + goto out;
35586 ++
35587 ++ track_exec_limit(current->mm, nstart, tmp, vm_flags);
35588 ++
35589 + nstart = tmp;
35590 +
35591 + if (nstart < prev->vm_end)
35592 +diff -urNp linux-2.6.27.10/mm/mremap.c linux-2.6.27.10/mm/mremap.c
35593 +--- linux-2.6.27.10/mm/mremap.c 2008-11-07 12:55:34.000000000 -0500
35594 ++++ linux-2.6.27.10/mm/mremap.c 2008-11-18 03:38:45.000000000 -0500
35595 +@@ -111,6 +111,12 @@ static void move_ptes(struct vm_area_str
35596 + continue;
35597 + pte = ptep_clear_flush(vma, old_addr, old_pte);
35598 + pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
35599 ++
35600 ++#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
35601 ++ if (!nx_enabled && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
35602 ++ pte = pte_exprotect(pte);
35603 ++#endif
35604 ++
35605 + set_pte_at(mm, new_addr, new_pte, pte);
35606 + }
35607 +
35608 +@@ -260,6 +266,7 @@ unsigned long do_mremap(unsigned long ad
35609 + struct vm_area_struct *vma;
35610 + unsigned long ret = -EINVAL;
35611 + unsigned long charged = 0;
35612 ++ unsigned long pax_task_size = TASK_SIZE;
35613 +
35614 + if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
35615 + goto out;
35616 +@@ -278,6 +285,15 @@ unsigned long do_mremap(unsigned long ad
35617 + if (!new_len)
35618 + goto out;
35619 +
35620 ++#ifdef CONFIG_PAX_SEGMEXEC
35621 ++ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
35622 ++ pax_task_size = SEGMEXEC_TASK_SIZE;
35623 ++#endif
35624 ++
35625 ++ if (new_len > pax_task_size || addr > pax_task_size-new_len ||
35626 ++ old_len > pax_task_size || addr > pax_task_size-old_len)
35627 ++ goto out;
35628 ++
35629 + /* new_addr is only valid if MREMAP_FIXED is specified */
35630 + if (flags & MREMAP_FIXED) {
35631 + if (new_addr & ~PAGE_MASK)
35632 +@@ -285,16 +301,13 @@ unsigned long do_mremap(unsigned long ad
35633 + if (!(flags & MREMAP_MAYMOVE))
35634 + goto out;
35635 +
35636 +- if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
35637 ++ if (new_addr > pax_task_size - new_len)
35638 + goto out;
35639 +
35640 + /* Check if the location we're moving into overlaps the
35641 + * old location at all, and fail if it does.
35642 + */
35643 +- if ((new_addr <= addr) && (new_addr+new_len) > addr)
35644 +- goto out;
35645 +-
35646 +- if ((addr <= new_addr) && (addr+old_len) > new_addr)
35647 ++ if (addr + old_len > new_addr && new_addr + new_len > addr)
35648 + goto out;
35649 +
35650 + ret = security_file_mmap(NULL, 0, 0, 0, new_addr, 1);
35651 +@@ -332,6 +345,14 @@ unsigned long do_mremap(unsigned long ad
35652 + ret = -EINVAL;
35653 + goto out;
35654 + }
35655 ++
35656 ++#ifdef CONFIG_PAX_SEGMEXEC
35657 ++ if (pax_find_mirror_vma(vma)) {
35658 ++ ret = -EINVAL;
35659 ++ goto out;
35660 ++ }
35661 ++#endif
35662 ++
35663 + /* We can't remap across vm area boundaries */
35664 + if (old_len > vma->vm_end - addr)
35665 + goto out;
35666 +@@ -365,7 +386,7 @@ unsigned long do_mremap(unsigned long ad
35667 + if (old_len == vma->vm_end - addr &&
35668 + !((flags & MREMAP_FIXED) && (addr != new_addr)) &&
35669 + (old_len != new_len || !(flags & MREMAP_MAYMOVE))) {
35670 +- unsigned long max_addr = TASK_SIZE;
35671 ++ unsigned long max_addr = pax_task_size;
35672 + if (vma->vm_next)
35673 + max_addr = vma->vm_next->vm_start;
35674 + /* can we just expand the current mapping? */
35675 +@@ -383,6 +404,7 @@ unsigned long do_mremap(unsigned long ad
35676 + addr + new_len);
35677 + }
35678 + ret = addr;
35679 ++ track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
35680 + goto out;
35681 + }
35682 + }
35683 +@@ -393,8 +415,8 @@ unsigned long do_mremap(unsigned long ad
35684 + */
35685 + ret = -ENOMEM;
35686 + if (flags & MREMAP_MAYMOVE) {
35687 ++ unsigned long map_flags = 0;
35688 + if (!(flags & MREMAP_FIXED)) {
35689 +- unsigned long map_flags = 0;
35690 + if (vma->vm_flags & VM_MAYSHARE)
35691 + map_flags |= MAP_SHARED;
35692 +
35693 +@@ -409,7 +431,12 @@ unsigned long do_mremap(unsigned long ad
35694 + if (ret)
35695 + goto out;
35696 + }
35697 ++ map_flags = vma->vm_flags;
35698 + ret = move_vma(vma, addr, old_len, new_len, new_addr);
35699 ++ if (!(ret & ~PAGE_MASK)) {
35700 ++ track_exec_limit(current->mm, addr, addr + old_len, 0UL);
35701 ++ track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
35702 ++ }
35703 + }
35704 + out:
35705 + if (ret & ~PAGE_MASK)
35706 +diff -urNp linux-2.6.27.10/mm/nommu.c linux-2.6.27.10/mm/nommu.c
35707 +--- linux-2.6.27.10/mm/nommu.c 2008-11-07 12:55:34.000000000 -0500
35708 ++++ linux-2.6.27.10/mm/nommu.c 2008-11-18 03:38:45.000000000 -0500
35709 +@@ -437,15 +437,6 @@ struct vm_area_struct *find_vma(struct m
35710 + }
35711 + EXPORT_SYMBOL(find_vma);
35712 +
35713 +-/*
35714 +- * find a VMA
35715 +- * - we don't extend stack VMAs under NOMMU conditions
35716 +- */
35717 +-struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
35718 +-{
35719 +- return find_vma(mm, addr);
35720 +-}
35721 +-
35722 + int expand_stack(struct vm_area_struct *vma, unsigned long address)
35723 + {
35724 + return -ENOMEM;
35725 +diff -urNp linux-2.6.27.10/mm/page_alloc.c linux-2.6.27.10/mm/page_alloc.c
35726 +--- linux-2.6.27.10/mm/page_alloc.c 2008-12-21 01:18:12.000000000 -0500
35727 ++++ linux-2.6.27.10/mm/page_alloc.c 2008-12-21 01:18:22.000000000 -0500
35728 +@@ -515,9 +515,20 @@ static void free_pages_bulk(struct zone
35729 +
35730 + static void free_one_page(struct zone *zone, struct page *page, int order)
35731 + {
35732 ++
35733 ++#ifdef CONFIG_PAX_MEMORY_SANITIZE
35734 ++ unsigned long index = 1UL << order;
35735 ++#endif
35736 ++
35737 + spin_lock(&zone->lock);
35738 + zone_clear_flag(zone, ZONE_ALL_UNRECLAIMABLE);
35739 + zone->pages_scanned = 0;
35740 ++
35741 ++#ifdef CONFIG_PAX_MEMORY_SANITIZE
35742 ++ for (; index; --index)
35743 ++ sanitize_highpage(page + index - 1);
35744 ++#endif
35745 ++
35746 + __free_one_page(page, zone, order);
35747 + spin_unlock(&zone->lock);
35748 + }
35749 +@@ -635,8 +646,10 @@ static int prep_new_page(struct page *pa
35750 + arch_alloc_page(page, order);
35751 + kernel_map_pages(page, 1 << order, 1);
35752 +
35753 ++#ifndef CONFIG_PAX_MEMORY_SANITIZE
35754 + if (gfp_flags & __GFP_ZERO)
35755 + prep_zero_page(page, order, gfp_flags);
35756 ++#endif
35757 +
35758 + if (order && (gfp_flags & __GFP_COMP))
35759 + prep_compound_page(page, order);
35760 +@@ -1009,6 +1022,11 @@ static void free_hot_cold_page(struct pa
35761 + list_add(&page->lru, &pcp->list);
35762 + set_page_private(page, get_pageblock_migratetype(page));
35763 + pcp->count++;
35764 ++
35765 ++#ifdef CONFIG_PAX_MEMORY_SANITIZE
35766 ++ sanitize_highpage(page);
35767 ++#endif
35768 ++
35769 + if (pcp->count >= pcp->high) {
35770 + free_pages_bulk(zone, pcp->batch, &pcp->list, 0);
35771 + pcp->count -= pcp->batch;
35772 +diff -urNp linux-2.6.27.10/mm/rmap.c linux-2.6.27.10/mm/rmap.c
35773 +--- linux-2.6.27.10/mm/rmap.c 2008-11-07 12:55:34.000000000 -0500
35774 ++++ linux-2.6.27.10/mm/rmap.c 2008-11-18 03:38:45.000000000 -0500
35775 +@@ -91,6 +91,10 @@ int anon_vma_prepare(struct vm_area_stru
35776 + struct mm_struct *mm = vma->vm_mm;
35777 + struct anon_vma *allocated;
35778 +
35779 ++#ifdef CONFIG_PAX_SEGMEXEC
35780 ++ struct vm_area_struct *vma_m;
35781 ++#endif
35782 ++
35783 + anon_vma = find_mergeable_anon_vma(vma);
35784 + allocated = NULL;
35785 + if (!anon_vma) {
35786 +@@ -104,6 +108,15 @@ int anon_vma_prepare(struct vm_area_stru
35787 + /* page_table_lock to protect against threads */
35788 + spin_lock(&mm->page_table_lock);
35789 + if (likely(!vma->anon_vma)) {
35790 ++
35791 ++#ifdef CONFIG_PAX_SEGMEXEC
35792 ++ vma_m = pax_find_mirror_vma(vma);
35793 ++ if (vma_m) {
35794 ++ vma_m->anon_vma = anon_vma;
35795 ++ __anon_vma_link(vma_m);
35796 ++ }
35797 ++#endif
35798 ++
35799 + vma->anon_vma = anon_vma;
35800 + list_add_tail(&vma->anon_vma_node, &anon_vma->head);
35801 + allocated = NULL;
35802 +diff -urNp linux-2.6.27.10/mm/shmem.c linux-2.6.27.10/mm/shmem.c
35803 +--- linux-2.6.27.10/mm/shmem.c 2008-11-07 12:55:34.000000000 -0500
35804 ++++ linux-2.6.27.10/mm/shmem.c 2008-11-18 03:38:45.000000000 -0500
35805 +@@ -2483,7 +2483,7 @@ static struct file_system_type tmpfs_fs_
35806 + .get_sb = shmem_get_sb,
35807 + .kill_sb = kill_litter_super,
35808 + };
35809 +-static struct vfsmount *shm_mnt;
35810 ++struct vfsmount *shm_mnt;
35811 +
35812 + static int __init init_tmpfs(void)
35813 + {
35814 +diff -urNp linux-2.6.27.10/mm/slab.c linux-2.6.27.10/mm/slab.c
35815 +--- linux-2.6.27.10/mm/slab.c 2008-11-07 12:55:34.000000000 -0500
35816 ++++ linux-2.6.27.10/mm/slab.c 2008-11-18 03:38:45.000000000 -0500
35817 +@@ -304,7 +304,7 @@ struct kmem_list3 {
35818 + * Need this for bootstrapping a per node allocator.
35819 + */
35820 + #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
35821 +-struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
35822 ++struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
35823 + #define CACHE_CACHE 0
35824 + #define SIZE_AC MAX_NUMNODES
35825 + #define SIZE_L3 (2 * MAX_NUMNODES)
35826 +@@ -653,14 +653,14 @@ struct cache_names {
35827 + static struct cache_names __initdata cache_names[] = {
35828 + #define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
35829 + #include <linux/kmalloc_sizes.h>
35830 +- {NULL,}
35831 ++ {NULL, NULL}
35832 + #undef CACHE
35833 + };
35834 +
35835 + static struct arraycache_init initarray_cache __initdata =
35836 +- { {0, BOOT_CPUCACHE_ENTRIES, 1, 0} };
35837 ++ { {0, BOOT_CPUCACHE_ENTRIES, 1, 0}, {NULL} };
35838 + static struct arraycache_init initarray_generic =
35839 +- { {0, BOOT_CPUCACHE_ENTRIES, 1, 0} };
35840 ++ { {0, BOOT_CPUCACHE_ENTRIES, 1, 0}, {NULL} };
35841 +
35842 + /* internal cache of cache description objs */
35843 + static struct kmem_cache cache_cache = {
35844 +@@ -2996,7 +2996,7 @@ retry:
35845 + * there must be at least one object available for
35846 + * allocation.
35847 + */
35848 +- BUG_ON(slabp->inuse < 0 || slabp->inuse >= cachep->num);
35849 ++ BUG_ON(slabp->inuse >= cachep->num);
35850 +
35851 + while (slabp->inuse < cachep->num && batchcount--) {
35852 + STATS_INC_ALLOCED(cachep);
35853 +diff -urNp linux-2.6.27.10/mm/tiny-shmem.c linux-2.6.27.10/mm/tiny-shmem.c
35854 +--- linux-2.6.27.10/mm/tiny-shmem.c 2008-11-07 12:55:34.000000000 -0500
35855 ++++ linux-2.6.27.10/mm/tiny-shmem.c 2008-11-18 03:38:45.000000000 -0500
35856 +@@ -26,7 +26,7 @@ static struct file_system_type tmpfs_fs_
35857 + .kill_sb = kill_litter_super,
35858 + };
35859 +
35860 +-static struct vfsmount *shm_mnt;
35861 ++struct vfsmount *shm_mnt;
35862 +
35863 + static int __init init_tmpfs(void)
35864 + {
35865 +diff -urNp linux-2.6.27.10/mm/util.c linux-2.6.27.10/mm/util.c
35866 +--- linux-2.6.27.10/mm/util.c 2008-11-07 12:55:34.000000000 -0500
35867 ++++ linux-2.6.27.10/mm/util.c 2008-11-18 03:38:45.000000000 -0500
35868 +@@ -167,6 +167,12 @@ EXPORT_SYMBOL(strndup_user);
35869 + void arch_pick_mmap_layout(struct mm_struct *mm)
35870 + {
35871 + mm->mmap_base = TASK_UNMAPPED_BASE;
35872 ++
35873 ++#ifdef CONFIG_PAX_RANDMMAP
35874 ++ if (mm->pax_flags & MF_PAX_RANDMMAP)
35875 ++ mm->mmap_base += mm->delta_mmap;
35876 ++#endif
35877 ++
35878 + mm->get_unmapped_area = arch_get_unmapped_area;
35879 + mm->unmap_area = arch_unmap_area;
35880 + }
35881 +diff -urNp linux-2.6.27.10/mm/vmalloc.c linux-2.6.27.10/mm/vmalloc.c
35882 +--- linux-2.6.27.10/mm/vmalloc.c 2008-11-07 12:55:34.000000000 -0500
35883 ++++ linux-2.6.27.10/mm/vmalloc.c 2008-11-18 03:38:45.000000000 -0500
35884 +@@ -98,19 +98,36 @@ static int vmap_pte_range(pmd_t *pmd, un
35885 + unsigned long end, pgprot_t prot, struct page ***pages)
35886 + {
35887 + pte_t *pte;
35888 ++ int ret = -ENOMEM;
35889 ++
35890 ++#ifdef CONFIG_PAX_KERNEXEC
35891 ++ unsigned long cr0;
35892 ++#endif
35893 +
35894 + pte = pte_alloc_kernel(pmd, addr);
35895 + if (!pte)
35896 + return -ENOMEM;
35897 ++
35898 ++#ifdef CONFIG_PAX_KERNEXEC
35899 ++ pax_open_kernel(cr0);
35900 ++#endif
35901 ++
35902 + do {
35903 + struct page *page = **pages;
35904 + WARN_ON(!pte_none(*pte));
35905 + if (!page)
35906 +- return -ENOMEM;
35907 ++ goto out;
35908 + set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
35909 + (*pages)++;
35910 + } while (pte++, addr += PAGE_SIZE, addr != end);
35911 +- return 0;
35912 ++ ret = 0;
35913 ++out:
35914 ++
35915 ++#ifdef CONFIG_PAX_KERNEXEC
35916 ++ pax_close_kernel(cr0);
35917 ++#endif
35918 ++
35919 ++ return ret;
35920 + }
35921 +
35922 + static inline int vmap_pmd_range(pud_t *pud, unsigned long addr,
35923 +@@ -215,6 +232,16 @@ __get_vm_area_node(unsigned long size, u
35924 + unsigned long addr;
35925 +
35926 + BUG_ON(in_interrupt());
35927 ++
35928 ++#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
35929 ++ if (flags & VM_KERNEXEC) {
35930 ++ if (start != VMALLOC_START || end != VMALLOC_END)
35931 ++ return NULL;
35932 ++ start = (unsigned long)MODULES_VADDR;
35933 ++ end = (unsigned long)MODULES_END;
35934 ++ }
35935 ++#endif
35936 ++
35937 + if (flags & VM_IOREMAP) {
35938 + int bit = fls(size);
35939 +
35940 +@@ -248,20 +275,15 @@ __get_vm_area_node(unsigned long size, u
35941 + (unsigned long)tmp->addr, align);
35942 + continue;
35943 + }
35944 +- if ((size + addr) < addr)
35945 +- goto out;
35946 + if (size + addr <= (unsigned long)tmp->addr)
35947 +- goto found;
35948 ++ break;
35949 + addr = ALIGN(tmp->size + (unsigned long)tmp->addr, align);
35950 +- if (addr > end - size)
35951 +- goto out;
35952 + }
35953 + if ((size + addr) < addr)
35954 + goto out;
35955 + if (addr > end - size)
35956 + goto out;
35957 +
35958 +-found:
35959 + area->next = *p;
35960 + *p = area;
35961 +
35962 +@@ -466,6 +488,11 @@ void *vmap(struct page **pages, unsigned
35963 + if (count > num_physpages)
35964 + return NULL;
35965 +
35966 ++#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
35967 ++ if (!(pgprot_val(prot) & _PAGE_NX))
35968 ++ flags |= VM_KERNEXEC;
35969 ++#endif
35970 ++
35971 + area = get_vm_area_caller((count << PAGE_SHIFT), flags,
35972 + __builtin_return_address(0));
35973 + if (!area)
35974 +@@ -560,6 +587,13 @@ static void *__vmalloc_node(unsigned lon
35975 + if (!size || (size >> PAGE_SHIFT) > num_physpages)
35976 + return NULL;
35977 +
35978 ++#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
35979 ++ if (!(pgprot_val(prot) & _PAGE_NX))
35980 ++ area = __get_vm_area_node(size, VM_ALLOC | VM_KERNEXEC, VMALLOC_START, VMALLOC_END,
35981 ++ node, gfp_mask, caller);
35982 ++ else
35983 ++#endif
35984 ++
35985 + area = __get_vm_area_node(size, VM_ALLOC, VMALLOC_START, VMALLOC_END,
35986 + node, gfp_mask, caller);
35987 +
35988 +@@ -651,7 +685,7 @@ EXPORT_SYMBOL(vmalloc_node);
35989 +
35990 + void *vmalloc_exec(unsigned long size)
35991 + {
35992 +- return __vmalloc(size, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC);
35993 ++ return __vmalloc(size, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC);
35994 + }
35995 +
35996 + #if defined(CONFIG_64BIT) && defined(CONFIG_ZONE_DMA32)
35997 +diff -urNp linux-2.6.27.10/net/bridge/br_stp_if.c linux-2.6.27.10/net/bridge/br_stp_if.c
35998 +--- linux-2.6.27.10/net/bridge/br_stp_if.c 2008-11-07 12:55:34.000000000 -0500
35999 ++++ linux-2.6.27.10/net/bridge/br_stp_if.c 2008-11-18 03:38:45.000000000 -0500
36000 +@@ -146,7 +146,7 @@ static void br_stp_stop(struct net_bridg
36001 + char *envp[] = { NULL };
36002 +
36003 + if (br->stp_enabled == BR_USER_STP) {
36004 +- r = call_usermodehelper(BR_STP_PROG, argv, envp, 1);
36005 ++ r = call_usermodehelper(BR_STP_PROG, argv, envp, UMH_WAIT_PROC);
36006 + printk(KERN_INFO "%s: userspace STP stopped, return code %d\n",
36007 + br->dev->name, r);
36008 +
36009 +diff -urNp linux-2.6.27.10/net/core/flow.c linux-2.6.27.10/net/core/flow.c
36010 +--- linux-2.6.27.10/net/core/flow.c 2008-11-07 12:55:34.000000000 -0500
36011 ++++ linux-2.6.27.10/net/core/flow.c 2008-11-18 03:38:45.000000000 -0500
36012 +@@ -39,7 +39,7 @@ atomic_t flow_cache_genid = ATOMIC_INIT(
36013 +
36014 + static u32 flow_hash_shift;
36015 + #define flow_hash_size (1 << flow_hash_shift)
36016 +-static DEFINE_PER_CPU(struct flow_cache_entry **, flow_tables) = { NULL };
36017 ++static DEFINE_PER_CPU(struct flow_cache_entry **, flow_tables);
36018 +
36019 + #define flow_table(cpu) (per_cpu(flow_tables, cpu))
36020 +
36021 +@@ -52,7 +52,7 @@ struct flow_percpu_info {
36022 + u32 hash_rnd;
36023 + int count;
36024 + };
36025 +-static DEFINE_PER_CPU(struct flow_percpu_info, flow_hash_info) = { 0 };
36026 ++static DEFINE_PER_CPU(struct flow_percpu_info, flow_hash_info);
36027 +
36028 + #define flow_hash_rnd_recalc(cpu) \
36029 + (per_cpu(flow_hash_info, cpu).hash_rnd_recalc)
36030 +@@ -69,7 +69,7 @@ struct flow_flush_info {
36031 + atomic_t cpuleft;
36032 + struct completion completion;
36033 + };
36034 +-static DEFINE_PER_CPU(struct tasklet_struct, flow_flush_tasklets) = { NULL };
36035 ++static DEFINE_PER_CPU(struct tasklet_struct, flow_flush_tasklets);
36036 +
36037 + #define flow_flush_tasklet(cpu) (&per_cpu(flow_flush_tasklets, cpu))
36038 +
36039 +diff -urNp linux-2.6.27.10/net/dccp/ccids/ccid3.c linux-2.6.27.10/net/dccp/ccids/ccid3.c
36040 +--- linux-2.6.27.10/net/dccp/ccids/ccid3.c 2008-11-07 12:55:34.000000000 -0500
36041 ++++ linux-2.6.27.10/net/dccp/ccids/ccid3.c 2008-11-18 03:38:45.000000000 -0500
36042 +@@ -43,7 +43,7 @@
36043 + static int ccid3_debug;
36044 + #define ccid3_pr_debug(format, a...) DCCP_PR_DEBUG(ccid3_debug, format, ##a)
36045 + #else
36046 +-#define ccid3_pr_debug(format, a...)
36047 ++#define ccid3_pr_debug(format, a...) do {} while (0)
36048 + #endif
36049 +
36050 + /*
36051 +diff -urNp linux-2.6.27.10/net/dccp/dccp.h linux-2.6.27.10/net/dccp/dccp.h
36052 +--- linux-2.6.27.10/net/dccp/dccp.h 2008-11-07 12:55:34.000000000 -0500
36053 ++++ linux-2.6.27.10/net/dccp/dccp.h 2008-11-18 03:38:45.000000000 -0500
36054 +@@ -43,8 +43,8 @@ extern int dccp_debug;
36055 + #define dccp_pr_debug(format, a...) DCCP_PR_DEBUG(dccp_debug, format, ##a)
36056 + #define dccp_pr_debug_cat(format, a...) DCCP_PRINTK(dccp_debug, format, ##a)
36057 + #else
36058 +-#define dccp_pr_debug(format, a...)
36059 +-#define dccp_pr_debug_cat(format, a...)
36060 ++#define dccp_pr_debug(format, a...) do {} while (0)
36061 ++#define dccp_pr_debug_cat(format, a...) do {} while (0)
36062 + #endif
36063 +
36064 + extern struct inet_hashinfo dccp_hashinfo;
36065 +diff -urNp linux-2.6.27.10/net/ipv4/inet_connection_sock.c linux-2.6.27.10/net/ipv4/inet_connection_sock.c
36066 +--- linux-2.6.27.10/net/ipv4/inet_connection_sock.c 2008-11-07 12:55:34.000000000 -0500
36067 ++++ linux-2.6.27.10/net/ipv4/inet_connection_sock.c 2008-11-18 03:38:45.000000000 -0500
36068 +@@ -15,6 +15,7 @@
36069 +
36070 + #include <linux/module.h>
36071 + #include <linux/jhash.h>
36072 ++#include <linux/grsecurity.h>
36073 +
36074 + #include <net/inet_connection_sock.h>
36075 + #include <net/inet_hashtables.h>
36076 +diff -urNp linux-2.6.27.10/net/ipv4/inet_hashtables.c linux-2.6.27.10/net/ipv4/inet_hashtables.c
36077 +--- linux-2.6.27.10/net/ipv4/inet_hashtables.c 2008-11-07 12:55:34.000000000 -0500
36078 ++++ linux-2.6.27.10/net/ipv4/inet_hashtables.c 2008-11-18 03:38:45.000000000 -0500
36079 +@@ -18,11 +18,14 @@
36080 + #include <linux/sched.h>
36081 + #include <linux/slab.h>
36082 + #include <linux/wait.h>
36083 ++#include <linux/grsecurity.h>
36084 +
36085 + #include <net/inet_connection_sock.h>
36086 + #include <net/inet_hashtables.h>
36087 + #include <net/ip.h>
36088 +
36089 ++extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
36090 ++
36091 + /*
36092 + * Allocate and initialize a new local port bind bucket.
36093 + * The bindhash mutex for snum's hash chain must be held here.
36094 +@@ -487,6 +490,8 @@ ok:
36095 + }
36096 + spin_unlock(&head->lock);
36097 +
36098 ++ gr_update_task_in_ip_table(current, inet_sk(sk));
36099 ++
36100 + if (tw) {
36101 + inet_twsk_deschedule(tw, death_row);
36102 + inet_twsk_put(tw);
36103 +diff -urNp linux-2.6.27.10/net/ipv4/netfilter/ipt_stealth.c linux-2.6.27.10/net/ipv4/netfilter/ipt_stealth.c
36104 +--- linux-2.6.27.10/net/ipv4/netfilter/ipt_stealth.c 1969-12-31 19:00:00.000000000 -0500
36105 ++++ linux-2.6.27.10/net/ipv4/netfilter/ipt_stealth.c 2008-11-18 03:38:45.000000000 -0500
36106 +@@ -0,0 +1,114 @@
36107 ++/* Kernel module to add stealth support.
36108 ++ *
36109 ++ * Copyright (C) 2002-2006 Brad Spengler <spender@××××××××××.net>
36110 ++ *
36111 ++ */
36112 ++
36113 ++#include <linux/kernel.h>
36114 ++#include <linux/module.h>
36115 ++#include <linux/skbuff.h>
36116 ++#include <linux/net.h>
36117 ++#include <linux/sched.h>
36118 ++#include <linux/inet.h>
36119 ++#include <linux/stddef.h>
36120 ++
36121 ++#include <net/ip.h>
36122 ++#include <net/sock.h>
36123 ++#include <net/tcp.h>
36124 ++#include <net/udp.h>
36125 ++#include <net/route.h>
36126 ++#include <net/inet_common.h>
36127 ++
36128 ++#include <linux/netfilter_ipv4/ip_tables.h>
36129 ++
36130 ++MODULE_LICENSE("GPL");
36131 ++
36132 ++extern struct sock *udp_v4_lookup(struct net *net, u32 saddr, u16 sport, u32 daddr, u16 dport, int dif);
36133 ++
36134 ++static bool
36135 ++match(const struct sk_buff *skb,
36136 ++ const struct net_device *in,
36137 ++ const struct net_device *out,
36138 ++ const struct xt_match *match,
36139 ++ const void *matchinfo,
36140 ++ int offset,
36141 ++ unsigned int protoff,
36142 ++ bool *hotdrop)
36143 ++{
36144 ++ struct iphdr *ip = ip_hdr(skb);
36145 ++ struct tcphdr th;
36146 ++ struct udphdr uh;
36147 ++ struct sock *sk = NULL;
36148 ++
36149 ++ if (!ip || offset) return false;
36150 ++
36151 ++ switch(ip->protocol) {
36152 ++ case IPPROTO_TCP:
36153 ++ if (skb_copy_bits(skb, (ip_hdr(skb))->ihl*4, &th, sizeof(th)) < 0) {
36154 ++ *hotdrop = true;
36155 ++ return false;
36156 ++ }
36157 ++ if (!(th.syn && !th.ack)) return false;
36158 ++ sk = inet_lookup_listener(dev_net(skb->dev), &tcp_hashinfo, ip->daddr, th.dest, inet_iif(skb));
36159 ++ break;
36160 ++ case IPPROTO_UDP:
36161 ++ if (skb_copy_bits(skb, (ip_hdr(skb))->ihl*4, &uh, sizeof(uh)) < 0) {
36162 ++ *hotdrop = true;
36163 ++ return false;
36164 ++ }
36165 ++ sk = udp_v4_lookup(dev_net(skb->dev), ip->saddr, uh.source, ip->daddr, uh.dest, skb->dev->ifindex);
36166 ++ break;
36167 ++ default:
36168 ++ return false;
36169 ++ }
36170 ++
36171 ++ if(!sk) // port is being listened on, match this
36172 ++ return true;
36173 ++ else {
36174 ++ sock_put(sk);
36175 ++ return false;
36176 ++ }
36177 ++}
36178 ++
36179 ++/* Called when user tries to insert an entry of this type. */
36180 ++static bool
36181 ++checkentry(const char *tablename,
36182 ++ const void *nip,
36183 ++ const struct xt_match *match,
36184 ++ void *matchinfo,
36185 ++ unsigned int hook_mask)
36186 ++{
36187 ++ const struct ipt_ip *ip = (const struct ipt_ip *)nip;
36188 ++
36189 ++ if(((ip->proto == IPPROTO_TCP && !(ip->invflags & IPT_INV_PROTO)) ||
36190 ++ ((ip->proto == IPPROTO_UDP) && !(ip->invflags & IPT_INV_PROTO)))
36191 ++ && (hook_mask & (1 << NF_INET_LOCAL_IN)))
36192 ++ return true;
36193 ++
36194 ++ printk("stealth: Only works on TCP and UDP for the INPUT chain.\n");
36195 ++
36196 ++ return false;
36197 ++}
36198 ++
36199 ++
36200 ++static struct xt_match stealth_match __read_mostly = {
36201 ++ .name = "stealth",
36202 ++ .family = AF_INET,
36203 ++ .match = match,
36204 ++ .checkentry = checkentry,
36205 ++ .destroy = NULL,
36206 ++ .me = THIS_MODULE
36207 ++};
36208 ++
36209 ++static int __init init(void)
36210 ++{
36211 ++ return xt_register_match(&stealth_match);
36212 ++}
36213 ++
36214 ++static void __exit fini(void)
36215 ++{
36216 ++ xt_unregister_match(&stealth_match);
36217 ++}
36218 ++
36219 ++module_init(init);
36220 ++module_exit(fini);
36221 +diff -urNp linux-2.6.27.10/net/ipv4/netfilter/Kconfig linux-2.6.27.10/net/ipv4/netfilter/Kconfig
36222 +--- linux-2.6.27.10/net/ipv4/netfilter/Kconfig 2008-11-07 12:55:34.000000000 -0500
36223 ++++ linux-2.6.27.10/net/ipv4/netfilter/Kconfig 2008-11-18 03:38:45.000000000 -0500
36224 +@@ -111,6 +111,21 @@ config IP_NF_MATCH_ADDRTYPE
36225 + If you want to compile it as a module, say M here and read
36226 + <file:Documentation/kbuild/modules.txt>. If unsure, say `N'.
36227 +
36228 ++config IP_NF_MATCH_STEALTH
36229 ++ tristate "stealth match support"
36230 ++ depends on IP_NF_IPTABLES
36231 ++ help
36232 ++ Enabling this option will drop all syn packets coming to unserved tcp
36233 ++ ports as well as all packets coming to unserved udp ports. If you
36234 ++ are using your system to route any type of packets (ie. via NAT)
36235 ++ you should put this module at the end of your ruleset, since it will
36236 ++ drop packets that aren't going to ports that are listening on your
36237 ++ machine itself, it doesn't take into account that the packet might be
36238 ++ destined for someone on your internal network if you're using NAT for
36239 ++ instance.
36240 ++
36241 ++ To compile it as a module, choose M here. If unsure, say N.
36242 ++
36243 + # `filter', generic and specific targets
36244 + config IP_NF_FILTER
36245 + tristate "Packet filtering"
36246 +@@ -407,4 +422,3 @@ config IP_NF_ARP_MANGLE
36247 + hardware and network addresses.
36248 +
36249 + endmenu
36250 +-
36251 +diff -urNp linux-2.6.27.10/net/ipv4/netfilter/Makefile linux-2.6.27.10/net/ipv4/netfilter/Makefile
36252 +--- linux-2.6.27.10/net/ipv4/netfilter/Makefile 2008-11-07 12:55:34.000000000 -0500
36253 ++++ linux-2.6.27.10/net/ipv4/netfilter/Makefile 2008-11-18 03:38:45.000000000 -0500
36254 +@@ -59,6 +59,7 @@ obj-$(CONFIG_IP_NF_TARGET_MASQUERADE) +=
36255 + obj-$(CONFIG_IP_NF_TARGET_NETMAP) += ipt_NETMAP.o
36256 + obj-$(CONFIG_IP_NF_TARGET_REDIRECT) += ipt_REDIRECT.o
36257 + obj-$(CONFIG_IP_NF_TARGET_REJECT) += ipt_REJECT.o
36258 ++obj-$(CONFIG_IP_NF_MATCH_STEALTH) += ipt_stealth.o
36259 + obj-$(CONFIG_IP_NF_TARGET_TTL) += ipt_TTL.o
36260 + obj-$(CONFIG_IP_NF_TARGET_ULOG) += ipt_ULOG.o
36261 +
36262 +diff -urNp linux-2.6.27.10/net/ipv4/tcp_ipv4.c linux-2.6.27.10/net/ipv4/tcp_ipv4.c
36263 +--- linux-2.6.27.10/net/ipv4/tcp_ipv4.c 2008-11-07 12:55:34.000000000 -0500
36264 ++++ linux-2.6.27.10/net/ipv4/tcp_ipv4.c 2008-11-18 03:38:45.000000000 -0500
36265 +@@ -59,6 +59,7 @@
36266 + #include <linux/jhash.h>
36267 + #include <linux/init.h>
36268 + #include <linux/times.h>
36269 ++#include <linux/grsecurity.h>
36270 +
36271 + #include <net/net_namespace.h>
36272 + #include <net/icmp.h>
36273 +diff -urNp linux-2.6.27.10/net/ipv4/udp.c linux-2.6.27.10/net/ipv4/udp.c
36274 +--- linux-2.6.27.10/net/ipv4/udp.c 2008-12-21 01:16:52.000000000 -0500
36275 ++++ linux-2.6.27.10/net/ipv4/udp.c 2008-12-21 01:13:47.000000000 -0500
36276 +@@ -97,6 +97,7 @@
36277 + #include <linux/skbuff.h>
36278 + #include <linux/proc_fs.h>
36279 + #include <linux/seq_file.h>
36280 ++#include <linux/grsecurity.h>
36281 + #include <net/net_namespace.h>
36282 + #include <net/icmp.h>
36283 + #include <net/route.h>
36284 +@@ -104,6 +105,11 @@
36285 + #include <net/xfrm.h>
36286 + #include "udp_impl.h"
36287 +
36288 ++extern int gr_search_udp_recvmsg(const struct sock *sk,
36289 ++ const struct sk_buff *skb);
36290 ++extern int gr_search_udp_sendmsg(const struct sock *sk,
36291 ++ const struct sockaddr_in *addr);
36292 ++
36293 + /*
36294 + * Snmp MIB for the UDP layer
36295 + */
36296 +@@ -302,6 +308,13 @@ static struct sock *__udp4_lib_lookup(st
36297 + return result;
36298 + }
36299 +
36300 ++struct sock *udp_v4_lookup(struct net *net, __be32 saddr, __be16 sport,
36301 ++ __be32 daddr, __be16 dport, int dif)
36302 ++{
36303 ++ return __udp4_lib_lookup(net, saddr, sport, daddr, dport, dif, udp_hash);
36304 ++}
36305 ++
36306 ++
36307 + static inline struct sock *udp_v4_mcast_next(struct net *net, struct sock *sk,
36308 + __be16 loc_port, __be32 loc_addr,
36309 + __be16 rmt_port, __be32 rmt_addr,
36310 +@@ -592,9 +605,16 @@ int udp_sendmsg(struct kiocb *iocb, stru
36311 + dport = usin->sin_port;
36312 + if (dport == 0)
36313 + return -EINVAL;
36314 ++
36315 ++ if (!gr_search_udp_sendmsg(sk, usin))
36316 ++ return -EPERM;
36317 + } else {
36318 + if (sk->sk_state != TCP_ESTABLISHED)
36319 + return -EDESTADDRREQ;
36320 ++
36321 ++ if (!gr_search_udp_sendmsg(sk, NULL))
36322 ++ return -EPERM;
36323 ++
36324 + daddr = inet->daddr;
36325 + dport = inet->dport;
36326 + /* Open fast path for connected socket.
36327 +@@ -859,6 +879,11 @@ try_again:
36328 + if (!skb)
36329 + goto out;
36330 +
36331 ++ if (!gr_search_udp_recvmsg(sk, skb)) {
36332 ++ err = -EPERM;
36333 ++ goto out_free;
36334 ++ }
36335 ++
36336 + ulen = skb->len - sizeof(struct udphdr);
36337 + copied = len;
36338 + if (copied > ulen)
36339 +diff -urNp linux-2.6.27.10/net/ipv6/exthdrs.c linux-2.6.27.10/net/ipv6/exthdrs.c
36340 +--- linux-2.6.27.10/net/ipv6/exthdrs.c 2008-11-07 12:55:34.000000000 -0500
36341 ++++ linux-2.6.27.10/net/ipv6/exthdrs.c 2008-11-18 03:38:45.000000000 -0500
36342 +@@ -624,7 +624,7 @@ static struct tlvtype_proc tlvprochopopt
36343 + .type = IPV6_TLV_JUMBO,
36344 + .func = ipv6_hop_jumbo,
36345 + },
36346 +- { -1, }
36347 ++ { -1, NULL }
36348 + };
36349 +
36350 + int ipv6_parse_hopopts(struct sk_buff *skb)
36351 +diff -urNp linux-2.6.27.10/net/ipv6/raw.c linux-2.6.27.10/net/ipv6/raw.c
36352 +--- linux-2.6.27.10/net/ipv6/raw.c 2008-11-07 12:55:34.000000000 -0500
36353 ++++ linux-2.6.27.10/net/ipv6/raw.c 2008-11-18 03:38:45.000000000 -0500
36354 +@@ -600,7 +600,7 @@ out:
36355 + return err;
36356 + }
36357 +
36358 +-static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
36359 ++static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
36360 + struct flowi *fl, struct rt6_info *rt,
36361 + unsigned int flags)
36362 + {
36363 +diff -urNp linux-2.6.27.10/net/irda/ircomm/ircomm_tty.c linux-2.6.27.10/net/irda/ircomm/ircomm_tty.c
36364 +--- linux-2.6.27.10/net/irda/ircomm/ircomm_tty.c 2008-11-07 12:55:34.000000000 -0500
36365 ++++ linux-2.6.27.10/net/irda/ircomm/ircomm_tty.c 2008-11-18 03:38:45.000000000 -0500
36366 +@@ -371,7 +371,7 @@ static int ircomm_tty_open(struct tty_st
36367 + IRDA_DEBUG(2, "%s()\n", __func__ );
36368 +
36369 + line = tty->index;
36370 +- if ((line < 0) || (line >= IRCOMM_TTY_PORTS)) {
36371 ++ if (line >= IRCOMM_TTY_PORTS) {
36372 + return -ENODEV;
36373 + }
36374 +
36375 +diff -urNp linux-2.6.27.10/net/sctp/socket.c linux-2.6.27.10/net/sctp/socket.c
36376 +--- linux-2.6.27.10/net/sctp/socket.c 2008-11-07 12:55:34.000000000 -0500
36377 ++++ linux-2.6.27.10/net/sctp/socket.c 2008-11-18 03:38:45.000000000 -0500
36378 +@@ -1434,7 +1434,7 @@ SCTP_STATIC int sctp_sendmsg(struct kioc
36379 + struct sctp_sndrcvinfo *sinfo;
36380 + struct sctp_initmsg *sinit;
36381 + sctp_assoc_t associd = 0;
36382 +- sctp_cmsgs_t cmsgs = { NULL };
36383 ++ sctp_cmsgs_t cmsgs = { NULL, NULL };
36384 + int err;
36385 + sctp_scope_t scope;
36386 + long timeo;
36387 +@@ -5616,7 +5616,6 @@ pp_found:
36388 + */
36389 + int reuse = sk->sk_reuse;
36390 + struct sock *sk2;
36391 +- struct hlist_node *node;
36392 +
36393 + SCTP_DEBUG_PRINTK("sctp_get_port() found a possible match\n");
36394 + if (pp->fastreuse && sk->sk_reuse &&
36395 +diff -urNp linux-2.6.27.10/net/socket.c linux-2.6.27.10/net/socket.c
36396 +--- linux-2.6.27.10/net/socket.c 2008-11-07 12:55:34.000000000 -0500
36397 ++++ linux-2.6.27.10/net/socket.c 2008-11-18 03:38:45.000000000 -0500
36398 +@@ -87,6 +87,7 @@
36399 + #include <linux/audit.h>
36400 + #include <linux/wireless.h>
36401 + #include <linux/nsproxy.h>
36402 ++#include <linux/in.h>
36403 +
36404 + #include <asm/uaccess.h>
36405 + #include <asm/unistd.h>
36406 +@@ -97,6 +98,21 @@
36407 + #include <net/sock.h>
36408 + #include <linux/netfilter.h>
36409 +
36410 ++extern void gr_attach_curr_ip(const struct sock *sk);
36411 ++extern int gr_handle_sock_all(const int family, const int type,
36412 ++ const int protocol);
36413 ++extern int gr_handle_sock_server(const struct sockaddr *sck);
36414 ++extern int gr_handle_sock_server_other(const struct socket *sck);
36415 ++extern int gr_handle_sock_client(const struct sockaddr *sck);
36416 ++extern int gr_search_connect(const struct socket * sock,
36417 ++ const struct sockaddr_in * addr);
36418 ++extern int gr_search_bind(const struct socket * sock,
36419 ++ const struct sockaddr_in * addr);
36420 ++extern int gr_search_listen(const struct socket * sock);
36421 ++extern int gr_search_accept(const struct socket * sock);
36422 ++extern int gr_search_socket(const int domain, const int type,
36423 ++ const int protocol);
36424 ++
36425 + static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
36426 + static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
36427 + unsigned long nr_segs, loff_t pos);
36428 +@@ -300,7 +316,7 @@ static int sockfs_get_sb(struct file_sys
36429 + mnt);
36430 + }
36431 +
36432 +-static struct vfsmount *sock_mnt __read_mostly;
36433 ++struct vfsmount *sock_mnt __read_mostly;
36434 +
36435 + static struct file_system_type sock_fs_type = {
36436 + .name = "sockfs",
36437 +@@ -1236,6 +1252,16 @@ asmlinkage long sys_socket(int family, i
36438 + if (SOCK_NONBLOCK != O_NONBLOCK && (flags & SOCK_NONBLOCK))
36439 + flags = (flags & ~SOCK_NONBLOCK) | O_NONBLOCK;
36440 +
36441 ++ if(!gr_search_socket(family, type, protocol)) {
36442 ++ retval = -EACCES;
36443 ++ goto out;
36444 ++ }
36445 ++
36446 ++ if (gr_handle_sock_all(family, type, protocol)) {
36447 ++ retval = -EACCES;
36448 ++ goto out;
36449 ++ }
36450 ++
36451 + retval = sock_create(family, type, protocol, &sock);
36452 + if (retval < 0)
36453 + goto out;
36454 +@@ -1375,6 +1401,12 @@ asmlinkage long sys_bind(int fd, struct
36455 + if (sock) {
36456 + err = move_addr_to_kernel(umyaddr, addrlen, (struct sockaddr *)&address);
36457 + if (err >= 0) {
36458 ++ if (!gr_search_bind(sock, (struct sockaddr_in *)&address) ||
36459 ++ gr_handle_sock_server((struct sockaddr *)&address)) {
36460 ++ err = -EACCES;
36461 ++ goto error;
36462 ++ }
36463 ++
36464 + err = security_socket_bind(sock,
36465 + (struct sockaddr *)&address,
36466 + addrlen);
36467 +@@ -1383,6 +1415,7 @@ asmlinkage long sys_bind(int fd, struct
36468 + (struct sockaddr *)
36469 + &address, addrlen);
36470 + }
36471 ++error:
36472 + fput_light(sock->file, fput_needed);
36473 + }
36474 + return err;
36475 +@@ -1406,10 +1439,17 @@ asmlinkage long sys_listen(int fd, int b
36476 + if ((unsigned)backlog > somaxconn)
36477 + backlog = somaxconn;
36478 +
36479 ++ if (gr_handle_sock_server_other(sock) ||
36480 ++ !gr_search_listen(sock)) {
36481 ++ err = -EPERM;
36482 ++ goto error;
36483 ++ }
36484 ++
36485 + err = security_socket_listen(sock, backlog);
36486 + if (!err)
36487 + err = sock->ops->listen(sock, backlog);
36488 +
36489 ++error:
36490 + fput_light(sock->file, fput_needed);
36491 + }
36492 + return err;
36493 +@@ -1452,6 +1492,13 @@ long do_accept(int fd, struct sockaddr _
36494 + newsock->type = sock->type;
36495 + newsock->ops = sock->ops;
36496 +
36497 ++ if (gr_handle_sock_server_other(sock) ||
36498 ++ !gr_search_accept(sock)) {
36499 ++ err = -EPERM;
36500 ++ sock_release(newsock);
36501 ++ goto out_put;
36502 ++ }
36503 ++
36504 + /*
36505 + * We don't need try_module_get here, as the listening socket (sock)
36506 + * has the protocol module (sock->ops->owner) held.
36507 +@@ -1495,6 +1542,7 @@ long do_accept(int fd, struct sockaddr _
36508 + err = newfd;
36509 +
36510 + security_socket_post_accept(sock, newsock);
36511 ++ gr_attach_curr_ip(newsock->sk);
36512 +
36513 + out_put:
36514 + fput_light(sock->file, fput_needed);
36515 +@@ -1589,6 +1637,7 @@ asmlinkage long sys_connect(int fd, stru
36516 + int addrlen)
36517 + {
36518 + struct socket *sock;
36519 ++ struct sockaddr *sck;
36520 + struct sockaddr_storage address;
36521 + int err, fput_needed;
36522 +
36523 +@@ -1599,6 +1648,13 @@ asmlinkage long sys_connect(int fd, stru
36524 + if (err < 0)
36525 + goto out_put;
36526 +
36527 ++ sck = (struct sockaddr *)&address;
36528 ++ if (!gr_search_connect(sock, (struct sockaddr_in *)sck) ||
36529 ++ gr_handle_sock_client(sck)) {
36530 ++ err = -EACCES;
36531 ++ goto out_put;
36532 ++ }
36533 ++
36534 + err =
36535 + security_socket_connect(sock, (struct sockaddr *)&address, addrlen);
36536 + if (err)
36537 +@@ -1866,6 +1922,7 @@ asmlinkage long sys_shutdown(int fd, int
36538 + err = sock->ops->shutdown(sock, how);
36539 + fput_light(sock->file, fput_needed);
36540 + }
36541 ++
36542 + return err;
36543 + }
36544 +
36545 +diff -urNp linux-2.6.27.10/net/unix/af_unix.c linux-2.6.27.10/net/unix/af_unix.c
36546 +--- linux-2.6.27.10/net/unix/af_unix.c 2008-12-21 01:16:52.000000000 -0500
36547 ++++ linux-2.6.27.10/net/unix/af_unix.c 2008-12-21 01:13:47.000000000 -0500
36548 +@@ -114,6 +114,7 @@
36549 + #include <linux/mount.h>
36550 + #include <net/checksum.h>
36551 + #include <linux/security.h>
36552 ++#include <linux/grsecurity.h>
36553 +
36554 + static struct hlist_head unix_socket_table[UNIX_HASH_SIZE + 1];
36555 + static DEFINE_SPINLOCK(unix_table_lock);
36556 +@@ -725,6 +726,12 @@ static struct sock *unix_find_other(stru
36557 + err = -ECONNREFUSED;
36558 + if (!S_ISSOCK(nd.path.dentry->d_inode->i_mode))
36559 + goto put_fail;
36560 ++
36561 ++ if (!gr_acl_handle_unix(nd.path.dentry, nd.path.mnt)) {
36562 ++ err = -EACCES;
36563 ++ goto put_fail;
36564 ++ }
36565 ++
36566 + u = unix_find_socket_byinode(net, nd.path.dentry->d_inode);
36567 + if (!u)
36568 + goto put_fail;
36569 +@@ -745,6 +752,13 @@ static struct sock *unix_find_other(stru
36570 + if (u) {
36571 + struct dentry *dentry;
36572 + dentry = unix_sk(u)->dentry;
36573 ++
36574 ++ if (!gr_handle_chroot_unix(u->sk_peercred.pid)) {
36575 ++ err = -EPERM;
36576 ++ sock_put(u);
36577 ++ goto fail;
36578 ++ }
36579 ++
36580 + if (dentry)
36581 + touch_atime(unix_sk(u)->mnt, dentry);
36582 + } else
36583 +@@ -827,10 +841,20 @@ static int unix_bind(struct socket *sock
36584 + err = mnt_want_write(nd.path.mnt);
36585 + if (err)
36586 + goto out_mknod_dput;
36587 ++
36588 ++ if (!gr_acl_handle_mknod(dentry, nd.path.dentry, nd.path.mnt, mode)) {
36589 ++ err = -EACCES;
36590 ++ mnt_drop_write(nd.path.mnt);
36591 ++ goto out_mknod_dput;
36592 ++ }
36593 ++
36594 + err = vfs_mknod(nd.path.dentry->d_inode, dentry, mode, 0);
36595 + mnt_drop_write(nd.path.mnt);
36596 + if (err)
36597 + goto out_mknod_dput;
36598 ++
36599 ++ gr_handle_create(dentry, nd.path.mnt);
36600 ++
36601 + mutex_unlock(&nd.path.dentry->d_inode->i_mutex);
36602 + dput(nd.path.dentry);
36603 + nd.path.dentry = dentry;
36604 +@@ -848,6 +872,10 @@ static int unix_bind(struct socket *sock
36605 + goto out_unlock;
36606 + }
36607 +
36608 ++#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
36609 ++ sk->sk_peercred.pid = current->pid;
36610 ++#endif
36611 ++
36612 + list = &unix_socket_table[addr->hash];
36613 + } else {
36614 + list = &unix_socket_table[dentry->d_inode->i_ino & (UNIX_HASH_SIZE-1)];
36615 +diff -urNp linux-2.6.27.10/scripts/pnmtologo.c linux-2.6.27.10/scripts/pnmtologo.c
36616 +--- linux-2.6.27.10/scripts/pnmtologo.c 2008-11-07 12:55:34.000000000 -0500
36617 ++++ linux-2.6.27.10/scripts/pnmtologo.c 2008-11-18 03:38:45.000000000 -0500
36618 +@@ -237,14 +237,14 @@ static void write_header(void)
36619 + fprintf(out, " * Linux logo %s\n", logoname);
36620 + fputs(" */\n\n", out);
36621 + fputs("#include <linux/linux_logo.h>\n\n", out);
36622 +- fprintf(out, "static unsigned char %s_data[] __initdata = {\n",
36623 ++ fprintf(out, "static unsigned char %s_data[] = {\n",
36624 + logoname);
36625 + }
36626 +
36627 + static void write_footer(void)
36628 + {
36629 + fputs("\n};\n\n", out);
36630 +- fprintf(out, "struct linux_logo %s __initdata = {\n", logoname);
36631 ++ fprintf(out, "struct linux_logo %s = {\n", logoname);
36632 + fprintf(out, " .type\t= %s,\n", logo_types[logo_type]);
36633 + fprintf(out, " .width\t= %d,\n", logo_width);
36634 + fprintf(out, " .height\t= %d,\n", logo_height);
36635 +@@ -374,7 +374,7 @@ static void write_logo_clut224(void)
36636 + fputs("\n};\n\n", out);
36637 +
36638 + /* write logo clut */
36639 +- fprintf(out, "static unsigned char %s_clut[] __initdata = {\n",
36640 ++ fprintf(out, "static unsigned char %s_clut[] = {\n",
36641 + logoname);
36642 + write_hex_cnt = 0;
36643 + for (i = 0; i < logo_clutsize; i++) {
36644 +diff -urNp linux-2.6.27.10/security/commoncap.c linux-2.6.27.10/security/commoncap.c
36645 +--- linux-2.6.27.10/security/commoncap.c 2008-11-07 12:55:34.000000000 -0500
36646 ++++ linux-2.6.27.10/security/commoncap.c 2008-11-18 03:38:45.000000000 -0500
36647 +@@ -26,10 +26,13 @@
36648 + #include <linux/sched.h>
36649 + #include <linux/prctl.h>
36650 + #include <linux/securebits.h>
36651 ++#include <linux/grsecurity.h>
36652 ++
36653 ++extern kernel_cap_t gr_cap_rtnetlink(struct sock *sk);
36654 +
36655 + int cap_netlink_send(struct sock *sk, struct sk_buff *skb)
36656 + {
36657 +- NETLINK_CB(skb).eff_cap = current->cap_effective;
36658 ++ NETLINK_CB(skb).eff_cap = gr_cap_rtnetlink(sk);
36659 + return 0;
36660 + }
36661 +
36662 +@@ -51,7 +54,15 @@ EXPORT_SYMBOL(cap_netlink_recv);
36663 + int cap_capable (struct task_struct *tsk, int cap)
36664 + {
36665 + /* Derived from include/linux/sched.h:capable. */
36666 +- if (cap_raised(tsk->cap_effective, cap))
36667 ++ if (cap_raised (tsk->cap_effective, cap))
36668 ++ return 0;
36669 ++ return -EPERM;
36670 ++}
36671 ++
36672 ++int cap_capable_nolog (struct task_struct *tsk, int cap)
36673 ++{
36674 ++ /* tsk = current for all callers */
36675 ++ if (cap_raised(tsk->cap_effective, cap) && gr_is_capable_nolog(cap))
36676 + return 0;
36677 + return -EPERM;
36678 + }
36679 +@@ -379,8 +390,11 @@ void cap_bprm_apply_creds (struct linux_
36680 + }
36681 + }
36682 +
36683 +- current->suid = current->euid = current->fsuid = bprm->e_uid;
36684 +- current->sgid = current->egid = current->fsgid = bprm->e_gid;
36685 ++ if (!gr_check_user_change(-1, bprm->e_uid, bprm->e_uid))
36686 ++ current->suid = current->euid = current->fsuid = bprm->e_uid;
36687 ++
36688 ++ if (!gr_check_group_change(-1, bprm->e_gid, bprm->e_gid))
36689 ++ current->sgid = current->egid = current->fsgid = bprm->e_gid;
36690 +
36691 + /* For init, we want to retain the capabilities set
36692 + * in the init_task struct. Thus we skip the usual
36693 +@@ -393,6 +407,8 @@ void cap_bprm_apply_creds (struct linux_
36694 + cap_clear(current->cap_effective);
36695 + }
36696 +
36697 ++ gr_handle_chroot_caps(current);
36698 ++
36699 + /* AUD: Audit candidate if current->cap_effective is set */
36700 +
36701 + current->securebits &= ~issecure_mask(SECURE_KEEP_CAPS);
36702 +@@ -705,7 +721,7 @@ int cap_vm_enough_memory(struct mm_struc
36703 + {
36704 + int cap_sys_admin = 0;
36705 +
36706 +- if (cap_capable(current, CAP_SYS_ADMIN) == 0)
36707 ++ if (cap_capable_nolog(current, CAP_SYS_ADMIN) == 0)
36708 + cap_sys_admin = 1;
36709 + return __vm_enough_memory(mm, pages, cap_sys_admin);
36710 + }
36711 +diff -urNp linux-2.6.27.10/security/Kconfig linux-2.6.27.10/security/Kconfig
36712 +--- linux-2.6.27.10/security/Kconfig 2008-11-07 12:55:34.000000000 -0500
36713 ++++ linux-2.6.27.10/security/Kconfig 2008-11-18 03:38:45.000000000 -0500
36714 +@@ -4,6 +4,447 @@
36715 +
36716 + menu "Security options"
36717 +
36718 ++source grsecurity/Kconfig
36719 ++
36720 ++menu "PaX"
36721 ++
36722 ++config PAX
36723 ++ bool "Enable various PaX features"
36724 ++ depends on GRKERNSEC && (ALPHA || ARM || AVR32 || IA64 || MIPS32 || MIPS64 || PARISC || PPC32 || PPC64 || SPARC32 || SPARC64 || X86)
36725 ++ help
36726 ++ This allows you to enable various PaX features. PaX adds
36727 ++ intrusion prevention mechanisms to the kernel that reduce
36728 ++ the risks posed by exploitable memory corruption bugs.
36729 ++
36730 ++menu "PaX Control"
36731 ++ depends on PAX
36732 ++
36733 ++config PAX_SOFTMODE
36734 ++ bool 'Support soft mode'
36735 ++ help
36736 ++ Enabling this option will allow you to run PaX in soft mode, that
36737 ++ is, PaX features will not be enforced by default, only on executables
36738 ++ marked explicitly. You must also enable PT_PAX_FLAGS support as it
36739 ++ is the only way to mark executables for soft mode use.
36740 ++
36741 ++ Soft mode can be activated by using the "pax_softmode=1" kernel command
36742 ++ line option on boot. Furthermore you can control various PaX features
36743 ++ at runtime via the entries in /proc/sys/kernel/pax.
36744 ++
36745 ++config PAX_EI_PAX
36746 ++ bool 'Use legacy ELF header marking'
36747 ++ help
36748 ++ Enabling this option will allow you to control PaX features on
36749 ++ a per executable basis via the 'chpax' utility available at
36750 ++ http://pax.grsecurity.net/. The control flags will be read from
36751 ++ an otherwise reserved part of the ELF header. This marking has
36752 ++ numerous drawbacks (no support for soft-mode, toolchain does not
36753 ++ know about the non-standard use of the ELF header) therefore it
36754 ++ has been deprecated in favour of PT_PAX_FLAGS support.
36755 ++
36756 ++ If you have applications not marked by the PT_PAX_FLAGS ELF
36757 ++ program header then you MUST enable this option otherwise they
36758 ++ will not get any protection.
36759 ++
36760 ++ Note that if you enable PT_PAX_FLAGS marking support as well,
36761 ++ the PT_PAX_FLAG marks will override the legacy EI_PAX marks.
36762 ++
36763 ++config PAX_PT_PAX_FLAGS
36764 ++ bool 'Use ELF program header marking'
36765 ++ help
36766 ++ Enabling this option will allow you to control PaX features on
36767 ++ a per executable basis via the 'paxctl' utility available at
36768 ++ http://pax.grsecurity.net/. The control flags will be read from
36769 ++ a PaX specific ELF program header (PT_PAX_FLAGS). This marking
36770 ++ has the benefits of supporting both soft mode and being fully
36771 ++ integrated into the toolchain (the binutils patch is available
36772 ++ from http://pax.grsecurity.net).
36773 ++
36774 ++ If you have applications not marked by the PT_PAX_FLAGS ELF
36775 ++ program header then you MUST enable the EI_PAX marking support
36776 ++ otherwise they will not get any protection.
36777 ++
36778 ++ Note that if you enable the legacy EI_PAX marking support as well,
36779 ++ the EI_PAX marks will be overridden by the PT_PAX_FLAGS marks.
36780 ++
36781 ++choice
36782 ++ prompt 'MAC system integration'
36783 ++ default PAX_HAVE_ACL_FLAGS
36784 ++ help
36785 ++ Mandatory Access Control systems have the option of controlling
36786 ++ PaX flags on a per executable basis, choose the method supported
36787 ++ by your particular system.
36788 ++
36789 ++ - "none": if your MAC system does not interact with PaX,
36790 ++ - "direct": if your MAC system defines pax_set_initial_flags() itself,
36791 ++ - "hook": if your MAC system uses the pax_set_initial_flags_func callback.
36792 ++
36793 ++ NOTE: this option is for developers/integrators only.
36794 ++
36795 ++ config PAX_NO_ACL_FLAGS
36796 ++ bool 'none'
36797 ++
36798 ++ config PAX_HAVE_ACL_FLAGS
36799 ++ bool 'direct'
36800 ++
36801 ++ config PAX_HOOK_ACL_FLAGS
36802 ++ bool 'hook'
36803 ++endchoice
36804 ++
36805 ++endmenu
36806 ++
36807 ++menu "Non-executable pages"
36808 ++ depends on PAX
36809 ++
36810 ++config PAX_NOEXEC
36811 ++ bool "Enforce non-executable pages"
36812 ++ depends on (PAX_EI_PAX || PAX_PT_PAX_FLAGS || PAX_HAVE_ACL_FLAGS || PAX_HOOK_ACL_FLAGS) && (ALPHA || IA64 || MIPS32 || MIPS64 || PARISC || PPC32 || PPC64 || SPARC32 || SPARC64 || X86)
36813 ++ help
36814 ++ By design some architectures do not allow for protecting memory
36815 ++ pages against execution or even if they do, Linux does not make
36816 ++ use of this feature. In practice this means that if a page is
36817 ++ readable (such as the stack or heap) it is also executable.
36818 ++
36819 ++ There is a well known exploit technique that makes use of this
36820 ++ fact and a common programming mistake where an attacker can
36821 ++ introduce code of his choice somewhere in the attacked program's
36822 ++ memory (typically the stack or the heap) and then execute it.
36823 ++
36824 ++ If the attacked program was running with different (typically
36825 ++ higher) privileges than that of the attacker, then he can elevate
36826 ++ his own privilege level (e.g. get a root shell, write to files for
36827 ++ which he does not have write access to, etc).
36828 ++
36829 ++ Enabling this option will let you choose from various features
36830 ++ that prevent the injection and execution of 'foreign' code in
36831 ++ a program.
36832 ++
36833 ++ This will also break programs that rely on the old behaviour and
36834 ++ expect that dynamically allocated memory via the malloc() family
36835 ++ of functions is executable (which it is not). Notable examples
36836 ++ are the XFree86 4.x server, the java runtime and wine.
36837 ++
36838 ++config PAX_PAGEEXEC
36839 ++ bool "Paging based non-executable pages"
36840 ++ depends on !COMPAT_VDSO && PAX_NOEXEC && (!X86_32 || M586 || M586TSC || M586MMX || M686 || MPENTIUMII || MPENTIUMIII || MPENTIUMM || MCORE2 || MPENTIUM4 || MPSC || MK7 || MK8 || MWINCHIPC6 || MWINCHIP2 || MWINCHIP3D || MVIAC3_2 || MVIAC7)
36841 ++ help
36842 ++ This implementation is based on the paging feature of the CPU.
36843 ++ On i386 without hardware non-executable bit support there is a
36844 ++ variable but usually low performance impact, however on Intel's
36845 ++ P4 core based CPUs it is very high so you should not enable this
36846 ++ for kernels meant to be used on such CPUs.
36847 ++
36848 ++ On alpha, avr32, ia64, parisc, sparc, sparc64, x86_64 and i386
36849 ++ with hardware non-executable bit support there is no performance
36850 ++ impact, on ppc the impact is negligible.
36851 ++
36852 ++ Note that several architectures require various emulations due to
36853 ++ badly designed userland ABIs, this will cause a performance impact
36854 ++ but will disappear as soon as userland is fixed (e.g., ppc users
36855 ++ can make use of the secure-plt feature found in binutils).
36856 ++
36857 ++config PAX_SEGMEXEC
36858 ++ bool "Segmentation based non-executable pages"
36859 ++ depends on !COMPAT_VDSO && PAX_NOEXEC && X86_32
36860 ++ help
36861 ++ This implementation is based on the segmentation feature of the
36862 ++ CPU and has a very small performance impact, however applications
36863 ++ will be limited to a 1.5 GB address space instead of the normal
36864 ++ 3 GB.
36865 ++
36866 ++config PAX_EMUTRAMP
36867 ++ bool "Emulate trampolines" if (PAX_PAGEEXEC || PAX_SEGMEXEC) && (PARISC || PPC32 || X86)
36868 ++ default y if PARISC || PPC32
36869 ++ help
36870 ++ There are some programs and libraries that for one reason or
36871 ++ another attempt to execute special small code snippets from
36872 ++ non-executable memory pages. Most notable examples are the
36873 ++ signal handler return code generated by the kernel itself and
36874 ++ the GCC trampolines.
36875 ++
36876 ++ If you enabled CONFIG_PAX_PAGEEXEC or CONFIG_PAX_SEGMEXEC then
36877 ++ such programs will no longer work under your kernel.
36878 ++
36879 ++ As a remedy you can say Y here and use the 'chpax' or 'paxctl'
36880 ++ utilities to enable trampoline emulation for the affected programs
36881 ++ yet still have the protection provided by the non-executable pages.
36882 ++
36883 ++ On parisc and ppc you MUST enable this option and EMUSIGRT as
36884 ++ well, otherwise your system will not even boot.
36885 ++
36886 ++ Alternatively you can say N here and use the 'chpax' or 'paxctl'
36887 ++ utilities to disable CONFIG_PAX_PAGEEXEC and CONFIG_PAX_SEGMEXEC
36888 ++ for the affected files.
36889 ++
36890 ++ NOTE: enabling this feature *may* open up a loophole in the
36891 ++ protection provided by non-executable pages that an attacker
36892 ++ could abuse. Therefore the best solution is to not have any
36893 ++ files on your system that would require this option. This can
36894 ++ be achieved by not using libc5 (which relies on the kernel
36895 ++ signal handler return code) and not using or rewriting programs
36896 ++ that make use of the nested function implementation of GCC.
36897 ++ Skilled users can just fix GCC itself so that it implements
36898 ++ nested function calls in a way that does not interfere with PaX.
36899 ++
36900 ++config PAX_EMUSIGRT
36901 ++ bool "Automatically emulate sigreturn trampolines"
36902 ++ depends on PAX_EMUTRAMP && (PARISC || PPC32)
36903 ++ default y
36904 ++ help
36905 ++ Enabling this option will have the kernel automatically detect
36906 ++ and emulate signal return trampolines executing on the stack
36907 ++ that would otherwise lead to task termination.
36908 ++
36909 ++ This solution is intended as a temporary one for users with
36910 ++ legacy versions of libc (libc5, glibc 2.0, uClibc before 0.9.17,
36911 ++ Modula-3 runtime, etc) or executables linked to such, basically
36912 ++ everything that does not specify its own SA_RESTORER function in
36913 ++ normal executable memory like glibc 2.1+ does.
36914 ++
36915 ++ On parisc and ppc you MUST enable this option, otherwise your
36916 ++ system will not even boot.
36917 ++
36918 ++ NOTE: this feature cannot be disabled on a per executable basis
36919 ++ and since it *does* open up a loophole in the protection provided
36920 ++ by non-executable pages, the best solution is to not have any
36921 ++ files on your system that would require this option.
36922 ++
36923 ++config PAX_MPROTECT
36924 ++ bool "Restrict mprotect()"
36925 ++ depends on (PAX_PAGEEXEC || PAX_SEGMEXEC) && !PPC64
36926 ++ help
36927 ++ Enabling this option will prevent programs from
36928 ++ - changing the executable status of memory pages that were
36929 ++ not originally created as executable,
36930 ++ - making read-only executable pages writable again,
36931 ++ - creating executable pages from anonymous memory.
36932 ++
36933 ++ You should say Y here to complete the protection provided by
36934 ++ the enforcement of non-executable pages.
36935 ++
36936 ++ NOTE: you can use the 'chpax' or 'paxctl' utilities to control
36937 ++ this feature on a per file basis.
36938 ++
36939 ++config PAX_NOELFRELOCS
36940 ++ bool "Disallow ELF text relocations"
36941 ++ depends on PAX_MPROTECT && !PAX_ETEXECRELOCS && (IA64 || X86)
36942 ++ help
36943 ++ Non-executable pages and mprotect() restrictions are effective
36944 ++ in preventing the introduction of new executable code into an
36945 ++ attacked task's address space. There remain only two venues
36946 ++ for this kind of attack: if the attacker can execute already
36947 ++ existing code in the attacked task then he can either have it
36948 ++ create and mmap() a file containing his code or have it mmap()
36949 ++ an already existing ELF library that does not have position
36950 ++ independent code in it and use mprotect() on it to make it
36951 ++ writable and copy his code there. While protecting against
36952 ++ the former approach is beyond PaX, the latter can be prevented
36953 ++ by having only PIC ELF libraries on one's system (which do not
36954 ++ need to relocate their code). If you are sure this is your case,
36955 ++ then enable this option otherwise be careful as you may not even
36956 ++ be able to boot or log on your system (for example, some PAM
36957 ++ modules are erroneously compiled as non-PIC by default).
36958 ++
36959 ++ NOTE: if you are using dynamic ELF executables (as suggested
36960 ++ when using ASLR) then you must have made sure that you linked
36961 ++ your files using the PIC version of crt1 (the et_dyn.tar.gz package
36962 ++ referenced there has already been updated to support this).
36963 ++
36964 ++config PAX_ETEXECRELOCS
36965 ++ bool "Allow ELF ET_EXEC text relocations"
36966 ++ depends on PAX_MPROTECT && (ALPHA || IA64 || PARISC)
36967 ++ default y
36968 ++ help
36969 ++ On some architectures there are incorrectly created applications
36970 ++ that require text relocations and would not work without enabling
36971 ++ this option. If you are an alpha, ia64 or parisc user, you should
36972 ++ enable this option and disable it once you have made sure that
36973 ++ none of your applications need it.
36974 ++
36975 ++config PAX_EMUPLT
36976 ++ bool "Automatically emulate ELF PLT"
36977 ++ depends on PAX_MPROTECT && (ALPHA || PARISC || PPC32 || SPARC32 || SPARC64)
36978 ++ default y
36979 ++ help
36980 ++ Enabling this option will have the kernel automatically detect
36981 ++ and emulate the Procedure Linkage Table entries in ELF files.
36982 ++ On some architectures such entries are in writable memory, and
36983 ++ become non-executable leading to task termination. Therefore
36984 ++ it is mandatory that you enable this option on alpha, parisc,
36985 ++ ppc (if secure-plt is not used throughout in userland), sparc
36986 ++ and sparc64, otherwise your system would not even boot.
36987 ++
36988 ++ NOTE: this feature *does* open up a loophole in the protection
36989 ++ provided by the non-executable pages, therefore the proper
36990 ++ solution is to modify the toolchain to produce a PLT that does
36991 ++ not need to be writable.
36992 ++
36993 ++config PAX_DLRESOLVE
36994 ++ bool
36995 ++ depends on PAX_EMUPLT && (SPARC32 || SPARC64)
36996 ++ default y
36997 ++
36998 ++config PAX_SYSCALL
36999 ++ bool
37000 ++ depends on PAX_PAGEEXEC && PPC32
37001 ++ default y
37002 ++
37003 ++config PAX_KERNEXEC
37004 ++ bool "Enforce non-executable kernel pages"
37005 ++ depends on PAX_NOEXEC && X86 && !EFI && !COMPAT_VDSO && (!X86_32 || X86_WP_WORKS_OK) && !PARAVIRT
37006 ++ help
37007 ++ This is the kernel land equivalent of PAGEEXEC and MPROTECT,
37008 ++ that is, enabling this option will make it harder to inject
37009 ++ and execute 'foreign' code in kernel memory itself.
37010 ++
37011 ++endmenu
37012 ++
37013 ++menu "Address Space Layout Randomization"
37014 ++ depends on PAX
37015 ++
37016 ++config PAX_ASLR
37017 ++ bool "Address Space Layout Randomization"
37018 ++ depends on PAX_EI_PAX || PAX_PT_PAX_FLAGS || PAX_HAVE_ACL_FLAGS || PAX_HOOK_ACL_FLAGS
37019 ++ help
37020 ++ Many if not most exploit techniques rely on the knowledge of
37021 ++ certain addresses in the attacked program. The following options
37022 ++ will allow the kernel to apply a certain amount of randomization
37023 ++ to specific parts of the program thereby forcing an attacker to
37024 ++ guess them in most cases. Any failed guess will most likely crash
37025 ++ the attacked program which allows the kernel to detect such attempts
37026 ++ and react on them. PaX itself provides no reaction mechanisms,
37027 ++ instead it is strongly encouraged that you make use of Nergal's
37028 ++ segvguard (ftp://ftp.pl.openwall.com/misc/segvguard/) or grsecurity's
37029 ++ (http://www.grsecurity.net/) built-in crash detection features or
37030 ++ develop one yourself.
37031 ++
37032 ++ By saying Y here you can choose to randomize the following areas:
37033 ++ - top of the task's kernel stack
37034 ++ - top of the task's userland stack
37035 ++ - base address for mmap() requests that do not specify one
37036 ++ (this includes all libraries)
37037 ++ - base address of the main executable
37038 ++
37039 ++ It is strongly recommended to say Y here as address space layout
37040 ++ randomization has negligible impact on performance yet it provides
37041 ++ a very effective protection.
37042 ++
37043 ++ NOTE: you can use the 'chpax' or 'paxctl' utilities to control
37044 ++ this feature on a per file basis.
37045 ++
37046 ++config PAX_RANDKSTACK
37047 ++ bool "Randomize kernel stack base"
37048 ++ depends on PAX_ASLR && X86_TSC && X86_32
37049 ++ help
37050 ++ By saying Y here the kernel will randomize every task's kernel
37051 ++ stack on every system call. This will not only force an attacker
37052 ++ to guess it but also prevent him from making use of possible
37053 ++ leaked information about it.
37054 ++
37055 ++ Since the kernel stack is a rather scarce resource, randomization
37056 ++ may cause unexpected stack overflows, therefore you should very
37057 ++ carefully test your system. Note that once enabled in the kernel
37058 ++ configuration, this feature cannot be disabled on a per file basis.
37059 ++
37060 ++config PAX_RANDUSTACK
37061 ++ bool "Randomize user stack base"
37062 ++ depends on PAX_ASLR
37063 ++ help
37064 ++ By saying Y here the kernel will randomize every task's userland
37065 ++ stack. The randomization is done in two steps where the second
37066 ++ one may apply a big amount of shift to the top of the stack and
37067 ++ cause problems for programs that want to use lots of memory (more
37068 ++ than 2.5 GB if SEGMEXEC is not active, or 1.25 GB when it is).
37069 ++ For this reason the second step can be controlled by 'chpax' or
37070 ++ 'paxctl' on a per file basis.
37071 ++
37072 ++config PAX_RANDMMAP
37073 ++ bool "Randomize mmap() base"
37074 ++ depends on PAX_ASLR
37075 ++ help
37076 ++ By saying Y here the kernel will use a randomized base address for
37077 ++ mmap() requests that do not specify one themselves. As a result
37078 ++ all dynamically loaded libraries will appear at random addresses
37079 ++ and therefore be harder to exploit by a technique where an attacker
37080 ++ attempts to execute library code for his purposes (e.g. spawn a
37081 ++ shell from an exploited program that is running at an elevated
37082 ++ privilege level).
37083 ++
37084 ++ Furthermore, if a program is relinked as a dynamic ELF file, its
37085 ++ base address will be randomized as well, completing the full
37086 ++ randomization of the address space layout. Attacking such programs
37087 ++ becomes a guess game. You can find an example of doing this at
37088 ++ http://pax.grsecurity.net/et_dyn.tar.gz and practical samples at
37089 ++ http://www.grsecurity.net/grsec-gcc-specs.tar.gz .
37090 ++
37091 ++ NOTE: you can use the 'chpax' or 'paxctl' utilities to control this
37092 ++ feature on a per file basis.
37093 ++
37094 ++endmenu
37095 ++
37096 ++menu "Miscellaneous hardening features"
37097 ++
37098 ++config PAX_MEMORY_SANITIZE
37099 ++ bool "Sanitize all freed memory"
37100 ++ help
37101 ++ By saying Y here the kernel will erase memory pages as soon as they
37102 ++ are freed. This in turn reduces the lifetime of data stored in the
37103 ++ pages, making it less likely that sensitive information such as
37104 ++ passwords, cryptographic secrets, etc stay in memory for too long.
37105 ++
37106 ++ This is especially useful for programs whose runtime is short, long
37107 ++ lived processes and the kernel itself benefit from this as long as
37108 ++ they operate on whole memory pages and ensure timely freeing of pages
37109 ++ that may hold sensitive information.
37110 ++
37111 ++ The tradeoff is performance impact, on a single CPU system kernel
37112 ++ compilation sees a 3% slowdown, other systems and workloads may vary
37113 ++ and you are advised to test this feature on your expected workload
37114 ++ before deploying it.
37115 ++
37116 ++ Note that this feature does not protect data stored in live pages,
37117 ++ e.g., process memory swapped to disk may stay there for a long time.
37118 ++
37119 ++config PAX_MEMORY_UDEREF
37120 ++ bool "Prevent invalid userland pointer dereference"
37121 ++ depends on X86_32 && !COMPAT_VDSO && !UML_X86
37122 ++ help
37123 ++ By saying Y here the kernel will be prevented from dereferencing
37124 ++ userland pointers in contexts where the kernel expects only kernel
37125 ++ pointers. This is both a useful runtime debugging feature and a
37126 ++ security measure that prevents exploiting a class of kernel bugs.
37127 ++
37128 ++ The tradeoff is that some virtualization solutions may experience
37129 ++ a huge slowdown and therefore you should not enable this feature
37130 ++ for kernels meant to run in such environments. Whether a given VM
37131 ++ solution is affected or not is best determined by simply trying it
37132 ++ out, the performance impact will be obvious right on boot as this
37133 ++ mechanism engages from very early on. A good rule of thumb is that
37134 ++ VMs running on CPUs without hardware virtualization support (i.e.,
37135 ++ the majority of IA-32 CPUs) will likely experience the slowdown.
37136 ++
37137 ++config PAX_REFCOUNT
37138 ++ bool "Prevent various kernel object reference counter overflows"
37139 ++ depends on X86
37140 ++ help
37141 ++ By saying Y here the kernel will detect and prevent overflowing
37142 ++ various (but not all) kinds of object reference counters. Such
37143 ++ overflows can normally occur due to bugs only and are often, if
37144 ++ not always, exploitable.
37145 ++
37146 ++ The tradeoff is that data structures protected by an oveflowed
37147 ++ refcount will never be freed and therefore will leak memory. Note
37148 ++ that this leak also happens even without this protection but in
37149 ++ that case the overflow can eventually trigger the freeing of the
37150 ++ data structure while it is still being used elsewhere, resulting
37151 ++ in the exploitable situation that this feature prevents.
37152 ++
37153 ++ Since this has a negligible performance impact, you should enable
37154 ++ this feature.
37155 ++endmenu
37156 ++
37157 ++endmenu
37158 ++
37159 + config KEYS
37160 + bool "Enable access key retention support"
37161 + help
37162 +diff -urNp linux-2.6.27.10/sound/core/oss/pcm_oss.c linux-2.6.27.10/sound/core/oss/pcm_oss.c
37163 +--- linux-2.6.27.10/sound/core/oss/pcm_oss.c 2008-11-07 12:55:34.000000000 -0500
37164 ++++ linux-2.6.27.10/sound/core/oss/pcm_oss.c 2008-11-18 03:38:45.000000000 -0500
37165 +@@ -2911,8 +2911,8 @@ static void snd_pcm_oss_proc_done(struct
37166 + }
37167 + }
37168 + #else /* !CONFIG_SND_VERBOSE_PROCFS */
37169 +-#define snd_pcm_oss_proc_init(pcm)
37170 +-#define snd_pcm_oss_proc_done(pcm)
37171 ++#define snd_pcm_oss_proc_init(pcm) do {} while (0)
37172 ++#define snd_pcm_oss_proc_done(pcm) do {} while (0)
37173 + #endif /* CONFIG_SND_VERBOSE_PROCFS */
37174 +
37175 + /*
37176 +diff -urNp linux-2.6.27.10/sound/core/seq/seq_lock.h linux-2.6.27.10/sound/core/seq/seq_lock.h
37177 +--- linux-2.6.27.10/sound/core/seq/seq_lock.h 2008-11-07 12:55:34.000000000 -0500
37178 ++++ linux-2.6.27.10/sound/core/seq/seq_lock.h 2008-11-18 03:38:45.000000000 -0500
37179 +@@ -23,10 +23,10 @@ void snd_use_lock_sync_helper(snd_use_lo
37180 + #else /* SMP || CONFIG_SND_DEBUG */
37181 +
37182 + typedef spinlock_t snd_use_lock_t; /* dummy */
37183 +-#define snd_use_lock_init(lockp) /**/
37184 +-#define snd_use_lock_use(lockp) /**/
37185 +-#define snd_use_lock_free(lockp) /**/
37186 +-#define snd_use_lock_sync(lockp) /**/
37187 ++#define snd_use_lock_init(lockp) do {} while (0)
37188 ++#define snd_use_lock_use(lockp) do {} while (0)
37189 ++#define snd_use_lock_free(lockp) do {} while (0)
37190 ++#define snd_use_lock_sync(lockp) do {} while (0)
37191 +
37192 + #endif /* SMP || CONFIG_SND_DEBUG */
37193 +
37194 +diff -urNp linux-2.6.27.10/sound/pci/ac97/ac97_patch.c linux-2.6.27.10/sound/pci/ac97/ac97_patch.c
37195 +--- linux-2.6.27.10/sound/pci/ac97/ac97_patch.c 2008-11-07 12:55:34.000000000 -0500
37196 ++++ linux-2.6.27.10/sound/pci/ac97/ac97_patch.c 2008-11-18 03:38:45.000000000 -0500
37197 +@@ -1498,7 +1498,7 @@ static const struct snd_ac97_res_table a
37198 + { AC97_VIDEO, 0x9f1f },
37199 + { AC97_AUX, 0x9f1f },
37200 + { AC97_PCM, 0x9f1f },
37201 +- { } /* terminator */
37202 ++ { 0, 0 } /* terminator */
37203 + };
37204 +
37205 + static int patch_ad1819(struct snd_ac97 * ac97)
37206 +@@ -3668,7 +3668,7 @@ static struct snd_ac97_res_table lm4550_
37207 + { AC97_AUX, 0x1f1f },
37208 + { AC97_PCM, 0x1f1f },
37209 + { AC97_REC_GAIN, 0x0f0f },
37210 +- { } /* terminator */
37211 ++ { 0, 0 } /* terminator */
37212 + };
37213 +
37214 + static int patch_lm4550(struct snd_ac97 *ac97)
37215 +diff -urNp linux-2.6.27.10/sound/pci/ens1370.c linux-2.6.27.10/sound/pci/ens1370.c
37216 +--- linux-2.6.27.10/sound/pci/ens1370.c 2008-11-07 12:55:34.000000000 -0500
37217 ++++ linux-2.6.27.10/sound/pci/ens1370.c 2008-11-18 03:38:45.000000000 -0500
37218 +@@ -452,7 +452,7 @@ static struct pci_device_id snd_audiopci
37219 + { 0x1274, 0x5880, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* ES1373 - CT5880 */
37220 + { 0x1102, 0x8938, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* Ectiva EV1938 */
37221 + #endif
37222 +- { 0, }
37223 ++ { 0, 0, 0, 0, 0, 0, 0 }
37224 + };
37225 +
37226 + MODULE_DEVICE_TABLE(pci, snd_audiopci_ids);
37227 +diff -urNp linux-2.6.27.10/sound/pci/intel8x0.c linux-2.6.27.10/sound/pci/intel8x0.c
37228 +--- linux-2.6.27.10/sound/pci/intel8x0.c 2008-11-07 12:55:34.000000000 -0500
37229 ++++ linux-2.6.27.10/sound/pci/intel8x0.c 2008-11-18 03:38:45.000000000 -0500
37230 +@@ -437,7 +437,7 @@ static struct pci_device_id snd_intel8x0
37231 + { 0x1022, 0x746d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL }, /* AMD8111 */
37232 + { 0x1022, 0x7445, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL }, /* AMD768 */
37233 + { 0x10b9, 0x5455, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_ALI }, /* Ali5455 */
37234 +- { 0, }
37235 ++ { 0, 0, 0, 0, 0, 0, 0 }
37236 + };
37237 +
37238 + MODULE_DEVICE_TABLE(pci, snd_intel8x0_ids);
37239 +@@ -2076,7 +2076,7 @@ static struct ac97_quirk ac97_quirks[] _
37240 + .type = AC97_TUNE_HP_ONLY
37241 + },
37242 + #endif
37243 +- { } /* terminator */
37244 ++ { 0, 0, 0, 0, NULL, 0 } /* terminator */
37245 + };
37246 +
37247 + static int __devinit snd_intel8x0_mixer(struct intel8x0 *chip, int ac97_clock,
37248 +diff -urNp linux-2.6.27.10/sound/pci/intel8x0m.c linux-2.6.27.10/sound/pci/intel8x0m.c
37249 +--- linux-2.6.27.10/sound/pci/intel8x0m.c 2008-11-07 12:55:34.000000000 -0500
37250 ++++ linux-2.6.27.10/sound/pci/intel8x0m.c 2008-11-18 03:38:45.000000000 -0500
37251 +@@ -239,7 +239,7 @@ static struct pci_device_id snd_intel8x0
37252 + { 0x1022, 0x746d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL }, /* AMD8111 */
37253 + { 0x10b9, 0x5455, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_ALI }, /* Ali5455 */
37254 + #endif
37255 +- { 0, }
37256 ++ { 0, 0, 0, 0, 0, 0, 0 }
37257 + };
37258 +
37259 + MODULE_DEVICE_TABLE(pci, snd_intel8x0m_ids);
37260 +@@ -1257,7 +1257,7 @@ static struct shortname_table {
37261 + { 0x5455, "ALi M5455" },
37262 + { 0x746d, "AMD AMD8111" },
37263 + #endif
37264 +- { 0 },
37265 ++ { 0, NULL },
37266 + };
37267 +
37268 + static int __devinit snd_intel8x0m_probe(struct pci_dev *pci,
37269 +diff -urNp linux-2.6.27.10/virt/kvm/kvm_main.c linux-2.6.27.10/virt/kvm/kvm_main.c
37270 +--- linux-2.6.27.10/virt/kvm/kvm_main.c 2008-11-07 12:55:34.000000000 -0500
37271 ++++ linux-2.6.27.10/virt/kvm/kvm_main.c 2008-11-18 03:38:45.000000000 -0500
37272 +@@ -1469,6 +1469,9 @@ static struct miscdevice kvm_dev = {
37273 + KVM_MINOR,
37274 + "kvm",
37275 + &kvm_chardev_ops,
37276 ++ {NULL, NULL},
37277 ++ NULL,
37278 ++ NULL
37279 + };
37280 +
37281 + static void hardware_enable(void *junk)
37282
37283 Added: hardened/2.6/tags/2.6.27-7/4421_grsec-remove-localversion-grsec.patch
37284 ===================================================================
37285 --- hardened/2.6/tags/2.6.27-7/4421_grsec-remove-localversion-grsec.patch (rev 0)
37286 +++ hardened/2.6/tags/2.6.27-7/4421_grsec-remove-localversion-grsec.patch 2009-01-24 22:34:22 UTC (rev 1484)
37287 @@ -0,0 +1,9 @@
37288 +From: Kerin Millar <kerframil@×××××.com>
37289 +
37290 +Remove grsecurity's localversion-grsec file as it is inconsistent with
37291 +Gentoo's kernel practices and naming scheme.
37292 +
37293 +--- a/localversion-grsec 2008-02-24 14:26:59.000000000 +0000
37294 ++++ b/localversion-grsec 1970-01-01 01:00:00.000000000 +0100
37295 +@@ -1 +0,0 @@
37296 +--grsec
37297
37298 Added: hardened/2.6/tags/2.6.27-7/4422_grsec-mute-warnings.patch
37299 ===================================================================
37300 --- hardened/2.6/tags/2.6.27-7/4422_grsec-mute-warnings.patch (rev 0)
37301 +++ hardened/2.6/tags/2.6.27-7/4422_grsec-mute-warnings.patch 2009-01-24 22:34:22 UTC (rev 1484)
37302 @@ -0,0 +1,28 @@
37303 +From: Gordon Malm <gengor@g.o>
37304 +
37305 +Updated patch for kernel series 2.6.24.
37306 +
37307 +The credits/description from the original version of this patch remain accurate
37308 +and are included below.
37309 +
37310 +---
37311 +From: Alexander Gabert <gaberta@××××××××.de>
37312 +
37313 +This patch removes the warnings introduced by grsec patch 2.1.9 and later.
37314 +It removes the -W options added by the patch and restores the original
37315 +warning flags of vanilla kernel versions.
37316 +
37317 +Acked-by: Christian Heim <phreak@g.o>
37318 +---
37319 +
37320 +--- a/Makefile
37321 ++++ b/Makefile
37322 +@@ -214,7 +214,7 @@
37323 +
37324 + HOSTCC = gcc
37325 + HOSTCXX = g++
37326 +-HOSTCFLAGS = -Wall -W -Wno-unused -Wno-sign-compare -Wstrict-prototypes -O2 -fomit-frame-pointer
37327 ++HOSTCFLAGS = -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer
37328 + HOSTCXXFLAGS = -O2
37329 +
37330 + # Decide whether to build built-in, modular, or both.
37331
37332 Added: hardened/2.6/tags/2.6.27-7/4425_grsec-pax-without-grsec.patch
37333 ===================================================================
37334 --- hardened/2.6/tags/2.6.27-7/4425_grsec-pax-without-grsec.patch (rev 0)
37335 +++ hardened/2.6/tags/2.6.27-7/4425_grsec-pax-without-grsec.patch 2009-01-24 22:34:22 UTC (rev 1484)
37336 @@ -0,0 +1,47 @@
37337 +From: Gordon Malm <gengor@g.o>
37338 +
37339 +Allow PaX options to be selected without first selecting CONFIG_GRKERNSEC.
37340 +
37341 +This patch has been updated to keep current with newer kernel versions.
37342 +The original version of this patch contained no credits/description.
37343 +
37344 +--- a/arch/x86/mm/fault.c
37345 ++++ b/arch/x86/mm/fault.c
37346 +@@ -433,10 +433,12 @@ static void show_fault_oops(struct pt_re
37347 + if (init_mm.start_code <= address && address < init_mm.end_code)
37348 + #endif
37349 + {
37350 ++#ifdef CONFIG_GRKERNSEC
37351 + if (current->signal->curr_ip)
37352 + printk(KERN_ERR "PAX: From %u.%u.%u.%u: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
37353 + NIPQUAD(current->signal->curr_ip), current->comm, task_pid_nr(current), current->uid, current->euid);
37354 + else
37355 ++#endif
37356 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
37357 + current->comm, task_pid_nr(current), current->uid, current->euid);
37358 + }
37359 +--- a/fs/exec.c
37360 ++++ b/fs/exec.c
37361 +@@ -1691,9 +1691,11 @@ void pax_report_fault(struct pt_regs *re
37362 + }
37363 + up_read(&mm->mmap_sem);
37364 + }
37365 ++#ifdef CONFIG_GRKERNSEC
37366 + if (tsk->signal->curr_ip)
37367 + printk(KERN_ERR "PAX: From %u.%u.%u.%u: execution attempt in: %s, %08lx-%08lx %08lx\n", NIPQUAD(tsk->signal->curr_ip), path_fault, start, end, offset);
37368 + else
37369 ++#endif
37370 + printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
37371 + printk(KERN_ERR "PAX: terminating task: %s(%s):%d, uid/euid: %u/%u, "
37372 + "PC: %p, SP: %p\n", path_exec, tsk->comm, task_pid_nr(tsk),
37373 +--- a/security/Kconfig
37374 ++++ b/security/Kconfig
37375 +@@ -10,7 +10,7 @@ menu "PaX"
37376 +
37377 + config PAX
37378 + bool "Enable various PaX features"
37379 +- depends on GRKERNSEC && (ALPHA || ARM || AVR32 || IA64 || MIPS32 || MIPS64 || PARISC || PPC32 || PPC64 || SPARC32 || SPARC64 || X86)
37380 ++ depends on (ALPHA || ARM || AVR32 || IA64 || MIPS32 || MIPS64 || PARISC || PPC32 || PPC64 || SPARC32 || SPARC64 || X86)
37381 + help
37382 + This allows you to enable various PaX features. PaX adds
37383 + intrusion prevention mechanisms to the kernel that reduce
37384
37385 Added: hardened/2.6/tags/2.6.27-7/4430_grsec-kconfig-default-gids.patch
37386 ===================================================================
37387 --- hardened/2.6/tags/2.6.27-7/4430_grsec-kconfig-default-gids.patch (rev 0)
37388 +++ hardened/2.6/tags/2.6.27-7/4430_grsec-kconfig-default-gids.patch 2009-01-24 22:34:22 UTC (rev 1484)
37389 @@ -0,0 +1,76 @@
37390 +From: Kerin Millar <kerframil@×××××.com>
37391 +
37392 +grsecurity contains a number of options which allow certain protections
37393 +to be applied to or exempted from members of a given group. However, the
37394 +default GIDs specified in the upstream patch are entirely arbitrary and
37395 +there is no telling which (if any) groups the GIDs will correlate with
37396 +on an end-user's system. Because some users don't pay a great deal of
37397 +attention to the finer points of kernel configuration, it is probably
37398 +wise to specify some reasonable defaults so as to stop careless users
37399 +from shooting themselves in the foot.
37400 +
37401 +--- a/grsecurity/Kconfig
37402 ++++ b/grsecurity/Kconfig
37403 +@@ -352,7 +564,7 @@
37404 + config GRKERNSEC_PROC_GID
37405 + int "GID for special group"
37406 + depends on GRKERNSEC_PROC_USERGROUP
37407 +- default 1001
37408 ++ default 10
37409 +
37410 + config GRKERNSEC_PROC_ADD
37411 + bool "Additional restrictions"
37412 +@@ -547,7 +759,7 @@
37413 + config GRKERNSEC_AUDIT_GID
37414 + int "GID for auditing"
37415 + depends on GRKERNSEC_AUDIT_GROUP
37416 +- default 1007
37417 ++ default 100
37418 +
37419 + config GRKERNSEC_EXECLOG
37420 + bool "Exec logging"
37421 +@@ -700,7 +912,7 @@
37422 + config GRKERNSEC_TPE_GID
37423 + int "GID for untrusted users"
37424 + depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
37425 +- default 1005
37426 ++ default 100
37427 + help
37428 + If you have selected the "Invert GID option" above, setting this
37429 + GID determines what group TPE restrictions will be *disabled* for.
37430 +@@ -712,7 +924,7 @@
37431 + config GRKERNSEC_TPE_GID
37432 + int "GID for trusted users"
37433 + depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
37434 +- default 1005
37435 ++ default 10
37436 + help
37437 + If you have selected the "Invert GID option" above, setting this
37438 + GID determines what group TPE restrictions will be *disabled* for.
37439 +@@ -754,7 +966,7 @@
37440 + config GRKERNSEC_SOCKET_ALL_GID
37441 + int "GID to deny all sockets for"
37442 + depends on GRKERNSEC_SOCKET_ALL
37443 +- default 1004
37444 ++ default 65534
37445 + help
37446 + Here you can choose the GID to disable socket access for. Remember to
37447 + add the users you want socket access disabled for to the GID
37448 +@@ -775,7 +987,7 @@
37449 + config GRKERNSEC_SOCKET_CLIENT_GID
37450 + int "GID to deny client sockets for"
37451 + depends on GRKERNSEC_SOCKET_CLIENT
37452 +- default 1003
37453 ++ default 65534
37454 + help
37455 + Here you can choose the GID to disable client socket access for.
37456 + Remember to add the users you want client socket access disabled for to
37457 +@@ -793,7 +1005,7 @@
37458 + config GRKERNSEC_SOCKET_SERVER_GID
37459 + int "GID to deny server sockets for"
37460 + depends on GRKERNSEC_SOCKET_SERVER
37461 +- default 1002
37462 ++ default 65534
37463 + help
37464 + Here you can choose the GID to disable server socket access for.
37465 + Remember to add the users you want server socket access disabled for to
37466
37467 Added: hardened/2.6/tags/2.6.27-7/4435_grsec-kconfig-gentoo.patch
37468 ===================================================================
37469 --- hardened/2.6/tags/2.6.27-7/4435_grsec-kconfig-gentoo.patch (rev 0)
37470 +++ hardened/2.6/tags/2.6.27-7/4435_grsec-kconfig-gentoo.patch 2009-01-24 22:34:22 UTC (rev 1484)
37471 @@ -0,0 +1,243 @@
37472 +From: Gordon Malm <gengor@g.o>
37473 +From: Kerin Millar <kerframil@×××××.com>
37474 +
37475 +Add Hardened Gentoo [server/workstation] predefined grsecurity
37476 +levels. They're designed to provide a comparitively high level of
37477 +security while remaining generally suitable for as great a majority
37478 +of the userbase as possible (particularly new users).
37479 +
37480 +Make Hardened Gentoo [workstation] predefined grsecurity level the
37481 +default. The Hardened Gentoo [server] level is more restrictive
37482 +and conflicts with some software and thus would be less suitable.
37483 +
37484 +The original version of this patch was conceived and created by:
37485 +Ned Ludd <solar@g.o>
37486 +
37487 +--- a/grsecurity/Kconfig
37488 ++++ b/grsecurity/Kconfig
37489 +@@ -20,7 +20,7 @@ config GRKERNSEC
37490 + choice
37491 + prompt "Security Level"
37492 + depends on GRKERNSEC
37493 +- default GRKERNSEC_CUSTOM
37494 ++ default GRKERNSEC_HARDENED_WORKSTATION
37495 +
37496 + config GRKERNSEC_LOW
37497 + bool "Low"
37498 +@@ -183,6 +183,216 @@ config GRKERNSEC_HIGH
37499 + - Mount/unmount/remount logging
37500 + - Kernel symbol hiding
37501 + - Prevention of memory exhaustion-based exploits
37502 ++
37503 ++config GRKERNSEC_HARDENED_SERVER
37504 ++ bool "Hardened Gentoo [server]"
37505 ++ select GRKERNSEC_AUDIT_MOUNT
37506 ++ select GRKERNSEC_BRUTE
37507 ++ select GRKERNSEC_CHROOT
37508 ++ select GRKERNSEC_CHROOT_CAPS
37509 ++ select GRKERNSEC_CHROOT_CHDIR
37510 ++ select GRKERNSEC_CHROOT_CHMOD
37511 ++ select GRKERNSEC_CHROOT_DOUBLE
37512 ++ select GRKERNSEC_CHROOT_FCHDIR
37513 ++ select GRKERNSEC_CHROOT_FINDTASK
37514 ++ select GRKERNSEC_CHROOT_MKNOD
37515 ++ select GRKERNSEC_CHROOT_MOUNT
37516 ++ select GRKERNSEC_CHROOT_NICE
37517 ++ select GRKERNSEC_CHROOT_PIVOT
37518 ++ select GRKERNSEC_CHROOT_SHMAT
37519 ++ select GRKERNSEC_CHROOT_SYSCTL
37520 ++ select GRKERNSEC_CHROOT_UNIX
37521 ++ select GRKERNSEC_DMESG
37522 ++ select GRKERNSEC_EXECVE
37523 ++ select GRKERNSEC_FIFO
37524 ++ select GRKERNSEC_FORKFAIL
37525 ++ select GRKERNSEC_HIDESYM
37526 ++ select GRKERNSEC_IO if (X86)
37527 ++ select GRKERNSEC_KMEM
37528 ++ select GRKERNSEC_LINK
37529 ++ select GRKERNSEC_MODSTOP if (MODULES)
37530 ++ select GRKERNSEC_PROC
37531 ++ select GRKERNSEC_PROC_ADD
37532 ++ select GRKERNSEC_PROC_IPADDR
37533 ++ select GRKERNSEC_PROC_MEMMAP
37534 ++ select GRKERNSEC_PROC_USERGROUP
37535 ++ select GRKERNSEC_RANDNET
37536 ++ select GRKERNSEC_RESLOG
37537 ++ select GRKERNSEC_SIGNAL
37538 ++# select GRKERNSEC_SOCKET
37539 ++# select GRKERNSEC_SOCKET_SERVER
37540 ++ select GRKERNSEC_SYSCTL
37541 ++ select GRKERNSEC_SYSCTL_ON
37542 ++ select GRKERNSEC_TIME
37543 ++ select PAX
37544 ++ select PAX_ASLR
37545 ++ select PAX_DLRESOLVE if (SPARC32 || SPARC64)
37546 ++ select PAX_EI_PAX
37547 ++ select PAX_EMUPLT if (ALPHA || PARISC || PPC32 || SPARC32 || SPARC64)
37548 ++ select PAX_EMUSIGRT if (PARISC || PPC32)
37549 ++ select PAX_EMUTRAMP if (PARISC || PPC32)
37550 ++ select PAX_ETEXECRELOCS if (ALPHA || IA64 || PARISC)
37551 ++ select PAX_KERNEXEC if (X86 && !EFI && !COMPAT_VDSO && !PARAVIRT && (!X86_32 || X86_WP_WORKS_OK))
37552 ++ select PAX_MEMORY_SANITIZE
37553 ++ select PAX_MEMORY_UDEREF if (X86_32 && !COMPAT_VDSO && !UML_X86)
37554 ++ select PAX_MPROTECT if (!PPC64)
37555 ++ select PAX_HAVE_ACL_FLAGS
37556 ++ select PAX_NOELFRELOCS if (X86)
37557 ++ select PAX_NOEXEC
37558 ++ select PAX_PAGEEXEC
37559 ++ select PAX_PT_PAX_FLAGS
37560 ++ select PAX_RANDKSTACK if (X86_32 && X86_TSC)
37561 ++ select PAX_RANDMMAP
37562 ++ select PAX_RANDUSTACK
37563 ++ select PAX_REFCOUNT if (X86)
37564 ++ select PAX_SEGMEXEC if (X86_32)
37565 ++ select PAX_SYSCALL if (PPC32)
37566 ++ help
37567 ++ If you say Y here, a configuration will be used that is endorsed by
37568 ++ the Hardened Gentoo project. Therefore, many of the protections
37569 ++ made available by grsecurity and PaX will be enabled.
37570 ++
37571 ++ Hardened Gentoo's pre-defined security levels are designed to provide
37572 ++ a high level of security while minimizing incompatibilities with the
37573 ++ majority of available software. For further information, please
37574 ++ view <http://www.grsecurity.net> and <http://pax.grsecurity.net> as
37575 ++ well as the Hardened Gentoo Primer at
37576 ++ <http://www.gentoo.org/proj/en/hardened/primer.xml>.
37577 ++
37578 ++ This Hardened Gentoo [server] level is identical to the
37579 ++ Hardened Gentoo [workstation] level, but with the GRKERNSEC_IO,
37580 ++ PAX_KERNEXEC and PAX_NOELFRELOCS security features enabled.
37581 ++ Accordingly, this is the preferred security level if the system will
37582 ++ not be utilizing software incompatible with the aforementioned
37583 ++ grsecurity/PaX features.
37584 ++
37585 ++ You may wish to emerge paxctl, a utility which allows you to toggle
37586 ++ PaX features on problematic binaries on an individual basis. Note that
37587 ++ this only works for ELF binaries that contain a PT_PAX_FLAGS header.
37588 ++ Translated, this means that if you wish to toggle PaX features on
37589 ++ binaries provided by applications that are distributed only in binary
37590 ++ format (rather than being built locally from sources), you will need to
37591 ++ run paxctl -C on the binaries beforehand so as to inject the missing
37592 ++ headers.
37593 ++
37594 ++ When this level is selected, some options cannot be changed. However,
37595 ++ you may opt to fully customize the options that are selected by
37596 ++ choosing "Custom" in the Security Level menu. You may find it helpful
37597 ++ to inherit the options selected by the "Hardened Gentoo [server]"
37598 ++ security level as a starting point for further configuration. To
37599 ++ accomplish this, select this security level then exit the menuconfig
37600 ++ interface, saving changes when prompted. Then, run make menuconfig
37601 ++ again and select the "Custom" level.
37602 ++
37603 ++ Note that this security level probably should not be used if the
37604 ++ target system is a 32bit x86 virtualized guest. If you intend to run
37605 ++ the kernel in a 32bit x86 virtualized guest you will likely need to
37606 ++ disable the PAX_MEMORY_UDEREF option in order to avoid an unacceptable
37607 ++ impact on performance.
37608 ++
37609 ++config GRKERNSEC_HARDENED_WORKSTATION
37610 ++ bool "Hardened Gentoo [workstation]"
37611 ++ select GRKERNSEC_AUDIT_MOUNT
37612 ++ select GRKERNSEC_BRUTE
37613 ++ select GRKERNSEC_CHROOT
37614 ++ select GRKERNSEC_CHROOT_CAPS
37615 ++ select GRKERNSEC_CHROOT_CHDIR
37616 ++ select GRKERNSEC_CHROOT_CHMOD
37617 ++ select GRKERNSEC_CHROOT_DOUBLE
37618 ++ select GRKERNSEC_CHROOT_FCHDIR
37619 ++ select GRKERNSEC_CHROOT_FINDTASK
37620 ++ select GRKERNSEC_CHROOT_MKNOD
37621 ++ select GRKERNSEC_CHROOT_MOUNT
37622 ++ select GRKERNSEC_CHROOT_NICE
37623 ++ select GRKERNSEC_CHROOT_PIVOT
37624 ++ select GRKERNSEC_CHROOT_SHMAT
37625 ++ select GRKERNSEC_CHROOT_SYSCTL
37626 ++ select GRKERNSEC_CHROOT_UNIX
37627 ++ select GRKERNSEC_DMESG
37628 ++ select GRKERNSEC_EXECVE
37629 ++ select GRKERNSEC_FIFO
37630 ++ select GRKERNSEC_FORKFAIL
37631 ++ select GRKERNSEC_HIDESYM
37632 ++ select GRKERNSEC_KMEM
37633 ++ select GRKERNSEC_LINK
37634 ++ select GRKERNSEC_MODSTOP if (MODULES)
37635 ++ select GRKERNSEC_PROC
37636 ++ select GRKERNSEC_PROC_ADD
37637 ++ select GRKERNSEC_PROC_IPADDR
37638 ++ select GRKERNSEC_PROC_MEMMAP
37639 ++ select GRKERNSEC_PROC_USERGROUP
37640 ++ select GRKERNSEC_RANDNET
37641 ++ select GRKERNSEC_RESLOG
37642 ++ select GRKERNSEC_SIGNAL
37643 ++# select GRKERNSEC_SOCKET
37644 ++# select GRKERNSEC_SOCKET_SERVER
37645 ++ select GRKERNSEC_SYSCTL
37646 ++ select GRKERNSEC_SYSCTL_ON
37647 ++ select GRKERNSEC_TIME
37648 ++ select PAX
37649 ++ select PAX_ASLR
37650 ++ select PAX_DLRESOLVE if (SPARC32 || SPARC64)
37651 ++ select PAX_EI_PAX
37652 ++ select PAX_EMUPLT if (ALPHA || PARISC || PPC32 || SPARC32 || SPARC64)
37653 ++ select PAX_EMUSIGRT if (PARISC || PPC32)
37654 ++ select PAX_EMUTRAMP if (PARISC || PPC32)
37655 ++ select PAX_ETEXECRELOCS if (ALPHA || IA64 || PARISC)
37656 ++ select PAX_MEMORY_SANITIZE
37657 ++ select PAX_MEMORY_UDEREF if (X86_32 && !COMPAT_VDSO && !UML_X86)
37658 ++ select PAX_MPROTECT if (!PPC64)
37659 ++ select PAX_HAVE_ACL_FLAGS
37660 ++ select PAX_NOEXEC
37661 ++ select PAX_PAGEEXEC
37662 ++ select PAX_PT_PAX_FLAGS
37663 ++ select PAX_RANDKSTACK if (X86_32 && X86_TSC)
37664 ++ select PAX_RANDMMAP
37665 ++ select PAX_RANDUSTACK
37666 ++ select PAX_REFCOUNT if (X86)
37667 ++ select PAX_SEGMEXEC if (X86_32)
37668 ++ select PAX_SYSCALL if (PPC32)
37669 ++ help
37670 ++ If you say Y here, a configuration will be used that is endorsed by
37671 ++ the Hardened Gentoo project. Therefore, many of the protections
37672 ++ made available by grsecurity and PaX will be enabled.
37673 ++
37674 ++ Hardened Gentoo's pre-defined security levels are designed to provide
37675 ++ a high level of security while minimizing incompatibilities with the
37676 ++ majority of available software. For further information, please
37677 ++ view <http://www.grsecurity.net> and <http://pax.grsecurity.net> as
37678 ++ well as the Hardened Gentoo Primer at
37679 ++ <http://www.gentoo.org/proj/en/hardened/primer.xml>.
37680 ++
37681 ++ This Hardened Gentoo [workstation] level is designed for machines
37682 ++ which are intended to run software not compatible with the
37683 ++ GRKERNSEC_IO, PAX_KERNEXEC and PAX_NOELFRELOCS features of grsecurity.
37684 ++ Accordingly, this security level is suitable for use with the X server
37685 ++ "Xorg" and/or any system that will act as host OS to the virtualization
37686 ++ softwares vmware-server or virtualbox.
37687 ++
37688 ++ You may wish to emerge paxctl, a utility which allows you to toggle
37689 ++ PaX features on problematic binaries on an individual basis. Note that
37690 ++ this only works for ELF binaries that contain a PT_PAX_FLAGS header.
37691 ++ Translated, this means that if you wish to toggle PaX features on
37692 ++ binaries provided by applications that are distributed only in binary
37693 ++ format (rather than being built locally from sources), you will need to
37694 ++ run paxctl -C on the binaries beforehand so as to inject the missing
37695 ++ headers.
37696 ++
37697 ++ When this level is selected, some options cannot be changed. However,
37698 ++ you may opt to fully customize the options that are selected by
37699 ++ choosing "Custom" in the Security Level menu. You may find it helpful
37700 ++ to inherit the options selected by the "Hardened Gentoo [workstation]"
37701 ++ security level as a starting point for further configuration. To
37702 ++ accomplish this, select this security level then exit the menuconfig
37703 ++ interface, saving changes when prompted. Then, run make menuconfig
37704 ++ again and select the "Custom" level.
37705 ++
37706 ++ Note that this security level probably should not be used if the
37707 ++ target system is a 32bit x86 virtualized guest. If you intend to run
37708 ++ the kernel in a 32bit x86 virtualized guest you will likely need to
37709 ++ disable the PAX_MEMORY_UDEREF option in order to avoid an unacceptable
37710 ++ impact on performance.
37711 ++
37712 + config GRKERNSEC_CUSTOM
37713 + bool "Custom"
37714 + help
37715
37716 Added: hardened/2.6/tags/2.6.27-7/4440_selinux-avc_audit-log-curr_ip.patch
37717 ===================================================================
37718 --- hardened/2.6/tags/2.6.27-7/4440_selinux-avc_audit-log-curr_ip.patch (rev 0)
37719 +++ hardened/2.6/tags/2.6.27-7/4440_selinux-avc_audit-log-curr_ip.patch 2009-01-24 22:34:22 UTC (rev 1484)
37720 @@ -0,0 +1,65 @@
37721 +From: Gordon Malm <gengor@g.o>
37722 +
37723 +This is a reworked version of the original
37724 +*_selinux-avc_audit-log-curr_ip.patch carried in earlier releases of
37725 +hardened-sources.
37726 +
37727 +Dropping the patch, or simply fixing the #ifdef of the original patch
37728 +could break automated logging setups so this route was necessary.
37729 +
37730 +Suggestions for improving the help text are welcome.
37731 +
37732 +The original patch's description is still accurate and included below.
37733 +
37734 +---
37735 +Provides support for a new field ipaddr within the SELinux
37736 +AVC audit log, relying in task_struct->curr_ip (ipv4 only)
37737 +provided by grSecurity patch to be applied before.
37738 +
37739 +Signed-off-by: Lorenzo Hernandez Garcia-Hierro <lorenzo@×××.org>
37740 +---
37741 +
37742 +--- a/grsecurity/Kconfig
37743 ++++ b/grsecurity/Kconfig
37744 +@@ -1044,6 +1044,27 @@ endmenu
37745 + menu "Logging Options"
37746 + depends on GRKERNSEC
37747 +
37748 ++config GRKERNSEC_SELINUX_AVC_LOG_IPADDR
37749 ++ def_bool n
37750 ++ prompt "Add source IP address to SELinux AVC log messages"
37751 ++ depends on GRKERNSEC && SECURITY_SELINUX
37752 ++ help
37753 ++ If you say Y here, a new field "ipaddr=" will be added to many SELinux
37754 ++ AVC log messages. The value of this field in any given message
37755 ++ represents the source IP address of the remote machine/user that created
37756 ++ the offending process.
37757 ++
37758 ++ This information is sourced from task_struct->curr_ip provided by
37759 ++ grsecurity's GRKERNSEC top-level configuration option. One limitation
37760 ++ is that only IPv4 is supported.
37761 ++
37762 ++ In many instances SELinux AVC log messages already log a superior level
37763 ++ of information that also includes source port and destination ip/port.
37764 ++ Additionally, SELinux's AVC log code supports IPv6.
37765 ++
37766 ++ However, grsecurity's task_struct->curr_ip will sometimes (often?)
37767 ++ provide the offender's IP address where stock SELinux logging fails to.
37768 ++
37769 + config GRKERNSEC_FLOODTIME
37770 + int "Seconds in between log messages (minimum)"
37771 + default 10
37772 +--- a/security/selinux/avc.c
37773 ++++ b/security/selinux/avc.c
37774 +@@ -202,6 +202,11 @@ static void avc_dump_query(struct audit_
37775 + char *scontext;
37776 + u32 scontext_len;
37777 +
37778 ++#ifdef CONFIG_GRKERNSEC_SELINUX_AVC_LOG_IPADDR
37779 ++ if (current->signal->curr_ip)
37780 ++ audit_log_format(ab, "ipaddr=%u.%u.%u.%u ", NIPQUAD(current->signal->curr_ip));
37781 ++#endif
37782 ++
37783 + rc = security_sid_to_context(ssid, &scontext, &scontext_len);
37784 + if (rc)
37785 + audit_log_format(ab, "ssid=%d", ssid);
37786
37787 Added: hardened/2.6/tags/2.6.27-7/4445_disable-compat_vdso.patch
37788 ===================================================================
37789 --- hardened/2.6/tags/2.6.27-7/4445_disable-compat_vdso.patch (rev 0)
37790 +++ hardened/2.6/tags/2.6.27-7/4445_disable-compat_vdso.patch 2009-01-24 22:34:22 UTC (rev 1484)
37791 @@ -0,0 +1,74 @@
37792 +From: Gordon Malm <gengor@g.o>
37793 +From: Kerin Millar <kerframil@×××××.com>
37794 +
37795 +COMPAT_VDSO is inappropriate for any modern Hardened Gentoo system. It
37796 +conflicts with various parts of PaX, crashing the system if enabled
37797 +while PaX's NOEXEC or UDEREF features are active. Moreover, it prevents
37798 +a number of important PaX options from appearing in the configuration
37799 +menu, including all PaX NOEXEC implementations. Unfortunately, the
37800 +reason for the disappearance of these PaX configuration options is
37801 +often far from obvious to inexperienced users.
37802 +
37803 +Therefore, we disable the COMPAT_VDSO menu entry entirely. However,
37804 +COMPAT_VDSO operation can still be enabled via bootparam and sysctl
37805 +interfaces. Consequently, we must also disable the ability to select
37806 +COMPAT_VDSO operation at boot or runtime. Here we patch the kernel so
37807 +that selecting COMPAT_VDSO operation at boot/runtime has no effect if
37808 +conflicting PaX options are enabled, leaving VDSO_ENABLED operation
37809 +intact.
37810 +
37811 +Closes bug: http://bugs.gentoo.org/show_bug.cgi?id=210138
37812 +
37813 +--- a/arch/x86/Kconfig
37814 ++++ b/arch/x86/Kconfig
37815 +@@ -1215,16 +1215,7 @@ config HOTPLUG_CPU
37816 +
37817 + config COMPAT_VDSO
37818 + def_bool n
37819 +- prompt "Compat VDSO support"
37820 + depends on (X86_32 || IA32_EMULATION) && !PAX_NOEXEC
37821 +- help
37822 +- Map the 32-bit VDSO to the predictable old-style address too.
37823 +- ---help---
37824 +- Say N here if you are running a sufficiently recent glibc
37825 +- version (2.3.3 or later), to remove the high-mapped
37826 +- VDSO mapping and to exclusively use the randomized VDSO.
37827 +-
37828 +- If unsure, say Y.
37829 +
37830 + endmenu
37831 +
37832 +--- a/arch/x86/vdso/vdso32-setup.c
37833 ++++ b/arch/x86/vdso/vdso32-setup.c
37834 +@@ -333,17 +333,21 @@ int arch_setup_additional_pages(struct l
37835 +
37836 + map_compat_vdso(compat);
37837 +
37838 ++#if !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_MEMORY_UDEREF)
37839 + if (compat)
37840 + addr = VDSO_HIGH_BASE;
37841 + else {
37842 ++#endif
37843 + addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
37844 + if (IS_ERR_VALUE(addr)) {
37845 + ret = addr;
37846 + goto up_fail;
37847 + }
37848 ++#if !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_MEMORY_UDEREF)
37849 + }
37850 +
37851 + if (compat_uses_vma || !compat) {
37852 ++#endif
37853 + /*
37854 + * MAYWRITE to allow gdb to COW and set breakpoints
37855 + *
37856 +@@ -361,7 +365,9 @@ int arch_setup_additional_pages(struct l
37857 +
37858 + if (ret)
37859 + goto up_fail;
37860 ++#if !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_MEMORY_UDEREF)
37861 + }
37862 ++#endif
37863 +
37864 + current->mm->context.vdso = addr;
37865 + current_thread_info()->sysenter_return =
37866
37867 Added: hardened/2.6/tags/2.6.27-7/4450_grsec-add-offender-IP-to-pax_refcount-logging.patch
37868 ===================================================================
37869 --- hardened/2.6/tags/2.6.27-7/4450_grsec-add-offender-IP-to-pax_refcount-logging.patch (rev 0)
37870 +++ hardened/2.6/tags/2.6.27-7/4450_grsec-add-offender-IP-to-pax_refcount-logging.patch 2009-01-24 22:34:22 UTC (rev 1484)
37871 @@ -0,0 +1,21 @@
37872 +From: Gordon Malm <gengor@g.o>
37873 +
37874 +Add offender's IP to PAX_REFCOUNT log messages if it is available.
37875 +
37876 +--- a/fs/exec.c
37877 ++++ b/fs/exec.c
37878 +@@ -1710,7 +1710,13 @@ void pax_report_fault(struct pt_regs *re
37879 + #ifdef CONFIG_PAX_REFCOUNT
37880 + void pax_report_refcount_overflow(struct pt_regs *regs)
37881 + {
37882 +- printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
37883 ++#ifdef CONFIG_GRKERNSEC
37884 ++ if (current->signal->curr_ip)
37885 ++ printk(KERN_ERR "PAX: From %u.%u.%u.%u: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
37886 ++ NIPQUAD(current->signal->curr_ip), current->comm, task_pid_nr(current), current->uid, current->euid);
37887 ++ else
37888 ++#endif
37889 ++ printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
37890 + current->comm, task_pid_nr(current), current->uid, current->euid);
37891 + print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
37892 + show_registers(regs);
37893
37894 Added: hardened/2.6/tags/2.6.27-7/4455_pax-revert-fix-false-RLIMIT_STACK-warnings.patch
37895 ===================================================================
37896 --- hardened/2.6/tags/2.6.27-7/4455_pax-revert-fix-false-RLIMIT_STACK-warnings.patch (rev 0)
37897 +++ hardened/2.6/tags/2.6.27-7/4455_pax-revert-fix-false-RLIMIT_STACK-warnings.patch 2009-01-24 22:34:22 UTC (rev 1484)
37898 @@ -0,0 +1,33 @@
37899 +From: Gordon Malm <gengor@g.o>
37900 +
37901 +Revert RLIMIT_STACK false-positives-avoidance change in PaX for now.
37902 +
37903 +Fixes random segmentation faults, bugs 253773 and 254843.
37904 +
37905 +--- a/arch/x86/mm/fault.c
37906 ++++ b/arch/x86/mm/fault.c
37907 +@@ -852,14 +852,16 @@ not_pax_fault:
37908 + goto good_area;
37909 + if (!(vma->vm_flags & VM_GROWSDOWN))
37910 + goto bad_area;
37911 +- /*
37912 +- * Accessing the stack below %sp is always a bug.
37913 +- * The large cushion allows instructions like enter
37914 +- * and pusha to work. ("enter $65535,$31" pushes
37915 +- * 32 pointers and then decrements %sp by 65535.)
37916 +- */
37917 +- if (address + 65536 + 32 * sizeof(unsigned long) < regs->sp)
37918 +- goto bad_area;
37919 ++ if (error_code & PF_USER) {
37920 ++ /*
37921 ++ * Accessing the stack below %sp is always a bug.
37922 ++ * The large cushion allows instructions like enter
37923 ++ * and pusha to work. ("enter $65535,$31" pushes
37924 ++ * 32 pointers and then decrements %sp by 65535.)
37925 ++ */
37926 ++ if (address + 65536 + 32 * sizeof(unsigned long) < regs->sp)
37927 ++ goto bad_area;
37928 ++ }
37929 +
37930 + #ifdef CONFIG_PAX_SEGMEXEC
37931 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)